From a73bc5831d11b6bb4376391fcbda42d11b58f4be Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Wed, 21 Feb 2024 15:19:00 +0530 Subject: [PATCH 01/49] feat: new listener interface (#359) * added `Channel`, `ChannelGroup`, `ChannelMetadata`, `UserMetadata`, `Subscription`, `SubscriptionSet` entities definitions * added factory function at PubNub and implementation at EventEmitter to support new listener interface * lib/dist * * test: adding channel, channelGroup, subscription, SubscriptionSet listenr tests * fix: unique channel and groups for subscription, no telemetry for event engine, avoid duplicate listener registration * dist/lib * refactored listeners tests with callback style * take-1: commented new tests * Update run-tests.yml * fix: telemetry condition to add query param * lib/dist * fix: lint * reverted workflow file changes * restore all previous changes of telemetry * dist/lib * *remove unncessary subscriptionOptions prop. * added support for subscriptionSet operations * lib/dist * refactor: naming convention in subscriptionSet class * no presence subscription for channel metadata * fix channles and groups initialisation in constructor * refactor: subscriptionSet will get constructed in form of set of subscriptions when channels/groups set is provided * handling overlapping or unique channels/groups subscribe/unsubscribe with new listener/entity interface * tests and utils * lib/dist * test/ cleanup after test * refactor/fix: new listeners backward compatible to old subscription loop * dist/lib * fix typo in argument * dist/lib * attemp to address Codacy reported warnings * lint! * Codacy warnings fix * Codacy warning fix * added support for event specific listener registration. * refactor subscription/subscriptionSet class definition through common abstract class. * dist/lib * fix: test flakiness * PubNub SDK v7.6.0 release. --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> --- .github/workflows/run-tests.yml | 2 +- .pubnub.yml | 11 +- CHANGELOG.md | 6 + README.md | 4 +- dist/web/pubnub.js | 778 +++++++++++------- dist/web/pubnub.min.js | 4 +- lib/core/components/config.js | 2 +- lib/core/components/eventEmitter.js | 78 +- lib/core/components/subscription_manager.js | 190 +---- lib/core/components/telemetry_manager.js | 9 +- .../endpoints/subscriptionUtils/handshake.js | 5 +- .../subscriptionUtils/receiveMessages.js | 5 +- lib/core/pubnub-common.js | 36 +- lib/core/utils.js | 42 + lib/entities/Channel.js | 22 + lib/entities/ChannelGroup.js | 22 + lib/entities/ChannelMetadata.js | 22 + lib/entities/SubscribeCapable.js | 92 +++ lib/entities/Subscription.js | 84 ++ lib/entities/SubscriptionSet.js | 103 +++ lib/entities/UserMetadata.js | 22 + lib/entities/common.js | 2 + lib/entities/commonTypes.js | 2 + lib/event-engine/index.js | 46 +- package.json | 2 +- src/core/components/config.js | 2 +- src/core/components/eventEmitter.js | 79 +- src/core/components/subscription_manager.js | 223 +---- src/core/components/telemetry_manager.js | 10 +- .../endpoints/subscriptionUtils/handshake.js | 5 +- .../subscriptionUtils/receiveMessages.js | 5 +- src/core/pubnub-common.js | 38 +- src/core/utils.js | 21 + src/entities/Channel.ts | 24 + src/entities/ChannelGroup.ts | 24 + src/entities/ChannelMetadata.ts | 24 + src/entities/SubscribeCapable.ts | 68 ++ src/entities/Subscription.ts | 49 ++ src/entities/SubscriptionSet.ts | 81 ++ src/entities/UserMetadata.ts | 24 + src/entities/commonTypes.ts | 31 + src/event-engine/index.ts | 91 +- test/integration/components/listeners.test.js | 544 ++++++++++++ .../components/subscription_manager.test.js | 1 - 44 files changed, 2128 insertions(+), 807 deletions(-) create mode 100644 lib/entities/Channel.js create mode 100644 lib/entities/ChannelGroup.js create mode 100644 lib/entities/ChannelMetadata.js create mode 100644 lib/entities/SubscribeCapable.js create mode 100644 lib/entities/Subscription.js create mode 100644 lib/entities/SubscriptionSet.js create mode 100644 lib/entities/UserMetadata.js create mode 100644 lib/entities/common.js create mode 100644 lib/entities/commonTypes.js create mode 100644 src/entities/Channel.ts create mode 100644 src/entities/ChannelGroup.ts create mode 100644 src/entities/ChannelMetadata.ts create mode 100644 src/entities/SubscribeCapable.ts create mode 100644 src/entities/Subscription.ts create mode 100644 src/entities/SubscriptionSet.ts create mode 100644 src/entities/UserMetadata.ts create mode 100644 src/entities/commonTypes.ts create mode 100644 test/integration/components/listeners.test.js diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 7e8adc3f0..003bf6d03 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -53,4 +53,4 @@ jobs: needs: [tests] steps: - name: Tests summary - run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed" + run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed" \ No newline at end of file diff --git a/.pubnub.yml b/.pubnub.yml index c9d019e0a..96fb55bb4 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-02-21 + version: v7.6.0 + changes: + - type: feature + text: "Adding channel, channelGroup, channelMetadata and userMetadata entities to be first-class citizens to access APIs related to them. Currently, access is provided only for subscription API." - date: 2024-01-16 version: v7.5.0 changes: @@ -938,7 +943,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '7.5.0' +version: '7.6.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -954,7 +959,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v7.5.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1625,7 +1630,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v7.5.0/pubnub.7.5.0.js + location: https://github.com/pubnub/javascript/releases/download/v7.6.0/pubnub.7.6.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index cdce7699f..bf8d08de1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v7.6.0 +February 21 2024 + +#### Added +- Adding channel, channelGroup, channelMetadata and userMetadata entities to be first-class citizens to access APIs related to them. Currently, access is provided only for subscription API. + ## v7.5.0 January 16 2024 diff --git a/README.md b/README.md index 1dc2eb8d9..23b76595e 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.5.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.5.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 1c0eca8fc..112124b0c 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -108,7 +108,7 @@ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); } - function __read(o, n) { + function __read$1(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; @@ -125,7 +125,7 @@ return ar; } - function __spreadArray(to, from, pack) { + function __spreadArray$1(to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); @@ -794,7 +794,7 @@ return this; }; default_1.prototype.getVersion = function () { - return '7.5.0'; + return '7.6.0'; }; default_1.prototype._setRetryConfiguration = function (configuration) { if (configuration.minimumdelay < 2) { @@ -1802,49 +1802,6 @@ return default_1; }()); - 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 }; - } - function stringToArrayBuffer(str) { - var buf = new ArrayBuffer(str.length * 2); - var bufView = new Uint16Array(buf); - for (var i = 0, strLen = str.length; i < strLen; i++) { - bufView[i] = str.charCodeAt(i); - } - return buf; - } - var utils$5 = { - signPamFromParams: signPamFromParams, - endsWith: endsWith, - createPromise: createPromise, - encodeString: encodeString, - stringToArrayBuffer: stringToArrayBuffer, - }; - /* */ var categories = { // SDK will announce when the network appears to be connected again. @@ -1872,7 +1829,7 @@ var default_1$7 = /** @class */ (function () { function default_1(_a) { - var subscribeEndpoint = _a.subscribeEndpoint, leaveEndpoint = _a.leaveEndpoint, heartbeatEndpoint = _a.heartbeatEndpoint, setStateEndpoint = _a.setStateEndpoint, timeEndpoint = _a.timeEndpoint, getFileUrl = _a.getFileUrl, config = _a.config, crypto = _a.crypto, listenerManager = _a.listenerManager, cryptoModule = _a.cryptoModule; + var subscribeEndpoint = _a.subscribeEndpoint, leaveEndpoint = _a.leaveEndpoint, heartbeatEndpoint = _a.heartbeatEndpoint, setStateEndpoint = _a.setStateEndpoint, timeEndpoint = _a.timeEndpoint, getFileUrl = _a.getFileUrl, config = _a.config, crypto = _a.crypto, listenerManager = _a.listenerManager, cryptoModule = _a.cryptoModule, eventEmitter = _a.eventEmitter; this._listenerManager = listenerManager; this._config = config; this._leaveEndpoint = leaveEndpoint; @@ -1899,6 +1856,7 @@ this._dedupingManager = new default_1$8({ config: config }); if (this._cryptoModule) this._decoder = new TextDecoder(); + this._eventEmitter = eventEmitter; } default_1.prototype.adaptStateChange = function (args, callback) { var _this = this; @@ -2249,191 +2207,15 @@ this._listenerManager.announceStatus(countAnnouncement); } messages.forEach(function (message) { - var channel = message.channel; - var subscriptionMatch = message.subscriptionMatch; - var publishMetaData = message.publishMetaData; - if (channel === subscriptionMatch) { - subscriptionMatch = null; - } + message.channel; + message.subscriptionMatch; if (dedupeOnSubscribe) { if (_this._dedupingManager.isDuplicate(message)) { return; } _this._dedupingManager.addEntry(message); } - if (utils$5.endsWith(message.channel, '-pnpres')) { - var announce = {}; - announce.channel = null; - announce.subscription = null; - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - if (channel) { - announce.channel = channel.substring(0, channel.lastIndexOf('-pnpres')); - } - if (subscriptionMatch) { - announce.subscription = subscriptionMatch.substring(0, subscriptionMatch.lastIndexOf('-pnpres')); - } - announce.action = message.payload.action; - announce.state = message.payload.data; - announce.timetoken = publishMetaData.publishTimetoken; - announce.occupancy = message.payload.occupancy; - announce.uuid = message.payload.uuid; - announce.timestamp = message.payload.timestamp; - if (message.payload.join) { - announce.join = message.payload.join; - } - if (message.payload.leave) { - announce.leave = message.payload.leave; - } - if (message.payload.timeout) { - announce.timeout = message.payload.timeout; - } - _this._listenerManager.announcePresence(announce); - } - else if (message.messageType === 1) { - // this is a signal message - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - announce.message = message.payload; - _this._listenerManager.announceSignal(announce); - } - else if (message.messageType === 2) { - // this is an object message - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - announce.message = { - event: message.payload.event, - type: message.payload.type, - data: message.payload.data, - }; - _this._listenerManager.announceObjects(announce); - if (message.payload.type === 'uuid') { - var eventData = _this._renameChannelField(announce); - _this._listenerManager.announceUser(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: _this._renameEvent(eventData.message.event), type: 'user' }) })); - } - else if (message.payload.type === 'channel') { - var eventData = _this._renameChannelField(announce); - _this._listenerManager.announceSpace(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: _this._renameEvent(eventData.message.event), type: 'space' }) })); - } - else if (message.payload.type === 'membership') { - var eventData = _this._renameChannelField(announce); - var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]); - membershipData.user = user; - membershipData.space = space; - _this._listenerManager.announceMembership(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: _this._renameEvent(eventData.message.event), data: membershipData }) })); - } - } - else if (message.messageType === 3) { - // this is a message action - var announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - announce.data = { - messageTimetoken: message.payload.data.messageTimetoken, - actionTimetoken: message.payload.data.actionTimetoken, - type: message.payload.data.type, - uuid: message.issuingClientId, - value: message.payload.data.value, - }; - announce.event = message.payload.event; - _this._listenerManager.announceMessageAction(announce); - } - else if (message.messageType === 4) { - // this is a file message - var announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - var msgPayload = message.payload; - if (_this._cryptoModule) { - var decryptedPayload = void 0; - try { - var decryptedData = _this._cryptoModule.decrypt(message.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(_this._decoder.decode(decryptedData)) : decryptedData; - } - catch (e) { - decryptedPayload = null; - announce.error = "Error while decrypting message content: ".concat(e.message); - } - if (decryptedPayload !== null) { - msgPayload = decryptedPayload; - } - } - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - announce.message = msgPayload.message; - announce.file = { - id: msgPayload.file.id, - name: msgPayload.file.name, - url: _this._getFileUrl({ - id: msgPayload.file.id, - name: msgPayload.file.name, - channel: channel, - }), - }; - _this._listenerManager.announceFile(announce); - } - else { - var announce = {}; - announce.channel = null; - announce.subscription = null; - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - if (_this._cryptoModule) { - var decryptedPayload = void 0; - try { - var decryptedData = _this._cryptoModule.decrypt(message.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(_this._decoder.decode(decryptedData)) : decryptedData; - } - catch (e) { - decryptedPayload = null; - announce.error = "Error while decrypting message content: ".concat(e.message); - } - if (decryptedPayload != null) { - announce.message = decryptedPayload; - } - else { - announce.message = message.payload; - } - } - else { - announce.message = message.payload; - } - _this._listenerManager.announceMessage(announce); - } + _this._eventEmitter.emitEvent(message); }); this._region = payload.metadata.region; this._startSubscribeLoop(); @@ -2545,6 +2327,11 @@ this._maximumSamplesCount = 100; this._trackedLatencies = {}; this._latencies = {}; + this._telemetryExcludeOperations = [ + OPERATIONS.PNSubscribeOperation, + OPERATIONS.PNReceiveMessagesOperation, + OPERATIONS.PNHandshakeOperation, + ]; this._maximumSamplesCount = configuration.maximumSamplesCount || this._maximumSamplesCount; } /** @@ -2565,13 +2352,13 @@ return latencies; }; default_1.prototype.startLatencyMeasure = function (operationType, identifier) { - if (operationType === OPERATIONS.PNSubscribeOperation || !identifier) { + if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { return; } this._trackedLatencies[identifier] = Date.now(); }; default_1.prototype.stopLatencyMeasure = function (operationType, identifier) { - if (operationType === OPERATIONS.PNSubscribeOperation || !identifier) { + if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { return; } var endpointName = this._endpointName(operationType); @@ -3439,6 +3226,66 @@ return default_1; }()); + 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 }; + } + function stringToArrayBuffer(str) { + var buf = new ArrayBuffer(str.length * 2); + var bufView = new Uint16Array(buf); + for (var i = 0, strLen = str.length; i < strLen; i++) { + bufView[i] = str.charCodeAt(i); + } + return buf; + } + function removeSingleOccurance(source, elementsToRemove) { + var removed = Object.fromEntries(elementsToRemove.map(function (prop) { return [prop, false]; })); + return source.filter(function (e) { + if (elementsToRemove.includes(e) && !removed[e]) { + removed[e] = true; + return false; + } + return true; + }); + } + function findUniqueCommonElements(a, b) { + return __spreadArray([], __read(a), false).filter(function (value) { + return b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value); + }); + } + var utils$5 = { + signPamFromParams: signPamFromParams, + endsWith: endsWith, + createPromise: createPromise, + encodeString: encodeString, + stringToArrayBuffer: stringToArrayBuffer, + removeSingleOccurance: removeSingleOccurance, + findUniqueCommonElements: findUniqueCommonElements, + }; + var PubNubError = /** @class */ (function (_super) { __extends(PubNubError, _super); function PubNubError(message, status) { @@ -5106,7 +4953,7 @@ queryParams.limit = (_h = params === null || params === void 0 ? void 0 : params.limit) !== null && _h !== void 0 ? _h : 100; if (params === null || params === void 0 ? void 0 : params.sort) { queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; + var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; if (value === 'asc' || value === 'desc') { return "".concat(key, ":").concat(value); } @@ -5269,7 +5116,7 @@ queryParams.limit = (_h = params === null || params === void 0 ? void 0 : params.limit) !== null && _h !== void 0 ? _h : 100; if (params === null || params === void 0 ? void 0 : params.sort) { queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; + var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; if (value === 'asc' || value === 'desc') { return "".concat(key, ":").concat(value); } @@ -5443,7 +5290,7 @@ queryParams.limit = (_o = params === null || params === void 0 ? void 0 : params.limit) !== null && _o !== void 0 ? _o : 100; if (params === null || params === void 0 ? void 0 : params.sort) { queryParams.sort = Object.entries((_p = params.sort) !== null && _p !== void 0 ? _p : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; + var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; if (value === 'asc' || value === 'desc') { return "".concat(key, ":").concat(value); } @@ -5536,7 +5383,7 @@ } if (params === null || params === void 0 ? void 0 : params.sort) { queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; + var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; if (value === 'asc' || value === 'desc') { return "".concat(key, ":").concat(value); } @@ -5609,7 +5456,7 @@ queryParams.limit = (_o = params === null || params === void 0 ? void 0 : params.limit) !== null && _o !== void 0 ? _o : 100; if (params === null || params === void 0 ? void 0 : params.sort) { queryParams.sort = Object.entries((_p = params.sort) !== null && _p !== void 0 ? _p : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; + var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; if (value === 'asc' || value === 'desc') { return "".concat(key, ":").concat(value); } @@ -5701,7 +5548,7 @@ } if (params === null || params === void 0 ? void 0 : params.sort) { queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; + var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; if (value === 'asc' || value === 'desc') { return "".concat(key, ":").concat(value); } @@ -6457,7 +6304,7 @@ var timetoken = incomingParams.timetoken, channelTimetokens = incomingParams.channelTimetokens; var outgoingParams = {}; if (channelTimetokens && channelTimetokens.length === 1) { - var _a = __read(channelTimetokens, 1), tt = _a[0]; + var _a = __read$1(channelTimetokens, 1), tt = _a[0]; outgoingParams.timetoken = tt; } else if (channelTimetokens) { @@ -6731,8 +6578,9 @@ }, getURL: function (_a, params) { var config = _a.config; - var channelsString = params.channels ? params.channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils$5.encodeString(channelsString), "/0"); + var _b = params.channels, channels = _b === void 0 ? [] : _b; + var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; + return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils$5.encodeString(stringifiedChannels), "/0"); }, getRequestTimeout: function (_a) { var config = _a.config; @@ -6775,8 +6623,9 @@ }, getURL: function (_a, params) { var config = _a.config; - var channelsString = params.channels ? params.channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils$5.encodeString(channelsString), "/0"); + var _b = params.channels, channels = _b === void 0 ? [] : _b; + var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; + return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils$5.encodeString(stringifiedChannels), "/0"); }, getRequestTimeout: function (_a) { var config = _a.config; @@ -6920,7 +6769,7 @@ }); var transition = this.currentState.transition(this.currentContext, event); if (transition) { - var _d = __read(transition, 3), newState = _d[0], newContext = _d[1], effects = _d[2]; + var _d = __read$1(transition, 3), newState = _d[0], newContext = _d[1], effects = _d[2]; try { for (var _e = __values(this.currentState.exitEffects), _f = _e.next(); !_f.done; _f = _e.next()) { var effect = _f.value; @@ -7019,7 +6868,7 @@ var e_1, _a; try { for (var _b = __values(this.instances.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { - var _d = __read(_c.value, 2), key = _d[0], instance = _d[1]; + var _d = __read$1(_c.value, 2), key = _d[0], instance = _d[1]; instance.cancel(); this.instances.delete(key); } @@ -7044,7 +6893,7 @@ } return { type: type, - payload: fn === null || fn === void 0 ? void 0 : fn.apply(void 0, __spreadArray([], __read(args), false)), + payload: fn === null || fn === void 0 ? void 0 : fn.apply(void 0, __spreadArray$1([], __read$1(args), false)), }; }; creator.type = type; @@ -7056,7 +6905,7 @@ for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } - return { type: type, payload: fn.apply(void 0, __spreadArray([], __read(args), false)), managed: false }; + return { type: type, payload: fn.apply(void 0, __spreadArray$1([], __read$1(args), false)), managed: false }; }; creator.type = type; return creator; @@ -7067,7 +6916,7 @@ for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } - return { type: type, payload: fn.apply(void 0, __spreadArray([], __read(args), false)), managed: true }; + return { type: type, payload: fn.apply(void 0, __spreadArray$1([], __read$1(args), false)), managed: true }; }; creator.type = type; creator.cancel = { type: 'CANCEL', payload: type, managed: false }; @@ -7726,44 +7575,47 @@ EventEngine.prototype.subscribe = function (_a) { var _this = this; var channels = _a.channels, channelGroups = _a.channelGroups, timetoken = _a.timetoken, withPresence = _a.withPresence; - this.channels = __spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false); - this.groups = __spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false); + this.channels = __spreadArray$1(__spreadArray$1([], __read$1(this.channels), false), __read$1((channels !== null && channels !== void 0 ? channels : [])), false); + this.groups = __spreadArray$1(__spreadArray$1([], __read$1(this.groups), false), __read$1((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false); if (withPresence) { this.channels.map(function (c) { return _this.channels.push("".concat(c, "-pnpres")); }); this.groups.map(function (g) { return _this.groups.push("".concat(g, "-pnpres")); }); } if (timetoken) { - this.engine.transition(restore(this.channels, this.groups, timetoken)); + this.engine.transition(restore(Array.from(new Set(__spreadArray$1(__spreadArray$1([], __read$1(this.channels), false), __read$1((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray$1(__spreadArray$1([], __read$1(this.groups), false), __read$1((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false))), timetoken)); } else { - this.engine.transition(subscriptionChange(this.channels, this.groups)); + this.engine.transition(subscriptionChange(Array.from(new Set(__spreadArray$1(__spreadArray$1([], __read$1(this.channels), false), __read$1((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray$1(__spreadArray$1([], __read$1(this.groups), false), __read$1((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false))))); } if (this.dependencies.join) { this.dependencies.join({ - channels: this.channels.filter(function (c) { return !c.endsWith('-pnpres'); }), - groups: this.groups.filter(function (g) { return !g.endsWith('-pnpres'); }), + channels: Array.from(new Set(this.channels.filter(function (c) { return !c.endsWith('-pnpres'); }))), + groups: Array.from(new Set(this.groups.filter(function (g) { return !g.endsWith('-pnpres'); }))), }); } }; EventEngine.prototype.unsubscribe = function (_a) { var _this = this; - var channels = _a.channels, groups = _a.groups; - var channlesWithPres = channels === null || channels === void 0 ? void 0 : channels.slice(0); - channels === null || channels === void 0 ? void 0 : channels.map(function (c) { return channlesWithPres.push("".concat(c, "-pnpres")); }); - this.channels = this.channels.filter(function (channel) { return !(channlesWithPres === null || channlesWithPres === void 0 ? void 0 : channlesWithPres.includes(channel)); }); - var groupsWithPres = groups === null || groups === void 0 ? void 0 : groups.slice(0); - groups === null || groups === void 0 ? void 0 : groups.map(function (g) { return groupsWithPres.push("".concat(g, "-pnpres")); }); - this.groups = this.groups.filter(function (group) { return !(groupsWithPres === null || groupsWithPres === void 0 ? void 0 : groupsWithPres.includes(group)); }); - if (this.dependencies.presenceState) { - channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { return delete _this.dependencies.presenceState[c]; }); - groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { return delete _this.dependencies.presenceState[g]; }); - } - this.engine.transition(subscriptionChange(this.channels.slice(0), this.groups.slice(0))); - if (this.dependencies.leave) { - this.dependencies.leave({ - channels: channels, - groups: groups, - }); + var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c; + var filteredChannels = utils$5.removeSingleOccurance(this.channels, __spreadArray$1(__spreadArray$1([], __read$1(channels), false), __read$1(channels.map(function (c) { return "".concat(c, "-pnpres"); })), false)); + var filteredGroups = utils$5.removeSingleOccurance(this.groups, __spreadArray$1(__spreadArray$1([], __read$1(channelGroups), false), __read$1(channelGroups.map(function (c) { return "".concat(c, "-pnpres"); })), false)); + if (new Set(this.channels).size !== new Set(filteredChannels).size || + new Set(this.groups).size !== new Set(filteredGroups).size) { + var channelsToLeave = utils$5.findUniqueCommonElements(this.channels, channels); + var groupstoLeave = utils$5.findUniqueCommonElements(this.groups, channelGroups); + if (this.dependencies.presenceState) { + channelsToLeave === null || channelsToLeave === void 0 ? void 0 : channelsToLeave.forEach(function (c) { return delete _this.dependencies.presenceState[c]; }); + groupstoLeave === null || groupstoLeave === void 0 ? void 0 : groupstoLeave.forEach(function (g) { return delete _this.dependencies.presenceState[g]; }); + } + this.channels = filteredChannels; + this.groups = filteredGroups; + this.engine.transition(subscriptionChange(Array.from(new Set(this.channels.slice(0))), Array.from(new Set(this.groups.slice(0))))); + if (this.dependencies.leave) { + this.dependencies.leave({ + channels: channelsToLeave.slice(0), + groups: groupstoLeave.slice(0), + }); + } } }; EventEngine.prototype.unsubscribeAll = function () { @@ -7957,8 +7809,8 @@ var HeartbeatStoppedState = new State('HEARTBEAT_STOPPED'); HeartbeatStoppedState.on(joined.type, function (context, event) { return HeartbeatStoppedState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), + channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), + groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), }); }); HeartbeatStoppedState.on(left.type, function (context, event) { @@ -7986,8 +7838,8 @@ }); HeartbeatCooldownState.on(joined.type, function (context, event) { return HeartbeatingState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), + channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), + groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), }); }); HeartbeatCooldownState.on(left.type, function (context, event) { @@ -8009,8 +7861,8 @@ var HeartbeatFailedState = new State('HEARTBEAT_FAILED'); HeartbeatFailedState.on(joined.type, function (context, event) { return HeartbeatingState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), + channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), + groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), }); }); HeartbeatFailedState.on(left.type, function (context, event) { @@ -8040,8 +7892,8 @@ HearbeatReconnectingState.onExit(function () { return delayedHeartbeat.cancel; }); HearbeatReconnectingState.on(joined.type, function (context, event) { return HeartbeatingState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), + channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), + groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), }); }); HearbeatReconnectingState.on(left.type, function (context, event) { @@ -8085,8 +7937,8 @@ }); HeartbeatingState.on(joined.type, function (context, event) { return HeartbeatingState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), + channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), + groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), }); }); HeartbeatingState.on(left.type, function (context, event) { @@ -8140,8 +7992,8 @@ }); PresenceEventEngine.prototype.join = function (_a) { var channels = _a.channels, groups = _a.groups; - this.channels = __spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false); - this.groups = __spreadArray(__spreadArray([], __read(this.groups), false), __read((groups !== null && groups !== void 0 ? groups : [])), false); + this.channels = __spreadArray$1(__spreadArray$1([], __read$1(this.channels), false), __read$1((channels !== null && channels !== void 0 ? channels : [])), false); + this.groups = __spreadArray$1(__spreadArray$1([], __read$1(this.groups), false), __read$1((groups !== null && groups !== void 0 ? groups : [])), false); this.engine.transition(joined(this.channels.slice(0), this.groups.slice(0))); }; PresenceEventEngine.prototype.leave = function (_a) { @@ -8232,6 +8084,8 @@ this.modules = modules; this.listenerManager = listenerManager; this.getFileUrl = getFileUrl; + this._channelListenerMap = new Map(); + this._groupListenerMap = new Map(); if (modules.cryptoModule) this._decoder = new TextDecoder(); } @@ -8266,7 +8120,12 @@ if (e.payload.timeout) { announce.timeout = e.payload.timeout; } + // deprecated --> + announce.actualChannel = subscriptionMatch != null ? channel : null; + announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; + // <-- deprecated this.listenerManager.announcePresence(announce); + this._announce('presence', announce, announce.channel, announce.subscription); } else if (e.messageType === 1) { var announce = {}; @@ -8281,6 +8140,7 @@ } announce.message = e.payload; this.listenerManager.announceSignal(announce); + this._announce('signal', announce, announce.channel, announce.subscription); } else if (e.messageType === 2) { var announce = {}; @@ -8299,20 +8159,27 @@ data: e.payload.data, }; this.listenerManager.announceObjects(announce); + this._announce('objects', announce, announce.channel, announce.subscription); if (e.payload.type === 'uuid') { var eventData = this._renameChannelField(announce); - this.listenerManager.announceUser(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) })); + var userEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) }); + this.listenerManager.announceUser(userEvent); + this._announce('user', userEvent, announce.channel, announce.subscription); } else if (message.payload.type === 'channel') { var eventData = this._renameChannelField(announce); - this.listenerManager.announceSpace(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) })); + var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) }); + this.listenerManager.announceSpace(spaceEvent); + this._announce('space', spaceEvent, announce.channel, announce.subscription); } else if (message.payload.type === 'membership') { var eventData = this._renameChannelField(announce); var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]); membershipData.user = user; membershipData.space = space; - this.listenerManager.announceMembership(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) })); + var membershipEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) }); + this.listenerManager.announceMembership(membershipEvent); + this._announce('membership', membershipEvent, announce.channel, announce.subscription); } } else if (e.messageType === 3) { @@ -8330,6 +8197,7 @@ }; announce.event = e.payload.event; this.listenerManager.announceMessageAction(announce); + this._announce('messageAction', announce, announce.channel, announce.subscription); } else if (e.messageType === 4) { var announce = {}; @@ -8367,6 +8235,7 @@ }), }; this.listenerManager.announceFile(announce); + this._announce('file', announce, announce.channel, announce.subscription); } else { var announce = {}; @@ -8400,9 +8269,59 @@ else { announce.message = e.payload; } + // deprecated --> + announce.actualChannel = subscriptionMatch != null ? channel : null; + announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; + // <-- deprecated this.listenerManager.announceMessage(announce); + this._announce('message', announce, announce.channel, announce.subscription); } }; + EventEmitter.prototype.addListener = function (l, channels, groups) { + var _this = this; + if (!(channels && groups)) { + this.listenerManager.addListener(l); + } + else { + channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { + if (_this._channelListenerMap[c]) { + if (!_this._channelListenerMap[c].includes(l)) + _this._channelListenerMap[c].push(l); + } + else { + _this._channelListenerMap[c] = [l]; + } + }); + groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { + if (_this._groupListenerMap[g]) { + if (!_this._groupListenerMap[g].includes(l)) + _this._groupListenerMap[g].push(l); + } + else { + _this._groupListenerMap[g] = [l]; + } + }); + } + }; + EventEmitter.prototype.removeListener = function (listener, channels, groups) { + var _this = this; + if (!(channels && groups)) { + this.listenerManager.removeListener(listener); + } + else { + channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { + var _a; + _this._channelListenerMap[c] = (_a = _this._channelListenerMap[c]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; }); + }); + groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { + var _a; + _this._groupListenerMap[g] = (_a = _this._groupListenerMap[g]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; }); + }); + } + }; + EventEmitter.prototype.removeAllListeners = function () { + this.listenerManager.removeAllListeners(); + }; EventEmitter.prototype._renameEvent = function (e) { return e === 'set' ? 'updated' : 'removed'; }; @@ -8411,9 +8330,251 @@ eventData.spaceId = channel; return eventData; }; + EventEmitter.prototype._announce = function (type, event, channel, group) { + var _a, _b; + (_a = this._channelListenerMap[channel]) === null || _a === void 0 ? void 0 : _a.forEach(function (l) { return l[type] && l[type](event); }); + (_b = this._groupListenerMap[group]) === null || _b === void 0 ? void 0 : _b.forEach(function (l) { return l[type] && l[type](event); }); + }; return EventEmitter; }()); + var SubscribeCapable = /** @class */ (function () { + function SubscribeCapable() { + } + SubscribeCapable.prototype.subscribe = function () { + var _a, _b; + this.pubnub.subscribe(__assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken }))); + }; + SubscribeCapable.prototype.unsubscribe = function () { + this.pubnub.unsubscribe({ + channels: this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), + channelGroups: this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }), + }); + }; + Object.defineProperty(SubscribeCapable.prototype, "onMessage", { + set: function (onMessagelistener) { + this.listener.message = onMessagelistener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onPresence", { + set: function (onPresencelistener) { + this.listener.presence = onPresencelistener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onSignal", { + set: function (onSignalListener) { + this.listener.signal = onSignalListener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onObjects", { + set: function (onObjectsListener) { + this.listener.objects = onObjectsListener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onMessageAction", { + set: function (messageActionEventListener) { + this.listener.messageAction = messageActionEventListener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onFile", { + set: function (fileEventListener) { + this.listener.file = fileEventListener; + }, + enumerable: false, + configurable: true + }); + SubscribeCapable.prototype.addListener = function (listener) { + this.eventEmitter.addListener(listener, this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); + }; + SubscribeCapable.prototype.removeListener = function (listener) { + this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); + }; + Object.defineProperty(SubscribeCapable.prototype, "channels", { + get: function () { + return this.channelNames.slice(0); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "channelGroups", { + get: function () { + return this.groupNames.slice(0); + }, + enumerable: false, + configurable: true + }); + return SubscribeCapable; + }()); + + var SubscriptionSet = /** @class */ (function (_super) { + __extends(SubscriptionSet, _super); + function SubscriptionSet(_a) { + var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub; + var _this = _super.call(this) || this; + _this.channelNames = []; + _this.groupNames = []; + _this.subscriptionList = []; + _this.options = subscriptionOptions; + _this.eventEmitter = eventEmitter; + _this.pubnub = pubnub; + channels.forEach(function (c) { + var subscription = _this.pubnub.channel(c).subscription(_this.options); + _this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.channelNames), false), __read$1(subscription.channels), false); + _this.subscriptionList.push(subscription); + }); + channelGroups.forEach(function (cg) { + var subscription = _this.pubnub.channelGroup(cg).subscription(_this.options); + _this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.groupNames), false), __read$1(subscription.channelGroups), false); + _this.subscriptionList.push(subscription); + }); + _this.listener = {}; + eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); + return _this; + } + SubscriptionSet.prototype.addSubscription = function (subscription) { + this.subscriptionList.push(subscription); + this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscription.channels), false); + this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscription.channelGroups), false); + }; + SubscriptionSet.prototype.removeSubscription = function (subscription) { + var channelsToRemove = subscription.channels; + var groupsToRemove = subscription.channelGroups; + this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); + this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); + this.subscriptionList = this.subscriptionList.filter(function (s) { return s !== subscription; }); + }; + SubscriptionSet.prototype.addSubscriptionSet = function (subscriptionSet) { + this.subscriptionList = __spreadArray$1(__spreadArray$1([], __read$1(this.subscriptionList), false), __read$1(subscriptionSet.subscriptions), false); + this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscriptionSet.channels), false); + this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscriptionSet.channelGroups), false); + }; + SubscriptionSet.prototype.removeSubscriptionSet = function (subscriptionSet) { + var channelsToRemove = subscriptionSet.channels; + var groupsToRemove = subscriptionSet.channelGroups; + this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); + this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); + this.subscriptionList = this.subscriptionList.filter(function (s) { return !subscriptionSet.subscriptions.includes(s); }); + }; + Object.defineProperty(SubscriptionSet.prototype, "subscriptions", { + get: function () { + return this.subscriptionList.slice(0); + }, + enumerable: false, + configurable: true + }); + return SubscriptionSet; + }(SubscribeCapable)); + + var Subscription = /** @class */ (function (_super) { + __extends(Subscription, _super); + function Subscription(_a) { + var channels = _a.channels, channelGroups = _a.channelGroups, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub; + var _this = _super.call(this) || this; + _this.channelNames = []; + _this.groupNames = []; + _this.channelNames = channels; + _this.groupNames = channelGroups; + _this.options = subscriptionOptions; + _this.pubnub = pubnub; + _this.eventEmitter = eventEmitter; + _this.listener = {}; + eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); + return _this; + } + Subscription.prototype.addSubscription = function (subscription) { + return new SubscriptionSet({ + channels: __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscription.channels), false), + channelGroups: __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscription.channelGroups), false), + subscriptionOptions: __assign(__assign({}, this.options), subscription === null || subscription === void 0 ? void 0 : subscription.options), + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return Subscription; + }(SubscribeCapable)); + + var Channel = /** @class */ (function () { + function Channel(channelName, eventEmitter, pubnub) { + this.name = channelName; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + Channel.prototype.subscription = function (subscriptionOptions) { + return new Subscription({ + channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, "".concat(this.name, "-pnpres")] : [this.name], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return Channel; + }()); + + var ChannelGroup = /** @class */ (function () { + function ChannelGroup(channelGroup, eventEmitter, pubnub) { + this.name = channelGroup; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + ChannelGroup.prototype.subscription = function (subscriptionOptions) { + return new Subscription({ + channels: [], + channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, "".concat(this.name, "-pnpres")] : [this.name], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return ChannelGroup; + }()); + + var ChannelMetadata = /** @class */ (function () { + function ChannelMetadata(id, eventEmitter, pubnub) { + this.id = id; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + ChannelMetadata.prototype.subscription = function (subscriptionOptions) { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return ChannelMetadata; + }()); + + var UserMetadata = /** @class */ (function () { + function UserMetadata(id, eventEmitter, pubnub) { + this.id = id; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + UserMetadata.prototype.subscription = function (subscriptionOptions) { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return UserMetadata; + }()); + var default_1$3 = /** @class */ (function () { function default_1(setup) { var _this = this; @@ -8468,12 +8629,12 @@ this.setPresenceState = endpointCreator.bind(this, modules, presenceSetStateConfig); this.handshake = endpointCreator.bind(this, modules, endpoint$1); this.receiveMessages = endpointCreator.bind(this, modules, endpoint); + this._eventEmitter = new EventEmitter({ + modules: modules, + listenerManager: this._listenerManager, + getFileUrl: function (params) { return getFileUrlFunction(modules, params); }, + }); if (config.enableEventEngine === true) { - this._eventEmitter = new EventEmitter({ - modules: modules, - listenerManager: this._listenerManager, - getFileUrl: function (params) { return getFileUrlFunction(modules, params); }, - }); if (config.maintainPresenceState) { this.presenceState = {}; this.setState = function (args) { @@ -8557,6 +8718,7 @@ listenerManager: listenerManager, getFileUrl: function (params) { return getFileUrlFunction(modules, params); }, cryptoModule: modules.cryptoModule, + eventEmitter: this._eventEmitter, }); this.subscribe = subscriptionManager_1.adaptSubscribeChange.bind(subscriptionManager_1); this.unsubscribe = subscriptionManager_1.adaptUnsubscribeChange.bind(subscriptionManager_1); @@ -8572,9 +8734,9 @@ subscriptionManager_1.disconnect(); }; } - this.addListener = listenerManager.addListener.bind(listenerManager); - this.removeListener = listenerManager.removeListener.bind(listenerManager); - this.removeAllListeners = listenerManager.removeAllListeners.bind(listenerManager); + this.addListener = this._eventEmitter.addListener.bind(this._eventEmitter); + this.removeListener = this._eventEmitter.removeListener.bind(this._eventEmitter); + this.removeAllListeners = this._eventEmitter.removeAllListeners.bind(this._eventEmitter); this.parseToken = tokenManager.parseToken.bind(tokenManager); this.setToken = tokenManager.setToken.bind(tokenManager); this.getToken = tokenManager.getToken.bind(tokenManager); @@ -8629,6 +8791,20 @@ this.getFileUrl = function (params) { return getFileUrlFunction(modules, params); }; this.downloadFile = endpointCreator.bind(this, modules, endpoint$g); this.deleteFile = endpointCreator.bind(this, modules, endpoint$f); + // entities + this.channel = function (name) { return new Channel(name, _this._eventEmitter, _this); }; + this.channelGroup = function (name) { return new ChannelGroup(name, _this._eventEmitter, _this); }; + this.channelMetadata = function (id) { return new ChannelMetadata(id, _this._eventEmitter, _this); }; + this.userMetadata = function (id) { return new UserMetadata(id, _this._eventEmitter, _this); }; + this.subscriptionSet = function (args) { + return new SubscriptionSet({ + channels: args.channels, + channelGroups: args.channelGroups, + subscriptionOptions: args.subscriptionOptions, + eventEmitter: _this._eventEmitter, + pubnub: _this, + }); + }; // Objects API v2 this.objects = { getAllUUIDMetadata: endpointCreator.bind(this, modules, endpoint$e), @@ -8645,18 +8821,18 @@ for (var _i = 1; _i < arguments.length; _i++) { rest[_i - 1] = arguments[_i]; } - return endpointCreator.call.apply(endpointCreator, __spreadArray([_this, + return endpointCreator.call.apply(endpointCreator, __spreadArray$1([_this, modules, - endpoint$5, __assign({ type: 'set' }, parameters)], __read(rest), false)); + endpoint$5, __assign({ type: 'set' }, parameters)], __read$1(rest), false)); }, removeChannelMembers: function (parameters) { var rest = []; for (var _i = 1; _i < arguments.length; _i++) { rest[_i - 1] = arguments[_i]; } - return endpointCreator.call.apply(endpointCreator, __spreadArray([_this, + return endpointCreator.call.apply(endpointCreator, __spreadArray$1([_this, modules, - endpoint$5, __assign({ type: 'delete' }, parameters)], __read(rest), false)); + endpoint$5, __assign({ type: 'delete' }, parameters)], __read$1(rest), false)); }, getMemberships: endpointCreator.bind(this, modules, endpoint$4), setMemberships: function (parameters) { @@ -8664,18 +8840,18 @@ for (var _i = 1; _i < arguments.length; _i++) { rest[_i - 1] = arguments[_i]; } - return endpointCreator.call.apply(endpointCreator, __spreadArray([_this, + return endpointCreator.call.apply(endpointCreator, __spreadArray$1([_this, modules, - endpoint$3, __assign({ type: 'set' }, parameters)], __read(rest), false)); + endpoint$3, __assign({ type: 'set' }, parameters)], __read$1(rest), false)); }, removeMemberships: function (parameters) { var rest = []; for (var _i = 1; _i < arguments.length; _i++) { rest[_i - 1] = arguments[_i]; } - return endpointCreator.call.apply(endpointCreator, __spreadArray([_this, + return endpointCreator.call.apply(endpointCreator, __spreadArray$1([_this, modules, - endpoint$3, __assign({ type: 'delete' }, parameters)], __read(rest), false)); + endpoint$3, __assign({ type: 'delete' }, parameters)], __read$1(rest), false)); }, }; // User Apis @@ -8792,7 +8968,7 @@ }, sort: params.sort != null ? Object.fromEntries(Object.entries(params.sort).map(function (_a) { - var _b = __read(_a, 2), k = _b[0], v = _b[1]; + var _b = __read$1(_a, 2), k = _b[0], v = _b[1]; return [k.replace('user', 'uuid'), v]; })) : null, @@ -8828,7 +9004,7 @@ }, sort: params.sort != null ? Object.fromEntries(Object.entries(params.sort).map(function (_a) { - var _b = __read(_a, 2), k = _b[0], v = _b[1]; + var _b = __read$1(_a, 2), k = _b[0], v = _b[1]; return [k.replace('space', 'channel'), v]; })) : null, @@ -14135,7 +14311,7 @@ return new this({ default: defaultCryptor }); }; CryptoModule.prototype.getAllCryptors = function () { - return __spreadArray([this.defaultCryptor], __read(this.cryptors), false); + return __spreadArray$1([this.defaultCryptor], __read$1(this.cryptors), false); }; CryptoModule.prototype.encrypt = function (data) { var encrypted = this.defaultCryptor.encrypt(data); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index bc8818dc5..97c551cf2 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -12,6 +12,6 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - ***************************************************************************** */var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function s(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function u(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o>2,c=0;c>6),o.push(128|63&a)):a<55296?(o.push(224|a>>12),o.push(128|a>>6&63),o.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++r),a+=65536,o.push(240|a>>18),o.push(128|a>>12&63),o.push(128|a>>6&63),o.push(128|63&a))}return h(3,o.length),p(o);default:var f;if(Array.isArray(t))for(h(4,f=t.length),r=0;r>5!==e)throw"Invalid indefinite length element";return n}function g(e,t){for(var n=0;n>10),e.push(56320|1023&r))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var o,h,m=l(),v=m>>5,b=31&m;if(7===v)switch(b){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=p(),o=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*r;return t.setUint32(0,o<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return u(a.getFloat32(s),4);case 27:return u(a.getFloat64(s),8)}if((h=d(b))<0&&(v<2||6=0;)S+=h,_.push(c(h));var w=new Uint8Array(S),O=0;for(o=0;o<_.length;++o)w.set(_[o],O),O+=_[o].length;return w}return c(h);case 3:var P=[];if(h<0)for(;(h=y(v))>=0;)g(P,h);else g(P,h);return String.fromCharCode.apply(null,P);case 4:var E;if(h<0)for(E=[];!f();)E.push(e());else for(E=new Array(h),o=0;o0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function u(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o>2,c=0;c>6),o.push(128|63&s)):s<55296?(o.push(224|s>>12),o.push(128|s>>6&63),o.push(128|63&s)):(s=(1023&s)<<10,s|=1023&t.charCodeAt(++r),s+=65536,o.push(240|s>>18),o.push(128|s>>12&63),o.push(128|s>>6&63),o.push(128|63&s))}return h(3,o.length),p(o);default:var f;if(Array.isArray(t))for(h(4,f=t.length),r=0;r>5!==e)throw"Invalid indefinite length element";return n}function g(e,t){for(var n=0;n>10),e.push(56320|1023&r))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var o,h,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=p(),o=32768&n,i=31744&n,s=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==s)return s*r;return t.setUint32(0,o<<16|i<<13|s<<13),t.getFloat32(0)}();case 26:return u(s.getFloat32(a),4);case 27:return u(s.getFloat64(a),8)}if((h=d(v))<0&&(b<2||6=0;)S+=h,_.push(c(h));var w=new Uint8Array(S),O=0;for(o=0;o<_.length;++o)w.set(_[o],O),O+=_[o].length;return w}return c(h);case 3:var P=[];if(h<0)for(;(h=y(b))>=0;)g(P,h);else g(P,h);return String.fromCharCode.apply(null,P);case 4:var E;if(h<0)for(E=[];!f();)E.push(e());else for(E=new Array(h),o=0;o=20?this._presenceTimeout=e:(this._presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",this._presenceTimeout)),this.setHeartbeatInterval(this._presenceTimeout/2-1),this},e.prototype.setProxy=function(e){this.proxy=e},e.prototype.getHeartbeatInterval=function(){return this._heartbeatInterval},e.prototype.setHeartbeatInterval=function(e){return this._heartbeatInterval=e,this},e.prototype.getSubscribeTimeout=function(){return this._subscribeRequestTimeout},e.prototype.setSubscribeTimeout=function(e){return this._subscribeRequestTimeout=e,this},e.prototype.getTransactionTimeout=function(){return this._transactionalRequestTimeout},e.prototype.setTransactionTimeout=function(e){return this._transactionalRequestTimeout=e,this},e.prototype.isSendBeaconEnabled=function(){return this._useSendBeacon},e.prototype.setSendBeaconConfig=function(e){return this._useSendBeacon=e,this},e.prototype.getVersion=function(){return"7.5.0"},e.prototype._setRetryConfiguration=function(e){if(e.minimumdelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(e.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(e.maximumDelay&&maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6");if(e.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10");this.retryConfiguration=e},e.prototype._addPnsdkSuffix=function(e,t){this._PNSDKSuffix[e]=t},e.prototype._getPnsdkSuffix=function(e){var t=this;return Object.keys(this._PNSDKSuffix).reduce((function(n,r){return n+e+t._PNSDKSuffix[r]}),"")},e}();function m(e){var t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;function a(){var e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error("Illegal character at ".concat(i,": ").concat(t.charAt(i-1)));return n}for(var s=0;s>4,f=(15&c)<<4|l>>2,d=(3&l)<<6|p>>0;o[s]=h,64!=l&&(o[s+1]=f),64!=p&&(o[s+2]=d)}return r}function v(e){for(var t,n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=new Uint8Array(e),i=o.byteLength,a=i%3,s=i-a,u=0;u>18]+r[(258048&t)>>12]+r[(4032&t)>>6]+r[63&t];return 1==a?n+=r[(252&(t=o[s]))>>2]+r[(3&t)<<4]+"==":2==a&&(n+=r[(64512&(t=o[s]<<8|o[s+1]))>>10]+r[(1008&t)>>4]+r[(15&t)<<2]+"="),n}var b,_,S,w,O,P=P||function(e,t){var n={},r=n.lib={},o=function(){},i=r.Base={extend:function(e){o.prototype=this;var t=new o;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},a=r.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var o=0;o>>2]|=(n[o>>>2]>>>24-o%4*8&255)<<24-(r+o)%4*8;else if(65535>>2]=n[o>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r>>2]>>>24-r%4*8&255;n.push((o>>>4).toString(16)),n.push((15&o).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new a.init(n,t/2)}},c=s.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new a.init(n,t)}},l=s.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new a.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,s=o/(4*i);if(t=(s=t?e.ceil(s):e.max((0|s)-this._minBufferSize,0))*i,o=e.min(4*t,o),t){for(var u=0;uc;){var l;e:{l=u;for(var p=e.sqrt(l),h=2;h<=p;h++)if(!(l%h)){l=!1;break e}l=!0}l&&(8>c&&(i[c]=s(e.pow(u,.5))),a[c]=s(e.pow(u,1/3)),c++),u++}var f=[];o=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],s=n[3],u=n[4],c=n[5],l=n[6],p=n[7],h=0;64>h;h++){if(16>h)f[h]=0|e[t+h];else{var d=f[h-15],y=f[h-2];f[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+f[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+f[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+a[h]+f[h],y=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=l,l=c,c=u,u=s+d|0,s=i,i=o,o=r,r=d+y|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+s|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+p|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(o),t.HmacSHA256=r._createHmacHelper(o)}(Math),_=(b=P).enc.Utf8,b.algo.HMAC=b.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=_.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),a=o.words,s=i.words,u=0;u>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,a=0;4>a&&o+.75*a>>6*(3-a)&63));if(t=r.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(r=n.charAt(64))&&-1!=(r=e.indexOf(r))&&(t=r);for(var r=[],o=0,i=0;i>>6-i%4*2;r[o>>>2]|=(a|s)<<24-o%4*8,o++}return w.create(r,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,r,o,i,a){return((e=e+(t&n|~t&r)+o+a)<>>32-i)+t}function n(e,t,n,r,o,i,a){return((e=e+(t&r|n&~r)+o+a)<>>32-i)+t}function r(e,t,n,r,o,i,a){return((e=e+(t^n^r)+o+a)<>>32-i)+t}function o(e,t,n,r,o,i,a){return((e=e+(n^(t|~r))+o+a)<>>32-i)+t}for(var i=P,a=(u=i.lib).WordArray,s=u.Hasher,u=i.algo,c=[],l=0;64>l;l++)c[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=s.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var s=e[u=i+a];e[u]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}a=this._hash.words;var u=e[i+0],l=(s=e[i+1],e[i+2]),p=e[i+3],h=e[i+4],f=e[i+5],d=e[i+6],y=e[i+7],g=e[i+8],m=e[i+9],v=e[i+10],b=e[i+11],_=e[i+12],S=e[i+13],w=e[i+14],O=e[i+15],P=t(P=a[0],A=a[1],T=a[2],E=a[3],u,7,c[0]),E=t(E,P,A,T,s,12,c[1]),T=t(T,E,P,A,l,17,c[2]),A=t(A,T,E,P,p,22,c[3]);P=t(P,A,T,E,h,7,c[4]),E=t(E,P,A,T,f,12,c[5]),T=t(T,E,P,A,d,17,c[6]),A=t(A,T,E,P,y,22,c[7]),P=t(P,A,T,E,g,7,c[8]),E=t(E,P,A,T,m,12,c[9]),T=t(T,E,P,A,v,17,c[10]),A=t(A,T,E,P,b,22,c[11]),P=t(P,A,T,E,_,7,c[12]),E=t(E,P,A,T,S,12,c[13]),T=t(T,E,P,A,w,17,c[14]),P=n(P,A=t(A,T,E,P,O,22,c[15]),T,E,s,5,c[16]),E=n(E,P,A,T,d,9,c[17]),T=n(T,E,P,A,b,14,c[18]),A=n(A,T,E,P,u,20,c[19]),P=n(P,A,T,E,f,5,c[20]),E=n(E,P,A,T,v,9,c[21]),T=n(T,E,P,A,O,14,c[22]),A=n(A,T,E,P,h,20,c[23]),P=n(P,A,T,E,m,5,c[24]),E=n(E,P,A,T,w,9,c[25]),T=n(T,E,P,A,p,14,c[26]),A=n(A,T,E,P,g,20,c[27]),P=n(P,A,T,E,S,5,c[28]),E=n(E,P,A,T,l,9,c[29]),T=n(T,E,P,A,y,14,c[30]),P=r(P,A=n(A,T,E,P,_,20,c[31]),T,E,f,4,c[32]),E=r(E,P,A,T,g,11,c[33]),T=r(T,E,P,A,b,16,c[34]),A=r(A,T,E,P,w,23,c[35]),P=r(P,A,T,E,s,4,c[36]),E=r(E,P,A,T,h,11,c[37]),T=r(T,E,P,A,y,16,c[38]),A=r(A,T,E,P,v,23,c[39]),P=r(P,A,T,E,S,4,c[40]),E=r(E,P,A,T,u,11,c[41]),T=r(T,E,P,A,p,16,c[42]),A=r(A,T,E,P,d,23,c[43]),P=r(P,A,T,E,m,4,c[44]),E=r(E,P,A,T,_,11,c[45]),T=r(T,E,P,A,O,16,c[46]),P=o(P,A=r(A,T,E,P,l,23,c[47]),T,E,u,6,c[48]),E=o(E,P,A,T,y,10,c[49]),T=o(T,E,P,A,w,15,c[50]),A=o(A,T,E,P,f,21,c[51]),P=o(P,A,T,E,_,6,c[52]),E=o(E,P,A,T,p,10,c[53]),T=o(T,E,P,A,v,15,c[54]),A=o(A,T,E,P,s,21,c[55]),P=o(P,A,T,E,g,6,c[56]),E=o(E,P,A,T,O,10,c[57]),T=o(T,E,P,A,d,15,c[58]),A=o(A,T,E,P,S,21,c[59]),P=o(P,A,T,E,h,6,c[60]),E=o(E,P,A,T,b,10,c[61]),T=o(T,E,P,A,l,15,c[62]),A=o(A,T,E,P,m,21,c[63]);a[0]=a[0]+P|0,a[1]=a[1]+A|0,a[2]=a[2]+T|0,a[3]=a[3]+E|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var i=e.floor(r/4294967296);for(n[15+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(o+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,r=0;4>r;r++)o=n[r],n[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);return t},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=s._createHelper(u),i.HmacMD5=s._createHmacHelper(u)}(Math),function(){var e,t=P,n=(e=t.lib).Base,r=e.WordArray,o=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(s=this.cfg).hasher.create(),o=r.create(),i=o.words,a=s.keySize,s=s.iterations;i.length>>2]}},t.BlockCipher=s.extend({cfg:s.cfg.extend({mode:u,padding:l}),reset:function(){s.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var p=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(u=(f.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return p.create({ciphertext:e,salt:n})}},t.SerializableCipher=n.extend({cfg:n.extend({format:u}),encrypt:function(e,t,n,r){r=this.cfg.extend(r);var o=e.createEncryptor(n,r);return t=o.finalize(t),o=o.cfg,p.create({ciphertext:t,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:r.format})},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),e.createDecryptor(n,r).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),f=(f.kdf={}).OpenSSL={execute:function(e,t,n,o){return o||(o=r.random(8)),e=a.create({keySize:t+n}).compute(e,o),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,p.create({key:e,iv:n,salt:o})}},d=t.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:f}),encrypt:function(e,t,n,r){return n=(r=this.cfg.extend(r)).kdf.execute(n,e.keySize,e.ivSize),r.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,r)).mixIn(n),e},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),n=r.kdf.execute(n,e.keySize,e.ivSize,t.salt),r.iv=n.iv,h.decrypt.call(this,e,t,n.key,r)}})}(),function(){for(var e=P,t=e.lib.BlockCipher,n=e.algo,r=[],o=[],i=[],a=[],s=[],u=[],c=[],l=[],p=[],h=[],f=[],d=0;256>d;d++)f[d]=128>d?d<<1:d<<1^283;var y=0,g=0;for(d=0;256>d;d++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;r[y]=m,o[m]=y;var v=f[y],b=f[v],_=f[b],S=257*f[m]^16843008*m;i[y]=S<<24|S>>>8,a[y]=S<<16|S>>>16,s[y]=S<<8|S>>>24,u[y]=S,S=16843009*_^65537*b^257*v^16843008*y,c[m]=S<<24|S>>>8,l[m]=S<<16|S>>>16,p[m]=S<<8|S>>>24,h[m]=S,y?(y=v^f[f[f[_^v]]],g^=f[f[g]]):y=g=1}var w=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),o=this._keySchedule=[],i=0;i>>24]<<24|r[a>>>16&255]<<16|r[a>>>8&255]<<8|r[255&a]):(a=r[(a=a<<8|a>>>24)>>>24]<<24|r[a>>>16&255]<<16|r[a>>>8&255]<<8|r[255&a],a^=w[i/t|0]<<24),o[i]=o[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:c[r[a>>>24]]^l[r[a>>>16&255]]^p[r[a>>>8&255]]^h[r[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,s,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,c,l,p,h,o),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,r,o,i,a,s){for(var u=this._nRounds,c=e[t]^n[0],l=e[t+1]^n[1],p=e[t+2]^n[2],h=e[t+3]^n[3],f=4,d=1;d>>24]^o[l>>>16&255]^i[p>>>8&255]^a[255&h]^n[f++],g=r[l>>>24]^o[p>>>16&255]^i[h>>>8&255]^a[255&c]^n[f++],m=r[p>>>24]^o[h>>>16&255]^i[c>>>8&255]^a[255&l]^n[f++];h=r[h>>>24]^o[c>>>16&255]^i[l>>>8&255]^a[255&p]^n[f++],c=y,l=g,p=m}y=(s[c>>>24]<<24|s[l>>>16&255]<<16|s[p>>>8&255]<<8|s[255&h])^n[f++],g=(s[l>>>24]<<24|s[p>>>16&255]<<16|s[h>>>8&255]<<8|s[255&c])^n[f++],m=(s[p>>>24]<<24|s[h>>>16&255]<<16|s[c>>>8&255]<<8|s[255&l])^n[f++],h=(s[h>>>24]<<24|s[c>>>16&255]<<16|s[l>>>8&255]<<8|s[255&p])^n[f++],e[t]=y,e[t+1]=g,e[t+2]=m,e[t+3]=h},keySize:8});e.AES=t._createHelper(n)}(),P.mode.ECB=((O=P.lib.BlockCipherMode.extend()).Encryptor=O.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),O.Decryptor=O.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),O);var E=P;function T(e){var t,n=[];for(t=0;t=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))},e.prototype.clearHistory=function(){this.hashHistory=[]},e}();function N(e){return encodeURIComponent(e).replace(/[!~*'()]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())}))}function M(e){return function(e){var t=[];return Object.keys(e).forEach((function(e){return t.push(e)})),t}(e).sort()}var j={signPamFromParams:function(e){return M(e).map((function(t){return"".concat(t,"=").concat(N(e[t]))})).join("&")},endsWith:function(e,t){return-1!==e.indexOf(t,this.length-t.length)},createPromise:function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),reject:t,fulfill:e}},encodeString:N,stringToArrayBuffer:function(e){for(var t=new ArrayBuffer(2*e.length),n=new Uint16Array(t),r=0,o=e.length;r=u){var l={};l.category=R.PNRequestMessageCountExceededCategory,l.operation=e.operation,this._listenerManager.announceStatus(l)}a.forEach((function(e){var t=e.channel,i=e.subscriptionMatch,a=e.publishMetaData;if(t===i&&(i=null),c){if(o._dedupingManager.isDuplicate(e))return;o._dedupingManager.addEntry(e)}if(j.endsWith(e.channel,"-pnpres"))(y={channel:null,subscription:null}).actualChannel=null!=i?t:null,y.subscribedChannel=null!=i?i:t,t&&(y.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(y.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),y.action=e.payload.action,y.state=e.payload.data,y.timetoken=a.publishTimetoken,y.occupancy=e.payload.occupancy,y.uuid=e.payload.uuid,y.timestamp=e.payload.timestamp,e.payload.join&&(y.join=e.payload.join),e.payload.leave&&(y.leave=e.payload.leave),e.payload.timeout&&(y.timeout=e.payload.timeout),o._listenerManager.announcePresence(y);else if(1===e.messageType){(y={channel:null,subscription:null}).channel=t,y.subscription=i,y.timetoken=a.publishTimetoken,y.publisher=e.issuingClientId,e.userMetadata&&(y.userMetadata=e.userMetadata),y.message=e.payload,o._listenerManager.announceSignal(y)}else if(2===e.messageType){if((y={channel:null,subscription:null}).channel=t,y.subscription=i,y.timetoken=a.publishTimetoken,y.publisher=e.issuingClientId,e.userMetadata&&(y.userMetadata=e.userMetadata),y.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},o._listenerManager.announceObjects(y),"uuid"===e.payload.type){var s=o._renameChannelField(y);o._listenerManager.announceUser(n(n({},s),{message:n(n({},s.message),{event:o._renameEvent(s.message.event),type:"user"})}))}else if("channel"===e.payload.type){s=o._renameChannelField(y);o._listenerManager.announceSpace(n(n({},s),{message:n(n({},s.message),{event:o._renameEvent(s.message.event),type:"space"})}))}else if("membership"===e.payload.type){var u=(s=o._renameChannelField(y)).message.data,l=u.uuid,p=u.channel,h=r(u,["uuid","channel"]);h.user=l,h.space=p,o._listenerManager.announceMembership(n(n({},s),{message:n(n({},s.message),{event:o._renameEvent(s.message.event),data:h})}))}}else if(3===e.messageType){(y={}).channel=t,y.subscription=i,y.timetoken=a.publishTimetoken,y.publisher=e.issuingClientId,y.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},y.event=e.payload.event,o._listenerManager.announceMessageAction(y)}else if(4===e.messageType){(y={}).channel=t,y.subscription=i,y.timetoken=a.publishTimetoken,y.publisher=e.issuingClientId;var f=e.payload;if(o._cryptoModule){var d=void 0;try{d=(g=o._cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(o._decoder.decode(g)):g}catch(e){d=null,y.error="Error while decrypting message content: ".concat(e.message)}null!==d&&(f=d)}e.userMetadata&&(y.userMetadata=e.userMetadata),y.message=f.message,y.file={id:f.file.id,name:f.file.name,url:o._getFileUrl({id:f.file.id,name:f.file.name,channel:t})},o._listenerManager.announceFile(y)}else{var y;if((y={channel:null,subscription:null}).actualChannel=null!=i?t:null,y.subscribedChannel=null!=i?i:t,y.channel=t,y.subscription=i,y.timetoken=a.publishTimetoken,y.publisher=e.issuingClientId,e.userMetadata&&(y.userMetadata=e.userMetadata),o._cryptoModule){d=void 0;try{var g;d=(g=o._cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(o._decoder.decode(g)):g}catch(e){d=null,y.error="Error while decrypting message content: ".concat(e.message)}y.message=null!=d?d:e.payload}else y.message=e.payload;o._listenerManager.announceMessage(y)}})),this._region=t.metadata.region,this._startSubscribeLoop()}},e.prototype._stopSubscribeLoop=function(){this._subscribeCall&&("function"==typeof this._subscribeCall.abort&&this._subscribeCall.abort(),this._subscribeCall=null)},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),U={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",PNAccessManagerRevokeToken:"PNAccessManagerRevokeToken",PNHandshakeOperation:"PNHandshakeOperation",PNReceiveMessagesOperation:"PNReceiveMessagesOperation"},I=function(){function e(e){this._maximumSamplesCount=100,this._trackedLatencies={},this._latencies={},this._maximumSamplesCount=e.maximumSamplesCount||this._maximumSamplesCount}return e.prototype.operationsLatencyForRequest=function(){var e=this,t={};return Object.keys(this._latencies).forEach((function(n){var r=e._latencies[n],o=e._averageLatency(r);o>0&&(t["l_".concat(n)]=o)})),t},e.prototype.startLatencyMeasure=function(e,t){e!==U.PNSubscribeOperation&&t&&(this._trackedLatencies[t]=Date.now())},e.prototype.stopLatencyMeasure=function(e,t){if(e!==U.PNSubscribeOperation&&t){var n=this._endpointName(e),r=this._latencies[n],o=this._trackedLatencies[t];r||(this._latencies[n]=[],r=this._latencies[n]),r.push(Date.now()-o),r.length>this._maximumSamplesCount&&r.splice(0,r.length-this._maximumSamplesCount),delete this._trackedLatencies[t]}},e.prototype._averageLatency=function(e){return Math.floor(e.reduce((function(e,t){return e+t}),0)/e.length)},e.prototype._endpointName=function(e){var t=null;switch(e){case U.PNPublishOperation:t="pub";break;case U.PNSignalOperation:t="sig";break;case U.PNHistoryOperation:case U.PNFetchMessagesOperation:case U.PNDeleteMessagesOperation:case U.PNMessageCounts:t="hist";break;case U.PNUnsubscribeOperation:case U.PNWhereNowOperation:case U.PNHereNowOperation:case U.PNHeartbeatOperation:case U.PNSetStateOperation:case U.PNGetStateOperation:t="pres";break;case U.PNAddChannelsToGroupOperation:case U.PNRemoveChannelsFromGroupOperation:case U.PNChannelGroupsOperation:case U.PNRemoveGroupOperation:case U.PNChannelsForGroupOperation:t="cg";break;case U.PNPushNotificationEnabledChannelsOperation:case U.PNRemoveAllPushNotificationsOperation:t="push";break;case U.PNCreateUserOperation:case U.PNUpdateUserOperation:case U.PNDeleteUserOperation:case U.PNGetUserOperation:case U.PNGetUsersOperation:case U.PNCreateSpaceOperation:case U.PNUpdateSpaceOperation:case U.PNDeleteSpaceOperation:case U.PNGetSpaceOperation:case U.PNGetSpacesOperation:case U.PNGetMembersOperation:case U.PNUpdateMembersOperation:case U.PNGetMembershipsOperation:case U.PNUpdateMembershipsOperation:t="obj";break;case U.PNAddMessageActionOperation:case U.PNRemoveMessageActionOperation:case U.PNGetMessageActionsOperation:t="msga";break;case U.PNAccessManagerGrant:case U.PNAccessManagerAudit:t="pam";break;case U.PNAccessManagerGrantToken:case U.PNAccessManagerRevokeToken:t="pamv3";break;default:t="time"}return t},e}(),D=function(){function e(e,t,n){this._payload=e,this._setDefaultPayloadStructure(),this.title=t,this.body=n}return Object.defineProperty(e.prototype,"payload",{get:function(){return this._payload},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{set:function(e){this._title=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{set:function(e){this._subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{set:function(e){this._body=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{set:function(e){this._badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{set:function(e){this._sound=e},enumerable:!1,configurable:!0}),e.prototype._setDefaultPayloadStructure=function(){},e.prototype.toObject=function(){return{}},e}(),F=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"configurations",{set:function(e){e&&e.length&&(this._configurations=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"notification",{get:function(){return this._payload.aps},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.aps.alert.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){e&&e.length&&(this._payload.aps.alert.subtitle=e,this._subtitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.aps.alert.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this._badge},set:function(e){null!=e&&(this._payload.aps.badge=e,this._badge=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.aps.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),r.prototype._setDefaultPayloadStructure=function(){this._payload.aps={alert:{}}},r.prototype.toObject=function(){var e=this,t=n({},this._payload),r=t.aps,o=r.alert;if(this._isSilent&&(r["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");var i=[];this._configurations.forEach((function(t){i.push(e._objectFromAPNS2Configuration(t))})),i.length&&(t.pn_push=i)}return o&&Object.keys(o).length||delete r.alert,this._isSilent&&(delete r.alert,delete r.badge,delete r.sound,o={}),this._isSilent||Object.keys(o).length?t:null},r.prototype._objectFromAPNS2Configuration=function(e){var t=this;if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");var n=[];e.targets.forEach((function(e){n.push(t._objectFromAPNSTarget(e))}));var r=e.collapseId,o=e.expirationDate,i={auth_method:"token",targets:n,version:"v2"};return r&&r.length&&(i.collapse_id=r),o&&(i.expiration=o.toISOString()),i},r.prototype._objectFromAPNSTarget=function(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");var t=e.topic,n=e.environment,r=void 0===n?"development":n,o=e.excludedDevices,i=void 0===o?[]:o,a={topic:t,environment:r};return i.length&&(a.excluded_devices=i),a},r}(D),G=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"backContent",{get:function(){return this._backContent},set:function(e){e&&e.length&&(this._payload.back_content=e,this._backContent=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"backTitle",{get:function(){return this._backTitle},set:function(e){e&&e.length&&(this._payload.back_title=e,this._backTitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"count",{get:function(){return this._count},set:function(e){null!=e&&(this._payload.count=e,this._count=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"type",{get:function(){return this._type},set:function(e){e&&e.length&&(this._payload.type=e,this._type=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this.backTitle},set:function(e){this.backTitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this.backContent},set:function(e){this.backContent=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this.count},set:function(e){this.count=e},enumerable:!1,configurable:!0}),r.prototype.toObject=function(){return Object.keys(this._payload).length?n({},this._payload):null},r}(D),L=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return t(o,e),Object.defineProperty(o.prototype,"notification",{get:function(){return this._payload.notification},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"data",{get:function(){return this._payload.data},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.notification.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.notification.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.notification.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"icon",{get:function(){return this._icon},set:function(e){e&&e.length&&(this._payload.notification.icon=e,this._icon=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"tag",{get:function(){return this._tag},set:function(e){e&&e.length&&(this._payload.notification.tag=e,this._tag=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),o.prototype._setDefaultPayloadStructure=function(){this._payload.notification={},this._payload.data={}},o.prototype.toObject=function(){var e=n({},this._payload.data),t=null,o={};if(Object.keys(this._payload).length>2){var i=this._payload;i.notification,i.data;var a=r(i,["notification","data"]);e=n(n({},e),a)}return this._isSilent?e.notification=this._payload.notification:t=this._payload.notification,Object.keys(e).length&&(o.data=e),t&&Object.keys(t).length&&(o.notification=t),Object.keys(o).length?o:null},o}(D),K=function(){function e(e,t){this._payload={apns:{},mpns:{},fcm:{}},this._title=e,this._body=t,this.apns=new F(this._payload.apns,e,t),this.mpns=new G(this._payload.mpns,e,t),this.fcm=new L(this._payload.fcm,e,t)}return Object.defineProperty(e.prototype,"debugging",{set:function(e){this._debugging=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this._body},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){this._subtitle=e,this.apns.subtitle=e,this.mpns.subtitle=e,this.fcm.subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{get:function(){return this._badge},set:function(e){this._badge=e,this.apns.badge=e,this.mpns.badge=e,this.fcm.badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{get:function(){return this._sound},set:function(e){this._sound=e,this.apns.sound=e,this.mpns.sound=e,this.fcm.sound=e},enumerable:!1,configurable:!0}),e.prototype.buildPayload=function(e){var t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";var n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("mpns")){var r=this.mpns.toObject();r&&Object.keys(r).length&&(t.pn_mpns=r)}if(e.includes("fcm")){var o=this.fcm.toObject();o&&Object.keys(o).length&&(t.pn_gcm=o)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t},e}(),B=function(){function e(){this._listeners=[]}return e.prototype.addListener=function(e){this._listeners.includes(e)||this._listeners.push(e)},e.prototype.removeListener=function(e){var t=[];this._listeners.forEach((function(n){n!==e&&t.push(n)})),this._listeners=t},e.prototype.removeAllListeners=function(){this._listeners=[]},e.prototype.announcePresence=function(e){this._listeners.forEach((function(t){t.presence&&t.presence(e)}))},e.prototype.announceStatus=function(e){this._listeners.forEach((function(t){t.status&&t.status(e)}))},e.prototype.announceMessage=function(e){this._listeners.forEach((function(t){t.message&&t.message(e)}))},e.prototype.announceSignal=function(e){this._listeners.forEach((function(t){t.signal&&t.signal(e)}))},e.prototype.announceMessageAction=function(e){this._listeners.forEach((function(t){t.messageAction&&t.messageAction(e)}))},e.prototype.announceFile=function(e){this._listeners.forEach((function(t){t.file&&t.file(e)}))},e.prototype.announceObjects=function(e){this._listeners.forEach((function(t){t.objects&&t.objects(e)}))},e.prototype.announceUser=function(e){this._listeners.forEach((function(t){t.user&&t.user(e)}))},e.prototype.announceSpace=function(e){this._listeners.forEach((function(t){t.space&&t.space(e)}))},e.prototype.announceMembership=function(e){this._listeners.forEach((function(t){t.membership&&t.membership(e)}))},e.prototype.announceNetworkUp=function(){var e={};e.category=R.PNNetworkUpCategory,this.announceStatus(e)},e.prototype.announceNetworkDown=function(){var e={};e.category=R.PNNetworkDownCategory,this.announceStatus(e)},e}(),H=function(){function e(e,t){this._config=e,this._cbor=t}return e.prototype.setToken=function(e){e&&e.length>0?this._token=e:this._token=void 0},e.prototype.getToken=function(){return this._token},e.prototype.extractPermissions=function(e){var t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128==(128&e)&&(t.join=!0),64==(64&e)&&(t.update=!0),32==(32&e)&&(t.get=!0),8==(8&e)&&(t.delete=!0),4==(4&e)&&(t.manage=!0),2==(2&e)&&(t.write=!0),1==(1&e)&&(t.read=!0),t},e.prototype.parseToken=function(e){var t=this,n=this._cbor.decodeToken(e);if(void 0!==n){var r=n.res.uuid?Object.keys(n.res.uuid):[],o=Object.keys(n.res.chan),i=Object.keys(n.res.grp),a=n.pat.uuid?Object.keys(n.pat.uuid):[],s=Object.keys(n.pat.chan),u=Object.keys(n.pat.grp),c={version:n.v,timestamp:n.t,ttl:n.ttl,authorized_uuid:n.uuid},l=r.length>0,p=o.length>0,h=i.length>0;(l||p||h)&&(c.resources={},l&&(c.resources.uuids={},r.forEach((function(e){c.resources.uuids[e]=t.extractPermissions(n.res.uuid[e])}))),p&&(c.resources.channels={},o.forEach((function(e){c.resources.channels[e]=t.extractPermissions(n.res.chan[e])}))),h&&(c.resources.groups={},i.forEach((function(e){c.resources.groups[e]=t.extractPermissions(n.res.grp[e])}))));var f=a.length>0,d=s.length>0,y=u.length>0;return(f||d||y)&&(c.patterns={},f&&(c.patterns.uuids={},a.forEach((function(e){c.patterns.uuids[e]=t.extractPermissions(n.pat.uuid[e])}))),d&&(c.patterns.channels={},s.forEach((function(e){c.patterns.channels[e]=t.extractPermissions(n.pat.chan[e])}))),y&&(c.patterns.groups={},u.forEach((function(e){c.patterns.groups[e]=t.extractPermissions(n.pat.grp[e])})))),Object.keys(n.meta).length>0&&(c.meta=n.meta),c.signature=n.sig,c}},e}(),q=function(e){function n(t,n){var r=this.constructor,o=e.call(this,t)||this;return o.name=o.constructor.name,o.status=n,o.message=t,Object.setPrototypeOf(o,r.prototype),o}return t(n,e),n}(Error);function z(e){return(t={message:e}).type="validationError",t.error=!0,t;var t}function V(e,t,n){return e.usePost&&e.usePost(t,n)?e.postURL(t,n):e.usePatch&&e.usePatch(t,n)?e.patchURL(t,n):e.useGetFile&&e.useGetFile(t,n)?e.getFileURL(t,n):e.getURL(t,n)}function W(e){if(e.sdkName)return e.sdkName;var t="PubNub-JS-".concat(e.sdkFamily);e.partnerId&&(t+="-".concat(e.partnerId)),t+="/".concat(e.getVersion());var n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}function J(e,t,n){return t.usePost&&t.usePost(e,n)?"POST":t.usePatch&&t.usePatch(e,n)?"PATCH":t.useDelete&&t.useDelete(e,n)?"DELETE":t.useGetFile&&t.useGetFile(e,n)?"GETFILE":"GET"}function $(e,t,n,r,o){var i=e.config,a=e.crypto,s=J(e,o,r);n.timestamp=Math.floor((new Date).getTime()/1e3),"PNPublishOperation"===o.getOperation()&&o.usePost&&o.usePost(e,r)&&(s="GET"),"GETFILE"===s&&(s="GET");var u="".concat(s,"\n").concat(i.publishKey,"\n").concat(t,"\n").concat(j.signPamFromParams(n),"\n");if("POST"===s)u+="string"==typeof(c=o.postPayload(e,r))?c:JSON.stringify(c);else if("PATCH"===s){var c;u+="string"==typeof(c=o.patchPayload(e,r))?c:JSON.stringify(c)}var l="v2.".concat(a.HMACSHA256(u));l=(l=(l=l.replace(/\+/g,"-")).replace(/\//g,"_")).replace(/=+$/,""),n.signature=l}function Q(e,t){for(var r=[],o=2;o0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(j.encodeString(i),"/leave")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(){return{}}});var se=Object.freeze({__proto__:null,getOperation:function(){return U.PNWhereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r;return"/v2/presence/sub-key/".concat(n.subscribeKey,"/uuid/").concat(j.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return t.payload?{channels:t.payload.channels}:{channels:[]}}});var ue=Object.freeze({__proto__:null,getOperation:function(){return U.PNHeartbeatOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(j.encodeString(i),"/heartbeat")},isAuthSupported:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o=t.state,i=e.config,a={};return r.length>0&&(a["channel-group"]=r.join(",")),o&&(a.state=JSON.stringify(o)),a.heartbeat=i.getPresenceTimeout(),a},handleResponse:function(){return{}}});var ce=Object.freeze({__proto__:null,getOperation:function(){return U.PNGetStateOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r,i=t.channels,a=void 0===i?[]:i,s=a.length>0?a.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(j.encodeString(s),"/uuid/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,a=void 0===i?[]:i,s={};return 1===o.length&&0===a.length?s[o[0]]=t.payload:s=t.payload,{channels:s}}});var le=Object.freeze({__proto__:null,getOperation:function(){return U.PNSetStateOperation},validateParams:function(e,t){var n=e.config,r=t.state,o=t.channels,i=void 0===o?[]:o,a=t.channelGroups,s=void 0===a?[]:a;return r?n.subscribeKey?0===i.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key":"Missing State"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(j.encodeString(i),"/uuid/").concat(j.encodeString(n.UUID),"/data")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.state,r=t.channelGroups,o=void 0===r?[]:r,i={};return i.state=JSON.stringify(n),o.length>0&&(i["channel-group"]=o.join(",")),i},handleResponse:function(e,t){return{state:t.payload}}});var pe=Object.freeze({__proto__:null,getOperation:function(){return U.PNHereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=t.channelGroups,a=void 0===i?[]:i,s="/v2/presence/sub-key/".concat(n.subscribeKey);if(o.length>0||a.length>0){var u=o.length>0?o.join(","):",";s+="/channel/".concat(j.encodeString(u))}return s},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.channelGroups,o=void 0===r?[]:r,i=t.includeUUIDs,a=void 0===i||i,s=t.includeState,u=void 0!==s&&s,c=t.queryParameters,l=void 0===c?{}:c,p={};return a||(p.disable_uuids=1),u&&(p.state=1),o.length>0&&(p["channel-group"]=o.join(",")),p=n(n({},p),l)},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,a=void 0===i?[]:i,s=n.includeUUIDs,u=void 0===s||s,c=n.includeState,l=void 0!==c&&c;return o.length>1||a.length>0||0===a.length&&0===o.length?function(){var e={};return e.totalChannels=t.payload.total_channels,e.totalOccupancy=t.payload.total_occupancy,e.channels={},Object.keys(t.payload.channels).forEach((function(n){var r=t.payload.channels[n],o=[];return e.channels[n]={occupants:o,name:n,occupancy:r.occupancy},u&&r.uuids.forEach((function(e){l?o.push({state:e.state,uuid:e.uuid}):o.push({state:null,uuid:e})})),e})),e}():function(){var e={},n=[];return e.totalChannels=1,e.totalOccupancy=t.occupancy,e.channels={},e.channels[o[0]]={occupants:n,name:o[0],occupancy:t.occupancy},u&&t.uuids&&t.uuids.forEach((function(e){l?n.push({state:e.state,uuid:e.uuid}):n.push({state:null,uuid:e})})),e}()},handleError:function(e,t,n){402!==n.statusCode||this.getURL(e,t).includes("channel")||(n.errorData.message="You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.")}});var he=Object.freeze({__proto__:null,getOperation:function(){return U.PNAddMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.action,o=t.channel;return t.messageTimetoken?n.subscribeKey?o?r?r.value?r.type?r.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message channel":"Missing Subscribe Key":"Missing message timetoken"},usePost:function(){return!0},postURL:function(e,t){var n=e.config,r=t.channel,o=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(j.encodeString(r),"/message/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},getRequestHeaders:function(){return{"Content-Type":"application/json"}},isAuthSupported:function(){return!0},prepareParams:function(){return{}},postPayload:function(e,t){return t.action},handleResponse:function(e,t){return{data:t.data}}});var fe=Object.freeze({__proto__:null,getOperation:function(){return U.PNRemoveMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken;return t.messageTimetoken?o?n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key":"Missing action timetoken":"Missing message timetoken"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken,i=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(j.encodeString(r),"/message/").concat(i,"/action/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{data:t.data}}});var de=Object.freeze({__proto__:null,getOperation:function(){return U.PNGetMessageActionsOperation},validateParams:function(e,t){var n=e.config,r=t.channel;return n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channel;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(j.encodeString(r))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.limit,r=t.start,o=t.end,i={};return n&&(i.limit=n),r&&(i.start=r),o&&(i.end=o),i},handleResponse:function(e,t){var n={data:t.data,start:null,end:null};return n.data.length&&(n.end=n.data[n.data.length-1].actionTimetoken,n.start=n.data[0].actionTimetoken),n}}),ye={getOperation:function(){return U.PNListFilesOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel can't be empty"},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(j.encodeString(t.channel),"/files")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.limit&&(n.limit=t.limit),t.next&&(n.next=t.next),n},handleResponse:function(e,t){return{status:t.status,data:t.data,next:t.next,count:t.count}}},ge={getOperation:function(){return U.PNGenerateUploadUrlOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?void 0:"name can't be empty":"channel can't be empty"},usePost:function(){return!0},postURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(j.encodeString(t.channel),"/generate-upload-url")},postPayload:function(e,t){return{name:t.name}},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data,file_upload_request:t.file_upload_request}}},me={getOperation:function(){return U.PNPublishFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.fileId)?(null==t?void 0:t.fileName)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},getURL:function(e,t){var n=e.config,r=n.publishKey,o=n.subscribeKey,i=function(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:v(r),n=JSON.stringify(n)}return n||""}(e,{message:t.message,file:{name:t.fileName,id:t.fileId}});return"/v1/files/publish-file/".concat(r,"/").concat(o,"/0/").concat(j.encodeString(t.channel),"/0/").concat(j.encodeString(i))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.ttl&&(n.ttl=t.ttl),void 0!==t.storeInHistory&&(n.store=t.storeInHistory?"1":"0"),t.meta&&"object"==typeof t.meta&&(n.meta=JSON.stringify(t.meta)),n},handleResponse:function(e,t){return{timetoken:t[2]}}},ve=function(e){var t=function(e){var t=this,n=e.generateUploadUrl,r=e.publishFile,a=e.modules,s=a.PubNubFile,u=a.config,c=a.cryptography,l=a.cryptoModule,p=a.networking;return function(e){var a=e.channel,h=e.file,f=e.message,d=e.cipherKey,y=e.meta,g=e.ttl,m=e.storeInHistory;return o(t,void 0,void 0,(function(){var e,t,o,v,b,_,S,w,O,P,E,T,A,C,k,N,M,j,R,x,U,I,D,F,G,L,K,B,H;return i(this,(function(i){switch(i.label){case 0:if(!a)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!h)throw new q("Validation failed, check status for details",z("file can't be empty"));return e=s.create(h),[4,n({channel:a,name:e.name})];case 1:return t=i.sent(),o=t.file_upload_request,v=o.url,b=o.form_fields,_=t.data,S=_.id,w=_.name,s.supportsEncryptFile&&(d||l)?null!=d?[3,3]:[4,l.encryptFile(e,s)]:[3,6];case 2:return O=i.sent(),[3,5];case 3:return[4,c.encryptFile(d,e,s)];case 4:O=i.sent(),i.label=5;case 5:e=O,i.label=6;case 6:P=b,e.mimeType&&(P=b.map((function(t){return"Content-Type"===t.key?{key:t.key,value:e.mimeType}:t}))),i.label=7;case 7:return i.trys.push([7,21,,22]),s.supportsFileUri&&h.uri?(A=(T=p).POSTFILE,C=[v,P],[4,e.toFileUri()]):[3,10];case 8:return[4,A.apply(T,C.concat([i.sent()]))];case 9:return E=i.sent(),[3,20];case 10:return s.supportsFile?(N=(k=p).POSTFILE,M=[v,P],[4,e.toFile()]):[3,13];case 11:return[4,N.apply(k,M.concat([i.sent()]))];case 12:return E=i.sent(),[3,20];case 13:return s.supportsBuffer?(R=(j=p).POSTFILE,x=[v,P],[4,e.toBuffer()]):[3,16];case 14:return[4,R.apply(j,x.concat([i.sent()]))];case 15:return E=i.sent(),[3,20];case 16:return s.supportsBlob?(I=(U=p).POSTFILE,D=[v,P],[4,e.toBlob()]):[3,19];case 17:return[4,I.apply(U,D.concat([i.sent()]))];case 18:return E=i.sent(),[3,20];case 19:throw new Error("Unsupported environment");case 20:return[3,22];case 21:throw(F=i.sent()).response&&"string"==typeof F.response.text?(G=F.response.text,L=/(.*)<\/Message>/gi.exec(G),new q(L?"Upload to bucket failed: ".concat(L[1]):"Upload to bucket failed.",F)):new q("Upload to bucket failed.",F);case 22:if(204!==E.status)throw new q("Upload to bucket was unsuccessful",E);K=u.fileUploadPublishRetryLimit,B=!1,H={timetoken:"0"},i.label=23;case 23:return i.trys.push([23,25,,26]),[4,r({channel:a,message:f,fileId:S,fileName:w,meta:y,storeInHistory:m,ttl:g})];case 24:return H=i.sent(),B=!0,[3,26];case 25:return i.sent(),K-=1,[3,26];case 26:if(!B&&K>0)return[3,23];i.label=27;case 27:if(B)return[2,{timetoken:H.timetoken,id:S,name:w}];throw new q("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{channel:a,id:S,name:w})}}))}))}}(e);return function(e,n){var r=t(e);return"function"==typeof n?(r.then((function(e){return n(null,e)})).catch((function(e){return n(e,null)})),r):r}},be=function(e,t){var n=t.channel,r=t.id,o=t.name,i=e.config,a=e.networking,s=e.tokenManager;if(!n)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!r)throw new q("Validation failed, check status for details",z("file id can't be empty"));if(!o)throw new q("Validation failed, check status for details",z("file name can't be empty"));var u="/v1/files/".concat(i.subscribeKey,"/channels/").concat(j.encodeString(n),"/files/").concat(r,"/").concat(o),c={};c.uuid=i.getUUID(),c.pnsdk=W(i);var l=s.getToken()||i.getAuthKey();l&&(c.auth=l),i.secretKey&&$(e,u,c,{},{getOperation:function(){return"PubNubGetFileUrlOperation"}});var p=Object.keys(c).map((function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(c[e]))})).join("&");return""!==p?"".concat(a.getStandardOrigin()).concat(u,"?").concat(p):"".concat(a.getStandardOrigin()).concat(u)},_e={getOperation:function(){return U.PNDownloadFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?(null==t?void 0:t.id)?void 0:"id can't be empty":"name can't be empty":"channel can't be empty"},useGetFile:function(){return!0},getFileURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(j.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},ignoreBody:function(){return!0},forceBuffered:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t,n){var r=e.PubNubFile,a=e.config,s=e.cryptography,u=e.cryptoModule;return o(void 0,void 0,void 0,(function(){var e,o,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.response.body,r.supportsEncryptFile&&(n.cipherKey||u)?null!=n.cipherKey?[3,2]:[4,u.decryptFile(r.create({data:e,name:n.name}),r)]:[3,5];case 1:return o=i.sent().data,[3,4];case 2:return[4,s.decrypt(null!==(c=n.cipherKey)&&void 0!==c?c:a.cipherKey,e)];case 3:o=i.sent(),i.label=4;case 4:e=o,i.label=5;case 5:return[2,r.create({data:e,name:null!==(l=t.response.name)&&void 0!==l?l:n.name,mimeType:t.response.type})]}}))}))}},Se={getOperation:function(){return U.PNListFilesOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.id)?(null==t?void 0:t.name)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(j.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status}}},we={getOperation:function(){return U.PNGetAllUUIDMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,a,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(a=t.page)||void 0===a?void 0:a.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=s(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,next:t.next,prev:t.prev}}},Oe={getOperation:function(){return U.PNGetUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(j.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Pe={getOperation:function(){return U.PNSetUUIDMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.data))return"Data cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(j.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ee={getOperation:function(){return U.PNRemoveUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(j.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r=e.config;return{uuid:null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Te={getOperation:function(){return U.PNGetAllChannelMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,a,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(a=t.page)||void 0===a?void 0:a.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=s(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Ae={getOperation:function(){return U.PNGetChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(j.encodeString(t.channel))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ce={getOperation:function(){return U.PNSetChannelMetadataOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.data)?void 0:"Data cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(j.encodeString(t.channel))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},ke={getOperation:function(){return U.PNRemoveChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(j.encodeString(t.channel))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ne={getOperation:function(){return U.PNGetMembersOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(j.encodeString(t.channel),"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,a,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&m.include.push("uuid"),(null===(i=t.include)||void 0===i?void 0:i.customUUIDFields)&&m.include.push("uuid.custom"),(null===(a=t.include)||void 0===a?void 0:a.UUIDStatusField)&&m.include.push("uuid.status"),(null===(u=t.include)||void 0===u?void 0:u.UUIDTypeField)&&m.include.push("uuid.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=s(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Me={getOperation:function(){return U.PNSetMembersOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.uuids)&&0!==(null==t?void 0:t.uuids.length)?void 0:"UUIDs cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(j.encodeString(t.channel),"/uuids")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.uuids.map((function(e){return"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,a,u,c,l,p,h={include:["uuid.status","uuid.type","type"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customUUIDFields)&&h.include.push("uuid.custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&h.include.push("uuid")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(a=null==t?void 0:t.page)||void 0===a?void 0:a.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=s(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},je={getOperation:function(){return U.PNGetMembershipsOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(j.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,a,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&m.include.push("channel"),(null===(i=t.include)||void 0===i?void 0:i.customChannelFields)&&m.include.push("channel.custom"),(null===(a=t.include)||void 0===a?void 0:a.channelStatusField)&&m.include.push("channel.status"),(null===(u=t.include)||void 0===u?void 0:u.channelTypeField)&&m.include.push("channel.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=s(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Re={getOperation:function(){return U.PNSetMembershipsOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)||0===(null==t?void 0:t.channels.length))return"Channels cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(j.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.channels.map((function(e){return"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,a,u,c,l,p,h={include:["channel.status","channel.type","status"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customChannelFields)&&h.include.push("channel.custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&h.include.push("channel")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(a=null==t?void 0:t.page)||void 0===a?void 0:a.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=s(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}};var xe=Object.freeze({__proto__:null,getOperation:function(){return U.PNAccessManagerAudit},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/audit/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channel,r=t.channelGroup,o=t.authKeys,i=void 0===o?[]:o,a={};return n&&(a.channel=n),r&&(a["channel-group"]=r),i.length>0&&(a.auth=i.join(",")),a},handleResponse:function(e,t){return t.payload}});var Ue=Object.freeze({__proto__:null,getOperation:function(){return U.PNAccessManagerGrant},validateParams:function(e,t){var n=e.config;return n.subscribeKey?n.publishKey?n.secretKey?null==t.uuids||t.authKeys?null==t.uuids||null==t.channels&&null==t.channelGroups?void 0:"Both channel/channelgroup and uuid cannot be used in the same request":"authKeys are required for grant request on uuids":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/grant/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,a=t.uuids,s=void 0===a?[]:a,u=t.ttl,c=t.read,l=void 0!==c&&c,p=t.write,h=void 0!==p&&p,f=t.manage,d=void 0!==f&&f,y=t.get,g=void 0!==y&&y,m=t.join,v=void 0!==m&&m,b=t.update,_=void 0!==b&&b,S=t.authKeys,w=void 0===S?[]:S,O=t.delete,P={};return P.r=l?"1":"0",P.w=h?"1":"0",P.m=d?"1":"0",P.d=O?"1":"0",P.g=g?"1":"0",P.j=v?"1":"0",P.u=_?"1":"0",r.length>0&&(P.channel=r.join(",")),i.length>0&&(P["channel-group"]=i.join(",")),w.length>0&&(P.auth=w.join(",")),s.length>0&&(P["target-uuid"]=s.join(",")),(u||0===u)&&(P.ttl=u),P},handleResponse:function(){return{}}});function Ie(e){var t,n,r,o,i=void 0!==(null==e?void 0:e.authorizedUserId),a=void 0!==(null===(t=null==e?void 0:e.resources)||void 0===t?void 0:t.users),s=void 0!==(null===(n=null==e?void 0:e.resources)||void 0===n?void 0:n.spaces),u=void 0!==(null===(r=null==e?void 0:e.patterns)||void 0===r?void 0:r.users),c=void 0!==(null===(o=null==e?void 0:e.patterns)||void 0===o?void 0:o.spaces);return u||a||c||s||i}function De(e){var t=0;return e.join&&(t|=128),e.update&&(t|=64),e.get&&(t|=32),e.delete&&(t|=8),e.manage&&(t|=4),e.write&&(t|=2),e.read&&(t|=1),t}function Fe(e,t){if(Ie(t))return function(e,t){var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,a=t.authorizedUserId,s={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.users,c=r.spaces,l=r.groups;u&&Object.keys(u).forEach((function(e){s.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){s.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){s.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.users,h=o.spaces,f=o.groups;p&&Object.keys(p).forEach((function(e){s.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){s.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){s.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(s.ttl=n),i&&(s.permissions.meta=i),a&&(s.permissions.uuid="".concat(a)),s}(0,t);var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,a=t.authorized_uuid,s={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.uuids,c=r.channels,l=r.groups;u&&Object.keys(u).forEach((function(e){s.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){s.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){s.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.uuids,h=o.channels,f=o.groups;p&&Object.keys(p).forEach((function(e){s.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){s.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){s.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(s.ttl=n),i&&(s.permissions.meta=i),a&&(s.permissions.uuid="".concat(a)),s}var Ge=Object.freeze({__proto__:null,getOperation:function(){return U.PNAccessManagerGrantToken},extractPermissions:De,validateParams:function(e,t){var n,r,o,i,a,s,u=e.config;if(!u.subscribeKey)return"Missing Subscribe Key";if(!u.publishKey)return"Missing Publish Key";if(!u.secretKey)return"Missing Secret Key";if(!t.resources&&!t.patterns)return"Missing either Resources or Patterns.";var c=void 0!==(null==t?void 0:t.authorized_uuid),l=void 0!==(null===(n=null==t?void 0:t.resources)||void 0===n?void 0:n.uuids),p=void 0!==(null===(r=null==t?void 0:t.resources)||void 0===r?void 0:r.channels),h=void 0!==(null===(o=null==t?void 0:t.resources)||void 0===o?void 0:o.groups),f=void 0!==(null===(i=null==t?void 0:t.patterns)||void 0===i?void 0:i.uuids),d=void 0!==(null===(a=null==t?void 0:t.patterns)||void 0===a?void 0:a.channels),y=void 0!==(null===(s=null==t?void 0:t.patterns)||void 0===s?void 0:s.groups),g=c||l||f||p||d||h||y;return Ie(t)&&g?"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`":(!t.resources||t.resources.uuids&&0!==Object.keys(t.resources.uuids).length||t.resources.channels&&0!==Object.keys(t.resources.channels).length||t.resources.groups&&0!==Object.keys(t.resources.groups).length||t.resources.users&&0!==Object.keys(t.resources.users).length||t.resources.spaces&&0!==Object.keys(t.resources.spaces).length)&&(!t.patterns||t.patterns.uuids&&0!==Object.keys(t.patterns.uuids).length||t.patterns.channels&&0!==Object.keys(t.patterns.channels).length||t.patterns.groups&&0!==Object.keys(t.patterns.groups).length||t.patterns.users&&0!==Object.keys(t.patterns.users).length||t.patterns.spaces&&0!==Object.keys(t.patterns.spaces).length)?void 0:"Missing values for either Resources or Patterns."},postURL:function(e){var t=e.config;return"/v3/pam/".concat(t.subscribeKey,"/grant")},usePost:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(){return{}},postPayload:function(e,t){return Fe(0,t)},handleResponse:function(e,t){return t.data.token}}),Le={getOperation:function(){return U.PNAccessManagerRevokeToken},validateParams:function(e,t){return e.config.secretKey?t?void 0:"token can't be empty":"Missing Secret Key"},getURL:function(e,t){var n=e.config;return"/v3/pam/".concat(n.subscribeKey,"/grant/").concat(j.encodeString(t))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e){return{uuid:e.config.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}};function Ke(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:v(r),n=JSON.stringify(n)}return n||""}var Be=Object.freeze({__proto__:null,getOperation:function(){return U.PNPublishOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},usePost:function(e,t){var n=t.sendByPost;return void 0!==n&&n},getURL:function(e,t){var n=e.config,r=t.channel,o=Ke(e,t.message);return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(j.encodeString(r),"/0/").concat(j.encodeString(o))},postURL:function(e,t){var n=e.config,r=t.channel;return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(j.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},postPayload:function(e,t){return Ke(e,t.message)},prepareParams:function(e,t){var n=t.meta,r=t.replicate,o=void 0===r||r,i=t.storeInHistory,a=t.ttl,s={};return null!=i&&(s.store=i?"1":"0"),a&&(s.ttl=a),!1===o&&(s.norep="true"),n&&"object"==typeof n&&(s.meta=JSON.stringify(n)),s},handleResponse:function(e,t){return{timetoken:t[2]}}});var He=Object.freeze({__proto__:null,getOperation:function(){return U.PNSignalOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},getURL:function(e,t){var n,r=e.config,o=t.channel,i=t.message,a=(n=i,JSON.stringify(n));return"/signal/".concat(r.publishKey,"/").concat(r.subscribeKey,"/0/").concat(j.encodeString(o),"/0/").concat(j.encodeString(a))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{timetoken:t[2]}}});var qe=Object.freeze({__proto__:null,getOperation:function(){return U.PNHistoryOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channel,r=e.config;return"/v2/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(j.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o=t.reverse,i=t.count,a=void 0===i?100:i,s=t.stringifiedTimeToken,u=void 0!==s&&s,c=t.includeMeta,l=void 0!==c&&c,p={include_token:"true"};return p.count=a,n&&(p.start=n),r&&(p.end=r),u&&(p.string_message_token="true"),null!=o&&(p.reverse=o.toString()),l&&(p.include_meta="true"),p},handleResponse:function(e,t){var n={messages:[],startTimeToken:t[1],endTimeToken:t[2]};return Array.isArray(t[0])&&t[0].forEach((function(t){var r=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message),o={timetoken:t.timetoken,entry:r.payload};t.meta&&(o.meta=t.meta),r.error&&(o.error=r.error),n.messages.push(o)})),n}});var ze=Object.freeze({__proto__:null,getOperation:function(){return U.PNDeleteMessagesOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},useDelete:function(){return!0},getURL:function(e,t){var n=t.channel,r=e.config;return"/v3/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(j.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o={};return n&&(o.start=n),r&&(o.end=r),o},handleResponse:function(e,t){return t.payload}});var Ve=Object.freeze({__proto__:null,getOperation:function(){return U.PNMessageCounts},validateParams:function(e,t){var n=t.channels,r=t.timetoken,o=t.channelTimetokens,i=e.config;return n?r&&o?"timetoken and channelTimetokens are incompatible together":o&&o.length>1&&n.length!==o.length?"Length of channelTimetokens and channels do not match":i.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channels,r=e.config,o=n.join(",");return"/v3/history/sub-key/".concat(r.subscribeKey,"/message-counts/").concat(j.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.timetoken,r=t.channelTimetokens,o={};if(r&&1===r.length){var i=s(r,1)[0];o.timetoken=i}else r?o.channelsTimetoken=r.join(","):n&&(o.timetoken=n);return o},handleResponse:function(e,t){return{channels:t.channels}}});var We=Object.freeze({__proto__:null,getOperation:function(){return U.PNFetchMessagesOperation},validateParams:function(e,t){var n=t.channels,r=t.includeMessageActions,o=void 0!==r&&r,i=e.config;if(!n||0===n.length)return"Missing channels";if(!i.subscribeKey)return"Missing Subscribe Key";if(o&&n.length>1)throw new TypeError("History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.")},getURL:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.includeMessageActions,i=void 0!==o&&o,a=e.config,s=i?"history-with-actions":"history",u=r.length>0?r.join(","):",";return"/v3/".concat(s,"/sub-key/").concat(a.subscribeKey,"/channel/").concat(j.encodeString(u))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channels,r=t.start,o=t.end,i=t.includeMessageActions,a=t.count,s=t.stringifiedTimeToken,u=void 0!==s&&s,c=t.includeMeta,l=void 0!==c&&c,p=t.includeUuid,h=t.includeUUID,f=void 0===h||h,d=t.includeMessageType,y=void 0===d||d,g={};return g.max=a||(n.length>1||!0===i?25:100),r&&(g.start=r),o&&(g.end=o),u&&(g.string_message_token="true"),l&&(g.include_meta="true"),f&&!1!==p&&(g.include_uuid="true"),y&&(g.include_message_type="true"),g},handleResponse:function(e,t){var n={channels:{}};return Object.keys(t.channels||{}).forEach((function(r){n.channels[r]=[],(t.channels[r]||[]).forEach((function(t){var o={},i=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message);o.channel=r,o.timetoken=t.timetoken,o.message=i.payload,o.messageType=t.message_type,o.uuid=t.uuid,t.actions&&(o.actions=t.actions,o.data=t.actions),t.meta&&(o.meta=t.meta),i.error&&(o.error=i.error),n.channels[r].push(o)}))})),t.more&&(n.more=t.more),n}});var Je=Object.freeze({__proto__:null,getOperation:function(){return U.PNTimeOperation},getURL:function(){return"/time/0"},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(){return{}},isAuthSupported:function(){return!1},handleResponse:function(e,t){return{timetoken:t[0]}},validateParams:function(){}});var $e=Object.freeze({__proto__:null,getOperation:function(){return U.PNSubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(j.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=e.config,r=t.state,o=t.channelGroups,i=void 0===o?[]:o,a=t.timetoken,s=t.filterExpression,u=t.region,c={heartbeat:n.getPresenceTimeout()};return i.length>0&&(c["channel-group"]=i.join(",")),s&&s.length>0&&(c["filter-expr"]=s),Object.keys(r).length&&(c.state=JSON.stringify(r)),a&&(c.tt=a),u&&(c.tr=u),c},handleResponse:function(e,t){var n=[];t.m.forEach((function(e){var t={publishTimetoken:e.p.t,region:e.p.r},r={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:t};n.push(r)}));var r={timetoken:t.t.t,region:t.t.r};return{messages:n,metadata:r}}}),Qe={getOperation:function(){return U.PNHandshakeOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)&&!(null==t?void 0:t.channelGroups))return"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels?t.channels.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(j.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),n.tt=0,t.state&&(n.state=JSON.stringify(t.state)),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.ee="",n},handleResponse:function(e,t){return{region:t.t.r,timetoken:t.t.t}}},Xe={getOperation:function(){return U.PNReceiveMessagesOperation},validateParams:function(e,t){return(null==t?void 0:t.channels)||(null==t?void 0:t.channelGroups)?(null==t?void 0:t.timetoken)?(null==t?void 0:t.region)?void 0:"region can not be empty":"timetoken can not be empty":"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels?t.channels.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(j.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},getAbortSignal:function(e,t){return t.abortSignal},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.tt=t.timetoken,n.tr=t.region,n.ee="",n},handleResponse:function(e,t){var n=[];return t.m.forEach((function(e){var t={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,publishMetaData:{timetoken:e.p.t,region:e.p.r}};n.push(t)})),{messages:n,metadata:{region:t.t.r,timetoken:t.t.t}}}},Ye=function(){function e(e){void 0===e&&(e=!1),this.sync=e,this.listeners=new Set}return e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.notify=function(e){var t=this,n=function(){t.listeners.forEach((function(t){t(e)}))};this.sync?n():setTimeout(n,0)},e}(),Ze=function(){function e(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}return e.prototype.transition=function(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)},e.prototype.on=function(e,t){return this.transitionMap.set(e,t),this},e.prototype.with=function(e,t){return[this,e,null!=t?t:[]]},e.prototype.onEnter=function(e){return this.enterEffects.push(e),this},e.prototype.onExit=function(e){return this.exitEffects.push(e),this},e}(),et=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return t(n,e),n.prototype.describe=function(e){return new Ze(e)},n.prototype.start=function(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})},n.prototype.transition=function(e){var t,n,r,o,i,u;if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});var c=this.currentState.transition(this.currentContext,e);if(c){var l=s(c,3),p=l[0],h=l[1],f=l[2];try{for(var d=a(this.currentState.exitEffects),y=d.next();!y.done;y=d.next()){var g=y.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}var m=this.currentState;this.currentState=p;var v=this.currentContext;this.currentContext=h,this.notify({type:"transitionDone",fromState:m,fromContext:v,toState:p,toContext:h,event:e});try{for(var b=a(f),_=b.next();!_.done;_=b.next()){g=_.value;this.notify({type:"invocationDispatched",invocation:g})}}catch(e){r={error:e}}finally{try{_&&!_.done&&(o=b.return)&&o.call(b)}finally{if(r)throw r.error}}try{for(var S=a(this.currentState.enterEffects),w=S.next();!w.done;w=S.next()){g=w.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){i={error:e}}finally{try{w&&!w.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}},n}(Ye),tt=function(){function e(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}return e.prototype.on=function(e,t){this.handlers.set(e,t)},e.prototype.dispatch=function(e){if("CANCEL"!==e.type){var t=this.handlers.get(e.type);if(!t)throw new Error("Unhandled invocation '".concat(e.type,"'"));var n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}else if(this.instances.has(e.payload)){var r=this.instances.get(e.payload);null==r||r.cancel(),this.instances.delete(e.payload)}},e.prototype.dispose=function(){var e,t;try{for(var n=a(this.instances.entries()),r=n.next();!r.done;r=n.next()){var o=s(r.value,2),i=o[0];o[1].cancel(),this.instances.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();function nt(e,t){var n=function(){for(var n=[],r=0;r0&&r(e),[2]}))}))}))),a.on(ht.type,ut((function(e,t,n){var r=n.emitStatus;return o(a,void 0,void 0,(function(){return i(this,(function(t){return r(e),[2]}))}))}))),a.on(ft.type,ut((function(e,n,r){var s=r.receiveMessages,u=r.delay,c=r.config;return o(a,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return c.retryConfiguration&&c.retryConfiguration.shouldRetry(e.reason,e.attempts)?(n.throwIfAborted(),[4,u(c.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),n.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,s({abortSignal:n,channels:e.channels,channelGroups:e.groups,timetoken:e.cursor.timetoken,region:e.cursor.region,filterExpression:c.filterExpression})];case 3:return r=i.sent(),[2,t.transition(Pt(r.metadata,r.messages))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Et(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Tt(new q(c.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),a.on(dt.type,ut((function(e,r,s){var u=s.handshake,c=s.delay,l=s.presenceState,p=s.config;return o(a,void 0,void 0,(function(){var o,a;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({abortSignal:r,channels:e.channels,channelGroups:e.groups,filterExpression:p.filterExpression},p.maintainPresenceState&&{state:l}))];case 3:return o=i.sent(),[2,t.transition(bt(o))];case 4:return(a=i.sent())instanceof Error&&"Aborted"===a.message?[2]:a instanceof q?[2,t.transition(_t(a))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(St(new q(p.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),a}return t(r,e),r}(tt),Mt=new Ze("HANDSHAKE_FAILED");Mt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Mt.on(Ct.type,(function(e,t){return Ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor})})),Mt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(r=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==r?r:0}})})),Mt.on(kt.type,(function(e){return Gt.with()}));var jt=new Ze("HANDSHAKE_STOPPED");jt.on(yt.type,(function(e,t){return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),jt.on(Ct.type,(function(e,t){return Ft.with(n(n({},e),{cursor:t.payload.cursor||e.cursor}))})),jt.on(gt.type,(function(e,t){var n;return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),jt.on(kt.type,(function(e){return Gt.with()}));var Rt=new Ze("RECEIVE_FAILED");Rt.on(Ct.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Rt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(kt.type,(function(e){return Gt.with(void 0)}));var xt=new Ze("RECEIVE_STOPPED");xt.on(yt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),xt.on(gt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Ct.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(kt.type,(function(){return Gt.with(void 0)}));var Ut=new Ze("RECEIVE_RECONNECTING");Ut.onEnter((function(e){return ft(e)})),Ut.onExit((function(){return ft.cancel})),Ut.on(Pt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),Ut.on(Et.type,(function(e,t){return Ut.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Ut.on(Tt.type,(function(e,t){var n;return Rt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:R.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Ut.on(At.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:R.PNDisconnectedCategory})])})),Ut.on(gt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Ut.on(yt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ut.on(kt.type,(function(e){return Gt.with(void 0,[ht({category:R.PNDisconnectedCategory})])}));var It=new Ze("RECEIVING");It.onEnter((function(e){return lt(e.channels,e.groups,e.cursor)})),It.onExit((function(){return lt.cancel})),It.on(wt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),It.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Gt.with(void 0):It.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups})})),It.on(gt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Gt.with(void 0):It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),It.on(Ot.type,(function(e,t){return Ut.with(n(n({},e),{attempts:0,reason:t.payload}))})),It.on(At.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:R.PNDisconnectedCategory})])})),It.on(kt.type,(function(e){return Gt.with(void 0,[ht({category:R.PNDisconnectedCategory})])}));var Dt=new Ze("HANDSHAKE_RECONNECTING");Dt.onEnter((function(e){return dt(e)})),Dt.onExit((function(){return dt.cancel})),Dt.on(bt.type,(function(e,t){var n,r,o={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=e.cursor)||void 0===r?void 0:r.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return It.with({channels:e.channels,groups:e.groups,cursor:o},[ht({category:R.PNConnectedCategory})])})),Dt.on(_t.type,(function(e,t){return Dt.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Dt.on(St.type,(function(e,t){var n;return Mt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:R.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Dt.on(At.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Dt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Dt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.region)||0}})})),Dt.on(kt.type,(function(e){return Gt.with(void 0)}));var Ft=new Ze("HANDSHAKING");Ft.onEnter((function(e){return ct(e.channels,e.groups)})),Ft.onExit((function(){return ct.cancel})),Ft.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Gt.with(void 0):Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ft.on(mt.type,(function(e,t){var n,r;return It.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.timetoken:t.payload.timetoken,region:t.payload.region}},[ht({category:R.PNConnectedCategory})])})),Ft.on(vt.type,(function(e,t){return Dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload})})),Ft.on(At.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Ft.on(gt.type,(function(e,t){var n;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),Ft.on(kt.type,(function(e){return Gt.with()}));var Gt=new Ze("UNSUBSCRIBED");Gt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups})})),Gt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})}));var Lt=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new Nt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(Gt,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e){var t=this,n=e.channels,r=e.channelGroups,o=e.timetoken,i=e.withPresence;this.channels=u(u([],s(this.channels),!1),s(null!=n?n:[]),!1),this.groups=u(u([],s(this.groups),!1),s(null!=r?r:[]),!1),i&&(this.channels.map((function(e){return t.channels.push("".concat(e,"-pnpres"))})),this.groups.map((function(e){return t.groups.push("".concat(e,"-pnpres"))}))),o?this.engine.transition(gt(this.channels,this.groups,o)):this.engine.transition(yt(this.channels,this.groups)),this.dependencies.join&&this.dependencies.join({channels:this.channels.filter((function(e){return!e.endsWith("-pnpres")})),groups:this.groups.filter((function(e){return!e.endsWith("-pnpres")}))})},e.prototype.unsubscribe=function(e){var t=this,n=e.channels,r=e.groups,o=null==n?void 0:n.slice(0);null==n||n.map((function(e){return o.push("".concat(e,"-pnpres"))})),this.channels=this.channels.filter((function(e){return!(null==o?void 0:o.includes(e))}));var i=null==r?void 0:r.slice(0);null==r||r.map((function(e){return i.push("".concat(e,"-pnpres"))})),this.groups=this.groups.filter((function(e){return!(null==i?void 0:i.includes(e))})),this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leave&&this.dependencies.leave({channels:n,groups:r})},e.prototype.unsubscribeAll=function(){this.channels=[],this.groups=[],this.dependencies.presenceState&&(this.dependencies.presenceState={}),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.reconnect=function(e){var t=e.timetoken,n=e.region;this.engine.transition(Ct(t,n))},e.prototype.disconnect=function(){this.engine.transition(At()),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.getSubscribedChannels=function(){return this.channels.slice(0)},e.prototype.getSubscribedChannelGroups=function(){return this.groups.slice(0)},e.prototype.dispose=function(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),Kt=nt("RECONNECT",(function(){return{}})),Bt=nt("DISCONNECT",(function(){return{}})),Ht=nt("JOINED",(function(e,t){return{channels:e,groups:t}})),qt=nt("LEFT",(function(e,t){return{channels:e,groups:t}})),zt=nt("LEFT_ALL",(function(){return{}})),Vt=nt("HEARTBEAT_SUCCESS",(function(e){return{statusCode:e}})),Wt=nt("HEARTBEAT_FAILURE",(function(e){return e})),Jt=nt("HEARTBEAT_GIVEUP",(function(){return{}})),$t=nt("TIMES_UP",(function(){return{}})),Qt=rt("HEARTBEAT",(function(e,t){return{channels:e,groups:t}})),Xt=rt("LEAVE",(function(e,t){return{channels:e,groups:t}})),Yt=rt("EMIT_STATUS",(function(e){return e})),Zt=ot("WAIT",(function(){return{}})),en=ot("DELAYED_HEARTBEAT",(function(e){return e})),tn=function(e){function r(t,r){var a=e.call(this,r)||this;return a.on(Qt.type,ut((function(e,r,s){var u=s.heartbeat,c=s.presenceState,l=s.config;return o(a,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,u(n({channels:e.channels,channelGroups:e.groups},l.maintainPresenceState&&{state:c}))];case 1:return o.sent(),t.transition(Vt(200)),[3,3];case 2:return(r=o.sent())instanceof q?[2,t.transition(Wt(r))]:[3,3];case 3:return[2]}}))}))}))),a.on(Xt.type,ut((function(e,t,n){var r=n.leave,s=n.config;return o(a,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:if(s.suppressLeaveEvents)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r({channels:e.channels,channelGroups:e.groups})];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}}))}))}))),a.on(Zt.type,ut((function(e,n,r){var s=r.heartbeatDelay;return o(a,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return n.throwIfAborted(),[4,s()];case 1:return e.sent(),n.throwIfAborted(),[2,t.transition($t())]}}))}))}))),a.on(en.type,ut((function(e,r,s){var u=s.heartbeat,c=s.retryDelay,l=s.presenceState,p=s.config;return o(a,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({channels:e.channels,channelGroups:e.groups},p.maintainPresenceState&&{state:l}))];case 3:return i.sent(),[2,t.transition(Vt(200))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Wt(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Jt())];case 7:return[2]}}))}))}))),a.on(Yt.type,ut((function(e,t,r){var s=r.emitStatus,u=r.config;return o(a,void 0,void 0,(function(){var t;return i(this,(function(r){return u.announceFailedHeartbeats&&!0===(null===(t=null==e?void 0:e.status)||void 0===t?void 0:t.error)?s(e.status):u.announceSuccessfulHeartbeats&&200===e.statusCode&&s(n(n({},e),{operation:U.PNHeartbeatOperation,error:!1})),[2]}))}))}))),a}return t(r,e),r}(tt),nn=new Ze("HEARTBEAT_STOPPED");nn.on(Ht.type,(function(e,t){return nn.with({channels:u(u([],s(e.channels),!1),s(t.payload.channels),!1),groups:u(u([],s(e.groups),!1),s(t.payload.groups),!1)})})),nn.on(qt.type,(function(e,t){return nn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))})})),nn.on(Kt.type,(function(e,t){return sn.with({channels:e.channels,groups:e.groups})})),nn.on(zt.type,(function(e,t){return un.with(void 0)}));var rn=new Ze("HEARTBEAT_COOLDOWN");rn.onEnter((function(){return Zt()})),rn.onExit((function(){return Zt.cancel})),rn.on($t.type,(function(e,t){return sn.with({channels:e.channels,groups:e.groups})})),rn.on(Ht.type,(function(e,t){return sn.with({channels:u(u([],s(e.channels),!1),s(t.payload.channels),!1),groups:u(u([],s(e.groups),!1),s(t.payload.groups),!1)})})),rn.on(qt.type,(function(e,t){return sn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),rn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),rn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var on=new Ze("HEARTBEAT_FAILED");on.on(Ht.type,(function(e,t){return sn.with({channels:u(u([],s(e.channels),!1),s(t.payload.channels),!1),groups:u(u([],s(e.groups),!1),s(t.payload.groups),!1)})})),on.on(qt.type,(function(e,t){return sn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),on.on(Kt.type,(function(e,t){return sn.with({channels:e.channels,groups:e.groups})})),on.on(Bt.type,(function(e,t){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),on.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var an=new Ze("HEARBEAT_RECONNECTING");an.onEnter((function(e){return en(e)})),an.onExit((function(){return en.cancel})),an.on(Ht.type,(function(e,t){return sn.with({channels:u(u([],s(e.channels),!1),s(t.payload.channels),!1),groups:u(u([],s(e.groups),!1),s(t.payload.groups),!1)})})),an.on(qt.type,(function(e,t){return sn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),an.on(Bt.type,(function(e,t){nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),an.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),an.on(Wt.type,(function(e,t){return an.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),an.on(Jt.type,(function(e,t){return on.with({channels:e.channels,groups:e.groups})})),an.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var sn=new Ze("HEARTBEATING");sn.onEnter((function(e){return Qt(e.channels,e.groups)})),sn.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),sn.on(Ht.type,(function(e,t){return sn.with({channels:u(u([],s(e.channels),!1),s(t.payload.channels),!1),groups:u(u([],s(e.groups),!1),s(t.payload.groups),!1)})})),sn.on(qt.type,(function(e,t){return sn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),sn.on(Wt.type,(function(e,t){return an.with(n(n({},e),{attempts:0,reason:t.payload}))})),sn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),sn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var un=new Ze("HEARTBEAT_INACTIVE");un.on(Ht.type,(function(e,t){return sn.with({channels:t.payload.channels,groups:t.payload.groups})}));var cn=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dispatcher=new tn(this.engine,e),this.dependencies=e,this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(un,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.join=function(e){var t=e.channels,n=e.groups;this.channels=u(u([],s(this.channels),!1),s(null!=t?t:[]),!1),this.groups=u(u([],s(this.groups),!1),s(null!=n?n:[]),!1),this.engine.transition(Ht(this.channels.slice(0),this.groups.slice(0)))},e.prototype.leave=function(e){var t=this,n=e.channels,r=e.groups;this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(qt(null!=n?n:[],null!=r?r:[]))},e.prototype.leaveAll=function(){this.engine.transition(zt())},e.prototype.dispose=function(){this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),ln=function(){function e(){}return e.LinearRetryPolicy=function(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e.ExponentialRetryPolicy=function(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e}(),pn=function(){function e(e){var t=e.modules,n=e.listenerManager,r=e.getFileUrl;this.modules=t,this.listenerManager=n,this.getFileUrl=r,t.cryptoModule&&(this._decoder=new TextDecoder)}return e.prototype.emitEvent=function(e){var t=e.channel,o=e.publishMetaData,i=e.subscriptionMatch;if(t===i&&(i=null),e.channel.endsWith("-pnpres")){var a={channel:null,subscription:null};t&&(a.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(a.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),a.action=e.payload.action,a.state=e.payload.data,a.timetoken=o.publishTimetoken,a.occupancy=e.payload.occupancy,a.uuid=e.payload.uuid,a.timestamp=e.payload.timestamp,e.payload.join&&(a.join=e.payload.join),e.payload.leave&&(a.leave=e.payload.leave),e.payload.timeout&&(a.timeout=e.payload.timeout),this.listenerManager.announcePresence(a)}else if(1===e.messageType){(a={channel:null,subscription:null}).channel=t,a.subscription=i,a.timetoken=o.publishTimetoken,a.publisher=e.issuingClientId,e.userMetadata&&(a.userMetadata=e.userMetadata),a.message=e.payload,this.listenerManager.announceSignal(a)}else if(2===e.messageType){if((a={channel:null,subscription:null}).channel=t,a.subscription=i,a.timetoken=o.publishTimetoken,a.publisher=e.issuingClientId,e.userMetadata&&(a.userMetadata=e.userMetadata),a.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},this.listenerManager.announceObjects(a),"uuid"===e.payload.type){var s=this._renameChannelField(a);this.listenerManager.announceUser(n(n({},s),{message:n(n({},s.message),{event:this._renameEvent(s.message.event),type:"user"})}))}else if("channel"===message.payload.type){s=this._renameChannelField(a);this.listenerManager.announceSpace(n(n({},s),{message:n(n({},s.message),{event:this._renameEvent(s.message.event),type:"space"})}))}else if("membership"===message.payload.type){var u=(s=this._renameChannelField(a)).message.data,c=u.uuid,l=u.channel,p=r(u,["uuid","channel"]);p.user=c,p.space=l,this.listenerManager.announceMembership(n(n({},s),{message:n(n({},s.message),{event:this._renameEvent(s.message.event),data:p})}))}}else if(3===e.messageType){(a={}).channel=t,a.subscription=i,a.timetoken=o.publishTimetoken,a.publisher=e.issuingClientId,a.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},a.event=e.payload.event,this.listenerManager.announceMessageAction(a)}else if(4===e.messageType){(a={}).channel=t,a.subscription=i,a.timetoken=o.publishTimetoken,a.publisher=e.issuingClientId;var h=e.payload;if(this.modules.cryptoModule){var f=void 0;try{f=(d=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(d)):d}catch(e){f=null,a.error="Error while decrypting message content: ".concat(e.message)}null!==f&&(h=f)}e.userMetadata&&(a.userMetadata=e.userMetadata),a.message=h.message,a.file={id:h.file.id,name:h.file.name,url:this.getFileUrl({id:h.file.id,name:h.file.name,channel:t})},this.listenerManager.announceFile(a)}else{if((a={channel:null,subscription:null}).channel=t,a.subscription=i,a.timetoken=o.publishTimetoken,a.publisher=e.issuingClientId,e.userMetadata&&(a.userMetadata=e.userMetadata),this.modules.cryptoModule){f=void 0;try{var d;f=(d=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(d)):d}catch(e){f=null,a.error="Error while decrypting message content: ".concat(e.message)}a.message=null!=f?f:e.payload}else a.message=e.payload;this.listenerManager.announceMessage(a)}},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),hn=function(){function e(e){var t=this,r=e.networking,o=e.cbor,i=new g({setup:e});this._config=i;var c=new A({config:i}),l=e.cryptography;r.init(i);var p=new H(i,o);this._tokenManager=p;var h=new I({maximumSamplesCount:6e4});this._telemetryManager=h;var f=this._config.cryptoModule,d={config:i,networking:r,crypto:c,cryptography:l,tokenManager:p,telemetryManager:h,PubNubFile:e.PubNubFile,cryptoModule:f};this.File=e.PubNubFile,this.encryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.encryptFile(t,this.File)):l.encryptFile(e,t,this.File)},this.decryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.decryptFile(t,this.File)):l.decryptFile(e,t,this.File)};var y=Q.bind(this,d,Je),m=Q.bind(this,d,ae),b=Q.bind(this,d,ue),_=Q.bind(this,d,le),S=Q.bind(this,d,$e),w=new B;if(this._listenerManager=w,this.iAmHere=Q.bind(this,d,ue),this.iAmAway=Q.bind(this,d,ae),this.setPresenceState=Q.bind(this,d,le),this.handshake=Q.bind(this,d,Qe),this.receiveMessages=Q.bind(this,d,Xe),!0===i.enableEventEngine){if(this._eventEmitter=new pn({modules:d,listenerManager:this._listenerManager,getFileUrl:function(e){return be(d,e)}}),i.maintainPresenceState&&(this.presenceState={},this.setState=function(e){var n,r;return null===(n=e.channels)||void 0===n||n.forEach((function(n){return t.presenceState[n]=e.state})),null===(r=e.channelGroups)||void 0===r||r.forEach((function(n){return t.presenceState[n]=e.state})),t.setPresenceState({channels:e.channels,channelGroups:e.channelGroups,state:t.presenceState})}),i.getHeartbeatInterval()){var O=new cn({heartbeat:this.iAmHere,leave:this.iAmAway,heartbeatDelay:function(){return new Promise((function(e){return setTimeout(e,1e3*d.config.getHeartbeatInterval())}))},retryDelay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},config:d.config,presenceState:this.presenceState,emitStatus:function(e){w.announceStatus(e)}});this.presenceEventEngine=O,this.join=this.presenceEventEngine.join.bind(O),this.leave=this.presenceEventEngine.leave.bind(O),this.leaveAll=this.presenceEventEngine.leaveAll.bind(O)}var P=new Lt({handshake:this.handshake,receiveMessages:this.receiveMessages,delay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},join:this.join,leave:this.leave,leaveAll:this.leaveAll,presenceState:this.presenceState,config:d.config,emitMessages:function(e){var n,r;try{for(var o=a(e),i=o.next();!i.done;i=o.next()){var s=i.value;t._eventEmitter.emitEvent(s)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},emitStatus:function(e){w.announceStatus(e)}});this.subscribe=P.subscribe.bind(P),this.unsubscribe=P.unsubscribe.bind(P),this.unsubscribeAll=P.unsubscribeAll.bind(P),this.reconnect=P.reconnect.bind(P),this.disconnect=P.disconnect.bind(P),this.destroy=P.dispose.bind(P),this.getSubscribedChannels=P.getSubscribedChannels.bind(P),this.getSubscribedChannelGroups=P.getSubscribedChannelGroups.bind(P),this.eventEngine=P}else{var E=new x({timeEndpoint:y,leaveEndpoint:m,heartbeatEndpoint:b,setStateEndpoint:_,subscribeEndpoint:S,crypto:d.crypto,config:d.config,listenerManager:w,getFileUrl:function(e){return be(d,e)},cryptoModule:d.cryptoModule});this.subscribe=E.adaptSubscribeChange.bind(E),this.unsubscribe=E.adaptUnsubscribeChange.bind(E),this.disconnect=E.disconnect.bind(E),this.reconnect=E.reconnect.bind(E),this.unsubscribeAll=E.unsubscribeAll.bind(E),this.getSubscribedChannels=E.getSubscribedChannels.bind(E),this.getSubscribedChannelGroups=E.getSubscribedChannelGroups.bind(E),this.setState=E.adaptStateChange.bind(E),this.presence=E.adaptPresenceChange.bind(E),this.destroy=function(e){E.unsubscribeAll(e),E.disconnect()}}this.addListener=w.addListener.bind(w),this.removeListener=w.removeListener.bind(w),this.removeAllListeners=w.removeAllListeners.bind(w),this.parseToken=p.parseToken.bind(p),this.setToken=p.setToken.bind(p),this.getToken=p.getToken.bind(p),this.channelGroups={listGroups:Q.bind(this,d,ee),listChannels:Q.bind(this,d,te),addChannels:Q.bind(this,d,X),removeChannels:Q.bind(this,d,Y),deleteGroup:Q.bind(this,d,Z)},this.push={addChannels:Q.bind(this,d,ne),removeChannels:Q.bind(this,d,re),deleteDevice:Q.bind(this,d,ie),listChannels:Q.bind(this,d,oe)},this.hereNow=Q.bind(this,d,pe),this.whereNow=Q.bind(this,d,se),this.getState=Q.bind(this,d,ce),this.grant=Q.bind(this,d,Ue),this.grantToken=Q.bind(this,d,Ge),this.audit=Q.bind(this,d,xe),this.revokeToken=Q.bind(this,d,Le),this.publish=Q.bind(this,d,Be),this.fire=function(e,n){return e.replicate=!1,e.storeInHistory=!1,t.publish(e,n)},this.signal=Q.bind(this,d,He),this.history=Q.bind(this,d,qe),this.deleteMessages=Q.bind(this,d,ze),this.messageCounts=Q.bind(this,d,Ve),this.fetchMessages=Q.bind(this,d,We),this.addMessageAction=Q.bind(this,d,he),this.removeMessageAction=Q.bind(this,d,fe),this.getMessageActions=Q.bind(this,d,de),this.listFiles=Q.bind(this,d,ye);var T=Q.bind(this,d,ge);this.publishFile=Q.bind(this,d,me),this.sendFile=ve({generateUploadUrl:T,publishFile:this.publishFile,modules:d}),this.getFileUrl=function(e){return be(d,e)},this.downloadFile=Q.bind(this,d,_e),this.deleteFile=Q.bind(this,d,Se),this.objects={getAllUUIDMetadata:Q.bind(this,d,we),getUUIDMetadata:Q.bind(this,d,Oe),setUUIDMetadata:Q.bind(this,d,Pe),removeUUIDMetadata:Q.bind(this,d,Ee),getAllChannelMetadata:Q.bind(this,d,Te),getChannelMetadata:Q.bind(this,d,Ae),setChannelMetadata:Q.bind(this,d,Ce),removeChannelMetadata:Q.bind(this,d,ke),getChannelMembers:Q.bind(this,d,Ne),setChannelMembers:function(e){for(var r=[],o=1;o=this._config.origin.length&&(this._currentSubDomain=0);var t=this._config.origin[this._currentSubDomain];return"".concat(e).concat(t)},e.prototype.hasModule=function(e){return e in this._modules},e.prototype.shiftStandardOrigin=function(){return this._standardOrigin=this.nextOrigin(),this._standardOrigin},e.prototype.getStandardOrigin=function(){return this._standardOrigin},e.prototype.POSTFILE=function(e,t,n){return this._modules.postfile(e,t,n)},e.prototype.GETFILE=function(e,t,n){return this._modules.getfile(e,t,n)},e.prototype.POST=function(e,t,n,r){return this._modules.post(e,t,n,r)},e.prototype.PATCH=function(e,t,n,r){return this._modules.patch(e,t,n,r)},e.prototype.GET=function(e,t,n){return this._modules.get(e,t,n)},e.prototype.DELETE=function(e,t,n){return this._modules.del(e,t,n)},e.prototype._detectErrorCategory=function(e){if("ENOTFOUND"===e.code)return R.PNNetworkIssuesCategory;if("ECONNREFUSED"===e.code)return R.PNNetworkIssuesCategory;if("ECONNRESET"===e.code)return R.PNNetworkIssuesCategory;if("EAI_AGAIN"===e.code)return R.PNNetworkIssuesCategory;if(0===e.status||e.hasOwnProperty("status")&&void 0===e.status)return R.PNNetworkIssuesCategory;if(e.timeout)return R.PNTimeoutCategory;if("ETIMEDOUT"===e.code)return R.PNNetworkIssuesCategory;if(e.response){if(e.response.badRequest)return R.PNBadRequestCategory;if(e.response.forbidden)return R.PNAccessDeniedCategory}return R.PNUnknownCategory},e}();function dn(e){var t=function(e){return e&&"object"==typeof e&&e.constructor===Object};if(!t(e))return e;var n={};return Object.keys(e).forEach((function(r){var o=function(e){return"string"==typeof e||e instanceof String}(r),i=r,a=e[r];Array.isArray(r)||o&&r.indexOf(",")>=0?i=(o?r.split(","):r).reduce((function(e,t){return e+=String.fromCharCode(t)}),""):(function(e){return"number"==typeof e&&isFinite(e)}(r)||o&&!isNaN(r))&&(i=String.fromCharCode(o?parseInt(r,10):10));n[i]=t(a)?dn(a):a})),n}var yn=function(){function e(e,t){this._base64ToBinary=t,this._decode=e}return e.prototype.decodeToken=function(e){var t="";e.length%4==3?t="=":e.length%4==2&&(t="==");var n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,r=this._decode(this._base64ToBinary(n));if("object"==typeof r)return r},e}(),gn={exports:{}},mn={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;oa.depthLimit)return void En(bn,e,t,o);if(void 0!==a.edgesLimit&&n+1>a.edgesLimit)return void En(bn,e,t,o);if(r.push(e),Array.isArray(e))for(s=0;st?1:0}function Cn(e,t,n,r){void 0===r&&(r=On());var o,i=kn(e,"",0,[],void 0,0,r)||e;try{o=0===wn.length?JSON.stringify(i,t,n):JSON.stringify(i,Nn(t),n)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==Sn.length;){var a=Sn.pop();4===a.length?Object.defineProperty(a[0],a[1],a[3]):a[0][a[1]]=a[2]}}return o}function kn(e,t,n,r,o,i,a){var s;if(i+=1,"object"==typeof e&&null!==e){for(s=0;sa.depthLimit)return void En(bn,e,t,o);if(void 0!==a.edgesLimit&&n+1>a.edgesLimit)return void En(bn,e,t,o);if(r.push(e),Array.isArray(e))for(s=0;s0)for(var r=0;r1&&"boolean"!=typeof t)throw new Hn('"allowMissing" argument must be a boolean');var n=cr(e),r=n.length>0?n[0]:"",o=lr("%"+r+"%",t),i=o.name,a=o.value,s=!1,u=o.alias;u&&(r=u[0],or(n,rr([0,1],u)));for(var c=1,l=!0;c=n.length){var d=zn(a,p);a=(l=!!d)&&"get"in d&&!("originalValue"in d.get)?d.get:a[p]}else l=nr(a,p),a=a[p];l&&!s&&(Yn[i]=a)}}return a},hr={exports:{}};!function(e){var t=Gn,n=pr,r=n("%Function.prototype.apply%"),o=n("%Function.prototype.call%"),i=n("%Reflect.apply%",!0)||t.call(o,r),a=n("%Object.getOwnPropertyDescriptor%",!0),s=n("%Object.defineProperty%",!0),u=n("%Math.max%");if(s)try{s({},"a",{value:1})}catch(e){s=null}e.exports=function(e){var n=i(t,o,arguments);if(a&&s){var r=a(n,"length");r.configurable&&s(n,"length",{value:1+u(0,e.length-(arguments.length-1))})}return n};var c=function(){return i(t,r,arguments)};s?s(e.exports,"apply",{value:c}):e.exports.apply=c}(hr);var fr=pr,dr=hr.exports,yr=dr(fr("String.prototype.indexOf")),gr=l(Object.freeze({__proto__:null,default:{}})),mr="function"==typeof Map&&Map.prototype,vr=Object.getOwnPropertyDescriptor&&mr?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,br=mr&&vr&&"function"==typeof vr.get?vr.get:null,_r=mr&&Map.prototype.forEach,Sr="function"==typeof Set&&Set.prototype,wr=Object.getOwnPropertyDescriptor&&Sr?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Or=Sr&&wr&&"function"==typeof wr.get?wr.get:null,Pr=Sr&&Set.prototype.forEach,Er="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Tr="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,Ar="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Cr=Boolean.prototype.valueOf,kr=Object.prototype.toString,Nr=Function.prototype.toString,Mr=String.prototype.match,jr=String.prototype.slice,Rr=String.prototype.replace,xr=String.prototype.toUpperCase,Ur=String.prototype.toLowerCase,Ir=RegExp.prototype.test,Dr=Array.prototype.concat,Fr=Array.prototype.join,Gr=Array.prototype.slice,Lr=Math.floor,Kr="function"==typeof BigInt?BigInt.prototype.valueOf:null,Br=Object.getOwnPropertySymbols,Hr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,qr="function"==typeof Symbol&&"object"==typeof Symbol.iterator,zr="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===qr||"symbol")?Symbol.toStringTag:null,Vr=Object.prototype.propertyIsEnumerable,Wr=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function Jr(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||Ir.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var r=e<0?-Lr(-e):Lr(e);if(r!==e){var o=String(r),i=jr.call(t,o.length+1);return Rr.call(o,n,"$&_")+"."+Rr.call(Rr.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Rr.call(t,n,"$&_")}var $r=gr,Qr=$r.custom,Xr=no(Qr)?Qr:null;function Yr(e,t,n){var r="double"===(n.quoteStyle||t)?'"':"'";return r+e+r}function Zr(e){return Rr.call(String(e),/"/g,""")}function eo(e){return!("[object Array]"!==io(e)||zr&&"object"==typeof e&&zr in e)}function to(e){return!("[object RegExp]"!==io(e)||zr&&"object"==typeof e&&zr in e)}function no(e){if(qr)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!Hr)return!1;try{return Hr.call(e),!0}catch(e){}return!1}var ro=Object.prototype.hasOwnProperty||function(e){return e in this};function oo(e,t){return ro.call(e,t)}function io(e){return kr.call(e)}function ao(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;nt.maxStringLength){var n=e.length-t.maxStringLength,r="... "+n+" more character"+(n>1?"s":"");return so(jr.call(e,0,t.maxStringLength),t)+r}return Yr(Rr.call(Rr.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,uo),"single",t)}function uo(e){var t=e.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return n?"\\"+n:"\\x"+(t<16?"0":"")+xr.call(t.toString(16))}function co(e){return"Object("+e+")"}function lo(e){return e+" { ? }"}function po(e,t,n,r){return e+" ("+t+") {"+(r?ho(n,r):Fr.call(n,", "))+"}"}function ho(e,t){if(0===e.length)return"";var n="\n"+t.prev+t.base;return n+Fr.call(e,","+n)+"\n"+t.prev}function fo(e,t){var n=eo(e),r=[];if(n){r.length=e.length;for(var o=0;o-1?dr(n):n},mo=function e(t,n,r,o){var i=n||{};if(oo(i,"quoteStyle")&&"single"!==i.quoteStyle&&"double"!==i.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(oo(i,"maxStringLength")&&("number"==typeof i.maxStringLength?i.maxStringLength<0&&i.maxStringLength!==1/0:null!==i.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var a=!oo(i,"customInspect")||i.customInspect;if("boolean"!=typeof a&&"symbol"!==a)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(oo(i,"indent")&&null!==i.indent&&"\t"!==i.indent&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(oo(i,"numericSeparator")&&"boolean"!=typeof i.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var s=i.numericSeparator;if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return so(t,i);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var u=String(t);return s?Jr(t,u):u}if("bigint"==typeof t){var l=String(t)+"n";return s?Jr(t,l):l}var p=void 0===i.depth?5:i.depth;if(void 0===r&&(r=0),r>=p&&p>0&&"object"==typeof t)return eo(t)?"[Array]":"[Object]";var h=function(e,t){var n;if("\t"===e.indent)n="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;n=Fr.call(Array(e.indent+1)," ")}return{base:n,prev:Fr.call(Array(t+1),n)}}(i,r);if(void 0===o)o=[];else if(ao(o,t)>=0)return"[Circular]";function f(t,n,a){if(n&&(o=Gr.call(o)).push(n),a){var s={depth:i.depth};return oo(i,"quoteStyle")&&(s.quoteStyle=i.quoteStyle),e(t,s,r+1,o)}return e(t,i,r+1,o)}if("function"==typeof t&&!to(t)){var d=function(e){if(e.name)return e.name;var t=Mr.call(Nr.call(e),/^function\s*([\w$]+)/);if(t)return t[1];return null}(t),y=fo(t,f);return"[Function"+(d?": "+d:" (anonymous)")+"]"+(y.length>0?" { "+Fr.call(y,", ")+" }":"")}if(no(t)){var g=qr?Rr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Hr.call(t);return"object"!=typeof t||qr?g:co(g)}if(function(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return!0;return"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}(t)){for(var m="<"+Ur.call(String(t.nodeName)),v=t.attributes||[],b=0;b"}if(eo(t)){if(0===t.length)return"[]";var _=fo(t,f);return h&&!function(e){for(var t=0;t=0)return!1;return!0}(_)?"["+ho(_,h)+"]":"[ "+Fr.call(_,", ")+" ]"}if(function(e){return!("[object Error]"!==io(e)||zr&&"object"==typeof e&&zr in e)}(t)){var S=fo(t,f);return"cause"in Error.prototype||!("cause"in t)||Vr.call(t,"cause")?0===S.length?"["+String(t)+"]":"{ ["+String(t)+"] "+Fr.call(S,", ")+" }":"{ ["+String(t)+"] "+Fr.call(Dr.call("[cause]: "+f(t.cause),S),", ")+" }"}if("object"==typeof t&&a){if(Xr&&"function"==typeof t[Xr]&&$r)return $r(t,{depth:p-r});if("symbol"!==a&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!br||!e||"object"!=typeof e)return!1;try{br.call(e);try{Or.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}(t)){var w=[];return _r&&_r.call(t,(function(e,n){w.push(f(n,t,!0)+" => "+f(e,t))})),po("Map",br.call(t),w,h)}if(function(e){if(!Or||!e||"object"!=typeof e)return!1;try{Or.call(e);try{br.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}(t)){var O=[];return Pr&&Pr.call(t,(function(e){O.push(f(e,t))})),po("Set",Or.call(t),O,h)}if(function(e){if(!Er||!e||"object"!=typeof e)return!1;try{Er.call(e,Er);try{Tr.call(e,Tr)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}(t))return lo("WeakMap");if(function(e){if(!Tr||!e||"object"!=typeof e)return!1;try{Tr.call(e,Tr);try{Er.call(e,Er)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}(t))return lo("WeakSet");if(function(e){if(!Ar||!e||"object"!=typeof e)return!1;try{return Ar.call(e),!0}catch(e){}return!1}(t))return lo("WeakRef");if(function(e){return!("[object Number]"!==io(e)||zr&&"object"==typeof e&&zr in e)}(t))return co(f(Number(t)));if(function(e){if(!e||"object"!=typeof e||!Kr)return!1;try{return Kr.call(e),!0}catch(e){}return!1}(t))return co(f(Kr.call(t)));if(function(e){return!("[object Boolean]"!==io(e)||zr&&"object"==typeof e&&zr in e)}(t))return co(Cr.call(t));if(function(e){return!("[object String]"!==io(e)||zr&&"object"==typeof e&&zr in e)}(t))return co(f(String(t)));if("undefined"!=typeof window&&t===window)return"{ [object Window] }";if(t===c)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==io(e)||zr&&"object"==typeof e&&zr in e)}(t)&&!to(t)){var P=fo(t,f),E=Wr?Wr(t)===Object.prototype:t instanceof Object||t.constructor===Object,T=t instanceof Object?"":"null prototype",A=!E&&zr&&Object(t)===t&&zr in t?jr.call(io(t),8,-1):T?"Object":"",C=(E||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(A||T?"["+Fr.call(Dr.call([],A||[],T||[]),": ")+"] ":"");return 0===P.length?C+"{}":h?C+"{"+ho(P,h)+"}":C+"{ "+Fr.call(P,", ")+" }"}return String(t)},vo=yo("%TypeError%"),bo=yo("%WeakMap%",!0),_o=yo("%Map%",!0),So=go("WeakMap.prototype.get",!0),wo=go("WeakMap.prototype.set",!0),Oo=go("WeakMap.prototype.has",!0),Po=go("Map.prototype.get",!0),Eo=go("Map.prototype.set",!0),To=go("Map.prototype.has",!0),Ao=function(e,t){for(var n,r=e;null!==(n=r.next);r=n)if(n.key===t)return r.next=n.next,n.next=e.next,e.next=n,n},Co=String.prototype.replace,ko=/%20/g,No="RFC3986",Mo={default:No,formatters:{RFC1738:function(e){return Co.call(e,ko,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:No},jo=Mo,Ro=Object.prototype.hasOwnProperty,xo=Array.isArray,Uo=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),Io=function(e,t){for(var n=t&&t.plainObjects?Object.create(null):{},r=0;r1;){var t=e.pop(),n=t.obj[t.prop];if(xo(n)){for(var r=[],o=0;o=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===jo.RFC1738&&(40===u||41===u)?a+=i.charAt(s):u<128?a+=Uo[u]:u<2048?a+=Uo[192|u>>6]+Uo[128|63&u]:u<55296||u>=57344?a+=Uo[224|u>>12]+Uo[128|u>>6&63]+Uo[128|63&u]:(s+=1,u=65536+((1023&u)<<10|1023&i.charCodeAt(s)),a+=Uo[240|u>>18]+Uo[128|u>>12&63]+Uo[128|u>>6&63]+Uo[128|63&u])}return a},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(xo(e)){for(var n=[],r=0;r0?v.join(",")||null:void 0}];else if(Ho(u))O=u;else{var E=Object.keys(v);O=c?E.sort(c):E}for(var T=o&&Ho(v)&&1===v.length?n+"[]":n,A=0;A-1?e.split(","):e},ri=function(e,t,n,r){if(e){var o=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,a=n.depth>0&&/(\[[^[\]]*])/.exec(o),s=a?o.slice(0,a.index):o,u=[];if(s){if(!n.plainObjects&&Yo.call(Object.prototype,s)&&!n.allowPrototypes)return;u.push(s)}for(var c=0;n.depth>0&&null!==(a=i.exec(o))&&c=0;--i){var a,s=e[i];if("[]"===s&&n.parseArrays)a=[].concat(o);else{a=n.plainObjects?Object.create(null):{};var u="["===s.charAt(0)&&"]"===s.charAt(s.length-1)?s.slice(1,-1):s,c=parseInt(u,10);n.parseArrays||""!==u?!isNaN(c)&&s!==u&&String(c)===u&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(a=[])[c]=o:"__proto__"!==u&&(a[u]=o):a={0:o}}o=a}return o}(u,t,n,r)}},oi=function(e,t){var n,r=e,o=function(e){if(!e)return Jo;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||Jo.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Lo.default;if(void 0!==e.format){if(!Ko.call(Lo.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var r=Lo.formatters[n],o=Jo.filter;return("function"==typeof e.filter||Ho(e.filter))&&(o=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:Jo.addQueryPrefix,allowDots:void 0===e.allowDots?Jo.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:Jo.charsetSentinel,delimiter:void 0===e.delimiter?Jo.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:Jo.encode,encoder:"function"==typeof e.encoder?e.encoder:Jo.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:Jo.encodeValuesOnly,filter:o,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:Jo.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:Jo.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:Jo.strictNullHandling}}(t);"function"==typeof o.filter?r=(0,o.filter)("",r):Ho(o.filter)&&(n=o.filter);var i,a=[];if("object"!=typeof r||null===r)return"";i=t&&t.arrayFormat in Bo?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var s=Bo[i];if(t&&"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var u="comma"===s&&t&&t.commaRoundTrip;n||(n=Object.keys(r)),o.sort&&n.sort(o.sort);for(var c=Fo(),l=0;l0?f+h:""},ii={formats:Mo,parse:function(e,t){var n=function(e){if(!e)return ei;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?ei.charset:e.charset;return{allowDots:void 0===e.allowDots?ei.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:ei.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:ei.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:ei.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ei.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:ei.comma,decoder:"function"==typeof e.decoder?e.decoder:ei.decoder,delimiter:"string"==typeof e.delimiter||Xo.isRegExp(e.delimiter)?e.delimiter:ei.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:ei.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:ei.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:ei.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:ei.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ei.strictNullHandling}}(t);if(""===e||null==e)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof e?function(e,t){var n,r={__proto__:null},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,a=o.split(t.delimiter,i),s=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(l=Zo(l)?[l]:l),Yo.call(r,c)?r[c]=Xo.combine(r[c],l):r[c]=l}return r}(e,n):e,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),a=0;a=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return s=e.done,e},e:function(e){u=!0,a=e},f:function(){try{s||null==r.return||r.return()}finally{if(u)throw a}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.split(/ *; */).shift(),e.params=e=>{const n={};var r,o=t(e.split(/ *; */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *= */),t=e.shift(),o=e.shift();t&&o&&(n[t]=o)}}catch(e){o.e(e)}finally{o.f()}return n},e.parseLinks=e=>{const n={};var r,o=t(e.split(/ *, */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *; */),t=e[0].slice(1,-1);n[e[1].split(/ *= */)[1].slice(1,-1)]=t}}catch(e){o.e(e)}finally{o.f()}return n},e.cleanHeader=(e,t)=>(delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e),e.isObject=e=>null!==e&&"object"==typeof e,e.hasOwn=Object.hasOwn||function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(new Object(e),t)},e.mixin=(t,n)=>{for(const r in n)e.hasOwn(n,r)&&(t[r]=n[r])}}(ai);const si=gr,ui=ai.isObject,ci=ai.hasOwn;var li=pi;function pi(){}pi.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},pi.prototype.parse=function(e){return this._parser=e,this},pi.prototype.responseType=function(e){return this._responseType=e,this},pi.prototype.serialize=function(e){return this._serializer=e,this},pi.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(const t in e)if(ci(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},pi.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};const hi=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),fi=new Set([408,413,429,500,502,503,504,521,522,524]);pi.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{const n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&fi.has(t.status))return!0;if(e){if(e.code&&hi.has(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},pi.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},pi.prototype.then=function(e,t){if(!this._fullfilledPromise){const e=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(((t,n)=>{e.on("abort",(()=>{if(this._maxRetries&&this._maxRetries>this._retries)return;if(this.timedout&&this.timedoutError)return void n(this.timedoutError);const e=new Error("Aborted");e.code="ABORTED",e.status=this.status,e.method=this.method,e.url=this.url,n(e)})),e.end(((e,r)=>{e?n(e):t(r)}))}))}return this._fullfilledPromise.then(e,t)},pi.prototype.catch=function(e){return this.then(void 0,e)},pi.prototype.use=function(e){return e(this),this},pi.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},pi.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},pi.prototype.get=function(e){return this._header[e.toLowerCase()]},pi.prototype.getHeader=pi.prototype.get,pi.prototype.set=function(e,t){if(ui(e)){for(const t in e)ci(e,t)&&this.set(t,e[t]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},pi.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},pi.prototype.field=function(e,t,n){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(ui(e)){for(const t in e)ci(e,t)&&this.field(t,e[t]);return this}if(Array.isArray(t)){for(const n in t)ci(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),n?this._getFormData().append(e,t,n):this._getFormData().append(e,t),this},pi.prototype.abort=function(){if(this._aborted)return this;if(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req){if(si.gte(process.version,"v13.0.0")&&si.lt(process.version,"v14.0.0"))throw new Error("Superagent does not work in v13 properly with abort() due to Node.js core changes");this.req.abort()}return this.clearTimeout(),this.emit("abort"),this},pi.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization",`Basic ${r(`${e}:${t}`)}`);break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization",`Bearer ${e}`)}return this},pi.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},pi.prototype.redirects=function(e){return this._maxRedirects=e,this},pi.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},pi.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},pi.prototype.send=function(e){const t=ui(e);let n=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&ui(this._data))for(const t in e){if("bigint"==typeof e[t]&&!e[t].toJSON)throw new Error("Cannot serialize BigInt value to json");ci(e,t)&&(this._data[t]=e[t])}else{if("bigint"==typeof e)throw new Error("Cannot send value of type BigInt");"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],n&&(n=n.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===n?this._data?`${this._data}&${e}`:e:(this._data||"")+e):this._data=e}return!t||this._isHost(e)||n||this.type("json"),this},pi.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},pi.prototype._finalizeQueryString=function(){const e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){const e=this.url.indexOf("?");if(e>=0){const t=this.url.slice(e+1).split("&");"function"==typeof this._sort?t.sort(this._sort):t.sort(),this.url=this.url.slice(0,e)+"?"+t.join("&")}}},pi.prototype._appendQueryString=()=>{console.warn("Unsupported")},pi.prototype._timeoutError=function(e,t,n){if(this._aborted)return;const r=new Error(`${e+t}ms exceeded`);r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.timedoutError=r,this.abort(),this.callback(r)},pi.prototype._setTimeouts=function(){const e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((()=>{e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((()=>{e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};const di=ai;var yi=gi;function gi(){}function mi(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return vi(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return vi(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==n.return||n.return()}finally{if(s)throw i}}}}function vi(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var a,s=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){u=!0,a=e},f:function(){try{s||null==n.return||n.return()}finally{if(u)throw a}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n{if(o.XMLHttpRequest)return new o.XMLHttpRequest;throw new Error("Browser-only version of superagent could not find XHR")};const g="".trim?e=>e.trim():e=>e.replace(/(^\s*|\s*$)/g,"");function m(e){if(!c(e))return e;const t=[];for(const n in e)p(e,n)&&v(t,n,e[n]);return t.join("&")}function v(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r)){var o,i=n(r);try{for(i.s();!(o=i.n()).done;){v(e,t,o.value)}}catch(e){i.e(e)}finally{i.f()}}else if(c(r))for(const n in r)p(r,n)&&v(e,`${t}[${n}]`,r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function b(e){const t={},n=e.split("&");let r,o;for(let e=0,i=n.length;e{let e,t=null,r=null;try{r=new S(n)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||r.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=e.status||r.status,n.callback(e,r)):n.callback(null,r)}))}y.serializeObject=m,y.parseString=b,y.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":s.stringify,"application/json":a},y.parse={"application/x-www-form-urlencoded":b,"application/json":JSON.parse},l(S.prototype,h.prototype),S.prototype._parseBody=function(e){let t=y.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&_(this.type)&&(t=y.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},S.prototype.toError=function(){const e=this.req,t=e.method,n=e.url,r=`cannot ${t} ${n} (${this.status})`,o=new Error(r);return o.status=this.status,o.method=t,o.url=n,o},y.Response=S,i(w.prototype),l(w.prototype,u.prototype),w.prototype.type=function(e){return this.set("Content-Type",y.types[e]||e),this},w.prototype.accept=function(e){return this.set("Accept",y.types[e]||e),this},w.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});const r=n.encoder?n.encoder:e=>{if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},w.prototype.query=function(e){return"string"!=typeof e&&(e=m(e)),e&&this._query.push(e),this},w.prototype.attach=function(e,t,n){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},w.prototype._getFormData=function(){return this._formData||(this._formData=new o.FormData),this._formData},w.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();const n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},w.prototype.crossDomainError=function(){const e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},w.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},w.prototype.ca=w.prototype.agent,w.prototype.buffer=w.prototype.ca,w.prototype.write=()=>{throw new Error("Streaming is not supported in browser version of superagent")},w.prototype.pipe=w.prototype.write,w.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},w.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||d,this._finalizeQueryString(),this._end()},w.prototype._setUploadTimeout=function(){const e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((()=>{e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},w.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));const e=this;this.xhr=y.getXHR();const t=this.xhr;let n=this._formData||this._data;this._setTimeouts(),t.addEventListener("readystatechange",(()=>{const n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4!==n)return;let r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}));const r=(t,n)=>{n.total>0&&(n.percent=n.loaded/n.total*100,100===n.percent&&clearTimeout(e._uploadTimeoutTimer)),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.addEventListener("progress",r.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",r.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof n&&!this._isHost(n)){const e=this._header["content-type"];let t=this._serializer||y.serialize[e?e.split(";")[0]:""];!t&&_(e)&&(t=y.serialize["application/json"]),t&&(n=t(n))}for(const e in this.header)null!==this.header[e]&&p(this.header,e)&&t.setRequestHeader(e,this.header[e]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===n?null:n)},y.agent=()=>new f;for(var O=0,P=["GET","POST","OPTIONS","PATCH","PUT","DELETE"];O{const r=y("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.head=(e,t,n)=>{const r=y("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.options=(e,t,n)=>{const r=y("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.del=E,y.delete=E,y.patch=(e,t,n)=>{const r=y("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.post=(e,t,n)=>{const r=y("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.put=(e,t,n)=>{const r=y("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}}(gn,gn.exports);var Oi=gn.exports;function Pi(e){var t=(new Date).getTime(),n=(new Date).toISOString(),r=console&&console.log?console:window&&window.console&&window.console.log?window.console:console;r.log("<<<<<"),r.log("[".concat(n,"]"),"\n",e.url,"\n",e.qs),r.log("-----"),e.on("response",(function(n){var o=(new Date).getTime()-t,i=(new Date).toISOString();r.log(">>>>>>"),r.log("[".concat(i," / ").concat(o,"]"),"\n",e.url,"\n",e.qs,"\n",n.text),r.log("-----")}))}function Ei(e,t,n){var r=this;this._config.logVerbosity&&(e=e.use(Pi)),this._config.proxy&&this._modules.proxy&&(e=this._modules.proxy.call(this,e)),this._config.keepAlive&&this._modules.keepAlive&&(e=this._modules.keepAlive(e));var o=e;if(t.abortSignal)var i=t.abortSignal.subscribe((function(){o.abort(),i()}));return!0===t.forceBuffered?o="undefined"==typeof Blob?o.buffer().responseType("arraybuffer"):o.responseType("arraybuffer"):!1===t.forceBuffered&&(o=o.buffer(!1)),(o=o.timeout(t.timeout)).on("abort",(function(){return n({category:R.PNUnknownCategory,error:!0,operation:t.operation,errorData:new Error("Aborted")},null)})),o.end((function(e,o){var i,a={};if(a.error=null!==e,a.operation=t.operation,o&&o.status&&(a.statusCode=o.status),e){if(e.response&&e.response.text&&!r._config.logVerbosity)try{a.errorData=JSON.parse(e.response.text)}catch(t){a.errorData=e}else a.errorData=e;return a.category=r._detectErrorCategory(e),n(a,null)}if(t.ignoreBody)i={headers:o.headers,redirects:o.redirects,response:o};else try{i=JSON.parse(o.text)}catch(e){return a.errorData=o,a.error=!0,n(a,null)}return i.error&&1===i.error&&i.status&&i.message&&i.service?(a.errorData=i,a.statusCode=i.status,a.error=!0,a.category=r._detectErrorCategory(a),n(a,null)):(i.error&&i.error.message&&(a.errorData=i.error),n(a,i))})),o}function Ti(e,t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return r=Oi.post(e),t.forEach((function(e){var t=e.key,n=e.value;r=r.field(t,n)})),r.attach("file",n,{contentType:"application/octet-stream"}),[4,r];case 1:return[2,o.sent()]}}))}))}function Ai(e,t,n){var r=Oi.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return Ei.call(this,r,t,n)}function Ci(e,t,n){var r=Oi.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return Ei.call(this,r,t,n)}function ki(e,t,n,r){var o=Oi.post(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return Ei.call(this,o,n,r)}function Ni(e,t,n,r){var o=Oi.patch(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return Ei.call(this,o,n,r)}function Mi(e,t,n){var r=Oi.delete(this.getStandardOrigin()+t.url).set(t.headers).query(e);return Ei.call(this,r,t,n)}function ji(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}var Ri,xi=function(){function e(){}return Object.defineProperty(e.prototype,"algo",{get:function(){return"aes-256-cbc"},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.encryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.encryptString(n,t)];throw new Error("Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer")}}))}))},e.prototype.decrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.decryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.decryptString(n,t)];throw new Error("Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer")}}))}))},e.prototype.encryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,a;return i(this,(function(i){switch(i.label){case 0:if(t.data.byteLength<=0)throw new Error("encryption error. empty content");return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.encryptArrayBuffer(r,o)];case 3:return a=i.sent(),[2,n.create({name:t.name,mimeType:"application/octet-stream",data:a})]}}))}))},e.prototype.decryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,a;return i(this,(function(i){switch(i.label){case 0:return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.decryptArrayBuffer(r,o)];case 3:return a=i.sent(),[2,n.create({name:t.name,data:a})]}}))}))},e.prototype.getKey=function(t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return[4,crypto.subtle.digest("SHA-256",e.encoder.encode(t))];case 1:return n=i.sent(),r=Array.from(new Uint8Array(n)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),o=e.encoder.encode(r.slice(0,32)).buffer,[2,crypto.subtle.importKey("raw",o,"AES-CBC",!0,["encrypt","decrypt"])]}}))}))},e.prototype.encryptArrayBuffer=function(e,t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),r=ji,o=[n.buffer],[4,crypto.subtle.encrypt({name:"AES-CBC",iv:n},e,t)];case 1:return[2,r.apply(void 0,o.concat([i.sent()]))]}}))}))},e.prototype.decryptArrayBuffer=function(t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:if(r=n.slice(0,16),n.slice(e.IV_LENGTH).byteLength<=0)throw new Error("decryption error: empty content");return[4,crypto.subtle.decrypt({name:"AES-CBC",iv:r},t,n.slice(e.IV_LENGTH))];case 1:return[2,o.sent()]}}))}))},e.prototype.encryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,a,s;return i(this,(function(i){switch(i.label){case 0:return r=crypto.getRandomValues(new Uint8Array(16)),o=e.encoder.encode(n).buffer,[4,crypto.subtle.encrypt({name:"AES-CBC",iv:r},t,o)];case 1:return a=i.sent(),s=ji(r.buffer,a),[2,e.decoder.decode(s)]}}))}))},e.prototype.decryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,a,s;return i(this,(function(i){switch(i.label){case 0:return r=e.encoder.encode(n).buffer,o=r.slice(0,16),a=r.slice(16),[4,crypto.subtle.decrypt({name:"AES-CBC",iv:o},t,a)];case 1:return s=i.sent(),[2,e.decoder.decode(s)]}}))}))},e.IV_LENGTH=16,e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Ui=(Ri=function(){function e(e){if(e instanceof File)this.data=e,this.name=this.data.name,this.mimeType=this.data.type;else if(e.data){var t=e.data;this.data=new File([t],e.name,{type:e.mimeType}),this.name=e.name,e.mimeType&&(this.mimeType=e.mimeType)}if(void 0===this.data)throw new Error("Couldn't construct a file out of supplied options.");if(void 0===this.name)throw new Error("Couldn't guess filename out of the options. Please provide one.")}return e.create=function(e){return new this(e)},e.prototype.toBuffer=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toStream=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toFileUri=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in react native environments.")}))}))},e.prototype.toBlob=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e.prototype.toArrayBuffer=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if(r.result instanceof ArrayBuffer)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsArrayBuffer(e.data)}))]}))}))},e.prototype.toString=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if("string"==typeof r.result)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsBinaryString(e.data)}))]}))}))},e.prototype.toFile=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e}(),Ri.supportsFile="undefined"!=typeof File,Ri.supportsBlob="undefined"!=typeof Blob,Ri.supportsArrayBuffer="undefined"!=typeof ArrayBuffer,Ri.supportsBuffer=!1,Ri.supportsStream=!1,Ri.supportsString=!0,Ri.supportsEncryptFile=!0,Ri.supportsFileUri=!1,Ri),Ii=function(){function e(e){this.config=e,this.cryptor=new A({config:e}),this.fileCryptor=new xi}return Object.defineProperty(e.prototype,"identifier",{get:function(){return""},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e){var t="string"==typeof e?e:(new TextDecoder).decode(e);return{data:this.cryptor.encrypt(t),metadata:null}},e.prototype.decrypt=function(e){var t="string"==typeof e.data?e.data:v(e.data);return this.cryptor.decrypt(t)},e.prototype.encryptFile=function(e,t){var n;return o(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)]}))}))},e.prototype.decryptFile=function(e,t){return o(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.fileCryptor.decryptFile(this.config.cipherKey,e,t)]}))}))},e}(),Di=function(){function e(e){this.cipherKey=e.cipherKey,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(this.cipherKey)}return Object.defineProperty(e.prototype,"algo",{get:function(){return"AES-CBC"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return"ACRH"},enumerable:!1,configurable:!0}),e.prototype.getIv=function(){return crypto.getRandomValues(new Uint8Array(e.BLOCK_SIZE))},e.prototype.getKey=function(){return o(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return t=e.encoder.encode(this.cipherKey),[4,crypto.subtle.digest("SHA-256",t.buffer)];case 1:return n=r.sent(),[2,crypto.subtle.importKey("raw",n,this.algo,!0,["encrypt","decrypt"])]}}))}))},e.prototype.encrypt=function(t){if(0===("string"==typeof t?t:e.decoder.decode(t)).length)throw new Error("encryption error. empty content");var n=this.getIv();return{metadata:n,data:m(this.CryptoJS.AES.encrypt(t,this.encryptedKey,{iv:this.bufferToWordArray(n),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}},e.prototype.decrypt=function(t){var n=this.bufferToWordArray(new Uint8ClampedArray(t.metadata)),r=this.bufferToWordArray(new Uint8ClampedArray(t.data));return e.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:r},this.encryptedKey,{iv:n,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer},e.prototype.encryptFileData=function(e){return o(this,void 0,void 0,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:return[4,this.getKey()];case 1:return t=o.sent(),n=this.getIv(),r={},[4,crypto.subtle.encrypt({name:this.algo,iv:n},t,e)];case 2:return[2,(r.data=o.sent(),r.metadata=n,r)]}}))}))},e.prototype.decryptFileData=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.getKey()];case 1:return t=n.sent(),[2,crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)]}}))}))},e.prototype.bufferToWordArray=function(e){var t,n=[];for(t=0;t0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("decryption error. empty content");return r.decrypt({data:t.slice(n.length),metadata:o})},e.prototype.encryptFile=function(e,t){return o(this,void 0,void 0,(function(){var n,r;return i(this,(function(o){switch(o.label){case 0:return this.defaultCryptor.identifier===Gi.LEGACY_IDENTIFIER?[2,this.defaultCryptor.encryptFile(e,t)]:[4,this.getFileData(e.data)];case 1:return n=o.sent(),[4,this.defaultCryptor.encryptFileData(n)];case 2:return r=o.sent(),[2,t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(r),r.data)})]}}))}))},e.prototype.decryptFile=function(t,n){return o(this,void 0,void 0,(function(){var r,o,a,s,u,c,l,p;return i(this,(function(i){switch(i.label){case 0:return[4,t.data.arrayBuffer()];case 1:return r=i.sent(),o=Gi.tryParse(r),(null==(a=this.getCryptor(o))?void 0:a.identifier)===e.LEGACY_IDENTIFIER?[2,a.decryptFile(t,n)]:[4,this.getFileData(r)];case 2:return s=i.sent(),u=s.slice(o.length-o.metadataLength,o.length),l=(c=n).create,p={name:t.name},[4,this.defaultCryptor.decryptFileData({data:r.slice(o.length),metadata:u})];case 3:return[2,l.apply(c,[(p.data=i.sent(),p)])]}}))}))},e.prototype.getCryptor=function(e){if(""===e){var t=this.getAllCryptors().find((function(e){return""===e.identifier}));if(t)return t;throw new Error("unknown cryptor error")}if(e instanceof Li)return this.getCryptorFromId(e.identifier)},e.prototype.getCryptorFromId=function(e){var t=this.getAllCryptors().find((function(t){return e===t.identifier}));if(t)return t;throw Error("unknown cryptor error")},e.prototype.concatArrayBuffer=function(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer},e.prototype.getHeaderData=function(e){if(e.metadata){var t=Gi.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length),r=0;return n.set(t.data,r),r+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),r),n.buffer}},e.prototype.getFileData=function(t){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return t instanceof Blob?[4,t.arrayBuffer()]:[3,2];case 1:return[2,n.sent()];case 2:if(t instanceof ArrayBuffer)return[2,t];if("string"==typeof t)return[2,e.encoder.encode(t)];throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}}))}))},e.LEGACY_IDENTIFIER="",e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Gi=function(){function e(){}return e.from=function(t,n){if(t!==e.LEGACY_IDENTIFIER)return new Li(t,n.byteLength)},e.tryParse=function(t){var n=new Uint8Array(t),r="";if(n.byteLength>=4&&(r=n.slice(0,4),this.decoder.decode(r)!==e.SENTINEL))return"";if(!(n.byteLength>=5))throw new Error("decryption error. invalid header version");if(n[4]>e.MAX_VERSION)throw new Error("unknown cryptor error");var o="",i=5+e.IDENTIFIER_LENGTH;if(!(n.byteLength>=i))throw new Error("decryption error. invalid crypto identifier");o=n.slice(5,i);var a=null;if(!(n.byteLength>=i+1))throw new Error("decryption error. invalid metadata length");return a=n[i],i+=1,255===a&&n.byteLength>=i+2&&(a=new Uint16Array(n.slice(i,i+2)).reduce((function(e,t){return(e<<8)+t}),0),i+=2),new Li(this.decoder.decode(o),a)},e.SENTINEL="PNED",e.LEGACY_IDENTIFIER="",e.IDENTIFIER_LENGTH=4,e.VERSION=1,e.MAX_VERSION=1,e.decoder=new TextDecoder,e}(),Li=function(){function e(e,t){this._identifier=e,this._metadataLength=t}return Object.defineProperty(e.prototype,"identifier",{get:function(){return this._identifier},set:function(e){this._identifier=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"metadataLength",{get:function(){return this._metadataLength},set:function(e){this._metadataLength=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return Gi.VERSION},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return Gi.SENTINEL.length+1+Gi.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){var e=0,t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(Gi.SENTINEL)),t[e+=Gi.SENTINEL.length]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e),e+=Gi.IDENTIFIER_LENGTH;var r=this.metadataLength;return r<255?t[e]=r:t.set([255,r>>8,255&r],e),t},enumerable:!1,configurable:!0}),e.IDENTIFIER_LENGTH=4,e.SENTINEL="PNED",e}();function Ki(e){if(!navigator||!navigator.sendBeacon)return!1;navigator.sendBeacon(e)}var Bi=function(e){function n(t){var n=this,r=t.listenToBrowserNetworkEvents,o=void 0===r||r;return t.sdkFamily="Web",t.networking=new fn({del:Mi,get:Ci,post:ki,patch:Ni,sendBeacon:Ki,getfile:Ai,postfile:Ti}),t.cbor=new yn((function(e){return dn(h.decode(e))}),m),t.PubNubFile=Ui,t.cryptography=new xi,t.initCryptoModule=function(e){return new Fi({default:new Ii({cipherKey:e.cipherKey,useRandomIVs:e.useRandomIVs}),cryptors:[new Di({cipherKey:e.cipherKey})]})},n=e.call(this,t)||this,o&&(window.addEventListener("offline",(function(){n.networkDownDetected()})),window.addEventListener("online",(function(){n.networkUpDetected()}))),n}return t(n,e),n.CryptoModule=Fi,n}(hn);return Bi})); +!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function o(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=o,r.VERSION=t,e.uuid=r,e.isUUID=o}(t),null!==e&&(e.exports=t.uuid)}(f,f.exports);var d=f.exports,y=function(){return d.uuid?d.uuid():d()},g=function(){function e(e){var t,n,r,o,i=e.setup;if(this._PNSDKSuffix={},this.instanceId="pn-".concat(y()),this.secretKey=i.secretKey||i.secret_key,this.subscribeKey=i.subscribeKey||i.subscribe_key,this.publishKey=i.publishKey||i.publish_key,this.sdkName=i.sdkName,this.sdkFamily=i.sdkFamily,this.partnerId=i.partnerId,this.setAuthKey(i.authKey),this.cryptoModule=i.cryptoModule,this.setFilterExpression(i.filterExpression),"string"!=typeof i.origin&&!Array.isArray(i.origin)&&void 0!==i.origin)throw new Error("Origin must be either undefined, a string or a list of strings.");if(this.origin=i.origin||Array.from({length:20},(function(e,t){return"ps".concat(t+1,".pndsn.com")})),this.secure=i.ssl||!1,this.restore=i.restore||!1,this.proxy=i.proxy,this.keepAlive=i.keepAlive,this.keepAliveSettings=i.keepAliveSettings,this.autoNetworkDetection=i.autoNetworkDetection||!1,this.dedupeOnSubscribe=i.dedupeOnSubscribe||!1,this.maximumCacheSize=i.maximumCacheSize||100,this.customEncrypt=i.customEncrypt,this.customDecrypt=i.customDecrypt,this.fileUploadPublishRetryLimit=null!==(t=i.fileUploadPublishRetryLimit)&&void 0!==t?t:5,this.useRandomIVs=null===(n=i.useRandomIVs)||void 0===n||n,this.enableEventEngine=null!==(r=i.enableEventEngine)&&void 0!==r&&r,this.maintainPresenceState=null===(o=i.maintainPresenceState)||void 0===o||o,"undefined"!=typeof location&&"https:"===location.protocol&&(this.secure=!0),this.logVerbosity=i.logVerbosity||!1,this.suppressLeaveEvents=i.suppressLeaveEvents||!1,this.announceFailedHeartbeats=i.announceFailedHeartbeats||!0,this.announceSuccessfulHeartbeats=i.announceSuccessfulHeartbeats||!1,this.useInstanceId=i.useInstanceId||!1,this.useRequestId=i.useRequestId||!1,this.requestMessageCountThreshold=i.requestMessageCountThreshold,i.retryConfiguration&&this._setRetryConfiguration(i.retryConfiguration),this.setTransactionTimeout(i.transactionalRequestTimeout||15e3),this.setSubscribeTimeout(i.subscribeRequestTimeout||31e4),this.setSendBeaconConfig(i.useSendBeacon||!0),i.presenceTimeout?this.setPresenceTimeout(i.presenceTimeout):this._presenceTimeout=300,null!=i.heartbeatInterval&&this.setHeartbeatInterval(i.heartbeatInterval),"string"==typeof i.userId){if("string"==typeof i.uuid)throw new Error("Only one of the following configuration options has to be provided: `uuid` or `userId`");this.setUserId(i.userId)}else{if("string"!=typeof i.uuid)throw new Error("One of the following configuration options has to be provided: `uuid` or `userId`");this.setUUID(i.uuid)}this.setCipherKey(i.cipherKey,i)}return e.prototype.getAuthKey=function(){return this.authKey},e.prototype.setAuthKey=function(e){return this.authKey=e,this},e.prototype.setCipherKey=function(e,t,n){var r;return this.cipherKey=e,this.cipherKey&&(this.cryptoModule=null!==(r=t.cryptoModule)&&void 0!==r?r:t.initCryptoModule({cipherKey:this.cipherKey,useRandomIVs:this.useRandomIVs}),n&&(n.cryptoModule=this.cryptoModule)),this},e.prototype.getUUID=function(){return this.UUID},e.prototype.setUUID=function(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing uuid parameter. Provide a valid string uuid");return this.UUID=e,this},e.prototype.getUserId=function(){return this.UUID},e.prototype.setUserId=function(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");return this.UUID=e,this},e.prototype.getFilterExpression=function(){return this.filterExpression},e.prototype.setFilterExpression=function(e){return this.filterExpression=e,this},e.prototype.getPresenceTimeout=function(){return this._presenceTimeout},e.prototype.setPresenceTimeout=function(e){return e>=20?this._presenceTimeout=e:(this._presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",this._presenceTimeout)),this.setHeartbeatInterval(this._presenceTimeout/2-1),this},e.prototype.setProxy=function(e){this.proxy=e},e.prototype.getHeartbeatInterval=function(){return this._heartbeatInterval},e.prototype.setHeartbeatInterval=function(e){return this._heartbeatInterval=e,this},e.prototype.getSubscribeTimeout=function(){return this._subscribeRequestTimeout},e.prototype.setSubscribeTimeout=function(e){return this._subscribeRequestTimeout=e,this},e.prototype.getTransactionTimeout=function(){return this._transactionalRequestTimeout},e.prototype.setTransactionTimeout=function(e){return this._transactionalRequestTimeout=e,this},e.prototype.isSendBeaconEnabled=function(){return this._useSendBeacon},e.prototype.setSendBeaconConfig=function(e){return this._useSendBeacon=e,this},e.prototype.getVersion=function(){return"7.6.0"},e.prototype._setRetryConfiguration=function(e){if(e.minimumdelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(e.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(e.maximumDelay&&maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6");if(e.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10");this.retryConfiguration=e},e.prototype._addPnsdkSuffix=function(e,t){this._PNSDKSuffix[e]=t},e.prototype._getPnsdkSuffix=function(e){var t=this;return Object.keys(this._PNSDKSuffix).reduce((function(n,r){return n+e+t._PNSDKSuffix[r]}),"")},e}();function m(e){var t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;function s(){var e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error("Illegal character at ".concat(i,": ").concat(t.charAt(i-1)));return n}for(var a=0;a>4,f=(15&c)<<4|l>>2,d=(3&l)<<6|p>>0;o[a]=h,64!=l&&(o[a+1]=f),64!=p&&(o[a+2]=d)}return r}function b(e){for(var t,n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=new Uint8Array(e),i=o.byteLength,s=i%3,a=i-s,u=0;u>18]+r[(258048&t)>>12]+r[(4032&t)>>6]+r[63&t];return 1==s?n+=r[(252&(t=o[a]))>>2]+r[(3&t)<<4]+"==":2==s&&(n+=r[(64512&(t=o[a]<<8|o[a+1]))>>10]+r[(1008&t)>>4]+r[(15&t)<<2]+"="),n}var v,_,S,w,O,P=P||function(e,t){var n={},r=n.lib={},o=function(){},i=r.Base={extend:function(e){o.prototype=this;var t=new o;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var o=0;o>>2]|=(n[o>>>2]>>>24-o%4*8&255)<<24-(r+o)%4*8;else if(65535>>2]=n[o>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r>>2]>>>24-r%4*8&255;n.push((o>>>4).toString(16)),n.push((15&o).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,a=o/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,o=e.min(4*t,o),t){for(var u=0;uc;){var l;e:{l=u;for(var p=e.sqrt(l),h=2;h<=p;h++)if(!(l%h)){l=!1;break e}l=!0}l&&(8>c&&(i[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var f=[];o=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],a=n[3],u=n[4],c=n[5],l=n[6],p=n[7],h=0;64>h;h++){if(16>h)f[h]=0|e[t+h];else{var d=f[h-15],y=f[h-2];f[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+f[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+f[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[h]+f[h],y=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=l,l=c,c=u,u=a+d|0,a=i,i=o,o=r,r=d+y|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+p|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(o),t.HmacSHA256=r._createHmacHelper(o)}(Math),_=(v=P).enc.Utf8,v.algo.HMAC=v.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=_.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,a=i.words,u=0;u>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;4>s&&o+.75*s>>6*(3-s)&63));if(t=r.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(r=n.charAt(64))&&-1!=(r=e.indexOf(r))&&(t=r);for(var r=[],o=0,i=0;i>>6-i%4*2;r[o>>>2]|=(s|a)<<24-o%4*8,o++}return w.create(r,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,r,o,i,s){return((e=e+(t&n|~t&r)+o+s)<>>32-i)+t}function n(e,t,n,r,o,i,s){return((e=e+(t&r|n&~r)+o+s)<>>32-i)+t}function r(e,t,n,r,o,i,s){return((e=e+(t^n^r)+o+s)<>>32-i)+t}function o(e,t,n,r,o,i,s){return((e=e+(n^(t|~r))+o+s)<>>32-i)+t}for(var i=P,s=(u=i.lib).WordArray,a=u.Hasher,u=i.algo,c=[],l=0;64>l;l++)c[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=a.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var s=0;16>s;s++){var a=e[u=i+s];e[u]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}s=this._hash.words;var u=e[i+0],l=(a=e[i+1],e[i+2]),p=e[i+3],h=e[i+4],f=e[i+5],d=e[i+6],y=e[i+7],g=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],_=e[i+12],S=e[i+13],w=e[i+14],O=e[i+15],P=t(P=s[0],T=s[1],A=s[2],E=s[3],u,7,c[0]),E=t(E,P,T,A,a,12,c[1]),A=t(A,E,P,T,l,17,c[2]),T=t(T,A,E,P,p,22,c[3]);P=t(P,T,A,E,h,7,c[4]),E=t(E,P,T,A,f,12,c[5]),A=t(A,E,P,T,d,17,c[6]),T=t(T,A,E,P,y,22,c[7]),P=t(P,T,A,E,g,7,c[8]),E=t(E,P,T,A,m,12,c[9]),A=t(A,E,P,T,b,17,c[10]),T=t(T,A,E,P,v,22,c[11]),P=t(P,T,A,E,_,7,c[12]),E=t(E,P,T,A,S,12,c[13]),A=t(A,E,P,T,w,17,c[14]),P=n(P,T=t(T,A,E,P,O,22,c[15]),A,E,a,5,c[16]),E=n(E,P,T,A,d,9,c[17]),A=n(A,E,P,T,v,14,c[18]),T=n(T,A,E,P,u,20,c[19]),P=n(P,T,A,E,f,5,c[20]),E=n(E,P,T,A,b,9,c[21]),A=n(A,E,P,T,O,14,c[22]),T=n(T,A,E,P,h,20,c[23]),P=n(P,T,A,E,m,5,c[24]),E=n(E,P,T,A,w,9,c[25]),A=n(A,E,P,T,p,14,c[26]),T=n(T,A,E,P,g,20,c[27]),P=n(P,T,A,E,S,5,c[28]),E=n(E,P,T,A,l,9,c[29]),A=n(A,E,P,T,y,14,c[30]),P=r(P,T=n(T,A,E,P,_,20,c[31]),A,E,f,4,c[32]),E=r(E,P,T,A,g,11,c[33]),A=r(A,E,P,T,v,16,c[34]),T=r(T,A,E,P,w,23,c[35]),P=r(P,T,A,E,a,4,c[36]),E=r(E,P,T,A,h,11,c[37]),A=r(A,E,P,T,y,16,c[38]),T=r(T,A,E,P,b,23,c[39]),P=r(P,T,A,E,S,4,c[40]),E=r(E,P,T,A,u,11,c[41]),A=r(A,E,P,T,p,16,c[42]),T=r(T,A,E,P,d,23,c[43]),P=r(P,T,A,E,m,4,c[44]),E=r(E,P,T,A,_,11,c[45]),A=r(A,E,P,T,O,16,c[46]),P=o(P,T=r(T,A,E,P,l,23,c[47]),A,E,u,6,c[48]),E=o(E,P,T,A,y,10,c[49]),A=o(A,E,P,T,w,15,c[50]),T=o(T,A,E,P,f,21,c[51]),P=o(P,T,A,E,_,6,c[52]),E=o(E,P,T,A,p,10,c[53]),A=o(A,E,P,T,b,15,c[54]),T=o(T,A,E,P,a,21,c[55]),P=o(P,T,A,E,g,6,c[56]),E=o(E,P,T,A,O,10,c[57]),A=o(A,E,P,T,d,15,c[58]),T=o(T,A,E,P,S,21,c[59]),P=o(P,T,A,E,h,6,c[60]),E=o(E,P,T,A,v,10,c[61]),A=o(A,E,P,T,l,15,c[62]),T=o(T,A,E,P,m,21,c[63]);s[0]=s[0]+P|0,s[1]=s[1]+T|0,s[2]=s[2]+A|0,s[3]=s[3]+E|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var i=e.floor(r/4294967296);for(n[15+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(o+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,r=0;4>r;r++)o=n[r],n[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(u),i.HmacMD5=a._createHmacHelper(u)}(Math),function(){var e,t=P,n=(e=t.lib).Base,r=e.WordArray,o=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),o=r.create(),i=o.words,s=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:u,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var p=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(u=(f.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return p.create({ciphertext:e,salt:n})}},t.SerializableCipher=n.extend({cfg:n.extend({format:u}),encrypt:function(e,t,n,r){r=this.cfg.extend(r);var o=e.createEncryptor(n,r);return t=o.finalize(t),o=o.cfg,p.create({ciphertext:t,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:r.format})},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),e.createDecryptor(n,r).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),f=(f.kdf={}).OpenSSL={execute:function(e,t,n,o){return o||(o=r.random(8)),e=s.create({keySize:t+n}).compute(e,o),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,p.create({key:e,iv:n,salt:o})}},d=t.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:f}),encrypt:function(e,t,n,r){return n=(r=this.cfg.extend(r)).kdf.execute(n,e.keySize,e.ivSize),r.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,r)).mixIn(n),e},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),n=r.kdf.execute(n,e.keySize,e.ivSize,t.salt),r.iv=n.iv,h.decrypt.call(this,e,t,n.key,r)}})}(),function(){for(var e=P,t=e.lib.BlockCipher,n=e.algo,r=[],o=[],i=[],s=[],a=[],u=[],c=[],l=[],p=[],h=[],f=[],d=0;256>d;d++)f[d]=128>d?d<<1:d<<1^283;var y=0,g=0;for(d=0;256>d;d++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;r[y]=m,o[m]=y;var b=f[y],v=f[b],_=f[v],S=257*f[m]^16843008*m;i[y]=S<<24|S>>>8,s[y]=S<<16|S>>>16,a[y]=S<<8|S>>>24,u[y]=S,S=16843009*_^65537*v^257*b^16843008*y,c[m]=S<<24|S>>>8,l[m]=S<<16|S>>>16,p[m]=S<<8|S>>>24,h[m]=S,y?(y=b^f[f[f[_^b]]],g^=f[f[g]]):y=g=1}var w=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),o=this._keySchedule=[],i=0;i>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s]):(s=r[(s=s<<8|s>>>24)>>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s],s^=w[i/t|0]<<24),o[i]=o[i-t]^s}for(e=this._invKeySchedule=[],t=0;tt||4>=i?s:c[r[s>>>24]]^l[r[s>>>16&255]]^p[r[s>>>8&255]]^h[r[255&s]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,s,a,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,c,l,p,h,o),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,r,o,i,s,a){for(var u=this._nRounds,c=e[t]^n[0],l=e[t+1]^n[1],p=e[t+2]^n[2],h=e[t+3]^n[3],f=4,d=1;d>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&h]^n[f++],g=r[l>>>24]^o[p>>>16&255]^i[h>>>8&255]^s[255&c]^n[f++],m=r[p>>>24]^o[h>>>16&255]^i[c>>>8&255]^s[255&l]^n[f++];h=r[h>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^n[f++],c=y,l=g,p=m}y=(a[c>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&h])^n[f++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[h>>>8&255]<<8|a[255&c])^n[f++],m=(a[p>>>24]<<24|a[h>>>16&255]<<16|a[c>>>8&255]<<8|a[255&l])^n[f++],h=(a[h>>>24]<<24|a[c>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^n[f++],e[t]=y,e[t+1]=g,e[t+2]=m,e[t+3]=h},keySize:8});e.AES=t._createHelper(n)}(),P.mode.ECB=((O=P.lib.BlockCipherMode.extend()).Encryptor=O.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),O.Decryptor=O.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),O);var E=P;function A(e){var t,n=[];for(t=0;t=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))},e.prototype.clearHistory=function(){this.hashHistory=[]},e}(),k={PNNetworkUpCategory:"PNNetworkUpCategory",PNNetworkDownCategory:"PNNetworkDownCategory",PNNetworkIssuesCategory:"PNNetworkIssuesCategory",PNTimeoutCategory:"PNTimeoutCategory",PNBadRequestCategory:"PNBadRequestCategory",PNAccessDeniedCategory:"PNAccessDeniedCategory",PNUnknownCategory:"PNUnknownCategory",PNReconnectedCategory:"PNReconnectedCategory",PNConnectedCategory:"PNConnectedCategory",PNRequestMessageCountExceededCategory:"PNRequestMessageCountExceededCategory",PNDisconnectedCategory:"PNDisconnectedCategory",PNConnectionErrorCategory:"PNConnectionErrorCategory",PNDisconnectedUnexpectedlyCategory:"PNDisconnectedUnexpectedlyCategory"},M=function(){function e(e){var t=e.subscribeEndpoint,n=e.leaveEndpoint,r=e.heartbeatEndpoint,o=e.setStateEndpoint,i=e.timeEndpoint,s=e.getFileUrl,a=e.config,u=e.crypto,c=e.listenerManager,l=e.cryptoModule,p=e.eventEmitter;this._listenerManager=c,this._config=a,this._leaveEndpoint=n,this._heartbeatEndpoint=r,this._setStateEndpoint=o,this._subscribeEndpoint=t,this._getFileUrl=s,this._crypto=u,this._cryptoModule=l,this._channels={},this._presenceChannels={},this._heartbeatChannels={},this._heartbeatChannelGroups={},this._channelGroups={},this._presenceChannelGroups={},this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[],this._currentTimetoken=0,this._lastTimetoken=0,this._storedTimetoken=null,this._subscriptionStatusAnnounced=!1,this._isOnline=!0,this._reconnectionManager=new N({timeEndpoint:i}),this._dedupingManager=new C({config:a}),this._cryptoModule&&(this._decoder=new TextDecoder),this._eventEmitter=p}return e.prototype.adaptStateChange=function(e,t){var n=this,r=e.state,o=e.channels,i=void 0===o?[]:o,s=e.channelGroups,a=void 0===s?[]:s,u=e.withHeartbeat,c=void 0!==u&&u;if(i.forEach((function(e){e in n._channels&&(n._channels[e].state=r)})),a.forEach((function(e){e in n._channelGroups&&(n._channelGroups[e].state=r)})),c){var l={};return i.forEach((function(e){return l[e]=r})),a.forEach((function(e){return l[e]=r})),this._heartbeatEndpoint({channels:i,channelGroups:a,state:l},t)}return this._setStateEndpoint({state:r,channels:i,channelGroups:a},t)},e.prototype.adaptPresenceChange=function(e){var t=this,n=e.connected,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i;n?(o.forEach((function(e){t._heartbeatChannels[e]={state:{}}})),s.forEach((function(e){t._heartbeatChannelGroups[e]={state:{}}}))):(o.forEach((function(e){e in t._heartbeatChannels&&delete t._heartbeatChannels[e]})),s.forEach((function(e){e in t._heartbeatChannelGroups&&delete t._heartbeatChannelGroups[e]})),!1===this._config.suppressLeaveEvents&&this._leaveEndpoint({channels:o,channelGroups:s},(function(e){t._listenerManager.announceStatus(e)}))),this.reconnect()},e.prototype.adaptSubscribeChange=function(e){var t=this,n=e.timetoken,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=e.withPresence,u=void 0!==a&&a,c=e.withHeartbeats,l=void 0!==c&&c;this._config.subscribeKey&&""!==this._config.subscribeKey?(n&&(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=n),"0"!==this._currentTimetoken&&0!==this._currentTimetoken&&(this._storedTimetoken=this._currentTimetoken,this._currentTimetoken=0),o.forEach((function(e){t._channels[e]={state:{}},u&&(t._presenceChannels[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannels[e]={}),t._pendingChannelSubscriptions.push(e)})),s.forEach((function(e){t._channelGroups[e]={state:{}},u&&(t._presenceChannelGroups[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannelGroups[e]={}),t._pendingChannelGroupSubscriptions.push(e)})),this._subscriptionStatusAnnounced=!1,this.reconnect()):console&&console.log&&console.log("subscribe key missing; aborting subscribe")},e.prototype.adaptUnsubscribeChange=function(e,t){var n=this,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=[],u=[];o.forEach((function(e){e in n._channels&&(delete n._channels[e],a.push(e),e in n._heartbeatChannels&&delete n._heartbeatChannels[e]),e in n._presenceChannels&&(delete n._presenceChannels[e],a.push(e))})),s.forEach((function(e){e in n._channelGroups&&(delete n._channelGroups[e],u.push(e),e in n._heartbeatChannelGroups&&delete n._heartbeatChannelGroups[e]),e in n._presenceChannelGroups&&(delete n._presenceChannelGroups[e],u.push(e))})),0===a.length&&0===u.length||(!1!==this._config.suppressLeaveEvents||t||this._leaveEndpoint({channels:a,channelGroups:u},(function(e){e.affectedChannels=a,e.affectedChannelGroups=u,e.currentTimetoken=n._currentTimetoken,e.lastTimetoken=n._lastTimetoken,n._listenerManager.announceStatus(e)})),0===Object.keys(this._channels).length&&0===Object.keys(this._presenceChannels).length&&0===Object.keys(this._channelGroups).length&&0===Object.keys(this._presenceChannelGroups).length&&(this._lastTimetoken=0,this._currentTimetoken=0,this._storedTimetoken=null,this._region=null,this._reconnectionManager.stopPolling()),this.reconnect())},e.prototype.unsubscribeAll=function(e){this.adaptUnsubscribeChange({channels:this.getSubscribedChannels(),channelGroups:this.getSubscribedChannelGroups()},e)},e.prototype.getHeartbeatChannels=function(){return Object.keys(this._heartbeatChannels)},e.prototype.getHeartbeatChannelGroups=function(){return Object.keys(this._heartbeatChannelGroups)},e.prototype.getSubscribedChannels=function(){return Object.keys(this._channels)},e.prototype.getSubscribedChannelGroups=function(){return Object.keys(this._channelGroups)},e.prototype.reconnect=function(){this._startSubscribeLoop(),this._registerHeartbeatTimer()},e.prototype.disconnect=function(){this._stopSubscribeLoop(),this._stopHeartbeatTimer(),this._reconnectionManager.stopPolling()},e.prototype._registerHeartbeatTimer=function(){this._stopHeartbeatTimer(),0!==this._config.getHeartbeatInterval()&&void 0!==this._config.getHeartbeatInterval()&&(this._performHeartbeatLoop(),this._heartbeatTimer=setInterval(this._performHeartbeatLoop.bind(this),1e3*this._config.getHeartbeatInterval()))},e.prototype._stopHeartbeatTimer=function(){this._heartbeatTimer&&(clearInterval(this._heartbeatTimer),this._heartbeatTimer=null)},e.prototype._performHeartbeatLoop=function(){var e=this,t=this.getHeartbeatChannels(),n=this.getHeartbeatChannelGroups(),r={};if(0!==t.length||0!==n.length){this.getSubscribedChannels().forEach((function(t){var n=e._channels[t].state;Object.keys(n).length&&(r[t]=n)})),this.getSubscribedChannelGroups().forEach((function(t){var n=e._channelGroups[t].state;Object.keys(n).length&&(r[t]=n)}));this._heartbeatEndpoint({channels:t,channelGroups:n,state:r},function(t){t.error&&e._config.announceFailedHeartbeats&&e._listenerManager.announceStatus(t),t.error&&e._config.autoNetworkDetection&&e._isOnline&&(e._isOnline=!1,e.disconnect(),e._listenerManager.announceNetworkDown(),e.reconnect()),!t.error&&e._config.announceSuccessfulHeartbeats&&e._listenerManager.announceStatus(t)}.bind(this))}},e.prototype._startSubscribeLoop=function(){var e=this;this._stopSubscribeLoop();var t={},n=[],r=[];if(Object.keys(this._channels).forEach((function(r){var o=e._channels[r].state;Object.keys(o).length&&(t[r]=o),n.push(r)})),Object.keys(this._presenceChannels).forEach((function(e){n.push("".concat(e,"-pnpres"))})),Object.keys(this._channelGroups).forEach((function(n){var o=e._channelGroups[n].state;Object.keys(o).length&&(t[n]=o),r.push(n)})),Object.keys(this._presenceChannelGroups).forEach((function(e){r.push("".concat(e,"-pnpres"))})),0!==n.length||0!==r.length){var o={channels:n,channelGroups:r,state:t,timetoken:this._currentTimetoken,filterExpression:this._config.filterExpression,region:this._region};this._subscribeCall=this._subscribeEndpoint(o,this._processSubscribeResponse.bind(this))}},e.prototype._processSubscribeResponse=function(e,t){var n=this;if(e.error){if(e.errorData&&"Aborted"===e.errorData.message)return;e.category===k.PNTimeoutCategory?this._startSubscribeLoop():e.category===k.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this._config.autoNetworkDetection&&this._isOnline&&(this._isOnline=!1,this._listenerManager.announceNetworkDown()),this._reconnectionManager.onReconnection((function(){n._config.autoNetworkDetection&&!n._isOnline&&(n._isOnline=!0,n._listenerManager.announceNetworkUp()),n.reconnect(),n._subscriptionStatusAnnounced=!0;var t={category:k.PNReconnectedCategory,operation:e.operation,lastTimetoken:n._lastTimetoken,currentTimetoken:n._currentTimetoken};n._listenerManager.announceStatus(t)})),this._reconnectionManager.startPolling(),this._listenerManager.announceStatus(e)):e.category===k.PNBadRequestCategory?(this._stopHeartbeatTimer(),this._listenerManager.announceStatus(e)):this._listenerManager.announceStatus(e)}else{if(this._storedTimetoken?(this._currentTimetoken=this._storedTimetoken,this._storedTimetoken=null):(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=t.metadata.timetoken),!this._subscriptionStatusAnnounced){var r={};r.category=k.PNConnectedCategory,r.operation=e.operation,r.affectedChannels=this._pendingChannelSubscriptions,r.subscribedChannels=this.getSubscribedChannels(),r.affectedChannelGroups=this._pendingChannelGroupSubscriptions,r.lastTimetoken=this._lastTimetoken,r.currentTimetoken=this._currentTimetoken,this._subscriptionStatusAnnounced=!0,this._listenerManager.announceStatus(r),this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[]}var o=t.messages||[],i=this._config,s=i.requestMessageCountThreshold,a=i.dedupeOnSubscribe;if(s&&o.length>=s){var u={};u.category=k.PNRequestMessageCountExceededCategory,u.operation=e.operation,this._listenerManager.announceStatus(u)}o.forEach((function(e){if(e.channel,e.subscriptionMatch,a){if(n._dedupingManager.isDuplicate(e))return;n._dedupingManager.addEntry(e)}n._eventEmitter.emitEvent(e)})),this._region=t.metadata.region,this._startSubscribeLoop()}},e.prototype._stopSubscribeLoop=function(){this._subscribeCall&&("function"==typeof this._subscribeCall.abort&&this._subscribeCall.abort(),this._subscribeCall=null)},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),j={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",PNAccessManagerRevokeToken:"PNAccessManagerRevokeToken",PNHandshakeOperation:"PNHandshakeOperation",PNReceiveMessagesOperation:"PNReceiveMessagesOperation"},R=function(){function e(e){this._maximumSamplesCount=100,this._trackedLatencies={},this._latencies={},this._telemetryExcludeOperations=[j.PNSubscribeOperation,j.PNReceiveMessagesOperation,j.PNHandshakeOperation],this._maximumSamplesCount=e.maximumSamplesCount||this._maximumSamplesCount}return e.prototype.operationsLatencyForRequest=function(){var e=this,t={};return Object.keys(this._latencies).forEach((function(n){var r=e._latencies[n],o=e._averageLatency(r);o>0&&(t["l_".concat(n)]=o)})),t},e.prototype.startLatencyMeasure=function(e,t){!this._telemetryExcludeOperations.includes(e)&&t&&(this._trackedLatencies[t]=Date.now())},e.prototype.stopLatencyMeasure=function(e,t){if(!this._telemetryExcludeOperations.includes(e)&&t){var n=this._endpointName(e),r=this._latencies[n],o=this._trackedLatencies[t];r||(this._latencies[n]=[],r=this._latencies[n]),r.push(Date.now()-o),r.length>this._maximumSamplesCount&&r.splice(0,r.length-this._maximumSamplesCount),delete this._trackedLatencies[t]}},e.prototype._averageLatency=function(e){return Math.floor(e.reduce((function(e,t){return e+t}),0)/e.length)},e.prototype._endpointName=function(e){var t=null;switch(e){case j.PNPublishOperation:t="pub";break;case j.PNSignalOperation:t="sig";break;case j.PNHistoryOperation:case j.PNFetchMessagesOperation:case j.PNDeleteMessagesOperation:case j.PNMessageCounts:t="hist";break;case j.PNUnsubscribeOperation:case j.PNWhereNowOperation:case j.PNHereNowOperation:case j.PNHeartbeatOperation:case j.PNSetStateOperation:case j.PNGetStateOperation:t="pres";break;case j.PNAddChannelsToGroupOperation:case j.PNRemoveChannelsFromGroupOperation:case j.PNChannelGroupsOperation:case j.PNRemoveGroupOperation:case j.PNChannelsForGroupOperation:t="cg";break;case j.PNPushNotificationEnabledChannelsOperation:case j.PNRemoveAllPushNotificationsOperation:t="push";break;case j.PNCreateUserOperation:case j.PNUpdateUserOperation:case j.PNDeleteUserOperation:case j.PNGetUserOperation:case j.PNGetUsersOperation:case j.PNCreateSpaceOperation:case j.PNUpdateSpaceOperation:case j.PNDeleteSpaceOperation:case j.PNGetSpaceOperation:case j.PNGetSpacesOperation:case j.PNGetMembersOperation:case j.PNUpdateMembersOperation:case j.PNGetMembershipsOperation:case j.PNUpdateMembershipsOperation:t="obj";break;case j.PNAddMessageActionOperation:case j.PNRemoveMessageActionOperation:case j.PNGetMessageActionsOperation:t="msga";break;case j.PNAccessManagerGrant:case j.PNAccessManagerAudit:t="pam";break;case j.PNAccessManagerGrantToken:case j.PNAccessManagerRevokeToken:t="pamv3";break;default:t="time"}return t},e}(),x=function(){function e(e,t,n){this._payload=e,this._setDefaultPayloadStructure(),this.title=t,this.body=n}return Object.defineProperty(e.prototype,"payload",{get:function(){return this._payload},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{set:function(e){this._title=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{set:function(e){this._subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{set:function(e){this._body=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{set:function(e){this._badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{set:function(e){this._sound=e},enumerable:!1,configurable:!0}),e.prototype._setDefaultPayloadStructure=function(){},e.prototype.toObject=function(){return{}},e}(),U=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"configurations",{set:function(e){e&&e.length&&(this._configurations=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"notification",{get:function(){return this._payload.aps},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.aps.alert.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){e&&e.length&&(this._payload.aps.alert.subtitle=e,this._subtitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.aps.alert.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this._badge},set:function(e){null!=e&&(this._payload.aps.badge=e,this._badge=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.aps.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),r.prototype._setDefaultPayloadStructure=function(){this._payload.aps={alert:{}}},r.prototype.toObject=function(){var e=this,t=n({},this._payload),r=t.aps,o=r.alert;if(this._isSilent&&(r["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");var i=[];this._configurations.forEach((function(t){i.push(e._objectFromAPNS2Configuration(t))})),i.length&&(t.pn_push=i)}return o&&Object.keys(o).length||delete r.alert,this._isSilent&&(delete r.alert,delete r.badge,delete r.sound,o={}),this._isSilent||Object.keys(o).length?t:null},r.prototype._objectFromAPNS2Configuration=function(e){var t=this;if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");var n=[];e.targets.forEach((function(e){n.push(t._objectFromAPNSTarget(e))}));var r=e.collapseId,o=e.expirationDate,i={auth_method:"token",targets:n,version:"v2"};return r&&r.length&&(i.collapse_id=r),o&&(i.expiration=o.toISOString()),i},r.prototype._objectFromAPNSTarget=function(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");var t=e.topic,n=e.environment,r=void 0===n?"development":n,o=e.excludedDevices,i=void 0===o?[]:o,s={topic:t,environment:r};return i.length&&(s.excluded_devices=i),s},r}(x),I=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"backContent",{get:function(){return this._backContent},set:function(e){e&&e.length&&(this._payload.back_content=e,this._backContent=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"backTitle",{get:function(){return this._backTitle},set:function(e){e&&e.length&&(this._payload.back_title=e,this._backTitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"count",{get:function(){return this._count},set:function(e){null!=e&&(this._payload.count=e,this._count=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"type",{get:function(){return this._type},set:function(e){e&&e.length&&(this._payload.type=e,this._type=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this.backTitle},set:function(e){this.backTitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this.backContent},set:function(e){this.backContent=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this.count},set:function(e){this.count=e},enumerable:!1,configurable:!0}),r.prototype.toObject=function(){return Object.keys(this._payload).length?n({},this._payload):null},r}(x),D=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return t(o,e),Object.defineProperty(o.prototype,"notification",{get:function(){return this._payload.notification},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"data",{get:function(){return this._payload.data},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.notification.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.notification.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.notification.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"icon",{get:function(){return this._icon},set:function(e){e&&e.length&&(this._payload.notification.icon=e,this._icon=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"tag",{get:function(){return this._tag},set:function(e){e&&e.length&&(this._payload.notification.tag=e,this._tag=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),o.prototype._setDefaultPayloadStructure=function(){this._payload.notification={},this._payload.data={}},o.prototype.toObject=function(){var e=n({},this._payload.data),t=null,o={};if(Object.keys(this._payload).length>2){var i=this._payload;i.notification,i.data;var s=r(i,["notification","data"]);e=n(n({},e),s)}return this._isSilent?e.notification=this._payload.notification:t=this._payload.notification,Object.keys(e).length&&(o.data=e),t&&Object.keys(t).length&&(o.notification=t),Object.keys(o).length?o:null},o}(x),F=function(){function e(e,t){this._payload={apns:{},mpns:{},fcm:{}},this._title=e,this._body=t,this.apns=new U(this._payload.apns,e,t),this.mpns=new I(this._payload.mpns,e,t),this.fcm=new D(this._payload.fcm,e,t)}return Object.defineProperty(e.prototype,"debugging",{set:function(e){this._debugging=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this._body},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){this._subtitle=e,this.apns.subtitle=e,this.mpns.subtitle=e,this.fcm.subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{get:function(){return this._badge},set:function(e){this._badge=e,this.apns.badge=e,this.mpns.badge=e,this.fcm.badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{get:function(){return this._sound},set:function(e){this._sound=e,this.apns.sound=e,this.mpns.sound=e,this.fcm.sound=e},enumerable:!1,configurable:!0}),e.prototype.buildPayload=function(e){var t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";var n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("mpns")){var r=this.mpns.toObject();r&&Object.keys(r).length&&(t.pn_mpns=r)}if(e.includes("fcm")){var o=this.fcm.toObject();o&&Object.keys(o).length&&(t.pn_gcm=o)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t},e}(),L=function(){function e(){this._listeners=[]}return e.prototype.addListener=function(e){this._listeners.includes(e)||this._listeners.push(e)},e.prototype.removeListener=function(e){var t=[];this._listeners.forEach((function(n){n!==e&&t.push(n)})),this._listeners=t},e.prototype.removeAllListeners=function(){this._listeners=[]},e.prototype.announcePresence=function(e){this._listeners.forEach((function(t){t.presence&&t.presence(e)}))},e.prototype.announceStatus=function(e){this._listeners.forEach((function(t){t.status&&t.status(e)}))},e.prototype.announceMessage=function(e){this._listeners.forEach((function(t){t.message&&t.message(e)}))},e.prototype.announceSignal=function(e){this._listeners.forEach((function(t){t.signal&&t.signal(e)}))},e.prototype.announceMessageAction=function(e){this._listeners.forEach((function(t){t.messageAction&&t.messageAction(e)}))},e.prototype.announceFile=function(e){this._listeners.forEach((function(t){t.file&&t.file(e)}))},e.prototype.announceObjects=function(e){this._listeners.forEach((function(t){t.objects&&t.objects(e)}))},e.prototype.announceUser=function(e){this._listeners.forEach((function(t){t.user&&t.user(e)}))},e.prototype.announceSpace=function(e){this._listeners.forEach((function(t){t.space&&t.space(e)}))},e.prototype.announceMembership=function(e){this._listeners.forEach((function(t){t.membership&&t.membership(e)}))},e.prototype.announceNetworkUp=function(){var e={};e.category=k.PNNetworkUpCategory,this.announceStatus(e)},e.prototype.announceNetworkDown=function(){var e={};e.category=k.PNNetworkDownCategory,this.announceStatus(e)},e}(),G=function(){function e(e,t){this._config=e,this._cbor=t}return e.prototype.setToken=function(e){e&&e.length>0?this._token=e:this._token=void 0},e.prototype.getToken=function(){return this._token},e.prototype.extractPermissions=function(e){var t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128==(128&e)&&(t.join=!0),64==(64&e)&&(t.update=!0),32==(32&e)&&(t.get=!0),8==(8&e)&&(t.delete=!0),4==(4&e)&&(t.manage=!0),2==(2&e)&&(t.write=!0),1==(1&e)&&(t.read=!0),t},e.prototype.parseToken=function(e){var t=this,n=this._cbor.decodeToken(e);if(void 0!==n){var r=n.res.uuid?Object.keys(n.res.uuid):[],o=Object.keys(n.res.chan),i=Object.keys(n.res.grp),s=n.pat.uuid?Object.keys(n.pat.uuid):[],a=Object.keys(n.pat.chan),u=Object.keys(n.pat.grp),c={version:n.v,timestamp:n.t,ttl:n.ttl,authorized_uuid:n.uuid},l=r.length>0,p=o.length>0,h=i.length>0;(l||p||h)&&(c.resources={},l&&(c.resources.uuids={},r.forEach((function(e){c.resources.uuids[e]=t.extractPermissions(n.res.uuid[e])}))),p&&(c.resources.channels={},o.forEach((function(e){c.resources.channels[e]=t.extractPermissions(n.res.chan[e])}))),h&&(c.resources.groups={},i.forEach((function(e){c.resources.groups[e]=t.extractPermissions(n.res.grp[e])}))));var f=s.length>0,d=a.length>0,y=u.length>0;return(f||d||y)&&(c.patterns={},f&&(c.patterns.uuids={},s.forEach((function(e){c.patterns.uuids[e]=t.extractPermissions(n.pat.uuid[e])}))),d&&(c.patterns.channels={},a.forEach((function(e){c.patterns.channels[e]=t.extractPermissions(n.pat.chan[e])}))),y&&(c.patterns.groups={},u.forEach((function(e){c.patterns.groups[e]=t.extractPermissions(n.pat.grp[e])})))),Object.keys(n.meta).length>0&&(c.meta=n.meta),c.signature=n.sig,c}},e}();function K(e){return encodeURIComponent(e).replace(/[!~*'()]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())}))}function B(e){return function(e){var t=[];return Object.keys(e).forEach((function(e){return t.push(e)})),t}(e).sort()}var H={signPamFromParams:function(e){return B(e).map((function(t){return"".concat(t,"=").concat(K(e[t]))})).join("&")},endsWith:function(e,t){return-1!==e.indexOf(t,this.length-t.length)},createPromise:function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),reject:t,fulfill:e}},encodeString:K,stringToArrayBuffer:function(e){for(var t=new ArrayBuffer(2*e.length),n=new Uint16Array(t),r=0,o=e.length;r0&&(t+=n),t}function J(e,t,n){return t.usePost&&t.usePost(e,n)?"POST":t.usePatch&&t.usePatch(e,n)?"PATCH":t.useDelete&&t.useDelete(e,n)?"DELETE":t.useGetFile&&t.useGetFile(e,n)?"GETFILE":"GET"}function $(e,t,n,r,o){var i=e.config,s=e.crypto,a=J(e,o,r);n.timestamp=Math.floor((new Date).getTime()/1e3),"PNPublishOperation"===o.getOperation()&&o.usePost&&o.usePost(e,r)&&(a="GET"),"GETFILE"===a&&(a="GET");var u="".concat(a,"\n").concat(i.publishKey,"\n").concat(t,"\n").concat(H.signPamFromParams(n),"\n");if("POST"===a)u+="string"==typeof(c=o.postPayload(e,r))?c:JSON.stringify(c);else if("PATCH"===a){var c;u+="string"==typeof(c=o.patchPayload(e,r))?c:JSON.stringify(c)}var l="v2.".concat(s.HMACSHA256(u));l=(l=(l=l.replace(/\+/g,"-")).replace(/\//g,"_")).replace(/=+$/,""),n.signature=l}function Q(e,t){for(var r=[],o=2;o0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/leave")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(){return{}}});var ae=Object.freeze({__proto__:null,getOperation:function(){return j.PNWhereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r;return"/v2/presence/sub-key/".concat(n.subscribeKey,"/uuid/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return t.payload?{channels:t.payload.channels}:{channels:[]}}});var ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNHeartbeatOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/heartbeat")},isAuthSupported:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o=t.state,i=e.config,s={};return r.length>0&&(s["channel-group"]=r.join(",")),o&&(s.state=JSON.stringify(o)),s.heartbeat=i.getPresenceTimeout(),s},handleResponse:function(){return{}}});var ce=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetStateOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r,i=t.channels,s=void 0===i?[]:i,a=s.length>0?s.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(a),"/uuid/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a={};return 1===o.length&&0===s.length?a[o[0]]=t.payload:a=t.payload,{channels:a}}});var le=Object.freeze({__proto__:null,getOperation:function(){return j.PNSetStateOperation},validateParams:function(e,t){var n=e.config,r=t.state,o=t.channels,i=void 0===o?[]:o,s=t.channelGroups,a=void 0===s?[]:s;return r?n.subscribeKey?0===i.length&&0===a.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key":"Missing State"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/uuid/").concat(H.encodeString(n.UUID),"/data")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.state,r=t.channelGroups,o=void 0===r?[]:r,i={};return i.state=JSON.stringify(n),o.length>0&&(i["channel-group"]=o.join(",")),i},handleResponse:function(e,t){return{state:t.payload}}});var pe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=t.channelGroups,s=void 0===i?[]:i,a="/v2/presence/sub-key/".concat(n.subscribeKey);if(o.length>0||s.length>0){var u=o.length>0?o.join(","):",";a+="/channel/".concat(H.encodeString(u))}return a},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.channelGroups,o=void 0===r?[]:r,i=t.includeUUIDs,s=void 0===i||i,a=t.includeState,u=void 0!==a&&a,c=t.queryParameters,l=void 0===c?{}:c,p={};return s||(p.disable_uuids=1),u&&(p.state=1),o.length>0&&(p["channel-group"]=o.join(",")),p=n(n({},p),l)},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a=n.includeUUIDs,u=void 0===a||a,c=n.includeState,l=void 0!==c&&c;return o.length>1||s.length>0||0===s.length&&0===o.length?function(){var e={};return e.totalChannels=t.payload.total_channels,e.totalOccupancy=t.payload.total_occupancy,e.channels={},Object.keys(t.payload.channels).forEach((function(n){var r=t.payload.channels[n],o=[];return e.channels[n]={occupants:o,name:n,occupancy:r.occupancy},u&&r.uuids.forEach((function(e){l?o.push({state:e.state,uuid:e.uuid}):o.push({state:null,uuid:e})})),e})),e}():function(){var e={},n=[];return e.totalChannels=1,e.totalOccupancy=t.occupancy,e.channels={},e.channels[o[0]]={occupants:n,name:o[0],occupancy:t.occupancy},u&&t.uuids&&t.uuids.forEach((function(e){l?n.push({state:e.state,uuid:e.uuid}):n.push({state:null,uuid:e})})),e}()},handleError:function(e,t,n){402!==n.statusCode||this.getURL(e,t).includes("channel")||(n.errorData.message="You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.")}});var he=Object.freeze({__proto__:null,getOperation:function(){return j.PNAddMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.action,o=t.channel;return t.messageTimetoken?n.subscribeKey?o?r?r.value?r.type?r.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message channel":"Missing Subscribe Key":"Missing message timetoken"},usePost:function(){return!0},postURL:function(e,t){var n=e.config,r=t.channel,o=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},getRequestHeaders:function(){return{"Content-Type":"application/json"}},isAuthSupported:function(){return!0},prepareParams:function(){return{}},postPayload:function(e,t){return t.action},handleResponse:function(e,t){return{data:t.data}}});var fe=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken;return t.messageTimetoken?o?n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key":"Missing action timetoken":"Missing message timetoken"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken,i=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(i,"/action/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{data:t.data}}});var de=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetMessageActionsOperation},validateParams:function(e,t){var n=e.config,r=t.channel;return n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channel;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.limit,r=t.start,o=t.end,i={};return n&&(i.limit=n),r&&(i.start=r),o&&(i.end=o),i},handleResponse:function(e,t){var n={data:t.data,start:null,end:null};return n.data.length&&(n.end=n.data[n.data.length-1].actionTimetoken,n.start=n.data[0].actionTimetoken),n}}),ye={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel can't be empty"},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.limit&&(n.limit=t.limit),t.next&&(n.next=t.next),n},handleResponse:function(e,t){return{status:t.status,data:t.data,next:t.next,count:t.count}}},ge={getOperation:function(){return j.PNGenerateUploadUrlOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?void 0:"name can't be empty":"channel can't be empty"},usePost:function(){return!0},postURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/generate-upload-url")},postPayload:function(e,t){return{name:t.name}},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data,file_upload_request:t.file_upload_request}}},me={getOperation:function(){return j.PNPublishFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.fileId)?(null==t?void 0:t.fileName)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},getURL:function(e,t){var n=e.config,r=n.publishKey,o=n.subscribeKey,i=function(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}(e,{message:t.message,file:{name:t.fileName,id:t.fileId}});return"/v1/files/publish-file/".concat(r,"/").concat(o,"/0/").concat(H.encodeString(t.channel),"/0/").concat(H.encodeString(i))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.ttl&&(n.ttl=t.ttl),void 0!==t.storeInHistory&&(n.store=t.storeInHistory?"1":"0"),t.meta&&"object"==typeof t.meta&&(n.meta=JSON.stringify(t.meta)),n},handleResponse:function(e,t){return{timetoken:t[2]}}},be=function(e){var t=function(e){var t=this,n=e.generateUploadUrl,r=e.publishFile,s=e.modules,a=s.PubNubFile,u=s.config,c=s.cryptography,l=s.cryptoModule,p=s.networking;return function(e){var s=e.channel,h=e.file,f=e.message,d=e.cipherKey,y=e.meta,g=e.ttl,m=e.storeInHistory;return o(t,void 0,void 0,(function(){var e,t,o,b,v,_,S,w,O,P,E,A,T,N,C,k,M,j,R,x,U,I,D,F,L,G,K,B,H;return i(this,(function(i){switch(i.label){case 0:if(!s)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!h)throw new q("Validation failed, check status for details",z("file can't be empty"));return e=a.create(h),[4,n({channel:s,name:e.name})];case 1:return t=i.sent(),o=t.file_upload_request,b=o.url,v=o.form_fields,_=t.data,S=_.id,w=_.name,a.supportsEncryptFile&&(d||l)?null!=d?[3,3]:[4,l.encryptFile(e,a)]:[3,6];case 2:return O=i.sent(),[3,5];case 3:return[4,c.encryptFile(d,e,a)];case 4:O=i.sent(),i.label=5;case 5:e=O,i.label=6;case 6:P=v,e.mimeType&&(P=v.map((function(t){return"Content-Type"===t.key?{key:t.key,value:e.mimeType}:t}))),i.label=7;case 7:return i.trys.push([7,21,,22]),a.supportsFileUri&&h.uri?(T=(A=p).POSTFILE,N=[b,P],[4,e.toFileUri()]):[3,10];case 8:return[4,T.apply(A,N.concat([i.sent()]))];case 9:return E=i.sent(),[3,20];case 10:return a.supportsFile?(k=(C=p).POSTFILE,M=[b,P],[4,e.toFile()]):[3,13];case 11:return[4,k.apply(C,M.concat([i.sent()]))];case 12:return E=i.sent(),[3,20];case 13:return a.supportsBuffer?(R=(j=p).POSTFILE,x=[b,P],[4,e.toBuffer()]):[3,16];case 14:return[4,R.apply(j,x.concat([i.sent()]))];case 15:return E=i.sent(),[3,20];case 16:return a.supportsBlob?(I=(U=p).POSTFILE,D=[b,P],[4,e.toBlob()]):[3,19];case 17:return[4,I.apply(U,D.concat([i.sent()]))];case 18:return E=i.sent(),[3,20];case 19:throw new Error("Unsupported environment");case 20:return[3,22];case 21:throw(F=i.sent()).response&&"string"==typeof F.response.text?(L=F.response.text,G=/(.*)<\/Message>/gi.exec(L),new q(G?"Upload to bucket failed: ".concat(G[1]):"Upload to bucket failed.",F)):new q("Upload to bucket failed.",F);case 22:if(204!==E.status)throw new q("Upload to bucket was unsuccessful",E);K=u.fileUploadPublishRetryLimit,B=!1,H={timetoken:"0"},i.label=23;case 23:return i.trys.push([23,25,,26]),[4,r({channel:s,message:f,fileId:S,fileName:w,meta:y,storeInHistory:m,ttl:g})];case 24:return H=i.sent(),B=!0,[3,26];case 25:return i.sent(),K-=1,[3,26];case 26:if(!B&&K>0)return[3,23];i.label=27;case 27:if(B)return[2,{timetoken:H.timetoken,id:S,name:w}];throw new q("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{channel:s,id:S,name:w})}}))}))}}(e);return function(e,n){var r=t(e);return"function"==typeof n?(r.then((function(e){return n(null,e)})).catch((function(e){return n(e,null)})),r):r}},ve=function(e,t){var n=t.channel,r=t.id,o=t.name,i=e.config,s=e.networking,a=e.tokenManager;if(!n)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!r)throw new q("Validation failed, check status for details",z("file id can't be empty"));if(!o)throw new q("Validation failed, check status for details",z("file name can't be empty"));var u="/v1/files/".concat(i.subscribeKey,"/channels/").concat(H.encodeString(n),"/files/").concat(r,"/").concat(o),c={};c.uuid=i.getUUID(),c.pnsdk=W(i);var l=a.getToken()||i.getAuthKey();l&&(c.auth=l),i.secretKey&&$(e,u,c,{},{getOperation:function(){return"PubNubGetFileUrlOperation"}});var p=Object.keys(c).map((function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(c[e]))})).join("&");return""!==p?"".concat(s.getStandardOrigin()).concat(u,"?").concat(p):"".concat(s.getStandardOrigin()).concat(u)},_e={getOperation:function(){return j.PNDownloadFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?(null==t?void 0:t.id)?void 0:"id can't be empty":"name can't be empty":"channel can't be empty"},useGetFile:function(){return!0},getFileURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},ignoreBody:function(){return!0},forceBuffered:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t,n){var r=e.PubNubFile,s=e.config,a=e.cryptography,u=e.cryptoModule;return o(void 0,void 0,void 0,(function(){var e,o,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.response.body,r.supportsEncryptFile&&(n.cipherKey||u)?null!=n.cipherKey?[3,2]:[4,u.decryptFile(r.create({data:e,name:n.name}),r)]:[3,5];case 1:return o=i.sent().data,[3,4];case 2:return[4,a.decrypt(null!==(c=n.cipherKey)&&void 0!==c?c:s.cipherKey,e)];case 3:o=i.sent(),i.label=4;case 4:e=o,i.label=5;case 5:return[2,r.create({data:e,name:null!==(l=t.response.name)&&void 0!==l?l:n.name,mimeType:t.response.type})]}}))}))}},Se={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.id)?(null==t?void 0:t.name)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status}}},we={getOperation:function(){return j.PNGetAllUUIDMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,next:t.next,prev:t.prev}}},Oe={getOperation:function(){return j.PNGetUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Pe={getOperation:function(){return j.PNSetUUIDMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.data))return"Data cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ee={getOperation:function(){return j.PNRemoveUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r=e.config;return{uuid:null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ae={getOperation:function(){return j.PNGetAllChannelMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Te={getOperation:function(){return j.PNGetChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ne={getOperation:function(){return j.PNSetChannelMetadataOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.data)?void 0:"Data cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ce={getOperation:function(){return j.PNRemoveChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},ke={getOperation:function(){return j.PNGetMembersOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&m.include.push("uuid"),(null===(i=t.include)||void 0===i?void 0:i.customUUIDFields)&&m.include.push("uuid.custom"),(null===(s=t.include)||void 0===s?void 0:s.UUIDStatusField)&&m.include.push("uuid.status"),(null===(u=t.include)||void 0===u?void 0:u.UUIDTypeField)&&m.include.push("uuid.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Me={getOperation:function(){return j.PNSetMembersOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.uuids)&&0!==(null==t?void 0:t.uuids.length)?void 0:"UUIDs cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.uuids.map((function(e){return"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["uuid.status","uuid.type","type"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customUUIDFields)&&h.include.push("uuid.custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&h.include.push("uuid")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},je={getOperation:function(){return j.PNGetMembershipsOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&m.include.push("channel"),(null===(i=t.include)||void 0===i?void 0:i.customChannelFields)&&m.include.push("channel.custom"),(null===(s=t.include)||void 0===s?void 0:s.channelStatusField)&&m.include.push("channel.status"),(null===(u=t.include)||void 0===u?void 0:u.channelTypeField)&&m.include.push("channel.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Re={getOperation:function(){return j.PNSetMembershipsOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)||0===(null==t?void 0:t.channels.length))return"Channels cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.channels.map((function(e){return"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["channel.status","channel.type","status"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customChannelFields)&&h.include.push("channel.custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&h.include.push("channel")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}};var xe=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerAudit},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/audit/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channel,r=t.channelGroup,o=t.authKeys,i=void 0===o?[]:o,s={};return n&&(s.channel=n),r&&(s["channel-group"]=r),i.length>0&&(s.auth=i.join(",")),s},handleResponse:function(e,t){return t.payload}});var Ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrant},validateParams:function(e,t){var n=e.config;return n.subscribeKey?n.publishKey?n.secretKey?null==t.uuids||t.authKeys?null==t.uuids||null==t.channels&&null==t.channelGroups?void 0:"Both channel/channelgroup and uuid cannot be used in the same request":"authKeys are required for grant request on uuids":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/grant/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.uuids,a=void 0===s?[]:s,u=t.ttl,c=t.read,l=void 0!==c&&c,p=t.write,h=void 0!==p&&p,f=t.manage,d=void 0!==f&&f,y=t.get,g=void 0!==y&&y,m=t.join,b=void 0!==m&&m,v=t.update,_=void 0!==v&&v,S=t.authKeys,w=void 0===S?[]:S,O=t.delete,P={};return P.r=l?"1":"0",P.w=h?"1":"0",P.m=d?"1":"0",P.d=O?"1":"0",P.g=g?"1":"0",P.j=b?"1":"0",P.u=_?"1":"0",r.length>0&&(P.channel=r.join(",")),i.length>0&&(P["channel-group"]=i.join(",")),w.length>0&&(P.auth=w.join(",")),a.length>0&&(P["target-uuid"]=a.join(",")),(u||0===u)&&(P.ttl=u),P},handleResponse:function(){return{}}});function Ie(e){var t,n,r,o,i=void 0!==(null==e?void 0:e.authorizedUserId),s=void 0!==(null===(t=null==e?void 0:e.resources)||void 0===t?void 0:t.users),a=void 0!==(null===(n=null==e?void 0:e.resources)||void 0===n?void 0:n.spaces),u=void 0!==(null===(r=null==e?void 0:e.patterns)||void 0===r?void 0:r.users),c=void 0!==(null===(o=null==e?void 0:e.patterns)||void 0===o?void 0:o.spaces);return u||s||c||a||i}function De(e){var t=0;return e.join&&(t|=128),e.update&&(t|=64),e.get&&(t|=32),e.delete&&(t|=8),e.manage&&(t|=4),e.write&&(t|=2),e.read&&(t|=1),t}function Fe(e,t){if(Ie(t))return function(e,t){var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorizedUserId,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.users,c=r.spaces,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.users,h=o.spaces,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}(0,t);var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorized_uuid,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.uuids,c=r.channels,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.uuids,h=o.channels,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}var Le=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrantToken},extractPermissions:De,validateParams:function(e,t){var n,r,o,i,s,a,u=e.config;if(!u.subscribeKey)return"Missing Subscribe Key";if(!u.publishKey)return"Missing Publish Key";if(!u.secretKey)return"Missing Secret Key";if(!t.resources&&!t.patterns)return"Missing either Resources or Patterns.";var c=void 0!==(null==t?void 0:t.authorized_uuid),l=void 0!==(null===(n=null==t?void 0:t.resources)||void 0===n?void 0:n.uuids),p=void 0!==(null===(r=null==t?void 0:t.resources)||void 0===r?void 0:r.channels),h=void 0!==(null===(o=null==t?void 0:t.resources)||void 0===o?void 0:o.groups),f=void 0!==(null===(i=null==t?void 0:t.patterns)||void 0===i?void 0:i.uuids),d=void 0!==(null===(s=null==t?void 0:t.patterns)||void 0===s?void 0:s.channels),y=void 0!==(null===(a=null==t?void 0:t.patterns)||void 0===a?void 0:a.groups),g=c||l||f||p||d||h||y;return Ie(t)&&g?"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`":(!t.resources||t.resources.uuids&&0!==Object.keys(t.resources.uuids).length||t.resources.channels&&0!==Object.keys(t.resources.channels).length||t.resources.groups&&0!==Object.keys(t.resources.groups).length||t.resources.users&&0!==Object.keys(t.resources.users).length||t.resources.spaces&&0!==Object.keys(t.resources.spaces).length)&&(!t.patterns||t.patterns.uuids&&0!==Object.keys(t.patterns.uuids).length||t.patterns.channels&&0!==Object.keys(t.patterns.channels).length||t.patterns.groups&&0!==Object.keys(t.patterns.groups).length||t.patterns.users&&0!==Object.keys(t.patterns.users).length||t.patterns.spaces&&0!==Object.keys(t.patterns.spaces).length)?void 0:"Missing values for either Resources or Patterns."},postURL:function(e){var t=e.config;return"/v3/pam/".concat(t.subscribeKey,"/grant")},usePost:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(){return{}},postPayload:function(e,t){return Fe(0,t)},handleResponse:function(e,t){return t.data.token}}),Ge={getOperation:function(){return j.PNAccessManagerRevokeToken},validateParams:function(e,t){return e.config.secretKey?t?void 0:"token can't be empty":"Missing Secret Key"},getURL:function(e,t){var n=e.config;return"/v3/pam/".concat(n.subscribeKey,"/grant/").concat(H.encodeString(t))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e){return{uuid:e.config.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}};function Ke(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}var Be=Object.freeze({__proto__:null,getOperation:function(){return j.PNPublishOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},usePost:function(e,t){var n=t.sendByPost;return void 0!==n&&n},getURL:function(e,t){var n=e.config,r=t.channel,o=Ke(e,t.message);return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0/").concat(H.encodeString(o))},postURL:function(e,t){var n=e.config,r=t.channel;return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},postPayload:function(e,t){return Ke(e,t.message)},prepareParams:function(e,t){var n=t.meta,r=t.replicate,o=void 0===r||r,i=t.storeInHistory,s=t.ttl,a={};return null!=i&&(a.store=i?"1":"0"),s&&(a.ttl=s),!1===o&&(a.norep="true"),n&&"object"==typeof n&&(a.meta=JSON.stringify(n)),a},handleResponse:function(e,t){return{timetoken:t[2]}}});var He=Object.freeze({__proto__:null,getOperation:function(){return j.PNSignalOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},getURL:function(e,t){var n,r=e.config,o=t.channel,i=t.message,s=(n=i,JSON.stringify(n));return"/signal/".concat(r.publishKey,"/").concat(r.subscribeKey,"/0/").concat(H.encodeString(o),"/0/").concat(H.encodeString(s))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{timetoken:t[2]}}});var qe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHistoryOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channel,r=e.config;return"/v2/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o=t.reverse,i=t.count,s=void 0===i?100:i,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p={include_token:"true"};return p.count=s,n&&(p.start=n),r&&(p.end=r),u&&(p.string_message_token="true"),null!=o&&(p.reverse=o.toString()),l&&(p.include_meta="true"),p},handleResponse:function(e,t){var n={messages:[],startTimeToken:t[1],endTimeToken:t[2]};return Array.isArray(t[0])&&t[0].forEach((function(t){var r=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message),o={timetoken:t.timetoken,entry:r.payload};t.meta&&(o.meta=t.meta),r.error&&(o.error=r.error),n.messages.push(o)})),n}});var ze=Object.freeze({__proto__:null,getOperation:function(){return j.PNDeleteMessagesOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},useDelete:function(){return!0},getURL:function(e,t){var n=t.channel,r=e.config;return"/v3/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o={};return n&&(o.start=n),r&&(o.end=r),o},handleResponse:function(e,t){return t.payload}});var Ve=Object.freeze({__proto__:null,getOperation:function(){return j.PNMessageCounts},validateParams:function(e,t){var n=t.channels,r=t.timetoken,o=t.channelTimetokens,i=e.config;return n?r&&o?"timetoken and channelTimetokens are incompatible together":o&&o.length>1&&n.length!==o.length?"Length of channelTimetokens and channels do not match":i.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channels,r=e.config,o=n.join(",");return"/v3/history/sub-key/".concat(r.subscribeKey,"/message-counts/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.timetoken,r=t.channelTimetokens,o={};if(r&&1===r.length){var i=a(r,1)[0];o.timetoken=i}else r?o.channelsTimetoken=r.join(","):n&&(o.timetoken=n);return o},handleResponse:function(e,t){return{channels:t.channels}}});var We=Object.freeze({__proto__:null,getOperation:function(){return j.PNFetchMessagesOperation},validateParams:function(e,t){var n=t.channels,r=t.includeMessageActions,o=void 0!==r&&r,i=e.config;if(!n||0===n.length)return"Missing channels";if(!i.subscribeKey)return"Missing Subscribe Key";if(o&&n.length>1)throw new TypeError("History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.")},getURL:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.includeMessageActions,i=void 0!==o&&o,s=e.config,a=i?"history-with-actions":"history",u=r.length>0?r.join(","):",";return"/v3/".concat(a,"/sub-key/").concat(s.subscribeKey,"/channel/").concat(H.encodeString(u))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channels,r=t.start,o=t.end,i=t.includeMessageActions,s=t.count,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p=t.includeUuid,h=t.includeUUID,f=void 0===h||h,d=t.includeMessageType,y=void 0===d||d,g={};return g.max=s||(n.length>1||!0===i?25:100),r&&(g.start=r),o&&(g.end=o),u&&(g.string_message_token="true"),l&&(g.include_meta="true"),f&&!1!==p&&(g.include_uuid="true"),y&&(g.include_message_type="true"),g},handleResponse:function(e,t){var n={channels:{}};return Object.keys(t.channels||{}).forEach((function(r){n.channels[r]=[],(t.channels[r]||[]).forEach((function(t){var o={},i=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message);o.channel=r,o.timetoken=t.timetoken,o.message=i.payload,o.messageType=t.message_type,o.uuid=t.uuid,t.actions&&(o.actions=t.actions,o.data=t.actions),t.meta&&(o.meta=t.meta),i.error&&(o.error=i.error),n.channels[r].push(o)}))})),t.more&&(n.more=t.more),n}});var Je=Object.freeze({__proto__:null,getOperation:function(){return j.PNTimeOperation},getURL:function(){return"/time/0"},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(){return{}},isAuthSupported:function(){return!1},handleResponse:function(e,t){return{timetoken:t[0]}},validateParams:function(){}});var $e=Object.freeze({__proto__:null,getOperation:function(){return j.PNSubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=e.config,r=t.state,o=t.channelGroups,i=void 0===o?[]:o,s=t.timetoken,a=t.filterExpression,u=t.region,c={heartbeat:n.getPresenceTimeout()};return i.length>0&&(c["channel-group"]=i.join(",")),a&&a.length>0&&(c["filter-expr"]=a),Object.keys(r).length&&(c.state=JSON.stringify(r)),s&&(c.tt=s),u&&(c.tr=u),c},handleResponse:function(e,t){var n=[];t.m.forEach((function(e){var t={publishTimetoken:e.p.t,region:e.p.r},r={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:t};n.push(r)}));var r={timetoken:t.t.t,region:t.t.r};return{messages:n,metadata:r}}}),Qe={getOperation:function(){return j.PNHandshakeOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)&&!(null==t?void 0:t.channelGroups))return"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),n.tt=0,t.state&&(n.state=JSON.stringify(t.state)),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.ee="",n},handleResponse:function(e,t){return{region:t.t.r,timetoken:t.t.t}}},Xe={getOperation:function(){return j.PNReceiveMessagesOperation},validateParams:function(e,t){return(null==t?void 0:t.channels)||(null==t?void 0:t.channelGroups)?(null==t?void 0:t.timetoken)?(null==t?void 0:t.region)?void 0:"region can not be empty":"timetoken can not be empty":"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},getAbortSignal:function(e,t){return t.abortSignal},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.tt=t.timetoken,n.tr=t.region,n.ee="",n},handleResponse:function(e,t){var n=[];return t.m.forEach((function(e){var t={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,publishMetaData:{timetoken:e.p.t,region:e.p.r}};n.push(t)})),{messages:n,metadata:{region:t.t.r,timetoken:t.t.t}}}},Ye=function(){function e(e){void 0===e&&(e=!1),this.sync=e,this.listeners=new Set}return e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.notify=function(e){var t=this,n=function(){t.listeners.forEach((function(t){t(e)}))};this.sync?n():setTimeout(n,0)},e}(),Ze=function(){function e(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}return e.prototype.transition=function(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)},e.prototype.on=function(e,t){return this.transitionMap.set(e,t),this},e.prototype.with=function(e,t){return[this,e,null!=t?t:[]]},e.prototype.onEnter=function(e){return this.enterEffects.push(e),this},e.prototype.onExit=function(e){return this.exitEffects.push(e),this},e}(),et=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return t(n,e),n.prototype.describe=function(e){return new Ze(e)},n.prototype.start=function(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})},n.prototype.transition=function(e){var t,n,r,o,i,u;if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});var c=this.currentState.transition(this.currentContext,e);if(c){var l=a(c,3),p=l[0],h=l[1],f=l[2];try{for(var d=s(this.currentState.exitEffects),y=d.next();!y.done;y=d.next()){var g=y.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}var m=this.currentState;this.currentState=p;var b=this.currentContext;this.currentContext=h,this.notify({type:"transitionDone",fromState:m,fromContext:b,toState:p,toContext:h,event:e});try{for(var v=s(f),_=v.next();!_.done;_=v.next()){g=_.value;this.notify({type:"invocationDispatched",invocation:g})}}catch(e){r={error:e}}finally{try{_&&!_.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var S=s(this.currentState.enterEffects),w=S.next();!w.done;w=S.next()){g=w.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){i={error:e}}finally{try{w&&!w.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}},n}(Ye),tt=function(){function e(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}return e.prototype.on=function(e,t){this.handlers.set(e,t)},e.prototype.dispatch=function(e){if("CANCEL"!==e.type){var t=this.handlers.get(e.type);if(!t)throw new Error("Unhandled invocation '".concat(e.type,"'"));var n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}else if(this.instances.has(e.payload)){var r=this.instances.get(e.payload);null==r||r.cancel(),this.instances.delete(e.payload)}},e.prototype.dispose=function(){var e,t;try{for(var n=s(this.instances.entries()),r=n.next();!r.done;r=n.next()){var o=a(r.value,2),i=o[0];o[1].cancel(),this.instances.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();function nt(e,t){var n=function(){for(var n=[],r=0;r0&&r(e),[2]}))}))}))),s.on(ht.type,ut((function(e,t,n){var r=n.emitStatus;return o(s,void 0,void 0,(function(){return i(this,(function(t){return r(e),[2]}))}))}))),s.on(ft.type,ut((function(e,n,r){var a=r.receiveMessages,u=r.delay,c=r.config;return o(s,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return c.retryConfiguration&&c.retryConfiguration.shouldRetry(e.reason,e.attempts)?(n.throwIfAborted(),[4,u(c.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),n.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,a({abortSignal:n,channels:e.channels,channelGroups:e.groups,timetoken:e.cursor.timetoken,region:e.cursor.region,filterExpression:c.filterExpression})];case 3:return r=i.sent(),[2,t.transition(Pt(r.metadata,r.messages))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Et(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(At(new q(c.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s.on(dt.type,ut((function(e,r,a){var u=a.handshake,c=a.delay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({abortSignal:r,channels:e.channels,channelGroups:e.groups,filterExpression:p.filterExpression},p.maintainPresenceState&&{state:l}))];case 3:return o=i.sent(),[2,t.transition(vt(o))];case 4:return(s=i.sent())instanceof Error&&"Aborted"===s.message?[2]:s instanceof q?[2,t.transition(_t(s))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(St(new q(p.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s}return t(r,e),r}(tt),Mt=new Ze("HANDSHAKE_FAILED");Mt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Mt.on(Nt.type,(function(e,t){return Ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor})})),Mt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(r=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==r?r:0}})})),Mt.on(Ct.type,(function(e){return Lt.with()}));var jt=new Ze("HANDSHAKE_STOPPED");jt.on(yt.type,(function(e,t){return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),jt.on(Nt.type,(function(e,t){return Ft.with(n(n({},e),{cursor:t.payload.cursor||e.cursor}))})),jt.on(gt.type,(function(e,t){var n;return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),jt.on(Ct.type,(function(e){return Lt.with()}));var Rt=new Ze("RECEIVE_FAILED");Rt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Rt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(Ct.type,(function(e){return Lt.with(void 0)}));var xt=new Ze("RECEIVE_STOPPED");xt.on(yt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),xt.on(gt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Ct.type,(function(){return Lt.with(void 0)}));var Ut=new Ze("RECEIVE_RECONNECTING");Ut.onEnter((function(e){return ft(e)})),Ut.onExit((function(){return ft.cancel})),Ut.on(Pt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),Ut.on(Et.type,(function(e,t){return Ut.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Ut.on(At.type,(function(e,t){var n;return Rt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Ut.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),Ut.on(gt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Ut.on(yt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ut.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var It=new Ze("RECEIVING");It.onEnter((function(e){return lt(e.channels,e.groups,e.cursor)})),It.onExit((function(){return lt.cancel})),It.on(wt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),It.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups})})),It.on(gt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),It.on(Ot.type,(function(e,t){return Ut.with(n(n({},e),{attempts:0,reason:t.payload}))})),It.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),It.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var Dt=new Ze("HANDSHAKE_RECONNECTING");Dt.onEnter((function(e){return dt(e)})),Dt.onExit((function(){return dt.cancel})),Dt.on(vt.type,(function(e,t){var n,r,o={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=e.cursor)||void 0===r?void 0:r.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return It.with({channels:e.channels,groups:e.groups,cursor:o},[ht({category:k.PNConnectedCategory})])})),Dt.on(_t.type,(function(e,t){return Dt.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Dt.on(St.type,(function(e,t){var n;return Mt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Dt.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Dt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Dt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.region)||0}})})),Dt.on(Ct.type,(function(e){return Lt.with(void 0)}));var Ft=new Ze("HANDSHAKING");Ft.onEnter((function(e){return ct(e.channels,e.groups)})),Ft.onExit((function(){return ct.cancel})),Ft.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ft.on(mt.type,(function(e,t){var n,r;return It.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.timetoken:t.payload.timetoken,region:t.payload.region}},[ht({category:k.PNConnectedCategory})])})),Ft.on(bt.type,(function(e,t){return Dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload})})),Ft.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Ft.on(gt.type,(function(e,t){var n;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),Ft.on(Ct.type,(function(e){return Lt.with()}));var Lt=new Ze("UNSUBSCRIBED");Lt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups})})),Lt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})}));var Gt=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new kt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(Lt,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e){var t=this,n=e.channels,r=e.channelGroups,o=e.timetoken,i=e.withPresence;this.channels=u(u([],a(this.channels),!1),a(null!=n?n:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=r?r:[]),!1),i&&(this.channels.map((function(e){return t.channels.push("".concat(e,"-pnpres"))})),this.groups.map((function(e){return t.groups.push("".concat(e,"-pnpres"))}))),o?this.engine.transition(gt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))),o)):this.engine.transition(yt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((function(e){return!e.endsWith("-pnpres")})))),groups:Array.from(new Set(this.groups.filter((function(e){return!e.endsWith("-pnpres")}))))})},e.prototype.unsubscribe=function(e){var t=this,n=e.channels,r=void 0===n?[]:n,o=e.channelGroups,i=void 0===o?[]:o,s=H.removeSingleOccurance(this.channels,u(u([],a(r),!1),a(r.map((function(e){return"".concat(e,"-pnpres")}))),!1)),c=H.removeSingleOccurance(this.groups,u(u([],a(i),!1),a(i.map((function(e){return"".concat(e,"-pnpres")}))),!1));if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(c).size){var l=H.findUniqueCommonElements(this.channels,r),p=H.findUniqueCommonElements(this.groups,i);this.dependencies.presenceState&&(null==l||l.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==p||p.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.channels=s,this.groups=c,this.engine.transition(yt(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:l.slice(0),groups:p.slice(0)})}},e.prototype.unsubscribeAll=function(){this.channels=[],this.groups=[],this.dependencies.presenceState&&(this.dependencies.presenceState={}),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.reconnect=function(e){var t=e.timetoken,n=e.region;this.engine.transition(Nt(t,n))},e.prototype.disconnect=function(){this.engine.transition(Tt()),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.getSubscribedChannels=function(){return this.channels.slice(0)},e.prototype.getSubscribedChannelGroups=function(){return this.groups.slice(0)},e.prototype.dispose=function(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),Kt=nt("RECONNECT",(function(){return{}})),Bt=nt("DISCONNECT",(function(){return{}})),Ht=nt("JOINED",(function(e,t){return{channels:e,groups:t}})),qt=nt("LEFT",(function(e,t){return{channels:e,groups:t}})),zt=nt("LEFT_ALL",(function(){return{}})),Vt=nt("HEARTBEAT_SUCCESS",(function(e){return{statusCode:e}})),Wt=nt("HEARTBEAT_FAILURE",(function(e){return e})),Jt=nt("HEARTBEAT_GIVEUP",(function(){return{}})),$t=nt("TIMES_UP",(function(){return{}})),Qt=rt("HEARTBEAT",(function(e,t){return{channels:e,groups:t}})),Xt=rt("LEAVE",(function(e,t){return{channels:e,groups:t}})),Yt=rt("EMIT_STATUS",(function(e){return e})),Zt=ot("WAIT",(function(){return{}})),en=ot("DELAYED_HEARTBEAT",(function(e){return e})),tn=function(e){function r(t,r){var s=e.call(this,r)||this;return s.on(Qt.type,ut((function(e,r,a){var u=a.heartbeat,c=a.presenceState,l=a.config;return o(s,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,u(n({channels:e.channels,channelGroups:e.groups},l.maintainPresenceState&&{state:c}))];case 1:return o.sent(),t.transition(Vt(200)),[3,3];case 2:return(r=o.sent())instanceof q?[2,t.transition(Wt(r))]:[3,3];case 3:return[2]}}))}))}))),s.on(Xt.type,ut((function(e,t,n){var r=n.leave,a=n.config;return o(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:if(a.suppressLeaveEvents)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r({channels:e.channels,channelGroups:e.groups})];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}}))}))}))),s.on(Zt.type,ut((function(e,n,r){var a=r.heartbeatDelay;return o(s,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return n.throwIfAborted(),[4,a()];case 1:return e.sent(),n.throwIfAborted(),[2,t.transition($t())]}}))}))}))),s.on(en.type,ut((function(e,r,a){var u=a.heartbeat,c=a.retryDelay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({channels:e.channels,channelGroups:e.groups},p.maintainPresenceState&&{state:l}))];case 3:return i.sent(),[2,t.transition(Vt(200))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Wt(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Jt())];case 7:return[2]}}))}))}))),s.on(Yt.type,ut((function(e,t,r){var a=r.emitStatus,u=r.config;return o(s,void 0,void 0,(function(){var t;return i(this,(function(r){return u.announceFailedHeartbeats&&!0===(null===(t=null==e?void 0:e.status)||void 0===t?void 0:t.error)?a(e.status):u.announceSuccessfulHeartbeats&&200===e.statusCode&&a(n(n({},e),{operation:j.PNHeartbeatOperation,error:!1})),[2]}))}))}))),s}return t(r,e),r}(tt),nn=new Ze("HEARTBEAT_STOPPED");nn.on(Ht.type,(function(e,t){return nn.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),nn.on(qt.type,(function(e,t){return nn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))})})),nn.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),nn.on(zt.type,(function(e,t){return un.with(void 0)}));var rn=new Ze("HEARTBEAT_COOLDOWN");rn.onEnter((function(){return Zt()})),rn.onExit((function(){return Zt.cancel})),rn.on($t.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),rn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),rn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),rn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),rn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var on=new Ze("HEARTBEAT_FAILED");on.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),on.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),on.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),on.on(Bt.type,(function(e,t){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),on.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var sn=new Ze("HEARBEAT_RECONNECTING");sn.onEnter((function(e){return en(e)})),sn.onExit((function(){return en.cancel})),sn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),sn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),sn.on(Bt.type,(function(e,t){nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),sn.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),sn.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),sn.on(Jt.type,(function(e,t){return on.with({channels:e.channels,groups:e.groups})})),sn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var an=new Ze("HEARTBEATING");an.onEnter((function(e){return Qt(e.channels,e.groups)})),an.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),an.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),an.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),an.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:0,reason:t.payload}))})),an.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),an.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var un=new Ze("HEARTBEAT_INACTIVE");un.on(Ht.type,(function(e,t){return an.with({channels:t.payload.channels,groups:t.payload.groups})}));var cn=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dispatcher=new tn(this.engine,e),this.dependencies=e,this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(un,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.join=function(e){var t=e.channels,n=e.groups;this.channels=u(u([],a(this.channels),!1),a(null!=t?t:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=n?n:[]),!1),this.engine.transition(Ht(this.channels.slice(0),this.groups.slice(0)))},e.prototype.leave=function(e){var t=this,n=e.channels,r=e.groups;this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(qt(null!=n?n:[],null!=r?r:[]))},e.prototype.leaveAll=function(){this.engine.transition(zt())},e.prototype.dispose=function(){this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),ln=function(){function e(){}return e.LinearRetryPolicy=function(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e.ExponentialRetryPolicy=function(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e}(),pn=function(){function e(e){var t=e.modules,n=e.listenerManager,r=e.getFileUrl;this.modules=t,this.listenerManager=n,this.getFileUrl=r,this._channelListenerMap=new Map,this._groupListenerMap=new Map,t.cryptoModule&&(this._decoder=new TextDecoder)}return e.prototype.emitEvent=function(e){var t=e.channel,o=e.publishMetaData,i=e.subscriptionMatch;if(t===i&&(i=null),e.channel.endsWith("-pnpres")){var s={channel:null,subscription:null};t&&(s.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(s.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),s.action=e.payload.action,s.state=e.payload.data,s.timetoken=o.publishTimetoken,s.occupancy=e.payload.occupancy,s.uuid=e.payload.uuid,s.timestamp=e.payload.timestamp,e.payload.join&&(s.join=e.payload.join),e.payload.leave&&(s.leave=e.payload.leave),e.payload.timeout&&(s.timeout=e.payload.timeout),s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announcePresence(s),this._announce("presence",s,s.channel,s.subscription)}else if(1===e.messageType){(s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=e.payload,this.listenerManager.announceSignal(s),this._announce("signal",s,s.channel,s.subscription)}else if(2===e.messageType){if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},this.listenerManager.announceObjects(s),this._announce("objects",s,s.channel,s.subscription),"uuid"===e.payload.type){var a=this._renameChannelField(s),u=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"user"})});this.listenerManager.announceUser(u),this._announce("user",u,s.channel,s.subscription)}else if("channel"===message.payload.type){a=this._renameChannelField(s);var c=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"space"})});this.listenerManager.announceSpace(c),this._announce("space",c,s.channel,s.subscription)}else if("membership"===message.payload.type){var l=(a=this._renameChannelField(s)).message.data,p=l.uuid,h=l.channel,f=r(l,["uuid","channel"]);f.user=p,f.space=h;var d=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),data:f})});this.listenerManager.announceMembership(d),this._announce("membership",d,s.channel,s.subscription)}}else if(3===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId,s.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},s.event=e.payload.event,this.listenerManager.announceMessageAction(s),this._announce("messageAction",s,s.channel,s.subscription)}else if(4===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId;var y=e.payload;if(this.modules.cryptoModule){var g=void 0;try{g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}null!==g&&(y=g)}e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=y.message,s.file={id:y.file.id,name:y.file.name,url:this.getFileUrl({id:y.file.id,name:y.file.name,channel:t})},this.listenerManager.announceFile(s),this._announce("file",s,s.channel,s.subscription)}else{if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),this.modules.cryptoModule){g=void 0;try{var m;g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}s.message=null!=g?g:e.payload}else s.message=e.payload;s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announceMessage(s),this._announce("message",s,s.channel,s.subscription)}},e.prototype.addListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){r._channelListenerMap[t]?r._channelListenerMap[t].includes(e)||r._channelListenerMap[t].push(e):r._channelListenerMap[t]=[e]})),null==n||n.forEach((function(t){r._groupListenerMap[t]?r._groupListenerMap[t].includes(e)||r._groupListenerMap[t].push(e):r._groupListenerMap[t]=[e]}))):this.listenerManager.addListener(e)},e.prototype.removeListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){var n;r._channelListenerMap[t]=null===(n=r._channelListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))})),null==n||n.forEach((function(t){var n;r._groupListenerMap[t]=null===(n=r._groupListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))}))):this.listenerManager.removeListener(e)},e.prototype.removeAllListeners=function(){this.listenerManager.removeAllListeners()},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e.prototype._announce=function(e,t,n,r){var o,i;null===(o=this._channelListenerMap[n])||void 0===o||o.forEach((function(n){return n[e]&&n[e](t)})),null===(i=this._groupListenerMap[r])||void 0===i||i.forEach((function(n){return n[e]&&n[e](t)}))},e}(),hn=function(){function e(){}return e.prototype.subscribe=function(){var e,t;this.pubnub.subscribe(n({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))},e.prototype.unsubscribe=function(){this.pubnub.unsubscribe({channels:this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),channelGroups:this.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))})},Object.defineProperty(e.prototype,"onMessage",{set:function(e){this.listener.message=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onPresence",{set:function(e){this.listener.presence=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onSignal",{set:function(e){this.listener.signal=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onObjects",{set:function(e){this.listener.objects=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onMessageAction",{set:function(e){this.listener.messageAction=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onFile",{set:function(e){this.listener.file=e},enumerable:!1,configurable:!0}),e.prototype.addListener=function(e){this.eventEmitter.addListener(e,this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),this.groupNames.filter((function(e){return!e.endsWith("-pnpres")})))},e.prototype.removeListener=function(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)},Object.defineProperty(e.prototype,"channels",{get:function(){return this.channelNames.slice(0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"channelGroups",{get:function(){return this.groupNames.slice(0)},enumerable:!1,configurable:!0}),e}(),fn=function(e){function n(t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.subscriptionOptions,c=t.eventEmitter,l=t.pubnub,p=e.call(this)||this;return p.channelNames=[],p.groupNames=[],p.subscriptionList=[],p.options=s,p.eventEmitter=c,p.pubnub=l,r.forEach((function(e){var t=p.pubnub.channel(e).subscription(p.options);p.channelNames=u(u([],a(p.channelNames),!1),a(t.channels),!1),p.subscriptionList.push(t)})),i.forEach((function(e){var t=p.pubnub.channelGroup(e).subscription(p.options);p.groupNames=u(u([],a(p.groupNames),!1),a(t.channelGroups),!1),p.subscriptionList.push(t)})),p.listener={},c.addListener(p.listener,p.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),p.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),p}return t(n,e),n.prototype.addSubscription=function(e){this.subscriptionList.push(e),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscription=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return t!==e}))},n.prototype.addSubscriptionSet=function(e){this.subscriptionList=u(u([],a(this.subscriptionList),!1),a(e.subscriptions),!1),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscriptionSet=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return!e.subscriptions.includes(t)}))},Object.defineProperty(n.prototype,"subscriptions",{get:function(){return this.subscriptionList.slice(0)},enumerable:!1,configurable:!0}),n}(hn),dn=function(e){function r(t){var n=t.channels,r=t.channelGroups,o=t.subscriptionOptions,i=t.eventEmitter,s=t.pubnub,a=e.call(this)||this;return a.channelNames=[],a.groupNames=[],a.channelNames=n,a.groupNames=r,a.options=o,a.pubnub=s,a.eventEmitter=i,a.listener={},i.addListener(a.listener,a.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),a.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),a}return t(r,e),r.prototype.addSubscription=function(e){return new fn({channels:u(u([],a(this.channelNames),!1),a(e.channels),!1),channelGroups:u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),subscriptionOptions:n(n({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})},r}(hn),yn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),gn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),mn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),bn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),vn=function(){function e(e){var t=this,r=e.networking,o=e.cbor,i=new g({setup:e});this._config=i;var c=new T({config:i}),l=e.cryptography;r.init(i);var p=new G(i,o);this._tokenManager=p;var h=new R({maximumSamplesCount:6e4});this._telemetryManager=h;var f=this._config.cryptoModule,d={config:i,networking:r,crypto:c,cryptography:l,tokenManager:p,telemetryManager:h,PubNubFile:e.PubNubFile,cryptoModule:f};this.File=e.PubNubFile,this.encryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.encryptFile(t,this.File)):l.encryptFile(e,t,this.File)},this.decryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.decryptFile(t,this.File)):l.decryptFile(e,t,this.File)};var y=Q.bind(this,d,Je),m=Q.bind(this,d,se),v=Q.bind(this,d,ue),_=Q.bind(this,d,le),S=Q.bind(this,d,$e),w=new L;if(this._listenerManager=w,this.iAmHere=Q.bind(this,d,ue),this.iAmAway=Q.bind(this,d,se),this.setPresenceState=Q.bind(this,d,le),this.handshake=Q.bind(this,d,Qe),this.receiveMessages=Q.bind(this,d,Xe),this._eventEmitter=new pn({modules:d,listenerManager:this._listenerManager,getFileUrl:function(e){return ve(d,e)}}),!0===i.enableEventEngine){if(i.maintainPresenceState&&(this.presenceState={},this.setState=function(e){var n,r;return null===(n=e.channels)||void 0===n||n.forEach((function(n){return t.presenceState[n]=e.state})),null===(r=e.channelGroups)||void 0===r||r.forEach((function(n){return t.presenceState[n]=e.state})),t.setPresenceState({channels:e.channels,channelGroups:e.channelGroups,state:t.presenceState})}),i.getHeartbeatInterval()){var O=new cn({heartbeat:this.iAmHere,leave:this.iAmAway,heartbeatDelay:function(){return new Promise((function(e){return setTimeout(e,1e3*d.config.getHeartbeatInterval())}))},retryDelay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},config:d.config,presenceState:this.presenceState,emitStatus:function(e){w.announceStatus(e)}});this.presenceEventEngine=O,this.join=this.presenceEventEngine.join.bind(O),this.leave=this.presenceEventEngine.leave.bind(O),this.leaveAll=this.presenceEventEngine.leaveAll.bind(O)}var P=new Gt({handshake:this.handshake,receiveMessages:this.receiveMessages,delay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},join:this.join,leave:this.leave,leaveAll:this.leaveAll,presenceState:this.presenceState,config:d.config,emitMessages:function(e){var n,r;try{for(var o=s(e),i=o.next();!i.done;i=o.next()){var a=i.value;t._eventEmitter.emitEvent(a)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},emitStatus:function(e){w.announceStatus(e)}});this.subscribe=P.subscribe.bind(P),this.unsubscribe=P.unsubscribe.bind(P),this.unsubscribeAll=P.unsubscribeAll.bind(P),this.reconnect=P.reconnect.bind(P),this.disconnect=P.disconnect.bind(P),this.destroy=P.dispose.bind(P),this.getSubscribedChannels=P.getSubscribedChannels.bind(P),this.getSubscribedChannelGroups=P.getSubscribedChannelGroups.bind(P),this.eventEngine=P}else{var E=new M({timeEndpoint:y,leaveEndpoint:m,heartbeatEndpoint:v,setStateEndpoint:_,subscribeEndpoint:S,crypto:d.crypto,config:d.config,listenerManager:w,getFileUrl:function(e){return ve(d,e)},cryptoModule:d.cryptoModule,eventEmitter:this._eventEmitter});this.subscribe=E.adaptSubscribeChange.bind(E),this.unsubscribe=E.adaptUnsubscribeChange.bind(E),this.disconnect=E.disconnect.bind(E),this.reconnect=E.reconnect.bind(E),this.unsubscribeAll=E.unsubscribeAll.bind(E),this.getSubscribedChannels=E.getSubscribedChannels.bind(E),this.getSubscribedChannelGroups=E.getSubscribedChannelGroups.bind(E),this.setState=E.adaptStateChange.bind(E),this.presence=E.adaptPresenceChange.bind(E),this.destroy=function(e){E.unsubscribeAll(e),E.disconnect()}}this.addListener=this._eventEmitter.addListener.bind(this._eventEmitter),this.removeListener=this._eventEmitter.removeListener.bind(this._eventEmitter),this.removeAllListeners=this._eventEmitter.removeAllListeners.bind(this._eventEmitter),this.parseToken=p.parseToken.bind(p),this.setToken=p.setToken.bind(p),this.getToken=p.getToken.bind(p),this.channelGroups={listGroups:Q.bind(this,d,ee),listChannels:Q.bind(this,d,te),addChannels:Q.bind(this,d,X),removeChannels:Q.bind(this,d,Y),deleteGroup:Q.bind(this,d,Z)},this.push={addChannels:Q.bind(this,d,ne),removeChannels:Q.bind(this,d,re),deleteDevice:Q.bind(this,d,ie),listChannels:Q.bind(this,d,oe)},this.hereNow=Q.bind(this,d,pe),this.whereNow=Q.bind(this,d,ae),this.getState=Q.bind(this,d,ce),this.grant=Q.bind(this,d,Ue),this.grantToken=Q.bind(this,d,Le),this.audit=Q.bind(this,d,xe),this.revokeToken=Q.bind(this,d,Ge),this.publish=Q.bind(this,d,Be),this.fire=function(e,n){return e.replicate=!1,e.storeInHistory=!1,t.publish(e,n)},this.signal=Q.bind(this,d,He),this.history=Q.bind(this,d,qe),this.deleteMessages=Q.bind(this,d,ze),this.messageCounts=Q.bind(this,d,Ve),this.fetchMessages=Q.bind(this,d,We),this.addMessageAction=Q.bind(this,d,he),this.removeMessageAction=Q.bind(this,d,fe),this.getMessageActions=Q.bind(this,d,de),this.listFiles=Q.bind(this,d,ye);var A=Q.bind(this,d,ge);this.publishFile=Q.bind(this,d,me),this.sendFile=be({generateUploadUrl:A,publishFile:this.publishFile,modules:d}),this.getFileUrl=function(e){return ve(d,e)},this.downloadFile=Q.bind(this,d,_e),this.deleteFile=Q.bind(this,d,Se),this.channel=function(e){return new yn(e,t._eventEmitter,t)},this.channelGroup=function(e){return new gn(e,t._eventEmitter,t)},this.channelMetadata=function(e){return new mn(e,t._eventEmitter,t)},this.userMetadata=function(e){return new bn(e,t._eventEmitter,t)},this.subscriptionSet=function(e){return new fn({channels:e.channels,channelGroups:e.channelGroups,subscriptionOptions:e.subscriptionOptions,eventEmitter:t._eventEmitter,pubnub:t})},this.objects={getAllUUIDMetadata:Q.bind(this,d,we),getUUIDMetadata:Q.bind(this,d,Oe),setUUIDMetadata:Q.bind(this,d,Pe),removeUUIDMetadata:Q.bind(this,d,Ee),getAllChannelMetadata:Q.bind(this,d,Ae),getChannelMetadata:Q.bind(this,d,Te),setChannelMetadata:Q.bind(this,d,Ne),removeChannelMetadata:Q.bind(this,d,Ce),getChannelMembers:Q.bind(this,d,ke),setChannelMembers:function(e){for(var r=[],o=1;o=this._config.origin.length&&(this._currentSubDomain=0);var t=this._config.origin[this._currentSubDomain];return"".concat(e).concat(t)},e.prototype.hasModule=function(e){return e in this._modules},e.prototype.shiftStandardOrigin=function(){return this._standardOrigin=this.nextOrigin(),this._standardOrigin},e.prototype.getStandardOrigin=function(){return this._standardOrigin},e.prototype.POSTFILE=function(e,t,n){return this._modules.postfile(e,t,n)},e.prototype.GETFILE=function(e,t,n){return this._modules.getfile(e,t,n)},e.prototype.POST=function(e,t,n,r){return this._modules.post(e,t,n,r)},e.prototype.PATCH=function(e,t,n,r){return this._modules.patch(e,t,n,r)},e.prototype.GET=function(e,t,n){return this._modules.get(e,t,n)},e.prototype.DELETE=function(e,t,n){return this._modules.del(e,t,n)},e.prototype._detectErrorCategory=function(e){if("ENOTFOUND"===e.code)return k.PNNetworkIssuesCategory;if("ECONNREFUSED"===e.code)return k.PNNetworkIssuesCategory;if("ECONNRESET"===e.code)return k.PNNetworkIssuesCategory;if("EAI_AGAIN"===e.code)return k.PNNetworkIssuesCategory;if(0===e.status||e.hasOwnProperty("status")&&void 0===e.status)return k.PNNetworkIssuesCategory;if(e.timeout)return k.PNTimeoutCategory;if("ETIMEDOUT"===e.code)return k.PNNetworkIssuesCategory;if(e.response){if(e.response.badRequest)return k.PNBadRequestCategory;if(e.response.forbidden)return k.PNAccessDeniedCategory}return k.PNUnknownCategory},e}();function Sn(e){var t=function(e){return e&&"object"==typeof e&&e.constructor===Object};if(!t(e))return e;var n={};return Object.keys(e).forEach((function(r){var o=function(e){return"string"==typeof e||e instanceof String}(r),i=r,s=e[r];Array.isArray(r)||o&&r.indexOf(",")>=0?i=(o?r.split(","):r).reduce((function(e,t){return e+=String.fromCharCode(t)}),""):(function(e){return"number"==typeof e&&isFinite(e)}(r)||o&&!isNaN(r))&&(i=String.fromCharCode(o?parseInt(r,10):10));n[i]=t(s)?Sn(s):s})),n}var wn=function(){function e(e,t){this._base64ToBinary=t,this._decode=e}return e.prototype.decodeToken=function(e){var t="";e.length%4==3?t="=":e.length%4==2&&(t="==");var n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,r=this._decode(this._base64ToBinary(n));if("object"==typeof r)return r},e}(),On={exports:{}},Pn={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;os.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;at?1:0}function Un(e,t,n,r){void 0===r&&(r=kn());var o,i=In(e,"",0,[],void 0,0,r)||e;try{o=0===Cn.length?JSON.stringify(i,t,n):JSON.stringify(i,Dn(t),n)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==Nn.length;){var s=Nn.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return o}function In(e,t,n,r,o,i,s){var a;if(i+=1,"object"==typeof e&&null!==e){for(a=0;as.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;a0)for(var r=0;r1&&"boolean"!=typeof t)throw new Qn('"allowMissing" argument must be a boolean');var n=gr(e),r=n.length>0?n[0]:"",o=mr("%"+r+"%",t),i=o.name,s=o.value,a=!1,u=o.alias;u&&(r=u[0],pr(n,lr([0,1],u)));for(var c=1,l=!0;c=n.length){var d=Yn(s,p);s=(l=!!d)&&"get"in d&&!("originalValue"in d.get)?d.get:s[p]}else l=cr(s,p),s=s[p];l&&!a&&(ir[i]=s)}}return s},vr={exports:{}};!function(e){var t=Vn,n=br,r=n("%Function.prototype.apply%"),o=n("%Function.prototype.call%"),i=n("%Reflect.apply%",!0)||t.call(o,r),s=n("%Object.getOwnPropertyDescriptor%",!0),a=n("%Object.defineProperty%",!0),u=n("%Math.max%");if(a)try{a({},"a",{value:1})}catch(e){a=null}e.exports=function(e){var n=i(t,o,arguments);if(s&&a){var r=s(n,"length");r.configurable&&a(n,"length",{value:1+u(0,e.length-(arguments.length-1))})}return n};var c=function(){return i(t,r,arguments)};a?a(e.exports,"apply",{value:c}):e.exports.apply=c}(vr);var _r=br,Sr=vr.exports,wr=Sr(_r("String.prototype.indexOf")),Or=l(Object.freeze({__proto__:null,default:{}})),Pr="function"==typeof Map&&Map.prototype,Er=Object.getOwnPropertyDescriptor&&Pr?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ar=Pr&&Er&&"function"==typeof Er.get?Er.get:null,Tr=Pr&&Map.prototype.forEach,Nr="function"==typeof Set&&Set.prototype,Cr=Object.getOwnPropertyDescriptor&&Nr?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,kr=Nr&&Cr&&"function"==typeof Cr.get?Cr.get:null,Mr=Nr&&Set.prototype.forEach,jr="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Rr="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,xr="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Ur=Boolean.prototype.valueOf,Ir=Object.prototype.toString,Dr=Function.prototype.toString,Fr=String.prototype.match,Lr=String.prototype.slice,Gr=String.prototype.replace,Kr=String.prototype.toUpperCase,Br=String.prototype.toLowerCase,Hr=RegExp.prototype.test,qr=Array.prototype.concat,zr=Array.prototype.join,Vr=Array.prototype.slice,Wr=Math.floor,Jr="function"==typeof BigInt?BigInt.prototype.valueOf:null,$r=Object.getOwnPropertySymbols,Qr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,Xr="function"==typeof Symbol&&"object"==typeof Symbol.iterator,Yr="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xr||"symbol")?Symbol.toStringTag:null,Zr=Object.prototype.propertyIsEnumerable,eo=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function to(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||Hr.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var r=e<0?-Wr(-e):Wr(e);if(r!==e){var o=String(r),i=Lr.call(t,o.length+1);return Gr.call(o,n,"$&_")+"."+Gr.call(Gr.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Gr.call(t,n,"$&_")}var no=Or,ro=no.custom,oo=co(ro)?ro:null;function io(e,t,n){var r="double"===(n.quoteStyle||t)?'"':"'";return r+e+r}function so(e){return Gr.call(String(e),/"/g,""")}function ao(e){return!("[object Array]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function uo(e){return!("[object RegExp]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function co(e){if(Xr)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!Qr)return!1;try{return Qr.call(e),!0}catch(e){}return!1}var lo=Object.prototype.hasOwnProperty||function(e){return e in this};function po(e,t){return lo.call(e,t)}function ho(e){return Ir.call(e)}function fo(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;nt.maxStringLength){var n=e.length-t.maxStringLength,r="... "+n+" more character"+(n>1?"s":"");return yo(Lr.call(e,0,t.maxStringLength),t)+r}return io(Gr.call(Gr.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,go),"single",t)}function go(e){var t=e.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return n?"\\"+n:"\\x"+(t<16?"0":"")+Kr.call(t.toString(16))}function mo(e){return"Object("+e+")"}function bo(e){return e+" { ? }"}function vo(e,t,n,r){return e+" ("+t+") {"+(r?_o(n,r):zr.call(n,", "))+"}"}function _o(e,t){if(0===e.length)return"";var n="\n"+t.prev+t.base;return n+zr.call(e,","+n)+"\n"+t.prev}function So(e,t){var n=ao(e),r=[];if(n){r.length=e.length;for(var o=0;o-1?Sr(n):n},Po=function e(t,n,r,o){var i=n||{};if(po(i,"quoteStyle")&&"single"!==i.quoteStyle&&"double"!==i.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(po(i,"maxStringLength")&&("number"==typeof i.maxStringLength?i.maxStringLength<0&&i.maxStringLength!==1/0:null!==i.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var s=!po(i,"customInspect")||i.customInspect;if("boolean"!=typeof s&&"symbol"!==s)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(po(i,"indent")&&null!==i.indent&&"\t"!==i.indent&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(po(i,"numericSeparator")&&"boolean"!=typeof i.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=i.numericSeparator;if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return yo(t,i);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var u=String(t);return a?to(t,u):u}if("bigint"==typeof t){var l=String(t)+"n";return a?to(t,l):l}var p=void 0===i.depth?5:i.depth;if(void 0===r&&(r=0),r>=p&&p>0&&"object"==typeof t)return ao(t)?"[Array]":"[Object]";var h=function(e,t){var n;if("\t"===e.indent)n="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;n=zr.call(Array(e.indent+1)," ")}return{base:n,prev:zr.call(Array(t+1),n)}}(i,r);if(void 0===o)o=[];else if(fo(o,t)>=0)return"[Circular]";function f(t,n,s){if(n&&(o=Vr.call(o)).push(n),s){var a={depth:i.depth};return po(i,"quoteStyle")&&(a.quoteStyle=i.quoteStyle),e(t,a,r+1,o)}return e(t,i,r+1,o)}if("function"==typeof t&&!uo(t)){var d=function(e){if(e.name)return e.name;var t=Fr.call(Dr.call(e),/^function\s*([\w$]+)/);if(t)return t[1];return null}(t),y=So(t,f);return"[Function"+(d?": "+d:" (anonymous)")+"]"+(y.length>0?" { "+zr.call(y,", ")+" }":"")}if(co(t)){var g=Xr?Gr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qr.call(t);return"object"!=typeof t||Xr?g:mo(g)}if(function(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return!0;return"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}(t)){for(var m="<"+Br.call(String(t.nodeName)),b=t.attributes||[],v=0;v"}if(ao(t)){if(0===t.length)return"[]";var _=So(t,f);return h&&!function(e){for(var t=0;t=0)return!1;return!0}(_)?"["+_o(_,h)+"]":"[ "+zr.call(_,", ")+" ]"}if(function(e){return!("[object Error]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)){var S=So(t,f);return"cause"in Error.prototype||!("cause"in t)||Zr.call(t,"cause")?0===S.length?"["+String(t)+"]":"{ ["+String(t)+"] "+zr.call(S,", ")+" }":"{ ["+String(t)+"] "+zr.call(qr.call("[cause]: "+f(t.cause),S),", ")+" }"}if("object"==typeof t&&s){if(oo&&"function"==typeof t[oo]&&no)return no(t,{depth:p-r});if("symbol"!==s&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!Ar||!e||"object"!=typeof e)return!1;try{Ar.call(e);try{kr.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}(t)){var w=[];return Tr&&Tr.call(t,(function(e,n){w.push(f(n,t,!0)+" => "+f(e,t))})),vo("Map",Ar.call(t),w,h)}if(function(e){if(!kr||!e||"object"!=typeof e)return!1;try{kr.call(e);try{Ar.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}(t)){var O=[];return Mr&&Mr.call(t,(function(e){O.push(f(e,t))})),vo("Set",kr.call(t),O,h)}if(function(e){if(!jr||!e||"object"!=typeof e)return!1;try{jr.call(e,jr);try{Rr.call(e,Rr)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}(t))return bo("WeakMap");if(function(e){if(!Rr||!e||"object"!=typeof e)return!1;try{Rr.call(e,Rr);try{jr.call(e,jr)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}(t))return bo("WeakSet");if(function(e){if(!xr||!e||"object"!=typeof e)return!1;try{return xr.call(e),!0}catch(e){}return!1}(t))return bo("WeakRef");if(function(e){return!("[object Number]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(Number(t)));if(function(e){if(!e||"object"!=typeof e||!Jr)return!1;try{return Jr.call(e),!0}catch(e){}return!1}(t))return mo(f(Jr.call(t)));if(function(e){return!("[object Boolean]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(Ur.call(t));if(function(e){return!("[object String]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(String(t)));if("undefined"!=typeof window&&t===window)return"{ [object Window] }";if(t===c)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)&&!uo(t)){var P=So(t,f),E=eo?eo(t)===Object.prototype:t instanceof Object||t.constructor===Object,A=t instanceof Object?"":"null prototype",T=!E&&Yr&&Object(t)===t&&Yr in t?Lr.call(ho(t),8,-1):A?"Object":"",N=(E||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(T||A?"["+zr.call(qr.call([],T||[],A||[]),": ")+"] ":"");return 0===P.length?N+"{}":h?N+"{"+_o(P,h)+"}":N+"{ "+zr.call(P,", ")+" }"}return String(t)},Eo=wo("%TypeError%"),Ao=wo("%WeakMap%",!0),To=wo("%Map%",!0),No=Oo("WeakMap.prototype.get",!0),Co=Oo("WeakMap.prototype.set",!0),ko=Oo("WeakMap.prototype.has",!0),Mo=Oo("Map.prototype.get",!0),jo=Oo("Map.prototype.set",!0),Ro=Oo("Map.prototype.has",!0),xo=function(e,t){for(var n,r=e;null!==(n=r.next);r=n)if(n.key===t)return r.next=n.next,n.next=e.next,e.next=n,n},Uo=String.prototype.replace,Io=/%20/g,Do="RFC3986",Fo={default:Do,formatters:{RFC1738:function(e){return Uo.call(e,Io,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:Do},Lo=Fo,Go=Object.prototype.hasOwnProperty,Ko=Array.isArray,Bo=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),Ho=function(e,t){for(var n=t&&t.plainObjects?Object.create(null):{},r=0;r1;){var t=e.pop(),n=t.obj[t.prop];if(Ko(n)){for(var r=[],o=0;o=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===Lo.RFC1738&&(40===u||41===u)?s+=i.charAt(a):u<128?s+=Bo[u]:u<2048?s+=Bo[192|u>>6]+Bo[128|63&u]:u<55296||u>=57344?s+=Bo[224|u>>12]+Bo[128|u>>6&63]+Bo[128|63&u]:(a+=1,u=65536+((1023&u)<<10|1023&i.charCodeAt(a)),s+=Bo[240|u>>18]+Bo[128|u>>12&63]+Bo[128|u>>6&63]+Bo[128|63&u])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(Ko(e)){for(var n=[],r=0;r0?b.join(",")||null:void 0}];else if(Qo(u))O=u;else{var E=Object.keys(b);O=c?E.sort(c):E}for(var A=o&&Qo(b)&&1===b.length?n+"[]":n,T=0;T-1?e.split(","):e},li=function(e,t,n,r){if(e){var o=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,s=n.depth>0&&/(\[[^[\]]*])/.exec(o),a=s?o.slice(0,s.index):o,u=[];if(a){if(!n.plainObjects&&ii.call(Object.prototype,a)&&!n.allowPrototypes)return;u.push(a)}for(var c=0;n.depth>0&&null!==(s=i.exec(o))&&c=0;--i){var s,a=e[i];if("[]"===a&&n.parseArrays)s=[].concat(o);else{s=n.plainObjects?Object.create(null):{};var u="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(u,10);n.parseArrays||""!==u?!isNaN(c)&&a!==u&&String(c)===u&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(s=[])[c]=o:"__proto__"!==u&&(s[u]=o):s={0:o}}o=s}return o}(u,t,n,r)}},pi=function(e,t){var n,r=e,o=function(e){if(!e)return ti;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||ti.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Wo.default;if(void 0!==e.format){if(!Jo.call(Wo.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var r=Wo.formatters[n],o=ti.filter;return("function"==typeof e.filter||Qo(e.filter))&&(o=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:ti.addQueryPrefix,allowDots:void 0===e.allowDots?ti.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ti.charsetSentinel,delimiter:void 0===e.delimiter?ti.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:ti.encode,encoder:"function"==typeof e.encoder?e.encoder:ti.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:ti.encodeValuesOnly,filter:o,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:ti.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:ti.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ti.strictNullHandling}}(t);"function"==typeof o.filter?r=(0,o.filter)("",r):Qo(o.filter)&&(n=o.filter);var i,s=[];if("object"!=typeof r||null===r)return"";i=t&&t.arrayFormat in $o?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=$o[i];if(t&&"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var u="comma"===a&&t&&t.commaRoundTrip;n||(n=Object.keys(r)),o.sort&&n.sort(o.sort);for(var c=zo(),l=0;l0?f+h:""},hi={formats:Fo,parse:function(e,t){var n=function(e){if(!e)return ai;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?ai.charset:e.charset;return{allowDots:void 0===e.allowDots?ai.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:ai.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:ai.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:ai.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ai.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:ai.comma,decoder:"function"==typeof e.decoder?e.decoder:ai.decoder,delimiter:"string"==typeof e.delimiter||oi.isRegExp(e.delimiter)?e.delimiter:ai.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:ai.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:ai.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:ai.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:ai.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ai.strictNullHandling}}(t);if(""===e||null==e)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof e?function(e,t){var n,r={__proto__:null},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,i),a=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(l=si(l)?[l]:l),ii.call(r,c)?r[c]=oi.combine(r[c],l):r[c]=l}return r}(e,n):e,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),s=0;s=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.split(/ *; */).shift(),e.params=e=>{const n={};var r,o=t(e.split(/ *; */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *= */),t=e.shift(),o=e.shift();t&&o&&(n[t]=o)}}catch(e){o.e(e)}finally{o.f()}return n},e.parseLinks=e=>{const n={};var r,o=t(e.split(/ *, */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *; */),t=e[0].slice(1,-1);n[e[1].split(/ *= */)[1].slice(1,-1)]=t}}catch(e){o.e(e)}finally{o.f()}return n},e.cleanHeader=(e,t)=>(delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e),e.isObject=e=>null!==e&&"object"==typeof e,e.hasOwn=Object.hasOwn||function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(new Object(e),t)},e.mixin=(t,n)=>{for(const r in n)e.hasOwn(n,r)&&(t[r]=n[r])}}(fi);const di=Or,yi=fi.isObject,gi=fi.hasOwn;var mi=bi;function bi(){}bi.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},bi.prototype.parse=function(e){return this._parser=e,this},bi.prototype.responseType=function(e){return this._responseType=e,this},bi.prototype.serialize=function(e){return this._serializer=e,this},bi.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(const t in e)if(gi(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},bi.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};const vi=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),_i=new Set([408,413,429,500,502,503,504,521,522,524]);bi.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{const n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&_i.has(t.status))return!0;if(e){if(e.code&&vi.has(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},bi.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},bi.prototype.then=function(e,t){if(!this._fullfilledPromise){const e=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(((t,n)=>{e.on("abort",(()=>{if(this._maxRetries&&this._maxRetries>this._retries)return;if(this.timedout&&this.timedoutError)return void n(this.timedoutError);const e=new Error("Aborted");e.code="ABORTED",e.status=this.status,e.method=this.method,e.url=this.url,n(e)})),e.end(((e,r)=>{e?n(e):t(r)}))}))}return this._fullfilledPromise.then(e,t)},bi.prototype.catch=function(e){return this.then(void 0,e)},bi.prototype.use=function(e){return e(this),this},bi.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},bi.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},bi.prototype.get=function(e){return this._header[e.toLowerCase()]},bi.prototype.getHeader=bi.prototype.get,bi.prototype.set=function(e,t){if(yi(e)){for(const t in e)gi(e,t)&&this.set(t,e[t]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},bi.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},bi.prototype.field=function(e,t,n){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(yi(e)){for(const t in e)gi(e,t)&&this.field(t,e[t]);return this}if(Array.isArray(t)){for(const n in t)gi(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),n?this._getFormData().append(e,t,n):this._getFormData().append(e,t),this},bi.prototype.abort=function(){if(this._aborted)return this;if(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req){if(di.gte(process.version,"v13.0.0")&&di.lt(process.version,"v14.0.0"))throw new Error("Superagent does not work in v13 properly with abort() due to Node.js core changes");this.req.abort()}return this.clearTimeout(),this.emit("abort"),this},bi.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization",`Basic ${r(`${e}:${t}`)}`);break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization",`Bearer ${e}`)}return this},bi.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},bi.prototype.redirects=function(e){return this._maxRedirects=e,this},bi.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},bi.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},bi.prototype.send=function(e){const t=yi(e);let n=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&yi(this._data))for(const t in e){if("bigint"==typeof e[t]&&!e[t].toJSON)throw new Error("Cannot serialize BigInt value to json");gi(e,t)&&(this._data[t]=e[t])}else{if("bigint"==typeof e)throw new Error("Cannot send value of type BigInt");"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],n&&(n=n.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===n?this._data?`${this._data}&${e}`:e:(this._data||"")+e):this._data=e}return!t||this._isHost(e)||n||this.type("json"),this},bi.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},bi.prototype._finalizeQueryString=function(){const e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){const e=this.url.indexOf("?");if(e>=0){const t=this.url.slice(e+1).split("&");"function"==typeof this._sort?t.sort(this._sort):t.sort(),this.url=this.url.slice(0,e)+"?"+t.join("&")}}},bi.prototype._appendQueryString=()=>{console.warn("Unsupported")},bi.prototype._timeoutError=function(e,t,n){if(this._aborted)return;const r=new Error(`${e+t}ms exceeded`);r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.timedoutError=r,this.abort(),this.callback(r)},bi.prototype._setTimeouts=function(){const e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((()=>{e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((()=>{e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};const Si=fi;var wi=Oi;function Oi(){}function Pi(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Ei(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ei(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw i}}}}function Ei(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n{if(o.XMLHttpRequest)return new o.XMLHttpRequest;throw new Error("Browser-only version of superagent could not find XHR")};const g="".trim?e=>e.trim():e=>e.replace(/(^\s*|\s*$)/g,"");function m(e){if(!c(e))return e;const t=[];for(const n in e)p(e,n)&&b(t,n,e[n]);return t.join("&")}function b(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r)){var o,i=n(r);try{for(i.s();!(o=i.n()).done;){b(e,t,o.value)}}catch(e){i.e(e)}finally{i.f()}}else if(c(r))for(const n in r)p(r,n)&&b(e,`${t}[${n}]`,r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function v(e){const t={},n=e.split("&");let r,o;for(let e=0,i=n.length;e{let e,t=null,r=null;try{r=new S(n)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||r.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=e.status||r.status,n.callback(e,r)):n.callback(null,r)}))}y.serializeObject=m,y.parseString=v,y.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":a.stringify,"application/json":s},y.parse={"application/x-www-form-urlencoded":v,"application/json":JSON.parse},l(S.prototype,h.prototype),S.prototype._parseBody=function(e){let t=y.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&_(this.type)&&(t=y.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},S.prototype.toError=function(){const e=this.req,t=e.method,n=e.url,r=`cannot ${t} ${n} (${this.status})`,o=new Error(r);return o.status=this.status,o.method=t,o.url=n,o},y.Response=S,i(w.prototype),l(w.prototype,u.prototype),w.prototype.type=function(e){return this.set("Content-Type",y.types[e]||e),this},w.prototype.accept=function(e){return this.set("Accept",y.types[e]||e),this},w.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});const r=n.encoder?n.encoder:e=>{if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},w.prototype.query=function(e){return"string"!=typeof e&&(e=m(e)),e&&this._query.push(e),this},w.prototype.attach=function(e,t,n){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},w.prototype._getFormData=function(){return this._formData||(this._formData=new o.FormData),this._formData},w.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();const n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},w.prototype.crossDomainError=function(){const e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},w.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},w.prototype.ca=w.prototype.agent,w.prototype.buffer=w.prototype.ca,w.prototype.write=()=>{throw new Error("Streaming is not supported in browser version of superagent")},w.prototype.pipe=w.prototype.write,w.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},w.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||d,this._finalizeQueryString(),this._end()},w.prototype._setUploadTimeout=function(){const e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((()=>{e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},w.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));const e=this;this.xhr=y.getXHR();const t=this.xhr;let n=this._formData||this._data;this._setTimeouts(),t.addEventListener("readystatechange",(()=>{const n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4!==n)return;let r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}));const r=(t,n)=>{n.total>0&&(n.percent=n.loaded/n.total*100,100===n.percent&&clearTimeout(e._uploadTimeoutTimer)),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.addEventListener("progress",r.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",r.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof n&&!this._isHost(n)){const e=this._header["content-type"];let t=this._serializer||y.serialize[e?e.split(";")[0]:""];!t&&_(e)&&(t=y.serialize["application/json"]),t&&(n=t(n))}for(const e in this.header)null!==this.header[e]&&p(this.header,e)&&t.setRequestHeader(e,this.header[e]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===n?null:n)},y.agent=()=>new f;for(var O=0,P=["GET","POST","OPTIONS","PATCH","PUT","DELETE"];O{const r=y("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.head=(e,t,n)=>{const r=y("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.options=(e,t,n)=>{const r=y("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.del=E,y.delete=E,y.patch=(e,t,n)=>{const r=y("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.post=(e,t,n)=>{const r=y("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.put=(e,t,n)=>{const r=y("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}}(On,On.exports);var ki=On.exports;function Mi(e){var t=(new Date).getTime(),n=(new Date).toISOString(),r=console&&console.log?console:window&&window.console&&window.console.log?window.console:console;r.log("<<<<<"),r.log("[".concat(n,"]"),"\n",e.url,"\n",e.qs),r.log("-----"),e.on("response",(function(n){var o=(new Date).getTime()-t,i=(new Date).toISOString();r.log(">>>>>>"),r.log("[".concat(i," / ").concat(o,"]"),"\n",e.url,"\n",e.qs,"\n",n.text),r.log("-----")}))}function ji(e,t,n){var r=this;this._config.logVerbosity&&(e=e.use(Mi)),this._config.proxy&&this._modules.proxy&&(e=this._modules.proxy.call(this,e)),this._config.keepAlive&&this._modules.keepAlive&&(e=this._modules.keepAlive(e));var o=e;if(t.abortSignal)var i=t.abortSignal.subscribe((function(){o.abort(),i()}));return!0===t.forceBuffered?o="undefined"==typeof Blob?o.buffer().responseType("arraybuffer"):o.responseType("arraybuffer"):!1===t.forceBuffered&&(o=o.buffer(!1)),(o=o.timeout(t.timeout)).on("abort",(function(){return n({category:k.PNUnknownCategory,error:!0,operation:t.operation,errorData:new Error("Aborted")},null)})),o.end((function(e,o){var i,s={};if(s.error=null!==e,s.operation=t.operation,o&&o.status&&(s.statusCode=o.status),e){if(e.response&&e.response.text&&!r._config.logVerbosity)try{s.errorData=JSON.parse(e.response.text)}catch(t){s.errorData=e}else s.errorData=e;return s.category=r._detectErrorCategory(e),n(s,null)}if(t.ignoreBody)i={headers:o.headers,redirects:o.redirects,response:o};else try{i=JSON.parse(o.text)}catch(e){return s.errorData=o,s.error=!0,n(s,null)}return i.error&&1===i.error&&i.status&&i.message&&i.service?(s.errorData=i,s.statusCode=i.status,s.error=!0,s.category=r._detectErrorCategory(s),n(s,null)):(i.error&&i.error.message&&(s.errorData=i.error),n(s,i))})),o}function Ri(e,t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return r=ki.post(e),t.forEach((function(e){var t=e.key,n=e.value;r=r.field(t,n)})),r.attach("file",n,{contentType:"application/octet-stream"}),[4,r];case 1:return[2,o.sent()]}}))}))}function xi(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ui(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ii(e,t,n,r){var o=ki.post(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Di(e,t,n,r){var o=ki.patch(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Fi(e,t,n){var r=ki.delete(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Li(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}var Gi,Ki=function(){function e(){}return Object.defineProperty(e.prototype,"algo",{get:function(){return"aes-256-cbc"},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.encryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.encryptString(n,t)];throw new Error("Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer")}}))}))},e.prototype.decrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.decryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.decryptString(n,t)];throw new Error("Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer")}}))}))},e.prototype.encryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:if(t.data.byteLength<=0)throw new Error("encryption error. empty content");return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.encryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,mimeType:"application/octet-stream",data:s})]}}))}))},e.prototype.decryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.decryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,data:s})]}}))}))},e.prototype.getKey=function(t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return[4,crypto.subtle.digest("SHA-256",e.encoder.encode(t))];case 1:return n=i.sent(),r=Array.from(new Uint8Array(n)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),o=e.encoder.encode(r.slice(0,32)).buffer,[2,crypto.subtle.importKey("raw",o,"AES-CBC",!0,["encrypt","decrypt"])]}}))}))},e.prototype.encryptArrayBuffer=function(e,t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),r=Li,o=[n.buffer],[4,crypto.subtle.encrypt({name:"AES-CBC",iv:n},e,t)];case 1:return[2,r.apply(void 0,o.concat([i.sent()]))]}}))}))},e.prototype.decryptArrayBuffer=function(t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:if(r=n.slice(0,16),n.slice(e.IV_LENGTH).byteLength<=0)throw new Error("decryption error: empty content");return[4,crypto.subtle.decrypt({name:"AES-CBC",iv:r},t,n.slice(e.IV_LENGTH))];case 1:return[2,o.sent()]}}))}))},e.prototype.encryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=crypto.getRandomValues(new Uint8Array(16)),o=e.encoder.encode(n).buffer,[4,crypto.subtle.encrypt({name:"AES-CBC",iv:r},t,o)];case 1:return s=i.sent(),a=Li(r.buffer,s),[2,e.decoder.decode(a)]}}))}))},e.prototype.decryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=e.encoder.encode(n).buffer,o=r.slice(0,16),s=r.slice(16),[4,crypto.subtle.decrypt({name:"AES-CBC",iv:o},t,s)];case 1:return a=i.sent(),[2,e.decoder.decode(a)]}}))}))},e.IV_LENGTH=16,e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Bi=(Gi=function(){function e(e){if(e instanceof File)this.data=e,this.name=this.data.name,this.mimeType=this.data.type;else if(e.data){var t=e.data;this.data=new File([t],e.name,{type:e.mimeType}),this.name=e.name,e.mimeType&&(this.mimeType=e.mimeType)}if(void 0===this.data)throw new Error("Couldn't construct a file out of supplied options.");if(void 0===this.name)throw new Error("Couldn't guess filename out of the options. Please provide one.")}return e.create=function(e){return new this(e)},e.prototype.toBuffer=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toStream=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toFileUri=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in react native environments.")}))}))},e.prototype.toBlob=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e.prototype.toArrayBuffer=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if(r.result instanceof ArrayBuffer)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsArrayBuffer(e.data)}))]}))}))},e.prototype.toString=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if("string"==typeof r.result)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsBinaryString(e.data)}))]}))}))},e.prototype.toFile=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e}(),Gi.supportsFile="undefined"!=typeof File,Gi.supportsBlob="undefined"!=typeof Blob,Gi.supportsArrayBuffer="undefined"!=typeof ArrayBuffer,Gi.supportsBuffer=!1,Gi.supportsStream=!1,Gi.supportsString=!0,Gi.supportsEncryptFile=!0,Gi.supportsFileUri=!1,Gi),Hi=function(){function e(e){this.config=e,this.cryptor=new T({config:e}),this.fileCryptor=new Ki}return Object.defineProperty(e.prototype,"identifier",{get:function(){return""},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e){var t="string"==typeof e?e:(new TextDecoder).decode(e);return{data:this.cryptor.encrypt(t),metadata:null}},e.prototype.decrypt=function(e){var t="string"==typeof e.data?e.data:b(e.data);return this.cryptor.decrypt(t)},e.prototype.encryptFile=function(e,t){var n;return o(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)]}))}))},e.prototype.decryptFile=function(e,t){return o(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.fileCryptor.decryptFile(this.config.cipherKey,e,t)]}))}))},e}(),qi=function(){function e(e){this.cipherKey=e.cipherKey,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(this.cipherKey)}return Object.defineProperty(e.prototype,"algo",{get:function(){return"AES-CBC"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return"ACRH"},enumerable:!1,configurable:!0}),e.prototype.getIv=function(){return crypto.getRandomValues(new Uint8Array(e.BLOCK_SIZE))},e.prototype.getKey=function(){return o(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return t=e.encoder.encode(this.cipherKey),[4,crypto.subtle.digest("SHA-256",t.buffer)];case 1:return n=r.sent(),[2,crypto.subtle.importKey("raw",n,this.algo,!0,["encrypt","decrypt"])]}}))}))},e.prototype.encrypt=function(t){if(0===("string"==typeof t?t:e.decoder.decode(t)).length)throw new Error("encryption error. empty content");var n=this.getIv();return{metadata:n,data:m(this.CryptoJS.AES.encrypt(t,this.encryptedKey,{iv:this.bufferToWordArray(n),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}},e.prototype.decrypt=function(t){var n=this.bufferToWordArray(new Uint8ClampedArray(t.metadata)),r=this.bufferToWordArray(new Uint8ClampedArray(t.data));return e.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:r},this.encryptedKey,{iv:n,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer},e.prototype.encryptFileData=function(e){return o(this,void 0,void 0,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:return[4,this.getKey()];case 1:return t=o.sent(),n=this.getIv(),r={},[4,crypto.subtle.encrypt({name:this.algo,iv:n},t,e)];case 2:return[2,(r.data=o.sent(),r.metadata=n,r)]}}))}))},e.prototype.decryptFileData=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.getKey()];case 1:return t=n.sent(),[2,crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)]}}))}))},e.prototype.bufferToWordArray=function(e){var t,n=[];for(t=0;t0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("decryption error. empty content");return r.decrypt({data:t.slice(n.length),metadata:o})},e.prototype.encryptFile=function(e,t){return o(this,void 0,void 0,(function(){var n,r;return i(this,(function(o){switch(o.label){case 0:return this.defaultCryptor.identifier===Vi.LEGACY_IDENTIFIER?[2,this.defaultCryptor.encryptFile(e,t)]:[4,this.getFileData(e.data)];case 1:return n=o.sent(),[4,this.defaultCryptor.encryptFileData(n)];case 2:return r=o.sent(),[2,t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(r),r.data)})]}}))}))},e.prototype.decryptFile=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a,u,c,l,p;return i(this,(function(i){switch(i.label){case 0:return[4,t.data.arrayBuffer()];case 1:return r=i.sent(),o=Vi.tryParse(r),(null==(s=this.getCryptor(o))?void 0:s.identifier)===e.LEGACY_IDENTIFIER?[2,s.decryptFile(t,n)]:[4,this.getFileData(r)];case 2:return a=i.sent(),u=a.slice(o.length-o.metadataLength,o.length),l=(c=n).create,p={name:t.name},[4,this.defaultCryptor.decryptFileData({data:r.slice(o.length),metadata:u})];case 3:return[2,l.apply(c,[(p.data=i.sent(),p)])]}}))}))},e.prototype.getCryptor=function(e){if(""===e){var t=this.getAllCryptors().find((function(e){return""===e.identifier}));if(t)return t;throw new Error("unknown cryptor error")}if(e instanceof Wi)return this.getCryptorFromId(e.identifier)},e.prototype.getCryptorFromId=function(e){var t=this.getAllCryptors().find((function(t){return e===t.identifier}));if(t)return t;throw Error("unknown cryptor error")},e.prototype.concatArrayBuffer=function(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer},e.prototype.getHeaderData=function(e){if(e.metadata){var t=Vi.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length),r=0;return n.set(t.data,r),r+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),r),n.buffer}},e.prototype.getFileData=function(t){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return t instanceof Blob?[4,t.arrayBuffer()]:[3,2];case 1:return[2,n.sent()];case 2:if(t instanceof ArrayBuffer)return[2,t];if("string"==typeof t)return[2,e.encoder.encode(t)];throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}}))}))},e.LEGACY_IDENTIFIER="",e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Vi=function(){function e(){}return e.from=function(t,n){if(t!==e.LEGACY_IDENTIFIER)return new Wi(t,n.byteLength)},e.tryParse=function(t){var n=new Uint8Array(t),r="";if(n.byteLength>=4&&(r=n.slice(0,4),this.decoder.decode(r)!==e.SENTINEL))return"";if(!(n.byteLength>=5))throw new Error("decryption error. invalid header version");if(n[4]>e.MAX_VERSION)throw new Error("unknown cryptor error");var o="",i=5+e.IDENTIFIER_LENGTH;if(!(n.byteLength>=i))throw new Error("decryption error. invalid crypto identifier");o=n.slice(5,i);var s=null;if(!(n.byteLength>=i+1))throw new Error("decryption error. invalid metadata length");return s=n[i],i+=1,255===s&&n.byteLength>=i+2&&(s=new Uint16Array(n.slice(i,i+2)).reduce((function(e,t){return(e<<8)+t}),0),i+=2),new Wi(this.decoder.decode(o),s)},e.SENTINEL="PNED",e.LEGACY_IDENTIFIER="",e.IDENTIFIER_LENGTH=4,e.VERSION=1,e.MAX_VERSION=1,e.decoder=new TextDecoder,e}(),Wi=function(){function e(e,t){this._identifier=e,this._metadataLength=t}return Object.defineProperty(e.prototype,"identifier",{get:function(){return this._identifier},set:function(e){this._identifier=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"metadataLength",{get:function(){return this._metadataLength},set:function(e){this._metadataLength=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return Vi.VERSION},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return Vi.SENTINEL.length+1+Vi.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){var e=0,t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(Vi.SENTINEL)),t[e+=Vi.SENTINEL.length]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e),e+=Vi.IDENTIFIER_LENGTH;var r=this.metadataLength;return r<255?t[e]=r:t.set([255,r>>8,255&r],e),t},enumerable:!1,configurable:!0}),e.IDENTIFIER_LENGTH=4,e.SENTINEL="PNED",e}();function Ji(e){if(!navigator||!navigator.sendBeacon)return!1;navigator.sendBeacon(e)}var $i=function(e){function n(t){var n=this,r=t.listenToBrowserNetworkEvents,o=void 0===r||r;return t.sdkFamily="Web",t.networking=new _n({del:Fi,get:Ui,post:Ii,patch:Di,sendBeacon:Ji,getfile:xi,postfile:Ri}),t.cbor=new wn((function(e){return Sn(h.decode(e))}),m),t.PubNubFile=Bi,t.cryptography=new Ki,t.initCryptoModule=function(e){return new zi({default:new Hi({cipherKey:e.cipherKey,useRandomIVs:e.useRandomIVs}),cryptors:[new qi({cipherKey:e.cipherKey})]})},n=e.call(this,t)||this,o&&(window.addEventListener("offline",(function(){n.networkDownDetected()})),window.addEventListener("online",(function(){n.networkUpDetected()}))),n}return t(n,e),n.CryptoModule=zi,n}(vn);return $i})); diff --git a/lib/core/components/config.js b/lib/core/components/config.js index f6dcceb4e..0b7786537 100644 --- a/lib/core/components/config.js +++ b/lib/core/components/config.js @@ -180,7 +180,7 @@ var default_1 = /** @class */ (function () { return this; }; default_1.prototype.getVersion = function () { - return '7.5.0'; + return '7.6.0'; }; default_1.prototype._setRetryConfiguration = function (configuration) { if (configuration.minimumdelay < 2) { diff --git a/lib/core/components/eventEmitter.js b/lib/core/components/eventEmitter.js index d9f6def25..06c8dc8eb 100644 --- a/lib/core/components/eventEmitter.js +++ b/lib/core/components/eventEmitter.js @@ -28,6 +28,8 @@ var EventEmitter = /** @class */ (function () { this.modules = modules; this.listenerManager = listenerManager; this.getFileUrl = getFileUrl; + this._channelListenerMap = new Map(); + this._groupListenerMap = new Map(); if (modules.cryptoModule) this._decoder = new TextDecoder(); } @@ -62,7 +64,12 @@ var EventEmitter = /** @class */ (function () { if (e.payload.timeout) { announce.timeout = e.payload.timeout; } + // deprecated --> + announce.actualChannel = subscriptionMatch != null ? channel : null; + announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; + // <-- deprecated this.listenerManager.announcePresence(announce); + this._announce('presence', announce, announce.channel, announce.subscription); } else if (e.messageType === 1) { var announce = {}; @@ -77,6 +84,7 @@ var EventEmitter = /** @class */ (function () { } announce.message = e.payload; this.listenerManager.announceSignal(announce); + this._announce('signal', announce, announce.channel, announce.subscription); } else if (e.messageType === 2) { var announce = {}; @@ -95,20 +103,27 @@ var EventEmitter = /** @class */ (function () { data: e.payload.data, }; this.listenerManager.announceObjects(announce); + this._announce('objects', announce, announce.channel, announce.subscription); if (e.payload.type === 'uuid') { var eventData = this._renameChannelField(announce); - this.listenerManager.announceUser(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) })); + var userEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) }); + this.listenerManager.announceUser(userEvent); + this._announce('user', userEvent, announce.channel, announce.subscription); } else if (message.payload.type === 'channel') { var eventData = this._renameChannelField(announce); - this.listenerManager.announceSpace(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) })); + var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) }); + this.listenerManager.announceSpace(spaceEvent); + this._announce('space', spaceEvent, announce.channel, announce.subscription); } else if (message.payload.type === 'membership') { var eventData = this._renameChannelField(announce); var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]); membershipData.user = user; membershipData.space = space; - this.listenerManager.announceMembership(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) })); + var membershipEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) }); + this.listenerManager.announceMembership(membershipEvent); + this._announce('membership', membershipEvent, announce.channel, announce.subscription); } } else if (e.messageType === 3) { @@ -126,6 +141,7 @@ var EventEmitter = /** @class */ (function () { }; announce.event = e.payload.event; this.listenerManager.announceMessageAction(announce); + this._announce('messageAction', announce, announce.channel, announce.subscription); } else if (e.messageType === 4) { var announce = {}; @@ -163,6 +179,7 @@ var EventEmitter = /** @class */ (function () { }), }; this.listenerManager.announceFile(announce); + this._announce('file', announce, announce.channel, announce.subscription); } else { var announce = {}; @@ -196,9 +213,59 @@ var EventEmitter = /** @class */ (function () { else { announce.message = e.payload; } + // deprecated --> + announce.actualChannel = subscriptionMatch != null ? channel : null; + announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; + // <-- deprecated this.listenerManager.announceMessage(announce); + this._announce('message', announce, announce.channel, announce.subscription); } }; + EventEmitter.prototype.addListener = function (l, channels, groups) { + var _this = this; + if (!(channels && groups)) { + this.listenerManager.addListener(l); + } + else { + channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { + if (_this._channelListenerMap[c]) { + if (!_this._channelListenerMap[c].includes(l)) + _this._channelListenerMap[c].push(l); + } + else { + _this._channelListenerMap[c] = [l]; + } + }); + groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { + if (_this._groupListenerMap[g]) { + if (!_this._groupListenerMap[g].includes(l)) + _this._groupListenerMap[g].push(l); + } + else { + _this._groupListenerMap[g] = [l]; + } + }); + } + }; + EventEmitter.prototype.removeListener = function (listener, channels, groups) { + var _this = this; + if (!(channels && groups)) { + this.listenerManager.removeListener(listener); + } + else { + channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { + var _a; + _this._channelListenerMap[c] = (_a = _this._channelListenerMap[c]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; }); + }); + groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { + var _a; + _this._groupListenerMap[g] = (_a = _this._groupListenerMap[g]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; }); + }); + } + }; + EventEmitter.prototype.removeAllListeners = function () { + this.listenerManager.removeAllListeners(); + }; EventEmitter.prototype._renameEvent = function (e) { return e === 'set' ? 'updated' : 'removed'; }; @@ -207,6 +274,11 @@ var EventEmitter = /** @class */ (function () { eventData.spaceId = channel; return eventData; }; + EventEmitter.prototype._announce = function (type, event, channel, group) { + var _a, _b; + (_a = this._channelListenerMap[channel]) === null || _a === void 0 ? void 0 : _a.forEach(function (l) { return l[type] && l[type](event); }); + (_b = this._groupListenerMap[group]) === null || _b === void 0 ? void 0 : _b.forEach(function (l) { return l[type] && l[type](event); }); + }; return EventEmitter; }()); exports.default = EventEmitter; diff --git a/lib/core/components/subscription_manager.js b/lib/core/components/subscription_manager.js index 28166718e..077bb4a1b 100644 --- a/lib/core/components/subscription_manager.js +++ b/lib/core/components/subscription_manager.js @@ -1,15 +1,4 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) @@ -27,11 +16,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); var reconnection_manager_1 = __importDefault(require("./reconnection_manager")); var deduping_manager_1 = __importDefault(require("./deduping_manager")); -var utils_1 = __importDefault(require("../utils")); var categories_1 = __importDefault(require("../constants/categories")); var default_1 = /** @class */ (function () { function default_1(_a) { - var subscribeEndpoint = _a.subscribeEndpoint, leaveEndpoint = _a.leaveEndpoint, heartbeatEndpoint = _a.heartbeatEndpoint, setStateEndpoint = _a.setStateEndpoint, timeEndpoint = _a.timeEndpoint, getFileUrl = _a.getFileUrl, config = _a.config, crypto = _a.crypto, listenerManager = _a.listenerManager, cryptoModule = _a.cryptoModule; + var subscribeEndpoint = _a.subscribeEndpoint, leaveEndpoint = _a.leaveEndpoint, heartbeatEndpoint = _a.heartbeatEndpoint, setStateEndpoint = _a.setStateEndpoint, timeEndpoint = _a.timeEndpoint, getFileUrl = _a.getFileUrl, config = _a.config, crypto = _a.crypto, listenerManager = _a.listenerManager, cryptoModule = _a.cryptoModule, eventEmitter = _a.eventEmitter; this._listenerManager = listenerManager; this._config = config; this._leaveEndpoint = leaveEndpoint; @@ -58,6 +46,7 @@ var default_1 = /** @class */ (function () { this._dedupingManager = new deduping_manager_1.default({ config: config }); if (this._cryptoModule) this._decoder = new TextDecoder(); + this._eventEmitter = eventEmitter; } default_1.prototype.adaptStateChange = function (args, callback) { var _this = this; @@ -410,7 +399,6 @@ var default_1 = /** @class */ (function () { messages.forEach(function (message) { var channel = message.channel; var subscriptionMatch = message.subscriptionMatch; - var publishMetaData = message.publishMetaData; if (channel === subscriptionMatch) { subscriptionMatch = null; } @@ -420,179 +408,7 @@ var default_1 = /** @class */ (function () { } _this._dedupingManager.addEntry(message); } - if (utils_1.default.endsWith(message.channel, '-pnpres')) { - var announce = {}; - announce.channel = null; - announce.subscription = null; - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - if (channel) { - announce.channel = channel.substring(0, channel.lastIndexOf('-pnpres')); - } - if (subscriptionMatch) { - announce.subscription = subscriptionMatch.substring(0, subscriptionMatch.lastIndexOf('-pnpres')); - } - announce.action = message.payload.action; - announce.state = message.payload.data; - announce.timetoken = publishMetaData.publishTimetoken; - announce.occupancy = message.payload.occupancy; - announce.uuid = message.payload.uuid; - announce.timestamp = message.payload.timestamp; - if (message.payload.join) { - announce.join = message.payload.join; - } - if (message.payload.leave) { - announce.leave = message.payload.leave; - } - if (message.payload.timeout) { - announce.timeout = message.payload.timeout; - } - _this._listenerManager.announcePresence(announce); - } - else if (message.messageType === 1) { - // this is a signal message - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - announce.message = message.payload; - _this._listenerManager.announceSignal(announce); - } - else if (message.messageType === 2) { - // this is an object message - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - announce.message = { - event: message.payload.event, - type: message.payload.type, - data: message.payload.data, - }; - _this._listenerManager.announceObjects(announce); - if (message.payload.type === 'uuid') { - var eventData = _this._renameChannelField(announce); - _this._listenerManager.announceUser(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: _this._renameEvent(eventData.message.event), type: 'user' }) })); - } - else if (message.payload.type === 'channel') { - var eventData = _this._renameChannelField(announce); - _this._listenerManager.announceSpace(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: _this._renameEvent(eventData.message.event), type: 'space' }) })); - } - else if (message.payload.type === 'membership') { - var eventData = _this._renameChannelField(announce); - var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]); - membershipData.user = user; - membershipData.space = space; - _this._listenerManager.announceMembership(__assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: _this._renameEvent(eventData.message.event), data: membershipData }) })); - } - } - else if (message.messageType === 3) { - // this is a message action - var announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - announce.data = { - messageTimetoken: message.payload.data.messageTimetoken, - actionTimetoken: message.payload.data.actionTimetoken, - type: message.payload.data.type, - uuid: message.issuingClientId, - value: message.payload.data.value, - }; - announce.event = message.payload.event; - _this._listenerManager.announceMessageAction(announce); - } - else if (message.messageType === 4) { - // this is a file message - var announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - var msgPayload = message.payload; - if (_this._cryptoModule) { - var decryptedPayload = void 0; - try { - var decryptedData = _this._cryptoModule.decrypt(message.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(_this._decoder.decode(decryptedData)) : decryptedData; - } - catch (e) { - decryptedPayload = null; - announce.error = "Error while decrypting message content: ".concat(e.message); - } - if (decryptedPayload !== null) { - msgPayload = decryptedPayload; - } - } - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - announce.message = msgPayload.message; - announce.file = { - id: msgPayload.file.id, - name: msgPayload.file.name, - url: _this._getFileUrl({ - id: msgPayload.file.id, - name: msgPayload.file.name, - channel: channel, - }), - }; - _this._listenerManager.announceFile(announce); - } - else { - var announce = {}; - announce.channel = null; - announce.subscription = null; - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - if (_this._cryptoModule) { - var decryptedPayload = void 0; - try { - var decryptedData = _this._cryptoModule.decrypt(message.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(_this._decoder.decode(decryptedData)) : decryptedData; - } - catch (e) { - decryptedPayload = null; - announce.error = "Error while decrypting message content: ".concat(e.message); - } - if (decryptedPayload != null) { - announce.message = decryptedPayload; - } - else { - announce.message = message.payload; - } - } - else { - announce.message = message.payload; - } - _this._listenerManager.announceMessage(announce); - } + _this._eventEmitter.emitEvent(message); }); this._region = payload.metadata.region; this._startSubscribeLoop(); diff --git a/lib/core/components/telemetry_manager.js b/lib/core/components/telemetry_manager.js index d5d9a7d40..f63405121 100644 --- a/lib/core/components/telemetry_manager.js +++ b/lib/core/components/telemetry_manager.js @@ -10,6 +10,11 @@ var default_1 = /** @class */ (function () { this._maximumSamplesCount = 100; this._trackedLatencies = {}; this._latencies = {}; + this._telemetryExcludeOperations = [ + operations_1.default.PNSubscribeOperation, + operations_1.default.PNReceiveMessagesOperation, + operations_1.default.PNHandshakeOperation, + ]; this._maximumSamplesCount = configuration.maximumSamplesCount || this._maximumSamplesCount; } /** @@ -30,13 +35,13 @@ var default_1 = /** @class */ (function () { return latencies; }; default_1.prototype.startLatencyMeasure = function (operationType, identifier) { - if (operationType === operations_1.default.PNSubscribeOperation || !identifier) { + if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { return; } this._trackedLatencies[identifier] = Date.now(); }; default_1.prototype.stopLatencyMeasure = function (operationType, identifier) { - if (operationType === operations_1.default.PNSubscribeOperation || !identifier) { + if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { return; } var endpointName = this._endpointName(operationType); diff --git a/lib/core/endpoints/subscriptionUtils/handshake.js b/lib/core/endpoints/subscriptionUtils/handshake.js index 6eb2f5333..c30834e5b 100644 --- a/lib/core/endpoints/subscriptionUtils/handshake.js +++ b/lib/core/endpoints/subscriptionUtils/handshake.js @@ -14,8 +14,9 @@ var endpoint = { }, getURL: function (_a, params) { var config = _a.config; - var channelsString = params.channels ? params.channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils_1.default.encodeString(channelsString), "/0"); + var _b = params.channels, channels = _b === void 0 ? [] : _b; + var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; + return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils_1.default.encodeString(stringifiedChannels), "/0"); }, getRequestTimeout: function (_a) { var config = _a.config; diff --git a/lib/core/endpoints/subscriptionUtils/receiveMessages.js b/lib/core/endpoints/subscriptionUtils/receiveMessages.js index 0bf41a38c..e9d07554a 100644 --- a/lib/core/endpoints/subscriptionUtils/receiveMessages.js +++ b/lib/core/endpoints/subscriptionUtils/receiveMessages.js @@ -20,8 +20,9 @@ var endpoint = { }, getURL: function (_a, params) { var config = _a.config; - var channelsString = params.channels ? params.channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils_1.default.encodeString(channelsString), "/0"); + var _b = params.channels, channels = _b === void 0 ? [] : _b; + var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; + return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils_1.default.encodeString(stringifiedChannels), "/0"); }, getRequestTimeout: function (_a) { var config = _a.config; diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 80e6d8562..9a145cdc7 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -144,6 +144,11 @@ var event_engine_1 = require("../event-engine"); var presence_1 = require("../event-engine/presence/presence"); var retryPolicy_1 = require("../event-engine/core/retryPolicy"); var eventEmitter_1 = __importDefault(require("./components/eventEmitter")); +var Channel_1 = require("../entities/Channel"); +var ChannelGroup_1 = require("../entities/ChannelGroup"); +var ChannelMetadata_1 = require("../entities/ChannelMetadata"); +var UserMetadata_1 = require("../entities/UserMetadata"); +var SubscriptionSet_1 = require("../entities/SubscriptionSet"); var default_1 = /** @class */ (function () { function default_1(setup) { var _this = this; @@ -198,12 +203,12 @@ var default_1 = /** @class */ (function () { this.setPresenceState = endpoint_1.default.bind(this, modules, presenceSetStateConfig); this.handshake = endpoint_1.default.bind(this, modules, handshake_1.default); this.receiveMessages = endpoint_1.default.bind(this, modules, receiveMessages_1.default); + this._eventEmitter = new eventEmitter_1.default({ + modules: modules, + listenerManager: this._listenerManager, + getFileUrl: function (params) { return (0, get_file_url_1.default)(modules, params); }, + }); if (config.enableEventEngine === true) { - this._eventEmitter = new eventEmitter_1.default({ - modules: modules, - listenerManager: this._listenerManager, - getFileUrl: function (params) { return (0, get_file_url_1.default)(modules, params); }, - }); if (config.maintainPresenceState) { this.presenceState = {}; this.setState = function (args) { @@ -287,6 +292,7 @@ var default_1 = /** @class */ (function () { listenerManager: listenerManager, getFileUrl: function (params) { return (0, get_file_url_1.default)(modules, params); }, cryptoModule: modules.cryptoModule, + eventEmitter: this._eventEmitter, }); this.subscribe = subscriptionManager_1.adaptSubscribeChange.bind(subscriptionManager_1); this.unsubscribe = subscriptionManager_1.adaptUnsubscribeChange.bind(subscriptionManager_1); @@ -302,9 +308,9 @@ var default_1 = /** @class */ (function () { subscriptionManager_1.disconnect(); }; } - this.addListener = listenerManager.addListener.bind(listenerManager); - this.removeListener = listenerManager.removeListener.bind(listenerManager); - this.removeAllListeners = listenerManager.removeAllListeners.bind(listenerManager); + this.addListener = this._eventEmitter.addListener.bind(this._eventEmitter); + this.removeListener = this._eventEmitter.removeListener.bind(this._eventEmitter); + this.removeAllListeners = this._eventEmitter.removeAllListeners.bind(this._eventEmitter); this.parseToken = tokenManager.parseToken.bind(tokenManager); this.setToken = tokenManager.setToken.bind(tokenManager); this.getToken = tokenManager.getToken.bind(tokenManager); @@ -359,6 +365,20 @@ var default_1 = /** @class */ (function () { this.getFileUrl = function (params) { return (0, get_file_url_1.default)(modules, params); }; this.downloadFile = endpoint_1.default.bind(this, modules, download_file_1.default); this.deleteFile = endpoint_1.default.bind(this, modules, delete_file_1.default); + // entities + this.channel = function (name) { return new Channel_1.Channel(name, _this._eventEmitter, _this); }; + this.channelGroup = function (name) { return new ChannelGroup_1.ChannelGroup(name, _this._eventEmitter, _this); }; + this.channelMetadata = function (id) { return new ChannelMetadata_1.ChannelMetadata(id, _this._eventEmitter, _this); }; + this.userMetadata = function (id) { return new UserMetadata_1.UserMetadata(id, _this._eventEmitter, _this); }; + this.subscriptionSet = function (args) { + return new SubscriptionSet_1.SubscriptionSet({ + channels: args.channels, + channelGroups: args.channelGroups, + subscriptionOptions: args.subscriptionOptions, + eventEmitter: _this._eventEmitter, + pubnub: _this, + }); + }; // Objects API v2 this.objects = { getAllUUIDMetadata: endpoint_1.default.bind(this, modules, get_all_1.default), diff --git a/lib/core/utils.js b/lib/core/utils.js index 3859102bc..51f97541f 100644 --- a/lib/core/utils.js +++ b/lib/core/utils.js @@ -1,4 +1,29 @@ "use strict"; +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; function objectToList(o) { var l = []; Object.keys(o).forEach(function (key) { return l.push(key); }); @@ -34,10 +59,27 @@ function stringToArrayBuffer(str) { } return buf; } +function removeSingleOccurance(source, elementsToRemove) { + var removed = Object.fromEntries(elementsToRemove.map(function (prop) { return [prop, false]; })); + return source.filter(function (e) { + if (elementsToRemove.includes(e) && !removed[e]) { + removed[e] = true; + return false; + } + return true; + }); +} +function findUniqueCommonElements(a, b) { + return __spreadArray([], __read(a), false).filter(function (value) { + return b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value); + }); +} module.exports = { signPamFromParams: signPamFromParams, endsWith: endsWith, createPromise: createPromise, encodeString: encodeString, stringToArrayBuffer: stringToArrayBuffer, + removeSingleOccurance: removeSingleOccurance, + findUniqueCommonElements: findUniqueCommonElements, }; diff --git a/lib/entities/Channel.js b/lib/entities/Channel.js new file mode 100644 index 000000000..0043f20dc --- /dev/null +++ b/lib/entities/Channel.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Channel = void 0; +var Subscription_1 = require("./Subscription"); +var Channel = /** @class */ (function () { + function Channel(channelName, eventEmitter, pubnub) { + this.name = channelName; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + Channel.prototype.subscription = function (subscriptionOptions) { + return new Subscription_1.Subscription({ + channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, "".concat(this.name, "-pnpres")] : [this.name], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return Channel; +}()); +exports.Channel = Channel; diff --git a/lib/entities/ChannelGroup.js b/lib/entities/ChannelGroup.js new file mode 100644 index 000000000..07a0bea48 --- /dev/null +++ b/lib/entities/ChannelGroup.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ChannelGroup = void 0; +var Subscription_1 = require("./Subscription"); +var ChannelGroup = /** @class */ (function () { + function ChannelGroup(channelGroup, eventEmitter, pubnub) { + this.name = channelGroup; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + ChannelGroup.prototype.subscription = function (subscriptionOptions) { + return new Subscription_1.Subscription({ + channels: [], + channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, "".concat(this.name, "-pnpres")] : [this.name], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return ChannelGroup; +}()); +exports.ChannelGroup = ChannelGroup; diff --git a/lib/entities/ChannelMetadata.js b/lib/entities/ChannelMetadata.js new file mode 100644 index 000000000..5345f4ed8 --- /dev/null +++ b/lib/entities/ChannelMetadata.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.ChannelMetadata = void 0; +var Subscription_1 = require("./Subscription"); +var ChannelMetadata = /** @class */ (function () { + function ChannelMetadata(id, eventEmitter, pubnub) { + this.id = id; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + ChannelMetadata.prototype.subscription = function (subscriptionOptions) { + return new Subscription_1.Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return ChannelMetadata; +}()); +exports.ChannelMetadata = ChannelMetadata; diff --git a/lib/entities/SubscribeCapable.js b/lib/entities/SubscribeCapable.js new file mode 100644 index 000000000..554527544 --- /dev/null +++ b/lib/entities/SubscribeCapable.js @@ -0,0 +1,92 @@ +"use strict"; +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SubscribeCapable = void 0; +var SubscribeCapable = /** @class */ (function () { + function SubscribeCapable() { + } + SubscribeCapable.prototype.subscribe = function () { + var _a, _b; + this.pubnub.subscribe(__assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken }))); + }; + SubscribeCapable.prototype.unsubscribe = function () { + this.pubnub.unsubscribe({ + channels: this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), + channelGroups: this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }), + }); + }; + Object.defineProperty(SubscribeCapable.prototype, "onMessage", { + set: function (onMessagelistener) { + this.listener.message = onMessagelistener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onPresence", { + set: function (onPresencelistener) { + this.listener.presence = onPresencelistener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onSignal", { + set: function (onSignalListener) { + this.listener.signal = onSignalListener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onObjects", { + set: function (onObjectsListener) { + this.listener.objects = onObjectsListener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onMessageAction", { + set: function (messageActionEventListener) { + this.listener.messageAction = messageActionEventListener; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "onFile", { + set: function (fileEventListener) { + this.listener.file = fileEventListener; + }, + enumerable: false, + configurable: true + }); + SubscribeCapable.prototype.addListener = function (listener) { + this.eventEmitter.addListener(listener, this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); + }; + SubscribeCapable.prototype.removeListener = function (listener) { + this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); + }; + Object.defineProperty(SubscribeCapable.prototype, "channels", { + get: function () { + return this.channelNames.slice(0); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(SubscribeCapable.prototype, "channelGroups", { + get: function () { + return this.groupNames.slice(0); + }, + enumerable: false, + configurable: true + }); + return SubscribeCapable; +}()); +exports.SubscribeCapable = SubscribeCapable; diff --git a/lib/entities/Subscription.js b/lib/entities/Subscription.js new file mode 100644 index 000000000..586f8d3c3 --- /dev/null +++ b/lib/entities/Subscription.js @@ -0,0 +1,84 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __assign = (this && this.__assign) || function () { + __assign = Object.assign || function(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) + t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Subscription = void 0; +var SubscriptionSet_1 = require("./SubscriptionSet"); +var SubscribeCapable_1 = require("./SubscribeCapable"); +var Subscription = /** @class */ (function (_super) { + __extends(Subscription, _super); + function Subscription(_a) { + var channels = _a.channels, channelGroups = _a.channelGroups, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub; + var _this = _super.call(this) || this; + _this.channelNames = []; + _this.groupNames = []; + _this.channelNames = channels; + _this.groupNames = channelGroups; + _this.options = subscriptionOptions; + _this.pubnub = pubnub; + _this.eventEmitter = eventEmitter; + _this.listener = {}; + eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); + return _this; + } + Subscription.prototype.addSubscription = function (subscription) { + return new SubscriptionSet_1.SubscriptionSet({ + channels: __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscription.channels), false), + channelGroups: __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(subscription.channelGroups), false), + subscriptionOptions: __assign(__assign({}, this.options), subscription === null || subscription === void 0 ? void 0 : subscription.options), + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return Subscription; +}(SubscribeCapable_1.SubscribeCapable)); +exports.Subscription = Subscription; diff --git a/lib/entities/SubscriptionSet.js b/lib/entities/SubscriptionSet.js new file mode 100644 index 000000000..bc1417e61 --- /dev/null +++ b/lib/entities/SubscriptionSet.js @@ -0,0 +1,103 @@ +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + if (typeof b !== "function" && b !== null) + throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var __read = (this && this.__read) || function (o, n) { + var m = typeof Symbol === "function" && o[Symbol.iterator]; + if (!m) return o; + var i = m.call(o), r, ar = [], e; + try { + while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); + } + catch (error) { e = { error: error }; } + finally { + try { + if (r && !r.done && (m = i["return"])) m.call(i); + } + finally { if (e) throw e.error; } + } + return ar; +}; +var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SubscriptionSet = void 0; +var SubscribeCapable_1 = require("./SubscribeCapable"); +var SubscriptionSet = /** @class */ (function (_super) { + __extends(SubscriptionSet, _super); + function SubscriptionSet(_a) { + var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub; + var _this = _super.call(this) || this; + _this.channelNames = []; + _this.groupNames = []; + _this.subscriptionList = []; + _this.options = subscriptionOptions; + _this.eventEmitter = eventEmitter; + _this.pubnub = pubnub; + channels.forEach(function (c) { + var subscription = _this.pubnub.channel(c).subscription(_this.options); + _this.channelNames = __spreadArray(__spreadArray([], __read(_this.channelNames), false), __read(subscription.channels), false); + _this.subscriptionList.push(subscription); + }); + channelGroups.forEach(function (cg) { + var subscription = _this.pubnub.channelGroup(cg).subscription(_this.options); + _this.groupNames = __spreadArray(__spreadArray([], __read(_this.groupNames), false), __read(subscription.channelGroups), false); + _this.subscriptionList.push(subscription); + }); + _this.listener = {}; + eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); + return _this; + } + SubscriptionSet.prototype.addSubscription = function (subscription) { + this.subscriptionList.push(subscription); + this.channelNames = __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscription.channels), false); + this.groupNames = __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(subscription.channelGroups), false); + }; + SubscriptionSet.prototype.removeSubscription = function (subscription) { + var channelsToRemove = subscription.channels; + var groupsToRemove = subscription.channelGroups; + this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); + this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); + this.subscriptionList = this.subscriptionList.filter(function (s) { return s !== subscription; }); + }; + SubscriptionSet.prototype.addSubscriptionSet = function (subscriptionSet) { + this.subscriptionList = __spreadArray(__spreadArray([], __read(this.subscriptionList), false), __read(subscriptionSet.subscriptions), false); + this.channelNames = __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscriptionSet.channels), false); + this.groupNames = __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(subscriptionSet.channelGroups), false); + }; + SubscriptionSet.prototype.removeSubscriptionSet = function (subscriptionSet) { + var channelsToRemove = subscriptionSet.channels; + var groupsToRemove = subscriptionSet.channelGroups; + this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); + this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); + this.subscriptionList = this.subscriptionList.filter(function (s) { return !subscriptionSet.subscriptions.includes(s); }); + }; + Object.defineProperty(SubscriptionSet.prototype, "subscriptions", { + get: function () { + return this.subscriptionList.slice(0); + }, + enumerable: false, + configurable: true + }); + return SubscriptionSet; +}(SubscribeCapable_1.SubscribeCapable)); +exports.SubscriptionSet = SubscriptionSet; diff --git a/lib/entities/UserMetadata.js b/lib/entities/UserMetadata.js new file mode 100644 index 000000000..8989b01f3 --- /dev/null +++ b/lib/entities/UserMetadata.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UserMetadata = void 0; +var Subscription_1 = require("./Subscription"); +var UserMetadata = /** @class */ (function () { + function UserMetadata(id, eventEmitter, pubnub) { + this.id = id; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + UserMetadata.prototype.subscription = function (subscriptionOptions) { + return new Subscription_1.Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + }; + return UserMetadata; +}()); +exports.UserMetadata = UserMetadata; diff --git a/lib/entities/common.js b/lib/entities/common.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/entities/common.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/entities/commonTypes.js b/lib/entities/commonTypes.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/entities/commonTypes.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/event-engine/index.js b/lib/event-engine/index.js index 1cd5fa289..7d8811c25 100644 --- a/lib/event-engine/index.js +++ b/lib/event-engine/index.js @@ -53,6 +53,7 @@ var core_1 = require("./core"); var dispatcher_1 = require("./dispatcher"); var events = __importStar(require("./events")); var unsubscribed_1 = require("./states/unsubscribed"); +var utils = __importStar(require("../core/utils")); var EventEngine = /** @class */ (function () { function EventEngine(dependencies) { var _this = this; @@ -85,37 +86,40 @@ var EventEngine = /** @class */ (function () { this.groups.map(function (g) { return _this.groups.push("".concat(g, "-pnpres")); }); } if (timetoken) { - this.engine.transition(events.restore(this.channels, this.groups, timetoken)); + this.engine.transition(events.restore(Array.from(new Set(__spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false))), timetoken)); } else { - this.engine.transition(events.subscriptionChange(this.channels, this.groups)); + this.engine.transition(events.subscriptionChange(Array.from(new Set(__spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false))))); } if (this.dependencies.join) { this.dependencies.join({ - channels: this.channels.filter(function (c) { return !c.endsWith('-pnpres'); }), - groups: this.groups.filter(function (g) { return !g.endsWith('-pnpres'); }), + channels: Array.from(new Set(this.channels.filter(function (c) { return !c.endsWith('-pnpres'); }))), + groups: Array.from(new Set(this.groups.filter(function (g) { return !g.endsWith('-pnpres'); }))), }); } }; EventEngine.prototype.unsubscribe = function (_a) { var _this = this; - var channels = _a.channels, groups = _a.groups; - var channlesWithPres = channels === null || channels === void 0 ? void 0 : channels.slice(0); - channels === null || channels === void 0 ? void 0 : channels.map(function (c) { return channlesWithPres.push("".concat(c, "-pnpres")); }); - this.channels = this.channels.filter(function (channel) { return !(channlesWithPres === null || channlesWithPres === void 0 ? void 0 : channlesWithPres.includes(channel)); }); - var groupsWithPres = groups === null || groups === void 0 ? void 0 : groups.slice(0); - groups === null || groups === void 0 ? void 0 : groups.map(function (g) { return groupsWithPres.push("".concat(g, "-pnpres")); }); - this.groups = this.groups.filter(function (group) { return !(groupsWithPres === null || groupsWithPres === void 0 ? void 0 : groupsWithPres.includes(group)); }); - if (this.dependencies.presenceState) { - channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { return delete _this.dependencies.presenceState[c]; }); - groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { return delete _this.dependencies.presenceState[g]; }); - } - this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0))); - if (this.dependencies.leave) { - this.dependencies.leave({ - channels: channels, - groups: groups, - }); + var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c; + var filteredChannels = utils.removeSingleOccurance(this.channels, __spreadArray(__spreadArray([], __read(channels), false), __read(channels.map(function (c) { return "".concat(c, "-pnpres"); })), false)); + var filteredGroups = utils.removeSingleOccurance(this.groups, __spreadArray(__spreadArray([], __read(channelGroups), false), __read(channelGroups.map(function (c) { return "".concat(c, "-pnpres"); })), false)); + if (new Set(this.channels).size !== new Set(filteredChannels).size || + new Set(this.groups).size !== new Set(filteredGroups).size) { + var channelsToLeave = utils.findUniqueCommonElements(this.channels, channels); + var groupstoLeave = utils.findUniqueCommonElements(this.groups, channelGroups); + if (this.dependencies.presenceState) { + channelsToLeave === null || channelsToLeave === void 0 ? void 0 : channelsToLeave.forEach(function (c) { return delete _this.dependencies.presenceState[c]; }); + groupstoLeave === null || groupstoLeave === void 0 ? void 0 : groupstoLeave.forEach(function (g) { return delete _this.dependencies.presenceState[g]; }); + } + this.channels = filteredChannels; + this.groups = filteredGroups; + this.engine.transition(events.subscriptionChange(Array.from(new Set(this.channels.slice(0))), Array.from(new Set(this.groups.slice(0))))); + if (this.dependencies.leave) { + this.dependencies.leave({ + channels: channelsToLeave.slice(0), + groups: groupstoLeave.slice(0), + }); + } } }; EventEngine.prototype.unsubscribeAll = function () { diff --git a/package.json b/package.json index 82ffad741..da6bd4c2c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "7.5.0", + "version": "7.6.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/config.js b/src/core/components/config.js index ab9050acc..69bef414a 100644 --- a/src/core/components/config.js +++ b/src/core/components/config.js @@ -358,7 +358,7 @@ export default class { } getVersion() { - return '7.5.0'; + return '7.6.0'; } _setRetryConfiguration(configuration) { diff --git a/src/core/components/eventEmitter.js b/src/core/components/eventEmitter.js index 05a39972f..2157569de 100644 --- a/src/core/components/eventEmitter.js +++ b/src/core/components/eventEmitter.js @@ -3,11 +3,15 @@ export default class EventEmitter { listenerManager; getFileUrl; + _channelListenerMap; + _groupListenerMap; _decoder; constructor({ modules, listenerManager, getFileUrl }) { this.modules = modules; this.listenerManager = listenerManager; this.getFileUrl = getFileUrl; + this._channelListenerMap = new Map(); + this._groupListenerMap = new Map(); if (modules.cryptoModule) this._decoder = new TextDecoder(); } emitEvent(e) { @@ -48,8 +52,13 @@ export default class EventEmitter { if (e.payload.timeout) { announce.timeout = e.payload.timeout; } + // deprecated --> + announce.actualChannel = subscriptionMatch != null ? channel : null; + announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; + // <-- deprecated this.listenerManager.announcePresence(announce); + this._announce('presence', announce, announce.channel, announce.subscription); } else if (e.messageType === 1) { const announce = {}; announce.channel = null; @@ -66,6 +75,7 @@ export default class EventEmitter { announce.message = e.payload; this.listenerManager.announceSignal(announce); + this._announce('signal', announce, announce.channel, announce.subscription); } else if (e.messageType === 2) { const announce = {}; announce.channel = null; @@ -83,39 +93,46 @@ export default class EventEmitter { data: e.payload.data, }; this.listenerManager.announceObjects(announce); + this._announce('objects', announce, announce.channel, announce.subscription); if (e.payload.type === 'uuid') { const eventData = this._renameChannelField(announce); - this.listenerManager.announceUser({ + const userEvent = { ...eventData, message: { ...eventData.message, event: this._renameEvent(eventData.message.event), type: 'user', }, - }); + }; + this.listenerManager.announceUser(userEvent); + this._announce('user', userEvent, announce.channel, announce.subscription); } else if (message.payload.type === 'channel') { const eventData = this._renameChannelField(announce); - this.listenerManager.announceSpace({ + const spaceEvent = { ...eventData, message: { ...eventData.message, event: this._renameEvent(eventData.message.event), type: 'space', }, - }); + }; + this.listenerManager.announceSpace(spaceEvent); + this._announce('space', spaceEvent, announce.channel, announce.subscription); } else if (message.payload.type === 'membership') { const eventData = this._renameChannelField(announce); const { uuid: user, channel: space, ...membershipData } = eventData.message.data; membershipData.user = user; membershipData.space = space; - this.listenerManager.announceMembership({ + const membershipEvent = { ...eventData, message: { ...eventData.message, event: this._renameEvent(eventData.message.event), data: membershipData, }, - }); + }; + this.listenerManager.announceMembership(membershipEvent); + this._announce('membership', membershipEvent, announce.channel, announce.subscription); } } else if (e.messageType === 3) { const announce = {}; @@ -132,6 +149,7 @@ export default class EventEmitter { }; announce.event = e.payload.event; this.listenerManager.announceMessageAction(announce); + this._announce('messageAction', announce, announce.channel, announce.subscription); } else if (e.messageType === 4) { const announce = {}; announce.channel = channel; @@ -173,6 +191,7 @@ export default class EventEmitter { }; this.listenerManager.announceFile(announce); + this._announce('file', announce, announce.channel, announce.subscription); } else { const announce = {}; announce.channel = null; @@ -205,11 +224,54 @@ export default class EventEmitter { } else { announce.message = e.payload; } + // deprecated --> + announce.actualChannel = subscriptionMatch != null ? channel : null; + announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; + // <-- deprecated this.listenerManager.announceMessage(announce); + this._announce('message', announce, announce.channel, announce.subscription); } } + addListener(l, channels, groups) { + if (!(channels && groups)) { + this.listenerManager.addListener(l); + } else { + channels?.forEach((c) => { + if (this._channelListenerMap[c]) { + if (!this._channelListenerMap[c].includes(l)) this._channelListenerMap[c].push(l); + } else { + this._channelListenerMap[c] = [l]; + } + }); + groups?.forEach((g) => { + if (this._groupListenerMap[g]) { + if (!this._groupListenerMap[g].includes(l)) this._groupListenerMap[g].push(l); + } else { + this._groupListenerMap[g] = [l]; + } + }); + } + } + + removeListener(listener, channels, groups) { + if (!(channels && groups)) { + this.listenerManager.removeListener(listener); + } else { + channels?.forEach((c) => { + this._channelListenerMap[c] = this._channelListenerMap[c]?.filter((l) => l !== listener); + }); + groups?.forEach((g) => { + this._groupListenerMap[g] = this._groupListenerMap[g]?.filter((l) => l !== listener); + }); + } + } + + removeAllListeners() { + this.listenerManager.removeAllListeners(); + } + _renameEvent(e) { return e === 'set' ? 'updated' : 'removed'; } @@ -219,4 +281,9 @@ export default class EventEmitter { eventData.spaceId = channel; return eventData; } + + _announce(type, event, channel, group) { + this._channelListenerMap[channel]?.forEach((l) => l[type] && l[type](event)); + this._groupListenerMap[group]?.forEach((l) => l[type] && l[type](event)); + } } diff --git a/src/core/components/subscription_manager.js b/src/core/components/subscription_manager.js index 3480eca7a..1dd6fbed2 100644 --- a/src/core/components/subscription_manager.js +++ b/src/core/components/subscription_manager.js @@ -64,6 +64,8 @@ export default class { _dedupingManager; + _eventEmitter; + constructor({ subscribeEndpoint, leaveEndpoint, @@ -75,6 +77,7 @@ export default class { crypto, listenerManager, cryptoModule, + eventEmitter, }) { this._listenerManager = listenerManager; this._config = config; @@ -112,6 +115,8 @@ export default class { this._dedupingManager = new DedupingManager({ config }); if (this._cryptoModule) this._decoder = new TextDecoder(); + + this._eventEmitter = eventEmitter; } adaptStateChange(args, callback) { @@ -534,7 +539,6 @@ export default class { messages.forEach((message) => { const { channel } = message; let { subscriptionMatch } = message; - const { publishMetaData } = message; if (channel === subscriptionMatch) { subscriptionMatch = null; @@ -547,222 +551,7 @@ export default class { this._dedupingManager.addEntry(message); } - if (utils.endsWith(message.channel, '-pnpres')) { - const announce = {}; - announce.channel = null; - announce.subscription = null; - - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - - if (channel) { - announce.channel = channel.substring(0, channel.lastIndexOf('-pnpres')); - } - - if (subscriptionMatch) { - announce.subscription = subscriptionMatch.substring(0, subscriptionMatch.lastIndexOf('-pnpres')); - } - - announce.action = message.payload.action; - announce.state = message.payload.data; - announce.timetoken = publishMetaData.publishTimetoken; - announce.occupancy = message.payload.occupancy; - announce.uuid = message.payload.uuid; - announce.timestamp = message.payload.timestamp; - - if (message.payload.join) { - announce.join = message.payload.join; - } - - if (message.payload.leave) { - announce.leave = message.payload.leave; - } - - if (message.payload.timeout) { - announce.timeout = message.payload.timeout; - } - - this._listenerManager.announcePresence(announce); - } else if (message.messageType === 1) { - // this is a signal message - const announce = {}; - announce.channel = null; - announce.subscription = null; - - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - - announce.message = message.payload; - - this._listenerManager.announceSignal(announce); - } else if (message.messageType === 2) { - // this is an object message - - const announce = {}; - - announce.channel = null; - announce.subscription = null; - - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - - announce.message = { - event: message.payload.event, - type: message.payload.type, - data: message.payload.data, - }; - - this._listenerManager.announceObjects(announce); - - if (message.payload.type === 'uuid') { - const eventData = this._renameChannelField(announce); - this._listenerManager.announceUser({ - ...eventData, - message: { - ...eventData.message, - event: this._renameEvent(eventData.message.event), - type: 'user', - }, - }); - } else if (message.payload.type === 'channel') { - const eventData = this._renameChannelField(announce); - this._listenerManager.announceSpace({ - ...eventData, - message: { - ...eventData.message, - event: this._renameEvent(eventData.message.event), - type: 'space', - }, - }); - } else if (message.payload.type === 'membership') { - const eventData = this._renameChannelField(announce); - const { uuid: user, channel: space, ...membershipData } = eventData.message.data; - membershipData.user = user; - membershipData.space = space; - this._listenerManager.announceMembership({ - ...eventData, - message: { - ...eventData.message, - event: this._renameEvent(eventData.message.event), - data: membershipData, - }, - }); - } - } else if (message.messageType === 3) { - // this is a message action - const announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - - announce.data = { - messageTimetoken: message.payload.data.messageTimetoken, - actionTimetoken: message.payload.data.actionTimetoken, - type: message.payload.data.type, - uuid: message.issuingClientId, - value: message.payload.data.value, - }; - - announce.event = message.payload.event; - - this._listenerManager.announceMessageAction(announce); - } else if (message.messageType === 4) { - // this is a file message - const announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - - let msgPayload = message.payload; - - if (this._cryptoModule) { - let decryptedPayload; - try { - const decryptedData = this._cryptoModule.decrypt(message.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData; - } catch (e) { - decryptedPayload = null; - announce.error = `Error while decrypting message content: ${e.message}`; - } - if (decryptedPayload !== null) { - msgPayload = decryptedPayload; - } - } - - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - - announce.message = msgPayload.message; - - announce.file = { - id: msgPayload.file.id, - name: msgPayload.file.name, - url: this._getFileUrl({ - id: msgPayload.file.id, - name: msgPayload.file.name, - channel, - }), - }; - - this._listenerManager.announceFile(announce); - } else { - const announce = {}; - announce.channel = null; - announce.subscription = null; - - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; - announce.publisher = message.issuingClientId; - - if (message.userMetadata) { - announce.userMetadata = message.userMetadata; - } - - if (this._cryptoModule) { - let decryptedPayload; - try { - const decryptedData = this._cryptoModule.decrypt(message.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData; - } catch (e) { - decryptedPayload = null; - announce.error = `Error while decrypting message content: ${e.message}`; - } - if (decryptedPayload != null) { - announce.message = decryptedPayload; - } else { - announce.message = message.payload; - } - } else { - announce.message = message.payload; - } - - this._listenerManager.announceMessage(announce); - } + this._eventEmitter.emitEvent(message); }); this._region = payload.metadata.region; diff --git a/src/core/components/telemetry_manager.js b/src/core/components/telemetry_manager.js index 474b5f206..fa4392df4 100644 --- a/src/core/components/telemetry_manager.js +++ b/src/core/components/telemetry_manager.js @@ -8,6 +8,12 @@ export default class { _latencies = {}; + _telemetryExcludeOperations = [ + operationConstants.PNSubscribeOperation, + operationConstants.PNReceiveMessagesOperation, + operationConstants.PNHandshakeOperation, + ]; + constructor(configuration) { this._maximumSamplesCount = configuration.maximumSamplesCount || this._maximumSamplesCount; } @@ -33,7 +39,7 @@ export default class { } startLatencyMeasure(operationType, identifier) { - if (operationType === operationConstants.PNSubscribeOperation || !identifier) { + if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { return; } @@ -41,7 +47,7 @@ export default class { } stopLatencyMeasure(operationType, identifier) { - if (operationType === operationConstants.PNSubscribeOperation || !identifier) { + if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { return; } diff --git a/src/core/endpoints/subscriptionUtils/handshake.js b/src/core/endpoints/subscriptionUtils/handshake.js index 84fd489fc..68487c68d 100644 --- a/src/core/endpoints/subscriptionUtils/handshake.js +++ b/src/core/endpoints/subscriptionUtils/handshake.js @@ -11,8 +11,9 @@ const endpoint = { }, getURL: ({ config }, params) => { - const channelsString = params.channels ? params.channels.join(',') : ','; - return `/v2/subscribe/${config.subscribeKey}/${utils.encodeString(channelsString)}/0`; + const { channels = [] } = params; + const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; + return `/v2/subscribe/${config.subscribeKey}/${utils.encodeString(stringifiedChannels)}/0`; }, getRequestTimeout: ({ config }) => config.getSubscribeTimeout(), diff --git a/src/core/endpoints/subscriptionUtils/receiveMessages.js b/src/core/endpoints/subscriptionUtils/receiveMessages.js index b62c3acb3..c85a52ab5 100644 --- a/src/core/endpoints/subscriptionUtils/receiveMessages.js +++ b/src/core/endpoints/subscriptionUtils/receiveMessages.js @@ -17,8 +17,9 @@ const endpoint = { }, getURL: ({ config }, params) => { - const channelsString = params.channels ? params.channels.join(',') : ','; - return `/v2/subscribe/${config.subscribeKey}/${utils.encodeString(channelsString)}/0`; + const { channels = [] } = params; + const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; + return `/v2/subscribe/${config.subscribeKey}/${utils.encodeString(stringifiedChannels)}/0`; }, getRequestTimeout: ({ config }) => config.getSubscribeTimeout(), diff --git a/src/core/pubnub-common.js b/src/core/pubnub-common.js index e187a1995..3aa12932e 100644 --- a/src/core/pubnub-common.js +++ b/src/core/pubnub-common.js @@ -95,6 +95,12 @@ import { PresenceEventEngine } from '../event-engine/presence/presence'; import { RetryPolicy } from '../event-engine/core/retryPolicy'; import EventEmitter from './components/eventEmitter'; +import { Channel } from '../entities/Channel'; +import { ChannelGroup } from '../entities/ChannelGroup'; +import { ChannelMetadata } from '../entities/ChannelMetadata'; +import { UserMetadata } from '../entities/UserMetadata'; +import { SubscriptionSet } from '../entities/SubscriptionSet'; + export default class { _config; @@ -341,12 +347,12 @@ export default class { this.handshake = endpointCreator.bind(this, modules, handshakeEndpointConfig); this.receiveMessages = endpointCreator.bind(this, modules, receiveMessagesConfig); + this._eventEmitter = new EventEmitter({ + modules: modules, + listenerManager: this._listenerManager, + getFileUrl: (params) => getFileUrlFunction(modules, params), + }); if (config.enableEventEngine === true) { - this._eventEmitter = new EventEmitter({ - modules: modules, - listenerManager: this._listenerManager, - getFileUrl: (params) => getFileUrlFunction(modules, params), - }); if (config.maintainPresenceState) { this.presenceState = {}; this.setState = (args) => { @@ -418,6 +424,7 @@ export default class { listenerManager, getFileUrl: (params) => getFileUrlFunction(modules, params), cryptoModule: modules.cryptoModule, + eventEmitter: this._eventEmitter, }); this.subscribe = subscriptionManager.adaptSubscribeChange.bind(subscriptionManager); @@ -437,9 +444,9 @@ export default class { }; } - this.addListener = listenerManager.addListener.bind(listenerManager); - this.removeListener = listenerManager.removeListener.bind(listenerManager); - this.removeAllListeners = listenerManager.removeAllListeners.bind(listenerManager); + this.addListener = this._eventEmitter.addListener.bind(this._eventEmitter); + this.removeListener = this._eventEmitter.removeListener.bind(this._eventEmitter); + this.removeAllListeners = this._eventEmitter.removeAllListeners.bind(this._eventEmitter); this.parseToken = tokenManager.parseToken.bind(tokenManager); this.setToken = tokenManager.setToken.bind(tokenManager); @@ -511,6 +518,21 @@ export default class { this.deleteFile = endpointCreator.bind(this, modules, deleteFileEndpointConfig); + // entities + + this.channel = (name) => new Channel(name, this._eventEmitter, this); + this.channelGroup = (name) => new ChannelGroup(name, this._eventEmitter, this); + this.channelMetadata = (id) => new ChannelMetadata(id, this._eventEmitter, this); + this.userMetadata = (id) => new UserMetadata(id, this._eventEmitter, this); + this.subscriptionSet = (args) => + new SubscriptionSet({ + channels: args.channels, + channelGroups: args.channelGroups, + subscriptionOptions: args.subscriptionOptions, + eventEmitter: this._eventEmitter, + pubnub: this, + }); + // Objects API v2 this.objects = { diff --git a/src/core/utils.js b/src/core/utils.js index 5f88aeccc..668845dd6 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -41,10 +41,31 @@ function stringToArrayBuffer(str) { return buf; } +function removeSingleOccurance(source, elementsToRemove) { + let removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); + + return source.filter((e) => { + if (elementsToRemove.includes(e) && !removed[e]) { + removed[e] = true; + return false; + } + return true; + }); +} + +function findUniqueCommonElements(a, b) { + return [...a].filter( + (value) => + b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value), + ); +} + module.exports = { signPamFromParams, endsWith, createPromise, encodeString, stringToArrayBuffer, + removeSingleOccurance, + findUniqueCommonElements, }; diff --git a/src/entities/Channel.ts b/src/entities/Channel.ts new file mode 100644 index 000000000..e3ad72904 --- /dev/null +++ b/src/entities/Channel.ts @@ -0,0 +1,24 @@ +import { Subscription } from './Subscription'; +import { SubscriptionOptions, EventEmitter } from './commonTypes'; +import type PubNub from '../core/pubnub-common'; + +export class Channel { + private name: string; + private eventEmitter: EventEmitter; + private pubnub: PubNub; + + constructor(channelName: string, eventEmitter: EventEmitter, pubnub: PubNub) { + this.name = channelName; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + subscription(subscriptionOptions?: SubscriptionOptions) { + return new Subscription({ + channels: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } +} diff --git a/src/entities/ChannelGroup.ts b/src/entities/ChannelGroup.ts new file mode 100644 index 000000000..f668e79c9 --- /dev/null +++ b/src/entities/ChannelGroup.ts @@ -0,0 +1,24 @@ +import { Subscription } from './Subscription'; +import { SubscriptionOptions, EventEmitter } from './commonTypes'; +import type PubNub from '../core/pubnub-common'; + +export class ChannelGroup { + private name: string; + private eventEmitter: EventEmitter; + private pubnub: PubNub; + + constructor(channelGroup: string, eventEmitter: EventEmitter, pubnub: PubNub) { + this.name = channelGroup; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + subscription(subscriptionOptions?: SubscriptionOptions) { + return new Subscription({ + channels: [], + channelGroups: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } +} diff --git a/src/entities/ChannelMetadata.ts b/src/entities/ChannelMetadata.ts new file mode 100644 index 000000000..78020d988 --- /dev/null +++ b/src/entities/ChannelMetadata.ts @@ -0,0 +1,24 @@ +import { Subscription } from './Subscription'; +import { SubscriptionOptions, EventEmitter } from './commonTypes'; +import type PubNub from '../core/pubnub-common'; + +export class ChannelMetadata { + private id: string; + private eventEmitter: EventEmitter; + private pubnub: PubNub; + + constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub) { + this.id = id; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + subscription(subscriptionOptions?: SubscriptionOptions) { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } +} diff --git a/src/entities/SubscribeCapable.ts b/src/entities/SubscribeCapable.ts new file mode 100644 index 000000000..93d2e7ebf --- /dev/null +++ b/src/entities/SubscribeCapable.ts @@ -0,0 +1,68 @@ +import { EventEmitter, Listener, SubscriptionOptions } from './commonTypes'; +import PubNubType from 'pubnub'; +import type PubNub from '../core/pubnub-common'; + +export abstract class SubscribeCapable { + protected abstract channelNames: string[]; + protected abstract groupNames: string[]; + protected abstract listener: Listener; + protected abstract eventEmitter: EventEmitter; + protected abstract pubnub: PubNub; + protected abstract options?: SubscriptionOptions; + + subscribe() { + this.pubnub.subscribe({ + channels: this.channelNames, + channelGroups: this.groupNames, + ...(this.options?.cursor?.timetoken && { timetoken: this.options.cursor.timetoken }), + }); + } + unsubscribe() { + this.pubnub.unsubscribe({ + channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')), + channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), + }); + } + + set onMessage(onMessagelistener: (messageEvent: PubNubType.MessageEvent) => void) { + this.listener.message = onMessagelistener; + } + + set onPresence(onPresencelistener: (presenceEvent: PubNubType.PresenceEvent) => void) { + this.listener.presence = onPresencelistener; + } + + set onSignal(onSignalListener: (signalEvent: PubNubType.SignalEvent) => void) { + this.listener.signal = onSignalListener; + } + + set onObjects(onObjectsListener: (objectsEvent: PubNubType.ObjectsEvent) => void) { + this.listener.objects = onObjectsListener; + } + + set onMessageAction(messageActionEventListener: (messageActionEvent: PubNubType.MessageActionEvent) => void) { + this.listener.messageAction = messageActionEventListener; + } + + set onFile(fileEventListener: (fileEvent: PubNubType.FileEvent) => void) { + this.listener.file = fileEventListener; + } + + addListener(listener: Listener) { + this.eventEmitter.addListener( + listener, + this.channelNames.filter((c) => !c.endsWith('-pnpres')), + this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), + ); + } + removeListener(listener: Listener) { + this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); + } + + get channels(): string[] { + return this.channelNames.slice(0); + } + get channelGroups(): string[] { + return this.groupNames.slice(0); + } +} diff --git a/src/entities/Subscription.ts b/src/entities/Subscription.ts new file mode 100644 index 000000000..6e2a17aa3 --- /dev/null +++ b/src/entities/Subscription.ts @@ -0,0 +1,49 @@ +import { SubscriptionSet } from './SubscriptionSet'; +import { SubscriptionOptions, EventEmitter, Listener } from './commonTypes'; +import type PubNub from '../core/pubnub-common'; +import { SubscribeCapable } from './SubscribeCapable'; + +export class Subscription extends SubscribeCapable { + protected channelNames: string[] = []; + protected groupNames: string[] = []; + protected options?: SubscriptionOptions; + protected pubnub: PubNub; + protected eventEmitter: EventEmitter; + protected listener: Listener; + + constructor({ + channels, + channelGroups, + subscriptionOptions, + eventEmitter, + pubnub, + }: { + channels: string[]; + channelGroups: string[]; + subscriptionOptions?: SubscriptionOptions; + eventEmitter: EventEmitter; + pubnub: PubNub; + }) { + super(); + this.channelNames = channels; + this.groupNames = channelGroups; + this.options = subscriptionOptions; + this.pubnub = pubnub; + this.eventEmitter = eventEmitter; + this.listener = {}; + eventEmitter.addListener( + this.listener, + this.channelNames.filter((c) => !c.endsWith('-pnpres')), + this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), + ); + } + addSubscription(subscription: Subscription) { + return new SubscriptionSet({ + channels: [...this.channelNames, ...subscription.channels], + channelGroups: [...this.groupNames, ...subscription.channelGroups], + subscriptionOptions: { ...this.options, ...subscription?.options }, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } +} diff --git a/src/entities/SubscriptionSet.ts b/src/entities/SubscriptionSet.ts new file mode 100644 index 000000000..83eedff14 --- /dev/null +++ b/src/entities/SubscriptionSet.ts @@ -0,0 +1,81 @@ +import { Subscription } from './Subscription'; +import { SubscriptionOptions, EventEmitter, Listener } from './commonTypes'; +import type PubNub from '../core/pubnub-common'; +import { SubscribeCapable } from './SubscribeCapable'; + +export class SubscriptionSet extends SubscribeCapable { + protected channelNames: string[] = []; + protected groupNames: string[] = []; + protected options: SubscriptionOptions; + protected pubnub: PubNub; + protected eventEmitter: EventEmitter; + protected subscriptionList: Subscription[] = []; + protected listener: Listener; + + constructor({ + channels = [], + channelGroups = [], + subscriptionOptions, + eventEmitter, + pubnub, + }: { + channels: string[]; + channelGroups: string[]; + subscriptionOptions: SubscriptionOptions; + eventEmitter: EventEmitter; + pubnub: PubNub; + }) { + super(); + this.options = subscriptionOptions; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + channels.forEach((c) => { + const subscription = this.pubnub.channel(c).subscription(this.options); + this.channelNames = [...this.channelNames, ...subscription.channels]; + this.subscriptionList.push(subscription); + }); + channelGroups.forEach((cg) => { + const subscription = this.pubnub.channelGroup(cg).subscription(this.options); + this.groupNames = [...this.groupNames, ...subscription.channelGroups]; + this.subscriptionList.push(subscription); + }); + this.listener = {}; + eventEmitter.addListener( + this.listener, + this.channelNames.filter((c) => !c.endsWith('-pnpres')), + this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), + ); + } + + addSubscription(subscription: Subscription) { + this.subscriptionList.push(subscription); + this.channelNames = [...this.channelNames, ...subscription.channels]; + this.groupNames = [...this.groupNames, ...subscription.channelGroups]; + } + + removeSubscription(subscription: Subscription) { + const channelsToRemove = subscription.channels; + const groupsToRemove = subscription.channelGroups; + this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); + this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); + this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); + } + + addSubscriptionSet(subscriptionSet: SubscriptionSet) { + this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; + this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; + this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; + } + + removeSubscriptionSet(subscriptionSet: SubscriptionSet) { + const channelsToRemove = subscriptionSet.channels; + const groupsToRemove = subscriptionSet.channelGroups; + this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); + this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); + this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); + } + + get subscriptions(): Subscription[] { + return this.subscriptionList.slice(0); + } +} diff --git a/src/entities/UserMetadata.ts b/src/entities/UserMetadata.ts new file mode 100644 index 000000000..3364374f0 --- /dev/null +++ b/src/entities/UserMetadata.ts @@ -0,0 +1,24 @@ +import { Subscription } from './Subscription'; +import { SubscriptionOptions, EventEmitter } from './commonTypes'; +import type PubNub from '../core/pubnub-common'; + +export class UserMetadata { + private id: string; + private eventEmitter: EventEmitter; + private pubnub: PubNub; + + constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub) { + this.id = id; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + subscription(subscriptionOptions?: SubscriptionOptions) { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } +} diff --git a/src/entities/commonTypes.ts b/src/entities/commonTypes.ts new file mode 100644 index 000000000..496d5047d --- /dev/null +++ b/src/entities/commonTypes.ts @@ -0,0 +1,31 @@ +import PubNub from 'pubnub'; + +export type SubscriptionOptions = { + cursor?: { timetoken?: string; region?: number }; + receivePresenceEvents?: boolean; +}; + +export type EventEmitter = { + emitEvent(e: Event): void; + addListener(l: Listener, channels?: string[], groups?: string[]): void; + removeListener(listener: Listener, channels?: string[], groups?: string[]): void; + removeAllListeners(): void; +}; + +export type Listener = { + message?(m: PubNub.MessageEvent): void; + presence?(p: PubNub.PresenceEvent): void; + signal?(s: PubNub.SignalEvent): void; + objects?(o: PubNub.ObjectsEvent): void; + messageAction?(ma: PubNub.MessageActionEvent): void; + file?(f: PubNub.FileEvent): void; + status?(s: PubNub.StatusEvent): void; +}; + +type Event = + | PubNub.MessageEvent + | PubNub.PresenceEvent + | PubNub.SignalEvent + | PubNub.ObjectsEvent + | PubNub.MessageActionEvent + | PubNub.FileEvent; diff --git a/src/event-engine/index.ts b/src/event-engine/index.ts index 18b9cb9d4..c4fb5a0a1 100644 --- a/src/event-engine/index.ts +++ b/src/event-engine/index.ts @@ -2,13 +2,14 @@ import { Dispatcher, Engine } from './core'; import { Dependencies, EventEngineDispatcher } from './dispatcher'; import * as effects from './effects'; import * as events from './events'; - import { UnsubscribedState } from './states/unsubscribed'; +import * as utils from '../core/utils'; + export class EventEngine { private engine: Engine = new Engine(); private dispatcher: Dispatcher; - private dependencies: any; + private dependencies: Dependencies; get _engine() { return this.engine; @@ -42,7 +43,7 @@ export class EventEngine { channelGroups?: string[]; timetoken?: string; withPresence?: boolean; - }) { + }): void { this.channels = [...this.channels, ...(channels ?? [])]; this.groups = [...this.groups, ...(channelGroups ?? [])]; if (withPresence) { @@ -50,41 +51,67 @@ export class EventEngine { this.groups.map((g) => this.groups.push(`${g}-pnpres`)); } if (timetoken) { - this.engine.transition(events.restore(this.channels, this.groups, timetoken)); + this.engine.transition( + events.restore( + Array.from(new Set([...this.channels, ...(channels ?? [])])), + Array.from(new Set([...this.groups, ...(channelGroups ?? [])])), + timetoken, + ), + ); } else { - this.engine.transition(events.subscriptionChange(this.channels, this.groups)); + this.engine.transition( + events.subscriptionChange( + Array.from(new Set([...this.channels, ...(channels ?? [])])), + Array.from(new Set([...this.groups, ...(channelGroups ?? [])])), + ), + ); } if (this.dependencies.join) { this.dependencies.join({ - channels: this.channels.filter((c) => !c.endsWith('-pnpres')), - groups: this.groups.filter((g) => !g.endsWith('-pnpres')), + channels: Array.from(new Set(this.channels.filter((c) => !c.endsWith('-pnpres')))), + groups: Array.from(new Set(this.groups.filter((g) => !g.endsWith('-pnpres')))), }); } } - unsubscribe({ channels, groups }: { channels?: string[]; groups?: string[] }) { - const channlesWithPres: any = channels?.slice(0); - channels?.map((c) => channlesWithPres.push(`${c}-pnpres`)); - this.channels = this.channels.filter((channel) => !channlesWithPres?.includes(channel)); - - const groupsWithPres: any = groups?.slice(0); - groups?.map((g) => groupsWithPres.push(`${g}-pnpres`)); - this.groups = this.groups.filter((group) => !groupsWithPres?.includes(group)); - - if (this.dependencies.presenceState) { - channels?.forEach((c) => delete this.dependencies.presenceState[c]); - groups?.forEach((g) => delete this.dependencies.presenceState[g]); - } - this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0))); - if (this.dependencies.leave) { - this.dependencies.leave({ - channels: channels, - groups: groups, - }); + unsubscribe({ channels = [], channelGroups = [] }: { channels?: string[]; channelGroups?: string[] }): void { + const filteredChannels = utils.removeSingleOccurance(this.channels, [ + ...channels, + ...channels.map((c) => `${c}-pnpres`), + ]); + const filteredGroups = utils.removeSingleOccurance(this.groups, [ + ...channelGroups, + ...channelGroups.map((c) => `${c}-pnpres`), + ]); + + if ( + new Set(this.channels).size !== new Set(filteredChannels).size || + new Set(this.groups).size !== new Set(filteredGroups).size + ) { + const channelsToLeave = utils.findUniqueCommonElements(this.channels, channels); + const groupstoLeave = utils.findUniqueCommonElements(this.groups, channelGroups); + if (this.dependencies.presenceState) { + channelsToLeave?.forEach((c) => delete this.dependencies.presenceState[c]); + groupstoLeave?.forEach((g) => delete this.dependencies.presenceState[g]); + } + this.channels = filteredChannels; + this.groups = filteredGroups; + this.engine.transition( + events.subscriptionChange( + Array.from(new Set(this.channels.slice(0))), + Array.from(new Set(this.groups.slice(0))), + ), + ); + if (this.dependencies.leave) { + this.dependencies.leave({ + channels: channelsToLeave.slice(0), + groups: groupstoLeave.slice(0), + }); + } } } - unsubscribeAll() { + unsubscribeAll(): void { this.channels = []; this.groups = []; @@ -97,26 +124,26 @@ export class EventEngine { } } - reconnect({ timetoken, region }: { timetoken?: string; region?: number }) { + reconnect({ timetoken, region }: { timetoken?: string; region?: number }): void { this.engine.transition(events.reconnect(timetoken, region)); } - disconnect() { + disconnect(): void { this.engine.transition(events.disconnect()); if (this.dependencies.leaveAll) { this.dependencies.leaveAll(); } } - getSubscribedChannels() { + getSubscribedChannels(): string[] { return this.channels.slice(0); } - getSubscribedChannelGroups() { + getSubscribedChannelGroups(): string[] { return this.groups.slice(0); } - dispose() { + dispose(): void { this.disconnect(); this._unsubscribeEngine(); this.dispatcher.dispose(); diff --git a/test/integration/components/listeners.test.js b/test/integration/components/listeners.test.js new file mode 100644 index 000000000..77e676f64 --- /dev/null +++ b/test/integration/components/listeners.test.js @@ -0,0 +1,544 @@ +import nock from 'nock'; +import _ from 'underscore'; + +import utils from '../../utils'; +import PubNub from '../../../src/node/index'; + +let pubnub; + +describe('#listeners', () => { + before(() => { + nock.disableNetConnect(); + }); + + after(() => { + nock.enableNetConnect(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + uuid: 'myUUID', + enableEventEngine: true, + autoNetworkDetection: false, + }); + }); + + afterEach(() => { + pubnub.stop(); + pubnub.destroy(); + }); + + it('should pass messages of subscribed channel to its listener', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + var channel = pubnub.channel('ch1'); + var subscription = channel.subscription(); + var messagePromise = new Promise((resolveMessage) => + subscription.addListener({ + message: (m) => resolveMessage(m), + }), + ); + subscription.subscribe(); + const actual = await messagePromise; + expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); + }); + it('should subscribed to channel and presence channels', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + + const channel = pubnub.channel('ch1'); + const subscription = channel.subscription({ receivePresenceEvents: true }); + const messagePromise = new Promise((resolveMessage) => + subscription.addListener({ + message: (m) => resolveMessage(m), + }), + ); + subscription.subscribe(); + const actual = await messagePromise; + expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); + }); + + it('should work with subscriptionSet', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + + const channel = pubnub.channel('ch1'); + const subscription = channel.subscription(); + const subscriptionSet = subscription.addSubscription(pubnub.channel('ch2').subscription()); + const messagePromise = new Promise((resolveMessage) => + subscriptionSet.addListener({ + message: (m) => resolveMessage(m), + }), + ); + subscriptionSet.subscribe(); + const actual = await messagePromise; + expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); + }); + + it('should able to create subscriptionSet', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + + const subscriptionSet = pubnub.subscriptionSet({ channels: ['ch1', 'ch2'] }); + + const messagePromise = new Promise((resolveMessage) => + subscriptionSet.addListener({ + message: (m) => resolveMessage(m), + }), + ); + subscriptionSet.subscribe(); + const actual = await messagePromise; + expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); + }); + + it('subscriptionSet works with add/remove with set', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch3%2Cch4/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch3%2Cch4/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch3","d":{"message":"My message!"}}]}', + ); + + const subscriptionSetCh34 = pubnub.subscriptionSet({ channels: ['ch3', 'ch4'] }); + + const subscriptionSetCh12 = pubnub + .channel('ch1') + .subscription() + .addSubscription(pubnub.channel('ch2').subscription()); + + subscriptionSetCh34.addSubscriptionSet(subscriptionSetCh12); + subscriptionSetCh34.removeSubscriptionSet(subscriptionSetCh12); + + const messagePromise = new Promise((resolveMessage) => + subscriptionSetCh34.addListener({ + message: (m) => resolveMessage(m), + }), + ); + subscriptionSetCh34.subscribe(); + const actual = await messagePromise; + expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); + }); + it('listener should route presence event to registered handler', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"17070458535164862","r":31},"m":[{"a":"0","f":0,"p":{"t":"17070458535164862","r":31},"k":"mySubKey","c":"ch1-pnpres","u":{"pn_action":"join","pn_uuid":"dartClient","pn_timestamp":1707045853,"pn_precise_timestamp":1707045853513,"pn_occupancy":2,"pn_ispresence":1,"pn_channel":"ch1"},"d":{"action":"join","uuid":"p2","timestamp":1707045853,"precise_timestamp":1707045853513,"occupancy":2},"b":"ch1-pnpres"}]}', + ); + + const channel = pubnub.channel('ch1'); + const subscription = channel.subscription({ receivePresenceEvents: true }); + const presencePromise = new Promise((resolvePresence) => + subscription.addListener({ + presence: (p) => resolvePresence(p), + }), + ); + subscription.subscribe(); + const actual = await presencePromise; + expect(actual.action).to.equal('join'); + expect(actual.occupancy).to.equal(2); + }); + + it('add/remove listener should work on subscription', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + const messages = []; + const channel = pubnub.channel('ch1'); + const subscription = channel.subscription(); + const listener = { message: (m) => messages.push(m) }; + subscription.addListener(listener); + const messagePromise = new Promise((resolveMessage) => + subscription.addListener({ + message: (m) => resolveMessage(m), + }), + ); + subscription.removeListener(listener); + subscription.subscribe(); + const actual = await messagePromise; + expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); + expect(messages.length).to.equal(0); + }); + + it('should work with channel groups and their presence', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/%2C/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + 'channel-group': 'cg1,cg1-pnpres', + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/%2C/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + 'channel-group': 'cg1,cg1-pnpres', + }) + .reply( + 200, + '{"t":{"t":"17070655215847224","r":33},"m":[{"a":"0","f":0,"i":"cl1","p":{"t":"17070655215847224","r":31},"k":"mySubKey","c":"ch1","d":{"message":"My message!"},"b":"cg1"}]}', + ); + var channelGroup = pubnub.channelGroup('cg1'); + var subscription = channelGroup.subscription({ receivePresenceEvents: true }); + var messagePromise = new Promise((resolveMessage) => + subscription.addListener({ + message: (m) => resolveMessage(m), + }), + ); + subscription.subscribe(); + const actual = await messagePromise; + expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); + }); + + it('subscribe/unsubscribe handle edge case of having overlaping channel/group set', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '10', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '10', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch3/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '10', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch2%2Cch3/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '10', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"12","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch2","d":{"ch2":"My message!"}}]}', + ); + const messages = []; + const channel = pubnub.channel('ch1'); + const subscription = channel.subscription(); + const listener = { message: (m) => messages.push(m) }; + subscription.addListener(listener); + const messagePromise = new Promise((resolveMessage) => + subscription.addListener({ + message: (m) => resolveMessage(m), + }), + ); + subscription.removeListener(listener); + subscription.subscribe(); + const actual = await messagePromise; + expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); + expect(messages.length).to.equal(0); + const subscriptionCh2 = pubnub.channel('ch2').subscription(); + subscriptionCh2.subscribe(); + const subscriptionCh3 = pubnub.channel('ch3').subscription(); + const subscriptionSetCh23 = subscriptionCh3.addSubscription(pubnub.channel('ch2').subscription()); + const messagePromiseChannel2 = new Promise((resolveMessage) => + subscriptionSetCh23.addListener({ + message: (m) => resolveMessage(m), + }), + ); + subscriptionSetCh23.subscribe(); + subscription.unsubscribe(); + subscriptionCh2.unsubscribe(); + const actualChannel2MessageAfterOneUnsubCh2 = await messagePromiseChannel2; + pubnub.destroy(); + expect(JSON.stringify(actualChannel2MessageAfterOneUnsubCh2.message)).to.equal('{"ch2":"My message!"}'); + }); + + it('should work with event type specific listener registraction', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + ); + var channel = pubnub.channel('ch1'); + var subscription = channel.subscription(); + var messagePromise = new Promise((resolveMessage) => (subscription.onMessage = (m) => resolveMessage(m))); + subscription.subscribe(); + const actual = await messagePromise; + expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); + }); + + it('with presence should work with event type specific listener registraction', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"p":{"t":"8","r":2},"k":"subKey","c":"ch1-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "testid", "occupancy": 1},"b":"ch1-pnpres"}]}', + ); + + const channel = pubnub.channel('ch1'); + const subscription = channel.subscription({ receivePresenceEvents: true }); + const presencePromise = new Promise( + (resolvePresenceEvent) => (subscription.onPresence = (p) => resolvePresenceEvent(p)), + ); + subscription.subscribe(); + const actual = await presencePromise; + expect(JSON.stringify(actual)).to.equal( + '{"channel":"ch1","subscription":null,"action":"join","occupancy":1,"uuid":"testid","timestamp":1461451222,"actualChannel":null,"subscribedChannel":"ch1-pnpres"}', + ); + }); +}); diff --git a/test/integration/components/subscription_manager.test.js b/test/integration/components/subscription_manager.test.js index 56990f990..dfc871aaf 100644 --- a/test/integration/components/subscription_manager.test.js +++ b/test/integration/components/subscription_manager.test.js @@ -722,7 +722,6 @@ describe('#components/subscription_manager', () => { pubnubWithCrypto.addListener({ message(messagePayload) { incomingPayloads.push(messagePayload); - console.log('\n\n\n incomingpayload = ', JSON.stringify(incomingPayloads)); if (incomingPayloads.length === 1) { assert.equal(scope.isDone(), true); assert.deepEqual(incomingPayloads, [ From a551a84d8491d966abfa7812e906485deb9345b8 Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Mon, 26 Feb 2024 13:21:23 +0530 Subject: [PATCH 02/49] fix: App context event handling for channel and membership (#362) * fix: test with overlapping channels subscription using new listener interface * dist/lib * event emitter: fix and test for objects event type handling * dist/lib update * Apply suggestions from code review Co-authored-by: Serhii Mamontov * renamed property name publishTimetoken to timetoken in publishMetadata * lib/dist * PubNub SDK v7.6.1 release. --------- Co-authored-by: Serhii Mamontov Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> --- .pubnub.yml | 11 +- CHANGELOG.md | 6 + README.md | 4 +- dist/web/pubnub.js | 25 ++-- dist/web/pubnub.min.js | 2 +- lib/core/components/config.js | 2 +- lib/core/components/eventEmitter.js | 16 +- lib/core/endpoints/subscribe.js | 2 +- .../subscriptionUtils/receiveMessages.js | 1 + lib/event-engine/index.js | 4 +- package-lock.json | 16 +- package.json | 2 +- src/core/components/config.js | 2 +- src/core/components/eventEmitter.js | 16 +- src/core/endpoints/subscribe.js | 2 +- .../subscriptionUtils/receiveMessages.js | 1 + src/event-engine/index.ts | 4 +- test/integration/components/listeners.test.js | 138 +++++++++++++++++- 18 files changed, 195 insertions(+), 59 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 96fb55bb4..fc5a3fb57 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-02-26 + version: v7.6.1 + changes: + - type: bug + text: "Fixes issue of App context event handling for channel and membership." - date: 2024-02-21 version: v7.6.0 changes: @@ -943,7 +948,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '7.6.0' +version: '7.6.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -959,7 +964,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1630,7 +1635,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v7.6.0/pubnub.7.6.0.js + location: https://github.com/pubnub/javascript/releases/download/v7.6.1/pubnub.7.6.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index bf8d08de1..fd8c4684c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v7.6.1 +February 26 2024 + +#### Fixed +- Fixes issue of App context event handling for channel and membership. + ## v7.6.0 February 21 2024 diff --git a/README.md b/README.md index 23b76595e..69a73ad04 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 112124b0c..e1982409d 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -794,7 +794,7 @@ return this; }; default_1.prototype.getVersion = function () { - return '7.6.0'; + return '7.6.1'; }; default_1.prototype._setRetryConfiguration = function (configuration) { if (configuration.minimumdelay < 2) { @@ -6533,7 +6533,7 @@ var messages = []; serverResponse.m.forEach(function (rawMessage) { var publishMetaData = { - publishTimetoken: rawMessage.p.t, + timetoken: rawMessage.p.t, region: rawMessage.p.r, }; var parsedMessage = { @@ -6659,6 +6659,7 @@ issuingClientId: envelope.i, subscribeKey: envelope.k, originationTimetoken: envelope.o, + userMetadata: envelope.u, publishMetaData: { timetoken: envelope.p.t, region: envelope.p.r, @@ -7640,10 +7641,10 @@ } }; EventEngine.prototype.getSubscribedChannels = function () { - return this.channels.slice(0); + return Array.from(new Set(this.channels)); }; EventEngine.prototype.getSubscribedChannelGroups = function () { - return this.groups.slice(0); + return Array.from(new Set(this.groups)); }; EventEngine.prototype.dispose = function () { this.disconnect(); @@ -8107,7 +8108,7 @@ } announce.action = e.payload.action; announce.state = e.payload.data; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.occupancy = e.payload.occupancy; announce.uuid = e.payload.uuid; announce.timestamp = e.payload.timestamp; @@ -8133,7 +8134,7 @@ announce.subscription = null; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; if (e.userMetadata) { announce.userMetadata = e.userMetadata; @@ -8148,7 +8149,7 @@ announce.subscription = null; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; if (e.userMetadata) { announce.userMetadata = e.userMetadata; @@ -8166,13 +8167,13 @@ this.listenerManager.announceUser(userEvent); this._announce('user', userEvent, announce.channel, announce.subscription); } - else if (message.payload.type === 'channel') { + else if (e.payload.type === 'channel') { var eventData = this._renameChannelField(announce); var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) }); this.listenerManager.announceSpace(spaceEvent); this._announce('space', spaceEvent, announce.channel, announce.subscription); } - else if (message.payload.type === 'membership') { + else if (e.payload.type === 'membership') { var eventData = this._renameChannelField(announce); var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]); membershipData.user = user; @@ -8186,7 +8187,7 @@ var announce = {}; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; announce.data = { messageTimetoken: e.payload.data.messageTimetoken, @@ -8203,7 +8204,7 @@ var announce = {}; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; var msgPayload = e.payload; if (this.modules.cryptoModule) { @@ -8243,7 +8244,7 @@ announce.subscription = null; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; if (e.userMetadata) { announce.userMetadata = e.userMetadata; diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 97c551cf2..dad8e7f1e 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -14,4 +14,4 @@ PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function u(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o>2,c=0;c>6),o.push(128|63&s)):s<55296?(o.push(224|s>>12),o.push(128|s>>6&63),o.push(128|63&s)):(s=(1023&s)<<10,s|=1023&t.charCodeAt(++r),s+=65536,o.push(240|s>>18),o.push(128|s>>12&63),o.push(128|s>>6&63),o.push(128|63&s))}return h(3,o.length),p(o);default:var f;if(Array.isArray(t))for(h(4,f=t.length),r=0;r>5!==e)throw"Invalid indefinite length element";return n}function g(e,t){for(var n=0;n>10),e.push(56320|1023&r))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var o,h,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=p(),o=32768&n,i=31744&n,s=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==s)return s*r;return t.setUint32(0,o<<16|i<<13|s<<13),t.getFloat32(0)}();case 26:return u(s.getFloat32(a),4);case 27:return u(s.getFloat64(a),8)}if((h=d(v))<0&&(b<2||6=0;)S+=h,_.push(c(h));var w=new Uint8Array(S),O=0;for(o=0;o<_.length;++o)w.set(_[o],O),O+=_[o].length;return w}return c(h);case 3:var P=[];if(h<0)for(;(h=y(b))>=0;)g(P,h);else g(P,h);return String.fromCharCode.apply(null,P);case 4:var E;if(h<0)for(E=[];!f();)E.push(e());else for(E=new Array(h),o=0;o=20?this._presenceTimeout=e:(this._presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",this._presenceTimeout)),this.setHeartbeatInterval(this._presenceTimeout/2-1),this},e.prototype.setProxy=function(e){this.proxy=e},e.prototype.getHeartbeatInterval=function(){return this._heartbeatInterval},e.prototype.setHeartbeatInterval=function(e){return this._heartbeatInterval=e,this},e.prototype.getSubscribeTimeout=function(){return this._subscribeRequestTimeout},e.prototype.setSubscribeTimeout=function(e){return this._subscribeRequestTimeout=e,this},e.prototype.getTransactionTimeout=function(){return this._transactionalRequestTimeout},e.prototype.setTransactionTimeout=function(e){return this._transactionalRequestTimeout=e,this},e.prototype.isSendBeaconEnabled=function(){return this._useSendBeacon},e.prototype.setSendBeaconConfig=function(e){return this._useSendBeacon=e,this},e.prototype.getVersion=function(){return"7.6.0"},e.prototype._setRetryConfiguration=function(e){if(e.minimumdelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(e.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(e.maximumDelay&&maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6");if(e.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10");this.retryConfiguration=e},e.prototype._addPnsdkSuffix=function(e,t){this._PNSDKSuffix[e]=t},e.prototype._getPnsdkSuffix=function(e){var t=this;return Object.keys(this._PNSDKSuffix).reduce((function(n,r){return n+e+t._PNSDKSuffix[r]}),"")},e}();function m(e){var t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;function s(){var e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error("Illegal character at ".concat(i,": ").concat(t.charAt(i-1)));return n}for(var a=0;a>4,f=(15&c)<<4|l>>2,d=(3&l)<<6|p>>0;o[a]=h,64!=l&&(o[a+1]=f),64!=p&&(o[a+2]=d)}return r}function b(e){for(var t,n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=new Uint8Array(e),i=o.byteLength,s=i%3,a=i-s,u=0;u>18]+r[(258048&t)>>12]+r[(4032&t)>>6]+r[63&t];return 1==s?n+=r[(252&(t=o[a]))>>2]+r[(3&t)<<4]+"==":2==s&&(n+=r[(64512&(t=o[a]<<8|o[a+1]))>>10]+r[(1008&t)>>4]+r[(15&t)<<2]+"="),n}var v,_,S,w,O,P=P||function(e,t){var n={},r=n.lib={},o=function(){},i=r.Base={extend:function(e){o.prototype=this;var t=new o;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var o=0;o>>2]|=(n[o>>>2]>>>24-o%4*8&255)<<24-(r+o)%4*8;else if(65535>>2]=n[o>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r>>2]>>>24-r%4*8&255;n.push((o>>>4).toString(16)),n.push((15&o).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,a=o/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,o=e.min(4*t,o),t){for(var u=0;uc;){var l;e:{l=u;for(var p=e.sqrt(l),h=2;h<=p;h++)if(!(l%h)){l=!1;break e}l=!0}l&&(8>c&&(i[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var f=[];o=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],a=n[3],u=n[4],c=n[5],l=n[6],p=n[7],h=0;64>h;h++){if(16>h)f[h]=0|e[t+h];else{var d=f[h-15],y=f[h-2];f[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+f[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+f[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[h]+f[h],y=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=l,l=c,c=u,u=a+d|0,a=i,i=o,o=r,r=d+y|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+p|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(o),t.HmacSHA256=r._createHmacHelper(o)}(Math),_=(v=P).enc.Utf8,v.algo.HMAC=v.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=_.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,a=i.words,u=0;u>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;4>s&&o+.75*s>>6*(3-s)&63));if(t=r.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(r=n.charAt(64))&&-1!=(r=e.indexOf(r))&&(t=r);for(var r=[],o=0,i=0;i>>6-i%4*2;r[o>>>2]|=(s|a)<<24-o%4*8,o++}return w.create(r,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,r,o,i,s){return((e=e+(t&n|~t&r)+o+s)<>>32-i)+t}function n(e,t,n,r,o,i,s){return((e=e+(t&r|n&~r)+o+s)<>>32-i)+t}function r(e,t,n,r,o,i,s){return((e=e+(t^n^r)+o+s)<>>32-i)+t}function o(e,t,n,r,o,i,s){return((e=e+(n^(t|~r))+o+s)<>>32-i)+t}for(var i=P,s=(u=i.lib).WordArray,a=u.Hasher,u=i.algo,c=[],l=0;64>l;l++)c[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=a.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var s=0;16>s;s++){var a=e[u=i+s];e[u]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}s=this._hash.words;var u=e[i+0],l=(a=e[i+1],e[i+2]),p=e[i+3],h=e[i+4],f=e[i+5],d=e[i+6],y=e[i+7],g=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],_=e[i+12],S=e[i+13],w=e[i+14],O=e[i+15],P=t(P=s[0],T=s[1],A=s[2],E=s[3],u,7,c[0]),E=t(E,P,T,A,a,12,c[1]),A=t(A,E,P,T,l,17,c[2]),T=t(T,A,E,P,p,22,c[3]);P=t(P,T,A,E,h,7,c[4]),E=t(E,P,T,A,f,12,c[5]),A=t(A,E,P,T,d,17,c[6]),T=t(T,A,E,P,y,22,c[7]),P=t(P,T,A,E,g,7,c[8]),E=t(E,P,T,A,m,12,c[9]),A=t(A,E,P,T,b,17,c[10]),T=t(T,A,E,P,v,22,c[11]),P=t(P,T,A,E,_,7,c[12]),E=t(E,P,T,A,S,12,c[13]),A=t(A,E,P,T,w,17,c[14]),P=n(P,T=t(T,A,E,P,O,22,c[15]),A,E,a,5,c[16]),E=n(E,P,T,A,d,9,c[17]),A=n(A,E,P,T,v,14,c[18]),T=n(T,A,E,P,u,20,c[19]),P=n(P,T,A,E,f,5,c[20]),E=n(E,P,T,A,b,9,c[21]),A=n(A,E,P,T,O,14,c[22]),T=n(T,A,E,P,h,20,c[23]),P=n(P,T,A,E,m,5,c[24]),E=n(E,P,T,A,w,9,c[25]),A=n(A,E,P,T,p,14,c[26]),T=n(T,A,E,P,g,20,c[27]),P=n(P,T,A,E,S,5,c[28]),E=n(E,P,T,A,l,9,c[29]),A=n(A,E,P,T,y,14,c[30]),P=r(P,T=n(T,A,E,P,_,20,c[31]),A,E,f,4,c[32]),E=r(E,P,T,A,g,11,c[33]),A=r(A,E,P,T,v,16,c[34]),T=r(T,A,E,P,w,23,c[35]),P=r(P,T,A,E,a,4,c[36]),E=r(E,P,T,A,h,11,c[37]),A=r(A,E,P,T,y,16,c[38]),T=r(T,A,E,P,b,23,c[39]),P=r(P,T,A,E,S,4,c[40]),E=r(E,P,T,A,u,11,c[41]),A=r(A,E,P,T,p,16,c[42]),T=r(T,A,E,P,d,23,c[43]),P=r(P,T,A,E,m,4,c[44]),E=r(E,P,T,A,_,11,c[45]),A=r(A,E,P,T,O,16,c[46]),P=o(P,T=r(T,A,E,P,l,23,c[47]),A,E,u,6,c[48]),E=o(E,P,T,A,y,10,c[49]),A=o(A,E,P,T,w,15,c[50]),T=o(T,A,E,P,f,21,c[51]),P=o(P,T,A,E,_,6,c[52]),E=o(E,P,T,A,p,10,c[53]),A=o(A,E,P,T,b,15,c[54]),T=o(T,A,E,P,a,21,c[55]),P=o(P,T,A,E,g,6,c[56]),E=o(E,P,T,A,O,10,c[57]),A=o(A,E,P,T,d,15,c[58]),T=o(T,A,E,P,S,21,c[59]),P=o(P,T,A,E,h,6,c[60]),E=o(E,P,T,A,v,10,c[61]),A=o(A,E,P,T,l,15,c[62]),T=o(T,A,E,P,m,21,c[63]);s[0]=s[0]+P|0,s[1]=s[1]+T|0,s[2]=s[2]+A|0,s[3]=s[3]+E|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var i=e.floor(r/4294967296);for(n[15+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(o+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,r=0;4>r;r++)o=n[r],n[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(u),i.HmacMD5=a._createHmacHelper(u)}(Math),function(){var e,t=P,n=(e=t.lib).Base,r=e.WordArray,o=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),o=r.create(),i=o.words,s=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:u,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var p=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(u=(f.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return p.create({ciphertext:e,salt:n})}},t.SerializableCipher=n.extend({cfg:n.extend({format:u}),encrypt:function(e,t,n,r){r=this.cfg.extend(r);var o=e.createEncryptor(n,r);return t=o.finalize(t),o=o.cfg,p.create({ciphertext:t,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:r.format})},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),e.createDecryptor(n,r).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),f=(f.kdf={}).OpenSSL={execute:function(e,t,n,o){return o||(o=r.random(8)),e=s.create({keySize:t+n}).compute(e,o),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,p.create({key:e,iv:n,salt:o})}},d=t.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:f}),encrypt:function(e,t,n,r){return n=(r=this.cfg.extend(r)).kdf.execute(n,e.keySize,e.ivSize),r.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,r)).mixIn(n),e},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),n=r.kdf.execute(n,e.keySize,e.ivSize,t.salt),r.iv=n.iv,h.decrypt.call(this,e,t,n.key,r)}})}(),function(){for(var e=P,t=e.lib.BlockCipher,n=e.algo,r=[],o=[],i=[],s=[],a=[],u=[],c=[],l=[],p=[],h=[],f=[],d=0;256>d;d++)f[d]=128>d?d<<1:d<<1^283;var y=0,g=0;for(d=0;256>d;d++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;r[y]=m,o[m]=y;var b=f[y],v=f[b],_=f[v],S=257*f[m]^16843008*m;i[y]=S<<24|S>>>8,s[y]=S<<16|S>>>16,a[y]=S<<8|S>>>24,u[y]=S,S=16843009*_^65537*v^257*b^16843008*y,c[m]=S<<24|S>>>8,l[m]=S<<16|S>>>16,p[m]=S<<8|S>>>24,h[m]=S,y?(y=b^f[f[f[_^b]]],g^=f[f[g]]):y=g=1}var w=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),o=this._keySchedule=[],i=0;i>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s]):(s=r[(s=s<<8|s>>>24)>>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s],s^=w[i/t|0]<<24),o[i]=o[i-t]^s}for(e=this._invKeySchedule=[],t=0;tt||4>=i?s:c[r[s>>>24]]^l[r[s>>>16&255]]^p[r[s>>>8&255]]^h[r[255&s]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,s,a,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,c,l,p,h,o),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,r,o,i,s,a){for(var u=this._nRounds,c=e[t]^n[0],l=e[t+1]^n[1],p=e[t+2]^n[2],h=e[t+3]^n[3],f=4,d=1;d>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&h]^n[f++],g=r[l>>>24]^o[p>>>16&255]^i[h>>>8&255]^s[255&c]^n[f++],m=r[p>>>24]^o[h>>>16&255]^i[c>>>8&255]^s[255&l]^n[f++];h=r[h>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^n[f++],c=y,l=g,p=m}y=(a[c>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&h])^n[f++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[h>>>8&255]<<8|a[255&c])^n[f++],m=(a[p>>>24]<<24|a[h>>>16&255]<<16|a[c>>>8&255]<<8|a[255&l])^n[f++],h=(a[h>>>24]<<24|a[c>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^n[f++],e[t]=y,e[t+1]=g,e[t+2]=m,e[t+3]=h},keySize:8});e.AES=t._createHelper(n)}(),P.mode.ECB=((O=P.lib.BlockCipherMode.extend()).Encryptor=O.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),O.Decryptor=O.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),O);var E=P;function A(e){var t,n=[];for(t=0;t=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))},e.prototype.clearHistory=function(){this.hashHistory=[]},e}(),k={PNNetworkUpCategory:"PNNetworkUpCategory",PNNetworkDownCategory:"PNNetworkDownCategory",PNNetworkIssuesCategory:"PNNetworkIssuesCategory",PNTimeoutCategory:"PNTimeoutCategory",PNBadRequestCategory:"PNBadRequestCategory",PNAccessDeniedCategory:"PNAccessDeniedCategory",PNUnknownCategory:"PNUnknownCategory",PNReconnectedCategory:"PNReconnectedCategory",PNConnectedCategory:"PNConnectedCategory",PNRequestMessageCountExceededCategory:"PNRequestMessageCountExceededCategory",PNDisconnectedCategory:"PNDisconnectedCategory",PNConnectionErrorCategory:"PNConnectionErrorCategory",PNDisconnectedUnexpectedlyCategory:"PNDisconnectedUnexpectedlyCategory"},M=function(){function e(e){var t=e.subscribeEndpoint,n=e.leaveEndpoint,r=e.heartbeatEndpoint,o=e.setStateEndpoint,i=e.timeEndpoint,s=e.getFileUrl,a=e.config,u=e.crypto,c=e.listenerManager,l=e.cryptoModule,p=e.eventEmitter;this._listenerManager=c,this._config=a,this._leaveEndpoint=n,this._heartbeatEndpoint=r,this._setStateEndpoint=o,this._subscribeEndpoint=t,this._getFileUrl=s,this._crypto=u,this._cryptoModule=l,this._channels={},this._presenceChannels={},this._heartbeatChannels={},this._heartbeatChannelGroups={},this._channelGroups={},this._presenceChannelGroups={},this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[],this._currentTimetoken=0,this._lastTimetoken=0,this._storedTimetoken=null,this._subscriptionStatusAnnounced=!1,this._isOnline=!0,this._reconnectionManager=new N({timeEndpoint:i}),this._dedupingManager=new C({config:a}),this._cryptoModule&&(this._decoder=new TextDecoder),this._eventEmitter=p}return e.prototype.adaptStateChange=function(e,t){var n=this,r=e.state,o=e.channels,i=void 0===o?[]:o,s=e.channelGroups,a=void 0===s?[]:s,u=e.withHeartbeat,c=void 0!==u&&u;if(i.forEach((function(e){e in n._channels&&(n._channels[e].state=r)})),a.forEach((function(e){e in n._channelGroups&&(n._channelGroups[e].state=r)})),c){var l={};return i.forEach((function(e){return l[e]=r})),a.forEach((function(e){return l[e]=r})),this._heartbeatEndpoint({channels:i,channelGroups:a,state:l},t)}return this._setStateEndpoint({state:r,channels:i,channelGroups:a},t)},e.prototype.adaptPresenceChange=function(e){var t=this,n=e.connected,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i;n?(o.forEach((function(e){t._heartbeatChannels[e]={state:{}}})),s.forEach((function(e){t._heartbeatChannelGroups[e]={state:{}}}))):(o.forEach((function(e){e in t._heartbeatChannels&&delete t._heartbeatChannels[e]})),s.forEach((function(e){e in t._heartbeatChannelGroups&&delete t._heartbeatChannelGroups[e]})),!1===this._config.suppressLeaveEvents&&this._leaveEndpoint({channels:o,channelGroups:s},(function(e){t._listenerManager.announceStatus(e)}))),this.reconnect()},e.prototype.adaptSubscribeChange=function(e){var t=this,n=e.timetoken,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=e.withPresence,u=void 0!==a&&a,c=e.withHeartbeats,l=void 0!==c&&c;this._config.subscribeKey&&""!==this._config.subscribeKey?(n&&(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=n),"0"!==this._currentTimetoken&&0!==this._currentTimetoken&&(this._storedTimetoken=this._currentTimetoken,this._currentTimetoken=0),o.forEach((function(e){t._channels[e]={state:{}},u&&(t._presenceChannels[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannels[e]={}),t._pendingChannelSubscriptions.push(e)})),s.forEach((function(e){t._channelGroups[e]={state:{}},u&&(t._presenceChannelGroups[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannelGroups[e]={}),t._pendingChannelGroupSubscriptions.push(e)})),this._subscriptionStatusAnnounced=!1,this.reconnect()):console&&console.log&&console.log("subscribe key missing; aborting subscribe")},e.prototype.adaptUnsubscribeChange=function(e,t){var n=this,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=[],u=[];o.forEach((function(e){e in n._channels&&(delete n._channels[e],a.push(e),e in n._heartbeatChannels&&delete n._heartbeatChannels[e]),e in n._presenceChannels&&(delete n._presenceChannels[e],a.push(e))})),s.forEach((function(e){e in n._channelGroups&&(delete n._channelGroups[e],u.push(e),e in n._heartbeatChannelGroups&&delete n._heartbeatChannelGroups[e]),e in n._presenceChannelGroups&&(delete n._presenceChannelGroups[e],u.push(e))})),0===a.length&&0===u.length||(!1!==this._config.suppressLeaveEvents||t||this._leaveEndpoint({channels:a,channelGroups:u},(function(e){e.affectedChannels=a,e.affectedChannelGroups=u,e.currentTimetoken=n._currentTimetoken,e.lastTimetoken=n._lastTimetoken,n._listenerManager.announceStatus(e)})),0===Object.keys(this._channels).length&&0===Object.keys(this._presenceChannels).length&&0===Object.keys(this._channelGroups).length&&0===Object.keys(this._presenceChannelGroups).length&&(this._lastTimetoken=0,this._currentTimetoken=0,this._storedTimetoken=null,this._region=null,this._reconnectionManager.stopPolling()),this.reconnect())},e.prototype.unsubscribeAll=function(e){this.adaptUnsubscribeChange({channels:this.getSubscribedChannels(),channelGroups:this.getSubscribedChannelGroups()},e)},e.prototype.getHeartbeatChannels=function(){return Object.keys(this._heartbeatChannels)},e.prototype.getHeartbeatChannelGroups=function(){return Object.keys(this._heartbeatChannelGroups)},e.prototype.getSubscribedChannels=function(){return Object.keys(this._channels)},e.prototype.getSubscribedChannelGroups=function(){return Object.keys(this._channelGroups)},e.prototype.reconnect=function(){this._startSubscribeLoop(),this._registerHeartbeatTimer()},e.prototype.disconnect=function(){this._stopSubscribeLoop(),this._stopHeartbeatTimer(),this._reconnectionManager.stopPolling()},e.prototype._registerHeartbeatTimer=function(){this._stopHeartbeatTimer(),0!==this._config.getHeartbeatInterval()&&void 0!==this._config.getHeartbeatInterval()&&(this._performHeartbeatLoop(),this._heartbeatTimer=setInterval(this._performHeartbeatLoop.bind(this),1e3*this._config.getHeartbeatInterval()))},e.prototype._stopHeartbeatTimer=function(){this._heartbeatTimer&&(clearInterval(this._heartbeatTimer),this._heartbeatTimer=null)},e.prototype._performHeartbeatLoop=function(){var e=this,t=this.getHeartbeatChannels(),n=this.getHeartbeatChannelGroups(),r={};if(0!==t.length||0!==n.length){this.getSubscribedChannels().forEach((function(t){var n=e._channels[t].state;Object.keys(n).length&&(r[t]=n)})),this.getSubscribedChannelGroups().forEach((function(t){var n=e._channelGroups[t].state;Object.keys(n).length&&(r[t]=n)}));this._heartbeatEndpoint({channels:t,channelGroups:n,state:r},function(t){t.error&&e._config.announceFailedHeartbeats&&e._listenerManager.announceStatus(t),t.error&&e._config.autoNetworkDetection&&e._isOnline&&(e._isOnline=!1,e.disconnect(),e._listenerManager.announceNetworkDown(),e.reconnect()),!t.error&&e._config.announceSuccessfulHeartbeats&&e._listenerManager.announceStatus(t)}.bind(this))}},e.prototype._startSubscribeLoop=function(){var e=this;this._stopSubscribeLoop();var t={},n=[],r=[];if(Object.keys(this._channels).forEach((function(r){var o=e._channels[r].state;Object.keys(o).length&&(t[r]=o),n.push(r)})),Object.keys(this._presenceChannels).forEach((function(e){n.push("".concat(e,"-pnpres"))})),Object.keys(this._channelGroups).forEach((function(n){var o=e._channelGroups[n].state;Object.keys(o).length&&(t[n]=o),r.push(n)})),Object.keys(this._presenceChannelGroups).forEach((function(e){r.push("".concat(e,"-pnpres"))})),0!==n.length||0!==r.length){var o={channels:n,channelGroups:r,state:t,timetoken:this._currentTimetoken,filterExpression:this._config.filterExpression,region:this._region};this._subscribeCall=this._subscribeEndpoint(o,this._processSubscribeResponse.bind(this))}},e.prototype._processSubscribeResponse=function(e,t){var n=this;if(e.error){if(e.errorData&&"Aborted"===e.errorData.message)return;e.category===k.PNTimeoutCategory?this._startSubscribeLoop():e.category===k.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this._config.autoNetworkDetection&&this._isOnline&&(this._isOnline=!1,this._listenerManager.announceNetworkDown()),this._reconnectionManager.onReconnection((function(){n._config.autoNetworkDetection&&!n._isOnline&&(n._isOnline=!0,n._listenerManager.announceNetworkUp()),n.reconnect(),n._subscriptionStatusAnnounced=!0;var t={category:k.PNReconnectedCategory,operation:e.operation,lastTimetoken:n._lastTimetoken,currentTimetoken:n._currentTimetoken};n._listenerManager.announceStatus(t)})),this._reconnectionManager.startPolling(),this._listenerManager.announceStatus(e)):e.category===k.PNBadRequestCategory?(this._stopHeartbeatTimer(),this._listenerManager.announceStatus(e)):this._listenerManager.announceStatus(e)}else{if(this._storedTimetoken?(this._currentTimetoken=this._storedTimetoken,this._storedTimetoken=null):(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=t.metadata.timetoken),!this._subscriptionStatusAnnounced){var r={};r.category=k.PNConnectedCategory,r.operation=e.operation,r.affectedChannels=this._pendingChannelSubscriptions,r.subscribedChannels=this.getSubscribedChannels(),r.affectedChannelGroups=this._pendingChannelGroupSubscriptions,r.lastTimetoken=this._lastTimetoken,r.currentTimetoken=this._currentTimetoken,this._subscriptionStatusAnnounced=!0,this._listenerManager.announceStatus(r),this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[]}var o=t.messages||[],i=this._config,s=i.requestMessageCountThreshold,a=i.dedupeOnSubscribe;if(s&&o.length>=s){var u={};u.category=k.PNRequestMessageCountExceededCategory,u.operation=e.operation,this._listenerManager.announceStatus(u)}o.forEach((function(e){if(e.channel,e.subscriptionMatch,a){if(n._dedupingManager.isDuplicate(e))return;n._dedupingManager.addEntry(e)}n._eventEmitter.emitEvent(e)})),this._region=t.metadata.region,this._startSubscribeLoop()}},e.prototype._stopSubscribeLoop=function(){this._subscribeCall&&("function"==typeof this._subscribeCall.abort&&this._subscribeCall.abort(),this._subscribeCall=null)},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),j={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",PNAccessManagerRevokeToken:"PNAccessManagerRevokeToken",PNHandshakeOperation:"PNHandshakeOperation",PNReceiveMessagesOperation:"PNReceiveMessagesOperation"},R=function(){function e(e){this._maximumSamplesCount=100,this._trackedLatencies={},this._latencies={},this._telemetryExcludeOperations=[j.PNSubscribeOperation,j.PNReceiveMessagesOperation,j.PNHandshakeOperation],this._maximumSamplesCount=e.maximumSamplesCount||this._maximumSamplesCount}return e.prototype.operationsLatencyForRequest=function(){var e=this,t={};return Object.keys(this._latencies).forEach((function(n){var r=e._latencies[n],o=e._averageLatency(r);o>0&&(t["l_".concat(n)]=o)})),t},e.prototype.startLatencyMeasure=function(e,t){!this._telemetryExcludeOperations.includes(e)&&t&&(this._trackedLatencies[t]=Date.now())},e.prototype.stopLatencyMeasure=function(e,t){if(!this._telemetryExcludeOperations.includes(e)&&t){var n=this._endpointName(e),r=this._latencies[n],o=this._trackedLatencies[t];r||(this._latencies[n]=[],r=this._latencies[n]),r.push(Date.now()-o),r.length>this._maximumSamplesCount&&r.splice(0,r.length-this._maximumSamplesCount),delete this._trackedLatencies[t]}},e.prototype._averageLatency=function(e){return Math.floor(e.reduce((function(e,t){return e+t}),0)/e.length)},e.prototype._endpointName=function(e){var t=null;switch(e){case j.PNPublishOperation:t="pub";break;case j.PNSignalOperation:t="sig";break;case j.PNHistoryOperation:case j.PNFetchMessagesOperation:case j.PNDeleteMessagesOperation:case j.PNMessageCounts:t="hist";break;case j.PNUnsubscribeOperation:case j.PNWhereNowOperation:case j.PNHereNowOperation:case j.PNHeartbeatOperation:case j.PNSetStateOperation:case j.PNGetStateOperation:t="pres";break;case j.PNAddChannelsToGroupOperation:case j.PNRemoveChannelsFromGroupOperation:case j.PNChannelGroupsOperation:case j.PNRemoveGroupOperation:case j.PNChannelsForGroupOperation:t="cg";break;case j.PNPushNotificationEnabledChannelsOperation:case j.PNRemoveAllPushNotificationsOperation:t="push";break;case j.PNCreateUserOperation:case j.PNUpdateUserOperation:case j.PNDeleteUserOperation:case j.PNGetUserOperation:case j.PNGetUsersOperation:case j.PNCreateSpaceOperation:case j.PNUpdateSpaceOperation:case j.PNDeleteSpaceOperation:case j.PNGetSpaceOperation:case j.PNGetSpacesOperation:case j.PNGetMembersOperation:case j.PNUpdateMembersOperation:case j.PNGetMembershipsOperation:case j.PNUpdateMembershipsOperation:t="obj";break;case j.PNAddMessageActionOperation:case j.PNRemoveMessageActionOperation:case j.PNGetMessageActionsOperation:t="msga";break;case j.PNAccessManagerGrant:case j.PNAccessManagerAudit:t="pam";break;case j.PNAccessManagerGrantToken:case j.PNAccessManagerRevokeToken:t="pamv3";break;default:t="time"}return t},e}(),x=function(){function e(e,t,n){this._payload=e,this._setDefaultPayloadStructure(),this.title=t,this.body=n}return Object.defineProperty(e.prototype,"payload",{get:function(){return this._payload},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{set:function(e){this._title=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{set:function(e){this._subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{set:function(e){this._body=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{set:function(e){this._badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{set:function(e){this._sound=e},enumerable:!1,configurable:!0}),e.prototype._setDefaultPayloadStructure=function(){},e.prototype.toObject=function(){return{}},e}(),U=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"configurations",{set:function(e){e&&e.length&&(this._configurations=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"notification",{get:function(){return this._payload.aps},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.aps.alert.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){e&&e.length&&(this._payload.aps.alert.subtitle=e,this._subtitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.aps.alert.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this._badge},set:function(e){null!=e&&(this._payload.aps.badge=e,this._badge=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.aps.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),r.prototype._setDefaultPayloadStructure=function(){this._payload.aps={alert:{}}},r.prototype.toObject=function(){var e=this,t=n({},this._payload),r=t.aps,o=r.alert;if(this._isSilent&&(r["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");var i=[];this._configurations.forEach((function(t){i.push(e._objectFromAPNS2Configuration(t))})),i.length&&(t.pn_push=i)}return o&&Object.keys(o).length||delete r.alert,this._isSilent&&(delete r.alert,delete r.badge,delete r.sound,o={}),this._isSilent||Object.keys(o).length?t:null},r.prototype._objectFromAPNS2Configuration=function(e){var t=this;if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");var n=[];e.targets.forEach((function(e){n.push(t._objectFromAPNSTarget(e))}));var r=e.collapseId,o=e.expirationDate,i={auth_method:"token",targets:n,version:"v2"};return r&&r.length&&(i.collapse_id=r),o&&(i.expiration=o.toISOString()),i},r.prototype._objectFromAPNSTarget=function(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");var t=e.topic,n=e.environment,r=void 0===n?"development":n,o=e.excludedDevices,i=void 0===o?[]:o,s={topic:t,environment:r};return i.length&&(s.excluded_devices=i),s},r}(x),I=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"backContent",{get:function(){return this._backContent},set:function(e){e&&e.length&&(this._payload.back_content=e,this._backContent=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"backTitle",{get:function(){return this._backTitle},set:function(e){e&&e.length&&(this._payload.back_title=e,this._backTitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"count",{get:function(){return this._count},set:function(e){null!=e&&(this._payload.count=e,this._count=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"type",{get:function(){return this._type},set:function(e){e&&e.length&&(this._payload.type=e,this._type=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this.backTitle},set:function(e){this.backTitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this.backContent},set:function(e){this.backContent=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this.count},set:function(e){this.count=e},enumerable:!1,configurable:!0}),r.prototype.toObject=function(){return Object.keys(this._payload).length?n({},this._payload):null},r}(x),D=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return t(o,e),Object.defineProperty(o.prototype,"notification",{get:function(){return this._payload.notification},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"data",{get:function(){return this._payload.data},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.notification.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.notification.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.notification.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"icon",{get:function(){return this._icon},set:function(e){e&&e.length&&(this._payload.notification.icon=e,this._icon=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"tag",{get:function(){return this._tag},set:function(e){e&&e.length&&(this._payload.notification.tag=e,this._tag=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),o.prototype._setDefaultPayloadStructure=function(){this._payload.notification={},this._payload.data={}},o.prototype.toObject=function(){var e=n({},this._payload.data),t=null,o={};if(Object.keys(this._payload).length>2){var i=this._payload;i.notification,i.data;var s=r(i,["notification","data"]);e=n(n({},e),s)}return this._isSilent?e.notification=this._payload.notification:t=this._payload.notification,Object.keys(e).length&&(o.data=e),t&&Object.keys(t).length&&(o.notification=t),Object.keys(o).length?o:null},o}(x),F=function(){function e(e,t){this._payload={apns:{},mpns:{},fcm:{}},this._title=e,this._body=t,this.apns=new U(this._payload.apns,e,t),this.mpns=new I(this._payload.mpns,e,t),this.fcm=new D(this._payload.fcm,e,t)}return Object.defineProperty(e.prototype,"debugging",{set:function(e){this._debugging=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this._body},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){this._subtitle=e,this.apns.subtitle=e,this.mpns.subtitle=e,this.fcm.subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{get:function(){return this._badge},set:function(e){this._badge=e,this.apns.badge=e,this.mpns.badge=e,this.fcm.badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{get:function(){return this._sound},set:function(e){this._sound=e,this.apns.sound=e,this.mpns.sound=e,this.fcm.sound=e},enumerable:!1,configurable:!0}),e.prototype.buildPayload=function(e){var t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";var n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("mpns")){var r=this.mpns.toObject();r&&Object.keys(r).length&&(t.pn_mpns=r)}if(e.includes("fcm")){var o=this.fcm.toObject();o&&Object.keys(o).length&&(t.pn_gcm=o)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t},e}(),L=function(){function e(){this._listeners=[]}return e.prototype.addListener=function(e){this._listeners.includes(e)||this._listeners.push(e)},e.prototype.removeListener=function(e){var t=[];this._listeners.forEach((function(n){n!==e&&t.push(n)})),this._listeners=t},e.prototype.removeAllListeners=function(){this._listeners=[]},e.prototype.announcePresence=function(e){this._listeners.forEach((function(t){t.presence&&t.presence(e)}))},e.prototype.announceStatus=function(e){this._listeners.forEach((function(t){t.status&&t.status(e)}))},e.prototype.announceMessage=function(e){this._listeners.forEach((function(t){t.message&&t.message(e)}))},e.prototype.announceSignal=function(e){this._listeners.forEach((function(t){t.signal&&t.signal(e)}))},e.prototype.announceMessageAction=function(e){this._listeners.forEach((function(t){t.messageAction&&t.messageAction(e)}))},e.prototype.announceFile=function(e){this._listeners.forEach((function(t){t.file&&t.file(e)}))},e.prototype.announceObjects=function(e){this._listeners.forEach((function(t){t.objects&&t.objects(e)}))},e.prototype.announceUser=function(e){this._listeners.forEach((function(t){t.user&&t.user(e)}))},e.prototype.announceSpace=function(e){this._listeners.forEach((function(t){t.space&&t.space(e)}))},e.prototype.announceMembership=function(e){this._listeners.forEach((function(t){t.membership&&t.membership(e)}))},e.prototype.announceNetworkUp=function(){var e={};e.category=k.PNNetworkUpCategory,this.announceStatus(e)},e.prototype.announceNetworkDown=function(){var e={};e.category=k.PNNetworkDownCategory,this.announceStatus(e)},e}(),G=function(){function e(e,t){this._config=e,this._cbor=t}return e.prototype.setToken=function(e){e&&e.length>0?this._token=e:this._token=void 0},e.prototype.getToken=function(){return this._token},e.prototype.extractPermissions=function(e){var t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128==(128&e)&&(t.join=!0),64==(64&e)&&(t.update=!0),32==(32&e)&&(t.get=!0),8==(8&e)&&(t.delete=!0),4==(4&e)&&(t.manage=!0),2==(2&e)&&(t.write=!0),1==(1&e)&&(t.read=!0),t},e.prototype.parseToken=function(e){var t=this,n=this._cbor.decodeToken(e);if(void 0!==n){var r=n.res.uuid?Object.keys(n.res.uuid):[],o=Object.keys(n.res.chan),i=Object.keys(n.res.grp),s=n.pat.uuid?Object.keys(n.pat.uuid):[],a=Object.keys(n.pat.chan),u=Object.keys(n.pat.grp),c={version:n.v,timestamp:n.t,ttl:n.ttl,authorized_uuid:n.uuid},l=r.length>0,p=o.length>0,h=i.length>0;(l||p||h)&&(c.resources={},l&&(c.resources.uuids={},r.forEach((function(e){c.resources.uuids[e]=t.extractPermissions(n.res.uuid[e])}))),p&&(c.resources.channels={},o.forEach((function(e){c.resources.channels[e]=t.extractPermissions(n.res.chan[e])}))),h&&(c.resources.groups={},i.forEach((function(e){c.resources.groups[e]=t.extractPermissions(n.res.grp[e])}))));var f=s.length>0,d=a.length>0,y=u.length>0;return(f||d||y)&&(c.patterns={},f&&(c.patterns.uuids={},s.forEach((function(e){c.patterns.uuids[e]=t.extractPermissions(n.pat.uuid[e])}))),d&&(c.patterns.channels={},a.forEach((function(e){c.patterns.channels[e]=t.extractPermissions(n.pat.chan[e])}))),y&&(c.patterns.groups={},u.forEach((function(e){c.patterns.groups[e]=t.extractPermissions(n.pat.grp[e])})))),Object.keys(n.meta).length>0&&(c.meta=n.meta),c.signature=n.sig,c}},e}();function K(e){return encodeURIComponent(e).replace(/[!~*'()]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())}))}function B(e){return function(e){var t=[];return Object.keys(e).forEach((function(e){return t.push(e)})),t}(e).sort()}var H={signPamFromParams:function(e){return B(e).map((function(t){return"".concat(t,"=").concat(K(e[t]))})).join("&")},endsWith:function(e,t){return-1!==e.indexOf(t,this.length-t.length)},createPromise:function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),reject:t,fulfill:e}},encodeString:K,stringToArrayBuffer:function(e){for(var t=new ArrayBuffer(2*e.length),n=new Uint16Array(t),r=0,o=e.length;r0&&(t+=n),t}function J(e,t,n){return t.usePost&&t.usePost(e,n)?"POST":t.usePatch&&t.usePatch(e,n)?"PATCH":t.useDelete&&t.useDelete(e,n)?"DELETE":t.useGetFile&&t.useGetFile(e,n)?"GETFILE":"GET"}function $(e,t,n,r,o){var i=e.config,s=e.crypto,a=J(e,o,r);n.timestamp=Math.floor((new Date).getTime()/1e3),"PNPublishOperation"===o.getOperation()&&o.usePost&&o.usePost(e,r)&&(a="GET"),"GETFILE"===a&&(a="GET");var u="".concat(a,"\n").concat(i.publishKey,"\n").concat(t,"\n").concat(H.signPamFromParams(n),"\n");if("POST"===a)u+="string"==typeof(c=o.postPayload(e,r))?c:JSON.stringify(c);else if("PATCH"===a){var c;u+="string"==typeof(c=o.patchPayload(e,r))?c:JSON.stringify(c)}var l="v2.".concat(s.HMACSHA256(u));l=(l=(l=l.replace(/\+/g,"-")).replace(/\//g,"_")).replace(/=+$/,""),n.signature=l}function Q(e,t){for(var r=[],o=2;o0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/leave")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(){return{}}});var ae=Object.freeze({__proto__:null,getOperation:function(){return j.PNWhereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r;return"/v2/presence/sub-key/".concat(n.subscribeKey,"/uuid/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return t.payload?{channels:t.payload.channels}:{channels:[]}}});var ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNHeartbeatOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/heartbeat")},isAuthSupported:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o=t.state,i=e.config,s={};return r.length>0&&(s["channel-group"]=r.join(",")),o&&(s.state=JSON.stringify(o)),s.heartbeat=i.getPresenceTimeout(),s},handleResponse:function(){return{}}});var ce=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetStateOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r,i=t.channels,s=void 0===i?[]:i,a=s.length>0?s.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(a),"/uuid/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a={};return 1===o.length&&0===s.length?a[o[0]]=t.payload:a=t.payload,{channels:a}}});var le=Object.freeze({__proto__:null,getOperation:function(){return j.PNSetStateOperation},validateParams:function(e,t){var n=e.config,r=t.state,o=t.channels,i=void 0===o?[]:o,s=t.channelGroups,a=void 0===s?[]:s;return r?n.subscribeKey?0===i.length&&0===a.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key":"Missing State"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/uuid/").concat(H.encodeString(n.UUID),"/data")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.state,r=t.channelGroups,o=void 0===r?[]:r,i={};return i.state=JSON.stringify(n),o.length>0&&(i["channel-group"]=o.join(",")),i},handleResponse:function(e,t){return{state:t.payload}}});var pe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=t.channelGroups,s=void 0===i?[]:i,a="/v2/presence/sub-key/".concat(n.subscribeKey);if(o.length>0||s.length>0){var u=o.length>0?o.join(","):",";a+="/channel/".concat(H.encodeString(u))}return a},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.channelGroups,o=void 0===r?[]:r,i=t.includeUUIDs,s=void 0===i||i,a=t.includeState,u=void 0!==a&&a,c=t.queryParameters,l=void 0===c?{}:c,p={};return s||(p.disable_uuids=1),u&&(p.state=1),o.length>0&&(p["channel-group"]=o.join(",")),p=n(n({},p),l)},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a=n.includeUUIDs,u=void 0===a||a,c=n.includeState,l=void 0!==c&&c;return o.length>1||s.length>0||0===s.length&&0===o.length?function(){var e={};return e.totalChannels=t.payload.total_channels,e.totalOccupancy=t.payload.total_occupancy,e.channels={},Object.keys(t.payload.channels).forEach((function(n){var r=t.payload.channels[n],o=[];return e.channels[n]={occupants:o,name:n,occupancy:r.occupancy},u&&r.uuids.forEach((function(e){l?o.push({state:e.state,uuid:e.uuid}):o.push({state:null,uuid:e})})),e})),e}():function(){var e={},n=[];return e.totalChannels=1,e.totalOccupancy=t.occupancy,e.channels={},e.channels[o[0]]={occupants:n,name:o[0],occupancy:t.occupancy},u&&t.uuids&&t.uuids.forEach((function(e){l?n.push({state:e.state,uuid:e.uuid}):n.push({state:null,uuid:e})})),e}()},handleError:function(e,t,n){402!==n.statusCode||this.getURL(e,t).includes("channel")||(n.errorData.message="You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.")}});var he=Object.freeze({__proto__:null,getOperation:function(){return j.PNAddMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.action,o=t.channel;return t.messageTimetoken?n.subscribeKey?o?r?r.value?r.type?r.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message channel":"Missing Subscribe Key":"Missing message timetoken"},usePost:function(){return!0},postURL:function(e,t){var n=e.config,r=t.channel,o=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},getRequestHeaders:function(){return{"Content-Type":"application/json"}},isAuthSupported:function(){return!0},prepareParams:function(){return{}},postPayload:function(e,t){return t.action},handleResponse:function(e,t){return{data:t.data}}});var fe=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken;return t.messageTimetoken?o?n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key":"Missing action timetoken":"Missing message timetoken"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken,i=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(i,"/action/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{data:t.data}}});var de=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetMessageActionsOperation},validateParams:function(e,t){var n=e.config,r=t.channel;return n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channel;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.limit,r=t.start,o=t.end,i={};return n&&(i.limit=n),r&&(i.start=r),o&&(i.end=o),i},handleResponse:function(e,t){var n={data:t.data,start:null,end:null};return n.data.length&&(n.end=n.data[n.data.length-1].actionTimetoken,n.start=n.data[0].actionTimetoken),n}}),ye={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel can't be empty"},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.limit&&(n.limit=t.limit),t.next&&(n.next=t.next),n},handleResponse:function(e,t){return{status:t.status,data:t.data,next:t.next,count:t.count}}},ge={getOperation:function(){return j.PNGenerateUploadUrlOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?void 0:"name can't be empty":"channel can't be empty"},usePost:function(){return!0},postURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/generate-upload-url")},postPayload:function(e,t){return{name:t.name}},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data,file_upload_request:t.file_upload_request}}},me={getOperation:function(){return j.PNPublishFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.fileId)?(null==t?void 0:t.fileName)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},getURL:function(e,t){var n=e.config,r=n.publishKey,o=n.subscribeKey,i=function(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}(e,{message:t.message,file:{name:t.fileName,id:t.fileId}});return"/v1/files/publish-file/".concat(r,"/").concat(o,"/0/").concat(H.encodeString(t.channel),"/0/").concat(H.encodeString(i))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.ttl&&(n.ttl=t.ttl),void 0!==t.storeInHistory&&(n.store=t.storeInHistory?"1":"0"),t.meta&&"object"==typeof t.meta&&(n.meta=JSON.stringify(t.meta)),n},handleResponse:function(e,t){return{timetoken:t[2]}}},be=function(e){var t=function(e){var t=this,n=e.generateUploadUrl,r=e.publishFile,s=e.modules,a=s.PubNubFile,u=s.config,c=s.cryptography,l=s.cryptoModule,p=s.networking;return function(e){var s=e.channel,h=e.file,f=e.message,d=e.cipherKey,y=e.meta,g=e.ttl,m=e.storeInHistory;return o(t,void 0,void 0,(function(){var e,t,o,b,v,_,S,w,O,P,E,A,T,N,C,k,M,j,R,x,U,I,D,F,L,G,K,B,H;return i(this,(function(i){switch(i.label){case 0:if(!s)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!h)throw new q("Validation failed, check status for details",z("file can't be empty"));return e=a.create(h),[4,n({channel:s,name:e.name})];case 1:return t=i.sent(),o=t.file_upload_request,b=o.url,v=o.form_fields,_=t.data,S=_.id,w=_.name,a.supportsEncryptFile&&(d||l)?null!=d?[3,3]:[4,l.encryptFile(e,a)]:[3,6];case 2:return O=i.sent(),[3,5];case 3:return[4,c.encryptFile(d,e,a)];case 4:O=i.sent(),i.label=5;case 5:e=O,i.label=6;case 6:P=v,e.mimeType&&(P=v.map((function(t){return"Content-Type"===t.key?{key:t.key,value:e.mimeType}:t}))),i.label=7;case 7:return i.trys.push([7,21,,22]),a.supportsFileUri&&h.uri?(T=(A=p).POSTFILE,N=[b,P],[4,e.toFileUri()]):[3,10];case 8:return[4,T.apply(A,N.concat([i.sent()]))];case 9:return E=i.sent(),[3,20];case 10:return a.supportsFile?(k=(C=p).POSTFILE,M=[b,P],[4,e.toFile()]):[3,13];case 11:return[4,k.apply(C,M.concat([i.sent()]))];case 12:return E=i.sent(),[3,20];case 13:return a.supportsBuffer?(R=(j=p).POSTFILE,x=[b,P],[4,e.toBuffer()]):[3,16];case 14:return[4,R.apply(j,x.concat([i.sent()]))];case 15:return E=i.sent(),[3,20];case 16:return a.supportsBlob?(I=(U=p).POSTFILE,D=[b,P],[4,e.toBlob()]):[3,19];case 17:return[4,I.apply(U,D.concat([i.sent()]))];case 18:return E=i.sent(),[3,20];case 19:throw new Error("Unsupported environment");case 20:return[3,22];case 21:throw(F=i.sent()).response&&"string"==typeof F.response.text?(L=F.response.text,G=/(.*)<\/Message>/gi.exec(L),new q(G?"Upload to bucket failed: ".concat(G[1]):"Upload to bucket failed.",F)):new q("Upload to bucket failed.",F);case 22:if(204!==E.status)throw new q("Upload to bucket was unsuccessful",E);K=u.fileUploadPublishRetryLimit,B=!1,H={timetoken:"0"},i.label=23;case 23:return i.trys.push([23,25,,26]),[4,r({channel:s,message:f,fileId:S,fileName:w,meta:y,storeInHistory:m,ttl:g})];case 24:return H=i.sent(),B=!0,[3,26];case 25:return i.sent(),K-=1,[3,26];case 26:if(!B&&K>0)return[3,23];i.label=27;case 27:if(B)return[2,{timetoken:H.timetoken,id:S,name:w}];throw new q("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{channel:s,id:S,name:w})}}))}))}}(e);return function(e,n){var r=t(e);return"function"==typeof n?(r.then((function(e){return n(null,e)})).catch((function(e){return n(e,null)})),r):r}},ve=function(e,t){var n=t.channel,r=t.id,o=t.name,i=e.config,s=e.networking,a=e.tokenManager;if(!n)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!r)throw new q("Validation failed, check status for details",z("file id can't be empty"));if(!o)throw new q("Validation failed, check status for details",z("file name can't be empty"));var u="/v1/files/".concat(i.subscribeKey,"/channels/").concat(H.encodeString(n),"/files/").concat(r,"/").concat(o),c={};c.uuid=i.getUUID(),c.pnsdk=W(i);var l=a.getToken()||i.getAuthKey();l&&(c.auth=l),i.secretKey&&$(e,u,c,{},{getOperation:function(){return"PubNubGetFileUrlOperation"}});var p=Object.keys(c).map((function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(c[e]))})).join("&");return""!==p?"".concat(s.getStandardOrigin()).concat(u,"?").concat(p):"".concat(s.getStandardOrigin()).concat(u)},_e={getOperation:function(){return j.PNDownloadFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?(null==t?void 0:t.id)?void 0:"id can't be empty":"name can't be empty":"channel can't be empty"},useGetFile:function(){return!0},getFileURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},ignoreBody:function(){return!0},forceBuffered:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t,n){var r=e.PubNubFile,s=e.config,a=e.cryptography,u=e.cryptoModule;return o(void 0,void 0,void 0,(function(){var e,o,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.response.body,r.supportsEncryptFile&&(n.cipherKey||u)?null!=n.cipherKey?[3,2]:[4,u.decryptFile(r.create({data:e,name:n.name}),r)]:[3,5];case 1:return o=i.sent().data,[3,4];case 2:return[4,a.decrypt(null!==(c=n.cipherKey)&&void 0!==c?c:s.cipherKey,e)];case 3:o=i.sent(),i.label=4;case 4:e=o,i.label=5;case 5:return[2,r.create({data:e,name:null!==(l=t.response.name)&&void 0!==l?l:n.name,mimeType:t.response.type})]}}))}))}},Se={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.id)?(null==t?void 0:t.name)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status}}},we={getOperation:function(){return j.PNGetAllUUIDMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,next:t.next,prev:t.prev}}},Oe={getOperation:function(){return j.PNGetUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Pe={getOperation:function(){return j.PNSetUUIDMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.data))return"Data cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ee={getOperation:function(){return j.PNRemoveUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r=e.config;return{uuid:null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ae={getOperation:function(){return j.PNGetAllChannelMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Te={getOperation:function(){return j.PNGetChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ne={getOperation:function(){return j.PNSetChannelMetadataOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.data)?void 0:"Data cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ce={getOperation:function(){return j.PNRemoveChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},ke={getOperation:function(){return j.PNGetMembersOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&m.include.push("uuid"),(null===(i=t.include)||void 0===i?void 0:i.customUUIDFields)&&m.include.push("uuid.custom"),(null===(s=t.include)||void 0===s?void 0:s.UUIDStatusField)&&m.include.push("uuid.status"),(null===(u=t.include)||void 0===u?void 0:u.UUIDTypeField)&&m.include.push("uuid.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Me={getOperation:function(){return j.PNSetMembersOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.uuids)&&0!==(null==t?void 0:t.uuids.length)?void 0:"UUIDs cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.uuids.map((function(e){return"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["uuid.status","uuid.type","type"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customUUIDFields)&&h.include.push("uuid.custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&h.include.push("uuid")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},je={getOperation:function(){return j.PNGetMembershipsOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&m.include.push("channel"),(null===(i=t.include)||void 0===i?void 0:i.customChannelFields)&&m.include.push("channel.custom"),(null===(s=t.include)||void 0===s?void 0:s.channelStatusField)&&m.include.push("channel.status"),(null===(u=t.include)||void 0===u?void 0:u.channelTypeField)&&m.include.push("channel.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Re={getOperation:function(){return j.PNSetMembershipsOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)||0===(null==t?void 0:t.channels.length))return"Channels cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.channels.map((function(e){return"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["channel.status","channel.type","status"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customChannelFields)&&h.include.push("channel.custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&h.include.push("channel")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}};var xe=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerAudit},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/audit/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channel,r=t.channelGroup,o=t.authKeys,i=void 0===o?[]:o,s={};return n&&(s.channel=n),r&&(s["channel-group"]=r),i.length>0&&(s.auth=i.join(",")),s},handleResponse:function(e,t){return t.payload}});var Ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrant},validateParams:function(e,t){var n=e.config;return n.subscribeKey?n.publishKey?n.secretKey?null==t.uuids||t.authKeys?null==t.uuids||null==t.channels&&null==t.channelGroups?void 0:"Both channel/channelgroup and uuid cannot be used in the same request":"authKeys are required for grant request on uuids":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/grant/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.uuids,a=void 0===s?[]:s,u=t.ttl,c=t.read,l=void 0!==c&&c,p=t.write,h=void 0!==p&&p,f=t.manage,d=void 0!==f&&f,y=t.get,g=void 0!==y&&y,m=t.join,b=void 0!==m&&m,v=t.update,_=void 0!==v&&v,S=t.authKeys,w=void 0===S?[]:S,O=t.delete,P={};return P.r=l?"1":"0",P.w=h?"1":"0",P.m=d?"1":"0",P.d=O?"1":"0",P.g=g?"1":"0",P.j=b?"1":"0",P.u=_?"1":"0",r.length>0&&(P.channel=r.join(",")),i.length>0&&(P["channel-group"]=i.join(",")),w.length>0&&(P.auth=w.join(",")),a.length>0&&(P["target-uuid"]=a.join(",")),(u||0===u)&&(P.ttl=u),P},handleResponse:function(){return{}}});function Ie(e){var t,n,r,o,i=void 0!==(null==e?void 0:e.authorizedUserId),s=void 0!==(null===(t=null==e?void 0:e.resources)||void 0===t?void 0:t.users),a=void 0!==(null===(n=null==e?void 0:e.resources)||void 0===n?void 0:n.spaces),u=void 0!==(null===(r=null==e?void 0:e.patterns)||void 0===r?void 0:r.users),c=void 0!==(null===(o=null==e?void 0:e.patterns)||void 0===o?void 0:o.spaces);return u||s||c||a||i}function De(e){var t=0;return e.join&&(t|=128),e.update&&(t|=64),e.get&&(t|=32),e.delete&&(t|=8),e.manage&&(t|=4),e.write&&(t|=2),e.read&&(t|=1),t}function Fe(e,t){if(Ie(t))return function(e,t){var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorizedUserId,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.users,c=r.spaces,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.users,h=o.spaces,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}(0,t);var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorized_uuid,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.uuids,c=r.channels,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.uuids,h=o.channels,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}var Le=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrantToken},extractPermissions:De,validateParams:function(e,t){var n,r,o,i,s,a,u=e.config;if(!u.subscribeKey)return"Missing Subscribe Key";if(!u.publishKey)return"Missing Publish Key";if(!u.secretKey)return"Missing Secret Key";if(!t.resources&&!t.patterns)return"Missing either Resources or Patterns.";var c=void 0!==(null==t?void 0:t.authorized_uuid),l=void 0!==(null===(n=null==t?void 0:t.resources)||void 0===n?void 0:n.uuids),p=void 0!==(null===(r=null==t?void 0:t.resources)||void 0===r?void 0:r.channels),h=void 0!==(null===(o=null==t?void 0:t.resources)||void 0===o?void 0:o.groups),f=void 0!==(null===(i=null==t?void 0:t.patterns)||void 0===i?void 0:i.uuids),d=void 0!==(null===(s=null==t?void 0:t.patterns)||void 0===s?void 0:s.channels),y=void 0!==(null===(a=null==t?void 0:t.patterns)||void 0===a?void 0:a.groups),g=c||l||f||p||d||h||y;return Ie(t)&&g?"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`":(!t.resources||t.resources.uuids&&0!==Object.keys(t.resources.uuids).length||t.resources.channels&&0!==Object.keys(t.resources.channels).length||t.resources.groups&&0!==Object.keys(t.resources.groups).length||t.resources.users&&0!==Object.keys(t.resources.users).length||t.resources.spaces&&0!==Object.keys(t.resources.spaces).length)&&(!t.patterns||t.patterns.uuids&&0!==Object.keys(t.patterns.uuids).length||t.patterns.channels&&0!==Object.keys(t.patterns.channels).length||t.patterns.groups&&0!==Object.keys(t.patterns.groups).length||t.patterns.users&&0!==Object.keys(t.patterns.users).length||t.patterns.spaces&&0!==Object.keys(t.patterns.spaces).length)?void 0:"Missing values for either Resources or Patterns."},postURL:function(e){var t=e.config;return"/v3/pam/".concat(t.subscribeKey,"/grant")},usePost:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(){return{}},postPayload:function(e,t){return Fe(0,t)},handleResponse:function(e,t){return t.data.token}}),Ge={getOperation:function(){return j.PNAccessManagerRevokeToken},validateParams:function(e,t){return e.config.secretKey?t?void 0:"token can't be empty":"Missing Secret Key"},getURL:function(e,t){var n=e.config;return"/v3/pam/".concat(n.subscribeKey,"/grant/").concat(H.encodeString(t))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e){return{uuid:e.config.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}};function Ke(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}var Be=Object.freeze({__proto__:null,getOperation:function(){return j.PNPublishOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},usePost:function(e,t){var n=t.sendByPost;return void 0!==n&&n},getURL:function(e,t){var n=e.config,r=t.channel,o=Ke(e,t.message);return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0/").concat(H.encodeString(o))},postURL:function(e,t){var n=e.config,r=t.channel;return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},postPayload:function(e,t){return Ke(e,t.message)},prepareParams:function(e,t){var n=t.meta,r=t.replicate,o=void 0===r||r,i=t.storeInHistory,s=t.ttl,a={};return null!=i&&(a.store=i?"1":"0"),s&&(a.ttl=s),!1===o&&(a.norep="true"),n&&"object"==typeof n&&(a.meta=JSON.stringify(n)),a},handleResponse:function(e,t){return{timetoken:t[2]}}});var He=Object.freeze({__proto__:null,getOperation:function(){return j.PNSignalOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},getURL:function(e,t){var n,r=e.config,o=t.channel,i=t.message,s=(n=i,JSON.stringify(n));return"/signal/".concat(r.publishKey,"/").concat(r.subscribeKey,"/0/").concat(H.encodeString(o),"/0/").concat(H.encodeString(s))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{timetoken:t[2]}}});var qe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHistoryOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channel,r=e.config;return"/v2/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o=t.reverse,i=t.count,s=void 0===i?100:i,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p={include_token:"true"};return p.count=s,n&&(p.start=n),r&&(p.end=r),u&&(p.string_message_token="true"),null!=o&&(p.reverse=o.toString()),l&&(p.include_meta="true"),p},handleResponse:function(e,t){var n={messages:[],startTimeToken:t[1],endTimeToken:t[2]};return Array.isArray(t[0])&&t[0].forEach((function(t){var r=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message),o={timetoken:t.timetoken,entry:r.payload};t.meta&&(o.meta=t.meta),r.error&&(o.error=r.error),n.messages.push(o)})),n}});var ze=Object.freeze({__proto__:null,getOperation:function(){return j.PNDeleteMessagesOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},useDelete:function(){return!0},getURL:function(e,t){var n=t.channel,r=e.config;return"/v3/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o={};return n&&(o.start=n),r&&(o.end=r),o},handleResponse:function(e,t){return t.payload}});var Ve=Object.freeze({__proto__:null,getOperation:function(){return j.PNMessageCounts},validateParams:function(e,t){var n=t.channels,r=t.timetoken,o=t.channelTimetokens,i=e.config;return n?r&&o?"timetoken and channelTimetokens are incompatible together":o&&o.length>1&&n.length!==o.length?"Length of channelTimetokens and channels do not match":i.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channels,r=e.config,o=n.join(",");return"/v3/history/sub-key/".concat(r.subscribeKey,"/message-counts/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.timetoken,r=t.channelTimetokens,o={};if(r&&1===r.length){var i=a(r,1)[0];o.timetoken=i}else r?o.channelsTimetoken=r.join(","):n&&(o.timetoken=n);return o},handleResponse:function(e,t){return{channels:t.channels}}});var We=Object.freeze({__proto__:null,getOperation:function(){return j.PNFetchMessagesOperation},validateParams:function(e,t){var n=t.channels,r=t.includeMessageActions,o=void 0!==r&&r,i=e.config;if(!n||0===n.length)return"Missing channels";if(!i.subscribeKey)return"Missing Subscribe Key";if(o&&n.length>1)throw new TypeError("History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.")},getURL:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.includeMessageActions,i=void 0!==o&&o,s=e.config,a=i?"history-with-actions":"history",u=r.length>0?r.join(","):",";return"/v3/".concat(a,"/sub-key/").concat(s.subscribeKey,"/channel/").concat(H.encodeString(u))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channels,r=t.start,o=t.end,i=t.includeMessageActions,s=t.count,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p=t.includeUuid,h=t.includeUUID,f=void 0===h||h,d=t.includeMessageType,y=void 0===d||d,g={};return g.max=s||(n.length>1||!0===i?25:100),r&&(g.start=r),o&&(g.end=o),u&&(g.string_message_token="true"),l&&(g.include_meta="true"),f&&!1!==p&&(g.include_uuid="true"),y&&(g.include_message_type="true"),g},handleResponse:function(e,t){var n={channels:{}};return Object.keys(t.channels||{}).forEach((function(r){n.channels[r]=[],(t.channels[r]||[]).forEach((function(t){var o={},i=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message);o.channel=r,o.timetoken=t.timetoken,o.message=i.payload,o.messageType=t.message_type,o.uuid=t.uuid,t.actions&&(o.actions=t.actions,o.data=t.actions),t.meta&&(o.meta=t.meta),i.error&&(o.error=i.error),n.channels[r].push(o)}))})),t.more&&(n.more=t.more),n}});var Je=Object.freeze({__proto__:null,getOperation:function(){return j.PNTimeOperation},getURL:function(){return"/time/0"},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(){return{}},isAuthSupported:function(){return!1},handleResponse:function(e,t){return{timetoken:t[0]}},validateParams:function(){}});var $e=Object.freeze({__proto__:null,getOperation:function(){return j.PNSubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=e.config,r=t.state,o=t.channelGroups,i=void 0===o?[]:o,s=t.timetoken,a=t.filterExpression,u=t.region,c={heartbeat:n.getPresenceTimeout()};return i.length>0&&(c["channel-group"]=i.join(",")),a&&a.length>0&&(c["filter-expr"]=a),Object.keys(r).length&&(c.state=JSON.stringify(r)),s&&(c.tt=s),u&&(c.tr=u),c},handleResponse:function(e,t){var n=[];t.m.forEach((function(e){var t={publishTimetoken:e.p.t,region:e.p.r},r={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:t};n.push(r)}));var r={timetoken:t.t.t,region:t.t.r};return{messages:n,metadata:r}}}),Qe={getOperation:function(){return j.PNHandshakeOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)&&!(null==t?void 0:t.channelGroups))return"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),n.tt=0,t.state&&(n.state=JSON.stringify(t.state)),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.ee="",n},handleResponse:function(e,t){return{region:t.t.r,timetoken:t.t.t}}},Xe={getOperation:function(){return j.PNReceiveMessagesOperation},validateParams:function(e,t){return(null==t?void 0:t.channels)||(null==t?void 0:t.channelGroups)?(null==t?void 0:t.timetoken)?(null==t?void 0:t.region)?void 0:"region can not be empty":"timetoken can not be empty":"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},getAbortSignal:function(e,t){return t.abortSignal},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.tt=t.timetoken,n.tr=t.region,n.ee="",n},handleResponse:function(e,t){var n=[];return t.m.forEach((function(e){var t={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,publishMetaData:{timetoken:e.p.t,region:e.p.r}};n.push(t)})),{messages:n,metadata:{region:t.t.r,timetoken:t.t.t}}}},Ye=function(){function e(e){void 0===e&&(e=!1),this.sync=e,this.listeners=new Set}return e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.notify=function(e){var t=this,n=function(){t.listeners.forEach((function(t){t(e)}))};this.sync?n():setTimeout(n,0)},e}(),Ze=function(){function e(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}return e.prototype.transition=function(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)},e.prototype.on=function(e,t){return this.transitionMap.set(e,t),this},e.prototype.with=function(e,t){return[this,e,null!=t?t:[]]},e.prototype.onEnter=function(e){return this.enterEffects.push(e),this},e.prototype.onExit=function(e){return this.exitEffects.push(e),this},e}(),et=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return t(n,e),n.prototype.describe=function(e){return new Ze(e)},n.prototype.start=function(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})},n.prototype.transition=function(e){var t,n,r,o,i,u;if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});var c=this.currentState.transition(this.currentContext,e);if(c){var l=a(c,3),p=l[0],h=l[1],f=l[2];try{for(var d=s(this.currentState.exitEffects),y=d.next();!y.done;y=d.next()){var g=y.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}var m=this.currentState;this.currentState=p;var b=this.currentContext;this.currentContext=h,this.notify({type:"transitionDone",fromState:m,fromContext:b,toState:p,toContext:h,event:e});try{for(var v=s(f),_=v.next();!_.done;_=v.next()){g=_.value;this.notify({type:"invocationDispatched",invocation:g})}}catch(e){r={error:e}}finally{try{_&&!_.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var S=s(this.currentState.enterEffects),w=S.next();!w.done;w=S.next()){g=w.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){i={error:e}}finally{try{w&&!w.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}},n}(Ye),tt=function(){function e(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}return e.prototype.on=function(e,t){this.handlers.set(e,t)},e.prototype.dispatch=function(e){if("CANCEL"!==e.type){var t=this.handlers.get(e.type);if(!t)throw new Error("Unhandled invocation '".concat(e.type,"'"));var n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}else if(this.instances.has(e.payload)){var r=this.instances.get(e.payload);null==r||r.cancel(),this.instances.delete(e.payload)}},e.prototype.dispose=function(){var e,t;try{for(var n=s(this.instances.entries()),r=n.next();!r.done;r=n.next()){var o=a(r.value,2),i=o[0];o[1].cancel(),this.instances.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();function nt(e,t){var n=function(){for(var n=[],r=0;r0&&r(e),[2]}))}))}))),s.on(ht.type,ut((function(e,t,n){var r=n.emitStatus;return o(s,void 0,void 0,(function(){return i(this,(function(t){return r(e),[2]}))}))}))),s.on(ft.type,ut((function(e,n,r){var a=r.receiveMessages,u=r.delay,c=r.config;return o(s,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return c.retryConfiguration&&c.retryConfiguration.shouldRetry(e.reason,e.attempts)?(n.throwIfAborted(),[4,u(c.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),n.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,a({abortSignal:n,channels:e.channels,channelGroups:e.groups,timetoken:e.cursor.timetoken,region:e.cursor.region,filterExpression:c.filterExpression})];case 3:return r=i.sent(),[2,t.transition(Pt(r.metadata,r.messages))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Et(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(At(new q(c.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s.on(dt.type,ut((function(e,r,a){var u=a.handshake,c=a.delay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({abortSignal:r,channels:e.channels,channelGroups:e.groups,filterExpression:p.filterExpression},p.maintainPresenceState&&{state:l}))];case 3:return o=i.sent(),[2,t.transition(vt(o))];case 4:return(s=i.sent())instanceof Error&&"Aborted"===s.message?[2]:s instanceof q?[2,t.transition(_t(s))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(St(new q(p.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s}return t(r,e),r}(tt),Mt=new Ze("HANDSHAKE_FAILED");Mt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Mt.on(Nt.type,(function(e,t){return Ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor})})),Mt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(r=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==r?r:0}})})),Mt.on(Ct.type,(function(e){return Lt.with()}));var jt=new Ze("HANDSHAKE_STOPPED");jt.on(yt.type,(function(e,t){return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),jt.on(Nt.type,(function(e,t){return Ft.with(n(n({},e),{cursor:t.payload.cursor||e.cursor}))})),jt.on(gt.type,(function(e,t){var n;return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),jt.on(Ct.type,(function(e){return Lt.with()}));var Rt=new Ze("RECEIVE_FAILED");Rt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Rt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(Ct.type,(function(e){return Lt.with(void 0)}));var xt=new Ze("RECEIVE_STOPPED");xt.on(yt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),xt.on(gt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Ct.type,(function(){return Lt.with(void 0)}));var Ut=new Ze("RECEIVE_RECONNECTING");Ut.onEnter((function(e){return ft(e)})),Ut.onExit((function(){return ft.cancel})),Ut.on(Pt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),Ut.on(Et.type,(function(e,t){return Ut.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Ut.on(At.type,(function(e,t){var n;return Rt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Ut.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),Ut.on(gt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Ut.on(yt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ut.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var It=new Ze("RECEIVING");It.onEnter((function(e){return lt(e.channels,e.groups,e.cursor)})),It.onExit((function(){return lt.cancel})),It.on(wt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),It.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups})})),It.on(gt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),It.on(Ot.type,(function(e,t){return Ut.with(n(n({},e),{attempts:0,reason:t.payload}))})),It.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),It.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var Dt=new Ze("HANDSHAKE_RECONNECTING");Dt.onEnter((function(e){return dt(e)})),Dt.onExit((function(){return dt.cancel})),Dt.on(vt.type,(function(e,t){var n,r,o={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=e.cursor)||void 0===r?void 0:r.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return It.with({channels:e.channels,groups:e.groups,cursor:o},[ht({category:k.PNConnectedCategory})])})),Dt.on(_t.type,(function(e,t){return Dt.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Dt.on(St.type,(function(e,t){var n;return Mt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Dt.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Dt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Dt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.region)||0}})})),Dt.on(Ct.type,(function(e){return Lt.with(void 0)}));var Ft=new Ze("HANDSHAKING");Ft.onEnter((function(e){return ct(e.channels,e.groups)})),Ft.onExit((function(){return ct.cancel})),Ft.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ft.on(mt.type,(function(e,t){var n,r;return It.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.timetoken:t.payload.timetoken,region:t.payload.region}},[ht({category:k.PNConnectedCategory})])})),Ft.on(bt.type,(function(e,t){return Dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload})})),Ft.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Ft.on(gt.type,(function(e,t){var n;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),Ft.on(Ct.type,(function(e){return Lt.with()}));var Lt=new Ze("UNSUBSCRIBED");Lt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups})})),Lt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})}));var Gt=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new kt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(Lt,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e){var t=this,n=e.channels,r=e.channelGroups,o=e.timetoken,i=e.withPresence;this.channels=u(u([],a(this.channels),!1),a(null!=n?n:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=r?r:[]),!1),i&&(this.channels.map((function(e){return t.channels.push("".concat(e,"-pnpres"))})),this.groups.map((function(e){return t.groups.push("".concat(e,"-pnpres"))}))),o?this.engine.transition(gt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))),o)):this.engine.transition(yt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((function(e){return!e.endsWith("-pnpres")})))),groups:Array.from(new Set(this.groups.filter((function(e){return!e.endsWith("-pnpres")}))))})},e.prototype.unsubscribe=function(e){var t=this,n=e.channels,r=void 0===n?[]:n,o=e.channelGroups,i=void 0===o?[]:o,s=H.removeSingleOccurance(this.channels,u(u([],a(r),!1),a(r.map((function(e){return"".concat(e,"-pnpres")}))),!1)),c=H.removeSingleOccurance(this.groups,u(u([],a(i),!1),a(i.map((function(e){return"".concat(e,"-pnpres")}))),!1));if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(c).size){var l=H.findUniqueCommonElements(this.channels,r),p=H.findUniqueCommonElements(this.groups,i);this.dependencies.presenceState&&(null==l||l.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==p||p.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.channels=s,this.groups=c,this.engine.transition(yt(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:l.slice(0),groups:p.slice(0)})}},e.prototype.unsubscribeAll=function(){this.channels=[],this.groups=[],this.dependencies.presenceState&&(this.dependencies.presenceState={}),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.reconnect=function(e){var t=e.timetoken,n=e.region;this.engine.transition(Nt(t,n))},e.prototype.disconnect=function(){this.engine.transition(Tt()),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.getSubscribedChannels=function(){return this.channels.slice(0)},e.prototype.getSubscribedChannelGroups=function(){return this.groups.slice(0)},e.prototype.dispose=function(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),Kt=nt("RECONNECT",(function(){return{}})),Bt=nt("DISCONNECT",(function(){return{}})),Ht=nt("JOINED",(function(e,t){return{channels:e,groups:t}})),qt=nt("LEFT",(function(e,t){return{channels:e,groups:t}})),zt=nt("LEFT_ALL",(function(){return{}})),Vt=nt("HEARTBEAT_SUCCESS",(function(e){return{statusCode:e}})),Wt=nt("HEARTBEAT_FAILURE",(function(e){return e})),Jt=nt("HEARTBEAT_GIVEUP",(function(){return{}})),$t=nt("TIMES_UP",(function(){return{}})),Qt=rt("HEARTBEAT",(function(e,t){return{channels:e,groups:t}})),Xt=rt("LEAVE",(function(e,t){return{channels:e,groups:t}})),Yt=rt("EMIT_STATUS",(function(e){return e})),Zt=ot("WAIT",(function(){return{}})),en=ot("DELAYED_HEARTBEAT",(function(e){return e})),tn=function(e){function r(t,r){var s=e.call(this,r)||this;return s.on(Qt.type,ut((function(e,r,a){var u=a.heartbeat,c=a.presenceState,l=a.config;return o(s,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,u(n({channels:e.channels,channelGroups:e.groups},l.maintainPresenceState&&{state:c}))];case 1:return o.sent(),t.transition(Vt(200)),[3,3];case 2:return(r=o.sent())instanceof q?[2,t.transition(Wt(r))]:[3,3];case 3:return[2]}}))}))}))),s.on(Xt.type,ut((function(e,t,n){var r=n.leave,a=n.config;return o(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:if(a.suppressLeaveEvents)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r({channels:e.channels,channelGroups:e.groups})];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}}))}))}))),s.on(Zt.type,ut((function(e,n,r){var a=r.heartbeatDelay;return o(s,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return n.throwIfAborted(),[4,a()];case 1:return e.sent(),n.throwIfAborted(),[2,t.transition($t())]}}))}))}))),s.on(en.type,ut((function(e,r,a){var u=a.heartbeat,c=a.retryDelay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({channels:e.channels,channelGroups:e.groups},p.maintainPresenceState&&{state:l}))];case 3:return i.sent(),[2,t.transition(Vt(200))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Wt(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Jt())];case 7:return[2]}}))}))}))),s.on(Yt.type,ut((function(e,t,r){var a=r.emitStatus,u=r.config;return o(s,void 0,void 0,(function(){var t;return i(this,(function(r){return u.announceFailedHeartbeats&&!0===(null===(t=null==e?void 0:e.status)||void 0===t?void 0:t.error)?a(e.status):u.announceSuccessfulHeartbeats&&200===e.statusCode&&a(n(n({},e),{operation:j.PNHeartbeatOperation,error:!1})),[2]}))}))}))),s}return t(r,e),r}(tt),nn=new Ze("HEARTBEAT_STOPPED");nn.on(Ht.type,(function(e,t){return nn.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),nn.on(qt.type,(function(e,t){return nn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))})})),nn.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),nn.on(zt.type,(function(e,t){return un.with(void 0)}));var rn=new Ze("HEARTBEAT_COOLDOWN");rn.onEnter((function(){return Zt()})),rn.onExit((function(){return Zt.cancel})),rn.on($t.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),rn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),rn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),rn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),rn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var on=new Ze("HEARTBEAT_FAILED");on.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),on.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),on.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),on.on(Bt.type,(function(e,t){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),on.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var sn=new Ze("HEARBEAT_RECONNECTING");sn.onEnter((function(e){return en(e)})),sn.onExit((function(){return en.cancel})),sn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),sn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),sn.on(Bt.type,(function(e,t){nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),sn.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),sn.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),sn.on(Jt.type,(function(e,t){return on.with({channels:e.channels,groups:e.groups})})),sn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var an=new Ze("HEARTBEATING");an.onEnter((function(e){return Qt(e.channels,e.groups)})),an.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),an.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),an.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),an.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:0,reason:t.payload}))})),an.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),an.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var un=new Ze("HEARTBEAT_INACTIVE");un.on(Ht.type,(function(e,t){return an.with({channels:t.payload.channels,groups:t.payload.groups})}));var cn=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dispatcher=new tn(this.engine,e),this.dependencies=e,this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(un,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.join=function(e){var t=e.channels,n=e.groups;this.channels=u(u([],a(this.channels),!1),a(null!=t?t:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=n?n:[]),!1),this.engine.transition(Ht(this.channels.slice(0),this.groups.slice(0)))},e.prototype.leave=function(e){var t=this,n=e.channels,r=e.groups;this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(qt(null!=n?n:[],null!=r?r:[]))},e.prototype.leaveAll=function(){this.engine.transition(zt())},e.prototype.dispose=function(){this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),ln=function(){function e(){}return e.LinearRetryPolicy=function(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e.ExponentialRetryPolicy=function(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e}(),pn=function(){function e(e){var t=e.modules,n=e.listenerManager,r=e.getFileUrl;this.modules=t,this.listenerManager=n,this.getFileUrl=r,this._channelListenerMap=new Map,this._groupListenerMap=new Map,t.cryptoModule&&(this._decoder=new TextDecoder)}return e.prototype.emitEvent=function(e){var t=e.channel,o=e.publishMetaData,i=e.subscriptionMatch;if(t===i&&(i=null),e.channel.endsWith("-pnpres")){var s={channel:null,subscription:null};t&&(s.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(s.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),s.action=e.payload.action,s.state=e.payload.data,s.timetoken=o.publishTimetoken,s.occupancy=e.payload.occupancy,s.uuid=e.payload.uuid,s.timestamp=e.payload.timestamp,e.payload.join&&(s.join=e.payload.join),e.payload.leave&&(s.leave=e.payload.leave),e.payload.timeout&&(s.timeout=e.payload.timeout),s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announcePresence(s),this._announce("presence",s,s.channel,s.subscription)}else if(1===e.messageType){(s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=e.payload,this.listenerManager.announceSignal(s),this._announce("signal",s,s.channel,s.subscription)}else if(2===e.messageType){if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},this.listenerManager.announceObjects(s),this._announce("objects",s,s.channel,s.subscription),"uuid"===e.payload.type){var a=this._renameChannelField(s),u=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"user"})});this.listenerManager.announceUser(u),this._announce("user",u,s.channel,s.subscription)}else if("channel"===message.payload.type){a=this._renameChannelField(s);var c=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"space"})});this.listenerManager.announceSpace(c),this._announce("space",c,s.channel,s.subscription)}else if("membership"===message.payload.type){var l=(a=this._renameChannelField(s)).message.data,p=l.uuid,h=l.channel,f=r(l,["uuid","channel"]);f.user=p,f.space=h;var d=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),data:f})});this.listenerManager.announceMembership(d),this._announce("membership",d,s.channel,s.subscription)}}else if(3===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId,s.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},s.event=e.payload.event,this.listenerManager.announceMessageAction(s),this._announce("messageAction",s,s.channel,s.subscription)}else if(4===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId;var y=e.payload;if(this.modules.cryptoModule){var g=void 0;try{g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}null!==g&&(y=g)}e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=y.message,s.file={id:y.file.id,name:y.file.name,url:this.getFileUrl({id:y.file.id,name:y.file.name,channel:t})},this.listenerManager.announceFile(s),this._announce("file",s,s.channel,s.subscription)}else{if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.publishTimetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),this.modules.cryptoModule){g=void 0;try{var m;g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}s.message=null!=g?g:e.payload}else s.message=e.payload;s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announceMessage(s),this._announce("message",s,s.channel,s.subscription)}},e.prototype.addListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){r._channelListenerMap[t]?r._channelListenerMap[t].includes(e)||r._channelListenerMap[t].push(e):r._channelListenerMap[t]=[e]})),null==n||n.forEach((function(t){r._groupListenerMap[t]?r._groupListenerMap[t].includes(e)||r._groupListenerMap[t].push(e):r._groupListenerMap[t]=[e]}))):this.listenerManager.addListener(e)},e.prototype.removeListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){var n;r._channelListenerMap[t]=null===(n=r._channelListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))})),null==n||n.forEach((function(t){var n;r._groupListenerMap[t]=null===(n=r._groupListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))}))):this.listenerManager.removeListener(e)},e.prototype.removeAllListeners=function(){this.listenerManager.removeAllListeners()},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e.prototype._announce=function(e,t,n,r){var o,i;null===(o=this._channelListenerMap[n])||void 0===o||o.forEach((function(n){return n[e]&&n[e](t)})),null===(i=this._groupListenerMap[r])||void 0===i||i.forEach((function(n){return n[e]&&n[e](t)}))},e}(),hn=function(){function e(){}return e.prototype.subscribe=function(){var e,t;this.pubnub.subscribe(n({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))},e.prototype.unsubscribe=function(){this.pubnub.unsubscribe({channels:this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),channelGroups:this.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))})},Object.defineProperty(e.prototype,"onMessage",{set:function(e){this.listener.message=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onPresence",{set:function(e){this.listener.presence=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onSignal",{set:function(e){this.listener.signal=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onObjects",{set:function(e){this.listener.objects=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onMessageAction",{set:function(e){this.listener.messageAction=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onFile",{set:function(e){this.listener.file=e},enumerable:!1,configurable:!0}),e.prototype.addListener=function(e){this.eventEmitter.addListener(e,this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),this.groupNames.filter((function(e){return!e.endsWith("-pnpres")})))},e.prototype.removeListener=function(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)},Object.defineProperty(e.prototype,"channels",{get:function(){return this.channelNames.slice(0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"channelGroups",{get:function(){return this.groupNames.slice(0)},enumerable:!1,configurable:!0}),e}(),fn=function(e){function n(t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.subscriptionOptions,c=t.eventEmitter,l=t.pubnub,p=e.call(this)||this;return p.channelNames=[],p.groupNames=[],p.subscriptionList=[],p.options=s,p.eventEmitter=c,p.pubnub=l,r.forEach((function(e){var t=p.pubnub.channel(e).subscription(p.options);p.channelNames=u(u([],a(p.channelNames),!1),a(t.channels),!1),p.subscriptionList.push(t)})),i.forEach((function(e){var t=p.pubnub.channelGroup(e).subscription(p.options);p.groupNames=u(u([],a(p.groupNames),!1),a(t.channelGroups),!1),p.subscriptionList.push(t)})),p.listener={},c.addListener(p.listener,p.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),p.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),p}return t(n,e),n.prototype.addSubscription=function(e){this.subscriptionList.push(e),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscription=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return t!==e}))},n.prototype.addSubscriptionSet=function(e){this.subscriptionList=u(u([],a(this.subscriptionList),!1),a(e.subscriptions),!1),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscriptionSet=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return!e.subscriptions.includes(t)}))},Object.defineProperty(n.prototype,"subscriptions",{get:function(){return this.subscriptionList.slice(0)},enumerable:!1,configurable:!0}),n}(hn),dn=function(e){function r(t){var n=t.channels,r=t.channelGroups,o=t.subscriptionOptions,i=t.eventEmitter,s=t.pubnub,a=e.call(this)||this;return a.channelNames=[],a.groupNames=[],a.channelNames=n,a.groupNames=r,a.options=o,a.pubnub=s,a.eventEmitter=i,a.listener={},i.addListener(a.listener,a.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),a.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),a}return t(r,e),r.prototype.addSubscription=function(e){return new fn({channels:u(u([],a(this.channelNames),!1),a(e.channels),!1),channelGroups:u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),subscriptionOptions:n(n({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})},r}(hn),yn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),gn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),mn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),bn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),vn=function(){function e(e){var t=this,r=e.networking,o=e.cbor,i=new g({setup:e});this._config=i;var c=new T({config:i}),l=e.cryptography;r.init(i);var p=new G(i,o);this._tokenManager=p;var h=new R({maximumSamplesCount:6e4});this._telemetryManager=h;var f=this._config.cryptoModule,d={config:i,networking:r,crypto:c,cryptography:l,tokenManager:p,telemetryManager:h,PubNubFile:e.PubNubFile,cryptoModule:f};this.File=e.PubNubFile,this.encryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.encryptFile(t,this.File)):l.encryptFile(e,t,this.File)},this.decryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.decryptFile(t,this.File)):l.decryptFile(e,t,this.File)};var y=Q.bind(this,d,Je),m=Q.bind(this,d,se),v=Q.bind(this,d,ue),_=Q.bind(this,d,le),S=Q.bind(this,d,$e),w=new L;if(this._listenerManager=w,this.iAmHere=Q.bind(this,d,ue),this.iAmAway=Q.bind(this,d,se),this.setPresenceState=Q.bind(this,d,le),this.handshake=Q.bind(this,d,Qe),this.receiveMessages=Q.bind(this,d,Xe),this._eventEmitter=new pn({modules:d,listenerManager:this._listenerManager,getFileUrl:function(e){return ve(d,e)}}),!0===i.enableEventEngine){if(i.maintainPresenceState&&(this.presenceState={},this.setState=function(e){var n,r;return null===(n=e.channels)||void 0===n||n.forEach((function(n){return t.presenceState[n]=e.state})),null===(r=e.channelGroups)||void 0===r||r.forEach((function(n){return t.presenceState[n]=e.state})),t.setPresenceState({channels:e.channels,channelGroups:e.channelGroups,state:t.presenceState})}),i.getHeartbeatInterval()){var O=new cn({heartbeat:this.iAmHere,leave:this.iAmAway,heartbeatDelay:function(){return new Promise((function(e){return setTimeout(e,1e3*d.config.getHeartbeatInterval())}))},retryDelay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},config:d.config,presenceState:this.presenceState,emitStatus:function(e){w.announceStatus(e)}});this.presenceEventEngine=O,this.join=this.presenceEventEngine.join.bind(O),this.leave=this.presenceEventEngine.leave.bind(O),this.leaveAll=this.presenceEventEngine.leaveAll.bind(O)}var P=new Gt({handshake:this.handshake,receiveMessages:this.receiveMessages,delay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},join:this.join,leave:this.leave,leaveAll:this.leaveAll,presenceState:this.presenceState,config:d.config,emitMessages:function(e){var n,r;try{for(var o=s(e),i=o.next();!i.done;i=o.next()){var a=i.value;t._eventEmitter.emitEvent(a)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},emitStatus:function(e){w.announceStatus(e)}});this.subscribe=P.subscribe.bind(P),this.unsubscribe=P.unsubscribe.bind(P),this.unsubscribeAll=P.unsubscribeAll.bind(P),this.reconnect=P.reconnect.bind(P),this.disconnect=P.disconnect.bind(P),this.destroy=P.dispose.bind(P),this.getSubscribedChannels=P.getSubscribedChannels.bind(P),this.getSubscribedChannelGroups=P.getSubscribedChannelGroups.bind(P),this.eventEngine=P}else{var E=new M({timeEndpoint:y,leaveEndpoint:m,heartbeatEndpoint:v,setStateEndpoint:_,subscribeEndpoint:S,crypto:d.crypto,config:d.config,listenerManager:w,getFileUrl:function(e){return ve(d,e)},cryptoModule:d.cryptoModule,eventEmitter:this._eventEmitter});this.subscribe=E.adaptSubscribeChange.bind(E),this.unsubscribe=E.adaptUnsubscribeChange.bind(E),this.disconnect=E.disconnect.bind(E),this.reconnect=E.reconnect.bind(E),this.unsubscribeAll=E.unsubscribeAll.bind(E),this.getSubscribedChannels=E.getSubscribedChannels.bind(E),this.getSubscribedChannelGroups=E.getSubscribedChannelGroups.bind(E),this.setState=E.adaptStateChange.bind(E),this.presence=E.adaptPresenceChange.bind(E),this.destroy=function(e){E.unsubscribeAll(e),E.disconnect()}}this.addListener=this._eventEmitter.addListener.bind(this._eventEmitter),this.removeListener=this._eventEmitter.removeListener.bind(this._eventEmitter),this.removeAllListeners=this._eventEmitter.removeAllListeners.bind(this._eventEmitter),this.parseToken=p.parseToken.bind(p),this.setToken=p.setToken.bind(p),this.getToken=p.getToken.bind(p),this.channelGroups={listGroups:Q.bind(this,d,ee),listChannels:Q.bind(this,d,te),addChannels:Q.bind(this,d,X),removeChannels:Q.bind(this,d,Y),deleteGroup:Q.bind(this,d,Z)},this.push={addChannels:Q.bind(this,d,ne),removeChannels:Q.bind(this,d,re),deleteDevice:Q.bind(this,d,ie),listChannels:Q.bind(this,d,oe)},this.hereNow=Q.bind(this,d,pe),this.whereNow=Q.bind(this,d,ae),this.getState=Q.bind(this,d,ce),this.grant=Q.bind(this,d,Ue),this.grantToken=Q.bind(this,d,Le),this.audit=Q.bind(this,d,xe),this.revokeToken=Q.bind(this,d,Ge),this.publish=Q.bind(this,d,Be),this.fire=function(e,n){return e.replicate=!1,e.storeInHistory=!1,t.publish(e,n)},this.signal=Q.bind(this,d,He),this.history=Q.bind(this,d,qe),this.deleteMessages=Q.bind(this,d,ze),this.messageCounts=Q.bind(this,d,Ve),this.fetchMessages=Q.bind(this,d,We),this.addMessageAction=Q.bind(this,d,he),this.removeMessageAction=Q.bind(this,d,fe),this.getMessageActions=Q.bind(this,d,de),this.listFiles=Q.bind(this,d,ye);var A=Q.bind(this,d,ge);this.publishFile=Q.bind(this,d,me),this.sendFile=be({generateUploadUrl:A,publishFile:this.publishFile,modules:d}),this.getFileUrl=function(e){return ve(d,e)},this.downloadFile=Q.bind(this,d,_e),this.deleteFile=Q.bind(this,d,Se),this.channel=function(e){return new yn(e,t._eventEmitter,t)},this.channelGroup=function(e){return new gn(e,t._eventEmitter,t)},this.channelMetadata=function(e){return new mn(e,t._eventEmitter,t)},this.userMetadata=function(e){return new bn(e,t._eventEmitter,t)},this.subscriptionSet=function(e){return new fn({channels:e.channels,channelGroups:e.channelGroups,subscriptionOptions:e.subscriptionOptions,eventEmitter:t._eventEmitter,pubnub:t})},this.objects={getAllUUIDMetadata:Q.bind(this,d,we),getUUIDMetadata:Q.bind(this,d,Oe),setUUIDMetadata:Q.bind(this,d,Pe),removeUUIDMetadata:Q.bind(this,d,Ee),getAllChannelMetadata:Q.bind(this,d,Ae),getChannelMetadata:Q.bind(this,d,Te),setChannelMetadata:Q.bind(this,d,Ne),removeChannelMetadata:Q.bind(this,d,Ce),getChannelMembers:Q.bind(this,d,ke),setChannelMembers:function(e){for(var r=[],o=1;o=this._config.origin.length&&(this._currentSubDomain=0);var t=this._config.origin[this._currentSubDomain];return"".concat(e).concat(t)},e.prototype.hasModule=function(e){return e in this._modules},e.prototype.shiftStandardOrigin=function(){return this._standardOrigin=this.nextOrigin(),this._standardOrigin},e.prototype.getStandardOrigin=function(){return this._standardOrigin},e.prototype.POSTFILE=function(e,t,n){return this._modules.postfile(e,t,n)},e.prototype.GETFILE=function(e,t,n){return this._modules.getfile(e,t,n)},e.prototype.POST=function(e,t,n,r){return this._modules.post(e,t,n,r)},e.prototype.PATCH=function(e,t,n,r){return this._modules.patch(e,t,n,r)},e.prototype.GET=function(e,t,n){return this._modules.get(e,t,n)},e.prototype.DELETE=function(e,t,n){return this._modules.del(e,t,n)},e.prototype._detectErrorCategory=function(e){if("ENOTFOUND"===e.code)return k.PNNetworkIssuesCategory;if("ECONNREFUSED"===e.code)return k.PNNetworkIssuesCategory;if("ECONNRESET"===e.code)return k.PNNetworkIssuesCategory;if("EAI_AGAIN"===e.code)return k.PNNetworkIssuesCategory;if(0===e.status||e.hasOwnProperty("status")&&void 0===e.status)return k.PNNetworkIssuesCategory;if(e.timeout)return k.PNTimeoutCategory;if("ETIMEDOUT"===e.code)return k.PNNetworkIssuesCategory;if(e.response){if(e.response.badRequest)return k.PNBadRequestCategory;if(e.response.forbidden)return k.PNAccessDeniedCategory}return k.PNUnknownCategory},e}();function Sn(e){var t=function(e){return e&&"object"==typeof e&&e.constructor===Object};if(!t(e))return e;var n={};return Object.keys(e).forEach((function(r){var o=function(e){return"string"==typeof e||e instanceof String}(r),i=r,s=e[r];Array.isArray(r)||o&&r.indexOf(",")>=0?i=(o?r.split(","):r).reduce((function(e,t){return e+=String.fromCharCode(t)}),""):(function(e){return"number"==typeof e&&isFinite(e)}(r)||o&&!isNaN(r))&&(i=String.fromCharCode(o?parseInt(r,10):10));n[i]=t(s)?Sn(s):s})),n}var wn=function(){function e(e,t){this._base64ToBinary=t,this._decode=e}return e.prototype.decodeToken=function(e){var t="";e.length%4==3?t="=":e.length%4==2&&(t="==");var n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,r=this._decode(this._base64ToBinary(n));if("object"==typeof r)return r},e}(),On={exports:{}},Pn={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;os.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;at?1:0}function Un(e,t,n,r){void 0===r&&(r=kn());var o,i=In(e,"",0,[],void 0,0,r)||e;try{o=0===Cn.length?JSON.stringify(i,t,n):JSON.stringify(i,Dn(t),n)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==Nn.length;){var s=Nn.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return o}function In(e,t,n,r,o,i,s){var a;if(i+=1,"object"==typeof e&&null!==e){for(a=0;as.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;a0)for(var r=0;r1&&"boolean"!=typeof t)throw new Qn('"allowMissing" argument must be a boolean');var n=gr(e),r=n.length>0?n[0]:"",o=mr("%"+r+"%",t),i=o.name,s=o.value,a=!1,u=o.alias;u&&(r=u[0],pr(n,lr([0,1],u)));for(var c=1,l=!0;c=n.length){var d=Yn(s,p);s=(l=!!d)&&"get"in d&&!("originalValue"in d.get)?d.get:s[p]}else l=cr(s,p),s=s[p];l&&!a&&(ir[i]=s)}}return s},vr={exports:{}};!function(e){var t=Vn,n=br,r=n("%Function.prototype.apply%"),o=n("%Function.prototype.call%"),i=n("%Reflect.apply%",!0)||t.call(o,r),s=n("%Object.getOwnPropertyDescriptor%",!0),a=n("%Object.defineProperty%",!0),u=n("%Math.max%");if(a)try{a({},"a",{value:1})}catch(e){a=null}e.exports=function(e){var n=i(t,o,arguments);if(s&&a){var r=s(n,"length");r.configurable&&a(n,"length",{value:1+u(0,e.length-(arguments.length-1))})}return n};var c=function(){return i(t,r,arguments)};a?a(e.exports,"apply",{value:c}):e.exports.apply=c}(vr);var _r=br,Sr=vr.exports,wr=Sr(_r("String.prototype.indexOf")),Or=l(Object.freeze({__proto__:null,default:{}})),Pr="function"==typeof Map&&Map.prototype,Er=Object.getOwnPropertyDescriptor&&Pr?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ar=Pr&&Er&&"function"==typeof Er.get?Er.get:null,Tr=Pr&&Map.prototype.forEach,Nr="function"==typeof Set&&Set.prototype,Cr=Object.getOwnPropertyDescriptor&&Nr?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,kr=Nr&&Cr&&"function"==typeof Cr.get?Cr.get:null,Mr=Nr&&Set.prototype.forEach,jr="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Rr="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,xr="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Ur=Boolean.prototype.valueOf,Ir=Object.prototype.toString,Dr=Function.prototype.toString,Fr=String.prototype.match,Lr=String.prototype.slice,Gr=String.prototype.replace,Kr=String.prototype.toUpperCase,Br=String.prototype.toLowerCase,Hr=RegExp.prototype.test,qr=Array.prototype.concat,zr=Array.prototype.join,Vr=Array.prototype.slice,Wr=Math.floor,Jr="function"==typeof BigInt?BigInt.prototype.valueOf:null,$r=Object.getOwnPropertySymbols,Qr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,Xr="function"==typeof Symbol&&"object"==typeof Symbol.iterator,Yr="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xr||"symbol")?Symbol.toStringTag:null,Zr=Object.prototype.propertyIsEnumerable,eo=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function to(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||Hr.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var r=e<0?-Wr(-e):Wr(e);if(r!==e){var o=String(r),i=Lr.call(t,o.length+1);return Gr.call(o,n,"$&_")+"."+Gr.call(Gr.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Gr.call(t,n,"$&_")}var no=Or,ro=no.custom,oo=co(ro)?ro:null;function io(e,t,n){var r="double"===(n.quoteStyle||t)?'"':"'";return r+e+r}function so(e){return Gr.call(String(e),/"/g,""")}function ao(e){return!("[object Array]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function uo(e){return!("[object RegExp]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function co(e){if(Xr)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!Qr)return!1;try{return Qr.call(e),!0}catch(e){}return!1}var lo=Object.prototype.hasOwnProperty||function(e){return e in this};function po(e,t){return lo.call(e,t)}function ho(e){return Ir.call(e)}function fo(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;nt.maxStringLength){var n=e.length-t.maxStringLength,r="... "+n+" more character"+(n>1?"s":"");return yo(Lr.call(e,0,t.maxStringLength),t)+r}return io(Gr.call(Gr.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,go),"single",t)}function go(e){var t=e.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return n?"\\"+n:"\\x"+(t<16?"0":"")+Kr.call(t.toString(16))}function mo(e){return"Object("+e+")"}function bo(e){return e+" { ? }"}function vo(e,t,n,r){return e+" ("+t+") {"+(r?_o(n,r):zr.call(n,", "))+"}"}function _o(e,t){if(0===e.length)return"";var n="\n"+t.prev+t.base;return n+zr.call(e,","+n)+"\n"+t.prev}function So(e,t){var n=ao(e),r=[];if(n){r.length=e.length;for(var o=0;o-1?Sr(n):n},Po=function e(t,n,r,o){var i=n||{};if(po(i,"quoteStyle")&&"single"!==i.quoteStyle&&"double"!==i.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(po(i,"maxStringLength")&&("number"==typeof i.maxStringLength?i.maxStringLength<0&&i.maxStringLength!==1/0:null!==i.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var s=!po(i,"customInspect")||i.customInspect;if("boolean"!=typeof s&&"symbol"!==s)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(po(i,"indent")&&null!==i.indent&&"\t"!==i.indent&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(po(i,"numericSeparator")&&"boolean"!=typeof i.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=i.numericSeparator;if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return yo(t,i);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var u=String(t);return a?to(t,u):u}if("bigint"==typeof t){var l=String(t)+"n";return a?to(t,l):l}var p=void 0===i.depth?5:i.depth;if(void 0===r&&(r=0),r>=p&&p>0&&"object"==typeof t)return ao(t)?"[Array]":"[Object]";var h=function(e,t){var n;if("\t"===e.indent)n="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;n=zr.call(Array(e.indent+1)," ")}return{base:n,prev:zr.call(Array(t+1),n)}}(i,r);if(void 0===o)o=[];else if(fo(o,t)>=0)return"[Circular]";function f(t,n,s){if(n&&(o=Vr.call(o)).push(n),s){var a={depth:i.depth};return po(i,"quoteStyle")&&(a.quoteStyle=i.quoteStyle),e(t,a,r+1,o)}return e(t,i,r+1,o)}if("function"==typeof t&&!uo(t)){var d=function(e){if(e.name)return e.name;var t=Fr.call(Dr.call(e),/^function\s*([\w$]+)/);if(t)return t[1];return null}(t),y=So(t,f);return"[Function"+(d?": "+d:" (anonymous)")+"]"+(y.length>0?" { "+zr.call(y,", ")+" }":"")}if(co(t)){var g=Xr?Gr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qr.call(t);return"object"!=typeof t||Xr?g:mo(g)}if(function(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return!0;return"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}(t)){for(var m="<"+Br.call(String(t.nodeName)),b=t.attributes||[],v=0;v"}if(ao(t)){if(0===t.length)return"[]";var _=So(t,f);return h&&!function(e){for(var t=0;t=0)return!1;return!0}(_)?"["+_o(_,h)+"]":"[ "+zr.call(_,", ")+" ]"}if(function(e){return!("[object Error]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)){var S=So(t,f);return"cause"in Error.prototype||!("cause"in t)||Zr.call(t,"cause")?0===S.length?"["+String(t)+"]":"{ ["+String(t)+"] "+zr.call(S,", ")+" }":"{ ["+String(t)+"] "+zr.call(qr.call("[cause]: "+f(t.cause),S),", ")+" }"}if("object"==typeof t&&s){if(oo&&"function"==typeof t[oo]&&no)return no(t,{depth:p-r});if("symbol"!==s&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!Ar||!e||"object"!=typeof e)return!1;try{Ar.call(e);try{kr.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}(t)){var w=[];return Tr&&Tr.call(t,(function(e,n){w.push(f(n,t,!0)+" => "+f(e,t))})),vo("Map",Ar.call(t),w,h)}if(function(e){if(!kr||!e||"object"!=typeof e)return!1;try{kr.call(e);try{Ar.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}(t)){var O=[];return Mr&&Mr.call(t,(function(e){O.push(f(e,t))})),vo("Set",kr.call(t),O,h)}if(function(e){if(!jr||!e||"object"!=typeof e)return!1;try{jr.call(e,jr);try{Rr.call(e,Rr)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}(t))return bo("WeakMap");if(function(e){if(!Rr||!e||"object"!=typeof e)return!1;try{Rr.call(e,Rr);try{jr.call(e,jr)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}(t))return bo("WeakSet");if(function(e){if(!xr||!e||"object"!=typeof e)return!1;try{return xr.call(e),!0}catch(e){}return!1}(t))return bo("WeakRef");if(function(e){return!("[object Number]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(Number(t)));if(function(e){if(!e||"object"!=typeof e||!Jr)return!1;try{return Jr.call(e),!0}catch(e){}return!1}(t))return mo(f(Jr.call(t)));if(function(e){return!("[object Boolean]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(Ur.call(t));if(function(e){return!("[object String]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(String(t)));if("undefined"!=typeof window&&t===window)return"{ [object Window] }";if(t===c)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)&&!uo(t)){var P=So(t,f),E=eo?eo(t)===Object.prototype:t instanceof Object||t.constructor===Object,A=t instanceof Object?"":"null prototype",T=!E&&Yr&&Object(t)===t&&Yr in t?Lr.call(ho(t),8,-1):A?"Object":"",N=(E||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(T||A?"["+zr.call(qr.call([],T||[],A||[]),": ")+"] ":"");return 0===P.length?N+"{}":h?N+"{"+_o(P,h)+"}":N+"{ "+zr.call(P,", ")+" }"}return String(t)},Eo=wo("%TypeError%"),Ao=wo("%WeakMap%",!0),To=wo("%Map%",!0),No=Oo("WeakMap.prototype.get",!0),Co=Oo("WeakMap.prototype.set",!0),ko=Oo("WeakMap.prototype.has",!0),Mo=Oo("Map.prototype.get",!0),jo=Oo("Map.prototype.set",!0),Ro=Oo("Map.prototype.has",!0),xo=function(e,t){for(var n,r=e;null!==(n=r.next);r=n)if(n.key===t)return r.next=n.next,n.next=e.next,e.next=n,n},Uo=String.prototype.replace,Io=/%20/g,Do="RFC3986",Fo={default:Do,formatters:{RFC1738:function(e){return Uo.call(e,Io,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:Do},Lo=Fo,Go=Object.prototype.hasOwnProperty,Ko=Array.isArray,Bo=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),Ho=function(e,t){for(var n=t&&t.plainObjects?Object.create(null):{},r=0;r1;){var t=e.pop(),n=t.obj[t.prop];if(Ko(n)){for(var r=[],o=0;o=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===Lo.RFC1738&&(40===u||41===u)?s+=i.charAt(a):u<128?s+=Bo[u]:u<2048?s+=Bo[192|u>>6]+Bo[128|63&u]:u<55296||u>=57344?s+=Bo[224|u>>12]+Bo[128|u>>6&63]+Bo[128|63&u]:(a+=1,u=65536+((1023&u)<<10|1023&i.charCodeAt(a)),s+=Bo[240|u>>18]+Bo[128|u>>12&63]+Bo[128|u>>6&63]+Bo[128|63&u])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(Ko(e)){for(var n=[],r=0;r0?b.join(",")||null:void 0}];else if(Qo(u))O=u;else{var E=Object.keys(b);O=c?E.sort(c):E}for(var A=o&&Qo(b)&&1===b.length?n+"[]":n,T=0;T-1?e.split(","):e},li=function(e,t,n,r){if(e){var o=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,s=n.depth>0&&/(\[[^[\]]*])/.exec(o),a=s?o.slice(0,s.index):o,u=[];if(a){if(!n.plainObjects&&ii.call(Object.prototype,a)&&!n.allowPrototypes)return;u.push(a)}for(var c=0;n.depth>0&&null!==(s=i.exec(o))&&c=0;--i){var s,a=e[i];if("[]"===a&&n.parseArrays)s=[].concat(o);else{s=n.plainObjects?Object.create(null):{};var u="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(u,10);n.parseArrays||""!==u?!isNaN(c)&&a!==u&&String(c)===u&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(s=[])[c]=o:"__proto__"!==u&&(s[u]=o):s={0:o}}o=s}return o}(u,t,n,r)}},pi=function(e,t){var n,r=e,o=function(e){if(!e)return ti;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||ti.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Wo.default;if(void 0!==e.format){if(!Jo.call(Wo.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var r=Wo.formatters[n],o=ti.filter;return("function"==typeof e.filter||Qo(e.filter))&&(o=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:ti.addQueryPrefix,allowDots:void 0===e.allowDots?ti.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ti.charsetSentinel,delimiter:void 0===e.delimiter?ti.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:ti.encode,encoder:"function"==typeof e.encoder?e.encoder:ti.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:ti.encodeValuesOnly,filter:o,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:ti.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:ti.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ti.strictNullHandling}}(t);"function"==typeof o.filter?r=(0,o.filter)("",r):Qo(o.filter)&&(n=o.filter);var i,s=[];if("object"!=typeof r||null===r)return"";i=t&&t.arrayFormat in $o?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=$o[i];if(t&&"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var u="comma"===a&&t&&t.commaRoundTrip;n||(n=Object.keys(r)),o.sort&&n.sort(o.sort);for(var c=zo(),l=0;l0?f+h:""},hi={formats:Fo,parse:function(e,t){var n=function(e){if(!e)return ai;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?ai.charset:e.charset;return{allowDots:void 0===e.allowDots?ai.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:ai.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:ai.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:ai.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ai.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:ai.comma,decoder:"function"==typeof e.decoder?e.decoder:ai.decoder,delimiter:"string"==typeof e.delimiter||oi.isRegExp(e.delimiter)?e.delimiter:ai.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:ai.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:ai.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:ai.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:ai.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ai.strictNullHandling}}(t);if(""===e||null==e)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof e?function(e,t){var n,r={__proto__:null},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,i),a=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(l=si(l)?[l]:l),ii.call(r,c)?r[c]=oi.combine(r[c],l):r[c]=l}return r}(e,n):e,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),s=0;s=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.split(/ *; */).shift(),e.params=e=>{const n={};var r,o=t(e.split(/ *; */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *= */),t=e.shift(),o=e.shift();t&&o&&(n[t]=o)}}catch(e){o.e(e)}finally{o.f()}return n},e.parseLinks=e=>{const n={};var r,o=t(e.split(/ *, */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *; */),t=e[0].slice(1,-1);n[e[1].split(/ *= */)[1].slice(1,-1)]=t}}catch(e){o.e(e)}finally{o.f()}return n},e.cleanHeader=(e,t)=>(delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e),e.isObject=e=>null!==e&&"object"==typeof e,e.hasOwn=Object.hasOwn||function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(new Object(e),t)},e.mixin=(t,n)=>{for(const r in n)e.hasOwn(n,r)&&(t[r]=n[r])}}(fi);const di=Or,yi=fi.isObject,gi=fi.hasOwn;var mi=bi;function bi(){}bi.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},bi.prototype.parse=function(e){return this._parser=e,this},bi.prototype.responseType=function(e){return this._responseType=e,this},bi.prototype.serialize=function(e){return this._serializer=e,this},bi.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(const t in e)if(gi(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},bi.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};const vi=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),_i=new Set([408,413,429,500,502,503,504,521,522,524]);bi.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{const n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&_i.has(t.status))return!0;if(e){if(e.code&&vi.has(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},bi.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},bi.prototype.then=function(e,t){if(!this._fullfilledPromise){const e=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(((t,n)=>{e.on("abort",(()=>{if(this._maxRetries&&this._maxRetries>this._retries)return;if(this.timedout&&this.timedoutError)return void n(this.timedoutError);const e=new Error("Aborted");e.code="ABORTED",e.status=this.status,e.method=this.method,e.url=this.url,n(e)})),e.end(((e,r)=>{e?n(e):t(r)}))}))}return this._fullfilledPromise.then(e,t)},bi.prototype.catch=function(e){return this.then(void 0,e)},bi.prototype.use=function(e){return e(this),this},bi.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},bi.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},bi.prototype.get=function(e){return this._header[e.toLowerCase()]},bi.prototype.getHeader=bi.prototype.get,bi.prototype.set=function(e,t){if(yi(e)){for(const t in e)gi(e,t)&&this.set(t,e[t]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},bi.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},bi.prototype.field=function(e,t,n){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(yi(e)){for(const t in e)gi(e,t)&&this.field(t,e[t]);return this}if(Array.isArray(t)){for(const n in t)gi(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),n?this._getFormData().append(e,t,n):this._getFormData().append(e,t),this},bi.prototype.abort=function(){if(this._aborted)return this;if(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req){if(di.gte(process.version,"v13.0.0")&&di.lt(process.version,"v14.0.0"))throw new Error("Superagent does not work in v13 properly with abort() due to Node.js core changes");this.req.abort()}return this.clearTimeout(),this.emit("abort"),this},bi.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization",`Basic ${r(`${e}:${t}`)}`);break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization",`Bearer ${e}`)}return this},bi.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},bi.prototype.redirects=function(e){return this._maxRedirects=e,this},bi.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},bi.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},bi.prototype.send=function(e){const t=yi(e);let n=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&yi(this._data))for(const t in e){if("bigint"==typeof e[t]&&!e[t].toJSON)throw new Error("Cannot serialize BigInt value to json");gi(e,t)&&(this._data[t]=e[t])}else{if("bigint"==typeof e)throw new Error("Cannot send value of type BigInt");"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],n&&(n=n.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===n?this._data?`${this._data}&${e}`:e:(this._data||"")+e):this._data=e}return!t||this._isHost(e)||n||this.type("json"),this},bi.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},bi.prototype._finalizeQueryString=function(){const e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){const e=this.url.indexOf("?");if(e>=0){const t=this.url.slice(e+1).split("&");"function"==typeof this._sort?t.sort(this._sort):t.sort(),this.url=this.url.slice(0,e)+"?"+t.join("&")}}},bi.prototype._appendQueryString=()=>{console.warn("Unsupported")},bi.prototype._timeoutError=function(e,t,n){if(this._aborted)return;const r=new Error(`${e+t}ms exceeded`);r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.timedoutError=r,this.abort(),this.callback(r)},bi.prototype._setTimeouts=function(){const e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((()=>{e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((()=>{e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};const Si=fi;var wi=Oi;function Oi(){}function Pi(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Ei(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ei(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw i}}}}function Ei(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n{if(o.XMLHttpRequest)return new o.XMLHttpRequest;throw new Error("Browser-only version of superagent could not find XHR")};const g="".trim?e=>e.trim():e=>e.replace(/(^\s*|\s*$)/g,"");function m(e){if(!c(e))return e;const t=[];for(const n in e)p(e,n)&&b(t,n,e[n]);return t.join("&")}function b(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r)){var o,i=n(r);try{for(i.s();!(o=i.n()).done;){b(e,t,o.value)}}catch(e){i.e(e)}finally{i.f()}}else if(c(r))for(const n in r)p(r,n)&&b(e,`${t}[${n}]`,r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function v(e){const t={},n=e.split("&");let r,o;for(let e=0,i=n.length;e{let e,t=null,r=null;try{r=new S(n)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||r.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=e.status||r.status,n.callback(e,r)):n.callback(null,r)}))}y.serializeObject=m,y.parseString=v,y.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":a.stringify,"application/json":s},y.parse={"application/x-www-form-urlencoded":v,"application/json":JSON.parse},l(S.prototype,h.prototype),S.prototype._parseBody=function(e){let t=y.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&_(this.type)&&(t=y.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},S.prototype.toError=function(){const e=this.req,t=e.method,n=e.url,r=`cannot ${t} ${n} (${this.status})`,o=new Error(r);return o.status=this.status,o.method=t,o.url=n,o},y.Response=S,i(w.prototype),l(w.prototype,u.prototype),w.prototype.type=function(e){return this.set("Content-Type",y.types[e]||e),this},w.prototype.accept=function(e){return this.set("Accept",y.types[e]||e),this},w.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});const r=n.encoder?n.encoder:e=>{if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},w.prototype.query=function(e){return"string"!=typeof e&&(e=m(e)),e&&this._query.push(e),this},w.prototype.attach=function(e,t,n){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},w.prototype._getFormData=function(){return this._formData||(this._formData=new o.FormData),this._formData},w.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();const n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},w.prototype.crossDomainError=function(){const e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},w.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},w.prototype.ca=w.prototype.agent,w.prototype.buffer=w.prototype.ca,w.prototype.write=()=>{throw new Error("Streaming is not supported in browser version of superagent")},w.prototype.pipe=w.prototype.write,w.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},w.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||d,this._finalizeQueryString(),this._end()},w.prototype._setUploadTimeout=function(){const e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((()=>{e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},w.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));const e=this;this.xhr=y.getXHR();const t=this.xhr;let n=this._formData||this._data;this._setTimeouts(),t.addEventListener("readystatechange",(()=>{const n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4!==n)return;let r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}));const r=(t,n)=>{n.total>0&&(n.percent=n.loaded/n.total*100,100===n.percent&&clearTimeout(e._uploadTimeoutTimer)),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.addEventListener("progress",r.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",r.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof n&&!this._isHost(n)){const e=this._header["content-type"];let t=this._serializer||y.serialize[e?e.split(";")[0]:""];!t&&_(e)&&(t=y.serialize["application/json"]),t&&(n=t(n))}for(const e in this.header)null!==this.header[e]&&p(this.header,e)&&t.setRequestHeader(e,this.header[e]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===n?null:n)},y.agent=()=>new f;for(var O=0,P=["GET","POST","OPTIONS","PATCH","PUT","DELETE"];O{const r=y("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.head=(e,t,n)=>{const r=y("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.options=(e,t,n)=>{const r=y("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.del=E,y.delete=E,y.patch=(e,t,n)=>{const r=y("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.post=(e,t,n)=>{const r=y("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.put=(e,t,n)=>{const r=y("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}}(On,On.exports);var ki=On.exports;function Mi(e){var t=(new Date).getTime(),n=(new Date).toISOString(),r=console&&console.log?console:window&&window.console&&window.console.log?window.console:console;r.log("<<<<<"),r.log("[".concat(n,"]"),"\n",e.url,"\n",e.qs),r.log("-----"),e.on("response",(function(n){var o=(new Date).getTime()-t,i=(new Date).toISOString();r.log(">>>>>>"),r.log("[".concat(i," / ").concat(o,"]"),"\n",e.url,"\n",e.qs,"\n",n.text),r.log("-----")}))}function ji(e,t,n){var r=this;this._config.logVerbosity&&(e=e.use(Mi)),this._config.proxy&&this._modules.proxy&&(e=this._modules.proxy.call(this,e)),this._config.keepAlive&&this._modules.keepAlive&&(e=this._modules.keepAlive(e));var o=e;if(t.abortSignal)var i=t.abortSignal.subscribe((function(){o.abort(),i()}));return!0===t.forceBuffered?o="undefined"==typeof Blob?o.buffer().responseType("arraybuffer"):o.responseType("arraybuffer"):!1===t.forceBuffered&&(o=o.buffer(!1)),(o=o.timeout(t.timeout)).on("abort",(function(){return n({category:k.PNUnknownCategory,error:!0,operation:t.operation,errorData:new Error("Aborted")},null)})),o.end((function(e,o){var i,s={};if(s.error=null!==e,s.operation=t.operation,o&&o.status&&(s.statusCode=o.status),e){if(e.response&&e.response.text&&!r._config.logVerbosity)try{s.errorData=JSON.parse(e.response.text)}catch(t){s.errorData=e}else s.errorData=e;return s.category=r._detectErrorCategory(e),n(s,null)}if(t.ignoreBody)i={headers:o.headers,redirects:o.redirects,response:o};else try{i=JSON.parse(o.text)}catch(e){return s.errorData=o,s.error=!0,n(s,null)}return i.error&&1===i.error&&i.status&&i.message&&i.service?(s.errorData=i,s.statusCode=i.status,s.error=!0,s.category=r._detectErrorCategory(s),n(s,null)):(i.error&&i.error.message&&(s.errorData=i.error),n(s,i))})),o}function Ri(e,t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return r=ki.post(e),t.forEach((function(e){var t=e.key,n=e.value;r=r.field(t,n)})),r.attach("file",n,{contentType:"application/octet-stream"}),[4,r];case 1:return[2,o.sent()]}}))}))}function xi(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ui(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ii(e,t,n,r){var o=ki.post(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Di(e,t,n,r){var o=ki.patch(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Fi(e,t,n){var r=ki.delete(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Li(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}var Gi,Ki=function(){function e(){}return Object.defineProperty(e.prototype,"algo",{get:function(){return"aes-256-cbc"},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.encryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.encryptString(n,t)];throw new Error("Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer")}}))}))},e.prototype.decrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.decryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.decryptString(n,t)];throw new Error("Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer")}}))}))},e.prototype.encryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:if(t.data.byteLength<=0)throw new Error("encryption error. empty content");return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.encryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,mimeType:"application/octet-stream",data:s})]}}))}))},e.prototype.decryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.decryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,data:s})]}}))}))},e.prototype.getKey=function(t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return[4,crypto.subtle.digest("SHA-256",e.encoder.encode(t))];case 1:return n=i.sent(),r=Array.from(new Uint8Array(n)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),o=e.encoder.encode(r.slice(0,32)).buffer,[2,crypto.subtle.importKey("raw",o,"AES-CBC",!0,["encrypt","decrypt"])]}}))}))},e.prototype.encryptArrayBuffer=function(e,t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),r=Li,o=[n.buffer],[4,crypto.subtle.encrypt({name:"AES-CBC",iv:n},e,t)];case 1:return[2,r.apply(void 0,o.concat([i.sent()]))]}}))}))},e.prototype.decryptArrayBuffer=function(t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:if(r=n.slice(0,16),n.slice(e.IV_LENGTH).byteLength<=0)throw new Error("decryption error: empty content");return[4,crypto.subtle.decrypt({name:"AES-CBC",iv:r},t,n.slice(e.IV_LENGTH))];case 1:return[2,o.sent()]}}))}))},e.prototype.encryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=crypto.getRandomValues(new Uint8Array(16)),o=e.encoder.encode(n).buffer,[4,crypto.subtle.encrypt({name:"AES-CBC",iv:r},t,o)];case 1:return s=i.sent(),a=Li(r.buffer,s),[2,e.decoder.decode(a)]}}))}))},e.prototype.decryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=e.encoder.encode(n).buffer,o=r.slice(0,16),s=r.slice(16),[4,crypto.subtle.decrypt({name:"AES-CBC",iv:o},t,s)];case 1:return a=i.sent(),[2,e.decoder.decode(a)]}}))}))},e.IV_LENGTH=16,e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Bi=(Gi=function(){function e(e){if(e instanceof File)this.data=e,this.name=this.data.name,this.mimeType=this.data.type;else if(e.data){var t=e.data;this.data=new File([t],e.name,{type:e.mimeType}),this.name=e.name,e.mimeType&&(this.mimeType=e.mimeType)}if(void 0===this.data)throw new Error("Couldn't construct a file out of supplied options.");if(void 0===this.name)throw new Error("Couldn't guess filename out of the options. Please provide one.")}return e.create=function(e){return new this(e)},e.prototype.toBuffer=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toStream=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toFileUri=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in react native environments.")}))}))},e.prototype.toBlob=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e.prototype.toArrayBuffer=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if(r.result instanceof ArrayBuffer)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsArrayBuffer(e.data)}))]}))}))},e.prototype.toString=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if("string"==typeof r.result)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsBinaryString(e.data)}))]}))}))},e.prototype.toFile=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e}(),Gi.supportsFile="undefined"!=typeof File,Gi.supportsBlob="undefined"!=typeof Blob,Gi.supportsArrayBuffer="undefined"!=typeof ArrayBuffer,Gi.supportsBuffer=!1,Gi.supportsStream=!1,Gi.supportsString=!0,Gi.supportsEncryptFile=!0,Gi.supportsFileUri=!1,Gi),Hi=function(){function e(e){this.config=e,this.cryptor=new T({config:e}),this.fileCryptor=new Ki}return Object.defineProperty(e.prototype,"identifier",{get:function(){return""},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e){var t="string"==typeof e?e:(new TextDecoder).decode(e);return{data:this.cryptor.encrypt(t),metadata:null}},e.prototype.decrypt=function(e){var t="string"==typeof e.data?e.data:b(e.data);return this.cryptor.decrypt(t)},e.prototype.encryptFile=function(e,t){var n;return o(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)]}))}))},e.prototype.decryptFile=function(e,t){return o(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.fileCryptor.decryptFile(this.config.cipherKey,e,t)]}))}))},e}(),qi=function(){function e(e){this.cipherKey=e.cipherKey,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(this.cipherKey)}return Object.defineProperty(e.prototype,"algo",{get:function(){return"AES-CBC"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return"ACRH"},enumerable:!1,configurable:!0}),e.prototype.getIv=function(){return crypto.getRandomValues(new Uint8Array(e.BLOCK_SIZE))},e.prototype.getKey=function(){return o(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return t=e.encoder.encode(this.cipherKey),[4,crypto.subtle.digest("SHA-256",t.buffer)];case 1:return n=r.sent(),[2,crypto.subtle.importKey("raw",n,this.algo,!0,["encrypt","decrypt"])]}}))}))},e.prototype.encrypt=function(t){if(0===("string"==typeof t?t:e.decoder.decode(t)).length)throw new Error("encryption error. empty content");var n=this.getIv();return{metadata:n,data:m(this.CryptoJS.AES.encrypt(t,this.encryptedKey,{iv:this.bufferToWordArray(n),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}},e.prototype.decrypt=function(t){var n=this.bufferToWordArray(new Uint8ClampedArray(t.metadata)),r=this.bufferToWordArray(new Uint8ClampedArray(t.data));return e.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:r},this.encryptedKey,{iv:n,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer},e.prototype.encryptFileData=function(e){return o(this,void 0,void 0,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:return[4,this.getKey()];case 1:return t=o.sent(),n=this.getIv(),r={},[4,crypto.subtle.encrypt({name:this.algo,iv:n},t,e)];case 2:return[2,(r.data=o.sent(),r.metadata=n,r)]}}))}))},e.prototype.decryptFileData=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.getKey()];case 1:return t=n.sent(),[2,crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)]}}))}))},e.prototype.bufferToWordArray=function(e){var t,n=[];for(t=0;t0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("decryption error. empty content");return r.decrypt({data:t.slice(n.length),metadata:o})},e.prototype.encryptFile=function(e,t){return o(this,void 0,void 0,(function(){var n,r;return i(this,(function(o){switch(o.label){case 0:return this.defaultCryptor.identifier===Vi.LEGACY_IDENTIFIER?[2,this.defaultCryptor.encryptFile(e,t)]:[4,this.getFileData(e.data)];case 1:return n=o.sent(),[4,this.defaultCryptor.encryptFileData(n)];case 2:return r=o.sent(),[2,t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(r),r.data)})]}}))}))},e.prototype.decryptFile=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a,u,c,l,p;return i(this,(function(i){switch(i.label){case 0:return[4,t.data.arrayBuffer()];case 1:return r=i.sent(),o=Vi.tryParse(r),(null==(s=this.getCryptor(o))?void 0:s.identifier)===e.LEGACY_IDENTIFIER?[2,s.decryptFile(t,n)]:[4,this.getFileData(r)];case 2:return a=i.sent(),u=a.slice(o.length-o.metadataLength,o.length),l=(c=n).create,p={name:t.name},[4,this.defaultCryptor.decryptFileData({data:r.slice(o.length),metadata:u})];case 3:return[2,l.apply(c,[(p.data=i.sent(),p)])]}}))}))},e.prototype.getCryptor=function(e){if(""===e){var t=this.getAllCryptors().find((function(e){return""===e.identifier}));if(t)return t;throw new Error("unknown cryptor error")}if(e instanceof Wi)return this.getCryptorFromId(e.identifier)},e.prototype.getCryptorFromId=function(e){var t=this.getAllCryptors().find((function(t){return e===t.identifier}));if(t)return t;throw Error("unknown cryptor error")},e.prototype.concatArrayBuffer=function(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer},e.prototype.getHeaderData=function(e){if(e.metadata){var t=Vi.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length),r=0;return n.set(t.data,r),r+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),r),n.buffer}},e.prototype.getFileData=function(t){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return t instanceof Blob?[4,t.arrayBuffer()]:[3,2];case 1:return[2,n.sent()];case 2:if(t instanceof ArrayBuffer)return[2,t];if("string"==typeof t)return[2,e.encoder.encode(t)];throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}}))}))},e.LEGACY_IDENTIFIER="",e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Vi=function(){function e(){}return e.from=function(t,n){if(t!==e.LEGACY_IDENTIFIER)return new Wi(t,n.byteLength)},e.tryParse=function(t){var n=new Uint8Array(t),r="";if(n.byteLength>=4&&(r=n.slice(0,4),this.decoder.decode(r)!==e.SENTINEL))return"";if(!(n.byteLength>=5))throw new Error("decryption error. invalid header version");if(n[4]>e.MAX_VERSION)throw new Error("unknown cryptor error");var o="",i=5+e.IDENTIFIER_LENGTH;if(!(n.byteLength>=i))throw new Error("decryption error. invalid crypto identifier");o=n.slice(5,i);var s=null;if(!(n.byteLength>=i+1))throw new Error("decryption error. invalid metadata length");return s=n[i],i+=1,255===s&&n.byteLength>=i+2&&(s=new Uint16Array(n.slice(i,i+2)).reduce((function(e,t){return(e<<8)+t}),0),i+=2),new Wi(this.decoder.decode(o),s)},e.SENTINEL="PNED",e.LEGACY_IDENTIFIER="",e.IDENTIFIER_LENGTH=4,e.VERSION=1,e.MAX_VERSION=1,e.decoder=new TextDecoder,e}(),Wi=function(){function e(e,t){this._identifier=e,this._metadataLength=t}return Object.defineProperty(e.prototype,"identifier",{get:function(){return this._identifier},set:function(e){this._identifier=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"metadataLength",{get:function(){return this._metadataLength},set:function(e){this._metadataLength=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return Vi.VERSION},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return Vi.SENTINEL.length+1+Vi.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){var e=0,t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(Vi.SENTINEL)),t[e+=Vi.SENTINEL.length]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e),e+=Vi.IDENTIFIER_LENGTH;var r=this.metadataLength;return r<255?t[e]=r:t.set([255,r>>8,255&r],e),t},enumerable:!1,configurable:!0}),e.IDENTIFIER_LENGTH=4,e.SENTINEL="PNED",e}();function Ji(e){if(!navigator||!navigator.sendBeacon)return!1;navigator.sendBeacon(e)}var $i=function(e){function n(t){var n=this,r=t.listenToBrowserNetworkEvents,o=void 0===r||r;return t.sdkFamily="Web",t.networking=new _n({del:Fi,get:Ui,post:Ii,patch:Di,sendBeacon:Ji,getfile:xi,postfile:Ri}),t.cbor=new wn((function(e){return Sn(h.decode(e))}),m),t.PubNubFile=Bi,t.cryptography=new Ki,t.initCryptoModule=function(e){return new zi({default:new Hi({cipherKey:e.cipherKey,useRandomIVs:e.useRandomIVs}),cryptors:[new qi({cipherKey:e.cipherKey})]})},n=e.call(this,t)||this,o&&(window.addEventListener("offline",(function(){n.networkDownDetected()})),window.addEventListener("online",(function(){n.networkUpDetected()}))),n}return t(n,e),n.CryptoModule=zi,n}(vn);return $i})); +!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function o(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=o,r.VERSION=t,e.uuid=r,e.isUUID=o}(t),null!==e&&(e.exports=t.uuid)}(f,f.exports);var d=f.exports,y=function(){return d.uuid?d.uuid():d()},g=function(){function e(e){var t,n,r,o,i=e.setup;if(this._PNSDKSuffix={},this.instanceId="pn-".concat(y()),this.secretKey=i.secretKey||i.secret_key,this.subscribeKey=i.subscribeKey||i.subscribe_key,this.publishKey=i.publishKey||i.publish_key,this.sdkName=i.sdkName,this.sdkFamily=i.sdkFamily,this.partnerId=i.partnerId,this.setAuthKey(i.authKey),this.cryptoModule=i.cryptoModule,this.setFilterExpression(i.filterExpression),"string"!=typeof i.origin&&!Array.isArray(i.origin)&&void 0!==i.origin)throw new Error("Origin must be either undefined, a string or a list of strings.");if(this.origin=i.origin||Array.from({length:20},(function(e,t){return"ps".concat(t+1,".pndsn.com")})),this.secure=i.ssl||!1,this.restore=i.restore||!1,this.proxy=i.proxy,this.keepAlive=i.keepAlive,this.keepAliveSettings=i.keepAliveSettings,this.autoNetworkDetection=i.autoNetworkDetection||!1,this.dedupeOnSubscribe=i.dedupeOnSubscribe||!1,this.maximumCacheSize=i.maximumCacheSize||100,this.customEncrypt=i.customEncrypt,this.customDecrypt=i.customDecrypt,this.fileUploadPublishRetryLimit=null!==(t=i.fileUploadPublishRetryLimit)&&void 0!==t?t:5,this.useRandomIVs=null===(n=i.useRandomIVs)||void 0===n||n,this.enableEventEngine=null!==(r=i.enableEventEngine)&&void 0!==r&&r,this.maintainPresenceState=null===(o=i.maintainPresenceState)||void 0===o||o,"undefined"!=typeof location&&"https:"===location.protocol&&(this.secure=!0),this.logVerbosity=i.logVerbosity||!1,this.suppressLeaveEvents=i.suppressLeaveEvents||!1,this.announceFailedHeartbeats=i.announceFailedHeartbeats||!0,this.announceSuccessfulHeartbeats=i.announceSuccessfulHeartbeats||!1,this.useInstanceId=i.useInstanceId||!1,this.useRequestId=i.useRequestId||!1,this.requestMessageCountThreshold=i.requestMessageCountThreshold,i.retryConfiguration&&this._setRetryConfiguration(i.retryConfiguration),this.setTransactionTimeout(i.transactionalRequestTimeout||15e3),this.setSubscribeTimeout(i.subscribeRequestTimeout||31e4),this.setSendBeaconConfig(i.useSendBeacon||!0),i.presenceTimeout?this.setPresenceTimeout(i.presenceTimeout):this._presenceTimeout=300,null!=i.heartbeatInterval&&this.setHeartbeatInterval(i.heartbeatInterval),"string"==typeof i.userId){if("string"==typeof i.uuid)throw new Error("Only one of the following configuration options has to be provided: `uuid` or `userId`");this.setUserId(i.userId)}else{if("string"!=typeof i.uuid)throw new Error("One of the following configuration options has to be provided: `uuid` or `userId`");this.setUUID(i.uuid)}this.setCipherKey(i.cipherKey,i)}return e.prototype.getAuthKey=function(){return this.authKey},e.prototype.setAuthKey=function(e){return this.authKey=e,this},e.prototype.setCipherKey=function(e,t,n){var r;return this.cipherKey=e,this.cipherKey&&(this.cryptoModule=null!==(r=t.cryptoModule)&&void 0!==r?r:t.initCryptoModule({cipherKey:this.cipherKey,useRandomIVs:this.useRandomIVs}),n&&(n.cryptoModule=this.cryptoModule)),this},e.prototype.getUUID=function(){return this.UUID},e.prototype.setUUID=function(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing uuid parameter. Provide a valid string uuid");return this.UUID=e,this},e.prototype.getUserId=function(){return this.UUID},e.prototype.setUserId=function(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");return this.UUID=e,this},e.prototype.getFilterExpression=function(){return this.filterExpression},e.prototype.setFilterExpression=function(e){return this.filterExpression=e,this},e.prototype.getPresenceTimeout=function(){return this._presenceTimeout},e.prototype.setPresenceTimeout=function(e){return e>=20?this._presenceTimeout=e:(this._presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",this._presenceTimeout)),this.setHeartbeatInterval(this._presenceTimeout/2-1),this},e.prototype.setProxy=function(e){this.proxy=e},e.prototype.getHeartbeatInterval=function(){return this._heartbeatInterval},e.prototype.setHeartbeatInterval=function(e){return this._heartbeatInterval=e,this},e.prototype.getSubscribeTimeout=function(){return this._subscribeRequestTimeout},e.prototype.setSubscribeTimeout=function(e){return this._subscribeRequestTimeout=e,this},e.prototype.getTransactionTimeout=function(){return this._transactionalRequestTimeout},e.prototype.setTransactionTimeout=function(e){return this._transactionalRequestTimeout=e,this},e.prototype.isSendBeaconEnabled=function(){return this._useSendBeacon},e.prototype.setSendBeaconConfig=function(e){return this._useSendBeacon=e,this},e.prototype.getVersion=function(){return"7.6.1"},e.prototype._setRetryConfiguration=function(e){if(e.minimumdelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(e.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(e.maximumDelay&&maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6");if(e.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10");this.retryConfiguration=e},e.prototype._addPnsdkSuffix=function(e,t){this._PNSDKSuffix[e]=t},e.prototype._getPnsdkSuffix=function(e){var t=this;return Object.keys(this._PNSDKSuffix).reduce((function(n,r){return n+e+t._PNSDKSuffix[r]}),"")},e}();function m(e){var t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;function s(){var e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error("Illegal character at ".concat(i,": ").concat(t.charAt(i-1)));return n}for(var a=0;a>4,f=(15&c)<<4|l>>2,d=(3&l)<<6|p>>0;o[a]=h,64!=l&&(o[a+1]=f),64!=p&&(o[a+2]=d)}return r}function b(e){for(var t,n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=new Uint8Array(e),i=o.byteLength,s=i%3,a=i-s,u=0;u>18]+r[(258048&t)>>12]+r[(4032&t)>>6]+r[63&t];return 1==s?n+=r[(252&(t=o[a]))>>2]+r[(3&t)<<4]+"==":2==s&&(n+=r[(64512&(t=o[a]<<8|o[a+1]))>>10]+r[(1008&t)>>4]+r[(15&t)<<2]+"="),n}var v,_,S,w,O,P=P||function(e,t){var n={},r=n.lib={},o=function(){},i=r.Base={extend:function(e){o.prototype=this;var t=new o;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var o=0;o>>2]|=(n[o>>>2]>>>24-o%4*8&255)<<24-(r+o)%4*8;else if(65535>>2]=n[o>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r>>2]>>>24-r%4*8&255;n.push((o>>>4).toString(16)),n.push((15&o).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,a=o/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,o=e.min(4*t,o),t){for(var u=0;uc;){var l;e:{l=u;for(var p=e.sqrt(l),h=2;h<=p;h++)if(!(l%h)){l=!1;break e}l=!0}l&&(8>c&&(i[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var f=[];o=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],a=n[3],u=n[4],c=n[5],l=n[6],p=n[7],h=0;64>h;h++){if(16>h)f[h]=0|e[t+h];else{var d=f[h-15],y=f[h-2];f[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+f[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+f[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[h]+f[h],y=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=l,l=c,c=u,u=a+d|0,a=i,i=o,o=r,r=d+y|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+p|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(o),t.HmacSHA256=r._createHmacHelper(o)}(Math),_=(v=P).enc.Utf8,v.algo.HMAC=v.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=_.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,a=i.words,u=0;u>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;4>s&&o+.75*s>>6*(3-s)&63));if(t=r.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(r=n.charAt(64))&&-1!=(r=e.indexOf(r))&&(t=r);for(var r=[],o=0,i=0;i>>6-i%4*2;r[o>>>2]|=(s|a)<<24-o%4*8,o++}return w.create(r,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,r,o,i,s){return((e=e+(t&n|~t&r)+o+s)<>>32-i)+t}function n(e,t,n,r,o,i,s){return((e=e+(t&r|n&~r)+o+s)<>>32-i)+t}function r(e,t,n,r,o,i,s){return((e=e+(t^n^r)+o+s)<>>32-i)+t}function o(e,t,n,r,o,i,s){return((e=e+(n^(t|~r))+o+s)<>>32-i)+t}for(var i=P,s=(u=i.lib).WordArray,a=u.Hasher,u=i.algo,c=[],l=0;64>l;l++)c[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=a.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var s=0;16>s;s++){var a=e[u=i+s];e[u]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}s=this._hash.words;var u=e[i+0],l=(a=e[i+1],e[i+2]),p=e[i+3],h=e[i+4],f=e[i+5],d=e[i+6],y=e[i+7],g=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],_=e[i+12],S=e[i+13],w=e[i+14],O=e[i+15],P=t(P=s[0],T=s[1],A=s[2],E=s[3],u,7,c[0]),E=t(E,P,T,A,a,12,c[1]),A=t(A,E,P,T,l,17,c[2]),T=t(T,A,E,P,p,22,c[3]);P=t(P,T,A,E,h,7,c[4]),E=t(E,P,T,A,f,12,c[5]),A=t(A,E,P,T,d,17,c[6]),T=t(T,A,E,P,y,22,c[7]),P=t(P,T,A,E,g,7,c[8]),E=t(E,P,T,A,m,12,c[9]),A=t(A,E,P,T,b,17,c[10]),T=t(T,A,E,P,v,22,c[11]),P=t(P,T,A,E,_,7,c[12]),E=t(E,P,T,A,S,12,c[13]),A=t(A,E,P,T,w,17,c[14]),P=n(P,T=t(T,A,E,P,O,22,c[15]),A,E,a,5,c[16]),E=n(E,P,T,A,d,9,c[17]),A=n(A,E,P,T,v,14,c[18]),T=n(T,A,E,P,u,20,c[19]),P=n(P,T,A,E,f,5,c[20]),E=n(E,P,T,A,b,9,c[21]),A=n(A,E,P,T,O,14,c[22]),T=n(T,A,E,P,h,20,c[23]),P=n(P,T,A,E,m,5,c[24]),E=n(E,P,T,A,w,9,c[25]),A=n(A,E,P,T,p,14,c[26]),T=n(T,A,E,P,g,20,c[27]),P=n(P,T,A,E,S,5,c[28]),E=n(E,P,T,A,l,9,c[29]),A=n(A,E,P,T,y,14,c[30]),P=r(P,T=n(T,A,E,P,_,20,c[31]),A,E,f,4,c[32]),E=r(E,P,T,A,g,11,c[33]),A=r(A,E,P,T,v,16,c[34]),T=r(T,A,E,P,w,23,c[35]),P=r(P,T,A,E,a,4,c[36]),E=r(E,P,T,A,h,11,c[37]),A=r(A,E,P,T,y,16,c[38]),T=r(T,A,E,P,b,23,c[39]),P=r(P,T,A,E,S,4,c[40]),E=r(E,P,T,A,u,11,c[41]),A=r(A,E,P,T,p,16,c[42]),T=r(T,A,E,P,d,23,c[43]),P=r(P,T,A,E,m,4,c[44]),E=r(E,P,T,A,_,11,c[45]),A=r(A,E,P,T,O,16,c[46]),P=o(P,T=r(T,A,E,P,l,23,c[47]),A,E,u,6,c[48]),E=o(E,P,T,A,y,10,c[49]),A=o(A,E,P,T,w,15,c[50]),T=o(T,A,E,P,f,21,c[51]),P=o(P,T,A,E,_,6,c[52]),E=o(E,P,T,A,p,10,c[53]),A=o(A,E,P,T,b,15,c[54]),T=o(T,A,E,P,a,21,c[55]),P=o(P,T,A,E,g,6,c[56]),E=o(E,P,T,A,O,10,c[57]),A=o(A,E,P,T,d,15,c[58]),T=o(T,A,E,P,S,21,c[59]),P=o(P,T,A,E,h,6,c[60]),E=o(E,P,T,A,v,10,c[61]),A=o(A,E,P,T,l,15,c[62]),T=o(T,A,E,P,m,21,c[63]);s[0]=s[0]+P|0,s[1]=s[1]+T|0,s[2]=s[2]+A|0,s[3]=s[3]+E|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var i=e.floor(r/4294967296);for(n[15+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(o+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,r=0;4>r;r++)o=n[r],n[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(u),i.HmacMD5=a._createHmacHelper(u)}(Math),function(){var e,t=P,n=(e=t.lib).Base,r=e.WordArray,o=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),o=r.create(),i=o.words,s=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:u,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var p=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(u=(f.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return p.create({ciphertext:e,salt:n})}},t.SerializableCipher=n.extend({cfg:n.extend({format:u}),encrypt:function(e,t,n,r){r=this.cfg.extend(r);var o=e.createEncryptor(n,r);return t=o.finalize(t),o=o.cfg,p.create({ciphertext:t,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:r.format})},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),e.createDecryptor(n,r).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),f=(f.kdf={}).OpenSSL={execute:function(e,t,n,o){return o||(o=r.random(8)),e=s.create({keySize:t+n}).compute(e,o),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,p.create({key:e,iv:n,salt:o})}},d=t.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:f}),encrypt:function(e,t,n,r){return n=(r=this.cfg.extend(r)).kdf.execute(n,e.keySize,e.ivSize),r.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,r)).mixIn(n),e},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),n=r.kdf.execute(n,e.keySize,e.ivSize,t.salt),r.iv=n.iv,h.decrypt.call(this,e,t,n.key,r)}})}(),function(){for(var e=P,t=e.lib.BlockCipher,n=e.algo,r=[],o=[],i=[],s=[],a=[],u=[],c=[],l=[],p=[],h=[],f=[],d=0;256>d;d++)f[d]=128>d?d<<1:d<<1^283;var y=0,g=0;for(d=0;256>d;d++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;r[y]=m,o[m]=y;var b=f[y],v=f[b],_=f[v],S=257*f[m]^16843008*m;i[y]=S<<24|S>>>8,s[y]=S<<16|S>>>16,a[y]=S<<8|S>>>24,u[y]=S,S=16843009*_^65537*v^257*b^16843008*y,c[m]=S<<24|S>>>8,l[m]=S<<16|S>>>16,p[m]=S<<8|S>>>24,h[m]=S,y?(y=b^f[f[f[_^b]]],g^=f[f[g]]):y=g=1}var w=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),o=this._keySchedule=[],i=0;i>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s]):(s=r[(s=s<<8|s>>>24)>>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s],s^=w[i/t|0]<<24),o[i]=o[i-t]^s}for(e=this._invKeySchedule=[],t=0;tt||4>=i?s:c[r[s>>>24]]^l[r[s>>>16&255]]^p[r[s>>>8&255]]^h[r[255&s]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,s,a,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,c,l,p,h,o),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,r,o,i,s,a){for(var u=this._nRounds,c=e[t]^n[0],l=e[t+1]^n[1],p=e[t+2]^n[2],h=e[t+3]^n[3],f=4,d=1;d>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&h]^n[f++],g=r[l>>>24]^o[p>>>16&255]^i[h>>>8&255]^s[255&c]^n[f++],m=r[p>>>24]^o[h>>>16&255]^i[c>>>8&255]^s[255&l]^n[f++];h=r[h>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^n[f++],c=y,l=g,p=m}y=(a[c>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&h])^n[f++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[h>>>8&255]<<8|a[255&c])^n[f++],m=(a[p>>>24]<<24|a[h>>>16&255]<<16|a[c>>>8&255]<<8|a[255&l])^n[f++],h=(a[h>>>24]<<24|a[c>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^n[f++],e[t]=y,e[t+1]=g,e[t+2]=m,e[t+3]=h},keySize:8});e.AES=t._createHelper(n)}(),P.mode.ECB=((O=P.lib.BlockCipherMode.extend()).Encryptor=O.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),O.Decryptor=O.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),O);var E=P;function A(e){var t,n=[];for(t=0;t=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))},e.prototype.clearHistory=function(){this.hashHistory=[]},e}(),k={PNNetworkUpCategory:"PNNetworkUpCategory",PNNetworkDownCategory:"PNNetworkDownCategory",PNNetworkIssuesCategory:"PNNetworkIssuesCategory",PNTimeoutCategory:"PNTimeoutCategory",PNBadRequestCategory:"PNBadRequestCategory",PNAccessDeniedCategory:"PNAccessDeniedCategory",PNUnknownCategory:"PNUnknownCategory",PNReconnectedCategory:"PNReconnectedCategory",PNConnectedCategory:"PNConnectedCategory",PNRequestMessageCountExceededCategory:"PNRequestMessageCountExceededCategory",PNDisconnectedCategory:"PNDisconnectedCategory",PNConnectionErrorCategory:"PNConnectionErrorCategory",PNDisconnectedUnexpectedlyCategory:"PNDisconnectedUnexpectedlyCategory"},M=function(){function e(e){var t=e.subscribeEndpoint,n=e.leaveEndpoint,r=e.heartbeatEndpoint,o=e.setStateEndpoint,i=e.timeEndpoint,s=e.getFileUrl,a=e.config,u=e.crypto,c=e.listenerManager,l=e.cryptoModule,p=e.eventEmitter;this._listenerManager=c,this._config=a,this._leaveEndpoint=n,this._heartbeatEndpoint=r,this._setStateEndpoint=o,this._subscribeEndpoint=t,this._getFileUrl=s,this._crypto=u,this._cryptoModule=l,this._channels={},this._presenceChannels={},this._heartbeatChannels={},this._heartbeatChannelGroups={},this._channelGroups={},this._presenceChannelGroups={},this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[],this._currentTimetoken=0,this._lastTimetoken=0,this._storedTimetoken=null,this._subscriptionStatusAnnounced=!1,this._isOnline=!0,this._reconnectionManager=new N({timeEndpoint:i}),this._dedupingManager=new C({config:a}),this._cryptoModule&&(this._decoder=new TextDecoder),this._eventEmitter=p}return e.prototype.adaptStateChange=function(e,t){var n=this,r=e.state,o=e.channels,i=void 0===o?[]:o,s=e.channelGroups,a=void 0===s?[]:s,u=e.withHeartbeat,c=void 0!==u&&u;if(i.forEach((function(e){e in n._channels&&(n._channels[e].state=r)})),a.forEach((function(e){e in n._channelGroups&&(n._channelGroups[e].state=r)})),c){var l={};return i.forEach((function(e){return l[e]=r})),a.forEach((function(e){return l[e]=r})),this._heartbeatEndpoint({channels:i,channelGroups:a,state:l},t)}return this._setStateEndpoint({state:r,channels:i,channelGroups:a},t)},e.prototype.adaptPresenceChange=function(e){var t=this,n=e.connected,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i;n?(o.forEach((function(e){t._heartbeatChannels[e]={state:{}}})),s.forEach((function(e){t._heartbeatChannelGroups[e]={state:{}}}))):(o.forEach((function(e){e in t._heartbeatChannels&&delete t._heartbeatChannels[e]})),s.forEach((function(e){e in t._heartbeatChannelGroups&&delete t._heartbeatChannelGroups[e]})),!1===this._config.suppressLeaveEvents&&this._leaveEndpoint({channels:o,channelGroups:s},(function(e){t._listenerManager.announceStatus(e)}))),this.reconnect()},e.prototype.adaptSubscribeChange=function(e){var t=this,n=e.timetoken,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=e.withPresence,u=void 0!==a&&a,c=e.withHeartbeats,l=void 0!==c&&c;this._config.subscribeKey&&""!==this._config.subscribeKey?(n&&(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=n),"0"!==this._currentTimetoken&&0!==this._currentTimetoken&&(this._storedTimetoken=this._currentTimetoken,this._currentTimetoken=0),o.forEach((function(e){t._channels[e]={state:{}},u&&(t._presenceChannels[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannels[e]={}),t._pendingChannelSubscriptions.push(e)})),s.forEach((function(e){t._channelGroups[e]={state:{}},u&&(t._presenceChannelGroups[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannelGroups[e]={}),t._pendingChannelGroupSubscriptions.push(e)})),this._subscriptionStatusAnnounced=!1,this.reconnect()):console&&console.log&&console.log("subscribe key missing; aborting subscribe")},e.prototype.adaptUnsubscribeChange=function(e,t){var n=this,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=[],u=[];o.forEach((function(e){e in n._channels&&(delete n._channels[e],a.push(e),e in n._heartbeatChannels&&delete n._heartbeatChannels[e]),e in n._presenceChannels&&(delete n._presenceChannels[e],a.push(e))})),s.forEach((function(e){e in n._channelGroups&&(delete n._channelGroups[e],u.push(e),e in n._heartbeatChannelGroups&&delete n._heartbeatChannelGroups[e]),e in n._presenceChannelGroups&&(delete n._presenceChannelGroups[e],u.push(e))})),0===a.length&&0===u.length||(!1!==this._config.suppressLeaveEvents||t||this._leaveEndpoint({channels:a,channelGroups:u},(function(e){e.affectedChannels=a,e.affectedChannelGroups=u,e.currentTimetoken=n._currentTimetoken,e.lastTimetoken=n._lastTimetoken,n._listenerManager.announceStatus(e)})),0===Object.keys(this._channels).length&&0===Object.keys(this._presenceChannels).length&&0===Object.keys(this._channelGroups).length&&0===Object.keys(this._presenceChannelGroups).length&&(this._lastTimetoken=0,this._currentTimetoken=0,this._storedTimetoken=null,this._region=null,this._reconnectionManager.stopPolling()),this.reconnect())},e.prototype.unsubscribeAll=function(e){this.adaptUnsubscribeChange({channels:this.getSubscribedChannels(),channelGroups:this.getSubscribedChannelGroups()},e)},e.prototype.getHeartbeatChannels=function(){return Object.keys(this._heartbeatChannels)},e.prototype.getHeartbeatChannelGroups=function(){return Object.keys(this._heartbeatChannelGroups)},e.prototype.getSubscribedChannels=function(){return Object.keys(this._channels)},e.prototype.getSubscribedChannelGroups=function(){return Object.keys(this._channelGroups)},e.prototype.reconnect=function(){this._startSubscribeLoop(),this._registerHeartbeatTimer()},e.prototype.disconnect=function(){this._stopSubscribeLoop(),this._stopHeartbeatTimer(),this._reconnectionManager.stopPolling()},e.prototype._registerHeartbeatTimer=function(){this._stopHeartbeatTimer(),0!==this._config.getHeartbeatInterval()&&void 0!==this._config.getHeartbeatInterval()&&(this._performHeartbeatLoop(),this._heartbeatTimer=setInterval(this._performHeartbeatLoop.bind(this),1e3*this._config.getHeartbeatInterval()))},e.prototype._stopHeartbeatTimer=function(){this._heartbeatTimer&&(clearInterval(this._heartbeatTimer),this._heartbeatTimer=null)},e.prototype._performHeartbeatLoop=function(){var e=this,t=this.getHeartbeatChannels(),n=this.getHeartbeatChannelGroups(),r={};if(0!==t.length||0!==n.length){this.getSubscribedChannels().forEach((function(t){var n=e._channels[t].state;Object.keys(n).length&&(r[t]=n)})),this.getSubscribedChannelGroups().forEach((function(t){var n=e._channelGroups[t].state;Object.keys(n).length&&(r[t]=n)}));this._heartbeatEndpoint({channels:t,channelGroups:n,state:r},function(t){t.error&&e._config.announceFailedHeartbeats&&e._listenerManager.announceStatus(t),t.error&&e._config.autoNetworkDetection&&e._isOnline&&(e._isOnline=!1,e.disconnect(),e._listenerManager.announceNetworkDown(),e.reconnect()),!t.error&&e._config.announceSuccessfulHeartbeats&&e._listenerManager.announceStatus(t)}.bind(this))}},e.prototype._startSubscribeLoop=function(){var e=this;this._stopSubscribeLoop();var t={},n=[],r=[];if(Object.keys(this._channels).forEach((function(r){var o=e._channels[r].state;Object.keys(o).length&&(t[r]=o),n.push(r)})),Object.keys(this._presenceChannels).forEach((function(e){n.push("".concat(e,"-pnpres"))})),Object.keys(this._channelGroups).forEach((function(n){var o=e._channelGroups[n].state;Object.keys(o).length&&(t[n]=o),r.push(n)})),Object.keys(this._presenceChannelGroups).forEach((function(e){r.push("".concat(e,"-pnpres"))})),0!==n.length||0!==r.length){var o={channels:n,channelGroups:r,state:t,timetoken:this._currentTimetoken,filterExpression:this._config.filterExpression,region:this._region};this._subscribeCall=this._subscribeEndpoint(o,this._processSubscribeResponse.bind(this))}},e.prototype._processSubscribeResponse=function(e,t){var n=this;if(e.error){if(e.errorData&&"Aborted"===e.errorData.message)return;e.category===k.PNTimeoutCategory?this._startSubscribeLoop():e.category===k.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this._config.autoNetworkDetection&&this._isOnline&&(this._isOnline=!1,this._listenerManager.announceNetworkDown()),this._reconnectionManager.onReconnection((function(){n._config.autoNetworkDetection&&!n._isOnline&&(n._isOnline=!0,n._listenerManager.announceNetworkUp()),n.reconnect(),n._subscriptionStatusAnnounced=!0;var t={category:k.PNReconnectedCategory,operation:e.operation,lastTimetoken:n._lastTimetoken,currentTimetoken:n._currentTimetoken};n._listenerManager.announceStatus(t)})),this._reconnectionManager.startPolling(),this._listenerManager.announceStatus(e)):e.category===k.PNBadRequestCategory?(this._stopHeartbeatTimer(),this._listenerManager.announceStatus(e)):this._listenerManager.announceStatus(e)}else{if(this._storedTimetoken?(this._currentTimetoken=this._storedTimetoken,this._storedTimetoken=null):(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=t.metadata.timetoken),!this._subscriptionStatusAnnounced){var r={};r.category=k.PNConnectedCategory,r.operation=e.operation,r.affectedChannels=this._pendingChannelSubscriptions,r.subscribedChannels=this.getSubscribedChannels(),r.affectedChannelGroups=this._pendingChannelGroupSubscriptions,r.lastTimetoken=this._lastTimetoken,r.currentTimetoken=this._currentTimetoken,this._subscriptionStatusAnnounced=!0,this._listenerManager.announceStatus(r),this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[]}var o=t.messages||[],i=this._config,s=i.requestMessageCountThreshold,a=i.dedupeOnSubscribe;if(s&&o.length>=s){var u={};u.category=k.PNRequestMessageCountExceededCategory,u.operation=e.operation,this._listenerManager.announceStatus(u)}o.forEach((function(e){if(e.channel,e.subscriptionMatch,a){if(n._dedupingManager.isDuplicate(e))return;n._dedupingManager.addEntry(e)}n._eventEmitter.emitEvent(e)})),this._region=t.metadata.region,this._startSubscribeLoop()}},e.prototype._stopSubscribeLoop=function(){this._subscribeCall&&("function"==typeof this._subscribeCall.abort&&this._subscribeCall.abort(),this._subscribeCall=null)},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),j={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",PNAccessManagerRevokeToken:"PNAccessManagerRevokeToken",PNHandshakeOperation:"PNHandshakeOperation",PNReceiveMessagesOperation:"PNReceiveMessagesOperation"},R=function(){function e(e){this._maximumSamplesCount=100,this._trackedLatencies={},this._latencies={},this._telemetryExcludeOperations=[j.PNSubscribeOperation,j.PNReceiveMessagesOperation,j.PNHandshakeOperation],this._maximumSamplesCount=e.maximumSamplesCount||this._maximumSamplesCount}return e.prototype.operationsLatencyForRequest=function(){var e=this,t={};return Object.keys(this._latencies).forEach((function(n){var r=e._latencies[n],o=e._averageLatency(r);o>0&&(t["l_".concat(n)]=o)})),t},e.prototype.startLatencyMeasure=function(e,t){!this._telemetryExcludeOperations.includes(e)&&t&&(this._trackedLatencies[t]=Date.now())},e.prototype.stopLatencyMeasure=function(e,t){if(!this._telemetryExcludeOperations.includes(e)&&t){var n=this._endpointName(e),r=this._latencies[n],o=this._trackedLatencies[t];r||(this._latencies[n]=[],r=this._latencies[n]),r.push(Date.now()-o),r.length>this._maximumSamplesCount&&r.splice(0,r.length-this._maximumSamplesCount),delete this._trackedLatencies[t]}},e.prototype._averageLatency=function(e){return Math.floor(e.reduce((function(e,t){return e+t}),0)/e.length)},e.prototype._endpointName=function(e){var t=null;switch(e){case j.PNPublishOperation:t="pub";break;case j.PNSignalOperation:t="sig";break;case j.PNHistoryOperation:case j.PNFetchMessagesOperation:case j.PNDeleteMessagesOperation:case j.PNMessageCounts:t="hist";break;case j.PNUnsubscribeOperation:case j.PNWhereNowOperation:case j.PNHereNowOperation:case j.PNHeartbeatOperation:case j.PNSetStateOperation:case j.PNGetStateOperation:t="pres";break;case j.PNAddChannelsToGroupOperation:case j.PNRemoveChannelsFromGroupOperation:case j.PNChannelGroupsOperation:case j.PNRemoveGroupOperation:case j.PNChannelsForGroupOperation:t="cg";break;case j.PNPushNotificationEnabledChannelsOperation:case j.PNRemoveAllPushNotificationsOperation:t="push";break;case j.PNCreateUserOperation:case j.PNUpdateUserOperation:case j.PNDeleteUserOperation:case j.PNGetUserOperation:case j.PNGetUsersOperation:case j.PNCreateSpaceOperation:case j.PNUpdateSpaceOperation:case j.PNDeleteSpaceOperation:case j.PNGetSpaceOperation:case j.PNGetSpacesOperation:case j.PNGetMembersOperation:case j.PNUpdateMembersOperation:case j.PNGetMembershipsOperation:case j.PNUpdateMembershipsOperation:t="obj";break;case j.PNAddMessageActionOperation:case j.PNRemoveMessageActionOperation:case j.PNGetMessageActionsOperation:t="msga";break;case j.PNAccessManagerGrant:case j.PNAccessManagerAudit:t="pam";break;case j.PNAccessManagerGrantToken:case j.PNAccessManagerRevokeToken:t="pamv3";break;default:t="time"}return t},e}(),x=function(){function e(e,t,n){this._payload=e,this._setDefaultPayloadStructure(),this.title=t,this.body=n}return Object.defineProperty(e.prototype,"payload",{get:function(){return this._payload},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{set:function(e){this._title=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{set:function(e){this._subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{set:function(e){this._body=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{set:function(e){this._badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{set:function(e){this._sound=e},enumerable:!1,configurable:!0}),e.prototype._setDefaultPayloadStructure=function(){},e.prototype.toObject=function(){return{}},e}(),U=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"configurations",{set:function(e){e&&e.length&&(this._configurations=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"notification",{get:function(){return this._payload.aps},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.aps.alert.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){e&&e.length&&(this._payload.aps.alert.subtitle=e,this._subtitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.aps.alert.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this._badge},set:function(e){null!=e&&(this._payload.aps.badge=e,this._badge=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.aps.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),r.prototype._setDefaultPayloadStructure=function(){this._payload.aps={alert:{}}},r.prototype.toObject=function(){var e=this,t=n({},this._payload),r=t.aps,o=r.alert;if(this._isSilent&&(r["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");var i=[];this._configurations.forEach((function(t){i.push(e._objectFromAPNS2Configuration(t))})),i.length&&(t.pn_push=i)}return o&&Object.keys(o).length||delete r.alert,this._isSilent&&(delete r.alert,delete r.badge,delete r.sound,o={}),this._isSilent||Object.keys(o).length?t:null},r.prototype._objectFromAPNS2Configuration=function(e){var t=this;if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");var n=[];e.targets.forEach((function(e){n.push(t._objectFromAPNSTarget(e))}));var r=e.collapseId,o=e.expirationDate,i={auth_method:"token",targets:n,version:"v2"};return r&&r.length&&(i.collapse_id=r),o&&(i.expiration=o.toISOString()),i},r.prototype._objectFromAPNSTarget=function(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");var t=e.topic,n=e.environment,r=void 0===n?"development":n,o=e.excludedDevices,i=void 0===o?[]:o,s={topic:t,environment:r};return i.length&&(s.excluded_devices=i),s},r}(x),I=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"backContent",{get:function(){return this._backContent},set:function(e){e&&e.length&&(this._payload.back_content=e,this._backContent=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"backTitle",{get:function(){return this._backTitle},set:function(e){e&&e.length&&(this._payload.back_title=e,this._backTitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"count",{get:function(){return this._count},set:function(e){null!=e&&(this._payload.count=e,this._count=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"type",{get:function(){return this._type},set:function(e){e&&e.length&&(this._payload.type=e,this._type=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this.backTitle},set:function(e){this.backTitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this.backContent},set:function(e){this.backContent=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this.count},set:function(e){this.count=e},enumerable:!1,configurable:!0}),r.prototype.toObject=function(){return Object.keys(this._payload).length?n({},this._payload):null},r}(x),D=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return t(o,e),Object.defineProperty(o.prototype,"notification",{get:function(){return this._payload.notification},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"data",{get:function(){return this._payload.data},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.notification.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.notification.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.notification.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"icon",{get:function(){return this._icon},set:function(e){e&&e.length&&(this._payload.notification.icon=e,this._icon=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"tag",{get:function(){return this._tag},set:function(e){e&&e.length&&(this._payload.notification.tag=e,this._tag=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),o.prototype._setDefaultPayloadStructure=function(){this._payload.notification={},this._payload.data={}},o.prototype.toObject=function(){var e=n({},this._payload.data),t=null,o={};if(Object.keys(this._payload).length>2){var i=this._payload;i.notification,i.data;var s=r(i,["notification","data"]);e=n(n({},e),s)}return this._isSilent?e.notification=this._payload.notification:t=this._payload.notification,Object.keys(e).length&&(o.data=e),t&&Object.keys(t).length&&(o.notification=t),Object.keys(o).length?o:null},o}(x),F=function(){function e(e,t){this._payload={apns:{},mpns:{},fcm:{}},this._title=e,this._body=t,this.apns=new U(this._payload.apns,e,t),this.mpns=new I(this._payload.mpns,e,t),this.fcm=new D(this._payload.fcm,e,t)}return Object.defineProperty(e.prototype,"debugging",{set:function(e){this._debugging=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this._body},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){this._subtitle=e,this.apns.subtitle=e,this.mpns.subtitle=e,this.fcm.subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{get:function(){return this._badge},set:function(e){this._badge=e,this.apns.badge=e,this.mpns.badge=e,this.fcm.badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{get:function(){return this._sound},set:function(e){this._sound=e,this.apns.sound=e,this.mpns.sound=e,this.fcm.sound=e},enumerable:!1,configurable:!0}),e.prototype.buildPayload=function(e){var t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";var n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("mpns")){var r=this.mpns.toObject();r&&Object.keys(r).length&&(t.pn_mpns=r)}if(e.includes("fcm")){var o=this.fcm.toObject();o&&Object.keys(o).length&&(t.pn_gcm=o)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t},e}(),L=function(){function e(){this._listeners=[]}return e.prototype.addListener=function(e){this._listeners.includes(e)||this._listeners.push(e)},e.prototype.removeListener=function(e){var t=[];this._listeners.forEach((function(n){n!==e&&t.push(n)})),this._listeners=t},e.prototype.removeAllListeners=function(){this._listeners=[]},e.prototype.announcePresence=function(e){this._listeners.forEach((function(t){t.presence&&t.presence(e)}))},e.prototype.announceStatus=function(e){this._listeners.forEach((function(t){t.status&&t.status(e)}))},e.prototype.announceMessage=function(e){this._listeners.forEach((function(t){t.message&&t.message(e)}))},e.prototype.announceSignal=function(e){this._listeners.forEach((function(t){t.signal&&t.signal(e)}))},e.prototype.announceMessageAction=function(e){this._listeners.forEach((function(t){t.messageAction&&t.messageAction(e)}))},e.prototype.announceFile=function(e){this._listeners.forEach((function(t){t.file&&t.file(e)}))},e.prototype.announceObjects=function(e){this._listeners.forEach((function(t){t.objects&&t.objects(e)}))},e.prototype.announceUser=function(e){this._listeners.forEach((function(t){t.user&&t.user(e)}))},e.prototype.announceSpace=function(e){this._listeners.forEach((function(t){t.space&&t.space(e)}))},e.prototype.announceMembership=function(e){this._listeners.forEach((function(t){t.membership&&t.membership(e)}))},e.prototype.announceNetworkUp=function(){var e={};e.category=k.PNNetworkUpCategory,this.announceStatus(e)},e.prototype.announceNetworkDown=function(){var e={};e.category=k.PNNetworkDownCategory,this.announceStatus(e)},e}(),G=function(){function e(e,t){this._config=e,this._cbor=t}return e.prototype.setToken=function(e){e&&e.length>0?this._token=e:this._token=void 0},e.prototype.getToken=function(){return this._token},e.prototype.extractPermissions=function(e){var t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128==(128&e)&&(t.join=!0),64==(64&e)&&(t.update=!0),32==(32&e)&&(t.get=!0),8==(8&e)&&(t.delete=!0),4==(4&e)&&(t.manage=!0),2==(2&e)&&(t.write=!0),1==(1&e)&&(t.read=!0),t},e.prototype.parseToken=function(e){var t=this,n=this._cbor.decodeToken(e);if(void 0!==n){var r=n.res.uuid?Object.keys(n.res.uuid):[],o=Object.keys(n.res.chan),i=Object.keys(n.res.grp),s=n.pat.uuid?Object.keys(n.pat.uuid):[],a=Object.keys(n.pat.chan),u=Object.keys(n.pat.grp),c={version:n.v,timestamp:n.t,ttl:n.ttl,authorized_uuid:n.uuid},l=r.length>0,p=o.length>0,h=i.length>0;(l||p||h)&&(c.resources={},l&&(c.resources.uuids={},r.forEach((function(e){c.resources.uuids[e]=t.extractPermissions(n.res.uuid[e])}))),p&&(c.resources.channels={},o.forEach((function(e){c.resources.channels[e]=t.extractPermissions(n.res.chan[e])}))),h&&(c.resources.groups={},i.forEach((function(e){c.resources.groups[e]=t.extractPermissions(n.res.grp[e])}))));var f=s.length>0,d=a.length>0,y=u.length>0;return(f||d||y)&&(c.patterns={},f&&(c.patterns.uuids={},s.forEach((function(e){c.patterns.uuids[e]=t.extractPermissions(n.pat.uuid[e])}))),d&&(c.patterns.channels={},a.forEach((function(e){c.patterns.channels[e]=t.extractPermissions(n.pat.chan[e])}))),y&&(c.patterns.groups={},u.forEach((function(e){c.patterns.groups[e]=t.extractPermissions(n.pat.grp[e])})))),Object.keys(n.meta).length>0&&(c.meta=n.meta),c.signature=n.sig,c}},e}();function K(e){return encodeURIComponent(e).replace(/[!~*'()]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())}))}function B(e){return function(e){var t=[];return Object.keys(e).forEach((function(e){return t.push(e)})),t}(e).sort()}var H={signPamFromParams:function(e){return B(e).map((function(t){return"".concat(t,"=").concat(K(e[t]))})).join("&")},endsWith:function(e,t){return-1!==e.indexOf(t,this.length-t.length)},createPromise:function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),reject:t,fulfill:e}},encodeString:K,stringToArrayBuffer:function(e){for(var t=new ArrayBuffer(2*e.length),n=new Uint16Array(t),r=0,o=e.length;r0&&(t+=n),t}function J(e,t,n){return t.usePost&&t.usePost(e,n)?"POST":t.usePatch&&t.usePatch(e,n)?"PATCH":t.useDelete&&t.useDelete(e,n)?"DELETE":t.useGetFile&&t.useGetFile(e,n)?"GETFILE":"GET"}function $(e,t,n,r,o){var i=e.config,s=e.crypto,a=J(e,o,r);n.timestamp=Math.floor((new Date).getTime()/1e3),"PNPublishOperation"===o.getOperation()&&o.usePost&&o.usePost(e,r)&&(a="GET"),"GETFILE"===a&&(a="GET");var u="".concat(a,"\n").concat(i.publishKey,"\n").concat(t,"\n").concat(H.signPamFromParams(n),"\n");if("POST"===a)u+="string"==typeof(c=o.postPayload(e,r))?c:JSON.stringify(c);else if("PATCH"===a){var c;u+="string"==typeof(c=o.patchPayload(e,r))?c:JSON.stringify(c)}var l="v2.".concat(s.HMACSHA256(u));l=(l=(l=l.replace(/\+/g,"-")).replace(/\//g,"_")).replace(/=+$/,""),n.signature=l}function Q(e,t){for(var r=[],o=2;o0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/leave")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(){return{}}});var ae=Object.freeze({__proto__:null,getOperation:function(){return j.PNWhereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r;return"/v2/presence/sub-key/".concat(n.subscribeKey,"/uuid/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return t.payload?{channels:t.payload.channels}:{channels:[]}}});var ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNHeartbeatOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/heartbeat")},isAuthSupported:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o=t.state,i=e.config,s={};return r.length>0&&(s["channel-group"]=r.join(",")),o&&(s.state=JSON.stringify(o)),s.heartbeat=i.getPresenceTimeout(),s},handleResponse:function(){return{}}});var ce=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetStateOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r,i=t.channels,s=void 0===i?[]:i,a=s.length>0?s.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(a),"/uuid/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a={};return 1===o.length&&0===s.length?a[o[0]]=t.payload:a=t.payload,{channels:a}}});var le=Object.freeze({__proto__:null,getOperation:function(){return j.PNSetStateOperation},validateParams:function(e,t){var n=e.config,r=t.state,o=t.channels,i=void 0===o?[]:o,s=t.channelGroups,a=void 0===s?[]:s;return r?n.subscribeKey?0===i.length&&0===a.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key":"Missing State"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/uuid/").concat(H.encodeString(n.UUID),"/data")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.state,r=t.channelGroups,o=void 0===r?[]:r,i={};return i.state=JSON.stringify(n),o.length>0&&(i["channel-group"]=o.join(",")),i},handleResponse:function(e,t){return{state:t.payload}}});var pe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=t.channelGroups,s=void 0===i?[]:i,a="/v2/presence/sub-key/".concat(n.subscribeKey);if(o.length>0||s.length>0){var u=o.length>0?o.join(","):",";a+="/channel/".concat(H.encodeString(u))}return a},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.channelGroups,o=void 0===r?[]:r,i=t.includeUUIDs,s=void 0===i||i,a=t.includeState,u=void 0!==a&&a,c=t.queryParameters,l=void 0===c?{}:c,p={};return s||(p.disable_uuids=1),u&&(p.state=1),o.length>0&&(p["channel-group"]=o.join(",")),p=n(n({},p),l)},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a=n.includeUUIDs,u=void 0===a||a,c=n.includeState,l=void 0!==c&&c;return o.length>1||s.length>0||0===s.length&&0===o.length?function(){var e={};return e.totalChannels=t.payload.total_channels,e.totalOccupancy=t.payload.total_occupancy,e.channels={},Object.keys(t.payload.channels).forEach((function(n){var r=t.payload.channels[n],o=[];return e.channels[n]={occupants:o,name:n,occupancy:r.occupancy},u&&r.uuids.forEach((function(e){l?o.push({state:e.state,uuid:e.uuid}):o.push({state:null,uuid:e})})),e})),e}():function(){var e={},n=[];return e.totalChannels=1,e.totalOccupancy=t.occupancy,e.channels={},e.channels[o[0]]={occupants:n,name:o[0],occupancy:t.occupancy},u&&t.uuids&&t.uuids.forEach((function(e){l?n.push({state:e.state,uuid:e.uuid}):n.push({state:null,uuid:e})})),e}()},handleError:function(e,t,n){402!==n.statusCode||this.getURL(e,t).includes("channel")||(n.errorData.message="You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.")}});var he=Object.freeze({__proto__:null,getOperation:function(){return j.PNAddMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.action,o=t.channel;return t.messageTimetoken?n.subscribeKey?o?r?r.value?r.type?r.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message channel":"Missing Subscribe Key":"Missing message timetoken"},usePost:function(){return!0},postURL:function(e,t){var n=e.config,r=t.channel,o=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},getRequestHeaders:function(){return{"Content-Type":"application/json"}},isAuthSupported:function(){return!0},prepareParams:function(){return{}},postPayload:function(e,t){return t.action},handleResponse:function(e,t){return{data:t.data}}});var fe=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken;return t.messageTimetoken?o?n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key":"Missing action timetoken":"Missing message timetoken"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken,i=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(i,"/action/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{data:t.data}}});var de=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetMessageActionsOperation},validateParams:function(e,t){var n=e.config,r=t.channel;return n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channel;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.limit,r=t.start,o=t.end,i={};return n&&(i.limit=n),r&&(i.start=r),o&&(i.end=o),i},handleResponse:function(e,t){var n={data:t.data,start:null,end:null};return n.data.length&&(n.end=n.data[n.data.length-1].actionTimetoken,n.start=n.data[0].actionTimetoken),n}}),ye={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel can't be empty"},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.limit&&(n.limit=t.limit),t.next&&(n.next=t.next),n},handleResponse:function(e,t){return{status:t.status,data:t.data,next:t.next,count:t.count}}},ge={getOperation:function(){return j.PNGenerateUploadUrlOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?void 0:"name can't be empty":"channel can't be empty"},usePost:function(){return!0},postURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/generate-upload-url")},postPayload:function(e,t){return{name:t.name}},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data,file_upload_request:t.file_upload_request}}},me={getOperation:function(){return j.PNPublishFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.fileId)?(null==t?void 0:t.fileName)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},getURL:function(e,t){var n=e.config,r=n.publishKey,o=n.subscribeKey,i=function(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}(e,{message:t.message,file:{name:t.fileName,id:t.fileId}});return"/v1/files/publish-file/".concat(r,"/").concat(o,"/0/").concat(H.encodeString(t.channel),"/0/").concat(H.encodeString(i))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.ttl&&(n.ttl=t.ttl),void 0!==t.storeInHistory&&(n.store=t.storeInHistory?"1":"0"),t.meta&&"object"==typeof t.meta&&(n.meta=JSON.stringify(t.meta)),n},handleResponse:function(e,t){return{timetoken:t[2]}}},be=function(e){var t=function(e){var t=this,n=e.generateUploadUrl,r=e.publishFile,s=e.modules,a=s.PubNubFile,u=s.config,c=s.cryptography,l=s.cryptoModule,p=s.networking;return function(e){var s=e.channel,h=e.file,f=e.message,d=e.cipherKey,y=e.meta,g=e.ttl,m=e.storeInHistory;return o(t,void 0,void 0,(function(){var e,t,o,b,v,_,S,w,O,P,E,A,T,N,C,k,M,j,R,x,U,I,D,F,L,G,K,B,H;return i(this,(function(i){switch(i.label){case 0:if(!s)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!h)throw new q("Validation failed, check status for details",z("file can't be empty"));return e=a.create(h),[4,n({channel:s,name:e.name})];case 1:return t=i.sent(),o=t.file_upload_request,b=o.url,v=o.form_fields,_=t.data,S=_.id,w=_.name,a.supportsEncryptFile&&(d||l)?null!=d?[3,3]:[4,l.encryptFile(e,a)]:[3,6];case 2:return O=i.sent(),[3,5];case 3:return[4,c.encryptFile(d,e,a)];case 4:O=i.sent(),i.label=5;case 5:e=O,i.label=6;case 6:P=v,e.mimeType&&(P=v.map((function(t){return"Content-Type"===t.key?{key:t.key,value:e.mimeType}:t}))),i.label=7;case 7:return i.trys.push([7,21,,22]),a.supportsFileUri&&h.uri?(T=(A=p).POSTFILE,N=[b,P],[4,e.toFileUri()]):[3,10];case 8:return[4,T.apply(A,N.concat([i.sent()]))];case 9:return E=i.sent(),[3,20];case 10:return a.supportsFile?(k=(C=p).POSTFILE,M=[b,P],[4,e.toFile()]):[3,13];case 11:return[4,k.apply(C,M.concat([i.sent()]))];case 12:return E=i.sent(),[3,20];case 13:return a.supportsBuffer?(R=(j=p).POSTFILE,x=[b,P],[4,e.toBuffer()]):[3,16];case 14:return[4,R.apply(j,x.concat([i.sent()]))];case 15:return E=i.sent(),[3,20];case 16:return a.supportsBlob?(I=(U=p).POSTFILE,D=[b,P],[4,e.toBlob()]):[3,19];case 17:return[4,I.apply(U,D.concat([i.sent()]))];case 18:return E=i.sent(),[3,20];case 19:throw new Error("Unsupported environment");case 20:return[3,22];case 21:throw(F=i.sent()).response&&"string"==typeof F.response.text?(L=F.response.text,G=/(.*)<\/Message>/gi.exec(L),new q(G?"Upload to bucket failed: ".concat(G[1]):"Upload to bucket failed.",F)):new q("Upload to bucket failed.",F);case 22:if(204!==E.status)throw new q("Upload to bucket was unsuccessful",E);K=u.fileUploadPublishRetryLimit,B=!1,H={timetoken:"0"},i.label=23;case 23:return i.trys.push([23,25,,26]),[4,r({channel:s,message:f,fileId:S,fileName:w,meta:y,storeInHistory:m,ttl:g})];case 24:return H=i.sent(),B=!0,[3,26];case 25:return i.sent(),K-=1,[3,26];case 26:if(!B&&K>0)return[3,23];i.label=27;case 27:if(B)return[2,{timetoken:H.timetoken,id:S,name:w}];throw new q("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{channel:s,id:S,name:w})}}))}))}}(e);return function(e,n){var r=t(e);return"function"==typeof n?(r.then((function(e){return n(null,e)})).catch((function(e){return n(e,null)})),r):r}},ve=function(e,t){var n=t.channel,r=t.id,o=t.name,i=e.config,s=e.networking,a=e.tokenManager;if(!n)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!r)throw new q("Validation failed, check status for details",z("file id can't be empty"));if(!o)throw new q("Validation failed, check status for details",z("file name can't be empty"));var u="/v1/files/".concat(i.subscribeKey,"/channels/").concat(H.encodeString(n),"/files/").concat(r,"/").concat(o),c={};c.uuid=i.getUUID(),c.pnsdk=W(i);var l=a.getToken()||i.getAuthKey();l&&(c.auth=l),i.secretKey&&$(e,u,c,{},{getOperation:function(){return"PubNubGetFileUrlOperation"}});var p=Object.keys(c).map((function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(c[e]))})).join("&");return""!==p?"".concat(s.getStandardOrigin()).concat(u,"?").concat(p):"".concat(s.getStandardOrigin()).concat(u)},_e={getOperation:function(){return j.PNDownloadFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?(null==t?void 0:t.id)?void 0:"id can't be empty":"name can't be empty":"channel can't be empty"},useGetFile:function(){return!0},getFileURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},ignoreBody:function(){return!0},forceBuffered:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t,n){var r=e.PubNubFile,s=e.config,a=e.cryptography,u=e.cryptoModule;return o(void 0,void 0,void 0,(function(){var e,o,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.response.body,r.supportsEncryptFile&&(n.cipherKey||u)?null!=n.cipherKey?[3,2]:[4,u.decryptFile(r.create({data:e,name:n.name}),r)]:[3,5];case 1:return o=i.sent().data,[3,4];case 2:return[4,a.decrypt(null!==(c=n.cipherKey)&&void 0!==c?c:s.cipherKey,e)];case 3:o=i.sent(),i.label=4;case 4:e=o,i.label=5;case 5:return[2,r.create({data:e,name:null!==(l=t.response.name)&&void 0!==l?l:n.name,mimeType:t.response.type})]}}))}))}},Se={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.id)?(null==t?void 0:t.name)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status}}},we={getOperation:function(){return j.PNGetAllUUIDMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,next:t.next,prev:t.prev}}},Oe={getOperation:function(){return j.PNGetUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Pe={getOperation:function(){return j.PNSetUUIDMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.data))return"Data cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ee={getOperation:function(){return j.PNRemoveUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r=e.config;return{uuid:null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ae={getOperation:function(){return j.PNGetAllChannelMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Te={getOperation:function(){return j.PNGetChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ne={getOperation:function(){return j.PNSetChannelMetadataOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.data)?void 0:"Data cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ce={getOperation:function(){return j.PNRemoveChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},ke={getOperation:function(){return j.PNGetMembersOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&m.include.push("uuid"),(null===(i=t.include)||void 0===i?void 0:i.customUUIDFields)&&m.include.push("uuid.custom"),(null===(s=t.include)||void 0===s?void 0:s.UUIDStatusField)&&m.include.push("uuid.status"),(null===(u=t.include)||void 0===u?void 0:u.UUIDTypeField)&&m.include.push("uuid.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Me={getOperation:function(){return j.PNSetMembersOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.uuids)&&0!==(null==t?void 0:t.uuids.length)?void 0:"UUIDs cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.uuids.map((function(e){return"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["uuid.status","uuid.type","type"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customUUIDFields)&&h.include.push("uuid.custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&h.include.push("uuid")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},je={getOperation:function(){return j.PNGetMembershipsOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&m.include.push("channel"),(null===(i=t.include)||void 0===i?void 0:i.customChannelFields)&&m.include.push("channel.custom"),(null===(s=t.include)||void 0===s?void 0:s.channelStatusField)&&m.include.push("channel.status"),(null===(u=t.include)||void 0===u?void 0:u.channelTypeField)&&m.include.push("channel.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Re={getOperation:function(){return j.PNSetMembershipsOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)||0===(null==t?void 0:t.channels.length))return"Channels cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.channels.map((function(e){return"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["channel.status","channel.type","status"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customChannelFields)&&h.include.push("channel.custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&h.include.push("channel")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}};var xe=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerAudit},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/audit/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channel,r=t.channelGroup,o=t.authKeys,i=void 0===o?[]:o,s={};return n&&(s.channel=n),r&&(s["channel-group"]=r),i.length>0&&(s.auth=i.join(",")),s},handleResponse:function(e,t){return t.payload}});var Ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrant},validateParams:function(e,t){var n=e.config;return n.subscribeKey?n.publishKey?n.secretKey?null==t.uuids||t.authKeys?null==t.uuids||null==t.channels&&null==t.channelGroups?void 0:"Both channel/channelgroup and uuid cannot be used in the same request":"authKeys are required for grant request on uuids":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/grant/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.uuids,a=void 0===s?[]:s,u=t.ttl,c=t.read,l=void 0!==c&&c,p=t.write,h=void 0!==p&&p,f=t.manage,d=void 0!==f&&f,y=t.get,g=void 0!==y&&y,m=t.join,b=void 0!==m&&m,v=t.update,_=void 0!==v&&v,S=t.authKeys,w=void 0===S?[]:S,O=t.delete,P={};return P.r=l?"1":"0",P.w=h?"1":"0",P.m=d?"1":"0",P.d=O?"1":"0",P.g=g?"1":"0",P.j=b?"1":"0",P.u=_?"1":"0",r.length>0&&(P.channel=r.join(",")),i.length>0&&(P["channel-group"]=i.join(",")),w.length>0&&(P.auth=w.join(",")),a.length>0&&(P["target-uuid"]=a.join(",")),(u||0===u)&&(P.ttl=u),P},handleResponse:function(){return{}}});function Ie(e){var t,n,r,o,i=void 0!==(null==e?void 0:e.authorizedUserId),s=void 0!==(null===(t=null==e?void 0:e.resources)||void 0===t?void 0:t.users),a=void 0!==(null===(n=null==e?void 0:e.resources)||void 0===n?void 0:n.spaces),u=void 0!==(null===(r=null==e?void 0:e.patterns)||void 0===r?void 0:r.users),c=void 0!==(null===(o=null==e?void 0:e.patterns)||void 0===o?void 0:o.spaces);return u||s||c||a||i}function De(e){var t=0;return e.join&&(t|=128),e.update&&(t|=64),e.get&&(t|=32),e.delete&&(t|=8),e.manage&&(t|=4),e.write&&(t|=2),e.read&&(t|=1),t}function Fe(e,t){if(Ie(t))return function(e,t){var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorizedUserId,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.users,c=r.spaces,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.users,h=o.spaces,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}(0,t);var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorized_uuid,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.uuids,c=r.channels,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.uuids,h=o.channels,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}var Le=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrantToken},extractPermissions:De,validateParams:function(e,t){var n,r,o,i,s,a,u=e.config;if(!u.subscribeKey)return"Missing Subscribe Key";if(!u.publishKey)return"Missing Publish Key";if(!u.secretKey)return"Missing Secret Key";if(!t.resources&&!t.patterns)return"Missing either Resources or Patterns.";var c=void 0!==(null==t?void 0:t.authorized_uuid),l=void 0!==(null===(n=null==t?void 0:t.resources)||void 0===n?void 0:n.uuids),p=void 0!==(null===(r=null==t?void 0:t.resources)||void 0===r?void 0:r.channels),h=void 0!==(null===(o=null==t?void 0:t.resources)||void 0===o?void 0:o.groups),f=void 0!==(null===(i=null==t?void 0:t.patterns)||void 0===i?void 0:i.uuids),d=void 0!==(null===(s=null==t?void 0:t.patterns)||void 0===s?void 0:s.channels),y=void 0!==(null===(a=null==t?void 0:t.patterns)||void 0===a?void 0:a.groups),g=c||l||f||p||d||h||y;return Ie(t)&&g?"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`":(!t.resources||t.resources.uuids&&0!==Object.keys(t.resources.uuids).length||t.resources.channels&&0!==Object.keys(t.resources.channels).length||t.resources.groups&&0!==Object.keys(t.resources.groups).length||t.resources.users&&0!==Object.keys(t.resources.users).length||t.resources.spaces&&0!==Object.keys(t.resources.spaces).length)&&(!t.patterns||t.patterns.uuids&&0!==Object.keys(t.patterns.uuids).length||t.patterns.channels&&0!==Object.keys(t.patterns.channels).length||t.patterns.groups&&0!==Object.keys(t.patterns.groups).length||t.patterns.users&&0!==Object.keys(t.patterns.users).length||t.patterns.spaces&&0!==Object.keys(t.patterns.spaces).length)?void 0:"Missing values for either Resources or Patterns."},postURL:function(e){var t=e.config;return"/v3/pam/".concat(t.subscribeKey,"/grant")},usePost:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(){return{}},postPayload:function(e,t){return Fe(0,t)},handleResponse:function(e,t){return t.data.token}}),Ge={getOperation:function(){return j.PNAccessManagerRevokeToken},validateParams:function(e,t){return e.config.secretKey?t?void 0:"token can't be empty":"Missing Secret Key"},getURL:function(e,t){var n=e.config;return"/v3/pam/".concat(n.subscribeKey,"/grant/").concat(H.encodeString(t))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e){return{uuid:e.config.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}};function Ke(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}var Be=Object.freeze({__proto__:null,getOperation:function(){return j.PNPublishOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},usePost:function(e,t){var n=t.sendByPost;return void 0!==n&&n},getURL:function(e,t){var n=e.config,r=t.channel,o=Ke(e,t.message);return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0/").concat(H.encodeString(o))},postURL:function(e,t){var n=e.config,r=t.channel;return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},postPayload:function(e,t){return Ke(e,t.message)},prepareParams:function(e,t){var n=t.meta,r=t.replicate,o=void 0===r||r,i=t.storeInHistory,s=t.ttl,a={};return null!=i&&(a.store=i?"1":"0"),s&&(a.ttl=s),!1===o&&(a.norep="true"),n&&"object"==typeof n&&(a.meta=JSON.stringify(n)),a},handleResponse:function(e,t){return{timetoken:t[2]}}});var He=Object.freeze({__proto__:null,getOperation:function(){return j.PNSignalOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},getURL:function(e,t){var n,r=e.config,o=t.channel,i=t.message,s=(n=i,JSON.stringify(n));return"/signal/".concat(r.publishKey,"/").concat(r.subscribeKey,"/0/").concat(H.encodeString(o),"/0/").concat(H.encodeString(s))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{timetoken:t[2]}}});var qe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHistoryOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channel,r=e.config;return"/v2/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o=t.reverse,i=t.count,s=void 0===i?100:i,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p={include_token:"true"};return p.count=s,n&&(p.start=n),r&&(p.end=r),u&&(p.string_message_token="true"),null!=o&&(p.reverse=o.toString()),l&&(p.include_meta="true"),p},handleResponse:function(e,t){var n={messages:[],startTimeToken:t[1],endTimeToken:t[2]};return Array.isArray(t[0])&&t[0].forEach((function(t){var r=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message),o={timetoken:t.timetoken,entry:r.payload};t.meta&&(o.meta=t.meta),r.error&&(o.error=r.error),n.messages.push(o)})),n}});var ze=Object.freeze({__proto__:null,getOperation:function(){return j.PNDeleteMessagesOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},useDelete:function(){return!0},getURL:function(e,t){var n=t.channel,r=e.config;return"/v3/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o={};return n&&(o.start=n),r&&(o.end=r),o},handleResponse:function(e,t){return t.payload}});var Ve=Object.freeze({__proto__:null,getOperation:function(){return j.PNMessageCounts},validateParams:function(e,t){var n=t.channels,r=t.timetoken,o=t.channelTimetokens,i=e.config;return n?r&&o?"timetoken and channelTimetokens are incompatible together":o&&o.length>1&&n.length!==o.length?"Length of channelTimetokens and channels do not match":i.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channels,r=e.config,o=n.join(",");return"/v3/history/sub-key/".concat(r.subscribeKey,"/message-counts/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.timetoken,r=t.channelTimetokens,o={};if(r&&1===r.length){var i=a(r,1)[0];o.timetoken=i}else r?o.channelsTimetoken=r.join(","):n&&(o.timetoken=n);return o},handleResponse:function(e,t){return{channels:t.channels}}});var We=Object.freeze({__proto__:null,getOperation:function(){return j.PNFetchMessagesOperation},validateParams:function(e,t){var n=t.channels,r=t.includeMessageActions,o=void 0!==r&&r,i=e.config;if(!n||0===n.length)return"Missing channels";if(!i.subscribeKey)return"Missing Subscribe Key";if(o&&n.length>1)throw new TypeError("History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.")},getURL:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.includeMessageActions,i=void 0!==o&&o,s=e.config,a=i?"history-with-actions":"history",u=r.length>0?r.join(","):",";return"/v3/".concat(a,"/sub-key/").concat(s.subscribeKey,"/channel/").concat(H.encodeString(u))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channels,r=t.start,o=t.end,i=t.includeMessageActions,s=t.count,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p=t.includeUuid,h=t.includeUUID,f=void 0===h||h,d=t.includeMessageType,y=void 0===d||d,g={};return g.max=s||(n.length>1||!0===i?25:100),r&&(g.start=r),o&&(g.end=o),u&&(g.string_message_token="true"),l&&(g.include_meta="true"),f&&!1!==p&&(g.include_uuid="true"),y&&(g.include_message_type="true"),g},handleResponse:function(e,t){var n={channels:{}};return Object.keys(t.channels||{}).forEach((function(r){n.channels[r]=[],(t.channels[r]||[]).forEach((function(t){var o={},i=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message);o.channel=r,o.timetoken=t.timetoken,o.message=i.payload,o.messageType=t.message_type,o.uuid=t.uuid,t.actions&&(o.actions=t.actions,o.data=t.actions),t.meta&&(o.meta=t.meta),i.error&&(o.error=i.error),n.channels[r].push(o)}))})),t.more&&(n.more=t.more),n}});var Je=Object.freeze({__proto__:null,getOperation:function(){return j.PNTimeOperation},getURL:function(){return"/time/0"},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(){return{}},isAuthSupported:function(){return!1},handleResponse:function(e,t){return{timetoken:t[0]}},validateParams:function(){}});var $e=Object.freeze({__proto__:null,getOperation:function(){return j.PNSubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=e.config,r=t.state,o=t.channelGroups,i=void 0===o?[]:o,s=t.timetoken,a=t.filterExpression,u=t.region,c={heartbeat:n.getPresenceTimeout()};return i.length>0&&(c["channel-group"]=i.join(",")),a&&a.length>0&&(c["filter-expr"]=a),Object.keys(r).length&&(c.state=JSON.stringify(r)),s&&(c.tt=s),u&&(c.tr=u),c},handleResponse:function(e,t){var n=[];t.m.forEach((function(e){var t={timetoken:e.p.t,region:e.p.r},r={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:t};n.push(r)}));var r={timetoken:t.t.t,region:t.t.r};return{messages:n,metadata:r}}}),Qe={getOperation:function(){return j.PNHandshakeOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)&&!(null==t?void 0:t.channelGroups))return"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),n.tt=0,t.state&&(n.state=JSON.stringify(t.state)),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.ee="",n},handleResponse:function(e,t){return{region:t.t.r,timetoken:t.t.t}}},Xe={getOperation:function(){return j.PNReceiveMessagesOperation},validateParams:function(e,t){return(null==t?void 0:t.channels)||(null==t?void 0:t.channelGroups)?(null==t?void 0:t.timetoken)?(null==t?void 0:t.region)?void 0:"region can not be empty":"timetoken can not be empty":"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},getAbortSignal:function(e,t){return t.abortSignal},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.tt=t.timetoken,n.tr=t.region,n.ee="",n},handleResponse:function(e,t){var n=[];return t.m.forEach((function(e){var t={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:{timetoken:e.p.t,region:e.p.r}};n.push(t)})),{messages:n,metadata:{region:t.t.r,timetoken:t.t.t}}}},Ye=function(){function e(e){void 0===e&&(e=!1),this.sync=e,this.listeners=new Set}return e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.notify=function(e){var t=this,n=function(){t.listeners.forEach((function(t){t(e)}))};this.sync?n():setTimeout(n,0)},e}(),Ze=function(){function e(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}return e.prototype.transition=function(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)},e.prototype.on=function(e,t){return this.transitionMap.set(e,t),this},e.prototype.with=function(e,t){return[this,e,null!=t?t:[]]},e.prototype.onEnter=function(e){return this.enterEffects.push(e),this},e.prototype.onExit=function(e){return this.exitEffects.push(e),this},e}(),et=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return t(n,e),n.prototype.describe=function(e){return new Ze(e)},n.prototype.start=function(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})},n.prototype.transition=function(e){var t,n,r,o,i,u;if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});var c=this.currentState.transition(this.currentContext,e);if(c){var l=a(c,3),p=l[0],h=l[1],f=l[2];try{for(var d=s(this.currentState.exitEffects),y=d.next();!y.done;y=d.next()){var g=y.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}var m=this.currentState;this.currentState=p;var b=this.currentContext;this.currentContext=h,this.notify({type:"transitionDone",fromState:m,fromContext:b,toState:p,toContext:h,event:e});try{for(var v=s(f),_=v.next();!_.done;_=v.next()){g=_.value;this.notify({type:"invocationDispatched",invocation:g})}}catch(e){r={error:e}}finally{try{_&&!_.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var S=s(this.currentState.enterEffects),w=S.next();!w.done;w=S.next()){g=w.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){i={error:e}}finally{try{w&&!w.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}},n}(Ye),tt=function(){function e(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}return e.prototype.on=function(e,t){this.handlers.set(e,t)},e.prototype.dispatch=function(e){if("CANCEL"!==e.type){var t=this.handlers.get(e.type);if(!t)throw new Error("Unhandled invocation '".concat(e.type,"'"));var n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}else if(this.instances.has(e.payload)){var r=this.instances.get(e.payload);null==r||r.cancel(),this.instances.delete(e.payload)}},e.prototype.dispose=function(){var e,t;try{for(var n=s(this.instances.entries()),r=n.next();!r.done;r=n.next()){var o=a(r.value,2),i=o[0];o[1].cancel(),this.instances.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();function nt(e,t){var n=function(){for(var n=[],r=0;r0&&r(e),[2]}))}))}))),s.on(ht.type,ut((function(e,t,n){var r=n.emitStatus;return o(s,void 0,void 0,(function(){return i(this,(function(t){return r(e),[2]}))}))}))),s.on(ft.type,ut((function(e,n,r){var a=r.receiveMessages,u=r.delay,c=r.config;return o(s,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return c.retryConfiguration&&c.retryConfiguration.shouldRetry(e.reason,e.attempts)?(n.throwIfAborted(),[4,u(c.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),n.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,a({abortSignal:n,channels:e.channels,channelGroups:e.groups,timetoken:e.cursor.timetoken,region:e.cursor.region,filterExpression:c.filterExpression})];case 3:return r=i.sent(),[2,t.transition(Pt(r.metadata,r.messages))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Et(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(At(new q(c.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s.on(dt.type,ut((function(e,r,a){var u=a.handshake,c=a.delay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({abortSignal:r,channels:e.channels,channelGroups:e.groups,filterExpression:p.filterExpression},p.maintainPresenceState&&{state:l}))];case 3:return o=i.sent(),[2,t.transition(vt(o))];case 4:return(s=i.sent())instanceof Error&&"Aborted"===s.message?[2]:s instanceof q?[2,t.transition(_t(s))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(St(new q(p.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s}return t(r,e),r}(tt),Mt=new Ze("HANDSHAKE_FAILED");Mt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Mt.on(Nt.type,(function(e,t){return Ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor})})),Mt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(r=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==r?r:0}})})),Mt.on(Ct.type,(function(e){return Lt.with()}));var jt=new Ze("HANDSHAKE_STOPPED");jt.on(yt.type,(function(e,t){return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),jt.on(Nt.type,(function(e,t){return Ft.with(n(n({},e),{cursor:t.payload.cursor||e.cursor}))})),jt.on(gt.type,(function(e,t){var n;return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),jt.on(Ct.type,(function(e){return Lt.with()}));var Rt=new Ze("RECEIVE_FAILED");Rt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Rt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(Ct.type,(function(e){return Lt.with(void 0)}));var xt=new Ze("RECEIVE_STOPPED");xt.on(yt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),xt.on(gt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Ct.type,(function(){return Lt.with(void 0)}));var Ut=new Ze("RECEIVE_RECONNECTING");Ut.onEnter((function(e){return ft(e)})),Ut.onExit((function(){return ft.cancel})),Ut.on(Pt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),Ut.on(Et.type,(function(e,t){return Ut.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Ut.on(At.type,(function(e,t){var n;return Rt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Ut.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),Ut.on(gt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Ut.on(yt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ut.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var It=new Ze("RECEIVING");It.onEnter((function(e){return lt(e.channels,e.groups,e.cursor)})),It.onExit((function(){return lt.cancel})),It.on(wt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),It.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups})})),It.on(gt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),It.on(Ot.type,(function(e,t){return Ut.with(n(n({},e),{attempts:0,reason:t.payload}))})),It.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),It.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var Dt=new Ze("HANDSHAKE_RECONNECTING");Dt.onEnter((function(e){return dt(e)})),Dt.onExit((function(){return dt.cancel})),Dt.on(vt.type,(function(e,t){var n,r,o={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=e.cursor)||void 0===r?void 0:r.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return It.with({channels:e.channels,groups:e.groups,cursor:o},[ht({category:k.PNConnectedCategory})])})),Dt.on(_t.type,(function(e,t){return Dt.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Dt.on(St.type,(function(e,t){var n;return Mt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Dt.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Dt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Dt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.region)||0}})})),Dt.on(Ct.type,(function(e){return Lt.with(void 0)}));var Ft=new Ze("HANDSHAKING");Ft.onEnter((function(e){return ct(e.channels,e.groups)})),Ft.onExit((function(){return ct.cancel})),Ft.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ft.on(mt.type,(function(e,t){var n,r;return It.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.timetoken:t.payload.timetoken,region:t.payload.region}},[ht({category:k.PNConnectedCategory})])})),Ft.on(bt.type,(function(e,t){return Dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload})})),Ft.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Ft.on(gt.type,(function(e,t){var n;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),Ft.on(Ct.type,(function(e){return Lt.with()}));var Lt=new Ze("UNSUBSCRIBED");Lt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups})})),Lt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})}));var Gt=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new kt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(Lt,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e){var t=this,n=e.channels,r=e.channelGroups,o=e.timetoken,i=e.withPresence;this.channels=u(u([],a(this.channels),!1),a(null!=n?n:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=r?r:[]),!1),i&&(this.channels.map((function(e){return t.channels.push("".concat(e,"-pnpres"))})),this.groups.map((function(e){return t.groups.push("".concat(e,"-pnpres"))}))),o?this.engine.transition(gt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))),o)):this.engine.transition(yt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((function(e){return!e.endsWith("-pnpres")})))),groups:Array.from(new Set(this.groups.filter((function(e){return!e.endsWith("-pnpres")}))))})},e.prototype.unsubscribe=function(e){var t=this,n=e.channels,r=void 0===n?[]:n,o=e.channelGroups,i=void 0===o?[]:o,s=H.removeSingleOccurance(this.channels,u(u([],a(r),!1),a(r.map((function(e){return"".concat(e,"-pnpres")}))),!1)),c=H.removeSingleOccurance(this.groups,u(u([],a(i),!1),a(i.map((function(e){return"".concat(e,"-pnpres")}))),!1));if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(c).size){var l=H.findUniqueCommonElements(this.channels,r),p=H.findUniqueCommonElements(this.groups,i);this.dependencies.presenceState&&(null==l||l.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==p||p.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.channels=s,this.groups=c,this.engine.transition(yt(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:l.slice(0),groups:p.slice(0)})}},e.prototype.unsubscribeAll=function(){this.channels=[],this.groups=[],this.dependencies.presenceState&&(this.dependencies.presenceState={}),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.reconnect=function(e){var t=e.timetoken,n=e.region;this.engine.transition(Nt(t,n))},e.prototype.disconnect=function(){this.engine.transition(Tt()),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.getSubscribedChannels=function(){return Array.from(new Set(this.channels))},e.prototype.getSubscribedChannelGroups=function(){return Array.from(new Set(this.groups))},e.prototype.dispose=function(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),Kt=nt("RECONNECT",(function(){return{}})),Bt=nt("DISCONNECT",(function(){return{}})),Ht=nt("JOINED",(function(e,t){return{channels:e,groups:t}})),qt=nt("LEFT",(function(e,t){return{channels:e,groups:t}})),zt=nt("LEFT_ALL",(function(){return{}})),Vt=nt("HEARTBEAT_SUCCESS",(function(e){return{statusCode:e}})),Wt=nt("HEARTBEAT_FAILURE",(function(e){return e})),Jt=nt("HEARTBEAT_GIVEUP",(function(){return{}})),$t=nt("TIMES_UP",(function(){return{}})),Qt=rt("HEARTBEAT",(function(e,t){return{channels:e,groups:t}})),Xt=rt("LEAVE",(function(e,t){return{channels:e,groups:t}})),Yt=rt("EMIT_STATUS",(function(e){return e})),Zt=ot("WAIT",(function(){return{}})),en=ot("DELAYED_HEARTBEAT",(function(e){return e})),tn=function(e){function r(t,r){var s=e.call(this,r)||this;return s.on(Qt.type,ut((function(e,r,a){var u=a.heartbeat,c=a.presenceState,l=a.config;return o(s,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,u(n({channels:e.channels,channelGroups:e.groups},l.maintainPresenceState&&{state:c}))];case 1:return o.sent(),t.transition(Vt(200)),[3,3];case 2:return(r=o.sent())instanceof q?[2,t.transition(Wt(r))]:[3,3];case 3:return[2]}}))}))}))),s.on(Xt.type,ut((function(e,t,n){var r=n.leave,a=n.config;return o(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:if(a.suppressLeaveEvents)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r({channels:e.channels,channelGroups:e.groups})];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}}))}))}))),s.on(Zt.type,ut((function(e,n,r){var a=r.heartbeatDelay;return o(s,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return n.throwIfAborted(),[4,a()];case 1:return e.sent(),n.throwIfAborted(),[2,t.transition($t())]}}))}))}))),s.on(en.type,ut((function(e,r,a){var u=a.heartbeat,c=a.retryDelay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({channels:e.channels,channelGroups:e.groups},p.maintainPresenceState&&{state:l}))];case 3:return i.sent(),[2,t.transition(Vt(200))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Wt(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Jt())];case 7:return[2]}}))}))}))),s.on(Yt.type,ut((function(e,t,r){var a=r.emitStatus,u=r.config;return o(s,void 0,void 0,(function(){var t;return i(this,(function(r){return u.announceFailedHeartbeats&&!0===(null===(t=null==e?void 0:e.status)||void 0===t?void 0:t.error)?a(e.status):u.announceSuccessfulHeartbeats&&200===e.statusCode&&a(n(n({},e),{operation:j.PNHeartbeatOperation,error:!1})),[2]}))}))}))),s}return t(r,e),r}(tt),nn=new Ze("HEARTBEAT_STOPPED");nn.on(Ht.type,(function(e,t){return nn.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),nn.on(qt.type,(function(e,t){return nn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))})})),nn.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),nn.on(zt.type,(function(e,t){return un.with(void 0)}));var rn=new Ze("HEARTBEAT_COOLDOWN");rn.onEnter((function(){return Zt()})),rn.onExit((function(){return Zt.cancel})),rn.on($t.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),rn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),rn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),rn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),rn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var on=new Ze("HEARTBEAT_FAILED");on.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),on.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),on.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),on.on(Bt.type,(function(e,t){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),on.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var sn=new Ze("HEARBEAT_RECONNECTING");sn.onEnter((function(e){return en(e)})),sn.onExit((function(){return en.cancel})),sn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),sn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),sn.on(Bt.type,(function(e,t){nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),sn.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),sn.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),sn.on(Jt.type,(function(e,t){return on.with({channels:e.channels,groups:e.groups})})),sn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var an=new Ze("HEARTBEATING");an.onEnter((function(e){return Qt(e.channels,e.groups)})),an.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),an.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),an.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),an.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:0,reason:t.payload}))})),an.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),an.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var un=new Ze("HEARTBEAT_INACTIVE");un.on(Ht.type,(function(e,t){return an.with({channels:t.payload.channels,groups:t.payload.groups})}));var cn=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dispatcher=new tn(this.engine,e),this.dependencies=e,this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(un,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.join=function(e){var t=e.channels,n=e.groups;this.channels=u(u([],a(this.channels),!1),a(null!=t?t:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=n?n:[]),!1),this.engine.transition(Ht(this.channels.slice(0),this.groups.slice(0)))},e.prototype.leave=function(e){var t=this,n=e.channels,r=e.groups;this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(qt(null!=n?n:[],null!=r?r:[]))},e.prototype.leaveAll=function(){this.engine.transition(zt())},e.prototype.dispose=function(){this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),ln=function(){function e(){}return e.LinearRetryPolicy=function(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e.ExponentialRetryPolicy=function(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e}(),pn=function(){function e(e){var t=e.modules,n=e.listenerManager,r=e.getFileUrl;this.modules=t,this.listenerManager=n,this.getFileUrl=r,this._channelListenerMap=new Map,this._groupListenerMap=new Map,t.cryptoModule&&(this._decoder=new TextDecoder)}return e.prototype.emitEvent=function(e){var t=e.channel,o=e.publishMetaData,i=e.subscriptionMatch;if(t===i&&(i=null),e.channel.endsWith("-pnpres")){var s={channel:null,subscription:null};t&&(s.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(s.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),s.action=e.payload.action,s.state=e.payload.data,s.timetoken=o.timetoken,s.occupancy=e.payload.occupancy,s.uuid=e.payload.uuid,s.timestamp=e.payload.timestamp,e.payload.join&&(s.join=e.payload.join),e.payload.leave&&(s.leave=e.payload.leave),e.payload.timeout&&(s.timeout=e.payload.timeout),s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announcePresence(s),this._announce("presence",s,s.channel,s.subscription)}else if(1===e.messageType){(s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=e.payload,this.listenerManager.announceSignal(s),this._announce("signal",s,s.channel,s.subscription)}else if(2===e.messageType){if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},this.listenerManager.announceObjects(s),this._announce("objects",s,s.channel,s.subscription),"uuid"===e.payload.type){var a=this._renameChannelField(s),u=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"user"})});this.listenerManager.announceUser(u),this._announce("user",u,s.channel,s.subscription)}else if("channel"===e.payload.type){a=this._renameChannelField(s);var c=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"space"})});this.listenerManager.announceSpace(c),this._announce("space",c,s.channel,s.subscription)}else if("membership"===e.payload.type){var l=(a=this._renameChannelField(s)).message.data,p=l.uuid,h=l.channel,f=r(l,["uuid","channel"]);f.user=p,f.space=h;var d=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),data:f})});this.listenerManager.announceMembership(d),this._announce("membership",d,s.channel,s.subscription)}}else if(3===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,s.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},s.event=e.payload.event,this.listenerManager.announceMessageAction(s),this._announce("messageAction",s,s.channel,s.subscription)}else if(4===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId;var y=e.payload;if(this.modules.cryptoModule){var g=void 0;try{g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}null!==g&&(y=g)}e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=y.message,s.file={id:y.file.id,name:y.file.name,url:this.getFileUrl({id:y.file.id,name:y.file.name,channel:t})},this.listenerManager.announceFile(s),this._announce("file",s,s.channel,s.subscription)}else{if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),this.modules.cryptoModule){g=void 0;try{var m;g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}s.message=null!=g?g:e.payload}else s.message=e.payload;s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announceMessage(s),this._announce("message",s,s.channel,s.subscription)}},e.prototype.addListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){r._channelListenerMap[t]?r._channelListenerMap[t].includes(e)||r._channelListenerMap[t].push(e):r._channelListenerMap[t]=[e]})),null==n||n.forEach((function(t){r._groupListenerMap[t]?r._groupListenerMap[t].includes(e)||r._groupListenerMap[t].push(e):r._groupListenerMap[t]=[e]}))):this.listenerManager.addListener(e)},e.prototype.removeListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){var n;r._channelListenerMap[t]=null===(n=r._channelListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))})),null==n||n.forEach((function(t){var n;r._groupListenerMap[t]=null===(n=r._groupListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))}))):this.listenerManager.removeListener(e)},e.prototype.removeAllListeners=function(){this.listenerManager.removeAllListeners()},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e.prototype._announce=function(e,t,n,r){var o,i;null===(o=this._channelListenerMap[n])||void 0===o||o.forEach((function(n){return n[e]&&n[e](t)})),null===(i=this._groupListenerMap[r])||void 0===i||i.forEach((function(n){return n[e]&&n[e](t)}))},e}(),hn=function(){function e(){}return e.prototype.subscribe=function(){var e,t;this.pubnub.subscribe(n({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))},e.prototype.unsubscribe=function(){this.pubnub.unsubscribe({channels:this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),channelGroups:this.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))})},Object.defineProperty(e.prototype,"onMessage",{set:function(e){this.listener.message=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onPresence",{set:function(e){this.listener.presence=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onSignal",{set:function(e){this.listener.signal=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onObjects",{set:function(e){this.listener.objects=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onMessageAction",{set:function(e){this.listener.messageAction=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onFile",{set:function(e){this.listener.file=e},enumerable:!1,configurable:!0}),e.prototype.addListener=function(e){this.eventEmitter.addListener(e,this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),this.groupNames.filter((function(e){return!e.endsWith("-pnpres")})))},e.prototype.removeListener=function(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)},Object.defineProperty(e.prototype,"channels",{get:function(){return this.channelNames.slice(0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"channelGroups",{get:function(){return this.groupNames.slice(0)},enumerable:!1,configurable:!0}),e}(),fn=function(e){function n(t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.subscriptionOptions,c=t.eventEmitter,l=t.pubnub,p=e.call(this)||this;return p.channelNames=[],p.groupNames=[],p.subscriptionList=[],p.options=s,p.eventEmitter=c,p.pubnub=l,r.forEach((function(e){var t=p.pubnub.channel(e).subscription(p.options);p.channelNames=u(u([],a(p.channelNames),!1),a(t.channels),!1),p.subscriptionList.push(t)})),i.forEach((function(e){var t=p.pubnub.channelGroup(e).subscription(p.options);p.groupNames=u(u([],a(p.groupNames),!1),a(t.channelGroups),!1),p.subscriptionList.push(t)})),p.listener={},c.addListener(p.listener,p.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),p.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),p}return t(n,e),n.prototype.addSubscription=function(e){this.subscriptionList.push(e),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscription=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return t!==e}))},n.prototype.addSubscriptionSet=function(e){this.subscriptionList=u(u([],a(this.subscriptionList),!1),a(e.subscriptions),!1),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscriptionSet=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return!e.subscriptions.includes(t)}))},Object.defineProperty(n.prototype,"subscriptions",{get:function(){return this.subscriptionList.slice(0)},enumerable:!1,configurable:!0}),n}(hn),dn=function(e){function r(t){var n=t.channels,r=t.channelGroups,o=t.subscriptionOptions,i=t.eventEmitter,s=t.pubnub,a=e.call(this)||this;return a.channelNames=[],a.groupNames=[],a.channelNames=n,a.groupNames=r,a.options=o,a.pubnub=s,a.eventEmitter=i,a.listener={},i.addListener(a.listener,a.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),a.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),a}return t(r,e),r.prototype.addSubscription=function(e){return new fn({channels:u(u([],a(this.channelNames),!1),a(e.channels),!1),channelGroups:u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),subscriptionOptions:n(n({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})},r}(hn),yn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),gn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),mn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),bn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),vn=function(){function e(e){var t=this,r=e.networking,o=e.cbor,i=new g({setup:e});this._config=i;var c=new T({config:i}),l=e.cryptography;r.init(i);var p=new G(i,o);this._tokenManager=p;var h=new R({maximumSamplesCount:6e4});this._telemetryManager=h;var f=this._config.cryptoModule,d={config:i,networking:r,crypto:c,cryptography:l,tokenManager:p,telemetryManager:h,PubNubFile:e.PubNubFile,cryptoModule:f};this.File=e.PubNubFile,this.encryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.encryptFile(t,this.File)):l.encryptFile(e,t,this.File)},this.decryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.decryptFile(t,this.File)):l.decryptFile(e,t,this.File)};var y=Q.bind(this,d,Je),m=Q.bind(this,d,se),v=Q.bind(this,d,ue),_=Q.bind(this,d,le),S=Q.bind(this,d,$e),w=new L;if(this._listenerManager=w,this.iAmHere=Q.bind(this,d,ue),this.iAmAway=Q.bind(this,d,se),this.setPresenceState=Q.bind(this,d,le),this.handshake=Q.bind(this,d,Qe),this.receiveMessages=Q.bind(this,d,Xe),this._eventEmitter=new pn({modules:d,listenerManager:this._listenerManager,getFileUrl:function(e){return ve(d,e)}}),!0===i.enableEventEngine){if(i.maintainPresenceState&&(this.presenceState={},this.setState=function(e){var n,r;return null===(n=e.channels)||void 0===n||n.forEach((function(n){return t.presenceState[n]=e.state})),null===(r=e.channelGroups)||void 0===r||r.forEach((function(n){return t.presenceState[n]=e.state})),t.setPresenceState({channels:e.channels,channelGroups:e.channelGroups,state:t.presenceState})}),i.getHeartbeatInterval()){var O=new cn({heartbeat:this.iAmHere,leave:this.iAmAway,heartbeatDelay:function(){return new Promise((function(e){return setTimeout(e,1e3*d.config.getHeartbeatInterval())}))},retryDelay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},config:d.config,presenceState:this.presenceState,emitStatus:function(e){w.announceStatus(e)}});this.presenceEventEngine=O,this.join=this.presenceEventEngine.join.bind(O),this.leave=this.presenceEventEngine.leave.bind(O),this.leaveAll=this.presenceEventEngine.leaveAll.bind(O)}var P=new Gt({handshake:this.handshake,receiveMessages:this.receiveMessages,delay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},join:this.join,leave:this.leave,leaveAll:this.leaveAll,presenceState:this.presenceState,config:d.config,emitMessages:function(e){var n,r;try{for(var o=s(e),i=o.next();!i.done;i=o.next()){var a=i.value;t._eventEmitter.emitEvent(a)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},emitStatus:function(e){w.announceStatus(e)}});this.subscribe=P.subscribe.bind(P),this.unsubscribe=P.unsubscribe.bind(P),this.unsubscribeAll=P.unsubscribeAll.bind(P),this.reconnect=P.reconnect.bind(P),this.disconnect=P.disconnect.bind(P),this.destroy=P.dispose.bind(P),this.getSubscribedChannels=P.getSubscribedChannels.bind(P),this.getSubscribedChannelGroups=P.getSubscribedChannelGroups.bind(P),this.eventEngine=P}else{var E=new M({timeEndpoint:y,leaveEndpoint:m,heartbeatEndpoint:v,setStateEndpoint:_,subscribeEndpoint:S,crypto:d.crypto,config:d.config,listenerManager:w,getFileUrl:function(e){return ve(d,e)},cryptoModule:d.cryptoModule,eventEmitter:this._eventEmitter});this.subscribe=E.adaptSubscribeChange.bind(E),this.unsubscribe=E.adaptUnsubscribeChange.bind(E),this.disconnect=E.disconnect.bind(E),this.reconnect=E.reconnect.bind(E),this.unsubscribeAll=E.unsubscribeAll.bind(E),this.getSubscribedChannels=E.getSubscribedChannels.bind(E),this.getSubscribedChannelGroups=E.getSubscribedChannelGroups.bind(E),this.setState=E.adaptStateChange.bind(E),this.presence=E.adaptPresenceChange.bind(E),this.destroy=function(e){E.unsubscribeAll(e),E.disconnect()}}this.addListener=this._eventEmitter.addListener.bind(this._eventEmitter),this.removeListener=this._eventEmitter.removeListener.bind(this._eventEmitter),this.removeAllListeners=this._eventEmitter.removeAllListeners.bind(this._eventEmitter),this.parseToken=p.parseToken.bind(p),this.setToken=p.setToken.bind(p),this.getToken=p.getToken.bind(p),this.channelGroups={listGroups:Q.bind(this,d,ee),listChannels:Q.bind(this,d,te),addChannels:Q.bind(this,d,X),removeChannels:Q.bind(this,d,Y),deleteGroup:Q.bind(this,d,Z)},this.push={addChannels:Q.bind(this,d,ne),removeChannels:Q.bind(this,d,re),deleteDevice:Q.bind(this,d,ie),listChannels:Q.bind(this,d,oe)},this.hereNow=Q.bind(this,d,pe),this.whereNow=Q.bind(this,d,ae),this.getState=Q.bind(this,d,ce),this.grant=Q.bind(this,d,Ue),this.grantToken=Q.bind(this,d,Le),this.audit=Q.bind(this,d,xe),this.revokeToken=Q.bind(this,d,Ge),this.publish=Q.bind(this,d,Be),this.fire=function(e,n){return e.replicate=!1,e.storeInHistory=!1,t.publish(e,n)},this.signal=Q.bind(this,d,He),this.history=Q.bind(this,d,qe),this.deleteMessages=Q.bind(this,d,ze),this.messageCounts=Q.bind(this,d,Ve),this.fetchMessages=Q.bind(this,d,We),this.addMessageAction=Q.bind(this,d,he),this.removeMessageAction=Q.bind(this,d,fe),this.getMessageActions=Q.bind(this,d,de),this.listFiles=Q.bind(this,d,ye);var A=Q.bind(this,d,ge);this.publishFile=Q.bind(this,d,me),this.sendFile=be({generateUploadUrl:A,publishFile:this.publishFile,modules:d}),this.getFileUrl=function(e){return ve(d,e)},this.downloadFile=Q.bind(this,d,_e),this.deleteFile=Q.bind(this,d,Se),this.channel=function(e){return new yn(e,t._eventEmitter,t)},this.channelGroup=function(e){return new gn(e,t._eventEmitter,t)},this.channelMetadata=function(e){return new mn(e,t._eventEmitter,t)},this.userMetadata=function(e){return new bn(e,t._eventEmitter,t)},this.subscriptionSet=function(e){return new fn({channels:e.channels,channelGroups:e.channelGroups,subscriptionOptions:e.subscriptionOptions,eventEmitter:t._eventEmitter,pubnub:t})},this.objects={getAllUUIDMetadata:Q.bind(this,d,we),getUUIDMetadata:Q.bind(this,d,Oe),setUUIDMetadata:Q.bind(this,d,Pe),removeUUIDMetadata:Q.bind(this,d,Ee),getAllChannelMetadata:Q.bind(this,d,Ae),getChannelMetadata:Q.bind(this,d,Te),setChannelMetadata:Q.bind(this,d,Ne),removeChannelMetadata:Q.bind(this,d,Ce),getChannelMembers:Q.bind(this,d,ke),setChannelMembers:function(e){for(var r=[],o=1;o=this._config.origin.length&&(this._currentSubDomain=0);var t=this._config.origin[this._currentSubDomain];return"".concat(e).concat(t)},e.prototype.hasModule=function(e){return e in this._modules},e.prototype.shiftStandardOrigin=function(){return this._standardOrigin=this.nextOrigin(),this._standardOrigin},e.prototype.getStandardOrigin=function(){return this._standardOrigin},e.prototype.POSTFILE=function(e,t,n){return this._modules.postfile(e,t,n)},e.prototype.GETFILE=function(e,t,n){return this._modules.getfile(e,t,n)},e.prototype.POST=function(e,t,n,r){return this._modules.post(e,t,n,r)},e.prototype.PATCH=function(e,t,n,r){return this._modules.patch(e,t,n,r)},e.prototype.GET=function(e,t,n){return this._modules.get(e,t,n)},e.prototype.DELETE=function(e,t,n){return this._modules.del(e,t,n)},e.prototype._detectErrorCategory=function(e){if("ENOTFOUND"===e.code)return k.PNNetworkIssuesCategory;if("ECONNREFUSED"===e.code)return k.PNNetworkIssuesCategory;if("ECONNRESET"===e.code)return k.PNNetworkIssuesCategory;if("EAI_AGAIN"===e.code)return k.PNNetworkIssuesCategory;if(0===e.status||e.hasOwnProperty("status")&&void 0===e.status)return k.PNNetworkIssuesCategory;if(e.timeout)return k.PNTimeoutCategory;if("ETIMEDOUT"===e.code)return k.PNNetworkIssuesCategory;if(e.response){if(e.response.badRequest)return k.PNBadRequestCategory;if(e.response.forbidden)return k.PNAccessDeniedCategory}return k.PNUnknownCategory},e}();function Sn(e){var t=function(e){return e&&"object"==typeof e&&e.constructor===Object};if(!t(e))return e;var n={};return Object.keys(e).forEach((function(r){var o=function(e){return"string"==typeof e||e instanceof String}(r),i=r,s=e[r];Array.isArray(r)||o&&r.indexOf(",")>=0?i=(o?r.split(","):r).reduce((function(e,t){return e+=String.fromCharCode(t)}),""):(function(e){return"number"==typeof e&&isFinite(e)}(r)||o&&!isNaN(r))&&(i=String.fromCharCode(o?parseInt(r,10):10));n[i]=t(s)?Sn(s):s})),n}var wn=function(){function e(e,t){this._base64ToBinary=t,this._decode=e}return e.prototype.decodeToken=function(e){var t="";e.length%4==3?t="=":e.length%4==2&&(t="==");var n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,r=this._decode(this._base64ToBinary(n));if("object"==typeof r)return r},e}(),On={exports:{}},Pn={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;os.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;at?1:0}function Un(e,t,n,r){void 0===r&&(r=kn());var o,i=In(e,"",0,[],void 0,0,r)||e;try{o=0===Cn.length?JSON.stringify(i,t,n):JSON.stringify(i,Dn(t),n)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==Nn.length;){var s=Nn.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return o}function In(e,t,n,r,o,i,s){var a;if(i+=1,"object"==typeof e&&null!==e){for(a=0;as.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;a0)for(var r=0;r1&&"boolean"!=typeof t)throw new Qn('"allowMissing" argument must be a boolean');var n=gr(e),r=n.length>0?n[0]:"",o=mr("%"+r+"%",t),i=o.name,s=o.value,a=!1,u=o.alias;u&&(r=u[0],pr(n,lr([0,1],u)));for(var c=1,l=!0;c=n.length){var d=Yn(s,p);s=(l=!!d)&&"get"in d&&!("originalValue"in d.get)?d.get:s[p]}else l=cr(s,p),s=s[p];l&&!a&&(ir[i]=s)}}return s},vr={exports:{}};!function(e){var t=Vn,n=br,r=n("%Function.prototype.apply%"),o=n("%Function.prototype.call%"),i=n("%Reflect.apply%",!0)||t.call(o,r),s=n("%Object.getOwnPropertyDescriptor%",!0),a=n("%Object.defineProperty%",!0),u=n("%Math.max%");if(a)try{a({},"a",{value:1})}catch(e){a=null}e.exports=function(e){var n=i(t,o,arguments);if(s&&a){var r=s(n,"length");r.configurable&&a(n,"length",{value:1+u(0,e.length-(arguments.length-1))})}return n};var c=function(){return i(t,r,arguments)};a?a(e.exports,"apply",{value:c}):e.exports.apply=c}(vr);var _r=br,Sr=vr.exports,wr=Sr(_r("String.prototype.indexOf")),Or=l(Object.freeze({__proto__:null,default:{}})),Pr="function"==typeof Map&&Map.prototype,Er=Object.getOwnPropertyDescriptor&&Pr?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ar=Pr&&Er&&"function"==typeof Er.get?Er.get:null,Tr=Pr&&Map.prototype.forEach,Nr="function"==typeof Set&&Set.prototype,Cr=Object.getOwnPropertyDescriptor&&Nr?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,kr=Nr&&Cr&&"function"==typeof Cr.get?Cr.get:null,Mr=Nr&&Set.prototype.forEach,jr="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Rr="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,xr="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Ur=Boolean.prototype.valueOf,Ir=Object.prototype.toString,Dr=Function.prototype.toString,Fr=String.prototype.match,Lr=String.prototype.slice,Gr=String.prototype.replace,Kr=String.prototype.toUpperCase,Br=String.prototype.toLowerCase,Hr=RegExp.prototype.test,qr=Array.prototype.concat,zr=Array.prototype.join,Vr=Array.prototype.slice,Wr=Math.floor,Jr="function"==typeof BigInt?BigInt.prototype.valueOf:null,$r=Object.getOwnPropertySymbols,Qr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,Xr="function"==typeof Symbol&&"object"==typeof Symbol.iterator,Yr="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xr||"symbol")?Symbol.toStringTag:null,Zr=Object.prototype.propertyIsEnumerable,eo=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function to(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||Hr.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var r=e<0?-Wr(-e):Wr(e);if(r!==e){var o=String(r),i=Lr.call(t,o.length+1);return Gr.call(o,n,"$&_")+"."+Gr.call(Gr.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Gr.call(t,n,"$&_")}var no=Or,ro=no.custom,oo=co(ro)?ro:null;function io(e,t,n){var r="double"===(n.quoteStyle||t)?'"':"'";return r+e+r}function so(e){return Gr.call(String(e),/"/g,""")}function ao(e){return!("[object Array]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function uo(e){return!("[object RegExp]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function co(e){if(Xr)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!Qr)return!1;try{return Qr.call(e),!0}catch(e){}return!1}var lo=Object.prototype.hasOwnProperty||function(e){return e in this};function po(e,t){return lo.call(e,t)}function ho(e){return Ir.call(e)}function fo(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;nt.maxStringLength){var n=e.length-t.maxStringLength,r="... "+n+" more character"+(n>1?"s":"");return yo(Lr.call(e,0,t.maxStringLength),t)+r}return io(Gr.call(Gr.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,go),"single",t)}function go(e){var t=e.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return n?"\\"+n:"\\x"+(t<16?"0":"")+Kr.call(t.toString(16))}function mo(e){return"Object("+e+")"}function bo(e){return e+" { ? }"}function vo(e,t,n,r){return e+" ("+t+") {"+(r?_o(n,r):zr.call(n,", "))+"}"}function _o(e,t){if(0===e.length)return"";var n="\n"+t.prev+t.base;return n+zr.call(e,","+n)+"\n"+t.prev}function So(e,t){var n=ao(e),r=[];if(n){r.length=e.length;for(var o=0;o-1?Sr(n):n},Po=function e(t,n,r,o){var i=n||{};if(po(i,"quoteStyle")&&"single"!==i.quoteStyle&&"double"!==i.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(po(i,"maxStringLength")&&("number"==typeof i.maxStringLength?i.maxStringLength<0&&i.maxStringLength!==1/0:null!==i.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var s=!po(i,"customInspect")||i.customInspect;if("boolean"!=typeof s&&"symbol"!==s)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(po(i,"indent")&&null!==i.indent&&"\t"!==i.indent&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(po(i,"numericSeparator")&&"boolean"!=typeof i.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=i.numericSeparator;if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return yo(t,i);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var u=String(t);return a?to(t,u):u}if("bigint"==typeof t){var l=String(t)+"n";return a?to(t,l):l}var p=void 0===i.depth?5:i.depth;if(void 0===r&&(r=0),r>=p&&p>0&&"object"==typeof t)return ao(t)?"[Array]":"[Object]";var h=function(e,t){var n;if("\t"===e.indent)n="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;n=zr.call(Array(e.indent+1)," ")}return{base:n,prev:zr.call(Array(t+1),n)}}(i,r);if(void 0===o)o=[];else if(fo(o,t)>=0)return"[Circular]";function f(t,n,s){if(n&&(o=Vr.call(o)).push(n),s){var a={depth:i.depth};return po(i,"quoteStyle")&&(a.quoteStyle=i.quoteStyle),e(t,a,r+1,o)}return e(t,i,r+1,o)}if("function"==typeof t&&!uo(t)){var d=function(e){if(e.name)return e.name;var t=Fr.call(Dr.call(e),/^function\s*([\w$]+)/);if(t)return t[1];return null}(t),y=So(t,f);return"[Function"+(d?": "+d:" (anonymous)")+"]"+(y.length>0?" { "+zr.call(y,", ")+" }":"")}if(co(t)){var g=Xr?Gr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qr.call(t);return"object"!=typeof t||Xr?g:mo(g)}if(function(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return!0;return"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}(t)){for(var m="<"+Br.call(String(t.nodeName)),b=t.attributes||[],v=0;v"}if(ao(t)){if(0===t.length)return"[]";var _=So(t,f);return h&&!function(e){for(var t=0;t=0)return!1;return!0}(_)?"["+_o(_,h)+"]":"[ "+zr.call(_,", ")+" ]"}if(function(e){return!("[object Error]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)){var S=So(t,f);return"cause"in Error.prototype||!("cause"in t)||Zr.call(t,"cause")?0===S.length?"["+String(t)+"]":"{ ["+String(t)+"] "+zr.call(S,", ")+" }":"{ ["+String(t)+"] "+zr.call(qr.call("[cause]: "+f(t.cause),S),", ")+" }"}if("object"==typeof t&&s){if(oo&&"function"==typeof t[oo]&&no)return no(t,{depth:p-r});if("symbol"!==s&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!Ar||!e||"object"!=typeof e)return!1;try{Ar.call(e);try{kr.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}(t)){var w=[];return Tr&&Tr.call(t,(function(e,n){w.push(f(n,t,!0)+" => "+f(e,t))})),vo("Map",Ar.call(t),w,h)}if(function(e){if(!kr||!e||"object"!=typeof e)return!1;try{kr.call(e);try{Ar.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}(t)){var O=[];return Mr&&Mr.call(t,(function(e){O.push(f(e,t))})),vo("Set",kr.call(t),O,h)}if(function(e){if(!jr||!e||"object"!=typeof e)return!1;try{jr.call(e,jr);try{Rr.call(e,Rr)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}(t))return bo("WeakMap");if(function(e){if(!Rr||!e||"object"!=typeof e)return!1;try{Rr.call(e,Rr);try{jr.call(e,jr)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}(t))return bo("WeakSet");if(function(e){if(!xr||!e||"object"!=typeof e)return!1;try{return xr.call(e),!0}catch(e){}return!1}(t))return bo("WeakRef");if(function(e){return!("[object Number]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(Number(t)));if(function(e){if(!e||"object"!=typeof e||!Jr)return!1;try{return Jr.call(e),!0}catch(e){}return!1}(t))return mo(f(Jr.call(t)));if(function(e){return!("[object Boolean]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(Ur.call(t));if(function(e){return!("[object String]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(String(t)));if("undefined"!=typeof window&&t===window)return"{ [object Window] }";if(t===c)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)&&!uo(t)){var P=So(t,f),E=eo?eo(t)===Object.prototype:t instanceof Object||t.constructor===Object,A=t instanceof Object?"":"null prototype",T=!E&&Yr&&Object(t)===t&&Yr in t?Lr.call(ho(t),8,-1):A?"Object":"",N=(E||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(T||A?"["+zr.call(qr.call([],T||[],A||[]),": ")+"] ":"");return 0===P.length?N+"{}":h?N+"{"+_o(P,h)+"}":N+"{ "+zr.call(P,", ")+" }"}return String(t)},Eo=wo("%TypeError%"),Ao=wo("%WeakMap%",!0),To=wo("%Map%",!0),No=Oo("WeakMap.prototype.get",!0),Co=Oo("WeakMap.prototype.set",!0),ko=Oo("WeakMap.prototype.has",!0),Mo=Oo("Map.prototype.get",!0),jo=Oo("Map.prototype.set",!0),Ro=Oo("Map.prototype.has",!0),xo=function(e,t){for(var n,r=e;null!==(n=r.next);r=n)if(n.key===t)return r.next=n.next,n.next=e.next,e.next=n,n},Uo=String.prototype.replace,Io=/%20/g,Do="RFC3986",Fo={default:Do,formatters:{RFC1738:function(e){return Uo.call(e,Io,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:Do},Lo=Fo,Go=Object.prototype.hasOwnProperty,Ko=Array.isArray,Bo=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),Ho=function(e,t){for(var n=t&&t.plainObjects?Object.create(null):{},r=0;r1;){var t=e.pop(),n=t.obj[t.prop];if(Ko(n)){for(var r=[],o=0;o=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===Lo.RFC1738&&(40===u||41===u)?s+=i.charAt(a):u<128?s+=Bo[u]:u<2048?s+=Bo[192|u>>6]+Bo[128|63&u]:u<55296||u>=57344?s+=Bo[224|u>>12]+Bo[128|u>>6&63]+Bo[128|63&u]:(a+=1,u=65536+((1023&u)<<10|1023&i.charCodeAt(a)),s+=Bo[240|u>>18]+Bo[128|u>>12&63]+Bo[128|u>>6&63]+Bo[128|63&u])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(Ko(e)){for(var n=[],r=0;r0?b.join(",")||null:void 0}];else if(Qo(u))O=u;else{var E=Object.keys(b);O=c?E.sort(c):E}for(var A=o&&Qo(b)&&1===b.length?n+"[]":n,T=0;T-1?e.split(","):e},li=function(e,t,n,r){if(e){var o=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,s=n.depth>0&&/(\[[^[\]]*])/.exec(o),a=s?o.slice(0,s.index):o,u=[];if(a){if(!n.plainObjects&&ii.call(Object.prototype,a)&&!n.allowPrototypes)return;u.push(a)}for(var c=0;n.depth>0&&null!==(s=i.exec(o))&&c=0;--i){var s,a=e[i];if("[]"===a&&n.parseArrays)s=[].concat(o);else{s=n.plainObjects?Object.create(null):{};var u="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(u,10);n.parseArrays||""!==u?!isNaN(c)&&a!==u&&String(c)===u&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(s=[])[c]=o:"__proto__"!==u&&(s[u]=o):s={0:o}}o=s}return o}(u,t,n,r)}},pi=function(e,t){var n,r=e,o=function(e){if(!e)return ti;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||ti.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Wo.default;if(void 0!==e.format){if(!Jo.call(Wo.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var r=Wo.formatters[n],o=ti.filter;return("function"==typeof e.filter||Qo(e.filter))&&(o=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:ti.addQueryPrefix,allowDots:void 0===e.allowDots?ti.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ti.charsetSentinel,delimiter:void 0===e.delimiter?ti.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:ti.encode,encoder:"function"==typeof e.encoder?e.encoder:ti.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:ti.encodeValuesOnly,filter:o,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:ti.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:ti.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ti.strictNullHandling}}(t);"function"==typeof o.filter?r=(0,o.filter)("",r):Qo(o.filter)&&(n=o.filter);var i,s=[];if("object"!=typeof r||null===r)return"";i=t&&t.arrayFormat in $o?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=$o[i];if(t&&"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var u="comma"===a&&t&&t.commaRoundTrip;n||(n=Object.keys(r)),o.sort&&n.sort(o.sort);for(var c=zo(),l=0;l0?f+h:""},hi={formats:Fo,parse:function(e,t){var n=function(e){if(!e)return ai;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?ai.charset:e.charset;return{allowDots:void 0===e.allowDots?ai.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:ai.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:ai.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:ai.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ai.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:ai.comma,decoder:"function"==typeof e.decoder?e.decoder:ai.decoder,delimiter:"string"==typeof e.delimiter||oi.isRegExp(e.delimiter)?e.delimiter:ai.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:ai.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:ai.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:ai.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:ai.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ai.strictNullHandling}}(t);if(""===e||null==e)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof e?function(e,t){var n,r={__proto__:null},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,i),a=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(l=si(l)?[l]:l),ii.call(r,c)?r[c]=oi.combine(r[c],l):r[c]=l}return r}(e,n):e,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),s=0;s=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.split(/ *; */).shift(),e.params=e=>{const n={};var r,o=t(e.split(/ *; */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *= */),t=e.shift(),o=e.shift();t&&o&&(n[t]=o)}}catch(e){o.e(e)}finally{o.f()}return n},e.parseLinks=e=>{const n={};var r,o=t(e.split(/ *, */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *; */),t=e[0].slice(1,-1);n[e[1].split(/ *= */)[1].slice(1,-1)]=t}}catch(e){o.e(e)}finally{o.f()}return n},e.cleanHeader=(e,t)=>(delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e),e.isObject=e=>null!==e&&"object"==typeof e,e.hasOwn=Object.hasOwn||function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(new Object(e),t)},e.mixin=(t,n)=>{for(const r in n)e.hasOwn(n,r)&&(t[r]=n[r])}}(fi);const di=Or,yi=fi.isObject,gi=fi.hasOwn;var mi=bi;function bi(){}bi.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},bi.prototype.parse=function(e){return this._parser=e,this},bi.prototype.responseType=function(e){return this._responseType=e,this},bi.prototype.serialize=function(e){return this._serializer=e,this},bi.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(const t in e)if(gi(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},bi.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};const vi=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),_i=new Set([408,413,429,500,502,503,504,521,522,524]);bi.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{const n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&_i.has(t.status))return!0;if(e){if(e.code&&vi.has(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},bi.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},bi.prototype.then=function(e,t){if(!this._fullfilledPromise){const e=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(((t,n)=>{e.on("abort",(()=>{if(this._maxRetries&&this._maxRetries>this._retries)return;if(this.timedout&&this.timedoutError)return void n(this.timedoutError);const e=new Error("Aborted");e.code="ABORTED",e.status=this.status,e.method=this.method,e.url=this.url,n(e)})),e.end(((e,r)=>{e?n(e):t(r)}))}))}return this._fullfilledPromise.then(e,t)},bi.prototype.catch=function(e){return this.then(void 0,e)},bi.prototype.use=function(e){return e(this),this},bi.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},bi.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},bi.prototype.get=function(e){return this._header[e.toLowerCase()]},bi.prototype.getHeader=bi.prototype.get,bi.prototype.set=function(e,t){if(yi(e)){for(const t in e)gi(e,t)&&this.set(t,e[t]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},bi.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},bi.prototype.field=function(e,t,n){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(yi(e)){for(const t in e)gi(e,t)&&this.field(t,e[t]);return this}if(Array.isArray(t)){for(const n in t)gi(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),n?this._getFormData().append(e,t,n):this._getFormData().append(e,t),this},bi.prototype.abort=function(){if(this._aborted)return this;if(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req){if(di.gte(process.version,"v13.0.0")&&di.lt(process.version,"v14.0.0"))throw new Error("Superagent does not work in v13 properly with abort() due to Node.js core changes");this.req.abort()}return this.clearTimeout(),this.emit("abort"),this},bi.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization",`Basic ${r(`${e}:${t}`)}`);break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization",`Bearer ${e}`)}return this},bi.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},bi.prototype.redirects=function(e){return this._maxRedirects=e,this},bi.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},bi.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},bi.prototype.send=function(e){const t=yi(e);let n=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&yi(this._data))for(const t in e){if("bigint"==typeof e[t]&&!e[t].toJSON)throw new Error("Cannot serialize BigInt value to json");gi(e,t)&&(this._data[t]=e[t])}else{if("bigint"==typeof e)throw new Error("Cannot send value of type BigInt");"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],n&&(n=n.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===n?this._data?`${this._data}&${e}`:e:(this._data||"")+e):this._data=e}return!t||this._isHost(e)||n||this.type("json"),this},bi.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},bi.prototype._finalizeQueryString=function(){const e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){const e=this.url.indexOf("?");if(e>=0){const t=this.url.slice(e+1).split("&");"function"==typeof this._sort?t.sort(this._sort):t.sort(),this.url=this.url.slice(0,e)+"?"+t.join("&")}}},bi.prototype._appendQueryString=()=>{console.warn("Unsupported")},bi.prototype._timeoutError=function(e,t,n){if(this._aborted)return;const r=new Error(`${e+t}ms exceeded`);r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.timedoutError=r,this.abort(),this.callback(r)},bi.prototype._setTimeouts=function(){const e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((()=>{e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((()=>{e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};const Si=fi;var wi=Oi;function Oi(){}function Pi(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Ei(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ei(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw i}}}}function Ei(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n{if(o.XMLHttpRequest)return new o.XMLHttpRequest;throw new Error("Browser-only version of superagent could not find XHR")};const g="".trim?e=>e.trim():e=>e.replace(/(^\s*|\s*$)/g,"");function m(e){if(!c(e))return e;const t=[];for(const n in e)p(e,n)&&b(t,n,e[n]);return t.join("&")}function b(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r)){var o,i=n(r);try{for(i.s();!(o=i.n()).done;){b(e,t,o.value)}}catch(e){i.e(e)}finally{i.f()}}else if(c(r))for(const n in r)p(r,n)&&b(e,`${t}[${n}]`,r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function v(e){const t={},n=e.split("&");let r,o;for(let e=0,i=n.length;e{let e,t=null,r=null;try{r=new S(n)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||r.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=e.status||r.status,n.callback(e,r)):n.callback(null,r)}))}y.serializeObject=m,y.parseString=v,y.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":a.stringify,"application/json":s},y.parse={"application/x-www-form-urlencoded":v,"application/json":JSON.parse},l(S.prototype,h.prototype),S.prototype._parseBody=function(e){let t=y.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&_(this.type)&&(t=y.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},S.prototype.toError=function(){const e=this.req,t=e.method,n=e.url,r=`cannot ${t} ${n} (${this.status})`,o=new Error(r);return o.status=this.status,o.method=t,o.url=n,o},y.Response=S,i(w.prototype),l(w.prototype,u.prototype),w.prototype.type=function(e){return this.set("Content-Type",y.types[e]||e),this},w.prototype.accept=function(e){return this.set("Accept",y.types[e]||e),this},w.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});const r=n.encoder?n.encoder:e=>{if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},w.prototype.query=function(e){return"string"!=typeof e&&(e=m(e)),e&&this._query.push(e),this},w.prototype.attach=function(e,t,n){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},w.prototype._getFormData=function(){return this._formData||(this._formData=new o.FormData),this._formData},w.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();const n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},w.prototype.crossDomainError=function(){const e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},w.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},w.prototype.ca=w.prototype.agent,w.prototype.buffer=w.prototype.ca,w.prototype.write=()=>{throw new Error("Streaming is not supported in browser version of superagent")},w.prototype.pipe=w.prototype.write,w.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},w.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||d,this._finalizeQueryString(),this._end()},w.prototype._setUploadTimeout=function(){const e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((()=>{e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},w.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));const e=this;this.xhr=y.getXHR();const t=this.xhr;let n=this._formData||this._data;this._setTimeouts(),t.addEventListener("readystatechange",(()=>{const n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4!==n)return;let r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}));const r=(t,n)=>{n.total>0&&(n.percent=n.loaded/n.total*100,100===n.percent&&clearTimeout(e._uploadTimeoutTimer)),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.addEventListener("progress",r.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",r.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof n&&!this._isHost(n)){const e=this._header["content-type"];let t=this._serializer||y.serialize[e?e.split(";")[0]:""];!t&&_(e)&&(t=y.serialize["application/json"]),t&&(n=t(n))}for(const e in this.header)null!==this.header[e]&&p(this.header,e)&&t.setRequestHeader(e,this.header[e]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===n?null:n)},y.agent=()=>new f;for(var O=0,P=["GET","POST","OPTIONS","PATCH","PUT","DELETE"];O{const r=y("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.head=(e,t,n)=>{const r=y("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.options=(e,t,n)=>{const r=y("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.del=E,y.delete=E,y.patch=(e,t,n)=>{const r=y("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.post=(e,t,n)=>{const r=y("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.put=(e,t,n)=>{const r=y("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}}(On,On.exports);var ki=On.exports;function Mi(e){var t=(new Date).getTime(),n=(new Date).toISOString(),r=console&&console.log?console:window&&window.console&&window.console.log?window.console:console;r.log("<<<<<"),r.log("[".concat(n,"]"),"\n",e.url,"\n",e.qs),r.log("-----"),e.on("response",(function(n){var o=(new Date).getTime()-t,i=(new Date).toISOString();r.log(">>>>>>"),r.log("[".concat(i," / ").concat(o,"]"),"\n",e.url,"\n",e.qs,"\n",n.text),r.log("-----")}))}function ji(e,t,n){var r=this;this._config.logVerbosity&&(e=e.use(Mi)),this._config.proxy&&this._modules.proxy&&(e=this._modules.proxy.call(this,e)),this._config.keepAlive&&this._modules.keepAlive&&(e=this._modules.keepAlive(e));var o=e;if(t.abortSignal)var i=t.abortSignal.subscribe((function(){o.abort(),i()}));return!0===t.forceBuffered?o="undefined"==typeof Blob?o.buffer().responseType("arraybuffer"):o.responseType("arraybuffer"):!1===t.forceBuffered&&(o=o.buffer(!1)),(o=o.timeout(t.timeout)).on("abort",(function(){return n({category:k.PNUnknownCategory,error:!0,operation:t.operation,errorData:new Error("Aborted")},null)})),o.end((function(e,o){var i,s={};if(s.error=null!==e,s.operation=t.operation,o&&o.status&&(s.statusCode=o.status),e){if(e.response&&e.response.text&&!r._config.logVerbosity)try{s.errorData=JSON.parse(e.response.text)}catch(t){s.errorData=e}else s.errorData=e;return s.category=r._detectErrorCategory(e),n(s,null)}if(t.ignoreBody)i={headers:o.headers,redirects:o.redirects,response:o};else try{i=JSON.parse(o.text)}catch(e){return s.errorData=o,s.error=!0,n(s,null)}return i.error&&1===i.error&&i.status&&i.message&&i.service?(s.errorData=i,s.statusCode=i.status,s.error=!0,s.category=r._detectErrorCategory(s),n(s,null)):(i.error&&i.error.message&&(s.errorData=i.error),n(s,i))})),o}function Ri(e,t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return r=ki.post(e),t.forEach((function(e){var t=e.key,n=e.value;r=r.field(t,n)})),r.attach("file",n,{contentType:"application/octet-stream"}),[4,r];case 1:return[2,o.sent()]}}))}))}function xi(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ui(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ii(e,t,n,r){var o=ki.post(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Di(e,t,n,r){var o=ki.patch(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Fi(e,t,n){var r=ki.delete(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Li(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}var Gi,Ki=function(){function e(){}return Object.defineProperty(e.prototype,"algo",{get:function(){return"aes-256-cbc"},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.encryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.encryptString(n,t)];throw new Error("Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer")}}))}))},e.prototype.decrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.decryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.decryptString(n,t)];throw new Error("Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer")}}))}))},e.prototype.encryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:if(t.data.byteLength<=0)throw new Error("encryption error. empty content");return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.encryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,mimeType:"application/octet-stream",data:s})]}}))}))},e.prototype.decryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.decryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,data:s})]}}))}))},e.prototype.getKey=function(t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return[4,crypto.subtle.digest("SHA-256",e.encoder.encode(t))];case 1:return n=i.sent(),r=Array.from(new Uint8Array(n)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),o=e.encoder.encode(r.slice(0,32)).buffer,[2,crypto.subtle.importKey("raw",o,"AES-CBC",!0,["encrypt","decrypt"])]}}))}))},e.prototype.encryptArrayBuffer=function(e,t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),r=Li,o=[n.buffer],[4,crypto.subtle.encrypt({name:"AES-CBC",iv:n},e,t)];case 1:return[2,r.apply(void 0,o.concat([i.sent()]))]}}))}))},e.prototype.decryptArrayBuffer=function(t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:if(r=n.slice(0,16),n.slice(e.IV_LENGTH).byteLength<=0)throw new Error("decryption error: empty content");return[4,crypto.subtle.decrypt({name:"AES-CBC",iv:r},t,n.slice(e.IV_LENGTH))];case 1:return[2,o.sent()]}}))}))},e.prototype.encryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=crypto.getRandomValues(new Uint8Array(16)),o=e.encoder.encode(n).buffer,[4,crypto.subtle.encrypt({name:"AES-CBC",iv:r},t,o)];case 1:return s=i.sent(),a=Li(r.buffer,s),[2,e.decoder.decode(a)]}}))}))},e.prototype.decryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=e.encoder.encode(n).buffer,o=r.slice(0,16),s=r.slice(16),[4,crypto.subtle.decrypt({name:"AES-CBC",iv:o},t,s)];case 1:return a=i.sent(),[2,e.decoder.decode(a)]}}))}))},e.IV_LENGTH=16,e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Bi=(Gi=function(){function e(e){if(e instanceof File)this.data=e,this.name=this.data.name,this.mimeType=this.data.type;else if(e.data){var t=e.data;this.data=new File([t],e.name,{type:e.mimeType}),this.name=e.name,e.mimeType&&(this.mimeType=e.mimeType)}if(void 0===this.data)throw new Error("Couldn't construct a file out of supplied options.");if(void 0===this.name)throw new Error("Couldn't guess filename out of the options. Please provide one.")}return e.create=function(e){return new this(e)},e.prototype.toBuffer=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toStream=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toFileUri=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in react native environments.")}))}))},e.prototype.toBlob=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e.prototype.toArrayBuffer=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if(r.result instanceof ArrayBuffer)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsArrayBuffer(e.data)}))]}))}))},e.prototype.toString=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if("string"==typeof r.result)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsBinaryString(e.data)}))]}))}))},e.prototype.toFile=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e}(),Gi.supportsFile="undefined"!=typeof File,Gi.supportsBlob="undefined"!=typeof Blob,Gi.supportsArrayBuffer="undefined"!=typeof ArrayBuffer,Gi.supportsBuffer=!1,Gi.supportsStream=!1,Gi.supportsString=!0,Gi.supportsEncryptFile=!0,Gi.supportsFileUri=!1,Gi),Hi=function(){function e(e){this.config=e,this.cryptor=new T({config:e}),this.fileCryptor=new Ki}return Object.defineProperty(e.prototype,"identifier",{get:function(){return""},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e){var t="string"==typeof e?e:(new TextDecoder).decode(e);return{data:this.cryptor.encrypt(t),metadata:null}},e.prototype.decrypt=function(e){var t="string"==typeof e.data?e.data:b(e.data);return this.cryptor.decrypt(t)},e.prototype.encryptFile=function(e,t){var n;return o(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)]}))}))},e.prototype.decryptFile=function(e,t){return o(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.fileCryptor.decryptFile(this.config.cipherKey,e,t)]}))}))},e}(),qi=function(){function e(e){this.cipherKey=e.cipherKey,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(this.cipherKey)}return Object.defineProperty(e.prototype,"algo",{get:function(){return"AES-CBC"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return"ACRH"},enumerable:!1,configurable:!0}),e.prototype.getIv=function(){return crypto.getRandomValues(new Uint8Array(e.BLOCK_SIZE))},e.prototype.getKey=function(){return o(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return t=e.encoder.encode(this.cipherKey),[4,crypto.subtle.digest("SHA-256",t.buffer)];case 1:return n=r.sent(),[2,crypto.subtle.importKey("raw",n,this.algo,!0,["encrypt","decrypt"])]}}))}))},e.prototype.encrypt=function(t){if(0===("string"==typeof t?t:e.decoder.decode(t)).length)throw new Error("encryption error. empty content");var n=this.getIv();return{metadata:n,data:m(this.CryptoJS.AES.encrypt(t,this.encryptedKey,{iv:this.bufferToWordArray(n),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}},e.prototype.decrypt=function(t){var n=this.bufferToWordArray(new Uint8ClampedArray(t.metadata)),r=this.bufferToWordArray(new Uint8ClampedArray(t.data));return e.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:r},this.encryptedKey,{iv:n,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer},e.prototype.encryptFileData=function(e){return o(this,void 0,void 0,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:return[4,this.getKey()];case 1:return t=o.sent(),n=this.getIv(),r={},[4,crypto.subtle.encrypt({name:this.algo,iv:n},t,e)];case 2:return[2,(r.data=o.sent(),r.metadata=n,r)]}}))}))},e.prototype.decryptFileData=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.getKey()];case 1:return t=n.sent(),[2,crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)]}}))}))},e.prototype.bufferToWordArray=function(e){var t,n=[];for(t=0;t0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("decryption error. empty content");return r.decrypt({data:t.slice(n.length),metadata:o})},e.prototype.encryptFile=function(e,t){return o(this,void 0,void 0,(function(){var n,r;return i(this,(function(o){switch(o.label){case 0:return this.defaultCryptor.identifier===Vi.LEGACY_IDENTIFIER?[2,this.defaultCryptor.encryptFile(e,t)]:[4,this.getFileData(e.data)];case 1:return n=o.sent(),[4,this.defaultCryptor.encryptFileData(n)];case 2:return r=o.sent(),[2,t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(r),r.data)})]}}))}))},e.prototype.decryptFile=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a,u,c,l,p;return i(this,(function(i){switch(i.label){case 0:return[4,t.data.arrayBuffer()];case 1:return r=i.sent(),o=Vi.tryParse(r),(null==(s=this.getCryptor(o))?void 0:s.identifier)===e.LEGACY_IDENTIFIER?[2,s.decryptFile(t,n)]:[4,this.getFileData(r)];case 2:return a=i.sent(),u=a.slice(o.length-o.metadataLength,o.length),l=(c=n).create,p={name:t.name},[4,this.defaultCryptor.decryptFileData({data:r.slice(o.length),metadata:u})];case 3:return[2,l.apply(c,[(p.data=i.sent(),p)])]}}))}))},e.prototype.getCryptor=function(e){if(""===e){var t=this.getAllCryptors().find((function(e){return""===e.identifier}));if(t)return t;throw new Error("unknown cryptor error")}if(e instanceof Wi)return this.getCryptorFromId(e.identifier)},e.prototype.getCryptorFromId=function(e){var t=this.getAllCryptors().find((function(t){return e===t.identifier}));if(t)return t;throw Error("unknown cryptor error")},e.prototype.concatArrayBuffer=function(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer},e.prototype.getHeaderData=function(e){if(e.metadata){var t=Vi.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length),r=0;return n.set(t.data,r),r+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),r),n.buffer}},e.prototype.getFileData=function(t){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return t instanceof Blob?[4,t.arrayBuffer()]:[3,2];case 1:return[2,n.sent()];case 2:if(t instanceof ArrayBuffer)return[2,t];if("string"==typeof t)return[2,e.encoder.encode(t)];throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}}))}))},e.LEGACY_IDENTIFIER="",e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Vi=function(){function e(){}return e.from=function(t,n){if(t!==e.LEGACY_IDENTIFIER)return new Wi(t,n.byteLength)},e.tryParse=function(t){var n=new Uint8Array(t),r="";if(n.byteLength>=4&&(r=n.slice(0,4),this.decoder.decode(r)!==e.SENTINEL))return"";if(!(n.byteLength>=5))throw new Error("decryption error. invalid header version");if(n[4]>e.MAX_VERSION)throw new Error("unknown cryptor error");var o="",i=5+e.IDENTIFIER_LENGTH;if(!(n.byteLength>=i))throw new Error("decryption error. invalid crypto identifier");o=n.slice(5,i);var s=null;if(!(n.byteLength>=i+1))throw new Error("decryption error. invalid metadata length");return s=n[i],i+=1,255===s&&n.byteLength>=i+2&&(s=new Uint16Array(n.slice(i,i+2)).reduce((function(e,t){return(e<<8)+t}),0),i+=2),new Wi(this.decoder.decode(o),s)},e.SENTINEL="PNED",e.LEGACY_IDENTIFIER="",e.IDENTIFIER_LENGTH=4,e.VERSION=1,e.MAX_VERSION=1,e.decoder=new TextDecoder,e}(),Wi=function(){function e(e,t){this._identifier=e,this._metadataLength=t}return Object.defineProperty(e.prototype,"identifier",{get:function(){return this._identifier},set:function(e){this._identifier=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"metadataLength",{get:function(){return this._metadataLength},set:function(e){this._metadataLength=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return Vi.VERSION},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return Vi.SENTINEL.length+1+Vi.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){var e=0,t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(Vi.SENTINEL)),t[e+=Vi.SENTINEL.length]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e),e+=Vi.IDENTIFIER_LENGTH;var r=this.metadataLength;return r<255?t[e]=r:t.set([255,r>>8,255&r],e),t},enumerable:!1,configurable:!0}),e.IDENTIFIER_LENGTH=4,e.SENTINEL="PNED",e}();function Ji(e){if(!navigator||!navigator.sendBeacon)return!1;navigator.sendBeacon(e)}var $i=function(e){function n(t){var n=this,r=t.listenToBrowserNetworkEvents,o=void 0===r||r;return t.sdkFamily="Web",t.networking=new _n({del:Fi,get:Ui,post:Ii,patch:Di,sendBeacon:Ji,getfile:xi,postfile:Ri}),t.cbor=new wn((function(e){return Sn(h.decode(e))}),m),t.PubNubFile=Bi,t.cryptography=new Ki,t.initCryptoModule=function(e){return new zi({default:new Hi({cipherKey:e.cipherKey,useRandomIVs:e.useRandomIVs}),cryptors:[new qi({cipherKey:e.cipherKey})]})},n=e.call(this,t)||this,o&&(window.addEventListener("offline",(function(){n.networkDownDetected()})),window.addEventListener("online",(function(){n.networkUpDetected()}))),n}return t(n,e),n.CryptoModule=zi,n}(vn);return $i})); diff --git a/lib/core/components/config.js b/lib/core/components/config.js index 0b7786537..96fa4e7a2 100644 --- a/lib/core/components/config.js +++ b/lib/core/components/config.js @@ -180,7 +180,7 @@ var default_1 = /** @class */ (function () { return this; }; default_1.prototype.getVersion = function () { - return '7.6.0'; + return '7.6.1'; }; default_1.prototype._setRetryConfiguration = function (configuration) { if (configuration.minimumdelay < 2) { diff --git a/lib/core/components/eventEmitter.js b/lib/core/components/eventEmitter.js index 06c8dc8eb..c75d9c60d 100644 --- a/lib/core/components/eventEmitter.js +++ b/lib/core/components/eventEmitter.js @@ -51,7 +51,7 @@ var EventEmitter = /** @class */ (function () { } announce.action = e.payload.action; announce.state = e.payload.data; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.occupancy = e.payload.occupancy; announce.uuid = e.payload.uuid; announce.timestamp = e.payload.timestamp; @@ -77,7 +77,7 @@ var EventEmitter = /** @class */ (function () { announce.subscription = null; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; if (e.userMetadata) { announce.userMetadata = e.userMetadata; @@ -92,7 +92,7 @@ var EventEmitter = /** @class */ (function () { announce.subscription = null; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; if (e.userMetadata) { announce.userMetadata = e.userMetadata; @@ -110,13 +110,13 @@ var EventEmitter = /** @class */ (function () { this.listenerManager.announceUser(userEvent); this._announce('user', userEvent, announce.channel, announce.subscription); } - else if (message.payload.type === 'channel') { + else if (e.payload.type === 'channel') { var eventData = this._renameChannelField(announce); var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) }); this.listenerManager.announceSpace(spaceEvent); this._announce('space', spaceEvent, announce.channel, announce.subscription); } - else if (message.payload.type === 'membership') { + else if (e.payload.type === 'membership') { var eventData = this._renameChannelField(announce); var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]); membershipData.user = user; @@ -130,7 +130,7 @@ var EventEmitter = /** @class */ (function () { var announce = {}; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; announce.data = { messageTimetoken: e.payload.data.messageTimetoken, @@ -147,7 +147,7 @@ var EventEmitter = /** @class */ (function () { var announce = {}; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; var msgPayload = e.payload; if (this.modules.cryptoModule) { @@ -187,7 +187,7 @@ var EventEmitter = /** @class */ (function () { announce.subscription = null; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; if (e.userMetadata) { announce.userMetadata = e.userMetadata; diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index 702295738..4e05c306c 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -61,7 +61,7 @@ function handleResponse(modules, serverResponse) { var messages = []; serverResponse.m.forEach(function (rawMessage) { var publishMetaData = { - publishTimetoken: rawMessage.p.t, + timetoken: rawMessage.p.t, region: rawMessage.p.r, }; var parsedMessage = { diff --git a/lib/core/endpoints/subscriptionUtils/receiveMessages.js b/lib/core/endpoints/subscriptionUtils/receiveMessages.js index e9d07554a..278049190 100644 --- a/lib/core/endpoints/subscriptionUtils/receiveMessages.js +++ b/lib/core/endpoints/subscriptionUtils/receiveMessages.js @@ -56,6 +56,7 @@ var endpoint = { issuingClientId: envelope.i, subscribeKey: envelope.k, originationTimetoken: envelope.o, + userMetadata: envelope.u, publishMetaData: { timetoken: envelope.p.t, region: envelope.p.r, diff --git a/lib/event-engine/index.js b/lib/event-engine/index.js index 7d8811c25..2dcdfa1bd 100644 --- a/lib/event-engine/index.js +++ b/lib/event-engine/index.js @@ -144,10 +144,10 @@ var EventEngine = /** @class */ (function () { } }; EventEngine.prototype.getSubscribedChannels = function () { - return this.channels.slice(0); + return Array.from(new Set(this.channels)); }; EventEngine.prototype.getSubscribedChannelGroups = function () { - return this.groups.slice(0); + return Array.from(new Set(this.groups)); }; EventEngine.prototype.dispose = function () { this.disconnect(); diff --git a/package-lock.json b/package-lock.json index 0167e25f4..36efbc4cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "7.4.5", + "version": "7.6.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "7.4.5", + "version": "7.6.0", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", @@ -4069,9 +4069,9 @@ "dev": true }, "node_modules/ip": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz", - "integrity": "sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg==" + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.9.tgz", + "integrity": "sha512-cyRxvOEpNHNtchU3Ln9KC/auJgup87llfQpQ+t5ghoC/UhL16SWzbueiCsdTnWmqAWl7LadfuwhlqmtOaqMHdQ==" }, "node_modules/is-arguments": { "version": "1.1.1", @@ -6701,9 +6701,9 @@ } }, "node_modules/socks/node_modules/ip": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", - "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==" + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz", + "integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==" }, "node_modules/source-map": { "version": "0.6.1", diff --git a/package.json b/package.json index da6bd4c2c..b691b4bf8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "7.6.0", + "version": "7.6.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/config.js b/src/core/components/config.js index 69bef414a..dd552f456 100644 --- a/src/core/components/config.js +++ b/src/core/components/config.js @@ -358,7 +358,7 @@ export default class { } getVersion() { - return '7.6.0'; + return '7.6.1'; } _setRetryConfiguration(configuration) { diff --git a/src/core/components/eventEmitter.js b/src/core/components/eventEmitter.js index 2157569de..6dde752b8 100644 --- a/src/core/components/eventEmitter.js +++ b/src/core/components/eventEmitter.js @@ -36,7 +36,7 @@ export default class EventEmitter { announce.action = e.payload.action; announce.state = e.payload.data; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.occupancy = e.payload.occupancy; announce.uuid = e.payload.uuid; announce.timestamp = e.payload.timestamp; @@ -66,7 +66,7 @@ export default class EventEmitter { announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; if (e.userMetadata) { announce.userMetadata = e.userMetadata; @@ -82,7 +82,7 @@ export default class EventEmitter { announce.subscription = null; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; if (e.userMetadata) { announce.userMetadata = e.userMetadata; @@ -106,7 +106,7 @@ export default class EventEmitter { }; this.listenerManager.announceUser(userEvent); this._announce('user', userEvent, announce.channel, announce.subscription); - } else if (message.payload.type === 'channel') { + } else if (e.payload.type === 'channel') { const eventData = this._renameChannelField(announce); const spaceEvent = { ...eventData, @@ -118,7 +118,7 @@ export default class EventEmitter { }; this.listenerManager.announceSpace(spaceEvent); this._announce('space', spaceEvent, announce.channel, announce.subscription); - } else if (message.payload.type === 'membership') { + } else if (e.payload.type === 'membership') { const eventData = this._renameChannelField(announce); const { uuid: user, channel: space, ...membershipData } = eventData.message.data; membershipData.user = user; @@ -138,7 +138,7 @@ export default class EventEmitter { const announce = {}; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; announce.data = { messageTimetoken: e.payload.data.messageTimetoken, @@ -154,7 +154,7 @@ export default class EventEmitter { const announce = {}; announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; let msgPayload = e.payload; @@ -199,7 +199,7 @@ export default class EventEmitter { announce.channel = channel; announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.publishTimetoken; + announce.timetoken = publishMetaData.timetoken; announce.publisher = e.issuingClientId; if (e.userMetadata) { diff --git a/src/core/endpoints/subscribe.js b/src/core/endpoints/subscribe.js index faf6d1306..8058b094e 100644 --- a/src/core/endpoints/subscribe.js +++ b/src/core/endpoints/subscribe.js @@ -61,7 +61,7 @@ export function handleResponse(modules, serverResponse) { serverResponse.m.forEach((rawMessage) => { const publishMetaData = { - publishTimetoken: rawMessage.p.t, + timetoken: rawMessage.p.t, region: rawMessage.p.r, }; const parsedMessage = { diff --git a/src/core/endpoints/subscriptionUtils/receiveMessages.js b/src/core/endpoints/subscriptionUtils/receiveMessages.js index c85a52ab5..6558af81c 100644 --- a/src/core/endpoints/subscriptionUtils/receiveMessages.js +++ b/src/core/endpoints/subscriptionUtils/receiveMessages.js @@ -56,6 +56,7 @@ const endpoint = { issuingClientId: envelope.i, subscribeKey: envelope.k, originationTimetoken: envelope.o, + userMetadata: envelope.u, publishMetaData: { timetoken: envelope.p.t, region: envelope.p.r, diff --git a/src/event-engine/index.ts b/src/event-engine/index.ts index c4fb5a0a1..5e948e769 100644 --- a/src/event-engine/index.ts +++ b/src/event-engine/index.ts @@ -136,11 +136,11 @@ export class EventEngine { } getSubscribedChannels(): string[] { - return this.channels.slice(0); + return Array.from(new Set(this.channels)); } getSubscribedChannelGroups(): string[] { - return this.groups.slice(0); + return Array.from(new Set(this.groups)); } dispose(): void { diff --git a/test/integration/components/listeners.test.js b/test/integration/components/listeners.test.js index 77e676f64..ef54a7d5b 100644 --- a/test/integration/components/listeners.test.js +++ b/test/integration/components/listeners.test.js @@ -449,24 +449,26 @@ describe('#listeners', () => { ); subscription.removeListener(listener); subscription.subscribe(); + expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch1']); const actual = await messagePromise; expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); expect(messages.length).to.equal(0); + const subscriptionCh2 = pubnub.channel('ch2').subscription(); subscriptionCh2.subscribe(); + expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch1', 'ch2']); + const subscriptionCh3 = pubnub.channel('ch3').subscription(); const subscriptionSetCh23 = subscriptionCh3.addSubscription(pubnub.channel('ch2').subscription()); - const messagePromiseChannel2 = new Promise((resolveMessage) => - subscriptionSetCh23.addListener({ - message: (m) => resolveMessage(m), - }), - ); subscriptionSetCh23.subscribe(); + expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch1', 'ch2', 'ch3']); + subscription.unsubscribe(); + expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch2', 'ch3']); + subscriptionCh2.unsubscribe(); - const actualChannel2MessageAfterOneUnsubCh2 = await messagePromiseChannel2; + expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch2', 'ch3']); pubnub.destroy(); - expect(JSON.stringify(actualChannel2MessageAfterOneUnsubCh2.message)).to.equal('{"ch2":"My message!"}'); }); it('should work with event type specific listener registraction', async () => { @@ -538,7 +540,127 @@ describe('#listeners', () => { subscription.subscribe(); const actual = await presencePromise; expect(JSON.stringify(actual)).to.equal( - '{"channel":"ch1","subscription":null,"action":"join","occupancy":1,"uuid":"testid","timestamp":1461451222,"actualChannel":null,"subscribedChannel":"ch1-pnpres"}', + '{"channel":"ch1","subscription":null,"action":"join","timetoken":"8","occupancy":1,"uuid":"testid","timestamp":1461451222,"actualChannel":null,"subscribedChannel":"ch1-pnpres"}', + ); + }); + + it('should work with objects data - membership', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + `{"t":{"t":"17087917617921775","r":31},"m":[{"a":"0","f":0,"e":2,"p":{"t":"17087917617921775","r":31},"k":"mySubKey","c":"ch1","d":{"source":"objects","version":"2.0","event":"set","type":"membership","data":{"channel":{"id":"c1"},"eTag":"AZO/t53al7m8fw","updated":"2024-02-24T16:22:41.786844939Z","uuid":{"id":"userIdTest"}}},"b":"ch1"}]}`, + ); + var channel = pubnub.channel('ch1'); + var subscription = channel.subscription(); + var membershipPromise = new Promise((resolveObjects) => + subscription.addListener({ + objects: (objectsEvent) => resolveObjects(objectsEvent), + }), + ); + subscription.subscribe(); + const actual = await membershipPromise; + expect(JSON.stringify(actual)).to.equal( + `{"channel":"ch1","subscription":null,"timetoken":"17087917617921775","message":{"event":"set","type":"membership","data":{"channel":{"id":"c1"},"eTag":"AZO/t53al7m8fw","updated":"2024-02-24T16:22:41.786844939Z","uuid":{"id":"userIdTest"}}}}`, + ); + }); + + it('should work with objects data - channel', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + `{"t":{"t":"17087625097482155","r":33},"m":[{"a":"0","f":0,"e":2,"p":{"t":"17087625097482155","r":33},"k":"mySubKey","c":"ch1","d":{"source":"objects","version":"2.0","event":"set","type":"channel","data":{"custom":{"occupancy":1},"eTag":"125aasww","id":"user-1","updated":"2024-02-24T08:15:09.744661Z"}},"b":"ch1"}]}`, + ); + var channel = pubnub.channel('ch1'); + var subscription = channel.subscription(); + var objectsEventPromise = new Promise((resolveObjects) => + subscription.addListener({ + objects: (objectsEvent) => resolveObjects(objectsEvent), + }), + ); + subscription.subscribe(); + const actual = await objectsEventPromise; + expect(JSON.stringify(actual)).to.equal( + '{"channel":"ch1","subscription":null,"timetoken":"17087625097482155","message":{"event":"set","type":"channel","data":{"custom":{"occupancy":1},"eTag":"125aasww","id":"user-1","updated":"2024-02-24T08:15:09.744661Z"}}}', + ); + }); + + it('should work with message actions', async () => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + state: '{}', + tt: 0, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '3', + tr: 1, + }) + .reply( + 200, + `{"t":{"t":"17087942541729876","r":31},"m":[{"a":"0","f":0,"e":3,"i":"userIdTest","p":{"t":"17087942541729876","r":31},"k":"mySubKey","c":"ch1","d":{"source":"actions","version":"1.0","data":{"messageTimetoken":"17087942466262824","type":"reaction","value":"smiley","actionTimetoken":"17087942541639760"},"event":"added"},"b":"ch1"}]}`, + ); + var channel = pubnub.channel('ch1'); + var subscription = channel.subscription(); + var messageActionPromise = new Promise((resolveMessageActionEvent) => + subscription.addListener({ + messageAction: (messageActionEvent) => resolveMessageActionEvent(messageActionEvent), + }), + ); + subscription.subscribe(); + const actual = await messageActionPromise; + expect(JSON.stringify(actual)).to.equal( + '{"channel":"ch1","subscription":null,"timetoken":"17087942541729876","publisher":"userIdTest","data":{"messageTimetoken":"17087942466262824","actionTimetoken":"17087942541639760","type":"reaction","uuid":"userIdTest","value":"smiley"},"event":"added"}', ); }); }); From 8d9d8c2befe1d6e5e727ec109881281074f2b44e Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Thu, 28 Mar 2024 18:58:44 +0530 Subject: [PATCH 03/49] CLEN-1924: pagination params listChannels api for push devices (#366) * added `start` and `count` to listChannels api for push devices * PubNub SDK v7.6.2 release. * Update .pubnub.yml Co-authored-by: Karolina Rymer --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> Co-authored-by: Karolina Rymer --- .pubnub.yml | 11 +++- CHANGELOG.md | 6 ++ README.md | 4 +- dist/web/pubnub.js | 8 ++- dist/web/pubnub.min.js | 2 +- lib/core/components/config.js | 2 +- lib/core/endpoints/push/list_push_channels.js | 6 +- package.json | 2 +- src/core/components/config.js | 2 +- src/core/endpoints/push/list_push_channels.js | 5 +- test/integration/endpoints/push.test.js | 55 +++++++++++++++++++ 11 files changed, 90 insertions(+), 13 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index fc5a3fb57..5d46365c9 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-03-28 + version: v7.6.2 + changes: + - type: feature + text: "Added support for pagination params for listChannels API of push notification devices." - date: 2024-02-26 version: v7.6.1 changes: @@ -948,7 +953,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '7.6.1' +version: '7.6.2' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -964,7 +969,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.2.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1635,7 +1640,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v7.6.1/pubnub.7.6.1.js + location: https://github.com/pubnub/javascript/releases/download/v7.6.2/pubnub.7.6.2.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index fd8c4684c..3a311b725 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v7.6.2 +March 28 2024 + +#### Added +- Added support for pagination params for listChannels api of push notification devices. + ## v7.6.1 February 26 2024 diff --git a/README.md b/README.md index 69a73ad04..f2a160dd5 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.2.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.2.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index e1982409d..6cfbcf2aa 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -794,7 +794,7 @@ return this; }; default_1.prototype.getVersion = function () { - return '7.6.1'; + return '7.6.2'; }; default_1.prototype._setRetryConfiguration = function (configuration) { if (configuration.minimumdelay < 2) { @@ -3893,12 +3893,16 @@ return true; } function prepareParams$l(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.environment, environment = _a === void 0 ? 'development' : _a, topic = incomingParams.topic; + var pushGateway = incomingParams.pushGateway, _a = incomingParams.environment, environment = _a === void 0 ? 'development' : _a, topic = incomingParams.topic, start = incomingParams.start, count = incomingParams.count; var parameters = { type: pushGateway }; if (pushGateway === 'apns2') { parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); delete parameters.type; } + if (start) + parameters.start = start; + if (count && count > 0) + parameters.count = count; return parameters; } function handleResponse$l(modules, serverResponse) { diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index dad8e7f1e..f8c1b2a31 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -14,4 +14,4 @@ PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function u(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o>2,c=0;c>6),o.push(128|63&s)):s<55296?(o.push(224|s>>12),o.push(128|s>>6&63),o.push(128|63&s)):(s=(1023&s)<<10,s|=1023&t.charCodeAt(++r),s+=65536,o.push(240|s>>18),o.push(128|s>>12&63),o.push(128|s>>6&63),o.push(128|63&s))}return h(3,o.length),p(o);default:var f;if(Array.isArray(t))for(h(4,f=t.length),r=0;r>5!==e)throw"Invalid indefinite length element";return n}function g(e,t){for(var n=0;n>10),e.push(56320|1023&r))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var o,h,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=p(),o=32768&n,i=31744&n,s=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==s)return s*r;return t.setUint32(0,o<<16|i<<13|s<<13),t.getFloat32(0)}();case 26:return u(s.getFloat32(a),4);case 27:return u(s.getFloat64(a),8)}if((h=d(v))<0&&(b<2||6=0;)S+=h,_.push(c(h));var w=new Uint8Array(S),O=0;for(o=0;o<_.length;++o)w.set(_[o],O),O+=_[o].length;return w}return c(h);case 3:var P=[];if(h<0)for(;(h=y(b))>=0;)g(P,h);else g(P,h);return String.fromCharCode.apply(null,P);case 4:var E;if(h<0)for(E=[];!f();)E.push(e());else for(E=new Array(h),o=0;o=20?this._presenceTimeout=e:(this._presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",this._presenceTimeout)),this.setHeartbeatInterval(this._presenceTimeout/2-1),this},e.prototype.setProxy=function(e){this.proxy=e},e.prototype.getHeartbeatInterval=function(){return this._heartbeatInterval},e.prototype.setHeartbeatInterval=function(e){return this._heartbeatInterval=e,this},e.prototype.getSubscribeTimeout=function(){return this._subscribeRequestTimeout},e.prototype.setSubscribeTimeout=function(e){return this._subscribeRequestTimeout=e,this},e.prototype.getTransactionTimeout=function(){return this._transactionalRequestTimeout},e.prototype.setTransactionTimeout=function(e){return this._transactionalRequestTimeout=e,this},e.prototype.isSendBeaconEnabled=function(){return this._useSendBeacon},e.prototype.setSendBeaconConfig=function(e){return this._useSendBeacon=e,this},e.prototype.getVersion=function(){return"7.6.1"},e.prototype._setRetryConfiguration=function(e){if(e.minimumdelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(e.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(e.maximumDelay&&maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6");if(e.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10");this.retryConfiguration=e},e.prototype._addPnsdkSuffix=function(e,t){this._PNSDKSuffix[e]=t},e.prototype._getPnsdkSuffix=function(e){var t=this;return Object.keys(this._PNSDKSuffix).reduce((function(n,r){return n+e+t._PNSDKSuffix[r]}),"")},e}();function m(e){var t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;function s(){var e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error("Illegal character at ".concat(i,": ").concat(t.charAt(i-1)));return n}for(var a=0;a>4,f=(15&c)<<4|l>>2,d=(3&l)<<6|p>>0;o[a]=h,64!=l&&(o[a+1]=f),64!=p&&(o[a+2]=d)}return r}function b(e){for(var t,n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=new Uint8Array(e),i=o.byteLength,s=i%3,a=i-s,u=0;u>18]+r[(258048&t)>>12]+r[(4032&t)>>6]+r[63&t];return 1==s?n+=r[(252&(t=o[a]))>>2]+r[(3&t)<<4]+"==":2==s&&(n+=r[(64512&(t=o[a]<<8|o[a+1]))>>10]+r[(1008&t)>>4]+r[(15&t)<<2]+"="),n}var v,_,S,w,O,P=P||function(e,t){var n={},r=n.lib={},o=function(){},i=r.Base={extend:function(e){o.prototype=this;var t=new o;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var o=0;o>>2]|=(n[o>>>2]>>>24-o%4*8&255)<<24-(r+o)%4*8;else if(65535>>2]=n[o>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r>>2]>>>24-r%4*8&255;n.push((o>>>4).toString(16)),n.push((15&o).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,a=o/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,o=e.min(4*t,o),t){for(var u=0;uc;){var l;e:{l=u;for(var p=e.sqrt(l),h=2;h<=p;h++)if(!(l%h)){l=!1;break e}l=!0}l&&(8>c&&(i[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var f=[];o=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],a=n[3],u=n[4],c=n[5],l=n[6],p=n[7],h=0;64>h;h++){if(16>h)f[h]=0|e[t+h];else{var d=f[h-15],y=f[h-2];f[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+f[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+f[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[h]+f[h],y=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=l,l=c,c=u,u=a+d|0,a=i,i=o,o=r,r=d+y|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+p|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(o),t.HmacSHA256=r._createHmacHelper(o)}(Math),_=(v=P).enc.Utf8,v.algo.HMAC=v.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=_.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,a=i.words,u=0;u>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;4>s&&o+.75*s>>6*(3-s)&63));if(t=r.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(r=n.charAt(64))&&-1!=(r=e.indexOf(r))&&(t=r);for(var r=[],o=0,i=0;i>>6-i%4*2;r[o>>>2]|=(s|a)<<24-o%4*8,o++}return w.create(r,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,r,o,i,s){return((e=e+(t&n|~t&r)+o+s)<>>32-i)+t}function n(e,t,n,r,o,i,s){return((e=e+(t&r|n&~r)+o+s)<>>32-i)+t}function r(e,t,n,r,o,i,s){return((e=e+(t^n^r)+o+s)<>>32-i)+t}function o(e,t,n,r,o,i,s){return((e=e+(n^(t|~r))+o+s)<>>32-i)+t}for(var i=P,s=(u=i.lib).WordArray,a=u.Hasher,u=i.algo,c=[],l=0;64>l;l++)c[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=a.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var s=0;16>s;s++){var a=e[u=i+s];e[u]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}s=this._hash.words;var u=e[i+0],l=(a=e[i+1],e[i+2]),p=e[i+3],h=e[i+4],f=e[i+5],d=e[i+6],y=e[i+7],g=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],_=e[i+12],S=e[i+13],w=e[i+14],O=e[i+15],P=t(P=s[0],T=s[1],A=s[2],E=s[3],u,7,c[0]),E=t(E,P,T,A,a,12,c[1]),A=t(A,E,P,T,l,17,c[2]),T=t(T,A,E,P,p,22,c[3]);P=t(P,T,A,E,h,7,c[4]),E=t(E,P,T,A,f,12,c[5]),A=t(A,E,P,T,d,17,c[6]),T=t(T,A,E,P,y,22,c[7]),P=t(P,T,A,E,g,7,c[8]),E=t(E,P,T,A,m,12,c[9]),A=t(A,E,P,T,b,17,c[10]),T=t(T,A,E,P,v,22,c[11]),P=t(P,T,A,E,_,7,c[12]),E=t(E,P,T,A,S,12,c[13]),A=t(A,E,P,T,w,17,c[14]),P=n(P,T=t(T,A,E,P,O,22,c[15]),A,E,a,5,c[16]),E=n(E,P,T,A,d,9,c[17]),A=n(A,E,P,T,v,14,c[18]),T=n(T,A,E,P,u,20,c[19]),P=n(P,T,A,E,f,5,c[20]),E=n(E,P,T,A,b,9,c[21]),A=n(A,E,P,T,O,14,c[22]),T=n(T,A,E,P,h,20,c[23]),P=n(P,T,A,E,m,5,c[24]),E=n(E,P,T,A,w,9,c[25]),A=n(A,E,P,T,p,14,c[26]),T=n(T,A,E,P,g,20,c[27]),P=n(P,T,A,E,S,5,c[28]),E=n(E,P,T,A,l,9,c[29]),A=n(A,E,P,T,y,14,c[30]),P=r(P,T=n(T,A,E,P,_,20,c[31]),A,E,f,4,c[32]),E=r(E,P,T,A,g,11,c[33]),A=r(A,E,P,T,v,16,c[34]),T=r(T,A,E,P,w,23,c[35]),P=r(P,T,A,E,a,4,c[36]),E=r(E,P,T,A,h,11,c[37]),A=r(A,E,P,T,y,16,c[38]),T=r(T,A,E,P,b,23,c[39]),P=r(P,T,A,E,S,4,c[40]),E=r(E,P,T,A,u,11,c[41]),A=r(A,E,P,T,p,16,c[42]),T=r(T,A,E,P,d,23,c[43]),P=r(P,T,A,E,m,4,c[44]),E=r(E,P,T,A,_,11,c[45]),A=r(A,E,P,T,O,16,c[46]),P=o(P,T=r(T,A,E,P,l,23,c[47]),A,E,u,6,c[48]),E=o(E,P,T,A,y,10,c[49]),A=o(A,E,P,T,w,15,c[50]),T=o(T,A,E,P,f,21,c[51]),P=o(P,T,A,E,_,6,c[52]),E=o(E,P,T,A,p,10,c[53]),A=o(A,E,P,T,b,15,c[54]),T=o(T,A,E,P,a,21,c[55]),P=o(P,T,A,E,g,6,c[56]),E=o(E,P,T,A,O,10,c[57]),A=o(A,E,P,T,d,15,c[58]),T=o(T,A,E,P,S,21,c[59]),P=o(P,T,A,E,h,6,c[60]),E=o(E,P,T,A,v,10,c[61]),A=o(A,E,P,T,l,15,c[62]),T=o(T,A,E,P,m,21,c[63]);s[0]=s[0]+P|0,s[1]=s[1]+T|0,s[2]=s[2]+A|0,s[3]=s[3]+E|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var i=e.floor(r/4294967296);for(n[15+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(o+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,r=0;4>r;r++)o=n[r],n[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(u),i.HmacMD5=a._createHmacHelper(u)}(Math),function(){var e,t=P,n=(e=t.lib).Base,r=e.WordArray,o=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),o=r.create(),i=o.words,s=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:u,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var p=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(u=(f.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return p.create({ciphertext:e,salt:n})}},t.SerializableCipher=n.extend({cfg:n.extend({format:u}),encrypt:function(e,t,n,r){r=this.cfg.extend(r);var o=e.createEncryptor(n,r);return t=o.finalize(t),o=o.cfg,p.create({ciphertext:t,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:r.format})},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),e.createDecryptor(n,r).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),f=(f.kdf={}).OpenSSL={execute:function(e,t,n,o){return o||(o=r.random(8)),e=s.create({keySize:t+n}).compute(e,o),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,p.create({key:e,iv:n,salt:o})}},d=t.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:f}),encrypt:function(e,t,n,r){return n=(r=this.cfg.extend(r)).kdf.execute(n,e.keySize,e.ivSize),r.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,r)).mixIn(n),e},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),n=r.kdf.execute(n,e.keySize,e.ivSize,t.salt),r.iv=n.iv,h.decrypt.call(this,e,t,n.key,r)}})}(),function(){for(var e=P,t=e.lib.BlockCipher,n=e.algo,r=[],o=[],i=[],s=[],a=[],u=[],c=[],l=[],p=[],h=[],f=[],d=0;256>d;d++)f[d]=128>d?d<<1:d<<1^283;var y=0,g=0;for(d=0;256>d;d++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;r[y]=m,o[m]=y;var b=f[y],v=f[b],_=f[v],S=257*f[m]^16843008*m;i[y]=S<<24|S>>>8,s[y]=S<<16|S>>>16,a[y]=S<<8|S>>>24,u[y]=S,S=16843009*_^65537*v^257*b^16843008*y,c[m]=S<<24|S>>>8,l[m]=S<<16|S>>>16,p[m]=S<<8|S>>>24,h[m]=S,y?(y=b^f[f[f[_^b]]],g^=f[f[g]]):y=g=1}var w=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),o=this._keySchedule=[],i=0;i>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s]):(s=r[(s=s<<8|s>>>24)>>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s],s^=w[i/t|0]<<24),o[i]=o[i-t]^s}for(e=this._invKeySchedule=[],t=0;tt||4>=i?s:c[r[s>>>24]]^l[r[s>>>16&255]]^p[r[s>>>8&255]]^h[r[255&s]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,s,a,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,c,l,p,h,o),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,r,o,i,s,a){for(var u=this._nRounds,c=e[t]^n[0],l=e[t+1]^n[1],p=e[t+2]^n[2],h=e[t+3]^n[3],f=4,d=1;d>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&h]^n[f++],g=r[l>>>24]^o[p>>>16&255]^i[h>>>8&255]^s[255&c]^n[f++],m=r[p>>>24]^o[h>>>16&255]^i[c>>>8&255]^s[255&l]^n[f++];h=r[h>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^n[f++],c=y,l=g,p=m}y=(a[c>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&h])^n[f++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[h>>>8&255]<<8|a[255&c])^n[f++],m=(a[p>>>24]<<24|a[h>>>16&255]<<16|a[c>>>8&255]<<8|a[255&l])^n[f++],h=(a[h>>>24]<<24|a[c>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^n[f++],e[t]=y,e[t+1]=g,e[t+2]=m,e[t+3]=h},keySize:8});e.AES=t._createHelper(n)}(),P.mode.ECB=((O=P.lib.BlockCipherMode.extend()).Encryptor=O.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),O.Decryptor=O.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),O);var E=P;function A(e){var t,n=[];for(t=0;t=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))},e.prototype.clearHistory=function(){this.hashHistory=[]},e}(),k={PNNetworkUpCategory:"PNNetworkUpCategory",PNNetworkDownCategory:"PNNetworkDownCategory",PNNetworkIssuesCategory:"PNNetworkIssuesCategory",PNTimeoutCategory:"PNTimeoutCategory",PNBadRequestCategory:"PNBadRequestCategory",PNAccessDeniedCategory:"PNAccessDeniedCategory",PNUnknownCategory:"PNUnknownCategory",PNReconnectedCategory:"PNReconnectedCategory",PNConnectedCategory:"PNConnectedCategory",PNRequestMessageCountExceededCategory:"PNRequestMessageCountExceededCategory",PNDisconnectedCategory:"PNDisconnectedCategory",PNConnectionErrorCategory:"PNConnectionErrorCategory",PNDisconnectedUnexpectedlyCategory:"PNDisconnectedUnexpectedlyCategory"},M=function(){function e(e){var t=e.subscribeEndpoint,n=e.leaveEndpoint,r=e.heartbeatEndpoint,o=e.setStateEndpoint,i=e.timeEndpoint,s=e.getFileUrl,a=e.config,u=e.crypto,c=e.listenerManager,l=e.cryptoModule,p=e.eventEmitter;this._listenerManager=c,this._config=a,this._leaveEndpoint=n,this._heartbeatEndpoint=r,this._setStateEndpoint=o,this._subscribeEndpoint=t,this._getFileUrl=s,this._crypto=u,this._cryptoModule=l,this._channels={},this._presenceChannels={},this._heartbeatChannels={},this._heartbeatChannelGroups={},this._channelGroups={},this._presenceChannelGroups={},this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[],this._currentTimetoken=0,this._lastTimetoken=0,this._storedTimetoken=null,this._subscriptionStatusAnnounced=!1,this._isOnline=!0,this._reconnectionManager=new N({timeEndpoint:i}),this._dedupingManager=new C({config:a}),this._cryptoModule&&(this._decoder=new TextDecoder),this._eventEmitter=p}return e.prototype.adaptStateChange=function(e,t){var n=this,r=e.state,o=e.channels,i=void 0===o?[]:o,s=e.channelGroups,a=void 0===s?[]:s,u=e.withHeartbeat,c=void 0!==u&&u;if(i.forEach((function(e){e in n._channels&&(n._channels[e].state=r)})),a.forEach((function(e){e in n._channelGroups&&(n._channelGroups[e].state=r)})),c){var l={};return i.forEach((function(e){return l[e]=r})),a.forEach((function(e){return l[e]=r})),this._heartbeatEndpoint({channels:i,channelGroups:a,state:l},t)}return this._setStateEndpoint({state:r,channels:i,channelGroups:a},t)},e.prototype.adaptPresenceChange=function(e){var t=this,n=e.connected,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i;n?(o.forEach((function(e){t._heartbeatChannels[e]={state:{}}})),s.forEach((function(e){t._heartbeatChannelGroups[e]={state:{}}}))):(o.forEach((function(e){e in t._heartbeatChannels&&delete t._heartbeatChannels[e]})),s.forEach((function(e){e in t._heartbeatChannelGroups&&delete t._heartbeatChannelGroups[e]})),!1===this._config.suppressLeaveEvents&&this._leaveEndpoint({channels:o,channelGroups:s},(function(e){t._listenerManager.announceStatus(e)}))),this.reconnect()},e.prototype.adaptSubscribeChange=function(e){var t=this,n=e.timetoken,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=e.withPresence,u=void 0!==a&&a,c=e.withHeartbeats,l=void 0!==c&&c;this._config.subscribeKey&&""!==this._config.subscribeKey?(n&&(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=n),"0"!==this._currentTimetoken&&0!==this._currentTimetoken&&(this._storedTimetoken=this._currentTimetoken,this._currentTimetoken=0),o.forEach((function(e){t._channels[e]={state:{}},u&&(t._presenceChannels[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannels[e]={}),t._pendingChannelSubscriptions.push(e)})),s.forEach((function(e){t._channelGroups[e]={state:{}},u&&(t._presenceChannelGroups[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannelGroups[e]={}),t._pendingChannelGroupSubscriptions.push(e)})),this._subscriptionStatusAnnounced=!1,this.reconnect()):console&&console.log&&console.log("subscribe key missing; aborting subscribe")},e.prototype.adaptUnsubscribeChange=function(e,t){var n=this,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=[],u=[];o.forEach((function(e){e in n._channels&&(delete n._channels[e],a.push(e),e in n._heartbeatChannels&&delete n._heartbeatChannels[e]),e in n._presenceChannels&&(delete n._presenceChannels[e],a.push(e))})),s.forEach((function(e){e in n._channelGroups&&(delete n._channelGroups[e],u.push(e),e in n._heartbeatChannelGroups&&delete n._heartbeatChannelGroups[e]),e in n._presenceChannelGroups&&(delete n._presenceChannelGroups[e],u.push(e))})),0===a.length&&0===u.length||(!1!==this._config.suppressLeaveEvents||t||this._leaveEndpoint({channels:a,channelGroups:u},(function(e){e.affectedChannels=a,e.affectedChannelGroups=u,e.currentTimetoken=n._currentTimetoken,e.lastTimetoken=n._lastTimetoken,n._listenerManager.announceStatus(e)})),0===Object.keys(this._channels).length&&0===Object.keys(this._presenceChannels).length&&0===Object.keys(this._channelGroups).length&&0===Object.keys(this._presenceChannelGroups).length&&(this._lastTimetoken=0,this._currentTimetoken=0,this._storedTimetoken=null,this._region=null,this._reconnectionManager.stopPolling()),this.reconnect())},e.prototype.unsubscribeAll=function(e){this.adaptUnsubscribeChange({channels:this.getSubscribedChannels(),channelGroups:this.getSubscribedChannelGroups()},e)},e.prototype.getHeartbeatChannels=function(){return Object.keys(this._heartbeatChannels)},e.prototype.getHeartbeatChannelGroups=function(){return Object.keys(this._heartbeatChannelGroups)},e.prototype.getSubscribedChannels=function(){return Object.keys(this._channels)},e.prototype.getSubscribedChannelGroups=function(){return Object.keys(this._channelGroups)},e.prototype.reconnect=function(){this._startSubscribeLoop(),this._registerHeartbeatTimer()},e.prototype.disconnect=function(){this._stopSubscribeLoop(),this._stopHeartbeatTimer(),this._reconnectionManager.stopPolling()},e.prototype._registerHeartbeatTimer=function(){this._stopHeartbeatTimer(),0!==this._config.getHeartbeatInterval()&&void 0!==this._config.getHeartbeatInterval()&&(this._performHeartbeatLoop(),this._heartbeatTimer=setInterval(this._performHeartbeatLoop.bind(this),1e3*this._config.getHeartbeatInterval()))},e.prototype._stopHeartbeatTimer=function(){this._heartbeatTimer&&(clearInterval(this._heartbeatTimer),this._heartbeatTimer=null)},e.prototype._performHeartbeatLoop=function(){var e=this,t=this.getHeartbeatChannels(),n=this.getHeartbeatChannelGroups(),r={};if(0!==t.length||0!==n.length){this.getSubscribedChannels().forEach((function(t){var n=e._channels[t].state;Object.keys(n).length&&(r[t]=n)})),this.getSubscribedChannelGroups().forEach((function(t){var n=e._channelGroups[t].state;Object.keys(n).length&&(r[t]=n)}));this._heartbeatEndpoint({channels:t,channelGroups:n,state:r},function(t){t.error&&e._config.announceFailedHeartbeats&&e._listenerManager.announceStatus(t),t.error&&e._config.autoNetworkDetection&&e._isOnline&&(e._isOnline=!1,e.disconnect(),e._listenerManager.announceNetworkDown(),e.reconnect()),!t.error&&e._config.announceSuccessfulHeartbeats&&e._listenerManager.announceStatus(t)}.bind(this))}},e.prototype._startSubscribeLoop=function(){var e=this;this._stopSubscribeLoop();var t={},n=[],r=[];if(Object.keys(this._channels).forEach((function(r){var o=e._channels[r].state;Object.keys(o).length&&(t[r]=o),n.push(r)})),Object.keys(this._presenceChannels).forEach((function(e){n.push("".concat(e,"-pnpres"))})),Object.keys(this._channelGroups).forEach((function(n){var o=e._channelGroups[n].state;Object.keys(o).length&&(t[n]=o),r.push(n)})),Object.keys(this._presenceChannelGroups).forEach((function(e){r.push("".concat(e,"-pnpres"))})),0!==n.length||0!==r.length){var o={channels:n,channelGroups:r,state:t,timetoken:this._currentTimetoken,filterExpression:this._config.filterExpression,region:this._region};this._subscribeCall=this._subscribeEndpoint(o,this._processSubscribeResponse.bind(this))}},e.prototype._processSubscribeResponse=function(e,t){var n=this;if(e.error){if(e.errorData&&"Aborted"===e.errorData.message)return;e.category===k.PNTimeoutCategory?this._startSubscribeLoop():e.category===k.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this._config.autoNetworkDetection&&this._isOnline&&(this._isOnline=!1,this._listenerManager.announceNetworkDown()),this._reconnectionManager.onReconnection((function(){n._config.autoNetworkDetection&&!n._isOnline&&(n._isOnline=!0,n._listenerManager.announceNetworkUp()),n.reconnect(),n._subscriptionStatusAnnounced=!0;var t={category:k.PNReconnectedCategory,operation:e.operation,lastTimetoken:n._lastTimetoken,currentTimetoken:n._currentTimetoken};n._listenerManager.announceStatus(t)})),this._reconnectionManager.startPolling(),this._listenerManager.announceStatus(e)):e.category===k.PNBadRequestCategory?(this._stopHeartbeatTimer(),this._listenerManager.announceStatus(e)):this._listenerManager.announceStatus(e)}else{if(this._storedTimetoken?(this._currentTimetoken=this._storedTimetoken,this._storedTimetoken=null):(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=t.metadata.timetoken),!this._subscriptionStatusAnnounced){var r={};r.category=k.PNConnectedCategory,r.operation=e.operation,r.affectedChannels=this._pendingChannelSubscriptions,r.subscribedChannels=this.getSubscribedChannels(),r.affectedChannelGroups=this._pendingChannelGroupSubscriptions,r.lastTimetoken=this._lastTimetoken,r.currentTimetoken=this._currentTimetoken,this._subscriptionStatusAnnounced=!0,this._listenerManager.announceStatus(r),this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[]}var o=t.messages||[],i=this._config,s=i.requestMessageCountThreshold,a=i.dedupeOnSubscribe;if(s&&o.length>=s){var u={};u.category=k.PNRequestMessageCountExceededCategory,u.operation=e.operation,this._listenerManager.announceStatus(u)}o.forEach((function(e){if(e.channel,e.subscriptionMatch,a){if(n._dedupingManager.isDuplicate(e))return;n._dedupingManager.addEntry(e)}n._eventEmitter.emitEvent(e)})),this._region=t.metadata.region,this._startSubscribeLoop()}},e.prototype._stopSubscribeLoop=function(){this._subscribeCall&&("function"==typeof this._subscribeCall.abort&&this._subscribeCall.abort(),this._subscribeCall=null)},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),j={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",PNAccessManagerRevokeToken:"PNAccessManagerRevokeToken",PNHandshakeOperation:"PNHandshakeOperation",PNReceiveMessagesOperation:"PNReceiveMessagesOperation"},R=function(){function e(e){this._maximumSamplesCount=100,this._trackedLatencies={},this._latencies={},this._telemetryExcludeOperations=[j.PNSubscribeOperation,j.PNReceiveMessagesOperation,j.PNHandshakeOperation],this._maximumSamplesCount=e.maximumSamplesCount||this._maximumSamplesCount}return e.prototype.operationsLatencyForRequest=function(){var e=this,t={};return Object.keys(this._latencies).forEach((function(n){var r=e._latencies[n],o=e._averageLatency(r);o>0&&(t["l_".concat(n)]=o)})),t},e.prototype.startLatencyMeasure=function(e,t){!this._telemetryExcludeOperations.includes(e)&&t&&(this._trackedLatencies[t]=Date.now())},e.prototype.stopLatencyMeasure=function(e,t){if(!this._telemetryExcludeOperations.includes(e)&&t){var n=this._endpointName(e),r=this._latencies[n],o=this._trackedLatencies[t];r||(this._latencies[n]=[],r=this._latencies[n]),r.push(Date.now()-o),r.length>this._maximumSamplesCount&&r.splice(0,r.length-this._maximumSamplesCount),delete this._trackedLatencies[t]}},e.prototype._averageLatency=function(e){return Math.floor(e.reduce((function(e,t){return e+t}),0)/e.length)},e.prototype._endpointName=function(e){var t=null;switch(e){case j.PNPublishOperation:t="pub";break;case j.PNSignalOperation:t="sig";break;case j.PNHistoryOperation:case j.PNFetchMessagesOperation:case j.PNDeleteMessagesOperation:case j.PNMessageCounts:t="hist";break;case j.PNUnsubscribeOperation:case j.PNWhereNowOperation:case j.PNHereNowOperation:case j.PNHeartbeatOperation:case j.PNSetStateOperation:case j.PNGetStateOperation:t="pres";break;case j.PNAddChannelsToGroupOperation:case j.PNRemoveChannelsFromGroupOperation:case j.PNChannelGroupsOperation:case j.PNRemoveGroupOperation:case j.PNChannelsForGroupOperation:t="cg";break;case j.PNPushNotificationEnabledChannelsOperation:case j.PNRemoveAllPushNotificationsOperation:t="push";break;case j.PNCreateUserOperation:case j.PNUpdateUserOperation:case j.PNDeleteUserOperation:case j.PNGetUserOperation:case j.PNGetUsersOperation:case j.PNCreateSpaceOperation:case j.PNUpdateSpaceOperation:case j.PNDeleteSpaceOperation:case j.PNGetSpaceOperation:case j.PNGetSpacesOperation:case j.PNGetMembersOperation:case j.PNUpdateMembersOperation:case j.PNGetMembershipsOperation:case j.PNUpdateMembershipsOperation:t="obj";break;case j.PNAddMessageActionOperation:case j.PNRemoveMessageActionOperation:case j.PNGetMessageActionsOperation:t="msga";break;case j.PNAccessManagerGrant:case j.PNAccessManagerAudit:t="pam";break;case j.PNAccessManagerGrantToken:case j.PNAccessManagerRevokeToken:t="pamv3";break;default:t="time"}return t},e}(),x=function(){function e(e,t,n){this._payload=e,this._setDefaultPayloadStructure(),this.title=t,this.body=n}return Object.defineProperty(e.prototype,"payload",{get:function(){return this._payload},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{set:function(e){this._title=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{set:function(e){this._subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{set:function(e){this._body=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{set:function(e){this._badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{set:function(e){this._sound=e},enumerable:!1,configurable:!0}),e.prototype._setDefaultPayloadStructure=function(){},e.prototype.toObject=function(){return{}},e}(),U=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"configurations",{set:function(e){e&&e.length&&(this._configurations=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"notification",{get:function(){return this._payload.aps},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.aps.alert.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){e&&e.length&&(this._payload.aps.alert.subtitle=e,this._subtitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.aps.alert.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this._badge},set:function(e){null!=e&&(this._payload.aps.badge=e,this._badge=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.aps.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),r.prototype._setDefaultPayloadStructure=function(){this._payload.aps={alert:{}}},r.prototype.toObject=function(){var e=this,t=n({},this._payload),r=t.aps,o=r.alert;if(this._isSilent&&(r["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");var i=[];this._configurations.forEach((function(t){i.push(e._objectFromAPNS2Configuration(t))})),i.length&&(t.pn_push=i)}return o&&Object.keys(o).length||delete r.alert,this._isSilent&&(delete r.alert,delete r.badge,delete r.sound,o={}),this._isSilent||Object.keys(o).length?t:null},r.prototype._objectFromAPNS2Configuration=function(e){var t=this;if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");var n=[];e.targets.forEach((function(e){n.push(t._objectFromAPNSTarget(e))}));var r=e.collapseId,o=e.expirationDate,i={auth_method:"token",targets:n,version:"v2"};return r&&r.length&&(i.collapse_id=r),o&&(i.expiration=o.toISOString()),i},r.prototype._objectFromAPNSTarget=function(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");var t=e.topic,n=e.environment,r=void 0===n?"development":n,o=e.excludedDevices,i=void 0===o?[]:o,s={topic:t,environment:r};return i.length&&(s.excluded_devices=i),s},r}(x),I=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"backContent",{get:function(){return this._backContent},set:function(e){e&&e.length&&(this._payload.back_content=e,this._backContent=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"backTitle",{get:function(){return this._backTitle},set:function(e){e&&e.length&&(this._payload.back_title=e,this._backTitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"count",{get:function(){return this._count},set:function(e){null!=e&&(this._payload.count=e,this._count=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"type",{get:function(){return this._type},set:function(e){e&&e.length&&(this._payload.type=e,this._type=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this.backTitle},set:function(e){this.backTitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this.backContent},set:function(e){this.backContent=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this.count},set:function(e){this.count=e},enumerable:!1,configurable:!0}),r.prototype.toObject=function(){return Object.keys(this._payload).length?n({},this._payload):null},r}(x),D=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return t(o,e),Object.defineProperty(o.prototype,"notification",{get:function(){return this._payload.notification},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"data",{get:function(){return this._payload.data},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.notification.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.notification.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.notification.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"icon",{get:function(){return this._icon},set:function(e){e&&e.length&&(this._payload.notification.icon=e,this._icon=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"tag",{get:function(){return this._tag},set:function(e){e&&e.length&&(this._payload.notification.tag=e,this._tag=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),o.prototype._setDefaultPayloadStructure=function(){this._payload.notification={},this._payload.data={}},o.prototype.toObject=function(){var e=n({},this._payload.data),t=null,o={};if(Object.keys(this._payload).length>2){var i=this._payload;i.notification,i.data;var s=r(i,["notification","data"]);e=n(n({},e),s)}return this._isSilent?e.notification=this._payload.notification:t=this._payload.notification,Object.keys(e).length&&(o.data=e),t&&Object.keys(t).length&&(o.notification=t),Object.keys(o).length?o:null},o}(x),F=function(){function e(e,t){this._payload={apns:{},mpns:{},fcm:{}},this._title=e,this._body=t,this.apns=new U(this._payload.apns,e,t),this.mpns=new I(this._payload.mpns,e,t),this.fcm=new D(this._payload.fcm,e,t)}return Object.defineProperty(e.prototype,"debugging",{set:function(e){this._debugging=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this._body},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){this._subtitle=e,this.apns.subtitle=e,this.mpns.subtitle=e,this.fcm.subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{get:function(){return this._badge},set:function(e){this._badge=e,this.apns.badge=e,this.mpns.badge=e,this.fcm.badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{get:function(){return this._sound},set:function(e){this._sound=e,this.apns.sound=e,this.mpns.sound=e,this.fcm.sound=e},enumerable:!1,configurable:!0}),e.prototype.buildPayload=function(e){var t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";var n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("mpns")){var r=this.mpns.toObject();r&&Object.keys(r).length&&(t.pn_mpns=r)}if(e.includes("fcm")){var o=this.fcm.toObject();o&&Object.keys(o).length&&(t.pn_gcm=o)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t},e}(),L=function(){function e(){this._listeners=[]}return e.prototype.addListener=function(e){this._listeners.includes(e)||this._listeners.push(e)},e.prototype.removeListener=function(e){var t=[];this._listeners.forEach((function(n){n!==e&&t.push(n)})),this._listeners=t},e.prototype.removeAllListeners=function(){this._listeners=[]},e.prototype.announcePresence=function(e){this._listeners.forEach((function(t){t.presence&&t.presence(e)}))},e.prototype.announceStatus=function(e){this._listeners.forEach((function(t){t.status&&t.status(e)}))},e.prototype.announceMessage=function(e){this._listeners.forEach((function(t){t.message&&t.message(e)}))},e.prototype.announceSignal=function(e){this._listeners.forEach((function(t){t.signal&&t.signal(e)}))},e.prototype.announceMessageAction=function(e){this._listeners.forEach((function(t){t.messageAction&&t.messageAction(e)}))},e.prototype.announceFile=function(e){this._listeners.forEach((function(t){t.file&&t.file(e)}))},e.prototype.announceObjects=function(e){this._listeners.forEach((function(t){t.objects&&t.objects(e)}))},e.prototype.announceUser=function(e){this._listeners.forEach((function(t){t.user&&t.user(e)}))},e.prototype.announceSpace=function(e){this._listeners.forEach((function(t){t.space&&t.space(e)}))},e.prototype.announceMembership=function(e){this._listeners.forEach((function(t){t.membership&&t.membership(e)}))},e.prototype.announceNetworkUp=function(){var e={};e.category=k.PNNetworkUpCategory,this.announceStatus(e)},e.prototype.announceNetworkDown=function(){var e={};e.category=k.PNNetworkDownCategory,this.announceStatus(e)},e}(),G=function(){function e(e,t){this._config=e,this._cbor=t}return e.prototype.setToken=function(e){e&&e.length>0?this._token=e:this._token=void 0},e.prototype.getToken=function(){return this._token},e.prototype.extractPermissions=function(e){var t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128==(128&e)&&(t.join=!0),64==(64&e)&&(t.update=!0),32==(32&e)&&(t.get=!0),8==(8&e)&&(t.delete=!0),4==(4&e)&&(t.manage=!0),2==(2&e)&&(t.write=!0),1==(1&e)&&(t.read=!0),t},e.prototype.parseToken=function(e){var t=this,n=this._cbor.decodeToken(e);if(void 0!==n){var r=n.res.uuid?Object.keys(n.res.uuid):[],o=Object.keys(n.res.chan),i=Object.keys(n.res.grp),s=n.pat.uuid?Object.keys(n.pat.uuid):[],a=Object.keys(n.pat.chan),u=Object.keys(n.pat.grp),c={version:n.v,timestamp:n.t,ttl:n.ttl,authorized_uuid:n.uuid},l=r.length>0,p=o.length>0,h=i.length>0;(l||p||h)&&(c.resources={},l&&(c.resources.uuids={},r.forEach((function(e){c.resources.uuids[e]=t.extractPermissions(n.res.uuid[e])}))),p&&(c.resources.channels={},o.forEach((function(e){c.resources.channels[e]=t.extractPermissions(n.res.chan[e])}))),h&&(c.resources.groups={},i.forEach((function(e){c.resources.groups[e]=t.extractPermissions(n.res.grp[e])}))));var f=s.length>0,d=a.length>0,y=u.length>0;return(f||d||y)&&(c.patterns={},f&&(c.patterns.uuids={},s.forEach((function(e){c.patterns.uuids[e]=t.extractPermissions(n.pat.uuid[e])}))),d&&(c.patterns.channels={},a.forEach((function(e){c.patterns.channels[e]=t.extractPermissions(n.pat.chan[e])}))),y&&(c.patterns.groups={},u.forEach((function(e){c.patterns.groups[e]=t.extractPermissions(n.pat.grp[e])})))),Object.keys(n.meta).length>0&&(c.meta=n.meta),c.signature=n.sig,c}},e}();function K(e){return encodeURIComponent(e).replace(/[!~*'()]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())}))}function B(e){return function(e){var t=[];return Object.keys(e).forEach((function(e){return t.push(e)})),t}(e).sort()}var H={signPamFromParams:function(e){return B(e).map((function(t){return"".concat(t,"=").concat(K(e[t]))})).join("&")},endsWith:function(e,t){return-1!==e.indexOf(t,this.length-t.length)},createPromise:function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),reject:t,fulfill:e}},encodeString:K,stringToArrayBuffer:function(e){for(var t=new ArrayBuffer(2*e.length),n=new Uint16Array(t),r=0,o=e.length;r0&&(t+=n),t}function J(e,t,n){return t.usePost&&t.usePost(e,n)?"POST":t.usePatch&&t.usePatch(e,n)?"PATCH":t.useDelete&&t.useDelete(e,n)?"DELETE":t.useGetFile&&t.useGetFile(e,n)?"GETFILE":"GET"}function $(e,t,n,r,o){var i=e.config,s=e.crypto,a=J(e,o,r);n.timestamp=Math.floor((new Date).getTime()/1e3),"PNPublishOperation"===o.getOperation()&&o.usePost&&o.usePost(e,r)&&(a="GET"),"GETFILE"===a&&(a="GET");var u="".concat(a,"\n").concat(i.publishKey,"\n").concat(t,"\n").concat(H.signPamFromParams(n),"\n");if("POST"===a)u+="string"==typeof(c=o.postPayload(e,r))?c:JSON.stringify(c);else if("PATCH"===a){var c;u+="string"==typeof(c=o.patchPayload(e,r))?c:JSON.stringify(c)}var l="v2.".concat(s.HMACSHA256(u));l=(l=(l=l.replace(/\+/g,"-")).replace(/\//g,"_")).replace(/=+$/,""),n.signature=l}function Q(e,t){for(var r=[],o=2;o0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/leave")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(){return{}}});var ae=Object.freeze({__proto__:null,getOperation:function(){return j.PNWhereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r;return"/v2/presence/sub-key/".concat(n.subscribeKey,"/uuid/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return t.payload?{channels:t.payload.channels}:{channels:[]}}});var ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNHeartbeatOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/heartbeat")},isAuthSupported:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o=t.state,i=e.config,s={};return r.length>0&&(s["channel-group"]=r.join(",")),o&&(s.state=JSON.stringify(o)),s.heartbeat=i.getPresenceTimeout(),s},handleResponse:function(){return{}}});var ce=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetStateOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r,i=t.channels,s=void 0===i?[]:i,a=s.length>0?s.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(a),"/uuid/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a={};return 1===o.length&&0===s.length?a[o[0]]=t.payload:a=t.payload,{channels:a}}});var le=Object.freeze({__proto__:null,getOperation:function(){return j.PNSetStateOperation},validateParams:function(e,t){var n=e.config,r=t.state,o=t.channels,i=void 0===o?[]:o,s=t.channelGroups,a=void 0===s?[]:s;return r?n.subscribeKey?0===i.length&&0===a.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key":"Missing State"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/uuid/").concat(H.encodeString(n.UUID),"/data")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.state,r=t.channelGroups,o=void 0===r?[]:r,i={};return i.state=JSON.stringify(n),o.length>0&&(i["channel-group"]=o.join(",")),i},handleResponse:function(e,t){return{state:t.payload}}});var pe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=t.channelGroups,s=void 0===i?[]:i,a="/v2/presence/sub-key/".concat(n.subscribeKey);if(o.length>0||s.length>0){var u=o.length>0?o.join(","):",";a+="/channel/".concat(H.encodeString(u))}return a},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.channelGroups,o=void 0===r?[]:r,i=t.includeUUIDs,s=void 0===i||i,a=t.includeState,u=void 0!==a&&a,c=t.queryParameters,l=void 0===c?{}:c,p={};return s||(p.disable_uuids=1),u&&(p.state=1),o.length>0&&(p["channel-group"]=o.join(",")),p=n(n({},p),l)},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a=n.includeUUIDs,u=void 0===a||a,c=n.includeState,l=void 0!==c&&c;return o.length>1||s.length>0||0===s.length&&0===o.length?function(){var e={};return e.totalChannels=t.payload.total_channels,e.totalOccupancy=t.payload.total_occupancy,e.channels={},Object.keys(t.payload.channels).forEach((function(n){var r=t.payload.channels[n],o=[];return e.channels[n]={occupants:o,name:n,occupancy:r.occupancy},u&&r.uuids.forEach((function(e){l?o.push({state:e.state,uuid:e.uuid}):o.push({state:null,uuid:e})})),e})),e}():function(){var e={},n=[];return e.totalChannels=1,e.totalOccupancy=t.occupancy,e.channels={},e.channels[o[0]]={occupants:n,name:o[0],occupancy:t.occupancy},u&&t.uuids&&t.uuids.forEach((function(e){l?n.push({state:e.state,uuid:e.uuid}):n.push({state:null,uuid:e})})),e}()},handleError:function(e,t,n){402!==n.statusCode||this.getURL(e,t).includes("channel")||(n.errorData.message="You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.")}});var he=Object.freeze({__proto__:null,getOperation:function(){return j.PNAddMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.action,o=t.channel;return t.messageTimetoken?n.subscribeKey?o?r?r.value?r.type?r.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message channel":"Missing Subscribe Key":"Missing message timetoken"},usePost:function(){return!0},postURL:function(e,t){var n=e.config,r=t.channel,o=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},getRequestHeaders:function(){return{"Content-Type":"application/json"}},isAuthSupported:function(){return!0},prepareParams:function(){return{}},postPayload:function(e,t){return t.action},handleResponse:function(e,t){return{data:t.data}}});var fe=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken;return t.messageTimetoken?o?n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key":"Missing action timetoken":"Missing message timetoken"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken,i=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(i,"/action/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{data:t.data}}});var de=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetMessageActionsOperation},validateParams:function(e,t){var n=e.config,r=t.channel;return n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channel;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.limit,r=t.start,o=t.end,i={};return n&&(i.limit=n),r&&(i.start=r),o&&(i.end=o),i},handleResponse:function(e,t){var n={data:t.data,start:null,end:null};return n.data.length&&(n.end=n.data[n.data.length-1].actionTimetoken,n.start=n.data[0].actionTimetoken),n}}),ye={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel can't be empty"},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.limit&&(n.limit=t.limit),t.next&&(n.next=t.next),n},handleResponse:function(e,t){return{status:t.status,data:t.data,next:t.next,count:t.count}}},ge={getOperation:function(){return j.PNGenerateUploadUrlOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?void 0:"name can't be empty":"channel can't be empty"},usePost:function(){return!0},postURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/generate-upload-url")},postPayload:function(e,t){return{name:t.name}},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data,file_upload_request:t.file_upload_request}}},me={getOperation:function(){return j.PNPublishFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.fileId)?(null==t?void 0:t.fileName)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},getURL:function(e,t){var n=e.config,r=n.publishKey,o=n.subscribeKey,i=function(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}(e,{message:t.message,file:{name:t.fileName,id:t.fileId}});return"/v1/files/publish-file/".concat(r,"/").concat(o,"/0/").concat(H.encodeString(t.channel),"/0/").concat(H.encodeString(i))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.ttl&&(n.ttl=t.ttl),void 0!==t.storeInHistory&&(n.store=t.storeInHistory?"1":"0"),t.meta&&"object"==typeof t.meta&&(n.meta=JSON.stringify(t.meta)),n},handleResponse:function(e,t){return{timetoken:t[2]}}},be=function(e){var t=function(e){var t=this,n=e.generateUploadUrl,r=e.publishFile,s=e.modules,a=s.PubNubFile,u=s.config,c=s.cryptography,l=s.cryptoModule,p=s.networking;return function(e){var s=e.channel,h=e.file,f=e.message,d=e.cipherKey,y=e.meta,g=e.ttl,m=e.storeInHistory;return o(t,void 0,void 0,(function(){var e,t,o,b,v,_,S,w,O,P,E,A,T,N,C,k,M,j,R,x,U,I,D,F,L,G,K,B,H;return i(this,(function(i){switch(i.label){case 0:if(!s)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!h)throw new q("Validation failed, check status for details",z("file can't be empty"));return e=a.create(h),[4,n({channel:s,name:e.name})];case 1:return t=i.sent(),o=t.file_upload_request,b=o.url,v=o.form_fields,_=t.data,S=_.id,w=_.name,a.supportsEncryptFile&&(d||l)?null!=d?[3,3]:[4,l.encryptFile(e,a)]:[3,6];case 2:return O=i.sent(),[3,5];case 3:return[4,c.encryptFile(d,e,a)];case 4:O=i.sent(),i.label=5;case 5:e=O,i.label=6;case 6:P=v,e.mimeType&&(P=v.map((function(t){return"Content-Type"===t.key?{key:t.key,value:e.mimeType}:t}))),i.label=7;case 7:return i.trys.push([7,21,,22]),a.supportsFileUri&&h.uri?(T=(A=p).POSTFILE,N=[b,P],[4,e.toFileUri()]):[3,10];case 8:return[4,T.apply(A,N.concat([i.sent()]))];case 9:return E=i.sent(),[3,20];case 10:return a.supportsFile?(k=(C=p).POSTFILE,M=[b,P],[4,e.toFile()]):[3,13];case 11:return[4,k.apply(C,M.concat([i.sent()]))];case 12:return E=i.sent(),[3,20];case 13:return a.supportsBuffer?(R=(j=p).POSTFILE,x=[b,P],[4,e.toBuffer()]):[3,16];case 14:return[4,R.apply(j,x.concat([i.sent()]))];case 15:return E=i.sent(),[3,20];case 16:return a.supportsBlob?(I=(U=p).POSTFILE,D=[b,P],[4,e.toBlob()]):[3,19];case 17:return[4,I.apply(U,D.concat([i.sent()]))];case 18:return E=i.sent(),[3,20];case 19:throw new Error("Unsupported environment");case 20:return[3,22];case 21:throw(F=i.sent()).response&&"string"==typeof F.response.text?(L=F.response.text,G=/(.*)<\/Message>/gi.exec(L),new q(G?"Upload to bucket failed: ".concat(G[1]):"Upload to bucket failed.",F)):new q("Upload to bucket failed.",F);case 22:if(204!==E.status)throw new q("Upload to bucket was unsuccessful",E);K=u.fileUploadPublishRetryLimit,B=!1,H={timetoken:"0"},i.label=23;case 23:return i.trys.push([23,25,,26]),[4,r({channel:s,message:f,fileId:S,fileName:w,meta:y,storeInHistory:m,ttl:g})];case 24:return H=i.sent(),B=!0,[3,26];case 25:return i.sent(),K-=1,[3,26];case 26:if(!B&&K>0)return[3,23];i.label=27;case 27:if(B)return[2,{timetoken:H.timetoken,id:S,name:w}];throw new q("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{channel:s,id:S,name:w})}}))}))}}(e);return function(e,n){var r=t(e);return"function"==typeof n?(r.then((function(e){return n(null,e)})).catch((function(e){return n(e,null)})),r):r}},ve=function(e,t){var n=t.channel,r=t.id,o=t.name,i=e.config,s=e.networking,a=e.tokenManager;if(!n)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!r)throw new q("Validation failed, check status for details",z("file id can't be empty"));if(!o)throw new q("Validation failed, check status for details",z("file name can't be empty"));var u="/v1/files/".concat(i.subscribeKey,"/channels/").concat(H.encodeString(n),"/files/").concat(r,"/").concat(o),c={};c.uuid=i.getUUID(),c.pnsdk=W(i);var l=a.getToken()||i.getAuthKey();l&&(c.auth=l),i.secretKey&&$(e,u,c,{},{getOperation:function(){return"PubNubGetFileUrlOperation"}});var p=Object.keys(c).map((function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(c[e]))})).join("&");return""!==p?"".concat(s.getStandardOrigin()).concat(u,"?").concat(p):"".concat(s.getStandardOrigin()).concat(u)},_e={getOperation:function(){return j.PNDownloadFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?(null==t?void 0:t.id)?void 0:"id can't be empty":"name can't be empty":"channel can't be empty"},useGetFile:function(){return!0},getFileURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},ignoreBody:function(){return!0},forceBuffered:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t,n){var r=e.PubNubFile,s=e.config,a=e.cryptography,u=e.cryptoModule;return o(void 0,void 0,void 0,(function(){var e,o,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.response.body,r.supportsEncryptFile&&(n.cipherKey||u)?null!=n.cipherKey?[3,2]:[4,u.decryptFile(r.create({data:e,name:n.name}),r)]:[3,5];case 1:return o=i.sent().data,[3,4];case 2:return[4,a.decrypt(null!==(c=n.cipherKey)&&void 0!==c?c:s.cipherKey,e)];case 3:o=i.sent(),i.label=4;case 4:e=o,i.label=5;case 5:return[2,r.create({data:e,name:null!==(l=t.response.name)&&void 0!==l?l:n.name,mimeType:t.response.type})]}}))}))}},Se={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.id)?(null==t?void 0:t.name)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status}}},we={getOperation:function(){return j.PNGetAllUUIDMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,next:t.next,prev:t.prev}}},Oe={getOperation:function(){return j.PNGetUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Pe={getOperation:function(){return j.PNSetUUIDMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.data))return"Data cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ee={getOperation:function(){return j.PNRemoveUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r=e.config;return{uuid:null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ae={getOperation:function(){return j.PNGetAllChannelMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Te={getOperation:function(){return j.PNGetChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ne={getOperation:function(){return j.PNSetChannelMetadataOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.data)?void 0:"Data cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ce={getOperation:function(){return j.PNRemoveChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},ke={getOperation:function(){return j.PNGetMembersOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&m.include.push("uuid"),(null===(i=t.include)||void 0===i?void 0:i.customUUIDFields)&&m.include.push("uuid.custom"),(null===(s=t.include)||void 0===s?void 0:s.UUIDStatusField)&&m.include.push("uuid.status"),(null===(u=t.include)||void 0===u?void 0:u.UUIDTypeField)&&m.include.push("uuid.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Me={getOperation:function(){return j.PNSetMembersOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.uuids)&&0!==(null==t?void 0:t.uuids.length)?void 0:"UUIDs cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.uuids.map((function(e){return"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["uuid.status","uuid.type","type"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customUUIDFields)&&h.include.push("uuid.custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&h.include.push("uuid")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},je={getOperation:function(){return j.PNGetMembershipsOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&m.include.push("channel"),(null===(i=t.include)||void 0===i?void 0:i.customChannelFields)&&m.include.push("channel.custom"),(null===(s=t.include)||void 0===s?void 0:s.channelStatusField)&&m.include.push("channel.status"),(null===(u=t.include)||void 0===u?void 0:u.channelTypeField)&&m.include.push("channel.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Re={getOperation:function(){return j.PNSetMembershipsOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)||0===(null==t?void 0:t.channels.length))return"Channels cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.channels.map((function(e){return"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["channel.status","channel.type","status"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customChannelFields)&&h.include.push("channel.custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&h.include.push("channel")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}};var xe=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerAudit},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/audit/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channel,r=t.channelGroup,o=t.authKeys,i=void 0===o?[]:o,s={};return n&&(s.channel=n),r&&(s["channel-group"]=r),i.length>0&&(s.auth=i.join(",")),s},handleResponse:function(e,t){return t.payload}});var Ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrant},validateParams:function(e,t){var n=e.config;return n.subscribeKey?n.publishKey?n.secretKey?null==t.uuids||t.authKeys?null==t.uuids||null==t.channels&&null==t.channelGroups?void 0:"Both channel/channelgroup and uuid cannot be used in the same request":"authKeys are required for grant request on uuids":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/grant/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.uuids,a=void 0===s?[]:s,u=t.ttl,c=t.read,l=void 0!==c&&c,p=t.write,h=void 0!==p&&p,f=t.manage,d=void 0!==f&&f,y=t.get,g=void 0!==y&&y,m=t.join,b=void 0!==m&&m,v=t.update,_=void 0!==v&&v,S=t.authKeys,w=void 0===S?[]:S,O=t.delete,P={};return P.r=l?"1":"0",P.w=h?"1":"0",P.m=d?"1":"0",P.d=O?"1":"0",P.g=g?"1":"0",P.j=b?"1":"0",P.u=_?"1":"0",r.length>0&&(P.channel=r.join(",")),i.length>0&&(P["channel-group"]=i.join(",")),w.length>0&&(P.auth=w.join(",")),a.length>0&&(P["target-uuid"]=a.join(",")),(u||0===u)&&(P.ttl=u),P},handleResponse:function(){return{}}});function Ie(e){var t,n,r,o,i=void 0!==(null==e?void 0:e.authorizedUserId),s=void 0!==(null===(t=null==e?void 0:e.resources)||void 0===t?void 0:t.users),a=void 0!==(null===(n=null==e?void 0:e.resources)||void 0===n?void 0:n.spaces),u=void 0!==(null===(r=null==e?void 0:e.patterns)||void 0===r?void 0:r.users),c=void 0!==(null===(o=null==e?void 0:e.patterns)||void 0===o?void 0:o.spaces);return u||s||c||a||i}function De(e){var t=0;return e.join&&(t|=128),e.update&&(t|=64),e.get&&(t|=32),e.delete&&(t|=8),e.manage&&(t|=4),e.write&&(t|=2),e.read&&(t|=1),t}function Fe(e,t){if(Ie(t))return function(e,t){var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorizedUserId,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.users,c=r.spaces,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.users,h=o.spaces,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}(0,t);var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorized_uuid,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.uuids,c=r.channels,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.uuids,h=o.channels,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}var Le=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrantToken},extractPermissions:De,validateParams:function(e,t){var n,r,o,i,s,a,u=e.config;if(!u.subscribeKey)return"Missing Subscribe Key";if(!u.publishKey)return"Missing Publish Key";if(!u.secretKey)return"Missing Secret Key";if(!t.resources&&!t.patterns)return"Missing either Resources or Patterns.";var c=void 0!==(null==t?void 0:t.authorized_uuid),l=void 0!==(null===(n=null==t?void 0:t.resources)||void 0===n?void 0:n.uuids),p=void 0!==(null===(r=null==t?void 0:t.resources)||void 0===r?void 0:r.channels),h=void 0!==(null===(o=null==t?void 0:t.resources)||void 0===o?void 0:o.groups),f=void 0!==(null===(i=null==t?void 0:t.patterns)||void 0===i?void 0:i.uuids),d=void 0!==(null===(s=null==t?void 0:t.patterns)||void 0===s?void 0:s.channels),y=void 0!==(null===(a=null==t?void 0:t.patterns)||void 0===a?void 0:a.groups),g=c||l||f||p||d||h||y;return Ie(t)&&g?"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`":(!t.resources||t.resources.uuids&&0!==Object.keys(t.resources.uuids).length||t.resources.channels&&0!==Object.keys(t.resources.channels).length||t.resources.groups&&0!==Object.keys(t.resources.groups).length||t.resources.users&&0!==Object.keys(t.resources.users).length||t.resources.spaces&&0!==Object.keys(t.resources.spaces).length)&&(!t.patterns||t.patterns.uuids&&0!==Object.keys(t.patterns.uuids).length||t.patterns.channels&&0!==Object.keys(t.patterns.channels).length||t.patterns.groups&&0!==Object.keys(t.patterns.groups).length||t.patterns.users&&0!==Object.keys(t.patterns.users).length||t.patterns.spaces&&0!==Object.keys(t.patterns.spaces).length)?void 0:"Missing values for either Resources or Patterns."},postURL:function(e){var t=e.config;return"/v3/pam/".concat(t.subscribeKey,"/grant")},usePost:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(){return{}},postPayload:function(e,t){return Fe(0,t)},handleResponse:function(e,t){return t.data.token}}),Ge={getOperation:function(){return j.PNAccessManagerRevokeToken},validateParams:function(e,t){return e.config.secretKey?t?void 0:"token can't be empty":"Missing Secret Key"},getURL:function(e,t){var n=e.config;return"/v3/pam/".concat(n.subscribeKey,"/grant/").concat(H.encodeString(t))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e){return{uuid:e.config.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}};function Ke(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}var Be=Object.freeze({__proto__:null,getOperation:function(){return j.PNPublishOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},usePost:function(e,t){var n=t.sendByPost;return void 0!==n&&n},getURL:function(e,t){var n=e.config,r=t.channel,o=Ke(e,t.message);return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0/").concat(H.encodeString(o))},postURL:function(e,t){var n=e.config,r=t.channel;return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},postPayload:function(e,t){return Ke(e,t.message)},prepareParams:function(e,t){var n=t.meta,r=t.replicate,o=void 0===r||r,i=t.storeInHistory,s=t.ttl,a={};return null!=i&&(a.store=i?"1":"0"),s&&(a.ttl=s),!1===o&&(a.norep="true"),n&&"object"==typeof n&&(a.meta=JSON.stringify(n)),a},handleResponse:function(e,t){return{timetoken:t[2]}}});var He=Object.freeze({__proto__:null,getOperation:function(){return j.PNSignalOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},getURL:function(e,t){var n,r=e.config,o=t.channel,i=t.message,s=(n=i,JSON.stringify(n));return"/signal/".concat(r.publishKey,"/").concat(r.subscribeKey,"/0/").concat(H.encodeString(o),"/0/").concat(H.encodeString(s))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{timetoken:t[2]}}});var qe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHistoryOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channel,r=e.config;return"/v2/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o=t.reverse,i=t.count,s=void 0===i?100:i,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p={include_token:"true"};return p.count=s,n&&(p.start=n),r&&(p.end=r),u&&(p.string_message_token="true"),null!=o&&(p.reverse=o.toString()),l&&(p.include_meta="true"),p},handleResponse:function(e,t){var n={messages:[],startTimeToken:t[1],endTimeToken:t[2]};return Array.isArray(t[0])&&t[0].forEach((function(t){var r=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message),o={timetoken:t.timetoken,entry:r.payload};t.meta&&(o.meta=t.meta),r.error&&(o.error=r.error),n.messages.push(o)})),n}});var ze=Object.freeze({__proto__:null,getOperation:function(){return j.PNDeleteMessagesOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},useDelete:function(){return!0},getURL:function(e,t){var n=t.channel,r=e.config;return"/v3/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o={};return n&&(o.start=n),r&&(o.end=r),o},handleResponse:function(e,t){return t.payload}});var Ve=Object.freeze({__proto__:null,getOperation:function(){return j.PNMessageCounts},validateParams:function(e,t){var n=t.channels,r=t.timetoken,o=t.channelTimetokens,i=e.config;return n?r&&o?"timetoken and channelTimetokens are incompatible together":o&&o.length>1&&n.length!==o.length?"Length of channelTimetokens and channels do not match":i.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channels,r=e.config,o=n.join(",");return"/v3/history/sub-key/".concat(r.subscribeKey,"/message-counts/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.timetoken,r=t.channelTimetokens,o={};if(r&&1===r.length){var i=a(r,1)[0];o.timetoken=i}else r?o.channelsTimetoken=r.join(","):n&&(o.timetoken=n);return o},handleResponse:function(e,t){return{channels:t.channels}}});var We=Object.freeze({__proto__:null,getOperation:function(){return j.PNFetchMessagesOperation},validateParams:function(e,t){var n=t.channels,r=t.includeMessageActions,o=void 0!==r&&r,i=e.config;if(!n||0===n.length)return"Missing channels";if(!i.subscribeKey)return"Missing Subscribe Key";if(o&&n.length>1)throw new TypeError("History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.")},getURL:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.includeMessageActions,i=void 0!==o&&o,s=e.config,a=i?"history-with-actions":"history",u=r.length>0?r.join(","):",";return"/v3/".concat(a,"/sub-key/").concat(s.subscribeKey,"/channel/").concat(H.encodeString(u))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channels,r=t.start,o=t.end,i=t.includeMessageActions,s=t.count,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p=t.includeUuid,h=t.includeUUID,f=void 0===h||h,d=t.includeMessageType,y=void 0===d||d,g={};return g.max=s||(n.length>1||!0===i?25:100),r&&(g.start=r),o&&(g.end=o),u&&(g.string_message_token="true"),l&&(g.include_meta="true"),f&&!1!==p&&(g.include_uuid="true"),y&&(g.include_message_type="true"),g},handleResponse:function(e,t){var n={channels:{}};return Object.keys(t.channels||{}).forEach((function(r){n.channels[r]=[],(t.channels[r]||[]).forEach((function(t){var o={},i=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message);o.channel=r,o.timetoken=t.timetoken,o.message=i.payload,o.messageType=t.message_type,o.uuid=t.uuid,t.actions&&(o.actions=t.actions,o.data=t.actions),t.meta&&(o.meta=t.meta),i.error&&(o.error=i.error),n.channels[r].push(o)}))})),t.more&&(n.more=t.more),n}});var Je=Object.freeze({__proto__:null,getOperation:function(){return j.PNTimeOperation},getURL:function(){return"/time/0"},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(){return{}},isAuthSupported:function(){return!1},handleResponse:function(e,t){return{timetoken:t[0]}},validateParams:function(){}});var $e=Object.freeze({__proto__:null,getOperation:function(){return j.PNSubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=e.config,r=t.state,o=t.channelGroups,i=void 0===o?[]:o,s=t.timetoken,a=t.filterExpression,u=t.region,c={heartbeat:n.getPresenceTimeout()};return i.length>0&&(c["channel-group"]=i.join(",")),a&&a.length>0&&(c["filter-expr"]=a),Object.keys(r).length&&(c.state=JSON.stringify(r)),s&&(c.tt=s),u&&(c.tr=u),c},handleResponse:function(e,t){var n=[];t.m.forEach((function(e){var t={timetoken:e.p.t,region:e.p.r},r={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:t};n.push(r)}));var r={timetoken:t.t.t,region:t.t.r};return{messages:n,metadata:r}}}),Qe={getOperation:function(){return j.PNHandshakeOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)&&!(null==t?void 0:t.channelGroups))return"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),n.tt=0,t.state&&(n.state=JSON.stringify(t.state)),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.ee="",n},handleResponse:function(e,t){return{region:t.t.r,timetoken:t.t.t}}},Xe={getOperation:function(){return j.PNReceiveMessagesOperation},validateParams:function(e,t){return(null==t?void 0:t.channels)||(null==t?void 0:t.channelGroups)?(null==t?void 0:t.timetoken)?(null==t?void 0:t.region)?void 0:"region can not be empty":"timetoken can not be empty":"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},getAbortSignal:function(e,t){return t.abortSignal},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.tt=t.timetoken,n.tr=t.region,n.ee="",n},handleResponse:function(e,t){var n=[];return t.m.forEach((function(e){var t={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:{timetoken:e.p.t,region:e.p.r}};n.push(t)})),{messages:n,metadata:{region:t.t.r,timetoken:t.t.t}}}},Ye=function(){function e(e){void 0===e&&(e=!1),this.sync=e,this.listeners=new Set}return e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.notify=function(e){var t=this,n=function(){t.listeners.forEach((function(t){t(e)}))};this.sync?n():setTimeout(n,0)},e}(),Ze=function(){function e(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}return e.prototype.transition=function(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)},e.prototype.on=function(e,t){return this.transitionMap.set(e,t),this},e.prototype.with=function(e,t){return[this,e,null!=t?t:[]]},e.prototype.onEnter=function(e){return this.enterEffects.push(e),this},e.prototype.onExit=function(e){return this.exitEffects.push(e),this},e}(),et=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return t(n,e),n.prototype.describe=function(e){return new Ze(e)},n.prototype.start=function(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})},n.prototype.transition=function(e){var t,n,r,o,i,u;if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});var c=this.currentState.transition(this.currentContext,e);if(c){var l=a(c,3),p=l[0],h=l[1],f=l[2];try{for(var d=s(this.currentState.exitEffects),y=d.next();!y.done;y=d.next()){var g=y.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}var m=this.currentState;this.currentState=p;var b=this.currentContext;this.currentContext=h,this.notify({type:"transitionDone",fromState:m,fromContext:b,toState:p,toContext:h,event:e});try{for(var v=s(f),_=v.next();!_.done;_=v.next()){g=_.value;this.notify({type:"invocationDispatched",invocation:g})}}catch(e){r={error:e}}finally{try{_&&!_.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var S=s(this.currentState.enterEffects),w=S.next();!w.done;w=S.next()){g=w.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){i={error:e}}finally{try{w&&!w.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}},n}(Ye),tt=function(){function e(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}return e.prototype.on=function(e,t){this.handlers.set(e,t)},e.prototype.dispatch=function(e){if("CANCEL"!==e.type){var t=this.handlers.get(e.type);if(!t)throw new Error("Unhandled invocation '".concat(e.type,"'"));var n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}else if(this.instances.has(e.payload)){var r=this.instances.get(e.payload);null==r||r.cancel(),this.instances.delete(e.payload)}},e.prototype.dispose=function(){var e,t;try{for(var n=s(this.instances.entries()),r=n.next();!r.done;r=n.next()){var o=a(r.value,2),i=o[0];o[1].cancel(),this.instances.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();function nt(e,t){var n=function(){for(var n=[],r=0;r0&&r(e),[2]}))}))}))),s.on(ht.type,ut((function(e,t,n){var r=n.emitStatus;return o(s,void 0,void 0,(function(){return i(this,(function(t){return r(e),[2]}))}))}))),s.on(ft.type,ut((function(e,n,r){var a=r.receiveMessages,u=r.delay,c=r.config;return o(s,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return c.retryConfiguration&&c.retryConfiguration.shouldRetry(e.reason,e.attempts)?(n.throwIfAborted(),[4,u(c.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),n.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,a({abortSignal:n,channels:e.channels,channelGroups:e.groups,timetoken:e.cursor.timetoken,region:e.cursor.region,filterExpression:c.filterExpression})];case 3:return r=i.sent(),[2,t.transition(Pt(r.metadata,r.messages))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Et(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(At(new q(c.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s.on(dt.type,ut((function(e,r,a){var u=a.handshake,c=a.delay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({abortSignal:r,channels:e.channels,channelGroups:e.groups,filterExpression:p.filterExpression},p.maintainPresenceState&&{state:l}))];case 3:return o=i.sent(),[2,t.transition(vt(o))];case 4:return(s=i.sent())instanceof Error&&"Aborted"===s.message?[2]:s instanceof q?[2,t.transition(_t(s))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(St(new q(p.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s}return t(r,e),r}(tt),Mt=new Ze("HANDSHAKE_FAILED");Mt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Mt.on(Nt.type,(function(e,t){return Ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor})})),Mt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(r=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==r?r:0}})})),Mt.on(Ct.type,(function(e){return Lt.with()}));var jt=new Ze("HANDSHAKE_STOPPED");jt.on(yt.type,(function(e,t){return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),jt.on(Nt.type,(function(e,t){return Ft.with(n(n({},e),{cursor:t.payload.cursor||e.cursor}))})),jt.on(gt.type,(function(e,t){var n;return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),jt.on(Ct.type,(function(e){return Lt.with()}));var Rt=new Ze("RECEIVE_FAILED");Rt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Rt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(Ct.type,(function(e){return Lt.with(void 0)}));var xt=new Ze("RECEIVE_STOPPED");xt.on(yt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),xt.on(gt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Ct.type,(function(){return Lt.with(void 0)}));var Ut=new Ze("RECEIVE_RECONNECTING");Ut.onEnter((function(e){return ft(e)})),Ut.onExit((function(){return ft.cancel})),Ut.on(Pt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),Ut.on(Et.type,(function(e,t){return Ut.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Ut.on(At.type,(function(e,t){var n;return Rt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Ut.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),Ut.on(gt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Ut.on(yt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ut.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var It=new Ze("RECEIVING");It.onEnter((function(e){return lt(e.channels,e.groups,e.cursor)})),It.onExit((function(){return lt.cancel})),It.on(wt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),It.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups})})),It.on(gt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),It.on(Ot.type,(function(e,t){return Ut.with(n(n({},e),{attempts:0,reason:t.payload}))})),It.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),It.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var Dt=new Ze("HANDSHAKE_RECONNECTING");Dt.onEnter((function(e){return dt(e)})),Dt.onExit((function(){return dt.cancel})),Dt.on(vt.type,(function(e,t){var n,r,o={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=e.cursor)||void 0===r?void 0:r.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return It.with({channels:e.channels,groups:e.groups,cursor:o},[ht({category:k.PNConnectedCategory})])})),Dt.on(_t.type,(function(e,t){return Dt.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Dt.on(St.type,(function(e,t){var n;return Mt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Dt.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Dt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Dt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.region)||0}})})),Dt.on(Ct.type,(function(e){return Lt.with(void 0)}));var Ft=new Ze("HANDSHAKING");Ft.onEnter((function(e){return ct(e.channels,e.groups)})),Ft.onExit((function(){return ct.cancel})),Ft.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ft.on(mt.type,(function(e,t){var n,r;return It.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.timetoken:t.payload.timetoken,region:t.payload.region}},[ht({category:k.PNConnectedCategory})])})),Ft.on(bt.type,(function(e,t){return Dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload})})),Ft.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Ft.on(gt.type,(function(e,t){var n;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),Ft.on(Ct.type,(function(e){return Lt.with()}));var Lt=new Ze("UNSUBSCRIBED");Lt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups})})),Lt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})}));var Gt=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new kt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(Lt,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e){var t=this,n=e.channels,r=e.channelGroups,o=e.timetoken,i=e.withPresence;this.channels=u(u([],a(this.channels),!1),a(null!=n?n:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=r?r:[]),!1),i&&(this.channels.map((function(e){return t.channels.push("".concat(e,"-pnpres"))})),this.groups.map((function(e){return t.groups.push("".concat(e,"-pnpres"))}))),o?this.engine.transition(gt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))),o)):this.engine.transition(yt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((function(e){return!e.endsWith("-pnpres")})))),groups:Array.from(new Set(this.groups.filter((function(e){return!e.endsWith("-pnpres")}))))})},e.prototype.unsubscribe=function(e){var t=this,n=e.channels,r=void 0===n?[]:n,o=e.channelGroups,i=void 0===o?[]:o,s=H.removeSingleOccurance(this.channels,u(u([],a(r),!1),a(r.map((function(e){return"".concat(e,"-pnpres")}))),!1)),c=H.removeSingleOccurance(this.groups,u(u([],a(i),!1),a(i.map((function(e){return"".concat(e,"-pnpres")}))),!1));if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(c).size){var l=H.findUniqueCommonElements(this.channels,r),p=H.findUniqueCommonElements(this.groups,i);this.dependencies.presenceState&&(null==l||l.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==p||p.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.channels=s,this.groups=c,this.engine.transition(yt(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:l.slice(0),groups:p.slice(0)})}},e.prototype.unsubscribeAll=function(){this.channels=[],this.groups=[],this.dependencies.presenceState&&(this.dependencies.presenceState={}),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.reconnect=function(e){var t=e.timetoken,n=e.region;this.engine.transition(Nt(t,n))},e.prototype.disconnect=function(){this.engine.transition(Tt()),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.getSubscribedChannels=function(){return Array.from(new Set(this.channels))},e.prototype.getSubscribedChannelGroups=function(){return Array.from(new Set(this.groups))},e.prototype.dispose=function(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),Kt=nt("RECONNECT",(function(){return{}})),Bt=nt("DISCONNECT",(function(){return{}})),Ht=nt("JOINED",(function(e,t){return{channels:e,groups:t}})),qt=nt("LEFT",(function(e,t){return{channels:e,groups:t}})),zt=nt("LEFT_ALL",(function(){return{}})),Vt=nt("HEARTBEAT_SUCCESS",(function(e){return{statusCode:e}})),Wt=nt("HEARTBEAT_FAILURE",(function(e){return e})),Jt=nt("HEARTBEAT_GIVEUP",(function(){return{}})),$t=nt("TIMES_UP",(function(){return{}})),Qt=rt("HEARTBEAT",(function(e,t){return{channels:e,groups:t}})),Xt=rt("LEAVE",(function(e,t){return{channels:e,groups:t}})),Yt=rt("EMIT_STATUS",(function(e){return e})),Zt=ot("WAIT",(function(){return{}})),en=ot("DELAYED_HEARTBEAT",(function(e){return e})),tn=function(e){function r(t,r){var s=e.call(this,r)||this;return s.on(Qt.type,ut((function(e,r,a){var u=a.heartbeat,c=a.presenceState,l=a.config;return o(s,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,u(n({channels:e.channels,channelGroups:e.groups},l.maintainPresenceState&&{state:c}))];case 1:return o.sent(),t.transition(Vt(200)),[3,3];case 2:return(r=o.sent())instanceof q?[2,t.transition(Wt(r))]:[3,3];case 3:return[2]}}))}))}))),s.on(Xt.type,ut((function(e,t,n){var r=n.leave,a=n.config;return o(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:if(a.suppressLeaveEvents)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r({channels:e.channels,channelGroups:e.groups})];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}}))}))}))),s.on(Zt.type,ut((function(e,n,r){var a=r.heartbeatDelay;return o(s,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return n.throwIfAborted(),[4,a()];case 1:return e.sent(),n.throwIfAborted(),[2,t.transition($t())]}}))}))}))),s.on(en.type,ut((function(e,r,a){var u=a.heartbeat,c=a.retryDelay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({channels:e.channels,channelGroups:e.groups},p.maintainPresenceState&&{state:l}))];case 3:return i.sent(),[2,t.transition(Vt(200))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Wt(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Jt())];case 7:return[2]}}))}))}))),s.on(Yt.type,ut((function(e,t,r){var a=r.emitStatus,u=r.config;return o(s,void 0,void 0,(function(){var t;return i(this,(function(r){return u.announceFailedHeartbeats&&!0===(null===(t=null==e?void 0:e.status)||void 0===t?void 0:t.error)?a(e.status):u.announceSuccessfulHeartbeats&&200===e.statusCode&&a(n(n({},e),{operation:j.PNHeartbeatOperation,error:!1})),[2]}))}))}))),s}return t(r,e),r}(tt),nn=new Ze("HEARTBEAT_STOPPED");nn.on(Ht.type,(function(e,t){return nn.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),nn.on(qt.type,(function(e,t){return nn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))})})),nn.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),nn.on(zt.type,(function(e,t){return un.with(void 0)}));var rn=new Ze("HEARTBEAT_COOLDOWN");rn.onEnter((function(){return Zt()})),rn.onExit((function(){return Zt.cancel})),rn.on($t.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),rn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),rn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),rn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),rn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var on=new Ze("HEARTBEAT_FAILED");on.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),on.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),on.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),on.on(Bt.type,(function(e,t){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),on.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var sn=new Ze("HEARBEAT_RECONNECTING");sn.onEnter((function(e){return en(e)})),sn.onExit((function(){return en.cancel})),sn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),sn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),sn.on(Bt.type,(function(e,t){nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),sn.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),sn.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),sn.on(Jt.type,(function(e,t){return on.with({channels:e.channels,groups:e.groups})})),sn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var an=new Ze("HEARTBEATING");an.onEnter((function(e){return Qt(e.channels,e.groups)})),an.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),an.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),an.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),an.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:0,reason:t.payload}))})),an.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),an.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var un=new Ze("HEARTBEAT_INACTIVE");un.on(Ht.type,(function(e,t){return an.with({channels:t.payload.channels,groups:t.payload.groups})}));var cn=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dispatcher=new tn(this.engine,e),this.dependencies=e,this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(un,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.join=function(e){var t=e.channels,n=e.groups;this.channels=u(u([],a(this.channels),!1),a(null!=t?t:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=n?n:[]),!1),this.engine.transition(Ht(this.channels.slice(0),this.groups.slice(0)))},e.prototype.leave=function(e){var t=this,n=e.channels,r=e.groups;this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(qt(null!=n?n:[],null!=r?r:[]))},e.prototype.leaveAll=function(){this.engine.transition(zt())},e.prototype.dispose=function(){this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),ln=function(){function e(){}return e.LinearRetryPolicy=function(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e.ExponentialRetryPolicy=function(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e}(),pn=function(){function e(e){var t=e.modules,n=e.listenerManager,r=e.getFileUrl;this.modules=t,this.listenerManager=n,this.getFileUrl=r,this._channelListenerMap=new Map,this._groupListenerMap=new Map,t.cryptoModule&&(this._decoder=new TextDecoder)}return e.prototype.emitEvent=function(e){var t=e.channel,o=e.publishMetaData,i=e.subscriptionMatch;if(t===i&&(i=null),e.channel.endsWith("-pnpres")){var s={channel:null,subscription:null};t&&(s.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(s.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),s.action=e.payload.action,s.state=e.payload.data,s.timetoken=o.timetoken,s.occupancy=e.payload.occupancy,s.uuid=e.payload.uuid,s.timestamp=e.payload.timestamp,e.payload.join&&(s.join=e.payload.join),e.payload.leave&&(s.leave=e.payload.leave),e.payload.timeout&&(s.timeout=e.payload.timeout),s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announcePresence(s),this._announce("presence",s,s.channel,s.subscription)}else if(1===e.messageType){(s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=e.payload,this.listenerManager.announceSignal(s),this._announce("signal",s,s.channel,s.subscription)}else if(2===e.messageType){if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},this.listenerManager.announceObjects(s),this._announce("objects",s,s.channel,s.subscription),"uuid"===e.payload.type){var a=this._renameChannelField(s),u=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"user"})});this.listenerManager.announceUser(u),this._announce("user",u,s.channel,s.subscription)}else if("channel"===e.payload.type){a=this._renameChannelField(s);var c=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"space"})});this.listenerManager.announceSpace(c),this._announce("space",c,s.channel,s.subscription)}else if("membership"===e.payload.type){var l=(a=this._renameChannelField(s)).message.data,p=l.uuid,h=l.channel,f=r(l,["uuid","channel"]);f.user=p,f.space=h;var d=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),data:f})});this.listenerManager.announceMembership(d),this._announce("membership",d,s.channel,s.subscription)}}else if(3===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,s.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},s.event=e.payload.event,this.listenerManager.announceMessageAction(s),this._announce("messageAction",s,s.channel,s.subscription)}else if(4===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId;var y=e.payload;if(this.modules.cryptoModule){var g=void 0;try{g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}null!==g&&(y=g)}e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=y.message,s.file={id:y.file.id,name:y.file.name,url:this.getFileUrl({id:y.file.id,name:y.file.name,channel:t})},this.listenerManager.announceFile(s),this._announce("file",s,s.channel,s.subscription)}else{if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),this.modules.cryptoModule){g=void 0;try{var m;g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}s.message=null!=g?g:e.payload}else s.message=e.payload;s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announceMessage(s),this._announce("message",s,s.channel,s.subscription)}},e.prototype.addListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){r._channelListenerMap[t]?r._channelListenerMap[t].includes(e)||r._channelListenerMap[t].push(e):r._channelListenerMap[t]=[e]})),null==n||n.forEach((function(t){r._groupListenerMap[t]?r._groupListenerMap[t].includes(e)||r._groupListenerMap[t].push(e):r._groupListenerMap[t]=[e]}))):this.listenerManager.addListener(e)},e.prototype.removeListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){var n;r._channelListenerMap[t]=null===(n=r._channelListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))})),null==n||n.forEach((function(t){var n;r._groupListenerMap[t]=null===(n=r._groupListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))}))):this.listenerManager.removeListener(e)},e.prototype.removeAllListeners=function(){this.listenerManager.removeAllListeners()},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e.prototype._announce=function(e,t,n,r){var o,i;null===(o=this._channelListenerMap[n])||void 0===o||o.forEach((function(n){return n[e]&&n[e](t)})),null===(i=this._groupListenerMap[r])||void 0===i||i.forEach((function(n){return n[e]&&n[e](t)}))},e}(),hn=function(){function e(){}return e.prototype.subscribe=function(){var e,t;this.pubnub.subscribe(n({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))},e.prototype.unsubscribe=function(){this.pubnub.unsubscribe({channels:this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),channelGroups:this.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))})},Object.defineProperty(e.prototype,"onMessage",{set:function(e){this.listener.message=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onPresence",{set:function(e){this.listener.presence=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onSignal",{set:function(e){this.listener.signal=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onObjects",{set:function(e){this.listener.objects=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onMessageAction",{set:function(e){this.listener.messageAction=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onFile",{set:function(e){this.listener.file=e},enumerable:!1,configurable:!0}),e.prototype.addListener=function(e){this.eventEmitter.addListener(e,this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),this.groupNames.filter((function(e){return!e.endsWith("-pnpres")})))},e.prototype.removeListener=function(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)},Object.defineProperty(e.prototype,"channels",{get:function(){return this.channelNames.slice(0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"channelGroups",{get:function(){return this.groupNames.slice(0)},enumerable:!1,configurable:!0}),e}(),fn=function(e){function n(t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.subscriptionOptions,c=t.eventEmitter,l=t.pubnub,p=e.call(this)||this;return p.channelNames=[],p.groupNames=[],p.subscriptionList=[],p.options=s,p.eventEmitter=c,p.pubnub=l,r.forEach((function(e){var t=p.pubnub.channel(e).subscription(p.options);p.channelNames=u(u([],a(p.channelNames),!1),a(t.channels),!1),p.subscriptionList.push(t)})),i.forEach((function(e){var t=p.pubnub.channelGroup(e).subscription(p.options);p.groupNames=u(u([],a(p.groupNames),!1),a(t.channelGroups),!1),p.subscriptionList.push(t)})),p.listener={},c.addListener(p.listener,p.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),p.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),p}return t(n,e),n.prototype.addSubscription=function(e){this.subscriptionList.push(e),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscription=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return t!==e}))},n.prototype.addSubscriptionSet=function(e){this.subscriptionList=u(u([],a(this.subscriptionList),!1),a(e.subscriptions),!1),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscriptionSet=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return!e.subscriptions.includes(t)}))},Object.defineProperty(n.prototype,"subscriptions",{get:function(){return this.subscriptionList.slice(0)},enumerable:!1,configurable:!0}),n}(hn),dn=function(e){function r(t){var n=t.channels,r=t.channelGroups,o=t.subscriptionOptions,i=t.eventEmitter,s=t.pubnub,a=e.call(this)||this;return a.channelNames=[],a.groupNames=[],a.channelNames=n,a.groupNames=r,a.options=o,a.pubnub=s,a.eventEmitter=i,a.listener={},i.addListener(a.listener,a.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),a.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),a}return t(r,e),r.prototype.addSubscription=function(e){return new fn({channels:u(u([],a(this.channelNames),!1),a(e.channels),!1),channelGroups:u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),subscriptionOptions:n(n({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})},r}(hn),yn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),gn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),mn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),bn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),vn=function(){function e(e){var t=this,r=e.networking,o=e.cbor,i=new g({setup:e});this._config=i;var c=new T({config:i}),l=e.cryptography;r.init(i);var p=new G(i,o);this._tokenManager=p;var h=new R({maximumSamplesCount:6e4});this._telemetryManager=h;var f=this._config.cryptoModule,d={config:i,networking:r,crypto:c,cryptography:l,tokenManager:p,telemetryManager:h,PubNubFile:e.PubNubFile,cryptoModule:f};this.File=e.PubNubFile,this.encryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.encryptFile(t,this.File)):l.encryptFile(e,t,this.File)},this.decryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.decryptFile(t,this.File)):l.decryptFile(e,t,this.File)};var y=Q.bind(this,d,Je),m=Q.bind(this,d,se),v=Q.bind(this,d,ue),_=Q.bind(this,d,le),S=Q.bind(this,d,$e),w=new L;if(this._listenerManager=w,this.iAmHere=Q.bind(this,d,ue),this.iAmAway=Q.bind(this,d,se),this.setPresenceState=Q.bind(this,d,le),this.handshake=Q.bind(this,d,Qe),this.receiveMessages=Q.bind(this,d,Xe),this._eventEmitter=new pn({modules:d,listenerManager:this._listenerManager,getFileUrl:function(e){return ve(d,e)}}),!0===i.enableEventEngine){if(i.maintainPresenceState&&(this.presenceState={},this.setState=function(e){var n,r;return null===(n=e.channels)||void 0===n||n.forEach((function(n){return t.presenceState[n]=e.state})),null===(r=e.channelGroups)||void 0===r||r.forEach((function(n){return t.presenceState[n]=e.state})),t.setPresenceState({channels:e.channels,channelGroups:e.channelGroups,state:t.presenceState})}),i.getHeartbeatInterval()){var O=new cn({heartbeat:this.iAmHere,leave:this.iAmAway,heartbeatDelay:function(){return new Promise((function(e){return setTimeout(e,1e3*d.config.getHeartbeatInterval())}))},retryDelay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},config:d.config,presenceState:this.presenceState,emitStatus:function(e){w.announceStatus(e)}});this.presenceEventEngine=O,this.join=this.presenceEventEngine.join.bind(O),this.leave=this.presenceEventEngine.leave.bind(O),this.leaveAll=this.presenceEventEngine.leaveAll.bind(O)}var P=new Gt({handshake:this.handshake,receiveMessages:this.receiveMessages,delay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},join:this.join,leave:this.leave,leaveAll:this.leaveAll,presenceState:this.presenceState,config:d.config,emitMessages:function(e){var n,r;try{for(var o=s(e),i=o.next();!i.done;i=o.next()){var a=i.value;t._eventEmitter.emitEvent(a)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},emitStatus:function(e){w.announceStatus(e)}});this.subscribe=P.subscribe.bind(P),this.unsubscribe=P.unsubscribe.bind(P),this.unsubscribeAll=P.unsubscribeAll.bind(P),this.reconnect=P.reconnect.bind(P),this.disconnect=P.disconnect.bind(P),this.destroy=P.dispose.bind(P),this.getSubscribedChannels=P.getSubscribedChannels.bind(P),this.getSubscribedChannelGroups=P.getSubscribedChannelGroups.bind(P),this.eventEngine=P}else{var E=new M({timeEndpoint:y,leaveEndpoint:m,heartbeatEndpoint:v,setStateEndpoint:_,subscribeEndpoint:S,crypto:d.crypto,config:d.config,listenerManager:w,getFileUrl:function(e){return ve(d,e)},cryptoModule:d.cryptoModule,eventEmitter:this._eventEmitter});this.subscribe=E.adaptSubscribeChange.bind(E),this.unsubscribe=E.adaptUnsubscribeChange.bind(E),this.disconnect=E.disconnect.bind(E),this.reconnect=E.reconnect.bind(E),this.unsubscribeAll=E.unsubscribeAll.bind(E),this.getSubscribedChannels=E.getSubscribedChannels.bind(E),this.getSubscribedChannelGroups=E.getSubscribedChannelGroups.bind(E),this.setState=E.adaptStateChange.bind(E),this.presence=E.adaptPresenceChange.bind(E),this.destroy=function(e){E.unsubscribeAll(e),E.disconnect()}}this.addListener=this._eventEmitter.addListener.bind(this._eventEmitter),this.removeListener=this._eventEmitter.removeListener.bind(this._eventEmitter),this.removeAllListeners=this._eventEmitter.removeAllListeners.bind(this._eventEmitter),this.parseToken=p.parseToken.bind(p),this.setToken=p.setToken.bind(p),this.getToken=p.getToken.bind(p),this.channelGroups={listGroups:Q.bind(this,d,ee),listChannels:Q.bind(this,d,te),addChannels:Q.bind(this,d,X),removeChannels:Q.bind(this,d,Y),deleteGroup:Q.bind(this,d,Z)},this.push={addChannels:Q.bind(this,d,ne),removeChannels:Q.bind(this,d,re),deleteDevice:Q.bind(this,d,ie),listChannels:Q.bind(this,d,oe)},this.hereNow=Q.bind(this,d,pe),this.whereNow=Q.bind(this,d,ae),this.getState=Q.bind(this,d,ce),this.grant=Q.bind(this,d,Ue),this.grantToken=Q.bind(this,d,Le),this.audit=Q.bind(this,d,xe),this.revokeToken=Q.bind(this,d,Ge),this.publish=Q.bind(this,d,Be),this.fire=function(e,n){return e.replicate=!1,e.storeInHistory=!1,t.publish(e,n)},this.signal=Q.bind(this,d,He),this.history=Q.bind(this,d,qe),this.deleteMessages=Q.bind(this,d,ze),this.messageCounts=Q.bind(this,d,Ve),this.fetchMessages=Q.bind(this,d,We),this.addMessageAction=Q.bind(this,d,he),this.removeMessageAction=Q.bind(this,d,fe),this.getMessageActions=Q.bind(this,d,de),this.listFiles=Q.bind(this,d,ye);var A=Q.bind(this,d,ge);this.publishFile=Q.bind(this,d,me),this.sendFile=be({generateUploadUrl:A,publishFile:this.publishFile,modules:d}),this.getFileUrl=function(e){return ve(d,e)},this.downloadFile=Q.bind(this,d,_e),this.deleteFile=Q.bind(this,d,Se),this.channel=function(e){return new yn(e,t._eventEmitter,t)},this.channelGroup=function(e){return new gn(e,t._eventEmitter,t)},this.channelMetadata=function(e){return new mn(e,t._eventEmitter,t)},this.userMetadata=function(e){return new bn(e,t._eventEmitter,t)},this.subscriptionSet=function(e){return new fn({channels:e.channels,channelGroups:e.channelGroups,subscriptionOptions:e.subscriptionOptions,eventEmitter:t._eventEmitter,pubnub:t})},this.objects={getAllUUIDMetadata:Q.bind(this,d,we),getUUIDMetadata:Q.bind(this,d,Oe),setUUIDMetadata:Q.bind(this,d,Pe),removeUUIDMetadata:Q.bind(this,d,Ee),getAllChannelMetadata:Q.bind(this,d,Ae),getChannelMetadata:Q.bind(this,d,Te),setChannelMetadata:Q.bind(this,d,Ne),removeChannelMetadata:Q.bind(this,d,Ce),getChannelMembers:Q.bind(this,d,ke),setChannelMembers:function(e){for(var r=[],o=1;o=this._config.origin.length&&(this._currentSubDomain=0);var t=this._config.origin[this._currentSubDomain];return"".concat(e).concat(t)},e.prototype.hasModule=function(e){return e in this._modules},e.prototype.shiftStandardOrigin=function(){return this._standardOrigin=this.nextOrigin(),this._standardOrigin},e.prototype.getStandardOrigin=function(){return this._standardOrigin},e.prototype.POSTFILE=function(e,t,n){return this._modules.postfile(e,t,n)},e.prototype.GETFILE=function(e,t,n){return this._modules.getfile(e,t,n)},e.prototype.POST=function(e,t,n,r){return this._modules.post(e,t,n,r)},e.prototype.PATCH=function(e,t,n,r){return this._modules.patch(e,t,n,r)},e.prototype.GET=function(e,t,n){return this._modules.get(e,t,n)},e.prototype.DELETE=function(e,t,n){return this._modules.del(e,t,n)},e.prototype._detectErrorCategory=function(e){if("ENOTFOUND"===e.code)return k.PNNetworkIssuesCategory;if("ECONNREFUSED"===e.code)return k.PNNetworkIssuesCategory;if("ECONNRESET"===e.code)return k.PNNetworkIssuesCategory;if("EAI_AGAIN"===e.code)return k.PNNetworkIssuesCategory;if(0===e.status||e.hasOwnProperty("status")&&void 0===e.status)return k.PNNetworkIssuesCategory;if(e.timeout)return k.PNTimeoutCategory;if("ETIMEDOUT"===e.code)return k.PNNetworkIssuesCategory;if(e.response){if(e.response.badRequest)return k.PNBadRequestCategory;if(e.response.forbidden)return k.PNAccessDeniedCategory}return k.PNUnknownCategory},e}();function Sn(e){var t=function(e){return e&&"object"==typeof e&&e.constructor===Object};if(!t(e))return e;var n={};return Object.keys(e).forEach((function(r){var o=function(e){return"string"==typeof e||e instanceof String}(r),i=r,s=e[r];Array.isArray(r)||o&&r.indexOf(",")>=0?i=(o?r.split(","):r).reduce((function(e,t){return e+=String.fromCharCode(t)}),""):(function(e){return"number"==typeof e&&isFinite(e)}(r)||o&&!isNaN(r))&&(i=String.fromCharCode(o?parseInt(r,10):10));n[i]=t(s)?Sn(s):s})),n}var wn=function(){function e(e,t){this._base64ToBinary=t,this._decode=e}return e.prototype.decodeToken=function(e){var t="";e.length%4==3?t="=":e.length%4==2&&(t="==");var n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,r=this._decode(this._base64ToBinary(n));if("object"==typeof r)return r},e}(),On={exports:{}},Pn={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;os.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;at?1:0}function Un(e,t,n,r){void 0===r&&(r=kn());var o,i=In(e,"",0,[],void 0,0,r)||e;try{o=0===Cn.length?JSON.stringify(i,t,n):JSON.stringify(i,Dn(t),n)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==Nn.length;){var s=Nn.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return o}function In(e,t,n,r,o,i,s){var a;if(i+=1,"object"==typeof e&&null!==e){for(a=0;as.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;a0)for(var r=0;r1&&"boolean"!=typeof t)throw new Qn('"allowMissing" argument must be a boolean');var n=gr(e),r=n.length>0?n[0]:"",o=mr("%"+r+"%",t),i=o.name,s=o.value,a=!1,u=o.alias;u&&(r=u[0],pr(n,lr([0,1],u)));for(var c=1,l=!0;c=n.length){var d=Yn(s,p);s=(l=!!d)&&"get"in d&&!("originalValue"in d.get)?d.get:s[p]}else l=cr(s,p),s=s[p];l&&!a&&(ir[i]=s)}}return s},vr={exports:{}};!function(e){var t=Vn,n=br,r=n("%Function.prototype.apply%"),o=n("%Function.prototype.call%"),i=n("%Reflect.apply%",!0)||t.call(o,r),s=n("%Object.getOwnPropertyDescriptor%",!0),a=n("%Object.defineProperty%",!0),u=n("%Math.max%");if(a)try{a({},"a",{value:1})}catch(e){a=null}e.exports=function(e){var n=i(t,o,arguments);if(s&&a){var r=s(n,"length");r.configurable&&a(n,"length",{value:1+u(0,e.length-(arguments.length-1))})}return n};var c=function(){return i(t,r,arguments)};a?a(e.exports,"apply",{value:c}):e.exports.apply=c}(vr);var _r=br,Sr=vr.exports,wr=Sr(_r("String.prototype.indexOf")),Or=l(Object.freeze({__proto__:null,default:{}})),Pr="function"==typeof Map&&Map.prototype,Er=Object.getOwnPropertyDescriptor&&Pr?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ar=Pr&&Er&&"function"==typeof Er.get?Er.get:null,Tr=Pr&&Map.prototype.forEach,Nr="function"==typeof Set&&Set.prototype,Cr=Object.getOwnPropertyDescriptor&&Nr?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,kr=Nr&&Cr&&"function"==typeof Cr.get?Cr.get:null,Mr=Nr&&Set.prototype.forEach,jr="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Rr="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,xr="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Ur=Boolean.prototype.valueOf,Ir=Object.prototype.toString,Dr=Function.prototype.toString,Fr=String.prototype.match,Lr=String.prototype.slice,Gr=String.prototype.replace,Kr=String.prototype.toUpperCase,Br=String.prototype.toLowerCase,Hr=RegExp.prototype.test,qr=Array.prototype.concat,zr=Array.prototype.join,Vr=Array.prototype.slice,Wr=Math.floor,Jr="function"==typeof BigInt?BigInt.prototype.valueOf:null,$r=Object.getOwnPropertySymbols,Qr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,Xr="function"==typeof Symbol&&"object"==typeof Symbol.iterator,Yr="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xr||"symbol")?Symbol.toStringTag:null,Zr=Object.prototype.propertyIsEnumerable,eo=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function to(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||Hr.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var r=e<0?-Wr(-e):Wr(e);if(r!==e){var o=String(r),i=Lr.call(t,o.length+1);return Gr.call(o,n,"$&_")+"."+Gr.call(Gr.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Gr.call(t,n,"$&_")}var no=Or,ro=no.custom,oo=co(ro)?ro:null;function io(e,t,n){var r="double"===(n.quoteStyle||t)?'"':"'";return r+e+r}function so(e){return Gr.call(String(e),/"/g,""")}function ao(e){return!("[object Array]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function uo(e){return!("[object RegExp]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function co(e){if(Xr)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!Qr)return!1;try{return Qr.call(e),!0}catch(e){}return!1}var lo=Object.prototype.hasOwnProperty||function(e){return e in this};function po(e,t){return lo.call(e,t)}function ho(e){return Ir.call(e)}function fo(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;nt.maxStringLength){var n=e.length-t.maxStringLength,r="... "+n+" more character"+(n>1?"s":"");return yo(Lr.call(e,0,t.maxStringLength),t)+r}return io(Gr.call(Gr.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,go),"single",t)}function go(e){var t=e.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return n?"\\"+n:"\\x"+(t<16?"0":"")+Kr.call(t.toString(16))}function mo(e){return"Object("+e+")"}function bo(e){return e+" { ? }"}function vo(e,t,n,r){return e+" ("+t+") {"+(r?_o(n,r):zr.call(n,", "))+"}"}function _o(e,t){if(0===e.length)return"";var n="\n"+t.prev+t.base;return n+zr.call(e,","+n)+"\n"+t.prev}function So(e,t){var n=ao(e),r=[];if(n){r.length=e.length;for(var o=0;o-1?Sr(n):n},Po=function e(t,n,r,o){var i=n||{};if(po(i,"quoteStyle")&&"single"!==i.quoteStyle&&"double"!==i.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(po(i,"maxStringLength")&&("number"==typeof i.maxStringLength?i.maxStringLength<0&&i.maxStringLength!==1/0:null!==i.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var s=!po(i,"customInspect")||i.customInspect;if("boolean"!=typeof s&&"symbol"!==s)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(po(i,"indent")&&null!==i.indent&&"\t"!==i.indent&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(po(i,"numericSeparator")&&"boolean"!=typeof i.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=i.numericSeparator;if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return yo(t,i);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var u=String(t);return a?to(t,u):u}if("bigint"==typeof t){var l=String(t)+"n";return a?to(t,l):l}var p=void 0===i.depth?5:i.depth;if(void 0===r&&(r=0),r>=p&&p>0&&"object"==typeof t)return ao(t)?"[Array]":"[Object]";var h=function(e,t){var n;if("\t"===e.indent)n="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;n=zr.call(Array(e.indent+1)," ")}return{base:n,prev:zr.call(Array(t+1),n)}}(i,r);if(void 0===o)o=[];else if(fo(o,t)>=0)return"[Circular]";function f(t,n,s){if(n&&(o=Vr.call(o)).push(n),s){var a={depth:i.depth};return po(i,"quoteStyle")&&(a.quoteStyle=i.quoteStyle),e(t,a,r+1,o)}return e(t,i,r+1,o)}if("function"==typeof t&&!uo(t)){var d=function(e){if(e.name)return e.name;var t=Fr.call(Dr.call(e),/^function\s*([\w$]+)/);if(t)return t[1];return null}(t),y=So(t,f);return"[Function"+(d?": "+d:" (anonymous)")+"]"+(y.length>0?" { "+zr.call(y,", ")+" }":"")}if(co(t)){var g=Xr?Gr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qr.call(t);return"object"!=typeof t||Xr?g:mo(g)}if(function(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return!0;return"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}(t)){for(var m="<"+Br.call(String(t.nodeName)),b=t.attributes||[],v=0;v"}if(ao(t)){if(0===t.length)return"[]";var _=So(t,f);return h&&!function(e){for(var t=0;t=0)return!1;return!0}(_)?"["+_o(_,h)+"]":"[ "+zr.call(_,", ")+" ]"}if(function(e){return!("[object Error]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)){var S=So(t,f);return"cause"in Error.prototype||!("cause"in t)||Zr.call(t,"cause")?0===S.length?"["+String(t)+"]":"{ ["+String(t)+"] "+zr.call(S,", ")+" }":"{ ["+String(t)+"] "+zr.call(qr.call("[cause]: "+f(t.cause),S),", ")+" }"}if("object"==typeof t&&s){if(oo&&"function"==typeof t[oo]&&no)return no(t,{depth:p-r});if("symbol"!==s&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!Ar||!e||"object"!=typeof e)return!1;try{Ar.call(e);try{kr.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}(t)){var w=[];return Tr&&Tr.call(t,(function(e,n){w.push(f(n,t,!0)+" => "+f(e,t))})),vo("Map",Ar.call(t),w,h)}if(function(e){if(!kr||!e||"object"!=typeof e)return!1;try{kr.call(e);try{Ar.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}(t)){var O=[];return Mr&&Mr.call(t,(function(e){O.push(f(e,t))})),vo("Set",kr.call(t),O,h)}if(function(e){if(!jr||!e||"object"!=typeof e)return!1;try{jr.call(e,jr);try{Rr.call(e,Rr)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}(t))return bo("WeakMap");if(function(e){if(!Rr||!e||"object"!=typeof e)return!1;try{Rr.call(e,Rr);try{jr.call(e,jr)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}(t))return bo("WeakSet");if(function(e){if(!xr||!e||"object"!=typeof e)return!1;try{return xr.call(e),!0}catch(e){}return!1}(t))return bo("WeakRef");if(function(e){return!("[object Number]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(Number(t)));if(function(e){if(!e||"object"!=typeof e||!Jr)return!1;try{return Jr.call(e),!0}catch(e){}return!1}(t))return mo(f(Jr.call(t)));if(function(e){return!("[object Boolean]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(Ur.call(t));if(function(e){return!("[object String]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(String(t)));if("undefined"!=typeof window&&t===window)return"{ [object Window] }";if(t===c)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)&&!uo(t)){var P=So(t,f),E=eo?eo(t)===Object.prototype:t instanceof Object||t.constructor===Object,A=t instanceof Object?"":"null prototype",T=!E&&Yr&&Object(t)===t&&Yr in t?Lr.call(ho(t),8,-1):A?"Object":"",N=(E||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(T||A?"["+zr.call(qr.call([],T||[],A||[]),": ")+"] ":"");return 0===P.length?N+"{}":h?N+"{"+_o(P,h)+"}":N+"{ "+zr.call(P,", ")+" }"}return String(t)},Eo=wo("%TypeError%"),Ao=wo("%WeakMap%",!0),To=wo("%Map%",!0),No=Oo("WeakMap.prototype.get",!0),Co=Oo("WeakMap.prototype.set",!0),ko=Oo("WeakMap.prototype.has",!0),Mo=Oo("Map.prototype.get",!0),jo=Oo("Map.prototype.set",!0),Ro=Oo("Map.prototype.has",!0),xo=function(e,t){for(var n,r=e;null!==(n=r.next);r=n)if(n.key===t)return r.next=n.next,n.next=e.next,e.next=n,n},Uo=String.prototype.replace,Io=/%20/g,Do="RFC3986",Fo={default:Do,formatters:{RFC1738:function(e){return Uo.call(e,Io,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:Do},Lo=Fo,Go=Object.prototype.hasOwnProperty,Ko=Array.isArray,Bo=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),Ho=function(e,t){for(var n=t&&t.plainObjects?Object.create(null):{},r=0;r1;){var t=e.pop(),n=t.obj[t.prop];if(Ko(n)){for(var r=[],o=0;o=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===Lo.RFC1738&&(40===u||41===u)?s+=i.charAt(a):u<128?s+=Bo[u]:u<2048?s+=Bo[192|u>>6]+Bo[128|63&u]:u<55296||u>=57344?s+=Bo[224|u>>12]+Bo[128|u>>6&63]+Bo[128|63&u]:(a+=1,u=65536+((1023&u)<<10|1023&i.charCodeAt(a)),s+=Bo[240|u>>18]+Bo[128|u>>12&63]+Bo[128|u>>6&63]+Bo[128|63&u])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(Ko(e)){for(var n=[],r=0;r0?b.join(",")||null:void 0}];else if(Qo(u))O=u;else{var E=Object.keys(b);O=c?E.sort(c):E}for(var A=o&&Qo(b)&&1===b.length?n+"[]":n,T=0;T-1?e.split(","):e},li=function(e,t,n,r){if(e){var o=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,s=n.depth>0&&/(\[[^[\]]*])/.exec(o),a=s?o.slice(0,s.index):o,u=[];if(a){if(!n.plainObjects&&ii.call(Object.prototype,a)&&!n.allowPrototypes)return;u.push(a)}for(var c=0;n.depth>0&&null!==(s=i.exec(o))&&c=0;--i){var s,a=e[i];if("[]"===a&&n.parseArrays)s=[].concat(o);else{s=n.plainObjects?Object.create(null):{};var u="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(u,10);n.parseArrays||""!==u?!isNaN(c)&&a!==u&&String(c)===u&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(s=[])[c]=o:"__proto__"!==u&&(s[u]=o):s={0:o}}o=s}return o}(u,t,n,r)}},pi=function(e,t){var n,r=e,o=function(e){if(!e)return ti;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||ti.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Wo.default;if(void 0!==e.format){if(!Jo.call(Wo.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var r=Wo.formatters[n],o=ti.filter;return("function"==typeof e.filter||Qo(e.filter))&&(o=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:ti.addQueryPrefix,allowDots:void 0===e.allowDots?ti.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ti.charsetSentinel,delimiter:void 0===e.delimiter?ti.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:ti.encode,encoder:"function"==typeof e.encoder?e.encoder:ti.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:ti.encodeValuesOnly,filter:o,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:ti.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:ti.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ti.strictNullHandling}}(t);"function"==typeof o.filter?r=(0,o.filter)("",r):Qo(o.filter)&&(n=o.filter);var i,s=[];if("object"!=typeof r||null===r)return"";i=t&&t.arrayFormat in $o?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=$o[i];if(t&&"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var u="comma"===a&&t&&t.commaRoundTrip;n||(n=Object.keys(r)),o.sort&&n.sort(o.sort);for(var c=zo(),l=0;l0?f+h:""},hi={formats:Fo,parse:function(e,t){var n=function(e){if(!e)return ai;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?ai.charset:e.charset;return{allowDots:void 0===e.allowDots?ai.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:ai.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:ai.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:ai.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ai.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:ai.comma,decoder:"function"==typeof e.decoder?e.decoder:ai.decoder,delimiter:"string"==typeof e.delimiter||oi.isRegExp(e.delimiter)?e.delimiter:ai.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:ai.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:ai.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:ai.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:ai.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ai.strictNullHandling}}(t);if(""===e||null==e)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof e?function(e,t){var n,r={__proto__:null},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,i),a=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(l=si(l)?[l]:l),ii.call(r,c)?r[c]=oi.combine(r[c],l):r[c]=l}return r}(e,n):e,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),s=0;s=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.split(/ *; */).shift(),e.params=e=>{const n={};var r,o=t(e.split(/ *; */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *= */),t=e.shift(),o=e.shift();t&&o&&(n[t]=o)}}catch(e){o.e(e)}finally{o.f()}return n},e.parseLinks=e=>{const n={};var r,o=t(e.split(/ *, */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *; */),t=e[0].slice(1,-1);n[e[1].split(/ *= */)[1].slice(1,-1)]=t}}catch(e){o.e(e)}finally{o.f()}return n},e.cleanHeader=(e,t)=>(delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e),e.isObject=e=>null!==e&&"object"==typeof e,e.hasOwn=Object.hasOwn||function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(new Object(e),t)},e.mixin=(t,n)=>{for(const r in n)e.hasOwn(n,r)&&(t[r]=n[r])}}(fi);const di=Or,yi=fi.isObject,gi=fi.hasOwn;var mi=bi;function bi(){}bi.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},bi.prototype.parse=function(e){return this._parser=e,this},bi.prototype.responseType=function(e){return this._responseType=e,this},bi.prototype.serialize=function(e){return this._serializer=e,this},bi.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(const t in e)if(gi(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},bi.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};const vi=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),_i=new Set([408,413,429,500,502,503,504,521,522,524]);bi.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{const n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&_i.has(t.status))return!0;if(e){if(e.code&&vi.has(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},bi.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},bi.prototype.then=function(e,t){if(!this._fullfilledPromise){const e=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(((t,n)=>{e.on("abort",(()=>{if(this._maxRetries&&this._maxRetries>this._retries)return;if(this.timedout&&this.timedoutError)return void n(this.timedoutError);const e=new Error("Aborted");e.code="ABORTED",e.status=this.status,e.method=this.method,e.url=this.url,n(e)})),e.end(((e,r)=>{e?n(e):t(r)}))}))}return this._fullfilledPromise.then(e,t)},bi.prototype.catch=function(e){return this.then(void 0,e)},bi.prototype.use=function(e){return e(this),this},bi.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},bi.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},bi.prototype.get=function(e){return this._header[e.toLowerCase()]},bi.prototype.getHeader=bi.prototype.get,bi.prototype.set=function(e,t){if(yi(e)){for(const t in e)gi(e,t)&&this.set(t,e[t]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},bi.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},bi.prototype.field=function(e,t,n){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(yi(e)){for(const t in e)gi(e,t)&&this.field(t,e[t]);return this}if(Array.isArray(t)){for(const n in t)gi(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),n?this._getFormData().append(e,t,n):this._getFormData().append(e,t),this},bi.prototype.abort=function(){if(this._aborted)return this;if(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req){if(di.gte(process.version,"v13.0.0")&&di.lt(process.version,"v14.0.0"))throw new Error("Superagent does not work in v13 properly with abort() due to Node.js core changes");this.req.abort()}return this.clearTimeout(),this.emit("abort"),this},bi.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization",`Basic ${r(`${e}:${t}`)}`);break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization",`Bearer ${e}`)}return this},bi.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},bi.prototype.redirects=function(e){return this._maxRedirects=e,this},bi.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},bi.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},bi.prototype.send=function(e){const t=yi(e);let n=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&yi(this._data))for(const t in e){if("bigint"==typeof e[t]&&!e[t].toJSON)throw new Error("Cannot serialize BigInt value to json");gi(e,t)&&(this._data[t]=e[t])}else{if("bigint"==typeof e)throw new Error("Cannot send value of type BigInt");"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],n&&(n=n.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===n?this._data?`${this._data}&${e}`:e:(this._data||"")+e):this._data=e}return!t||this._isHost(e)||n||this.type("json"),this},bi.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},bi.prototype._finalizeQueryString=function(){const e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){const e=this.url.indexOf("?");if(e>=0){const t=this.url.slice(e+1).split("&");"function"==typeof this._sort?t.sort(this._sort):t.sort(),this.url=this.url.slice(0,e)+"?"+t.join("&")}}},bi.prototype._appendQueryString=()=>{console.warn("Unsupported")},bi.prototype._timeoutError=function(e,t,n){if(this._aborted)return;const r=new Error(`${e+t}ms exceeded`);r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.timedoutError=r,this.abort(),this.callback(r)},bi.prototype._setTimeouts=function(){const e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((()=>{e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((()=>{e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};const Si=fi;var wi=Oi;function Oi(){}function Pi(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Ei(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ei(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw i}}}}function Ei(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n{if(o.XMLHttpRequest)return new o.XMLHttpRequest;throw new Error("Browser-only version of superagent could not find XHR")};const g="".trim?e=>e.trim():e=>e.replace(/(^\s*|\s*$)/g,"");function m(e){if(!c(e))return e;const t=[];for(const n in e)p(e,n)&&b(t,n,e[n]);return t.join("&")}function b(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r)){var o,i=n(r);try{for(i.s();!(o=i.n()).done;){b(e,t,o.value)}}catch(e){i.e(e)}finally{i.f()}}else if(c(r))for(const n in r)p(r,n)&&b(e,`${t}[${n}]`,r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function v(e){const t={},n=e.split("&");let r,o;for(let e=0,i=n.length;e{let e,t=null,r=null;try{r=new S(n)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||r.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=e.status||r.status,n.callback(e,r)):n.callback(null,r)}))}y.serializeObject=m,y.parseString=v,y.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":a.stringify,"application/json":s},y.parse={"application/x-www-form-urlencoded":v,"application/json":JSON.parse},l(S.prototype,h.prototype),S.prototype._parseBody=function(e){let t=y.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&_(this.type)&&(t=y.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},S.prototype.toError=function(){const e=this.req,t=e.method,n=e.url,r=`cannot ${t} ${n} (${this.status})`,o=new Error(r);return o.status=this.status,o.method=t,o.url=n,o},y.Response=S,i(w.prototype),l(w.prototype,u.prototype),w.prototype.type=function(e){return this.set("Content-Type",y.types[e]||e),this},w.prototype.accept=function(e){return this.set("Accept",y.types[e]||e),this},w.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});const r=n.encoder?n.encoder:e=>{if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},w.prototype.query=function(e){return"string"!=typeof e&&(e=m(e)),e&&this._query.push(e),this},w.prototype.attach=function(e,t,n){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},w.prototype._getFormData=function(){return this._formData||(this._formData=new o.FormData),this._formData},w.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();const n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},w.prototype.crossDomainError=function(){const e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},w.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},w.prototype.ca=w.prototype.agent,w.prototype.buffer=w.prototype.ca,w.prototype.write=()=>{throw new Error("Streaming is not supported in browser version of superagent")},w.prototype.pipe=w.prototype.write,w.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},w.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||d,this._finalizeQueryString(),this._end()},w.prototype._setUploadTimeout=function(){const e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((()=>{e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},w.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));const e=this;this.xhr=y.getXHR();const t=this.xhr;let n=this._formData||this._data;this._setTimeouts(),t.addEventListener("readystatechange",(()=>{const n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4!==n)return;let r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}));const r=(t,n)=>{n.total>0&&(n.percent=n.loaded/n.total*100,100===n.percent&&clearTimeout(e._uploadTimeoutTimer)),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.addEventListener("progress",r.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",r.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof n&&!this._isHost(n)){const e=this._header["content-type"];let t=this._serializer||y.serialize[e?e.split(";")[0]:""];!t&&_(e)&&(t=y.serialize["application/json"]),t&&(n=t(n))}for(const e in this.header)null!==this.header[e]&&p(this.header,e)&&t.setRequestHeader(e,this.header[e]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===n?null:n)},y.agent=()=>new f;for(var O=0,P=["GET","POST","OPTIONS","PATCH","PUT","DELETE"];O{const r=y("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.head=(e,t,n)=>{const r=y("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.options=(e,t,n)=>{const r=y("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.del=E,y.delete=E,y.patch=(e,t,n)=>{const r=y("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.post=(e,t,n)=>{const r=y("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.put=(e,t,n)=>{const r=y("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}}(On,On.exports);var ki=On.exports;function Mi(e){var t=(new Date).getTime(),n=(new Date).toISOString(),r=console&&console.log?console:window&&window.console&&window.console.log?window.console:console;r.log("<<<<<"),r.log("[".concat(n,"]"),"\n",e.url,"\n",e.qs),r.log("-----"),e.on("response",(function(n){var o=(new Date).getTime()-t,i=(new Date).toISOString();r.log(">>>>>>"),r.log("[".concat(i," / ").concat(o,"]"),"\n",e.url,"\n",e.qs,"\n",n.text),r.log("-----")}))}function ji(e,t,n){var r=this;this._config.logVerbosity&&(e=e.use(Mi)),this._config.proxy&&this._modules.proxy&&(e=this._modules.proxy.call(this,e)),this._config.keepAlive&&this._modules.keepAlive&&(e=this._modules.keepAlive(e));var o=e;if(t.abortSignal)var i=t.abortSignal.subscribe((function(){o.abort(),i()}));return!0===t.forceBuffered?o="undefined"==typeof Blob?o.buffer().responseType("arraybuffer"):o.responseType("arraybuffer"):!1===t.forceBuffered&&(o=o.buffer(!1)),(o=o.timeout(t.timeout)).on("abort",(function(){return n({category:k.PNUnknownCategory,error:!0,operation:t.operation,errorData:new Error("Aborted")},null)})),o.end((function(e,o){var i,s={};if(s.error=null!==e,s.operation=t.operation,o&&o.status&&(s.statusCode=o.status),e){if(e.response&&e.response.text&&!r._config.logVerbosity)try{s.errorData=JSON.parse(e.response.text)}catch(t){s.errorData=e}else s.errorData=e;return s.category=r._detectErrorCategory(e),n(s,null)}if(t.ignoreBody)i={headers:o.headers,redirects:o.redirects,response:o};else try{i=JSON.parse(o.text)}catch(e){return s.errorData=o,s.error=!0,n(s,null)}return i.error&&1===i.error&&i.status&&i.message&&i.service?(s.errorData=i,s.statusCode=i.status,s.error=!0,s.category=r._detectErrorCategory(s),n(s,null)):(i.error&&i.error.message&&(s.errorData=i.error),n(s,i))})),o}function Ri(e,t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return r=ki.post(e),t.forEach((function(e){var t=e.key,n=e.value;r=r.field(t,n)})),r.attach("file",n,{contentType:"application/octet-stream"}),[4,r];case 1:return[2,o.sent()]}}))}))}function xi(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ui(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ii(e,t,n,r){var o=ki.post(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Di(e,t,n,r){var o=ki.patch(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Fi(e,t,n){var r=ki.delete(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Li(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}var Gi,Ki=function(){function e(){}return Object.defineProperty(e.prototype,"algo",{get:function(){return"aes-256-cbc"},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.encryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.encryptString(n,t)];throw new Error("Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer")}}))}))},e.prototype.decrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.decryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.decryptString(n,t)];throw new Error("Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer")}}))}))},e.prototype.encryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:if(t.data.byteLength<=0)throw new Error("encryption error. empty content");return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.encryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,mimeType:"application/octet-stream",data:s})]}}))}))},e.prototype.decryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.decryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,data:s})]}}))}))},e.prototype.getKey=function(t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return[4,crypto.subtle.digest("SHA-256",e.encoder.encode(t))];case 1:return n=i.sent(),r=Array.from(new Uint8Array(n)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),o=e.encoder.encode(r.slice(0,32)).buffer,[2,crypto.subtle.importKey("raw",o,"AES-CBC",!0,["encrypt","decrypt"])]}}))}))},e.prototype.encryptArrayBuffer=function(e,t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),r=Li,o=[n.buffer],[4,crypto.subtle.encrypt({name:"AES-CBC",iv:n},e,t)];case 1:return[2,r.apply(void 0,o.concat([i.sent()]))]}}))}))},e.prototype.decryptArrayBuffer=function(t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:if(r=n.slice(0,16),n.slice(e.IV_LENGTH).byteLength<=0)throw new Error("decryption error: empty content");return[4,crypto.subtle.decrypt({name:"AES-CBC",iv:r},t,n.slice(e.IV_LENGTH))];case 1:return[2,o.sent()]}}))}))},e.prototype.encryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=crypto.getRandomValues(new Uint8Array(16)),o=e.encoder.encode(n).buffer,[4,crypto.subtle.encrypt({name:"AES-CBC",iv:r},t,o)];case 1:return s=i.sent(),a=Li(r.buffer,s),[2,e.decoder.decode(a)]}}))}))},e.prototype.decryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=e.encoder.encode(n).buffer,o=r.slice(0,16),s=r.slice(16),[4,crypto.subtle.decrypt({name:"AES-CBC",iv:o},t,s)];case 1:return a=i.sent(),[2,e.decoder.decode(a)]}}))}))},e.IV_LENGTH=16,e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Bi=(Gi=function(){function e(e){if(e instanceof File)this.data=e,this.name=this.data.name,this.mimeType=this.data.type;else if(e.data){var t=e.data;this.data=new File([t],e.name,{type:e.mimeType}),this.name=e.name,e.mimeType&&(this.mimeType=e.mimeType)}if(void 0===this.data)throw new Error("Couldn't construct a file out of supplied options.");if(void 0===this.name)throw new Error("Couldn't guess filename out of the options. Please provide one.")}return e.create=function(e){return new this(e)},e.prototype.toBuffer=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toStream=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toFileUri=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in react native environments.")}))}))},e.prototype.toBlob=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e.prototype.toArrayBuffer=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if(r.result instanceof ArrayBuffer)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsArrayBuffer(e.data)}))]}))}))},e.prototype.toString=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if("string"==typeof r.result)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsBinaryString(e.data)}))]}))}))},e.prototype.toFile=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e}(),Gi.supportsFile="undefined"!=typeof File,Gi.supportsBlob="undefined"!=typeof Blob,Gi.supportsArrayBuffer="undefined"!=typeof ArrayBuffer,Gi.supportsBuffer=!1,Gi.supportsStream=!1,Gi.supportsString=!0,Gi.supportsEncryptFile=!0,Gi.supportsFileUri=!1,Gi),Hi=function(){function e(e){this.config=e,this.cryptor=new T({config:e}),this.fileCryptor=new Ki}return Object.defineProperty(e.prototype,"identifier",{get:function(){return""},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e){var t="string"==typeof e?e:(new TextDecoder).decode(e);return{data:this.cryptor.encrypt(t),metadata:null}},e.prototype.decrypt=function(e){var t="string"==typeof e.data?e.data:b(e.data);return this.cryptor.decrypt(t)},e.prototype.encryptFile=function(e,t){var n;return o(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)]}))}))},e.prototype.decryptFile=function(e,t){return o(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.fileCryptor.decryptFile(this.config.cipherKey,e,t)]}))}))},e}(),qi=function(){function e(e){this.cipherKey=e.cipherKey,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(this.cipherKey)}return Object.defineProperty(e.prototype,"algo",{get:function(){return"AES-CBC"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return"ACRH"},enumerable:!1,configurable:!0}),e.prototype.getIv=function(){return crypto.getRandomValues(new Uint8Array(e.BLOCK_SIZE))},e.prototype.getKey=function(){return o(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return t=e.encoder.encode(this.cipherKey),[4,crypto.subtle.digest("SHA-256",t.buffer)];case 1:return n=r.sent(),[2,crypto.subtle.importKey("raw",n,this.algo,!0,["encrypt","decrypt"])]}}))}))},e.prototype.encrypt=function(t){if(0===("string"==typeof t?t:e.decoder.decode(t)).length)throw new Error("encryption error. empty content");var n=this.getIv();return{metadata:n,data:m(this.CryptoJS.AES.encrypt(t,this.encryptedKey,{iv:this.bufferToWordArray(n),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}},e.prototype.decrypt=function(t){var n=this.bufferToWordArray(new Uint8ClampedArray(t.metadata)),r=this.bufferToWordArray(new Uint8ClampedArray(t.data));return e.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:r},this.encryptedKey,{iv:n,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer},e.prototype.encryptFileData=function(e){return o(this,void 0,void 0,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:return[4,this.getKey()];case 1:return t=o.sent(),n=this.getIv(),r={},[4,crypto.subtle.encrypt({name:this.algo,iv:n},t,e)];case 2:return[2,(r.data=o.sent(),r.metadata=n,r)]}}))}))},e.prototype.decryptFileData=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.getKey()];case 1:return t=n.sent(),[2,crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)]}}))}))},e.prototype.bufferToWordArray=function(e){var t,n=[];for(t=0;t0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("decryption error. empty content");return r.decrypt({data:t.slice(n.length),metadata:o})},e.prototype.encryptFile=function(e,t){return o(this,void 0,void 0,(function(){var n,r;return i(this,(function(o){switch(o.label){case 0:return this.defaultCryptor.identifier===Vi.LEGACY_IDENTIFIER?[2,this.defaultCryptor.encryptFile(e,t)]:[4,this.getFileData(e.data)];case 1:return n=o.sent(),[4,this.defaultCryptor.encryptFileData(n)];case 2:return r=o.sent(),[2,t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(r),r.data)})]}}))}))},e.prototype.decryptFile=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a,u,c,l,p;return i(this,(function(i){switch(i.label){case 0:return[4,t.data.arrayBuffer()];case 1:return r=i.sent(),o=Vi.tryParse(r),(null==(s=this.getCryptor(o))?void 0:s.identifier)===e.LEGACY_IDENTIFIER?[2,s.decryptFile(t,n)]:[4,this.getFileData(r)];case 2:return a=i.sent(),u=a.slice(o.length-o.metadataLength,o.length),l=(c=n).create,p={name:t.name},[4,this.defaultCryptor.decryptFileData({data:r.slice(o.length),metadata:u})];case 3:return[2,l.apply(c,[(p.data=i.sent(),p)])]}}))}))},e.prototype.getCryptor=function(e){if(""===e){var t=this.getAllCryptors().find((function(e){return""===e.identifier}));if(t)return t;throw new Error("unknown cryptor error")}if(e instanceof Wi)return this.getCryptorFromId(e.identifier)},e.prototype.getCryptorFromId=function(e){var t=this.getAllCryptors().find((function(t){return e===t.identifier}));if(t)return t;throw Error("unknown cryptor error")},e.prototype.concatArrayBuffer=function(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer},e.prototype.getHeaderData=function(e){if(e.metadata){var t=Vi.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length),r=0;return n.set(t.data,r),r+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),r),n.buffer}},e.prototype.getFileData=function(t){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return t instanceof Blob?[4,t.arrayBuffer()]:[3,2];case 1:return[2,n.sent()];case 2:if(t instanceof ArrayBuffer)return[2,t];if("string"==typeof t)return[2,e.encoder.encode(t)];throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}}))}))},e.LEGACY_IDENTIFIER="",e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Vi=function(){function e(){}return e.from=function(t,n){if(t!==e.LEGACY_IDENTIFIER)return new Wi(t,n.byteLength)},e.tryParse=function(t){var n=new Uint8Array(t),r="";if(n.byteLength>=4&&(r=n.slice(0,4),this.decoder.decode(r)!==e.SENTINEL))return"";if(!(n.byteLength>=5))throw new Error("decryption error. invalid header version");if(n[4]>e.MAX_VERSION)throw new Error("unknown cryptor error");var o="",i=5+e.IDENTIFIER_LENGTH;if(!(n.byteLength>=i))throw new Error("decryption error. invalid crypto identifier");o=n.slice(5,i);var s=null;if(!(n.byteLength>=i+1))throw new Error("decryption error. invalid metadata length");return s=n[i],i+=1,255===s&&n.byteLength>=i+2&&(s=new Uint16Array(n.slice(i,i+2)).reduce((function(e,t){return(e<<8)+t}),0),i+=2),new Wi(this.decoder.decode(o),s)},e.SENTINEL="PNED",e.LEGACY_IDENTIFIER="",e.IDENTIFIER_LENGTH=4,e.VERSION=1,e.MAX_VERSION=1,e.decoder=new TextDecoder,e}(),Wi=function(){function e(e,t){this._identifier=e,this._metadataLength=t}return Object.defineProperty(e.prototype,"identifier",{get:function(){return this._identifier},set:function(e){this._identifier=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"metadataLength",{get:function(){return this._metadataLength},set:function(e){this._metadataLength=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return Vi.VERSION},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return Vi.SENTINEL.length+1+Vi.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){var e=0,t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(Vi.SENTINEL)),t[e+=Vi.SENTINEL.length]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e),e+=Vi.IDENTIFIER_LENGTH;var r=this.metadataLength;return r<255?t[e]=r:t.set([255,r>>8,255&r],e),t},enumerable:!1,configurable:!0}),e.IDENTIFIER_LENGTH=4,e.SENTINEL="PNED",e}();function Ji(e){if(!navigator||!navigator.sendBeacon)return!1;navigator.sendBeacon(e)}var $i=function(e){function n(t){var n=this,r=t.listenToBrowserNetworkEvents,o=void 0===r||r;return t.sdkFamily="Web",t.networking=new _n({del:Fi,get:Ui,post:Ii,patch:Di,sendBeacon:Ji,getfile:xi,postfile:Ri}),t.cbor=new wn((function(e){return Sn(h.decode(e))}),m),t.PubNubFile=Bi,t.cryptography=new Ki,t.initCryptoModule=function(e){return new zi({default:new Hi({cipherKey:e.cipherKey,useRandomIVs:e.useRandomIVs}),cryptors:[new qi({cipherKey:e.cipherKey})]})},n=e.call(this,t)||this,o&&(window.addEventListener("offline",(function(){n.networkDownDetected()})),window.addEventListener("online",(function(){n.networkUpDetected()}))),n}return t(n,e),n.CryptoModule=zi,n}(vn);return $i})); +!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function o(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=o,r.VERSION=t,e.uuid=r,e.isUUID=o}(t),null!==e&&(e.exports=t.uuid)}(f,f.exports);var d=f.exports,y=function(){return d.uuid?d.uuid():d()},g=function(){function e(e){var t,n,r,o,i=e.setup;if(this._PNSDKSuffix={},this.instanceId="pn-".concat(y()),this.secretKey=i.secretKey||i.secret_key,this.subscribeKey=i.subscribeKey||i.subscribe_key,this.publishKey=i.publishKey||i.publish_key,this.sdkName=i.sdkName,this.sdkFamily=i.sdkFamily,this.partnerId=i.partnerId,this.setAuthKey(i.authKey),this.cryptoModule=i.cryptoModule,this.setFilterExpression(i.filterExpression),"string"!=typeof i.origin&&!Array.isArray(i.origin)&&void 0!==i.origin)throw new Error("Origin must be either undefined, a string or a list of strings.");if(this.origin=i.origin||Array.from({length:20},(function(e,t){return"ps".concat(t+1,".pndsn.com")})),this.secure=i.ssl||!1,this.restore=i.restore||!1,this.proxy=i.proxy,this.keepAlive=i.keepAlive,this.keepAliveSettings=i.keepAliveSettings,this.autoNetworkDetection=i.autoNetworkDetection||!1,this.dedupeOnSubscribe=i.dedupeOnSubscribe||!1,this.maximumCacheSize=i.maximumCacheSize||100,this.customEncrypt=i.customEncrypt,this.customDecrypt=i.customDecrypt,this.fileUploadPublishRetryLimit=null!==(t=i.fileUploadPublishRetryLimit)&&void 0!==t?t:5,this.useRandomIVs=null===(n=i.useRandomIVs)||void 0===n||n,this.enableEventEngine=null!==(r=i.enableEventEngine)&&void 0!==r&&r,this.maintainPresenceState=null===(o=i.maintainPresenceState)||void 0===o||o,"undefined"!=typeof location&&"https:"===location.protocol&&(this.secure=!0),this.logVerbosity=i.logVerbosity||!1,this.suppressLeaveEvents=i.suppressLeaveEvents||!1,this.announceFailedHeartbeats=i.announceFailedHeartbeats||!0,this.announceSuccessfulHeartbeats=i.announceSuccessfulHeartbeats||!1,this.useInstanceId=i.useInstanceId||!1,this.useRequestId=i.useRequestId||!1,this.requestMessageCountThreshold=i.requestMessageCountThreshold,i.retryConfiguration&&this._setRetryConfiguration(i.retryConfiguration),this.setTransactionTimeout(i.transactionalRequestTimeout||15e3),this.setSubscribeTimeout(i.subscribeRequestTimeout||31e4),this.setSendBeaconConfig(i.useSendBeacon||!0),i.presenceTimeout?this.setPresenceTimeout(i.presenceTimeout):this._presenceTimeout=300,null!=i.heartbeatInterval&&this.setHeartbeatInterval(i.heartbeatInterval),"string"==typeof i.userId){if("string"==typeof i.uuid)throw new Error("Only one of the following configuration options has to be provided: `uuid` or `userId`");this.setUserId(i.userId)}else{if("string"!=typeof i.uuid)throw new Error("One of the following configuration options has to be provided: `uuid` or `userId`");this.setUUID(i.uuid)}this.setCipherKey(i.cipherKey,i)}return e.prototype.getAuthKey=function(){return this.authKey},e.prototype.setAuthKey=function(e){return this.authKey=e,this},e.prototype.setCipherKey=function(e,t,n){var r;return this.cipherKey=e,this.cipherKey&&(this.cryptoModule=null!==(r=t.cryptoModule)&&void 0!==r?r:t.initCryptoModule({cipherKey:this.cipherKey,useRandomIVs:this.useRandomIVs}),n&&(n.cryptoModule=this.cryptoModule)),this},e.prototype.getUUID=function(){return this.UUID},e.prototype.setUUID=function(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing uuid parameter. Provide a valid string uuid");return this.UUID=e,this},e.prototype.getUserId=function(){return this.UUID},e.prototype.setUserId=function(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");return this.UUID=e,this},e.prototype.getFilterExpression=function(){return this.filterExpression},e.prototype.setFilterExpression=function(e){return this.filterExpression=e,this},e.prototype.getPresenceTimeout=function(){return this._presenceTimeout},e.prototype.setPresenceTimeout=function(e){return e>=20?this._presenceTimeout=e:(this._presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",this._presenceTimeout)),this.setHeartbeatInterval(this._presenceTimeout/2-1),this},e.prototype.setProxy=function(e){this.proxy=e},e.prototype.getHeartbeatInterval=function(){return this._heartbeatInterval},e.prototype.setHeartbeatInterval=function(e){return this._heartbeatInterval=e,this},e.prototype.getSubscribeTimeout=function(){return this._subscribeRequestTimeout},e.prototype.setSubscribeTimeout=function(e){return this._subscribeRequestTimeout=e,this},e.prototype.getTransactionTimeout=function(){return this._transactionalRequestTimeout},e.prototype.setTransactionTimeout=function(e){return this._transactionalRequestTimeout=e,this},e.prototype.isSendBeaconEnabled=function(){return this._useSendBeacon},e.prototype.setSendBeaconConfig=function(e){return this._useSendBeacon=e,this},e.prototype.getVersion=function(){return"7.6.2"},e.prototype._setRetryConfiguration=function(e){if(e.minimumdelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(e.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(e.maximumDelay&&maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6");if(e.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10");this.retryConfiguration=e},e.prototype._addPnsdkSuffix=function(e,t){this._PNSDKSuffix[e]=t},e.prototype._getPnsdkSuffix=function(e){var t=this;return Object.keys(this._PNSDKSuffix).reduce((function(n,r){return n+e+t._PNSDKSuffix[r]}),"")},e}();function m(e){var t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;function s(){var e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error("Illegal character at ".concat(i,": ").concat(t.charAt(i-1)));return n}for(var a=0;a>4,f=(15&c)<<4|l>>2,d=(3&l)<<6|p>>0;o[a]=h,64!=l&&(o[a+1]=f),64!=p&&(o[a+2]=d)}return r}function b(e){for(var t,n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=new Uint8Array(e),i=o.byteLength,s=i%3,a=i-s,u=0;u>18]+r[(258048&t)>>12]+r[(4032&t)>>6]+r[63&t];return 1==s?n+=r[(252&(t=o[a]))>>2]+r[(3&t)<<4]+"==":2==s&&(n+=r[(64512&(t=o[a]<<8|o[a+1]))>>10]+r[(1008&t)>>4]+r[(15&t)<<2]+"="),n}var v,_,S,w,O,P=P||function(e,t){var n={},r=n.lib={},o=function(){},i=r.Base={extend:function(e){o.prototype=this;var t=new o;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var o=0;o>>2]|=(n[o>>>2]>>>24-o%4*8&255)<<24-(r+o)%4*8;else if(65535>>2]=n[o>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r>>2]>>>24-r%4*8&255;n.push((o>>>4).toString(16)),n.push((15&o).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,a=o/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,o=e.min(4*t,o),t){for(var u=0;uc;){var l;e:{l=u;for(var p=e.sqrt(l),h=2;h<=p;h++)if(!(l%h)){l=!1;break e}l=!0}l&&(8>c&&(i[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var f=[];o=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],a=n[3],u=n[4],c=n[5],l=n[6],p=n[7],h=0;64>h;h++){if(16>h)f[h]=0|e[t+h];else{var d=f[h-15],y=f[h-2];f[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+f[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+f[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[h]+f[h],y=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=l,l=c,c=u,u=a+d|0,a=i,i=o,o=r,r=d+y|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+p|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(o),t.HmacSHA256=r._createHmacHelper(o)}(Math),_=(v=P).enc.Utf8,v.algo.HMAC=v.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=_.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,a=i.words,u=0;u>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;4>s&&o+.75*s>>6*(3-s)&63));if(t=r.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(r=n.charAt(64))&&-1!=(r=e.indexOf(r))&&(t=r);for(var r=[],o=0,i=0;i>>6-i%4*2;r[o>>>2]|=(s|a)<<24-o%4*8,o++}return w.create(r,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,r,o,i,s){return((e=e+(t&n|~t&r)+o+s)<>>32-i)+t}function n(e,t,n,r,o,i,s){return((e=e+(t&r|n&~r)+o+s)<>>32-i)+t}function r(e,t,n,r,o,i,s){return((e=e+(t^n^r)+o+s)<>>32-i)+t}function o(e,t,n,r,o,i,s){return((e=e+(n^(t|~r))+o+s)<>>32-i)+t}for(var i=P,s=(u=i.lib).WordArray,a=u.Hasher,u=i.algo,c=[],l=0;64>l;l++)c[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=a.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var s=0;16>s;s++){var a=e[u=i+s];e[u]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}s=this._hash.words;var u=e[i+0],l=(a=e[i+1],e[i+2]),p=e[i+3],h=e[i+4],f=e[i+5],d=e[i+6],y=e[i+7],g=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],_=e[i+12],S=e[i+13],w=e[i+14],O=e[i+15],P=t(P=s[0],T=s[1],A=s[2],E=s[3],u,7,c[0]),E=t(E,P,T,A,a,12,c[1]),A=t(A,E,P,T,l,17,c[2]),T=t(T,A,E,P,p,22,c[3]);P=t(P,T,A,E,h,7,c[4]),E=t(E,P,T,A,f,12,c[5]),A=t(A,E,P,T,d,17,c[6]),T=t(T,A,E,P,y,22,c[7]),P=t(P,T,A,E,g,7,c[8]),E=t(E,P,T,A,m,12,c[9]),A=t(A,E,P,T,b,17,c[10]),T=t(T,A,E,P,v,22,c[11]),P=t(P,T,A,E,_,7,c[12]),E=t(E,P,T,A,S,12,c[13]),A=t(A,E,P,T,w,17,c[14]),P=n(P,T=t(T,A,E,P,O,22,c[15]),A,E,a,5,c[16]),E=n(E,P,T,A,d,9,c[17]),A=n(A,E,P,T,v,14,c[18]),T=n(T,A,E,P,u,20,c[19]),P=n(P,T,A,E,f,5,c[20]),E=n(E,P,T,A,b,9,c[21]),A=n(A,E,P,T,O,14,c[22]),T=n(T,A,E,P,h,20,c[23]),P=n(P,T,A,E,m,5,c[24]),E=n(E,P,T,A,w,9,c[25]),A=n(A,E,P,T,p,14,c[26]),T=n(T,A,E,P,g,20,c[27]),P=n(P,T,A,E,S,5,c[28]),E=n(E,P,T,A,l,9,c[29]),A=n(A,E,P,T,y,14,c[30]),P=r(P,T=n(T,A,E,P,_,20,c[31]),A,E,f,4,c[32]),E=r(E,P,T,A,g,11,c[33]),A=r(A,E,P,T,v,16,c[34]),T=r(T,A,E,P,w,23,c[35]),P=r(P,T,A,E,a,4,c[36]),E=r(E,P,T,A,h,11,c[37]),A=r(A,E,P,T,y,16,c[38]),T=r(T,A,E,P,b,23,c[39]),P=r(P,T,A,E,S,4,c[40]),E=r(E,P,T,A,u,11,c[41]),A=r(A,E,P,T,p,16,c[42]),T=r(T,A,E,P,d,23,c[43]),P=r(P,T,A,E,m,4,c[44]),E=r(E,P,T,A,_,11,c[45]),A=r(A,E,P,T,O,16,c[46]),P=o(P,T=r(T,A,E,P,l,23,c[47]),A,E,u,6,c[48]),E=o(E,P,T,A,y,10,c[49]),A=o(A,E,P,T,w,15,c[50]),T=o(T,A,E,P,f,21,c[51]),P=o(P,T,A,E,_,6,c[52]),E=o(E,P,T,A,p,10,c[53]),A=o(A,E,P,T,b,15,c[54]),T=o(T,A,E,P,a,21,c[55]),P=o(P,T,A,E,g,6,c[56]),E=o(E,P,T,A,O,10,c[57]),A=o(A,E,P,T,d,15,c[58]),T=o(T,A,E,P,S,21,c[59]),P=o(P,T,A,E,h,6,c[60]),E=o(E,P,T,A,v,10,c[61]),A=o(A,E,P,T,l,15,c[62]),T=o(T,A,E,P,m,21,c[63]);s[0]=s[0]+P|0,s[1]=s[1]+T|0,s[2]=s[2]+A|0,s[3]=s[3]+E|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var i=e.floor(r/4294967296);for(n[15+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(o+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,r=0;4>r;r++)o=n[r],n[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(u),i.HmacMD5=a._createHmacHelper(u)}(Math),function(){var e,t=P,n=(e=t.lib).Base,r=e.WordArray,o=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),o=r.create(),i=o.words,s=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:u,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var p=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(u=(f.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return p.create({ciphertext:e,salt:n})}},t.SerializableCipher=n.extend({cfg:n.extend({format:u}),encrypt:function(e,t,n,r){r=this.cfg.extend(r);var o=e.createEncryptor(n,r);return t=o.finalize(t),o=o.cfg,p.create({ciphertext:t,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:r.format})},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),e.createDecryptor(n,r).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),f=(f.kdf={}).OpenSSL={execute:function(e,t,n,o){return o||(o=r.random(8)),e=s.create({keySize:t+n}).compute(e,o),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,p.create({key:e,iv:n,salt:o})}},d=t.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:f}),encrypt:function(e,t,n,r){return n=(r=this.cfg.extend(r)).kdf.execute(n,e.keySize,e.ivSize),r.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,r)).mixIn(n),e},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),n=r.kdf.execute(n,e.keySize,e.ivSize,t.salt),r.iv=n.iv,h.decrypt.call(this,e,t,n.key,r)}})}(),function(){for(var e=P,t=e.lib.BlockCipher,n=e.algo,r=[],o=[],i=[],s=[],a=[],u=[],c=[],l=[],p=[],h=[],f=[],d=0;256>d;d++)f[d]=128>d?d<<1:d<<1^283;var y=0,g=0;for(d=0;256>d;d++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;r[y]=m,o[m]=y;var b=f[y],v=f[b],_=f[v],S=257*f[m]^16843008*m;i[y]=S<<24|S>>>8,s[y]=S<<16|S>>>16,a[y]=S<<8|S>>>24,u[y]=S,S=16843009*_^65537*v^257*b^16843008*y,c[m]=S<<24|S>>>8,l[m]=S<<16|S>>>16,p[m]=S<<8|S>>>24,h[m]=S,y?(y=b^f[f[f[_^b]]],g^=f[f[g]]):y=g=1}var w=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),o=this._keySchedule=[],i=0;i>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s]):(s=r[(s=s<<8|s>>>24)>>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s],s^=w[i/t|0]<<24),o[i]=o[i-t]^s}for(e=this._invKeySchedule=[],t=0;tt||4>=i?s:c[r[s>>>24]]^l[r[s>>>16&255]]^p[r[s>>>8&255]]^h[r[255&s]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,s,a,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,c,l,p,h,o),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,r,o,i,s,a){for(var u=this._nRounds,c=e[t]^n[0],l=e[t+1]^n[1],p=e[t+2]^n[2],h=e[t+3]^n[3],f=4,d=1;d>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&h]^n[f++],g=r[l>>>24]^o[p>>>16&255]^i[h>>>8&255]^s[255&c]^n[f++],m=r[p>>>24]^o[h>>>16&255]^i[c>>>8&255]^s[255&l]^n[f++];h=r[h>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^n[f++],c=y,l=g,p=m}y=(a[c>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&h])^n[f++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[h>>>8&255]<<8|a[255&c])^n[f++],m=(a[p>>>24]<<24|a[h>>>16&255]<<16|a[c>>>8&255]<<8|a[255&l])^n[f++],h=(a[h>>>24]<<24|a[c>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^n[f++],e[t]=y,e[t+1]=g,e[t+2]=m,e[t+3]=h},keySize:8});e.AES=t._createHelper(n)}(),P.mode.ECB=((O=P.lib.BlockCipherMode.extend()).Encryptor=O.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),O.Decryptor=O.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),O);var E=P;function A(e){var t,n=[];for(t=0;t=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))},e.prototype.clearHistory=function(){this.hashHistory=[]},e}(),k={PNNetworkUpCategory:"PNNetworkUpCategory",PNNetworkDownCategory:"PNNetworkDownCategory",PNNetworkIssuesCategory:"PNNetworkIssuesCategory",PNTimeoutCategory:"PNTimeoutCategory",PNBadRequestCategory:"PNBadRequestCategory",PNAccessDeniedCategory:"PNAccessDeniedCategory",PNUnknownCategory:"PNUnknownCategory",PNReconnectedCategory:"PNReconnectedCategory",PNConnectedCategory:"PNConnectedCategory",PNRequestMessageCountExceededCategory:"PNRequestMessageCountExceededCategory",PNDisconnectedCategory:"PNDisconnectedCategory",PNConnectionErrorCategory:"PNConnectionErrorCategory",PNDisconnectedUnexpectedlyCategory:"PNDisconnectedUnexpectedlyCategory"},M=function(){function e(e){var t=e.subscribeEndpoint,n=e.leaveEndpoint,r=e.heartbeatEndpoint,o=e.setStateEndpoint,i=e.timeEndpoint,s=e.getFileUrl,a=e.config,u=e.crypto,c=e.listenerManager,l=e.cryptoModule,p=e.eventEmitter;this._listenerManager=c,this._config=a,this._leaveEndpoint=n,this._heartbeatEndpoint=r,this._setStateEndpoint=o,this._subscribeEndpoint=t,this._getFileUrl=s,this._crypto=u,this._cryptoModule=l,this._channels={},this._presenceChannels={},this._heartbeatChannels={},this._heartbeatChannelGroups={},this._channelGroups={},this._presenceChannelGroups={},this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[],this._currentTimetoken=0,this._lastTimetoken=0,this._storedTimetoken=null,this._subscriptionStatusAnnounced=!1,this._isOnline=!0,this._reconnectionManager=new N({timeEndpoint:i}),this._dedupingManager=new C({config:a}),this._cryptoModule&&(this._decoder=new TextDecoder),this._eventEmitter=p}return e.prototype.adaptStateChange=function(e,t){var n=this,r=e.state,o=e.channels,i=void 0===o?[]:o,s=e.channelGroups,a=void 0===s?[]:s,u=e.withHeartbeat,c=void 0!==u&&u;if(i.forEach((function(e){e in n._channels&&(n._channels[e].state=r)})),a.forEach((function(e){e in n._channelGroups&&(n._channelGroups[e].state=r)})),c){var l={};return i.forEach((function(e){return l[e]=r})),a.forEach((function(e){return l[e]=r})),this._heartbeatEndpoint({channels:i,channelGroups:a,state:l},t)}return this._setStateEndpoint({state:r,channels:i,channelGroups:a},t)},e.prototype.adaptPresenceChange=function(e){var t=this,n=e.connected,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i;n?(o.forEach((function(e){t._heartbeatChannels[e]={state:{}}})),s.forEach((function(e){t._heartbeatChannelGroups[e]={state:{}}}))):(o.forEach((function(e){e in t._heartbeatChannels&&delete t._heartbeatChannels[e]})),s.forEach((function(e){e in t._heartbeatChannelGroups&&delete t._heartbeatChannelGroups[e]})),!1===this._config.suppressLeaveEvents&&this._leaveEndpoint({channels:o,channelGroups:s},(function(e){t._listenerManager.announceStatus(e)}))),this.reconnect()},e.prototype.adaptSubscribeChange=function(e){var t=this,n=e.timetoken,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=e.withPresence,u=void 0!==a&&a,c=e.withHeartbeats,l=void 0!==c&&c;this._config.subscribeKey&&""!==this._config.subscribeKey?(n&&(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=n),"0"!==this._currentTimetoken&&0!==this._currentTimetoken&&(this._storedTimetoken=this._currentTimetoken,this._currentTimetoken=0),o.forEach((function(e){t._channels[e]={state:{}},u&&(t._presenceChannels[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannels[e]={}),t._pendingChannelSubscriptions.push(e)})),s.forEach((function(e){t._channelGroups[e]={state:{}},u&&(t._presenceChannelGroups[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannelGroups[e]={}),t._pendingChannelGroupSubscriptions.push(e)})),this._subscriptionStatusAnnounced=!1,this.reconnect()):console&&console.log&&console.log("subscribe key missing; aborting subscribe")},e.prototype.adaptUnsubscribeChange=function(e,t){var n=this,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=[],u=[];o.forEach((function(e){e in n._channels&&(delete n._channels[e],a.push(e),e in n._heartbeatChannels&&delete n._heartbeatChannels[e]),e in n._presenceChannels&&(delete n._presenceChannels[e],a.push(e))})),s.forEach((function(e){e in n._channelGroups&&(delete n._channelGroups[e],u.push(e),e in n._heartbeatChannelGroups&&delete n._heartbeatChannelGroups[e]),e in n._presenceChannelGroups&&(delete n._presenceChannelGroups[e],u.push(e))})),0===a.length&&0===u.length||(!1!==this._config.suppressLeaveEvents||t||this._leaveEndpoint({channels:a,channelGroups:u},(function(e){e.affectedChannels=a,e.affectedChannelGroups=u,e.currentTimetoken=n._currentTimetoken,e.lastTimetoken=n._lastTimetoken,n._listenerManager.announceStatus(e)})),0===Object.keys(this._channels).length&&0===Object.keys(this._presenceChannels).length&&0===Object.keys(this._channelGroups).length&&0===Object.keys(this._presenceChannelGroups).length&&(this._lastTimetoken=0,this._currentTimetoken=0,this._storedTimetoken=null,this._region=null,this._reconnectionManager.stopPolling()),this.reconnect())},e.prototype.unsubscribeAll=function(e){this.adaptUnsubscribeChange({channels:this.getSubscribedChannels(),channelGroups:this.getSubscribedChannelGroups()},e)},e.prototype.getHeartbeatChannels=function(){return Object.keys(this._heartbeatChannels)},e.prototype.getHeartbeatChannelGroups=function(){return Object.keys(this._heartbeatChannelGroups)},e.prototype.getSubscribedChannels=function(){return Object.keys(this._channels)},e.prototype.getSubscribedChannelGroups=function(){return Object.keys(this._channelGroups)},e.prototype.reconnect=function(){this._startSubscribeLoop(),this._registerHeartbeatTimer()},e.prototype.disconnect=function(){this._stopSubscribeLoop(),this._stopHeartbeatTimer(),this._reconnectionManager.stopPolling()},e.prototype._registerHeartbeatTimer=function(){this._stopHeartbeatTimer(),0!==this._config.getHeartbeatInterval()&&void 0!==this._config.getHeartbeatInterval()&&(this._performHeartbeatLoop(),this._heartbeatTimer=setInterval(this._performHeartbeatLoop.bind(this),1e3*this._config.getHeartbeatInterval()))},e.prototype._stopHeartbeatTimer=function(){this._heartbeatTimer&&(clearInterval(this._heartbeatTimer),this._heartbeatTimer=null)},e.prototype._performHeartbeatLoop=function(){var e=this,t=this.getHeartbeatChannels(),n=this.getHeartbeatChannelGroups(),r={};if(0!==t.length||0!==n.length){this.getSubscribedChannels().forEach((function(t){var n=e._channels[t].state;Object.keys(n).length&&(r[t]=n)})),this.getSubscribedChannelGroups().forEach((function(t){var n=e._channelGroups[t].state;Object.keys(n).length&&(r[t]=n)}));this._heartbeatEndpoint({channels:t,channelGroups:n,state:r},function(t){t.error&&e._config.announceFailedHeartbeats&&e._listenerManager.announceStatus(t),t.error&&e._config.autoNetworkDetection&&e._isOnline&&(e._isOnline=!1,e.disconnect(),e._listenerManager.announceNetworkDown(),e.reconnect()),!t.error&&e._config.announceSuccessfulHeartbeats&&e._listenerManager.announceStatus(t)}.bind(this))}},e.prototype._startSubscribeLoop=function(){var e=this;this._stopSubscribeLoop();var t={},n=[],r=[];if(Object.keys(this._channels).forEach((function(r){var o=e._channels[r].state;Object.keys(o).length&&(t[r]=o),n.push(r)})),Object.keys(this._presenceChannels).forEach((function(e){n.push("".concat(e,"-pnpres"))})),Object.keys(this._channelGroups).forEach((function(n){var o=e._channelGroups[n].state;Object.keys(o).length&&(t[n]=o),r.push(n)})),Object.keys(this._presenceChannelGroups).forEach((function(e){r.push("".concat(e,"-pnpres"))})),0!==n.length||0!==r.length){var o={channels:n,channelGroups:r,state:t,timetoken:this._currentTimetoken,filterExpression:this._config.filterExpression,region:this._region};this._subscribeCall=this._subscribeEndpoint(o,this._processSubscribeResponse.bind(this))}},e.prototype._processSubscribeResponse=function(e,t){var n=this;if(e.error){if(e.errorData&&"Aborted"===e.errorData.message)return;e.category===k.PNTimeoutCategory?this._startSubscribeLoop():e.category===k.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this._config.autoNetworkDetection&&this._isOnline&&(this._isOnline=!1,this._listenerManager.announceNetworkDown()),this._reconnectionManager.onReconnection((function(){n._config.autoNetworkDetection&&!n._isOnline&&(n._isOnline=!0,n._listenerManager.announceNetworkUp()),n.reconnect(),n._subscriptionStatusAnnounced=!0;var t={category:k.PNReconnectedCategory,operation:e.operation,lastTimetoken:n._lastTimetoken,currentTimetoken:n._currentTimetoken};n._listenerManager.announceStatus(t)})),this._reconnectionManager.startPolling(),this._listenerManager.announceStatus(e)):e.category===k.PNBadRequestCategory?(this._stopHeartbeatTimer(),this._listenerManager.announceStatus(e)):this._listenerManager.announceStatus(e)}else{if(this._storedTimetoken?(this._currentTimetoken=this._storedTimetoken,this._storedTimetoken=null):(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=t.metadata.timetoken),!this._subscriptionStatusAnnounced){var r={};r.category=k.PNConnectedCategory,r.operation=e.operation,r.affectedChannels=this._pendingChannelSubscriptions,r.subscribedChannels=this.getSubscribedChannels(),r.affectedChannelGroups=this._pendingChannelGroupSubscriptions,r.lastTimetoken=this._lastTimetoken,r.currentTimetoken=this._currentTimetoken,this._subscriptionStatusAnnounced=!0,this._listenerManager.announceStatus(r),this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[]}var o=t.messages||[],i=this._config,s=i.requestMessageCountThreshold,a=i.dedupeOnSubscribe;if(s&&o.length>=s){var u={};u.category=k.PNRequestMessageCountExceededCategory,u.operation=e.operation,this._listenerManager.announceStatus(u)}o.forEach((function(e){if(e.channel,e.subscriptionMatch,a){if(n._dedupingManager.isDuplicate(e))return;n._dedupingManager.addEntry(e)}n._eventEmitter.emitEvent(e)})),this._region=t.metadata.region,this._startSubscribeLoop()}},e.prototype._stopSubscribeLoop=function(){this._subscribeCall&&("function"==typeof this._subscribeCall.abort&&this._subscribeCall.abort(),this._subscribeCall=null)},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),j={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",PNAccessManagerRevokeToken:"PNAccessManagerRevokeToken",PNHandshakeOperation:"PNHandshakeOperation",PNReceiveMessagesOperation:"PNReceiveMessagesOperation"},R=function(){function e(e){this._maximumSamplesCount=100,this._trackedLatencies={},this._latencies={},this._telemetryExcludeOperations=[j.PNSubscribeOperation,j.PNReceiveMessagesOperation,j.PNHandshakeOperation],this._maximumSamplesCount=e.maximumSamplesCount||this._maximumSamplesCount}return e.prototype.operationsLatencyForRequest=function(){var e=this,t={};return Object.keys(this._latencies).forEach((function(n){var r=e._latencies[n],o=e._averageLatency(r);o>0&&(t["l_".concat(n)]=o)})),t},e.prototype.startLatencyMeasure=function(e,t){!this._telemetryExcludeOperations.includes(e)&&t&&(this._trackedLatencies[t]=Date.now())},e.prototype.stopLatencyMeasure=function(e,t){if(!this._telemetryExcludeOperations.includes(e)&&t){var n=this._endpointName(e),r=this._latencies[n],o=this._trackedLatencies[t];r||(this._latencies[n]=[],r=this._latencies[n]),r.push(Date.now()-o),r.length>this._maximumSamplesCount&&r.splice(0,r.length-this._maximumSamplesCount),delete this._trackedLatencies[t]}},e.prototype._averageLatency=function(e){return Math.floor(e.reduce((function(e,t){return e+t}),0)/e.length)},e.prototype._endpointName=function(e){var t=null;switch(e){case j.PNPublishOperation:t="pub";break;case j.PNSignalOperation:t="sig";break;case j.PNHistoryOperation:case j.PNFetchMessagesOperation:case j.PNDeleteMessagesOperation:case j.PNMessageCounts:t="hist";break;case j.PNUnsubscribeOperation:case j.PNWhereNowOperation:case j.PNHereNowOperation:case j.PNHeartbeatOperation:case j.PNSetStateOperation:case j.PNGetStateOperation:t="pres";break;case j.PNAddChannelsToGroupOperation:case j.PNRemoveChannelsFromGroupOperation:case j.PNChannelGroupsOperation:case j.PNRemoveGroupOperation:case j.PNChannelsForGroupOperation:t="cg";break;case j.PNPushNotificationEnabledChannelsOperation:case j.PNRemoveAllPushNotificationsOperation:t="push";break;case j.PNCreateUserOperation:case j.PNUpdateUserOperation:case j.PNDeleteUserOperation:case j.PNGetUserOperation:case j.PNGetUsersOperation:case j.PNCreateSpaceOperation:case j.PNUpdateSpaceOperation:case j.PNDeleteSpaceOperation:case j.PNGetSpaceOperation:case j.PNGetSpacesOperation:case j.PNGetMembersOperation:case j.PNUpdateMembersOperation:case j.PNGetMembershipsOperation:case j.PNUpdateMembershipsOperation:t="obj";break;case j.PNAddMessageActionOperation:case j.PNRemoveMessageActionOperation:case j.PNGetMessageActionsOperation:t="msga";break;case j.PNAccessManagerGrant:case j.PNAccessManagerAudit:t="pam";break;case j.PNAccessManagerGrantToken:case j.PNAccessManagerRevokeToken:t="pamv3";break;default:t="time"}return t},e}(),x=function(){function e(e,t,n){this._payload=e,this._setDefaultPayloadStructure(),this.title=t,this.body=n}return Object.defineProperty(e.prototype,"payload",{get:function(){return this._payload},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{set:function(e){this._title=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{set:function(e){this._subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{set:function(e){this._body=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{set:function(e){this._badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{set:function(e){this._sound=e},enumerable:!1,configurable:!0}),e.prototype._setDefaultPayloadStructure=function(){},e.prototype.toObject=function(){return{}},e}(),U=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"configurations",{set:function(e){e&&e.length&&(this._configurations=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"notification",{get:function(){return this._payload.aps},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.aps.alert.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){e&&e.length&&(this._payload.aps.alert.subtitle=e,this._subtitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.aps.alert.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this._badge},set:function(e){null!=e&&(this._payload.aps.badge=e,this._badge=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.aps.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),r.prototype._setDefaultPayloadStructure=function(){this._payload.aps={alert:{}}},r.prototype.toObject=function(){var e=this,t=n({},this._payload),r=t.aps,o=r.alert;if(this._isSilent&&(r["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");var i=[];this._configurations.forEach((function(t){i.push(e._objectFromAPNS2Configuration(t))})),i.length&&(t.pn_push=i)}return o&&Object.keys(o).length||delete r.alert,this._isSilent&&(delete r.alert,delete r.badge,delete r.sound,o={}),this._isSilent||Object.keys(o).length?t:null},r.prototype._objectFromAPNS2Configuration=function(e){var t=this;if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");var n=[];e.targets.forEach((function(e){n.push(t._objectFromAPNSTarget(e))}));var r=e.collapseId,o=e.expirationDate,i={auth_method:"token",targets:n,version:"v2"};return r&&r.length&&(i.collapse_id=r),o&&(i.expiration=o.toISOString()),i},r.prototype._objectFromAPNSTarget=function(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");var t=e.topic,n=e.environment,r=void 0===n?"development":n,o=e.excludedDevices,i=void 0===o?[]:o,s={topic:t,environment:r};return i.length&&(s.excluded_devices=i),s},r}(x),I=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"backContent",{get:function(){return this._backContent},set:function(e){e&&e.length&&(this._payload.back_content=e,this._backContent=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"backTitle",{get:function(){return this._backTitle},set:function(e){e&&e.length&&(this._payload.back_title=e,this._backTitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"count",{get:function(){return this._count},set:function(e){null!=e&&(this._payload.count=e,this._count=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"type",{get:function(){return this._type},set:function(e){e&&e.length&&(this._payload.type=e,this._type=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this.backTitle},set:function(e){this.backTitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this.backContent},set:function(e){this.backContent=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this.count},set:function(e){this.count=e},enumerable:!1,configurable:!0}),r.prototype.toObject=function(){return Object.keys(this._payload).length?n({},this._payload):null},r}(x),D=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return t(o,e),Object.defineProperty(o.prototype,"notification",{get:function(){return this._payload.notification},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"data",{get:function(){return this._payload.data},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.notification.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.notification.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.notification.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"icon",{get:function(){return this._icon},set:function(e){e&&e.length&&(this._payload.notification.icon=e,this._icon=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"tag",{get:function(){return this._tag},set:function(e){e&&e.length&&(this._payload.notification.tag=e,this._tag=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),o.prototype._setDefaultPayloadStructure=function(){this._payload.notification={},this._payload.data={}},o.prototype.toObject=function(){var e=n({},this._payload.data),t=null,o={};if(Object.keys(this._payload).length>2){var i=this._payload;i.notification,i.data;var s=r(i,["notification","data"]);e=n(n({},e),s)}return this._isSilent?e.notification=this._payload.notification:t=this._payload.notification,Object.keys(e).length&&(o.data=e),t&&Object.keys(t).length&&(o.notification=t),Object.keys(o).length?o:null},o}(x),F=function(){function e(e,t){this._payload={apns:{},mpns:{},fcm:{}},this._title=e,this._body=t,this.apns=new U(this._payload.apns,e,t),this.mpns=new I(this._payload.mpns,e,t),this.fcm=new D(this._payload.fcm,e,t)}return Object.defineProperty(e.prototype,"debugging",{set:function(e){this._debugging=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this._body},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){this._subtitle=e,this.apns.subtitle=e,this.mpns.subtitle=e,this.fcm.subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{get:function(){return this._badge},set:function(e){this._badge=e,this.apns.badge=e,this.mpns.badge=e,this.fcm.badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{get:function(){return this._sound},set:function(e){this._sound=e,this.apns.sound=e,this.mpns.sound=e,this.fcm.sound=e},enumerable:!1,configurable:!0}),e.prototype.buildPayload=function(e){var t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";var n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("mpns")){var r=this.mpns.toObject();r&&Object.keys(r).length&&(t.pn_mpns=r)}if(e.includes("fcm")){var o=this.fcm.toObject();o&&Object.keys(o).length&&(t.pn_gcm=o)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t},e}(),L=function(){function e(){this._listeners=[]}return e.prototype.addListener=function(e){this._listeners.includes(e)||this._listeners.push(e)},e.prototype.removeListener=function(e){var t=[];this._listeners.forEach((function(n){n!==e&&t.push(n)})),this._listeners=t},e.prototype.removeAllListeners=function(){this._listeners=[]},e.prototype.announcePresence=function(e){this._listeners.forEach((function(t){t.presence&&t.presence(e)}))},e.prototype.announceStatus=function(e){this._listeners.forEach((function(t){t.status&&t.status(e)}))},e.prototype.announceMessage=function(e){this._listeners.forEach((function(t){t.message&&t.message(e)}))},e.prototype.announceSignal=function(e){this._listeners.forEach((function(t){t.signal&&t.signal(e)}))},e.prototype.announceMessageAction=function(e){this._listeners.forEach((function(t){t.messageAction&&t.messageAction(e)}))},e.prototype.announceFile=function(e){this._listeners.forEach((function(t){t.file&&t.file(e)}))},e.prototype.announceObjects=function(e){this._listeners.forEach((function(t){t.objects&&t.objects(e)}))},e.prototype.announceUser=function(e){this._listeners.forEach((function(t){t.user&&t.user(e)}))},e.prototype.announceSpace=function(e){this._listeners.forEach((function(t){t.space&&t.space(e)}))},e.prototype.announceMembership=function(e){this._listeners.forEach((function(t){t.membership&&t.membership(e)}))},e.prototype.announceNetworkUp=function(){var e={};e.category=k.PNNetworkUpCategory,this.announceStatus(e)},e.prototype.announceNetworkDown=function(){var e={};e.category=k.PNNetworkDownCategory,this.announceStatus(e)},e}(),G=function(){function e(e,t){this._config=e,this._cbor=t}return e.prototype.setToken=function(e){e&&e.length>0?this._token=e:this._token=void 0},e.prototype.getToken=function(){return this._token},e.prototype.extractPermissions=function(e){var t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128==(128&e)&&(t.join=!0),64==(64&e)&&(t.update=!0),32==(32&e)&&(t.get=!0),8==(8&e)&&(t.delete=!0),4==(4&e)&&(t.manage=!0),2==(2&e)&&(t.write=!0),1==(1&e)&&(t.read=!0),t},e.prototype.parseToken=function(e){var t=this,n=this._cbor.decodeToken(e);if(void 0!==n){var r=n.res.uuid?Object.keys(n.res.uuid):[],o=Object.keys(n.res.chan),i=Object.keys(n.res.grp),s=n.pat.uuid?Object.keys(n.pat.uuid):[],a=Object.keys(n.pat.chan),u=Object.keys(n.pat.grp),c={version:n.v,timestamp:n.t,ttl:n.ttl,authorized_uuid:n.uuid},l=r.length>0,p=o.length>0,h=i.length>0;(l||p||h)&&(c.resources={},l&&(c.resources.uuids={},r.forEach((function(e){c.resources.uuids[e]=t.extractPermissions(n.res.uuid[e])}))),p&&(c.resources.channels={},o.forEach((function(e){c.resources.channels[e]=t.extractPermissions(n.res.chan[e])}))),h&&(c.resources.groups={},i.forEach((function(e){c.resources.groups[e]=t.extractPermissions(n.res.grp[e])}))));var f=s.length>0,d=a.length>0,y=u.length>0;return(f||d||y)&&(c.patterns={},f&&(c.patterns.uuids={},s.forEach((function(e){c.patterns.uuids[e]=t.extractPermissions(n.pat.uuid[e])}))),d&&(c.patterns.channels={},a.forEach((function(e){c.patterns.channels[e]=t.extractPermissions(n.pat.chan[e])}))),y&&(c.patterns.groups={},u.forEach((function(e){c.patterns.groups[e]=t.extractPermissions(n.pat.grp[e])})))),Object.keys(n.meta).length>0&&(c.meta=n.meta),c.signature=n.sig,c}},e}();function K(e){return encodeURIComponent(e).replace(/[!~*'()]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())}))}function B(e){return function(e){var t=[];return Object.keys(e).forEach((function(e){return t.push(e)})),t}(e).sort()}var H={signPamFromParams:function(e){return B(e).map((function(t){return"".concat(t,"=").concat(K(e[t]))})).join("&")},endsWith:function(e,t){return-1!==e.indexOf(t,this.length-t.length)},createPromise:function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),reject:t,fulfill:e}},encodeString:K,stringToArrayBuffer:function(e){for(var t=new ArrayBuffer(2*e.length),n=new Uint16Array(t),r=0,o=e.length;r0&&(t+=n),t}function J(e,t,n){return t.usePost&&t.usePost(e,n)?"POST":t.usePatch&&t.usePatch(e,n)?"PATCH":t.useDelete&&t.useDelete(e,n)?"DELETE":t.useGetFile&&t.useGetFile(e,n)?"GETFILE":"GET"}function $(e,t,n,r,o){var i=e.config,s=e.crypto,a=J(e,o,r);n.timestamp=Math.floor((new Date).getTime()/1e3),"PNPublishOperation"===o.getOperation()&&o.usePost&&o.usePost(e,r)&&(a="GET"),"GETFILE"===a&&(a="GET");var u="".concat(a,"\n").concat(i.publishKey,"\n").concat(t,"\n").concat(H.signPamFromParams(n),"\n");if("POST"===a)u+="string"==typeof(c=o.postPayload(e,r))?c:JSON.stringify(c);else if("PATCH"===a){var c;u+="string"==typeof(c=o.patchPayload(e,r))?c:JSON.stringify(c)}var l="v2.".concat(s.HMACSHA256(u));l=(l=(l=l.replace(/\+/g,"-")).replace(/\//g,"_")).replace(/=+$/,""),n.signature=l}function Q(e,t){for(var r=[],o=2;o0&&(c.count=u),c},handleResponse:function(e,t){return{channels:t}}});var ie=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveAllPushNotificationsOperation},validateParams:function(e,t){var n=t.device,r=t.pushGateway,o=t.topic,i=e.config;return n?r?"apns2"!==r||o?i.subscribeKey?void 0:"Missing Subscribe Key":"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm, apns or apns2)":"Missing Device ID (device)"},getURL:function(e,t){var n=t.device,r=t.pushGateway,o=e.config;return"apns2"===r?"/v2/push/sub-key/".concat(o.subscribeKey,"/devices-apns2/").concat(n,"/remove"):"/v1/push/sub-key/".concat(o.subscribeKey,"/devices/").concat(n,"/remove")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.pushGateway,o=t.environment,i=void 0===o?"development":o,s=t.topic,a={type:r};return"apns2"===r&&delete(a=n(n({},a),{environment:i,topic:s})).type,a},handleResponse:function(){return{}}});var se=Object.freeze({__proto__:null,getOperation:function(){return j.PNUnsubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/leave")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(){return{}}});var ae=Object.freeze({__proto__:null,getOperation:function(){return j.PNWhereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r;return"/v2/presence/sub-key/".concat(n.subscribeKey,"/uuid/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return t.payload?{channels:t.payload.channels}:{channels:[]}}});var ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNHeartbeatOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/heartbeat")},isAuthSupported:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o=t.state,i=e.config,s={};return r.length>0&&(s["channel-group"]=r.join(",")),o&&(s.state=JSON.stringify(o)),s.heartbeat=i.getPresenceTimeout(),s},handleResponse:function(){return{}}});var ce=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetStateOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r,i=t.channels,s=void 0===i?[]:i,a=s.length>0?s.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(a),"/uuid/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a={};return 1===o.length&&0===s.length?a[o[0]]=t.payload:a=t.payload,{channels:a}}});var le=Object.freeze({__proto__:null,getOperation:function(){return j.PNSetStateOperation},validateParams:function(e,t){var n=e.config,r=t.state,o=t.channels,i=void 0===o?[]:o,s=t.channelGroups,a=void 0===s?[]:s;return r?n.subscribeKey?0===i.length&&0===a.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key":"Missing State"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/uuid/").concat(H.encodeString(n.UUID),"/data")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.state,r=t.channelGroups,o=void 0===r?[]:r,i={};return i.state=JSON.stringify(n),o.length>0&&(i["channel-group"]=o.join(",")),i},handleResponse:function(e,t){return{state:t.payload}}});var pe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=t.channelGroups,s=void 0===i?[]:i,a="/v2/presence/sub-key/".concat(n.subscribeKey);if(o.length>0||s.length>0){var u=o.length>0?o.join(","):",";a+="/channel/".concat(H.encodeString(u))}return a},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.channelGroups,o=void 0===r?[]:r,i=t.includeUUIDs,s=void 0===i||i,a=t.includeState,u=void 0!==a&&a,c=t.queryParameters,l=void 0===c?{}:c,p={};return s||(p.disable_uuids=1),u&&(p.state=1),o.length>0&&(p["channel-group"]=o.join(",")),p=n(n({},p),l)},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a=n.includeUUIDs,u=void 0===a||a,c=n.includeState,l=void 0!==c&&c;return o.length>1||s.length>0||0===s.length&&0===o.length?function(){var e={};return e.totalChannels=t.payload.total_channels,e.totalOccupancy=t.payload.total_occupancy,e.channels={},Object.keys(t.payload.channels).forEach((function(n){var r=t.payload.channels[n],o=[];return e.channels[n]={occupants:o,name:n,occupancy:r.occupancy},u&&r.uuids.forEach((function(e){l?o.push({state:e.state,uuid:e.uuid}):o.push({state:null,uuid:e})})),e})),e}():function(){var e={},n=[];return e.totalChannels=1,e.totalOccupancy=t.occupancy,e.channels={},e.channels[o[0]]={occupants:n,name:o[0],occupancy:t.occupancy},u&&t.uuids&&t.uuids.forEach((function(e){l?n.push({state:e.state,uuid:e.uuid}):n.push({state:null,uuid:e})})),e}()},handleError:function(e,t,n){402!==n.statusCode||this.getURL(e,t).includes("channel")||(n.errorData.message="You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.")}});var he=Object.freeze({__proto__:null,getOperation:function(){return j.PNAddMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.action,o=t.channel;return t.messageTimetoken?n.subscribeKey?o?r?r.value?r.type?r.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message channel":"Missing Subscribe Key":"Missing message timetoken"},usePost:function(){return!0},postURL:function(e,t){var n=e.config,r=t.channel,o=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},getRequestHeaders:function(){return{"Content-Type":"application/json"}},isAuthSupported:function(){return!0},prepareParams:function(){return{}},postPayload:function(e,t){return t.action},handleResponse:function(e,t){return{data:t.data}}});var fe=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken;return t.messageTimetoken?o?n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key":"Missing action timetoken":"Missing message timetoken"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken,i=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(i,"/action/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{data:t.data}}});var de=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetMessageActionsOperation},validateParams:function(e,t){var n=e.config,r=t.channel;return n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channel;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.limit,r=t.start,o=t.end,i={};return n&&(i.limit=n),r&&(i.start=r),o&&(i.end=o),i},handleResponse:function(e,t){var n={data:t.data,start:null,end:null};return n.data.length&&(n.end=n.data[n.data.length-1].actionTimetoken,n.start=n.data[0].actionTimetoken),n}}),ye={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel can't be empty"},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.limit&&(n.limit=t.limit),t.next&&(n.next=t.next),n},handleResponse:function(e,t){return{status:t.status,data:t.data,next:t.next,count:t.count}}},ge={getOperation:function(){return j.PNGenerateUploadUrlOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?void 0:"name can't be empty":"channel can't be empty"},usePost:function(){return!0},postURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/generate-upload-url")},postPayload:function(e,t){return{name:t.name}},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data,file_upload_request:t.file_upload_request}}},me={getOperation:function(){return j.PNPublishFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.fileId)?(null==t?void 0:t.fileName)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},getURL:function(e,t){var n=e.config,r=n.publishKey,o=n.subscribeKey,i=function(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}(e,{message:t.message,file:{name:t.fileName,id:t.fileId}});return"/v1/files/publish-file/".concat(r,"/").concat(o,"/0/").concat(H.encodeString(t.channel),"/0/").concat(H.encodeString(i))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.ttl&&(n.ttl=t.ttl),void 0!==t.storeInHistory&&(n.store=t.storeInHistory?"1":"0"),t.meta&&"object"==typeof t.meta&&(n.meta=JSON.stringify(t.meta)),n},handleResponse:function(e,t){return{timetoken:t[2]}}},be=function(e){var t=function(e){var t=this,n=e.generateUploadUrl,r=e.publishFile,s=e.modules,a=s.PubNubFile,u=s.config,c=s.cryptography,l=s.cryptoModule,p=s.networking;return function(e){var s=e.channel,h=e.file,f=e.message,d=e.cipherKey,y=e.meta,g=e.ttl,m=e.storeInHistory;return o(t,void 0,void 0,(function(){var e,t,o,b,v,_,S,w,O,P,E,A,T,N,C,k,M,j,R,x,U,I,D,F,L,G,K,B,H;return i(this,(function(i){switch(i.label){case 0:if(!s)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!h)throw new q("Validation failed, check status for details",z("file can't be empty"));return e=a.create(h),[4,n({channel:s,name:e.name})];case 1:return t=i.sent(),o=t.file_upload_request,b=o.url,v=o.form_fields,_=t.data,S=_.id,w=_.name,a.supportsEncryptFile&&(d||l)?null!=d?[3,3]:[4,l.encryptFile(e,a)]:[3,6];case 2:return O=i.sent(),[3,5];case 3:return[4,c.encryptFile(d,e,a)];case 4:O=i.sent(),i.label=5;case 5:e=O,i.label=6;case 6:P=v,e.mimeType&&(P=v.map((function(t){return"Content-Type"===t.key?{key:t.key,value:e.mimeType}:t}))),i.label=7;case 7:return i.trys.push([7,21,,22]),a.supportsFileUri&&h.uri?(T=(A=p).POSTFILE,N=[b,P],[4,e.toFileUri()]):[3,10];case 8:return[4,T.apply(A,N.concat([i.sent()]))];case 9:return E=i.sent(),[3,20];case 10:return a.supportsFile?(k=(C=p).POSTFILE,M=[b,P],[4,e.toFile()]):[3,13];case 11:return[4,k.apply(C,M.concat([i.sent()]))];case 12:return E=i.sent(),[3,20];case 13:return a.supportsBuffer?(R=(j=p).POSTFILE,x=[b,P],[4,e.toBuffer()]):[3,16];case 14:return[4,R.apply(j,x.concat([i.sent()]))];case 15:return E=i.sent(),[3,20];case 16:return a.supportsBlob?(I=(U=p).POSTFILE,D=[b,P],[4,e.toBlob()]):[3,19];case 17:return[4,I.apply(U,D.concat([i.sent()]))];case 18:return E=i.sent(),[3,20];case 19:throw new Error("Unsupported environment");case 20:return[3,22];case 21:throw(F=i.sent()).response&&"string"==typeof F.response.text?(L=F.response.text,G=/(.*)<\/Message>/gi.exec(L),new q(G?"Upload to bucket failed: ".concat(G[1]):"Upload to bucket failed.",F)):new q("Upload to bucket failed.",F);case 22:if(204!==E.status)throw new q("Upload to bucket was unsuccessful",E);K=u.fileUploadPublishRetryLimit,B=!1,H={timetoken:"0"},i.label=23;case 23:return i.trys.push([23,25,,26]),[4,r({channel:s,message:f,fileId:S,fileName:w,meta:y,storeInHistory:m,ttl:g})];case 24:return H=i.sent(),B=!0,[3,26];case 25:return i.sent(),K-=1,[3,26];case 26:if(!B&&K>0)return[3,23];i.label=27;case 27:if(B)return[2,{timetoken:H.timetoken,id:S,name:w}];throw new q("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{channel:s,id:S,name:w})}}))}))}}(e);return function(e,n){var r=t(e);return"function"==typeof n?(r.then((function(e){return n(null,e)})).catch((function(e){return n(e,null)})),r):r}},ve=function(e,t){var n=t.channel,r=t.id,o=t.name,i=e.config,s=e.networking,a=e.tokenManager;if(!n)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!r)throw new q("Validation failed, check status for details",z("file id can't be empty"));if(!o)throw new q("Validation failed, check status for details",z("file name can't be empty"));var u="/v1/files/".concat(i.subscribeKey,"/channels/").concat(H.encodeString(n),"/files/").concat(r,"/").concat(o),c={};c.uuid=i.getUUID(),c.pnsdk=W(i);var l=a.getToken()||i.getAuthKey();l&&(c.auth=l),i.secretKey&&$(e,u,c,{},{getOperation:function(){return"PubNubGetFileUrlOperation"}});var p=Object.keys(c).map((function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(c[e]))})).join("&");return""!==p?"".concat(s.getStandardOrigin()).concat(u,"?").concat(p):"".concat(s.getStandardOrigin()).concat(u)},_e={getOperation:function(){return j.PNDownloadFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?(null==t?void 0:t.id)?void 0:"id can't be empty":"name can't be empty":"channel can't be empty"},useGetFile:function(){return!0},getFileURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},ignoreBody:function(){return!0},forceBuffered:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t,n){var r=e.PubNubFile,s=e.config,a=e.cryptography,u=e.cryptoModule;return o(void 0,void 0,void 0,(function(){var e,o,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.response.body,r.supportsEncryptFile&&(n.cipherKey||u)?null!=n.cipherKey?[3,2]:[4,u.decryptFile(r.create({data:e,name:n.name}),r)]:[3,5];case 1:return o=i.sent().data,[3,4];case 2:return[4,a.decrypt(null!==(c=n.cipherKey)&&void 0!==c?c:s.cipherKey,e)];case 3:o=i.sent(),i.label=4;case 4:e=o,i.label=5;case 5:return[2,r.create({data:e,name:null!==(l=t.response.name)&&void 0!==l?l:n.name,mimeType:t.response.type})]}}))}))}},Se={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.id)?(null==t?void 0:t.name)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status}}},we={getOperation:function(){return j.PNGetAllUUIDMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,next:t.next,prev:t.prev}}},Oe={getOperation:function(){return j.PNGetUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Pe={getOperation:function(){return j.PNSetUUIDMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.data))return"Data cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ee={getOperation:function(){return j.PNRemoveUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r=e.config;return{uuid:null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ae={getOperation:function(){return j.PNGetAllChannelMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Te={getOperation:function(){return j.PNGetChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ne={getOperation:function(){return j.PNSetChannelMetadataOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.data)?void 0:"Data cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ce={getOperation:function(){return j.PNRemoveChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},ke={getOperation:function(){return j.PNGetMembersOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&m.include.push("uuid"),(null===(i=t.include)||void 0===i?void 0:i.customUUIDFields)&&m.include.push("uuid.custom"),(null===(s=t.include)||void 0===s?void 0:s.UUIDStatusField)&&m.include.push("uuid.status"),(null===(u=t.include)||void 0===u?void 0:u.UUIDTypeField)&&m.include.push("uuid.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Me={getOperation:function(){return j.PNSetMembersOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.uuids)&&0!==(null==t?void 0:t.uuids.length)?void 0:"UUIDs cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.uuids.map((function(e){return"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["uuid.status","uuid.type","type"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customUUIDFields)&&h.include.push("uuid.custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&h.include.push("uuid")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},je={getOperation:function(){return j.PNGetMembershipsOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&m.include.push("channel"),(null===(i=t.include)||void 0===i?void 0:i.customChannelFields)&&m.include.push("channel.custom"),(null===(s=t.include)||void 0===s?void 0:s.channelStatusField)&&m.include.push("channel.status"),(null===(u=t.include)||void 0===u?void 0:u.channelTypeField)&&m.include.push("channel.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Re={getOperation:function(){return j.PNSetMembershipsOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)||0===(null==t?void 0:t.channels.length))return"Channels cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.channels.map((function(e){return"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["channel.status","channel.type","status"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customChannelFields)&&h.include.push("channel.custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&h.include.push("channel")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}};var xe=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerAudit},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/audit/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channel,r=t.channelGroup,o=t.authKeys,i=void 0===o?[]:o,s={};return n&&(s.channel=n),r&&(s["channel-group"]=r),i.length>0&&(s.auth=i.join(",")),s},handleResponse:function(e,t){return t.payload}});var Ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrant},validateParams:function(e,t){var n=e.config;return n.subscribeKey?n.publishKey?n.secretKey?null==t.uuids||t.authKeys?null==t.uuids||null==t.channels&&null==t.channelGroups?void 0:"Both channel/channelgroup and uuid cannot be used in the same request":"authKeys are required for grant request on uuids":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/grant/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.uuids,a=void 0===s?[]:s,u=t.ttl,c=t.read,l=void 0!==c&&c,p=t.write,h=void 0!==p&&p,f=t.manage,d=void 0!==f&&f,y=t.get,g=void 0!==y&&y,m=t.join,b=void 0!==m&&m,v=t.update,_=void 0!==v&&v,S=t.authKeys,w=void 0===S?[]:S,O=t.delete,P={};return P.r=l?"1":"0",P.w=h?"1":"0",P.m=d?"1":"0",P.d=O?"1":"0",P.g=g?"1":"0",P.j=b?"1":"0",P.u=_?"1":"0",r.length>0&&(P.channel=r.join(",")),i.length>0&&(P["channel-group"]=i.join(",")),w.length>0&&(P.auth=w.join(",")),a.length>0&&(P["target-uuid"]=a.join(",")),(u||0===u)&&(P.ttl=u),P},handleResponse:function(){return{}}});function Ie(e){var t,n,r,o,i=void 0!==(null==e?void 0:e.authorizedUserId),s=void 0!==(null===(t=null==e?void 0:e.resources)||void 0===t?void 0:t.users),a=void 0!==(null===(n=null==e?void 0:e.resources)||void 0===n?void 0:n.spaces),u=void 0!==(null===(r=null==e?void 0:e.patterns)||void 0===r?void 0:r.users),c=void 0!==(null===(o=null==e?void 0:e.patterns)||void 0===o?void 0:o.spaces);return u||s||c||a||i}function De(e){var t=0;return e.join&&(t|=128),e.update&&(t|=64),e.get&&(t|=32),e.delete&&(t|=8),e.manage&&(t|=4),e.write&&(t|=2),e.read&&(t|=1),t}function Fe(e,t){if(Ie(t))return function(e,t){var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorizedUserId,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.users,c=r.spaces,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.users,h=o.spaces,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}(0,t);var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorized_uuid,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.uuids,c=r.channels,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.uuids,h=o.channels,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}var Le=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrantToken},extractPermissions:De,validateParams:function(e,t){var n,r,o,i,s,a,u=e.config;if(!u.subscribeKey)return"Missing Subscribe Key";if(!u.publishKey)return"Missing Publish Key";if(!u.secretKey)return"Missing Secret Key";if(!t.resources&&!t.patterns)return"Missing either Resources or Patterns.";var c=void 0!==(null==t?void 0:t.authorized_uuid),l=void 0!==(null===(n=null==t?void 0:t.resources)||void 0===n?void 0:n.uuids),p=void 0!==(null===(r=null==t?void 0:t.resources)||void 0===r?void 0:r.channels),h=void 0!==(null===(o=null==t?void 0:t.resources)||void 0===o?void 0:o.groups),f=void 0!==(null===(i=null==t?void 0:t.patterns)||void 0===i?void 0:i.uuids),d=void 0!==(null===(s=null==t?void 0:t.patterns)||void 0===s?void 0:s.channels),y=void 0!==(null===(a=null==t?void 0:t.patterns)||void 0===a?void 0:a.groups),g=c||l||f||p||d||h||y;return Ie(t)&&g?"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`":(!t.resources||t.resources.uuids&&0!==Object.keys(t.resources.uuids).length||t.resources.channels&&0!==Object.keys(t.resources.channels).length||t.resources.groups&&0!==Object.keys(t.resources.groups).length||t.resources.users&&0!==Object.keys(t.resources.users).length||t.resources.spaces&&0!==Object.keys(t.resources.spaces).length)&&(!t.patterns||t.patterns.uuids&&0!==Object.keys(t.patterns.uuids).length||t.patterns.channels&&0!==Object.keys(t.patterns.channels).length||t.patterns.groups&&0!==Object.keys(t.patterns.groups).length||t.patterns.users&&0!==Object.keys(t.patterns.users).length||t.patterns.spaces&&0!==Object.keys(t.patterns.spaces).length)?void 0:"Missing values for either Resources or Patterns."},postURL:function(e){var t=e.config;return"/v3/pam/".concat(t.subscribeKey,"/grant")},usePost:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(){return{}},postPayload:function(e,t){return Fe(0,t)},handleResponse:function(e,t){return t.data.token}}),Ge={getOperation:function(){return j.PNAccessManagerRevokeToken},validateParams:function(e,t){return e.config.secretKey?t?void 0:"token can't be empty":"Missing Secret Key"},getURL:function(e,t){var n=e.config;return"/v3/pam/".concat(n.subscribeKey,"/grant/").concat(H.encodeString(t))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e){return{uuid:e.config.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}};function Ke(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}var Be=Object.freeze({__proto__:null,getOperation:function(){return j.PNPublishOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},usePost:function(e,t){var n=t.sendByPost;return void 0!==n&&n},getURL:function(e,t){var n=e.config,r=t.channel,o=Ke(e,t.message);return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0/").concat(H.encodeString(o))},postURL:function(e,t){var n=e.config,r=t.channel;return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},postPayload:function(e,t){return Ke(e,t.message)},prepareParams:function(e,t){var n=t.meta,r=t.replicate,o=void 0===r||r,i=t.storeInHistory,s=t.ttl,a={};return null!=i&&(a.store=i?"1":"0"),s&&(a.ttl=s),!1===o&&(a.norep="true"),n&&"object"==typeof n&&(a.meta=JSON.stringify(n)),a},handleResponse:function(e,t){return{timetoken:t[2]}}});var He=Object.freeze({__proto__:null,getOperation:function(){return j.PNSignalOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},getURL:function(e,t){var n,r=e.config,o=t.channel,i=t.message,s=(n=i,JSON.stringify(n));return"/signal/".concat(r.publishKey,"/").concat(r.subscribeKey,"/0/").concat(H.encodeString(o),"/0/").concat(H.encodeString(s))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{timetoken:t[2]}}});var qe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHistoryOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channel,r=e.config;return"/v2/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o=t.reverse,i=t.count,s=void 0===i?100:i,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p={include_token:"true"};return p.count=s,n&&(p.start=n),r&&(p.end=r),u&&(p.string_message_token="true"),null!=o&&(p.reverse=o.toString()),l&&(p.include_meta="true"),p},handleResponse:function(e,t){var n={messages:[],startTimeToken:t[1],endTimeToken:t[2]};return Array.isArray(t[0])&&t[0].forEach((function(t){var r=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message),o={timetoken:t.timetoken,entry:r.payload};t.meta&&(o.meta=t.meta),r.error&&(o.error=r.error),n.messages.push(o)})),n}});var ze=Object.freeze({__proto__:null,getOperation:function(){return j.PNDeleteMessagesOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},useDelete:function(){return!0},getURL:function(e,t){var n=t.channel,r=e.config;return"/v3/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o={};return n&&(o.start=n),r&&(o.end=r),o},handleResponse:function(e,t){return t.payload}});var Ve=Object.freeze({__proto__:null,getOperation:function(){return j.PNMessageCounts},validateParams:function(e,t){var n=t.channels,r=t.timetoken,o=t.channelTimetokens,i=e.config;return n?r&&o?"timetoken and channelTimetokens are incompatible together":o&&o.length>1&&n.length!==o.length?"Length of channelTimetokens and channels do not match":i.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channels,r=e.config,o=n.join(",");return"/v3/history/sub-key/".concat(r.subscribeKey,"/message-counts/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.timetoken,r=t.channelTimetokens,o={};if(r&&1===r.length){var i=a(r,1)[0];o.timetoken=i}else r?o.channelsTimetoken=r.join(","):n&&(o.timetoken=n);return o},handleResponse:function(e,t){return{channels:t.channels}}});var We=Object.freeze({__proto__:null,getOperation:function(){return j.PNFetchMessagesOperation},validateParams:function(e,t){var n=t.channels,r=t.includeMessageActions,o=void 0!==r&&r,i=e.config;if(!n||0===n.length)return"Missing channels";if(!i.subscribeKey)return"Missing Subscribe Key";if(o&&n.length>1)throw new TypeError("History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.")},getURL:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.includeMessageActions,i=void 0!==o&&o,s=e.config,a=i?"history-with-actions":"history",u=r.length>0?r.join(","):",";return"/v3/".concat(a,"/sub-key/").concat(s.subscribeKey,"/channel/").concat(H.encodeString(u))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channels,r=t.start,o=t.end,i=t.includeMessageActions,s=t.count,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p=t.includeUuid,h=t.includeUUID,f=void 0===h||h,d=t.includeMessageType,y=void 0===d||d,g={};return g.max=s||(n.length>1||!0===i?25:100),r&&(g.start=r),o&&(g.end=o),u&&(g.string_message_token="true"),l&&(g.include_meta="true"),f&&!1!==p&&(g.include_uuid="true"),y&&(g.include_message_type="true"),g},handleResponse:function(e,t){var n={channels:{}};return Object.keys(t.channels||{}).forEach((function(r){n.channels[r]=[],(t.channels[r]||[]).forEach((function(t){var o={},i=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message);o.channel=r,o.timetoken=t.timetoken,o.message=i.payload,o.messageType=t.message_type,o.uuid=t.uuid,t.actions&&(o.actions=t.actions,o.data=t.actions),t.meta&&(o.meta=t.meta),i.error&&(o.error=i.error),n.channels[r].push(o)}))})),t.more&&(n.more=t.more),n}});var Je=Object.freeze({__proto__:null,getOperation:function(){return j.PNTimeOperation},getURL:function(){return"/time/0"},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(){return{}},isAuthSupported:function(){return!1},handleResponse:function(e,t){return{timetoken:t[0]}},validateParams:function(){}});var $e=Object.freeze({__proto__:null,getOperation:function(){return j.PNSubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=e.config,r=t.state,o=t.channelGroups,i=void 0===o?[]:o,s=t.timetoken,a=t.filterExpression,u=t.region,c={heartbeat:n.getPresenceTimeout()};return i.length>0&&(c["channel-group"]=i.join(",")),a&&a.length>0&&(c["filter-expr"]=a),Object.keys(r).length&&(c.state=JSON.stringify(r)),s&&(c.tt=s),u&&(c.tr=u),c},handleResponse:function(e,t){var n=[];t.m.forEach((function(e){var t={timetoken:e.p.t,region:e.p.r},r={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:t};n.push(r)}));var r={timetoken:t.t.t,region:t.t.r};return{messages:n,metadata:r}}}),Qe={getOperation:function(){return j.PNHandshakeOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)&&!(null==t?void 0:t.channelGroups))return"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),n.tt=0,t.state&&(n.state=JSON.stringify(t.state)),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.ee="",n},handleResponse:function(e,t){return{region:t.t.r,timetoken:t.t.t}}},Xe={getOperation:function(){return j.PNReceiveMessagesOperation},validateParams:function(e,t){return(null==t?void 0:t.channels)||(null==t?void 0:t.channelGroups)?(null==t?void 0:t.timetoken)?(null==t?void 0:t.region)?void 0:"region can not be empty":"timetoken can not be empty":"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},getAbortSignal:function(e,t){return t.abortSignal},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.tt=t.timetoken,n.tr=t.region,n.ee="",n},handleResponse:function(e,t){var n=[];return t.m.forEach((function(e){var t={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:{timetoken:e.p.t,region:e.p.r}};n.push(t)})),{messages:n,metadata:{region:t.t.r,timetoken:t.t.t}}}},Ye=function(){function e(e){void 0===e&&(e=!1),this.sync=e,this.listeners=new Set}return e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.notify=function(e){var t=this,n=function(){t.listeners.forEach((function(t){t(e)}))};this.sync?n():setTimeout(n,0)},e}(),Ze=function(){function e(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}return e.prototype.transition=function(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)},e.prototype.on=function(e,t){return this.transitionMap.set(e,t),this},e.prototype.with=function(e,t){return[this,e,null!=t?t:[]]},e.prototype.onEnter=function(e){return this.enterEffects.push(e),this},e.prototype.onExit=function(e){return this.exitEffects.push(e),this},e}(),et=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return t(n,e),n.prototype.describe=function(e){return new Ze(e)},n.prototype.start=function(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})},n.prototype.transition=function(e){var t,n,r,o,i,u;if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});var c=this.currentState.transition(this.currentContext,e);if(c){var l=a(c,3),p=l[0],h=l[1],f=l[2];try{for(var d=s(this.currentState.exitEffects),y=d.next();!y.done;y=d.next()){var g=y.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}var m=this.currentState;this.currentState=p;var b=this.currentContext;this.currentContext=h,this.notify({type:"transitionDone",fromState:m,fromContext:b,toState:p,toContext:h,event:e});try{for(var v=s(f),_=v.next();!_.done;_=v.next()){g=_.value;this.notify({type:"invocationDispatched",invocation:g})}}catch(e){r={error:e}}finally{try{_&&!_.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var S=s(this.currentState.enterEffects),w=S.next();!w.done;w=S.next()){g=w.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){i={error:e}}finally{try{w&&!w.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}},n}(Ye),tt=function(){function e(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}return e.prototype.on=function(e,t){this.handlers.set(e,t)},e.prototype.dispatch=function(e){if("CANCEL"!==e.type){var t=this.handlers.get(e.type);if(!t)throw new Error("Unhandled invocation '".concat(e.type,"'"));var n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}else if(this.instances.has(e.payload)){var r=this.instances.get(e.payload);null==r||r.cancel(),this.instances.delete(e.payload)}},e.prototype.dispose=function(){var e,t;try{for(var n=s(this.instances.entries()),r=n.next();!r.done;r=n.next()){var o=a(r.value,2),i=o[0];o[1].cancel(),this.instances.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();function nt(e,t){var n=function(){for(var n=[],r=0;r0&&r(e),[2]}))}))}))),s.on(ht.type,ut((function(e,t,n){var r=n.emitStatus;return o(s,void 0,void 0,(function(){return i(this,(function(t){return r(e),[2]}))}))}))),s.on(ft.type,ut((function(e,n,r){var a=r.receiveMessages,u=r.delay,c=r.config;return o(s,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return c.retryConfiguration&&c.retryConfiguration.shouldRetry(e.reason,e.attempts)?(n.throwIfAborted(),[4,u(c.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),n.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,a({abortSignal:n,channels:e.channels,channelGroups:e.groups,timetoken:e.cursor.timetoken,region:e.cursor.region,filterExpression:c.filterExpression})];case 3:return r=i.sent(),[2,t.transition(Pt(r.metadata,r.messages))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Et(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(At(new q(c.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s.on(dt.type,ut((function(e,r,a){var u=a.handshake,c=a.delay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({abortSignal:r,channels:e.channels,channelGroups:e.groups,filterExpression:p.filterExpression},p.maintainPresenceState&&{state:l}))];case 3:return o=i.sent(),[2,t.transition(vt(o))];case 4:return(s=i.sent())instanceof Error&&"Aborted"===s.message?[2]:s instanceof q?[2,t.transition(_t(s))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(St(new q(p.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s}return t(r,e),r}(tt),Mt=new Ze("HANDSHAKE_FAILED");Mt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Mt.on(Nt.type,(function(e,t){return Ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor})})),Mt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(r=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==r?r:0}})})),Mt.on(Ct.type,(function(e){return Lt.with()}));var jt=new Ze("HANDSHAKE_STOPPED");jt.on(yt.type,(function(e,t){return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),jt.on(Nt.type,(function(e,t){return Ft.with(n(n({},e),{cursor:t.payload.cursor||e.cursor}))})),jt.on(gt.type,(function(e,t){var n;return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),jt.on(Ct.type,(function(e){return Lt.with()}));var Rt=new Ze("RECEIVE_FAILED");Rt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Rt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(Ct.type,(function(e){return Lt.with(void 0)}));var xt=new Ze("RECEIVE_STOPPED");xt.on(yt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),xt.on(gt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Ct.type,(function(){return Lt.with(void 0)}));var Ut=new Ze("RECEIVE_RECONNECTING");Ut.onEnter((function(e){return ft(e)})),Ut.onExit((function(){return ft.cancel})),Ut.on(Pt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),Ut.on(Et.type,(function(e,t){return Ut.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Ut.on(At.type,(function(e,t){var n;return Rt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Ut.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),Ut.on(gt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Ut.on(yt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ut.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var It=new Ze("RECEIVING");It.onEnter((function(e){return lt(e.channels,e.groups,e.cursor)})),It.onExit((function(){return lt.cancel})),It.on(wt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),It.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups})})),It.on(gt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),It.on(Ot.type,(function(e,t){return Ut.with(n(n({},e),{attempts:0,reason:t.payload}))})),It.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),It.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var Dt=new Ze("HANDSHAKE_RECONNECTING");Dt.onEnter((function(e){return dt(e)})),Dt.onExit((function(){return dt.cancel})),Dt.on(vt.type,(function(e,t){var n,r,o={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=e.cursor)||void 0===r?void 0:r.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return It.with({channels:e.channels,groups:e.groups,cursor:o},[ht({category:k.PNConnectedCategory})])})),Dt.on(_t.type,(function(e,t){return Dt.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Dt.on(St.type,(function(e,t){var n;return Mt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Dt.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Dt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Dt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.region)||0}})})),Dt.on(Ct.type,(function(e){return Lt.with(void 0)}));var Ft=new Ze("HANDSHAKING");Ft.onEnter((function(e){return ct(e.channels,e.groups)})),Ft.onExit((function(){return ct.cancel})),Ft.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ft.on(mt.type,(function(e,t){var n,r;return It.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.timetoken:t.payload.timetoken,region:t.payload.region}},[ht({category:k.PNConnectedCategory})])})),Ft.on(bt.type,(function(e,t){return Dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload})})),Ft.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Ft.on(gt.type,(function(e,t){var n;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),Ft.on(Ct.type,(function(e){return Lt.with()}));var Lt=new Ze("UNSUBSCRIBED");Lt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups})})),Lt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})}));var Gt=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new kt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(Lt,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e){var t=this,n=e.channels,r=e.channelGroups,o=e.timetoken,i=e.withPresence;this.channels=u(u([],a(this.channels),!1),a(null!=n?n:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=r?r:[]),!1),i&&(this.channels.map((function(e){return t.channels.push("".concat(e,"-pnpres"))})),this.groups.map((function(e){return t.groups.push("".concat(e,"-pnpres"))}))),o?this.engine.transition(gt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))),o)):this.engine.transition(yt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((function(e){return!e.endsWith("-pnpres")})))),groups:Array.from(new Set(this.groups.filter((function(e){return!e.endsWith("-pnpres")}))))})},e.prototype.unsubscribe=function(e){var t=this,n=e.channels,r=void 0===n?[]:n,o=e.channelGroups,i=void 0===o?[]:o,s=H.removeSingleOccurance(this.channels,u(u([],a(r),!1),a(r.map((function(e){return"".concat(e,"-pnpres")}))),!1)),c=H.removeSingleOccurance(this.groups,u(u([],a(i),!1),a(i.map((function(e){return"".concat(e,"-pnpres")}))),!1));if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(c).size){var l=H.findUniqueCommonElements(this.channels,r),p=H.findUniqueCommonElements(this.groups,i);this.dependencies.presenceState&&(null==l||l.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==p||p.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.channels=s,this.groups=c,this.engine.transition(yt(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:l.slice(0),groups:p.slice(0)})}},e.prototype.unsubscribeAll=function(){this.channels=[],this.groups=[],this.dependencies.presenceState&&(this.dependencies.presenceState={}),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.reconnect=function(e){var t=e.timetoken,n=e.region;this.engine.transition(Nt(t,n))},e.prototype.disconnect=function(){this.engine.transition(Tt()),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.getSubscribedChannels=function(){return Array.from(new Set(this.channels))},e.prototype.getSubscribedChannelGroups=function(){return Array.from(new Set(this.groups))},e.prototype.dispose=function(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),Kt=nt("RECONNECT",(function(){return{}})),Bt=nt("DISCONNECT",(function(){return{}})),Ht=nt("JOINED",(function(e,t){return{channels:e,groups:t}})),qt=nt("LEFT",(function(e,t){return{channels:e,groups:t}})),zt=nt("LEFT_ALL",(function(){return{}})),Vt=nt("HEARTBEAT_SUCCESS",(function(e){return{statusCode:e}})),Wt=nt("HEARTBEAT_FAILURE",(function(e){return e})),Jt=nt("HEARTBEAT_GIVEUP",(function(){return{}})),$t=nt("TIMES_UP",(function(){return{}})),Qt=rt("HEARTBEAT",(function(e,t){return{channels:e,groups:t}})),Xt=rt("LEAVE",(function(e,t){return{channels:e,groups:t}})),Yt=rt("EMIT_STATUS",(function(e){return e})),Zt=ot("WAIT",(function(){return{}})),en=ot("DELAYED_HEARTBEAT",(function(e){return e})),tn=function(e){function r(t,r){var s=e.call(this,r)||this;return s.on(Qt.type,ut((function(e,r,a){var u=a.heartbeat,c=a.presenceState,l=a.config;return o(s,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,u(n({channels:e.channels,channelGroups:e.groups},l.maintainPresenceState&&{state:c}))];case 1:return o.sent(),t.transition(Vt(200)),[3,3];case 2:return(r=o.sent())instanceof q?[2,t.transition(Wt(r))]:[3,3];case 3:return[2]}}))}))}))),s.on(Xt.type,ut((function(e,t,n){var r=n.leave,a=n.config;return o(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:if(a.suppressLeaveEvents)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r({channels:e.channels,channelGroups:e.groups})];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}}))}))}))),s.on(Zt.type,ut((function(e,n,r){var a=r.heartbeatDelay;return o(s,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return n.throwIfAborted(),[4,a()];case 1:return e.sent(),n.throwIfAborted(),[2,t.transition($t())]}}))}))}))),s.on(en.type,ut((function(e,r,a){var u=a.heartbeat,c=a.retryDelay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({channels:e.channels,channelGroups:e.groups},p.maintainPresenceState&&{state:l}))];case 3:return i.sent(),[2,t.transition(Vt(200))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Wt(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Jt())];case 7:return[2]}}))}))}))),s.on(Yt.type,ut((function(e,t,r){var a=r.emitStatus,u=r.config;return o(s,void 0,void 0,(function(){var t;return i(this,(function(r){return u.announceFailedHeartbeats&&!0===(null===(t=null==e?void 0:e.status)||void 0===t?void 0:t.error)?a(e.status):u.announceSuccessfulHeartbeats&&200===e.statusCode&&a(n(n({},e),{operation:j.PNHeartbeatOperation,error:!1})),[2]}))}))}))),s}return t(r,e),r}(tt),nn=new Ze("HEARTBEAT_STOPPED");nn.on(Ht.type,(function(e,t){return nn.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),nn.on(qt.type,(function(e,t){return nn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))})})),nn.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),nn.on(zt.type,(function(e,t){return un.with(void 0)}));var rn=new Ze("HEARTBEAT_COOLDOWN");rn.onEnter((function(){return Zt()})),rn.onExit((function(){return Zt.cancel})),rn.on($t.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),rn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),rn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),rn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),rn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var on=new Ze("HEARTBEAT_FAILED");on.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),on.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),on.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),on.on(Bt.type,(function(e,t){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),on.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var sn=new Ze("HEARBEAT_RECONNECTING");sn.onEnter((function(e){return en(e)})),sn.onExit((function(){return en.cancel})),sn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),sn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),sn.on(Bt.type,(function(e,t){nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),sn.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),sn.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),sn.on(Jt.type,(function(e,t){return on.with({channels:e.channels,groups:e.groups})})),sn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var an=new Ze("HEARTBEATING");an.onEnter((function(e){return Qt(e.channels,e.groups)})),an.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),an.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),an.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),an.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:0,reason:t.payload}))})),an.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),an.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var un=new Ze("HEARTBEAT_INACTIVE");un.on(Ht.type,(function(e,t){return an.with({channels:t.payload.channels,groups:t.payload.groups})}));var cn=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dispatcher=new tn(this.engine,e),this.dependencies=e,this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(un,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.join=function(e){var t=e.channels,n=e.groups;this.channels=u(u([],a(this.channels),!1),a(null!=t?t:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=n?n:[]),!1),this.engine.transition(Ht(this.channels.slice(0),this.groups.slice(0)))},e.prototype.leave=function(e){var t=this,n=e.channels,r=e.groups;this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(qt(null!=n?n:[],null!=r?r:[]))},e.prototype.leaveAll=function(){this.engine.transition(zt())},e.prototype.dispose=function(){this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),ln=function(){function e(){}return e.LinearRetryPolicy=function(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e.ExponentialRetryPolicy=function(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e}(),pn=function(){function e(e){var t=e.modules,n=e.listenerManager,r=e.getFileUrl;this.modules=t,this.listenerManager=n,this.getFileUrl=r,this._channelListenerMap=new Map,this._groupListenerMap=new Map,t.cryptoModule&&(this._decoder=new TextDecoder)}return e.prototype.emitEvent=function(e){var t=e.channel,o=e.publishMetaData,i=e.subscriptionMatch;if(t===i&&(i=null),e.channel.endsWith("-pnpres")){var s={channel:null,subscription:null};t&&(s.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(s.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),s.action=e.payload.action,s.state=e.payload.data,s.timetoken=o.timetoken,s.occupancy=e.payload.occupancy,s.uuid=e.payload.uuid,s.timestamp=e.payload.timestamp,e.payload.join&&(s.join=e.payload.join),e.payload.leave&&(s.leave=e.payload.leave),e.payload.timeout&&(s.timeout=e.payload.timeout),s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announcePresence(s),this._announce("presence",s,s.channel,s.subscription)}else if(1===e.messageType){(s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=e.payload,this.listenerManager.announceSignal(s),this._announce("signal",s,s.channel,s.subscription)}else if(2===e.messageType){if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},this.listenerManager.announceObjects(s),this._announce("objects",s,s.channel,s.subscription),"uuid"===e.payload.type){var a=this._renameChannelField(s),u=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"user"})});this.listenerManager.announceUser(u),this._announce("user",u,s.channel,s.subscription)}else if("channel"===e.payload.type){a=this._renameChannelField(s);var c=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"space"})});this.listenerManager.announceSpace(c),this._announce("space",c,s.channel,s.subscription)}else if("membership"===e.payload.type){var l=(a=this._renameChannelField(s)).message.data,p=l.uuid,h=l.channel,f=r(l,["uuid","channel"]);f.user=p,f.space=h;var d=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),data:f})});this.listenerManager.announceMembership(d),this._announce("membership",d,s.channel,s.subscription)}}else if(3===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,s.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},s.event=e.payload.event,this.listenerManager.announceMessageAction(s),this._announce("messageAction",s,s.channel,s.subscription)}else if(4===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId;var y=e.payload;if(this.modules.cryptoModule){var g=void 0;try{g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}null!==g&&(y=g)}e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=y.message,s.file={id:y.file.id,name:y.file.name,url:this.getFileUrl({id:y.file.id,name:y.file.name,channel:t})},this.listenerManager.announceFile(s),this._announce("file",s,s.channel,s.subscription)}else{if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),this.modules.cryptoModule){g=void 0;try{var m;g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}s.message=null!=g?g:e.payload}else s.message=e.payload;s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announceMessage(s),this._announce("message",s,s.channel,s.subscription)}},e.prototype.addListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){r._channelListenerMap[t]?r._channelListenerMap[t].includes(e)||r._channelListenerMap[t].push(e):r._channelListenerMap[t]=[e]})),null==n||n.forEach((function(t){r._groupListenerMap[t]?r._groupListenerMap[t].includes(e)||r._groupListenerMap[t].push(e):r._groupListenerMap[t]=[e]}))):this.listenerManager.addListener(e)},e.prototype.removeListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){var n;r._channelListenerMap[t]=null===(n=r._channelListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))})),null==n||n.forEach((function(t){var n;r._groupListenerMap[t]=null===(n=r._groupListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))}))):this.listenerManager.removeListener(e)},e.prototype.removeAllListeners=function(){this.listenerManager.removeAllListeners()},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e.prototype._announce=function(e,t,n,r){var o,i;null===(o=this._channelListenerMap[n])||void 0===o||o.forEach((function(n){return n[e]&&n[e](t)})),null===(i=this._groupListenerMap[r])||void 0===i||i.forEach((function(n){return n[e]&&n[e](t)}))},e}(),hn=function(){function e(){}return e.prototype.subscribe=function(){var e,t;this.pubnub.subscribe(n({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))},e.prototype.unsubscribe=function(){this.pubnub.unsubscribe({channels:this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),channelGroups:this.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))})},Object.defineProperty(e.prototype,"onMessage",{set:function(e){this.listener.message=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onPresence",{set:function(e){this.listener.presence=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onSignal",{set:function(e){this.listener.signal=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onObjects",{set:function(e){this.listener.objects=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onMessageAction",{set:function(e){this.listener.messageAction=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onFile",{set:function(e){this.listener.file=e},enumerable:!1,configurable:!0}),e.prototype.addListener=function(e){this.eventEmitter.addListener(e,this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),this.groupNames.filter((function(e){return!e.endsWith("-pnpres")})))},e.prototype.removeListener=function(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)},Object.defineProperty(e.prototype,"channels",{get:function(){return this.channelNames.slice(0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"channelGroups",{get:function(){return this.groupNames.slice(0)},enumerable:!1,configurable:!0}),e}(),fn=function(e){function n(t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.subscriptionOptions,c=t.eventEmitter,l=t.pubnub,p=e.call(this)||this;return p.channelNames=[],p.groupNames=[],p.subscriptionList=[],p.options=s,p.eventEmitter=c,p.pubnub=l,r.forEach((function(e){var t=p.pubnub.channel(e).subscription(p.options);p.channelNames=u(u([],a(p.channelNames),!1),a(t.channels),!1),p.subscriptionList.push(t)})),i.forEach((function(e){var t=p.pubnub.channelGroup(e).subscription(p.options);p.groupNames=u(u([],a(p.groupNames),!1),a(t.channelGroups),!1),p.subscriptionList.push(t)})),p.listener={},c.addListener(p.listener,p.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),p.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),p}return t(n,e),n.prototype.addSubscription=function(e){this.subscriptionList.push(e),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscription=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return t!==e}))},n.prototype.addSubscriptionSet=function(e){this.subscriptionList=u(u([],a(this.subscriptionList),!1),a(e.subscriptions),!1),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscriptionSet=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return!e.subscriptions.includes(t)}))},Object.defineProperty(n.prototype,"subscriptions",{get:function(){return this.subscriptionList.slice(0)},enumerable:!1,configurable:!0}),n}(hn),dn=function(e){function r(t){var n=t.channels,r=t.channelGroups,o=t.subscriptionOptions,i=t.eventEmitter,s=t.pubnub,a=e.call(this)||this;return a.channelNames=[],a.groupNames=[],a.channelNames=n,a.groupNames=r,a.options=o,a.pubnub=s,a.eventEmitter=i,a.listener={},i.addListener(a.listener,a.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),a.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),a}return t(r,e),r.prototype.addSubscription=function(e){return new fn({channels:u(u([],a(this.channelNames),!1),a(e.channels),!1),channelGroups:u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),subscriptionOptions:n(n({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})},r}(hn),yn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),gn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),mn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),bn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),vn=function(){function e(e){var t=this,r=e.networking,o=e.cbor,i=new g({setup:e});this._config=i;var c=new T({config:i}),l=e.cryptography;r.init(i);var p=new G(i,o);this._tokenManager=p;var h=new R({maximumSamplesCount:6e4});this._telemetryManager=h;var f=this._config.cryptoModule,d={config:i,networking:r,crypto:c,cryptography:l,tokenManager:p,telemetryManager:h,PubNubFile:e.PubNubFile,cryptoModule:f};this.File=e.PubNubFile,this.encryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.encryptFile(t,this.File)):l.encryptFile(e,t,this.File)},this.decryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.decryptFile(t,this.File)):l.decryptFile(e,t,this.File)};var y=Q.bind(this,d,Je),m=Q.bind(this,d,se),v=Q.bind(this,d,ue),_=Q.bind(this,d,le),S=Q.bind(this,d,$e),w=new L;if(this._listenerManager=w,this.iAmHere=Q.bind(this,d,ue),this.iAmAway=Q.bind(this,d,se),this.setPresenceState=Q.bind(this,d,le),this.handshake=Q.bind(this,d,Qe),this.receiveMessages=Q.bind(this,d,Xe),this._eventEmitter=new pn({modules:d,listenerManager:this._listenerManager,getFileUrl:function(e){return ve(d,e)}}),!0===i.enableEventEngine){if(i.maintainPresenceState&&(this.presenceState={},this.setState=function(e){var n,r;return null===(n=e.channels)||void 0===n||n.forEach((function(n){return t.presenceState[n]=e.state})),null===(r=e.channelGroups)||void 0===r||r.forEach((function(n){return t.presenceState[n]=e.state})),t.setPresenceState({channels:e.channels,channelGroups:e.channelGroups,state:t.presenceState})}),i.getHeartbeatInterval()){var O=new cn({heartbeat:this.iAmHere,leave:this.iAmAway,heartbeatDelay:function(){return new Promise((function(e){return setTimeout(e,1e3*d.config.getHeartbeatInterval())}))},retryDelay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},config:d.config,presenceState:this.presenceState,emitStatus:function(e){w.announceStatus(e)}});this.presenceEventEngine=O,this.join=this.presenceEventEngine.join.bind(O),this.leave=this.presenceEventEngine.leave.bind(O),this.leaveAll=this.presenceEventEngine.leaveAll.bind(O)}var P=new Gt({handshake:this.handshake,receiveMessages:this.receiveMessages,delay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},join:this.join,leave:this.leave,leaveAll:this.leaveAll,presenceState:this.presenceState,config:d.config,emitMessages:function(e){var n,r;try{for(var o=s(e),i=o.next();!i.done;i=o.next()){var a=i.value;t._eventEmitter.emitEvent(a)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},emitStatus:function(e){w.announceStatus(e)}});this.subscribe=P.subscribe.bind(P),this.unsubscribe=P.unsubscribe.bind(P),this.unsubscribeAll=P.unsubscribeAll.bind(P),this.reconnect=P.reconnect.bind(P),this.disconnect=P.disconnect.bind(P),this.destroy=P.dispose.bind(P),this.getSubscribedChannels=P.getSubscribedChannels.bind(P),this.getSubscribedChannelGroups=P.getSubscribedChannelGroups.bind(P),this.eventEngine=P}else{var E=new M({timeEndpoint:y,leaveEndpoint:m,heartbeatEndpoint:v,setStateEndpoint:_,subscribeEndpoint:S,crypto:d.crypto,config:d.config,listenerManager:w,getFileUrl:function(e){return ve(d,e)},cryptoModule:d.cryptoModule,eventEmitter:this._eventEmitter});this.subscribe=E.adaptSubscribeChange.bind(E),this.unsubscribe=E.adaptUnsubscribeChange.bind(E),this.disconnect=E.disconnect.bind(E),this.reconnect=E.reconnect.bind(E),this.unsubscribeAll=E.unsubscribeAll.bind(E),this.getSubscribedChannels=E.getSubscribedChannels.bind(E),this.getSubscribedChannelGroups=E.getSubscribedChannelGroups.bind(E),this.setState=E.adaptStateChange.bind(E),this.presence=E.adaptPresenceChange.bind(E),this.destroy=function(e){E.unsubscribeAll(e),E.disconnect()}}this.addListener=this._eventEmitter.addListener.bind(this._eventEmitter),this.removeListener=this._eventEmitter.removeListener.bind(this._eventEmitter),this.removeAllListeners=this._eventEmitter.removeAllListeners.bind(this._eventEmitter),this.parseToken=p.parseToken.bind(p),this.setToken=p.setToken.bind(p),this.getToken=p.getToken.bind(p),this.channelGroups={listGroups:Q.bind(this,d,ee),listChannels:Q.bind(this,d,te),addChannels:Q.bind(this,d,X),removeChannels:Q.bind(this,d,Y),deleteGroup:Q.bind(this,d,Z)},this.push={addChannels:Q.bind(this,d,ne),removeChannels:Q.bind(this,d,re),deleteDevice:Q.bind(this,d,ie),listChannels:Q.bind(this,d,oe)},this.hereNow=Q.bind(this,d,pe),this.whereNow=Q.bind(this,d,ae),this.getState=Q.bind(this,d,ce),this.grant=Q.bind(this,d,Ue),this.grantToken=Q.bind(this,d,Le),this.audit=Q.bind(this,d,xe),this.revokeToken=Q.bind(this,d,Ge),this.publish=Q.bind(this,d,Be),this.fire=function(e,n){return e.replicate=!1,e.storeInHistory=!1,t.publish(e,n)},this.signal=Q.bind(this,d,He),this.history=Q.bind(this,d,qe),this.deleteMessages=Q.bind(this,d,ze),this.messageCounts=Q.bind(this,d,Ve),this.fetchMessages=Q.bind(this,d,We),this.addMessageAction=Q.bind(this,d,he),this.removeMessageAction=Q.bind(this,d,fe),this.getMessageActions=Q.bind(this,d,de),this.listFiles=Q.bind(this,d,ye);var A=Q.bind(this,d,ge);this.publishFile=Q.bind(this,d,me),this.sendFile=be({generateUploadUrl:A,publishFile:this.publishFile,modules:d}),this.getFileUrl=function(e){return ve(d,e)},this.downloadFile=Q.bind(this,d,_e),this.deleteFile=Q.bind(this,d,Se),this.channel=function(e){return new yn(e,t._eventEmitter,t)},this.channelGroup=function(e){return new gn(e,t._eventEmitter,t)},this.channelMetadata=function(e){return new mn(e,t._eventEmitter,t)},this.userMetadata=function(e){return new bn(e,t._eventEmitter,t)},this.subscriptionSet=function(e){return new fn({channels:e.channels,channelGroups:e.channelGroups,subscriptionOptions:e.subscriptionOptions,eventEmitter:t._eventEmitter,pubnub:t})},this.objects={getAllUUIDMetadata:Q.bind(this,d,we),getUUIDMetadata:Q.bind(this,d,Oe),setUUIDMetadata:Q.bind(this,d,Pe),removeUUIDMetadata:Q.bind(this,d,Ee),getAllChannelMetadata:Q.bind(this,d,Ae),getChannelMetadata:Q.bind(this,d,Te),setChannelMetadata:Q.bind(this,d,Ne),removeChannelMetadata:Q.bind(this,d,Ce),getChannelMembers:Q.bind(this,d,ke),setChannelMembers:function(e){for(var r=[],o=1;o=this._config.origin.length&&(this._currentSubDomain=0);var t=this._config.origin[this._currentSubDomain];return"".concat(e).concat(t)},e.prototype.hasModule=function(e){return e in this._modules},e.prototype.shiftStandardOrigin=function(){return this._standardOrigin=this.nextOrigin(),this._standardOrigin},e.prototype.getStandardOrigin=function(){return this._standardOrigin},e.prototype.POSTFILE=function(e,t,n){return this._modules.postfile(e,t,n)},e.prototype.GETFILE=function(e,t,n){return this._modules.getfile(e,t,n)},e.prototype.POST=function(e,t,n,r){return this._modules.post(e,t,n,r)},e.prototype.PATCH=function(e,t,n,r){return this._modules.patch(e,t,n,r)},e.prototype.GET=function(e,t,n){return this._modules.get(e,t,n)},e.prototype.DELETE=function(e,t,n){return this._modules.del(e,t,n)},e.prototype._detectErrorCategory=function(e){if("ENOTFOUND"===e.code)return k.PNNetworkIssuesCategory;if("ECONNREFUSED"===e.code)return k.PNNetworkIssuesCategory;if("ECONNRESET"===e.code)return k.PNNetworkIssuesCategory;if("EAI_AGAIN"===e.code)return k.PNNetworkIssuesCategory;if(0===e.status||e.hasOwnProperty("status")&&void 0===e.status)return k.PNNetworkIssuesCategory;if(e.timeout)return k.PNTimeoutCategory;if("ETIMEDOUT"===e.code)return k.PNNetworkIssuesCategory;if(e.response){if(e.response.badRequest)return k.PNBadRequestCategory;if(e.response.forbidden)return k.PNAccessDeniedCategory}return k.PNUnknownCategory},e}();function Sn(e){var t=function(e){return e&&"object"==typeof e&&e.constructor===Object};if(!t(e))return e;var n={};return Object.keys(e).forEach((function(r){var o=function(e){return"string"==typeof e||e instanceof String}(r),i=r,s=e[r];Array.isArray(r)||o&&r.indexOf(",")>=0?i=(o?r.split(","):r).reduce((function(e,t){return e+=String.fromCharCode(t)}),""):(function(e){return"number"==typeof e&&isFinite(e)}(r)||o&&!isNaN(r))&&(i=String.fromCharCode(o?parseInt(r,10):10));n[i]=t(s)?Sn(s):s})),n}var wn=function(){function e(e,t){this._base64ToBinary=t,this._decode=e}return e.prototype.decodeToken=function(e){var t="";e.length%4==3?t="=":e.length%4==2&&(t="==");var n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,r=this._decode(this._base64ToBinary(n));if("object"==typeof r)return r},e}(),On={exports:{}},Pn={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;os.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;at?1:0}function Un(e,t,n,r){void 0===r&&(r=kn());var o,i=In(e,"",0,[],void 0,0,r)||e;try{o=0===Cn.length?JSON.stringify(i,t,n):JSON.stringify(i,Dn(t),n)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==Nn.length;){var s=Nn.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return o}function In(e,t,n,r,o,i,s){var a;if(i+=1,"object"==typeof e&&null!==e){for(a=0;as.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;a0)for(var r=0;r1&&"boolean"!=typeof t)throw new Qn('"allowMissing" argument must be a boolean');var n=gr(e),r=n.length>0?n[0]:"",o=mr("%"+r+"%",t),i=o.name,s=o.value,a=!1,u=o.alias;u&&(r=u[0],pr(n,lr([0,1],u)));for(var c=1,l=!0;c=n.length){var d=Yn(s,p);s=(l=!!d)&&"get"in d&&!("originalValue"in d.get)?d.get:s[p]}else l=cr(s,p),s=s[p];l&&!a&&(ir[i]=s)}}return s},vr={exports:{}};!function(e){var t=Vn,n=br,r=n("%Function.prototype.apply%"),o=n("%Function.prototype.call%"),i=n("%Reflect.apply%",!0)||t.call(o,r),s=n("%Object.getOwnPropertyDescriptor%",!0),a=n("%Object.defineProperty%",!0),u=n("%Math.max%");if(a)try{a({},"a",{value:1})}catch(e){a=null}e.exports=function(e){var n=i(t,o,arguments);if(s&&a){var r=s(n,"length");r.configurable&&a(n,"length",{value:1+u(0,e.length-(arguments.length-1))})}return n};var c=function(){return i(t,r,arguments)};a?a(e.exports,"apply",{value:c}):e.exports.apply=c}(vr);var _r=br,Sr=vr.exports,wr=Sr(_r("String.prototype.indexOf")),Or=l(Object.freeze({__proto__:null,default:{}})),Pr="function"==typeof Map&&Map.prototype,Er=Object.getOwnPropertyDescriptor&&Pr?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ar=Pr&&Er&&"function"==typeof Er.get?Er.get:null,Tr=Pr&&Map.prototype.forEach,Nr="function"==typeof Set&&Set.prototype,Cr=Object.getOwnPropertyDescriptor&&Nr?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,kr=Nr&&Cr&&"function"==typeof Cr.get?Cr.get:null,Mr=Nr&&Set.prototype.forEach,jr="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Rr="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,xr="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Ur=Boolean.prototype.valueOf,Ir=Object.prototype.toString,Dr=Function.prototype.toString,Fr=String.prototype.match,Lr=String.prototype.slice,Gr=String.prototype.replace,Kr=String.prototype.toUpperCase,Br=String.prototype.toLowerCase,Hr=RegExp.prototype.test,qr=Array.prototype.concat,zr=Array.prototype.join,Vr=Array.prototype.slice,Wr=Math.floor,Jr="function"==typeof BigInt?BigInt.prototype.valueOf:null,$r=Object.getOwnPropertySymbols,Qr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,Xr="function"==typeof Symbol&&"object"==typeof Symbol.iterator,Yr="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xr||"symbol")?Symbol.toStringTag:null,Zr=Object.prototype.propertyIsEnumerable,eo=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function to(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||Hr.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var r=e<0?-Wr(-e):Wr(e);if(r!==e){var o=String(r),i=Lr.call(t,o.length+1);return Gr.call(o,n,"$&_")+"."+Gr.call(Gr.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Gr.call(t,n,"$&_")}var no=Or,ro=no.custom,oo=co(ro)?ro:null;function io(e,t,n){var r="double"===(n.quoteStyle||t)?'"':"'";return r+e+r}function so(e){return Gr.call(String(e),/"/g,""")}function ao(e){return!("[object Array]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function uo(e){return!("[object RegExp]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function co(e){if(Xr)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!Qr)return!1;try{return Qr.call(e),!0}catch(e){}return!1}var lo=Object.prototype.hasOwnProperty||function(e){return e in this};function po(e,t){return lo.call(e,t)}function ho(e){return Ir.call(e)}function fo(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;nt.maxStringLength){var n=e.length-t.maxStringLength,r="... "+n+" more character"+(n>1?"s":"");return yo(Lr.call(e,0,t.maxStringLength),t)+r}return io(Gr.call(Gr.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,go),"single",t)}function go(e){var t=e.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return n?"\\"+n:"\\x"+(t<16?"0":"")+Kr.call(t.toString(16))}function mo(e){return"Object("+e+")"}function bo(e){return e+" { ? }"}function vo(e,t,n,r){return e+" ("+t+") {"+(r?_o(n,r):zr.call(n,", "))+"}"}function _o(e,t){if(0===e.length)return"";var n="\n"+t.prev+t.base;return n+zr.call(e,","+n)+"\n"+t.prev}function So(e,t){var n=ao(e),r=[];if(n){r.length=e.length;for(var o=0;o-1?Sr(n):n},Po=function e(t,n,r,o){var i=n||{};if(po(i,"quoteStyle")&&"single"!==i.quoteStyle&&"double"!==i.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(po(i,"maxStringLength")&&("number"==typeof i.maxStringLength?i.maxStringLength<0&&i.maxStringLength!==1/0:null!==i.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var s=!po(i,"customInspect")||i.customInspect;if("boolean"!=typeof s&&"symbol"!==s)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(po(i,"indent")&&null!==i.indent&&"\t"!==i.indent&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(po(i,"numericSeparator")&&"boolean"!=typeof i.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=i.numericSeparator;if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return yo(t,i);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var u=String(t);return a?to(t,u):u}if("bigint"==typeof t){var l=String(t)+"n";return a?to(t,l):l}var p=void 0===i.depth?5:i.depth;if(void 0===r&&(r=0),r>=p&&p>0&&"object"==typeof t)return ao(t)?"[Array]":"[Object]";var h=function(e,t){var n;if("\t"===e.indent)n="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;n=zr.call(Array(e.indent+1)," ")}return{base:n,prev:zr.call(Array(t+1),n)}}(i,r);if(void 0===o)o=[];else if(fo(o,t)>=0)return"[Circular]";function f(t,n,s){if(n&&(o=Vr.call(o)).push(n),s){var a={depth:i.depth};return po(i,"quoteStyle")&&(a.quoteStyle=i.quoteStyle),e(t,a,r+1,o)}return e(t,i,r+1,o)}if("function"==typeof t&&!uo(t)){var d=function(e){if(e.name)return e.name;var t=Fr.call(Dr.call(e),/^function\s*([\w$]+)/);if(t)return t[1];return null}(t),y=So(t,f);return"[Function"+(d?": "+d:" (anonymous)")+"]"+(y.length>0?" { "+zr.call(y,", ")+" }":"")}if(co(t)){var g=Xr?Gr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qr.call(t);return"object"!=typeof t||Xr?g:mo(g)}if(function(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return!0;return"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}(t)){for(var m="<"+Br.call(String(t.nodeName)),b=t.attributes||[],v=0;v"}if(ao(t)){if(0===t.length)return"[]";var _=So(t,f);return h&&!function(e){for(var t=0;t=0)return!1;return!0}(_)?"["+_o(_,h)+"]":"[ "+zr.call(_,", ")+" ]"}if(function(e){return!("[object Error]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)){var S=So(t,f);return"cause"in Error.prototype||!("cause"in t)||Zr.call(t,"cause")?0===S.length?"["+String(t)+"]":"{ ["+String(t)+"] "+zr.call(S,", ")+" }":"{ ["+String(t)+"] "+zr.call(qr.call("[cause]: "+f(t.cause),S),", ")+" }"}if("object"==typeof t&&s){if(oo&&"function"==typeof t[oo]&&no)return no(t,{depth:p-r});if("symbol"!==s&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!Ar||!e||"object"!=typeof e)return!1;try{Ar.call(e);try{kr.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}(t)){var w=[];return Tr&&Tr.call(t,(function(e,n){w.push(f(n,t,!0)+" => "+f(e,t))})),vo("Map",Ar.call(t),w,h)}if(function(e){if(!kr||!e||"object"!=typeof e)return!1;try{kr.call(e);try{Ar.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}(t)){var O=[];return Mr&&Mr.call(t,(function(e){O.push(f(e,t))})),vo("Set",kr.call(t),O,h)}if(function(e){if(!jr||!e||"object"!=typeof e)return!1;try{jr.call(e,jr);try{Rr.call(e,Rr)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}(t))return bo("WeakMap");if(function(e){if(!Rr||!e||"object"!=typeof e)return!1;try{Rr.call(e,Rr);try{jr.call(e,jr)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}(t))return bo("WeakSet");if(function(e){if(!xr||!e||"object"!=typeof e)return!1;try{return xr.call(e),!0}catch(e){}return!1}(t))return bo("WeakRef");if(function(e){return!("[object Number]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(Number(t)));if(function(e){if(!e||"object"!=typeof e||!Jr)return!1;try{return Jr.call(e),!0}catch(e){}return!1}(t))return mo(f(Jr.call(t)));if(function(e){return!("[object Boolean]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(Ur.call(t));if(function(e){return!("[object String]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(String(t)));if("undefined"!=typeof window&&t===window)return"{ [object Window] }";if(t===c)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)&&!uo(t)){var P=So(t,f),E=eo?eo(t)===Object.prototype:t instanceof Object||t.constructor===Object,A=t instanceof Object?"":"null prototype",T=!E&&Yr&&Object(t)===t&&Yr in t?Lr.call(ho(t),8,-1):A?"Object":"",N=(E||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(T||A?"["+zr.call(qr.call([],T||[],A||[]),": ")+"] ":"");return 0===P.length?N+"{}":h?N+"{"+_o(P,h)+"}":N+"{ "+zr.call(P,", ")+" }"}return String(t)},Eo=wo("%TypeError%"),Ao=wo("%WeakMap%",!0),To=wo("%Map%",!0),No=Oo("WeakMap.prototype.get",!0),Co=Oo("WeakMap.prototype.set",!0),ko=Oo("WeakMap.prototype.has",!0),Mo=Oo("Map.prototype.get",!0),jo=Oo("Map.prototype.set",!0),Ro=Oo("Map.prototype.has",!0),xo=function(e,t){for(var n,r=e;null!==(n=r.next);r=n)if(n.key===t)return r.next=n.next,n.next=e.next,e.next=n,n},Uo=String.prototype.replace,Io=/%20/g,Do="RFC3986",Fo={default:Do,formatters:{RFC1738:function(e){return Uo.call(e,Io,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:Do},Lo=Fo,Go=Object.prototype.hasOwnProperty,Ko=Array.isArray,Bo=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),Ho=function(e,t){for(var n=t&&t.plainObjects?Object.create(null):{},r=0;r1;){var t=e.pop(),n=t.obj[t.prop];if(Ko(n)){for(var r=[],o=0;o=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===Lo.RFC1738&&(40===u||41===u)?s+=i.charAt(a):u<128?s+=Bo[u]:u<2048?s+=Bo[192|u>>6]+Bo[128|63&u]:u<55296||u>=57344?s+=Bo[224|u>>12]+Bo[128|u>>6&63]+Bo[128|63&u]:(a+=1,u=65536+((1023&u)<<10|1023&i.charCodeAt(a)),s+=Bo[240|u>>18]+Bo[128|u>>12&63]+Bo[128|u>>6&63]+Bo[128|63&u])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(Ko(e)){for(var n=[],r=0;r0?b.join(",")||null:void 0}];else if(Qo(u))O=u;else{var E=Object.keys(b);O=c?E.sort(c):E}for(var A=o&&Qo(b)&&1===b.length?n+"[]":n,T=0;T-1?e.split(","):e},li=function(e,t,n,r){if(e){var o=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,s=n.depth>0&&/(\[[^[\]]*])/.exec(o),a=s?o.slice(0,s.index):o,u=[];if(a){if(!n.plainObjects&&ii.call(Object.prototype,a)&&!n.allowPrototypes)return;u.push(a)}for(var c=0;n.depth>0&&null!==(s=i.exec(o))&&c=0;--i){var s,a=e[i];if("[]"===a&&n.parseArrays)s=[].concat(o);else{s=n.plainObjects?Object.create(null):{};var u="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(u,10);n.parseArrays||""!==u?!isNaN(c)&&a!==u&&String(c)===u&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(s=[])[c]=o:"__proto__"!==u&&(s[u]=o):s={0:o}}o=s}return o}(u,t,n,r)}},pi=function(e,t){var n,r=e,o=function(e){if(!e)return ti;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||ti.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Wo.default;if(void 0!==e.format){if(!Jo.call(Wo.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var r=Wo.formatters[n],o=ti.filter;return("function"==typeof e.filter||Qo(e.filter))&&(o=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:ti.addQueryPrefix,allowDots:void 0===e.allowDots?ti.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ti.charsetSentinel,delimiter:void 0===e.delimiter?ti.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:ti.encode,encoder:"function"==typeof e.encoder?e.encoder:ti.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:ti.encodeValuesOnly,filter:o,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:ti.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:ti.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ti.strictNullHandling}}(t);"function"==typeof o.filter?r=(0,o.filter)("",r):Qo(o.filter)&&(n=o.filter);var i,s=[];if("object"!=typeof r||null===r)return"";i=t&&t.arrayFormat in $o?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=$o[i];if(t&&"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var u="comma"===a&&t&&t.commaRoundTrip;n||(n=Object.keys(r)),o.sort&&n.sort(o.sort);for(var c=zo(),l=0;l0?f+h:""},hi={formats:Fo,parse:function(e,t){var n=function(e){if(!e)return ai;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?ai.charset:e.charset;return{allowDots:void 0===e.allowDots?ai.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:ai.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:ai.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:ai.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ai.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:ai.comma,decoder:"function"==typeof e.decoder?e.decoder:ai.decoder,delimiter:"string"==typeof e.delimiter||oi.isRegExp(e.delimiter)?e.delimiter:ai.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:ai.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:ai.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:ai.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:ai.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ai.strictNullHandling}}(t);if(""===e||null==e)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof e?function(e,t){var n,r={__proto__:null},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,i),a=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(l=si(l)?[l]:l),ii.call(r,c)?r[c]=oi.combine(r[c],l):r[c]=l}return r}(e,n):e,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),s=0;s=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.split(/ *; */).shift(),e.params=e=>{const n={};var r,o=t(e.split(/ *; */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *= */),t=e.shift(),o=e.shift();t&&o&&(n[t]=o)}}catch(e){o.e(e)}finally{o.f()}return n},e.parseLinks=e=>{const n={};var r,o=t(e.split(/ *, */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *; */),t=e[0].slice(1,-1);n[e[1].split(/ *= */)[1].slice(1,-1)]=t}}catch(e){o.e(e)}finally{o.f()}return n},e.cleanHeader=(e,t)=>(delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e),e.isObject=e=>null!==e&&"object"==typeof e,e.hasOwn=Object.hasOwn||function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(new Object(e),t)},e.mixin=(t,n)=>{for(const r in n)e.hasOwn(n,r)&&(t[r]=n[r])}}(fi);const di=Or,yi=fi.isObject,gi=fi.hasOwn;var mi=bi;function bi(){}bi.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},bi.prototype.parse=function(e){return this._parser=e,this},bi.prototype.responseType=function(e){return this._responseType=e,this},bi.prototype.serialize=function(e){return this._serializer=e,this},bi.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(const t in e)if(gi(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},bi.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};const vi=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),_i=new Set([408,413,429,500,502,503,504,521,522,524]);bi.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{const n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&_i.has(t.status))return!0;if(e){if(e.code&&vi.has(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},bi.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},bi.prototype.then=function(e,t){if(!this._fullfilledPromise){const e=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(((t,n)=>{e.on("abort",(()=>{if(this._maxRetries&&this._maxRetries>this._retries)return;if(this.timedout&&this.timedoutError)return void n(this.timedoutError);const e=new Error("Aborted");e.code="ABORTED",e.status=this.status,e.method=this.method,e.url=this.url,n(e)})),e.end(((e,r)=>{e?n(e):t(r)}))}))}return this._fullfilledPromise.then(e,t)},bi.prototype.catch=function(e){return this.then(void 0,e)},bi.prototype.use=function(e){return e(this),this},bi.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},bi.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},bi.prototype.get=function(e){return this._header[e.toLowerCase()]},bi.prototype.getHeader=bi.prototype.get,bi.prototype.set=function(e,t){if(yi(e)){for(const t in e)gi(e,t)&&this.set(t,e[t]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},bi.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},bi.prototype.field=function(e,t,n){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(yi(e)){for(const t in e)gi(e,t)&&this.field(t,e[t]);return this}if(Array.isArray(t)){for(const n in t)gi(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),n?this._getFormData().append(e,t,n):this._getFormData().append(e,t),this},bi.prototype.abort=function(){if(this._aborted)return this;if(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req){if(di.gte(process.version,"v13.0.0")&&di.lt(process.version,"v14.0.0"))throw new Error("Superagent does not work in v13 properly with abort() due to Node.js core changes");this.req.abort()}return this.clearTimeout(),this.emit("abort"),this},bi.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization",`Basic ${r(`${e}:${t}`)}`);break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization",`Bearer ${e}`)}return this},bi.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},bi.prototype.redirects=function(e){return this._maxRedirects=e,this},bi.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},bi.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},bi.prototype.send=function(e){const t=yi(e);let n=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&yi(this._data))for(const t in e){if("bigint"==typeof e[t]&&!e[t].toJSON)throw new Error("Cannot serialize BigInt value to json");gi(e,t)&&(this._data[t]=e[t])}else{if("bigint"==typeof e)throw new Error("Cannot send value of type BigInt");"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],n&&(n=n.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===n?this._data?`${this._data}&${e}`:e:(this._data||"")+e):this._data=e}return!t||this._isHost(e)||n||this.type("json"),this},bi.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},bi.prototype._finalizeQueryString=function(){const e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){const e=this.url.indexOf("?");if(e>=0){const t=this.url.slice(e+1).split("&");"function"==typeof this._sort?t.sort(this._sort):t.sort(),this.url=this.url.slice(0,e)+"?"+t.join("&")}}},bi.prototype._appendQueryString=()=>{console.warn("Unsupported")},bi.prototype._timeoutError=function(e,t,n){if(this._aborted)return;const r=new Error(`${e+t}ms exceeded`);r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.timedoutError=r,this.abort(),this.callback(r)},bi.prototype._setTimeouts=function(){const e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((()=>{e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((()=>{e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};const Si=fi;var wi=Oi;function Oi(){}function Pi(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Ei(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ei(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw i}}}}function Ei(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n{if(o.XMLHttpRequest)return new o.XMLHttpRequest;throw new Error("Browser-only version of superagent could not find XHR")};const g="".trim?e=>e.trim():e=>e.replace(/(^\s*|\s*$)/g,"");function m(e){if(!c(e))return e;const t=[];for(const n in e)p(e,n)&&b(t,n,e[n]);return t.join("&")}function b(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r)){var o,i=n(r);try{for(i.s();!(o=i.n()).done;){b(e,t,o.value)}}catch(e){i.e(e)}finally{i.f()}}else if(c(r))for(const n in r)p(r,n)&&b(e,`${t}[${n}]`,r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function v(e){const t={},n=e.split("&");let r,o;for(let e=0,i=n.length;e{let e,t=null,r=null;try{r=new S(n)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||r.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=e.status||r.status,n.callback(e,r)):n.callback(null,r)}))}y.serializeObject=m,y.parseString=v,y.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":a.stringify,"application/json":s},y.parse={"application/x-www-form-urlencoded":v,"application/json":JSON.parse},l(S.prototype,h.prototype),S.prototype._parseBody=function(e){let t=y.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&_(this.type)&&(t=y.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},S.prototype.toError=function(){const e=this.req,t=e.method,n=e.url,r=`cannot ${t} ${n} (${this.status})`,o=new Error(r);return o.status=this.status,o.method=t,o.url=n,o},y.Response=S,i(w.prototype),l(w.prototype,u.prototype),w.prototype.type=function(e){return this.set("Content-Type",y.types[e]||e),this},w.prototype.accept=function(e){return this.set("Accept",y.types[e]||e),this},w.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});const r=n.encoder?n.encoder:e=>{if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},w.prototype.query=function(e){return"string"!=typeof e&&(e=m(e)),e&&this._query.push(e),this},w.prototype.attach=function(e,t,n){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},w.prototype._getFormData=function(){return this._formData||(this._formData=new o.FormData),this._formData},w.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();const n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},w.prototype.crossDomainError=function(){const e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},w.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},w.prototype.ca=w.prototype.agent,w.prototype.buffer=w.prototype.ca,w.prototype.write=()=>{throw new Error("Streaming is not supported in browser version of superagent")},w.prototype.pipe=w.prototype.write,w.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},w.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||d,this._finalizeQueryString(),this._end()},w.prototype._setUploadTimeout=function(){const e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((()=>{e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},w.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));const e=this;this.xhr=y.getXHR();const t=this.xhr;let n=this._formData||this._data;this._setTimeouts(),t.addEventListener("readystatechange",(()=>{const n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4!==n)return;let r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}));const r=(t,n)=>{n.total>0&&(n.percent=n.loaded/n.total*100,100===n.percent&&clearTimeout(e._uploadTimeoutTimer)),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.addEventListener("progress",r.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",r.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof n&&!this._isHost(n)){const e=this._header["content-type"];let t=this._serializer||y.serialize[e?e.split(";")[0]:""];!t&&_(e)&&(t=y.serialize["application/json"]),t&&(n=t(n))}for(const e in this.header)null!==this.header[e]&&p(this.header,e)&&t.setRequestHeader(e,this.header[e]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===n?null:n)},y.agent=()=>new f;for(var O=0,P=["GET","POST","OPTIONS","PATCH","PUT","DELETE"];O{const r=y("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.head=(e,t,n)=>{const r=y("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.options=(e,t,n)=>{const r=y("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.del=E,y.delete=E,y.patch=(e,t,n)=>{const r=y("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.post=(e,t,n)=>{const r=y("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.put=(e,t,n)=>{const r=y("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}}(On,On.exports);var ki=On.exports;function Mi(e){var t=(new Date).getTime(),n=(new Date).toISOString(),r=console&&console.log?console:window&&window.console&&window.console.log?window.console:console;r.log("<<<<<"),r.log("[".concat(n,"]"),"\n",e.url,"\n",e.qs),r.log("-----"),e.on("response",(function(n){var o=(new Date).getTime()-t,i=(new Date).toISOString();r.log(">>>>>>"),r.log("[".concat(i," / ").concat(o,"]"),"\n",e.url,"\n",e.qs,"\n",n.text),r.log("-----")}))}function ji(e,t,n){var r=this;this._config.logVerbosity&&(e=e.use(Mi)),this._config.proxy&&this._modules.proxy&&(e=this._modules.proxy.call(this,e)),this._config.keepAlive&&this._modules.keepAlive&&(e=this._modules.keepAlive(e));var o=e;if(t.abortSignal)var i=t.abortSignal.subscribe((function(){o.abort(),i()}));return!0===t.forceBuffered?o="undefined"==typeof Blob?o.buffer().responseType("arraybuffer"):o.responseType("arraybuffer"):!1===t.forceBuffered&&(o=o.buffer(!1)),(o=o.timeout(t.timeout)).on("abort",(function(){return n({category:k.PNUnknownCategory,error:!0,operation:t.operation,errorData:new Error("Aborted")},null)})),o.end((function(e,o){var i,s={};if(s.error=null!==e,s.operation=t.operation,o&&o.status&&(s.statusCode=o.status),e){if(e.response&&e.response.text&&!r._config.logVerbosity)try{s.errorData=JSON.parse(e.response.text)}catch(t){s.errorData=e}else s.errorData=e;return s.category=r._detectErrorCategory(e),n(s,null)}if(t.ignoreBody)i={headers:o.headers,redirects:o.redirects,response:o};else try{i=JSON.parse(o.text)}catch(e){return s.errorData=o,s.error=!0,n(s,null)}return i.error&&1===i.error&&i.status&&i.message&&i.service?(s.errorData=i,s.statusCode=i.status,s.error=!0,s.category=r._detectErrorCategory(s),n(s,null)):(i.error&&i.error.message&&(s.errorData=i.error),n(s,i))})),o}function Ri(e,t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return r=ki.post(e),t.forEach((function(e){var t=e.key,n=e.value;r=r.field(t,n)})),r.attach("file",n,{contentType:"application/octet-stream"}),[4,r];case 1:return[2,o.sent()]}}))}))}function xi(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ui(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ii(e,t,n,r){var o=ki.post(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Di(e,t,n,r){var o=ki.patch(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Fi(e,t,n){var r=ki.delete(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Li(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}var Gi,Ki=function(){function e(){}return Object.defineProperty(e.prototype,"algo",{get:function(){return"aes-256-cbc"},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.encryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.encryptString(n,t)];throw new Error("Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer")}}))}))},e.prototype.decrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.decryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.decryptString(n,t)];throw new Error("Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer")}}))}))},e.prototype.encryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:if(t.data.byteLength<=0)throw new Error("encryption error. empty content");return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.encryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,mimeType:"application/octet-stream",data:s})]}}))}))},e.prototype.decryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.decryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,data:s})]}}))}))},e.prototype.getKey=function(t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return[4,crypto.subtle.digest("SHA-256",e.encoder.encode(t))];case 1:return n=i.sent(),r=Array.from(new Uint8Array(n)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),o=e.encoder.encode(r.slice(0,32)).buffer,[2,crypto.subtle.importKey("raw",o,"AES-CBC",!0,["encrypt","decrypt"])]}}))}))},e.prototype.encryptArrayBuffer=function(e,t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),r=Li,o=[n.buffer],[4,crypto.subtle.encrypt({name:"AES-CBC",iv:n},e,t)];case 1:return[2,r.apply(void 0,o.concat([i.sent()]))]}}))}))},e.prototype.decryptArrayBuffer=function(t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:if(r=n.slice(0,16),n.slice(e.IV_LENGTH).byteLength<=0)throw new Error("decryption error: empty content");return[4,crypto.subtle.decrypt({name:"AES-CBC",iv:r},t,n.slice(e.IV_LENGTH))];case 1:return[2,o.sent()]}}))}))},e.prototype.encryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=crypto.getRandomValues(new Uint8Array(16)),o=e.encoder.encode(n).buffer,[4,crypto.subtle.encrypt({name:"AES-CBC",iv:r},t,o)];case 1:return s=i.sent(),a=Li(r.buffer,s),[2,e.decoder.decode(a)]}}))}))},e.prototype.decryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=e.encoder.encode(n).buffer,o=r.slice(0,16),s=r.slice(16),[4,crypto.subtle.decrypt({name:"AES-CBC",iv:o},t,s)];case 1:return a=i.sent(),[2,e.decoder.decode(a)]}}))}))},e.IV_LENGTH=16,e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Bi=(Gi=function(){function e(e){if(e instanceof File)this.data=e,this.name=this.data.name,this.mimeType=this.data.type;else if(e.data){var t=e.data;this.data=new File([t],e.name,{type:e.mimeType}),this.name=e.name,e.mimeType&&(this.mimeType=e.mimeType)}if(void 0===this.data)throw new Error("Couldn't construct a file out of supplied options.");if(void 0===this.name)throw new Error("Couldn't guess filename out of the options. Please provide one.")}return e.create=function(e){return new this(e)},e.prototype.toBuffer=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toStream=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toFileUri=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in react native environments.")}))}))},e.prototype.toBlob=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e.prototype.toArrayBuffer=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if(r.result instanceof ArrayBuffer)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsArrayBuffer(e.data)}))]}))}))},e.prototype.toString=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if("string"==typeof r.result)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsBinaryString(e.data)}))]}))}))},e.prototype.toFile=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e}(),Gi.supportsFile="undefined"!=typeof File,Gi.supportsBlob="undefined"!=typeof Blob,Gi.supportsArrayBuffer="undefined"!=typeof ArrayBuffer,Gi.supportsBuffer=!1,Gi.supportsStream=!1,Gi.supportsString=!0,Gi.supportsEncryptFile=!0,Gi.supportsFileUri=!1,Gi),Hi=function(){function e(e){this.config=e,this.cryptor=new T({config:e}),this.fileCryptor=new Ki}return Object.defineProperty(e.prototype,"identifier",{get:function(){return""},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e){var t="string"==typeof e?e:(new TextDecoder).decode(e);return{data:this.cryptor.encrypt(t),metadata:null}},e.prototype.decrypt=function(e){var t="string"==typeof e.data?e.data:b(e.data);return this.cryptor.decrypt(t)},e.prototype.encryptFile=function(e,t){var n;return o(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)]}))}))},e.prototype.decryptFile=function(e,t){return o(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.fileCryptor.decryptFile(this.config.cipherKey,e,t)]}))}))},e}(),qi=function(){function e(e){this.cipherKey=e.cipherKey,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(this.cipherKey)}return Object.defineProperty(e.prototype,"algo",{get:function(){return"AES-CBC"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return"ACRH"},enumerable:!1,configurable:!0}),e.prototype.getIv=function(){return crypto.getRandomValues(new Uint8Array(e.BLOCK_SIZE))},e.prototype.getKey=function(){return o(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return t=e.encoder.encode(this.cipherKey),[4,crypto.subtle.digest("SHA-256",t.buffer)];case 1:return n=r.sent(),[2,crypto.subtle.importKey("raw",n,this.algo,!0,["encrypt","decrypt"])]}}))}))},e.prototype.encrypt=function(t){if(0===("string"==typeof t?t:e.decoder.decode(t)).length)throw new Error("encryption error. empty content");var n=this.getIv();return{metadata:n,data:m(this.CryptoJS.AES.encrypt(t,this.encryptedKey,{iv:this.bufferToWordArray(n),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}},e.prototype.decrypt=function(t){var n=this.bufferToWordArray(new Uint8ClampedArray(t.metadata)),r=this.bufferToWordArray(new Uint8ClampedArray(t.data));return e.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:r},this.encryptedKey,{iv:n,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer},e.prototype.encryptFileData=function(e){return o(this,void 0,void 0,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:return[4,this.getKey()];case 1:return t=o.sent(),n=this.getIv(),r={},[4,crypto.subtle.encrypt({name:this.algo,iv:n},t,e)];case 2:return[2,(r.data=o.sent(),r.metadata=n,r)]}}))}))},e.prototype.decryptFileData=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.getKey()];case 1:return t=n.sent(),[2,crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)]}}))}))},e.prototype.bufferToWordArray=function(e){var t,n=[];for(t=0;t0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("decryption error. empty content");return r.decrypt({data:t.slice(n.length),metadata:o})},e.prototype.encryptFile=function(e,t){return o(this,void 0,void 0,(function(){var n,r;return i(this,(function(o){switch(o.label){case 0:return this.defaultCryptor.identifier===Vi.LEGACY_IDENTIFIER?[2,this.defaultCryptor.encryptFile(e,t)]:[4,this.getFileData(e.data)];case 1:return n=o.sent(),[4,this.defaultCryptor.encryptFileData(n)];case 2:return r=o.sent(),[2,t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(r),r.data)})]}}))}))},e.prototype.decryptFile=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a,u,c,l,p;return i(this,(function(i){switch(i.label){case 0:return[4,t.data.arrayBuffer()];case 1:return r=i.sent(),o=Vi.tryParse(r),(null==(s=this.getCryptor(o))?void 0:s.identifier)===e.LEGACY_IDENTIFIER?[2,s.decryptFile(t,n)]:[4,this.getFileData(r)];case 2:return a=i.sent(),u=a.slice(o.length-o.metadataLength,o.length),l=(c=n).create,p={name:t.name},[4,this.defaultCryptor.decryptFileData({data:r.slice(o.length),metadata:u})];case 3:return[2,l.apply(c,[(p.data=i.sent(),p)])]}}))}))},e.prototype.getCryptor=function(e){if(""===e){var t=this.getAllCryptors().find((function(e){return""===e.identifier}));if(t)return t;throw new Error("unknown cryptor error")}if(e instanceof Wi)return this.getCryptorFromId(e.identifier)},e.prototype.getCryptorFromId=function(e){var t=this.getAllCryptors().find((function(t){return e===t.identifier}));if(t)return t;throw Error("unknown cryptor error")},e.prototype.concatArrayBuffer=function(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer},e.prototype.getHeaderData=function(e){if(e.metadata){var t=Vi.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length),r=0;return n.set(t.data,r),r+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),r),n.buffer}},e.prototype.getFileData=function(t){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return t instanceof Blob?[4,t.arrayBuffer()]:[3,2];case 1:return[2,n.sent()];case 2:if(t instanceof ArrayBuffer)return[2,t];if("string"==typeof t)return[2,e.encoder.encode(t)];throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}}))}))},e.LEGACY_IDENTIFIER="",e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Vi=function(){function e(){}return e.from=function(t,n){if(t!==e.LEGACY_IDENTIFIER)return new Wi(t,n.byteLength)},e.tryParse=function(t){var n=new Uint8Array(t),r="";if(n.byteLength>=4&&(r=n.slice(0,4),this.decoder.decode(r)!==e.SENTINEL))return"";if(!(n.byteLength>=5))throw new Error("decryption error. invalid header version");if(n[4]>e.MAX_VERSION)throw new Error("unknown cryptor error");var o="",i=5+e.IDENTIFIER_LENGTH;if(!(n.byteLength>=i))throw new Error("decryption error. invalid crypto identifier");o=n.slice(5,i);var s=null;if(!(n.byteLength>=i+1))throw new Error("decryption error. invalid metadata length");return s=n[i],i+=1,255===s&&n.byteLength>=i+2&&(s=new Uint16Array(n.slice(i,i+2)).reduce((function(e,t){return(e<<8)+t}),0),i+=2),new Wi(this.decoder.decode(o),s)},e.SENTINEL="PNED",e.LEGACY_IDENTIFIER="",e.IDENTIFIER_LENGTH=4,e.VERSION=1,e.MAX_VERSION=1,e.decoder=new TextDecoder,e}(),Wi=function(){function e(e,t){this._identifier=e,this._metadataLength=t}return Object.defineProperty(e.prototype,"identifier",{get:function(){return this._identifier},set:function(e){this._identifier=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"metadataLength",{get:function(){return this._metadataLength},set:function(e){this._metadataLength=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return Vi.VERSION},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return Vi.SENTINEL.length+1+Vi.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){var e=0,t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(Vi.SENTINEL)),t[e+=Vi.SENTINEL.length]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e),e+=Vi.IDENTIFIER_LENGTH;var r=this.metadataLength;return r<255?t[e]=r:t.set([255,r>>8,255&r],e),t},enumerable:!1,configurable:!0}),e.IDENTIFIER_LENGTH=4,e.SENTINEL="PNED",e}();function Ji(e){if(!navigator||!navigator.sendBeacon)return!1;navigator.sendBeacon(e)}var $i=function(e){function n(t){var n=this,r=t.listenToBrowserNetworkEvents,o=void 0===r||r;return t.sdkFamily="Web",t.networking=new _n({del:Fi,get:Ui,post:Ii,patch:Di,sendBeacon:Ji,getfile:xi,postfile:Ri}),t.cbor=new wn((function(e){return Sn(h.decode(e))}),m),t.PubNubFile=Bi,t.cryptography=new Ki,t.initCryptoModule=function(e){return new zi({default:new Hi({cipherKey:e.cipherKey,useRandomIVs:e.useRandomIVs}),cryptors:[new qi({cipherKey:e.cipherKey})]})},n=e.call(this,t)||this,o&&(window.addEventListener("offline",(function(){n.networkDownDetected()})),window.addEventListener("online",(function(){n.networkUpDetected()}))),n}return t(n,e),n.CryptoModule=zi,n}(vn);return $i})); diff --git a/lib/core/components/config.js b/lib/core/components/config.js index 96fa4e7a2..3e10ed32e 100644 --- a/lib/core/components/config.js +++ b/lib/core/components/config.js @@ -180,7 +180,7 @@ var default_1 = /** @class */ (function () { return this; }; default_1.prototype.getVersion = function () { - return '7.6.1'; + return '7.6.2'; }; default_1.prototype._setRetryConfiguration = function (configuration) { if (configuration.minimumdelay < 2) { diff --git a/lib/core/endpoints/push/list_push_channels.js b/lib/core/endpoints/push/list_push_channels.js index 304662c2c..1acd572ab 100644 --- a/lib/core/endpoints/push/list_push_channels.js +++ b/lib/core/endpoints/push/list_push_channels.js @@ -53,12 +53,16 @@ function isAuthSupported() { } exports.isAuthSupported = isAuthSupported; function prepareParams(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.environment, environment = _a === void 0 ? 'development' : _a, topic = incomingParams.topic; + var pushGateway = incomingParams.pushGateway, _a = incomingParams.environment, environment = _a === void 0 ? 'development' : _a, topic = incomingParams.topic, start = incomingParams.start, count = incomingParams.count; var parameters = { type: pushGateway }; if (pushGateway === 'apns2') { parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); delete parameters.type; } + if (start) + parameters.start = start; + if (count && count > 0) + parameters.count = count; return parameters; } exports.prepareParams = prepareParams; diff --git a/package.json b/package.json index b691b4bf8..07327404b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "7.6.1", + "version": "7.6.2", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/config.js b/src/core/components/config.js index dd552f456..11b48ec1c 100644 --- a/src/core/components/config.js +++ b/src/core/components/config.js @@ -358,7 +358,7 @@ export default class { } getVersion() { - return '7.6.1'; + return '7.6.2'; } _setRetryConfiguration(configuration) { diff --git a/src/core/endpoints/push/list_push_channels.js b/src/core/endpoints/push/list_push_channels.js index 25e6fc347..2241407d7 100644 --- a/src/core/endpoints/push/list_push_channels.js +++ b/src/core/endpoints/push/list_push_channels.js @@ -35,7 +35,7 @@ export function isAuthSupported() { } export function prepareParams(modules, incomingParams) { - const { pushGateway, environment = 'development', topic } = incomingParams; + const { pushGateway, environment = 'development', topic, start, count } = incomingParams; let parameters = { type: pushGateway }; if (pushGateway === 'apns2') { @@ -43,6 +43,9 @@ export function prepareParams(modules, incomingParams) { delete parameters.type; } + if (start) parameters.start = start; + if (count && count > 0) parameters.count = count; + return parameters; } diff --git a/test/integration/endpoints/push.test.js b/test/integration/endpoints/push.test.js index 5c222e746..a3c163e8b 100644 --- a/test/integration/endpoints/push.test.js +++ b/test/integration/endpoints/push.test.js @@ -395,6 +395,61 @@ describe('push endpoints', () => { ); }); + it('supports channel listing with start and count params', async () => { + const scope = utils + .createNock() + .get('/v1/push/sub-key/mySubKey/devices/coolDevice') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + type: 'apns', + uuid: 'myUUID', + start: 'ch1', + count: 10, + }) + .reply(200, '["ch1", "ch2", "ch3"]'); + + var res = await pubnub.push.listChannels( + { device: 'coolDevice', pushGateway: 'apns', start: 'ch1', count: 10 }, + (status, response) => { + assert.equal(status.error, false); + assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); + assert.equal(scope.isDone(), true); + done(); + }, + ); + }); + + it('supports channel listing with(APNS2) start and count params', async () => { + const scope = utils + .createNock() + .get('/v2/push/sub-key/mySubKey/devices-apns2/coolDevice') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + environment: 'production', + topic: 'com.test.apns', + uuid: 'myUUID', + start: 'ch1', + count: 10, + }) + .reply(200, '["ch1", "ch2", "ch3"]'); + pubnub.push.listChannels( + { + device: 'coolDevice', + pushGateway: 'apns2', + environment: 'production', + topic: 'com.test.apns', + start: 'ch1', + count: 10, + }, + (status, response) => { + assert.equal(status.error, false); + assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); + assert.equal(scope.isDone(), true); + done(); + }, + ); + }); + it('should add push disable for channels API telemetry information', (done) => { let scope = utils.createNock().get('/v1/push/sub-key/mySubKey/devices/niceDevice').query(true); const delays = [100, 200, 300, 400]; From b29cc36c8b730ad903a7cfc4480b2012e02da4bc Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Thu, 18 Apr 2024 14:04:02 +0530 Subject: [PATCH 04/49] fix: add-remove-subscription-listener-to-set (#368) * add/remove listener from subscription to subscriptionSet. * fixed additional entity name with pnpres being added while creating subscriptionSet * PubNub SDK v7.6.3 release. --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> --- .pubnub.yml | 11 ++++++++--- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- dist/web/pubnub.js | 14 +++++++++++--- dist/web/pubnub.min.js | 2 +- lib/core/components/config.js | 2 +- lib/entities/SubscriptionSet.js | 12 ++++++++++-- package.json | 2 +- src/core/components/config.js | 2 +- src/entities/SubscriptionSet.ts | 28 ++++++++++++++++++---------- 10 files changed, 59 insertions(+), 24 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 5d46365c9..488da2ef3 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-04-18 + version: v7.6.3 + changes: + - type: bug + text: "Fixes issue of add or remove listener of subscription to/from subscriptionSet." - date: 2024-03-28 version: v7.6.2 changes: @@ -953,7 +958,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '7.6.2' +version: '7.6.3' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -969,7 +974,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.2.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.3.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1640,7 +1645,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v7.6.2/pubnub.7.6.2.js + location: https://github.com/pubnub/javascript/releases/download/v7.6.3/pubnub.7.6.3.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a311b725..c23b9c468 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v7.6.3 +April 18 2024 + +#### Fixed +- Fixes issue of add or remove listener of subscription to/from subscriptionSet. + ## v7.6.2 March 28 2024 diff --git a/README.md b/README.md index f2a160dd5..a4edab3ab 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.2.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.2.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.3.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.3.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 6cfbcf2aa..66510cb25 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -794,7 +794,7 @@ return this; }; default_1.prototype.getVersion = function () { - return '7.6.2'; + return '7.6.3'; }; default_1.prototype._setRetryConfiguration = function (configuration) { if (configuration.minimumdelay < 2) { @@ -8432,12 +8432,16 @@ _this.options = subscriptionOptions; _this.eventEmitter = eventEmitter; _this.pubnub = pubnub; - channels.forEach(function (c) { + channels + .filter(function (c) { return !c.endsWith('-pnpres'); }) + .forEach(function (c) { var subscription = _this.pubnub.channel(c).subscription(_this.options); _this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.channelNames), false), __read$1(subscription.channels), false); _this.subscriptionList.push(subscription); }); - channelGroups.forEach(function (cg) { + channelGroups + .filter(function (cg) { return !cg.endsWith('-pnpres'); }) + .forEach(function (cg) { var subscription = _this.pubnub.channelGroup(cg).subscription(_this.options); _this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.groupNames), false), __read$1(subscription.channelGroups), false); _this.subscriptionList.push(subscription); @@ -8450,6 +8454,7 @@ this.subscriptionList.push(subscription); this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscription.channels), false); this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscription.channelGroups), false); + this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); }; SubscriptionSet.prototype.removeSubscription = function (subscription) { var channelsToRemove = subscription.channels; @@ -8457,11 +8462,13 @@ this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); this.subscriptionList = this.subscriptionList.filter(function (s) { return s !== subscription; }); + this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); }; SubscriptionSet.prototype.addSubscriptionSet = function (subscriptionSet) { this.subscriptionList = __spreadArray$1(__spreadArray$1([], __read$1(this.subscriptionList), false), __read$1(subscriptionSet.subscriptions), false); this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscriptionSet.channels), false); this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscriptionSet.channelGroups), false); + this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); }; SubscriptionSet.prototype.removeSubscriptionSet = function (subscriptionSet) { var channelsToRemove = subscriptionSet.channels; @@ -8469,6 +8476,7 @@ this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); this.subscriptionList = this.subscriptionList.filter(function (s) { return !subscriptionSet.subscriptions.includes(s); }); + this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); }; Object.defineProperty(SubscriptionSet.prototype, "subscriptions", { get: function () { diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index f8c1b2a31..9efac6f66 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -14,4 +14,4 @@ PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function u(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o>2,c=0;c>6),o.push(128|63&s)):s<55296?(o.push(224|s>>12),o.push(128|s>>6&63),o.push(128|63&s)):(s=(1023&s)<<10,s|=1023&t.charCodeAt(++r),s+=65536,o.push(240|s>>18),o.push(128|s>>12&63),o.push(128|s>>6&63),o.push(128|63&s))}return h(3,o.length),p(o);default:var f;if(Array.isArray(t))for(h(4,f=t.length),r=0;r>5!==e)throw"Invalid indefinite length element";return n}function g(e,t){for(var n=0;n>10),e.push(56320|1023&r))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var o,h,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=p(),o=32768&n,i=31744&n,s=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==s)return s*r;return t.setUint32(0,o<<16|i<<13|s<<13),t.getFloat32(0)}();case 26:return u(s.getFloat32(a),4);case 27:return u(s.getFloat64(a),8)}if((h=d(v))<0&&(b<2||6=0;)S+=h,_.push(c(h));var w=new Uint8Array(S),O=0;for(o=0;o<_.length;++o)w.set(_[o],O),O+=_[o].length;return w}return c(h);case 3:var P=[];if(h<0)for(;(h=y(b))>=0;)g(P,h);else g(P,h);return String.fromCharCode.apply(null,P);case 4:var E;if(h<0)for(E=[];!f();)E.push(e());else for(E=new Array(h),o=0;o=20?this._presenceTimeout=e:(this._presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",this._presenceTimeout)),this.setHeartbeatInterval(this._presenceTimeout/2-1),this},e.prototype.setProxy=function(e){this.proxy=e},e.prototype.getHeartbeatInterval=function(){return this._heartbeatInterval},e.prototype.setHeartbeatInterval=function(e){return this._heartbeatInterval=e,this},e.prototype.getSubscribeTimeout=function(){return this._subscribeRequestTimeout},e.prototype.setSubscribeTimeout=function(e){return this._subscribeRequestTimeout=e,this},e.prototype.getTransactionTimeout=function(){return this._transactionalRequestTimeout},e.prototype.setTransactionTimeout=function(e){return this._transactionalRequestTimeout=e,this},e.prototype.isSendBeaconEnabled=function(){return this._useSendBeacon},e.prototype.setSendBeaconConfig=function(e){return this._useSendBeacon=e,this},e.prototype.getVersion=function(){return"7.6.2"},e.prototype._setRetryConfiguration=function(e){if(e.minimumdelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(e.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(e.maximumDelay&&maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6");if(e.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10");this.retryConfiguration=e},e.prototype._addPnsdkSuffix=function(e,t){this._PNSDKSuffix[e]=t},e.prototype._getPnsdkSuffix=function(e){var t=this;return Object.keys(this._PNSDKSuffix).reduce((function(n,r){return n+e+t._PNSDKSuffix[r]}),"")},e}();function m(e){var t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;function s(){var e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error("Illegal character at ".concat(i,": ").concat(t.charAt(i-1)));return n}for(var a=0;a>4,f=(15&c)<<4|l>>2,d=(3&l)<<6|p>>0;o[a]=h,64!=l&&(o[a+1]=f),64!=p&&(o[a+2]=d)}return r}function b(e){for(var t,n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=new Uint8Array(e),i=o.byteLength,s=i%3,a=i-s,u=0;u>18]+r[(258048&t)>>12]+r[(4032&t)>>6]+r[63&t];return 1==s?n+=r[(252&(t=o[a]))>>2]+r[(3&t)<<4]+"==":2==s&&(n+=r[(64512&(t=o[a]<<8|o[a+1]))>>10]+r[(1008&t)>>4]+r[(15&t)<<2]+"="),n}var v,_,S,w,O,P=P||function(e,t){var n={},r=n.lib={},o=function(){},i=r.Base={extend:function(e){o.prototype=this;var t=new o;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var o=0;o>>2]|=(n[o>>>2]>>>24-o%4*8&255)<<24-(r+o)%4*8;else if(65535>>2]=n[o>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r>>2]>>>24-r%4*8&255;n.push((o>>>4).toString(16)),n.push((15&o).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,a=o/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,o=e.min(4*t,o),t){for(var u=0;uc;){var l;e:{l=u;for(var p=e.sqrt(l),h=2;h<=p;h++)if(!(l%h)){l=!1;break e}l=!0}l&&(8>c&&(i[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var f=[];o=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],a=n[3],u=n[4],c=n[5],l=n[6],p=n[7],h=0;64>h;h++){if(16>h)f[h]=0|e[t+h];else{var d=f[h-15],y=f[h-2];f[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+f[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+f[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[h]+f[h],y=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=l,l=c,c=u,u=a+d|0,a=i,i=o,o=r,r=d+y|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+p|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(o),t.HmacSHA256=r._createHmacHelper(o)}(Math),_=(v=P).enc.Utf8,v.algo.HMAC=v.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=_.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,a=i.words,u=0;u>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;4>s&&o+.75*s>>6*(3-s)&63));if(t=r.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(r=n.charAt(64))&&-1!=(r=e.indexOf(r))&&(t=r);for(var r=[],o=0,i=0;i>>6-i%4*2;r[o>>>2]|=(s|a)<<24-o%4*8,o++}return w.create(r,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,r,o,i,s){return((e=e+(t&n|~t&r)+o+s)<>>32-i)+t}function n(e,t,n,r,o,i,s){return((e=e+(t&r|n&~r)+o+s)<>>32-i)+t}function r(e,t,n,r,o,i,s){return((e=e+(t^n^r)+o+s)<>>32-i)+t}function o(e,t,n,r,o,i,s){return((e=e+(n^(t|~r))+o+s)<>>32-i)+t}for(var i=P,s=(u=i.lib).WordArray,a=u.Hasher,u=i.algo,c=[],l=0;64>l;l++)c[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=a.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var s=0;16>s;s++){var a=e[u=i+s];e[u]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}s=this._hash.words;var u=e[i+0],l=(a=e[i+1],e[i+2]),p=e[i+3],h=e[i+4],f=e[i+5],d=e[i+6],y=e[i+7],g=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],_=e[i+12],S=e[i+13],w=e[i+14],O=e[i+15],P=t(P=s[0],T=s[1],A=s[2],E=s[3],u,7,c[0]),E=t(E,P,T,A,a,12,c[1]),A=t(A,E,P,T,l,17,c[2]),T=t(T,A,E,P,p,22,c[3]);P=t(P,T,A,E,h,7,c[4]),E=t(E,P,T,A,f,12,c[5]),A=t(A,E,P,T,d,17,c[6]),T=t(T,A,E,P,y,22,c[7]),P=t(P,T,A,E,g,7,c[8]),E=t(E,P,T,A,m,12,c[9]),A=t(A,E,P,T,b,17,c[10]),T=t(T,A,E,P,v,22,c[11]),P=t(P,T,A,E,_,7,c[12]),E=t(E,P,T,A,S,12,c[13]),A=t(A,E,P,T,w,17,c[14]),P=n(P,T=t(T,A,E,P,O,22,c[15]),A,E,a,5,c[16]),E=n(E,P,T,A,d,9,c[17]),A=n(A,E,P,T,v,14,c[18]),T=n(T,A,E,P,u,20,c[19]),P=n(P,T,A,E,f,5,c[20]),E=n(E,P,T,A,b,9,c[21]),A=n(A,E,P,T,O,14,c[22]),T=n(T,A,E,P,h,20,c[23]),P=n(P,T,A,E,m,5,c[24]),E=n(E,P,T,A,w,9,c[25]),A=n(A,E,P,T,p,14,c[26]),T=n(T,A,E,P,g,20,c[27]),P=n(P,T,A,E,S,5,c[28]),E=n(E,P,T,A,l,9,c[29]),A=n(A,E,P,T,y,14,c[30]),P=r(P,T=n(T,A,E,P,_,20,c[31]),A,E,f,4,c[32]),E=r(E,P,T,A,g,11,c[33]),A=r(A,E,P,T,v,16,c[34]),T=r(T,A,E,P,w,23,c[35]),P=r(P,T,A,E,a,4,c[36]),E=r(E,P,T,A,h,11,c[37]),A=r(A,E,P,T,y,16,c[38]),T=r(T,A,E,P,b,23,c[39]),P=r(P,T,A,E,S,4,c[40]),E=r(E,P,T,A,u,11,c[41]),A=r(A,E,P,T,p,16,c[42]),T=r(T,A,E,P,d,23,c[43]),P=r(P,T,A,E,m,4,c[44]),E=r(E,P,T,A,_,11,c[45]),A=r(A,E,P,T,O,16,c[46]),P=o(P,T=r(T,A,E,P,l,23,c[47]),A,E,u,6,c[48]),E=o(E,P,T,A,y,10,c[49]),A=o(A,E,P,T,w,15,c[50]),T=o(T,A,E,P,f,21,c[51]),P=o(P,T,A,E,_,6,c[52]),E=o(E,P,T,A,p,10,c[53]),A=o(A,E,P,T,b,15,c[54]),T=o(T,A,E,P,a,21,c[55]),P=o(P,T,A,E,g,6,c[56]),E=o(E,P,T,A,O,10,c[57]),A=o(A,E,P,T,d,15,c[58]),T=o(T,A,E,P,S,21,c[59]),P=o(P,T,A,E,h,6,c[60]),E=o(E,P,T,A,v,10,c[61]),A=o(A,E,P,T,l,15,c[62]),T=o(T,A,E,P,m,21,c[63]);s[0]=s[0]+P|0,s[1]=s[1]+T|0,s[2]=s[2]+A|0,s[3]=s[3]+E|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var i=e.floor(r/4294967296);for(n[15+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(o+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,r=0;4>r;r++)o=n[r],n[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(u),i.HmacMD5=a._createHmacHelper(u)}(Math),function(){var e,t=P,n=(e=t.lib).Base,r=e.WordArray,o=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),o=r.create(),i=o.words,s=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:u,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var p=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(u=(f.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return p.create({ciphertext:e,salt:n})}},t.SerializableCipher=n.extend({cfg:n.extend({format:u}),encrypt:function(e,t,n,r){r=this.cfg.extend(r);var o=e.createEncryptor(n,r);return t=o.finalize(t),o=o.cfg,p.create({ciphertext:t,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:r.format})},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),e.createDecryptor(n,r).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),f=(f.kdf={}).OpenSSL={execute:function(e,t,n,o){return o||(o=r.random(8)),e=s.create({keySize:t+n}).compute(e,o),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,p.create({key:e,iv:n,salt:o})}},d=t.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:f}),encrypt:function(e,t,n,r){return n=(r=this.cfg.extend(r)).kdf.execute(n,e.keySize,e.ivSize),r.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,r)).mixIn(n),e},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),n=r.kdf.execute(n,e.keySize,e.ivSize,t.salt),r.iv=n.iv,h.decrypt.call(this,e,t,n.key,r)}})}(),function(){for(var e=P,t=e.lib.BlockCipher,n=e.algo,r=[],o=[],i=[],s=[],a=[],u=[],c=[],l=[],p=[],h=[],f=[],d=0;256>d;d++)f[d]=128>d?d<<1:d<<1^283;var y=0,g=0;for(d=0;256>d;d++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;r[y]=m,o[m]=y;var b=f[y],v=f[b],_=f[v],S=257*f[m]^16843008*m;i[y]=S<<24|S>>>8,s[y]=S<<16|S>>>16,a[y]=S<<8|S>>>24,u[y]=S,S=16843009*_^65537*v^257*b^16843008*y,c[m]=S<<24|S>>>8,l[m]=S<<16|S>>>16,p[m]=S<<8|S>>>24,h[m]=S,y?(y=b^f[f[f[_^b]]],g^=f[f[g]]):y=g=1}var w=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),o=this._keySchedule=[],i=0;i>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s]):(s=r[(s=s<<8|s>>>24)>>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s],s^=w[i/t|0]<<24),o[i]=o[i-t]^s}for(e=this._invKeySchedule=[],t=0;tt||4>=i?s:c[r[s>>>24]]^l[r[s>>>16&255]]^p[r[s>>>8&255]]^h[r[255&s]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,s,a,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,c,l,p,h,o),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,r,o,i,s,a){for(var u=this._nRounds,c=e[t]^n[0],l=e[t+1]^n[1],p=e[t+2]^n[2],h=e[t+3]^n[3],f=4,d=1;d>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&h]^n[f++],g=r[l>>>24]^o[p>>>16&255]^i[h>>>8&255]^s[255&c]^n[f++],m=r[p>>>24]^o[h>>>16&255]^i[c>>>8&255]^s[255&l]^n[f++];h=r[h>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^n[f++],c=y,l=g,p=m}y=(a[c>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&h])^n[f++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[h>>>8&255]<<8|a[255&c])^n[f++],m=(a[p>>>24]<<24|a[h>>>16&255]<<16|a[c>>>8&255]<<8|a[255&l])^n[f++],h=(a[h>>>24]<<24|a[c>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^n[f++],e[t]=y,e[t+1]=g,e[t+2]=m,e[t+3]=h},keySize:8});e.AES=t._createHelper(n)}(),P.mode.ECB=((O=P.lib.BlockCipherMode.extend()).Encryptor=O.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),O.Decryptor=O.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),O);var E=P;function A(e){var t,n=[];for(t=0;t=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))},e.prototype.clearHistory=function(){this.hashHistory=[]},e}(),k={PNNetworkUpCategory:"PNNetworkUpCategory",PNNetworkDownCategory:"PNNetworkDownCategory",PNNetworkIssuesCategory:"PNNetworkIssuesCategory",PNTimeoutCategory:"PNTimeoutCategory",PNBadRequestCategory:"PNBadRequestCategory",PNAccessDeniedCategory:"PNAccessDeniedCategory",PNUnknownCategory:"PNUnknownCategory",PNReconnectedCategory:"PNReconnectedCategory",PNConnectedCategory:"PNConnectedCategory",PNRequestMessageCountExceededCategory:"PNRequestMessageCountExceededCategory",PNDisconnectedCategory:"PNDisconnectedCategory",PNConnectionErrorCategory:"PNConnectionErrorCategory",PNDisconnectedUnexpectedlyCategory:"PNDisconnectedUnexpectedlyCategory"},M=function(){function e(e){var t=e.subscribeEndpoint,n=e.leaveEndpoint,r=e.heartbeatEndpoint,o=e.setStateEndpoint,i=e.timeEndpoint,s=e.getFileUrl,a=e.config,u=e.crypto,c=e.listenerManager,l=e.cryptoModule,p=e.eventEmitter;this._listenerManager=c,this._config=a,this._leaveEndpoint=n,this._heartbeatEndpoint=r,this._setStateEndpoint=o,this._subscribeEndpoint=t,this._getFileUrl=s,this._crypto=u,this._cryptoModule=l,this._channels={},this._presenceChannels={},this._heartbeatChannels={},this._heartbeatChannelGroups={},this._channelGroups={},this._presenceChannelGroups={},this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[],this._currentTimetoken=0,this._lastTimetoken=0,this._storedTimetoken=null,this._subscriptionStatusAnnounced=!1,this._isOnline=!0,this._reconnectionManager=new N({timeEndpoint:i}),this._dedupingManager=new C({config:a}),this._cryptoModule&&(this._decoder=new TextDecoder),this._eventEmitter=p}return e.prototype.adaptStateChange=function(e,t){var n=this,r=e.state,o=e.channels,i=void 0===o?[]:o,s=e.channelGroups,a=void 0===s?[]:s,u=e.withHeartbeat,c=void 0!==u&&u;if(i.forEach((function(e){e in n._channels&&(n._channels[e].state=r)})),a.forEach((function(e){e in n._channelGroups&&(n._channelGroups[e].state=r)})),c){var l={};return i.forEach((function(e){return l[e]=r})),a.forEach((function(e){return l[e]=r})),this._heartbeatEndpoint({channels:i,channelGroups:a,state:l},t)}return this._setStateEndpoint({state:r,channels:i,channelGroups:a},t)},e.prototype.adaptPresenceChange=function(e){var t=this,n=e.connected,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i;n?(o.forEach((function(e){t._heartbeatChannels[e]={state:{}}})),s.forEach((function(e){t._heartbeatChannelGroups[e]={state:{}}}))):(o.forEach((function(e){e in t._heartbeatChannels&&delete t._heartbeatChannels[e]})),s.forEach((function(e){e in t._heartbeatChannelGroups&&delete t._heartbeatChannelGroups[e]})),!1===this._config.suppressLeaveEvents&&this._leaveEndpoint({channels:o,channelGroups:s},(function(e){t._listenerManager.announceStatus(e)}))),this.reconnect()},e.prototype.adaptSubscribeChange=function(e){var t=this,n=e.timetoken,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=e.withPresence,u=void 0!==a&&a,c=e.withHeartbeats,l=void 0!==c&&c;this._config.subscribeKey&&""!==this._config.subscribeKey?(n&&(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=n),"0"!==this._currentTimetoken&&0!==this._currentTimetoken&&(this._storedTimetoken=this._currentTimetoken,this._currentTimetoken=0),o.forEach((function(e){t._channels[e]={state:{}},u&&(t._presenceChannels[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannels[e]={}),t._pendingChannelSubscriptions.push(e)})),s.forEach((function(e){t._channelGroups[e]={state:{}},u&&(t._presenceChannelGroups[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannelGroups[e]={}),t._pendingChannelGroupSubscriptions.push(e)})),this._subscriptionStatusAnnounced=!1,this.reconnect()):console&&console.log&&console.log("subscribe key missing; aborting subscribe")},e.prototype.adaptUnsubscribeChange=function(e,t){var n=this,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=[],u=[];o.forEach((function(e){e in n._channels&&(delete n._channels[e],a.push(e),e in n._heartbeatChannels&&delete n._heartbeatChannels[e]),e in n._presenceChannels&&(delete n._presenceChannels[e],a.push(e))})),s.forEach((function(e){e in n._channelGroups&&(delete n._channelGroups[e],u.push(e),e in n._heartbeatChannelGroups&&delete n._heartbeatChannelGroups[e]),e in n._presenceChannelGroups&&(delete n._presenceChannelGroups[e],u.push(e))})),0===a.length&&0===u.length||(!1!==this._config.suppressLeaveEvents||t||this._leaveEndpoint({channels:a,channelGroups:u},(function(e){e.affectedChannels=a,e.affectedChannelGroups=u,e.currentTimetoken=n._currentTimetoken,e.lastTimetoken=n._lastTimetoken,n._listenerManager.announceStatus(e)})),0===Object.keys(this._channels).length&&0===Object.keys(this._presenceChannels).length&&0===Object.keys(this._channelGroups).length&&0===Object.keys(this._presenceChannelGroups).length&&(this._lastTimetoken=0,this._currentTimetoken=0,this._storedTimetoken=null,this._region=null,this._reconnectionManager.stopPolling()),this.reconnect())},e.prototype.unsubscribeAll=function(e){this.adaptUnsubscribeChange({channels:this.getSubscribedChannels(),channelGroups:this.getSubscribedChannelGroups()},e)},e.prototype.getHeartbeatChannels=function(){return Object.keys(this._heartbeatChannels)},e.prototype.getHeartbeatChannelGroups=function(){return Object.keys(this._heartbeatChannelGroups)},e.prototype.getSubscribedChannels=function(){return Object.keys(this._channels)},e.prototype.getSubscribedChannelGroups=function(){return Object.keys(this._channelGroups)},e.prototype.reconnect=function(){this._startSubscribeLoop(),this._registerHeartbeatTimer()},e.prototype.disconnect=function(){this._stopSubscribeLoop(),this._stopHeartbeatTimer(),this._reconnectionManager.stopPolling()},e.prototype._registerHeartbeatTimer=function(){this._stopHeartbeatTimer(),0!==this._config.getHeartbeatInterval()&&void 0!==this._config.getHeartbeatInterval()&&(this._performHeartbeatLoop(),this._heartbeatTimer=setInterval(this._performHeartbeatLoop.bind(this),1e3*this._config.getHeartbeatInterval()))},e.prototype._stopHeartbeatTimer=function(){this._heartbeatTimer&&(clearInterval(this._heartbeatTimer),this._heartbeatTimer=null)},e.prototype._performHeartbeatLoop=function(){var e=this,t=this.getHeartbeatChannels(),n=this.getHeartbeatChannelGroups(),r={};if(0!==t.length||0!==n.length){this.getSubscribedChannels().forEach((function(t){var n=e._channels[t].state;Object.keys(n).length&&(r[t]=n)})),this.getSubscribedChannelGroups().forEach((function(t){var n=e._channelGroups[t].state;Object.keys(n).length&&(r[t]=n)}));this._heartbeatEndpoint({channels:t,channelGroups:n,state:r},function(t){t.error&&e._config.announceFailedHeartbeats&&e._listenerManager.announceStatus(t),t.error&&e._config.autoNetworkDetection&&e._isOnline&&(e._isOnline=!1,e.disconnect(),e._listenerManager.announceNetworkDown(),e.reconnect()),!t.error&&e._config.announceSuccessfulHeartbeats&&e._listenerManager.announceStatus(t)}.bind(this))}},e.prototype._startSubscribeLoop=function(){var e=this;this._stopSubscribeLoop();var t={},n=[],r=[];if(Object.keys(this._channels).forEach((function(r){var o=e._channels[r].state;Object.keys(o).length&&(t[r]=o),n.push(r)})),Object.keys(this._presenceChannels).forEach((function(e){n.push("".concat(e,"-pnpres"))})),Object.keys(this._channelGroups).forEach((function(n){var o=e._channelGroups[n].state;Object.keys(o).length&&(t[n]=o),r.push(n)})),Object.keys(this._presenceChannelGroups).forEach((function(e){r.push("".concat(e,"-pnpres"))})),0!==n.length||0!==r.length){var o={channels:n,channelGroups:r,state:t,timetoken:this._currentTimetoken,filterExpression:this._config.filterExpression,region:this._region};this._subscribeCall=this._subscribeEndpoint(o,this._processSubscribeResponse.bind(this))}},e.prototype._processSubscribeResponse=function(e,t){var n=this;if(e.error){if(e.errorData&&"Aborted"===e.errorData.message)return;e.category===k.PNTimeoutCategory?this._startSubscribeLoop():e.category===k.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this._config.autoNetworkDetection&&this._isOnline&&(this._isOnline=!1,this._listenerManager.announceNetworkDown()),this._reconnectionManager.onReconnection((function(){n._config.autoNetworkDetection&&!n._isOnline&&(n._isOnline=!0,n._listenerManager.announceNetworkUp()),n.reconnect(),n._subscriptionStatusAnnounced=!0;var t={category:k.PNReconnectedCategory,operation:e.operation,lastTimetoken:n._lastTimetoken,currentTimetoken:n._currentTimetoken};n._listenerManager.announceStatus(t)})),this._reconnectionManager.startPolling(),this._listenerManager.announceStatus(e)):e.category===k.PNBadRequestCategory?(this._stopHeartbeatTimer(),this._listenerManager.announceStatus(e)):this._listenerManager.announceStatus(e)}else{if(this._storedTimetoken?(this._currentTimetoken=this._storedTimetoken,this._storedTimetoken=null):(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=t.metadata.timetoken),!this._subscriptionStatusAnnounced){var r={};r.category=k.PNConnectedCategory,r.operation=e.operation,r.affectedChannels=this._pendingChannelSubscriptions,r.subscribedChannels=this.getSubscribedChannels(),r.affectedChannelGroups=this._pendingChannelGroupSubscriptions,r.lastTimetoken=this._lastTimetoken,r.currentTimetoken=this._currentTimetoken,this._subscriptionStatusAnnounced=!0,this._listenerManager.announceStatus(r),this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[]}var o=t.messages||[],i=this._config,s=i.requestMessageCountThreshold,a=i.dedupeOnSubscribe;if(s&&o.length>=s){var u={};u.category=k.PNRequestMessageCountExceededCategory,u.operation=e.operation,this._listenerManager.announceStatus(u)}o.forEach((function(e){if(e.channel,e.subscriptionMatch,a){if(n._dedupingManager.isDuplicate(e))return;n._dedupingManager.addEntry(e)}n._eventEmitter.emitEvent(e)})),this._region=t.metadata.region,this._startSubscribeLoop()}},e.prototype._stopSubscribeLoop=function(){this._subscribeCall&&("function"==typeof this._subscribeCall.abort&&this._subscribeCall.abort(),this._subscribeCall=null)},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),j={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",PNAccessManagerRevokeToken:"PNAccessManagerRevokeToken",PNHandshakeOperation:"PNHandshakeOperation",PNReceiveMessagesOperation:"PNReceiveMessagesOperation"},R=function(){function e(e){this._maximumSamplesCount=100,this._trackedLatencies={},this._latencies={},this._telemetryExcludeOperations=[j.PNSubscribeOperation,j.PNReceiveMessagesOperation,j.PNHandshakeOperation],this._maximumSamplesCount=e.maximumSamplesCount||this._maximumSamplesCount}return e.prototype.operationsLatencyForRequest=function(){var e=this,t={};return Object.keys(this._latencies).forEach((function(n){var r=e._latencies[n],o=e._averageLatency(r);o>0&&(t["l_".concat(n)]=o)})),t},e.prototype.startLatencyMeasure=function(e,t){!this._telemetryExcludeOperations.includes(e)&&t&&(this._trackedLatencies[t]=Date.now())},e.prototype.stopLatencyMeasure=function(e,t){if(!this._telemetryExcludeOperations.includes(e)&&t){var n=this._endpointName(e),r=this._latencies[n],o=this._trackedLatencies[t];r||(this._latencies[n]=[],r=this._latencies[n]),r.push(Date.now()-o),r.length>this._maximumSamplesCount&&r.splice(0,r.length-this._maximumSamplesCount),delete this._trackedLatencies[t]}},e.prototype._averageLatency=function(e){return Math.floor(e.reduce((function(e,t){return e+t}),0)/e.length)},e.prototype._endpointName=function(e){var t=null;switch(e){case j.PNPublishOperation:t="pub";break;case j.PNSignalOperation:t="sig";break;case j.PNHistoryOperation:case j.PNFetchMessagesOperation:case j.PNDeleteMessagesOperation:case j.PNMessageCounts:t="hist";break;case j.PNUnsubscribeOperation:case j.PNWhereNowOperation:case j.PNHereNowOperation:case j.PNHeartbeatOperation:case j.PNSetStateOperation:case j.PNGetStateOperation:t="pres";break;case j.PNAddChannelsToGroupOperation:case j.PNRemoveChannelsFromGroupOperation:case j.PNChannelGroupsOperation:case j.PNRemoveGroupOperation:case j.PNChannelsForGroupOperation:t="cg";break;case j.PNPushNotificationEnabledChannelsOperation:case j.PNRemoveAllPushNotificationsOperation:t="push";break;case j.PNCreateUserOperation:case j.PNUpdateUserOperation:case j.PNDeleteUserOperation:case j.PNGetUserOperation:case j.PNGetUsersOperation:case j.PNCreateSpaceOperation:case j.PNUpdateSpaceOperation:case j.PNDeleteSpaceOperation:case j.PNGetSpaceOperation:case j.PNGetSpacesOperation:case j.PNGetMembersOperation:case j.PNUpdateMembersOperation:case j.PNGetMembershipsOperation:case j.PNUpdateMembershipsOperation:t="obj";break;case j.PNAddMessageActionOperation:case j.PNRemoveMessageActionOperation:case j.PNGetMessageActionsOperation:t="msga";break;case j.PNAccessManagerGrant:case j.PNAccessManagerAudit:t="pam";break;case j.PNAccessManagerGrantToken:case j.PNAccessManagerRevokeToken:t="pamv3";break;default:t="time"}return t},e}(),x=function(){function e(e,t,n){this._payload=e,this._setDefaultPayloadStructure(),this.title=t,this.body=n}return Object.defineProperty(e.prototype,"payload",{get:function(){return this._payload},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{set:function(e){this._title=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{set:function(e){this._subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{set:function(e){this._body=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{set:function(e){this._badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{set:function(e){this._sound=e},enumerable:!1,configurable:!0}),e.prototype._setDefaultPayloadStructure=function(){},e.prototype.toObject=function(){return{}},e}(),U=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"configurations",{set:function(e){e&&e.length&&(this._configurations=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"notification",{get:function(){return this._payload.aps},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.aps.alert.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){e&&e.length&&(this._payload.aps.alert.subtitle=e,this._subtitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.aps.alert.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this._badge},set:function(e){null!=e&&(this._payload.aps.badge=e,this._badge=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.aps.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),r.prototype._setDefaultPayloadStructure=function(){this._payload.aps={alert:{}}},r.prototype.toObject=function(){var e=this,t=n({},this._payload),r=t.aps,o=r.alert;if(this._isSilent&&(r["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");var i=[];this._configurations.forEach((function(t){i.push(e._objectFromAPNS2Configuration(t))})),i.length&&(t.pn_push=i)}return o&&Object.keys(o).length||delete r.alert,this._isSilent&&(delete r.alert,delete r.badge,delete r.sound,o={}),this._isSilent||Object.keys(o).length?t:null},r.prototype._objectFromAPNS2Configuration=function(e){var t=this;if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");var n=[];e.targets.forEach((function(e){n.push(t._objectFromAPNSTarget(e))}));var r=e.collapseId,o=e.expirationDate,i={auth_method:"token",targets:n,version:"v2"};return r&&r.length&&(i.collapse_id=r),o&&(i.expiration=o.toISOString()),i},r.prototype._objectFromAPNSTarget=function(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");var t=e.topic,n=e.environment,r=void 0===n?"development":n,o=e.excludedDevices,i=void 0===o?[]:o,s={topic:t,environment:r};return i.length&&(s.excluded_devices=i),s},r}(x),I=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"backContent",{get:function(){return this._backContent},set:function(e){e&&e.length&&(this._payload.back_content=e,this._backContent=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"backTitle",{get:function(){return this._backTitle},set:function(e){e&&e.length&&(this._payload.back_title=e,this._backTitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"count",{get:function(){return this._count},set:function(e){null!=e&&(this._payload.count=e,this._count=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"type",{get:function(){return this._type},set:function(e){e&&e.length&&(this._payload.type=e,this._type=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this.backTitle},set:function(e){this.backTitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this.backContent},set:function(e){this.backContent=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this.count},set:function(e){this.count=e},enumerable:!1,configurable:!0}),r.prototype.toObject=function(){return Object.keys(this._payload).length?n({},this._payload):null},r}(x),D=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return t(o,e),Object.defineProperty(o.prototype,"notification",{get:function(){return this._payload.notification},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"data",{get:function(){return this._payload.data},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.notification.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.notification.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.notification.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"icon",{get:function(){return this._icon},set:function(e){e&&e.length&&(this._payload.notification.icon=e,this._icon=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"tag",{get:function(){return this._tag},set:function(e){e&&e.length&&(this._payload.notification.tag=e,this._tag=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),o.prototype._setDefaultPayloadStructure=function(){this._payload.notification={},this._payload.data={}},o.prototype.toObject=function(){var e=n({},this._payload.data),t=null,o={};if(Object.keys(this._payload).length>2){var i=this._payload;i.notification,i.data;var s=r(i,["notification","data"]);e=n(n({},e),s)}return this._isSilent?e.notification=this._payload.notification:t=this._payload.notification,Object.keys(e).length&&(o.data=e),t&&Object.keys(t).length&&(o.notification=t),Object.keys(o).length?o:null},o}(x),F=function(){function e(e,t){this._payload={apns:{},mpns:{},fcm:{}},this._title=e,this._body=t,this.apns=new U(this._payload.apns,e,t),this.mpns=new I(this._payload.mpns,e,t),this.fcm=new D(this._payload.fcm,e,t)}return Object.defineProperty(e.prototype,"debugging",{set:function(e){this._debugging=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this._body},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){this._subtitle=e,this.apns.subtitle=e,this.mpns.subtitle=e,this.fcm.subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{get:function(){return this._badge},set:function(e){this._badge=e,this.apns.badge=e,this.mpns.badge=e,this.fcm.badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{get:function(){return this._sound},set:function(e){this._sound=e,this.apns.sound=e,this.mpns.sound=e,this.fcm.sound=e},enumerable:!1,configurable:!0}),e.prototype.buildPayload=function(e){var t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";var n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("mpns")){var r=this.mpns.toObject();r&&Object.keys(r).length&&(t.pn_mpns=r)}if(e.includes("fcm")){var o=this.fcm.toObject();o&&Object.keys(o).length&&(t.pn_gcm=o)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t},e}(),L=function(){function e(){this._listeners=[]}return e.prototype.addListener=function(e){this._listeners.includes(e)||this._listeners.push(e)},e.prototype.removeListener=function(e){var t=[];this._listeners.forEach((function(n){n!==e&&t.push(n)})),this._listeners=t},e.prototype.removeAllListeners=function(){this._listeners=[]},e.prototype.announcePresence=function(e){this._listeners.forEach((function(t){t.presence&&t.presence(e)}))},e.prototype.announceStatus=function(e){this._listeners.forEach((function(t){t.status&&t.status(e)}))},e.prototype.announceMessage=function(e){this._listeners.forEach((function(t){t.message&&t.message(e)}))},e.prototype.announceSignal=function(e){this._listeners.forEach((function(t){t.signal&&t.signal(e)}))},e.prototype.announceMessageAction=function(e){this._listeners.forEach((function(t){t.messageAction&&t.messageAction(e)}))},e.prototype.announceFile=function(e){this._listeners.forEach((function(t){t.file&&t.file(e)}))},e.prototype.announceObjects=function(e){this._listeners.forEach((function(t){t.objects&&t.objects(e)}))},e.prototype.announceUser=function(e){this._listeners.forEach((function(t){t.user&&t.user(e)}))},e.prototype.announceSpace=function(e){this._listeners.forEach((function(t){t.space&&t.space(e)}))},e.prototype.announceMembership=function(e){this._listeners.forEach((function(t){t.membership&&t.membership(e)}))},e.prototype.announceNetworkUp=function(){var e={};e.category=k.PNNetworkUpCategory,this.announceStatus(e)},e.prototype.announceNetworkDown=function(){var e={};e.category=k.PNNetworkDownCategory,this.announceStatus(e)},e}(),G=function(){function e(e,t){this._config=e,this._cbor=t}return e.prototype.setToken=function(e){e&&e.length>0?this._token=e:this._token=void 0},e.prototype.getToken=function(){return this._token},e.prototype.extractPermissions=function(e){var t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128==(128&e)&&(t.join=!0),64==(64&e)&&(t.update=!0),32==(32&e)&&(t.get=!0),8==(8&e)&&(t.delete=!0),4==(4&e)&&(t.manage=!0),2==(2&e)&&(t.write=!0),1==(1&e)&&(t.read=!0),t},e.prototype.parseToken=function(e){var t=this,n=this._cbor.decodeToken(e);if(void 0!==n){var r=n.res.uuid?Object.keys(n.res.uuid):[],o=Object.keys(n.res.chan),i=Object.keys(n.res.grp),s=n.pat.uuid?Object.keys(n.pat.uuid):[],a=Object.keys(n.pat.chan),u=Object.keys(n.pat.grp),c={version:n.v,timestamp:n.t,ttl:n.ttl,authorized_uuid:n.uuid},l=r.length>0,p=o.length>0,h=i.length>0;(l||p||h)&&(c.resources={},l&&(c.resources.uuids={},r.forEach((function(e){c.resources.uuids[e]=t.extractPermissions(n.res.uuid[e])}))),p&&(c.resources.channels={},o.forEach((function(e){c.resources.channels[e]=t.extractPermissions(n.res.chan[e])}))),h&&(c.resources.groups={},i.forEach((function(e){c.resources.groups[e]=t.extractPermissions(n.res.grp[e])}))));var f=s.length>0,d=a.length>0,y=u.length>0;return(f||d||y)&&(c.patterns={},f&&(c.patterns.uuids={},s.forEach((function(e){c.patterns.uuids[e]=t.extractPermissions(n.pat.uuid[e])}))),d&&(c.patterns.channels={},a.forEach((function(e){c.patterns.channels[e]=t.extractPermissions(n.pat.chan[e])}))),y&&(c.patterns.groups={},u.forEach((function(e){c.patterns.groups[e]=t.extractPermissions(n.pat.grp[e])})))),Object.keys(n.meta).length>0&&(c.meta=n.meta),c.signature=n.sig,c}},e}();function K(e){return encodeURIComponent(e).replace(/[!~*'()]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())}))}function B(e){return function(e){var t=[];return Object.keys(e).forEach((function(e){return t.push(e)})),t}(e).sort()}var H={signPamFromParams:function(e){return B(e).map((function(t){return"".concat(t,"=").concat(K(e[t]))})).join("&")},endsWith:function(e,t){return-1!==e.indexOf(t,this.length-t.length)},createPromise:function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),reject:t,fulfill:e}},encodeString:K,stringToArrayBuffer:function(e){for(var t=new ArrayBuffer(2*e.length),n=new Uint16Array(t),r=0,o=e.length;r0&&(t+=n),t}function J(e,t,n){return t.usePost&&t.usePost(e,n)?"POST":t.usePatch&&t.usePatch(e,n)?"PATCH":t.useDelete&&t.useDelete(e,n)?"DELETE":t.useGetFile&&t.useGetFile(e,n)?"GETFILE":"GET"}function $(e,t,n,r,o){var i=e.config,s=e.crypto,a=J(e,o,r);n.timestamp=Math.floor((new Date).getTime()/1e3),"PNPublishOperation"===o.getOperation()&&o.usePost&&o.usePost(e,r)&&(a="GET"),"GETFILE"===a&&(a="GET");var u="".concat(a,"\n").concat(i.publishKey,"\n").concat(t,"\n").concat(H.signPamFromParams(n),"\n");if("POST"===a)u+="string"==typeof(c=o.postPayload(e,r))?c:JSON.stringify(c);else if("PATCH"===a){var c;u+="string"==typeof(c=o.patchPayload(e,r))?c:JSON.stringify(c)}var l="v2.".concat(s.HMACSHA256(u));l=(l=(l=l.replace(/\+/g,"-")).replace(/\//g,"_")).replace(/=+$/,""),n.signature=l}function Q(e,t){for(var r=[],o=2;o0&&(c.count=u),c},handleResponse:function(e,t){return{channels:t}}});var ie=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveAllPushNotificationsOperation},validateParams:function(e,t){var n=t.device,r=t.pushGateway,o=t.topic,i=e.config;return n?r?"apns2"!==r||o?i.subscribeKey?void 0:"Missing Subscribe Key":"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm, apns or apns2)":"Missing Device ID (device)"},getURL:function(e,t){var n=t.device,r=t.pushGateway,o=e.config;return"apns2"===r?"/v2/push/sub-key/".concat(o.subscribeKey,"/devices-apns2/").concat(n,"/remove"):"/v1/push/sub-key/".concat(o.subscribeKey,"/devices/").concat(n,"/remove")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.pushGateway,o=t.environment,i=void 0===o?"development":o,s=t.topic,a={type:r};return"apns2"===r&&delete(a=n(n({},a),{environment:i,topic:s})).type,a},handleResponse:function(){return{}}});var se=Object.freeze({__proto__:null,getOperation:function(){return j.PNUnsubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/leave")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(){return{}}});var ae=Object.freeze({__proto__:null,getOperation:function(){return j.PNWhereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r;return"/v2/presence/sub-key/".concat(n.subscribeKey,"/uuid/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return t.payload?{channels:t.payload.channels}:{channels:[]}}});var ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNHeartbeatOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/heartbeat")},isAuthSupported:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o=t.state,i=e.config,s={};return r.length>0&&(s["channel-group"]=r.join(",")),o&&(s.state=JSON.stringify(o)),s.heartbeat=i.getPresenceTimeout(),s},handleResponse:function(){return{}}});var ce=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetStateOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r,i=t.channels,s=void 0===i?[]:i,a=s.length>0?s.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(a),"/uuid/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a={};return 1===o.length&&0===s.length?a[o[0]]=t.payload:a=t.payload,{channels:a}}});var le=Object.freeze({__proto__:null,getOperation:function(){return j.PNSetStateOperation},validateParams:function(e,t){var n=e.config,r=t.state,o=t.channels,i=void 0===o?[]:o,s=t.channelGroups,a=void 0===s?[]:s;return r?n.subscribeKey?0===i.length&&0===a.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key":"Missing State"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/uuid/").concat(H.encodeString(n.UUID),"/data")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.state,r=t.channelGroups,o=void 0===r?[]:r,i={};return i.state=JSON.stringify(n),o.length>0&&(i["channel-group"]=o.join(",")),i},handleResponse:function(e,t){return{state:t.payload}}});var pe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=t.channelGroups,s=void 0===i?[]:i,a="/v2/presence/sub-key/".concat(n.subscribeKey);if(o.length>0||s.length>0){var u=o.length>0?o.join(","):",";a+="/channel/".concat(H.encodeString(u))}return a},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.channelGroups,o=void 0===r?[]:r,i=t.includeUUIDs,s=void 0===i||i,a=t.includeState,u=void 0!==a&&a,c=t.queryParameters,l=void 0===c?{}:c,p={};return s||(p.disable_uuids=1),u&&(p.state=1),o.length>0&&(p["channel-group"]=o.join(",")),p=n(n({},p),l)},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a=n.includeUUIDs,u=void 0===a||a,c=n.includeState,l=void 0!==c&&c;return o.length>1||s.length>0||0===s.length&&0===o.length?function(){var e={};return e.totalChannels=t.payload.total_channels,e.totalOccupancy=t.payload.total_occupancy,e.channels={},Object.keys(t.payload.channels).forEach((function(n){var r=t.payload.channels[n],o=[];return e.channels[n]={occupants:o,name:n,occupancy:r.occupancy},u&&r.uuids.forEach((function(e){l?o.push({state:e.state,uuid:e.uuid}):o.push({state:null,uuid:e})})),e})),e}():function(){var e={},n=[];return e.totalChannels=1,e.totalOccupancy=t.occupancy,e.channels={},e.channels[o[0]]={occupants:n,name:o[0],occupancy:t.occupancy},u&&t.uuids&&t.uuids.forEach((function(e){l?n.push({state:e.state,uuid:e.uuid}):n.push({state:null,uuid:e})})),e}()},handleError:function(e,t,n){402!==n.statusCode||this.getURL(e,t).includes("channel")||(n.errorData.message="You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.")}});var he=Object.freeze({__proto__:null,getOperation:function(){return j.PNAddMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.action,o=t.channel;return t.messageTimetoken?n.subscribeKey?o?r?r.value?r.type?r.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message channel":"Missing Subscribe Key":"Missing message timetoken"},usePost:function(){return!0},postURL:function(e,t){var n=e.config,r=t.channel,o=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},getRequestHeaders:function(){return{"Content-Type":"application/json"}},isAuthSupported:function(){return!0},prepareParams:function(){return{}},postPayload:function(e,t){return t.action},handleResponse:function(e,t){return{data:t.data}}});var fe=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken;return t.messageTimetoken?o?n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key":"Missing action timetoken":"Missing message timetoken"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken,i=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(i,"/action/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{data:t.data}}});var de=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetMessageActionsOperation},validateParams:function(e,t){var n=e.config,r=t.channel;return n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channel;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.limit,r=t.start,o=t.end,i={};return n&&(i.limit=n),r&&(i.start=r),o&&(i.end=o),i},handleResponse:function(e,t){var n={data:t.data,start:null,end:null};return n.data.length&&(n.end=n.data[n.data.length-1].actionTimetoken,n.start=n.data[0].actionTimetoken),n}}),ye={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel can't be empty"},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.limit&&(n.limit=t.limit),t.next&&(n.next=t.next),n},handleResponse:function(e,t){return{status:t.status,data:t.data,next:t.next,count:t.count}}},ge={getOperation:function(){return j.PNGenerateUploadUrlOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?void 0:"name can't be empty":"channel can't be empty"},usePost:function(){return!0},postURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/generate-upload-url")},postPayload:function(e,t){return{name:t.name}},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data,file_upload_request:t.file_upload_request}}},me={getOperation:function(){return j.PNPublishFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.fileId)?(null==t?void 0:t.fileName)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},getURL:function(e,t){var n=e.config,r=n.publishKey,o=n.subscribeKey,i=function(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}(e,{message:t.message,file:{name:t.fileName,id:t.fileId}});return"/v1/files/publish-file/".concat(r,"/").concat(o,"/0/").concat(H.encodeString(t.channel),"/0/").concat(H.encodeString(i))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.ttl&&(n.ttl=t.ttl),void 0!==t.storeInHistory&&(n.store=t.storeInHistory?"1":"0"),t.meta&&"object"==typeof t.meta&&(n.meta=JSON.stringify(t.meta)),n},handleResponse:function(e,t){return{timetoken:t[2]}}},be=function(e){var t=function(e){var t=this,n=e.generateUploadUrl,r=e.publishFile,s=e.modules,a=s.PubNubFile,u=s.config,c=s.cryptography,l=s.cryptoModule,p=s.networking;return function(e){var s=e.channel,h=e.file,f=e.message,d=e.cipherKey,y=e.meta,g=e.ttl,m=e.storeInHistory;return o(t,void 0,void 0,(function(){var e,t,o,b,v,_,S,w,O,P,E,A,T,N,C,k,M,j,R,x,U,I,D,F,L,G,K,B,H;return i(this,(function(i){switch(i.label){case 0:if(!s)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!h)throw new q("Validation failed, check status for details",z("file can't be empty"));return e=a.create(h),[4,n({channel:s,name:e.name})];case 1:return t=i.sent(),o=t.file_upload_request,b=o.url,v=o.form_fields,_=t.data,S=_.id,w=_.name,a.supportsEncryptFile&&(d||l)?null!=d?[3,3]:[4,l.encryptFile(e,a)]:[3,6];case 2:return O=i.sent(),[3,5];case 3:return[4,c.encryptFile(d,e,a)];case 4:O=i.sent(),i.label=5;case 5:e=O,i.label=6;case 6:P=v,e.mimeType&&(P=v.map((function(t){return"Content-Type"===t.key?{key:t.key,value:e.mimeType}:t}))),i.label=7;case 7:return i.trys.push([7,21,,22]),a.supportsFileUri&&h.uri?(T=(A=p).POSTFILE,N=[b,P],[4,e.toFileUri()]):[3,10];case 8:return[4,T.apply(A,N.concat([i.sent()]))];case 9:return E=i.sent(),[3,20];case 10:return a.supportsFile?(k=(C=p).POSTFILE,M=[b,P],[4,e.toFile()]):[3,13];case 11:return[4,k.apply(C,M.concat([i.sent()]))];case 12:return E=i.sent(),[3,20];case 13:return a.supportsBuffer?(R=(j=p).POSTFILE,x=[b,P],[4,e.toBuffer()]):[3,16];case 14:return[4,R.apply(j,x.concat([i.sent()]))];case 15:return E=i.sent(),[3,20];case 16:return a.supportsBlob?(I=(U=p).POSTFILE,D=[b,P],[4,e.toBlob()]):[3,19];case 17:return[4,I.apply(U,D.concat([i.sent()]))];case 18:return E=i.sent(),[3,20];case 19:throw new Error("Unsupported environment");case 20:return[3,22];case 21:throw(F=i.sent()).response&&"string"==typeof F.response.text?(L=F.response.text,G=/(.*)<\/Message>/gi.exec(L),new q(G?"Upload to bucket failed: ".concat(G[1]):"Upload to bucket failed.",F)):new q("Upload to bucket failed.",F);case 22:if(204!==E.status)throw new q("Upload to bucket was unsuccessful",E);K=u.fileUploadPublishRetryLimit,B=!1,H={timetoken:"0"},i.label=23;case 23:return i.trys.push([23,25,,26]),[4,r({channel:s,message:f,fileId:S,fileName:w,meta:y,storeInHistory:m,ttl:g})];case 24:return H=i.sent(),B=!0,[3,26];case 25:return i.sent(),K-=1,[3,26];case 26:if(!B&&K>0)return[3,23];i.label=27;case 27:if(B)return[2,{timetoken:H.timetoken,id:S,name:w}];throw new q("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{channel:s,id:S,name:w})}}))}))}}(e);return function(e,n){var r=t(e);return"function"==typeof n?(r.then((function(e){return n(null,e)})).catch((function(e){return n(e,null)})),r):r}},ve=function(e,t){var n=t.channel,r=t.id,o=t.name,i=e.config,s=e.networking,a=e.tokenManager;if(!n)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!r)throw new q("Validation failed, check status for details",z("file id can't be empty"));if(!o)throw new q("Validation failed, check status for details",z("file name can't be empty"));var u="/v1/files/".concat(i.subscribeKey,"/channels/").concat(H.encodeString(n),"/files/").concat(r,"/").concat(o),c={};c.uuid=i.getUUID(),c.pnsdk=W(i);var l=a.getToken()||i.getAuthKey();l&&(c.auth=l),i.secretKey&&$(e,u,c,{},{getOperation:function(){return"PubNubGetFileUrlOperation"}});var p=Object.keys(c).map((function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(c[e]))})).join("&");return""!==p?"".concat(s.getStandardOrigin()).concat(u,"?").concat(p):"".concat(s.getStandardOrigin()).concat(u)},_e={getOperation:function(){return j.PNDownloadFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?(null==t?void 0:t.id)?void 0:"id can't be empty":"name can't be empty":"channel can't be empty"},useGetFile:function(){return!0},getFileURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},ignoreBody:function(){return!0},forceBuffered:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t,n){var r=e.PubNubFile,s=e.config,a=e.cryptography,u=e.cryptoModule;return o(void 0,void 0,void 0,(function(){var e,o,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.response.body,r.supportsEncryptFile&&(n.cipherKey||u)?null!=n.cipherKey?[3,2]:[4,u.decryptFile(r.create({data:e,name:n.name}),r)]:[3,5];case 1:return o=i.sent().data,[3,4];case 2:return[4,a.decrypt(null!==(c=n.cipherKey)&&void 0!==c?c:s.cipherKey,e)];case 3:o=i.sent(),i.label=4;case 4:e=o,i.label=5;case 5:return[2,r.create({data:e,name:null!==(l=t.response.name)&&void 0!==l?l:n.name,mimeType:t.response.type})]}}))}))}},Se={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.id)?(null==t?void 0:t.name)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status}}},we={getOperation:function(){return j.PNGetAllUUIDMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,next:t.next,prev:t.prev}}},Oe={getOperation:function(){return j.PNGetUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Pe={getOperation:function(){return j.PNSetUUIDMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.data))return"Data cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ee={getOperation:function(){return j.PNRemoveUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r=e.config;return{uuid:null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ae={getOperation:function(){return j.PNGetAllChannelMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Te={getOperation:function(){return j.PNGetChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ne={getOperation:function(){return j.PNSetChannelMetadataOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.data)?void 0:"Data cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ce={getOperation:function(){return j.PNRemoveChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},ke={getOperation:function(){return j.PNGetMembersOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&m.include.push("uuid"),(null===(i=t.include)||void 0===i?void 0:i.customUUIDFields)&&m.include.push("uuid.custom"),(null===(s=t.include)||void 0===s?void 0:s.UUIDStatusField)&&m.include.push("uuid.status"),(null===(u=t.include)||void 0===u?void 0:u.UUIDTypeField)&&m.include.push("uuid.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Me={getOperation:function(){return j.PNSetMembersOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.uuids)&&0!==(null==t?void 0:t.uuids.length)?void 0:"UUIDs cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.uuids.map((function(e){return"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["uuid.status","uuid.type","type"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customUUIDFields)&&h.include.push("uuid.custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&h.include.push("uuid")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},je={getOperation:function(){return j.PNGetMembershipsOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&m.include.push("channel"),(null===(i=t.include)||void 0===i?void 0:i.customChannelFields)&&m.include.push("channel.custom"),(null===(s=t.include)||void 0===s?void 0:s.channelStatusField)&&m.include.push("channel.status"),(null===(u=t.include)||void 0===u?void 0:u.channelTypeField)&&m.include.push("channel.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Re={getOperation:function(){return j.PNSetMembershipsOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)||0===(null==t?void 0:t.channels.length))return"Channels cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.channels.map((function(e){return"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["channel.status","channel.type","status"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customChannelFields)&&h.include.push("channel.custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&h.include.push("channel")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}};var xe=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerAudit},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/audit/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channel,r=t.channelGroup,o=t.authKeys,i=void 0===o?[]:o,s={};return n&&(s.channel=n),r&&(s["channel-group"]=r),i.length>0&&(s.auth=i.join(",")),s},handleResponse:function(e,t){return t.payload}});var Ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrant},validateParams:function(e,t){var n=e.config;return n.subscribeKey?n.publishKey?n.secretKey?null==t.uuids||t.authKeys?null==t.uuids||null==t.channels&&null==t.channelGroups?void 0:"Both channel/channelgroup and uuid cannot be used in the same request":"authKeys are required for grant request on uuids":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/grant/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.uuids,a=void 0===s?[]:s,u=t.ttl,c=t.read,l=void 0!==c&&c,p=t.write,h=void 0!==p&&p,f=t.manage,d=void 0!==f&&f,y=t.get,g=void 0!==y&&y,m=t.join,b=void 0!==m&&m,v=t.update,_=void 0!==v&&v,S=t.authKeys,w=void 0===S?[]:S,O=t.delete,P={};return P.r=l?"1":"0",P.w=h?"1":"0",P.m=d?"1":"0",P.d=O?"1":"0",P.g=g?"1":"0",P.j=b?"1":"0",P.u=_?"1":"0",r.length>0&&(P.channel=r.join(",")),i.length>0&&(P["channel-group"]=i.join(",")),w.length>0&&(P.auth=w.join(",")),a.length>0&&(P["target-uuid"]=a.join(",")),(u||0===u)&&(P.ttl=u),P},handleResponse:function(){return{}}});function Ie(e){var t,n,r,o,i=void 0!==(null==e?void 0:e.authorizedUserId),s=void 0!==(null===(t=null==e?void 0:e.resources)||void 0===t?void 0:t.users),a=void 0!==(null===(n=null==e?void 0:e.resources)||void 0===n?void 0:n.spaces),u=void 0!==(null===(r=null==e?void 0:e.patterns)||void 0===r?void 0:r.users),c=void 0!==(null===(o=null==e?void 0:e.patterns)||void 0===o?void 0:o.spaces);return u||s||c||a||i}function De(e){var t=0;return e.join&&(t|=128),e.update&&(t|=64),e.get&&(t|=32),e.delete&&(t|=8),e.manage&&(t|=4),e.write&&(t|=2),e.read&&(t|=1),t}function Fe(e,t){if(Ie(t))return function(e,t){var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorizedUserId,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.users,c=r.spaces,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.users,h=o.spaces,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}(0,t);var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorized_uuid,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.uuids,c=r.channels,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.uuids,h=o.channels,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}var Le=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrantToken},extractPermissions:De,validateParams:function(e,t){var n,r,o,i,s,a,u=e.config;if(!u.subscribeKey)return"Missing Subscribe Key";if(!u.publishKey)return"Missing Publish Key";if(!u.secretKey)return"Missing Secret Key";if(!t.resources&&!t.patterns)return"Missing either Resources or Patterns.";var c=void 0!==(null==t?void 0:t.authorized_uuid),l=void 0!==(null===(n=null==t?void 0:t.resources)||void 0===n?void 0:n.uuids),p=void 0!==(null===(r=null==t?void 0:t.resources)||void 0===r?void 0:r.channels),h=void 0!==(null===(o=null==t?void 0:t.resources)||void 0===o?void 0:o.groups),f=void 0!==(null===(i=null==t?void 0:t.patterns)||void 0===i?void 0:i.uuids),d=void 0!==(null===(s=null==t?void 0:t.patterns)||void 0===s?void 0:s.channels),y=void 0!==(null===(a=null==t?void 0:t.patterns)||void 0===a?void 0:a.groups),g=c||l||f||p||d||h||y;return Ie(t)&&g?"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`":(!t.resources||t.resources.uuids&&0!==Object.keys(t.resources.uuids).length||t.resources.channels&&0!==Object.keys(t.resources.channels).length||t.resources.groups&&0!==Object.keys(t.resources.groups).length||t.resources.users&&0!==Object.keys(t.resources.users).length||t.resources.spaces&&0!==Object.keys(t.resources.spaces).length)&&(!t.patterns||t.patterns.uuids&&0!==Object.keys(t.patterns.uuids).length||t.patterns.channels&&0!==Object.keys(t.patterns.channels).length||t.patterns.groups&&0!==Object.keys(t.patterns.groups).length||t.patterns.users&&0!==Object.keys(t.patterns.users).length||t.patterns.spaces&&0!==Object.keys(t.patterns.spaces).length)?void 0:"Missing values for either Resources or Patterns."},postURL:function(e){var t=e.config;return"/v3/pam/".concat(t.subscribeKey,"/grant")},usePost:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(){return{}},postPayload:function(e,t){return Fe(0,t)},handleResponse:function(e,t){return t.data.token}}),Ge={getOperation:function(){return j.PNAccessManagerRevokeToken},validateParams:function(e,t){return e.config.secretKey?t?void 0:"token can't be empty":"Missing Secret Key"},getURL:function(e,t){var n=e.config;return"/v3/pam/".concat(n.subscribeKey,"/grant/").concat(H.encodeString(t))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e){return{uuid:e.config.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}};function Ke(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}var Be=Object.freeze({__proto__:null,getOperation:function(){return j.PNPublishOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},usePost:function(e,t){var n=t.sendByPost;return void 0!==n&&n},getURL:function(e,t){var n=e.config,r=t.channel,o=Ke(e,t.message);return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0/").concat(H.encodeString(o))},postURL:function(e,t){var n=e.config,r=t.channel;return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},postPayload:function(e,t){return Ke(e,t.message)},prepareParams:function(e,t){var n=t.meta,r=t.replicate,o=void 0===r||r,i=t.storeInHistory,s=t.ttl,a={};return null!=i&&(a.store=i?"1":"0"),s&&(a.ttl=s),!1===o&&(a.norep="true"),n&&"object"==typeof n&&(a.meta=JSON.stringify(n)),a},handleResponse:function(e,t){return{timetoken:t[2]}}});var He=Object.freeze({__proto__:null,getOperation:function(){return j.PNSignalOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},getURL:function(e,t){var n,r=e.config,o=t.channel,i=t.message,s=(n=i,JSON.stringify(n));return"/signal/".concat(r.publishKey,"/").concat(r.subscribeKey,"/0/").concat(H.encodeString(o),"/0/").concat(H.encodeString(s))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{timetoken:t[2]}}});var qe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHistoryOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channel,r=e.config;return"/v2/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o=t.reverse,i=t.count,s=void 0===i?100:i,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p={include_token:"true"};return p.count=s,n&&(p.start=n),r&&(p.end=r),u&&(p.string_message_token="true"),null!=o&&(p.reverse=o.toString()),l&&(p.include_meta="true"),p},handleResponse:function(e,t){var n={messages:[],startTimeToken:t[1],endTimeToken:t[2]};return Array.isArray(t[0])&&t[0].forEach((function(t){var r=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message),o={timetoken:t.timetoken,entry:r.payload};t.meta&&(o.meta=t.meta),r.error&&(o.error=r.error),n.messages.push(o)})),n}});var ze=Object.freeze({__proto__:null,getOperation:function(){return j.PNDeleteMessagesOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},useDelete:function(){return!0},getURL:function(e,t){var n=t.channel,r=e.config;return"/v3/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o={};return n&&(o.start=n),r&&(o.end=r),o},handleResponse:function(e,t){return t.payload}});var Ve=Object.freeze({__proto__:null,getOperation:function(){return j.PNMessageCounts},validateParams:function(e,t){var n=t.channels,r=t.timetoken,o=t.channelTimetokens,i=e.config;return n?r&&o?"timetoken and channelTimetokens are incompatible together":o&&o.length>1&&n.length!==o.length?"Length of channelTimetokens and channels do not match":i.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channels,r=e.config,o=n.join(",");return"/v3/history/sub-key/".concat(r.subscribeKey,"/message-counts/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.timetoken,r=t.channelTimetokens,o={};if(r&&1===r.length){var i=a(r,1)[0];o.timetoken=i}else r?o.channelsTimetoken=r.join(","):n&&(o.timetoken=n);return o},handleResponse:function(e,t){return{channels:t.channels}}});var We=Object.freeze({__proto__:null,getOperation:function(){return j.PNFetchMessagesOperation},validateParams:function(e,t){var n=t.channels,r=t.includeMessageActions,o=void 0!==r&&r,i=e.config;if(!n||0===n.length)return"Missing channels";if(!i.subscribeKey)return"Missing Subscribe Key";if(o&&n.length>1)throw new TypeError("History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.")},getURL:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.includeMessageActions,i=void 0!==o&&o,s=e.config,a=i?"history-with-actions":"history",u=r.length>0?r.join(","):",";return"/v3/".concat(a,"/sub-key/").concat(s.subscribeKey,"/channel/").concat(H.encodeString(u))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channels,r=t.start,o=t.end,i=t.includeMessageActions,s=t.count,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p=t.includeUuid,h=t.includeUUID,f=void 0===h||h,d=t.includeMessageType,y=void 0===d||d,g={};return g.max=s||(n.length>1||!0===i?25:100),r&&(g.start=r),o&&(g.end=o),u&&(g.string_message_token="true"),l&&(g.include_meta="true"),f&&!1!==p&&(g.include_uuid="true"),y&&(g.include_message_type="true"),g},handleResponse:function(e,t){var n={channels:{}};return Object.keys(t.channels||{}).forEach((function(r){n.channels[r]=[],(t.channels[r]||[]).forEach((function(t){var o={},i=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message);o.channel=r,o.timetoken=t.timetoken,o.message=i.payload,o.messageType=t.message_type,o.uuid=t.uuid,t.actions&&(o.actions=t.actions,o.data=t.actions),t.meta&&(o.meta=t.meta),i.error&&(o.error=i.error),n.channels[r].push(o)}))})),t.more&&(n.more=t.more),n}});var Je=Object.freeze({__proto__:null,getOperation:function(){return j.PNTimeOperation},getURL:function(){return"/time/0"},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(){return{}},isAuthSupported:function(){return!1},handleResponse:function(e,t){return{timetoken:t[0]}},validateParams:function(){}});var $e=Object.freeze({__proto__:null,getOperation:function(){return j.PNSubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=e.config,r=t.state,o=t.channelGroups,i=void 0===o?[]:o,s=t.timetoken,a=t.filterExpression,u=t.region,c={heartbeat:n.getPresenceTimeout()};return i.length>0&&(c["channel-group"]=i.join(",")),a&&a.length>0&&(c["filter-expr"]=a),Object.keys(r).length&&(c.state=JSON.stringify(r)),s&&(c.tt=s),u&&(c.tr=u),c},handleResponse:function(e,t){var n=[];t.m.forEach((function(e){var t={timetoken:e.p.t,region:e.p.r},r={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:t};n.push(r)}));var r={timetoken:t.t.t,region:t.t.r};return{messages:n,metadata:r}}}),Qe={getOperation:function(){return j.PNHandshakeOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)&&!(null==t?void 0:t.channelGroups))return"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),n.tt=0,t.state&&(n.state=JSON.stringify(t.state)),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.ee="",n},handleResponse:function(e,t){return{region:t.t.r,timetoken:t.t.t}}},Xe={getOperation:function(){return j.PNReceiveMessagesOperation},validateParams:function(e,t){return(null==t?void 0:t.channels)||(null==t?void 0:t.channelGroups)?(null==t?void 0:t.timetoken)?(null==t?void 0:t.region)?void 0:"region can not be empty":"timetoken can not be empty":"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},getAbortSignal:function(e,t){return t.abortSignal},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.tt=t.timetoken,n.tr=t.region,n.ee="",n},handleResponse:function(e,t){var n=[];return t.m.forEach((function(e){var t={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:{timetoken:e.p.t,region:e.p.r}};n.push(t)})),{messages:n,metadata:{region:t.t.r,timetoken:t.t.t}}}},Ye=function(){function e(e){void 0===e&&(e=!1),this.sync=e,this.listeners=new Set}return e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.notify=function(e){var t=this,n=function(){t.listeners.forEach((function(t){t(e)}))};this.sync?n():setTimeout(n,0)},e}(),Ze=function(){function e(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}return e.prototype.transition=function(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)},e.prototype.on=function(e,t){return this.transitionMap.set(e,t),this},e.prototype.with=function(e,t){return[this,e,null!=t?t:[]]},e.prototype.onEnter=function(e){return this.enterEffects.push(e),this},e.prototype.onExit=function(e){return this.exitEffects.push(e),this},e}(),et=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return t(n,e),n.prototype.describe=function(e){return new Ze(e)},n.prototype.start=function(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})},n.prototype.transition=function(e){var t,n,r,o,i,u;if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});var c=this.currentState.transition(this.currentContext,e);if(c){var l=a(c,3),p=l[0],h=l[1],f=l[2];try{for(var d=s(this.currentState.exitEffects),y=d.next();!y.done;y=d.next()){var g=y.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}var m=this.currentState;this.currentState=p;var b=this.currentContext;this.currentContext=h,this.notify({type:"transitionDone",fromState:m,fromContext:b,toState:p,toContext:h,event:e});try{for(var v=s(f),_=v.next();!_.done;_=v.next()){g=_.value;this.notify({type:"invocationDispatched",invocation:g})}}catch(e){r={error:e}}finally{try{_&&!_.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var S=s(this.currentState.enterEffects),w=S.next();!w.done;w=S.next()){g=w.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){i={error:e}}finally{try{w&&!w.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}},n}(Ye),tt=function(){function e(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}return e.prototype.on=function(e,t){this.handlers.set(e,t)},e.prototype.dispatch=function(e){if("CANCEL"!==e.type){var t=this.handlers.get(e.type);if(!t)throw new Error("Unhandled invocation '".concat(e.type,"'"));var n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}else if(this.instances.has(e.payload)){var r=this.instances.get(e.payload);null==r||r.cancel(),this.instances.delete(e.payload)}},e.prototype.dispose=function(){var e,t;try{for(var n=s(this.instances.entries()),r=n.next();!r.done;r=n.next()){var o=a(r.value,2),i=o[0];o[1].cancel(),this.instances.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();function nt(e,t){var n=function(){for(var n=[],r=0;r0&&r(e),[2]}))}))}))),s.on(ht.type,ut((function(e,t,n){var r=n.emitStatus;return o(s,void 0,void 0,(function(){return i(this,(function(t){return r(e),[2]}))}))}))),s.on(ft.type,ut((function(e,n,r){var a=r.receiveMessages,u=r.delay,c=r.config;return o(s,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return c.retryConfiguration&&c.retryConfiguration.shouldRetry(e.reason,e.attempts)?(n.throwIfAborted(),[4,u(c.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),n.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,a({abortSignal:n,channels:e.channels,channelGroups:e.groups,timetoken:e.cursor.timetoken,region:e.cursor.region,filterExpression:c.filterExpression})];case 3:return r=i.sent(),[2,t.transition(Pt(r.metadata,r.messages))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Et(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(At(new q(c.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s.on(dt.type,ut((function(e,r,a){var u=a.handshake,c=a.delay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({abortSignal:r,channels:e.channels,channelGroups:e.groups,filterExpression:p.filterExpression},p.maintainPresenceState&&{state:l}))];case 3:return o=i.sent(),[2,t.transition(vt(o))];case 4:return(s=i.sent())instanceof Error&&"Aborted"===s.message?[2]:s instanceof q?[2,t.transition(_t(s))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(St(new q(p.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s}return t(r,e),r}(tt),Mt=new Ze("HANDSHAKE_FAILED");Mt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Mt.on(Nt.type,(function(e,t){return Ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor})})),Mt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(r=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==r?r:0}})})),Mt.on(Ct.type,(function(e){return Lt.with()}));var jt=new Ze("HANDSHAKE_STOPPED");jt.on(yt.type,(function(e,t){return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),jt.on(Nt.type,(function(e,t){return Ft.with(n(n({},e),{cursor:t.payload.cursor||e.cursor}))})),jt.on(gt.type,(function(e,t){var n;return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),jt.on(Ct.type,(function(e){return Lt.with()}));var Rt=new Ze("RECEIVE_FAILED");Rt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Rt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(Ct.type,(function(e){return Lt.with(void 0)}));var xt=new Ze("RECEIVE_STOPPED");xt.on(yt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),xt.on(gt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Ct.type,(function(){return Lt.with(void 0)}));var Ut=new Ze("RECEIVE_RECONNECTING");Ut.onEnter((function(e){return ft(e)})),Ut.onExit((function(){return ft.cancel})),Ut.on(Pt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),Ut.on(Et.type,(function(e,t){return Ut.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Ut.on(At.type,(function(e,t){var n;return Rt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Ut.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),Ut.on(gt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Ut.on(yt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ut.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var It=new Ze("RECEIVING");It.onEnter((function(e){return lt(e.channels,e.groups,e.cursor)})),It.onExit((function(){return lt.cancel})),It.on(wt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),It.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups})})),It.on(gt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),It.on(Ot.type,(function(e,t){return Ut.with(n(n({},e),{attempts:0,reason:t.payload}))})),It.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),It.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var Dt=new Ze("HANDSHAKE_RECONNECTING");Dt.onEnter((function(e){return dt(e)})),Dt.onExit((function(){return dt.cancel})),Dt.on(vt.type,(function(e,t){var n,r,o={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=e.cursor)||void 0===r?void 0:r.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return It.with({channels:e.channels,groups:e.groups,cursor:o},[ht({category:k.PNConnectedCategory})])})),Dt.on(_t.type,(function(e,t){return Dt.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Dt.on(St.type,(function(e,t){var n;return Mt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Dt.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Dt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Dt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.region)||0}})})),Dt.on(Ct.type,(function(e){return Lt.with(void 0)}));var Ft=new Ze("HANDSHAKING");Ft.onEnter((function(e){return ct(e.channels,e.groups)})),Ft.onExit((function(){return ct.cancel})),Ft.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ft.on(mt.type,(function(e,t){var n,r;return It.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.timetoken:t.payload.timetoken,region:t.payload.region}},[ht({category:k.PNConnectedCategory})])})),Ft.on(bt.type,(function(e,t){return Dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload})})),Ft.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Ft.on(gt.type,(function(e,t){var n;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),Ft.on(Ct.type,(function(e){return Lt.with()}));var Lt=new Ze("UNSUBSCRIBED");Lt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups})})),Lt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})}));var Gt=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new kt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(Lt,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e){var t=this,n=e.channels,r=e.channelGroups,o=e.timetoken,i=e.withPresence;this.channels=u(u([],a(this.channels),!1),a(null!=n?n:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=r?r:[]),!1),i&&(this.channels.map((function(e){return t.channels.push("".concat(e,"-pnpres"))})),this.groups.map((function(e){return t.groups.push("".concat(e,"-pnpres"))}))),o?this.engine.transition(gt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))),o)):this.engine.transition(yt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((function(e){return!e.endsWith("-pnpres")})))),groups:Array.from(new Set(this.groups.filter((function(e){return!e.endsWith("-pnpres")}))))})},e.prototype.unsubscribe=function(e){var t=this,n=e.channels,r=void 0===n?[]:n,o=e.channelGroups,i=void 0===o?[]:o,s=H.removeSingleOccurance(this.channels,u(u([],a(r),!1),a(r.map((function(e){return"".concat(e,"-pnpres")}))),!1)),c=H.removeSingleOccurance(this.groups,u(u([],a(i),!1),a(i.map((function(e){return"".concat(e,"-pnpres")}))),!1));if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(c).size){var l=H.findUniqueCommonElements(this.channels,r),p=H.findUniqueCommonElements(this.groups,i);this.dependencies.presenceState&&(null==l||l.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==p||p.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.channels=s,this.groups=c,this.engine.transition(yt(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:l.slice(0),groups:p.slice(0)})}},e.prototype.unsubscribeAll=function(){this.channels=[],this.groups=[],this.dependencies.presenceState&&(this.dependencies.presenceState={}),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.reconnect=function(e){var t=e.timetoken,n=e.region;this.engine.transition(Nt(t,n))},e.prototype.disconnect=function(){this.engine.transition(Tt()),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.getSubscribedChannels=function(){return Array.from(new Set(this.channels))},e.prototype.getSubscribedChannelGroups=function(){return Array.from(new Set(this.groups))},e.prototype.dispose=function(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),Kt=nt("RECONNECT",(function(){return{}})),Bt=nt("DISCONNECT",(function(){return{}})),Ht=nt("JOINED",(function(e,t){return{channels:e,groups:t}})),qt=nt("LEFT",(function(e,t){return{channels:e,groups:t}})),zt=nt("LEFT_ALL",(function(){return{}})),Vt=nt("HEARTBEAT_SUCCESS",(function(e){return{statusCode:e}})),Wt=nt("HEARTBEAT_FAILURE",(function(e){return e})),Jt=nt("HEARTBEAT_GIVEUP",(function(){return{}})),$t=nt("TIMES_UP",(function(){return{}})),Qt=rt("HEARTBEAT",(function(e,t){return{channels:e,groups:t}})),Xt=rt("LEAVE",(function(e,t){return{channels:e,groups:t}})),Yt=rt("EMIT_STATUS",(function(e){return e})),Zt=ot("WAIT",(function(){return{}})),en=ot("DELAYED_HEARTBEAT",(function(e){return e})),tn=function(e){function r(t,r){var s=e.call(this,r)||this;return s.on(Qt.type,ut((function(e,r,a){var u=a.heartbeat,c=a.presenceState,l=a.config;return o(s,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,u(n({channels:e.channels,channelGroups:e.groups},l.maintainPresenceState&&{state:c}))];case 1:return o.sent(),t.transition(Vt(200)),[3,3];case 2:return(r=o.sent())instanceof q?[2,t.transition(Wt(r))]:[3,3];case 3:return[2]}}))}))}))),s.on(Xt.type,ut((function(e,t,n){var r=n.leave,a=n.config;return o(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:if(a.suppressLeaveEvents)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r({channels:e.channels,channelGroups:e.groups})];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}}))}))}))),s.on(Zt.type,ut((function(e,n,r){var a=r.heartbeatDelay;return o(s,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return n.throwIfAborted(),[4,a()];case 1:return e.sent(),n.throwIfAborted(),[2,t.transition($t())]}}))}))}))),s.on(en.type,ut((function(e,r,a){var u=a.heartbeat,c=a.retryDelay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({channels:e.channels,channelGroups:e.groups},p.maintainPresenceState&&{state:l}))];case 3:return i.sent(),[2,t.transition(Vt(200))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Wt(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Jt())];case 7:return[2]}}))}))}))),s.on(Yt.type,ut((function(e,t,r){var a=r.emitStatus,u=r.config;return o(s,void 0,void 0,(function(){var t;return i(this,(function(r){return u.announceFailedHeartbeats&&!0===(null===(t=null==e?void 0:e.status)||void 0===t?void 0:t.error)?a(e.status):u.announceSuccessfulHeartbeats&&200===e.statusCode&&a(n(n({},e),{operation:j.PNHeartbeatOperation,error:!1})),[2]}))}))}))),s}return t(r,e),r}(tt),nn=new Ze("HEARTBEAT_STOPPED");nn.on(Ht.type,(function(e,t){return nn.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),nn.on(qt.type,(function(e,t){return nn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))})})),nn.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),nn.on(zt.type,(function(e,t){return un.with(void 0)}));var rn=new Ze("HEARTBEAT_COOLDOWN");rn.onEnter((function(){return Zt()})),rn.onExit((function(){return Zt.cancel})),rn.on($t.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),rn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),rn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),rn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),rn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var on=new Ze("HEARTBEAT_FAILED");on.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),on.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),on.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),on.on(Bt.type,(function(e,t){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),on.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var sn=new Ze("HEARBEAT_RECONNECTING");sn.onEnter((function(e){return en(e)})),sn.onExit((function(){return en.cancel})),sn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),sn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),sn.on(Bt.type,(function(e,t){nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),sn.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),sn.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),sn.on(Jt.type,(function(e,t){return on.with({channels:e.channels,groups:e.groups})})),sn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var an=new Ze("HEARTBEATING");an.onEnter((function(e){return Qt(e.channels,e.groups)})),an.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),an.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),an.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),an.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:0,reason:t.payload}))})),an.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),an.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var un=new Ze("HEARTBEAT_INACTIVE");un.on(Ht.type,(function(e,t){return an.with({channels:t.payload.channels,groups:t.payload.groups})}));var cn=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dispatcher=new tn(this.engine,e),this.dependencies=e,this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(un,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.join=function(e){var t=e.channels,n=e.groups;this.channels=u(u([],a(this.channels),!1),a(null!=t?t:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=n?n:[]),!1),this.engine.transition(Ht(this.channels.slice(0),this.groups.slice(0)))},e.prototype.leave=function(e){var t=this,n=e.channels,r=e.groups;this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(qt(null!=n?n:[],null!=r?r:[]))},e.prototype.leaveAll=function(){this.engine.transition(zt())},e.prototype.dispose=function(){this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),ln=function(){function e(){}return e.LinearRetryPolicy=function(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e.ExponentialRetryPolicy=function(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e}(),pn=function(){function e(e){var t=e.modules,n=e.listenerManager,r=e.getFileUrl;this.modules=t,this.listenerManager=n,this.getFileUrl=r,this._channelListenerMap=new Map,this._groupListenerMap=new Map,t.cryptoModule&&(this._decoder=new TextDecoder)}return e.prototype.emitEvent=function(e){var t=e.channel,o=e.publishMetaData,i=e.subscriptionMatch;if(t===i&&(i=null),e.channel.endsWith("-pnpres")){var s={channel:null,subscription:null};t&&(s.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(s.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),s.action=e.payload.action,s.state=e.payload.data,s.timetoken=o.timetoken,s.occupancy=e.payload.occupancy,s.uuid=e.payload.uuid,s.timestamp=e.payload.timestamp,e.payload.join&&(s.join=e.payload.join),e.payload.leave&&(s.leave=e.payload.leave),e.payload.timeout&&(s.timeout=e.payload.timeout),s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announcePresence(s),this._announce("presence",s,s.channel,s.subscription)}else if(1===e.messageType){(s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=e.payload,this.listenerManager.announceSignal(s),this._announce("signal",s,s.channel,s.subscription)}else if(2===e.messageType){if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},this.listenerManager.announceObjects(s),this._announce("objects",s,s.channel,s.subscription),"uuid"===e.payload.type){var a=this._renameChannelField(s),u=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"user"})});this.listenerManager.announceUser(u),this._announce("user",u,s.channel,s.subscription)}else if("channel"===e.payload.type){a=this._renameChannelField(s);var c=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"space"})});this.listenerManager.announceSpace(c),this._announce("space",c,s.channel,s.subscription)}else if("membership"===e.payload.type){var l=(a=this._renameChannelField(s)).message.data,p=l.uuid,h=l.channel,f=r(l,["uuid","channel"]);f.user=p,f.space=h;var d=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),data:f})});this.listenerManager.announceMembership(d),this._announce("membership",d,s.channel,s.subscription)}}else if(3===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,s.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},s.event=e.payload.event,this.listenerManager.announceMessageAction(s),this._announce("messageAction",s,s.channel,s.subscription)}else if(4===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId;var y=e.payload;if(this.modules.cryptoModule){var g=void 0;try{g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}null!==g&&(y=g)}e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=y.message,s.file={id:y.file.id,name:y.file.name,url:this.getFileUrl({id:y.file.id,name:y.file.name,channel:t})},this.listenerManager.announceFile(s),this._announce("file",s,s.channel,s.subscription)}else{if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),this.modules.cryptoModule){g=void 0;try{var m;g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}s.message=null!=g?g:e.payload}else s.message=e.payload;s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announceMessage(s),this._announce("message",s,s.channel,s.subscription)}},e.prototype.addListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){r._channelListenerMap[t]?r._channelListenerMap[t].includes(e)||r._channelListenerMap[t].push(e):r._channelListenerMap[t]=[e]})),null==n||n.forEach((function(t){r._groupListenerMap[t]?r._groupListenerMap[t].includes(e)||r._groupListenerMap[t].push(e):r._groupListenerMap[t]=[e]}))):this.listenerManager.addListener(e)},e.prototype.removeListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){var n;r._channelListenerMap[t]=null===(n=r._channelListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))})),null==n||n.forEach((function(t){var n;r._groupListenerMap[t]=null===(n=r._groupListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))}))):this.listenerManager.removeListener(e)},e.prototype.removeAllListeners=function(){this.listenerManager.removeAllListeners()},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e.prototype._announce=function(e,t,n,r){var o,i;null===(o=this._channelListenerMap[n])||void 0===o||o.forEach((function(n){return n[e]&&n[e](t)})),null===(i=this._groupListenerMap[r])||void 0===i||i.forEach((function(n){return n[e]&&n[e](t)}))},e}(),hn=function(){function e(){}return e.prototype.subscribe=function(){var e,t;this.pubnub.subscribe(n({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))},e.prototype.unsubscribe=function(){this.pubnub.unsubscribe({channels:this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),channelGroups:this.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))})},Object.defineProperty(e.prototype,"onMessage",{set:function(e){this.listener.message=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onPresence",{set:function(e){this.listener.presence=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onSignal",{set:function(e){this.listener.signal=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onObjects",{set:function(e){this.listener.objects=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onMessageAction",{set:function(e){this.listener.messageAction=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onFile",{set:function(e){this.listener.file=e},enumerable:!1,configurable:!0}),e.prototype.addListener=function(e){this.eventEmitter.addListener(e,this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),this.groupNames.filter((function(e){return!e.endsWith("-pnpres")})))},e.prototype.removeListener=function(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)},Object.defineProperty(e.prototype,"channels",{get:function(){return this.channelNames.slice(0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"channelGroups",{get:function(){return this.groupNames.slice(0)},enumerable:!1,configurable:!0}),e}(),fn=function(e){function n(t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.subscriptionOptions,c=t.eventEmitter,l=t.pubnub,p=e.call(this)||this;return p.channelNames=[],p.groupNames=[],p.subscriptionList=[],p.options=s,p.eventEmitter=c,p.pubnub=l,r.forEach((function(e){var t=p.pubnub.channel(e).subscription(p.options);p.channelNames=u(u([],a(p.channelNames),!1),a(t.channels),!1),p.subscriptionList.push(t)})),i.forEach((function(e){var t=p.pubnub.channelGroup(e).subscription(p.options);p.groupNames=u(u([],a(p.groupNames),!1),a(t.channelGroups),!1),p.subscriptionList.push(t)})),p.listener={},c.addListener(p.listener,p.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),p.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),p}return t(n,e),n.prototype.addSubscription=function(e){this.subscriptionList.push(e),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscription=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return t!==e}))},n.prototype.addSubscriptionSet=function(e){this.subscriptionList=u(u([],a(this.subscriptionList),!1),a(e.subscriptions),!1),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1)},n.prototype.removeSubscriptionSet=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return!e.subscriptions.includes(t)}))},Object.defineProperty(n.prototype,"subscriptions",{get:function(){return this.subscriptionList.slice(0)},enumerable:!1,configurable:!0}),n}(hn),dn=function(e){function r(t){var n=t.channels,r=t.channelGroups,o=t.subscriptionOptions,i=t.eventEmitter,s=t.pubnub,a=e.call(this)||this;return a.channelNames=[],a.groupNames=[],a.channelNames=n,a.groupNames=r,a.options=o,a.pubnub=s,a.eventEmitter=i,a.listener={},i.addListener(a.listener,a.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),a.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),a}return t(r,e),r.prototype.addSubscription=function(e){return new fn({channels:u(u([],a(this.channelNames),!1),a(e.channels),!1),channelGroups:u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),subscriptionOptions:n(n({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})},r}(hn),yn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),gn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),mn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),bn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),vn=function(){function e(e){var t=this,r=e.networking,o=e.cbor,i=new g({setup:e});this._config=i;var c=new T({config:i}),l=e.cryptography;r.init(i);var p=new G(i,o);this._tokenManager=p;var h=new R({maximumSamplesCount:6e4});this._telemetryManager=h;var f=this._config.cryptoModule,d={config:i,networking:r,crypto:c,cryptography:l,tokenManager:p,telemetryManager:h,PubNubFile:e.PubNubFile,cryptoModule:f};this.File=e.PubNubFile,this.encryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.encryptFile(t,this.File)):l.encryptFile(e,t,this.File)},this.decryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.decryptFile(t,this.File)):l.decryptFile(e,t,this.File)};var y=Q.bind(this,d,Je),m=Q.bind(this,d,se),v=Q.bind(this,d,ue),_=Q.bind(this,d,le),S=Q.bind(this,d,$e),w=new L;if(this._listenerManager=w,this.iAmHere=Q.bind(this,d,ue),this.iAmAway=Q.bind(this,d,se),this.setPresenceState=Q.bind(this,d,le),this.handshake=Q.bind(this,d,Qe),this.receiveMessages=Q.bind(this,d,Xe),this._eventEmitter=new pn({modules:d,listenerManager:this._listenerManager,getFileUrl:function(e){return ve(d,e)}}),!0===i.enableEventEngine){if(i.maintainPresenceState&&(this.presenceState={},this.setState=function(e){var n,r;return null===(n=e.channels)||void 0===n||n.forEach((function(n){return t.presenceState[n]=e.state})),null===(r=e.channelGroups)||void 0===r||r.forEach((function(n){return t.presenceState[n]=e.state})),t.setPresenceState({channels:e.channels,channelGroups:e.channelGroups,state:t.presenceState})}),i.getHeartbeatInterval()){var O=new cn({heartbeat:this.iAmHere,leave:this.iAmAway,heartbeatDelay:function(){return new Promise((function(e){return setTimeout(e,1e3*d.config.getHeartbeatInterval())}))},retryDelay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},config:d.config,presenceState:this.presenceState,emitStatus:function(e){w.announceStatus(e)}});this.presenceEventEngine=O,this.join=this.presenceEventEngine.join.bind(O),this.leave=this.presenceEventEngine.leave.bind(O),this.leaveAll=this.presenceEventEngine.leaveAll.bind(O)}var P=new Gt({handshake:this.handshake,receiveMessages:this.receiveMessages,delay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},join:this.join,leave:this.leave,leaveAll:this.leaveAll,presenceState:this.presenceState,config:d.config,emitMessages:function(e){var n,r;try{for(var o=s(e),i=o.next();!i.done;i=o.next()){var a=i.value;t._eventEmitter.emitEvent(a)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},emitStatus:function(e){w.announceStatus(e)}});this.subscribe=P.subscribe.bind(P),this.unsubscribe=P.unsubscribe.bind(P),this.unsubscribeAll=P.unsubscribeAll.bind(P),this.reconnect=P.reconnect.bind(P),this.disconnect=P.disconnect.bind(P),this.destroy=P.dispose.bind(P),this.getSubscribedChannels=P.getSubscribedChannels.bind(P),this.getSubscribedChannelGroups=P.getSubscribedChannelGroups.bind(P),this.eventEngine=P}else{var E=new M({timeEndpoint:y,leaveEndpoint:m,heartbeatEndpoint:v,setStateEndpoint:_,subscribeEndpoint:S,crypto:d.crypto,config:d.config,listenerManager:w,getFileUrl:function(e){return ve(d,e)},cryptoModule:d.cryptoModule,eventEmitter:this._eventEmitter});this.subscribe=E.adaptSubscribeChange.bind(E),this.unsubscribe=E.adaptUnsubscribeChange.bind(E),this.disconnect=E.disconnect.bind(E),this.reconnect=E.reconnect.bind(E),this.unsubscribeAll=E.unsubscribeAll.bind(E),this.getSubscribedChannels=E.getSubscribedChannels.bind(E),this.getSubscribedChannelGroups=E.getSubscribedChannelGroups.bind(E),this.setState=E.adaptStateChange.bind(E),this.presence=E.adaptPresenceChange.bind(E),this.destroy=function(e){E.unsubscribeAll(e),E.disconnect()}}this.addListener=this._eventEmitter.addListener.bind(this._eventEmitter),this.removeListener=this._eventEmitter.removeListener.bind(this._eventEmitter),this.removeAllListeners=this._eventEmitter.removeAllListeners.bind(this._eventEmitter),this.parseToken=p.parseToken.bind(p),this.setToken=p.setToken.bind(p),this.getToken=p.getToken.bind(p),this.channelGroups={listGroups:Q.bind(this,d,ee),listChannels:Q.bind(this,d,te),addChannels:Q.bind(this,d,X),removeChannels:Q.bind(this,d,Y),deleteGroup:Q.bind(this,d,Z)},this.push={addChannels:Q.bind(this,d,ne),removeChannels:Q.bind(this,d,re),deleteDevice:Q.bind(this,d,ie),listChannels:Q.bind(this,d,oe)},this.hereNow=Q.bind(this,d,pe),this.whereNow=Q.bind(this,d,ae),this.getState=Q.bind(this,d,ce),this.grant=Q.bind(this,d,Ue),this.grantToken=Q.bind(this,d,Le),this.audit=Q.bind(this,d,xe),this.revokeToken=Q.bind(this,d,Ge),this.publish=Q.bind(this,d,Be),this.fire=function(e,n){return e.replicate=!1,e.storeInHistory=!1,t.publish(e,n)},this.signal=Q.bind(this,d,He),this.history=Q.bind(this,d,qe),this.deleteMessages=Q.bind(this,d,ze),this.messageCounts=Q.bind(this,d,Ve),this.fetchMessages=Q.bind(this,d,We),this.addMessageAction=Q.bind(this,d,he),this.removeMessageAction=Q.bind(this,d,fe),this.getMessageActions=Q.bind(this,d,de),this.listFiles=Q.bind(this,d,ye);var A=Q.bind(this,d,ge);this.publishFile=Q.bind(this,d,me),this.sendFile=be({generateUploadUrl:A,publishFile:this.publishFile,modules:d}),this.getFileUrl=function(e){return ve(d,e)},this.downloadFile=Q.bind(this,d,_e),this.deleteFile=Q.bind(this,d,Se),this.channel=function(e){return new yn(e,t._eventEmitter,t)},this.channelGroup=function(e){return new gn(e,t._eventEmitter,t)},this.channelMetadata=function(e){return new mn(e,t._eventEmitter,t)},this.userMetadata=function(e){return new bn(e,t._eventEmitter,t)},this.subscriptionSet=function(e){return new fn({channels:e.channels,channelGroups:e.channelGroups,subscriptionOptions:e.subscriptionOptions,eventEmitter:t._eventEmitter,pubnub:t})},this.objects={getAllUUIDMetadata:Q.bind(this,d,we),getUUIDMetadata:Q.bind(this,d,Oe),setUUIDMetadata:Q.bind(this,d,Pe),removeUUIDMetadata:Q.bind(this,d,Ee),getAllChannelMetadata:Q.bind(this,d,Ae),getChannelMetadata:Q.bind(this,d,Te),setChannelMetadata:Q.bind(this,d,Ne),removeChannelMetadata:Q.bind(this,d,Ce),getChannelMembers:Q.bind(this,d,ke),setChannelMembers:function(e){for(var r=[],o=1;o=this._config.origin.length&&(this._currentSubDomain=0);var t=this._config.origin[this._currentSubDomain];return"".concat(e).concat(t)},e.prototype.hasModule=function(e){return e in this._modules},e.prototype.shiftStandardOrigin=function(){return this._standardOrigin=this.nextOrigin(),this._standardOrigin},e.prototype.getStandardOrigin=function(){return this._standardOrigin},e.prototype.POSTFILE=function(e,t,n){return this._modules.postfile(e,t,n)},e.prototype.GETFILE=function(e,t,n){return this._modules.getfile(e,t,n)},e.prototype.POST=function(e,t,n,r){return this._modules.post(e,t,n,r)},e.prototype.PATCH=function(e,t,n,r){return this._modules.patch(e,t,n,r)},e.prototype.GET=function(e,t,n){return this._modules.get(e,t,n)},e.prototype.DELETE=function(e,t,n){return this._modules.del(e,t,n)},e.prototype._detectErrorCategory=function(e){if("ENOTFOUND"===e.code)return k.PNNetworkIssuesCategory;if("ECONNREFUSED"===e.code)return k.PNNetworkIssuesCategory;if("ECONNRESET"===e.code)return k.PNNetworkIssuesCategory;if("EAI_AGAIN"===e.code)return k.PNNetworkIssuesCategory;if(0===e.status||e.hasOwnProperty("status")&&void 0===e.status)return k.PNNetworkIssuesCategory;if(e.timeout)return k.PNTimeoutCategory;if("ETIMEDOUT"===e.code)return k.PNNetworkIssuesCategory;if(e.response){if(e.response.badRequest)return k.PNBadRequestCategory;if(e.response.forbidden)return k.PNAccessDeniedCategory}return k.PNUnknownCategory},e}();function Sn(e){var t=function(e){return e&&"object"==typeof e&&e.constructor===Object};if(!t(e))return e;var n={};return Object.keys(e).forEach((function(r){var o=function(e){return"string"==typeof e||e instanceof String}(r),i=r,s=e[r];Array.isArray(r)||o&&r.indexOf(",")>=0?i=(o?r.split(","):r).reduce((function(e,t){return e+=String.fromCharCode(t)}),""):(function(e){return"number"==typeof e&&isFinite(e)}(r)||o&&!isNaN(r))&&(i=String.fromCharCode(o?parseInt(r,10):10));n[i]=t(s)?Sn(s):s})),n}var wn=function(){function e(e,t){this._base64ToBinary=t,this._decode=e}return e.prototype.decodeToken=function(e){var t="";e.length%4==3?t="=":e.length%4==2&&(t="==");var n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,r=this._decode(this._base64ToBinary(n));if("object"==typeof r)return r},e}(),On={exports:{}},Pn={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;os.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;at?1:0}function Un(e,t,n,r){void 0===r&&(r=kn());var o,i=In(e,"",0,[],void 0,0,r)||e;try{o=0===Cn.length?JSON.stringify(i,t,n):JSON.stringify(i,Dn(t),n)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==Nn.length;){var s=Nn.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return o}function In(e,t,n,r,o,i,s){var a;if(i+=1,"object"==typeof e&&null!==e){for(a=0;as.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;a0)for(var r=0;r1&&"boolean"!=typeof t)throw new Qn('"allowMissing" argument must be a boolean');var n=gr(e),r=n.length>0?n[0]:"",o=mr("%"+r+"%",t),i=o.name,s=o.value,a=!1,u=o.alias;u&&(r=u[0],pr(n,lr([0,1],u)));for(var c=1,l=!0;c=n.length){var d=Yn(s,p);s=(l=!!d)&&"get"in d&&!("originalValue"in d.get)?d.get:s[p]}else l=cr(s,p),s=s[p];l&&!a&&(ir[i]=s)}}return s},vr={exports:{}};!function(e){var t=Vn,n=br,r=n("%Function.prototype.apply%"),o=n("%Function.prototype.call%"),i=n("%Reflect.apply%",!0)||t.call(o,r),s=n("%Object.getOwnPropertyDescriptor%",!0),a=n("%Object.defineProperty%",!0),u=n("%Math.max%");if(a)try{a({},"a",{value:1})}catch(e){a=null}e.exports=function(e){var n=i(t,o,arguments);if(s&&a){var r=s(n,"length");r.configurable&&a(n,"length",{value:1+u(0,e.length-(arguments.length-1))})}return n};var c=function(){return i(t,r,arguments)};a?a(e.exports,"apply",{value:c}):e.exports.apply=c}(vr);var _r=br,Sr=vr.exports,wr=Sr(_r("String.prototype.indexOf")),Or=l(Object.freeze({__proto__:null,default:{}})),Pr="function"==typeof Map&&Map.prototype,Er=Object.getOwnPropertyDescriptor&&Pr?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ar=Pr&&Er&&"function"==typeof Er.get?Er.get:null,Tr=Pr&&Map.prototype.forEach,Nr="function"==typeof Set&&Set.prototype,Cr=Object.getOwnPropertyDescriptor&&Nr?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,kr=Nr&&Cr&&"function"==typeof Cr.get?Cr.get:null,Mr=Nr&&Set.prototype.forEach,jr="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Rr="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,xr="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Ur=Boolean.prototype.valueOf,Ir=Object.prototype.toString,Dr=Function.prototype.toString,Fr=String.prototype.match,Lr=String.prototype.slice,Gr=String.prototype.replace,Kr=String.prototype.toUpperCase,Br=String.prototype.toLowerCase,Hr=RegExp.prototype.test,qr=Array.prototype.concat,zr=Array.prototype.join,Vr=Array.prototype.slice,Wr=Math.floor,Jr="function"==typeof BigInt?BigInt.prototype.valueOf:null,$r=Object.getOwnPropertySymbols,Qr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,Xr="function"==typeof Symbol&&"object"==typeof Symbol.iterator,Yr="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xr||"symbol")?Symbol.toStringTag:null,Zr=Object.prototype.propertyIsEnumerable,eo=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function to(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||Hr.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var r=e<0?-Wr(-e):Wr(e);if(r!==e){var o=String(r),i=Lr.call(t,o.length+1);return Gr.call(o,n,"$&_")+"."+Gr.call(Gr.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Gr.call(t,n,"$&_")}var no=Or,ro=no.custom,oo=co(ro)?ro:null;function io(e,t,n){var r="double"===(n.quoteStyle||t)?'"':"'";return r+e+r}function so(e){return Gr.call(String(e),/"/g,""")}function ao(e){return!("[object Array]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function uo(e){return!("[object RegExp]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function co(e){if(Xr)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!Qr)return!1;try{return Qr.call(e),!0}catch(e){}return!1}var lo=Object.prototype.hasOwnProperty||function(e){return e in this};function po(e,t){return lo.call(e,t)}function ho(e){return Ir.call(e)}function fo(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;nt.maxStringLength){var n=e.length-t.maxStringLength,r="... "+n+" more character"+(n>1?"s":"");return yo(Lr.call(e,0,t.maxStringLength),t)+r}return io(Gr.call(Gr.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,go),"single",t)}function go(e){var t=e.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return n?"\\"+n:"\\x"+(t<16?"0":"")+Kr.call(t.toString(16))}function mo(e){return"Object("+e+")"}function bo(e){return e+" { ? }"}function vo(e,t,n,r){return e+" ("+t+") {"+(r?_o(n,r):zr.call(n,", "))+"}"}function _o(e,t){if(0===e.length)return"";var n="\n"+t.prev+t.base;return n+zr.call(e,","+n)+"\n"+t.prev}function So(e,t){var n=ao(e),r=[];if(n){r.length=e.length;for(var o=0;o-1?Sr(n):n},Po=function e(t,n,r,o){var i=n||{};if(po(i,"quoteStyle")&&"single"!==i.quoteStyle&&"double"!==i.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(po(i,"maxStringLength")&&("number"==typeof i.maxStringLength?i.maxStringLength<0&&i.maxStringLength!==1/0:null!==i.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var s=!po(i,"customInspect")||i.customInspect;if("boolean"!=typeof s&&"symbol"!==s)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(po(i,"indent")&&null!==i.indent&&"\t"!==i.indent&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(po(i,"numericSeparator")&&"boolean"!=typeof i.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=i.numericSeparator;if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return yo(t,i);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var u=String(t);return a?to(t,u):u}if("bigint"==typeof t){var l=String(t)+"n";return a?to(t,l):l}var p=void 0===i.depth?5:i.depth;if(void 0===r&&(r=0),r>=p&&p>0&&"object"==typeof t)return ao(t)?"[Array]":"[Object]";var h=function(e,t){var n;if("\t"===e.indent)n="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;n=zr.call(Array(e.indent+1)," ")}return{base:n,prev:zr.call(Array(t+1),n)}}(i,r);if(void 0===o)o=[];else if(fo(o,t)>=0)return"[Circular]";function f(t,n,s){if(n&&(o=Vr.call(o)).push(n),s){var a={depth:i.depth};return po(i,"quoteStyle")&&(a.quoteStyle=i.quoteStyle),e(t,a,r+1,o)}return e(t,i,r+1,o)}if("function"==typeof t&&!uo(t)){var d=function(e){if(e.name)return e.name;var t=Fr.call(Dr.call(e),/^function\s*([\w$]+)/);if(t)return t[1];return null}(t),y=So(t,f);return"[Function"+(d?": "+d:" (anonymous)")+"]"+(y.length>0?" { "+zr.call(y,", ")+" }":"")}if(co(t)){var g=Xr?Gr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qr.call(t);return"object"!=typeof t||Xr?g:mo(g)}if(function(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return!0;return"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}(t)){for(var m="<"+Br.call(String(t.nodeName)),b=t.attributes||[],v=0;v"}if(ao(t)){if(0===t.length)return"[]";var _=So(t,f);return h&&!function(e){for(var t=0;t=0)return!1;return!0}(_)?"["+_o(_,h)+"]":"[ "+zr.call(_,", ")+" ]"}if(function(e){return!("[object Error]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)){var S=So(t,f);return"cause"in Error.prototype||!("cause"in t)||Zr.call(t,"cause")?0===S.length?"["+String(t)+"]":"{ ["+String(t)+"] "+zr.call(S,", ")+" }":"{ ["+String(t)+"] "+zr.call(qr.call("[cause]: "+f(t.cause),S),", ")+" }"}if("object"==typeof t&&s){if(oo&&"function"==typeof t[oo]&&no)return no(t,{depth:p-r});if("symbol"!==s&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!Ar||!e||"object"!=typeof e)return!1;try{Ar.call(e);try{kr.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}(t)){var w=[];return Tr&&Tr.call(t,(function(e,n){w.push(f(n,t,!0)+" => "+f(e,t))})),vo("Map",Ar.call(t),w,h)}if(function(e){if(!kr||!e||"object"!=typeof e)return!1;try{kr.call(e);try{Ar.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}(t)){var O=[];return Mr&&Mr.call(t,(function(e){O.push(f(e,t))})),vo("Set",kr.call(t),O,h)}if(function(e){if(!jr||!e||"object"!=typeof e)return!1;try{jr.call(e,jr);try{Rr.call(e,Rr)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}(t))return bo("WeakMap");if(function(e){if(!Rr||!e||"object"!=typeof e)return!1;try{Rr.call(e,Rr);try{jr.call(e,jr)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}(t))return bo("WeakSet");if(function(e){if(!xr||!e||"object"!=typeof e)return!1;try{return xr.call(e),!0}catch(e){}return!1}(t))return bo("WeakRef");if(function(e){return!("[object Number]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(Number(t)));if(function(e){if(!e||"object"!=typeof e||!Jr)return!1;try{return Jr.call(e),!0}catch(e){}return!1}(t))return mo(f(Jr.call(t)));if(function(e){return!("[object Boolean]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(Ur.call(t));if(function(e){return!("[object String]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(String(t)));if("undefined"!=typeof window&&t===window)return"{ [object Window] }";if(t===c)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)&&!uo(t)){var P=So(t,f),E=eo?eo(t)===Object.prototype:t instanceof Object||t.constructor===Object,A=t instanceof Object?"":"null prototype",T=!E&&Yr&&Object(t)===t&&Yr in t?Lr.call(ho(t),8,-1):A?"Object":"",N=(E||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(T||A?"["+zr.call(qr.call([],T||[],A||[]),": ")+"] ":"");return 0===P.length?N+"{}":h?N+"{"+_o(P,h)+"}":N+"{ "+zr.call(P,", ")+" }"}return String(t)},Eo=wo("%TypeError%"),Ao=wo("%WeakMap%",!0),To=wo("%Map%",!0),No=Oo("WeakMap.prototype.get",!0),Co=Oo("WeakMap.prototype.set",!0),ko=Oo("WeakMap.prototype.has",!0),Mo=Oo("Map.prototype.get",!0),jo=Oo("Map.prototype.set",!0),Ro=Oo("Map.prototype.has",!0),xo=function(e,t){for(var n,r=e;null!==(n=r.next);r=n)if(n.key===t)return r.next=n.next,n.next=e.next,e.next=n,n},Uo=String.prototype.replace,Io=/%20/g,Do="RFC3986",Fo={default:Do,formatters:{RFC1738:function(e){return Uo.call(e,Io,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:Do},Lo=Fo,Go=Object.prototype.hasOwnProperty,Ko=Array.isArray,Bo=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),Ho=function(e,t){for(var n=t&&t.plainObjects?Object.create(null):{},r=0;r1;){var t=e.pop(),n=t.obj[t.prop];if(Ko(n)){for(var r=[],o=0;o=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===Lo.RFC1738&&(40===u||41===u)?s+=i.charAt(a):u<128?s+=Bo[u]:u<2048?s+=Bo[192|u>>6]+Bo[128|63&u]:u<55296||u>=57344?s+=Bo[224|u>>12]+Bo[128|u>>6&63]+Bo[128|63&u]:(a+=1,u=65536+((1023&u)<<10|1023&i.charCodeAt(a)),s+=Bo[240|u>>18]+Bo[128|u>>12&63]+Bo[128|u>>6&63]+Bo[128|63&u])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(Ko(e)){for(var n=[],r=0;r0?b.join(",")||null:void 0}];else if(Qo(u))O=u;else{var E=Object.keys(b);O=c?E.sort(c):E}for(var A=o&&Qo(b)&&1===b.length?n+"[]":n,T=0;T-1?e.split(","):e},li=function(e,t,n,r){if(e){var o=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,s=n.depth>0&&/(\[[^[\]]*])/.exec(o),a=s?o.slice(0,s.index):o,u=[];if(a){if(!n.plainObjects&&ii.call(Object.prototype,a)&&!n.allowPrototypes)return;u.push(a)}for(var c=0;n.depth>0&&null!==(s=i.exec(o))&&c=0;--i){var s,a=e[i];if("[]"===a&&n.parseArrays)s=[].concat(o);else{s=n.plainObjects?Object.create(null):{};var u="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(u,10);n.parseArrays||""!==u?!isNaN(c)&&a!==u&&String(c)===u&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(s=[])[c]=o:"__proto__"!==u&&(s[u]=o):s={0:o}}o=s}return o}(u,t,n,r)}},pi=function(e,t){var n,r=e,o=function(e){if(!e)return ti;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||ti.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Wo.default;if(void 0!==e.format){if(!Jo.call(Wo.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var r=Wo.formatters[n],o=ti.filter;return("function"==typeof e.filter||Qo(e.filter))&&(o=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:ti.addQueryPrefix,allowDots:void 0===e.allowDots?ti.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ti.charsetSentinel,delimiter:void 0===e.delimiter?ti.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:ti.encode,encoder:"function"==typeof e.encoder?e.encoder:ti.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:ti.encodeValuesOnly,filter:o,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:ti.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:ti.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ti.strictNullHandling}}(t);"function"==typeof o.filter?r=(0,o.filter)("",r):Qo(o.filter)&&(n=o.filter);var i,s=[];if("object"!=typeof r||null===r)return"";i=t&&t.arrayFormat in $o?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=$o[i];if(t&&"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var u="comma"===a&&t&&t.commaRoundTrip;n||(n=Object.keys(r)),o.sort&&n.sort(o.sort);for(var c=zo(),l=0;l0?f+h:""},hi={formats:Fo,parse:function(e,t){var n=function(e){if(!e)return ai;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?ai.charset:e.charset;return{allowDots:void 0===e.allowDots?ai.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:ai.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:ai.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:ai.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ai.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:ai.comma,decoder:"function"==typeof e.decoder?e.decoder:ai.decoder,delimiter:"string"==typeof e.delimiter||oi.isRegExp(e.delimiter)?e.delimiter:ai.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:ai.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:ai.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:ai.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:ai.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ai.strictNullHandling}}(t);if(""===e||null==e)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof e?function(e,t){var n,r={__proto__:null},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,i),a=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(l=si(l)?[l]:l),ii.call(r,c)?r[c]=oi.combine(r[c],l):r[c]=l}return r}(e,n):e,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),s=0;s=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.split(/ *; */).shift(),e.params=e=>{const n={};var r,o=t(e.split(/ *; */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *= */),t=e.shift(),o=e.shift();t&&o&&(n[t]=o)}}catch(e){o.e(e)}finally{o.f()}return n},e.parseLinks=e=>{const n={};var r,o=t(e.split(/ *, */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *; */),t=e[0].slice(1,-1);n[e[1].split(/ *= */)[1].slice(1,-1)]=t}}catch(e){o.e(e)}finally{o.f()}return n},e.cleanHeader=(e,t)=>(delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e),e.isObject=e=>null!==e&&"object"==typeof e,e.hasOwn=Object.hasOwn||function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(new Object(e),t)},e.mixin=(t,n)=>{for(const r in n)e.hasOwn(n,r)&&(t[r]=n[r])}}(fi);const di=Or,yi=fi.isObject,gi=fi.hasOwn;var mi=bi;function bi(){}bi.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},bi.prototype.parse=function(e){return this._parser=e,this},bi.prototype.responseType=function(e){return this._responseType=e,this},bi.prototype.serialize=function(e){return this._serializer=e,this},bi.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(const t in e)if(gi(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},bi.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};const vi=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),_i=new Set([408,413,429,500,502,503,504,521,522,524]);bi.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{const n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&_i.has(t.status))return!0;if(e){if(e.code&&vi.has(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},bi.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},bi.prototype.then=function(e,t){if(!this._fullfilledPromise){const e=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(((t,n)=>{e.on("abort",(()=>{if(this._maxRetries&&this._maxRetries>this._retries)return;if(this.timedout&&this.timedoutError)return void n(this.timedoutError);const e=new Error("Aborted");e.code="ABORTED",e.status=this.status,e.method=this.method,e.url=this.url,n(e)})),e.end(((e,r)=>{e?n(e):t(r)}))}))}return this._fullfilledPromise.then(e,t)},bi.prototype.catch=function(e){return this.then(void 0,e)},bi.prototype.use=function(e){return e(this),this},bi.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},bi.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},bi.prototype.get=function(e){return this._header[e.toLowerCase()]},bi.prototype.getHeader=bi.prototype.get,bi.prototype.set=function(e,t){if(yi(e)){for(const t in e)gi(e,t)&&this.set(t,e[t]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},bi.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},bi.prototype.field=function(e,t,n){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(yi(e)){for(const t in e)gi(e,t)&&this.field(t,e[t]);return this}if(Array.isArray(t)){for(const n in t)gi(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),n?this._getFormData().append(e,t,n):this._getFormData().append(e,t),this},bi.prototype.abort=function(){if(this._aborted)return this;if(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req){if(di.gte(process.version,"v13.0.0")&&di.lt(process.version,"v14.0.0"))throw new Error("Superagent does not work in v13 properly with abort() due to Node.js core changes");this.req.abort()}return this.clearTimeout(),this.emit("abort"),this},bi.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization",`Basic ${r(`${e}:${t}`)}`);break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization",`Bearer ${e}`)}return this},bi.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},bi.prototype.redirects=function(e){return this._maxRedirects=e,this},bi.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},bi.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},bi.prototype.send=function(e){const t=yi(e);let n=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&yi(this._data))for(const t in e){if("bigint"==typeof e[t]&&!e[t].toJSON)throw new Error("Cannot serialize BigInt value to json");gi(e,t)&&(this._data[t]=e[t])}else{if("bigint"==typeof e)throw new Error("Cannot send value of type BigInt");"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],n&&(n=n.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===n?this._data?`${this._data}&${e}`:e:(this._data||"")+e):this._data=e}return!t||this._isHost(e)||n||this.type("json"),this},bi.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},bi.prototype._finalizeQueryString=function(){const e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){const e=this.url.indexOf("?");if(e>=0){const t=this.url.slice(e+1).split("&");"function"==typeof this._sort?t.sort(this._sort):t.sort(),this.url=this.url.slice(0,e)+"?"+t.join("&")}}},bi.prototype._appendQueryString=()=>{console.warn("Unsupported")},bi.prototype._timeoutError=function(e,t,n){if(this._aborted)return;const r=new Error(`${e+t}ms exceeded`);r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.timedoutError=r,this.abort(),this.callback(r)},bi.prototype._setTimeouts=function(){const e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((()=>{e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((()=>{e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};const Si=fi;var wi=Oi;function Oi(){}function Pi(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Ei(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ei(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw i}}}}function Ei(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n{if(o.XMLHttpRequest)return new o.XMLHttpRequest;throw new Error("Browser-only version of superagent could not find XHR")};const g="".trim?e=>e.trim():e=>e.replace(/(^\s*|\s*$)/g,"");function m(e){if(!c(e))return e;const t=[];for(const n in e)p(e,n)&&b(t,n,e[n]);return t.join("&")}function b(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r)){var o,i=n(r);try{for(i.s();!(o=i.n()).done;){b(e,t,o.value)}}catch(e){i.e(e)}finally{i.f()}}else if(c(r))for(const n in r)p(r,n)&&b(e,`${t}[${n}]`,r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function v(e){const t={},n=e.split("&");let r,o;for(let e=0,i=n.length;e{let e,t=null,r=null;try{r=new S(n)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||r.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=e.status||r.status,n.callback(e,r)):n.callback(null,r)}))}y.serializeObject=m,y.parseString=v,y.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":a.stringify,"application/json":s},y.parse={"application/x-www-form-urlencoded":v,"application/json":JSON.parse},l(S.prototype,h.prototype),S.prototype._parseBody=function(e){let t=y.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&_(this.type)&&(t=y.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},S.prototype.toError=function(){const e=this.req,t=e.method,n=e.url,r=`cannot ${t} ${n} (${this.status})`,o=new Error(r);return o.status=this.status,o.method=t,o.url=n,o},y.Response=S,i(w.prototype),l(w.prototype,u.prototype),w.prototype.type=function(e){return this.set("Content-Type",y.types[e]||e),this},w.prototype.accept=function(e){return this.set("Accept",y.types[e]||e),this},w.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});const r=n.encoder?n.encoder:e=>{if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},w.prototype.query=function(e){return"string"!=typeof e&&(e=m(e)),e&&this._query.push(e),this},w.prototype.attach=function(e,t,n){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},w.prototype._getFormData=function(){return this._formData||(this._formData=new o.FormData),this._formData},w.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();const n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},w.prototype.crossDomainError=function(){const e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},w.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},w.prototype.ca=w.prototype.agent,w.prototype.buffer=w.prototype.ca,w.prototype.write=()=>{throw new Error("Streaming is not supported in browser version of superagent")},w.prototype.pipe=w.prototype.write,w.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},w.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||d,this._finalizeQueryString(),this._end()},w.prototype._setUploadTimeout=function(){const e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((()=>{e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},w.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));const e=this;this.xhr=y.getXHR();const t=this.xhr;let n=this._formData||this._data;this._setTimeouts(),t.addEventListener("readystatechange",(()=>{const n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4!==n)return;let r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}));const r=(t,n)=>{n.total>0&&(n.percent=n.loaded/n.total*100,100===n.percent&&clearTimeout(e._uploadTimeoutTimer)),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.addEventListener("progress",r.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",r.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof n&&!this._isHost(n)){const e=this._header["content-type"];let t=this._serializer||y.serialize[e?e.split(";")[0]:""];!t&&_(e)&&(t=y.serialize["application/json"]),t&&(n=t(n))}for(const e in this.header)null!==this.header[e]&&p(this.header,e)&&t.setRequestHeader(e,this.header[e]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===n?null:n)},y.agent=()=>new f;for(var O=0,P=["GET","POST","OPTIONS","PATCH","PUT","DELETE"];O{const r=y("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.head=(e,t,n)=>{const r=y("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.options=(e,t,n)=>{const r=y("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.del=E,y.delete=E,y.patch=(e,t,n)=>{const r=y("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.post=(e,t,n)=>{const r=y("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.put=(e,t,n)=>{const r=y("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}}(On,On.exports);var ki=On.exports;function Mi(e){var t=(new Date).getTime(),n=(new Date).toISOString(),r=console&&console.log?console:window&&window.console&&window.console.log?window.console:console;r.log("<<<<<"),r.log("[".concat(n,"]"),"\n",e.url,"\n",e.qs),r.log("-----"),e.on("response",(function(n){var o=(new Date).getTime()-t,i=(new Date).toISOString();r.log(">>>>>>"),r.log("[".concat(i," / ").concat(o,"]"),"\n",e.url,"\n",e.qs,"\n",n.text),r.log("-----")}))}function ji(e,t,n){var r=this;this._config.logVerbosity&&(e=e.use(Mi)),this._config.proxy&&this._modules.proxy&&(e=this._modules.proxy.call(this,e)),this._config.keepAlive&&this._modules.keepAlive&&(e=this._modules.keepAlive(e));var o=e;if(t.abortSignal)var i=t.abortSignal.subscribe((function(){o.abort(),i()}));return!0===t.forceBuffered?o="undefined"==typeof Blob?o.buffer().responseType("arraybuffer"):o.responseType("arraybuffer"):!1===t.forceBuffered&&(o=o.buffer(!1)),(o=o.timeout(t.timeout)).on("abort",(function(){return n({category:k.PNUnknownCategory,error:!0,operation:t.operation,errorData:new Error("Aborted")},null)})),o.end((function(e,o){var i,s={};if(s.error=null!==e,s.operation=t.operation,o&&o.status&&(s.statusCode=o.status),e){if(e.response&&e.response.text&&!r._config.logVerbosity)try{s.errorData=JSON.parse(e.response.text)}catch(t){s.errorData=e}else s.errorData=e;return s.category=r._detectErrorCategory(e),n(s,null)}if(t.ignoreBody)i={headers:o.headers,redirects:o.redirects,response:o};else try{i=JSON.parse(o.text)}catch(e){return s.errorData=o,s.error=!0,n(s,null)}return i.error&&1===i.error&&i.status&&i.message&&i.service?(s.errorData=i,s.statusCode=i.status,s.error=!0,s.category=r._detectErrorCategory(s),n(s,null)):(i.error&&i.error.message&&(s.errorData=i.error),n(s,i))})),o}function Ri(e,t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return r=ki.post(e),t.forEach((function(e){var t=e.key,n=e.value;r=r.field(t,n)})),r.attach("file",n,{contentType:"application/octet-stream"}),[4,r];case 1:return[2,o.sent()]}}))}))}function xi(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ui(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ii(e,t,n,r){var o=ki.post(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Di(e,t,n,r){var o=ki.patch(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Fi(e,t,n){var r=ki.delete(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Li(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}var Gi,Ki=function(){function e(){}return Object.defineProperty(e.prototype,"algo",{get:function(){return"aes-256-cbc"},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.encryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.encryptString(n,t)];throw new Error("Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer")}}))}))},e.prototype.decrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.decryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.decryptString(n,t)];throw new Error("Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer")}}))}))},e.prototype.encryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:if(t.data.byteLength<=0)throw new Error("encryption error. empty content");return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.encryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,mimeType:"application/octet-stream",data:s})]}}))}))},e.prototype.decryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.decryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,data:s})]}}))}))},e.prototype.getKey=function(t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return[4,crypto.subtle.digest("SHA-256",e.encoder.encode(t))];case 1:return n=i.sent(),r=Array.from(new Uint8Array(n)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),o=e.encoder.encode(r.slice(0,32)).buffer,[2,crypto.subtle.importKey("raw",o,"AES-CBC",!0,["encrypt","decrypt"])]}}))}))},e.prototype.encryptArrayBuffer=function(e,t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),r=Li,o=[n.buffer],[4,crypto.subtle.encrypt({name:"AES-CBC",iv:n},e,t)];case 1:return[2,r.apply(void 0,o.concat([i.sent()]))]}}))}))},e.prototype.decryptArrayBuffer=function(t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:if(r=n.slice(0,16),n.slice(e.IV_LENGTH).byteLength<=0)throw new Error("decryption error: empty content");return[4,crypto.subtle.decrypt({name:"AES-CBC",iv:r},t,n.slice(e.IV_LENGTH))];case 1:return[2,o.sent()]}}))}))},e.prototype.encryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=crypto.getRandomValues(new Uint8Array(16)),o=e.encoder.encode(n).buffer,[4,crypto.subtle.encrypt({name:"AES-CBC",iv:r},t,o)];case 1:return s=i.sent(),a=Li(r.buffer,s),[2,e.decoder.decode(a)]}}))}))},e.prototype.decryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=e.encoder.encode(n).buffer,o=r.slice(0,16),s=r.slice(16),[4,crypto.subtle.decrypt({name:"AES-CBC",iv:o},t,s)];case 1:return a=i.sent(),[2,e.decoder.decode(a)]}}))}))},e.IV_LENGTH=16,e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Bi=(Gi=function(){function e(e){if(e instanceof File)this.data=e,this.name=this.data.name,this.mimeType=this.data.type;else if(e.data){var t=e.data;this.data=new File([t],e.name,{type:e.mimeType}),this.name=e.name,e.mimeType&&(this.mimeType=e.mimeType)}if(void 0===this.data)throw new Error("Couldn't construct a file out of supplied options.");if(void 0===this.name)throw new Error("Couldn't guess filename out of the options. Please provide one.")}return e.create=function(e){return new this(e)},e.prototype.toBuffer=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toStream=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toFileUri=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in react native environments.")}))}))},e.prototype.toBlob=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e.prototype.toArrayBuffer=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if(r.result instanceof ArrayBuffer)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsArrayBuffer(e.data)}))]}))}))},e.prototype.toString=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if("string"==typeof r.result)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsBinaryString(e.data)}))]}))}))},e.prototype.toFile=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e}(),Gi.supportsFile="undefined"!=typeof File,Gi.supportsBlob="undefined"!=typeof Blob,Gi.supportsArrayBuffer="undefined"!=typeof ArrayBuffer,Gi.supportsBuffer=!1,Gi.supportsStream=!1,Gi.supportsString=!0,Gi.supportsEncryptFile=!0,Gi.supportsFileUri=!1,Gi),Hi=function(){function e(e){this.config=e,this.cryptor=new T({config:e}),this.fileCryptor=new Ki}return Object.defineProperty(e.prototype,"identifier",{get:function(){return""},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e){var t="string"==typeof e?e:(new TextDecoder).decode(e);return{data:this.cryptor.encrypt(t),metadata:null}},e.prototype.decrypt=function(e){var t="string"==typeof e.data?e.data:b(e.data);return this.cryptor.decrypt(t)},e.prototype.encryptFile=function(e,t){var n;return o(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)]}))}))},e.prototype.decryptFile=function(e,t){return o(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.fileCryptor.decryptFile(this.config.cipherKey,e,t)]}))}))},e}(),qi=function(){function e(e){this.cipherKey=e.cipherKey,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(this.cipherKey)}return Object.defineProperty(e.prototype,"algo",{get:function(){return"AES-CBC"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return"ACRH"},enumerable:!1,configurable:!0}),e.prototype.getIv=function(){return crypto.getRandomValues(new Uint8Array(e.BLOCK_SIZE))},e.prototype.getKey=function(){return o(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return t=e.encoder.encode(this.cipherKey),[4,crypto.subtle.digest("SHA-256",t.buffer)];case 1:return n=r.sent(),[2,crypto.subtle.importKey("raw",n,this.algo,!0,["encrypt","decrypt"])]}}))}))},e.prototype.encrypt=function(t){if(0===("string"==typeof t?t:e.decoder.decode(t)).length)throw new Error("encryption error. empty content");var n=this.getIv();return{metadata:n,data:m(this.CryptoJS.AES.encrypt(t,this.encryptedKey,{iv:this.bufferToWordArray(n),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}},e.prototype.decrypt=function(t){var n=this.bufferToWordArray(new Uint8ClampedArray(t.metadata)),r=this.bufferToWordArray(new Uint8ClampedArray(t.data));return e.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:r},this.encryptedKey,{iv:n,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer},e.prototype.encryptFileData=function(e){return o(this,void 0,void 0,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:return[4,this.getKey()];case 1:return t=o.sent(),n=this.getIv(),r={},[4,crypto.subtle.encrypt({name:this.algo,iv:n},t,e)];case 2:return[2,(r.data=o.sent(),r.metadata=n,r)]}}))}))},e.prototype.decryptFileData=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.getKey()];case 1:return t=n.sent(),[2,crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)]}}))}))},e.prototype.bufferToWordArray=function(e){var t,n=[];for(t=0;t0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("decryption error. empty content");return r.decrypt({data:t.slice(n.length),metadata:o})},e.prototype.encryptFile=function(e,t){return o(this,void 0,void 0,(function(){var n,r;return i(this,(function(o){switch(o.label){case 0:return this.defaultCryptor.identifier===Vi.LEGACY_IDENTIFIER?[2,this.defaultCryptor.encryptFile(e,t)]:[4,this.getFileData(e.data)];case 1:return n=o.sent(),[4,this.defaultCryptor.encryptFileData(n)];case 2:return r=o.sent(),[2,t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(r),r.data)})]}}))}))},e.prototype.decryptFile=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a,u,c,l,p;return i(this,(function(i){switch(i.label){case 0:return[4,t.data.arrayBuffer()];case 1:return r=i.sent(),o=Vi.tryParse(r),(null==(s=this.getCryptor(o))?void 0:s.identifier)===e.LEGACY_IDENTIFIER?[2,s.decryptFile(t,n)]:[4,this.getFileData(r)];case 2:return a=i.sent(),u=a.slice(o.length-o.metadataLength,o.length),l=(c=n).create,p={name:t.name},[4,this.defaultCryptor.decryptFileData({data:r.slice(o.length),metadata:u})];case 3:return[2,l.apply(c,[(p.data=i.sent(),p)])]}}))}))},e.prototype.getCryptor=function(e){if(""===e){var t=this.getAllCryptors().find((function(e){return""===e.identifier}));if(t)return t;throw new Error("unknown cryptor error")}if(e instanceof Wi)return this.getCryptorFromId(e.identifier)},e.prototype.getCryptorFromId=function(e){var t=this.getAllCryptors().find((function(t){return e===t.identifier}));if(t)return t;throw Error("unknown cryptor error")},e.prototype.concatArrayBuffer=function(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer},e.prototype.getHeaderData=function(e){if(e.metadata){var t=Vi.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length),r=0;return n.set(t.data,r),r+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),r),n.buffer}},e.prototype.getFileData=function(t){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return t instanceof Blob?[4,t.arrayBuffer()]:[3,2];case 1:return[2,n.sent()];case 2:if(t instanceof ArrayBuffer)return[2,t];if("string"==typeof t)return[2,e.encoder.encode(t)];throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}}))}))},e.LEGACY_IDENTIFIER="",e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Vi=function(){function e(){}return e.from=function(t,n){if(t!==e.LEGACY_IDENTIFIER)return new Wi(t,n.byteLength)},e.tryParse=function(t){var n=new Uint8Array(t),r="";if(n.byteLength>=4&&(r=n.slice(0,4),this.decoder.decode(r)!==e.SENTINEL))return"";if(!(n.byteLength>=5))throw new Error("decryption error. invalid header version");if(n[4]>e.MAX_VERSION)throw new Error("unknown cryptor error");var o="",i=5+e.IDENTIFIER_LENGTH;if(!(n.byteLength>=i))throw new Error("decryption error. invalid crypto identifier");o=n.slice(5,i);var s=null;if(!(n.byteLength>=i+1))throw new Error("decryption error. invalid metadata length");return s=n[i],i+=1,255===s&&n.byteLength>=i+2&&(s=new Uint16Array(n.slice(i,i+2)).reduce((function(e,t){return(e<<8)+t}),0),i+=2),new Wi(this.decoder.decode(o),s)},e.SENTINEL="PNED",e.LEGACY_IDENTIFIER="",e.IDENTIFIER_LENGTH=4,e.VERSION=1,e.MAX_VERSION=1,e.decoder=new TextDecoder,e}(),Wi=function(){function e(e,t){this._identifier=e,this._metadataLength=t}return Object.defineProperty(e.prototype,"identifier",{get:function(){return this._identifier},set:function(e){this._identifier=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"metadataLength",{get:function(){return this._metadataLength},set:function(e){this._metadataLength=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return Vi.VERSION},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return Vi.SENTINEL.length+1+Vi.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){var e=0,t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(Vi.SENTINEL)),t[e+=Vi.SENTINEL.length]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e),e+=Vi.IDENTIFIER_LENGTH;var r=this.metadataLength;return r<255?t[e]=r:t.set([255,r>>8,255&r],e),t},enumerable:!1,configurable:!0}),e.IDENTIFIER_LENGTH=4,e.SENTINEL="PNED",e}();function Ji(e){if(!navigator||!navigator.sendBeacon)return!1;navigator.sendBeacon(e)}var $i=function(e){function n(t){var n=this,r=t.listenToBrowserNetworkEvents,o=void 0===r||r;return t.sdkFamily="Web",t.networking=new _n({del:Fi,get:Ui,post:Ii,patch:Di,sendBeacon:Ji,getfile:xi,postfile:Ri}),t.cbor=new wn((function(e){return Sn(h.decode(e))}),m),t.PubNubFile=Bi,t.cryptography=new Ki,t.initCryptoModule=function(e){return new zi({default:new Hi({cipherKey:e.cipherKey,useRandomIVs:e.useRandomIVs}),cryptors:[new qi({cipherKey:e.cipherKey})]})},n=e.call(this,t)||this,o&&(window.addEventListener("offline",(function(){n.networkDownDetected()})),window.addEventListener("online",(function(){n.networkUpDetected()}))),n}return t(n,e),n.CryptoModule=zi,n}(vn);return $i})); +!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function o(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=o,r.VERSION=t,e.uuid=r,e.isUUID=o}(t),null!==e&&(e.exports=t.uuid)}(f,f.exports);var d=f.exports,y=function(){return d.uuid?d.uuid():d()},g=function(){function e(e){var t,n,r,o,i=e.setup;if(this._PNSDKSuffix={},this.instanceId="pn-".concat(y()),this.secretKey=i.secretKey||i.secret_key,this.subscribeKey=i.subscribeKey||i.subscribe_key,this.publishKey=i.publishKey||i.publish_key,this.sdkName=i.sdkName,this.sdkFamily=i.sdkFamily,this.partnerId=i.partnerId,this.setAuthKey(i.authKey),this.cryptoModule=i.cryptoModule,this.setFilterExpression(i.filterExpression),"string"!=typeof i.origin&&!Array.isArray(i.origin)&&void 0!==i.origin)throw new Error("Origin must be either undefined, a string or a list of strings.");if(this.origin=i.origin||Array.from({length:20},(function(e,t){return"ps".concat(t+1,".pndsn.com")})),this.secure=i.ssl||!1,this.restore=i.restore||!1,this.proxy=i.proxy,this.keepAlive=i.keepAlive,this.keepAliveSettings=i.keepAliveSettings,this.autoNetworkDetection=i.autoNetworkDetection||!1,this.dedupeOnSubscribe=i.dedupeOnSubscribe||!1,this.maximumCacheSize=i.maximumCacheSize||100,this.customEncrypt=i.customEncrypt,this.customDecrypt=i.customDecrypt,this.fileUploadPublishRetryLimit=null!==(t=i.fileUploadPublishRetryLimit)&&void 0!==t?t:5,this.useRandomIVs=null===(n=i.useRandomIVs)||void 0===n||n,this.enableEventEngine=null!==(r=i.enableEventEngine)&&void 0!==r&&r,this.maintainPresenceState=null===(o=i.maintainPresenceState)||void 0===o||o,"undefined"!=typeof location&&"https:"===location.protocol&&(this.secure=!0),this.logVerbosity=i.logVerbosity||!1,this.suppressLeaveEvents=i.suppressLeaveEvents||!1,this.announceFailedHeartbeats=i.announceFailedHeartbeats||!0,this.announceSuccessfulHeartbeats=i.announceSuccessfulHeartbeats||!1,this.useInstanceId=i.useInstanceId||!1,this.useRequestId=i.useRequestId||!1,this.requestMessageCountThreshold=i.requestMessageCountThreshold,i.retryConfiguration&&this._setRetryConfiguration(i.retryConfiguration),this.setTransactionTimeout(i.transactionalRequestTimeout||15e3),this.setSubscribeTimeout(i.subscribeRequestTimeout||31e4),this.setSendBeaconConfig(i.useSendBeacon||!0),i.presenceTimeout?this.setPresenceTimeout(i.presenceTimeout):this._presenceTimeout=300,null!=i.heartbeatInterval&&this.setHeartbeatInterval(i.heartbeatInterval),"string"==typeof i.userId){if("string"==typeof i.uuid)throw new Error("Only one of the following configuration options has to be provided: `uuid` or `userId`");this.setUserId(i.userId)}else{if("string"!=typeof i.uuid)throw new Error("One of the following configuration options has to be provided: `uuid` or `userId`");this.setUUID(i.uuid)}this.setCipherKey(i.cipherKey,i)}return e.prototype.getAuthKey=function(){return this.authKey},e.prototype.setAuthKey=function(e){return this.authKey=e,this},e.prototype.setCipherKey=function(e,t,n){var r;return this.cipherKey=e,this.cipherKey&&(this.cryptoModule=null!==(r=t.cryptoModule)&&void 0!==r?r:t.initCryptoModule({cipherKey:this.cipherKey,useRandomIVs:this.useRandomIVs}),n&&(n.cryptoModule=this.cryptoModule)),this},e.prototype.getUUID=function(){return this.UUID},e.prototype.setUUID=function(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing uuid parameter. Provide a valid string uuid");return this.UUID=e,this},e.prototype.getUserId=function(){return this.UUID},e.prototype.setUserId=function(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");return this.UUID=e,this},e.prototype.getFilterExpression=function(){return this.filterExpression},e.prototype.setFilterExpression=function(e){return this.filterExpression=e,this},e.prototype.getPresenceTimeout=function(){return this._presenceTimeout},e.prototype.setPresenceTimeout=function(e){return e>=20?this._presenceTimeout=e:(this._presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",this._presenceTimeout)),this.setHeartbeatInterval(this._presenceTimeout/2-1),this},e.prototype.setProxy=function(e){this.proxy=e},e.prototype.getHeartbeatInterval=function(){return this._heartbeatInterval},e.prototype.setHeartbeatInterval=function(e){return this._heartbeatInterval=e,this},e.prototype.getSubscribeTimeout=function(){return this._subscribeRequestTimeout},e.prototype.setSubscribeTimeout=function(e){return this._subscribeRequestTimeout=e,this},e.prototype.getTransactionTimeout=function(){return this._transactionalRequestTimeout},e.prototype.setTransactionTimeout=function(e){return this._transactionalRequestTimeout=e,this},e.prototype.isSendBeaconEnabled=function(){return this._useSendBeacon},e.prototype.setSendBeaconConfig=function(e){return this._useSendBeacon=e,this},e.prototype.getVersion=function(){return"7.6.3"},e.prototype._setRetryConfiguration=function(e){if(e.minimumdelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(e.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(e.maximumDelay&&maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6");if(e.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10");this.retryConfiguration=e},e.prototype._addPnsdkSuffix=function(e,t){this._PNSDKSuffix[e]=t},e.prototype._getPnsdkSuffix=function(e){var t=this;return Object.keys(this._PNSDKSuffix).reduce((function(n,r){return n+e+t._PNSDKSuffix[r]}),"")},e}();function m(e){var t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;function s(){var e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error("Illegal character at ".concat(i,": ").concat(t.charAt(i-1)));return n}for(var a=0;a>4,f=(15&c)<<4|l>>2,d=(3&l)<<6|p>>0;o[a]=h,64!=l&&(o[a+1]=f),64!=p&&(o[a+2]=d)}return r}function b(e){for(var t,n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=new Uint8Array(e),i=o.byteLength,s=i%3,a=i-s,u=0;u>18]+r[(258048&t)>>12]+r[(4032&t)>>6]+r[63&t];return 1==s?n+=r[(252&(t=o[a]))>>2]+r[(3&t)<<4]+"==":2==s&&(n+=r[(64512&(t=o[a]<<8|o[a+1]))>>10]+r[(1008&t)>>4]+r[(15&t)<<2]+"="),n}var v,_,S,w,O,P=P||function(e,t){var n={},r=n.lib={},o=function(){},i=r.Base={extend:function(e){o.prototype=this;var t=new o;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var o=0;o>>2]|=(n[o>>>2]>>>24-o%4*8&255)<<24-(r+o)%4*8;else if(65535>>2]=n[o>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r>>2]>>>24-r%4*8&255;n.push((o>>>4).toString(16)),n.push((15&o).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,a=o/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,o=e.min(4*t,o),t){for(var u=0;uc;){var l;e:{l=u;for(var p=e.sqrt(l),h=2;h<=p;h++)if(!(l%h)){l=!1;break e}l=!0}l&&(8>c&&(i[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var f=[];o=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],a=n[3],u=n[4],c=n[5],l=n[6],p=n[7],h=0;64>h;h++){if(16>h)f[h]=0|e[t+h];else{var d=f[h-15],y=f[h-2];f[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+f[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+f[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[h]+f[h],y=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=l,l=c,c=u,u=a+d|0,a=i,i=o,o=r,r=d+y|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+p|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(o),t.HmacSHA256=r._createHmacHelper(o)}(Math),_=(v=P).enc.Utf8,v.algo.HMAC=v.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=_.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,a=i.words,u=0;u>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;4>s&&o+.75*s>>6*(3-s)&63));if(t=r.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(r=n.charAt(64))&&-1!=(r=e.indexOf(r))&&(t=r);for(var r=[],o=0,i=0;i>>6-i%4*2;r[o>>>2]|=(s|a)<<24-o%4*8,o++}return w.create(r,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,r,o,i,s){return((e=e+(t&n|~t&r)+o+s)<>>32-i)+t}function n(e,t,n,r,o,i,s){return((e=e+(t&r|n&~r)+o+s)<>>32-i)+t}function r(e,t,n,r,o,i,s){return((e=e+(t^n^r)+o+s)<>>32-i)+t}function o(e,t,n,r,o,i,s){return((e=e+(n^(t|~r))+o+s)<>>32-i)+t}for(var i=P,s=(u=i.lib).WordArray,a=u.Hasher,u=i.algo,c=[],l=0;64>l;l++)c[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=a.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var s=0;16>s;s++){var a=e[u=i+s];e[u]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}s=this._hash.words;var u=e[i+0],l=(a=e[i+1],e[i+2]),p=e[i+3],h=e[i+4],f=e[i+5],d=e[i+6],y=e[i+7],g=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],_=e[i+12],S=e[i+13],w=e[i+14],O=e[i+15],P=t(P=s[0],T=s[1],A=s[2],E=s[3],u,7,c[0]),E=t(E,P,T,A,a,12,c[1]),A=t(A,E,P,T,l,17,c[2]),T=t(T,A,E,P,p,22,c[3]);P=t(P,T,A,E,h,7,c[4]),E=t(E,P,T,A,f,12,c[5]),A=t(A,E,P,T,d,17,c[6]),T=t(T,A,E,P,y,22,c[7]),P=t(P,T,A,E,g,7,c[8]),E=t(E,P,T,A,m,12,c[9]),A=t(A,E,P,T,b,17,c[10]),T=t(T,A,E,P,v,22,c[11]),P=t(P,T,A,E,_,7,c[12]),E=t(E,P,T,A,S,12,c[13]),A=t(A,E,P,T,w,17,c[14]),P=n(P,T=t(T,A,E,P,O,22,c[15]),A,E,a,5,c[16]),E=n(E,P,T,A,d,9,c[17]),A=n(A,E,P,T,v,14,c[18]),T=n(T,A,E,P,u,20,c[19]),P=n(P,T,A,E,f,5,c[20]),E=n(E,P,T,A,b,9,c[21]),A=n(A,E,P,T,O,14,c[22]),T=n(T,A,E,P,h,20,c[23]),P=n(P,T,A,E,m,5,c[24]),E=n(E,P,T,A,w,9,c[25]),A=n(A,E,P,T,p,14,c[26]),T=n(T,A,E,P,g,20,c[27]),P=n(P,T,A,E,S,5,c[28]),E=n(E,P,T,A,l,9,c[29]),A=n(A,E,P,T,y,14,c[30]),P=r(P,T=n(T,A,E,P,_,20,c[31]),A,E,f,4,c[32]),E=r(E,P,T,A,g,11,c[33]),A=r(A,E,P,T,v,16,c[34]),T=r(T,A,E,P,w,23,c[35]),P=r(P,T,A,E,a,4,c[36]),E=r(E,P,T,A,h,11,c[37]),A=r(A,E,P,T,y,16,c[38]),T=r(T,A,E,P,b,23,c[39]),P=r(P,T,A,E,S,4,c[40]),E=r(E,P,T,A,u,11,c[41]),A=r(A,E,P,T,p,16,c[42]),T=r(T,A,E,P,d,23,c[43]),P=r(P,T,A,E,m,4,c[44]),E=r(E,P,T,A,_,11,c[45]),A=r(A,E,P,T,O,16,c[46]),P=o(P,T=r(T,A,E,P,l,23,c[47]),A,E,u,6,c[48]),E=o(E,P,T,A,y,10,c[49]),A=o(A,E,P,T,w,15,c[50]),T=o(T,A,E,P,f,21,c[51]),P=o(P,T,A,E,_,6,c[52]),E=o(E,P,T,A,p,10,c[53]),A=o(A,E,P,T,b,15,c[54]),T=o(T,A,E,P,a,21,c[55]),P=o(P,T,A,E,g,6,c[56]),E=o(E,P,T,A,O,10,c[57]),A=o(A,E,P,T,d,15,c[58]),T=o(T,A,E,P,S,21,c[59]),P=o(P,T,A,E,h,6,c[60]),E=o(E,P,T,A,v,10,c[61]),A=o(A,E,P,T,l,15,c[62]),T=o(T,A,E,P,m,21,c[63]);s[0]=s[0]+P|0,s[1]=s[1]+T|0,s[2]=s[2]+A|0,s[3]=s[3]+E|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var i=e.floor(r/4294967296);for(n[15+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(o+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,r=0;4>r;r++)o=n[r],n[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(u),i.HmacMD5=a._createHmacHelper(u)}(Math),function(){var e,t=P,n=(e=t.lib).Base,r=e.WordArray,o=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),o=r.create(),i=o.words,s=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:u,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var p=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(u=(f.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return p.create({ciphertext:e,salt:n})}},t.SerializableCipher=n.extend({cfg:n.extend({format:u}),encrypt:function(e,t,n,r){r=this.cfg.extend(r);var o=e.createEncryptor(n,r);return t=o.finalize(t),o=o.cfg,p.create({ciphertext:t,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:r.format})},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),e.createDecryptor(n,r).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),f=(f.kdf={}).OpenSSL={execute:function(e,t,n,o){return o||(o=r.random(8)),e=s.create({keySize:t+n}).compute(e,o),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,p.create({key:e,iv:n,salt:o})}},d=t.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:f}),encrypt:function(e,t,n,r){return n=(r=this.cfg.extend(r)).kdf.execute(n,e.keySize,e.ivSize),r.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,r)).mixIn(n),e},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),n=r.kdf.execute(n,e.keySize,e.ivSize,t.salt),r.iv=n.iv,h.decrypt.call(this,e,t,n.key,r)}})}(),function(){for(var e=P,t=e.lib.BlockCipher,n=e.algo,r=[],o=[],i=[],s=[],a=[],u=[],c=[],l=[],p=[],h=[],f=[],d=0;256>d;d++)f[d]=128>d?d<<1:d<<1^283;var y=0,g=0;for(d=0;256>d;d++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;r[y]=m,o[m]=y;var b=f[y],v=f[b],_=f[v],S=257*f[m]^16843008*m;i[y]=S<<24|S>>>8,s[y]=S<<16|S>>>16,a[y]=S<<8|S>>>24,u[y]=S,S=16843009*_^65537*v^257*b^16843008*y,c[m]=S<<24|S>>>8,l[m]=S<<16|S>>>16,p[m]=S<<8|S>>>24,h[m]=S,y?(y=b^f[f[f[_^b]]],g^=f[f[g]]):y=g=1}var w=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),o=this._keySchedule=[],i=0;i>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s]):(s=r[(s=s<<8|s>>>24)>>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s],s^=w[i/t|0]<<24),o[i]=o[i-t]^s}for(e=this._invKeySchedule=[],t=0;tt||4>=i?s:c[r[s>>>24]]^l[r[s>>>16&255]]^p[r[s>>>8&255]]^h[r[255&s]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,s,a,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,c,l,p,h,o),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,r,o,i,s,a){for(var u=this._nRounds,c=e[t]^n[0],l=e[t+1]^n[1],p=e[t+2]^n[2],h=e[t+3]^n[3],f=4,d=1;d>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&h]^n[f++],g=r[l>>>24]^o[p>>>16&255]^i[h>>>8&255]^s[255&c]^n[f++],m=r[p>>>24]^o[h>>>16&255]^i[c>>>8&255]^s[255&l]^n[f++];h=r[h>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^n[f++],c=y,l=g,p=m}y=(a[c>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&h])^n[f++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[h>>>8&255]<<8|a[255&c])^n[f++],m=(a[p>>>24]<<24|a[h>>>16&255]<<16|a[c>>>8&255]<<8|a[255&l])^n[f++],h=(a[h>>>24]<<24|a[c>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^n[f++],e[t]=y,e[t+1]=g,e[t+2]=m,e[t+3]=h},keySize:8});e.AES=t._createHelper(n)}(),P.mode.ECB=((O=P.lib.BlockCipherMode.extend()).Encryptor=O.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),O.Decryptor=O.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),O);var E=P;function A(e){var t,n=[];for(t=0;t=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))},e.prototype.clearHistory=function(){this.hashHistory=[]},e}(),k={PNNetworkUpCategory:"PNNetworkUpCategory",PNNetworkDownCategory:"PNNetworkDownCategory",PNNetworkIssuesCategory:"PNNetworkIssuesCategory",PNTimeoutCategory:"PNTimeoutCategory",PNBadRequestCategory:"PNBadRequestCategory",PNAccessDeniedCategory:"PNAccessDeniedCategory",PNUnknownCategory:"PNUnknownCategory",PNReconnectedCategory:"PNReconnectedCategory",PNConnectedCategory:"PNConnectedCategory",PNRequestMessageCountExceededCategory:"PNRequestMessageCountExceededCategory",PNDisconnectedCategory:"PNDisconnectedCategory",PNConnectionErrorCategory:"PNConnectionErrorCategory",PNDisconnectedUnexpectedlyCategory:"PNDisconnectedUnexpectedlyCategory"},M=function(){function e(e){var t=e.subscribeEndpoint,n=e.leaveEndpoint,r=e.heartbeatEndpoint,o=e.setStateEndpoint,i=e.timeEndpoint,s=e.getFileUrl,a=e.config,u=e.crypto,c=e.listenerManager,l=e.cryptoModule,p=e.eventEmitter;this._listenerManager=c,this._config=a,this._leaveEndpoint=n,this._heartbeatEndpoint=r,this._setStateEndpoint=o,this._subscribeEndpoint=t,this._getFileUrl=s,this._crypto=u,this._cryptoModule=l,this._channels={},this._presenceChannels={},this._heartbeatChannels={},this._heartbeatChannelGroups={},this._channelGroups={},this._presenceChannelGroups={},this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[],this._currentTimetoken=0,this._lastTimetoken=0,this._storedTimetoken=null,this._subscriptionStatusAnnounced=!1,this._isOnline=!0,this._reconnectionManager=new N({timeEndpoint:i}),this._dedupingManager=new C({config:a}),this._cryptoModule&&(this._decoder=new TextDecoder),this._eventEmitter=p}return e.prototype.adaptStateChange=function(e,t){var n=this,r=e.state,o=e.channels,i=void 0===o?[]:o,s=e.channelGroups,a=void 0===s?[]:s,u=e.withHeartbeat,c=void 0!==u&&u;if(i.forEach((function(e){e in n._channels&&(n._channels[e].state=r)})),a.forEach((function(e){e in n._channelGroups&&(n._channelGroups[e].state=r)})),c){var l={};return i.forEach((function(e){return l[e]=r})),a.forEach((function(e){return l[e]=r})),this._heartbeatEndpoint({channels:i,channelGroups:a,state:l},t)}return this._setStateEndpoint({state:r,channels:i,channelGroups:a},t)},e.prototype.adaptPresenceChange=function(e){var t=this,n=e.connected,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i;n?(o.forEach((function(e){t._heartbeatChannels[e]={state:{}}})),s.forEach((function(e){t._heartbeatChannelGroups[e]={state:{}}}))):(o.forEach((function(e){e in t._heartbeatChannels&&delete t._heartbeatChannels[e]})),s.forEach((function(e){e in t._heartbeatChannelGroups&&delete t._heartbeatChannelGroups[e]})),!1===this._config.suppressLeaveEvents&&this._leaveEndpoint({channels:o,channelGroups:s},(function(e){t._listenerManager.announceStatus(e)}))),this.reconnect()},e.prototype.adaptSubscribeChange=function(e){var t=this,n=e.timetoken,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=e.withPresence,u=void 0!==a&&a,c=e.withHeartbeats,l=void 0!==c&&c;this._config.subscribeKey&&""!==this._config.subscribeKey?(n&&(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=n),"0"!==this._currentTimetoken&&0!==this._currentTimetoken&&(this._storedTimetoken=this._currentTimetoken,this._currentTimetoken=0),o.forEach((function(e){t._channels[e]={state:{}},u&&(t._presenceChannels[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannels[e]={}),t._pendingChannelSubscriptions.push(e)})),s.forEach((function(e){t._channelGroups[e]={state:{}},u&&(t._presenceChannelGroups[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannelGroups[e]={}),t._pendingChannelGroupSubscriptions.push(e)})),this._subscriptionStatusAnnounced=!1,this.reconnect()):console&&console.log&&console.log("subscribe key missing; aborting subscribe")},e.prototype.adaptUnsubscribeChange=function(e,t){var n=this,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=[],u=[];o.forEach((function(e){e in n._channels&&(delete n._channels[e],a.push(e),e in n._heartbeatChannels&&delete n._heartbeatChannels[e]),e in n._presenceChannels&&(delete n._presenceChannels[e],a.push(e))})),s.forEach((function(e){e in n._channelGroups&&(delete n._channelGroups[e],u.push(e),e in n._heartbeatChannelGroups&&delete n._heartbeatChannelGroups[e]),e in n._presenceChannelGroups&&(delete n._presenceChannelGroups[e],u.push(e))})),0===a.length&&0===u.length||(!1!==this._config.suppressLeaveEvents||t||this._leaveEndpoint({channels:a,channelGroups:u},(function(e){e.affectedChannels=a,e.affectedChannelGroups=u,e.currentTimetoken=n._currentTimetoken,e.lastTimetoken=n._lastTimetoken,n._listenerManager.announceStatus(e)})),0===Object.keys(this._channels).length&&0===Object.keys(this._presenceChannels).length&&0===Object.keys(this._channelGroups).length&&0===Object.keys(this._presenceChannelGroups).length&&(this._lastTimetoken=0,this._currentTimetoken=0,this._storedTimetoken=null,this._region=null,this._reconnectionManager.stopPolling()),this.reconnect())},e.prototype.unsubscribeAll=function(e){this.adaptUnsubscribeChange({channels:this.getSubscribedChannels(),channelGroups:this.getSubscribedChannelGroups()},e)},e.prototype.getHeartbeatChannels=function(){return Object.keys(this._heartbeatChannels)},e.prototype.getHeartbeatChannelGroups=function(){return Object.keys(this._heartbeatChannelGroups)},e.prototype.getSubscribedChannels=function(){return Object.keys(this._channels)},e.prototype.getSubscribedChannelGroups=function(){return Object.keys(this._channelGroups)},e.prototype.reconnect=function(){this._startSubscribeLoop(),this._registerHeartbeatTimer()},e.prototype.disconnect=function(){this._stopSubscribeLoop(),this._stopHeartbeatTimer(),this._reconnectionManager.stopPolling()},e.prototype._registerHeartbeatTimer=function(){this._stopHeartbeatTimer(),0!==this._config.getHeartbeatInterval()&&void 0!==this._config.getHeartbeatInterval()&&(this._performHeartbeatLoop(),this._heartbeatTimer=setInterval(this._performHeartbeatLoop.bind(this),1e3*this._config.getHeartbeatInterval()))},e.prototype._stopHeartbeatTimer=function(){this._heartbeatTimer&&(clearInterval(this._heartbeatTimer),this._heartbeatTimer=null)},e.prototype._performHeartbeatLoop=function(){var e=this,t=this.getHeartbeatChannels(),n=this.getHeartbeatChannelGroups(),r={};if(0!==t.length||0!==n.length){this.getSubscribedChannels().forEach((function(t){var n=e._channels[t].state;Object.keys(n).length&&(r[t]=n)})),this.getSubscribedChannelGroups().forEach((function(t){var n=e._channelGroups[t].state;Object.keys(n).length&&(r[t]=n)}));this._heartbeatEndpoint({channels:t,channelGroups:n,state:r},function(t){t.error&&e._config.announceFailedHeartbeats&&e._listenerManager.announceStatus(t),t.error&&e._config.autoNetworkDetection&&e._isOnline&&(e._isOnline=!1,e.disconnect(),e._listenerManager.announceNetworkDown(),e.reconnect()),!t.error&&e._config.announceSuccessfulHeartbeats&&e._listenerManager.announceStatus(t)}.bind(this))}},e.prototype._startSubscribeLoop=function(){var e=this;this._stopSubscribeLoop();var t={},n=[],r=[];if(Object.keys(this._channels).forEach((function(r){var o=e._channels[r].state;Object.keys(o).length&&(t[r]=o),n.push(r)})),Object.keys(this._presenceChannels).forEach((function(e){n.push("".concat(e,"-pnpres"))})),Object.keys(this._channelGroups).forEach((function(n){var o=e._channelGroups[n].state;Object.keys(o).length&&(t[n]=o),r.push(n)})),Object.keys(this._presenceChannelGroups).forEach((function(e){r.push("".concat(e,"-pnpres"))})),0!==n.length||0!==r.length){var o={channels:n,channelGroups:r,state:t,timetoken:this._currentTimetoken,filterExpression:this._config.filterExpression,region:this._region};this._subscribeCall=this._subscribeEndpoint(o,this._processSubscribeResponse.bind(this))}},e.prototype._processSubscribeResponse=function(e,t){var n=this;if(e.error){if(e.errorData&&"Aborted"===e.errorData.message)return;e.category===k.PNTimeoutCategory?this._startSubscribeLoop():e.category===k.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this._config.autoNetworkDetection&&this._isOnline&&(this._isOnline=!1,this._listenerManager.announceNetworkDown()),this._reconnectionManager.onReconnection((function(){n._config.autoNetworkDetection&&!n._isOnline&&(n._isOnline=!0,n._listenerManager.announceNetworkUp()),n.reconnect(),n._subscriptionStatusAnnounced=!0;var t={category:k.PNReconnectedCategory,operation:e.operation,lastTimetoken:n._lastTimetoken,currentTimetoken:n._currentTimetoken};n._listenerManager.announceStatus(t)})),this._reconnectionManager.startPolling(),this._listenerManager.announceStatus(e)):e.category===k.PNBadRequestCategory?(this._stopHeartbeatTimer(),this._listenerManager.announceStatus(e)):this._listenerManager.announceStatus(e)}else{if(this._storedTimetoken?(this._currentTimetoken=this._storedTimetoken,this._storedTimetoken=null):(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=t.metadata.timetoken),!this._subscriptionStatusAnnounced){var r={};r.category=k.PNConnectedCategory,r.operation=e.operation,r.affectedChannels=this._pendingChannelSubscriptions,r.subscribedChannels=this.getSubscribedChannels(),r.affectedChannelGroups=this._pendingChannelGroupSubscriptions,r.lastTimetoken=this._lastTimetoken,r.currentTimetoken=this._currentTimetoken,this._subscriptionStatusAnnounced=!0,this._listenerManager.announceStatus(r),this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[]}var o=t.messages||[],i=this._config,s=i.requestMessageCountThreshold,a=i.dedupeOnSubscribe;if(s&&o.length>=s){var u={};u.category=k.PNRequestMessageCountExceededCategory,u.operation=e.operation,this._listenerManager.announceStatus(u)}o.forEach((function(e){if(e.channel,e.subscriptionMatch,a){if(n._dedupingManager.isDuplicate(e))return;n._dedupingManager.addEntry(e)}n._eventEmitter.emitEvent(e)})),this._region=t.metadata.region,this._startSubscribeLoop()}},e.prototype._stopSubscribeLoop=function(){this._subscribeCall&&("function"==typeof this._subscribeCall.abort&&this._subscribeCall.abort(),this._subscribeCall=null)},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),j={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",PNAccessManagerRevokeToken:"PNAccessManagerRevokeToken",PNHandshakeOperation:"PNHandshakeOperation",PNReceiveMessagesOperation:"PNReceiveMessagesOperation"},R=function(){function e(e){this._maximumSamplesCount=100,this._trackedLatencies={},this._latencies={},this._telemetryExcludeOperations=[j.PNSubscribeOperation,j.PNReceiveMessagesOperation,j.PNHandshakeOperation],this._maximumSamplesCount=e.maximumSamplesCount||this._maximumSamplesCount}return e.prototype.operationsLatencyForRequest=function(){var e=this,t={};return Object.keys(this._latencies).forEach((function(n){var r=e._latencies[n],o=e._averageLatency(r);o>0&&(t["l_".concat(n)]=o)})),t},e.prototype.startLatencyMeasure=function(e,t){!this._telemetryExcludeOperations.includes(e)&&t&&(this._trackedLatencies[t]=Date.now())},e.prototype.stopLatencyMeasure=function(e,t){if(!this._telemetryExcludeOperations.includes(e)&&t){var n=this._endpointName(e),r=this._latencies[n],o=this._trackedLatencies[t];r||(this._latencies[n]=[],r=this._latencies[n]),r.push(Date.now()-o),r.length>this._maximumSamplesCount&&r.splice(0,r.length-this._maximumSamplesCount),delete this._trackedLatencies[t]}},e.prototype._averageLatency=function(e){return Math.floor(e.reduce((function(e,t){return e+t}),0)/e.length)},e.prototype._endpointName=function(e){var t=null;switch(e){case j.PNPublishOperation:t="pub";break;case j.PNSignalOperation:t="sig";break;case j.PNHistoryOperation:case j.PNFetchMessagesOperation:case j.PNDeleteMessagesOperation:case j.PNMessageCounts:t="hist";break;case j.PNUnsubscribeOperation:case j.PNWhereNowOperation:case j.PNHereNowOperation:case j.PNHeartbeatOperation:case j.PNSetStateOperation:case j.PNGetStateOperation:t="pres";break;case j.PNAddChannelsToGroupOperation:case j.PNRemoveChannelsFromGroupOperation:case j.PNChannelGroupsOperation:case j.PNRemoveGroupOperation:case j.PNChannelsForGroupOperation:t="cg";break;case j.PNPushNotificationEnabledChannelsOperation:case j.PNRemoveAllPushNotificationsOperation:t="push";break;case j.PNCreateUserOperation:case j.PNUpdateUserOperation:case j.PNDeleteUserOperation:case j.PNGetUserOperation:case j.PNGetUsersOperation:case j.PNCreateSpaceOperation:case j.PNUpdateSpaceOperation:case j.PNDeleteSpaceOperation:case j.PNGetSpaceOperation:case j.PNGetSpacesOperation:case j.PNGetMembersOperation:case j.PNUpdateMembersOperation:case j.PNGetMembershipsOperation:case j.PNUpdateMembershipsOperation:t="obj";break;case j.PNAddMessageActionOperation:case j.PNRemoveMessageActionOperation:case j.PNGetMessageActionsOperation:t="msga";break;case j.PNAccessManagerGrant:case j.PNAccessManagerAudit:t="pam";break;case j.PNAccessManagerGrantToken:case j.PNAccessManagerRevokeToken:t="pamv3";break;default:t="time"}return t},e}(),x=function(){function e(e,t,n){this._payload=e,this._setDefaultPayloadStructure(),this.title=t,this.body=n}return Object.defineProperty(e.prototype,"payload",{get:function(){return this._payload},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{set:function(e){this._title=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{set:function(e){this._subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{set:function(e){this._body=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{set:function(e){this._badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{set:function(e){this._sound=e},enumerable:!1,configurable:!0}),e.prototype._setDefaultPayloadStructure=function(){},e.prototype.toObject=function(){return{}},e}(),U=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"configurations",{set:function(e){e&&e.length&&(this._configurations=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"notification",{get:function(){return this._payload.aps},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.aps.alert.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){e&&e.length&&(this._payload.aps.alert.subtitle=e,this._subtitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.aps.alert.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this._badge},set:function(e){null!=e&&(this._payload.aps.badge=e,this._badge=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.aps.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),r.prototype._setDefaultPayloadStructure=function(){this._payload.aps={alert:{}}},r.prototype.toObject=function(){var e=this,t=n({},this._payload),r=t.aps,o=r.alert;if(this._isSilent&&(r["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");var i=[];this._configurations.forEach((function(t){i.push(e._objectFromAPNS2Configuration(t))})),i.length&&(t.pn_push=i)}return o&&Object.keys(o).length||delete r.alert,this._isSilent&&(delete r.alert,delete r.badge,delete r.sound,o={}),this._isSilent||Object.keys(o).length?t:null},r.prototype._objectFromAPNS2Configuration=function(e){var t=this;if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");var n=[];e.targets.forEach((function(e){n.push(t._objectFromAPNSTarget(e))}));var r=e.collapseId,o=e.expirationDate,i={auth_method:"token",targets:n,version:"v2"};return r&&r.length&&(i.collapse_id=r),o&&(i.expiration=o.toISOString()),i},r.prototype._objectFromAPNSTarget=function(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");var t=e.topic,n=e.environment,r=void 0===n?"development":n,o=e.excludedDevices,i=void 0===o?[]:o,s={topic:t,environment:r};return i.length&&(s.excluded_devices=i),s},r}(x),I=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"backContent",{get:function(){return this._backContent},set:function(e){e&&e.length&&(this._payload.back_content=e,this._backContent=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"backTitle",{get:function(){return this._backTitle},set:function(e){e&&e.length&&(this._payload.back_title=e,this._backTitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"count",{get:function(){return this._count},set:function(e){null!=e&&(this._payload.count=e,this._count=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"type",{get:function(){return this._type},set:function(e){e&&e.length&&(this._payload.type=e,this._type=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this.backTitle},set:function(e){this.backTitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this.backContent},set:function(e){this.backContent=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this.count},set:function(e){this.count=e},enumerable:!1,configurable:!0}),r.prototype.toObject=function(){return Object.keys(this._payload).length?n({},this._payload):null},r}(x),D=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return t(o,e),Object.defineProperty(o.prototype,"notification",{get:function(){return this._payload.notification},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"data",{get:function(){return this._payload.data},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.notification.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.notification.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.notification.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"icon",{get:function(){return this._icon},set:function(e){e&&e.length&&(this._payload.notification.icon=e,this._icon=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"tag",{get:function(){return this._tag},set:function(e){e&&e.length&&(this._payload.notification.tag=e,this._tag=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),o.prototype._setDefaultPayloadStructure=function(){this._payload.notification={},this._payload.data={}},o.prototype.toObject=function(){var e=n({},this._payload.data),t=null,o={};if(Object.keys(this._payload).length>2){var i=this._payload;i.notification,i.data;var s=r(i,["notification","data"]);e=n(n({},e),s)}return this._isSilent?e.notification=this._payload.notification:t=this._payload.notification,Object.keys(e).length&&(o.data=e),t&&Object.keys(t).length&&(o.notification=t),Object.keys(o).length?o:null},o}(x),F=function(){function e(e,t){this._payload={apns:{},mpns:{},fcm:{}},this._title=e,this._body=t,this.apns=new U(this._payload.apns,e,t),this.mpns=new I(this._payload.mpns,e,t),this.fcm=new D(this._payload.fcm,e,t)}return Object.defineProperty(e.prototype,"debugging",{set:function(e){this._debugging=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this._body},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){this._subtitle=e,this.apns.subtitle=e,this.mpns.subtitle=e,this.fcm.subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{get:function(){return this._badge},set:function(e){this._badge=e,this.apns.badge=e,this.mpns.badge=e,this.fcm.badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{get:function(){return this._sound},set:function(e){this._sound=e,this.apns.sound=e,this.mpns.sound=e,this.fcm.sound=e},enumerable:!1,configurable:!0}),e.prototype.buildPayload=function(e){var t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";var n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("mpns")){var r=this.mpns.toObject();r&&Object.keys(r).length&&(t.pn_mpns=r)}if(e.includes("fcm")){var o=this.fcm.toObject();o&&Object.keys(o).length&&(t.pn_gcm=o)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t},e}(),L=function(){function e(){this._listeners=[]}return e.prototype.addListener=function(e){this._listeners.includes(e)||this._listeners.push(e)},e.prototype.removeListener=function(e){var t=[];this._listeners.forEach((function(n){n!==e&&t.push(n)})),this._listeners=t},e.prototype.removeAllListeners=function(){this._listeners=[]},e.prototype.announcePresence=function(e){this._listeners.forEach((function(t){t.presence&&t.presence(e)}))},e.prototype.announceStatus=function(e){this._listeners.forEach((function(t){t.status&&t.status(e)}))},e.prototype.announceMessage=function(e){this._listeners.forEach((function(t){t.message&&t.message(e)}))},e.prototype.announceSignal=function(e){this._listeners.forEach((function(t){t.signal&&t.signal(e)}))},e.prototype.announceMessageAction=function(e){this._listeners.forEach((function(t){t.messageAction&&t.messageAction(e)}))},e.prototype.announceFile=function(e){this._listeners.forEach((function(t){t.file&&t.file(e)}))},e.prototype.announceObjects=function(e){this._listeners.forEach((function(t){t.objects&&t.objects(e)}))},e.prototype.announceUser=function(e){this._listeners.forEach((function(t){t.user&&t.user(e)}))},e.prototype.announceSpace=function(e){this._listeners.forEach((function(t){t.space&&t.space(e)}))},e.prototype.announceMembership=function(e){this._listeners.forEach((function(t){t.membership&&t.membership(e)}))},e.prototype.announceNetworkUp=function(){var e={};e.category=k.PNNetworkUpCategory,this.announceStatus(e)},e.prototype.announceNetworkDown=function(){var e={};e.category=k.PNNetworkDownCategory,this.announceStatus(e)},e}(),G=function(){function e(e,t){this._config=e,this._cbor=t}return e.prototype.setToken=function(e){e&&e.length>0?this._token=e:this._token=void 0},e.prototype.getToken=function(){return this._token},e.prototype.extractPermissions=function(e){var t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128==(128&e)&&(t.join=!0),64==(64&e)&&(t.update=!0),32==(32&e)&&(t.get=!0),8==(8&e)&&(t.delete=!0),4==(4&e)&&(t.manage=!0),2==(2&e)&&(t.write=!0),1==(1&e)&&(t.read=!0),t},e.prototype.parseToken=function(e){var t=this,n=this._cbor.decodeToken(e);if(void 0!==n){var r=n.res.uuid?Object.keys(n.res.uuid):[],o=Object.keys(n.res.chan),i=Object.keys(n.res.grp),s=n.pat.uuid?Object.keys(n.pat.uuid):[],a=Object.keys(n.pat.chan),u=Object.keys(n.pat.grp),c={version:n.v,timestamp:n.t,ttl:n.ttl,authorized_uuid:n.uuid},l=r.length>0,p=o.length>0,h=i.length>0;(l||p||h)&&(c.resources={},l&&(c.resources.uuids={},r.forEach((function(e){c.resources.uuids[e]=t.extractPermissions(n.res.uuid[e])}))),p&&(c.resources.channels={},o.forEach((function(e){c.resources.channels[e]=t.extractPermissions(n.res.chan[e])}))),h&&(c.resources.groups={},i.forEach((function(e){c.resources.groups[e]=t.extractPermissions(n.res.grp[e])}))));var f=s.length>0,d=a.length>0,y=u.length>0;return(f||d||y)&&(c.patterns={},f&&(c.patterns.uuids={},s.forEach((function(e){c.patterns.uuids[e]=t.extractPermissions(n.pat.uuid[e])}))),d&&(c.patterns.channels={},a.forEach((function(e){c.patterns.channels[e]=t.extractPermissions(n.pat.chan[e])}))),y&&(c.patterns.groups={},u.forEach((function(e){c.patterns.groups[e]=t.extractPermissions(n.pat.grp[e])})))),Object.keys(n.meta).length>0&&(c.meta=n.meta),c.signature=n.sig,c}},e}();function K(e){return encodeURIComponent(e).replace(/[!~*'()]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())}))}function B(e){return function(e){var t=[];return Object.keys(e).forEach((function(e){return t.push(e)})),t}(e).sort()}var H={signPamFromParams:function(e){return B(e).map((function(t){return"".concat(t,"=").concat(K(e[t]))})).join("&")},endsWith:function(e,t){return-1!==e.indexOf(t,this.length-t.length)},createPromise:function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),reject:t,fulfill:e}},encodeString:K,stringToArrayBuffer:function(e){for(var t=new ArrayBuffer(2*e.length),n=new Uint16Array(t),r=0,o=e.length;r0&&(t+=n),t}function J(e,t,n){return t.usePost&&t.usePost(e,n)?"POST":t.usePatch&&t.usePatch(e,n)?"PATCH":t.useDelete&&t.useDelete(e,n)?"DELETE":t.useGetFile&&t.useGetFile(e,n)?"GETFILE":"GET"}function $(e,t,n,r,o){var i=e.config,s=e.crypto,a=J(e,o,r);n.timestamp=Math.floor((new Date).getTime()/1e3),"PNPublishOperation"===o.getOperation()&&o.usePost&&o.usePost(e,r)&&(a="GET"),"GETFILE"===a&&(a="GET");var u="".concat(a,"\n").concat(i.publishKey,"\n").concat(t,"\n").concat(H.signPamFromParams(n),"\n");if("POST"===a)u+="string"==typeof(c=o.postPayload(e,r))?c:JSON.stringify(c);else if("PATCH"===a){var c;u+="string"==typeof(c=o.patchPayload(e,r))?c:JSON.stringify(c)}var l="v2.".concat(s.HMACSHA256(u));l=(l=(l=l.replace(/\+/g,"-")).replace(/\//g,"_")).replace(/=+$/,""),n.signature=l}function Q(e,t){for(var r=[],o=2;o0&&(c.count=u),c},handleResponse:function(e,t){return{channels:t}}});var ie=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveAllPushNotificationsOperation},validateParams:function(e,t){var n=t.device,r=t.pushGateway,o=t.topic,i=e.config;return n?r?"apns2"!==r||o?i.subscribeKey?void 0:"Missing Subscribe Key":"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm, apns or apns2)":"Missing Device ID (device)"},getURL:function(e,t){var n=t.device,r=t.pushGateway,o=e.config;return"apns2"===r?"/v2/push/sub-key/".concat(o.subscribeKey,"/devices-apns2/").concat(n,"/remove"):"/v1/push/sub-key/".concat(o.subscribeKey,"/devices/").concat(n,"/remove")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.pushGateway,o=t.environment,i=void 0===o?"development":o,s=t.topic,a={type:r};return"apns2"===r&&delete(a=n(n({},a),{environment:i,topic:s})).type,a},handleResponse:function(){return{}}});var se=Object.freeze({__proto__:null,getOperation:function(){return j.PNUnsubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/leave")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(){return{}}});var ae=Object.freeze({__proto__:null,getOperation:function(){return j.PNWhereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r;return"/v2/presence/sub-key/".concat(n.subscribeKey,"/uuid/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return t.payload?{channels:t.payload.channels}:{channels:[]}}});var ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNHeartbeatOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/heartbeat")},isAuthSupported:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o=t.state,i=e.config,s={};return r.length>0&&(s["channel-group"]=r.join(",")),o&&(s.state=JSON.stringify(o)),s.heartbeat=i.getPresenceTimeout(),s},handleResponse:function(){return{}}});var ce=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetStateOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r,i=t.channels,s=void 0===i?[]:i,a=s.length>0?s.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(a),"/uuid/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a={};return 1===o.length&&0===s.length?a[o[0]]=t.payload:a=t.payload,{channels:a}}});var le=Object.freeze({__proto__:null,getOperation:function(){return j.PNSetStateOperation},validateParams:function(e,t){var n=e.config,r=t.state,o=t.channels,i=void 0===o?[]:o,s=t.channelGroups,a=void 0===s?[]:s;return r?n.subscribeKey?0===i.length&&0===a.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key":"Missing State"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/uuid/").concat(H.encodeString(n.UUID),"/data")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.state,r=t.channelGroups,o=void 0===r?[]:r,i={};return i.state=JSON.stringify(n),o.length>0&&(i["channel-group"]=o.join(",")),i},handleResponse:function(e,t){return{state:t.payload}}});var pe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=t.channelGroups,s=void 0===i?[]:i,a="/v2/presence/sub-key/".concat(n.subscribeKey);if(o.length>0||s.length>0){var u=o.length>0?o.join(","):",";a+="/channel/".concat(H.encodeString(u))}return a},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.channelGroups,o=void 0===r?[]:r,i=t.includeUUIDs,s=void 0===i||i,a=t.includeState,u=void 0!==a&&a,c=t.queryParameters,l=void 0===c?{}:c,p={};return s||(p.disable_uuids=1),u&&(p.state=1),o.length>0&&(p["channel-group"]=o.join(",")),p=n(n({},p),l)},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a=n.includeUUIDs,u=void 0===a||a,c=n.includeState,l=void 0!==c&&c;return o.length>1||s.length>0||0===s.length&&0===o.length?function(){var e={};return e.totalChannels=t.payload.total_channels,e.totalOccupancy=t.payload.total_occupancy,e.channels={},Object.keys(t.payload.channels).forEach((function(n){var r=t.payload.channels[n],o=[];return e.channels[n]={occupants:o,name:n,occupancy:r.occupancy},u&&r.uuids.forEach((function(e){l?o.push({state:e.state,uuid:e.uuid}):o.push({state:null,uuid:e})})),e})),e}():function(){var e={},n=[];return e.totalChannels=1,e.totalOccupancy=t.occupancy,e.channels={},e.channels[o[0]]={occupants:n,name:o[0],occupancy:t.occupancy},u&&t.uuids&&t.uuids.forEach((function(e){l?n.push({state:e.state,uuid:e.uuid}):n.push({state:null,uuid:e})})),e}()},handleError:function(e,t,n){402!==n.statusCode||this.getURL(e,t).includes("channel")||(n.errorData.message="You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.")}});var he=Object.freeze({__proto__:null,getOperation:function(){return j.PNAddMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.action,o=t.channel;return t.messageTimetoken?n.subscribeKey?o?r?r.value?r.type?r.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message channel":"Missing Subscribe Key":"Missing message timetoken"},usePost:function(){return!0},postURL:function(e,t){var n=e.config,r=t.channel,o=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},getRequestHeaders:function(){return{"Content-Type":"application/json"}},isAuthSupported:function(){return!0},prepareParams:function(){return{}},postPayload:function(e,t){return t.action},handleResponse:function(e,t){return{data:t.data}}});var fe=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken;return t.messageTimetoken?o?n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key":"Missing action timetoken":"Missing message timetoken"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken,i=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(i,"/action/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{data:t.data}}});var de=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetMessageActionsOperation},validateParams:function(e,t){var n=e.config,r=t.channel;return n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channel;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.limit,r=t.start,o=t.end,i={};return n&&(i.limit=n),r&&(i.start=r),o&&(i.end=o),i},handleResponse:function(e,t){var n={data:t.data,start:null,end:null};return n.data.length&&(n.end=n.data[n.data.length-1].actionTimetoken,n.start=n.data[0].actionTimetoken),n}}),ye={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel can't be empty"},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.limit&&(n.limit=t.limit),t.next&&(n.next=t.next),n},handleResponse:function(e,t){return{status:t.status,data:t.data,next:t.next,count:t.count}}},ge={getOperation:function(){return j.PNGenerateUploadUrlOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?void 0:"name can't be empty":"channel can't be empty"},usePost:function(){return!0},postURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/generate-upload-url")},postPayload:function(e,t){return{name:t.name}},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data,file_upload_request:t.file_upload_request}}},me={getOperation:function(){return j.PNPublishFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.fileId)?(null==t?void 0:t.fileName)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},getURL:function(e,t){var n=e.config,r=n.publishKey,o=n.subscribeKey,i=function(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}(e,{message:t.message,file:{name:t.fileName,id:t.fileId}});return"/v1/files/publish-file/".concat(r,"/").concat(o,"/0/").concat(H.encodeString(t.channel),"/0/").concat(H.encodeString(i))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.ttl&&(n.ttl=t.ttl),void 0!==t.storeInHistory&&(n.store=t.storeInHistory?"1":"0"),t.meta&&"object"==typeof t.meta&&(n.meta=JSON.stringify(t.meta)),n},handleResponse:function(e,t){return{timetoken:t[2]}}},be=function(e){var t=function(e){var t=this,n=e.generateUploadUrl,r=e.publishFile,s=e.modules,a=s.PubNubFile,u=s.config,c=s.cryptography,l=s.cryptoModule,p=s.networking;return function(e){var s=e.channel,h=e.file,f=e.message,d=e.cipherKey,y=e.meta,g=e.ttl,m=e.storeInHistory;return o(t,void 0,void 0,(function(){var e,t,o,b,v,_,S,w,O,P,E,A,T,N,C,k,M,j,R,x,U,I,D,F,L,G,K,B,H;return i(this,(function(i){switch(i.label){case 0:if(!s)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!h)throw new q("Validation failed, check status for details",z("file can't be empty"));return e=a.create(h),[4,n({channel:s,name:e.name})];case 1:return t=i.sent(),o=t.file_upload_request,b=o.url,v=o.form_fields,_=t.data,S=_.id,w=_.name,a.supportsEncryptFile&&(d||l)?null!=d?[3,3]:[4,l.encryptFile(e,a)]:[3,6];case 2:return O=i.sent(),[3,5];case 3:return[4,c.encryptFile(d,e,a)];case 4:O=i.sent(),i.label=5;case 5:e=O,i.label=6;case 6:P=v,e.mimeType&&(P=v.map((function(t){return"Content-Type"===t.key?{key:t.key,value:e.mimeType}:t}))),i.label=7;case 7:return i.trys.push([7,21,,22]),a.supportsFileUri&&h.uri?(T=(A=p).POSTFILE,N=[b,P],[4,e.toFileUri()]):[3,10];case 8:return[4,T.apply(A,N.concat([i.sent()]))];case 9:return E=i.sent(),[3,20];case 10:return a.supportsFile?(k=(C=p).POSTFILE,M=[b,P],[4,e.toFile()]):[3,13];case 11:return[4,k.apply(C,M.concat([i.sent()]))];case 12:return E=i.sent(),[3,20];case 13:return a.supportsBuffer?(R=(j=p).POSTFILE,x=[b,P],[4,e.toBuffer()]):[3,16];case 14:return[4,R.apply(j,x.concat([i.sent()]))];case 15:return E=i.sent(),[3,20];case 16:return a.supportsBlob?(I=(U=p).POSTFILE,D=[b,P],[4,e.toBlob()]):[3,19];case 17:return[4,I.apply(U,D.concat([i.sent()]))];case 18:return E=i.sent(),[3,20];case 19:throw new Error("Unsupported environment");case 20:return[3,22];case 21:throw(F=i.sent()).response&&"string"==typeof F.response.text?(L=F.response.text,G=/(.*)<\/Message>/gi.exec(L),new q(G?"Upload to bucket failed: ".concat(G[1]):"Upload to bucket failed.",F)):new q("Upload to bucket failed.",F);case 22:if(204!==E.status)throw new q("Upload to bucket was unsuccessful",E);K=u.fileUploadPublishRetryLimit,B=!1,H={timetoken:"0"},i.label=23;case 23:return i.trys.push([23,25,,26]),[4,r({channel:s,message:f,fileId:S,fileName:w,meta:y,storeInHistory:m,ttl:g})];case 24:return H=i.sent(),B=!0,[3,26];case 25:return i.sent(),K-=1,[3,26];case 26:if(!B&&K>0)return[3,23];i.label=27;case 27:if(B)return[2,{timetoken:H.timetoken,id:S,name:w}];throw new q("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{channel:s,id:S,name:w})}}))}))}}(e);return function(e,n){var r=t(e);return"function"==typeof n?(r.then((function(e){return n(null,e)})).catch((function(e){return n(e,null)})),r):r}},ve=function(e,t){var n=t.channel,r=t.id,o=t.name,i=e.config,s=e.networking,a=e.tokenManager;if(!n)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!r)throw new q("Validation failed, check status for details",z("file id can't be empty"));if(!o)throw new q("Validation failed, check status for details",z("file name can't be empty"));var u="/v1/files/".concat(i.subscribeKey,"/channels/").concat(H.encodeString(n),"/files/").concat(r,"/").concat(o),c={};c.uuid=i.getUUID(),c.pnsdk=W(i);var l=a.getToken()||i.getAuthKey();l&&(c.auth=l),i.secretKey&&$(e,u,c,{},{getOperation:function(){return"PubNubGetFileUrlOperation"}});var p=Object.keys(c).map((function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(c[e]))})).join("&");return""!==p?"".concat(s.getStandardOrigin()).concat(u,"?").concat(p):"".concat(s.getStandardOrigin()).concat(u)},_e={getOperation:function(){return j.PNDownloadFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?(null==t?void 0:t.id)?void 0:"id can't be empty":"name can't be empty":"channel can't be empty"},useGetFile:function(){return!0},getFileURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},ignoreBody:function(){return!0},forceBuffered:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t,n){var r=e.PubNubFile,s=e.config,a=e.cryptography,u=e.cryptoModule;return o(void 0,void 0,void 0,(function(){var e,o,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.response.body,r.supportsEncryptFile&&(n.cipherKey||u)?null!=n.cipherKey?[3,2]:[4,u.decryptFile(r.create({data:e,name:n.name}),r)]:[3,5];case 1:return o=i.sent().data,[3,4];case 2:return[4,a.decrypt(null!==(c=n.cipherKey)&&void 0!==c?c:s.cipherKey,e)];case 3:o=i.sent(),i.label=4;case 4:e=o,i.label=5;case 5:return[2,r.create({data:e,name:null!==(l=t.response.name)&&void 0!==l?l:n.name,mimeType:t.response.type})]}}))}))}},Se={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.id)?(null==t?void 0:t.name)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status}}},we={getOperation:function(){return j.PNGetAllUUIDMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,next:t.next,prev:t.prev}}},Oe={getOperation:function(){return j.PNGetUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Pe={getOperation:function(){return j.PNSetUUIDMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.data))return"Data cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ee={getOperation:function(){return j.PNRemoveUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r=e.config;return{uuid:null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ae={getOperation:function(){return j.PNGetAllChannelMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Te={getOperation:function(){return j.PNGetChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ne={getOperation:function(){return j.PNSetChannelMetadataOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.data)?void 0:"Data cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ce={getOperation:function(){return j.PNRemoveChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},ke={getOperation:function(){return j.PNGetMembersOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&m.include.push("uuid"),(null===(i=t.include)||void 0===i?void 0:i.customUUIDFields)&&m.include.push("uuid.custom"),(null===(s=t.include)||void 0===s?void 0:s.UUIDStatusField)&&m.include.push("uuid.status"),(null===(u=t.include)||void 0===u?void 0:u.UUIDTypeField)&&m.include.push("uuid.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Me={getOperation:function(){return j.PNSetMembersOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.uuids)&&0!==(null==t?void 0:t.uuids.length)?void 0:"UUIDs cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.uuids.map((function(e){return"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["uuid.status","uuid.type","type"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customUUIDFields)&&h.include.push("uuid.custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&h.include.push("uuid")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},je={getOperation:function(){return j.PNGetMembershipsOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&m.include.push("channel"),(null===(i=t.include)||void 0===i?void 0:i.customChannelFields)&&m.include.push("channel.custom"),(null===(s=t.include)||void 0===s?void 0:s.channelStatusField)&&m.include.push("channel.status"),(null===(u=t.include)||void 0===u?void 0:u.channelTypeField)&&m.include.push("channel.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Re={getOperation:function(){return j.PNSetMembershipsOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)||0===(null==t?void 0:t.channels.length))return"Channels cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.channels.map((function(e){return"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["channel.status","channel.type","status"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customChannelFields)&&h.include.push("channel.custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&h.include.push("channel")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}};var xe=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerAudit},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/audit/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channel,r=t.channelGroup,o=t.authKeys,i=void 0===o?[]:o,s={};return n&&(s.channel=n),r&&(s["channel-group"]=r),i.length>0&&(s.auth=i.join(",")),s},handleResponse:function(e,t){return t.payload}});var Ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrant},validateParams:function(e,t){var n=e.config;return n.subscribeKey?n.publishKey?n.secretKey?null==t.uuids||t.authKeys?null==t.uuids||null==t.channels&&null==t.channelGroups?void 0:"Both channel/channelgroup and uuid cannot be used in the same request":"authKeys are required for grant request on uuids":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/grant/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.uuids,a=void 0===s?[]:s,u=t.ttl,c=t.read,l=void 0!==c&&c,p=t.write,h=void 0!==p&&p,f=t.manage,d=void 0!==f&&f,y=t.get,g=void 0!==y&&y,m=t.join,b=void 0!==m&&m,v=t.update,_=void 0!==v&&v,S=t.authKeys,w=void 0===S?[]:S,O=t.delete,P={};return P.r=l?"1":"0",P.w=h?"1":"0",P.m=d?"1":"0",P.d=O?"1":"0",P.g=g?"1":"0",P.j=b?"1":"0",P.u=_?"1":"0",r.length>0&&(P.channel=r.join(",")),i.length>0&&(P["channel-group"]=i.join(",")),w.length>0&&(P.auth=w.join(",")),a.length>0&&(P["target-uuid"]=a.join(",")),(u||0===u)&&(P.ttl=u),P},handleResponse:function(){return{}}});function Ie(e){var t,n,r,o,i=void 0!==(null==e?void 0:e.authorizedUserId),s=void 0!==(null===(t=null==e?void 0:e.resources)||void 0===t?void 0:t.users),a=void 0!==(null===(n=null==e?void 0:e.resources)||void 0===n?void 0:n.spaces),u=void 0!==(null===(r=null==e?void 0:e.patterns)||void 0===r?void 0:r.users),c=void 0!==(null===(o=null==e?void 0:e.patterns)||void 0===o?void 0:o.spaces);return u||s||c||a||i}function De(e){var t=0;return e.join&&(t|=128),e.update&&(t|=64),e.get&&(t|=32),e.delete&&(t|=8),e.manage&&(t|=4),e.write&&(t|=2),e.read&&(t|=1),t}function Fe(e,t){if(Ie(t))return function(e,t){var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorizedUserId,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.users,c=r.spaces,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.users,h=o.spaces,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}(0,t);var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorized_uuid,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.uuids,c=r.channels,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.uuids,h=o.channels,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}var Le=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrantToken},extractPermissions:De,validateParams:function(e,t){var n,r,o,i,s,a,u=e.config;if(!u.subscribeKey)return"Missing Subscribe Key";if(!u.publishKey)return"Missing Publish Key";if(!u.secretKey)return"Missing Secret Key";if(!t.resources&&!t.patterns)return"Missing either Resources or Patterns.";var c=void 0!==(null==t?void 0:t.authorized_uuid),l=void 0!==(null===(n=null==t?void 0:t.resources)||void 0===n?void 0:n.uuids),p=void 0!==(null===(r=null==t?void 0:t.resources)||void 0===r?void 0:r.channels),h=void 0!==(null===(o=null==t?void 0:t.resources)||void 0===o?void 0:o.groups),f=void 0!==(null===(i=null==t?void 0:t.patterns)||void 0===i?void 0:i.uuids),d=void 0!==(null===(s=null==t?void 0:t.patterns)||void 0===s?void 0:s.channels),y=void 0!==(null===(a=null==t?void 0:t.patterns)||void 0===a?void 0:a.groups),g=c||l||f||p||d||h||y;return Ie(t)&&g?"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`":(!t.resources||t.resources.uuids&&0!==Object.keys(t.resources.uuids).length||t.resources.channels&&0!==Object.keys(t.resources.channels).length||t.resources.groups&&0!==Object.keys(t.resources.groups).length||t.resources.users&&0!==Object.keys(t.resources.users).length||t.resources.spaces&&0!==Object.keys(t.resources.spaces).length)&&(!t.patterns||t.patterns.uuids&&0!==Object.keys(t.patterns.uuids).length||t.patterns.channels&&0!==Object.keys(t.patterns.channels).length||t.patterns.groups&&0!==Object.keys(t.patterns.groups).length||t.patterns.users&&0!==Object.keys(t.patterns.users).length||t.patterns.spaces&&0!==Object.keys(t.patterns.spaces).length)?void 0:"Missing values for either Resources or Patterns."},postURL:function(e){var t=e.config;return"/v3/pam/".concat(t.subscribeKey,"/grant")},usePost:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(){return{}},postPayload:function(e,t){return Fe(0,t)},handleResponse:function(e,t){return t.data.token}}),Ge={getOperation:function(){return j.PNAccessManagerRevokeToken},validateParams:function(e,t){return e.config.secretKey?t?void 0:"token can't be empty":"Missing Secret Key"},getURL:function(e,t){var n=e.config;return"/v3/pam/".concat(n.subscribeKey,"/grant/").concat(H.encodeString(t))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e){return{uuid:e.config.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}};function Ke(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}var Be=Object.freeze({__proto__:null,getOperation:function(){return j.PNPublishOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},usePost:function(e,t){var n=t.sendByPost;return void 0!==n&&n},getURL:function(e,t){var n=e.config,r=t.channel,o=Ke(e,t.message);return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0/").concat(H.encodeString(o))},postURL:function(e,t){var n=e.config,r=t.channel;return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},postPayload:function(e,t){return Ke(e,t.message)},prepareParams:function(e,t){var n=t.meta,r=t.replicate,o=void 0===r||r,i=t.storeInHistory,s=t.ttl,a={};return null!=i&&(a.store=i?"1":"0"),s&&(a.ttl=s),!1===o&&(a.norep="true"),n&&"object"==typeof n&&(a.meta=JSON.stringify(n)),a},handleResponse:function(e,t){return{timetoken:t[2]}}});var He=Object.freeze({__proto__:null,getOperation:function(){return j.PNSignalOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},getURL:function(e,t){var n,r=e.config,o=t.channel,i=t.message,s=(n=i,JSON.stringify(n));return"/signal/".concat(r.publishKey,"/").concat(r.subscribeKey,"/0/").concat(H.encodeString(o),"/0/").concat(H.encodeString(s))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{timetoken:t[2]}}});var qe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHistoryOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channel,r=e.config;return"/v2/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o=t.reverse,i=t.count,s=void 0===i?100:i,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p={include_token:"true"};return p.count=s,n&&(p.start=n),r&&(p.end=r),u&&(p.string_message_token="true"),null!=o&&(p.reverse=o.toString()),l&&(p.include_meta="true"),p},handleResponse:function(e,t){var n={messages:[],startTimeToken:t[1],endTimeToken:t[2]};return Array.isArray(t[0])&&t[0].forEach((function(t){var r=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message),o={timetoken:t.timetoken,entry:r.payload};t.meta&&(o.meta=t.meta),r.error&&(o.error=r.error),n.messages.push(o)})),n}});var ze=Object.freeze({__proto__:null,getOperation:function(){return j.PNDeleteMessagesOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},useDelete:function(){return!0},getURL:function(e,t){var n=t.channel,r=e.config;return"/v3/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o={};return n&&(o.start=n),r&&(o.end=r),o},handleResponse:function(e,t){return t.payload}});var Ve=Object.freeze({__proto__:null,getOperation:function(){return j.PNMessageCounts},validateParams:function(e,t){var n=t.channels,r=t.timetoken,o=t.channelTimetokens,i=e.config;return n?r&&o?"timetoken and channelTimetokens are incompatible together":o&&o.length>1&&n.length!==o.length?"Length of channelTimetokens and channels do not match":i.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channels,r=e.config,o=n.join(",");return"/v3/history/sub-key/".concat(r.subscribeKey,"/message-counts/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.timetoken,r=t.channelTimetokens,o={};if(r&&1===r.length){var i=a(r,1)[0];o.timetoken=i}else r?o.channelsTimetoken=r.join(","):n&&(o.timetoken=n);return o},handleResponse:function(e,t){return{channels:t.channels}}});var We=Object.freeze({__proto__:null,getOperation:function(){return j.PNFetchMessagesOperation},validateParams:function(e,t){var n=t.channels,r=t.includeMessageActions,o=void 0!==r&&r,i=e.config;if(!n||0===n.length)return"Missing channels";if(!i.subscribeKey)return"Missing Subscribe Key";if(o&&n.length>1)throw new TypeError("History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.")},getURL:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.includeMessageActions,i=void 0!==o&&o,s=e.config,a=i?"history-with-actions":"history",u=r.length>0?r.join(","):",";return"/v3/".concat(a,"/sub-key/").concat(s.subscribeKey,"/channel/").concat(H.encodeString(u))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channels,r=t.start,o=t.end,i=t.includeMessageActions,s=t.count,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p=t.includeUuid,h=t.includeUUID,f=void 0===h||h,d=t.includeMessageType,y=void 0===d||d,g={};return g.max=s||(n.length>1||!0===i?25:100),r&&(g.start=r),o&&(g.end=o),u&&(g.string_message_token="true"),l&&(g.include_meta="true"),f&&!1!==p&&(g.include_uuid="true"),y&&(g.include_message_type="true"),g},handleResponse:function(e,t){var n={channels:{}};return Object.keys(t.channels||{}).forEach((function(r){n.channels[r]=[],(t.channels[r]||[]).forEach((function(t){var o={},i=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message);o.channel=r,o.timetoken=t.timetoken,o.message=i.payload,o.messageType=t.message_type,o.uuid=t.uuid,t.actions&&(o.actions=t.actions,o.data=t.actions),t.meta&&(o.meta=t.meta),i.error&&(o.error=i.error),n.channels[r].push(o)}))})),t.more&&(n.more=t.more),n}});var Je=Object.freeze({__proto__:null,getOperation:function(){return j.PNTimeOperation},getURL:function(){return"/time/0"},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(){return{}},isAuthSupported:function(){return!1},handleResponse:function(e,t){return{timetoken:t[0]}},validateParams:function(){}});var $e=Object.freeze({__proto__:null,getOperation:function(){return j.PNSubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=e.config,r=t.state,o=t.channelGroups,i=void 0===o?[]:o,s=t.timetoken,a=t.filterExpression,u=t.region,c={heartbeat:n.getPresenceTimeout()};return i.length>0&&(c["channel-group"]=i.join(",")),a&&a.length>0&&(c["filter-expr"]=a),Object.keys(r).length&&(c.state=JSON.stringify(r)),s&&(c.tt=s),u&&(c.tr=u),c},handleResponse:function(e,t){var n=[];t.m.forEach((function(e){var t={timetoken:e.p.t,region:e.p.r},r={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:t};n.push(r)}));var r={timetoken:t.t.t,region:t.t.r};return{messages:n,metadata:r}}}),Qe={getOperation:function(){return j.PNHandshakeOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)&&!(null==t?void 0:t.channelGroups))return"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),n.tt=0,t.state&&(n.state=JSON.stringify(t.state)),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.ee="",n},handleResponse:function(e,t){return{region:t.t.r,timetoken:t.t.t}}},Xe={getOperation:function(){return j.PNReceiveMessagesOperation},validateParams:function(e,t){return(null==t?void 0:t.channels)||(null==t?void 0:t.channelGroups)?(null==t?void 0:t.timetoken)?(null==t?void 0:t.region)?void 0:"region can not be empty":"timetoken can not be empty":"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},getAbortSignal:function(e,t){return t.abortSignal},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.tt=t.timetoken,n.tr=t.region,n.ee="",n},handleResponse:function(e,t){var n=[];return t.m.forEach((function(e){var t={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:{timetoken:e.p.t,region:e.p.r}};n.push(t)})),{messages:n,metadata:{region:t.t.r,timetoken:t.t.t}}}},Ye=function(){function e(e){void 0===e&&(e=!1),this.sync=e,this.listeners=new Set}return e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.notify=function(e){var t=this,n=function(){t.listeners.forEach((function(t){t(e)}))};this.sync?n():setTimeout(n,0)},e}(),Ze=function(){function e(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}return e.prototype.transition=function(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)},e.prototype.on=function(e,t){return this.transitionMap.set(e,t),this},e.prototype.with=function(e,t){return[this,e,null!=t?t:[]]},e.prototype.onEnter=function(e){return this.enterEffects.push(e),this},e.prototype.onExit=function(e){return this.exitEffects.push(e),this},e}(),et=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return t(n,e),n.prototype.describe=function(e){return new Ze(e)},n.prototype.start=function(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})},n.prototype.transition=function(e){var t,n,r,o,i,u;if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});var c=this.currentState.transition(this.currentContext,e);if(c){var l=a(c,3),p=l[0],h=l[1],f=l[2];try{for(var d=s(this.currentState.exitEffects),y=d.next();!y.done;y=d.next()){var g=y.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}var m=this.currentState;this.currentState=p;var b=this.currentContext;this.currentContext=h,this.notify({type:"transitionDone",fromState:m,fromContext:b,toState:p,toContext:h,event:e});try{for(var v=s(f),_=v.next();!_.done;_=v.next()){g=_.value;this.notify({type:"invocationDispatched",invocation:g})}}catch(e){r={error:e}}finally{try{_&&!_.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var S=s(this.currentState.enterEffects),w=S.next();!w.done;w=S.next()){g=w.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){i={error:e}}finally{try{w&&!w.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}},n}(Ye),tt=function(){function e(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}return e.prototype.on=function(e,t){this.handlers.set(e,t)},e.prototype.dispatch=function(e){if("CANCEL"!==e.type){var t=this.handlers.get(e.type);if(!t)throw new Error("Unhandled invocation '".concat(e.type,"'"));var n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}else if(this.instances.has(e.payload)){var r=this.instances.get(e.payload);null==r||r.cancel(),this.instances.delete(e.payload)}},e.prototype.dispose=function(){var e,t;try{for(var n=s(this.instances.entries()),r=n.next();!r.done;r=n.next()){var o=a(r.value,2),i=o[0];o[1].cancel(),this.instances.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();function nt(e,t){var n=function(){for(var n=[],r=0;r0&&r(e),[2]}))}))}))),s.on(ht.type,ut((function(e,t,n){var r=n.emitStatus;return o(s,void 0,void 0,(function(){return i(this,(function(t){return r(e),[2]}))}))}))),s.on(ft.type,ut((function(e,n,r){var a=r.receiveMessages,u=r.delay,c=r.config;return o(s,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return c.retryConfiguration&&c.retryConfiguration.shouldRetry(e.reason,e.attempts)?(n.throwIfAborted(),[4,u(c.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),n.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,a({abortSignal:n,channels:e.channels,channelGroups:e.groups,timetoken:e.cursor.timetoken,region:e.cursor.region,filterExpression:c.filterExpression})];case 3:return r=i.sent(),[2,t.transition(Pt(r.metadata,r.messages))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Et(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(At(new q(c.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s.on(dt.type,ut((function(e,r,a){var u=a.handshake,c=a.delay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({abortSignal:r,channels:e.channels,channelGroups:e.groups,filterExpression:p.filterExpression},p.maintainPresenceState&&{state:l}))];case 3:return o=i.sent(),[2,t.transition(vt(o))];case 4:return(s=i.sent())instanceof Error&&"Aborted"===s.message?[2]:s instanceof q?[2,t.transition(_t(s))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(St(new q(p.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s}return t(r,e),r}(tt),Mt=new Ze("HANDSHAKE_FAILED");Mt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Mt.on(Nt.type,(function(e,t){return Ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor})})),Mt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(r=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==r?r:0}})})),Mt.on(Ct.type,(function(e){return Lt.with()}));var jt=new Ze("HANDSHAKE_STOPPED");jt.on(yt.type,(function(e,t){return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),jt.on(Nt.type,(function(e,t){return Ft.with(n(n({},e),{cursor:t.payload.cursor||e.cursor}))})),jt.on(gt.type,(function(e,t){var n;return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),jt.on(Ct.type,(function(e){return Lt.with()}));var Rt=new Ze("RECEIVE_FAILED");Rt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Rt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(Ct.type,(function(e){return Lt.with(void 0)}));var xt=new Ze("RECEIVE_STOPPED");xt.on(yt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),xt.on(gt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Ct.type,(function(){return Lt.with(void 0)}));var Ut=new Ze("RECEIVE_RECONNECTING");Ut.onEnter((function(e){return ft(e)})),Ut.onExit((function(){return ft.cancel})),Ut.on(Pt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),Ut.on(Et.type,(function(e,t){return Ut.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Ut.on(At.type,(function(e,t){var n;return Rt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Ut.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),Ut.on(gt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Ut.on(yt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ut.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var It=new Ze("RECEIVING");It.onEnter((function(e){return lt(e.channels,e.groups,e.cursor)})),It.onExit((function(){return lt.cancel})),It.on(wt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),It.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups})})),It.on(gt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),It.on(Ot.type,(function(e,t){return Ut.with(n(n({},e),{attempts:0,reason:t.payload}))})),It.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),It.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var Dt=new Ze("HANDSHAKE_RECONNECTING");Dt.onEnter((function(e){return dt(e)})),Dt.onExit((function(){return dt.cancel})),Dt.on(vt.type,(function(e,t){var n,r,o={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=e.cursor)||void 0===r?void 0:r.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return It.with({channels:e.channels,groups:e.groups,cursor:o},[ht({category:k.PNConnectedCategory})])})),Dt.on(_t.type,(function(e,t){return Dt.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Dt.on(St.type,(function(e,t){var n;return Mt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Dt.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Dt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Dt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.region)||0}})})),Dt.on(Ct.type,(function(e){return Lt.with(void 0)}));var Ft=new Ze("HANDSHAKING");Ft.onEnter((function(e){return ct(e.channels,e.groups)})),Ft.onExit((function(){return ct.cancel})),Ft.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ft.on(mt.type,(function(e,t){var n,r;return It.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.timetoken:t.payload.timetoken,region:t.payload.region}},[ht({category:k.PNConnectedCategory})])})),Ft.on(bt.type,(function(e,t){return Dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload})})),Ft.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Ft.on(gt.type,(function(e,t){var n;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),Ft.on(Ct.type,(function(e){return Lt.with()}));var Lt=new Ze("UNSUBSCRIBED");Lt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups})})),Lt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})}));var Gt=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new kt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(Lt,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e){var t=this,n=e.channels,r=e.channelGroups,o=e.timetoken,i=e.withPresence;this.channels=u(u([],a(this.channels),!1),a(null!=n?n:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=r?r:[]),!1),i&&(this.channels.map((function(e){return t.channels.push("".concat(e,"-pnpres"))})),this.groups.map((function(e){return t.groups.push("".concat(e,"-pnpres"))}))),o?this.engine.transition(gt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))),o)):this.engine.transition(yt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((function(e){return!e.endsWith("-pnpres")})))),groups:Array.from(new Set(this.groups.filter((function(e){return!e.endsWith("-pnpres")}))))})},e.prototype.unsubscribe=function(e){var t=this,n=e.channels,r=void 0===n?[]:n,o=e.channelGroups,i=void 0===o?[]:o,s=H.removeSingleOccurance(this.channels,u(u([],a(r),!1),a(r.map((function(e){return"".concat(e,"-pnpres")}))),!1)),c=H.removeSingleOccurance(this.groups,u(u([],a(i),!1),a(i.map((function(e){return"".concat(e,"-pnpres")}))),!1));if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(c).size){var l=H.findUniqueCommonElements(this.channels,r),p=H.findUniqueCommonElements(this.groups,i);this.dependencies.presenceState&&(null==l||l.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==p||p.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.channels=s,this.groups=c,this.engine.transition(yt(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:l.slice(0),groups:p.slice(0)})}},e.prototype.unsubscribeAll=function(){this.channels=[],this.groups=[],this.dependencies.presenceState&&(this.dependencies.presenceState={}),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.reconnect=function(e){var t=e.timetoken,n=e.region;this.engine.transition(Nt(t,n))},e.prototype.disconnect=function(){this.engine.transition(Tt()),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.getSubscribedChannels=function(){return Array.from(new Set(this.channels))},e.prototype.getSubscribedChannelGroups=function(){return Array.from(new Set(this.groups))},e.prototype.dispose=function(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),Kt=nt("RECONNECT",(function(){return{}})),Bt=nt("DISCONNECT",(function(){return{}})),Ht=nt("JOINED",(function(e,t){return{channels:e,groups:t}})),qt=nt("LEFT",(function(e,t){return{channels:e,groups:t}})),zt=nt("LEFT_ALL",(function(){return{}})),Vt=nt("HEARTBEAT_SUCCESS",(function(e){return{statusCode:e}})),Wt=nt("HEARTBEAT_FAILURE",(function(e){return e})),Jt=nt("HEARTBEAT_GIVEUP",(function(){return{}})),$t=nt("TIMES_UP",(function(){return{}})),Qt=rt("HEARTBEAT",(function(e,t){return{channels:e,groups:t}})),Xt=rt("LEAVE",(function(e,t){return{channels:e,groups:t}})),Yt=rt("EMIT_STATUS",(function(e){return e})),Zt=ot("WAIT",(function(){return{}})),en=ot("DELAYED_HEARTBEAT",(function(e){return e})),tn=function(e){function r(t,r){var s=e.call(this,r)||this;return s.on(Qt.type,ut((function(e,r,a){var u=a.heartbeat,c=a.presenceState,l=a.config;return o(s,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,u(n({channels:e.channels,channelGroups:e.groups},l.maintainPresenceState&&{state:c}))];case 1:return o.sent(),t.transition(Vt(200)),[3,3];case 2:return(r=o.sent())instanceof q?[2,t.transition(Wt(r))]:[3,3];case 3:return[2]}}))}))}))),s.on(Xt.type,ut((function(e,t,n){var r=n.leave,a=n.config;return o(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:if(a.suppressLeaveEvents)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r({channels:e.channels,channelGroups:e.groups})];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}}))}))}))),s.on(Zt.type,ut((function(e,n,r){var a=r.heartbeatDelay;return o(s,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return n.throwIfAborted(),[4,a()];case 1:return e.sent(),n.throwIfAborted(),[2,t.transition($t())]}}))}))}))),s.on(en.type,ut((function(e,r,a){var u=a.heartbeat,c=a.retryDelay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({channels:e.channels,channelGroups:e.groups},p.maintainPresenceState&&{state:l}))];case 3:return i.sent(),[2,t.transition(Vt(200))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Wt(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Jt())];case 7:return[2]}}))}))}))),s.on(Yt.type,ut((function(e,t,r){var a=r.emitStatus,u=r.config;return o(s,void 0,void 0,(function(){var t;return i(this,(function(r){return u.announceFailedHeartbeats&&!0===(null===(t=null==e?void 0:e.status)||void 0===t?void 0:t.error)?a(e.status):u.announceSuccessfulHeartbeats&&200===e.statusCode&&a(n(n({},e),{operation:j.PNHeartbeatOperation,error:!1})),[2]}))}))}))),s}return t(r,e),r}(tt),nn=new Ze("HEARTBEAT_STOPPED");nn.on(Ht.type,(function(e,t){return nn.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),nn.on(qt.type,(function(e,t){return nn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))})})),nn.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),nn.on(zt.type,(function(e,t){return un.with(void 0)}));var rn=new Ze("HEARTBEAT_COOLDOWN");rn.onEnter((function(){return Zt()})),rn.onExit((function(){return Zt.cancel})),rn.on($t.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),rn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),rn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),rn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),rn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var on=new Ze("HEARTBEAT_FAILED");on.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),on.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),on.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),on.on(Bt.type,(function(e,t){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),on.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var sn=new Ze("HEARBEAT_RECONNECTING");sn.onEnter((function(e){return en(e)})),sn.onExit((function(){return en.cancel})),sn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),sn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),sn.on(Bt.type,(function(e,t){nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),sn.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),sn.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),sn.on(Jt.type,(function(e,t){return on.with({channels:e.channels,groups:e.groups})})),sn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var an=new Ze("HEARTBEATING");an.onEnter((function(e){return Qt(e.channels,e.groups)})),an.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),an.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),an.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),an.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:0,reason:t.payload}))})),an.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),an.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var un=new Ze("HEARTBEAT_INACTIVE");un.on(Ht.type,(function(e,t){return an.with({channels:t.payload.channels,groups:t.payload.groups})}));var cn=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dispatcher=new tn(this.engine,e),this.dependencies=e,this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(un,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.join=function(e){var t=e.channels,n=e.groups;this.channels=u(u([],a(this.channels),!1),a(null!=t?t:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=n?n:[]),!1),this.engine.transition(Ht(this.channels.slice(0),this.groups.slice(0)))},e.prototype.leave=function(e){var t=this,n=e.channels,r=e.groups;this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(qt(null!=n?n:[],null!=r?r:[]))},e.prototype.leaveAll=function(){this.engine.transition(zt())},e.prototype.dispose=function(){this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),ln=function(){function e(){}return e.LinearRetryPolicy=function(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e.ExponentialRetryPolicy=function(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e}(),pn=function(){function e(e){var t=e.modules,n=e.listenerManager,r=e.getFileUrl;this.modules=t,this.listenerManager=n,this.getFileUrl=r,this._channelListenerMap=new Map,this._groupListenerMap=new Map,t.cryptoModule&&(this._decoder=new TextDecoder)}return e.prototype.emitEvent=function(e){var t=e.channel,o=e.publishMetaData,i=e.subscriptionMatch;if(t===i&&(i=null),e.channel.endsWith("-pnpres")){var s={channel:null,subscription:null};t&&(s.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(s.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),s.action=e.payload.action,s.state=e.payload.data,s.timetoken=o.timetoken,s.occupancy=e.payload.occupancy,s.uuid=e.payload.uuid,s.timestamp=e.payload.timestamp,e.payload.join&&(s.join=e.payload.join),e.payload.leave&&(s.leave=e.payload.leave),e.payload.timeout&&(s.timeout=e.payload.timeout),s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announcePresence(s),this._announce("presence",s,s.channel,s.subscription)}else if(1===e.messageType){(s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=e.payload,this.listenerManager.announceSignal(s),this._announce("signal",s,s.channel,s.subscription)}else if(2===e.messageType){if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},this.listenerManager.announceObjects(s),this._announce("objects",s,s.channel,s.subscription),"uuid"===e.payload.type){var a=this._renameChannelField(s),u=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"user"})});this.listenerManager.announceUser(u),this._announce("user",u,s.channel,s.subscription)}else if("channel"===e.payload.type){a=this._renameChannelField(s);var c=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"space"})});this.listenerManager.announceSpace(c),this._announce("space",c,s.channel,s.subscription)}else if("membership"===e.payload.type){var l=(a=this._renameChannelField(s)).message.data,p=l.uuid,h=l.channel,f=r(l,["uuid","channel"]);f.user=p,f.space=h;var d=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),data:f})});this.listenerManager.announceMembership(d),this._announce("membership",d,s.channel,s.subscription)}}else if(3===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,s.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},s.event=e.payload.event,this.listenerManager.announceMessageAction(s),this._announce("messageAction",s,s.channel,s.subscription)}else if(4===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId;var y=e.payload;if(this.modules.cryptoModule){var g=void 0;try{g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}null!==g&&(y=g)}e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=y.message,s.file={id:y.file.id,name:y.file.name,url:this.getFileUrl({id:y.file.id,name:y.file.name,channel:t})},this.listenerManager.announceFile(s),this._announce("file",s,s.channel,s.subscription)}else{if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),this.modules.cryptoModule){g=void 0;try{var m;g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}s.message=null!=g?g:e.payload}else s.message=e.payload;s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announceMessage(s),this._announce("message",s,s.channel,s.subscription)}},e.prototype.addListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){r._channelListenerMap[t]?r._channelListenerMap[t].includes(e)||r._channelListenerMap[t].push(e):r._channelListenerMap[t]=[e]})),null==n||n.forEach((function(t){r._groupListenerMap[t]?r._groupListenerMap[t].includes(e)||r._groupListenerMap[t].push(e):r._groupListenerMap[t]=[e]}))):this.listenerManager.addListener(e)},e.prototype.removeListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){var n;r._channelListenerMap[t]=null===(n=r._channelListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))})),null==n||n.forEach((function(t){var n;r._groupListenerMap[t]=null===(n=r._groupListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))}))):this.listenerManager.removeListener(e)},e.prototype.removeAllListeners=function(){this.listenerManager.removeAllListeners()},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e.prototype._announce=function(e,t,n,r){var o,i;null===(o=this._channelListenerMap[n])||void 0===o||o.forEach((function(n){return n[e]&&n[e](t)})),null===(i=this._groupListenerMap[r])||void 0===i||i.forEach((function(n){return n[e]&&n[e](t)}))},e}(),hn=function(){function e(){}return e.prototype.subscribe=function(){var e,t;this.pubnub.subscribe(n({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))},e.prototype.unsubscribe=function(){this.pubnub.unsubscribe({channels:this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),channelGroups:this.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))})},Object.defineProperty(e.prototype,"onMessage",{set:function(e){this.listener.message=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onPresence",{set:function(e){this.listener.presence=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onSignal",{set:function(e){this.listener.signal=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onObjects",{set:function(e){this.listener.objects=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onMessageAction",{set:function(e){this.listener.messageAction=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onFile",{set:function(e){this.listener.file=e},enumerable:!1,configurable:!0}),e.prototype.addListener=function(e){this.eventEmitter.addListener(e,this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),this.groupNames.filter((function(e){return!e.endsWith("-pnpres")})))},e.prototype.removeListener=function(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)},Object.defineProperty(e.prototype,"channels",{get:function(){return this.channelNames.slice(0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"channelGroups",{get:function(){return this.groupNames.slice(0)},enumerable:!1,configurable:!0}),e}(),fn=function(e){function n(t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.subscriptionOptions,c=t.eventEmitter,l=t.pubnub,p=e.call(this)||this;return p.channelNames=[],p.groupNames=[],p.subscriptionList=[],p.options=s,p.eventEmitter=c,p.pubnub=l,r.filter((function(e){return!e.endsWith("-pnpres")})).forEach((function(e){var t=p.pubnub.channel(e).subscription(p.options);p.channelNames=u(u([],a(p.channelNames),!1),a(t.channels),!1),p.subscriptionList.push(t)})),i.filter((function(e){return!e.endsWith("-pnpres")})).forEach((function(e){var t=p.pubnub.channelGroup(e).subscription(p.options);p.groupNames=u(u([],a(p.groupNames),!1),a(t.channelGroups),!1),p.subscriptionList.push(t)})),p.listener={},c.addListener(p.listener,p.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),p.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),p}return t(n,e),n.prototype.addSubscription=function(e){this.subscriptionList.push(e),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)},n.prototype.removeSubscription=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return t!==e})),this.eventEmitter.removeListener(this.listener,t,n)},n.prototype.addSubscriptionSet=function(e){this.subscriptionList=u(u([],a(this.subscriptionList),!1),a(e.subscriptions),!1),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)},n.prototype.removeSubscriptionSet=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return!e.subscriptions.includes(t)})),this.eventEmitter.removeListener(this.listener,t,n)},Object.defineProperty(n.prototype,"subscriptions",{get:function(){return this.subscriptionList.slice(0)},enumerable:!1,configurable:!0}),n}(hn),dn=function(e){function r(t){var n=t.channels,r=t.channelGroups,o=t.subscriptionOptions,i=t.eventEmitter,s=t.pubnub,a=e.call(this)||this;return a.channelNames=[],a.groupNames=[],a.channelNames=n,a.groupNames=r,a.options=o,a.pubnub=s,a.eventEmitter=i,a.listener={},i.addListener(a.listener,a.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),a.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),a}return t(r,e),r.prototype.addSubscription=function(e){return new fn({channels:u(u([],a(this.channelNames),!1),a(e.channels),!1),channelGroups:u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),subscriptionOptions:n(n({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})},r}(hn),yn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),gn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),mn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),bn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),vn=function(){function e(e){var t=this,r=e.networking,o=e.cbor,i=new g({setup:e});this._config=i;var c=new T({config:i}),l=e.cryptography;r.init(i);var p=new G(i,o);this._tokenManager=p;var h=new R({maximumSamplesCount:6e4});this._telemetryManager=h;var f=this._config.cryptoModule,d={config:i,networking:r,crypto:c,cryptography:l,tokenManager:p,telemetryManager:h,PubNubFile:e.PubNubFile,cryptoModule:f};this.File=e.PubNubFile,this.encryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.encryptFile(t,this.File)):l.encryptFile(e,t,this.File)},this.decryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.decryptFile(t,this.File)):l.decryptFile(e,t,this.File)};var y=Q.bind(this,d,Je),m=Q.bind(this,d,se),v=Q.bind(this,d,ue),_=Q.bind(this,d,le),S=Q.bind(this,d,$e),w=new L;if(this._listenerManager=w,this.iAmHere=Q.bind(this,d,ue),this.iAmAway=Q.bind(this,d,se),this.setPresenceState=Q.bind(this,d,le),this.handshake=Q.bind(this,d,Qe),this.receiveMessages=Q.bind(this,d,Xe),this._eventEmitter=new pn({modules:d,listenerManager:this._listenerManager,getFileUrl:function(e){return ve(d,e)}}),!0===i.enableEventEngine){if(i.maintainPresenceState&&(this.presenceState={},this.setState=function(e){var n,r;return null===(n=e.channels)||void 0===n||n.forEach((function(n){return t.presenceState[n]=e.state})),null===(r=e.channelGroups)||void 0===r||r.forEach((function(n){return t.presenceState[n]=e.state})),t.setPresenceState({channels:e.channels,channelGroups:e.channelGroups,state:t.presenceState})}),i.getHeartbeatInterval()){var O=new cn({heartbeat:this.iAmHere,leave:this.iAmAway,heartbeatDelay:function(){return new Promise((function(e){return setTimeout(e,1e3*d.config.getHeartbeatInterval())}))},retryDelay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},config:d.config,presenceState:this.presenceState,emitStatus:function(e){w.announceStatus(e)}});this.presenceEventEngine=O,this.join=this.presenceEventEngine.join.bind(O),this.leave=this.presenceEventEngine.leave.bind(O),this.leaveAll=this.presenceEventEngine.leaveAll.bind(O)}var P=new Gt({handshake:this.handshake,receiveMessages:this.receiveMessages,delay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},join:this.join,leave:this.leave,leaveAll:this.leaveAll,presenceState:this.presenceState,config:d.config,emitMessages:function(e){var n,r;try{for(var o=s(e),i=o.next();!i.done;i=o.next()){var a=i.value;t._eventEmitter.emitEvent(a)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},emitStatus:function(e){w.announceStatus(e)}});this.subscribe=P.subscribe.bind(P),this.unsubscribe=P.unsubscribe.bind(P),this.unsubscribeAll=P.unsubscribeAll.bind(P),this.reconnect=P.reconnect.bind(P),this.disconnect=P.disconnect.bind(P),this.destroy=P.dispose.bind(P),this.getSubscribedChannels=P.getSubscribedChannels.bind(P),this.getSubscribedChannelGroups=P.getSubscribedChannelGroups.bind(P),this.eventEngine=P}else{var E=new M({timeEndpoint:y,leaveEndpoint:m,heartbeatEndpoint:v,setStateEndpoint:_,subscribeEndpoint:S,crypto:d.crypto,config:d.config,listenerManager:w,getFileUrl:function(e){return ve(d,e)},cryptoModule:d.cryptoModule,eventEmitter:this._eventEmitter});this.subscribe=E.adaptSubscribeChange.bind(E),this.unsubscribe=E.adaptUnsubscribeChange.bind(E),this.disconnect=E.disconnect.bind(E),this.reconnect=E.reconnect.bind(E),this.unsubscribeAll=E.unsubscribeAll.bind(E),this.getSubscribedChannels=E.getSubscribedChannels.bind(E),this.getSubscribedChannelGroups=E.getSubscribedChannelGroups.bind(E),this.setState=E.adaptStateChange.bind(E),this.presence=E.adaptPresenceChange.bind(E),this.destroy=function(e){E.unsubscribeAll(e),E.disconnect()}}this.addListener=this._eventEmitter.addListener.bind(this._eventEmitter),this.removeListener=this._eventEmitter.removeListener.bind(this._eventEmitter),this.removeAllListeners=this._eventEmitter.removeAllListeners.bind(this._eventEmitter),this.parseToken=p.parseToken.bind(p),this.setToken=p.setToken.bind(p),this.getToken=p.getToken.bind(p),this.channelGroups={listGroups:Q.bind(this,d,ee),listChannels:Q.bind(this,d,te),addChannels:Q.bind(this,d,X),removeChannels:Q.bind(this,d,Y),deleteGroup:Q.bind(this,d,Z)},this.push={addChannels:Q.bind(this,d,ne),removeChannels:Q.bind(this,d,re),deleteDevice:Q.bind(this,d,ie),listChannels:Q.bind(this,d,oe)},this.hereNow=Q.bind(this,d,pe),this.whereNow=Q.bind(this,d,ae),this.getState=Q.bind(this,d,ce),this.grant=Q.bind(this,d,Ue),this.grantToken=Q.bind(this,d,Le),this.audit=Q.bind(this,d,xe),this.revokeToken=Q.bind(this,d,Ge),this.publish=Q.bind(this,d,Be),this.fire=function(e,n){return e.replicate=!1,e.storeInHistory=!1,t.publish(e,n)},this.signal=Q.bind(this,d,He),this.history=Q.bind(this,d,qe),this.deleteMessages=Q.bind(this,d,ze),this.messageCounts=Q.bind(this,d,Ve),this.fetchMessages=Q.bind(this,d,We),this.addMessageAction=Q.bind(this,d,he),this.removeMessageAction=Q.bind(this,d,fe),this.getMessageActions=Q.bind(this,d,de),this.listFiles=Q.bind(this,d,ye);var A=Q.bind(this,d,ge);this.publishFile=Q.bind(this,d,me),this.sendFile=be({generateUploadUrl:A,publishFile:this.publishFile,modules:d}),this.getFileUrl=function(e){return ve(d,e)},this.downloadFile=Q.bind(this,d,_e),this.deleteFile=Q.bind(this,d,Se),this.channel=function(e){return new yn(e,t._eventEmitter,t)},this.channelGroup=function(e){return new gn(e,t._eventEmitter,t)},this.channelMetadata=function(e){return new mn(e,t._eventEmitter,t)},this.userMetadata=function(e){return new bn(e,t._eventEmitter,t)},this.subscriptionSet=function(e){return new fn({channels:e.channels,channelGroups:e.channelGroups,subscriptionOptions:e.subscriptionOptions,eventEmitter:t._eventEmitter,pubnub:t})},this.objects={getAllUUIDMetadata:Q.bind(this,d,we),getUUIDMetadata:Q.bind(this,d,Oe),setUUIDMetadata:Q.bind(this,d,Pe),removeUUIDMetadata:Q.bind(this,d,Ee),getAllChannelMetadata:Q.bind(this,d,Ae),getChannelMetadata:Q.bind(this,d,Te),setChannelMetadata:Q.bind(this,d,Ne),removeChannelMetadata:Q.bind(this,d,Ce),getChannelMembers:Q.bind(this,d,ke),setChannelMembers:function(e){for(var r=[],o=1;o=this._config.origin.length&&(this._currentSubDomain=0);var t=this._config.origin[this._currentSubDomain];return"".concat(e).concat(t)},e.prototype.hasModule=function(e){return e in this._modules},e.prototype.shiftStandardOrigin=function(){return this._standardOrigin=this.nextOrigin(),this._standardOrigin},e.prototype.getStandardOrigin=function(){return this._standardOrigin},e.prototype.POSTFILE=function(e,t,n){return this._modules.postfile(e,t,n)},e.prototype.GETFILE=function(e,t,n){return this._modules.getfile(e,t,n)},e.prototype.POST=function(e,t,n,r){return this._modules.post(e,t,n,r)},e.prototype.PATCH=function(e,t,n,r){return this._modules.patch(e,t,n,r)},e.prototype.GET=function(e,t,n){return this._modules.get(e,t,n)},e.prototype.DELETE=function(e,t,n){return this._modules.del(e,t,n)},e.prototype._detectErrorCategory=function(e){if("ENOTFOUND"===e.code)return k.PNNetworkIssuesCategory;if("ECONNREFUSED"===e.code)return k.PNNetworkIssuesCategory;if("ECONNRESET"===e.code)return k.PNNetworkIssuesCategory;if("EAI_AGAIN"===e.code)return k.PNNetworkIssuesCategory;if(0===e.status||e.hasOwnProperty("status")&&void 0===e.status)return k.PNNetworkIssuesCategory;if(e.timeout)return k.PNTimeoutCategory;if("ETIMEDOUT"===e.code)return k.PNNetworkIssuesCategory;if(e.response){if(e.response.badRequest)return k.PNBadRequestCategory;if(e.response.forbidden)return k.PNAccessDeniedCategory}return k.PNUnknownCategory},e}();function Sn(e){var t=function(e){return e&&"object"==typeof e&&e.constructor===Object};if(!t(e))return e;var n={};return Object.keys(e).forEach((function(r){var o=function(e){return"string"==typeof e||e instanceof String}(r),i=r,s=e[r];Array.isArray(r)||o&&r.indexOf(",")>=0?i=(o?r.split(","):r).reduce((function(e,t){return e+=String.fromCharCode(t)}),""):(function(e){return"number"==typeof e&&isFinite(e)}(r)||o&&!isNaN(r))&&(i=String.fromCharCode(o?parseInt(r,10):10));n[i]=t(s)?Sn(s):s})),n}var wn=function(){function e(e,t){this._base64ToBinary=t,this._decode=e}return e.prototype.decodeToken=function(e){var t="";e.length%4==3?t="=":e.length%4==2&&(t="==");var n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,r=this._decode(this._base64ToBinary(n));if("object"==typeof r)return r},e}(),On={exports:{}},Pn={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;os.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;at?1:0}function Un(e,t,n,r){void 0===r&&(r=kn());var o,i=In(e,"",0,[],void 0,0,r)||e;try{o=0===Cn.length?JSON.stringify(i,t,n):JSON.stringify(i,Dn(t),n)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==Nn.length;){var s=Nn.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return o}function In(e,t,n,r,o,i,s){var a;if(i+=1,"object"==typeof e&&null!==e){for(a=0;as.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;a0)for(var r=0;r1&&"boolean"!=typeof t)throw new Qn('"allowMissing" argument must be a boolean');var n=gr(e),r=n.length>0?n[0]:"",o=mr("%"+r+"%",t),i=o.name,s=o.value,a=!1,u=o.alias;u&&(r=u[0],pr(n,lr([0,1],u)));for(var c=1,l=!0;c=n.length){var d=Yn(s,p);s=(l=!!d)&&"get"in d&&!("originalValue"in d.get)?d.get:s[p]}else l=cr(s,p),s=s[p];l&&!a&&(ir[i]=s)}}return s},vr={exports:{}};!function(e){var t=Vn,n=br,r=n("%Function.prototype.apply%"),o=n("%Function.prototype.call%"),i=n("%Reflect.apply%",!0)||t.call(o,r),s=n("%Object.getOwnPropertyDescriptor%",!0),a=n("%Object.defineProperty%",!0),u=n("%Math.max%");if(a)try{a({},"a",{value:1})}catch(e){a=null}e.exports=function(e){var n=i(t,o,arguments);if(s&&a){var r=s(n,"length");r.configurable&&a(n,"length",{value:1+u(0,e.length-(arguments.length-1))})}return n};var c=function(){return i(t,r,arguments)};a?a(e.exports,"apply",{value:c}):e.exports.apply=c}(vr);var _r=br,Sr=vr.exports,wr=Sr(_r("String.prototype.indexOf")),Or=l(Object.freeze({__proto__:null,default:{}})),Pr="function"==typeof Map&&Map.prototype,Er=Object.getOwnPropertyDescriptor&&Pr?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ar=Pr&&Er&&"function"==typeof Er.get?Er.get:null,Tr=Pr&&Map.prototype.forEach,Nr="function"==typeof Set&&Set.prototype,Cr=Object.getOwnPropertyDescriptor&&Nr?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,kr=Nr&&Cr&&"function"==typeof Cr.get?Cr.get:null,Mr=Nr&&Set.prototype.forEach,jr="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Rr="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,xr="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Ur=Boolean.prototype.valueOf,Ir=Object.prototype.toString,Dr=Function.prototype.toString,Fr=String.prototype.match,Lr=String.prototype.slice,Gr=String.prototype.replace,Kr=String.prototype.toUpperCase,Br=String.prototype.toLowerCase,Hr=RegExp.prototype.test,qr=Array.prototype.concat,zr=Array.prototype.join,Vr=Array.prototype.slice,Wr=Math.floor,Jr="function"==typeof BigInt?BigInt.prototype.valueOf:null,$r=Object.getOwnPropertySymbols,Qr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,Xr="function"==typeof Symbol&&"object"==typeof Symbol.iterator,Yr="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xr||"symbol")?Symbol.toStringTag:null,Zr=Object.prototype.propertyIsEnumerable,eo=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function to(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||Hr.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var r=e<0?-Wr(-e):Wr(e);if(r!==e){var o=String(r),i=Lr.call(t,o.length+1);return Gr.call(o,n,"$&_")+"."+Gr.call(Gr.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Gr.call(t,n,"$&_")}var no=Or,ro=no.custom,oo=co(ro)?ro:null;function io(e,t,n){var r="double"===(n.quoteStyle||t)?'"':"'";return r+e+r}function so(e){return Gr.call(String(e),/"/g,""")}function ao(e){return!("[object Array]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function uo(e){return!("[object RegExp]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function co(e){if(Xr)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!Qr)return!1;try{return Qr.call(e),!0}catch(e){}return!1}var lo=Object.prototype.hasOwnProperty||function(e){return e in this};function po(e,t){return lo.call(e,t)}function ho(e){return Ir.call(e)}function fo(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;nt.maxStringLength){var n=e.length-t.maxStringLength,r="... "+n+" more character"+(n>1?"s":"");return yo(Lr.call(e,0,t.maxStringLength),t)+r}return io(Gr.call(Gr.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,go),"single",t)}function go(e){var t=e.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return n?"\\"+n:"\\x"+(t<16?"0":"")+Kr.call(t.toString(16))}function mo(e){return"Object("+e+")"}function bo(e){return e+" { ? }"}function vo(e,t,n,r){return e+" ("+t+") {"+(r?_o(n,r):zr.call(n,", "))+"}"}function _o(e,t){if(0===e.length)return"";var n="\n"+t.prev+t.base;return n+zr.call(e,","+n)+"\n"+t.prev}function So(e,t){var n=ao(e),r=[];if(n){r.length=e.length;for(var o=0;o-1?Sr(n):n},Po=function e(t,n,r,o){var i=n||{};if(po(i,"quoteStyle")&&"single"!==i.quoteStyle&&"double"!==i.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(po(i,"maxStringLength")&&("number"==typeof i.maxStringLength?i.maxStringLength<0&&i.maxStringLength!==1/0:null!==i.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var s=!po(i,"customInspect")||i.customInspect;if("boolean"!=typeof s&&"symbol"!==s)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(po(i,"indent")&&null!==i.indent&&"\t"!==i.indent&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(po(i,"numericSeparator")&&"boolean"!=typeof i.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=i.numericSeparator;if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return yo(t,i);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var u=String(t);return a?to(t,u):u}if("bigint"==typeof t){var l=String(t)+"n";return a?to(t,l):l}var p=void 0===i.depth?5:i.depth;if(void 0===r&&(r=0),r>=p&&p>0&&"object"==typeof t)return ao(t)?"[Array]":"[Object]";var h=function(e,t){var n;if("\t"===e.indent)n="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;n=zr.call(Array(e.indent+1)," ")}return{base:n,prev:zr.call(Array(t+1),n)}}(i,r);if(void 0===o)o=[];else if(fo(o,t)>=0)return"[Circular]";function f(t,n,s){if(n&&(o=Vr.call(o)).push(n),s){var a={depth:i.depth};return po(i,"quoteStyle")&&(a.quoteStyle=i.quoteStyle),e(t,a,r+1,o)}return e(t,i,r+1,o)}if("function"==typeof t&&!uo(t)){var d=function(e){if(e.name)return e.name;var t=Fr.call(Dr.call(e),/^function\s*([\w$]+)/);if(t)return t[1];return null}(t),y=So(t,f);return"[Function"+(d?": "+d:" (anonymous)")+"]"+(y.length>0?" { "+zr.call(y,", ")+" }":"")}if(co(t)){var g=Xr?Gr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qr.call(t);return"object"!=typeof t||Xr?g:mo(g)}if(function(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return!0;return"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}(t)){for(var m="<"+Br.call(String(t.nodeName)),b=t.attributes||[],v=0;v"}if(ao(t)){if(0===t.length)return"[]";var _=So(t,f);return h&&!function(e){for(var t=0;t=0)return!1;return!0}(_)?"["+_o(_,h)+"]":"[ "+zr.call(_,", ")+" ]"}if(function(e){return!("[object Error]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)){var S=So(t,f);return"cause"in Error.prototype||!("cause"in t)||Zr.call(t,"cause")?0===S.length?"["+String(t)+"]":"{ ["+String(t)+"] "+zr.call(S,", ")+" }":"{ ["+String(t)+"] "+zr.call(qr.call("[cause]: "+f(t.cause),S),", ")+" }"}if("object"==typeof t&&s){if(oo&&"function"==typeof t[oo]&&no)return no(t,{depth:p-r});if("symbol"!==s&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!Ar||!e||"object"!=typeof e)return!1;try{Ar.call(e);try{kr.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}(t)){var w=[];return Tr&&Tr.call(t,(function(e,n){w.push(f(n,t,!0)+" => "+f(e,t))})),vo("Map",Ar.call(t),w,h)}if(function(e){if(!kr||!e||"object"!=typeof e)return!1;try{kr.call(e);try{Ar.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}(t)){var O=[];return Mr&&Mr.call(t,(function(e){O.push(f(e,t))})),vo("Set",kr.call(t),O,h)}if(function(e){if(!jr||!e||"object"!=typeof e)return!1;try{jr.call(e,jr);try{Rr.call(e,Rr)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}(t))return bo("WeakMap");if(function(e){if(!Rr||!e||"object"!=typeof e)return!1;try{Rr.call(e,Rr);try{jr.call(e,jr)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}(t))return bo("WeakSet");if(function(e){if(!xr||!e||"object"!=typeof e)return!1;try{return xr.call(e),!0}catch(e){}return!1}(t))return bo("WeakRef");if(function(e){return!("[object Number]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(Number(t)));if(function(e){if(!e||"object"!=typeof e||!Jr)return!1;try{return Jr.call(e),!0}catch(e){}return!1}(t))return mo(f(Jr.call(t)));if(function(e){return!("[object Boolean]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(Ur.call(t));if(function(e){return!("[object String]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(String(t)));if("undefined"!=typeof window&&t===window)return"{ [object Window] }";if(t===c)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)&&!uo(t)){var P=So(t,f),E=eo?eo(t)===Object.prototype:t instanceof Object||t.constructor===Object,A=t instanceof Object?"":"null prototype",T=!E&&Yr&&Object(t)===t&&Yr in t?Lr.call(ho(t),8,-1):A?"Object":"",N=(E||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(T||A?"["+zr.call(qr.call([],T||[],A||[]),": ")+"] ":"");return 0===P.length?N+"{}":h?N+"{"+_o(P,h)+"}":N+"{ "+zr.call(P,", ")+" }"}return String(t)},Eo=wo("%TypeError%"),Ao=wo("%WeakMap%",!0),To=wo("%Map%",!0),No=Oo("WeakMap.prototype.get",!0),Co=Oo("WeakMap.prototype.set",!0),ko=Oo("WeakMap.prototype.has",!0),Mo=Oo("Map.prototype.get",!0),jo=Oo("Map.prototype.set",!0),Ro=Oo("Map.prototype.has",!0),xo=function(e,t){for(var n,r=e;null!==(n=r.next);r=n)if(n.key===t)return r.next=n.next,n.next=e.next,e.next=n,n},Uo=String.prototype.replace,Io=/%20/g,Do="RFC3986",Fo={default:Do,formatters:{RFC1738:function(e){return Uo.call(e,Io,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:Do},Lo=Fo,Go=Object.prototype.hasOwnProperty,Ko=Array.isArray,Bo=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),Ho=function(e,t){for(var n=t&&t.plainObjects?Object.create(null):{},r=0;r1;){var t=e.pop(),n=t.obj[t.prop];if(Ko(n)){for(var r=[],o=0;o=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===Lo.RFC1738&&(40===u||41===u)?s+=i.charAt(a):u<128?s+=Bo[u]:u<2048?s+=Bo[192|u>>6]+Bo[128|63&u]:u<55296||u>=57344?s+=Bo[224|u>>12]+Bo[128|u>>6&63]+Bo[128|63&u]:(a+=1,u=65536+((1023&u)<<10|1023&i.charCodeAt(a)),s+=Bo[240|u>>18]+Bo[128|u>>12&63]+Bo[128|u>>6&63]+Bo[128|63&u])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(Ko(e)){for(var n=[],r=0;r0?b.join(",")||null:void 0}];else if(Qo(u))O=u;else{var E=Object.keys(b);O=c?E.sort(c):E}for(var A=o&&Qo(b)&&1===b.length?n+"[]":n,T=0;T-1?e.split(","):e},li=function(e,t,n,r){if(e){var o=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,s=n.depth>0&&/(\[[^[\]]*])/.exec(o),a=s?o.slice(0,s.index):o,u=[];if(a){if(!n.plainObjects&&ii.call(Object.prototype,a)&&!n.allowPrototypes)return;u.push(a)}for(var c=0;n.depth>0&&null!==(s=i.exec(o))&&c=0;--i){var s,a=e[i];if("[]"===a&&n.parseArrays)s=[].concat(o);else{s=n.plainObjects?Object.create(null):{};var u="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(u,10);n.parseArrays||""!==u?!isNaN(c)&&a!==u&&String(c)===u&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(s=[])[c]=o:"__proto__"!==u&&(s[u]=o):s={0:o}}o=s}return o}(u,t,n,r)}},pi=function(e,t){var n,r=e,o=function(e){if(!e)return ti;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||ti.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Wo.default;if(void 0!==e.format){if(!Jo.call(Wo.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var r=Wo.formatters[n],o=ti.filter;return("function"==typeof e.filter||Qo(e.filter))&&(o=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:ti.addQueryPrefix,allowDots:void 0===e.allowDots?ti.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ti.charsetSentinel,delimiter:void 0===e.delimiter?ti.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:ti.encode,encoder:"function"==typeof e.encoder?e.encoder:ti.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:ti.encodeValuesOnly,filter:o,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:ti.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:ti.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ti.strictNullHandling}}(t);"function"==typeof o.filter?r=(0,o.filter)("",r):Qo(o.filter)&&(n=o.filter);var i,s=[];if("object"!=typeof r||null===r)return"";i=t&&t.arrayFormat in $o?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=$o[i];if(t&&"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var u="comma"===a&&t&&t.commaRoundTrip;n||(n=Object.keys(r)),o.sort&&n.sort(o.sort);for(var c=zo(),l=0;l0?f+h:""},hi={formats:Fo,parse:function(e,t){var n=function(e){if(!e)return ai;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?ai.charset:e.charset;return{allowDots:void 0===e.allowDots?ai.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:ai.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:ai.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:ai.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ai.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:ai.comma,decoder:"function"==typeof e.decoder?e.decoder:ai.decoder,delimiter:"string"==typeof e.delimiter||oi.isRegExp(e.delimiter)?e.delimiter:ai.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:ai.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:ai.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:ai.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:ai.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ai.strictNullHandling}}(t);if(""===e||null==e)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof e?function(e,t){var n,r={__proto__:null},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,i),a=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(l=si(l)?[l]:l),ii.call(r,c)?r[c]=oi.combine(r[c],l):r[c]=l}return r}(e,n):e,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),s=0;s=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.split(/ *; */).shift(),e.params=e=>{const n={};var r,o=t(e.split(/ *; */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *= */),t=e.shift(),o=e.shift();t&&o&&(n[t]=o)}}catch(e){o.e(e)}finally{o.f()}return n},e.parseLinks=e=>{const n={};var r,o=t(e.split(/ *, */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *; */),t=e[0].slice(1,-1);n[e[1].split(/ *= */)[1].slice(1,-1)]=t}}catch(e){o.e(e)}finally{o.f()}return n},e.cleanHeader=(e,t)=>(delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e),e.isObject=e=>null!==e&&"object"==typeof e,e.hasOwn=Object.hasOwn||function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(new Object(e),t)},e.mixin=(t,n)=>{for(const r in n)e.hasOwn(n,r)&&(t[r]=n[r])}}(fi);const di=Or,yi=fi.isObject,gi=fi.hasOwn;var mi=bi;function bi(){}bi.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},bi.prototype.parse=function(e){return this._parser=e,this},bi.prototype.responseType=function(e){return this._responseType=e,this},bi.prototype.serialize=function(e){return this._serializer=e,this},bi.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(const t in e)if(gi(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},bi.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};const vi=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),_i=new Set([408,413,429,500,502,503,504,521,522,524]);bi.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{const n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&_i.has(t.status))return!0;if(e){if(e.code&&vi.has(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},bi.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},bi.prototype.then=function(e,t){if(!this._fullfilledPromise){const e=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(((t,n)=>{e.on("abort",(()=>{if(this._maxRetries&&this._maxRetries>this._retries)return;if(this.timedout&&this.timedoutError)return void n(this.timedoutError);const e=new Error("Aborted");e.code="ABORTED",e.status=this.status,e.method=this.method,e.url=this.url,n(e)})),e.end(((e,r)=>{e?n(e):t(r)}))}))}return this._fullfilledPromise.then(e,t)},bi.prototype.catch=function(e){return this.then(void 0,e)},bi.prototype.use=function(e){return e(this),this},bi.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},bi.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},bi.prototype.get=function(e){return this._header[e.toLowerCase()]},bi.prototype.getHeader=bi.prototype.get,bi.prototype.set=function(e,t){if(yi(e)){for(const t in e)gi(e,t)&&this.set(t,e[t]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},bi.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},bi.prototype.field=function(e,t,n){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(yi(e)){for(const t in e)gi(e,t)&&this.field(t,e[t]);return this}if(Array.isArray(t)){for(const n in t)gi(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),n?this._getFormData().append(e,t,n):this._getFormData().append(e,t),this},bi.prototype.abort=function(){if(this._aborted)return this;if(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req){if(di.gte(process.version,"v13.0.0")&&di.lt(process.version,"v14.0.0"))throw new Error("Superagent does not work in v13 properly with abort() due to Node.js core changes");this.req.abort()}return this.clearTimeout(),this.emit("abort"),this},bi.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization",`Basic ${r(`${e}:${t}`)}`);break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization",`Bearer ${e}`)}return this},bi.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},bi.prototype.redirects=function(e){return this._maxRedirects=e,this},bi.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},bi.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},bi.prototype.send=function(e){const t=yi(e);let n=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&yi(this._data))for(const t in e){if("bigint"==typeof e[t]&&!e[t].toJSON)throw new Error("Cannot serialize BigInt value to json");gi(e,t)&&(this._data[t]=e[t])}else{if("bigint"==typeof e)throw new Error("Cannot send value of type BigInt");"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],n&&(n=n.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===n?this._data?`${this._data}&${e}`:e:(this._data||"")+e):this._data=e}return!t||this._isHost(e)||n||this.type("json"),this},bi.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},bi.prototype._finalizeQueryString=function(){const e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){const e=this.url.indexOf("?");if(e>=0){const t=this.url.slice(e+1).split("&");"function"==typeof this._sort?t.sort(this._sort):t.sort(),this.url=this.url.slice(0,e)+"?"+t.join("&")}}},bi.prototype._appendQueryString=()=>{console.warn("Unsupported")},bi.prototype._timeoutError=function(e,t,n){if(this._aborted)return;const r=new Error(`${e+t}ms exceeded`);r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.timedoutError=r,this.abort(),this.callback(r)},bi.prototype._setTimeouts=function(){const e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((()=>{e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((()=>{e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};const Si=fi;var wi=Oi;function Oi(){}function Pi(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Ei(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ei(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw i}}}}function Ei(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n{if(o.XMLHttpRequest)return new o.XMLHttpRequest;throw new Error("Browser-only version of superagent could not find XHR")};const g="".trim?e=>e.trim():e=>e.replace(/(^\s*|\s*$)/g,"");function m(e){if(!c(e))return e;const t=[];for(const n in e)p(e,n)&&b(t,n,e[n]);return t.join("&")}function b(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r)){var o,i=n(r);try{for(i.s();!(o=i.n()).done;){b(e,t,o.value)}}catch(e){i.e(e)}finally{i.f()}}else if(c(r))for(const n in r)p(r,n)&&b(e,`${t}[${n}]`,r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function v(e){const t={},n=e.split("&");let r,o;for(let e=0,i=n.length;e{let e,t=null,r=null;try{r=new S(n)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||r.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=e.status||r.status,n.callback(e,r)):n.callback(null,r)}))}y.serializeObject=m,y.parseString=v,y.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":a.stringify,"application/json":s},y.parse={"application/x-www-form-urlencoded":v,"application/json":JSON.parse},l(S.prototype,h.prototype),S.prototype._parseBody=function(e){let t=y.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&_(this.type)&&(t=y.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},S.prototype.toError=function(){const e=this.req,t=e.method,n=e.url,r=`cannot ${t} ${n} (${this.status})`,o=new Error(r);return o.status=this.status,o.method=t,o.url=n,o},y.Response=S,i(w.prototype),l(w.prototype,u.prototype),w.prototype.type=function(e){return this.set("Content-Type",y.types[e]||e),this},w.prototype.accept=function(e){return this.set("Accept",y.types[e]||e),this},w.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});const r=n.encoder?n.encoder:e=>{if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},w.prototype.query=function(e){return"string"!=typeof e&&(e=m(e)),e&&this._query.push(e),this},w.prototype.attach=function(e,t,n){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},w.prototype._getFormData=function(){return this._formData||(this._formData=new o.FormData),this._formData},w.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();const n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},w.prototype.crossDomainError=function(){const e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},w.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},w.prototype.ca=w.prototype.agent,w.prototype.buffer=w.prototype.ca,w.prototype.write=()=>{throw new Error("Streaming is not supported in browser version of superagent")},w.prototype.pipe=w.prototype.write,w.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},w.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||d,this._finalizeQueryString(),this._end()},w.prototype._setUploadTimeout=function(){const e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((()=>{e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},w.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));const e=this;this.xhr=y.getXHR();const t=this.xhr;let n=this._formData||this._data;this._setTimeouts(),t.addEventListener("readystatechange",(()=>{const n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4!==n)return;let r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}));const r=(t,n)=>{n.total>0&&(n.percent=n.loaded/n.total*100,100===n.percent&&clearTimeout(e._uploadTimeoutTimer)),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.addEventListener("progress",r.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",r.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof n&&!this._isHost(n)){const e=this._header["content-type"];let t=this._serializer||y.serialize[e?e.split(";")[0]:""];!t&&_(e)&&(t=y.serialize["application/json"]),t&&(n=t(n))}for(const e in this.header)null!==this.header[e]&&p(this.header,e)&&t.setRequestHeader(e,this.header[e]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===n?null:n)},y.agent=()=>new f;for(var O=0,P=["GET","POST","OPTIONS","PATCH","PUT","DELETE"];O{const r=y("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.head=(e,t,n)=>{const r=y("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.options=(e,t,n)=>{const r=y("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.del=E,y.delete=E,y.patch=(e,t,n)=>{const r=y("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.post=(e,t,n)=>{const r=y("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.put=(e,t,n)=>{const r=y("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}}(On,On.exports);var ki=On.exports;function Mi(e){var t=(new Date).getTime(),n=(new Date).toISOString(),r=console&&console.log?console:window&&window.console&&window.console.log?window.console:console;r.log("<<<<<"),r.log("[".concat(n,"]"),"\n",e.url,"\n",e.qs),r.log("-----"),e.on("response",(function(n){var o=(new Date).getTime()-t,i=(new Date).toISOString();r.log(">>>>>>"),r.log("[".concat(i," / ").concat(o,"]"),"\n",e.url,"\n",e.qs,"\n",n.text),r.log("-----")}))}function ji(e,t,n){var r=this;this._config.logVerbosity&&(e=e.use(Mi)),this._config.proxy&&this._modules.proxy&&(e=this._modules.proxy.call(this,e)),this._config.keepAlive&&this._modules.keepAlive&&(e=this._modules.keepAlive(e));var o=e;if(t.abortSignal)var i=t.abortSignal.subscribe((function(){o.abort(),i()}));return!0===t.forceBuffered?o="undefined"==typeof Blob?o.buffer().responseType("arraybuffer"):o.responseType("arraybuffer"):!1===t.forceBuffered&&(o=o.buffer(!1)),(o=o.timeout(t.timeout)).on("abort",(function(){return n({category:k.PNUnknownCategory,error:!0,operation:t.operation,errorData:new Error("Aborted")},null)})),o.end((function(e,o){var i,s={};if(s.error=null!==e,s.operation=t.operation,o&&o.status&&(s.statusCode=o.status),e){if(e.response&&e.response.text&&!r._config.logVerbosity)try{s.errorData=JSON.parse(e.response.text)}catch(t){s.errorData=e}else s.errorData=e;return s.category=r._detectErrorCategory(e),n(s,null)}if(t.ignoreBody)i={headers:o.headers,redirects:o.redirects,response:o};else try{i=JSON.parse(o.text)}catch(e){return s.errorData=o,s.error=!0,n(s,null)}return i.error&&1===i.error&&i.status&&i.message&&i.service?(s.errorData=i,s.statusCode=i.status,s.error=!0,s.category=r._detectErrorCategory(s),n(s,null)):(i.error&&i.error.message&&(s.errorData=i.error),n(s,i))})),o}function Ri(e,t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return r=ki.post(e),t.forEach((function(e){var t=e.key,n=e.value;r=r.field(t,n)})),r.attach("file",n,{contentType:"application/octet-stream"}),[4,r];case 1:return[2,o.sent()]}}))}))}function xi(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ui(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ii(e,t,n,r){var o=ki.post(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Di(e,t,n,r){var o=ki.patch(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Fi(e,t,n){var r=ki.delete(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Li(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}var Gi,Ki=function(){function e(){}return Object.defineProperty(e.prototype,"algo",{get:function(){return"aes-256-cbc"},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.encryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.encryptString(n,t)];throw new Error("Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer")}}))}))},e.prototype.decrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.decryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.decryptString(n,t)];throw new Error("Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer")}}))}))},e.prototype.encryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:if(t.data.byteLength<=0)throw new Error("encryption error. empty content");return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.encryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,mimeType:"application/octet-stream",data:s})]}}))}))},e.prototype.decryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.decryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,data:s})]}}))}))},e.prototype.getKey=function(t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return[4,crypto.subtle.digest("SHA-256",e.encoder.encode(t))];case 1:return n=i.sent(),r=Array.from(new Uint8Array(n)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),o=e.encoder.encode(r.slice(0,32)).buffer,[2,crypto.subtle.importKey("raw",o,"AES-CBC",!0,["encrypt","decrypt"])]}}))}))},e.prototype.encryptArrayBuffer=function(e,t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),r=Li,o=[n.buffer],[4,crypto.subtle.encrypt({name:"AES-CBC",iv:n},e,t)];case 1:return[2,r.apply(void 0,o.concat([i.sent()]))]}}))}))},e.prototype.decryptArrayBuffer=function(t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:if(r=n.slice(0,16),n.slice(e.IV_LENGTH).byteLength<=0)throw new Error("decryption error: empty content");return[4,crypto.subtle.decrypt({name:"AES-CBC",iv:r},t,n.slice(e.IV_LENGTH))];case 1:return[2,o.sent()]}}))}))},e.prototype.encryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=crypto.getRandomValues(new Uint8Array(16)),o=e.encoder.encode(n).buffer,[4,crypto.subtle.encrypt({name:"AES-CBC",iv:r},t,o)];case 1:return s=i.sent(),a=Li(r.buffer,s),[2,e.decoder.decode(a)]}}))}))},e.prototype.decryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=e.encoder.encode(n).buffer,o=r.slice(0,16),s=r.slice(16),[4,crypto.subtle.decrypt({name:"AES-CBC",iv:o},t,s)];case 1:return a=i.sent(),[2,e.decoder.decode(a)]}}))}))},e.IV_LENGTH=16,e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Bi=(Gi=function(){function e(e){if(e instanceof File)this.data=e,this.name=this.data.name,this.mimeType=this.data.type;else if(e.data){var t=e.data;this.data=new File([t],e.name,{type:e.mimeType}),this.name=e.name,e.mimeType&&(this.mimeType=e.mimeType)}if(void 0===this.data)throw new Error("Couldn't construct a file out of supplied options.");if(void 0===this.name)throw new Error("Couldn't guess filename out of the options. Please provide one.")}return e.create=function(e){return new this(e)},e.prototype.toBuffer=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toStream=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toFileUri=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in react native environments.")}))}))},e.prototype.toBlob=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e.prototype.toArrayBuffer=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if(r.result instanceof ArrayBuffer)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsArrayBuffer(e.data)}))]}))}))},e.prototype.toString=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if("string"==typeof r.result)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsBinaryString(e.data)}))]}))}))},e.prototype.toFile=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e}(),Gi.supportsFile="undefined"!=typeof File,Gi.supportsBlob="undefined"!=typeof Blob,Gi.supportsArrayBuffer="undefined"!=typeof ArrayBuffer,Gi.supportsBuffer=!1,Gi.supportsStream=!1,Gi.supportsString=!0,Gi.supportsEncryptFile=!0,Gi.supportsFileUri=!1,Gi),Hi=function(){function e(e){this.config=e,this.cryptor=new T({config:e}),this.fileCryptor=new Ki}return Object.defineProperty(e.prototype,"identifier",{get:function(){return""},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e){var t="string"==typeof e?e:(new TextDecoder).decode(e);return{data:this.cryptor.encrypt(t),metadata:null}},e.prototype.decrypt=function(e){var t="string"==typeof e.data?e.data:b(e.data);return this.cryptor.decrypt(t)},e.prototype.encryptFile=function(e,t){var n;return o(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)]}))}))},e.prototype.decryptFile=function(e,t){return o(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.fileCryptor.decryptFile(this.config.cipherKey,e,t)]}))}))},e}(),qi=function(){function e(e){this.cipherKey=e.cipherKey,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(this.cipherKey)}return Object.defineProperty(e.prototype,"algo",{get:function(){return"AES-CBC"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return"ACRH"},enumerable:!1,configurable:!0}),e.prototype.getIv=function(){return crypto.getRandomValues(new Uint8Array(e.BLOCK_SIZE))},e.prototype.getKey=function(){return o(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return t=e.encoder.encode(this.cipherKey),[4,crypto.subtle.digest("SHA-256",t.buffer)];case 1:return n=r.sent(),[2,crypto.subtle.importKey("raw",n,this.algo,!0,["encrypt","decrypt"])]}}))}))},e.prototype.encrypt=function(t){if(0===("string"==typeof t?t:e.decoder.decode(t)).length)throw new Error("encryption error. empty content");var n=this.getIv();return{metadata:n,data:m(this.CryptoJS.AES.encrypt(t,this.encryptedKey,{iv:this.bufferToWordArray(n),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}},e.prototype.decrypt=function(t){var n=this.bufferToWordArray(new Uint8ClampedArray(t.metadata)),r=this.bufferToWordArray(new Uint8ClampedArray(t.data));return e.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:r},this.encryptedKey,{iv:n,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer},e.prototype.encryptFileData=function(e){return o(this,void 0,void 0,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:return[4,this.getKey()];case 1:return t=o.sent(),n=this.getIv(),r={},[4,crypto.subtle.encrypt({name:this.algo,iv:n},t,e)];case 2:return[2,(r.data=o.sent(),r.metadata=n,r)]}}))}))},e.prototype.decryptFileData=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.getKey()];case 1:return t=n.sent(),[2,crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)]}}))}))},e.prototype.bufferToWordArray=function(e){var t,n=[];for(t=0;t0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("decryption error. empty content");return r.decrypt({data:t.slice(n.length),metadata:o})},e.prototype.encryptFile=function(e,t){return o(this,void 0,void 0,(function(){var n,r;return i(this,(function(o){switch(o.label){case 0:return this.defaultCryptor.identifier===Vi.LEGACY_IDENTIFIER?[2,this.defaultCryptor.encryptFile(e,t)]:[4,this.getFileData(e.data)];case 1:return n=o.sent(),[4,this.defaultCryptor.encryptFileData(n)];case 2:return r=o.sent(),[2,t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(r),r.data)})]}}))}))},e.prototype.decryptFile=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a,u,c,l,p;return i(this,(function(i){switch(i.label){case 0:return[4,t.data.arrayBuffer()];case 1:return r=i.sent(),o=Vi.tryParse(r),(null==(s=this.getCryptor(o))?void 0:s.identifier)===e.LEGACY_IDENTIFIER?[2,s.decryptFile(t,n)]:[4,this.getFileData(r)];case 2:return a=i.sent(),u=a.slice(o.length-o.metadataLength,o.length),l=(c=n).create,p={name:t.name},[4,this.defaultCryptor.decryptFileData({data:r.slice(o.length),metadata:u})];case 3:return[2,l.apply(c,[(p.data=i.sent(),p)])]}}))}))},e.prototype.getCryptor=function(e){if(""===e){var t=this.getAllCryptors().find((function(e){return""===e.identifier}));if(t)return t;throw new Error("unknown cryptor error")}if(e instanceof Wi)return this.getCryptorFromId(e.identifier)},e.prototype.getCryptorFromId=function(e){var t=this.getAllCryptors().find((function(t){return e===t.identifier}));if(t)return t;throw Error("unknown cryptor error")},e.prototype.concatArrayBuffer=function(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer},e.prototype.getHeaderData=function(e){if(e.metadata){var t=Vi.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length),r=0;return n.set(t.data,r),r+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),r),n.buffer}},e.prototype.getFileData=function(t){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return t instanceof Blob?[4,t.arrayBuffer()]:[3,2];case 1:return[2,n.sent()];case 2:if(t instanceof ArrayBuffer)return[2,t];if("string"==typeof t)return[2,e.encoder.encode(t)];throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}}))}))},e.LEGACY_IDENTIFIER="",e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Vi=function(){function e(){}return e.from=function(t,n){if(t!==e.LEGACY_IDENTIFIER)return new Wi(t,n.byteLength)},e.tryParse=function(t){var n=new Uint8Array(t),r="";if(n.byteLength>=4&&(r=n.slice(0,4),this.decoder.decode(r)!==e.SENTINEL))return"";if(!(n.byteLength>=5))throw new Error("decryption error. invalid header version");if(n[4]>e.MAX_VERSION)throw new Error("unknown cryptor error");var o="",i=5+e.IDENTIFIER_LENGTH;if(!(n.byteLength>=i))throw new Error("decryption error. invalid crypto identifier");o=n.slice(5,i);var s=null;if(!(n.byteLength>=i+1))throw new Error("decryption error. invalid metadata length");return s=n[i],i+=1,255===s&&n.byteLength>=i+2&&(s=new Uint16Array(n.slice(i,i+2)).reduce((function(e,t){return(e<<8)+t}),0),i+=2),new Wi(this.decoder.decode(o),s)},e.SENTINEL="PNED",e.LEGACY_IDENTIFIER="",e.IDENTIFIER_LENGTH=4,e.VERSION=1,e.MAX_VERSION=1,e.decoder=new TextDecoder,e}(),Wi=function(){function e(e,t){this._identifier=e,this._metadataLength=t}return Object.defineProperty(e.prototype,"identifier",{get:function(){return this._identifier},set:function(e){this._identifier=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"metadataLength",{get:function(){return this._metadataLength},set:function(e){this._metadataLength=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return Vi.VERSION},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return Vi.SENTINEL.length+1+Vi.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){var e=0,t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(Vi.SENTINEL)),t[e+=Vi.SENTINEL.length]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e),e+=Vi.IDENTIFIER_LENGTH;var r=this.metadataLength;return r<255?t[e]=r:t.set([255,r>>8,255&r],e),t},enumerable:!1,configurable:!0}),e.IDENTIFIER_LENGTH=4,e.SENTINEL="PNED",e}();function Ji(e){if(!navigator||!navigator.sendBeacon)return!1;navigator.sendBeacon(e)}var $i=function(e){function n(t){var n=this,r=t.listenToBrowserNetworkEvents,o=void 0===r||r;return t.sdkFamily="Web",t.networking=new _n({del:Fi,get:Ui,post:Ii,patch:Di,sendBeacon:Ji,getfile:xi,postfile:Ri}),t.cbor=new wn((function(e){return Sn(h.decode(e))}),m),t.PubNubFile=Bi,t.cryptography=new Ki,t.initCryptoModule=function(e){return new zi({default:new Hi({cipherKey:e.cipherKey,useRandomIVs:e.useRandomIVs}),cryptors:[new qi({cipherKey:e.cipherKey})]})},n=e.call(this,t)||this,o&&(window.addEventListener("offline",(function(){n.networkDownDetected()})),window.addEventListener("online",(function(){n.networkUpDetected()}))),n}return t(n,e),n.CryptoModule=zi,n}(vn);return $i})); diff --git a/lib/core/components/config.js b/lib/core/components/config.js index 3e10ed32e..0b4c6b105 100644 --- a/lib/core/components/config.js +++ b/lib/core/components/config.js @@ -180,7 +180,7 @@ var default_1 = /** @class */ (function () { return this; }; default_1.prototype.getVersion = function () { - return '7.6.2'; + return '7.6.3'; }; default_1.prototype._setRetryConfiguration = function (configuration) { if (configuration.minimumdelay < 2) { diff --git a/lib/entities/SubscriptionSet.js b/lib/entities/SubscriptionSet.js index bc1417e61..590de45e0 100644 --- a/lib/entities/SubscriptionSet.js +++ b/lib/entities/SubscriptionSet.js @@ -53,12 +53,16 @@ var SubscriptionSet = /** @class */ (function (_super) { _this.options = subscriptionOptions; _this.eventEmitter = eventEmitter; _this.pubnub = pubnub; - channels.forEach(function (c) { + channels + .filter(function (c) { return !c.endsWith('-pnpres'); }) + .forEach(function (c) { var subscription = _this.pubnub.channel(c).subscription(_this.options); _this.channelNames = __spreadArray(__spreadArray([], __read(_this.channelNames), false), __read(subscription.channels), false); _this.subscriptionList.push(subscription); }); - channelGroups.forEach(function (cg) { + channelGroups + .filter(function (cg) { return !cg.endsWith('-pnpres'); }) + .forEach(function (cg) { var subscription = _this.pubnub.channelGroup(cg).subscription(_this.options); _this.groupNames = __spreadArray(__spreadArray([], __read(_this.groupNames), false), __read(subscription.channelGroups), false); _this.subscriptionList.push(subscription); @@ -71,6 +75,7 @@ var SubscriptionSet = /** @class */ (function (_super) { this.subscriptionList.push(subscription); this.channelNames = __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscription.channels), false); this.groupNames = __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(subscription.channelGroups), false); + this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); }; SubscriptionSet.prototype.removeSubscription = function (subscription) { var channelsToRemove = subscription.channels; @@ -78,11 +83,13 @@ var SubscriptionSet = /** @class */ (function (_super) { this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); this.subscriptionList = this.subscriptionList.filter(function (s) { return s !== subscription; }); + this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); }; SubscriptionSet.prototype.addSubscriptionSet = function (subscriptionSet) { this.subscriptionList = __spreadArray(__spreadArray([], __read(this.subscriptionList), false), __read(subscriptionSet.subscriptions), false); this.channelNames = __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscriptionSet.channels), false); this.groupNames = __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(subscriptionSet.channelGroups), false); + this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); }; SubscriptionSet.prototype.removeSubscriptionSet = function (subscriptionSet) { var channelsToRemove = subscriptionSet.channels; @@ -90,6 +97,7 @@ var SubscriptionSet = /** @class */ (function (_super) { this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); this.subscriptionList = this.subscriptionList.filter(function (s) { return !subscriptionSet.subscriptions.includes(s); }); + this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); }; Object.defineProperty(SubscriptionSet.prototype, "subscriptions", { get: function () { diff --git a/package.json b/package.json index 07327404b..ac243ddc9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "7.6.2", + "version": "7.6.3", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/config.js b/src/core/components/config.js index 11b48ec1c..7b7cb1840 100644 --- a/src/core/components/config.js +++ b/src/core/components/config.js @@ -358,7 +358,7 @@ export default class { } getVersion() { - return '7.6.2'; + return '7.6.3'; } _setRetryConfiguration(configuration) { diff --git a/src/entities/SubscriptionSet.ts b/src/entities/SubscriptionSet.ts index 83eedff14..d824e682b 100644 --- a/src/entities/SubscriptionSet.ts +++ b/src/entities/SubscriptionSet.ts @@ -29,16 +29,20 @@ export class SubscriptionSet extends SubscribeCapable { this.options = subscriptionOptions; this.eventEmitter = eventEmitter; this.pubnub = pubnub; - channels.forEach((c) => { - const subscription = this.pubnub.channel(c).subscription(this.options); - this.channelNames = [...this.channelNames, ...subscription.channels]; - this.subscriptionList.push(subscription); - }); - channelGroups.forEach((cg) => { - const subscription = this.pubnub.channelGroup(cg).subscription(this.options); - this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.subscriptionList.push(subscription); - }); + channels + .filter((c) => !c.endsWith('-pnpres')) + .forEach((c) => { + const subscription = this.pubnub.channel(c).subscription(this.options); + this.channelNames = [...this.channelNames, ...subscription.channels]; + this.subscriptionList.push(subscription); + }); + channelGroups + .filter((cg) => !cg.endsWith('-pnpres')) + .forEach((cg) => { + const subscription = this.pubnub.channelGroup(cg).subscription(this.options); + this.groupNames = [...this.groupNames, ...subscription.channelGroups]; + this.subscriptionList.push(subscription); + }); this.listener = {}; eventEmitter.addListener( this.listener, @@ -51,6 +55,7 @@ export class SubscriptionSet extends SubscribeCapable { this.subscriptionList.push(subscription); this.channelNames = [...this.channelNames, ...subscription.channels]; this.groupNames = [...this.groupNames, ...subscription.channelGroups]; + this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); } removeSubscription(subscription: Subscription) { @@ -59,12 +64,14 @@ export class SubscriptionSet extends SubscribeCapable { this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); + this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); } addSubscriptionSet(subscriptionSet: SubscriptionSet) { this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; + this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); } removeSubscriptionSet(subscriptionSet: SubscriptionSet) { @@ -73,6 +80,7 @@ export class SubscriptionSet extends SubscribeCapable { this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); + this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); } get subscriptions(): Subscription[] { From 410930fa497da3ad05f18ec9d6cf21654ddc2e8e Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Mon, 22 Apr 2024 22:17:04 +0300 Subject: [PATCH 05/49] `superagent` replacement and web worker for web (#367) feat(network): replace `superagent` with `fetch` Upgraded the network layer, replacing the `superagent` module with the `Fetch API` for browser integrations and node-fetch for `npm` integrations, ensuring enhanced performance and reliability. feat(service-worker): added service worker Enhanced the subscribe feature with service worker support, improving user experience across multiple browser windows and tabs. feat(types): client interface rewritten with TypeScript The client interface rewritten with TypeScript, which gives an up-to-date interface. * PubNub SDK v8.0.0 release. * Update configuration.ts --------- Co-authored-by: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> --- .eslintrc.js => .eslintrc.cjs | 0 .github/workflows/release/versions.json | 2 +- .github/workflows/run-tests.yml | 11 +- .mocharc.json | 10 + .mocharc.yml | 7 - .pubnub.yml | 15 +- CHANGELOG.md | 8 + README.md | 4 +- cucumber.js | 2 +- dist/web/pubnub.js | 27669 ++++++++-------- dist/web/pubnub.min.js | 19 +- dist/web/pubnub.worker.js | 979 + dist/web/pubnub.worker.min.js | 2 + karma/{web.config.js => web.config.cjs} | 0 lib/cbor/common.js | 34 +- lib/core/components/abort_signal.js | 64 +- lib/core/components/base64_codec.js | 92 +- lib/core/components/config.js | 209 - lib/core/components/configuration.js | 125 + .../components/cryptography/hmac-sha256.js | 14 - lib/core/components/cryptography/index.js | 211 +- lib/core/components/deduping_manager.js | 43 +- lib/core/components/endpoint.js | 282 - lib/core/components/eventEmitter.js | 329 +- lib/core/components/listener_manager.js | 150 +- lib/core/components/push_payload.js | 788 +- lib/core/components/reconnection_manager.js | 45 +- lib/core/components/request.js | 98 + lib/core/components/stringify_buffer_keys.js | 32 +- lib/core/components/subject.js | 26 +- lib/core/components/subscription-manager.js | 354 + lib/core/components/subscription_manager.js | 434 - lib/core/components/telemetry_manager.js | 137 - lib/core/components/token_manager.js | 176 +- lib/core/components/uuid.js | 4 +- lib/core/constants/categories.js | 44 +- lib/core/constants/operations.js | 137 +- lib/core/endpoints/access_manager/audit.js | 88 +- lib/core/endpoints/access_manager/grant.js | 130 +- .../endpoints/access_manager/grant_token.js | 407 +- .../endpoints/access_manager/revoke_token.js | 77 +- .../endpoints/actions/add_message_action.js | 124 +- .../endpoints/actions/get_message_actions.js | 111 +- .../actions/remove_message_action.js | 100 +- .../endpoints/channel_groups/add_channels.js | 95 +- .../endpoints/channel_groups/delete_group.js | 84 +- .../endpoints/channel_groups/list_channels.js | 86 +- .../endpoints/channel_groups/list_groups.js | 77 +- .../channel_groups/remove_channels.js | 95 +- lib/core/endpoints/endpoint.js | 3 - lib/core/endpoints/fetch_messages.js | 267 +- lib/core/endpoints/file_upload/delete_file.js | 76 +- .../endpoints/file_upload/download_file.js | 134 +- .../file_upload/generate_upload_url.js | 87 +- .../endpoints/file_upload/get_file_url.js | 66 +- lib/core/endpoints/file_upload/list_files.js | 87 +- .../endpoints/file_upload/publish_file.js | 118 +- lib/core/endpoints/file_upload/send_file.js | 283 +- lib/core/endpoints/file_upload/types.js | 2 - lib/core/endpoints/file_upload/upload-file.js | 68 + lib/core/endpoints/history/delete_messages.js | 101 +- lib/core/endpoints/history/get_history.js | 183 +- lib/core/endpoints/history/message_counts.js | 119 +- lib/core/endpoints/objects/channel/get.js | 86 +- lib/core/endpoints/objects/channel/get_all.js | 122 +- lib/core/endpoints/objects/channel/remove.js | 70 +- lib/core/endpoints/objects/channel/set.js | 96 +- lib/core/endpoints/objects/member/get.js | 170 +- lib/core/endpoints/objects/member/set.js | 185 +- lib/core/endpoints/objects/membership/get.js | 170 +- lib/core/endpoints/objects/membership/set.js | 188 +- lib/core/endpoints/objects/uuid/get.js | 91 +- lib/core/endpoints/objects/uuid/get_all.js | 120 +- lib/core/endpoints/objects/uuid/remove.js | 77 +- lib/core/endpoints/objects/uuid/set.js | 100 +- lib/core/endpoints/presence/get_state.js | 104 +- lib/core/endpoints/presence/heartbeat.js | 98 +- lib/core/endpoints/presence/here_now.js | 205 +- lib/core/endpoints/presence/leave.js | 97 +- lib/core/endpoints/presence/set_state.js | 99 +- lib/core/endpoints/presence/where_now.js | 84 +- lib/core/endpoints/publish.js | 154 +- lib/core/endpoints/push/add_push_channels.js | 87 +- lib/core/endpoints/push/list_push_channels.js | 89 +- lib/core/endpoints/push/push.js | 70 + lib/core/endpoints/push/remove_device.js | 85 +- .../endpoints/push/remove_push_channels.js | 87 +- lib/core/endpoints/signal.js | 94 +- lib/core/endpoints/subscribe.js | 335 +- .../endpoints/subscriptionUtils/handshake.js | 66 +- .../subscriptionUtils/receiveMessages.js | 105 +- lib/core/endpoints/time.js | 65 +- lib/core/endpoints/user/create.js | 40 - lib/core/endpoints/user/fetch.js | 34 - lib/core/interfaces/configuration.js | 90 + lib/core/interfaces/crypto-module.js | 22 + .../cryptography.js} | 0 .../interfaces/request.js} | 0 .../interfaces/transport.js} | 0 lib/core/pubnub-channel-groups.js | 63 + lib/core/pubnub-common.js | 1423 +- lib/core/pubnub-objects.js | 317 + lib/core/pubnub-push.js | 54 + .../types/api/access-panager.js} | 0 lib/core/types/api/app-context.js | 2 + lib/core/types/api/channel-groups.js | 2 + lib/core/types/api/file-sharing.js | 2 + lib/core/types/api/history.js | 8 + lib/core/types/api/index.js | 2 + lib/core/types/api/message-action.js | 2 + lib/core/types/api/presence.js | 2 + lib/core/types/api/push-notifications.js | 2 + lib/core/types/api/push.js | 2 + lib/core/types/api/subscription.js | 2 + lib/core/types/file.js | 2 + lib/core/types/transport-request.js | 11 + lib/core/types/transport-response.js | 2 + lib/core/utils.js | 103 +- lib/crypto/index.js | 1 - .../modules/NodeCryptoModule/aesCbcCryptor.js | 204 +- .../modules/NodeCryptoModule/legacyCryptor.js | 91 +- .../NodeCryptoModule/nodeCryptoModule.js | 650 +- .../modules/WebCryptoModule/aesCbcCryptor.js | 148 - .../modules/WebCryptoModule/legacyCryptor.js | 90 - .../WebCryptoModule/webCryptoModule.js | 376 - lib/crypto/modules/node.js | 357 +- lib/crypto/modules/web.js | 230 - lib/entities/Channel.js | 17 +- lib/entities/ChannelGroup.js | 17 +- lib/entities/ChannelMetadata.js | 13 +- lib/entities/SubscribeCapable.js | 122 +- lib/entities/Subscription.js | 95 +- lib/entities/SubscriptionSet.js | 146 +- lib/entities/UserMetadata.js | 13 +- lib/errors/pubnub-api-error.js | 140 + lib/errors/pubnub-error.js | 26 + lib/event-engine/core/change.js | 1 - lib/event-engine/core/dispatcher.js | 74 +- lib/event-engine/core/engine.js | 137 +- lib/event-engine/core/handler.js | 57 +- lib/event-engine/core/reconnectionDelay.js | 27 - lib/event-engine/core/retryPolicy.js | 49 +- lib/event-engine/core/state.js | 38 +- lib/event-engine/core/types.js | 52 +- lib/event-engine/dispatcher.js | 330 +- lib/event-engine/effects.js | 20 +- lib/event-engine/events.js | 62 +- lib/event-engine/index.js | 136 +- lib/event-engine/presence/dispatcher.js | 250 +- lib/event-engine/presence/effects.js | 24 +- lib/event-engine/presence/events.js | 32 +- lib/event-engine/presence/presence.js | 84 +- .../presence/states/heartbeat_cooldown.js | 85 +- .../presence/states/heartbeat_failed.js | 81 +- .../presence/states/heartbeat_inactive.js | 16 +- .../presence/states/heartbeat_reconnecting.js | 90 +- .../presence/states/heartbeat_stopped.js | 65 +- .../presence/states/heartbeating.js | 88 +- lib/event-engine/states/handshake_failed.js | 36 +- lib/event-engine/states/handshake_failure.js | 26 - .../states/handshake_reconnecting.js | 71 +- lib/event-engine/states/handshake_stopped.js | 39 +- lib/event-engine/states/handshaking.js | 42 +- lib/event-engine/states/receive_failed.js | 42 +- lib/event-engine/states/receive_failure.js | 38 - .../states/receive_reconnecting.js | 95 +- lib/event-engine/states/receive_stopped.js | 42 +- lib/event-engine/states/receiving.js | 45 +- lib/event-engine/states/unsubscribed.js | 18 +- lib/file/index.js | 2 - lib/file/modules/node.js | 266 +- lib/file/modules/react-native.js | 333 +- lib/file/modules/web.js | 150 - lib/nativescript/index.js | 41 - lib/networking/index.js | 102 - lib/networking/modules/nativescript.js | 78 - lib/networking/modules/node.js | 31 - lib/networking/modules/react_native.js | 164 - lib/networking/modules/titanium.js | 86 - lib/networking/modules/web-node.js | 228 - lib/networking/proxyAgent.js | 15 - lib/networking/utils.js | 33 - lib/node/configuration.js | 10 + lib/node/index.js | 110 +- lib/react_native/configuration.js | 8 + lib/react_native/index.js | 88 +- lib/titanium/index.js | 42 - lib/transport/middleware.js | 106 + lib/transport/node-transport.js | 162 + lib/transport/web-react-native-transport.js | 122 + lib/web/index.js | 84 - package-lock.json | 16874 +++++++--- package.json | 93 +- rollup.config.js | 171 +- src/cbor/common.js | 29 - src/cbor/common.ts | 32 + src/core/components/config.js | 386 - src/core/components/configuration.ts | 220 + src/core/components/cryptography/index.js | 173 - src/core/components/cryptography/index.ts | 309 + src/core/components/deduping_manager.js | 6 +- src/core/components/endpoint.js | 280 - src/core/components/eventEmitter.js | 289 - src/core/components/eventEmitter.ts | 197 + src/core/components/listener_manager.js | 102 - src/core/components/listener_manager.ts | 279 + src/core/components/push_payload.js | 545 - src/core/components/push_payload.ts | 893 + src/core/components/reconnection_manager.js | 34 - src/core/components/reconnection_manager.ts | 56 + src/core/components/request.ts | 182 + src/core/components/stringify_buffer_keys.js | 32 - src/core/components/stringify_buffer_keys.ts | 30 + src/core/components/subscription-manager.ts | 569 + src/core/components/subscription_manager.js | 579 - src/core/components/telemetry_manager.js | 151 - src/core/components/token_manager.js | 157 - src/core/components/token_manager.ts | 333 + src/core/components/{uuid.js => uuid.ts} | 1 + src/core/constants/categories.js | 36 - src/core/constants/categories.ts | 99 + src/core/constants/operations.js | 92 - src/core/constants/operations.ts | 298 + src/core/endpoints/access_manager/audit.js | 49 - src/core/endpoints/access_manager/audit.ts | 110 + src/core/endpoints/access_manager/grant.js | 84 - src/core/endpoints/access_manager/grant.ts | 186 + .../endpoints/access_manager/grant_token.js | 299 - .../endpoints/access_manager/grant_token.ts | 271 + .../endpoints/access_manager/revoke_token.js | 37 - .../endpoints/access_manager/revoke_token.ts | 91 + .../endpoints/actions/add_message_action.js | 56 - .../endpoints/actions/add_message_action.ts | 105 + .../endpoints/actions/get_message_actions.js | 51 - .../endpoints/actions/get_message_actions.ts | 111 + .../actions/remove_message_action.js | 45 - .../actions/remove_message_action.ts | 97 + .../endpoints/channel_groups/add_channels.js | 42 - .../endpoints/channel_groups/add_channels.ts | 104 + .../endpoints/channel_groups/delete_group.js | 40 - .../endpoints/channel_groups/delete_group.ts | 93 + .../endpoints/channel_groups/list_channels.js | 39 - .../endpoints/channel_groups/list_channels.ts | 108 + .../endpoints/channel_groups/list_groups.js | 36 - .../endpoints/channel_groups/list_groups.ts | 101 + .../channel_groups/remove_channels.js | 42 - .../channel_groups/remove_channels.ts | 107 + src/core/endpoints/endpoint.js | 3 - src/core/endpoints/fetch_messages.js | 127 - src/core/endpoints/fetch_messages.ts | 347 + src/core/endpoints/file_upload/delete_file.js | 39 - src/core/endpoints/file_upload/delete_file.ts | 84 + .../endpoints/file_upload/download_file.js | 56 - .../endpoints/file_upload/download_file.ts | 101 + .../file_upload/generate_upload_url.js | 41 - .../file_upload/generate_upload_url.ts | 148 + .../endpoints/file_upload/get_file_url.js | 63 - .../endpoints/file_upload/get_file_url.ts | 70 + src/core/endpoints/file_upload/list_files.js | 45 - src/core/endpoints/file_upload/list_files.ts | 112 + .../endpoints/file_upload/publish_file.js | 79 - .../endpoints/file_upload/publish_file.ts | 134 + src/core/endpoints/file_upload/send_file.js | 130 - src/core/endpoints/file_upload/send_file.ts | 197 + src/core/endpoints/file_upload/types.js | 1 - src/core/endpoints/file_upload/upload-file.ts | 70 + src/core/endpoints/history/delete_messages.js | 50 - src/core/endpoints/history/delete_messages.ts | 98 + src/core/endpoints/history/get_history.js | 92 - src/core/endpoints/history/get_history.ts | 210 + src/core/endpoints/history/message_counts.js | 55 - src/core/endpoints/history/message_counts.ts | 124 + src/core/endpoints/objects/channel/get.js | 40 - src/core/endpoints/objects/channel/get.ts | 91 + src/core/endpoints/objects/channel/get_all.js | 66 - src/core/endpoints/objects/channel/get_all.ts | 105 + src/core/endpoints/objects/channel/remove.js | 31 - src/core/endpoints/objects/channel/remove.ts | 70 + src/core/endpoints/objects/channel/set.js | 49 - src/core/endpoints/objects/channel/set.ts | 97 + src/core/endpoints/objects/member/get.js | 93 - src/core/endpoints/objects/member/get.ts | 153 + src/core/endpoints/objects/member/set.js | 107 - src/core/endpoints/objects/member/set.ts | 155 + src/core/endpoints/objects/membership/get.js | 89 - src/core/endpoints/objects/membership/get.ts | 156 + src/core/endpoints/objects/membership/set.js | 105 - src/core/endpoints/objects/membership/set.ts | 158 + src/core/endpoints/objects/uuid/get.js | 44 - src/core/endpoints/objects/uuid/get.ts | 94 + src/core/endpoints/objects/uuid/get_all.js | 67 - src/core/endpoints/objects/uuid/get_all.ts | 96 + src/core/endpoints/objects/uuid/remove.js | 32 - src/core/endpoints/objects/uuid/remove.ts | 73 + src/core/endpoints/objects/uuid/set.js | 50 - src/core/endpoints/objects/uuid/set.ts | 100 + src/core/endpoints/presence/get_state.js | 53 - src/core/endpoints/presence/get_state.ts | 121 + src/core/endpoints/presence/heartbeat.js | 49 - src/core/endpoints/presence/heartbeat.ts | 102 + src/core/endpoints/presence/here_now.js | 133 - src/core/endpoints/presence/here_now.ts | 216 + src/core/endpoints/presence/leave.js | 44 - src/core/endpoints/presence/leave.ts | 108 + src/core/endpoints/presence/set_state.js | 50 - src/core/endpoints/presence/set_state.ts | 119 + src/core/endpoints/presence/where_now.js | 40 - src/core/endpoints/presence/where_now.ts | 95 + src/core/endpoints/publish.js | 91 - src/core/endpoints/publish.ts | 220 + src/core/endpoints/push/add_push_channels.js | 53 - src/core/endpoints/push/add_push_channels.ts | 59 + src/core/endpoints/push/list_push_channels.js | 54 - src/core/endpoints/push/list_push_channels.ts | 59 + src/core/endpoints/push/push.ts | 121 + src/core/endpoints/push/remove_device.js | 52 - src/core/endpoints/push/remove_device.ts | 59 + .../endpoints/push/remove_push_channels.js | 53 - .../endpoints/push/remove_push_channels.ts | 59 + src/core/endpoints/signal.js | 49 - src/core/endpoints/signal.ts | 103 + src/core/endpoints/subscribe.js | 89 - src/core/endpoints/subscribe.ts | 870 + .../endpoints/subscriptionUtils/handshake.js | 45 - .../endpoints/subscriptionUtils/handshake.ts | 39 + .../subscriptionUtils/receiveMessages.js | 77 - .../subscriptionUtils/receiveMessages.ts | 48 + src/core/endpoints/time.js | 32 - src/core/endpoints/time.ts | 55 + src/core/interfaces/configuration.ts | 789 + src/core/interfaces/crypto-module.ts | 235 + src/core/interfaces/cryptography.ts | 70 + src/core/interfaces/request.ts | 38 + src/core/interfaces/transport.ts | 67 + src/core/pubnub-channel-groups.ts | 222 + src/core/pubnub-common.js | 847 - src/core/pubnub-common.ts | 3271 ++ src/core/pubnub-objects.ts | 1096 + src/core/pubnub-push.ts | 157 + src/core/types/api/access-panager.ts | 564 + src/core/types/api/app-context.ts | 1104 + src/core/types/api/channel-groups.ts | 64 + src/core/types/api/file-sharing.ts | 454 + src/core/types/api/history.ts | 475 + src/core/types/api/index.ts | 145 + src/core/types/api/message-action.ts | 175 + src/core/types/api/presence.ts | 250 + src/core/types/api/push-notifications.ts | 53 + src/core/types/api/push.ts | 156 + src/core/types/api/subscription.ts | 371 + src/core/types/file.ts | 120 + src/core/types/transport-request.ts | 110 + src/core/types/transport-response.ts | 26 + src/core/utils.js | 71 - src/core/utils.ts | 65 + .../modules/NodeCryptoModule/ICryptor.ts | 91 +- .../NodeCryptoModule/ILegacyCryptor.ts | 94 +- .../modules/NodeCryptoModule/aesCbcCryptor.ts | 148 +- .../modules/NodeCryptoModule/legacyCryptor.ts | 77 +- .../NodeCryptoModule/nodeCryptoModule.ts | 450 +- .../modules/WebCryptoModule/ICryptor.ts | 79 +- .../modules/WebCryptoModule/ILegacyCryptor.ts | 94 +- .../modules/WebCryptoModule/aesCbcCryptor.ts | 142 +- .../modules/WebCryptoModule/legacyCryptor.ts | 90 +- .../WebCryptoModule/webCryptoModule.ts | 303 +- src/crypto/modules/node.js | 191 - src/crypto/modules/node.ts | 300 + src/crypto/modules/web.js | 117 - src/crypto/modules/web.ts | 233 + src/entities/Channel.ts | 18 +- src/entities/ChannelGroup.ts | 18 +- src/entities/ChannelMetadata.ts | 18 +- src/entities/SubscribeCapable.ts | 26 +- src/entities/Subscription.ts | 12 +- src/entities/SubscriptionSet.ts | 20 +- src/entities/UserMetadata.ts | 18 +- src/entities/commonTypes.ts | 27 - src/errors/pubnub-api-error.ts | 194 + src/errors/pubnub-error.ts | 30 + src/event-engine/core/handler.ts | 5 +- src/event-engine/core/retryPolicy.ts | 78 +- src/event-engine/core/types.ts | 2 - src/event-engine/dispatcher.ts | 66 +- src/event-engine/effects.ts | 12 +- src/event-engine/events.ts | 39 +- src/event-engine/index.ts | 14 +- src/event-engine/presence/dispatcher.ts | 30 +- src/event-engine/presence/effects.ts | 2 + src/event-engine/presence/events.ts | 2 +- src/event-engine/presence/presence.ts | 4 +- .../presence/states/heartbeat_reconnecting.ts | 2 +- src/event-engine/states/handshake_failed.ts | 6 +- .../states/handshake_reconnecting.ts | 6 +- src/event-engine/states/handshake_stopped.ts | 4 +- src/event-engine/states/handshaking.ts | 4 +- src/event-engine/states/receive_failed.ts | 6 +- .../states/receive_reconnecting.ts | 6 +- src/event-engine/states/receive_stopped.ts | 4 +- src/event-engine/states/receiving.ts | 4 +- src/file/index.js | 1 - src/file/modules/node.js | 136 - src/file/modules/node.ts | 257 + src/file/modules/react-native.js | 167 - src/file/modules/react-native.ts | 265 + src/file/modules/web.js | 116 - src/file/modules/web.ts | 209 + src/networking/index.js | 135 - src/networking/modules/nativescript.js | 85 - src/networking/modules/node.js | 27 - src/networking/modules/react_native.js | 119 - src/networking/modules/titanium.js | 107 - src/networking/modules/web-node.js | 196 - src/networking/proxyAgent.js | 15 - src/networking/utils.js | 29 - src/node/configuration.ts | 94 + src/node/index.ts | 139 +- src/react_native/configuration.ts | 19 + src/react_native/index.js | 35 - src/react_native/index.ts | 67 + src/titanium/configuration.ts | 43 + src/titanium/index.js | 22 - src/titanium/index.ts | 42 + src/transport/middleware.ts | 177 + src/transport/node-transport.ts | 218 + .../subscription-service-worker-middleware.ts | 304 + .../subscription-service-worker.ts | 1390 + src/transport/titanium-transport.ts | 173 + src/transport/web-react-native-transport.ts | 172 + src/web/components/configuration.ts | 80 + src/web/index.js | 67 - src/web/index.ts | 119 + test/contract/definitions/auth.ts | 5 +- test/contract/definitions/event-engine.ts | 27 +- test/contract/definitions/grant.ts | 5 +- test/contract/shared/keysets.ts | 6 +- test/contract/shared/pubnub.ts | 7 +- test/contract/tsconfig.json | 15 +- .../{objectsv2.test.js => objectsv2.test.ts} | 52 +- test/dist/react-native.test.js | 50 +- test/dist/web-titanium.test.js | 112 +- ....node.test.js => file_upload.node.test.ts} | 86 +- test/feature/file_upload.web.test.js | 17 +- .../{config.test.js => config.test.ts} | 16 +- .../{crypto.test.js => crypto.test.ts} | 23 +- .../{listeners.test.js => listeners.test.ts} | 313 +- ...{networking.test.js => networking.test.ts} | 82 +- .../components/reconnection_manager.test.js | 128 - .../components/reconnection_manager.test.ts | 164 + ...r.test.js => subscription_manager.test.ts} | 642 +- ..._manager.test.js => token_manager.test.ts} | 28 +- .../{access.test.js => access.test.ts} | 524 +- .../endpoints/channel_groups.test.js | 265 - .../endpoints/channel_groups.test.ts | 167 + .../endpoints/fetch_messages.test.js | 606 - .../endpoints/fetch_messages.test.ts | 709 + ..._file_url.test.js => get_file_url.test.ts} | 24 +- ...rant_token.test.js => grant_token.test.ts} | 130 +- .../{history.test.js => history.test.ts} | 164 +- .../endpoints/message_actions.test.js | 612 - .../endpoints/message_actions.test.ts | 752 + .../endpoints/message_counts.test.js | 187 - .../endpoints/message_counts.test.ts | 173 + .../{channel.test.js => channel.test.ts} | 30 +- .../objects/{fixtures.js => fixtures.ts} | 2 +- ...{membership.test.js => membership.test.ts} | 9 +- .../objects/{uuid.test.js => uuid.test.ts} | 27 +- .../{presence.test.js => presence.test.ts} | 739 +- test/integration/endpoints/publish.test.js | 300 - test/integration/endpoints/publish.test.ts | 286 + test/integration/endpoints/push.test.js | 632 - test/integration/endpoints/push.test.ts | 342 + test/integration/endpoints/signal.test.js | 80 - test/integration/endpoints/signal.test.ts | 72 + .../{subscribe.test.js => subscribe.test.ts} | 116 +- test/integration/endpoints/time.test.js | 106 - test/integration/endpoints/time.test.ts | 89 + .../{heartbeat.test.js => heartbeat.test.ts} | 81 +- ...teSetting.test.js => stateSetting.test.ts} | 91 +- ...nsubscribe.test.js => unsubscribe.test.ts} | 183 +- test/old_contract/world.ts | 10 +- .../{release.test.js => release.test.ts} | 0 test/setup.js | 10 - test/setup.ts | 8 + test/unit/base64.test.ts | 6 +- test/unit/{cbor.test.js => cbor.test.ts} | 7 +- test/unit/{common.test.js => common.test.ts} | 79 +- test/unit/event_engine.test.ts | 30 +- test/unit/event_engine_presence.test.ts | 35 +- ...nager.test.js => listener_manager.test.ts} | 100 +- test/unit/networking.test.js | 136 - test/unit/networking.test.ts | 37 + ....test.js => notifications_payload.test.ts} | 280 +- test/utils.js | 47 - test/utils.ts | 67 + tsconfig.json | 17 +- tsconfig.mocha.json | 14 +- tsconfig.rollup.json | 26 +- 497 files changed, 66207 insertions(+), 45428 deletions(-) rename .eslintrc.js => .eslintrc.cjs (100%) create mode 100644 .mocharc.json delete mode 100644 .mocharc.yml create mode 100644 dist/web/pubnub.worker.js create mode 100644 dist/web/pubnub.worker.min.js rename karma/{web.config.js => web.config.cjs} (100%) delete mode 100644 lib/core/components/config.js create mode 100644 lib/core/components/configuration.js delete mode 100644 lib/core/components/endpoint.js create mode 100644 lib/core/components/request.js create mode 100644 lib/core/components/subscription-manager.js delete mode 100644 lib/core/components/subscription_manager.js delete mode 100644 lib/core/components/telemetry_manager.js delete mode 100644 lib/core/endpoints/endpoint.js delete mode 100644 lib/core/endpoints/file_upload/types.js create mode 100644 lib/core/endpoints/file_upload/upload-file.js create mode 100644 lib/core/endpoints/push/push.js delete mode 100644 lib/core/endpoints/user/create.js delete mode 100644 lib/core/endpoints/user/fetch.js create mode 100644 lib/core/interfaces/configuration.js create mode 100644 lib/core/interfaces/crypto-module.js rename lib/core/{components/_endpoint.js => interfaces/cryptography.js} (100%) rename lib/{crypto/modules/WebCryptoModule/ICryptor.js => core/interfaces/request.js} (100%) rename lib/{crypto/modules/WebCryptoModule/ILegacyCryptor.js => core/interfaces/transport.js} (100%) create mode 100644 lib/core/pubnub-channel-groups.js create mode 100644 lib/core/pubnub-objects.js create mode 100644 lib/core/pubnub-push.js rename lib/{entities/common.js => core/types/api/access-panager.js} (100%) create mode 100644 lib/core/types/api/app-context.js create mode 100644 lib/core/types/api/channel-groups.js create mode 100644 lib/core/types/api/file-sharing.js create mode 100644 lib/core/types/api/history.js create mode 100644 lib/core/types/api/index.js create mode 100644 lib/core/types/api/message-action.js create mode 100644 lib/core/types/api/presence.js create mode 100644 lib/core/types/api/push-notifications.js create mode 100644 lib/core/types/api/push.js create mode 100644 lib/core/types/api/subscription.js create mode 100644 lib/core/types/file.js create mode 100644 lib/core/types/transport-request.js create mode 100644 lib/core/types/transport-response.js delete mode 100644 lib/crypto/modules/WebCryptoModule/aesCbcCryptor.js delete mode 100644 lib/crypto/modules/WebCryptoModule/legacyCryptor.js delete mode 100644 lib/crypto/modules/WebCryptoModule/webCryptoModule.js delete mode 100644 lib/crypto/modules/web.js create mode 100644 lib/errors/pubnub-api-error.js create mode 100644 lib/errors/pubnub-error.js delete mode 100644 lib/event-engine/core/reconnectionDelay.js delete mode 100644 lib/event-engine/states/handshake_failure.js delete mode 100644 lib/event-engine/states/receive_failure.js delete mode 100644 lib/file/index.js delete mode 100644 lib/file/modules/web.js delete mode 100644 lib/nativescript/index.js delete mode 100644 lib/networking/index.js delete mode 100644 lib/networking/modules/nativescript.js delete mode 100644 lib/networking/modules/node.js delete mode 100644 lib/networking/modules/react_native.js delete mode 100644 lib/networking/modules/titanium.js delete mode 100644 lib/networking/modules/web-node.js delete mode 100644 lib/networking/proxyAgent.js delete mode 100644 lib/networking/utils.js create mode 100644 lib/node/configuration.js create mode 100644 lib/react_native/configuration.js delete mode 100644 lib/titanium/index.js create mode 100644 lib/transport/middleware.js create mode 100644 lib/transport/node-transport.js create mode 100644 lib/transport/web-react-native-transport.js delete mode 100644 lib/web/index.js delete mode 100644 src/cbor/common.js create mode 100644 src/cbor/common.ts delete mode 100644 src/core/components/config.js create mode 100644 src/core/components/configuration.ts delete mode 100644 src/core/components/cryptography/index.js create mode 100644 src/core/components/cryptography/index.ts delete mode 100644 src/core/components/endpoint.js delete mode 100644 src/core/components/eventEmitter.js create mode 100644 src/core/components/eventEmitter.ts delete mode 100644 src/core/components/listener_manager.js create mode 100644 src/core/components/listener_manager.ts delete mode 100644 src/core/components/push_payload.js create mode 100644 src/core/components/push_payload.ts delete mode 100644 src/core/components/reconnection_manager.js create mode 100644 src/core/components/reconnection_manager.ts create mode 100644 src/core/components/request.ts delete mode 100644 src/core/components/stringify_buffer_keys.js create mode 100644 src/core/components/stringify_buffer_keys.ts create mode 100644 src/core/components/subscription-manager.ts delete mode 100644 src/core/components/subscription_manager.js delete mode 100644 src/core/components/telemetry_manager.js delete mode 100644 src/core/components/token_manager.js create mode 100644 src/core/components/token_manager.ts rename src/core/components/{uuid.js => uuid.ts} (72%) delete mode 100644 src/core/constants/categories.js create mode 100644 src/core/constants/categories.ts delete mode 100644 src/core/constants/operations.js create mode 100644 src/core/constants/operations.ts delete mode 100644 src/core/endpoints/access_manager/audit.js create mode 100644 src/core/endpoints/access_manager/audit.ts delete mode 100644 src/core/endpoints/access_manager/grant.js create mode 100644 src/core/endpoints/access_manager/grant.ts delete mode 100644 src/core/endpoints/access_manager/grant_token.js create mode 100644 src/core/endpoints/access_manager/grant_token.ts delete mode 100644 src/core/endpoints/access_manager/revoke_token.js create mode 100644 src/core/endpoints/access_manager/revoke_token.ts delete mode 100644 src/core/endpoints/actions/add_message_action.js create mode 100644 src/core/endpoints/actions/add_message_action.ts delete mode 100644 src/core/endpoints/actions/get_message_actions.js create mode 100644 src/core/endpoints/actions/get_message_actions.ts delete mode 100644 src/core/endpoints/actions/remove_message_action.js create mode 100644 src/core/endpoints/actions/remove_message_action.ts delete mode 100644 src/core/endpoints/channel_groups/add_channels.js create mode 100644 src/core/endpoints/channel_groups/add_channels.ts delete mode 100644 src/core/endpoints/channel_groups/delete_group.js create mode 100644 src/core/endpoints/channel_groups/delete_group.ts delete mode 100644 src/core/endpoints/channel_groups/list_channels.js create mode 100644 src/core/endpoints/channel_groups/list_channels.ts delete mode 100644 src/core/endpoints/channel_groups/list_groups.js create mode 100644 src/core/endpoints/channel_groups/list_groups.ts delete mode 100644 src/core/endpoints/channel_groups/remove_channels.js create mode 100644 src/core/endpoints/channel_groups/remove_channels.ts delete mode 100644 src/core/endpoints/endpoint.js delete mode 100644 src/core/endpoints/fetch_messages.js create mode 100644 src/core/endpoints/fetch_messages.ts delete mode 100644 src/core/endpoints/file_upload/delete_file.js create mode 100644 src/core/endpoints/file_upload/delete_file.ts delete mode 100644 src/core/endpoints/file_upload/download_file.js create mode 100644 src/core/endpoints/file_upload/download_file.ts delete mode 100644 src/core/endpoints/file_upload/generate_upload_url.js create mode 100644 src/core/endpoints/file_upload/generate_upload_url.ts delete mode 100644 src/core/endpoints/file_upload/get_file_url.js create mode 100644 src/core/endpoints/file_upload/get_file_url.ts delete mode 100644 src/core/endpoints/file_upload/list_files.js create mode 100644 src/core/endpoints/file_upload/list_files.ts delete mode 100644 src/core/endpoints/file_upload/publish_file.js create mode 100644 src/core/endpoints/file_upload/publish_file.ts delete mode 100644 src/core/endpoints/file_upload/send_file.js create mode 100644 src/core/endpoints/file_upload/send_file.ts delete mode 100644 src/core/endpoints/file_upload/types.js create mode 100644 src/core/endpoints/file_upload/upload-file.ts delete mode 100644 src/core/endpoints/history/delete_messages.js create mode 100644 src/core/endpoints/history/delete_messages.ts delete mode 100644 src/core/endpoints/history/get_history.js create mode 100644 src/core/endpoints/history/get_history.ts delete mode 100644 src/core/endpoints/history/message_counts.js create mode 100644 src/core/endpoints/history/message_counts.ts delete mode 100644 src/core/endpoints/objects/channel/get.js create mode 100644 src/core/endpoints/objects/channel/get.ts delete mode 100644 src/core/endpoints/objects/channel/get_all.js create mode 100644 src/core/endpoints/objects/channel/get_all.ts delete mode 100644 src/core/endpoints/objects/channel/remove.js create mode 100644 src/core/endpoints/objects/channel/remove.ts delete mode 100644 src/core/endpoints/objects/channel/set.js create mode 100644 src/core/endpoints/objects/channel/set.ts delete mode 100644 src/core/endpoints/objects/member/get.js create mode 100644 src/core/endpoints/objects/member/get.ts delete mode 100644 src/core/endpoints/objects/member/set.js create mode 100644 src/core/endpoints/objects/member/set.ts delete mode 100644 src/core/endpoints/objects/membership/get.js create mode 100644 src/core/endpoints/objects/membership/get.ts delete mode 100644 src/core/endpoints/objects/membership/set.js create mode 100644 src/core/endpoints/objects/membership/set.ts delete mode 100644 src/core/endpoints/objects/uuid/get.js create mode 100644 src/core/endpoints/objects/uuid/get.ts delete mode 100644 src/core/endpoints/objects/uuid/get_all.js create mode 100644 src/core/endpoints/objects/uuid/get_all.ts delete mode 100644 src/core/endpoints/objects/uuid/remove.js create mode 100644 src/core/endpoints/objects/uuid/remove.ts delete mode 100644 src/core/endpoints/objects/uuid/set.js create mode 100644 src/core/endpoints/objects/uuid/set.ts delete mode 100644 src/core/endpoints/presence/get_state.js create mode 100644 src/core/endpoints/presence/get_state.ts delete mode 100644 src/core/endpoints/presence/heartbeat.js create mode 100644 src/core/endpoints/presence/heartbeat.ts delete mode 100644 src/core/endpoints/presence/here_now.js create mode 100644 src/core/endpoints/presence/here_now.ts delete mode 100644 src/core/endpoints/presence/leave.js create mode 100644 src/core/endpoints/presence/leave.ts delete mode 100644 src/core/endpoints/presence/set_state.js create mode 100644 src/core/endpoints/presence/set_state.ts delete mode 100644 src/core/endpoints/presence/where_now.js create mode 100644 src/core/endpoints/presence/where_now.ts delete mode 100644 src/core/endpoints/publish.js create mode 100644 src/core/endpoints/publish.ts delete mode 100644 src/core/endpoints/push/add_push_channels.js create mode 100644 src/core/endpoints/push/add_push_channels.ts delete mode 100644 src/core/endpoints/push/list_push_channels.js create mode 100644 src/core/endpoints/push/list_push_channels.ts create mode 100644 src/core/endpoints/push/push.ts delete mode 100644 src/core/endpoints/push/remove_device.js create mode 100644 src/core/endpoints/push/remove_device.ts delete mode 100644 src/core/endpoints/push/remove_push_channels.js create mode 100644 src/core/endpoints/push/remove_push_channels.ts delete mode 100644 src/core/endpoints/signal.js create mode 100644 src/core/endpoints/signal.ts delete mode 100644 src/core/endpoints/subscribe.js create mode 100644 src/core/endpoints/subscribe.ts delete mode 100644 src/core/endpoints/subscriptionUtils/handshake.js create mode 100644 src/core/endpoints/subscriptionUtils/handshake.ts delete mode 100644 src/core/endpoints/subscriptionUtils/receiveMessages.js create mode 100644 src/core/endpoints/subscriptionUtils/receiveMessages.ts delete mode 100644 src/core/endpoints/time.js create mode 100644 src/core/endpoints/time.ts create mode 100644 src/core/interfaces/configuration.ts create mode 100644 src/core/interfaces/crypto-module.ts create mode 100644 src/core/interfaces/cryptography.ts create mode 100644 src/core/interfaces/request.ts create mode 100644 src/core/interfaces/transport.ts create mode 100644 src/core/pubnub-channel-groups.ts delete mode 100644 src/core/pubnub-common.js create mode 100644 src/core/pubnub-common.ts create mode 100644 src/core/pubnub-objects.ts create mode 100644 src/core/pubnub-push.ts create mode 100644 src/core/types/api/access-panager.ts create mode 100644 src/core/types/api/app-context.ts create mode 100644 src/core/types/api/channel-groups.ts create mode 100644 src/core/types/api/file-sharing.ts create mode 100644 src/core/types/api/history.ts create mode 100644 src/core/types/api/index.ts create mode 100644 src/core/types/api/message-action.ts create mode 100644 src/core/types/api/presence.ts create mode 100644 src/core/types/api/push-notifications.ts create mode 100644 src/core/types/api/push.ts create mode 100644 src/core/types/api/subscription.ts create mode 100644 src/core/types/file.ts create mode 100644 src/core/types/transport-request.ts create mode 100644 src/core/types/transport-response.ts delete mode 100644 src/core/utils.js create mode 100644 src/core/utils.ts delete mode 100644 src/crypto/modules/node.js create mode 100644 src/crypto/modules/node.ts delete mode 100644 src/crypto/modules/web.js create mode 100644 src/crypto/modules/web.ts create mode 100644 src/errors/pubnub-api-error.ts create mode 100644 src/errors/pubnub-error.ts delete mode 100644 src/file/index.js delete mode 100644 src/file/modules/node.js create mode 100644 src/file/modules/node.ts delete mode 100644 src/file/modules/react-native.js create mode 100644 src/file/modules/react-native.ts delete mode 100644 src/file/modules/web.js create mode 100644 src/file/modules/web.ts delete mode 100644 src/networking/index.js delete mode 100644 src/networking/modules/nativescript.js delete mode 100644 src/networking/modules/node.js delete mode 100644 src/networking/modules/react_native.js delete mode 100644 src/networking/modules/titanium.js delete mode 100644 src/networking/modules/web-node.js delete mode 100644 src/networking/proxyAgent.js delete mode 100644 src/networking/utils.js create mode 100644 src/node/configuration.ts create mode 100644 src/react_native/configuration.ts delete mode 100644 src/react_native/index.js create mode 100644 src/react_native/index.ts create mode 100644 src/titanium/configuration.ts delete mode 100644 src/titanium/index.js create mode 100644 src/titanium/index.ts create mode 100644 src/transport/middleware.ts create mode 100644 src/transport/node-transport.ts create mode 100644 src/transport/service-worker/subscription-service-worker-middleware.ts create mode 100644 src/transport/service-worker/subscription-service-worker.ts create mode 100644 src/transport/titanium-transport.ts create mode 100644 src/transport/web-react-native-transport.ts create mode 100644 src/web/components/configuration.ts delete mode 100644 src/web/index.js create mode 100644 src/web/index.ts rename test/dist/{objectsv2.test.js => objectsv2.test.ts} (75%) rename test/feature/{file_upload.node.test.js => file_upload.node.test.ts} (71%) rename test/integration/components/{config.test.js => config.test.ts} (86%) rename test/integration/components/{crypto.test.js => crypto.test.ts} (83%) rename test/integration/components/{listeners.test.js => listeners.test.ts} (61%) rename test/integration/components/{networking.test.js => networking.test.ts} (54%) delete mode 100644 test/integration/components/reconnection_manager.test.js create mode 100644 test/integration/components/reconnection_manager.test.ts rename test/integration/components/{subscription_manager.test.js => subscription_manager.test.ts} (55%) rename test/integration/components/{token_manager.test.js => token_manager.test.ts} (60%) rename test/integration/endpoints/{access.test.js => access.test.ts} (53%) delete mode 100644 test/integration/endpoints/channel_groups.test.js create mode 100644 test/integration/endpoints/channel_groups.test.ts delete mode 100644 test/integration/endpoints/fetch_messages.test.js create mode 100644 test/integration/endpoints/fetch_messages.test.ts rename test/integration/endpoints/{get_file_url.test.js => get_file_url.test.ts} (66%) rename test/integration/endpoints/{grant_token.test.js => grant_token.test.ts} (62%) rename test/integration/endpoints/{history.test.js => history.test.ts} (51%) delete mode 100644 test/integration/endpoints/message_actions.test.js create mode 100644 test/integration/endpoints/message_actions.test.ts delete mode 100644 test/integration/endpoints/message_counts.test.js create mode 100644 test/integration/endpoints/message_counts.test.ts rename test/integration/endpoints/objects/{channel.test.js => channel.test.ts} (92%) rename test/integration/endpoints/objects/{fixtures.js => fixtures.ts} (92%) rename test/integration/endpoints/objects/{membership.test.js => membership.test.ts} (84%) rename test/integration/endpoints/objects/{uuid.test.js => uuid.test.ts} (95%) rename test/integration/endpoints/{presence.test.js => presence.test.ts} (54%) delete mode 100644 test/integration/endpoints/publish.test.js create mode 100644 test/integration/endpoints/publish.test.ts delete mode 100644 test/integration/endpoints/push.test.js create mode 100644 test/integration/endpoints/push.test.ts delete mode 100644 test/integration/endpoints/signal.test.js create mode 100644 test/integration/endpoints/signal.test.ts rename test/integration/endpoints/{subscribe.test.js => subscribe.test.ts} (57%) delete mode 100644 test/integration/endpoints/time.test.js create mode 100644 test/integration/endpoints/time.test.ts rename test/integration/operations/{heartbeat.test.js => heartbeat.test.ts} (68%) rename test/integration/operations/{stateSetting.test.js => stateSetting.test.ts} (62%) rename test/integration/operations/{unsubscribe.test.js => unsubscribe.test.ts} (59%) rename test/release/{release.test.js => release.test.ts} (100%) delete mode 100644 test/setup.js create mode 100644 test/setup.ts rename test/unit/{cbor.test.js => cbor.test.ts} (84%) rename test/unit/{common.test.js => common.test.ts} (64%) rename test/unit/{listener_manager.test.js => listener_manager.test.ts} (59%) delete mode 100644 test/unit/networking.test.js create mode 100644 test/unit/networking.test.ts rename test/unit/{notifications_payload.test.js => notifications_payload.test.ts} (62%) delete mode 100644 test/utils.js create mode 100644 test/utils.ts diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 100% rename from .eslintrc.js rename to .eslintrc.cjs diff --git a/.github/workflows/release/versions.json b/.github/workflows/release/versions.json index 51884f614..dc23f3b23 100644 --- a/.github/workflows/release/versions.json +++ b/.github/workflows/release/versions.json @@ -20,7 +20,7 @@ "clearedSuffix": false } ], - "src/core/components/config.js": [ + "src/core/components/configuration.ts": [ { "pattern": "^\\s{2,}return '(v?(\\.?\\d+){2,}([a-zA-Z0-9-]+(\\.?\\d+)?)?)';$", "clearedPrefix": true, diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 003bf6d03..524b3c68a 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -11,6 +11,11 @@ defaults: shell: bash env: CXX: 'g++-4.8' + PAM_SUBSCRIBE_KEY: ${{ secrets.SDK_PAM_SUB_KEY }} + PAM_PUBLISH_KEY: ${{ secrets.SDK_PAM_PUB_KEY }} + PAM_SECRET_KEY: ${{ secrets.SDK_PAM_SEC_KEY }} + SUBSCRIBE_KEY: ${{ secrets.SDK_SUB_KEY }} + PUBLISH_KEY: ${{ secrets.SDK_PUB_KEY }} jobs: tests: @@ -19,10 +24,10 @@ jobs: strategy: fail-fast: true matrix: - node: [14, 16] + node: [18.18.0, 20] env: ['ci:node'] include: - - node: 16 + - node: 18.18.0 env: 'ci:web' steps: - name: Checkout repository @@ -53,4 +58,4 @@ jobs: needs: [tests] steps: - name: Tests summary - run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed" \ No newline at end of file + run: echo -e "\033[38;2;95;215;0m\033[1mAll tests successfully passed" diff --git a/.mocharc.json b/.mocharc.json new file mode 100644 index 000000000..eb96a9a45 --- /dev/null +++ b/.mocharc.json @@ -0,0 +1,10 @@ +{ + "require": "tsx", + "spec": "test/**/*.test.ts", + "exclude": [ + "test/dist/*.{js,ts}", + "test/feature/*.{js,ts}" + ], + "timeout": 5000, + "reporter": "spec" +} \ No newline at end of file diff --git a/.mocharc.yml b/.mocharc.yml deleted file mode 100644 index 425715e05..000000000 --- a/.mocharc.yml +++ /dev/null @@ -1,7 +0,0 @@ -spec: test/**/*.test.{ts,js} -require: test/setup.js -exclude: - - test/dist/*.js - - test/feature/*.js -timeout: 5000 -reporter: spec diff --git a/.pubnub.yml b/.pubnub.yml index 488da2ef3..f86467bbe 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,14 @@ --- changelog: + - date: 2024-04-22 + version: v8.0.0 + changes: + - type: feature + text: "Upgraded the network layer, replacing the `superagent` module with the `Fetch API` for browser integrations and node-fetch for `npm` integrations, ensuring enhanced performance and reliability." + - type: feature + text: "Added service worker ." + - type: feature + text: "Enhanced the subscribe feature with service worker support, improving user experience across multiple browser windows and tabs. The client interface rewritten with TypeScript, which gives an up-to-date interface." - date: 2024-04-18 version: v7.6.3 changes: @@ -958,7 +967,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '7.6.3' +version: '8.0.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -974,7 +983,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v7.6.3.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.0.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1645,7 +1654,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v7.6.3/pubnub.7.6.3.js + location: https://github.com/pubnub/javascript/releases/download/v8.0.0/pubnub.8.0.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index c23b9c468..8da7ea74d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## v8.0.0 +April 22 2024 + +#### Added +- Upgraded the network layer, replacing the `superagent` module with the `Fetch API` for browser integrations and node-fetch for `npm` integrations, ensuring enhanced performance and reliability. +- Added service worker . +- Enhanced the subscribe feature with service worker support, improving user experience across multiple browser windows and tabs. The client interface rewritten with TypeScript, which gives an up-to-date interface. + ## v7.6.3 April 18 2024 diff --git a/README.md b/README.md index a4edab3ab..b9c208c6e 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.3.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.7.6.3.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.0.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.0.0.min.js 2. Configure your keys: diff --git a/cucumber.js b/cucumber.js index ff60e6702..754cfd292 100644 --- a/cucumber.js +++ b/cucumber.js @@ -7,6 +7,6 @@ module.exports = { '--format summary', '--format progress-bar', // '--format @cucumber/pretty-formatter', - '--publish-quiet', + // '--publish-quiet', ].join(' '), }; diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 66510cb25..92b49723d 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -1,14652 +1,13083 @@ (function (global, factory) { - typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : - typeof define === 'function' && define.amd ? define(factory) : - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.PubNub = factory()); + typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : + typeof define === 'function' && define.amd ? define(factory) : + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.PubNub = factory()); })(this, (function () { 'use strict'; - /*! ***************************************************************************** - Copyright (c) Microsoft Corporation. + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + function getDefaultExportFromCjs (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; + } + + var cbor = {exports: {}}; + + /* + * The MIT License (MIT) + * + * Copyright (c) 2014 Patrick Gansterer + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + (function (module) { + (function(global, undefined$1) { var POW_2_24 = Math.pow(2, -24), + POW_2_32 = Math.pow(2, 32), + POW_2_53 = Math.pow(2, 53); - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted. + function encode(value) { + var data = new ArrayBuffer(256); + var dataView = new DataView(data); + var lastLength; + var offset = 0; - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR - OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - PERFORMANCE OF THIS SOFTWARE. - ***************************************************************************** */ - /* global Reflect, Promise */ + function ensureSpace(length) { + var newByteLength = data.byteLength; + var requiredLength = offset + length; + while (newByteLength < requiredLength) + newByteLength *= 2; + if (newByteLength !== data.byteLength) { + var oldDataView = dataView; + data = new ArrayBuffer(newByteLength); + dataView = new DataView(data); + var uint32count = (offset + 3) >> 2; + for (var i = 0; i < uint32count; ++i) + dataView.setUint32(i * 4, oldDataView.getUint32(i * 4)); + } - var extendStatics = function(d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; + lastLength = length; + return dataView; + } + function write() { + offset += lastLength; + } + function writeFloat64(value) { + write(ensureSpace(8).setFloat64(offset, value)); + } + function writeUint8(value) { + write(ensureSpace(1).setUint8(offset, value)); + } + function writeUint8Array(value) { + var dataView = ensureSpace(value.length); + for (var i = 0; i < value.length; ++i) + dataView.setUint8(offset + i, value[i]); + write(); + } + function writeUint16(value) { + write(ensureSpace(2).setUint16(offset, value)); + } + function writeUint32(value) { + write(ensureSpace(4).setUint32(offset, value)); + } + function writeUint64(value) { + var low = value % POW_2_32; + var high = (value - low) / POW_2_32; + var dataView = ensureSpace(8); + dataView.setUint32(offset, high); + dataView.setUint32(offset + 4, low); + write(); + } + function writeTypeAndLength(type, length) { + if (length < 24) { + writeUint8(type << 5 | length); + } else if (length < 0x100) { + writeUint8(type << 5 | 24); + writeUint8(length); + } else if (length < 0x10000) { + writeUint8(type << 5 | 25); + writeUint16(length); + } else if (length < 0x100000000) { + writeUint8(type << 5 | 26); + writeUint32(length); + } else { + writeUint8(type << 5 | 27); + writeUint64(length); + } + } + + function encodeItem(value) { + var i; - function __extends(d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - } + if (value === false) + return writeUint8(0xf4); + if (value === true) + return writeUint8(0xf5); + if (value === null) + return writeUint8(0xf6); + if (value === undefined$1) + return writeUint8(0xf7); + + switch (typeof value) { + case "number": + if (Math.floor(value) === value) { + if (0 <= value && value <= POW_2_53) + return writeTypeAndLength(0, value); + if (-POW_2_53 <= value && value < 0) + return writeTypeAndLength(1, -(value + 1)); + } + writeUint8(0xfb); + return writeFloat64(value); - var __assign = function() { - __assign = Object.assign || function __assign(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); - }; + case "string": + var utf8data = []; + for (i = 0; i < value.length; ++i) { + var charCode = value.charCodeAt(i); + if (charCode < 0x80) { + utf8data.push(charCode); + } else if (charCode < 0x800) { + utf8data.push(0xc0 | charCode >> 6); + utf8data.push(0x80 | charCode & 0x3f); + } else if (charCode < 0xd800) { + utf8data.push(0xe0 | charCode >> 12); + utf8data.push(0x80 | (charCode >> 6) & 0x3f); + utf8data.push(0x80 | charCode & 0x3f); + } else { + charCode = (charCode & 0x3ff) << 10; + charCode |= value.charCodeAt(++i) & 0x3ff; + charCode += 0x10000; - function __rest(s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; - } + utf8data.push(0xf0 | charCode >> 18); + utf8data.push(0x80 | (charCode >> 12) & 0x3f); + utf8data.push(0x80 | (charCode >> 6) & 0x3f); + utf8data.push(0x80 | charCode & 0x3f); + } + } - function __awaiter(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()); - }); - } + writeTypeAndLength(3, utf8data.length); + return writeUint8Array(utf8data); - function __generator(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 (_) 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 }; - } - } + default: + var length; + if (Array.isArray(value)) { + length = value.length; + writeTypeAndLength(4, length); + for (i = 0; i < length; ++i) + encodeItem(value[i]); + } else if (value instanceof Uint8Array) { + writeTypeAndLength(2, value.length); + writeUint8Array(value); + } else { + var keys = Object.keys(value); + length = keys.length; + writeTypeAndLength(5, length); + for (i = 0; i < length; ++i) { + var key = keys[i]; + encodeItem(key); + encodeItem(value[key]); + } + } + } + } + + encodeItem(value); - function __values(o) { - var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; - if (m) return m.call(o); - if (o && typeof o.length === "number") return { - next: function () { - if (o && i >= o.length) o = void 0; - return { value: o && o[i++], done: !o }; - } - }; - throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); - } + if ("slice" in data) + return data.slice(0, offset); + + var ret = new ArrayBuffer(offset); + var retView = new DataView(ret); + for (var i = 0; i < offset; ++i) + retView.setUint8(i, dataView.getUint8(i)); + return ret; + } - function __read$1(o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; - } + function decode(data, tagger, simpleValue) { + var dataView = new DataView(data); + var offset = 0; + + if (typeof tagger !== "function") + tagger = function(value) { return value; }; + if (typeof simpleValue !== "function") + simpleValue = function() { return undefined$1; }; - function __spreadArray$1(to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); - } - - var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; - - function getAugmentedNamespace(n) { - if (n.__esModule) return n; - var a = Object.defineProperty({}, '__esModule', {value: true}); - Object.keys(n).forEach(function (k) { - var d = Object.getOwnPropertyDescriptor(n, k); - Object.defineProperty(a, k, d.get ? d : { - enumerable: true, - get: function () { - return n[k]; - } - }); - }); - return a; - } - - var cbor = {exports: {}}; - - /* - * The MIT License (MIT) - * - * Copyright (c) 2014 Patrick Gansterer - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - - (function (module) { - (function(global, undefined$1) {var POW_2_24 = Math.pow(2, -24), - POW_2_32 = Math.pow(2, 32), - POW_2_53 = Math.pow(2, 53); + function read(value, length) { + offset += length; + return value; + } + function readArrayBuffer(length) { + return read(new Uint8Array(data, offset, length), length); + } + function readFloat16() { + var tempArrayBuffer = new ArrayBuffer(4); + var tempDataView = new DataView(tempArrayBuffer); + var value = readUint16(); - function encode(value) { - var data = new ArrayBuffer(256); - var dataView = new DataView(data); - var lastLength; - var offset = 0; + var sign = value & 0x8000; + var exponent = value & 0x7c00; + var fraction = value & 0x03ff; + + if (exponent === 0x7c00) + exponent = 0xff << 10; + else if (exponent !== 0) + exponent += (127 - 15) << 10; + else if (fraction !== 0) + return fraction * POW_2_24; + + tempDataView.setUint32(0, sign << 16 | exponent << 13 | fraction << 13); + return tempDataView.getFloat32(0); + } + function readFloat32() { + return read(dataView.getFloat32(offset), 4); + } + function readFloat64() { + return read(dataView.getFloat64(offset), 8); + } + function readUint8() { + return read(dataView.getUint8(offset), 1); + } + function readUint16() { + return read(dataView.getUint16(offset), 2); + } + function readUint32() { + return read(dataView.getUint32(offset), 4); + } + function readUint64() { + return readUint32() * POW_2_32 + readUint32(); + } + function readBreak() { + if (dataView.getUint8(offset) !== 0xff) + return false; + offset += 1; + return true; + } + function readLength(additionalInformation) { + if (additionalInformation < 24) + return additionalInformation; + if (additionalInformation === 24) + return readUint8(); + if (additionalInformation === 25) + return readUint16(); + if (additionalInformation === 26) + return readUint32(); + if (additionalInformation === 27) + return readUint64(); + if (additionalInformation === 31) + return -1; + throw "Invalid length encoding"; + } + function readIndefiniteStringLength(majorType) { + var initialByte = readUint8(); + if (initialByte === 0xff) + return -1; + var length = readLength(initialByte & 0x1f); + if (length < 0 || (initialByte >> 5) !== majorType) + throw "Invalid indefinite length element"; + return length; + } - function ensureSpace(length) { - var newByteLength = data.byteLength; - var requiredLength = offset + length; - while (newByteLength < requiredLength) - newByteLength *= 2; - if (newByteLength !== data.byteLength) { - var oldDataView = dataView; - data = new ArrayBuffer(newByteLength); - dataView = new DataView(data); - var uint32count = (offset + 3) >> 2; - for (var i = 0; i < uint32count; ++i) - dataView.setUint32(i * 4, oldDataView.getUint32(i * 4)); - } + function appendUtf16data(utf16data, length) { + for (var i = 0; i < length; ++i) { + var value = readUint8(); + if (value & 0x80) { + if (value < 0xe0) { + value = (value & 0x1f) << 6 + | (readUint8() & 0x3f); + length -= 1; + } else if (value < 0xf0) { + value = (value & 0x0f) << 12 + | (readUint8() & 0x3f) << 6 + | (readUint8() & 0x3f); + length -= 2; + } else { + value = (value & 0x0f) << 18 + | (readUint8() & 0x3f) << 12 + | (readUint8() & 0x3f) << 6 + | (readUint8() & 0x3f); + length -= 3; + } + } - lastLength = length; - return dataView; - } - function write() { - offset += lastLength; - } - function writeFloat64(value) { - write(ensureSpace(8).setFloat64(offset, value)); - } - function writeUint8(value) { - write(ensureSpace(1).setUint8(offset, value)); - } - function writeUint8Array(value) { - var dataView = ensureSpace(value.length); - for (var i = 0; i < value.length; ++i) - dataView.setUint8(offset + i, value[i]); - write(); - } - function writeUint16(value) { - write(ensureSpace(2).setUint16(offset, value)); - } - function writeUint32(value) { - write(ensureSpace(4).setUint32(offset, value)); - } - function writeUint64(value) { - var low = value % POW_2_32; - var high = (value - low) / POW_2_32; - var dataView = ensureSpace(8); - dataView.setUint32(offset, high); - dataView.setUint32(offset + 4, low); - write(); - } - function writeTypeAndLength(type, length) { - if (length < 24) { - writeUint8(type << 5 | length); - } else if (length < 0x100) { - writeUint8(type << 5 | 24); - writeUint8(length); - } else if (length < 0x10000) { - writeUint8(type << 5 | 25); - writeUint16(length); - } else if (length < 0x100000000) { - writeUint8(type << 5 | 26); - writeUint32(length); - } else { - writeUint8(type << 5 | 27); - writeUint64(length); - } - } - - function encodeItem(value) { - var i; + if (value < 0x10000) { + utf16data.push(value); + } else { + value -= 0x10000; + utf16data.push(0xd800 | (value >> 10)); + utf16data.push(0xdc00 | (value & 0x3ff)); + } + } + } - if (value === false) - return writeUint8(0xf4); - if (value === true) - return writeUint8(0xf5); - if (value === null) - return writeUint8(0xf6); - if (value === undefined$1) - return writeUint8(0xf7); - - switch (typeof value) { - case "number": - if (Math.floor(value) === value) { - if (0 <= value && value <= POW_2_53) - return writeTypeAndLength(0, value); - if (-POW_2_53 <= value && value < 0) - return writeTypeAndLength(1, -(value + 1)); - } - writeUint8(0xfb); - return writeFloat64(value); + function decodeItem() { + var initialByte = readUint8(); + var majorType = initialByte >> 5; + var additionalInformation = initialByte & 0x1f; + var i; + var length; - case "string": - var utf8data = []; - for (i = 0; i < value.length; ++i) { - var charCode = value.charCodeAt(i); - if (charCode < 0x80) { - utf8data.push(charCode); - } else if (charCode < 0x800) { - utf8data.push(0xc0 | charCode >> 6); - utf8data.push(0x80 | charCode & 0x3f); - } else if (charCode < 0xd800) { - utf8data.push(0xe0 | charCode >> 12); - utf8data.push(0x80 | (charCode >> 6) & 0x3f); - utf8data.push(0x80 | charCode & 0x3f); - } else { - charCode = (charCode & 0x3ff) << 10; - charCode |= value.charCodeAt(++i) & 0x3ff; - charCode += 0x10000; + if (majorType === 7) { + switch (additionalInformation) { + case 25: + return readFloat16(); + case 26: + return readFloat32(); + case 27: + return readFloat64(); + } + } - utf8data.push(0xf0 | charCode >> 18); - utf8data.push(0x80 | (charCode >> 12) & 0x3f); - utf8data.push(0x80 | (charCode >> 6) & 0x3f); - utf8data.push(0x80 | charCode & 0x3f); - } - } + length = readLength(additionalInformation); + if (length < 0 && (majorType < 2 || 6 < majorType)) + throw "Invalid length"; - writeTypeAndLength(3, utf8data.length); - return writeUint8Array(utf8data); + switch (majorType) { + case 0: + return length; + case 1: + return -1 - length; + case 2: + if (length < 0) { + var elements = []; + var fullArrayLength = 0; + while ((length = readIndefiniteStringLength(majorType)) >= 0) { + fullArrayLength += length; + elements.push(readArrayBuffer(length)); + } + var fullArray = new Uint8Array(fullArrayLength); + var fullArrayOffset = 0; + for (i = 0; i < elements.length; ++i) { + fullArray.set(elements[i], fullArrayOffset); + fullArrayOffset += elements[i].length; + } + return fullArray; + } + return readArrayBuffer(length); + case 3: + var utf16data = []; + if (length < 0) { + while ((length = readIndefiniteStringLength(majorType)) >= 0) + appendUtf16data(utf16data, length); + } else + appendUtf16data(utf16data, length); + return String.fromCharCode.apply(null, utf16data); + case 4: + var retArray; + if (length < 0) { + retArray = []; + while (!readBreak()) + retArray.push(decodeItem()); + } else { + retArray = new Array(length); + for (i = 0; i < length; ++i) + retArray[i] = decodeItem(); + } + return retArray; + case 5: + var retObject = {}; + for (i = 0; i < length || length < 0 && !readBreak(); ++i) { + var key = decodeItem(); + retObject[key] = decodeItem(); + } + return retObject; + case 6: + return tagger(decodeItem(), length); + case 7: + switch (length) { + case 20: + return false; + case 21: + return true; + case 22: + return null; + case 23: + return undefined$1; + default: + return simpleValue(length); + } + } + } - default: - var length; - if (Array.isArray(value)) { - length = value.length; - writeTypeAndLength(4, length); - for (i = 0; i < length; ++i) - encodeItem(value[i]); - } else if (value instanceof Uint8Array) { - writeTypeAndLength(2, value.length); - writeUint8Array(value); - } else { - var keys = Object.keys(value); - length = keys.length; - writeTypeAndLength(5, length); - for (i = 0; i < length; ++i) { - var key = keys[i]; - encodeItem(key); - encodeItem(value[key]); - } - } - } - } - - encodeItem(value); + var ret = decodeItem(); + if (offset !== data.byteLength) + throw "Remaining bytes"; + return ret; + } - if ("slice" in data) - return data.slice(0, offset); - - var ret = new ArrayBuffer(offset); - var retView = new DataView(ret); - for (var i = 0; i < offset; ++i) - retView.setUint8(i, dataView.getUint8(i)); - return ret; - } + var obj = { encode: encode, decode: decode }; - function decode(data, tagger, simpleValue) { - var dataView = new DataView(data); - var offset = 0; - - if (typeof tagger !== "function") - tagger = function(value) { return value; }; - if (typeof simpleValue !== "function") - simpleValue = function() { return undefined$1; }; + if (typeof undefined$1 === "function" && undefined$1.amd) + undefined$1("cbor/cbor", obj); + else if (module.exports) + module.exports = obj; + else if (!global.CBOR) + global.CBOR = obj; - function read(value, length) { - offset += length; - return value; - } - function readArrayBuffer(length) { - return read(new Uint8Array(data, offset, length), length); - } - function readFloat16() { - var tempArrayBuffer = new ArrayBuffer(4); - var tempDataView = new DataView(tempArrayBuffer); - var value = readUint16(); + })(commonjsGlobal); + } (cbor)); + + var cborExports = cbor.exports; + var CborReader = /*@__PURE__*/getDefaultExportFromCjs(cborExports); + + /** + * Request processing status categories. + */ + var StatusCategory; + (function (StatusCategory) { + /** + * Call failed when network was unable to complete the call. + */ + StatusCategory["PNNetworkIssuesCategory"] = "PNNetworkIssuesCategory"; + /** + * Network call timed out. + */ + StatusCategory["PNTimeoutCategory"] = "PNTimeoutCategory"; + /** + * Request has been cancelled. + */ + StatusCategory["PNCancelledCategory"] = "PNCancelledCategory"; + /** + * Server responded with bad response. + */ + StatusCategory["PNBadRequestCategory"] = "PNBadRequestCategory"; + /** + * Server responded with access denied. + */ + StatusCategory["PNAccessDeniedCategory"] = "PNAccessDeniedCategory"; + /** + * Incomplete parameters provided for used endpoint. + */ + StatusCategory["PNValidationErrorCategory"] = "PNValidationErrorCategory"; + /** + * PubNub request acknowledgment status. + * + * Some API endpoints respond with request processing status w/o useful data. + */ + StatusCategory["PNAcknowledgmentCategory"] = "PNAcknowledgmentCategory"; + /** + * Something strange happened; please check the logs. + */ + StatusCategory["PNUnknownCategory"] = "PNUnknownCategory"; + // -------------------------------------------------------- + // --------------------- Network status ------------------- + // -------------------------------------------------------- + /** + * SDK will announce when the network appears to be connected again. + */ + StatusCategory["PNNetworkUpCategory"] = "PNNetworkUpCategory"; + /** + * SDK will announce when the network appears to down. + */ + StatusCategory["PNNetworkDownCategory"] = "PNNetworkDownCategory"; + // -------------------------------------------------------- + // -------------------- Real-time events ------------------ + // -------------------------------------------------------- + /** + * PubNub client reconnected to the real-time updates stream. + */ + StatusCategory["PNReconnectedCategory"] = "PNReconnectedCategory"; + /** + * PubNub client connected to the real-time updates stream. + */ + StatusCategory["PNConnectedCategory"] = "PNConnectedCategory"; + /** + * Received real-time updates exceed specified threshold. + * + * After temporary disconnection and catchup, this category means that potentially some + * real-time updates have been pushed into `storage` and need to be requested separately. + */ + StatusCategory["PNRequestMessageCountExceededCategory"] = "PNRequestMessageCountExceededCategory"; + /** + * PubNub client disconnected from the real-time updates streams. + */ + StatusCategory["PNDisconnectedCategory"] = "PNDisconnectedCategory"; + /** + * PubNub client wasn't able to connect to the real-time updates streams. + */ + StatusCategory["PNConnectionErrorCategory"] = "PNConnectionErrorCategory"; + /** + * PubNub client unexpectedly disconnected from the real-time updates streams. + */ + StatusCategory["PNDisconnectedUnexpectedlyCategory"] = "PNDisconnectedUnexpectedlyCategory"; + })(StatusCategory || (StatusCategory = {})); + var StatusCategory$1 = StatusCategory; + + class PubNubError extends Error { + constructor(message, status) { + super(message); + this.status = status; + this.name = 'PubNubError'; + this.message = message; + Object.setPrototypeOf(this, new.target.prototype); + } + } + function createError(errorPayload) { + var _a; + (_a = errorPayload.statusCode) !== null && _a !== void 0 ? _a : (errorPayload.statusCode = 0); + return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: StatusCategory$1.PNValidationErrorCategory, error: true }); + } + function createValidationError(message, statusCode) { + return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {}))); + } + + /** + * REST API endpoint use error module. + */ + /** + * PubNub REST API call error. + */ + class PubNubAPIError extends Error { + /** + * Construct API from known error object or {@link PubNub} service error response. + * + * @param errorOrResponse - `Error` or service error response object from which error information + * should be extracted. + * @param data - Preprocessed service error response. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + static create(errorOrResponse, data) { + if (errorOrResponse instanceof Error) + return PubNubAPIError.createFromError(errorOrResponse); + else + return PubNubAPIError.createFromServiceResponse(errorOrResponse, data); + } + /** + * Create API error instance from other error object. + * + * @param error - `Error` object provided by network provider (mostly) or other {@link PubNub} client components. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + static createFromError(error) { + let category = StatusCategory$1.PNUnknownCategory; + let message = 'Unknown error'; + let errorName = 'Error'; + if (!error) + return new PubNubAPIError(message, category, 0); + else if (error instanceof PubNubAPIError) + return error; + if (error instanceof Error) { + message = error.message; + errorName = error.name; + } + if (errorName === 'AbortError' || message.indexOf('Aborted') !== -1) { + category = StatusCategory$1.PNCancelledCategory; + message = 'Request cancelled'; + } + else if (message.indexOf('timeout') !== -1) { + category = StatusCategory$1.PNTimeoutCategory; + message = 'Request timeout'; + } + else if (message.indexOf('network') !== -1) { + category = StatusCategory$1.PNNetworkIssuesCategory; + message = 'Network issues'; + } + else if (errorName === 'TypeError') { + category = StatusCategory$1.PNBadRequestCategory; + } + else if (errorName === 'FetchError') { + const errorCode = error.code; + if (['ECONNREFUSED', 'ENETUNREACH', 'ENOTFOUND', 'ECONNRESET', 'EAI_AGAIN'].includes(errorCode)) + category = StatusCategory$1.PNNetworkIssuesCategory; + if (errorCode === 'ECONNREFUSED') + message = 'Connection refused'; + else if (errorCode === 'ENETUNREACH') + message = 'Network not reachable'; + else if (errorCode === 'ENOTFOUND') + message = 'Server not found'; + else if (errorCode === 'ECONNRESET') + message = 'Connection reset by peer'; + else if (errorCode === 'EAI_AGAIN') + message = 'Name resolution error'; + else if (errorCode === 'ETIMEDOUT') { + category = StatusCategory$1.PNTimeoutCategory; + message = 'Request timeout'; + } + else + message = `Unknown system error: ${error}`; + } + else if (message === 'Request timeout') + category = StatusCategory$1.PNTimeoutCategory; + return new PubNubAPIError(message, category, 0, error); + } + /** + * Construct API from known {@link PubNub} service error response. + * + * @param response - Service error response object from which error information should be + * extracted. + * @param data - Preprocessed service error response. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + static createFromServiceResponse(response, data) { + let category = StatusCategory$1.PNUnknownCategory; + let errorData; + let message = 'Unknown error'; + let { status } = response; + data !== null && data !== void 0 ? data : (data = response.body); + if (status === 402) + message = 'Not available for used key set. Contact support@pubnub.com'; + else if (status === 400) { + category = StatusCategory$1.PNBadRequestCategory; + message = 'Bad request'; + } + else if (status === 403) { + category = StatusCategory$1.PNAccessDeniedCategory; + message = 'Access denied'; + } + // Try to get more information about error from service response. + if (data && data.byteLength > 0) { + const decoded = new TextDecoder().decode(data); + if (response.headers['content-type'].indexOf('text/javascript') !== -1 || + response.headers['content-type'].indexOf('application/json') !== -1) { + try { + const errorResponse = JSON.parse(decoded); + if (typeof errorResponse === 'object' && !Array.isArray(errorResponse)) { + if ('error' in errorResponse && + (errorResponse.error === 1 || errorResponse.error === true) && + 'status' in errorResponse && + typeof errorResponse.status === 'number' && + 'message' in errorResponse && + 'service' in errorResponse) { + errorData = errorResponse; + status = errorResponse.status; + } + else + errorData = errorResponse; + if ('error' in errorResponse && errorResponse.error instanceof Error) + errorData = errorResponse.error; + } + } + catch (_) { + errorData = decoded; + } + } + else if (response.headers['content-type'].indexOf('xml') !== -1) { + const reason = /(.*)<\/Message>/gi.exec(decoded); + message = reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.'; + } + else { + errorData = decoded; + } + } + return new PubNubAPIError(message, category, status, errorData); + } + /** + * Construct PubNub endpoint error. + * + * @param message - Short API call error description. + * @param category - Error category. + * @param statusCode - Response HTTP status code. + * @param errorData - Error information. + */ + constructor(message, category, statusCode, errorData) { + super(message); + this.category = category; + this.statusCode = statusCode; + this.errorData = errorData; + this.name = 'PubNubAPIError'; + } + /** + * Convert API error object to API callback status object. + * + * @param operation - Request operation during which error happened. + * + * @returns Pre-formatted API callback status object. + */ + toStatus(operation) { + return { + error: true, + category: this.category, + operation, + statusCode: this.statusCode, + errorData: this.errorData, + }; + } + /** + * Convert API error object to PubNub client error object. + * + * @param operation - Request operation during which error happened. + * @param message - Custom error message. + * + * @returns Client-facing pre-formatted endpoint call error. + */ + toPubNubError(operation, message) { + return new PubNubError(message !== null && message !== void 0 ? message : this.message, this.toStatus(operation)); + } + } + + /** + * Subscription Service Worker transport middleware module. + * + * Middleware optimize subscription feature requests utilizing `Subscription Service Worker` if available and not + * disabled by user. + */ + // endregion + /** + * Subscription Service Worker transport middleware. + */ + class SubscriptionServiceWorkerMiddleware { + constructor(configuration) { + this.configuration = configuration; + this.serviceWorkerEventsQueue = []; + this.callbacks = new Map(); + this.setupServiceWorker(); + } + makeSendable(req) { + // Use default request flow for non-subscribe / presence leave requests. + if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/leave')) + return this.configuration.transport.makeSendable(req); + let controller; + const sendRequestEvent = { + type: 'send-request', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + logVerbosity: this.configuration.logVerbosity, + request: req, + }; + if (req.cancellable) { + controller = { + abort: () => { + const cancelRequest = { + type: 'cancel-request', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + logVerbosity: this.configuration.logVerbosity, + identifier: req.identifier, + }; + // Cancel active request with specified identifier. + this.scheduleEventPost(cancelRequest); + }, + }; + } + return [ + new Promise((resolve, reject) => { + // Associate Promise resolution / reject with request identifier for future usage in + // `onmessage` handler block to return results. + this.callbacks.set(req.identifier, { resolve, reject }); + // Trigger request processing by Service Worker. + this.scheduleEventPost(sendRequestEvent); + }), + controller, + ]; + } + request(req) { + return req; + } + /** + * Schedule {@link event} publish to the service worker. + * + * Service worker may not be ready for events processing and this method build queue for the time when worker will be + * ready. + * + * @param event - Event payload for service worker. + * @param outOfOrder - Whether event should be processed first then enqueued queue. + */ + scheduleEventPost(event, outOfOrder = false) { + // Trigger request processing by Web Worker. + const serviceWorker = this.serviceWorker; + if (serviceWorker) + serviceWorker.postMessage(event); + else { + if (outOfOrder) + this.serviceWorkerEventsQueue.splice(0, 0, event); + else + this.serviceWorkerEventsQueue.push(event); + } + } + /** + * Dequeue and post events from the queue to the service worker. + */ + flushScheduledEvents() { + // Trigger request processing by Web Worker. + const serviceWorker = this.serviceWorker; + if (!serviceWorker || this.serviceWorkerEventsQueue.length === 0) + return; + // Clean up from cancelled events. + const outdatedEvents = []; + for (let i = 0; i < this.serviceWorkerEventsQueue.length; i++) { + const event = this.serviceWorkerEventsQueue[i]; + // Check whether found request cancel event to search for request send event it cancels. + if (event.type !== 'cancel-request' || i === 0) + continue; + for (let j = 0; j < i; j++) { + const otherEvent = this.serviceWorkerEventsQueue[j]; + if (otherEvent.type !== 'send-request') + continue; + // Collect outdated events if identifiers match. + if (otherEvent.request.identifier === event.identifier) { + outdatedEvents.push(event, otherEvent); + break; + } + } + } + // Actualizing events queue. + this.serviceWorkerEventsQueue = this.serviceWorkerEventsQueue.filter((event) => !outdatedEvents.includes(event)); + this.serviceWorkerEventsQueue.forEach((event) => serviceWorker.postMessage(event)); + this.serviceWorkerEventsQueue = []; + } + /** + * Subscription service worker. + * + * @returns Service worker which has been registered by the PubNub SDK. + */ + get serviceWorker() { + return this.serviceWorkerRegistration ? this.serviceWorkerRegistration.active : null; + } + setupServiceWorker() { + if (!('serviceWorker' in navigator)) + return; + const serviceWorkerContainer = navigator.serviceWorker; + serviceWorkerContainer + .register(`https://cdn.pubnub.com/sdk/javascript/dist/web/pubnub.worker.js`, { + scope: `/pubnub-${this.configuration.sdkVersion}`, + }) + .then((registration) => { + this.serviceWorkerRegistration = registration; + // Flush any pending service worker events. + if (registration.active) + this.flushScheduledEvents(); + /** + * Listening for service worker code update. + * + * It is possible that one of the tabs will open with newer SDK version and Subscription Service Worker + * will be re-installed - in this case we need to "rehydrate" it. + * + * After re-installation of new service worker it will lose all accumulated state and client need to + * re-introduce itself and its state. + */ + this.serviceWorkerRegistration.addEventListener('updatefound', () => { + if (!this.serviceWorkerRegistration) + return; + // New service installing right now. + const serviceWorker = this.serviceWorkerRegistration.installing; + const stateChangeListener = () => { + // Flush any pending service worker events. + if (serviceWorker.state === 'activated') { + // Flush any pending service worker events. + this.flushScheduledEvents(); + } + else if (serviceWorker.state === 'redundant') { + // Clean up listener from deprecated service worker version. + serviceWorker.removeEventListener('statechange', stateChangeListener); + } + }; + serviceWorker.addEventListener('statechange', stateChangeListener); + }); + }); + serviceWorkerContainer.addEventListener('message', (event) => this.handleServiceWorkerEvent(event)); + } + handleServiceWorkerEvent(event) { + const { data } = event; + // Ignoring updates not related to this instance. + if (data.clientIdentifier !== this.configuration.clientIdentifier) + return; + if (data.type === 'request-progress-start' || data.type === 'request-progress-end') { + this.logRequestProgress(data); + } + else if (data.type === 'request-process-success' || data.type === 'request-process-error') { + const { resolve, reject } = this.callbacks.get(data.identifier); + if (data.type === 'request-process-success') { + resolve({ + status: data.response.status, + url: data.url, + headers: data.response.headers, + body: data.response.body, + }); + } + else { + let category = StatusCategory$1.PNUnknownCategory; + let message = 'Unknown error'; + // Handle client-side issues (if any). + if (data.error) { + if (data.error.type === 'NETWORK_ISSUE') + category = StatusCategory$1.PNNetworkIssuesCategory; + else if (data.error.type === 'TIMEOUT') + category = StatusCategory$1.PNTimeoutCategory; + else if (data.error.type === 'ABORTED') + category = StatusCategory$1.PNCancelledCategory; + message = `${data.error.message} (${data.identifier})`; + } + // Handle service error response. + else if (data.response) { + return reject(PubNubAPIError.create({ + url: data.url, + headers: data.response.headers, + body: data.response.body, + status: data.response.status, + }, data.response.body)); + } + reject(new PubNubAPIError(message, category, 0, new Error(message))); + } + } + } + /** + * Print request progress information. + * + * @param information - Request progress information from Web Worker. + */ + logRequestProgress(information) { + var _a, _b; + if (information.type === 'request-progress-start') { + console.log('<<<<<'); + console.log(`[${information.timestamp}] ${information.url}\n${JSON.stringify((_a = information.query) !== null && _a !== void 0 ? _a : {})}`); + console.log('-----'); + } + else { + console.log('>>>>>>'); + console.log(`[${information.timestamp} / ${information.duration}] ${information.url}\n${JSON.stringify((_b = information.query) !== null && _b !== void 0 ? _b : {})}\n${information.response}`); + console.log('-----'); + } + } + } + + /****************************************************************************** + Copyright (c) Microsoft Corporation. - var sign = value & 0x8000; - var exponent = value & 0x7c00; - var fraction = value & 0x03ff; - - if (exponent === 0x7c00) - exponent = 0xff << 10; - else if (exponent !== 0) - exponent += (127 - 15) << 10; - else if (fraction !== 0) - return fraction * POW_2_24; - - tempDataView.setUint32(0, sign << 16 | exponent << 13 | fraction << 13); - return tempDataView.getFloat32(0); - } - function readFloat32() { - return read(dataView.getFloat32(offset), 4); - } - function readFloat64() { - return read(dataView.getFloat64(offset), 8); - } - function readUint8() { - return read(dataView.getUint8(offset), 1); - } - function readUint16() { - return read(dataView.getUint16(offset), 2); - } - function readUint32() { - return read(dataView.getUint32(offset), 4); - } - function readUint64() { - return readUint32() * POW_2_32 + readUint32(); - } - function readBreak() { - if (dataView.getUint8(offset) !== 0xff) - return false; - offset += 1; - return true; - } - function readLength(additionalInformation) { - if (additionalInformation < 24) - return additionalInformation; - if (additionalInformation === 24) - return readUint8(); - if (additionalInformation === 25) - return readUint16(); - if (additionalInformation === 26) - return readUint32(); - if (additionalInformation === 27) - return readUint64(); - if (additionalInformation === 31) - return -1; - throw "Invalid length encoding"; - } - function readIndefiniteStringLength(majorType) { - var initialByte = readUint8(); - if (initialByte === 0xff) - return -1; - var length = readLength(initialByte & 0x1f); - if (length < 0 || (initialByte >> 5) !== majorType) - throw "Invalid indefinite length element"; - return length; - } + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted. - function appendUtf16data(utf16data, length) { - for (var i = 0; i < length; ++i) { - var value = readUint8(); - if (value & 0x80) { - if (value < 0xe0) { - value = (value & 0x1f) << 6 - | (readUint8() & 0x3f); - length -= 1; - } else if (value < 0xf0) { - value = (value & 0x0f) << 12 - | (readUint8() & 0x3f) << 6 - | (readUint8() & 0x3f); - length -= 2; - } else { - value = (value & 0x0f) << 18 - | (readUint8() & 0x3f) << 12 - | (readUint8() & 0x3f) << 6 - | (readUint8() & 0x3f); - length -= 3; - } - } + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THIS SOFTWARE. + ***************************************************************************** */ + /* global Reflect, Promise, SuppressedError, Symbol */ - if (value < 0x10000) { - utf16data.push(value); - } else { - value -= 0x10000; - utf16data.push(0xd800 | (value >> 10)); - utf16data.push(0xdc00 | (value & 0x3ff)); - } - } - } - function decodeItem() { - var initialByte = readUint8(); - var majorType = initialByte >> 5; - var additionalInformation = initialByte & 0x1f; - var i; - var length; + function __rest(s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; + } - if (majorType === 7) { - switch (additionalInformation) { - case 25: - return readFloat16(); - case 26: - return readFloat32(); - case 27: - return readFloat64(); - } - } + function __awaiter(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()); + }); + } - length = readLength(additionalInformation); - if (length < 0 && (majorType < 2 || 6 < majorType)) - throw "Invalid length"; - - switch (majorType) { - case 0: - return length; - case 1: - return -1 - length; - case 2: - if (length < 0) { - var elements = []; - var fullArrayLength = 0; - while ((length = readIndefiniteStringLength(majorType)) >= 0) { - fullArrayLength += length; - elements.push(readArrayBuffer(length)); - } - var fullArray = new Uint8Array(fullArrayLength); - var fullArrayOffset = 0; - for (i = 0; i < elements.length; ++i) { - fullArray.set(elements[i], fullArrayOffset); - fullArrayOffset += elements[i].length; - } - return fullArray; - } - return readArrayBuffer(length); - case 3: - var utf16data = []; - if (length < 0) { - while ((length = readIndefiniteStringLength(majorType)) >= 0) - appendUtf16data(utf16data, length); - } else - appendUtf16data(utf16data, length); - return String.fromCharCode.apply(null, utf16data); - case 4: - var retArray; - if (length < 0) { - retArray = []; - while (!readBreak()) - retArray.push(decodeItem()); - } else { - retArray = new Array(length); - for (i = 0; i < length; ++i) - retArray[i] = decodeItem(); - } - return retArray; - case 5: - var retObject = {}; - for (i = 0; i < length || length < 0 && !readBreak(); ++i) { - var key = decodeItem(); - retObject[key] = decodeItem(); - } - return retObject; - case 6: - return tagger(decodeItem(), length); - case 7: - switch (length) { - case 20: - return false; - case 21: - return true; - case 22: - return null; - case 23: - return undefined$1; - default: - return simpleValue(length); - } - } - } - - var ret = decodeItem(); - if (offset !== data.byteLength) - throw "Remaining bytes"; - return ret; - } - - var obj = { encode: encode, decode: decode }; - - if (typeof undefined$1 === "function" && undefined$1.amd) - undefined$1("cbor/cbor", obj); - else if (module.exports) - module.exports = obj; - else if (!global.CBOR) - global.CBOR = obj; - - })(commonjsGlobal); - }(cbor)); - - var CborReader = cbor.exports; - - var uuid = {exports: {}}; - - /*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */ - - (function (module, exports) { - (function (root, factory) { - { - factory(exports); - if (module !== null) { - module.exports = exports.uuid; - } - } - }(commonjsGlobal, function (exports) { - var VERSION = '0.1.0'; - var uuidRegex = { - '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, - '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, - '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, - all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i - }; - - function uuid() { - var uuid = '', i, random; - for (i = 0; i < 32; i++) { - random = Math.random() * 16 | 0; - if (i === 8 || i === 12 || i === 16 || i === 20) uuid += '-'; - uuid += (i === 12 ? 4 : (i === 16 ? (random & 3 | 8) : random)).toString(16); - } - return uuid - } - - function isUUID(str, version) { - var pattern = uuidRegex[version || 'all']; - return pattern && pattern.test(str) || false - } - - uuid.isUUID = isUUID; - uuid.VERSION = VERSION; - - exports.uuid = uuid; - exports.isUUID = isUUID; - })); - }(uuid, uuid.exports)); - - var uuidGenerator$1 = uuid.exports; - - var uuidGenerator = { - createUUID: function () { - if (uuidGenerator$1.uuid) { - return uuidGenerator$1.uuid(); - } - return uuidGenerator$1(); - }, - }; - - /* */ - var PRESENCE_TIMEOUT_MINIMUM = 20; - var PRESENCE_TIMEOUT_DEFAULT = 300; - var makeDefaultOrigins = function () { return Array.from({ length: 20 }, function (_, i) { return "ps".concat(i + 1, ".pndsn.com"); }); }; - var default_1$b = /** @class */ (function () { - function default_1(_a) { - var setup = _a.setup; - var _b, _c, _d, _e; - this._PNSDKSuffix = {}; - this.instanceId = "pn-".concat(uuidGenerator.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.cryptoModule = setup.cryptoModule; - this.setFilterExpression(setup.filterExpression); - if (typeof setup.origin !== 'string' && !Array.isArray(setup.origin) && setup.origin !== undefined) { - throw new Error('Origin must be either undefined, a string or a list of strings.'); - } - this.origin = setup.origin || makeDefaultOrigins(); - 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 = (_b = setup.fileUploadPublishRetryLimit) !== null && _b !== void 0 ? _b : 5; - this.useRandomIVs = (_c = setup.useRandomIVs) !== null && _c !== void 0 ? _c : true; - this.enableEventEngine = (_d = setup.enableEventEngine) !== null && _d !== void 0 ? _d : false; - this.maintainPresenceState = (_e = setup.maintainPresenceState) !== null && _e !== void 0 ? _e : true; - // if location config exist and we are in https, force secure to 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; - if (setup.retryConfiguration) { - this._setRetryConfiguration(setup.retryConfiguration); - } - // set timeout to how long a transaction request will wait for the server (default 15 seconds) - this.setTransactionTimeout(setup.transactionalRequestTimeout || 15 * 1000); - // set timeout to how long a subscribe event loop will run (default 310 seconds) - this.setSubscribeTimeout(setup.subscribeRequestTimeout || 310 * 1000); - // set config on beacon (https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon) usage - this.setSendBeaconConfig(setup.useSendBeacon || true); - // how long the SDK will report the client to be alive before issuing a timeout - if (setup.presenceTimeout) { - this.setPresenceTimeout(setup.presenceTimeout); - } - else { - this._presenceTimeout = PRESENCE_TIMEOUT_DEFAULT; - } - if (setup.heartbeatInterval != null) { - this.setHeartbeatInterval(setup.heartbeatInterval); - } - if (typeof setup.userId === 'string') { - if (typeof setup.uuid === 'string') { - throw new Error('Only one of the following configuration options has to be provided: `uuid` or `userId`'); - } - this.setUserId(setup.userId); - } - else { - if (typeof setup.uuid !== 'string') { - throw new Error('One of the following configuration options has to be provided: `uuid` or `userId`'); - } - this.setUUID(setup.uuid); - } - this.setCipherKey(setup.cipherKey, setup); - } - // exposed setters - default_1.prototype.getAuthKey = function () { - return this.authKey; - }; - default_1.prototype.setAuthKey = function (val) { - this.authKey = val; - return this; - }; - default_1.prototype.setCipherKey = function (val, setup, modules) { - var _a; - this.cipherKey = val; - if (this.cipherKey) { - this.cryptoModule = - (_a = setup.cryptoModule) !== null && _a !== void 0 ? _a : setup.initCryptoModule({ cipherKey: this.cipherKey, useRandomIVs: this.useRandomIVs }); - if (modules) - modules.cryptoModule = this.cryptoModule; - } - return this; - }; - default_1.prototype.getUUID = function () { - return this.UUID; - }; - default_1.prototype.setUUID = function (val) { - if (!val || typeof val !== 'string' || val.trim().length === 0) { - throw new Error('Missing uuid parameter. Provide a valid string uuid'); - } - this.UUID = val; - return this; - }; - default_1.prototype.getUserId = function () { - return this.UUID; - }; - default_1.prototype.setUserId = function (value) { - if (!value || typeof value !== 'string' || value.trim().length === 0) { - throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); - } - this.UUID = value; - return this; - }; - default_1.prototype.getFilterExpression = function () { - return this.filterExpression; - }; - default_1.prototype.setFilterExpression = function (val) { - this.filterExpression = val; - return this; - }; - default_1.prototype.getPresenceTimeout = function () { - return this._presenceTimeout; - }; - default_1.prototype.setPresenceTimeout = function (val) { - if (val >= PRESENCE_TIMEOUT_MINIMUM) { - this._presenceTimeout = val; - } - else { - this._presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; - // eslint-disable-next-line no-console - console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', this._presenceTimeout); - } - this.setHeartbeatInterval(this._presenceTimeout / 2 - 1); - return this; - }; - default_1.prototype.setProxy = function (proxy) { - this.proxy = proxy; - }; - default_1.prototype.getHeartbeatInterval = function () { - return this._heartbeatInterval; - }; - default_1.prototype.setHeartbeatInterval = function (val) { - this._heartbeatInterval = val; - return this; - }; - // deprecated setters. - default_1.prototype.getSubscribeTimeout = function () { - return this._subscribeRequestTimeout; - }; - default_1.prototype.setSubscribeTimeout = function (val) { - this._subscribeRequestTimeout = val; - return this; - }; - default_1.prototype.getTransactionTimeout = function () { - return this._transactionalRequestTimeout; - }; - default_1.prototype.setTransactionTimeout = function (val) { - this._transactionalRequestTimeout = val; - return this; - }; - default_1.prototype.isSendBeaconEnabled = function () { - return this._useSendBeacon; - }; - default_1.prototype.setSendBeaconConfig = function (val) { - this._useSendBeacon = val; - return this; - }; - default_1.prototype.getVersion = function () { - return '7.6.3'; - }; - default_1.prototype._setRetryConfiguration = function (configuration) { - if (configuration.minimumdelay < 2) { - throw new Error('Minimum delay can not be set less than 2 seconds for retry'); - } - if (configuration.maximumDelay > 150) { - throw new Error('Maximum delay can not be set more than 150 seconds for retry'); - } - if (configuration.maximumDelay && maximumRetry > 6) { - throw new Error('Maximum retry for exponential retry policy can not be more than 6'); - } - else if (configuration.maximumRetry > 10) { - throw new Error('Maximum retry for linear retry policy can not be more than 10'); - } - this.retryConfiguration = configuration; - }; - default_1.prototype._addPnsdkSuffix = function (name, suffix) { - this._PNSDKSuffix[name] = suffix; - }; - default_1.prototype._getPnsdkSuffix = function (separator) { - var _this = this; - return Object.keys(this._PNSDKSuffix).reduce(function (result, key) { return result + separator + _this._PNSDKSuffix[key]; }, ''); - }; - return default_1; - }()); - - var BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; - /** - * Decode a Base64 encoded string. - * - * @param paddedInput Base64 string with padding - * @returns ArrayBuffer with decoded data - */ - function decode$1(paddedInput) { - // Remove up to last two equal signs. - var input = paddedInput.replace(/==?$/, ''); - var outputLength = Math.floor((input.length / 4) * 3); - // Prepare output buffer. - var data = new ArrayBuffer(outputLength); - var view = new Uint8Array(data); - var cursor = 0; - /** - * Returns the next integer representation of a sixtet of bytes from the input - * @returns sixtet of bytes - */ - function nextSixtet() { - var char = input.charAt(cursor++); - var index = BASE64_CHARMAP.indexOf(char); - if (index === -1) { - throw new Error("Illegal character at ".concat(cursor, ": ").concat(input.charAt(cursor - 1))); - } - return index; - } - for (var i = 0; i < outputLength; i += 3) { - // Obtain four sixtets - var sx1 = nextSixtet(); - var sx2 = nextSixtet(); - var sx3 = nextSixtet(); - var sx4 = nextSixtet(); - // Encode them as three octets - var oc1 = ((sx1 & 63) << 2) | (sx2 >> 4); - var oc2 = ((sx2 & 15) << 4) | (sx3 >> 2); - var oc3 = ((sx3 & 3) << 6) | (sx4 >> 0); - view[i] = oc1; - // Skip padding bytes. - if (sx3 != 64) - view[i + 1] = oc2; - if (sx4 != 64) - view[i + 2] = oc3; - } - return data; - } - function encode$1(input) { - var base64 = ''; - var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - var bytes = new Uint8Array(input); - var byteLength = bytes.byteLength; - var byteRemainder = byteLength % 3; - var mainLength = byteLength - byteRemainder; - var a, b, c, d; - var chunk; - // Main loop deals with bytes in chunks of 3 - for (var i = 0; i < mainLength; i = i + 3) { - // Combine the three bytes into a single integer - chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; - // Use bitmasks to extract 6-bit segments from the triplet - a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18 - b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12 - c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6 - d = chunk & 63; // 63 = 2^6 - 1 - // Convert the raw binary segments to the appropriate ASCII encoding - base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]; - } - // Deal with the remaining bytes and padding - if (byteRemainder == 1) { - chunk = bytes[mainLength]; - a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2 - // Set the 4 least significant bits to zero - b = (chunk & 3) << 4; // 3 = 2^2 - 1 - base64 += encodings[a] + encodings[b] + '=='; - } - else if (byteRemainder == 2) { - chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]; - a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10 - b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4 - // Set the 2 least significant bits to zero - c = (chunk & 15) << 2; // 15 = 2^4 - 1 - base64 += encodings[a] + encodings[b] + encodings[c] + '='; - } - return base64; - } - - /*eslint-disable */ - /* - CryptoJS v3.1.2 - code.google.com/p/crypto-js - (c) 2009-2013 by Jeff Mott. All rights reserved. - code.google.com/p/crypto-js/wiki/License - */ - var CryptoJS = CryptoJS || - (function (h, s) { - var f = {}, g = (f.lib = {}), q = function () { }, m = (g.Base = { - extend: function (a) { - q.prototype = this; - var c = new q(); - a && c.mixIn(a); - c.hasOwnProperty('init') || - (c.init = function () { - c.$super.init.apply(this, arguments); - }); - c.init.prototype = c; - c.$super = this; - return c; - }, - create: function () { - var a = this.extend(); - a.init.apply(a, arguments); - return a; - }, - init: function () { }, - mixIn: function (a) { - for (var c in a) - a.hasOwnProperty(c) && (this[c] = a[c]); - a.hasOwnProperty('toString') && (this.toString = a.toString); - }, - clone: function () { - return this.init.prototype.extend(this); - }, - }), r = (g.WordArray = m.extend({ - init: function (a, c) { - a = this.words = a || []; - this.sigBytes = c != s ? c : 4 * a.length; - }, - toString: function (a) { - return (a || k).stringify(this); - }, - concat: function (a) { - var c = this.words, d = a.words, b = this.sigBytes; - a = a.sigBytes; - this.clamp(); - if (b % 4) - for (var e = 0; e < a; e++) - c[(b + e) >>> 2] |= ((d[e >>> 2] >>> (24 - 8 * (e % 4))) & 255) << (24 - 8 * ((b + e) % 4)); - else if (65535 < d.length) - for (e = 0; e < a; e += 4) - c[(b + e) >>> 2] = d[e >>> 2]; - else - c.push.apply(c, d); - this.sigBytes += a; - return this; - }, - clamp: function () { - var a = this.words, c = this.sigBytes; - a[c >>> 2] &= 4294967295 << (32 - 8 * (c % 4)); - a.length = h.ceil(c / 4); - }, - clone: function () { - var a = m.clone.call(this); - a.words = this.words.slice(0); - return a; - }, - random: function (a) { - for (var c = [], d = 0; d < a; d += 4) - c.push((4294967296 * h.random()) | 0); - return new r.init(c, a); - }, - })), l = (f.enc = {}), k = (l.Hex = { - stringify: function (a) { - var c = a.words; - a = a.sigBytes; - for (var d = [], b = 0; b < a; b++) { - var e = (c[b >>> 2] >>> (24 - 8 * (b % 4))) & 255; - d.push((e >>> 4).toString(16)); - d.push((e & 15).toString(16)); - } - return d.join(''); - }, - parse: function (a) { - for (var c = a.length, d = [], b = 0; b < c; b += 2) - d[b >>> 3] |= parseInt(a.substr(b, 2), 16) << (24 - 4 * (b % 8)); - return new r.init(d, c / 2); - }, - }), n = (l.Latin1 = { - stringify: function (a) { - var c = a.words; - a = a.sigBytes; - for (var d = [], b = 0; b < a; b++) - d.push(String.fromCharCode((c[b >>> 2] >>> (24 - 8 * (b % 4))) & 255)); - return d.join(''); - }, - parse: function (a) { - for (var c = a.length, d = [], b = 0; b < c; b++) - d[b >>> 2] |= (a.charCodeAt(b) & 255) << (24 - 8 * (b % 4)); - return new r.init(d, c); - }, - }), j = (l.Utf8 = { - stringify: function (a) { - try { - return decodeURIComponent(escape(n.stringify(a))); - } - catch (c) { - throw Error('Malformed UTF-8 data'); - } - }, - parse: function (a) { - return n.parse(unescape(encodeURIComponent(a))); - }, - }), u = (g.BufferedBlockAlgorithm = m.extend({ - reset: function () { - this._data = new r.init(); - this._nDataBytes = 0; - }, - _append: function (a) { - 'string' == typeof a && (a = j.parse(a)); - this._data.concat(a); - this._nDataBytes += a.sigBytes; - }, - _process: function (a) { - var c = this._data, d = c.words, b = c.sigBytes, e = this.blockSize, f = b / (4 * e), f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0); - a = f * e; - b = h.min(4 * a, b); - if (a) { - for (var g = 0; g < a; g += e) - this._doProcessBlock(d, g); - g = d.splice(0, a); - c.sigBytes -= b; - } - return new r.init(g, b); - }, - clone: function () { - var a = m.clone.call(this); - a._data = this._data.clone(); - return a; - }, - _minBufferSize: 0, - })); - g.Hasher = u.extend({ - cfg: m.extend(), - init: function (a) { - this.cfg = this.cfg.extend(a); - this.reset(); - }, - reset: function () { - u.reset.call(this); - this._doReset(); - }, - update: function (a) { - this._append(a); - this._process(); - return this; - }, - finalize: function (a) { - a && this._append(a); - return this._doFinalize(); - }, - blockSize: 16, - _createHelper: function (a) { - return function (c, d) { - return new a.init(d).finalize(c); - }; - }, - _createHmacHelper: function (a) { - return function (c, d) { - return new t.HMAC.init(a, d).finalize(c); - }; - }, - }); - var t = (f.algo = {}); - return f; - })(Math); - // SHA256 - (function (h) { - for (var s = CryptoJS, f = s.lib, g = f.WordArray, q = f.Hasher, f = s.algo, m = [], r = [], l = function (a) { - return (4294967296 * (a - (a | 0))) | 0; - }, k = 2, n = 0; 64 > n;) { - var j; - a: { - j = k; - for (var u = h.sqrt(j), t = 2; t <= u; t++) - if (!(j % t)) { - j = !1; - break a; - } - j = !0; - } - j && (8 > n && (m[n] = l(h.pow(k, 0.5))), (r[n] = l(h.pow(k, 1 / 3))), n++); - k++; - } - var a = [], f = (f.SHA256 = q.extend({ - _doReset: function () { - this._hash = new g.init(m.slice(0)); - }, - _doProcessBlock: function (c, d) { - for (var b = this._hash.words, e = b[0], f = b[1], g = b[2], j = b[3], h = b[4], m = b[5], n = b[6], q = b[7], p = 0; 64 > p; p++) { - if (16 > p) - a[p] = c[d + p] | 0; - else { - var k = a[p - 15], l = a[p - 2]; - a[p] = - (((k << 25) | (k >>> 7)) ^ ((k << 14) | (k >>> 18)) ^ (k >>> 3)) + - a[p - 7] + - (((l << 15) | (l >>> 17)) ^ ((l << 13) | (l >>> 19)) ^ (l >>> 10)) + - a[p - 16]; - } - k = - q + - (((h << 26) | (h >>> 6)) ^ ((h << 21) | (h >>> 11)) ^ ((h << 7) | (h >>> 25))) + - ((h & m) ^ (~h & n)) + - r[p] + - a[p]; - l = - (((e << 30) | (e >>> 2)) ^ ((e << 19) | (e >>> 13)) ^ ((e << 10) | (e >>> 22))) + - ((e & f) ^ (e & g) ^ (f & g)); - q = n; - n = m; - m = h; - h = (j + k) | 0; - j = g; - g = f; - f = e; - e = (k + l) | 0; - } - b[0] = (b[0] + e) | 0; - b[1] = (b[1] + f) | 0; - b[2] = (b[2] + g) | 0; - b[3] = (b[3] + j) | 0; - b[4] = (b[4] + h) | 0; - b[5] = (b[5] + m) | 0; - b[6] = (b[6] + n) | 0; - b[7] = (b[7] + q) | 0; - }, - _doFinalize: function () { - var a = this._data, d = a.words, b = 8 * this._nDataBytes, e = 8 * a.sigBytes; - d[e >>> 5] |= 128 << (24 - (e % 32)); - d[(((e + 64) >>> 9) << 4) + 14] = h.floor(b / 4294967296); - d[(((e + 64) >>> 9) << 4) + 15] = b; - a.sigBytes = 4 * d.length; - this._process(); - return this._hash; - }, - clone: function () { - var a = q.clone.call(this); - a._hash = this._hash.clone(); - return a; - }, - })); - s.SHA256 = q._createHelper(f); - s.HmacSHA256 = q._createHmacHelper(f); - })(Math); - // HMAC SHA256 - (function () { - var h = CryptoJS, s = h.enc.Utf8; - h.algo.HMAC = h.lib.Base.extend({ - init: function (f, g) { - f = this._hasher = new f.init(); - 'string' == typeof g && (g = s.parse(g)); - var h = f.blockSize, m = 4 * h; - g.sigBytes > m && (g = f.finalize(g)); - g.clamp(); - for (var r = (this._oKey = g.clone()), l = (this._iKey = g.clone()), k = r.words, n = l.words, j = 0; j < h; j++) - (k[j] ^= 1549556828), (n[j] ^= 909522486); - r.sigBytes = l.sigBytes = m; - this.reset(); - }, - reset: function () { - var f = this._hasher; - f.reset(); - f.update(this._iKey); - }, - update: function (f) { - this._hasher.update(f); - return this; - }, - finalize: function (f) { - var g = this._hasher; - f = g.finalize(f); - g.reset(); - return g.finalize(this._oKey.clone().concat(f)); - }, - }); - })(); - // Base64 - (function () { - var u = CryptoJS, p = u.lib.WordArray; - u.enc.Base64 = { - stringify: function (d) { - var l = d.words, p = d.sigBytes, t = this._map; - d.clamp(); - d = []; - for (var r = 0; r < p; r += 3) - for (var w = (((l[r >>> 2] >>> (24 - 8 * (r % 4))) & 255) << 16) | - (((l[(r + 1) >>> 2] >>> (24 - 8 * ((r + 1) % 4))) & 255) << 8) | - ((l[(r + 2) >>> 2] >>> (24 - 8 * ((r + 2) % 4))) & 255), v = 0; 4 > v && r + 0.75 * v < p; v++) - d.push(t.charAt((w >>> (6 * (3 - v))) & 63)); - if ((l = t.charAt(64))) - for (; d.length % 4;) - d.push(l); - return d.join(''); - }, - parse: function (d) { - var l = d.length, s = this._map, t = s.charAt(64); - t && ((t = d.indexOf(t)), -1 != t && (l = t)); - for (var t = [], r = 0, w = 0; w < l; w++) - if (w % 4) { - var v = s.indexOf(d.charAt(w - 1)) << (2 * (w % 4)), b = s.indexOf(d.charAt(w)) >>> (6 - 2 * (w % 4)); - t[r >>> 2] |= (v | b) << (24 - 8 * (r % 4)); - r++; - } - return p.create(t, r); - }, - _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', - }; - })(); - // BlockCipher - (function (u) { - function p(b, n, a, c, e, j, k) { - b = b + ((n & a) | (~n & c)) + e + k; - return ((b << j) | (b >>> (32 - j))) + n; - } - function d(b, n, a, c, e, j, k) { - b = b + ((n & c) | (a & ~c)) + e + k; - return ((b << j) | (b >>> (32 - j))) + n; - } - function l(b, n, a, c, e, j, k) { - b = b + (n ^ a ^ c) + e + k; - return ((b << j) | (b >>> (32 - j))) + n; - } - function s(b, n, a, c, e, j, k) { - b = b + (a ^ (n | ~c)) + e + k; - return ((b << j) | (b >>> (32 - j))) + n; - } - for (var t = CryptoJS, r = t.lib, w = r.WordArray, v = r.Hasher, r = t.algo, b = [], x = 0; 64 > x; x++) - b[x] = (4294967296 * u.abs(u.sin(x + 1))) | 0; - r = r.MD5 = v.extend({ - _doReset: function () { - this._hash = new w.init([1732584193, 4023233417, 2562383102, 271733878]); - }, - _doProcessBlock: function (q, n) { - for (var a = 0; 16 > a; a++) { - var c = n + a, e = q[c]; - q[c] = (((e << 8) | (e >>> 24)) & 16711935) | (((e << 24) | (e >>> 8)) & 4278255360); - } - var a = this._hash.words, c = q[n + 0], e = q[n + 1], j = q[n + 2], k = q[n + 3], z = q[n + 4], r = q[n + 5], t = q[n + 6], w = q[n + 7], v = q[n + 8], A = q[n + 9], B = q[n + 10], C = q[n + 11], u = q[n + 12], D = q[n + 13], E = q[n + 14], x = q[n + 15], f = a[0], m = a[1], g = a[2], h = a[3], f = p(f, m, g, h, c, 7, b[0]), h = p(h, f, m, g, e, 12, b[1]), g = p(g, h, f, m, j, 17, b[2]), m = p(m, g, h, f, k, 22, b[3]), f = p(f, m, g, h, z, 7, b[4]), h = p(h, f, m, g, r, 12, b[5]), g = p(g, h, f, m, t, 17, b[6]), m = p(m, g, h, f, w, 22, b[7]), f = p(f, m, g, h, v, 7, b[8]), h = p(h, f, m, g, A, 12, b[9]), g = p(g, h, f, m, B, 17, b[10]), m = p(m, g, h, f, C, 22, b[11]), f = p(f, m, g, h, u, 7, b[12]), h = p(h, f, m, g, D, 12, b[13]), g = p(g, h, f, m, E, 17, b[14]), m = p(m, g, h, f, x, 22, b[15]), f = d(f, m, g, h, e, 5, b[16]), h = d(h, f, m, g, t, 9, b[17]), g = d(g, h, f, m, C, 14, b[18]), m = d(m, g, h, f, c, 20, b[19]), f = d(f, m, g, h, r, 5, b[20]), h = d(h, f, m, g, B, 9, b[21]), g = d(g, h, f, m, x, 14, b[22]), m = d(m, g, h, f, z, 20, b[23]), f = d(f, m, g, h, A, 5, b[24]), h = d(h, f, m, g, E, 9, b[25]), g = d(g, h, f, m, k, 14, b[26]), m = d(m, g, h, f, v, 20, b[27]), f = d(f, m, g, h, D, 5, b[28]), h = d(h, f, m, g, j, 9, b[29]), g = d(g, h, f, m, w, 14, b[30]), m = d(m, g, h, f, u, 20, b[31]), f = l(f, m, g, h, r, 4, b[32]), h = l(h, f, m, g, v, 11, b[33]), g = l(g, h, f, m, C, 16, b[34]), m = l(m, g, h, f, E, 23, b[35]), f = l(f, m, g, h, e, 4, b[36]), h = l(h, f, m, g, z, 11, b[37]), g = l(g, h, f, m, w, 16, b[38]), m = l(m, g, h, f, B, 23, b[39]), f = l(f, m, g, h, D, 4, b[40]), h = l(h, f, m, g, c, 11, b[41]), g = l(g, h, f, m, k, 16, b[42]), m = l(m, g, h, f, t, 23, b[43]), f = l(f, m, g, h, A, 4, b[44]), h = l(h, f, m, g, u, 11, b[45]), g = l(g, h, f, m, x, 16, b[46]), m = l(m, g, h, f, j, 23, b[47]), f = s(f, m, g, h, c, 6, b[48]), h = s(h, f, m, g, w, 10, b[49]), g = s(g, h, f, m, E, 15, b[50]), m = s(m, g, h, f, r, 21, b[51]), f = s(f, m, g, h, u, 6, b[52]), h = s(h, f, m, g, k, 10, b[53]), g = s(g, h, f, m, B, 15, b[54]), m = s(m, g, h, f, e, 21, b[55]), f = s(f, m, g, h, v, 6, b[56]), h = s(h, f, m, g, x, 10, b[57]), g = s(g, h, f, m, t, 15, b[58]), m = s(m, g, h, f, D, 21, b[59]), f = s(f, m, g, h, z, 6, b[60]), h = s(h, f, m, g, C, 10, b[61]), g = s(g, h, f, m, j, 15, b[62]), m = s(m, g, h, f, A, 21, b[63]); - a[0] = (a[0] + f) | 0; - a[1] = (a[1] + m) | 0; - a[2] = (a[2] + g) | 0; - a[3] = (a[3] + h) | 0; - }, - _doFinalize: function () { - var b = this._data, n = b.words, a = 8 * this._nDataBytes, c = 8 * b.sigBytes; - n[c >>> 5] |= 128 << (24 - (c % 32)); - var e = u.floor(a / 4294967296); - n[(((c + 64) >>> 9) << 4) + 15] = (((e << 8) | (e >>> 24)) & 16711935) | (((e << 24) | (e >>> 8)) & 4278255360); - n[(((c + 64) >>> 9) << 4) + 14] = (((a << 8) | (a >>> 24)) & 16711935) | (((a << 24) | (a >>> 8)) & 4278255360); - b.sigBytes = 4 * (n.length + 1); - this._process(); - b = this._hash; - n = b.words; - for (a = 0; 4 > a; a++) - (c = n[a]), (n[a] = (((c << 8) | (c >>> 24)) & 16711935) | (((c << 24) | (c >>> 8)) & 4278255360)); - return b; - }, - clone: function () { - var b = v.clone.call(this); - b._hash = this._hash.clone(); - return b; - }, - }); - t.MD5 = v._createHelper(r); - t.HmacMD5 = v._createHmacHelper(r); - })(Math); - (function () { - var u = CryptoJS, p = u.lib, d = p.Base, l = p.WordArray, p = u.algo, s = (p.EvpKDF = d.extend({ - cfg: d.extend({ keySize: 4, hasher: p.MD5, iterations: 1 }), - init: function (d) { - this.cfg = this.cfg.extend(d); - }, - compute: function (d, r) { - for (var p = this.cfg, s = p.hasher.create(), b = l.create(), u = b.words, q = p.keySize, p = p.iterations; u.length < q;) { - n && s.update(n); - var n = s.update(d).finalize(r); - s.reset(); - for (var a = 1; a < p; a++) - (n = s.finalize(n)), s.reset(); - b.concat(n); - } - b.sigBytes = 4 * q; - return b; - }, - })); - u.EvpKDF = function (d, l, p) { - return s.create(p).compute(d, l); - }; - })(); - // Cipher - CryptoJS.lib.Cipher || - (function (u) { - var p = CryptoJS, d = p.lib, l = d.Base, s = d.WordArray, t = d.BufferedBlockAlgorithm, r = p.enc.Base64, w = p.algo.EvpKDF, v = (d.Cipher = t.extend({ - cfg: l.extend(), - createEncryptor: function (e, a) { - return this.create(this._ENC_XFORM_MODE, e, a); - }, - createDecryptor: function (e, a) { - return this.create(this._DEC_XFORM_MODE, e, a); - }, - init: function (e, a, b) { - this.cfg = this.cfg.extend(b); - this._xformMode = e; - this._key = a; - this.reset(); - }, - reset: function () { - t.reset.call(this); - this._doReset(); - }, - process: function (e) { - this._append(e); - return this._process(); - }, - finalize: function (e) { - e && this._append(e); - return this._doFinalize(); - }, - keySize: 4, - ivSize: 4, - _ENC_XFORM_MODE: 1, - _DEC_XFORM_MODE: 2, - _createHelper: function (e) { - return { - encrypt: function (b, k, d) { - return ('string' == typeof k ? c : a).encrypt(e, b, k, d); - }, - decrypt: function (b, k, d) { - return ('string' == typeof k ? c : a).decrypt(e, b, k, d); - }, - }; - }, - })); - d.StreamCipher = v.extend({ - _doFinalize: function () { - return this._process(!0); - }, - blockSize: 1, - }); - var b = (p.mode = {}), x = function (e, a, b) { - var c = this._iv; - c ? (this._iv = u) : (c = this._prevBlock); - for (var d = 0; d < b; d++) - e[a + d] ^= c[d]; - }, q = (d.BlockCipherMode = l.extend({ - createEncryptor: function (e, a) { - return this.Encryptor.create(e, a); - }, - createDecryptor: function (e, a) { - return this.Decryptor.create(e, a); - }, - init: function (e, a) { - this._cipher = e; - this._iv = a; - }, - })).extend(); - q.Encryptor = q.extend({ - processBlock: function (e, a) { - var b = this._cipher, c = b.blockSize; - x.call(this, e, a, c); - b.encryptBlock(e, a); - this._prevBlock = e.slice(a, a + c); - }, - }); - q.Decryptor = q.extend({ - processBlock: function (e, a) { - var b = this._cipher, c = b.blockSize, d = e.slice(a, a + c); - b.decryptBlock(e, a); - x.call(this, e, a, c); - this._prevBlock = d; - }, - }); - b = b.CBC = q; - q = (p.pad = {}).Pkcs7 = { - pad: function (a, b) { - for (var c = 4 * b, c = c - (a.sigBytes % c), d = (c << 24) | (c << 16) | (c << 8) | c, l = [], n = 0; n < c; n += 4) - l.push(d); - c = s.create(l, c); - a.concat(c); - }, - unpad: function (a) { - a.sigBytes -= a.words[(a.sigBytes - 1) >>> 2] & 255; - }, - }; - d.BlockCipher = v.extend({ - cfg: v.cfg.extend({ mode: b, padding: q }), - reset: function () { - v.reset.call(this); - var a = this.cfg, b = a.iv, a = a.mode; - if (this._xformMode == this._ENC_XFORM_MODE) - var c = a.createEncryptor; - else - (c = a.createDecryptor), (this._minBufferSize = 1); - this._mode = c.call(a, this, b && b.words); - }, - _doProcessBlock: function (a, b) { - this._mode.processBlock(a, b); - }, - _doFinalize: function () { - var a = this.cfg.padding; - if (this._xformMode == this._ENC_XFORM_MODE) { - a.pad(this._data, this.blockSize); - var b = this._process(!0); - } - else - (b = this._process(!0)), a.unpad(b); - return b; - }, - blockSize: 4, - }); - var n = (d.CipherParams = l.extend({ - init: function (a) { - this.mixIn(a); - }, - toString: function (a) { - return (a || this.formatter).stringify(this); - }, - })), b = ((p.format = {}).OpenSSL = { - stringify: function (a) { - var b = a.ciphertext; - a = a.salt; - return (a ? s.create([1398893684, 1701076831]).concat(a).concat(b) : b).toString(r); - }, - parse: function (a) { - a = r.parse(a); - var b = a.words; - if (1398893684 == b[0] && 1701076831 == b[1]) { - var c = s.create(b.slice(2, 4)); - b.splice(0, 4); - a.sigBytes -= 16; - } - return n.create({ ciphertext: a, salt: c }); - }, - }), a = (d.SerializableCipher = l.extend({ - cfg: l.extend({ format: b }), - encrypt: function (a, b, c, d) { - d = this.cfg.extend(d); - var l = a.createEncryptor(c, d); - b = l.finalize(b); - l = l.cfg; - return n.create({ - ciphertext: b, - key: c, - iv: l.iv, - algorithm: a, - mode: l.mode, - padding: l.padding, - blockSize: a.blockSize, - formatter: d.format, - }); - }, - decrypt: function (a, b, c, d) { - d = this.cfg.extend(d); - b = this._parse(b, d.format); - return a.createDecryptor(c, d).finalize(b.ciphertext); - }, - _parse: function (a, b) { - return 'string' == typeof a ? b.parse(a, this) : a; - }, - })), p = ((p.kdf = {}).OpenSSL = { - execute: function (a, b, c, d) { - d || (d = s.random(8)); - a = w.create({ keySize: b + c }).compute(a, d); - c = s.create(a.words.slice(b), 4 * c); - a.sigBytes = 4 * b; - return n.create({ key: a, iv: c, salt: d }); - }, - }), c = (d.PasswordBasedCipher = a.extend({ - cfg: a.cfg.extend({ kdf: p }), - encrypt: function (b, c, d, l) { - l = this.cfg.extend(l); - d = l.kdf.execute(d, b.keySize, b.ivSize); - l.iv = d.iv; - b = a.encrypt.call(this, b, c, d.key, l); - b.mixIn(d); - return b; - }, - decrypt: function (b, c, d, l) { - l = this.cfg.extend(l); - c = this._parse(c, l.format); - d = l.kdf.execute(d, b.keySize, b.ivSize, c.salt); - l.iv = d.iv; - return a.decrypt.call(this, b, c, d.key, l); - }, - })); - })(); - // AES - (function () { - for (var u = CryptoJS, p = u.lib.BlockCipher, d = u.algo, l = [], s = [], t = [], r = [], w = [], v = [], b = [], x = [], q = [], n = [], a = [], c = 0; 256 > c; c++) - a[c] = 128 > c ? c << 1 : (c << 1) ^ 283; - for (var e = 0, j = 0, c = 0; 256 > c; c++) { - var k = j ^ (j << 1) ^ (j << 2) ^ (j << 3) ^ (j << 4), k = (k >>> 8) ^ (k & 255) ^ 99; - l[e] = k; - s[k] = e; - var z = a[e], F = a[z], G = a[F], y = (257 * a[k]) ^ (16843008 * k); - t[e] = (y << 24) | (y >>> 8); - r[e] = (y << 16) | (y >>> 16); - w[e] = (y << 8) | (y >>> 24); - v[e] = y; - y = (16843009 * G) ^ (65537 * F) ^ (257 * z) ^ (16843008 * e); - b[k] = (y << 24) | (y >>> 8); - x[k] = (y << 16) | (y >>> 16); - q[k] = (y << 8) | (y >>> 24); - n[k] = y; - e ? ((e = z ^ a[a[a[G ^ z]]]), (j ^= a[a[j]])) : (e = j = 1); - } - var H = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54], d = (d.AES = p.extend({ - _doReset: function () { - for (var a = this._key, c = a.words, d = a.sigBytes / 4, a = 4 * ((this._nRounds = d + 6) + 1), e = (this._keySchedule = []), j = 0; j < a; j++) - if (j < d) - e[j] = c[j]; - else { - var k = e[j - 1]; - j % d - ? 6 < d && - 4 == j % d && - (k = (l[k >>> 24] << 24) | (l[(k >>> 16) & 255] << 16) | (l[(k >>> 8) & 255] << 8) | l[k & 255]) - : ((k = (k << 8) | (k >>> 24)), - (k = (l[k >>> 24] << 24) | (l[(k >>> 16) & 255] << 16) | (l[(k >>> 8) & 255] << 8) | l[k & 255]), - (k ^= H[(j / d) | 0] << 24)); - e[j] = e[j - d] ^ k; - } - c = this._invKeySchedule = []; - for (d = 0; d < a; d++) - (j = a - d), - (k = d % 4 ? e[j] : e[j - 4]), - (c[d] = - 4 > d || 4 >= j ? k : b[l[k >>> 24]] ^ x[l[(k >>> 16) & 255]] ^ q[l[(k >>> 8) & 255]] ^ n[l[k & 255]]); - }, - encryptBlock: function (a, b) { - this._doCryptBlock(a, b, this._keySchedule, t, r, w, v, l); - }, - decryptBlock: function (a, c) { - var d = a[c + 1]; - a[c + 1] = a[c + 3]; - a[c + 3] = d; - this._doCryptBlock(a, c, this._invKeySchedule, b, x, q, n, s); - d = a[c + 1]; - a[c + 1] = a[c + 3]; - a[c + 3] = d; - }, - _doCryptBlock: function (a, b, c, d, e, j, l, f) { - for (var m = this._nRounds, g = a[b] ^ c[0], h = a[b + 1] ^ c[1], k = a[b + 2] ^ c[2], n = a[b + 3] ^ c[3], p = 4, r = 1; r < m; r++) - var q = d[g >>> 24] ^ e[(h >>> 16) & 255] ^ j[(k >>> 8) & 255] ^ l[n & 255] ^ c[p++], s = d[h >>> 24] ^ e[(k >>> 16) & 255] ^ j[(n >>> 8) & 255] ^ l[g & 255] ^ c[p++], t = d[k >>> 24] ^ e[(n >>> 16) & 255] ^ j[(g >>> 8) & 255] ^ l[h & 255] ^ c[p++], n = d[n >>> 24] ^ e[(g >>> 16) & 255] ^ j[(h >>> 8) & 255] ^ l[k & 255] ^ c[p++], g = q, h = s, k = t; - q = ((f[g >>> 24] << 24) | (f[(h >>> 16) & 255] << 16) | (f[(k >>> 8) & 255] << 8) | f[n & 255]) ^ c[p++]; - s = ((f[h >>> 24] << 24) | (f[(k >>> 16) & 255] << 16) | (f[(n >>> 8) & 255] << 8) | f[g & 255]) ^ c[p++]; - t = ((f[k >>> 24] << 24) | (f[(n >>> 16) & 255] << 16) | (f[(g >>> 8) & 255] << 8) | f[h & 255]) ^ c[p++]; - n = ((f[n >>> 24] << 24) | (f[(g >>> 16) & 255] << 16) | (f[(h >>> 8) & 255] << 8) | f[k & 255]) ^ c[p++]; - a[b] = q; - a[b + 1] = s; - a[b + 2] = t; - a[b + 3] = n; - }, - keySize: 8, - })); - u.AES = p._createHelper(d); - })(); - // Mode ECB - CryptoJS.mode.ECB = (function () { - var ECB = CryptoJS.lib.BlockCipherMode.extend(); - ECB.Encryptor = ECB.extend({ - processBlock: function (words, offset) { - this._cipher.encryptBlock(words, offset); - }, - }); - ECB.Decryptor = ECB.extend({ - processBlock: function (words, offset) { - this._cipher.decryptBlock(words, offset); - }, - }); - return ECB; - })(); - var hmacSha256 = CryptoJS; - - 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 hmacSha256.lib.WordArray.create(wa, b.length); - } - var default_1$a = /** @class */ (function () { - function default_1(_a) { - var config = _a.config; - 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', - }; - } - default_1.prototype.HMACSHA256 = function (data) { - var hash = hmacSha256.HmacSHA256(data, this._config.secretKey); - return hash.toString(hmacSha256.enc.Base64); - }; - default_1.prototype.SHA256 = function (s) { - return hmacSha256.SHA256(s).toString(hmacSha256.enc.Hex); - }; - default_1.prototype._parseOptions = function (incomingOptions) { - // Defaults - 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; - // Validation - 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; - }; - default_1.prototype._decodeKey = function (key, options) { - if (options.keyEncoding === 'base64') { - return hmacSha256.enc.Base64.parse(key); - } - if (options.keyEncoding === 'hex') { - return hmacSha256.enc.Hex.parse(key); - } - return key; - }; - default_1.prototype._getPaddedKey = function (key, options) { - key = this._decodeKey(key, options); - if (options.encryptKey) { - return hmacSha256.enc.Utf8.parse(this.SHA256(key).slice(0, 32)); - } - return key; - }; - default_1.prototype._getMode = function (options) { - if (options.mode === 'ecb') { - return hmacSha256.mode.ECB; - } - return hmacSha256.mode.CBC; - }; - default_1.prototype._getIV = function (options) { - return options.mode === 'cbc' ? hmacSha256.enc.Utf8.parse(this._iv) : null; - }; - default_1.prototype._getRandomIV = function () { - return hmacSha256.lib.WordArray.random(16); - }; - default_1.prototype.encrypt = function (data, customCipherKey, options) { - if (this._config.customEncrypt) { - return this._config.customEncrypt(data); - } - return this.pnEncrypt(data, customCipherKey, options); - }; - default_1.prototype.decrypt = function (data, customCipherKey, options) { - if (this._config.customDecrypt) { - return this._config.customDecrypt(data); - } - return this.pnDecrypt(data, customCipherKey, options); - }; - default_1.prototype.pnEncrypt = function (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 = hmacSha256.AES.encrypt(data, cipherKey, { iv: waIv, mode: mode }).ciphertext; - return waIv.clone().concat(waPayload.clone()).toString(hmacSha256.enc.Base64); - } - var iv = this._getIV(options); - var encryptedHexArray = hmacSha256.AES.encrypt(data, cipherKey, { iv: iv, mode: mode }).ciphertext; - var base64Encrypted = encryptedHexArray.toString(hmacSha256.enc.Base64); - return base64Encrypted || data; - }; - default_1.prototype.pnDecrypt = function (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 = new Uint8ClampedArray(decode$1(data)); - var iv = bufferToWordArray(ciphertext.slice(0, 16)); - var payload = bufferToWordArray(ciphertext.slice(16)); - try { - var plainJSON = hmacSha256.AES.decrypt({ ciphertext: payload }, cipherKey, { iv: iv, mode: mode }).toString(hmacSha256.enc.Utf8); - var plaintext = JSON.parse(plainJSON); - return plaintext; - } - catch (e) { - return null; - } - } - else { - var iv = this._getIV(options); - try { - var ciphertext = hmacSha256.enc.Base64.parse(data); - var plainJSON = hmacSha256.AES.decrypt({ ciphertext: ciphertext }, cipherKey, { iv: iv, mode: mode }).toString(hmacSha256.enc.Utf8); - var plaintext = JSON.parse(plainJSON); - return plaintext; - } - catch (e) { - return null; - } - } - }; - return default_1; - }()); - - var default_1$9 = /** @class */ (function () { - function default_1(_a) { - var timeEndpoint = _a.timeEndpoint; - this._timeEndpoint = timeEndpoint; - } - default_1.prototype.onReconnection = function (reconnectionCallback) { - this._reconnectionCallback = reconnectionCallback; - }; - default_1.prototype.startPolling = function () { - this._timeTimer = setInterval(this._performTimeLoop.bind(this), 3000); - }; - default_1.prototype.stopPolling = function () { - clearInterval(this._timeTimer); - }; - default_1.prototype._performTimeLoop = function () { - var _this = this; - this._timeEndpoint(function (status) { - if (!status.error) { - clearInterval(_this._timeTimer); - _this._reconnectionCallback(); - } - }); - }; - return default_1; - }()); - - /* */ - var hashCode = function (payload) { - var hash = 0; - if (payload.length === 0) - return hash; - for (var i = 0; i < payload.length; i += 1) { - var character = payload.charCodeAt(i); - hash = (hash << 5) - hash + character; // eslint-disable-line - hash = hash & hash; // eslint-disable-line - } - return hash; - }; - var default_1$8 = /** @class */ (function () { - function default_1(_a) { - var config = _a.config; - this.hashHistory = []; - this._config = config; - } - default_1.prototype.getKey = function (message) { - var hashedPayload = hashCode(JSON.stringify(message.payload)).toString(); - var timetoken = message.publishMetaData.publishTimetoken; - return "".concat(timetoken, "-").concat(hashedPayload); - }; - default_1.prototype.isDuplicate = function (message) { - return this.hashHistory.includes(this.getKey(message)); - }; - default_1.prototype.addEntry = function (message) { - if (this.hashHistory.length >= this._config.maximumCacheSize) { - this.hashHistory.shift(); - } - this.hashHistory.push(this.getKey(message)); - }; - default_1.prototype.clearHistory = function () { - this.hashHistory = []; - }; - return default_1; - }()); - - /* */ - var categories = { - // SDK will announce when the network appears to be connected again. - PNNetworkUpCategory: 'PNNetworkUpCategory', - // SDK will announce when the network appears to down. - PNNetworkDownCategory: 'PNNetworkDownCategory', - // call failed when network was unable to complete the call. - PNNetworkIssuesCategory: 'PNNetworkIssuesCategory', - // network call timed out - PNTimeoutCategory: 'PNTimeoutCategory', - // server responded with bad response - PNBadRequestCategory: 'PNBadRequestCategory', - // server responded with access denied - PNAccessDeniedCategory: 'PNAccessDeniedCategory', - // something strange happened; please check the logs. - PNUnknownCategory: 'PNUnknownCategory', - // on reconnection - PNReconnectedCategory: 'PNReconnectedCategory', - PNConnectedCategory: 'PNConnectedCategory', - PNRequestMessageCountExceededCategory: 'PNRequestMessageCountExceededCategory', - PNDisconnectedCategory: 'PNDisconnectedCategory', - PNConnectionErrorCategory: 'PNConnectionErrorCategory', - PNDisconnectedUnexpectedlyCategory: 'PNDisconnectedUnexpectedlyCategory', - }; - - var default_1$7 = /** @class */ (function () { - function default_1(_a) { - var subscribeEndpoint = _a.subscribeEndpoint, leaveEndpoint = _a.leaveEndpoint, heartbeatEndpoint = _a.heartbeatEndpoint, setStateEndpoint = _a.setStateEndpoint, timeEndpoint = _a.timeEndpoint, getFileUrl = _a.getFileUrl, config = _a.config, crypto = _a.crypto, listenerManager = _a.listenerManager, cryptoModule = _a.cryptoModule, eventEmitter = _a.eventEmitter; - this._listenerManager = listenerManager; - this._config = config; - this._leaveEndpoint = leaveEndpoint; - this._heartbeatEndpoint = heartbeatEndpoint; - this._setStateEndpoint = setStateEndpoint; - this._subscribeEndpoint = subscribeEndpoint; - this._getFileUrl = getFileUrl; - this._crypto = crypto; - this._cryptoModule = cryptoModule; - this._channels = {}; - this._presenceChannels = {}; - this._heartbeatChannels = {}; - this._heartbeatChannelGroups = {}; - this._channelGroups = {}; - this._presenceChannelGroups = {}; - this._pendingChannelSubscriptions = []; - this._pendingChannelGroupSubscriptions = []; - this._currentTimetoken = 0; - this._lastTimetoken = 0; - this._storedTimetoken = null; - this._subscriptionStatusAnnounced = false; - this._isOnline = true; - this._reconnectionManager = new default_1$9({ timeEndpoint: timeEndpoint }); - this._dedupingManager = new default_1$8({ config: config }); - if (this._cryptoModule) - this._decoder = new TextDecoder(); - this._eventEmitter = eventEmitter; - } - default_1.prototype.adaptStateChange = function (args, callback) { - var _this = this; - var state = args.state, _a = args.channels, channels = _a === void 0 ? [] : _a, _b = args.channelGroups, channelGroups = _b === void 0 ? [] : _b, _c = args.withHeartbeat, withHeartbeat = _c === void 0 ? false : _c; - channels.forEach(function (channel) { - if (channel in _this._channels) - _this._channels[channel].state = state; - }); - channelGroups.forEach(function (channelGroup) { - if (channelGroup in _this._channelGroups) { - _this._channelGroups[channelGroup].state = state; - } - }); - if (withHeartbeat) { - var presenceState_1 = {}; - channels.forEach(function (channel) { return (presenceState_1[channel] = state); }); - channelGroups.forEach(function (group) { return (presenceState_1[group] = state); }); - return this._heartbeatEndpoint({ channels: channels, channelGroups: channelGroups, state: presenceState_1 }, callback); - } - return this._setStateEndpoint({ state: state, channels: channels, channelGroups: channelGroups }, callback); - }; - default_1.prototype.adaptPresenceChange = function (args) { - var _this = this; - var connected = args.connected, _a = args.channels, channels = _a === void 0 ? [] : _a, _b = args.channelGroups, channelGroups = _b === void 0 ? [] : _b; - if (connected) { - channels.forEach(function (channel) { - _this._heartbeatChannels[channel] = { state: {} }; - }); - channelGroups.forEach(function (channelGroup) { - _this._heartbeatChannelGroups[channelGroup] = { state: {} }; - }); - } - else { - channels.forEach(function (channel) { - if (channel in _this._heartbeatChannels) { - delete _this._heartbeatChannels[channel]; - } - }); - channelGroups.forEach(function (channelGroup) { - if (channelGroup in _this._heartbeatChannelGroups) { - delete _this._heartbeatChannelGroups[channelGroup]; - } - }); - if (this._config.suppressLeaveEvents === false) { - this._leaveEndpoint({ channels: channels, channelGroups: channelGroups }, function (status) { - _this._listenerManager.announceStatus(status); - }); - } - } - this.reconnect(); - }; - default_1.prototype.adaptSubscribeChange = function (args) { - var _this = this; - var timetoken = args.timetoken, _a = args.channels, channels = _a === void 0 ? [] : _a, _b = args.channelGroups, channelGroups = _b === void 0 ? [] : _b, _c = args.withPresence, withPresence = _c === void 0 ? false : _c, _d = args.withHeartbeats, withHeartbeats = _d === void 0 ? false : _d; - if (!this._config.subscribeKey || this._config.subscribeKey === '') { - // eslint-disable-next-line - if (console && console.log) { - console.log('subscribe key missing; aborting subscribe'); //eslint-disable-line - } - return; - } - if (timetoken) { - this._lastTimetoken = this._currentTimetoken; - this._currentTimetoken = timetoken; - } - // reset the current timetoken to get a connect event. - // $FlowFixMe - if (this._currentTimetoken !== '0' && this._currentTimetoken !== 0) { - this._storedTimetoken = this._currentTimetoken; - this._currentTimetoken = 0; - } - channels.forEach(function (channel) { - _this._channels[channel] = { state: {} }; - if (withPresence) - _this._presenceChannels[channel] = {}; - if (withHeartbeats || _this._config.getHeartbeatInterval()) - _this._heartbeatChannels[channel] = {}; - _this._pendingChannelSubscriptions.push(channel); - }); - channelGroups.forEach(function (channelGroup) { - _this._channelGroups[channelGroup] = { state: {} }; - if (withPresence) - _this._presenceChannelGroups[channelGroup] = {}; - if (withHeartbeats || _this._config.getHeartbeatInterval()) - _this._heartbeatChannelGroups[channelGroup] = {}; - _this._pendingChannelGroupSubscriptions.push(channelGroup); - }); - this._subscriptionStatusAnnounced = false; - this.reconnect(); - }; - default_1.prototype.adaptUnsubscribeChange = function (args, isOffline) { - var _this = this; - var _a = args.channels, channels = _a === void 0 ? [] : _a, _b = args.channelGroups, channelGroups = _b === void 0 ? [] : _b; - // keep track of which channels and channel groups - // we are going to unsubscribe from. - var actualChannels = []; - var actualChannelGroups = []; - // - channels.forEach(function (channel) { - if (channel in _this._channels) { - delete _this._channels[channel]; - actualChannels.push(channel); - if (channel in _this._heartbeatChannels) { - delete _this._heartbeatChannels[channel]; - } - } - if (channel in _this._presenceChannels) { - delete _this._presenceChannels[channel]; - actualChannels.push(channel); - } - }); - channelGroups.forEach(function (channelGroup) { - if (channelGroup in _this._channelGroups) { - delete _this._channelGroups[channelGroup]; - actualChannelGroups.push(channelGroup); - if (channelGroup in _this._heartbeatChannelGroups) { - delete _this._heartbeatChannelGroups[channelGroup]; - } - } - if (channelGroup in _this._presenceChannelGroups) { - delete _this._presenceChannelGroups[channelGroup]; - actualChannelGroups.push(channelGroup); - } - }); - // no-op if there are no channels and cg's to unsubscribe from. - if (actualChannels.length === 0 && actualChannelGroups.length === 0) { - return; - } - if (this._config.suppressLeaveEvents === false && !isOffline) { - this._leaveEndpoint({ channels: actualChannels, channelGroups: actualChannelGroups }, function (status) { - status.affectedChannels = actualChannels; - status.affectedChannelGroups = actualChannelGroups; - status.currentTimetoken = _this._currentTimetoken; - status.lastTimetoken = _this._lastTimetoken; - _this._listenerManager.announceStatus(status); - }); - } - // if we have nothing to subscribe to, reset the timetoken. - if (Object.keys(this._channels).length === 0 && - Object.keys(this._presenceChannels).length === 0 && - Object.keys(this._channelGroups).length === 0 && - Object.keys(this._presenceChannelGroups).length === 0) { - this._lastTimetoken = 0; - this._currentTimetoken = 0; - this._storedTimetoken = null; - this._region = null; - this._reconnectionManager.stopPolling(); - } - this.reconnect(); - }; - default_1.prototype.unsubscribeAll = function (isOffline) { - this.adaptUnsubscribeChange({ - channels: this.getSubscribedChannels(), - channelGroups: this.getSubscribedChannelGroups(), - }, isOffline); - }; - default_1.prototype.getHeartbeatChannels = function () { - return Object.keys(this._heartbeatChannels); - }; - default_1.prototype.getHeartbeatChannelGroups = function () { - return Object.keys(this._heartbeatChannelGroups); - }; - default_1.prototype.getSubscribedChannels = function () { - return Object.keys(this._channels); - }; - default_1.prototype.getSubscribedChannelGroups = function () { - return Object.keys(this._channelGroups); - }; - default_1.prototype.reconnect = function () { - this._startSubscribeLoop(); - this._registerHeartbeatTimer(); - }; - default_1.prototype.disconnect = function () { - this._stopSubscribeLoop(); - this._stopHeartbeatTimer(); - this._reconnectionManager.stopPolling(); - }; - default_1.prototype._registerHeartbeatTimer = function () { - this._stopHeartbeatTimer(); - // if the interval is 0 or undefined, do not queue up heartbeating - if (this._config.getHeartbeatInterval() === 0 || this._config.getHeartbeatInterval() === undefined) { - return; - } - this._performHeartbeatLoop(); - // $FlowFixMe - this._heartbeatTimer = setInterval(this._performHeartbeatLoop.bind(this), this._config.getHeartbeatInterval() * 1000); - }; - default_1.prototype._stopHeartbeatTimer = function () { - if (this._heartbeatTimer) { - // $FlowFixMe - clearInterval(this._heartbeatTimer); - this._heartbeatTimer = null; - } - }; - default_1.prototype._performHeartbeatLoop = function () { - var _this = this; - var heartbeatChannels = this.getHeartbeatChannels(); - var heartbeatChannelGroups = this.getHeartbeatChannelGroups(); - var presenceState = {}; - if (heartbeatChannels.length === 0 && heartbeatChannelGroups.length === 0) { - return; - } - this.getSubscribedChannels().forEach(function (channel) { - var channelState = _this._channels[channel].state; - if (Object.keys(channelState).length) { - presenceState[channel] = channelState; - } - }); - this.getSubscribedChannelGroups().forEach(function (channelGroup) { - var channelGroupState = _this._channelGroups[channelGroup].state; - if (Object.keys(channelGroupState).length) { - presenceState[channelGroup] = channelGroupState; - } - }); - var onHeartbeat = function (status) { - if (status.error && _this._config.announceFailedHeartbeats) { - _this._listenerManager.announceStatus(status); - } - if (status.error && _this._config.autoNetworkDetection && _this._isOnline) { - _this._isOnline = false; - _this.disconnect(); - _this._listenerManager.announceNetworkDown(); - _this.reconnect(); - } - if (!status.error && _this._config.announceSuccessfulHeartbeats) { - _this._listenerManager.announceStatus(status); - } - }; - this._heartbeatEndpoint({ - channels: heartbeatChannels, - channelGroups: heartbeatChannelGroups, - state: presenceState, - }, onHeartbeat.bind(this)); - }; - default_1.prototype._startSubscribeLoop = function () { - var _this = this; - this._stopSubscribeLoop(); - var presenceState = {}; - var channels = []; - var channelGroups = []; - Object.keys(this._channels).forEach(function (channel) { - var channelState = _this._channels[channel].state; - if (Object.keys(channelState).length) { - presenceState[channel] = channelState; - } - channels.push(channel); - }); - Object.keys(this._presenceChannels).forEach(function (channel) { - channels.push("".concat(channel, "-pnpres")); - }); - Object.keys(this._channelGroups).forEach(function (channelGroup) { - var channelGroupState = _this._channelGroups[channelGroup].state; - if (Object.keys(channelGroupState).length) { - presenceState[channelGroup] = channelGroupState; - } - channelGroups.push(channelGroup); - }); - Object.keys(this._presenceChannelGroups).forEach(function (channelGroup) { - channelGroups.push("".concat(channelGroup, "-pnpres")); - }); - if (channels.length === 0 && channelGroups.length === 0) { - return; - } - var subscribeArgs = { - channels: channels, - channelGroups: channelGroups, - state: presenceState, - timetoken: this._currentTimetoken, - filterExpression: this._config.filterExpression, - region: this._region, - }; - this._subscribeCall = this._subscribeEndpoint(subscribeArgs, this._processSubscribeResponse.bind(this)); - }; - default_1.prototype._processSubscribeResponse = function (status, payload) { - var _this = this; - if (status.error) { - // if error comes from request abort, ignore - if (status.errorData && status.errorData.message === 'Aborted') { - return; - } - // if we timeout from server, restart the loop. - if (status.category === categories.PNTimeoutCategory) { - this._startSubscribeLoop(); - } - else if (status.category === categories.PNNetworkIssuesCategory) { - // we lost internet connection, alert the reconnection manager and terminate all loops - this.disconnect(); - if (status.error && this._config.autoNetworkDetection && this._isOnline) { - this._isOnline = false; - this._listenerManager.announceNetworkDown(); - } - this._reconnectionManager.onReconnection(function () { - if (_this._config.autoNetworkDetection && !_this._isOnline) { - _this._isOnline = true; - _this._listenerManager.announceNetworkUp(); - } - _this.reconnect(); - _this._subscriptionStatusAnnounced = true; - var reconnectedAnnounce = { - category: categories.PNReconnectedCategory, - operation: status.operation, - lastTimetoken: _this._lastTimetoken, - currentTimetoken: _this._currentTimetoken, - }; - _this._listenerManager.announceStatus(reconnectedAnnounce); - }); - this._reconnectionManager.startPolling(); - this._listenerManager.announceStatus(status); - } - else if (status.category === categories.PNBadRequestCategory) { - this._stopHeartbeatTimer(); - this._listenerManager.announceStatus(status); - } - else { - this._listenerManager.announceStatus(status); - } - return; - } - if (this._storedTimetoken) { - this._currentTimetoken = this._storedTimetoken; - this._storedTimetoken = null; - } - else { - this._lastTimetoken = this._currentTimetoken; - this._currentTimetoken = payload.metadata.timetoken; - } - if (!this._subscriptionStatusAnnounced) { - var connectedAnnounce = {}; - connectedAnnounce.category = categories.PNConnectedCategory; - connectedAnnounce.operation = status.operation; - connectedAnnounce.affectedChannels = this._pendingChannelSubscriptions; - connectedAnnounce.subscribedChannels = this.getSubscribedChannels(); - connectedAnnounce.affectedChannelGroups = this._pendingChannelGroupSubscriptions; - connectedAnnounce.lastTimetoken = this._lastTimetoken; - connectedAnnounce.currentTimetoken = this._currentTimetoken; - this._subscriptionStatusAnnounced = true; - this._listenerManager.announceStatus(connectedAnnounce); - // clear the pending connections list - this._pendingChannelSubscriptions = []; - this._pendingChannelGroupSubscriptions = []; - } - var messages = payload.messages || []; - var _a = this._config, requestMessageCountThreshold = _a.requestMessageCountThreshold, dedupeOnSubscribe = _a.dedupeOnSubscribe; - if (requestMessageCountThreshold && messages.length >= requestMessageCountThreshold) { - var countAnnouncement = {}; - countAnnouncement.category = categories.PNRequestMessageCountExceededCategory; - countAnnouncement.operation = status.operation; - this._listenerManager.announceStatus(countAnnouncement); - } - messages.forEach(function (message) { - message.channel; - message.subscriptionMatch; - if (dedupeOnSubscribe) { - if (_this._dedupingManager.isDuplicate(message)) { - return; - } - _this._dedupingManager.addEntry(message); - } - _this._eventEmitter.emitEvent(message); - }); - this._region = payload.metadata.region; - this._startSubscribeLoop(); - }; - default_1.prototype._stopSubscribeLoop = function () { - if (this._subscribeCall) { - if (typeof this._subscribeCall.abort === 'function') { - this._subscribeCall.abort(); - } - this._subscribeCall = null; - } - }; - default_1.prototype._renameEvent = function (e) { - return e === 'set' ? 'updated' : 'removed'; - }; - default_1.prototype._renameChannelField = function (announce) { - var channel = announce.channel, eventData = __rest(announce, ["channel"]); - eventData.spaceId = channel; - return eventData; - }; - return default_1; - }()); - - /* */ - var OPERATIONS = { - PNTimeOperation: 'PNTimeOperation', - PNHistoryOperation: 'PNHistoryOperation', - PNDeleteMessagesOperation: 'PNDeleteMessagesOperation', - PNFetchMessagesOperation: 'PNFetchMessagesOperation', - PNMessageCounts: 'PNMessageCountsOperation', - // pubsub - PNSubscribeOperation: 'PNSubscribeOperation', - PNUnsubscribeOperation: 'PNUnsubscribeOperation', - PNPublishOperation: 'PNPublishOperation', - PNSignalOperation: 'PNSignalOperation', - // Actions API - PNAddMessageActionOperation: 'PNAddActionOperation', - PNRemoveMessageActionOperation: 'PNRemoveMessageActionOperation', - PNGetMessageActionsOperation: 'PNGetMessageActionsOperation', - // Objects API - 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', - // File Upload API v1 - PNListFilesOperation: 'PNListFilesOperation', - PNGenerateUploadUrlOperation: 'PNGenerateUploadUrlOperation', - PNPublishFileOperation: 'PNPublishFileOperation', - PNGetFileUrlOperation: 'PNGetFileUrlOperation', - PNDownloadFileOperation: 'PNDownloadFileOperation', - // Objects API v2 - // UUID - PNGetAllUUIDMetadataOperation: 'PNGetAllUUIDMetadataOperation', - PNGetUUIDMetadataOperation: 'PNGetUUIDMetadataOperation', - PNSetUUIDMetadataOperation: 'PNSetUUIDMetadataOperation', - PNRemoveUUIDMetadataOperation: 'PNRemoveUUIDMetadataOperation', - // channel - PNGetAllChannelMetadataOperation: 'PNGetAllChannelMetadataOperation', - PNGetChannelMetadataOperation: 'PNGetChannelMetadataOperation', - PNSetChannelMetadataOperation: 'PNSetChannelMetadataOperation', - PNRemoveChannelMetadataOperation: 'PNRemoveChannelMetadataOperation', - // member - // PNGetMembersOperation: 'PNGetMembersOperation', - PNSetMembersOperation: 'PNSetMembersOperation', - // PNGetMembershipsOperation: 'PNGetMembersOperation', - PNSetMembershipsOperation: 'PNSetMembershipsOperation', - // push - PNPushNotificationEnabledChannelsOperation: 'PNPushNotificationEnabledChannelsOperation', - PNRemoveAllPushNotificationsOperation: 'PNRemoveAllPushNotificationsOperation', - // - // presence - PNWhereNowOperation: 'PNWhereNowOperation', - PNSetStateOperation: 'PNSetStateOperation', - PNHereNowOperation: 'PNHereNowOperation', - PNGetStateOperation: 'PNGetStateOperation', - PNHeartbeatOperation: 'PNHeartbeatOperation', - // - // channel group - PNChannelGroupsOperation: 'PNChannelGroupsOperation', - PNRemoveGroupOperation: 'PNRemoveGroupOperation', - PNChannelsForGroupOperation: 'PNChannelsForGroupOperation', - PNAddChannelsToGroupOperation: 'PNAddChannelsToGroupOperation', - PNRemoveChannelsFromGroupOperation: 'PNRemoveChannelsFromGroupOperation', - // - // PAM - PNAccessManagerGrant: 'PNAccessManagerGrant', - PNAccessManagerGrantToken: 'PNAccessManagerGrantToken', - PNAccessManagerAudit: 'PNAccessManagerAudit', - PNAccessManagerRevokeToken: 'PNAccessManagerRevokeToken', - // - // subscription utilities - PNHandshakeOperation: 'PNHandshakeOperation', - PNReceiveMessagesOperation: 'PNReceiveMessagesOperation', - }; - - /* */ - var default_1$6 = /** @class */ (function () { - function default_1(configuration) { - this._maximumSamplesCount = 100; - this._trackedLatencies = {}; - this._latencies = {}; - this._telemetryExcludeOperations = [ - OPERATIONS.PNSubscribeOperation, - OPERATIONS.PNReceiveMessagesOperation, - OPERATIONS.PNHandshakeOperation, - ]; - this._maximumSamplesCount = configuration.maximumSamplesCount || this._maximumSamplesCount; - } - /** - * Compose object with latency information of recently used API endpoints. - * - * @return {Object} Object with request query key/value pairs. - */ - default_1.prototype.operationsLatencyForRequest = function () { - var _this = this; - var latencies = {}; - Object.keys(this._latencies).forEach(function (endpointName) { - var operationLatencies = _this._latencies[endpointName]; - var averageLatency = _this._averageLatency(operationLatencies); - if (averageLatency > 0) { - latencies["l_".concat(endpointName)] = averageLatency; - } - }); - return latencies; - }; - default_1.prototype.startLatencyMeasure = function (operationType, identifier) { - if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { - return; - } - this._trackedLatencies[identifier] = Date.now(); - }; - default_1.prototype.stopLatencyMeasure = function (operationType, identifier) { - if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { - return; - } - var endpointName = this._endpointName(operationType); - /** @type Array */ - var endpointLatencies = this._latencies[endpointName]; - var startDate = this._trackedLatencies[identifier]; - if (!endpointLatencies) { - this._latencies[endpointName] = []; - endpointLatencies = this._latencies[endpointName]; - } - endpointLatencies.push(Date.now() - startDate); - // Truncate samples count if there is more then configured. - if (endpointLatencies.length > this._maximumSamplesCount) { - endpointLatencies.splice(0, endpointLatencies.length - this._maximumSamplesCount); - } - delete this._trackedLatencies[identifier]; - }; - default_1.prototype._averageLatency = function (latencies) { - var arrayReduce = function (accumulatedLatency, latency) { return accumulatedLatency + latency; }; - return Math.floor(latencies.reduce(arrayReduce, 0) / latencies.length); - }; - default_1.prototype._endpointName = function (operationType) { - var operation = null; - switch (operationType) { - case OPERATIONS.PNPublishOperation: - operation = 'pub'; - break; - case OPERATIONS.PNSignalOperation: - operation = 'sig'; - break; - case OPERATIONS.PNHistoryOperation: - case OPERATIONS.PNFetchMessagesOperation: - case OPERATIONS.PNDeleteMessagesOperation: - case OPERATIONS.PNMessageCounts: - operation = 'hist'; - break; - case OPERATIONS.PNUnsubscribeOperation: - case OPERATIONS.PNWhereNowOperation: - case OPERATIONS.PNHereNowOperation: - case OPERATIONS.PNHeartbeatOperation: - case OPERATIONS.PNSetStateOperation: - case OPERATIONS.PNGetStateOperation: - operation = 'pres'; - break; - case OPERATIONS.PNAddChannelsToGroupOperation: - case OPERATIONS.PNRemoveChannelsFromGroupOperation: - case OPERATIONS.PNChannelGroupsOperation: - case OPERATIONS.PNRemoveGroupOperation: - case OPERATIONS.PNChannelsForGroupOperation: - operation = 'cg'; - break; - case OPERATIONS.PNPushNotificationEnabledChannelsOperation: - case OPERATIONS.PNRemoveAllPushNotificationsOperation: - operation = 'push'; - break; - case OPERATIONS.PNCreateUserOperation: - case OPERATIONS.PNUpdateUserOperation: - case OPERATIONS.PNDeleteUserOperation: - case OPERATIONS.PNGetUserOperation: - case OPERATIONS.PNGetUsersOperation: - case OPERATIONS.PNCreateSpaceOperation: - case OPERATIONS.PNUpdateSpaceOperation: - case OPERATIONS.PNDeleteSpaceOperation: - case OPERATIONS.PNGetSpaceOperation: - case OPERATIONS.PNGetSpacesOperation: - case OPERATIONS.PNGetMembersOperation: - case OPERATIONS.PNUpdateMembersOperation: - case OPERATIONS.PNGetMembershipsOperation: - case OPERATIONS.PNUpdateMembershipsOperation: - operation = 'obj'; - break; - case OPERATIONS.PNAddMessageActionOperation: - case OPERATIONS.PNRemoveMessageActionOperation: - case OPERATIONS.PNGetMessageActionsOperation: - operation = 'msga'; - break; - case OPERATIONS.PNAccessManagerGrant: - case OPERATIONS.PNAccessManagerAudit: - operation = 'pam'; - break; - case OPERATIONS.PNAccessManagerGrantToken: - case OPERATIONS.PNAccessManagerRevokeToken: - operation = 'pamv3'; - break; - default: - operation = 'time'; - break; - } - return operation; - }; - return default_1; - }()); - - /* */ - var BaseNotificationPayload = /** @class */ (function () { - function BaseNotificationPayload(payload, title, body) { - this._payload = payload; - this._setDefaultPayloadStructure(); - this.title = title; - this.body = body; - } - Object.defineProperty(BaseNotificationPayload.prototype, "payload", { - get: function () { - return this._payload; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "title", { - set: function (value) { - this._title = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "subtitle", { - set: function (value) { - this._subtitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "body", { - set: function (value) { - this._body = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "badge", { - set: function (value) { - this._badge = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "sound", { - set: function (value) { - this._sound = value; - }, - enumerable: false, - configurable: true - }); - BaseNotificationPayload.prototype._setDefaultPayloadStructure = function () { - // Empty. - }; - BaseNotificationPayload.prototype.toObject = function () { - return {}; - }; - return BaseNotificationPayload; - }()); - var APNSNotificationPayload = /** @class */ (function (_super) { - __extends(APNSNotificationPayload, _super); - function APNSNotificationPayload() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(APNSNotificationPayload.prototype, "configurations", { - set: function (value) { - if (!value || !value.length) - return; - this._configurations = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "notification", { - get: function () { - return this._payload.aps; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "title", { - get: function () { - return this._title; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.aps.alert.title = value; - this._title = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "subtitle", { - get: function () { - return this._subtitle; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.aps.alert.subtitle = value; - this._subtitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "body", { - get: function () { - return this._body; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.aps.alert.body = value; - this._body = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "badge", { - get: function () { - return this._badge; - }, - set: function (value) { - if (value === undefined || value === null) - return; - this._payload.aps.badge = value; - this._badge = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "sound", { - get: function () { - return this._sound; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.aps.sound = value; - this._sound = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "silent", { - set: function (value) { - this._isSilent = value; - }, - enumerable: false, - configurable: true - }); - APNSNotificationPayload.prototype._setDefaultPayloadStructure = function () { - this._payload.aps = { alert: {} }; - }; - APNSNotificationPayload.prototype.toObject = function () { - var _this = this; - var payload = __assign({}, this._payload); - /** @type {{alert: Object, badge: number, sound: string}} */ - var aps = payload.aps; - var alert = aps.alert; - if (this._isSilent) { - aps['content-available'] = 1; - } - if (this._apnsPushType === 'apns2') { - if (!this._configurations || !this._configurations.length) { - throw new ReferenceError('APNS2 configuration is missing'); - } - var configurations_1 = []; - this._configurations.forEach(function (configuration) { - configurations_1.push(_this._objectFromAPNS2Configuration(configuration)); - }); - if (configurations_1.length) { - payload.pn_push = configurations_1; - } - } - if (!alert || !Object.keys(alert).length) { - delete aps.alert; - } - if (this._isSilent) { - delete aps.alert; - delete aps.badge; - delete aps.sound; - alert = {}; - } - return this._isSilent || Object.keys(alert).length ? payload : null; - }; - APNSNotificationPayload.prototype._objectFromAPNS2Configuration = function (configuration) { - var _this = this; - if (!configuration.targets || !configuration.targets.length) { - throw new ReferenceError('At least one APNS2 target should be provided'); - } - var targets = []; - configuration.targets.forEach(function (target) { - targets.push(_this._objectFromAPNSTarget(target)); - }); - var collapseId = configuration.collapseId, expirationDate = configuration.expirationDate; - var objectifiedConfiguration = { auth_method: 'token', targets: targets, version: 'v2' }; - if (collapseId && collapseId.length) { - objectifiedConfiguration.collapse_id = collapseId; - } - if (expirationDate) { - objectifiedConfiguration.expiration = expirationDate.toISOString(); - } - return objectifiedConfiguration; - }; - APNSNotificationPayload.prototype._objectFromAPNSTarget = function (target) { - if (!target.topic || !target.topic.length) { - throw new TypeError("Target 'topic' undefined."); - } - var topic = target.topic, _a = target.environment, environment = _a === void 0 ? 'development' : _a, _b = target.excludedDevices, excludedDevices = _b === void 0 ? [] : _b; - var objectifiedTarget = { topic: topic, environment: environment }; - if (excludedDevices.length) { - objectifiedTarget.excluded_devices = excludedDevices; - } - return objectifiedTarget; - }; - return APNSNotificationPayload; - }(BaseNotificationPayload)); - var MPNSNotificationPayload = /** @class */ (function (_super) { - __extends(MPNSNotificationPayload, _super); - function MPNSNotificationPayload() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(MPNSNotificationPayload.prototype, "backContent", { - get: function () { - return this._backContent; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.back_content = value; - this._backContent = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "backTitle", { - get: function () { - return this._backTitle; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.back_title = value; - this._backTitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "count", { - get: function () { - return this._count; - }, - set: function (value) { - if (value === undefined || value === null) - return; - this._payload.count = value; - this._count = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "title", { - get: function () { - return this._title; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.title = value; - this._title = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "type", { - get: function () { - return this._type; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.type = value; - this._type = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "subtitle", { - get: function () { - return this.backTitle; - }, - set: function (value) { - this.backTitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "body", { - get: function () { - return this.backContent; - }, - set: function (value) { - this.backContent = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "badge", { - get: function () { - return this.count; - }, - set: function (value) { - this.count = value; - }, - enumerable: false, - configurable: true - }); - MPNSNotificationPayload.prototype.toObject = function () { - return Object.keys(this._payload).length ? __assign({}, this._payload) : null; - }; - return MPNSNotificationPayload; - }(BaseNotificationPayload)); - var FCMNotificationPayload = /** @class */ (function (_super) { - __extends(FCMNotificationPayload, _super); - function FCMNotificationPayload() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(FCMNotificationPayload.prototype, "notification", { - get: function () { - return this._payload.notification; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "data", { - get: function () { - return this._payload.data; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "title", { - get: function () { - return this._title; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.title = value; - this._title = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "body", { - get: function () { - return this._body; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.body = value; - this._body = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "sound", { - get: function () { - return this._sound; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.sound = value; - this._sound = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "icon", { - get: function () { - return this._icon; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.icon = value; - this._icon = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "tag", { - get: function () { - return this._tag; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.tag = value; - this._tag = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "silent", { - set: function (value) { - this._isSilent = value; - }, - enumerable: false, - configurable: true - }); - FCMNotificationPayload.prototype._setDefaultPayloadStructure = function () { - this._payload.notification = {}; - this._payload.data = {}; - }; - FCMNotificationPayload.prototype.toObject = function () { - var data = __assign({}, this._payload.data); - var notification = null; - var payload = {}; - /** - * Check whether additional data has been passed outside of 'data' object - * and put it into it if required. - */ - if (Object.keys(this._payload).length > 2) { - var _a = this._payload; _a.notification; _a.data; var additionalData = __rest(_a, ["notification", "data"]); - data = __assign(__assign({}, data), additionalData); - } - if (this._isSilent) { - data.notification = this._payload.notification; - } - else { - notification = this._payload.notification; - } - if (Object.keys(data).length) { - payload.data = data; - } - if (notification && Object.keys(notification).length) { - payload.notification = notification; - } - return Object.keys(payload).length ? payload : null; - }; - return FCMNotificationPayload; - }(BaseNotificationPayload)); - var NotificationsPayload = /** @class */ (function () { - function NotificationsPayload(title, body) { - this._payload = { apns: {}, mpns: {}, fcm: {} }; - this._title = title; - this._body = body; - this.apns = new APNSNotificationPayload(this._payload.apns, title, body); - this.mpns = new MPNSNotificationPayload(this._payload.mpns, title, body); - this.fcm = new FCMNotificationPayload(this._payload.fcm, title, body); - } - Object.defineProperty(NotificationsPayload.prototype, "debugging", { - set: function (value) { - this._debugging = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "title", { - get: function () { - return this._title; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "body", { - get: function () { - return this._body; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "subtitle", { - get: function () { - return this._subtitle; - }, - set: function (value) { - this._subtitle = value; - this.apns.subtitle = value; - this.mpns.subtitle = value; - this.fcm.subtitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "badge", { - get: function () { - return this._badge; - }, - set: function (value) { - this._badge = value; - this.apns.badge = value; - this.mpns.badge = value; - this.fcm.badge = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "sound", { - get: function () { - return this._sound; - }, - set: function (value) { - this._sound = value; - this.apns.sound = value; - this.mpns.sound = value; - this.fcm.sound = value; - }, - enumerable: false, - configurable: true - }); - /** - * Build notifications platform for requested platforms. - * - * @param {Array} platforms - List of platforms for which payload - * should be added to final dictionary. Supported values: gcm, apns, apns2, - * mpns. - * - * @returns {Object} Object with data, which can be sent with publish method - * call and trigger remote notifications for specified platforms. - */ - NotificationsPayload.prototype.buildPayload = function (platforms) { - var payload = {}; - if (platforms.includes('apns') || platforms.includes('apns2')) { - this.apns._apnsPushType = platforms.includes('apns') ? 'apns' : 'apns2'; - var apnsPayload = this.apns.toObject(); - if (apnsPayload && Object.keys(apnsPayload).length) { - payload.pn_apns = apnsPayload; - } - } - if (platforms.includes('mpns')) { - var mpnsPayload = this.mpns.toObject(); - if (mpnsPayload && Object.keys(mpnsPayload).length) { - payload.pn_mpns = mpnsPayload; - } - } - if (platforms.includes('fcm')) { - var fcmPayload = this.fcm.toObject(); - if (fcmPayload && Object.keys(fcmPayload).length) { - payload.pn_gcm = fcmPayload; - } - } - if (Object.keys(payload).length && this._debugging) { - payload.pn_debug = true; - } - return payload; - }; - return NotificationsPayload; - }()); - - var default_1$5 = /** @class */ (function () { - function default_1() { - this._listeners = []; - } - default_1.prototype.addListener = function (newListener) { - if (this._listeners.includes(newListener)) { - return; - } - this._listeners.push(newListener); - }; - default_1.prototype.removeListener = function (deprecatedListener) { - var newListeners = []; - this._listeners.forEach(function (listener) { - if (listener !== deprecatedListener) - newListeners.push(listener); - }); - this._listeners = newListeners; - }; - default_1.prototype.removeAllListeners = function () { - this._listeners = []; - }; - default_1.prototype.announcePresence = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.presence) - listener.presence(announce); - }); - }; - default_1.prototype.announceStatus = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.status) - listener.status(announce); - }); - }; - default_1.prototype.announceMessage = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.message) - listener.message(announce); - }); - }; - default_1.prototype.announceSignal = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.signal) - listener.signal(announce); - }); - }; - default_1.prototype.announceMessageAction = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.messageAction) - listener.messageAction(announce); - }); - }; - default_1.prototype.announceFile = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.file) - listener.file(announce); - }); - }; - default_1.prototype.announceObjects = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.objects) - listener.objects(announce); - }); - }; - default_1.prototype.announceUser = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.user) - listener.user(announce); - }); - }; - default_1.prototype.announceSpace = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.space) - listener.space(announce); - }); - }; - default_1.prototype.announceMembership = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.membership) - listener.membership(announce); - }); - }; - default_1.prototype.announceNetworkUp = function () { - var networkStatus = {}; - networkStatus.category = categories.PNNetworkUpCategory; - this.announceStatus(networkStatus); - }; - default_1.prototype.announceNetworkDown = function () { - var networkStatus = {}; - networkStatus.category = categories.PNNetworkDownCategory; - this.announceStatus(networkStatus); - }; - return default_1; - }()); - - var default_1$4 = /** @class */ (function () { - function default_1(config, cbor) { - this._config = config; - this._cbor = cbor; - } - default_1.prototype.setToken = function (token) { - if (token && token.length > 0) { - this._token = token; - } - else { - this._token = undefined; - } - }; - default_1.prototype.getToken = function () { - return this._token; - }; - default_1.prototype.extractPermissions = function (permissions) { - var permissionsResult = { - read: false, - write: false, - manage: false, - delete: false, - get: false, - update: false, - join: false, - }; - /* eslint-disable */ - if ((permissions & 128) === 128) { - permissionsResult.join = true; - } - if ((permissions & 64) === 64) { - permissionsResult.update = true; - } - if ((permissions & 32) === 32) { - permissionsResult.get = true; - } - if ((permissions & 8) === 8) { - permissionsResult.delete = true; - } - if ((permissions & 4) === 4) { - permissionsResult.manage = true; - } - if ((permissions & 2) === 2) { - permissionsResult.write = true; - } - if ((permissions & 1) === 1) { - permissionsResult.read = true; - } - /* eslint-enable */ - return permissionsResult; - }; - default_1.prototype.parseToken = function (tokenString) { - var _this = this; - var parsed = this._cbor.decodeToken(tokenString); - if (parsed !== undefined) { - var uuidResourcePermissions = parsed.res.uuid ? Object.keys(parsed.res.uuid) : []; - var channelResourcePermissions = Object.keys(parsed.res.chan); - var groupResourcePermissions = Object.keys(parsed.res.grp); - var uuidPatternPermissions = parsed.pat.uuid ? Object.keys(parsed.pat.uuid) : []; - var channelPatternPermissions = Object.keys(parsed.pat.chan); - var groupPatternPermissions = Object.keys(parsed.pat.grp); - var result_1 = { - version: parsed.v, - timestamp: parsed.t, - ttl: parsed.ttl, - authorized_uuid: parsed.uuid, - }; - var uuidResources = uuidResourcePermissions.length > 0; - var channelResources = channelResourcePermissions.length > 0; - var groupResources = groupResourcePermissions.length > 0; - if (uuidResources || channelResources || groupResources) { - result_1.resources = {}; - if (uuidResources) { - result_1.resources.uuids = {}; - uuidResourcePermissions.forEach(function (id) { - result_1.resources.uuids[id] = _this.extractPermissions(parsed.res.uuid[id]); - }); - } - if (channelResources) { - result_1.resources.channels = {}; - channelResourcePermissions.forEach(function (id) { - result_1.resources.channels[id] = _this.extractPermissions(parsed.res.chan[id]); - }); - } - if (groupResources) { - result_1.resources.groups = {}; - groupResourcePermissions.forEach(function (id) { - result_1.resources.groups[id] = _this.extractPermissions(parsed.res.grp[id]); - }); - } - } - var uuidPatterns = uuidPatternPermissions.length > 0; - var channelPatterns = channelPatternPermissions.length > 0; - var groupPatterns = groupPatternPermissions.length > 0; - if (uuidPatterns || channelPatterns || groupPatterns) { - result_1.patterns = {}; - if (uuidPatterns) { - result_1.patterns.uuids = {}; - uuidPatternPermissions.forEach(function (id) { - result_1.patterns.uuids[id] = _this.extractPermissions(parsed.pat.uuid[id]); - }); - } - if (channelPatterns) { - result_1.patterns.channels = {}; - channelPatternPermissions.forEach(function (id) { - result_1.patterns.channels[id] = _this.extractPermissions(parsed.pat.chan[id]); - }); - } - if (groupPatterns) { - result_1.patterns.groups = {}; - groupPatternPermissions.forEach(function (id) { - result_1.patterns.groups[id] = _this.extractPermissions(parsed.pat.grp[id]); - }); - } - } - if (Object.keys(parsed.meta).length > 0) { - result_1.meta = parsed.meta; - } - result_1.signature = parsed.sig; - return result_1; - } - return undefined; - }; - return default_1; - }()); - - 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 }; - } - function stringToArrayBuffer(str) { - var buf = new ArrayBuffer(str.length * 2); - var bufView = new Uint16Array(buf); - for (var i = 0, strLen = str.length; i < strLen; i++) { - bufView[i] = str.charCodeAt(i); - } - return buf; - } - function removeSingleOccurance(source, elementsToRemove) { - var removed = Object.fromEntries(elementsToRemove.map(function (prop) { return [prop, false]; })); - return source.filter(function (e) { - if (elementsToRemove.includes(e) && !removed[e]) { - removed[e] = true; - return false; - } - return true; - }); - } - function findUniqueCommonElements(a, b) { - return __spreadArray([], __read(a), false).filter(function (value) { - return b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value); - }); - } - var utils$5 = { - signPamFromParams: signPamFromParams, - endsWith: endsWith, - createPromise: createPromise, - encodeString: encodeString, - stringToArrayBuffer: stringToArrayBuffer, - removeSingleOccurance: removeSingleOccurance, - findUniqueCommonElements: findUniqueCommonElements, - }; - - var PubNubError = /** @class */ (function (_super) { - __extends(PubNubError, _super); - function PubNubError(message, status) { - var _newTarget = this.constructor; - var _this = _super.call(this, message) || this; - _this.name = _this.constructor.name; - _this.status = status; - _this.message = message; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return PubNubError; - }(Error)); - 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); - } - if (endpoint.usePatch && endpoint.usePatch(modules, incomingParams)) { - return endpoint.patchURL(modules, incomingParams); - } - if (endpoint.useGetFile && endpoint.useGetFile(modules, incomingParams)) { - return endpoint.getFileURL(modules, incomingParams); - } - return endpoint.getURL(modules, incomingParams); - } - 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'; - } - if (endpoint.usePatch && endpoint.usePatch(modules, incomingParams)) { - return 'PATCH'; - } - if (endpoint.useDelete && endpoint.useDelete(modules, incomingParams)) { - return 'DELETE'; - } - if (endpoint.useGetFile && endpoint.useGetFile(modules, incomingParams)) { - return 'GETFILE'; - } - 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); - // This is because of a server-side bug, old publish using post should be deprecated - 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$5.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 endpointCreator (modules, endpoint) { - var args = []; - for (var _i = 2; _i < arguments.length; _i++) { - args[_i - 2] = arguments[_i]; - } - var networking = modules.networking, config = modules.config, telemetryManager = modules.telemetryManager, tokenManager = modules.tokenManager; - var requestId = uuidGenerator.createUUID(); - var callback = null; - var promiseComponent = null; - var incomingParams = {}; - if (endpoint.getOperation() === OPERATIONS.PNTimeOperation || - endpoint.getOperation() === OPERATIONS.PNChannelGroupsOperation) { - callback = args[0]; - } - else { - incomingParams = args[0]; - callback = args[1]; - } - // bridge in Promise support. - if (typeof Promise !== 'undefined' && !callback) { - promiseComponent = utils$5.createPromise(); - } - var validationResult = endpoint.validateParams(modules, incomingParams); - if (validationResult) { - if (callback) { - return callback(createValidationError(validationResult)); - } - 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, - abortSignal: typeof endpoint.getAbortSignal === 'function' ? endpoint.getAbortSignal(modules, incomingParams) : null, - }; - outgoingParams.uuid = config.UUID; - outgoingParams.pnsdk = generatePNSDK(config); - // Add telemetry information (if there is any available). - var telemetryLatencies = telemetryManager.operationsLatencyForRequest(); - if (Object.keys(telemetryLatencies).length) { - outgoingParams = __assign(__assign({}, outgoingParams), telemetryLatencies); - } - if (config.useInstanceId) { - outgoingParams.instanceid = config.instanceId; - } - if (config.useRequestId) { - outgoingParams.requestid = requestId; - } - if (endpoint.isAuthSupported()) { - var tokenOrKey = tokenManager.getToken() || config.getAuthKey(); - if (tokenOrKey) { - outgoingParams.auth = tokenOrKey; - } - } - if (config.secretKey) { - signRequest(modules, url, outgoingParams, incomingParams, endpoint); - } - var onResponse = function (status, payload) { - 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; - } - // Stop endpoint latency tracking. - telemetryManager.stopLatencyMeasure(endpoint.getOperation(), requestId); - var responseP = endpoint.handleResponse(modules, payload, incomingParams); - if (typeof (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.PNSubscribeOperation) { - errorData = { - statusCode: 400, - error: true, - operation: endpoint.getOperation(), - errorData: e, - category: categories.PNUnknownCategory, - }; - } - callback(errorData, null); - } - else if (promiseComponent) { - promiseComponent.reject(new PubNubError('PubNub call failed, check status for details', e)); - } - }); - }; - // Start endpoint latency tracking. - 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 payload = endpoint.patchPayload(modules, incomingParams); - callInstance = networking.PATCH(outgoingParams, payload, 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.PNSubscribeOperation) { - return callInstance; - } - if (promiseComponent) { - return promiseComponent.promise; - } - } - - /* */ - function getOperation$s() { - return OPERATIONS.PNAddChannelsToGroupOperation; - } - function validateParams$s(modules, incomingParams) { - var channels = incomingParams.channels, channelGroup = incomingParams.channelGroup; - var config = modules.config; - if (!channelGroup) - return 'Missing Channel Group'; - if (!channels || channels.length === 0) - return 'Missing Channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$q(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group/").concat(utils$5.encodeString(channelGroup)); - } - function getRequestTimeout$s(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$s() { - return true; - } - function prepareParams$s(modules, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - return { - add: channels.join(','), - }; - } - function handleResponse$s() { - return {}; - } - - var addChannelsChannelGroupConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$s, - validateParams: validateParams$s, - getURL: getURL$q, - getRequestTimeout: getRequestTimeout$s, - isAuthSupported: isAuthSupported$s, - prepareParams: prepareParams$s, - handleResponse: handleResponse$s - }); - - /* */ - function getOperation$r() { - return OPERATIONS.PNRemoveChannelsFromGroupOperation; - } - function validateParams$r(modules, incomingParams) { - var channels = incomingParams.channels, channelGroup = incomingParams.channelGroup; - var config = modules.config; - if (!channelGroup) - return 'Missing Channel Group'; - if (!channels || channels.length === 0) - return 'Missing Channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$p(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group/").concat(utils$5.encodeString(channelGroup)); - } - function getRequestTimeout$r(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$r() { - return true; - } - function prepareParams$r(modules, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - return { - remove: channels.join(','), - }; - } - function handleResponse$r() { - return {}; - } - - var removeChannelsChannelGroupConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$r, - validateParams: validateParams$r, - getURL: getURL$p, - getRequestTimeout: getRequestTimeout$r, - isAuthSupported: isAuthSupported$r, - prepareParams: prepareParams$r, - handleResponse: handleResponse$r - }); - - /* */ - function getOperation$q() { - return OPERATIONS.PNRemoveGroupOperation; - } - function validateParams$q(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - if (!channelGroup) - return 'Missing Channel Group'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$o(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group/").concat(utils$5.encodeString(channelGroup), "/remove"); - } - function isAuthSupported$q() { - return true; - } - function getRequestTimeout$q(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function prepareParams$q() { - return {}; - } - function handleResponse$q() { - return {}; - } - - var deleteChannelGroupConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$q, - validateParams: validateParams$q, - getURL: getURL$o, - isAuthSupported: isAuthSupported$q, - getRequestTimeout: getRequestTimeout$q, - prepareParams: prepareParams$q, - handleResponse: handleResponse$q - }); - - /* */ - function getOperation$p() { - return OPERATIONS.PNChannelGroupsOperation; - } - function validateParams$p(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$n(modules) { - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group"); - } - function getRequestTimeout$p(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$p() { - return true; - } - function prepareParams$p() { - return {}; - } - function handleResponse$p(modules, serverResponse) { - return { - groups: serverResponse.payload.groups, - }; - } - - var listChannelGroupsConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$p, - validateParams: validateParams$p, - getURL: getURL$n, - getRequestTimeout: getRequestTimeout$p, - isAuthSupported: isAuthSupported$p, - prepareParams: prepareParams$p, - handleResponse: handleResponse$p - }); - - /* */ - function getOperation$o() { - return OPERATIONS.PNChannelsForGroupOperation; - } - function validateParams$o(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - if (!channelGroup) - return 'Missing Channel Group'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$m(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group/").concat(utils$5.encodeString(channelGroup)); - } - function getRequestTimeout$o(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$o() { - return true; - } - function prepareParams$o() { - return {}; - } - function handleResponse$o(modules, serverResponse) { - return { - channels: serverResponse.payload.channels, - }; - } - - var listChannelsInChannelGroupConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$o, - validateParams: validateParams$o, - getURL: getURL$m, - getRequestTimeout: getRequestTimeout$o, - isAuthSupported: isAuthSupported$o, - prepareParams: prepareParams$o, - handleResponse: handleResponse$o - }); - - /* */ - function getOperation$n() { - return OPERATIONS.PNPushNotificationEnabledChannelsOperation; - } - function validateParams$n(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway, channels = incomingParams.channels, topic = incomingParams.topic; - var config = modules.config; - if (!device) - return 'Missing Device ID (device)'; - if (!pushGateway) - return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) - return 'Missing APNS2 topic'; - if (!channels || channels.length === 0) - return 'Missing Channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$l(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway; - var config = modules.config; - if (pushGateway === 'apns2') { - return "/v2/push/sub-key/".concat(config.subscribeKey, "/devices-apns2/").concat(device); - } - return "/v1/push/sub-key/".concat(config.subscribeKey, "/devices/").concat(device); - } - function getRequestTimeout$n(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$n() { - return true; - } - function prepareParams$n(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.environment, environment = _b === void 0 ? 'development' : _b, topic = incomingParams.topic; - var parameters = { type: pushGateway, add: channels.join(',') }; - if (pushGateway === 'apns2') { - parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); - delete parameters.type; - } - return parameters; - } - function handleResponse$n() { - return {}; - } - - var addPushChannelsConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$n, - validateParams: validateParams$n, - getURL: getURL$l, - getRequestTimeout: getRequestTimeout$n, - isAuthSupported: isAuthSupported$n, - prepareParams: prepareParams$n, - handleResponse: handleResponse$n - }); - - /* */ - function getOperation$m() { - return OPERATIONS.PNPushNotificationEnabledChannelsOperation; - } - function validateParams$m(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway, channels = incomingParams.channels, topic = incomingParams.topic; - var config = modules.config; - if (!device) - return 'Missing Device ID (device)'; - if (!pushGateway) - return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) - return 'Missing APNS2 topic'; - if (!channels || channels.length === 0) - return 'Missing Channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$k(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway; - var config = modules.config; - if (pushGateway === 'apns2') { - return "/v2/push/sub-key/".concat(config.subscribeKey, "/devices-apns2/").concat(device); - } - return "/v1/push/sub-key/".concat(config.subscribeKey, "/devices/").concat(device); - } - function getRequestTimeout$m(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$m() { - return true; - } - function prepareParams$m(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.environment, environment = _b === void 0 ? 'development' : _b, topic = incomingParams.topic; - var parameters = { type: pushGateway, remove: channels.join(',') }; - if (pushGateway === 'apns2') { - parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); - delete parameters.type; - } - return parameters; - } - function handleResponse$m() { - return {}; - } - - var removePushChannelsConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$m, - validateParams: validateParams$m, - getURL: getURL$k, - getRequestTimeout: getRequestTimeout$m, - isAuthSupported: isAuthSupported$m, - prepareParams: prepareParams$m, - handleResponse: handleResponse$m - }); - - function getOperation$l() { - return OPERATIONS.PNPushNotificationEnabledChannelsOperation; - } - function validateParams$l(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway, topic = incomingParams.topic; - var config = modules.config; - if (!device) - return 'Missing Device ID (device)'; - if (!pushGateway) - return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) - return 'Missing APNS2 topic'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$j(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway; - var config = modules.config; - if (pushGateway === 'apns2') { - return "/v2/push/sub-key/".concat(config.subscribeKey, "/devices-apns2/").concat(device); - } - return "/v1/push/sub-key/".concat(config.subscribeKey, "/devices/").concat(device); - } - function getRequestTimeout$l(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$l() { - return true; - } - function prepareParams$l(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.environment, environment = _a === void 0 ? 'development' : _a, topic = incomingParams.topic, start = incomingParams.start, count = incomingParams.count; - var parameters = { type: pushGateway }; - if (pushGateway === 'apns2') { - parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); - delete parameters.type; - } - if (start) - parameters.start = start; - if (count && count > 0) - parameters.count = count; - return parameters; - } - function handleResponse$l(modules, serverResponse) { - return { channels: serverResponse }; - } - - var listPushChannelsConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$l, - validateParams: validateParams$l, - getURL: getURL$j, - getRequestTimeout: getRequestTimeout$l, - isAuthSupported: isAuthSupported$l, - prepareParams: prepareParams$l, - handleResponse: handleResponse$l - }); - - /* */ - function getOperation$k() { - return OPERATIONS.PNRemoveAllPushNotificationsOperation; - } - function validateParams$k(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway, topic = incomingParams.topic; - var config = modules.config; - if (!device) - return 'Missing Device ID (device)'; - if (!pushGateway) - return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) - return 'Missing APNS2 topic'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$i(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway; - var config = modules.config; - if (pushGateway === 'apns2') { - return "/v2/push/sub-key/".concat(config.subscribeKey, "/devices-apns2/").concat(device, "/remove"); - } - return "/v1/push/sub-key/".concat(config.subscribeKey, "/devices/").concat(device, "/remove"); - } - function getRequestTimeout$k(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$k() { - return true; - } - function prepareParams$k(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.environment, environment = _a === void 0 ? 'development' : _a, topic = incomingParams.topic; - var parameters = { type: pushGateway }; - if (pushGateway === 'apns2') { - parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); - delete parameters.type; - } - return parameters; - } - function handleResponse$k() { - return {}; - } - - var removeDevicePushConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$k, - validateParams: validateParams$k, - getURL: getURL$i, - getRequestTimeout: getRequestTimeout$k, - isAuthSupported: isAuthSupported$k, - prepareParams: prepareParams$k, - handleResponse: handleResponse$k - }); - - /* */ - function getOperation$j() { - return OPERATIONS.PNUnsubscribeOperation; - } - function validateParams$j(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$h(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(stringifiedChannels), "/leave"); - } - function getRequestTimeout$j(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$j() { - return true; - } - function prepareParams$j(modules, incomingParams) { - var _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a; - var params = {}; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - return params; - } - function handleResponse$j() { - return {}; - } - - var presenceLeaveEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$j, - validateParams: validateParams$j, - getURL: getURL$h, - getRequestTimeout: getRequestTimeout$j, - isAuthSupported: isAuthSupported$j, - prepareParams: prepareParams$j, - handleResponse: handleResponse$j - }); - - /* */ - function getOperation$i() { - return OPERATIONS.PNWhereNowOperation; - } - function validateParams$i(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$g(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.uuid, uuid = _a === void 0 ? config.UUID : _a; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/uuid/").concat(utils$5.encodeString(uuid)); - } - function getRequestTimeout$i(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$i() { - return true; - } - function prepareParams$i() { - return {}; - } - function handleResponse$i(modules, serverResponse) { - // This is a quick fix for when the server does not include a payload - // in where now responses - if (!serverResponse.payload) { - return { channels: [] }; - } - return { channels: serverResponse.payload.channels }; - } - - var presenceWhereNowEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$i, - validateParams: validateParams$i, - getURL: getURL$g, - getRequestTimeout: getRequestTimeout$i, - isAuthSupported: isAuthSupported$i, - prepareParams: prepareParams$i, - handleResponse: handleResponse$i - }); - - /* */ - function getOperation$h() { - return OPERATIONS.PNHeartbeatOperation; - } - function validateParams$h(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$f(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(stringifiedChannels), "/heartbeat"); - } - function isAuthSupported$h() { - return true; - } - function getRequestTimeout$h(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function prepareParams$h(modules, incomingParams) { - var _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a, state = incomingParams.state; - var config = modules.config; - var params = {}; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - if (state) { - params.state = JSON.stringify(state); - } - params.heartbeat = config.getPresenceTimeout(); - return params; - } - function handleResponse$h() { - return {}; - } - - var presenceHeartbeatEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$h, - validateParams: validateParams$h, - getURL: getURL$f, - isAuthSupported: isAuthSupported$h, - getRequestTimeout: getRequestTimeout$h, - prepareParams: prepareParams$h, - handleResponse: handleResponse$h - }); - - /* */ - function getOperation$g() { - return OPERATIONS.PNGetStateOperation; - } - function validateParams$g(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$e(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.uuid, uuid = _a === void 0 ? config.UUID : _a, _b = incomingParams.channels, channels = _b === void 0 ? [] : _b; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(stringifiedChannels), "/uuid/").concat(uuid); - } - function getRequestTimeout$g(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$g() { - return true; - } - function prepareParams$g(modules, incomingParams) { - var _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a; - var params = {}; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - return params; - } - function handleResponse$g(modules, serverResponse, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b; - var channelsResponse = {}; - if (channels.length === 1 && channelGroups.length === 0) { - channelsResponse[channels[0]] = serverResponse.payload; - } - else { - channelsResponse = serverResponse.payload; - } - return { channels: channelsResponse }; - } - - var presenceGetStateConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$g, - validateParams: validateParams$g, - getURL: getURL$e, - getRequestTimeout: getRequestTimeout$g, - isAuthSupported: isAuthSupported$g, - prepareParams: prepareParams$g, - handleResponse: handleResponse$g - }); - - function getOperation$f() { - return OPERATIONS.PNSetStateOperation; - } - function validateParams$f(modules, incomingParams) { - var config = modules.config; - var state = incomingParams.state, _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b; - if (!state) - return 'Missing State'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (channels.length === 0 && channelGroups.length === 0) { - return 'Please provide a list of channels and/or channel-groups'; - } - } - function getURL$d(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(stringifiedChannels), "/uuid/").concat(utils$5.encodeString(config.UUID), "/data"); - } - function getRequestTimeout$f(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$f() { - return true; - } - function prepareParams$f(modules, incomingParams) { - var state = incomingParams.state, _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a; - var params = {}; - params.state = JSON.stringify(state); - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - return params; - } - function handleResponse$f(modules, serverResponse) { - return { state: serverResponse.payload }; - } - - var presenceSetStateConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$f, - validateParams: validateParams$f, - getURL: getURL$d, - getRequestTimeout: getRequestTimeout$f, - isAuthSupported: isAuthSupported$f, - prepareParams: prepareParams$f, - handleResponse: handleResponse$f - }); - - function getOperation$e() { - return OPERATIONS.PNHereNowOperation; - } - function validateParams$e(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$c(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b; - var baseURL = "/v2/presence/sub-key/".concat(config.subscribeKey); - if (channels.length > 0 || channelGroups.length > 0) { - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - baseURL += "/channel/".concat(utils$5.encodeString(stringifiedChannels)); - } - return baseURL; - } - function getRequestTimeout$e(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$e() { - return true; - } - function prepareParams$e(modules, incomingParams) { - var _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a, _b = incomingParams.includeUUIDs, includeUUIDs = _b === void 0 ? true : _b, _c = incomingParams.includeState, includeState = _c === void 0 ? false : _c, _d = incomingParams.queryParameters, queryParameters = _d === void 0 ? {} : _d; - var params = {}; - if (!includeUUIDs) - params.disable_uuids = 1; - if (includeState) - params.state = 1; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - params = __assign(__assign({}, params), queryParameters); - return params; - } - function handleResponse$e(modules, serverResponse, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b, _c = incomingParams.includeUUIDs, includeUUIDs = _c === void 0 ? true : _c, _d = incomingParams.includeState, includeState = _d === void 0 ? false : _d; - var prepareSingularChannel = function () { - var response = {}; - var occupantsList = []; - response.totalChannels = 1; - response.totalOccupancy = serverResponse.occupancy; - response.channels = {}; - response.channels[channels[0]] = { - occupants: occupantsList, - name: channels[0], - occupancy: serverResponse.occupancy, - }; - // We have had issues in the past with server returning responses - // that contain no uuids array - if (includeUUIDs && serverResponse.uuids) { - serverResponse.uuids.forEach(function (uuidEntry) { - if (includeState) { - occupantsList.push({ state: uuidEntry.state, uuid: uuidEntry.uuid }); - } - else { - occupantsList.push({ state: null, uuid: uuidEntry }); - } - }); - } - return response; - }; - var prepareMultipleChannel = function () { - var response = {}; - response.totalChannels = serverResponse.payload.total_channels; - response.totalOccupancy = serverResponse.payload.total_occupancy; - response.channels = {}; - Object.keys(serverResponse.payload.channels).forEach(function (channelName) { - var channelEntry = serverResponse.payload.channels[channelName]; - var occupantsList = []; - response.channels[channelName] = { - occupants: occupantsList, - name: channelName, - occupancy: channelEntry.occupancy, - }; - if (includeUUIDs) { - channelEntry.uuids.forEach(function (uuidEntry) { - if (includeState) { - occupantsList.push({ - state: uuidEntry.state, - uuid: uuidEntry.uuid, - }); - } - else { - occupantsList.push({ state: null, uuid: uuidEntry }); - } - }); - } - return response; - }); - return response; - }; - var response; - if (channels.length > 1 || channelGroups.length > 0 || (channelGroups.length === 0 && channels.length === 0)) { - response = prepareMultipleChannel(); - } - else { - response = prepareSingularChannel(); - } - return response; - } - function handleError(modules, params, status) { - if (status.statusCode === 402 && !this.getURL(modules, params).includes('channel')) { - status.errorData.message = - 'You have tried to perform a Global Here Now operation, ' + - 'your keyset configuration does not support that. Please provide a channel, ' + - 'or enable the Global Here Now feature from the Portal.'; - } - } - - var presenceHereNowConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$e, - validateParams: validateParams$e, - getURL: getURL$c, - getRequestTimeout: getRequestTimeout$e, - isAuthSupported: isAuthSupported$e, - prepareParams: prepareParams$e, - handleResponse: handleResponse$e, - handleError: handleError - }); - - /* */ - function getOperation$d() { - return OPERATIONS.PNAddMessageActionOperation; - } - function validateParams$d(_a, incomingParams) { - var config = _a.config; - var action = incomingParams.action, channel = incomingParams.channel, messageTimetoken = incomingParams.messageTimetoken; - if (!messageTimetoken) - return 'Missing message timetoken'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!channel) - return 'Missing message channel'; - if (!action) - return 'Missing Action'; - if (!action.value) - return 'Missing Action.value'; - if (!action.type) - return 'Missing Action.type'; - if (action.type.length > 15) - return 'Action.type value exceed maximum length of 15'; - } - function usePost$2() { - return true; - } - function postURL$2(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel, messageTimetoken = incomingParams.messageTimetoken; - return "/v1/message-actions/".concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(channel), "/message/").concat(messageTimetoken); - } - function getRequestTimeout$d(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function getRequestHeaders() { - return { 'Content-Type': 'application/json' }; - } - function isAuthSupported$d() { - return true; - } - function prepareParams$d() { - return {}; - } - function postPayload$2(modules, incomingParams) { - return incomingParams.action; - } - function handleResponse$d(modules, addMessageActionResponse) { - return { data: addMessageActionResponse.data }; - } - - var addMessageActionEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$d, - validateParams: validateParams$d, - usePost: usePost$2, - postURL: postURL$2, - getRequestTimeout: getRequestTimeout$d, - getRequestHeaders: getRequestHeaders, - isAuthSupported: isAuthSupported$d, - prepareParams: prepareParams$d, - postPayload: postPayload$2, - handleResponse: handleResponse$d - }); - - /* */ - function getOperation$c() { - return OPERATIONS.PNRemoveMessageActionOperation; - } - function validateParams$c(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel, actionTimetoken = incomingParams.actionTimetoken, messageTimetoken = incomingParams.messageTimetoken; - if (!messageTimetoken) - return 'Missing message timetoken'; - if (!actionTimetoken) - return 'Missing action timetoken'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!channel) - return 'Missing message channel'; - } - function useDelete$1() { - return true; - } - function getURL$b(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel, actionTimetoken = incomingParams.actionTimetoken, messageTimetoken = incomingParams.messageTimetoken; - return "/v1/message-actions/".concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(channel), "/message/").concat(messageTimetoken, "/action/").concat(actionTimetoken); - } - function getRequestTimeout$c(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$c() { - return true; - } - function prepareParams$c() { - return {}; - } - function handleResponse$c(modules, removeMessageActionResponse) { - return { data: removeMessageActionResponse.data }; - } - - var removeMessageActionEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$c, - validateParams: validateParams$c, - useDelete: useDelete$1, - getURL: getURL$b, - getRequestTimeout: getRequestTimeout$c, - isAuthSupported: isAuthSupported$c, - prepareParams: prepareParams$c, - handleResponse: handleResponse$c - }); - - /* */ - function getOperation$b() { - return OPERATIONS.PNGetMessageActionsOperation; - } - function validateParams$b(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!channel) - return 'Missing message channel'; - } - function getURL$a(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel; - return "/v1/message-actions/".concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(channel)); - } - function getRequestTimeout$b(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$b() { - return true; - } - function prepareParams$b(modules, incomingParams) { - var limit = incomingParams.limit, start = incomingParams.start, end = incomingParams.end; - var outgoingParams = {}; - if (limit) - outgoingParams.limit = limit; - if (start) - outgoingParams.start = start; - if (end) - outgoingParams.end = end; - return outgoingParams; - } - function handleResponse$b(modules, getMessageActionsResponse) { - /** @type GetMessageActionsResponse */ - var response = { data: getMessageActionsResponse.data, start: null, end: null }; - if (response.data.length) { - response.end = response.data[response.data.length - 1].actionTimetoken; - response.start = response.data[0].actionTimetoken; - } - return response; - } - - var getMessageActionEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$b, - validateParams: validateParams$b, - getURL: getURL$a, - getRequestTimeout: getRequestTimeout$b, - isAuthSupported: isAuthSupported$b, - prepareParams: prepareParams$b, - handleResponse: handleResponse$b - }); - - /** */ - var endpoint$j = { - getOperation: function () { return OPERATIONS.PNListFilesOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return "channel can't be empty"; - } - }, - getURL: function (_a, params) { - var config = _a.config; - return "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(params.channel), "/files"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var outParams = {}; - if (params.limit) { - outParams.limit = params.limit; - } - if (params.next) { - outParams.next = params.next; - } - return outParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - next: response.next, - count: response.count, - }); }, - }; - - /** */ - var endpoint$i = { - getOperation: function () { return OPERATIONS.PNGenerateUploadUrlOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return "channel can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.name)) { - return "name can't be empty"; - } - }, - usePost: function () { return true; }, - postURL: function (_a, params) { - var config = _a.config; - return "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(params.channel), "/generate-upload-url"); - }, - postPayload: function (_, params) { return ({ - name: params.name, - }); }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function () { return ({}); }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - file_upload_request: response.file_upload_request, - }); }, - }; - - /** */ - var preparePayload = function (modules, payload) { - var stringifiedPayload = JSON.stringify(payload); - if (modules.cryptoModule) { - var encrypted = modules.cryptoModule.encrypt(stringifiedPayload); - stringifiedPayload = typeof encrypted === 'string' ? encrypted : encode$1(encrypted); - stringifiedPayload = JSON.stringify(stringifiedPayload); - } - return stringifiedPayload || ''; - }; - var endpoint$h = { - getOperation: function () { return OPERATIONS.PNPublishFileOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return "channel can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.fileId)) { - return "file id can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.fileName)) { - return "file name can't be empty"; - } - }, - getURL: function (modules, params) { - var _a = modules.config, publishKey = _a.publishKey, subscribeKey = _a.subscribeKey; - var message = { - message: params.message, - file: { - name: params.fileName, - id: params.fileId, - }, - }; - var payload = preparePayload(modules, message); - return "/v1/files/publish-file/".concat(publishKey, "/").concat(subscribeKey, "/0/").concat(utils$5.encodeString(params.channel), "/0/").concat(utils$5.encodeString(payload)); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var outParams = {}; - if (params.ttl) { - outParams.ttl = params.ttl; - } - if (params.storeInHistory !== undefined) { - outParams.store = params.storeInHistory ? '1' : '0'; - } - if (params.meta && typeof params.meta === 'object') { - outParams.meta = JSON.stringify(params.meta); - } - return outParams; - }, - handleResponse: function (_, response) { return ({ - timetoken: response['2'], - }); }, - }; - - var sendFile = function (_a) { - var _this = this; - var generateUploadUrl = _a.generateUploadUrl, publishFile = _a.publishFile, _b = _a.modules, PubNubFile = _b.PubNubFile, config = _b.config, cryptography = _b.cryptography, cryptoModule = _b.cryptoModule, networking = _b.networking; - return function (_a) { - var channel = _a.channel, input = _a.file, message = _a.message, cipherKey = _a.cipherKey, meta = _a.meta, ttl = _a.ttl, storeInHistory = _a.storeInHistory; - return __awaiter(_this, void 0, void 0, function () { - var file, _b, _c, url, formFields, _d, id, name, _e, formFieldsWithMimeType, result, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, e_1, errorBody, reason, retries, wasSuccessful, publishResult; - return __generator(this, function (_t) { - switch (_t.label) { - case 0: - if (!channel) { - throw new PubNubError('Validation failed, check status for details', createValidationError("channel can't be empty")); - } - if (!input) { - throw new PubNubError('Validation failed, check status for details', createValidationError("file can't be empty")); - } - file = PubNubFile.create(input); - return [4 /*yield*/, generateUploadUrl({ channel: channel, name: file.name })]; - case 1: - _b = _t.sent(), _c = _b.file_upload_request, url = _c.url, formFields = _c.form_fields, _d = _b.data, id = _d.id, name = _d.name; - if (!(PubNubFile.supportsEncryptFile && (cipherKey || cryptoModule))) return [3 /*break*/, 6]; - if (!(cipherKey == null)) return [3 /*break*/, 3]; - return [4 /*yield*/, cryptoModule.encryptFile(file, PubNubFile)]; - case 2: - _e = _t.sent(); - return [3 /*break*/, 5]; - case 3: return [4 /*yield*/, cryptography.encryptFile(cipherKey, file, PubNubFile)]; - case 4: - _e = _t.sent(); - _t.label = 5; - case 5: - file = _e; - _t.label = 6; - case 6: - formFieldsWithMimeType = formFields; - if (file.mimeType) { - formFieldsWithMimeType = formFields.map(function (entry) { - if (entry.key === 'Content-Type') - return { key: entry.key, value: file.mimeType }; - return entry; - }); - } - _t.label = 7; - case 7: - _t.trys.push([7, 21, , 22]); - if (!(PubNubFile.supportsFileUri && input.uri)) return [3 /*break*/, 10]; - _g = (_f = networking).POSTFILE; - _h = [url, formFieldsWithMimeType]; - return [4 /*yield*/, file.toFileUri()]; - case 8: return [4 /*yield*/, _g.apply(_f, _h.concat([_t.sent()]))]; - case 9: - result = _t.sent(); - return [3 /*break*/, 20]; - case 10: - if (!PubNubFile.supportsFile) return [3 /*break*/, 13]; - _k = (_j = networking).POSTFILE; - _l = [url, formFieldsWithMimeType]; - return [4 /*yield*/, file.toFile()]; - case 11: return [4 /*yield*/, _k.apply(_j, _l.concat([_t.sent()]))]; - case 12: - result = _t.sent(); - return [3 /*break*/, 20]; - case 13: - if (!PubNubFile.supportsBuffer) return [3 /*break*/, 16]; - _o = (_m = networking).POSTFILE; - _p = [url, formFieldsWithMimeType]; - return [4 /*yield*/, file.toBuffer()]; - case 14: return [4 /*yield*/, _o.apply(_m, _p.concat([_t.sent()]))]; - case 15: - result = _t.sent(); - return [3 /*break*/, 20]; - case 16: - if (!PubNubFile.supportsBlob) return [3 /*break*/, 19]; - _r = (_q = networking).POSTFILE; - _s = [url, formFieldsWithMimeType]; - return [4 /*yield*/, file.toBlob()]; - case 17: return [4 /*yield*/, _r.apply(_q, _s.concat([_t.sent()]))]; - case 18: - result = _t.sent(); - return [3 /*break*/, 20]; - case 19: throw new Error('Unsupported environment'); - case 20: return [3 /*break*/, 22]; - case 21: - e_1 = _t.sent(); - if (e_1.response && typeof e_1.response.text === 'string') { - errorBody = e_1.response.text; - reason = /(.*)<\/Message>/gi.exec(errorBody); - throw new PubNubError(reason ? "Upload to bucket failed: ".concat(reason[1]) : 'Upload to bucket failed.', e_1); - } - else { - throw new PubNubError('Upload to bucket failed.', e_1); - } - case 22: - if (result.status !== 204) { - throw new PubNubError('Upload to bucket was unsuccessful', result); - } - retries = config.fileUploadPublishRetryLimit; - wasSuccessful = false; - publishResult = { timetoken: '0' }; - _t.label = 23; - case 23: - _t.trys.push([23, 25, , 26]); - return [4 /*yield*/, publishFile({ - channel: channel, - message: message, - fileId: id, - fileName: name, - meta: meta, - storeInHistory: storeInHistory, - ttl: ttl, - })]; - case 24: - /* eslint-disable-next-line no-await-in-loop */ - publishResult = _t.sent(); - wasSuccessful = true; - return [3 /*break*/, 26]; - case 25: - _t.sent(); - retries -= 1; - return [3 /*break*/, 26]; - case 26: - if (!wasSuccessful && retries > 0) return [3 /*break*/, 23]; - _t.label = 27; - case 27: - if (!wasSuccessful) { - throw new PubNubError('Publish failed. You may want to execute that operation manually using pubnub.publishFile', { - channel: channel, - id: id, - name: name, - }); - } - else { - return [2 /*return*/, { - timetoken: publishResult.timetoken, - id: id, - name: name, - }]; - } - } - }); - }); - }; - }; - var sendFileFunction = (function (deps) { - var f = sendFile(deps); - return function (params, cb) { - var resultP = f(params); - if (typeof cb === 'function') { - resultP.then(function (result) { return cb(null, result); }).catch(function (error) { return cb(error, null); }); - return resultP; - } - return resultP; - }; - }); - - /** */ - var getFileUrlFunction = (function (modules, _a) { - var channel = _a.channel, id = _a.id, name = _a.name; - var config = modules.config, networking = modules.networking, tokenManager = modules.tokenManager; - if (!channel) { - throw new PubNubError('Validation failed, check status for details', createValidationError("channel can't be empty")); - } - if (!id) { - throw new PubNubError('Validation failed, check status for details', createValidationError("file id can't be empty")); - } - if (!name) { - throw new PubNubError('Validation failed, check status for details', createValidationError("file name can't be empty")); - } - var url = "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(channel), "/files/").concat(id, "/").concat(name); - var params = {}; - params.uuid = config.getUUID(); - params.pnsdk = generatePNSDK(config); - var tokenOrKey = tokenManager.getToken() || config.getAuthKey(); - if (tokenOrKey) { - params.auth = tokenOrKey; - } - if (config.secretKey) { - signRequest(modules, url, params, {}, { - getOperation: function () { return 'PubNubGetFileUrlOperation'; }, - }); - } - var queryParams = Object.keys(params) - .map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(params[key])); }) - .join('&'); - if (queryParams !== '') { - return "".concat(networking.getStandardOrigin()).concat(url, "?").concat(queryParams); - } - return "".concat(networking.getStandardOrigin()).concat(url); - }); - - // Download_file.js - var endpoint$g = { - getOperation: function () { return OPERATIONS.PNDownloadFileOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return "channel can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.name)) { - return "name can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.id)) { - return "id can't be empty"; - } - }, - useGetFile: function () { return true; }, - getFileURL: function (_a, params) { - var config = _a.config; - return "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(params.channel), "/files/").concat(params.id, "/").concat(params.name); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - ignoreBody: function () { return true; }, - forceBuffered: function () { return true; }, - prepareParams: function () { return ({}); }, - handleResponse: function (_a, res, params) { - var PubNubFile = _a.PubNubFile, config = _a.config, cryptography = _a.cryptography, cryptoModule = _a.cryptoModule; - return __awaiter(void 0, void 0, void 0, function () { - var body, _b; - var _c, _d; - return __generator(this, function (_e) { - switch (_e.label) { - case 0: - body = res.response.body; - if (!(PubNubFile.supportsEncryptFile && (params.cipherKey || cryptoModule))) return [3 /*break*/, 5]; - if (!(params.cipherKey == null)) return [3 /*break*/, 2]; - return [4 /*yield*/, cryptoModule.decryptFile(PubNubFile.create({ data: body, name: params.name }), PubNubFile)]; - case 1: - _b = (_e.sent()).data; - return [3 /*break*/, 4]; - case 2: return [4 /*yield*/, cryptography.decrypt((_c = params.cipherKey) !== null && _c !== void 0 ? _c : config.cipherKey, body)]; - case 3: - _b = _e.sent(); - _e.label = 4; - case 4: - body = _b; - _e.label = 5; - case 5: return [2 /*return*/, PubNubFile.create({ - data: body, - name: (_d = res.response.name) !== null && _d !== void 0 ? _d : params.name, - mimeType: res.response.type, - })]; - } - }); - }); - }, - }; - - /** */ - var endpoint$f = { - getOperation: function () { return OPERATIONS.PNListFilesOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return "channel can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.id)) { - return "file id can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.name)) { - return "file name can't be empty"; - } - }, - useDelete: function () { return true; }, - getURL: function (_a, params) { - var config = _a.config; - return "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(params.channel), "/files/").concat(params.id, "/").concat(params.name); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function () { return ({}); }, - handleResponse: function (_, response) { return ({ - status: response.status, - }); }, - }; - - var endpoint$e = { - getOperation: function () { return OPERATIONS.PNGetAllUUIDMetadataOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var queryParams = {}; - queryParams.include = ['status', 'type']; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) { - queryParams.include.push('custom'); - } - } - queryParams.include = queryParams.include.join(','); - if ((_b = params === null || params === void 0 ? void 0 : params.include) === null || _b === void 0 ? void 0 : _b.totalCount) { - queryParams.count = (_c = params.include) === null || _c === void 0 ? void 0 : _c.totalCount; - } - if ((_d = params === null || params === void 0 ? void 0 : params.page) === null || _d === void 0 ? void 0 : _d.next) { - queryParams.start = (_e = params.page) === null || _e === void 0 ? void 0 : _e.next; - } - if ((_f = params === null || params === void 0 ? void 0 : params.page) === null || _f === void 0 ? void 0 : _f.prev) { - queryParams.end = (_g = params.page) === null || _g === void 0 ? void 0 : _g.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - queryParams.limit = (_h = params === null || params === void 0 ? void 0 : params.limit) !== null && _h !== void 0 ? _h : 100; - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - next: response.next, - prev: response.prev, - }); }, - }; - - /** */ - var endpoint$d = { - getOperation: function () { return OPERATIONS.PNGetUUIDMetadataOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils$5.encodeString((_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID())); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_a, params) { - var _b, _c; - var config = _a.config; - var queryParams = {}; - queryParams.uuid = (_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID(); - queryParams.include = ['status', 'type', 'custom']; - if (params === null || params === void 0 ? void 0 : params.include) { - if (((_c = params.include) === null || _c === void 0 ? void 0 : _c.customFields) === false) { - queryParams.include.pop(); - } - } - queryParams.include = queryParams.include.join(','); - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, - }; - - /** */ - var endpoint$c = { - getOperation: function () { return OPERATIONS.PNSetUUIDMetadataOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.data)) { - return 'Data cannot be empty'; - } - }, - usePatch: function () { return true; }, - patchURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils$5.encodeString((_b = params.uuid) !== null && _b !== void 0 ? _b : config.getUUID())); - }, - patchPayload: function (_, params) { return params.data; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_a, params) { - var _b, _c; - var config = _a.config; - var queryParams = {}; - queryParams.uuid = (_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID(); - queryParams.include = ['status', 'type', 'custom']; - if (params === null || params === void 0 ? void 0 : params.include) { - if (((_c = params.include) === null || _c === void 0 ? void 0 : _c.customFields) === false) { - queryParams.include.pop(); - } - } - queryParams.include = queryParams.include.join(','); - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, - }; - - /** */ - var endpoint$b = { - getOperation: function () { return OPERATIONS.PNRemoveUUIDMetadataOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils$5.encodeString((_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID())); - }, - useDelete: function () { return true; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_a, params) { - var _b; - var config = _a.config; - return ({ - uuid: (_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID(), - }); - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, - }; - - var endpoint$a = { - getOperation: function () { return OPERATIONS.PNGetAllChannelMetadataOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var queryParams = {}; - queryParams.include = ['status', 'type']; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) { - queryParams.include.push('custom'); - } - } - queryParams.include = queryParams.include.join(','); - if ((_b = params === null || params === void 0 ? void 0 : params.include) === null || _b === void 0 ? void 0 : _b.totalCount) { - queryParams.count = (_c = params.include) === null || _c === void 0 ? void 0 : _c.totalCount; - } - if ((_d = params === null || params === void 0 ? void 0 : params.page) === null || _d === void 0 ? void 0 : _d.next) { - queryParams.start = (_e = params.page) === null || _e === void 0 ? void 0 : _e.next; - } - if ((_f = params === null || params === void 0 ? void 0 : params.page) === null || _f === void 0 ? void 0 : _f.prev) { - queryParams.end = (_g = params.page) === null || _g === void 0 ? void 0 : _g.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - queryParams.limit = (_h = params === null || params === void 0 ? void 0 : params.limit) !== null && _h !== void 0 ? _h : 100; - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, - }; - - var endpoint$9 = { - getOperation: function () { return OPERATIONS.PNGetChannelMetadataOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return 'Channel cannot be empty'; - } - }, - getURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(params.channel)); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var _a; - var queryParams = {}; - queryParams.include = ['status', 'type', 'custom']; - if (params === null || params === void 0 ? void 0 : params.include) { - if (((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) === false) { - queryParams.include.pop(); - } - } - queryParams.include = queryParams.include.join(','); - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, - }; - - /** */ - var endpoint$8 = { - getOperation: function () { return OPERATIONS.PNSetChannelMetadataOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return 'Channel cannot be empty'; - } - if (!(params === null || params === void 0 ? void 0 : params.data)) { - return 'Data cannot be empty'; - } - }, - usePatch: function () { return true; }, - patchURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(params.channel)); - }, - patchPayload: function (_, params) { return params.data; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var _a; - var queryParams = {}; - queryParams.include = ['status', 'type', 'custom']; - if (params === null || params === void 0 ? void 0 : params.include) { - if (((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) === false) { - queryParams.include.pop(); - } - } - queryParams.include = queryParams.include.join(','); - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, - }; - - /** */ - var endpoint$7 = { - getOperation: function () { return OPERATIONS.PNRemoveChannelMetadataOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return 'Channel cannot be empty'; - } - }, - getURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(params.channel)); - }, - useDelete: function () { return true; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function () { return ({}); }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, - }; - - /** */ - var endpoint$6 = { - getOperation: function () { return OPERATIONS.PNGetMembersOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return 'channel cannot be empty'; - } - }, - getURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(params.channel), "/uuids"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; - var queryParams = {}; - queryParams.include = []; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.statusField) { - queryParams.include.push('status'); - } - if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customFields) { - queryParams.include.push('custom'); - } - if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.UUIDFields) { - queryParams.include.push('uuid'); - } - if ((_d = params.include) === null || _d === void 0 ? void 0 : _d.customUUIDFields) { - queryParams.include.push('uuid.custom'); - } - if ((_e = params.include) === null || _e === void 0 ? void 0 : _e.UUIDStatusField) { - queryParams.include.push('uuid.status'); - } - if ((_f = params.include) === null || _f === void 0 ? void 0 : _f.UUIDTypeField) { - queryParams.include.push('uuid.type'); - } - } - queryParams.include = queryParams.include.join(','); - if ((_g = params === null || params === void 0 ? void 0 : params.include) === null || _g === void 0 ? void 0 : _g.totalCount) { - queryParams.count = (_h = params.include) === null || _h === void 0 ? void 0 : _h.totalCount; - } - if ((_j = params === null || params === void 0 ? void 0 : params.page) === null || _j === void 0 ? void 0 : _j.next) { - queryParams.start = (_k = params.page) === null || _k === void 0 ? void 0 : _k.next; - } - if ((_l = params === null || params === void 0 ? void 0 : params.page) === null || _l === void 0 ? void 0 : _l.prev) { - queryParams.end = (_m = params.page) === null || _m === void 0 ? void 0 : _m.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - queryParams.limit = (_o = params === null || params === void 0 ? void 0 : params.limit) !== null && _o !== void 0 ? _o : 100; - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_p = params.sort) !== null && _p !== void 0 ? _p : {}).map(function (_a) { - var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, - }; - - var endpoint$5 = { - getOperation: function () { return OPERATIONS.PNSetMembersOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return 'Channel cannot be empty'; - } - if (!(params === null || params === void 0 ? void 0 : params.uuids) || (params === null || params === void 0 ? void 0 : params.uuids.length) === 0) { - return 'UUIDs cannot be empty'; - } - }, - usePatch: function () { return true; }, - patchURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils$5.encodeString(params.channel), "/uuids"); - }, - patchPayload: function (_, params) { - var _a; - return (_a = { - set: [], - delete: [] - }, - _a[params.type] = params.uuids.map(function (uuid) { - if (typeof uuid === 'string') { - return { - uuid: { - id: uuid, - }, - }; - } - return { - uuid: { id: uuid.id }, - custom: uuid.custom, - status: uuid.status, - }; - }), - _a); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var queryParams = {}; - queryParams.include = ['uuid.status', 'uuid.type', 'type']; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) { - queryParams.include.push('custom'); - } - if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customUUIDFields) { - queryParams.include.push('uuid.custom'); - } - if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.UUIDFields) { - queryParams.include.push('uuid'); - } - } - queryParams.include = queryParams.include.join(','); - if ((_d = params === null || params === void 0 ? void 0 : params.include) === null || _d === void 0 ? void 0 : _d.totalCount) { - queryParams.count = true; - } - if ((_e = params === null || params === void 0 ? void 0 : params.page) === null || _e === void 0 ? void 0 : _e.next) { - queryParams.start = (_f = params.page) === null || _f === void 0 ? void 0 : _f.next; - } - if ((_g = params === null || params === void 0 ? void 0 : params.page) === null || _g === void 0 ? void 0 : _g.prev) { - queryParams.end = (_h = params.page) === null || _h === void 0 ? void 0 : _h.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - if (params.limit != null) { - queryParams.limit = params.limit; - } - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, - }; - - var endpoint$4 = { - getOperation: function () { return OPERATIONS.PNGetMembershipsOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils$5.encodeString((_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID()), "/channels"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; - var queryParams = {}; - queryParams.include = []; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.statusField) { - queryParams.include.push('status'); - } - if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customFields) { - queryParams.include.push('custom'); - } - if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.channelFields) { - queryParams.include.push('channel'); - } - if ((_d = params.include) === null || _d === void 0 ? void 0 : _d.customChannelFields) { - queryParams.include.push('channel.custom'); - } - if ((_e = params.include) === null || _e === void 0 ? void 0 : _e.channelStatusField) { - queryParams.include.push('channel.status'); - } - if ((_f = params.include) === null || _f === void 0 ? void 0 : _f.channelTypeField) { - queryParams.include.push('channel.type'); - } - } - queryParams.include = queryParams.include.join(','); - if ((_g = params === null || params === void 0 ? void 0 : params.include) === null || _g === void 0 ? void 0 : _g.totalCount) { - queryParams.count = (_h = params.include) === null || _h === void 0 ? void 0 : _h.totalCount; - } - if ((_j = params === null || params === void 0 ? void 0 : params.page) === null || _j === void 0 ? void 0 : _j.next) { - queryParams.start = (_k = params.page) === null || _k === void 0 ? void 0 : _k.next; - } - if ((_l = params === null || params === void 0 ? void 0 : params.page) === null || _l === void 0 ? void 0 : _l.prev) { - queryParams.end = (_m = params.page) === null || _m === void 0 ? void 0 : _m.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - queryParams.limit = (_o = params === null || params === void 0 ? void 0 : params.limit) !== null && _o !== void 0 ? _o : 100; - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_p = params.sort) !== null && _p !== void 0 ? _p : {}).map(function (_a) { - var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, - }; - - /** */ - var endpoint$3 = { - getOperation: function () { return OPERATIONS.PNSetMembershipsOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channels) || (params === null || params === void 0 ? void 0 : params.channels.length) === 0) { - return 'Channels cannot be empty'; - } - }, - usePatch: function () { return true; }, - patchURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils$5.encodeString((_b = params.uuid) !== null && _b !== void 0 ? _b : config.getUUID()), "/channels"); - }, - patchPayload: function (_, params) { - var _a; - return (_a = { - set: [], - delete: [] - }, - _a[params.type] = params.channels.map(function (channel) { - if (typeof channel === 'string') { - return { - channel: { - id: channel, - }, - }; - } - return { - channel: { id: channel.id }, - custom: channel.custom, - status: channel.status, - }; - }), - _a); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var queryParams = {}; - queryParams.include = ['channel.status', 'channel.type', 'status']; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) { - queryParams.include.push('custom'); - } - if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customChannelFields) { - queryParams.include.push('channel.custom'); - } - if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.channelFields) { - queryParams.include.push('channel'); - } - } - queryParams.include = queryParams.include.join(','); - if ((_d = params === null || params === void 0 ? void 0 : params.include) === null || _d === void 0 ? void 0 : _d.totalCount) { - queryParams.count = true; - } - if ((_e = params === null || params === void 0 ? void 0 : params.page) === null || _e === void 0 ? void 0 : _e.next) { - queryParams.start = (_f = params.page) === null || _f === void 0 ? void 0 : _f.next; - } - if ((_g = params === null || params === void 0 ? void 0 : params.page) === null || _g === void 0 ? void 0 : _g.prev) { - queryParams.end = (_h = params.page) === null || _h === void 0 ? void 0 : _h.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - if (params.limit != null) { - queryParams.limit = params.limit; - } - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read$1(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, - }; - - /* */ - function getOperation$a() { - return OPERATIONS.PNAccessManagerAudit; - } - function validateParams$a(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$9(modules) { - var config = modules.config; - return "/v2/auth/audit/sub-key/".concat(config.subscribeKey); - } - function getRequestTimeout$a(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$a() { - return false; - } - function prepareParams$a(modules, incomingParams) { - var channel = incomingParams.channel, channelGroup = incomingParams.channelGroup, _a = incomingParams.authKeys, authKeys = _a === void 0 ? [] : _a; - var params = {}; - if (channel) { - params.channel = channel; - } - if (channelGroup) { - params['channel-group'] = channelGroup; - } - if (authKeys.length > 0) { - params.auth = authKeys.join(','); - } - return params; - } - function handleResponse$a(modules, serverResponse) { - return serverResponse.payload; - } - - var auditEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$a, - validateParams: validateParams$a, - getURL: getURL$9, - getRequestTimeout: getRequestTimeout$a, - isAuthSupported: isAuthSupported$a, - prepareParams: prepareParams$a, - handleResponse: handleResponse$a - }); - - /* */ - function getOperation$9() { - return OPERATIONS.PNAccessManagerGrant; - } - function validateParams$9(modules, incomingParams) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!config.publishKey) - return 'Missing Publish Key'; - if (!config.secretKey) - return 'Missing Secret Key'; - if (incomingParams.uuids != null && !incomingParams.authKeys) { - return 'authKeys are required for grant request on uuids'; - } - if (incomingParams.uuids != null && (incomingParams.channels != null || incomingParams.channelGroups != null)) { - return 'Both channel/channelgroup and uuid cannot be used in the same request'; - } - } - function getURL$8(modules) { - var config = modules.config; - return "/v2/auth/grant/sub-key/".concat(config.subscribeKey); - } - function getRequestTimeout$9(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$9() { - return false; - } - function prepareParams$9(modules, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b, _c = incomingParams.uuids, uuids = _c === void 0 ? [] : _c, ttl = incomingParams.ttl, _d = incomingParams.read, read = _d === void 0 ? false : _d, _e = incomingParams.write, write = _e === void 0 ? false : _e, _f = incomingParams.manage, manage = _f === void 0 ? false : _f, _g = incomingParams.get, get = _g === void 0 ? false : _g, _h = incomingParams.join, join = _h === void 0 ? false : _h, _j = incomingParams.update, update = _j === void 0 ? false : _j, _k = incomingParams.authKeys, authKeys = _k === void 0 ? [] : _k; - var deleteParam = incomingParams.delete; - var params = {}; - params.r = read ? '1' : '0'; - params.w = write ? '1' : '0'; - params.m = manage ? '1' : '0'; - params.d = deleteParam ? '1' : '0'; - params.g = get ? '1' : '0'; - params.j = join ? '1' : '0'; - params.u = update ? '1' : '0'; - if (channels.length > 0) { - params.channel = channels.join(','); - } - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - if (authKeys.length > 0) { - params.auth = authKeys.join(','); - } - if (uuids.length > 0) { - params['target-uuid'] = uuids.join(','); - } - if (ttl || ttl === 0) { - params.ttl = ttl; - } - return params; - } - function handleResponse$9() { - return {}; - } - - var grantEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$9, - validateParams: validateParams$9, - getURL: getURL$8, - getRequestTimeout: getRequestTimeout$9, - isAuthSupported: isAuthSupported$9, - prepareParams: prepareParams$9, - handleResponse: handleResponse$9 - }); - - function getOperation$8() { - return OPERATIONS.PNAccessManagerGrantToken; - } - function hasVspTerms(incomingParams) { - var _a, _b, _c, _d; - var hasAuthorizedUserId = (incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.authorizedUserId) !== undefined; - var hasUserResources = ((_a = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _a === void 0 ? void 0 : _a.users) !== undefined; - var hasSpaceResources = ((_b = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _b === void 0 ? void 0 : _b.spaces) !== undefined; - var hasUserPatterns = ((_c = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _c === void 0 ? void 0 : _c.users) !== undefined; - var hasSpacePatterns = ((_d = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _d === void 0 ? void 0 : _d.spaces) !== undefined; - return hasUserPatterns || hasUserResources || hasSpacePatterns || hasSpaceResources || hasAuthorizedUserId; - } - function extractPermissions(permissions) { - var permissionsResult = 0; - if (permissions.join) { - permissionsResult |= 128; - } - if (permissions.update) { - permissionsResult |= 64; - } - if (permissions.get) { - permissionsResult |= 32; - } - if (permissions.delete) { - permissionsResult |= 8; - } - if (permissions.manage) { - permissionsResult |= 4; - } - if (permissions.write) { - permissionsResult |= 2; - } - if (permissions.read) { - permissionsResult |= 1; - } - return permissionsResult; - } - function prepareMessagePayloadVsp(_modules, _a) { - var ttl = _a.ttl, resources = _a.resources, patterns = _a.patterns, meta = _a.meta, authorizedUserId = _a.authorizedUserId; - var params = { - ttl: 0, - permissions: { - resources: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, - spaces: {}, // not used, needed for api backward compatibility - }, - patterns: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, - spaces: {}, // not used, needed for api backward compatibility - }, - meta: {}, - }, - }; - if (resources) { - var users_1 = resources.users, spaces_1 = resources.spaces, groups_1 = resources.groups; - if (users_1) { - Object.keys(users_1).forEach(function (userID) { - params.permissions.resources.uuids[userID] = extractPermissions(users_1[userID]); - }); - } - if (spaces_1) { - Object.keys(spaces_1).forEach(function (spaceId) { - params.permissions.resources.channels[spaceId] = extractPermissions(spaces_1[spaceId]); - }); - } - if (groups_1) { - Object.keys(groups_1).forEach(function (group) { - params.permissions.resources.groups[group] = extractPermissions(groups_1[group]); - }); - } - } - if (patterns) { - var users_2 = patterns.users, spaces_2 = patterns.spaces, groups_2 = patterns.groups; - if (users_2) { - Object.keys(users_2).forEach(function (userId) { - params.permissions.patterns.uuids[userId] = extractPermissions(users_2[userId]); - }); - } - if (spaces_2) { - Object.keys(spaces_2).forEach(function (spaceId) { - params.permissions.patterns.channels[spaceId] = extractPermissions(spaces_2[spaceId]); - }); - } - if (groups_2) { - Object.keys(groups_2).forEach(function (group) { - params.permissions.patterns.groups[group] = extractPermissions(groups_2[group]); - }); - } - } - if (ttl || ttl === 0) { - params.ttl = ttl; - } - if (meta) { - params.permissions.meta = meta; - } - if (authorizedUserId) { - params.permissions.uuid = "".concat(authorizedUserId); // ensure this is a string - } - return params; - } - function prepareMessagePayload$2(_modules, incomingParams) { - if (hasVspTerms(incomingParams)) { - return prepareMessagePayloadVsp(_modules, incomingParams); - } - var ttl = incomingParams.ttl, resources = incomingParams.resources, patterns = incomingParams.patterns, meta = incomingParams.meta, authorized_uuid = incomingParams.authorized_uuid; - var params = { - ttl: 0, - permissions: { - resources: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, - spaces: {}, // not used, needed for api backward compatibility - }, - patterns: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, - spaces: {}, // not used, needed for api backward compatibility - }, - meta: {}, - }, - }; - if (resources) { - var uuids_1 = resources.uuids, channels_1 = resources.channels, groups_3 = resources.groups; - if (uuids_1) { - Object.keys(uuids_1).forEach(function (uuid) { - params.permissions.resources.uuids[uuid] = extractPermissions(uuids_1[uuid]); - }); - } - if (channels_1) { - Object.keys(channels_1).forEach(function (channel) { - params.permissions.resources.channels[channel] = extractPermissions(channels_1[channel]); - }); - } - if (groups_3) { - Object.keys(groups_3).forEach(function (group) { - params.permissions.resources.groups[group] = extractPermissions(groups_3[group]); - }); - } - } - if (patterns) { - var uuids_2 = patterns.uuids, channels_2 = patterns.channels, groups_4 = patterns.groups; - if (uuids_2) { - Object.keys(uuids_2).forEach(function (uuid) { - params.permissions.patterns.uuids[uuid] = extractPermissions(uuids_2[uuid]); - }); - } - if (channels_2) { - Object.keys(channels_2).forEach(function (channel) { - params.permissions.patterns.channels[channel] = extractPermissions(channels_2[channel]); - }); - } - if (groups_4) { - Object.keys(groups_4).forEach(function (group) { - params.permissions.patterns.groups[group] = extractPermissions(groups_4[group]); - }); - } - } - if (ttl || ttl === 0) { - params.ttl = ttl; - } - if (meta) { - params.permissions.meta = meta; - } - if (authorized_uuid) { - params.permissions.uuid = "".concat(authorized_uuid); // ensure this is a string - } - return params; - } - function validateParams$8(modules, incomingParams) { - var _a, _b, _c, _d, _e, _f; - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!config.publishKey) - return 'Missing Publish Key'; - if (!config.secretKey) - return 'Missing Secret Key'; - if (!incomingParams.resources && !incomingParams.patterns) - return 'Missing either Resources or Patterns.'; - var hasAuthorizedUuid = (incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.authorized_uuid) !== undefined; - var hasUuidResources = ((_a = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _a === void 0 ? void 0 : _a.uuids) !== undefined; - var hasChannelResources = ((_b = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _b === void 0 ? void 0 : _b.channels) !== undefined; - var hasGroupResources = ((_c = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _c === void 0 ? void 0 : _c.groups) !== undefined; - var hasUuidPatterns = ((_d = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _d === void 0 ? void 0 : _d.uuids) !== undefined; - var hasChannelPatterns = ((_e = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _e === void 0 ? void 0 : _e.channels) !== undefined; - var hasGroupPatterns = ((_f = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _f === void 0 ? void 0 : _f.groups) !== undefined; - var hasLegacyTerms = hasAuthorizedUuid || - hasUuidResources || - hasUuidPatterns || - hasChannelResources || - hasChannelPatterns || - hasGroupResources || - hasGroupPatterns; - if (hasVspTerms(incomingParams) && hasLegacyTerms) { - return ('Cannot mix `users`, `spaces` and `authorizedUserId` ' + - 'with `uuids`, `channels`, `groups` and `authorized_uuid`'); - } - if ((incomingParams.resources && - (!incomingParams.resources.uuids || Object.keys(incomingParams.resources.uuids).length === 0) && - (!incomingParams.resources.channels || Object.keys(incomingParams.resources.channels).length === 0) && - (!incomingParams.resources.groups || Object.keys(incomingParams.resources.groups).length === 0) && - (!incomingParams.resources.users || Object.keys(incomingParams.resources.users).length === 0) && - (!incomingParams.resources.spaces || Object.keys(incomingParams.resources.spaces).length === 0)) || - (incomingParams.patterns && - (!incomingParams.patterns.uuids || Object.keys(incomingParams.patterns.uuids).length === 0) && - (!incomingParams.patterns.channels || Object.keys(incomingParams.patterns.channels).length === 0) && - (!incomingParams.patterns.groups || Object.keys(incomingParams.patterns.groups).length === 0) && - (!incomingParams.patterns.users || Object.keys(incomingParams.patterns.users).length === 0) && - (!incomingParams.patterns.spaces || Object.keys(incomingParams.patterns.spaces).length === 0))) { - return 'Missing values for either Resources or Patterns.'; - } - } - function postURL$1(modules) { - var config = modules.config; - return "/v3/pam/".concat(config.subscribeKey, "/grant"); - } - function usePost$1() { - return true; - } - function getRequestTimeout$8(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$8() { - return false; - } - function prepareParams$8() { - return {}; - } - function postPayload$1(modules, incomingParams) { - return prepareMessagePayload$2(modules, incomingParams); - } - function handleResponse$8(modules, response) { - var token = response.data.token; - return token; - } - - var grantTokenEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$8, - extractPermissions: extractPermissions, - validateParams: validateParams$8, - postURL: postURL$1, - usePost: usePost$1, - getRequestTimeout: getRequestTimeout$8, - isAuthSupported: isAuthSupported$8, - prepareParams: prepareParams$8, - postPayload: postPayload$1, - handleResponse: handleResponse$8 - }); - - /** */ - var endpoint$2 = { - getOperation: function () { return OPERATIONS.PNAccessManagerRevokeToken; }, - validateParams: function (modules, token) { - var secretKey = modules.config.secretKey; - if (!secretKey) { - return 'Missing Secret Key'; - } - if (!token) { - return "token can't be empty"; - } - }, - getURL: function (_a, token) { - var config = _a.config; - return "/v3/pam/".concat(config.subscribeKey, "/grant/").concat(utils$5.encodeString(token)); - }, - useDelete: function () { return true; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return false; }, - prepareParams: function (_a) { - var config = _a.config; - return ({ - uuid: config.getUUID(), - }); - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, - }; - - /* */ - function prepareMessagePayload$1(modules, messagePayload) { - var stringifiedPayload = JSON.stringify(messagePayload); - if (modules.cryptoModule) { - var encrypted = modules.cryptoModule.encrypt(stringifiedPayload); - stringifiedPayload = typeof encrypted === 'string' ? encrypted : encode$1(encrypted); - stringifiedPayload = JSON.stringify(stringifiedPayload); - } - return stringifiedPayload || ''; - } - function getOperation$7() { - return OPERATIONS.PNPublishOperation; - } - function validateParams$7(_a, incomingParams) { - var config = _a.config; - var message = incomingParams.message, channel = incomingParams.channel; - if (!channel) - return 'Missing Channel'; - if (!message) - return 'Missing Message'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function usePost(modules, incomingParams) { - var _a = incomingParams.sendByPost, sendByPost = _a === void 0 ? false : _a; - return sendByPost; - } - function getURL$7(modules, incomingParams) { - var config = modules.config; - var channel = incomingParams.channel, message = incomingParams.message; - var stringifiedPayload = prepareMessagePayload$1(modules, message); - return "/publish/".concat(config.publishKey, "/").concat(config.subscribeKey, "/0/").concat(utils$5.encodeString(channel), "/0/").concat(utils$5.encodeString(stringifiedPayload)); - } - function postURL(modules, incomingParams) { - var config = modules.config; - var channel = incomingParams.channel; - return "/publish/".concat(config.publishKey, "/").concat(config.subscribeKey, "/0/").concat(utils$5.encodeString(channel), "/0"); - } - function getRequestTimeout$7(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$7() { - return true; - } - function postPayload(modules, incomingParams) { - var message = incomingParams.message; - return prepareMessagePayload$1(modules, message); - } - function prepareParams$7(modules, incomingParams) { - var meta = incomingParams.meta, _a = incomingParams.replicate, replicate = _a === void 0 ? true : _a, storeInHistory = incomingParams.storeInHistory, ttl = incomingParams.ttl; - var params = {}; - if (storeInHistory != null) { - if (storeInHistory) { - params.store = '1'; - } - else { - params.store = '0'; - } - } - if (ttl) { - params.ttl = ttl; - } - if (replicate === false) { - params.norep = 'true'; - } - if (meta && typeof meta === 'object') { - params.meta = JSON.stringify(meta); - } - return params; - } - function handleResponse$7(modules, serverResponse) { - return { timetoken: serverResponse[2] }; - } - - var publishEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$7, - validateParams: validateParams$7, - usePost: usePost, - getURL: getURL$7, - postURL: postURL, - getRequestTimeout: getRequestTimeout$7, - isAuthSupported: isAuthSupported$7, - postPayload: postPayload, - prepareParams: prepareParams$7, - handleResponse: handleResponse$7 - }); - - /* */ - function prepareMessagePayload(modules, messagePayload) { - var stringifiedPayload = JSON.stringify(messagePayload); - return stringifiedPayload; - } - function getOperation$6() { - return OPERATIONS.PNSignalOperation; - } - function validateParams$6(_a, incomingParams) { - var config = _a.config; - var message = incomingParams.message, channel = incomingParams.channel; - if (!channel) - return 'Missing Channel'; - if (!message) - return 'Missing Message'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$6(modules, incomingParams) { - var config = modules.config; - var channel = incomingParams.channel, message = incomingParams.message; - var stringifiedPayload = prepareMessagePayload(modules, message); - return "/signal/".concat(config.publishKey, "/").concat(config.subscribeKey, "/0/").concat(utils$5.encodeString(channel), "/0/").concat(utils$5.encodeString(stringifiedPayload)); - } - function getRequestTimeout$6(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$6() { - return true; - } - function prepareParams$6() { - var params = {}; - return params; - } - function handleResponse$6(modules, serverResponse) { - return { timetoken: serverResponse[2] }; - } - - var signalEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$6, - validateParams: validateParams$6, - getURL: getURL$6, - getRequestTimeout: getRequestTimeout$6, - isAuthSupported: isAuthSupported$6, - prepareParams: prepareParams$6, - handleResponse: handleResponse$6 - }); - - /* */ - function __processMessage$1(modules, message) { - var result = {}; - if (!modules.cryptoModule) { - result.payload = message; - return result; - } - try { - var decryptedData = modules.cryptoModule.decrypt(message); - var decryptedPayload = decryptedData instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decryptedData)) : decryptedData; - result.payload = decryptedPayload; - return result; - } - catch (e) { - if (modules.config.logVerbosity && console && console.log) - console.log('decryption error', e.message); - result.payload = message; - result.error = "Error while decrypting message content: ".concat(e.message); - } - return result; - } - function getOperation$5() { - return OPERATIONS.PNHistoryOperation; - } - function validateParams$5(modules, incomingParams) { - var channel = incomingParams.channel; - var config = modules.config; - if (!channel) - return 'Missing channel'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$5(modules, incomingParams) { - var channel = incomingParams.channel; - var config = modules.config; - return "/v2/history/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(channel)); - } - function getRequestTimeout$5(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$5() { - return true; - } - function prepareParams$5(modules, incomingParams) { - var start = incomingParams.start, end = incomingParams.end, reverse = incomingParams.reverse, _a = incomingParams.count, count = _a === void 0 ? 100 : _a, _b = incomingParams.stringifiedTimeToken, stringifiedTimeToken = _b === void 0 ? false : _b, _c = incomingParams.includeMeta, includeMeta = _c === void 0 ? false : _c; - var outgoingParams = { - include_token: 'true', - }; - outgoingParams.count = count; - if (start) - outgoingParams.start = start; - if (end) - outgoingParams.end = end; - if (stringifiedTimeToken) - outgoingParams.string_message_token = 'true'; - if (reverse != null) - outgoingParams.reverse = reverse.toString(); - if (includeMeta) - outgoingParams.include_meta = 'true'; - return outgoingParams; - } - function handleResponse$5(modules, serverResponse) { - var response = { - messages: [], - startTimeToken: serverResponse[1], - endTimeToken: serverResponse[2], - }; - if (Array.isArray(serverResponse[0])) { - serverResponse[0].forEach(function (serverHistoryItem) { - var processedMessgeResult = __processMessage$1(modules, serverHistoryItem.message); - var item = { - timetoken: serverHistoryItem.timetoken, - entry: processedMessgeResult.payload, - }; - if (serverHistoryItem.meta) { - item.meta = serverHistoryItem.meta; - } - if (processedMessgeResult.error) - item.error = processedMessgeResult.error; - response.messages.push(item); - }); - } - return response; - } - - var historyEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$5, - validateParams: validateParams$5, - getURL: getURL$5, - getRequestTimeout: getRequestTimeout$5, - isAuthSupported: isAuthSupported$5, - prepareParams: prepareParams$5, - handleResponse: handleResponse$5 - }); - - /* */ - function getOperation$4() { - return OPERATIONS.PNDeleteMessagesOperation; - } - function validateParams$4(modules, incomingParams) { - var channel = incomingParams.channel; - var config = modules.config; - if (!channel) - return 'Missing channel'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function useDelete() { - return true; - } - function getURL$4(modules, incomingParams) { - var channel = incomingParams.channel; - var config = modules.config; - return "/v3/history/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(channel)); - } - function getRequestTimeout$4(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$4() { - return true; - } - function prepareParams$4(modules, incomingParams) { - var start = incomingParams.start, end = incomingParams.end; - var outgoingParams = {}; - if (start) - outgoingParams.start = start; - if (end) - outgoingParams.end = end; - return outgoingParams; - } - function handleResponse$4(modules, serverResponse) { - return serverResponse.payload; - } - - var deleteMessagesEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$4, - validateParams: validateParams$4, - useDelete: useDelete, - getURL: getURL$4, - getRequestTimeout: getRequestTimeout$4, - isAuthSupported: isAuthSupported$4, - prepareParams: prepareParams$4, - handleResponse: handleResponse$4 - }); - - function getOperation$3() { - return OPERATIONS.PNMessageCounts; - } - function validateParams$3(modules, incomingParams) { - var channels = incomingParams.channels, timetoken = incomingParams.timetoken, channelTimetokens = incomingParams.channelTimetokens; - var config = modules.config; - if (!channels) - return 'Missing channel'; - if (timetoken && channelTimetokens) - return 'timetoken and channelTimetokens are incompatible together'; - if (channelTimetokens && channelTimetokens.length > 1 && channels.length !== channelTimetokens.length) { - return 'Length of channelTimetokens and channels do not match'; - } - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL$3(modules, incomingParams) { - var channels = incomingParams.channels; - var config = modules.config; - var stringifiedChannels = channels.join(','); - return "/v3/history/sub-key/".concat(config.subscribeKey, "/message-counts/").concat(utils$5.encodeString(stringifiedChannels)); - } - function getRequestTimeout$3(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$3() { - return true; - } - function prepareParams$3(modules, incomingParams) { - var timetoken = incomingParams.timetoken, channelTimetokens = incomingParams.channelTimetokens; - var outgoingParams = {}; - if (channelTimetokens && channelTimetokens.length === 1) { - var _a = __read$1(channelTimetokens, 1), tt = _a[0]; - outgoingParams.timetoken = tt; - } - else if (channelTimetokens) { - outgoingParams.channelsTimetoken = channelTimetokens.join(','); - } - else if (timetoken) { - outgoingParams.timetoken = timetoken; - } - return outgoingParams; - } - function handleResponse$3(modules, serverResponse) { - return { channels: serverResponse.channels }; - } - - var messageCountsEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$3, - validateParams: validateParams$3, - getURL: getURL$3, - getRequestTimeout: getRequestTimeout$3, - isAuthSupported: isAuthSupported$3, - prepareParams: prepareParams$3, - handleResponse: handleResponse$3 - }); - - /* */ - function __processMessage(modules, message) { - var result = {}; - if (!modules.cryptoModule) { - result.payload = message; - return result; - } - try { - var decryptedData = modules.cryptoModule.decrypt(message); - var decryptedPayload = decryptedData instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decryptedData)) : decryptedData; - result.payload = decryptedPayload; - return result; - } - catch (e) { - if (modules.config.logVerbosity && console && console.log) - console.log('decryption error', e.message); - result.payload = message; - result.error = "Error while decrypting message content: ".concat(e.message); - } - return result; - } - function getOperation$2() { - return OPERATIONS.PNFetchMessagesOperation; - } - function validateParams$2(modules, incomingParams) { - var channels = incomingParams.channels, _a = incomingParams.includeMessageActions, includeMessageActions = _a === void 0 ? false : _a; - var config = modules.config; - if (!channels || channels.length === 0) - return 'Missing channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (includeMessageActions && channels.length > 1) { - throw new TypeError('History can return actions data for a single channel only. ' + - 'Either pass a single channel or disable the includeMessageActions flag.'); - } - } - function getURL$2(modules, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.includeMessageActions, includeMessageActions = _b === void 0 ? false : _b; - var config = modules.config; - var endpoint = !includeMessageActions ? 'history' : 'history-with-actions'; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v3/".concat(endpoint, "/sub-key/").concat(config.subscribeKey, "/channel/").concat(utils$5.encodeString(stringifiedChannels)); - } - function getRequestTimeout$2(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function isAuthSupported$2() { - return true; - } - function prepareParams$2(modules, incomingParams) { - var channels = incomingParams.channels, start = incomingParams.start, end = incomingParams.end, includeMessageActions = incomingParams.includeMessageActions, count = incomingParams.count, _a = incomingParams.stringifiedTimeToken, stringifiedTimeToken = _a === void 0 ? false : _a, _b = incomingParams.includeMeta, includeMeta = _b === void 0 ? false : _b, includeUuid = incomingParams.includeUuid, _c = incomingParams.includeUUID, includeUUID = _c === void 0 ? true : _c, _d = incomingParams.includeMessageType, includeMessageType = _d === void 0 ? true : _d; - var outgoingParams = {}; - if (count) { - outgoingParams.max = count; - } - else { - outgoingParams.max = channels.length > 1 || includeMessageActions === true ? 25 : 100; - } - if (start) - outgoingParams.start = start; - if (end) - outgoingParams.end = end; - if (stringifiedTimeToken) - outgoingParams.string_message_token = 'true'; - if (includeMeta) - outgoingParams.include_meta = 'true'; - if (includeUUID && includeUuid !== false) - outgoingParams.include_uuid = 'true'; - if (includeMessageType) - outgoingParams.include_message_type = 'true'; - return outgoingParams; - } - function handleResponse$2(modules, serverResponse) { - var response = { - channels: {}, - }; - Object.keys(serverResponse.channels || {}).forEach(function (channelName) { - response.channels[channelName] = []; - (serverResponse.channels[channelName] || []).forEach(function (messageEnvelope) { - var announce = {}; - var processedMessgeResult = __processMessage(modules, messageEnvelope.message); - announce.channel = channelName; - announce.timetoken = messageEnvelope.timetoken; - announce.message = processedMessgeResult.payload; - announce.messageType = messageEnvelope.message_type; - announce.uuid = messageEnvelope.uuid; - if (messageEnvelope.actions) { - announce.actions = messageEnvelope.actions; - // This should be kept for few updates for existing clients consistency. - announce.data = messageEnvelope.actions; - } - if (messageEnvelope.meta) { - announce.meta = messageEnvelope.meta; - } - if (processedMessgeResult.error) - announce.error = processedMessgeResult.error; - response.channels[channelName].push(announce); - }); - }); - if (serverResponse.more) { - response.more = serverResponse.more; - } - return response; - } - - var fetchMessagesEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$2, - validateParams: validateParams$2, - getURL: getURL$2, - getRequestTimeout: getRequestTimeout$2, - isAuthSupported: isAuthSupported$2, - prepareParams: prepareParams$2, - handleResponse: handleResponse$2 - }); - - /* */ - function getOperation$1() { - return OPERATIONS.PNTimeOperation; - } - function getURL$1() { - return '/time/0'; - } - function getRequestTimeout$1(_a) { - var config = _a.config; - return config.getTransactionTimeout(); - } - function prepareParams$1() { - return {}; - } - function isAuthSupported$1() { - return false; - } - function handleResponse$1(modules, serverResponse) { - return { - timetoken: serverResponse[0], - }; - } - function validateParams$1() { - // pass - } - - var timeEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation$1, - getURL: getURL$1, - getRequestTimeout: getRequestTimeout$1, - prepareParams: prepareParams$1, - isAuthSupported: isAuthSupported$1, - handleResponse: handleResponse$1, - validateParams: validateParams$1 - }); - - /* */ - function getOperation() { - return OPERATIONS.PNSubscribeOperation; - } - function validateParams(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - } - function getURL(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils$5.encodeString(stringifiedChannels), "/0"); - } - function getRequestTimeout(_a) { - var config = _a.config; - return config.getSubscribeTimeout(); - } - function isAuthSupported() { - return true; - } - function prepareParams(_a, incomingParams) { - var config = _a.config; - var state = incomingParams.state, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b, timetoken = incomingParams.timetoken, filterExpression = incomingParams.filterExpression, region = incomingParams.region; - var params = { - heartbeat: config.getPresenceTimeout(), - }; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - if (filterExpression && filterExpression.length > 0) { - params['filter-expr'] = filterExpression; - } - if (Object.keys(state).length) { - params.state = JSON.stringify(state); - } - if (timetoken) { - params.tt = timetoken; - } - if (region) { - params.tr = region; - } - return params; - } - function handleResponse(modules, serverResponse) { - var messages = []; - serverResponse.m.forEach(function (rawMessage) { - var publishMetaData = { - timetoken: rawMessage.p.t, - region: rawMessage.p.r, - }; - var parsedMessage = { - shard: parseInt(rawMessage.a, 10), - subscriptionMatch: rawMessage.b, - channel: rawMessage.c, - messageType: rawMessage.e, - payload: rawMessage.d, - flags: rawMessage.f, - issuingClientId: rawMessage.i, - subscribeKey: rawMessage.k, - originationTimetoken: rawMessage.o, - userMetadata: rawMessage.u, - publishMetaData: publishMetaData, - }; - messages.push(parsedMessage); - }); - var metadata = { - timetoken: serverResponse.t.t, - region: serverResponse.t.r, - }; - return { messages: messages, metadata: metadata }; - } - - var subscribeEndpointConfig = /*#__PURE__*/Object.freeze({ - __proto__: null, - getOperation: getOperation, - validateParams: validateParams, - getURL: getURL, - getRequestTimeout: getRequestTimeout, - isAuthSupported: isAuthSupported, - prepareParams: prepareParams, - handleResponse: handleResponse - }); - - var endpoint$1 = { - getOperation: function () { return OPERATIONS.PNHandshakeOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channels) && !(params === null || params === void 0 ? void 0 : params.channelGroups)) { - return 'channels and channleGroups both should not be empty'; - } - }, - getURL: function (_a, params) { - var config = _a.config; - var _b = params.channels, channels = _b === void 0 ? [] : _b; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils$5.encodeString(stringifiedChannels), "/0"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getSubscribeTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var outParams = {}; - if (params.channelGroups && params.channelGroups.length > 0) { - outParams['channel-group'] = params.channelGroups.join(','); - } - outParams.tt = 0; - if (params.state) { - outParams.state = JSON.stringify(params.state); - } - if (params.filterExpression && params.filterExpression.length > 0) { - outParams['filter-expr'] = params.filterExpression; - } - outParams.ee = ''; - return outParams; - }, - handleResponse: function (_, response) { return ({ - region: response.t.r, - timetoken: response.t.t, - }); }, - }; - - var endpoint = { - getOperation: function () { return OPERATIONS.PNReceiveMessagesOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channels) && !(params === null || params === void 0 ? void 0 : params.channelGroups)) { - return 'channels and channleGroups both should not be empty'; - } - if (!(params === null || params === void 0 ? void 0 : params.timetoken)) { - return 'timetoken can not be empty'; - } - if (!(params === null || params === void 0 ? void 0 : params.region)) { - return 'region can not be empty'; - } - }, - getURL: function (_a, params) { - var config = _a.config; - var _b = params.channels, channels = _b === void 0 ? [] : _b; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils$5.encodeString(stringifiedChannels), "/0"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getSubscribeTimeout(); - }, - isAuthSupported: function () { return true; }, - getAbortSignal: function (_, params) { return params.abortSignal; }, - prepareParams: function (_, params) { - var outParams = {}; - if (params.channelGroups && params.channelGroups.length > 0) { - outParams['channel-group'] = params.channelGroups.join(','); - } - if (params.filterExpression && params.filterExpression.length > 0) { - outParams['filter-expr'] = params.filterExpression; - } - outParams.tt = params.timetoken; - outParams.tr = params.region; - outParams.ee = ''; - return outParams; - }, - handleResponse: function (_, response) { - var parsedMessages = []; - response.m.forEach(function (envelope) { - var parsedMessage = { - shard: parseInt(envelope.a, 10), - subscriptionMatch: envelope.b, - channel: envelope.c, - messageType: envelope.e, - payload: envelope.d, - flags: envelope.f, - issuingClientId: envelope.i, - subscribeKey: envelope.k, - originationTimetoken: envelope.o, - userMetadata: envelope.u, - publishMetaData: { - timetoken: envelope.p.t, - region: envelope.p.r, - }, - }; - parsedMessages.push(parsedMessage); - }); - return { - messages: parsedMessages, - metadata: { - region: response.t.r, - timetoken: response.t.t, - }, - }; - }, - }; - - var Subject = /** @class */ (function () { - function Subject(sync) { - if (sync === void 0) { sync = false; } - this.sync = sync; - this.listeners = new Set(); - } - Subject.prototype.subscribe = function (listener) { - var _this = this; - this.listeners.add(listener); - return function () { - _this.listeners.delete(listener); - }; - }; - Subject.prototype.notify = function (event) { - var _this = this; - var wrapper = function () { - _this.listeners.forEach(function (listener) { - listener(event); - }); - }; - if (this.sync) { - wrapper(); - } - else { - setTimeout(wrapper, 0); - } - }; - return Subject; - }()); - - /* eslint-disable @typescript-eslint/no-explicit-any */ - var State = /** @class */ (function () { - function State(label) { - this.label = label; - this.transitionMap = new Map(); - this.enterEffects = []; - this.exitEffects = []; - } - State.prototype.transition = function (context, event) { - var _a; - if (this.transitionMap.has(event.type)) { - return (_a = this.transitionMap.get(event.type)) === null || _a === void 0 ? void 0 : _a(context, event); - } - return undefined; - }; - State.prototype.on = function (eventType, transition) { - this.transitionMap.set(eventType, transition); - return this; - }; - State.prototype.with = function (context, effects) { - return [this, context, effects !== null && effects !== void 0 ? effects : []]; - }; - State.prototype.onEnter = function (effect) { - this.enterEffects.push(effect); - return this; - }; - State.prototype.onExit = function (effect) { - this.exitEffects.push(effect); - return this; - }; - return State; - }()); - - /* eslint-disable @typescript-eslint/no-explicit-any */ - var Engine = /** @class */ (function (_super) { - __extends(Engine, _super); - function Engine() { - return _super !== null && _super.apply(this, arguments) || this; - } - Engine.prototype.describe = function (label) { - return new State(label); - }; - Engine.prototype.start = function (initialState, initialContext) { - this.currentState = initialState; - this.currentContext = initialContext; - this.notify({ - type: 'engineStarted', - state: initialState, - context: initialContext, - }); - return; - }; - Engine.prototype.transition = function (event) { - var e_1, _a, e_2, _b, e_3, _c; - if (!this.currentState) { - throw new Error('Start the engine first'); - } - this.notify({ - type: 'eventReceived', - event: event, - }); - var transition = this.currentState.transition(this.currentContext, event); - if (transition) { - var _d = __read$1(transition, 3), newState = _d[0], newContext = _d[1], effects = _d[2]; - try { - for (var _e = __values(this.currentState.exitEffects), _f = _e.next(); !_f.done; _f = _e.next()) { - var effect = _f.value; - this.notify({ - type: 'invocationDispatched', - invocation: effect(this.currentContext), - }); - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (_f && !_f.done && (_a = _e.return)) _a.call(_e); - } - finally { if (e_1) throw e_1.error; } - } - var oldState = this.currentState; - this.currentState = newState; - var oldContext = this.currentContext; - this.currentContext = newContext; - this.notify({ - type: 'transitionDone', - fromState: oldState, - fromContext: oldContext, - toState: newState, - toContext: newContext, - event: event, - }); - try { - for (var effects_1 = __values(effects), effects_1_1 = effects_1.next(); !effects_1_1.done; effects_1_1 = effects_1.next()) { - var effect = effects_1_1.value; - this.notify({ - type: 'invocationDispatched', - invocation: effect, - }); - } - } - catch (e_2_1) { e_2 = { error: e_2_1 }; } - finally { - try { - if (effects_1_1 && !effects_1_1.done && (_b = effects_1.return)) _b.call(effects_1); - } - finally { if (e_2) throw e_2.error; } - } - try { - for (var _g = __values(this.currentState.enterEffects), _h = _g.next(); !_h.done; _h = _g.next()) { - var effect = _h.value; - this.notify({ - type: 'invocationDispatched', - invocation: effect(this.currentContext), - }); - } - } - catch (e_3_1) { e_3 = { error: e_3_1 }; } - finally { - try { - if (_h && !_h.done && (_c = _g.return)) _c.call(_g); - } - finally { if (e_3) throw e_3.error; } - } - } - }; - return Engine; - }(Subject)); - - /* eslint-disable @typescript-eslint/no-explicit-any */ - var Dispatcher = /** @class */ (function () { - function Dispatcher(dependencies) { - this.dependencies = dependencies; - this.instances = new Map(); - this.handlers = new Map(); - } - Dispatcher.prototype.on = function (type, handlerCreator) { - this.handlers.set(type, handlerCreator); - }; - Dispatcher.prototype.dispatch = function (invocation) { - if (invocation.type === 'CANCEL') { - if (this.instances.has(invocation.payload)) { - var instance_1 = this.instances.get(invocation.payload); - instance_1 === null || instance_1 === void 0 ? void 0 : instance_1.cancel(); - this.instances.delete(invocation.payload); - } - return; - } - var handlerCreator = this.handlers.get(invocation.type); - if (!handlerCreator) { - throw new Error("Unhandled invocation '".concat(invocation.type, "'")); - } - var instance = handlerCreator(invocation.payload, this.dependencies); - if (invocation.managed) { - this.instances.set(invocation.type, instance); - } - instance.start(); - }; - Dispatcher.prototype.dispose = function () { - var e_1, _a; - try { - for (var _b = __values(this.instances.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { - var _d = __read$1(_c.value, 2), key = _d[0], instance = _d[1]; - instance.cancel(); - this.instances.delete(key); - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (_c && !_c.done && (_a = _b.return)) _a.call(_b); - } - finally { if (e_1) throw e_1.error; } - } - }; - return Dispatcher; - }()); - - /* eslint-disable @typescript-eslint/no-explicit-any */ - function createEvent(type, fn) { - var creator = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return { - type: type, - payload: fn === null || fn === void 0 ? void 0 : fn.apply(void 0, __spreadArray$1([], __read$1(args), false)), - }; - }; - creator.type = type; - return creator; - } - function createEffect(type, fn) { - var creator = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return { type: type, payload: fn.apply(void 0, __spreadArray$1([], __read$1(args), false)), managed: false }; - }; - creator.type = type; - return creator; - } - function createManagedEffect(type, fn) { - var creator = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return { type: type, payload: fn.apply(void 0, __spreadArray$1([], __read$1(args), false)), managed: true }; - }; - creator.type = type; - creator.cancel = { type: 'CANCEL', payload: type, managed: false }; - return creator; - } - - var AbortError = /** @class */ (function (_super) { - __extends(AbortError, _super); - function AbortError() { - var _newTarget = this.constructor; - var _this = _super.call(this, 'The operation was aborted.') || this; - _this.name = 'AbortError'; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return AbortError; - }(Error)); - var AbortSignal = /** @class */ (function (_super) { - __extends(AbortSignal, _super); - function AbortSignal() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this._aborted = false; - return _this; - } - Object.defineProperty(AbortSignal.prototype, "aborted", { - get: function () { - return this._aborted; - }, - enumerable: false, - configurable: true - }); - AbortSignal.prototype.throwIfAborted = function () { - if (this._aborted) { - throw new AbortError(); - } - }; - AbortSignal.prototype.abort = function () { - this._aborted = true; - this.notify(new AbortError()); - }; - return AbortSignal; - }(Subject)); - - var Handler = /** @class */ (function () { - function Handler(payload, dependencies) { - this.payload = payload; - this.dependencies = dependencies; - } - return Handler; - }()); - var AsyncHandler = /** @class */ (function (_super) { - __extends(AsyncHandler, _super); - function AsyncHandler(payload, dependencies, asyncFunction) { - var _this = _super.call(this, payload, dependencies) || this; - _this.asyncFunction = asyncFunction; - _this.abortSignal = new AbortSignal(); - return _this; - } - AsyncHandler.prototype.start = function () { - this.asyncFunction(this.payload, this.abortSignal, this.dependencies).catch(function (error) { - // console.log('Unhandled error:', error); - // swallow the error - }); - }; - AsyncHandler.prototype.cancel = function () { - this.abortSignal.abort(); - }; - return AsyncHandler; - }(Handler)); - var asyncHandler = function (handlerFunction) { - return function (payload, dependencies) { - return new AsyncHandler(payload, dependencies, handlerFunction); - }; - }; - - var handshake = createManagedEffect('HANDSHAKE', function (channels, groups) { return ({ - channels: channels, - groups: groups, - }); }); - var receiveMessages = createManagedEffect('RECEIVE_MESSAGES', function (channels, groups, cursor) { return ({ channels: channels, groups: groups, cursor: cursor }); }); - var emitMessages = createEffect('EMIT_MESSAGES', function (events) { return events; }); - var emitStatus$1 = createEffect('EMIT_STATUS', function (status) { return status; }); - var receiveReconnect = createManagedEffect('RECEIVE_RECONNECT', function (context) { return context; }); - var handshakeReconnect = createManagedEffect('HANDSHAKE_RECONNECT', function (context) { return context; }); - - var subscriptionChange = createEvent('SUBSCRIPTION_CHANGED', function (channels, groups) { return ({ - channels: channels, - groups: groups, - }); }); - var restore = createEvent('SUBSCRIPTION_RESTORED', function (channels, groups, timetoken, region) { return ({ - channels: channels, - groups: groups, - cursor: { - timetoken: timetoken, - region: region !== null && region !== void 0 ? region : 0, - }, - }); }); - var handshakeSuccess = createEvent('HANDSHAKE_SUCCESS', function (cursor) { return cursor; }); - var handshakeFailure = createEvent('HANDSHAKE_FAILURE', function (error) { return error; }); - var handshakeReconnectSuccess = createEvent('HANDSHAKE_RECONNECT_SUCCESS', function (cursor) { return ({ - cursor: cursor, - }); }); - var handshakeReconnectFailure = createEvent('HANDSHAKE_RECONNECT_FAILURE', function (error) { return error; }); - var handshakeReconnectGiveup = createEvent('HANDSHAKE_RECONNECT_GIVEUP', function (error) { return error; }); - var receiveSuccess = createEvent('RECEIVE_SUCCESS', function (cursor, events) { return ({ - cursor: cursor, - events: events, - }); }); - var receiveFailure = createEvent('RECEIVE_FAILURE', function (error) { return error; }); - var receiveReconnectSuccess = createEvent('RECEIVE_RECONNECT_SUCCESS', function (cursor, events) { return ({ - cursor: cursor, - events: events, - }); }); - var receiveReconnectFailure = createEvent('RECEIVE_RECONNECT_FAILURE', function (error) { return error; }); - var receiveReconnectGiveup = createEvent('RECEIVING_RECONNECT_GIVEUP', function (error) { return error; }); - var disconnect$1 = createEvent('DISCONNECT', function () { return ({}); }); - var reconnect$1 = createEvent('RECONNECT', function (timetoken, region) { return ({ - cursor: { - timetoken: timetoken !== null && timetoken !== void 0 ? timetoken : '', - region: region !== null && region !== void 0 ? region : 0, - }, - }); }); - var unsubscribeAll = createEvent('UNSUBSCRIBE_ALL', function () { return ({}); }); - - var EventEngineDispatcher = /** @class */ (function (_super) { - __extends(EventEngineDispatcher, _super); - function EventEngineDispatcher(engine, dependencies) { - var _this = _super.call(this, dependencies) || this; - _this.on(handshake.type, asyncHandler(function (payload, abortSignal, _a) { - var handshake = _a.handshake, presenceState = _a.presenceState, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, e_1; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - abortSignal.throwIfAborted(); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - return [4 /*yield*/, handshake(__assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState })))]; - case 2: - result = _b.sent(); - return [2 /*return*/, engine.transition(handshakeSuccess(result))]; - case 3: - e_1 = _b.sent(); - if (e_1 instanceof Error && e_1.message === 'Aborted') { - return [2 /*return*/]; - } - if (e_1 instanceof PubNubError) { - return [2 /*return*/, engine.transition(handshakeFailure(e_1))]; - } - return [3 /*break*/, 4]; - case 4: return [2 /*return*/]; - } - }); - }); - })); - _this.on(receiveMessages.type, asyncHandler(function (payload, abortSignal, _a) { - var receiveMessages = _a.receiveMessages, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, error_1; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - abortSignal.throwIfAborted(); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - return [4 /*yield*/, receiveMessages({ - abortSignal: abortSignal, - channels: payload.channels, - channelGroups: payload.groups, - timetoken: payload.cursor.timetoken, - region: payload.cursor.region, - filterExpression: config.filterExpression, - })]; - case 2: - result = _b.sent(); - engine.transition(receiveSuccess(result.metadata, result.messages)); - return [3 /*break*/, 4]; - case 3: - error_1 = _b.sent(); - if (error_1 instanceof Error && error_1.message === 'Aborted') { - return [2 /*return*/]; - } - if (error_1 instanceof PubNubError && !abortSignal.aborted) { - return [2 /*return*/, engine.transition(receiveFailure(error_1))]; - } - return [3 /*break*/, 4]; - case 4: return [2 /*return*/]; - } - }); - }); - })); - _this.on(emitMessages.type, asyncHandler(function (payload, _, _a) { - var emitMessages = _a.emitMessages; - return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_b) { - if (payload.length > 0) { - emitMessages(payload); - } - return [2 /*return*/]; - }); - }); - })); - _this.on(emitStatus$1.type, asyncHandler(function (payload, _, _a) { - var emitStatus = _a.emitStatus; - return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_b) { - emitStatus(payload); - return [2 /*return*/]; - }); - }); - })); - _this.on(receiveReconnect.type, asyncHandler(function (payload, abortSignal, _a) { - var receiveMessages = _a.receiveMessages, delay = _a.delay, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, error_2; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!(config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts))) return [3 /*break*/, 6]; - abortSignal.throwIfAborted(); - return [4 /*yield*/, delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason))]; - case 1: - _b.sent(); - abortSignal.throwIfAborted(); - _b.label = 2; - case 2: - _b.trys.push([2, 4, , 5]); - return [4 /*yield*/, receiveMessages({ - abortSignal: abortSignal, - channels: payload.channels, - channelGroups: payload.groups, - timetoken: payload.cursor.timetoken, - region: payload.cursor.region, - filterExpression: config.filterExpression, - })]; - case 3: - result = _b.sent(); - return [2 /*return*/, engine.transition(receiveReconnectSuccess(result.metadata, result.messages))]; - case 4: - error_2 = _b.sent(); - if (error_2 instanceof Error && error_2.message === 'Aborted') { - return [2 /*return*/]; - } - if (error_2 instanceof PubNubError) { - return [2 /*return*/, engine.transition(receiveReconnectFailure(error_2))]; - } - return [3 /*break*/, 5]; - case 5: return [3 /*break*/, 7]; - case 6: return [2 /*return*/, engine.transition(receiveReconnectGiveup(new PubNubError(config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts))))]; - case 7: return [2 /*return*/]; - } - }); - }); - })); - _this.on(handshakeReconnect.type, asyncHandler(function (payload, abortSignal, _a) { - var handshake = _a.handshake, delay = _a.delay, presenceState = _a.presenceState, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, error_3; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!(config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts))) return [3 /*break*/, 6]; - abortSignal.throwIfAborted(); - return [4 /*yield*/, delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason))]; - case 1: - _b.sent(); - abortSignal.throwIfAborted(); - _b.label = 2; - case 2: - _b.trys.push([2, 4, , 5]); - return [4 /*yield*/, handshake(__assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState })))]; - case 3: - result = _b.sent(); - return [2 /*return*/, engine.transition(handshakeReconnectSuccess(result))]; - case 4: - error_3 = _b.sent(); - if (error_3 instanceof Error && error_3.message === 'Aborted') { - return [2 /*return*/]; - } - if (error_3 instanceof PubNubError) { - return [2 /*return*/, engine.transition(handshakeReconnectFailure(error_3))]; - } - return [3 /*break*/, 5]; - case 5: return [3 /*break*/, 7]; - case 6: return [2 /*return*/, engine.transition(handshakeReconnectGiveup(new PubNubError(config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts))))]; - case 7: return [2 /*return*/]; - } - }); - }); - })); - return _this; - } - return EventEngineDispatcher; - }(Dispatcher)); - - var HandshakeFailedState = new State('HANDSHAKE_FAILED'); - HandshakeFailedState.on(subscriptionChange.type, function (context, event) { - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); - }); - HandshakeFailedState.on(reconnect$1.type, function (context, event) { - return HandshakingState.with({ - channels: context.channels, - groups: context.groups, - cursor: event.payload.cursor || context.cursor, - }); - }); - HandshakeFailedState.on(restore.type, function (context, event) { - var _a, _b; - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region ? event.payload.cursor.region : (_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0, - }, - }); - }); - HandshakeFailedState.on(unsubscribeAll.type, function (_) { return UnsubscribedState.with(); }); - - var HandshakeStoppedState = new State('HANDSHAKE_STOPPED'); - HandshakeStoppedState.on(subscriptionChange.type, function (context, event) { - return HandshakeStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); - }); - HandshakeStoppedState.on(reconnect$1.type, function (context, event) { - return HandshakingState.with(__assign(__assign({}, context), { cursor: event.payload.cursor || context.cursor })); - }); - HandshakeStoppedState.on(restore.type, function (context, event) { - var _a; - return HandshakeStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0, - }, - }); - }); - HandshakeStoppedState.on(unsubscribeAll.type, function (_) { return UnsubscribedState.with(); }); - - var ReceiveFailedState = new State('RECEIVE_FAILED'); - ReceiveFailedState.on(reconnect$1.type, function (context, event) { - var _a; - return HandshakingState.with({ - channels: context.channels, - groups: context.groups, - cursor: { - timetoken: !!event.payload.cursor.timetoken ? (_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); - }); - ReceiveFailedState.on(subscriptionChange.type, function (context, event) { - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); - }); - ReceiveFailedState.on(restore.type, function (context, event) { - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); - }); - ReceiveFailedState.on(unsubscribeAll.type, function (_) { return UnsubscribedState.with(undefined); }); - - var ReceiveStoppedState = new State('RECEIVE_STOPPED'); - ReceiveStoppedState.on(subscriptionChange.type, function (context, event) { - return ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); - }); - ReceiveStoppedState.on(restore.type, function (context, event) { - return ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); - }); - ReceiveStoppedState.on(reconnect$1.type, function (context, event) { - var _a; - return HandshakingState.with({ - channels: context.channels, - groups: context.groups, - cursor: { - timetoken: !!event.payload.cursor.timetoken ? (_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); - }); - ReceiveStoppedState.on(unsubscribeAll.type, function () { return UnsubscribedState.with(undefined); }); - - var ReceiveReconnectingState = new State('RECEIVE_RECONNECTING'); - ReceiveReconnectingState.onEnter(function (context) { return receiveReconnect(context); }); - ReceiveReconnectingState.onExit(function () { return receiveReconnect.cancel; }); - ReceiveReconnectingState.on(receiveReconnectSuccess.type, function (context, event) { - return ReceivingState.with({ - channels: context.channels, - groups: context.groups, - cursor: event.payload.cursor, - }, [emitMessages(event.payload.events)]); - }); - ReceiveReconnectingState.on(receiveReconnectFailure.type, function (context, event) { - return ReceiveReconnectingState.with(__assign(__assign({}, context), { attempts: context.attempts + 1, reason: event.payload })); - }); - ReceiveReconnectingState.on(receiveReconnectGiveup.type, function (context, event) { - var _a; - return ReceiveFailedState.with({ - groups: context.groups, - channels: context.channels, - cursor: context.cursor, - reason: event.payload, - }, [emitStatus$1({ category: categories.PNDisconnectedUnexpectedlyCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); - }); - ReceiveReconnectingState.on(disconnect$1.type, function (context) { - return ReceiveStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }, [emitStatus$1({ category: categories.PNDisconnectedCategory })]); - }); - ReceiveReconnectingState.on(restore.type, function (context, event) { - return ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); - }); - ReceiveReconnectingState.on(subscriptionChange.type, function (context, event) { - return ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); - }); - ReceiveReconnectingState.on(unsubscribeAll.type, function (_) { - return UnsubscribedState.with(undefined, [emitStatus$1({ category: categories.PNDisconnectedCategory })]); - }); - - var ReceivingState = new State('RECEIVING'); - ReceivingState.onEnter(function (context) { return receiveMessages(context.channels, context.groups, context.cursor); }); - ReceivingState.onExit(function () { return receiveMessages.cancel; }); - ReceivingState.on(receiveSuccess.type, function (context, event) { - return ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: event.payload.cursor }, [ - emitMessages(event.payload.events), - ]); - }); - ReceivingState.on(subscriptionChange.type, function (context, event) { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return UnsubscribedState.with(undefined); - } - return ReceivingState.with({ - cursor: context.cursor, - channels: event.payload.channels, - groups: event.payload.groups, - }); - }); - ReceivingState.on(restore.type, function (context, event) { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return UnsubscribedState.with(undefined); - } - return ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); - }); - ReceivingState.on(receiveFailure.type, function (context, event) { - return ReceiveReconnectingState.with(__assign(__assign({}, context), { attempts: 0, reason: event.payload })); - }); - ReceivingState.on(disconnect$1.type, function (context) { - return ReceiveStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }, [emitStatus$1({ category: categories.PNDisconnectedCategory })]); - }); - ReceivingState.on(unsubscribeAll.type, function (_) { - return UnsubscribedState.with(undefined, [emitStatus$1({ category: categories.PNDisconnectedCategory })]); - }); - - var HandshakeReconnectingState = new State('HANDSHAKE_RECONNECTING'); - HandshakeReconnectingState.onEnter(function (context) { return handshakeReconnect(context); }); - HandshakeReconnectingState.onExit(function () { return handshakeReconnect.cancel; }); - HandshakeReconnectingState.on(handshakeReconnectSuccess.type, function (context, event) { - var _a, _b; - var cursor = { - timetoken: !!((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : event.payload.cursor.timetoken, - region: event.payload.cursor.region, - }; - return ReceivingState.with({ - channels: context.channels, - groups: context.groups, - cursor: cursor, - }, [emitStatus$1({ category: categories.PNConnectedCategory })]); - }); - HandshakeReconnectingState.on(handshakeReconnectFailure.type, function (context, event) { - return HandshakeReconnectingState.with(__assign(__assign({}, context), { attempts: context.attempts + 1, reason: event.payload })); - }); - HandshakeReconnectingState.on(handshakeReconnectGiveup.type, function (context, event) { - var _a; - return HandshakeFailedState.with({ - groups: context.groups, - channels: context.channels, - cursor: context.cursor, - reason: event.payload, - }, [emitStatus$1({ category: categories.PNConnectionErrorCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); - }); - HandshakeReconnectingState.on(disconnect$1.type, function (context) { - return HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }); - }); - HandshakeReconnectingState.on(subscriptionChange.type, function (context, event) { - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); - }); - HandshakeReconnectingState.on(restore.type, function (context, event) { - var _a, _b; - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: ((_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.region) || ((_b = context === null || context === void 0 ? void 0 : context.cursor) === null || _b === void 0 ? void 0 : _b.region) || 0, - }, - }); - }); - HandshakeReconnectingState.on(unsubscribeAll.type, function (_) { return UnsubscribedState.with(undefined); }); - - var HandshakingState = new State('HANDSHAKING'); - HandshakingState.onEnter(function (context) { return handshake(context.channels, context.groups); }); - HandshakingState.onExit(function () { return handshake.cancel; }); - HandshakingState.on(subscriptionChange.type, function (context, event) { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return UnsubscribedState.with(undefined); - } - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); - }); - HandshakingState.on(handshakeSuccess.type, function (context, event) { - var _a, _b; - return ReceivingState.with({ - channels: context.channels, - groups: context.groups, - cursor: { - timetoken: !!((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context === null || context === void 0 ? void 0 : context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : event.payload.timetoken, - region: event.payload.region, - }, - }, [ - emitStatus$1({ - category: categories.PNConnectedCategory, - }), - ]); - }); - HandshakingState.on(handshakeFailure.type, function (context, event) { - return HandshakeReconnectingState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - attempts: 0, - reason: event.payload, - }); - }); - HandshakingState.on(disconnect$1.type, function (context) { - return HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }); - }); - HandshakingState.on(restore.type, function (context, event) { - var _a; - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0, - }, - }); - }); - HandshakingState.on(unsubscribeAll.type, function (_) { return UnsubscribedState.with(); }); - - var UnsubscribedState = new State('UNSUBSCRIBED'); - UnsubscribedState.on(subscriptionChange.type, function (_, event) { - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - }); - }); - UnsubscribedState.on(restore.type, function (_, event) { - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: event.payload.cursor, - }); - }); - - var EventEngine = /** @class */ (function () { - function EventEngine(dependencies) { - var _this = this; - this.engine = new Engine(); - this.channels = []; - this.groups = []; - this.dependencies = dependencies; - this.dispatcher = new EventEngineDispatcher(this.engine, dependencies); - this._unsubscribeEngine = this.engine.subscribe(function (change) { - if (change.type === 'invocationDispatched') { - _this.dispatcher.dispatch(change.invocation); - } - }); - this.engine.start(UnsubscribedState, undefined); - } - Object.defineProperty(EventEngine.prototype, "_engine", { - get: function () { - return this.engine; - }, - enumerable: false, - configurable: true - }); - EventEngine.prototype.subscribe = function (_a) { - var _this = this; - var channels = _a.channels, channelGroups = _a.channelGroups, timetoken = _a.timetoken, withPresence = _a.withPresence; - this.channels = __spreadArray$1(__spreadArray$1([], __read$1(this.channels), false), __read$1((channels !== null && channels !== void 0 ? channels : [])), false); - this.groups = __spreadArray$1(__spreadArray$1([], __read$1(this.groups), false), __read$1((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false); - if (withPresence) { - this.channels.map(function (c) { return _this.channels.push("".concat(c, "-pnpres")); }); - this.groups.map(function (g) { return _this.groups.push("".concat(g, "-pnpres")); }); - } - if (timetoken) { - this.engine.transition(restore(Array.from(new Set(__spreadArray$1(__spreadArray$1([], __read$1(this.channels), false), __read$1((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray$1(__spreadArray$1([], __read$1(this.groups), false), __read$1((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false))), timetoken)); - } - else { - this.engine.transition(subscriptionChange(Array.from(new Set(__spreadArray$1(__spreadArray$1([], __read$1(this.channels), false), __read$1((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray$1(__spreadArray$1([], __read$1(this.groups), false), __read$1((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false))))); - } - if (this.dependencies.join) { - this.dependencies.join({ - channels: Array.from(new Set(this.channels.filter(function (c) { return !c.endsWith('-pnpres'); }))), - groups: Array.from(new Set(this.groups.filter(function (g) { return !g.endsWith('-pnpres'); }))), - }); - } - }; - EventEngine.prototype.unsubscribe = function (_a) { - var _this = this; - var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c; - var filteredChannels = utils$5.removeSingleOccurance(this.channels, __spreadArray$1(__spreadArray$1([], __read$1(channels), false), __read$1(channels.map(function (c) { return "".concat(c, "-pnpres"); })), false)); - var filteredGroups = utils$5.removeSingleOccurance(this.groups, __spreadArray$1(__spreadArray$1([], __read$1(channelGroups), false), __read$1(channelGroups.map(function (c) { return "".concat(c, "-pnpres"); })), false)); - if (new Set(this.channels).size !== new Set(filteredChannels).size || - new Set(this.groups).size !== new Set(filteredGroups).size) { - var channelsToLeave = utils$5.findUniqueCommonElements(this.channels, channels); - var groupstoLeave = utils$5.findUniqueCommonElements(this.groups, channelGroups); - if (this.dependencies.presenceState) { - channelsToLeave === null || channelsToLeave === void 0 ? void 0 : channelsToLeave.forEach(function (c) { return delete _this.dependencies.presenceState[c]; }); - groupstoLeave === null || groupstoLeave === void 0 ? void 0 : groupstoLeave.forEach(function (g) { return delete _this.dependencies.presenceState[g]; }); - } - this.channels = filteredChannels; - this.groups = filteredGroups; - this.engine.transition(subscriptionChange(Array.from(new Set(this.channels.slice(0))), Array.from(new Set(this.groups.slice(0))))); - if (this.dependencies.leave) { - this.dependencies.leave({ - channels: channelsToLeave.slice(0), - groups: groupstoLeave.slice(0), - }); - } - } - }; - EventEngine.prototype.unsubscribeAll = function () { - this.channels = []; - this.groups = []; - if (this.dependencies.presenceState) { - this.dependencies.presenceState = {}; - } - this.engine.transition(subscriptionChange(this.channels.slice(0), this.groups.slice(0))); - if (this.dependencies.leaveAll) { - this.dependencies.leaveAll(); - } - }; - EventEngine.prototype.reconnect = function (_a) { - var timetoken = _a.timetoken, region = _a.region; - this.engine.transition(reconnect$1(timetoken, region)); - }; - EventEngine.prototype.disconnect = function () { - this.engine.transition(disconnect$1()); - if (this.dependencies.leaveAll) { - this.dependencies.leaveAll(); - } - }; - EventEngine.prototype.getSubscribedChannels = function () { - return Array.from(new Set(this.channels)); - }; - EventEngine.prototype.getSubscribedChannelGroups = function () { - return Array.from(new Set(this.groups)); - }; - EventEngine.prototype.dispose = function () { - this.disconnect(); - this._unsubscribeEngine(); - this.dispatcher.dispose(); - }; - return EventEngine; - }()); - - var reconnect = createEvent('RECONNECT', function () { return ({}); }); - var disconnect = createEvent('DISCONNECT', function () { return ({}); }); - var joined = createEvent('JOINED', function (channels, groups) { return ({ - channels: channels, - groups: groups, - }); }); - var left = createEvent('LEFT', function (channels, groups) { return ({ - channels: channels, - groups: groups, - }); }); - var leftAll = createEvent('LEFT_ALL', function () { return ({}); }); - var heartbeatSuccess = createEvent('HEARTBEAT_SUCCESS', function (statusCode) { return ({ statusCode: statusCode }); }); - var heartbeatFailure = createEvent('HEARTBEAT_FAILURE', function (error) { return error; }); - var heartbeatGiveup = createEvent('HEARTBEAT_GIVEUP', function () { return ({}); }); - var timesUp = createEvent('TIMES_UP', function () { return ({}); }); - - var heartbeat = createEffect('HEARTBEAT', function (channels, groups) { return ({ - channels: channels, - groups: groups, - }); }); - var leave = createEffect('LEAVE', function (channels, groups) { return ({ - channels: channels, - groups: groups, - }); }); - var emitStatus = createEffect('EMIT_STATUS', function (status) { return status; }); - var wait = createManagedEffect('WAIT', function () { return ({}); }); - var delayedHeartbeat = createManagedEffect('DELAYED_HEARTBEAT', function (context) { return context; }); - - var PresenceEventEngineDispatcher = /** @class */ (function (_super) { - __extends(PresenceEventEngineDispatcher, _super); - function PresenceEventEngineDispatcher(engine, dependencies) { - var _this = _super.call(this, dependencies) || this; - _this.on(heartbeat.type, asyncHandler(function (payload, _, _a) { - var heartbeat = _a.heartbeat, presenceState = _a.presenceState, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var e_1; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 2, , 3]); - return [4 /*yield*/, heartbeat(__assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })))]; - case 1: - _b.sent(); - engine.transition(heartbeatSuccess(200)); - return [3 /*break*/, 3]; - case 2: - e_1 = _b.sent(); - if (e_1 instanceof PubNubError) { - return [2 /*return*/, engine.transition(heartbeatFailure(e_1))]; - } - return [3 /*break*/, 3]; - case 3: return [2 /*return*/]; - } - }); - }); - })); - _this.on(leave.type, asyncHandler(function (payload, _, _a) { - var leave = _a.leave, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!!config.suppressLeaveEvents) return [3 /*break*/, 4]; - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - return [4 /*yield*/, leave({ - channels: payload.channels, - channelGroups: payload.groups, - })]; - case 2: - _b.sent(); - return [3 /*break*/, 4]; - case 3: - _b.sent(); - return [3 /*break*/, 4]; - case 4: return [2 /*return*/]; - } - }); - }); - })); - _this.on(wait.type, asyncHandler(function (_, abortSignal, _a) { - var heartbeatDelay = _a.heartbeatDelay; - return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - abortSignal.throwIfAborted(); - return [4 /*yield*/, heartbeatDelay()]; - case 1: - _b.sent(); - abortSignal.throwIfAborted(); - return [2 /*return*/, engine.transition(timesUp())]; - } - }); - }); - })); - _this.on(delayedHeartbeat.type, asyncHandler(function (payload, abortSignal, _a) { - var heartbeat = _a.heartbeat, retryDelay = _a.retryDelay, presenceState = _a.presenceState, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var e_3; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!(config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts))) return [3 /*break*/, 6]; - abortSignal.throwIfAborted(); - return [4 /*yield*/, retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason))]; - case 1: - _b.sent(); - abortSignal.throwIfAborted(); - _b.label = 2; - case 2: - _b.trys.push([2, 4, , 5]); - return [4 /*yield*/, heartbeat(__assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })))]; - case 3: - _b.sent(); - return [2 /*return*/, engine.transition(heartbeatSuccess(200))]; - case 4: - e_3 = _b.sent(); - if (e_3 instanceof Error && e_3.message === 'Aborted') { - return [2 /*return*/]; - } - if (e_3 instanceof PubNubError) { - return [2 /*return*/, engine.transition(heartbeatFailure(e_3))]; - } - return [3 /*break*/, 5]; - case 5: return [3 /*break*/, 7]; - case 6: return [2 /*return*/, engine.transition(heartbeatGiveup())]; - case 7: return [2 /*return*/]; - } - }); - }); - })); - _this.on(emitStatus.type, asyncHandler(function (payload, _, _a) { - var emitStatus = _a.emitStatus, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var _b; - return __generator(this, function (_c) { - if (config.announceFailedHeartbeats && ((_b = payload === null || payload === void 0 ? void 0 : payload.status) === null || _b === void 0 ? void 0 : _b.error) === true) { - emitStatus(payload.status); - } - else if (config.announceSuccessfulHeartbeats && payload.statusCode === 200) { - emitStatus(__assign(__assign({}, payload), { operation: OPERATIONS.PNHeartbeatOperation, error: false })); - } - return [2 /*return*/]; - }); - }); - })); - return _this; - } - return PresenceEventEngineDispatcher; - }(Dispatcher)); - - var HeartbeatStoppedState = new State('HEARTBEAT_STOPPED'); - HeartbeatStoppedState.on(joined.type, function (context, event) { - return HeartbeatStoppedState.with({ - channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), - groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), - }); - }); - HeartbeatStoppedState.on(left.type, function (context, event) { - return HeartbeatStoppedState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), - }); - }); - HeartbeatStoppedState.on(reconnect.type, function (context, _) { - return HeartbeatingState.with({ - channels: context.channels, - groups: context.groups, - }); - }); - HeartbeatStoppedState.on(leftAll.type, function (context, _) { return HeartbeatInactiveState.with(undefined); }); - - var HeartbeatCooldownState = new State('HEARTBEAT_COOLDOWN'); - HeartbeatCooldownState.onEnter(function () { return wait(); }); - HeartbeatCooldownState.onExit(function () { return wait.cancel; }); - HeartbeatCooldownState.on(timesUp.type, function (context, _) { - return HeartbeatingState.with({ - channels: context.channels, - groups: context.groups, - }); - }); - HeartbeatCooldownState.on(joined.type, function (context, event) { - return HeartbeatingState.with({ - channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), - groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), - }); - }); - HeartbeatCooldownState.on(left.type, function (context, event) { - return HeartbeatingState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), - }, [leave(event.payload.channels, event.payload.groups)]); - }); - HeartbeatCooldownState.on(disconnect.type, function (context) { - return HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [leave(context.channels, context.groups)]); - }); - HeartbeatCooldownState.on(leftAll.type, function (context, _) { - return HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)]); - }); - - var HeartbeatFailedState = new State('HEARTBEAT_FAILED'); - HeartbeatFailedState.on(joined.type, function (context, event) { - return HeartbeatingState.with({ - channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), - groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), - }); - }); - HeartbeatFailedState.on(left.type, function (context, event) { - return HeartbeatingState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), - }, [leave(event.payload.channels, event.payload.groups)]); - }); - HeartbeatFailedState.on(reconnect.type, function (context, _) { - return HeartbeatingState.with({ - channels: context.channels, - groups: context.groups, - }); - }); - HeartbeatFailedState.on(disconnect.type, function (context, _) { - return HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [leave(context.channels, context.groups)]); - }); - HeartbeatFailedState.on(leftAll.type, function (context, _) { - return HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)]); - }); - - var HearbeatReconnectingState = new State('HEARBEAT_RECONNECTING'); - HearbeatReconnectingState.onEnter(function (context) { return delayedHeartbeat(context); }); - HearbeatReconnectingState.onExit(function () { return delayedHeartbeat.cancel; }); - HearbeatReconnectingState.on(joined.type, function (context, event) { - return HeartbeatingState.with({ - channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), - groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), - }); - }); - HearbeatReconnectingState.on(left.type, function (context, event) { - return HeartbeatingState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), - }, [leave(event.payload.channels, event.payload.groups)]); - }); - HearbeatReconnectingState.on(disconnect.type, function (context, _) { - HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [leave(context.channels, context.groups)]); - }); - HearbeatReconnectingState.on(heartbeatSuccess.type, function (context, event) { - return HeartbeatCooldownState.with({ - channels: context.channels, - groups: context.groups, - }); - }); - HearbeatReconnectingState.on(heartbeatFailure.type, function (context, event) { - return HearbeatReconnectingState.with(__assign(__assign({}, context), { attempts: context.attempts + 1, reason: event.payload })); - }); - HearbeatReconnectingState.on(heartbeatGiveup.type, function (context, event) { - return HeartbeatFailedState.with({ - channels: context.channels, - groups: context.groups, - }); - }); - HearbeatReconnectingState.on(leftAll.type, function (context, _) { - return HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)]); - }); - - var HeartbeatingState = new State('HEARTBEATING'); - HeartbeatingState.onEnter(function (context) { return heartbeat(context.channels, context.groups); }); - HeartbeatingState.on(heartbeatSuccess.type, function (context, event) { - return HeartbeatCooldownState.with({ - channels: context.channels, - groups: context.groups, - }); - }); - HeartbeatingState.on(joined.type, function (context, event) { - return HeartbeatingState.with({ - channels: __spreadArray$1(__spreadArray$1([], __read$1(context.channels), false), __read$1(event.payload.channels), false), - groups: __spreadArray$1(__spreadArray$1([], __read$1(context.groups), false), __read$1(event.payload.groups), false), - }); - }); - HeartbeatingState.on(left.type, function (context, event) { - return HeartbeatingState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), - }, [leave(event.payload.channels, event.payload.groups)]); - }); - HeartbeatingState.on(heartbeatFailure.type, function (context, event) { - return HearbeatReconnectingState.with(__assign(__assign({}, context), { attempts: 0, reason: event.payload })); - }); - HeartbeatingState.on(disconnect.type, function (context) { - return HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [leave(context.channels, context.groups)]); - }); - HeartbeatingState.on(leftAll.type, function (context, _) { - return HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)]); - }); - - var HeartbeatInactiveState = new State('HEARTBEAT_INACTIVE'); - HeartbeatInactiveState.on(joined.type, function (_, event) { - return HeartbeatingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - }); - }); - - var PresenceEventEngine = /** @class */ (function () { - function PresenceEventEngine(dependencies) { - var _this = this; - this.engine = new Engine(); - this.channels = []; - this.groups = []; - this.dispatcher = new PresenceEventEngineDispatcher(this.engine, dependencies); - this.dependencies = dependencies; - this._unsubscribeEngine = this.engine.subscribe(function (change) { - if (change.type === 'invocationDispatched') { - _this.dispatcher.dispatch(change.invocation); - } - }); - this.engine.start(HeartbeatInactiveState, undefined); - } - Object.defineProperty(PresenceEventEngine.prototype, "_engine", { - get: function () { - return this.engine; - }, - enumerable: false, - configurable: true - }); - PresenceEventEngine.prototype.join = function (_a) { - var channels = _a.channels, groups = _a.groups; - this.channels = __spreadArray$1(__spreadArray$1([], __read$1(this.channels), false), __read$1((channels !== null && channels !== void 0 ? channels : [])), false); - this.groups = __spreadArray$1(__spreadArray$1([], __read$1(this.groups), false), __read$1((groups !== null && groups !== void 0 ? groups : [])), false); - this.engine.transition(joined(this.channels.slice(0), this.groups.slice(0))); - }; - PresenceEventEngine.prototype.leave = function (_a) { - var _this = this; - var channels = _a.channels, groups = _a.groups; - if (this.dependencies.presenceState) { - channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { return delete _this.dependencies.presenceState[c]; }); - groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { return delete _this.dependencies.presenceState[g]; }); - } - this.engine.transition(left(channels !== null && channels !== void 0 ? channels : [], groups !== null && groups !== void 0 ? groups : [])); - }; - PresenceEventEngine.prototype.leaveAll = function () { - this.engine.transition(leftAll()); - }; - PresenceEventEngine.prototype.dispose = function () { - this._unsubscribeEngine(); - this.dispatcher.dispose(); - }; - return PresenceEventEngine; - }()); - - var RetryPolicy = /** @class */ (function () { - function RetryPolicy() { - } - RetryPolicy.LinearRetryPolicy = function (configuration) { - return { - delay: configuration.delay, - maximumRetry: configuration.maximumRetry, - shouldRetry: function (error, attempt) { - var _a; - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return false; - } - return this.maximumRetry > attempt; - }, - getDelay: function (_, reason) { - var _a; - var delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : this.delay; - return (delay + Math.random()) * 1000; - }, - getGiveupReason: function (error, attempt) { - var _a; - if (this.maximumRetry <= attempt) { - return 'retry attempts exhaused.'; - } - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return 'forbidden operation.'; - } - return 'unknown error'; - }, - }; - }; - RetryPolicy.ExponentialRetryPolicy = function (configuration) { - return { - minimumDelay: configuration.minimumDelay, - maximumDelay: configuration.maximumDelay, - maximumRetry: configuration.maximumRetry, - shouldRetry: function (error, attempt) { - var _a; - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return false; - } - return this.maximumRetry > attempt; - }, - getDelay: function (attempt, reason) { - var _a; - var delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : Math.min(Math.pow(2, attempt), this.maximumDelay); - return (delay + Math.random()) * 1000; - }, - getGiveupReason: function (error, attempt) { - var _a; - if (this.maximumRetry <= attempt) { - return 'retry attempts exhaused.'; - } - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return 'forbidden operation.'; - } - return 'unknown error'; - }, - }; - }; - return RetryPolicy; - }()); - - var EventEmitter = /** @class */ (function () { - function EventEmitter(_a) { - var modules = _a.modules, listenerManager = _a.listenerManager, getFileUrl = _a.getFileUrl; - this.modules = modules; - this.listenerManager = listenerManager; - this.getFileUrl = getFileUrl; - this._channelListenerMap = new Map(); - this._groupListenerMap = new Map(); - if (modules.cryptoModule) - this._decoder = new TextDecoder(); - } - EventEmitter.prototype.emitEvent = function (e) { - var channel = e.channel, publishMetaData = e.publishMetaData; - var subscriptionMatch = e.subscriptionMatch; - if (channel === subscriptionMatch) { - subscriptionMatch = null; - } - if (e.channel.endsWith('-pnpres')) { - var announce = {}; - announce.channel = null; - announce.subscription = null; - if (channel) { - announce.channel = channel.substring(0, channel.lastIndexOf('-pnpres')); - } - if (subscriptionMatch) { - announce.subscription = subscriptionMatch.substring(0, subscriptionMatch.lastIndexOf('-pnpres')); - } - announce.action = e.payload.action; - announce.state = e.payload.data; - announce.timetoken = publishMetaData.timetoken; - announce.occupancy = e.payload.occupancy; - announce.uuid = e.payload.uuid; - announce.timestamp = e.payload.timestamp; - if (e.payload.join) { - announce.join = e.payload.join; - } - if (e.payload.leave) { - announce.leave = e.payload.leave; - } - if (e.payload.timeout) { - announce.timeout = e.payload.timeout; - } - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - this.listenerManager.announcePresence(announce); - this._announce('presence', announce, announce.channel, announce.subscription); - } - else if (e.messageType === 1) { - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - announce.message = e.payload; - this.listenerManager.announceSignal(announce); - this._announce('signal', announce, announce.channel, announce.subscription); - } - else if (e.messageType === 2) { - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - announce.message = { - event: e.payload.event, - type: e.payload.type, - data: e.payload.data, - }; - this.listenerManager.announceObjects(announce); - this._announce('objects', announce, announce.channel, announce.subscription); - if (e.payload.type === 'uuid') { - var eventData = this._renameChannelField(announce); - var userEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) }); - this.listenerManager.announceUser(userEvent); - this._announce('user', userEvent, announce.channel, announce.subscription); - } - else if (e.payload.type === 'channel') { - var eventData = this._renameChannelField(announce); - var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) }); - this.listenerManager.announceSpace(spaceEvent); - this._announce('space', spaceEvent, announce.channel, announce.subscription); - } - else if (e.payload.type === 'membership') { - var eventData = this._renameChannelField(announce); - var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]); - membershipData.user = user; - membershipData.space = space; - var membershipEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) }); - this.listenerManager.announceMembership(membershipEvent); - this._announce('membership', membershipEvent, announce.channel, announce.subscription); - } - } - else if (e.messageType === 3) { - var announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - announce.data = { - messageTimetoken: e.payload.data.messageTimetoken, - actionTimetoken: e.payload.data.actionTimetoken, - type: e.payload.data.type, - uuid: e.issuingClientId, - value: e.payload.data.value, - }; - announce.event = e.payload.event; - this.listenerManager.announceMessageAction(announce); - this._announce('messageAction', announce, announce.channel, announce.subscription); - } - else if (e.messageType === 4) { - var announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - var msgPayload = e.payload; - if (this.modules.cryptoModule) { - var decryptedPayload = void 0; - try { - var decryptedData = this.modules.cryptoModule.decrypt(e.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData; - } - catch (e) { - decryptedPayload = null; - announce.error = "Error while decrypting message content: ".concat(e.message); - } - if (decryptedPayload !== null) { - msgPayload = decryptedPayload; - } - } - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - announce.message = msgPayload.message; - announce.file = { - id: msgPayload.file.id, - name: msgPayload.file.name, - url: this.getFileUrl({ - id: msgPayload.file.id, - name: msgPayload.file.name, - channel: channel, - }), - }; - this.listenerManager.announceFile(announce); - this._announce('file', announce, announce.channel, announce.subscription); - } - else { - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - if (this.modules.cryptoModule) { - var decryptedPayload = void 0; - try { - var decryptedData = this.modules.cryptoModule.decrypt(e.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData; - } - catch (e) { - decryptedPayload = null; - announce.error = "Error while decrypting message content: ".concat(e.message); - } - if (decryptedPayload != null) { - announce.message = decryptedPayload; - } - else { - announce.message = e.payload; - } - } - else { - announce.message = e.payload; - } - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - this.listenerManager.announceMessage(announce); - this._announce('message', announce, announce.channel, announce.subscription); - } - }; - EventEmitter.prototype.addListener = function (l, channels, groups) { - var _this = this; - if (!(channels && groups)) { - this.listenerManager.addListener(l); - } - else { - channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { - if (_this._channelListenerMap[c]) { - if (!_this._channelListenerMap[c].includes(l)) - _this._channelListenerMap[c].push(l); - } - else { - _this._channelListenerMap[c] = [l]; - } - }); - groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { - if (_this._groupListenerMap[g]) { - if (!_this._groupListenerMap[g].includes(l)) - _this._groupListenerMap[g].push(l); - } - else { - _this._groupListenerMap[g] = [l]; - } - }); - } - }; - EventEmitter.prototype.removeListener = function (listener, channels, groups) { - var _this = this; - if (!(channels && groups)) { - this.listenerManager.removeListener(listener); - } - else { - channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { - var _a; - _this._channelListenerMap[c] = (_a = _this._channelListenerMap[c]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; }); - }); - groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { - var _a; - _this._groupListenerMap[g] = (_a = _this._groupListenerMap[g]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; }); - }); - } - }; - EventEmitter.prototype.removeAllListeners = function () { - this.listenerManager.removeAllListeners(); - }; - EventEmitter.prototype._renameEvent = function (e) { - return e === 'set' ? 'updated' : 'removed'; - }; - EventEmitter.prototype._renameChannelField = function (announce) { - var channel = announce.channel, eventData = __rest(announce, ["channel"]); - eventData.spaceId = channel; - return eventData; - }; - EventEmitter.prototype._announce = function (type, event, channel, group) { - var _a, _b; - (_a = this._channelListenerMap[channel]) === null || _a === void 0 ? void 0 : _a.forEach(function (l) { return l[type] && l[type](event); }); - (_b = this._groupListenerMap[group]) === null || _b === void 0 ? void 0 : _b.forEach(function (l) { return l[type] && l[type](event); }); - }; - return EventEmitter; - }()); - - var SubscribeCapable = /** @class */ (function () { - function SubscribeCapable() { - } - SubscribeCapable.prototype.subscribe = function () { - var _a, _b; - this.pubnub.subscribe(__assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken }))); - }; - SubscribeCapable.prototype.unsubscribe = function () { - this.pubnub.unsubscribe({ - channels: this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), - channelGroups: this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }), - }); - }; - Object.defineProperty(SubscribeCapable.prototype, "onMessage", { - set: function (onMessagelistener) { - this.listener.message = onMessagelistener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onPresence", { - set: function (onPresencelistener) { - this.listener.presence = onPresencelistener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onSignal", { - set: function (onSignalListener) { - this.listener.signal = onSignalListener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onObjects", { - set: function (onObjectsListener) { - this.listener.objects = onObjectsListener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onMessageAction", { - set: function (messageActionEventListener) { - this.listener.messageAction = messageActionEventListener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onFile", { - set: function (fileEventListener) { - this.listener.file = fileEventListener; - }, - enumerable: false, - configurable: true - }); - SubscribeCapable.prototype.addListener = function (listener) { - this.eventEmitter.addListener(listener, this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); - }; - SubscribeCapable.prototype.removeListener = function (listener) { - this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); - }; - Object.defineProperty(SubscribeCapable.prototype, "channels", { - get: function () { - return this.channelNames.slice(0); - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "channelGroups", { - get: function () { - return this.groupNames.slice(0); - }, - enumerable: false, - configurable: true - }); - return SubscribeCapable; - }()); - - var SubscriptionSet = /** @class */ (function (_super) { - __extends(SubscriptionSet, _super); - function SubscriptionSet(_a) { - var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub; - var _this = _super.call(this) || this; - _this.channelNames = []; - _this.groupNames = []; - _this.subscriptionList = []; - _this.options = subscriptionOptions; - _this.eventEmitter = eventEmitter; - _this.pubnub = pubnub; - channels - .filter(function (c) { return !c.endsWith('-pnpres'); }) - .forEach(function (c) { - var subscription = _this.pubnub.channel(c).subscription(_this.options); - _this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.channelNames), false), __read$1(subscription.channels), false); - _this.subscriptionList.push(subscription); - }); - channelGroups - .filter(function (cg) { return !cg.endsWith('-pnpres'); }) - .forEach(function (cg) { - var subscription = _this.pubnub.channelGroup(cg).subscription(_this.options); - _this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(_this.groupNames), false), __read$1(subscription.channelGroups), false); - _this.subscriptionList.push(subscription); - }); - _this.listener = {}; - eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); - return _this; - } - SubscriptionSet.prototype.addSubscription = function (subscription) { - this.subscriptionList.push(subscription); - this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscription.channels), false); - this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscription.channelGroups), false); - this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); - }; - SubscriptionSet.prototype.removeSubscription = function (subscription) { - var channelsToRemove = subscription.channels; - var groupsToRemove = subscription.channelGroups; - this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); - this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); - this.subscriptionList = this.subscriptionList.filter(function (s) { return s !== subscription; }); - this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); - }; - SubscriptionSet.prototype.addSubscriptionSet = function (subscriptionSet) { - this.subscriptionList = __spreadArray$1(__spreadArray$1([], __read$1(this.subscriptionList), false), __read$1(subscriptionSet.subscriptions), false); - this.channelNames = __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscriptionSet.channels), false); - this.groupNames = __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscriptionSet.channelGroups), false); - this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); - }; - SubscriptionSet.prototype.removeSubscriptionSet = function (subscriptionSet) { - var channelsToRemove = subscriptionSet.channels; - var groupsToRemove = subscriptionSet.channelGroups; - this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); - this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); - this.subscriptionList = this.subscriptionList.filter(function (s) { return !subscriptionSet.subscriptions.includes(s); }); - this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); - }; - Object.defineProperty(SubscriptionSet.prototype, "subscriptions", { - get: function () { - return this.subscriptionList.slice(0); - }, - enumerable: false, - configurable: true - }); - return SubscriptionSet; - }(SubscribeCapable)); - - var Subscription = /** @class */ (function (_super) { - __extends(Subscription, _super); - function Subscription(_a) { - var channels = _a.channels, channelGroups = _a.channelGroups, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub; - var _this = _super.call(this) || this; - _this.channelNames = []; - _this.groupNames = []; - _this.channelNames = channels; - _this.groupNames = channelGroups; - _this.options = subscriptionOptions; - _this.pubnub = pubnub; - _this.eventEmitter = eventEmitter; - _this.listener = {}; - eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); - return _this; - } - Subscription.prototype.addSubscription = function (subscription) { - return new SubscriptionSet({ - channels: __spreadArray$1(__spreadArray$1([], __read$1(this.channelNames), false), __read$1(subscription.channels), false), - channelGroups: __spreadArray$1(__spreadArray$1([], __read$1(this.groupNames), false), __read$1(subscription.channelGroups), false), - subscriptionOptions: __assign(__assign({}, this.options), subscription === null || subscription === void 0 ? void 0 : subscription.options), - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); - }; - return Subscription; - }(SubscribeCapable)); - - var Channel = /** @class */ (function () { - function Channel(channelName, eventEmitter, pubnub) { - this.name = channelName; - this.eventEmitter = eventEmitter; - this.pubnub = pubnub; - } - Channel.prototype.subscription = function (subscriptionOptions) { - return new Subscription({ - channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, "".concat(this.name, "-pnpres")] : [this.name], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); - }; - return Channel; - }()); - - var ChannelGroup = /** @class */ (function () { - function ChannelGroup(channelGroup, eventEmitter, pubnub) { - this.name = channelGroup; - this.eventEmitter = eventEmitter; - this.pubnub = pubnub; - } - ChannelGroup.prototype.subscription = function (subscriptionOptions) { - return new Subscription({ - channels: [], - channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, "".concat(this.name, "-pnpres")] : [this.name], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); - }; - return ChannelGroup; - }()); - - var ChannelMetadata = /** @class */ (function () { - function ChannelMetadata(id, eventEmitter, pubnub) { - this.id = id; - this.eventEmitter = eventEmitter; - this.pubnub = pubnub; - } - ChannelMetadata.prototype.subscription = function (subscriptionOptions) { - return new Subscription({ - channels: [this.id], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); - }; - return ChannelMetadata; - }()); - - var UserMetadata = /** @class */ (function () { - function UserMetadata(id, eventEmitter, pubnub) { - this.id = id; - this.eventEmitter = eventEmitter; - this.pubnub = pubnub; - } - UserMetadata.prototype.subscription = function (subscriptionOptions) { - return new Subscription({ - channels: [this.id], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); - }; - return UserMetadata; - }()); - - var default_1$3 = /** @class */ (function () { - function default_1(setup) { - var _this = this; - var networking = setup.networking, cbor = setup.cbor; - var config = new default_1$b({ setup: setup }); - this._config = config; - var crypto = new default_1$a({ config: config }); // LEGACY - var cryptography = setup.cryptography; - networking.init(config); - var tokenManager = new default_1$4(config, cbor); - this._tokenManager = tokenManager; - var telemetryManager = new default_1$6({ - maximumSamplesCount: 60000, - }); - this._telemetryManager = telemetryManager; - var cryptoModule = this._config.cryptoModule; - var modules = { - config: config, - networking: networking, - crypto: crypto, - cryptography: cryptography, - tokenManager: tokenManager, - telemetryManager: telemetryManager, - PubNubFile: setup.PubNubFile, - cryptoModule: cryptoModule, - }; - this.File = setup.PubNubFile; - this.encryptFile = function (key, file) { - if (arguments.length == 1 && typeof key != 'string' && modules.cryptoModule) { - file = key; - return modules.cryptoModule.encryptFile(file, this.File); - } - return cryptography.encryptFile(key, file, this.File); - }; - this.decryptFile = function (key, file) { - if (arguments.length == 1 && typeof key != 'string' && modules.cryptoModule) { - file = key; - return modules.cryptoModule.decryptFile(file, this.File); - } - return cryptography.decryptFile(key, file, this.File); - }; - var timeEndpoint = endpointCreator.bind(this, modules, timeEndpointConfig); - var leaveEndpoint = endpointCreator.bind(this, modules, presenceLeaveEndpointConfig); - var heartbeatEndpoint = endpointCreator.bind(this, modules, presenceHeartbeatEndpointConfig); - var setStateEndpoint = endpointCreator.bind(this, modules, presenceSetStateConfig); - var subscribeEndpoint = endpointCreator.bind(this, modules, subscribeEndpointConfig); - // managers - var listenerManager = new default_1$5(); - this._listenerManager = listenerManager; - this.iAmHere = endpointCreator.bind(this, modules, presenceHeartbeatEndpointConfig); - this.iAmAway = endpointCreator.bind(this, modules, presenceLeaveEndpointConfig); - this.setPresenceState = endpointCreator.bind(this, modules, presenceSetStateConfig); - this.handshake = endpointCreator.bind(this, modules, endpoint$1); - this.receiveMessages = endpointCreator.bind(this, modules, endpoint); - this._eventEmitter = new EventEmitter({ - modules: modules, - listenerManager: this._listenerManager, - getFileUrl: function (params) { return getFileUrlFunction(modules, params); }, - }); - if (config.enableEventEngine === true) { - if (config.maintainPresenceState) { - this.presenceState = {}; - this.setState = function (args) { - var _a, _b; - (_a = args.channels) === null || _a === void 0 ? void 0 : _a.forEach(function (channel) { return (_this.presenceState[channel] = args.state); }); - (_b = args.channelGroups) === null || _b === void 0 ? void 0 : _b.forEach(function (group) { return (_this.presenceState[group] = args.state); }); - return _this.setPresenceState({ - channels: args.channels, - channelGroups: args.channelGroups, - state: _this.presenceState, - }); - }; - } - if (config.getHeartbeatInterval()) { - var presenceEventEngine = new PresenceEventEngine({ - heartbeat: this.iAmHere, - leave: this.iAmAway, - heartbeatDelay: function () { - return new Promise(function (resolve) { return setTimeout(resolve, modules.config.getHeartbeatInterval() * 1000); }); - }, - retryDelay: function (amount) { return new Promise(function (resolve) { return setTimeout(resolve, amount); }); }, - config: modules.config, - presenceState: this.presenceState, - emitStatus: function (status) { - listenerManager.announceStatus(status); - }, - }); - this.presenceEventEngine = presenceEventEngine; - this.join = this.presenceEventEngine.join.bind(presenceEventEngine); - this.leave = this.presenceEventEngine.leave.bind(presenceEventEngine); - this.leaveAll = this.presenceEventEngine.leaveAll.bind(presenceEventEngine); - } - var eventEngine = new EventEngine({ - handshake: this.handshake, - receiveMessages: this.receiveMessages, - delay: function (amount) { return new Promise(function (resolve) { return setTimeout(resolve, amount); }); }, - join: this.join, - leave: this.leave, - leaveAll: this.leaveAll, - presenceState: this.presenceState, - config: modules.config, - emitMessages: function (events) { - var e_1, _a; - try { - for (var events_1 = __values(events), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) { - var event_1 = events_1_1.value; - _this._eventEmitter.emitEvent(event_1); - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1); - } - finally { if (e_1) throw e_1.error; } - } - }, - emitStatus: function (status) { - listenerManager.announceStatus(status); - }, - }); - this.subscribe = eventEngine.subscribe.bind(eventEngine); - this.unsubscribe = eventEngine.unsubscribe.bind(eventEngine); - this.unsubscribeAll = eventEngine.unsubscribeAll.bind(eventEngine); - this.reconnect = eventEngine.reconnect.bind(eventEngine); - this.disconnect = eventEngine.disconnect.bind(eventEngine); - this.destroy = eventEngine.dispose.bind(eventEngine); - this.getSubscribedChannels = eventEngine.getSubscribedChannels.bind(eventEngine); - this.getSubscribedChannelGroups = eventEngine.getSubscribedChannelGroups.bind(eventEngine); - this.eventEngine = eventEngine; - } - else { - var subscriptionManager_1 = new default_1$7({ - timeEndpoint: timeEndpoint, - leaveEndpoint: leaveEndpoint, - heartbeatEndpoint: heartbeatEndpoint, - setStateEndpoint: setStateEndpoint, - subscribeEndpoint: subscribeEndpoint, - crypto: modules.crypto, - config: modules.config, - listenerManager: listenerManager, - getFileUrl: function (params) { return getFileUrlFunction(modules, params); }, - cryptoModule: modules.cryptoModule, - eventEmitter: this._eventEmitter, - }); - this.subscribe = subscriptionManager_1.adaptSubscribeChange.bind(subscriptionManager_1); - this.unsubscribe = subscriptionManager_1.adaptUnsubscribeChange.bind(subscriptionManager_1); - this.disconnect = subscriptionManager_1.disconnect.bind(subscriptionManager_1); - this.reconnect = subscriptionManager_1.reconnect.bind(subscriptionManager_1); - this.unsubscribeAll = subscriptionManager_1.unsubscribeAll.bind(subscriptionManager_1); - this.getSubscribedChannels = subscriptionManager_1.getSubscribedChannels.bind(subscriptionManager_1); - this.getSubscribedChannelGroups = subscriptionManager_1.getSubscribedChannelGroups.bind(subscriptionManager_1); - this.setState = subscriptionManager_1.adaptStateChange.bind(subscriptionManager_1); - this.presence = subscriptionManager_1.adaptPresenceChange.bind(subscriptionManager_1); - this.destroy = function (isOffline) { - subscriptionManager_1.unsubscribeAll(isOffline); - subscriptionManager_1.disconnect(); - }; - } - this.addListener = this._eventEmitter.addListener.bind(this._eventEmitter); - this.removeListener = this._eventEmitter.removeListener.bind(this._eventEmitter); - this.removeAllListeners = this._eventEmitter.removeAllListeners.bind(this._eventEmitter); - this.parseToken = tokenManager.parseToken.bind(tokenManager); - this.setToken = tokenManager.setToken.bind(tokenManager); - this.getToken = tokenManager.getToken.bind(tokenManager); - /* channel groups */ - this.channelGroups = { - listGroups: endpointCreator.bind(this, modules, listChannelGroupsConfig), - listChannels: endpointCreator.bind(this, modules, listChannelsInChannelGroupConfig), - addChannels: endpointCreator.bind(this, modules, addChannelsChannelGroupConfig), - removeChannels: endpointCreator.bind(this, modules, removeChannelsChannelGroupConfig), - deleteGroup: endpointCreator.bind(this, modules, deleteChannelGroupConfig), - }; - /* push */ - this.push = { - addChannels: endpointCreator.bind(this, modules, addPushChannelsConfig), - removeChannels: endpointCreator.bind(this, modules, removePushChannelsConfig), - deleteDevice: endpointCreator.bind(this, modules, removeDevicePushConfig), - listChannels: endpointCreator.bind(this, modules, listPushChannelsConfig), - }; - /* presence */ - this.hereNow = endpointCreator.bind(this, modules, presenceHereNowConfig); - this.whereNow = endpointCreator.bind(this, modules, presenceWhereNowEndpointConfig); - this.getState = endpointCreator.bind(this, modules, presenceGetStateConfig); - /* PAM */ - this.grant = endpointCreator.bind(this, modules, grantEndpointConfig); - this.grantToken = endpointCreator.bind(this, modules, grantTokenEndpointConfig); - this.audit = endpointCreator.bind(this, modules, auditEndpointConfig); - this.revokeToken = endpointCreator.bind(this, modules, endpoint$2); - this.publish = endpointCreator.bind(this, modules, publishEndpointConfig); - this.fire = function (args, callback) { - args.replicate = false; - args.storeInHistory = false; - return _this.publish(args, callback); - }; - this.signal = endpointCreator.bind(this, modules, signalEndpointConfig); - this.history = endpointCreator.bind(this, modules, historyEndpointConfig); - this.deleteMessages = endpointCreator.bind(this, modules, deleteMessagesEndpointConfig); - this.messageCounts = endpointCreator.bind(this, modules, messageCountsEndpointConfig); - this.fetchMessages = endpointCreator.bind(this, modules, fetchMessagesEndpointConfig); - // Actions API - this.addMessageAction = endpointCreator.bind(this, modules, addMessageActionEndpointConfig); - this.removeMessageAction = endpointCreator.bind(this, modules, removeMessageActionEndpointConfig); - this.getMessageActions = endpointCreator.bind(this, modules, getMessageActionEndpointConfig); - // File Upload API v1 - this.listFiles = endpointCreator.bind(this, modules, endpoint$j); - var generateUploadUrl = endpointCreator.bind(this, modules, endpoint$i); - this.publishFile = endpointCreator.bind(this, modules, endpoint$h); - this.sendFile = sendFileFunction({ - generateUploadUrl: generateUploadUrl, - publishFile: this.publishFile, - modules: modules, - }); - this.getFileUrl = function (params) { return getFileUrlFunction(modules, params); }; - this.downloadFile = endpointCreator.bind(this, modules, endpoint$g); - this.deleteFile = endpointCreator.bind(this, modules, endpoint$f); - // entities - this.channel = function (name) { return new Channel(name, _this._eventEmitter, _this); }; - this.channelGroup = function (name) { return new ChannelGroup(name, _this._eventEmitter, _this); }; - this.channelMetadata = function (id) { return new ChannelMetadata(id, _this._eventEmitter, _this); }; - this.userMetadata = function (id) { return new UserMetadata(id, _this._eventEmitter, _this); }; - this.subscriptionSet = function (args) { - return new SubscriptionSet({ - channels: args.channels, - channelGroups: args.channelGroups, - subscriptionOptions: args.subscriptionOptions, - eventEmitter: _this._eventEmitter, - pubnub: _this, - }); - }; - // Objects API v2 - this.objects = { - getAllUUIDMetadata: endpointCreator.bind(this, modules, endpoint$e), - getUUIDMetadata: endpointCreator.bind(this, modules, endpoint$d), - setUUIDMetadata: endpointCreator.bind(this, modules, endpoint$c), - removeUUIDMetadata: endpointCreator.bind(this, modules, endpoint$b), - getAllChannelMetadata: endpointCreator.bind(this, modules, endpoint$a), - getChannelMetadata: endpointCreator.bind(this, modules, endpoint$9), - setChannelMetadata: endpointCreator.bind(this, modules, endpoint$8), - removeChannelMetadata: endpointCreator.bind(this, modules, endpoint$7), - getChannelMembers: endpointCreator.bind(this, modules, endpoint$6), - setChannelMembers: function (parameters) { - var rest = []; - for (var _i = 1; _i < arguments.length; _i++) { - rest[_i - 1] = arguments[_i]; - } - return endpointCreator.call.apply(endpointCreator, __spreadArray$1([_this, - modules, - endpoint$5, __assign({ type: 'set' }, parameters)], __read$1(rest), false)); - }, - removeChannelMembers: function (parameters) { - var rest = []; - for (var _i = 1; _i < arguments.length; _i++) { - rest[_i - 1] = arguments[_i]; - } - return endpointCreator.call.apply(endpointCreator, __spreadArray$1([_this, - modules, - endpoint$5, __assign({ type: 'delete' }, parameters)], __read$1(rest), false)); - }, - getMemberships: endpointCreator.bind(this, modules, endpoint$4), - setMemberships: function (parameters) { - var rest = []; - for (var _i = 1; _i < arguments.length; _i++) { - rest[_i - 1] = arguments[_i]; - } - return endpointCreator.call.apply(endpointCreator, __spreadArray$1([_this, - modules, - endpoint$3, __assign({ type: 'set' }, parameters)], __read$1(rest), false)); - }, - removeMemberships: function (parameters) { - var rest = []; - for (var _i = 1; _i < arguments.length; _i++) { - rest[_i - 1] = arguments[_i]; - } - return endpointCreator.call.apply(endpointCreator, __spreadArray$1([_this, - modules, - endpoint$3, __assign({ type: 'delete' }, parameters)], __read$1(rest), false)); - }, - }; - // User Apis - this.createUser = function (args) { - return _this.objects.setUUIDMetadata({ - uuid: args.userId, - data: args.data, - include: args.include, - }); - }; - this.updateUser = this.createUser; - this.removeUser = function (args) { - return _this.objects.removeUUIDMetadata({ - uuid: args === null || args === void 0 ? void 0 : args.userId, - }); - }; - this.fetchUser = function (args) { - return _this.objects.getUUIDMetadata({ - uuid: args === null || args === void 0 ? void 0 : args.userId, - include: args === null || args === void 0 ? void 0 : args.include, - }); - }; - this.fetchUsers = this.objects.getAllUUIDMetadata; - // Space apis - this.createSpace = function (args) { - return _this.objects.setChannelMetadata({ - channel: args.spaceId, - data: args.data, - include: args.include, - }); - }; - this.updateSpace = this.createSpace; - this.removeSpace = function (args) { - return _this.objects.removeChannelMetadata({ - channel: args.spaceId, - }); - }; - this.fetchSpace = function (args) { - return _this.objects.getChannelMetadata({ - channel: args.spaceId, - include: args.include, - }); - }; - this.fetchSpaces = this.objects.getAllChannelMetadata; - // Membership apis - this.addMemberships = function (parameters) { - var _a, _b; - if (typeof parameters.spaceId === 'string') { - return _this.objects.setChannelMembers({ - channel: parameters.spaceId, - uuids: (_a = parameters.users) === null || _a === void 0 ? void 0 : _a.map(function (user) { - if (typeof user === 'string') { - return user; - } - return { - id: user.userId, - custom: user.custom, - status: user.status, - }; - }), - limit: 0, - }); - } - else { - return _this.objects.setMemberships({ - uuid: parameters.userId, - channels: (_b = parameters.spaces) === null || _b === void 0 ? void 0 : _b.map(function (space) { - if (typeof space === 'string') { - return space; - } - return { - id: space.spaceId, - custom: space.custom, - status: space.status, - }; - }), - limit: 0, - }); - } - }; - this.updateMemberships = this.addMemberships; - this.removeMemberships = function (parameters) { - if (typeof parameters.spaceId === 'string') { - return _this.objects.removeChannelMembers({ - channel: parameters.spaceId, - uuids: parameters.userIds, - limit: 0, - }); - } - else { - return _this.objects.removeMemberships({ - uuid: parameters.userId, - channels: parameters.spaceIds, - limit: 0, - }); - } - }; - this.fetchMemberships = function (params) { - if (typeof params.spaceId === 'string') { - return _this.objects - .getChannelMembers({ - channel: params.spaceId, - filter: params.filter, - limit: params.limit, - page: params.page, - include: { - customFields: params.include.customFields, - UUIDFields: params.include.userFields, - customUUIDFields: params.include.customUserFields, - statusField: params.include.statusField, - UUIDStatusField: params.include.userStatusField, - UUIDTypeField: params.include.userTypeField, - totalCount: params.include.totalCount, - }, - sort: params.sort != null - ? Object.fromEntries(Object.entries(params.sort).map(function (_a) { - var _b = __read$1(_a, 2), k = _b[0], v = _b[1]; - return [k.replace('user', 'uuid'), v]; - })) - : null, - }) - .then(function (res) { - var _a; - res.data = (_a = res.data) === null || _a === void 0 ? void 0 : _a.map(function (m) { - return { - user: m.uuid, - custom: m.custom, - updated: m.updated, - eTag: m.eTag, - }; - }); - return res; - }); - } - else { - return _this.objects - .getMemberships({ - uuid: params.userId, - filter: params.filter, - limit: params.limit, - page: params.page, - include: { - customFields: params.include.customFields, - channelFields: params.include.spaceFields, - customChannelFields: params.include.customSpaceFields, - statusField: params.include.statusField, - channelStatusField: params.include.spaceStatusField, - channelTypeField: params.include.spaceTypeField, - totalCount: params.include.totalCount, - }, - sort: params.sort != null - ? Object.fromEntries(Object.entries(params.sort).map(function (_a) { - var _b = __read$1(_a, 2), k = _b[0], v = _b[1]; - return [k.replace('space', 'channel'), v]; - })) - : null, - }) - .then(function (res) { - var _a; - res.data = (_a = res.data) === null || _a === void 0 ? void 0 : _a.map(function (m) { - return { - space: m.channel, - custom: m.custom, - updated: m.updated, - eTag: m.eTag, - }; - }); - return res; - }); - } - }; - this.time = timeEndpoint; - // --- deprecated ------------------ - this.stop = this.destroy; // -------- - // --- deprecated ------------------ - // mount crypto - this.encrypt = function (data, key) { - if (typeof key === 'undefined' && modules.cryptoModule) { - var encrypted = modules.cryptoModule.encrypt(data); - return typeof encrypted === 'string' ? encrypted : encode$1(encrypted); - } - else { - return crypto.encrypt(data, key); - } - }; - this.decrypt = function (data, key) { - if (typeof key === 'undefined' && cryptoModule) { - var decrypted = modules.cryptoModule.decrypt(data); - return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted; - } - else { - return crypto.decrypt(data, key); - } - }; - /* config */ - this.getAuthKey = modules.config.getAuthKey.bind(modules.config); - this.setAuthKey = modules.config.setAuthKey.bind(modules.config); - this.getUUID = modules.config.getUUID.bind(modules.config); - this.setUUID = modules.config.setUUID.bind(modules.config); - this.getUserId = modules.config.getUserId.bind(modules.config); - this.setUserId = modules.config.setUserId.bind(modules.config); - this.getFilterExpression = modules.config.getFilterExpression.bind(modules.config); - this.setFilterExpression = modules.config.setFilterExpression.bind(modules.config); - this.setCipherKey = function (key) { return modules.config.setCipherKey(key, setup, modules); }; - this.setHeartbeatInterval = modules.config.setHeartbeatInterval.bind(modules.config); - if (networking.hasModule('proxy')) { - this.setProxy = function (proxy) { - modules.config.setProxy(proxy); - _this.reconnect(); - }; - } - } - default_1.prototype.getVersion = function () { - return this._config.getVersion(); - }; - default_1.prototype._addPnsdkSuffix = function (name, suffix) { - this._config._addPnsdkSuffix(name, suffix); - }; - // network hooks to indicate network changes - default_1.prototype.networkDownDetected = function () { - this._listenerManager.announceNetworkDown(); - if (this._config.restore) { - this.disconnect(); - } - else { - this.destroy(true); - } - }; - default_1.prototype.networkUpDetected = function () { - this._listenerManager.announceNetworkUp(); - this.reconnect(); - }; - default_1.notificationPayload = function (title, body) { - return new NotificationsPayload(title, body); - }; - default_1.generateUUID = function () { - return uuidGenerator.createUUID(); - }; - default_1.OPERATIONS = OPERATIONS; - default_1.CATEGORIES = categories; - default_1.LinearRetryPolicy = RetryPolicy.LinearRetryPolicy; - default_1.ExponentialRetryPolicy = RetryPolicy.ExponentialRetryPolicy; - return default_1; - }()); - - /* */ - var default_1$2 = /** @class */ (function () { - function default_1(modules) { - var _this = this; - this._modules = {}; - Object.keys(modules).forEach(function (key) { - _this._modules[key] = modules[key].bind(_this); - }); - } - default_1.prototype.init = function (config) { - this._config = config; - if (Array.isArray(this._config.origin)) { - this._currentSubDomain = Math.floor(Math.random() * this._config.origin.length); - } - else { - this._currentSubDomain = 0; - } - this._coreParams = {}; - // create initial origins - this.shiftStandardOrigin(); - }; - default_1.prototype.nextOrigin = function () { - var protocol = this._config.secure ? 'https://' : 'http://'; - if (typeof this._config.origin === 'string') { - return "".concat(protocol).concat(this._config.origin); - } - this._currentSubDomain += 1; - if (this._currentSubDomain >= this._config.origin.length) { - this._currentSubDomain = 0; - } - var origin = this._config.origin[this._currentSubDomain]; - return "".concat(protocol).concat(origin); - }; - default_1.prototype.hasModule = function (name) { - return name in this._modules; - }; - // origin operations - default_1.prototype.shiftStandardOrigin = function () { - this._standardOrigin = this.nextOrigin(); - return this._standardOrigin; - }; - default_1.prototype.getStandardOrigin = function () { - return this._standardOrigin; - }; - default_1.prototype.POSTFILE = function (url, fields, file) { - return this._modules.postfile(url, fields, file); - }; - default_1.prototype.GETFILE = function (params, endpoint, callback) { - return this._modules.getfile(params, endpoint, callback); - }; - default_1.prototype.POST = function (params, body, endpoint, callback) { - return this._modules.post(params, body, endpoint, callback); - }; - default_1.prototype.PATCH = function (params, body, endpoint, callback) { - return this._modules.patch(params, body, endpoint, callback); - }; - default_1.prototype.GET = function (params, endpoint, callback) { - return this._modules.get(params, endpoint, callback); - }; - default_1.prototype.DELETE = function (params, endpoint, callback) { - return this._modules.del(params, endpoint, callback); - }; - default_1.prototype._detectErrorCategory = function (err) { - if (err.code === 'ENOTFOUND') { - return categories.PNNetworkIssuesCategory; - } - if (err.code === 'ECONNREFUSED') { - return categories.PNNetworkIssuesCategory; - } - if (err.code === 'ECONNRESET') { - return categories.PNNetworkIssuesCategory; - } - if (err.code === 'EAI_AGAIN') { - return categories.PNNetworkIssuesCategory; - } - if (err.status === 0 || (err.hasOwnProperty('status') && typeof err.status === 'undefined')) { - return categories.PNNetworkIssuesCategory; - } - if (err.timeout) - return categories.PNTimeoutCategory; - if (err.code === 'ETIMEDOUT') { - return categories.PNNetworkIssuesCategory; - } - if (err.response) { - if (err.response.badRequest) { - return categories.PNBadRequestCategory; - } - if (err.response.forbidden) { - return categories.PNAccessDeniedCategory; - } - } - return categories.PNUnknownCategory; - }; - return default_1; - }()); - - function stringifyBufferKeys(obj) { - var isObject = function (value) { return value && typeof value === 'object' && value.constructor === Object; }; - var isString = function (value) { return typeof value === 'string' || value instanceof String; }; - var isNumber = function (value) { return typeof value === 'number' && isFinite(value); }; - if (!isObject(obj)) { - return obj; - } - var normalizedObject = {}; - Object.keys(obj).forEach(function (key) { - var keyIsString = isString(key); - var stringifiedKey = key; - var value = obj[key]; - if (Array.isArray(key) || (keyIsString && key.indexOf(',') >= 0)) { - var bytes = keyIsString ? key.split(',') : key; - stringifiedKey = bytes.reduce(function (string, byte) { - string += String.fromCharCode(byte); - return string; - }, ''); - } - else if (isNumber(key) || (keyIsString && !isNaN(key))) { - stringifiedKey = String.fromCharCode(keyIsString ? parseInt(key, 10) : 10); - } - normalizedObject[stringifiedKey] = isObject(value) ? stringifyBufferKeys(value) : value; - }); - return normalizedObject; - } - - var default_1$1 = /** @class */ (function () { - function default_1(decode, base64ToBinary) { - this._base64ToBinary = base64ToBinary; - this._decode = decode; - } - default_1.prototype.decodeToken = function (tokenString) { - var padding = ''; - if (tokenString.length % 4 === 3) { - padding = '='; - } - else if (tokenString.length % 4 === 2) { - padding = '=='; - } - var cleaned = tokenString.replace(/-/gi, '+').replace(/_/gi, '/') + padding; - var result = this._decode(this._base64ToBinary(cleaned)); - if (typeof result === 'object') { - return result; - } - return undefined; - }; - return default_1; - }()); - - var client = {exports: {}}; - - var componentEmitter = {exports: {}}; - - (function (module) { - /** - * Expose `Emitter`. - */ - - { - module.exports = Emitter; - } - - /** - * Initialize a new `Emitter`. - * - * @api public - */ - - function Emitter(obj) { - if (obj) return mixin(obj); - } - /** - * Mixin the emitter properties. - * - * @param {Object} obj - * @return {Object} - * @api private - */ - - function mixin(obj) { - for (var key in Emitter.prototype) { - obj[key] = Emitter.prototype[key]; - } - return obj; - } - - /** - * Listen on the given `event` with `fn`. - * - * @param {String} event - * @param {Function} fn - * @return {Emitter} - * @api public - */ - - Emitter.prototype.on = - Emitter.prototype.addEventListener = function(event, fn){ - this._callbacks = this._callbacks || {}; - (this._callbacks['$' + event] = this._callbacks['$' + event] || []) - .push(fn); - return this; - }; - - /** - * Adds an `event` listener that will be invoked a single - * time then automatically removed. - * - * @param {String} event - * @param {Function} fn - * @return {Emitter} - * @api public - */ - - Emitter.prototype.once = function(event, fn){ - function on() { - this.off(event, on); - fn.apply(this, arguments); - } - - on.fn = fn; - this.on(event, on); - return this; - }; - - /** - * Remove the given callback for `event` or all - * registered callbacks. - * - * @param {String} event - * @param {Function} fn - * @return {Emitter} - * @api public - */ - - Emitter.prototype.off = - Emitter.prototype.removeListener = - Emitter.prototype.removeAllListeners = - Emitter.prototype.removeEventListener = function(event, fn){ - this._callbacks = this._callbacks || {}; - - // all - if (0 == arguments.length) { - this._callbacks = {}; - return this; - } - - // specific event - var callbacks = this._callbacks['$' + event]; - if (!callbacks) return this; - - // remove all handlers - if (1 == arguments.length) { - delete this._callbacks['$' + event]; - return this; - } - - // remove specific handler - var cb; - for (var i = 0; i < callbacks.length; i++) { - cb = callbacks[i]; - if (cb === fn || cb.fn === fn) { - callbacks.splice(i, 1); - break; - } - } - - // Remove event specific arrays for event types that no - // one is subscribed for to avoid memory leak. - if (callbacks.length === 0) { - delete this._callbacks['$' + event]; - } - - return this; - }; - - /** - * Emit `event` with the given args. - * - * @param {String} event - * @param {Mixed} ... - * @return {Emitter} - */ - - Emitter.prototype.emit = function(event){ - this._callbacks = this._callbacks || {}; - - var args = new Array(arguments.length - 1) - , callbacks = this._callbacks['$' + event]; - - for (var i = 1; i < arguments.length; i++) { - args[i - 1] = arguments[i]; - } - - if (callbacks) { - callbacks = callbacks.slice(0); - for (var i = 0, len = callbacks.length; i < len; ++i) { - callbacks[i].apply(this, args); - } - } - - return this; - }; - - /** - * Return array of callbacks for `event`. - * - * @param {String} event - * @return {Array} - * @api public - */ - - Emitter.prototype.listeners = function(event){ - this._callbacks = this._callbacks || {}; - return this._callbacks['$' + event] || []; - }; - - /** - * Check if this emitter has `event` handlers. - * - * @param {String} event - * @return {Boolean} - * @api public - */ - - Emitter.prototype.hasListeners = function(event){ - return !! this.listeners(event).length; - }; - }(componentEmitter)); - - var fastSafeStringify = stringify$2; - stringify$2.default = stringify$2; - stringify$2.stable = deterministicStringify; - stringify$2.stableStringify = deterministicStringify; - - var LIMIT_REPLACE_NODE = '[...]'; - var CIRCULAR_REPLACE_NODE = '[Circular]'; - - var arr = []; - var replacerStack = []; - - function defaultOptions () { - return { - depthLimit: Number.MAX_SAFE_INTEGER, - edgesLimit: Number.MAX_SAFE_INTEGER - } - } - - // Regular stringify - function stringify$2 (obj, replacer, spacer, options) { - if (typeof options === 'undefined') { - options = defaultOptions(); - } - - decirc(obj, '', 0, [], undefined, 0, options); - var res; - try { - if (replacerStack.length === 0) { - res = JSON.stringify(obj, replacer, spacer); - } else { - res = JSON.stringify(obj, replaceGetterValues(replacer), spacer); - } - } catch (_) { - return JSON.stringify('[unable to serialize, circular reference is too complex to analyze]') - } finally { - while (arr.length !== 0) { - var part = arr.pop(); - if (part.length === 4) { - Object.defineProperty(part[0], part[1], part[3]); - } else { - part[0][part[1]] = part[2]; - } - } - } - return res - } - - function setReplace (replace, val, k, parent) { - var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k); - if (propertyDescriptor.get !== undefined) { - if (propertyDescriptor.configurable) { - Object.defineProperty(parent, k, { value: replace }); - arr.push([parent, k, val, propertyDescriptor]); - } else { - replacerStack.push([val, k, replace]); - } - } else { - parent[k] = replace; - arr.push([parent, k, val]); - } - } - - function decirc (val, k, edgeIndex, stack, parent, depth, options) { - depth += 1; - var i; - if (typeof val === 'object' && val !== null) { - for (i = 0; i < stack.length; i++) { - if (stack[i] === val) { - setReplace(CIRCULAR_REPLACE_NODE, val, k, parent); - return - } - } - - if ( - typeof options.depthLimit !== 'undefined' && - depth > options.depthLimit - ) { - setReplace(LIMIT_REPLACE_NODE, val, k, parent); - return - } - - if ( - typeof options.edgesLimit !== 'undefined' && - edgeIndex + 1 > options.edgesLimit - ) { - setReplace(LIMIT_REPLACE_NODE, val, k, parent); - return - } - - stack.push(val); - // Optimize for Arrays. Big arrays could kill the performance otherwise! - if (Array.isArray(val)) { - for (i = 0; i < val.length; i++) { - decirc(val[i], i, i, stack, val, depth, options); - } - } else { - var keys = Object.keys(val); - for (i = 0; i < keys.length; i++) { - var key = keys[i]; - decirc(val[key], key, i, stack, val, depth, options); - } - } - stack.pop(); - } - } - - // Stable-stringify - function compareFunction (a, b) { - if (a < b) { - return -1 - } - if (a > b) { - return 1 - } - return 0 - } - - function deterministicStringify (obj, replacer, spacer, options) { - if (typeof options === 'undefined') { - options = defaultOptions(); - } - - var tmp = deterministicDecirc(obj, '', 0, [], undefined, 0, options) || obj; - var res; - try { - if (replacerStack.length === 0) { - res = JSON.stringify(tmp, replacer, spacer); - } else { - res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer); - } - } catch (_) { - return JSON.stringify('[unable to serialize, circular reference is too complex to analyze]') - } finally { - // Ensure that we restore the object as it was. - while (arr.length !== 0) { - var part = arr.pop(); - if (part.length === 4) { - Object.defineProperty(part[0], part[1], part[3]); - } else { - part[0][part[1]] = part[2]; - } - } - } - return res - } - - function deterministicDecirc (val, k, edgeIndex, stack, parent, depth, options) { - depth += 1; - var i; - if (typeof val === 'object' && val !== null) { - for (i = 0; i < stack.length; i++) { - if (stack[i] === val) { - setReplace(CIRCULAR_REPLACE_NODE, val, k, parent); - return - } - } - try { - if (typeof val.toJSON === 'function') { - return - } - } catch (_) { - return - } - - if ( - typeof options.depthLimit !== 'undefined' && - depth > options.depthLimit - ) { - setReplace(LIMIT_REPLACE_NODE, val, k, parent); - return - } - - if ( - typeof options.edgesLimit !== 'undefined' && - edgeIndex + 1 > options.edgesLimit - ) { - setReplace(LIMIT_REPLACE_NODE, val, k, parent); - return - } - - stack.push(val); - // Optimize for Arrays. Big arrays could kill the performance otherwise! - if (Array.isArray(val)) { - for (i = 0; i < val.length; i++) { - deterministicDecirc(val[i], i, i, stack, val, depth, options); - } - } else { - // Create a temporary object in the required way - var tmp = {}; - var keys = Object.keys(val).sort(compareFunction); - for (i = 0; i < keys.length; i++) { - var key = keys[i]; - deterministicDecirc(val[key], key, i, stack, val, depth, options); - tmp[key] = val[key]; - } - if (typeof parent !== 'undefined') { - arr.push([parent, k, val]); - parent[k] = tmp; - } else { - return tmp - } - } - stack.pop(); - } - } - - // wraps replacer function to handle values we couldn't replace - // and mark them as replaced value - function replaceGetterValues (replacer) { - replacer = - typeof replacer !== 'undefined' - ? replacer - : function (k, v) { - return v - }; - return function (key, val) { - if (replacerStack.length > 0) { - for (var i = 0; i < replacerStack.length; i++) { - var part = replacerStack[i]; - if (part[1] === key && part[0] === val) { - val = part[2]; - replacerStack.splice(i, 1); - break - } - } - } - return replacer.call(this, key, val) - } - } - - /* eslint complexity: [2, 18], max-statements: [2, 33] */ - var shams = function hasSymbols() { - if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; } - if (typeof Symbol.iterator === 'symbol') { return true; } - - var obj = {}; - var sym = Symbol('test'); - var symObj = Object(sym); - if (typeof sym === 'string') { return false; } - - if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; } - if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; } - - // temp disabled per https://github.com/ljharb/object.assign/issues/17 - // if (sym instanceof Symbol) { return false; } - // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4 - // if (!(symObj instanceof Symbol)) { return false; } - - // if (typeof Symbol.prototype.toString !== 'function') { return false; } - // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; } - - var symVal = 42; - obj[sym] = symVal; - for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax, no-unreachable-loop - if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; } - - if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; } - - var syms = Object.getOwnPropertySymbols(obj); - if (syms.length !== 1 || syms[0] !== sym) { return false; } - - if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; } - - if (typeof Object.getOwnPropertyDescriptor === 'function') { - var descriptor = Object.getOwnPropertyDescriptor(obj, sym); - if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; } - } - - return true; - }; - - var origSymbol = typeof Symbol !== 'undefined' && Symbol; - var hasSymbolSham = shams; - - var hasSymbols$1 = function hasNativeSymbols() { - if (typeof origSymbol !== 'function') { return false; } - if (typeof Symbol !== 'function') { return false; } - if (typeof origSymbol('foo') !== 'symbol') { return false; } - if (typeof Symbol('bar') !== 'symbol') { return false; } - - return hasSymbolSham(); - }; - - /* eslint no-invalid-this: 1 */ - - var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible '; - var slice = Array.prototype.slice; - var toStr$1 = Object.prototype.toString; - var funcType = '[object Function]'; - - var implementation$1 = function bind(that) { - var target = this; - if (typeof target !== 'function' || toStr$1.call(target) !== funcType) { - throw new TypeError(ERROR_MESSAGE + target); - } - var args = slice.call(arguments, 1); - - var bound; - var binder = function () { - if (this instanceof bound) { - var result = target.apply( - this, - args.concat(slice.call(arguments)) - ); - if (Object(result) === result) { - return result; - } - return this; - } else { - return target.apply( - that, - args.concat(slice.call(arguments)) - ); - } - }; - - var boundLength = Math.max(0, target.length - args.length); - var boundArgs = []; - for (var i = 0; i < boundLength; i++) { - boundArgs.push('$' + i); - } - - bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder); - - if (target.prototype) { - var Empty = function Empty() {}; - Empty.prototype = target.prototype; - bound.prototype = new Empty(); - Empty.prototype = null; - } - - return bound; - }; - - var implementation = implementation$1; - - var functionBind = Function.prototype.bind || implementation; - - var bind$1 = functionBind; - - var src = bind$1.call(Function.call, Object.prototype.hasOwnProperty); - - var undefined$1; - - var $SyntaxError = SyntaxError; - var $Function = Function; - var $TypeError$1 = TypeError; - - // eslint-disable-next-line consistent-return - var getEvalledConstructor = function (expressionSyntax) { - try { - return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')(); - } catch (e) {} - }; - - var $gOPD = Object.getOwnPropertyDescriptor; - if ($gOPD) { - try { - $gOPD({}, ''); - } catch (e) { - $gOPD = null; // this is IE 8, which has a broken gOPD - } - } - - var throwTypeError = function () { - throw new $TypeError$1(); - }; - var ThrowTypeError = $gOPD - ? (function () { - try { - // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties - arguments.callee; // IE 8 does not throw here - return throwTypeError; - } catch (calleeThrows) { - try { - // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '') - return $gOPD(arguments, 'callee').get; - } catch (gOPDthrows) { - return throwTypeError; - } - } - }()) - : throwTypeError; - - var hasSymbols = hasSymbols$1(); - - var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto - - var needsEval = {}; - - var TypedArray = typeof Uint8Array === 'undefined' ? undefined$1 : getProto(Uint8Array); - - var INTRINSICS = { - '%AggregateError%': typeof AggregateError === 'undefined' ? undefined$1 : AggregateError, - '%Array%': Array, - '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer, - '%ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined$1, - '%AsyncFromSyncIteratorPrototype%': undefined$1, - '%AsyncFunction%': needsEval, - '%AsyncGenerator%': needsEval, - '%AsyncGeneratorFunction%': needsEval, - '%AsyncIteratorPrototype%': needsEval, - '%Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics, - '%BigInt%': typeof BigInt === 'undefined' ? undefined$1 : BigInt, - '%Boolean%': Boolean, - '%DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView, - '%Date%': Date, - '%decodeURI%': decodeURI, - '%decodeURIComponent%': decodeURIComponent, - '%encodeURI%': encodeURI, - '%encodeURIComponent%': encodeURIComponent, - '%Error%': Error, - '%eval%': eval, // eslint-disable-line no-eval - '%EvalError%': EvalError, - '%Float32Array%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array, - '%Float64Array%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array, - '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined$1 : FinalizationRegistry, - '%Function%': $Function, - '%GeneratorFunction%': needsEval, - '%Int8Array%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array, - '%Int16Array%': typeof Int16Array === 'undefined' ? undefined$1 : Int16Array, - '%Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array, - '%isFinite%': isFinite, - '%isNaN%': isNaN, - '%IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined$1, - '%JSON%': typeof JSON === 'object' ? JSON : undefined$1, - '%Map%': typeof Map === 'undefined' ? undefined$1 : Map, - '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined$1 : getProto(new Map()[Symbol.iterator]()), - '%Math%': Math, - '%Number%': Number, - '%Object%': Object, - '%parseFloat%': parseFloat, - '%parseInt%': parseInt, - '%Promise%': typeof Promise === 'undefined' ? undefined$1 : Promise, - '%Proxy%': typeof Proxy === 'undefined' ? undefined$1 : Proxy, - '%RangeError%': RangeError, - '%ReferenceError%': ReferenceError, - '%Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect, - '%RegExp%': RegExp, - '%Set%': typeof Set === 'undefined' ? undefined$1 : Set, - '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined$1 : getProto(new Set()[Symbol.iterator]()), - '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer, - '%String%': String, - '%StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined$1, - '%Symbol%': hasSymbols ? Symbol : undefined$1, - '%SyntaxError%': $SyntaxError, - '%ThrowTypeError%': ThrowTypeError, - '%TypedArray%': TypedArray, - '%TypeError%': $TypeError$1, - '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array, - '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray, - '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array, - '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array, - '%URIError%': URIError, - '%WeakMap%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap, - '%WeakRef%': typeof WeakRef === 'undefined' ? undefined$1 : WeakRef, - '%WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet - }; - - var doEval = function doEval(name) { - var value; - if (name === '%AsyncFunction%') { - value = getEvalledConstructor('async function () {}'); - } else if (name === '%GeneratorFunction%') { - value = getEvalledConstructor('function* () {}'); - } else if (name === '%AsyncGeneratorFunction%') { - value = getEvalledConstructor('async function* () {}'); - } else if (name === '%AsyncGenerator%') { - var fn = doEval('%AsyncGeneratorFunction%'); - if (fn) { - value = fn.prototype; - } - } else if (name === '%AsyncIteratorPrototype%') { - var gen = doEval('%AsyncGenerator%'); - if (gen) { - value = getProto(gen.prototype); - } - } - - INTRINSICS[name] = value; - - return value; - }; - - var LEGACY_ALIASES = { - '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'], - '%ArrayPrototype%': ['Array', 'prototype'], - '%ArrayProto_entries%': ['Array', 'prototype', 'entries'], - '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'], - '%ArrayProto_keys%': ['Array', 'prototype', 'keys'], - '%ArrayProto_values%': ['Array', 'prototype', 'values'], - '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'], - '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'], - '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'], - '%BooleanPrototype%': ['Boolean', 'prototype'], - '%DataViewPrototype%': ['DataView', 'prototype'], - '%DatePrototype%': ['Date', 'prototype'], - '%ErrorPrototype%': ['Error', 'prototype'], - '%EvalErrorPrototype%': ['EvalError', 'prototype'], - '%Float32ArrayPrototype%': ['Float32Array', 'prototype'], - '%Float64ArrayPrototype%': ['Float64Array', 'prototype'], - '%FunctionPrototype%': ['Function', 'prototype'], - '%Generator%': ['GeneratorFunction', 'prototype'], - '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'], - '%Int8ArrayPrototype%': ['Int8Array', 'prototype'], - '%Int16ArrayPrototype%': ['Int16Array', 'prototype'], - '%Int32ArrayPrototype%': ['Int32Array', 'prototype'], - '%JSONParse%': ['JSON', 'parse'], - '%JSONStringify%': ['JSON', 'stringify'], - '%MapPrototype%': ['Map', 'prototype'], - '%NumberPrototype%': ['Number', 'prototype'], - '%ObjectPrototype%': ['Object', 'prototype'], - '%ObjProto_toString%': ['Object', 'prototype', 'toString'], - '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'], - '%PromisePrototype%': ['Promise', 'prototype'], - '%PromiseProto_then%': ['Promise', 'prototype', 'then'], - '%Promise_all%': ['Promise', 'all'], - '%Promise_reject%': ['Promise', 'reject'], - '%Promise_resolve%': ['Promise', 'resolve'], - '%RangeErrorPrototype%': ['RangeError', 'prototype'], - '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'], - '%RegExpPrototype%': ['RegExp', 'prototype'], - '%SetPrototype%': ['Set', 'prototype'], - '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'], - '%StringPrototype%': ['String', 'prototype'], - '%SymbolPrototype%': ['Symbol', 'prototype'], - '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'], - '%TypedArrayPrototype%': ['TypedArray', 'prototype'], - '%TypeErrorPrototype%': ['TypeError', 'prototype'], - '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'], - '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'], - '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'], - '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'], - '%URIErrorPrototype%': ['URIError', 'prototype'], - '%WeakMapPrototype%': ['WeakMap', 'prototype'], - '%WeakSetPrototype%': ['WeakSet', 'prototype'] - }; - - var bind = functionBind; - var hasOwn$2 = src; - var $concat$1 = bind.call(Function.call, Array.prototype.concat); - var $spliceApply = bind.call(Function.apply, Array.prototype.splice); - var $replace$1 = bind.call(Function.call, String.prototype.replace); - var $strSlice = bind.call(Function.call, String.prototype.slice); - - /* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */ - var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g; - var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */ - var stringToPath = function stringToPath(string) { - var first = $strSlice(string, 0, 1); - var last = $strSlice(string, -1); - if (first === '%' && last !== '%') { - throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`'); - } else if (last === '%' && first !== '%') { - throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`'); - } - var result = []; - $replace$1(string, rePropName, function (match, number, quote, subString) { - result[result.length] = quote ? $replace$1(subString, reEscapeChar, '$1') : number || match; - }); - return result; - }; - /* end adaptation */ - - var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) { - var intrinsicName = name; - var alias; - if (hasOwn$2(LEGACY_ALIASES, intrinsicName)) { - alias = LEGACY_ALIASES[intrinsicName]; - intrinsicName = '%' + alias[0] + '%'; - } - - if (hasOwn$2(INTRINSICS, intrinsicName)) { - var value = INTRINSICS[intrinsicName]; - if (value === needsEval) { - value = doEval(intrinsicName); - } - if (typeof value === 'undefined' && !allowMissing) { - throw new $TypeError$1('intrinsic ' + name + ' exists, but is not available. Please file an issue!'); - } - - return { - alias: alias, - name: intrinsicName, - value: value - }; - } - - throw new $SyntaxError('intrinsic ' + name + ' does not exist!'); - }; - - var getIntrinsic = function GetIntrinsic(name, allowMissing) { - if (typeof name !== 'string' || name.length === 0) { - throw new $TypeError$1('intrinsic name must be a non-empty string'); - } - if (arguments.length > 1 && typeof allowMissing !== 'boolean') { - throw new $TypeError$1('"allowMissing" argument must be a boolean'); - } - - var parts = stringToPath(name); - var intrinsicBaseName = parts.length > 0 ? parts[0] : ''; - - var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing); - var intrinsicRealName = intrinsic.name; - var value = intrinsic.value; - var skipFurtherCaching = false; - - var alias = intrinsic.alias; - if (alias) { - intrinsicBaseName = alias[0]; - $spliceApply(parts, $concat$1([0, 1], alias)); - } - - for (var i = 1, isOwn = true; i < parts.length; i += 1) { - var part = parts[i]; - var first = $strSlice(part, 0, 1); - var last = $strSlice(part, -1); - if ( - ( - (first === '"' || first === "'" || first === '`') - || (last === '"' || last === "'" || last === '`') - ) - && first !== last - ) { - throw new $SyntaxError('property names with quotes must have matching quotes'); - } - if (part === 'constructor' || !isOwn) { - skipFurtherCaching = true; - } - - intrinsicBaseName += '.' + part; - intrinsicRealName = '%' + intrinsicBaseName + '%'; - - if (hasOwn$2(INTRINSICS, intrinsicRealName)) { - value = INTRINSICS[intrinsicRealName]; - } else if (value != null) { - if (!(part in value)) { - if (!allowMissing) { - throw new $TypeError$1('base intrinsic for ' + name + ' exists, but the property is not available.'); - } - return void undefined$1; - } - if ($gOPD && (i + 1) >= parts.length) { - var desc = $gOPD(value, part); - isOwn = !!desc; - - // By convention, when a data property is converted to an accessor - // property to emulate a data property that does not suffer from - // the override mistake, that accessor's getter is marked with - // an `originalValue` property. Here, when we detect this, we - // uphold the illusion by pretending to see that original data - // property, i.e., returning the value rather than the getter - // itself. - if (isOwn && 'get' in desc && !('originalValue' in desc.get)) { - value = desc.get; - } else { - value = value[part]; - } - } else { - isOwn = hasOwn$2(value, part); - value = value[part]; - } - - if (isOwn && !skipFurtherCaching) { - INTRINSICS[intrinsicRealName] = value; - } - } - } - return value; - }; - - var callBind$1 = {exports: {}}; - - (function (module) { - - var bind = functionBind; - var GetIntrinsic = getIntrinsic; - - var $apply = GetIntrinsic('%Function.prototype.apply%'); - var $call = GetIntrinsic('%Function.prototype.call%'); - var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply); - - var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true); - var $defineProperty = GetIntrinsic('%Object.defineProperty%', true); - var $max = GetIntrinsic('%Math.max%'); - - if ($defineProperty) { - try { - $defineProperty({}, 'a', { value: 1 }); - } catch (e) { - // IE 8 has a broken defineProperty - $defineProperty = null; - } - } - - module.exports = function callBind(originalFunction) { - var func = $reflectApply(bind, $call, arguments); - if ($gOPD && $defineProperty) { - var desc = $gOPD(func, 'length'); - if (desc.configurable) { - // original length, plus the receiver, minus any additional arguments (after the receiver) - $defineProperty( - func, - 'length', - { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) } - ); - } - } - return func; - }; - - var applyBind = function applyBind() { - return $reflectApply(bind, $apply, arguments); - }; - - if ($defineProperty) { - $defineProperty(module.exports, 'apply', { value: applyBind }); - } else { - module.exports.apply = applyBind; - } - }(callBind$1)); - - var GetIntrinsic$1 = getIntrinsic; - - var callBind = callBind$1.exports; - - var $indexOf = callBind(GetIntrinsic$1('String.prototype.indexOf')); - - var callBound$1 = function callBoundIntrinsic(name, allowMissing) { - var intrinsic = GetIntrinsic$1(name, !!allowMissing); - if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) { - return callBind(intrinsic); - } - return intrinsic; - }; - - var _nodeResolve_empty = {}; - - var _nodeResolve_empty$1 = /*#__PURE__*/Object.freeze({ - __proto__: null, - 'default': _nodeResolve_empty - }); - - var require$$0 = /*@__PURE__*/getAugmentedNamespace(_nodeResolve_empty$1); - - var hasMap = typeof Map === 'function' && Map.prototype; - var mapSizeDescriptor = Object.getOwnPropertyDescriptor && hasMap ? Object.getOwnPropertyDescriptor(Map.prototype, 'size') : null; - var mapSize = hasMap && mapSizeDescriptor && typeof mapSizeDescriptor.get === 'function' ? mapSizeDescriptor.get : null; - var mapForEach = hasMap && Map.prototype.forEach; - var hasSet = typeof Set === 'function' && Set.prototype; - var setSizeDescriptor = Object.getOwnPropertyDescriptor && hasSet ? Object.getOwnPropertyDescriptor(Set.prototype, 'size') : null; - var setSize = hasSet && setSizeDescriptor && typeof setSizeDescriptor.get === 'function' ? setSizeDescriptor.get : null; - var setForEach = hasSet && Set.prototype.forEach; - var hasWeakMap = typeof WeakMap === 'function' && WeakMap.prototype; - var weakMapHas = hasWeakMap ? WeakMap.prototype.has : null; - var hasWeakSet = typeof WeakSet === 'function' && WeakSet.prototype; - var weakSetHas = hasWeakSet ? WeakSet.prototype.has : null; - var hasWeakRef = typeof WeakRef === 'function' && WeakRef.prototype; - var weakRefDeref = hasWeakRef ? WeakRef.prototype.deref : null; - var booleanValueOf = Boolean.prototype.valueOf; - var objectToString = Object.prototype.toString; - var functionToString = Function.prototype.toString; - var $match = String.prototype.match; - var $slice = String.prototype.slice; - var $replace = String.prototype.replace; - var $toUpperCase = String.prototype.toUpperCase; - var $toLowerCase = String.prototype.toLowerCase; - var $test = RegExp.prototype.test; - var $concat = Array.prototype.concat; - var $join = Array.prototype.join; - var $arrSlice = Array.prototype.slice; - var $floor = Math.floor; - var bigIntValueOf = typeof BigInt === 'function' ? BigInt.prototype.valueOf : null; - var gOPS = Object.getOwnPropertySymbols; - var symToString = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol' ? Symbol.prototype.toString : null; - var hasShammedSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'object'; - // ie, `has-tostringtag/shams - var toStringTag = typeof Symbol === 'function' && Symbol.toStringTag && (typeof Symbol.toStringTag === hasShammedSymbols ? 'object' : 'symbol') - ? Symbol.toStringTag - : null; - var isEnumerable = Object.prototype.propertyIsEnumerable; - - var gPO = (typeof Reflect === 'function' ? Reflect.getPrototypeOf : Object.getPrototypeOf) || ( - [].__proto__ === Array.prototype // eslint-disable-line no-proto - ? function (O) { - return O.__proto__; // eslint-disable-line no-proto - } - : null - ); - - function addNumericSeparator(num, str) { - if ( - num === Infinity - || num === -Infinity - || num !== num - || (num && num > -1000 && num < 1000) - || $test.call(/e/, str) - ) { - return str; - } - var sepRegex = /[0-9](?=(?:[0-9]{3})+(?![0-9]))/g; - if (typeof num === 'number') { - var int = num < 0 ? -$floor(-num) : $floor(num); // trunc(num) - if (int !== num) { - var intStr = String(int); - var dec = $slice.call(str, intStr.length + 1); - return $replace.call(intStr, sepRegex, '$&_') + '.' + $replace.call($replace.call(dec, /([0-9]{3})/g, '$&_'), /_$/, ''); - } - } - return $replace.call(str, sepRegex, '$&_'); - } - - var utilInspect = require$$0; - var inspectCustom = utilInspect.custom; - var inspectSymbol = isSymbol(inspectCustom) ? inspectCustom : null; - - var objectInspect = function inspect_(obj, options, depth, seen) { - var opts = options || {}; - - if (has$3(opts, 'quoteStyle') && (opts.quoteStyle !== 'single' && opts.quoteStyle !== 'double')) { - throw new TypeError('option "quoteStyle" must be "single" or "double"'); - } - if ( - has$3(opts, 'maxStringLength') && (typeof opts.maxStringLength === 'number' - ? opts.maxStringLength < 0 && opts.maxStringLength !== Infinity - : opts.maxStringLength !== null - ) - ) { - throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`'); - } - var customInspect = has$3(opts, 'customInspect') ? opts.customInspect : true; - if (typeof customInspect !== 'boolean' && customInspect !== 'symbol') { - throw new TypeError('option "customInspect", if provided, must be `true`, `false`, or `\'symbol\'`'); - } - - if ( - has$3(opts, 'indent') - && opts.indent !== null - && opts.indent !== '\t' - && !(parseInt(opts.indent, 10) === opts.indent && opts.indent > 0) - ) { - throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`'); - } - if (has$3(opts, 'numericSeparator') && typeof opts.numericSeparator !== 'boolean') { - throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`'); - } - var numericSeparator = opts.numericSeparator; - - if (typeof obj === 'undefined') { - return 'undefined'; - } - if (obj === null) { - return 'null'; - } - if (typeof obj === 'boolean') { - return obj ? 'true' : 'false'; - } - - if (typeof obj === 'string') { - return inspectString(obj, opts); - } - if (typeof obj === 'number') { - if (obj === 0) { - return Infinity / obj > 0 ? '0' : '-0'; - } - var str = String(obj); - return numericSeparator ? addNumericSeparator(obj, str) : str; - } - if (typeof obj === 'bigint') { - var bigIntStr = String(obj) + 'n'; - return numericSeparator ? addNumericSeparator(obj, bigIntStr) : bigIntStr; - } - - var maxDepth = typeof opts.depth === 'undefined' ? 5 : opts.depth; - if (typeof depth === 'undefined') { depth = 0; } - if (depth >= maxDepth && maxDepth > 0 && typeof obj === 'object') { - return isArray$3(obj) ? '[Array]' : '[Object]'; - } - - var indent = getIndent(opts, depth); - - if (typeof seen === 'undefined') { - seen = []; - } else if (indexOf(seen, obj) >= 0) { - return '[Circular]'; - } - - function inspect(value, from, noIndent) { - if (from) { - seen = $arrSlice.call(seen); - seen.push(from); - } - if (noIndent) { - var newOpts = { - depth: opts.depth - }; - if (has$3(opts, 'quoteStyle')) { - newOpts.quoteStyle = opts.quoteStyle; - } - return inspect_(value, newOpts, depth + 1, seen); - } - return inspect_(value, opts, depth + 1, seen); - } - - if (typeof obj === 'function' && !isRegExp$1(obj)) { // in older engines, regexes are callable - var name = nameOf(obj); - var keys = arrObjKeys(obj, inspect); - return '[Function' + (name ? ': ' + name : ' (anonymous)') + ']' + (keys.length > 0 ? ' { ' + $join.call(keys, ', ') + ' }' : ''); - } - if (isSymbol(obj)) { - var symString = hasShammedSymbols ? $replace.call(String(obj), /^(Symbol\(.*\))_[^)]*$/, '$1') : symToString.call(obj); - return typeof obj === 'object' && !hasShammedSymbols ? markBoxed(symString) : symString; - } - if (isElement(obj)) { - var s = '<' + $toLowerCase.call(String(obj.nodeName)); - var attrs = obj.attributes || []; - for (var i = 0; i < attrs.length; i++) { - s += ' ' + attrs[i].name + '=' + wrapQuotes(quote(attrs[i].value), 'double', opts); - } - s += '>'; - if (obj.childNodes && obj.childNodes.length) { s += '...'; } - s += ''; - return s; - } - if (isArray$3(obj)) { - if (obj.length === 0) { return '[]'; } - var xs = arrObjKeys(obj, inspect); - if (indent && !singleLineValues(xs)) { - return '[' + indentedJoin(xs, indent) + ']'; - } - return '[ ' + $join.call(xs, ', ') + ' ]'; - } - if (isError(obj)) { - var parts = arrObjKeys(obj, inspect); - if (!('cause' in Error.prototype) && 'cause' in obj && !isEnumerable.call(obj, 'cause')) { - return '{ [' + String(obj) + '] ' + $join.call($concat.call('[cause]: ' + inspect(obj.cause), parts), ', ') + ' }'; - } - if (parts.length === 0) { return '[' + String(obj) + ']'; } - return '{ [' + String(obj) + '] ' + $join.call(parts, ', ') + ' }'; - } - if (typeof obj === 'object' && customInspect) { - if (inspectSymbol && typeof obj[inspectSymbol] === 'function' && utilInspect) { - return utilInspect(obj, { depth: maxDepth - depth }); - } else if (customInspect !== 'symbol' && typeof obj.inspect === 'function') { - return obj.inspect(); - } - } - if (isMap(obj)) { - var mapParts = []; - if (mapForEach) { - mapForEach.call(obj, function (value, key) { - mapParts.push(inspect(key, obj, true) + ' => ' + inspect(value, obj)); - }); - } - return collectionOf('Map', mapSize.call(obj), mapParts, indent); - } - if (isSet(obj)) { - var setParts = []; - if (setForEach) { - setForEach.call(obj, function (value) { - setParts.push(inspect(value, obj)); - }); - } - return collectionOf('Set', setSize.call(obj), setParts, indent); - } - if (isWeakMap(obj)) { - return weakCollectionOf('WeakMap'); - } - if (isWeakSet(obj)) { - return weakCollectionOf('WeakSet'); - } - if (isWeakRef(obj)) { - return weakCollectionOf('WeakRef'); - } - if (isNumber(obj)) { - return markBoxed(inspect(Number(obj))); - } - if (isBigInt(obj)) { - return markBoxed(inspect(bigIntValueOf.call(obj))); - } - if (isBoolean(obj)) { - return markBoxed(booleanValueOf.call(obj)); - } - if (isString(obj)) { - return markBoxed(inspect(String(obj))); - } - // note: in IE 8, sometimes `global !== window` but both are the prototypes of each other - /* eslint-env browser */ - if (typeof window !== 'undefined' && obj === window) { - return '{ [object Window] }'; - } - if (obj === commonjsGlobal) { - return '{ [object globalThis] }'; - } - if (!isDate(obj) && !isRegExp$1(obj)) { - var ys = arrObjKeys(obj, inspect); - var isPlainObject = gPO ? gPO(obj) === Object.prototype : obj instanceof Object || obj.constructor === Object; - var protoTag = obj instanceof Object ? '' : 'null prototype'; - var stringTag = !isPlainObject && toStringTag && Object(obj) === obj && toStringTag in obj ? $slice.call(toStr(obj), 8, -1) : protoTag ? 'Object' : ''; - var constructorTag = isPlainObject || typeof obj.constructor !== 'function' ? '' : obj.constructor.name ? obj.constructor.name + ' ' : ''; - var tag = constructorTag + (stringTag || protoTag ? '[' + $join.call($concat.call([], stringTag || [], protoTag || []), ': ') + '] ' : ''); - if (ys.length === 0) { return tag + '{}'; } - if (indent) { - return tag + '{' + indentedJoin(ys, indent) + '}'; - } - return tag + '{ ' + $join.call(ys, ', ') + ' }'; - } - return String(obj); - }; - - function wrapQuotes(s, defaultStyle, opts) { - var quoteChar = (opts.quoteStyle || defaultStyle) === 'double' ? '"' : "'"; - return quoteChar + s + quoteChar; - } - - function quote(s) { - return $replace.call(String(s), /"/g, '"'); - } - - function isArray$3(obj) { return toStr(obj) === '[object Array]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } - function isDate(obj) { return toStr(obj) === '[object Date]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } - function isRegExp$1(obj) { return toStr(obj) === '[object RegExp]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } - function isError(obj) { return toStr(obj) === '[object Error]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } - function isString(obj) { return toStr(obj) === '[object String]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } - function isNumber(obj) { return toStr(obj) === '[object Number]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } - function isBoolean(obj) { return toStr(obj) === '[object Boolean]' && (!toStringTag || !(typeof obj === 'object' && toStringTag in obj)); } - - // Symbol and BigInt do have Symbol.toStringTag by spec, so that can't be used to eliminate false positives - function isSymbol(obj) { - if (hasShammedSymbols) { - return obj && typeof obj === 'object' && obj instanceof Symbol; - } - if (typeof obj === 'symbol') { - return true; - } - if (!obj || typeof obj !== 'object' || !symToString) { - return false; - } - try { - symToString.call(obj); - return true; - } catch (e) {} - return false; - } - - function isBigInt(obj) { - if (!obj || typeof obj !== 'object' || !bigIntValueOf) { - return false; - } - try { - bigIntValueOf.call(obj); - return true; - } catch (e) {} - return false; - } - - var hasOwn$1 = Object.prototype.hasOwnProperty || function (key) { return key in this; }; - function has$3(obj, key) { - return hasOwn$1.call(obj, key); - } - - function toStr(obj) { - return objectToString.call(obj); - } - - function nameOf(f) { - if (f.name) { return f.name; } - var m = $match.call(functionToString.call(f), /^function\s*([\w$]+)/); - if (m) { return m[1]; } - return null; - } - - function indexOf(xs, x) { - if (xs.indexOf) { return xs.indexOf(x); } - for (var i = 0, l = xs.length; i < l; i++) { - if (xs[i] === x) { return i; } - } - return -1; - } - - function isMap(x) { - if (!mapSize || !x || typeof x !== 'object') { - return false; - } - try { - mapSize.call(x); - try { - setSize.call(x); - } catch (s) { - return true; - } - return x instanceof Map; // core-js workaround, pre-v2.5.0 - } catch (e) {} - return false; - } - - function isWeakMap(x) { - if (!weakMapHas || !x || typeof x !== 'object') { - return false; - } - try { - weakMapHas.call(x, weakMapHas); - try { - weakSetHas.call(x, weakSetHas); - } catch (s) { - return true; - } - return x instanceof WeakMap; // core-js workaround, pre-v2.5.0 - } catch (e) {} - return false; - } - - function isWeakRef(x) { - if (!weakRefDeref || !x || typeof x !== 'object') { - return false; - } - try { - weakRefDeref.call(x); - return true; - } catch (e) {} - return false; - } - - function isSet(x) { - if (!setSize || !x || typeof x !== 'object') { - return false; - } - try { - setSize.call(x); - try { - mapSize.call(x); - } catch (m) { - return true; - } - return x instanceof Set; // core-js workaround, pre-v2.5.0 - } catch (e) {} - return false; - } - - function isWeakSet(x) { - if (!weakSetHas || !x || typeof x !== 'object') { - return false; - } - try { - weakSetHas.call(x, weakSetHas); - try { - weakMapHas.call(x, weakMapHas); - } catch (s) { - return true; - } - return x instanceof WeakSet; // core-js workaround, pre-v2.5.0 - } catch (e) {} - return false; - } - - function isElement(x) { - if (!x || typeof x !== 'object') { return false; } - if (typeof HTMLElement !== 'undefined' && x instanceof HTMLElement) { - return true; - } - return typeof x.nodeName === 'string' && typeof x.getAttribute === 'function'; - } - - function inspectString(str, opts) { - if (str.length > opts.maxStringLength) { - var remaining = str.length - opts.maxStringLength; - var trailer = '... ' + remaining + ' more character' + (remaining > 1 ? 's' : ''); - return inspectString($slice.call(str, 0, opts.maxStringLength), opts) + trailer; - } - // eslint-disable-next-line no-control-regex - var s = $replace.call($replace.call(str, /(['\\])/g, '\\$1'), /[\x00-\x1f]/g, lowbyte); - return wrapQuotes(s, 'single', opts); - } - - function lowbyte(c) { - var n = c.charCodeAt(0); - var x = { - 8: 'b', - 9: 't', - 10: 'n', - 12: 'f', - 13: 'r' - }[n]; - if (x) { return '\\' + x; } - return '\\x' + (n < 0x10 ? '0' : '') + $toUpperCase.call(n.toString(16)); - } - - function markBoxed(str) { - return 'Object(' + str + ')'; - } - - function weakCollectionOf(type) { - return type + ' { ? }'; - } - - function collectionOf(type, size, entries, indent) { - var joinedEntries = indent ? indentedJoin(entries, indent) : $join.call(entries, ', '); - return type + ' (' + size + ') {' + joinedEntries + '}'; - } - - function singleLineValues(xs) { - for (var i = 0; i < xs.length; i++) { - if (indexOf(xs[i], '\n') >= 0) { - return false; - } - } - return true; - } - - function getIndent(opts, depth) { - var baseIndent; - if (opts.indent === '\t') { - baseIndent = '\t'; - } else if (typeof opts.indent === 'number' && opts.indent > 0) { - baseIndent = $join.call(Array(opts.indent + 1), ' '); - } else { - return null; - } - return { - base: baseIndent, - prev: $join.call(Array(depth + 1), baseIndent) - }; - } - - function indentedJoin(xs, indent) { - if (xs.length === 0) { return ''; } - var lineJoiner = '\n' + indent.prev + indent.base; - return lineJoiner + $join.call(xs, ',' + lineJoiner) + '\n' + indent.prev; - } - - function arrObjKeys(obj, inspect) { - var isArr = isArray$3(obj); - var xs = []; - if (isArr) { - xs.length = obj.length; - for (var i = 0; i < obj.length; i++) { - xs[i] = has$3(obj, i) ? inspect(obj[i], obj) : ''; - } - } - var syms = typeof gOPS === 'function' ? gOPS(obj) : []; - var symMap; - if (hasShammedSymbols) { - symMap = {}; - for (var k = 0; k < syms.length; k++) { - symMap['$' + syms[k]] = syms[k]; - } - } - - for (var key in obj) { // eslint-disable-line no-restricted-syntax - if (!has$3(obj, key)) { continue; } // eslint-disable-line no-restricted-syntax, no-continue - if (isArr && String(Number(key)) === key && key < obj.length) { continue; } // eslint-disable-line no-restricted-syntax, no-continue - if (hasShammedSymbols && symMap['$' + key] instanceof Symbol) { - // this is to prevent shammed Symbols, which are stored as strings, from being included in the string key section - continue; // eslint-disable-line no-restricted-syntax, no-continue - } else if ($test.call(/[^\w$]/, key)) { - xs.push(inspect(key, obj) + ': ' + inspect(obj[key], obj)); - } else { - xs.push(key + ': ' + inspect(obj[key], obj)); - } - } - if (typeof gOPS === 'function') { - for (var j = 0; j < syms.length; j++) { - if (isEnumerable.call(obj, syms[j])) { - xs.push('[' + inspect(syms[j]) + ']: ' + inspect(obj[syms[j]], obj)); - } - } - } - return xs; - } - - var GetIntrinsic = getIntrinsic; - var callBound = callBound$1; - var inspect = objectInspect; - - var $TypeError = GetIntrinsic('%TypeError%'); - var $WeakMap = GetIntrinsic('%WeakMap%', true); - var $Map = GetIntrinsic('%Map%', true); - - var $weakMapGet = callBound('WeakMap.prototype.get', true); - var $weakMapSet = callBound('WeakMap.prototype.set', true); - var $weakMapHas = callBound('WeakMap.prototype.has', true); - var $mapGet = callBound('Map.prototype.get', true); - var $mapSet = callBound('Map.prototype.set', true); - var $mapHas = callBound('Map.prototype.has', true); - - /* - * This function traverses the list returning the node corresponding to the - * given key. - * - * That node is also moved to the head of the list, so that if it's accessed - * again we don't need to traverse the whole list. By doing so, all the recently - * used nodes can be accessed relatively quickly. - */ - var listGetNode = function (list, key) { // eslint-disable-line consistent-return - for (var prev = list, curr; (curr = prev.next) !== null; prev = curr) { - if (curr.key === key) { - prev.next = curr.next; - curr.next = list.next; - list.next = curr; // eslint-disable-line no-param-reassign - return curr; - } - } - }; - - var listGet = function (objects, key) { - var node = listGetNode(objects, key); - return node && node.value; - }; - var listSet = function (objects, key, value) { - var node = listGetNode(objects, key); - if (node) { - node.value = value; - } else { - // Prepend the new node to the beginning of the list - objects.next = { // eslint-disable-line no-param-reassign - key: key, - next: objects.next, - value: value - }; - } - }; - var listHas = function (objects, key) { - return !!listGetNode(objects, key); - }; - - var sideChannel = function getSideChannel() { - var $wm; - var $m; - var $o; - var channel = { - assert: function (key) { - if (!channel.has(key)) { - throw new $TypeError('Side channel does not contain ' + inspect(key)); - } - }, - get: function (key) { // eslint-disable-line consistent-return - if ($WeakMap && key && (typeof key === 'object' || typeof key === 'function')) { - if ($wm) { - return $weakMapGet($wm, key); - } - } else if ($Map) { - if ($m) { - return $mapGet($m, key); - } - } else { - if ($o) { // eslint-disable-line no-lonely-if - return listGet($o, key); - } - } - }, - has: function (key) { - if ($WeakMap && key && (typeof key === 'object' || typeof key === 'function')) { - if ($wm) { - return $weakMapHas($wm, key); - } - } else if ($Map) { - if ($m) { - return $mapHas($m, key); - } - } else { - if ($o) { // eslint-disable-line no-lonely-if - return listHas($o, key); - } - } - return false; - }, - set: function (key, value) { - if ($WeakMap && key && (typeof key === 'object' || typeof key === 'function')) { - if (!$wm) { - $wm = new $WeakMap(); - } - $weakMapSet($wm, key, value); - } else if ($Map) { - if (!$m) { - $m = new $Map(); - } - $mapSet($m, key, value); - } else { - if (!$o) { - /* - * Initialize the linked list as an empty node, so that we don't have - * to special-case handling of the first node: we can always refer to - * it as (previous node).next, instead of something like (list).head - */ - $o = { key: {}, next: null }; - } - listSet($o, key, value); - } - } - }; - return channel; - }; - - var replace = String.prototype.replace; - var percentTwenties = /%20/g; - - var Format = { - RFC1738: 'RFC1738', - RFC3986: 'RFC3986' - }; - - var formats$3 = { - 'default': Format.RFC3986, - formatters: { - RFC1738: function (value) { - return replace.call(value, percentTwenties, '+'); - }, - RFC3986: function (value) { - return String(value); - } - }, - RFC1738: Format.RFC1738, - RFC3986: Format.RFC3986 - }; - - var formats$2 = formats$3; - - var has$2 = Object.prototype.hasOwnProperty; - var isArray$2 = Array.isArray; - - var hexTable = (function () { - var array = []; - for (var i = 0; i < 256; ++i) { - array.push('%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase()); - } - - return array; - }()); - - var compactQueue = function compactQueue(queue) { - while (queue.length > 1) { - var item = queue.pop(); - var obj = item.obj[item.prop]; - - if (isArray$2(obj)) { - var compacted = []; - - for (var j = 0; j < obj.length; ++j) { - if (typeof obj[j] !== 'undefined') { - compacted.push(obj[j]); - } - } - - item.obj[item.prop] = compacted; - } - } - }; - - var arrayToObject = function arrayToObject(source, options) { - var obj = options && options.plainObjects ? Object.create(null) : {}; - for (var i = 0; i < source.length; ++i) { - if (typeof source[i] !== 'undefined') { - obj[i] = source[i]; - } - } - - return obj; - }; - - var merge = function merge(target, source, options) { - /* eslint no-param-reassign: 0 */ - if (!source) { - return target; - } - - if (typeof source !== 'object') { - if (isArray$2(target)) { - target.push(source); - } else if (target && typeof target === 'object') { - if ((options && (options.plainObjects || options.allowPrototypes)) || !has$2.call(Object.prototype, source)) { - target[source] = true; - } - } else { - return [target, source]; - } - - return target; - } - - if (!target || typeof target !== 'object') { - return [target].concat(source); - } - - var mergeTarget = target; - if (isArray$2(target) && !isArray$2(source)) { - mergeTarget = arrayToObject(target, options); - } - - if (isArray$2(target) && isArray$2(source)) { - source.forEach(function (item, i) { - if (has$2.call(target, i)) { - var targetItem = target[i]; - if (targetItem && typeof targetItem === 'object' && item && typeof item === 'object') { - target[i] = merge(targetItem, item, options); - } else { - target.push(item); - } - } else { - target[i] = item; - } - }); - return target; - } - - return Object.keys(source).reduce(function (acc, key) { - var value = source[key]; - - if (has$2.call(acc, key)) { - acc[key] = merge(acc[key], value, options); - } else { - acc[key] = value; - } - return acc; - }, mergeTarget); - }; - - var assign = function assignSingleSource(target, source) { - return Object.keys(source).reduce(function (acc, key) { - acc[key] = source[key]; - return acc; - }, target); - }; - - var decode = function (str, decoder, charset) { - var strWithoutPlus = str.replace(/\+/g, ' '); - if (charset === 'iso-8859-1') { - // unescape never throws, no try...catch needed: - return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape); - } - // utf-8 - try { - return decodeURIComponent(strWithoutPlus); - } catch (e) { - return strWithoutPlus; - } - }; - - var encode = function encode(str, defaultEncoder, charset, kind, format) { - // This code was originally written by Brian White (mscdex) for the io.js core querystring library. - // It has been adapted here for stricter adherence to RFC 3986 - if (str.length === 0) { - return str; - } - - var string = str; - if (typeof str === 'symbol') { - string = Symbol.prototype.toString.call(str); - } else if (typeof str !== 'string') { - string = String(str); - } - - if (charset === 'iso-8859-1') { - return escape(string).replace(/%u[0-9a-f]{4}/gi, function ($0) { - return '%26%23' + parseInt($0.slice(2), 16) + '%3B'; - }); - } - - var out = ''; - for (var i = 0; i < string.length; ++i) { - var c = string.charCodeAt(i); - - if ( - c === 0x2D // - - || c === 0x2E // . - || c === 0x5F // _ - || c === 0x7E // ~ - || (c >= 0x30 && c <= 0x39) // 0-9 - || (c >= 0x41 && c <= 0x5A) // a-z - || (c >= 0x61 && c <= 0x7A) // A-Z - || (format === formats$2.RFC1738 && (c === 0x28 || c === 0x29)) // ( ) - ) { - out += string.charAt(i); - continue; - } - - if (c < 0x80) { - out = out + hexTable[c]; - continue; - } - - if (c < 0x800) { - out = out + (hexTable[0xC0 | (c >> 6)] + hexTable[0x80 | (c & 0x3F)]); - continue; - } - - if (c < 0xD800 || c >= 0xE000) { - out = out + (hexTable[0xE0 | (c >> 12)] + hexTable[0x80 | ((c >> 6) & 0x3F)] + hexTable[0x80 | (c & 0x3F)]); - continue; - } - - i += 1; - c = 0x10000 + (((c & 0x3FF) << 10) | (string.charCodeAt(i) & 0x3FF)); - /* eslint operator-linebreak: [2, "before"] */ - out += hexTable[0xF0 | (c >> 18)] - + hexTable[0x80 | ((c >> 12) & 0x3F)] - + hexTable[0x80 | ((c >> 6) & 0x3F)] - + hexTable[0x80 | (c & 0x3F)]; - } - - return out; - }; - - var compact = function compact(value) { - var queue = [{ obj: { o: value }, prop: 'o' }]; - var refs = []; - - for (var i = 0; i < queue.length; ++i) { - var item = queue[i]; - var obj = item.obj[item.prop]; - - var keys = Object.keys(obj); - for (var j = 0; j < keys.length; ++j) { - var key = keys[j]; - var val = obj[key]; - if (typeof val === 'object' && val !== null && refs.indexOf(val) === -1) { - queue.push({ obj: obj, prop: key }); - refs.push(val); - } - } - } - - compactQueue(queue); - - return value; - }; - - var isRegExp = function isRegExp(obj) { - return Object.prototype.toString.call(obj) === '[object RegExp]'; - }; - - var isBuffer = function isBuffer(obj) { - if (!obj || typeof obj !== 'object') { - return false; - } - - return !!(obj.constructor && obj.constructor.isBuffer && obj.constructor.isBuffer(obj)); - }; - - var combine = function combine(a, b) { - return [].concat(a, b); - }; - - var maybeMap = function maybeMap(val, fn) { - if (isArray$2(val)) { - var mapped = []; - for (var i = 0; i < val.length; i += 1) { - mapped.push(fn(val[i])); - } - return mapped; - } - return fn(val); - }; - - var utils$4 = { - arrayToObject: arrayToObject, - assign: assign, - combine: combine, - compact: compact, - decode: decode, - encode: encode, - isBuffer: isBuffer, - isRegExp: isRegExp, - maybeMap: maybeMap, - merge: merge - }; - - var getSideChannel = sideChannel; - var utils$3 = utils$4; - var formats$1 = formats$3; - var has$1 = Object.prototype.hasOwnProperty; - - var arrayPrefixGenerators = { - brackets: function brackets(prefix) { - return prefix + '[]'; - }, - comma: 'comma', - indices: function indices(prefix, key) { - return prefix + '[' + key + ']'; - }, - repeat: function repeat(prefix) { - return prefix; - } - }; - - var isArray$1 = Array.isArray; - var push = Array.prototype.push; - var pushToArray = function (arr, valueOrArray) { - push.apply(arr, isArray$1(valueOrArray) ? valueOrArray : [valueOrArray]); - }; - - var toISO = Date.prototype.toISOString; - - var defaultFormat = formats$1['default']; - var defaults$1 = { - addQueryPrefix: false, - allowDots: false, - charset: 'utf-8', - charsetSentinel: false, - delimiter: '&', - encode: true, - encoder: utils$3.encode, - encodeValuesOnly: false, - format: defaultFormat, - formatter: formats$1.formatters[defaultFormat], - // deprecated - indices: false, - serializeDate: function serializeDate(date) { - return toISO.call(date); - }, - skipNulls: false, - strictNullHandling: false - }; - - var isNonNullishPrimitive = function isNonNullishPrimitive(v) { - return typeof v === 'string' - || typeof v === 'number' - || typeof v === 'boolean' - || typeof v === 'symbol' - || typeof v === 'bigint'; - }; - - var sentinel = {}; - - var stringify$1 = function stringify( - object, - prefix, - generateArrayPrefix, - commaRoundTrip, - strictNullHandling, - skipNulls, - encoder, - filter, - sort, - allowDots, - serializeDate, - format, - formatter, - encodeValuesOnly, - charset, - sideChannel - ) { - var obj = object; - - var tmpSc = sideChannel; - var step = 0; - var findFlag = false; - while ((tmpSc = tmpSc.get(sentinel)) !== void undefined && !findFlag) { - // Where object last appeared in the ref tree - var pos = tmpSc.get(object); - step += 1; - if (typeof pos !== 'undefined') { - if (pos === step) { - throw new RangeError('Cyclic object value'); - } else { - findFlag = true; // Break while - } - } - if (typeof tmpSc.get(sentinel) === 'undefined') { - step = 0; - } - } - - if (typeof filter === 'function') { - obj = filter(prefix, obj); - } else if (obj instanceof Date) { - obj = serializeDate(obj); - } else if (generateArrayPrefix === 'comma' && isArray$1(obj)) { - obj = utils$3.maybeMap(obj, function (value) { - if (value instanceof Date) { - return serializeDate(value); - } - return value; - }); - } - - if (obj === null) { - if (strictNullHandling) { - return encoder && !encodeValuesOnly ? encoder(prefix, defaults$1.encoder, charset, 'key', format) : prefix; - } - - obj = ''; - } - - if (isNonNullishPrimitive(obj) || utils$3.isBuffer(obj)) { - if (encoder) { - var keyValue = encodeValuesOnly ? prefix : encoder(prefix, defaults$1.encoder, charset, 'key', format); - return [formatter(keyValue) + '=' + formatter(encoder(obj, defaults$1.encoder, charset, 'value', format))]; - } - return [formatter(prefix) + '=' + formatter(String(obj))]; - } - - var values = []; - - if (typeof obj === 'undefined') { - return values; - } - - var objKeys; - if (generateArrayPrefix === 'comma' && isArray$1(obj)) { - // we need to join elements in - if (encodeValuesOnly && encoder) { - obj = utils$3.maybeMap(obj, encoder); - } - objKeys = [{ value: obj.length > 0 ? obj.join(',') || null : void undefined }]; - } else if (isArray$1(filter)) { - objKeys = filter; - } else { - var keys = Object.keys(obj); - objKeys = sort ? keys.sort(sort) : keys; - } - - var adjustedPrefix = commaRoundTrip && isArray$1(obj) && obj.length === 1 ? prefix + '[]' : prefix; - - for (var j = 0; j < objKeys.length; ++j) { - var key = objKeys[j]; - var value = typeof key === 'object' && typeof key.value !== 'undefined' ? key.value : obj[key]; - - if (skipNulls && value === null) { - continue; - } - - var keyPrefix = isArray$1(obj) - ? typeof generateArrayPrefix === 'function' ? generateArrayPrefix(adjustedPrefix, key) : adjustedPrefix - : adjustedPrefix + (allowDots ? '.' + key : '[' + key + ']'); - - sideChannel.set(object, step); - var valueSideChannel = getSideChannel(); - valueSideChannel.set(sentinel, sideChannel); - pushToArray(values, stringify( - value, - keyPrefix, - generateArrayPrefix, - commaRoundTrip, - strictNullHandling, - skipNulls, - generateArrayPrefix === 'comma' && encodeValuesOnly && isArray$1(obj) ? null : encoder, - filter, - sort, - allowDots, - serializeDate, - format, - formatter, - encodeValuesOnly, - charset, - valueSideChannel - )); - } - - return values; - }; - - var normalizeStringifyOptions = function normalizeStringifyOptions(opts) { - if (!opts) { - return defaults$1; - } - - if (opts.encoder !== null && typeof opts.encoder !== 'undefined' && typeof opts.encoder !== 'function') { - throw new TypeError('Encoder has to be a function.'); - } - - var charset = opts.charset || defaults$1.charset; - if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') { - throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'); - } - - var format = formats$1['default']; - if (typeof opts.format !== 'undefined') { - if (!has$1.call(formats$1.formatters, opts.format)) { - throw new TypeError('Unknown format option provided.'); - } - format = opts.format; - } - var formatter = formats$1.formatters[format]; - - var filter = defaults$1.filter; - if (typeof opts.filter === 'function' || isArray$1(opts.filter)) { - filter = opts.filter; - } - - return { - addQueryPrefix: typeof opts.addQueryPrefix === 'boolean' ? opts.addQueryPrefix : defaults$1.addQueryPrefix, - allowDots: typeof opts.allowDots === 'undefined' ? defaults$1.allowDots : !!opts.allowDots, - charset: charset, - charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults$1.charsetSentinel, - delimiter: typeof opts.delimiter === 'undefined' ? defaults$1.delimiter : opts.delimiter, - encode: typeof opts.encode === 'boolean' ? opts.encode : defaults$1.encode, - encoder: typeof opts.encoder === 'function' ? opts.encoder : defaults$1.encoder, - encodeValuesOnly: typeof opts.encodeValuesOnly === 'boolean' ? opts.encodeValuesOnly : defaults$1.encodeValuesOnly, - filter: filter, - format: format, - formatter: formatter, - serializeDate: typeof opts.serializeDate === 'function' ? opts.serializeDate : defaults$1.serializeDate, - skipNulls: typeof opts.skipNulls === 'boolean' ? opts.skipNulls : defaults$1.skipNulls, - sort: typeof opts.sort === 'function' ? opts.sort : null, - strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults$1.strictNullHandling - }; - }; - - var stringify_1 = function (object, opts) { - var obj = object; - var options = normalizeStringifyOptions(opts); - - var objKeys; - var filter; - - if (typeof options.filter === 'function') { - filter = options.filter; - obj = filter('', obj); - } else if (isArray$1(options.filter)) { - filter = options.filter; - objKeys = filter; - } - - var keys = []; - - if (typeof obj !== 'object' || obj === null) { - return ''; - } - - var arrayFormat; - if (opts && opts.arrayFormat in arrayPrefixGenerators) { - arrayFormat = opts.arrayFormat; - } else if (opts && 'indices' in opts) { - arrayFormat = opts.indices ? 'indices' : 'repeat'; - } else { - arrayFormat = 'indices'; - } - - var generateArrayPrefix = arrayPrefixGenerators[arrayFormat]; - if (opts && 'commaRoundTrip' in opts && typeof opts.commaRoundTrip !== 'boolean') { - throw new TypeError('`commaRoundTrip` must be a boolean, or absent'); - } - var commaRoundTrip = generateArrayPrefix === 'comma' && opts && opts.commaRoundTrip; - - if (!objKeys) { - objKeys = Object.keys(obj); - } - - if (options.sort) { - objKeys.sort(options.sort); - } - - var sideChannel = getSideChannel(); - for (var i = 0; i < objKeys.length; ++i) { - var key = objKeys[i]; - - if (options.skipNulls && obj[key] === null) { - continue; - } - pushToArray(keys, stringify$1( - obj[key], - key, - generateArrayPrefix, - commaRoundTrip, - options.strictNullHandling, - options.skipNulls, - options.encode ? options.encoder : null, - options.filter, - options.sort, - options.allowDots, - options.serializeDate, - options.format, - options.formatter, - options.encodeValuesOnly, - options.charset, - sideChannel - )); - } - - var joined = keys.join(options.delimiter); - var prefix = options.addQueryPrefix === true ? '?' : ''; - - if (options.charsetSentinel) { - if (options.charset === 'iso-8859-1') { - // encodeURIComponent('✓'), the "numeric entity" representation of a checkmark - prefix += 'utf8=%26%2310003%3B&'; - } else { - // encodeURIComponent('✓') - prefix += 'utf8=%E2%9C%93&'; - } - } - - return joined.length > 0 ? prefix + joined : ''; - }; - - var utils$2 = utils$4; - - var has = Object.prototype.hasOwnProperty; - var isArray = Array.isArray; - - var defaults = { - allowDots: false, - allowPrototypes: false, - allowSparse: false, - arrayLimit: 20, - charset: 'utf-8', - charsetSentinel: false, - comma: false, - decoder: utils$2.decode, - delimiter: '&', - depth: 5, - ignoreQueryPrefix: false, - interpretNumericEntities: false, - parameterLimit: 1000, - parseArrays: true, - plainObjects: false, - strictNullHandling: false - }; - - var interpretNumericEntities = function (str) { - return str.replace(/&#(\d+);/g, function ($0, numberStr) { - return String.fromCharCode(parseInt(numberStr, 10)); - }); - }; - - var parseArrayValue = function (val, options) { - if (val && typeof val === 'string' && options.comma && val.indexOf(',') > -1) { - return val.split(','); - } - - return val; - }; - - // This is what browsers will submit when the ✓ character occurs in an - // application/x-www-form-urlencoded body and the encoding of the page containing - // the form is iso-8859-1, or when the submitted form has an accept-charset - // attribute of iso-8859-1. Presumably also with other charsets that do not contain - // the ✓ character, such as us-ascii. - var isoSentinel = 'utf8=%26%2310003%3B'; // encodeURIComponent('✓') - - // These are the percent-encoded utf-8 octets representing a checkmark, indicating that the request actually is utf-8 encoded. - var charsetSentinel = 'utf8=%E2%9C%93'; // encodeURIComponent('✓') - - var parseValues = function parseQueryStringValues(str, options) { - var obj = { __proto__: null }; - - var cleanStr = options.ignoreQueryPrefix ? str.replace(/^\?/, '') : str; - var limit = options.parameterLimit === Infinity ? undefined : options.parameterLimit; - var parts = cleanStr.split(options.delimiter, limit); - var skipIndex = -1; // Keep track of where the utf8 sentinel was found - var i; - - var charset = options.charset; - if (options.charsetSentinel) { - for (i = 0; i < parts.length; ++i) { - if (parts[i].indexOf('utf8=') === 0) { - if (parts[i] === charsetSentinel) { - charset = 'utf-8'; - } else if (parts[i] === isoSentinel) { - charset = 'iso-8859-1'; - } - skipIndex = i; - i = parts.length; // The eslint settings do not allow break; - } - } - } - - for (i = 0; i < parts.length; ++i) { - if (i === skipIndex) { - continue; - } - var part = parts[i]; - - var bracketEqualsPos = part.indexOf(']='); - var pos = bracketEqualsPos === -1 ? part.indexOf('=') : bracketEqualsPos + 1; - - var key, val; - if (pos === -1) { - key = options.decoder(part, defaults.decoder, charset, 'key'); - val = options.strictNullHandling ? null : ''; - } else { - key = options.decoder(part.slice(0, pos), defaults.decoder, charset, 'key'); - val = utils$2.maybeMap( - parseArrayValue(part.slice(pos + 1), options), - function (encodedVal) { - return options.decoder(encodedVal, defaults.decoder, charset, 'value'); - } - ); - } - - if (val && options.interpretNumericEntities && charset === 'iso-8859-1') { - val = interpretNumericEntities(val); - } - - if (part.indexOf('[]=') > -1) { - val = isArray(val) ? [val] : val; - } - - if (has.call(obj, key)) { - obj[key] = utils$2.combine(obj[key], val); - } else { - obj[key] = val; - } - } - - return obj; - }; - - var parseObject = function (chain, val, options, valuesParsed) { - var leaf = valuesParsed ? val : parseArrayValue(val, options); - - for (var i = chain.length - 1; i >= 0; --i) { - var obj; - var root = chain[i]; - - if (root === '[]' && options.parseArrays) { - obj = [].concat(leaf); - } else { - obj = options.plainObjects ? Object.create(null) : {}; - var cleanRoot = root.charAt(0) === '[' && root.charAt(root.length - 1) === ']' ? root.slice(1, -1) : root; - var index = parseInt(cleanRoot, 10); - if (!options.parseArrays && cleanRoot === '') { - obj = { 0: leaf }; - } else if ( - !isNaN(index) - && root !== cleanRoot - && String(index) === cleanRoot - && index >= 0 - && (options.parseArrays && index <= options.arrayLimit) - ) { - obj = []; - obj[index] = leaf; - } else if (cleanRoot !== '__proto__') { - obj[cleanRoot] = leaf; - } - } - - leaf = obj; - } - - return leaf; - }; - - var parseKeys = function parseQueryStringKeys(givenKey, val, options, valuesParsed) { - if (!givenKey) { - return; - } - - // Transform dot notation to bracket notation - var key = options.allowDots ? givenKey.replace(/\.([^.[]+)/g, '[$1]') : givenKey; - - // The regex chunks - - var brackets = /(\[[^[\]]*])/; - var child = /(\[[^[\]]*])/g; - - // Get the parent - - var segment = options.depth > 0 && brackets.exec(key); - var parent = segment ? key.slice(0, segment.index) : key; - - // Stash the parent if it exists - - var keys = []; - if (parent) { - // If we aren't using plain objects, optionally prefix keys that would overwrite object prototype properties - if (!options.plainObjects && has.call(Object.prototype, parent)) { - if (!options.allowPrototypes) { - return; - } - } - - keys.push(parent); - } - - // Loop through children appending to the array until we hit depth - - var i = 0; - while (options.depth > 0 && (segment = child.exec(key)) !== null && i < options.depth) { - i += 1; - if (!options.plainObjects && has.call(Object.prototype, segment[1].slice(1, -1))) { - if (!options.allowPrototypes) { - return; - } - } - keys.push(segment[1]); - } - - // If there's a remainder, just add whatever is left - - if (segment) { - keys.push('[' + key.slice(segment.index) + ']'); - } - - return parseObject(keys, val, options, valuesParsed); - }; - - var normalizeParseOptions = function normalizeParseOptions(opts) { - if (!opts) { - return defaults; - } - - if (opts.decoder !== null && opts.decoder !== undefined && typeof opts.decoder !== 'function') { - throw new TypeError('Decoder has to be a function.'); - } - - if (typeof opts.charset !== 'undefined' && opts.charset !== 'utf-8' && opts.charset !== 'iso-8859-1') { - throw new TypeError('The charset option must be either utf-8, iso-8859-1, or undefined'); - } - var charset = typeof opts.charset === 'undefined' ? defaults.charset : opts.charset; - - return { - allowDots: typeof opts.allowDots === 'undefined' ? defaults.allowDots : !!opts.allowDots, - allowPrototypes: typeof opts.allowPrototypes === 'boolean' ? opts.allowPrototypes : defaults.allowPrototypes, - allowSparse: typeof opts.allowSparse === 'boolean' ? opts.allowSparse : defaults.allowSparse, - arrayLimit: typeof opts.arrayLimit === 'number' ? opts.arrayLimit : defaults.arrayLimit, - charset: charset, - charsetSentinel: typeof opts.charsetSentinel === 'boolean' ? opts.charsetSentinel : defaults.charsetSentinel, - comma: typeof opts.comma === 'boolean' ? opts.comma : defaults.comma, - decoder: typeof opts.decoder === 'function' ? opts.decoder : defaults.decoder, - delimiter: typeof opts.delimiter === 'string' || utils$2.isRegExp(opts.delimiter) ? opts.delimiter : defaults.delimiter, - // eslint-disable-next-line no-implicit-coercion, no-extra-parens - depth: (typeof opts.depth === 'number' || opts.depth === false) ? +opts.depth : defaults.depth, - ignoreQueryPrefix: opts.ignoreQueryPrefix === true, - interpretNumericEntities: typeof opts.interpretNumericEntities === 'boolean' ? opts.interpretNumericEntities : defaults.interpretNumericEntities, - parameterLimit: typeof opts.parameterLimit === 'number' ? opts.parameterLimit : defaults.parameterLimit, - parseArrays: opts.parseArrays !== false, - plainObjects: typeof opts.plainObjects === 'boolean' ? opts.plainObjects : defaults.plainObjects, - strictNullHandling: typeof opts.strictNullHandling === 'boolean' ? opts.strictNullHandling : defaults.strictNullHandling - }; - }; - - var parse$1 = function (str, opts) { - var options = normalizeParseOptions(opts); - - if (str === '' || str === null || typeof str === 'undefined') { - return options.plainObjects ? Object.create(null) : {}; - } - - var tempObj = typeof str === 'string' ? parseValues(str, options) : str; - var obj = options.plainObjects ? Object.create(null) : {}; - - // Iterate over the keys and setup the new object - - var keys = Object.keys(tempObj); - for (var i = 0; i < keys.length; ++i) { - var key = keys[i]; - var newObj = parseKeys(key, tempObj[key], options, typeof str === 'string'); - obj = utils$2.merge(obj, newObj, options); - } - - if (options.allowSparse === true) { - return obj; - } - - return utils$2.compact(obj); - }; - - var stringify = stringify_1; - var parse = parse$1; - var formats = formats$3; - - var lib = { - formats: formats, - parse: parse, - stringify: stringify - }; - - var utils$1 = {}; - - (function (exports) { - - function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } - function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } - /** - * Return the mime type for the given `str`. - * - * @param {String} str - * @return {String} - * @api private - */ - - exports.type = string_ => string_.split(/ *; */).shift(); - - /** - * Return header field parameters. - * - * @param {String} str - * @return {Object} - * @api private - */ - - exports.params = value => { - const object = {}; - var _iterator = _createForOfIteratorHelper(value.split(/ *; */)), - _step; - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - const string_ = _step.value; - const parts = string_.split(/ *= */); - const key = parts.shift(); - const value = parts.shift(); - if (key && value) object[key] = value; - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - return object; - }; - - /** - * Parse Link header fields. - * - * @param {String} str - * @return {Object} - * @api private - */ - - exports.parseLinks = value => { - const object = {}; - var _iterator2 = _createForOfIteratorHelper(value.split(/ *, */)), - _step2; - try { - for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) { - const string_ = _step2.value; - const parts = string_.split(/ *; */); - const url = parts[0].slice(1, -1); - const rel = parts[1].split(/ *= */)[1].slice(1, -1); - object[rel] = url; - } - } catch (err) { - _iterator2.e(err); - } finally { - _iterator2.f(); - } - return object; - }; - - /** - * Strip content related fields from `header`. - * - * @param {Object} header - * @return {Object} header - * @api private - */ - - exports.cleanHeader = (header, changesOrigin) => { - delete header['content-type']; - delete header['content-length']; - delete header['transfer-encoding']; - delete header.host; - // secuirty - if (changesOrigin) { - delete header.authorization; - delete header.cookie; - } - return header; - }; - - /** - * Check if `obj` is an object. - * - * @param {Object} object - * @return {Boolean} - * @api private - */ - exports.isObject = object => { - return object !== null && typeof object === 'object'; - }; - - /** - * Object.hasOwn fallback/polyfill. - * - * @type {(object: object, property: string) => boolean} object - * @api private - */ - exports.hasOwn = Object.hasOwn || function (object, property) { - if (object == null) { - throw new TypeError('Cannot convert undefined or null to object'); - } - return Object.prototype.hasOwnProperty.call(new Object(object), property); - }; - exports.mixin = (target, source) => { - for (const key in source) { - if (exports.hasOwn(source, key)) { - target[key] = source[key]; - } - } - }; - - }(utils$1)); - - const semver = require$$0; - - /** - * Module of mixed-in functions shared between node and client code - */ - const _require = utils$1, - isObject = _require.isObject, - hasOwn = _require.hasOwn; - - /** - * Expose `RequestBase`. - */ - - var requestBase = RequestBase; - - /** - * Initialize a new `RequestBase`. - * - * @api public - */ - - function RequestBase() {} - - /** - * Clear previous timeout. - * - * @return {Request} for chaining - * @api public - */ - - RequestBase.prototype.clearTimeout = function () { - clearTimeout(this._timer); - clearTimeout(this._responseTimeoutTimer); - clearTimeout(this._uploadTimeoutTimer); - delete this._timer; - delete this._responseTimeoutTimer; - delete this._uploadTimeoutTimer; - return this; - }; - - /** - * Override default response body parser - * - * This function will be called to convert incoming data into request.body - * - * @param {Function} - * @api public - */ - - RequestBase.prototype.parse = function (fn) { - this._parser = fn; - return this; - }; - - /** - * Set format of binary response body. - * In browser valid formats are 'blob' and 'arraybuffer', - * which return Blob and ArrayBuffer, respectively. - * - * In Node all values result in Buffer. - * - * Examples: - * - * req.get('/') - * .responseType('blob') - * .end(callback); - * - * @param {String} val - * @return {Request} for chaining - * @api public - */ - - RequestBase.prototype.responseType = function (value) { - this._responseType = value; - return this; - }; - - /** - * Override default request body serializer - * - * This function will be called to convert data set via .send or .attach into payload to send - * - * @param {Function} - * @api public - */ - - RequestBase.prototype.serialize = function (fn) { - this._serializer = fn; - return this; - }; - - /** - * Set timeouts. - * - * - response timeout is time between sending request and receiving the first byte of the response. Includes DNS and connection time. - * - deadline is the time from start of the request to receiving response body in full. If the deadline is too short large files may not load at all on slow connections. - * - upload is the time since last bit of data was sent or received. This timeout works only if deadline timeout is off - * - * Value of 0 or false means no timeout. - * - * @param {Number|Object} ms or {response, deadline} - * @return {Request} for chaining - * @api public - */ - - RequestBase.prototype.timeout = function (options) { - if (!options || typeof options !== 'object') { - this._timeout = options; - this._responseTimeout = 0; - this._uploadTimeout = 0; - return this; - } - for (const option in options) { - if (hasOwn(options, option)) { - switch (option) { - case 'deadline': - this._timeout = options.deadline; - break; - case 'response': - this._responseTimeout = options.response; - break; - case 'upload': - this._uploadTimeout = options.upload; - break; - default: - console.warn('Unknown timeout option', option); - } - } - } - return this; - }; - - /** - * Set number of retry attempts on error. - * - * Failed requests will be retried 'count' times if timeout or err.code >= 500. - * - * @param {Number} count - * @param {Function} [fn] - * @return {Request} for chaining - * @api public - */ - - RequestBase.prototype.retry = function (count, fn) { - // Default to 1 if no count passed or true - if (arguments.length === 0 || count === true) count = 1; - if (count <= 0) count = 0; - this._maxRetries = count; - this._retries = 0; - this._retryCallback = fn; - return this; - }; - - // - // NOTE: we do not include ESOCKETTIMEDOUT because that is from `request` package - // - // - // NOTE: we do not include EADDRINFO because it was removed from libuv in 2014 - // - // - // - // - // TODO: expose these as configurable defaults - // - const ERROR_CODES = new Set(['ETIMEDOUT', 'ECONNRESET', 'EADDRINUSE', 'ECONNREFUSED', 'EPIPE', 'ENOTFOUND', 'ENETUNREACH', 'EAI_AGAIN']); - const STATUS_CODES = new Set([408, 413, 429, 500, 502, 503, 504, 521, 522, 524]); - - // TODO: we would need to make this easily configurable before adding it in (e.g. some might want to add POST) - // const METHODS = new Set(['GET', 'PUT', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE']); - - /** - * Determine if a request should be retried. - * (Inspired by https://github.com/sindresorhus/got#retry) - * - * @param {Error} err an error - * @param {Response} [res] response - * @returns {Boolean} if segment should be retried - */ - RequestBase.prototype._shouldRetry = function (error, res) { - if (!this._maxRetries || this._retries++ >= this._maxRetries) { - return false; - } - if (this._retryCallback) { - try { - const override = this._retryCallback(error, res); - if (override === true) return true; - if (override === false) return false; - // undefined falls back to defaults - } catch (err) { - console.error(err); - } - } - - // TODO: we would need to make this easily configurable before adding it in (e.g. some might want to add POST) - /* - if ( - this.req && - this.req.method && - !METHODS.has(this.req.method.toUpperCase()) - ) - return false; - */ - if (res && res.status && STATUS_CODES.has(res.status)) return true; - if (error) { - if (error.code && ERROR_CODES.has(error.code)) return true; - // Superagent timeout - if (error.timeout && error.code === 'ECONNABORTED') return true; - if (error.crossDomain) return true; - } - return false; - }; - - /** - * Retry request - * - * @return {Request} for chaining - * @api private - */ - - RequestBase.prototype._retry = function () { - this.clearTimeout(); - - // node - if (this.req) { - this.req = null; - this.req = this.request(); - } - this._aborted = false; - this.timedout = false; - this.timedoutError = null; - return this._end(); - }; - - /** - * Promise support - * - * @param {Function} resolve - * @param {Function} [reject] - * @return {Request} - */ - - RequestBase.prototype.then = function (resolve, reject) { - if (!this._fullfilledPromise) { - const self = this; - if (this._endCalled) { - console.warn('Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises'); - } - this._fullfilledPromise = new Promise((resolve, reject) => { - self.on('abort', () => { - if (this._maxRetries && this._maxRetries > this._retries) { - return; - } - if (this.timedout && this.timedoutError) { - reject(this.timedoutError); - return; - } - const error = new Error('Aborted'); - error.code = 'ABORTED'; - error.status = this.status; - error.method = this.method; - error.url = this.url; - reject(error); - }); - self.end((error, res) => { - if (error) reject(error);else resolve(res); - }); - }); - } - return this._fullfilledPromise.then(resolve, reject); - }; - RequestBase.prototype.catch = function (callback) { - return this.then(undefined, callback); - }; - - /** - * Allow for extension - */ - - RequestBase.prototype.use = function (fn) { - fn(this); - return this; - }; - RequestBase.prototype.ok = function (callback) { - if (typeof callback !== 'function') throw new Error('Callback required'); - this._okCallback = callback; - return this; - }; - RequestBase.prototype._isResponseOK = function (res) { - if (!res) { - return false; - } - if (this._okCallback) { - return this._okCallback(res); - } - return res.status >= 200 && res.status < 300; - }; - - /** - * Get request header `field`. - * Case-insensitive. - * - * @param {String} field - * @return {String} - * @api public - */ - - RequestBase.prototype.get = function (field) { - return this._header[field.toLowerCase()]; - }; - - /** - * Get case-insensitive header `field` value. - * This is a deprecated internal API. Use `.get(field)` instead. - * - * (getHeader is no longer used internally by the superagent code base) - * - * @param {String} field - * @return {String} - * @api private - * @deprecated - */ - - RequestBase.prototype.getHeader = RequestBase.prototype.get; - - /** - * Set header `field` to `val`, or multiple fields with one object. - * Case-insensitive. - * - * Examples: - * - * req.get('/') - * .set('Accept', 'application/json') - * .set('X-API-Key', 'foobar') - * .end(callback); - * - * req.get('/') - * .set({ Accept: 'application/json', 'X-API-Key': 'foobar' }) - * .end(callback); - * - * @param {String|Object} field - * @param {String} val - * @return {Request} for chaining - * @api public - */ - - RequestBase.prototype.set = function (field, value) { - if (isObject(field)) { - for (const key in field) { - if (hasOwn(field, key)) this.set(key, field[key]); - } - return this; - } - this._header[field.toLowerCase()] = value; - this.header[field] = value; - return this; - }; - - /** - * Remove header `field`. - * Case-insensitive. - * - * Example: - * - * req.get('/') - * .unset('User-Agent') - * .end(callback); - * - * @param {String} field field name - */ - RequestBase.prototype.unset = function (field) { - delete this._header[field.toLowerCase()]; - delete this.header[field]; - return this; - }; - - /** - * Write the field `name` and `val`, or multiple fields with one object - * for "multipart/form-data" request bodies. - * - * ``` js - * request.post('/upload') - * .field('foo', 'bar') - * .end(callback); - * - * request.post('/upload') - * .field({ foo: 'bar', baz: 'qux' }) - * .end(callback); - * ``` - * - * @param {String|Object} name name of field - * @param {String|Blob|File|Buffer|fs.ReadStream} val value of field - * @param {String} options extra options, e.g. 'blob' - * @return {Request} for chaining - * @api public - */ - RequestBase.prototype.field = function (name, value, options) { - // name should be either a string or an object. - if (name === null || undefined === name) { - throw new Error('.field(name, val) name can not be empty'); - } - if (this._data) { - throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()"); - } - if (isObject(name)) { - for (const key in name) { - if (hasOwn(name, key)) this.field(key, name[key]); - } - return this; - } - if (Array.isArray(value)) { - for (const i in value) { - if (hasOwn(value, i)) this.field(name, value[i]); - } - return this; - } - - // val should be defined now - if (value === null || undefined === value) { - throw new Error('.field(name, val) val can not be empty'); - } - if (typeof value === 'boolean') { - value = String(value); - } - - // fix https://github.com/ladjs/superagent/issues/1680 - if (options) this._getFormData().append(name, value, options);else this._getFormData().append(name, value); - return this; - }; - - /** - * Abort the request, and clear potential timeout. - * - * @return {Request} request - * @api public - */ - RequestBase.prototype.abort = function () { - if (this._aborted) { - return this; - } - this._aborted = true; - if (this.xhr) this.xhr.abort(); // browser - if (this.req) { - // Node v13 has major differences in `abort()` - // https://github.com/nodejs/node/blob/v12.x/lib/internal/streams/end-of-stream.js - // https://github.com/nodejs/node/blob/v13.x/lib/internal/streams/end-of-stream.js - // https://github.com/nodejs/node/blob/v14.x/lib/internal/streams/end-of-stream.js - // (if you run a diff across these you will see the differences) - // - // References: - // - // - // - // Thanks to @shadowgate15 and @niftylettuce - if (semver.gte(process.version, 'v13.0.0') && semver.lt(process.version, 'v14.0.0')) { - // Note that the reason this doesn't work is because in v13 as compared to v14 - // there is no `callback = nop` set in end-of-stream.js above - throw new Error('Superagent does not work in v13 properly with abort() due to Node.js core changes'); - } - this.req.abort(); // node - } - - this.clearTimeout(); - this.emit('abort'); - return this; - }; - RequestBase.prototype._auth = function (user, pass, options, base64Encoder) { - switch (options.type) { - case 'basic': - this.set('Authorization', `Basic ${base64Encoder(`${user}:${pass}`)}`); - break; - case 'auto': - this.username = user; - this.password = pass; - break; - case 'bearer': - // usage would be .auth(accessToken, { type: 'bearer' }) - this.set('Authorization', `Bearer ${user}`); - break; - } - return this; - }; - - /** - * Enable transmission of cookies with x-domain requests. - * - * Note that for this to work the origin must not be - * using "Access-Control-Allow-Origin" with a wildcard, - * and also must set "Access-Control-Allow-Credentials" - * to "true". - * @param {Boolean} [on=true] - Set 'withCredentials' state - * @return {Request} for chaining - * @api public - */ - - RequestBase.prototype.withCredentials = function (on) { - // This is browser-only functionality. Node side is no-op. - if (on === undefined) on = true; - this._withCredentials = on; - return this; - }; - - /** - * Set the max redirects to `n`. Does nothing in browser XHR implementation. - * - * @param {Number} n - * @return {Request} for chaining - * @api public - */ - - RequestBase.prototype.redirects = function (n) { - this._maxRedirects = n; - return this; - }; - - /** - * Maximum size of buffered response body, in bytes. Counts uncompressed size. - * Default 200MB. - * - * @param {Number} n number of bytes - * @return {Request} for chaining - */ - RequestBase.prototype.maxResponseSize = function (n) { - if (typeof n !== 'number') { - throw new TypeError('Invalid argument'); - } - this._maxResponseSize = n; - return this; - }; - - /** - * Convert to a plain javascript object (not JSON string) of scalar properties. - * Note as this method is designed to return a useful non-this value, - * it cannot be chained. - * - * @return {Object} describing method, url, and data of this request - * @api public - */ - - RequestBase.prototype.toJSON = function () { - return { - method: this.method, - url: this.url, - data: this._data, - headers: this._header - }; - }; - - /** - * Send `data` as the request body, defaulting the `.type()` to "json" when - * an object is given. - * - * Examples: - * - * // manual json - * request.post('/user') - * .type('json') - * .send('{"name":"tj"}') - * .end(callback) - * - * // auto json - * request.post('/user') - * .send({ name: 'tj' }) - * .end(callback) - * - * // manual x-www-form-urlencoded - * request.post('/user') - * .type('form') - * .send('name=tj') - * .end(callback) - * - * // auto x-www-form-urlencoded - * request.post('/user') - * .type('form') - * .send({ name: 'tj' }) - * .end(callback) - * - * // defaults to x-www-form-urlencoded - * request.post('/user') - * .send('name=tobi') - * .send('species=ferret') - * .end(callback) - * - * @param {String|Object} data - * @return {Request} for chaining - * @api public - */ - - // eslint-disable-next-line complexity - RequestBase.prototype.send = function (data) { - const isObject_ = isObject(data); - let type = this._header['content-type']; - if (this._formData) { - throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()"); - } - if (isObject_ && !this._data) { - if (Array.isArray(data)) { - this._data = []; - } else if (!this._isHost(data)) { - this._data = {}; - } - } else if (data && this._data && this._isHost(this._data)) { - throw new Error("Can't merge these send calls"); - } - - // merge - if (isObject_ && isObject(this._data)) { - for (const key in data) { - if (typeof data[key] == 'bigint' && !data[key].toJSON) throw new Error('Cannot serialize BigInt value to json'); - if (hasOwn(data, key)) this._data[key] = data[key]; - } - } else if (typeof data === 'bigint') throw new Error("Cannot send value of type BigInt");else if (typeof data === 'string') { - // default to x-www-form-urlencoded - if (!type) this.type('form'); - type = this._header['content-type']; - if (type) type = type.toLowerCase().trim(); - if (type === 'application/x-www-form-urlencoded') { - this._data = this._data ? `${this._data}&${data}` : data; - } else { - this._data = (this._data || '') + data; - } - } else { - this._data = data; - } - if (!isObject_ || this._isHost(data)) { - return this; - } - - // default to json - if (!type) this.type('json'); - return this; - }; - - /** - * Sort `querystring` by the sort function - * - * - * Examples: - * - * // default order - * request.get('/user') - * .query('name=Nick') - * .query('search=Manny') - * .sortQuery() - * .end(callback) - * - * // customized sort function - * request.get('/user') - * .query('name=Nick') - * .query('search=Manny') - * .sortQuery(function(a, b){ - * return a.length - b.length; - * }) - * .end(callback) - * - * - * @param {Function} sort - * @return {Request} for chaining - * @api public - */ - - RequestBase.prototype.sortQuery = function (sort) { - // _sort default to true but otherwise can be a function or boolean - this._sort = typeof sort === 'undefined' ? true : sort; - return this; - }; - - /** - * Compose querystring to append to req.url - * - * @api private - */ - RequestBase.prototype._finalizeQueryString = function () { - const query = this._query.join('&'); - if (query) { - this.url += (this.url.includes('?') ? '&' : '?') + query; - } - this._query.length = 0; // Makes the call idempotent - - if (this._sort) { - const index = this.url.indexOf('?'); - if (index >= 0) { - const queryArray = this.url.slice(index + 1).split('&'); - if (typeof this._sort === 'function') { - queryArray.sort(this._sort); - } else { - queryArray.sort(); - } - this.url = this.url.slice(0, index) + '?' + queryArray.join('&'); - } - } - }; - - // For backwards compat only - RequestBase.prototype._appendQueryString = () => { - console.warn('Unsupported'); - }; - - /** - * Invoke callback with timeout error. - * - * @api private - */ - - RequestBase.prototype._timeoutError = function (reason, timeout, errno) { - if (this._aborted) { - return; - } - const error = new Error(`${reason + timeout}ms exceeded`); - error.timeout = timeout; - error.code = 'ECONNABORTED'; - error.errno = errno; - this.timedout = true; - this.timedoutError = error; - this.abort(); - this.callback(error); - }; - RequestBase.prototype._setTimeouts = function () { - const self = this; - - // deadline - if (this._timeout && !this._timer) { - this._timer = setTimeout(() => { - self._timeoutError('Timeout of ', self._timeout, 'ETIME'); - }, this._timeout); - } - - // response timeout - if (this._responseTimeout && !this._responseTimeoutTimer) { - this._responseTimeoutTimer = setTimeout(() => { - self._timeoutError('Response timeout of ', self._responseTimeout, 'ETIMEDOUT'); - }, this._responseTimeout); - } - }; - - /** - * Module dependencies. - */ - - const utils = utils$1; - - /** - * Expose `ResponseBase`. - */ - - var responseBase = ResponseBase; - - /** - * Initialize a new `ResponseBase`. - * - * @api public - */ - - function ResponseBase() {} - - /** - * Get case-insensitive `field` value. - * - * @param {String} field - * @return {String} - * @api public - */ - - ResponseBase.prototype.get = function (field) { - return this.header[field.toLowerCase()]; - }; - - /** - * Set header related properties: - * - * - `.type` the content type without params - * - * A response of "Content-Type: text/plain; charset=utf-8" - * will provide you with a `.type` of "text/plain". - * - * @param {Object} header - * @api private - */ - - ResponseBase.prototype._setHeaderProperties = function (header) { - // TODO: moar! - // TODO: make this a util - - // content-type - const ct = header['content-type'] || ''; - this.type = utils.type(ct); - - // params - const parameters = utils.params(ct); - for (const key in parameters) { - if (Object.prototype.hasOwnProperty.call(parameters, key)) this[key] = parameters[key]; - } - this.links = {}; - - // links - try { - if (header.link) { - this.links = utils.parseLinks(header.link); - } - } catch (err) { - // ignore - } - }; - - /** - * Set flags such as `.ok` based on `status`. - * - * For example a 2xx response will give you a `.ok` of __true__ - * whereas 5xx will be __false__ and `.error` will be __true__. The - * `.clientError` and `.serverError` are also available to be more - * specific, and `.statusType` is the class of error ranging from 1..5 - * sometimes useful for mapping respond colors etc. - * - * "sugar" properties are also defined for common cases. Currently providing: - * - * - .noContent - * - .badRequest - * - .unauthorized - * - .notAcceptable - * - .notFound - * - * @param {Number} status - * @api private - */ - - ResponseBase.prototype._setStatusProperties = function (status) { - const type = Math.trunc(status / 100); - - // status / class - this.statusCode = status; - this.status = this.statusCode; - this.statusType = type; - - // basics - this.info = type === 1; - this.ok = type === 2; - this.redirect = type === 3; - this.clientError = type === 4; - this.serverError = type === 5; - this.error = type === 4 || type === 5 ? this.toError() : false; - - // sugar - this.created = status === 201; - this.accepted = status === 202; - this.noContent = status === 204; - this.badRequest = status === 400; - this.unauthorized = status === 401; - this.notAcceptable = status === 406; - this.forbidden = status === 403; - this.notFound = status === 404; - this.unprocessableEntity = status === 422; - }; - - function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } - function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } - function Agent() { - this._defaults = []; - } - for (var _i = 0, _arr = ['use', 'on', 'once', 'set', 'query', 'type', 'accept', 'auth', 'withCredentials', 'sortQuery', 'retry', 'ok', 'redirects', 'timeout', 'buffer', 'serialize', 'parse', 'ca', 'key', 'pfx', 'cert', 'disableTLSCerts']; _i < _arr.length; _i++) { - const fn = _arr[_i]; - // Default setting for all requests from this agent - Agent.prototype[fn] = function () { - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; - } - this._defaults.push({ - fn, - args - }); - return this; - }; - } - Agent.prototype._setDefaults = function (request) { - var _iterator = _createForOfIteratorHelper(this._defaults), - _step; - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - const def = _step.value; - request[def.fn](...def.args); - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - }; - var agentBase = Agent; - - (function (module, exports) { - - function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; } - function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } - /** - * Root reference for iframes. - */ - - let root; - if (typeof window !== 'undefined') { - // Browser window - root = window; - } else if (typeof self === 'undefined') { - // Other environments - console.warn('Using browser-only version of superagent in non-browser environment'); - root = void 0; - } else { - // Web Worker - root = self; - } - const Emitter = componentEmitter.exports; - const safeStringify = fastSafeStringify; - const qs = lib; - const RequestBase = requestBase; - const _require = utils$1, - isObject = _require.isObject, - mixin = _require.mixin, - hasOwn = _require.hasOwn; - const ResponseBase = responseBase; - const Agent = agentBase; - - /** - * Noop. - */ - - function noop() {} - - /** - * Expose `request`. - */ - - module.exports = function (method, url) { - // callback - if (typeof url === 'function') { - return new exports.Request('GET', method).end(url); - } - - // url first - if (arguments.length === 1) { - return new exports.Request('GET', method); - } - return new exports.Request(method, url); - }; - exports = module.exports; - const request = exports; - exports.Request = Request; - - /** - * Determine XHR. - */ - - request.getXHR = () => { - if (root.XMLHttpRequest) { - return new root.XMLHttpRequest(); - } - throw new Error('Browser-only version of superagent could not find XHR'); - }; - - /** - * Removes leading and trailing whitespace, added to support IE. - * - * @param {String} s - * @return {String} - * @api private - */ - - const trim = ''.trim ? s => s.trim() : s => s.replace(/(^\s*|\s*$)/g, ''); - - /** - * Serialize the given `obj`. - * - * @param {Object} obj - * @return {String} - * @api private - */ - - function serialize(object) { - if (!isObject(object)) return object; - const pairs = []; - for (const key in object) { - if (hasOwn(object, key)) pushEncodedKeyValuePair(pairs, key, object[key]); - } - return pairs.join('&'); - } - - /** - * Helps 'serialize' with serializing arrays. - * Mutates the pairs array. - * - * @param {Array} pairs - * @param {String} key - * @param {Mixed} val - */ - - function pushEncodedKeyValuePair(pairs, key, value) { - if (value === undefined) return; - if (value === null) { - pairs.push(encodeURI(key)); - return; - } - if (Array.isArray(value)) { - var _iterator = _createForOfIteratorHelper(value), - _step; - try { - for (_iterator.s(); !(_step = _iterator.n()).done;) { - const v = _step.value; - pushEncodedKeyValuePair(pairs, key, v); - } - } catch (err) { - _iterator.e(err); - } finally { - _iterator.f(); - } - } else if (isObject(value)) { - for (const subkey in value) { - if (hasOwn(value, subkey)) pushEncodedKeyValuePair(pairs, `${key}[${subkey}]`, value[subkey]); - } - } else { - pairs.push(encodeURI(key) + '=' + encodeURIComponent(value)); - } - } - - /** - * Expose serialization method. - */ - - request.serializeObject = serialize; - - /** - * Parse the given x-www-form-urlencoded `str`. - * - * @param {String} str - * @return {Object} - * @api private - */ - - function parseString(string_) { - const object = {}; - const pairs = string_.split('&'); - let pair; - let pos; - for (let i = 0, length_ = pairs.length; i < length_; ++i) { - pair = pairs[i]; - pos = pair.indexOf('='); - if (pos === -1) { - object[decodeURIComponent(pair)] = ''; - } else { - object[decodeURIComponent(pair.slice(0, pos))] = decodeURIComponent(pair.slice(pos + 1)); - } - } - return object; - } - - /** - * Expose parser. - */ - - request.parseString = parseString; - - /** - * Default MIME type map. - * - * superagent.types.xml = 'application/xml'; - * - */ - - request.types = { - html: 'text/html', - json: 'application/json', - xml: 'text/xml', - urlencoded: 'application/x-www-form-urlencoded', - form: 'application/x-www-form-urlencoded', - 'form-data': 'application/x-www-form-urlencoded' - }; - - /** - * Default serialization map. - * - * superagent.serialize['application/xml'] = function(obj){ - * return 'generated xml here'; - * }; - * - */ - - request.serialize = { - 'application/x-www-form-urlencoded': qs.stringify, - 'application/json': safeStringify - }; - - /** - * Default parsers. - * - * superagent.parse['application/xml'] = function(str){ - * return { object parsed from str }; - * }; - * - */ - - request.parse = { - 'application/x-www-form-urlencoded': parseString, - 'application/json': JSON.parse - }; - - /** - * Parse the given header `str` into - * an object containing the mapped fields. - * - * @param {String} str - * @return {Object} - * @api private - */ - - function parseHeader(string_) { - const lines = string_.split(/\r?\n/); - const fields = {}; - let index; - let line; - let field; - let value; - for (let i = 0, length_ = lines.length; i < length_; ++i) { - line = lines[i]; - index = line.indexOf(':'); - if (index === -1) { - // could be empty line, just skip it - continue; - } - field = line.slice(0, index).toLowerCase(); - value = trim(line.slice(index + 1)); - fields[field] = value; - } - return fields; - } - - /** - * Check if `mime` is json or has +json structured syntax suffix. - * - * @param {String} mime - * @return {Boolean} - * @api private - */ - - function isJSON(mime) { - // should match /json or +json - // but not /json-seq - return /[/+]json($|[^-\w])/i.test(mime); - } - - /** - * Initialize a new `Response` with the given `xhr`. - * - * - set flags (.ok, .error, etc) - * - parse header - * - * Examples: - * - * Aliasing `superagent` as `request` is nice: - * - * request = superagent; - * - * We can use the promise-like API, or pass callbacks: - * - * request.get('/').end(function(res){}); - * request.get('/', function(res){}); - * - * Sending data can be chained: - * - * request - * .post('/user') - * .send({ name: 'tj' }) - * .end(function(res){}); - * - * Or passed to `.send()`: - * - * request - * .post('/user') - * .send({ name: 'tj' }, function(res){}); - * - * Or passed to `.post()`: - * - * request - * .post('/user', { name: 'tj' }) - * .end(function(res){}); - * - * Or further reduced to a single call for simple cases: - * - * request - * .post('/user', { name: 'tj' }, function(res){}); - * - * @param {XMLHTTPRequest} xhr - * @param {Object} options - * @api private - */ - - function Response(request_) { - this.req = request_; - this.xhr = this.req.xhr; - // responseText is accessible only if responseType is '' or 'text' and on older browsers - this.text = this.req.method !== 'HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text') || typeof this.xhr.responseType === 'undefined' ? this.xhr.responseText : null; - this.statusText = this.req.xhr.statusText; - let status = this.xhr.status; - // handle IE9 bug: http://stackoverflow.com/questions/10046972/msie-returns-status-code-of-1223-for-ajax-request - if (status === 1223) { - status = 204; - } - this._setStatusProperties(status); - this.headers = parseHeader(this.xhr.getAllResponseHeaders()); - this.header = this.headers; - // getAllResponseHeaders sometimes falsely returns "" for CORS requests, but - // getResponseHeader still works. so we get content-type even if getting - // other headers fails. - this.header['content-type'] = this.xhr.getResponseHeader('content-type'); - this._setHeaderProperties(this.header); - if (this.text === null && request_._responseType) { - this.body = this.xhr.response; - } else { - this.body = this.req.method === 'HEAD' ? null : this._parseBody(this.text ? this.text : this.xhr.response); - } - } - mixin(Response.prototype, ResponseBase.prototype); - - /** - * Parse the given body `str`. - * - * Used for auto-parsing of bodies. Parsers - * are defined on the `superagent.parse` object. - * - * @param {String} str - * @return {Mixed} - * @api private - */ - - Response.prototype._parseBody = function (string_) { - let parse = request.parse[this.type]; - if (this.req._parser) { - return this.req._parser(this, string_); - } - if (!parse && isJSON(this.type)) { - parse = request.parse['application/json']; - } - return parse && string_ && (string_.length > 0 || string_ instanceof Object) ? parse(string_) : null; - }; - - /** - * Return an `Error` representative of this response. - * - * @return {Error} - * @api public - */ - - Response.prototype.toError = function () { - const req = this.req; - const method = req.method; - const url = req.url; - const message = `cannot ${method} ${url} (${this.status})`; - const error = new Error(message); - error.status = this.status; - error.method = method; - error.url = url; - return error; - }; - - /** - * Expose `Response`. - */ - - request.Response = Response; - - /** - * Initialize a new `Request` with the given `method` and `url`. - * - * @param {String} method - * @param {String} url - * @api public - */ - - function Request(method, url) { - const self = this; - this._query = this._query || []; - this.method = method; - this.url = url; - this.header = {}; // preserves header name case - this._header = {}; // coerces header names to lowercase - this.on('end', () => { - let error = null; - let res = null; - try { - res = new Response(self); - } catch (err) { - error = new Error('Parser is unable to parse the response'); - error.parse = true; - error.original = err; - // issue #675: return the raw response if the response parsing fails - if (self.xhr) { - // ie9 doesn't have 'response' property - error.rawResponse = typeof self.xhr.responseType === 'undefined' ? self.xhr.responseText : self.xhr.response; - // issue #876: return the http status code if the response parsing fails - error.status = self.xhr.status ? self.xhr.status : null; - error.statusCode = error.status; // backwards-compat only - } else { - error.rawResponse = null; - error.status = null; - } - return self.callback(error); - } - self.emit('response', res); - let new_error; - try { - if (!self._isResponseOK(res)) { - new_error = new Error(res.statusText || res.text || 'Unsuccessful HTTP response'); - } - } catch (err) { - new_error = err; // ok() callback can throw - } - - // #1000 don't catch errors from the callback to avoid double calling it - if (new_error) { - new_error.original = error; - new_error.response = res; - new_error.status = new_error.status || res.status; - self.callback(new_error, res); - } else { - self.callback(null, res); - } - }); - } - - /** - * Mixin `Emitter` and `RequestBase`. - */ - - // eslint-disable-next-line new-cap - Emitter(Request.prototype); - mixin(Request.prototype, RequestBase.prototype); - - /** - * Set Content-Type to `type`, mapping values from `request.types`. - * - * Examples: - * - * superagent.types.xml = 'application/xml'; - * - * request.post('/') - * .type('xml') - * .send(xmlstring) - * .end(callback); - * - * request.post('/') - * .type('application/xml') - * .send(xmlstring) - * .end(callback); - * - * @param {String} type - * @return {Request} for chaining - * @api public - */ - - Request.prototype.type = function (type) { - this.set('Content-Type', request.types[type] || type); - return this; - }; - - /** - * Set Accept to `type`, mapping values from `request.types`. - * - * Examples: - * - * superagent.types.json = 'application/json'; - * - * request.get('/agent') - * .accept('json') - * .end(callback); - * - * request.get('/agent') - * .accept('application/json') - * .end(callback); - * - * @param {String} accept - * @return {Request} for chaining - * @api public - */ - - Request.prototype.accept = function (type) { - this.set('Accept', request.types[type] || type); - return this; - }; - - /** - * Set Authorization field value with `user` and `pass`. - * - * @param {String} user - * @param {String} [pass] optional in case of using 'bearer' as type - * @param {Object} options with 'type' property 'auto', 'basic' or 'bearer' (default 'basic') - * @return {Request} for chaining - * @api public - */ - - Request.prototype.auth = function (user, pass, options) { - if (arguments.length === 1) pass = ''; - if (typeof pass === 'object' && pass !== null) { - // pass is optional and can be replaced with options - options = pass; - pass = ''; - } - if (!options) { - options = { - type: typeof btoa === 'function' ? 'basic' : 'auto' - }; - } - const encoder = options.encoder ? options.encoder : string => { - if (typeof btoa === 'function') { - return btoa(string); - } - throw new Error('Cannot use basic auth, btoa is not a function'); - }; - return this._auth(user, pass, options, encoder); - }; - - /** - * Add query-string `val`. - * - * Examples: - * - * request.get('/shoes') - * .query('size=10') - * .query({ color: 'blue' }) - * - * @param {Object|String} val - * @return {Request} for chaining - * @api public - */ - - Request.prototype.query = function (value) { - if (typeof value !== 'string') value = serialize(value); - if (value) this._query.push(value); - return this; - }; - - /** - * Queue the given `file` as an attachment to the specified `field`, - * with optional `options` (or filename). - * - * ``` js - * request.post('/upload') - * .attach('content', new Blob(['hey!'], { type: "text/html"})) - * .end(callback); - * ``` - * - * @param {String} field - * @param {Blob|File} file - * @param {String|Object} options - * @return {Request} for chaining - * @api public - */ - - Request.prototype.attach = function (field, file, options) { - if (file) { - if (this._data) { - throw new Error("superagent can't mix .send() and .attach()"); - } - this._getFormData().append(field, file, options || file.name); - } - return this; - }; - Request.prototype._getFormData = function () { - if (!this._formData) { - this._formData = new root.FormData(); - } - return this._formData; - }; - - /** - * Invoke the callback with `err` and `res` - * and handle arity check. - * - * @param {Error} err - * @param {Response} res - * @api private - */ - - Request.prototype.callback = function (error, res) { - if (this._shouldRetry(error, res)) { - return this._retry(); - } - const fn = this._callback; - this.clearTimeout(); - if (error) { - if (this._maxRetries) error.retries = this._retries - 1; - this.emit('error', error); - } - fn(error, res); - }; - - /** - * Invoke callback with x-domain error. - * - * @api private - */ - - Request.prototype.crossDomainError = function () { - const error = new Error('Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.'); - error.crossDomain = true; - error.status = this.status; - error.method = this.method; - error.url = this.url; - this.callback(error); - }; - - // This only warns, because the request is still likely to work - Request.prototype.agent = function () { - console.warn('This is not supported in browser version of superagent'); - return this; - }; - Request.prototype.ca = Request.prototype.agent; - Request.prototype.buffer = Request.prototype.ca; - - // This throws, because it can't send/receive data as expected - Request.prototype.write = () => { - throw new Error('Streaming is not supported in browser version of superagent'); - }; - Request.prototype.pipe = Request.prototype.write; - - /** - * Check if `obj` is a host object, - * we don't want to serialize these :) - * - * @param {Object} obj host object - * @return {Boolean} is a host object - * @api private - */ - Request.prototype._isHost = function (object) { - // Native objects stringify to [object File], [object Blob], [object FormData], etc. - return object && typeof object === 'object' && !Array.isArray(object) && Object.prototype.toString.call(object) !== '[object Object]'; - }; - - /** - * Initiate request, invoking callback `fn(res)` - * with an instanceof `Response`. - * - * @param {Function} fn - * @return {Request} for chaining - * @api public - */ - - Request.prototype.end = function (fn) { - if (this._endCalled) { - console.warn('Warning: .end() was called twice. This is not supported in superagent'); - } - this._endCalled = true; - - // store callback - this._callback = fn || noop; - - // querystring - this._finalizeQueryString(); - this._end(); - }; - Request.prototype._setUploadTimeout = function () { - const self = this; - - // upload timeout it's wokrs only if deadline timeout is off - if (this._uploadTimeout && !this._uploadTimeoutTimer) { - this._uploadTimeoutTimer = setTimeout(() => { - self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT'); - }, this._uploadTimeout); - } - }; - - // eslint-disable-next-line complexity - Request.prototype._end = function () { - if (this._aborted) return this.callback(new Error('The request has been aborted even before .end() was called')); - const self = this; - this.xhr = request.getXHR(); - const xhr = this.xhr; - let data = this._formData || this._data; - this._setTimeouts(); - - // state change - xhr.addEventListener('readystatechange', () => { - const readyState = xhr.readyState; - if (readyState >= 2 && self._responseTimeoutTimer) { - clearTimeout(self._responseTimeoutTimer); - } - if (readyState !== 4) { - return; - } - - // In IE9, reads to any property (e.g. status) off of an aborted XHR will - // result in the error "Could not complete the operation due to error c00c023f" - let status; - try { - status = xhr.status; - } catch (err) { - status = 0; - } - if (!status) { - if (self.timedout || self._aborted) return; - return self.crossDomainError(); - } - self.emit('end'); - }); - - // progress - const handleProgress = (direction, e) => { - if (e.total > 0) { - e.percent = e.loaded / e.total * 100; - if (e.percent === 100) { - clearTimeout(self._uploadTimeoutTimer); - } - } - e.direction = direction; - self.emit('progress', e); - }; - if (this.hasListeners('progress')) { - try { - xhr.addEventListener('progress', handleProgress.bind(null, 'download')); - if (xhr.upload) { - xhr.upload.addEventListener('progress', handleProgress.bind(null, 'upload')); - } - } catch (err) { - // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist. - // Reported here: - // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context - } - } - if (xhr.upload) { - this._setUploadTimeout(); - } - - // initiate request - try { - if (this.username && this.password) { - xhr.open(this.method, this.url, true, this.username, this.password); - } else { - xhr.open(this.method, this.url, true); - } - } catch (err) { - // see #1149 - return this.callback(err); - } - - // CORS - if (this._withCredentials) xhr.withCredentials = true; - - // body - if (!this._formData && this.method !== 'GET' && this.method !== 'HEAD' && typeof data !== 'string' && !this._isHost(data)) { - // serialize stuff - const contentType = this._header['content-type']; - let serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : '']; - if (!serialize && isJSON(contentType)) { - serialize = request.serialize['application/json']; - } - if (serialize) data = serialize(data); - } - - // set header fields - for (const field in this.header) { - if (this.header[field] === null) continue; - if (hasOwn(this.header, field)) xhr.setRequestHeader(field, this.header[field]); - } - if (this._responseType) { - xhr.responseType = this._responseType; - } - - // send stuff - this.emit('request', this); - - // IE11 xhr.send(undefined) sends 'undefined' string as POST payload (instead of nothing) - // We need null here if data is undefined - xhr.send(typeof data === 'undefined' ? null : data); - }; - request.agent = () => new Agent(); - for (var _i = 0, _arr = ['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE']; _i < _arr.length; _i++) { - const method = _arr[_i]; - Agent.prototype[method.toLowerCase()] = function (url, fn) { - const request_ = new request.Request(method, url); - this._setDefaults(request_); - if (fn) { - request_.end(fn); - } - return request_; - }; - } - Agent.prototype.del = Agent.prototype.delete; - - /** - * GET `url` with optional callback `fn(res)`. - * - * @param {String} url - * @param {Mixed|Function} [data] or fn - * @param {Function} [fn] - * @return {Request} - * @api public - */ - - request.get = (url, data, fn) => { - const request_ = request('GET', url); - if (typeof data === 'function') { - fn = data; - data = null; - } - if (data) request_.query(data); - if (fn) request_.end(fn); - return request_; - }; - - /** - * HEAD `url` with optional callback `fn(res)`. - * - * @param {String} url - * @param {Mixed|Function} [data] or fn - * @param {Function} [fn] - * @return {Request} - * @api public - */ - - request.head = (url, data, fn) => { - const request_ = request('HEAD', url); - if (typeof data === 'function') { - fn = data; - data = null; - } - if (data) request_.query(data); - if (fn) request_.end(fn); - return request_; - }; - - /** - * OPTIONS query to `url` with optional callback `fn(res)`. - * - * @param {String} url - * @param {Mixed|Function} [data] or fn - * @param {Function} [fn] - * @return {Request} - * @api public - */ - - request.options = (url, data, fn) => { - const request_ = request('OPTIONS', url); - if (typeof data === 'function') { - fn = data; - data = null; - } - if (data) request_.send(data); - if (fn) request_.end(fn); - return request_; - }; - - /** - * DELETE `url` with optional `data` and callback `fn(res)`. - * - * @param {String} url - * @param {Mixed} [data] - * @param {Function} [fn] - * @return {Request} - * @api public - */ - - function del(url, data, fn) { - const request_ = request('DELETE', url); - if (typeof data === 'function') { - fn = data; - data = null; - } - if (data) request_.send(data); - if (fn) request_.end(fn); - return request_; - } - request.del = del; - request.delete = del; - - /** - * PATCH `url` with optional `data` and callback `fn(res)`. - * - * @param {String} url - * @param {Mixed} [data] - * @param {Function} [fn] - * @return {Request} - * @api public - */ - - request.patch = (url, data, fn) => { - const request_ = request('PATCH', url); - if (typeof data === 'function') { - fn = data; - data = null; - } - if (data) request_.send(data); - if (fn) request_.end(fn); - return request_; - }; - - /** - * POST `url` with optional `data` and callback `fn(res)`. - * - * @param {String} url - * @param {Mixed} [data] - * @param {Function} [fn] - * @return {Request} - * @api public - */ - - request.post = (url, data, fn) => { - const request_ = request('POST', url); - if (typeof data === 'function') { - fn = data; - data = null; - } - if (data) request_.send(data); - if (fn) request_.end(fn); - return request_; - }; - - /** - * PUT `url` with optional `data` and callback `fn(res)`. - * - * @param {String} url - * @param {Mixed|Function} [data] or fn - * @param {Function} [fn] - * @return {Request} - * @api public - */ - - request.put = (url, data, fn) => { - const request_ = request('PUT', url); - if (typeof data === 'function') { - fn = data; - data = null; - } - if (data) request_.send(data); - if (fn) request_.end(fn); - return request_; - }; - - }(client, client.exports)); - - var superagent = client.exports; - - /* */ - function log(req) { - var _pickLogger = function () { - if (console && console.log) - return console; // eslint-disable-line no-console - if (window && window.console && window.console.log) - return window.console; - return console; - }; - var start = new Date().getTime(); - var timestamp = new Date().toISOString(); - var logger = _pickLogger(); - logger.log('<<<<<'); - logger.log("[".concat(timestamp, "]"), '\n', req.url, '\n', req.qs); - logger.log('-----'); - req.on('response', function (res) { - var now = new Date().getTime(); - var elapsed = now - start; - var timestampDone = new Date().toISOString(); - logger.log('>>>>>>'); - logger.log("[".concat(timestampDone, " / ").concat(elapsed, "]"), '\n', req.url, '\n', req.qs, '\n', res.text); - logger.log('-----'); - }); - } - function xdr(superagentConstruct, endpoint, callback) { - var _this = this; - if (this._config.logVerbosity) { - superagentConstruct = superagentConstruct.use(log); - } - if (this._config.proxy && this._modules.proxy) { - superagentConstruct = this._modules.proxy.call(this, superagentConstruct); - } - if (this._config.keepAlive && this._modules.keepAlive) { - superagentConstruct = this._modules.keepAlive(superagentConstruct); - } - var sc = superagentConstruct; - if (endpoint.abortSignal) { - var unsubscribe_1 = endpoint.abortSignal.subscribe(function () { - sc.abort(); - unsubscribe_1(); - }); - } - if (endpoint.forceBuffered === true) { - if (typeof Blob === 'undefined') { - sc = sc.buffer().responseType('arraybuffer'); - } - else { - sc = sc.responseType('arraybuffer'); - } - } - else if (endpoint.forceBuffered === false) { - sc = sc.buffer(false); - } - sc = sc.timeout(endpoint.timeout); - sc.on('abort', function () { - return callback({ - category: categories.PNUnknownCategory, - error: true, - operation: endpoint.operation, - errorData: new Error('Aborted'), - }, null); - }); - sc.end(function (err, resp) { - var parsedResponse; - var status = {}; - status.error = err !== null; - status.operation = endpoint.operation; - if (resp && resp.status) { - status.statusCode = resp.status; - } - if (err) { - if (err.response && err.response.text && !_this._config.logVerbosity) { - try { - status.errorData = JSON.parse(err.response.text); - } - catch (e) { - status.errorData = err; - } - } - else { - status.errorData = err; - } - status.category = _this._detectErrorCategory(err); - return callback(status, null); - } - if (endpoint.ignoreBody) { - parsedResponse = { - headers: resp.headers, - redirects: resp.redirects, - response: resp, - }; - } - else { - try { - parsedResponse = JSON.parse(resp.text); - } - catch (e) { - status.errorData = resp; - status.error = true; - return callback(status, null); - } - } - if (parsedResponse.error && - parsedResponse.error === 1 && - parsedResponse.status && - parsedResponse.message && - parsedResponse.service) { - status.errorData = parsedResponse; - status.statusCode = parsedResponse.status; - status.error = true; - status.category = _this._detectErrorCategory(status); - return callback(status, null); - } - if (parsedResponse.error && parsedResponse.error.message) { - status.errorData = parsedResponse.error; - } - return callback(status, parsedResponse); - }); - return sc; - } - function postfile(url, fields, fileInput) { - return __awaiter(this, void 0, void 0, function () { - var agent, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - agent = superagent.post(url); - fields.forEach(function (_a) { - var key = _a.key, value = _a.value; - agent = agent.field(key, value); - }); - agent.attach('file', fileInput, { contentType: 'application/octet-stream' }); - return [4 /*yield*/, agent]; - case 1: - result = _a.sent(); - return [2 /*return*/, result]; - } - }); - }); - } - function getfile(params, endpoint, callback) { - var superagentConstruct = superagent - .get(this.getStandardOrigin() + endpoint.url) - .set(endpoint.headers) - .query(params); - return xdr.call(this, superagentConstruct, endpoint, callback); - } - function get(params, endpoint, callback) { - var superagentConstruct = superagent - .get(this.getStandardOrigin() + endpoint.url) - .set(endpoint.headers) - .query(params); - return xdr.call(this, superagentConstruct, endpoint, callback); - } - function post(params, body, endpoint, callback) { - var superagentConstruct = superagent - .post(this.getStandardOrigin() + endpoint.url) - .query(params) - .set(endpoint.headers) - .send(body); - return xdr.call(this, superagentConstruct, endpoint, callback); - } - function patch(params, body, endpoint, callback) { - var superagentConstruct = superagent - .patch(this.getStandardOrigin() + endpoint.url) - .query(params) - .set(endpoint.headers) - .send(body); - return xdr.call(this, superagentConstruct, endpoint, callback); - } - function del(params, endpoint, callback) { - var superagentConstruct = superagent - .delete(this.getStandardOrigin() + endpoint.url) - .set(endpoint.headers) - .query(params); - return xdr.call(this, superagentConstruct, endpoint, callback); - } - - /* global crypto */ - function concatArrayBuffer(ab1, ab2) { - var tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); - tmp.set(new Uint8Array(ab1), 0); - tmp.set(new Uint8Array(ab2), ab1.byteLength); - return tmp.buffer; - } - var WebCryptography = /** @class */ (function () { - function WebCryptography() { - } - Object.defineProperty(WebCryptography.prototype, "algo", { - get: function () { - return 'aes-256-cbc'; - }, - enumerable: false, - configurable: true - }); - WebCryptography.prototype.encrypt = function (key, input) { - return __awaiter(this, void 0, void 0, function () { - var cKey; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.getKey(key)]; - case 1: - cKey = _a.sent(); - if (input instanceof ArrayBuffer) { - return [2 /*return*/, this.encryptArrayBuffer(cKey, input)]; - } - if (typeof input === 'string') { - return [2 /*return*/, this.encryptString(cKey, input)]; - } - throw new Error('Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer'); - } - }); - }); - }; - WebCryptography.prototype.decrypt = function (key, input) { - return __awaiter(this, void 0, void 0, function () { - var cKey; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.getKey(key)]; - case 1: - cKey = _a.sent(); - if (input instanceof ArrayBuffer) { - return [2 /*return*/, this.decryptArrayBuffer(cKey, input)]; - } - if (typeof input === 'string') { - return [2 /*return*/, this.decryptString(cKey, input)]; - } - throw new Error('Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer'); - } - }); - }); - }; - WebCryptography.prototype.encryptFile = function (key, file, File) { - return __awaiter(this, void 0, void 0, function () { - var bKey, abPlaindata, abCipherdata; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (file.data.byteLength <= 0) - throw new Error('encryption error. empty content'); - return [4 /*yield*/, this.getKey(key)]; - case 1: - bKey = _a.sent(); - return [4 /*yield*/, file.data.arrayBuffer()]; - case 2: - abPlaindata = _a.sent(); - return [4 /*yield*/, this.encryptArrayBuffer(bKey, abPlaindata)]; - case 3: - abCipherdata = _a.sent(); - return [2 /*return*/, File.create({ - name: file.name, - mimeType: 'application/octet-stream', - data: abCipherdata, - })]; - } - }); - }); - }; - WebCryptography.prototype.decryptFile = function (key, file, File) { - return __awaiter(this, void 0, void 0, function () { - var bKey, abCipherdata, abPlaindata; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.getKey(key)]; - case 1: - bKey = _a.sent(); - return [4 /*yield*/, file.data.arrayBuffer()]; - case 2: - abCipherdata = _a.sent(); - return [4 /*yield*/, this.decryptArrayBuffer(bKey, abCipherdata)]; - case 3: - abPlaindata = _a.sent(); - return [2 /*return*/, File.create({ - name: file.name, - data: abPlaindata, - })]; - } - }); - }); - }; - WebCryptography.prototype.getKey = function (key) { - return __awaiter(this, void 0, void 0, function () { - var digest, hashHex, abKey; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, crypto.subtle.digest('SHA-256', WebCryptography.encoder.encode(key))]; - case 1: - digest = _a.sent(); - hashHex = Array.from(new Uint8Array(digest)) - .map(function (b) { return b.toString(16).padStart(2, '0'); }) - .join(''); - abKey = WebCryptography.encoder.encode(hashHex.slice(0, 32)).buffer; - return [2 /*return*/, crypto.subtle.importKey('raw', abKey, 'AES-CBC', true, ['encrypt', 'decrypt'])]; - } - }); - }); - }; - WebCryptography.prototype.encryptArrayBuffer = function (key, plaintext) { - return __awaiter(this, void 0, void 0, function () { - var abIv, _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - abIv = crypto.getRandomValues(new Uint8Array(16)); - _a = concatArrayBuffer; - _b = [abIv.buffer]; - return [4 /*yield*/, crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, plaintext)]; - case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; - } - }); - }); - }; - WebCryptography.prototype.decryptArrayBuffer = function (key, ciphertext) { - return __awaiter(this, void 0, void 0, function () { - var abIv, data; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - abIv = ciphertext.slice(0, 16); - if (ciphertext.slice(WebCryptography.IV_LENGTH).byteLength <= 0) - throw new Error('decryption error: empty content'); - return [4 /*yield*/, crypto.subtle.decrypt({ name: 'AES-CBC', iv: abIv }, key, ciphertext.slice(WebCryptography.IV_LENGTH))]; - case 1: - data = _a.sent(); - return [2 /*return*/, data]; - } - }); - }); - }; - WebCryptography.prototype.encryptString = function (key, plaintext) { - return __awaiter(this, void 0, void 0, function () { - var abIv, abPlaintext, abPayload, ciphertext; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - abIv = crypto.getRandomValues(new Uint8Array(16)); - abPlaintext = WebCryptography.encoder.encode(plaintext).buffer; - return [4 /*yield*/, crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, abPlaintext)]; - case 1: - abPayload = _a.sent(); - ciphertext = concatArrayBuffer(abIv.buffer, abPayload); - return [2 /*return*/, WebCryptography.decoder.decode(ciphertext)]; - } - }); - }); - }; - WebCryptography.prototype.decryptString = function (key, ciphertext) { - return __awaiter(this, void 0, void 0, function () { - var abCiphertext, abIv, abPayload, abPlaintext; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - abCiphertext = WebCryptography.encoder.encode(ciphertext).buffer; - abIv = abCiphertext.slice(0, 16); - abPayload = abCiphertext.slice(16); - return [4 /*yield*/, crypto.subtle.decrypt({ name: 'AES-CBC', iv: abIv }, key, abPayload)]; - case 1: - abPlaintext = _a.sent(); - return [2 /*return*/, WebCryptography.decoder.decode(abPlaintext)]; - } - }); - }); - }; - WebCryptography.IV_LENGTH = 16; - WebCryptography.encoder = new TextEncoder(); - WebCryptography.decoder = new TextDecoder(); - return WebCryptography; - }()); - - /* global File, FileReader */ - var _a; - var PubNubFile = (_a = /** @class */ (function () { - function PubNubFile(config) { - if (config instanceof File) { - this.data = config; - this.name = this.data.name; - this.mimeType = this.data.type; - } - else if (config.data) { - var contents = config.data; - this.data = new File([contents], config.name, { type: config.mimeType }); - this.name = config.name; - if (config.mimeType) { - this.mimeType = config.mimeType; - } - } - if (this.data === undefined) { - throw new Error("Couldn't construct a file out of supplied options."); - } - if (this.name === undefined) { - throw new Error("Couldn't guess filename out of the options. Please provide one."); - } - } - PubNubFile.create = function (config) { - return new this(config); - }; - PubNubFile.prototype.toBuffer = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in Node.js environments.'); - }); - }); - }; - PubNubFile.prototype.toStream = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in Node.js environments.'); - }); - }); - }; - PubNubFile.prototype.toFileUri = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in react native environments.'); - }); - }); - }; - PubNubFile.prototype.toBlob = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, this.data]; - }); - }); - }; - PubNubFile.prototype.toArrayBuffer = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - return [2 /*return*/, new Promise(function (resolve, reject) { - var reader = new FileReader(); - reader.addEventListener('load', function () { - if (reader.result instanceof ArrayBuffer) { - return resolve(reader.result); - } - }); - reader.addEventListener('error', function () { - reject(reader.error); - }); - reader.readAsArrayBuffer(_this.data); - })]; - }); - }); - }; - PubNubFile.prototype.toString = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - return [2 /*return*/, new Promise(function (resolve, reject) { - var reader = new FileReader(); - reader.addEventListener('load', function () { - if (typeof reader.result === 'string') { - return resolve(reader.result); - } - }); - reader.addEventListener('error', function () { - reject(reader.error); - }); - reader.readAsBinaryString(_this.data); - })]; - }); - }); - }; - PubNubFile.prototype.toFile = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, this.data]; - }); - }); - }; - return PubNubFile; - }()), - _a.supportsFile = typeof File !== 'undefined', - _a.supportsBlob = typeof Blob !== 'undefined', - _a.supportsArrayBuffer = typeof ArrayBuffer !== 'undefined', - _a.supportsBuffer = false, - _a.supportsStream = false, - _a.supportsString = true, - _a.supportsEncryptFile = true, - _a.supportsFileUri = false, - _a); - - var LegacyCryptor = /** @class */ (function () { - function LegacyCryptor(config) { - this.config = config; - this.cryptor = new default_1$a({ config: config }); - this.fileCryptor = new WebCryptography(); - } - Object.defineProperty(LegacyCryptor.prototype, "identifier", { - get: function () { - return ''; - }, - enumerable: false, - configurable: true - }); - LegacyCryptor.prototype.encrypt = function (data) { - var stringData = typeof data === 'string' ? data : new TextDecoder().decode(data); - return { - data: this.cryptor.encrypt(stringData), - metadata: null, - }; - }; - LegacyCryptor.prototype.decrypt = function (encryptedData) { - var data = typeof encryptedData.data === 'string' ? encryptedData.data : encode$1(encryptedData.data); - return this.cryptor.decrypt(data); - }; - LegacyCryptor.prototype.encryptFile = function (file, File) { - var _a; - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_b) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore: can not detect cipherKey from old Config - return [2 /*return*/, this.fileCryptor.encryptFile((_a = this.config) === null || _a === void 0 ? void 0 : _a.cipherKey, file, File)]; - }); - }); - }; - LegacyCryptor.prototype.decryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore: can not detect cipherKey from old Config - return [2 /*return*/, this.fileCryptor.decryptFile(this.config.cipherKey, file, File)]; - }); - }); - }; - return LegacyCryptor; - }()); - - var AesCbcCryptor = /** @class */ (function () { - function AesCbcCryptor(configuration) { - this.cipherKey = configuration.cipherKey; - this.CryptoJS = hmacSha256; - this.encryptedKey = this.CryptoJS.SHA256(this.cipherKey); - } - Object.defineProperty(AesCbcCryptor.prototype, "algo", { - get: function () { - return 'AES-CBC'; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(AesCbcCryptor.prototype, "identifier", { - get: function () { - return 'ACRH'; - }, - enumerable: false, - configurable: true - }); - AesCbcCryptor.prototype.getIv = function () { - return crypto.getRandomValues(new Uint8Array(AesCbcCryptor.BLOCK_SIZE)); - }; - AesCbcCryptor.prototype.getKey = function () { - return __awaiter(this, void 0, void 0, function () { - var bKey, abHash; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - bKey = AesCbcCryptor.encoder.encode(this.cipherKey); - return [4 /*yield*/, crypto.subtle.digest('SHA-256', bKey.buffer)]; - case 1: - abHash = _a.sent(); - return [2 /*return*/, crypto.subtle.importKey('raw', abHash, this.algo, true, ['encrypt', 'decrypt'])]; - } - }); - }); - }; - AesCbcCryptor.prototype.encrypt = function (data) { - var stringData = typeof data === 'string' ? data : AesCbcCryptor.decoder.decode(data); - if (stringData.length === 0) - throw new Error('encryption error. empty content'); - var abIv = this.getIv(); - return { - metadata: abIv, - data: decode$1(this.CryptoJS.AES.encrypt(data, this.encryptedKey, { - iv: this.bufferToWordArray(abIv), - mode: this.CryptoJS.mode.CBC, - }).ciphertext.toString(this.CryptoJS.enc.Base64)), - }; - }; - AesCbcCryptor.prototype.decrypt = function (encryptedData) { - var iv = this.bufferToWordArray(new Uint8ClampedArray(encryptedData.metadata)); - var data = this.bufferToWordArray(new Uint8ClampedArray(encryptedData.data)); - return AesCbcCryptor.encoder.encode(this.CryptoJS.AES.decrypt({ ciphertext: data }, this.encryptedKey, { - iv: iv, - mode: this.CryptoJS.mode.CBC, - }).toString(this.CryptoJS.enc.Utf8)).buffer; - }; - AesCbcCryptor.prototype.encryptFileData = function (data) { - return __awaiter(this, void 0, void 0, function () { - var key, iv; - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, this.getKey()]; - case 1: - key = _b.sent(); - iv = this.getIv(); - _a = {}; - return [4 /*yield*/, crypto.subtle.encrypt({ name: this.algo, iv: iv }, key, data)]; - case 2: return [2 /*return*/, (_a.data = _b.sent(), - _a.metadata = iv, - _a)]; - } - }); - }); - }; - AesCbcCryptor.prototype.decryptFileData = function (encryptedData) { - return __awaiter(this, void 0, void 0, function () { - var key; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.getKey()]; - case 1: - key = _a.sent(); - return [2 /*return*/, crypto.subtle.decrypt({ name: this.algo, iv: encryptedData.metadata }, key, encryptedData.data)]; - } - }); - }); - }; - AesCbcCryptor.prototype.bufferToWordArray = function (b) { - var wa = []; - var i; - for (i = 0; i < b.length; i += 1) { - wa[(i / 4) | 0] |= b[i] << (24 - 8 * i); - } - return this.CryptoJS.lib.WordArray.create(wa, b.length); - }; - AesCbcCryptor.BLOCK_SIZE = 16; - AesCbcCryptor.encoder = new TextEncoder(); - AesCbcCryptor.decoder = new TextDecoder(); - return AesCbcCryptor; - }()); - - var CryptoModule = /** @class */ (function () { - function CryptoModule(cryptoModuleConfiguration) { - var _a; - this.defaultCryptor = cryptoModuleConfiguration.default; - this.cryptors = (_a = cryptoModuleConfiguration.cryptors) !== null && _a !== void 0 ? _a : []; - } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore: type detection issue with old Config type assignment - CryptoModule.legacyCryptoModule = function (config) { - var _a; - return new this({ - default: new LegacyCryptor({ - cipherKey: config.cipherKey, - useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true, - }), - cryptors: [new AesCbcCryptor({ cipherKey: config.cipherKey })], - }); - }; - CryptoModule.aesCbcCryptoModule = function (config) { - var _a; - return new this({ - default: new AesCbcCryptor({ cipherKey: config.cipherKey }), - cryptors: [ - new LegacyCryptor({ - cipherKey: config.cipherKey, - useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true, - }), - ], - }); - }; - CryptoModule.withDefaultCryptor = function (defaultCryptor) { - return new this({ default: defaultCryptor }); - }; - CryptoModule.prototype.getAllCryptors = function () { - return __spreadArray$1([this.defaultCryptor], __read$1(this.cryptors), false); - }; - CryptoModule.prototype.encrypt = function (data) { - var encrypted = this.defaultCryptor.encrypt(data); - if (!encrypted.metadata) - return encrypted.data; - var headerData = this.getHeaderData(encrypted); - return this.concatArrayBuffer(headerData, encrypted.data); - }; - CryptoModule.prototype.decrypt = function (data) { - var encryptedData = typeof data === 'string' ? decode$1(data) : data; - var header = CryptorHeader.tryParse(encryptedData); - var cryptor = this.getCryptor(header); - var metadata = header.length > 0 - ? encryptedData.slice(header.length - header.metadataLength, header.length) - : null; - if (encryptedData.slice(header.length).byteLength <= 0) - throw new Error('decryption error. empty content'); - return cryptor.decrypt({ - data: encryptedData.slice(header.length), - metadata: metadata, - }); - }; - CryptoModule.prototype.encryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - var fileData, encrypted; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (this.defaultCryptor.identifier === CryptorHeader.LEGACY_IDENTIFIER) - return [2 /*return*/, this.defaultCryptor.encryptFile(file, File)]; - return [4 /*yield*/, this.getFileData(file.data)]; - case 1: - fileData = _a.sent(); - return [4 /*yield*/, this.defaultCryptor.encryptFileData(fileData)]; - case 2: - encrypted = _a.sent(); - return [2 /*return*/, File.create({ - name: file.name, - mimeType: 'application/octet-stream', - data: this.concatArrayBuffer(this.getHeaderData(encrypted), encrypted.data), - })]; - } - }); - }); - }; - CryptoModule.prototype.decryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - var data, header, cryptor, fileData, metadata, _a, _b; - var _c; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: return [4 /*yield*/, file.data.arrayBuffer()]; - case 1: - data = _d.sent(); - header = CryptorHeader.tryParse(data); - cryptor = this.getCryptor(header); - if ((cryptor === null || cryptor === void 0 ? void 0 : cryptor.identifier) === CryptoModule.LEGACY_IDENTIFIER) { - return [2 /*return*/, cryptor.decryptFile(file, File)]; - } - return [4 /*yield*/, this.getFileData(data)]; - case 2: - fileData = _d.sent(); - metadata = fileData.slice(header.length - header.metadataLength, header.length); - _b = (_a = File).create; - _c = { - name: file.name - }; - return [4 /*yield*/, this.defaultCryptor.decryptFileData({ - data: data.slice(header.length), - metadata: metadata, - })]; - case 3: return [2 /*return*/, _b.apply(_a, [(_c.data = _d.sent(), - _c)])]; - } - }); - }); - }; - CryptoModule.prototype.getCryptor = function (header) { - if (header === '') { - var cryptor = this.getAllCryptors().find(function (c) { return c.identifier === ''; }); - if (cryptor) - return cryptor; - throw new Error('unknown cryptor error'); - } - else if (header instanceof CryptorHeaderV1) { - return this.getCryptorFromId(header.identifier); - } - }; - CryptoModule.prototype.getCryptorFromId = function (id) { - var cryptor = this.getAllCryptors().find(function (c) { return id === c.identifier; }); - if (cryptor) { - return cryptor; - } - throw Error('unknown cryptor error'); - }; - CryptoModule.prototype.concatArrayBuffer = function (ab1, ab2) { - var tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); - tmp.set(new Uint8Array(ab1), 0); - tmp.set(new Uint8Array(ab2), ab1.byteLength); - return tmp.buffer; - }; - CryptoModule.prototype.getHeaderData = function (encrypted) { - if (!encrypted.metadata) - return; - var header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); - var headerData = new Uint8Array(header.length); - var pos = 0; - headerData.set(header.data, pos); - pos += header.length - encrypted.metadata.byteLength; - headerData.set(new Uint8Array(encrypted.metadata), pos); - return headerData.buffer; - }; - CryptoModule.prototype.getFileData = function (input) { - return __awaiter(this, void 0, void 0, function () { - var fileData; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(input instanceof Blob)) return [3 /*break*/, 2]; - return [4 /*yield*/, input.arrayBuffer()]; - case 1: - fileData = _a.sent(); - return [2 /*return*/, fileData]; - case 2: - if (input instanceof ArrayBuffer) { - return [2 /*return*/, input]; - } - if (typeof input === 'string') { - return [2 /*return*/, CryptoModule.encoder.encode(input)]; - } - throw new Error('Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob'); - } - }); - }); - }; - CryptoModule.LEGACY_IDENTIFIER = ''; - CryptoModule.encoder = new TextEncoder(); - CryptoModule.decoder = new TextDecoder(); - return CryptoModule; - }()); - // CryptorHeader Utility - var CryptorHeader = /** @class */ (function () { - function CryptorHeader() { - } - CryptorHeader.from = function (id, metadata) { - if (id === CryptorHeader.LEGACY_IDENTIFIER) - return; - return new CryptorHeaderV1(id, metadata.byteLength); - }; - CryptorHeader.tryParse = function (data) { - var encryptedData = new Uint8Array(data); - var sentinel = ''; - var version = null; - if (encryptedData.byteLength >= 4) { - sentinel = encryptedData.slice(0, 4); - if (this.decoder.decode(sentinel) !== CryptorHeader.SENTINEL) - return ''; - } - if (encryptedData.byteLength >= 5) { - version = encryptedData[4]; - } - else { - throw new Error('decryption error. invalid header version'); - } - if (version > CryptorHeader.MAX_VERSION) - throw new Error('unknown cryptor error'); - var identifier = ''; - var pos = 5 + CryptorHeader.IDENTIFIER_LENGTH; - if (encryptedData.byteLength >= pos) { - identifier = encryptedData.slice(5, pos); - } - else { - throw new Error('decryption error. invalid crypto identifier'); - } - var metadataLength = null; - if (encryptedData.byteLength >= pos + 1) { - metadataLength = encryptedData[pos]; - } - else { - throw new Error('decryption error. invalid metadata length'); - } - pos += 1; - if (metadataLength === 255 && encryptedData.byteLength >= pos + 2) { - metadataLength = new Uint16Array(encryptedData.slice(pos, pos + 2)).reduce(function (acc, val) { return (acc << 8) + val; }, 0); - pos += 2; - } - return new CryptorHeaderV1(this.decoder.decode(identifier), metadataLength); - }; - CryptorHeader.SENTINEL = 'PNED'; - CryptorHeader.LEGACY_IDENTIFIER = ''; - CryptorHeader.IDENTIFIER_LENGTH = 4; - CryptorHeader.VERSION = 1; - CryptorHeader.MAX_VERSION = 1; - CryptorHeader.decoder = new TextDecoder(); - return CryptorHeader; - }()); - // v1 CryptorHeader - var CryptorHeaderV1 = /** @class */ (function () { - function CryptorHeaderV1(id, metadataLength) { - this._identifier = id; - this._metadataLength = metadataLength; - } - Object.defineProperty(CryptorHeaderV1.prototype, "identifier", { - get: function () { - return this._identifier; - }, - set: function (value) { - this._identifier = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "metadataLength", { - get: function () { - return this._metadataLength; - }, - set: function (value) { - this._metadataLength = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "version", { - get: function () { - return CryptorHeader.VERSION; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "length", { - get: function () { - return (CryptorHeader.SENTINEL.length + - 1 + - CryptorHeader.IDENTIFIER_LENGTH + - (this.metadataLength < 255 ? 1 : 3) + - this.metadataLength); - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "data", { - get: function () { - var pos = 0; - var header = new Uint8Array(this.length); - var encoder = new TextEncoder(); - header.set(encoder.encode(CryptorHeader.SENTINEL)); - pos += CryptorHeader.SENTINEL.length; - header[pos] = this.version; - pos++; - if (this.identifier) - header.set(encoder.encode(this.identifier), pos); - pos += CryptorHeader.IDENTIFIER_LENGTH; - var metadataLength = this.metadataLength; - if (metadataLength < 255) { - header[pos] = metadataLength; - } - else { - header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); - } - return header; - }, - enumerable: false, - configurable: true - }); - CryptorHeaderV1.IDENTIFIER_LENGTH = 4; - CryptorHeaderV1.SENTINEL = 'PNED'; - return CryptorHeaderV1; - }()); - - /* eslint no-bitwise: ["error", { "allow": ["~", "&", ">>"] }] */ - function sendBeacon(url) { - if (navigator && navigator.sendBeacon) { - navigator.sendBeacon(url); - } - else { - return false; - } - } - var default_1 = /** @class */ (function (_super) { - __extends(default_1, _super); - function default_1(setup) { - var _this = this; - // extract config. - var _a = setup.listenToBrowserNetworkEvents, listenToBrowserNetworkEvents = _a === void 0 ? true : _a; - setup.sdkFamily = 'Web'; - setup.networking = new default_1$2({ - del: del, - get: get, - post: post, - patch: patch, - sendBeacon: sendBeacon, - getfile: getfile, - postfile: postfile, - }); - setup.cbor = new default_1$1(function (arrayBuffer) { return stringifyBufferKeys(CborReader.decode(arrayBuffer)); }, decode$1); - setup.PubNubFile = PubNubFile; - setup.cryptography = new WebCryptography(); - setup.initCryptoModule = function (cryptoConfiguration) { - return new CryptoModule({ - default: new LegacyCryptor({ - cipherKey: cryptoConfiguration.cipherKey, - useRandomIVs: cryptoConfiguration.useRandomIVs, - }), - cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], - }); - }; - _this = _super.call(this, setup) || this; - if (listenToBrowserNetworkEvents) { - // mount network events. - window.addEventListener('offline', function () { - _this.networkDownDetected(); - }); - window.addEventListener('online', function () { - _this.networkUpDetected(); - }); - } - return _this; - } - default_1.CryptoModule = CryptoModule; - return default_1; - }(default_1$3)); - - return default_1; + typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { + var e = new Error(message); + return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; + }; + + /** + * Crypto module. + */ + class AbstractCryptoModule { + // -------------------------------------------------------- + // --------------- Convenience functions ------------------ + // -------------------------------------------------------- + // region Convenience functions + /** + * Construct crypto module with legacy cryptor for encryption and both legacy and AES-CBC + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using legacy cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ + static legacyCryptoModule(config) { + throw new Error('Should be implemented by concrete crypto module implementation.'); + } + /** + * Construct crypto module with AES-CBC cryptor for encryption and both AES-CBC and legacy + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using AES-CBC cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ + static aesCbcCryptoModule(config) { + throw new Error('Should be implemented by concrete crypto module implementation.'); + } + // endregion + constructor(configuration) { + var _a; + this.defaultCryptor = configuration.default; + this.cryptors = (_a = configuration.cryptors) !== null && _a !== void 0 ? _a : []; + } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + /** + * Retrieve list of module's cryptors. + */ + getAllCryptors() { + return [this.defaultCryptor, ...this.cryptors]; + } + } + /** + * `String` to {@link ArrayBuffer} response decoder. + */ + AbstractCryptoModule.encoder = new TextEncoder(); + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + AbstractCryptoModule.decoder = new TextDecoder(); + + /* global File, FileReader */ + /** + * Browser {@link PubNub} File object module. + */ + // endregion + /** + * Web implementation for {@link PubNub} File object. + * + * **Important:** Class should implement constructor and class fields from {@link PubNubFileConstructor}. + */ + class PubNubFile { + // endregion + static create(file) { + return new PubNubFile(file); + } + constructor(file) { + let contentLength; + let fileMimeType; + let fileName; + let fileData; + if (file instanceof File) { + fileData = file; + fileName = file.name; + fileMimeType = file.type; + contentLength = file.size; + } + else if ('data' in file) { + const contents = file.data; + fileMimeType = file.mimeType; + fileName = file.name; + fileData = new File([contents], fileName, { type: fileMimeType }); + contentLength = fileData.size; + } + if (fileData === undefined) + throw new Error("Couldn't construct a file out of supplied options."); + if (fileName === undefined) + throw new Error("Couldn't guess filename out of the options. Please provide one."); + if (contentLength) + this.contentLength = contentLength; + this.mimeType = fileMimeType; + this.data = fileData; + this.name = fileName; + } + /** + * Convert {@link PubNub} File object content to {@link Buffer}. + * + * @throws Error because {@link Buffer} not available in browser environment. + */ + toBuffer() { + return __awaiter(this, void 0, void 0, function* () { + throw new Error('This feature is only supported in Node.js environments.'); + }); + } + /** + * Convert {@link PubNub} File object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + */ + toArrayBuffer() { + return __awaiter(this, void 0, void 0, function* () { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.addEventListener('load', () => { + if (reader.result instanceof ArrayBuffer) + return resolve(reader.result); + }); + reader.addEventListener('error', () => reject(reader.error)); + reader.readAsArrayBuffer(this.data); + }); + }); + } + /** + * Convert {@link PubNub} File object content to {@link string}. + * + * @returns Asynchronous results of conversion to the {@link string}. + */ + toString() { + return __awaiter(this, void 0, void 0, function* () { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.addEventListener('load', () => { + if (typeof reader.result === 'string') { + return resolve(reader.result); + } + }); + reader.addEventListener('error', () => { + reject(reader.error); + }); + reader.readAsBinaryString(this.data); + }); + }); + } + /** + * Convert {@link PubNub} File object content to {@link Readable} stream. + * + * @throws Error because {@link Readable} stream not available in browser environment. + */ + toStream() { + return __awaiter(this, void 0, void 0, function* () { + throw new Error('This feature is only supported in Node.js environments.'); + }); + } + /** + * Convert {@link PubNub} File object content to {@link File}. + * + * @returns Asynchronous results of conversion to the {@link File}. + */ + toFile() { + return __awaiter(this, void 0, void 0, function* () { + return this.data; + }); + } + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @throws Error because file `Uri` not available in browser environment. + */ + toFileUri() { + return __awaiter(this, void 0, void 0, function* () { + throw new Error('This feature is only supported in React Native environments.'); + }); + } + /** + * Convert {@link PubNub} File object content to {@link Blob}. + * + * @returns Asynchronous results of conversion to the {@link Blob}. + */ + toBlob() { + return __awaiter(this, void 0, void 0, function* () { + return this.data; + }); + } + } + // region Class properties + /** + * Whether {@link Blob} data supported by platform or not. + */ + PubNubFile.supportsBlob = typeof Blob !== 'undefined'; + /** + * Whether {@link File} data supported by platform or not. + */ + PubNubFile.supportsFile = typeof File !== 'undefined'; + /** + * Whether {@link Buffer} data supported by platform or not. + */ + PubNubFile.supportsBuffer = false; + /** + * Whether {@link Stream} data supported by platform or not. + */ + PubNubFile.supportsStream = false; + /** + * Whether {@link String} data supported by platform or not. + */ + PubNubFile.supportsString = true; + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + PubNubFile.supportsArrayBuffer = true; + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + PubNubFile.supportsEncryptFile = true; + /** + * Whether `File Uri` data supported by platform or not. + */ + PubNubFile.supportsFileUri = false; + + const BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + /** + * Decode a Base64 encoded string. + * + * @param paddedInput Base64 string with padding + * @returns ArrayBuffer with decoded data + */ + function decode(paddedInput) { + // Remove up to last two equal signs. + const input = paddedInput.replace(/==?$/, ''); + const outputLength = Math.floor((input.length / 4) * 3); + // Prepare output buffer. + const data = new ArrayBuffer(outputLength); + const view = new Uint8Array(data); + let cursor = 0; + /** + * Returns the next integer representation of a sixtet of bytes from the input + * @returns sixtet of bytes + */ + function nextSixtet() { + const char = input.charAt(cursor++); + const index = BASE64_CHARMAP.indexOf(char); + if (index === -1) { + throw new Error(`Illegal character at ${cursor}: ${input.charAt(cursor - 1)}`); + } + return index; + } + for (let i = 0; i < outputLength; i += 3) { + // Obtain four sixtets + const sx1 = nextSixtet(); + const sx2 = nextSixtet(); + const sx3 = nextSixtet(); + const sx4 = nextSixtet(); + // Encode them as three octets + const oc1 = ((sx1 & 0b00111111) << 2) | (sx2 >> 4); + const oc2 = ((sx2 & 0b00001111) << 4) | (sx3 >> 2); + const oc3 = ((sx3 & 0b00000011) << 6) | (sx4 >> 0); + view[i] = oc1; + // Skip padding bytes. + if (sx3 != 64) + view[i + 1] = oc2; + if (sx4 != 64) + view[i + 2] = oc3; + } + return data; + } + function encode(input) { + let base64 = ''; + const encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + const bytes = new Uint8Array(input); + const byteLength = bytes.byteLength; + const byteRemainder = byteLength % 3; + const mainLength = byteLength - byteRemainder; + let a, b, c, d; + let chunk; + // Main loop deals with bytes in chunks of 3 + for (let i = 0; i < mainLength; i = i + 3) { + // Combine the three bytes into a single integer + chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; + // Use bitmasks to extract 6-bit segments from the triplet + a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18 + b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12 + c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6 + d = chunk & 63; // 63 = 2^6 - 1 + // Convert the raw binary segments to the appropriate ASCII encoding + base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]; + } + // Deal with the remaining bytes and padding + if (byteRemainder == 1) { + chunk = bytes[mainLength]; + a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2 + // Set the 4 least significant bits to zero + b = (chunk & 3) << 4; // 3 = 2^2 - 1 + base64 += encodings[a] + encodings[b] + '=='; + } + else if (byteRemainder == 2) { + chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]; + a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10 + b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4 + // Set the 2 least significant bits to zero + c = (chunk & 15) << 2; // 15 = 2^4 - 1 + base64 += encodings[a] + encodings[b] + encodings[c] + '='; + } + return base64; + } + + /*eslint-disable */ + + /* + CryptoJS v3.1.2 + code.google.com/p/crypto-js + (c) 2009-2013 by Jeff Mott. All rights reserved. + code.google.com/p/crypto-js/wiki/License + */ + var CryptoJS = + CryptoJS || + (function (h, s) { + var f = {}, + g = (f.lib = {}), + q = function () {}, + m = (g.Base = { + extend: function (a) { + q.prototype = this; + var c = new q(); + a && c.mixIn(a); + c.hasOwnProperty('init') || + (c.init = function () { + c.$super.init.apply(this, arguments); + }); + c.init.prototype = c; + c.$super = this; + return c; + }, + create: function () { + var a = this.extend(); + a.init.apply(a, arguments); + return a; + }, + init: function () {}, + mixIn: function (a) { + for (var c in a) a.hasOwnProperty(c) && (this[c] = a[c]); + a.hasOwnProperty('toString') && (this.toString = a.toString); + }, + clone: function () { + return this.init.prototype.extend(this); + }, + }), + r = (g.WordArray = m.extend({ + init: function (a, c) { + a = this.words = a || []; + this.sigBytes = c != s ? c : 4 * a.length; + }, + toString: function (a) { + return (a || k).stringify(this); + }, + concat: function (a) { + var c = this.words, + d = a.words, + b = this.sigBytes; + a = a.sigBytes; + this.clamp(); + if (b % 4) + for (var e = 0; e < a; e++) + c[(b + e) >>> 2] |= ((d[e >>> 2] >>> (24 - 8 * (e % 4))) & 255) << (24 - 8 * ((b + e) % 4)); + else if (65535 < d.length) for (e = 0; e < a; e += 4) c[(b + e) >>> 2] = d[e >>> 2]; + else c.push.apply(c, d); + this.sigBytes += a; + return this; + }, + clamp: function () { + var a = this.words, + c = this.sigBytes; + a[c >>> 2] &= 4294967295 << (32 - 8 * (c % 4)); + a.length = h.ceil(c / 4); + }, + clone: function () { + var a = m.clone.call(this); + a.words = this.words.slice(0); + return a; + }, + random: function (a) { + for (var c = [], d = 0; d < a; d += 4) c.push((4294967296 * h.random()) | 0); + return new r.init(c, a); + }, + })), + l = (f.enc = {}), + k = (l.Hex = { + stringify: function (a) { + var c = a.words; + a = a.sigBytes; + for (var d = [], b = 0; b < a; b++) { + var e = (c[b >>> 2] >>> (24 - 8 * (b % 4))) & 255; + d.push((e >>> 4).toString(16)); + d.push((e & 15).toString(16)); + } + return d.join(''); + }, + parse: function (a) { + for (var c = a.length, d = [], b = 0; b < c; b += 2) + d[b >>> 3] |= parseInt(a.substr(b, 2), 16) << (24 - 4 * (b % 8)); + return new r.init(d, c / 2); + }, + }), + n = (l.Latin1 = { + stringify: function (a) { + var c = a.words; + a = a.sigBytes; + for (var d = [], b = 0; b < a; b++) d.push(String.fromCharCode((c[b >>> 2] >>> (24 - 8 * (b % 4))) & 255)); + return d.join(''); + }, + parse: function (a) { + for (var c = a.length, d = [], b = 0; b < c; b++) d[b >>> 2] |= (a.charCodeAt(b) & 255) << (24 - 8 * (b % 4)); + return new r.init(d, c); + }, + }), + j = (l.Utf8 = { + stringify: function (a) { + try { + return decodeURIComponent(escape(n.stringify(a))); + } catch (c) { + throw Error('Malformed UTF-8 data'); + } + }, + parse: function (a) { + return n.parse(unescape(encodeURIComponent(a))); + }, + }), + u = (g.BufferedBlockAlgorithm = m.extend({ + reset: function () { + this._data = new r.init(); + this._nDataBytes = 0; + }, + _append: function (a) { + 'string' == typeof a && (a = j.parse(a)); + this._data.concat(a); + this._nDataBytes += a.sigBytes; + }, + _process: function (a) { + var c = this._data, + d = c.words, + b = c.sigBytes, + e = this.blockSize, + f = b / (4 * e), + f = a ? h.ceil(f) : h.max((f | 0) - this._minBufferSize, 0); + a = f * e; + b = h.min(4 * a, b); + if (a) { + for (var g = 0; g < a; g += e) this._doProcessBlock(d, g); + g = d.splice(0, a); + c.sigBytes -= b; + } + return new r.init(g, b); + }, + clone: function () { + var a = m.clone.call(this); + a._data = this._data.clone(); + return a; + }, + _minBufferSize: 0, + })); + g.Hasher = u.extend({ + cfg: m.extend(), + init: function (a) { + this.cfg = this.cfg.extend(a); + this.reset(); + }, + reset: function () { + u.reset.call(this); + this._doReset(); + }, + update: function (a) { + this._append(a); + this._process(); + return this; + }, + finalize: function (a) { + a && this._append(a); + return this._doFinalize(); + }, + blockSize: 16, + _createHelper: function (a) { + return function (c, d) { + return new a.init(d).finalize(c); + }; + }, + _createHmacHelper: function (a) { + return function (c, d) { + return new t.HMAC.init(a, d).finalize(c); + }; + }, + }); + var t = (f.algo = {}); + return f; + })(Math); + + // SHA256 + (function (h) { + for ( + var s = CryptoJS, + f = s.lib, + g = f.WordArray, + q = f.Hasher, + f = s.algo, + m = [], + r = [], + l = function (a) { + return (4294967296 * (a - (a | 0))) | 0; + }, + k = 2, + n = 0; + 64 > n; + + ) { + var j; + a: { + j = k; + for (var u = h.sqrt(j), t = 2; t <= u; t++) + if (!(j % t)) { + j = !1; + break a; + } + j = !0; + } + j && (8 > n && (m[n] = l(h.pow(k, 0.5))), (r[n] = l(h.pow(k, 1 / 3))), n++); + k++; + } + var a = [], + f = (f.SHA256 = q.extend({ + _doReset: function () { + this._hash = new g.init(m.slice(0)); + }, + _doProcessBlock: function (c, d) { + for ( + var b = this._hash.words, + e = b[0], + f = b[1], + g = b[2], + j = b[3], + h = b[4], + m = b[5], + n = b[6], + q = b[7], + p = 0; + 64 > p; + p++ + ) { + if (16 > p) a[p] = c[d + p] | 0; + else { + var k = a[p - 15], + l = a[p - 2]; + a[p] = + (((k << 25) | (k >>> 7)) ^ ((k << 14) | (k >>> 18)) ^ (k >>> 3)) + + a[p - 7] + + (((l << 15) | (l >>> 17)) ^ ((l << 13) | (l >>> 19)) ^ (l >>> 10)) + + a[p - 16]; + } + k = + q + + (((h << 26) | (h >>> 6)) ^ ((h << 21) | (h >>> 11)) ^ ((h << 7) | (h >>> 25))) + + ((h & m) ^ (~h & n)) + + r[p] + + a[p]; + l = + (((e << 30) | (e >>> 2)) ^ ((e << 19) | (e >>> 13)) ^ ((e << 10) | (e >>> 22))) + + ((e & f) ^ (e & g) ^ (f & g)); + q = n; + n = m; + m = h; + h = (j + k) | 0; + j = g; + g = f; + f = e; + e = (k + l) | 0; + } + b[0] = (b[0] + e) | 0; + b[1] = (b[1] + f) | 0; + b[2] = (b[2] + g) | 0; + b[3] = (b[3] + j) | 0; + b[4] = (b[4] + h) | 0; + b[5] = (b[5] + m) | 0; + b[6] = (b[6] + n) | 0; + b[7] = (b[7] + q) | 0; + }, + _doFinalize: function () { + var a = this._data, + d = a.words, + b = 8 * this._nDataBytes, + e = 8 * a.sigBytes; + d[e >>> 5] |= 128 << (24 - (e % 32)); + d[(((e + 64) >>> 9) << 4) + 14] = h.floor(b / 4294967296); + d[(((e + 64) >>> 9) << 4) + 15] = b; + a.sigBytes = 4 * d.length; + this._process(); + return this._hash; + }, + clone: function () { + var a = q.clone.call(this); + a._hash = this._hash.clone(); + return a; + }, + })); + s.SHA256 = q._createHelper(f); + s.HmacSHA256 = q._createHmacHelper(f); + })(Math); + + // HMAC SHA256 + (function () { + var h = CryptoJS, + s = h.enc.Utf8; + h.algo.HMAC = h.lib.Base.extend({ + init: function (f, g) { + f = this._hasher = new f.init(); + 'string' == typeof g && (g = s.parse(g)); + var h = f.blockSize, + m = 4 * h; + g.sigBytes > m && (g = f.finalize(g)); + g.clamp(); + for (var r = (this._oKey = g.clone()), l = (this._iKey = g.clone()), k = r.words, n = l.words, j = 0; j < h; j++) + (k[j] ^= 1549556828), (n[j] ^= 909522486); + r.sigBytes = l.sigBytes = m; + this.reset(); + }, + reset: function () { + var f = this._hasher; + f.reset(); + f.update(this._iKey); + }, + update: function (f) { + this._hasher.update(f); + return this; + }, + finalize: function (f) { + var g = this._hasher; + f = g.finalize(f); + g.reset(); + return g.finalize(this._oKey.clone().concat(f)); + }, + }); + })(); + + // Base64 + (function () { + var u = CryptoJS, + p = u.lib.WordArray; + u.enc.Base64 = { + stringify: function (d) { + var l = d.words, + p = d.sigBytes, + t = this._map; + d.clamp(); + d = []; + for (var r = 0; r < p; r += 3) + for ( + var w = + (((l[r >>> 2] >>> (24 - 8 * (r % 4))) & 255) << 16) | + (((l[(r + 1) >>> 2] >>> (24 - 8 * ((r + 1) % 4))) & 255) << 8) | + ((l[(r + 2) >>> 2] >>> (24 - 8 * ((r + 2) % 4))) & 255), + v = 0; + 4 > v && r + 0.75 * v < p; + v++ + ) + d.push(t.charAt((w >>> (6 * (3 - v))) & 63)); + if ((l = t.charAt(64))) for (; d.length % 4; ) d.push(l); + return d.join(''); + }, + parse: function (d) { + var l = d.length, + s = this._map, + t = s.charAt(64); + t && ((t = d.indexOf(t)), -1 != t && (l = t)); + for (var t = [], r = 0, w = 0; w < l; w++) + if (w % 4) { + var v = s.indexOf(d.charAt(w - 1)) << (2 * (w % 4)), + b = s.indexOf(d.charAt(w)) >>> (6 - 2 * (w % 4)); + t[r >>> 2] |= (v | b) << (24 - 8 * (r % 4)); + r++; + } + return p.create(t, r); + }, + _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', + }; + })(); + + // BlockCipher + (function (u) { + function p(b, n, a, c, e, j, k) { + b = b + ((n & a) | (~n & c)) + e + k; + return ((b << j) | (b >>> (32 - j))) + n; + } + function d(b, n, a, c, e, j, k) { + b = b + ((n & c) | (a & ~c)) + e + k; + return ((b << j) | (b >>> (32 - j))) + n; + } + function l(b, n, a, c, e, j, k) { + b = b + (n ^ a ^ c) + e + k; + return ((b << j) | (b >>> (32 - j))) + n; + } + function s(b, n, a, c, e, j, k) { + b = b + (a ^ (n | ~c)) + e + k; + return ((b << j) | (b >>> (32 - j))) + n; + } + for (var t = CryptoJS, r = t.lib, w = r.WordArray, v = r.Hasher, r = t.algo, b = [], x = 0; 64 > x; x++) + b[x] = (4294967296 * u.abs(u.sin(x + 1))) | 0; + r = r.MD5 = v.extend({ + _doReset: function () { + this._hash = new w.init([1732584193, 4023233417, 2562383102, 271733878]); + }, + _doProcessBlock: function (q, n) { + for (var a = 0; 16 > a; a++) { + var c = n + a, + e = q[c]; + q[c] = (((e << 8) | (e >>> 24)) & 16711935) | (((e << 24) | (e >>> 8)) & 4278255360); + } + var a = this._hash.words, + c = q[n + 0], + e = q[n + 1], + j = q[n + 2], + k = q[n + 3], + z = q[n + 4], + r = q[n + 5], + t = q[n + 6], + w = q[n + 7], + v = q[n + 8], + A = q[n + 9], + B = q[n + 10], + C = q[n + 11], + u = q[n + 12], + D = q[n + 13], + E = q[n + 14], + x = q[n + 15], + f = a[0], + m = a[1], + g = a[2], + h = a[3], + f = p(f, m, g, h, c, 7, b[0]), + h = p(h, f, m, g, e, 12, b[1]), + g = p(g, h, f, m, j, 17, b[2]), + m = p(m, g, h, f, k, 22, b[3]), + f = p(f, m, g, h, z, 7, b[4]), + h = p(h, f, m, g, r, 12, b[5]), + g = p(g, h, f, m, t, 17, b[6]), + m = p(m, g, h, f, w, 22, b[7]), + f = p(f, m, g, h, v, 7, b[8]), + h = p(h, f, m, g, A, 12, b[9]), + g = p(g, h, f, m, B, 17, b[10]), + m = p(m, g, h, f, C, 22, b[11]), + f = p(f, m, g, h, u, 7, b[12]), + h = p(h, f, m, g, D, 12, b[13]), + g = p(g, h, f, m, E, 17, b[14]), + m = p(m, g, h, f, x, 22, b[15]), + f = d(f, m, g, h, e, 5, b[16]), + h = d(h, f, m, g, t, 9, b[17]), + g = d(g, h, f, m, C, 14, b[18]), + m = d(m, g, h, f, c, 20, b[19]), + f = d(f, m, g, h, r, 5, b[20]), + h = d(h, f, m, g, B, 9, b[21]), + g = d(g, h, f, m, x, 14, b[22]), + m = d(m, g, h, f, z, 20, b[23]), + f = d(f, m, g, h, A, 5, b[24]), + h = d(h, f, m, g, E, 9, b[25]), + g = d(g, h, f, m, k, 14, b[26]), + m = d(m, g, h, f, v, 20, b[27]), + f = d(f, m, g, h, D, 5, b[28]), + h = d(h, f, m, g, j, 9, b[29]), + g = d(g, h, f, m, w, 14, b[30]), + m = d(m, g, h, f, u, 20, b[31]), + f = l(f, m, g, h, r, 4, b[32]), + h = l(h, f, m, g, v, 11, b[33]), + g = l(g, h, f, m, C, 16, b[34]), + m = l(m, g, h, f, E, 23, b[35]), + f = l(f, m, g, h, e, 4, b[36]), + h = l(h, f, m, g, z, 11, b[37]), + g = l(g, h, f, m, w, 16, b[38]), + m = l(m, g, h, f, B, 23, b[39]), + f = l(f, m, g, h, D, 4, b[40]), + h = l(h, f, m, g, c, 11, b[41]), + g = l(g, h, f, m, k, 16, b[42]), + m = l(m, g, h, f, t, 23, b[43]), + f = l(f, m, g, h, A, 4, b[44]), + h = l(h, f, m, g, u, 11, b[45]), + g = l(g, h, f, m, x, 16, b[46]), + m = l(m, g, h, f, j, 23, b[47]), + f = s(f, m, g, h, c, 6, b[48]), + h = s(h, f, m, g, w, 10, b[49]), + g = s(g, h, f, m, E, 15, b[50]), + m = s(m, g, h, f, r, 21, b[51]), + f = s(f, m, g, h, u, 6, b[52]), + h = s(h, f, m, g, k, 10, b[53]), + g = s(g, h, f, m, B, 15, b[54]), + m = s(m, g, h, f, e, 21, b[55]), + f = s(f, m, g, h, v, 6, b[56]), + h = s(h, f, m, g, x, 10, b[57]), + g = s(g, h, f, m, t, 15, b[58]), + m = s(m, g, h, f, D, 21, b[59]), + f = s(f, m, g, h, z, 6, b[60]), + h = s(h, f, m, g, C, 10, b[61]), + g = s(g, h, f, m, j, 15, b[62]), + m = s(m, g, h, f, A, 21, b[63]); + a[0] = (a[0] + f) | 0; + a[1] = (a[1] + m) | 0; + a[2] = (a[2] + g) | 0; + a[3] = (a[3] + h) | 0; + }, + _doFinalize: function () { + var b = this._data, + n = b.words, + a = 8 * this._nDataBytes, + c = 8 * b.sigBytes; + n[c >>> 5] |= 128 << (24 - (c % 32)); + var e = u.floor(a / 4294967296); + n[(((c + 64) >>> 9) << 4) + 15] = (((e << 8) | (e >>> 24)) & 16711935) | (((e << 24) | (e >>> 8)) & 4278255360); + n[(((c + 64) >>> 9) << 4) + 14] = (((a << 8) | (a >>> 24)) & 16711935) | (((a << 24) | (a >>> 8)) & 4278255360); + b.sigBytes = 4 * (n.length + 1); + this._process(); + b = this._hash; + n = b.words; + for (a = 0; 4 > a; a++) + (c = n[a]), (n[a] = (((c << 8) | (c >>> 24)) & 16711935) | (((c << 24) | (c >>> 8)) & 4278255360)); + return b; + }, + clone: function () { + var b = v.clone.call(this); + b._hash = this._hash.clone(); + return b; + }, + }); + t.MD5 = v._createHelper(r); + t.HmacMD5 = v._createHmacHelper(r); + })(Math); + (function () { + var u = CryptoJS, + p = u.lib, + d = p.Base, + l = p.WordArray, + p = u.algo, + s = (p.EvpKDF = d.extend({ + cfg: d.extend({ keySize: 4, hasher: p.MD5, iterations: 1 }), + init: function (d) { + this.cfg = this.cfg.extend(d); + }, + compute: function (d, r) { + for ( + var p = this.cfg, s = p.hasher.create(), b = l.create(), u = b.words, q = p.keySize, p = p.iterations; + u.length < q; + + ) { + n && s.update(n); + var n = s.update(d).finalize(r); + s.reset(); + for (var a = 1; a < p; a++) (n = s.finalize(n)), s.reset(); + b.concat(n); + } + b.sigBytes = 4 * q; + return b; + }, + })); + u.EvpKDF = function (d, l, p) { + return s.create(p).compute(d, l); + }; + })(); + + // Cipher + CryptoJS.lib.Cipher || + (function (u) { + var p = CryptoJS, + d = p.lib, + l = d.Base, + s = d.WordArray, + t = d.BufferedBlockAlgorithm, + r = p.enc.Base64, + w = p.algo.EvpKDF, + v = (d.Cipher = t.extend({ + cfg: l.extend(), + createEncryptor: function (e, a) { + return this.create(this._ENC_XFORM_MODE, e, a); + }, + createDecryptor: function (e, a) { + return this.create(this._DEC_XFORM_MODE, e, a); + }, + init: function (e, a, b) { + this.cfg = this.cfg.extend(b); + this._xformMode = e; + this._key = a; + this.reset(); + }, + reset: function () { + t.reset.call(this); + this._doReset(); + }, + process: function (e) { + this._append(e); + return this._process(); + }, + finalize: function (e) { + e && this._append(e); + return this._doFinalize(); + }, + keySize: 4, + ivSize: 4, + _ENC_XFORM_MODE: 1, + _DEC_XFORM_MODE: 2, + _createHelper: function (e) { + return { + encrypt: function (b, k, d) { + return ('string' == typeof k ? c : a).encrypt(e, b, k, d); + }, + decrypt: function (b, k, d) { + return ('string' == typeof k ? c : a).decrypt(e, b, k, d); + }, + }; + }, + })); + d.StreamCipher = v.extend({ + _doFinalize: function () { + return this._process(!0); + }, + blockSize: 1, + }); + var b = (p.mode = {}), + x = function (e, a, b) { + var c = this._iv; + c ? (this._iv = u) : (c = this._prevBlock); + for (var d = 0; d < b; d++) e[a + d] ^= c[d]; + }, + q = (d.BlockCipherMode = l.extend({ + createEncryptor: function (e, a) { + return this.Encryptor.create(e, a); + }, + createDecryptor: function (e, a) { + return this.Decryptor.create(e, a); + }, + init: function (e, a) { + this._cipher = e; + this._iv = a; + }, + })).extend(); + q.Encryptor = q.extend({ + processBlock: function (e, a) { + var b = this._cipher, + c = b.blockSize; + x.call(this, e, a, c); + b.encryptBlock(e, a); + this._prevBlock = e.slice(a, a + c); + }, + }); + q.Decryptor = q.extend({ + processBlock: function (e, a) { + var b = this._cipher, + c = b.blockSize, + d = e.slice(a, a + c); + b.decryptBlock(e, a); + x.call(this, e, a, c); + this._prevBlock = d; + }, + }); + b = b.CBC = q; + q = (p.pad = {}).Pkcs7 = { + pad: function (a, b) { + for ( + var c = 4 * b, c = c - (a.sigBytes % c), d = (c << 24) | (c << 16) | (c << 8) | c, l = [], n = 0; + n < c; + n += 4 + ) + l.push(d); + c = s.create(l, c); + a.concat(c); + }, + unpad: function (a) { + a.sigBytes -= a.words[(a.sigBytes - 1) >>> 2] & 255; + }, + }; + d.BlockCipher = v.extend({ + cfg: v.cfg.extend({ mode: b, padding: q }), + reset: function () { + v.reset.call(this); + var a = this.cfg, + b = a.iv, + a = a.mode; + if (this._xformMode == this._ENC_XFORM_MODE) var c = a.createEncryptor; + else (c = a.createDecryptor), (this._minBufferSize = 1); + this._mode = c.call(a, this, b && b.words); + }, + _doProcessBlock: function (a, b) { + this._mode.processBlock(a, b); + }, + _doFinalize: function () { + var a = this.cfg.padding; + if (this._xformMode == this._ENC_XFORM_MODE) { + a.pad(this._data, this.blockSize); + var b = this._process(!0); + } else (b = this._process(!0)), a.unpad(b); + return b; + }, + blockSize: 4, + }); + var n = (d.CipherParams = l.extend({ + init: function (a) { + this.mixIn(a); + }, + toString: function (a) { + return (a || this.formatter).stringify(this); + }, + })), + b = ((p.format = {}).OpenSSL = { + stringify: function (a) { + var b = a.ciphertext; + a = a.salt; + return (a ? s.create([1398893684, 1701076831]).concat(a).concat(b) : b).toString(r); + }, + parse: function (a) { + a = r.parse(a); + var b = a.words; + if (1398893684 == b[0] && 1701076831 == b[1]) { + var c = s.create(b.slice(2, 4)); + b.splice(0, 4); + a.sigBytes -= 16; + } + return n.create({ ciphertext: a, salt: c }); + }, + }), + a = (d.SerializableCipher = l.extend({ + cfg: l.extend({ format: b }), + encrypt: function (a, b, c, d) { + d = this.cfg.extend(d); + var l = a.createEncryptor(c, d); + b = l.finalize(b); + l = l.cfg; + return n.create({ + ciphertext: b, + key: c, + iv: l.iv, + algorithm: a, + mode: l.mode, + padding: l.padding, + blockSize: a.blockSize, + formatter: d.format, + }); + }, + decrypt: function (a, b, c, d) { + d = this.cfg.extend(d); + b = this._parse(b, d.format); + return a.createDecryptor(c, d).finalize(b.ciphertext); + }, + _parse: function (a, b) { + return 'string' == typeof a ? b.parse(a, this) : a; + }, + })), + p = ((p.kdf = {}).OpenSSL = { + execute: function (a, b, c, d) { + d || (d = s.random(8)); + a = w.create({ keySize: b + c }).compute(a, d); + c = s.create(a.words.slice(b), 4 * c); + a.sigBytes = 4 * b; + return n.create({ key: a, iv: c, salt: d }); + }, + }), + c = (d.PasswordBasedCipher = a.extend({ + cfg: a.cfg.extend({ kdf: p }), + encrypt: function (b, c, d, l) { + l = this.cfg.extend(l); + d = l.kdf.execute(d, b.keySize, b.ivSize); + l.iv = d.iv; + b = a.encrypt.call(this, b, c, d.key, l); + b.mixIn(d); + return b; + }, + decrypt: function (b, c, d, l) { + l = this.cfg.extend(l); + c = this._parse(c, l.format); + d = l.kdf.execute(d, b.keySize, b.ivSize, c.salt); + l.iv = d.iv; + return a.decrypt.call(this, b, c, d.key, l); + }, + })); + })(); + + // AES + (function () { + for ( + var u = CryptoJS, + p = u.lib.BlockCipher, + d = u.algo, + l = [], + s = [], + t = [], + r = [], + w = [], + v = [], + b = [], + x = [], + q = [], + n = [], + a = [], + c = 0; + 256 > c; + c++ + ) + a[c] = 128 > c ? c << 1 : (c << 1) ^ 283; + for (var e = 0, j = 0, c = 0; 256 > c; c++) { + var k = j ^ (j << 1) ^ (j << 2) ^ (j << 3) ^ (j << 4), + k = (k >>> 8) ^ (k & 255) ^ 99; + l[e] = k; + s[k] = e; + var z = a[e], + F = a[z], + G = a[F], + y = (257 * a[k]) ^ (16843008 * k); + t[e] = (y << 24) | (y >>> 8); + r[e] = (y << 16) | (y >>> 16); + w[e] = (y << 8) | (y >>> 24); + v[e] = y; + y = (16843009 * G) ^ (65537 * F) ^ (257 * z) ^ (16843008 * e); + b[k] = (y << 24) | (y >>> 8); + x[k] = (y << 16) | (y >>> 16); + q[k] = (y << 8) | (y >>> 24); + n[k] = y; + e ? ((e = z ^ a[a[a[G ^ z]]]), (j ^= a[a[j]])) : (e = j = 1); + } + var H = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54], + d = (d.AES = p.extend({ + _doReset: function () { + for ( + var a = this._key, + c = a.words, + d = a.sigBytes / 4, + a = 4 * ((this._nRounds = d + 6) + 1), + e = (this._keySchedule = []), + j = 0; + j < a; + j++ + ) + if (j < d) e[j] = c[j]; + else { + var k = e[j - 1]; + j % d + ? 6 < d && + 4 == j % d && + (k = (l[k >>> 24] << 24) | (l[(k >>> 16) & 255] << 16) | (l[(k >>> 8) & 255] << 8) | l[k & 255]) + : ((k = (k << 8) | (k >>> 24)), + (k = (l[k >>> 24] << 24) | (l[(k >>> 16) & 255] << 16) | (l[(k >>> 8) & 255] << 8) | l[k & 255]), + (k ^= H[(j / d) | 0] << 24)); + e[j] = e[j - d] ^ k; + } + c = this._invKeySchedule = []; + for (d = 0; d < a; d++) + (j = a - d), + (k = d % 4 ? e[j] : e[j - 4]), + (c[d] = + 4 > d || 4 >= j ? k : b[l[k >>> 24]] ^ x[l[(k >>> 16) & 255]] ^ q[l[(k >>> 8) & 255]] ^ n[l[k & 255]]); + }, + encryptBlock: function (a, b) { + this._doCryptBlock(a, b, this._keySchedule, t, r, w, v, l); + }, + decryptBlock: function (a, c) { + var d = a[c + 1]; + a[c + 1] = a[c + 3]; + a[c + 3] = d; + this._doCryptBlock(a, c, this._invKeySchedule, b, x, q, n, s); + d = a[c + 1]; + a[c + 1] = a[c + 3]; + a[c + 3] = d; + }, + _doCryptBlock: function (a, b, c, d, e, j, l, f) { + for ( + var m = this._nRounds, + g = a[b] ^ c[0], + h = a[b + 1] ^ c[1], + k = a[b + 2] ^ c[2], + n = a[b + 3] ^ c[3], + p = 4, + r = 1; + r < m; + r++ + ) + var q = d[g >>> 24] ^ e[(h >>> 16) & 255] ^ j[(k >>> 8) & 255] ^ l[n & 255] ^ c[p++], + s = d[h >>> 24] ^ e[(k >>> 16) & 255] ^ j[(n >>> 8) & 255] ^ l[g & 255] ^ c[p++], + t = d[k >>> 24] ^ e[(n >>> 16) & 255] ^ j[(g >>> 8) & 255] ^ l[h & 255] ^ c[p++], + n = d[n >>> 24] ^ e[(g >>> 16) & 255] ^ j[(h >>> 8) & 255] ^ l[k & 255] ^ c[p++], + g = q, + h = s, + k = t; + q = ((f[g >>> 24] << 24) | (f[(h >>> 16) & 255] << 16) | (f[(k >>> 8) & 255] << 8) | f[n & 255]) ^ c[p++]; + s = ((f[h >>> 24] << 24) | (f[(k >>> 16) & 255] << 16) | (f[(n >>> 8) & 255] << 8) | f[g & 255]) ^ c[p++]; + t = ((f[k >>> 24] << 24) | (f[(n >>> 16) & 255] << 16) | (f[(g >>> 8) & 255] << 8) | f[h & 255]) ^ c[p++]; + n = ((f[n >>> 24] << 24) | (f[(g >>> 16) & 255] << 16) | (f[(h >>> 8) & 255] << 8) | f[k & 255]) ^ c[p++]; + a[b] = q; + a[b + 1] = s; + a[b + 2] = t; + a[b + 3] = n; + }, + keySize: 8, + })); + u.AES = p._createHelper(d); + })(); + + // Mode ECB + CryptoJS.mode.ECB = (function () { + var ECB = CryptoJS.lib.BlockCipherMode.extend(); + + ECB.Encryptor = ECB.extend({ + processBlock: function (words, offset) { + this._cipher.encryptBlock(words, offset); + }, + }); + + ECB.Decryptor = ECB.extend({ + processBlock: function (words, offset) { + this._cipher.decryptBlock(words, offset); + }, + }); + + return ECB; + })(); + + var hmacSha256 = CryptoJS; + + var CryptoJS$1 = /*@__PURE__*/getDefaultExportFromCjs(hmacSha256); + + /** + * AES-CBC cryptor module. + */ + /** + * AES-CBC cryptor. + * + * AES-CBC cryptor with enhanced cipher strength. + */ + class AesCbcCryptor { + constructor({ cipherKey }) { + this.cipherKey = cipherKey; + this.CryptoJS = CryptoJS$1; + this.encryptedKey = this.CryptoJS.SHA256(cipherKey); + } + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption + encrypt(data) { + const stringData = typeof data === 'string' ? data : AesCbcCryptor.decoder.decode(data); + if (stringData.length === 0) + throw new Error('encryption error. empty content'); + const abIv = this.getIv(); + return { + metadata: abIv, + data: decode(this.CryptoJS.AES.encrypt(data, this.encryptedKey, { + iv: this.bufferToWordArray(abIv), + mode: this.CryptoJS.mode.CBC, + }).ciphertext.toString(this.CryptoJS.enc.Base64)), + }; + } + encryptFileData(data) { + return __awaiter(this, void 0, void 0, function* () { + const key = yield this.getKey(); + const iv = this.getIv(); + return { + data: yield crypto.subtle.encrypt({ name: this.algo, iv: iv }, key, data), + metadata: iv, + }; + }); + } + // endregion + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + decrypt(encryptedData) { + if (typeof encryptedData.data === 'string') + throw new Error('Decryption error: data for decryption should be ArrayBuffed.'); + const iv = this.bufferToWordArray(new Uint8ClampedArray(encryptedData.metadata)); + const data = this.bufferToWordArray(new Uint8ClampedArray(encryptedData.data)); + return AesCbcCryptor.encoder.encode(this.CryptoJS.AES.decrypt({ ciphertext: data }, this.encryptedKey, { + iv, + mode: this.CryptoJS.mode.CBC, + }).toString(this.CryptoJS.enc.Utf8)).buffer; + } + decryptFileData(encryptedData) { + return __awaiter(this, void 0, void 0, function* () { + if (typeof encryptedData.data === 'string') + throw new Error('Decryption error: data for decryption should be ArrayBuffed.'); + const key = yield this.getKey(); + return crypto.subtle.decrypt({ name: this.algo, iv: encryptedData.metadata }, key, encryptedData.data); + }); + } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + get identifier() { + return 'ACRH'; + } + /** + * Cryptor algorithm. + * + * @returns Cryptor module algorithm. + */ + get algo() { + return 'AES-CBC'; + } + /** + * Generate random initialization vector. + * + * @returns Random initialization vector. + */ + getIv() { + return crypto.getRandomValues(new Uint8Array(AesCbcCryptor.BLOCK_SIZE)); + } + /** + * Convert cipher key to the {@link Buffer}. + * + * @returns SHA256 encoded cipher key {@link Buffer}. + */ + getKey() { + return __awaiter(this, void 0, void 0, function* () { + const bKey = AesCbcCryptor.encoder.encode(this.cipherKey); + const abHash = yield crypto.subtle.digest('SHA-256', bKey.buffer); + return crypto.subtle.importKey('raw', abHash, this.algo, true, ['encrypt', 'decrypt']); + }); + } + /** + * Convert bytes array to words array. + * + * @param b - Bytes array (buffer) which should be converted. + * + * @returns Word sized array. + */ + bufferToWordArray(b) { + const wa = []; + let i; + for (i = 0; i < b.length; i += 1) { + wa[(i / 4) | 0] |= b[i] << (24 - 8 * i); + } + return this.CryptoJS.lib.WordArray.create(wa, b.length); + } + } + /** + * Cryptor block size. + */ + AesCbcCryptor.BLOCK_SIZE = 16; + /** + * {@link string|String} to {@link ArrayBuffer} response decoder. + */ + AesCbcCryptor.encoder = new TextEncoder(); + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + AesCbcCryptor.decoder = new TextDecoder(); + + /** + * Legacy cryptography module. + */ + /** + * Convert bytes array to words array. + * + * @param b - Bytes array (buffer) which should be converted. + * + * @returns Word sized array. + */ + /* eslint-disable @typescript-eslint/no-explicit-any */ + function bufferToWordArray(b) { + const wa = []; + let i; + for (i = 0; i < b.length; i += 1) { + wa[(i / 4) | 0] |= b[i] << (24 - 8 * i); + } + // @ts-expect-error Bundled library without types. + return CryptoJS$1.lib.WordArray.create(wa, b.length); + } + class Crypto { + constructor(configuration) { + this.configuration = configuration; + /** + * Crypto initialization vector. + */ + this.iv = '0123456789012345'; + /** + * List os allowed cipher key encodings. + */ + this.allowedKeyEncodings = ['hex', 'utf8', 'base64', 'binary']; + /** + * Allowed cipher key lengths. + */ + this.allowedKeyLengths = [128, 256]; + /** + * Allowed crypto modes. + */ + this.allowedModes = ['ecb', 'cbc']; + this.defaultOptions = { + encryptKey: true, + keyEncoding: 'utf8', + keyLength: 256, + mode: 'cbc', + }; + } + /** + * Generate HMAC-SHA256 hash from input data. + * + * @param data - Data from which hash should be generated. + * + * @returns HMAC-SHA256 hash from provided `data`. + */ + HMACSHA256(data) { + // @ts-expect-error Bundled library without types. + const hash = CryptoJS$1.HmacSHA256(data, this.configuration.secretKey); + // @ts-expect-error Bundled library without types. + return hash.toString(CryptoJS$1.enc.Base64); + } + /** + * Generate SHA256 hash from input data. + * + * @param data - Data from which hash should be generated. + * + * @returns SHA256 hash from provided `data`. + */ + SHA256(data) { + // @ts-expect-error Bundled library without types. + return CryptoJS$1.SHA256(data).toString(CryptoJS$1.enc.Hex); + } + /** + * Encrypt provided data. + * + * @param data - Source data which should be encrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Encrypted `data`. + */ + encrypt(data, customCipherKey, options) { + if (this.configuration.customEncrypt) + return this.configuration.customEncrypt(data); + return this.pnEncrypt(data, customCipherKey, options); + } + /** + * Decrypt provided data. + * + * @param data - Encrypted data which should be decrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Decrypted `data`. + */ + decrypt(data, customCipherKey, options) { + if (this.configuration.customDecrypt) + return this.configuration.customDecrypt(data); + return this.pnDecrypt(data, customCipherKey, options); + } + /** + * Encrypt provided data. + * + * @param data - Source data which should be encrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Encrypted `data` as string. + */ + pnEncrypt(data, customCipherKey, options) { + const decidedCipherKey = customCipherKey !== null && customCipherKey !== void 0 ? customCipherKey : this.configuration.cipherKey; + if (!decidedCipherKey) + return data; + options = this.parseOptions(options); + const mode = this.getMode(options); + const cipherKey = this.getPaddedKey(decidedCipherKey, options); + if (this.configuration.useRandomIVs) { + const waIv = this.getRandomIV(); + // @ts-expect-error Bundled library without types. + const waPayload = CryptoJS$1.AES.encrypt(data, cipherKey, { iv: waIv, mode }).ciphertext; + // @ts-expect-error Bundled library without types. + return waIv.clone().concat(waPayload.clone()).toString(CryptoJS$1.enc.Base64); + } + const iv = this.getIV(options); + // @ts-expect-error Bundled library without types. + const encryptedHexArray = CryptoJS$1.AES.encrypt(data, cipherKey, { iv, mode }).ciphertext; + // @ts-expect-error Bundled library without types. + const base64Encrypted = encryptedHexArray.toString(CryptoJS$1.enc.Base64); + return base64Encrypted || data; + } + /** + * Decrypt provided data. + * + * @param data - Encrypted data which should be decrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Decrypted `data`. + */ + pnDecrypt(data, customCipherKey, options) { + const decidedCipherKey = customCipherKey !== null && customCipherKey !== void 0 ? customCipherKey : this.configuration.cipherKey; + if (!decidedCipherKey) + return data; + options = this.parseOptions(options); + const mode = this.getMode(options); + const cipherKey = this.getPaddedKey(decidedCipherKey, options); + if (this.configuration.useRandomIVs) { + const ciphertext = new Uint8ClampedArray(decode(data)); + const iv = bufferToWordArray(ciphertext.slice(0, 16)); + const payload = bufferToWordArray(ciphertext.slice(16)); + try { + // @ts-expect-error Bundled library without types. + const plainJSON = CryptoJS$1.AES.decrypt({ ciphertext: payload }, cipherKey, { iv, mode }).toString( + // @ts-expect-error Bundled library without types. + CryptoJS$1.enc.Utf8); + return JSON.parse(plainJSON); + } + catch (e) { + return null; + } + } + else { + const iv = this.getIV(options); + try { + // @ts-expect-error Bundled library without types. + const ciphertext = CryptoJS$1.enc.Base64.parse(data); + // @ts-expect-error Bundled library without types. + const plainJSON = CryptoJS$1.AES.decrypt({ ciphertext }, cipherKey, { iv, mode }).toString(CryptoJS$1.enc.Utf8); + return JSON.parse(plainJSON); + } + catch (e) { + return null; + } + } + } + /** + * Pre-process provided custom crypto configuration. + * + * @param incomingOptions - Configuration which should be pre-processed before use. + * + * @returns Normalized crypto configuration options. + */ + parseOptions(incomingOptions) { + var _a, _b, _c, _d; + if (!incomingOptions) + return this.defaultOptions; + // Defaults + const options = { + encryptKey: (_a = incomingOptions.encryptKey) !== null && _a !== void 0 ? _a : this.defaultOptions.encryptKey, + keyEncoding: (_b = incomingOptions.keyEncoding) !== null && _b !== void 0 ? _b : this.defaultOptions.keyEncoding, + keyLength: (_c = incomingOptions.keyLength) !== null && _c !== void 0 ? _c : this.defaultOptions.keyLength, + mode: (_d = incomingOptions.mode) !== null && _d !== void 0 ? _d : this.defaultOptions.mode, + }; + // Validation + if (this.allowedKeyEncodings.indexOf(options.keyEncoding.toLowerCase()) === -1) + options.keyEncoding = this.defaultOptions.keyEncoding; + if (this.allowedKeyLengths.indexOf(options.keyLength) === -1) + options.keyLength = this.defaultOptions.keyLength; + if (this.allowedModes.indexOf(options.mode.toLowerCase()) === -1) + options.mode = this.defaultOptions.mode; + return options; + } + /** + * Decode provided cipher key. + * + * @param key - Key in `encoding` provided by `options`. + * @param options - Crypto configuration options with cipher key details. + * + * @returns Array buffer with decoded key. + */ + decodeKey(key, options) { + // @ts-expect-error Bundled library without types. + if (options.keyEncoding === 'base64') + return CryptoJS$1.enc.Base64.parse(key); + // @ts-expect-error Bundled library without types. + if (options.keyEncoding === 'hex') + return CryptoJS$1.enc.Hex.parse(key); + return key; + } + /** + * Add padding to the cipher key. + * + * @param key - Key which should be padded. + * @param options - Crypto configuration options with cipher key details. + * + * @returns Properly padded cipher key. + */ + getPaddedKey(key, options) { + key = this.decodeKey(key, options); + // @ts-expect-error Bundled library without types. + if (options.encryptKey) + return CryptoJS$1.enc.Utf8.parse(this.SHA256(key).slice(0, 32)); + return key; + } + /** + * Cipher mode. + * + * @param options - Crypto configuration with information about cipher mode. + * + * @returns Crypto cipher mode. + */ + getMode(options) { + // @ts-expect-error Bundled library without types. + if (options.mode === 'ecb') + return CryptoJS$1.mode.ECB; + // @ts-expect-error Bundled library without types. + return CryptoJS$1.mode.CBC; + } + /** + * Cipher initialization vector. + * + * @param options - Crypto configuration with information about cipher mode. + * + * @returns Initialization vector. + */ + getIV(options) { + // @ts-expect-error Bundled library without types. + return options.mode === 'cbc' ? CryptoJS$1.enc.Utf8.parse(this.iv) : null; + } + /** + * Random initialization vector. + * + * @returns Generated random initialization vector. + */ + getRandomIV() { + // @ts-expect-error Bundled library without types. + return CryptoJS$1.lib.WordArray.random(16); + } + } + + /* global crypto */ + /** + * Legacy browser cryptography module. + */ + function concatArrayBuffer(ab1, ab2) { + const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); + tmp.set(new Uint8Array(ab1), 0); + tmp.set(new Uint8Array(ab2), ab1.byteLength); + return tmp.buffer; + } + /** + * Legacy cryptography implementation for browser-based {@link PubNub} client. + */ + class WebCryptography { + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption + /** + * Encrypt provided source data using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` data. + * @param input - Source data for encryption. + * + * @returns Encrypted data as object or stream (depending on from source data type). + * + * @throws Error if unknown data type has been passed. + */ + encrypt(key, input) { + return __awaiter(this, void 0, void 0, function* () { + if (!(input instanceof ArrayBuffer) && typeof input !== 'string') + throw new Error('Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer'); + const cKey = yield this.getKey(key); + return input instanceof ArrayBuffer ? this.encryptArrayBuffer(cKey, input) : this.encryptString(cKey, input); + }); + } + /** + * Encrypt provided source {@link Buffer} using specific encryption {@link ArrayBuffer}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link ArrayBuffer}. + * @param buffer - Source {@link ArrayBuffer} for encryption. + * + * @returns Encrypted data as {@link ArrayBuffer} object. + */ + encryptArrayBuffer(key, buffer) { + return __awaiter(this, void 0, void 0, function* () { + const abIv = crypto.getRandomValues(new Uint8Array(16)); + return concatArrayBuffer(abIv.buffer, yield crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, buffer)); + }); + } + /** + * Encrypt provided source {@link string} using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link string}. + * @param text - Source {@link string} for encryption. + * + * @returns Encrypted data as byte {@link string}. + */ + encryptString(key, text) { + return __awaiter(this, void 0, void 0, function* () { + const abIv = crypto.getRandomValues(new Uint8Array(16)); + const abPlaintext = WebCryptography.encoder.encode(text).buffer; + const abPayload = yield crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, abPlaintext); + const ciphertext = concatArrayBuffer(abIv.buffer, abPayload); + return WebCryptography.decoder.decode(ciphertext); + }); + } + /** + * Encrypt provided {@link PubNub} File object using specific encryption {@link key}. + * + * @param key - Key for {@link PubNub} File object encryption.
**Note:** Same key should be + * used to `decrypt` data. + * @param file - Source {@link PubNub} File object for encryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Encrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + encryptFile(key, file, File) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b; + if (((_a = file.contentLength) !== null && _a !== void 0 ? _a : 0) <= 0) + throw new Error('encryption error. empty content'); + const bKey = yield this.getKey(key); + const abPlaindata = yield file.toArrayBuffer(); + const abCipherdata = yield this.encryptArrayBuffer(bKey, abPlaindata); + return File.create({ + name: file.name, + mimeType: (_b = file.mimeType) !== null && _b !== void 0 ? _b : 'application/octet-stream', + data: abCipherdata, + }); + }); + } + // endregion + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + /** + * Decrypt provided encrypted data using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` data. + * @param input - Encrypted data for decryption. + * + * @returns Decrypted data as object or stream (depending on from encrypted data type). + * + * @throws Error if unknown data type has been passed. + */ + decrypt(key, input) { + return __awaiter(this, void 0, void 0, function* () { + if (!(input instanceof ArrayBuffer) && typeof input !== 'string') + throw new Error('Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer'); + const cKey = yield this.getKey(key); + return input instanceof ArrayBuffer ? this.decryptArrayBuffer(cKey, input) : this.decryptString(cKey, input); + }); + } + /** + * Decrypt provided encrypted {@link ArrayBuffer} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link ArrayBuffer}. + * @param buffer - Encrypted {@link ArrayBuffer} for decryption. + * + * @returns Decrypted data as {@link ArrayBuffer} object. + */ + decryptArrayBuffer(key, buffer) { + return __awaiter(this, void 0, void 0, function* () { + const abIv = buffer.slice(0, 16); + if (buffer.slice(WebCryptography.IV_LENGTH).byteLength <= 0) + throw new Error('decryption error: empty content'); + return yield crypto.subtle.decrypt({ name: 'AES-CBC', iv: abIv }, key, buffer.slice(WebCryptography.IV_LENGTH)); + }); + } + /** + * Decrypt provided encrypted {@link string} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link string}. + * @param text - Encrypted {@link string} for decryption. + * + * @returns Decrypted data as byte {@link string}. + */ + decryptString(key, text) { + return __awaiter(this, void 0, void 0, function* () { + const abCiphertext = WebCryptography.encoder.encode(text).buffer; + const abIv = abCiphertext.slice(0, 16); + const abPayload = abCiphertext.slice(16); + const abPlaintext = yield crypto.subtle.decrypt({ name: 'AES-CBC', iv: abIv }, key, abPayload); + return WebCryptography.decoder.decode(abPlaintext); + }); + } + /** + * Decrypt provided {@link PubNub} File object using specific decryption {@link key}. + * + * @param key - Key for {@link PubNub} File object decryption.
**Note:** Should be the same + * as used to `encrypt` data. + * @param file - Encrypted {@link PubNub} File object for decryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + decryptFile(key, file, File) { + return __awaiter(this, void 0, void 0, function* () { + const bKey = yield this.getKey(key); + const abCipherdata = yield file.toArrayBuffer(); + const abPlaindata = yield this.decryptArrayBuffer(bKey, abCipherdata); + return File.create({ + name: file.name, + mimeType: file.mimeType, + data: abPlaindata, + }); + }); + } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + /** + * Convert cipher key to the {@link Buffer}. + * + * @param key - String cipher key. + * + * @returns SHA256 HEX encoded cipher key {@link CryptoKey}. + */ + getKey(key) { + return __awaiter(this, void 0, void 0, function* () { + const digest = yield crypto.subtle.digest('SHA-256', WebCryptography.encoder.encode(key)); + const hashHex = Array.from(new Uint8Array(digest)) + .map((b) => b.toString(16).padStart(2, '0')) + .join(''); + const abKey = WebCryptography.encoder.encode(hashHex.slice(0, 32)).buffer; + return crypto.subtle.importKey('raw', abKey, 'AES-CBC', true, ['encrypt', 'decrypt']); + }); + } + } + /** + * Random initialization vector size. + */ + WebCryptography.IV_LENGTH = 16; + /** + * {@link string|String} to {@link ArrayBuffer} response decoder. + */ + WebCryptography.encoder = new TextEncoder(); + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + WebCryptography.decoder = new TextDecoder(); + + /** + * Legacy cryptor module. + */ + /** + * Legacy cryptor. + */ + class LegacyCryptor { + constructor(config) { + this.config = config; + this.cryptor = new Crypto(Object.assign({}, config)); + this.fileCryptor = new WebCryptography(); + } + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption + encrypt(data) { + const stringData = typeof data === 'string' ? data : LegacyCryptor.decoder.decode(data); + return { + data: this.cryptor.encrypt(stringData), + metadata: null, + }; + } + encryptFile(file, File) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (!this.config.cipherKey) + throw new PubNubError('File encryption error: cipher key not set.'); + return this.fileCryptor.encryptFile((_a = this.config) === null || _a === void 0 ? void 0 : _a.cipherKey, file, File); + }); + } + // endregion + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + decrypt(encryptedData) { + const data = typeof encryptedData.data === 'string' ? encryptedData.data : encode(encryptedData.data); + return this.cryptor.decrypt(data); + } + decryptFile(file, File) { + return __awaiter(this, void 0, void 0, function* () { + if (!this.config.cipherKey) + throw new PubNubError('File encryption error: cipher key not set.'); + return this.fileCryptor.decryptFile(this.config.cipherKey, file, File); + }); + } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + get identifier() { + return ''; + } + } + /** + * `string` to {@link ArrayBuffer} response decoder. + */ + LegacyCryptor.encoder = new TextEncoder(); + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + LegacyCryptor.decoder = new TextDecoder(); + + /** + * Browser crypto module. + */ + /** + * CryptoModule for browser platform. + */ + class WebCryptoModule extends AbstractCryptoModule { + // -------------------------------------------------------- + // --------------- Convenience functions ------------------ + // ------------------------------------------------------- + // region Convenience functions + static legacyCryptoModule(config) { + var _a; + if (!config.cipherKey) + throw new PubNubError('Crypto module error: cipher key not set.'); + return new WebCryptoModule({ + default: new LegacyCryptor(Object.assign(Object.assign({}, config), { useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true })), + cryptors: [new AesCbcCryptor({ cipherKey: config.cipherKey })], + }); + } + static aesCbcCryptoModule(config) { + var _a; + if (!config.cipherKey) + throw new PubNubError('Crypto module error: cipher key not set.'); + return new WebCryptoModule({ + default: new AesCbcCryptor({ cipherKey: config.cipherKey }), + cryptors: [ + new LegacyCryptor(Object.assign(Object.assign({}, config), { useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true })), + ], + }); + } + /** + * Construct crypto module with `cryptor` as default for data encryption and decryption. + * + * @param defaultCryptor - Default cryptor for data encryption and decryption. + * + * @returns Crypto module with pre-configured default cryptor. + */ + static withDefaultCryptor(defaultCryptor) { + return new this({ default: defaultCryptor }); + } + // endregion + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption + encrypt(data) { + // Encrypt data. + const encrypted = data instanceof ArrayBuffer && this.defaultCryptor.identifier === WebCryptoModule.LEGACY_IDENTIFIER + ? this.defaultCryptor.encrypt(WebCryptoModule.decoder.decode(data)) + : this.defaultCryptor.encrypt(data); + if (!encrypted.metadata) + return encrypted.data; + else if (typeof encrypted.data === 'string') + throw new Error('Encryption error: encrypted data should be ArrayBuffed.'); + const headerData = this.getHeaderData(encrypted); + return this.concatArrayBuffer(headerData, encrypted.data); + } + encryptFile(file, File) { + return __awaiter(this, void 0, void 0, function* () { + /** + * Files handled differently in case of Legacy cryptor. + * (as long as we support legacy need to check on instance type) + */ + if (this.defaultCryptor.identifier === CryptorHeader.LEGACY_IDENTIFIER) + return this.defaultCryptor.encryptFile(file, File); + const fileData = yield this.getFileData(file); + const encrypted = yield this.defaultCryptor.encryptFileData(fileData); + if (typeof encrypted.data === 'string') + throw new Error('Encryption error: encrypted data should be ArrayBuffed.'); + return File.create({ + name: file.name, + mimeType: 'application/octet-stream', + data: this.concatArrayBuffer(this.getHeaderData(encrypted), encrypted.data), + }); + }); + } + // endregion + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + decrypt(data) { + const encryptedData = typeof data === 'string' ? decode(data) : data; + const header = CryptorHeader.tryParse(encryptedData); + const cryptor = this.getCryptor(header); + const metadata = header.length > 0 + ? encryptedData.slice(header.length - header.metadataLength, header.length) + : null; + if (encryptedData.slice(header.length).byteLength <= 0) + throw new Error('Decryption error: empty content'); + return cryptor.decrypt({ + data: encryptedData.slice(header.length), + metadata: metadata, + }); + } + decryptFile(file, File) { + return __awaiter(this, void 0, void 0, function* () { + const data = yield file.data.arrayBuffer(); + const header = CryptorHeader.tryParse(data); + const cryptor = this.getCryptor(header); + /** + * Files handled differently in case of Legacy cryptor. + * (as long as we support legacy need to check on instance type) + */ + if ((cryptor === null || cryptor === void 0 ? void 0 : cryptor.identifier) === CryptorHeader.LEGACY_IDENTIFIER) + return cryptor.decryptFile(file, File); + const fileData = yield this.getFileData(data); + const metadata = fileData.slice(header.length - header.metadataLength, header.length); + return File.create({ + name: file.name, + data: yield this.defaultCryptor.decryptFileData({ + data: data.slice(header.length), + metadata: metadata, + }), + }); + }); + } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + /** + * Retrieve registered cryptor by its identifier. + * + * @param id - Unique cryptor identifier. + * + * @returns Registered cryptor with specified identifier. + * + * @throws Error if cryptor with specified {@link id} can't be found. + */ + getCryptorFromId(id) { + const cryptor = this.getAllCryptors().find((cryptor) => id === cryptor.identifier); + if (cryptor) + return cryptor; + throw Error('Unknown cryptor error'); + } + /** + * Retrieve cryptor by its identifier. + * + * @param header - Header with cryptor-defined data or raw cryptor identifier. + * + * @returns Cryptor which correspond to provided {@link header}. + */ + getCryptor(header) { + if (typeof header === 'string') { + const cryptor = this.getAllCryptors().find((cryptor) => cryptor.identifier === header); + if (cryptor) + return cryptor; + throw new Error('Unknown cryptor error'); + } + else if (header instanceof CryptorHeaderV1) { + return this.getCryptorFromId(header.identifier); + } + } + /** + * Create cryptor header data. + * + * @param encrypted - Encryption data object as source for header data. + * + * @returns Binary representation of the cryptor header data. + */ + getHeaderData(encrypted) { + if (!encrypted.metadata) + return; + const header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); + const headerData = new Uint8Array(header.length); + let pos = 0; + headerData.set(header.data, pos); + pos += header.length - encrypted.metadata.byteLength; + headerData.set(new Uint8Array(encrypted.metadata), pos); + return headerData.buffer; + } + /** + * Merge two {@link ArrayBuffer} instances. + * + * @param ab1 - First {@link ArrayBuffer}. + * @param ab2 - Second {@link ArrayBuffer}. + * + * @returns Merged data as {@link ArrayBuffer}. + */ + concatArrayBuffer(ab1, ab2) { + const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); + tmp.set(new Uint8Array(ab1), 0); + tmp.set(new Uint8Array(ab2), ab1.byteLength); + return tmp.buffer; + } + /** + * Retrieve file content. + * + * @param file - Content of the {@link PubNub} File object. + * + * @returns Normalized file {@link data} as {@link ArrayBuffer}; + */ + getFileData(file) { + return __awaiter(this, void 0, void 0, function* () { + if (file instanceof ArrayBuffer) + return file; + else if (file instanceof PubNubFile) + return file.toArrayBuffer(); + throw new Error('Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob'); + }); + } + } + /** + * {@link LegacyCryptor|Legacy} cryptor identifier. + */ + WebCryptoModule.LEGACY_IDENTIFIER = ''; + /** + * CryptorHeader Utility + */ + class CryptorHeader { + static from(id, metadata) { + if (id === CryptorHeader.LEGACY_IDENTIFIER) + return; + return new CryptorHeaderV1(id, metadata.byteLength); + } + static tryParse(data) { + const encryptedData = new Uint8Array(data); + let sentinel; + let version = null; + if (encryptedData.byteLength >= 4) { + sentinel = encryptedData.slice(0, 4); + if (this.decoder.decode(sentinel) !== CryptorHeader.SENTINEL) + return WebCryptoModule.LEGACY_IDENTIFIER; + } + if (encryptedData.byteLength >= 5) + version = encryptedData[4]; + else + throw new Error('Decryption error: invalid header version'); + if (version > CryptorHeader.MAX_VERSION) + throw new Error('Decryption error: Unknown cryptor error'); + let identifier; + let pos = 5 + CryptorHeader.IDENTIFIER_LENGTH; + if (encryptedData.byteLength >= pos) + identifier = encryptedData.slice(5, pos); + else + throw new Error('Decryption error: invalid crypto identifier'); + let metadataLength = null; + if (encryptedData.byteLength >= pos + 1) + metadataLength = encryptedData[pos]; + else + throw new Error('Decryption error: invalid metadata length'); + pos += 1; + if (metadataLength === 255 && encryptedData.byteLength >= pos + 2) { + metadataLength = new Uint16Array(encryptedData.slice(pos, pos + 2)).reduce((acc, val) => (acc << 8) + val, 0); + } + return new CryptorHeaderV1(this.decoder.decode(identifier), metadataLength); + } + } + CryptorHeader.SENTINEL = 'PNED'; + CryptorHeader.LEGACY_IDENTIFIER = ''; + CryptorHeader.IDENTIFIER_LENGTH = 4; + CryptorHeader.VERSION = 1; + CryptorHeader.MAX_VERSION = 1; + CryptorHeader.decoder = new TextDecoder(); + // v1 CryptorHeader + class CryptorHeaderV1 { + constructor(id, metadataLength) { + this._identifier = id; + this._metadataLength = metadataLength; + } + get identifier() { + return this._identifier; + } + set identifier(value) { + this._identifier = value; + } + get metadataLength() { + return this._metadataLength; + } + set metadataLength(value) { + this._metadataLength = value; + } + get version() { + return CryptorHeader.VERSION; + } + get length() { + return (CryptorHeader.SENTINEL.length + + 1 + + CryptorHeader.IDENTIFIER_LENGTH + + (this.metadataLength < 255 ? 1 : 3) + + this.metadataLength); + } + get data() { + let pos = 0; + const header = new Uint8Array(this.length); + const encoder = new TextEncoder(); + header.set(encoder.encode(CryptorHeader.SENTINEL)); + pos += CryptorHeader.SENTINEL.length; + header[pos] = this.version; + pos++; + if (this.identifier) + header.set(encoder.encode(this.identifier), pos); + const metadataLength = this.metadataLength; + pos += CryptorHeader.IDENTIFIER_LENGTH; + if (metadataLength < 255) + header[pos] = metadataLength; + else + header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); + return header; + } + } + CryptorHeaderV1.IDENTIFIER_LENGTH = 4; + CryptorHeaderV1.SENTINEL = 'PNED'; + + /** + * Percent-encode input string. + * + * **Note:** Encode content in accordance of the `PubNub` service requirements. + * + * @param input - Source string or number for encoding. + * + * @returns Percent-encoded string. + */ + const encodeString = (input) => { + return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); + }; + /** + * Percent-encode list of names (channels). + * + * @param names - List of names which should be encoded. + * + * @param [defaultString] - String which should be used in case if {@link names} is empty. + * + * @returns String which contains encoded names joined by non-encoded `,`. + */ + const encodeNames = (names, defaultString) => { + const encodedNames = names.map((name) => encodeString(name)); + return encodedNames.length ? encodedNames.join(',') : defaultString !== null && defaultString !== void 0 ? defaultString : ''; + }; + const removeSingleOccurance = (source, elementsToRemove) => { + const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); + return source.filter((e) => { + if (elementsToRemove.includes(e) && !removed[e]) { + removed[e] = true; + return false; + } + return true; + }); + }; + const findUniqueCommonElements = (a, b) => { + return [...a].filter((value) => b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value)); + }; + /** + * Transform query key / value pairs to the string. + * + * @param query - Key / value pairs of the request query parameters. + * + * @returns Stringified query key / value pairs. + */ + const queryStringFromObject = (query) => { + return Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${encodeString(queryValue)}`; + return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); + }) + .join('&'); + }; + + /** + * Common browser and React Native Transport provider module. + */ + /** + * Class representing a `fetch`-based browser and React Native transport provider. + */ + class WebReactNativeTransport { + constructor(keepAlive = false, logVerbosity) { + this.keepAlive = keepAlive; + this.logVerbosity = logVerbosity; + } + makeSendable(req) { + let controller; + let abortController; + if (req.cancellable) { + abortController = new AbortController(); + controller = { + // Storing controller inside to prolong object lifetime. + abortController, + abort: () => abortController === null || abortController === void 0 ? void 0 : abortController.abort(), + }; + } + return [ + this.requestFromTransportRequest(req).then((request) => { + const start = new Date().getTime(); + this.logRequestProcessProgress(request); + /** + * Setup request timeout promise. + * + * **Note:** Native Fetch API doesn't support `timeout` out-of-box. + */ + const requestTimeout = new Promise((_, reject) => { + const timeoutId = setTimeout(() => { + // Clean up. + clearTimeout(timeoutId); + reject(new Error('Request timeout')); + }, req.timeout * 1000); + }); + return Promise.race([fetch(request, { signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal }), requestTimeout]) + .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) + .then((response) => { + const responseBody = response[1].byteLength > 0 ? response[1] : undefined; + const { status, headers: requestHeaders } = response[0]; + const headers = {}; + // Copy Headers object content into plain Record. + requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); + const transportResponse = { + status, + url: request.url, + headers, + body: responseBody, + }; + if (status >= 400) + throw PubNubAPIError.create(transportResponse); + this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + return transportResponse; + }) + .catch((error) => { + throw PubNubAPIError.create(error); + }); + }), + controller, + ]; + } + request(req) { + return req; + } + /** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + */ + requestFromTransportRequest(req) { + return __awaiter(this, void 0, void 0, function* () { + let body; + let path = req.path; + // Create multipart request body. + if (req.formData && req.formData.length > 0) { + // Reset query parameters to conform to signed URL + req.queryParameters = {}; + const file = req.body; + const formData = new FormData(); + for (const { key, value } of req.formData) + formData.append(key, value); + try { + const fileData = yield file.toArrayBuffer(); + formData.append('file', new Blob([fileData], { type: 'application/octet-stream' }), file.name); + } + catch (_) { + try { + const fileData = yield file.toFileUri(); + // @ts-expect-error React Native File Uri support. + formData.append('file', fileData, file.name); + } + catch (_) { } + } + body = formData; + } + // Handle regular body payload (if passed). + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) + body = req.body; + if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) + path = `${path}?${queryStringFromObject(req.queryParameters)}`; + return new Request(`${req.origin}${path}`, { + method: req.method, + headers: req.headers, + redirect: 'follow', + body, + }); + }); + } + /** + * Log out request processing progress and result. + * + * @param request - Platform-specific + * @param [elapsed] - How many seconds passed since request processing started. + * @param [body] - Service response (if available). + */ + logRequestProcessProgress(request, elapsed, body) { + if (!this.logVerbosity) + return; + const { protocol, host, pathname, search } = new URL(request.url); + const timestamp = new Date().toISOString(); + if (!elapsed) { + console.log('<<<<<'); + console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + console.log('-----'); + } + else { + const stringifiedBody = body ? WebReactNativeTransport.decoder.decode(body) : undefined; + console.log('>>>>>>'); + console.log(`[${timestamp} / ${elapsed}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`, `\n${stringifiedBody}`); + console.log('-----'); + } + } + } + /** + * Service {@link ArrayBuffer} response decoder. + */ + WebReactNativeTransport.decoder = new TextDecoder(); + + function stringifyBufferKeys(obj) { + const isObject = (value) => typeof value === 'object' && value !== null && value.constructor === Object; + const isString = (value) => typeof value === 'string' || value instanceof String; + const isNumber = (value) => typeof value === 'number' && isFinite(value); + if (!isObject(obj)) + return obj; + const normalizedObject = {}; + Object.keys(obj).forEach((key) => { + const keyIsString = isString(key); + let stringifiedKey = key; + const value = obj[key]; + if (keyIsString && key.indexOf(',') >= 0) { + const bytes = key.split(',').map(Number); + stringifiedKey = bytes.reduce((string, byte) => { + return string + String.fromCharCode(byte); + }, ''); + } + else if (isNumber(key) || (keyIsString && !isNaN(Number(key)))) { + stringifiedKey = String.fromCharCode(isNumber(key) ? key : parseInt(key, 10)); + } + normalizedObject[stringifiedKey] = isObject(value) ? stringifyBufferKeys(value) : value; + }); + return normalizedObject; + } + + /** + * {@link PubNub} client configuration module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether secured connection should be used by or not. + */ + const USE_SSL = true; + /** + * Whether PubNub client should catch up subscription after network issues. + */ + const RESTORE = false; + /** + * Whether network availability change should be announced with `PNNetworkDownCategory` and + * `PNNetworkUpCategory` state or not. + */ + const AUTO_NETWORK_DETECTION = false; + /** + * Whether messages should be de-duplicated before announcement or not. + */ + const DEDUPE_ON_SUBSCRIBE = false; + /** + * Maximum cache which should be used for message de-duplication functionality. + */ + const DEDUPE_CACHE_SIZE = 100; + /** + * Maximum number of file message publish retries. + */ + const FILE_PUBLISH_RETRY_LIMIT = 5; + /** + * Whether subscription event engine should be used or not. + */ + const ENABLE_EVENT_ENGINE = false; + /** + * Whether configured user presence state should be maintained by the PubNub client or not. + */ + const MAINTAIN_PRESENCE_STATE = true; + /** + * Whether PubNub client should try to utilize existing TCP connection for new requests or not. + */ + const KEEP_ALIVE$1 = false; + /** + * Whether verbose logging should be enabled or not. + */ + const USE_VERBOSE_LOGGING = false; + /** + * Whether leave events should be suppressed or not. + */ + const SUPPRESS_LEAVE_EVENTS = false; + /** + * Whether heartbeat request failure should be announced or not. + */ + const ANNOUNCE_HEARTBEAT_FAILURE = true; + /** + * Whether heartbeat request success should be announced or not. + */ + const ANNOUNCE_HEARTBEAT_SUCCESS = false; + /** + * Whether PubNub client instance id should be added to the requests or not. + */ + const USE_INSTANCE_ID = false; + /** + * Whether unique identifier should be added to the request or not. + */ + const USE_REQUEST_ID = true; + /** + * Transactional requests timeout. + */ + const TRANSACTIONAL_REQUEST_TIMEOUT = 15; + /** + * Subscription request timeout. + */ + const SUBSCRIBE_REQUEST_TIMEOUT = 310; + /** + * Default user presence timeout. + */ + const PRESENCE_TIMEOUT = 300; + /** + * Minimum user presence timeout. + */ + const PRESENCE_TIMEOUT_MINIMUM = 20; + /** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + */ + const setDefaults$1 = (configuration) => { + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; + // Copy configuration. + const configurationCopy = Object.assign({}, configuration); + (_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING); + (_b = configurationCopy.ssl) !== null && _b !== void 0 ? _b : (configurationCopy.ssl = USE_SSL); + (_c = configurationCopy.transactionalRequestTimeout) !== null && _c !== void 0 ? _c : (configurationCopy.transactionalRequestTimeout = TRANSACTIONAL_REQUEST_TIMEOUT); + (_d = configurationCopy.subscribeRequestTimeout) !== null && _d !== void 0 ? _d : (configurationCopy.subscribeRequestTimeout = SUBSCRIBE_REQUEST_TIMEOUT); + (_e = configurationCopy.restore) !== null && _e !== void 0 ? _e : (configurationCopy.restore = RESTORE); + (_f = configurationCopy.useInstanceId) !== null && _f !== void 0 ? _f : (configurationCopy.useInstanceId = USE_INSTANCE_ID); + (_g = configurationCopy.suppressLeaveEvents) !== null && _g !== void 0 ? _g : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS); + (_h = configurationCopy.requestMessageCountThreshold) !== null && _h !== void 0 ? _h : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE); + (_j = configurationCopy.autoNetworkDetection) !== null && _j !== void 0 ? _j : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION); + (_k = configurationCopy.enableEventEngine) !== null && _k !== void 0 ? _k : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE); + (_l = configurationCopy.maintainPresenceState) !== null && _l !== void 0 ? _l : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE); + (_m = configurationCopy.keepAlive) !== null && _m !== void 0 ? _m : (configurationCopy.keepAlive = KEEP_ALIVE$1); + if (configurationCopy.userId && configurationCopy.uuid) + throw new PubNubError("PubNub client configuration error: use only 'userId'"); + (_o = configurationCopy.userId) !== null && _o !== void 0 ? _o : (configurationCopy.userId = configurationCopy.uuid); + if (!configurationCopy.userId) + throw new PubNubError("PubNub client configuration error: 'userId' not set"); + else if (((_p = configurationCopy.userId) === null || _p === void 0 ? void 0 : _p.trim().length) === 0) + throw new PubNubError("PubNub client configuration error: 'userId' is empty"); + // Generate default origin subdomains. + if (!configurationCopy.origin) + configurationCopy.origin = Array.from({ length: 20 }, (_, i) => `ps${i + 1}.pndsn.com`); + const keySet = { + subscribeKey: configurationCopy.subscribeKey, + publishKey: configurationCopy.publishKey, + secretKey: configurationCopy.secretKey, + }; + if (configurationCopy.presenceTimeout !== undefined && configurationCopy.presenceTimeout < PRESENCE_TIMEOUT_MINIMUM) { + configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; + // eslint-disable-next-line no-console + console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); + } + (_q = configurationCopy.presenceTimeout) !== null && _q !== void 0 ? _q : (configurationCopy.presenceTimeout = PRESENCE_TIMEOUT); + // Apply extended configuration defaults. + let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS; + let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE; + let fileUploadPublishRetryLimit = FILE_PUBLISH_RETRY_LIMIT; + let dedupeOnSubscribe = DEDUPE_ON_SUBSCRIBE; + const maximumCacheSize = DEDUPE_CACHE_SIZE; + let useRequestId = USE_REQUEST_ID; + // @ts-expect-error Not documented legacy configuration options. + if (configurationCopy.dedupeOnSubscribe !== undefined && typeof configurationCopy.dedupeOnSubscribe === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. + dedupeOnSubscribe = configurationCopy.dedupeOnSubscribe; + } + // @ts-expect-error Not documented legacy configuration options. + if (configurationCopy.useRequestId !== undefined && typeof configurationCopy.useRequestId === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. + useRequestId = configurationCopy.useRequestId; + } + if ( + // @ts-expect-error Not documented legacy configuration options. + configurationCopy.announceSuccessfulHeartbeats !== undefined && + // @ts-expect-error Not documented legacy configuration options. + typeof configurationCopy.announceSuccessfulHeartbeats === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. + announceSuccessfulHeartbeats = configurationCopy.announceSuccessfulHeartbeats; + } + if ( + // @ts-expect-error Not documented legacy configuration options. + configurationCopy.announceFailedHeartbeats !== undefined && + // @ts-expect-error Not documented legacy configuration options. + typeof configurationCopy.announceFailedHeartbeats === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. + announceFailedHeartbeats = configurationCopy.announceFailedHeartbeats; + } + if ( + // @ts-expect-error Not documented legacy configuration options. + configurationCopy.fileUploadPublishRetryLimit !== undefined && + // @ts-expect-error Not documented legacy configuration options. + typeof configurationCopy.fileUploadPublishRetryLimit === 'number') { + // @ts-expect-error Not documented legacy configuration options. + fileUploadPublishRetryLimit = configurationCopy.fileUploadPublishRetryLimit; + } + return Object.assign(Object.assign({}, configurationCopy), { keySet, + dedupeOnSubscribe, + maximumCacheSize, + useRequestId, + announceSuccessfulHeartbeats, + announceFailedHeartbeats, + fileUploadPublishRetryLimit }); + }; + + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether PubNub client should update its state using browser's reachability events or not. + * + * If the browser fails to detect the network changes from Wi-Fi to LAN and vice versa, or you get + * reconnection issues, set the flag to `false`. This allows the SDK reconnection logic to take over. + */ + const LISTEN_TO_BROWSER_NETWORK_EVENTS = true; + /** + * Whether PubNub client should spawn `Subscription` service worker for better user presence + * experience or not. + */ + const ENABLE_SERVICE_WORKER = false; + /** + * Whether PubNub client should try to utilize existing TCP connection for new requests or not. + */ + const KEEP_ALIVE = true; + /** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + */ + const setDefaults = (configuration) => { + var _a, _b, _c, _d; + // Force disable service workers if environment doesn't support them. + if (((_a = configuration.enableServiceWorker) !== null && _a !== void 0 ? _a : ENABLE_SERVICE_WORKER) && !('serviceWorker' in navigator)) + configuration.enableServiceWorker = false; + return Object.assign(Object.assign({}, setDefaults$1(configuration)), { + // Set platform-specific options. + listenToBrowserNetworkEvents: (_b = configuration.listenToBrowserNetworkEvents) !== null && _b !== void 0 ? _b : LISTEN_TO_BROWSER_NETWORK_EVENTS, enableServiceWorker: (_c = configuration.enableServiceWorker) !== null && _c !== void 0 ? _c : ENABLE_SERVICE_WORKER, keepAlive: (_d = configuration.keepAlive) !== null && _d !== void 0 ? _d : KEEP_ALIVE }); + }; + + var uuid = {exports: {}}; + + /*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */ + uuid.exports; + + (function (module, exports) { + (function (root, factory) { + { + factory(exports); + if (module !== null) { + module.exports = exports.uuid; + } + } + }(commonjsGlobal, function (exports) { + var VERSION = '0.1.0'; + var uuidRegex = { + '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, + '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, + '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, + all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i + }; + + function uuid() { + var uuid = '', i, random; + for (i = 0; i < 32; i++) { + random = Math.random() * 16 | 0; + if (i === 8 || i === 12 || i === 16 || i === 20) uuid += '-'; + uuid += (i === 12 ? 4 : (i === 16 ? (random & 3 | 8) : random)).toString(16); + } + return uuid + } + + function isUUID(str, version) { + var pattern = uuidRegex[version || 'all']; + return pattern && pattern.test(str) || false + } + + uuid.isUUID = isUUID; + uuid.VERSION = VERSION; + + exports.uuid = uuid; + exports.isUUID = isUUID; + })); + } (uuid, uuid.exports)); + + var uuidExports = uuid.exports; + var uuidGenerator$1 = /*@__PURE__*/getDefaultExportFromCjs(uuidExports); + + var uuidGenerator = { + createUUID() { + if (uuidGenerator$1.uuid) { + return uuidGenerator$1.uuid(); + } + // @ts-expect-error Depending on module type it may be callable. + return uuidGenerator$1(); + }, + }; + + /** + * {@link PubNub} client configuration module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether encryption (if set) should use random initialization vector or not. + */ + const USE_RANDOM_INITIALIZATION_VECTOR = true; + /** + * Create {@link PubNub} client private configuration object. + * + * @param base - User- and platform-provided configuration. + * @param setupCryptoModule - Platform-provided {@link CryptoModule} configuration block. + * + * @returns `PubNub` client private configuration. + */ + const makeConfiguration = (base, setupCryptoModule) => { + var _a, _b, _c; + // Ensure that retry policy has proper configuration (if has been set). + (_a = base.retryConfiguration) === null || _a === void 0 ? void 0 : _a.validate(); + (_b = base.useRandomIVs) !== null && _b !== void 0 ? _b : (base.useRandomIVs = USE_RANDOM_INITIALIZATION_VECTOR); + // Override origin value. + base.origin = standardOrigin((_c = base.ssl) !== null && _c !== void 0 ? _c : false, base.origin); + const cryptoModule = base.cryptoModule; + if (cryptoModule) + delete base.cryptoModule; + const clientConfiguration = Object.assign(Object.assign({}, base), { _pnsdkSuffix: {}, _instanceId: `pn-${uuidGenerator.createUUID()}`, _cryptoModule: undefined, _cipherKey: undefined, _setupCryptoModule: setupCryptoModule, get instanceId() { + if (this.useInstanceId) + return this._instanceId; + return undefined; + }, + getUserId() { + return this.userId; + }, + setUserId(value) { + if (!value || typeof value !== 'string' || value.trim().length === 0) + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); + this.userId = value; + }, + getAuthKey() { + return this.authKey; + }, + setAuthKey(authKey) { + this.authKey = authKey; + }, + getFilterExpression() { + return this.filterExpression; + }, + setFilterExpression(expression) { + this.filterExpression = expression; + }, + getCipherKey() { + return this._cipherKey; + }, + setCipherKey(key) { + this._cipherKey = key; + if (!key && this._cryptoModule) { + this._cryptoModule = undefined; + return; + } + else if (!key || !this._setupCryptoModule) + return; + this._cryptoModule = this._setupCryptoModule({ + cipherKey: key, + useRandomIVs: base.useRandomIVs, + customEncrypt: this.getCustomEncrypt(), + customDecrypt: this.getCustomDecrypt(), + }); + }, + getCryptoModule() { + return this._cryptoModule; + }, + getUseRandomIVs() { + return base.useRandomIVs; + }, + setPresenceTimeout(value) { + this.heartbeatInterval = value / 2 - 1; + this.presenceTimeout = value; + }, + getPresenceTimeout() { + return this.presenceTimeout; + }, + getHeartbeatInterval() { + return this.heartbeatInterval; + }, + setHeartbeatInterval(interval) { + this.heartbeatInterval = interval; + }, + getTransactionTimeout() { + return this.transactionalRequestTimeout; + }, + getSubscribeTimeout() { + return this.subscribeRequestTimeout; + }, + get PubNubFile() { + return base.PubNubFile; + }, + get version() { + return '7.6.3'; + }, + getVersion() { + return this.version; + }, + _addPnsdkSuffix(name, suffix) { + this._pnsdkSuffix[name] = `${suffix}`; + }, + _getPnsdkSuffix(separator) { + const sdk = Object.values(this._pnsdkSuffix).join(separator); + return sdk.length > 0 ? separator + sdk : ''; + }, + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + getUUID() { + return this.getUserId(); + }, + setUUID(value) { + this.setUserId(value); + }, + getCustomEncrypt() { + return base.customEncrypt; + }, + getCustomDecrypt() { + return base.customDecrypt; + } }); + // Setup `CryptoModule` if possible. + if (base.cipherKey) + clientConfiguration.setCipherKey(base.cipherKey); + else if (cryptoModule) + clientConfiguration._cryptoModule = cryptoModule; + return clientConfiguration; + }; + /** + * Decide {@lin PubNub} service REST API origin. + * + * @param secure - Whether preferred to use secured connection or not. + * @param origin - User-provided or default origin. + * + * @returns `PubNub` REST API endpoints origin. + */ + const standardOrigin = (secure, origin) => { + const protocol = secure ? 'https://' : 'http://'; + if (typeof origin === 'string') + return `${protocol}${origin}`; + return `${protocol}${origin[Math.floor(Math.random() * origin.length)]}`; + }; + + /** + * PubNub Access Token Manager module. + */ + // endregion + /** + * REST API access token manager. + * + * Manager maintains active access token and let parse it to get information about permissions. + */ + class TokenManager { + constructor(cbor) { + this.cbor = cbor; + } + /** + * Update REST API access token. + * + * **Note:** Token will be applied only for next requests and won't affect ongoing requests. + * + * @param [token] - Access token which should be used to access PubNub REST API. + */ + setToken(token) { + if (token && token.length > 0) + this.token = token; + else + this.token = undefined; + } + /** + * REST API access token. + * + * @returns Previously configured REST API access token. + */ + getToken() { + return this.token; + } + /** + * Parse Base64-encoded access token. + * + * @param tokenString - Base64-encoded access token. + * + * @returns Information about resources and permissions which has been granted for them. + */ + parseToken(tokenString) { + const parsed = this.cbor.decodeToken(tokenString); + if (parsed !== undefined) { + const uuidResourcePermissions = parsed.res.uuid ? Object.keys(parsed.res.uuid) : []; + const channelResourcePermissions = Object.keys(parsed.res.chan); + const groupResourcePermissions = Object.keys(parsed.res.grp); + const uuidPatternPermissions = parsed.pat.uuid ? Object.keys(parsed.pat.uuid) : []; + const channelPatternPermissions = Object.keys(parsed.pat.chan); + const groupPatternPermissions = Object.keys(parsed.pat.grp); + const result = { + version: parsed.v, + timestamp: parsed.t, + ttl: parsed.ttl, + authorized_uuid: parsed.uuid, + signature: parsed.sig, + }; + const uuidResources = uuidResourcePermissions.length > 0; + const channelResources = channelResourcePermissions.length > 0; + const groupResources = groupResourcePermissions.length > 0; + if (uuidResources || channelResources || groupResources) { + result.resources = {}; + if (uuidResources) { + const uuids = (result.resources.uuids = {}); + uuidResourcePermissions.forEach((id) => (uuids[id] = this.extractPermissions(parsed.res.uuid[id]))); + } + if (channelResources) { + const channels = (result.resources.channels = {}); + channelResourcePermissions.forEach((id) => (channels[id] = this.extractPermissions(parsed.res.chan[id]))); + } + if (groupResources) { + const groups = (result.resources.groups = {}); + groupResourcePermissions.forEach((id) => (groups[id] = this.extractPermissions(parsed.res.grp[id]))); + } + } + const uuidPatterns = uuidPatternPermissions.length > 0; + const channelPatterns = channelPatternPermissions.length > 0; + const groupPatterns = groupPatternPermissions.length > 0; + if (uuidPatterns || channelPatterns || groupPatterns) { + result.patterns = {}; + if (uuidPatterns) { + const uuids = (result.patterns.uuids = {}); + uuidPatternPermissions.forEach((id) => (uuids[id] = this.extractPermissions(parsed.pat.uuid[id]))); + } + if (channelPatterns) { + const channels = (result.patterns.channels = {}); + channelPatternPermissions.forEach((id) => (channels[id] = this.extractPermissions(parsed.pat.chan[id]))); + } + if (groupPatterns) { + const groups = (result.patterns.groups = {}); + groupPatternPermissions.forEach((id) => (groups[id] = this.extractPermissions(parsed.pat.grp[id]))); + } + } + if (parsed.meta && Object.keys(parsed.meta).length > 0) + result.meta = parsed.meta; + return result; + } + return undefined; + } + /** + * Extract resource access permission information. + * + * @param permissions - Bit-encoded resource permissions. + * + * @returns Human-readable resource permissions. + */ + extractPermissions(permissions) { + const permissionsResult = { + read: false, + write: false, + manage: false, + delete: false, + get: false, + update: false, + join: false, + }; + if ((permissions & 128) === 128) + permissionsResult.join = true; + if ((permissions & 64) === 64) + permissionsResult.update = true; + if ((permissions & 32) === 32) + permissionsResult.get = true; + if ((permissions & 8) === 8) + permissionsResult.delete = true; + if ((permissions & 4) === 4) + permissionsResult.manage = true; + if ((permissions & 2) === 2) + permissionsResult.write = true; + if ((permissions & 1) === 1) + permissionsResult.read = true; + return permissionsResult; + } + } + + /** + * Enum representing possible transport methods for HTTP requests. + * + * @enum {number} + */ + var TransportMethod; + (function (TransportMethod) { + /** + * Request will be sent using `GET` method. + */ + TransportMethod["GET"] = "GET"; + /** + * Request will be sent using `POST` method. + */ + TransportMethod["POST"] = "POST"; + /** + * Request will be sent using `PATCH` method. + */ + TransportMethod["PATCH"] = "PATCH"; + /** + * Request will be sent using `DELETE` method. + */ + TransportMethod["DELETE"] = "DELETE"; + /** + * Local request. + * + * Request won't be sent to the service and probably used to compute URL. + */ + TransportMethod["LOCAL"] = "LOCAL"; + })(TransportMethod || (TransportMethod = {})); + + class RequestSignature { + constructor(publishKey, secretKey, hasher) { + this.publishKey = publishKey; + this.secretKey = secretKey; + this.hasher = hasher; + } + /** + * Compute request signature. + * + * @param req - Request which will be used to compute signature. + * @returns {string} `v2` request signature. + */ + signature(req) { + const method = req.path.startsWith('/publish') ? TransportMethod.GET : req.method; + let signatureInput = `${method}\n${this.publishKey}\n${req.path}\n${this.queryParameters(req.queryParameters)}\n`; + if (method === TransportMethod.POST || method === TransportMethod.PATCH) { + const body = req.body; + let payload; + if (body && body instanceof ArrayBuffer) { + payload = RequestSignature.textDecoder.decode(body); + } + else if (body && typeof body !== 'object') { + payload = body; + } + if (payload) + signatureInput += payload; + } + return `v2.${this.hasher(signatureInput, this.secretKey)}` + .replace(/\+/g, '-') + .replace(/\//g, '_') + .replace(/=+$/, ''); + } + /** + * Prepare request query parameters for signature. + * + * @param query - Key / value pair of the request query parameters. + * @private + */ + queryParameters(query) { + return Object.keys(query) + .sort() + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${encodeString(queryValue)}`; + return queryValue + .sort() + .map((value) => `${key}=${encodeString(value)}`) + .join('&'); + }) + .join('&'); + } + } + RequestSignature.textDecoder = new TextDecoder('utf-8'); + class PubNubMiddleware { + constructor(configuration) { + this.configuration = configuration; + const { clientConfiguration: { keySet }, shaHMAC, } = configuration; + if (keySet.secretKey && shaHMAC) + this.signatureGenerator = new RequestSignature(keySet.publishKey, keySet.secretKey, shaHMAC); + } + makeSendable(req) { + return this.configuration.transport.makeSendable(this.request(req)); + } + request(req) { + var _a; + const { clientConfiguration } = this.configuration; + // Get request patched by transport provider. + req = this.configuration.transport.request(req); + if (!req.queryParameters) + req.queryParameters = {}; + // Modify request with required information. + if (clientConfiguration.useInstanceId) + req.queryParameters['instanceid'] = clientConfiguration.instanceId; + if (!req.queryParameters['uuid']) + req.queryParameters['uuid'] = clientConfiguration.userId; + if (clientConfiguration.useRequestId) + req.queryParameters['requestid'] = req.identifier; + req.queryParameters['pnsdk'] = this.generatePNSDK(); + (_a = req.origin) !== null && _a !== void 0 ? _a : (req.origin = clientConfiguration.origin); + // Authenticate request if required. + this.authenticateRequest(req); + // Sign request if it is required. + this.signRequest(req); + return req; + } + authenticateRequest(req) { + var _a; + // Access management endpoints doesn't need authentication (signature required instead). + if (req.path.startsWith('/v2/auth/') || req.path.startsWith('/v3/pam/') || req.path.startsWith('/time')) + return; + const { clientConfiguration, tokenManager } = this.configuration; + const accessKey = (_a = tokenManager.getToken()) !== null && _a !== void 0 ? _a : clientConfiguration.authKey; + if (accessKey) + req.queryParameters['auth'] = accessKey; + } + /** + * Compute and append request signature. + * + * @param req - Transport request with information which should be used to generate signature. + */ + signRequest(req) { + if (!this.signatureGenerator || req.path.startsWith('/time')) + return; + req.queryParameters['timestamp'] = String(Math.floor(new Date().getTime() / 1000)); + req.queryParameters['signature'] = this.signatureGenerator.signature(req); + } + /** + * Compose `pnsdk` query parameter. + * + * SDK provides ability to set custom name or append vendor information to the `pnsdk` query + * parameter. + * + * @returns Finalized `pnsdk` query parameter value. + */ + generatePNSDK() { + const { clientConfiguration } = this.configuration; + if (clientConfiguration.sdkName) + return clientConfiguration.sdkName; + let base = `PubNub-JS-${clientConfiguration.sdkFamily}`; + if (clientConfiguration.partnerId) + base += `-${clientConfiguration.partnerId}`; + base += `/${clientConfiguration.getVersion()}`; + const pnsdkSuffix = clientConfiguration._getPnsdkSuffix(' '); + if (pnsdkSuffix.length > 0) + base += pnsdkSuffix; + return base; + } + } + + /** + * Events listener manager module. + */ + /** + * Real-time listeners' manager. + */ + class ListenerManager { + constructor() { + /** + * List of registered event listeners. + */ + this.listeners = []; + // endregion + } + /** + * Register new real-time events listener. + * + * @param listener - Listener with event callbacks to handle different types of events. + */ + addListener(listener) { + if (this.listeners.includes(listener)) + return; + this.listeners.push(listener); + } + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + */ + removeListener(listener) { + this.listeners = this.listeners.filter((storedListener) => storedListener !== listener); + } + /** + * Clear all real-time event listeners. + */ + removeAllListeners() { + this.listeners = []; + } + /** + * Announce PubNub client status change event. + * + * @param status - PubNub client status. + */ + announceStatus(status) { + this.listeners.forEach((listener) => { + if (listener.status) + listener.status(status); + }); + } + /** + * Announce channel presence change event. + * + * @param presence - Channel presence change information. + */ + announcePresence(presence) { + this.listeners.forEach((listener) => { + if (listener.presence) + listener.presence(presence); + }); + } + /** + * Announce real-time message event. + * + * @param message - Received real-time message. + */ + announceMessage(message) { + this.listeners.forEach((listener) => { + if (listener.message) + listener.message(message); + }); + } + /** + * Announce real-time signal event. + * + * @param signal - Received real-time signal. + */ + announceSignal(signal) { + this.listeners.forEach((listener) => { + if (listener.signal) + listener.signal(signal); + }); + } + /** + * Announce message actions change event. + * + * @param messageAction - Message action change information. + */ + announceMessageAction(messageAction) { + this.listeners.forEach((listener) => { + if (listener.messageAction) + listener.messageAction(messageAction); + }); + } + /** + * Announce fie share event. + * + * @param file - Shared file information. + */ + announceFile(file) { + this.listeners.forEach((listener) => { + if (listener.file) + listener.file(file); + }); + } + /** + * Announce App Context Object change event. + * + * @param object - App Context change information. + */ + announceObjects(object) { + this.listeners.forEach((listener) => { + if (listener.objects) + listener.objects(object); + }); + } + /** + * Announce network up status. + */ + announceNetworkUp() { + this.listeners.forEach((listener) => { + if (listener.status) { + listener.status({ + category: StatusCategory$1.PNNetworkUpCategory, + }); + } + }); + } + /** + * Announce network down status. + */ + announceNetworkDown() { + this.listeners.forEach((listener) => { + if (listener.status) { + listener.status({ + category: StatusCategory$1.PNNetworkDownCategory, + }); + } + }); + } + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + /** + * Announce User App Context Object change event. + * + * @param user - User App Context change information. + * + * @deprecated Use {@link announceObjects} method instead. + */ + announceUser(user) { + this.listeners.forEach((listener) => { + if (listener.user) + listener.user(user); + }); + } + /** + * Announce Space App Context Object change event. + * + * @param space - Space App Context change information. + * + * @deprecated Use {@link announceObjects} method instead. + */ + announceSpace(space) { + this.listeners.forEach((listener) => { + if (listener.space) + listener.space(space); + }); + } + /** + * Announce VSP Membership App Context Object change event. + * + * @param membership - VSP Membership App Context change information. + * + * @deprecated Use {@link announceObjects} method instead. + */ + announceMembership(membership) { + this.listeners.forEach((listener) => { + if (listener.membership) + listener.membership(membership); + }); + } + } + + /** + * Subscription reconnection-manager. + * + * **Note:** Reconnection manger rely on legacy time-based availability check. + */ + class ReconnectionManager { + constructor(time) { + this.time = time; + } + /** + * Configure reconnection handler. + * + * @param callback - Successful availability check notify callback. + */ + onReconnect(callback) { + this.callback = callback; + } + /** + * Start periodic "availability" check. + */ + startPolling() { + this.timeTimer = setInterval(() => this.callTime(), 3000); + } + /** + * Stop periodic "availability" check. + */ + stopPolling() { + if (this.timeTimer) + clearInterval(this.timeTimer); + this.timeTimer = null; + } + callTime() { + this.time((status) => { + if (!status.error) { + this.stopPolling(); + if (this.callback) + this.callback(); + } + }); + } + } + + /* */ + + const hashCode = (payload) => { + let hash = 0; + if (payload.length === 0) return hash; + for (let i = 0; i < payload.length; i += 1) { + const character = payload.charCodeAt(i); + hash = (hash << 5) - hash + character; // eslint-disable-line + hash = hash & hash; // eslint-disable-line + } + return hash; + }; + + class DedupingManager { + _config; + + hashHistory; + + constructor({ config }) { + this.hashHistory = []; + this._config = config; + } + + getKey(message) { + const hashedPayload = hashCode(JSON.stringify(message.message)).toString(); + const timetoken = message.timetoken; + return `${timetoken}-${hashedPayload}`; + } + + isDuplicate(message) { + return this.hashHistory.includes(this.getKey(message)); + } + + addEntry(message) { + if (this.hashHistory.length >= this._config.maximumCacheSize) { + this.hashHistory.shift(); + } + + this.hashHistory.push(this.getKey(message)); + } + + clearHistory() { + this.hashHistory = []; + } + } + + /** + * Subscription manager module. + */ + /** + * Subscription loop manager. + */ + class SubscriptionManager { + constructor(configuration, listenerManager, eventEmitter, subscribeCall, heartbeatCall, leaveCall, time) { + this.configuration = configuration; + this.listenerManager = listenerManager; + this.eventEmitter = eventEmitter; + this.subscribeCall = subscribeCall; + this.heartbeatCall = heartbeatCall; + this.leaveCall = leaveCall; + this.reconnectionManager = new ReconnectionManager(time); + this.dedupingManager = new DedupingManager({ config: this.configuration }); + this.heartbeatChannelGroups = {}; + this.heartbeatChannels = {}; + this.presenceChannelGroups = {}; + this.presenceChannels = {}; + this.heartbeatTimer = null; + this.presenceState = {}; + this.pendingChannelGroupSubscriptions = new Set(); + this.pendingChannelSubscriptions = new Set(); + this.channelGroups = {}; + this.channels = {}; + this.currentTimetoken = '0'; + this.lastTimetoken = '0'; + this.storedTimetoken = null; + this.subscriptionStatusAnnounced = false; + this.isOnline = true; + } + // region Information + get subscribedChannels() { + return Object.keys(this.channels); + } + get subscribedChannelGroups() { + return Object.keys(this.channelGroups); + } + get abort() { + return this._subscribeAbort; + } + set abort(call) { + this._subscribeAbort = call; + } + // endregion + // region Subscription + disconnect() { + this.stopSubscribeLoop(); + this.stopHeartbeatTimer(); + this.reconnectionManager.stopPolling(); + } + reconnect() { + this.startSubscribeLoop(); + this.startHeartbeatTimer(); + } + /** + * Update channels and groups used in subscription loop. + * + * @param parameters - Subscribe configuration parameters. + */ + subscribe(parameters) { + const { channels, channelGroups, timetoken, withPresence = false, withHeartbeats = false } = parameters; + if (timetoken) { + this.lastTimetoken = this.currentTimetoken; + this.currentTimetoken = timetoken; + } + if (this.currentTimetoken !== '0' && this.currentTimetoken !== 0) { + this.storedTimetoken = this.currentTimetoken; + this.currentTimetoken = 0; + } + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + this.pendingChannelSubscriptions.add(channel); + this.channels[channel] = {}; + if (withPresence) + this.presenceChannels[channel] = {}; + if (withHeartbeats || this.configuration.getHeartbeatInterval()) + this.heartbeatChannels[channel] = {}; + }); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => { + this.pendingChannelGroupSubscriptions.add(group); + this.channelGroups[group] = {}; + if (withPresence) + this.presenceChannelGroups[group] = {}; + if (withHeartbeats || this.configuration.getHeartbeatInterval()) + this.heartbeatChannelGroups[group] = {}; + }); + this.subscriptionStatusAnnounced = false; + this.reconnect(); + } + unsubscribe(parameters, isOffline) { + let { channels, channelGroups } = parameters; + const actualChannelGroups = new Set(); + const actualChannels = new Set(); + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + if (channel in this.channels) { + delete this.channels[channel]; + actualChannels.add(channel); + if (channel in this.heartbeatChannels) + delete this.heartbeatChannels[channel]; + } + if (channel in this.presenceState) + delete this.presenceState[channel]; + if (channel in this.presenceChannels) { + delete this.presenceChannels[channel]; + actualChannels.add(channel); + } + }); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => { + if (group in this.channelGroups) { + delete this.channelGroups[group]; + actualChannelGroups.add(group); + if (group in this.heartbeatChannelGroups) + delete this.heartbeatChannelGroups[group]; + } + if (group in this.presenceState) + delete this.presenceState[group]; + if (group in this.presenceChannelGroups) { + delete this.presenceChannelGroups[group]; + actualChannelGroups.add(group); + } + }); + // There is no need to unsubscribe to empty list of data sources. + if (actualChannels.size === 0 && actualChannelGroups.size === 0) + return; + if (this.configuration.suppressLeaveEvents === false && !isOffline) { + channelGroups = Array.from(actualChannelGroups); + channels = Array.from(actualChannels); + this.leaveCall({ channels, channelGroups }, (status) => { + const { error } = status, restOfStatus = __rest(status, ["error"]); + let errorMessage; + if (error) { + if (status.errorData && + typeof status.errorData === 'object' && + 'message' in status.errorData && + typeof status.errorData.message === 'string') + errorMessage = status.errorData.message; + else if ('message' in status && typeof status.message === 'string') + errorMessage = status.message; + } + this.listenerManager.announceStatus(Object.assign(Object.assign({}, restOfStatus), { error: errorMessage !== null && errorMessage !== void 0 ? errorMessage : false, affectedChannels: channels, affectedChannelGroups: channelGroups, currentTimetoken: this.currentTimetoken, lastTimetoken: this.lastTimetoken })); + }); + } + if (Object.keys(this.channels).length === 0 && + Object.keys(this.presenceChannels).length === 0 && + Object.keys(this.channelGroups).length === 0 && + Object.keys(this.presenceChannelGroups).length === 0) { + this.lastTimetoken = 0; + this.currentTimetoken = 0; + this.storedTimetoken = null; + this.region = null; + this.reconnectionManager.stopPolling(); + } + this.reconnect(); + } + unsubscribeAll(isOffline) { + this.unsubscribe({ + channels: this.subscribedChannels, + channelGroups: this.subscribedChannelGroups, + }, isOffline); + } + startSubscribeLoop() { + this.stopSubscribeLoop(); + const channelGroups = [...Object.keys(this.channelGroups)]; + const channels = [...Object.keys(this.channels)]; + Object.keys(this.presenceChannelGroups).forEach((group) => channelGroups.push(`${group}-pnpres`)); + Object.keys(this.presenceChannels).forEach((channel) => channels.push(`${channel}-pnpres`)); + // There is no need to start subscription loop for empty list of data sources. + if (channels.length === 0 && channelGroups.length === 0) + return; + this.subscribeCall({ + channels, + channelGroups, + state: this.presenceState, + heartbeat: this.configuration.getPresenceTimeout(), + timetoken: this.currentTimetoken, + region: this.region !== null ? this.region : undefined, + filterExpression: this.configuration.filterExpression, + }, (status, result) => { + this.processSubscribeResponse(status, result); + }); + } + stopSubscribeLoop() { + if (this._subscribeAbort) { + this._subscribeAbort(); + this._subscribeAbort = null; + } + } + /** + * Process subscribe REST API endpoint response. + */ + processSubscribeResponse(status, result) { + if (status.error) { + // Ignore aborted request. + if ((typeof status.errorData === 'object' && + 'name' in status.errorData && + status.errorData.name === 'AbortError') || + status.category === StatusCategory$1.PNCancelledCategory) + return; + if (status.category === StatusCategory$1.PNTimeoutCategory) { + this.startSubscribeLoop(); + } + else if (status.category === StatusCategory$1.PNNetworkIssuesCategory) { + this.disconnect(); + if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { + this.isOnline = false; + this.listenerManager.announceNetworkDown(); + } + this.reconnectionManager.onReconnect(() => { + if (this.configuration.autoNetworkDetection && !this.isOnline) { + this.isOnline = true; + this.listenerManager.announceNetworkUp(); + } + this.reconnect(); + this.subscriptionStatusAnnounced = true; + const reconnectedAnnounce = { + category: StatusCategory$1.PNReconnectedCategory, + operation: status.operation, + lastTimetoken: this.lastTimetoken, + currentTimetoken: this.currentTimetoken, + }; + this.listenerManager.announceStatus(reconnectedAnnounce); + }); + this.reconnectionManager.startPolling(); + this.listenerManager.announceStatus(status); + } + else if (status.category === StatusCategory$1.PNBadRequestCategory) { + this.stopHeartbeatTimer(); + this.listenerManager.announceStatus(status); + } + else { + this.listenerManager.announceStatus(status); + } + return; + } + if (this.storedTimetoken) { + this.currentTimetoken = this.storedTimetoken; + this.storedTimetoken = null; + } + else { + this.lastTimetoken = this.currentTimetoken; + this.currentTimetoken = result.cursor.timetoken; + } + if (!this.subscriptionStatusAnnounced) { + const connected = { + category: StatusCategory$1.PNConnectedCategory, + operation: status.operation, + affectedChannels: Array.from(this.pendingChannelSubscriptions), + subscribedChannels: this.subscribedChannels, + affectedChannelGroups: Array.from(this.pendingChannelGroupSubscriptions), + lastTimetoken: this.lastTimetoken, + currentTimetoken: this.currentTimetoken, + }; + this.subscriptionStatusAnnounced = true; + this.listenerManager.announceStatus(connected); + // Clear pending channels and groups. + this.pendingChannelGroupSubscriptions.clear(); + this.pendingChannelSubscriptions.clear(); + } + const { messages } = result; + const { requestMessageCountThreshold, dedupeOnSubscribe } = this.configuration; + if (requestMessageCountThreshold && messages.length >= requestMessageCountThreshold) { + this.listenerManager.announceStatus({ + category: StatusCategory$1.PNRequestMessageCountExceededCategory, + operation: status.operation, + }); + } + try { + messages.forEach((message) => { + if (dedupeOnSubscribe) { + if (this.dedupingManager.isDuplicate(message.data)) + return; + this.dedupingManager.addEntry(message.data); + } + this.eventEmitter.emitEvent(message); + }); + } + catch (e) { + const errorStatus = { + error: true, + category: StatusCategory$1.PNUnknownCategory, + errorData: e, + statusCode: 0, + }; + this.listenerManager.announceStatus(errorStatus); + } + this.region = result.cursor.region; + this.startSubscribeLoop(); + } + // endregion + // region Presence + /** + * Update `uuid` state which should be sent with subscribe request. + * + * @param parameters - Channels and groups with state which should be associated to `uuid`. + */ + setState(parameters) { + const { state, channels, channelGroups } = parameters; + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => channel in this.channels && (this.presenceState[channel] = state)); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => group in this.channelGroups && (this.presenceState[group] = state)); + } + /** + * Manual presence management. + * + * @param parameters - Desired presence state for provided list of channels and groups. + */ + changePresence(parameters) { + const { connected, channels, channelGroups } = parameters; + if (connected) { + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => (this.heartbeatChannels[channel] = {})); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => (this.heartbeatChannelGroups[group] = {})); + } + else { + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + if (channel in this.heartbeatChannels) + delete this.heartbeatChannels[channel]; + }); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => { + if (group in this.heartbeatChannelGroups) + delete this.heartbeatChannelGroups[group]; + }); + if (this.configuration.suppressLeaveEvents === false) { + this.leaveCall({ channels, channelGroups }, (status) => this.listenerManager.announceStatus(status)); + } + } + this.reconnect(); + } + startHeartbeatTimer() { + this.stopHeartbeatTimer(); + const heartbeatInterval = this.configuration.getHeartbeatInterval(); + if (!heartbeatInterval || heartbeatInterval === 0) + return; + this.sendHeartbeat(); + this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), heartbeatInterval * 1000); + } + /** + * Stop heartbeat. + * + * Stop timer which trigger {@link HeartbeatRequest} sending with configured presence intervals. + */ + stopHeartbeatTimer() { + if (!this.heartbeatTimer) + return; + clearInterval(this.heartbeatTimer); + this.heartbeatTimer = null; + } + /** + * Send heartbeat request. + */ + sendHeartbeat() { + const heartbeatChannelGroups = Object.keys(this.heartbeatChannelGroups); + const heartbeatChannels = Object.keys(this.heartbeatChannels); + // There is no need to start heartbeat loop if there is no channels and groups to use. + if (heartbeatChannels.length === 0 && heartbeatChannelGroups.length === 0) + return; + this.heartbeatCall({ + channels: heartbeatChannels, + channelGroups: heartbeatChannelGroups, + heartbeat: this.configuration.getPresenceTimeout(), + state: this.presenceState, + }, (status) => { + if (status.error && this.configuration.announceFailedHeartbeats) + this.listenerManager.announceStatus(status); + if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { + this.isOnline = false; + this.disconnect(); + this.listenerManager.announceNetworkDown(); + this.reconnect(); + } + if (!status.error && this.configuration.announceSuccessfulHeartbeats) + this.listenerManager.announceStatus(status); + }); + } + } + + // -------------------------------------------------------- + // ------------------------ Types ------------------------- + // -------------------------------------------------------- + // region Types + // endregion + // endregion + /** + * Base notification payload object. + */ + class BaseNotificationPayload { + constructor(payload, title, body) { + this._payload = payload; + this.setDefaultPayloadStructure(); + this.title = title; + this.body = body; + } + /** + * Retrieve resulting notification payload content for message. + * + * @returns Preformatted push notification payload data. + */ + get payload() { + return this._payload; + } + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value) { + this._title = value; + } + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value) { + this._subtitle = value; + } + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value) { + this._body = value; + } + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value) { + this._badge = value; + } + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value) { + this._sound = value; + } + /** + * Platform-specific structure initialization. + */ + setDefaultPayloadStructure() { } + /** + * Translate data object into PubNub push notification payload object. + * + * @returns Preformatted push notification payload. + */ + toObject() { + return {}; + } + } + /** + * Message payload for Apple Push Notification Service. + */ + class APNSNotificationPayload extends BaseNotificationPayload { + constructor() { + super(...arguments); + /** + * Type of push notification service for which payload will be created. + */ + this._apnsPushType = 'apns'; + /** + * Whether resulting payload should trigger silent notification or not. + */ + this._isSilent = false; + } + get payload() { + return this._payload; + } + /** + * Update notification receivers configuration. + * + * @param value - New APNS2 configurations. + */ + set configurations(value) { + if (!value || !value.length) + return; + this._configurations = value; + } + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ + get notification() { + return this.payload.aps; + } + /** + * Notification title. + * + * @returns Main notification title. + */ + get title() { + return this._title; + } + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value) { + if (!value || !value.length) + return; + this.payload.aps.alert.title = value; + this._title = value; + } + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ + get subtitle() { + return this._subtitle; + } + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value) { + if (!value || !value.length) + return; + this.payload.aps.alert.subtitle = value; + this._subtitle = value; + } + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body() { + return this._body; + } + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value) { + if (!value || !value.length) + return; + this.payload.aps.alert.body = value; + this._body = value; + } + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ + get badge() { + return this._badge; + } + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value) { + if (value === undefined || value === null) + return; + this.payload.aps.badge = value; + this._badge = value; + } + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound() { + return this._sound; + } + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value) { + if (!value || !value.length) + return; + this.payload.aps.sound = value; + this._sound = value; + } + /** + * Set whether notification should be silent or not. + * + * `content-available` notification type will be used to deliver silent notification if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ + set silent(value) { + this._isSilent = value; + } + setDefaultPayloadStructure() { + this.payload.aps = { alert: {} }; + } + toObject() { + const payload = Object.assign({}, this.payload); + const { aps } = payload; + let { alert } = aps; + if (this._isSilent) + aps['content-available'] = 1; + if (this._apnsPushType === 'apns2') { + if (!this._configurations || !this._configurations.length) + throw new ReferenceError('APNS2 configuration is missing'); + const configurations = []; + this._configurations.forEach((configuration) => { + configurations.push(this.objectFromAPNS2Configuration(configuration)); + }); + if (configurations.length) + payload.pn_push = configurations; + } + if (!alert || !Object.keys(alert).length) + delete aps.alert; + if (this._isSilent) { + delete aps.alert; + delete aps.badge; + delete aps.sound; + alert = {}; + } + return this._isSilent || (alert && Object.keys(alert).length) ? payload : null; + } + /** + * Create PubNub push notification service APNS2 configuration information object. + * + * @param configuration - Source user-provided APNS2 configuration. + * + * @returns Preformatted for PubNub service APNS2 configuration information. + */ + objectFromAPNS2Configuration(configuration) { + if (!configuration.targets || !configuration.targets.length) + throw new ReferenceError('At least one APNS2 target should be provided'); + const { collapseId, expirationDate } = configuration; + const objectifiedConfiguration = { + auth_method: 'token', + targets: configuration.targets.map((target) => this.objectFromAPNSTarget(target)), + version: 'v2', + }; + if (collapseId && collapseId.length) + objectifiedConfiguration.collapse_id = collapseId; + if (expirationDate) + objectifiedConfiguration.expiration = expirationDate.toISOString(); + return objectifiedConfiguration; + } + /** + * Create PubNub push notification service APNS2 target information object. + * + * @param target - Source user-provided data. + * + * @returns Preformatted for PubNub service APNS2 target information. + */ + objectFromAPNSTarget(target) { + if (!target.topic || !target.topic.length) + throw new TypeError("Target 'topic' undefined."); + const { topic, environment = 'development', excludedDevices = [] } = target; + const objectifiedTarget = { topic, environment }; + if (excludedDevices.length) + objectifiedTarget.excluded_devices = excludedDevices; + return objectifiedTarget; + } + } + /** + * Message payload for Firebase Clouse Messaging service. + */ + class FCMNotificationPayload extends BaseNotificationPayload { + get payload() { + return this._payload; + } + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ + get notification() { + return this.payload.notification; + } + /** + * Silent notification payload. + * + * @returns Silent notification payload (data notification). + */ + get data() { + return this.payload.data; + } + /** + * Notification title. + * + * @returns Main notification title. + */ + get title() { + return this._title; + } + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value) { + if (!value || !value.length) + return; + this.payload.notification.title = value; + this._title = value; + } + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body() { + return this._body; + } + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value) { + if (!value || !value.length) + return; + this.payload.notification.body = value; + this._body = value; + } + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound() { + return this._sound; + } + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value) { + if (!value || !value.length) + return; + this.payload.notification.sound = value; + this._sound = value; + } + /** + * Retrieve notification icon file. + * + * @returns Notification icon file name from resource bundle. + */ + get icon() { + return this._icon; + } + /** + * Update notification icon. + * + * @param value - Name of the icon file which should be shown on notification. + */ + set icon(value) { + if (!value || !value.length) + return; + this.payload.notification.icon = value; + this._icon = value; + } + get tag() { + return this._tag; + } + set tag(value) { + if (!value || !value.length) + return; + this.payload.notification.tag = value; + this._tag = value; + } + /** + * Set whether notification should be silent or not. + * + * All notification data will be sent under `data` field if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ + set silent(value) { + this._isSilent = value; + } + setDefaultPayloadStructure() { + this.payload.notification = {}; + this.payload.data = {}; + } + toObject() { + let data = Object.assign({}, this.payload.data); + let notification = null; + const payload = {}; + // Check whether additional data has been passed outside 'data' object and put it into it if required. + if (Object.keys(this.payload).length > 2) { + const _a = this.payload, additionalData = __rest(_a, ["notification", "data"]); + data = Object.assign(Object.assign({}, data), additionalData); + } + if (this._isSilent) + data.notification = this.payload.notification; + else + notification = this.payload.notification; + if (Object.keys(data).length) + payload.data = data; + if (notification && Object.keys(notification).length) + payload.notification = notification; + return Object.keys(payload).length ? payload : null; + } + } + class NotificationsPayload { + constructor(title, body) { + this._payload = { apns: {}, fcm: {} }; + this._title = title; + this._body = body; + this.apns = new APNSNotificationPayload(this._payload.apns, title, body); + this.fcm = new FCMNotificationPayload(this._payload.fcm, title, body); + } + set debugging(value) { + this._debugging = value; + } + /** + * Notification title. + * + * @returns Main notification title. + */ + get title() { + return this._title; + } + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ + get subtitle() { + return this._subtitle; + } + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value) { + this._subtitle = value; + this.apns.subtitle = value; + this.fcm.subtitle = value; + } + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body() { + return this._body; + } + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ + get badge() { + return this._badge; + } + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value) { + this._badge = value; + this.apns.badge = value; + this.fcm.badge = value; + } + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound() { + return this._sound; + } + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value) { + this._sound = value; + this.apns.sound = value; + this.fcm.sound = value; + } + /** + * Build notifications platform for requested platforms. + * + * @param platforms - List of platforms for which payload should be added to final dictionary. Supported values: + * gcm, apns, and apns2. + * + * @returns Object with data, which can be sent with publish method call and trigger remote notifications for + * specified platforms. + */ + buildPayload(platforms) { + const payload = {}; + if (platforms.includes('apns') || platforms.includes('apns2')) { + // @ts-expect-error Override APNS version. + this.apns._apnsPushType = platforms.includes('apns') ? 'apns' : 'apns2'; + const apnsPayload = this.apns.toObject(); + if (apnsPayload && Object.keys(apnsPayload).length) + payload.pn_apns = apnsPayload; + } + if (platforms.includes('fcm')) { + const fcmPayload = this.fcm.toObject(); + if (fcmPayload && Object.keys(fcmPayload).length) + payload.pn_gcm = fcmPayload; + } + if (Object.keys(payload).length && this._debugging) + payload.pn_debug = true; + return payload; + } + } + + /** + * Base REST API request class. + */ + class AbstractRequest { + /** + * Construct base request. + * + * Constructed request by default won't be cancellable and performed using `GET` HTTP method. + * + * @param params - Request configuration parameters. + */ + constructor(params) { + this.params = params; + /** + * Unique request identifier. + */ + this.requestIdentifier = uuidGenerator.createUUID(); + this._cancellationController = null; + } + /** + * Retrieve configured cancellation controller. + * + * @returns Cancellation controller. + */ + get cancellationController() { + return this._cancellationController; + } + /** + * Update request cancellation controller. + * + * Controller itself provided by transport provider implementation and set only when request + * sending has been scheduled. + * + * @param controller - Cancellation controller or `null` to reset it. + */ + set cancellationController(controller) { + this._cancellationController = controller; + } + /** + * Abort request if possible. + */ + abort() { + if (this && this.cancellationController) + this.cancellationController.abort(); + } + /** + * Target REST API endpoint operation type. + */ + operation() { + throw Error('Should be implemented by subclass.'); + } + /** + * Validate user-provided data before scheduling request. + * + * @returns Error message if request can't be sent without missing or malformed parameters. + */ + validate() { + return undefined; + } + /** + * Parse service response. + * + * @param _response - Raw service response which should be parsed. + */ + parse(_response) { + return __awaiter(this, void 0, void 0, function* () { + throw Error('Should be implemented by subclass.'); + }); + } + /** + * Create platform-agnostic request object. + * + * @returns Request object which can be processed using platform-specific requirements. + */ + request() { + var _a, _b, _c, _d; + const request = { + method: (_b = (_a = this.params) === null || _a === void 0 ? void 0 : _a.method) !== null && _b !== void 0 ? _b : TransportMethod.GET, + path: this.path, + queryParameters: this.queryParameters, + cancellable: (_d = (_c = this.params) === null || _c === void 0 ? void 0 : _c.cancellable) !== null && _d !== void 0 ? _d : false, + timeout: 10000, + identifier: this.requestIdentifier, + }; + // Attach headers (if required). + const headers = this.headers; + if (headers) + request.headers = headers; + // Attach body (if required). + if (request.method === TransportMethod.POST || request.method === TransportMethod.PATCH) { + const [body, formData] = [this.body, this.formData]; + if (formData) + request.formData = formData; + if (body) + request.body = body; + } + return request; + } + /** + * Target REST API endpoint request headers getter. + * + * @returns Key/value headers which should be used with request. + */ + get headers() { + return undefined; + } + /** + * Target REST API endpoint request path getter. + * + * @returns REST API path. + */ + get path() { + throw Error('`path` getter should be implemented by subclass.'); + } + /** + * Target REST API endpoint request query parameters getter. + * + * @returns Key/value pairs which should be appended to the REST API path. + */ + get queryParameters() { + return {}; + } + get formData() { + return undefined; + } + /** + * Target REST API Request body payload getter. + * + * @returns Buffer of stringified data which should be sent with `POST` or `PATCH` request. + */ + get body() { + return undefined; + } + /** + * Deserialize service response. + * + * @param response - Transparent response object with headers and body information. + * + * @returns Deserialized data or `undefined` in case of `JSON.parse(..)` error. + */ + deserializeResponse(response) { + const contentType = response.headers['content-type']; + if (!contentType || (contentType.indexOf('javascript') === -1 && contentType.indexOf('json') === -1)) + return undefined; + const json = AbstractRequest.decoder.decode(response.body); + try { + const parsedJson = JSON.parse(json); + return parsedJson; + } + catch (error) { + console.error('Error parsing JSON response:', error); + return undefined; + } + } + } + /** + * Service `ArrayBuffer` response decoder. + */ + AbstractRequest.decoder = new TextDecoder(); + + /* */ + var RequestOperation; + (function (RequestOperation) { + // -------------------------------------------------------- + // ---------------------- Publish API --------------------- + // -------------------------------------------------------- + /** + * Data publish REST API operation. + */ + RequestOperation["PNPublishOperation"] = "PNPublishOperation"; + /** + * Signal sending REST API operation. + */ + RequestOperation["PNSignalOperation"] = "PNSignalOperation"; + // -------------------------------------------------------- + // --------------------- Subscribe API -------------------- + // -------------------------------------------------------- + /** + * Subscribe for real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `join` event. + */ + RequestOperation["PNSubscribeOperation"] = "PNSubscribeOperation"; + /** + * Unsubscribe from real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `leave` event. + */ + RequestOperation["PNUnsubscribeOperation"] = "PNUnsubscribeOperation"; + // -------------------------------------------------------- + // --------------------- Presence API --------------------- + // -------------------------------------------------------- + /** + * Fetch user's presence information REST API operation. + */ + RequestOperation["PNWhereNowOperation"] = "PNWhereNowOperation"; + /** + * Fetch channel's presence information REST API operation. + */ + RequestOperation["PNHereNowOperation"] = "PNHereNowOperation"; + /** + * Fetch global presence information REST API operation. + */ + RequestOperation["PNGlobalHereNowOperation"] = "PNGlobalHereNowOperation"; + /** + * Update user's information associated with specified channel REST API operation. + */ + RequestOperation["PNSetStateOperation"] = "PNSetStateOperation"; + /** + * Fetch user's information associated with the specified channel REST API operation. + */ + RequestOperation["PNGetStateOperation"] = "PNGetStateOperation"; + /** + * Announce presence on managed channels REST API operation. + */ + RequestOperation["PNHeartbeatOperation"] = "PNHeartbeatOperation"; + // -------------------------------------------------------- + // ----------------- Message Reaction API ----------------- + // -------------------------------------------------------- + /** + * Add a reaction to the specified message REST API operation. + */ + RequestOperation["PNAddMessageActionOperation"] = "PNAddActionOperation"; + /** + * Remove reaction from the specified message REST API operation. + */ + RequestOperation["PNRemoveMessageActionOperation"] = "PNRemoveMessageActionOperation"; + /** + * Fetch reactions for specific message REST API operation. + */ + RequestOperation["PNGetMessageActionsOperation"] = "PNGetMessageActionsOperation"; + RequestOperation["PNTimeOperation"] = "PNTimeOperation"; + // -------------------------------------------------------- + // ---------------------- Storage API --------------------- + // -------------------------------------------------------- + /** + * Channel history REST API operation. + */ + RequestOperation["PNHistoryOperation"] = "PNHistoryOperation"; + /** + * Delete messages from channel history REST API operation. + */ + RequestOperation["PNDeleteMessagesOperation"] = "PNDeleteMessagesOperation"; + /** + * History for channels REST API operation. + */ + RequestOperation["PNFetchMessagesOperation"] = "PNFetchMessagesOperation"; + /** + * Number of messages for channels in specified time frame REST API operation. + */ + RequestOperation["PNMessageCounts"] = "PNMessageCountsOperation"; + // -------------------------------------------------------- + // -------------------- App Context API ------------------- + // -------------------------------------------------------- + /** + * Fetch users metadata REST API operation. + */ + RequestOperation["PNGetAllUUIDMetadataOperation"] = "PNGetAllUUIDMetadataOperation"; + /** + * Fetch user metadata REST API operation. + */ + RequestOperation["PNGetUUIDMetadataOperation"] = "PNGetUUIDMetadataOperation"; + /** + * Set user metadata REST API operation. + */ + RequestOperation["PNSetUUIDMetadataOperation"] = "PNSetUUIDMetadataOperation"; + /** + * Remove user metadata REST API operation. + */ + RequestOperation["PNRemoveUUIDMetadataOperation"] = "PNRemoveUUIDMetadataOperation"; + /** + * Fetch channels metadata REST API operation. + */ + RequestOperation["PNGetAllChannelMetadataOperation"] = "PNGetAllChannelMetadataOperation"; + /** + * Fetch channel metadata REST API operation. + */ + RequestOperation["PNGetChannelMetadataOperation"] = "PNGetChannelMetadataOperation"; + /** + * Set channel metadata REST API operation. + */ + RequestOperation["PNSetChannelMetadataOperation"] = "PNSetChannelMetadataOperation"; + /** + * Remove channel metadata REST API operation. + */ + RequestOperation["PNRemoveChannelMetadataOperation"] = "PNRemoveChannelMetadataOperation"; + /** + * Fetch channel members REST API operation. + */ + RequestOperation["PNGetMembersOperation"] = "PNGetMembersOperation"; + /** + * Update channel members REST API operation. + */ + RequestOperation["PNSetMembersOperation"] = "PNSetMembersOperation"; + /** + * Fetch channel memberships REST API operation. + */ + RequestOperation["PNGetMembershipsOperation"] = "PNGetMembershipsOperation"; + /** + * Update channel memberships REST API operation. + */ + RequestOperation["PNSetMembershipsOperation"] = "PNSetMembershipsOperation"; + // -------------------------------------------------------- + // -------------------- File Upload API ------------------- + // -------------------------------------------------------- + /** + * Fetch list of files sent to the channel REST API operation. + */ + RequestOperation["PNListFilesOperation"] = "PNListFilesOperation"; + /** + * Retrieve file upload URL REST API operation. + */ + RequestOperation["PNGenerateUploadUrlOperation"] = "PNGenerateUploadUrlOperation"; + /** + * Upload file to the channel REST API operation. + */ + RequestOperation["PNPublishFileOperation"] = "PNPublishFileOperation"; + /** + * Publish File Message to the channel REST API operation. + */ + RequestOperation["PNPublishFileMessageOperation"] = "PNPublishFileMessageOperation"; + /** + * Retrieve file download URL REST API operation. + */ + RequestOperation["PNGetFileUrlOperation"] = "PNGetFileUrlOperation"; + /** + * Download file from the channel REST API operation. + */ + RequestOperation["PNDownloadFileOperation"] = "PNDownloadFileOperation"; + /** + * Delete file sent to the channel REST API operation. + */ + RequestOperation["PNDeleteFileOperation"] = "PNDeleteFileOperation"; + // -------------------------------------------------------- + // -------------------- Mobile Push API ------------------- + // -------------------------------------------------------- + /** + * Register channels with device push notifications REST API operation. + */ + RequestOperation["PNAddPushNotificationEnabledChannelsOperation"] = "PNAddPushNotificationEnabledChannelsOperation"; + /** + * Unregister channels with device push notifications REST API operation. + */ + RequestOperation["PNRemovePushNotificationEnabledChannelsOperation"] = "PNRemovePushNotificationEnabledChannelsOperation"; + /** + * Fetch list of channels with enabled push notifications for device REST API operation. + */ + RequestOperation["PNPushNotificationEnabledChannelsOperation"] = "PNPushNotificationEnabledChannelsOperation"; + /** + * Disable push notifications for device REST API operation. + */ + RequestOperation["PNRemoveAllPushNotificationsOperation"] = "PNRemoveAllPushNotificationsOperation"; + // -------------------------------------------------------- + // ------------------ Channel Groups API ------------------ + // -------------------------------------------------------- + /** + * Fetch channels groups list REST API operation. + */ + RequestOperation["PNChannelGroupsOperation"] = "PNChannelGroupsOperation"; + /** + * Remove specified channel group REST API operation. + */ + RequestOperation["PNRemoveGroupOperation"] = "PNRemoveGroupOperation"; + /** + * Fetch list of channels for the specified channel group REST API operation. + */ + RequestOperation["PNChannelsForGroupOperation"] = "PNChannelsForGroupOperation"; + /** + * Add list of channels to the specified channel group REST API operation. + */ + RequestOperation["PNAddChannelsToGroupOperation"] = "PNAddChannelsToGroupOperation"; + /** + * Remove list of channels from the specified channel group REST API operation. + */ + RequestOperation["PNRemoveChannelsFromGroupOperation"] = "PNRemoveChannelsFromGroupOperation"; + // -------------------------------------------------------- + // ----------------------- PAM API ------------------------ + // -------------------------------------------------------- + /** + * Generate authorized token REST API operation. + */ + RequestOperation["PNAccessManagerGrant"] = "PNAccessManagerGrant"; + /** + * Generate authorized token REST API operation. + */ + RequestOperation["PNAccessManagerGrantToken"] = "PNAccessManagerGrantToken"; + RequestOperation["PNAccessManagerAudit"] = "PNAccessManagerAudit"; + /** + * Revoke authorized token REST API operation. + */ + RequestOperation["PNAccessManagerRevokeToken"] = "PNAccessManagerRevokeToken"; + // + // -------------------------------------------------------- + // ---------------- Subscription Utility ------------------ + // -------------------------------------------------------- + RequestOperation["PNHandshakeOperation"] = "PNHandshakeOperation"; + RequestOperation["PNReceiveMessagesOperation"] = "PNReceiveMessagesOperation"; + })(RequestOperation || (RequestOperation = {})); + var RequestOperation$1 = RequestOperation; + + /** + * Subscription REST API module. + */ + // -------------------------------------------------------- + // ---------------------- Defaults ------------------------ + // -------------------------------------------------------- + // region Defaults + /** + * Whether should subscribe to channels / groups presence announcements or not. + */ + const WITH_PRESENCE = false; + // endregion + // -------------------------------------------------------- + // ------------------------ Types ------------------------- + // -------------------------------------------------------- + // region Types + /** + * PubNub-defined event types by payload. + */ + var PubNubEventType; + (function (PubNubEventType) { + /** + * Presence change event. + */ + PubNubEventType[PubNubEventType["Presence"] = -2] = "Presence"; + /** + * Regular message event. + * + * **Note:** This is default type assigned for non-presence events if `e` field is missing. + */ + PubNubEventType[PubNubEventType["Message"] = -1] = "Message"; + /** + * Signal data event. + */ + PubNubEventType[PubNubEventType["Signal"] = 1] = "Signal"; + /** + * App Context object event. + */ + PubNubEventType[PubNubEventType["AppContext"] = 2] = "AppContext"; + /** + * Message reaction event. + */ + PubNubEventType[PubNubEventType["MessageAction"] = 3] = "MessageAction"; + /** + * Files event. + */ + PubNubEventType[PubNubEventType["Files"] = 4] = "Files"; + })(PubNubEventType || (PubNubEventType = {})); + // endregion + /** + * Base subscription request implementation. + * + * Subscription request used in small variations in two cases: + * - subscription manager + * - event engine + */ + class BaseSubscribeRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c; + var _d, _e, _f; + super({ cancellable: true }); + this.parameters = parameters; + // Apply default request parameters. + (_a = (_d = this.parameters).withPresence) !== null && _a !== void 0 ? _a : (_d.withPresence = WITH_PRESENCE); + (_b = (_e = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_e.channelGroups = []); + (_c = (_f = this.parameters).channels) !== null && _c !== void 0 ? _c : (_f.channels = []); + } + operation() { + return RequestOperation$1.PNSubscribeOperation; + } + validate() { + const { keySet: { subscribeKey }, channels, channelGroups, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channels && !channelGroups) + return '`channels` and `channelGroups` both should not be empty'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + let serviceResponse; + try { + const json = AbstractRequest.decoder.decode(response.body); + const parsedJson = JSON.parse(json); + serviceResponse = parsedJson; + } + catch (error) { + console.error('Error parsing JSON response:', error); + } + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + const events = serviceResponse.m.map((envelope) => { + let { e: eventType } = envelope; + // Resolve missing event type. + eventType !== null && eventType !== void 0 ? eventType : (eventType = envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message); + // Check whether payload is string (potentially encrypted data). + if (typeof envelope.d === 'string') { + if (eventType == PubNubEventType.Message) { + return { + type: PubNubEventType.Message, + data: this.messageFromEnvelope(envelope), + }; + } + return { + type: PubNubEventType.Files, + data: this.fileFromEnvelope(envelope), + }; + } + else if (eventType == PubNubEventType.Message) { + return { + type: PubNubEventType.Message, + data: this.messageFromEnvelope(envelope), + }; + } + else if (eventType === PubNubEventType.Presence) { + return { + type: PubNubEventType.Presence, + data: this.presenceEventFromEnvelope(envelope), + }; + } + else if (eventType == PubNubEventType.Signal) { + return { + type: PubNubEventType.Signal, + data: this.signalFromEnvelope(envelope), + }; + } + else if (eventType === PubNubEventType.AppContext) { + return { + type: PubNubEventType.AppContext, + data: this.appContextFromEnvelope(envelope), + }; + } + else if (eventType === PubNubEventType.MessageAction) { + return { + type: PubNubEventType.MessageAction, + data: this.messageActionFromEnvelope(envelope), + }; + } + return { + type: PubNubEventType.Files, + data: this.fileFromEnvelope(envelope), + }; + }); + return { + cursor: { timetoken: serviceResponse.t.t, region: serviceResponse.t.r }, + messages: events, + }; + }); + } + get headers() { + return { accept: 'text/javascript' }; + } + // -------------------------------------------------------- + // ------------------ Envelope parsing -------------------- + // -------------------------------------------------------- + // region Envelope parsing + presenceEventFromEnvelope(envelope) { + const { d: payload } = envelope; + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + // Clean up channel and subscription name from presence suffix. + const trimmedChannel = channel.replace('-pnpres', ''); + // Backward compatibility with deprecated properties. + const actualChannel = subscription !== null ? trimmedChannel : null; + const subscribedChannel = subscription !== null ? subscription : trimmedChannel; + if (typeof payload !== 'string' && 'data' in payload) { + // @ts-expect-error This is `state-change` object which should have `state` field. + payload['state'] = payload.data; + delete payload.data; + } + return Object.assign({ channel: trimmedChannel, subscription, + actualChannel, + subscribedChannel, timetoken: envelope.p.t }, payload); + } + messageFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const [message, decryptionError] = this.decryptedData(envelope.d); + // Backward compatibility with deprecated properties. + const actualChannel = subscription !== null ? channel : null; + const subscribedChannel = subscription !== null ? subscription : channel; + // Basic message event payload. + const event = { + channel, + subscription, + actualChannel, + subscribedChannel, + timetoken: envelope.p.t, + publisher: envelope.i, + message, + }; + if (envelope.u) + event.userMetadata = envelope.u; + if (decryptionError) + event.error = decryptionError; + return event; + } + signalFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const event = { + channel, + subscription, + timetoken: envelope.p.t, + publisher: envelope.i, + message: envelope.d, + }; + if (envelope.u) + event.userMetadata = envelope.u; + return event; + } + messageActionFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const action = envelope.d; + return { + channel, + subscription, + timetoken: envelope.p.t, + publisher: envelope.i, + event: action.event, + data: Object.assign(Object.assign({}, action.data), { uuid: envelope.i }), + }; + } + appContextFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const object = envelope.d; + return { + channel, + subscription, + timetoken: envelope.p.t, + message: object, + }; + } + fileFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const [file, decryptionError] = this.decryptedData(envelope.d); + let errorMessage = decryptionError; + // Basic file event payload. + const event = { + channel, + subscription, + timetoken: envelope.p.t, + publisher: envelope.i, + }; + if (envelope.u) + event.userMetadata = envelope.u; + if (!file) + errorMessage !== null && errorMessage !== void 0 ? errorMessage : (errorMessage = `File information payload is missing.`); + else if (typeof file === 'string') + errorMessage !== null && errorMessage !== void 0 ? errorMessage : (errorMessage = `Unexpected file information payload data type.`); + else { + event.message = file.message; + if (file.file) { + event.file = { + id: file.file.id, + name: file.file.name, + url: this.parameters.getFileUrl({ id: file.file.id, name: file.file.name, channel }), + }; + } + } + if (errorMessage) + event.error = errorMessage; + return event; + } + // endregion + subscriptionChannelFromEnvelope(envelope) { + return [envelope.c, envelope.b === undefined ? envelope.c : envelope.b]; + } + /** + * Decrypt provided `data`. + * + * @param [data] - Message or file information which should be decrypted if possible. + * + * @returns Tuple with decrypted data and decryption error (if any). + */ + decryptedData(data) { + if (!this.parameters.crypto || typeof data !== 'string') + return [data, undefined]; + let payload; + let error; + try { + const decryptedData = this.parameters.crypto.decrypt(data); + payload = + decryptedData instanceof ArrayBuffer + ? JSON.parse(SubscribeRequest.decoder.decode(decryptedData)) + : decryptedData; + } + catch (err) { + payload = null; + error = `Error while decrypting message content: ${err.message}`; + } + return [(payload !== null && payload !== void 0 ? payload : data), error]; + } + } + /** + * Subscribe request. + */ + class SubscribeRequest extends BaseSubscribeRequest { + get path() { + var _a; + const { keySet: { subscribeKey }, channels, } = this.parameters; + return `/v2/subscribe/${subscribeKey}/${encodeNames((_a = channels === null || channels === void 0 ? void 0 : channels.sort()) !== null && _a !== void 0 ? _a : [], ',')}/0`; + } + get queryParameters() { + const { channelGroups, filterExpression, heartbeat, state, timetoken, region } = this.parameters; + const query = {}; + if (channelGroups && channelGroups.length > 0) + query['channel-group'] = channelGroups.sort().join(','); + if (filterExpression && filterExpression.length > 0) + query['filter-expr'] = filterExpression; + if (heartbeat) + query.heartbeat = heartbeat; + if (state && Object.keys(state).length > 0) + query['state'] = JSON.stringify(state); + if (timetoken !== undefined && typeof timetoken === 'string') { + if (timetoken.length > 0 && timetoken !== '0') + query['tt'] = timetoken; + } + else if (timetoken !== undefined && timetoken > 0) + query['tt'] = timetoken; + if (region) + query['tr'] = region; + return query; + } + } + + class EventEmitter { + constructor(listenerManager) { + this.listenerManager = listenerManager; + /** + * Map of channels to listener callbacks for them. + */ + this.channelListenerMap = new Map(); + /** + * Map of channel group names to the listener callbacks for them. + */ + this.groupListenerMap = new Map(); + } + /** + * Emit specific real-time event. + * + * Proper listener will be notified basing on event `type`. + * + * @param event - Received real-time event. + */ + emitEvent(event) { + if (event.type === PubNubEventType.Message) { + this.listenerManager.announceMessage(event.data); + this.announce('message', event.data, event.data.channel, event.data.subscription); + } + else if (event.type === PubNubEventType.Signal) { + this.listenerManager.announceSignal(event.data); + this.announce('signal', event.data, event.data.channel, event.data.subscription); + } + else if (event.type === PubNubEventType.Presence) { + this.listenerManager.announcePresence(event.data); + this.announce('presence', event.data, event.data.channel, event.data.subscription); + } + else if (event.type === PubNubEventType.AppContext) { + const { data: objectEvent } = event; + const { message: object } = objectEvent; + this.listenerManager.announceObjects(objectEvent); + this.announce('objects', objectEvent, objectEvent.channel, objectEvent.subscription); + if (object.type === 'uuid') { + const { message, channel } = objectEvent, restEvent = __rest(objectEvent, ["message", "channel"]); + const { event, type } = object, restObject = __rest(object, ["event", "type"]); + const userEvent = Object.assign(Object.assign({}, restEvent), { spaceId: channel, message: Object.assign(Object.assign({}, restObject), { event: event === 'set' ? 'updated' : 'removed', type: 'user' }) }); + this.listenerManager.announceUser(userEvent); + this.announce('user', userEvent, userEvent.spaceId, userEvent.subscription); + } + else if (object.type === 'channel') { + const { message, channel } = objectEvent, restEvent = __rest(objectEvent, ["message", "channel"]); + const { event, type } = object, restObject = __rest(object, ["event", "type"]); + const spaceEvent = Object.assign(Object.assign({}, restEvent), { spaceId: channel, message: Object.assign(Object.assign({}, restObject), { event: event === 'set' ? 'updated' : 'removed', type: 'space' }) }); + this.listenerManager.announceSpace(spaceEvent); + this.announce('space', spaceEvent, spaceEvent.spaceId, spaceEvent.subscription); + } + else if (object.type === 'membership') { + const { message, channel } = objectEvent, restEvent = __rest(objectEvent, ["message", "channel"]); + const { event, data } = object, restObject = __rest(object, ["event", "data"]); + const { uuid, channel: channelMeta } = data, restData = __rest(data, ["uuid", "channel"]); + const membershipEvent = Object.assign(Object.assign({}, restEvent), { spaceId: channel, message: Object.assign(Object.assign({}, restObject), { event: event === 'set' ? 'updated' : 'removed', data: Object.assign(Object.assign({}, restData), { user: uuid, space: channelMeta }) }) }); + this.listenerManager.announceMembership(membershipEvent); + this.announce('membership', membershipEvent, membershipEvent.spaceId, membershipEvent.subscription); + } + } + else if (event.type === PubNubEventType.MessageAction) { + this.listenerManager.announceMessageAction(event.data); + this.announce('messageAction', event.data, event.data.channel, event.data.subscription); + } + else if (event.type === PubNubEventType.Files) { + this.listenerManager.announceFile(event.data); + this.announce('file', event.data, event.data.channel, event.data.subscription); + } + } + /** + * Register real-time event listener for specific channels and groups. + * + * @param listener - Listener with event callbacks to handle different types of events. + * @param channels - List of channels for which listener should be registered. + * @param groups - List of channel groups for which listener should be registered. + */ + addListener(listener, channels, groups) { + // Register event-listener listener globally. + if (!(channels && groups)) { + this.listenerManager.addListener(listener); + } + else { + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + if (this.channelListenerMap.has(channel)) { + const channelListeners = this.channelListenerMap.get(channel); + if (!channelListeners.includes(listener)) + channelListeners.push(listener); + } + else + this.channelListenerMap.set(channel, [listener]); + }); + groups === null || groups === void 0 ? void 0 : groups.forEach((group) => { + if (this.groupListenerMap.has(group)) { + const groupListeners = this.groupListenerMap.get(group); + if (!groupListeners.includes(listener)) + groupListeners.push(listener); + } + else + this.groupListenerMap.set(group, [listener]); + }); + } + } + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + * @param channels - List of channels for which listener should be removed. + * @param groups - List of channel groups for which listener should be removed. + */ + removeListener(listener, channels, groups) { + if (!(channels && groups)) { + this.listenerManager.removeListener(listener); + } + else { + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + if (this.channelListenerMap.has(channel)) { + this.channelListenerMap.set(channel, this.channelListenerMap.get(channel).filter((channelListener) => channelListener !== listener)); + } + }); + groups === null || groups === void 0 ? void 0 : groups.forEach((group) => { + if (this.groupListenerMap.has(group)) { + this.groupListenerMap.set(group, this.groupListenerMap.get(group).filter((groupListener) => groupListener !== listener)); + } + }); + } + } + /** + * Clear all real-time event listeners. + */ + removeAllListeners() { + this.listenerManager.removeAllListeners(); + this.channelListenerMap.clear(); + this.groupListenerMap.clear(); + } + /** + * Announce real-time event to all listeners. + * + * @param type - Type of event which should be announced. + * @param event - Announced real-time event payload. + * @param channel - Name of the channel for which registered listeners should be notified. + * @param group - Name of the channel group for which registered listeners should be notified. + */ + announce(type, event, channel, group) { + if (event && this.channelListenerMap.has(channel)) + this.channelListenerMap.get(channel).forEach((listener) => { + const typedListener = listener[type]; + // @ts-expect-error Dynamic events mapping. + if (typedListener) + typedListener(event); + }); + if (group && this.groupListenerMap.has(group)) + this.groupListenerMap.get(group).forEach((listener) => { + const typedListener = listener[type]; + // @ts-expect-error Dynamic events mapping. + if (typedListener) + typedListener(event); + }); + } + } + + class Subject { + constructor(sync = false) { + this.sync = sync; + this.listeners = new Set(); + } + subscribe(listener) { + this.listeners.add(listener); + return () => { + this.listeners.delete(listener); + }; + } + notify(event) { + const wrapper = () => { + this.listeners.forEach((listener) => { + listener(event); + }); + }; + if (this.sync) { + wrapper(); + } + else { + setTimeout(wrapper, 0); + } + } + } + + /* eslint-disable @typescript-eslint/no-explicit-any */ + class State { + transition(context, event) { + var _a; + if (this.transitionMap.has(event.type)) { + return (_a = this.transitionMap.get(event.type)) === null || _a === void 0 ? void 0 : _a(context, event); + } + return undefined; + } + constructor(label) { + this.label = label; + this.transitionMap = new Map(); + this.enterEffects = []; + this.exitEffects = []; + } + on(eventType, transition) { + this.transitionMap.set(eventType, transition); + return this; + } + with(context, effects) { + return [this, context, effects !== null && effects !== void 0 ? effects : []]; + } + onEnter(effect) { + this.enterEffects.push(effect); + return this; + } + onExit(effect) { + this.exitEffects.push(effect); + return this; + } + } + + /* eslint-disable @typescript-eslint/no-explicit-any */ + class Engine extends Subject { + describe(label) { + return new State(label); + } + start(initialState, initialContext) { + this.currentState = initialState; + this.currentContext = initialContext; + this.notify({ + type: 'engineStarted', + state: initialState, + context: initialContext, + }); + return; + } + transition(event) { + if (!this.currentState) { + throw new Error('Start the engine first'); + } + this.notify({ + type: 'eventReceived', + event: event, + }); + const transition = this.currentState.transition(this.currentContext, event); + if (transition) { + const [newState, newContext, effects] = transition; + for (const effect of this.currentState.exitEffects) { + this.notify({ + type: 'invocationDispatched', + invocation: effect(this.currentContext), + }); + } + const oldState = this.currentState; + this.currentState = newState; + const oldContext = this.currentContext; + this.currentContext = newContext; + this.notify({ + type: 'transitionDone', + fromState: oldState, + fromContext: oldContext, + toState: newState, + toContext: newContext, + event: event, + }); + for (const effect of effects) { + this.notify({ + type: 'invocationDispatched', + invocation: effect, + }); + } + for (const effect of this.currentState.enterEffects) { + this.notify({ + type: 'invocationDispatched', + invocation: effect(this.currentContext), + }); + } + } + } + } + + /* eslint-disable @typescript-eslint/no-explicit-any */ + class Dispatcher { + constructor(dependencies) { + this.dependencies = dependencies; + this.instances = new Map(); + this.handlers = new Map(); + } + on(type, handlerCreator) { + this.handlers.set(type, handlerCreator); + } + dispatch(invocation) { + if (invocation.type === 'CANCEL') { + if (this.instances.has(invocation.payload)) { + const instance = this.instances.get(invocation.payload); + instance === null || instance === void 0 ? void 0 : instance.cancel(); + this.instances.delete(invocation.payload); + } + return; + } + const handlerCreator = this.handlers.get(invocation.type); + if (!handlerCreator) { + throw new Error(`Unhandled invocation '${invocation.type}'`); + } + const instance = handlerCreator(invocation.payload, this.dependencies); + if (invocation.managed) { + this.instances.set(invocation.type, instance); + } + instance.start(); + } + dispose() { + for (const [key, instance] of this.instances.entries()) { + instance.cancel(); + this.instances.delete(key); + } + } + } + + /* eslint-disable @typescript-eslint/no-explicit-any */ + function createEvent(type, fn) { + const creator = function (...args) { + return { + type, + payload: fn === null || fn === void 0 ? void 0 : fn(...args), + }; + }; + creator.type = type; + return creator; + } + function createEffect(type, fn) { + const creator = (...args) => { + return { type, payload: fn(...args), managed: false }; + }; + creator.type = type; + return creator; + } + function createManagedEffect(type, fn) { + const creator = (...args) => { + return { type, payload: fn(...args), managed: true }; + }; + creator.type = type; + creator.cancel = { type: 'CANCEL', payload: type, managed: false }; + return creator; + } + + class AbortError extends Error { + constructor() { + super('The operation was aborted.'); + this.name = 'AbortError'; + Object.setPrototypeOf(this, new.target.prototype); + } + } + class AbortSignal extends Subject { + constructor() { + super(...arguments); + this._aborted = false; + } + get aborted() { + return this._aborted; + } + throwIfAborted() { + if (this._aborted) { + throw new AbortError(); + } + } + abort() { + this._aborted = true; + this.notify(new AbortError()); + } + } + + class Handler { + constructor(payload, dependencies) { + this.payload = payload; + this.dependencies = dependencies; + } + } + class AsyncHandler extends Handler { + constructor(payload, dependencies, asyncFunction) { + super(payload, dependencies); + this.asyncFunction = asyncFunction; + this.abortSignal = new AbortSignal(); + } + start() { + this.asyncFunction(this.payload, this.abortSignal, this.dependencies).catch((error) => { + // console.log('Unhandled error:', error); + // swallow the error + }); + } + cancel() { + this.abortSignal.abort(); + } + } + const asyncHandler = (handlerFunction) => (payload, dependencies) => new AsyncHandler(payload, dependencies, handlerFunction); + + const reconnect$1 = createEvent('RECONNECT', () => ({})); + const disconnect$1 = createEvent('DISCONNECT', () => ({})); + const joined = createEvent('JOINED', (channels, groups) => ({ + channels, + groups, + })); + const left = createEvent('LEFT', (channels, groups) => ({ + channels, + groups, + })); + const leftAll = createEvent('LEFT_ALL', () => ({})); + const heartbeatSuccess = createEvent('HEARTBEAT_SUCCESS', (statusCode) => ({ statusCode })); + const heartbeatFailure = createEvent('HEARTBEAT_FAILURE', (error) => error); + const heartbeatGiveup = createEvent('HEARTBEAT_GIVEUP', () => ({})); + const timesUp = createEvent('TIMES_UP', () => ({})); + + const heartbeat = createEffect('HEARTBEAT', (channels, groups) => ({ + channels, + groups, + })); + const leave = createEffect('LEAVE', (channels, groups) => ({ + channels, + groups, + })); + /* eslint-disable @typescript-eslint/no-explicit-any */ + const emitStatus$1 = createEffect('EMIT_STATUS', (status) => status); + const wait = createManagedEffect('WAIT', () => ({})); + const delayedHeartbeat = createManagedEffect('DELAYED_HEARTBEAT', (context) => context); + + class PresenceEventEngineDispatcher extends Dispatcher { + constructor(engine, dependencies) { + super(dependencies); + this.on(heartbeat.type, asyncHandler((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { heartbeat, presenceState, config }) { + try { + const result = yield heartbeat(Object.assign(Object.assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })), { heartbeat: config.presenceTimeout })); + engine.transition(heartbeatSuccess(200)); + } + catch (e) { + if (e instanceof PubNubError) { + if (e.status && e.status.category == StatusCategory$1.PNCancelledCategory) + return; + return engine.transition(heartbeatFailure(e)); + } + } + }))); + this.on(leave.type, asyncHandler((payload_2, _2, _b) => __awaiter(this, [payload_2, _2, _b], void 0, function* (payload, _, { leave, config }) { + if (!config.suppressLeaveEvents) { + try { + leave({ + channels: payload.channels, + channelGroups: payload.groups, + }); + } + catch (e) { } + } + }))); + this.on(wait.type, asyncHandler((_3, abortSignal_1, _c) => __awaiter(this, [_3, abortSignal_1, _c], void 0, function* (_, abortSignal, { heartbeatDelay }) { + abortSignal.throwIfAborted(); + yield heartbeatDelay(); + abortSignal.throwIfAborted(); + return engine.transition(timesUp()); + }))); + this.on(delayedHeartbeat.type, asyncHandler((payload_3, abortSignal_2, _d) => __awaiter(this, [payload_3, abortSignal_2, _d], void 0, function* (payload, abortSignal, { heartbeat, retryDelay, presenceState, config }) { + if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { + abortSignal.throwIfAborted(); + yield retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); + abortSignal.throwIfAborted(); + try { + const result = yield heartbeat(Object.assign(Object.assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })), { heartbeat: config.presenceTimeout })); + return engine.transition(heartbeatSuccess(200)); + } + catch (e) { + if (e instanceof PubNubError) { + if (e.status && e.status.category == StatusCategory$1.PNCancelledCategory) + return; + return engine.transition(heartbeatFailure(e)); + } + } + } + else { + return engine.transition(heartbeatGiveup()); + } + }))); + this.on(emitStatus$1.type, asyncHandler((payload_4, _4, _e) => __awaiter(this, [payload_4, _4, _e], void 0, function* (payload, _, { emitStatus, config }) { + var _f; + if (config.announceFailedHeartbeats && ((_f = payload === null || payload === void 0 ? void 0 : payload.status) === null || _f === void 0 ? void 0 : _f.error) === true) { + emitStatus(payload.status); + } + else if (config.announceSuccessfulHeartbeats && payload.statusCode === 200) { + emitStatus(Object.assign(Object.assign({}, payload), { operation: RequestOperation$1.PNHeartbeatOperation, error: false })); + } + }))); + } + } + + const HeartbeatStoppedState = new State('HEARTBEAT_STOPPED'); + HeartbeatStoppedState.on(joined.type, (context, event) => HeartbeatStoppedState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], + })); + HeartbeatStoppedState.on(left.type, (context, event) => HeartbeatStoppedState.with({ + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), + })); + HeartbeatStoppedState.on(reconnect$1.type, (context, _) => HeartbeatingState.with({ + channels: context.channels, + groups: context.groups, + })); + HeartbeatStoppedState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined)); + + const HeartbeatCooldownState = new State('HEARTBEAT_COOLDOWN'); + HeartbeatCooldownState.onEnter(() => wait()); + HeartbeatCooldownState.onExit(() => wait.cancel); + HeartbeatCooldownState.on(timesUp.type, (context, _) => HeartbeatingState.with({ + channels: context.channels, + groups: context.groups, + })); + HeartbeatCooldownState.on(joined.type, (context, event) => HeartbeatingState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], + })); + HeartbeatCooldownState.on(left.type, (context, event) => HeartbeatingState.with({ + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), + }, [leave(event.payload.channels, event.payload.groups)])); + HeartbeatCooldownState.on(disconnect$1.type, (context) => HeartbeatStoppedState.with({ + channels: context.channels, + groups: context.groups, + }, [leave(context.channels, context.groups)])); + HeartbeatCooldownState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + + const HeartbeatFailedState = new State('HEARTBEAT_FAILED'); + HeartbeatFailedState.on(joined.type, (context, event) => HeartbeatingState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], + })); + HeartbeatFailedState.on(left.type, (context, event) => HeartbeatingState.with({ + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), + }, [leave(event.payload.channels, event.payload.groups)])); + HeartbeatFailedState.on(reconnect$1.type, (context, _) => HeartbeatingState.with({ + channels: context.channels, + groups: context.groups, + })); + HeartbeatFailedState.on(disconnect$1.type, (context, _) => HeartbeatStoppedState.with({ + channels: context.channels, + groups: context.groups, + }, [leave(context.channels, context.groups)])); + HeartbeatFailedState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + + const HearbeatReconnectingState = new State('HEARBEAT_RECONNECTING'); + HearbeatReconnectingState.onEnter((context) => delayedHeartbeat(context)); + HearbeatReconnectingState.onExit(() => delayedHeartbeat.cancel); + HearbeatReconnectingState.on(joined.type, (context, event) => HeartbeatingState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], + })); + HearbeatReconnectingState.on(left.type, (context, event) => HeartbeatingState.with({ + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), + }, [leave(event.payload.channels, event.payload.groups)])); + HearbeatReconnectingState.on(disconnect$1.type, (context, _) => { + HeartbeatStoppedState.with({ + channels: context.channels, + groups: context.groups, + }, [leave(context.channels, context.groups)]); + }); + HearbeatReconnectingState.on(heartbeatSuccess.type, (context, event) => { + return HeartbeatCooldownState.with({ + channels: context.channels, + groups: context.groups, + }); + }); + HearbeatReconnectingState.on(heartbeatFailure.type, (context, event) => HearbeatReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); + HearbeatReconnectingState.on(heartbeatGiveup.type, (context, event) => { + return HeartbeatFailedState.with({ + channels: context.channels, + groups: context.groups, + }); + }); + HearbeatReconnectingState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + + const HeartbeatingState = new State('HEARTBEATING'); + HeartbeatingState.onEnter((context) => heartbeat(context.channels, context.groups)); + HeartbeatingState.on(heartbeatSuccess.type, (context, event) => { + return HeartbeatCooldownState.with({ + channels: context.channels, + groups: context.groups, + }); + }); + HeartbeatingState.on(joined.type, (context, event) => HeartbeatingState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], + })); + HeartbeatingState.on(left.type, (context, event) => { + return HeartbeatingState.with({ + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), + }, [leave(event.payload.channels, event.payload.groups)]); + }); + HeartbeatingState.on(heartbeatFailure.type, (context, event) => { + return HearbeatReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: 0, reason: event.payload })); + }); + HeartbeatingState.on(disconnect$1.type, (context) => HeartbeatStoppedState.with({ + channels: context.channels, + groups: context.groups, + }, [leave(context.channels, context.groups)])); + HeartbeatingState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + + const HeartbeatInactiveState = new State('HEARTBEAT_INACTIVE'); + HeartbeatInactiveState.on(joined.type, (_, event) => HeartbeatingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + })); + + class PresenceEventEngine { + get _engine() { + return this.engine; + } + constructor(dependencies) { + this.dependencies = dependencies; + this.engine = new Engine(); + this.channels = []; + this.groups = []; + this.dispatcher = new PresenceEventEngineDispatcher(this.engine, dependencies); + this._unsubscribeEngine = this.engine.subscribe((change) => { + if (change.type === 'invocationDispatched') { + this.dispatcher.dispatch(change.invocation); + } + }); + this.engine.start(HeartbeatInactiveState, undefined); + } + join({ channels, groups }) { + this.channels = [...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])]; + this.groups = [...this.groups, ...(groups !== null && groups !== void 0 ? groups : [])]; + this.engine.transition(joined(this.channels.slice(0), this.groups.slice(0))); + } + leave({ channels, groups }) { + if (this.dependencies.presenceState) { + channels === null || channels === void 0 ? void 0 : channels.forEach((c) => delete this.dependencies.presenceState[c]); + groups === null || groups === void 0 ? void 0 : groups.forEach((g) => delete this.dependencies.presenceState[g]); + } + this.engine.transition(left(channels !== null && channels !== void 0 ? channels : [], groups !== null && groups !== void 0 ? groups : [])); + } + leaveAll() { + this.engine.transition(leftAll()); + } + dispose() { + this._unsubscribeEngine(); + this.dispatcher.dispose(); + } + } + + class RetryPolicy { + static LinearRetryPolicy(configuration) { + return { + delay: configuration.delay, + maximumRetry: configuration.maximumRetry, + /* eslint-disable @typescript-eslint/no-explicit-any */ + shouldRetry(error, attempt) { + var _a; + if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { + return false; + } + return this.maximumRetry > attempt; + }, + getDelay(_, reason) { + var _a; + const delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : this.delay; + return (delay + Math.random()) * 1000; + }, + /* eslint-disable @typescript-eslint/no-explicit-any */ + getGiveupReason(error, attempt) { + var _a; + if (this.maximumRetry <= attempt) { + return 'retry attempts exhaused.'; + } + if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { + return 'forbidden operation.'; + } + return 'unknown error'; + }, + validate() { + if (this.maximumRetry > 10) + throw new Error('Maximum retry for linear retry policy can not be more than 10'); + }, + }; + } + static ExponentialRetryPolicy(configuration) { + return { + minimumDelay: configuration.minimumDelay, + maximumDelay: configuration.maximumDelay, + maximumRetry: configuration.maximumRetry, + shouldRetry(reason, attempt) { + var _a; + if (((_a = reason === null || reason === void 0 ? void 0 : reason.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { + return false; + } + return this.maximumRetry > attempt; + }, + getDelay(attempt, reason) { + var _a; + const delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : Math.min(Math.pow(2, attempt), this.maximumDelay); + return (delay + Math.random()) * 1000; + }, + getGiveupReason(reason, attempt) { + var _a; + if (this.maximumRetry <= attempt) { + return 'retry attempts exhausted.'; + } + if (((_a = reason === null || reason === void 0 ? void 0 : reason.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { + return 'forbidden operation.'; + } + return 'unknown error'; + }, + validate() { + if (this.minimumDelay < 2) + throw new Error('Minimum delay can not be set less than 2 seconds for retry'); + else if (this.maximumDelay) + throw new Error('Maximum delay can not be set more than 150 seconds for retry'); + else if (this.maximumRetry > 6) + throw new Error('Maximum retry for exponential retry policy can not be more than 6'); + }, + }; + } + } + + const handshake = createManagedEffect('HANDSHAKE', (channels, groups) => ({ + channels, + groups, + })); + const receiveMessages = createManagedEffect('RECEIVE_MESSAGES', (channels, groups, cursor) => ({ channels, groups, cursor })); + const emitMessages = createEffect('EMIT_MESSAGES', (events) => events); + const emitStatus = createEffect('EMIT_STATUS', (status) => status); + const receiveReconnect = createManagedEffect('RECEIVE_RECONNECT', (context) => context); + const handshakeReconnect = createManagedEffect('HANDSHAKE_RECONNECT', (context) => context); + + const subscriptionChange = createEvent('SUBSCRIPTION_CHANGED', (channels, groups) => ({ + channels, + groups, + })); + const restore = createEvent('SUBSCRIPTION_RESTORED', (channels, groups, timetoken, region) => ({ + channels, + groups, + cursor: { + timetoken: timetoken, + region: region !== null && region !== void 0 ? region : 0, + }, + })); + const handshakeSuccess = createEvent('HANDSHAKE_SUCCESS', (cursor) => cursor); + const handshakeFailure = createEvent('HANDSHAKE_FAILURE', (error) => error); + const handshakeReconnectSuccess = createEvent('HANDSHAKE_RECONNECT_SUCCESS', (cursor) => ({ + cursor, + })); + const handshakeReconnectFailure = createEvent('HANDSHAKE_RECONNECT_FAILURE', (error) => error); + const handshakeReconnectGiveup = createEvent('HANDSHAKE_RECONNECT_GIVEUP', (error) => error); + const receiveSuccess = createEvent('RECEIVE_SUCCESS', (cursor, events) => ({ + cursor, + events, + })); + const receiveFailure = createEvent('RECEIVE_FAILURE', (error) => error); + const receiveReconnectSuccess = createEvent('RECEIVE_RECONNECT_SUCCESS', (cursor, events) => ({ + cursor, + events, + })); + const receiveReconnectFailure = createEvent('RECEIVE_RECONNECT_FAILURE', (error) => error); + const receiveReconnectGiveup = createEvent('RECEIVING_RECONNECT_GIVEUP', (error) => error); + const disconnect = createEvent('DISCONNECT', () => ({})); + const reconnect = createEvent('RECONNECT', (timetoken, region) => ({ + cursor: { + timetoken: timetoken !== null && timetoken !== void 0 ? timetoken : '', + region: region !== null && region !== void 0 ? region : 0, + }, + })); + const unsubscribeAll = createEvent('UNSUBSCRIBE_ALL', () => ({})); + + class EventEngineDispatcher extends Dispatcher { + constructor(engine, dependencies) { + super(dependencies); + this.on(handshake.type, asyncHandler((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { handshake, presenceState, config }) { + abortSignal.throwIfAborted(); + try { + const result = yield handshake(Object.assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState }))); + return engine.transition(handshakeSuccess(result)); + } + catch (e) { + if (e instanceof PubNubError) { + if (e.status && e.status.category == StatusCategory$1.PNCancelledCategory) + return; + return engine.transition(handshakeFailure(e)); + } + } + }))); + this.on(receiveMessages.type, asyncHandler((payload_2, abortSignal_2, _b) => __awaiter(this, [payload_2, abortSignal_2, _b], void 0, function* (payload, abortSignal, { receiveMessages, config }) { + abortSignal.throwIfAborted(); + try { + const result = yield receiveMessages({ + abortSignal: abortSignal, + channels: payload.channels, + channelGroups: payload.groups, + timetoken: payload.cursor.timetoken, + region: payload.cursor.region, + filterExpression: config.filterExpression, + }); + engine.transition(receiveSuccess(result.cursor, result.messages)); + } + catch (error) { + if (error instanceof PubNubError) { + if (error.status && error.status.category == StatusCategory$1.PNCancelledCategory) + return; + if (!abortSignal.aborted) + return engine.transition(receiveFailure(error)); + } + } + }))); + this.on(emitMessages.type, asyncHandler((payload_3, _1, _c) => __awaiter(this, [payload_3, _1, _c], void 0, function* (payload, _, { emitMessages }) { + if (payload.length > 0) { + emitMessages(payload); + } + }))); + this.on(emitStatus.type, asyncHandler((payload_4, _2, _d) => __awaiter(this, [payload_4, _2, _d], void 0, function* (payload, _, { emitStatus }) { + emitStatus(payload); + }))); + this.on(receiveReconnect.type, asyncHandler((payload_5, abortSignal_3, _e) => __awaiter(this, [payload_5, abortSignal_3, _e], void 0, function* (payload, abortSignal, { receiveMessages, delay, config }) { + if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { + abortSignal.throwIfAborted(); + yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); + abortSignal.throwIfAborted(); + try { + const result = yield receiveMessages({ + abortSignal: abortSignal, + channels: payload.channels, + channelGroups: payload.groups, + timetoken: payload.cursor.timetoken, + region: payload.cursor.region, + filterExpression: config.filterExpression, + }); + return engine.transition(receiveReconnectSuccess(result.cursor, result.messages)); + } + catch (error) { + if (error instanceof PubNubError) { + if (error.status && error.status.category == StatusCategory$1.PNCancelledCategory) + return; + return engine.transition(receiveReconnectFailure(error)); + } + } + } + else { + return engine.transition(receiveReconnectGiveup(new PubNubError(config.retryConfiguration + ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) + : 'Unable to complete subscribe messages receive.'))); + } + }))); + this.on(handshakeReconnect.type, asyncHandler((payload_6, abortSignal_4, _f) => __awaiter(this, [payload_6, abortSignal_4, _f], void 0, function* (payload, abortSignal, { handshake, delay, presenceState, config }) { + if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { + abortSignal.throwIfAborted(); + yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); + abortSignal.throwIfAborted(); + try { + const result = yield handshake(Object.assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState }))); + return engine.transition(handshakeReconnectSuccess(result)); + } + catch (error) { + if (error instanceof PubNubError) { + if (error.status && error.status.category == StatusCategory$1.PNCancelledCategory) + return; + return engine.transition(handshakeReconnectFailure(error)); + } + } + } + else { + return engine.transition(handshakeReconnectGiveup(new PubNubError(config.retryConfiguration + ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) + : 'Unable to complete subscribe handshake'))); + } + }))); + } + } + + const HandshakeFailedState = new State('HANDSHAKE_FAILED'); + HandshakeFailedState.on(subscriptionChange.type, (context, event) => HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, + })); + HandshakeFailedState.on(reconnect.type, (context, event) => HandshakingState.with({ + channels: context.channels, + groups: context.groups, + cursor: event.payload.cursor || context.cursor, + })); + HandshakeFailedState.on(restore.type, (context, event) => { + var _a, _b; + return HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region ? event.payload.cursor.region : (_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0, + }, + }); + }); + HandshakeFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); + + const HandshakeStoppedState = new State('HANDSHAKE_STOPPED'); + HandshakeStoppedState.on(subscriptionChange.type, (context, event) => HandshakeStoppedState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, + })); + HandshakeStoppedState.on(reconnect.type, (context, event) => HandshakingState.with(Object.assign(Object.assign({}, context), { cursor: event.payload.cursor || context.cursor }))); + HandshakeStoppedState.on(restore.type, (context, event) => { + var _a; + return HandshakeStoppedState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0, + }, + }); + }); + HandshakeStoppedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); + + const ReceiveFailedState = new State('RECEIVE_FAILED'); + ReceiveFailedState.on(reconnect.type, (context, event) => { + var _a; + return HandshakingState.with({ + channels: context.channels, + groups: context.groups, + cursor: { + timetoken: !!event.payload.cursor.timetoken ? (_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, + region: event.payload.cursor.region || context.cursor.region, + }, + }); + }); + ReceiveFailedState.on(subscriptionChange.type, (context, event) => HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, + })); + ReceiveFailedState.on(restore.type, (context, event) => HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region || context.cursor.region, + }, + })); + ReceiveFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); + + const ReceiveStoppedState = new State('RECEIVE_STOPPED'); + ReceiveStoppedState.on(subscriptionChange.type, (context, event) => ReceiveStoppedState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, + })); + ReceiveStoppedState.on(restore.type, (context, event) => ReceiveStoppedState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region || context.cursor.region, + }, + })); + ReceiveStoppedState.on(reconnect.type, (context, event) => { + var _a; + return HandshakingState.with({ + channels: context.channels, + groups: context.groups, + cursor: { + timetoken: !!event.payload.cursor.timetoken ? (_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, + region: event.payload.cursor.region || context.cursor.region, + }, + }); + }); + ReceiveStoppedState.on(unsubscribeAll.type, () => UnsubscribedState.with(undefined)); + + const ReceiveReconnectingState = new State('RECEIVE_RECONNECTING'); + ReceiveReconnectingState.onEnter((context) => receiveReconnect(context)); + ReceiveReconnectingState.onExit(() => receiveReconnect.cancel); + ReceiveReconnectingState.on(receiveReconnectSuccess.type, (context, event) => ReceivingState.with({ + channels: context.channels, + groups: context.groups, + cursor: event.payload.cursor, + }, [emitMessages(event.payload.events)])); + ReceiveReconnectingState.on(receiveReconnectFailure.type, (context, event) => ReceiveReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); + ReceiveReconnectingState.on(receiveReconnectGiveup.type, (context, event) => { + var _a; + return ReceiveFailedState.with({ + groups: context.groups, + channels: context.channels, + cursor: context.cursor, + reason: event.payload, + }, [emitStatus({ category: StatusCategory$1.PNDisconnectedUnexpectedlyCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); + }); + ReceiveReconnectingState.on(disconnect.type, (context) => ReceiveStoppedState.with({ + channels: context.channels, + groups: context.groups, + cursor: context.cursor, + }, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })])); + ReceiveReconnectingState.on(restore.type, (context, event) => ReceivingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region || context.cursor.region, + }, + })); + ReceiveReconnectingState.on(subscriptionChange.type, (context, event) => ReceivingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, + })); + ReceiveReconnectingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })])); + + const ReceivingState = new State('RECEIVING'); + ReceivingState.onEnter((context) => receiveMessages(context.channels, context.groups, context.cursor)); + ReceivingState.onExit(() => receiveMessages.cancel); + ReceivingState.on(receiveSuccess.type, (context, event) => { + return ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: event.payload.cursor }, [ + emitMessages(event.payload.events), + ]); + }); + ReceivingState.on(subscriptionChange.type, (context, event) => { + if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { + return UnsubscribedState.with(undefined); + } + return ReceivingState.with({ + cursor: context.cursor, + channels: event.payload.channels, + groups: event.payload.groups, + }); + }); + ReceivingState.on(restore.type, (context, event) => { + if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { + return UnsubscribedState.with(undefined); + } + return ReceivingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region || context.cursor.region, + }, + }); + }); + ReceivingState.on(receiveFailure.type, (context, event) => { + return ReceiveReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: 0, reason: event.payload })); + }); + ReceivingState.on(disconnect.type, (context) => { + return ReceiveStoppedState.with({ + channels: context.channels, + groups: context.groups, + cursor: context.cursor, + }, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })]); + }); + ReceivingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })])); + + const HandshakeReconnectingState = new State('HANDSHAKE_RECONNECTING'); + HandshakeReconnectingState.onEnter((context) => handshakeReconnect(context)); + HandshakeReconnectingState.onExit(() => handshakeReconnect.cancel); + HandshakeReconnectingState.on(handshakeReconnectSuccess.type, (context, event) => { + var _a, _b; + const cursor = { + timetoken: !!((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : event.payload.cursor.timetoken, + region: event.payload.cursor.region, + }; + return ReceivingState.with({ + channels: context.channels, + groups: context.groups, + cursor: cursor, + }, [emitStatus({ category: StatusCategory$1.PNConnectedCategory })]); + }); + HandshakeReconnectingState.on(handshakeReconnectFailure.type, (context, event) => HandshakeReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); + HandshakeReconnectingState.on(handshakeReconnectGiveup.type, (context, event) => { + var _a; + return HandshakeFailedState.with({ + groups: context.groups, + channels: context.channels, + cursor: context.cursor, + reason: event.payload, + }, [emitStatus({ category: StatusCategory$1.PNConnectionErrorCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); + }); + HandshakeReconnectingState.on(disconnect.type, (context) => HandshakeStoppedState.with({ + channels: context.channels, + groups: context.groups, + cursor: context.cursor, + })); + HandshakeReconnectingState.on(subscriptionChange.type, (context, event) => HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, + })); + HandshakeReconnectingState.on(restore.type, (context, event) => { + var _a, _b; + return HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: ((_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.region) || ((_b = context === null || context === void 0 ? void 0 : context.cursor) === null || _b === void 0 ? void 0 : _b.region) || 0, + }, + }); + }); + HandshakeReconnectingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); + + const HandshakingState = new State('HANDSHAKING'); + HandshakingState.onEnter((context) => handshake(context.channels, context.groups)); + HandshakingState.onExit(() => handshake.cancel); + HandshakingState.on(subscriptionChange.type, (context, event) => { + if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { + return UnsubscribedState.with(undefined); + } + return HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, + }); + }); + HandshakingState.on(handshakeSuccess.type, (context, event) => { + var _a, _b; + return ReceivingState.with({ + channels: context.channels, + groups: context.groups, + cursor: { + timetoken: !!((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context === null || context === void 0 ? void 0 : context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : event.payload.timetoken, + region: event.payload.region, + }, + }, [ + emitStatus({ + category: StatusCategory$1.PNConnectedCategory, + }), + ]); + }); + HandshakingState.on(handshakeFailure.type, (context, event) => { + return HandshakeReconnectingState.with({ + channels: context.channels, + groups: context.groups, + cursor: context.cursor, + attempts: 0, + reason: event.payload, + }); + }); + HandshakingState.on(disconnect.type, (context) => HandshakeStoppedState.with({ + channels: context.channels, + groups: context.groups, + cursor: context.cursor, + })); + HandshakingState.on(restore.type, (context, event) => { + var _a; + return HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0, + }, + }); + }); + HandshakingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); + + const UnsubscribedState = new State('UNSUBSCRIBED'); + UnsubscribedState.on(subscriptionChange.type, (_, event) => HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + })); + UnsubscribedState.on(restore.type, (_, event) => { + return HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: event.payload.cursor, + }); + }); + + class EventEngine { + get _engine() { + return this.engine; + } + constructor(dependencies) { + this.engine = new Engine(); + this.channels = []; + this.groups = []; + this.dependencies = dependencies; + this.dispatcher = new EventEngineDispatcher(this.engine, dependencies); + this._unsubscribeEngine = this.engine.subscribe((change) => { + if (change.type === 'invocationDispatched') { + this.dispatcher.dispatch(change.invocation); + } + }); + this.engine.start(UnsubscribedState, undefined); + } + subscribe({ channels, channelGroups, timetoken, withPresence, }) { + this.channels = [...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])]; + this.groups = [...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])]; + if (withPresence) { + this.channels.map((c) => this.channels.push(`${c}-pnpres`)); + this.groups.map((g) => this.groups.push(`${g}-pnpres`)); + } + if (timetoken) { + this.engine.transition(restore(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])])), timetoken)); + } + else { + this.engine.transition(subscriptionChange(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])])))); + } + if (this.dependencies.join) { + this.dependencies.join({ + channels: Array.from(new Set(this.channels.filter((c) => !c.endsWith('-pnpres')))), + groups: Array.from(new Set(this.groups.filter((g) => !g.endsWith('-pnpres')))), + }); + } + } + unsubscribe({ channels = [], channelGroups = [] }) { + const filteredChannels = removeSingleOccurance(this.channels, [ + ...channels, + ...channels.map((c) => `${c}-pnpres`), + ]); + const filteredGroups = removeSingleOccurance(this.groups, [ + ...channelGroups, + ...channelGroups.map((c) => `${c}-pnpres`), + ]); + if (new Set(this.channels).size !== new Set(filteredChannels).size || + new Set(this.groups).size !== new Set(filteredGroups).size) { + const channelsToLeave = findUniqueCommonElements(this.channels, channels); + const groupstoLeave = findUniqueCommonElements(this.groups, channelGroups); + if (this.dependencies.presenceState) { + channelsToLeave === null || channelsToLeave === void 0 ? void 0 : channelsToLeave.forEach((c) => delete this.dependencies.presenceState[c]); + groupstoLeave === null || groupstoLeave === void 0 ? void 0 : groupstoLeave.forEach((g) => delete this.dependencies.presenceState[g]); + } + this.channels = filteredChannels; + this.groups = filteredGroups; + this.engine.transition(subscriptionChange(Array.from(new Set(this.channels.slice(0))), Array.from(new Set(this.groups.slice(0))))); + if (this.dependencies.leave) { + this.dependencies.leave({ + channels: channelsToLeave.slice(0), + groups: groupstoLeave.slice(0), + }); + } + } + } + unsubscribeAll() { + this.channels = []; + this.groups = []; + if (this.dependencies.presenceState) { + Object.keys(this.dependencies.presenceState).forEach((objectName) => { + delete this.dependencies.presenceState[objectName]; + }); + } + this.engine.transition(subscriptionChange(this.channels.slice(0), this.groups.slice(0))); + if (this.dependencies.leaveAll) { + this.dependencies.leaveAll(); + } + } + reconnect({ timetoken, region }) { + this.engine.transition(reconnect(timetoken, region)); + } + disconnect() { + this.engine.transition(disconnect()); + if (this.dependencies.leaveAll) { + this.dependencies.leaveAll(); + } + } + getSubscribedChannels() { + return Array.from(new Set(this.channels.slice(0))); + } + getSubscribedChannelGroups() { + return Array.from(new Set(this.groups.slice(0))); + } + dispose() { + this.disconnect(); + this._unsubscribeEngine(); + this.dispatcher.dispose(); + } + } + + /** + * Publish REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether data is published used `POST` body or not. + */ + const SEND_BY_POST = false; + // endregion + /** + * Data publish request. + * + * Request will normalize and encrypt (if required) provided data and push it to the specified + * channel. + */ + class PublishRequest extends AbstractRequest { + /** + * Construct data publish request. + * + * @param parameters - Request configuration. + */ + constructor(parameters) { + var _a; + var _b; + super({ method: parameters.sendByPost ? TransportMethod.POST : TransportMethod.GET }); + this.parameters = parameters; + // Apply default request parameters. + (_a = (_b = this.parameters).sendByPost) !== null && _a !== void 0 ? _a : (_b.sendByPost = SEND_BY_POST); + } + operation() { + return RequestOperation$1.PNPublishOperation; + } + validate() { + const { message, channel, keySet: { publishKey }, } = this.parameters; + if (!channel) + return "Missing 'channel'"; + if (!message) + return "Missing 'message'"; + if (!publishKey) + return "Missing 'publishKey'"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + return { timetoken: serviceResponse[2] }; + }); + } + get path() { + const { message, channel, keySet } = this.parameters; + const stringifiedPayload = this.prepareMessagePayload(message); + return `/publish/${keySet.publishKey}/${keySet.subscribeKey}/0/${encodeString(channel)}/0${!this.parameters.sendByPost ? `/${encodeString(stringifiedPayload)}` : ''}`; + } + get queryParameters() { + const { meta, replicate, storeInHistory, ttl } = this.parameters; + const query = {}; + if (storeInHistory !== undefined) + query.store = storeInHistory ? '1' : '0'; + if (ttl !== undefined) + query.ttl = ttl; + if (replicate !== undefined && !replicate) + query.norep = 'true'; + if (meta && typeof meta === 'object') + query.meta = JSON.stringify(meta); + return query; + } + get headers() { + return { 'Content-Type': 'application/json' }; + } + get body() { + return this.prepareMessagePayload(this.parameters.message); + } + /** + * Pre-process provided data. + * + * Data will be "normalized" and encrypted if `cryptoModule` has been provided. + * + * @param payload - User-provided data which should be pre-processed before use. + * + * @returns Payload which can be used as part of request URL or body. + * + * @throws {Error} in case if provided `payload` or results of `encryption` can't be stringified. + */ + prepareMessagePayload(payload) { + const { crypto } = this.parameters; + if (!crypto) + return JSON.stringify(payload) || ''; + const encrypted = crypto.encrypt(JSON.stringify(payload)); + return JSON.stringify(typeof encrypted === 'string' ? encrypted : encode(encrypted)); + } + } + + /** + * Signal REST API module. + */ + // endregion + class SignalRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNSignalOperation; + } + validate() { + const { message, channel, keySet: { publishKey }, } = this.parameters; + if (!channel) + return "Missing 'channel'"; + if (!message) + return "Missing 'message'"; + if (!publishKey) + return "Missing 'publishKey'"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + return { timetoken: serviceResponse[2] }; + }); + } + get path() { + const { keySet: { publishKey, subscribeKey }, channel, message, } = this.parameters; + const stringifiedPayload = JSON.stringify(message); + return `/signal/${publishKey}/${subscribeKey}/0/${encodeString(channel)}/0/${encodeString(stringifiedPayload)}`; + } + } + + /** + * Receive messages subscribe REST API module. + */ + /** + * Receive messages subscribe request. + */ + class ReceiveMessagesSubscribeRequest extends BaseSubscribeRequest { + operation() { + return RequestOperation$1.PNReceiveMessagesOperation; + } + validate() { + const validationResult = super.validate(); + if (validationResult) + return validationResult; + if (!this.parameters.timetoken) + return 'timetoken can not be empty'; + if (!this.parameters.region) + return 'region can not be empty'; + } + get path() { + const { keySet: { subscribeKey }, channels = [], } = this.parameters; + return `/v2/subscribe/${subscribeKey}/${encodeNames(channels.sort(), ',')}/0`; + } + get queryParameters() { + const { channelGroups, filterExpression, timetoken, region } = this.parameters; + const query = { ee: '' }; + if (channelGroups && channelGroups.length > 0) + query['channel-group'] = channelGroups.sort().join(','); + if (filterExpression && filterExpression.length > 0) + query['filter-expr'] = filterExpression; + if (typeof timetoken === 'string') { + if (timetoken && timetoken.length > 0) + query['tt'] = timetoken; + } + else if (timetoken && timetoken > 0) + query['tt'] = timetoken; + if (region) + query['tr'] = region; + return query; + } + } + + /** + * Handshake subscribe REST API module. + */ + /** + * Handshake subscribe request. + * + * Separate subscribe request required by Event Engine. + */ + class HandshakeSubscribeRequest extends BaseSubscribeRequest { + operation() { + return RequestOperation$1.PNHandshakeOperation; + } + get path() { + const { keySet: { subscribeKey }, channels = [], } = this.parameters; + return `/v2/subscribe/${subscribeKey}/${encodeNames(channels.sort(), ',')}/0`; + } + get queryParameters() { + const { channelGroups, filterExpression, state } = this.parameters; + const query = { tt: 0, ee: '' }; + if (channelGroups && channelGroups.length > 0) + query['channel-group'] = channelGroups.sort().join(','); + if (filterExpression && filterExpression.length > 0) + query['filter-expr'] = filterExpression; + if (state && Object.keys(state).length > 0) + query['state'] = JSON.stringify(state); + return query; + } + } + + /** + * Get Presence State REST API module. + */ + // endregion + /** + * Get `uuid` presence state request. + */ + class GetPresenceStateRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c, _d; + super(); + this.parameters = parameters; + // Apply defaults. + (_a = (_c = this.parameters).channels) !== null && _a !== void 0 ? _a : (_c.channels = []); + (_b = (_d = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_d.channelGroups = []); + } + operation() { + return RequestOperation$1.PNGetStateOperation; + } + validate() { + const { keySet: { subscribeKey }, channels, channelGroups, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + const { channels = [], channelGroups = [] } = this.parameters; + const state = { channels: {} }; + if (channels.length === 1 && channelGroups.length === 0) + state.channels[channels[0]] = serviceResponse.payload; + else + state.channels = serviceResponse.payload; + return state; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, channels, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${uuid}`; + } + get queryParameters() { + const { channelGroups } = this.parameters; + if (!channelGroups || channelGroups.length === 0) + return {}; + return { 'channel-group': channelGroups.join(',') }; + } + } + + /** + * Set Presence State REST API module. + */ + // endregion + /** + * Set `uuid` presence state request. + */ + class SetPresenceStateRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNSetStateOperation; + } + validate() { + const { keySet: { subscribeKey }, state, channels = [], channelGroups = [], } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!state) + return 'Missing State'; + if ((channels === null || channels === void 0 ? void 0 : channels.length) === 0 && (channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.length) === 0) + return 'Please provide a list of channels and/or channel-groups'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return { state: serviceResponse.payload }; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, channels, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${encodeString(uuid)}/data`; + } + get queryParameters() { + const { channelGroups, state } = this.parameters; + const query = { state: JSON.stringify(state) }; + if (channelGroups && channelGroups.length !== 0) + query['channel-group'] = channelGroups.join(','); + return query; + } + } + + /** + * Announce heartbeat REST API module. + */ + // endregion + class HeartbeatRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNHeartbeatOperation; + } + validate() { + const { keySet: { subscribeKey }, channels = [], channelGroups = [], } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (channels.length === 0 && channelGroups.length === 0) + return 'Please provide a list of channels and/or channel-groups'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channels, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels !== null && channels !== void 0 ? channels : [], ',')}/heartbeat`; + } + get queryParameters() { + const { channelGroups, state, heartbeat } = this.parameters; + const query = { heartbeat: `${heartbeat}` }; + if (channelGroups && channelGroups.length !== 0) + query['channel-group'] = channelGroups.join(','); + if (state) + query.state = JSON.stringify(state); + return query; + } + } + + /** + * Announce leave REST API module. + */ + // endregion + class PresenceLeaveRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + if (this.parameters.channelGroups) + this.parameters.channelGroups = Array.from(new Set(this.parameters.channelGroups)); + if (this.parameters.channels) + this.parameters.channels = Array.from(new Set(this.parameters.channels)); + } + operation() { + return RequestOperation$1.PNUnsubscribeOperation; + } + validate() { + const { keySet: { subscribeKey }, channels = [], channelGroups = [], } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (channels.length === 0 && channelGroups.length === 0) + return 'At least one `channel` or `channel group` should be provided.'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return {}; + }); + } + get path() { + var _a; + const { keySet: { subscribeKey }, channels, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames((_a = channels === null || channels === void 0 ? void 0 : channels.sort()) !== null && _a !== void 0 ? _a : [], ',')}/leave`; + } + get queryParameters() { + const { channelGroups } = this.parameters; + if (!channelGroups || channelGroups.length === 0) + return {}; + return { 'channel-group': channelGroups.sort().join(',') }; + } + } + + /** + * `uuid` presence REST API module. + */ + // endregion + class WhereNowRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNWhereNowOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + if (!serviceResponse.payload) + return { channels: [] }; + return { channels: serviceResponse.payload.channels }; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/uuid/${encodeString(uuid)}`; + } + } + + /** + * Channels / channel groups presence REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `uuid` should be included in response or not. + */ + const INCLUDE_UUID$1 = true; + /** + * Whether state associated with `uuid` should be included in response or not. + */ + const INCLUDE_STATE = false; + // endregion + class HereNowRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c; + var _d, _e, _f; + super(); + this.parameters = parameters; + // Apply defaults. + (_a = (_d = this.parameters).queryParameters) !== null && _a !== void 0 ? _a : (_d.queryParameters = {}); + (_b = (_e = this.parameters).includeUUIDs) !== null && _b !== void 0 ? _b : (_e.includeUUIDs = INCLUDE_UUID$1); + (_c = (_f = this.parameters).includeState) !== null && _c !== void 0 ? _c : (_f.includeState = INCLUDE_STATE); + } + operation() { + const { channels = [], channelGroups = [] } = this.parameters; + return channels.length === 0 && channelGroups.length === 0 + ? RequestOperation$1.PNGlobalHereNowOperation + : RequestOperation$1.PNHereNowOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b; + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + // Extract general presence information. + const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; + const totalOccupancy = 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_channels; + const channelsPresence = {}; + let channels = {}; + // Remap single channel presence to multiple channels presence response. + if ('occupancy' in serviceResponse) { + const channel = this.parameters.channels[0]; + channels[channel] = { uuids: (_a = serviceResponse.uuids) !== null && _a !== void 0 ? _a : [], occupancy: totalOccupancy }; + } + else + channels = (_b = serviceResponse.payload.channels) !== null && _b !== void 0 ? _b : {}; + Object.keys(channels).forEach((channel) => { + const channelEntry = channels[channel]; + channelsPresence[channel] = { + occupants: this.parameters.includeUUIDs + ? channelEntry.uuids.map((uuid) => { + if (typeof uuid === 'string') + return { uuid, state: null }; + return uuid; + }) + : [], + name: channel, + occupancy: channelEntry.occupancy, + }; + }); + return { + totalChannels, + totalOccupancy, + channels: channelsPresence, + }; + }); + } + get path() { + const { keySet: { subscribeKey }, channels, channelGroups, } = this.parameters; + let path = `/v2/presence/sub-key/${subscribeKey}`; + if ((channels && channels.length > 0) || (channelGroups && channelGroups.length > 0)) + path += `/channel/${encodeNames(channels !== null && channels !== void 0 ? channels : [], ',')}`; + return path; + } + get queryParameters() { + const { channelGroups, includeUUIDs, includeState, queryParameters } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign({}, (!includeUUIDs ? { disable_uuids: '1' } : {})), ((includeState !== null && includeState !== void 0 ? includeState : false) ? { state: '1' } : {})), (channelGroups && channelGroups.length > 0 ? { 'channel-group': channelGroups.join(',') } : {})), queryParameters); + } + } + + /** + * Delete messages REST API module. + */ + // endregion + /** + * Delete messages from channel history. + */ + class DeleteMessageRequest extends AbstractRequest { + constructor(parameters) { + super({ method: TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNDeleteMessagesOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channel) + return 'Missing channel'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v3/history/sub-key/${subscribeKey}/channel/${encodeString(channel)}`; + } + get queryParameters() { + const { start, end } = this.parameters; + return Object.assign(Object.assign({}, (start ? { start } : {})), (end ? { end } : {})); + } + } + + /** + * Messages count REST API module. + */ + // endregion + class MessageCountRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNMessageCounts; + } + validate() { + const { keySet: { subscribeKey }, channels, timetoken, channelTimetokens, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channels) + return 'Missing channels'; + if (timetoken && channelTimetokens) + return '`timetoken` and `channelTimetokens` are incompatible together'; + if (!timetoken && !channelTimetokens) + return '`timetoken` or `channelTimetokens` need to be set'; + if (channelTimetokens && channelTimetokens.length > 1 && channelTimetokens.length !== channels.length) + return 'Length of `channelTimetokens` and `channels` do not match'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return { channels: serviceResponse.channels }; + }); + } + get path() { + return `/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${encodeNames(this.parameters.channels)}`; + } + get queryParameters() { + let { channelTimetokens } = this.parameters; + if (this.parameters.timetoken) + channelTimetokens = [this.parameters.timetoken]; + return Object.assign(Object.assign({}, (channelTimetokens.length === 1 ? { timetoken: channelTimetokens[0] } : {})), (channelTimetokens.length > 1 ? { channelsTimetoken: channelTimetokens.join(',') } : {})); + } + } + + /** + * Get history REST API module. + */ + // -------------------------------------------------------- + // ---------------------- Defaults ------------------------ + // -------------------------------------------------------- + // region Defaults + /** + * Whether verbose logging enabled or not. + */ + const LOG_VERBOSITY$1 = false; + /** + * Whether associated message metadata should be returned or not. + */ + const INCLUDE_METADATA = false; + /** + * Whether timetokens should be returned as strings by default or not. + */ + const STRINGIFY_TIMETOKENS$1 = false; + /** + * Default and maximum number of messages which should be returned. + */ + const MESSAGES_COUNT = 100; + // endregion + /** + * Get single channel messages request. + */ + class GetHistoryRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c; + super(); + this.parameters = parameters; + // Apply defaults. + if (parameters.count) + parameters.count = Math.min(parameters.count, MESSAGES_COUNT); + else + parameters.count = MESSAGES_COUNT; + (_a = parameters.stringifiedTimeToken) !== null && _a !== void 0 ? _a : (parameters.stringifiedTimeToken = STRINGIFY_TIMETOKENS$1); + (_b = parameters.includeMeta) !== null && _b !== void 0 ? _b : (parameters.includeMeta = INCLUDE_METADATA); + (_c = parameters.logVerbosity) !== null && _c !== void 0 ? _c : (parameters.logVerbosity = LOG_VERBOSITY$1); + } + operation() { + return RequestOperation$1.PNHistoryOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channel) + return 'Missing channel'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + const messages = serviceResponse[0]; + const startTimeToken = serviceResponse[1]; + const endTimeToken = serviceResponse[2]; + // Handle malformed get history response. + if (!Array.isArray(messages)) + return { messages: [], startTimeToken, endTimeToken }; + return { + messages: messages.map((payload) => { + const processedPayload = this.processPayload(payload.message); + const item = { + entry: processedPayload.payload, + timetoken: payload.timetoken, + }; + if (processedPayload.error) + item.error = processedPayload.error; + if (payload.meta) + item.meta = payload.meta; + return item; + }), + startTimeToken, + endTimeToken, + }; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/history/sub-key/${subscribeKey}/channel/${encodeString(channel)}`; + } + get queryParameters() { + const { start, end, reverse, count, stringifiedTimeToken, includeMeta } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: count, include_token: 'true' }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (reverse !== undefined && reverse !== null ? { reverse: reverse.toString() } : {})), (includeMeta ? { include_meta: 'true' } : {})); + } + processPayload(payload) { + const { crypto, logVerbosity } = this.parameters; + if (!crypto || typeof payload !== 'string') + return { payload }; + let decryptedPayload; + let error; + try { + const decryptedData = crypto.decrypt(payload); + decryptedPayload = + decryptedData instanceof ArrayBuffer + ? JSON.parse(GetHistoryRequest.decoder.decode(decryptedData)) + : decryptedData; + } + catch (err) { + if (logVerbosity) + console.log(`decryption error`, err.message); + decryptedPayload = payload; + error = `Error while decrypting message content: ${err.message}`; + } + return { + payload: decryptedPayload, + error, + }; + } + } + + // endregion + // -------------------------------------------------------- + // -------------------- Fetch Messages -------------------- + // -------------------------------------------------------- + // region Fetch Messages + /** + * PubNub-defined message type. + * + * Types of messages which can be retrieved with fetch messages REST API. + */ + var PubNubMessageType; + (function (PubNubMessageType) { + /** + * Regular message. + */ + PubNubMessageType[PubNubMessageType["Message"] = -1] = "Message"; + /** + * File message. + */ + PubNubMessageType[PubNubMessageType["Files"] = 4] = "Files"; + })(PubNubMessageType || (PubNubMessageType = {})); + // endregion + + /** + * Fetch messages REST API module. + */ + // -------------------------------------------------------- + // ---------------------- Defaults ------------------------ + // -------------------------------------------------------- + // region Defaults + /** + * Whether verbose logging enabled or not. + */ + const LOG_VERBOSITY = false; + /** + * Whether message type should be returned or not. + */ + const INCLUDE_MESSAGE_TYPE = true; + /** + * Whether timetokens should be returned as strings by default or not. + */ + const STRINGIFY_TIMETOKENS = false; + /** + * Whether message publisher `uuid` should be returned or not. + */ + const INCLUDE_UUID = true; + /** + * Default number of messages which can be returned for single channel, and it is maximum as well. + */ + const SINGLE_CHANNEL_MESSAGES_COUNT = 100; + /** + * Default number of messages which can be returned for multiple channels or when fetched + * message actions. + */ + const MULTIPLE_CHANNELS_MESSAGES_COUNT = 25; + // endregion + /** + * Fetch messages from channels request. + */ + class FetchMessagesRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e; + super(); + this.parameters = parameters; + // Apply defaults. + const includeMessageActions = (_a = parameters.includeMessageActions) !== null && _a !== void 0 ? _a : false; + const defaultCount = parameters.channels.length > 1 || includeMessageActions + ? MULTIPLE_CHANNELS_MESSAGES_COUNT + : SINGLE_CHANNEL_MESSAGES_COUNT; + if (!parameters.count) + parameters.count = defaultCount; + else + parameters.count = Math.min(parameters.count, defaultCount); + if (parameters.includeUuid) + parameters.includeUUID = parameters.includeUuid; + else + (_b = parameters.includeUUID) !== null && _b !== void 0 ? _b : (parameters.includeUUID = INCLUDE_UUID); + (_c = parameters.stringifiedTimeToken) !== null && _c !== void 0 ? _c : (parameters.stringifiedTimeToken = STRINGIFY_TIMETOKENS); + (_d = parameters.includeMessageType) !== null && _d !== void 0 ? _d : (parameters.includeMessageType = INCLUDE_MESSAGE_TYPE); + (_e = parameters.logVerbosity) !== null && _e !== void 0 ? _e : (parameters.logVerbosity = LOG_VERBOSITY); + } + operation() { + return RequestOperation$1.PNFetchMessagesOperation; + } + validate() { + const { keySet: { subscribeKey }, channels, includeMessageActions, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channels) + return 'Missing channels'; + if (includeMessageActions !== undefined && includeMessageActions && channels.length > 1) + return ('History can return actions data for a single channel only. Either pass a single channel ' + + 'or disable the includeMessageActions flag.'); + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + const responseChannels = (_a = serviceResponse.channels) !== null && _a !== void 0 ? _a : {}; + const channels = {}; + Object.keys(responseChannels).forEach((channel) => { + // Map service response to expected data object type structure. + channels[channel] = responseChannels[channel].map((payload) => { + // `null` message type means regular message. + if (payload.message_type === null) + payload.message_type = PubNubMessageType.Message; + const processedPayload = this.processPayload(channel, payload); + const item = { + channel, + timetoken: payload.timetoken, + message: processedPayload.payload, + messageType: payload.message_type, + uuid: payload.uuid, + }; + if (payload.actions) { + const itemWithActions = item; + itemWithActions.actions = payload.actions; + // Backward compatibility for existing users. + // TODO: Remove in next release. + itemWithActions.data = payload.actions; + } + if (payload.meta) + item.meta = payload.meta; + if (processedPayload.error) + item.error = processedPayload.error; + return item; + }); + }); + if (serviceResponse.more) + return { channels, more: serviceResponse.more }; + return { channels }; + }); + } + get path() { + const { keySet: { subscribeKey }, channels, includeMessageActions, } = this.parameters; + const endpoint = !includeMessageActions ? 'history' : 'history-with-actions'; + return `/v3/${endpoint}/sub-key/${subscribeKey}/channel/${encodeNames(channels)}`; + } + get queryParameters() { + const { start, end, count, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeMessageType ? { include_message_type: 'true' } : {})); + } + /** + * Parse single channel data entry. + * + * @param channel - Channel for which {@link payload} should be processed. + * @param payload - Source payload which should be processed and parsed to expected type. + * + * @returns + */ + processPayload(channel, payload) { + const { crypto, logVerbosity } = this.parameters; + if (!crypto || typeof payload.message !== 'string') + return { payload: payload.message }; + let decryptedPayload; + let error; + try { + const decryptedData = crypto.decrypt(payload.message); + decryptedPayload = + decryptedData instanceof ArrayBuffer + ? JSON.parse(FetchMessagesRequest.decoder.decode(decryptedData)) + : decryptedData; + } + catch (err) { + if (logVerbosity) + console.log(`decryption error`, err.message); + decryptedPayload = payload.message; + error = `Error while decrypting message content: ${err.message}`; + } + if (!error && + decryptedPayload && + payload.message_type == PubNubMessageType.Files && + typeof decryptedPayload === 'object' && + this.isFileMessage(decryptedPayload)) { + const fileMessage = decryptedPayload; + return { + payload: { + message: fileMessage.message, + file: Object.assign(Object.assign({}, fileMessage.file), { url: this.parameters.getFileUrl({ channel, id: fileMessage.file.id, name: fileMessage.file.name }) }), + }, + error, + }; + } + return { payload: decryptedPayload, error }; + } + /** + * Check whether `payload` potentially represents file message. + * + * @param payload - Fetched message payload. + * + * @returns `true` if payload can be {@link History#FileMessage|FileMessage}. + */ + isFileMessage(payload) { + return payload.file !== undefined; + } + } + + /** + * Get Message Actions REST API module. + */ + // endregion + /** + * Fetch channel message actions request. + */ + class GetMessageActionsRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNGetMessageActionsOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channel) + return 'Missing message channel'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + let start = null; + let end = null; + if (serviceResponse.data.length > 0) { + start = serviceResponse.data[0].actionTimetoken; + end = serviceResponse.data[serviceResponse.data.length - 1].actionTimetoken; + } + return { + data: serviceResponse.data, + more: serviceResponse.more, + start, + end, + }; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v1/message-actions/${subscribeKey}/channel/${encodeString(channel)}`; + } + get queryParameters() { + const { limit, start, end } = this.parameters; + return Object.assign(Object.assign(Object.assign({}, (start ? { start } : {})), (end ? { end } : {})), (limit ? { limit } : {})); + } + } + + /** + * Add Message Action REST API module. + */ + // endregion + /** + * Add Message Reaction request. + */ + class AddMessageActionRequest extends AbstractRequest { + constructor(parameters) { + super({ method: TransportMethod.POST }); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNAddMessageActionOperation; + } + validate() { + const { keySet: { subscribeKey }, action, channel, messageTimetoken, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channel) + return 'Missing message channel'; + if (!messageTimetoken) + return 'Missing message timetoken'; + if (!action) + return 'Missing Action'; + if (!action.value) + return 'Missing Action.value'; + if (!action.type) + return 'Missing Action.type'; + if (action.type.length > 15) + return 'Action.type value exceed maximum length of 15'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return { data: serviceResponse.data }; + }); + } + get headers() { + return { 'Content-Type': 'application/json' }; + } + get path() { + const { keySet: { subscribeKey }, channel, messageTimetoken, } = this.parameters; + return `/v1/message-actions/${subscribeKey}/channel/${encodeString(channel)}/message/${messageTimetoken}`; + } + get body() { + return JSON.stringify(this.parameters.action); + } + } + + /** + * Remove Message Action REST API module. + */ + // endregion + /** + * Remove specific message action request. + */ + class RemoveMessageAction extends AbstractRequest { + constructor(parameters) { + super({ method: TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNRemoveMessageActionOperation; + } + validate() { + const { keySet: { subscribeKey }, channel, messageTimetoken, actionTimetoken, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channel) + return 'Missing message action channel'; + if (!messageTimetoken) + return 'Missing message timetoken'; + if (!actionTimetoken) + return 'Missing action timetoken'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return { data: serviceResponse.data }; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, actionTimetoken, messageTimetoken, } = this.parameters; + return `/v1/message-actions/${subscribeKey}/channel/${encodeString(channel)}/message/${messageTimetoken}/action/${actionTimetoken}`; + } + } + + /** + * Publish File Message REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether published file messages should be stored in the channel's history. + */ + const STORE_IN_HISTORY = true; + // endregion + class PublishFileMessageRequest extends AbstractRequest { + constructor(parameters) { + var _a; + var _b; + super(); + this.parameters = parameters; + // Apply default request parameters. + (_a = (_b = this.parameters).storeInHistory) !== null && _a !== void 0 ? _a : (_b.storeInHistory = STORE_IN_HISTORY); + } + operation() { + return RequestOperation$1.PNPublishFileMessageOperation; + } + validate() { + const { channel, fileId, fileName } = this.parameters; + if (!channel) + return "channel can't be empty"; + if (!fileId) + return "file id can't be empty"; + if (!fileName) + return "file name can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + return { timetoken: serviceResponse[2] }; + }); + } + get path() { + const { message, channel, keySet: { publishKey, subscribeKey }, fileId, fileName, } = this.parameters; + const fileMessage = Object.assign({ file: { + name: fileName, + id: fileId, + } }, (message ? { message } : {})); + return `/v1/files/publish-file/${publishKey}/${subscribeKey}/0/${encodeString(channel)}/0/${encodeString(this.prepareMessagePayload(fileMessage))}`; + } + get queryParameters() { + const { storeInHistory, ttl, meta } = this.parameters; + return Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {})); + } + /** + * Pre-process provided data. + * + * Data will be "normalized" and encrypted if `cryptoModule` has been provided. + * + * @param payload - User-provided data which should be pre-processed before use. + * + * @returns Payload which can be used as part of request URL or body. + * + * @throws {Error} in case if provided `payload` or results of `encryption` can't be stringified. + */ + prepareMessagePayload(payload) { + const { crypto } = this.parameters; + if (!crypto) + return JSON.stringify(payload) || ''; + const encrypted = crypto.encrypt(JSON.stringify(payload)); + return JSON.stringify(typeof encrypted === 'string' ? encrypted : encode(encrypted)); + } + } + + /** + * File sharing REST API module. + */ + // endregion + /** + * File download Url generation request. + * + * Local request which generates Url to download shared file from the specific channel. + */ + class GetFileDownloadUrlRequest extends AbstractRequest { + /** + * Construct file download Url generation request. + * + * @param parameters - Request configuration. + */ + constructor(parameters) { + super({ method: TransportMethod.LOCAL }); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNGetFileUrlOperation; + } + validate() { + const { channel, id, name } = this.parameters; + if (!channel) + return "channel can't be empty"; + if (!id) + return "file id can't be empty"; + if (!name) + return "file name can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + return response.url; + }); + } + get path() { + const { channel, id, name, keySet: { subscribeKey }, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files/${id}/${name}`; + } + } + + /** + * Delete file REST API module. + */ + // endregion + /** + * Delete File request. + */ + class DeleteFileRequest extends AbstractRequest { + constructor(parameters) { + super({ method: TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNDeleteFileOperation; + } + validate() { + const { channel, id, name } = this.parameters; + if (!channel) + return "channel can't be empty"; + if (!id) + return "file id can't be empty"; + if (!name) + return "file name can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, id, channel, name, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files/${id}/${name}`; + } + } + + /** + * List Files REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Number of files to return in response. + */ + const LIMIT$6 = 100; + // endregion + /** + * Files List request. + */ + class FilesListRequest extends AbstractRequest { + constructor(parameters) { + var _a; + var _b; + super(); + this.parameters = parameters; + // Apply default request parameters. + (_a = (_b = this.parameters).limit) !== null && _a !== void 0 ? _a : (_b.limit = LIMIT$6); + } + operation() { + return RequestOperation$1.PNListFilesOperation; + } + validate() { + if (!this.parameters.channel) + return "channel can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files`; + } + get queryParameters() { + const { limit, next } = this.parameters; + return Object.assign({ limit: limit }, (next ? { next } : {})); + } + } + + /** + * Generate file upload URL REST API request. + */ + // endregion + /** + * Generate File Upload Url request. + */ + class GenerateFileUploadUrlRequest extends AbstractRequest { + constructor(parameters) { + super({ method: TransportMethod.POST }); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNGenerateUploadUrlOperation; + } + validate() { + if (!this.parameters.channel) + return "channel can't be empty"; + if (!this.parameters.name) + return "'name' can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return { + id: serviceResponse.data.id, + name: serviceResponse.data.name, + url: serviceResponse.file_upload_request.url, + formFields: serviceResponse.file_upload_request.form_fields, + }; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/generate-upload-url`; + } + get body() { + return JSON.stringify({ name: this.parameters.name }); + } + } + + /** + * Upload file REST API request. + */ + /** + * File Upload request. + */ + class UploadFileRequest extends AbstractRequest { + constructor(parameters) { + super({ method: TransportMethod.POST }); + this.parameters = parameters; + // Use file's actual mime type if available. + const mimeType = parameters.file.mimeType; + if (mimeType) { + parameters.formFields = parameters.formFields.map((entry) => { + if (entry.name === 'Content-Type') + return { name: entry.name, value: mimeType }; + return entry; + }); + } + } + operation() { + return RequestOperation$1.PNPublishFileOperation; + } + validate() { + const { fileId, fileName, file, uploadUrl } = this.parameters; + if (!fileId) + return "Validation failed: file 'id' can't be empty"; + if (!fileName) + return "Validation failed: file 'name' can't be empty"; + if (!file) + return "Validation failed: 'file' can't be empty"; + if (!uploadUrl) + return "Validation failed: file upload 'url' can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + return { + status: response.status, + message: response.body ? UploadFileRequest.decoder.decode(response.body) : 'OK', + }; + }); + } + request() { + return Object.assign(Object.assign({}, super.request()), { origin: new URL(this.parameters.uploadUrl).origin, timeout: 300 }); + } + get path() { + const { pathname, search } = new URL(this.parameters.uploadUrl); + return `${pathname}${search}`; + } + get body() { + return this.parameters.file; + } + get formData() { + return this.parameters.formFields; + } + } + + // endregion + /** + * Send file composed request. + */ + class SendFileRequest { + constructor(parameters) { + var _a; + this.parameters = parameters; + this.file = (_a = this.parameters.PubNubFile) === null || _a === void 0 ? void 0 : _a.create(parameters.file); + if (!this.file) + throw new Error('File upload error: unable to create File object.'); + } + /** + * Process user-input and upload file. + * + * @returns File upload request response. + */ + process() { + return __awaiter(this, void 0, void 0, function* () { + let fileName; + let fileId; + return this.generateFileUploadUrl() + .then((result) => { + fileName = result.name; + fileId = result.id; + return this.uploadFile(result); + }) + .then((result) => { + if (result.status !== 204) { + throw new PubNubError('Upload to bucket was unsuccessful', { + error: true, + statusCode: result.status, + category: StatusCategory$1.PNUnknownCategory, + operation: RequestOperation$1.PNPublishFileOperation, + errorData: { message: result.message }, + }); + } + }) + .then(() => this.publishFileMessage(fileId, fileName)) + .catch((error) => { + if (error instanceof PubNubError) + throw error; + const apiError = !(error instanceof PubNubAPIError) ? PubNubAPIError.create(error) : error; + throw new PubNubError('File upload error.', apiError.toStatus(RequestOperation$1.PNPublishFileOperation)); + }); + }); + } + /** + * Generate pre-signed file upload Url. + * + * @returns File upload credentials. + */ + generateFileUploadUrl() { + return __awaiter(this, void 0, void 0, function* () { + const request = new GenerateFileUploadUrlRequest(Object.assign(Object.assign({}, this.parameters), { name: this.file.name, keySet: this.parameters.keySet })); + return this.parameters.sendRequest(request); + }); + } + /** + * Prepare and upload {@link PubNub} File object to remote storage. + * + * @param uploadParameters - File upload request parameters. + * + * @returns + */ + uploadFile(uploadParameters) { + return __awaiter(this, void 0, void 0, function* () { + const { cipherKey, PubNubFile, crypto, cryptography } = this.parameters; + const { id, name, url, formFields } = uploadParameters; + // Encrypt file if possible. + if (this.parameters.PubNubFile.supportsEncryptFile) { + if (!cipherKey && crypto) + this.file = (yield crypto.encryptFile(this.file, PubNubFile)); + else if (cipherKey && cryptography) + this.file = (yield cryptography.encryptFile(cipherKey, this.file, PubNubFile)); + } + return this.parameters.sendRequest(new UploadFileRequest({ + fileId: id, + fileName: name, + file: this.file, + uploadUrl: url, + formFields, + })); + }); + } + publishFileMessage(fileId, fileName) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b, _c, _d; + let result = { timetoken: '0' }; + let retries = this.parameters.fileUploadPublishRetryLimit; + let publishError; + let wasSuccessful = false; + do { + try { + result = yield this.parameters.publishFile(Object.assign(Object.assign({}, this.parameters), { fileId, fileName })); + wasSuccessful = true; + } + catch (error) { + if (error instanceof PubNubError) + publishError = error; + retries -= 1; + } + } while (!wasSuccessful && retries > 0); + if (!wasSuccessful) { + throw new PubNubError('Publish failed. You may want to execute that operation manually using pubnub.publishFile', { + error: true, + category: (_b = (_a = publishError.status) === null || _a === void 0 ? void 0 : _a.category) !== null && _b !== void 0 ? _b : StatusCategory$1.PNUnknownCategory, + statusCode: (_d = (_c = publishError.status) === null || _c === void 0 ? void 0 : _c.statusCode) !== null && _d !== void 0 ? _d : 0, + channel: this.parameters.channel, + id: fileId, + name: fileName, + }); + } + else + return { status: 200, timetoken: result.timetoken, id: fileId, name: fileName }; + }); + } + } + + /** + * PAM Revoke Token REST API module. + */ + // endregion + /** + * Access token revoke request. + * + * Invalidate token and permissions which has been granted for it. + */ + class RevokeTokenRequest extends AbstractRequest { + constructor(parameters) { + super({ method: TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNAccessManagerRevokeToken; + } + validate() { + if (!this.parameters.keySet.secretKey) + return 'Missing Secret Key'; + if (!this.parameters.token) + return "token can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, token, } = this.parameters; + return `/v3/pam/${subscribeKey}/grant/${encodeString(token)}`; + } + } + + /** + * PAM Grant Token REST API module. + */ + // endregion + /** + * Grant token permissions request. + */ + class GrantTokenRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c, _d; + super({ method: TransportMethod.POST }); + this.parameters = parameters; + // Apply defaults. + (_a = (_c = this.parameters).resources) !== null && _a !== void 0 ? _a : (_c.resources = {}); + (_b = (_d = this.parameters).patterns) !== null && _b !== void 0 ? _b : (_d.patterns = {}); + } + operation() { + return RequestOperation$1.PNAccessManagerGrantToken; + } + validate() { + var _a, _b, _c, _d, _e, _f; + const { keySet: { subscribeKey, publishKey, secretKey }, resources, patterns, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!publishKey) + return 'Missing Publish Key'; + if (!secretKey) + return 'Missing Secret Key'; + if (!resources && !patterns) + return 'Missing either Resources or Patterns'; + if (this.isVspPermissions(this.parameters) && + ('channels' in ((_a = this.parameters.resources) !== null && _a !== void 0 ? _a : {}) || + 'uuids' in ((_b = this.parameters.resources) !== null && _b !== void 0 ? _b : {}) || + 'groups' in ((_c = this.parameters.resources) !== null && _c !== void 0 ? _c : {}) || + 'channels' in ((_d = this.parameters.patterns) !== null && _d !== void 0 ? _d : {}) || + 'uuids' in ((_e = this.parameters.patterns) !== null && _e !== void 0 ? _e : {}) || + 'groups' in ((_f = this.parameters.patterns) !== null && _f !== void 0 ? _f : {}))) + return ('Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`,' + + ' `groups` and `authorized_uuid`'); + let permissionsEmpty = true; + [this.parameters.resources, this.parameters.patterns].forEach((refPerm) => { + Object.keys(refPerm !== null && refPerm !== void 0 ? refPerm : {}).forEach((scope) => { + var _a; + // @ts-expect-error Permissions with backward compatibility. + if (refPerm && permissionsEmpty && Object.keys((_a = refPerm[scope]) !== null && _a !== void 0 ? _a : {}).length > 0) { + permissionsEmpty = false; + } + }); + }); + if (permissionsEmpty) + return 'Missing values for either Resources or Patterns'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse.data.token; + }); + } + get path() { + return `/v3/pam/${this.parameters.keySet.subscribeKey}/grant`; + } + get body() { + const { ttl, meta } = this.parameters; + const body = Object.assign({}, (ttl || ttl === 0 ? { ttl } : {})); + const uuid = this.isVspPermissions(this.parameters) + ? this.parameters.authorizedUserId + : this.parameters.authorized_uuid; + const permissions = {}; + const resourcePermissions = {}; + const patternPermissions = {}; + const mapPermissions = (name, permissionBit, type, permissions) => { + if (!permissions[type]) + permissions[type] = {}; + permissions[type][name] = permissionBit; + }; + const { resources, patterns } = this.parameters; + [resources, patterns].forEach((refPerm, idx) => { + var _a, _b, _c, _d, _e; + const target = idx === 0 ? resourcePermissions : patternPermissions; + let channelsPermissions = {}; + let channelGroupsPermissions = {}; + let uuidsPermissions = {}; + if (!target.channels) + target.channels = {}; + if (!target.groups) + target.groups = {}; + if (!target.uuids) + target.uuids = {}; + // @ts-expect-error Not used, needed for api backward compatibility + if (!target.users) + target.users = {}; + // @ts-expect-error Not used, needed for api backward compatibility + if (!target.spaces) + target.spaces = {}; + if (refPerm) { + // Check whether working with legacy Objects permissions. + if ('spaces' in refPerm || 'users' in refPerm) { + channelsPermissions = (_a = refPerm.spaces) !== null && _a !== void 0 ? _a : {}; + uuidsPermissions = (_b = refPerm.users) !== null && _b !== void 0 ? _b : {}; + } + else if ('channels' in refPerm || 'uuids' in refPerm || 'groups' in refPerm) { + channelsPermissions = (_c = refPerm.channels) !== null && _c !== void 0 ? _c : {}; + channelGroupsPermissions = (_d = refPerm.groups) !== null && _d !== void 0 ? _d : {}; + uuidsPermissions = (_e = refPerm.uuids) !== null && _e !== void 0 ? _e : {}; + } + } + Object.keys(channelsPermissions).forEach((channel) => mapPermissions(channel, this.extractPermissions(channelsPermissions[channel]), 'channels', target)); + Object.keys(channelGroupsPermissions).forEach((groups) => mapPermissions(groups, this.extractPermissions(channelGroupsPermissions[groups]), 'groups', target)); + Object.keys(uuidsPermissions).forEach((uuids) => mapPermissions(uuids, this.extractPermissions(uuidsPermissions[uuids]), 'uuids', target)); + }); + if (uuid) + permissions.uuid = `${uuid}`; + permissions.resources = resourcePermissions; + permissions.patterns = patternPermissions; + permissions.meta = meta !== null && meta !== void 0 ? meta : {}; + body.permissions = permissions; + return JSON.stringify(body); + } + /** + * Extract permissions bit from permission configuration object. + * + * @param permissions - User provided scope-based permissions. + * + * @returns Permissions bit. + */ + extractPermissions(permissions) { + let permissionsResult = 0; + if ('join' in permissions && permissions.join) + permissionsResult |= 128; + if ('update' in permissions && permissions.update) + permissionsResult |= 64; + if ('get' in permissions && permissions.get) + permissionsResult |= 32; + if ('delete' in permissions && permissions.delete) + permissionsResult |= 8; + if ('manage' in permissions && permissions.manage) + permissionsResult |= 4; + if ('write' in permissions && permissions.write) + permissionsResult |= 2; + if ('read' in permissions && permissions.read) + permissionsResult |= 1; + return permissionsResult; + } + /** + * Check whether provided parameters is part of legacy VSP access token configuration. + * + * @param parameters - Parameters which should be checked. + * + * @returns VSP request parameters if it is legacy configuration. + */ + isVspPermissions(parameters) { + var _a, _b, _c, _d; + return ('authorizedUserId' in parameters || + 'spaces' in ((_a = parameters.resources) !== null && _a !== void 0 ? _a : {}) || + 'users' in ((_b = parameters.resources) !== null && _b !== void 0 ? _b : {}) || + 'spaces' in ((_c = parameters.patterns) !== null && _c !== void 0 ? _c : {}) || + 'users' in ((_d = parameters.patterns) !== null && _d !== void 0 ? _d : {})); + } + } + + /** + * PAM Grant REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Resources `read` permission. + */ + const READ_PERMISSION = false; + /** + * Resources `write` permission. + */ + const WRITE_PERMISSION = false; + /** + * Resources `delete` permission. + */ + const DELETE_PERMISSION = false; + /** + * Resources `get` permission. + */ + const GET_PERMISSION = false; + /** + * Resources `update` permission. + */ + const UPDATE_PERMISSION = false; + /** + * Resources `manage` permission. + */ + const MANAGE_PERMISSION = false; + /** + * Resources `join` permission. + */ + const JOIN_PERMISSION = false; + // endregion + /** + * Grant permissions request. + */ + class GrantRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; + super(); + this.parameters = parameters; + // Apply defaults. + (_a = (_l = this.parameters).channels) !== null && _a !== void 0 ? _a : (_l.channels = []); + (_b = (_m = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_m.channelGroups = []); + (_c = (_o = this.parameters).uuids) !== null && _c !== void 0 ? _c : (_o.uuids = []); + (_d = (_p = this.parameters).read) !== null && _d !== void 0 ? _d : (_p.read = READ_PERMISSION); + (_e = (_q = this.parameters).write) !== null && _e !== void 0 ? _e : (_q.write = WRITE_PERMISSION); + (_f = (_r = this.parameters).delete) !== null && _f !== void 0 ? _f : (_r.delete = DELETE_PERMISSION); + (_g = (_s = this.parameters).get) !== null && _g !== void 0 ? _g : (_s.get = GET_PERMISSION); + (_h = (_t = this.parameters).update) !== null && _h !== void 0 ? _h : (_t.update = UPDATE_PERMISSION); + (_j = (_u = this.parameters).manage) !== null && _j !== void 0 ? _j : (_u.manage = MANAGE_PERMISSION); + (_k = (_v = this.parameters).join) !== null && _k !== void 0 ? _k : (_v.join = JOIN_PERMISSION); + } + operation() { + return RequestOperation$1.PNAccessManagerGrant; + } + validate() { + const { keySet: { subscribeKey, publishKey, secretKey }, uuids = [], channels = [], channelGroups = [], authKeys = [], } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!publishKey) + return 'Missing Publish Key'; + if (!secretKey) + return 'Missing Secret Key'; + if (uuids.length !== 0 && authKeys.length === 0) + return 'authKeys are required for grant request on uuids'; + if (uuids.length && (channels.length !== 0 || channelGroups.length !== 0)) + return 'Both channel/channel group and uuid cannot be used in the same request'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse.payload; + }); + } + get path() { + return `/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`; + } + get queryParameters() { + const { channels, channelGroups, authKeys, uuids, read, write, manage, delete: del, get, join, update, ttl, } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (channels && (channels === null || channels === void 0 ? void 0 : channels.length) > 0 ? { channel: channels.join(',') } : {})), (channelGroups && (channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.length) > 0 ? { 'channel-group': channelGroups.join(',') } : {})), (authKeys && (authKeys === null || authKeys === void 0 ? void 0 : authKeys.length) > 0 ? { auth: authKeys.join(',') } : {})), (uuids && (uuids === null || uuids === void 0 ? void 0 : uuids.length) > 0 ? { 'target-uuid': uuids.join(',') } : {})), { r: read ? '1' : '0', w: write ? '1' : '0', m: manage ? '1' : '0', d: del ? '1' : '0', g: get ? '1' : '0', j: join ? '1' : '0', u: update ? '1' : '0' }), (ttl || ttl === 0 ? { ttl } : {})); + } + } + + /** + * PAM Audit REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Auth keys for which permissions should be audited. + */ + const AUTH_KEYS = []; + // endregion + /** + * Permissions audit request. + */ + class AuditRequest extends AbstractRequest { + constructor(parameters) { + var _a; + var _b; + super(); + this.parameters = parameters; + // Apply default request parameters. + (_a = (_b = this.parameters).authKeys) !== null && _a !== void 0 ? _a : (_b.authKeys = AUTH_KEYS); + } + operation() { + return RequestOperation$1.PNAccessManagerAudit; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse.payload; + }); + } + get path() { + return `/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`; + } + get queryParameters() { + const { channel, channelGroup, authKeys } = this.parameters; + return Object.assign(Object.assign(Object.assign({}, (channel ? { channel } : {})), (channelGroup ? { 'channel-group': channelGroup } : {})), (authKeys && authKeys.length ? { auth: authKeys.join(',') } : {})); + } + } + + class SubscribeCapable { + subscribe() { + var _a, _b; + this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken }))); + } + unsubscribe() { + this.pubnub.unsubscribe({ + channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')), + channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), + }); + } + set onMessage(onMessageListener) { + this.listener.message = onMessageListener; + } + set onPresence(onPresenceListener) { + this.listener.presence = onPresenceListener; + } + set onSignal(onSignalListener) { + this.listener.signal = onSignalListener; + } + set onObjects(onObjectsListener) { + this.listener.objects = onObjectsListener; + } + set onMessageAction(messageActionEventListener) { + this.listener.messageAction = messageActionEventListener; + } + set onFile(fileEventListener) { + this.listener.file = fileEventListener; + } + addListener(listener) { + this.eventEmitter.addListener(listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + } + removeListener(listener) { + this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); + } + get channels() { + return this.channelNames.slice(0); + } + get channelGroups() { + return this.groupNames.slice(0); + } + } + + class SubscriptionSet extends SubscribeCapable { + constructor({ channels = [], channelGroups = [], subscriptionOptions, eventEmitter, pubnub, }) { + super(); + this.channelNames = []; + this.groupNames = []; + this.subscriptionList = []; + this.options = subscriptionOptions; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + channels + .filter((c) => !c.endsWith('-pnpres')) + .forEach((c) => { + const subscription = this.pubnub.channel(c).subscription(this.options); + this.channelNames = [...this.channelNames, ...subscription.channels]; + this.subscriptionList.push(subscription); + }); + channelGroups + .filter((cg) => !cg.endsWith('-pnpres')) + .forEach((cg) => { + const subscription = this.pubnub.channelGroup(cg).subscription(this.options); + this.groupNames = [...this.groupNames, ...subscription.channelGroups]; + this.subscriptionList.push(subscription); + }); + this.listener = {}; + eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + } + addSubscription(subscription) { + this.subscriptionList.push(subscription); + this.channelNames = [...this.channelNames, ...subscription.channels]; + this.groupNames = [...this.groupNames, ...subscription.channelGroups]; + this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); + } + removeSubscription(subscription) { + const channelsToRemove = subscription.channels; + const groupsToRemove = subscription.channelGroups; + this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); + this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); + this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); + this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + } + addSubscriptionSet(subscriptionSet) { + this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; + this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; + this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; + this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); + } + removeSubscriptionSet(subscriptionSet) { + const channelsToRemove = subscriptionSet.channels; + const groupsToRemove = subscriptionSet.channelGroups; + this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); + this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); + this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); + this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + } + get subscriptions() { + return this.subscriptionList.slice(0); + } + } + + class Subscription extends SubscribeCapable { + constructor({ channels, channelGroups, subscriptionOptions, eventEmitter, pubnub, }) { + super(); + this.channelNames = []; + this.groupNames = []; + this.channelNames = channels; + this.groupNames = channelGroups; + this.options = subscriptionOptions; + this.pubnub = pubnub; + this.eventEmitter = eventEmitter; + this.listener = {}; + eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + } + addSubscription(subscription) { + return new SubscriptionSet({ + channels: [...this.channelNames, ...subscription.channels], + channelGroups: [...this.groupNames, ...subscription.channelGroups], + subscriptionOptions: Object.assign(Object.assign({}, this.options), subscription === null || subscription === void 0 ? void 0 : subscription.options), + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } + } + + class ChannelMetadata { + constructor(id, eventEmitter, pubnub) { + this.id = id; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + subscription(subscriptionOptions) { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } + } + + class ChannelGroup { + constructor(channelGroup, eventEmitter, pubnub) { + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + this.name = channelGroup; + } + subscription(subscriptionOptions) { + return new Subscription({ + channels: [], + channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } + } + + class UserMetadata { + constructor(id, eventEmitter, pubnub) { + this.id = id; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + } + subscription(subscriptionOptions) { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } + } + + class Channel { + constructor(channelName, eventEmitter, pubnub) { + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + this.name = channelName; + } + subscription(subscriptionOptions) { + return new Subscription({ + channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } + } + + /** + * Remove channel group channels REST API module. + */ + // endregion + /** + * Remove channel group channels request. + */ + // prettier-ignore + class RemoveChannelGroupChannelsRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNRemoveChannelsFromGroupOperation; + } + validate() { + const { keySet: { subscribeKey }, channels, channelGroup, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channelGroup) + return 'Missing Channel Group'; + if (!channels) + return 'Missing channels'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channelGroup, } = this.parameters; + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${encodeString(channelGroup)}`; + } + get queryParameters() { + return { remove: this.parameters.channels.join(',') }; + } + } + + /** + * Add channel group channels REST API module. + */ + // endregion + /** + * Add channel group channels request. + */ + class AddChannelGroupChannelsRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNAddChannelsToGroupOperation; + } + validate() { + const { keySet: { subscribeKey }, channels, channelGroup, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channelGroup) + return 'Missing Channel Group'; + if (!channels) + return 'Missing channels'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channelGroup, } = this.parameters; + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${encodeString(channelGroup)}`; + } + get queryParameters() { + return { add: this.parameters.channels.join(',') }; + } + } + + /** + * List channel group channels REST API module. + */ + // endregion + /** + * List Channel Group Channels request. + */ + class ListChannelGroupChannels extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNChannelsForGroupOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channelGroup) + return 'Missing Channel Group'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return { channels: serviceResponse.payload.channels }; + }); + } + get path() { + const { keySet: { subscribeKey }, channelGroup, } = this.parameters; + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${encodeString(channelGroup)}`; + } + } + + /** + * Delete channel group REST API module. + */ + // endregion + /** + * Channel group delete request. + */ + class DeleteChannelGroupRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNRemoveGroupOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channelGroup) + return 'Missing Channel Group'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channelGroup, } = this.parameters; + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${encodeString(channelGroup)}/remove`; + } + } + + /** + * List All Channel Groups REST API module. + */ + // endregion + /** + * List all channel groups request. + */ + class ListChannelGroupsRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNChannelGroupsOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return { groups: serviceResponse.payload.groups }; + }); + } + get path() { + return `/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`; + } + } + + /** + * PubNub Channel Groups API module. + */ + class PubnubChannelGroups { + constructor(keySet, + /* eslint-disable @typescript-eslint/no-explicit-any */ + sendRequest) { + this.keySet = keySet; + this.sendRequest = sendRequest; + } + /** + * Fetch channel group channels. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get channel group channels response or `void` in case if `callback` + * provided. + */ + listChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new ListChannelGroupChannels(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Fetch all channel groups. + * + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all channel groups response or `void` in case if `callback` provided. + * + * @deprecated + */ + listGroups(callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new ListChannelGroupsRequest({ keySet: this.keySet }); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Add channels to the channel group. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add channels to the channel group response or `void` in case if + * `callback` provided. + */ + addChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new AddChannelGroupChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Remove channels from the channel group. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous remove channels from the channel group response or `void` in + * case if `callback` provided. + */ + removeChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new RemoveChannelGroupChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Remove channel group. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous remove channel group response or `void` in case if `callback` provided. + */ + deleteGroup(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new DeleteChannelGroupRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + } + + /** + * Manage channels enabled for device push REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Environment for which APNS2 notifications + */ + const ENVIRONMENT = 'development'; + /** + * Maximum number of channels in `list` response. + */ + const MAX_COUNT = 1000; + // endregion + /** + * Base push notification request. + */ + class BasePushNotificationChannelsRequest extends AbstractRequest { + constructor(parameters) { + var _a; + var _b; + super(); + this.parameters = parameters; + // Apply request defaults + if (this.parameters.pushGateway === 'apns2') + (_a = (_b = this.parameters).environment) !== null && _a !== void 0 ? _a : (_b.environment = ENVIRONMENT); + if (this.parameters.count && this.parameters.count > MAX_COUNT) + this.parameters.count = MAX_COUNT; + } + operation() { + throw Error('Should be implemented in subclass.'); + } + validate() { + const { keySet: { subscribeKey }, action, device, pushGateway, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!device) + return 'Missing Device ID (device)'; + if ((action === 'add' || action === 'remove') && + (!('channels' in this.parameters) || this.parameters.channels.length === 0)) + return 'Missing Channels'; + if (!pushGateway) + return 'Missing GW Type (pushGateway: gcm or apns2)'; + if (this.parameters.pushGateway === 'apns2' && !this.parameters.topic) + return 'Missing APNS2 topic'; + } + parse(_response) { + return __awaiter(this, void 0, void 0, function* () { + throw Error('Should be implemented in subclass.'); + }); + } + get path() { + const { keySet: { subscribeKey }, action, device, pushGateway, } = this.parameters; + let path = pushGateway === 'apns2' + ? `/v2/push/sub-key/${subscribeKey}/devices-apns2/${device}` + : `/v1/push/sub-key/${subscribeKey}/devices/${device}`; + if (action === 'remove-device') + path = `${path}/remove`; + return path; + } + get queryParameters() { + const { start, count } = this.parameters; + let query = Object.assign(Object.assign({ type: this.parameters.pushGateway }, (start ? { start } : {})), (count && count > 0 ? { count } : {})); + if ('channels' in this.parameters) + query[this.parameters.action] = this.parameters.channels.join(','); + if (this.parameters.pushGateway === 'apns2') { + const { environment, topic } = this.parameters; + query = Object.assign(Object.assign({}, query), { environment: environment, topic }); + } + return query; + } + } + + /** + * Unregister Channels from Device push REST API module. + */ + // endregion + /** + * Unregister channels from device push request. + */ + // prettier-ignore + class RemoveDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest { + constructor(parameters) { + super(Object.assign(Object.assign({}, parameters), { action: 'remove' })); + } + operation() { + return RequestOperation$1.PNRemovePushNotificationEnabledChannelsOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + return {}; + }); + } + } + + /** + * List Device push enabled channels REST API module. + */ + // endregion + /** + * List device push enabled channels request. + */ + // prettier-ignore + class ListDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest { + constructor(parameters) { + super(Object.assign(Object.assign({}, parameters), { action: 'list' })); + } + operation() { + return RequestOperation$1.PNPushNotificationEnabledChannelsOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + return { channels: serviceResponse }; + }); + } + } + + /** + * Register Channels with Device push REST API module. + */ + // endregion + /** + * Register channels with device push request. + */ + // prettier-ignore + class AddDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest { + constructor(parameters) { + super(Object.assign(Object.assign({}, parameters), { action: 'add' })); + } + operation() { + return RequestOperation$1.PNAddPushNotificationEnabledChannelsOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + return {}; + }); + } + } + + /** + * Unregister Device push REST API module. + */ + // endregion + /** + * Unregister device push notifications request. + */ + // prettier-ignore + class RemoveDevicePushNotificationRequest extends BasePushNotificationChannelsRequest { + constructor(parameters) { + super(Object.assign(Object.assign({}, parameters), { action: 'remove-device' })); + } + operation() { + return RequestOperation$1.PNRemoveAllPushNotificationsOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + return {}; + }); + } + } + + /** + * PubNub Push Notifications API module. + */ + class PubNubPushNotifications { + constructor(keySet, + /* eslint-disable @typescript-eslint/no-explicit-any */ + sendRequest) { + this.keySet = keySet; + this.sendRequest = sendRequest; + } + /** + * Fetch device's push notification enabled channels. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get device channels response or `void` in case if `callback` provided. + */ + listChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new ListDevicePushNotificationChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Enable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + */ + addChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new AddDevicePushNotificationChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Disable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + */ + removeChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new RemoveDevicePushNotificationChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Disable push notifications for device. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + */ + deleteDevice(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new RemoveDevicePushNotificationRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + } + + /** + * Get All Channel Metadata REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `Channel` custom fields should be included in response or not. + */ + const INCLUDE_CUSTOM_FIELDS$9 = false; + /** + * Whether total number of channels should be included in response or not. + */ + const INCLUDE_TOTAL_COUNT$4 = false; + /** + * Number of objects to return in response. + */ + const LIMIT$5 = 100; + // endregion + /** + * Get All Channels Metadata request. + */ + class GetAllChannelsMetadataRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d; + var _e, _f; + super(); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_e = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_e.customFields = INCLUDE_CUSTOM_FIELDS$9); + (_c = (_f = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_f.totalCount = INCLUDE_TOTAL_COUNT$4); + (_d = parameters.limit) !== null && _d !== void 0 ? _d : (parameters.limit = LIMIT$5); + } + operation() { + return RequestOperation$1.PNGetAllChannelMetadataOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + return `/v2/objects/${this.parameters.keySet.subscribeKey}/channels`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(','), count: `${include.totalCount}` }, (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } + } + + /** + * Remove Channel Metadata REST API module. + */ + // endregion + /** + * Remove Channel Metadata request. + */ + class RemoveChannelMetadataRequest extends AbstractRequest { + constructor(parameters) { + super({ method: TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNRemoveChannelMetadataOperation; + } + validate() { + if (!this.parameters.channel) + return 'Channel cannot be empty'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}`; + } + } + + /** + * Get UUID Memberships REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `Membership` custom field should be included in response or not. + */ + const INCLUDE_CUSTOM_FIELDS$8 = false; + /** + * Whether membership's status field should be included in response or not. + */ + const INCLUDE_STATUS$1 = false; + /** + * Whether total number of memberships should be included in response or not. + */ + const INCLUDE_TOTAL_COUNT$3 = false; + /** + * Whether `Channel` fields should be included in response or not. + */ + const INCLUDE_CHANNEL_FIELDS$1 = false; + /** + * Whether `Channel` status field should be included in response or not. + */ + const INCLUDE_CHANNEL_STATUS_FIELD = false; + /** + * Whether `Channel` type field should be included in response or not. + */ + const INCLUDE_CHANNEL_TYPE_FIELD = false; + /** + * Whether `Channel` custom field should be included in response or not. + */ + const INCLUDE_CHANNEL_CUSTOM_FIELDS$1 = false; + /** + * Number of objects to return in response. + */ + const LIMIT$4 = 100; + // endregion + /** + * Get UUID Memberships request. + */ + class GetUUIDMembershipsRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j; + var _k, _l, _m, _o, _p, _q, _r; + super(); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS$8); + (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT$3); + (_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS$1); + (_e = (_o = parameters.include).channelFields) !== null && _e !== void 0 ? _e : (_o.channelFields = INCLUDE_CHANNEL_FIELDS$1); + (_f = (_p = parameters.include).customChannelFields) !== null && _f !== void 0 ? _f : (_p.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS$1); + (_g = (_q = parameters.include).channelStatusField) !== null && _g !== void 0 ? _g : (_q.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD); + (_h = (_r = parameters.include).channelTypeField) !== null && _h !== void 0 ? _h : (_r.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD); + (_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT$4); + // Remap for backward compatibility. + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return RequestOperation$1.PNGetMembershipsOperation; + } + validate() { + if (!this.parameters.uuid) + return "'uuid' cannot be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}/channels`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + const includeFlags = []; + if (include.statusField) + includeFlags.push('status'); + if (include.customFields) + includeFlags.push('custom'); + if (include.channelFields) + includeFlags.push('channel'); + if (include.channelStatusField) + includeFlags.push('channel.status'); + if (include.channelTypeField) + includeFlags.push('channel.type'); + if (include.customChannelFields) + includeFlags.push('channel.custom'); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } + } + + /** + * Set UUID Memberships REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `Membership` custom field should be included in response or not. + */ + const INCLUDE_CUSTOM_FIELDS$7 = false; + /** + * Whether total number of memberships should be included in response or not. + */ + const INCLUDE_TOTAL_COUNT$2 = false; + /** + * Whether `Channel` fields should be included in response or not. + */ + const INCLUDE_CHANNEL_FIELDS = false; + /** + * Whether `Channel` custom field should be included in response or not. + */ + const INCLUDE_CHANNEL_CUSTOM_FIELDS = false; + /** + * Number of objects to return in response. + */ + const LIMIT$3 = 100; + // endregion + /** + * Set UUID Memberships request. + */ + class SetUUIDMembershipsRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f; + var _g, _h, _j, _k; + super({ method: TransportMethod.PATCH }); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS$7); + (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT$2); + (_d = (_j = parameters.include).channelFields) !== null && _d !== void 0 ? _d : (_j.channelFields = INCLUDE_CHANNEL_FIELDS); + (_e = (_k = parameters.include).customChannelFields) !== null && _e !== void 0 ? _e : (_k.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); + (_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT$3); + // Remap for backward compatibility. + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return RequestOperation$1.PNSetMembershipsOperation; + } + validate() { + const { uuid, channels } = this.parameters; + if (!uuid) + return "'uuid' cannot be empty"; + if (!channels || channels.length === 0) + return 'Channels cannot be empty'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}/channels`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + const includeFlags = ['channel.status', 'channel.type', 'status']; + if (include.customFields) + includeFlags.push('custom'); + if (include.channelFields) + includeFlags.push('channel'); + if (include.customChannelFields) + includeFlags.push('channel.custom'); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } + get body() { + const { channels, type } = this.parameters; + return JSON.stringify({ + [`${type}`]: channels.map((channel) => { + if (typeof channel === 'string') { + return { channel: { id: channel } }; + } + else { + return { channel: { id: channel.id }, status: channel.status, custom: channel.custom }; + } + }), + }); + } + } + + /** + * Get All UUID Metadata REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `Channel` custom field should be included by default or not. + */ + const INCLUDE_CUSTOM_FIELDS$6 = false; + /** + * Number of objects to return in response. + */ + const LIMIT$2 = 100; + // endregion + class GetAllUUIDMetadataRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c; + var _d; + super(); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_d = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_d.customFields = INCLUDE_CUSTOM_FIELDS$6); + (_c = parameters.limit) !== null && _c !== void 0 ? _c : (parameters.limit = LIMIT$2); + } + operation() { + return RequestOperation$1.PNGetAllUUIDMetadataOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + return `/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(',') }, (include.totalCount !== undefined ? { count: `${include.totalCount}` } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } + } + + /** + * Get Channel Metadata REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `Channel` custom field should be included by default or not. + */ + const INCLUDE_CUSTOM_FIELDS$5 = true; + // endregion + /** + * Get Channel Metadata request. + */ + class GetChannelMetadataRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c; + super(); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS$5); + } + operation() { + return RequestOperation$1.PNGetChannelMetadataOperation; + } + validate() { + if (!this.parameters.channel) + return 'Channel cannot be empty'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}`; + } + get queryParameters() { + return { + include: ['status', 'type', ...(this.parameters.include.customFields ? ['custom'] : [])].join(','), + }; + } + } + + /** + * Set Channel Metadata REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `Channel` custom field should be included by default or not. + */ + const INCLUDE_CUSTOM_FIELDS$4 = true; + // endregion + /** + * Set Channel Metadata request. + */ + class SetChannelMetadataRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c; + super({ method: TransportMethod.PATCH }); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS$4); + } + operation() { + return RequestOperation$1.PNSetChannelMetadataOperation; + } + validate() { + if (!this.parameters.channel) + return 'Channel cannot be empty'; + if (!this.parameters.data) + return 'Data cannot be empty'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}`; + } + get queryParameters() { + return { + include: ['status', 'type', ...(this.parameters.include.customFields ? ['custom'] : [])].join(','), + }; + } + get body() { + return JSON.stringify(this.parameters.data); + } + } + + /** + * Remove UUID Metadata REST API module. + */ + // endregion + /** + * Remove UUID Metadata request. + */ + class RemoveUUIDMetadataRequest extends AbstractRequest { + constructor(parameters) { + super({ method: TransportMethod.DELETE }); + this.parameters = parameters; + // Remap for backward compatibility. + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return RequestOperation$1.PNRemoveUUIDMetadataOperation; + } + validate() { + if (!this.parameters.uuid) + return "'uuid' cannot be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}`; + } + } + + /** + * Get Channel Members REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `Member` custom field should be included in response or not. + */ + const INCLUDE_CUSTOM_FIELDS$3 = false; + /** + * Whether member's status field should be included in response or not. + */ + const INCLUDE_STATUS = false; + /** + * Whether total number of members should be included in response or not. + */ + const INCLUDE_TOTAL_COUNT$1 = false; + /** + * Whether `UUID` fields should be included in response or not. + */ + const INCLUDE_UUID_FIELDS$1 = false; + /** + * Whether `UUID` status field should be included in response or not. + */ + const INCLUDE_UUID_STATUS_FIELD = false; + /** + * Whether `UUID` type field should be included in response or not. + */ + const INCLUDE_UUID_TYPE_FIELD = false; + /** + * Whether `UUID` custom field should be included in response or not. + */ + const INCLUDE_UUID_CUSTOM_FIELDS$1 = false; + /** + * Number of objects to return in response. + */ + const LIMIT$1 = 100; + // endregion + /** + * Get Channel Members request. + */ + class GetChannelMembersRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j; + var _k, _l, _m, _o, _p, _q, _r; + super(); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS$3); + (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT$1); + (_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS); + (_e = (_o = parameters.include).UUIDFields) !== null && _e !== void 0 ? _e : (_o.UUIDFields = INCLUDE_UUID_FIELDS$1); + (_f = (_p = parameters.include).customUUIDFields) !== null && _f !== void 0 ? _f : (_p.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS$1); + (_g = (_q = parameters.include).UUIDStatusField) !== null && _g !== void 0 ? _g : (_q.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD); + (_h = (_r = parameters.include).UUIDTypeField) !== null && _h !== void 0 ? _h : (_r.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD); + (_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT$1); + } + operation() { + return RequestOperation$1.PNSetMembersOperation; + } + validate() { + if (!this.parameters.channel) + return 'Channel cannot be empty'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}/uuids`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + const includeFlags = []; + if (include.statusField) + includeFlags.push('status'); + if (include.customFields) + includeFlags.push('custom'); + if (include.UUIDFields) + includeFlags.push('uuid'); + if (include.UUIDStatusField) + includeFlags.push('uuid.status'); + if (include.UUIDTypeField) + includeFlags.push('uuid.type'); + if (include.customUUIDFields) + includeFlags.push('uuid.custom'); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } + } + + /** + * Set Channel Members REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `Member` custom field should be included in response or not. + */ + const INCLUDE_CUSTOM_FIELDS$2 = false; + /** + * Whether total number of members should be included in response or not. + */ + const INCLUDE_TOTAL_COUNT = false; + /** + * Whether `UUID` fields should be included in response or not. + */ + const INCLUDE_UUID_FIELDS = false; + /** + * Whether `UUID` custom field should be included in response or not. + */ + const INCLUDE_UUID_CUSTOM_FIELDS = false; + /** + * Number of objects to return in response. + */ + const LIMIT = 100; + // endregion + /** + * Set Channel Members request. + */ + class SetChannelMembersRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f; + var _g, _h, _j, _k; + super({ method: TransportMethod.PATCH }); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS$2); + (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_j = parameters.include).UUIDFields) !== null && _d !== void 0 ? _d : (_j.UUIDFields = INCLUDE_UUID_FIELDS); + (_e = (_k = parameters.include).customUUIDFields) !== null && _e !== void 0 ? _e : (_k.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS); + (_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT); + } + operation() { + return RequestOperation$1.PNSetMembersOperation; + } + validate() { + const { channel, uuids } = this.parameters; + if (!channel) + return 'Channel cannot be empty'; + if (!uuids || uuids.length === 0) + return 'UUIDs cannot be empty'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}/uuids`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + const includeFlags = ['uuid.status', 'uuid.type', 'type']; + if (include.customFields) + includeFlags.push('custom'); + if (include.UUIDFields) + includeFlags.push('uuid'); + if (include.customUUIDFields) + includeFlags.push('uuid.custom'); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } + get body() { + const { uuids, type } = this.parameters; + return JSON.stringify({ + [`${type}`]: uuids.map((uuid) => { + if (typeof uuid === 'string') { + return { uuid: { id: uuid } }; + } + else { + return { uuid: { id: uuid.id }, status: uuid.status, custom: uuid.custom }; + } + }), + }); + } + } + + /** + * Get UUID Metadata REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether UUID custom field should be included by default or not. + */ + const INCLUDE_CUSTOM_FIELDS$1 = true; + // endregion + /** + * Get UUID Metadata request. + */ + class GetUUIDMetadataRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c; + super(); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS$1); + // Remap for backward compatibility. + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return RequestOperation$1.PNGetUUIDMetadataOperation; + } + validate() { + if (!this.parameters.uuid) + return "'uuid' cannot be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}`; + } + get queryParameters() { + const { include } = this.parameters; + return { include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(',') }; + } + } + + /** + * Set UUID Metadata REST API module. + */ + // -------------------------------------------------------- + // ----------------------- Defaults ----------------------- + // -------------------------------------------------------- + // region Defaults + /** + * Whether `Channel` custom field should be included by default or not. + */ + const INCLUDE_CUSTOM_FIELDS = true; + // endregion + /** + * Set UUID Metadata request. + */ + class SetUUIDMetadataRequest extends AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c; + super({ method: TransportMethod.PATCH }); + this.parameters = parameters; + // Apply default request parameters. + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); + // Remap for backward compatibility. + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return RequestOperation$1.PNSetUUIDMetadataOperation; + } + validate() { + if (!this.parameters.uuid) + return "'uuid' cannot be empty"; + if (!this.parameters.data) + return 'Data cannot be empty'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}`; + } + get queryParameters() { + return { + include: ['status', 'type', ...(this.parameters.include.customFields ? ['custom'] : [])].join(','), + }; + } + get body() { + return JSON.stringify(this.parameters.data); + } + } + + /** + * PubNub Objects API module. + */ + class PubNubObjects { + constructor(configuration, + /* eslint-disable @typescript-eslint/no-explicit-any */ + sendRequest) { + this.configuration = configuration; + this.sendRequest = sendRequest; + this.keySet = configuration.keySet; + } + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + */ + getAllUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._getAllUUIDMetadata(parametersOrCallback, callback); + }); + } + /** + * Fetch a paginated list of UUID Metadata objects. + * + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + */ + _getAllUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + // Get user request parameters. + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + const request = new GetAllUUIDMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Fetch a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + */ + getUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._getUUIDMetadata(parametersOrCallback, callback); + }); + } + /** + * Fetch a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + */ + _getUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + // Get user request parameters. + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new GetUUIDMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set UUID metadata response or `void` in case if `callback` provided. + */ + setUUIDMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._setUUIDMetadata(parameters, callback); + }); + } + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set UUID metadata response or `void` in case if `callback` provided. + */ + _setUUIDMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new SetUUIDMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Remove a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID metadata remove response or `void` in case if `callback` provided. + */ + removeUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._removeUUIDMetadata(parametersOrCallback, callback); + }); + } + /** + * Remove a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID metadata remove response or `void` in case if `callback` provided. + */ + _removeUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + // Get user request parameters. + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new RemoveUUIDMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Channel metadata response or `void` in case if `callback` + * provided. + */ + getAllChannelMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._getAllChannelMetadata(parametersOrCallback, callback); + }); + } + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Channel metadata response or `void` in case if `callback` + * provided. + */ + _getAllChannelMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + // Get user request parameters. + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + const request = new GetAllChannelsMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel metadata response or `void` in case if `callback` provided. + */ + getChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._getChannelMetadata(parameters, callback); + }); + } + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel metadata response or `void` in case if `callback` provided. + */ + _getChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new GetChannelMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set Channel metadata response or `void` in case if `callback` provided. + */ + setChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._setChannelMetadata(parameters, callback); + }); + } + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set Channel metadata response or `void` in case if `callback` provided. + */ + _setChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new SetChannelMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel metadata remove response or `void` in case if `callback` + * provided. + */ + removeChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._removeChannelMetadata(parameters, callback); + }); + } + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel metadata remove response or `void` in case if `callback` + * provided. + */ + _removeChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new RemoveChannelMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Fetch a paginated list of Channel Member objects. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel Members response or `void` in case if `callback` provided. + */ + getChannelMembers(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new GetChannelMembersRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Update specific Channel Members list. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update Channel members list response or `void` in case if `callback` + * provided. + */ + setChannelMembers(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new SetChannelMembersRequest(Object.assign(Object.assign({}, parameters), { type: 'set', keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Remove Members from the Channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel Members remove response or `void` in case if `callback` provided. + */ + removeChannelMembers(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new SetChannelMembersRequest(Object.assign(Object.assign({}, parameters), { type: 'delete', keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Fetch a specific UUID Memberships list. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID Memberships response or `void` in case if `callback` provided. + */ + getMemberships(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + // Get user request parameters. + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new GetUUIDMembershipsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Update specific UUID Memberships list. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update UUID Memberships list response or `void` in case if `callback` + * provided. + */ + setMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new SetUUIDMembershipsRequest(Object.assign(Object.assign({}, parameters), { type: 'set', keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Remove a specific UUID Memberships. + * + * @param parameters - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID Memberships remove response or `void` in case if `callback` + * provided. + */ + removeMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new SetUUIDMembershipsRequest(Object.assign(Object.assign({}, parameters), { type: 'delete', keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + // endregion + // endregion + // -------------------------------------------------------- + // --------------------- Deprecated API ------------------- + // -------------------------------------------------------- + // region Deprecated + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get specific Space members or specific User memberships response. + * + * @deprecated Use {@link PubNubObjects#getChannelMembers} or {@link PubNubObjects#getMemberships} methods instead. + */ + fetchMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b; + if ('spaceId' in parameters) { + const spaceParameters = parameters; + const mappedParameters = { + channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, + filter: spaceParameters.filter, + limit: spaceParameters.limit, + page: spaceParameters.page, + include: Object.assign({}, spaceParameters.include), + sort: spaceParameters.sort + ? Object.fromEntries(Object.entries(spaceParameters.sort).map(([key, value]) => [key.replace('user', 'uuid'), value])) + : undefined, + }; + // Map Members object to the older version. + const mapMembers = (response) => ({ + status: response.status, + data: response.data.map((members) => ({ + user: members.uuid, + custom: members.custom, + updated: members.updated, + eTag: members.eTag, + })), + totalCount: response.totalCount, + next: response.next, + prev: response.prev, + }); + if (callback) + return this.getChannelMembers(mappedParameters, (status, result) => { + callback(status, result ? mapMembers(result) : result); + }); + return this.getChannelMembers(mappedParameters).then(mapMembers); + } + const userParameters = parameters; + const mappedParameters = { + uuid: (_b = userParameters.userId) !== null && _b !== void 0 ? _b : userParameters.uuid, + filter: userParameters.filter, + limit: userParameters.limit, + page: userParameters.page, + include: Object.assign({}, userParameters.include), + sort: userParameters.sort + ? Object.fromEntries(Object.entries(userParameters.sort).map(([key, value]) => [key.replace('space', 'channel'), value])) + : undefined, + }; + // Map Memberships object to the older version. + const mapMemberships = (response) => ({ + status: response.status, + data: response.data.map((membership) => ({ + space: membership.channel, + custom: membership.custom, + updated: membership.updated, + eTag: membership.eTag, + })), + totalCount: response.totalCount, + next: response.next, + prev: response.prev, + }); + if (callback) + return this.getMemberships(mappedParameters, (status, result) => { + callback(status, result ? mapMemberships(result) : result); + }); + return this.getMemberships(mappedParameters).then(mapMemberships); + }); + } + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add members to specific Space or memberships specific User response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubObjects#setChannelMembers} or {@link PubNubObjects#setMemberships} methods instead. + */ + addMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b, _c, _d, _e, _f; + if ('spaceId' in parameters) { + const spaceParameters = parameters; + const mappedParameters = { + channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, + uuids: (_c = (_b = spaceParameters.users) === null || _b === void 0 ? void 0 : _b.map((user) => { + if (typeof user === 'string') + return user; + user.userId; + return { id: user.userId, custom: user.custom }; + })) !== null && _c !== void 0 ? _c : spaceParameters.uuids, + limit: 0, + }; + if (callback) + return this.setChannelMembers(mappedParameters, callback); + return this.setChannelMembers(mappedParameters); + } + const userParameters = parameters; + const mappedParameters = { + uuid: (_d = userParameters.userId) !== null && _d !== void 0 ? _d : userParameters.uuid, + channels: (_f = (_e = userParameters.spaces) === null || _e === void 0 ? void 0 : _e.map((space) => { + if (typeof space === 'string') + return space; + return { + id: space.spaceId, + custom: space.custom, + }; + })) !== null && _f !== void 0 ? _f : userParameters.channels, + limit: 0, + }; + if (callback) + return this.setMemberships(mappedParameters, callback); + return this.setMemberships(mappedParameters); + }); + } + } + + /** + * Time REST API module. + */ + // endregion + class TimeRequest extends AbstractRequest { + constructor() { + super(); + } + operation() { + return RequestOperation$1.PNTimeOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + return { timetoken: serviceResponse[0] }; + }); + } + get path() { + return '/time/0'; + } + } + + /** + * Download File REST API module. + */ + // endregion + /** + * Download File request. + */ + class DownloadFileRequest extends AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return RequestOperation$1.PNDownloadFileOperation; + } + validate() { + const { channel, id, name } = this.parameters; + if (!channel) + return "channel can't be empty"; + if (!id) + return "file id can't be empty"; + if (!name) + return "file name can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const { cipherKey, crypto, cryptography, name, PubNubFile } = this.parameters; + const mimeType = response.headers['content-type']; + let decryptedFile; + let body = response.body; + if (PubNubFile.supportsEncryptFile && (cipherKey || crypto)) { + if (cipherKey && cryptography) + body = yield cryptography.decrypt(cipherKey, body); + else if (!cipherKey && crypto) + decryptedFile = yield crypto.decryptFile(PubNubFile.create({ data: body, name: name, mimeType }), PubNubFile); + } + return (decryptedFile + ? decryptedFile + : PubNubFile.create({ + data: body, + name, + mimeType, + })); + }); + } + get path() { + const { keySet: { subscribeKey }, channel, id, name, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files/${id}/${name}`; + } + } + + // endregion + /** + * Platform-agnostic PubNub client core. + */ + class PubNubCore { + /** + * Construct notification payload which will trigger push notification. + * + * @param title - Title which will be shown on notification. + * @param body - Payload which will be sent as part of notification. + * + * @returns Pre-formatted message payload which will trigger push notification. + */ + static notificationPayload(title, body) { + return new NotificationsPayload(title, body); + } + /** + * Generate unique identifier. + * + * @returns Unique identifier. + */ + static generateUUID() { + return uuidGenerator.createUUID(); + } + // endregion + constructor(configuration) { + this._configuration = configuration.configuration; + this.cryptography = configuration.cryptography; + this.tokenManager = configuration.tokenManager; + this.transport = configuration.transport; + this.crypto = configuration.crypto; + // API group entry points initialization. + this._objects = new PubNubObjects(this._configuration, this.sendRequest.bind(this)); + this._channelGroups = new PubnubChannelGroups(this._configuration.keySet, this.sendRequest.bind(this)); + this._push = new PubNubPushNotifications(this._configuration.keySet, this.sendRequest.bind(this)); + // Prepare for real-time events announcement. + this.listenerManager = new ListenerManager(); + this.eventEmitter = new EventEmitter(this.listenerManager); + if (this._configuration.enableEventEngine) { + let heartbeatInterval = this._configuration.getHeartbeatInterval(); + this.presenceState = {}; + if (heartbeatInterval) { + this.presenceEventEngine = new PresenceEventEngine({ + heartbeat: this.heartbeat.bind(this), + leave: (parameters) => this.makeUnsubscribe(parameters, () => { }), + heartbeatDelay: () => new Promise((resolve, reject) => { + heartbeatInterval = this._configuration.getHeartbeatInterval(); + if (!heartbeatInterval) + reject(new PubNubError('Heartbeat interval has been reset.')); + else + setTimeout(resolve, heartbeatInterval * 1000); + }), + retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + emitStatus: (status) => this.listenerManager.announceStatus(status), + config: this._configuration, + presenceState: this.presenceState, + }); + } + this.eventEngine = new EventEngine({ + handshake: this.subscribeHandshake.bind(this), + receiveMessages: this.subscribeReceiveMessages.bind(this), + delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + join: this.join.bind(this), + leave: this.leave.bind(this), + leaveAll: this.leaveAll.bind(this), + presenceState: this.presenceState, + config: this._configuration, + emitMessages: (events) => { + try { + events.forEach((event) => this.eventEmitter.emitEvent(event)); + } + catch (e) { + const errorStatus = { + error: true, + category: StatusCategory$1.PNUnknownCategory, + errorData: e, + statusCode: 0, + }; + this.listenerManager.announceStatus(errorStatus); + } + }, + emitStatus: (status) => this.listenerManager.announceStatus(status), + }); + } + else { + this.subscriptionManager = new SubscriptionManager(this._configuration, this.listenerManager, this.eventEmitter, this.makeSubscribe.bind(this), this.heartbeat.bind(this), this.makeUnsubscribe.bind(this), this.time.bind(this)); + } + } + // -------------------------------------------------------- + // -------------------- Configuration ---------------------- + // -------------------------------------------------------- + // region Configuration + /** + * PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + */ + get configuration() { + return this._configuration; + } + /** + * Current PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + * + * @deprecated Use {@link configuration} getter instead. + */ + get _config() { + return this.configuration; + } + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ + get authKey() { + var _a; + return (_a = this._configuration.authKey) !== null && _a !== void 0 ? _a : undefined; + } + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ + getAuthKey() { + return this.authKey; + } + /** + * Change REST API endpoint access authorization key. + * + * @param authKey - New authorization key which should be used with new requests. + */ + setAuthKey(authKey) { + this._configuration.setAuthKey(authKey); + } + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + get userId() { + return this._configuration.userId; + } + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + set userId(value) { + if (!value || typeof value !== 'string' || value.trim().length === 0) + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); + this._configuration.userId = value; + } + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + getUserId() { + return this._configuration.userId; + } + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + setUserId(value) { + if (!value || typeof value !== 'string' || value.trim().length === 0) + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); + this._configuration.userId = value; + } + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + get filterExpression() { + var _a; + return (_a = this._configuration.getFilterExpression()) !== null && _a !== void 0 ? _a : undefined; + } + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + getFilterExpression() { + return this.filterExpression; + } + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + set filterExpression(expression) { + this._configuration.setFilterExpression(expression); + } + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + setFilterExpression(expression) { + this.filterExpression = expression; + } + /** + * Dta encryption / decryption key. + * + * @returns Currently used key for data encryption / decryption. + */ + get cipherKey() { + return this._configuration.getCipherKey(); + } + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + set cipherKey(key) { + this._configuration.setCipherKey(key); + } + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + setCipherKey(key) { + this.cipherKey = key; + } + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ + set heartbeatInterval(interval) { + this._configuration.setHeartbeatInterval(interval); + } + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ + setHeartbeatInterval(interval) { + this.heartbeatInterval = interval; + } + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + getVersion() { + return this._configuration.getVersion(); + } + /** + * Add framework's prefix. + * + * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. + * @param suffix - Suffix with information about framework. + */ + _addPnsdkSuffix(name, suffix) { + this._configuration._addPnsdkSuffix(name, suffix); + } + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + * + * @deprecated Use the {@link getUserId} or {@link userId} getter instead. + */ + getUUID() { + return this.userId; + } + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + * + * @deprecated Use the {@link PubNubCore#setUserId} or {@link PubNubCore#userId} setter instead. + */ + setUUID(value) { + this.userId = value; + } + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + get customEncrypt() { + return this._configuration.getCustomEncrypt(); + } + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + get customDecrypt() { + return this._configuration.getCustomDecrypt(); + } + // endregion + // endregion + // -------------------------------------------------------- + // ---------------------- Entities ------------------------ + // -------------------------------------------------------- + // region Entities + /** + * Create a `Channel` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel name. + * @returns `Channel` entity. + */ + channel(name) { + return new Channel(name, this.eventEmitter, this); + } + /** + * Create a `ChannelGroup` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel group name. + * @returns `ChannelGroup` entity. + */ + channelGroup(name) { + return new ChannelGroup(name, this.eventEmitter, this); + } + /** + * Create a `ChannelMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique channel metadata object identifier. + * @returns `ChannelMetadata` entity. + */ + channelMetadata(id) { + return new ChannelMetadata(id, this.eventEmitter, this); + } + /** + * Create a `UserMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique user metadata object identifier. + * @returns `UserMetadata` entity. + */ + userMetadata(id) { + return new UserMetadata(id, this.eventEmitter, this); + } + /** + * Create subscriptions set object. + * + * @param parameters - Subscriptions set configuration parameters. + */ + subscriptionSet(parameters) { + return new SubscriptionSet(Object.assign(Object.assign({}, parameters), { eventEmitter: this.eventEmitter, pubnub: this })); + } + /** + * Schedule request execution. + * + * @param request - REST API request. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous request execution and response parsing result or `void` in case if + * `callback` provided. + * + * @throws PubNubError in case of request processing error. + */ + sendRequest(request, callback) { + return __awaiter(this, void 0, void 0, function* () { + // Validate user-input. + const validationResult = request.validate(); + if (validationResult) { + if (callback) + return callback(createValidationError(validationResult), null); + throw new PubNubError('Validation failed, check status for details', createValidationError(validationResult)); + } + // Complete request configuration. + const transportRequest = request.request(); + if (transportRequest.formData && transportRequest.formData.length > 0) { + // Set 300 seconds file upload request delay. + transportRequest.timeout = 300; + } + else { + if (request.operation() === RequestOperation$1.PNSubscribeOperation) + transportRequest.timeout = this._configuration.getSubscribeTimeout(); + else + transportRequest.timeout = this._configuration.getTransactionTimeout(); + } + // API request processing status. + const status = { + error: false, + operation: request.operation(), + category: StatusCategory$1.PNAcknowledgmentCategory, + statusCode: 0, + }; + const [sendableRequest, cancellationController] = this.transport.makeSendable(transportRequest); + /** + * **Important:** Because of multiple environments where JS SDK can be used control over + * cancellation had to be inverted to let transport provider solve request cancellation task + * more efficiently. As result, cancellation controller can be retrieved and used only after + * request will be scheduled by transport provider. + */ + request.cancellationController = cancellationController ? cancellationController : null; + return sendableRequest + .then((response) => { + status.statusCode = response.status; + // Handle special case when request completed but not fully processed by PubNub service. + if (response.status !== 200 && response.status !== 204) { + const contentType = response.headers['content-type']; + if (contentType || contentType.indexOf('javascript') !== -1 || contentType.indexOf('json') !== -1) { + const json = JSON.parse(PubNubCore.decoder.decode(response.body)); + if (typeof json === 'object' && 'error' in json && json.error && typeof json.error === 'object') + status.errorData = json.error; + } + } + return request.parse(response); + }) + .then((parsed) => { + // Notify callback (if possible). + if (callback) + return callback(status, parsed); + return parsed; + }) + .catch((error) => { + const apiError = !(error instanceof PubNubAPIError) ? PubNubAPIError.create(error) : error; + // Notify callback (if possible). + if (callback) + return callback(apiError.toStatus(request.operation()), null); + throw apiError.toPubNubError(request.operation(), 'REST API request processing error, check status for details'); + }); + }); + } + /** + * Unsubscribe from all channels and groups. + * + * @param [isOffline] - Whether `offline` presence should be notified or not. + */ + destroy(isOffline) { + if (this.subscriptionManager) { + this.subscriptionManager.unsubscribeAll(isOffline); + this.subscriptionManager.disconnect(); + } + else if (this.eventEngine) + this.eventEngine.dispose(); + } + /** + * Unsubscribe from all channels and groups. + * + * @deprecated Use {@link destroy} method instead. + */ + stop() { + this.destroy(); + } + // endregion + // -------------------------------------------------------- + // ----------------------- Listener ----------------------- + // -------------------------------------------------------- + // region Listener + /** + * Register real-time events listener. + * + * @param listener - Listener with event callbacks to handle different types of events. + */ + addListener(listener) { + this.listenerManager.addListener(listener); + } + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + */ + removeListener(listener) { + this.listenerManager.removeListener(listener); + } + /** + * Clear all real-time event listeners. + */ + removeAllListeners() { + this.listenerManager.removeAllListeners(); + } + /** + * Publish data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous publish data response or `void` in case if `callback` provided. + */ + publish(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new PublishRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Signal data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous signal data response or `void` in case if `callback` provided. + */ + signal(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new SignalRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * `Fire` a data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous signal data response or `void` in case if `callback` provided. + * + * @deprecated Use {@link publish} method instead. + */ + fire(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + callback !== null && callback !== void 0 ? callback : (callback = () => { }); + return this.publish(Object.assign(Object.assign({}, parameters), { replicate: false, storeInHistory: false }), callback); + }); + } + // endregion + // -------------------------------------------------------- + // -------------------- Subscribe API --------------------- + // -------------------------------------------------------- + // region Subscribe API + /** + * Get list of channels on which PubNub client currently subscribed. + * + * @returns List of active channels. + */ + getSubscribedChannels() { + if (this.subscriptionManager) + return this.subscriptionManager.subscribedChannels; + else if (this.eventEngine) + return this.eventEngine.getSubscribedChannels(); + return []; + } + /** + * Get list of channel groups on which PubNub client currently subscribed. + * + * @returns List of active channel groups. + */ + getSubscribedChannelGroups() { + if (this.subscriptionManager) + return this.subscriptionManager.subscribedChannelGroups; + else if (this.eventEngine) + return this.eventEngine.getSubscribedChannelGroups(); + return []; + } + /** + * Subscribe to specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ + subscribe(parameters) { + if (this.subscriptionManager) + this.subscriptionManager.subscribe(parameters); + else if (this.eventEngine) + this.eventEngine.subscribe(parameters); + } + /** + * Perform subscribe request. + * + * **Note:** Method passed into managers to let them use it when required. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + makeSubscribe(parameters, callback) { + const request = new SubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + this.sendRequest(request, (status, result) => { + var _a; + if (this.subscriptionManager && ((_a = this.subscriptionManager.abort) === null || _a === void 0 ? void 0 : _a.identifier) === request.requestIdentifier) + this.subscriptionManager.abort = null; + callback(status, result); + }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + if (this.subscriptionManager) { + // Creating identifiable abort caller. + const callableAbort = () => request.abort(); + callableAbort.identifier = request.requestIdentifier; + this.subscriptionManager.abort = callableAbort; + } + } + /** + * Unsubscribe from specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ + unsubscribe(parameters) { + if (this.subscriptionManager) + this.subscriptionManager.unsubscribe(parameters); + else if (this.eventEngine) + this.eventEngine.unsubscribe(parameters); + } + /** + * Perform unsubscribe request. + * + * **Note:** Method passed into managers to let them use it when required. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + makeUnsubscribe(parameters, callback) { + this.sendRequest(new PresenceLeaveRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })), callback); + } + /** + * Unsubscribe from all channels and groups. + */ + unsubscribeAll() { + if (this.subscriptionManager) + this.subscriptionManager.unsubscribeAll(); + else if (this.eventEngine) + this.eventEngine.unsubscribeAll(); + } + /** + * Temporarily disconnect from real-time events stream. + */ + disconnect() { + if (this.subscriptionManager) + this.subscriptionManager.disconnect(); + else if (this.eventEngine) + this.eventEngine.disconnect(); + } + /** + * Restore connection to the real-time events stream. + * + * @param parameters - Reconnection catch up configuration. **Note:** available only with + * enabled event engine. + */ + reconnect(parameters) { + if (this.subscriptionManager) + this.subscriptionManager.reconnect(); + else if (this.eventEngine) + this.eventEngine.reconnect(parameters !== null && parameters !== void 0 ? parameters : {}); + } + /** + * Event engine handshake subscribe. + * + * @param parameters - Request configuration parameters. + */ + subscribeHandshake(parameters) { + return __awaiter(this, void 0, void 0, function* () { + const request = new HandshakeSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response.cursor; + }); + }); + } + /** + * Event engine receive messages subscribe. + * + * @param parameters - Request configuration parameters. + */ + subscribeReceiveMessages(parameters) { + return __awaiter(this, void 0, void 0, function* () { + const request = new ReceiveMessagesSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response; + }); + }); + } + /** + * Get reactions to a specific message. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get reactions response or `void` in case if `callback` provided. + */ + getMessageActions(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new GetMessageActionsRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Add a reaction to a specific message. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add a reaction response or `void` in case if `callback` provided. + */ + addMessageAction(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new AddMessageActionRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Remove a reaction from a specific message. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous remove a reaction response or `void` in case if `callback` provided. + */ + removeMessageAction(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new RemoveMessageAction(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Fetch messages history for channels. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous fetch messages response or `void` in case if `callback` provided. + */ + fetchMessages(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new FetchMessagesRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Delete messages from the channel history. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous delete messages response or `void` in case if `callback` provided. + * + * @deprecated + */ + deleteMessages(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new DeleteMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Count messages from the channels' history. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous count messages response or `void` in case if `callback` provided. + */ + messageCounts(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new MessageCountRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Fetch single channel history. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous fetch channel history response or `void` in case if `callback` provided. + * + * @deprecated + */ + history(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new GetHistoryRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Get channel's presence information. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get channel's presence response or `void` in case if `callback` provided. + */ + hereNow(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new HereNowRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Get user's presence information. + * + * Get list of channels to which `uuid` currently subscribed. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get user's presence response or `void` in case if `callback` provided. + */ + whereNow(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const request = new WhereNowRequest({ + uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, + keySet: this._configuration.keySet, + }); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Get associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get user's data response or `void` in case if `callback` provided. + */ + getState(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const request = new GetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Set associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set user's data response or `void` in case if `callback` provided. + */ + setState(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b; + const { keySet, userId: userId } = this._configuration; + const heartbeat = this._configuration.getPresenceTimeout(); + let request; + // Maintain presence information (if required). + if (this._configuration.enableEventEngine && this.presenceState) { + const presenceState = this.presenceState; + (_a = parameters.channels) === null || _a === void 0 ? void 0 : _a.forEach((channel) => (presenceState[channel] = parameters.state)); + if ('channelGroups' in parameters) { + (_b = parameters.channelGroups) === null || _b === void 0 ? void 0 : _b.forEach((group) => (presenceState[group] = parameters.state)); + } + } + // Check whether state should be set with heartbeat or not. + if ('withHeartbeat' in parameters) { + request = new HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet, heartbeat })); + } + else { + request = new SetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { keySet, uuid: userId })); + } + // Update state used by subscription manager. + if (this.subscriptionManager) + this.subscriptionManager.setState(parameters); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + // endregion + // region Change presence state + /** + * Manual presence management. + * + * @param parameters - Desired presence state for provided list of channels and groups. + */ + presence(parameters) { + var _a; + (_a = this.subscriptionManager) === null || _a === void 0 ? void 0 : _a.changePresence(parameters); + } + // endregion + // region Heartbeat + /** + * Announce user presence + * + * @param parameters - Desired presence state for provided list of channels and groups. + * @param callback - Request completion handler callback. + */ + heartbeat(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + // endregion + // region Join + /** + * Announce user `join` on specified list of channels and groups. + * + * @param parameters - List of channels and groups where `join` event should be sent. + */ + join(parameters) { + var _a; + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.join(parameters); + } + // endregion + // region Leave + /** + * Announce user `leave` on specified list of channels and groups. + * + * @param parameters - List of channels and groups where `leave` event should be sent. + */ + leave(parameters) { + var _a; + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leave(parameters); + } + /** + * Announce user `leave` on all subscribed channels. + */ + leaveAll() { + var _a; + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leaveAll(); + } + /** + * Grant token permission. + * + * Generate access token with requested permissions. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous grant token response or `void` in case if `callback` provided. + */ + grantToken(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new GrantTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Revoke token permission. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous revoke token response or `void` in case if `callback` provided. + */ + revokeToken(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new RevokeTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + // endregion + // region Token Manipulation + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ + get token() { + return this.tokenManager.getToken(); + } + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ + getToken() { + return this.token; + } + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ + set token(token) { + this.tokenManager.setToken(token); + } + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ + setToken(token) { + this.token = token; + } + /** + * Parse access token. + * + * Parse token to see what permissions token owner has. + * + * @param token - Token which should be parsed. + * + * @returns Token's permissions information for the resources. + */ + parseToken(token) { + return this.tokenManager.parseToken(token); + } + /** + * Grant auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous grant auth key(s) permissions or `void` in case if `callback` provided. + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + grant(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new GrantRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Audit auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @deprecated + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + audit(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new AuditRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + // endregion + // endregion + // endregion + // -------------------------------------------------------- + // ------------------- App Context API -------------------- + // -------------------------------------------------------- + // region App Context API + /** + * PubNub App Context API group. + */ + get objects() { + return this._objects; + } + /** + Fetch a paginated list of User objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all User objects response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + fetchUsers(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._getAllUUIDMetadata(parametersOrCallback, callback); + }); + } + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get User object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + fetchUser(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._getUUIDMetadata(parametersOrCallback, callback); + }); + } + /** + * Create User object. + * + * @param parameters - Request configuration parameters. Will create User object for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous create User object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + createUser(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._setUUIDMetadata(parameters, callback); + }); + } + /** + * Update User object. + * + * @param parameters - Request configuration parameters. Will update User object for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update User object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + updateUser(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._setUUIDMetadata(parameters, callback); + }); + } + /** + * Remove a specific User object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous User object remove response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + removeUser(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._removeUUIDMetadata(parametersOrCallback, callback); + }); + } + /** + * Fetch a paginated list of Space objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Space objects response or `void` in case if `callback` + * provided. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + fetchSpaces(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._getAllChannelMetadata(parametersOrCallback, callback); + }); + } + /** + * Fetch a specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Space object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. + */ + fetchSpace(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._getChannelMetadata(parameters, callback); + }); + } + /** + * Create specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous create Space object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + createSpace(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._setChannelMetadata(parameters, callback); + }); + } + /** + * Update specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update Space object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + updateSpace(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._setChannelMetadata(parameters, callback); + }); + } + /** + * Remove a specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Space object remove response or `void` in case if `callback` + * provided. + * + * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. + */ + removeSpace(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._removeChannelMetadata(parameters, callback); + }); + } + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get specific Space members or specific User memberships response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} + * methods instead. + */ + fetchMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects.fetchMemberships(parameters, callback); + }); + } + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add members to specific Space or memberships specific User response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + addMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects.addMemberships(parameters, callback); + }); + } + /** + * Update specific Space members or User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update Space members or User memberships response or `void` in case + * if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + updateMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects.addMemberships(parameters, callback); + }); + } + /** + * Remove User membership. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous memberships modification response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} + * methods instead + * from `objects` API group.. + */ + removeMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b, _c; + if ('spaceId' in parameters) { + const spaceParameters = parameters; + const requestParameters = { + channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, + uuids: (_b = spaceParameters.userIds) !== null && _b !== void 0 ? _b : spaceParameters.uuids, + limit: 0, + }; + if (callback) + return this.objects.removeChannelMembers(requestParameters, callback); + return this.objects.removeChannelMembers(requestParameters); + } + const userParameters = parameters; + const requestParameters = { + uuid: userParameters.userId, + channels: (_c = userParameters.spaceIds) !== null && _c !== void 0 ? _c : userParameters.channels, + limit: 0, + }; + if (callback) + return this.objects.removeMemberships(requestParameters, callback); + return this.objects.removeMemberships(requestParameters); + }); + } + // endregion + // endregion + // -------------------------------------------------------- + // ----------------- Channel Groups API ------------------- + // -------------------------------------------------------- + // region Channel Groups API + /** + * PubNub Channel Groups API group. + */ + get channelGroups() { + return this._channelGroups; + } + // endregion + // -------------------------------------------------------- + // ---------------- Push Notifications API ----------------- + // -------------------------------------------------------- + // region Push Notifications API + /** + * PubNub Push Notifications API group. + */ + get push() { + return this._push; + } + /** + * Share file to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous file sharing response or `void` in case if `callback` provided. + */ + sendFile(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const sendFileRequest = new SendFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, fileUploadPublishRetryLimit: this._configuration.fileUploadPublishRetryLimit, file: parameters.file, sendRequest: this.sendRequest.bind(this), publishFile: this.publishFile.bind(this), crypto: this._configuration.getCryptoModule(), cryptography: this.cryptography ? this.cryptography : undefined })); + const status = { + error: false, + operation: RequestOperation$1.PNPublishFileOperation, + category: StatusCategory$1.PNAcknowledgmentCategory, + statusCode: 0, + }; + return sendFileRequest + .process() + .then((response) => { + status.statusCode = response.status; + if (callback) + return callback(status, response); + return response; + }) + .catch((error) => { + let errorStatus; + if (error instanceof PubNubError) + errorStatus = error.status; + else if (error instanceof PubNubAPIError) + errorStatus = error.toStatus(status.operation); + // Notify callback (if possible). + if (callback && errorStatus) + callback(errorStatus, null); + throw new PubNubError('REST API request processing error, check status for details', errorStatus); + }); + }); + } + /** + * Publish file message to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous publish file message response or `void` in case if `callback` provided. + */ + publishFile(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const request = new PublishFileMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + * Retrieve list of shared files in specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous shared files list response or `void` in case if `callback` provided. + */ + listFiles(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new FilesListRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + // endregion + // region Get Download Url + /** + * Get file download Url. + * + * @param parameters - Request configuration parameters. + * + * @returns File download Url. + */ + getFileUrl(parameters) { + var _a; + const request = this.transport.request(new GetFileDownloadUrlRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })).request()); + const query = (_a = request.queryParameters) !== null && _a !== void 0 ? _a : {}; + const queryString = Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${encodeString(queryValue)}`; + return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); + }) + .join('&'); + return `${request.origin}${request.path}?${queryString}`; + } + /** + * Download shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous download shared file response or `void` in case if `callback` provided. + */ + downloadFile(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const request = new DownloadFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, cryptography: this.cryptography ? this.cryptography : undefined, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return (yield this.sendRequest(request)); + }); + } + /** + * Delete shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous delete shared file response or `void` in case if `callback` provided. + */ + deleteFile(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new DeleteFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + /** + Get current high-precision timetoken. + * + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get current timetoken response or `void` in case if `callback` provided. + */ + time(callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new TimeRequest(); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + // endregion + // -------------------------------------------------------- + // ------------------ Cryptography API -------------------- + // -------------------------------------------------------- + // region Cryptography + // region Common + /** + * Encrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @deprecated + * @param [customCipherKey] - Cipher key which should be used to encrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data encryption result as a string. + */ + encrypt(data, customCipherKey) { + const cryptoModule = this._configuration.getCryptoModule(); + if (!customCipherKey && cryptoModule && typeof data === 'string') { + const encrypted = cryptoModule.encrypt(data); + return typeof encrypted === 'string' ? encrypted : encode(encrypted); + } + if (!this.crypto) + throw new Error('Encryption error: cypher key not set'); + return this.crypto.encrypt(data, customCipherKey); + } + /** + * Decrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @param [customCipherKey] - Cipher key which should be used to decrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data decryption result as an object. + */ + decrypt(data, customCipherKey) { + const cryptoModule = this._configuration.getCryptoModule(); + if (!customCipherKey && cryptoModule) { + const decrypted = cryptoModule.decrypt(data); + return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted; + } + if (!this.crypto) + throw new Error('Decryption error: cypher key not set'); + return this.crypto.decrypt(data, customCipherKey); + } + /** + * Encrypt file content. + * + * @param keyOrFile - Cipher key which should be used to encrypt data or file which should be + * encrypted using `CryptoModule`. + * @param [file] - File which should be encrypted using legacy cryptography. + * + * @returns Asynchronous file encryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + encryptFile(keyOrFile, file) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (typeof keyOrFile !== 'string') + file = keyOrFile; + if (!file) + throw new Error('File encryption error. Source file is missing.'); + if (!this._configuration.PubNubFile) + throw new Error('File encryption error. File constructor not configured.'); + if (typeof keyOrFile !== 'string' && !this._configuration.getCryptoModule()) + throw new Error('File encryption error. Crypto module not configured.'); + if (typeof keyOrFile === 'string') { + if (!this.cryptography) + throw new Error('File encryption error. File encryption not available'); + return this.cryptography.encryptFile(keyOrFile, file, this._configuration.PubNubFile); + } + return (_a = this._configuration.getCryptoModule()) === null || _a === void 0 ? void 0 : _a.encryptFile(file, this._configuration.PubNubFile); + }); + } + /** + * Decrypt file content. + * + * @param keyOrFile - Cipher key which should be used to decrypt data or file which should be + * decrypted using `CryptoModule`. + * @param [file] - File which should be decrypted using legacy cryptography. + * + * @returns Asynchronous file decryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + decryptFile(keyOrFile, file) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (typeof keyOrFile !== 'string') + file = keyOrFile; + if (!file) + throw new Error('File encryption error. Source file is missing.'); + if (!this._configuration.PubNubFile) + throw new Error('File decryption error. File constructor' + ' not configured.'); + if (typeof keyOrFile === 'string' && !this._configuration.getCryptoModule()) + throw new Error('File decryption error. Crypto module not configured.'); + if (typeof keyOrFile === 'string') { + if (!this.cryptography) + throw new Error('File decryption error. File decryption not available'); + return this.cryptography.decryptFile(keyOrFile, file, this._configuration.PubNubFile); + } + return (_a = this._configuration.getCryptoModule()) === null || _a === void 0 ? void 0 : _a.decryptFile(file, this._configuration.PubNubFile); + }); + } + } + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + PubNubCore.decoder = new TextDecoder(); + // -------------------------------------------------------- + // ----------------------- Static ------------------------- + // -------------------------------------------------------- + // region Static + /** + * Type of REST API endpoint which reported status. + */ + PubNubCore.OPERATIONS = RequestOperation$1; + /** + * API call status category. + */ + PubNubCore.CATEGORIES = StatusCategory$1; + /** + * Exponential retry policy constructor. + */ + PubNubCore.ExponentialRetryPolicy = RetryPolicy.ExponentialRetryPolicy; + /** + * Linear retry policy constructor. + */ + PubNubCore.LinearRetryPolicy = RetryPolicy.LinearRetryPolicy; + + /** + * Cbor decoder module. + */ + /** + * CBOR data decoder. + */ + class Cbor { + constructor(decode, base64ToBinary) { + this.decode = decode; + this.base64ToBinary = base64ToBinary; + } + /** + * Decode CBOR base64-encoded object. + * + * @param tokenString - Base64-encoded token. + * + * @returns Token object decoded from CBOR. + */ + decodeToken(tokenString) { + let padding = ''; + if (tokenString.length % 4 === 3) + padding = '='; + else if (tokenString.length % 4 === 2) + padding = '=='; + const cleaned = tokenString.replace(/-/gi, '+').replace(/_/gi, '/') + padding; + const result = this.decode(this.base64ToBinary(cleaned)); + return typeof result === 'object' ? result : undefined; + } + } + + /* eslint no-bitwise: ["error", { "allow": ["~", "&", ">>"] }] */ + /* global navigator */ + /** + * PubNub client for browser platform. + */ + class PubNub extends PubNubCore { + constructor(configuration) { + var _a; + const configurationCopy = setDefaults(configuration); + const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'Web', PubNubFile }); + // Prepare full client configuration. + const clientConfiguration = makeConfiguration(platformConfiguration, (cryptoConfiguration) => { + if (!cryptoConfiguration.cipherKey) + return undefined; + return new WebCryptoModule({ + default: new LegacyCryptor(Object.assign({}, cryptoConfiguration)), + cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], + }); + }); + // Prepare Token manager. + const tokenManager = new TokenManager(new Cbor((arrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode)); + // Legacy crypto (legacy data encryption / decryption and request signature support). + let crypto; + if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { + crypto = new Crypto({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } + // Setup transport provider. + let transport = new WebReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity); + if (configurationCopy.enableServiceWorker) { + // Inject subscription service worker into transport provider stack. + transport = new SubscriptionServiceWorkerMiddleware({ + clientIdentifier: clientConfiguration._instanceId, + subscriptionKey: clientConfiguration.subscribeKey, + sdkVersion: clientConfiguration.getVersion(), + logVerbosity: clientConfiguration.logVerbosity, + transport, + }); + } + const transportMiddleware = new PubNubMiddleware({ + clientConfiguration, + tokenManager, + transport, + }); + super({ + configuration: clientConfiguration, + transport: transportMiddleware, + cryptography: new WebCryptography(), + tokenManager, + crypto, + }); + if ((_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : true) { + window.addEventListener('offline', () => { + this.networkDownDetected(); + }); + window.addEventListener('online', () => { + this.networkUpDetected(); + }); + } + } + networkDownDetected() { + this.listenerManager.announceNetworkDown(); + if (this._configuration.restore) + this.disconnect(); + else + this.destroy(true); + } + networkUpDetected() { + this.listenerManager.announceNetworkUp(); + this.reconnect(); + } + } + /** + * Data encryption / decryption module constructor. + */ + PubNub.CryptoModule = WebCryptoModule; + + return PubNub; })); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 9efac6f66..4e1a1a155 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,17 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict"; -/*! ***************************************************************************** - Copyright (c) Microsoft Corporation. - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH - REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM - LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR - OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - PERFORMANCE OF THIS SOFTWARE. - ***************************************************************************** */var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};function t(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}var n=function(){return n=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function a(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s}function u(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o>2,c=0;c>6),o.push(128|63&s)):s<55296?(o.push(224|s>>12),o.push(128|s>>6&63),o.push(128|63&s)):(s=(1023&s)<<10,s|=1023&t.charCodeAt(++r),s+=65536,o.push(240|s>>18),o.push(128|s>>12&63),o.push(128|s>>6&63),o.push(128|63&s))}return h(3,o.length),p(o);default:var f;if(Array.isArray(t))for(h(4,f=t.length),r=0;r>5!==e)throw"Invalid indefinite length element";return n}function g(e,t){for(var n=0;n>10),e.push(56320|1023&r))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var o,h,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=p(),o=32768&n,i=31744&n,s=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==s)return s*r;return t.setUint32(0,o<<16|i<<13|s<<13),t.getFloat32(0)}();case 26:return u(s.getFloat32(a),4);case 27:return u(s.getFloat64(a),8)}if((h=d(v))<0&&(b<2||6=0;)S+=h,_.push(c(h));var w=new Uint8Array(S),O=0;for(o=0;o<_.length;++o)w.set(_[o],O),O+=_[o].length;return w}return c(h);case 3:var P=[];if(h<0)for(;(h=y(b))>=0;)g(P,h);else g(P,h);return String.fromCharCode.apply(null,P);case 4:var E;if(h<0)for(E=[];!f();)E.push(e());else for(E=new Array(h),o=0;o=20?this._presenceTimeout=e:(this._presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",this._presenceTimeout)),this.setHeartbeatInterval(this._presenceTimeout/2-1),this},e.prototype.setProxy=function(e){this.proxy=e},e.prototype.getHeartbeatInterval=function(){return this._heartbeatInterval},e.prototype.setHeartbeatInterval=function(e){return this._heartbeatInterval=e,this},e.prototype.getSubscribeTimeout=function(){return this._subscribeRequestTimeout},e.prototype.setSubscribeTimeout=function(e){return this._subscribeRequestTimeout=e,this},e.prototype.getTransactionTimeout=function(){return this._transactionalRequestTimeout},e.prototype.setTransactionTimeout=function(e){return this._transactionalRequestTimeout=e,this},e.prototype.isSendBeaconEnabled=function(){return this._useSendBeacon},e.prototype.setSendBeaconConfig=function(e){return this._useSendBeacon=e,this},e.prototype.getVersion=function(){return"7.6.3"},e.prototype._setRetryConfiguration=function(e){if(e.minimumdelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(e.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(e.maximumDelay&&maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6");if(e.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10");this.retryConfiguration=e},e.prototype._addPnsdkSuffix=function(e,t){this._PNSDKSuffix[e]=t},e.prototype._getPnsdkSuffix=function(e){var t=this;return Object.keys(this._PNSDKSuffix).reduce((function(n,r){return n+e+t._PNSDKSuffix[r]}),"")},e}();function m(e){var t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;function s(){var e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error("Illegal character at ".concat(i,": ").concat(t.charAt(i-1)));return n}for(var a=0;a>4,f=(15&c)<<4|l>>2,d=(3&l)<<6|p>>0;o[a]=h,64!=l&&(o[a+1]=f),64!=p&&(o[a+2]=d)}return r}function b(e){for(var t,n="",r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",o=new Uint8Array(e),i=o.byteLength,s=i%3,a=i-s,u=0;u>18]+r[(258048&t)>>12]+r[(4032&t)>>6]+r[63&t];return 1==s?n+=r[(252&(t=o[a]))>>2]+r[(3&t)<<4]+"==":2==s&&(n+=r[(64512&(t=o[a]<<8|o[a+1]))>>10]+r[(1008&t)>>4]+r[(15&t)<<2]+"="),n}var v,_,S,w,O,P=P||function(e,t){var n={},r=n.lib={},o=function(){},i=r.Base={extend:function(e){o.prototype=this;var t=new o;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},s=r.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||u).stringify(this)},concat:function(e){var t=this.words,n=e.words,r=this.sigBytes;if(e=e.sigBytes,this.clamp(),r%4)for(var o=0;o>>2]|=(n[o>>>2]>>>24-o%4*8&255)<<24-(r+o)%4*8;else if(65535>>2]=n[o>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],r=0;r>>2]>>>24-r%4*8&255;n.push((o>>>4).toString(16)),n.push((15&o).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>3]|=parseInt(e.substr(r,2),16)<<24-r%8*4;return new s.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],r=0;r>>2]>>>24-r%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],r=0;r>>2]|=(255&e.charCodeAt(r))<<24-r%4*8;return new s.init(n,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},p=r.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new s.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,r=n.words,o=n.sigBytes,i=this.blockSize,a=o/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,o=e.min(4*t,o),t){for(var u=0;uc;){var l;e:{l=u;for(var p=e.sqrt(l),h=2;h<=p;h++)if(!(l%h)){l=!1;break e}l=!0}l&&(8>c&&(i[c]=a(e.pow(u,.5))),s[c]=a(e.pow(u,1/3)),c++),u++}var f=[];o=o.SHA256=r.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,r=n[0],o=n[1],i=n[2],a=n[3],u=n[4],c=n[5],l=n[6],p=n[7],h=0;64>h;h++){if(16>h)f[h]=0|e[t+h];else{var d=f[h-15],y=f[h-2];f[h]=((d<<25|d>>>7)^(d<<14|d>>>18)^d>>>3)+f[h-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+f[h-16]}d=p+((u<<26|u>>>6)^(u<<21|u>>>11)^(u<<7|u>>>25))+(u&c^~u&l)+s[h]+f[h],y=((r<<30|r>>>2)^(r<<19|r>>>13)^(r<<10|r>>>22))+(r&o^r&i^o&i),p=l,l=c,c=u,u=a+d|0,a=i,i=o,o=r,r=d+y|0}n[0]=n[0]+r|0,n[1]=n[1]+o|0,n[2]=n[2]+i|0,n[3]=n[3]+a|0,n[4]=n[4]+u|0,n[5]=n[5]+c|0,n[6]=n[6]+l|0,n[7]=n[7]+p|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;return n[o>>>5]|=128<<24-o%32,n[14+(o+64>>>9<<4)]=e.floor(r/4294967296),n[15+(o+64>>>9<<4)]=r,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=r.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=r._createHelper(o),t.HmacSHA256=r._createHmacHelper(o)}(Math),_=(v=P).enc.Utf8,v.algo.HMAC=v.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=_.parse(t));var n=e.blockSize,r=4*n;t.sigBytes>r&&(t=e.finalize(t)),t.clamp();for(var o=this._oKey=t.clone(),i=this._iKey=t.clone(),s=o.words,a=i.words,u=0;u>>2]>>>24-o%4*8&255)<<16|(t[o+1>>>2]>>>24-(o+1)%4*8&255)<<8|t[o+2>>>2]>>>24-(o+2)%4*8&255,s=0;4>s&&o+.75*s>>6*(3-s)&63));if(t=r.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(r=n.charAt(64))&&-1!=(r=e.indexOf(r))&&(t=r);for(var r=[],o=0,i=0;i>>6-i%4*2;r[o>>>2]|=(s|a)<<24-o%4*8,o++}return w.create(r,o)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,r,o,i,s){return((e=e+(t&n|~t&r)+o+s)<>>32-i)+t}function n(e,t,n,r,o,i,s){return((e=e+(t&r|n&~r)+o+s)<>>32-i)+t}function r(e,t,n,r,o,i,s){return((e=e+(t^n^r)+o+s)<>>32-i)+t}function o(e,t,n,r,o,i,s){return((e=e+(n^(t|~r))+o+s)<>>32-i)+t}for(var i=P,s=(u=i.lib).WordArray,a=u.Hasher,u=i.algo,c=[],l=0;64>l;l++)c[l]=4294967296*e.abs(e.sin(l+1))|0;u=u.MD5=a.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var s=0;16>s;s++){var a=e[u=i+s];e[u]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}s=this._hash.words;var u=e[i+0],l=(a=e[i+1],e[i+2]),p=e[i+3],h=e[i+4],f=e[i+5],d=e[i+6],y=e[i+7],g=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],_=e[i+12],S=e[i+13],w=e[i+14],O=e[i+15],P=t(P=s[0],T=s[1],A=s[2],E=s[3],u,7,c[0]),E=t(E,P,T,A,a,12,c[1]),A=t(A,E,P,T,l,17,c[2]),T=t(T,A,E,P,p,22,c[3]);P=t(P,T,A,E,h,7,c[4]),E=t(E,P,T,A,f,12,c[5]),A=t(A,E,P,T,d,17,c[6]),T=t(T,A,E,P,y,22,c[7]),P=t(P,T,A,E,g,7,c[8]),E=t(E,P,T,A,m,12,c[9]),A=t(A,E,P,T,b,17,c[10]),T=t(T,A,E,P,v,22,c[11]),P=t(P,T,A,E,_,7,c[12]),E=t(E,P,T,A,S,12,c[13]),A=t(A,E,P,T,w,17,c[14]),P=n(P,T=t(T,A,E,P,O,22,c[15]),A,E,a,5,c[16]),E=n(E,P,T,A,d,9,c[17]),A=n(A,E,P,T,v,14,c[18]),T=n(T,A,E,P,u,20,c[19]),P=n(P,T,A,E,f,5,c[20]),E=n(E,P,T,A,b,9,c[21]),A=n(A,E,P,T,O,14,c[22]),T=n(T,A,E,P,h,20,c[23]),P=n(P,T,A,E,m,5,c[24]),E=n(E,P,T,A,w,9,c[25]),A=n(A,E,P,T,p,14,c[26]),T=n(T,A,E,P,g,20,c[27]),P=n(P,T,A,E,S,5,c[28]),E=n(E,P,T,A,l,9,c[29]),A=n(A,E,P,T,y,14,c[30]),P=r(P,T=n(T,A,E,P,_,20,c[31]),A,E,f,4,c[32]),E=r(E,P,T,A,g,11,c[33]),A=r(A,E,P,T,v,16,c[34]),T=r(T,A,E,P,w,23,c[35]),P=r(P,T,A,E,a,4,c[36]),E=r(E,P,T,A,h,11,c[37]),A=r(A,E,P,T,y,16,c[38]),T=r(T,A,E,P,b,23,c[39]),P=r(P,T,A,E,S,4,c[40]),E=r(E,P,T,A,u,11,c[41]),A=r(A,E,P,T,p,16,c[42]),T=r(T,A,E,P,d,23,c[43]),P=r(P,T,A,E,m,4,c[44]),E=r(E,P,T,A,_,11,c[45]),A=r(A,E,P,T,O,16,c[46]),P=o(P,T=r(T,A,E,P,l,23,c[47]),A,E,u,6,c[48]),E=o(E,P,T,A,y,10,c[49]),A=o(A,E,P,T,w,15,c[50]),T=o(T,A,E,P,f,21,c[51]),P=o(P,T,A,E,_,6,c[52]),E=o(E,P,T,A,p,10,c[53]),A=o(A,E,P,T,b,15,c[54]),T=o(T,A,E,P,a,21,c[55]),P=o(P,T,A,E,g,6,c[56]),E=o(E,P,T,A,O,10,c[57]),A=o(A,E,P,T,d,15,c[58]),T=o(T,A,E,P,S,21,c[59]),P=o(P,T,A,E,h,6,c[60]),E=o(E,P,T,A,v,10,c[61]),A=o(A,E,P,T,l,15,c[62]),T=o(T,A,E,P,m,21,c[63]);s[0]=s[0]+P|0,s[1]=s[1]+T|0,s[2]=s[2]+A|0,s[3]=s[3]+E|0},_doFinalize:function(){var t=this._data,n=t.words,r=8*this._nDataBytes,o=8*t.sigBytes;n[o>>>5]|=128<<24-o%32;var i=e.floor(r/4294967296);for(n[15+(o+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(o+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,r=0;4>r;r++)o=n[r],n[r]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(u),i.HmacMD5=a._createHmacHelper(u)}(Math),function(){var e,t=P,n=(e=t.lib).Base,r=e.WordArray,o=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(a=this.cfg).hasher.create(),o=r.create(),i=o.words,s=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:u,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var p=t.CipherParams=n.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(u=(f.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?r.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=r.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return p.create({ciphertext:e,salt:n})}},t.SerializableCipher=n.extend({cfg:n.extend({format:u}),encrypt:function(e,t,n,r){r=this.cfg.extend(r);var o=e.createEncryptor(n,r);return t=o.finalize(t),o=o.cfg,p.create({ciphertext:t,key:n,iv:o.iv,algorithm:e,mode:o.mode,padding:o.padding,blockSize:e.blockSize,formatter:r.format})},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),e.createDecryptor(n,r).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),f=(f.kdf={}).OpenSSL={execute:function(e,t,n,o){return o||(o=r.random(8)),e=s.create({keySize:t+n}).compute(e,o),n=r.create(e.words.slice(t),4*n),e.sigBytes=4*t,p.create({key:e,iv:n,salt:o})}},d=t.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:f}),encrypt:function(e,t,n,r){return n=(r=this.cfg.extend(r)).kdf.execute(n,e.keySize,e.ivSize),r.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,r)).mixIn(n),e},decrypt:function(e,t,n,r){return r=this.cfg.extend(r),t=this._parse(t,r.format),n=r.kdf.execute(n,e.keySize,e.ivSize,t.salt),r.iv=n.iv,h.decrypt.call(this,e,t,n.key,r)}})}(),function(){for(var e=P,t=e.lib.BlockCipher,n=e.algo,r=[],o=[],i=[],s=[],a=[],u=[],c=[],l=[],p=[],h=[],f=[],d=0;256>d;d++)f[d]=128>d?d<<1:d<<1^283;var y=0,g=0;for(d=0;256>d;d++){var m=(m=g^g<<1^g<<2^g<<3^g<<4)>>>8^255&m^99;r[y]=m,o[m]=y;var b=f[y],v=f[b],_=f[v],S=257*f[m]^16843008*m;i[y]=S<<24|S>>>8,s[y]=S<<16|S>>>16,a[y]=S<<8|S>>>24,u[y]=S,S=16843009*_^65537*v^257*b^16843008*y,c[m]=S<<24|S>>>8,l[m]=S<<16|S>>>16,p[m]=S<<8|S>>>24,h[m]=S,y?(y=b^f[f[f[_^b]]],g^=f[f[g]]):y=g=1}var w=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),o=this._keySchedule=[],i=0;i>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s]):(s=r[(s=s<<8|s>>>24)>>>24]<<24|r[s>>>16&255]<<16|r[s>>>8&255]<<8|r[255&s],s^=w[i/t|0]<<24),o[i]=o[i-t]^s}for(e=this._invKeySchedule=[],t=0;tt||4>=i?s:c[r[s>>>24]]^l[r[s>>>16&255]]^p[r[s>>>8&255]]^h[r[255&s]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,s,a,u,r)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,c,l,p,h,o),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,r,o,i,s,a){for(var u=this._nRounds,c=e[t]^n[0],l=e[t+1]^n[1],p=e[t+2]^n[2],h=e[t+3]^n[3],f=4,d=1;d>>24]^o[l>>>16&255]^i[p>>>8&255]^s[255&h]^n[f++],g=r[l>>>24]^o[p>>>16&255]^i[h>>>8&255]^s[255&c]^n[f++],m=r[p>>>24]^o[h>>>16&255]^i[c>>>8&255]^s[255&l]^n[f++];h=r[h>>>24]^o[c>>>16&255]^i[l>>>8&255]^s[255&p]^n[f++],c=y,l=g,p=m}y=(a[c>>>24]<<24|a[l>>>16&255]<<16|a[p>>>8&255]<<8|a[255&h])^n[f++],g=(a[l>>>24]<<24|a[p>>>16&255]<<16|a[h>>>8&255]<<8|a[255&c])^n[f++],m=(a[p>>>24]<<24|a[h>>>16&255]<<16|a[c>>>8&255]<<8|a[255&l])^n[f++],h=(a[h>>>24]<<24|a[c>>>16&255]<<16|a[l>>>8&255]<<8|a[255&p])^n[f++],e[t]=y,e[t+1]=g,e[t+2]=m,e[t+3]=h},keySize:8});e.AES=t._createHelper(n)}(),P.mode.ECB=((O=P.lib.BlockCipherMode.extend()).Encryptor=O.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),O.Decryptor=O.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),O);var E=P;function A(e){var t,n=[];for(t=0;t=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))},e.prototype.clearHistory=function(){this.hashHistory=[]},e}(),k={PNNetworkUpCategory:"PNNetworkUpCategory",PNNetworkDownCategory:"PNNetworkDownCategory",PNNetworkIssuesCategory:"PNNetworkIssuesCategory",PNTimeoutCategory:"PNTimeoutCategory",PNBadRequestCategory:"PNBadRequestCategory",PNAccessDeniedCategory:"PNAccessDeniedCategory",PNUnknownCategory:"PNUnknownCategory",PNReconnectedCategory:"PNReconnectedCategory",PNConnectedCategory:"PNConnectedCategory",PNRequestMessageCountExceededCategory:"PNRequestMessageCountExceededCategory",PNDisconnectedCategory:"PNDisconnectedCategory",PNConnectionErrorCategory:"PNConnectionErrorCategory",PNDisconnectedUnexpectedlyCategory:"PNDisconnectedUnexpectedlyCategory"},M=function(){function e(e){var t=e.subscribeEndpoint,n=e.leaveEndpoint,r=e.heartbeatEndpoint,o=e.setStateEndpoint,i=e.timeEndpoint,s=e.getFileUrl,a=e.config,u=e.crypto,c=e.listenerManager,l=e.cryptoModule,p=e.eventEmitter;this._listenerManager=c,this._config=a,this._leaveEndpoint=n,this._heartbeatEndpoint=r,this._setStateEndpoint=o,this._subscribeEndpoint=t,this._getFileUrl=s,this._crypto=u,this._cryptoModule=l,this._channels={},this._presenceChannels={},this._heartbeatChannels={},this._heartbeatChannelGroups={},this._channelGroups={},this._presenceChannelGroups={},this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[],this._currentTimetoken=0,this._lastTimetoken=0,this._storedTimetoken=null,this._subscriptionStatusAnnounced=!1,this._isOnline=!0,this._reconnectionManager=new N({timeEndpoint:i}),this._dedupingManager=new C({config:a}),this._cryptoModule&&(this._decoder=new TextDecoder),this._eventEmitter=p}return e.prototype.adaptStateChange=function(e,t){var n=this,r=e.state,o=e.channels,i=void 0===o?[]:o,s=e.channelGroups,a=void 0===s?[]:s,u=e.withHeartbeat,c=void 0!==u&&u;if(i.forEach((function(e){e in n._channels&&(n._channels[e].state=r)})),a.forEach((function(e){e in n._channelGroups&&(n._channelGroups[e].state=r)})),c){var l={};return i.forEach((function(e){return l[e]=r})),a.forEach((function(e){return l[e]=r})),this._heartbeatEndpoint({channels:i,channelGroups:a,state:l},t)}return this._setStateEndpoint({state:r,channels:i,channelGroups:a},t)},e.prototype.adaptPresenceChange=function(e){var t=this,n=e.connected,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i;n?(o.forEach((function(e){t._heartbeatChannels[e]={state:{}}})),s.forEach((function(e){t._heartbeatChannelGroups[e]={state:{}}}))):(o.forEach((function(e){e in t._heartbeatChannels&&delete t._heartbeatChannels[e]})),s.forEach((function(e){e in t._heartbeatChannelGroups&&delete t._heartbeatChannelGroups[e]})),!1===this._config.suppressLeaveEvents&&this._leaveEndpoint({channels:o,channelGroups:s},(function(e){t._listenerManager.announceStatus(e)}))),this.reconnect()},e.prototype.adaptSubscribeChange=function(e){var t=this,n=e.timetoken,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=e.withPresence,u=void 0!==a&&a,c=e.withHeartbeats,l=void 0!==c&&c;this._config.subscribeKey&&""!==this._config.subscribeKey?(n&&(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=n),"0"!==this._currentTimetoken&&0!==this._currentTimetoken&&(this._storedTimetoken=this._currentTimetoken,this._currentTimetoken=0),o.forEach((function(e){t._channels[e]={state:{}},u&&(t._presenceChannels[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannels[e]={}),t._pendingChannelSubscriptions.push(e)})),s.forEach((function(e){t._channelGroups[e]={state:{}},u&&(t._presenceChannelGroups[e]={}),(l||t._config.getHeartbeatInterval())&&(t._heartbeatChannelGroups[e]={}),t._pendingChannelGroupSubscriptions.push(e)})),this._subscriptionStatusAnnounced=!1,this.reconnect()):console&&console.log&&console.log("subscribe key missing; aborting subscribe")},e.prototype.adaptUnsubscribeChange=function(e,t){var n=this,r=e.channels,o=void 0===r?[]:r,i=e.channelGroups,s=void 0===i?[]:i,a=[],u=[];o.forEach((function(e){e in n._channels&&(delete n._channels[e],a.push(e),e in n._heartbeatChannels&&delete n._heartbeatChannels[e]),e in n._presenceChannels&&(delete n._presenceChannels[e],a.push(e))})),s.forEach((function(e){e in n._channelGroups&&(delete n._channelGroups[e],u.push(e),e in n._heartbeatChannelGroups&&delete n._heartbeatChannelGroups[e]),e in n._presenceChannelGroups&&(delete n._presenceChannelGroups[e],u.push(e))})),0===a.length&&0===u.length||(!1!==this._config.suppressLeaveEvents||t||this._leaveEndpoint({channels:a,channelGroups:u},(function(e){e.affectedChannels=a,e.affectedChannelGroups=u,e.currentTimetoken=n._currentTimetoken,e.lastTimetoken=n._lastTimetoken,n._listenerManager.announceStatus(e)})),0===Object.keys(this._channels).length&&0===Object.keys(this._presenceChannels).length&&0===Object.keys(this._channelGroups).length&&0===Object.keys(this._presenceChannelGroups).length&&(this._lastTimetoken=0,this._currentTimetoken=0,this._storedTimetoken=null,this._region=null,this._reconnectionManager.stopPolling()),this.reconnect())},e.prototype.unsubscribeAll=function(e){this.adaptUnsubscribeChange({channels:this.getSubscribedChannels(),channelGroups:this.getSubscribedChannelGroups()},e)},e.prototype.getHeartbeatChannels=function(){return Object.keys(this._heartbeatChannels)},e.prototype.getHeartbeatChannelGroups=function(){return Object.keys(this._heartbeatChannelGroups)},e.prototype.getSubscribedChannels=function(){return Object.keys(this._channels)},e.prototype.getSubscribedChannelGroups=function(){return Object.keys(this._channelGroups)},e.prototype.reconnect=function(){this._startSubscribeLoop(),this._registerHeartbeatTimer()},e.prototype.disconnect=function(){this._stopSubscribeLoop(),this._stopHeartbeatTimer(),this._reconnectionManager.stopPolling()},e.prototype._registerHeartbeatTimer=function(){this._stopHeartbeatTimer(),0!==this._config.getHeartbeatInterval()&&void 0!==this._config.getHeartbeatInterval()&&(this._performHeartbeatLoop(),this._heartbeatTimer=setInterval(this._performHeartbeatLoop.bind(this),1e3*this._config.getHeartbeatInterval()))},e.prototype._stopHeartbeatTimer=function(){this._heartbeatTimer&&(clearInterval(this._heartbeatTimer),this._heartbeatTimer=null)},e.prototype._performHeartbeatLoop=function(){var e=this,t=this.getHeartbeatChannels(),n=this.getHeartbeatChannelGroups(),r={};if(0!==t.length||0!==n.length){this.getSubscribedChannels().forEach((function(t){var n=e._channels[t].state;Object.keys(n).length&&(r[t]=n)})),this.getSubscribedChannelGroups().forEach((function(t){var n=e._channelGroups[t].state;Object.keys(n).length&&(r[t]=n)}));this._heartbeatEndpoint({channels:t,channelGroups:n,state:r},function(t){t.error&&e._config.announceFailedHeartbeats&&e._listenerManager.announceStatus(t),t.error&&e._config.autoNetworkDetection&&e._isOnline&&(e._isOnline=!1,e.disconnect(),e._listenerManager.announceNetworkDown(),e.reconnect()),!t.error&&e._config.announceSuccessfulHeartbeats&&e._listenerManager.announceStatus(t)}.bind(this))}},e.prototype._startSubscribeLoop=function(){var e=this;this._stopSubscribeLoop();var t={},n=[],r=[];if(Object.keys(this._channels).forEach((function(r){var o=e._channels[r].state;Object.keys(o).length&&(t[r]=o),n.push(r)})),Object.keys(this._presenceChannels).forEach((function(e){n.push("".concat(e,"-pnpres"))})),Object.keys(this._channelGroups).forEach((function(n){var o=e._channelGroups[n].state;Object.keys(o).length&&(t[n]=o),r.push(n)})),Object.keys(this._presenceChannelGroups).forEach((function(e){r.push("".concat(e,"-pnpres"))})),0!==n.length||0!==r.length){var o={channels:n,channelGroups:r,state:t,timetoken:this._currentTimetoken,filterExpression:this._config.filterExpression,region:this._region};this._subscribeCall=this._subscribeEndpoint(o,this._processSubscribeResponse.bind(this))}},e.prototype._processSubscribeResponse=function(e,t){var n=this;if(e.error){if(e.errorData&&"Aborted"===e.errorData.message)return;e.category===k.PNTimeoutCategory?this._startSubscribeLoop():e.category===k.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this._config.autoNetworkDetection&&this._isOnline&&(this._isOnline=!1,this._listenerManager.announceNetworkDown()),this._reconnectionManager.onReconnection((function(){n._config.autoNetworkDetection&&!n._isOnline&&(n._isOnline=!0,n._listenerManager.announceNetworkUp()),n.reconnect(),n._subscriptionStatusAnnounced=!0;var t={category:k.PNReconnectedCategory,operation:e.operation,lastTimetoken:n._lastTimetoken,currentTimetoken:n._currentTimetoken};n._listenerManager.announceStatus(t)})),this._reconnectionManager.startPolling(),this._listenerManager.announceStatus(e)):e.category===k.PNBadRequestCategory?(this._stopHeartbeatTimer(),this._listenerManager.announceStatus(e)):this._listenerManager.announceStatus(e)}else{if(this._storedTimetoken?(this._currentTimetoken=this._storedTimetoken,this._storedTimetoken=null):(this._lastTimetoken=this._currentTimetoken,this._currentTimetoken=t.metadata.timetoken),!this._subscriptionStatusAnnounced){var r={};r.category=k.PNConnectedCategory,r.operation=e.operation,r.affectedChannels=this._pendingChannelSubscriptions,r.subscribedChannels=this.getSubscribedChannels(),r.affectedChannelGroups=this._pendingChannelGroupSubscriptions,r.lastTimetoken=this._lastTimetoken,r.currentTimetoken=this._currentTimetoken,this._subscriptionStatusAnnounced=!0,this._listenerManager.announceStatus(r),this._pendingChannelSubscriptions=[],this._pendingChannelGroupSubscriptions=[]}var o=t.messages||[],i=this._config,s=i.requestMessageCountThreshold,a=i.dedupeOnSubscribe;if(s&&o.length>=s){var u={};u.category=k.PNRequestMessageCountExceededCategory,u.operation=e.operation,this._listenerManager.announceStatus(u)}o.forEach((function(e){if(e.channel,e.subscriptionMatch,a){if(n._dedupingManager.isDuplicate(e))return;n._dedupingManager.addEntry(e)}n._eventEmitter.emitEvent(e)})),this._region=t.metadata.region,this._startSubscribeLoop()}},e.prototype._stopSubscribeLoop=function(){this._subscribeCall&&("function"==typeof this._subscribeCall.abort&&this._subscribeCall.abort(),this._subscribeCall=null)},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e}(),j={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",PNAccessManagerRevokeToken:"PNAccessManagerRevokeToken",PNHandshakeOperation:"PNHandshakeOperation",PNReceiveMessagesOperation:"PNReceiveMessagesOperation"},R=function(){function e(e){this._maximumSamplesCount=100,this._trackedLatencies={},this._latencies={},this._telemetryExcludeOperations=[j.PNSubscribeOperation,j.PNReceiveMessagesOperation,j.PNHandshakeOperation],this._maximumSamplesCount=e.maximumSamplesCount||this._maximumSamplesCount}return e.prototype.operationsLatencyForRequest=function(){var e=this,t={};return Object.keys(this._latencies).forEach((function(n){var r=e._latencies[n],o=e._averageLatency(r);o>0&&(t["l_".concat(n)]=o)})),t},e.prototype.startLatencyMeasure=function(e,t){!this._telemetryExcludeOperations.includes(e)&&t&&(this._trackedLatencies[t]=Date.now())},e.prototype.stopLatencyMeasure=function(e,t){if(!this._telemetryExcludeOperations.includes(e)&&t){var n=this._endpointName(e),r=this._latencies[n],o=this._trackedLatencies[t];r||(this._latencies[n]=[],r=this._latencies[n]),r.push(Date.now()-o),r.length>this._maximumSamplesCount&&r.splice(0,r.length-this._maximumSamplesCount),delete this._trackedLatencies[t]}},e.prototype._averageLatency=function(e){return Math.floor(e.reduce((function(e,t){return e+t}),0)/e.length)},e.prototype._endpointName=function(e){var t=null;switch(e){case j.PNPublishOperation:t="pub";break;case j.PNSignalOperation:t="sig";break;case j.PNHistoryOperation:case j.PNFetchMessagesOperation:case j.PNDeleteMessagesOperation:case j.PNMessageCounts:t="hist";break;case j.PNUnsubscribeOperation:case j.PNWhereNowOperation:case j.PNHereNowOperation:case j.PNHeartbeatOperation:case j.PNSetStateOperation:case j.PNGetStateOperation:t="pres";break;case j.PNAddChannelsToGroupOperation:case j.PNRemoveChannelsFromGroupOperation:case j.PNChannelGroupsOperation:case j.PNRemoveGroupOperation:case j.PNChannelsForGroupOperation:t="cg";break;case j.PNPushNotificationEnabledChannelsOperation:case j.PNRemoveAllPushNotificationsOperation:t="push";break;case j.PNCreateUserOperation:case j.PNUpdateUserOperation:case j.PNDeleteUserOperation:case j.PNGetUserOperation:case j.PNGetUsersOperation:case j.PNCreateSpaceOperation:case j.PNUpdateSpaceOperation:case j.PNDeleteSpaceOperation:case j.PNGetSpaceOperation:case j.PNGetSpacesOperation:case j.PNGetMembersOperation:case j.PNUpdateMembersOperation:case j.PNGetMembershipsOperation:case j.PNUpdateMembershipsOperation:t="obj";break;case j.PNAddMessageActionOperation:case j.PNRemoveMessageActionOperation:case j.PNGetMessageActionsOperation:t="msga";break;case j.PNAccessManagerGrant:case j.PNAccessManagerAudit:t="pam";break;case j.PNAccessManagerGrantToken:case j.PNAccessManagerRevokeToken:t="pamv3";break;default:t="time"}return t},e}(),x=function(){function e(e,t,n){this._payload=e,this._setDefaultPayloadStructure(),this.title=t,this.body=n}return Object.defineProperty(e.prototype,"payload",{get:function(){return this._payload},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{set:function(e){this._title=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{set:function(e){this._subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{set:function(e){this._body=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{set:function(e){this._badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{set:function(e){this._sound=e},enumerable:!1,configurable:!0}),e.prototype._setDefaultPayloadStructure=function(){},e.prototype.toObject=function(){return{}},e}(),U=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"configurations",{set:function(e){e&&e.length&&(this._configurations=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"notification",{get:function(){return this._payload.aps},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.aps.alert.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){e&&e.length&&(this._payload.aps.alert.subtitle=e,this._subtitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.aps.alert.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this._badge},set:function(e){null!=e&&(this._payload.aps.badge=e,this._badge=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.aps.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),r.prototype._setDefaultPayloadStructure=function(){this._payload.aps={alert:{}}},r.prototype.toObject=function(){var e=this,t=n({},this._payload),r=t.aps,o=r.alert;if(this._isSilent&&(r["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");var i=[];this._configurations.forEach((function(t){i.push(e._objectFromAPNS2Configuration(t))})),i.length&&(t.pn_push=i)}return o&&Object.keys(o).length||delete r.alert,this._isSilent&&(delete r.alert,delete r.badge,delete r.sound,o={}),this._isSilent||Object.keys(o).length?t:null},r.prototype._objectFromAPNS2Configuration=function(e){var t=this;if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");var n=[];e.targets.forEach((function(e){n.push(t._objectFromAPNSTarget(e))}));var r=e.collapseId,o=e.expirationDate,i={auth_method:"token",targets:n,version:"v2"};return r&&r.length&&(i.collapse_id=r),o&&(i.expiration=o.toISOString()),i},r.prototype._objectFromAPNSTarget=function(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");var t=e.topic,n=e.environment,r=void 0===n?"development":n,o=e.excludedDevices,i=void 0===o?[]:o,s={topic:t,environment:r};return i.length&&(s.excluded_devices=i),s},r}(x),I=function(e){function r(){return null!==e&&e.apply(this,arguments)||this}return t(r,e),Object.defineProperty(r.prototype,"backContent",{get:function(){return this._backContent},set:function(e){e&&e.length&&(this._payload.back_content=e,this._backContent=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"backTitle",{get:function(){return this._backTitle},set:function(e){e&&e.length&&(this._payload.back_title=e,this._backTitle=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"count",{get:function(){return this._count},set:function(e){null!=e&&(this._payload.count=e,this._count=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"type",{get:function(){return this._type},set:function(e){e&&e.length&&(this._payload.type=e,this._type=e)},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"subtitle",{get:function(){return this.backTitle},set:function(e){this.backTitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"body",{get:function(){return this.backContent},set:function(e){this.backContent=e},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"badge",{get:function(){return this.count},set:function(e){this.count=e},enumerable:!1,configurable:!0}),r.prototype.toObject=function(){return Object.keys(this._payload).length?n({},this._payload):null},r}(x),D=function(e){function o(){return null!==e&&e.apply(this,arguments)||this}return t(o,e),Object.defineProperty(o.prototype,"notification",{get:function(){return this._payload.notification},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"data",{get:function(){return this._payload.data},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"title",{get:function(){return this._title},set:function(e){e&&e.length&&(this._payload.notification.title=e,this._title=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"body",{get:function(){return this._body},set:function(e){e&&e.length&&(this._payload.notification.body=e,this._body=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"sound",{get:function(){return this._sound},set:function(e){e&&e.length&&(this._payload.notification.sound=e,this._sound=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"icon",{get:function(){return this._icon},set:function(e){e&&e.length&&(this._payload.notification.icon=e,this._icon=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"tag",{get:function(){return this._tag},set:function(e){e&&e.length&&(this._payload.notification.tag=e,this._tag=e)},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"silent",{set:function(e){this._isSilent=e},enumerable:!1,configurable:!0}),o.prototype._setDefaultPayloadStructure=function(){this._payload.notification={},this._payload.data={}},o.prototype.toObject=function(){var e=n({},this._payload.data),t=null,o={};if(Object.keys(this._payload).length>2){var i=this._payload;i.notification,i.data;var s=r(i,["notification","data"]);e=n(n({},e),s)}return this._isSilent?e.notification=this._payload.notification:t=this._payload.notification,Object.keys(e).length&&(o.data=e),t&&Object.keys(t).length&&(o.notification=t),Object.keys(o).length?o:null},o}(x),F=function(){function e(e,t){this._payload={apns:{},mpns:{},fcm:{}},this._title=e,this._body=t,this.apns=new U(this._payload.apns,e,t),this.mpns=new I(this._payload.mpns,e,t),this.fcm=new D(this._payload.fcm,e,t)}return Object.defineProperty(e.prototype,"debugging",{set:function(e){this._debugging=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"title",{get:function(){return this._title},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"body",{get:function(){return this._body},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"subtitle",{get:function(){return this._subtitle},set:function(e){this._subtitle=e,this.apns.subtitle=e,this.mpns.subtitle=e,this.fcm.subtitle=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"badge",{get:function(){return this._badge},set:function(e){this._badge=e,this.apns.badge=e,this.mpns.badge=e,this.fcm.badge=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"sound",{get:function(){return this._sound},set:function(e){this._sound=e,this.apns.sound=e,this.mpns.sound=e,this.fcm.sound=e},enumerable:!1,configurable:!0}),e.prototype.buildPayload=function(e){var t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";var n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("mpns")){var r=this.mpns.toObject();r&&Object.keys(r).length&&(t.pn_mpns=r)}if(e.includes("fcm")){var o=this.fcm.toObject();o&&Object.keys(o).length&&(t.pn_gcm=o)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t},e}(),L=function(){function e(){this._listeners=[]}return e.prototype.addListener=function(e){this._listeners.includes(e)||this._listeners.push(e)},e.prototype.removeListener=function(e){var t=[];this._listeners.forEach((function(n){n!==e&&t.push(n)})),this._listeners=t},e.prototype.removeAllListeners=function(){this._listeners=[]},e.prototype.announcePresence=function(e){this._listeners.forEach((function(t){t.presence&&t.presence(e)}))},e.prototype.announceStatus=function(e){this._listeners.forEach((function(t){t.status&&t.status(e)}))},e.prototype.announceMessage=function(e){this._listeners.forEach((function(t){t.message&&t.message(e)}))},e.prototype.announceSignal=function(e){this._listeners.forEach((function(t){t.signal&&t.signal(e)}))},e.prototype.announceMessageAction=function(e){this._listeners.forEach((function(t){t.messageAction&&t.messageAction(e)}))},e.prototype.announceFile=function(e){this._listeners.forEach((function(t){t.file&&t.file(e)}))},e.prototype.announceObjects=function(e){this._listeners.forEach((function(t){t.objects&&t.objects(e)}))},e.prototype.announceUser=function(e){this._listeners.forEach((function(t){t.user&&t.user(e)}))},e.prototype.announceSpace=function(e){this._listeners.forEach((function(t){t.space&&t.space(e)}))},e.prototype.announceMembership=function(e){this._listeners.forEach((function(t){t.membership&&t.membership(e)}))},e.prototype.announceNetworkUp=function(){var e={};e.category=k.PNNetworkUpCategory,this.announceStatus(e)},e.prototype.announceNetworkDown=function(){var e={};e.category=k.PNNetworkDownCategory,this.announceStatus(e)},e}(),G=function(){function e(e,t){this._config=e,this._cbor=t}return e.prototype.setToken=function(e){e&&e.length>0?this._token=e:this._token=void 0},e.prototype.getToken=function(){return this._token},e.prototype.extractPermissions=function(e){var t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128==(128&e)&&(t.join=!0),64==(64&e)&&(t.update=!0),32==(32&e)&&(t.get=!0),8==(8&e)&&(t.delete=!0),4==(4&e)&&(t.manage=!0),2==(2&e)&&(t.write=!0),1==(1&e)&&(t.read=!0),t},e.prototype.parseToken=function(e){var t=this,n=this._cbor.decodeToken(e);if(void 0!==n){var r=n.res.uuid?Object.keys(n.res.uuid):[],o=Object.keys(n.res.chan),i=Object.keys(n.res.grp),s=n.pat.uuid?Object.keys(n.pat.uuid):[],a=Object.keys(n.pat.chan),u=Object.keys(n.pat.grp),c={version:n.v,timestamp:n.t,ttl:n.ttl,authorized_uuid:n.uuid},l=r.length>0,p=o.length>0,h=i.length>0;(l||p||h)&&(c.resources={},l&&(c.resources.uuids={},r.forEach((function(e){c.resources.uuids[e]=t.extractPermissions(n.res.uuid[e])}))),p&&(c.resources.channels={},o.forEach((function(e){c.resources.channels[e]=t.extractPermissions(n.res.chan[e])}))),h&&(c.resources.groups={},i.forEach((function(e){c.resources.groups[e]=t.extractPermissions(n.res.grp[e])}))));var f=s.length>0,d=a.length>0,y=u.length>0;return(f||d||y)&&(c.patterns={},f&&(c.patterns.uuids={},s.forEach((function(e){c.patterns.uuids[e]=t.extractPermissions(n.pat.uuid[e])}))),d&&(c.patterns.channels={},a.forEach((function(e){c.patterns.channels[e]=t.extractPermissions(n.pat.chan[e])}))),y&&(c.patterns.groups={},u.forEach((function(e){c.patterns.groups[e]=t.extractPermissions(n.pat.grp[e])})))),Object.keys(n.meta).length>0&&(c.meta=n.meta),c.signature=n.sig,c}},e}();function K(e){return encodeURIComponent(e).replace(/[!~*'()]/g,(function(e){return"%".concat(e.charCodeAt(0).toString(16).toUpperCase())}))}function B(e){return function(e){var t=[];return Object.keys(e).forEach((function(e){return t.push(e)})),t}(e).sort()}var H={signPamFromParams:function(e){return B(e).map((function(t){return"".concat(t,"=").concat(K(e[t]))})).join("&")},endsWith:function(e,t){return-1!==e.indexOf(t,this.length-t.length)},createPromise:function(){var e,t;return{promise:new Promise((function(n,r){e=n,t=r})),reject:t,fulfill:e}},encodeString:K,stringToArrayBuffer:function(e){for(var t=new ArrayBuffer(2*e.length),n=new Uint16Array(t),r=0,o=e.length;r0&&(t+=n),t}function J(e,t,n){return t.usePost&&t.usePost(e,n)?"POST":t.usePatch&&t.usePatch(e,n)?"PATCH":t.useDelete&&t.useDelete(e,n)?"DELETE":t.useGetFile&&t.useGetFile(e,n)?"GETFILE":"GET"}function $(e,t,n,r,o){var i=e.config,s=e.crypto,a=J(e,o,r);n.timestamp=Math.floor((new Date).getTime()/1e3),"PNPublishOperation"===o.getOperation()&&o.usePost&&o.usePost(e,r)&&(a="GET"),"GETFILE"===a&&(a="GET");var u="".concat(a,"\n").concat(i.publishKey,"\n").concat(t,"\n").concat(H.signPamFromParams(n),"\n");if("POST"===a)u+="string"==typeof(c=o.postPayload(e,r))?c:JSON.stringify(c);else if("PATCH"===a){var c;u+="string"==typeof(c=o.patchPayload(e,r))?c:JSON.stringify(c)}var l="v2.".concat(s.HMACSHA256(u));l=(l=(l=l.replace(/\+/g,"-")).replace(/\//g,"_")).replace(/=+$/,""),n.signature=l}function Q(e,t){for(var r=[],o=2;o0&&(c.count=u),c},handleResponse:function(e,t){return{channels:t}}});var ie=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveAllPushNotificationsOperation},validateParams:function(e,t){var n=t.device,r=t.pushGateway,o=t.topic,i=e.config;return n?r?"apns2"!==r||o?i.subscribeKey?void 0:"Missing Subscribe Key":"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm, apns or apns2)":"Missing Device ID (device)"},getURL:function(e,t){var n=t.device,r=t.pushGateway,o=e.config;return"apns2"===r?"/v2/push/sub-key/".concat(o.subscribeKey,"/devices-apns2/").concat(n,"/remove"):"/v1/push/sub-key/".concat(o.subscribeKey,"/devices/").concat(n,"/remove")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.pushGateway,o=t.environment,i=void 0===o?"development":o,s=t.topic,a={type:r};return"apns2"===r&&delete(a=n(n({},a),{environment:i,topic:s})).type,a},handleResponse:function(){return{}}});var se=Object.freeze({__proto__:null,getOperation:function(){return j.PNUnsubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/leave")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(){return{}}});var ae=Object.freeze({__proto__:null,getOperation:function(){return j.PNWhereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r;return"/v2/presence/sub-key/".concat(n.subscribeKey,"/uuid/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return t.payload?{channels:t.payload.channels}:{channels:[]}}});var ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNHeartbeatOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/heartbeat")},isAuthSupported:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o=t.state,i=e.config,s={};return r.length>0&&(s["channel-group"]=r.join(",")),o&&(s.state=JSON.stringify(o)),s.heartbeat=i.getPresenceTimeout(),s},handleResponse:function(){return{}}});var ce=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetStateOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.uuid,o=void 0===r?n.UUID:r,i=t.channels,s=void 0===i?[]:i,a=s.length>0?s.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(a),"/uuid/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channelGroups,r=void 0===n?[]:n,o={};return r.length>0&&(o["channel-group"]=r.join(",")),o},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a={};return 1===o.length&&0===s.length?a[o[0]]=t.payload:a=t.payload,{channels:a}}});var le=Object.freeze({__proto__:null,getOperation:function(){return j.PNSetStateOperation},validateParams:function(e,t){var n=e.config,r=t.state,o=t.channels,i=void 0===o?[]:o,s=t.channelGroups,a=void 0===s?[]:s;return r?n.subscribeKey?0===i.length&&0===a.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key":"Missing State"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/presence/sub-key/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(i),"/uuid/").concat(H.encodeString(n.UUID),"/data")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.state,r=t.channelGroups,o=void 0===r?[]:r,i={};return i.state=JSON.stringify(n),o.length>0&&(i["channel-group"]=o.join(",")),i},handleResponse:function(e,t){return{state:t.payload}}});var pe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHereNowOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=t.channelGroups,s=void 0===i?[]:i,a="/v2/presence/sub-key/".concat(n.subscribeKey);if(o.length>0||s.length>0){var u=o.length>0?o.join(","):",";a+="/channel/".concat(H.encodeString(u))}return a},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var r=t.channelGroups,o=void 0===r?[]:r,i=t.includeUUIDs,s=void 0===i||i,a=t.includeState,u=void 0!==a&&a,c=t.queryParameters,l=void 0===c?{}:c,p={};return s||(p.disable_uuids=1),u&&(p.state=1),o.length>0&&(p["channel-group"]=o.join(",")),p=n(n({},p),l)},handleResponse:function(e,t,n){var r=n.channels,o=void 0===r?[]:r,i=n.channelGroups,s=void 0===i?[]:i,a=n.includeUUIDs,u=void 0===a||a,c=n.includeState,l=void 0!==c&&c;return o.length>1||s.length>0||0===s.length&&0===o.length?function(){var e={};return e.totalChannels=t.payload.total_channels,e.totalOccupancy=t.payload.total_occupancy,e.channels={},Object.keys(t.payload.channels).forEach((function(n){var r=t.payload.channels[n],o=[];return e.channels[n]={occupants:o,name:n,occupancy:r.occupancy},u&&r.uuids.forEach((function(e){l?o.push({state:e.state,uuid:e.uuid}):o.push({state:null,uuid:e})})),e})),e}():function(){var e={},n=[];return e.totalChannels=1,e.totalOccupancy=t.occupancy,e.channels={},e.channels[o[0]]={occupants:n,name:o[0],occupancy:t.occupancy},u&&t.uuids&&t.uuids.forEach((function(e){l?n.push({state:e.state,uuid:e.uuid}):n.push({state:null,uuid:e})})),e}()},handleError:function(e,t,n){402!==n.statusCode||this.getURL(e,t).includes("channel")||(n.errorData.message="You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.")}});var he=Object.freeze({__proto__:null,getOperation:function(){return j.PNAddMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.action,o=t.channel;return t.messageTimetoken?n.subscribeKey?o?r?r.value?r.type?r.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message channel":"Missing Subscribe Key":"Missing message timetoken"},usePost:function(){return!0},postURL:function(e,t){var n=e.config,r=t.channel,o=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},getRequestHeaders:function(){return{"Content-Type":"application/json"}},isAuthSupported:function(){return!0},prepareParams:function(){return{}},postPayload:function(e,t){return t.action},handleResponse:function(e,t){return{data:t.data}}});var fe=Object.freeze({__proto__:null,getOperation:function(){return j.PNRemoveMessageActionOperation},validateParams:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken;return t.messageTimetoken?o?n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key":"Missing action timetoken":"Missing message timetoken"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config,r=t.channel,o=t.actionTimetoken,i=t.messageTimetoken;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r),"/message/").concat(i,"/action/").concat(o)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{data:t.data}}});var de=Object.freeze({__proto__:null,getOperation:function(){return j.PNGetMessageActionsOperation},validateParams:function(e,t){var n=e.config,r=t.channel;return n.subscribeKey?r?void 0:"Missing message channel":"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channel;return"/v1/message-actions/".concat(n.subscribeKey,"/channel/").concat(H.encodeString(r))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.limit,r=t.start,o=t.end,i={};return n&&(i.limit=n),r&&(i.start=r),o&&(i.end=o),i},handleResponse:function(e,t){var n={data:t.data,start:null,end:null};return n.data.length&&(n.end=n.data[n.data.length-1].actionTimetoken,n.start=n.data[0].actionTimetoken),n}}),ye={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel can't be empty"},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.limit&&(n.limit=t.limit),t.next&&(n.next=t.next),n},handleResponse:function(e,t){return{status:t.status,data:t.data,next:t.next,count:t.count}}},ge={getOperation:function(){return j.PNGenerateUploadUrlOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?void 0:"name can't be empty":"channel can't be empty"},usePost:function(){return!0},postURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/generate-upload-url")},postPayload:function(e,t){return{name:t.name}},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data,file_upload_request:t.file_upload_request}}},me={getOperation:function(){return j.PNPublishFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.fileId)?(null==t?void 0:t.fileName)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},getURL:function(e,t){var n=e.config,r=n.publishKey,o=n.subscribeKey,i=function(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}(e,{message:t.message,file:{name:t.fileName,id:t.fileId}});return"/v1/files/publish-file/".concat(r,"/").concat(o,"/0/").concat(H.encodeString(t.channel),"/0/").concat(H.encodeString(i))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.ttl&&(n.ttl=t.ttl),void 0!==t.storeInHistory&&(n.store=t.storeInHistory?"1":"0"),t.meta&&"object"==typeof t.meta&&(n.meta=JSON.stringify(t.meta)),n},handleResponse:function(e,t){return{timetoken:t[2]}}},be=function(e){var t=function(e){var t=this,n=e.generateUploadUrl,r=e.publishFile,s=e.modules,a=s.PubNubFile,u=s.config,c=s.cryptography,l=s.cryptoModule,p=s.networking;return function(e){var s=e.channel,h=e.file,f=e.message,d=e.cipherKey,y=e.meta,g=e.ttl,m=e.storeInHistory;return o(t,void 0,void 0,(function(){var e,t,o,b,v,_,S,w,O,P,E,A,T,N,C,k,M,j,R,x,U,I,D,F,L,G,K,B,H;return i(this,(function(i){switch(i.label){case 0:if(!s)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!h)throw new q("Validation failed, check status for details",z("file can't be empty"));return e=a.create(h),[4,n({channel:s,name:e.name})];case 1:return t=i.sent(),o=t.file_upload_request,b=o.url,v=o.form_fields,_=t.data,S=_.id,w=_.name,a.supportsEncryptFile&&(d||l)?null!=d?[3,3]:[4,l.encryptFile(e,a)]:[3,6];case 2:return O=i.sent(),[3,5];case 3:return[4,c.encryptFile(d,e,a)];case 4:O=i.sent(),i.label=5;case 5:e=O,i.label=6;case 6:P=v,e.mimeType&&(P=v.map((function(t){return"Content-Type"===t.key?{key:t.key,value:e.mimeType}:t}))),i.label=7;case 7:return i.trys.push([7,21,,22]),a.supportsFileUri&&h.uri?(T=(A=p).POSTFILE,N=[b,P],[4,e.toFileUri()]):[3,10];case 8:return[4,T.apply(A,N.concat([i.sent()]))];case 9:return E=i.sent(),[3,20];case 10:return a.supportsFile?(k=(C=p).POSTFILE,M=[b,P],[4,e.toFile()]):[3,13];case 11:return[4,k.apply(C,M.concat([i.sent()]))];case 12:return E=i.sent(),[3,20];case 13:return a.supportsBuffer?(R=(j=p).POSTFILE,x=[b,P],[4,e.toBuffer()]):[3,16];case 14:return[4,R.apply(j,x.concat([i.sent()]))];case 15:return E=i.sent(),[3,20];case 16:return a.supportsBlob?(I=(U=p).POSTFILE,D=[b,P],[4,e.toBlob()]):[3,19];case 17:return[4,I.apply(U,D.concat([i.sent()]))];case 18:return E=i.sent(),[3,20];case 19:throw new Error("Unsupported environment");case 20:return[3,22];case 21:throw(F=i.sent()).response&&"string"==typeof F.response.text?(L=F.response.text,G=/(.*)<\/Message>/gi.exec(L),new q(G?"Upload to bucket failed: ".concat(G[1]):"Upload to bucket failed.",F)):new q("Upload to bucket failed.",F);case 22:if(204!==E.status)throw new q("Upload to bucket was unsuccessful",E);K=u.fileUploadPublishRetryLimit,B=!1,H={timetoken:"0"},i.label=23;case 23:return i.trys.push([23,25,,26]),[4,r({channel:s,message:f,fileId:S,fileName:w,meta:y,storeInHistory:m,ttl:g})];case 24:return H=i.sent(),B=!0,[3,26];case 25:return i.sent(),K-=1,[3,26];case 26:if(!B&&K>0)return[3,23];i.label=27;case 27:if(B)return[2,{timetoken:H.timetoken,id:S,name:w}];throw new q("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{channel:s,id:S,name:w})}}))}))}}(e);return function(e,n){var r=t(e);return"function"==typeof n?(r.then((function(e){return n(null,e)})).catch((function(e){return n(e,null)})),r):r}},ve=function(e,t){var n=t.channel,r=t.id,o=t.name,i=e.config,s=e.networking,a=e.tokenManager;if(!n)throw new q("Validation failed, check status for details",z("channel can't be empty"));if(!r)throw new q("Validation failed, check status for details",z("file id can't be empty"));if(!o)throw new q("Validation failed, check status for details",z("file name can't be empty"));var u="/v1/files/".concat(i.subscribeKey,"/channels/").concat(H.encodeString(n),"/files/").concat(r,"/").concat(o),c={};c.uuid=i.getUUID(),c.pnsdk=W(i);var l=a.getToken()||i.getAuthKey();l&&(c.auth=l),i.secretKey&&$(e,u,c,{},{getOperation:function(){return"PubNubGetFileUrlOperation"}});var p=Object.keys(c).map((function(e){return"".concat(encodeURIComponent(e),"=").concat(encodeURIComponent(c[e]))})).join("&");return""!==p?"".concat(s.getStandardOrigin()).concat(u,"?").concat(p):"".concat(s.getStandardOrigin()).concat(u)},_e={getOperation:function(){return j.PNDownloadFileOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.name)?(null==t?void 0:t.id)?void 0:"id can't be empty":"name can't be empty":"channel can't be empty"},useGetFile:function(){return!0},getFileURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},ignoreBody:function(){return!0},forceBuffered:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t,n){var r=e.PubNubFile,s=e.config,a=e.cryptography,u=e.cryptoModule;return o(void 0,void 0,void 0,(function(){var e,o,c,l;return i(this,(function(i){switch(i.label){case 0:return e=t.response.body,r.supportsEncryptFile&&(n.cipherKey||u)?null!=n.cipherKey?[3,2]:[4,u.decryptFile(r.create({data:e,name:n.name}),r)]:[3,5];case 1:return o=i.sent().data,[3,4];case 2:return[4,a.decrypt(null!==(c=n.cipherKey)&&void 0!==c?c:s.cipherKey,e)];case 3:o=i.sent(),i.label=4;case 4:e=o,i.label=5;case 5:return[2,r.create({data:e,name:null!==(l=t.response.name)&&void 0!==l?l:n.name,mimeType:t.response.type})]}}))}))}},Se={getOperation:function(){return j.PNListFilesOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.id)?(null==t?void 0:t.name)?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"},useDelete:function(){return!0},getURL:function(e,t){var n=e.config;return"/v1/files/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/files/").concat(t.id,"/").concat(t.name)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status}}},we={getOperation:function(){return j.PNGetAllUUIDMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,next:t.next,prev:t.prev}}},Oe={getOperation:function(){return j.PNGetUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Pe={getOperation:function(){return j.PNSetUUIDMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.data))return"Data cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o=e.config,i={};return i.uuid=null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:o.getUUID(),i.include=["status","type","custom"],(null==t?void 0:t.include)&&!1===(null===(r=t.include)||void 0===r?void 0:r.customFields)&&i.include.pop(),i.include=i.include.join(","),i},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ee={getOperation:function(){return j.PNRemoveUUIDMetadataOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r=e.config;return{uuid:null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ae={getOperation:function(){return j.PNGetAllChannelMetadataOperation},validateParams:function(){},getURL:function(e){var t=e.config;return"/v2/objects/".concat(t.subscribeKey,"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["status","type"]};return(null==t?void 0:t.include)&&(null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),h.include=h.include.join(","),(null===(r=null==t?void 0:t.include)||void 0===r?void 0:r.totalCount)&&(h.count=null===(o=t.include)||void 0===o?void 0:o.totalCount),(null===(i=null==t?void 0:t.page)||void 0===i?void 0:i.next)&&(h.start=null===(s=t.page)||void 0===s?void 0:s.next),(null===(u=null==t?void 0:t.page)||void 0===u?void 0:u.prev)&&(h.end=null===(c=t.page)||void 0===c?void 0:c.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),h.limit=null!==(l=null==t?void 0:t.limit)&&void 0!==l?l:100,(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Te={getOperation:function(){return j.PNGetChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ne={getOperation:function(){return j.PNSetChannelMetadataOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.data)?void 0:"Data cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},patchPayload:function(e,t){return t.data},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r={include:["status","type","custom"]};return(null==t?void 0:t.include)&&!1===(null===(n=t.include)||void 0===n?void 0:n.customFields)&&r.include.pop(),r.include=r.include.join(","),r},handleResponse:function(e,t){return{status:t.status,data:t.data}}},Ce={getOperation:function(){return j.PNRemoveChannelMetadataOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"Channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{status:t.status,data:t.data}}},ke={getOperation:function(){return j.PNGetMembersOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channel))return"channel cannot be empty"},getURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&m.include.push("uuid"),(null===(i=t.include)||void 0===i?void 0:i.customUUIDFields)&&m.include.push("uuid.custom"),(null===(s=t.include)||void 0===s?void 0:s.UUIDStatusField)&&m.include.push("uuid.status"),(null===(u=t.include)||void 0===u?void 0:u.UUIDTypeField)&&m.include.push("uuid.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Me={getOperation:function(){return j.PNSetMembersOperation},validateParams:function(e,t){return(null==t?void 0:t.channel)?(null==t?void 0:t.uuids)&&0!==(null==t?void 0:t.uuids.length)?void 0:"UUIDs cannot be empty":"Channel cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n=e.config;return"/v2/objects/".concat(n.subscribeKey,"/channels/").concat(H.encodeString(t.channel),"/uuids")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.uuids.map((function(e){return"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["uuid.status","uuid.type","type"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customUUIDFields)&&h.include.push("uuid.custom"),(null===(o=t.include)||void 0===o?void 0:o.UUIDFields)&&h.include.push("uuid")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},je={getOperation:function(){return j.PNGetMembershipsOperation},validateParams:function(){},getURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=null==t?void 0:t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h,f,d,y,g,m={include:[]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.statusField)&&m.include.push("status"),(null===(r=t.include)||void 0===r?void 0:r.customFields)&&m.include.push("custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&m.include.push("channel"),(null===(i=t.include)||void 0===i?void 0:i.customChannelFields)&&m.include.push("channel.custom"),(null===(s=t.include)||void 0===s?void 0:s.channelStatusField)&&m.include.push("channel.status"),(null===(u=t.include)||void 0===u?void 0:u.channelTypeField)&&m.include.push("channel.type")),m.include=m.include.join(","),(null===(c=null==t?void 0:t.include)||void 0===c?void 0:c.totalCount)&&(m.count=null===(l=t.include)||void 0===l?void 0:l.totalCount),(null===(p=null==t?void 0:t.page)||void 0===p?void 0:p.next)&&(m.start=null===(h=t.page)||void 0===h?void 0:h.next),(null===(f=null==t?void 0:t.page)||void 0===f?void 0:f.prev)&&(m.end=null===(d=t.page)||void 0===d?void 0:d.prev),(null==t?void 0:t.filter)&&(m.filter=t.filter),m.limit=null!==(y=null==t?void 0:t.limit)&&void 0!==y?y:100,(null==t?void 0:t.sort)&&(m.sort=Object.entries(null!==(g=t.sort)&&void 0!==g?g:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),m},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}},Re={getOperation:function(){return j.PNSetMembershipsOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)||0===(null==t?void 0:t.channels.length))return"Channels cannot be empty"},usePatch:function(){return!0},patchURL:function(e,t){var n,r=e.config;return"/v2/objects/".concat(r.subscribeKey,"/uuids/").concat(H.encodeString(null!==(n=t.uuid)&&void 0!==n?n:r.getUUID()),"/channels")},patchPayload:function(e,t){var n;return(n={set:[],delete:[]})[t.type]=t.channels.map((function(e){return"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},custom:e.custom,status:e.status}})),n},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n,r,o,i,s,u,c,l,p,h={include:["channel.status","channel.type","status"]};return(null==t?void 0:t.include)&&((null===(n=t.include)||void 0===n?void 0:n.customFields)&&h.include.push("custom"),(null===(r=t.include)||void 0===r?void 0:r.customChannelFields)&&h.include.push("channel.custom"),(null===(o=t.include)||void 0===o?void 0:o.channelFields)&&h.include.push("channel")),h.include=h.include.join(","),(null===(i=null==t?void 0:t.include)||void 0===i?void 0:i.totalCount)&&(h.count=!0),(null===(s=null==t?void 0:t.page)||void 0===s?void 0:s.next)&&(h.start=null===(u=t.page)||void 0===u?void 0:u.next),(null===(c=null==t?void 0:t.page)||void 0===c?void 0:c.prev)&&(h.end=null===(l=t.page)||void 0===l?void 0:l.prev),(null==t?void 0:t.filter)&&(h.filter=t.filter),null!=t.limit&&(h.limit=t.limit),(null==t?void 0:t.sort)&&(h.sort=Object.entries(null!==(p=t.sort)&&void 0!==p?p:{}).map((function(e){var t=a(e,2),n=t[0],r=t[1];return"asc"===r||"desc"===r?"".concat(n,":").concat(r):n}))),h},handleResponse:function(e,t){return{status:t.status,data:t.data,totalCount:t.totalCount,prev:t.prev,next:t.next}}};var xe=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerAudit},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/audit/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channel,r=t.channelGroup,o=t.authKeys,i=void 0===o?[]:o,s={};return n&&(s.channel=n),r&&(s["channel-group"]=r),i.length>0&&(s.auth=i.join(",")),s},handleResponse:function(e,t){return t.payload}});var Ue=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrant},validateParams:function(e,t){var n=e.config;return n.subscribeKey?n.publishKey?n.secretKey?null==t.uuids||t.authKeys?null==t.uuids||null==t.channels&&null==t.channelGroups?void 0:"Both channel/channelgroup and uuid cannot be used in the same request":"authKeys are required for grant request on uuids":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"},getURL:function(e){var t=e.config;return"/v2/auth/grant/sub-key/".concat(t.subscribeKey)},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.uuids,a=void 0===s?[]:s,u=t.ttl,c=t.read,l=void 0!==c&&c,p=t.write,h=void 0!==p&&p,f=t.manage,d=void 0!==f&&f,y=t.get,g=void 0!==y&&y,m=t.join,b=void 0!==m&&m,v=t.update,_=void 0!==v&&v,S=t.authKeys,w=void 0===S?[]:S,O=t.delete,P={};return P.r=l?"1":"0",P.w=h?"1":"0",P.m=d?"1":"0",P.d=O?"1":"0",P.g=g?"1":"0",P.j=b?"1":"0",P.u=_?"1":"0",r.length>0&&(P.channel=r.join(",")),i.length>0&&(P["channel-group"]=i.join(",")),w.length>0&&(P.auth=w.join(",")),a.length>0&&(P["target-uuid"]=a.join(",")),(u||0===u)&&(P.ttl=u),P},handleResponse:function(){return{}}});function Ie(e){var t,n,r,o,i=void 0!==(null==e?void 0:e.authorizedUserId),s=void 0!==(null===(t=null==e?void 0:e.resources)||void 0===t?void 0:t.users),a=void 0!==(null===(n=null==e?void 0:e.resources)||void 0===n?void 0:n.spaces),u=void 0!==(null===(r=null==e?void 0:e.patterns)||void 0===r?void 0:r.users),c=void 0!==(null===(o=null==e?void 0:e.patterns)||void 0===o?void 0:o.spaces);return u||s||c||a||i}function De(e){var t=0;return e.join&&(t|=128),e.update&&(t|=64),e.get&&(t|=32),e.delete&&(t|=8),e.manage&&(t|=4),e.write&&(t|=2),e.read&&(t|=1),t}function Fe(e,t){if(Ie(t))return function(e,t){var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorizedUserId,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.users,c=r.spaces,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.users,h=o.spaces,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}(0,t);var n=t.ttl,r=t.resources,o=t.patterns,i=t.meta,s=t.authorized_uuid,a={ttl:0,permissions:{resources:{channels:{},groups:{},uuids:{},users:{},spaces:{}},patterns:{channels:{},groups:{},uuids:{},users:{},spaces:{}},meta:{}}};if(r){var u=r.uuids,c=r.channels,l=r.groups;u&&Object.keys(u).forEach((function(e){a.permissions.resources.uuids[e]=De(u[e])})),c&&Object.keys(c).forEach((function(e){a.permissions.resources.channels[e]=De(c[e])})),l&&Object.keys(l).forEach((function(e){a.permissions.resources.groups[e]=De(l[e])}))}if(o){var p=o.uuids,h=o.channels,f=o.groups;p&&Object.keys(p).forEach((function(e){a.permissions.patterns.uuids[e]=De(p[e])})),h&&Object.keys(h).forEach((function(e){a.permissions.patterns.channels[e]=De(h[e])})),f&&Object.keys(f).forEach((function(e){a.permissions.patterns.groups[e]=De(f[e])}))}return(n||0===n)&&(a.ttl=n),i&&(a.permissions.meta=i),s&&(a.permissions.uuid="".concat(s)),a}var Le=Object.freeze({__proto__:null,getOperation:function(){return j.PNAccessManagerGrantToken},extractPermissions:De,validateParams:function(e,t){var n,r,o,i,s,a,u=e.config;if(!u.subscribeKey)return"Missing Subscribe Key";if(!u.publishKey)return"Missing Publish Key";if(!u.secretKey)return"Missing Secret Key";if(!t.resources&&!t.patterns)return"Missing either Resources or Patterns.";var c=void 0!==(null==t?void 0:t.authorized_uuid),l=void 0!==(null===(n=null==t?void 0:t.resources)||void 0===n?void 0:n.uuids),p=void 0!==(null===(r=null==t?void 0:t.resources)||void 0===r?void 0:r.channels),h=void 0!==(null===(o=null==t?void 0:t.resources)||void 0===o?void 0:o.groups),f=void 0!==(null===(i=null==t?void 0:t.patterns)||void 0===i?void 0:i.uuids),d=void 0!==(null===(s=null==t?void 0:t.patterns)||void 0===s?void 0:s.channels),y=void 0!==(null===(a=null==t?void 0:t.patterns)||void 0===a?void 0:a.groups),g=c||l||f||p||d||h||y;return Ie(t)&&g?"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`":(!t.resources||t.resources.uuids&&0!==Object.keys(t.resources.uuids).length||t.resources.channels&&0!==Object.keys(t.resources.channels).length||t.resources.groups&&0!==Object.keys(t.resources.groups).length||t.resources.users&&0!==Object.keys(t.resources.users).length||t.resources.spaces&&0!==Object.keys(t.resources.spaces).length)&&(!t.patterns||t.patterns.uuids&&0!==Object.keys(t.patterns.uuids).length||t.patterns.channels&&0!==Object.keys(t.patterns.channels).length||t.patterns.groups&&0!==Object.keys(t.patterns.groups).length||t.patterns.users&&0!==Object.keys(t.patterns.users).length||t.patterns.spaces&&0!==Object.keys(t.patterns.spaces).length)?void 0:"Missing values for either Resources or Patterns."},postURL:function(e){var t=e.config;return"/v3/pam/".concat(t.subscribeKey,"/grant")},usePost:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(){return{}},postPayload:function(e,t){return Fe(0,t)},handleResponse:function(e,t){return t.data.token}}),Ge={getOperation:function(){return j.PNAccessManagerRevokeToken},validateParams:function(e,t){return e.config.secretKey?t?void 0:"token can't be empty":"Missing Secret Key"},getURL:function(e,t){var n=e.config;return"/v3/pam/".concat(n.subscribeKey,"/grant/").concat(H.encodeString(t))},useDelete:function(){return!0},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!1},prepareParams:function(e){return{uuid:e.config.getUUID()}},handleResponse:function(e,t){return{status:t.status,data:t.data}}};function Ke(e,t){var n=JSON.stringify(t);if(e.cryptoModule){var r=e.cryptoModule.encrypt(n);n="string"==typeof r?r:b(r),n=JSON.stringify(n)}return n||""}var Be=Object.freeze({__proto__:null,getOperation:function(){return j.PNPublishOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},usePost:function(e,t){var n=t.sendByPost;return void 0!==n&&n},getURL:function(e,t){var n=e.config,r=t.channel,o=Ke(e,t.message);return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0/").concat(H.encodeString(o))},postURL:function(e,t){var n=e.config,r=t.channel;return"/publish/".concat(n.publishKey,"/").concat(n.subscribeKey,"/0/").concat(H.encodeString(r),"/0")},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},postPayload:function(e,t){return Ke(e,t.message)},prepareParams:function(e,t){var n=t.meta,r=t.replicate,o=void 0===r||r,i=t.storeInHistory,s=t.ttl,a={};return null!=i&&(a.store=i?"1":"0"),s&&(a.ttl=s),!1===o&&(a.norep="true"),n&&"object"==typeof n&&(a.meta=JSON.stringify(n)),a},handleResponse:function(e,t){return{timetoken:t[2]}}});var He=Object.freeze({__proto__:null,getOperation:function(){return j.PNSignalOperation},validateParams:function(e,t){var n=e.config,r=t.message;return t.channel?r?n.subscribeKey?void 0:"Missing Subscribe Key":"Missing Message":"Missing Channel"},getURL:function(e,t){var n,r=e.config,o=t.channel,i=t.message,s=(n=i,JSON.stringify(n));return"/signal/".concat(r.publishKey,"/").concat(r.subscribeKey,"/0/").concat(H.encodeString(o),"/0/").concat(H.encodeString(s))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(){return{}},handleResponse:function(e,t){return{timetoken:t[2]}}});var qe=Object.freeze({__proto__:null,getOperation:function(){return j.PNHistoryOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channel,r=e.config;return"/v2/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o=t.reverse,i=t.count,s=void 0===i?100:i,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p={include_token:"true"};return p.count=s,n&&(p.start=n),r&&(p.end=r),u&&(p.string_message_token="true"),null!=o&&(p.reverse=o.toString()),l&&(p.include_meta="true"),p},handleResponse:function(e,t){var n={messages:[],startTimeToken:t[1],endTimeToken:t[2]};return Array.isArray(t[0])&&t[0].forEach((function(t){var r=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message),o={timetoken:t.timetoken,entry:r.payload};t.meta&&(o.meta=t.meta),r.error&&(o.error=r.error),n.messages.push(o)})),n}});var ze=Object.freeze({__proto__:null,getOperation:function(){return j.PNDeleteMessagesOperation},validateParams:function(e,t){var n=t.channel,r=e.config;return n?r.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},useDelete:function(){return!0},getURL:function(e,t){var n=t.channel,r=e.config;return"/v3/history/sub-key/".concat(r.subscribeKey,"/channel/").concat(H.encodeString(n))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.start,r=t.end,o={};return n&&(o.start=n),r&&(o.end=r),o},handleResponse:function(e,t){return t.payload}});var Ve=Object.freeze({__proto__:null,getOperation:function(){return j.PNMessageCounts},validateParams:function(e,t){var n=t.channels,r=t.timetoken,o=t.channelTimetokens,i=e.config;return n?r&&o?"timetoken and channelTimetokens are incompatible together":o&&o.length>1&&n.length!==o.length?"Length of channelTimetokens and channels do not match":i.subscribeKey?void 0:"Missing Subscribe Key":"Missing channel"},getURL:function(e,t){var n=t.channels,r=e.config,o=n.join(",");return"/v3/history/sub-key/".concat(r.subscribeKey,"/message-counts/").concat(H.encodeString(o))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.timetoken,r=t.channelTimetokens,o={};if(r&&1===r.length){var i=a(r,1)[0];o.timetoken=i}else r?o.channelsTimetoken=r.join(","):n&&(o.timetoken=n);return o},handleResponse:function(e,t){return{channels:t.channels}}});var We=Object.freeze({__proto__:null,getOperation:function(){return j.PNFetchMessagesOperation},validateParams:function(e,t){var n=t.channels,r=t.includeMessageActions,o=void 0!==r&&r,i=e.config;if(!n||0===n.length)return"Missing channels";if(!i.subscribeKey)return"Missing Subscribe Key";if(o&&n.length>1)throw new TypeError("History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.")},getURL:function(e,t){var n=t.channels,r=void 0===n?[]:n,o=t.includeMessageActions,i=void 0!==o&&o,s=e.config,a=i?"history-with-actions":"history",u=r.length>0?r.join(","):",";return"/v3/".concat(a,"/sub-key/").concat(s.subscribeKey,"/channel/").concat(H.encodeString(u))},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=t.channels,r=t.start,o=t.end,i=t.includeMessageActions,s=t.count,a=t.stringifiedTimeToken,u=void 0!==a&&a,c=t.includeMeta,l=void 0!==c&&c,p=t.includeUuid,h=t.includeUUID,f=void 0===h||h,d=t.includeMessageType,y=void 0===d||d,g={};return g.max=s||(n.length>1||!0===i?25:100),r&&(g.start=r),o&&(g.end=o),u&&(g.string_message_token="true"),l&&(g.include_meta="true"),f&&!1!==p&&(g.include_uuid="true"),y&&(g.include_message_type="true"),g},handleResponse:function(e,t){var n={channels:{}};return Object.keys(t.channels||{}).forEach((function(r){n.channels[r]=[],(t.channels[r]||[]).forEach((function(t){var o={},i=function(e,t){var n={};if(!e.cryptoModule)return n.payload=t,n;try{var r=e.cryptoModule.decrypt(t),o=r instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(r)):r;return n.payload=o,n}catch(r){e.config.logVerbosity&&console&&console.log&&console.log("decryption error",r.message),n.payload=t,n.error="Error while decrypting message content: ".concat(r.message)}return n}(e,t.message);o.channel=r,o.timetoken=t.timetoken,o.message=i.payload,o.messageType=t.message_type,o.uuid=t.uuid,t.actions&&(o.actions=t.actions,o.data=t.actions),t.meta&&(o.meta=t.meta),i.error&&(o.error=i.error),n.channels[r].push(o)}))})),t.more&&(n.more=t.more),n}});var Je=Object.freeze({__proto__:null,getOperation:function(){return j.PNTimeOperation},getURL:function(){return"/time/0"},getRequestTimeout:function(e){return e.config.getTransactionTimeout()},prepareParams:function(){return{}},isAuthSupported:function(){return!1},handleResponse:function(e,t){return{timetoken:t[0]}},validateParams:function(){}});var $e=Object.freeze({__proto__:null,getOperation:function(){return j.PNSubscribeOperation},validateParams:function(e){if(!e.config.subscribeKey)return"Missing Subscribe Key"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n=e.config,r=t.state,o=t.channelGroups,i=void 0===o?[]:o,s=t.timetoken,a=t.filterExpression,u=t.region,c={heartbeat:n.getPresenceTimeout()};return i.length>0&&(c["channel-group"]=i.join(",")),a&&a.length>0&&(c["filter-expr"]=a),Object.keys(r).length&&(c.state=JSON.stringify(r)),s&&(c.tt=s),u&&(c.tr=u),c},handleResponse:function(e,t){var n=[];t.m.forEach((function(e){var t={timetoken:e.p.t,region:e.p.r},r={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:t};n.push(r)}));var r={timetoken:t.t.t,region:t.t.r};return{messages:n,metadata:r}}}),Qe={getOperation:function(){return j.PNHandshakeOperation},validateParams:function(e,t){if(!(null==t?void 0:t.channels)&&!(null==t?void 0:t.channelGroups))return"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),n.tt=0,t.state&&(n.state=JSON.stringify(t.state)),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.ee="",n},handleResponse:function(e,t){return{region:t.t.r,timetoken:t.t.t}}},Xe={getOperation:function(){return j.PNReceiveMessagesOperation},validateParams:function(e,t){return(null==t?void 0:t.channels)||(null==t?void 0:t.channelGroups)?(null==t?void 0:t.timetoken)?(null==t?void 0:t.region)?void 0:"region can not be empty":"timetoken can not be empty":"channels and channleGroups both should not be empty"},getURL:function(e,t){var n=e.config,r=t.channels,o=void 0===r?[]:r,i=o.length>0?o.join(","):",";return"/v2/subscribe/".concat(n.subscribeKey,"/").concat(H.encodeString(i),"/0")},getRequestTimeout:function(e){return e.config.getSubscribeTimeout()},isAuthSupported:function(){return!0},getAbortSignal:function(e,t){return t.abortSignal},prepareParams:function(e,t){var n={};return t.channelGroups&&t.channelGroups.length>0&&(n["channel-group"]=t.channelGroups.join(",")),t.filterExpression&&t.filterExpression.length>0&&(n["filter-expr"]=t.filterExpression),n.tt=t.timetoken,n.tr=t.region,n.ee="",n},handleResponse:function(e,t){var n=[];return t.m.forEach((function(e){var t={shard:parseInt(e.a,10),subscriptionMatch:e.b,channel:e.c,messageType:e.e,payload:e.d,flags:e.f,issuingClientId:e.i,subscribeKey:e.k,originationTimetoken:e.o,userMetadata:e.u,publishMetaData:{timetoken:e.p.t,region:e.p.r}};n.push(t)})),{messages:n,metadata:{region:t.t.r,timetoken:t.t.t}}}},Ye=function(){function e(e){void 0===e&&(e=!1),this.sync=e,this.listeners=new Set}return e.prototype.subscribe=function(e){var t=this;return this.listeners.add(e),function(){t.listeners.delete(e)}},e.prototype.notify=function(e){var t=this,n=function(){t.listeners.forEach((function(t){t(e)}))};this.sync?n():setTimeout(n,0)},e}(),Ze=function(){function e(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}return e.prototype.transition=function(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)},e.prototype.on=function(e,t){return this.transitionMap.set(e,t),this},e.prototype.with=function(e,t){return[this,e,null!=t?t:[]]},e.prototype.onEnter=function(e){return this.enterEffects.push(e),this},e.prototype.onExit=function(e){return this.exitEffects.push(e),this},e}(),et=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return t(n,e),n.prototype.describe=function(e){return new Ze(e)},n.prototype.start=function(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})},n.prototype.transition=function(e){var t,n,r,o,i,u;if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});var c=this.currentState.transition(this.currentContext,e);if(c){var l=a(c,3),p=l[0],h=l[1],f=l[2];try{for(var d=s(this.currentState.exitEffects),y=d.next();!y.done;y=d.next()){var g=y.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){t={error:e}}finally{try{y&&!y.done&&(n=d.return)&&n.call(d)}finally{if(t)throw t.error}}var m=this.currentState;this.currentState=p;var b=this.currentContext;this.currentContext=h,this.notify({type:"transitionDone",fromState:m,fromContext:b,toState:p,toContext:h,event:e});try{for(var v=s(f),_=v.next();!_.done;_=v.next()){g=_.value;this.notify({type:"invocationDispatched",invocation:g})}}catch(e){r={error:e}}finally{try{_&&!_.done&&(o=v.return)&&o.call(v)}finally{if(r)throw r.error}}try{for(var S=s(this.currentState.enterEffects),w=S.next();!w.done;w=S.next()){g=w.value;this.notify({type:"invocationDispatched",invocation:g(this.currentContext)})}}catch(e){i={error:e}}finally{try{w&&!w.done&&(u=S.return)&&u.call(S)}finally{if(i)throw i.error}}}},n}(Ye),tt=function(){function e(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}return e.prototype.on=function(e,t){this.handlers.set(e,t)},e.prototype.dispatch=function(e){if("CANCEL"!==e.type){var t=this.handlers.get(e.type);if(!t)throw new Error("Unhandled invocation '".concat(e.type,"'"));var n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}else if(this.instances.has(e.payload)){var r=this.instances.get(e.payload);null==r||r.cancel(),this.instances.delete(e.payload)}},e.prototype.dispose=function(){var e,t;try{for(var n=s(this.instances.entries()),r=n.next();!r.done;r=n.next()){var o=a(r.value,2),i=o[0];o[1].cancel(),this.instances.delete(i)}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}},e}();function nt(e,t){var n=function(){for(var n=[],r=0;r0&&r(e),[2]}))}))}))),s.on(ht.type,ut((function(e,t,n){var r=n.emitStatus;return o(s,void 0,void 0,(function(){return i(this,(function(t){return r(e),[2]}))}))}))),s.on(ft.type,ut((function(e,n,r){var a=r.receiveMessages,u=r.delay,c=r.config;return o(s,void 0,void 0,(function(){var r,o;return i(this,(function(i){switch(i.label){case 0:return c.retryConfiguration&&c.retryConfiguration.shouldRetry(e.reason,e.attempts)?(n.throwIfAborted(),[4,u(c.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),n.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,a({abortSignal:n,channels:e.channels,channelGroups:e.groups,timetoken:e.cursor.timetoken,region:e.cursor.region,filterExpression:c.filterExpression})];case 3:return r=i.sent(),[2,t.transition(Pt(r.metadata,r.messages))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Et(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(At(new q(c.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s.on(dt.type,ut((function(e,r,a){var u=a.handshake,c=a.delay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o,s;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({abortSignal:r,channels:e.channels,channelGroups:e.groups,filterExpression:p.filterExpression},p.maintainPresenceState&&{state:l}))];case 3:return o=i.sent(),[2,t.transition(vt(o))];case 4:return(s=i.sent())instanceof Error&&"Aborted"===s.message?[2]:s instanceof q?[2,t.transition(_t(s))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(St(new q(p.retryConfiguration.getGiveupReason(e.reason,e.attempts))))];case 7:return[2]}}))}))}))),s}return t(r,e),r}(tt),Mt=new Ze("HANDSHAKE_FAILED");Mt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Mt.on(Nt.type,(function(e,t){return Ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor})})),Mt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(r=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==r?r:0}})})),Mt.on(Ct.type,(function(e){return Lt.with()}));var jt=new Ze("HANDSHAKE_STOPPED");jt.on(yt.type,(function(e,t){return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),jt.on(Nt.type,(function(e,t){return Ft.with(n(n({},e),{cursor:t.payload.cursor||e.cursor}))})),jt.on(gt.type,(function(e,t){var n;return jt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),jt.on(Ct.type,(function(e){return Lt.with()}));var Rt=new Ze("RECEIVE_FAILED");Rt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Rt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Rt.on(Ct.type,(function(e){return Lt.with(void 0)}));var xt=new Ze("RECEIVE_STOPPED");xt.on(yt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),xt.on(gt.type,(function(e,t){return xt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Nt.type,(function(e,t){var n;return Ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),xt.on(Ct.type,(function(){return Lt.with(void 0)}));var Ut=new Ze("RECEIVE_RECONNECTING");Ut.onEnter((function(e){return ft(e)})),Ut.onExit((function(){return ft.cancel})),Ut.on(Pt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),Ut.on(Et.type,(function(e,t){return Ut.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Ut.on(At.type,(function(e,t){var n;return Rt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Ut.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),Ut.on(gt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),Ut.on(yt.type,(function(e,t){return It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ut.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var It=new Ze("RECEIVING");It.onEnter((function(e){return lt(e.channels,e.groups,e.cursor)})),It.onExit((function(){return lt.cancel})),It.on(wt.type,(function(e,t){return It.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[pt(t.payload.events)])})),It.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups})})),It.on(gt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):It.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),It.on(Ot.type,(function(e,t){return Ut.with(n(n({},e),{attempts:0,reason:t.payload}))})),It.on(Tt.type,(function(e){return xt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ht({category:k.PNDisconnectedCategory})])})),It.on(Ct.type,(function(e){return Lt.with(void 0,[ht({category:k.PNDisconnectedCategory})])}));var Dt=new Ze("HANDSHAKE_RECONNECTING");Dt.onEnter((function(e){return dt(e)})),Dt.onExit((function(){return dt.cancel})),Dt.on(vt.type,(function(e,t){var n,r,o={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=e.cursor)||void 0===r?void 0:r.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return It.with({channels:e.channels,groups:e.groups,cursor:o},[ht({category:k.PNConnectedCategory})])})),Dt.on(_t.type,(function(e,t){return Dt.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),Dt.on(St.type,(function(e,t){var n;return Mt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ht({category:k.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),Dt.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Dt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Dt.on(gt.type,(function(e,t){var n,r;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.region)||0}})})),Dt.on(Ct.type,(function(e){return Lt.with(void 0)}));var Ft=new Ze("HANDSHAKING");Ft.onEnter((function(e){return ct(e.channels,e.groups)})),Ft.onExit((function(){return ct.cancel})),Ft.on(yt.type,(function(e,t){return 0===t.payload.channels.length&&0===t.payload.groups.length?Lt.with(void 0):Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor})})),Ft.on(mt.type,(function(e,t){var n,r;return It.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(r=null==e?void 0:e.cursor)||void 0===r?void 0:r.timetoken:t.payload.timetoken,region:t.payload.region}},[ht({category:k.PNConnectedCategory})])})),Ft.on(bt.type,(function(e,t){return Dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload})})),Ft.on(Tt.type,(function(e){return jt.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),Ft.on(gt.type,(function(e,t){var n;return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),Ft.on(Ct.type,(function(e){return Lt.with()}));var Lt=new Ze("UNSUBSCRIBED");Lt.on(yt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups})})),Lt.on(gt.type,(function(e,t){return Ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})}));var Gt=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new kt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(Lt,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.subscribe=function(e){var t=this,n=e.channels,r=e.channelGroups,o=e.timetoken,i=e.withPresence;this.channels=u(u([],a(this.channels),!1),a(null!=n?n:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=r?r:[]),!1),i&&(this.channels.map((function(e){return t.channels.push("".concat(e,"-pnpres"))})),this.groups.map((function(e){return t.groups.push("".concat(e,"-pnpres"))}))),o?this.engine.transition(gt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))),o)):this.engine.transition(yt(Array.from(new Set(u(u([],a(this.channels),!1),a(null!=n?n:[]),!1))),Array.from(new Set(u(u([],a(this.groups),!1),a(null!=r?r:[]),!1))))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((function(e){return!e.endsWith("-pnpres")})))),groups:Array.from(new Set(this.groups.filter((function(e){return!e.endsWith("-pnpres")}))))})},e.prototype.unsubscribe=function(e){var t=this,n=e.channels,r=void 0===n?[]:n,o=e.channelGroups,i=void 0===o?[]:o,s=H.removeSingleOccurance(this.channels,u(u([],a(r),!1),a(r.map((function(e){return"".concat(e,"-pnpres")}))),!1)),c=H.removeSingleOccurance(this.groups,u(u([],a(i),!1),a(i.map((function(e){return"".concat(e,"-pnpres")}))),!1));if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(c).size){var l=H.findUniqueCommonElements(this.channels,r),p=H.findUniqueCommonElements(this.groups,i);this.dependencies.presenceState&&(null==l||l.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==p||p.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.channels=s,this.groups=c,this.engine.transition(yt(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:l.slice(0),groups:p.slice(0)})}},e.prototype.unsubscribeAll=function(){this.channels=[],this.groups=[],this.dependencies.presenceState&&(this.dependencies.presenceState={}),this.engine.transition(yt(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.reconnect=function(e){var t=e.timetoken,n=e.region;this.engine.transition(Nt(t,n))},e.prototype.disconnect=function(){this.engine.transition(Tt()),this.dependencies.leaveAll&&this.dependencies.leaveAll()},e.prototype.getSubscribedChannels=function(){return Array.from(new Set(this.channels))},e.prototype.getSubscribedChannelGroups=function(){return Array.from(new Set(this.groups))},e.prototype.dispose=function(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),Kt=nt("RECONNECT",(function(){return{}})),Bt=nt("DISCONNECT",(function(){return{}})),Ht=nt("JOINED",(function(e,t){return{channels:e,groups:t}})),qt=nt("LEFT",(function(e,t){return{channels:e,groups:t}})),zt=nt("LEFT_ALL",(function(){return{}})),Vt=nt("HEARTBEAT_SUCCESS",(function(e){return{statusCode:e}})),Wt=nt("HEARTBEAT_FAILURE",(function(e){return e})),Jt=nt("HEARTBEAT_GIVEUP",(function(){return{}})),$t=nt("TIMES_UP",(function(){return{}})),Qt=rt("HEARTBEAT",(function(e,t){return{channels:e,groups:t}})),Xt=rt("LEAVE",(function(e,t){return{channels:e,groups:t}})),Yt=rt("EMIT_STATUS",(function(e){return e})),Zt=ot("WAIT",(function(){return{}})),en=ot("DELAYED_HEARTBEAT",(function(e){return e})),tn=function(e){function r(t,r){var s=e.call(this,r)||this;return s.on(Qt.type,ut((function(e,r,a){var u=a.heartbeat,c=a.presenceState,l=a.config;return o(s,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return o.trys.push([0,2,,3]),[4,u(n({channels:e.channels,channelGroups:e.groups},l.maintainPresenceState&&{state:c}))];case 1:return o.sent(),t.transition(Vt(200)),[3,3];case 2:return(r=o.sent())instanceof q?[2,t.transition(Wt(r))]:[3,3];case 3:return[2]}}))}))}))),s.on(Xt.type,ut((function(e,t,n){var r=n.leave,a=n.config;return o(s,void 0,void 0,(function(){return i(this,(function(t){switch(t.label){case 0:if(a.suppressLeaveEvents)return[3,4];t.label=1;case 1:return t.trys.push([1,3,,4]),[4,r({channels:e.channels,channelGroups:e.groups})];case 2:case 3:return t.sent(),[3,4];case 4:return[2]}}))}))}))),s.on(Zt.type,ut((function(e,n,r){var a=r.heartbeatDelay;return o(s,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return n.throwIfAborted(),[4,a()];case 1:return e.sent(),n.throwIfAborted(),[2,t.transition($t())]}}))}))}))),s.on(en.type,ut((function(e,r,a){var u=a.heartbeat,c=a.retryDelay,l=a.presenceState,p=a.config;return o(s,void 0,void 0,(function(){var o;return i(this,(function(i){switch(i.label){case 0:return p.retryConfiguration&&p.retryConfiguration.shouldRetry(e.reason,e.attempts)?(r.throwIfAborted(),[4,c(p.retryConfiguration.getDelay(e.attempts,e.reason))]):[3,6];case 1:i.sent(),r.throwIfAborted(),i.label=2;case 2:return i.trys.push([2,4,,5]),[4,u(n({channels:e.channels,channelGroups:e.groups},p.maintainPresenceState&&{state:l}))];case 3:return i.sent(),[2,t.transition(Vt(200))];case 4:return(o=i.sent())instanceof Error&&"Aborted"===o.message?[2]:o instanceof q?[2,t.transition(Wt(o))]:[3,5];case 5:return[3,7];case 6:return[2,t.transition(Jt())];case 7:return[2]}}))}))}))),s.on(Yt.type,ut((function(e,t,r){var a=r.emitStatus,u=r.config;return o(s,void 0,void 0,(function(){var t;return i(this,(function(r){return u.announceFailedHeartbeats&&!0===(null===(t=null==e?void 0:e.status)||void 0===t?void 0:t.error)?a(e.status):u.announceSuccessfulHeartbeats&&200===e.statusCode&&a(n(n({},e),{operation:j.PNHeartbeatOperation,error:!1})),[2]}))}))}))),s}return t(r,e),r}(tt),nn=new Ze("HEARTBEAT_STOPPED");nn.on(Ht.type,(function(e,t){return nn.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),nn.on(qt.type,(function(e,t){return nn.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))})})),nn.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),nn.on(zt.type,(function(e,t){return un.with(void 0)}));var rn=new Ze("HEARTBEAT_COOLDOWN");rn.onEnter((function(){return Zt()})),rn.onExit((function(){return Zt.cancel})),rn.on($t.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),rn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),rn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),rn.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),rn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var on=new Ze("HEARTBEAT_FAILED");on.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),on.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),on.on(Kt.type,(function(e,t){return an.with({channels:e.channels,groups:e.groups})})),on.on(Bt.type,(function(e,t){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),on.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var sn=new Ze("HEARBEAT_RECONNECTING");sn.onEnter((function(e){return en(e)})),sn.onExit((function(){return en.cancel})),sn.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),sn.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),sn.on(Bt.type,(function(e,t){nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),sn.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),sn.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:e.attempts+1,reason:t.payload}))})),sn.on(Jt.type,(function(e,t){return on.with({channels:e.channels,groups:e.groups})})),sn.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var an=new Ze("HEARTBEATING");an.onEnter((function(e){return Qt(e.channels,e.groups)})),an.on(Vt.type,(function(e,t){return rn.with({channels:e.channels,groups:e.groups})})),an.on(Ht.type,(function(e,t){return an.with({channels:u(u([],a(e.channels),!1),a(t.payload.channels),!1),groups:u(u([],a(e.groups),!1),a(t.payload.groups),!1)})})),an.on(qt.type,(function(e,t){return an.with({channels:e.channels.filter((function(e){return!t.payload.channels.includes(e)})),groups:e.groups.filter((function(e){return!t.payload.groups.includes(e)}))},[Xt(t.payload.channels,t.payload.groups)])})),an.on(Wt.type,(function(e,t){return sn.with(n(n({},e),{attempts:0,reason:t.payload}))})),an.on(Bt.type,(function(e){return nn.with({channels:e.channels,groups:e.groups},[Xt(e.channels,e.groups)])})),an.on(zt.type,(function(e,t){return un.with(void 0,[Xt(e.channels,e.groups)])}));var un=new Ze("HEARTBEAT_INACTIVE");un.on(Ht.type,(function(e,t){return an.with({channels:t.payload.channels,groups:t.payload.groups})}));var cn=function(){function e(e){var t=this;this.engine=new et,this.channels=[],this.groups=[],this.dispatcher=new tn(this.engine,e),this.dependencies=e,this._unsubscribeEngine=this.engine.subscribe((function(e){"invocationDispatched"===e.type&&t.dispatcher.dispatch(e.invocation)})),this.engine.start(un,void 0)}return Object.defineProperty(e.prototype,"_engine",{get:function(){return this.engine},enumerable:!1,configurable:!0}),e.prototype.join=function(e){var t=e.channels,n=e.groups;this.channels=u(u([],a(this.channels),!1),a(null!=t?t:[]),!1),this.groups=u(u([],a(this.groups),!1),a(null!=n?n:[]),!1),this.engine.transition(Ht(this.channels.slice(0),this.groups.slice(0)))},e.prototype.leave=function(e){var t=this,n=e.channels,r=e.groups;this.dependencies.presenceState&&(null==n||n.forEach((function(e){return delete t.dependencies.presenceState[e]})),null==r||r.forEach((function(e){return delete t.dependencies.presenceState[e]}))),this.engine.transition(qt(null!=n?n:[],null!=r?r:[]))},e.prototype.leaveAll=function(){this.engine.transition(zt())},e.prototype.dispose=function(){this._unsubscribeEngine(),this.dispatcher.dispose()},e}(),ln=function(){function e(){}return e.LinearRetryPolicy=function(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e.ExponentialRetryPolicy=function(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry:function(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay:function(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason:function(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"}}},e}(),pn=function(){function e(e){var t=e.modules,n=e.listenerManager,r=e.getFileUrl;this.modules=t,this.listenerManager=n,this.getFileUrl=r,this._channelListenerMap=new Map,this._groupListenerMap=new Map,t.cryptoModule&&(this._decoder=new TextDecoder)}return e.prototype.emitEvent=function(e){var t=e.channel,o=e.publishMetaData,i=e.subscriptionMatch;if(t===i&&(i=null),e.channel.endsWith("-pnpres")){var s={channel:null,subscription:null};t&&(s.channel=t.substring(0,t.lastIndexOf("-pnpres"))),i&&(s.subscription=i.substring(0,i.lastIndexOf("-pnpres"))),s.action=e.payload.action,s.state=e.payload.data,s.timetoken=o.timetoken,s.occupancy=e.payload.occupancy,s.uuid=e.payload.uuid,s.timestamp=e.payload.timestamp,e.payload.join&&(s.join=e.payload.join),e.payload.leave&&(s.leave=e.payload.leave),e.payload.timeout&&(s.timeout=e.payload.timeout),s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announcePresence(s),this._announce("presence",s,s.channel,s.subscription)}else if(1===e.messageType){(s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=e.payload,this.listenerManager.announceSignal(s),this._announce("signal",s,s.channel,s.subscription)}else if(2===e.messageType){if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),s.message={event:e.payload.event,type:e.payload.type,data:e.payload.data},this.listenerManager.announceObjects(s),this._announce("objects",s,s.channel,s.subscription),"uuid"===e.payload.type){var a=this._renameChannelField(s),u=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"user"})});this.listenerManager.announceUser(u),this._announce("user",u,s.channel,s.subscription)}else if("channel"===e.payload.type){a=this._renameChannelField(s);var c=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),type:"space"})});this.listenerManager.announceSpace(c),this._announce("space",c,s.channel,s.subscription)}else if("membership"===e.payload.type){var l=(a=this._renameChannelField(s)).message.data,p=l.uuid,h=l.channel,f=r(l,["uuid","channel"]);f.user=p,f.space=h;var d=n(n({},a),{message:n(n({},a.message),{event:this._renameEvent(a.message.event),data:f})});this.listenerManager.announceMembership(d),this._announce("membership",d,s.channel,s.subscription)}}else if(3===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,s.data={messageTimetoken:e.payload.data.messageTimetoken,actionTimetoken:e.payload.data.actionTimetoken,type:e.payload.data.type,uuid:e.issuingClientId,value:e.payload.data.value},s.event=e.payload.event,this.listenerManager.announceMessageAction(s),this._announce("messageAction",s,s.channel,s.subscription)}else if(4===e.messageType){(s={}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId;var y=e.payload;if(this.modules.cryptoModule){var g=void 0;try{g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}null!==g&&(y=g)}e.userMetadata&&(s.userMetadata=e.userMetadata),s.message=y.message,s.file={id:y.file.id,name:y.file.name,url:this.getFileUrl({id:y.file.id,name:y.file.name,channel:t})},this.listenerManager.announceFile(s),this._announce("file",s,s.channel,s.subscription)}else{if((s={channel:null,subscription:null}).channel=t,s.subscription=i,s.timetoken=o.timetoken,s.publisher=e.issuingClientId,e.userMetadata&&(s.userMetadata=e.userMetadata),this.modules.cryptoModule){g=void 0;try{var m;g=(m=this.modules.cryptoModule.decrypt(e.payload))instanceof ArrayBuffer?JSON.parse(this._decoder.decode(m)):m}catch(e){g=null,s.error="Error while decrypting message content: ".concat(e.message)}s.message=null!=g?g:e.payload}else s.message=e.payload;s.actualChannel=null!=i?t:null,s.subscribedChannel=null!=i?i:t,this.listenerManager.announceMessage(s),this._announce("message",s,s.channel,s.subscription)}},e.prototype.addListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){r._channelListenerMap[t]?r._channelListenerMap[t].includes(e)||r._channelListenerMap[t].push(e):r._channelListenerMap[t]=[e]})),null==n||n.forEach((function(t){r._groupListenerMap[t]?r._groupListenerMap[t].includes(e)||r._groupListenerMap[t].push(e):r._groupListenerMap[t]=[e]}))):this.listenerManager.addListener(e)},e.prototype.removeListener=function(e,t,n){var r=this;t&&n?(null==t||t.forEach((function(t){var n;r._channelListenerMap[t]=null===(n=r._channelListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))})),null==n||n.forEach((function(t){var n;r._groupListenerMap[t]=null===(n=r._groupListenerMap[t])||void 0===n?void 0:n.filter((function(t){return t!==e}))}))):this.listenerManager.removeListener(e)},e.prototype.removeAllListeners=function(){this.listenerManager.removeAllListeners()},e.prototype._renameEvent=function(e){return"set"===e?"updated":"removed"},e.prototype._renameChannelField=function(e){var t=e.channel,n=r(e,["channel"]);return n.spaceId=t,n},e.prototype._announce=function(e,t,n,r){var o,i;null===(o=this._channelListenerMap[n])||void 0===o||o.forEach((function(n){return n[e]&&n[e](t)})),null===(i=this._groupListenerMap[r])||void 0===i||i.forEach((function(n){return n[e]&&n[e](t)}))},e}(),hn=function(){function e(){}return e.prototype.subscribe=function(){var e,t;this.pubnub.subscribe(n({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))},e.prototype.unsubscribe=function(){this.pubnub.unsubscribe({channels:this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),channelGroups:this.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))})},Object.defineProperty(e.prototype,"onMessage",{set:function(e){this.listener.message=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onPresence",{set:function(e){this.listener.presence=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onSignal",{set:function(e){this.listener.signal=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onObjects",{set:function(e){this.listener.objects=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onMessageAction",{set:function(e){this.listener.messageAction=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"onFile",{set:function(e){this.listener.file=e},enumerable:!1,configurable:!0}),e.prototype.addListener=function(e){this.eventEmitter.addListener(e,this.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),this.groupNames.filter((function(e){return!e.endsWith("-pnpres")})))},e.prototype.removeListener=function(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)},Object.defineProperty(e.prototype,"channels",{get:function(){return this.channelNames.slice(0)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"channelGroups",{get:function(){return this.groupNames.slice(0)},enumerable:!1,configurable:!0}),e}(),fn=function(e){function n(t){var n=t.channels,r=void 0===n?[]:n,o=t.channelGroups,i=void 0===o?[]:o,s=t.subscriptionOptions,c=t.eventEmitter,l=t.pubnub,p=e.call(this)||this;return p.channelNames=[],p.groupNames=[],p.subscriptionList=[],p.options=s,p.eventEmitter=c,p.pubnub=l,r.filter((function(e){return!e.endsWith("-pnpres")})).forEach((function(e){var t=p.pubnub.channel(e).subscription(p.options);p.channelNames=u(u([],a(p.channelNames),!1),a(t.channels),!1),p.subscriptionList.push(t)})),i.filter((function(e){return!e.endsWith("-pnpres")})).forEach((function(e){var t=p.pubnub.channelGroup(e).subscription(p.options);p.groupNames=u(u([],a(p.groupNames),!1),a(t.channelGroups),!1),p.subscriptionList.push(t)})),p.listener={},c.addListener(p.listener,p.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),p.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),p}return t(n,e),n.prototype.addSubscription=function(e){this.subscriptionList.push(e),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)},n.prototype.removeSubscription=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return t!==e})),this.eventEmitter.removeListener(this.listener,t,n)},n.prototype.addSubscriptionSet=function(e){this.subscriptionList=u(u([],a(this.subscriptionList),!1),a(e.subscriptions),!1),this.channelNames=u(u([],a(this.channelNames),!1),a(e.channels),!1),this.groupNames=u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)},n.prototype.removeSubscriptionSet=function(e){var t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((function(e){return!t.includes(e)})),this.groupNames=this.groupNames.filter((function(e){return!n.includes(e)})),this.subscriptionList=this.subscriptionList.filter((function(t){return!e.subscriptions.includes(t)})),this.eventEmitter.removeListener(this.listener,t,n)},Object.defineProperty(n.prototype,"subscriptions",{get:function(){return this.subscriptionList.slice(0)},enumerable:!1,configurable:!0}),n}(hn),dn=function(e){function r(t){var n=t.channels,r=t.channelGroups,o=t.subscriptionOptions,i=t.eventEmitter,s=t.pubnub,a=e.call(this)||this;return a.channelNames=[],a.groupNames=[],a.channelNames=n,a.groupNames=r,a.options=o,a.pubnub=s,a.eventEmitter=i,a.listener={},i.addListener(a.listener,a.channelNames.filter((function(e){return!e.endsWith("-pnpres")})),a.groupNames.filter((function(e){return!e.endsWith("-pnpres")}))),a}return t(r,e),r.prototype.addSubscription=function(e){return new fn({channels:u(u([],a(this.channelNames),!1),a(e.channels),!1),channelGroups:u(u([],a(this.groupNames),!1),a(e.channelGroups),!1),subscriptionOptions:n(n({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})},r}(hn),yn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),gn=function(){function e(e,t,n){this.name=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,"".concat(this.name,"-pnpres")]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),mn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),bn=function(){function e(e,t,n){this.id=e,this.eventEmitter=t,this.pubnub=n}return e.prototype.subscription=function(e){return new dn({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})},e}(),vn=function(){function e(e){var t=this,r=e.networking,o=e.cbor,i=new g({setup:e});this._config=i;var c=new T({config:i}),l=e.cryptography;r.init(i);var p=new G(i,o);this._tokenManager=p;var h=new R({maximumSamplesCount:6e4});this._telemetryManager=h;var f=this._config.cryptoModule,d={config:i,networking:r,crypto:c,cryptography:l,tokenManager:p,telemetryManager:h,PubNubFile:e.PubNubFile,cryptoModule:f};this.File=e.PubNubFile,this.encryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.encryptFile(t,this.File)):l.encryptFile(e,t,this.File)},this.decryptFile=function(e,t){return 1==arguments.length&&"string"!=typeof e&&d.cryptoModule?(t=e,d.cryptoModule.decryptFile(t,this.File)):l.decryptFile(e,t,this.File)};var y=Q.bind(this,d,Je),m=Q.bind(this,d,se),v=Q.bind(this,d,ue),_=Q.bind(this,d,le),S=Q.bind(this,d,$e),w=new L;if(this._listenerManager=w,this.iAmHere=Q.bind(this,d,ue),this.iAmAway=Q.bind(this,d,se),this.setPresenceState=Q.bind(this,d,le),this.handshake=Q.bind(this,d,Qe),this.receiveMessages=Q.bind(this,d,Xe),this._eventEmitter=new pn({modules:d,listenerManager:this._listenerManager,getFileUrl:function(e){return ve(d,e)}}),!0===i.enableEventEngine){if(i.maintainPresenceState&&(this.presenceState={},this.setState=function(e){var n,r;return null===(n=e.channels)||void 0===n||n.forEach((function(n){return t.presenceState[n]=e.state})),null===(r=e.channelGroups)||void 0===r||r.forEach((function(n){return t.presenceState[n]=e.state})),t.setPresenceState({channels:e.channels,channelGroups:e.channelGroups,state:t.presenceState})}),i.getHeartbeatInterval()){var O=new cn({heartbeat:this.iAmHere,leave:this.iAmAway,heartbeatDelay:function(){return new Promise((function(e){return setTimeout(e,1e3*d.config.getHeartbeatInterval())}))},retryDelay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},config:d.config,presenceState:this.presenceState,emitStatus:function(e){w.announceStatus(e)}});this.presenceEventEngine=O,this.join=this.presenceEventEngine.join.bind(O),this.leave=this.presenceEventEngine.leave.bind(O),this.leaveAll=this.presenceEventEngine.leaveAll.bind(O)}var P=new Gt({handshake:this.handshake,receiveMessages:this.receiveMessages,delay:function(e){return new Promise((function(t){return setTimeout(t,e)}))},join:this.join,leave:this.leave,leaveAll:this.leaveAll,presenceState:this.presenceState,config:d.config,emitMessages:function(e){var n,r;try{for(var o=s(e),i=o.next();!i.done;i=o.next()){var a=i.value;t._eventEmitter.emitEvent(a)}}catch(e){n={error:e}}finally{try{i&&!i.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},emitStatus:function(e){w.announceStatus(e)}});this.subscribe=P.subscribe.bind(P),this.unsubscribe=P.unsubscribe.bind(P),this.unsubscribeAll=P.unsubscribeAll.bind(P),this.reconnect=P.reconnect.bind(P),this.disconnect=P.disconnect.bind(P),this.destroy=P.dispose.bind(P),this.getSubscribedChannels=P.getSubscribedChannels.bind(P),this.getSubscribedChannelGroups=P.getSubscribedChannelGroups.bind(P),this.eventEngine=P}else{var E=new M({timeEndpoint:y,leaveEndpoint:m,heartbeatEndpoint:v,setStateEndpoint:_,subscribeEndpoint:S,crypto:d.crypto,config:d.config,listenerManager:w,getFileUrl:function(e){return ve(d,e)},cryptoModule:d.cryptoModule,eventEmitter:this._eventEmitter});this.subscribe=E.adaptSubscribeChange.bind(E),this.unsubscribe=E.adaptUnsubscribeChange.bind(E),this.disconnect=E.disconnect.bind(E),this.reconnect=E.reconnect.bind(E),this.unsubscribeAll=E.unsubscribeAll.bind(E),this.getSubscribedChannels=E.getSubscribedChannels.bind(E),this.getSubscribedChannelGroups=E.getSubscribedChannelGroups.bind(E),this.setState=E.adaptStateChange.bind(E),this.presence=E.adaptPresenceChange.bind(E),this.destroy=function(e){E.unsubscribeAll(e),E.disconnect()}}this.addListener=this._eventEmitter.addListener.bind(this._eventEmitter),this.removeListener=this._eventEmitter.removeListener.bind(this._eventEmitter),this.removeAllListeners=this._eventEmitter.removeAllListeners.bind(this._eventEmitter),this.parseToken=p.parseToken.bind(p),this.setToken=p.setToken.bind(p),this.getToken=p.getToken.bind(p),this.channelGroups={listGroups:Q.bind(this,d,ee),listChannels:Q.bind(this,d,te),addChannels:Q.bind(this,d,X),removeChannels:Q.bind(this,d,Y),deleteGroup:Q.bind(this,d,Z)},this.push={addChannels:Q.bind(this,d,ne),removeChannels:Q.bind(this,d,re),deleteDevice:Q.bind(this,d,ie),listChannels:Q.bind(this,d,oe)},this.hereNow=Q.bind(this,d,pe),this.whereNow=Q.bind(this,d,ae),this.getState=Q.bind(this,d,ce),this.grant=Q.bind(this,d,Ue),this.grantToken=Q.bind(this,d,Le),this.audit=Q.bind(this,d,xe),this.revokeToken=Q.bind(this,d,Ge),this.publish=Q.bind(this,d,Be),this.fire=function(e,n){return e.replicate=!1,e.storeInHistory=!1,t.publish(e,n)},this.signal=Q.bind(this,d,He),this.history=Q.bind(this,d,qe),this.deleteMessages=Q.bind(this,d,ze),this.messageCounts=Q.bind(this,d,Ve),this.fetchMessages=Q.bind(this,d,We),this.addMessageAction=Q.bind(this,d,he),this.removeMessageAction=Q.bind(this,d,fe),this.getMessageActions=Q.bind(this,d,de),this.listFiles=Q.bind(this,d,ye);var A=Q.bind(this,d,ge);this.publishFile=Q.bind(this,d,me),this.sendFile=be({generateUploadUrl:A,publishFile:this.publishFile,modules:d}),this.getFileUrl=function(e){return ve(d,e)},this.downloadFile=Q.bind(this,d,_e),this.deleteFile=Q.bind(this,d,Se),this.channel=function(e){return new yn(e,t._eventEmitter,t)},this.channelGroup=function(e){return new gn(e,t._eventEmitter,t)},this.channelMetadata=function(e){return new mn(e,t._eventEmitter,t)},this.userMetadata=function(e){return new bn(e,t._eventEmitter,t)},this.subscriptionSet=function(e){return new fn({channels:e.channels,channelGroups:e.channelGroups,subscriptionOptions:e.subscriptionOptions,eventEmitter:t._eventEmitter,pubnub:t})},this.objects={getAllUUIDMetadata:Q.bind(this,d,we),getUUIDMetadata:Q.bind(this,d,Oe),setUUIDMetadata:Q.bind(this,d,Pe),removeUUIDMetadata:Q.bind(this,d,Ee),getAllChannelMetadata:Q.bind(this,d,Ae),getChannelMetadata:Q.bind(this,d,Te),setChannelMetadata:Q.bind(this,d,Ne),removeChannelMetadata:Q.bind(this,d,Ce),getChannelMembers:Q.bind(this,d,ke),setChannelMembers:function(e){for(var r=[],o=1;o=this._config.origin.length&&(this._currentSubDomain=0);var t=this._config.origin[this._currentSubDomain];return"".concat(e).concat(t)},e.prototype.hasModule=function(e){return e in this._modules},e.prototype.shiftStandardOrigin=function(){return this._standardOrigin=this.nextOrigin(),this._standardOrigin},e.prototype.getStandardOrigin=function(){return this._standardOrigin},e.prototype.POSTFILE=function(e,t,n){return this._modules.postfile(e,t,n)},e.prototype.GETFILE=function(e,t,n){return this._modules.getfile(e,t,n)},e.prototype.POST=function(e,t,n,r){return this._modules.post(e,t,n,r)},e.prototype.PATCH=function(e,t,n,r){return this._modules.patch(e,t,n,r)},e.prototype.GET=function(e,t,n){return this._modules.get(e,t,n)},e.prototype.DELETE=function(e,t,n){return this._modules.del(e,t,n)},e.prototype._detectErrorCategory=function(e){if("ENOTFOUND"===e.code)return k.PNNetworkIssuesCategory;if("ECONNREFUSED"===e.code)return k.PNNetworkIssuesCategory;if("ECONNRESET"===e.code)return k.PNNetworkIssuesCategory;if("EAI_AGAIN"===e.code)return k.PNNetworkIssuesCategory;if(0===e.status||e.hasOwnProperty("status")&&void 0===e.status)return k.PNNetworkIssuesCategory;if(e.timeout)return k.PNTimeoutCategory;if("ETIMEDOUT"===e.code)return k.PNNetworkIssuesCategory;if(e.response){if(e.response.badRequest)return k.PNBadRequestCategory;if(e.response.forbidden)return k.PNAccessDeniedCategory}return k.PNUnknownCategory},e}();function Sn(e){var t=function(e){return e&&"object"==typeof e&&e.constructor===Object};if(!t(e))return e;var n={};return Object.keys(e).forEach((function(r){var o=function(e){return"string"==typeof e||e instanceof String}(r),i=r,s=e[r];Array.isArray(r)||o&&r.indexOf(",")>=0?i=(o?r.split(","):r).reduce((function(e,t){return e+=String.fromCharCode(t)}),""):(function(e){return"number"==typeof e&&isFinite(e)}(r)||o&&!isNaN(r))&&(i=String.fromCharCode(o?parseInt(r,10):10));n[i]=t(s)?Sn(s):s})),n}var wn=function(){function e(e,t){this._base64ToBinary=t,this._decode=e}return e.prototype.decodeToken=function(e){var t="";e.length%4==3?t="=":e.length%4==2&&(t="==");var n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,r=this._decode(this._base64ToBinary(n));if("object"==typeof r)return r},e}(),On={exports:{}},Pn={exports:{}};!function(e){function t(e){if(e)return function(e){for(var n in t.prototype)e[n]=t.prototype[n];return e}(e)}e.exports=t,t.prototype.on=t.prototype.addEventListener=function(e,t){return this._callbacks=this._callbacks||{},(this._callbacks["$"+e]=this._callbacks["$"+e]||[]).push(t),this},t.prototype.once=function(e,t){function n(){this.off(e,n),t.apply(this,arguments)}return n.fn=t,this.on(e,n),this},t.prototype.off=t.prototype.removeListener=t.prototype.removeAllListeners=t.prototype.removeEventListener=function(e,t){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var n,r=this._callbacks["$"+e];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+e],this;for(var o=0;os.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;at?1:0}function Un(e,t,n,r){void 0===r&&(r=kn());var o,i=In(e,"",0,[],void 0,0,r)||e;try{o=0===Cn.length?JSON.stringify(i,t,n):JSON.stringify(i,Dn(t),n)}catch(e){return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]")}finally{for(;0!==Nn.length;){var s=Nn.pop();4===s.length?Object.defineProperty(s[0],s[1],s[3]):s[0][s[1]]=s[2]}}return o}function In(e,t,n,r,o,i,s){var a;if(i+=1,"object"==typeof e&&null!==e){for(a=0;as.depthLimit)return void jn(An,e,t,o);if(void 0!==s.edgesLimit&&n+1>s.edgesLimit)return void jn(An,e,t,o);if(r.push(e),Array.isArray(e))for(a=0;a0)for(var r=0;r1&&"boolean"!=typeof t)throw new Qn('"allowMissing" argument must be a boolean');var n=gr(e),r=n.length>0?n[0]:"",o=mr("%"+r+"%",t),i=o.name,s=o.value,a=!1,u=o.alias;u&&(r=u[0],pr(n,lr([0,1],u)));for(var c=1,l=!0;c=n.length){var d=Yn(s,p);s=(l=!!d)&&"get"in d&&!("originalValue"in d.get)?d.get:s[p]}else l=cr(s,p),s=s[p];l&&!a&&(ir[i]=s)}}return s},vr={exports:{}};!function(e){var t=Vn,n=br,r=n("%Function.prototype.apply%"),o=n("%Function.prototype.call%"),i=n("%Reflect.apply%",!0)||t.call(o,r),s=n("%Object.getOwnPropertyDescriptor%",!0),a=n("%Object.defineProperty%",!0),u=n("%Math.max%");if(a)try{a({},"a",{value:1})}catch(e){a=null}e.exports=function(e){var n=i(t,o,arguments);if(s&&a){var r=s(n,"length");r.configurable&&a(n,"length",{value:1+u(0,e.length-(arguments.length-1))})}return n};var c=function(){return i(t,r,arguments)};a?a(e.exports,"apply",{value:c}):e.exports.apply=c}(vr);var _r=br,Sr=vr.exports,wr=Sr(_r("String.prototype.indexOf")),Or=l(Object.freeze({__proto__:null,default:{}})),Pr="function"==typeof Map&&Map.prototype,Er=Object.getOwnPropertyDescriptor&&Pr?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ar=Pr&&Er&&"function"==typeof Er.get?Er.get:null,Tr=Pr&&Map.prototype.forEach,Nr="function"==typeof Set&&Set.prototype,Cr=Object.getOwnPropertyDescriptor&&Nr?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,kr=Nr&&Cr&&"function"==typeof Cr.get?Cr.get:null,Mr=Nr&&Set.prototype.forEach,jr="function"==typeof WeakMap&&WeakMap.prototype?WeakMap.prototype.has:null,Rr="function"==typeof WeakSet&&WeakSet.prototype?WeakSet.prototype.has:null,xr="function"==typeof WeakRef&&WeakRef.prototype?WeakRef.prototype.deref:null,Ur=Boolean.prototype.valueOf,Ir=Object.prototype.toString,Dr=Function.prototype.toString,Fr=String.prototype.match,Lr=String.prototype.slice,Gr=String.prototype.replace,Kr=String.prototype.toUpperCase,Br=String.prototype.toLowerCase,Hr=RegExp.prototype.test,qr=Array.prototype.concat,zr=Array.prototype.join,Vr=Array.prototype.slice,Wr=Math.floor,Jr="function"==typeof BigInt?BigInt.prototype.valueOf:null,$r=Object.getOwnPropertySymbols,Qr="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?Symbol.prototype.toString:null,Xr="function"==typeof Symbol&&"object"==typeof Symbol.iterator,Yr="function"==typeof Symbol&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Xr||"symbol")?Symbol.toStringTag:null,Zr=Object.prototype.propertyIsEnumerable,eo=("function"==typeof Reflect?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(e){return e.__proto__}:null);function to(e,t){if(e===1/0||e===-1/0||e!=e||e&&e>-1e3&&e<1e3||Hr.call(/e/,t))return t;var n=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if("number"==typeof e){var r=e<0?-Wr(-e):Wr(e);if(r!==e){var o=String(r),i=Lr.call(t,o.length+1);return Gr.call(o,n,"$&_")+"."+Gr.call(Gr.call(i,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Gr.call(t,n,"$&_")}var no=Or,ro=no.custom,oo=co(ro)?ro:null;function io(e,t,n){var r="double"===(n.quoteStyle||t)?'"':"'";return r+e+r}function so(e){return Gr.call(String(e),/"/g,""")}function ao(e){return!("[object Array]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function uo(e){return!("[object RegExp]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}function co(e){if(Xr)return e&&"object"==typeof e&&e instanceof Symbol;if("symbol"==typeof e)return!0;if(!e||"object"!=typeof e||!Qr)return!1;try{return Qr.call(e),!0}catch(e){}return!1}var lo=Object.prototype.hasOwnProperty||function(e){return e in this};function po(e,t){return lo.call(e,t)}function ho(e){return Ir.call(e)}function fo(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,r=e.length;nt.maxStringLength){var n=e.length-t.maxStringLength,r="... "+n+" more character"+(n>1?"s":"");return yo(Lr.call(e,0,t.maxStringLength),t)+r}return io(Gr.call(Gr.call(e,/(['\\])/g,"\\$1"),/[\x00-\x1f]/g,go),"single",t)}function go(e){var t=e.charCodeAt(0),n={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return n?"\\"+n:"\\x"+(t<16?"0":"")+Kr.call(t.toString(16))}function mo(e){return"Object("+e+")"}function bo(e){return e+" { ? }"}function vo(e,t,n,r){return e+" ("+t+") {"+(r?_o(n,r):zr.call(n,", "))+"}"}function _o(e,t){if(0===e.length)return"";var n="\n"+t.prev+t.base;return n+zr.call(e,","+n)+"\n"+t.prev}function So(e,t){var n=ao(e),r=[];if(n){r.length=e.length;for(var o=0;o-1?Sr(n):n},Po=function e(t,n,r,o){var i=n||{};if(po(i,"quoteStyle")&&"single"!==i.quoteStyle&&"double"!==i.quoteStyle)throw new TypeError('option "quoteStyle" must be "single" or "double"');if(po(i,"maxStringLength")&&("number"==typeof i.maxStringLength?i.maxStringLength<0&&i.maxStringLength!==1/0:null!==i.maxStringLength))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var s=!po(i,"customInspect")||i.customInspect;if("boolean"!=typeof s&&"symbol"!==s)throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(po(i,"indent")&&null!==i.indent&&"\t"!==i.indent&&!(parseInt(i.indent,10)===i.indent&&i.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(po(i,"numericSeparator")&&"boolean"!=typeof i.numericSeparator)throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=i.numericSeparator;if(void 0===t)return"undefined";if(null===t)return"null";if("boolean"==typeof t)return t?"true":"false";if("string"==typeof t)return yo(t,i);if("number"==typeof t){if(0===t)return 1/0/t>0?"0":"-0";var u=String(t);return a?to(t,u):u}if("bigint"==typeof t){var l=String(t)+"n";return a?to(t,l):l}var p=void 0===i.depth?5:i.depth;if(void 0===r&&(r=0),r>=p&&p>0&&"object"==typeof t)return ao(t)?"[Array]":"[Object]";var h=function(e,t){var n;if("\t"===e.indent)n="\t";else{if(!("number"==typeof e.indent&&e.indent>0))return null;n=zr.call(Array(e.indent+1)," ")}return{base:n,prev:zr.call(Array(t+1),n)}}(i,r);if(void 0===o)o=[];else if(fo(o,t)>=0)return"[Circular]";function f(t,n,s){if(n&&(o=Vr.call(o)).push(n),s){var a={depth:i.depth};return po(i,"quoteStyle")&&(a.quoteStyle=i.quoteStyle),e(t,a,r+1,o)}return e(t,i,r+1,o)}if("function"==typeof t&&!uo(t)){var d=function(e){if(e.name)return e.name;var t=Fr.call(Dr.call(e),/^function\s*([\w$]+)/);if(t)return t[1];return null}(t),y=So(t,f);return"[Function"+(d?": "+d:" (anonymous)")+"]"+(y.length>0?" { "+zr.call(y,", ")+" }":"")}if(co(t)){var g=Xr?Gr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qr.call(t);return"object"!=typeof t||Xr?g:mo(g)}if(function(e){if(!e||"object"!=typeof e)return!1;if("undefined"!=typeof HTMLElement&&e instanceof HTMLElement)return!0;return"string"==typeof e.nodeName&&"function"==typeof e.getAttribute}(t)){for(var m="<"+Br.call(String(t.nodeName)),b=t.attributes||[],v=0;v"}if(ao(t)){if(0===t.length)return"[]";var _=So(t,f);return h&&!function(e){for(var t=0;t=0)return!1;return!0}(_)?"["+_o(_,h)+"]":"[ "+zr.call(_,", ")+" ]"}if(function(e){return!("[object Error]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)){var S=So(t,f);return"cause"in Error.prototype||!("cause"in t)||Zr.call(t,"cause")?0===S.length?"["+String(t)+"]":"{ ["+String(t)+"] "+zr.call(S,", ")+" }":"{ ["+String(t)+"] "+zr.call(qr.call("[cause]: "+f(t.cause),S),", ")+" }"}if("object"==typeof t&&s){if(oo&&"function"==typeof t[oo]&&no)return no(t,{depth:p-r});if("symbol"!==s&&"function"==typeof t.inspect)return t.inspect()}if(function(e){if(!Ar||!e||"object"!=typeof e)return!1;try{Ar.call(e);try{kr.call(e)}catch(e){return!0}return e instanceof Map}catch(e){}return!1}(t)){var w=[];return Tr&&Tr.call(t,(function(e,n){w.push(f(n,t,!0)+" => "+f(e,t))})),vo("Map",Ar.call(t),w,h)}if(function(e){if(!kr||!e||"object"!=typeof e)return!1;try{kr.call(e);try{Ar.call(e)}catch(e){return!0}return e instanceof Set}catch(e){}return!1}(t)){var O=[];return Mr&&Mr.call(t,(function(e){O.push(f(e,t))})),vo("Set",kr.call(t),O,h)}if(function(e){if(!jr||!e||"object"!=typeof e)return!1;try{jr.call(e,jr);try{Rr.call(e,Rr)}catch(e){return!0}return e instanceof WeakMap}catch(e){}return!1}(t))return bo("WeakMap");if(function(e){if(!Rr||!e||"object"!=typeof e)return!1;try{Rr.call(e,Rr);try{jr.call(e,jr)}catch(e){return!0}return e instanceof WeakSet}catch(e){}return!1}(t))return bo("WeakSet");if(function(e){if(!xr||!e||"object"!=typeof e)return!1;try{return xr.call(e),!0}catch(e){}return!1}(t))return bo("WeakRef");if(function(e){return!("[object Number]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(Number(t)));if(function(e){if(!e||"object"!=typeof e||!Jr)return!1;try{return Jr.call(e),!0}catch(e){}return!1}(t))return mo(f(Jr.call(t)));if(function(e){return!("[object Boolean]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(Ur.call(t));if(function(e){return!("[object String]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t))return mo(f(String(t)));if("undefined"!=typeof window&&t===window)return"{ [object Window] }";if(t===c)return"{ [object globalThis] }";if(!function(e){return!("[object Date]"!==ho(e)||Yr&&"object"==typeof e&&Yr in e)}(t)&&!uo(t)){var P=So(t,f),E=eo?eo(t)===Object.prototype:t instanceof Object||t.constructor===Object,A=t instanceof Object?"":"null prototype",T=!E&&Yr&&Object(t)===t&&Yr in t?Lr.call(ho(t),8,-1):A?"Object":"",N=(E||"function"!=typeof t.constructor?"":t.constructor.name?t.constructor.name+" ":"")+(T||A?"["+zr.call(qr.call([],T||[],A||[]),": ")+"] ":"");return 0===P.length?N+"{}":h?N+"{"+_o(P,h)+"}":N+"{ "+zr.call(P,", ")+" }"}return String(t)},Eo=wo("%TypeError%"),Ao=wo("%WeakMap%",!0),To=wo("%Map%",!0),No=Oo("WeakMap.prototype.get",!0),Co=Oo("WeakMap.prototype.set",!0),ko=Oo("WeakMap.prototype.has",!0),Mo=Oo("Map.prototype.get",!0),jo=Oo("Map.prototype.set",!0),Ro=Oo("Map.prototype.has",!0),xo=function(e,t){for(var n,r=e;null!==(n=r.next);r=n)if(n.key===t)return r.next=n.next,n.next=e.next,e.next=n,n},Uo=String.prototype.replace,Io=/%20/g,Do="RFC3986",Fo={default:Do,formatters:{RFC1738:function(e){return Uo.call(e,Io,"+")},RFC3986:function(e){return String(e)}},RFC1738:"RFC1738",RFC3986:Do},Lo=Fo,Go=Object.prototype.hasOwnProperty,Ko=Array.isArray,Bo=function(){for(var e=[],t=0;t<256;++t)e.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return e}(),Ho=function(e,t){for(var n=t&&t.plainObjects?Object.create(null):{},r=0;r1;){var t=e.pop(),n=t.obj[t.prop];if(Ko(n)){for(var r=[],o=0;o=48&&u<=57||u>=65&&u<=90||u>=97&&u<=122||o===Lo.RFC1738&&(40===u||41===u)?s+=i.charAt(a):u<128?s+=Bo[u]:u<2048?s+=Bo[192|u>>6]+Bo[128|63&u]:u<55296||u>=57344?s+=Bo[224|u>>12]+Bo[128|u>>6&63]+Bo[128|63&u]:(a+=1,u=65536+((1023&u)<<10|1023&i.charCodeAt(a)),s+=Bo[240|u>>18]+Bo[128|u>>12&63]+Bo[128|u>>6&63]+Bo[128|63&u])}return s},isBuffer:function(e){return!(!e||"object"!=typeof e)&&!!(e.constructor&&e.constructor.isBuffer&&e.constructor.isBuffer(e))},isRegExp:function(e){return"[object RegExp]"===Object.prototype.toString.call(e)},maybeMap:function(e,t){if(Ko(e)){for(var n=[],r=0;r0?b.join(",")||null:void 0}];else if(Qo(u))O=u;else{var E=Object.keys(b);O=c?E.sort(c):E}for(var A=o&&Qo(b)&&1===b.length?n+"[]":n,T=0;T-1?e.split(","):e},li=function(e,t,n,r){if(e){var o=n.allowDots?e.replace(/\.([^.[]+)/g,"[$1]"):e,i=/(\[[^[\]]*])/g,s=n.depth>0&&/(\[[^[\]]*])/.exec(o),a=s?o.slice(0,s.index):o,u=[];if(a){if(!n.plainObjects&&ii.call(Object.prototype,a)&&!n.allowPrototypes)return;u.push(a)}for(var c=0;n.depth>0&&null!==(s=i.exec(o))&&c=0;--i){var s,a=e[i];if("[]"===a&&n.parseArrays)s=[].concat(o);else{s=n.plainObjects?Object.create(null):{};var u="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(u,10);n.parseArrays||""!==u?!isNaN(c)&&a!==u&&String(c)===u&&c>=0&&n.parseArrays&&c<=n.arrayLimit?(s=[])[c]=o:"__proto__"!==u&&(s[u]=o):s={0:o}}o=s}return o}(u,t,n,r)}},pi=function(e,t){var n,r=e,o=function(e){if(!e)return ti;if(null!==e.encoder&&void 0!==e.encoder&&"function"!=typeof e.encoder)throw new TypeError("Encoder has to be a function.");var t=e.charset||ti.charset;if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var n=Wo.default;if(void 0!==e.format){if(!Jo.call(Wo.formatters,e.format))throw new TypeError("Unknown format option provided.");n=e.format}var r=Wo.formatters[n],o=ti.filter;return("function"==typeof e.filter||Qo(e.filter))&&(o=e.filter),{addQueryPrefix:"boolean"==typeof e.addQueryPrefix?e.addQueryPrefix:ti.addQueryPrefix,allowDots:void 0===e.allowDots?ti.allowDots:!!e.allowDots,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ti.charsetSentinel,delimiter:void 0===e.delimiter?ti.delimiter:e.delimiter,encode:"boolean"==typeof e.encode?e.encode:ti.encode,encoder:"function"==typeof e.encoder?e.encoder:ti.encoder,encodeValuesOnly:"boolean"==typeof e.encodeValuesOnly?e.encodeValuesOnly:ti.encodeValuesOnly,filter:o,format:n,formatter:r,serializeDate:"function"==typeof e.serializeDate?e.serializeDate:ti.serializeDate,skipNulls:"boolean"==typeof e.skipNulls?e.skipNulls:ti.skipNulls,sort:"function"==typeof e.sort?e.sort:null,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ti.strictNullHandling}}(t);"function"==typeof o.filter?r=(0,o.filter)("",r):Qo(o.filter)&&(n=o.filter);var i,s=[];if("object"!=typeof r||null===r)return"";i=t&&t.arrayFormat in $o?t.arrayFormat:t&&"indices"in t?t.indices?"indices":"repeat":"indices";var a=$o[i];if(t&&"commaRoundTrip"in t&&"boolean"!=typeof t.commaRoundTrip)throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var u="comma"===a&&t&&t.commaRoundTrip;n||(n=Object.keys(r)),o.sort&&n.sort(o.sort);for(var c=zo(),l=0;l0?f+h:""},hi={formats:Fo,parse:function(e,t){var n=function(e){if(!e)return ai;if(null!==e.decoder&&void 0!==e.decoder&&"function"!=typeof e.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==e.charset&&"utf-8"!==e.charset&&"iso-8859-1"!==e.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var t=void 0===e.charset?ai.charset:e.charset;return{allowDots:void 0===e.allowDots?ai.allowDots:!!e.allowDots,allowPrototypes:"boolean"==typeof e.allowPrototypes?e.allowPrototypes:ai.allowPrototypes,allowSparse:"boolean"==typeof e.allowSparse?e.allowSparse:ai.allowSparse,arrayLimit:"number"==typeof e.arrayLimit?e.arrayLimit:ai.arrayLimit,charset:t,charsetSentinel:"boolean"==typeof e.charsetSentinel?e.charsetSentinel:ai.charsetSentinel,comma:"boolean"==typeof e.comma?e.comma:ai.comma,decoder:"function"==typeof e.decoder?e.decoder:ai.decoder,delimiter:"string"==typeof e.delimiter||oi.isRegExp(e.delimiter)?e.delimiter:ai.delimiter,depth:"number"==typeof e.depth||!1===e.depth?+e.depth:ai.depth,ignoreQueryPrefix:!0===e.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof e.interpretNumericEntities?e.interpretNumericEntities:ai.interpretNumericEntities,parameterLimit:"number"==typeof e.parameterLimit?e.parameterLimit:ai.parameterLimit,parseArrays:!1!==e.parseArrays,plainObjects:"boolean"==typeof e.plainObjects?e.plainObjects:ai.plainObjects,strictNullHandling:"boolean"==typeof e.strictNullHandling?e.strictNullHandling:ai.strictNullHandling}}(t);if(""===e||null==e)return n.plainObjects?Object.create(null):{};for(var r="string"==typeof e?function(e,t){var n,r={__proto__:null},o=t.ignoreQueryPrefix?e.replace(/^\?/,""):e,i=t.parameterLimit===1/0?void 0:t.parameterLimit,s=o.split(t.delimiter,i),a=-1,u=t.charset;if(t.charsetSentinel)for(n=0;n-1&&(l=si(l)?[l]:l),ii.call(r,c)?r[c]=oi.combine(r[c],l):r[c]=l}return r}(e,n):e,o=n.plainObjects?Object.create(null):{},i=Object.keys(r),s=0;s=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);ne.split(/ *; */).shift(),e.params=e=>{const n={};var r,o=t(e.split(/ *; */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *= */),t=e.shift(),o=e.shift();t&&o&&(n[t]=o)}}catch(e){o.e(e)}finally{o.f()}return n},e.parseLinks=e=>{const n={};var r,o=t(e.split(/ *, */));try{for(o.s();!(r=o.n()).done;){const e=r.value.split(/ *; */),t=e[0].slice(1,-1);n[e[1].split(/ *= */)[1].slice(1,-1)]=t}}catch(e){o.e(e)}finally{o.f()}return n},e.cleanHeader=(e,t)=>(delete e["content-type"],delete e["content-length"],delete e["transfer-encoding"],delete e.host,t&&(delete e.authorization,delete e.cookie),e),e.isObject=e=>null!==e&&"object"==typeof e,e.hasOwn=Object.hasOwn||function(e,t){if(null==e)throw new TypeError("Cannot convert undefined or null to object");return Object.prototype.hasOwnProperty.call(new Object(e),t)},e.mixin=(t,n)=>{for(const r in n)e.hasOwn(n,r)&&(t[r]=n[r])}}(fi);const di=Or,yi=fi.isObject,gi=fi.hasOwn;var mi=bi;function bi(){}bi.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},bi.prototype.parse=function(e){return this._parser=e,this},bi.prototype.responseType=function(e){return this._responseType=e,this},bi.prototype.serialize=function(e){return this._serializer=e,this},bi.prototype.timeout=function(e){if(!e||"object"!=typeof e)return this._timeout=e,this._responseTimeout=0,this._uploadTimeout=0,this;for(const t in e)if(gi(e,t))switch(t){case"deadline":this._timeout=e.deadline;break;case"response":this._responseTimeout=e.response;break;case"upload":this._uploadTimeout=e.upload;break;default:console.warn("Unknown timeout option",t)}return this},bi.prototype.retry=function(e,t){return 0!==arguments.length&&!0!==e||(e=1),e<=0&&(e=0),this._maxRetries=e,this._retries=0,this._retryCallback=t,this};const vi=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),_i=new Set([408,413,429,500,502,503,504,521,522,524]);bi.prototype._shouldRetry=function(e,t){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{const n=this._retryCallback(e,t);if(!0===n)return!0;if(!1===n)return!1}catch(e){console.error(e)}if(t&&t.status&&_i.has(t.status))return!0;if(e){if(e.code&&vi.has(e.code))return!0;if(e.timeout&&"ECONNABORTED"===e.code)return!0;if(e.crossDomain)return!0}return!1},bi.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},bi.prototype.then=function(e,t){if(!this._fullfilledPromise){const e=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(((t,n)=>{e.on("abort",(()=>{if(this._maxRetries&&this._maxRetries>this._retries)return;if(this.timedout&&this.timedoutError)return void n(this.timedoutError);const e=new Error("Aborted");e.code="ABORTED",e.status=this.status,e.method=this.method,e.url=this.url,n(e)})),e.end(((e,r)=>{e?n(e):t(r)}))}))}return this._fullfilledPromise.then(e,t)},bi.prototype.catch=function(e){return this.then(void 0,e)},bi.prototype.use=function(e){return e(this),this},bi.prototype.ok=function(e){if("function"!=typeof e)throw new Error("Callback required");return this._okCallback=e,this},bi.prototype._isResponseOK=function(e){return!!e&&(this._okCallback?this._okCallback(e):e.status>=200&&e.status<300)},bi.prototype.get=function(e){return this._header[e.toLowerCase()]},bi.prototype.getHeader=bi.prototype.get,bi.prototype.set=function(e,t){if(yi(e)){for(const t in e)gi(e,t)&&this.set(t,e[t]);return this}return this._header[e.toLowerCase()]=t,this.header[e]=t,this},bi.prototype.unset=function(e){return delete this._header[e.toLowerCase()],delete this.header[e],this},bi.prototype.field=function(e,t,n){if(null==e)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(yi(e)){for(const t in e)gi(e,t)&&this.field(t,e[t]);return this}if(Array.isArray(t)){for(const n in t)gi(t,n)&&this.field(e,t[n]);return this}if(null==t)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof t&&(t=String(t)),n?this._getFormData().append(e,t,n):this._getFormData().append(e,t),this},bi.prototype.abort=function(){if(this._aborted)return this;if(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req){if(di.gte(process.version,"v13.0.0")&&di.lt(process.version,"v14.0.0"))throw new Error("Superagent does not work in v13 properly with abort() due to Node.js core changes");this.req.abort()}return this.clearTimeout(),this.emit("abort"),this},bi.prototype._auth=function(e,t,n,r){switch(n.type){case"basic":this.set("Authorization",`Basic ${r(`${e}:${t}`)}`);break;case"auto":this.username=e,this.password=t;break;case"bearer":this.set("Authorization",`Bearer ${e}`)}return this},bi.prototype.withCredentials=function(e){return void 0===e&&(e=!0),this._withCredentials=e,this},bi.prototype.redirects=function(e){return this._maxRedirects=e,this},bi.prototype.maxResponseSize=function(e){if("number"!=typeof e)throw new TypeError("Invalid argument");return this._maxResponseSize=e,this},bi.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},bi.prototype.send=function(e){const t=yi(e);let n=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(t&&!this._data)Array.isArray(e)?this._data=[]:this._isHost(e)||(this._data={});else if(e&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(t&&yi(this._data))for(const t in e){if("bigint"==typeof e[t]&&!e[t].toJSON)throw new Error("Cannot serialize BigInt value to json");gi(e,t)&&(this._data[t]=e[t])}else{if("bigint"==typeof e)throw new Error("Cannot send value of type BigInt");"string"==typeof e?(n||this.type("form"),n=this._header["content-type"],n&&(n=n.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===n?this._data?`${this._data}&${e}`:e:(this._data||"")+e):this._data=e}return!t||this._isHost(e)||n||this.type("json"),this},bi.prototype.sortQuery=function(e){return this._sort=void 0===e||e,this},bi.prototype._finalizeQueryString=function(){const e=this._query.join("&");if(e&&(this.url+=(this.url.includes("?")?"&":"?")+e),this._query.length=0,this._sort){const e=this.url.indexOf("?");if(e>=0){const t=this.url.slice(e+1).split("&");"function"==typeof this._sort?t.sort(this._sort):t.sort(),this.url=this.url.slice(0,e)+"?"+t.join("&")}}},bi.prototype._appendQueryString=()=>{console.warn("Unsupported")},bi.prototype._timeoutError=function(e,t,n){if(this._aborted)return;const r=new Error(`${e+t}ms exceeded`);r.timeout=t,r.code="ECONNABORTED",r.errno=n,this.timedout=!0,this.timedoutError=r,this.abort(),this.callback(r)},bi.prototype._setTimeouts=function(){const e=this;this._timeout&&!this._timer&&(this._timer=setTimeout((()=>{e._timeoutError("Timeout of ",e._timeout,"ETIME")}),this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout((()=>{e._timeoutError("Response timeout of ",e._responseTimeout,"ETIMEDOUT")}),this._responseTimeout))};const Si=fi;var wi=Oi;function Oi(){}function Pi(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!n){if(Array.isArray(e)||(n=function(e,t){if(!e)return;if("string"==typeof e)return Ei(e,t);var n=Object.prototype.toString.call(e).slice(8,-1);"Object"===n&&e.constructor&&(n=e.constructor.name);if("Map"===n||"Set"===n)return Array.from(e);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return Ei(e,t)}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0,o=function(){};return{s:o,n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return s=e.done,e},e:function(e){a=!0,i=e},f:function(){try{s||null==n.return||n.return()}finally{if(a)throw i}}}}function Ei(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n=e.length?{done:!0}:{done:!1,value:e[o++]}},e:function(e){throw e},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){n=n.call(e)},n:function(){var e=n.next();return a=e.done,e},e:function(e){u=!0,s=e},f:function(){try{a||null==n.return||n.return()}finally{if(u)throw s}}}}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n{if(o.XMLHttpRequest)return new o.XMLHttpRequest;throw new Error("Browser-only version of superagent could not find XHR")};const g="".trim?e=>e.trim():e=>e.replace(/(^\s*|\s*$)/g,"");function m(e){if(!c(e))return e;const t=[];for(const n in e)p(e,n)&&b(t,n,e[n]);return t.join("&")}function b(e,t,r){if(void 0!==r)if(null!==r)if(Array.isArray(r)){var o,i=n(r);try{for(i.s();!(o=i.n()).done;){b(e,t,o.value)}}catch(e){i.e(e)}finally{i.f()}}else if(c(r))for(const n in r)p(r,n)&&b(e,`${t}[${n}]`,r[n]);else e.push(encodeURI(t)+"="+encodeURIComponent(r));else e.push(encodeURI(t))}function v(e){const t={},n=e.split("&");let r,o;for(let e=0,i=n.length;e{let e,t=null,r=null;try{r=new S(n)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,n.xhr?(t.rawResponse=void 0===n.xhr.responseType?n.xhr.responseText:n.xhr.response,t.status=n.xhr.status?n.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),n.callback(t)}n.emit("response",r);try{n._isResponseOK(r)||(e=new Error(r.statusText||r.text||"Unsuccessful HTTP response"))}catch(t){e=t}e?(e.original=t,e.response=r,e.status=e.status||r.status,n.callback(e,r)):n.callback(null,r)}))}y.serializeObject=m,y.parseString=v,y.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},y.serialize={"application/x-www-form-urlencoded":a.stringify,"application/json":s},y.parse={"application/x-www-form-urlencoded":v,"application/json":JSON.parse},l(S.prototype,h.prototype),S.prototype._parseBody=function(e){let t=y.parse[this.type];return this.req._parser?this.req._parser(this,e):(!t&&_(this.type)&&(t=y.parse["application/json"]),t&&e&&(e.length>0||e instanceof Object)?t(e):null)},S.prototype.toError=function(){const e=this.req,t=e.method,n=e.url,r=`cannot ${t} ${n} (${this.status})`,o=new Error(r);return o.status=this.status,o.method=t,o.url=n,o},y.Response=S,i(w.prototype),l(w.prototype,u.prototype),w.prototype.type=function(e){return this.set("Content-Type",y.types[e]||e),this},w.prototype.accept=function(e){return this.set("Accept",y.types[e]||e),this},w.prototype.auth=function(e,t,n){1===arguments.length&&(t=""),"object"==typeof t&&null!==t&&(n=t,t=""),n||(n={type:"function"==typeof btoa?"basic":"auto"});const r=n.encoder?n.encoder:e=>{if("function"==typeof btoa)return btoa(e);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(e,t,n,r)},w.prototype.query=function(e){return"string"!=typeof e&&(e=m(e)),e&&this._query.push(e),this},w.prototype.attach=function(e,t,n){if(t){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(e,t,n||t.name)}return this},w.prototype._getFormData=function(){return this._formData||(this._formData=new o.FormData),this._formData},w.prototype.callback=function(e,t){if(this._shouldRetry(e,t))return this._retry();const n=this._callback;this.clearTimeout(),e&&(this._maxRetries&&(e.retries=this._retries-1),this.emit("error",e)),n(e,t)},w.prototype.crossDomainError=function(){const e=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");e.crossDomain=!0,e.status=this.status,e.method=this.method,e.url=this.url,this.callback(e)},w.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},w.prototype.ca=w.prototype.agent,w.prototype.buffer=w.prototype.ca,w.prototype.write=()=>{throw new Error("Streaming is not supported in browser version of superagent")},w.prototype.pipe=w.prototype.write,w.prototype._isHost=function(e){return e&&"object"==typeof e&&!Array.isArray(e)&&"[object Object]"!==Object.prototype.toString.call(e)},w.prototype.end=function(e){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=e||d,this._finalizeQueryString(),this._end()},w.prototype._setUploadTimeout=function(){const e=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout((()=>{e._timeoutError("Upload timeout of ",e._uploadTimeout,"ETIMEDOUT")}),this._uploadTimeout))},w.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));const e=this;this.xhr=y.getXHR();const t=this.xhr;let n=this._formData||this._data;this._setTimeouts(),t.addEventListener("readystatechange",(()=>{const n=t.readyState;if(n>=2&&e._responseTimeoutTimer&&clearTimeout(e._responseTimeoutTimer),4!==n)return;let r;try{r=t.status}catch(e){r=0}if(!r){if(e.timedout||e._aborted)return;return e.crossDomainError()}e.emit("end")}));const r=(t,n)=>{n.total>0&&(n.percent=n.loaded/n.total*100,100===n.percent&&clearTimeout(e._uploadTimeoutTimer)),n.direction=t,e.emit("progress",n)};if(this.hasListeners("progress"))try{t.addEventListener("progress",r.bind(null,"download")),t.upload&&t.upload.addEventListener("progress",r.bind(null,"upload"))}catch(e){}t.upload&&this._setUploadTimeout();try{this.username&&this.password?t.open(this.method,this.url,!0,this.username,this.password):t.open(this.method,this.url,!0)}catch(e){return this.callback(e)}if(this._withCredentials&&(t.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof n&&!this._isHost(n)){const e=this._header["content-type"];let t=this._serializer||y.serialize[e?e.split(";")[0]:""];!t&&_(e)&&(t=y.serialize["application/json"]),t&&(n=t(n))}for(const e in this.header)null!==this.header[e]&&p(this.header,e)&&t.setRequestHeader(e,this.header[e]);this._responseType&&(t.responseType=this._responseType),this.emit("request",this),t.send(void 0===n?null:n)},y.agent=()=>new f;for(var O=0,P=["GET","POST","OPTIONS","PATCH","PUT","DELETE"];O{const r=y("GET",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.head=(e,t,n)=>{const r=y("HEAD",e);return"function"==typeof t&&(n=t,t=null),t&&r.query(t),n&&r.end(n),r},y.options=(e,t,n)=>{const r=y("OPTIONS",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.del=E,y.delete=E,y.patch=(e,t,n)=>{const r=y("PATCH",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.post=(e,t,n)=>{const r=y("POST",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r},y.put=(e,t,n)=>{const r=y("PUT",e);return"function"==typeof t&&(n=t,t=null),t&&r.send(t),n&&r.end(n),r}}(On,On.exports);var ki=On.exports;function Mi(e){var t=(new Date).getTime(),n=(new Date).toISOString(),r=console&&console.log?console:window&&window.console&&window.console.log?window.console:console;r.log("<<<<<"),r.log("[".concat(n,"]"),"\n",e.url,"\n",e.qs),r.log("-----"),e.on("response",(function(n){var o=(new Date).getTime()-t,i=(new Date).toISOString();r.log(">>>>>>"),r.log("[".concat(i," / ").concat(o,"]"),"\n",e.url,"\n",e.qs,"\n",n.text),r.log("-----")}))}function ji(e,t,n){var r=this;this._config.logVerbosity&&(e=e.use(Mi)),this._config.proxy&&this._modules.proxy&&(e=this._modules.proxy.call(this,e)),this._config.keepAlive&&this._modules.keepAlive&&(e=this._modules.keepAlive(e));var o=e;if(t.abortSignal)var i=t.abortSignal.subscribe((function(){o.abort(),i()}));return!0===t.forceBuffered?o="undefined"==typeof Blob?o.buffer().responseType("arraybuffer"):o.responseType("arraybuffer"):!1===t.forceBuffered&&(o=o.buffer(!1)),(o=o.timeout(t.timeout)).on("abort",(function(){return n({category:k.PNUnknownCategory,error:!0,operation:t.operation,errorData:new Error("Aborted")},null)})),o.end((function(e,o){var i,s={};if(s.error=null!==e,s.operation=t.operation,o&&o.status&&(s.statusCode=o.status),e){if(e.response&&e.response.text&&!r._config.logVerbosity)try{s.errorData=JSON.parse(e.response.text)}catch(t){s.errorData=e}else s.errorData=e;return s.category=r._detectErrorCategory(e),n(s,null)}if(t.ignoreBody)i={headers:o.headers,redirects:o.redirects,response:o};else try{i=JSON.parse(o.text)}catch(e){return s.errorData=o,s.error=!0,n(s,null)}return i.error&&1===i.error&&i.status&&i.message&&i.service?(s.errorData=i,s.statusCode=i.status,s.error=!0,s.category=r._detectErrorCategory(s),n(s,null)):(i.error&&i.error.message&&(s.errorData=i.error),n(s,i))})),o}function Ri(e,t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:return r=ki.post(e),t.forEach((function(e){var t=e.key,n=e.value;r=r.field(t,n)})),r.attach("file",n,{contentType:"application/octet-stream"}),[4,r];case 1:return[2,o.sent()]}}))}))}function xi(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ui(e,t,n){var r=ki.get(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Ii(e,t,n,r){var o=ki.post(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Di(e,t,n,r){var o=ki.patch(this.getStandardOrigin()+n.url).query(e).set(n.headers).send(t);return ji.call(this,o,n,r)}function Fi(e,t,n){var r=ki.delete(this.getStandardOrigin()+t.url).set(t.headers).query(e);return ji.call(this,r,t,n)}function Li(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}var Gi,Ki=function(){function e(){}return Object.defineProperty(e.prototype,"algo",{get:function(){return"aes-256-cbc"},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.encryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.encryptString(n,t)];throw new Error("Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer")}}))}))},e.prototype.decrypt=function(e,t){return o(this,void 0,void 0,(function(){var n;return i(this,(function(r){switch(r.label){case 0:return[4,this.getKey(e)];case 1:if(n=r.sent(),t instanceof ArrayBuffer)return[2,this.decryptArrayBuffer(n,t)];if("string"==typeof t)return[2,this.decryptString(n,t)];throw new Error("Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer")}}))}))},e.prototype.encryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:if(t.data.byteLength<=0)throw new Error("encryption error. empty content");return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.encryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,mimeType:"application/octet-stream",data:s})]}}))}))},e.prototype.decryptFile=function(e,t,n){return o(this,void 0,void 0,(function(){var r,o,s;return i(this,(function(i){switch(i.label){case 0:return[4,this.getKey(e)];case 1:return r=i.sent(),[4,t.data.arrayBuffer()];case 2:return o=i.sent(),[4,this.decryptArrayBuffer(r,o)];case 3:return s=i.sent(),[2,n.create({name:t.name,data:s})]}}))}))},e.prototype.getKey=function(t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return[4,crypto.subtle.digest("SHA-256",e.encoder.encode(t))];case 1:return n=i.sent(),r=Array.from(new Uint8Array(n)).map((function(e){return e.toString(16).padStart(2,"0")})).join(""),o=e.encoder.encode(r.slice(0,32)).buffer,[2,crypto.subtle.importKey("raw",o,"AES-CBC",!0,["encrypt","decrypt"])]}}))}))},e.prototype.encryptArrayBuffer=function(e,t){return o(this,void 0,void 0,(function(){var n,r,o;return i(this,(function(i){switch(i.label){case 0:return n=crypto.getRandomValues(new Uint8Array(16)),r=Li,o=[n.buffer],[4,crypto.subtle.encrypt({name:"AES-CBC",iv:n},e,t)];case 1:return[2,r.apply(void 0,o.concat([i.sent()]))]}}))}))},e.prototype.decryptArrayBuffer=function(t,n){return o(this,void 0,void 0,(function(){var r;return i(this,(function(o){switch(o.label){case 0:if(r=n.slice(0,16),n.slice(e.IV_LENGTH).byteLength<=0)throw new Error("decryption error: empty content");return[4,crypto.subtle.decrypt({name:"AES-CBC",iv:r},t,n.slice(e.IV_LENGTH))];case 1:return[2,o.sent()]}}))}))},e.prototype.encryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=crypto.getRandomValues(new Uint8Array(16)),o=e.encoder.encode(n).buffer,[4,crypto.subtle.encrypt({name:"AES-CBC",iv:r},t,o)];case 1:return s=i.sent(),a=Li(r.buffer,s),[2,e.decoder.decode(a)]}}))}))},e.prototype.decryptString=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a;return i(this,(function(i){switch(i.label){case 0:return r=e.encoder.encode(n).buffer,o=r.slice(0,16),s=r.slice(16),[4,crypto.subtle.decrypt({name:"AES-CBC",iv:o},t,s)];case 1:return a=i.sent(),[2,e.decoder.decode(a)]}}))}))},e.IV_LENGTH=16,e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Bi=(Gi=function(){function e(e){if(e instanceof File)this.data=e,this.name=this.data.name,this.mimeType=this.data.type;else if(e.data){var t=e.data;this.data=new File([t],e.name,{type:e.mimeType}),this.name=e.name,e.mimeType&&(this.mimeType=e.mimeType)}if(void 0===this.data)throw new Error("Couldn't construct a file out of supplied options.");if(void 0===this.name)throw new Error("Couldn't guess filename out of the options. Please provide one.")}return e.create=function(e){return new this(e)},e.prototype.toBuffer=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toStream=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in Node.js environments.")}))}))},e.prototype.toFileUri=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){throw new Error("This feature is only supported in react native environments.")}))}))},e.prototype.toBlob=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e.prototype.toArrayBuffer=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if(r.result instanceof ArrayBuffer)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsArrayBuffer(e.data)}))]}))}))},e.prototype.toString=function(){return o(this,void 0,void 0,(function(){var e=this;return i(this,(function(t){return[2,new Promise((function(t,n){var r=new FileReader;r.addEventListener("load",(function(){if("string"==typeof r.result)return t(r.result)})),r.addEventListener("error",(function(){n(r.error)})),r.readAsBinaryString(e.data)}))]}))}))},e.prototype.toFile=function(){return o(this,void 0,void 0,(function(){return i(this,(function(e){return[2,this.data]}))}))},e}(),Gi.supportsFile="undefined"!=typeof File,Gi.supportsBlob="undefined"!=typeof Blob,Gi.supportsArrayBuffer="undefined"!=typeof ArrayBuffer,Gi.supportsBuffer=!1,Gi.supportsStream=!1,Gi.supportsString=!0,Gi.supportsEncryptFile=!0,Gi.supportsFileUri=!1,Gi),Hi=function(){function e(e){this.config=e,this.cryptor=new T({config:e}),this.fileCryptor=new Ki}return Object.defineProperty(e.prototype,"identifier",{get:function(){return""},enumerable:!1,configurable:!0}),e.prototype.encrypt=function(e){var t="string"==typeof e?e:(new TextDecoder).decode(e);return{data:this.cryptor.encrypt(t),metadata:null}},e.prototype.decrypt=function(e){var t="string"==typeof e.data?e.data:b(e.data);return this.cryptor.decrypt(t)},e.prototype.encryptFile=function(e,t){var n;return o(this,void 0,void 0,(function(){return i(this,(function(r){return[2,this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)]}))}))},e.prototype.decryptFile=function(e,t){return o(this,void 0,void 0,(function(){return i(this,(function(n){return[2,this.fileCryptor.decryptFile(this.config.cipherKey,e,t)]}))}))},e}(),qi=function(){function e(e){this.cipherKey=e.cipherKey,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(this.cipherKey)}return Object.defineProperty(e.prototype,"algo",{get:function(){return"AES-CBC"},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"identifier",{get:function(){return"ACRH"},enumerable:!1,configurable:!0}),e.prototype.getIv=function(){return crypto.getRandomValues(new Uint8Array(e.BLOCK_SIZE))},e.prototype.getKey=function(){return o(this,void 0,void 0,(function(){var t,n;return i(this,(function(r){switch(r.label){case 0:return t=e.encoder.encode(this.cipherKey),[4,crypto.subtle.digest("SHA-256",t.buffer)];case 1:return n=r.sent(),[2,crypto.subtle.importKey("raw",n,this.algo,!0,["encrypt","decrypt"])]}}))}))},e.prototype.encrypt=function(t){if(0===("string"==typeof t?t:e.decoder.decode(t)).length)throw new Error("encryption error. empty content");var n=this.getIv();return{metadata:n,data:m(this.CryptoJS.AES.encrypt(t,this.encryptedKey,{iv:this.bufferToWordArray(n),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}},e.prototype.decrypt=function(t){var n=this.bufferToWordArray(new Uint8ClampedArray(t.metadata)),r=this.bufferToWordArray(new Uint8ClampedArray(t.data));return e.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:r},this.encryptedKey,{iv:n,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer},e.prototype.encryptFileData=function(e){return o(this,void 0,void 0,(function(){var t,n,r;return i(this,(function(o){switch(o.label){case 0:return[4,this.getKey()];case 1:return t=o.sent(),n=this.getIv(),r={},[4,crypto.subtle.encrypt({name:this.algo,iv:n},t,e)];case 2:return[2,(r.data=o.sent(),r.metadata=n,r)]}}))}))},e.prototype.decryptFileData=function(e){return o(this,void 0,void 0,(function(){var t;return i(this,(function(n){switch(n.label){case 0:return[4,this.getKey()];case 1:return t=n.sent(),[2,crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)]}}))}))},e.prototype.bufferToWordArray=function(e){var t,n=[];for(t=0;t0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("decryption error. empty content");return r.decrypt({data:t.slice(n.length),metadata:o})},e.prototype.encryptFile=function(e,t){return o(this,void 0,void 0,(function(){var n,r;return i(this,(function(o){switch(o.label){case 0:return this.defaultCryptor.identifier===Vi.LEGACY_IDENTIFIER?[2,this.defaultCryptor.encryptFile(e,t)]:[4,this.getFileData(e.data)];case 1:return n=o.sent(),[4,this.defaultCryptor.encryptFileData(n)];case 2:return r=o.sent(),[2,t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(r),r.data)})]}}))}))},e.prototype.decryptFile=function(t,n){return o(this,void 0,void 0,(function(){var r,o,s,a,u,c,l,p;return i(this,(function(i){switch(i.label){case 0:return[4,t.data.arrayBuffer()];case 1:return r=i.sent(),o=Vi.tryParse(r),(null==(s=this.getCryptor(o))?void 0:s.identifier)===e.LEGACY_IDENTIFIER?[2,s.decryptFile(t,n)]:[4,this.getFileData(r)];case 2:return a=i.sent(),u=a.slice(o.length-o.metadataLength,o.length),l=(c=n).create,p={name:t.name},[4,this.defaultCryptor.decryptFileData({data:r.slice(o.length),metadata:u})];case 3:return[2,l.apply(c,[(p.data=i.sent(),p)])]}}))}))},e.prototype.getCryptor=function(e){if(""===e){var t=this.getAllCryptors().find((function(e){return""===e.identifier}));if(t)return t;throw new Error("unknown cryptor error")}if(e instanceof Wi)return this.getCryptorFromId(e.identifier)},e.prototype.getCryptorFromId=function(e){var t=this.getAllCryptors().find((function(t){return e===t.identifier}));if(t)return t;throw Error("unknown cryptor error")},e.prototype.concatArrayBuffer=function(e,t){var n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer},e.prototype.getHeaderData=function(e){if(e.metadata){var t=Vi.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length),r=0;return n.set(t.data,r),r+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),r),n.buffer}},e.prototype.getFileData=function(t){return o(this,void 0,void 0,(function(){return i(this,(function(n){switch(n.label){case 0:return t instanceof Blob?[4,t.arrayBuffer()]:[3,2];case 1:return[2,n.sent()];case 2:if(t instanceof ArrayBuffer)return[2,t];if("string"==typeof t)return[2,e.encoder.encode(t)];throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}}))}))},e.LEGACY_IDENTIFIER="",e.encoder=new TextEncoder,e.decoder=new TextDecoder,e}(),Vi=function(){function e(){}return e.from=function(t,n){if(t!==e.LEGACY_IDENTIFIER)return new Wi(t,n.byteLength)},e.tryParse=function(t){var n=new Uint8Array(t),r="";if(n.byteLength>=4&&(r=n.slice(0,4),this.decoder.decode(r)!==e.SENTINEL))return"";if(!(n.byteLength>=5))throw new Error("decryption error. invalid header version");if(n[4]>e.MAX_VERSION)throw new Error("unknown cryptor error");var o="",i=5+e.IDENTIFIER_LENGTH;if(!(n.byteLength>=i))throw new Error("decryption error. invalid crypto identifier");o=n.slice(5,i);var s=null;if(!(n.byteLength>=i+1))throw new Error("decryption error. invalid metadata length");return s=n[i],i+=1,255===s&&n.byteLength>=i+2&&(s=new Uint16Array(n.slice(i,i+2)).reduce((function(e,t){return(e<<8)+t}),0),i+=2),new Wi(this.decoder.decode(o),s)},e.SENTINEL="PNED",e.LEGACY_IDENTIFIER="",e.IDENTIFIER_LENGTH=4,e.VERSION=1,e.MAX_VERSION=1,e.decoder=new TextDecoder,e}(),Wi=function(){function e(e,t){this._identifier=e,this._metadataLength=t}return Object.defineProperty(e.prototype,"identifier",{get:function(){return this._identifier},set:function(e){this._identifier=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"metadataLength",{get:function(){return this._metadataLength},set:function(e){this._metadataLength=e},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"version",{get:function(){return Vi.VERSION},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return Vi.SENTINEL.length+1+Vi.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){var e=0,t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(Vi.SENTINEL)),t[e+=Vi.SENTINEL.length]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e),e+=Vi.IDENTIFIER_LENGTH;var r=this.metadataLength;return r<255?t[e]=r:t.set([255,r>>8,255&r],e),t},enumerable:!1,configurable:!0}),e.IDENTIFIER_LENGTH=4,e.SENTINEL="PNED",e}();function Ji(e){if(!navigator||!navigator.sendBeacon)return!1;navigator.sendBeacon(e)}var $i=function(e){function n(t){var n=this,r=t.listenToBrowserNetworkEvents,o=void 0===r||r;return t.sdkFamily="Web",t.networking=new _n({del:Fi,get:Ui,post:Ii,patch:Di,sendBeacon:Ji,getfile:xi,postfile:Ri}),t.cbor=new wn((function(e){return Sn(h.decode(e))}),m),t.PubNubFile=Bi,t.cryptography=new Ki,t.initCryptoModule=function(e){return new zi({default:new Hi({cipherKey:e.cipherKey,useRandomIVs:e.useRandomIVs}),cryptors:[new qi({cipherKey:e.cipherKey})]})},n=e.call(this,t)||this,o&&(window.addEventListener("offline",(function(){n.networkDownDetected()})),window.addEventListener("online",(function(){n.networkUpDetected()}))),n}return t(n,e),n.CryptoModule=zi,n}(vn);return $i})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,o=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new c(r,n,o,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new o(null!=t?t:this.message,this.toStatus(e))}}class u{constructor(e){this.configuration=e,this.serviceWorkerEventsQueue=[],this.callbacks=new Map,this.setupServiceWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.serviceWorker;s?s.postMessage(e):t?this.serviceWorkerEventsQueue.splice(0,0,e):this.serviceWorkerEventsQueue.push(e)}flushScheduledEvents(){const e=this.serviceWorker;if(!e||0===this.serviceWorkerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.serviceWorkerEventsQueue.forEach((t=>e.postMessage(t))),this.serviceWorkerEventsQueue=[]}get serviceWorker(){return this.serviceWorkerRegistration?this.serviceWorkerRegistration.active:null}setupServiceWorker(){if(!("serviceWorker"in navigator))return;const e=navigator.serviceWorker;e.register("https://cdn.pubnub.com/sdk/javascript/dist/web/pubnub.worker.min.js",{scope:`/pubnub-${this.configuration.sdkVersion}`}).then((e=>{this.serviceWorkerRegistration=e,e.active&&this.flushScheduledEvents(),this.serviceWorkerRegistration.addEventListener("updatefound",(()=>{if(!this.serviceWorkerRegistration)return;const e=this.serviceWorkerRegistration.installing,t=()=>{"activated"===e.state?this.flushScheduledEvents():"redundant"===e.state&&e.removeEventListener("statechange",t)};e.addEventListener("statechange",t)}))})),e.addEventListener("message",(e=>this.handleServiceWorkerEvent(e)))}handleServiceWorkerEvent(e){const{data:t}=e;if(t.clientIdentifier===this.configuration.clientIdentifier)if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=i.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=i.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=i.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=i.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(c.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new c(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}function l(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return h(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return h(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return h(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return h(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return h(this,void 0,void 0,(function*(){return this.data}))}}p.supportsBlob="undefined"!=typeof Blob,p.supportsFile="undefined"!=typeof File,p.supportsBuffer=!1,p.supportsStream=!1,p.supportsString=!0,p.supportsArrayBuffer=!0,p.supportsEncryptFile=!0,p.supportsFileUri=!1;function g(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function y(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var f,m,b,v,w,S=S||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return v.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=S,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=S,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:g(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return h(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return h(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return h(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=P.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:M.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new o("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:y(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return h(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new o("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}M.encoder=new TextEncoder,M.decoder=new TextDecoder;class j extends d{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new o("Crypto module error: cipher key not set.");return new j({default:new M(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new o("Crypto module error: cipher key not set.");return new j({default:new E({cipherKey:e.cipherKey}),cryptors:[new M(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(j.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return h(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?g(e):e,s=_.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return h(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=_.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return h(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof p)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}j.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==_.SENTINEL))return j.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(n),o)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";const R=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>R(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw c.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw c.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return h(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${R(t)}`)).join("&"):`${e}=${R(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=!1,K=e=>{var t,s,n,r;return(null!==(t=e.enableServiceWorker)&&void 0!==t?t:D)&&!("serviceWorker"in navigator)&&(e.enableServiceWorker=!1),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,a,c,u,l,h,d,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.restore)&&void 0!==i||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(d=m.maintainPresenceState)&&void 0!==d||(m.maintainPresenceState=!0),null!==(p=m.keepAlive)&&void 0!==p||(m.keepAlive=!1),m.userId&&m.uuid)throw new o("PubNub client configuration error: use only 'userId'");if(null!==(g=m.userId)&&void 0!==g||(m.userId=m.uuid),!m.userId)throw new o("PubNub client configuration error: 'userId' not set");if(0===(null===(y=m.userId)||void 0===y?void 0:y.trim().length))throw new o("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),null!==(f=m.presenceTimeout)&&void 0!==f||(m.presenceTimeout=300);let v=!1,w=!0,S=5,k=!1,E=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(E=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:100,useRequestId:E,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(s=e.listenToBrowserNetworkEvents)||void 0===s||s,enableServiceWorker:null!==(n=e.enableServiceWorker)&&void 0!==n?n:D,keepAlive:null===(r=e.keepAlive)||void 0===r||r})};var q={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),$={createUUID:()=>G.uuid?G.uuid():G()};const L=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=B(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${$.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"7.6.3"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},B=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class H{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var z;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(z||(z={}));class V{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?z.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===z.POST||t===z.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=V.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${R(e)}`)).join("&"):`${t}=${R(s)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:i.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:i.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class Q{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Y{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class X{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new Q(o),this.dedupingManager=new Y({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const r=new Set,i=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],i.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],i.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],r.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],r.add(e))})),0===i.size&&0===r.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(r),s=Array.from(i),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,r=l(e,["error"]);let i;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?i=e.errorData.message:"message"in e&&"string"==typeof e.message&&(i=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},r),{error:null!=i&&i,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===i.PNCancelledCategory)return;return void(e.category===i.PNTimeoutCategory?this.startSubscribeLoop():e.category===i.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:i.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===i.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:i.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:i.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:i.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=l(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class se{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class ne{constructor(e){this.params=e,this.requestIdentifier=$.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return h(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:z.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===z.POST||r.method===z.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=ne.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var re;ne.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var oe;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(oe||(oe={}));class ae extends ne{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){let t;try{const s=ne.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?oe.Presence:oe.Message),"string"==typeof e.d?t==oe.Message?{type:oe.Message,data:this.messageFromEnvelope(e)}:{type:oe.Files,data:this.fileFromEnvelope(e)}:t==oe.Message?{type:oe.Message,data:this.messageFromEnvelope(e)}:t===oe.Presence?{type:oe.Presence,data:this.presenceEventFromEnvelope(e)}:t==oe.Signal?{type:oe.Signal,data:this.signalFromEnvelope(e)}:t===oe.AppContext?{type:oe.AppContext,data:this.appContextFromEnvelope(e)}:t===oe.MessageAction?{type:oe.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:oe.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ce extends ae{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===oe.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===oe.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===oe.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===oe.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,type:o}=s,a=l(s,["event","type"]),c=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",type:"user"})});this.listenerManager.announceUser(c),this.announce("user",c,c.spaceId,c.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,type:o}=s,a=l(s,["event","type"]),c=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(c),this.announce("space",c,c.spaceId,c.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,data:o}=s,a=l(s,["event","data"]),{uuid:c,channel:u}=o,h=l(o,["uuid","channel"]),d=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",data:Object.assign(Object.assign({},h),{user:c,space:u})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===oe.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===oe.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function fe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class me extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class be extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new me}abort(){this._aborted=!0,this.notify(new me)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new be}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,s)=>new we(t,s,e),ke=ge("RECONNECT",(()=>({}))),Ee=ge("DISCONNECT",(()=>({}))),Oe=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),je=ge("HEARTBEAT_GIVEUP",(()=>({}))),_e=ge("TIMES_UP",(()=>({}))),Ae=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Re=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ye("EMIT_STATUS",(e=>e)),Ue=fe("WAIT",(()=>({}))),Te=fe("DELAYED_HEARTBEAT",(e=>e));class Fe extends pe{constructor(e,t){super(t),this.on(Ae.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:a}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:r}),{heartbeat:a.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Re.type,Se(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ue.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Te.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:a,config:c}){if(!c.retryConfiguration||!c.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(je());s.throwIfAborted(),yield r(c.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},c.maintainPresenceState&&{state:a}),{heartbeat:c.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Oe.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Ue())),De.onExit((()=>Ue.cancel)),De.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Re(t.payload.channels,t.payload.groups)]))),De.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Re(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Re(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_FAILED");Ke.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Re(t.payload.channels,t.payload.groups)]))),Ke.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Ke.on(Ee.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Re(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Re(e.channels,e.groups)])));const qe=new he("HEARBEAT_RECONNECTING");qe.onEnter((e=>Te(e))),qe.onExit((()=>Te.cancel)),qe.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Re(t.payload.channels,t.payload.groups)]))),qe.on(Ee.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Re(e.channels,e.groups)])})),qe.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Me.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(je.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Re(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Re(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Re(e.channels,e.groups)]))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Re(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(Oe.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Oe(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),ze=fe("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),Ve=ye("EMIT_MESSAGES",(e=>e)),We=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Qe=fe("HANDSHAKE_RECONNECT",(e=>e)),Ye=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Xe=ge("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),st=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),nt=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),ot=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),at=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:a}){s.throwIfAborted();try{const i=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:r}));return e.transition(Ze(i))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(ze.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;if(!s.aborted)return e.transition(it(t))}}}))))),this.on(Ve.type,Se(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(We.type,Se(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Je.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new o(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:a.filterExpression});return e.transition(ot(r.cursor,r.messages))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(at(t))}}}))))),this.on(Qe.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:a,config:c}){if(!c.retryConfiguration||!c.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(nt(new o(c.retryConfiguration?c.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(c.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:c.filterExpression},c.maintainPresenceState&&{state:a}));return e.transition(tt(r))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(st(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Xe.type,((e,t)=>{var s,n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Ye.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Xe.type,((e,t)=>{var s;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var s;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Xe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Xe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var s;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const mt=new he("RECEIVE_RECONNECTING");mt.onEnter((e=>Je(e))),mt.onExit((()=>Je.cancel)),mt.on(ot.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[Ve(t.payload.events)]))),mt.on(at.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(ct.type,((e,t)=>{var s;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:i.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:i.PNDisconnectedCategory})]))),mt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(Ye.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(ht.type,(e=>St.with(void 0,[We({category:i.PNDisconnectedCategory})])));const bt=new he("RECEIVING");bt.onEnter((e=>ze(e.channels,e.groups,e.cursor))),bt.onExit((()=>ze.cancel)),bt.on(rt.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[Ve(t.payload.events)]))),bt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),bt.on(Xe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(it.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:i.PNDisconnectedCategory})]))),bt.on(ht.type,(e=>St.with(void 0,[We({category:i.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Qe(e))),vt.onExit((()=>Qe.cancel)),vt.on(tt.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return bt.with({channels:e.channels,groups:e.groups,cursor:r},[We({category:i.PNConnectedCategory})])})),vt.on(st.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(nt.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:i.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var s,n;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[We({category:i.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Xe.type,((e,t)=>{var s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Xe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Ye(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Ye(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Et extends ne{constructor(e){var t,s;super({method:e.sendByPost?z.POST:z.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${R(t)}/0${this.parameters.sendByPost?"":`/${R(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:y(s))}}class Ot extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${R(s)}/0/${R(r)}`}}class Ct extends ae{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Nt extends ae{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Pt extends ne{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${R(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class jt extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends ne{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${R(t)}`}}class Rt extends ne{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(n.status>=400)throw c.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,u={};let l={};if("occupancy"in n){const e=this.parameters.channels[0];l[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else l=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(l).forEach((e=>{const t=l[e];u[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:u}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ut extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Tt extends ne{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class xt extends ne{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(s.status>=400)throw c.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Kt extends ne{constructor(e){super({method:z.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{data:t.data}}))}get headers(){return{"Content-Type":"application/json"}}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}/message/${s}`}get body(){return JSON.stringify(this.parameters.action)}}class qt extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}/message/${n}/action/${s}`}}class Gt extends ne{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${R(t)}/0/${R(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:y(s))}}class $t extends ne{constructor(e){super({method:z.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${R(e)}/files/${t}/${s}`}}class Lt extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${R(s)}/files/${t}/${n}`}}class Bt extends ne{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends ne{constructor(e){super({method:z.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/generate-upload-url`}get body(){return JSON.stringify({name:this.parameters.name})}}class zt extends ne{constructor(e){super({method:z.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?zt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Vt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return h(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new o("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:i.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof o)throw e;const t=e instanceof c?e:c.create(e);throw new o("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return h(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return h(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new zt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return h(this,void 0,void 0,(function*(){var s,n,r,a;let c,u={timetoken:"0"},l=this.parameters.fileUploadPublishRetryLimit,h=!1;do{try{u=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),h=!0}catch(e){e instanceof o&&(c=e),l-=1}}while(!h&&l>0);if(h)return{status:200,timetoken:u.timetoken,id:e,name:t};throw new o("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=c.status)||void 0===s?void 0:s.category)&&void 0!==n?n:i.PNUnknownCategory,statusCode:null!==(a=null===(r=c.status)||void 0===r?void 0:r.statusCode)&&void 0!==a?a:0,channel:this.parameters.channel,id:e,name:t})}))}}class Wt extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNAccessManagerRevokeToken}validate(){return this.parameters.keySet.secretKey?this.parameters.token?void 0:"token can't be empty":"Missing Secret Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},token:t}=this.parameters;return`/v3/pam/${e}/grant/${R(t)}`}}class Jt extends ne{constructor(e){var t,s,n,r;super({method:z.POST}),this.parameters=e,null!==(t=(n=this.parameters).resources)&&void 0!==t||(n.resources={}),null!==(s=(r=this.parameters).patterns)&&void 0!==s||(r.patterns={})}operation(){return ie.PNAccessManagerGrantToken}validate(){var e,t,s,n,r,i;const{keySet:{subscribeKey:o,publishKey:a,secretKey:c},resources:u,patterns:l}=this.parameters;if(!o)return"Missing Subscribe Key";if(!a)return"Missing Publish Key";if(!c)return"Missing Secret Key";if(!u&&!l)return"Missing either Resources or Patterns";if(this.isVspPermissions(this.parameters)&&("channels"in(null!==(e=this.parameters.resources)&&void 0!==e?e:{})||"uuids"in(null!==(t=this.parameters.resources)&&void 0!==t?t:{})||"groups"in(null!==(s=this.parameters.resources)&&void 0!==s?s:{})||"channels"in(null!==(n=this.parameters.patterns)&&void 0!==n?n:{})||"uuids"in(null!==(r=this.parameters.patterns)&&void 0!==r?r:{})||"groups"in(null!==(i=this.parameters.patterns)&&void 0!==i?i:{})))return"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`";let h=!0;return[this.parameters.resources,this.parameters.patterns].forEach((e=>{Object.keys(null!=e?e:{}).forEach((t=>{var s;e&&h&&Object.keys(null!==(s=e[t])&&void 0!==s?s:{}).length>0&&(h=!1)}))})),h?"Missing values for either Resources or Patterns":void 0}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.data.token}))}get path(){return`/v3/pam/${this.parameters.keySet.subscribeKey}/grant`}get body(){const{ttl:e,meta:t}=this.parameters,s=Object.assign({},e||0===e?{ttl:e}:{}),n=this.isVspPermissions(this.parameters)?this.parameters.authorizedUserId:this.parameters.authorized_uuid,r={},i={},o={},a=(e,t,s,n)=>{n[s]||(n[s]={}),n[s][e]=t},{resources:c,patterns:u}=this.parameters;return[c,u].forEach(((e,t)=>{var s,n,r,c,u;const l=0===t?i:o;let h={},d={},p={};l.channels||(l.channels={}),l.groups||(l.groups={}),l.uuids||(l.uuids={}),l.users||(l.users={}),l.spaces||(l.spaces={}),e&&("spaces"in e||"users"in e?(h=null!==(s=e.spaces)&&void 0!==s?s:{},p=null!==(n=e.users)&&void 0!==n?n:{}):("channels"in e||"uuids"in e||"groups"in e)&&(h=null!==(r=e.channels)&&void 0!==r?r:{},d=null!==(c=e.groups)&&void 0!==c?c:{},p=null!==(u=e.uuids)&&void 0!==u?u:{})),Object.keys(h).forEach((e=>a(e,this.extractPermissions(h[e]),"channels",l))),Object.keys(d).forEach((e=>a(e,this.extractPermissions(d[e]),"groups",l))),Object.keys(p).forEach((e=>a(e,this.extractPermissions(p[e]),"uuids",l)))})),n&&(r.uuid=`${n}`),r.resources=i,r.patterns=o,r.meta=null!=t?t:{},s.permissions=r,JSON.stringify(s)}extractPermissions(e){let t=0;return"join"in e&&e.join&&(t|=128),"update"in e&&e.update&&(t|=64),"get"in e&&e.get&&(t|=32),"delete"in e&&e.delete&&(t|=8),"manage"in e&&e.manage&&(t|=4),"write"in e&&e.write&&(t|=2),"read"in e&&e.read&&(t|=1),t}isVspPermissions(e){var t,s,n,r;return"authorizedUserId"in e||"spaces"in(null!==(t=e.resources)&&void 0!==t?t:{})||"users"in(null!==(s=e.resources)&&void 0!==s?s:{})||"spaces"in(null!==(n=e.patterns)&&void 0!==n?n:{})||"users"in(null!==(r=e.patterns)&&void 0!==r?r:{})}}class Qt extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b,v,w;super(),this.parameters=e,null!==(t=(h=this.parameters).channels)&&void 0!==t||(h.channels=[]),null!==(s=(d=this.parameters).channelGroups)&&void 0!==s||(d.channelGroups=[]),null!==(n=(p=this.parameters).uuids)&&void 0!==n||(p.uuids=[]),null!==(r=(g=this.parameters).read)&&void 0!==r||(g.read=false),null!==(i=(y=this.parameters).write)&&void 0!==i||(y.write=false),null!==(o=(f=this.parameters).delete)&&void 0!==o||(f.delete=false),null!==(a=(m=this.parameters).get)&&void 0!==a||(m.get=false),null!==(c=(b=this.parameters).update)&&void 0!==c||(b.update=false),null!==(u=(v=this.parameters).manage)&&void 0!==u||(v.manage=false),null!==(l=(w=this.parameters).join)&&void 0!==l||(w.join=false)}operation(){return ie.PNAccessManagerGrant}validate(){const{keySet:{subscribeKey:e,publishKey:t,secretKey:s},uuids:n=[],channels:r=[],channelGroups:i=[],authKeys:o=[]}=this.parameters;return e?t?s?0!==n.length&&0===o.length?"authKeys are required for grant request on uuids":!n.length||0===r.length&&0===i.length?void 0:"Both channel/channel group and uuid cannot be used in the same request":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload}))}get path(){return`/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channels:e,channelGroups:t,authKeys:s,uuids:n,read:r,write:i,manage:o,delete:a,get:c,join:u,update:l,ttl:h}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},e&&(null==e?void 0:e.length)>0?{channel:e.join(",")}:{}),t&&(null==t?void 0:t.length)>0?{"channel-group":t.join(",")}:{}),s&&(null==s?void 0:s.length)>0?{auth:s.join(",")}:{}),n&&(null==n?void 0:n.length)>0?{"target-uuid":n.join(",")}:{}),{r:r?"1":"0",w:i?"1":"0",m:o?"1":"0",d:a?"1":"0",g:c?"1":"0",j:u?"1":"0",u:l?"1":"0"}),h||0===h?{ttl:h}:{})}}const Yt=[];class Xt extends ne{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).authKeys)&&void 0!==t||(s.authKeys=Yt)}operation(){return ie.PNAccessManagerAudit}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload}))}get path(){return`/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channel:e,channelGroup:t,authKeys:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},e?{channel:e}:{}),t?{"channel-group":t}:{}),s&&s.length?{auth:s.join(",")}:{})}}class Zt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class es extends Zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class ts extends Zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new es({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ss{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new ts({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ns{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new ts({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class rs{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new ts({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class is{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new ts({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class os extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class as extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class cs extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}}class us extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}/remove`}}class ls extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return h(this,void 0,void 0,(function*(){const t=new ls({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return h(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends ne{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class ps extends ds{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class gs extends ds{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{channels:t}}))}}class ys extends ds{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class fs extends ds{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class ms{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new gs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new ys(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return h(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class bs extends ne{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vs extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}}class ws extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:z.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends ne{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Es extends ne{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class Os extends ne{constructor(e){var t,s,n;super({method:z.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Cs extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}}class Ns extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ps extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:z.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ms extends ne{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class js extends ne{constructor(e){var t,s,n;super({method:z.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class _s{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ks(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ms(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new js(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Cs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new bs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new Os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ps(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ps(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ws(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class As extends ne{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Rs extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/files/${s}/${n}`}}class Is{static notificationPayload(e,t){return new se(e,t)}static generateUUID(){return $.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new _s(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ms(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new o("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:i.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new X(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new is(e,this.eventEmitter,this)}channelGroup(e){return new ns(e,this.eventEmitter,this)}channelMetadata(e){return new ss(e,this.eventEmitter,this)}userMetadata(e){return new rs(e,this.eventEmitter,this)}subscriptionSet(e){return new es(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return h(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(a(s),null);throw new o("Validation failed, check status for details",a(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ie.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:i.PNAcknowledgmentCategory,statusCode:0},[u,l]=this.transport.makeSendable(n);return e.cancellationController=l||null,u.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Is.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof c?s:c.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return h(this,void 0,void 0,(function*(){const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}signal(e,t){return h(this,void 0,void 0,(function*(){const s=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fire(e,t){return h(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){const s=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return h(this,void 0,void 0,(function*(){const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}))}subscribeReceiveMessages(e){return h(this,void 0,void 0,(function*(){const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}))}getMessageActions(e,t){return h(this,void 0,void 0,(function*(){const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addMessageAction(e,t){return h(this,void 0,void 0,(function*(){const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMessageAction(e,t){return h(this,void 0,void 0,(function*(){const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMessages(e,t){return h(this,void 0,void 0,(function*(){const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteMessages(e,t){return h(this,void 0,void 0,(function*(){const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}messageCounts(e,t){return h(this,void 0,void 0,(function*(){const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}history(e,t){return h(this,void 0,void 0,(function*(){const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}hereNow(e,t){return h(this,void 0,void 0,(function*(){const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}whereNow(e,t){return h(this,void 0,void 0,(function*(){var s;const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}))}getState(e,t){return h(this,void 0,void 0,(function*(){var s;const n=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setState(e,t){return h(this,void 0,void 0,(function*(){var s,n;const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new jt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return h(this,void 0,void 0,(function*(){const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return h(this,void 0,void 0,(function*(){const s=new Jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}revokeToken(e,t){return h(this,void 0,void 0,(function*(){const s=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get token(){return this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager.parseToken(e)}grant(e,t){return h(this,void 0,void 0,(function*(){const s=new Qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}audit(e,t){return h(this,void 0,void 0,(function*(){const s=new Xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get objects(){return this._objects}fetchUsers(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n,r;if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Vt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ie.PNPublishFileOperation,category:i.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof o?s=e.status:e instanceof c&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new o("REST API request processing error, check status for details",s)}))}))}publishFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listFiles(e,t){return h(this,void 0,void 0,(function*(){const s=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getFileUrl(e){var t;const s=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${R(t)}`)).join("&"):`${e}=${R(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}downloadFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Rs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}))}deleteFile(e,t){return h(this,void 0,void 0,(function*(){const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}time(e){return h(this,void 0,void 0,(function*(){const t=new As;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:y(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Is.decoder=new TextDecoder,Is.OPERATIONS=ie,Is.CATEGORIES=i,Is.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,Is.LinearRetryPolicy=Be.LinearRetryPolicy;class Us{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ts extends Is{constructor(e){var t;const s=K(e),n=Object.assign(Object.assign({},s),{sdkFamily:"Web",PubNubFile:p}),i=L(n,(e=>{if(e.cipherKey)return new j({default:new M(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})})),o=new H(new Us((e=>x(r.decode(e))),g));let a;(i.getCipherKey()||i.secretKey)&&(a=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()}));let c=new F(i.keepAlive,i.logVerbosity);s.enableServiceWorker&&(c=new u({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,transport:c}));super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:o,transport:c}),cryptography:new P,tokenManager:o,crypto:a}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ts.CryptoModule=j,Ts})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js new file mode 100644 index 000000000..31a3ef3ac --- /dev/null +++ b/dist/web/pubnub.worker.js @@ -0,0 +1,979 @@ +(function (factory) { + typeof define === 'function' && define.amd ? define(factory) : + factory(); +})((function () { 'use strict'; + + /****************************************************************************** + Copyright (c) Microsoft Corporation. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH + REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, + INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM + LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + PERFORMANCE OF THIS SOFTWARE. + ***************************************************************************** */ + /* global Reflect, Promise, SuppressedError, Symbol */ + + + function __awaiter(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()); + }); + } + + typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { + var e = new Error(message); + return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; + }; + + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + + function getDefaultExportFromCjs (x) { + return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x; + } + + var uuid = {exports: {}}; + + /*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */ + uuid.exports; + + (function (module, exports) { + (function (root, factory) { + { + factory(exports); + if (module !== null) { + module.exports = exports.uuid; + } + } + }(commonjsGlobal, function (exports) { + var VERSION = '0.1.0'; + var uuidRegex = { + '3': /^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i, + '4': /^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, + '5': /^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i, + all: /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i + }; + + function uuid() { + var uuid = '', i, random; + for (i = 0; i < 32; i++) { + random = Math.random() * 16 | 0; + if (i === 8 || i === 12 || i === 16 || i === 20) uuid += '-'; + uuid += (i === 12 ? 4 : (i === 16 ? (random & 3 | 8) : random)).toString(16); + } + return uuid + } + + function isUUID(str, version) { + var pattern = uuidRegex[version || 'all']; + return pattern && pattern.test(str) || false + } + + uuid.isUUID = isUUID; + uuid.VERSION = VERSION; + + exports.uuid = uuid; + exports.isUUID = isUUID; + })); + } (uuid, uuid.exports)); + + var uuidExports = uuid.exports; + var uuidGenerator$1 = /*@__PURE__*/getDefaultExportFromCjs(uuidExports); + + var uuidGenerator = { + createUUID() { + if (uuidGenerator$1.uuid) { + return uuidGenerator$1.uuid(); + } + // @ts-expect-error Depending on module type it may be callable. + return uuidGenerator$1(); + }, + }; + + /// + /** + * Subscription Service Worker Transport provider. + * + * Service worker provides support for PubNub subscription feature to give better user experience across + * multiple opened pages. + */ + // region State + /** + * Service `ArrayBuffer` response decoder. + */ + const decoder = new TextDecoder(); + /** + * Map of identifiers, scheduled by the Service Worker, to their abort controllers. + * + * **Note:** Because of message-based nature of interaction it will be impossible to pass actual {@link AbortController} + * to the transport provider code. + */ + const abortControllers = new Map(); + /** + * Map of PubNub client identifiers to their state in the current Service Worker. + */ + const pubNubClients = {}; + /** + * Per-subscription key list of PubNub client state. + */ + const pubNubClientsBySubscriptionKey = {}; + /** + * Per-subscription key presence state associated with unique user identifiers with which {@link pubNubClients|clients} + * scheduled subscription request. + */ + const presenceState = {}; + /** + * Per-subscription key map of client identifiers to the Service Worker {@link Client} identifier. + * + * Service Worker {@link Client} represent pages at which PubNub clients registered Service Workers. + */ + const serviceWorkerClients = {}; + /** + * List of ongoing subscription requests. + * + * **Node:** Identifiers differ from request identifiers received in {@link SendRequestEvent} object. + */ + const serviceRequests = {}; + // endregion + // -------------------------------------------------------- + // ------------------- Event Handlers --------------------- + // -------------------------------------------------------- + // region Event Handlers + /** + * Listen for Service Worker activation. + */ + self.addEventListener('activate', (event) => { + event.waitUntil(self.clients.claim()); + }); + /** + * Listen for events from the client. + */ + self.addEventListener('message', (event) => { + // Ignoring requests sent from other service workers. + if (!validateEventPayload(event)) + return; + const data = event.data; + if (data.type === 'send-request') { + if (data.request.path.startsWith('/v2/subscribe')) { + registerClientIfRequired(event); + handleSendSubscribeRequestEvent(data); + } + else { + if (!pubNubClients[data.clientIdentifier]) + registerClientIfRequired(event); + handleSendLeaveRequestEvent(event); + } + } + else if (data.type === 'cancel-request') + handleCancelRequestEvent(data); + }); + /** + * Handle client request to send subscription request. + * + * @param event - Subscription event details. + */ + const handleSendSubscribeRequestEvent = (event) => { + const requestOrId = subscribeTransportRequestFromEvent(event); + const client = pubNubClients[event.clientIdentifier]; + if (client) + notifyRequestProcessing('start', [client], new Date().toISOString()); + if (typeof requestOrId === 'string') { + if (client) { + // Updating client timetoken information. + client.subscription.previousTimetoken = client.subscription.timetoken; + client.subscription.timetoken = serviceRequests[requestOrId].timetoken; + client.subscription.serviceRequestId = requestOrId; + } + return; + } + if (event.request.cancellable) + abortControllers.set(requestOrId.identifier, new AbortController()); + sendRequest(requestOrId, () => clientsForRequest(requestOrId.identifier), (clients, response) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, response); + // Clean up scheduled request and client references to it. + markRequestCompleted(clients, requestOrId.identifier); + }, (clients, error) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, null, requestOrId, requestProcessingError(error)); + // Clean up scheduled request and client references to it. + markRequestCompleted(clients, requestOrId.identifier); + }); + }; + /** + * Handle client request to leave request. + * + * @param event - Leave event details. + */ + const handleSendLeaveRequestEvent = (event) => { + const data = event.data; + const request = leaveTransportRequestFromEvent(data); + const client = pubNubClients[data.clientIdentifier]; + if (!client) + return; + if (!request) { + const body = new TextEncoder().encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'); + const headers = new Headers({ 'Content-Type': 'text/javascript; charset="UTF-8"', 'Content-Length': '74' }); + const response = new Response(body, { status: 200, headers }); + const result = requestProcessingSuccess([response, body]); + result.url = `${data.request.origin}${data.request.path}`; + result.clientIdentifier = data.clientIdentifier; + result.identifier = data.request.identifier; + publishClientEvent(event.source.id, result).then((sent) => { + if (sent) + invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); + }); + return; + } + sendRequest(request, () => [client], (clients, response) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, response, data.request); + }, (clients, error) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, null, data.request, requestProcessingError(error)); + }); + }; + /** + * Handle cancel request event. + * + * Try cancel request if there is no other observers. + * + * @param event - Request cancellation event details. + */ + const handleCancelRequestEvent = (event) => { + const client = pubNubClients[event.clientIdentifier]; + const serviceRequestId = client ? client.subscription.serviceRequestId : undefined; + if (!client || !serviceRequestId) + return; + // Unset awaited requests. + delete client.subscription.serviceRequestId; + delete client.subscription.request; + if (clientsForRequest(serviceRequestId).length === 0) { + const controller = abortControllers.get(serviceRequestId); + abortControllers.delete(serviceRequestId); + // Clean up scheduled requests. + delete serviceRequests[serviceRequestId]; + // Abort request if possible. + if (controller) + controller.abort(); + } + }; + // endregion + // -------------------------------------------------------- + // ------------------------ Common ------------------------ + // -------------------------------------------------------- + // region Common + /** + * Process transport request. + * + * @param request - Transport request with required information for {@link Request} creation. + * @param getClients - Request completion PubNub client observers getter. + * @param success - Request success completion handler. + * @param failure - Request failure handler. + */ + const sendRequest = (request, getClients, success, failure) => { + (() => __awaiter(void 0, void 0, void 0, function* () { + var _a; + // Request progress support. + const start = new Date().getTime(); + Promise.race([ + fetch(requestFromTransportRequest(request), { + signal: (_a = abortControllers.get(request.identifier)) === null || _a === void 0 ? void 0 : _a.signal, + keepalive: true, + }), + requestTimeoutTimer(request.identifier, request.timeout), + ]) + .then((response) => response.arrayBuffer().then((buffer) => [response, buffer])) + .then((response) => { + const responseBody = response[1].byteLength > 0 ? response[1] : undefined; + const clients = getClients(); + if (clients.length === 0) + return; + notifyRequestProcessing('end', clients, new Date().toISOString(), request, responseBody, response[0].headers.get('Content-Type'), new Date().getTime() - start); + success(clients, response); + }) + .catch((error) => { + const clients = getClients(); + if (clients.length === 0) + return; + failure(clients, error); + }); + }))(); + }; + /** + * Create request timeout timer. + * + * **Note:** Native Fetch API doesn't support `timeout` out-of-box and {@link Promise} used to emulate it. + * + * @param requestId - Unique identifier of request which will time out after {@link requestTimeout} seconds. + * @param requestTimeout - Number of seconds after which request with specified identifier will time out. + * + * @returns Promise which rejects after time out will fire. + */ + const requestTimeoutTimer = (requestId, requestTimeout) => new Promise((_, reject) => { + const timeoutId = setTimeout(() => { + // Clean up. + abortControllers.delete(requestId); + clearTimeout(timeoutId); + reject(new Error('Request timeout')); + }, requestTimeout * 1000); + }); + /** + * Retrieve list of PubNub clients which is pending for service worker request completion. + * + * @param identifier - Identifier of the subscription request which has been scheduled by the Service Worker. + * + * @returns List of PubNub client state objects for Service Worker. + */ + const clientsForRequest = (identifier) => { + return Object.values(pubNubClients).filter((client) => client !== undefined && client.subscription.serviceRequestId === identifier); + }; + /** + * Clean up PubNub client states from ongoing request. + * + * Reset requested and scheduled request information to make PubNub client "free" for neext requests. + * + * @param clients - List of PubNub clients which awaited for scheduled request completion. + * @param requestId - Unique subscribe request identifier for which {@link clients} has been provided. + */ + const markRequestCompleted = (clients, requestId) => { + delete serviceRequests[requestId]; + clients.forEach((client) => { + delete client.subscription.request; + delete client.subscription.serviceRequestId; + }); + }; + /** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns `Request` object generated from the {@link TransportRequest} object or `undefined` if no request + * should be sent. + */ + const requestFromTransportRequest = (req) => { + let headers = undefined; + const queryParameters = req.queryParameters; + let path = req.path; + if (req.headers) { + headers = {}; + for (const [key, value] of Object.entries(req.headers)) + headers[key] = value; + } + if (queryParameters && Object.keys(queryParameters).length !== 0) + path = `${path}?${queryStringFromObject(queryParameters)}`; + return new Request(`${req.origin}${path}`, { + method: req.method, + headers, + redirect: 'follow', + }); + }; + /** + * Construct transport request from send subscription request event. + * + * Update transport request to aggregate channels and groups if possible. + * + * @param event - Client's send subscription event request. + * + * @returns Final transport request or identifier from active request which will provide response to required + * channels and groups. + */ + const subscribeTransportRequestFromEvent = (event) => { + var _a, _b, _c, _d; + const client = pubNubClients[event.clientIdentifier]; + const clients = clientsForSendSubscribeRequestEvent(client.subscription.previousTimetoken, event); + const serviceRequestId = uuidGenerator.createUUID(); + const request = Object.assign({}, event.request); + if (clients.length > 1) { + const activeRequestId = activeSubscriptionForEvent(clients, event); + // Return identifier of the ongoing request. + if (activeRequestId) + return activeRequestId; + const state = ((_a = presenceState[client.subscriptionKey]) !== null && _a !== void 0 ? _a : {})[client.userId]; + const aggregatedState = {}; + const channelGroups = new Set(client.subscription.channelGroups); + const channels = new Set(client.subscription.channels); + if (state && client.subscription.objectsWithState.length) { + client.subscription.objectsWithState.forEach((name) => { + const objectState = state[name]; + if (objectState) + aggregatedState[name] = objectState; + }); + } + for (const client of clients) { + const { subscription } = client; + // Skip clients which already have active subscription request. + if (subscription.serviceRequestId) + continue; + subscription.channelGroups.forEach(channelGroups.add, channelGroups); + subscription.channels.forEach(channels.add, channels); + // Set awaited service worker request identifier. + subscription.serviceRequestId = serviceRequestId; + if (!state) + continue; + subscription.objectsWithState.forEach((name) => { + const objectState = state[name]; + if (objectState && !aggregatedState[name]) + aggregatedState[name] = objectState; + }); + } + const serviceRequest = ((_b = serviceRequests[serviceRequestId]) !== null && _b !== void 0 ? _b : (serviceRequests[serviceRequestId] = { + requestId: serviceRequestId, + timetoken: (_c = request.queryParameters.tt) !== null && _c !== void 0 ? _c : '0', + channelGroups: [], + channels: [], + })); + // Update request channels list (if required). + if (channels.size) { + serviceRequest.channels = Array.from(channels).sort(); + const pathComponents = request.path.split('/'); + pathComponents[4] = serviceRequest.channels.join(','); + request.path = pathComponents.join('/'); + } + // Update request channel groups list (if required). + if (channelGroups.size) { + serviceRequest.channelGroups = Array.from(channelGroups).sort(); + request.queryParameters['channel-group'] = serviceRequest.channelGroups.join(','); + } + // Update request `state` (if required). + if (Object.keys(aggregatedState).length) + request.queryParameters['state'] = JSON.stringify(aggregatedState); + } + else { + serviceRequests[serviceRequestId] = { + requestId: serviceRequestId, + timetoken: (_d = request.queryParameters.tt) !== null && _d !== void 0 ? _d : '0', + channelGroups: client.subscription.channelGroups, + channels: client.subscription.channels, + }; + } + client.subscription.serviceRequestId = serviceRequestId; + request.identifier = serviceRequestId; + return request; + }; + /** + * Construct transport request from send leave request event. + * + * Filter out channels and groups, which is still in use by other PubNub client instances from leave request. + * + * @param event - Client's send leave event request. + * + * @returns Final transport request or `undefined` in case if there is no channels and groups for which request can be + * done. + */ + const leaveTransportRequestFromEvent = (event) => { + const client = pubNubClients[event.clientIdentifier]; + const clients = clientsForSendLeaveRequestEvent(event); + let channelGroups = channelGroupsFromRequest(event.request); + let channels = channelsFromRequest(event.request); + const request = Object.assign({}, event.request); + if (client) { + const { subscription } = client; + if (channels.length) + subscription.channels = subscription.channels.filter((channel) => !channels.includes(channel)); + if (channelGroups.length) { + subscription.channelGroups = subscription.channelGroups.filter((group) => !channelGroups.includes(group)); + } + } + // Filter out channels and groups which is still in use by the other PubNub client instances. + for (const client of clients) { + if (client.clientIdentifier === event.clientIdentifier) + continue; + if (channels.length) + channels = channels.filter((channel) => !client.subscription.channels.includes(channel)); + if (channelGroups.length) + channelGroups = channelGroups.filter((group) => !client.subscription.channelGroups.includes(group)); + } + if (channels.length === 0 && channelGroups.length === 0) + return undefined; + // Update request channels list (if required). + if (channels.length) { + const pathComponents = request.path.split('/'); + pathComponents[4] = channels.join(','); + request.path = pathComponents.join('/'); + } + // Update request channel groups list (if required). + if (channelGroups.length) + request.queryParameters['channel-group'] = channelGroups.join(','); + return request; + }; + /** + * Send event to all service worker clients. + * + * @param identifier - Service Worker receiving {@link Client} identifier. + * @param event - Service worker event object. + */ + const publishClientEvent = (identifier, event) => { + return self.clients.get(identifier).then((client) => { + if (!client) + return false; + client.postMessage(event); + return true; + }); + }; + /** + * Send request processing update. + * + * @param type - Type of processing event. + * @param clients - List of PubNub clients which should be notified about request progress. + * @param timestamp - Date and time when request processing update happened. + * @param [request] - Processed request information. + * @param [responseBody] - PubNub service response. + * @param [contentType] - PubNub service response content type. + * @param [duration] - How long it took to complete request. + */ + const notifyRequestProcessing = (type, clients, timestamp, request, responseBody, contentType, duration) => { + var _a; + if (clients.length === 0) + return; + const clientIds = (_a = serviceWorkerClients[clients[0].subscriptionKey]) !== null && _a !== void 0 ? _a : {}; + let event; + if (type === 'start') { + event = { + type: 'request-progress-start', + clientIdentifier: '', + url: '', + timestamp, + }; + } + else { + let response; + if (responseBody && + contentType && + (contentType.indexOf('text/javascript') !== -1 || + contentType.indexOf('application/json') !== -1 || + contentType.indexOf('text/plain') !== -1 || + contentType.indexOf('text/html') !== -1)) { + response = decoder.decode(responseBody); + } + event = { + type: 'request-progress-end', + clientIdentifier: '', + url: '', + response, + timestamp, + duration: duration, + }; + } + clients.forEach((client) => { + const serviceWorkerClientId = clientIds[client.clientIdentifier]; + const { request: clientRequest } = client.subscription; + const decidedRequest = clientRequest !== null && clientRequest !== void 0 ? clientRequest : request; + if (client.logVerbosity && serviceWorkerClientId && decidedRequest) { + publishClientEvent(serviceWorkerClientId, Object.assign(Object.assign({}, event), { clientIdentifier: client.clientIdentifier, url: `${decidedRequest.origin}${decidedRequest.path}`, query: decidedRequest.queryParameters })).then((sent) => { + if (sent) + invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); + }); + } + }); + }; + /** + * Send request processing result event. + * + * @param clients - List of PubNub clients which should be notified about request result. + * @param [response] - PubNub service response. + * @param [request] - Processed request information. + * @param [result] - Explicit request processing result which should be notified. + */ + const notifyRequestProcessingResult = (clients, response, request, result) => { + var _a; + if (clients.length === 0) + return; + if (!result && !response) + return; + const clientIds = (_a = serviceWorkerClients[clients[0].subscriptionKey]) !== null && _a !== void 0 ? _a : {}; + if (!result && response) { + result = + response[0].status >= 400 + ? // Treat 4xx and 5xx status codes as errors. + requestProcessingError(undefined, response) + : requestProcessingSuccess(response); + } + clients.forEach((client) => { + const serviceWorkerClientId = clientIds[client.clientIdentifier]; + const { request: clientRequest } = client.subscription; + const decidedRequest = clientRequest !== null && clientRequest !== void 0 ? clientRequest : request; + if (serviceWorkerClientId && decidedRequest) { + publishClientEvent(serviceWorkerClientId, Object.assign(Object.assign({}, result), { clientIdentifier: client.clientIdentifier, identifier: decidedRequest.identifier, url: `${decidedRequest.origin}${decidedRequest.path}` })).then((sent) => { + if (sent) + invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); + }); + } + }); + }; + /** + * Create processing success event from service response. + * + * **Note:** The rest of information like `clientIdentifier`,`identifier`, and `url` will be added later for each + * specific PubNub client state. + * + * @param res - Service response for used REST API endpoint along with response body. + * + * @returns Request processing success event object. + */ + const requestProcessingSuccess = (res) => { + var _a; + const [response, body] = res; + const responseBody = body.byteLength > 0 ? body : undefined; + const contentLength = parseInt((_a = response.headers.get('Content-Length')) !== null && _a !== void 0 ? _a : '0', 10); + const contentType = response.headers.get('Content-Type'); + const headers = {}; + // Copy Headers object content into plain Record. + response.headers.forEach((value, key) => (headers[key] = value.toLowerCase())); + return { + type: 'request-process-success', + clientIdentifier: '', + identifier: '', + url: '', + response: { + contentLength, + contentType, + headers, + status: response.status, + body: responseBody, + }, + }; + }; + /** + * Create processing error event from service response. + * + * **Note:** The rest of information like `clientIdentifier`,`identifier`, and `url` will be added later for each + * specific PubNub client state. + * + * @param [error] - Client-side request processing error (for example network issues). + * @param [res] - Service error response (for example permissions error or malformed + * payload) along with service body. + * + * @returns Request processing error event object. + */ + const requestProcessingError = (error, res) => { + // User service response as error information source. + if (res) { + return Object.assign(Object.assign({}, requestProcessingSuccess(res)), { type: 'request-process-error' }); + } + let type = 'NETWORK_ISSUE'; + let message = 'Unknown error'; + let name = 'Error'; + if (error && error instanceof Error) { + message = error.message; + name = error.name; + } + if (name === 'AbortError') { + message = 'Request aborted'; + type = 'ABORTED'; + } + else if (message === 'Request timeout') + type = 'TIMEOUT'; + return { + type: 'request-process-error', + clientIdentifier: '', + identifier: '', + url: '', + error: { name, type, message }, + }; + }; + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + /** + * Register client if it didn't use Service Worker before. + * + * The registration process updates the Service Worker state with information about channels and groups in which + * particular PubNub clients are interested, and uses this information when another subscribe request is made to build + * shared requests. + * + * @param event - Base information about PubNub client instance and Service Worker {@link Client}. + */ + const registerClientIfRequired = (event) => { + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u; + var _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5; + const information = event.data; + const { clientIdentifier } = information; + const query = information.request.queryParameters; + let client = pubNubClients[clientIdentifier]; + if (!client) { + const isPresenceLeave = !information.request.path.startsWith('/v2/subscribe'); + const channelGroupQuery = !isPresenceLeave ? ((_a = query['channel-group']) !== null && _a !== void 0 ? _a : '') : ''; + const state = !isPresenceLeave ? ((_b = query.state) !== null && _b !== void 0 ? _b : '') : ''; + client = pubNubClients[clientIdentifier] = { + clientIdentifier, + subscriptionKey: information.subscriptionKey, + userId: query.uuid, + authKey: ((_c = query.auth) !== null && _c !== void 0 ? _c : ''), + logVerbosity: information.logVerbosity, + subscription: { + path: !isPresenceLeave ? information.request.path : '', + channelGroupQuery: !isPresenceLeave ? channelGroupQuery : '', + channels: !isPresenceLeave ? channelsFromRequest(information.request) : [], + channelGroups: !isPresenceLeave ? channelGroupsFromRequest(information.request) : [], + previousTimetoken: !isPresenceLeave ? ((_d = query.tt) !== null && _d !== void 0 ? _d : '0') : '0', + timetoken: !isPresenceLeave ? ((_e = query.tt) !== null && _e !== void 0 ? _e : '0') : '0', + request: !isPresenceLeave ? information.request : undefined, + objectsWithState: [], + filterExpression: !isPresenceLeave ? ((_f = query['filter-expr']) !== null && _f !== void 0 ? _f : '') : undefined, + }, + }; + if (!isPresenceLeave && state.length > 0) { + const parsedState = JSON.parse(state); + const userState = ((_h = (_w = ((_g = presenceState[_v = client.subscriptionKey]) !== null && _g !== void 0 ? _g : (presenceState[_v] = {})))[_x = client.userId]) !== null && _h !== void 0 ? _h : (_w[_x] = {})); + Object.entries(parsedState).forEach(([objectName, value]) => (userState[objectName] = value)); + client.subscription.objectsWithState = Object.keys(parsedState); + } + // Map registered PubNub client to its subscription key. + const clientsBySubscriptionKey = ((_j = pubNubClientsBySubscriptionKey[_y = information.subscriptionKey]) !== null && _j !== void 0 ? _j : (pubNubClientsBySubscriptionKey[_y] = [])); + if (clientsBySubscriptionKey.every((entry) => entry.clientIdentifier !== clientIdentifier)) + clientsBySubscriptionKey.push(client); + // Binding PubNub client to the page (Service Worker Client). + ((_k = serviceWorkerClients[_z = information.subscriptionKey]) !== null && _k !== void 0 ? _k : (serviceWorkerClients[_z] = {}))[clientIdentifier] = event.source.id; + } + else { + const channelGroupQuery = ((_l = query['channel-group']) !== null && _l !== void 0 ? _l : ''); + const state = ((_m = query.state) !== null && _m !== void 0 ? _m : ''); + client.subscription.filterExpression = ((_o = query['filter-expr']) !== null && _o !== void 0 ? _o : ''); + client.subscription.previousTimetoken = client.subscription.timetoken; + client.subscription.timetoken = ((_p = query.tt) !== null && _p !== void 0 ? _p : '0'); + client.subscription.request = information.request; + client.authKey = ((_q = query.auth) !== null && _q !== void 0 ? _q : ''); + client.userId = query.uuid; + if (client.subscription.path !== information.request.path) { + client.subscription.path = information.request.path; + client.subscription.channels = channelsFromRequest(information.request); + } + if (client.subscription.channelGroupQuery !== channelGroupQuery) { + client.subscription.channelGroupQuery = channelGroupQuery; + client.subscription.channelGroups = channelGroupsFromRequest(information.request); + } + if (state.length > 0) { + const parsedState = JSON.parse(state); + const userState = ((_s = (_1 = ((_r = presenceState[_0 = client.subscriptionKey]) !== null && _r !== void 0 ? _r : (presenceState[_0] = {})))[_2 = client.userId]) !== null && _s !== void 0 ? _s : (_1[_2] = {})); + Object.entries(parsedState).forEach(([objectName, value]) => (userState[objectName] = value)); + // Clean up state for objects where presence state has been reset. + for (const objectName of client.subscription.objectsWithState) + if (!parsedState[objectName]) + delete userState[objectName]; + client.subscription.objectsWithState = Object.keys(parsedState); + } + // Handle potential presence state reset. + else if (client.subscription.objectsWithState.length) { + const userState = ((_u = (_4 = ((_t = presenceState[_3 = client.subscriptionKey]) !== null && _t !== void 0 ? _t : (presenceState[_3] = {})))[_5 = client.userId]) !== null && _u !== void 0 ? _u : (_4[_5] = {})); + for (const objectName of client.subscription.objectsWithState) + delete userState[objectName]; + client.subscription.objectsWithState = []; + } + } + }; + /** + * Clean up resources used by registered PubNub client instance. + * + * @param subscriptionKey - Subscription key which has been used by the + * invalidated instance. + * @param clientId - Unique PubNub client identifier. + * @param userId - Unique identifier of the user used by PubNub client instance. + */ + const invalidateClient = (subscriptionKey, clientId, userId) => { + delete pubNubClients[clientId]; + let clients = pubNubClientsBySubscriptionKey[subscriptionKey]; + if (clients) { + // Clean up linkage between client and subscription key. + clients = clients.filter((client) => client.clientIdentifier !== clientId); + if (clients.length > 0) + pubNubClientsBySubscriptionKey[subscriptionKey] = clients; + else + delete pubNubClientsBySubscriptionKey[subscriptionKey]; + // Clean up presence state information if not in use anymore. + if (clients.length === 0) + delete presenceState[subscriptionKey]; + // Clean up service workers client linkage to PubNub clients. + if (clients.length > 0) { + const workerClients = serviceWorkerClients[subscriptionKey]; + if (workerClients) { + delete workerClients[clientId]; + if (Object.keys(workerClients).length === 0) + delete serviceWorkerClients[subscriptionKey]; + } + } + else + delete serviceWorkerClients[subscriptionKey]; + } + }; + /** + * Validate received event payload. + */ + const validateEventPayload = (event) => { + if (!event.source || !(event.source instanceof Client)) + return false; + const data = event.data; + const { clientIdentifier, subscriptionKey, logVerbosity } = data; + if (logVerbosity === undefined || typeof logVerbosity !== 'boolean') + return false; + if (!clientIdentifier || typeof clientIdentifier !== 'string') + return false; + return !(!subscriptionKey || typeof subscriptionKey !== 'string'); + }; + /** + * Search for active subscription for one of the passed {@link serviceWorkerClients}. + * + * @param activeClients - List of suitable registered PubNub clients. + * @param event - Send Subscriber Request event data. + * + * @returns Unique identifier of the active request which will receive real-time updates for channels and groups + * requested in received subscription request or `undefined` if none of active (or not scheduled) request can be used. + */ + const activeSubscriptionForEvent = (activeClients, event) => { + var _a; + const query = event.request.queryParameters; + const channelGroupQuery = ((_a = query['channel-group']) !== null && _a !== void 0 ? _a : ''); + const requestPath = event.request.path; + let channelGroups; + let channels; + for (const client of activeClients) { + const { subscription } = client; + // Skip PubNub clients which doesn't await for subscription response. + if (!subscription.serviceRequestId) + continue; + if (subscription.path === requestPath && subscription.channelGroupQuery === channelGroupQuery) { + return subscription.serviceRequestId; + } + else { + const scheduledRequest = serviceRequests[subscription.serviceRequestId]; + if (!channelGroups) + channelGroups = channelGroupsFromRequest(event.request); + if (!channels) + channels = channelsFromRequest(event.request); + // Checking whether all required channels and groups are handled already by active request or not. + if (channels.length && !includesStrings(scheduledRequest.channels, channels)) + continue; + if (channelGroups.length && !includesStrings(scheduledRequest.channelGroups, channelGroups)) + continue; + return subscription.serviceRequestId; + } + } + return undefined; + }; + /** + * Find PubNub client states with configuration compatible with the one in request. + * + * Method allow to find information about all PubNub client instances which use same: + * - subscription key + * - `userId` + * - `auth` key + * - `filter expression` + * - `timetoken` (compare should be done against previous timetoken of the client which requested new subscribe). + * + * @param timetoken - Previous timetoken used by the PubNub client which requested to send new subscription request + * (it will be the same as 'current' timetoken of the other PubNub clients). + * @param event - Send subscribe request event information. + * + * @returns List of PubNub client states which works from other pages for the same user. + */ + const clientsForSendSubscribeRequestEvent = (timetoken, event) => { + var _a, _b, _c; + const query = event.request.queryParameters; + const filterExpression = ((_a = query['filter-expr']) !== null && _a !== void 0 ? _a : ''); + const authKey = ((_b = query.auth) !== null && _b !== void 0 ? _b : ''); + const userId = query.uuid; + return ((_c = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _c !== void 0 ? _c : []).filter((client) => client.userId === userId && + client.authKey === authKey && + client.subscription.filterExpression === filterExpression && + (timetoken === '0' || + client.subscription.previousTimetoken === '0' || + client.subscription.previousTimetoken === timetoken)); + }; + /** + * Find PubNub client states with configuration compatible with the one in request. + * + * Method allow to find information about all PubNub client instances which use same: + * - subscription key + * - `userId` + * - `auth` key + * + * @param event - Send leave request event information. + * + * @returns List of PubNub client states which works from other pages for the same user. + */ + const clientsForSendLeaveRequestEvent = (event) => { + var _a, _b; + const query = event.request.queryParameters; + const authKey = ((_a = query.auth) !== null && _a !== void 0 ? _a : ''); + const userId = query.uuid; + return ((_b = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _b !== void 0 ? _b : []).filter((client) => client.userId === userId && client.authKey === authKey); + }; + /** + * Extract list of channels from request URI path. + * + * @param request - Transport request which should provide `path` for parsing. + * + * @returns List of channel names (not percent-decoded) for which `subscribe` or `leave` has been called. + */ + const channelsFromRequest = (request) => { + const channels = request.path.split('/')[request.path.startsWith('/v2/subscribe/') ? 4 : 6]; + return channels === ',' ? [] : channels.split(',').filter((name) => name.length > 0); + }; + /** + * Extract list of channel groups from request query. + * + * @param request - Transport request which should provide `query` for parsing. + * + * @returns List of channel group names (not percent-decoded) for which `subscribe` or `leave` has been called. + */ + const channelGroupsFromRequest = (request) => { + var _a; + const group = ((_a = request.queryParameters['channel-group']) !== null && _a !== void 0 ? _a : ''); + return group.length === 0 ? [] : group.split(',').filter((name) => name.length > 0); + }; + /** + * Check whether {@link main} array contains all entries from {@link sub} array. + * + * @param main - Main array with which `intersection` with {@link sub} should be checked. + * @param sub - Sub-array whose values should be checked in {@link main}. + * + * @returns `true` if all entries from {@link sub} is present in {@link main}. + */ + const includesStrings = (main, sub) => { + const set = new Set(main); + return sub.every(set.has, set); + }; + /** + * Stringify request query key / value pairs. + * + * @param query - Request query object. + * + * @returns Stringified query object. + */ + const queryStringFromObject = (query) => { + return Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${encodeString(queryValue)}`; + return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); + }) + .join('&'); + }; + /** + * Percent-encode input string. + * + * **Note:** Encode content in accordance of the `PubNub` service requirements. + * + * @param input - Source string or number for encoding. + * + * @returns Percent-encoded string. + */ + const encodeString = (input) => { + return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); + }; + // endregion + // endregion + +})); diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js new file mode 100644 index 000000000..864385802 --- /dev/null +++ b/dist/web/pubnub.worker.min.js @@ -0,0 +1,2 @@ +!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,i){return new(n||(n=Promise))((function(s,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function u(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,u)}c((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,i,s={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function i(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function s(e,t){var i=n[t||"all"];return i&&i.test(e)||!1}i.isUUID=s,i.VERSION=t,e.uuid=i,e.isUUID=s}(i=s.exports),null!==n&&(n.exports=i.uuid);var r=t(s.exports),o={createUUID:()=>r.uuid?r.uuid():r()};const u=new TextDecoder,c=new Map,l={},a={},d={},p={},f={};self.addEventListener("activate",(e=>{e.waitUntil(self.clients.claim())})),self.addEventListener("message",(e=>{if(!K(e))return;const t=e.data;"send-request"===t.type?t.request.path.startsWith("/v2/subscribe")?(k(e),h(t)):(l[t.clientIdentifier]||k(e),b(e)):"cancel-request"===t.type&&v(t)}));const h=e=>{const t=j(e),n=l[e.clientIdentifier];n&&w("start",[n],(new Date).toISOString()),"string"!=typeof t?(e.request.cancellable&&c.set(t.identifier,new AbortController),g(t,(()=>q(t.identifier)),((e,n)=>{E(e,n),I(e,t.identifier)}),((e,n)=>{E(e,null,t,T(n)),I(e,t.identifier)}))):n&&(n.subscription.previousTimetoken=n.subscription.timetoken,n.subscription.timetoken=f[t].timetoken,n.subscription.serviceRequestId=t)},b=e=>{const t=e.data,n=O(t),i=l[t.clientIdentifier];if(i){if(!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),s=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":"74"}),r=new Response(n,{status:200,headers:s}),o=S([r,n]);return o.url=`${t.request.origin}${t.request.path}`,o.clientIdentifier=t.clientIdentifier,o.identifier=t.request.identifier,void A(e.source.id,o).then((e=>{e&&x(i.subscriptionKey,i.clientIdentifier,i.userId)}))}g(n,(()=>[i]),((e,n)=>{E(e,n,t.request)}),((e,n)=>{E(e,null,t.request,T(n))}))}},v=e=>{const t=l[e.clientIdentifier],n=t?t.subscription.serviceRequestId:void 0;if(t&&n&&(delete t.subscription.serviceRequestId,delete t.subscription.request,0===q(n).length)){const e=c.get(n);c.delete(n),delete f[n],e&&e.abort()}},g=(t,n,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const r=(new Date).getTime();Promise.race([fetch(m(t),{signal:null===(e=c.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),y(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,o=n();0!==o.length&&(w("end",o,(new Date).toISOString(),t,s,e[0].headers.get("Content-Type"),(new Date).getTime()-r),i(o,e))})).catch((e=>{const t=n();0!==t.length&&s(t,e)}))}))},y=(e,t)=>new Promise(((n,i)=>{const s=setTimeout((()=>{c.delete(e),clearTimeout(s),i(new Error("Request timeout"))}),1e3*t)})),q=e=>Object.values(l).filter((t=>void 0!==t&&t.subscription.serviceRequestId===e)),I=(e,t)=>{delete f[t],e.forEach((e=>{delete e.subscription.request,delete e.subscription.serviceRequestId}))},m=e=>{let t;const n=e.queryParameters;let i=e.path;if(e.headers){t={};for(const[n,i]of Object.entries(e.headers))t[n]=i}return n&&0!==Object.keys(n).length&&(i=`${i}?${W(n)}`),new Request(`${e.origin}${i}`,{method:e.method,headers:t,redirect:"follow"})},j=e=>{var t,n,i,s;const r=l[e.clientIdentifier],u=R(r.subscription.previousTimetoken,e),c=o.createUUID(),a=Object.assign({},e.request);if(u.length>1){const s=F(u,e);if(s)return s;const o=(null!==(t=d[r.subscriptionKey])&&void 0!==t?t:{})[r.userId],l={},p=new Set(r.subscription.channelGroups),h=new Set(r.subscription.channels);o&&r.subscription.objectsWithState.length&&r.subscription.objectsWithState.forEach((e=>{const t=o[e];t&&(l[e]=t)}));for(const e of u){const{subscription:t}=e;t.serviceRequestId||(t.channelGroups.forEach(p.add,p),t.channels.forEach(h.add,h),t.serviceRequestId=c,o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!l[e]&&(l[e]=t)})))}const b=null!==(n=f[c])&&void 0!==n?n:f[c]={requestId:c,timetoken:null!==(i=a.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(h.size){b.channels=Array.from(h).sort();const e=a.path.split("/");e[4]=b.channels.join(","),a.path=e.join("/")}p.size&&(b.channelGroups=Array.from(p).sort(),a.queryParameters["channel-group"]=b.channelGroups.join(",")),Object.keys(l).length&&(a.queryParameters.state=JSON.stringify(l))}else f[c]={requestId:c,timetoken:null!==(s=a.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:r.subscription.channelGroups,channels:r.subscription.channels};return r.subscription.serviceRequestId=c,a.identifier=c,a},O=e=>{const t=l[e.clientIdentifier],n=$(e);let i=P(e.request),s=G(e.request);const r=Object.assign({},e.request);if(t){const{subscription:e}=t;s.length&&(e.channels=e.channels.filter((e=>!s.includes(e)))),i.length&&(e.channelGroups=e.channelGroups.filter((e=>!i.includes(e))))}for(const t of n)t.clientIdentifier!==e.clientIdentifier&&(s.length&&(s=s.filter((e=>!t.subscription.channels.includes(e)))),i.length&&(i=i.filter((e=>!t.subscription.channelGroups.includes(e)))));if(0!==s.length||0!==i.length){if(s.length){const e=r.path.split("/");e[4]=s.join(","),r.path=e.join("/")}return i.length&&(r.queryParameters["channel-group"]=i.join(",")),r}},A=(e,t)=>self.clients.get(e).then((e=>!!e&&(e.postMessage(t),!0))),w=(e,t,n,i,s,r,o)=>{var c;if(0===t.length)return;const l=null!==(c=p[t[0].subscriptionKey])&&void 0!==c?c:{};let a;if("start"===e)a={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;s&&r&&(-1!==r.indexOf("text/javascript")||-1!==r.indexOf("application/json")||-1!==r.indexOf("text/plain")||-1!==r.indexOf("text/html"))&&(e=u.decode(s)),a={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}t.forEach((e=>{const t=l[e.clientIdentifier],{request:n}=e.subscription,s=null!=n?n:i;e.logVerbosity&&t&&s&&A(t,Object.assign(Object.assign({},a),{clientIdentifier:e.clientIdentifier,url:`${s.origin}${s.path}`,query:s.queryParameters})).then((t=>{t&&x(e.subscriptionKey,e.clientIdentifier,e.userId)}))}))},E=(e,t,n,i)=>{var s;if(0===e.length)return;if(!i&&!t)return;const r=null!==(s=p[e[0].subscriptionKey])&&void 0!==s?s:{};!i&&t&&(i=t[0].status>=400?T(void 0,t):S(t)),e.forEach((e=>{const t=r[e.clientIdentifier],{request:s}=e.subscription,o=null!=s?s:n;t&&o&&A(t,Object.assign(Object.assign({},i),{clientIdentifier:e.clientIdentifier,identifier:o.identifier,url:`${o.origin}${o.path}`})).then((t=>{t&&x(e.subscriptionKey,e.clientIdentifier,e.userId)}))}))},S=e=>{var t;const[n,i]=e,s=i.byteLength>0?i:void 0,r=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),u={};return n.headers.forEach(((e,t)=>u[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:r,contentType:o,headers:u,status:n.status,body:s}}},T=(e,t)=>{if(t)return Object.assign(Object.assign({},S(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",i="Unknown error",s="Error";return e&&e instanceof Error&&(i=e.message,s=e.name),"AbortError"===s?(i="Request aborted",n="ABORTED"):"Request timeout"===i&&(n="TIMEOUT"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:s,type:n,message:i}}},k=e=>{var t,n,i,s,r,o,u,c,f,h,b,v,g,y,q,I,m,j,O,A,w,E,S,T,k,x,K,F,R,$;const U=e.data,{clientIdentifier:W}=U,C=U.request.queryParameters;let D=l[W];if(D){const e=null!==(b=C["channel-group"])&&void 0!==b?b:"",t=null!==(v=C.state)&&void 0!==v?v:"";if(D.subscription.filterExpression=null!==(g=C["filter-expr"])&&void 0!==g?g:"",D.subscription.previousTimetoken=D.subscription.timetoken,D.subscription.timetoken=null!==(y=C.tt)&&void 0!==y?y:"0",D.subscription.request=U.request,D.authKey=null!==(q=C.auth)&&void 0!==q?q:"",D.userId=C.uuid,D.subscription.path!==U.request.path&&(D.subscription.path=U.request.path,D.subscription.channels=G(U.request)),D.subscription.channelGroupQuery!==e&&(D.subscription.channelGroupQuery=e,D.subscription.channelGroups=P(U.request)),t.length>0){const e=JSON.parse(t),n=null!==(m=(x=null!==(I=d[k=D.subscriptionKey])&&void 0!==I?I:d[k]={})[K=D.userId])&&void 0!==m?m:x[K]={};Object.entries(e).forEach((([e,t])=>n[e]=t));for(const t of D.subscription.objectsWithState)e[t]||delete n[t];D.subscription.objectsWithState=Object.keys(e)}else if(D.subscription.objectsWithState.length){const e=null!==(O=(R=null!==(j=d[F=D.subscriptionKey])&&void 0!==j?j:d[F]={})[$=D.userId])&&void 0!==O?O:R[$]={};for(const t of D.subscription.objectsWithState)delete e[t];D.subscription.objectsWithState=[]}}else{const b=!U.request.path.startsWith("/v2/subscribe"),v=b?"":null!==(t=C["channel-group"])&&void 0!==t?t:"",g=b?"":null!==(n=C.state)&&void 0!==n?n:"";if(D=l[W]={clientIdentifier:W,subscriptionKey:U.subscriptionKey,userId:C.uuid,authKey:null!==(i=C.auth)&&void 0!==i?i:"",logVerbosity:U.logVerbosity,subscription:{path:b?"":U.request.path,channelGroupQuery:b?"":v,channels:b?[]:G(U.request),channelGroups:b?[]:P(U.request),previousTimetoken:b?"0":null!==(s=C.tt)&&void 0!==s?s:"0",timetoken:b?"0":null!==(r=C.tt)&&void 0!==r?r:"0",request:b?void 0:U.request,objectsWithState:[],filterExpression:b?void 0:null!==(o=C["filter-expr"])&&void 0!==o?o:""}},!b&&g.length>0){const e=JSON.parse(g),t=null!==(c=(w=null!==(u=d[A=D.subscriptionKey])&&void 0!==u?u:d[A]={})[E=D.userId])&&void 0!==c?c:w[E]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),D.subscription.objectsWithState=Object.keys(e)}const y=null!==(f=a[S=U.subscriptionKey])&&void 0!==f?f:a[S]=[];y.every((e=>e.clientIdentifier!==W))&&y.push(D),(null!==(h=p[T=U.subscriptionKey])&&void 0!==h?h:p[T]={})[W]=e.source.id}},x=(e,t,n)=>{delete l[t];let i=a[e];if(i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?a[e]=i:delete a[e],0===i.length&&delete d[e],i.length>0){const n=p[e];n&&(delete n[t],0===Object.keys(n).length&&delete p[e])}else delete p[e]},K=e=>{if(!(e.source&&e.source instanceof Client))return!1;const t=e.data,{clientIdentifier:n,subscriptionKey:i,logVerbosity:s}=t;return void 0!==s&&"boolean"==typeof s&&(!(!n||"string"!=typeof n)&&!(!i||"string"!=typeof i))},F=(e,t)=>{var n;const i=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",s=t.request.path;let r,o;for(const n of e){const{subscription:e}=n;if(e.serviceRequestId){if(e.path===s&&e.channelGroupQuery===i)return e.serviceRequestId;{const n=f[e.serviceRequestId];if(r||(r=P(t.request)),o||(o=G(t.request)),o.length&&!U(n.channels,o))continue;if(r.length&&!U(n.channelGroups,r))continue;return e.serviceRequestId}}}},R=(e,t)=>{var n,i,s;const r=t.request.queryParameters,o=null!==(n=r["filter-expr"])&&void 0!==n?n:"",u=null!==(i=r.auth)&&void 0!==i?i:"",c=r.uuid;return(null!==(s=a[t.subscriptionKey])&&void 0!==s?s:[]).filter((t=>t.userId===c&&t.authKey===u&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.previousTimetoken||t.subscription.previousTimetoken===e)))},$=e=>{var t,n;const i=e.request.queryParameters,s=null!==(t=i.auth)&&void 0!==t?t:"",r=i.uuid;return(null!==(n=a[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===r&&e.authKey===s))},G=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},P=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},U=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},W=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${C(e)}`)).join("&"):`${t}=${C(n)}`})).join("&"),C=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/karma/web.config.js b/karma/web.config.cjs similarity index 100% rename from karma/web.config.js rename to karma/web.config.cjs diff --git a/lib/cbor/common.js b/lib/cbor/common.js index 0a97069c6..29a9f2a2c 100644 --- a/lib/cbor/common.js +++ b/lib/cbor/common.js @@ -1,25 +1,19 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var default_1 = /** @class */ (function () { - function default_1(decode, base64ToBinary) { - this._base64ToBinary = base64ToBinary; - this._decode = decode; +class Cbor { + constructor(decode, base64ToBinary) { + this.decode = decode; + this.base64ToBinary = base64ToBinary; } - default_1.prototype.decodeToken = function (tokenString) { - var padding = ''; - if (tokenString.length % 4 === 3) { + decodeToken(tokenString) { + let padding = ''; + if (tokenString.length % 4 === 3) padding = '='; - } - else if (tokenString.length % 4 === 2) { + else if (tokenString.length % 4 === 2) padding = '=='; - } - var cleaned = tokenString.replace(/-/gi, '+').replace(/_/gi, '/') + padding; - var result = this._decode(this._base64ToBinary(cleaned)); - if (typeof result === 'object') { - return result; - } - return undefined; - }; - return default_1; -}()); -exports.default = default_1; + const cleaned = tokenString.replace(/-/gi, '+').replace(/_/gi, '/') + padding; + const result = this.decode(this.base64ToBinary(cleaned)); + return typeof result === 'object' ? result : undefined; + } +} +exports.default = Cbor; diff --git a/lib/core/components/abort_signal.js b/lib/core/components/abort_signal.js index acee414dd..6d51ec546 100644 --- a/lib/core/components/abort_signal.js +++ b/lib/core/components/abort_signal.js @@ -1,57 +1,31 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); exports.AbortSignal = exports.AbortError = void 0; -var subject_1 = require("./subject"); -var AbortError = /** @class */ (function (_super) { - __extends(AbortError, _super); - function AbortError() { - var _newTarget = this.constructor; - var _this = _super.call(this, 'The operation was aborted.') || this; - _this.name = 'AbortError'; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; +const subject_1 = require("./subject"); +class AbortError extends Error { + constructor() { + super('The operation was aborted.'); + this.name = 'AbortError'; + Object.setPrototypeOf(this, new.target.prototype); } - return AbortError; -}(Error)); +} exports.AbortError = AbortError; -var AbortSignal = /** @class */ (function (_super) { - __extends(AbortSignal, _super); - function AbortSignal() { - var _this = _super !== null && _super.apply(this, arguments) || this; - _this._aborted = false; - return _this; +class AbortSignal extends subject_1.Subject { + constructor() { + super(...arguments); + this._aborted = false; } - Object.defineProperty(AbortSignal.prototype, "aborted", { - get: function () { - return this._aborted; - }, - enumerable: false, - configurable: true - }); - AbortSignal.prototype.throwIfAborted = function () { + get aborted() { + return this._aborted; + } + throwIfAborted() { if (this._aborted) { throw new AbortError(); } - }; - AbortSignal.prototype.abort = function () { + } + abort() { this._aborted = true; this.notify(new AbortError()); - }; - return AbortSignal; -}(subject_1.Subject)); + } +} exports.AbortSignal = AbortSignal; diff --git a/lib/core/components/base64_codec.js b/lib/core/components/base64_codec.js index 157dd3b04..4bac838e0 100644 --- a/lib/core/components/base64_codec.js +++ b/lib/core/components/base64_codec.js @@ -1,45 +1,30 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.encode = exports.decode = void 0; -var BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; -/** - * Decode a Base64 encoded string. - * - * @param paddedInput Base64 string with padding - * @returns ArrayBuffer with decoded data - */ +const BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; function decode(paddedInput) { - // Remove up to last two equal signs. - var input = paddedInput.replace(/==?$/, ''); - var outputLength = Math.floor((input.length / 4) * 3); - // Prepare output buffer. - var data = new ArrayBuffer(outputLength); - var view = new Uint8Array(data); - var cursor = 0; - /** - * Returns the next integer representation of a sixtet of bytes from the input - * @returns sixtet of bytes - */ + const input = paddedInput.replace(/==?$/, ''); + const outputLength = Math.floor((input.length / 4) * 3); + const data = new ArrayBuffer(outputLength); + const view = new Uint8Array(data); + let cursor = 0; function nextSixtet() { - var char = input.charAt(cursor++); - var index = BASE64_CHARMAP.indexOf(char); + const char = input.charAt(cursor++); + const index = BASE64_CHARMAP.indexOf(char); if (index === -1) { - throw new Error("Illegal character at ".concat(cursor, ": ").concat(input.charAt(cursor - 1))); + throw new Error(`Illegal character at ${cursor}: ${input.charAt(cursor - 1)}`); } return index; } - for (var i = 0; i < outputLength; i += 3) { - // Obtain four sixtets - var sx1 = nextSixtet(); - var sx2 = nextSixtet(); - var sx3 = nextSixtet(); - var sx4 = nextSixtet(); - // Encode them as three octets - var oc1 = ((sx1 & 63) << 2) | (sx2 >> 4); - var oc2 = ((sx2 & 15) << 4) | (sx3 >> 2); - var oc3 = ((sx3 & 3) << 6) | (sx4 >> 0); + for (let i = 0; i < outputLength; i += 3) { + const sx1 = nextSixtet(); + const sx2 = nextSixtet(); + const sx3 = nextSixtet(); + const sx4 = nextSixtet(); + const oc1 = ((sx1 & 0b00111111) << 2) | (sx2 >> 4); + const oc2 = ((sx2 & 0b00001111) << 4) | (sx3 >> 2); + const oc3 = ((sx3 & 0b00000011) << 6) | (sx4 >> 0); view[i] = oc1; - // Skip padding bytes. if (sx3 != 64) view[i + 1] = oc2; if (sx4 != 64) @@ -49,40 +34,33 @@ function decode(paddedInput) { } exports.decode = decode; function encode(input) { - var base64 = ''; - var encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - var bytes = new Uint8Array(input); - var byteLength = bytes.byteLength; - var byteRemainder = byteLength % 3; - var mainLength = byteLength - byteRemainder; - var a, b, c, d; - var chunk; - // Main loop deals with bytes in chunks of 3 - for (var i = 0; i < mainLength; i = i + 3) { - // Combine the three bytes into a single integer + let base64 = ''; + const encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + const bytes = new Uint8Array(input); + const byteLength = bytes.byteLength; + const byteRemainder = byteLength % 3; + const mainLength = byteLength - byteRemainder; + let a, b, c, d; + let chunk; + for (let i = 0; i < mainLength; i = i + 3) { chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; - // Use bitmasks to extract 6-bit segments from the triplet - a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18 - b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12 - c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6 - d = chunk & 63; // 63 = 2^6 - 1 - // Convert the raw binary segments to the appropriate ASCII encoding + a = (chunk & 16515072) >> 18; + b = (chunk & 258048) >> 12; + c = (chunk & 4032) >> 6; + d = chunk & 63; base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]; } - // Deal with the remaining bytes and padding if (byteRemainder == 1) { chunk = bytes[mainLength]; - a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2 - // Set the 4 least significant bits to zero - b = (chunk & 3) << 4; // 3 = 2^2 - 1 + a = (chunk & 252) >> 2; + b = (chunk & 3) << 4; base64 += encodings[a] + encodings[b] + '=='; } else if (byteRemainder == 2) { chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]; - a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10 - b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4 - // Set the 2 least significant bits to zero - c = (chunk & 15) << 2; // 15 = 2^4 - 1 + a = (chunk & 64512) >> 10; + b = (chunk & 1008) >> 4; + c = (chunk & 15) << 2; base64 += encodings[a] + encodings[b] + encodings[c] + '='; } return base64; diff --git a/lib/core/components/config.js b/lib/core/components/config.js deleted file mode 100644 index 0b4c6b105..000000000 --- a/lib/core/components/config.js +++ /dev/null @@ -1,209 +0,0 @@ -"use strict"; -/* */ -/* global location */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var uuid_1 = __importDefault(require("./uuid")); -var PRESENCE_TIMEOUT_MINIMUM = 20; -var PRESENCE_TIMEOUT_DEFAULT = 300; -var makeDefaultOrigins = function () { return Array.from({ length: 20 }, function (_, i) { return "ps".concat(i + 1, ".pndsn.com"); }); }; -var default_1 = /** @class */ (function () { - function default_1(_a) { - var setup = _a.setup; - var _b, _c, _d, _e; - this._PNSDKSuffix = {}; - this.instanceId = "pn-".concat(uuid_1.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.cryptoModule = setup.cryptoModule; - this.setFilterExpression(setup.filterExpression); - if (typeof setup.origin !== 'string' && !Array.isArray(setup.origin) && setup.origin !== undefined) { - throw new Error('Origin must be either undefined, a string or a list of strings.'); - } - this.origin = setup.origin || makeDefaultOrigins(); - 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 = (_b = setup.fileUploadPublishRetryLimit) !== null && _b !== void 0 ? _b : 5; - this.useRandomIVs = (_c = setup.useRandomIVs) !== null && _c !== void 0 ? _c : true; - this.enableEventEngine = (_d = setup.enableEventEngine) !== null && _d !== void 0 ? _d : false; - this.maintainPresenceState = (_e = setup.maintainPresenceState) !== null && _e !== void 0 ? _e : true; - // if location config exist and we are in https, force secure to 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; - if (setup.retryConfiguration) { - this._setRetryConfiguration(setup.retryConfiguration); - } - // set timeout to how long a transaction request will wait for the server (default 15 seconds) - this.setTransactionTimeout(setup.transactionalRequestTimeout || 15 * 1000); - // set timeout to how long a subscribe event loop will run (default 310 seconds) - this.setSubscribeTimeout(setup.subscribeRequestTimeout || 310 * 1000); - // set config on beacon (https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon) usage - this.setSendBeaconConfig(setup.useSendBeacon || true); - // how long the SDK will report the client to be alive before issuing a timeout - if (setup.presenceTimeout) { - this.setPresenceTimeout(setup.presenceTimeout); - } - else { - this._presenceTimeout = PRESENCE_TIMEOUT_DEFAULT; - } - if (setup.heartbeatInterval != null) { - this.setHeartbeatInterval(setup.heartbeatInterval); - } - if (typeof setup.userId === 'string') { - if (typeof setup.uuid === 'string') { - throw new Error('Only one of the following configuration options has to be provided: `uuid` or `userId`'); - } - this.setUserId(setup.userId); - } - else { - if (typeof setup.uuid !== 'string') { - throw new Error('One of the following configuration options has to be provided: `uuid` or `userId`'); - } - this.setUUID(setup.uuid); - } - this.setCipherKey(setup.cipherKey, setup); - } - // exposed setters - default_1.prototype.getAuthKey = function () { - return this.authKey; - }; - default_1.prototype.setAuthKey = function (val) { - this.authKey = val; - return this; - }; - default_1.prototype.setCipherKey = function (val, setup, modules) { - var _a; - this.cipherKey = val; - if (this.cipherKey) { - this.cryptoModule = - (_a = setup.cryptoModule) !== null && _a !== void 0 ? _a : setup.initCryptoModule({ cipherKey: this.cipherKey, useRandomIVs: this.useRandomIVs }); - if (modules) - modules.cryptoModule = this.cryptoModule; - } - return this; - }; - default_1.prototype.getUUID = function () { - return this.UUID; - }; - default_1.prototype.setUUID = function (val) { - if (!val || typeof val !== 'string' || val.trim().length === 0) { - throw new Error('Missing uuid parameter. Provide a valid string uuid'); - } - this.UUID = val; - return this; - }; - default_1.prototype.getUserId = function () { - return this.UUID; - }; - default_1.prototype.setUserId = function (value) { - if (!value || typeof value !== 'string' || value.trim().length === 0) { - throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); - } - this.UUID = value; - return this; - }; - default_1.prototype.getFilterExpression = function () { - return this.filterExpression; - }; - default_1.prototype.setFilterExpression = function (val) { - this.filterExpression = val; - return this; - }; - default_1.prototype.getPresenceTimeout = function () { - return this._presenceTimeout; - }; - default_1.prototype.setPresenceTimeout = function (val) { - if (val >= PRESENCE_TIMEOUT_MINIMUM) { - this._presenceTimeout = val; - } - else { - this._presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; - // eslint-disable-next-line no-console - console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', this._presenceTimeout); - } - this.setHeartbeatInterval(this._presenceTimeout / 2 - 1); - return this; - }; - default_1.prototype.setProxy = function (proxy) { - this.proxy = proxy; - }; - default_1.prototype.getHeartbeatInterval = function () { - return this._heartbeatInterval; - }; - default_1.prototype.setHeartbeatInterval = function (val) { - this._heartbeatInterval = val; - return this; - }; - // deprecated setters. - default_1.prototype.getSubscribeTimeout = function () { - return this._subscribeRequestTimeout; - }; - default_1.prototype.setSubscribeTimeout = function (val) { - this._subscribeRequestTimeout = val; - return this; - }; - default_1.prototype.getTransactionTimeout = function () { - return this._transactionalRequestTimeout; - }; - default_1.prototype.setTransactionTimeout = function (val) { - this._transactionalRequestTimeout = val; - return this; - }; - default_1.prototype.isSendBeaconEnabled = function () { - return this._useSendBeacon; - }; - default_1.prototype.setSendBeaconConfig = function (val) { - this._useSendBeacon = val; - return this; - }; - default_1.prototype.getVersion = function () { - return '7.6.3'; - }; - default_1.prototype._setRetryConfiguration = function (configuration) { - if (configuration.minimumdelay < 2) { - throw new Error('Minimum delay can not be set less than 2 seconds for retry'); - } - if (configuration.maximumDelay > 150) { - throw new Error('Maximum delay can not be set more than 150 seconds for retry'); - } - if (configuration.maximumDelay && maximumRetry > 6) { - throw new Error('Maximum retry for exponential retry policy can not be more than 6'); - } - else if (configuration.maximumRetry > 10) { - throw new Error('Maximum retry for linear retry policy can not be more than 10'); - } - this.retryConfiguration = configuration; - }; - default_1.prototype._addPnsdkSuffix = function (name, suffix) { - this._PNSDKSuffix[name] = suffix; - }; - default_1.prototype._getPnsdkSuffix = function (separator) { - var _this = this; - return Object.keys(this._PNSDKSuffix).reduce(function (result, key) { return result + separator + _this._PNSDKSuffix[key]; }, ''); - }; - return default_1; -}()); -exports.default = default_1; diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js new file mode 100644 index 000000000..1b564c93b --- /dev/null +++ b/lib/core/components/configuration.js @@ -0,0 +1,125 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.makeConfiguration = void 0; +const uuid_1 = __importDefault(require("./uuid")); +const USE_RANDOM_INITIALIZATION_VECTOR = true; +const makeConfiguration = (base, setupCryptoModule) => { + var _a, _b, _c; + (_a = base.retryConfiguration) === null || _a === void 0 ? void 0 : _a.validate(); + (_b = base.useRandomIVs) !== null && _b !== void 0 ? _b : (base.useRandomIVs = USE_RANDOM_INITIALIZATION_VECTOR); + base.origin = standardOrigin((_c = base.ssl) !== null && _c !== void 0 ? _c : false, base.origin); + const cryptoModule = base.cryptoModule; + if (cryptoModule) + delete base.cryptoModule; + const clientConfiguration = Object.assign(Object.assign({}, base), { _pnsdkSuffix: {}, _instanceId: `pn-${uuid_1.default.createUUID()}`, _cryptoModule: undefined, _cipherKey: undefined, _setupCryptoModule: setupCryptoModule, get instanceId() { + if (this.useInstanceId) + return this._instanceId; + return undefined; + }, + getUserId() { + return this.userId; + }, + setUserId(value) { + if (!value || typeof value !== 'string' || value.trim().length === 0) + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); + this.userId = value; + }, + getAuthKey() { + return this.authKey; + }, + setAuthKey(authKey) { + this.authKey = authKey; + }, + getFilterExpression() { + return this.filterExpression; + }, + setFilterExpression(expression) { + this.filterExpression = expression; + }, + getCipherKey() { + return this._cipherKey; + }, + setCipherKey(key) { + this._cipherKey = key; + if (!key && this._cryptoModule) { + this._cryptoModule = undefined; + return; + } + else if (!key || !this._setupCryptoModule) + return; + this._cryptoModule = this._setupCryptoModule({ + cipherKey: key, + useRandomIVs: base.useRandomIVs, + customEncrypt: this.getCustomEncrypt(), + customDecrypt: this.getCustomDecrypt(), + }); + }, + getCryptoModule() { + return this._cryptoModule; + }, + getUseRandomIVs() { + return base.useRandomIVs; + }, + setPresenceTimeout(value) { + this.heartbeatInterval = value / 2 - 1; + this.presenceTimeout = value; + }, + getPresenceTimeout() { + return this.presenceTimeout; + }, + getHeartbeatInterval() { + return this.heartbeatInterval; + }, + setHeartbeatInterval(interval) { + this.heartbeatInterval = interval; + }, + getTransactionTimeout() { + return this.transactionalRequestTimeout; + }, + getSubscribeTimeout() { + return this.subscribeRequestTimeout; + }, + get PubNubFile() { + return base.PubNubFile; + }, + get version() { + return '7.6.3'; + }, + getVersion() { + return this.version; + }, + _addPnsdkSuffix(name, suffix) { + this._pnsdkSuffix[name] = `${suffix}`; + }, + _getPnsdkSuffix(separator) { + const sdk = Object.values(this._pnsdkSuffix).join(separator); + return sdk.length > 0 ? separator + sdk : ''; + }, + getUUID() { + return this.getUserId(); + }, + setUUID(value) { + this.setUserId(value); + }, + getCustomEncrypt() { + return base.customEncrypt; + }, + getCustomDecrypt() { + return base.customDecrypt; + } }); + if (base.cipherKey) + clientConfiguration.setCipherKey(base.cipherKey); + else if (cryptoModule) + clientConfiguration._cryptoModule = cryptoModule; + return clientConfiguration; +}; +exports.makeConfiguration = makeConfiguration; +const standardOrigin = (secure, origin) => { + const protocol = secure ? 'https://' : 'http://'; + if (typeof origin === 'string') + return `${protocol}${origin}`; + return `${protocol}${origin[Math.floor(Math.random() * origin.length)]}`; +}; diff --git a/lib/core/components/cryptography/hmac-sha256.js b/lib/core/components/cryptography/hmac-sha256.js index 4b8616de3..7f5e5716a 100644 --- a/lib/core/components/cryptography/hmac-sha256.js +++ b/lib/core/components/cryptography/hmac-sha256.js @@ -1,11 +1,4 @@ "use strict"; -/*eslint-disable */ -/* - CryptoJS v3.1.2 - code.google.com/p/crypto-js - (c) 2009-2013 by Jeff Mott. All rights reserved. - code.google.com/p/crypto-js/wiki/License - */ var CryptoJS = CryptoJS || (function (h, s) { var f = {}, g = (f.lib = {}), q = function () { }, m = (g.Base = { @@ -177,7 +170,6 @@ var CryptoJS = CryptoJS || var t = (f.algo = {}); return f; })(Math); -// SHA256 (function (h) { for (var s = CryptoJS, f = s.lib, g = f.WordArray, q = f.Hasher, f = s.algo, m = [], r = [], l = function (a) { return (4294967296 * (a - (a | 0))) | 0; @@ -256,7 +248,6 @@ var CryptoJS = CryptoJS || s.SHA256 = q._createHelper(f); s.HmacSHA256 = q._createHmacHelper(f); })(Math); -// HMAC SHA256 (function () { var h = CryptoJS, s = h.enc.Utf8; h.algo.HMAC = h.lib.Base.extend({ @@ -288,7 +279,6 @@ var CryptoJS = CryptoJS || }, }); })(); -// Base64 (function () { var u = CryptoJS, p = u.lib.WordArray; u.enc.Base64 = { @@ -320,7 +310,6 @@ var CryptoJS = CryptoJS || _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', }; })(); -// BlockCipher (function (u) { function p(b, n, a, c, e, j, k) { b = b + ((n & a) | (~n & c)) + e + k; @@ -401,7 +390,6 @@ var CryptoJS = CryptoJS || return s.create(p).compute(d, l); }; })(); -// Cipher CryptoJS.lib.Cipher || (function (u) { var p = CryptoJS, d = p.lib, l = d.Base, s = d.WordArray, t = d.BufferedBlockAlgorithm, r = p.enc.Base64, w = p.algo.EvpKDF, v = (d.Cipher = t.extend({ @@ -598,7 +586,6 @@ CryptoJS.lib.Cipher || }, })); })(); -// AES (function () { for (var u = CryptoJS, p = u.lib.BlockCipher, d = u.algo, l = [], s = [], t = [], r = [], w = [], v = [], b = [], x = [], q = [], n = [], a = [], c = 0; 256 > c; c++) a[c] = 128 > c ? c << 1 : (c << 1) ^ 283; @@ -669,7 +656,6 @@ CryptoJS.lib.Cipher || })); u.AES = p._createHelper(d); })(); -// Mode ECB CryptoJS.mode.ECB = (function () { var ECB = CryptoJS.lib.BlockCipherMode.extend(); ECB.Encryptor = ECB.extend({ diff --git a/lib/core/components/cryptography/index.js b/lib/core/components/cryptography/index.js index 19c58e51e..434020616 100644 --- a/lib/core/components/cryptography/index.js +++ b/lib/core/components/cryptography/index.js @@ -3,149 +3,136 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var base64_codec_1 = require("../base64_codec"); -var hmac_sha256_1 = __importDefault(require("./hmac-sha256")); +const base64_codec_1 = require("../base64_codec"); +const hmac_sha256_1 = __importDefault(require("./hmac-sha256")); function bufferToWordArray(b) { - var wa = []; - var i; + const wa = []; + let i; for (i = 0; i < b.length; i += 1) { wa[(i / 4) | 0] |= b[i] << (24 - 8 * i); } return hmac_sha256_1.default.lib.WordArray.create(wa, b.length); } -var default_1 = /** @class */ (function () { - function default_1(_a) { - var config = _a.config; - this._config = config; - this._iv = '0123456789012345'; - this._allowedKeyEncodings = ['hex', 'utf8', 'base64', 'binary']; - this._allowedKeyLengths = [128, 256]; - this._allowedModes = ['ecb', 'cbc']; - this._defaultOptions = { +class default_1 { + constructor(configuration) { + this.configuration = configuration; + 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', }; } - default_1.prototype.HMACSHA256 = function (data) { - var hash = hmac_sha256_1.default.HmacSHA256(data, this._config.secretKey); + HMACSHA256(data) { + const hash = hmac_sha256_1.default.HmacSHA256(data, this.configuration.secretKey); return hash.toString(hmac_sha256_1.default.enc.Base64); - }; - default_1.prototype.SHA256 = function (s) { - return hmac_sha256_1.default.SHA256(s).toString(hmac_sha256_1.default.enc.Hex); - }; - default_1.prototype._parseOptions = function (incomingOptions) { - // Defaults - 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; - // Validation - 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; - }; - default_1.prototype._decodeKey = function (key, options) { - if (options.keyEncoding === 'base64') { - return hmac_sha256_1.default.enc.Base64.parse(key); - } - if (options.keyEncoding === 'hex') { - return hmac_sha256_1.default.enc.Hex.parse(key); - } - return key; - }; - default_1.prototype._getPaddedKey = function (key, options) { - key = this._decodeKey(key, options); - if (options.encryptKey) { - return hmac_sha256_1.default.enc.Utf8.parse(this.SHA256(key).slice(0, 32)); - } - return key; - }; - default_1.prototype._getMode = function (options) { - if (options.mode === 'ecb') { - return hmac_sha256_1.default.mode.ECB; - } - return hmac_sha256_1.default.mode.CBC; - }; - default_1.prototype._getIV = function (options) { - return options.mode === 'cbc' ? hmac_sha256_1.default.enc.Utf8.parse(this._iv) : null; - }; - default_1.prototype._getRandomIV = function () { - return hmac_sha256_1.default.lib.WordArray.random(16); - }; - default_1.prototype.encrypt = function (data, customCipherKey, options) { - if (this._config.customEncrypt) { - return this._config.customEncrypt(data); - } + } + SHA256(data) { + return hmac_sha256_1.default.SHA256(data).toString(hmac_sha256_1.default.enc.Hex); + } + encrypt(data, customCipherKey, options) { + if (this.configuration.customEncrypt) + return this.configuration.customEncrypt(data); return this.pnEncrypt(data, customCipherKey, options); - }; - default_1.prototype.decrypt = function (data, customCipherKey, options) { - if (this._config.customDecrypt) { - return this._config.customDecrypt(data); - } + } + decrypt(data, customCipherKey, options) { + if (this.configuration.customDecrypt) + return this.configuration.customDecrypt(data); return this.pnDecrypt(data, customCipherKey, options); - }; - default_1.prototype.pnEncrypt = function (data, customCipherKey, options) { - if (!customCipherKey && !this._config.cipherKey) + } + pnEncrypt(data, customCipherKey, options) { + const decidedCipherKey = customCipherKey !== null && customCipherKey !== void 0 ? customCipherKey : this.configuration.cipherKey; + if (!decidedCipherKey) 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 = hmac_sha256_1.default.AES.encrypt(data, cipherKey, { iv: waIv, mode: mode }).ciphertext; + options = this.parseOptions(options); + const mode = this.getMode(options); + const cipherKey = this.getPaddedKey(decidedCipherKey, options); + if (this.configuration.useRandomIVs) { + const waIv = this.getRandomIV(); + const waPayload = hmac_sha256_1.default.AES.encrypt(data, cipherKey, { iv: waIv, mode }).ciphertext; return waIv.clone().concat(waPayload.clone()).toString(hmac_sha256_1.default.enc.Base64); } - var iv = this._getIV(options); - var encryptedHexArray = hmac_sha256_1.default.AES.encrypt(data, cipherKey, { iv: iv, mode: mode }).ciphertext; - var base64Encrypted = encryptedHexArray.toString(hmac_sha256_1.default.enc.Base64); + const iv = this.getIV(options); + const encryptedHexArray = hmac_sha256_1.default.AES.encrypt(data, cipherKey, { iv, mode }).ciphertext; + const base64Encrypted = encryptedHexArray.toString(hmac_sha256_1.default.enc.Base64); return base64Encrypted || data; - }; - default_1.prototype.pnDecrypt = function (data, customCipherKey, options) { - if (!customCipherKey && !this._config.cipherKey) + } + pnDecrypt(data, customCipherKey, options) { + const decidedCipherKey = customCipherKey !== null && customCipherKey !== void 0 ? customCipherKey : this.configuration.cipherKey; + if (!decidedCipherKey) 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 = new Uint8ClampedArray((0, base64_codec_1.decode)(data)); - var iv = bufferToWordArray(ciphertext.slice(0, 16)); - var payload = bufferToWordArray(ciphertext.slice(16)); + options = this.parseOptions(options); + const mode = this.getMode(options); + const cipherKey = this.getPaddedKey(decidedCipherKey, options); + if (this.configuration.useRandomIVs) { + const ciphertext = new Uint8ClampedArray((0, base64_codec_1.decode)(data)); + const iv = bufferToWordArray(ciphertext.slice(0, 16)); + const payload = bufferToWordArray(ciphertext.slice(16)); try { - var plainJSON = hmac_sha256_1.default.AES.decrypt({ ciphertext: payload }, cipherKey, { iv: iv, mode: mode }).toString(hmac_sha256_1.default.enc.Utf8); - var plaintext = JSON.parse(plainJSON); - return plaintext; + const plainJSON = hmac_sha256_1.default.AES.decrypt({ ciphertext: payload }, cipherKey, { iv, mode }).toString(hmac_sha256_1.default.enc.Utf8); + return JSON.parse(plainJSON); } catch (e) { return null; } } else { - var iv = this._getIV(options); + const iv = this.getIV(options); try { - var ciphertext = hmac_sha256_1.default.enc.Base64.parse(data); - var plainJSON = hmac_sha256_1.default.AES.decrypt({ ciphertext: ciphertext }, cipherKey, { iv: iv, mode: mode }).toString(hmac_sha256_1.default.enc.Utf8); - var plaintext = JSON.parse(plainJSON); - return plaintext; + const ciphertext = hmac_sha256_1.default.enc.Base64.parse(data); + const plainJSON = hmac_sha256_1.default.AES.decrypt({ ciphertext }, cipherKey, { iv, mode }).toString(hmac_sha256_1.default.enc.Utf8); + return JSON.parse(plainJSON); } catch (e) { return null; } } - }; - return default_1; -}()); + } + parseOptions(incomingOptions) { + var _a, _b, _c, _d; + if (!incomingOptions) + return this.defaultOptions; + const options = { + encryptKey: (_a = incomingOptions.encryptKey) !== null && _a !== void 0 ? _a : this.defaultOptions.encryptKey, + keyEncoding: (_b = incomingOptions.keyEncoding) !== null && _b !== void 0 ? _b : this.defaultOptions.keyEncoding, + keyLength: (_c = incomingOptions.keyLength) !== null && _c !== void 0 ? _c : this.defaultOptions.keyLength, + mode: (_d = incomingOptions.mode) !== null && _d !== void 0 ? _d : this.defaultOptions.mode, + }; + if (this.allowedKeyEncodings.indexOf(options.keyEncoding.toLowerCase()) === -1) + options.keyEncoding = this.defaultOptions.keyEncoding; + if (this.allowedKeyLengths.indexOf(options.keyLength) === -1) + options.keyLength = this.defaultOptions.keyLength; + if (this.allowedModes.indexOf(options.mode.toLowerCase()) === -1) + options.mode = this.defaultOptions.mode; + return options; + } + decodeKey(key, options) { + if (options.keyEncoding === 'base64') + return hmac_sha256_1.default.enc.Base64.parse(key); + if (options.keyEncoding === 'hex') + return hmac_sha256_1.default.enc.Hex.parse(key); + return key; + } + getPaddedKey(key, options) { + key = this.decodeKey(key, options); + if (options.encryptKey) + return hmac_sha256_1.default.enc.Utf8.parse(this.SHA256(key).slice(0, 32)); + return key; + } + getMode(options) { + if (options.mode === 'ecb') + return hmac_sha256_1.default.mode.ECB; + return hmac_sha256_1.default.mode.CBC; + } + getIV(options) { + return options.mode === 'cbc' ? hmac_sha256_1.default.enc.Utf8.parse(this.iv) : null; + } + getRandomIV() { + return hmac_sha256_1.default.lib.WordArray.random(16); + } +} exports.default = default_1; diff --git a/lib/core/components/deduping_manager.js b/lib/core/components/deduping_manager.js index 6ae413ad0..0f30833c4 100644 --- a/lib/core/components/deduping_manager.js +++ b/lib/core/components/deduping_manager.js @@ -1,40 +1,37 @@ "use strict"; -/* */ Object.defineProperty(exports, "__esModule", { value: true }); -var hashCode = function (payload) { - var hash = 0; +const hashCode = (payload) => { + let hash = 0; if (payload.length === 0) return hash; - for (var i = 0; i < payload.length; i += 1) { - var character = payload.charCodeAt(i); - hash = (hash << 5) - hash + character; // eslint-disable-line - hash = hash & hash; // eslint-disable-line + for (let i = 0; i < payload.length; i += 1) { + const character = payload.charCodeAt(i); + hash = (hash << 5) - hash + character; + hash = hash & hash; } return hash; }; -var default_1 = /** @class */ (function () { - function default_1(_a) { - var config = _a.config; +class default_1 { + constructor({ config }) { this.hashHistory = []; this._config = config; } - default_1.prototype.getKey = function (message) { - var hashedPayload = hashCode(JSON.stringify(message.payload)).toString(); - var timetoken = message.publishMetaData.publishTimetoken; - return "".concat(timetoken, "-").concat(hashedPayload); - }; - default_1.prototype.isDuplicate = function (message) { + getKey(message) { + const hashedPayload = hashCode(JSON.stringify(message.message)).toString(); + const timetoken = message.timetoken; + return `${timetoken}-${hashedPayload}`; + } + isDuplicate(message) { return this.hashHistory.includes(this.getKey(message)); - }; - default_1.prototype.addEntry = function (message) { + } + addEntry(message) { if (this.hashHistory.length >= this._config.maximumCacheSize) { this.hashHistory.shift(); } this.hashHistory.push(this.getKey(message)); - }; - default_1.prototype.clearHistory = function () { + } + clearHistory() { this.hashHistory = []; - }; - return default_1; -}()); + } +} exports.default = default_1; diff --git a/lib/core/components/endpoint.js b/lib/core/components/endpoint.js deleted file mode 100644 index 6c837275f..000000000 --- a/lib/core/components/endpoint.js +++ /dev/null @@ -1,282 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.signRequest = exports.generatePNSDK = exports.createValidationError = exports.PubNubError = void 0; -var uuid_1 = __importDefault(require("./uuid")); -var utils_1 = __importDefault(require("../utils")); -var operations_1 = __importDefault(require("../constants/operations")); -var categories_1 = __importDefault(require("../constants/categories")); -var PubNubError = /** @class */ (function (_super) { - __extends(PubNubError, _super); - function PubNubError(message, status) { - var _newTarget = this.constructor; - var _this = _super.call(this, message) || this; - _this.name = _this.constructor.name; - _this.status = status; - _this.message = message; - Object.setPrototypeOf(_this, _newTarget.prototype); - return _this; - } - return PubNubError; -}(Error)); -exports.PubNubError = PubNubError; -function createError(errorPayload, type) { - errorPayload.type = type; - errorPayload.error = true; - return errorPayload; -} -function createValidationError(message) { - return createError({ message: message }, 'validationError'); -} -exports.createValidationError = createValidationError; -function decideURL(endpoint, modules, incomingParams) { - if (endpoint.usePost && endpoint.usePost(modules, incomingParams)) { - return endpoint.postURL(modules, incomingParams); - } - if (endpoint.usePatch && endpoint.usePatch(modules, incomingParams)) { - return endpoint.patchURL(modules, incomingParams); - } - if (endpoint.useGetFile && endpoint.useGetFile(modules, incomingParams)) { - return endpoint.getFileURL(modules, incomingParams); - } - return endpoint.getURL(modules, incomingParams); -} -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; -} -exports.generatePNSDK = generatePNSDK; -function getHttpMethod(modules, endpoint, incomingParams) { - if (endpoint.usePost && endpoint.usePost(modules, incomingParams)) { - return 'POST'; - } - if (endpoint.usePatch && endpoint.usePatch(modules, incomingParams)) { - return 'PATCH'; - } - if (endpoint.useDelete && endpoint.useDelete(modules, incomingParams)) { - return 'DELETE'; - } - if (endpoint.useGetFile && endpoint.useGetFile(modules, incomingParams)) { - return 'GETFILE'; - } - 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); - // This is because of a server-side bug, old publish using post should be deprecated - 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_1.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; -} -exports.signRequest = signRequest; -function default_1(modules, endpoint) { - var args = []; - for (var _i = 2; _i < arguments.length; _i++) { - args[_i - 2] = arguments[_i]; - } - var networking = modules.networking, config = modules.config, telemetryManager = modules.telemetryManager, tokenManager = modules.tokenManager; - var requestId = uuid_1.default.createUUID(); - var callback = null; - var promiseComponent = null; - var incomingParams = {}; - if (endpoint.getOperation() === operations_1.default.PNTimeOperation || - endpoint.getOperation() === operations_1.default.PNChannelGroupsOperation) { - callback = args[0]; - } - else { - incomingParams = args[0]; - callback = args[1]; - } - // bridge in Promise support. - if (typeof Promise !== 'undefined' && !callback) { - promiseComponent = utils_1.default.createPromise(); - } - var validationResult = endpoint.validateParams(modules, incomingParams); - if (validationResult) { - if (callback) { - return callback(createValidationError(validationResult)); - } - 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, - abortSignal: typeof endpoint.getAbortSignal === 'function' ? endpoint.getAbortSignal(modules, incomingParams) : null, - }; - outgoingParams.uuid = config.UUID; - outgoingParams.pnsdk = generatePNSDK(config); - // Add telemetry information (if there is any available). - var telemetryLatencies = telemetryManager.operationsLatencyForRequest(); - if (Object.keys(telemetryLatencies).length) { - outgoingParams = __assign(__assign({}, outgoingParams), telemetryLatencies); - } - if (config.useInstanceId) { - outgoingParams.instanceid = config.instanceId; - } - if (config.useRequestId) { - outgoingParams.requestid = requestId; - } - if (endpoint.isAuthSupported()) { - var tokenOrKey = tokenManager.getToken() || config.getAuthKey(); - if (tokenOrKey) { - outgoingParams.auth = tokenOrKey; - } - } - if (config.secretKey) { - signRequest(modules, url, outgoingParams, incomingParams, endpoint); - } - var onResponse = function (status, payload) { - 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; - } - // Stop endpoint latency tracking. - telemetryManager.stopLatencyMeasure(endpoint.getOperation(), requestId); - var responseP = endpoint.handleResponse(modules, payload, incomingParams); - if (typeof (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_1.default.PNSubscribeOperation) { - errorData = { - statusCode: 400, - error: true, - operation: endpoint.getOperation(), - errorData: e, - category: categories_1.default.PNUnknownCategory, - }; - } - callback(errorData, null); - } - else if (promiseComponent) { - promiseComponent.reject(new PubNubError('PubNub call failed, check status for details', e)); - } - }); - }; - // Start endpoint latency tracking. - 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 payload = endpoint.patchPayload(modules, incomingParams); - callInstance = networking.PATCH(outgoingParams, payload, 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_1.default.PNSubscribeOperation) { - return callInstance; - } - if (promiseComponent) { - return promiseComponent.promise; - } -} -exports.default = default_1; diff --git a/lib/core/components/eventEmitter.js b/lib/core/components/eventEmitter.js index c75d9c60d..f843210ca 100644 --- a/lib/core/components/eventEmitter.js +++ b/lib/core/components/eventEmitter.js @@ -1,15 +1,4 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) @@ -22,263 +11,123 @@ var __rest = (this && this.__rest) || function (s, e) { return t; }; Object.defineProperty(exports, "__esModule", { value: true }); -var EventEmitter = /** @class */ (function () { - function EventEmitter(_a) { - var modules = _a.modules, listenerManager = _a.listenerManager, getFileUrl = _a.getFileUrl; - this.modules = modules; +const subscribe_1 = require("../endpoints/subscribe"); +class EventEmitter { + constructor(listenerManager) { this.listenerManager = listenerManager; - this.getFileUrl = getFileUrl; - this._channelListenerMap = new Map(); - this._groupListenerMap = new Map(); - if (modules.cryptoModule) - this._decoder = new TextDecoder(); + this.channelListenerMap = new Map(); + this.groupListenerMap = new Map(); } - EventEmitter.prototype.emitEvent = function (e) { - var channel = e.channel, publishMetaData = e.publishMetaData; - var subscriptionMatch = e.subscriptionMatch; - if (channel === subscriptionMatch) { - subscriptionMatch = null; + emitEvent(event) { + if (event.type === subscribe_1.PubNubEventType.Message) { + this.listenerManager.announceMessage(event.data); + this.announce('message', event.data, event.data.channel, event.data.subscription); } - if (e.channel.endsWith('-pnpres')) { - var announce = {}; - announce.channel = null; - announce.subscription = null; - if (channel) { - announce.channel = channel.substring(0, channel.lastIndexOf('-pnpres')); - } - if (subscriptionMatch) { - announce.subscription = subscriptionMatch.substring(0, subscriptionMatch.lastIndexOf('-pnpres')); - } - announce.action = e.payload.action; - announce.state = e.payload.data; - announce.timetoken = publishMetaData.timetoken; - announce.occupancy = e.payload.occupancy; - announce.uuid = e.payload.uuid; - announce.timestamp = e.payload.timestamp; - if (e.payload.join) { - announce.join = e.payload.join; - } - if (e.payload.leave) { - announce.leave = e.payload.leave; - } - if (e.payload.timeout) { - announce.timeout = e.payload.timeout; - } - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - this.listenerManager.announcePresence(announce); - this._announce('presence', announce, announce.channel, announce.subscription); + else if (event.type === subscribe_1.PubNubEventType.Signal) { + this.listenerManager.announceSignal(event.data); + this.announce('signal', event.data, event.data.channel, event.data.subscription); } - else if (e.messageType === 1) { - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - announce.message = e.payload; - this.listenerManager.announceSignal(announce); - this._announce('signal', announce, announce.channel, announce.subscription); + else if (event.type === subscribe_1.PubNubEventType.Presence) { + this.listenerManager.announcePresence(event.data); + this.announce('presence', event.data, event.data.channel, event.data.subscription); } - else if (e.messageType === 2) { - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - announce.message = { - event: e.payload.event, - type: e.payload.type, - data: e.payload.data, - }; - this.listenerManager.announceObjects(announce); - this._announce('objects', announce, announce.channel, announce.subscription); - if (e.payload.type === 'uuid') { - var eventData = this._renameChannelField(announce); - var userEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'user' }) }); + else if (event.type === subscribe_1.PubNubEventType.AppContext) { + const { data: objectEvent } = event; + const { message: object } = objectEvent; + this.listenerManager.announceObjects(objectEvent); + this.announce('objects', objectEvent, objectEvent.channel, objectEvent.subscription); + if (object.type === 'uuid') { + const { message, channel } = objectEvent, restEvent = __rest(objectEvent, ["message", "channel"]); + const { event, type } = object, restObject = __rest(object, ["event", "type"]); + const userEvent = Object.assign(Object.assign({}, restEvent), { spaceId: channel, message: Object.assign(Object.assign({}, restObject), { event: event === 'set' ? 'updated' : 'removed', type: 'user' }) }); this.listenerManager.announceUser(userEvent); - this._announce('user', userEvent, announce.channel, announce.subscription); + this.announce('user', userEvent, userEvent.spaceId, userEvent.subscription); } - else if (e.payload.type === 'channel') { - var eventData = this._renameChannelField(announce); - var spaceEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), type: 'space' }) }); + else if (object.type === 'channel') { + const { message, channel } = objectEvent, restEvent = __rest(objectEvent, ["message", "channel"]); + const { event, type } = object, restObject = __rest(object, ["event", "type"]); + const spaceEvent = Object.assign(Object.assign({}, restEvent), { spaceId: channel, message: Object.assign(Object.assign({}, restObject), { event: event === 'set' ? 'updated' : 'removed', type: 'space' }) }); this.listenerManager.announceSpace(spaceEvent); - this._announce('space', spaceEvent, announce.channel, announce.subscription); + this.announce('space', spaceEvent, spaceEvent.spaceId, spaceEvent.subscription); } - else if (e.payload.type === 'membership') { - var eventData = this._renameChannelField(announce); - var _a = eventData.message.data, user = _a.uuid, space = _a.channel, membershipData = __rest(_a, ["uuid", "channel"]); - membershipData.user = user; - membershipData.space = space; - var membershipEvent = __assign(__assign({}, eventData), { message: __assign(__assign({}, eventData.message), { event: this._renameEvent(eventData.message.event), data: membershipData }) }); + else if (object.type === 'membership') { + const { message, channel } = objectEvent, restEvent = __rest(objectEvent, ["message", "channel"]); + const { event, data } = object, restObject = __rest(object, ["event", "data"]); + const { uuid, channel: channelMeta } = data, restData = __rest(data, ["uuid", "channel"]); + const membershipEvent = Object.assign(Object.assign({}, restEvent), { spaceId: channel, message: Object.assign(Object.assign({}, restObject), { event: event === 'set' ? 'updated' : 'removed', data: Object.assign(Object.assign({}, restData), { user: uuid, space: channelMeta }) }) }); this.listenerManager.announceMembership(membershipEvent); - this._announce('membership', membershipEvent, announce.channel, announce.subscription); + this.announce('membership', membershipEvent, membershipEvent.spaceId, membershipEvent.subscription); } } - else if (e.messageType === 3) { - var announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - announce.data = { - messageTimetoken: e.payload.data.messageTimetoken, - actionTimetoken: e.payload.data.actionTimetoken, - type: e.payload.data.type, - uuid: e.issuingClientId, - value: e.payload.data.value, - }; - announce.event = e.payload.event; - this.listenerManager.announceMessageAction(announce); - this._announce('messageAction', announce, announce.channel, announce.subscription); + else if (event.type === subscribe_1.PubNubEventType.MessageAction) { + this.listenerManager.announceMessageAction(event.data); + this.announce('messageAction', event.data, event.data.channel, event.data.subscription); } - else if (e.messageType === 4) { - var announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - var msgPayload = e.payload; - if (this.modules.cryptoModule) { - var decryptedPayload = void 0; - try { - var decryptedData = this.modules.cryptoModule.decrypt(e.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData; - } - catch (e) { - decryptedPayload = null; - announce.error = "Error while decrypting message content: ".concat(e.message); - } - if (decryptedPayload !== null) { - msgPayload = decryptedPayload; - } - } - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - announce.message = msgPayload.message; - announce.file = { - id: msgPayload.file.id, - name: msgPayload.file.name, - url: this.getFileUrl({ - id: msgPayload.file.id, - name: msgPayload.file.name, - channel: channel, - }), - }; - this.listenerManager.announceFile(announce); - this._announce('file', announce, announce.channel, announce.subscription); - } - else { - var announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - if (this.modules.cryptoModule) { - var decryptedPayload = void 0; - try { - var decryptedData = this.modules.cryptoModule.decrypt(e.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData; - } - catch (e) { - decryptedPayload = null; - announce.error = "Error while decrypting message content: ".concat(e.message); - } - if (decryptedPayload != null) { - announce.message = decryptedPayload; - } - else { - announce.message = e.payload; - } - } - else { - announce.message = e.payload; - } - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - this.listenerManager.announceMessage(announce); - this._announce('message', announce, announce.channel, announce.subscription); + else if (event.type === subscribe_1.PubNubEventType.Files) { + this.listenerManager.announceFile(event.data); + this.announce('file', event.data, event.data.channel, event.data.subscription); } - }; - EventEmitter.prototype.addListener = function (l, channels, groups) { - var _this = this; + } + addListener(listener, channels, groups) { if (!(channels && groups)) { - this.listenerManager.addListener(l); + this.listenerManager.addListener(listener); } else { - channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { - if (_this._channelListenerMap[c]) { - if (!_this._channelListenerMap[c].includes(l)) - _this._channelListenerMap[c].push(l); - } - else { - _this._channelListenerMap[c] = [l]; + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + if (this.channelListenerMap.has(channel)) { + const channelListeners = this.channelListenerMap.get(channel); + if (!channelListeners.includes(listener)) + channelListeners.push(listener); } + else + this.channelListenerMap.set(channel, [listener]); }); - groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { - if (_this._groupListenerMap[g]) { - if (!_this._groupListenerMap[g].includes(l)) - _this._groupListenerMap[g].push(l); - } - else { - _this._groupListenerMap[g] = [l]; + groups === null || groups === void 0 ? void 0 : groups.forEach((group) => { + if (this.groupListenerMap.has(group)) { + const groupListeners = this.groupListenerMap.get(group); + if (!groupListeners.includes(listener)) + groupListeners.push(listener); } + else + this.groupListenerMap.set(group, [listener]); }); } - }; - EventEmitter.prototype.removeListener = function (listener, channels, groups) { - var _this = this; + } + removeListener(listener, channels, groups) { if (!(channels && groups)) { this.listenerManager.removeListener(listener); } else { - channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { - var _a; - _this._channelListenerMap[c] = (_a = _this._channelListenerMap[c]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; }); + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + if (this.channelListenerMap.has(channel)) { + this.channelListenerMap.set(channel, this.channelListenerMap.get(channel).filter((channelListener) => channelListener !== listener)); + } }); - groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { - var _a; - _this._groupListenerMap[g] = (_a = _this._groupListenerMap[g]) === null || _a === void 0 ? void 0 : _a.filter(function (l) { return l !== listener; }); + groups === null || groups === void 0 ? void 0 : groups.forEach((group) => { + if (this.groupListenerMap.has(group)) { + this.groupListenerMap.set(group, this.groupListenerMap.get(group).filter((groupListener) => groupListener !== listener)); + } }); } - }; - EventEmitter.prototype.removeAllListeners = function () { + } + removeAllListeners() { this.listenerManager.removeAllListeners(); - }; - EventEmitter.prototype._renameEvent = function (e) { - return e === 'set' ? 'updated' : 'removed'; - }; - EventEmitter.prototype._renameChannelField = function (announce) { - var channel = announce.channel, eventData = __rest(announce, ["channel"]); - eventData.spaceId = channel; - return eventData; - }; - EventEmitter.prototype._announce = function (type, event, channel, group) { - var _a, _b; - (_a = this._channelListenerMap[channel]) === null || _a === void 0 ? void 0 : _a.forEach(function (l) { return l[type] && l[type](event); }); - (_b = this._groupListenerMap[group]) === null || _b === void 0 ? void 0 : _b.forEach(function (l) { return l[type] && l[type](event); }); - }; - return EventEmitter; -}()); + this.channelListenerMap.clear(); + this.groupListenerMap.clear(); + } + announce(type, event, channel, group) { + if (event && this.channelListenerMap.has(channel)) + this.channelListenerMap.get(channel).forEach((listener) => { + const typedListener = listener[type]; + if (typedListener) + typedListener(event); + }); + if (group && this.groupListenerMap.has(group)) + this.groupListenerMap.get(group).forEach((listener) => { + const typedListener = listener[type]; + if (typedListener) + typedListener(event); + }); + } +} exports.default = EventEmitter; diff --git a/lib/core/components/listener_manager.js b/lib/core/components/listener_manager.js index 9518fb550..37778be75 100644 --- a/lib/core/components/listener_manager.js +++ b/lib/core/components/listener_manager.js @@ -3,98 +3,100 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var categories_1 = __importDefault(require("../constants/categories")); -var default_1 = /** @class */ (function () { - function default_1() { - this._listeners = []; +exports.ListenerManager = void 0; +const categories_1 = __importDefault(require("../constants/categories")); +class ListenerManager { + constructor() { + this.listeners = []; } - default_1.prototype.addListener = function (newListener) { - if (this._listeners.includes(newListener)) { + addListener(listener) { + if (this.listeners.includes(listener)) return; - } - this._listeners.push(newListener); - }; - default_1.prototype.removeListener = function (deprecatedListener) { - var newListeners = []; - this._listeners.forEach(function (listener) { - if (listener !== deprecatedListener) - newListeners.push(listener); + this.listeners.push(listener); + } + removeListener(listener) { + this.listeners = this.listeners.filter((storedListener) => storedListener !== listener); + } + removeAllListeners() { + this.listeners = []; + } + announceStatus(status) { + this.listeners.forEach((listener) => { + if (listener.status) + listener.status(status); }); - this._listeners = newListeners; - }; - default_1.prototype.removeAllListeners = function () { - this._listeners = []; - }; - default_1.prototype.announcePresence = function (announce) { - this._listeners.forEach(function (listener) { + } + announcePresence(presence) { + this.listeners.forEach((listener) => { if (listener.presence) - listener.presence(announce); + listener.presence(presence); }); - }; - default_1.prototype.announceStatus = function (announce) { - this._listeners.forEach(function (listener) { - if (listener.status) - listener.status(announce); - }); - }; - default_1.prototype.announceMessage = function (announce) { - this._listeners.forEach(function (listener) { + } + announceMessage(message) { + this.listeners.forEach((listener) => { if (listener.message) - listener.message(announce); + listener.message(message); }); - }; - default_1.prototype.announceSignal = function (announce) { - this._listeners.forEach(function (listener) { + } + announceSignal(signal) { + this.listeners.forEach((listener) => { if (listener.signal) - listener.signal(announce); + listener.signal(signal); }); - }; - default_1.prototype.announceMessageAction = function (announce) { - this._listeners.forEach(function (listener) { + } + announceMessageAction(messageAction) { + this.listeners.forEach((listener) => { if (listener.messageAction) - listener.messageAction(announce); + listener.messageAction(messageAction); }); - }; - default_1.prototype.announceFile = function (announce) { - this._listeners.forEach(function (listener) { + } + announceFile(file) { + this.listeners.forEach((listener) => { if (listener.file) - listener.file(announce); + listener.file(file); }); - }; - default_1.prototype.announceObjects = function (announce) { - this._listeners.forEach(function (listener) { + } + announceObjects(object) { + this.listeners.forEach((listener) => { if (listener.objects) - listener.objects(announce); + listener.objects(object); + }); + } + announceNetworkUp() { + this.listeners.forEach((listener) => { + if (listener.status) { + listener.status({ + category: categories_1.default.PNNetworkUpCategory, + }); + } + }); + } + announceNetworkDown() { + this.listeners.forEach((listener) => { + if (listener.status) { + listener.status({ + category: categories_1.default.PNNetworkDownCategory, + }); + } }); - }; - default_1.prototype.announceUser = function (announce) { - this._listeners.forEach(function (listener) { + } + announceUser(user) { + this.listeners.forEach((listener) => { if (listener.user) - listener.user(announce); + listener.user(user); }); - }; - default_1.prototype.announceSpace = function (announce) { - this._listeners.forEach(function (listener) { + } + announceSpace(space) { + this.listeners.forEach((listener) => { if (listener.space) - listener.space(announce); + listener.space(space); }); - }; - default_1.prototype.announceMembership = function (announce) { - this._listeners.forEach(function (listener) { + } + announceMembership(membership) { + this.listeners.forEach((listener) => { if (listener.membership) - listener.membership(announce); + listener.membership(membership); }); - }; - default_1.prototype.announceNetworkUp = function () { - var networkStatus = {}; - networkStatus.category = categories_1.default.PNNetworkUpCategory; - this.announceStatus(networkStatus); - }; - default_1.prototype.announceNetworkDown = function () { - var networkStatus = {}; - networkStatus.category = categories_1.default.PNNetworkDownCategory; - this.announceStatus(networkStatus); - }; - return default_1; -}()); -exports.default = default_1; + } +} +exports.ListenerManager = ListenerManager; diff --git a/lib/core/components/push_payload.js b/lib/core/components/push_payload.js index a35eb6aeb..e2196cd9b 100644 --- a/lib/core/components/push_payload.js +++ b/lib/core/components/push_payload.js @@ -1,32 +1,4 @@ "use strict"; -/* */ -/* eslint max-classes-per-file: ["error", 5] */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) @@ -39,560 +11,296 @@ var __rest = (this && this.__rest) || function (s, e) { return t; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.FCMNotificationPayload = exports.MPNSNotificationPayload = exports.APNSNotificationPayload = void 0; -var BaseNotificationPayload = /** @class */ (function () { - function BaseNotificationPayload(payload, title, body) { +exports.FCMNotificationPayload = exports.APNSNotificationPayload = void 0; +class BaseNotificationPayload { + constructor(payload, title, body) { this._payload = payload; - this._setDefaultPayloadStructure(); + this.setDefaultPayloadStructure(); this.title = title; this.body = body; } - Object.defineProperty(BaseNotificationPayload.prototype, "payload", { - get: function () { - return this._payload; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "title", { - set: function (value) { - this._title = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "subtitle", { - set: function (value) { - this._subtitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "body", { - set: function (value) { - this._body = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "badge", { - set: function (value) { - this._badge = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(BaseNotificationPayload.prototype, "sound", { - set: function (value) { - this._sound = value; - }, - enumerable: false, - configurable: true - }); - BaseNotificationPayload.prototype._setDefaultPayloadStructure = function () { - // Empty. - }; - BaseNotificationPayload.prototype.toObject = function () { + get payload() { + return this._payload; + } + set title(value) { + this._title = value; + } + set subtitle(value) { + this._subtitle = value; + } + set body(value) { + this._body = value; + } + set badge(value) { + this._badge = value; + } + set sound(value) { + this._sound = value; + } + setDefaultPayloadStructure() { } + toObject() { return {}; - }; - return BaseNotificationPayload; -}()); -var APNSNotificationPayload = /** @class */ (function (_super) { - __extends(APNSNotificationPayload, _super); - function APNSNotificationPayload() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(APNSNotificationPayload.prototype, "configurations", { - set: function (value) { - if (!value || !value.length) - return; - this._configurations = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "notification", { - get: function () { - return this._payload.aps; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "title", { - get: function () { - return this._title; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.aps.alert.title = value; - this._title = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "subtitle", { - get: function () { - return this._subtitle; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.aps.alert.subtitle = value; - this._subtitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "body", { - get: function () { - return this._body; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.aps.alert.body = value; - this._body = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "badge", { - get: function () { - return this._badge; - }, - set: function (value) { - if (value === undefined || value === null) - return; - this._payload.aps.badge = value; - this._badge = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "sound", { - get: function () { - return this._sound; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.aps.sound = value; - this._sound = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(APNSNotificationPayload.prototype, "silent", { - set: function (value) { - this._isSilent = value; - }, - enumerable: false, - configurable: true - }); - APNSNotificationPayload.prototype._setDefaultPayloadStructure = function () { - this._payload.aps = { alert: {} }; - }; - APNSNotificationPayload.prototype.toObject = function () { - var _this = this; - var payload = __assign({}, this._payload); - /** @type {{alert: Object, badge: number, sound: string}} */ - var aps = payload.aps; - var alert = aps.alert; - if (this._isSilent) { + } +} +class APNSNotificationPayload extends BaseNotificationPayload { + constructor() { + super(...arguments); + this._apnsPushType = 'apns'; + this._isSilent = false; + } + get payload() { + return this._payload; + } + set configurations(value) { + if (!value || !value.length) + return; + this._configurations = value; + } + get notification() { + return this.payload.aps; + } + get title() { + return this._title; + } + set title(value) { + if (!value || !value.length) + return; + this.payload.aps.alert.title = value; + this._title = value; + } + get subtitle() { + return this._subtitle; + } + set subtitle(value) { + if (!value || !value.length) + return; + this.payload.aps.alert.subtitle = value; + this._subtitle = value; + } + get body() { + return this._body; + } + set body(value) { + if (!value || !value.length) + return; + this.payload.aps.alert.body = value; + this._body = value; + } + get badge() { + return this._badge; + } + set badge(value) { + if (value === undefined || value === null) + return; + this.payload.aps.badge = value; + this._badge = value; + } + get sound() { + return this._sound; + } + set sound(value) { + if (!value || !value.length) + return; + this.payload.aps.sound = value; + this._sound = value; + } + set silent(value) { + this._isSilent = value; + } + setDefaultPayloadStructure() { + this.payload.aps = { alert: {} }; + } + toObject() { + const payload = Object.assign({}, this.payload); + const { aps } = payload; + let { alert } = aps; + if (this._isSilent) aps['content-available'] = 1; - } if (this._apnsPushType === 'apns2') { - if (!this._configurations || !this._configurations.length) { + if (!this._configurations || !this._configurations.length) throw new ReferenceError('APNS2 configuration is missing'); - } - var configurations_1 = []; - this._configurations.forEach(function (configuration) { - configurations_1.push(_this._objectFromAPNS2Configuration(configuration)); + const configurations = []; + this._configurations.forEach((configuration) => { + configurations.push(this.objectFromAPNS2Configuration(configuration)); }); - if (configurations_1.length) { - payload.pn_push = configurations_1; - } + if (configurations.length) + payload.pn_push = configurations; } - if (!alert || !Object.keys(alert).length) { + if (!alert || !Object.keys(alert).length) delete aps.alert; - } if (this._isSilent) { delete aps.alert; delete aps.badge; delete aps.sound; alert = {}; } - return this._isSilent || Object.keys(alert).length ? payload : null; - }; - APNSNotificationPayload.prototype._objectFromAPNS2Configuration = function (configuration) { - var _this = this; - if (!configuration.targets || !configuration.targets.length) { + return this._isSilent || (alert && Object.keys(alert).length) ? payload : null; + } + objectFromAPNS2Configuration(configuration) { + if (!configuration.targets || !configuration.targets.length) throw new ReferenceError('At least one APNS2 target should be provided'); - } - var targets = []; - configuration.targets.forEach(function (target) { - targets.push(_this._objectFromAPNSTarget(target)); - }); - var collapseId = configuration.collapseId, expirationDate = configuration.expirationDate; - var objectifiedConfiguration = { auth_method: 'token', targets: targets, version: 'v2' }; - if (collapseId && collapseId.length) { + const { collapseId, expirationDate } = configuration; + const objectifiedConfiguration = { + auth_method: 'token', + targets: configuration.targets.map((target) => this.objectFromAPNSTarget(target)), + version: 'v2', + }; + if (collapseId && collapseId.length) objectifiedConfiguration.collapse_id = collapseId; - } - if (expirationDate) { + if (expirationDate) objectifiedConfiguration.expiration = expirationDate.toISOString(); - } return objectifiedConfiguration; - }; - APNSNotificationPayload.prototype._objectFromAPNSTarget = function (target) { - if (!target.topic || !target.topic.length) { + } + objectFromAPNSTarget(target) { + if (!target.topic || !target.topic.length) throw new TypeError("Target 'topic' undefined."); - } - var topic = target.topic, _a = target.environment, environment = _a === void 0 ? 'development' : _a, _b = target.excludedDevices, excludedDevices = _b === void 0 ? [] : _b; - var objectifiedTarget = { topic: topic, environment: environment }; - if (excludedDevices.length) { + const { topic, environment = 'development', excludedDevices = [] } = target; + const objectifiedTarget = { topic, environment }; + if (excludedDevices.length) objectifiedTarget.excluded_devices = excludedDevices; - } return objectifiedTarget; - }; - return APNSNotificationPayload; -}(BaseNotificationPayload)); + } +} exports.APNSNotificationPayload = APNSNotificationPayload; -var MPNSNotificationPayload = /** @class */ (function (_super) { - __extends(MPNSNotificationPayload, _super); - function MPNSNotificationPayload() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(MPNSNotificationPayload.prototype, "backContent", { - get: function () { - return this._backContent; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.back_content = value; - this._backContent = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "backTitle", { - get: function () { - return this._backTitle; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.back_title = value; - this._backTitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "count", { - get: function () { - return this._count; - }, - set: function (value) { - if (value === undefined || value === null) - return; - this._payload.count = value; - this._count = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "title", { - get: function () { - return this._title; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.title = value; - this._title = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "type", { - get: function () { - return this._type; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.type = value; - this._type = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "subtitle", { - get: function () { - return this.backTitle; - }, - set: function (value) { - this.backTitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "body", { - get: function () { - return this.backContent; - }, - set: function (value) { - this.backContent = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(MPNSNotificationPayload.prototype, "badge", { - get: function () { - return this.count; - }, - set: function (value) { - this.count = value; - }, - enumerable: false, - configurable: true - }); - MPNSNotificationPayload.prototype.toObject = function () { - return Object.keys(this._payload).length ? __assign({}, this._payload) : null; - }; - return MPNSNotificationPayload; -}(BaseNotificationPayload)); -exports.MPNSNotificationPayload = MPNSNotificationPayload; -var FCMNotificationPayload = /** @class */ (function (_super) { - __extends(FCMNotificationPayload, _super); - function FCMNotificationPayload() { - return _super !== null && _super.apply(this, arguments) || this; - } - Object.defineProperty(FCMNotificationPayload.prototype, "notification", { - get: function () { - return this._payload.notification; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "data", { - get: function () { - return this._payload.data; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "title", { - get: function () { - return this._title; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.title = value; - this._title = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "body", { - get: function () { - return this._body; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.body = value; - this._body = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "sound", { - get: function () { - return this._sound; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.sound = value; - this._sound = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "icon", { - get: function () { - return this._icon; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.icon = value; - this._icon = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "tag", { - get: function () { - return this._tag; - }, - set: function (value) { - if (!value || !value.length) - return; - this._payload.notification.tag = value; - this._tag = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(FCMNotificationPayload.prototype, "silent", { - set: function (value) { - this._isSilent = value; - }, - enumerable: false, - configurable: true - }); - FCMNotificationPayload.prototype._setDefaultPayloadStructure = function () { - this._payload.notification = {}; - this._payload.data = {}; - }; - FCMNotificationPayload.prototype.toObject = function () { - var data = __assign({}, this._payload.data); - var notification = null; - var payload = {}; - /** - * Check whether additional data has been passed outside of 'data' object - * and put it into it if required. - */ - if (Object.keys(this._payload).length > 2) { - var _a = this._payload, initialNotification = _a.notification, initialData = _a.data, additionalData = __rest(_a, ["notification", "data"]); - data = __assign(__assign({}, data), additionalData); - } - if (this._isSilent) { - data.notification = this._payload.notification; - } - else { - notification = this._payload.notification; +class FCMNotificationPayload extends BaseNotificationPayload { + get payload() { + return this._payload; + } + get notification() { + return this.payload.notification; + } + get data() { + return this.payload.data; + } + get title() { + return this._title; + } + set title(value) { + if (!value || !value.length) + return; + this.payload.notification.title = value; + this._title = value; + } + get body() { + return this._body; + } + set body(value) { + if (!value || !value.length) + return; + this.payload.notification.body = value; + this._body = value; + } + get sound() { + return this._sound; + } + set sound(value) { + if (!value || !value.length) + return; + this.payload.notification.sound = value; + this._sound = value; + } + get icon() { + return this._icon; + } + set icon(value) { + if (!value || !value.length) + return; + this.payload.notification.icon = value; + this._icon = value; + } + get tag() { + return this._tag; + } + set tag(value) { + if (!value || !value.length) + return; + this.payload.notification.tag = value; + this._tag = value; + } + set silent(value) { + this._isSilent = value; + } + setDefaultPayloadStructure() { + this.payload.notification = {}; + this.payload.data = {}; + } + toObject() { + let data = Object.assign({}, this.payload.data); + let notification = null; + const payload = {}; + if (Object.keys(this.payload).length > 2) { + const _a = this.payload, { notification: initialNotification, data: initialData } = _a, additionalData = __rest(_a, ["notification", "data"]); + data = Object.assign(Object.assign({}, data), additionalData); } - if (Object.keys(data).length) { + if (this._isSilent) + data.notification = this.payload.notification; + else + notification = this.payload.notification; + if (Object.keys(data).length) payload.data = data; - } - if (notification && Object.keys(notification).length) { + if (notification && Object.keys(notification).length) payload.notification = notification; - } return Object.keys(payload).length ? payload : null; - }; - return FCMNotificationPayload; -}(BaseNotificationPayload)); + } +} exports.FCMNotificationPayload = FCMNotificationPayload; -var NotificationsPayload = /** @class */ (function () { - function NotificationsPayload(title, body) { - this._payload = { apns: {}, mpns: {}, fcm: {} }; +class NotificationsPayload { + constructor(title, body) { + this._payload = { apns: {}, fcm: {} }; this._title = title; this._body = body; this.apns = new APNSNotificationPayload(this._payload.apns, title, body); - this.mpns = new MPNSNotificationPayload(this._payload.mpns, title, body); this.fcm = new FCMNotificationPayload(this._payload.fcm, title, body); } - Object.defineProperty(NotificationsPayload.prototype, "debugging", { - set: function (value) { - this._debugging = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "title", { - get: function () { - return this._title; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "body", { - get: function () { - return this._body; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "subtitle", { - get: function () { - return this._subtitle; - }, - set: function (value) { - this._subtitle = value; - this.apns.subtitle = value; - this.mpns.subtitle = value; - this.fcm.subtitle = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "badge", { - get: function () { - return this._badge; - }, - set: function (value) { - this._badge = value; - this.apns.badge = value; - this.mpns.badge = value; - this.fcm.badge = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(NotificationsPayload.prototype, "sound", { - get: function () { - return this._sound; - }, - set: function (value) { - this._sound = value; - this.apns.sound = value; - this.mpns.sound = value; - this.fcm.sound = value; - }, - enumerable: false, - configurable: true - }); - /** - * Build notifications platform for requested platforms. - * - * @param {Array} platforms - List of platforms for which payload - * should be added to final dictionary. Supported values: gcm, apns, apns2, - * mpns. - * - * @returns {Object} Object with data, which can be sent with publish method - * call and trigger remote notifications for specified platforms. - */ - NotificationsPayload.prototype.buildPayload = function (platforms) { - var payload = {}; + set debugging(value) { + this._debugging = value; + } + get title() { + return this._title; + } + get subtitle() { + return this._subtitle; + } + set subtitle(value) { + this._subtitle = value; + this.apns.subtitle = value; + this.fcm.subtitle = value; + } + get body() { + return this._body; + } + get badge() { + return this._badge; + } + set badge(value) { + this._badge = value; + this.apns.badge = value; + this.fcm.badge = value; + } + get sound() { + return this._sound; + } + set sound(value) { + this._sound = value; + this.apns.sound = value; + this.fcm.sound = value; + } + buildPayload(platforms) { + const payload = {}; if (platforms.includes('apns') || platforms.includes('apns2')) { this.apns._apnsPushType = platforms.includes('apns') ? 'apns' : 'apns2'; - var apnsPayload = this.apns.toObject(); - if (apnsPayload && Object.keys(apnsPayload).length) { + const apnsPayload = this.apns.toObject(); + if (apnsPayload && Object.keys(apnsPayload).length) payload.pn_apns = apnsPayload; - } - } - if (platforms.includes('mpns')) { - var mpnsPayload = this.mpns.toObject(); - if (mpnsPayload && Object.keys(mpnsPayload).length) { - payload.pn_mpns = mpnsPayload; - } } if (platforms.includes('fcm')) { - var fcmPayload = this.fcm.toObject(); - if (fcmPayload && Object.keys(fcmPayload).length) { + const fcmPayload = this.fcm.toObject(); + if (fcmPayload && Object.keys(fcmPayload).length) payload.pn_gcm = fcmPayload; - } } - if (Object.keys(payload).length && this._debugging) { + if (Object.keys(payload).length && this._debugging) payload.pn_debug = true; - } return payload; - }; - return NotificationsPayload; -}()); + } +} exports.default = NotificationsPayload; diff --git a/lib/core/components/reconnection_manager.js b/lib/core/components/reconnection_manager.js index 26d293dc0..bc3065231 100644 --- a/lib/core/components/reconnection_manager.js +++ b/lib/core/components/reconnection_manager.js @@ -1,28 +1,29 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var default_1 = /** @class */ (function () { - function default_1(_a) { - var timeEndpoint = _a.timeEndpoint; - this._timeEndpoint = timeEndpoint; +exports.ReconnectionManager = void 0; +class ReconnectionManager { + constructor(time) { + this.time = time; } - default_1.prototype.onReconnection = function (reconnectionCallback) { - this._reconnectionCallback = reconnectionCallback; - }; - default_1.prototype.startPolling = function () { - this._timeTimer = setInterval(this._performTimeLoop.bind(this), 3000); - }; - default_1.prototype.stopPolling = function () { - clearInterval(this._timeTimer); - }; - default_1.prototype._performTimeLoop = function () { - var _this = this; - this._timeEndpoint(function (status) { + onReconnect(callback) { + this.callback = callback; + } + startPolling() { + this.timeTimer = setInterval(() => this.callTime(), 3000); + } + stopPolling() { + if (this.timeTimer) + clearInterval(this.timeTimer); + this.timeTimer = null; + } + callTime() { + this.time((status) => { if (!status.error) { - clearInterval(_this._timeTimer); - _this._reconnectionCallback(); + this.stopPolling(); + if (this.callback) + this.callback(); } }); - }; - return default_1; -}()); -exports.default = default_1; + } +} +exports.ReconnectionManager = ReconnectionManager; diff --git a/lib/core/components/request.js b/lib/core/components/request.js new file mode 100644 index 000000000..9da7e686b --- /dev/null +++ b/lib/core/components/request.js @@ -0,0 +1,98 @@ +"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 __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AbstractRequest = void 0; +const transport_request_1 = require("../types/transport-request"); +const uuid_1 = __importDefault(require("./uuid")); +class AbstractRequest { + constructor(params) { + this.params = params; + this.requestIdentifier = uuid_1.default.createUUID(); + this._cancellationController = null; + } + get cancellationController() { + return this._cancellationController; + } + set cancellationController(controller) { + this._cancellationController = controller; + } + abort() { + if (this && this.cancellationController) + this.cancellationController.abort(); + } + operation() { + throw Error('Should be implemented by subclass.'); + } + validate() { + return undefined; + } + parse(_response) { + return __awaiter(this, void 0, void 0, function* () { + throw Error('Should be implemented by subclass.'); + }); + } + request() { + var _a, _b, _c, _d; + const request = { + method: (_b = (_a = this.params) === null || _a === void 0 ? void 0 : _a.method) !== null && _b !== void 0 ? _b : transport_request_1.TransportMethod.GET, + path: this.path, + queryParameters: this.queryParameters, + cancellable: (_d = (_c = this.params) === null || _c === void 0 ? void 0 : _c.cancellable) !== null && _d !== void 0 ? _d : false, + timeout: 10000, + identifier: this.requestIdentifier, + }; + const headers = this.headers; + if (headers) + request.headers = headers; + if (request.method === transport_request_1.TransportMethod.POST || request.method === transport_request_1.TransportMethod.PATCH) { + const [body, formData] = [this.body, this.formData]; + if (formData) + request.formData = formData; + if (body) + request.body = body; + } + return request; + } + get headers() { + return undefined; + } + get path() { + throw Error('`path` getter should be implemented by subclass.'); + } + get queryParameters() { + return {}; + } + get formData() { + return undefined; + } + get body() { + return undefined; + } + deserializeResponse(response) { + const contentType = response.headers['content-type']; + if (!contentType || (contentType.indexOf('javascript') === -1 && contentType.indexOf('json') === -1)) + return undefined; + const json = AbstractRequest.decoder.decode(response.body); + try { + const parsedJson = JSON.parse(json); + return parsedJson; + } + catch (error) { + console.error('Error parsing JSON response:', error); + return undefined; + } + } +} +exports.AbstractRequest = AbstractRequest; +AbstractRequest.decoder = new TextDecoder(); diff --git a/lib/core/components/stringify_buffer_keys.js b/lib/core/components/stringify_buffer_keys.js index 8e982e01b..1a0b1692b 100644 --- a/lib/core/components/stringify_buffer_keys.js +++ b/lib/core/components/stringify_buffer_keys.js @@ -2,26 +2,24 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.stringifyBufferKeys = void 0; function stringifyBufferKeys(obj) { - var isObject = function (value) { return value && typeof value === 'object' && value.constructor === Object; }; - var isString = function (value) { return typeof value === 'string' || value instanceof String; }; - var isNumber = function (value) { return typeof value === 'number' && isFinite(value); }; - if (!isObject(obj)) { + const isObject = (value) => typeof value === 'object' && value !== null && value.constructor === Object; + const isString = (value) => typeof value === 'string' || value instanceof String; + const isNumber = (value) => typeof value === 'number' && isFinite(value); + if (!isObject(obj)) return obj; - } - var normalizedObject = {}; - Object.keys(obj).forEach(function (key) { - var keyIsString = isString(key); - var stringifiedKey = key; - var value = obj[key]; - if (Array.isArray(key) || (keyIsString && key.indexOf(',') >= 0)) { - var bytes = keyIsString ? key.split(',') : key; - stringifiedKey = bytes.reduce(function (string, byte) { - string += String.fromCharCode(byte); - return string; + const normalizedObject = {}; + Object.keys(obj).forEach((key) => { + const keyIsString = isString(key); + let stringifiedKey = key; + const value = obj[key]; + if (keyIsString && key.indexOf(',') >= 0) { + const bytes = key.split(',').map(Number); + stringifiedKey = bytes.reduce((string, byte) => { + return string + String.fromCharCode(byte); }, ''); } - else if (isNumber(key) || (keyIsString && !isNaN(key))) { - stringifiedKey = String.fromCharCode(keyIsString ? parseInt(key, 10) : 10); + else if (isNumber(key) || (keyIsString && !isNaN(Number(key)))) { + stringifiedKey = String.fromCharCode(isNumber(key) ? key : parseInt(key, 10)); } normalizedObject[stringifiedKey] = isObject(value) ? stringifyBufferKeys(value) : value; }); diff --git a/lib/core/components/subject.js b/lib/core/components/subject.js index 0a8252ed6..fed3f3ade 100644 --- a/lib/core/components/subject.js +++ b/lib/core/components/subject.js @@ -1,23 +1,20 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Subject = void 0; -var Subject = /** @class */ (function () { - function Subject(sync) { - if (sync === void 0) { sync = false; } +class Subject { + constructor(sync = false) { this.sync = sync; this.listeners = new Set(); } - Subject.prototype.subscribe = function (listener) { - var _this = this; + subscribe(listener) { this.listeners.add(listener); - return function () { - _this.listeners.delete(listener); + return () => { + this.listeners.delete(listener); }; - }; - Subject.prototype.notify = function (event) { - var _this = this; - var wrapper = function () { - _this.listeners.forEach(function (listener) { + } + notify(event) { + const wrapper = () => { + this.listeners.forEach((listener) => { listener(event); }); }; @@ -27,7 +24,6 @@ var Subject = /** @class */ (function () { else { setTimeout(wrapper, 0); } - }; - return Subject; -}()); + } +} exports.Subject = Subject; diff --git a/lib/core/components/subscription-manager.js b/lib/core/components/subscription-manager.js new file mode 100644 index 000000000..fa7d37902 --- /dev/null +++ b/lib/core/components/subscription-manager.js @@ -0,0 +1,354 @@ +"use strict"; +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.SubscriptionManager = void 0; +const reconnection_manager_1 = require("./reconnection_manager"); +const categories_1 = __importDefault(require("../constants/categories")); +const categories_2 = __importDefault(require("../constants/categories")); +const deduping_manager_1 = __importDefault(require("./deduping_manager")); +class SubscriptionManager { + constructor(configuration, listenerManager, eventEmitter, subscribeCall, heartbeatCall, leaveCall, time) { + this.configuration = configuration; + this.listenerManager = listenerManager; + this.eventEmitter = eventEmitter; + this.subscribeCall = subscribeCall; + this.heartbeatCall = heartbeatCall; + this.leaveCall = leaveCall; + this.reconnectionManager = new reconnection_manager_1.ReconnectionManager(time); + this.dedupingManager = new deduping_manager_1.default({ config: this.configuration }); + this.heartbeatChannelGroups = {}; + this.heartbeatChannels = {}; + this.presenceChannelGroups = {}; + this.presenceChannels = {}; + this.heartbeatTimer = null; + this.presenceState = {}; + this.pendingChannelGroupSubscriptions = new Set(); + this.pendingChannelSubscriptions = new Set(); + this.channelGroups = {}; + this.channels = {}; + this.currentTimetoken = '0'; + this.lastTimetoken = '0'; + this.storedTimetoken = null; + this.subscriptionStatusAnnounced = false; + this.isOnline = true; + } + get subscribedChannels() { + return Object.keys(this.channels); + } + get subscribedChannelGroups() { + return Object.keys(this.channelGroups); + } + get abort() { + return this._subscribeAbort; + } + set abort(call) { + this._subscribeAbort = call; + } + disconnect() { + this.stopSubscribeLoop(); + this.stopHeartbeatTimer(); + this.reconnectionManager.stopPolling(); + } + reconnect() { + this.startSubscribeLoop(); + this.startHeartbeatTimer(); + } + subscribe(parameters) { + const { channels, channelGroups, timetoken, withPresence = false, withHeartbeats = false } = parameters; + if (timetoken) { + this.lastTimetoken = this.currentTimetoken; + this.currentTimetoken = timetoken; + } + if (this.currentTimetoken !== '0' && this.currentTimetoken !== 0) { + this.storedTimetoken = this.currentTimetoken; + this.currentTimetoken = 0; + } + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + this.pendingChannelSubscriptions.add(channel); + this.channels[channel] = {}; + if (withPresence) + this.presenceChannels[channel] = {}; + if (withHeartbeats || this.configuration.getHeartbeatInterval()) + this.heartbeatChannels[channel] = {}; + }); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => { + this.pendingChannelGroupSubscriptions.add(group); + this.channelGroups[group] = {}; + if (withPresence) + this.presenceChannelGroups[group] = {}; + if (withHeartbeats || this.configuration.getHeartbeatInterval()) + this.heartbeatChannelGroups[group] = {}; + }); + this.subscriptionStatusAnnounced = false; + this.reconnect(); + } + unsubscribe(parameters, isOffline) { + let { channels, channelGroups } = parameters; + const actualChannelGroups = new Set(); + const actualChannels = new Set(); + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + if (channel in this.channels) { + delete this.channels[channel]; + actualChannels.add(channel); + if (channel in this.heartbeatChannels) + delete this.heartbeatChannels[channel]; + } + if (channel in this.presenceState) + delete this.presenceState[channel]; + if (channel in this.presenceChannels) { + delete this.presenceChannels[channel]; + actualChannels.add(channel); + } + }); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => { + if (group in this.channelGroups) { + delete this.channelGroups[group]; + actualChannelGroups.add(group); + if (group in this.heartbeatChannelGroups) + delete this.heartbeatChannelGroups[group]; + } + if (group in this.presenceState) + delete this.presenceState[group]; + if (group in this.presenceChannelGroups) { + delete this.presenceChannelGroups[group]; + actualChannelGroups.add(group); + } + }); + if (actualChannels.size === 0 && actualChannelGroups.size === 0) + return; + if (this.configuration.suppressLeaveEvents === false && !isOffline) { + channelGroups = Array.from(actualChannelGroups); + channels = Array.from(actualChannels); + this.leaveCall({ channels, channelGroups }, (status) => { + const { error } = status, restOfStatus = __rest(status, ["error"]); + let errorMessage; + if (error) { + if (status.errorData && + typeof status.errorData === 'object' && + 'message' in status.errorData && + typeof status.errorData.message === 'string') + errorMessage = status.errorData.message; + else if ('message' in status && typeof status.message === 'string') + errorMessage = status.message; + } + this.listenerManager.announceStatus(Object.assign(Object.assign({}, restOfStatus), { error: errorMessage !== null && errorMessage !== void 0 ? errorMessage : false, affectedChannels: channels, affectedChannelGroups: channelGroups, currentTimetoken: this.currentTimetoken, lastTimetoken: this.lastTimetoken })); + }); + } + if (Object.keys(this.channels).length === 0 && + Object.keys(this.presenceChannels).length === 0 && + Object.keys(this.channelGroups).length === 0 && + Object.keys(this.presenceChannelGroups).length === 0) { + this.lastTimetoken = 0; + this.currentTimetoken = 0; + this.storedTimetoken = null; + this.region = null; + this.reconnectionManager.stopPolling(); + } + this.reconnect(); + } + unsubscribeAll(isOffline) { + this.unsubscribe({ + channels: this.subscribedChannels, + channelGroups: this.subscribedChannelGroups, + }, isOffline); + } + startSubscribeLoop() { + this.stopSubscribeLoop(); + const channelGroups = [...Object.keys(this.channelGroups)]; + const channels = [...Object.keys(this.channels)]; + Object.keys(this.presenceChannelGroups).forEach((group) => channelGroups.push(`${group}-pnpres`)); + Object.keys(this.presenceChannels).forEach((channel) => channels.push(`${channel}-pnpres`)); + if (channels.length === 0 && channelGroups.length === 0) + return; + this.subscribeCall({ + channels, + channelGroups, + state: this.presenceState, + heartbeat: this.configuration.getPresenceTimeout(), + timetoken: this.currentTimetoken, + region: this.region !== null ? this.region : undefined, + filterExpression: this.configuration.filterExpression, + }, (status, result) => { + this.processSubscribeResponse(status, result); + }); + } + stopSubscribeLoop() { + if (this._subscribeAbort) { + this._subscribeAbort(); + this._subscribeAbort = null; + } + } + processSubscribeResponse(status, result) { + if (status.error) { + if ((typeof status.errorData === 'object' && + 'name' in status.errorData && + status.errorData.name === 'AbortError') || + status.category === categories_1.default.PNCancelledCategory) + return; + if (status.category === categories_2.default.PNTimeoutCategory) { + this.startSubscribeLoop(); + } + else if (status.category === categories_2.default.PNNetworkIssuesCategory) { + this.disconnect(); + if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { + this.isOnline = false; + this.listenerManager.announceNetworkDown(); + } + this.reconnectionManager.onReconnect(() => { + if (this.configuration.autoNetworkDetection && !this.isOnline) { + this.isOnline = true; + this.listenerManager.announceNetworkUp(); + } + this.reconnect(); + this.subscriptionStatusAnnounced = true; + const reconnectedAnnounce = { + category: categories_2.default.PNReconnectedCategory, + operation: status.operation, + lastTimetoken: this.lastTimetoken, + currentTimetoken: this.currentTimetoken, + }; + this.listenerManager.announceStatus(reconnectedAnnounce); + }); + this.reconnectionManager.startPolling(); + this.listenerManager.announceStatus(status); + } + else if (status.category === categories_2.default.PNBadRequestCategory) { + this.stopHeartbeatTimer(); + this.listenerManager.announceStatus(status); + } + else { + this.listenerManager.announceStatus(status); + } + return; + } + if (this.storedTimetoken) { + this.currentTimetoken = this.storedTimetoken; + this.storedTimetoken = null; + } + else { + this.lastTimetoken = this.currentTimetoken; + this.currentTimetoken = result.cursor.timetoken; + } + if (!this.subscriptionStatusAnnounced) { + const connected = { + category: categories_1.default.PNConnectedCategory, + operation: status.operation, + affectedChannels: Array.from(this.pendingChannelSubscriptions), + subscribedChannels: this.subscribedChannels, + affectedChannelGroups: Array.from(this.pendingChannelGroupSubscriptions), + lastTimetoken: this.lastTimetoken, + currentTimetoken: this.currentTimetoken, + }; + this.subscriptionStatusAnnounced = true; + this.listenerManager.announceStatus(connected); + this.pendingChannelGroupSubscriptions.clear(); + this.pendingChannelSubscriptions.clear(); + } + const { messages } = result; + const { requestMessageCountThreshold, dedupeOnSubscribe } = this.configuration; + if (requestMessageCountThreshold && messages.length >= requestMessageCountThreshold) { + this.listenerManager.announceStatus({ + category: categories_1.default.PNRequestMessageCountExceededCategory, + operation: status.operation, + }); + } + try { + messages.forEach((message) => { + if (dedupeOnSubscribe) { + if (this.dedupingManager.isDuplicate(message.data)) + return; + this.dedupingManager.addEntry(message.data); + } + this.eventEmitter.emitEvent(message); + }); + } + catch (e) { + const errorStatus = { + error: true, + category: categories_1.default.PNUnknownCategory, + errorData: e, + statusCode: 0, + }; + this.listenerManager.announceStatus(errorStatus); + } + this.region = result.cursor.region; + this.startSubscribeLoop(); + } + setState(parameters) { + const { state, channels, channelGroups } = parameters; + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => channel in this.channels && (this.presenceState[channel] = state)); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => group in this.channelGroups && (this.presenceState[group] = state)); + } + changePresence(parameters) { + const { connected, channels, channelGroups } = parameters; + if (connected) { + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => (this.heartbeatChannels[channel] = {})); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => (this.heartbeatChannelGroups[group] = {})); + } + else { + channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { + if (channel in this.heartbeatChannels) + delete this.heartbeatChannels[channel]; + }); + channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => { + if (group in this.heartbeatChannelGroups) + delete this.heartbeatChannelGroups[group]; + }); + if (this.configuration.suppressLeaveEvents === false) { + this.leaveCall({ channels, channelGroups }, (status) => this.listenerManager.announceStatus(status)); + } + } + this.reconnect(); + } + startHeartbeatTimer() { + this.stopHeartbeatTimer(); + const heartbeatInterval = this.configuration.getHeartbeatInterval(); + if (!heartbeatInterval || heartbeatInterval === 0) + return; + this.sendHeartbeat(); + this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), heartbeatInterval * 1000); + } + stopHeartbeatTimer() { + if (!this.heartbeatTimer) + return; + clearInterval(this.heartbeatTimer); + this.heartbeatTimer = null; + } + sendHeartbeat() { + const heartbeatChannelGroups = Object.keys(this.heartbeatChannelGroups); + const heartbeatChannels = Object.keys(this.heartbeatChannels); + if (heartbeatChannels.length === 0 && heartbeatChannelGroups.length === 0) + return; + this.heartbeatCall({ + channels: heartbeatChannels, + channelGroups: heartbeatChannelGroups, + heartbeat: this.configuration.getPresenceTimeout(), + state: this.presenceState, + }, (status) => { + if (status.error && this.configuration.announceFailedHeartbeats) + this.listenerManager.announceStatus(status); + if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { + this.isOnline = false; + this.disconnect(); + this.listenerManager.announceNetworkDown(); + this.reconnect(); + } + if (!status.error && this.configuration.announceSuccessfulHeartbeats) + this.listenerManager.announceStatus(status); + }); + } +} +exports.SubscriptionManager = SubscriptionManager; diff --git a/lib/core/components/subscription_manager.js b/lib/core/components/subscription_manager.js deleted file mode 100644 index 077bb4a1b..000000000 --- a/lib/core/components/subscription_manager.js +++ /dev/null @@ -1,434 +0,0 @@ -"use strict"; -var __rest = (this && this.__rest) || function (s, e) { - var t = {}; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) - t[p] = s[p]; - if (s != null && typeof Object.getOwnPropertySymbols === "function") - for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { - if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) - t[p[i]] = s[p[i]]; - } - return t; -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var reconnection_manager_1 = __importDefault(require("./reconnection_manager")); -var deduping_manager_1 = __importDefault(require("./deduping_manager")); -var categories_1 = __importDefault(require("../constants/categories")); -var default_1 = /** @class */ (function () { - function default_1(_a) { - var subscribeEndpoint = _a.subscribeEndpoint, leaveEndpoint = _a.leaveEndpoint, heartbeatEndpoint = _a.heartbeatEndpoint, setStateEndpoint = _a.setStateEndpoint, timeEndpoint = _a.timeEndpoint, getFileUrl = _a.getFileUrl, config = _a.config, crypto = _a.crypto, listenerManager = _a.listenerManager, cryptoModule = _a.cryptoModule, eventEmitter = _a.eventEmitter; - this._listenerManager = listenerManager; - this._config = config; - this._leaveEndpoint = leaveEndpoint; - this._heartbeatEndpoint = heartbeatEndpoint; - this._setStateEndpoint = setStateEndpoint; - this._subscribeEndpoint = subscribeEndpoint; - this._getFileUrl = getFileUrl; - this._crypto = crypto; - this._cryptoModule = cryptoModule; - this._channels = {}; - this._presenceChannels = {}; - this._heartbeatChannels = {}; - this._heartbeatChannelGroups = {}; - this._channelGroups = {}; - this._presenceChannelGroups = {}; - this._pendingChannelSubscriptions = []; - this._pendingChannelGroupSubscriptions = []; - this._currentTimetoken = 0; - this._lastTimetoken = 0; - this._storedTimetoken = null; - this._subscriptionStatusAnnounced = false; - this._isOnline = true; - this._reconnectionManager = new reconnection_manager_1.default({ timeEndpoint: timeEndpoint }); - this._dedupingManager = new deduping_manager_1.default({ config: config }); - if (this._cryptoModule) - this._decoder = new TextDecoder(); - this._eventEmitter = eventEmitter; - } - default_1.prototype.adaptStateChange = function (args, callback) { - var _this = this; - var state = args.state, _a = args.channels, channels = _a === void 0 ? [] : _a, _b = args.channelGroups, channelGroups = _b === void 0 ? [] : _b, _c = args.withHeartbeat, withHeartbeat = _c === void 0 ? false : _c; - channels.forEach(function (channel) { - if (channel in _this._channels) - _this._channels[channel].state = state; - }); - channelGroups.forEach(function (channelGroup) { - if (channelGroup in _this._channelGroups) { - _this._channelGroups[channelGroup].state = state; - } - }); - if (withHeartbeat) { - var presenceState_1 = {}; - channels.forEach(function (channel) { return (presenceState_1[channel] = state); }); - channelGroups.forEach(function (group) { return (presenceState_1[group] = state); }); - return this._heartbeatEndpoint({ channels: channels, channelGroups: channelGroups, state: presenceState_1 }, callback); - } - return this._setStateEndpoint({ state: state, channels: channels, channelGroups: channelGroups }, callback); - }; - default_1.prototype.adaptPresenceChange = function (args) { - var _this = this; - var connected = args.connected, _a = args.channels, channels = _a === void 0 ? [] : _a, _b = args.channelGroups, channelGroups = _b === void 0 ? [] : _b; - if (connected) { - channels.forEach(function (channel) { - _this._heartbeatChannels[channel] = { state: {} }; - }); - channelGroups.forEach(function (channelGroup) { - _this._heartbeatChannelGroups[channelGroup] = { state: {} }; - }); - } - else { - channels.forEach(function (channel) { - if (channel in _this._heartbeatChannels) { - delete _this._heartbeatChannels[channel]; - } - }); - channelGroups.forEach(function (channelGroup) { - if (channelGroup in _this._heartbeatChannelGroups) { - delete _this._heartbeatChannelGroups[channelGroup]; - } - }); - if (this._config.suppressLeaveEvents === false) { - this._leaveEndpoint({ channels: channels, channelGroups: channelGroups }, function (status) { - _this._listenerManager.announceStatus(status); - }); - } - } - this.reconnect(); - }; - default_1.prototype.adaptSubscribeChange = function (args) { - var _this = this; - var timetoken = args.timetoken, _a = args.channels, channels = _a === void 0 ? [] : _a, _b = args.channelGroups, channelGroups = _b === void 0 ? [] : _b, _c = args.withPresence, withPresence = _c === void 0 ? false : _c, _d = args.withHeartbeats, withHeartbeats = _d === void 0 ? false : _d; - if (!this._config.subscribeKey || this._config.subscribeKey === '') { - // eslint-disable-next-line - if (console && console.log) { - console.log('subscribe key missing; aborting subscribe'); //eslint-disable-line - } - return; - } - if (timetoken) { - this._lastTimetoken = this._currentTimetoken; - this._currentTimetoken = timetoken; - } - // reset the current timetoken to get a connect event. - // $FlowFixMe - if (this._currentTimetoken !== '0' && this._currentTimetoken !== 0) { - this._storedTimetoken = this._currentTimetoken; - this._currentTimetoken = 0; - } - channels.forEach(function (channel) { - _this._channels[channel] = { state: {} }; - if (withPresence) - _this._presenceChannels[channel] = {}; - if (withHeartbeats || _this._config.getHeartbeatInterval()) - _this._heartbeatChannels[channel] = {}; - _this._pendingChannelSubscriptions.push(channel); - }); - channelGroups.forEach(function (channelGroup) { - _this._channelGroups[channelGroup] = { state: {} }; - if (withPresence) - _this._presenceChannelGroups[channelGroup] = {}; - if (withHeartbeats || _this._config.getHeartbeatInterval()) - _this._heartbeatChannelGroups[channelGroup] = {}; - _this._pendingChannelGroupSubscriptions.push(channelGroup); - }); - this._subscriptionStatusAnnounced = false; - this.reconnect(); - }; - default_1.prototype.adaptUnsubscribeChange = function (args, isOffline) { - var _this = this; - var _a = args.channels, channels = _a === void 0 ? [] : _a, _b = args.channelGroups, channelGroups = _b === void 0 ? [] : _b; - // keep track of which channels and channel groups - // we are going to unsubscribe from. - var actualChannels = []; - var actualChannelGroups = []; - // - channels.forEach(function (channel) { - if (channel in _this._channels) { - delete _this._channels[channel]; - actualChannels.push(channel); - if (channel in _this._heartbeatChannels) { - delete _this._heartbeatChannels[channel]; - } - } - if (channel in _this._presenceChannels) { - delete _this._presenceChannels[channel]; - actualChannels.push(channel); - } - }); - channelGroups.forEach(function (channelGroup) { - if (channelGroup in _this._channelGroups) { - delete _this._channelGroups[channelGroup]; - actualChannelGroups.push(channelGroup); - if (channelGroup in _this._heartbeatChannelGroups) { - delete _this._heartbeatChannelGroups[channelGroup]; - } - } - if (channelGroup in _this._presenceChannelGroups) { - delete _this._presenceChannelGroups[channelGroup]; - actualChannelGroups.push(channelGroup); - } - }); - // no-op if there are no channels and cg's to unsubscribe from. - if (actualChannels.length === 0 && actualChannelGroups.length === 0) { - return; - } - if (this._config.suppressLeaveEvents === false && !isOffline) { - this._leaveEndpoint({ channels: actualChannels, channelGroups: actualChannelGroups }, function (status) { - status.affectedChannels = actualChannels; - status.affectedChannelGroups = actualChannelGroups; - status.currentTimetoken = _this._currentTimetoken; - status.lastTimetoken = _this._lastTimetoken; - _this._listenerManager.announceStatus(status); - }); - } - // if we have nothing to subscribe to, reset the timetoken. - if (Object.keys(this._channels).length === 0 && - Object.keys(this._presenceChannels).length === 0 && - Object.keys(this._channelGroups).length === 0 && - Object.keys(this._presenceChannelGroups).length === 0) { - this._lastTimetoken = 0; - this._currentTimetoken = 0; - this._storedTimetoken = null; - this._region = null; - this._reconnectionManager.stopPolling(); - } - this.reconnect(); - }; - default_1.prototype.unsubscribeAll = function (isOffline) { - this.adaptUnsubscribeChange({ - channels: this.getSubscribedChannels(), - channelGroups: this.getSubscribedChannelGroups(), - }, isOffline); - }; - default_1.prototype.getHeartbeatChannels = function () { - return Object.keys(this._heartbeatChannels); - }; - default_1.prototype.getHeartbeatChannelGroups = function () { - return Object.keys(this._heartbeatChannelGroups); - }; - default_1.prototype.getSubscribedChannels = function () { - return Object.keys(this._channels); - }; - default_1.prototype.getSubscribedChannelGroups = function () { - return Object.keys(this._channelGroups); - }; - default_1.prototype.reconnect = function () { - this._startSubscribeLoop(); - this._registerHeartbeatTimer(); - }; - default_1.prototype.disconnect = function () { - this._stopSubscribeLoop(); - this._stopHeartbeatTimer(); - this._reconnectionManager.stopPolling(); - }; - default_1.prototype._registerHeartbeatTimer = function () { - this._stopHeartbeatTimer(); - // if the interval is 0 or undefined, do not queue up heartbeating - if (this._config.getHeartbeatInterval() === 0 || this._config.getHeartbeatInterval() === undefined) { - return; - } - this._performHeartbeatLoop(); - // $FlowFixMe - this._heartbeatTimer = setInterval(this._performHeartbeatLoop.bind(this), this._config.getHeartbeatInterval() * 1000); - }; - default_1.prototype._stopHeartbeatTimer = function () { - if (this._heartbeatTimer) { - // $FlowFixMe - clearInterval(this._heartbeatTimer); - this._heartbeatTimer = null; - } - }; - default_1.prototype._performHeartbeatLoop = function () { - var _this = this; - var heartbeatChannels = this.getHeartbeatChannels(); - var heartbeatChannelGroups = this.getHeartbeatChannelGroups(); - var presenceState = {}; - if (heartbeatChannels.length === 0 && heartbeatChannelGroups.length === 0) { - return; - } - this.getSubscribedChannels().forEach(function (channel) { - var channelState = _this._channels[channel].state; - if (Object.keys(channelState).length) { - presenceState[channel] = channelState; - } - }); - this.getSubscribedChannelGroups().forEach(function (channelGroup) { - var channelGroupState = _this._channelGroups[channelGroup].state; - if (Object.keys(channelGroupState).length) { - presenceState[channelGroup] = channelGroupState; - } - }); - var onHeartbeat = function (status) { - if (status.error && _this._config.announceFailedHeartbeats) { - _this._listenerManager.announceStatus(status); - } - if (status.error && _this._config.autoNetworkDetection && _this._isOnline) { - _this._isOnline = false; - _this.disconnect(); - _this._listenerManager.announceNetworkDown(); - _this.reconnect(); - } - if (!status.error && _this._config.announceSuccessfulHeartbeats) { - _this._listenerManager.announceStatus(status); - } - }; - this._heartbeatEndpoint({ - channels: heartbeatChannels, - channelGroups: heartbeatChannelGroups, - state: presenceState, - }, onHeartbeat.bind(this)); - }; - default_1.prototype._startSubscribeLoop = function () { - var _this = this; - this._stopSubscribeLoop(); - var presenceState = {}; - var channels = []; - var channelGroups = []; - Object.keys(this._channels).forEach(function (channel) { - var channelState = _this._channels[channel].state; - if (Object.keys(channelState).length) { - presenceState[channel] = channelState; - } - channels.push(channel); - }); - Object.keys(this._presenceChannels).forEach(function (channel) { - channels.push("".concat(channel, "-pnpres")); - }); - Object.keys(this._channelGroups).forEach(function (channelGroup) { - var channelGroupState = _this._channelGroups[channelGroup].state; - if (Object.keys(channelGroupState).length) { - presenceState[channelGroup] = channelGroupState; - } - channelGroups.push(channelGroup); - }); - Object.keys(this._presenceChannelGroups).forEach(function (channelGroup) { - channelGroups.push("".concat(channelGroup, "-pnpres")); - }); - if (channels.length === 0 && channelGroups.length === 0) { - return; - } - var subscribeArgs = { - channels: channels, - channelGroups: channelGroups, - state: presenceState, - timetoken: this._currentTimetoken, - filterExpression: this._config.filterExpression, - region: this._region, - }; - this._subscribeCall = this._subscribeEndpoint(subscribeArgs, this._processSubscribeResponse.bind(this)); - }; - default_1.prototype._processSubscribeResponse = function (status, payload) { - var _this = this; - if (status.error) { - // if error comes from request abort, ignore - if (status.errorData && status.errorData.message === 'Aborted') { - return; - } - // if we timeout from server, restart the loop. - if (status.category === categories_1.default.PNTimeoutCategory) { - this._startSubscribeLoop(); - } - else if (status.category === categories_1.default.PNNetworkIssuesCategory) { - // we lost internet connection, alert the reconnection manager and terminate all loops - this.disconnect(); - if (status.error && this._config.autoNetworkDetection && this._isOnline) { - this._isOnline = false; - this._listenerManager.announceNetworkDown(); - } - this._reconnectionManager.onReconnection(function () { - if (_this._config.autoNetworkDetection && !_this._isOnline) { - _this._isOnline = true; - _this._listenerManager.announceNetworkUp(); - } - _this.reconnect(); - _this._subscriptionStatusAnnounced = true; - var reconnectedAnnounce = { - category: categories_1.default.PNReconnectedCategory, - operation: status.operation, - lastTimetoken: _this._lastTimetoken, - currentTimetoken: _this._currentTimetoken, - }; - _this._listenerManager.announceStatus(reconnectedAnnounce); - }); - this._reconnectionManager.startPolling(); - this._listenerManager.announceStatus(status); - } - else if (status.category === categories_1.default.PNBadRequestCategory) { - this._stopHeartbeatTimer(); - this._listenerManager.announceStatus(status); - } - else { - this._listenerManager.announceStatus(status); - } - return; - } - if (this._storedTimetoken) { - this._currentTimetoken = this._storedTimetoken; - this._storedTimetoken = null; - } - else { - this._lastTimetoken = this._currentTimetoken; - this._currentTimetoken = payload.metadata.timetoken; - } - if (!this._subscriptionStatusAnnounced) { - var connectedAnnounce = {}; - connectedAnnounce.category = categories_1.default.PNConnectedCategory; - connectedAnnounce.operation = status.operation; - connectedAnnounce.affectedChannels = this._pendingChannelSubscriptions; - connectedAnnounce.subscribedChannels = this.getSubscribedChannels(); - connectedAnnounce.affectedChannelGroups = this._pendingChannelGroupSubscriptions; - connectedAnnounce.lastTimetoken = this._lastTimetoken; - connectedAnnounce.currentTimetoken = this._currentTimetoken; - this._subscriptionStatusAnnounced = true; - this._listenerManager.announceStatus(connectedAnnounce); - // clear the pending connections list - this._pendingChannelSubscriptions = []; - this._pendingChannelGroupSubscriptions = []; - } - var messages = payload.messages || []; - var _a = this._config, requestMessageCountThreshold = _a.requestMessageCountThreshold, dedupeOnSubscribe = _a.dedupeOnSubscribe; - if (requestMessageCountThreshold && messages.length >= requestMessageCountThreshold) { - var countAnnouncement = {}; - countAnnouncement.category = categories_1.default.PNRequestMessageCountExceededCategory; - countAnnouncement.operation = status.operation; - this._listenerManager.announceStatus(countAnnouncement); - } - messages.forEach(function (message) { - var channel = message.channel; - var subscriptionMatch = message.subscriptionMatch; - if (channel === subscriptionMatch) { - subscriptionMatch = null; - } - if (dedupeOnSubscribe) { - if (_this._dedupingManager.isDuplicate(message)) { - return; - } - _this._dedupingManager.addEntry(message); - } - _this._eventEmitter.emitEvent(message); - }); - this._region = payload.metadata.region; - this._startSubscribeLoop(); - }; - default_1.prototype._stopSubscribeLoop = function () { - if (this._subscribeCall) { - if (typeof this._subscribeCall.abort === 'function') { - this._subscribeCall.abort(); - } - this._subscribeCall = null; - } - }; - default_1.prototype._renameEvent = function (e) { - return e === 'set' ? 'updated' : 'removed'; - }; - default_1.prototype._renameChannelField = function (announce) { - var channel = announce.channel, eventData = __rest(announce, ["channel"]); - eventData.spaceId = channel; - return eventData; - }; - return default_1; -}()); -exports.default = default_1; diff --git a/lib/core/components/telemetry_manager.js b/lib/core/components/telemetry_manager.js deleted file mode 100644 index f63405121..000000000 --- a/lib/core/components/telemetry_manager.js +++ /dev/null @@ -1,137 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -/* */ -var operations_1 = __importDefault(require("../constants/operations")); -var default_1 = /** @class */ (function () { - function default_1(configuration) { - this._maximumSamplesCount = 100; - this._trackedLatencies = {}; - this._latencies = {}; - this._telemetryExcludeOperations = [ - operations_1.default.PNSubscribeOperation, - operations_1.default.PNReceiveMessagesOperation, - operations_1.default.PNHandshakeOperation, - ]; - this._maximumSamplesCount = configuration.maximumSamplesCount || this._maximumSamplesCount; - } - /** - * Compose object with latency information of recently used API endpoints. - * - * @return {Object} Object with request query key/value pairs. - */ - default_1.prototype.operationsLatencyForRequest = function () { - var _this = this; - var latencies = {}; - Object.keys(this._latencies).forEach(function (endpointName) { - var operationLatencies = _this._latencies[endpointName]; - var averageLatency = _this._averageLatency(operationLatencies); - if (averageLatency > 0) { - latencies["l_".concat(endpointName)] = averageLatency; - } - }); - return latencies; - }; - default_1.prototype.startLatencyMeasure = function (operationType, identifier) { - if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { - return; - } - this._trackedLatencies[identifier] = Date.now(); - }; - default_1.prototype.stopLatencyMeasure = function (operationType, identifier) { - if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { - return; - } - var endpointName = this._endpointName(operationType); - /** @type Array */ - var endpointLatencies = this._latencies[endpointName]; - var startDate = this._trackedLatencies[identifier]; - if (!endpointLatencies) { - this._latencies[endpointName] = []; - endpointLatencies = this._latencies[endpointName]; - } - endpointLatencies.push(Date.now() - startDate); - // Truncate samples count if there is more then configured. - if (endpointLatencies.length > this._maximumSamplesCount) { - endpointLatencies.splice(0, endpointLatencies.length - this._maximumSamplesCount); - } - delete this._trackedLatencies[identifier]; - }; - default_1.prototype._averageLatency = function (latencies) { - var arrayReduce = function (accumulatedLatency, latency) { return accumulatedLatency + latency; }; - return Math.floor(latencies.reduce(arrayReduce, 0) / latencies.length); - }; - default_1.prototype._endpointName = function (operationType) { - var operation = null; - switch (operationType) { - case operations_1.default.PNPublishOperation: - operation = 'pub'; - break; - case operations_1.default.PNSignalOperation: - operation = 'sig'; - break; - case operations_1.default.PNHistoryOperation: - case operations_1.default.PNFetchMessagesOperation: - case operations_1.default.PNDeleteMessagesOperation: - case operations_1.default.PNMessageCounts: - operation = 'hist'; - break; - case operations_1.default.PNUnsubscribeOperation: - case operations_1.default.PNWhereNowOperation: - case operations_1.default.PNHereNowOperation: - case operations_1.default.PNHeartbeatOperation: - case operations_1.default.PNSetStateOperation: - case operations_1.default.PNGetStateOperation: - operation = 'pres'; - break; - case operations_1.default.PNAddChannelsToGroupOperation: - case operations_1.default.PNRemoveChannelsFromGroupOperation: - case operations_1.default.PNChannelGroupsOperation: - case operations_1.default.PNRemoveGroupOperation: - case operations_1.default.PNChannelsForGroupOperation: - operation = 'cg'; - break; - case operations_1.default.PNPushNotificationEnabledChannelsOperation: - case operations_1.default.PNRemoveAllPushNotificationsOperation: - operation = 'push'; - break; - case operations_1.default.PNCreateUserOperation: - case operations_1.default.PNUpdateUserOperation: - case operations_1.default.PNDeleteUserOperation: - case operations_1.default.PNGetUserOperation: - case operations_1.default.PNGetUsersOperation: - case operations_1.default.PNCreateSpaceOperation: - case operations_1.default.PNUpdateSpaceOperation: - case operations_1.default.PNDeleteSpaceOperation: - case operations_1.default.PNGetSpaceOperation: - case operations_1.default.PNGetSpacesOperation: - case operations_1.default.PNGetMembersOperation: - case operations_1.default.PNUpdateMembersOperation: - case operations_1.default.PNGetMembershipsOperation: - case operations_1.default.PNUpdateMembershipsOperation: - operation = 'obj'; - break; - case operations_1.default.PNAddMessageActionOperation: - case operations_1.default.PNRemoveMessageActionOperation: - case operations_1.default.PNGetMessageActionsOperation: - operation = 'msga'; - break; - case operations_1.default.PNAccessManagerGrant: - case operations_1.default.PNAccessManagerAudit: - operation = 'pam'; - break; - case operations_1.default.PNAccessManagerGrantToken: - case operations_1.default.PNAccessManagerRevokeToken: - operation = 'pamv3'; - break; - default: - operation = 'time'; - break; - } - return operation; - }; - return default_1; -}()); -exports.default = default_1; diff --git a/lib/core/components/token_manager.js b/lib/core/components/token_manager.js index e41ef77a1..9ada86a34 100644 --- a/lib/core/components/token_manager.js +++ b/lib/core/components/token_manager.js @@ -1,128 +1,102 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -var default_1 = /** @class */ (function () { - function default_1(config, cbor) { - this._config = config; - this._cbor = cbor; +exports.TokenManager = void 0; +class TokenManager { + constructor(cbor) { + this.cbor = cbor; } - default_1.prototype.setToken = function (token) { - if (token && token.length > 0) { - this._token = token; - } - else { - this._token = undefined; - } - }; - default_1.prototype.getToken = function () { - return this._token; - }; - default_1.prototype.extractPermissions = function (permissions) { - var permissionsResult = { - read: false, - write: false, - manage: false, - delete: false, - get: false, - update: false, - join: false, - }; - /* eslint-disable */ - if ((permissions & 128) === 128) { - permissionsResult.join = true; - } - if ((permissions & 64) === 64) { - permissionsResult.update = true; - } - if ((permissions & 32) === 32) { - permissionsResult.get = true; - } - if ((permissions & 8) === 8) { - permissionsResult.delete = true; - } - if ((permissions & 4) === 4) { - permissionsResult.manage = true; - } - if ((permissions & 2) === 2) { - permissionsResult.write = true; - } - if ((permissions & 1) === 1) { - permissionsResult.read = true; - } - /* eslint-enable */ - return permissionsResult; - }; - default_1.prototype.parseToken = function (tokenString) { - var _this = this; - var parsed = this._cbor.decodeToken(tokenString); + setToken(token) { + if (token && token.length > 0) + this.token = token; + else + this.token = undefined; + } + getToken() { + return this.token; + } + parseToken(tokenString) { + const parsed = this.cbor.decodeToken(tokenString); if (parsed !== undefined) { - var uuidResourcePermissions = parsed.res.uuid ? Object.keys(parsed.res.uuid) : []; - var channelResourcePermissions = Object.keys(parsed.res.chan); - var groupResourcePermissions = Object.keys(parsed.res.grp); - var uuidPatternPermissions = parsed.pat.uuid ? Object.keys(parsed.pat.uuid) : []; - var channelPatternPermissions = Object.keys(parsed.pat.chan); - var groupPatternPermissions = Object.keys(parsed.pat.grp); - var result_1 = { + const uuidResourcePermissions = parsed.res.uuid ? Object.keys(parsed.res.uuid) : []; + const channelResourcePermissions = Object.keys(parsed.res.chan); + const groupResourcePermissions = Object.keys(parsed.res.grp); + const uuidPatternPermissions = parsed.pat.uuid ? Object.keys(parsed.pat.uuid) : []; + const channelPatternPermissions = Object.keys(parsed.pat.chan); + const groupPatternPermissions = Object.keys(parsed.pat.grp); + const result = { version: parsed.v, timestamp: parsed.t, ttl: parsed.ttl, authorized_uuid: parsed.uuid, + signature: parsed.sig, }; - var uuidResources = uuidResourcePermissions.length > 0; - var channelResources = channelResourcePermissions.length > 0; - var groupResources = groupResourcePermissions.length > 0; + const uuidResources = uuidResourcePermissions.length > 0; + const channelResources = channelResourcePermissions.length > 0; + const groupResources = groupResourcePermissions.length > 0; if (uuidResources || channelResources || groupResources) { - result_1.resources = {}; + result.resources = {}; if (uuidResources) { - result_1.resources.uuids = {}; - uuidResourcePermissions.forEach(function (id) { - result_1.resources.uuids[id] = _this.extractPermissions(parsed.res.uuid[id]); - }); + const uuids = (result.resources.uuids = {}); + uuidResourcePermissions.forEach((id) => (uuids[id] = this.extractPermissions(parsed.res.uuid[id]))); } if (channelResources) { - result_1.resources.channels = {}; - channelResourcePermissions.forEach(function (id) { - result_1.resources.channels[id] = _this.extractPermissions(parsed.res.chan[id]); - }); + const channels = (result.resources.channels = {}); + channelResourcePermissions.forEach((id) => (channels[id] = this.extractPermissions(parsed.res.chan[id]))); } if (groupResources) { - result_1.resources.groups = {}; - groupResourcePermissions.forEach(function (id) { - result_1.resources.groups[id] = _this.extractPermissions(parsed.res.grp[id]); - }); + const groups = (result.resources.groups = {}); + groupResourcePermissions.forEach((id) => (groups[id] = this.extractPermissions(parsed.res.grp[id]))); } } - var uuidPatterns = uuidPatternPermissions.length > 0; - var channelPatterns = channelPatternPermissions.length > 0; - var groupPatterns = groupPatternPermissions.length > 0; + const uuidPatterns = uuidPatternPermissions.length > 0; + const channelPatterns = channelPatternPermissions.length > 0; + const groupPatterns = groupPatternPermissions.length > 0; if (uuidPatterns || channelPatterns || groupPatterns) { - result_1.patterns = {}; + result.patterns = {}; if (uuidPatterns) { - result_1.patterns.uuids = {}; - uuidPatternPermissions.forEach(function (id) { - result_1.patterns.uuids[id] = _this.extractPermissions(parsed.pat.uuid[id]); - }); + const uuids = (result.patterns.uuids = {}); + uuidPatternPermissions.forEach((id) => (uuids[id] = this.extractPermissions(parsed.pat.uuid[id]))); } if (channelPatterns) { - result_1.patterns.channels = {}; - channelPatternPermissions.forEach(function (id) { - result_1.patterns.channels[id] = _this.extractPermissions(parsed.pat.chan[id]); - }); + const channels = (result.patterns.channels = {}); + channelPatternPermissions.forEach((id) => (channels[id] = this.extractPermissions(parsed.pat.chan[id]))); } if (groupPatterns) { - result_1.patterns.groups = {}; - groupPatternPermissions.forEach(function (id) { - result_1.patterns.groups[id] = _this.extractPermissions(parsed.pat.grp[id]); - }); + const groups = (result.patterns.groups = {}); + groupPatternPermissions.forEach((id) => (groups[id] = this.extractPermissions(parsed.pat.grp[id]))); } } - if (Object.keys(parsed.meta).length > 0) { - result_1.meta = parsed.meta; - } - result_1.signature = parsed.sig; - return result_1; + if (parsed.meta && Object.keys(parsed.meta).length > 0) + result.meta = parsed.meta; + return result; } return undefined; - }; - return default_1; -}()); -exports.default = default_1; + } + extractPermissions(permissions) { + const permissionsResult = { + read: false, + write: false, + manage: false, + delete: false, + get: false, + update: false, + join: false, + }; + if ((permissions & 128) === 128) + permissionsResult.join = true; + if ((permissions & 64) === 64) + permissionsResult.update = true; + if ((permissions & 32) === 32) + permissionsResult.get = true; + if ((permissions & 8) === 8) + permissionsResult.delete = true; + if ((permissions & 4) === 4) + permissionsResult.manage = true; + if ((permissions & 2) === 2) + permissionsResult.write = true; + if ((permissions & 1) === 1) + permissionsResult.read = true; + return permissionsResult; + } +} +exports.TokenManager = TokenManager; diff --git a/lib/core/components/uuid.js b/lib/core/components/uuid.js index 18cbb6fd3..deb3c187f 100644 --- a/lib/core/components/uuid.js +++ b/lib/core/components/uuid.js @@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var lil_uuid_1 = __importDefault(require("lil-uuid")); +const lil_uuid_1 = __importDefault(require("lil-uuid")); exports.default = { - createUUID: function () { + createUUID() { if (lil_uuid_1.default.uuid) { return lil_uuid_1.default.uuid(); } diff --git a/lib/core/constants/categories.js b/lib/core/constants/categories.js index c976cd42a..de7657670 100644 --- a/lib/core/constants/categories.js +++ b/lib/core/constants/categories.js @@ -1,26 +1,22 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -/* */ -exports.default = { - // SDK will announce when the network appears to be connected again. - PNNetworkUpCategory: 'PNNetworkUpCategory', - // SDK will announce when the network appears to down. - PNNetworkDownCategory: 'PNNetworkDownCategory', - // call failed when network was unable to complete the call. - PNNetworkIssuesCategory: 'PNNetworkIssuesCategory', - // network call timed out - PNTimeoutCategory: 'PNTimeoutCategory', - // server responded with bad response - PNBadRequestCategory: 'PNBadRequestCategory', - // server responded with access denied - PNAccessDeniedCategory: 'PNAccessDeniedCategory', - // something strange happened; please check the logs. - PNUnknownCategory: 'PNUnknownCategory', - // on reconnection - PNReconnectedCategory: 'PNReconnectedCategory', - PNConnectedCategory: 'PNConnectedCategory', - PNRequestMessageCountExceededCategory: 'PNRequestMessageCountExceededCategory', - PNDisconnectedCategory: 'PNDisconnectedCategory', - PNConnectionErrorCategory: 'PNConnectionErrorCategory', - PNDisconnectedUnexpectedlyCategory: 'PNDisconnectedUnexpectedlyCategory', -}; +var StatusCategory; +(function (StatusCategory) { + StatusCategory["PNNetworkIssuesCategory"] = "PNNetworkIssuesCategory"; + StatusCategory["PNTimeoutCategory"] = "PNTimeoutCategory"; + StatusCategory["PNCancelledCategory"] = "PNCancelledCategory"; + StatusCategory["PNBadRequestCategory"] = "PNBadRequestCategory"; + StatusCategory["PNAccessDeniedCategory"] = "PNAccessDeniedCategory"; + StatusCategory["PNValidationErrorCategory"] = "PNValidationErrorCategory"; + StatusCategory["PNAcknowledgmentCategory"] = "PNAcknowledgmentCategory"; + StatusCategory["PNUnknownCategory"] = "PNUnknownCategory"; + StatusCategory["PNNetworkUpCategory"] = "PNNetworkUpCategory"; + StatusCategory["PNNetworkDownCategory"] = "PNNetworkDownCategory"; + StatusCategory["PNReconnectedCategory"] = "PNReconnectedCategory"; + StatusCategory["PNConnectedCategory"] = "PNConnectedCategory"; + StatusCategory["PNRequestMessageCountExceededCategory"] = "PNRequestMessageCountExceededCategory"; + StatusCategory["PNDisconnectedCategory"] = "PNDisconnectedCategory"; + StatusCategory["PNConnectionErrorCategory"] = "PNConnectionErrorCategory"; + StatusCategory["PNDisconnectedUnexpectedlyCategory"] = "PNDisconnectedUnexpectedlyCategory"; +})(StatusCategory || (StatusCategory = {})); +exports.default = StatusCategory; diff --git a/lib/core/constants/operations.js b/lib/core/constants/operations.js index 5a934e464..c30b7e919 100644 --- a/lib/core/constants/operations.js +++ b/lib/core/constants/operations.js @@ -1,83 +1,58 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -/* */ -exports.default = { - PNTimeOperation: 'PNTimeOperation', - PNHistoryOperation: 'PNHistoryOperation', - PNDeleteMessagesOperation: 'PNDeleteMessagesOperation', - PNFetchMessagesOperation: 'PNFetchMessagesOperation', - PNMessageCounts: 'PNMessageCountsOperation', - // pubsub - PNSubscribeOperation: 'PNSubscribeOperation', - PNUnsubscribeOperation: 'PNUnsubscribeOperation', - PNPublishOperation: 'PNPublishOperation', - PNSignalOperation: 'PNSignalOperation', - // Actions API - PNAddMessageActionOperation: 'PNAddActionOperation', - PNRemoveMessageActionOperation: 'PNRemoveMessageActionOperation', - PNGetMessageActionsOperation: 'PNGetMessageActionsOperation', - // Objects API - 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', - // File Upload API v1 - PNListFilesOperation: 'PNListFilesOperation', - PNGenerateUploadUrlOperation: 'PNGenerateUploadUrlOperation', - PNPublishFileOperation: 'PNPublishFileOperation', - PNGetFileUrlOperation: 'PNGetFileUrlOperation', - PNDownloadFileOperation: 'PNDownloadFileOperation', - // Objects API v2 - // UUID - PNGetAllUUIDMetadataOperation: 'PNGetAllUUIDMetadataOperation', - PNGetUUIDMetadataOperation: 'PNGetUUIDMetadataOperation', - PNSetUUIDMetadataOperation: 'PNSetUUIDMetadataOperation', - PNRemoveUUIDMetadataOperation: 'PNRemoveUUIDMetadataOperation', - // channel - PNGetAllChannelMetadataOperation: 'PNGetAllChannelMetadataOperation', - PNGetChannelMetadataOperation: 'PNGetChannelMetadataOperation', - PNSetChannelMetadataOperation: 'PNSetChannelMetadataOperation', - PNRemoveChannelMetadataOperation: 'PNRemoveChannelMetadataOperation', - // member - // PNGetMembersOperation: 'PNGetMembersOperation', - PNSetMembersOperation: 'PNSetMembersOperation', - // PNGetMembershipsOperation: 'PNGetMembersOperation', - PNSetMembershipsOperation: 'PNSetMembershipsOperation', - // push - PNPushNotificationEnabledChannelsOperation: 'PNPushNotificationEnabledChannelsOperation', - PNRemoveAllPushNotificationsOperation: 'PNRemoveAllPushNotificationsOperation', - // - // presence - PNWhereNowOperation: 'PNWhereNowOperation', - PNSetStateOperation: 'PNSetStateOperation', - PNHereNowOperation: 'PNHereNowOperation', - PNGetStateOperation: 'PNGetStateOperation', - PNHeartbeatOperation: 'PNHeartbeatOperation', - // - // channel group - PNChannelGroupsOperation: 'PNChannelGroupsOperation', - PNRemoveGroupOperation: 'PNRemoveGroupOperation', - PNChannelsForGroupOperation: 'PNChannelsForGroupOperation', - PNAddChannelsToGroupOperation: 'PNAddChannelsToGroupOperation', - PNRemoveChannelsFromGroupOperation: 'PNRemoveChannelsFromGroupOperation', - // - // PAM - PNAccessManagerGrant: 'PNAccessManagerGrant', - PNAccessManagerGrantToken: 'PNAccessManagerGrantToken', - PNAccessManagerAudit: 'PNAccessManagerAudit', - PNAccessManagerRevokeToken: 'PNAccessManagerRevokeToken', - // - // subscription utilities - PNHandshakeOperation: 'PNHandshakeOperation', - PNReceiveMessagesOperation: 'PNReceiveMessagesOperation', -}; +var RequestOperation; +(function (RequestOperation) { + RequestOperation["PNPublishOperation"] = "PNPublishOperation"; + RequestOperation["PNSignalOperation"] = "PNSignalOperation"; + RequestOperation["PNSubscribeOperation"] = "PNSubscribeOperation"; + RequestOperation["PNUnsubscribeOperation"] = "PNUnsubscribeOperation"; + RequestOperation["PNWhereNowOperation"] = "PNWhereNowOperation"; + RequestOperation["PNHereNowOperation"] = "PNHereNowOperation"; + RequestOperation["PNGlobalHereNowOperation"] = "PNGlobalHereNowOperation"; + RequestOperation["PNSetStateOperation"] = "PNSetStateOperation"; + RequestOperation["PNGetStateOperation"] = "PNGetStateOperation"; + RequestOperation["PNHeartbeatOperation"] = "PNHeartbeatOperation"; + RequestOperation["PNAddMessageActionOperation"] = "PNAddActionOperation"; + RequestOperation["PNRemoveMessageActionOperation"] = "PNRemoveMessageActionOperation"; + RequestOperation["PNGetMessageActionsOperation"] = "PNGetMessageActionsOperation"; + RequestOperation["PNTimeOperation"] = "PNTimeOperation"; + RequestOperation["PNHistoryOperation"] = "PNHistoryOperation"; + RequestOperation["PNDeleteMessagesOperation"] = "PNDeleteMessagesOperation"; + RequestOperation["PNFetchMessagesOperation"] = "PNFetchMessagesOperation"; + RequestOperation["PNMessageCounts"] = "PNMessageCountsOperation"; + RequestOperation["PNGetAllUUIDMetadataOperation"] = "PNGetAllUUIDMetadataOperation"; + RequestOperation["PNGetUUIDMetadataOperation"] = "PNGetUUIDMetadataOperation"; + RequestOperation["PNSetUUIDMetadataOperation"] = "PNSetUUIDMetadataOperation"; + RequestOperation["PNRemoveUUIDMetadataOperation"] = "PNRemoveUUIDMetadataOperation"; + RequestOperation["PNGetAllChannelMetadataOperation"] = "PNGetAllChannelMetadataOperation"; + RequestOperation["PNGetChannelMetadataOperation"] = "PNGetChannelMetadataOperation"; + RequestOperation["PNSetChannelMetadataOperation"] = "PNSetChannelMetadataOperation"; + RequestOperation["PNRemoveChannelMetadataOperation"] = "PNRemoveChannelMetadataOperation"; + RequestOperation["PNGetMembersOperation"] = "PNGetMembersOperation"; + RequestOperation["PNSetMembersOperation"] = "PNSetMembersOperation"; + RequestOperation["PNGetMembershipsOperation"] = "PNGetMembershipsOperation"; + RequestOperation["PNSetMembershipsOperation"] = "PNSetMembershipsOperation"; + RequestOperation["PNListFilesOperation"] = "PNListFilesOperation"; + RequestOperation["PNGenerateUploadUrlOperation"] = "PNGenerateUploadUrlOperation"; + RequestOperation["PNPublishFileOperation"] = "PNPublishFileOperation"; + RequestOperation["PNPublishFileMessageOperation"] = "PNPublishFileMessageOperation"; + RequestOperation["PNGetFileUrlOperation"] = "PNGetFileUrlOperation"; + RequestOperation["PNDownloadFileOperation"] = "PNDownloadFileOperation"; + RequestOperation["PNDeleteFileOperation"] = "PNDeleteFileOperation"; + RequestOperation["PNAddPushNotificationEnabledChannelsOperation"] = "PNAddPushNotificationEnabledChannelsOperation"; + RequestOperation["PNRemovePushNotificationEnabledChannelsOperation"] = "PNRemovePushNotificationEnabledChannelsOperation"; + RequestOperation["PNPushNotificationEnabledChannelsOperation"] = "PNPushNotificationEnabledChannelsOperation"; + RequestOperation["PNRemoveAllPushNotificationsOperation"] = "PNRemoveAllPushNotificationsOperation"; + RequestOperation["PNChannelGroupsOperation"] = "PNChannelGroupsOperation"; + RequestOperation["PNRemoveGroupOperation"] = "PNRemoveGroupOperation"; + RequestOperation["PNChannelsForGroupOperation"] = "PNChannelsForGroupOperation"; + RequestOperation["PNAddChannelsToGroupOperation"] = "PNAddChannelsToGroupOperation"; + RequestOperation["PNRemoveChannelsFromGroupOperation"] = "PNRemoveChannelsFromGroupOperation"; + RequestOperation["PNAccessManagerGrant"] = "PNAccessManagerGrant"; + RequestOperation["PNAccessManagerGrantToken"] = "PNAccessManagerGrantToken"; + RequestOperation["PNAccessManagerAudit"] = "PNAccessManagerAudit"; + RequestOperation["PNAccessManagerRevokeToken"] = "PNAccessManagerRevokeToken"; + RequestOperation["PNHandshakeOperation"] = "PNHandshakeOperation"; + RequestOperation["PNReceiveMessagesOperation"] = "PNReceiveMessagesOperation"; +})(RequestOperation || (RequestOperation = {})); +exports.default = RequestOperation; diff --git a/lib/core/endpoints/access_manager/audit.js b/lib/core/endpoints/access_manager/audit.js index 2cdd17c8e..e39aeb6d0 100644 --- a/lib/core/endpoints/access_manager/audit.js +++ b/lib/core/endpoints/access_manager/audit.js @@ -1,51 +1,55 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -function getOperation() { - return operations_1.default.PNAccessManagerAudit; -} -exports.getOperation = getOperation; -function validateParams(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules) { - var config = modules.config; - return "/v2/auth/audit/sub-key/".concat(config.subscribeKey); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return false; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var channel = incomingParams.channel, channelGroup = incomingParams.channelGroup, _a = incomingParams.authKeys, authKeys = _a === void 0 ? [] : _a; - var params = {}; - if (channel) { - params.channel = channel; +exports.AuditRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const AUTH_KEYS = []; +class AuditRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a; + var _b; + super(); + this.parameters = parameters; + (_a = (_b = this.parameters).authKeys) !== null && _a !== void 0 ? _a : (_b.authKeys = AUTH_KEYS); } - if (channelGroup) { - params['channel-group'] = channelGroup; + operation() { + return operations_1.default.PNAccessManagerAudit; } - if (authKeys.length > 0) { - params.auth = authKeys.join(','); + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse.payload; + }); + } + get path() { + return `/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`; + } + get queryParameters() { + const { channel, channelGroup, authKeys } = this.parameters; + return Object.assign(Object.assign(Object.assign({}, (channel ? { channel } : {})), (channelGroup ? { 'channel-group': channelGroup } : {})), (authKeys && authKeys.length ? { auth: authKeys.join(',') } : {})); } - return params; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - return serverResponse.payload; } -exports.handleResponse = handleResponse; +exports.AuditRequest = AuditRequest; diff --git a/lib/core/endpoints/access_manager/grant.js b/lib/core/endpoints/access_manager/grant.js index e65a390b5..dfb15e873 100644 --- a/lib/core/endpoints/access_manager/grant.js +++ b/lib/core/endpoints/access_manager/grant.js @@ -1,75 +1,79 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../../constants/operations")); -function getOperation() { - return operations_1.default.PNAccessManagerGrant; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!config.publishKey) - return 'Missing Publish Key'; - if (!config.secretKey) - return 'Missing Secret Key'; - if (incomingParams.uuids != null && !incomingParams.authKeys) { - return 'authKeys are required for grant request on uuids'; +exports.GrantRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const READ_PERMISSION = false; +const WRITE_PERMISSION = false; +const DELETE_PERMISSION = false; +const GET_PERMISSION = false; +const UPDATE_PERMISSION = false; +const MANAGE_PERMISSION = false; +const JOIN_PERMISSION = false; +class GrantRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; + super(); + this.parameters = parameters; + (_a = (_l = this.parameters).channels) !== null && _a !== void 0 ? _a : (_l.channels = []); + (_b = (_m = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_m.channelGroups = []); + (_c = (_o = this.parameters).uuids) !== null && _c !== void 0 ? _c : (_o.uuids = []); + (_d = (_p = this.parameters).read) !== null && _d !== void 0 ? _d : (_p.read = READ_PERMISSION); + (_e = (_q = this.parameters).write) !== null && _e !== void 0 ? _e : (_q.write = WRITE_PERMISSION); + (_f = (_r = this.parameters).delete) !== null && _f !== void 0 ? _f : (_r.delete = DELETE_PERMISSION); + (_g = (_s = this.parameters).get) !== null && _g !== void 0 ? _g : (_s.get = GET_PERMISSION); + (_h = (_t = this.parameters).update) !== null && _h !== void 0 ? _h : (_t.update = UPDATE_PERMISSION); + (_j = (_u = this.parameters).manage) !== null && _j !== void 0 ? _j : (_u.manage = MANAGE_PERMISSION); + (_k = (_v = this.parameters).join) !== null && _k !== void 0 ? _k : (_v.join = JOIN_PERMISSION); } - if (incomingParams.uuids != null && (incomingParams.channels != null || incomingParams.channelGroups != null)) { - return 'Both channel/channelgroup and uuid cannot be used in the same request'; - } -} -exports.validateParams = validateParams; -function getURL(modules) { - var config = modules.config; - return "/v2/auth/grant/sub-key/".concat(config.subscribeKey); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return false; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b, _c = incomingParams.uuids, uuids = _c === void 0 ? [] : _c, ttl = incomingParams.ttl, _d = incomingParams.read, read = _d === void 0 ? false : _d, _e = incomingParams.write, write = _e === void 0 ? false : _e, _f = incomingParams.manage, manage = _f === void 0 ? false : _f, _g = incomingParams.get, get = _g === void 0 ? false : _g, _h = incomingParams.join, join = _h === void 0 ? false : _h, _j = incomingParams.update, update = _j === void 0 ? false : _j, _k = incomingParams.authKeys, authKeys = _k === void 0 ? [] : _k; - var deleteParam = incomingParams.delete; - var params = {}; - params.r = read ? '1' : '0'; - params.w = write ? '1' : '0'; - params.m = manage ? '1' : '0'; - params.d = deleteParam ? '1' : '0'; - params.g = get ? '1' : '0'; - params.j = join ? '1' : '0'; - params.u = update ? '1' : '0'; - if (channels.length > 0) { - params.channel = channels.join(','); + operation() { + return operations_1.default.PNAccessManagerGrant; } - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); + validate() { + const { keySet: { subscribeKey, publishKey, secretKey }, uuids = [], channels = [], channelGroups = [], authKeys = [], } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!publishKey) + return 'Missing Publish Key'; + if (!secretKey) + return 'Missing Secret Key'; + if (uuids.length !== 0 && authKeys.length === 0) + return 'authKeys are required for grant request on uuids'; + if (uuids.length && (channels.length !== 0 || channelGroups.length !== 0)) + return 'Both channel/channel group and uuid cannot be used in the same request'; } - if (authKeys.length > 0) { - params.auth = authKeys.join(','); + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse.payload; + }); } - if (uuids.length > 0) { - params['target-uuid'] = uuids.join(','); + get path() { + return `/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`; } - if (ttl || ttl === 0) { - params.ttl = ttl; + get queryParameters() { + const { channels, channelGroups, authKeys, uuids, read, write, manage, delete: del, get, join, update, ttl, } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (channels && (channels === null || channels === void 0 ? void 0 : channels.length) > 0 ? { channel: channels.join(',') } : {})), (channelGroups && (channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.length) > 0 ? { 'channel-group': channelGroups.join(',') } : {})), (authKeys && (authKeys === null || authKeys === void 0 ? void 0 : authKeys.length) > 0 ? { auth: authKeys.join(',') } : {})), (uuids && (uuids === null || uuids === void 0 ? void 0 : uuids.length) > 0 ? { 'target-uuid': uuids.join(',') } : {})), { r: read ? '1' : '0', w: write ? '1' : '0', m: manage ? '1' : '0', d: del ? '1' : '0', g: get ? '1' : '0', j: join ? '1' : '0', u: update ? '1' : '0' }), (ttl || ttl === 0 ? { ttl } : {})); } - return params; -} -exports.prepareParams = prepareParams; -function handleResponse() { - return {}; } -exports.handleResponse = handleResponse; +exports.GrantRequest = GrantRequest; diff --git a/lib/core/endpoints/access_manager/grant_token.js b/lib/core/endpoints/access_manager/grant_token.js index 8c9f0b974..2c420331f 100644 --- a/lib/core/endpoints/access_manager/grant_token.js +++ b/lib/core/endpoints/access_manager/grant_token.js @@ -1,263 +1,160 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.postPayload = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.usePost = exports.postURL = exports.validateParams = exports.extractPermissions = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -function getOperation() { - return operations_1.default.PNAccessManagerGrantToken; -} -exports.getOperation = getOperation; -function hasVspTerms(incomingParams) { - var _a, _b, _c, _d; - var hasAuthorizedUserId = (incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.authorizedUserId) !== undefined; - var hasUserResources = ((_a = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _a === void 0 ? void 0 : _a.users) !== undefined; - var hasSpaceResources = ((_b = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _b === void 0 ? void 0 : _b.spaces) !== undefined; - var hasUserPatterns = ((_c = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _c === void 0 ? void 0 : _c.users) !== undefined; - var hasSpacePatterns = ((_d = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _d === void 0 ? void 0 : _d.spaces) !== undefined; - return hasUserPatterns || hasUserResources || hasSpacePatterns || hasSpaceResources || hasAuthorizedUserId; -} -function extractPermissions(permissions) { - var permissionsResult = 0; - if (permissions.join) { - permissionsResult |= 128; - } - if (permissions.update) { - permissionsResult |= 64; - } - if (permissions.get) { - permissionsResult |= 32; - } - if (permissions.delete) { - permissionsResult |= 8; - } - if (permissions.manage) { - permissionsResult |= 4; - } - if (permissions.write) { - permissionsResult |= 2; - } - if (permissions.read) { - permissionsResult |= 1; - } - return permissionsResult; -} -exports.extractPermissions = extractPermissions; -function prepareMessagePayloadVsp(_modules, _a) { - var ttl = _a.ttl, resources = _a.resources, patterns = _a.patterns, meta = _a.meta, authorizedUserId = _a.authorizedUserId; - var params = { - ttl: 0, - permissions: { - resources: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, - spaces: {}, // not used, needed for api backward compatibility - }, - patterns: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, - spaces: {}, // not used, needed for api backward compatibility - }, - meta: {}, - }, - }; - if (resources) { - var users_1 = resources.users, spaces_1 = resources.spaces, groups_1 = resources.groups; - if (users_1) { - Object.keys(users_1).forEach(function (userID) { - params.permissions.resources.uuids[userID] = extractPermissions(users_1[userID]); +exports.GrantTokenRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../types/transport-request"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +class GrantTokenRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c, _d; + super({ method: transport_request_1.TransportMethod.POST }); + this.parameters = parameters; + (_a = (_c = this.parameters).resources) !== null && _a !== void 0 ? _a : (_c.resources = {}); + (_b = (_d = this.parameters).patterns) !== null && _b !== void 0 ? _b : (_d.patterns = {}); + } + operation() { + return operations_1.default.PNAccessManagerGrantToken; + } + validate() { + var _a, _b, _c, _d, _e, _f; + const { keySet: { subscribeKey, publishKey, secretKey }, resources, patterns, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!publishKey) + return 'Missing Publish Key'; + if (!secretKey) + return 'Missing Secret Key'; + if (!resources && !patterns) + return 'Missing either Resources or Patterns'; + if (this.isVspPermissions(this.parameters) && + ('channels' in ((_a = this.parameters.resources) !== null && _a !== void 0 ? _a : {}) || + 'uuids' in ((_b = this.parameters.resources) !== null && _b !== void 0 ? _b : {}) || + 'groups' in ((_c = this.parameters.resources) !== null && _c !== void 0 ? _c : {}) || + 'channels' in ((_d = this.parameters.patterns) !== null && _d !== void 0 ? _d : {}) || + 'uuids' in ((_e = this.parameters.patterns) !== null && _e !== void 0 ? _e : {}) || + 'groups' in ((_f = this.parameters.patterns) !== null && _f !== void 0 ? _f : {}))) + return ('Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`,' + + ' `groups` and `authorized_uuid`'); + let permissionsEmpty = true; + [this.parameters.resources, this.parameters.patterns].forEach((refPerm) => { + Object.keys(refPerm !== null && refPerm !== void 0 ? refPerm : {}).forEach((scope) => { + var _a; + if (refPerm && permissionsEmpty && Object.keys((_a = refPerm[scope]) !== null && _a !== void 0 ? _a : {}).length > 0) { + permissionsEmpty = false; + } }); - } - if (spaces_1) { - Object.keys(spaces_1).forEach(function (spaceId) { - params.permissions.resources.channels[spaceId] = extractPermissions(spaces_1[spaceId]); - }); - } - if (groups_1) { - Object.keys(groups_1).forEach(function (group) { - params.permissions.resources.groups[group] = extractPermissions(groups_1[group]); - }); - } - } - if (patterns) { - var users_2 = patterns.users, spaces_2 = patterns.spaces, groups_2 = patterns.groups; - if (users_2) { - Object.keys(users_2).forEach(function (userId) { - params.permissions.patterns.uuids[userId] = extractPermissions(users_2[userId]); - }); - } - if (spaces_2) { - Object.keys(spaces_2).forEach(function (spaceId) { - params.permissions.patterns.channels[spaceId] = extractPermissions(spaces_2[spaceId]); - }); - } - if (groups_2) { - Object.keys(groups_2).forEach(function (group) { - params.permissions.patterns.groups[group] = extractPermissions(groups_2[group]); - }); - } - } - if (ttl || ttl === 0) { - params.ttl = ttl; - } - if (meta) { - params.permissions.meta = meta; - } - if (authorizedUserId) { - params.permissions.uuid = "".concat(authorizedUserId); // ensure this is a string - } - return params; -} -function prepareMessagePayload(_modules, incomingParams) { - if (hasVspTerms(incomingParams)) { - return prepareMessagePayloadVsp(_modules, incomingParams); + }); + if (permissionsEmpty) + return 'Missing values for either Resources or Patterns'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse.data.token; + }); + } + get path() { + return `/v3/pam/${this.parameters.keySet.subscribeKey}/grant`; + } + get body() { + const { ttl, meta } = this.parameters; + const body = Object.assign({}, (ttl || ttl === 0 ? { ttl } : {})); + const uuid = this.isVspPermissions(this.parameters) + ? this.parameters.authorizedUserId + : this.parameters.authorized_uuid; + const permissions = {}; + const resourcePermissions = {}; + const patternPermissions = {}; + const mapPermissions = (name, permissionBit, type, permissions) => { + if (!permissions[type]) + permissions[type] = {}; + permissions[type][name] = permissionBit; + }; + const { resources, patterns } = this.parameters; + [resources, patterns].forEach((refPerm, idx) => { + var _a, _b, _c, _d, _e; + const target = idx === 0 ? resourcePermissions : patternPermissions; + let channelsPermissions = {}; + let channelGroupsPermissions = {}; + let uuidsPermissions = {}; + if (!target.channels) + target.channels = {}; + if (!target.groups) + target.groups = {}; + if (!target.uuids) + target.uuids = {}; + if (!target.users) + target.users = {}; + if (!target.spaces) + target.spaces = {}; + if (refPerm) { + if ('spaces' in refPerm || 'users' in refPerm) { + channelsPermissions = (_a = refPerm.spaces) !== null && _a !== void 0 ? _a : {}; + uuidsPermissions = (_b = refPerm.users) !== null && _b !== void 0 ? _b : {}; + } + else if ('channels' in refPerm || 'uuids' in refPerm || 'groups' in refPerm) { + channelsPermissions = (_c = refPerm.channels) !== null && _c !== void 0 ? _c : {}; + channelGroupsPermissions = (_d = refPerm.groups) !== null && _d !== void 0 ? _d : {}; + uuidsPermissions = (_e = refPerm.uuids) !== null && _e !== void 0 ? _e : {}; + } + } + Object.keys(channelsPermissions).forEach((channel) => mapPermissions(channel, this.extractPermissions(channelsPermissions[channel]), 'channels', target)); + Object.keys(channelGroupsPermissions).forEach((groups) => mapPermissions(groups, this.extractPermissions(channelGroupsPermissions[groups]), 'groups', target)); + Object.keys(uuidsPermissions).forEach((uuids) => mapPermissions(uuids, this.extractPermissions(uuidsPermissions[uuids]), 'uuids', target)); + }); + if (uuid) + permissions.uuid = `${uuid}`; + permissions.resources = resourcePermissions; + permissions.patterns = patternPermissions; + permissions.meta = meta !== null && meta !== void 0 ? meta : {}; + body.permissions = permissions; + return JSON.stringify(body); + } + extractPermissions(permissions) { + let permissionsResult = 0; + if ('join' in permissions && permissions.join) + permissionsResult |= 128; + if ('update' in permissions && permissions.update) + permissionsResult |= 64; + if ('get' in permissions && permissions.get) + permissionsResult |= 32; + if ('delete' in permissions && permissions.delete) + permissionsResult |= 8; + if ('manage' in permissions && permissions.manage) + permissionsResult |= 4; + if ('write' in permissions && permissions.write) + permissionsResult |= 2; + if ('read' in permissions && permissions.read) + permissionsResult |= 1; + return permissionsResult; + } + isVspPermissions(parameters) { + var _a, _b, _c, _d; + return ('authorizedUserId' in parameters || + 'spaces' in ((_a = parameters.resources) !== null && _a !== void 0 ? _a : {}) || + 'users' in ((_b = parameters.resources) !== null && _b !== void 0 ? _b : {}) || + 'spaces' in ((_c = parameters.patterns) !== null && _c !== void 0 ? _c : {}) || + 'users' in ((_d = parameters.patterns) !== null && _d !== void 0 ? _d : {})); } - var ttl = incomingParams.ttl, resources = incomingParams.resources, patterns = incomingParams.patterns, meta = incomingParams.meta, authorized_uuid = incomingParams.authorized_uuid; - var params = { - ttl: 0, - permissions: { - resources: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, - spaces: {}, // not used, needed for api backward compatibility - }, - patterns: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, - spaces: {}, // not used, needed for api backward compatibility - }, - meta: {}, - }, - }; - if (resources) { - var uuids_1 = resources.uuids, channels_1 = resources.channels, groups_3 = resources.groups; - if (uuids_1) { - Object.keys(uuids_1).forEach(function (uuid) { - params.permissions.resources.uuids[uuid] = extractPermissions(uuids_1[uuid]); - }); - } - if (channels_1) { - Object.keys(channels_1).forEach(function (channel) { - params.permissions.resources.channels[channel] = extractPermissions(channels_1[channel]); - }); - } - if (groups_3) { - Object.keys(groups_3).forEach(function (group) { - params.permissions.resources.groups[group] = extractPermissions(groups_3[group]); - }); - } - } - if (patterns) { - var uuids_2 = patterns.uuids, channels_2 = patterns.channels, groups_4 = patterns.groups; - if (uuids_2) { - Object.keys(uuids_2).forEach(function (uuid) { - params.permissions.patterns.uuids[uuid] = extractPermissions(uuids_2[uuid]); - }); - } - if (channels_2) { - Object.keys(channels_2).forEach(function (channel) { - params.permissions.patterns.channels[channel] = extractPermissions(channels_2[channel]); - }); - } - if (groups_4) { - Object.keys(groups_4).forEach(function (group) { - params.permissions.patterns.groups[group] = extractPermissions(groups_4[group]); - }); - } - } - if (ttl || ttl === 0) { - params.ttl = ttl; - } - if (meta) { - params.permissions.meta = meta; - } - if (authorized_uuid) { - params.permissions.uuid = "".concat(authorized_uuid); // ensure this is a string - } - return params; -} -function validateParams(modules, incomingParams) { - var _a, _b, _c, _d, _e, _f; - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!config.publishKey) - return 'Missing Publish Key'; - if (!config.secretKey) - return 'Missing Secret Key'; - if (!incomingParams.resources && !incomingParams.patterns) - return 'Missing either Resources or Patterns.'; - var hasAuthorizedUuid = (incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.authorized_uuid) !== undefined; - var hasUuidResources = ((_a = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _a === void 0 ? void 0 : _a.uuids) !== undefined; - var hasChannelResources = ((_b = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _b === void 0 ? void 0 : _b.channels) !== undefined; - var hasGroupResources = ((_c = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.resources) === null || _c === void 0 ? void 0 : _c.groups) !== undefined; - var hasUuidPatterns = ((_d = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _d === void 0 ? void 0 : _d.uuids) !== undefined; - var hasChannelPatterns = ((_e = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _e === void 0 ? void 0 : _e.channels) !== undefined; - var hasGroupPatterns = ((_f = incomingParams === null || incomingParams === void 0 ? void 0 : incomingParams.patterns) === null || _f === void 0 ? void 0 : _f.groups) !== undefined; - var hasLegacyTerms = hasAuthorizedUuid || - hasUuidResources || - hasUuidPatterns || - hasChannelResources || - hasChannelPatterns || - hasGroupResources || - hasGroupPatterns; - if (hasVspTerms(incomingParams) && hasLegacyTerms) { - return ('Cannot mix `users`, `spaces` and `authorizedUserId` ' + - 'with `uuids`, `channels`, `groups` and `authorized_uuid`'); - } - if ((incomingParams.resources && - (!incomingParams.resources.uuids || Object.keys(incomingParams.resources.uuids).length === 0) && - (!incomingParams.resources.channels || Object.keys(incomingParams.resources.channels).length === 0) && - (!incomingParams.resources.groups || Object.keys(incomingParams.resources.groups).length === 0) && - (!incomingParams.resources.users || Object.keys(incomingParams.resources.users).length === 0) && - (!incomingParams.resources.spaces || Object.keys(incomingParams.resources.spaces).length === 0)) || - (incomingParams.patterns && - (!incomingParams.patterns.uuids || Object.keys(incomingParams.patterns.uuids).length === 0) && - (!incomingParams.patterns.channels || Object.keys(incomingParams.patterns.channels).length === 0) && - (!incomingParams.patterns.groups || Object.keys(incomingParams.patterns.groups).length === 0) && - (!incomingParams.patterns.users || Object.keys(incomingParams.patterns.users).length === 0) && - (!incomingParams.patterns.spaces || Object.keys(incomingParams.patterns.spaces).length === 0))) { - return 'Missing values for either Resources or Patterns.'; - } -} -exports.validateParams = validateParams; -function postURL(modules) { - var config = modules.config; - return "/v3/pam/".concat(config.subscribeKey, "/grant"); -} -exports.postURL = postURL; -function usePost() { - return true; -} -exports.usePost = usePost; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return false; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams() { - return {}; -} -exports.prepareParams = prepareParams; -function postPayload(modules, incomingParams) { - return prepareMessagePayload(modules, incomingParams); -} -exports.postPayload = postPayload; -function handleResponse(modules, response) { - var token = response.data.token; - return token; } -exports.handleResponse = handleResponse; +exports.GrantTokenRequest = GrantTokenRequest; diff --git a/lib/core/endpoints/access_manager/revoke_token.js b/lib/core/endpoints/access_manager/revoke_token.js index 81f04e9e5..648136fcc 100644 --- a/lib/core/endpoints/access_manager/revoke_token.js +++ b/lib/core/endpoints/access_manager/revoke_token.js @@ -1,41 +1,52 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNAccessManagerRevokeToken; }, - validateParams: function (modules, token) { - var secretKey = modules.config.secretKey; - if (!secretKey) { +exports.RevokeTokenRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../types/transport-request"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class RevokeTokenRequest extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNAccessManagerRevokeToken; + } + validate() { + if (!this.parameters.keySet.secretKey) return 'Missing Secret Key'; - } - if (!token) { + if (!this.parameters.token) return "token can't be empty"; - } - }, - getURL: function (_a, token) { - var config = _a.config; - return "/v3/pam/".concat(config.subscribeKey, "/grant/").concat(utils_1.default.encodeString(token)); - }, - useDelete: function () { return true; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return false; }, - prepareParams: function (_a) { - var config = _a.config; - return ({ - uuid: config.getUUID(), + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return {}; }); - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, -}; -exports.default = endpoint; + } + get path() { + const { keySet: { subscribeKey }, token, } = this.parameters; + return `/v3/pam/${subscribeKey}/grant/${(0, utils_1.encodeString)(token)}`; + } +} +exports.RevokeTokenRequest = RevokeTokenRequest; diff --git a/lib/core/endpoints/actions/add_message_action.js b/lib/core/endpoints/actions/add_message_action.js index fef7705ba..6f82bd0d5 100644 --- a/lib/core/endpoints/actions/add_message_action.js +++ b/lib/core/endpoints/actions/add_message_action.js @@ -1,67 +1,69 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.postPayload = exports.prepareParams = exports.isAuthSupported = exports.getRequestHeaders = exports.getRequestTimeout = exports.postURL = exports.usePost = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNAddMessageActionOperation; -} -exports.getOperation = getOperation; -function validateParams(_a, incomingParams) { - var config = _a.config; - var action = incomingParams.action, channel = incomingParams.channel, messageTimetoken = incomingParams.messageTimetoken; - if (!messageTimetoken) - return 'Missing message timetoken'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!channel) - return 'Missing message channel'; - if (!action) - return 'Missing Action'; - if (!action.value) - return 'Missing Action.value'; - if (!action.type) - return 'Missing Action.type'; - if (action.type.length > 15) - return 'Action.type value exceed maximum length of 15'; -} -exports.validateParams = validateParams; -function usePost() { - return true; -} -exports.usePost = usePost; -function postURL(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel, messageTimetoken = incomingParams.messageTimetoken; - return "/v1/message-actions/".concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(channel), "/message/").concat(messageTimetoken); -} -exports.postURL = postURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function getRequestHeaders() { - return { 'Content-Type': 'application/json' }; -} -exports.getRequestHeaders = getRequestHeaders; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams() { - return {}; -} -exports.prepareParams = prepareParams; -function postPayload(modules, incomingParams) { - return incomingParams.action; -} -exports.postPayload = postPayload; -function handleResponse(modules, addMessageActionResponse) { - return { data: addMessageActionResponse.data }; +exports.AddMessageActionRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../types/transport-request"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class AddMessageActionRequest extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.POST }); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNAddMessageActionOperation; + } + validate() { + const { keySet: { subscribeKey }, action, channel, messageTimetoken, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channel) + return 'Missing message channel'; + if (!messageTimetoken) + return 'Missing message timetoken'; + if (!action) + return 'Missing Action'; + if (!action.value) + return 'Missing Action.value'; + if (!action.type) + return 'Missing Action.type'; + if (action.type.length > 15) + return 'Action.type value exceed maximum length of 15'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return { data: serviceResponse.data }; + }); + } + get headers() { + return { 'Content-Type': 'application/json' }; + } + get path() { + const { keySet: { subscribeKey }, channel, messageTimetoken, } = this.parameters; + return `/v1/message-actions/${subscribeKey}/channel/${(0, utils_1.encodeString)(channel)}/message/${messageTimetoken}`; + } + get body() { + return JSON.stringify(this.parameters.action); + } } -exports.handleResponse = handleResponse; +exports.AddMessageActionRequest = AddMessageActionRequest; diff --git a/lib/core/endpoints/actions/get_message_actions.js b/lib/core/endpoints/actions/get_message_actions.js index 669face9a..3a0ffcd86 100644 --- a/lib/core/endpoints/actions/get_message_actions.js +++ b/lib/core/endpoints/actions/get_message_actions.js @@ -1,59 +1,66 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNGetMessageActionsOperation; -} -exports.getOperation = getOperation; -function validateParams(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!channel) - return 'Missing message channel'; -} -exports.validateParams = validateParams; -function getURL(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel; - return "/v1/message-actions/".concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(channel)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var limit = incomingParams.limit, start = incomingParams.start, end = incomingParams.end; - var outgoingParams = {}; - if (limit) - outgoingParams.limit = limit; - if (start) - outgoingParams.start = start; - if (end) - outgoingParams.end = end; - return outgoingParams; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, getMessageActionsResponse) { - /** @type GetMessageActionsResponse */ - var response = { data: getMessageActionsResponse.data, start: null, end: null }; - if (response.data.length) { - response.end = response.data[response.data.length - 1].actionTimetoken; - response.start = response.data[0].actionTimetoken; +exports.GetMessageActionsRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class GetMessageActionsRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNGetMessageActionsOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channel) + return 'Missing message channel'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + let start = null; + let end = null; + if (serviceResponse.data.length > 0) { + start = serviceResponse.data[0].actionTimetoken; + end = serviceResponse.data[serviceResponse.data.length - 1].actionTimetoken; + } + return { + data: serviceResponse.data, + more: serviceResponse.more, + start, + end, + }; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v1/message-actions/${subscribeKey}/channel/${(0, utils_1.encodeString)(channel)}`; + } + get queryParameters() { + const { limit, start, end } = this.parameters; + return Object.assign(Object.assign(Object.assign({}, (start ? { start } : {})), (end ? { end } : {})), (limit ? { limit } : {})); } - return response; } -exports.handleResponse = handleResponse; +exports.GetMessageActionsRequest = GetMessageActionsRequest; diff --git a/lib/core/endpoints/actions/remove_message_action.js b/lib/core/endpoints/actions/remove_message_action.js index b70bc0a18..95d0a1969 100644 --- a/lib/core/endpoints/actions/remove_message_action.js +++ b/lib/core/endpoints/actions/remove_message_action.js @@ -1,53 +1,57 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.useDelete = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNRemoveMessageActionOperation; -} -exports.getOperation = getOperation; -function validateParams(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel, actionTimetoken = incomingParams.actionTimetoken, messageTimetoken = incomingParams.messageTimetoken; - if (!messageTimetoken) - return 'Missing message timetoken'; - if (!actionTimetoken) - return 'Missing action timetoken'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (!channel) - return 'Missing message channel'; -} -exports.validateParams = validateParams; -function useDelete() { - return true; -} -exports.useDelete = useDelete; -function getURL(_a, incomingParams) { - var config = _a.config; - var channel = incomingParams.channel, actionTimetoken = incomingParams.actionTimetoken, messageTimetoken = incomingParams.messageTimetoken; - return "/v1/message-actions/".concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(channel), "/message/").concat(messageTimetoken, "/action/").concat(actionTimetoken); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams() { - return {}; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, removeMessageActionResponse) { - return { data: removeMessageActionResponse.data }; -} -exports.handleResponse = handleResponse; +exports.RemoveMessageAction = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../types/transport-request"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class RemoveMessageAction extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNRemoveMessageActionOperation; + } + validate() { + const { keySet: { subscribeKey }, channel, messageTimetoken, actionTimetoken, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channel) + return 'Missing message action channel'; + if (!messageTimetoken) + return 'Missing message timetoken'; + if (!actionTimetoken) + return 'Missing action timetoken'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return { data: serviceResponse.data }; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, actionTimetoken, messageTimetoken, } = this.parameters; + return `/v1/message-actions/${subscribeKey}/channel/${(0, utils_1.encodeString)(channel)}/message/${messageTimetoken}/action/${actionTimetoken}`; + } +} +exports.RemoveMessageAction = RemoveMessageAction; diff --git a/lib/core/endpoints/channel_groups/add_channels.js b/lib/core/endpoints/channel_groups/add_channels.js index 7c7426e5b..aa4720f56 100644 --- a/lib/core/endpoints/channel_groups/add_channels.js +++ b/lib/core/endpoints/channel_groups/add_channels.js @@ -1,50 +1,57 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNAddChannelsToGroupOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var channels = incomingParams.channels, channelGroup = incomingParams.channelGroup; - var config = modules.config; - if (!channelGroup) - return 'Missing Channel Group'; - if (!channels || channels.length === 0) - return 'Missing Channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group/").concat(utils_1.default.encodeString(channelGroup)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - return { - add: channels.join(','), - }; -} -exports.prepareParams = prepareParams; -function handleResponse() { - return {}; +exports.AddChannelGroupChannelsRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class AddChannelGroupChannelsRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNAddChannelsToGroupOperation; + } + validate() { + const { keySet: { subscribeKey }, channels, channelGroup, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channelGroup) + return 'Missing Channel Group'; + if (!channels) + return 'Missing channels'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channelGroup, } = this.parameters; + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${(0, utils_1.encodeString)(channelGroup)}`; + } + get queryParameters() { + return { add: this.parameters.channels.join(',') }; + } } -exports.handleResponse = handleResponse; +exports.AddChannelGroupChannelsRequest = AddChannelGroupChannelsRequest; diff --git a/lib/core/endpoints/channel_groups/delete_group.js b/lib/core/endpoints/channel_groups/delete_group.js index 4ee651809..e1def77fa 100644 --- a/lib/core/endpoints/channel_groups/delete_group.js +++ b/lib/core/endpoints/channel_groups/delete_group.js @@ -1,45 +1,51 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.getRequestTimeout = exports.isAuthSupported = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNRemoveGroupOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - if (!channelGroup) - return 'Missing Channel Group'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group/").concat(utils_1.default.encodeString(channelGroup), "/remove"); -} -exports.getURL = getURL; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function prepareParams() { - return {}; -} -exports.prepareParams = prepareParams; -function handleResponse() { - return {}; +exports.DeleteChannelGroupRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class DeleteChannelGroupRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNRemoveGroupOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channelGroup) + return 'Missing Channel Group'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channelGroup, } = this.parameters; + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${(0, utils_1.encodeString)(channelGroup)}/remove`; + } } -exports.handleResponse = handleResponse; +exports.DeleteChannelGroupRequest = DeleteChannelGroupRequest; diff --git a/lib/core/endpoints/channel_groups/list_channels.js b/lib/core/endpoints/channel_groups/list_channels.js index 6e385eec4..247359860 100644 --- a/lib/core/endpoints/channel_groups/list_channels.js +++ b/lib/core/endpoints/channel_groups/list_channels.js @@ -1,47 +1,51 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNChannelsForGroupOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - if (!channelGroup) - return 'Missing Channel Group'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group/").concat(utils_1.default.encodeString(channelGroup)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams() { - return {}; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - return { - channels: serverResponse.payload.channels, - }; +exports.ListChannelGroupChannels = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class ListChannelGroupChannels extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNChannelsForGroupOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channelGroup) + return 'Missing Channel Group'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return { channels: serviceResponse.payload.channels }; + }); + } + get path() { + const { keySet: { subscribeKey }, channelGroup, } = this.parameters; + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${(0, utils_1.encodeString)(channelGroup)}`; + } } -exports.handleResponse = handleResponse; +exports.ListChannelGroupChannels = ListChannelGroupChannels; diff --git a/lib/core/endpoints/channel_groups/list_groups.js b/lib/core/endpoints/channel_groups/list_groups.js index e97da0540..6e8b8b6b1 100644 --- a/lib/core/endpoints/channel_groups/list_groups.js +++ b/lib/core/endpoints/channel_groups/list_groups.js @@ -1,42 +1,47 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -function getOperation() { - return operations_1.default.PNChannelGroupsOperation; -} -exports.getOperation = getOperation; -function validateParams(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules) { - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group"); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams() { - return {}; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - return { - groups: serverResponse.payload.groups, - }; +exports.ListChannelGroupsRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +class ListChannelGroupsRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNChannelGroupsOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return { groups: serviceResponse.payload.groups }; + }); + } + get path() { + return `/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`; + } } -exports.handleResponse = handleResponse; +exports.ListChannelGroupsRequest = ListChannelGroupsRequest; diff --git a/lib/core/endpoints/channel_groups/remove_channels.js b/lib/core/endpoints/channel_groups/remove_channels.js index 74aa55bcf..cca35a99f 100644 --- a/lib/core/endpoints/channel_groups/remove_channels.js +++ b/lib/core/endpoints/channel_groups/remove_channels.js @@ -1,50 +1,57 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNRemoveChannelsFromGroupOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var channels = incomingParams.channels, channelGroup = incomingParams.channelGroup; - var config = modules.config; - if (!channelGroup) - return 'Missing Channel Group'; - if (!channels || channels.length === 0) - return 'Missing Channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var channelGroup = incomingParams.channelGroup; - var config = modules.config; - return "/v1/channel-registration/sub-key/".concat(config.subscribeKey, "/channel-group/").concat(utils_1.default.encodeString(channelGroup)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - return { - remove: channels.join(','), - }; -} -exports.prepareParams = prepareParams; -function handleResponse() { - return {}; +exports.RemoveChannelGroupChannelsRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class RemoveChannelGroupChannelsRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNRemoveChannelsFromGroupOperation; + } + validate() { + const { keySet: { subscribeKey }, channels, channelGroup, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channelGroup) + return 'Missing Channel Group'; + if (!channels) + return 'Missing channels'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channelGroup, } = this.parameters; + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${(0, utils_1.encodeString)(channelGroup)}`; + } + get queryParameters() { + return { remove: this.parameters.channels.join(',') }; + } } -exports.handleResponse = handleResponse; +exports.RemoveChannelGroupChannelsRequest = RemoveChannelGroupChannelsRequest; diff --git a/lib/core/endpoints/endpoint.js b/lib/core/endpoints/endpoint.js deleted file mode 100644 index 9fa8a127e..000000000 --- a/lib/core/endpoints/endpoint.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -/** */ -// endpoint definition structure diff --git a/lib/core/endpoints/fetch_messages.js b/lib/core/endpoints/fetch_messages.js index ba1c5e7ec..f3935c84e 100644 --- a/lib/core/endpoints/fetch_messages.js +++ b/lib/core/endpoints/fetch_messages.js @@ -1,120 +1,173 @@ "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../constants/operations")); -var utils_1 = __importDefault(require("../utils")); -function __processMessage(modules, message) { - var result = {}; - if (!modules.cryptoModule) { - result.payload = message; - return result; +exports.FetchMessagesRequest = void 0; +const pubnub_error_1 = require("../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../errors/pubnub-api-error"); +const request_1 = require("../components/request"); +const operations_1 = __importDefault(require("../constants/operations")); +const History = __importStar(require("../types/api/history")); +const utils_1 = require("../utils"); +const LOG_VERBOSITY = false; +const INCLUDE_MESSAGE_TYPE = true; +const STRINGIFY_TIMETOKENS = false; +const INCLUDE_UUID = true; +const SINGLE_CHANNEL_MESSAGES_COUNT = 100; +const MULTIPLE_CHANNELS_MESSAGES_COUNT = 25; +class FetchMessagesRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e; + super(); + this.parameters = parameters; + const includeMessageActions = (_a = parameters.includeMessageActions) !== null && _a !== void 0 ? _a : false; + const defaultCount = parameters.channels.length > 1 || includeMessageActions + ? MULTIPLE_CHANNELS_MESSAGES_COUNT + : SINGLE_CHANNEL_MESSAGES_COUNT; + if (!parameters.count) + parameters.count = defaultCount; + else + parameters.count = Math.min(parameters.count, defaultCount); + if (parameters.includeUuid) + parameters.includeUUID = parameters.includeUuid; + else + (_b = parameters.includeUUID) !== null && _b !== void 0 ? _b : (parameters.includeUUID = INCLUDE_UUID); + (_c = parameters.stringifiedTimeToken) !== null && _c !== void 0 ? _c : (parameters.stringifiedTimeToken = STRINGIFY_TIMETOKENS); + (_d = parameters.includeMessageType) !== null && _d !== void 0 ? _d : (parameters.includeMessageType = INCLUDE_MESSAGE_TYPE); + (_e = parameters.logVerbosity) !== null && _e !== void 0 ? _e : (parameters.logVerbosity = LOG_VERBOSITY); } - try { - var decryptedData = modules.cryptoModule.decrypt(message); - var decryptedPayload = decryptedData instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decryptedData)) : decryptedData; - result.payload = decryptedPayload; - return result; + operation() { + return operations_1.default.PNFetchMessagesOperation; } - catch (e) { - if (modules.config.logVerbosity && console && console.log) - console.log('decryption error', e.message); - result.payload = message; - result.error = "Error while decrypting message content: ".concat(e.message); + validate() { + const { keySet: { subscribeKey }, channels, includeMessageActions, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channels) + return 'Missing channels'; + if (includeMessageActions !== undefined && includeMessageActions && channels.length > 1) + return ('History can return actions data for a single channel only. Either pass a single channel ' + + 'or disable the includeMessageActions flag.'); } - return result; -} -function getOperation() { - return operations_1.default.PNFetchMessagesOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var channels = incomingParams.channels, _a = incomingParams.includeMessageActions, includeMessageActions = _a === void 0 ? false : _a; - var config = modules.config; - if (!channels || channels.length === 0) - return 'Missing channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (includeMessageActions && channels.length > 1) { - throw new TypeError('History can return actions data for a single channel only. ' + - 'Either pass a single channel or disable the includeMessageActions flag.'); + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + const responseChannels = (_a = serviceResponse.channels) !== null && _a !== void 0 ? _a : {}; + const channels = {}; + Object.keys(responseChannels).forEach((channel) => { + channels[channel] = responseChannels[channel].map((payload) => { + if (payload.message_type === null) + payload.message_type = History.PubNubMessageType.Message; + const processedPayload = this.processPayload(channel, payload); + const item = { + channel, + timetoken: payload.timetoken, + message: processedPayload.payload, + messageType: payload.message_type, + uuid: payload.uuid, + }; + if (payload.actions) { + const itemWithActions = item; + itemWithActions.actions = payload.actions; + itemWithActions.data = payload.actions; + } + if (payload.meta) + item.meta = payload.meta; + if (processedPayload.error) + item.error = processedPayload.error; + return item; + }); + }); + if (serviceResponse.more) + return { channels, more: serviceResponse.more }; + return { channels }; + }); } -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.includeMessageActions, includeMessageActions = _b === void 0 ? false : _b; - var config = modules.config; - var endpoint = !includeMessageActions ? 'history' : 'history-with-actions'; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v3/".concat(endpoint, "/sub-key/").concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(stringifiedChannels)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var channels = incomingParams.channels, start = incomingParams.start, end = incomingParams.end, includeMessageActions = incomingParams.includeMessageActions, count = incomingParams.count, _a = incomingParams.stringifiedTimeToken, stringifiedTimeToken = _a === void 0 ? false : _a, _b = incomingParams.includeMeta, includeMeta = _b === void 0 ? false : _b, includeUuid = incomingParams.includeUuid, _c = incomingParams.includeUUID, includeUUID = _c === void 0 ? true : _c, _d = incomingParams.includeMessageType, includeMessageType = _d === void 0 ? true : _d; - var outgoingParams = {}; - if (count) { - outgoingParams.max = count; + get path() { + const { keySet: { subscribeKey }, channels, includeMessageActions, } = this.parameters; + const endpoint = !includeMessageActions ? 'history' : 'history-with-actions'; + return `/v3/${endpoint}/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels)}`; } - else { - outgoingParams.max = channels.length > 1 || includeMessageActions === true ? 25 : 100; + get queryParameters() { + const { start, end, count, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeMessageType ? { include_message_type: 'true' } : {})); } - if (start) - outgoingParams.start = start; - if (end) - outgoingParams.end = end; - if (stringifiedTimeToken) - outgoingParams.string_message_token = 'true'; - if (includeMeta) - outgoingParams.include_meta = 'true'; - if (includeUUID && includeUuid !== false) - outgoingParams.include_uuid = 'true'; - if (includeMessageType) - outgoingParams.include_message_type = 'true'; - return outgoingParams; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - var response = { - channels: {}, - }; - Object.keys(serverResponse.channels || {}).forEach(function (channelName) { - response.channels[channelName] = []; - (serverResponse.channels[channelName] || []).forEach(function (messageEnvelope) { - var announce = {}; - var processedMessgeResult = __processMessage(modules, messageEnvelope.message); - announce.channel = channelName; - announce.timetoken = messageEnvelope.timetoken; - announce.message = processedMessgeResult.payload; - announce.messageType = messageEnvelope.message_type; - announce.uuid = messageEnvelope.uuid; - if (messageEnvelope.actions) { - announce.actions = messageEnvelope.actions; - // This should be kept for few updates for existing clients consistency. - announce.data = messageEnvelope.actions; - } - if (messageEnvelope.meta) { - announce.meta = messageEnvelope.meta; - } - if (processedMessgeResult.error) - announce.error = processedMessgeResult.error; - response.channels[channelName].push(announce); - }); - }); - if (serverResponse.more) { - response.more = serverResponse.more; + processPayload(channel, payload) { + const { crypto, logVerbosity } = this.parameters; + if (!crypto || typeof payload.message !== 'string') + return { payload: payload.message }; + let decryptedPayload; + let error; + try { + const decryptedData = crypto.decrypt(payload.message); + decryptedPayload = + decryptedData instanceof ArrayBuffer + ? JSON.parse(FetchMessagesRequest.decoder.decode(decryptedData)) + : decryptedData; + } + catch (err) { + if (logVerbosity) + console.log(`decryption error`, err.message); + decryptedPayload = payload.message; + error = `Error while decrypting message content: ${err.message}`; + } + if (!error && + decryptedPayload && + payload.message_type == History.PubNubMessageType.Files && + typeof decryptedPayload === 'object' && + this.isFileMessage(decryptedPayload)) { + const fileMessage = decryptedPayload; + return { + payload: { + message: fileMessage.message, + file: Object.assign(Object.assign({}, fileMessage.file), { url: this.parameters.getFileUrl({ channel, id: fileMessage.file.id, name: fileMessage.file.name }) }), + }, + error, + }; + } + return { payload: decryptedPayload, error }; + } + isFileMessage(payload) { + return payload.file !== undefined; } - return response; } -exports.handleResponse = handleResponse; +exports.FetchMessagesRequest = FetchMessagesRequest; diff --git a/lib/core/endpoints/file_upload/delete_file.js b/lib/core/endpoints/file_upload/delete_file.js index 1e9529932..00f0a40b5 100644 --- a/lib/core/endpoints/file_upload/delete_file.js +++ b/lib/core/endpoints/file_upload/delete_file.js @@ -1,37 +1,55 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNListFilesOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { +exports.DeleteFileRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../types/transport-request"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class DeleteFileRequest extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNDeleteFileOperation; + } + validate() { + const { channel, id, name } = this.parameters; + if (!channel) return "channel can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.id)) { + if (!id) return "file id can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.name)) { + if (!name) return "file name can't be empty"; - } - }, - useDelete: function () { return true; }, - getURL: function (_a, params) { - var config = _a.config; - return "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(params.channel), "/files/").concat(params.id, "/").concat(params.name); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function () { return ({}); }, - handleResponse: function (_, response) { return ({ - status: response.status, - }); }, -}; -exports.default = endpoint; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, id, channel, name, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/files/${id}/${name}`; + } +} +exports.DeleteFileRequest = DeleteFileRequest; diff --git a/lib/core/endpoints/file_upload/download_file.js b/lib/core/endpoints/file_upload/download_file.js index 65d4c6ee4..a5d6fae93 100644 --- a/lib/core/endpoints/file_upload/download_file.js +++ b/lib/core/endpoints/file_upload/download_file.js @@ -1,5 +1,4 @@ "use strict"; -// Download_file.js 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) { @@ -9,96 +8,55 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -/** */ -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNDownloadFileOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { +exports.DownloadFileRequest = void 0; +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class DownloadFileRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNDownloadFileOperation; + } + validate() { + const { channel, id, name } = this.parameters; + if (!channel) return "channel can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.name)) { - return "name can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.id)) { - return "id can't be empty"; - } - }, - useGetFile: function () { return true; }, - getFileURL: function (_a, params) { - var config = _a.config; - return "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(params.channel), "/files/").concat(params.id, "/").concat(params.name); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - ignoreBody: function () { return true; }, - forceBuffered: function () { return true; }, - prepareParams: function () { return ({}); }, - handleResponse: function (_a, res, params) { - var PubNubFile = _a.PubNubFile, config = _a.config, cryptography = _a.cryptography, cryptoModule = _a.cryptoModule; - return __awaiter(void 0, void 0, void 0, function () { - var body, _b; - var _c, _d; - return __generator(this, function (_e) { - switch (_e.label) { - case 0: - body = res.response.body; - if (!(PubNubFile.supportsEncryptFile && (params.cipherKey || cryptoModule))) return [3 /*break*/, 5]; - if (!(params.cipherKey == null)) return [3 /*break*/, 2]; - return [4 /*yield*/, cryptoModule.decryptFile(PubNubFile.create({ data: body, name: params.name }), PubNubFile)]; - case 1: - _b = (_e.sent()).data; - return [3 /*break*/, 4]; - case 2: return [4 /*yield*/, cryptography.decrypt((_c = params.cipherKey) !== null && _c !== void 0 ? _c : config.cipherKey, body)]; - case 3: - _b = _e.sent(); - _e.label = 4; - case 4: - body = _b; - _e.label = 5; - case 5: return [2 /*return*/, PubNubFile.create({ - data: body, - name: (_d = res.response.name) !== null && _d !== void 0 ? _d : params.name, - mimeType: res.response.type, - })]; - } - }); + if (!id) + return "file id can't be empty"; + if (!name) + return "file name can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const { cipherKey, crypto, cryptography, name, PubNubFile } = this.parameters; + const mimeType = response.headers['content-type']; + let decryptedFile; + let body = response.body; + if (PubNubFile.supportsEncryptFile && (cipherKey || crypto)) { + if (cipherKey && cryptography) + body = yield cryptography.decrypt(cipherKey, body); + else if (!cipherKey && crypto) + decryptedFile = yield crypto.decryptFile(PubNubFile.create({ data: body, name: name, mimeType }), PubNubFile); + } + return (decryptedFile + ? decryptedFile + : PubNubFile.create({ + data: body, + name, + mimeType, + })); }); - }, -}; -exports.default = endpoint; + } + get path() { + const { keySet: { subscribeKey }, channel, id, name, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/files/${id}/${name}`; + } +} +exports.DownloadFileRequest = DownloadFileRequest; diff --git a/lib/core/endpoints/file_upload/generate_upload_url.js b/lib/core/endpoints/file_upload/generate_upload_url.js index c35b508b4..4f89bc5c5 100644 --- a/lib/core/endpoints/file_upload/generate_upload_url.js +++ b/lib/core/endpoints/file_upload/generate_upload_url.js @@ -1,39 +1,60 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNGenerateUploadUrlOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { +exports.GenerateFileUploadUrlRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../types/transport-request"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class GenerateFileUploadUrlRequest extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.POST }); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNGenerateUploadUrlOperation; + } + validate() { + if (!this.parameters.channel) return "channel can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.name)) { - return "name can't be empty"; - } - }, - usePost: function () { return true; }, - postURL: function (_a, params) { - var config = _a.config; - return "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(params.channel), "/generate-upload-url"); - }, - postPayload: function (_, params) { return ({ - name: params.name, - }); }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function () { return ({}); }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - file_upload_request: response.file_upload_request, - }); }, -}; -exports.default = endpoint; + if (!this.parameters.name) + return "'name' can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return { + id: serviceResponse.data.id, + name: serviceResponse.data.name, + url: serviceResponse.file_upload_request.url, + formFields: serviceResponse.file_upload_request.form_fields, + }; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/generate-upload-url`; + } + get body() { + return JSON.stringify({ name: this.parameters.name }); + } +} +exports.GenerateFileUploadUrlRequest = GenerateFileUploadUrlRequest; diff --git a/lib/core/endpoints/file_upload/get_file_url.js b/lib/core/endpoints/file_upload/get_file_url.js index e7cb0e33e..91879738f 100644 --- a/lib/core/endpoints/file_upload/get_file_url.js +++ b/lib/core/endpoints/file_upload/get_file_url.js @@ -1,41 +1,47 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var endpoint_1 = require("../../components/endpoint"); -var utils_1 = __importDefault(require("../../utils")); -exports.default = (function (modules, _a) { - var channel = _a.channel, id = _a.id, name = _a.name; - var config = modules.config, networking = modules.networking, tokenManager = modules.tokenManager; - if (!channel) { - throw new endpoint_1.PubNubError('Validation failed, check status for details', (0, endpoint_1.createValidationError)("channel can't be empty")); - } - if (!id) { - throw new endpoint_1.PubNubError('Validation failed, check status for details', (0, endpoint_1.createValidationError)("file id can't be empty")); +exports.GetFileDownloadUrlRequest = void 0; +const transport_request_1 = require("../../types/transport-request"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class GetFileDownloadUrlRequest extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.LOCAL }); + this.parameters = parameters; } - if (!name) { - throw new endpoint_1.PubNubError('Validation failed, check status for details', (0, endpoint_1.createValidationError)("file name can't be empty")); + operation() { + return operations_1.default.PNGetFileUrlOperation; } - var url = "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(channel), "/files/").concat(id, "/").concat(name); - var params = {}; - params.uuid = config.getUUID(); - params.pnsdk = (0, endpoint_1.generatePNSDK)(config); - var tokenOrKey = tokenManager.getToken() || config.getAuthKey(); - if (tokenOrKey) { - params.auth = tokenOrKey; + validate() { + const { channel, id, name } = this.parameters; + if (!channel) + return "channel can't be empty"; + if (!id) + return "file id can't be empty"; + if (!name) + return "file name can't be empty"; } - if (config.secretKey) { - (0, endpoint_1.signRequest)(modules, url, params, {}, { - getOperation: function () { return 'PubNubGetFileUrlOperation'; }, + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + return response.url; }); } - var queryParams = Object.keys(params) - .map(function (key) { return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(params[key])); }) - .join('&'); - if (queryParams !== '') { - return "".concat(networking.getStandardOrigin()).concat(url, "?").concat(queryParams); + get path() { + const { channel, id, name, keySet: { subscribeKey }, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/files/${id}/${name}`; } - return "".concat(networking.getStandardOrigin()).concat(url); -}); +} +exports.GetFileDownloadUrlRequest = GetFileDownloadUrlRequest; diff --git a/lib/core/endpoints/file_upload/list_files.js b/lib/core/endpoints/file_upload/list_files.js index 64b8f28f0..f258331b8 100644 --- a/lib/core/endpoints/file_upload/list_files.js +++ b/lib/core/endpoints/file_upload/list_files.js @@ -1,42 +1,57 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNListFilesOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { +exports.FilesListRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +const LIMIT = 100; +class FilesListRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a; + var _b; + super(); + this.parameters = parameters; + (_a = (_b = this.parameters).limit) !== null && _a !== void 0 ? _a : (_b.limit = LIMIT); + } + operation() { + return operations_1.default.PNListFilesOperation; + } + validate() { + if (!this.parameters.channel) return "channel can't be empty"; - } - }, - getURL: function (_a, params) { - var config = _a.config; - return "/v1/files/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(params.channel), "/files"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var outParams = {}; - if (params.limit) { - outParams.limit = params.limit; - } - if (params.next) { - outParams.next = params.next; - } - return outParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - next: response.next, - count: response.count, - }); }, -}; -exports.default = endpoint; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v1/files/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/files`; + } + get queryParameters() { + const { limit, next } = this.parameters; + return Object.assign({ limit: limit }, (next ? { next } : {})); + } +} +exports.FilesListRequest = FilesListRequest; diff --git a/lib/core/endpoints/file_upload/publish_file.js b/lib/core/endpoints/file_upload/publish_file.js index 9a0a5584a..f69228964 100644 --- a/lib/core/endpoints/file_upload/publish_file.js +++ b/lib/core/endpoints/file_upload/publish_file.js @@ -1,66 +1,70 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var base64_codec_1 = require("../../components/base64_codec"); -var preparePayload = function (modules, payload) { - var stringifiedPayload = JSON.stringify(payload); - if (modules.cryptoModule) { - var encrypted = modules.cryptoModule.encrypt(stringifiedPayload); - stringifiedPayload = typeof encrypted === 'string' ? encrypted : (0, base64_codec_1.encode)(encrypted); - stringifiedPayload = JSON.stringify(stringifiedPayload); +exports.PublishFileMessageRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const base64_codec_1 = require("../../components/base64_codec"); +const utils_1 = require("../../utils"); +const STORE_IN_HISTORY = true; +class PublishFileMessageRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a; + var _b; + super(); + this.parameters = parameters; + (_a = (_b = this.parameters).storeInHistory) !== null && _a !== void 0 ? _a : (_b.storeInHistory = STORE_IN_HISTORY); } - return stringifiedPayload || ''; -}; -var endpoint = { - getOperation: function () { return operations_1.default.PNPublishFileOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { + operation() { + return operations_1.default.PNPublishFileMessageOperation; + } + validate() { + const { channel, fileId, fileName } = this.parameters; + if (!channel) return "channel can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.fileId)) { + if (!fileId) return "file id can't be empty"; - } - if (!(params === null || params === void 0 ? void 0 : params.fileName)) { + if (!fileName) return "file name can't be empty"; - } - }, - getURL: function (modules, params) { - var _a = modules.config, publishKey = _a.publishKey, subscribeKey = _a.subscribeKey; - var message = { - message: params.message, - file: { - name: params.fileName, - id: params.fileId, - }, - }; - var payload = preparePayload(modules, message); - return "/v1/files/publish-file/".concat(publishKey, "/").concat(subscribeKey, "/0/").concat(utils_1.default.encodeString(params.channel), "/0/").concat(utils_1.default.encodeString(payload)); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var outParams = {}; - if (params.ttl) { - outParams.ttl = params.ttl; - } - if (params.storeInHistory !== undefined) { - outParams.store = params.storeInHistory ? '1' : '0'; - } - if (params.meta && typeof params.meta === 'object') { - outParams.meta = JSON.stringify(params.meta); - } - return outParams; - }, - handleResponse: function (_, response) { return ({ - timetoken: response['2'], - }); }, -}; -exports.default = endpoint; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + return { timetoken: serviceResponse[2] }; + }); + } + get path() { + const { message, channel, keySet: { publishKey, subscribeKey }, fileId, fileName, } = this.parameters; + const fileMessage = Object.assign({ file: { + name: fileName, + id: fileId, + } }, (message ? { message } : {})); + return `/v1/files/publish-file/${publishKey}/${subscribeKey}/0/${(0, utils_1.encodeString)(channel)}/0/${(0, utils_1.encodeString)(this.prepareMessagePayload(fileMessage))}`; + } + get queryParameters() { + const { storeInHistory, ttl, meta } = this.parameters; + return Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {})); + } + prepareMessagePayload(payload) { + const { crypto } = this.parameters; + if (!crypto) + return JSON.stringify(payload) || ''; + const encrypted = crypto.encrypt(JSON.stringify(payload)); + return JSON.stringify(typeof encrypted === 'string' ? encrypted : (0, base64_codec_1.encode)(encrypted)); + } +} +exports.PublishFileMessageRequest = PublishFileMessageRequest; diff --git a/lib/core/endpoints/file_upload/send_file.js b/lib/core/endpoints/file_upload/send_file.js index 34aba2be1..ca036ee19 100644 --- a/lib/core/endpoints/file_upload/send_file.js +++ b/lib/core/endpoints/file_upload/send_file.js @@ -8,188 +8,111 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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) { + return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var endpoint_1 = require("../../components/endpoint"); -var sendFile = function (_a) { - var _this = this; - var generateUploadUrl = _a.generateUploadUrl, publishFile = _a.publishFile, _b = _a.modules, PubNubFile = _b.PubNubFile, config = _b.config, cryptography = _b.cryptography, cryptoModule = _b.cryptoModule, networking = _b.networking; - return function (_a) { - var channel = _a.channel, input = _a.file, message = _a.message, cipherKey = _a.cipherKey, meta = _a.meta, ttl = _a.ttl, storeInHistory = _a.storeInHistory; - return __awaiter(_this, void 0, void 0, function () { - var file, _b, _c, url, formFields, _d, id, name, _e, formFieldsWithMimeType, result, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, e_1, errorBody, reason, retries, wasSuccessful, publishResult, e_2; - return __generator(this, function (_t) { - switch (_t.label) { - case 0: - if (!channel) { - throw new endpoint_1.PubNubError('Validation failed, check status for details', (0, endpoint_1.createValidationError)("channel can't be empty")); - } - if (!input) { - throw new endpoint_1.PubNubError('Validation failed, check status for details', (0, endpoint_1.createValidationError)("file can't be empty")); - } - file = PubNubFile.create(input); - return [4 /*yield*/, generateUploadUrl({ channel: channel, name: file.name })]; - case 1: - _b = _t.sent(), _c = _b.file_upload_request, url = _c.url, formFields = _c.form_fields, _d = _b.data, id = _d.id, name = _d.name; - if (!(PubNubFile.supportsEncryptFile && (cipherKey || cryptoModule))) return [3 /*break*/, 6]; - if (!(cipherKey == null)) return [3 /*break*/, 3]; - return [4 /*yield*/, cryptoModule.encryptFile(file, PubNubFile)]; - case 2: - _e = _t.sent(); - return [3 /*break*/, 5]; - case 3: return [4 /*yield*/, cryptography.encryptFile(cipherKey, file, PubNubFile)]; - case 4: - _e = _t.sent(); - _t.label = 5; - case 5: - file = _e; - _t.label = 6; - case 6: - formFieldsWithMimeType = formFields; - if (file.mimeType) { - formFieldsWithMimeType = formFields.map(function (entry) { - if (entry.key === 'Content-Type') - return { key: entry.key, value: file.mimeType }; - return entry; - }); - } - _t.label = 7; - case 7: - _t.trys.push([7, 21, , 22]); - if (!(PubNubFile.supportsFileUri && input.uri)) return [3 /*break*/, 10]; - _g = (_f = networking).POSTFILE; - _h = [url, formFieldsWithMimeType]; - return [4 /*yield*/, file.toFileUri()]; - case 8: return [4 /*yield*/, _g.apply(_f, _h.concat([_t.sent()]))]; - case 9: - result = _t.sent(); - return [3 /*break*/, 20]; - case 10: - if (!PubNubFile.supportsFile) return [3 /*break*/, 13]; - _k = (_j = networking).POSTFILE; - _l = [url, formFieldsWithMimeType]; - return [4 /*yield*/, file.toFile()]; - case 11: return [4 /*yield*/, _k.apply(_j, _l.concat([_t.sent()]))]; - case 12: - result = _t.sent(); - return [3 /*break*/, 20]; - case 13: - if (!PubNubFile.supportsBuffer) return [3 /*break*/, 16]; - _o = (_m = networking).POSTFILE; - _p = [url, formFieldsWithMimeType]; - return [4 /*yield*/, file.toBuffer()]; - case 14: return [4 /*yield*/, _o.apply(_m, _p.concat([_t.sent()]))]; - case 15: - result = _t.sent(); - return [3 /*break*/, 20]; - case 16: - if (!PubNubFile.supportsBlob) return [3 /*break*/, 19]; - _r = (_q = networking).POSTFILE; - _s = [url, formFieldsWithMimeType]; - return [4 /*yield*/, file.toBlob()]; - case 17: return [4 /*yield*/, _r.apply(_q, _s.concat([_t.sent()]))]; - case 18: - result = _t.sent(); - return [3 /*break*/, 20]; - case 19: throw new Error('Unsupported environment'); - case 20: return [3 /*break*/, 22]; - case 21: - e_1 = _t.sent(); - if (e_1.response && typeof e_1.response.text === 'string') { - errorBody = e_1.response.text; - reason = /(.*)<\/Message>/gi.exec(errorBody); - throw new endpoint_1.PubNubError(reason ? "Upload to bucket failed: ".concat(reason[1]) : 'Upload to bucket failed.', e_1); - } - else { - throw new endpoint_1.PubNubError('Upload to bucket failed.', e_1); - } - return [3 /*break*/, 22]; - case 22: - if (result.status !== 204) { - throw new endpoint_1.PubNubError('Upload to bucket was unsuccessful', result); - } - retries = config.fileUploadPublishRetryLimit; - wasSuccessful = false; - publishResult = { timetoken: '0' }; - _t.label = 23; - case 23: - _t.trys.push([23, 25, , 26]); - return [4 /*yield*/, publishFile({ - channel: channel, - message: message, - fileId: id, - fileName: name, - meta: meta, - storeInHistory: storeInHistory, - ttl: ttl, - })]; - case 24: - /* eslint-disable-next-line no-await-in-loop */ - publishResult = _t.sent(); - wasSuccessful = true; - return [3 /*break*/, 26]; - case 25: - e_2 = _t.sent(); - retries -= 1; - return [3 /*break*/, 26]; - case 26: - if (!wasSuccessful && retries > 0) return [3 /*break*/, 23]; - _t.label = 27; - case 27: - if (!wasSuccessful) { - throw new endpoint_1.PubNubError('Publish failed. You may want to execute that operation manually using pubnub.publishFile', { - channel: channel, - id: id, - name: name, - }); - } - else { - return [2 /*return*/, { - timetoken: publishResult.timetoken, - id: id, - name: name, - }]; - } - return [2 /*return*/]; +exports.SendFileRequest = void 0; +const generate_upload_url_1 = require("./generate_upload_url"); +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const operations_1 = __importDefault(require("../../constants/operations")); +const upload_file_1 = require("./upload-file"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const categories_1 = __importDefault(require("../../constants/categories")); +class SendFileRequest { + constructor(parameters) { + var _a; + this.parameters = parameters; + this.file = (_a = this.parameters.PubNubFile) === null || _a === void 0 ? void 0 : _a.create(parameters.file); + if (!this.file) + throw new Error('File upload error: unable to create File object.'); + } + process() { + return __awaiter(this, void 0, void 0, function* () { + let fileName; + let fileId; + return this.generateFileUploadUrl() + .then((result) => { + fileName = result.name; + fileId = result.id; + return this.uploadFile(result); + }) + .then((result) => { + if (result.status !== 204) { + throw new pubnub_error_1.PubNubError('Upload to bucket was unsuccessful', { + error: true, + statusCode: result.status, + category: categories_1.default.PNUnknownCategory, + operation: operations_1.default.PNPublishFileOperation, + errorData: { message: result.message }, + }); } + }) + .then(() => this.publishFileMessage(fileId, fileName)) + .catch((error) => { + if (error instanceof pubnub_error_1.PubNubError) + throw error; + const apiError = !(error instanceof pubnub_api_error_1.PubNubAPIError) ? pubnub_api_error_1.PubNubAPIError.create(error) : error; + throw new pubnub_error_1.PubNubError('File upload error.', apiError.toStatus(operations_1.default.PNPublishFileOperation)); }); }); - }; -}; -exports.default = (function (deps) { - var f = sendFile(deps); - return function (params, cb) { - var resultP = f(params); - if (typeof cb === 'function') { - resultP.then(function (result) { return cb(null, result); }).catch(function (error) { return cb(error, null); }); - return resultP; - } - return resultP; - }; -}); + } + generateFileUploadUrl() { + return __awaiter(this, void 0, void 0, function* () { + const request = new generate_upload_url_1.GenerateFileUploadUrlRequest(Object.assign(Object.assign({}, this.parameters), { name: this.file.name, keySet: this.parameters.keySet })); + return this.parameters.sendRequest(request); + }); + } + uploadFile(uploadParameters) { + return __awaiter(this, void 0, void 0, function* () { + const { cipherKey, PubNubFile, crypto, cryptography } = this.parameters; + const { id, name, url, formFields } = uploadParameters; + if (this.parameters.PubNubFile.supportsEncryptFile) { + if (!cipherKey && crypto) + this.file = (yield crypto.encryptFile(this.file, PubNubFile)); + else if (cipherKey && cryptography) + this.file = (yield cryptography.encryptFile(cipherKey, this.file, PubNubFile)); + } + return this.parameters.sendRequest(new upload_file_1.UploadFileRequest({ + fileId: id, + fileName: name, + file: this.file, + uploadUrl: url, + formFields, + })); + }); + } + publishFileMessage(fileId, fileName) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b, _c, _d; + let result = { timetoken: '0' }; + let retries = this.parameters.fileUploadPublishRetryLimit; + let publishError; + let wasSuccessful = false; + do { + try { + result = yield this.parameters.publishFile(Object.assign(Object.assign({}, this.parameters), { fileId, fileName })); + wasSuccessful = true; + } + catch (error) { + if (error instanceof pubnub_error_1.PubNubError) + publishError = error; + retries -= 1; + } + } while (!wasSuccessful && retries > 0); + if (!wasSuccessful) { + throw new pubnub_error_1.PubNubError('Publish failed. You may want to execute that operation manually using pubnub.publishFile', { + error: true, + category: (_b = (_a = publishError.status) === null || _a === void 0 ? void 0 : _a.category) !== null && _b !== void 0 ? _b : categories_1.default.PNUnknownCategory, + statusCode: (_d = (_c = publishError.status) === null || _c === void 0 ? void 0 : _c.statusCode) !== null && _d !== void 0 ? _d : 0, + channel: this.parameters.channel, + id: fileId, + name: fileName, + }); + } + else + return { status: 200, timetoken: result.timetoken, id: fileId, name: fileName }; + }); + } +} +exports.SendFileRequest = SendFileRequest; diff --git a/lib/core/endpoints/file_upload/types.js b/lib/core/endpoints/file_upload/types.js deleted file mode 100644 index 1e44d895d..000000000 --- a/lib/core/endpoints/file_upload/types.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -/** */ diff --git a/lib/core/endpoints/file_upload/upload-file.js b/lib/core/endpoints/file_upload/upload-file.js new file mode 100644 index 000000000..fefdb0f2b --- /dev/null +++ b/lib/core/endpoints/file_upload/upload-file.js @@ -0,0 +1,68 @@ +"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 __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UploadFileRequest = void 0; +const transport_request_1 = require("../../types/transport-request"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +class UploadFileRequest extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.POST }); + this.parameters = parameters; + const mimeType = parameters.file.mimeType; + if (mimeType) { + parameters.formFields = parameters.formFields.map((entry) => { + if (entry.name === 'Content-Type') + return { name: entry.name, value: mimeType }; + return entry; + }); + } + } + operation() { + return operations_1.default.PNPublishFileOperation; + } + validate() { + const { fileId, fileName, file, uploadUrl } = this.parameters; + if (!fileId) + return "Validation failed: file 'id' can't be empty"; + if (!fileName) + return "Validation failed: file 'name' can't be empty"; + if (!file) + return "Validation failed: 'file' can't be empty"; + if (!uploadUrl) + return "Validation failed: file upload 'url' can't be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + return { + status: response.status, + message: response.body ? UploadFileRequest.decoder.decode(response.body) : 'OK', + }; + }); + } + request() { + return Object.assign(Object.assign({}, super.request()), { origin: new URL(this.parameters.uploadUrl).origin, timeout: 300 }); + } + get path() { + const { pathname, search } = new URL(this.parameters.uploadUrl); + return `${pathname}${search}`; + } + get body() { + return this.parameters.file; + } + get formData() { + return this.parameters.formFields; + } +} +exports.UploadFileRequest = UploadFileRequest; diff --git a/lib/core/endpoints/history/delete_messages.js b/lib/core/endpoints/history/delete_messages.js index 7a0e4df4a..6556ff638 100644 --- a/lib/core/endpoints/history/delete_messages.js +++ b/lib/core/endpoints/history/delete_messages.js @@ -1,55 +1,56 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.useDelete = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNDeleteMessagesOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var channel = incomingParams.channel; - var config = modules.config; - if (!channel) - return 'Missing channel'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function useDelete() { - return true; -} -exports.useDelete = useDelete; -function getURL(modules, incomingParams) { - var channel = incomingParams.channel; - var config = modules.config; - return "/v3/history/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(channel)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var start = incomingParams.start, end = incomingParams.end; - var outgoingParams = {}; - if (start) - outgoingParams.start = start; - if (end) - outgoingParams.end = end; - return outgoingParams; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - return serverResponse.payload; -} -exports.handleResponse = handleResponse; +exports.DeleteMessageRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../types/transport-request"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class DeleteMessageRequest extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNDeleteMessagesOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channel) + return 'Missing channel'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v3/history/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeString)(channel)}`; + } + get queryParameters() { + const { start, end } = this.parameters; + return Object.assign(Object.assign({}, (start ? { start } : {})), (end ? { end } : {})); + } +} +exports.DeleteMessageRequest = DeleteMessageRequest; diff --git a/lib/core/endpoints/history/get_history.js b/lib/core/endpoints/history/get_history.js index 5cbc72ad3..02691675a 100644 --- a/lib/core/endpoints/history/get_history.js +++ b/lib/core/endpoints/history/get_history.js @@ -1,100 +1,107 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function __processMessage(modules, message) { - var result = {}; - if (!modules.cryptoModule) { - result.payload = message; - return result; +exports.GetHistoryRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +const LOG_VERBOSITY = false; +const INCLUDE_METADATA = false; +const STRINGIFY_TIMETOKENS = false; +const MESSAGES_COUNT = 100; +class GetHistoryRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c; + super(); + this.parameters = parameters; + if (parameters.count) + parameters.count = Math.min(parameters.count, MESSAGES_COUNT); + else + parameters.count = MESSAGES_COUNT; + (_a = parameters.stringifiedTimeToken) !== null && _a !== void 0 ? _a : (parameters.stringifiedTimeToken = STRINGIFY_TIMETOKENS); + (_b = parameters.includeMeta) !== null && _b !== void 0 ? _b : (parameters.includeMeta = INCLUDE_METADATA); + (_c = parameters.logVerbosity) !== null && _c !== void 0 ? _c : (parameters.logVerbosity = LOG_VERBOSITY); } - try { - var decryptedData = modules.cryptoModule.decrypt(message); - var decryptedPayload = decryptedData instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decryptedData)) : decryptedData; - result.payload = decryptedPayload; - return result; + operation() { + return operations_1.default.PNHistoryOperation; } - catch (e) { - if (modules.config.logVerbosity && console && console.log) - console.log('decryption error', e.message); - result.payload = message; - result.error = "Error while decrypting message content: ".concat(e.message); + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + if (!this.parameters.channel) + return 'Missing channel'; } - return result; -} -function getOperation() { - return operations_1.default.PNHistoryOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var channel = incomingParams.channel; - var config = modules.config; - if (!channel) - return 'Missing channel'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var channel = incomingParams.channel; - var config = modules.config; - return "/v2/history/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(channel)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var start = incomingParams.start, end = incomingParams.end, reverse = incomingParams.reverse, _a = incomingParams.count, count = _a === void 0 ? 100 : _a, _b = incomingParams.stringifiedTimeToken, stringifiedTimeToken = _b === void 0 ? false : _b, _c = incomingParams.includeMeta, includeMeta = _c === void 0 ? false : _c; - var outgoingParams = { - include_token: 'true', - }; - outgoingParams.count = count; - if (start) - outgoingParams.start = start; - if (end) - outgoingParams.end = end; - if (stringifiedTimeToken) - outgoingParams.string_message_token = 'true'; - if (reverse != null) - outgoingParams.reverse = reverse.toString(); - if (includeMeta) - outgoingParams.include_meta = 'true'; - return outgoingParams; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - var response = { - messages: [], - startTimeToken: serverResponse[1], - endTimeToken: serverResponse[2], - }; - if (Array.isArray(serverResponse[0])) { - serverResponse[0].forEach(function (serverHistoryItem) { - var processedMessgeResult = __processMessage(modules, serverHistoryItem.message); - var item = { - timetoken: serverHistoryItem.timetoken, - entry: processedMessgeResult.payload, + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + const messages = serviceResponse[0]; + const startTimeToken = serviceResponse[1]; + const endTimeToken = serviceResponse[2]; + if (!Array.isArray(messages)) + return { messages: [], startTimeToken, endTimeToken }; + return { + messages: messages.map((payload) => { + const processedPayload = this.processPayload(payload.message); + const item = { + entry: processedPayload.payload, + timetoken: payload.timetoken, + }; + if (processedPayload.error) + item.error = processedPayload.error; + if (payload.meta) + item.meta = payload.meta; + return item; + }), + startTimeToken, + endTimeToken, }; - if (serverHistoryItem.meta) { - item.meta = serverHistoryItem.meta; - } - if (processedMessgeResult.error) - item.error = processedMessgeResult.error; - response.messages.push(item); }); } - return response; + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/history/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeString)(channel)}`; + } + get queryParameters() { + const { start, end, reverse, count, stringifiedTimeToken, includeMeta } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: count, include_token: 'true' }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (reverse !== undefined && reverse !== null ? { reverse: reverse.toString() } : {})), (includeMeta ? { include_meta: 'true' } : {})); + } + processPayload(payload) { + const { crypto, logVerbosity } = this.parameters; + if (!crypto || typeof payload !== 'string') + return { payload }; + let decryptedPayload; + let error; + try { + const decryptedData = crypto.decrypt(payload); + decryptedPayload = + decryptedData instanceof ArrayBuffer + ? JSON.parse(GetHistoryRequest.decoder.decode(decryptedData)) + : decryptedData; + } + catch (err) { + if (logVerbosity) + console.log(`decryption error`, err.message); + decryptedPayload = payload; + error = `Error while decrypting message content: ${err.message}`; + } + return { + payload: decryptedPayload, + error, + }; + } } -exports.handleResponse = handleResponse; +exports.GetHistoryRequest = GetHistoryRequest; diff --git a/lib/core/endpoints/history/message_counts.js b/lib/core/endpoints/history/message_counts.js index 7beb84974..66fb9ec0c 100644 --- a/lib/core/endpoints/history/message_counts.js +++ b/lib/core/endpoints/history/message_counts.js @@ -1,78 +1,63 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNMessageCounts; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var channels = incomingParams.channels, timetoken = incomingParams.timetoken, channelTimetokens = incomingParams.channelTimetokens; - var config = modules.config; - if (!channels) - return 'Missing channel'; - if (timetoken && channelTimetokens) - return 'timetoken and channelTimetokens are incompatible together'; - if (channelTimetokens && channelTimetokens.length > 1 && channels.length !== channelTimetokens.length) { - return 'Length of channelTimetokens and channels do not match'; +exports.MessageCountRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class MessageCountRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; } - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var channels = incomingParams.channels; - var config = modules.config; - var stringifiedChannels = channels.join(','); - return "/v3/history/sub-key/".concat(config.subscribeKey, "/message-counts/").concat(utils_1.default.encodeString(stringifiedChannels)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var timetoken = incomingParams.timetoken, channelTimetokens = incomingParams.channelTimetokens; - var outgoingParams = {}; - if (channelTimetokens && channelTimetokens.length === 1) { - var _a = __read(channelTimetokens, 1), tt = _a[0]; - outgoingParams.timetoken = tt; + operation() { + return operations_1.default.PNMessageCounts; } - else if (channelTimetokens) { - outgoingParams.channelsTimetoken = channelTimetokens.join(','); + validate() { + const { keySet: { subscribeKey }, channels, timetoken, channelTimetokens, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channels) + return 'Missing channels'; + if (timetoken && channelTimetokens) + return '`timetoken` and `channelTimetokens` are incompatible together'; + if (!timetoken && !channelTimetokens) + return '`timetoken` or `channelTimetokens` need to be set'; + if (channelTimetokens && channelTimetokens.length > 1 && channelTimetokens.length !== channels.length) + return 'Length of `channelTimetokens` and `channels` do not match'; } - else if (timetoken) { - outgoingParams.timetoken = timetoken; + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return { channels: serviceResponse.channels }; + }); + } + get path() { + return `/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${(0, utils_1.encodeNames)(this.parameters.channels)}`; + } + get queryParameters() { + let { channelTimetokens } = this.parameters; + if (this.parameters.timetoken) + channelTimetokens = [this.parameters.timetoken]; + return Object.assign(Object.assign({}, (channelTimetokens.length === 1 ? { timetoken: channelTimetokens[0] } : {})), (channelTimetokens.length > 1 ? { channelsTimetoken: channelTimetokens.join(',') } : {})); } - return outgoingParams; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - return { channels: serverResponse.channels }; } -exports.handleResponse = handleResponse; +exports.MessageCountRequest = MessageCountRequest; diff --git a/lib/core/endpoints/objects/channel/get.js b/lib/core/endpoints/objects/channel/get.js index b482749af..d7c3b86ed 100644 --- a/lib/core/endpoints/objects/channel/get.js +++ b/lib/core/endpoints/objects/channel/get.js @@ -1,41 +1,59 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNGetChannelMetadataOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { +exports.GetChannelMetadataRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +const INCLUDE_CUSTOM_FIELDS = true; +class GetChannelMetadataRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c; + super(); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); + } + operation() { + return operations_1.default.PNGetChannelMetadataOperation; + } + validate() { + if (!this.parameters.channel) return 'Channel cannot be empty'; - } - }, - getURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(params.channel)); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var _a; - var queryParams = {}; - queryParams.include = ['status', 'type', 'custom']; - if (params === null || params === void 0 ? void 0 : params.include) { - if (((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) === false) { - queryParams.include.pop(); + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); } - } - queryParams.include = queryParams.include.join(','); - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, -}; -exports.default = endpoint; + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}`; + } + get queryParameters() { + return { + include: ['status', 'type', ...(this.parameters.include.customFields ? ['custom'] : [])].join(','), + }; + } +} +exports.GetChannelMetadataRequest = GetChannelMetadataRequest; diff --git a/lib/core/endpoints/objects/channel/get_all.js b/lib/core/endpoints/objects/channel/get_all.js index a4e35acd2..228568d77 100644 --- a/lib/core/endpoints/objects/channel/get_all.js +++ b/lib/core/endpoints/objects/channel/get_all.js @@ -1,79 +1,57 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var endpoint = { - getOperation: function () { return operations_1.default.PNGetAllChannelMetadataOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var queryParams = {}; - queryParams.include = ['status', 'type']; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) { - queryParams.include.push('custom'); +exports.GetAllChannelsMetadataRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const INCLUDE_CUSTOM_FIELDS = false; +const INCLUDE_TOTAL_COUNT = false; +const LIMIT = 100; +class GetAllChannelsMetadataRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d; + var _e, _f; + super(); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_e = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_e.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = (_f = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_f.totalCount = INCLUDE_TOTAL_COUNT); + (_d = parameters.limit) !== null && _d !== void 0 ? _d : (parameters.limit = LIMIT); + } + operation() { + return operations_1.default.PNGetAllChannelMetadataOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); } - } - queryParams.include = queryParams.include.join(','); - if ((_b = params === null || params === void 0 ? void 0 : params.include) === null || _b === void 0 ? void 0 : _b.totalCount) { - queryParams.count = (_c = params.include) === null || _c === void 0 ? void 0 : _c.totalCount; - } - if ((_d = params === null || params === void 0 ? void 0 : params.page) === null || _d === void 0 ? void 0 : _d.next) { - queryParams.start = (_e = params.page) === null || _e === void 0 ? void 0 : _e.next; - } - if ((_f = params === null || params === void 0 ? void 0 : params.page) === null || _f === void 0 ? void 0 : _f.prev) { - queryParams.end = (_g = params.page) === null || _g === void 0 ? void 0 : _g.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - queryParams.limit = (_h = params === null || params === void 0 ? void 0 : params.limit) !== null && _h !== void 0 ? _h : 100; - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, -}; -exports.default = endpoint; + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + return `/v2/objects/${this.parameters.keySet.subscribeKey}/channels`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(','), count: `${include.totalCount}` }, (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } +} +exports.GetAllChannelsMetadataRequest = GetAllChannelsMetadataRequest; diff --git a/lib/core/endpoints/objects/channel/remove.js b/lib/core/endpoints/objects/channel/remove.js index 9942abc80..725b652ad 100644 --- a/lib/core/endpoints/objects/channel/remove.js +++ b/lib/core/endpoints/objects/channel/remove.js @@ -1,32 +1,50 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNRemoveChannelMetadataOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { +exports.RemoveChannelMetadataRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../../types/transport-request"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +class RemoveChannelMetadataRequest extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.DELETE }); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNRemoveChannelMetadataOperation; + } + validate() { + if (!this.parameters.channel) return 'Channel cannot be empty'; - } - }, - getURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(params.channel)); - }, - useDelete: function () { return true; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function () { return ({}); }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, -}; -exports.default = endpoint; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}`; + } +} +exports.RemoveChannelMetadataRequest = RemoveChannelMetadataRequest; diff --git a/lib/core/endpoints/objects/channel/set.js b/lib/core/endpoints/objects/channel/set.js index 881bf48d1..6d903debb 100644 --- a/lib/core/endpoints/objects/channel/set.js +++ b/lib/core/endpoints/objects/channel/set.js @@ -1,47 +1,65 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNSetChannelMetadataOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { +exports.SetChannelMetadataRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../../types/transport-request"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +const INCLUDE_CUSTOM_FIELDS = true; +class SetChannelMetadataRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c; + super({ method: transport_request_1.TransportMethod.PATCH }); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); + } + operation() { + return operations_1.default.PNSetChannelMetadataOperation; + } + validate() { + if (!this.parameters.channel) return 'Channel cannot be empty'; - } - if (!(params === null || params === void 0 ? void 0 : params.data)) { + if (!this.parameters.data) return 'Data cannot be empty'; - } - }, - usePatch: function () { return true; }, - patchURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(params.channel)); - }, - patchPayload: function (_, params) { return params.data; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var _a; - var queryParams = {}; - queryParams.include = ['status', 'type', 'custom']; - if (params === null || params === void 0 ? void 0 : params.include) { - if (((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) === false) { - queryParams.include.pop(); + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); } - } - queryParams.include = queryParams.include.join(','); - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, -}; -exports.default = endpoint; + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}`; + } + get queryParameters() { + return { + include: ['status', 'type', ...(this.parameters.include.customFields ? ['custom'] : [])].join(','), + }; + } + get body() { + return JSON.stringify(this.parameters.data); + } +} +exports.SetChannelMetadataRequest = SetChannelMetadataRequest; diff --git a/lib/core/endpoints/objects/member/get.js b/lib/core/endpoints/objects/member/get.js index e24405856..4329df0fc 100644 --- a/lib/core/endpoints/objects/member/get.js +++ b/lib/core/endpoints/objects/member/get.js @@ -1,98 +1,86 @@ "use strict"; -/** */ -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNGetMembersOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { - return 'channel cannot be empty'; - } - }, - getURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(params.channel), "/uuids"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; - var queryParams = {}; - queryParams.include = []; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.statusField) { - queryParams.include.push('status'); - } - if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customFields) { - queryParams.include.push('custom'); - } - if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.UUIDFields) { - queryParams.include.push('uuid'); - } - if ((_d = params.include) === null || _d === void 0 ? void 0 : _d.customUUIDFields) { - queryParams.include.push('uuid.custom'); - } - if ((_e = params.include) === null || _e === void 0 ? void 0 : _e.UUIDStatusField) { - queryParams.include.push('uuid.status'); - } - if ((_f = params.include) === null || _f === void 0 ? void 0 : _f.UUIDTypeField) { - queryParams.include.push('uuid.type'); +exports.GetChannelMembersRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +const INCLUDE_CUSTOM_FIELDS = false; +const INCLUDE_STATUS = false; +const INCLUDE_TOTAL_COUNT = false; +const INCLUDE_UUID_FIELDS = false; +const INCLUDE_UUID_STATUS_FIELD = false; +const INCLUDE_UUID_TYPE_FIELD = false; +const INCLUDE_UUID_CUSTOM_FIELDS = false; +const LIMIT = 100; +class GetChannelMembersRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j; + var _k, _l, _m, _o, _p, _q, _r; + super(); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS); + (_e = (_o = parameters.include).UUIDFields) !== null && _e !== void 0 ? _e : (_o.UUIDFields = INCLUDE_UUID_FIELDS); + (_f = (_p = parameters.include).customUUIDFields) !== null && _f !== void 0 ? _f : (_p.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS); + (_g = (_q = parameters.include).UUIDStatusField) !== null && _g !== void 0 ? _g : (_q.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD); + (_h = (_r = parameters.include).UUIDTypeField) !== null && _h !== void 0 ? _h : (_r.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD); + (_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT); + } + operation() { + return operations_1.default.PNSetMembersOperation; + } + validate() { + if (!this.parameters.channel) + return 'Channel cannot be empty'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); } - } - queryParams.include = queryParams.include.join(','); - if ((_g = params === null || params === void 0 ? void 0 : params.include) === null || _g === void 0 ? void 0 : _g.totalCount) { - queryParams.count = (_h = params.include) === null || _h === void 0 ? void 0 : _h.totalCount; - } - if ((_j = params === null || params === void 0 ? void 0 : params.page) === null || _j === void 0 ? void 0 : _j.next) { - queryParams.start = (_k = params.page) === null || _k === void 0 ? void 0 : _k.next; - } - if ((_l = params === null || params === void 0 ? void 0 : params.page) === null || _l === void 0 ? void 0 : _l.prev) { - queryParams.end = (_m = params.page) === null || _m === void 0 ? void 0 : _m.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - queryParams.limit = (_o = params === null || params === void 0 ? void 0 : params.limit) !== null && _o !== void 0 ? _o : 100; - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_p = params.sort) !== null && _p !== void 0 ? _p : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, -}; -exports.default = endpoint; + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/uuids`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + const includeFlags = []; + if (include.statusField) + includeFlags.push('status'); + if (include.customFields) + includeFlags.push('custom'); + if (include.UUIDFields) + includeFlags.push('uuid'); + if (include.UUIDStatusField) + includeFlags.push('uuid.status'); + if (include.UUIDTypeField) + includeFlags.push('uuid.type'); + if (include.customUUIDFields) + includeFlags.push('uuid.custom'); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } +} +exports.GetChannelMembersRequest = GetChannelMembersRequest; diff --git a/lib/core/endpoints/objects/member/set.js b/lib/core/endpoints/objects/member/set.js index 2aa211f29..6d6ba7cb5 100644 --- a/lib/core/endpoints/objects/member/set.js +++ b/lib/core/endpoints/objects/member/set.js @@ -1,116 +1,91 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNSetMembersOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channel)) { +exports.SetChannelMembersRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../../types/transport-request"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +const INCLUDE_CUSTOM_FIELDS = false; +const INCLUDE_TOTAL_COUNT = false; +const INCLUDE_UUID_FIELDS = false; +const INCLUDE_UUID_CUSTOM_FIELDS = false; +const LIMIT = 100; +class SetChannelMembersRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f; + var _g, _h, _j, _k; + super({ method: transport_request_1.TransportMethod.PATCH }); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_j = parameters.include).UUIDFields) !== null && _d !== void 0 ? _d : (_j.UUIDFields = INCLUDE_UUID_FIELDS); + (_e = (_k = parameters.include).customUUIDFields) !== null && _e !== void 0 ? _e : (_k.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS); + (_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT); + } + operation() { + return operations_1.default.PNSetMembersOperation; + } + validate() { + const { channel, uuids } = this.parameters; + if (!channel) return 'Channel cannot be empty'; - } - if (!(params === null || params === void 0 ? void 0 : params.uuids) || (params === null || params === void 0 ? void 0 : params.uuids.length) === 0) { + if (!uuids || uuids.length === 0) return 'UUIDs cannot be empty'; - } - }, - usePatch: function () { return true; }, - patchURL: function (_a, params) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/channels/").concat(utils_1.default.encodeString(params.channel), "/uuids"); - }, - patchPayload: function (_, params) { - var _a; - return (_a = { - set: [], - delete: [] - }, - _a[params.type] = params.uuids.map(function (uuid) { + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, channel, } = this.parameters; + return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/uuids`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + const includeFlags = ['uuid.status', 'uuid.type', 'type']; + if (include.customFields) + includeFlags.push('custom'); + if (include.UUIDFields) + includeFlags.push('uuid'); + if (include.customUUIDFields) + includeFlags.push('uuid.custom'); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } + get body() { + const { uuids, type } = this.parameters; + return JSON.stringify({ + [`${type}`]: uuids.map((uuid) => { if (typeof uuid === 'string') { - return { - uuid: { - id: uuid, - }, - }; + return { uuid: { id: uuid } }; } - return { - uuid: { id: uuid.id }, - custom: uuid.custom, - status: uuid.status, - }; - }), - _a); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var queryParams = {}; - queryParams.include = ['uuid.status', 'uuid.type', 'type']; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) { - queryParams.include.push('custom'); - } - if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customUUIDFields) { - queryParams.include.push('uuid.custom'); - } - if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.UUIDFields) { - queryParams.include.push('uuid'); - } - } - queryParams.include = queryParams.include.join(','); - if ((_d = params === null || params === void 0 ? void 0 : params.include) === null || _d === void 0 ? void 0 : _d.totalCount) { - queryParams.count = true; - } - if ((_e = params === null || params === void 0 ? void 0 : params.page) === null || _e === void 0 ? void 0 : _e.next) { - queryParams.start = (_f = params.page) === null || _f === void 0 ? void 0 : _f.next; - } - if ((_g = params === null || params === void 0 ? void 0 : params.page) === null || _g === void 0 ? void 0 : _g.prev) { - queryParams.end = (_h = params.page) === null || _h === void 0 ? void 0 : _h.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - if (params.limit != null) { - queryParams.limit = params.limit; - } - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); + else { + return { uuid: { id: uuid.id }, status: uuid.status, custom: uuid.custom }; } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, -}; -exports.default = endpoint; + }), + }); + } +} +exports.SetChannelMembersRequest = SetChannelMembersRequest; diff --git a/lib/core/endpoints/objects/membership/get.js b/lib/core/endpoints/objects/membership/get.js index 0e674260f..bc588f76c 100644 --- a/lib/core/endpoints/objects/membership/get.js +++ b/lib/core/endpoints/objects/membership/get.js @@ -1,96 +1,88 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNGetMembershipsOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils_1.default.encodeString((_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID()), "/channels"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; - var queryParams = {}; - queryParams.include = []; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.statusField) { - queryParams.include.push('status'); - } - if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customFields) { - queryParams.include.push('custom'); - } - if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.channelFields) { - queryParams.include.push('channel'); - } - if ((_d = params.include) === null || _d === void 0 ? void 0 : _d.customChannelFields) { - queryParams.include.push('channel.custom'); - } - if ((_e = params.include) === null || _e === void 0 ? void 0 : _e.channelStatusField) { - queryParams.include.push('channel.status'); - } - if ((_f = params.include) === null || _f === void 0 ? void 0 : _f.channelTypeField) { - queryParams.include.push('channel.type'); +exports.GetUUIDMembershipsRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +const INCLUDE_CUSTOM_FIELDS = false; +const INCLUDE_STATUS = false; +const INCLUDE_TOTAL_COUNT = false; +const INCLUDE_CHANNEL_FIELDS = false; +const INCLUDE_CHANNEL_STATUS_FIELD = false; +const INCLUDE_CHANNEL_TYPE_FIELD = false; +const INCLUDE_CHANNEL_CUSTOM_FIELDS = false; +const LIMIT = 100; +class GetUUIDMembershipsRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f, _g, _h, _j; + var _k, _l, _m, _o, _p, _q, _r; + super(); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS); + (_e = (_o = parameters.include).channelFields) !== null && _e !== void 0 ? _e : (_o.channelFields = INCLUDE_CHANNEL_FIELDS); + (_f = (_p = parameters.include).customChannelFields) !== null && _f !== void 0 ? _f : (_p.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); + (_g = (_q = parameters.include).channelStatusField) !== null && _g !== void 0 ? _g : (_q.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD); + (_h = (_r = parameters.include).channelTypeField) !== null && _h !== void 0 ? _h : (_r.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD); + (_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT); + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return operations_1.default.PNGetMembershipsOperation; + } + validate() { + if (!this.parameters.uuid) + return "'uuid' cannot be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); } - } - queryParams.include = queryParams.include.join(','); - if ((_g = params === null || params === void 0 ? void 0 : params.include) === null || _g === void 0 ? void 0 : _g.totalCount) { - queryParams.count = (_h = params.include) === null || _h === void 0 ? void 0 : _h.totalCount; - } - if ((_j = params === null || params === void 0 ? void 0 : params.page) === null || _j === void 0 ? void 0 : _j.next) { - queryParams.start = (_k = params.page) === null || _k === void 0 ? void 0 : _k.next; - } - if ((_l = params === null || params === void 0 ? void 0 : params.page) === null || _l === void 0 ? void 0 : _l.prev) { - queryParams.end = (_m = params.page) === null || _m === void 0 ? void 0 : _m.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - queryParams.limit = (_o = params === null || params === void 0 ? void 0 : params.limit) !== null && _o !== void 0 ? _o : 100; - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_p = params.sort) !== null && _p !== void 0 ? _p : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, -}; -exports.default = endpoint; + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}/channels`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + const includeFlags = []; + if (include.statusField) + includeFlags.push('status'); + if (include.customFields) + includeFlags.push('custom'); + if (include.channelFields) + includeFlags.push('channel'); + if (include.channelStatusField) + includeFlags.push('channel.status'); + if (include.channelTypeField) + includeFlags.push('channel.type'); + if (include.customChannelFields) + includeFlags.push('channel.custom'); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } +} +exports.GetUUIDMembershipsRequest = GetUUIDMembershipsRequest; diff --git a/lib/core/endpoints/objects/membership/set.js b/lib/core/endpoints/objects/membership/set.js index 13ea36ef5..10aaa32e3 100644 --- a/lib/core/endpoints/objects/membership/set.js +++ b/lib/core/endpoints/objects/membership/set.js @@ -1,115 +1,93 @@ "use strict"; -/** */ -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNSetMembershipsOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channels) || (params === null || params === void 0 ? void 0 : params.channels.length) === 0) { +exports.SetUUIDMembershipsRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../../types/transport-request"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +const INCLUDE_CUSTOM_FIELDS = false; +const INCLUDE_TOTAL_COUNT = false; +const INCLUDE_CHANNEL_FIELDS = false; +const INCLUDE_CHANNEL_CUSTOM_FIELDS = false; +const LIMIT = 100; +class SetUUIDMembershipsRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c, _d, _e, _f; + var _g, _h, _j, _k; + super({ method: transport_request_1.TransportMethod.PATCH }); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_j = parameters.include).channelFields) !== null && _d !== void 0 ? _d : (_j.channelFields = INCLUDE_CHANNEL_FIELDS); + (_e = (_k = parameters.include).customChannelFields) !== null && _e !== void 0 ? _e : (_k.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); + (_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT); + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return operations_1.default.PNSetMembershipsOperation; + } + validate() { + const { uuid, channels } = this.parameters; + if (!uuid) + return "'uuid' cannot be empty"; + if (!channels || channels.length === 0) return 'Channels cannot be empty'; - } - }, - usePatch: function () { return true; }, - patchURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils_1.default.encodeString((_b = params.uuid) !== null && _b !== void 0 ? _b : config.getUUID()), "/channels"); - }, - patchPayload: function (_, params) { - var _a; - return (_a = { - set: [], - delete: [] - }, - _a[params.type] = params.channels.map(function (channel) { + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}/channels`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + const includeFlags = ['channel.status', 'channel.type', 'status']; + if (include.customFields) + includeFlags.push('custom'); + if (include.channelFields) + includeFlags.push('channel'); + if (include.customChannelFields) + includeFlags.push('channel.custom'); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } + get body() { + const { channels, type } = this.parameters; + return JSON.stringify({ + [`${type}`]: channels.map((channel) => { if (typeof channel === 'string') { - return { - channel: { - id: channel, - }, - }; + return { channel: { id: channel } }; } - return { - channel: { id: channel.id }, - custom: channel.custom, - status: channel.status, - }; - }), - _a); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var queryParams = {}; - queryParams.include = ['channel.status', 'channel.type', 'status']; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) { - queryParams.include.push('custom'); - } - if ((_b = params.include) === null || _b === void 0 ? void 0 : _b.customChannelFields) { - queryParams.include.push('channel.custom'); - } - if ((_c = params.include) === null || _c === void 0 ? void 0 : _c.channelFields) { - queryParams.include.push('channel'); - } - } - queryParams.include = queryParams.include.join(','); - if ((_d = params === null || params === void 0 ? void 0 : params.include) === null || _d === void 0 ? void 0 : _d.totalCount) { - queryParams.count = true; - } - if ((_e = params === null || params === void 0 ? void 0 : params.page) === null || _e === void 0 ? void 0 : _e.next) { - queryParams.start = (_f = params.page) === null || _f === void 0 ? void 0 : _f.next; - } - if ((_g = params === null || params === void 0 ? void 0 : params.page) === null || _g === void 0 ? void 0 : _g.prev) { - queryParams.end = (_h = params.page) === null || _h === void 0 ? void 0 : _h.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - if (params.limit != null) { - queryParams.limit = params.limit; - } - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); + else { + return { channel: { id: channel.id }, status: channel.status, custom: channel.custom }; } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }); }, -}; -exports.default = endpoint; + }), + }); + } +} +exports.SetUUIDMembershipsRequest = SetUUIDMembershipsRequest; diff --git a/lib/core/endpoints/objects/uuid/get.js b/lib/core/endpoints/objects/uuid/get.js index 36e1293d6..56383f4dd 100644 --- a/lib/core/endpoints/objects/uuid/get.js +++ b/lib/core/endpoints/objects/uuid/get.js @@ -1,43 +1,60 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNGetUUIDMetadataOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils_1.default.encodeString((_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID())); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_a, params) { - var _b, _c; - var config = _a.config; - var queryParams = {}; - queryParams.uuid = (_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID(); - queryParams.include = ['status', 'type', 'custom']; - if (params === null || params === void 0 ? void 0 : params.include) { - if (((_c = params.include) === null || _c === void 0 ? void 0 : _c.customFields) === false) { - queryParams.include.pop(); +exports.GetUUIDMetadataRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +const INCLUDE_CUSTOM_FIELDS = true; +class GetUUIDMetadataRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c; + super(); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return operations_1.default.PNGetUUIDMetadataOperation; + } + validate() { + if (!this.parameters.uuid) + return "'uuid' cannot be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); } - } - queryParams.include = queryParams.include.join(','); - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, -}; -exports.default = endpoint; + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}`; + } + get queryParameters() { + const { include } = this.parameters; + return { include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(',') }; + } +} +exports.GetUUIDMetadataRequest = GetUUIDMetadataRequest; diff --git a/lib/core/endpoints/objects/uuid/get_all.js b/lib/core/endpoints/objects/uuid/get_all.js index f82c8e893..eae9bce3b 100644 --- a/lib/core/endpoints/objects/uuid/get_all.js +++ b/lib/core/endpoints/objects/uuid/get_all.js @@ -1,79 +1,55 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var endpoint = { - getOperation: function () { return operations_1.default.PNGetAllUUIDMetadataOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a) { - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_modules, params) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var queryParams = {}; - queryParams.include = ['status', 'type']; - if (params === null || params === void 0 ? void 0 : params.include) { - if ((_a = params.include) === null || _a === void 0 ? void 0 : _a.customFields) { - queryParams.include.push('custom'); +exports.GetAllUUIDMetadataRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const INCLUDE_CUSTOM_FIELDS = false; +const LIMIT = 100; +class GetAllUUIDMetadataRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c; + var _d; + super(); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_d = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_d.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = parameters.limit) !== null && _c !== void 0 ? _c : (parameters.limit = LIMIT); + } + operation() { + return operations_1.default.PNGetAllUUIDMetadataOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); } - } - queryParams.include = queryParams.include.join(','); - if ((_b = params === null || params === void 0 ? void 0 : params.include) === null || _b === void 0 ? void 0 : _b.totalCount) { - queryParams.count = (_c = params.include) === null || _c === void 0 ? void 0 : _c.totalCount; - } - if ((_d = params === null || params === void 0 ? void 0 : params.page) === null || _d === void 0 ? void 0 : _d.next) { - queryParams.start = (_e = params.page) === null || _e === void 0 ? void 0 : _e.next; - } - if ((_f = params === null || params === void 0 ? void 0 : params.page) === null || _f === void 0 ? void 0 : _f.prev) { - queryParams.end = (_g = params.page) === null || _g === void 0 ? void 0 : _g.prev; - } - if (params === null || params === void 0 ? void 0 : params.filter) { - queryParams.filter = params.filter; - } - queryParams.limit = (_h = params === null || params === void 0 ? void 0 : params.limit) !== null && _h !== void 0 ? _h : 100; - if (params === null || params === void 0 ? void 0 : params.sort) { - queryParams.sort = Object.entries((_j = params.sort) !== null && _j !== void 0 ? _j : {}).map(function (_a) { - var _b = __read(_a, 2), key = _b[0], value = _b[1]; - if (value === 'asc' || value === 'desc') { - return "".concat(key, ":").concat(value); - } - return key; - }); - } - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - next: response.next, - prev: response.prev, - }); }, -}; -exports.default = endpoint; + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + return `/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`; + } + get queryParameters() { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(',') }, (include.totalCount !== undefined ? { count: `${include.totalCount}` } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); + } +} +exports.GetAllUUIDMetadataRequest = GetAllUUIDMetadataRequest; diff --git a/lib/core/endpoints/objects/uuid/remove.js b/lib/core/endpoints/objects/uuid/remove.js index 5ad9a0599..9268a7792 100644 --- a/lib/core/endpoints/objects/uuid/remove.js +++ b/lib/core/endpoints/objects/uuid/remove.js @@ -1,37 +1,52 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNRemoveUUIDMetadataOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils_1.default.encodeString((_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID())); - }, - useDelete: function () { return true; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_a, params) { - var _b; - var config = _a.config; - return ({ - uuid: (_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID(), +exports.RemoveUUIDMetadataRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../../types/transport-request"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +class RemoveUUIDMetadataRequest extends request_1.AbstractRequest { + constructor(parameters) { + super({ method: transport_request_1.TransportMethod.DELETE }); + this.parameters = parameters; + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return operations_1.default.PNRemoveUUIDMetadataOperation; + } + validate() { + if (!this.parameters.uuid) + return "'uuid' cannot be empty"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; }); - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, -}; -exports.default = endpoint; + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}`; + } +} +exports.RemoveUUIDMetadataRequest = RemoveUUIDMetadataRequest; diff --git a/lib/core/endpoints/objects/uuid/set.js b/lib/core/endpoints/objects/uuid/set.js index 0f6f4e6e8..075c97b74 100644 --- a/lib/core/endpoints/objects/uuid/set.js +++ b/lib/core/endpoints/objects/uuid/set.js @@ -1,47 +1,67 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../../constants/operations")); -var utils_1 = __importDefault(require("../../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNSetUUIDMetadataOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.data)) { +exports.SetUUIDMetadataRequest = void 0; +const pubnub_error_1 = require("../../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); +const transport_request_1 = require("../../../types/transport-request"); +const request_1 = require("../../../components/request"); +const operations_1 = __importDefault(require("../../../constants/operations")); +const utils_1 = require("../../../utils"); +const INCLUDE_CUSTOM_FIELDS = true; +class SetUUIDMetadataRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c; + super({ method: transport_request_1.TransportMethod.PATCH }); + this.parameters = parameters; + (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); + (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); + if (this.parameters.userId) + this.parameters.uuid = this.parameters.userId; + } + operation() { + return operations_1.default.PNSetUUIDMetadataOperation; + } + validate() { + if (!this.parameters.uuid) + return "'uuid' cannot be empty"; + if (!this.parameters.data) return 'Data cannot be empty'; - } - }, - usePatch: function () { return true; }, - patchURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v2/objects/".concat(config.subscribeKey, "/uuids/").concat(utils_1.default.encodeString((_b = params.uuid) !== null && _b !== void 0 ? _b : config.getUUID())); - }, - patchPayload: function (_, params) { return params.data; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_a, params) { - var _b, _c; - var config = _a.config; - var queryParams = {}; - queryParams.uuid = (_b = params === null || params === void 0 ? void 0 : params.uuid) !== null && _b !== void 0 ? _b : config.getUUID(); - queryParams.include = ['status', 'type', 'custom']; - if (params === null || params === void 0 ? void 0 : params.include) { - if (((_c = params.include) === null || _c === void 0 ? void 0 : _c.customFields) === false) { - queryParams.include.pop(); + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); } - } - queryParams.include = queryParams.include.join(','); - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, -}; -exports.default = endpoint; + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return serviceResponse; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}`; + } + get queryParameters() { + return { + include: ['status', 'type', ...(this.parameters.include.customFields ? ['custom'] : [])].join(','), + }; + } + get body() { + return JSON.stringify(this.parameters.data); + } +} +exports.SetUUIDMetadataRequest = SetUUIDMetadataRequest; diff --git a/lib/core/endpoints/presence/get_state.js b/lib/core/endpoints/presence/get_state.js index 030ad9f8d..8373628e2 100644 --- a/lib/core/endpoints/presence/get_state.js +++ b/lib/core/endpoints/presence/get_state.js @@ -1,56 +1,66 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNGetStateOperation; -} -exports.getOperation = getOperation; -function validateParams(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.uuid, uuid = _a === void 0 ? config.UUID : _a, _b = incomingParams.channels, channels = _b === void 0 ? [] : _b; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(stringifiedChannels), "/uuid/").concat(uuid); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a; - var params = {}; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); +exports.GetPresenceStateRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class GetPresenceStateRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b; + var _c, _d; + super(); + this.parameters = parameters; + (_a = (_c = this.parameters).channels) !== null && _a !== void 0 ? _a : (_c.channels = []); + (_b = (_d = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_d.channelGroups = []); } - return params; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b; - var channelsResponse = {}; - if (channels.length === 1 && channelGroups.length === 0) { - channelsResponse[channels[0]] = serverResponse.payload; + operation() { + return operations_1.default.PNGetStateOperation; + } + validate() { + const { keySet: { subscribeKey }, channels, channelGroups, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + const { channels = [], channelGroups = [] } = this.parameters; + const state = { channels: {} }; + if (channels.length === 1 && channelGroups.length === 0) + state.channels[channels[0]] = serviceResponse.payload; + else + state.channels = serviceResponse.payload; + return state; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, channels, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${uuid}`; } - else { - channelsResponse = serverResponse.payload; + get queryParameters() { + const { channelGroups } = this.parameters; + if (!channelGroups || channelGroups.length === 0) + return {}; + return { 'channel-group': channelGroups.join(',') }; } - return { channels: channelsResponse }; } -exports.handleResponse = handleResponse; +exports.GetPresenceStateRequest = GetPresenceStateRequest; diff --git a/lib/core/endpoints/presence/heartbeat.js b/lib/core/endpoints/presence/heartbeat.js index 137bfad1a..52de83f8e 100644 --- a/lib/core/endpoints/presence/heartbeat.js +++ b/lib/core/endpoints/presence/heartbeat.js @@ -1,53 +1,61 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.getRequestTimeout = exports.isAuthSupported = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNHeartbeatOperation; -} -exports.getOperation = getOperation; -function validateParams(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(stringifiedChannels), "/heartbeat"); -} -exports.getURL = getURL; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function prepareParams(modules, incomingParams) { - var _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a, state = incomingParams.state; - var config = modules.config; - var params = {}; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); +exports.HeartbeatRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class HeartbeatRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; } - if (state) { - params.state = JSON.stringify(state); + operation() { + return operations_1.default.PNHeartbeatOperation; + } + validate() { + const { keySet: { subscribeKey }, channels = [], channelGroups = [], } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (channels.length === 0 && channelGroups.length === 0) + return 'Please provide a list of channels and/or channel-groups'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return {}; + }); + } + get path() { + const { keySet: { subscribeKey }, channels, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels !== null && channels !== void 0 ? channels : [], ',')}/heartbeat`; + } + get queryParameters() { + const { channelGroups, state, heartbeat } = this.parameters; + const query = { heartbeat: `${heartbeat}` }; + if (channelGroups && channelGroups.length !== 0) + query['channel-group'] = channelGroups.join(','); + if (state) + query.state = JSON.stringify(state); + return query; } - params.heartbeat = config.getPresenceTimeout(); - return params; -} -exports.prepareParams = prepareParams; -function handleResponse() { - return {}; } -exports.handleResponse = handleResponse; +exports.HeartbeatRequest = HeartbeatRequest; diff --git a/lib/core/endpoints/presence/here_now.js b/lib/core/endpoints/presence/here_now.js index 87cbd46e4..6900d5929 100644 --- a/lib/core/endpoints/presence/here_now.js +++ b/lib/core/endpoints/presence/here_now.js @@ -1,140 +1,95 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleError = exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNHereNowOperation; -} -exports.getOperation = getOperation; -function validateParams(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b; - var baseURL = "/v2/presence/sub-key/".concat(config.subscribeKey); - if (channels.length > 0 || channelGroups.length > 0) { - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - baseURL += "/channel/".concat(utils_1.default.encodeString(stringifiedChannels)); +exports.HereNowRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +const INCLUDE_UUID = true; +const INCLUDE_STATE = false; +class HereNowRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c; + var _d, _e, _f; + super(); + this.parameters = parameters; + (_a = (_d = this.parameters).queryParameters) !== null && _a !== void 0 ? _a : (_d.queryParameters = {}); + (_b = (_e = this.parameters).includeUUIDs) !== null && _b !== void 0 ? _b : (_e.includeUUIDs = INCLUDE_UUID); + (_c = (_f = this.parameters).includeState) !== null && _c !== void 0 ? _c : (_f.includeState = INCLUDE_STATE); } - return baseURL; -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a, _b = incomingParams.includeUUIDs, includeUUIDs = _b === void 0 ? true : _b, _c = incomingParams.includeState, includeState = _c === void 0 ? false : _c, _d = incomingParams.queryParameters, queryParameters = _d === void 0 ? {} : _d; - var params = {}; - if (!includeUUIDs) - params.disable_uuids = 1; - if (includeState) - params.state = 1; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); + operation() { + const { channels = [], channelGroups = [] } = this.parameters; + return channels.length === 0 && channelGroups.length === 0 + ? operations_1.default.PNGlobalHereNowOperation + : operations_1.default.PNHereNowOperation; } - params = __assign(__assign({}, params), queryParameters); - return params; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse, incomingParams) { - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b, _c = incomingParams.includeUUIDs, includeUUIDs = _c === void 0 ? true : _c, _d = incomingParams.includeState, includeState = _d === void 0 ? false : _d; - var prepareSingularChannel = function () { - var response = {}; - var occupantsList = []; - response.totalChannels = 1; - response.totalOccupancy = serverResponse.occupancy; - response.channels = {}; - response.channels[channels[0]] = { - occupants: occupantsList, - name: channels[0], - occupancy: serverResponse.occupancy, - }; - // We have had issues in the past with server returning responses - // that contain no uuids array - if (includeUUIDs && serverResponse.uuids) { - serverResponse.uuids.forEach(function (uuidEntry) { - if (includeState) { - occupantsList.push({ state: uuidEntry.state, uuid: uuidEntry.uuid }); - } - else { - occupantsList.push({ state: null, uuid: uuidEntry }); - } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b; + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; + const totalOccupancy = 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_channels; + const channelsPresence = {}; + let channels = {}; + if ('occupancy' in serviceResponse) { + const channel = this.parameters.channels[0]; + channels[channel] = { uuids: (_a = serviceResponse.uuids) !== null && _a !== void 0 ? _a : [], occupancy: totalOccupancy }; + } + else + channels = (_b = serviceResponse.payload.channels) !== null && _b !== void 0 ? _b : {}; + Object.keys(channels).forEach((channel) => { + const channelEntry = channels[channel]; + channelsPresence[channel] = { + occupants: this.parameters.includeUUIDs + ? channelEntry.uuids.map((uuid) => { + if (typeof uuid === 'string') + return { uuid, state: null }; + return uuid; + }) + : [], + name: channel, + occupancy: channelEntry.occupancy, + }; }); - } - return response; - }; - var prepareMultipleChannel = function () { - var response = {}; - response.totalChannels = serverResponse.payload.total_channels; - response.totalOccupancy = serverResponse.payload.total_occupancy; - response.channels = {}; - Object.keys(serverResponse.payload.channels).forEach(function (channelName) { - var channelEntry = serverResponse.payload.channels[channelName]; - var occupantsList = []; - response.channels[channelName] = { - occupants: occupantsList, - name: channelName, - occupancy: channelEntry.occupancy, + return { + totalChannels, + totalOccupancy, + channels: channelsPresence, }; - if (includeUUIDs) { - channelEntry.uuids.forEach(function (uuidEntry) { - if (includeState) { - occupantsList.push({ - state: uuidEntry.state, - uuid: uuidEntry.uuid, - }); - } - else { - occupantsList.push({ state: null, uuid: uuidEntry }); - } - }); - } - return response; }); - return response; - }; - var response; - if (channels.length > 1 || channelGroups.length > 0 || (channelGroups.length === 0 && channels.length === 0)) { - response = prepareMultipleChannel(); } - else { - response = prepareSingularChannel(); + get path() { + const { keySet: { subscribeKey }, channels, channelGroups, } = this.parameters; + let path = `/v2/presence/sub-key/${subscribeKey}`; + if ((channels && channels.length > 0) || (channelGroups && channelGroups.length > 0)) + path += `/channel/${(0, utils_1.encodeNames)(channels !== null && channels !== void 0 ? channels : [], ',')}`; + return path; } - return response; -} -exports.handleResponse = handleResponse; -function handleError(modules, params, status) { - if (status.statusCode === 402 && !this.getURL(modules, params).includes('channel')) { - status.errorData.message = - 'You have tried to perform a Global Here Now operation, ' + - 'your keyset configuration does not support that. Please provide a channel, ' + - 'or enable the Global Here Now feature from the Portal.'; + get queryParameters() { + const { channelGroups, includeUUIDs, includeState, queryParameters } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign({}, (!includeUUIDs ? { disable_uuids: '1' } : {})), ((includeState !== null && includeState !== void 0 ? includeState : false) ? { state: '1' } : {})), (channelGroups && channelGroups.length > 0 ? { 'channel-group': channelGroups.join(',') } : {})), queryParameters); } } -exports.handleError = handleError; +exports.HereNowRequest = HereNowRequest; diff --git a/lib/core/endpoints/presence/leave.js b/lib/core/endpoints/presence/leave.js index be63c00dd..ec29564ba 100644 --- a/lib/core/endpoints/presence/leave.js +++ b/lib/core/endpoints/presence/leave.js @@ -1,48 +1,63 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNUnsubscribeOperation; -} -exports.getOperation = getOperation; -function validateParams(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(stringifiedChannels), "/leave"); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a; - var params = {}; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); +exports.PresenceLeaveRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class PresenceLeaveRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + if (this.parameters.channelGroups) + this.parameters.channelGroups = Array.from(new Set(this.parameters.channelGroups)); + if (this.parameters.channels) + this.parameters.channels = Array.from(new Set(this.parameters.channels)); + } + operation() { + return operations_1.default.PNUnsubscribeOperation; + } + validate() { + const { keySet: { subscribeKey }, channels = [], channelGroups = [], } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (channels.length === 0 && channelGroups.length === 0) + return 'At least one `channel` or `channel group` should be provided.'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return {}; + }); + } + get path() { + var _a; + const { keySet: { subscribeKey }, channels, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)((_a = channels === null || channels === void 0 ? void 0 : channels.sort()) !== null && _a !== void 0 ? _a : [], ',')}/leave`; + } + get queryParameters() { + const { channelGroups } = this.parameters; + if (!channelGroups || channelGroups.length === 0) + return {}; + return { 'channel-group': channelGroups.sort().join(',') }; } - return params; -} -exports.prepareParams = prepareParams; -function handleResponse() { - return {}; } -exports.handleResponse = handleResponse; +exports.PresenceLeaveRequest = PresenceLeaveRequest; diff --git a/lib/core/endpoints/presence/set_state.js b/lib/core/endpoints/presence/set_state.js index daf813524..8ecfd935d 100644 --- a/lib/core/endpoints/presence/set_state.js +++ b/lib/core/endpoints/presence/set_state.js @@ -1,54 +1,61 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNSetStateOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var config = modules.config; - var state = incomingParams.state, _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b; - if (!state) - return 'Missing State'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; - if (channels.length === 0 && channelGroups.length === 0) { - return 'Please provide a list of channels and/or channel-groups'; +exports.SetPresenceStateRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class SetPresenceStateRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; } -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/channel/").concat(utils_1.default.encodeString(stringifiedChannels), "/uuid/").concat(utils_1.default.encodeString(config.UUID), "/data"); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var state = incomingParams.state, _a = incomingParams.channelGroups, channelGroups = _a === void 0 ? [] : _a; - var params = {}; - params.state = JSON.stringify(state); - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); + operation() { + return operations_1.default.PNSetStateOperation; + } + validate() { + const { keySet: { subscribeKey }, state, channels = [], channelGroups = [], } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!state) + return 'Missing State'; + if ((channels === null || channels === void 0 ? void 0 : channels.length) === 0 && (channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.length) === 0) + return 'Please provide a list of channels and/or channel-groups'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return { state: serviceResponse.payload }; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, channels, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels !== null && channels !== void 0 ? channels : [], ',')}/uuid/${(0, utils_1.encodeString)(uuid)}/data`; + } + get queryParameters() { + const { channelGroups, state } = this.parameters; + const query = { state: JSON.stringify(state) }; + if (channelGroups && channelGroups.length !== 0) + query['channel-group'] = channelGroups.join(','); + return query; } - return params; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - return { state: serverResponse.payload }; } -exports.handleResponse = handleResponse; +exports.SetPresenceStateRequest = SetPresenceStateRequest; diff --git a/lib/core/endpoints/presence/where_now.js b/lib/core/endpoints/presence/where_now.js index 05c069125..a536e143b 100644 --- a/lib/core/endpoints/presence/where_now.js +++ b/lib/core/endpoints/presence/where_now.js @@ -1,47 +1,51 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -function getOperation() { - return operations_1.default.PNWhereNowOperation; -} -exports.getOperation = getOperation; -function validateParams(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.uuid, uuid = _a === void 0 ? config.UUID : _a; - return "/v2/presence/sub-key/".concat(config.subscribeKey, "/uuid/").concat(utils_1.default.encodeString(uuid)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams() { - return {}; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - // This is a quick fix for when the server does not include a payload - // in where now responses - if (!serverResponse.payload) { - return { channels: [] }; +exports.WhereNowRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); +const request_1 = require("../../components/request"); +const operations_1 = __importDefault(require("../../constants/operations")); +const utils_1 = require("../../utils"); +class WhereNowRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNWhereNowOperation; + } + validate() { + if (!this.parameters.keySet.subscribeKey) + return 'Missing Subscribe Key'; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + else if (serviceResponse.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + if (!serviceResponse.payload) + return { channels: [] }; + return { channels: serviceResponse.payload.channels }; + }); + } + get path() { + const { keySet: { subscribeKey }, uuid, } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/uuid/${(0, utils_1.encodeString)(uuid)}`; } - return { channels: serverResponse.payload.channels }; } -exports.handleResponse = handleResponse; +exports.WhereNowRequest = WhereNowRequest; diff --git a/lib/core/endpoints/publish.js b/lib/core/endpoints/publish.js index f4d3dbafc..cd5d55ffb 100644 --- a/lib/core/endpoints/publish.js +++ b/lib/core/endpoints/publish.js @@ -1,93 +1,83 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.postPayload = exports.isAuthSupported = exports.getRequestTimeout = exports.postURL = exports.getURL = exports.usePost = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../constants/operations")); -var utils_1 = __importDefault(require("../utils")); -var base64_codec_1 = require("../components/base64_codec"); -function prepareMessagePayload(modules, messagePayload) { - var stringifiedPayload = JSON.stringify(messagePayload); - if (modules.cryptoModule) { - var encrypted = modules.cryptoModule.encrypt(stringifiedPayload); - stringifiedPayload = typeof encrypted === 'string' ? encrypted : (0, base64_codec_1.encode)(encrypted); - stringifiedPayload = JSON.stringify(stringifiedPayload); +exports.PublishRequest = void 0; +const pubnub_error_1 = require("../../errors/pubnub-error"); +const transport_request_1 = require("../types/transport-request"); +const request_1 = require("../components/request"); +const operations_1 = __importDefault(require("../constants/operations")); +const base64_codec_1 = require("../components/base64_codec"); +const utils_1 = require("../utils"); +const SEND_BY_POST = false; +class PublishRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a; + var _b; + super({ method: parameters.sendByPost ? transport_request_1.TransportMethod.POST : transport_request_1.TransportMethod.GET }); + this.parameters = parameters; + (_a = (_b = this.parameters).sendByPost) !== null && _a !== void 0 ? _a : (_b.sendByPost = SEND_BY_POST); } - return stringifiedPayload || ''; -} -function getOperation() { - return operations_1.default.PNPublishOperation; -} -exports.getOperation = getOperation; -function validateParams(_a, incomingParams) { - var config = _a.config; - var message = incomingParams.message, channel = incomingParams.channel; - if (!channel) - return 'Missing Channel'; - if (!message) - return 'Missing Message'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function usePost(modules, incomingParams) { - var _a = incomingParams.sendByPost, sendByPost = _a === void 0 ? false : _a; - return sendByPost; -} -exports.usePost = usePost; -function getURL(modules, incomingParams) { - var config = modules.config; - var channel = incomingParams.channel, message = incomingParams.message; - var stringifiedPayload = prepareMessagePayload(modules, message); - return "/publish/".concat(config.publishKey, "/").concat(config.subscribeKey, "/0/").concat(utils_1.default.encodeString(channel), "/0/").concat(utils_1.default.encodeString(stringifiedPayload)); -} -exports.getURL = getURL; -function postURL(modules, incomingParams) { - var config = modules.config; - var channel = incomingParams.channel; - return "/publish/".concat(config.publishKey, "/").concat(config.subscribeKey, "/0/").concat(utils_1.default.encodeString(channel), "/0"); -} -exports.postURL = postURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function postPayload(modules, incomingParams) { - var message = incomingParams.message; - return prepareMessagePayload(modules, message); -} -exports.postPayload = postPayload; -function prepareParams(modules, incomingParams) { - var meta = incomingParams.meta, _a = incomingParams.replicate, replicate = _a === void 0 ? true : _a, storeInHistory = incomingParams.storeInHistory, ttl = incomingParams.ttl; - var params = {}; - if (storeInHistory != null) { - if (storeInHistory) { - params.store = '1'; - } - else { - params.store = '0'; - } + operation() { + return operations_1.default.PNPublishOperation; } - if (ttl) { - params.ttl = ttl; + validate() { + const { message, channel, keySet: { publishKey }, } = this.parameters; + if (!channel) + return "Missing 'channel'"; + if (!message) + return "Missing 'message'"; + if (!publishKey) + return "Missing 'publishKey'"; } - if (replicate === false) { - params.norep = 'true'; + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + return { timetoken: serviceResponse[2] }; + }); } - if (meta && typeof meta === 'object') { - params.meta = JSON.stringify(meta); + get path() { + const { message, channel, keySet } = this.parameters; + const stringifiedPayload = this.prepareMessagePayload(message); + return `/publish/${keySet.publishKey}/${keySet.subscribeKey}/0/${(0, utils_1.encodeString)(channel)}/0${!this.parameters.sendByPost ? `/${(0, utils_1.encodeString)(stringifiedPayload)}` : ''}`; + } + get queryParameters() { + const { meta, replicate, storeInHistory, ttl } = this.parameters; + const query = {}; + if (storeInHistory !== undefined) + query.store = storeInHistory ? '1' : '0'; + if (ttl !== undefined) + query.ttl = ttl; + if (replicate !== undefined && !replicate) + query.norep = 'true'; + if (meta && typeof meta === 'object') + query.meta = JSON.stringify(meta); + return query; + } + get headers() { + return { 'Content-Type': 'application/json' }; + } + get body() { + return this.prepareMessagePayload(this.parameters.message); + } + prepareMessagePayload(payload) { + const { crypto } = this.parameters; + if (!crypto) + return JSON.stringify(payload) || ''; + const encrypted = crypto.encrypt(JSON.stringify(payload)); + return JSON.stringify(typeof encrypted === 'string' ? encrypted : (0, base64_codec_1.encode)(encrypted)); } - return params; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - return { timetoken: serverResponse[2] }; } -exports.handleResponse = handleResponse; +exports.PublishRequest = PublishRequest; diff --git a/lib/core/endpoints/push/add_push_channels.js b/lib/core/endpoints/push/add_push_channels.js index 8912132ba..7e6ca21d2 100644 --- a/lib/core/endpoints/push/add_push_channels.js +++ b/lib/core/endpoints/push/add_push_channels.js @@ -1,70 +1,35 @@ "use strict"; -/* */ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -function getOperation() { - return operations_1.default.PNPushNotificationEnabledChannelsOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway, channels = incomingParams.channels, topic = incomingParams.topic; - var config = modules.config; - if (!device) - return 'Missing Device ID (device)'; - if (!pushGateway) - return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) - return 'Missing APNS2 topic'; - if (!channels || channels.length === 0) - return 'Missing Channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway; - var config = modules.config; - if (pushGateway === 'apns2') { - return "/v2/push/sub-key/".concat(config.subscribeKey, "/devices-apns2/").concat(device); +exports.AddDevicePushNotificationChannelsRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const push_1 = require("./push"); +const operations_1 = __importDefault(require("../../constants/operations")); +class AddDevicePushNotificationChannelsRequest extends push_1.BasePushNotificationChannelsRequest { + constructor(parameters) { + super(Object.assign(Object.assign({}, parameters), { action: 'add' })); } - return "/v1/push/sub-key/".concat(config.subscribeKey, "/devices/").concat(device); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.environment, environment = _b === void 0 ? 'development' : _b, topic = incomingParams.topic; - var parameters = { type: pushGateway, add: channels.join(',') }; - if (pushGateway === 'apns2') { - parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); - delete parameters.type; + operation() { + return operations_1.default.PNAddPushNotificationEnabledChannelsOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + return {}; + }); } - return parameters; -} -exports.prepareParams = prepareParams; -function handleResponse() { - return {}; } -exports.handleResponse = handleResponse; +exports.AddDevicePushNotificationChannelsRequest = AddDevicePushNotificationChannelsRequest; diff --git a/lib/core/endpoints/push/list_push_channels.js b/lib/core/endpoints/push/list_push_channels.js index 1acd572ab..355026b81 100644 --- a/lib/core/endpoints/push/list_push_channels.js +++ b/lib/core/endpoints/push/list_push_channels.js @@ -1,72 +1,35 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../../constants/operations")); -function getOperation() { - return operations_1.default.PNPushNotificationEnabledChannelsOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway, topic = incomingParams.topic; - var config = modules.config; - if (!device) - return 'Missing Device ID (device)'; - if (!pushGateway) - return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) - return 'Missing APNS2 topic'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway; - var config = modules.config; - if (pushGateway === 'apns2') { - return "/v2/push/sub-key/".concat(config.subscribeKey, "/devices-apns2/").concat(device); +exports.ListDevicePushNotificationChannelsRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const push_1 = require("./push"); +const operations_1 = __importDefault(require("../../constants/operations")); +class ListDevicePushNotificationChannelsRequest extends push_1.BasePushNotificationChannelsRequest { + constructor(parameters) { + super(Object.assign(Object.assign({}, parameters), { action: 'list' })); } - return "/v1/push/sub-key/".concat(config.subscribeKey, "/devices/").concat(device); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.environment, environment = _a === void 0 ? 'development' : _a, topic = incomingParams.topic, start = incomingParams.start, count = incomingParams.count; - var parameters = { type: pushGateway }; - if (pushGateway === 'apns2') { - parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); - delete parameters.type; + operation() { + return operations_1.default.PNPushNotificationEnabledChannelsOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + return { channels: serviceResponse }; + }); } - if (start) - parameters.start = start; - if (count && count > 0) - parameters.count = count; - return parameters; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - return { channels: serverResponse }; } -exports.handleResponse = handleResponse; +exports.ListDevicePushNotificationChannelsRequest = ListDevicePushNotificationChannelsRequest; diff --git a/lib/core/endpoints/push/push.js b/lib/core/endpoints/push/push.js new file mode 100644 index 000000000..82c63aab4 --- /dev/null +++ b/lib/core/endpoints/push/push.js @@ -0,0 +1,70 @@ +"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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.BasePushNotificationChannelsRequest = void 0; +const request_1 = require("../../components/request"); +const ENVIRONMENT = 'development'; +const MAX_COUNT = 1000; +class BasePushNotificationChannelsRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a; + var _b; + super(); + this.parameters = parameters; + if (this.parameters.pushGateway === 'apns2') + (_a = (_b = this.parameters).environment) !== null && _a !== void 0 ? _a : (_b.environment = ENVIRONMENT); + if (this.parameters.count && this.parameters.count > MAX_COUNT) + this.parameters.count = MAX_COUNT; + } + operation() { + throw Error('Should be implemented in subclass.'); + } + validate() { + const { keySet: { subscribeKey }, action, device, pushGateway, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!device) + return 'Missing Device ID (device)'; + if ((action === 'add' || action === 'remove') && + (!('channels' in this.parameters) || this.parameters.channels.length === 0)) + return 'Missing Channels'; + if (!pushGateway) + return 'Missing GW Type (pushGateway: gcm or apns2)'; + if (this.parameters.pushGateway === 'apns2' && !this.parameters.topic) + return 'Missing APNS2 topic'; + } + parse(_response) { + return __awaiter(this, void 0, void 0, function* () { + throw Error('Should be implemented in subclass.'); + }); + } + get path() { + const { keySet: { subscribeKey }, action, device, pushGateway, } = this.parameters; + let path = pushGateway === 'apns2' + ? `/v2/push/sub-key/${subscribeKey}/devices-apns2/${device}` + : `/v1/push/sub-key/${subscribeKey}/devices/${device}`; + if (action === 'remove-device') + path = `${path}/remove`; + return path; + } + get queryParameters() { + const { start, count } = this.parameters; + let query = Object.assign(Object.assign({ type: this.parameters.pushGateway }, (start ? { start } : {})), (count && count > 0 ? { count } : {})); + if ('channels' in this.parameters) + query[this.parameters.action] = this.parameters.channels.join(','); + if (this.parameters.pushGateway === 'apns2') { + const { environment, topic } = this.parameters; + query = Object.assign(Object.assign({}, query), { environment: environment, topic }); + } + return query; + } +} +exports.BasePushNotificationChannelsRequest = BasePushNotificationChannelsRequest; diff --git a/lib/core/endpoints/push/remove_device.js b/lib/core/endpoints/push/remove_device.js index 80abf1028..4e71bc5ce 100644 --- a/lib/core/endpoints/push/remove_device.js +++ b/lib/core/endpoints/push/remove_device.js @@ -1,68 +1,35 @@ "use strict"; -/* */ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -function getOperation() { - return operations_1.default.PNRemoveAllPushNotificationsOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway, topic = incomingParams.topic; - var config = modules.config; - if (!device) - return 'Missing Device ID (device)'; - if (!pushGateway) - return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) - return 'Missing APNS2 topic'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway; - var config = modules.config; - if (pushGateway === 'apns2') { - return "/v2/push/sub-key/".concat(config.subscribeKey, "/devices-apns2/").concat(device, "/remove"); +exports.RemoveDevicePushNotificationRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const push_1 = require("./push"); +const operations_1 = __importDefault(require("../../constants/operations")); +class RemoveDevicePushNotificationRequest extends push_1.BasePushNotificationChannelsRequest { + constructor(parameters) { + super(Object.assign(Object.assign({}, parameters), { action: 'remove-device' })); } - return "/v1/push/sub-key/".concat(config.subscribeKey, "/devices/").concat(device, "/remove"); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.environment, environment = _a === void 0 ? 'development' : _a, topic = incomingParams.topic; - var parameters = { type: pushGateway }; - if (pushGateway === 'apns2') { - parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); - delete parameters.type; + operation() { + return operations_1.default.PNRemoveAllPushNotificationsOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + return {}; + }); } - return parameters; -} -exports.prepareParams = prepareParams; -function handleResponse() { - return {}; } -exports.handleResponse = handleResponse; +exports.RemoveDevicePushNotificationRequest = RemoveDevicePushNotificationRequest; diff --git a/lib/core/endpoints/push/remove_push_channels.js b/lib/core/endpoints/push/remove_push_channels.js index a6256a9f3..96d179ae7 100644 --- a/lib/core/endpoints/push/remove_push_channels.js +++ b/lib/core/endpoints/push/remove_push_channels.js @@ -1,70 +1,35 @@ "use strict"; -/* */ -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../../constants/operations")); -function getOperation() { - return operations_1.default.PNPushNotificationEnabledChannelsOperation; -} -exports.getOperation = getOperation; -function validateParams(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway, channels = incomingParams.channels, topic = incomingParams.topic; - var config = modules.config; - if (!device) - return 'Missing Device ID (device)'; - if (!pushGateway) - return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) - return 'Missing APNS2 topic'; - if (!channels || channels.length === 0) - return 'Missing Channels'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var device = incomingParams.device, pushGateway = incomingParams.pushGateway; - var config = modules.config; - if (pushGateway === 'apns2') { - return "/v2/push/sub-key/".concat(config.subscribeKey, "/devices-apns2/").concat(device); +exports.RemoveDevicePushNotificationChannelsRequest = void 0; +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const push_1 = require("./push"); +const operations_1 = __importDefault(require("../../constants/operations")); +class RemoveDevicePushNotificationChannelsRequest extends push_1.BasePushNotificationChannelsRequest { + constructor(parameters) { + super(Object.assign(Object.assign({}, parameters), { action: 'remove' })); } - return "/v1/push/sub-key/".concat(config.subscribeKey, "/devices/").concat(device); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(modules, incomingParams) { - var pushGateway = incomingParams.pushGateway, _a = incomingParams.channels, channels = _a === void 0 ? [] : _a, _b = incomingParams.environment, environment = _b === void 0 ? 'development' : _b, topic = incomingParams.topic; - var parameters = { type: pushGateway, remove: channels.join(',') }; - if (pushGateway === 'apns2') { - parameters = __assign(__assign({}, parameters), { environment: environment, topic: topic }); - delete parameters.type; + operation() { + return operations_1.default.PNRemovePushNotificationEnabledChannelsOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + return {}; + }); } - return parameters; -} -exports.prepareParams = prepareParams; -function handleResponse() { - return {}; } -exports.handleResponse = handleResponse; +exports.RemoveDevicePushNotificationChannelsRequest = RemoveDevicePushNotificationChannelsRequest; diff --git a/lib/core/endpoints/signal.js b/lib/core/endpoints/signal.js index e72ff68e8..ad60cb35e 100644 --- a/lib/core/endpoints/signal.js +++ b/lib/core/endpoints/signal.js @@ -1,53 +1,51 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -var operations_1 = __importDefault(require("../constants/operations")); -var utils_1 = __importDefault(require("../utils")); -function prepareMessagePayload(modules, messagePayload) { - var stringifiedPayload = JSON.stringify(messagePayload); - return stringifiedPayload; -} -function getOperation() { - return operations_1.default.PNSignalOperation; -} -exports.getOperation = getOperation; -function validateParams(_a, incomingParams) { - var config = _a.config; - var message = incomingParams.message, channel = incomingParams.channel; - if (!channel) - return 'Missing Channel'; - if (!message) - return 'Missing Message'; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var config = modules.config; - var channel = incomingParams.channel, message = incomingParams.message; - var stringifiedPayload = prepareMessagePayload(modules, message); - return "/signal/".concat(config.publishKey, "/").concat(config.subscribeKey, "/0/").concat(utils_1.default.encodeString(channel), "/0/").concat(utils_1.default.encodeString(stringifiedPayload)); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams() { - var params = {}; - return params; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - return { timetoken: serverResponse[2] }; -} -exports.handleResponse = handleResponse; +exports.SignalRequest = void 0; +const pubnub_error_1 = require("../../errors/pubnub-error"); +const request_1 = require("../components/request"); +const operations_1 = __importDefault(require("../constants/operations")); +const utils_1 = require("../utils"); +class SignalRequest extends request_1.AbstractRequest { + constructor(parameters) { + super(); + this.parameters = parameters; + } + operation() { + return operations_1.default.PNSignalOperation; + } + validate() { + const { message, channel, keySet: { publishKey }, } = this.parameters; + if (!channel) + return "Missing 'channel'"; + if (!message) + return "Missing 'message'"; + if (!publishKey) + return "Missing 'publishKey'"; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + return { timetoken: serviceResponse[2] }; + }); + } + get path() { + const { keySet: { publishKey, subscribeKey }, channel, message, } = this.parameters; + const stringifiedPayload = JSON.stringify(message); + return `/signal/${publishKey}/${subscribeKey}/0/${(0, utils_1.encodeString)(channel)}/0/${(0, utils_1.encodeString)(stringifiedPayload)}`; + } +} +exports.SignalRequest = SignalRequest; diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index 4e05c306c..2588611e4 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -1,88 +1,273 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.handleResponse = exports.prepareParams = exports.isAuthSupported = exports.getRequestTimeout = exports.getURL = exports.validateParams = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../constants/operations")); -var utils_1 = __importDefault(require("../utils")); -function getOperation() { - return operations_1.default.PNSubscribeOperation; -} -exports.getOperation = getOperation; -function validateParams(modules) { - var config = modules.config; - if (!config.subscribeKey) - return 'Missing Subscribe Key'; -} -exports.validateParams = validateParams; -function getURL(modules, incomingParams) { - var config = modules.config; - var _a = incomingParams.channels, channels = _a === void 0 ? [] : _a; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils_1.default.encodeString(stringifiedChannels), "/0"); -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getSubscribeTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function isAuthSupported() { - return true; -} -exports.isAuthSupported = isAuthSupported; -function prepareParams(_a, incomingParams) { - var config = _a.config; - var state = incomingParams.state, _b = incomingParams.channelGroups, channelGroups = _b === void 0 ? [] : _b, timetoken = incomingParams.timetoken, filterExpression = incomingParams.filterExpression, region = incomingParams.region; - var params = { - heartbeat: config.getPresenceTimeout(), - }; - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); +exports.SubscribeRequest = exports.BaseSubscribeRequest = exports.PubNubEventType = void 0; +const pubnub_error_1 = require("../../errors/pubnub-error"); +const request_1 = require("../components/request"); +const operations_1 = __importDefault(require("../constants/operations")); +const utils_1 = require("../utils"); +const WITH_PRESENCE = false; +var PubNubEventType; +(function (PubNubEventType) { + PubNubEventType[PubNubEventType["Presence"] = -2] = "Presence"; + PubNubEventType[PubNubEventType["Message"] = -1] = "Message"; + PubNubEventType[PubNubEventType["Signal"] = 1] = "Signal"; + PubNubEventType[PubNubEventType["AppContext"] = 2] = "AppContext"; + PubNubEventType[PubNubEventType["MessageAction"] = 3] = "MessageAction"; + PubNubEventType[PubNubEventType["Files"] = 4] = "Files"; +})(PubNubEventType || (exports.PubNubEventType = PubNubEventType = {})); +class BaseSubscribeRequest extends request_1.AbstractRequest { + constructor(parameters) { + var _a, _b, _c; + var _d, _e, _f; + super({ cancellable: true }); + this.parameters = parameters; + (_a = (_d = this.parameters).withPresence) !== null && _a !== void 0 ? _a : (_d.withPresence = WITH_PRESENCE); + (_b = (_e = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_e.channelGroups = []); + (_c = (_f = this.parameters).channels) !== null && _c !== void 0 ? _c : (_f.channels = []); } - if (filterExpression && filterExpression.length > 0) { - params['filter-expr'] = filterExpression; + operation() { + return operations_1.default.PNSubscribeOperation; } - if (Object.keys(state).length) { - params.state = JSON.stringify(state); + validate() { + const { keySet: { subscribeKey }, channels, channelGroups, } = this.parameters; + if (!subscribeKey) + return 'Missing Subscribe Key'; + if (!channels && !channelGroups) + return '`channels` and `channelGroups` both should not be empty'; } - if (timetoken) { - params.tt = timetoken; + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + let serviceResponse; + try { + const json = request_1.AbstractRequest.decoder.decode(response.body); + const parsedJson = JSON.parse(json); + serviceResponse = parsedJson; + } + catch (error) { + console.error('Error parsing JSON response:', error); + } + if (!serviceResponse) { + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + } + const events = serviceResponse.m.map((envelope) => { + let { e: eventType } = envelope; + eventType !== null && eventType !== void 0 ? eventType : (eventType = envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message); + if (typeof envelope.d === 'string') { + if (eventType == PubNubEventType.Message) { + return { + type: PubNubEventType.Message, + data: this.messageFromEnvelope(envelope), + }; + } + return { + type: PubNubEventType.Files, + data: this.fileFromEnvelope(envelope), + }; + } + else if (eventType == PubNubEventType.Message) { + return { + type: PubNubEventType.Message, + data: this.messageFromEnvelope(envelope), + }; + } + else if (eventType === PubNubEventType.Presence) { + return { + type: PubNubEventType.Presence, + data: this.presenceEventFromEnvelope(envelope), + }; + } + else if (eventType == PubNubEventType.Signal) { + return { + type: PubNubEventType.Signal, + data: this.signalFromEnvelope(envelope), + }; + } + else if (eventType === PubNubEventType.AppContext) { + return { + type: PubNubEventType.AppContext, + data: this.appContextFromEnvelope(envelope), + }; + } + else if (eventType === PubNubEventType.MessageAction) { + return { + type: PubNubEventType.MessageAction, + data: this.messageActionFromEnvelope(envelope), + }; + } + return { + type: PubNubEventType.Files, + data: this.fileFromEnvelope(envelope), + }; + }); + return { + cursor: { timetoken: serviceResponse.t.t, region: serviceResponse.t.r }, + messages: events, + }; + }); } - if (region) { - params.tr = region; + get headers() { + return { accept: 'text/javascript' }; } - return params; -} -exports.prepareParams = prepareParams; -function handleResponse(modules, serverResponse) { - var messages = []; - serverResponse.m.forEach(function (rawMessage) { - var publishMetaData = { - timetoken: rawMessage.p.t, - region: rawMessage.p.r, + presenceEventFromEnvelope(envelope) { + const { d: payload } = envelope; + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const trimmedChannel = channel.replace('-pnpres', ''); + const actualChannel = subscription !== null ? trimmedChannel : null; + const subscribedChannel = subscription !== null ? subscription : trimmedChannel; + if (typeof payload !== 'string' && 'data' in payload) { + payload['state'] = payload.data; + delete payload.data; + } + return Object.assign({ channel: trimmedChannel, subscription, + actualChannel, + subscribedChannel, timetoken: envelope.p.t }, payload); + } + messageFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const [message, decryptionError] = this.decryptedData(envelope.d); + const actualChannel = subscription !== null ? channel : null; + const subscribedChannel = subscription !== null ? subscription : channel; + const event = { + channel, + subscription, + actualChannel, + subscribedChannel, + timetoken: envelope.p.t, + publisher: envelope.i, + message, }; - var parsedMessage = { - shard: parseInt(rawMessage.a, 10), - subscriptionMatch: rawMessage.b, - channel: rawMessage.c, - messageType: rawMessage.e, - payload: rawMessage.d, - flags: rawMessage.f, - issuingClientId: rawMessage.i, - subscribeKey: rawMessage.k, - originationTimetoken: rawMessage.o, - userMetadata: rawMessage.u, - publishMetaData: publishMetaData, + if (envelope.u) + event.userMetadata = envelope.u; + if (decryptionError) + event.error = decryptionError; + return event; + } + signalFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const event = { + channel, + subscription, + timetoken: envelope.p.t, + publisher: envelope.i, + message: envelope.d, }; - messages.push(parsedMessage); - }); - var metadata = { - timetoken: serverResponse.t.t, - region: serverResponse.t.r, - }; - return { messages: messages, metadata: metadata }; + if (envelope.u) + event.userMetadata = envelope.u; + return event; + } + messageActionFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const action = envelope.d; + return { + channel, + subscription, + timetoken: envelope.p.t, + publisher: envelope.i, + event: action.event, + data: Object.assign(Object.assign({}, action.data), { uuid: envelope.i }), + }; + } + appContextFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const object = envelope.d; + return { + channel, + subscription, + timetoken: envelope.p.t, + message: object, + }; + } + fileFromEnvelope(envelope) { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const [file, decryptionError] = this.decryptedData(envelope.d); + let errorMessage = decryptionError; + const event = { + channel, + subscription, + timetoken: envelope.p.t, + publisher: envelope.i, + }; + if (envelope.u) + event.userMetadata = envelope.u; + if (!file) + errorMessage !== null && errorMessage !== void 0 ? errorMessage : (errorMessage = `File information payload is missing.`); + else if (typeof file === 'string') + errorMessage !== null && errorMessage !== void 0 ? errorMessage : (errorMessage = `Unexpected file information payload data type.`); + else { + event.message = file.message; + if (file.file) { + event.file = { + id: file.file.id, + name: file.file.name, + url: this.parameters.getFileUrl({ id: file.file.id, name: file.file.name, channel }), + }; + } + } + if (errorMessage) + event.error = errorMessage; + return event; + } + subscriptionChannelFromEnvelope(envelope) { + return [envelope.c, envelope.b === undefined ? envelope.c : envelope.b]; + } + decryptedData(data) { + if (!this.parameters.crypto || typeof data !== 'string') + return [data, undefined]; + let payload; + let error; + try { + const decryptedData = this.parameters.crypto.decrypt(data); + payload = + decryptedData instanceof ArrayBuffer + ? JSON.parse(SubscribeRequest.decoder.decode(decryptedData)) + : decryptedData; + } + catch (err) { + payload = null; + error = `Error while decrypting message content: ${err.message}`; + } + return [(payload !== null && payload !== void 0 ? payload : data), error]; + } +} +exports.BaseSubscribeRequest = BaseSubscribeRequest; +class SubscribeRequest extends BaseSubscribeRequest { + get path() { + var _a; + const { keySet: { subscribeKey }, channels, } = this.parameters; + return `/v2/subscribe/${subscribeKey}/${(0, utils_1.encodeNames)((_a = channels === null || channels === void 0 ? void 0 : channels.sort()) !== null && _a !== void 0 ? _a : [], ',')}/0`; + } + get queryParameters() { + const { channelGroups, filterExpression, heartbeat, state, timetoken, region } = this.parameters; + const query = {}; + if (channelGroups && channelGroups.length > 0) + query['channel-group'] = channelGroups.sort().join(','); + if (filterExpression && filterExpression.length > 0) + query['filter-expr'] = filterExpression; + if (heartbeat) + query.heartbeat = heartbeat; + if (state && Object.keys(state).length > 0) + query['state'] = JSON.stringify(state); + if (timetoken !== undefined && typeof timetoken === 'string') { + if (timetoken.length > 0 && timetoken !== '0') + query['tt'] = timetoken; + } + else if (timetoken !== undefined && timetoken > 0) + query['tt'] = timetoken; + if (region) + query['tr'] = region; + return query; + } } -exports.handleResponse = handleResponse; +exports.SubscribeRequest = SubscribeRequest; diff --git a/lib/core/endpoints/subscriptionUtils/handshake.js b/lib/core/endpoints/subscriptionUtils/handshake.js index c30834e5b..36e175b4d 100644 --- a/lib/core/endpoints/subscriptionUtils/handshake.js +++ b/lib/core/endpoints/subscriptionUtils/handshake.js @@ -3,44 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNHandshakeOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channels) && !(params === null || params === void 0 ? void 0 : params.channelGroups)) { - return 'channels and channleGroups both should not be empty'; - } - }, - getURL: function (_a, params) { - var config = _a.config; - var _b = params.channels, channels = _b === void 0 ? [] : _b; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils_1.default.encodeString(stringifiedChannels), "/0"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getSubscribeTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_, params) { - var outParams = {}; - if (params.channelGroups && params.channelGroups.length > 0) { - outParams['channel-group'] = params.channelGroups.join(','); - } - outParams.tt = 0; - if (params.state) { - outParams.state = JSON.stringify(params.state); - } - if (params.filterExpression && params.filterExpression.length > 0) { - outParams['filter-expr'] = params.filterExpression; - } - outParams.ee = ''; - return outParams; - }, - handleResponse: function (_, response) { return ({ - region: response.t.r, - timetoken: response.t.t, - }); }, -}; -exports.default = endpoint; +exports.HandshakeSubscribeRequest = void 0; +const operations_1 = __importDefault(require("../../constants/operations")); +const subscribe_1 = require("../subscribe"); +const utils_1 = require("../../utils"); +class HandshakeSubscribeRequest extends subscribe_1.BaseSubscribeRequest { + operation() { + return operations_1.default.PNHandshakeOperation; + } + get path() { + const { keySet: { subscribeKey }, channels = [], } = this.parameters; + return `/v2/subscribe/${subscribeKey}/${(0, utils_1.encodeNames)(channels.sort(), ',')}/0`; + } + get queryParameters() { + const { channelGroups, filterExpression, state } = this.parameters; + const query = { tt: 0, ee: '' }; + if (channelGroups && channelGroups.length > 0) + query['channel-group'] = channelGroups.sort().join(','); + if (filterExpression && filterExpression.length > 0) + query['filter-expr'] = filterExpression; + if (state && Object.keys(state).length > 0) + query['state'] = JSON.stringify(state); + return query; + } +} +exports.HandshakeSubscribeRequest = HandshakeSubscribeRequest; diff --git a/lib/core/endpoints/subscriptionUtils/receiveMessages.js b/lib/core/endpoints/subscriptionUtils/receiveMessages.js index 278049190..c78a73f84 100644 --- a/lib/core/endpoints/subscriptionUtils/receiveMessages.js +++ b/lib/core/endpoints/subscriptionUtils/receiveMessages.js @@ -3,74 +3,43 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNReceiveMessagesOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.channels) && !(params === null || params === void 0 ? void 0 : params.channelGroups)) { - return 'channels and channleGroups both should not be empty'; - } - if (!(params === null || params === void 0 ? void 0 : params.timetoken)) { +exports.ReceiveMessagesSubscribeRequest = void 0; +const operations_1 = __importDefault(require("../../constants/operations")); +const subscribe_1 = require("../subscribe"); +const utils_1 = require("../../utils"); +class ReceiveMessagesSubscribeRequest extends subscribe_1.BaseSubscribeRequest { + operation() { + return operations_1.default.PNReceiveMessagesOperation; + } + validate() { + const validationResult = super.validate(); + if (validationResult) + return validationResult; + if (!this.parameters.timetoken) return 'timetoken can not be empty'; - } - if (!(params === null || params === void 0 ? void 0 : params.region)) { + if (!this.parameters.region) return 'region can not be empty'; + } + get path() { + const { keySet: { subscribeKey }, channels = [], } = this.parameters; + return `/v2/subscribe/${subscribeKey}/${(0, utils_1.encodeNames)(channels.sort(), ',')}/0`; + } + get queryParameters() { + const { channelGroups, filterExpression, timetoken, region } = this.parameters; + const query = { ee: '' }; + if (channelGroups && channelGroups.length > 0) + query['channel-group'] = channelGroups.sort().join(','); + if (filterExpression && filterExpression.length > 0) + query['filter-expr'] = filterExpression; + if (typeof timetoken === 'string') { + if (timetoken && timetoken.length > 0) + query['tt'] = timetoken; } - }, - getURL: function (_a, params) { - var config = _a.config; - var _b = params.channels, channels = _b === void 0 ? [] : _b; - var stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return "/v2/subscribe/".concat(config.subscribeKey, "/").concat(utils_1.default.encodeString(stringifiedChannels), "/0"); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getSubscribeTimeout(); - }, - isAuthSupported: function () { return true; }, - getAbortSignal: function (_, params) { return params.abortSignal; }, - prepareParams: function (_, params) { - var outParams = {}; - if (params.channelGroups && params.channelGroups.length > 0) { - outParams['channel-group'] = params.channelGroups.join(','); - } - if (params.filterExpression && params.filterExpression.length > 0) { - outParams['filter-expr'] = params.filterExpression; - } - outParams.tt = params.timetoken; - outParams.tr = params.region; - outParams.ee = ''; - return outParams; - }, - handleResponse: function (_, response) { - var parsedMessages = []; - response.m.forEach(function (envelope) { - var parsedMessage = { - shard: parseInt(envelope.a, 10), - subscriptionMatch: envelope.b, - channel: envelope.c, - messageType: envelope.e, - payload: envelope.d, - flags: envelope.f, - issuingClientId: envelope.i, - subscribeKey: envelope.k, - originationTimetoken: envelope.o, - userMetadata: envelope.u, - publishMetaData: { - timetoken: envelope.p.t, - region: envelope.p.r, - }, - }; - parsedMessages.push(parsedMessage); - }); - return { - messages: parsedMessages, - metadata: { - region: response.t.r, - timetoken: response.t.t, - }, - }; - }, -}; -exports.default = endpoint; + else if (timetoken && timetoken > 0) + query['tt'] = timetoken; + if (region) + query['tr'] = region; + return query; + } +} +exports.ReceiveMessagesSubscribeRequest = ReceiveMessagesSubscribeRequest; diff --git a/lib/core/endpoints/time.js b/lib/core/endpoints/time.js index 8673d0a95..a09d61681 100644 --- a/lib/core/endpoints/time.js +++ b/lib/core/endpoints/time.js @@ -1,39 +1,38 @@ "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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.validateParams = exports.handleResponse = exports.isAuthSupported = exports.prepareParams = exports.getRequestTimeout = exports.getURL = exports.getOperation = void 0; -/* */ -var operations_1 = __importDefault(require("../constants/operations")); -function getOperation() { - return operations_1.default.PNTimeOperation; -} -exports.getOperation = getOperation; -function getURL() { - return '/time/0'; -} -exports.getURL = getURL; -function getRequestTimeout(_a) { - var config = _a.config; - return config.getTransactionTimeout(); -} -exports.getRequestTimeout = getRequestTimeout; -function prepareParams() { - return {}; -} -exports.prepareParams = prepareParams; -function isAuthSupported() { - return false; -} -exports.isAuthSupported = isAuthSupported; -function handleResponse(modules, serverResponse) { - return { - timetoken: serverResponse[0], - }; -} -exports.handleResponse = handleResponse; -function validateParams() { - // pass +exports.TimeRequest = void 0; +const pubnub_error_1 = require("../../errors/pubnub-error"); +const request_1 = require("../components/request"); +const operations_1 = __importDefault(require("../constants/operations")); +class TimeRequest extends request_1.AbstractRequest { + constructor() { + super(); + } + operation() { + return operations_1.default.PNTimeOperation; + } + parse(response) { + return __awaiter(this, void 0, void 0, function* () { + const serviceResponse = this.deserializeResponse(response); + if (!serviceResponse) + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + return { timetoken: serviceResponse[0] }; + }); + } + get path() { + return '/time/0'; + } } -exports.validateParams = validateParams; +exports.TimeRequest = TimeRequest; diff --git a/lib/core/endpoints/user/create.js b/lib/core/endpoints/user/create.js deleted file mode 100644 index e9526855c..000000000 --- a/lib/core/endpoints/user/create.js +++ /dev/null @@ -1,40 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNCreateUserOperation; }, - validateParams: function (_, params) { - if (!(params === null || params === void 0 ? void 0 : params.data)) { - return 'Data cannot be empty'; - } - }, - usePost: function () { return true; }, - postURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v3/objects/".concat(config.subscribeKey, "/users/").concat(utils_1.default.encodeString((_b = params.userId) !== null && _b !== void 0 ? _b : config.getUserId())); - }, - postPayload: function (_, params) { return params.data; }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_a, params) { - var _b; - var config = _a.config; - var queryParams = { - uuid: (_b = params === null || params === void 0 ? void 0 : params.userId) !== null && _b !== void 0 ? _b : config.getUserId(), - }; - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, -}; -exports.default = endpoint; diff --git a/lib/core/endpoints/user/fetch.js b/lib/core/endpoints/user/fetch.js deleted file mode 100644 index 473da58c5..000000000 --- a/lib/core/endpoints/user/fetch.js +++ /dev/null @@ -1,34 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var operations_1 = __importDefault(require("../../constants/operations")); -var utils_1 = __importDefault(require("../../utils")); -var endpoint = { - getOperation: function () { return operations_1.default.PNFetchUserOperation; }, - validateParams: function () { - // No required parameters. - }, - getURL: function (_a, params) { - var _b; - var config = _a.config; - return "/v3/objects/".concat(config.subscribeKey, "/users/").concat(utils_1.default.encodeString((_b = params === null || params === void 0 ? void 0 : params.userId) !== null && _b !== void 0 ? _b : config.getUserId())); - }, - getRequestTimeout: function (_a) { - var config = _a.config; - return config.getTransactionTimeout(); - }, - isAuthSupported: function () { return true; }, - prepareParams: function (_a, params) { - var _b; - var config = _a.config; - var queryParams = { uuid: (_b = params === null || params === void 0 ? void 0 : params.userId) !== null && _b !== void 0 ? _b : config.getUserId() }; - return queryParams; - }, - handleResponse: function (_, response) { return ({ - status: response.status, - data: response.data, - }); }, -}; -exports.default = endpoint; diff --git a/lib/core/interfaces/configuration.js b/lib/core/interfaces/configuration.js new file mode 100644 index 000000000..bd776878e --- /dev/null +++ b/lib/core/interfaces/configuration.js @@ -0,0 +1,90 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.setDefaults = void 0; +const pubnub_error_1 = require("../../errors/pubnub-error"); +const USE_SSL = true; +const RESTORE = false; +const AUTO_NETWORK_DETECTION = false; +const DEDUPE_ON_SUBSCRIBE = false; +const DEDUPE_CACHE_SIZE = 100; +const FILE_PUBLISH_RETRY_LIMIT = 5; +const ENABLE_EVENT_ENGINE = false; +const MAINTAIN_PRESENCE_STATE = true; +const KEEP_ALIVE = false; +const USE_VERBOSE_LOGGING = false; +const SUPPRESS_LEAVE_EVENTS = false; +const ANNOUNCE_HEARTBEAT_FAILURE = true; +const ANNOUNCE_HEARTBEAT_SUCCESS = false; +const USE_INSTANCE_ID = false; +const USE_REQUEST_ID = true; +const TRANSACTIONAL_REQUEST_TIMEOUT = 15; +const SUBSCRIBE_REQUEST_TIMEOUT = 310; +const PRESENCE_TIMEOUT = 300; +const PRESENCE_TIMEOUT_MINIMUM = 20; +const setDefaults = (configuration) => { + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; + const configurationCopy = Object.assign({}, configuration); + (_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING); + (_b = configurationCopy.ssl) !== null && _b !== void 0 ? _b : (configurationCopy.ssl = USE_SSL); + (_c = configurationCopy.transactionalRequestTimeout) !== null && _c !== void 0 ? _c : (configurationCopy.transactionalRequestTimeout = TRANSACTIONAL_REQUEST_TIMEOUT); + (_d = configurationCopy.subscribeRequestTimeout) !== null && _d !== void 0 ? _d : (configurationCopy.subscribeRequestTimeout = SUBSCRIBE_REQUEST_TIMEOUT); + (_e = configurationCopy.restore) !== null && _e !== void 0 ? _e : (configurationCopy.restore = RESTORE); + (_f = configurationCopy.useInstanceId) !== null && _f !== void 0 ? _f : (configurationCopy.useInstanceId = USE_INSTANCE_ID); + (_g = configurationCopy.suppressLeaveEvents) !== null && _g !== void 0 ? _g : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS); + (_h = configurationCopy.requestMessageCountThreshold) !== null && _h !== void 0 ? _h : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE); + (_j = configurationCopy.autoNetworkDetection) !== null && _j !== void 0 ? _j : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION); + (_k = configurationCopy.enableEventEngine) !== null && _k !== void 0 ? _k : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE); + (_l = configurationCopy.maintainPresenceState) !== null && _l !== void 0 ? _l : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE); + (_m = configurationCopy.keepAlive) !== null && _m !== void 0 ? _m : (configurationCopy.keepAlive = KEEP_ALIVE); + if (configurationCopy.userId && configurationCopy.uuid) + throw new pubnub_error_1.PubNubError("PubNub client configuration error: use only 'userId'"); + (_o = configurationCopy.userId) !== null && _o !== void 0 ? _o : (configurationCopy.userId = configurationCopy.uuid); + if (!configurationCopy.userId) + throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' not set"); + else if (((_p = configurationCopy.userId) === null || _p === void 0 ? void 0 : _p.trim().length) === 0) + throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' is empty"); + if (!configurationCopy.origin) + configurationCopy.origin = Array.from({ length: 20 }, (_, i) => `ps${i + 1}.pndsn.com`); + const keySet = { + subscribeKey: configurationCopy.subscribeKey, + publishKey: configurationCopy.publishKey, + secretKey: configurationCopy.secretKey, + }; + if (configurationCopy.presenceTimeout !== undefined && configurationCopy.presenceTimeout < PRESENCE_TIMEOUT_MINIMUM) { + configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; + console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); + } + (_q = configurationCopy.presenceTimeout) !== null && _q !== void 0 ? _q : (configurationCopy.presenceTimeout = PRESENCE_TIMEOUT); + let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS; + let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE; + let fileUploadPublishRetryLimit = FILE_PUBLISH_RETRY_LIMIT; + let dedupeOnSubscribe = DEDUPE_ON_SUBSCRIBE; + const maximumCacheSize = DEDUPE_CACHE_SIZE; + let useRequestId = USE_REQUEST_ID; + if (configurationCopy.dedupeOnSubscribe !== undefined && typeof configurationCopy.dedupeOnSubscribe === 'boolean') { + dedupeOnSubscribe = configurationCopy.dedupeOnSubscribe; + } + if (configurationCopy.useRequestId !== undefined && typeof configurationCopy.useRequestId === 'boolean') { + useRequestId = configurationCopy.useRequestId; + } + if (configurationCopy.announceSuccessfulHeartbeats !== undefined && + typeof configurationCopy.announceSuccessfulHeartbeats === 'boolean') { + announceSuccessfulHeartbeats = configurationCopy.announceSuccessfulHeartbeats; + } + if (configurationCopy.announceFailedHeartbeats !== undefined && + typeof configurationCopy.announceFailedHeartbeats === 'boolean') { + announceFailedHeartbeats = configurationCopy.announceFailedHeartbeats; + } + if (configurationCopy.fileUploadPublishRetryLimit !== undefined && + typeof configurationCopy.fileUploadPublishRetryLimit === 'number') { + fileUploadPublishRetryLimit = configurationCopy.fileUploadPublishRetryLimit; + } + return Object.assign(Object.assign({}, configurationCopy), { keySet, + dedupeOnSubscribe, + maximumCacheSize, + useRequestId, + announceSuccessfulHeartbeats, + announceFailedHeartbeats, + fileUploadPublishRetryLimit }); +}; +exports.setDefaults = setDefaults; diff --git a/lib/core/interfaces/crypto-module.js b/lib/core/interfaces/crypto-module.js new file mode 100644 index 000000000..72ba0823b --- /dev/null +++ b/lib/core/interfaces/crypto-module.js @@ -0,0 +1,22 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.AbstractCryptoModule = void 0; +class AbstractCryptoModule { + static legacyCryptoModule(config) { + throw new Error('Should be implemented by concrete crypto module implementation.'); + } + static aesCbcCryptoModule(config) { + throw new Error('Should be implemented by concrete crypto module implementation.'); + } + constructor(configuration) { + var _a; + this.defaultCryptor = configuration.default; + this.cryptors = (_a = configuration.cryptors) !== null && _a !== void 0 ? _a : []; + } + getAllCryptors() { + return [this.defaultCryptor, ...this.cryptors]; + } +} +exports.AbstractCryptoModule = AbstractCryptoModule; +AbstractCryptoModule.encoder = new TextEncoder(); +AbstractCryptoModule.decoder = new TextDecoder(); diff --git a/lib/core/components/_endpoint.js b/lib/core/interfaces/cryptography.js similarity index 100% rename from lib/core/components/_endpoint.js rename to lib/core/interfaces/cryptography.js diff --git a/lib/crypto/modules/WebCryptoModule/ICryptor.js b/lib/core/interfaces/request.js similarity index 100% rename from lib/crypto/modules/WebCryptoModule/ICryptor.js rename to lib/core/interfaces/request.js diff --git a/lib/crypto/modules/WebCryptoModule/ILegacyCryptor.js b/lib/core/interfaces/transport.js similarity index 100% rename from lib/crypto/modules/WebCryptoModule/ILegacyCryptor.js rename to lib/core/interfaces/transport.js diff --git a/lib/core/pubnub-channel-groups.js b/lib/core/pubnub-channel-groups.js new file mode 100644 index 000000000..fbab5c9b9 --- /dev/null +++ b/lib/core/pubnub-channel-groups.js @@ -0,0 +1,63 @@ +"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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const remove_channels_1 = require("./endpoints/channel_groups/remove_channels"); +const add_channels_1 = require("./endpoints/channel_groups/add_channels"); +const list_channels_1 = require("./endpoints/channel_groups/list_channels"); +const delete_group_1 = require("./endpoints/channel_groups/delete_group"); +const list_groups_1 = require("./endpoints/channel_groups/list_groups"); +class PubnubChannelGroups { + constructor(keySet, sendRequest) { + this.keySet = keySet; + this.sendRequest = sendRequest; + } + listChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new list_channels_1.ListChannelGroupChannels(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + listGroups(callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new list_groups_1.ListChannelGroupsRequest({ keySet: this.keySet }); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + addChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new add_channels_1.AddChannelGroupChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + removeChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new remove_channels_1.RemoveChannelGroupChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + deleteGroup(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new delete_group_1.DeleteChannelGroupRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } +} +exports.default = PubnubChannelGroups; diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 9a145cdc7..e0eed71e2 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -1,15 +1,4 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -33,641 +22,845 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; -var __values = (this && this.__values) || function(o) { - var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; - if (m) return m.call(o); - if (o && typeof o.length === "number") return { - next: function () { - if (o && i >= o.length) o = void 0; - return { value: o && o[i++], done: !o }; - } - }; - throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); -}; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); +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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var config_1 = __importDefault(require("./components/config")); -var index_1 = __importDefault(require("./components/cryptography/index")); -var base64_codec_1 = require("./components/base64_codec"); -var subscription_manager_1 = __importDefault(require("./components/subscription_manager")); -var telemetry_manager_1 = __importDefault(require("./components/telemetry_manager")); -var push_payload_1 = __importDefault(require("./components/push_payload")); -var listener_manager_1 = __importDefault(require("./components/listener_manager")); -var token_manager_1 = __importDefault(require("./components/token_manager")); -var endpoint_1 = __importDefault(require("./components/endpoint")); -var addChannelsChannelGroupConfig = __importStar(require("./endpoints/channel_groups/add_channels")); -var removeChannelsChannelGroupConfig = __importStar(require("./endpoints/channel_groups/remove_channels")); -var deleteChannelGroupConfig = __importStar(require("./endpoints/channel_groups/delete_group")); -var listChannelGroupsConfig = __importStar(require("./endpoints/channel_groups/list_groups")); -var listChannelsInChannelGroupConfig = __importStar(require("./endpoints/channel_groups/list_channels")); -var addPushChannelsConfig = __importStar(require("./endpoints/push/add_push_channels")); -var removePushChannelsConfig = __importStar(require("./endpoints/push/remove_push_channels")); -var listPushChannelsConfig = __importStar(require("./endpoints/push/list_push_channels")); -var removeDevicePushConfig = __importStar(require("./endpoints/push/remove_device")); -var presenceLeaveEndpointConfig = __importStar(require("./endpoints/presence/leave")); -var presenceWhereNowEndpointConfig = __importStar(require("./endpoints/presence/where_now")); -var presenceHeartbeatEndpointConfig = __importStar(require("./endpoints/presence/heartbeat")); -var presenceGetStateConfig = __importStar(require("./endpoints/presence/get_state")); -var presenceSetStateConfig = __importStar(require("./endpoints/presence/set_state")); -var presenceHereNowConfig = __importStar(require("./endpoints/presence/here_now")); -// Actions API -var addMessageActionEndpointConfig = __importStar(require("./endpoints/actions/add_message_action")); -var removeMessageActionEndpointConfig = __importStar(require("./endpoints/actions/remove_message_action")); -var getMessageActionEndpointConfig = __importStar(require("./endpoints/actions/get_message_actions")); -// File Upload API v1 -var list_files_1 = __importDefault(require("./endpoints/file_upload/list_files")); -var generate_upload_url_1 = __importDefault(require("./endpoints/file_upload/generate_upload_url")); -var publish_file_1 = __importDefault(require("./endpoints/file_upload/publish_file")); -var send_file_1 = __importDefault(require("./endpoints/file_upload/send_file")); -var get_file_url_1 = __importDefault(require("./endpoints/file_upload/get_file_url")); -var download_file_1 = __importDefault(require("./endpoints/file_upload/download_file")); -var delete_file_1 = __importDefault(require("./endpoints/file_upload/delete_file")); -// Object API v2 -var get_all_1 = __importDefault(require("./endpoints/objects/uuid/get_all")); -var get_1 = __importDefault(require("./endpoints/objects/uuid/get")); -var set_1 = __importDefault(require("./endpoints/objects/uuid/set")); -var remove_1 = __importDefault(require("./endpoints/objects/uuid/remove")); -var get_all_2 = __importDefault(require("./endpoints/objects/channel/get_all")); -var get_2 = __importDefault(require("./endpoints/objects/channel/get")); -var set_2 = __importDefault(require("./endpoints/objects/channel/set")); -var remove_2 = __importDefault(require("./endpoints/objects/channel/remove")); -var get_3 = __importDefault(require("./endpoints/objects/member/get")); -var set_3 = __importDefault(require("./endpoints/objects/member/set")); -var get_4 = __importDefault(require("./endpoints/objects/membership/get")); -var set_4 = __importDefault(require("./endpoints/objects/membership/set")); -var auditEndpointConfig = __importStar(require("./endpoints/access_manager/audit")); -var grantEndpointConfig = __importStar(require("./endpoints/access_manager/grant")); -var grantTokenEndpointConfig = __importStar(require("./endpoints/access_manager/grant_token")); -var revoke_token_1 = __importDefault(require("./endpoints/access_manager/revoke_token")); -var publishEndpointConfig = __importStar(require("./endpoints/publish")); -var signalEndpointConfig = __importStar(require("./endpoints/signal")); -var historyEndpointConfig = __importStar(require("./endpoints/history/get_history")); -var deleteMessagesEndpointConfig = __importStar(require("./endpoints/history/delete_messages")); -var messageCountsEndpointConfig = __importStar(require("./endpoints/history/message_counts")); -var fetchMessagesEndpointConfig = __importStar(require("./endpoints/fetch_messages")); -var timeEndpointConfig = __importStar(require("./endpoints/time")); -var subscribeEndpointConfig = __importStar(require("./endpoints/subscribe")); -// subscription utilities -var handshake_1 = __importDefault(require("./endpoints/subscriptionUtils/handshake")); -var receiveMessages_1 = __importDefault(require("./endpoints/subscriptionUtils/receiveMessages")); -var operations_1 = __importDefault(require("./constants/operations")); -var categories_1 = __importDefault(require("./constants/categories")); -var uuid_1 = __importDefault(require("./components/uuid")); -var event_engine_1 = require("../event-engine"); -var presence_1 = require("../event-engine/presence/presence"); -var retryPolicy_1 = require("../event-engine/core/retryPolicy"); -var eventEmitter_1 = __importDefault(require("./components/eventEmitter")); -var Channel_1 = require("../entities/Channel"); -var ChannelGroup_1 = require("../entities/ChannelGroup"); -var ChannelMetadata_1 = require("../entities/ChannelMetadata"); -var UserMetadata_1 = require("../entities/UserMetadata"); -var SubscriptionSet_1 = require("../entities/SubscriptionSet"); -var default_1 = /** @class */ (function () { - function default_1(setup) { - var _this = this; - var networking = setup.networking, cbor = setup.cbor; - var config = new config_1.default({ setup: setup }); - this._config = config; - var crypto = new index_1.default({ config: config }); // LEGACY - var cryptography = setup.cryptography; - networking.init(config); - var tokenManager = new token_manager_1.default(config, cbor); - this._tokenManager = tokenManager; - var telemetryManager = new telemetry_manager_1.default({ - maximumSamplesCount: 60000, - }); - this._telemetryManager = telemetryManager; - var cryptoModule = this._config.cryptoModule; - var modules = { - config: config, - networking: networking, - crypto: crypto, - cryptography: cryptography, - tokenManager: tokenManager, - telemetryManager: telemetryManager, - PubNubFile: setup.PubNubFile, - cryptoModule: cryptoModule, - }; - this.File = setup.PubNubFile; - this.encryptFile = function (key, file) { - if (arguments.length == 1 && typeof key != 'string' && modules.cryptoModule) { - file = key; - return modules.cryptoModule.encryptFile(file, this.File); - } - return cryptography.encryptFile(key, file, this.File); - }; - this.decryptFile = function (key, file) { - if (arguments.length == 1 && typeof key != 'string' && modules.cryptoModule) { - file = key; - return modules.cryptoModule.decryptFile(file, this.File); - } - return cryptography.decryptFile(key, file, this.File); - }; - var timeEndpoint = endpoint_1.default.bind(this, modules, timeEndpointConfig); - var leaveEndpoint = endpoint_1.default.bind(this, modules, presenceLeaveEndpointConfig); - var heartbeatEndpoint = endpoint_1.default.bind(this, modules, presenceHeartbeatEndpointConfig); - var setStateEndpoint = endpoint_1.default.bind(this, modules, presenceSetStateConfig); - var subscribeEndpoint = endpoint_1.default.bind(this, modules, subscribeEndpointConfig); - // managers - var listenerManager = new listener_manager_1.default(); - this._listenerManager = listenerManager; - this.iAmHere = endpoint_1.default.bind(this, modules, presenceHeartbeatEndpointConfig); - this.iAmAway = endpoint_1.default.bind(this, modules, presenceLeaveEndpointConfig); - this.setPresenceState = endpoint_1.default.bind(this, modules, presenceSetStateConfig); - this.handshake = endpoint_1.default.bind(this, modules, handshake_1.default); - this.receiveMessages = endpoint_1.default.bind(this, modules, receiveMessages_1.default); - this._eventEmitter = new eventEmitter_1.default({ - modules: modules, - listenerManager: this._listenerManager, - getFileUrl: function (params) { return (0, get_file_url_1.default)(modules, params); }, - }); - if (config.enableEventEngine === true) { - if (config.maintainPresenceState) { - this.presenceState = {}; - this.setState = function (args) { - var _a, _b; - (_a = args.channels) === null || _a === void 0 ? void 0 : _a.forEach(function (channel) { return (_this.presenceState[channel] = args.state); }); - (_b = args.channelGroups) === null || _b === void 0 ? void 0 : _b.forEach(function (group) { return (_this.presenceState[group] = args.state); }); - return _this.setPresenceState({ - channels: args.channels, - channelGroups: args.channelGroups, - state: _this.presenceState, - }); - }; - } - if (config.getHeartbeatInterval()) { - var presenceEventEngine = new presence_1.PresenceEventEngine({ - heartbeat: this.iAmHere, - leave: this.iAmAway, - heartbeatDelay: function () { - return new Promise(function (resolve) { return setTimeout(resolve, modules.config.getHeartbeatInterval() * 1000); }); - }, - retryDelay: function (amount) { return new Promise(function (resolve) { return setTimeout(resolve, amount); }); }, - config: modules.config, +exports.PubNubCore = void 0; +const listener_manager_1 = require("./components/listener_manager"); +const subscription_manager_1 = require("./components/subscription-manager"); +const push_payload_1 = __importDefault(require("./components/push_payload")); +const eventEmitter_1 = __importDefault(require("./components/eventEmitter")); +const base64_codec_1 = require("./components/base64_codec"); +const uuid_1 = __importDefault(require("./components/uuid")); +const operations_1 = __importDefault(require("./constants/operations")); +const categories_1 = __importDefault(require("./constants/categories")); +const pubnub_error_1 = require("../errors/pubnub-error"); +const pubnub_api_error_1 = require("../errors/pubnub-api-error"); +const presence_1 = require("../event-engine/presence/presence"); +const retryPolicy_1 = require("../event-engine/core/retryPolicy"); +const event_engine_1 = require("../event-engine"); +const Publish = __importStar(require("./endpoints/publish")); +const Signal = __importStar(require("./endpoints/signal")); +const subscribe_1 = require("./endpoints/subscribe"); +const receiveMessages_1 = require("./endpoints/subscriptionUtils/receiveMessages"); +const handshake_1 = require("./endpoints/subscriptionUtils/handshake"); +const get_state_1 = require("./endpoints/presence/get_state"); +const set_state_1 = require("./endpoints/presence/set_state"); +const heartbeat_1 = require("./endpoints/presence/heartbeat"); +const leave_1 = require("./endpoints/presence/leave"); +const where_now_1 = require("./endpoints/presence/where_now"); +const here_now_1 = require("./endpoints/presence/here_now"); +const delete_messages_1 = require("./endpoints/history/delete_messages"); +const message_counts_1 = require("./endpoints/history/message_counts"); +const get_history_1 = require("./endpoints/history/get_history"); +const fetch_messages_1 = require("./endpoints/fetch_messages"); +const get_message_actions_1 = require("./endpoints/actions/get_message_actions"); +const add_message_action_1 = require("./endpoints/actions/add_message_action"); +const remove_message_action_1 = require("./endpoints/actions/remove_message_action"); +const publish_file_1 = require("./endpoints/file_upload/publish_file"); +const get_file_url_1 = require("./endpoints/file_upload/get_file_url"); +const delete_file_1 = require("./endpoints/file_upload/delete_file"); +const list_files_1 = require("./endpoints/file_upload/list_files"); +const send_file_1 = require("./endpoints/file_upload/send_file"); +const revoke_token_1 = require("./endpoints/access_manager/revoke_token"); +const grant_token_1 = require("./endpoints/access_manager/grant_token"); +const grant_1 = require("./endpoints/access_manager/grant"); +const audit_1 = require("./endpoints/access_manager/audit"); +const ChannelMetadata_1 = require("../entities/ChannelMetadata"); +const SubscriptionSet_1 = require("../entities/SubscriptionSet"); +const ChannelGroup_1 = require("../entities/ChannelGroup"); +const UserMetadata_1 = require("../entities/UserMetadata"); +const Channel_1 = require("../entities/Channel"); +const pubnub_channel_groups_1 = __importDefault(require("./pubnub-channel-groups")); +const pubnub_push_1 = __importDefault(require("./pubnub-push")); +const pubnub_objects_1 = __importDefault(require("./pubnub-objects")); +const Time = __importStar(require("./endpoints/time")); +const utils_1 = require("./utils"); +const download_file_1 = require("./endpoints/file_upload/download_file"); +class PubNubCore { + static notificationPayload(title, body) { + return new push_payload_1.default(title, body); + } + static generateUUID() { + return uuid_1.default.createUUID(); + } + constructor(configuration) { + this._configuration = configuration.configuration; + this.cryptography = configuration.cryptography; + this.tokenManager = configuration.tokenManager; + this.transport = configuration.transport; + this.crypto = configuration.crypto; + this._objects = new pubnub_objects_1.default(this._configuration, this.sendRequest.bind(this)); + this._channelGroups = new pubnub_channel_groups_1.default(this._configuration.keySet, this.sendRequest.bind(this)); + this._push = new pubnub_push_1.default(this._configuration.keySet, this.sendRequest.bind(this)); + this.listenerManager = new listener_manager_1.ListenerManager(); + this.eventEmitter = new eventEmitter_1.default(this.listenerManager); + if (this._configuration.enableEventEngine) { + let heartbeatInterval = this._configuration.getHeartbeatInterval(); + this.presenceState = {}; + if (heartbeatInterval) { + this.presenceEventEngine = new presence_1.PresenceEventEngine({ + heartbeat: this.heartbeat.bind(this), + leave: (parameters) => this.makeUnsubscribe(parameters, () => { }), + heartbeatDelay: () => new Promise((resolve, reject) => { + heartbeatInterval = this._configuration.getHeartbeatInterval(); + if (!heartbeatInterval) + reject(new pubnub_error_1.PubNubError('Heartbeat interval has been reset.')); + else + setTimeout(resolve, heartbeatInterval * 1000); + }), + retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + emitStatus: (status) => this.listenerManager.announceStatus(status), + config: this._configuration, presenceState: this.presenceState, - emitStatus: function (status) { - listenerManager.announceStatus(status); - }, }); - this.presenceEventEngine = presenceEventEngine; - this.join = this.presenceEventEngine.join.bind(presenceEventEngine); - this.leave = this.presenceEventEngine.leave.bind(presenceEventEngine); - this.leaveAll = this.presenceEventEngine.leaveAll.bind(presenceEventEngine); } - var eventEngine = new event_engine_1.EventEngine({ - handshake: this.handshake, - receiveMessages: this.receiveMessages, - delay: function (amount) { return new Promise(function (resolve) { return setTimeout(resolve, amount); }); }, - join: this.join, - leave: this.leave, - leaveAll: this.leaveAll, + this.eventEngine = new event_engine_1.EventEngine({ + handshake: this.subscribeHandshake.bind(this), + receiveMessages: this.subscribeReceiveMessages.bind(this), + delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + join: this.join.bind(this), + leave: this.leave.bind(this), + leaveAll: this.leaveAll.bind(this), presenceState: this.presenceState, - config: modules.config, - emitMessages: function (events) { - var e_1, _a; + config: this._configuration, + emitMessages: (events) => { try { - for (var events_1 = __values(events), events_1_1 = events_1.next(); !events_1_1.done; events_1_1 = events_1.next()) { - var event_1 = events_1_1.value; - _this._eventEmitter.emitEvent(event_1); - } + events.forEach((event) => this.eventEmitter.emitEvent(event)); } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (events_1_1 && !events_1_1.done && (_a = events_1.return)) _a.call(events_1); - } - finally { if (e_1) throw e_1.error; } + catch (e) { + const errorStatus = { + error: true, + category: categories_1.default.PNUnknownCategory, + errorData: e, + statusCode: 0, + }; + this.listenerManager.announceStatus(errorStatus); } }, - emitStatus: function (status) { - listenerManager.announceStatus(status); - }, + emitStatus: (status) => this.listenerManager.announceStatus(status), }); - this.subscribe = eventEngine.subscribe.bind(eventEngine); - this.unsubscribe = eventEngine.unsubscribe.bind(eventEngine); - this.unsubscribeAll = eventEngine.unsubscribeAll.bind(eventEngine); - this.reconnect = eventEngine.reconnect.bind(eventEngine); - this.disconnect = eventEngine.disconnect.bind(eventEngine); - this.destroy = eventEngine.dispose.bind(eventEngine); - this.getSubscribedChannels = eventEngine.getSubscribedChannels.bind(eventEngine); - this.getSubscribedChannelGroups = eventEngine.getSubscribedChannelGroups.bind(eventEngine); - this.eventEngine = eventEngine; } else { - var subscriptionManager_1 = new subscription_manager_1.default({ - timeEndpoint: timeEndpoint, - leaveEndpoint: leaveEndpoint, - heartbeatEndpoint: heartbeatEndpoint, - setStateEndpoint: setStateEndpoint, - subscribeEndpoint: subscribeEndpoint, - crypto: modules.crypto, - config: modules.config, - listenerManager: listenerManager, - getFileUrl: function (params) { return (0, get_file_url_1.default)(modules, params); }, - cryptoModule: modules.cryptoModule, - eventEmitter: this._eventEmitter, - }); - this.subscribe = subscriptionManager_1.adaptSubscribeChange.bind(subscriptionManager_1); - this.unsubscribe = subscriptionManager_1.adaptUnsubscribeChange.bind(subscriptionManager_1); - this.disconnect = subscriptionManager_1.disconnect.bind(subscriptionManager_1); - this.reconnect = subscriptionManager_1.reconnect.bind(subscriptionManager_1); - this.unsubscribeAll = subscriptionManager_1.unsubscribeAll.bind(subscriptionManager_1); - this.getSubscribedChannels = subscriptionManager_1.getSubscribedChannels.bind(subscriptionManager_1); - this.getSubscribedChannelGroups = subscriptionManager_1.getSubscribedChannelGroups.bind(subscriptionManager_1); - this.setState = subscriptionManager_1.adaptStateChange.bind(subscriptionManager_1); - this.presence = subscriptionManager_1.adaptPresenceChange.bind(subscriptionManager_1); - this.destroy = function (isOffline) { - subscriptionManager_1.unsubscribeAll(isOffline); - subscriptionManager_1.disconnect(); - }; + this.subscriptionManager = new subscription_manager_1.SubscriptionManager(this._configuration, this.listenerManager, this.eventEmitter, this.makeSubscribe.bind(this), this.heartbeat.bind(this), this.makeUnsubscribe.bind(this), this.time.bind(this)); } - this.addListener = this._eventEmitter.addListener.bind(this._eventEmitter); - this.removeListener = this._eventEmitter.removeListener.bind(this._eventEmitter); - this.removeAllListeners = this._eventEmitter.removeAllListeners.bind(this._eventEmitter); - this.parseToken = tokenManager.parseToken.bind(tokenManager); - this.setToken = tokenManager.setToken.bind(tokenManager); - this.getToken = tokenManager.getToken.bind(tokenManager); - /* channel groups */ - this.channelGroups = { - listGroups: endpoint_1.default.bind(this, modules, listChannelGroupsConfig), - listChannels: endpoint_1.default.bind(this, modules, listChannelsInChannelGroupConfig), - addChannels: endpoint_1.default.bind(this, modules, addChannelsChannelGroupConfig), - removeChannels: endpoint_1.default.bind(this, modules, removeChannelsChannelGroupConfig), - deleteGroup: endpoint_1.default.bind(this, modules, deleteChannelGroupConfig), - }; - /* push */ - this.push = { - addChannels: endpoint_1.default.bind(this, modules, addPushChannelsConfig), - removeChannels: endpoint_1.default.bind(this, modules, removePushChannelsConfig), - deleteDevice: endpoint_1.default.bind(this, modules, removeDevicePushConfig), - listChannels: endpoint_1.default.bind(this, modules, listPushChannelsConfig), - }; - /* presence */ - this.hereNow = endpoint_1.default.bind(this, modules, presenceHereNowConfig); - this.whereNow = endpoint_1.default.bind(this, modules, presenceWhereNowEndpointConfig); - this.getState = endpoint_1.default.bind(this, modules, presenceGetStateConfig); - /* PAM */ - this.grant = endpoint_1.default.bind(this, modules, grantEndpointConfig); - this.grantToken = endpoint_1.default.bind(this, modules, grantTokenEndpointConfig); - this.audit = endpoint_1.default.bind(this, modules, auditEndpointConfig); - this.revokeToken = endpoint_1.default.bind(this, modules, revoke_token_1.default); - this.publish = endpoint_1.default.bind(this, modules, publishEndpointConfig); - this.fire = function (args, callback) { - args.replicate = false; - args.storeInHistory = false; - return _this.publish(args, callback); - }; - this.signal = endpoint_1.default.bind(this, modules, signalEndpointConfig); - this.history = endpoint_1.default.bind(this, modules, historyEndpointConfig); - this.deleteMessages = endpoint_1.default.bind(this, modules, deleteMessagesEndpointConfig); - this.messageCounts = endpoint_1.default.bind(this, modules, messageCountsEndpointConfig); - this.fetchMessages = endpoint_1.default.bind(this, modules, fetchMessagesEndpointConfig); - // Actions API - this.addMessageAction = endpoint_1.default.bind(this, modules, addMessageActionEndpointConfig); - this.removeMessageAction = endpoint_1.default.bind(this, modules, removeMessageActionEndpointConfig); - this.getMessageActions = endpoint_1.default.bind(this, modules, getMessageActionEndpointConfig); - // File Upload API v1 - this.listFiles = endpoint_1.default.bind(this, modules, list_files_1.default); - var generateUploadUrl = endpoint_1.default.bind(this, modules, generate_upload_url_1.default); - this.publishFile = endpoint_1.default.bind(this, modules, publish_file_1.default); - this.sendFile = (0, send_file_1.default)({ - generateUploadUrl: generateUploadUrl, - publishFile: this.publishFile, - modules: modules, - }); - this.getFileUrl = function (params) { return (0, get_file_url_1.default)(modules, params); }; - this.downloadFile = endpoint_1.default.bind(this, modules, download_file_1.default); - this.deleteFile = endpoint_1.default.bind(this, modules, delete_file_1.default); - // entities - this.channel = function (name) { return new Channel_1.Channel(name, _this._eventEmitter, _this); }; - this.channelGroup = function (name) { return new ChannelGroup_1.ChannelGroup(name, _this._eventEmitter, _this); }; - this.channelMetadata = function (id) { return new ChannelMetadata_1.ChannelMetadata(id, _this._eventEmitter, _this); }; - this.userMetadata = function (id) { return new UserMetadata_1.UserMetadata(id, _this._eventEmitter, _this); }; - this.subscriptionSet = function (args) { - return new SubscriptionSet_1.SubscriptionSet({ - channels: args.channels, - channelGroups: args.channelGroups, - subscriptionOptions: args.subscriptionOptions, - eventEmitter: _this._eventEmitter, - pubnub: _this, - }); - }; - // Objects API v2 - this.objects = { - getAllUUIDMetadata: endpoint_1.default.bind(this, modules, get_all_1.default), - getUUIDMetadata: endpoint_1.default.bind(this, modules, get_1.default), - setUUIDMetadata: endpoint_1.default.bind(this, modules, set_1.default), - removeUUIDMetadata: endpoint_1.default.bind(this, modules, remove_1.default), - getAllChannelMetadata: endpoint_1.default.bind(this, modules, get_all_2.default), - getChannelMetadata: endpoint_1.default.bind(this, modules, get_2.default), - setChannelMetadata: endpoint_1.default.bind(this, modules, set_2.default), - removeChannelMetadata: endpoint_1.default.bind(this, modules, remove_2.default), - getChannelMembers: endpoint_1.default.bind(this, modules, get_3.default), - setChannelMembers: function (parameters) { - var rest = []; - for (var _i = 1; _i < arguments.length; _i++) { - rest[_i - 1] = arguments[_i]; - } - return endpoint_1.default.call.apply(endpoint_1.default, __spreadArray([_this, - modules, - set_3.default, __assign({ type: 'set' }, parameters)], __read(rest), false)); - }, - removeChannelMembers: function (parameters) { - var rest = []; - for (var _i = 1; _i < arguments.length; _i++) { - rest[_i - 1] = arguments[_i]; - } - return endpoint_1.default.call.apply(endpoint_1.default, __spreadArray([_this, - modules, - set_3.default, __assign({ type: 'delete' }, parameters)], __read(rest), false)); - }, - getMemberships: endpoint_1.default.bind(this, modules, get_4.default), - setMemberships: function (parameters) { - var rest = []; - for (var _i = 1; _i < arguments.length; _i++) { - rest[_i - 1] = arguments[_i]; - } - return endpoint_1.default.call.apply(endpoint_1.default, __spreadArray([_this, - modules, - set_4.default, __assign({ type: 'set' }, parameters)], __read(rest), false)); - }, - removeMemberships: function (parameters) { - var rest = []; - for (var _i = 1; _i < arguments.length; _i++) { - rest[_i - 1] = arguments[_i]; + } + get configuration() { + return this._configuration; + } + get _config() { + return this.configuration; + } + get authKey() { + var _a; + return (_a = this._configuration.authKey) !== null && _a !== void 0 ? _a : undefined; + } + getAuthKey() { + return this.authKey; + } + setAuthKey(authKey) { + this._configuration.setAuthKey(authKey); + } + get userId() { + return this._configuration.userId; + } + set userId(value) { + if (!value || typeof value !== 'string' || value.trim().length === 0) + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); + this._configuration.userId = value; + } + getUserId() { + return this._configuration.userId; + } + setUserId(value) { + if (!value || typeof value !== 'string' || value.trim().length === 0) + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); + this._configuration.userId = value; + } + get filterExpression() { + var _a; + return (_a = this._configuration.getFilterExpression()) !== null && _a !== void 0 ? _a : undefined; + } + getFilterExpression() { + return this.filterExpression; + } + set filterExpression(expression) { + this._configuration.setFilterExpression(expression); + } + setFilterExpression(expression) { + this.filterExpression = expression; + } + get cipherKey() { + return this._configuration.getCipherKey(); + } + set cipherKey(key) { + this._configuration.setCipherKey(key); + } + setCipherKey(key) { + this.cipherKey = key; + } + set heartbeatInterval(interval) { + this._configuration.setHeartbeatInterval(interval); + } + setHeartbeatInterval(interval) { + this.heartbeatInterval = interval; + } + getVersion() { + return this._configuration.getVersion(); + } + _addPnsdkSuffix(name, suffix) { + this._configuration._addPnsdkSuffix(name, suffix); + } + getUUID() { + return this.userId; + } + setUUID(value) { + this.userId = value; + } + get customEncrypt() { + return this._configuration.getCustomEncrypt(); + } + get customDecrypt() { + return this._configuration.getCustomDecrypt(); + } + channel(name) { + return new Channel_1.Channel(name, this.eventEmitter, this); + } + channelGroup(name) { + return new ChannelGroup_1.ChannelGroup(name, this.eventEmitter, this); + } + channelMetadata(id) { + return new ChannelMetadata_1.ChannelMetadata(id, this.eventEmitter, this); + } + userMetadata(id) { + return new UserMetadata_1.UserMetadata(id, this.eventEmitter, this); + } + subscriptionSet(parameters) { + return new SubscriptionSet_1.SubscriptionSet(Object.assign(Object.assign({}, parameters), { eventEmitter: this.eventEmitter, pubnub: this })); + } + sendRequest(request, callback) { + return __awaiter(this, void 0, void 0, function* () { + const validationResult = request.validate(); + if (validationResult) { + if (callback) + return callback((0, pubnub_error_1.createValidationError)(validationResult), null); + throw new pubnub_error_1.PubNubError('Validation failed, check status for details', (0, pubnub_error_1.createValidationError)(validationResult)); + } + const transportRequest = request.request(); + if (transportRequest.formData && transportRequest.formData.length > 0) { + transportRequest.timeout = 300; + } + else { + if (request.operation() === operations_1.default.PNSubscribeOperation) + transportRequest.timeout = this._configuration.getSubscribeTimeout(); + else + transportRequest.timeout = this._configuration.getTransactionTimeout(); + } + const status = { + error: false, + operation: request.operation(), + category: categories_1.default.PNAcknowledgmentCategory, + statusCode: 0, + }; + const [sendableRequest, cancellationController] = this.transport.makeSendable(transportRequest); + request.cancellationController = cancellationController ? cancellationController : null; + return sendableRequest + .then((response) => { + status.statusCode = response.status; + if (response.status !== 200 && response.status !== 204) { + const contentType = response.headers['content-type']; + if (contentType || contentType.indexOf('javascript') !== -1 || contentType.indexOf('json') !== -1) { + const json = JSON.parse(PubNubCore.decoder.decode(response.body)); + if (typeof json === 'object' && 'error' in json && json.error && typeof json.error === 'object') + status.errorData = json.error; + } } - return endpoint_1.default.call.apply(endpoint_1.default, __spreadArray([_this, - modules, - set_4.default, __assign({ type: 'delete' }, parameters)], __read(rest), false)); - }, - }; - // User Apis - this.createUser = function (args) { - return _this.objects.setUUIDMetadata({ - uuid: args.userId, - data: args.data, - include: args.include, + return request.parse(response); + }) + .then((parsed) => { + if (callback) + return callback(status, parsed); + return parsed; + }) + .catch((error) => { + const apiError = !(error instanceof pubnub_api_error_1.PubNubAPIError) ? pubnub_api_error_1.PubNubAPIError.create(error) : error; + if (callback) + return callback(apiError.toStatus(request.operation()), null); + throw apiError.toPubNubError(request.operation(), 'REST API request processing error, check status for details'); }); - }; - this.updateUser = this.createUser; - this.removeUser = function (args) { - return _this.objects.removeUUIDMetadata({ - uuid: args === null || args === void 0 ? void 0 : args.userId, + }); + } + destroy(isOffline) { + if (this.subscriptionManager) { + this.subscriptionManager.unsubscribeAll(isOffline); + this.subscriptionManager.disconnect(); + } + else if (this.eventEngine) + this.eventEngine.dispose(); + } + stop() { + this.destroy(); + } + addListener(listener) { + this.listenerManager.addListener(listener); + } + removeListener(listener) { + this.listenerManager.removeListener(listener); + } + removeAllListeners() { + this.listenerManager.removeAllListeners(); + } + publish(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new Publish.PublishRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + signal(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new Signal.SignalRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + fire(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + callback !== null && callback !== void 0 ? callback : (callback = () => { }); + return this.publish(Object.assign(Object.assign({}, parameters), { replicate: false, storeInHistory: false }), callback); + }); + } + getSubscribedChannels() { + if (this.subscriptionManager) + return this.subscriptionManager.subscribedChannels; + else if (this.eventEngine) + return this.eventEngine.getSubscribedChannels(); + return []; + } + getSubscribedChannelGroups() { + if (this.subscriptionManager) + return this.subscriptionManager.subscribedChannelGroups; + else if (this.eventEngine) + return this.eventEngine.getSubscribedChannelGroups(); + return []; + } + subscribe(parameters) { + if (this.subscriptionManager) + this.subscriptionManager.subscribe(parameters); + else if (this.eventEngine) + this.eventEngine.subscribe(parameters); + } + makeSubscribe(parameters, callback) { + const request = new subscribe_1.SubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + this.sendRequest(request, (status, result) => { + var _a; + if (this.subscriptionManager && ((_a = this.subscriptionManager.abort) === null || _a === void 0 ? void 0 : _a.identifier) === request.requestIdentifier) + this.subscriptionManager.abort = null; + callback(status, result); + }); + if (this.subscriptionManager) { + const callableAbort = () => request.abort(); + callableAbort.identifier = request.requestIdentifier; + this.subscriptionManager.abort = callableAbort; + } + } + unsubscribe(parameters) { + if (this.subscriptionManager) + this.subscriptionManager.unsubscribe(parameters); + else if (this.eventEngine) + this.eventEngine.unsubscribe(parameters); + } + makeUnsubscribe(parameters, callback) { + this.sendRequest(new leave_1.PresenceLeaveRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })), callback); + } + unsubscribeAll() { + if (this.subscriptionManager) + this.subscriptionManager.unsubscribeAll(); + else if (this.eventEngine) + this.eventEngine.unsubscribeAll(); + } + disconnect() { + if (this.subscriptionManager) + this.subscriptionManager.disconnect(); + else if (this.eventEngine) + this.eventEngine.disconnect(); + } + reconnect(parameters) { + if (this.subscriptionManager) + this.subscriptionManager.reconnect(); + else if (this.eventEngine) + this.eventEngine.reconnect(parameters !== null && parameters !== void 0 ? parameters : {}); + } + subscribeHandshake(parameters) { + return __awaiter(this, void 0, void 0, function* () { + const request = new handshake_1.HandshakeSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); }); - }; - this.fetchUser = function (args) { - return _this.objects.getUUIDMetadata({ - uuid: args === null || args === void 0 ? void 0 : args.userId, - include: args === null || args === void 0 ? void 0 : args.include, + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response.cursor; }); - }; - this.fetchUsers = this.objects.getAllUUIDMetadata; - // Space apis - this.createSpace = function (args) { - return _this.objects.setChannelMetadata({ - channel: args.spaceId, - data: args.data, - include: args.include, + }); + } + subscribeReceiveMessages(parameters) { + return __awaiter(this, void 0, void 0, function* () { + const request = new receiveMessages_1.ReceiveMessagesSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); }); - }; - this.updateSpace = this.createSpace; - this.removeSpace = function (args) { - return _this.objects.removeChannelMetadata({ - channel: args.spaceId, + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response; }); - }; - this.fetchSpace = function (args) { - return _this.objects.getChannelMetadata({ - channel: args.spaceId, - include: args.include, + }); + } + getMessageActions(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new get_message_actions_1.GetMessageActionsRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + addMessageAction(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new add_message_action_1.AddMessageActionRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + removeMessageAction(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new remove_message_action_1.RemoveMessageAction(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + fetchMessages(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new fetch_messages_1.FetchMessagesRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + deleteMessages(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new delete_messages_1.DeleteMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + messageCounts(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new message_counts_1.MessageCountRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + history(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new get_history_1.GetHistoryRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + hereNow(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new here_now_1.HereNowRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + whereNow(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const request = new where_now_1.WhereNowRequest({ + uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, + keySet: this._configuration.keySet, }); - }; - this.fetchSpaces = this.objects.getAllChannelMetadata; - // Membership apis - this.addMemberships = function (parameters) { + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + getState(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const request = new get_state_1.GetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + setState(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { var _a, _b; - if (typeof parameters.spaceId === 'string') { - return _this.objects.setChannelMembers({ - channel: parameters.spaceId, - uuids: (_a = parameters.users) === null || _a === void 0 ? void 0 : _a.map(function (user) { - if (typeof user === 'string') { - return user; - } - return { - id: user.userId, - custom: user.custom, - status: user.status, - }; - }), - limit: 0, - }); - } - else { - return _this.objects.setMemberships({ - uuid: parameters.userId, - channels: (_b = parameters.spaces) === null || _b === void 0 ? void 0 : _b.map(function (space) { - if (typeof space === 'string') { - return space; - } - return { - id: space.spaceId, - custom: space.custom, - status: space.status, - }; - }), - limit: 0, - }); - } - }; - this.updateMemberships = this.addMemberships; - this.removeMemberships = function (parameters) { - if (typeof parameters.spaceId === 'string') { - return _this.objects.removeChannelMembers({ - channel: parameters.spaceId, - uuids: parameters.userIds, - limit: 0, - }); - } - else { - return _this.objects.removeMemberships({ - uuid: parameters.userId, - channels: parameters.spaceIds, - limit: 0, - }); - } - }; - this.fetchMemberships = function (params) { - if (typeof params.spaceId === 'string') { - return _this.objects - .getChannelMembers({ - channel: params.spaceId, - filter: params.filter, - limit: params.limit, - page: params.page, - include: { - customFields: params.include.customFields, - UUIDFields: params.include.userFields, - customUUIDFields: params.include.customUserFields, - statusField: params.include.statusField, - UUIDStatusField: params.include.userStatusField, - UUIDTypeField: params.include.userTypeField, - totalCount: params.include.totalCount, - }, - sort: params.sort != null - ? Object.fromEntries(Object.entries(params.sort).map(function (_a) { - var _b = __read(_a, 2), k = _b[0], v = _b[1]; - return [k.replace('user', 'uuid'), v]; - })) - : null, - }) - .then(function (res) { - var _a; - res.data = (_a = res.data) === null || _a === void 0 ? void 0 : _a.map(function (m) { - return { - user: m.uuid, - custom: m.custom, - updated: m.updated, - eTag: m.eTag, - }; - }); - return res; - }); - } - else { - return _this.objects - .getMemberships({ - uuid: params.userId, - filter: params.filter, - limit: params.limit, - page: params.page, - include: { - customFields: params.include.customFields, - channelFields: params.include.spaceFields, - customChannelFields: params.include.customSpaceFields, - statusField: params.include.statusField, - channelStatusField: params.include.spaceStatusField, - channelTypeField: params.include.spaceTypeField, - totalCount: params.include.totalCount, - }, - sort: params.sort != null - ? Object.fromEntries(Object.entries(params.sort).map(function (_a) { - var _b = __read(_a, 2), k = _b[0], v = _b[1]; - return [k.replace('space', 'channel'), v]; - })) - : null, - }) - .then(function (res) { - var _a; - res.data = (_a = res.data) === null || _a === void 0 ? void 0 : _a.map(function (m) { - return { - space: m.channel, - custom: m.custom, - updated: m.updated, - eTag: m.eTag, - }; - }); - return res; - }); + const { keySet, userId: userId } = this._configuration; + const heartbeat = this._configuration.getPresenceTimeout(); + let request; + if (this._configuration.enableEventEngine && this.presenceState) { + const presenceState = this.presenceState; + (_a = parameters.channels) === null || _a === void 0 ? void 0 : _a.forEach((channel) => (presenceState[channel] = parameters.state)); + if ('channelGroups' in parameters) { + (_b = parameters.channelGroups) === null || _b === void 0 ? void 0 : _b.forEach((group) => (presenceState[group] = parameters.state)); + } } - }; - this.time = timeEndpoint; - // --- deprecated ------------------ - this.stop = this.destroy; // -------- - // --- deprecated ------------------ - // mount crypto - this.encrypt = function (data, key) { - if (typeof key === 'undefined' && modules.cryptoModule) { - var encrypted = modules.cryptoModule.encrypt(data); - return typeof encrypted === 'string' ? encrypted : (0, base64_codec_1.encode)(encrypted); + if ('withHeartbeat' in parameters) { + request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet, heartbeat })); } else { - return crypto.encrypt(data, key); - } - }; - this.decrypt = function (data, key) { - if (typeof key === 'undefined' && cryptoModule) { - var decrypted = modules.cryptoModule.decrypt(data); - return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted; + request = new set_state_1.SetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { keySet, uuid: userId })); } - else { - return crypto.decrypt(data, key); + if (this.subscriptionManager) + this.subscriptionManager.setState(parameters); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + presence(parameters) { + var _a; + (_a = this.subscriptionManager) === null || _a === void 0 ? void 0 : _a.changePresence(parameters); + } + heartbeat(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + join(parameters) { + var _a; + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.join(parameters); + } + leave(parameters) { + var _a; + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leave(parameters); + } + leaveAll() { + var _a; + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leaveAll(); + } + grantToken(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new grant_token_1.GrantTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + revokeToken(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new revoke_token_1.RevokeTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + get token() { + return this.tokenManager.getToken(); + } + getToken() { + return this.token; + } + set token(token) { + this.tokenManager.setToken(token); + } + setToken(token) { + this.token = token; + } + parseToken(token) { + return this.tokenManager.parseToken(token); + } + grant(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new grant_1.GrantRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + audit(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new audit_1.AuditRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + get objects() { + return this._objects; + } + fetchUsers(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._getAllUUIDMetadata(parametersOrCallback, callback); + }); + } + fetchUser(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._getUUIDMetadata(parametersOrCallback, callback); + }); + } + createUser(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._setUUIDMetadata(parameters, callback); + }); + } + updateUser(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._setUUIDMetadata(parameters, callback); + }); + } + removeUser(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._removeUUIDMetadata(parametersOrCallback, callback); + }); + } + fetchSpaces(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._getAllChannelMetadata(parametersOrCallback, callback); + }); + } + fetchSpace(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._getChannelMetadata(parameters, callback); + }); + } + createSpace(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._setChannelMetadata(parameters, callback); + }); + } + updateSpace(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._setChannelMetadata(parameters, callback); + }); + } + removeSpace(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects._removeChannelMetadata(parameters, callback); + }); + } + fetchMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects.fetchMemberships(parameters, callback); + }); + } + addMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects.addMemberships(parameters, callback); + }); + } + updateMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this.objects.addMemberships(parameters, callback); + }); + } + removeMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b, _c; + if ('spaceId' in parameters) { + const spaceParameters = parameters; + const requestParameters = { + channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, + uuids: (_b = spaceParameters.userIds) !== null && _b !== void 0 ? _b : spaceParameters.uuids, + limit: 0, + }; + if (callback) + return this.objects.removeChannelMembers(requestParameters, callback); + return this.objects.removeChannelMembers(requestParameters); } - }; - /* config */ - this.getAuthKey = modules.config.getAuthKey.bind(modules.config); - this.setAuthKey = modules.config.setAuthKey.bind(modules.config); - this.getUUID = modules.config.getUUID.bind(modules.config); - this.setUUID = modules.config.setUUID.bind(modules.config); - this.getUserId = modules.config.getUserId.bind(modules.config); - this.setUserId = modules.config.setUserId.bind(modules.config); - this.getFilterExpression = modules.config.getFilterExpression.bind(modules.config); - this.setFilterExpression = modules.config.setFilterExpression.bind(modules.config); - this.setCipherKey = function (key) { return modules.config.setCipherKey(key, setup, modules); }; - this.setHeartbeatInterval = modules.config.setHeartbeatInterval.bind(modules.config); - if (networking.hasModule('proxy')) { - this.setProxy = function (proxy) { - modules.config.setProxy(proxy); - _this.reconnect(); + const userParameters = parameters; + const requestParameters = { + uuid: userParameters.userId, + channels: (_c = userParameters.spaceIds) !== null && _c !== void 0 ? _c : userParameters.channels, + limit: 0, }; - } + if (callback) + return this.objects.removeMemberships(requestParameters, callback); + return this.objects.removeMemberships(requestParameters); + }); + } + get channelGroups() { + return this._channelGroups; } - default_1.prototype.getVersion = function () { - return this._config.getVersion(); - }; - default_1.prototype._addPnsdkSuffix = function (name, suffix) { - this._config._addPnsdkSuffix(name, suffix); - }; - // network hooks to indicate network changes - default_1.prototype.networkDownDetected = function () { - this._listenerManager.announceNetworkDown(); - if (this._config.restore) { - this.disconnect(); + get push() { + return this._push; + } + sendFile(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const sendFileRequest = new send_file_1.SendFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, fileUploadPublishRetryLimit: this._configuration.fileUploadPublishRetryLimit, file: parameters.file, sendRequest: this.sendRequest.bind(this), publishFile: this.publishFile.bind(this), crypto: this._configuration.getCryptoModule(), cryptography: this.cryptography ? this.cryptography : undefined })); + const status = { + error: false, + operation: operations_1.default.PNPublishFileOperation, + category: categories_1.default.PNAcknowledgmentCategory, + statusCode: 0, + }; + return sendFileRequest + .process() + .then((response) => { + status.statusCode = response.status; + if (callback) + return callback(status, response); + return response; + }) + .catch((error) => { + let errorStatus; + if (error instanceof pubnub_error_1.PubNubError) + errorStatus = error.status; + else if (error instanceof pubnub_api_error_1.PubNubAPIError) + errorStatus = error.toStatus(status.operation); + if (callback && errorStatus) + callback(errorStatus, null); + throw new pubnub_error_1.PubNubError('REST API request processing error, check status for details', errorStatus); + }); + }); + } + publishFile(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const request = new publish_file_1.PublishFileMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + listFiles(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new list_files_1.FilesListRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + getFileUrl(parameters) { + var _a; + const request = this.transport.request(new get_file_url_1.GetFileDownloadUrlRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })).request()); + const query = (_a = request.queryParameters) !== null && _a !== void 0 ? _a : {}; + const queryString = Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${(0, utils_1.encodeString)(queryValue)}`; + return queryValue.map((value) => `${key}=${(0, utils_1.encodeString)(value)}`).join('&'); + }) + .join('&'); + return `${request.origin}${request.path}?${queryString}`; + } + downloadFile(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const request = new download_file_1.DownloadFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, cryptography: this.cryptography ? this.cryptography : undefined, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return (yield this.sendRequest(request)); + }); + } + deleteFile(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new delete_file_1.DeleteFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + time(callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new Time.TimeRequest(); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + encrypt(data, customCipherKey) { + const cryptoModule = this._configuration.getCryptoModule(); + if (!customCipherKey && cryptoModule && typeof data === 'string') { + const encrypted = cryptoModule.encrypt(data); + return typeof encrypted === 'string' ? encrypted : (0, base64_codec_1.encode)(encrypted); } - else { - this.destroy(true); + if (!this.crypto) + throw new Error('Encryption error: cypher key not set'); + return this.crypto.encrypt(data, customCipherKey); + } + decrypt(data, customCipherKey) { + const cryptoModule = this._configuration.getCryptoModule(); + if (!customCipherKey && cryptoModule) { + const decrypted = cryptoModule.decrypt(data); + return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted; } - }; - default_1.prototype.networkUpDetected = function () { - this._listenerManager.announceNetworkUp(); - this.reconnect(); - }; - default_1.notificationPayload = function (title, body) { - return new push_payload_1.default(title, body); - }; - default_1.generateUUID = function () { - return uuid_1.default.createUUID(); - }; - default_1.OPERATIONS = operations_1.default; - default_1.CATEGORIES = categories_1.default; - default_1.LinearRetryPolicy = retryPolicy_1.RetryPolicy.LinearRetryPolicy; - default_1.ExponentialRetryPolicy = retryPolicy_1.RetryPolicy.ExponentialRetryPolicy; - return default_1; -}()); -exports.default = default_1; + if (!this.crypto) + throw new Error('Decryption error: cypher key not set'); + return this.crypto.decrypt(data, customCipherKey); + } + encryptFile(keyOrFile, file) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (typeof keyOrFile !== 'string') + file = keyOrFile; + if (!file) + throw new Error('File encryption error. Source file is missing.'); + if (!this._configuration.PubNubFile) + throw new Error('File encryption error. File constructor not configured.'); + if (typeof keyOrFile !== 'string' && !this._configuration.getCryptoModule()) + throw new Error('File encryption error. Crypto module not configured.'); + if (typeof keyOrFile === 'string') { + if (!this.cryptography) + throw new Error('File encryption error. File encryption not available'); + return this.cryptography.encryptFile(keyOrFile, file, this._configuration.PubNubFile); + } + return (_a = this._configuration.getCryptoModule()) === null || _a === void 0 ? void 0 : _a.encryptFile(file, this._configuration.PubNubFile); + }); + } + decryptFile(keyOrFile, file) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (typeof keyOrFile !== 'string') + file = keyOrFile; + if (!file) + throw new Error('File encryption error. Source file is missing.'); + if (!this._configuration.PubNubFile) + throw new Error('File decryption error. File constructor' + ' not configured.'); + if (typeof keyOrFile === 'string' && !this._configuration.getCryptoModule()) + throw new Error('File decryption error. Crypto module not configured.'); + if (typeof keyOrFile === 'string') { + if (!this.cryptography) + throw new Error('File decryption error. File decryption not available'); + return this.cryptography.decryptFile(keyOrFile, file, this._configuration.PubNubFile); + } + return (_a = this._configuration.getCryptoModule()) === null || _a === void 0 ? void 0 : _a.decryptFile(file, this._configuration.PubNubFile); + }); + } +} +exports.PubNubCore = PubNubCore; +PubNubCore.decoder = new TextDecoder(); +PubNubCore.OPERATIONS = operations_1.default; +PubNubCore.CATEGORIES = categories_1.default; +PubNubCore.ExponentialRetryPolicy = retryPolicy_1.RetryPolicy.ExponentialRetryPolicy; +PubNubCore.LinearRetryPolicy = retryPolicy_1.RetryPolicy.LinearRetryPolicy; diff --git a/lib/core/pubnub-objects.js b/lib/core/pubnub-objects.js new file mode 100644 index 000000000..79b1e885b --- /dev/null +++ b/lib/core/pubnub-objects.js @@ -0,0 +1,317 @@ +"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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const get_all_1 = require("./endpoints/objects/channel/get_all"); +const remove_1 = require("./endpoints/objects/channel/remove"); +const get_1 = require("./endpoints/objects/membership/get"); +const set_1 = require("./endpoints/objects/membership/set"); +const get_all_2 = require("./endpoints/objects/uuid/get_all"); +const get_2 = require("./endpoints/objects/channel/get"); +const set_2 = require("./endpoints/objects/channel/set"); +const remove_2 = require("./endpoints/objects/uuid/remove"); +const get_3 = require("./endpoints/objects/member/get"); +const set_3 = require("./endpoints/objects/member/set"); +const get_4 = require("./endpoints/objects/uuid/get"); +const set_4 = require("./endpoints/objects/uuid/set"); +class PubNubObjects { + constructor(configuration, sendRequest) { + this.configuration = configuration; + this.sendRequest = sendRequest; + this.keySet = configuration.keySet; + } + getAllUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._getAllUUIDMetadata(parametersOrCallback, callback); + }); + } + _getAllUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + const request = new get_all_2.GetAllUUIDMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + getUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._getUUIDMetadata(parametersOrCallback, callback); + }); + } + _getUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new get_4.GetUUIDMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + setUUIDMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._setUUIDMetadata(parameters, callback); + }); + } + _setUUIDMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new set_4.SetUUIDMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + removeUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._removeUUIDMetadata(parametersOrCallback, callback); + }); + } + _removeUUIDMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new remove_2.RemoveUUIDMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + getAllChannelMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._getAllChannelMetadata(parametersOrCallback, callback); + }); + } + _getAllChannelMetadata(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + const request = new get_all_1.GetAllChannelsMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + getChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._getChannelMetadata(parameters, callback); + }); + } + _getChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new get_2.GetChannelMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + setChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._setChannelMetadata(parameters, callback); + }); + } + _setChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new set_2.SetChannelMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + removeChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + return this._removeChannelMetadata(parameters, callback); + }); + } + _removeChannelMetadata(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new remove_1.RemoveChannelMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + getChannelMembers(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new get_3.GetChannelMembersRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + setChannelMembers(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new set_3.SetChannelMembersRequest(Object.assign(Object.assign({}, parameters), { type: 'set', keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + removeChannelMembers(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new set_3.SetChannelMembersRequest(Object.assign(Object.assign({}, parameters), { type: 'delete', keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + getMemberships(parametersOrCallback, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new get_1.GetUUIDMembershipsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + setMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new set_1.SetUUIDMembershipsRequest(Object.assign(Object.assign({}, parameters), { type: 'set', keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + removeMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + if (parameters.userId) + parameters.uuid = parameters.userId; + (_a = parameters.uuid) !== null && _a !== void 0 ? _a : (parameters.uuid = this.configuration.userId); + const request = new set_1.SetUUIDMembershipsRequest(Object.assign(Object.assign({}, parameters), { type: 'delete', keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + fetchMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b; + if ('spaceId' in parameters) { + const spaceParameters = parameters; + const mappedParameters = { + channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, + filter: spaceParameters.filter, + limit: spaceParameters.limit, + page: spaceParameters.page, + include: Object.assign({}, spaceParameters.include), + sort: spaceParameters.sort + ? Object.fromEntries(Object.entries(spaceParameters.sort).map(([key, value]) => [key.replace('user', 'uuid'), value])) + : undefined, + }; + const mapMembers = (response) => ({ + status: response.status, + data: response.data.map((members) => ({ + user: members.uuid, + custom: members.custom, + updated: members.updated, + eTag: members.eTag, + })), + totalCount: response.totalCount, + next: response.next, + prev: response.prev, + }); + if (callback) + return this.getChannelMembers(mappedParameters, (status, result) => { + callback(status, result ? mapMembers(result) : result); + }); + return this.getChannelMembers(mappedParameters).then(mapMembers); + } + const userParameters = parameters; + const mappedParameters = { + uuid: (_b = userParameters.userId) !== null && _b !== void 0 ? _b : userParameters.uuid, + filter: userParameters.filter, + limit: userParameters.limit, + page: userParameters.page, + include: Object.assign({}, userParameters.include), + sort: userParameters.sort + ? Object.fromEntries(Object.entries(userParameters.sort).map(([key, value]) => [key.replace('space', 'channel'), value])) + : undefined, + }; + const mapMemberships = (response) => ({ + status: response.status, + data: response.data.map((membership) => ({ + space: membership.channel, + custom: membership.custom, + updated: membership.updated, + eTag: membership.eTag, + })), + totalCount: response.totalCount, + next: response.next, + prev: response.prev, + }); + if (callback) + return this.getMemberships(mappedParameters, (status, result) => { + callback(status, result ? mapMemberships(result) : result); + }); + return this.getMemberships(mappedParameters).then(mapMemberships); + }); + } + addMemberships(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + var _a, _b, _c, _d, _e, _f; + if ('spaceId' in parameters) { + const spaceParameters = parameters; + const mappedParameters = { + channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, + uuids: (_c = (_b = spaceParameters.users) === null || _b === void 0 ? void 0 : _b.map((user) => { + if (typeof user === 'string') + return user; + user.userId; + return { id: user.userId, custom: user.custom }; + })) !== null && _c !== void 0 ? _c : spaceParameters.uuids, + limit: 0, + }; + if (callback) + return this.setChannelMembers(mappedParameters, callback); + return this.setChannelMembers(mappedParameters); + } + const userParameters = parameters; + const mappedParameters = { + uuid: (_d = userParameters.userId) !== null && _d !== void 0 ? _d : userParameters.uuid, + channels: (_f = (_e = userParameters.spaces) === null || _e === void 0 ? void 0 : _e.map((space) => { + if (typeof space === 'string') + return space; + return { + id: space.spaceId, + custom: space.custom, + }; + })) !== null && _f !== void 0 ? _f : userParameters.channels, + limit: 0, + }; + if (callback) + return this.setMemberships(mappedParameters, callback); + return this.setMemberships(mappedParameters); + }); + } +} +exports.default = PubNubObjects; diff --git a/lib/core/pubnub-push.js b/lib/core/pubnub-push.js new file mode 100644 index 000000000..94f135a9c --- /dev/null +++ b/lib/core/pubnub-push.js @@ -0,0 +1,54 @@ +"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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const remove_push_channels_1 = require("./endpoints/push/remove_push_channels"); +const list_push_channels_1 = require("./endpoints/push/list_push_channels"); +const add_push_channels_1 = require("./endpoints/push/add_push_channels"); +const remove_device_1 = require("./endpoints/push/remove_device"); +class PubNubPushNotifications { + constructor(keySet, sendRequest) { + this.keySet = keySet; + this.sendRequest = sendRequest; + } + listChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new list_push_channels_1.ListDevicePushNotificationChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + addChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new add_push_channels_1.AddDevicePushNotificationChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + removeChannels(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new remove_push_channels_1.RemoveDevicePushNotificationChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } + deleteDevice(parameters, callback) { + return __awaiter(this, void 0, void 0, function* () { + const request = new remove_device_1.RemoveDevicePushNotificationRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + }); + } +} +exports.default = PubNubPushNotifications; diff --git a/lib/entities/common.js b/lib/core/types/api/access-panager.js similarity index 100% rename from lib/entities/common.js rename to lib/core/types/api/access-panager.js diff --git a/lib/core/types/api/app-context.js b/lib/core/types/api/app-context.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/api/app-context.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/api/channel-groups.js b/lib/core/types/api/channel-groups.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/api/channel-groups.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/api/file-sharing.js b/lib/core/types/api/file-sharing.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/api/file-sharing.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/api/history.js b/lib/core/types/api/history.js new file mode 100644 index 000000000..82e074734 --- /dev/null +++ b/lib/core/types/api/history.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PubNubMessageType = void 0; +var PubNubMessageType; +(function (PubNubMessageType) { + PubNubMessageType[PubNubMessageType["Message"] = -1] = "Message"; + PubNubMessageType[PubNubMessageType["Files"] = 4] = "Files"; +})(PubNubMessageType || (exports.PubNubMessageType = PubNubMessageType = {})); diff --git a/lib/core/types/api/index.js b/lib/core/types/api/index.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/api/index.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/api/message-action.js b/lib/core/types/api/message-action.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/api/message-action.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/api/presence.js b/lib/core/types/api/presence.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/api/presence.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/api/push-notifications.js b/lib/core/types/api/push-notifications.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/api/push-notifications.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/api/push.js b/lib/core/types/api/push.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/api/push.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/api/subscription.js b/lib/core/types/api/subscription.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/api/subscription.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/file.js b/lib/core/types/file.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/file.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/transport-request.js b/lib/core/types/transport-request.js new file mode 100644 index 000000000..d24afce7b --- /dev/null +++ b/lib/core/types/transport-request.js @@ -0,0 +1,11 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TransportMethod = void 0; +var TransportMethod; +(function (TransportMethod) { + TransportMethod["GET"] = "GET"; + TransportMethod["POST"] = "POST"; + TransportMethod["PATCH"] = "PATCH"; + TransportMethod["DELETE"] = "DELETE"; + TransportMethod["LOCAL"] = "LOCAL"; +})(TransportMethod || (exports.TransportMethod = TransportMethod = {})); diff --git a/lib/core/types/transport-response.js b/lib/core/types/transport-response.js new file mode 100644 index 000000000..c8ad2e549 --- /dev/null +++ b/lib/core/types/transport-response.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/utils.js b/lib/core/utils.js index 51f97541f..2bd14eee4 100644 --- a/lib/core/utils.js +++ b/lib/core/utils.js @@ -1,85 +1,38 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.queryStringFromObject = exports.findUniqueCommonElements = exports.removeSingleOccurance = exports.encodeNames = exports.encodeString = void 0; +const encodeString = (input) => { + return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); }; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); +exports.encodeString = encodeString; +const encodeNames = (names, defaultString) => { + const encodedNames = names.map((name) => (0, exports.encodeString)(name)); + return encodedNames.length ? encodedNames.join(',') : defaultString !== null && defaultString !== void 0 ? defaultString : ''; }; -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 }; -} -function stringToArrayBuffer(str) { - var buf = new ArrayBuffer(str.length * 2); - var bufView = new Uint16Array(buf); - for (var i = 0, strLen = str.length; i < strLen; i++) { - bufView[i] = str.charCodeAt(i); - } - return buf; -} -function removeSingleOccurance(source, elementsToRemove) { - var removed = Object.fromEntries(elementsToRemove.map(function (prop) { return [prop, false]; })); - return source.filter(function (e) { +exports.encodeNames = encodeNames; +const removeSingleOccurance = (source, elementsToRemove) => { + const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); + return source.filter((e) => { if (elementsToRemove.includes(e) && !removed[e]) { removed[e] = true; return false; } return true; }); -} -function findUniqueCommonElements(a, b) { - return __spreadArray([], __read(a), false).filter(function (value) { - return b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value); - }); -} -module.exports = { - signPamFromParams: signPamFromParams, - endsWith: endsWith, - createPromise: createPromise, - encodeString: encodeString, - stringToArrayBuffer: stringToArrayBuffer, - removeSingleOccurance: removeSingleOccurance, - findUniqueCommonElements: findUniqueCommonElements, }; +exports.removeSingleOccurance = removeSingleOccurance; +const findUniqueCommonElements = (a, b) => { + return [...a].filter((value) => b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value)); +}; +exports.findUniqueCommonElements = findUniqueCommonElements; +const queryStringFromObject = (query) => { + return Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${(0, exports.encodeString)(queryValue)}`; + return queryValue.map((value) => `${key}=${(0, exports.encodeString)(value)}`).join('&'); + }) + .join('&'); +}; +exports.queryStringFromObject = queryStringFromObject; diff --git a/lib/crypto/index.js b/lib/crypto/index.js index 1e44d895d..3918c74e4 100644 --- a/lib/crypto/index.js +++ b/lib/crypto/index.js @@ -1,2 +1 @@ "use strict"; -/** */ diff --git a/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js b/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js index 613e8cfec..c03ba9b34 100644 --- a/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js +++ b/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js @@ -8,139 +8,97 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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 }); -var stream_1 = require("stream"); -var crypto_1 = require("crypto"); -var AesCbcCryptor = /** @class */ (function () { - function AesCbcCryptor(configuration) { - this.cipherKey = configuration.cipherKey; +const crypto_1 = require("crypto"); +const stream_1 = require("stream"); +class AesCbcCryptor { + constructor({ cipherKey }) { + this.cipherKey = cipherKey; } - Object.defineProperty(AesCbcCryptor.prototype, "algo", { - get: function () { - return 'aes-256-cbc'; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(AesCbcCryptor.prototype, "identifier", { - get: function () { - return 'ACRH'; - }, - enumerable: false, - configurable: true - }); - AesCbcCryptor.prototype.getIv = function () { - return (0, crypto_1.randomBytes)(AesCbcCryptor.BLOCK_SIZE); - }; - AesCbcCryptor.prototype.getKey = function () { - var sha = (0, crypto_1.createHash)('sha256'); - sha.update(Buffer.from(this.cipherKey, 'utf8')); - return Buffer.from(sha.digest()); - }; - AesCbcCryptor.prototype.encrypt = function (data) { - var iv = this.getIv(); - var key = this.getKey(); - var plainData = typeof data === 'string' ? new TextEncoder().encode(data) : data; - var bPlain = Buffer.from(plainData); + encrypt(data) { + const iv = this.getIv(); + const key = this.getKey(); + const plainData = typeof data === 'string' ? AesCbcCryptor.encoder.encode(data) : data; + const bPlain = Buffer.from(plainData); if (bPlain.byteLength === 0) - throw new Error('encryption error. empty content'); - var aes = (0, crypto_1.createCipheriv)(this.algo, key, iv); + throw new Error('Encryption error: empty content'); + const aes = (0, crypto_1.createCipheriv)(this.algo, key, iv); return { metadata: iv, data: Buffer.concat([aes.update(bPlain), aes.final()]), }; - }; - AesCbcCryptor.prototype.decrypt = function (encryptedData) { - var data = typeof encryptedData.data === 'string' ? new TextEncoder().encode(encryptedData.data) : encryptedData.data; - if (data.byteLength <= 0) - throw new Error('decryption error: empty content'); - var aes = (0, crypto_1.createDecipheriv)(this.algo, this.getKey(), encryptedData.metadata); - return Uint8Array.from(Buffer.concat([aes.update(data), aes.final()])).buffer; - }; - AesCbcCryptor.prototype.encryptStream = function (stream) { - return __awaiter(this, void 0, void 0, function () { - var output, bIv, aes; - return __generator(this, function (_a) { - output = new stream_1.PassThrough(); - bIv = this.getIv(); - if (stream.readable === false) - throw new Error('encryption error. empty stream'); - aes = (0, crypto_1.createCipheriv)(this.algo, this.getKey(), bIv); - stream.pipe(aes).pipe(output); - return [2 /*return*/, { - stream: output, - metadata: bIv, - metadataLength: AesCbcCryptor.BLOCK_SIZE, - }]; - }); + } + encryptStream(stream) { + return __awaiter(this, void 0, void 0, function* () { + if (!stream.readable) + throw new Error('Encryption error: empty stream'); + const output = new stream_1.PassThrough(); + const bIv = this.getIv(); + const aes = (0, crypto_1.createCipheriv)(this.algo, this.getKey(), bIv); + stream.pipe(aes).pipe(output); + return { + stream: output, + metadata: bIv, + metadataLength: AesCbcCryptor.BLOCK_SIZE, + }; }); - }; - AesCbcCryptor.prototype.decryptStream = function (encryptedStream) { - return __awaiter(this, void 0, void 0, function () { - var decryptedStream, bIv, aes, onReadable; - var _this = this; - return __generator(this, function (_a) { - decryptedStream = new stream_1.PassThrough(); - bIv = Buffer.alloc(0); - aes = null; - onReadable = function () { - var data = encryptedStream.stream.read(); - while (data !== null) { - if (data) { - var bChunk = Buffer.from(data); - var sliceLen = encryptedStream.metadataLength - bIv.byteLength; - if (bChunk.byteLength < sliceLen) { - bIv = Buffer.concat([bIv, bChunk]); - } - else { - bIv = Buffer.concat([bIv, bChunk.slice(0, sliceLen)]); - aes = (0, crypto_1.createDecipheriv)(_this.algo, _this.getKey(), bIv); - aes.pipe(decryptedStream); - aes.write(bChunk.slice(sliceLen)); - } + } + decrypt(input) { + const data = typeof input.data === 'string' ? new TextEncoder().encode(input.data) : input.data; + if (data.byteLength <= 0) + throw new Error('Decryption error: empty content'); + const aes = (0, crypto_1.createDecipheriv)(this.algo, this.getKey(), input.metadata); + const decryptedDataBuffer = Buffer.concat([aes.update(data), aes.final()]); + return decryptedDataBuffer.buffer.slice(decryptedDataBuffer.byteOffset, decryptedDataBuffer.byteOffset + decryptedDataBuffer.length); + } + decryptStream(stream) { + return __awaiter(this, void 0, void 0, function* () { + const decryptedStream = new stream_1.PassThrough(); + let bIv = Buffer.alloc(0); + let aes = null; + const onReadable = () => { + let data = stream.stream.read(); + while (data !== null) { + if (data) { + const bChunk = Buffer.from(data); + const sliceLen = stream.metadataLength - bIv.byteLength; + if (bChunk.byteLength < sliceLen) { + bIv = Buffer.concat([bIv, bChunk]); + } + else { + bIv = Buffer.concat([bIv, bChunk.slice(0, sliceLen)]); + aes = (0, crypto_1.createDecipheriv)(this.algo, this.getKey(), bIv); + aes.pipe(decryptedStream); + aes.write(bChunk.slice(sliceLen)); } - data = encryptedStream.stream.read(); - } - }; - encryptedStream.stream.on('readable', onReadable); - encryptedStream.stream.on('end', function () { - if (aes) { - aes.end(); } - decryptedStream.end(); - }); - return [2 /*return*/, decryptedStream]; + data = stream.stream.read(); + } + }; + stream.stream.on('readable', onReadable); + stream.stream.on('end', () => { + if (aes) + aes.end(); + decryptedStream.end(); }); + return decryptedStream; }); - }; - AesCbcCryptor.BLOCK_SIZE = 16; - return AesCbcCryptor; -}()); + } + get identifier() { + return 'ACRH'; + } + get algo() { + return 'aes-256-cbc'; + } + getIv() { + return (0, crypto_1.randomBytes)(AesCbcCryptor.BLOCK_SIZE); + } + getKey() { + const sha = (0, crypto_1.createHash)('sha256'); + sha.update(Buffer.from(this.cipherKey, 'utf8')); + return Buffer.from(sha.digest()); + } +} +AesCbcCryptor.BLOCK_SIZE = 16; +AesCbcCryptor.encoder = new TextEncoder(); exports.default = AesCbcCryptor; diff --git a/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js b/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js index 21273869f..e1c348040 100644 --- a/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js +++ b/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js @@ -8,79 +8,48 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var index_1 = __importDefault(require("../../../core/components/cryptography/index")); -var base64_codec_1 = require("../../../core/components/base64_codec"); -var node_1 = __importDefault(require("../node")); -var LegacyCryptor = /** @class */ (function () { - function LegacyCryptor(config) { +const index_1 = __importDefault(require("../../../core/components/cryptography/index")); +const base64_codec_1 = require("../../../core/components/base64_codec"); +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const node_1 = __importDefault(require("../node")); +class LegacyCryptor { + constructor(config) { this.config = config; - this.cryptor = new index_1.default({ config: config }); + this.cryptor = new index_1.default(Object.assign({}, config)); this.fileCryptor = new node_1.default(); } - Object.defineProperty(LegacyCryptor.prototype, "identifier", { - get: function () { - return ''; - }, - enumerable: false, - configurable: true - }); - LegacyCryptor.prototype.encrypt = function (data) { + encrypt(data) { if (data.length === 0) - throw new Error('encryption error. empty content'); + throw new Error('Encryption error: empty content'); return { data: this.cryptor.encrypt(data), metadata: null, }; - }; - LegacyCryptor.prototype.decrypt = function (encryptedData) { - var data = typeof encryptedData.data === 'string' ? encryptedData.data : (0, base64_codec_1.encode)(encryptedData.data); - return this.cryptor.decrypt(data); - }; - LegacyCryptor.prototype.encryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, this.fileCryptor.encryptFile(this.config.cipherKey, file, File)]; - }); + } + encryptFile(file, File) { + return __awaiter(this, void 0, void 0, function* () { + if (!this.config.cipherKey) + throw new pubnub_error_1.PubNubError('File encryption error: cipher key not set.'); + return this.fileCryptor.encryptFile(this.config.cipherKey, file, File); }); - }; - LegacyCryptor.prototype.decryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, this.fileCryptor.decryptFile(this.config.cipherKey, file, File)]; - }); + } + decrypt(encryptedData) { + const data = typeof encryptedData.data === 'string' ? encryptedData.data : (0, base64_codec_1.encode)(encryptedData.data); + return this.cryptor.decrypt(data); + } + decryptFile(file, File) { + return __awaiter(this, void 0, void 0, function* () { + if (!this.config.cipherKey) + throw new pubnub_error_1.PubNubError('File decryption error: cipher key not set.'); + return this.fileCryptor.decryptFile(this.config.cipherKey, file, File); }); - }; - return LegacyCryptor; -}()); + } + get identifier() { + return ''; + } +} exports.default = LegacyCryptor; diff --git a/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js b/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js index fdaef2d94..bebd0de80 100644 --- a/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js +++ b/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js @@ -8,439 +8,323 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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 __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.CryptoModule = exports.AesCbcCryptor = exports.LegacyCryptor = void 0; -var stream_1 = require("stream"); -var base64_codec_1 = require("../../../core/components/base64_codec"); -var legacyCryptor_1 = __importDefault(require("./legacyCryptor")); -exports.LegacyCryptor = legacyCryptor_1.default; -var aesCbcCryptor_1 = __importDefault(require("./aesCbcCryptor")); +const stream_1 = require("stream"); +const buffer_1 = require("buffer"); +const crypto_module_1 = require("../../../core/interfaces/crypto-module"); +const base64_codec_1 = require("../../../core/components/base64_codec"); +const pubnub_error_1 = require("../../../errors/pubnub-error"); +const aesCbcCryptor_1 = __importDefault(require("./aesCbcCryptor")); exports.AesCbcCryptor = aesCbcCryptor_1.default; -var CryptoModule = /** @class */ (function () { - function CryptoModule(cryptoModuleConfiguration) { - var _a; - this.defaultCryptor = cryptoModuleConfiguration.default; - this.cryptors = (_a = cryptoModuleConfiguration.cryptors) !== null && _a !== void 0 ? _a : []; - } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore: type detection issue with old Config type assignment - CryptoModule.legacyCryptoModule = function (config) { +const legacyCryptor_1 = __importDefault(require("./legacyCryptor")); +exports.LegacyCryptor = legacyCryptor_1.default; +class CryptoModule extends crypto_module_1.AbstractCryptoModule { + static legacyCryptoModule(config) { var _a; + if (!config.cipherKey) + throw new pubnub_error_1.PubNubError('Crypto module error: cipher key not set.'); return new this({ - default: new legacyCryptor_1.default({ - cipherKey: config.cipherKey, - useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true, - }), + default: new legacyCryptor_1.default(Object.assign(Object.assign({}, config), { useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true })), cryptors: [new aesCbcCryptor_1.default({ cipherKey: config.cipherKey })], }); - }; - CryptoModule.aesCbcCryptoModule = function (config) { + } + static aesCbcCryptoModule(config) { var _a; + if (!config.cipherKey) + throw new pubnub_error_1.PubNubError('Crypto module error: cipher key not set.'); return new this({ default: new aesCbcCryptor_1.default({ cipherKey: config.cipherKey }), cryptors: [ - new legacyCryptor_1.default({ - cipherKey: config.cipherKey, - useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true, - }), + new legacyCryptor_1.default(Object.assign(Object.assign({}, config), { useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true })), ], }); - }; - CryptoModule.withDefaultCryptor = function (defaultCryptor) { + } + static withDefaultCryptor(defaultCryptor) { return new this({ default: defaultCryptor }); - }; - CryptoModule.prototype.getAllCryptors = function () { - return __spreadArray([this.defaultCryptor], __read(this.cryptors), false); - }; - CryptoModule.prototype.getLegacyCryptor = function () { - return this.getAllCryptors().find(function (c) { return c.identifier === ''; }); - }; - CryptoModule.prototype.encrypt = function (data) { - var encrypted = this.defaultCryptor.encrypt(data); + } + encrypt(data) { + const encrypted = data instanceof ArrayBuffer && this.defaultCryptor.identifier === CryptoModule.LEGACY_IDENTIFIER + ? this.defaultCryptor.encrypt(CryptoModule.decoder.decode(data)) + : this.defaultCryptor.encrypt(data); if (!encrypted.metadata) return encrypted.data; - var header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); - var headerData = new Uint8Array(header.length); - var pos = 0; - headerData.set(header.data, pos); - pos = header.length - encrypted.metadata.length; - headerData.set(encrypted.metadata, pos); - return Buffer.concat([headerData, Buffer.from(encrypted.data)]); - }; - CryptoModule.prototype.decrypt = function (data) { - var encryptedData = Buffer.from(typeof data === 'string' ? (0, base64_codec_1.decode)(data) : data); - var header = CryptorHeader.tryParse(encryptedData); - var cryptor = this.getCryptor(header); - var metadata = header.length > 0 + const headerData = this.getHeaderData(encrypted); + const encryptedData = typeof encrypted.data === 'string' + ? CryptoModule.encoder.encode(encrypted.data).buffer + : encrypted.data.buffer.slice(encrypted.data.byteOffset, encrypted.data.byteOffset + encrypted.data.length); + return this.concatArrayBuffer(headerData, encryptedData); + } + encryptFile(file, File) { + return __awaiter(this, void 0, void 0, function* () { + if (this.defaultCryptor.identifier === CryptorHeader.LEGACY_IDENTIFIER) + return this.defaultCryptor.encryptFile(file, File); + if (file.data instanceof buffer_1.Buffer) { + const encryptedData = this.encrypt(file.data); + return File.create({ + name: file.name, + mimeType: 'application/octet-stream', + data: buffer_1.Buffer.from(typeof encryptedData === 'string' ? CryptoModule.encoder.encode(encryptedData) : encryptedData), + }); + } + if (file.data instanceof stream_1.Readable) { + if (!file.contentLength || file.contentLength === 0) + throw new Error('Encryption error: empty content'); + const encryptedStream = yield this.defaultCryptor.encryptStream(file.data); + const header = CryptorHeader.from(this.defaultCryptor.identifier, encryptedStream.metadata); + const payload = new Uint8Array(header.length); + let pos = 0; + payload.set(header.data, pos); + pos += header.length; + if (encryptedStream.metadata) { + const metadata = new Uint8Array(encryptedStream.metadata); + pos -= encryptedStream.metadata.byteLength; + payload.set(metadata, pos); + } + const output = new stream_1.PassThrough(); + output.write(payload); + encryptedStream.stream.pipe(output); + return File.create({ + name: file.name, + mimeType: 'application/octet-stream', + stream: output, + }); + } + }); + } + decrypt(data) { + const encryptedData = buffer_1.Buffer.from(typeof data === 'string' ? (0, base64_codec_1.decode)(data) : data); + const header = CryptorHeader.tryParse(encryptedData.buffer.slice(encryptedData.byteOffset, encryptedData.byteOffset + encryptedData.length)); + const cryptor = this.getCryptor(header); + const metadata = header.length > 0 ? encryptedData.slice(header.length - header.metadataLength, header.length) : null; if (encryptedData.slice(header.length).byteLength <= 0) - throw new Error('decryption error. empty content'); + throw new Error('Decryption error: empty content'); return cryptor.decrypt({ data: encryptedData.slice(header.length), metadata: metadata, }); - }; - CryptoModule.prototype.encryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - var encryptedStream, header, payload, pos, output; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - /** - * Files handled differently in case of Legacy cryptor. - * (as long as we support legacy need to check on intsance type) - */ - if (this.defaultCryptor.identifier === CryptorHeader.LEGACY_IDENTIFIER) - return [2 /*return*/, this.defaultCryptor.encryptFile(file, File)]; - if (file.data instanceof Buffer) { - return [2 /*return*/, File.create({ - name: file.name, - mimeType: 'application/octet-stream', - data: Buffer.from(this.encrypt(file.data)), - })]; - } - if (!(file.data instanceof stream_1.Readable)) return [3 /*break*/, 2]; - if (file.contentLength === 0) - throw new Error('encryption error. empty content'); - return [4 /*yield*/, this.defaultCryptor.encryptStream(file.data)]; - case 1: - encryptedStream = _a.sent(); - header = CryptorHeader.from(this.defaultCryptor.identifier, encryptedStream.metadata); - payload = new Uint8Array(header.length); - pos = 0; - payload.set(header.data, pos); - pos += header.length; - if (encryptedStream.metadata) { - pos -= encryptedStream.metadata.length; - payload.set(encryptedStream.metadata, pos); - } - output = new stream_1.PassThrough(); - output.write(payload); - encryptedStream.stream.pipe(output); - return [2 /*return*/, File.create({ - name: file.name, - mimeType: 'application/octet-stream', - stream: output, - })]; - case 2: return [2 /*return*/]; - } - }); - }); - }; - CryptoModule.prototype.decryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - var header, cryptor, stream_2; - var _this = this; - return __generator(this, function (_a) { - if ((file === null || file === void 0 ? void 0 : file.data) instanceof Buffer) { - header = CryptorHeader.tryParse(file.data); - cryptor = this.getCryptor(header); - /** - * If It's legacyone then redirect it. - * (as long as we support legacy need to check on instance type) - */ - if ((cryptor === null || cryptor === void 0 ? void 0 : cryptor.identifier) === CryptoModule.LEGACY_IDENTIFIER) - return [2 /*return*/, cryptor.decryptFile(file, File)]; - return [2 /*return*/, File.create({ - name: file.name, - data: Buffer.from(this.decrypt(file === null || file === void 0 ? void 0 : file.data)), - })]; - } - if (file.data instanceof stream_1.Readable) { - stream_2 = file.data; - return [2 /*return*/, new Promise(function (resolve) { - stream_2.on('readable', function () { return resolve(_this.onStreamReadable(stream_2, file, File)); }); - })]; - } - return [2 /*return*/]; - }); - }); - }; - CryptoModule.prototype.onStreamReadable = function (stream, file, File) { - return __awaiter(this, void 0, void 0, function () { - var magicBytes, versionByte, identifier, cryptor, headerSize, _a, _b; - var _c; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: - stream.removeAllListeners('readable'); - magicBytes = stream.read(4); - if (!CryptorHeader.isSentinel(magicBytes)) { - if (magicBytes === null) - throw new Error('decryption error. empty content'); - stream.unshift(magicBytes); - return [2 /*return*/, this.decryptLegacyFileStream(stream, file, File)]; - } - versionByte = stream.read(1); - CryptorHeader.validateVersion(versionByte[0]); - identifier = stream.read(4); - cryptor = this.getCryptorFromId(CryptorHeader.tryGetIdentifier(identifier)); - headerSize = CryptorHeader.tryGetMetadataSizeFromStream(stream); - if (file.contentLength <= CryptorHeader.MIN_HEADER_LEGTH + headerSize) - throw new Error('decryption error. empty content'); - _b = (_a = File).create; - _c = { - name: file.name, - mimeType: 'application/octet-stream' - }; - return [4 /*yield*/, cryptor.decryptStream({ stream: stream, metadataLength: headerSize })]; - case 1: return [2 /*return*/, _b.apply(_a, [(_c.stream = _d.sent(), - _c)])]; - } - }); - }); - }; - CryptoModule.prototype.decryptLegacyFileStream = function (stream, file, File) { - return __awaiter(this, void 0, void 0, function () { - var cryptor; - return __generator(this, function (_a) { - if (file.contentLength <= 16) - throw new Error('decryption error: empty content'); - cryptor = this.getLegacyCryptor(); - if (cryptor) { - return [2 /*return*/, cryptor.decryptFile(File.create({ - name: file.name, - stream: stream, - }), File)]; - } - else { - throw new Error('unknown cryptor error'); - } - return [2 /*return*/]; - }); + } + decryptFile(file, File) { + return __awaiter(this, void 0, void 0, function* () { + if (file.data && file.data instanceof buffer_1.Buffer) { + const header = CryptorHeader.tryParse(file.data.buffer.slice(file.data.byteOffset, file.data.byteOffset + file.data.length)); + const cryptor = this.getCryptor(header); + if ((cryptor === null || cryptor === void 0 ? void 0 : cryptor.identifier) === CryptoModule.LEGACY_IDENTIFIER) + return cryptor.decryptFile(file, File); + return File.create({ + name: file.name, + data: buffer_1.Buffer.from(this.decrypt(file.data)), + }); + } + if (file.data && file.data instanceof stream_1.Readable) { + const stream = file.data; + return new Promise((resolve) => { + stream.on('readable', () => resolve(this.onStreamReadable(stream, file, File))); + }); + } }); - }; - CryptoModule.prototype.getCryptor = function (header) { - if (header === '') { - var cryptor = this.getAllCryptors().find(function (c) { return c.identifier === ''; }); + } + getLegacyCryptor() { + return this.getCryptorFromId(CryptoModule.LEGACY_IDENTIFIER); + } + getCryptorFromId(id) { + const cryptor = this.getAllCryptors().find((cryptor) => id === cryptor.identifier); + if (cryptor) + return cryptor; + throw new Error('Unknown cryptor error'); + } + getCryptor(header) { + if (typeof header === 'string') { + const cryptor = this.getAllCryptors().find((c) => c.identifier === header); if (cryptor) return cryptor; - throw new Error('unknown cryptor error'); + throw new Error('Unknown cryptor error'); } else if (header instanceof CryptorHeaderV1) { return this.getCryptorFromId(header.identifier); } - }; - CryptoModule.prototype.getCryptorFromId = function (id) { - var cryptor = this.getAllCryptors().find(function (c) { return id === c.identifier; }); - if (cryptor) { - return cryptor; - } - throw new Error('unknown cryptor error'); - }; - CryptoModule.LEGACY_IDENTIFIER = ''; - return CryptoModule; -}()); -exports.CryptoModule = CryptoModule; -// CryptorHeader Utility -var CryptorHeader = /** @class */ (function () { - function CryptorHeader() { } - CryptorHeader.from = function (id, metadata) { + getHeaderData(encrypted) { + if (!encrypted.metadata) + return; + const header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); + const headerData = new Uint8Array(header.length); + let pos = 0; + headerData.set(header.data, pos); + pos += header.length - encrypted.metadata.byteLength; + headerData.set(new Uint8Array(encrypted.metadata), pos); + return headerData.buffer; + } + concatArrayBuffer(ab1, ab2) { + const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); + tmp.set(new Uint8Array(ab1), 0); + tmp.set(new Uint8Array(ab2), ab1.byteLength); + return tmp.buffer; + } + onStreamReadable(stream, file, File) { + return __awaiter(this, void 0, void 0, function* () { + stream.removeAllListeners('readable'); + const magicBytes = stream.read(4); + if (!CryptorHeader.isSentinel(magicBytes)) { + if (magicBytes === null) + throw new Error('Decryption error: empty content'); + stream.unshift(magicBytes); + return this.decryptLegacyFileStream(stream, file, File); + } + const versionByte = stream.read(1); + CryptorHeader.validateVersion(versionByte[0]); + const identifier = stream.read(4); + const cryptor = this.getCryptorFromId(CryptorHeader.tryGetIdentifier(identifier)); + const headerSize = CryptorHeader.tryGetMetadataSizeFromStream(stream); + if (!file.contentLength || file.contentLength <= CryptorHeader.MIN_HEADER_LENGTH + headerSize) + throw new Error('Decryption error: empty content'); + return File.create({ + name: file.name, + mimeType: 'application/octet-stream', + stream: (yield cryptor.decryptStream({ + stream: stream, + metadataLength: headerSize, + })), + }); + }); + } + decryptLegacyFileStream(stream, file, File) { + return __awaiter(this, void 0, void 0, function* () { + if (!file.contentLength || file.contentLength <= 16) + throw new Error('Decryption error: empty content'); + const cryptor = this.getLegacyCryptor(); + if (cryptor) { + return cryptor.decryptFile(File.create({ + name: file.name, + stream: stream, + }), File); + } + else + throw new Error('unknown cryptor error'); + }); + } +} +exports.CryptoModule = CryptoModule; +CryptoModule.LEGACY_IDENTIFIER = ''; +class CryptorHeader { + static from(id, metadata) { if (id === CryptorHeader.LEGACY_IDENTIFIER) return; - return new CryptorHeaderV1(id, metadata.length); - }; - CryptorHeader.isSentinel = function (bytes) { - if (bytes && bytes.byteLength >= 4) { - if (bytes.toString('utf8') == CryptorHeader.SENTINEL) - return true; - } - }; - CryptorHeader.validateVersion = function (data) { + return new CryptorHeaderV1(id, metadata.byteLength); + } + static isSentinel(bytes) { + return bytes && bytes.byteLength >= 4 && CryptorHeader.decoder.decode(bytes) == CryptorHeader.SENTINEL; + } + static validateVersion(data) { if (data && data > CryptorHeader.MAX_VERSION) - throw new Error('decryption error. invalid header version'); + throw new Error('Decryption error: invalid header version'); return data; - }; - CryptorHeader.tryGetIdentifier = function (data) { - if (data.byteLength < 4) { - throw new Error('unknown cryptor error. decryption failed'); - } - else { - return data.toString('utf8'); - } - }; - CryptorHeader.tryGetMetadataSizeFromStream = function (stream) { - var sizeBuf = stream.read(1); - if (sizeBuf && sizeBuf[0] < 255) { + } + static tryGetIdentifier(data) { + if (data.byteLength < 4) + throw new Error('Decryption error: unknown cryptor error'); + else + return CryptorHeader.decoder.decode(data); + } + static tryGetMetadataSizeFromStream(stream) { + const sizeBuf = stream.read(1); + if (sizeBuf && sizeBuf[0] < 255) return sizeBuf[0]; - } if (sizeBuf[0] === 255) { - var nextBuf = stream.read(2); + const nextBuf = stream.read(2); if (nextBuf.length >= 2) { - return new Uint16Array([nextBuf[0], nextBuf[1]]).reduce(function (acc, val) { return (acc << 8) + val; }, 0); + return new Uint16Array([nextBuf[0], nextBuf[1]]).reduce((acc, val) => (acc << 8) + val, 0); } } - throw new Error('decryption error. Invalid metadata size'); - }; - CryptorHeader.tryParse = function (encryptedData) { - var sentinel = ''; - var version = null; - if (encryptedData.length >= 4) { + throw new Error('Decryption error: invalid metadata size'); + } + static tryParse(encryptedData) { + const encryptedDataView = new DataView(encryptedData); + let sentinel; + let version = null; + if (encryptedData.byteLength >= 4) { sentinel = encryptedData.slice(0, 4); - if (sentinel.toString('utf8') !== CryptorHeader.SENTINEL) - return ''; - } - if (encryptedData.length >= 5) { - version = encryptedData[4]; - } - else { - throw new Error('decryption error. invalid header version'); + if (!this.isSentinel(sentinel)) + return CryptoModule.LEGACY_IDENTIFIER; } + if (encryptedData.byteLength >= 5) + version = encryptedDataView.getInt8(4); + else + throw new Error('Decryption error: invalid header version'); if (version > CryptorHeader.MAX_VERSION) throw new Error('unknown cryptor error'); - var identifier; - var pos = 5 + CryptorHeader.IDENTIFIER_LENGTH; - if (encryptedData.length >= pos) { + let identifier; + let pos = 5 + CryptorHeader.IDENTIFIER_LENGTH; + if (encryptedData.byteLength >= pos) identifier = encryptedData.slice(5, pos); - } - else { - throw new Error('decryption error. invalid crypto identifier'); - } - var metadataLength = null; - if (encryptedData.length >= pos + 1) { - metadataLength = encryptedData[pos]; - } - else { - throw new Error('decryption error. invalid metadata length'); - } + else + throw new Error('Decryption error: invalid crypto identifier'); + let metadataLength = null; + if (encryptedData.byteLength >= pos + 1) + metadataLength = encryptedDataView.getInt8(pos); + else + throw new Error('Decryption error: invalid metadata length'); pos += 1; - if (metadataLength === 255 && encryptedData.length >= pos + 2) { - metadataLength = new Uint16Array(encryptedData.slice(pos, pos + 2)).reduce(function (acc, val) { return (acc << 8) + val; }, 0); - pos += 2; + if (metadataLength === 255 && encryptedData.byteLength >= pos + 2) { + metadataLength = new Uint16Array(encryptedData.slice(pos, pos + 2)).reduce((acc, val) => (acc << 8) + val, 0); } - return new CryptorHeaderV1(identifier.toString('utf8'), metadataLength); - }; - CryptorHeader.SENTINEL = 'PNED'; - CryptorHeader.LEGACY_IDENTIFIER = ''; - CryptorHeader.IDENTIFIER_LENGTH = 4; - CryptorHeader.VERSION = 1; - CryptorHeader.MAX_VERSION = 1; - CryptorHeader.MIN_HEADER_LEGTH = 10; - return CryptorHeader; -}()); -// v1 CryptorHeader -var CryptorHeaderV1 = /** @class */ (function () { - function CryptorHeaderV1(id, metadataLength) { + return new CryptorHeaderV1(CryptorHeader.decoder.decode(identifier), metadataLength); + } +} +CryptorHeader.decoder = new TextDecoder(); +CryptorHeader.SENTINEL = 'PNED'; +CryptorHeader.LEGACY_IDENTIFIER = ''; +CryptorHeader.IDENTIFIER_LENGTH = 4; +CryptorHeader.VERSION = 1; +CryptorHeader.MAX_VERSION = 1; +CryptorHeader.MIN_HEADER_LENGTH = 10; +class CryptorHeaderV1 { + constructor(id, metadataLength) { this._identifier = id; this._metadataLength = metadataLength; } - Object.defineProperty(CryptorHeaderV1.prototype, "identifier", { - get: function () { - return this._identifier; - }, - set: function (value) { - this._identifier = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "metadataLength", { - get: function () { - return this._metadataLength; - }, - set: function (value) { - this._metadataLength = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "version", { - get: function () { - return CryptorHeader.VERSION; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "length", { - get: function () { - return (CryptorHeader.SENTINEL.length + - 1 + - CryptorHeader.IDENTIFIER_LENGTH + - (this.metadataLength < 255 ? 1 : 3) + - this.metadataLength); - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "data", { - get: function () { - var pos = 0; - var header = new Uint8Array(this.length); - header.set(Buffer.from(CryptorHeader.SENTINEL)); - pos += CryptorHeader.SENTINEL.length; - header[pos] = this.version; - pos++; - if (this.identifier) - header.set(Buffer.from(this.identifier), pos); - pos += CryptorHeader.IDENTIFIER_LENGTH; - var metadataLength = this.metadataLength; - if (metadataLength < 255) { - header[pos] = metadataLength; - } - else { - header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); - } - return header; - }, - enumerable: false, - configurable: true - }); - return CryptorHeaderV1; -}()); + get identifier() { + return this._identifier; + } + set identifier(value) { + this._identifier = value; + } + get metadataLength() { + return this._metadataLength; + } + set metadataLength(value) { + this._metadataLength = value; + } + get version() { + return CryptorHeader.VERSION; + } + get length() { + return (CryptorHeader.SENTINEL.length + + 1 + + CryptorHeader.IDENTIFIER_LENGTH + + (this.metadataLength < 255 ? 1 : 3) + + this.metadataLength); + } + get data() { + let pos = 0; + const header = new Uint8Array(this.length); + header.set(buffer_1.Buffer.from(CryptorHeader.SENTINEL)); + pos += CryptorHeader.SENTINEL.length; + header[pos] = this.version; + pos++; + if (this.identifier) + header.set(buffer_1.Buffer.from(this.identifier), pos); + const metadataLength = this.metadataLength; + pos += CryptorHeader.IDENTIFIER_LENGTH; + if (metadataLength < 255) + header[pos] = metadataLength; + else + header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); + return header; + } +} diff --git a/lib/crypto/modules/WebCryptoModule/aesCbcCryptor.js b/lib/crypto/modules/WebCryptoModule/aesCbcCryptor.js deleted file mode 100644 index d80cbbb15..000000000 --- a/lib/crypto/modules/WebCryptoModule/aesCbcCryptor.js +++ /dev/null @@ -1,148 +0,0 @@ -"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 (_) 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) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var hmac_sha256_1 = __importDefault(require("../../../core/components/cryptography/hmac-sha256")); -var base64_codec_1 = require("../../../core/components/base64_codec"); -var AesCbcCryptor = /** @class */ (function () { - function AesCbcCryptor(configuration) { - this.cipherKey = configuration.cipherKey; - this.CryptoJS = hmac_sha256_1.default; - this.encryptedKey = this.CryptoJS.SHA256(this.cipherKey); - } - Object.defineProperty(AesCbcCryptor.prototype, "algo", { - get: function () { - return 'AES-CBC'; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(AesCbcCryptor.prototype, "identifier", { - get: function () { - return 'ACRH'; - }, - enumerable: false, - configurable: true - }); - AesCbcCryptor.prototype.getIv = function () { - return crypto.getRandomValues(new Uint8Array(AesCbcCryptor.BLOCK_SIZE)); - }; - AesCbcCryptor.prototype.getKey = function () { - return __awaiter(this, void 0, void 0, function () { - var bKey, abHash; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - bKey = AesCbcCryptor.encoder.encode(this.cipherKey); - return [4 /*yield*/, crypto.subtle.digest('SHA-256', bKey.buffer)]; - case 1: - abHash = _a.sent(); - return [2 /*return*/, crypto.subtle.importKey('raw', abHash, this.algo, true, ['encrypt', 'decrypt'])]; - } - }); - }); - }; - AesCbcCryptor.prototype.encrypt = function (data) { - var stringData = typeof data === 'string' ? data : AesCbcCryptor.decoder.decode(data); - if (stringData.length === 0) - throw new Error('encryption error. empty content'); - var abIv = this.getIv(); - return { - metadata: abIv, - data: (0, base64_codec_1.decode)(this.CryptoJS.AES.encrypt(data, this.encryptedKey, { - iv: this.bufferToWordArray(abIv), - mode: this.CryptoJS.mode.CBC, - }).ciphertext.toString(this.CryptoJS.enc.Base64)), - }; - }; - AesCbcCryptor.prototype.decrypt = function (encryptedData) { - var iv = this.bufferToWordArray(new Uint8ClampedArray(encryptedData.metadata)); - var data = this.bufferToWordArray(new Uint8ClampedArray(encryptedData.data)); - return AesCbcCryptor.encoder.encode(this.CryptoJS.AES.decrypt({ ciphertext: data }, this.encryptedKey, { - iv: iv, - mode: this.CryptoJS.mode.CBC, - }).toString(this.CryptoJS.enc.Utf8)).buffer; - }; - AesCbcCryptor.prototype.encryptFileData = function (data) { - return __awaiter(this, void 0, void 0, function () { - var key, iv; - var _a; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: return [4 /*yield*/, this.getKey()]; - case 1: - key = _b.sent(); - iv = this.getIv(); - _a = {}; - return [4 /*yield*/, crypto.subtle.encrypt({ name: this.algo, iv: iv }, key, data)]; - case 2: return [2 /*return*/, (_a.data = _b.sent(), - _a.metadata = iv, - _a)]; - } - }); - }); - }; - AesCbcCryptor.prototype.decryptFileData = function (encryptedData) { - return __awaiter(this, void 0, void 0, function () { - var key; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.getKey()]; - case 1: - key = _a.sent(); - return [2 /*return*/, crypto.subtle.decrypt({ name: this.algo, iv: encryptedData.metadata }, key, encryptedData.data)]; - } - }); - }); - }; - AesCbcCryptor.prototype.bufferToWordArray = function (b) { - var wa = []; - var i; - for (i = 0; i < b.length; i += 1) { - wa[(i / 4) | 0] |= b[i] << (24 - 8 * i); - } - return this.CryptoJS.lib.WordArray.create(wa, b.length); - }; - AesCbcCryptor.BLOCK_SIZE = 16; - AesCbcCryptor.encoder = new TextEncoder(); - AesCbcCryptor.decoder = new TextDecoder(); - return AesCbcCryptor; -}()); -exports.default = AesCbcCryptor; diff --git a/lib/crypto/modules/WebCryptoModule/legacyCryptor.js b/lib/crypto/modules/WebCryptoModule/legacyCryptor.js deleted file mode 100644 index 9b318e359..000000000 --- a/lib/crypto/modules/WebCryptoModule/legacyCryptor.js +++ /dev/null @@ -1,90 +0,0 @@ -"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 (_) 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) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var index_1 = __importDefault(require("../../../core/components/cryptography/index")); -var web_1 = __importDefault(require("../web")); -var base64_codec_1 = require("../../../core/components/base64_codec"); -var LegacyCryptor = /** @class */ (function () { - function LegacyCryptor(config) { - this.config = config; - this.cryptor = new index_1.default({ config: config }); - this.fileCryptor = new web_1.default(); - } - Object.defineProperty(LegacyCryptor.prototype, "identifier", { - get: function () { - return ''; - }, - enumerable: false, - configurable: true - }); - LegacyCryptor.prototype.encrypt = function (data) { - var stringData = typeof data === 'string' ? data : new TextDecoder().decode(data); - return { - data: this.cryptor.encrypt(stringData), - metadata: null, - }; - }; - LegacyCryptor.prototype.decrypt = function (encryptedData) { - var data = typeof encryptedData.data === 'string' ? encryptedData.data : (0, base64_codec_1.encode)(encryptedData.data); - return this.cryptor.decrypt(data); - }; - LegacyCryptor.prototype.encryptFile = function (file, File) { - var _a; - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_b) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore: can not detect cipherKey from old Config - return [2 /*return*/, this.fileCryptor.encryptFile((_a = this.config) === null || _a === void 0 ? void 0 : _a.cipherKey, file, File)]; - }); - }); - }; - LegacyCryptor.prototype.decryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore: can not detect cipherKey from old Config - return [2 /*return*/, this.fileCryptor.decryptFile(this.config.cipherKey, file, File)]; - }); - }); - }; - return LegacyCryptor; -}()); -exports.default = LegacyCryptor; diff --git a/lib/crypto/modules/WebCryptoModule/webCryptoModule.js b/lib/crypto/modules/WebCryptoModule/webCryptoModule.js deleted file mode 100644 index f4c7ccabf..000000000 --- a/lib/crypto/modules/WebCryptoModule/webCryptoModule.js +++ /dev/null @@ -1,376 +0,0 @@ -"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 (_) 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 __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.CryptoModule = exports.AesCbcCryptor = exports.LegacyCryptor = void 0; -var legacyCryptor_1 = __importDefault(require("./legacyCryptor")); -exports.LegacyCryptor = legacyCryptor_1.default; -var aesCbcCryptor_1 = __importDefault(require("./aesCbcCryptor")); -exports.AesCbcCryptor = aesCbcCryptor_1.default; -var base64_codec_1 = require("../../../core/components/base64_codec"); -var CryptoModule = /** @class */ (function () { - function CryptoModule(cryptoModuleConfiguration) { - var _a; - this.defaultCryptor = cryptoModuleConfiguration.default; - this.cryptors = (_a = cryptoModuleConfiguration.cryptors) !== null && _a !== void 0 ? _a : []; - } - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore: type detection issue with old Config type assignment - CryptoModule.legacyCryptoModule = function (config) { - var _a; - return new this({ - default: new legacyCryptor_1.default({ - cipherKey: config.cipherKey, - useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true, - }), - cryptors: [new aesCbcCryptor_1.default({ cipherKey: config.cipherKey })], - }); - }; - CryptoModule.aesCbcCryptoModule = function (config) { - var _a; - return new this({ - default: new aesCbcCryptor_1.default({ cipherKey: config.cipherKey }), - cryptors: [ - new legacyCryptor_1.default({ - cipherKey: config.cipherKey, - useRandomIVs: (_a = config.useRandomIVs) !== null && _a !== void 0 ? _a : true, - }), - ], - }); - }; - CryptoModule.withDefaultCryptor = function (defaultCryptor) { - return new this({ default: defaultCryptor }); - }; - CryptoModule.prototype.getAllCryptors = function () { - return __spreadArray([this.defaultCryptor], __read(this.cryptors), false); - }; - CryptoModule.prototype.encrypt = function (data) { - var encrypted = this.defaultCryptor.encrypt(data); - if (!encrypted.metadata) - return encrypted.data; - var headerData = this.getHeaderData(encrypted); - return this.concatArrayBuffer(headerData, encrypted.data); - }; - CryptoModule.prototype.decrypt = function (data) { - var encryptedData = typeof data === 'string' ? (0, base64_codec_1.decode)(data) : data; - var header = CryptorHeader.tryParse(encryptedData); - var cryptor = this.getCryptor(header); - var metadata = header.length > 0 - ? encryptedData.slice(header.length - header.metadataLength, header.length) - : null; - if (encryptedData.slice(header.length).byteLength <= 0) - throw new Error('decryption error. empty content'); - return cryptor.decrypt({ - data: encryptedData.slice(header.length), - metadata: metadata, - }); - }; - CryptoModule.prototype.encryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - var fileData, encrypted; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (this.defaultCryptor.identifier === CryptorHeader.LEGACY_IDENTIFIER) - return [2 /*return*/, this.defaultCryptor.encryptFile(file, File)]; - return [4 /*yield*/, this.getFileData(file.data)]; - case 1: - fileData = _a.sent(); - return [4 /*yield*/, this.defaultCryptor.encryptFileData(fileData)]; - case 2: - encrypted = _a.sent(); - return [2 /*return*/, File.create({ - name: file.name, - mimeType: 'application/octet-stream', - data: this.concatArrayBuffer(this.getHeaderData(encrypted), encrypted.data), - })]; - } - }); - }); - }; - CryptoModule.prototype.decryptFile = function (file, File) { - return __awaiter(this, void 0, void 0, function () { - var data, header, cryptor, fileData, metadata, _a, _b; - var _c; - return __generator(this, function (_d) { - switch (_d.label) { - case 0: return [4 /*yield*/, file.data.arrayBuffer()]; - case 1: - data = _d.sent(); - header = CryptorHeader.tryParse(data); - cryptor = this.getCryptor(header); - if ((cryptor === null || cryptor === void 0 ? void 0 : cryptor.identifier) === CryptoModule.LEGACY_IDENTIFIER) { - return [2 /*return*/, cryptor.decryptFile(file, File)]; - } - return [4 /*yield*/, this.getFileData(data)]; - case 2: - fileData = _d.sent(); - metadata = fileData.slice(header.length - header.metadataLength, header.length); - _b = (_a = File).create; - _c = { - name: file.name - }; - return [4 /*yield*/, this.defaultCryptor.decryptFileData({ - data: data.slice(header.length), - metadata: metadata, - })]; - case 3: return [2 /*return*/, _b.apply(_a, [(_c.data = _d.sent(), - _c)])]; - } - }); - }); - }; - CryptoModule.prototype.getCryptor = function (header) { - if (header === '') { - var cryptor = this.getAllCryptors().find(function (c) { return c.identifier === ''; }); - if (cryptor) - return cryptor; - throw new Error('unknown cryptor error'); - } - else if (header instanceof CryptorHeaderV1) { - return this.getCryptorFromId(header.identifier); - } - }; - CryptoModule.prototype.getCryptorFromId = function (id) { - var cryptor = this.getAllCryptors().find(function (c) { return id === c.identifier; }); - if (cryptor) { - return cryptor; - } - throw Error('unknown cryptor error'); - }; - CryptoModule.prototype.concatArrayBuffer = function (ab1, ab2) { - var tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); - tmp.set(new Uint8Array(ab1), 0); - tmp.set(new Uint8Array(ab2), ab1.byteLength); - return tmp.buffer; - }; - CryptoModule.prototype.getHeaderData = function (encrypted) { - if (!encrypted.metadata) - return; - var header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); - var headerData = new Uint8Array(header.length); - var pos = 0; - headerData.set(header.data, pos); - pos += header.length - encrypted.metadata.byteLength; - headerData.set(new Uint8Array(encrypted.metadata), pos); - return headerData.buffer; - }; - CryptoModule.prototype.getFileData = function (input) { - return __awaiter(this, void 0, void 0, function () { - var fileData; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(input instanceof Blob)) return [3 /*break*/, 2]; - return [4 /*yield*/, input.arrayBuffer()]; - case 1: - fileData = _a.sent(); - return [2 /*return*/, fileData]; - case 2: - if (input instanceof ArrayBuffer) { - return [2 /*return*/, input]; - } - if (typeof input === 'string') { - return [2 /*return*/, CryptoModule.encoder.encode(input)]; - } - throw new Error('Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob'); - } - }); - }); - }; - CryptoModule.LEGACY_IDENTIFIER = ''; - CryptoModule.encoder = new TextEncoder(); - CryptoModule.decoder = new TextDecoder(); - return CryptoModule; -}()); -exports.CryptoModule = CryptoModule; -// CryptorHeader Utility -var CryptorHeader = /** @class */ (function () { - function CryptorHeader() { - } - CryptorHeader.from = function (id, metadata) { - if (id === CryptorHeader.LEGACY_IDENTIFIER) - return; - return new CryptorHeaderV1(id, metadata.byteLength); - }; - CryptorHeader.tryParse = function (data) { - var encryptedData = new Uint8Array(data); - var sentinel = ''; - var version = null; - if (encryptedData.byteLength >= 4) { - sentinel = encryptedData.slice(0, 4); - if (this.decoder.decode(sentinel) !== CryptorHeader.SENTINEL) - return ''; - } - if (encryptedData.byteLength >= 5) { - version = encryptedData[4]; - } - else { - throw new Error('decryption error. invalid header version'); - } - if (version > CryptorHeader.MAX_VERSION) - throw new Error('unknown cryptor error'); - var identifier = ''; - var pos = 5 + CryptorHeader.IDENTIFIER_LENGTH; - if (encryptedData.byteLength >= pos) { - identifier = encryptedData.slice(5, pos); - } - else { - throw new Error('decryption error. invalid crypto identifier'); - } - var metadataLength = null; - if (encryptedData.byteLength >= pos + 1) { - metadataLength = encryptedData[pos]; - } - else { - throw new Error('decryption error. invalid metadata length'); - } - pos += 1; - if (metadataLength === 255 && encryptedData.byteLength >= pos + 2) { - metadataLength = new Uint16Array(encryptedData.slice(pos, pos + 2)).reduce(function (acc, val) { return (acc << 8) + val; }, 0); - pos += 2; - } - return new CryptorHeaderV1(this.decoder.decode(identifier), metadataLength); - }; - CryptorHeader.SENTINEL = 'PNED'; - CryptorHeader.LEGACY_IDENTIFIER = ''; - CryptorHeader.IDENTIFIER_LENGTH = 4; - CryptorHeader.VERSION = 1; - CryptorHeader.MAX_VERSION = 1; - CryptorHeader.decoder = new TextDecoder(); - return CryptorHeader; -}()); -// v1 CryptorHeader -var CryptorHeaderV1 = /** @class */ (function () { - function CryptorHeaderV1(id, metadataLength) { - this._identifier = id; - this._metadataLength = metadataLength; - } - Object.defineProperty(CryptorHeaderV1.prototype, "identifier", { - get: function () { - return this._identifier; - }, - set: function (value) { - this._identifier = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "metadataLength", { - get: function () { - return this._metadataLength; - }, - set: function (value) { - this._metadataLength = value; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "version", { - get: function () { - return CryptorHeader.VERSION; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "length", { - get: function () { - return (CryptorHeader.SENTINEL.length + - 1 + - CryptorHeader.IDENTIFIER_LENGTH + - (this.metadataLength < 255 ? 1 : 3) + - this.metadataLength); - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(CryptorHeaderV1.prototype, "data", { - get: function () { - var pos = 0; - var header = new Uint8Array(this.length); - var encoder = new TextEncoder(); - header.set(encoder.encode(CryptorHeader.SENTINEL)); - pos += CryptorHeader.SENTINEL.length; - header[pos] = this.version; - pos++; - if (this.identifier) - header.set(encoder.encode(this.identifier), pos); - pos += CryptorHeader.IDENTIFIER_LENGTH; - var metadataLength = this.metadataLength; - if (metadataLength < 255) { - header[pos] = metadataLength; - } - else { - header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); - } - return header; - }, - enumerable: false, - configurable: true - }); - CryptorHeaderV1.IDENTIFIER_LENGTH = 4; - CryptorHeaderV1.SENTINEL = 'PNED'; - return CryptorHeaderV1; -}()); diff --git a/lib/crypto/modules/node.js b/lib/crypto/modules/node.js index cb3968452..8e7d36a86 100644 --- a/lib/crypto/modules/node.js +++ b/lib/crypto/modules/node.js @@ -8,222 +8,115 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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 }); -/** */ -var stream_1 = require("stream"); -var crypto_1 = require("crypto"); -var NodeCryptography = /** @class */ (function () { - function NodeCryptography() { - } - Object.defineProperty(NodeCryptography.prototype, "algo", { - get: function () { - return 'aes-256-cbc'; - }, - enumerable: false, - configurable: true - }); - NodeCryptography.prototype.encrypt = function (key, input) { - return __awaiter(this, void 0, void 0, function () { - var bKey; - return __generator(this, function (_a) { - bKey = this.getKey(key); - if (input instanceof Buffer) { - return [2 /*return*/, this.encryptBuffer(bKey, input)]; - } - if (input instanceof stream_1.Readable) { - return [2 /*return*/, this.encryptStream(bKey, input)]; - } - if (typeof input === 'string') { - return [2 /*return*/, this.encryptString(bKey, input)]; - } - throw new Error('Unsupported input format'); - }); +const crypto_1 = require("crypto"); +const stream_1 = require("stream"); +const buffer_1 = require("buffer"); +class NodeCryptography { + encrypt(key, input) { + return __awaiter(this, void 0, void 0, function* () { + const bKey = this.getKey(key); + if (input instanceof buffer_1.Buffer) + return this.encryptBuffer(bKey, input); + if (input instanceof stream_1.Readable) + return this.encryptStream(bKey, input); + if (typeof input === 'string') + return this.encryptString(bKey, input); + throw new Error('Encryption error: unsupported input format'); }); - }; - NodeCryptography.prototype.decrypt = function (key, input) { - return __awaiter(this, void 0, void 0, function () { - var bKey; - return __generator(this, function (_a) { - bKey = this.getKey(key); - if (input instanceof Buffer) { - return [2 /*return*/, this.decryptBuffer(bKey, input)]; - } - if (input instanceof stream_1.Readable) { - return [2 /*return*/, this.decryptStream(bKey, input)]; - } - if (typeof input === 'string') { - return [2 /*return*/, this.decryptString(bKey, input)]; - } - throw new Error('Unsupported input format'); - }); + } + encryptBuffer(key, buffer) { + const bIv = this.getIv(); + const aes = (0, crypto_1.createCipheriv)(this.algo, key, bIv); + return buffer_1.Buffer.concat([bIv, aes.update(buffer), aes.final()]); + } + encryptStream(key, stream) { + return __awaiter(this, void 0, void 0, function* () { + const bIv = this.getIv(); + const aes = (0, crypto_1.createCipheriv)(this.algo, key, bIv).setAutoPadding(true); + let initiated = false; + return stream.pipe(aes).pipe(new stream_1.Transform({ + transform(chunk, _, cb) { + if (!initiated) { + initiated = true; + this.push(buffer_1.Buffer.concat([bIv, chunk])); + } + else + this.push(chunk); + cb(); + }, + })); }); - }; - NodeCryptography.prototype.encryptFile = function (key, file, File) { - return __awaiter(this, void 0, void 0, function () { - var bKey, _a, _b, _c, _d; - var _e, _f; - return __generator(this, function (_g) { - switch (_g.label) { - case 0: - bKey = this.getKey(key); - if (!(file.data instanceof Buffer)) return [3 /*break*/, 2]; - if (file.data.byteLength <= 0) - throw new Error('encryption error. empty content'); - _b = (_a = File).create; - _e = { - name: file.name, - mimeType: 'application/octet-stream' - }; - return [4 /*yield*/, this.encryptBuffer(bKey, file.data)]; - case 1: return [2 /*return*/, _b.apply(_a, [(_e.data = _g.sent(), - _e)])]; - case 2: - if (!(file.data instanceof stream_1.Readable)) return [3 /*break*/, 4]; - if (file.contentLength === 0) - throw new Error('encryption error. empty content'); - _d = (_c = File).create; - _f = { - name: file.name, - mimeType: 'application/octet-stream' - }; - return [4 /*yield*/, this.encryptStream(bKey, file.data)]; - case 3: return [2 /*return*/, _d.apply(_c, [(_f.stream = _g.sent(), - _f)])]; - case 4: throw new Error('Cannot encrypt this file. In Node.js file encryption supports only string, Buffer or Stream.'); - } - }); + } + encryptString(key, text) { + const bIv = this.getIv(); + const bPlaintext = buffer_1.Buffer.from(text); + const aes = (0, crypto_1.createCipheriv)(this.algo, key, bIv); + return buffer_1.Buffer.concat([bIv, aes.update(bPlaintext), aes.final()]).toString('utf8'); + } + encryptFile(key, file, File) { + return __awaiter(this, void 0, void 0, function* () { + const bKey = this.getKey(key); + if (file.data instanceof buffer_1.Buffer) { + if (file.data.byteLength <= 0) + throw new Error('Encryption error: empty content.'); + return File.create({ + name: file.name, + mimeType: file.mimeType, + data: this.encryptBuffer(bKey, file.data), + }); + } + if (file.data instanceof stream_1.Readable) { + if (!file.contentLength || file.contentLength === 0) + throw new Error('Encryption error: empty content.'); + return File.create({ + name: file.name, + mimeType: file.mimeType, + stream: yield this.encryptStream(bKey, file.data), + }); + } + throw new Error('Cannot encrypt this file. In Node.js file encryption supports only string, Buffer or Stream.'); }); - }; - NodeCryptography.prototype.decryptFile = function (key, file, File) { - return __awaiter(this, void 0, void 0, function () { - var bKey, _a, _b, _c, _d; - var _e, _f; - return __generator(this, function (_g) { - switch (_g.label) { - case 0: - bKey = this.getKey(key); - if (!(file.data instanceof Buffer)) return [3 /*break*/, 2]; - _b = (_a = File).create; - _e = { - name: file.name - }; - return [4 /*yield*/, this.decryptBuffer(bKey, file.data)]; - case 1: return [2 /*return*/, _b.apply(_a, [(_e.data = _g.sent(), - _e)])]; - case 2: - if (!(file.data instanceof stream_1.Readable)) return [3 /*break*/, 4]; - _d = (_c = File).create; - _f = { - name: file.name - }; - return [4 /*yield*/, this.decryptStream(bKey, file.data)]; - case 3: return [2 /*return*/, _d.apply(_c, [(_f.stream = _g.sent(), - _f)])]; - case 4: throw new Error('Cannot decrypt this file. In Node.js file decryption supports only string, Buffer or Stream.'); - } - }); + } + decrypt(key, input) { + return __awaiter(this, void 0, void 0, function* () { + const bKey = this.getKey(key); + if (input instanceof ArrayBuffer) { + const decryptedBuffer = this.decryptBuffer(bKey, buffer_1.Buffer.from(input)); + return decryptedBuffer.buffer.slice(decryptedBuffer.byteOffset, decryptedBuffer.byteOffset + decryptedBuffer.length); + } + if (input instanceof buffer_1.Buffer) + return this.decryptBuffer(bKey, input); + if (input instanceof stream_1.Readable) + return this.decryptStream(bKey, input); + if (typeof input === 'string') + return this.decryptString(bKey, input); + throw new Error('Decryption error: unsupported input format'); }); - }; - NodeCryptography.prototype.getKey = function (key) { - var sha = (0, crypto_1.createHash)('sha256'); - sha.update(Buffer.from(key, 'utf8')); - return Buffer.from(sha.digest('hex').slice(0, 32), 'utf8'); - }; - NodeCryptography.prototype.getIv = function () { - return (0, crypto_1.randomBytes)(NodeCryptography.IV_LENGTH); - }; - NodeCryptography.prototype.encryptString = function (key, plaintext) { - var bIv = this.getIv(); - var bPlaintext = Buffer.from(plaintext); - var aes = (0, crypto_1.createCipheriv)(this.algo, key, bIv); - return Buffer.concat([bIv, aes.update(bPlaintext), aes.final()]).toString('utf8'); - }; - NodeCryptography.prototype.decryptString = function (key, sCiphertext) { - var ciphertext = Buffer.from(sCiphertext); - var bIv = ciphertext.slice(0, NodeCryptography.IV_LENGTH); - var bCiphertext = ciphertext.slice(NodeCryptography.IV_LENGTH); - var aes = (0, crypto_1.createDecipheriv)(this.algo, key, bIv); - return Buffer.concat([aes.update(bCiphertext), aes.final()]).toString('utf8'); - }; - NodeCryptography.prototype.encryptBuffer = function (key, plaintext) { - var bIv = this.getIv(); - var aes = (0, crypto_1.createCipheriv)(this.algo, key, bIv); - return Buffer.concat([bIv, aes.update(plaintext), aes.final()]); - }; - NodeCryptography.prototype.decryptBuffer = function (key, ciphertext) { - var bIv = ciphertext.slice(0, NodeCryptography.IV_LENGTH); - var bCiphertext = ciphertext.slice(NodeCryptography.IV_LENGTH); + } + decryptBuffer(key, buffer) { + const bIv = buffer.slice(0, NodeCryptography.IV_LENGTH); + const bCiphertext = buffer.slice(NodeCryptography.IV_LENGTH); if (bCiphertext.byteLength <= 0) - throw new Error('decryption error: empty content'); - var aes = (0, crypto_1.createDecipheriv)(this.algo, key, bIv); - return Buffer.concat([aes.update(bCiphertext), aes.final()]); - }; - NodeCryptography.prototype.encryptStream = function (key, stream) { - return __awaiter(this, void 0, void 0, function () { - var bIv, aes, inited; - return __generator(this, function (_a) { - bIv = this.getIv(); - aes = (0, crypto_1.createCipheriv)('aes-256-cbc', key, bIv).setAutoPadding(true); - inited = false; - return [2 /*return*/, stream.pipe(aes).pipe(new stream_1.Transform({ - transform: function (chunk, _, cb) { - if (!inited) { - inited = true; - this.push(Buffer.concat([bIv, chunk])); - } - else { - this.push(chunk); - } - cb(); - }, - }))]; - }); - }); - }; - NodeCryptography.prototype.decryptStream = function (key, stream) { - var _this = this; - var output = new stream_1.PassThrough(); - var bIv = Buffer.alloc(0); - var aes = null; - var getIv = function () { - var data = stream.read(); + throw new Error('Decryption error: empty content'); + const aes = (0, crypto_1.createDecipheriv)(this.algo, key, bIv); + return buffer_1.Buffer.concat([aes.update(bCiphertext), aes.final()]); + } + decryptStream(key, stream) { + let aes = null; + const output = new stream_1.PassThrough(); + let bIv = buffer_1.Buffer.alloc(0); + const getIv = () => { + let data = stream.read(); while (data !== null) { if (data) { - var bChunk = Buffer.from(data); - var sliceLen = NodeCryptography.IV_LENGTH - bIv.byteLength; - if (bChunk.byteLength < sliceLen) { - bIv = Buffer.concat([bIv, bChunk]); - } + const bChunk = buffer_1.Buffer.from(data); + const sliceLen = NodeCryptography.IV_LENGTH - bIv.byteLength; + if (bChunk.byteLength < sliceLen) + bIv = buffer_1.Buffer.concat([bIv, bChunk]); else { - bIv = Buffer.concat([bIv, bChunk.slice(0, sliceLen)]); - aes = (0, crypto_1.createDecipheriv)(_this.algo, key, bIv); + bIv = buffer_1.Buffer.concat([bIv, bChunk.slice(0, sliceLen)]); + aes = (0, crypto_1.createDecipheriv)(this.algo, key, bIv); aes.pipe(output); aes.write(bChunk.slice(sliceLen)); } @@ -232,15 +125,51 @@ var NodeCryptography = /** @class */ (function () { } }; stream.on('readable', getIv); - stream.on('end', function () { - if (aes) { + stream.on('end', () => { + if (aes) aes.end(); - } output.end(); }); return output; - }; - NodeCryptography.IV_LENGTH = 16; - return NodeCryptography; -}()); + } + decryptString(key, text) { + const ciphertext = buffer_1.Buffer.from(text); + const bIv = ciphertext.slice(0, NodeCryptography.IV_LENGTH); + const bCiphertext = ciphertext.slice(NodeCryptography.IV_LENGTH); + const aes = (0, crypto_1.createDecipheriv)(this.algo, key, bIv); + return buffer_1.Buffer.concat([aes.update(bCiphertext), aes.final()]).toString('utf8'); + } + decryptFile(key, file, File) { + return __awaiter(this, void 0, void 0, function* () { + const bKey = this.getKey(key); + if (file.data instanceof buffer_1.Buffer) { + return File.create({ + name: file.name, + mimeType: file.mimeType, + data: this.decryptBuffer(bKey, file.data), + }); + } + if (file.data instanceof stream_1.Readable) { + return File.create({ + name: file.name, + mimeType: file.mimeType, + stream: this.decryptStream(bKey, file.data), + }); + } + throw new Error('Cannot decrypt this file. In Node.js file decryption supports only string, Buffer or Stream.'); + }); + } + get algo() { + return 'aes-256-cbc'; + } + getKey(key) { + const sha = (0, crypto_1.createHash)('sha256'); + sha.update(buffer_1.Buffer.from(key, 'utf8')); + return buffer_1.Buffer.from(sha.digest('hex').slice(0, 32), 'utf8'); + } + getIv() { + return (0, crypto_1.randomBytes)(NodeCryptography.IV_LENGTH); + } +} +NodeCryptography.IV_LENGTH = 16; exports.default = NodeCryptography; diff --git a/lib/crypto/modules/web.js b/lib/crypto/modules/web.js deleted file mode 100644 index b7bb887ea..000000000 --- a/lib/crypto/modules/web.js +++ /dev/null @@ -1,230 +0,0 @@ -"use strict"; -/* global crypto */ -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 (_) 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 }); -function concatArrayBuffer(ab1, ab2) { - var tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); - tmp.set(new Uint8Array(ab1), 0); - tmp.set(new Uint8Array(ab2), ab1.byteLength); - return tmp.buffer; -} -var WebCryptography = /** @class */ (function () { - function WebCryptography() { - } - Object.defineProperty(WebCryptography.prototype, "algo", { - get: function () { - return 'aes-256-cbc'; - }, - enumerable: false, - configurable: true - }); - WebCryptography.prototype.encrypt = function (key, input) { - return __awaiter(this, void 0, void 0, function () { - var cKey; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.getKey(key)]; - case 1: - cKey = _a.sent(); - if (input instanceof ArrayBuffer) { - return [2 /*return*/, this.encryptArrayBuffer(cKey, input)]; - } - if (typeof input === 'string') { - return [2 /*return*/, this.encryptString(cKey, input)]; - } - throw new Error('Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer'); - } - }); - }); - }; - WebCryptography.prototype.decrypt = function (key, input) { - return __awaiter(this, void 0, void 0, function () { - var cKey; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.getKey(key)]; - case 1: - cKey = _a.sent(); - if (input instanceof ArrayBuffer) { - return [2 /*return*/, this.decryptArrayBuffer(cKey, input)]; - } - if (typeof input === 'string') { - return [2 /*return*/, this.decryptString(cKey, input)]; - } - throw new Error('Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer'); - } - }); - }); - }; - WebCryptography.prototype.encryptFile = function (key, file, File) { - return __awaiter(this, void 0, void 0, function () { - var bKey, abPlaindata, abCipherdata; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (file.data.byteLength <= 0) - throw new Error('encryption error. empty content'); - return [4 /*yield*/, this.getKey(key)]; - case 1: - bKey = _a.sent(); - return [4 /*yield*/, file.data.arrayBuffer()]; - case 2: - abPlaindata = _a.sent(); - return [4 /*yield*/, this.encryptArrayBuffer(bKey, abPlaindata)]; - case 3: - abCipherdata = _a.sent(); - return [2 /*return*/, File.create({ - name: file.name, - mimeType: 'application/octet-stream', - data: abCipherdata, - })]; - } - }); - }); - }; - WebCryptography.prototype.decryptFile = function (key, file, File) { - return __awaiter(this, void 0, void 0, function () { - var bKey, abCipherdata, abPlaindata; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.getKey(key)]; - case 1: - bKey = _a.sent(); - return [4 /*yield*/, file.data.arrayBuffer()]; - case 2: - abCipherdata = _a.sent(); - return [4 /*yield*/, this.decryptArrayBuffer(bKey, abCipherdata)]; - case 3: - abPlaindata = _a.sent(); - return [2 /*return*/, File.create({ - name: file.name, - data: abPlaindata, - })]; - } - }); - }); - }; - WebCryptography.prototype.getKey = function (key) { - return __awaiter(this, void 0, void 0, function () { - var digest, hashHex, abKey; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, crypto.subtle.digest('SHA-256', WebCryptography.encoder.encode(key))]; - case 1: - digest = _a.sent(); - hashHex = Array.from(new Uint8Array(digest)) - .map(function (b) { return b.toString(16).padStart(2, '0'); }) - .join(''); - abKey = WebCryptography.encoder.encode(hashHex.slice(0, 32)).buffer; - return [2 /*return*/, crypto.subtle.importKey('raw', abKey, 'AES-CBC', true, ['encrypt', 'decrypt'])]; - } - }); - }); - }; - WebCryptography.prototype.encryptArrayBuffer = function (key, plaintext) { - return __awaiter(this, void 0, void 0, function () { - var abIv, _a, _b; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - abIv = crypto.getRandomValues(new Uint8Array(16)); - _a = concatArrayBuffer; - _b = [abIv.buffer]; - return [4 /*yield*/, crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, plaintext)]; - case 1: return [2 /*return*/, _a.apply(void 0, _b.concat([_c.sent()]))]; - } - }); - }); - }; - WebCryptography.prototype.decryptArrayBuffer = function (key, ciphertext) { - return __awaiter(this, void 0, void 0, function () { - var abIv, data; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - abIv = ciphertext.slice(0, 16); - if (ciphertext.slice(WebCryptography.IV_LENGTH).byteLength <= 0) - throw new Error('decryption error: empty content'); - return [4 /*yield*/, crypto.subtle.decrypt({ name: 'AES-CBC', iv: abIv }, key, ciphertext.slice(WebCryptography.IV_LENGTH))]; - case 1: - data = _a.sent(); - return [2 /*return*/, data]; - } - }); - }); - }; - WebCryptography.prototype.encryptString = function (key, plaintext) { - return __awaiter(this, void 0, void 0, function () { - var abIv, abPlaintext, abPayload, ciphertext; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - abIv = crypto.getRandomValues(new Uint8Array(16)); - abPlaintext = WebCryptography.encoder.encode(plaintext).buffer; - return [4 /*yield*/, crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, abPlaintext)]; - case 1: - abPayload = _a.sent(); - ciphertext = concatArrayBuffer(abIv.buffer, abPayload); - return [2 /*return*/, WebCryptography.decoder.decode(ciphertext)]; - } - }); - }); - }; - WebCryptography.prototype.decryptString = function (key, ciphertext) { - return __awaiter(this, void 0, void 0, function () { - var abCiphertext, abIv, abPayload, abPlaintext; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - abCiphertext = WebCryptography.encoder.encode(ciphertext).buffer; - abIv = abCiphertext.slice(0, 16); - abPayload = abCiphertext.slice(16); - return [4 /*yield*/, crypto.subtle.decrypt({ name: 'AES-CBC', iv: abIv }, key, abPayload)]; - case 1: - abPlaintext = _a.sent(); - return [2 /*return*/, WebCryptography.decoder.decode(abPlaintext)]; - } - }); - }); - }; - WebCryptography.IV_LENGTH = 16; - WebCryptography.encoder = new TextEncoder(); - WebCryptography.decoder = new TextDecoder(); - return WebCryptography; -}()); -exports.default = WebCryptography; diff --git a/lib/entities/Channel.js b/lib/entities/Channel.js index 0043f20dc..2aa39e7cf 100644 --- a/lib/entities/Channel.js +++ b/lib/entities/Channel.js @@ -1,22 +1,21 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Channel = void 0; -var Subscription_1 = require("./Subscription"); -var Channel = /** @class */ (function () { - function Channel(channelName, eventEmitter, pubnub) { - this.name = channelName; +const Subscription_1 = require("./Subscription"); +class Channel { + constructor(channelName, eventEmitter, pubnub) { this.eventEmitter = eventEmitter; this.pubnub = pubnub; + this.name = channelName; } - Channel.prototype.subscription = function (subscriptionOptions) { + subscription(subscriptionOptions) { return new Subscription_1.Subscription({ - channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, "".concat(this.name, "-pnpres")] : [this.name], + channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], channelGroups: [], subscriptionOptions: subscriptionOptions, eventEmitter: this.eventEmitter, pubnub: this.pubnub, }); - }; - return Channel; -}()); + } +} exports.Channel = Channel; diff --git a/lib/entities/ChannelGroup.js b/lib/entities/ChannelGroup.js index 07a0bea48..d4de51cac 100644 --- a/lib/entities/ChannelGroup.js +++ b/lib/entities/ChannelGroup.js @@ -1,22 +1,21 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChannelGroup = void 0; -var Subscription_1 = require("./Subscription"); -var ChannelGroup = /** @class */ (function () { - function ChannelGroup(channelGroup, eventEmitter, pubnub) { - this.name = channelGroup; +const Subscription_1 = require("./Subscription"); +class ChannelGroup { + constructor(channelGroup, eventEmitter, pubnub) { this.eventEmitter = eventEmitter; this.pubnub = pubnub; + this.name = channelGroup; } - ChannelGroup.prototype.subscription = function (subscriptionOptions) { + subscription(subscriptionOptions) { return new Subscription_1.Subscription({ channels: [], - channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, "".concat(this.name, "-pnpres")] : [this.name], + channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], subscriptionOptions: subscriptionOptions, eventEmitter: this.eventEmitter, pubnub: this.pubnub, }); - }; - return ChannelGroup; -}()); + } +} exports.ChannelGroup = ChannelGroup; diff --git a/lib/entities/ChannelMetadata.js b/lib/entities/ChannelMetadata.js index 5345f4ed8..c1d6fe93e 100644 --- a/lib/entities/ChannelMetadata.js +++ b/lib/entities/ChannelMetadata.js @@ -1,14 +1,14 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ChannelMetadata = void 0; -var Subscription_1 = require("./Subscription"); -var ChannelMetadata = /** @class */ (function () { - function ChannelMetadata(id, eventEmitter, pubnub) { +const Subscription_1 = require("./Subscription"); +class ChannelMetadata { + constructor(id, eventEmitter, pubnub) { this.id = id; this.eventEmitter = eventEmitter; this.pubnub = pubnub; } - ChannelMetadata.prototype.subscription = function (subscriptionOptions) { + subscription(subscriptionOptions) { return new Subscription_1.Subscription({ channels: [this.id], channelGroups: [], @@ -16,7 +16,6 @@ var ChannelMetadata = /** @class */ (function () { eventEmitter: this.eventEmitter, pubnub: this.pubnub, }); - }; - return ChannelMetadata; -}()); + } +} exports.ChannelMetadata = ChannelMetadata; diff --git a/lib/entities/SubscribeCapable.js b/lib/entities/SubscribeCapable.js index 554527544..3a037f788 100644 --- a/lib/entities/SubscribeCapable.js +++ b/lib/entities/SubscribeCapable.js @@ -1,92 +1,46 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.SubscribeCapable = void 0; -var SubscribeCapable = /** @class */ (function () { - function SubscribeCapable() { - } - SubscribeCapable.prototype.subscribe = function () { +class SubscribeCapable { + subscribe() { var _a, _b; - this.pubnub.subscribe(__assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken }))); - }; - SubscribeCapable.prototype.unsubscribe = function () { + this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken }))); + } + unsubscribe() { this.pubnub.unsubscribe({ - channels: this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), - channelGroups: this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); }), + channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')), + channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), }); - }; - Object.defineProperty(SubscribeCapable.prototype, "onMessage", { - set: function (onMessagelistener) { - this.listener.message = onMessagelistener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onPresence", { - set: function (onPresencelistener) { - this.listener.presence = onPresencelistener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onSignal", { - set: function (onSignalListener) { - this.listener.signal = onSignalListener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onObjects", { - set: function (onObjectsListener) { - this.listener.objects = onObjectsListener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onMessageAction", { - set: function (messageActionEventListener) { - this.listener.messageAction = messageActionEventListener; - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "onFile", { - set: function (fileEventListener) { - this.listener.file = fileEventListener; - }, - enumerable: false, - configurable: true - }); - SubscribeCapable.prototype.addListener = function (listener) { - this.eventEmitter.addListener(listener, this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); - }; - SubscribeCapable.prototype.removeListener = function (listener) { + } + set onMessage(onMessageListener) { + this.listener.message = onMessageListener; + } + set onPresence(onPresenceListener) { + this.listener.presence = onPresenceListener; + } + set onSignal(onSignalListener) { + this.listener.signal = onSignalListener; + } + set onObjects(onObjectsListener) { + this.listener.objects = onObjectsListener; + } + set onMessageAction(messageActionEventListener) { + this.listener.messageAction = messageActionEventListener; + } + set onFile(fileEventListener) { + this.listener.file = fileEventListener; + } + addListener(listener) { + this.eventEmitter.addListener(listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + } + removeListener(listener) { this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); - }; - Object.defineProperty(SubscribeCapable.prototype, "channels", { - get: function () { - return this.channelNames.slice(0); - }, - enumerable: false, - configurable: true - }); - Object.defineProperty(SubscribeCapable.prototype, "channelGroups", { - get: function () { - return this.groupNames.slice(0); - }, - enumerable: false, - configurable: true - }); - return SubscribeCapable; -}()); + } + get channels() { + return this.channelNames.slice(0); + } + get channelGroups() { + return this.groupNames.slice(0); + } +} exports.SubscribeCapable = SubscribeCapable; diff --git a/lib/entities/Subscription.js b/lib/entities/Subscription.js index 586f8d3c3..e2aa6e8ba 100644 --- a/lib/entities/Subscription.js +++ b/lib/entities/Subscription.js @@ -1,84 +1,29 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.Subscription = void 0; -var SubscriptionSet_1 = require("./SubscriptionSet"); -var SubscribeCapable_1 = require("./SubscribeCapable"); -var Subscription = /** @class */ (function (_super) { - __extends(Subscription, _super); - function Subscription(_a) { - var channels = _a.channels, channelGroups = _a.channelGroups, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub; - var _this = _super.call(this) || this; - _this.channelNames = []; - _this.groupNames = []; - _this.channelNames = channels; - _this.groupNames = channelGroups; - _this.options = subscriptionOptions; - _this.pubnub = pubnub; - _this.eventEmitter = eventEmitter; - _this.listener = {}; - eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); - return _this; +const SubscribeCapable_1 = require("./SubscribeCapable"); +const SubscriptionSet_1 = require("./SubscriptionSet"); +class Subscription extends SubscribeCapable_1.SubscribeCapable { + constructor({ channels, channelGroups, subscriptionOptions, eventEmitter, pubnub, }) { + super(); + this.channelNames = []; + this.groupNames = []; + this.channelNames = channels; + this.groupNames = channelGroups; + this.options = subscriptionOptions; + this.pubnub = pubnub; + this.eventEmitter = eventEmitter; + this.listener = {}; + eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); } - Subscription.prototype.addSubscription = function (subscription) { + addSubscription(subscription) { return new SubscriptionSet_1.SubscriptionSet({ - channels: __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscription.channels), false), - channelGroups: __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(subscription.channelGroups), false), - subscriptionOptions: __assign(__assign({}, this.options), subscription === null || subscription === void 0 ? void 0 : subscription.options), + channels: [...this.channelNames, ...subscription.channels], + channelGroups: [...this.groupNames, ...subscription.channelGroups], + subscriptionOptions: Object.assign(Object.assign({}, this.options), subscription === null || subscription === void 0 ? void 0 : subscription.options), eventEmitter: this.eventEmitter, pubnub: this.pubnub, }); - }; - return Subscription; -}(SubscribeCapable_1.SubscribeCapable)); + } +} exports.Subscription = Subscription; diff --git a/lib/entities/SubscriptionSet.js b/lib/entities/SubscriptionSet.js index 590de45e0..46f048685 100644 --- a/lib/entities/SubscriptionSet.js +++ b/lib/entities/SubscriptionSet.js @@ -1,111 +1,63 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.SubscriptionSet = void 0; -var SubscribeCapable_1 = require("./SubscribeCapable"); -var SubscriptionSet = /** @class */ (function (_super) { - __extends(SubscriptionSet, _super); - function SubscriptionSet(_a) { - var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c, subscriptionOptions = _a.subscriptionOptions, eventEmitter = _a.eventEmitter, pubnub = _a.pubnub; - var _this = _super.call(this) || this; - _this.channelNames = []; - _this.groupNames = []; - _this.subscriptionList = []; - _this.options = subscriptionOptions; - _this.eventEmitter = eventEmitter; - _this.pubnub = pubnub; +const SubscribeCapable_1 = require("./SubscribeCapable"); +class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { + constructor({ channels = [], channelGroups = [], subscriptionOptions, eventEmitter, pubnub, }) { + super(); + this.channelNames = []; + this.groupNames = []; + this.subscriptionList = []; + this.options = subscriptionOptions; + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; channels - .filter(function (c) { return !c.endsWith('-pnpres'); }) - .forEach(function (c) { - var subscription = _this.pubnub.channel(c).subscription(_this.options); - _this.channelNames = __spreadArray(__spreadArray([], __read(_this.channelNames), false), __read(subscription.channels), false); - _this.subscriptionList.push(subscription); + .filter((c) => !c.endsWith('-pnpres')) + .forEach((c) => { + const subscription = this.pubnub.channel(c).subscription(this.options); + this.channelNames = [...this.channelNames, ...subscription.channels]; + this.subscriptionList.push(subscription); }); channelGroups - .filter(function (cg) { return !cg.endsWith('-pnpres'); }) - .forEach(function (cg) { - var subscription = _this.pubnub.channelGroup(cg).subscription(_this.options); - _this.groupNames = __spreadArray(__spreadArray([], __read(_this.groupNames), false), __read(subscription.channelGroups), false); - _this.subscriptionList.push(subscription); + .filter((cg) => !cg.endsWith('-pnpres')) + .forEach((cg) => { + const subscription = this.pubnub.channelGroup(cg).subscription(this.options); + this.groupNames = [...this.groupNames, ...subscription.channelGroups]; + this.subscriptionList.push(subscription); }); - _this.listener = {}; - eventEmitter.addListener(_this.listener, _this.channelNames.filter(function (c) { return !c.endsWith('-pnpres'); }), _this.groupNames.filter(function (cg) { return !cg.endsWith('-pnpres'); })); - return _this; + this.listener = {}; + eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); } - SubscriptionSet.prototype.addSubscription = function (subscription) { + addSubscription(subscription) { this.subscriptionList.push(subscription); - this.channelNames = __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscription.channels), false); - this.groupNames = __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(subscription.channelGroups), false); + this.channelNames = [...this.channelNames, ...subscription.channels]; + this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); - }; - SubscriptionSet.prototype.removeSubscription = function (subscription) { - var channelsToRemove = subscription.channels; - var groupsToRemove = subscription.channelGroups; - this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); - this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); - this.subscriptionList = this.subscriptionList.filter(function (s) { return s !== subscription; }); + } + removeSubscription(subscription) { + const channelsToRemove = subscription.channels; + const groupsToRemove = subscription.channelGroups; + this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); + this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); + this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); - }; - SubscriptionSet.prototype.addSubscriptionSet = function (subscriptionSet) { - this.subscriptionList = __spreadArray(__spreadArray([], __read(this.subscriptionList), false), __read(subscriptionSet.subscriptions), false); - this.channelNames = __spreadArray(__spreadArray([], __read(this.channelNames), false), __read(subscriptionSet.channels), false); - this.groupNames = __spreadArray(__spreadArray([], __read(this.groupNames), false), __read(subscriptionSet.channelGroups), false); + } + addSubscriptionSet(subscriptionSet) { + this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; + this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; + this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); - }; - SubscriptionSet.prototype.removeSubscriptionSet = function (subscriptionSet) { - var channelsToRemove = subscriptionSet.channels; - var groupsToRemove = subscriptionSet.channelGroups; - this.channelNames = this.channelNames.filter(function (c) { return !channelsToRemove.includes(c); }); - this.groupNames = this.groupNames.filter(function (cg) { return !groupsToRemove.includes(cg); }); - this.subscriptionList = this.subscriptionList.filter(function (s) { return !subscriptionSet.subscriptions.includes(s); }); + } + removeSubscriptionSet(subscriptionSet) { + const channelsToRemove = subscriptionSet.channels; + const groupsToRemove = subscriptionSet.channelGroups; + this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); + this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); + this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); - }; - Object.defineProperty(SubscriptionSet.prototype, "subscriptions", { - get: function () { - return this.subscriptionList.slice(0); - }, - enumerable: false, - configurable: true - }); - return SubscriptionSet; -}(SubscribeCapable_1.SubscribeCapable)); + } + get subscriptions() { + return this.subscriptionList.slice(0); + } +} exports.SubscriptionSet = SubscriptionSet; diff --git a/lib/entities/UserMetadata.js b/lib/entities/UserMetadata.js index 8989b01f3..d7c03f5f1 100644 --- a/lib/entities/UserMetadata.js +++ b/lib/entities/UserMetadata.js @@ -1,14 +1,14 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UserMetadata = void 0; -var Subscription_1 = require("./Subscription"); -var UserMetadata = /** @class */ (function () { - function UserMetadata(id, eventEmitter, pubnub) { +const Subscription_1 = require("./Subscription"); +class UserMetadata { + constructor(id, eventEmitter, pubnub) { this.id = id; this.eventEmitter = eventEmitter; this.pubnub = pubnub; } - UserMetadata.prototype.subscription = function (subscriptionOptions) { + subscription(subscriptionOptions) { return new Subscription_1.Subscription({ channels: [this.id], channelGroups: [], @@ -16,7 +16,6 @@ var UserMetadata = /** @class */ (function () { eventEmitter: this.eventEmitter, pubnub: this.pubnub, }); - }; - return UserMetadata; -}()); + } +} exports.UserMetadata = UserMetadata; diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js new file mode 100644 index 000000000..193fd3562 --- /dev/null +++ b/lib/errors/pubnub-api-error.js @@ -0,0 +1,140 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PubNubAPIError = void 0; +const categories_1 = __importDefault(require("../core/constants/categories")); +const pubnub_error_1 = require("./pubnub-error"); +class PubNubAPIError extends Error { + static create(errorOrResponse, data) { + if (errorOrResponse instanceof Error) + return PubNubAPIError.createFromError(errorOrResponse); + else + return PubNubAPIError.createFromServiceResponse(errorOrResponse, data); + } + static createFromError(error) { + let category = categories_1.default.PNUnknownCategory; + let message = 'Unknown error'; + let errorName = 'Error'; + if (!error) + return new PubNubAPIError(message, category, 0); + else if (error instanceof PubNubAPIError) + return error; + if (error instanceof Error) { + message = error.message; + errorName = error.name; + } + if (errorName === 'AbortError' || message.indexOf('Aborted') !== -1) { + category = categories_1.default.PNCancelledCategory; + message = 'Request cancelled'; + } + else if (message.indexOf('timeout') !== -1) { + category = categories_1.default.PNTimeoutCategory; + message = 'Request timeout'; + } + else if (message.indexOf('network') !== -1) { + category = categories_1.default.PNNetworkIssuesCategory; + message = 'Network issues'; + } + else if (errorName === 'TypeError') { + category = categories_1.default.PNBadRequestCategory; + } + else if (errorName === 'FetchError') { + const errorCode = error.code; + if (['ECONNREFUSED', 'ENETUNREACH', 'ENOTFOUND', 'ECONNRESET', 'EAI_AGAIN'].includes(errorCode)) + category = categories_1.default.PNNetworkIssuesCategory; + if (errorCode === 'ECONNREFUSED') + message = 'Connection refused'; + else if (errorCode === 'ENETUNREACH') + message = 'Network not reachable'; + else if (errorCode === 'ENOTFOUND') + message = 'Server not found'; + else if (errorCode === 'ECONNRESET') + message = 'Connection reset by peer'; + else if (errorCode === 'EAI_AGAIN') + message = 'Name resolution error'; + else if (errorCode === 'ETIMEDOUT') { + category = categories_1.default.PNTimeoutCategory; + message = 'Request timeout'; + } + else + message = `Unknown system error: ${error}`; + } + else if (message === 'Request timeout') + category = categories_1.default.PNTimeoutCategory; + return new PubNubAPIError(message, category, 0, error); + } + static createFromServiceResponse(response, data) { + let category = categories_1.default.PNUnknownCategory; + let errorData; + let message = 'Unknown error'; + let { status } = response; + data !== null && data !== void 0 ? data : (data = response.body); + if (status === 402) + message = 'Not available for used key set. Contact support@pubnub.com'; + else if (status === 400) { + category = categories_1.default.PNBadRequestCategory; + message = 'Bad request'; + } + else if (status === 403) { + category = categories_1.default.PNAccessDeniedCategory; + message = 'Access denied'; + } + if (data && data.byteLength > 0) { + const decoded = new TextDecoder().decode(data); + if (response.headers['content-type'].indexOf('text/javascript') !== -1 || + response.headers['content-type'].indexOf('application/json') !== -1) { + try { + const errorResponse = JSON.parse(decoded); + if (typeof errorResponse === 'object' && !Array.isArray(errorResponse)) { + if ('error' in errorResponse && + (errorResponse.error === 1 || errorResponse.error === true) && + 'status' in errorResponse && + typeof errorResponse.status === 'number' && + 'message' in errorResponse && + 'service' in errorResponse) { + errorData = errorResponse; + status = errorResponse.status; + } + else + errorData = errorResponse; + if ('error' in errorResponse && errorResponse.error instanceof Error) + errorData = errorResponse.error; + } + } + catch (_) { + errorData = decoded; + } + } + else if (response.headers['content-type'].indexOf('xml') !== -1) { + const reason = /(.*)<\/Message>/gi.exec(decoded); + message = reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.'; + } + else { + errorData = decoded; + } + } + return new PubNubAPIError(message, category, status, errorData); + } + constructor(message, category, statusCode, errorData) { + super(message); + this.category = category; + this.statusCode = statusCode; + this.errorData = errorData; + this.name = 'PubNubAPIError'; + } + toStatus(operation) { + return { + error: true, + category: this.category, + operation, + statusCode: this.statusCode, + errorData: this.errorData, + }; + } + toPubNubError(operation, message) { + return new pubnub_error_1.PubNubError(message !== null && message !== void 0 ? message : this.message, this.toStatus(operation)); + } +} +exports.PubNubAPIError = PubNubAPIError; diff --git a/lib/errors/pubnub-error.js b/lib/errors/pubnub-error.js new file mode 100644 index 000000000..40c24f8df --- /dev/null +++ b/lib/errors/pubnub-error.js @@ -0,0 +1,26 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.createValidationError = exports.PubNubError = void 0; +const categories_1 = __importDefault(require("../core/constants/categories")); +class PubNubError extends Error { + constructor(message, status) { + super(message); + this.status = status; + this.name = 'PubNubError'; + this.message = message; + Object.setPrototypeOf(this, new.target.prototype); + } +} +exports.PubNubError = PubNubError; +function createError(errorPayload) { + var _a; + (_a = errorPayload.statusCode) !== null && _a !== void 0 ? _a : (errorPayload.statusCode = 0); + return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: categories_1.default.PNValidationErrorCategory, error: true }); +} +function createValidationError(message, statusCode) { + return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {}))); +} +exports.createValidationError = createValidationError; diff --git a/lib/event-engine/core/change.js b/lib/event-engine/core/change.js index 2b5963b5c..c8ad2e549 100644 --- a/lib/event-engine/core/change.js +++ b/lib/event-engine/core/change.js @@ -1,3 +1,2 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/event-engine/core/dispatcher.js b/lib/event-engine/core/dispatcher.js index 056a97830..4cfc94966 100644 --- a/lib/event-engine/core/dispatcher.js +++ b/lib/event-engine/core/dispatcher.js @@ -1,79 +1,39 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ -var __values = (this && this.__values) || function(o) { - var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; - if (m) return m.call(o); - if (o && typeof o.length === "number") return { - next: function () { - if (o && i >= o.length) o = void 0; - return { value: o && o[i++], done: !o }; - } - }; - throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); -}; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.Dispatcher = void 0; -var Dispatcher = /** @class */ (function () { - function Dispatcher(dependencies) { +class Dispatcher { + constructor(dependencies) { this.dependencies = dependencies; this.instances = new Map(); this.handlers = new Map(); } - Dispatcher.prototype.on = function (type, handlerCreator) { + on(type, handlerCreator) { this.handlers.set(type, handlerCreator); - }; - Dispatcher.prototype.dispatch = function (invocation) { + } + dispatch(invocation) { if (invocation.type === 'CANCEL') { if (this.instances.has(invocation.payload)) { - var instance_1 = this.instances.get(invocation.payload); - instance_1 === null || instance_1 === void 0 ? void 0 : instance_1.cancel(); + const instance = this.instances.get(invocation.payload); + instance === null || instance === void 0 ? void 0 : instance.cancel(); this.instances.delete(invocation.payload); } return; } - var handlerCreator = this.handlers.get(invocation.type); + const handlerCreator = this.handlers.get(invocation.type); if (!handlerCreator) { - throw new Error("Unhandled invocation '".concat(invocation.type, "'")); + throw new Error(`Unhandled invocation '${invocation.type}'`); } - var instance = handlerCreator(invocation.payload, this.dependencies); + const instance = handlerCreator(invocation.payload, this.dependencies); if (invocation.managed) { this.instances.set(invocation.type, instance); } instance.start(); - }; - Dispatcher.prototype.dispose = function () { - var e_1, _a; - try { - for (var _b = __values(this.instances.entries()), _c = _b.next(); !_c.done; _c = _b.next()) { - var _d = __read(_c.value, 2), key = _d[0], instance = _d[1]; - instance.cancel(); - this.instances.delete(key); - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (_c && !_c.done && (_a = _b.return)) _a.call(_b); - } - finally { if (e_1) throw e_1.error; } + } + dispose() { + for (const [key, instance] of this.instances.entries()) { + instance.cancel(); + this.instances.delete(key); } - }; - return Dispatcher; -}()); + } +} exports.Dispatcher = Dispatcher; diff --git a/lib/event-engine/core/engine.js b/lib/event-engine/core/engine.js index 2b0eb5519..351df033f 100644 --- a/lib/event-engine/core/engine.js +++ b/lib/event-engine/core/engine.js @@ -1,60 +1,13 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __values = (this && this.__values) || function(o) { - var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; - if (m) return m.call(o); - if (o && typeof o.length === "number") return { - next: function () { - if (o && i >= o.length) o = void 0; - return { value: o && o[i++], done: !o }; - } - }; - throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.Engine = void 0; -var subject_1 = require("../../core/components/subject"); -var state_1 = require("./state"); -var Engine = /** @class */ (function (_super) { - __extends(Engine, _super); - function Engine() { - return _super !== null && _super.apply(this, arguments) || this; - } - Engine.prototype.describe = function (label) { +const subject_1 = require("../../core/components/subject"); +const state_1 = require("./state"); +class Engine extends subject_1.Subject { + describe(label) { return new state_1.State(label); - }; - Engine.prototype.start = function (initialState, initialContext) { + } + start(initialState, initialContext) { this.currentState = initialState; this.currentContext = initialContext; this.notify({ @@ -63,9 +16,8 @@ var Engine = /** @class */ (function (_super) { context: initialContext, }); return; - }; - Engine.prototype.transition = function (event) { - var e_1, _a, e_2, _b, e_3, _c; + } + transition(event) { if (!this.currentState) { throw new Error('Start the engine first'); } @@ -73,28 +25,18 @@ var Engine = /** @class */ (function (_super) { type: 'eventReceived', event: event, }); - var transition = this.currentState.transition(this.currentContext, event); + const transition = this.currentState.transition(this.currentContext, event); if (transition) { - var _d = __read(transition, 3), newState = _d[0], newContext = _d[1], effects = _d[2]; - try { - for (var _e = __values(this.currentState.exitEffects), _f = _e.next(); !_f.done; _f = _e.next()) { - var effect = _f.value; - this.notify({ - type: 'invocationDispatched', - invocation: effect(this.currentContext), - }); - } - } - catch (e_1_1) { e_1 = { error: e_1_1 }; } - finally { - try { - if (_f && !_f.done && (_a = _e.return)) _a.call(_e); - } - finally { if (e_1) throw e_1.error; } + const [newState, newContext, effects] = transition; + for (const effect of this.currentState.exitEffects) { + this.notify({ + type: 'invocationDispatched', + invocation: effect(this.currentContext), + }); } - var oldState = this.currentState; + const oldState = this.currentState; this.currentState = newState; - var oldContext = this.currentContext; + const oldContext = this.currentContext; this.currentContext = newContext; this.notify({ type: 'transitionDone', @@ -104,40 +46,19 @@ var Engine = /** @class */ (function (_super) { toContext: newContext, event: event, }); - try { - for (var effects_1 = __values(effects), effects_1_1 = effects_1.next(); !effects_1_1.done; effects_1_1 = effects_1.next()) { - var effect = effects_1_1.value; - this.notify({ - type: 'invocationDispatched', - invocation: effect, - }); - } - } - catch (e_2_1) { e_2 = { error: e_2_1 }; } - finally { - try { - if (effects_1_1 && !effects_1_1.done && (_b = effects_1.return)) _b.call(effects_1); - } - finally { if (e_2) throw e_2.error; } + for (const effect of effects) { + this.notify({ + type: 'invocationDispatched', + invocation: effect, + }); } - try { - for (var _g = __values(this.currentState.enterEffects), _h = _g.next(); !_h.done; _h = _g.next()) { - var effect = _h.value; - this.notify({ - type: 'invocationDispatched', - invocation: effect(this.currentContext), - }); - } - } - catch (e_3_1) { e_3 = { error: e_3_1 }; } - finally { - try { - if (_h && !_h.done && (_c = _g.return)) _c.call(_g); - } - finally { if (e_3) throw e_3.error; } + for (const effect of this.currentState.enterEffects) { + this.notify({ + type: 'invocationDispatched', + invocation: effect(this.currentContext), + }); } } - }; - return Engine; -}(subject_1.Subject)); + } +} exports.Engine = Engine; diff --git a/lib/event-engine/core/handler.js b/lib/event-engine/core/handler.js index f5446b05f..88bead570 100644 --- a/lib/event-engine/core/handler.js +++ b/lib/event-engine/core/handler.js @@ -1,52 +1,27 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); Object.defineProperty(exports, "__esModule", { value: true }); exports.asyncHandler = exports.Handler = void 0; -var abort_signal_1 = require("../../core/components/abort_signal"); -var Handler = /** @class */ (function () { - function Handler(payload, dependencies) { +const abort_signal_1 = require("../../core/components/abort_signal"); +class Handler { + constructor(payload, dependencies) { this.payload = payload; this.dependencies = dependencies; } - return Handler; -}()); +} exports.Handler = Handler; -var AsyncHandler = /** @class */ (function (_super) { - __extends(AsyncHandler, _super); - function AsyncHandler(payload, dependencies, asyncFunction) { - var _this = _super.call(this, payload, dependencies) || this; - _this.asyncFunction = asyncFunction; - _this.abortSignal = new abort_signal_1.AbortSignal(); - return _this; +class AsyncHandler extends Handler { + constructor(payload, dependencies, asyncFunction) { + super(payload, dependencies); + this.asyncFunction = asyncFunction; + this.abortSignal = new abort_signal_1.AbortSignal(); } - AsyncHandler.prototype.start = function () { - this.asyncFunction(this.payload, this.abortSignal, this.dependencies).catch(function (error) { - // console.log('Unhandled error:', error); - // swallow the error + start() { + this.asyncFunction(this.payload, this.abortSignal, this.dependencies).catch((error) => { }); - }; - AsyncHandler.prototype.cancel = function () { + } + cancel() { this.abortSignal.abort(); - }; - return AsyncHandler; -}(Handler)); -var asyncHandler = function (handlerFunction) { - return function (payload, dependencies) { - return new AsyncHandler(payload, dependencies, handlerFunction); - }; -}; + } +} +const asyncHandler = (handlerFunction) => (payload, dependencies) => new AsyncHandler(payload, dependencies, handlerFunction); exports.asyncHandler = asyncHandler; diff --git a/lib/event-engine/core/reconnectionDelay.js b/lib/event-engine/core/reconnectionDelay.js deleted file mode 100644 index e2078670a..000000000 --- a/lib/event-engine/core/reconnectionDelay.js +++ /dev/null @@ -1,27 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ReconnectionDelay = void 0; -var ReconnectionDelay = /** @class */ (function () { - function ReconnectionDelay() { - } - ReconnectionDelay.getDelay = function (policy, attempts, backoff) { - var backoffValue = backoff !== null && backoff !== void 0 ? backoff : 5; - switch (policy.toUpperCase()) { - case 'LINEAR': - return attempts * backoffValue + 200; - case 'EXPONENTIAL': - return Math.trunc(Math.pow(2, attempts - 1)) * 1000 + Math.random() * 1000; - default: - throw new Error('invalid policy'); - } - }; - ReconnectionDelay.shouldRetry = function (maxRetries, attempts, policy) { - // maxRetries > attempts && policy && policy != 'None'; - if (policy && policy !== 'None') { - return maxRetries > attempts; - } - return false; - }; - return ReconnectionDelay; -}()); -exports.ReconnectionDelay = ReconnectionDelay; diff --git a/lib/event-engine/core/retryPolicy.js b/lib/event-engine/core/retryPolicy.js index dde639271..a038d25c3 100644 --- a/lib/event-engine/core/retryPolicy.js +++ b/lib/event-engine/core/retryPolicy.js @@ -1,26 +1,24 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RetryPolicy = void 0; -var RetryPolicy = /** @class */ (function () { - function RetryPolicy() { - } - RetryPolicy.LinearRetryPolicy = function (configuration) { +class RetryPolicy { + static LinearRetryPolicy(configuration) { return { delay: configuration.delay, maximumRetry: configuration.maximumRetry, - shouldRetry: function (error, attempt) { + shouldRetry(error, attempt) { var _a; if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { return false; } return this.maximumRetry > attempt; }, - getDelay: function (_, reason) { + getDelay(_, reason) { var _a; - var delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : this.delay; + const delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : this.delay; return (delay + Math.random()) * 1000; }, - getGiveupReason: function (error, attempt) { + getGiveupReason(error, attempt) { var _a; if (this.maximumRetry <= attempt) { return 'retry attempts exhaused.'; @@ -30,37 +28,48 @@ var RetryPolicy = /** @class */ (function () { } return 'unknown error'; }, + validate() { + if (this.maximumRetry > 10) + throw new Error('Maximum retry for linear retry policy can not be more than 10'); + }, }; - }; - RetryPolicy.ExponentialRetryPolicy = function (configuration) { + } + static ExponentialRetryPolicy(configuration) { return { minimumDelay: configuration.minimumDelay, maximumDelay: configuration.maximumDelay, maximumRetry: configuration.maximumRetry, - shouldRetry: function (error, attempt) { + shouldRetry(reason, attempt) { var _a; - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { + if (((_a = reason === null || reason === void 0 ? void 0 : reason.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { return false; } return this.maximumRetry > attempt; }, - getDelay: function (attempt, reason) { + getDelay(attempt, reason) { var _a; - var delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : Math.min(Math.pow(2, attempt), this.maximumDelay); + const delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : Math.min(Math.pow(2, attempt), this.maximumDelay); return (delay + Math.random()) * 1000; }, - getGiveupReason: function (error, attempt) { + getGiveupReason(reason, attempt) { var _a; if (this.maximumRetry <= attempt) { - return 'retry attempts exhaused.'; + return 'retry attempts exhausted.'; } - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { + if (((_a = reason === null || reason === void 0 ? void 0 : reason.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { return 'forbidden operation.'; } return 'unknown error'; }, + validate() { + if (this.minimumDelay < 2) + throw new Error('Minimum delay can not be set less than 2 seconds for retry'); + else if (this.maximumDelay) + throw new Error('Maximum delay can not be set more than 150 seconds for retry'); + else if (this.maximumRetry > 6) + throw new Error('Maximum retry for exponential retry policy can not be more than 6'); + }, }; - }; - return RetryPolicy; -}()); + } +} exports.RetryPolicy = RetryPolicy; diff --git a/lib/event-engine/core/state.js b/lib/event-engine/core/state.js index 0e722a6a3..88c83cf6a 100644 --- a/lib/event-engine/core/state.js +++ b/lib/event-engine/core/state.js @@ -1,36 +1,34 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.State = void 0; -var State = /** @class */ (function () { - function State(label) { - this.label = label; - this.transitionMap = new Map(); - this.enterEffects = []; - this.exitEffects = []; - } - State.prototype.transition = function (context, event) { +class State { + transition(context, event) { var _a; if (this.transitionMap.has(event.type)) { return (_a = this.transitionMap.get(event.type)) === null || _a === void 0 ? void 0 : _a(context, event); } return undefined; - }; - State.prototype.on = function (eventType, transition) { + } + constructor(label) { + this.label = label; + this.transitionMap = new Map(); + this.enterEffects = []; + this.exitEffects = []; + } + on(eventType, transition) { this.transitionMap.set(eventType, transition); return this; - }; - State.prototype.with = function (context, effects) { + } + with(context, effects) { return [this, context, effects !== null && effects !== void 0 ? effects : []]; - }; - State.prototype.onEnter = function (effect) { + } + onEnter(effect) { this.enterEffects.push(effect); return this; - }; - State.prototype.onExit = function (effect) { + } + onExit(effect) { this.exitEffects.push(effect); return this; - }; - return State; -}()); + } +} exports.State = State; diff --git a/lib/event-engine/core/types.js b/lib/event-engine/core/types.js index d21b2facd..85dc4a919 100644 --- a/lib/event-engine/core/types.js +++ b/lib/event-engine/core/types.js @@ -1,41 +1,11 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.createManagedEffect = exports.createEffect = exports.createEvent = void 0; function createEvent(type, fn) { - var creator = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } + const creator = function (...args) { return { - type: type, - payload: fn === null || fn === void 0 ? void 0 : fn.apply(void 0, __spreadArray([], __read(args), false)), + type, + payload: fn === null || fn === void 0 ? void 0 : fn(...args), }; }; creator.type = type; @@ -43,24 +13,16 @@ function createEvent(type, fn) { } exports.createEvent = createEvent; function createEffect(type, fn) { - var creator = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return { type: type, payload: fn.apply(void 0, __spreadArray([], __read(args), false)), managed: false }; + const creator = (...args) => { + return { type, payload: fn(...args), managed: false }; }; creator.type = type; return creator; } exports.createEffect = createEffect; function createManagedEffect(type, fn) { - var creator = function () { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - return { type: type, payload: fn.apply(void 0, __spreadArray([], __read(args), false)), managed: true }; + const creator = (...args) => { + return { type, payload: fn(...args), managed: true }; }; creator.type = type; creator.cancel = { type: 'CANCEL', payload: type, managed: false }; diff --git a/lib/event-engine/dispatcher.js b/lib/event-engine/dispatcher.js index 27e5c02a9..c8e3c2ddb 100644 --- a/lib/event-engine/dispatcher.js +++ b/lib/event-engine/dispatcher.js @@ -1,30 +1,4 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -57,210 +31,116 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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) { + return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventEngineDispatcher = void 0; -var endpoint_1 = require("../core/components/endpoint"); -var core_1 = require("./core"); -var effects = __importStar(require("./effects")); -var events = __importStar(require("./events")); -var EventEngineDispatcher = /** @class */ (function (_super) { - __extends(EventEngineDispatcher, _super); - function EventEngineDispatcher(engine, dependencies) { - var _this = _super.call(this, dependencies) || this; - _this.on(effects.handshake.type, (0, core_1.asyncHandler)(function (payload, abortSignal, _a) { - var handshake = _a.handshake, presenceState = _a.presenceState, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, e_1; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - abortSignal.throwIfAborted(); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - return [4 /*yield*/, handshake(__assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState })))]; - case 2: - result = _b.sent(); - return [2 /*return*/, engine.transition(events.handshakeSuccess(result))]; - case 3: - e_1 = _b.sent(); - if (e_1 instanceof Error && e_1.message === 'Aborted') { - return [2 /*return*/]; - } - if (e_1 instanceof endpoint_1.PubNubError) { - return [2 /*return*/, engine.transition(events.handshakeFailure(e_1))]; - } - return [3 /*break*/, 4]; - case 4: return [2 /*return*/]; - } - }); - }); - })); - _this.on(effects.receiveMessages.type, (0, core_1.asyncHandler)(function (payload, abortSignal, _a) { - var receiveMessages = _a.receiveMessages, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, error_1; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - abortSignal.throwIfAborted(); - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - return [4 /*yield*/, receiveMessages({ - abortSignal: abortSignal, - channels: payload.channels, - channelGroups: payload.groups, - timetoken: payload.cursor.timetoken, - region: payload.cursor.region, - filterExpression: config.filterExpression, - })]; - case 2: - result = _b.sent(); - engine.transition(events.receiveSuccess(result.metadata, result.messages)); - return [3 /*break*/, 4]; - case 3: - error_1 = _b.sent(); - if (error_1 instanceof Error && error_1.message === 'Aborted') { - return [2 /*return*/]; - } - if (error_1 instanceof endpoint_1.PubNubError && !abortSignal.aborted) { - return [2 /*return*/, engine.transition(events.receiveFailure(error_1))]; - } - return [3 /*break*/, 4]; - case 4: return [2 /*return*/]; - } - }); - }); - })); - _this.on(effects.emitMessages.type, (0, core_1.asyncHandler)(function (payload, _, _a) { - var emitMessages = _a.emitMessages; - return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_b) { - if (payload.length > 0) { - emitMessages(payload); - } - return [2 /*return*/]; - }); - }); - })); - _this.on(effects.emitStatus.type, (0, core_1.asyncHandler)(function (payload, _, _a) { - var emitStatus = _a.emitStatus; - return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_b) { - emitStatus(payload); - return [2 /*return*/]; +const pubnub_error_1 = require("../errors/pubnub-error"); +const core_1 = require("./core"); +const effects = __importStar(require("./effects")); +const events = __importStar(require("./events")); +const categories_1 = __importDefault(require("../core/constants/categories")); +class EventEngineDispatcher extends core_1.Dispatcher { + constructor(engine, dependencies) { + super(dependencies); + this.on(effects.handshake.type, (0, core_1.asyncHandler)((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { handshake, presenceState, config }) { + abortSignal.throwIfAborted(); + try { + const result = yield handshake(Object.assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState }))); + return engine.transition(events.handshakeSuccess(result)); + } + catch (e) { + if (e instanceof pubnub_error_1.PubNubError) { + if (e.status && e.status.category == categories_1.default.PNCancelledCategory) + return; + return engine.transition(events.handshakeFailure(e)); + } + } + }))); + this.on(effects.receiveMessages.type, (0, core_1.asyncHandler)((payload_2, abortSignal_2, _b) => __awaiter(this, [payload_2, abortSignal_2, _b], void 0, function* (payload, abortSignal, { receiveMessages, config }) { + abortSignal.throwIfAborted(); + try { + const result = yield receiveMessages({ + abortSignal: abortSignal, + channels: payload.channels, + channelGroups: payload.groups, + timetoken: payload.cursor.timetoken, + region: payload.cursor.region, + filterExpression: config.filterExpression, }); - }); - })); - _this.on(effects.receiveReconnect.type, (0, core_1.asyncHandler)(function (payload, abortSignal, _a) { - var receiveMessages = _a.receiveMessages, delay = _a.delay, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, error_2; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!(config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts))) return [3 /*break*/, 6]; - abortSignal.throwIfAborted(); - return [4 /*yield*/, delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason))]; - case 1: - _b.sent(); - abortSignal.throwIfAborted(); - _b.label = 2; - case 2: - _b.trys.push([2, 4, , 5]); - return [4 /*yield*/, receiveMessages({ - abortSignal: abortSignal, - channels: payload.channels, - channelGroups: payload.groups, - timetoken: payload.cursor.timetoken, - region: payload.cursor.region, - filterExpression: config.filterExpression, - })]; - case 3: - result = _b.sent(); - return [2 /*return*/, engine.transition(events.receiveReconnectSuccess(result.metadata, result.messages))]; - case 4: - error_2 = _b.sent(); - if (error_2 instanceof Error && error_2.message === 'Aborted') { - return [2 /*return*/]; - } - if (error_2 instanceof endpoint_1.PubNubError) { - return [2 /*return*/, engine.transition(events.receiveReconnectFailure(error_2))]; - } - return [3 /*break*/, 5]; - case 5: return [3 /*break*/, 7]; - case 6: return [2 /*return*/, engine.transition(events.receiveReconnectGiveup(new endpoint_1.PubNubError(config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts))))]; - case 7: return [2 /*return*/]; + engine.transition(events.receiveSuccess(result.cursor, result.messages)); + } + catch (error) { + if (error instanceof pubnub_error_1.PubNubError) { + if (error.status && error.status.category == categories_1.default.PNCancelledCategory) + return; + if (!abortSignal.aborted) + return engine.transition(events.receiveFailure(error)); + } + } + }))); + this.on(effects.emitMessages.type, (0, core_1.asyncHandler)((payload_3, _1, _c) => __awaiter(this, [payload_3, _1, _c], void 0, function* (payload, _, { emitMessages }) { + if (payload.length > 0) { + emitMessages(payload); + } + }))); + this.on(effects.emitStatus.type, (0, core_1.asyncHandler)((payload_4, _2, _d) => __awaiter(this, [payload_4, _2, _d], void 0, function* (payload, _, { emitStatus }) { + emitStatus(payload); + }))); + this.on(effects.receiveReconnect.type, (0, core_1.asyncHandler)((payload_5, abortSignal_3, _e) => __awaiter(this, [payload_5, abortSignal_3, _e], void 0, function* (payload, abortSignal, { receiveMessages, delay, config }) { + if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { + abortSignal.throwIfAborted(); + yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); + abortSignal.throwIfAborted(); + try { + const result = yield receiveMessages({ + abortSignal: abortSignal, + channels: payload.channels, + channelGroups: payload.groups, + timetoken: payload.cursor.timetoken, + region: payload.cursor.region, + filterExpression: config.filterExpression, + }); + return engine.transition(events.receiveReconnectSuccess(result.cursor, result.messages)); + } + catch (error) { + if (error instanceof pubnub_error_1.PubNubError) { + if (error.status && error.status.category == categories_1.default.PNCancelledCategory) + return; + return engine.transition(events.receiveReconnectFailure(error)); } - }); - }); - })); - _this.on(effects.handshakeReconnect.type, (0, core_1.asyncHandler)(function (payload, abortSignal, _a) { - var handshake = _a.handshake, delay = _a.delay, presenceState = _a.presenceState, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, error_3; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!(config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts))) return [3 /*break*/, 6]; - abortSignal.throwIfAborted(); - return [4 /*yield*/, delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason))]; - case 1: - _b.sent(); - abortSignal.throwIfAborted(); - _b.label = 2; - case 2: - _b.trys.push([2, 4, , 5]); - return [4 /*yield*/, handshake(__assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState })))]; - case 3: - result = _b.sent(); - return [2 /*return*/, engine.transition(events.handshakeReconnectSuccess(result))]; - case 4: - error_3 = _b.sent(); - if (error_3 instanceof Error && error_3.message === 'Aborted') { - return [2 /*return*/]; - } - if (error_3 instanceof endpoint_1.PubNubError) { - return [2 /*return*/, engine.transition(events.handshakeReconnectFailure(error_3))]; - } - return [3 /*break*/, 5]; - case 5: return [3 /*break*/, 7]; - case 6: return [2 /*return*/, engine.transition(events.handshakeReconnectGiveup(new endpoint_1.PubNubError(config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts))))]; - case 7: return [2 /*return*/]; + } + } + else { + return engine.transition(events.receiveReconnectGiveup(new pubnub_error_1.PubNubError(config.retryConfiguration + ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) + : 'Unable to complete subscribe messages receive.'))); + } + }))); + this.on(effects.handshakeReconnect.type, (0, core_1.asyncHandler)((payload_6, abortSignal_4, _f) => __awaiter(this, [payload_6, abortSignal_4, _f], void 0, function* (payload, abortSignal, { handshake, delay, presenceState, config }) { + if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { + abortSignal.throwIfAborted(); + yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); + abortSignal.throwIfAborted(); + try { + const result = yield handshake(Object.assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState }))); + return engine.transition(events.handshakeReconnectSuccess(result)); + } + catch (error) { + if (error instanceof pubnub_error_1.PubNubError) { + if (error.status && error.status.category == categories_1.default.PNCancelledCategory) + return; + return engine.transition(events.handshakeReconnectFailure(error)); } - }); - }); - })); - return _this; + } + } + else { + return engine.transition(events.handshakeReconnectGiveup(new pubnub_error_1.PubNubError(config.retryConfiguration + ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) + : 'Unable to complete subscribe handshake'))); + } + }))); } - return EventEngineDispatcher; -}(core_1.Dispatcher)); +} exports.EventEngineDispatcher = EventEngineDispatcher; diff --git a/lib/event-engine/effects.js b/lib/event-engine/effects.js index 2b5ead623..2c788f77c 100644 --- a/lib/event-engine/effects.js +++ b/lib/event-engine/effects.js @@ -1,13 +1,13 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handshakeReconnect = exports.receiveReconnect = exports.emitStatus = exports.emitMessages = exports.receiveMessages = exports.handshake = void 0; -var core_1 = require("./core"); -exports.handshake = (0, core_1.createManagedEffect)('HANDSHAKE', function (channels, groups) { return ({ - channels: channels, - groups: groups, -}); }); -exports.receiveMessages = (0, core_1.createManagedEffect)('RECEIVE_MESSAGES', function (channels, groups, cursor) { return ({ channels: channels, groups: groups, cursor: cursor }); }); -exports.emitMessages = (0, core_1.createEffect)('EMIT_MESSAGES', function (events) { return events; }); -exports.emitStatus = (0, core_1.createEffect)('EMIT_STATUS', function (status) { return status; }); -exports.receiveReconnect = (0, core_1.createManagedEffect)('RECEIVE_RECONNECT', function (context) { return context; }); -exports.handshakeReconnect = (0, core_1.createManagedEffect)('HANDSHAKE_RECONNECT', function (context) { return context; }); +const core_1 = require("./core"); +exports.handshake = (0, core_1.createManagedEffect)('HANDSHAKE', (channels, groups) => ({ + channels, + groups, +})); +exports.receiveMessages = (0, core_1.createManagedEffect)('RECEIVE_MESSAGES', (channels, groups, cursor) => ({ channels, groups, cursor })); +exports.emitMessages = (0, core_1.createEffect)('EMIT_MESSAGES', (events) => events); +exports.emitStatus = (0, core_1.createEffect)('EMIT_STATUS', (status) => status); +exports.receiveReconnect = (0, core_1.createManagedEffect)('RECEIVE_RECONNECT', (context) => context); +exports.handshakeReconnect = (0, core_1.createManagedEffect)('HANDSHAKE_RECONNECT', (context) => context); diff --git a/lib/event-engine/events.js b/lib/event-engine/events.js index bcea70719..3725ca704 100644 --- a/lib/event-engine/events.js +++ b/lib/event-engine/events.js @@ -1,42 +1,42 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unsubscribeAll = exports.reconnect = exports.disconnect = exports.receiveReconnectGiveup = exports.receiveReconnectFailure = exports.receiveReconnectSuccess = exports.receiveFailure = exports.receiveSuccess = exports.handshakeReconnectGiveup = exports.handshakeReconnectFailure = exports.handshakeReconnectSuccess = exports.handshakeFailure = exports.handshakeSuccess = exports.restore = exports.subscriptionChange = void 0; -var core_1 = require("./core"); -exports.subscriptionChange = (0, core_1.createEvent)('SUBSCRIPTION_CHANGED', function (channels, groups) { return ({ - channels: channels, - groups: groups, -}); }); -exports.restore = (0, core_1.createEvent)('SUBSCRIPTION_RESTORED', function (channels, groups, timetoken, region) { return ({ - channels: channels, - groups: groups, +const core_1 = require("./core"); +exports.subscriptionChange = (0, core_1.createEvent)('SUBSCRIPTION_CHANGED', (channels, groups) => ({ + channels, + groups, +})); +exports.restore = (0, core_1.createEvent)('SUBSCRIPTION_RESTORED', (channels, groups, timetoken, region) => ({ + channels, + groups, cursor: { timetoken: timetoken, region: region !== null && region !== void 0 ? region : 0, }, -}); }); -exports.handshakeSuccess = (0, core_1.createEvent)('HANDSHAKE_SUCCESS', function (cursor) { return cursor; }); -exports.handshakeFailure = (0, core_1.createEvent)('HANDSHAKE_FAILURE', function (error) { return error; }); -exports.handshakeReconnectSuccess = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_SUCCESS', function (cursor) { return ({ - cursor: cursor, -}); }); -exports.handshakeReconnectFailure = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_FAILURE', function (error) { return error; }); -exports.handshakeReconnectGiveup = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_GIVEUP', function (error) { return error; }); -exports.receiveSuccess = (0, core_1.createEvent)('RECEIVE_SUCCESS', function (cursor, events) { return ({ - cursor: cursor, - events: events, -}); }); -exports.receiveFailure = (0, core_1.createEvent)('RECEIVE_FAILURE', function (error) { return error; }); -exports.receiveReconnectSuccess = (0, core_1.createEvent)('RECEIVE_RECONNECT_SUCCESS', function (cursor, events) { return ({ - cursor: cursor, - events: events, -}); }); -exports.receiveReconnectFailure = (0, core_1.createEvent)('RECEIVE_RECONNECT_FAILURE', function (error) { return error; }); -exports.receiveReconnectGiveup = (0, core_1.createEvent)('RECEIVING_RECONNECT_GIVEUP', function (error) { return error; }); -exports.disconnect = (0, core_1.createEvent)('DISCONNECT', function () { return ({}); }); -exports.reconnect = (0, core_1.createEvent)('RECONNECT', function (timetoken, region) { return ({ +})); +exports.handshakeSuccess = (0, core_1.createEvent)('HANDSHAKE_SUCCESS', (cursor) => cursor); +exports.handshakeFailure = (0, core_1.createEvent)('HANDSHAKE_FAILURE', (error) => error); +exports.handshakeReconnectSuccess = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_SUCCESS', (cursor) => ({ + cursor, +})); +exports.handshakeReconnectFailure = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_FAILURE', (error) => error); +exports.handshakeReconnectGiveup = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_GIVEUP', (error) => error); +exports.receiveSuccess = (0, core_1.createEvent)('RECEIVE_SUCCESS', (cursor, events) => ({ + cursor, + events, +})); +exports.receiveFailure = (0, core_1.createEvent)('RECEIVE_FAILURE', (error) => error); +exports.receiveReconnectSuccess = (0, core_1.createEvent)('RECEIVE_RECONNECT_SUCCESS', (cursor, events) => ({ + cursor, + events, +})); +exports.receiveReconnectFailure = (0, core_1.createEvent)('RECEIVE_RECONNECT_FAILURE', (error) => error); +exports.receiveReconnectGiveup = (0, core_1.createEvent)('RECEIVING_RECONNECT_GIVEUP', (error) => error); +exports.disconnect = (0, core_1.createEvent)('DISCONNECT', () => ({})); +exports.reconnect = (0, core_1.createEvent)('RECONNECT', (timetoken, region) => ({ cursor: { timetoken: timetoken !== null && timetoken !== void 0 ? timetoken : '', region: region !== null && region !== void 0 ? region : 0, }, -}); }); -exports.unsubscribeAll = (0, core_1.createEvent)('UNSUBSCRIBE_ALL', function () { return ({}); }); +})); +exports.unsubscribeAll = (0, core_1.createEvent)('UNSUBSCRIBE_ALL', () => ({})); diff --git a/lib/event-engine/index.js b/lib/event-engine/index.js index 2dcdfa1bd..fd48c7427 100644 --- a/lib/event-engine/index.js +++ b/lib/event-engine/index.js @@ -22,94 +22,66 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.EventEngine = void 0; -var core_1 = require("./core"); -var dispatcher_1 = require("./dispatcher"); -var events = __importStar(require("./events")); -var unsubscribed_1 = require("./states/unsubscribed"); -var utils = __importStar(require("../core/utils")); -var EventEngine = /** @class */ (function () { - function EventEngine(dependencies) { - var _this = this; +const core_1 = require("./core"); +const dispatcher_1 = require("./dispatcher"); +const events = __importStar(require("./events")); +const unsubscribed_1 = require("./states/unsubscribed"); +const utils = __importStar(require("../core/utils")); +class EventEngine { + get _engine() { + return this.engine; + } + constructor(dependencies) { this.engine = new core_1.Engine(); this.channels = []; this.groups = []; this.dependencies = dependencies; this.dispatcher = new dispatcher_1.EventEngineDispatcher(this.engine, dependencies); - this._unsubscribeEngine = this.engine.subscribe(function (change) { + this._unsubscribeEngine = this.engine.subscribe((change) => { if (change.type === 'invocationDispatched') { - _this.dispatcher.dispatch(change.invocation); + this.dispatcher.dispatch(change.invocation); } }); this.engine.start(unsubscribed_1.UnsubscribedState, undefined); } - Object.defineProperty(EventEngine.prototype, "_engine", { - get: function () { - return this.engine; - }, - enumerable: false, - configurable: true - }); - EventEngine.prototype.subscribe = function (_a) { - var _this = this; - var channels = _a.channels, channelGroups = _a.channelGroups, timetoken = _a.timetoken, withPresence = _a.withPresence; - this.channels = __spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false); - this.groups = __spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false); + subscribe({ channels, channelGroups, timetoken, withPresence, }) { + this.channels = [...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])]; + this.groups = [...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])]; if (withPresence) { - this.channels.map(function (c) { return _this.channels.push("".concat(c, "-pnpres")); }); - this.groups.map(function (g) { return _this.groups.push("".concat(g, "-pnpres")); }); + this.channels.map((c) => this.channels.push(`${c}-pnpres`)); + this.groups.map((g) => this.groups.push(`${g}-pnpres`)); } if (timetoken) { - this.engine.transition(events.restore(Array.from(new Set(__spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false))), timetoken)); + this.engine.transition(events.restore(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])])), timetoken)); } else { - this.engine.transition(events.subscriptionChange(Array.from(new Set(__spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false))), Array.from(new Set(__spreadArray(__spreadArray([], __read(this.groups), false), __read((channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])), false))))); + this.engine.transition(events.subscriptionChange(Array.from(new Set([...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])])), Array.from(new Set([...this.groups, ...(channelGroups !== null && channelGroups !== void 0 ? channelGroups : [])])))); } if (this.dependencies.join) { this.dependencies.join({ - channels: Array.from(new Set(this.channels.filter(function (c) { return !c.endsWith('-pnpres'); }))), - groups: Array.from(new Set(this.groups.filter(function (g) { return !g.endsWith('-pnpres'); }))), + channels: Array.from(new Set(this.channels.filter((c) => !c.endsWith('-pnpres')))), + groups: Array.from(new Set(this.groups.filter((g) => !g.endsWith('-pnpres')))), }); } - }; - EventEngine.prototype.unsubscribe = function (_a) { - var _this = this; - var _b = _a.channels, channels = _b === void 0 ? [] : _b, _c = _a.channelGroups, channelGroups = _c === void 0 ? [] : _c; - var filteredChannels = utils.removeSingleOccurance(this.channels, __spreadArray(__spreadArray([], __read(channels), false), __read(channels.map(function (c) { return "".concat(c, "-pnpres"); })), false)); - var filteredGroups = utils.removeSingleOccurance(this.groups, __spreadArray(__spreadArray([], __read(channelGroups), false), __read(channelGroups.map(function (c) { return "".concat(c, "-pnpres"); })), false)); + } + unsubscribe({ channels = [], channelGroups = [] }) { + const filteredChannels = utils.removeSingleOccurance(this.channels, [ + ...channels, + ...channels.map((c) => `${c}-pnpres`), + ]); + const filteredGroups = utils.removeSingleOccurance(this.groups, [ + ...channelGroups, + ...channelGroups.map((c) => `${c}-pnpres`), + ]); if (new Set(this.channels).size !== new Set(filteredChannels).size || new Set(this.groups).size !== new Set(filteredGroups).size) { - var channelsToLeave = utils.findUniqueCommonElements(this.channels, channels); - var groupstoLeave = utils.findUniqueCommonElements(this.groups, channelGroups); + const channelsToLeave = utils.findUniqueCommonElements(this.channels, channels); + const groupstoLeave = utils.findUniqueCommonElements(this.groups, channelGroups); if (this.dependencies.presenceState) { - channelsToLeave === null || channelsToLeave === void 0 ? void 0 : channelsToLeave.forEach(function (c) { return delete _this.dependencies.presenceState[c]; }); - groupstoLeave === null || groupstoLeave === void 0 ? void 0 : groupstoLeave.forEach(function (g) { return delete _this.dependencies.presenceState[g]; }); + channelsToLeave === null || channelsToLeave === void 0 ? void 0 : channelsToLeave.forEach((c) => delete this.dependencies.presenceState[c]); + groupstoLeave === null || groupstoLeave === void 0 ? void 0 : groupstoLeave.forEach((g) => delete this.dependencies.presenceState[g]); } this.channels = filteredChannels; this.groups = filteredGroups; @@ -121,39 +93,39 @@ var EventEngine = /** @class */ (function () { }); } } - }; - EventEngine.prototype.unsubscribeAll = function () { + } + unsubscribeAll() { this.channels = []; this.groups = []; if (this.dependencies.presenceState) { - this.dependencies.presenceState = {}; + Object.keys(this.dependencies.presenceState).forEach((objectName) => { + delete this.dependencies.presenceState[objectName]; + }); } this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0))); if (this.dependencies.leaveAll) { this.dependencies.leaveAll(); } - }; - EventEngine.prototype.reconnect = function (_a) { - var timetoken = _a.timetoken, region = _a.region; + } + reconnect({ timetoken, region }) { this.engine.transition(events.reconnect(timetoken, region)); - }; - EventEngine.prototype.disconnect = function () { + } + disconnect() { this.engine.transition(events.disconnect()); if (this.dependencies.leaveAll) { this.dependencies.leaveAll(); } - }; - EventEngine.prototype.getSubscribedChannels = function () { - return Array.from(new Set(this.channels)); - }; - EventEngine.prototype.getSubscribedChannelGroups = function () { - return Array.from(new Set(this.groups)); - }; - EventEngine.prototype.dispose = function () { + } + getSubscribedChannels() { + return Array.from(new Set(this.channels.slice(0))); + } + getSubscribedChannelGroups() { + return Array.from(new Set(this.groups.slice(0))); + } + dispose() { this.disconnect(); this._unsubscribeEngine(); this.dispatcher.dispose(); - }; - return EventEngine; -}()); + } +} exports.EventEngine = EventEngine; diff --git a/lib/event-engine/presence/dispatcher.js b/lib/event-engine/presence/dispatcher.js index 2b79f44eb..e38d0f967 100644 --- a/lib/event-engine/presence/dispatcher.js +++ b/lib/event-engine/presence/dispatcher.js @@ -1,30 +1,4 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -57,166 +31,80 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PresenceEventEngineDispatcher = void 0; -var endpoint_1 = require("../../core/components/endpoint"); -var core_1 = require("../core"); -var operations_1 = __importDefault(require("../../core/constants/operations")); -var effects = __importStar(require("./effects")); -var events = __importStar(require("./events")); -var PresenceEventEngineDispatcher = /** @class */ (function (_super) { - __extends(PresenceEventEngineDispatcher, _super); - function PresenceEventEngineDispatcher(engine, dependencies) { - var _this = _super.call(this, dependencies) || this; - _this.on(effects.heartbeat.type, (0, core_1.asyncHandler)(function (payload, _, _a) { - var heartbeat = _a.heartbeat, presenceState = _a.presenceState, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, e_1; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - _b.trys.push([0, 2, , 3]); - return [4 /*yield*/, heartbeat(__assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })))]; - case 1: - result = _b.sent(); - engine.transition(events.heartbeatSuccess(200)); - return [3 /*break*/, 3]; - case 2: - e_1 = _b.sent(); - if (e_1 instanceof endpoint_1.PubNubError) { - return [2 /*return*/, engine.transition(events.heartbeatFailure(e_1))]; - } - return [3 /*break*/, 3]; - case 3: return [2 /*return*/]; - } - }); - }); - })); - _this.on(effects.leave.type, (0, core_1.asyncHandler)(function (payload, _, _a) { - var leave = _a.leave, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, e_2; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!!config.suppressLeaveEvents) return [3 /*break*/, 4]; - _b.label = 1; - case 1: - _b.trys.push([1, 3, , 4]); - return [4 /*yield*/, leave({ - channels: payload.channels, - channelGroups: payload.groups, - })]; - case 2: - result = _b.sent(); - return [3 /*break*/, 4]; - case 3: - e_2 = _b.sent(); - return [3 /*break*/, 4]; - case 4: return [2 /*return*/]; - } - }); - }); - })); - _this.on(effects.wait.type, (0, core_1.asyncHandler)(function (_, abortSignal, _a) { - var heartbeatDelay = _a.heartbeatDelay; - return __awaiter(_this, void 0, void 0, function () { - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - abortSignal.throwIfAborted(); - return [4 /*yield*/, heartbeatDelay()]; - case 1: - _b.sent(); - abortSignal.throwIfAborted(); - return [2 /*return*/, engine.transition(events.timesUp())]; - } - }); - }); - })); - _this.on(effects.delayedHeartbeat.type, (0, core_1.asyncHandler)(function (payload, abortSignal, _a) { - var heartbeat = _a.heartbeat, retryDelay = _a.retryDelay, presenceState = _a.presenceState, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var result, e_3; - return __generator(this, function (_b) { - switch (_b.label) { - case 0: - if (!(config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts))) return [3 /*break*/, 6]; - abortSignal.throwIfAborted(); - return [4 /*yield*/, retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason))]; - case 1: - _b.sent(); - abortSignal.throwIfAborted(); - _b.label = 2; - case 2: - _b.trys.push([2, 4, , 5]); - return [4 /*yield*/, heartbeat(__assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })))]; - case 3: - result = _b.sent(); - return [2 /*return*/, engine.transition(events.heartbeatSuccess(200))]; - case 4: - e_3 = _b.sent(); - if (e_3 instanceof Error && e_3.message === 'Aborted') { - return [2 /*return*/]; - } - if (e_3 instanceof endpoint_1.PubNubError) { - return [2 /*return*/, engine.transition(events.heartbeatFailure(e_3))]; - } - return [3 /*break*/, 5]; - case 5: return [3 /*break*/, 7]; - case 6: return [2 /*return*/, engine.transition(events.heartbeatGiveup())]; - case 7: return [2 /*return*/]; - } - }); - }); - })); - _this.on(effects.emitStatus.type, (0, core_1.asyncHandler)(function (payload, _, _a) { - var emitStatus = _a.emitStatus, config = _a.config; - return __awaiter(_this, void 0, void 0, function () { - var _b; - return __generator(this, function (_c) { - if (config.announceFailedHeartbeats && ((_b = payload === null || payload === void 0 ? void 0 : payload.status) === null || _b === void 0 ? void 0 : _b.error) === true) { - emitStatus(payload.status); - } - else if (config.announceSuccessfulHeartbeats && payload.statusCode === 200) { - emitStatus(__assign(__assign({}, payload), { operation: operations_1.default.PNHeartbeatOperation, error: false })); +const core_1 = require("../core"); +const operations_1 = __importDefault(require("../../core/constants/operations")); +const pubnub_error_1 = require("../../errors/pubnub-error"); +const effects = __importStar(require("./effects")); +const events = __importStar(require("./events")); +const categories_1 = __importDefault(require("../../core/constants/categories")); +class PresenceEventEngineDispatcher extends core_1.Dispatcher { + constructor(engine, dependencies) { + super(dependencies); + this.on(effects.heartbeat.type, (0, core_1.asyncHandler)((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { heartbeat, presenceState, config }) { + try { + const result = yield heartbeat(Object.assign(Object.assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })), { heartbeat: config.presenceTimeout })); + engine.transition(events.heartbeatSuccess(200)); + } + catch (e) { + if (e instanceof pubnub_error_1.PubNubError) { + if (e.status && e.status.category == categories_1.default.PNCancelledCategory) + return; + return engine.transition(events.heartbeatFailure(e)); + } + } + }))); + this.on(effects.leave.type, (0, core_1.asyncHandler)((payload_2, _2, _b) => __awaiter(this, [payload_2, _2, _b], void 0, function* (payload, _, { leave, config }) { + if (!config.suppressLeaveEvents) { + try { + leave({ + channels: payload.channels, + channelGroups: payload.groups, + }); + } + catch (e) { } + } + }))); + this.on(effects.wait.type, (0, core_1.asyncHandler)((_3, abortSignal_1, _c) => __awaiter(this, [_3, abortSignal_1, _c], void 0, function* (_, abortSignal, { heartbeatDelay }) { + abortSignal.throwIfAborted(); + yield heartbeatDelay(); + abortSignal.throwIfAborted(); + return engine.transition(events.timesUp()); + }))); + this.on(effects.delayedHeartbeat.type, (0, core_1.asyncHandler)((payload_3, abortSignal_2, _d) => __awaiter(this, [payload_3, abortSignal_2, _d], void 0, function* (payload, abortSignal, { heartbeat, retryDelay, presenceState, config }) { + if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { + abortSignal.throwIfAborted(); + yield retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); + abortSignal.throwIfAborted(); + try { + const result = yield heartbeat(Object.assign(Object.assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })), { heartbeat: config.presenceTimeout })); + return engine.transition(events.heartbeatSuccess(200)); + } + catch (e) { + if (e instanceof pubnub_error_1.PubNubError) { + if (e.status && e.status.category == categories_1.default.PNCancelledCategory) + return; + return engine.transition(events.heartbeatFailure(e)); } - return [2 /*return*/]; - }); - }); - })); - return _this; + } + } + else { + return engine.transition(events.heartbeatGiveup()); + } + }))); + this.on(effects.emitStatus.type, (0, core_1.asyncHandler)((payload_4, _4, _e) => __awaiter(this, [payload_4, _4, _e], void 0, function* (payload, _, { emitStatus, config }) { + var _f; + if (config.announceFailedHeartbeats && ((_f = payload === null || payload === void 0 ? void 0 : payload.status) === null || _f === void 0 ? void 0 : _f.error) === true) { + emitStatus(payload.status); + } + else if (config.announceSuccessfulHeartbeats && payload.statusCode === 200) { + emitStatus(Object.assign(Object.assign({}, payload), { operation: operations_1.default.PNHeartbeatOperation, error: false })); + } + }))); } - return PresenceEventEngineDispatcher; -}(core_1.Dispatcher)); +} exports.PresenceEventEngineDispatcher = PresenceEventEngineDispatcher; diff --git a/lib/event-engine/presence/effects.js b/lib/event-engine/presence/effects.js index 3e6dd2887..beab7cbc6 100644 --- a/lib/event-engine/presence/effects.js +++ b/lib/event-engine/presence/effects.js @@ -1,15 +1,15 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.delayedHeartbeat = exports.wait = exports.emitStatus = exports.leave = exports.heartbeat = void 0; -var core_1 = require("../core"); -exports.heartbeat = (0, core_1.createEffect)('HEARTBEAT', function (channels, groups) { return ({ - channels: channels, - groups: groups, -}); }); -exports.leave = (0, core_1.createEffect)('LEAVE', function (channels, groups) { return ({ - channels: channels, - groups: groups, -}); }); -exports.emitStatus = (0, core_1.createEffect)('EMIT_STATUS', function (status) { return status; }); -exports.wait = (0, core_1.createManagedEffect)('WAIT', function () { return ({}); }); -exports.delayedHeartbeat = (0, core_1.createManagedEffect)('DELAYED_HEARTBEAT', function (context) { return context; }); +const core_1 = require("../core"); +exports.heartbeat = (0, core_1.createEffect)('HEARTBEAT', (channels, groups) => ({ + channels, + groups, +})); +exports.leave = (0, core_1.createEffect)('LEAVE', (channels, groups) => ({ + channels, + groups, +})); +exports.emitStatus = (0, core_1.createEffect)('EMIT_STATUS', (status) => status); +exports.wait = (0, core_1.createManagedEffect)('WAIT', () => ({})); +exports.delayedHeartbeat = (0, core_1.createManagedEffect)('DELAYED_HEARTBEAT', (context) => context); diff --git a/lib/event-engine/presence/events.js b/lib/event-engine/presence/events.js index cca3e9a06..58bdd3e8c 100644 --- a/lib/event-engine/presence/events.js +++ b/lib/event-engine/presence/events.js @@ -1,19 +1,19 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.timesUp = exports.heartbeatGiveup = exports.heartbeatFailure = exports.heartbeatSuccess = exports.leftAll = exports.left = exports.joined = exports.disconnect = exports.reconnect = void 0; -var core_1 = require("../core"); -exports.reconnect = (0, core_1.createEvent)('RECONNECT', function () { return ({}); }); -exports.disconnect = (0, core_1.createEvent)('DISCONNECT', function () { return ({}); }); -exports.joined = (0, core_1.createEvent)('JOINED', function (channels, groups) { return ({ - channels: channels, - groups: groups, -}); }); -exports.left = (0, core_1.createEvent)('LEFT', function (channels, groups) { return ({ - channels: channels, - groups: groups, -}); }); -exports.leftAll = (0, core_1.createEvent)('LEFT_ALL', function () { return ({}); }); -exports.heartbeatSuccess = (0, core_1.createEvent)('HEARTBEAT_SUCCESS', function (statusCode) { return ({ statusCode: statusCode }); }); -exports.heartbeatFailure = (0, core_1.createEvent)('HEARTBEAT_FAILURE', function (error) { return error; }); -exports.heartbeatGiveup = (0, core_1.createEvent)('HEARTBEAT_GIVEUP', function () { return ({}); }); -exports.timesUp = (0, core_1.createEvent)('TIMES_UP', function () { return ({}); }); +const core_1 = require("../core"); +exports.reconnect = (0, core_1.createEvent)('RECONNECT', () => ({})); +exports.disconnect = (0, core_1.createEvent)('DISCONNECT', () => ({})); +exports.joined = (0, core_1.createEvent)('JOINED', (channels, groups) => ({ + channels, + groups, +})); +exports.left = (0, core_1.createEvent)('LEFT', (channels, groups) => ({ + channels, + groups, +})); +exports.leftAll = (0, core_1.createEvent)('LEFT_ALL', () => ({})); +exports.heartbeatSuccess = (0, core_1.createEvent)('HEARTBEAT_SUCCESS', (statusCode) => ({ statusCode })); +exports.heartbeatFailure = (0, core_1.createEvent)('HEARTBEAT_FAILURE', (error) => error); +exports.heartbeatGiveup = (0, core_1.createEvent)('HEARTBEAT_GIVEUP', () => ({})); +exports.timesUp = (0, core_1.createEvent)('TIMES_UP', () => ({})); diff --git a/lib/event-engine/presence/presence.js b/lib/event-engine/presence/presence.js index 40c6c11f3..fbfa7c939 100644 --- a/lib/event-engine/presence/presence.js +++ b/lib/event-engine/presence/presence.js @@ -22,81 +22,47 @@ var __importStar = (this && this.__importStar) || function (mod) { __setModuleDefault(result, mod); return result; }; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.PresenceEventEngine = void 0; -var core_1 = require("../core"); -var events = __importStar(require("./events")); -var dispatcher_1 = require("./dispatcher"); -var heartbeat_inactive_1 = require("./states/heartbeat_inactive"); -var PresenceEventEngine = /** @class */ (function () { - function PresenceEventEngine(dependencies) { - var _this = this; +const core_1 = require("../core"); +const events = __importStar(require("./events")); +const dispatcher_1 = require("./dispatcher"); +const heartbeat_inactive_1 = require("./states/heartbeat_inactive"); +class PresenceEventEngine { + get _engine() { + return this.engine; + } + constructor(dependencies) { + this.dependencies = dependencies; this.engine = new core_1.Engine(); this.channels = []; this.groups = []; this.dispatcher = new dispatcher_1.PresenceEventEngineDispatcher(this.engine, dependencies); - this.dependencies = dependencies; - this._unsubscribeEngine = this.engine.subscribe(function (change) { + this._unsubscribeEngine = this.engine.subscribe((change) => { if (change.type === 'invocationDispatched') { - _this.dispatcher.dispatch(change.invocation); + this.dispatcher.dispatch(change.invocation); } }); this.engine.start(heartbeat_inactive_1.HeartbeatInactiveState, undefined); } - Object.defineProperty(PresenceEventEngine.prototype, "_engine", { - get: function () { - return this.engine; - }, - enumerable: false, - configurable: true - }); - PresenceEventEngine.prototype.join = function (_a) { - var channels = _a.channels, groups = _a.groups; - this.channels = __spreadArray(__spreadArray([], __read(this.channels), false), __read((channels !== null && channels !== void 0 ? channels : [])), false); - this.groups = __spreadArray(__spreadArray([], __read(this.groups), false), __read((groups !== null && groups !== void 0 ? groups : [])), false); + join({ channels, groups }) { + this.channels = [...this.channels, ...(channels !== null && channels !== void 0 ? channels : [])]; + this.groups = [...this.groups, ...(groups !== null && groups !== void 0 ? groups : [])]; this.engine.transition(events.joined(this.channels.slice(0), this.groups.slice(0))); - }; - PresenceEventEngine.prototype.leave = function (_a) { - var _this = this; - var channels = _a.channels, groups = _a.groups; + } + leave({ channels, groups }) { if (this.dependencies.presenceState) { - channels === null || channels === void 0 ? void 0 : channels.forEach(function (c) { return delete _this.dependencies.presenceState[c]; }); - groups === null || groups === void 0 ? void 0 : groups.forEach(function (g) { return delete _this.dependencies.presenceState[g]; }); + channels === null || channels === void 0 ? void 0 : channels.forEach((c) => delete this.dependencies.presenceState[c]); + groups === null || groups === void 0 ? void 0 : groups.forEach((g) => delete this.dependencies.presenceState[g]); } this.engine.transition(events.left(channels !== null && channels !== void 0 ? channels : [], groups !== null && groups !== void 0 ? groups : [])); - }; - PresenceEventEngine.prototype.leaveAll = function () { + } + leaveAll() { this.engine.transition(events.leftAll()); - }; - PresenceEventEngine.prototype.dispose = function () { + } + dispose() { this._unsubscribeEngine(); this.dispatcher.dispose(); - }; - return PresenceEventEngine; -}()); + } +} exports.PresenceEventEngine = PresenceEventEngine; diff --git a/lib/event-engine/presence/states/heartbeat_cooldown.js b/lib/event-engine/presence/states/heartbeat_cooldown.js index 0ee9ba6ef..5dd1a1b8d 100644 --- a/lib/event-engine/presence/states/heartbeat_cooldown.js +++ b/lib/event-engine/presence/states/heartbeat_cooldown.js @@ -1,64 +1,29 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatCooldownState = void 0; -var state_1 = require("../../core/state"); -var events_1 = require("../events"); -var effects_1 = require("../effects"); -var heartbeating_1 = require("./heartbeating"); -var heartbeat_stopped_1 = require("./heartbeat_stopped"); -var heartbeat_inactive_1 = require("./heartbeat_inactive"); +const state_1 = require("../../core/state"); +const events_1 = require("../events"); +const effects_1 = require("../effects"); +const heartbeating_1 = require("./heartbeating"); +const heartbeat_stopped_1 = require("./heartbeat_stopped"); +const heartbeat_inactive_1 = require("./heartbeat_inactive"); exports.HeartbeatCooldownState = new state_1.State('HEARTBEAT_COOLDOWN'); -exports.HeartbeatCooldownState.onEnter(function () { return (0, effects_1.wait)(); }); -exports.HeartbeatCooldownState.onExit(function () { return effects_1.wait.cancel; }); -exports.HeartbeatCooldownState.on(events_1.timesUp.type, function (context, _) { - return heartbeating_1.HeartbeatingState.with({ - channels: context.channels, - groups: context.groups, - }); -}); -exports.HeartbeatCooldownState.on(events_1.joined.type, function (context, event) { - return heartbeating_1.HeartbeatingState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), - }); -}); -exports.HeartbeatCooldownState.on(events_1.left.type, function (context, event) { - return heartbeating_1.HeartbeatingState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), - }, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)]); -}); -exports.HeartbeatCooldownState.on(events_1.disconnect.type, function (context) { - return heartbeat_stopped_1.HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [(0, effects_1.leave)(context.channels, context.groups)]); -}); -exports.HeartbeatCooldownState.on(events_1.leftAll.type, function (context, _) { - return heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)]); -}); +exports.HeartbeatCooldownState.onEnter(() => (0, effects_1.wait)()); +exports.HeartbeatCooldownState.onExit(() => effects_1.wait.cancel); +exports.HeartbeatCooldownState.on(events_1.timesUp.type, (context, _) => heartbeating_1.HeartbeatingState.with({ + channels: context.channels, + groups: context.groups, +})); +exports.HeartbeatCooldownState.on(events_1.joined.type, (context, event) => heartbeating_1.HeartbeatingState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], +})); +exports.HeartbeatCooldownState.on(events_1.left.type, (context, event) => heartbeating_1.HeartbeatingState.with({ + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), +}, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)])); +exports.HeartbeatCooldownState.on(events_1.disconnect.type, (context) => heartbeat_stopped_1.HeartbeatStoppedState.with({ + channels: context.channels, + groups: context.groups, +}, [(0, effects_1.leave)(context.channels, context.groups)])); +exports.HeartbeatCooldownState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); diff --git a/lib/event-engine/presence/states/heartbeat_failed.js b/lib/event-engine/presence/states/heartbeat_failed.js index 349c75756..4ea95efa8 100644 --- a/lib/event-engine/presence/states/heartbeat_failed.js +++ b/lib/event-engine/presence/states/heartbeat_failed.js @@ -1,62 +1,27 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatFailedState = void 0; -var state_1 = require("../../core/state"); -var events_1 = require("../events"); -var effects_1 = require("../effects"); -var heartbeating_1 = require("./heartbeating"); -var heartbeat_stopped_1 = require("./heartbeat_stopped"); -var heartbeat_inactive_1 = require("./heartbeat_inactive"); +const state_1 = require("../../core/state"); +const events_1 = require("../events"); +const effects_1 = require("../effects"); +const heartbeating_1 = require("./heartbeating"); +const heartbeat_stopped_1 = require("./heartbeat_stopped"); +const heartbeat_inactive_1 = require("./heartbeat_inactive"); exports.HeartbeatFailedState = new state_1.State('HEARTBEAT_FAILED'); -exports.HeartbeatFailedState.on(events_1.joined.type, function (context, event) { - return heartbeating_1.HeartbeatingState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), - }); -}); -exports.HeartbeatFailedState.on(events_1.left.type, function (context, event) { - return heartbeating_1.HeartbeatingState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), - }, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)]); -}); -exports.HeartbeatFailedState.on(events_1.reconnect.type, function (context, _) { - return heartbeating_1.HeartbeatingState.with({ - channels: context.channels, - groups: context.groups, - }); -}); -exports.HeartbeatFailedState.on(events_1.disconnect.type, function (context, _) { - return heartbeat_stopped_1.HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [(0, effects_1.leave)(context.channels, context.groups)]); -}); -exports.HeartbeatFailedState.on(events_1.leftAll.type, function (context, _) { - return heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)]); -}); +exports.HeartbeatFailedState.on(events_1.joined.type, (context, event) => heartbeating_1.HeartbeatingState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], +})); +exports.HeartbeatFailedState.on(events_1.left.type, (context, event) => heartbeating_1.HeartbeatingState.with({ + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), +}, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)])); +exports.HeartbeatFailedState.on(events_1.reconnect.type, (context, _) => heartbeating_1.HeartbeatingState.with({ + channels: context.channels, + groups: context.groups, +})); +exports.HeartbeatFailedState.on(events_1.disconnect.type, (context, _) => heartbeat_stopped_1.HeartbeatStoppedState.with({ + channels: context.channels, + groups: context.groups, +}, [(0, effects_1.leave)(context.channels, context.groups)])); +exports.HeartbeatFailedState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); diff --git a/lib/event-engine/presence/states/heartbeat_inactive.js b/lib/event-engine/presence/states/heartbeat_inactive.js index ec795611e..7bbb964c7 100644 --- a/lib/event-engine/presence/states/heartbeat_inactive.js +++ b/lib/event-engine/presence/states/heartbeat_inactive.js @@ -1,13 +1,11 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatInactiveState = void 0; -var state_1 = require("../../core/state"); -var events_1 = require("../events"); -var heartbeating_1 = require("./heartbeating"); +const state_1 = require("../../core/state"); +const events_1 = require("../events"); +const heartbeating_1 = require("./heartbeating"); exports.HeartbeatInactiveState = new state_1.State('HEARTBEAT_INACTIVE'); -exports.HeartbeatInactiveState.on(events_1.joined.type, function (_, event) { - return heartbeating_1.HeartbeatingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - }); -}); +exports.HeartbeatInactiveState.on(events_1.joined.type, (_, event) => heartbeating_1.HeartbeatingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, +})); diff --git a/lib/event-engine/presence/states/heartbeat_reconnecting.js b/lib/event-engine/presence/states/heartbeat_reconnecting.js index 1fb51af39..d26321ccc 100644 --- a/lib/event-engine/presence/states/heartbeat_reconnecting.js +++ b/lib/event-engine/presence/states/heartbeat_reconnecting.js @@ -1,86 +1,42 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.HearbeatReconnectingState = void 0; -var state_1 = require("../../core/state"); -var events_1 = require("../events"); -var effects_1 = require("../effects"); -var heartbeating_1 = require("./heartbeating"); -var heartbeat_stopped_1 = require("./heartbeat_stopped"); -var heartbeat_cooldown_1 = require("./heartbeat_cooldown"); -var heartbeat_inactive_1 = require("./heartbeat_inactive"); -var heartbeat_failed_1 = require("./heartbeat_failed"); +const state_1 = require("../../core/state"); +const events_1 = require("../events"); +const effects_1 = require("../effects"); +const heartbeating_1 = require("./heartbeating"); +const heartbeat_stopped_1 = require("./heartbeat_stopped"); +const heartbeat_cooldown_1 = require("./heartbeat_cooldown"); +const heartbeat_inactive_1 = require("./heartbeat_inactive"); +const heartbeat_failed_1 = require("./heartbeat_failed"); exports.HearbeatReconnectingState = new state_1.State('HEARBEAT_RECONNECTING'); -exports.HearbeatReconnectingState.onEnter(function (context) { return (0, effects_1.delayedHeartbeat)(context); }); -exports.HearbeatReconnectingState.onExit(function () { return effects_1.delayedHeartbeat.cancel; }); -exports.HearbeatReconnectingState.on(events_1.joined.type, function (context, event) { - return heartbeating_1.HeartbeatingState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), - }); -}); -exports.HearbeatReconnectingState.on(events_1.left.type, function (context, event) { - return heartbeating_1.HeartbeatingState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), - }, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)]); -}); -exports.HearbeatReconnectingState.on(events_1.disconnect.type, function (context, _) { +exports.HearbeatReconnectingState.onEnter((context) => (0, effects_1.delayedHeartbeat)(context)); +exports.HearbeatReconnectingState.onExit(() => effects_1.delayedHeartbeat.cancel); +exports.HearbeatReconnectingState.on(events_1.joined.type, (context, event) => heartbeating_1.HeartbeatingState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], +})); +exports.HearbeatReconnectingState.on(events_1.left.type, (context, event) => heartbeating_1.HeartbeatingState.with({ + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), +}, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)])); +exports.HearbeatReconnectingState.on(events_1.disconnect.type, (context, _) => { heartbeat_stopped_1.HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups, }, [(0, effects_1.leave)(context.channels, context.groups)]); }); -exports.HearbeatReconnectingState.on(events_1.heartbeatSuccess.type, function (context, event) { +exports.HearbeatReconnectingState.on(events_1.heartbeatSuccess.type, (context, event) => { return heartbeat_cooldown_1.HeartbeatCooldownState.with({ channels: context.channels, groups: context.groups, }); }); -exports.HearbeatReconnectingState.on(events_1.heartbeatFailure.type, function (context, event) { - return exports.HearbeatReconnectingState.with(__assign(__assign({}, context), { attempts: context.attempts + 1, reason: event.payload })); -}); -exports.HearbeatReconnectingState.on(events_1.heartbeatGiveup.type, function (context, event) { +exports.HearbeatReconnectingState.on(events_1.heartbeatFailure.type, (context, event) => exports.HearbeatReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); +exports.HearbeatReconnectingState.on(events_1.heartbeatGiveup.type, (context, event) => { return heartbeat_failed_1.HeartbeatFailedState.with({ channels: context.channels, groups: context.groups, }); }); -exports.HearbeatReconnectingState.on(events_1.leftAll.type, function (context, _) { - return heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)]); -}); +exports.HearbeatReconnectingState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); diff --git a/lib/event-engine/presence/states/heartbeat_stopped.js b/lib/event-engine/presence/states/heartbeat_stopped.js index 6146a4266..6c162f433 100644 --- a/lib/event-engine/presence/states/heartbeat_stopped.js +++ b/lib/event-engine/presence/states/heartbeat_stopped.js @@ -1,52 +1,21 @@ "use strict"; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatStoppedState = void 0; -var state_1 = require("../../core/state"); -var events_1 = require("../events"); -var heartbeat_inactive_1 = require("./heartbeat_inactive"); -var heartbeating_1 = require("./heartbeating"); +const state_1 = require("../../core/state"); +const events_1 = require("../events"); +const heartbeat_inactive_1 = require("./heartbeat_inactive"); +const heartbeating_1 = require("./heartbeating"); exports.HeartbeatStoppedState = new state_1.State('HEARTBEAT_STOPPED'); -exports.HeartbeatStoppedState.on(events_1.joined.type, function (context, event) { - return exports.HeartbeatStoppedState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), - }); -}); -exports.HeartbeatStoppedState.on(events_1.left.type, function (context, event) { - return exports.HeartbeatStoppedState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), - }); -}); -exports.HeartbeatStoppedState.on(events_1.reconnect.type, function (context, _) { - return heartbeating_1.HeartbeatingState.with({ - channels: context.channels, - groups: context.groups, - }); -}); -exports.HeartbeatStoppedState.on(events_1.leftAll.type, function (context, _) { return heartbeat_inactive_1.HeartbeatInactiveState.with(undefined); }); +exports.HeartbeatStoppedState.on(events_1.joined.type, (context, event) => exports.HeartbeatStoppedState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], +})); +exports.HeartbeatStoppedState.on(events_1.left.type, (context, event) => exports.HeartbeatStoppedState.with({ + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), +})); +exports.HeartbeatStoppedState.on(events_1.reconnect.type, (context, _) => heartbeating_1.HeartbeatingState.with({ + channels: context.channels, + groups: context.groups, +})); +exports.HeartbeatStoppedState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined)); diff --git a/lib/event-engine/presence/states/heartbeating.js b/lib/event-engine/presence/states/heartbeating.js index 675f30d64..588b414ee 100644 --- a/lib/event-engine/presence/states/heartbeating.js +++ b/lib/event-engine/presence/states/heartbeating.js @@ -1,78 +1,36 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -var __read = (this && this.__read) || function (o, n) { - var m = typeof Symbol === "function" && o[Symbol.iterator]; - if (!m) return o; - var i = m.call(o), r, ar = [], e; - try { - while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); - } - catch (error) { e = { error: error }; } - finally { - try { - if (r && !r.done && (m = i["return"])) m.call(i); - } - finally { if (e) throw e.error; } - } - return ar; -}; -var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatingState = void 0; -var state_1 = require("../../core/state"); -var events_1 = require("../events"); -var effects_1 = require("../effects"); -var heartbeat_cooldown_1 = require("./heartbeat_cooldown"); -var heartbeat_reconnecting_1 = require("./heartbeat_reconnecting"); -var heartbeat_stopped_1 = require("./heartbeat_stopped"); -var heartbeat_inactive_1 = require("./heartbeat_inactive"); +const state_1 = require("../../core/state"); +const events_1 = require("../events"); +const effects_1 = require("../effects"); +const heartbeat_cooldown_1 = require("./heartbeat_cooldown"); +const heartbeat_reconnecting_1 = require("./heartbeat_reconnecting"); +const heartbeat_stopped_1 = require("./heartbeat_stopped"); +const heartbeat_inactive_1 = require("./heartbeat_inactive"); exports.HeartbeatingState = new state_1.State('HEARTBEATING'); -exports.HeartbeatingState.onEnter(function (context) { return (0, effects_1.heartbeat)(context.channels, context.groups); }); -exports.HeartbeatingState.on(events_1.heartbeatSuccess.type, function (context, event) { +exports.HeartbeatingState.onEnter((context) => (0, effects_1.heartbeat)(context.channels, context.groups)); +exports.HeartbeatingState.on(events_1.heartbeatSuccess.type, (context, event) => { return heartbeat_cooldown_1.HeartbeatCooldownState.with({ channels: context.channels, groups: context.groups, }); }); -exports.HeartbeatingState.on(events_1.joined.type, function (context, event) { +exports.HeartbeatingState.on(events_1.joined.type, (context, event) => exports.HeartbeatingState.with({ + channels: [...context.channels, ...event.payload.channels], + groups: [...context.groups, ...event.payload.groups], +})); +exports.HeartbeatingState.on(events_1.left.type, (context, event) => { return exports.HeartbeatingState.with({ - channels: __spreadArray(__spreadArray([], __read(context.channels), false), __read(event.payload.channels), false), - groups: __spreadArray(__spreadArray([], __read(context.groups), false), __read(event.payload.groups), false), - }); -}); -exports.HeartbeatingState.on(events_1.left.type, function (context, event) { - return exports.HeartbeatingState.with({ - channels: context.channels.filter(function (channel) { return !event.payload.channels.includes(channel); }), - groups: context.groups.filter(function (group) { return !event.payload.groups.includes(group); }), + channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), + groups: context.groups.filter((group) => !event.payload.groups.includes(group)), }, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)]); }); -exports.HeartbeatingState.on(events_1.heartbeatFailure.type, function (context, event) { - return heartbeat_reconnecting_1.HearbeatReconnectingState.with(__assign(__assign({}, context), { attempts: 0, reason: event.payload })); -}); -exports.HeartbeatingState.on(events_1.disconnect.type, function (context) { - return heartbeat_stopped_1.HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [(0, effects_1.leave)(context.channels, context.groups)]); -}); -exports.HeartbeatingState.on(events_1.leftAll.type, function (context, _) { - return heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)]); +exports.HeartbeatingState.on(events_1.heartbeatFailure.type, (context, event) => { + return heartbeat_reconnecting_1.HearbeatReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: 0, reason: event.payload })); }); +exports.HeartbeatingState.on(events_1.disconnect.type, (context) => heartbeat_stopped_1.HeartbeatStoppedState.with({ + channels: context.channels, + groups: context.groups, +}, [(0, effects_1.leave)(context.channels, context.groups)])); +exports.HeartbeatingState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); diff --git a/lib/event-engine/states/handshake_failed.js b/lib/event-engine/states/handshake_failed.js index 658ff855d..ad658adb6 100644 --- a/lib/event-engine/states/handshake_failed.js +++ b/lib/event-engine/states/handshake_failed.js @@ -1,26 +1,22 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HandshakeFailedState = void 0; -var state_1 = require("../core/state"); -var events_1 = require("../events"); -var handshaking_1 = require("./handshaking"); -var unsubscribed_1 = require("./unsubscribed"); +const state_1 = require("../core/state"); +const events_1 = require("../events"); +const handshaking_1 = require("./handshaking"); +const unsubscribed_1 = require("./unsubscribed"); exports.HandshakeFailedState = new state_1.State('HANDSHAKE_FAILED'); -exports.HandshakeFailedState.on(events_1.subscriptionChange.type, function (context, event) { - return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); -}); -exports.HandshakeFailedState.on(events_1.reconnect.type, function (context, event) { - return handshaking_1.HandshakingState.with({ - channels: context.channels, - groups: context.groups, - cursor: event.payload.cursor || context.cursor, - }); -}); -exports.HandshakeFailedState.on(events_1.restore.type, function (context, event) { +exports.HandshakeFailedState.on(events_1.subscriptionChange.type, (context, event) => handshaking_1.HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, +})); +exports.HandshakeFailedState.on(events_1.reconnect.type, (context, event) => handshaking_1.HandshakingState.with({ + channels: context.channels, + groups: context.groups, + cursor: event.payload.cursor || context.cursor, +})); +exports.HandshakeFailedState.on(events_1.restore.type, (context, event) => { var _a, _b; return handshaking_1.HandshakingState.with({ channels: event.payload.channels, @@ -31,4 +27,4 @@ exports.HandshakeFailedState.on(events_1.restore.type, function (context, event) }, }); }); -exports.HandshakeFailedState.on(events_1.unsubscribeAll.type, function (_) { return unsubscribed_1.UnsubscribedState.with(); }); +exports.HandshakeFailedState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with()); diff --git a/lib/event-engine/states/handshake_failure.js b/lib/event-engine/states/handshake_failure.js deleted file mode 100644 index 4f682098a..000000000 --- a/lib/event-engine/states/handshake_failure.js +++ /dev/null @@ -1,26 +0,0 @@ -"use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.HandshakeFailureState = void 0; -var state_1 = require("../core/state"); -var events_1 = require("../events"); -var handshake_stopped_1 = require("./handshake_stopped"); -var handshaking_1 = require("./handshaking"); -exports.HandshakeFailureState = new state_1.State('HANDSHAKE_FAILURE'); -exports.HandshakeFailureState.on(events_1.disconnect.type, function (context) { - return handshake_stopped_1.HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - }); -}); -exports.HandshakeFailureState.on(events_1.reconnect.type, function (context) { return handshaking_1.HandshakingState.with(__assign({}, context)); }); diff --git a/lib/event-engine/states/handshake_reconnecting.js b/lib/event-engine/states/handshake_reconnecting.js index 9f5339e73..6c95593aa 100644 --- a/lib/event-engine/states/handshake_reconnecting.js +++ b/lib/event-engine/states/handshake_reconnecting.js @@ -1,35 +1,24 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HandshakeReconnectingState = void 0; -var state_1 = require("../core/state"); -var effects_1 = require("../effects"); -var events_1 = require("../events"); -var handshake_failed_1 = require("./handshake_failed"); -var handshake_stopped_1 = require("./handshake_stopped"); -var handshaking_1 = require("./handshaking"); -var receiving_1 = require("./receiving"); -var unsubscribed_1 = require("./unsubscribed"); -var categories_1 = __importDefault(require("../../core/constants/categories")); +const state_1 = require("../core/state"); +const effects_1 = require("../effects"); +const events_1 = require("../events"); +const handshake_failed_1 = require("./handshake_failed"); +const handshake_stopped_1 = require("./handshake_stopped"); +const handshaking_1 = require("./handshaking"); +const receiving_1 = require("./receiving"); +const unsubscribed_1 = require("./unsubscribed"); +const categories_1 = __importDefault(require("../../core/constants/categories")); exports.HandshakeReconnectingState = new state_1.State('HANDSHAKE_RECONNECTING'); -exports.HandshakeReconnectingState.onEnter(function (context) { return (0, effects_1.handshakeReconnect)(context); }); -exports.HandshakeReconnectingState.onExit(function () { return effects_1.handshakeReconnect.cancel; }); -exports.HandshakeReconnectingState.on(events_1.handshakeReconnectSuccess.type, function (context, event) { +exports.HandshakeReconnectingState.onEnter((context) => (0, effects_1.handshakeReconnect)(context)); +exports.HandshakeReconnectingState.onExit(() => effects_1.handshakeReconnect.cancel); +exports.HandshakeReconnectingState.on(events_1.handshakeReconnectSuccess.type, (context, event) => { var _a, _b; - var cursor = { + const cursor = { timetoken: !!((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : event.payload.cursor.timetoken, region: event.payload.cursor.region, }; @@ -39,10 +28,8 @@ exports.HandshakeReconnectingState.on(events_1.handshakeReconnectSuccess.type, f cursor: cursor, }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNConnectedCategory })]); }); -exports.HandshakeReconnectingState.on(events_1.handshakeReconnectFailure.type, function (context, event) { - return exports.HandshakeReconnectingState.with(__assign(__assign({}, context), { attempts: context.attempts + 1, reason: event.payload })); -}); -exports.HandshakeReconnectingState.on(events_1.handshakeReconnectGiveup.type, function (context, event) { +exports.HandshakeReconnectingState.on(events_1.handshakeReconnectFailure.type, (context, event) => exports.HandshakeReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); +exports.HandshakeReconnectingState.on(events_1.handshakeReconnectGiveup.type, (context, event) => { var _a; return handshake_failed_1.HandshakeFailedState.with({ groups: context.groups, @@ -51,21 +38,17 @@ exports.HandshakeReconnectingState.on(events_1.handshakeReconnectGiveup.type, fu reason: event.payload, }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNConnectionErrorCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); }); -exports.HandshakeReconnectingState.on(events_1.disconnect.type, function (context) { - return handshake_stopped_1.HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }); -}); -exports.HandshakeReconnectingState.on(events_1.subscriptionChange.type, function (context, event) { - return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); -}); -exports.HandshakeReconnectingState.on(events_1.restore.type, function (context, event) { +exports.HandshakeReconnectingState.on(events_1.disconnect.type, (context) => handshake_stopped_1.HandshakeStoppedState.with({ + channels: context.channels, + groups: context.groups, + cursor: context.cursor, +})); +exports.HandshakeReconnectingState.on(events_1.subscriptionChange.type, (context, event) => handshaking_1.HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, +})); +exports.HandshakeReconnectingState.on(events_1.restore.type, (context, event) => { var _a, _b; return handshaking_1.HandshakingState.with({ channels: event.payload.channels, @@ -76,4 +59,4 @@ exports.HandshakeReconnectingState.on(events_1.restore.type, function (context, }, }); }); -exports.HandshakeReconnectingState.on(events_1.unsubscribeAll.type, function (_) { return unsubscribed_1.UnsubscribedState.with(undefined); }); +exports.HandshakeReconnectingState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with(undefined)); diff --git a/lib/event-engine/states/handshake_stopped.js b/lib/event-engine/states/handshake_stopped.js index 3e2838fb9..1cad18d75 100644 --- a/lib/event-engine/states/handshake_stopped.js +++ b/lib/event-engine/states/handshake_stopped.js @@ -1,33 +1,18 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.HandshakeStoppedState = void 0; -var state_1 = require("../core/state"); -var events_1 = require("../events"); -var handshaking_1 = require("./handshaking"); -var unsubscribed_1 = require("./unsubscribed"); +const state_1 = require("../core/state"); +const events_1 = require("../events"); +const handshaking_1 = require("./handshaking"); +const unsubscribed_1 = require("./unsubscribed"); exports.HandshakeStoppedState = new state_1.State('HANDSHAKE_STOPPED'); -exports.HandshakeStoppedState.on(events_1.subscriptionChange.type, function (context, event) { - return exports.HandshakeStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); -}); -exports.HandshakeStoppedState.on(events_1.reconnect.type, function (context, event) { - return handshaking_1.HandshakingState.with(__assign(__assign({}, context), { cursor: event.payload.cursor || context.cursor })); -}); -exports.HandshakeStoppedState.on(events_1.restore.type, function (context, event) { +exports.HandshakeStoppedState.on(events_1.subscriptionChange.type, (context, event) => exports.HandshakeStoppedState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, +})); +exports.HandshakeStoppedState.on(events_1.reconnect.type, (context, event) => handshaking_1.HandshakingState.with(Object.assign(Object.assign({}, context), { cursor: event.payload.cursor || context.cursor }))); +exports.HandshakeStoppedState.on(events_1.restore.type, (context, event) => { var _a; return exports.HandshakeStoppedState.with({ channels: event.payload.channels, @@ -38,4 +23,4 @@ exports.HandshakeStoppedState.on(events_1.restore.type, function (context, event }, }); }); -exports.HandshakeStoppedState.on(events_1.unsubscribeAll.type, function (_) { return unsubscribed_1.UnsubscribedState.with(); }); +exports.HandshakeStoppedState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with()); diff --git a/lib/event-engine/states/handshaking.js b/lib/event-engine/states/handshaking.js index acb960681..13d3c1cca 100644 --- a/lib/event-engine/states/handshaking.js +++ b/lib/event-engine/states/handshaking.js @@ -4,18 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HandshakingState = void 0; -var state_1 = require("../core/state"); -var effects_1 = require("../effects"); -var events_1 = require("../events"); -var handshake_reconnecting_1 = require("./handshake_reconnecting"); -var handshake_stopped_1 = require("./handshake_stopped"); -var receiving_1 = require("./receiving"); -var unsubscribed_1 = require("./unsubscribed"); -var categories_1 = __importDefault(require("../../core/constants/categories")); +const state_1 = require("../core/state"); +const effects_1 = require("../effects"); +const events_1 = require("../events"); +const handshake_reconnecting_1 = require("./handshake_reconnecting"); +const handshake_stopped_1 = require("./handshake_stopped"); +const receiving_1 = require("./receiving"); +const unsubscribed_1 = require("./unsubscribed"); +const categories_1 = __importDefault(require("../../core/constants/categories")); exports.HandshakingState = new state_1.State('HANDSHAKING'); -exports.HandshakingState.onEnter(function (context) { return (0, effects_1.handshake)(context.channels, context.groups); }); -exports.HandshakingState.onExit(function () { return effects_1.handshake.cancel; }); -exports.HandshakingState.on(events_1.subscriptionChange.type, function (context, event) { +exports.HandshakingState.onEnter((context) => (0, effects_1.handshake)(context.channels, context.groups)); +exports.HandshakingState.onExit(() => effects_1.handshake.cancel); +exports.HandshakingState.on(events_1.subscriptionChange.type, (context, event) => { if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { return unsubscribed_1.UnsubscribedState.with(undefined); } @@ -25,7 +25,7 @@ exports.HandshakingState.on(events_1.subscriptionChange.type, function (context, cursor: context.cursor, }); }); -exports.HandshakingState.on(events_1.handshakeSuccess.type, function (context, event) { +exports.HandshakingState.on(events_1.handshakeSuccess.type, (context, event) => { var _a, _b; return receiving_1.ReceivingState.with({ channels: context.channels, @@ -40,7 +40,7 @@ exports.HandshakingState.on(events_1.handshakeSuccess.type, function (context, e }), ]); }); -exports.HandshakingState.on(events_1.handshakeFailure.type, function (context, event) { +exports.HandshakingState.on(events_1.handshakeFailure.type, (context, event) => { return handshake_reconnecting_1.HandshakeReconnectingState.with({ channels: context.channels, groups: context.groups, @@ -49,14 +49,12 @@ exports.HandshakingState.on(events_1.handshakeFailure.type, function (context, e reason: event.payload, }); }); -exports.HandshakingState.on(events_1.disconnect.type, function (context) { - return handshake_stopped_1.HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }); -}); -exports.HandshakingState.on(events_1.restore.type, function (context, event) { +exports.HandshakingState.on(events_1.disconnect.type, (context) => handshake_stopped_1.HandshakeStoppedState.with({ + channels: context.channels, + groups: context.groups, + cursor: context.cursor, +})); +exports.HandshakingState.on(events_1.restore.type, (context, event) => { var _a; return exports.HandshakingState.with({ channels: event.payload.channels, @@ -67,4 +65,4 @@ exports.HandshakingState.on(events_1.restore.type, function (context, event) { }, }); }); -exports.HandshakingState.on(events_1.unsubscribeAll.type, function (_) { return unsubscribed_1.UnsubscribedState.with(); }); +exports.HandshakingState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with()); diff --git a/lib/event-engine/states/receive_failed.js b/lib/event-engine/states/receive_failed.js index 6a880df98..d6af9bfd3 100644 --- a/lib/event-engine/states/receive_failed.js +++ b/lib/event-engine/states/receive_failed.js @@ -1,12 +1,12 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReceiveFailedState = void 0; -var state_1 = require("../core/state"); -var events_1 = require("../events"); -var handshaking_1 = require("./handshaking"); -var unsubscribed_1 = require("./unsubscribed"); +const state_1 = require("../core/state"); +const events_1 = require("../events"); +const handshaking_1 = require("./handshaking"); +const unsubscribed_1 = require("./unsubscribed"); exports.ReceiveFailedState = new state_1.State('RECEIVE_FAILED'); -exports.ReceiveFailedState.on(events_1.reconnect.type, function (context, event) { +exports.ReceiveFailedState.on(events_1.reconnect.type, (context, event) => { var _a; return handshaking_1.HandshakingState.with({ channels: context.channels, @@ -17,21 +17,17 @@ exports.ReceiveFailedState.on(events_1.reconnect.type, function (context, event) }, }); }); -exports.ReceiveFailedState.on(events_1.subscriptionChange.type, function (context, event) { - return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); -}); -exports.ReceiveFailedState.on(events_1.restore.type, function (context, event) { - return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); -}); -exports.ReceiveFailedState.on(events_1.unsubscribeAll.type, function (_) { return unsubscribed_1.UnsubscribedState.with(undefined); }); +exports.ReceiveFailedState.on(events_1.subscriptionChange.type, (context, event) => handshaking_1.HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, +})); +exports.ReceiveFailedState.on(events_1.restore.type, (context, event) => handshaking_1.HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region || context.cursor.region, + }, +})); +exports.ReceiveFailedState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with(undefined)); diff --git a/lib/event-engine/states/receive_failure.js b/lib/event-engine/states/receive_failure.js deleted file mode 100644 index 4eb9e2b72..000000000 --- a/lib/event-engine/states/receive_failure.js +++ /dev/null @@ -1,38 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ReceiveFailureState = void 0; -var state_1 = require("../core/state"); -var events_1 = require("../events"); -var handshaking_1 = require("./handshaking"); -var receive_stopped_1 = require("./receive_stopped"); -var unsubscribed_1 = require("./unsubscribed"); -exports.ReceiveFailureState = new state_1.State('RECEIVE_FAILED'); -exports.ReceiveFailureState.on(events_1.reconnectingRetry.type, function (context) { - return handshaking_1.HandshakingState.with({ - channels: context.channels, - groups: context.groups, - timetoken: context.cursor.timetoken, - }); -}); -exports.ReceiveFailureState.on(events_1.disconnect.type, function (context) { - return receive_stopped_1.ReceiveStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }); -}); -exports.ReceiveFailureState.on(events_1.subscriptionChange.type, function (_, event) { - return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - timetoken: event.payload.timetoken, - }); -}); -exports.ReceiveFailureState.on(events_1.restore.type, function (_, event) { - return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - timetoken: event.payload.timetoken, - }); -}); -exports.ReceiveFailureState.on(events_1.unsubscribeAll.type, function (_) { return unsubscribed_1.UnsubscribedState.with(undefined); }); diff --git a/lib/event-engine/states/receive_reconnecting.js b/lib/event-engine/states/receive_reconnecting.js index 7f0559d5e..8f98426f1 100644 --- a/lib/event-engine/states/receive_reconnecting.js +++ b/lib/event-engine/states/receive_reconnecting.js @@ -1,42 +1,27 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReceiveReconnectingState = void 0; -var state_1 = require("../core/state"); -var effects_1 = require("../effects"); -var events_1 = require("../events"); -var receiving_1 = require("./receiving"); -var receive_failed_1 = require("./receive_failed"); -var receive_stopped_1 = require("./receive_stopped"); -var unsubscribed_1 = require("./unsubscribed"); -var categories_1 = __importDefault(require("../../core/constants/categories")); +const state_1 = require("../core/state"); +const effects_1 = require("../effects"); +const events_1 = require("../events"); +const receiving_1 = require("./receiving"); +const receive_failed_1 = require("./receive_failed"); +const receive_stopped_1 = require("./receive_stopped"); +const unsubscribed_1 = require("./unsubscribed"); +const categories_1 = __importDefault(require("../../core/constants/categories")); exports.ReceiveReconnectingState = new state_1.State('RECEIVE_RECONNECTING'); -exports.ReceiveReconnectingState.onEnter(function (context) { return (0, effects_1.receiveReconnect)(context); }); -exports.ReceiveReconnectingState.onExit(function () { return effects_1.receiveReconnect.cancel; }); -exports.ReceiveReconnectingState.on(events_1.receiveReconnectSuccess.type, function (context, event) { - return receiving_1.ReceivingState.with({ - channels: context.channels, - groups: context.groups, - cursor: event.payload.cursor, - }, [(0, effects_1.emitMessages)(event.payload.events)]); -}); -exports.ReceiveReconnectingState.on(events_1.receiveReconnectFailure.type, function (context, event) { - return exports.ReceiveReconnectingState.with(__assign(__assign({}, context), { attempts: context.attempts + 1, reason: event.payload })); -}); -exports.ReceiveReconnectingState.on(events_1.receiveReconnectGiveup.type, function (context, event) { +exports.ReceiveReconnectingState.onEnter((context) => (0, effects_1.receiveReconnect)(context)); +exports.ReceiveReconnectingState.onExit(() => effects_1.receiveReconnect.cancel); +exports.ReceiveReconnectingState.on(events_1.receiveReconnectSuccess.type, (context, event) => receiving_1.ReceivingState.with({ + channels: context.channels, + groups: context.groups, + cursor: event.payload.cursor, +}, [(0, effects_1.emitMessages)(event.payload.events)])); +exports.ReceiveReconnectingState.on(events_1.receiveReconnectFailure.type, (context, event) => exports.ReceiveReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); +exports.ReceiveReconnectingState.on(events_1.receiveReconnectGiveup.type, (context, event) => { var _a; return receive_failed_1.ReceiveFailedState.with({ groups: context.groups, @@ -45,30 +30,22 @@ exports.ReceiveReconnectingState.on(events_1.receiveReconnectGiveup.type, functi reason: event.payload, }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedUnexpectedlyCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); }); -exports.ReceiveReconnectingState.on(events_1.disconnect.type, function (context) { - return receive_stopped_1.ReceiveStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })]); -}); -exports.ReceiveReconnectingState.on(events_1.restore.type, function (context, event) { - return receiving_1.ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); -}); -exports.ReceiveReconnectingState.on(events_1.subscriptionChange.type, function (context, event) { - return receiving_1.ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); -}); -exports.ReceiveReconnectingState.on(events_1.unsubscribeAll.type, function (_) { - return unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })]); -}); +exports.ReceiveReconnectingState.on(events_1.disconnect.type, (context) => receive_stopped_1.ReceiveStoppedState.with({ + channels: context.channels, + groups: context.groups, + cursor: context.cursor, +}, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })])); +exports.ReceiveReconnectingState.on(events_1.restore.type, (context, event) => receiving_1.ReceivingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region || context.cursor.region, + }, +})); +exports.ReceiveReconnectingState.on(events_1.subscriptionChange.type, (context, event) => receiving_1.ReceivingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, +})); +exports.ReceiveReconnectingState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })])); diff --git a/lib/event-engine/states/receive_stopped.js b/lib/event-engine/states/receive_stopped.js index ea0eb5a13..1078a2e4b 100644 --- a/lib/event-engine/states/receive_stopped.js +++ b/lib/event-engine/states/receive_stopped.js @@ -1,29 +1,25 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReceiveStoppedState = void 0; -var state_1 = require("../core/state"); -var events_1 = require("../events"); -var handshaking_1 = require("./handshaking"); -var unsubscribed_1 = require("./unsubscribed"); +const state_1 = require("../core/state"); +const events_1 = require("../events"); +const handshaking_1 = require("./handshaking"); +const unsubscribed_1 = require("./unsubscribed"); exports.ReceiveStoppedState = new state_1.State('RECEIVE_STOPPED'); -exports.ReceiveStoppedState.on(events_1.subscriptionChange.type, function (context, event) { - return exports.ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); -}); -exports.ReceiveStoppedState.on(events_1.restore.type, function (context, event) { - return exports.ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); -}); -exports.ReceiveStoppedState.on(events_1.reconnect.type, function (context, event) { +exports.ReceiveStoppedState.on(events_1.subscriptionChange.type, (context, event) => exports.ReceiveStoppedState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: context.cursor, +})); +exports.ReceiveStoppedState.on(events_1.restore.type, (context, event) => exports.ReceiveStoppedState.with({ + channels: event.payload.channels, + groups: event.payload.groups, + cursor: { + timetoken: event.payload.cursor.timetoken, + region: event.payload.cursor.region || context.cursor.region, + }, +})); +exports.ReceiveStoppedState.on(events_1.reconnect.type, (context, event) => { var _a; return handshaking_1.HandshakingState.with({ channels: context.channels, @@ -34,4 +30,4 @@ exports.ReceiveStoppedState.on(events_1.reconnect.type, function (context, event }, }); }); -exports.ReceiveStoppedState.on(events_1.unsubscribeAll.type, function () { return unsubscribed_1.UnsubscribedState.with(undefined); }); +exports.ReceiveStoppedState.on(events_1.unsubscribeAll.type, () => unsubscribed_1.UnsubscribedState.with(undefined)); diff --git a/lib/event-engine/states/receiving.js b/lib/event-engine/states/receiving.js index 122018e8e..66f44e747 100644 --- a/lib/event-engine/states/receiving.js +++ b/lib/event-engine/states/receiving.js @@ -1,36 +1,25 @@ "use strict"; -var __assign = (this && this.__assign) || function () { - __assign = Object.assign || function(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) - t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReceivingState = void 0; -var state_1 = require("../core/state"); -var effects_1 = require("../effects"); -var events_1 = require("../events"); -var unsubscribed_1 = require("./unsubscribed"); -var receive_reconnecting_1 = require("./receive_reconnecting"); -var receive_stopped_1 = require("./receive_stopped"); -var categories_1 = __importDefault(require("../../core/constants/categories")); +const state_1 = require("../core/state"); +const effects_1 = require("../effects"); +const events_1 = require("../events"); +const unsubscribed_1 = require("./unsubscribed"); +const receive_reconnecting_1 = require("./receive_reconnecting"); +const receive_stopped_1 = require("./receive_stopped"); +const categories_1 = __importDefault(require("../../core/constants/categories")); exports.ReceivingState = new state_1.State('RECEIVING'); -exports.ReceivingState.onEnter(function (context) { return (0, effects_1.receiveMessages)(context.channels, context.groups, context.cursor); }); -exports.ReceivingState.onExit(function () { return effects_1.receiveMessages.cancel; }); -exports.ReceivingState.on(events_1.receiveSuccess.type, function (context, event) { +exports.ReceivingState.onEnter((context) => (0, effects_1.receiveMessages)(context.channels, context.groups, context.cursor)); +exports.ReceivingState.onExit(() => effects_1.receiveMessages.cancel); +exports.ReceivingState.on(events_1.receiveSuccess.type, (context, event) => { return exports.ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: event.payload.cursor }, [ (0, effects_1.emitMessages)(event.payload.events), ]); }); -exports.ReceivingState.on(events_1.subscriptionChange.type, function (context, event) { +exports.ReceivingState.on(events_1.subscriptionChange.type, (context, event) => { if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { return unsubscribed_1.UnsubscribedState.with(undefined); } @@ -40,7 +29,7 @@ exports.ReceivingState.on(events_1.subscriptionChange.type, function (context, e groups: event.payload.groups, }); }); -exports.ReceivingState.on(events_1.restore.type, function (context, event) { +exports.ReceivingState.on(events_1.restore.type, (context, event) => { if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { return unsubscribed_1.UnsubscribedState.with(undefined); } @@ -53,16 +42,14 @@ exports.ReceivingState.on(events_1.restore.type, function (context, event) { }, }); }); -exports.ReceivingState.on(events_1.receiveFailure.type, function (context, event) { - return receive_reconnecting_1.ReceiveReconnectingState.with(__assign(__assign({}, context), { attempts: 0, reason: event.payload })); +exports.ReceivingState.on(events_1.receiveFailure.type, (context, event) => { + return receive_reconnecting_1.ReceiveReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: 0, reason: event.payload })); }); -exports.ReceivingState.on(events_1.disconnect.type, function (context) { +exports.ReceivingState.on(events_1.disconnect.type, (context) => { return receive_stopped_1.ReceiveStoppedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor, }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })]); }); -exports.ReceivingState.on(events_1.unsubscribeAll.type, function (_) { - return unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })]); -}); +exports.ReceivingState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })])); diff --git a/lib/event-engine/states/unsubscribed.js b/lib/event-engine/states/unsubscribed.js index e5076d50c..10f3b2bad 100644 --- a/lib/event-engine/states/unsubscribed.js +++ b/lib/event-engine/states/unsubscribed.js @@ -1,17 +1,15 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.UnsubscribedState = void 0; -var state_1 = require("../core/state"); -var events_1 = require("../events"); -var handshaking_1 = require("./handshaking"); +const state_1 = require("../core/state"); +const events_1 = require("../events"); +const handshaking_1 = require("./handshaking"); exports.UnsubscribedState = new state_1.State('UNSUBSCRIBED'); -exports.UnsubscribedState.on(events_1.subscriptionChange.type, function (_, event) { - return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - }); -}); -exports.UnsubscribedState.on(events_1.restore.type, function (_, event) { +exports.UnsubscribedState.on(events_1.subscriptionChange.type, (_, event) => handshaking_1.HandshakingState.with({ + channels: event.payload.channels, + groups: event.payload.groups, +})); +exports.UnsubscribedState.on(events_1.restore.type, (_, event) => { return handshaking_1.HandshakingState.with({ channels: event.payload.channels, groups: event.payload.groups, diff --git a/lib/file/index.js b/lib/file/index.js deleted file mode 100644 index 1e44d895d..000000000 --- a/lib/file/index.js +++ /dev/null @@ -1,2 +0,0 @@ -"use strict"; -/** */ diff --git a/lib/file/modules/node.js b/lib/file/modules/node.js index bb0988238..5b0c17841 100644 --- a/lib/file/modules/node.js +++ b/lib/file/modules/node.js @@ -8,167 +8,125 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; -var _a; Object.defineProperty(exports, "__esModule", { value: true }); -var stream_1 = require("stream"); -var fs_1 = __importDefault(require("fs")); -var path_1 = require("path"); -var PubNubFile = (_a = /** @class */ (function () { - function PubNubFile(_a) { - var stream = _a.stream, data = _a.data, encoding = _a.encoding, name = _a.name, mimeType = _a.mimeType; - if (stream instanceof stream_1.Readable) { - this.data = stream; - if (stream instanceof fs_1.default.ReadStream) { - // $FlowFixMe: incomplete flow node definitions - this.name = (0, path_1.basename)(stream.path); - this.contentLength = fs_1.default.statSync(stream.path).size; - } - } - else if (data instanceof Buffer) { - this.data = Buffer.from(data); - } - else if (typeof data === 'string') { - // $FlowFixMe: incomplete flow node definitions - this.data = Buffer.from(data, encoding !== null && encoding !== void 0 ? encoding : 'utf8'); - } - if (name) { - this.name = (0, path_1.basename)(name); - } - if (mimeType) { - this.mimeType = mimeType; - } - if (this.data === undefined) { - throw new Error("Couldn't construct a file out of supplied options."); - } - if (this.name === undefined) { - throw new Error("Couldn't guess filename out of the options. Please provide one."); +const stream_1 = require("stream"); +const buffer_1 = require("buffer"); +const path_1 = require("path"); +const fs_1 = __importDefault(require("fs")); +class PubNubFile { + static create(file) { + return new PubNubFile(file); + } + constructor(file) { + const { stream, data, encoding, name, mimeType } = file; + let fileData; + let contentLength; + let fileMimeType; + let fileName; + if (stream && stream instanceof stream_1.Readable) { + fileData = stream; + if (stream instanceof fs_1.default.ReadStream) { + const streamFilePath = stream.path instanceof buffer_1.Buffer ? new TextDecoder().decode(stream.path) : stream.path; + fileName = (0, path_1.basename)(streamFilePath); + contentLength = fs_1.default.statSync(streamFilePath).size; } } - PubNubFile.create = function (config) { - return new this(config); - }; - PubNubFile.prototype.toBuffer = function () { - if (this.data instanceof Buffer) { - return Promise.resolve(Buffer.from(this.data)); - } - if (this.data instanceof stream_1.Readable) { - var stream_2 = this.data; - return new Promise(function (resolve, reject) { - var chunks = []; - stream_2.on('data', function (chunk) { return chunks.push(chunk); }); - stream_2.once('error', reject); - stream_2.once('end', function () { - resolve(Buffer.concat(chunks)); - }); - }); - } - if (typeof this.data === 'string') { - return Promise.resolve(Buffer.from(this.data)); - } - throw new Error("Can't cast to 'buffer'."); - }; - PubNubFile.prototype.toArrayBuffer = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in browser environments.'); - }); - }); - }; - PubNubFile.prototype.toString = function (encoding) { - if (encoding === void 0) { encoding = 'utf8'; } - return __awaiter(this, void 0, void 0, function () { - var buffer; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: return [4 /*yield*/, this.toBuffer()]; - case 1: - buffer = _a.sent(); - return [2 /*return*/, buffer.toString(encoding)]; - } - }); - }); - }; - PubNubFile.prototype.toStream = function () { - return __awaiter(this, void 0, void 0, function () { - var input_1, stream; - return __generator(this, function (_a) { - if (!(this.data instanceof stream_1.Readable)) { - input_1 = this.data; - return [2 /*return*/, new stream_1.Readable({ - read: function () { - this.push(Buffer.from(input_1)); - this.push(null); - }, - })]; - } - stream = new stream_1.PassThrough(); - if (this.data instanceof stream_1.Readable) { - this.data.pipe(stream); - } - return [2 /*return*/, stream]; - }); - }); - }; - PubNubFile.prototype.toFile = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in browser environments.'); - }); - }); - }; - PubNubFile.prototype.toFileUri = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in react native environments.'); + else if (data instanceof buffer_1.Buffer) { + contentLength = data.length; + fileData = buffer_1.Buffer.alloc(contentLength); + data.copy(fileData); + } + else if (data instanceof ArrayBuffer) { + contentLength = data.byteLength; + fileData = buffer_1.Buffer.from(data); + } + else if (typeof data === 'string') { + fileData = buffer_1.Buffer.from(data, encoding !== null && encoding !== void 0 ? encoding : 'utf8'); + contentLength = fileData.length; + } + if (contentLength) + this.contentLength = contentLength; + if (mimeType) + fileMimeType = mimeType; + else + fileMimeType = 'application/octet-stream'; + if (name) + fileName = (0, path_1.basename)(name); + if (fileData === undefined) + throw new Error("Couldn't construct a file out of supplied options."); + if (fileName === undefined) + throw new Error("Couldn't guess filename out of the options. Please provide one."); + this.mimeType = fileMimeType; + this.data = fileData; + this.name = fileName; + } + toBuffer() { + return __awaiter(this, void 0, void 0, function* () { + if (this.data instanceof buffer_1.Buffer) + return this.data; + const stream = this.data; + return new Promise((resolve, reject) => { + const chunks = []; + stream.on('data', (chunk) => { + chunks.push(chunk); }); - }); - }; - PubNubFile.prototype.toBlob = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in browser environments.'); + stream.on('end', () => { + resolve(buffer_1.Buffer.concat(chunks)); }); + stream.on('error', (error) => reject(error)); }); - }; - return PubNubFile; - }()), - _a.supportsBlob = false, - _a.supportsFile = false, - _a.supportsBuffer = typeof Buffer !== 'undefined', - _a.supportsStream = true, - _a.supportsString = true, - _a.supportsArrayBuffer = false, - _a.supportsEncryptFile = true, - _a.supportsFileUri = false, - _a); + }); + } + toArrayBuffer() { + return __awaiter(this, void 0, void 0, function* () { + return this.toBuffer().then((buffer) => buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.length)); + }); + } + toString() { + return __awaiter(this, arguments, void 0, function* (encoding = 'utf8') { + return this.toBuffer().then((buffer) => buffer.toString(encoding)); + }); + } + toStream() { + return __awaiter(this, void 0, void 0, function* () { + if (this.data instanceof stream_1.Readable) { + const stream = new stream_1.PassThrough(); + this.data.pipe(stream); + return stream; + } + return this.toBuffer().then((buffer) => new stream_1.Readable({ + read() { + this.push(buffer); + this.push(null); + }, + })); + }); + } + toFile() { + return __awaiter(this, void 0, void 0, function* () { + throw new Error('This feature is only supported in browser environments.'); + }); + } + toFileUri() { + return __awaiter(this, void 0, void 0, function* () { + throw new Error('This feature is only supported in React Native environments.'); + }); + } + toBlob() { + return __awaiter(this, void 0, void 0, function* () { + throw new Error('This feature is only supported in browser environments.'); + }); + } +} +PubNubFile.supportsBlob = false; +PubNubFile.supportsFile = false; +PubNubFile.supportsBuffer = true; +PubNubFile.supportsStream = true; +PubNubFile.supportsString = true; +PubNubFile.supportsArrayBuffer = true; +PubNubFile.supportsEncryptFile = true; +PubNubFile.supportsFileUri = false; exports.default = PubNubFile; diff --git a/lib/file/modules/react-native.js b/lib/file/modules/react-native.js index 6a83eca25..b66464e3a 100644 --- a/lib/file/modules/react-native.js +++ b/lib/file/modules/react-native.js @@ -1,5 +1,4 @@ "use strict"; -/* global File, FileReader */ 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) { @@ -9,207 +8,145 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge 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 (_) 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 _a; Object.defineProperty(exports, "__esModule", { value: true }); -var PubNubFile = (_a = /** @class */ (function () { - function PubNubFile(config) { - if (config instanceof File) { - this.data = config; - this.name = this.data.name; - this.mimeType = this.data.type; +exports.PubNubFile = void 0; +class PubNubFile { + static create(file) { + return new PubNubFile(file); + } + constructor(file) { + let fileData; + let contentLength; + let fileMimeType; + let fileName; + if (file instanceof File) { + fileData = file; + fileName = file.name; + fileMimeType = file.type; + contentLength = file.size; + } + else if ('data' in file) { + const contents = file.data; + fileMimeType = file.mimeType; + fileName = file.name; + fileData = new File([contents], fileName, { type: fileMimeType }); + contentLength = fileData.size; + } + else if ('uri' in file) { + fileMimeType = file.mimeType; + fileName = file.name; + fileData = { + uri: file.uri, + name: file.name, + type: file.mimeType, + }; + } + else + throw new Error("Couldn't construct a file out of supplied options. URI or file data required."); + if (fileData === undefined) + throw new Error("Couldn't construct a file out of supplied options."); + if (fileName === undefined) + throw new Error("Couldn't guess filename out of the options. Please provide one."); + if (contentLength) + this.contentLength = contentLength; + this.mimeType = fileMimeType; + this.data = fileData; + this.name = fileName; + } + toBuffer() { + return __awaiter(this, void 0, void 0, function* () { + throw new Error('This feature is only supported in Node.js environments.'); + }); + } + toArrayBuffer() { + return __awaiter(this, void 0, void 0, function* () { + if (this.data && this.data instanceof File) { + const data = this.data; + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.addEventListener('load', () => { + if (reader.result instanceof ArrayBuffer) + return resolve(reader.result); + }); + reader.addEventListener('error', () => reject(reader.error)); + reader.readAsArrayBuffer(data); + }); } - else if (config.uri) { - // uri upload for react native - this.data = { - uri: config.uri, - name: config.name, - type: config.mimeType, - }; - this.name = config.name; - if (config.mimeType) { - this.mimeType = config.mimeType; - } + else if (this.data && 'uri' in this.data) { + throw new Error('This file contains a file URI and does not contain the file contents.'); } - else if (config.data) { - this.data = config.data; - this.name = config.name; - if (config.mimeType) { - this.mimeType = config.mimeType; + else if (this.data) { + let result; + try { + result = yield this.data.arrayBuffer(); } + catch (error) { + throw new Error(`Unable to support toArrayBuffer in ReactNative environment: ${error}`); + } + return result; } - else { - throw new Error("Couldn't construct a file out of supplied options. URI or file data required."); - } - if (this.data === undefined) { - throw new Error("Couldn't construct a file out of supplied options."); - } - if (this.name === undefined) { - throw new Error("Couldn't guess filename out of the options. Please provide one."); - } - } - PubNubFile.create = function (config) { - return new this(config); - }; - PubNubFile.prototype.toBuffer = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in Node.js environments.'); - }); - }); - }; - PubNubFile.prototype.toStream = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in Node.js environments.'); - }); - }); - }; - PubNubFile.prototype.toBlob = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - if (this.data && this.data.uri) { - throw new Error('This file contains a file URI and does not contain the file contents.'); - } - else if (this.data instanceof File) { - return [2 /*return*/, this.data]; - } - else { - // data must be a fetch response - return [2 /*return*/, this.data.blob()]; - } - return [2 /*return*/]; - }); - }); - }; - PubNubFile.prototype.toArrayBuffer = function () { - return __awaiter(this, void 0, void 0, function () { - var result, e_1; - var _this = this; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - if (!(this.data && this.data.uri)) return [3 /*break*/, 1]; - throw new Error('This file contains a file URI and does not contain the file contents.'); - case 1: - if (!(this.data instanceof File)) return [3 /*break*/, 2]; - return [2 /*return*/, new Promise(function (resolve, reject) { - var reader = new FileReader(); - reader.addEventListener('load', function () { - if (reader.result instanceof ArrayBuffer) { - return resolve(reader.result); - } - }); - reader.addEventListener('error', function () { - reject(reader.error); - }); - reader.readAsArrayBuffer(_this.data); - })]; - case 2: - result = void 0; - _a.label = 3; - case 3: - _a.trys.push([3, 5, , 6]); - return [4 /*yield*/, this.data.arrayBuffer()]; - case 4: - result = _a.sent(); - return [3 /*break*/, 6]; - case 5: - e_1 = _a.sent(); - throw new Error("Unable to support toArrayBuffer in ReactNative environment: ".concat(e_1)); - case 6: return [2 /*return*/, result]; - } - }); - }); - }; - PubNubFile.prototype.toString = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - if (this.data && this.data.uri) { - return [2 /*return*/, JSON.stringify(this.data)]; - } - if (this.data instanceof File) { - return [2 /*return*/, new Promise(function (resolve, reject) { - var reader = new FileReader(); - reader.addEventListener('load', function () { - if (typeof reader.result === 'string') { - return resolve(reader.result); - } - }); - reader.addEventListener('error', function () { - reject(reader.error); - }); - reader.readAsBinaryString(_this.data); - })]; - } - // data must be a fetch response - return [2 /*return*/, this.data.text()]; - }); - }); - }; - PubNubFile.prototype.toFile = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - if (this.data.uri) { - throw new Error('This file contains a file URI and does not contain the file contents.'); - } - else if (this.data instanceof File) { - return [2 /*return*/, this.data]; - } - else { - // data must be a fetch response - return [2 /*return*/, this.data.blob()]; - } - return [2 /*return*/]; - }); - }); - }; - PubNubFile.prototype.toFileUri = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - if (this.data && this.data.uri) { - return [2 /*return*/, this.data]; - } - throw new Error('This file does not contain a file URI'); + throw new Error('Unable convert provided file content type to ArrayBuffer'); + }); + } + toString() { + return __awaiter(this, void 0, void 0, function* () { + if (this.data && 'uri' in this.data) + return JSON.stringify(this.data); + else if (this.data && this.data instanceof File) { + const data = this.data; + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.addEventListener('load', () => { + if (typeof reader.result === 'string') + return resolve(reader.result); + }); + reader.addEventListener('error', () => reject(reader.error)); + reader.readAsBinaryString(data); }); - }); - }; - return PubNubFile; - }()), - _a.supportsFile = typeof File !== 'undefined', - _a.supportsBlob = typeof Blob !== 'undefined', - _a.supportsArrayBuffer = typeof ArrayBuffer !== 'undefined', - _a.supportsBuffer = false, - _a.supportsStream = false, - _a.supportsString = true, - _a.supportsEncryptFile = false, - _a.supportsFileUri = true, - _a); + } + return this.data.text(); + }); + } + toStream() { + return __awaiter(this, void 0, void 0, function* () { + throw new Error('This feature is only supported in Node.js environments.'); + }); + } + toFile() { + return __awaiter(this, void 0, void 0, function* () { + if (this.data instanceof File) + return this.data; + else if ('uri' in this.data) + throw new Error('This file contains a file URI and does not contain the file contents.'); + else + return this.data.blob(); + }); + } + toFileUri() { + return __awaiter(this, void 0, void 0, function* () { + if (this.data && 'uri' in this.data) + return this.data; + throw new Error('This file does not contain a file URI'); + }); + } + toBlob() { + return __awaiter(this, void 0, void 0, function* () { + if (this.data instanceof File) + return this.data; + else if (this.data && 'uri' in this.data) + throw new Error('This file contains a file URI and does not contain the file contents.'); + else + return this.data.blob(); + }); + } +} +exports.PubNubFile = PubNubFile; +PubNubFile.supportsBlob = typeof Blob !== 'undefined'; +PubNubFile.supportsFile = typeof File !== 'undefined'; +PubNubFile.supportsBuffer = false; +PubNubFile.supportsStream = false; +PubNubFile.supportsString = true; +PubNubFile.supportsArrayBuffer = true; +PubNubFile.supportsEncryptFile = false; +PubNubFile.supportsFileUri = true; exports.default = PubNubFile; diff --git a/lib/file/modules/web.js b/lib/file/modules/web.js deleted file mode 100644 index 36be1d830..000000000 --- a/lib/file/modules/web.js +++ /dev/null @@ -1,150 +0,0 @@ -"use strict"; -/* global File, FileReader */ -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 (_) 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 _a; -Object.defineProperty(exports, "__esModule", { value: true }); -var PubNubFile = (_a = /** @class */ (function () { - function PubNubFile(config) { - if (config instanceof File) { - this.data = config; - this.name = this.data.name; - this.mimeType = this.data.type; - } - else if (config.data) { - var contents = config.data; - this.data = new File([contents], config.name, { type: config.mimeType }); - this.name = config.name; - if (config.mimeType) { - this.mimeType = config.mimeType; - } - } - if (this.data === undefined) { - throw new Error("Couldn't construct a file out of supplied options."); - } - if (this.name === undefined) { - throw new Error("Couldn't guess filename out of the options. Please provide one."); - } - } - PubNubFile.create = function (config) { - return new this(config); - }; - PubNubFile.prototype.toBuffer = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in Node.js environments.'); - }); - }); - }; - PubNubFile.prototype.toStream = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in Node.js environments.'); - }); - }); - }; - PubNubFile.prototype.toFileUri = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - throw new Error('This feature is only supported in react native environments.'); - }); - }); - }; - PubNubFile.prototype.toBlob = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, this.data]; - }); - }); - }; - PubNubFile.prototype.toArrayBuffer = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - return [2 /*return*/, new Promise(function (resolve, reject) { - var reader = new FileReader(); - reader.addEventListener('load', function () { - if (reader.result instanceof ArrayBuffer) { - return resolve(reader.result); - } - }); - reader.addEventListener('error', function () { - reject(reader.error); - }); - reader.readAsArrayBuffer(_this.data); - })]; - }); - }); - }; - PubNubFile.prototype.toString = function () { - return __awaiter(this, void 0, void 0, function () { - var _this = this; - return __generator(this, function (_a) { - return [2 /*return*/, new Promise(function (resolve, reject) { - var reader = new FileReader(); - reader.addEventListener('load', function () { - if (typeof reader.result === 'string') { - return resolve(reader.result); - } - }); - reader.addEventListener('error', function () { - reject(reader.error); - }); - reader.readAsBinaryString(_this.data); - })]; - }); - }); - }; - PubNubFile.prototype.toFile = function () { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - return [2 /*return*/, this.data]; - }); - }); - }; - return PubNubFile; - }()), - _a.supportsFile = typeof File !== 'undefined', - _a.supportsBlob = typeof Blob !== 'undefined', - _a.supportsArrayBuffer = typeof ArrayBuffer !== 'undefined', - _a.supportsBuffer = false, - _a.supportsStream = false, - _a.supportsString = true, - _a.supportsEncryptFile = true, - _a.supportsFileUri = false, - _a); -exports.default = PubNubFile; diff --git a/lib/nativescript/index.js b/lib/nativescript/index.js deleted file mode 100644 index 595f49acb..000000000 --- a/lib/nativescript/index.js +++ /dev/null @@ -1,41 +0,0 @@ -"use strict"; -/* */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var pubnub_common_1 = __importDefault(require("../core/pubnub-common")); -var networking_1 = __importDefault(require("../networking")); -var common_1 = __importDefault(require("../db/common")); -var nativescript_1 = require("../networking/modules/nativescript"); -var default_1 = /** @class */ (function (_super) { - __extends(default_1, _super); - function default_1(setup) { - setup.db = new common_1.default(); - setup.networking = new networking_1.default({ - del: nativescript_1.del, - get: nativescript_1.get, - post: nativescript_1.post, - patch: nativescript_1.patch, - }); - setup.sdkFamily = 'NativeScript'; - return _super.call(this, setup) || this; - } - return default_1; -}(pubnub_common_1.default)); -exports.default = default_1; diff --git a/lib/networking/index.js b/lib/networking/index.js deleted file mode 100644 index 2b25c9249..000000000 --- a/lib/networking/index.js +++ /dev/null @@ -1,102 +0,0 @@ -"use strict"; -/* */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var categories_1 = __importDefault(require("../core/constants/categories")); -var default_1 = /** @class */ (function () { - function default_1(modules) { - var _this = this; - this._modules = {}; - Object.keys(modules).forEach(function (key) { - _this._modules[key] = modules[key].bind(_this); - }); - } - default_1.prototype.init = function (config) { - this._config = config; - if (Array.isArray(this._config.origin)) { - this._currentSubDomain = Math.floor(Math.random() * this._config.origin.length); - } - else { - this._currentSubDomain = 0; - } - this._coreParams = {}; - // create initial origins - this.shiftStandardOrigin(); - }; - default_1.prototype.nextOrigin = function () { - var protocol = this._config.secure ? 'https://' : 'http://'; - if (typeof this._config.origin === 'string') { - return "".concat(protocol).concat(this._config.origin); - } - this._currentSubDomain += 1; - if (this._currentSubDomain >= this._config.origin.length) { - this._currentSubDomain = 0; - } - var origin = this._config.origin[this._currentSubDomain]; - return "".concat(protocol).concat(origin); - }; - default_1.prototype.hasModule = function (name) { - return name in this._modules; - }; - // origin operations - default_1.prototype.shiftStandardOrigin = function () { - this._standardOrigin = this.nextOrigin(); - return this._standardOrigin; - }; - default_1.prototype.getStandardOrigin = function () { - return this._standardOrigin; - }; - default_1.prototype.POSTFILE = function (url, fields, file) { - return this._modules.postfile(url, fields, file); - }; - default_1.prototype.GETFILE = function (params, endpoint, callback) { - return this._modules.getfile(params, endpoint, callback); - }; - default_1.prototype.POST = function (params, body, endpoint, callback) { - return this._modules.post(params, body, endpoint, callback); - }; - default_1.prototype.PATCH = function (params, body, endpoint, callback) { - return this._modules.patch(params, body, endpoint, callback); - }; - default_1.prototype.GET = function (params, endpoint, callback) { - return this._modules.get(params, endpoint, callback); - }; - default_1.prototype.DELETE = function (params, endpoint, callback) { - return this._modules.del(params, endpoint, callback); - }; - default_1.prototype._detectErrorCategory = function (err) { - if (err.code === 'ENOTFOUND') { - return categories_1.default.PNNetworkIssuesCategory; - } - if (err.code === 'ECONNREFUSED') { - return categories_1.default.PNNetworkIssuesCategory; - } - if (err.code === 'ECONNRESET') { - return categories_1.default.PNNetworkIssuesCategory; - } - if (err.code === 'EAI_AGAIN') { - return categories_1.default.PNNetworkIssuesCategory; - } - if (err.status === 0 || (err.hasOwnProperty('status') && typeof err.status === 'undefined')) { - return categories_1.default.PNNetworkIssuesCategory; - } - if (err.timeout) - return categories_1.default.PNTimeoutCategory; - if (err.code === 'ETIMEDOUT') { - return categories_1.default.PNNetworkIssuesCategory; - } - if (err.response) { - if (err.response.badRequest) { - return categories_1.default.PNBadRequestCategory; - } - if (err.response.forbidden) { - return categories_1.default.PNAccessDeniedCategory; - } - } - return categories_1.default.PNUnknownCategory; - }; - return default_1; -}()); -exports.default = default_1; diff --git a/lib/networking/modules/nativescript.js b/lib/networking/modules/nativescript.js deleted file mode 100644 index 3f8c3c568..000000000 --- a/lib/networking/modules/nativescript.js +++ /dev/null @@ -1,78 +0,0 @@ -"use strict"; -/* */ -Object.defineProperty(exports, "__esModule", { value: true }); -exports.del = exports.patch = exports.post = exports.get = void 0; -var http_1 = require("http"); -var utils_1 = require("../utils"); -function log(url, qs, res) { - var _pickLogger = function () { - if (console && console.log) - return console; // eslint-disable-line no-console - return console; - }; - var start = new Date().getTime(); - var timestamp = new Date().toISOString(); - var logger = _pickLogger(); - logger.log('<<<<<'); // eslint-disable-line no-console - logger.log("[".concat(timestamp, "]"), '\n', url, '\n', qs); // eslint-disable-line no-console - logger.log('-----'); // eslint-disable-line no-console - var now = new Date().getTime(); - var elapsed = now - start; - var timestampDone = new Date().toISOString(); - logger.log('>>>>>>'); // eslint-disable-line no-console - logger.log("[".concat(timestampDone, " / ").concat(elapsed, "]"), '\n', url, '\n', qs, '\n', res); // eslint-disable-line no-console - logger.log('-----'); // eslint-disable-line no-console -} -function xdr(method, url, params, body, endpoint, callback) { - var _this = this; - var status = {}; - status.operation = endpoint.operation; - var httpConfig = { - method: method, - url: (0, utils_1.buildUrl)(url, params), - timeout: endpoint.timeout, - content: body, - }; - // $FlowFixMe - return (0, http_1.request)(httpConfig) - .then(function (response) { - status.error = false; - if (response.statusCode) { - status.statusCode = response.statusCode; - } - return response.content.toJSON(); - }) - .then(function (response) { - var resp = response; - if (_this._config.logVerbosity) { - log(url, params, resp); - } - callback(status, resp); - }) - .catch(function (e) { - status.error = true; - status.errorData = e; - status.category = _this._detectErrorCategory(e); - callback(status, null); - }); -} -function get(params, endpoint, callback) { - var url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, 'GET', url, params, '', endpoint, callback); -} -exports.get = get; -function post(params, body, endpoint, callback) { - var url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, 'POST', url, params, body, endpoint, callback); -} -exports.post = post; -function patch(params, body, endpoint, callback) { - var url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, 'PATCH', url, params, body, endpoint, callback); -} -exports.patch = patch; -function del(params, endpoint, callback) { - var url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, 'DELETE', url, params, '', endpoint, callback); -} -exports.del = del; diff --git a/lib/networking/modules/node.js b/lib/networking/modules/node.js deleted file mode 100644 index 08fecd318..000000000 --- a/lib/networking/modules/node.js +++ /dev/null @@ -1,31 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.keepAlive = exports.proxy = void 0; -var superagent_1 = __importDefault(require("superagent")); -var agentkeepalive_1 = __importDefault(require("agentkeepalive")); -var proxyAgent_1 = __importDefault(require("../proxyAgent")); -var keepAliveAgent = null; -var keepAliveSecureAgent = null; -(0, proxyAgent_1.default)(superagent_1.default); -function proxy(superagentConstruct) { - return superagentConstruct.proxy(this._config.proxy); -} -exports.proxy = proxy; -function keepAlive(superagentConstruct) { - var agent = this._config.secure ? keepAliveSecureAgent : keepAliveAgent; - if (agent === null) { - var AgentClass = this._config.secure ? agentkeepalive_1.default.HttpsAgent : agentkeepalive_1.default; - agent = new AgentClass(this._config.keepAliveSettings); - if (this._config.secure) { - keepAliveSecureAgent = agent; - } - else { - keepAliveAgent = agent; - } - } - return superagentConstruct.agent(agent); -} -exports.keepAlive = keepAlive; diff --git a/lib/networking/modules/react_native.js b/lib/networking/modules/react_native.js deleted file mode 100644 index 34b26ba0d..000000000 --- a/lib/networking/modules/react_native.js +++ /dev/null @@ -1,164 +0,0 @@ -"use strict"; -/* */ -/* global FormData */ -/* global fetch */ -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 (_) 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 }); -exports.getfile = exports.postfile = void 0; -var web_node_1 = require("./web-node"); -function postfileuri(url, fields, fileInput) { - return __awaiter(this, void 0, void 0, function () { - var formData, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - formData = new FormData(); - fields.forEach(function (_a) { - var key = _a.key, value = _a.value; - formData.append(key, value); - }); - formData.append('file', fileInput); - return [4 /*yield*/, fetch(url, { - method: 'POST', - body: formData, - })]; - case 1: - result = _a.sent(); - return [2 /*return*/, result]; - } - }); - }); -} -function postfile(url, fields, fileInput) { - return __awaiter(this, void 0, void 0, function () { - return __generator(this, function (_a) { - if (!fileInput.uri) { - return [2 /*return*/, (0, web_node_1.postfile)(url, fields, fileInput)]; - } - return [2 /*return*/, postfileuri(url, fields, fileInput)]; - }); - }); -} -exports.postfile = postfile; -function getfile(params, endpoint, callback) { - var _this = this; - var url = this.getStandardOrigin() + endpoint.url; - if (params && Object.keys(params).length > 0) { - var searchParams = new URLSearchParams(params); - if (endpoint.url.indexOf('?') > -1) { - url += '&'; - } - else { - url += '?'; - } - url += searchParams.toString(); - } - var fetchResult = fetch(url, { method: 'GET', headers: endpoint.headers }); - fetchResult.then(function (resp) { return __awaiter(_this, void 0, void 0, function () { - var parsedResponse, status, _a, _b, e_1; - return __generator(this, function (_c) { - switch (_c.label) { - case 0: - status = {}; - status.error = false; - status.operation = endpoint.operation; - if (resp && resp.status) { - status.statusCode = resp.status; - } - if (!endpoint.ignoreBody) return [3 /*break*/, 1]; - parsedResponse = { - headers: resp.headers, - redirects: [], - response: resp, - }; - return [3 /*break*/, 4]; - case 1: - _c.trys.push([1, 3, , 4]); - _b = (_a = JSON).parse; - return [4 /*yield*/, resp.text()]; - case 2: - parsedResponse = _b.apply(_a, [_c.sent()]); - return [3 /*break*/, 4]; - case 3: - e_1 = _c.sent(); - status.errorData = resp; - status.error = true; - return [2 /*return*/, callback(status, null)]; - case 4: - if (parsedResponse.error && - parsedResponse.error === 1 && - parsedResponse.status && - parsedResponse.message && - parsedResponse.service) { - status.errorData = parsedResponse; - status.statusCode = parsedResponse.status; - status.error = true; - status.category = this._detectErrorCategory(status); - return [2 /*return*/, callback(status, null)]; - } - if (parsedResponse.error && parsedResponse.error.message) { - status.errorData = parsedResponse.error; - } - // returning the entire response in order to use response methods for - // reading the body in react native because the response.body - // is a ReadableStream which doesn't seem to be reliable on ios and android - return [2 /*return*/, callback(status, { response: { body: resp } })]; - } - }); - }); }); - fetchResult.catch(function (err) { - var status = {}; - status.error = true; - status.operation = endpoint.operation; - if (err.response && err.response.text && !_this._config.logVerbosity) { - try { - status.errorData = JSON.parse(err.response.text); - } - catch (e) { - status.errorData = err; - } - } - else { - status.errorData = err; - } - status.category = _this._detectErrorCategory(err); - return callback(status, null); - }); - return fetchResult; -} -exports.getfile = getfile; diff --git a/lib/networking/modules/titanium.js b/lib/networking/modules/titanium.js deleted file mode 100644 index 41975a4f0..000000000 --- a/lib/networking/modules/titanium.js +++ /dev/null @@ -1,86 +0,0 @@ -"use strict"; -/* */ -/* global XMLHttpRequest, Ti */ -Object.defineProperty(exports, "__esModule", { value: true }); -exports.del = exports.patch = exports.post = exports.get = void 0; -var utils_1 = require("../utils"); -function log(url, qs, res) { - var _pickLogger = function () { - if (Ti && Ti.API && Ti.API.log) - return Ti.API; - return console; - }; - var start = new Date().getTime(); - var timestamp = new Date().toISOString(); - var logger = _pickLogger(); - logger.log('<<<<<'); // eslint-disable-line no-console - logger.log("[".concat(timestamp, "]"), '\n', url, '\n', qs); // eslint-disable-line no-console - logger.log('-----'); // eslint-disable-line no-console - var now = new Date().getTime(); - var elapsed = now - start; - var timestampDone = new Date().toISOString(); - logger.log('>>>>>>'); // eslint-disable-line no-console - logger.log("[".concat(timestampDone, " / ").concat(elapsed, "]"), '\n', url, '\n', qs, '\n', res); // eslint-disable-line no-console - logger.log('-----'); -} -function getHttpClient() { - if (Ti.Platform.osname === 'mobileweb') { - return new XMLHttpRequest(); - } - return Ti.Network.createHTTPClient(); -} -function keepAlive(xhr) { - if (Ti.Platform.osname !== 'mobileweb' && this._config.keepAlive) { - xhr.enableKeepAlive = true; - } -} -function xdr(xhr, method, url, params, body, endpoint, callback) { - var _this = this; - var status = {}; - status.operation = endpoint.operation; - xhr.open(method, (0, utils_1.buildUrl)(url, params), true); - keepAlive.call(this, xhr); - xhr.onload = function () { - status.error = false; - if (xhr.status) { - status.statusCode = xhr.status; - } - var resp = JSON.parse(xhr.responseText); - if (_this._config.logVerbosity) { - log(url, params, xhr.responseText); - } - return callback(status, resp); - }; - xhr.onerror = function (e) { - status.error = true; - status.errorData = e.error; - status.category = _this._detectErrorCategory(e.error); - return callback(status, null); - }; - xhr.timeout = Ti.Platform.osname === 'android' ? 2147483647 : Infinity; - xhr.send(body); -} -function get(params, endpoint, callback) { - var xhr = getHttpClient(); - var url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, xhr, 'GET', url, params, {}, endpoint, callback); -} -exports.get = get; -function post(params, body, endpoint, callback) { - var xhr = getHttpClient(); - var url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, xhr, 'POST', url, params, JSON.parse(body), endpoint, callback); -} -exports.post = post; -function patch(params, body, endpoint, callback) { - var xhr = getHttpClient(); - var url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, xhr, 'PATCH', url, params, JSON.parse(body), endpoint, callback); -} -exports.patch = patch; -function del(params, endpoint, callback) { - var xhr = getHttpClient(); - var url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, xhr, 'DELETE', url, params, {}, endpoint, callback); -} -exports.del = del; diff --git a/lib/networking/modules/web-node.js b/lib/networking/modules/web-node.js deleted file mode 100644 index 55b14d860..000000000 --- a/lib/networking/modules/web-node.js +++ /dev/null @@ -1,228 +0,0 @@ -"use strict"; -/* */ -/* global window */ -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 (_) 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) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.del = exports.patch = exports.post = exports.get = exports.getfile = exports.postfile = void 0; -var superagent_1 = __importDefault(require("superagent")); -var categories_1 = __importDefault(require("../../core/constants/categories")); -function log(req) { - var _pickLogger = function () { - if (console && console.log) - return console; // eslint-disable-line no-console - if (window && window.console && window.console.log) - return window.console; - return console; - }; - var start = new Date().getTime(); - var timestamp = new Date().toISOString(); - var logger = _pickLogger(); - logger.log('<<<<<'); - logger.log("[".concat(timestamp, "]"), '\n', req.url, '\n', req.qs); - logger.log('-----'); - req.on('response', function (res) { - var now = new Date().getTime(); - var elapsed = now - start; - var timestampDone = new Date().toISOString(); - logger.log('>>>>>>'); - logger.log("[".concat(timestampDone, " / ").concat(elapsed, "]"), '\n', req.url, '\n', req.qs, '\n', res.text); - logger.log('-----'); - }); -} -function xdr(superagentConstruct, endpoint, callback) { - var _this = this; - if (this._config.logVerbosity) { - superagentConstruct = superagentConstruct.use(log); - } - if (this._config.proxy && this._modules.proxy) { - superagentConstruct = this._modules.proxy.call(this, superagentConstruct); - } - if (this._config.keepAlive && this._modules.keepAlive) { - superagentConstruct = this._modules.keepAlive(superagentConstruct); - } - var sc = superagentConstruct; - if (endpoint.abortSignal) { - var unsubscribe_1 = endpoint.abortSignal.subscribe(function () { - sc.abort(); - unsubscribe_1(); - }); - } - if (endpoint.forceBuffered === true) { - if (typeof Blob === 'undefined') { - sc = sc.buffer().responseType('arraybuffer'); - } - else { - sc = sc.responseType('arraybuffer'); - } - } - else if (endpoint.forceBuffered === false) { - sc = sc.buffer(false); - } - sc = sc.timeout(endpoint.timeout); - sc.on('abort', function () { - return callback({ - category: categories_1.default.PNUnknownCategory, - error: true, - operation: endpoint.operation, - errorData: new Error('Aborted'), - }, null); - }); - sc.end(function (err, resp) { - var parsedResponse; - var status = {}; - status.error = err !== null; - status.operation = endpoint.operation; - if (resp && resp.status) { - status.statusCode = resp.status; - } - if (err) { - if (err.response && err.response.text && !_this._config.logVerbosity) { - try { - status.errorData = JSON.parse(err.response.text); - } - catch (e) { - status.errorData = err; - } - } - else { - status.errorData = err; - } - status.category = _this._detectErrorCategory(err); - return callback(status, null); - } - if (endpoint.ignoreBody) { - parsedResponse = { - headers: resp.headers, - redirects: resp.redirects, - response: resp, - }; - } - else { - try { - parsedResponse = JSON.parse(resp.text); - } - catch (e) { - status.errorData = resp; - status.error = true; - return callback(status, null); - } - } - if (parsedResponse.error && - parsedResponse.error === 1 && - parsedResponse.status && - parsedResponse.message && - parsedResponse.service) { - status.errorData = parsedResponse; - status.statusCode = parsedResponse.status; - status.error = true; - status.category = _this._detectErrorCategory(status); - return callback(status, null); - } - if (parsedResponse.error && parsedResponse.error.message) { - status.errorData = parsedResponse.error; - } - return callback(status, parsedResponse); - }); - return sc; -} -function postfile(url, fields, fileInput) { - return __awaiter(this, void 0, void 0, function () { - var agent, result; - return __generator(this, function (_a) { - switch (_a.label) { - case 0: - agent = superagent_1.default.post(url); - fields.forEach(function (_a) { - var key = _a.key, value = _a.value; - agent = agent.field(key, value); - }); - agent.attach('file', fileInput, { contentType: 'application/octet-stream' }); - return [4 /*yield*/, agent]; - case 1: - result = _a.sent(); - return [2 /*return*/, result]; - } - }); - }); -} -exports.postfile = postfile; -function getfile(params, endpoint, callback) { - var superagentConstruct = superagent_1.default - .get(this.getStandardOrigin() + endpoint.url) - .set(endpoint.headers) - .query(params); - return xdr.call(this, superagentConstruct, endpoint, callback); -} -exports.getfile = getfile; -function get(params, endpoint, callback) { - var superagentConstruct = superagent_1.default - .get(this.getStandardOrigin() + endpoint.url) - .set(endpoint.headers) - .query(params); - return xdr.call(this, superagentConstruct, endpoint, callback); -} -exports.get = get; -function post(params, body, endpoint, callback) { - var superagentConstruct = superagent_1.default - .post(this.getStandardOrigin() + endpoint.url) - .query(params) - .set(endpoint.headers) - .send(body); - return xdr.call(this, superagentConstruct, endpoint, callback); -} -exports.post = post; -function patch(params, body, endpoint, callback) { - var superagentConstruct = superagent_1.default - .patch(this.getStandardOrigin() + endpoint.url) - .query(params) - .set(endpoint.headers) - .send(body); - return xdr.call(this, superagentConstruct, endpoint, callback); -} -exports.patch = patch; -function del(params, endpoint, callback) { - var superagentConstruct = superagent_1.default - .delete(this.getStandardOrigin() + endpoint.url) - .set(endpoint.headers) - .query(params); - return xdr.call(this, superagentConstruct, endpoint, callback); -} -exports.del = del; diff --git a/lib/networking/proxyAgent.js b/lib/networking/proxyAgent.js deleted file mode 100644 index dd7feee08..000000000 --- a/lib/networking/proxyAgent.js +++ /dev/null @@ -1,15 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -var proxy_agent_1 = require("proxy-agent"); -function default_1(superagent) { - var Request = superagent.Request; - Request.prototype.proxy = proxy; - return superagent; -} -exports.default = default_1; -function proxy(proxyConfiguration) { - var agent = new proxy_agent_1.ProxyAgent(proxyConfiguration); - if (agent) - this.agent(agent); - return this; -} diff --git a/lib/networking/utils.js b/lib/networking/utils.js deleted file mode 100644 index a554841c8..000000000 --- a/lib/networking/utils.js +++ /dev/null @@ -1,33 +0,0 @@ -"use strict"; -/* */ -Object.defineProperty(exports, "__esModule", { value: true }); -exports.buildUrl = exports.encodedKeyValuePair = void 0; -function encodedKeyValuePair(pairs, key, value) { - if (value != null) { - if (Array.isArray(value)) { - value.forEach(function (item) { - encodedKeyValuePair(pairs, key, item); - }); - } - else if (typeof value === 'object') { - Object.keys(value).forEach(function (subkey) { - encodedKeyValuePair(pairs, "".concat(key, "[").concat(subkey, "]"), value[subkey]); - }); - } - else { - pairs.push("".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value))); - } - } - else if (value === null) { - pairs.push(encodeURIComponent("".concat(encodeURIComponent(key)))); - } -} -exports.encodedKeyValuePair = encodedKeyValuePair; -function buildUrl(url, params) { - var pairs = []; - Object.keys(params).forEach(function (key) { - encodedKeyValuePair(pairs, key, params[key]); - }); - return "".concat(url, "?").concat(pairs.join('&')); -} -exports.buildUrl = buildUrl; diff --git a/lib/node/configuration.js b/lib/node/configuration.js new file mode 100644 index 000000000..2bdbc0ccc --- /dev/null +++ b/lib/node/configuration.js @@ -0,0 +1,10 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.setDefaults = void 0; +const configuration_1 = require("../core/interfaces/configuration"); +const KEEP_ALIVE = false; +const setDefaults = (configuration) => { + var _a; + return Object.assign(Object.assign({}, (0, configuration_1.setDefaults)(configuration)), { keepAlive: (_a = configuration.keepAlive) !== null && _a !== void 0 ? _a : KEEP_ALIVE }); +}; +exports.setDefaults = setDefaults; diff --git a/lib/node/index.js b/lib/node/index.js index 7f463e5fa..5fd5e321e 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -1,65 +1,67 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; var _a; -var cbor_sync_1 = __importDefault(require("cbor-sync")); -var pubnub_common_1 = __importDefault(require("../core/pubnub-common")); -var networking_1 = __importDefault(require("../networking")); -var common_1 = __importDefault(require("../cbor/common")); -var base64_codec_1 = require("../core/components/base64_codec"); -var web_node_1 = require("../networking/modules/web-node"); -var node_1 = require("../networking/modules/node"); -var node_2 = __importDefault(require("../crypto/modules/node")); -var node_3 = __importDefault(require("../file/modules/node")); -var nodeCryptoModule_1 = require("../crypto/modules/NodeCryptoModule/nodeCryptoModule"); -module.exports = (_a = /** @class */ (function (_super) { - __extends(class_1, _super); - function class_1(setup) { - setup.cbor = new common_1.default(function (buffer) { return cbor_sync_1.default.decode(Buffer.from(buffer)); }, base64_codec_1.decode); - setup.networking = new networking_1.default({ - keepAlive: node_1.keepAlive, - del: web_node_1.del, - get: web_node_1.get, - post: web_node_1.post, - patch: web_node_1.patch, - proxy: node_1.proxy, - getfile: web_node_1.getfile, - postfile: web_node_1.postfile, - }); - setup.sdkFamily = 'Nodejs'; - setup.PubNubFile = node_3.default; - setup.cryptography = new node_2.default(); - setup.initCryptoModule = function (cryptoConfiguration) { +const cbor_sync_1 = __importDefault(require("cbor-sync")); +const buffer_1 = require("buffer"); +const nodeCryptoModule_1 = require("../crypto/modules/NodeCryptoModule/nodeCryptoModule"); +const node_1 = __importDefault(require("../file/modules/node")); +const configuration_1 = require("../core/components/configuration"); +const configuration_2 = require("./configuration"); +const token_manager_1 = require("../core/components/token_manager"); +const node_transport_1 = require("../transport/node-transport"); +const middleware_1 = require("../transport/middleware"); +const base64_codec_1 = require("../core/components/base64_codec"); +const node_2 = __importDefault(require("../crypto/modules/node")); +const cryptography_1 = __importDefault(require("../core/components/cryptography")); +const pubnub_error_1 = require("../errors/pubnub-error"); +const pubnub_common_1 = require("../core/pubnub-common"); +const common_1 = __importDefault(require("../cbor/common")); +module.exports = (_a = class PubNub extends pubnub_common_1.PubNubCore { + constructor(configuration) { + const configurationCopy = (0, configuration_2.setDefaults)(configuration); + const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'Nodejs', PubNubFile: node_1.default }); + const clientConfiguration = (0, configuration_1.makeConfiguration)(platformConfiguration, (cryptoConfiguration) => { + if (!cryptoConfiguration.cipherKey) + return undefined; return new nodeCryptoModule_1.CryptoModule({ - default: new nodeCryptoModule_1.LegacyCryptor({ - cipherKey: cryptoConfiguration.cipherKey, - useRandomIVs: cryptoConfiguration.useRandomIVs, - }), + default: new nodeCryptoModule_1.LegacyCryptor(Object.assign({}, cryptoConfiguration)), cryptors: [new nodeCryptoModule_1.AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], }); - }; - if (!('ssl' in setup)) { - setup.ssl = true; - } - return _super.call(this, setup) || this; + }); + const tokenManager = new token_manager_1.TokenManager(new common_1.default((buffer) => cbor_sync_1.default.decode(buffer_1.Buffer.from(buffer)), base64_codec_1.decode)); + const crypto = new cryptography_1.default({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + const transport = new node_transport_1.NodeTransport(configuration.keepAlive, configuration.keepAliveSettings); + const transportMiddleware = new middleware_1.PubNubMiddleware({ + clientConfiguration, + tokenManager, + transport, + shaHMAC: crypto === null || crypto === void 0 ? void 0 : crypto.HMACSHA256.bind(crypto), + }); + super({ + configuration: clientConfiguration, + transport: transportMiddleware, + cryptography: new node_2.default(), + tokenManager, + crypto, + }); + this.File = node_1.default; + this.nodeTransport = transport; + } + setProxy(configuration) { + var _b; + if (configuration && ((_b = this._configuration.keepAlive) !== null && _b !== void 0 ? _b : false)) + throw new pubnub_error_1.PubNubError("Can't set 'proxy' because already configured for 'keepAlive'"); + this.nodeTransport.setProxy(configuration); + this.reconnect(); } - return class_1; - }(pubnub_common_1.default)), + }, _a.CryptoModule = nodeCryptoModule_1.CryptoModule, _a); diff --git a/lib/react_native/configuration.js b/lib/react_native/configuration.js new file mode 100644 index 000000000..3d4e24615 --- /dev/null +++ b/lib/react_native/configuration.js @@ -0,0 +1,8 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.setDefaults = void 0; +const configuration_1 = require("../core/interfaces/configuration"); +const setDefaults = (configuration) => { + return (0, configuration_1.setDefaults)(configuration); +}; +exports.setDefaults = setDefaults; diff --git a/lib/react_native/index.js b/lib/react_native/index.js index 8c1e501cb..7345921f2 100644 --- a/lib/react_native/index.js +++ b/lib/react_native/index.js @@ -1,51 +1,53 @@ "use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -var cbor_js_1 = __importDefault(require("cbor-js")); -var buffer_1 = require("buffer"); -var pubnub_common_1 = __importDefault(require("../core/pubnub-common")); -var networking_1 = __importDefault(require("../networking")); -var base64_codec_1 = require("../core/components/base64_codec"); -var stringify_buffer_keys_1 = require("../core/components/stringify_buffer_keys"); -var common_1 = __importDefault(require("../cbor/common")); -var web_node_1 = require("../networking/modules/web-node"); -var react_native_1 = require("../networking/modules/react_native"); -var react_native_2 = __importDefault(require("../file/modules/react-native")); +const text_encoding_1 = require("text-encoding"); +require("react-native-url-polyfill/auto"); +const cbor_js_1 = __importDefault(require("cbor-js")); +const buffer_1 = require("buffer"); +const web_react_native_transport_1 = require("../transport/web-react-native-transport"); +const stringify_buffer_keys_1 = require("../core/components/stringify_buffer_keys"); +const configuration_1 = require("../core/components/configuration"); +const token_manager_1 = require("../core/components/token_manager"); +const middleware_1 = require("../transport/middleware"); +const base64_codec_1 = require("../core/components/base64_codec"); +const react_native_1 = __importDefault(require("../file/modules/react-native")); +const cryptography_1 = __importDefault(require("../core/components/cryptography")); +const pubnub_common_1 = require("../core/pubnub-common"); +const configuration_2 = require("./configuration"); +const common_1 = __importDefault(require("../cbor/common")); +global.TextEncoder = global.TextEncoder || text_encoding_1.TextEncoder; +global.TextDecoder = global.TextDecoder || text_encoding_1.TextDecoder; global.Buffer = global.Buffer || buffer_1.Buffer; -var default_1 = /** @class */ (function (_super) { - __extends(default_1, _super); - function default_1(setup) { - setup.cbor = new common_1.default(function (arrayBuffer) { return (0, stringify_buffer_keys_1.stringifyBufferKeys)(cbor_js_1.default.decode(arrayBuffer)); }, base64_codec_1.decode); - setup.PubNubFile = react_native_2.default; - setup.networking = new networking_1.default({ - del: web_node_1.del, - get: web_node_1.get, - post: web_node_1.post, - patch: web_node_1.patch, - getfile: react_native_1.getfile, - postfile: react_native_1.postfile, +class PubNub extends pubnub_common_1.PubNubCore { + constructor(configuration) { + const configurationCopy = (0, configuration_2.setDefaults)(configuration); + const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'ReactNative', PubNubFile: react_native_1.default }); + const clientConfiguration = (0, configuration_1.makeConfiguration)(platformConfiguration); + const tokenManager = new token_manager_1.TokenManager(new common_1.default((arrayBuffer) => (0, stringify_buffer_keys_1.stringifyBufferKeys)(cbor_js_1.default.decode(arrayBuffer)), base64_codec_1.decode)); + let crypto; + if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { + crypto = new cryptography_1.default({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } + const transportMiddleware = new middleware_1.PubNubMiddleware({ + clientConfiguration, + tokenManager, + transport: new web_react_native_transport_1.WebReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity), + }); + super({ + configuration: clientConfiguration, + transport: transportMiddleware, + tokenManager, + crypto, }); - setup.sdkFamily = 'ReactNative'; - setup.ssl = true; - return _super.call(this, setup) || this; } - return default_1; -}(pubnub_common_1.default)); -exports.default = default_1; +} +exports.default = PubNub; diff --git a/lib/titanium/index.js b/lib/titanium/index.js deleted file mode 100644 index f577196b7..000000000 --- a/lib/titanium/index.js +++ /dev/null @@ -1,42 +0,0 @@ -"use strict"; -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = void 0; -var cbor_sync_1 = __importDefault(require("cbor-sync")); -var pubnub_common_1 = __importDefault(require("../core/pubnub-common")); -var networking_1 = __importDefault(require("../networking")); -var common_1 = __importDefault(require("../cbor/common")); -var titanium_1 = require("../networking/modules/titanium"); -var PubNub = /** @class */ (function (_super) { - __extends(PubNub, _super); - function PubNub(setup) { - setup.cbor = new common_1.default(cbor_sync_1.default.decode, function (base64String) { return Buffer.from(base64String, 'base64'); }); - setup.sdkFamily = 'TitaniumSDK'; - setup.networking = new networking_1.default({ - del: titanium_1.del, - get: titanium_1.get, - post: titanium_1.post, - patch: titanium_1.patch, - }); - return _super.call(this, setup) || this; - } - return PubNub; -}(pubnub_common_1.default)); -exports.default = PubNub; diff --git a/lib/transport/middleware.js b/lib/transport/middleware.js new file mode 100644 index 000000000..7433a00a1 --- /dev/null +++ b/lib/transport/middleware.js @@ -0,0 +1,106 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.PubNubMiddleware = exports.RequestSignature = void 0; +const transport_request_1 = require("../core/types/transport-request"); +const utils_1 = require("../core/utils"); +class RequestSignature { + constructor(publishKey, secretKey, hasher) { + this.publishKey = publishKey; + this.secretKey = secretKey; + this.hasher = hasher; + } + signature(req) { + const method = req.path.startsWith('/publish') ? transport_request_1.TransportMethod.GET : req.method; + let signatureInput = `${method}\n${this.publishKey}\n${req.path}\n${this.queryParameters(req.queryParameters)}\n`; + if (method === transport_request_1.TransportMethod.POST || method === transport_request_1.TransportMethod.PATCH) { + const body = req.body; + let payload; + if (body && body instanceof ArrayBuffer) { + payload = RequestSignature.textDecoder.decode(body); + } + else if (body && typeof body !== 'object') { + payload = body; + } + if (payload) + signatureInput += payload; + } + return `v2.${this.hasher(signatureInput, this.secretKey)}` + .replace(/\+/g, '-') + .replace(/\//g, '_') + .replace(/=+$/, ''); + } + queryParameters(query) { + return Object.keys(query) + .sort() + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${(0, utils_1.encodeString)(queryValue)}`; + return queryValue + .sort() + .map((value) => `${key}=${(0, utils_1.encodeString)(value)}`) + .join('&'); + }) + .join('&'); + } +} +exports.RequestSignature = RequestSignature; +RequestSignature.textDecoder = new TextDecoder('utf-8'); +class PubNubMiddleware { + constructor(configuration) { + this.configuration = configuration; + const { clientConfiguration: { keySet }, shaHMAC, } = configuration; + if (keySet.secretKey && shaHMAC) + this.signatureGenerator = new RequestSignature(keySet.publishKey, keySet.secretKey, shaHMAC); + } + makeSendable(req) { + return this.configuration.transport.makeSendable(this.request(req)); + } + request(req) { + var _a; + const { clientConfiguration } = this.configuration; + req = this.configuration.transport.request(req); + if (!req.queryParameters) + req.queryParameters = {}; + if (clientConfiguration.useInstanceId) + req.queryParameters['instanceid'] = clientConfiguration.instanceId; + if (!req.queryParameters['uuid']) + req.queryParameters['uuid'] = clientConfiguration.userId; + if (clientConfiguration.useRequestId) + req.queryParameters['requestid'] = req.identifier; + req.queryParameters['pnsdk'] = this.generatePNSDK(); + (_a = req.origin) !== null && _a !== void 0 ? _a : (req.origin = clientConfiguration.origin); + this.authenticateRequest(req); + this.signRequest(req); + return req; + } + authenticateRequest(req) { + var _a; + if (req.path.startsWith('/v2/auth/') || req.path.startsWith('/v3/pam/') || req.path.startsWith('/time')) + return; + const { clientConfiguration, tokenManager } = this.configuration; + const accessKey = (_a = tokenManager.getToken()) !== null && _a !== void 0 ? _a : clientConfiguration.authKey; + if (accessKey) + req.queryParameters['auth'] = accessKey; + } + signRequest(req) { + if (!this.signatureGenerator || req.path.startsWith('/time')) + return; + req.queryParameters['timestamp'] = String(Math.floor(new Date().getTime() / 1000)); + req.queryParameters['signature'] = this.signatureGenerator.signature(req); + } + generatePNSDK() { + const { clientConfiguration } = this.configuration; + if (clientConfiguration.sdkName) + return clientConfiguration.sdkName; + let base = `PubNub-JS-${clientConfiguration.sdkFamily}`; + if (clientConfiguration.partnerId) + base += `-${clientConfiguration.partnerId}`; + base += `/${clientConfiguration.getVersion()}`; + const pnsdkSuffix = clientConfiguration._getPnsdkSuffix(' '); + if (pnsdkSuffix.length > 0) + base += pnsdkSuffix; + return base; + } +} +exports.PubNubMiddleware = PubNubMiddleware; diff --git a/lib/transport/node-transport.js b/lib/transport/node-transport.js new file mode 100644 index 000000000..80418e7c2 --- /dev/null +++ b/lib/transport/node-transport.js @@ -0,0 +1,162 @@ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +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 __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.NodeTransport = void 0; +const node_fetch_1 = __importStar(require("node-fetch")); +const proxy_agent_1 = require("proxy-agent"); +const https_1 = require("https"); +const http_1 = require("http"); +const form_data_1 = __importDefault(require("form-data")); +const buffer_1 = require("buffer"); +const pubnub_api_error_1 = require("../errors/pubnub-api-error"); +const utils_1 = require("../core/utils"); +class NodeTransport { + constructor(keepAlive = false, keepAliveSettings = { timeout: 30000 }, logVerbosity = false) { + this.keepAlive = keepAlive; + this.keepAliveSettings = keepAliveSettings; + this.logVerbosity = logVerbosity; + } + setProxy(configuration) { + this.proxyConfiguration = configuration; + } + makeSendable(req) { + let controller = undefined; + let abortController; + if (req.cancellable) { + abortController = new AbortController(); + controller = { + abortController, + abort: () => abortController === null || abortController === void 0 ? void 0 : abortController.abort(), + }; + } + return [ + this.requestFromTransportRequest(req).then((request) => { + const start = new Date().getTime(); + this.logRequestProcessProgress(request); + return (0, node_fetch_1.default)(request, { + signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, + timeout: req.timeout * 1000, + }) + .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) + .then((response) => { + const responseBody = response[1].byteLength > 0 ? response[1] : undefined; + const { status, headers: requestHeaders } = response[0]; + const headers = {}; + requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); + const transportResponse = { + status, + url: request.url, + headers, + body: responseBody, + }; + if (status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(transportResponse); + this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + return transportResponse; + }) + .catch((error) => { + throw pubnub_api_error_1.PubNubAPIError.create(error); + }); + }), + controller, + ]; + } + request(req) { + return req; + } + requestFromTransportRequest(req) { + return __awaiter(this, void 0, void 0, function* () { + let headers = req.headers; + let body; + let path = req.path; + if (req.formData && req.formData.length > 0) { + req.queryParameters = {}; + const file = req.body; + const fileData = yield file.toArrayBuffer(); + const formData = new form_data_1.default(); + for (const { key, value } of req.formData) + formData.append(key, value); + formData.append('file', buffer_1.Buffer.from(fileData), { contentType: 'application/octet-stream', filename: file.name }); + body = formData; + headers = formData.getHeaders(headers !== null && headers !== void 0 ? headers : {}); + } + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) + body = req.body; + if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) + path = `${path}?${(0, utils_1.queryStringFromObject)(req.queryParameters)}`; + return new node_fetch_1.Request(`${req.origin}${path}`, { + agent: this.agentForTransportRequest(req), + method: req.method, + headers, + redirect: 'follow', + body, + }); + }); + } + agentForTransportRequest(req) { + if (!this.keepAlive && !this.proxyConfiguration) + return undefined; + if (this.proxyConfiguration) + return this.proxyAgent ? this.proxyAgent : (this.proxyAgent = new proxy_agent_1.ProxyAgent(this.proxyConfiguration)); + const useSecureAgent = req.origin.startsWith('https:'); + if (useSecureAgent && this.httpsAgent === undefined) + this.httpsAgent = new https_1.Agent(Object.assign({ keepAlive: true }, this.keepAliveSettings)); + else if (!useSecureAgent && this.httpAgent === undefined) { + this.httpAgent = new http_1.Agent(Object.assign({ keepAlive: true }, this.keepAliveSettings)); + } + return useSecureAgent ? this.httpsAgent : this.httpAgent; + } + logRequestProcessProgress(request, elapsed, body) { + if (!this.logVerbosity) + return; + const { protocol, host, pathname, search } = new URL(request.url); + const timestamp = new Date().toISOString(); + if (!elapsed) { + console.log('<<<<<'); + console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + console.log('-----'); + } + else { + const stringifiedBody = body ? NodeTransport.decoder.decode(body) : undefined; + console.log('>>>>>>'); + console.log(`[${timestamp} / ${elapsed}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`, `\n${stringifiedBody}`); + console.log('-----'); + } + } +} +exports.NodeTransport = NodeTransport; +NodeTransport.decoder = new TextDecoder(); diff --git a/lib/transport/web-react-native-transport.js b/lib/transport/web-react-native-transport.js new file mode 100644 index 000000000..bf09f69d2 --- /dev/null +++ b/lib/transport/web-react-native-transport.js @@ -0,0 +1,122 @@ +"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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.WebReactNativeTransport = void 0; +const pubnub_api_error_1 = require("../errors/pubnub-api-error"); +const utils_1 = require("../core/utils"); +class WebReactNativeTransport { + constructor(keepAlive = false, logVerbosity) { + this.keepAlive = keepAlive; + this.logVerbosity = logVerbosity; + } + makeSendable(req) { + let controller; + let abortController; + if (req.cancellable) { + abortController = new AbortController(); + controller = { + abortController, + abort: () => abortController === null || abortController === void 0 ? void 0 : abortController.abort(), + }; + } + return [ + this.requestFromTransportRequest(req).then((request) => { + const start = new Date().getTime(); + this.logRequestProcessProgress(request); + const requestTimeout = new Promise((_, reject) => { + const timeoutId = setTimeout(() => { + clearTimeout(timeoutId); + reject(new Error('Request timeout')); + }, req.timeout * 1000); + }); + return Promise.race([fetch(request, { signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal }), requestTimeout]) + .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) + .then((response) => { + const responseBody = response[1].byteLength > 0 ? response[1] : undefined; + const { status, headers: requestHeaders } = response[0]; + const headers = {}; + requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); + const transportResponse = { + status, + url: request.url, + headers, + body: responseBody, + }; + if (status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(transportResponse); + this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + return transportResponse; + }) + .catch((error) => { + throw pubnub_api_error_1.PubNubAPIError.create(error); + }); + }), + controller, + ]; + } + request(req) { + return req; + } + requestFromTransportRequest(req) { + return __awaiter(this, void 0, void 0, function* () { + let body; + let path = req.path; + if (req.formData && req.formData.length > 0) { + req.queryParameters = {}; + const file = req.body; + const formData = new FormData(); + for (const { key, value } of req.formData) + formData.append(key, value); + try { + const fileData = yield file.toArrayBuffer(); + formData.append('file', new Blob([fileData], { type: 'application/octet-stream' }), file.name); + } + catch (_) { + try { + const fileData = yield file.toFileUri(); + formData.append('file', fileData, file.name); + } + catch (_) { } + } + body = formData; + } + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) + body = req.body; + if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) + path = `${path}?${(0, utils_1.queryStringFromObject)(req.queryParameters)}`; + return new Request(`${req.origin}${path}`, { + method: req.method, + headers: req.headers, + redirect: 'follow', + body, + }); + }); + } + logRequestProcessProgress(request, elapsed, body) { + if (!this.logVerbosity) + return; + const { protocol, host, pathname, search } = new URL(request.url); + const timestamp = new Date().toISOString(); + if (!elapsed) { + console.log('<<<<<'); + console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + console.log('-----'); + } + else { + const stringifiedBody = body ? WebReactNativeTransport.decoder.decode(body) : undefined; + console.log('>>>>>>'); + console.log(`[${timestamp} / ${elapsed}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`, `\n${stringifiedBody}`); + console.log('-----'); + } + } +} +exports.WebReactNativeTransport = WebReactNativeTransport; +WebReactNativeTransport.decoder = new TextDecoder(); diff --git a/lib/web/index.js b/lib/web/index.js deleted file mode 100644 index fcda537bb..000000000 --- a/lib/web/index.js +++ /dev/null @@ -1,84 +0,0 @@ -"use strict"; -/* eslint no-bitwise: ["error", { "allow": ["~", "&", ">>"] }] */ -/* global navigator, window */ -var __extends = (this && this.__extends) || (function () { - var extendStatics = function (d, b) { - extendStatics = Object.setPrototypeOf || - ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || - function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); - }; - return function (d, b) { - if (typeof b !== "function" && b !== null) - throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); - extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); - }; -})(); -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -var cbor_js_1 = __importDefault(require("cbor-js")); -var pubnub_common_1 = __importDefault(require("../core/pubnub-common")); -var networking_1 = __importDefault(require("../networking")); -var base64_codec_1 = require("../core/components/base64_codec"); -var stringify_buffer_keys_1 = require("../core/components/stringify_buffer_keys"); -var common_1 = __importDefault(require("../cbor/common")); -var web_node_1 = require("../networking/modules/web-node"); -var web_1 = __importDefault(require("../crypto/modules/web")); -var web_2 = __importDefault(require("../file/modules/web")); -var webCryptoModule_1 = require("../crypto/modules/WebCryptoModule/webCryptoModule"); -function sendBeacon(url) { - if (navigator && navigator.sendBeacon) { - navigator.sendBeacon(url); - } - else { - return false; - } -} -var default_1 = /** @class */ (function (_super) { - __extends(default_1, _super); - function default_1(setup) { - var _this = this; - // extract config. - var _a = setup.listenToBrowserNetworkEvents, listenToBrowserNetworkEvents = _a === void 0 ? true : _a; - setup.sdkFamily = 'Web'; - setup.networking = new networking_1.default({ - del: web_node_1.del, - get: web_node_1.get, - post: web_node_1.post, - patch: web_node_1.patch, - sendBeacon: sendBeacon, - getfile: web_node_1.getfile, - postfile: web_node_1.postfile, - }); - setup.cbor = new common_1.default(function (arrayBuffer) { return (0, stringify_buffer_keys_1.stringifyBufferKeys)(cbor_js_1.default.decode(arrayBuffer)); }, base64_codec_1.decode); - setup.PubNubFile = web_2.default; - setup.cryptography = new web_1.default(); - setup.initCryptoModule = function (cryptoConfiguration) { - return new webCryptoModule_1.CryptoModule({ - default: new webCryptoModule_1.LegacyCryptor({ - cipherKey: cryptoConfiguration.cipherKey, - useRandomIVs: cryptoConfiguration.useRandomIVs, - }), - cryptors: [new webCryptoModule_1.AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], - }); - }; - _this = _super.call(this, setup) || this; - if (listenToBrowserNetworkEvents) { - // mount network events. - window.addEventListener('offline', function () { - _this.networkDownDetected(); - }); - window.addEventListener('online', function () { - _this.networkUpDetected(); - }); - } - return _this; - } - default_1.CryptoModule = webCryptoModule_1.CryptoModule; - return default_1; -}(pubnub_common_1.default)); -exports.default = default_1; diff --git a/package-lock.json b/package-lock.json index 36efbc4cc..089766f5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,49 +1,60 @@ { "name": "pubnub", - "version": "7.6.0", + "version": "7.6.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "7.6.0", + "version": "7.6.3", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", "buffer": "^6.0.3", "cbor-js": "^0.1.0", "cbor-sync": "^1.0.4", + "form-data": "^4.0.0", "lil-uuid": "^0.1.1", + "node-fetch": "^2.7.0", "proxy-agent": "^6.3.0", - "superagent": "^8.1.2" + "react-native-url-polyfill": "^2.0.0", + "text-encoding": "^0.7.0" }, "devDependencies": { - "@cucumber/cucumber": "^7.3.1", + "@cucumber/cucumber": "^10.4.0", "@cucumber/pretty-formatter": "^1.0.0", - "@rollup/plugin-commonjs": "^21.0.2", - "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^13.1.3", - "@rollup/plugin-typescript": "^8.3.1", - "@types/chai": "^4.3.3", + "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-json": "^6.1.0", + "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-replace": "^5.0.5", + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^11.1.6", + "@types/cbor-js": "^0.1.1", + "@types/chai": "^4.3.14", + "@types/chai-as-promised": "^7.1.8", "@types/cucumber": "^7.0.0", "@types/expect": "^24.3.0", + "@types/lil-uuid": "^0.1.3", "@types/mocha": "^9.1.0", "@types/nock": "^9.3.1", - "@types/node-fetch": "^2.6.3", + "@types/node-fetch": "^2.6.11", "@types/pubnub": "^7.2.0", - "@typescript-eslint/eslint-plugin": "^5.12.1", - "@typescript-eslint/parser": "^5.12.1", - "chai": "^4.3.4", + "@types/sinon": "^17.0.3", + "@types/text-encoding": "^0.0.39", + "@types/underscore": "^1.11.15", + "@typescript-eslint/eslint-plugin": "^7.4.0", + "@typescript-eslint/parser": "^7.4.0", + "chai": "^4.4.1", "chai-as-promised": "^7.1.1", "chai-nock": "^1.2.0", "cucumber-pretty": "^6.0.1", - "cucumber-tsflow": "^4.0.0-rc.11", - "es6-shim": "^0.35.6", - "eslint": "^8.9.0", - "eslint-plugin-mocha": "^10.0.3", - "eslint-plugin-prettier": "^4.0.0", + "cucumber-tsflow": "^4.4.4", + "es6-shim": "^0.35.8", + "eslint": "^8.57.0", + "eslint-plugin-mocha": "^10.4.1", + "eslint-plugin-prettier": "^5.1.3", "js-yaml": "^3.13.1", - "karma": "^5.0.3", + "karma": "6.4.3", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^3.1.0", "karma-mocha": "^2.0.1", @@ -51,3677 +62,9745 @@ "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.32", - "mocha": "^9.2.1", - "nock": "^9.6.1", - "node-fetch": "^2.6.9", + "mocha": "10.4.0", + "nock": "^14.0.0-beta.5", "phantomjs-prebuilt": "^2.1.16", - "prettier": "^2.5.1", + "prettier": "^3.2.5", "rimraf": "^3.0.2", - "rollup": "^2.68.0", - "rollup-plugin-gzip": "^3.0.1", - "rollup-plugin-terser": "^7.0.2", + "rollup": "^4.13.2", + "rollup-plugin-gzip": "^3.1.2", + "rollup-plugin-string": "^3.0.0", "sinon": "^7.5.0", "sinon-chai": "^3.3.0", "source-map-support": "^0.5.21", - "ts-mocha": "^9.0.2", - "ts-node": "^10.9.1", - "typescript": "^4.8.4", + "ts-mocha": "^10.0.0", + "ts-node": "^10.9.2", + "tsx": "^4.7.1", + "typescript": "^5.4.5", "underscore": "^1.9.2" } }, - "node_modules/@babel/code-frame": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.16.7.tgz", - "integrity": "sha512-iAXqUn8IIeBTNd72xsFlgaXHkMBMt6y4HJp1tIaK465CWLT/fG1aqB7ykr95gHHmlBdGbFeWWfyB4NJJ0nmeIg==", + "node_modules/@aashutoshrathi/word-wrap": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", + "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/@ampproject/remapping": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", + "integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==", + "peer": true, "dependencies": { - "@babel/highlight": "^7.16.7" + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.24" }, "engines": { - "node": ">=6.9.0" + "node": ">=6.0.0" } }, - "node_modules/@babel/helper-validator-identifier": { - "version": "7.16.7", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.16.7.tgz", - "integrity": "sha512-hsEnFemeiW4D08A5gUAZxLBTXpZ39P+a+DGDsHw1yxqyQ/jzFEnxf5uTEGp+3bzAbNOxU1paTgYS4ECU/IgfDw==", - "dev": true, + "node_modules/@babel/code-frame": { + "version": "7.24.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", + "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "dependencies": { + "@babel/highlight": "^7.24.2", + "picocolors": "^1.0.0" + }, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/highlight": { - "version": "7.16.10", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.16.10.tgz", - "integrity": "sha512-5FnTQLSLswEj6IkgVw5KusNUUFY9ZGqe/TRFnP/BKYHYgfh7tc+C7mwiy95/yNP7Dh9x580Vv8r7u7ZfTBFxdw==", - "dev": true, - "dependencies": { - "@babel/helper-validator-identifier": "^7.16.7", - "chalk": "^2.0.0", - "js-tokens": "^4.0.0" - }, + "node_modules/@babel/compat-data": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.24.4.tgz", + "integrity": "sha512-vg8Gih2MLK+kOkHJp4gBEIkyaIi00jgWot2D9QOmmfLC8jINSOzmCLta6Bvz/JSBCqnegV0L80jhxkol5GWNfQ==", + "peer": true, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/runtime-corejs3": { - "version": "7.20.0", - "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.20.0.tgz", - "integrity": "sha512-v1JH7PeAAGBEyTQM9TqojVl+b20zXtesFKCJHu50xMxZKD1fX0TKaKHPsZfFkXfs7D1M9M6Eeqg1FkJ3a0x2dA==", - "dev": true, + "node_modules/@babel/core": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.4.tgz", + "integrity": "sha512-MBVlMXP+kkl5394RBLSxxk/iLTeVGuXTV3cIDXavPpMMqnSnt6apKgan/U8O3USWZCWZT/TbgfEpKa4uMgN4Dg==", "peer": true, "dependencies": { - "core-js-pure": "^3.25.1", - "regenerator-runtime": "^0.13.10" + "@ampproject/remapping": "^2.2.0", + "@babel/code-frame": "^7.24.2", + "@babel/generator": "^7.24.4", + "@babel/helper-compilation-targets": "^7.23.6", + "@babel/helper-module-transforms": "^7.23.3", + "@babel/helpers": "^7.24.4", + "@babel/parser": "^7.24.4", + "@babel/template": "^7.24.0", + "@babel/traverse": "^7.24.1", + "@babel/types": "^7.24.0", + "convert-source-map": "^2.0.0", + "debug": "^4.1.0", + "gensync": "^1.0.0-beta.2", + "json5": "^2.2.3", + "semver": "^6.3.1" }, "engines": { "node": ">=6.9.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/babel" } }, - "node_modules/@colors/colors": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", - "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", - "dev": true, - "optional": true, + "node_modules/@babel/core/node_modules/json5": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "peer": true, + "bin": { + "json5": "lib/cli.js" + }, "engines": { - "node": ">=0.1.90" + "node": ">=6" } }, - "node_modules/@cspotcode/source-map-support": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", - "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", - "dev": true, + "node_modules/@babel/core/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "peer": true, + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/@babel/generator": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.4.tgz", + "integrity": "sha512-Xd6+v6SnjWVx/nus+y0l1sxMOTOMBkyL4+BIdbALyatQnAe/SRVjANeDPSCYaX+i1iJmuGSKf3Z+E+V/va1Hvw==", + "peer": true, "dependencies": { - "@jridgewell/trace-mapping": "0.3.9" + "@babel/types": "^7.24.0", + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.25", + "jsesc": "^2.5.1" }, "engines": { - "node": ">=12" + "node": ">=6.9.0" } }, - "node_modules/@cucumber/create-meta": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@cucumber/create-meta/-/create-meta-5.0.0.tgz", - "integrity": "sha512-Z5kMZkUff00S3/KSnKzB/KOm2UIxMXY1xXmj2dQMlD49lV6v/W8EEvgDMNtQotQNSOQU5bDupmWQpk+o16tXIw==", - "dev": true, + "node_modules/@babel/helper-annotate-as-pure": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.22.5.tgz", + "integrity": "sha512-LvBTxu8bQSQkcyKOU+a1btnNFQ1dMAd0R6PyW3arXes06F6QLWLIrd681bxRPIXlrMGR3XYnW9JyML7dP3qgxg==", + "peer": true, "dependencies": { - "@cucumber/messages": "^16.0.0" + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/create-meta/node_modules/@cucumber/messages": { - "version": "16.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-16.0.1.tgz", - "integrity": "sha512-80JcaAfQragFqR1rMhRwiqWL9HcR6Z4LDD2mfF0Lxg/lFkCNvmWa9Jl10NUNfFXYD555NKPzP/8xFo55abw8TQ==", - "dev": true, + "node_modules/@babel/helper-builder-binary-assignment-operator-visitor": { + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.22.15.tgz", + "integrity": "sha512-QkBXwGgaoC2GtGZRoma6kv7Szfv06khvhFav67ZExau2RaXzy8MpHSMO2PNoP2XtmQphJQRHFfg77Bq731Yizw==", + "peer": true, "dependencies": { - "@types/uuid": "8.3.0", - "class-transformer": "0.4.0", - "reflect-metadata": "0.1.13", - "uuid": "8.3.2" - } - }, - "node_modules/@cucumber/create-meta/node_modules/@types/uuid": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.0.tgz", - "integrity": "sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==", - "dev": true - }, - "node_modules/@cucumber/create-meta/node_modules/class-transformer": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.4.0.tgz", - "integrity": "sha512-ETWD/H2TbWbKEi7m9N4Km5+cw1hNcqJSxlSYhsLsNjQzWWiZIYA1zafxpK9PwVfaZ6AqR5rrjPVUBGESm5tQUA==", - "dev": true - }, - "node_modules/@cucumber/create-meta/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, - "bin": { - "uuid": "dist/bin/uuid" - } - }, - "node_modules/@cucumber/cucumber": { - "version": "7.3.2", - "resolved": "https://registry.npmjs.org/@cucumber/cucumber/-/cucumber-7.3.2.tgz", - "integrity": "sha512-qqptM9w+UqXEYBAkrIGpIVPXDWv+zp0LrS89LiwHZwBp0cJg00su/iPMZ4j8TvCJiKfAwJXsAI1yjrd1POtU+w==", - "dev": true, - "dependencies": { - "@cucumber/create-meta": "^5.0.0", - "@cucumber/cucumber-expressions": "^12.1.1", - "@cucumber/gherkin": "^19.0.3", - "@cucumber/gherkin-streams": "^2.0.2", - "@cucumber/html-formatter": "^15.0.2", - "@cucumber/messages": "^16.0.1", - "@cucumber/tag-expressions": "^3.0.1", - "assertion-error-formatter": "^3.0.0", - "bluebird": "^3.7.2", - "capital-case": "^1.0.4", - "cli-table3": "0.6.1", - "colors": "1.4.0", - "commander": "^7.0.0", - "create-require": "^1.1.1", - "duration": "^0.2.2", - "durations": "^3.4.2", - "figures": "^3.2.0", - "glob": "^7.1.6", - "indent-string": "^4.0.0", - "is-generator": "^1.0.3", - "is-stream": "^2.0.0", - "knuth-shuffle-seeded": "^1.0.6", - "lodash": "^4.17.21", - "mz": "^2.7.0", - "progress": "^2.0.3", - "resolve": "^1.19.0", - "resolve-pkg": "^2.0.0", - "stack-chain": "^2.0.0", - "stacktrace-js": "^2.0.2", - "string-argv": "^0.3.1", - "tmp": "^0.2.1", - "util-arity": "^1.1.0", - "verror": "^1.10.0" - }, - "bin": { - "cucumber-js": "bin/cucumber-js" + "@babel/types": "^7.22.15" }, "engines": { - "node": ">=10" + "node": ">=6.9.0" } }, - "node_modules/@cucumber/cucumber-expressions": { - "version": "12.1.3", - "resolved": "https://registry.npmjs.org/@cucumber/cucumber-expressions/-/cucumber-expressions-12.1.3.tgz", - "integrity": "sha512-LB8MAzE4F/t2KIgsDEz4gZH0xSI4aG0/LmYUPyISPPjUS1pI/yGWWyeX2WsiUQxpSs765WcNIq5Bggt7gGGO3Q==", - "dev": true, + "node_modules/@babel/helper-compilation-targets": { + "version": "7.23.6", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.23.6.tgz", + "integrity": "sha512-9JB548GZoQVmzrFgp8o7KxdgkTGm6xs9DW0o/Pim72UDjzr5ObUQ6ZzYPqA+g9OTS2bBQoctLJrky0RDCAWRgQ==", + "peer": true, "dependencies": { - "regexp-match-indices": "1.0.2" + "@babel/compat-data": "^7.23.5", + "@babel/helper-validator-option": "^7.23.5", + "browserslist": "^4.22.2", + "lru-cache": "^5.1.1", + "semver": "^6.3.1" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/cucumber/node_modules/@cucumber/messages": { - "version": "16.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-16.0.1.tgz", - "integrity": "sha512-80JcaAfQragFqR1rMhRwiqWL9HcR6Z4LDD2mfF0Lxg/lFkCNvmWa9Jl10NUNfFXYD555NKPzP/8xFo55abw8TQ==", - "dev": true, + "node_modules/@babel/helper-compilation-targets/node_modules/lru-cache": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", + "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", + "peer": true, "dependencies": { - "@types/uuid": "8.3.0", - "class-transformer": "0.4.0", - "reflect-metadata": "0.1.13", - "uuid": "8.3.2" + "yallist": "^3.0.2" } }, - "node_modules/@cucumber/cucumber/node_modules/@types/uuid": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.0.tgz", - "integrity": "sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==", - "dev": true + "node_modules/@babel/helper-compilation-targets/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "peer": true, + "bin": { + "semver": "bin/semver.js" + } }, - "node_modules/@cucumber/cucumber/node_modules/class-transformer": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.4.0.tgz", - "integrity": "sha512-ETWD/H2TbWbKEi7m9N4Km5+cw1hNcqJSxlSYhsLsNjQzWWiZIYA1zafxpK9PwVfaZ6AqR5rrjPVUBGESm5tQUA==", - "dev": true + "node_modules/@babel/helper-compilation-targets/node_modules/yallist": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", + "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", + "peer": true }, - "node_modules/@cucumber/cucumber/node_modules/cli-table3": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.1.tgz", - "integrity": "sha512-w0q/enDHhPLq44ovMGdQeeDLvwxwavsJX7oQGYt/LrBlYsyaxyDnp6z3QzFut/6kLLKnlcUVJLrpB7KBfgG/RA==", - "dev": true, + "node_modules/@babel/helper-create-class-features-plugin": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.24.4.tgz", + "integrity": "sha512-lG75yeuUSVu0pIcbhiYMXBXANHrpUPaOfu7ryAzskCgKUHuAxRQI5ssrtmF0X9UXldPlvT0XM/A4F44OXRt6iQ==", + "peer": true, "dependencies": { - "string-width": "^4.2.0" + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-member-expression-to-functions": "^7.23.0", + "@babel/helper-optimise-call-expression": "^7.22.5", + "@babel/helper-replace-supers": "^7.24.1", + "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "semver": "^6.3.1" }, "engines": { - "node": "10.* || >= 12.*" + "node": ">=6.9.0" }, - "optionalDependencies": { - "colors": "1.4.0" + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@cucumber/cucumber/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, + "node_modules/@babel/helper-create-class-features-plugin/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "peer": true, "bin": { - "uuid": "dist/bin/uuid" + "semver": "bin/semver.js" } }, - "node_modules/@cucumber/gherkin": { - "version": "19.0.3", - "resolved": "https://registry.npmjs.org/@cucumber/gherkin/-/gherkin-19.0.3.tgz", - "integrity": "sha512-gWdMm8mfRk3P+VugJWvNALaQV5QnT+5RkqWy3tO+4NsMSQZPo5p4V4vXwriQZ/sZR1Wni5TDRztuRsKLgZ3XHA==", - "dev": true, + "node_modules/@babel/helper-create-regexp-features-plugin": { + "version": "7.22.15", + "resolved": "https://registry.npmjs.org/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.22.15.tgz", + "integrity": "sha512-29FkPLFjn4TPEa3RE7GpW+qbE8tlsu3jntNYNfcGsc49LphF1PQIiD+vMZ1z1xVOKt+93khA9tc2JBs3kBjA7w==", + "peer": true, "dependencies": { - "@cucumber/message-streams": "^2.0.0", - "@cucumber/messages": "^16.0.1" + "@babel/helper-annotate-as-pure": "^7.22.5", + "regexpu-core": "^5.3.1", + "semver": "^6.3.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@cucumber/gherkin-streams": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@cucumber/gherkin-streams/-/gherkin-streams-2.0.2.tgz", - "integrity": "sha512-cKmXOBz4OwGlrHMBCc4qCC3KzLaqcEZ11nWWskIbv6jyfvlIRuM2OgEF6VLcNVewczifW1p6DrDj0OO+BeXocA==", - "dev": true, - "dependencies": { - "@cucumber/gherkin": "^19.0.1", - "@cucumber/message-streams": "^2.0.0", - "@cucumber/messages": "^16.0.0", - "commander": "7.2.0", - "source-map-support": "0.5.19" - }, + "node_modules/@babel/helper-create-regexp-features-plugin/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "peer": true, "bin": { - "gherkin-javascript": "bin/gherkin" + "semver": "bin/semver.js" } }, - "node_modules/@cucumber/gherkin-streams/node_modules/@cucumber/messages": { - "version": "16.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-16.0.1.tgz", - "integrity": "sha512-80JcaAfQragFqR1rMhRwiqWL9HcR6Z4LDD2mfF0Lxg/lFkCNvmWa9Jl10NUNfFXYD555NKPzP/8xFo55abw8TQ==", - "dev": true, + "node_modules/@babel/helper-define-polyfill-provider": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/@babel/helper-define-polyfill-provider/-/helper-define-polyfill-provider-0.6.1.tgz", + "integrity": "sha512-o7SDgTJuvx5vLKD6SFvkydkSMBvahDKGiNJzG22IZYXhiqoe9efY7zocICBgzHV4IRg5wdgl2nEL/tulKIEIbA==", + "peer": true, "dependencies": { - "@types/uuid": "8.3.0", - "class-transformer": "0.4.0", - "reflect-metadata": "0.1.13", - "uuid": "8.3.2" + "@babel/helper-compilation-targets": "^7.22.6", + "@babel/helper-plugin-utils": "^7.22.5", + "debug": "^4.1.1", + "lodash.debounce": "^4.0.8", + "resolve": "^1.14.2" + }, + "peerDependencies": { + "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, - "node_modules/@cucumber/gherkin-streams/node_modules/@types/uuid": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.0.tgz", - "integrity": "sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==", - "dev": true - }, - "node_modules/@cucumber/gherkin-streams/node_modules/class-transformer": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.4.0.tgz", - "integrity": "sha512-ETWD/H2TbWbKEi7m9N4Km5+cw1hNcqJSxlSYhsLsNjQzWWiZIYA1zafxpK9PwVfaZ6AqR5rrjPVUBGESm5tQUA==", - "dev": true + "node_modules/@babel/helper-environment-visitor": { + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", + "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", + "peer": true, + "engines": { + "node": ">=6.9.0" + } }, - "node_modules/@cucumber/gherkin-streams/node_modules/source-map-support": { - "version": "0.5.19", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", - "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", - "dev": true, + "node_modules/@babel/helper-function-name": { + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", + "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", + "peer": true, "dependencies": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" + "@babel/template": "^7.22.15", + "@babel/types": "^7.23.0" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/gherkin-streams/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, - "bin": { - "uuid": "dist/bin/uuid" + "node_modules/@babel/helper-hoist-variables": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", + "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", + "peer": true, + "dependencies": { + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/gherkin/node_modules/@cucumber/messages": { - "version": "16.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-16.0.1.tgz", - "integrity": "sha512-80JcaAfQragFqR1rMhRwiqWL9HcR6Z4LDD2mfF0Lxg/lFkCNvmWa9Jl10NUNfFXYD555NKPzP/8xFo55abw8TQ==", - "dev": true, + "node_modules/@babel/helper-member-expression-to-functions": { + "version": "7.23.0", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.23.0.tgz", + "integrity": "sha512-6gfrPwh7OuT6gZyJZvd6WbTfrqAo7vm4xCzAXOusKqq/vWdKXphTpj5klHKNmRUU6/QRGlBsyU9mAIPaWHlqJA==", + "peer": true, "dependencies": { - "@types/uuid": "8.3.0", - "class-transformer": "0.4.0", - "reflect-metadata": "0.1.13", - "uuid": "8.3.2" + "@babel/types": "^7.23.0" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/gherkin/node_modules/@types/uuid": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.0.tgz", - "integrity": "sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==", - "dev": true - }, - "node_modules/@cucumber/gherkin/node_modules/class-transformer": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.4.0.tgz", - "integrity": "sha512-ETWD/H2TbWbKEi7m9N4Km5+cw1hNcqJSxlSYhsLsNjQzWWiZIYA1zafxpK9PwVfaZ6AqR5rrjPVUBGESm5tQUA==", - "dev": true - }, - "node_modules/@cucumber/gherkin/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, - "bin": { - "uuid": "dist/bin/uuid" + "node_modules/@babel/helper-module-imports": { + "version": "7.24.3", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.3.tgz", + "integrity": "sha512-viKb0F9f2s0BCS22QSF308z/+1YWKV/76mwt61NBzS5izMzDPwdq1pTrzf+Li3npBWX9KdQbkeCt1jSAM7lZqg==", + "peer": true, + "dependencies": { + "@babel/types": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/html-formatter": { - "version": "15.0.2", - "resolved": "https://registry.npmjs.org/@cucumber/html-formatter/-/html-formatter-15.0.2.tgz", - "integrity": "sha512-j+YGY4ytj78G/v1gZo53D+vuKXlTg/oxNwSCCGvRQo75+AqYDJSkm/vexXJQ5lY1rXAvlbZ9KI6jhg6LDs0YdQ==", - "dev": true, + "node_modules/@babel/helper-module-transforms": { + "version": "7.23.3", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.3.tgz", + "integrity": "sha512-7bBs4ED9OmswdfDzpz4MpWgSrV7FXlc3zIagvLFjS5H+Mk7Snr21vQ6QwrsoCGMfNC4e4LQPdoULEt4ykz0SRQ==", + "peer": true, "dependencies": { - "@cucumber/messages": "^16.0.1", - "commander": "7.2.0", - "source-map-support": "0.5.19" + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-module-imports": "^7.22.15", + "@babel/helper-simple-access": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/helper-validator-identifier": "^7.22.20" }, - "bin": { - "cucumber-html-formatter": "bin/cucumber-html-formatter.js" + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@cucumber/html-formatter/node_modules/@cucumber/messages": { - "version": "16.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-16.0.1.tgz", - "integrity": "sha512-80JcaAfQragFqR1rMhRwiqWL9HcR6Z4LDD2mfF0Lxg/lFkCNvmWa9Jl10NUNfFXYD555NKPzP/8xFo55abw8TQ==", - "dev": true, + "node_modules/@babel/helper-optimise-call-expression": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.22.5.tgz", + "integrity": "sha512-HBwaojN0xFRx4yIvpwGqxiV2tUfl7401jlok564NgB9EHS1y6QT17FmKWm4ztqjeVdXLuC4fSvHc5ePpQjoTbw==", + "peer": true, "dependencies": { - "@types/uuid": "8.3.0", - "class-transformer": "0.4.0", - "reflect-metadata": "0.1.13", - "uuid": "8.3.2" + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/html-formatter/node_modules/@types/uuid": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.0.tgz", - "integrity": "sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==", - "dev": true + "node_modules/@babel/helper-plugin-utils": { + "version": "7.24.0", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.0.tgz", + "integrity": "sha512-9cUznXMG0+FxRuJfvL82QlTqIzhVW9sL0KjMPHhAOOvpQGL8QtdxnBKILjBqxlHyliz0yCa1G903ZXI/FuHy2w==", + "peer": true, + "engines": { + "node": ">=6.9.0" + } }, - "node_modules/@cucumber/html-formatter/node_modules/class-transformer": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.4.0.tgz", - "integrity": "sha512-ETWD/H2TbWbKEi7m9N4Km5+cw1hNcqJSxlSYhsLsNjQzWWiZIYA1zafxpK9PwVfaZ6AqR5rrjPVUBGESm5tQUA==", - "dev": true + "node_modules/@babel/helper-remap-async-to-generator": { + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.22.20.tgz", + "integrity": "sha512-pBGyV4uBqOns+0UvhsTO8qgl8hO89PmiDYv+/COyp1aeMcmfrfruz+/nCMFiYyFF/Knn0yfrC85ZzNFjembFTw==", + "peer": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-wrap-function": "^7.22.20" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } }, - "node_modules/@cucumber/html-formatter/node_modules/source-map-support": { - "version": "0.5.19", - "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.19.tgz", - "integrity": "sha512-Wonm7zOCIJzBGQdB+thsPar0kYuCIzYvxZwlBa87yi/Mdjv7Tip2cyVbLj5o0cFPN4EVkuTwb3GDDyUx2DGnGw==", - "dev": true, + "node_modules/@babel/helper-replace-supers": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.24.1.tgz", + "integrity": "sha512-QCR1UqC9BzG5vZl8BMicmZ28RuUBnHhAMddD8yHFHDRH9lLTZ9uUPehX8ctVPT8l0TKblJidqcgUUKGVrePleQ==", + "peer": true, "dependencies": { - "buffer-from": "^1.0.0", - "source-map": "^0.6.0" + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-member-expression-to-functions": "^7.23.0", + "@babel/helper-optimise-call-expression": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@cucumber/html-formatter/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, - "bin": { - "uuid": "dist/bin/uuid" + "node_modules/@babel/helper-simple-access": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.22.5.tgz", + "integrity": "sha512-n0H99E/K+Bika3++WNL17POvo4rKWZ7lZEp1Q+fStVbUi8nxPQEBOlTmCOxW/0JsS56SKKQ+ojAe2pHKJHN35w==", + "peer": true, + "dependencies": { + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/message-streams": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/@cucumber/message-streams/-/message-streams-2.1.0.tgz", - "integrity": "sha512-Yh3mw3qv6QL9NI/ihkZF8V9MX2GbnR6oktv34kC3uAbrQy9d/b2SZ3HNjG3J9JQqpV4B7Om3SPElJYIeo66TrA==", - "dev": true, + "node_modules/@babel/helper-skip-transparent-expression-wrappers": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/helper-skip-transparent-expression-wrappers/-/helper-skip-transparent-expression-wrappers-7.22.5.tgz", + "integrity": "sha512-tK14r66JZKiC43p8Ki33yLBVJKlQDFoA8GYN67lWCDCqoL6EMMSuM9b+Iff2jHaM/RRFYl7K+iiru7hbRqNx8Q==", + "peer": true, "dependencies": { - "@cucumber/messages": "^16.0.1" + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/message-streams/node_modules/@cucumber/messages": { - "version": "16.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-16.0.1.tgz", - "integrity": "sha512-80JcaAfQragFqR1rMhRwiqWL9HcR6Z4LDD2mfF0Lxg/lFkCNvmWa9Jl10NUNfFXYD555NKPzP/8xFo55abw8TQ==", - "dev": true, + "node_modules/@babel/helper-split-export-declaration": { + "version": "7.22.6", + "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", + "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", + "peer": true, "dependencies": { - "@types/uuid": "8.3.0", - "class-transformer": "0.4.0", - "reflect-metadata": "0.1.13", - "uuid": "8.3.2" + "@babel/types": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/message-streams/node_modules/@types/uuid": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.0.tgz", - "integrity": "sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==", - "dev": true - }, - "node_modules/@cucumber/message-streams/node_modules/class-transformer": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.4.0.tgz", - "integrity": "sha512-ETWD/H2TbWbKEi7m9N4Km5+cw1hNcqJSxlSYhsLsNjQzWWiZIYA1zafxpK9PwVfaZ6AqR5rrjPVUBGESm5tQUA==", - "dev": true + "node_modules/@babel/helper-string-parser": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.1.tgz", + "integrity": "sha512-2ofRCjnnA9y+wk8b9IAREroeUP02KHp431N2mhKniy2yKIDKpbrHv9eXwm8cBeWQYcJmzv5qKCu65P47eCF7CQ==", + "peer": true, + "engines": { + "node": ">=6.9.0" + } }, - "node_modules/@cucumber/message-streams/node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "dev": true, - "bin": { - "uuid": "dist/bin/uuid" + "node_modules/@babel/helper-validator-identifier": { + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", + "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/messages": { - "version": "21.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-21.0.1.tgz", - "integrity": "sha512-pGR7iURM4SF9Qp1IIpNiVQ77J9kfxMkPOEbyy+zRmGABnWWCsqMpJdfHeh9Mb3VskemVw85++e15JT0PYdcR3g==", - "dev": true, + "node_modules/@babel/helper-validator-option": { + "version": "7.23.5", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.23.5.tgz", + "integrity": "sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw==", "peer": true, - "dependencies": { - "@types/uuid": "8.3.4", - "class-transformer": "0.5.1", - "reflect-metadata": "0.1.13", - "uuid": "9.0.0" + "engines": { + "node": ">=6.9.0" } }, - "node_modules/@cucumber/pretty-formatter": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@cucumber/pretty-formatter/-/pretty-formatter-1.0.0.tgz", - "integrity": "sha512-wcnIMN94HyaHGsfq72dgCvr1d8q6VGH4Y6Gl5weJ2TNZw1qn2UY85Iki4c9VdaLUONYnyYH3+178YB+9RFe/Hw==", - "dev": true, + "node_modules/@babel/helper-wrap-function": { + "version": "7.22.20", + "resolved": "https://registry.npmjs.org/@babel/helper-wrap-function/-/helper-wrap-function-7.22.20.tgz", + "integrity": "sha512-pms/UwkOpnQe/PDAEdV/d7dVCoBbB+R4FvYoHGZz+4VPcg7RtYy2KP7S2lbuWM6FCSgob5wshfGESbC/hzNXZw==", + "peer": true, "dependencies": { - "ansi-styles": "^5.0.0", - "cli-table3": "^0.6.0", - "figures": "^3.2.0", - "ts-dedent": "^2.0.0" + "@babel/helper-function-name": "^7.22.5", + "@babel/template": "^7.22.15", + "@babel/types": "^7.22.19" }, - "peerDependencies": { - "@cucumber/cucumber": ">=7.0.0", - "@cucumber/messages": "*" - } - }, - "node_modules/@cucumber/pretty-formatter/node_modules/ansi-styles": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", - "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", - "dev": true, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "node": ">=6.9.0" } }, - "node_modules/@cucumber/tag-expressions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/tag-expressions/-/tag-expressions-3.0.1.tgz", - "integrity": "sha512-OGCXaJ1BQXmQ5b9pw+JYsBGumK2/LPZiLmbj1o1JFVeSNs2PY8WPQFSyXrskhrHz5Nd/6lYg7lvGMtFHOncC4w==", - "dev": true - }, - "node_modules/@eslint-community/eslint-utils": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", - "integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==", - "dev": true, + "node_modules/@babel/helpers": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.4.tgz", + "integrity": "sha512-FewdlZbSiwaVGlgT1DPANDuCHaDMiOo+D/IDYRFYjHOuv66xMSJ7fQwwODwRNAPkADIO/z1EoF/l2BCWlWABDw==", + "peer": true, "dependencies": { - "eslint-visitor-keys": "^3.3.0" + "@babel/template": "^7.24.0", + "@babel/traverse": "^7.24.1", + "@babel/types": "^7.24.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + "node": ">=6.9.0" } }, - "node_modules/@eslint-community/regexpp": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.5.0.tgz", - "integrity": "sha512-vITaYzIcNmjn5tF5uxcZ/ft7/RXGrMUIS9HalWckEOF6ESiwXKoMzAQf2UW0aVd6rnOeExTJVd5hmWXucBKGXQ==", - "dev": true, + "node_modules/@babel/highlight": { + "version": "7.24.2", + "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.2.tgz", + "integrity": "sha512-Yac1ao4flkTxTteCDZLEvdxg2fZfz1v8M4QpaGypq/WPDqg3ijHYbDfs+LG5hvzSoqaSZ9/Z9lKSP3CjZjv+pA==", + "dependencies": { + "@babel/helper-validator-identifier": "^7.22.20", + "chalk": "^2.4.2", + "js-tokens": "^4.0.0", + "picocolors": "^1.0.0" + }, "engines": { - "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + "node": ">=6.9.0" } }, - "node_modules/@eslint/eslintrc": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.0.2.tgz", - "integrity": "sha512-3W4f5tDUra+pA+FzgugqL2pRimUTDJWKr7BINqOpkZrC0uYI0NIc0/JFgBROCU07HR6GieA5m3/rsPIhDmCXTQ==", - "dev": true, + "node_modules/@babel/highlight/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "dependencies": { - "ajv": "^6.12.4", - "debug": "^4.3.2", - "espree": "^9.5.1", - "globals": "^13.19.0", - "ignore": "^5.2.0", - "import-fresh": "^3.2.1", - "js-yaml": "^4.1.0", - "minimatch": "^3.1.2", - "strip-json-comments": "^3.1.1" + "color-convert": "^1.9.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" + "node": ">=4" } }, - "node_modules/@eslint/eslintrc/node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, - "node_modules/@eslint/eslintrc/node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, + "node_modules/@babel/highlight/node_modules/chalk": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", + "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", "dependencies": { - "argparse": "^2.0.1" + "ansi-styles": "^3.2.1", + "escape-string-regexp": "^1.0.5", + "supports-color": "^5.3.0" }, - "bin": { - "js-yaml": "bin/js-yaml.js" + "engines": { + "node": ">=4" } }, - "node_modules/@eslint/js": { - "version": "8.37.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.37.0.tgz", - "integrity": "sha512-x5vzdtOOGgFVDCUs81QRB2+liax8rFg3+7hqM+QhBG0/G3F1ZsoYl97UrqgHgQ9KKT7G6c4V+aTUCgu/n22v1A==", - "dev": true, + "node_modules/@babel/highlight/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": ">=0.8.0" } }, - "node_modules/@humanwhocodes/config-array": { - "version": "0.11.8", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.8.tgz", - "integrity": "sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==", - "dev": true, + "node_modules/@babel/highlight/node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/highlight/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "dependencies": { - "@humanwhocodes/object-schema": "^1.2.1", - "debug": "^4.1.1", - "minimatch": "^3.0.5" + "has-flag": "^3.0.0" }, "engines": { - "node": ">=10.10.0" + "node": ">=4" } }, - "node_modules/@humanwhocodes/module-importer": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", - "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", - "dev": true, - "engines": { - "node": ">=12.22" + "node_modules/@babel/parser": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.4.tgz", + "integrity": "sha512-zTvEBcghmeBma9QIGunWevvBAp4/Qu9Bdq+2k0Ot4fVMD6v3dsC9WOcRSKk7tRRyBM/53yKMJko9xOatGQAwSg==", + "peer": true, + "bin": { + "parser": "bin/babel-parser.js" }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/nzakas" + "engines": { + "node": ">=6.0.0" } }, - "node_modules/@humanwhocodes/object-schema": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", - "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", - "dev": true - }, - "node_modules/@jest/types": { - "version": "27.5.1", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-27.5.1.tgz", - "integrity": "sha512-Cx46iJ9QpwQTjIdq5VJu2QTMMs3QlEjI0x1QbBP5W1+nMzyc2XmimiRR/CbX9TO0cPTeUlxWMOu8mslYsJ8DEw==", - "dev": true, + "node_modules/@babel/plugin-bugfix-firefox-class-in-computed-class-key": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-firefox-class-in-computed-class-key/-/plugin-bugfix-firefox-class-in-computed-class-key-7.24.4.tgz", + "integrity": "sha512-qpl6vOOEEzTLLcsuqYYo8yDtrTocmu2xkGvgNebvPjT9DTtfFYGmgDqY+rBYXNlqL4s9qLDn6xkrJv4RxAPiTA==", + "peer": true, "dependencies": { - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^16.0.0", - "chalk": "^4.0.0" + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { - "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@jest/types/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, + "node_modules/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression/-/plugin-bugfix-safari-id-destructuring-collision-in-function-expression-7.24.1.tgz", + "integrity": "sha512-y4HqEnkelJIOQGd+3g1bTeKsA5c6qM7eOn7VggGVbBc0y8MLSKHacwcIE2PplNlQSj0PqS9rrXL/nkPVK+kUNg==", + "peer": true, "dependencies": { - "color-convert": "^2.0.1" + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { - "node": ">=8" + "node": ">=6.9.0" }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@jest/types/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, + "node_modules/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining/-/plugin-bugfix-v8-spread-parameters-in-optional-chaining-7.24.1.tgz", + "integrity": "sha512-Hj791Ii4ci8HqnaKHAlLNs+zaLXb0EzSDhiAWp5VNlyvCNymYfacs64pxTxbH1znW/NcArSmwpmG9IKE/TUVVQ==", + "peer": true, "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5", + "@babel/plugin-transform-optional-chaining": "^7.24.1" }, "engines": { - "node": ">=10" + "node": ">=6.9.0" }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "peerDependencies": { + "@babel/core": "^7.13.0" } }, - "node_modules/@jest/types/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, + "node_modules/@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly/-/plugin-bugfix-v8-static-class-fields-redefine-readonly-7.24.1.tgz", + "integrity": "sha512-m9m/fXsXLiHfwdgydIFnpk+7jlVbnvlK5B2EKiPdLUb6WX654ZaaEWJUjk8TftRbZpK0XibovlLWX4KIZhV6jw==", + "peer": true, "dependencies": { - "color-name": "~1.1.4" + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { - "node": ">=7.0.0" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" } }, - "node_modules/@jest/types/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "node_modules/@jest/types/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, + "node_modules/@babel/plugin-proposal-async-generator-functions": { + "version": "7.20.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.20.7.tgz", + "integrity": "sha512-xMbiLsn/8RK7Wq7VeVytytS2L6qE69bXPB10YCmMdDZbKF4okCqY74pI/jJQ/8U0b/F6NrT2+14b8/P9/3AMGA==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.", + "peer": true, + "dependencies": { + "@babel/helper-environment-visitor": "^7.18.9", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/helper-remap-async-to-generator": "^7.18.9", + "@babel/plugin-syntax-async-generators": "^7.8.4" + }, "engines": { - "node": ">=8" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@jest/types/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, + "node_modules/@babel/plugin-proposal-class-properties": { + "version": "7.18.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.18.6.tgz", + "integrity": "sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.", + "peer": true, "dependencies": { - "has-flag": "^4.0.0" + "@babel/helper-create-class-features-plugin": "^7.18.6", + "@babel/helper-plugin-utils": "^7.18.6" }, "engines": { - "node": ">=8" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@jridgewell/resolve-uri": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz", - "integrity": "sha512-F2msla3tad+Mfht5cJq7LSXcdudKTWCVYUgw6pLFOOHSTtZlj6SWNYAp+AhuqLmWdBO2X5hPrLcu8cVP8fy28w==", - "dev": true, + "node_modules/@babel/plugin-proposal-export-default-from": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-export-default-from/-/plugin-proposal-export-default-from-7.24.1.tgz", + "integrity": "sha512-+0hrgGGV3xyYIjOrD/bUZk/iUwOIGuoANfRfVg1cPhYBxF+TIXSEcc42DqzBICmWsnAQ+SfKedY0bj8QD+LuMg==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-export-default-from": "^7.24.1" + }, "engines": { - "node": ">=6.0.0" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.14", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.14.tgz", - "integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==", - "dev": true - }, - "node_modules/@jridgewell/trace-mapping": { - "version": "0.3.9", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", - "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", - "dev": true, + "node_modules/@babel/plugin-proposal-nullish-coalescing-operator": { + "version": "7.18.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.18.6.tgz", + "integrity": "sha512-wQxQzxYeJqHcfppzBDnm1yAY0jSRkUXR2z8RePZYrKwMKgMlE8+Z6LUno+bd6LvbGh8Gltvy74+9pIYkr+XkKA==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.", + "peer": true, "dependencies": { - "@jridgewell/resolve-uri": "^3.0.3", - "@jridgewell/sourcemap-codec": "^1.4.10" + "@babel/helper-plugin-utils": "^7.18.6", + "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@nodelib/fs.scandir": { - "version": "2.1.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", - "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", - "dev": true, + "node_modules/@babel/plugin-proposal-numeric-separator": { + "version": "7.18.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-numeric-separator/-/plugin-proposal-numeric-separator-7.18.6.tgz", + "integrity": "sha512-ozlZFogPqoLm8WBr5Z8UckIoE4YQ5KESVcNudyXOR8uqIkliTEgJ3RoketfG6pmzLdeZF0H/wjE9/cCEitBl7Q==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.", + "peer": true, "dependencies": { - "@nodelib/fs.stat": "2.0.5", - "run-parallel": "^1.1.9" + "@babel/helper-plugin-utils": "^7.18.6", + "@babel/plugin-syntax-numeric-separator": "^7.10.4" }, "engines": { - "node": ">= 8" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@nodelib/fs.stat": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", - "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", - "dev": true, + "node_modules/@babel/plugin-proposal-object-rest-spread": { + "version": "7.20.7", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.20.7.tgz", + "integrity": "sha512-d2S98yCiLxDVmBmE8UjGcfPvNEUbA1U5q5WxaWFUGRzJSVAZqm5W6MbPct0jxnegUZ0niLeNX+IOzEs7wYg9Dg==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.", + "peer": true, + "dependencies": { + "@babel/compat-data": "^7.20.5", + "@babel/helper-compilation-targets": "^7.20.7", + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/plugin-syntax-object-rest-spread": "^7.8.3", + "@babel/plugin-transform-parameters": "^7.20.7" + }, "engines": { - "node": ">= 8" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@nodelib/fs.walk": { - "version": "1.2.8", - "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", - "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", - "dev": true, + "node_modules/@babel/plugin-proposal-optional-catch-binding": { + "version": "7.18.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.18.6.tgz", + "integrity": "sha512-Q40HEhs9DJQyaZfUjjn6vE8Cv4GmMHCYuMGIWUnlxH6400VGxOuwWsPt4FxXxJkC/5eOzgn0z21M9gMT4MOhbw==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.", + "peer": true, "dependencies": { - "@nodelib/fs.scandir": "2.1.5", - "fastq": "^1.6.0" + "@babel/helper-plugin-utils": "^7.18.6", + "@babel/plugin-syntax-optional-catch-binding": "^7.8.3" }, "engines": { - "node": ">= 8" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@rollup/plugin-commonjs": { - "version": "21.0.2", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-21.0.2.tgz", - "integrity": "sha512-d/OmjaLVO4j/aQX69bwpWPpbvI3TJkQuxoAk7BH8ew1PyoMBLTOuvJTjzG8oEoW7drIIqB0KCJtfFLu/2GClWg==", - "dev": true, + "node_modules/@babel/plugin-proposal-optional-chaining": { + "version": "7.21.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.21.0.tgz", + "integrity": "sha512-p4zeefM72gpmEe2fkUr/OnOXpWEf8nAgk7ZYVqqfFiyIG7oFfVZcCrU64hWn5xp4tQ9LkV4bTIa5rD0KANpKNA==", + "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.", + "peer": true, "dependencies": { - "@rollup/pluginutils": "^3.1.0", - "commondir": "^1.0.1", - "estree-walker": "^2.0.1", - "glob": "^7.1.6", - "is-reference": "^1.2.1", - "magic-string": "^0.25.7", - "resolve": "^1.17.0" + "@babel/helper-plugin-utils": "^7.20.2", + "@babel/helper-skip-transparent-expression-wrappers": "^7.20.0", + "@babel/plugin-syntax-optional-chaining": "^7.8.3" }, "engines": { - "node": ">= 8.0.0" + "node": ">=6.9.0" }, "peerDependencies": { - "rollup": "^2.38.3" + "@babel/core": "^7.0.0-0" } }, - "node_modules/@rollup/plugin-json": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-4.1.0.tgz", - "integrity": "sha512-yfLbTdNS6amI/2OpmbiBoW12vngr5NW2jCJVZSBEz+H5KfUJZ2M7sDjk0U6GOOdCWFVScShte29o9NezJ53TPw==", - "dev": true, - "dependencies": { - "@rollup/pluginutils": "^3.0.8" + "node_modules/@babel/plugin-proposal-private-property-in-object": { + "version": "7.21.0-placeholder-for-preset-env.2", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", + "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "peer": true, + "engines": { + "node": ">=6.9.0" }, "peerDependencies": { - "rollup": "^1.20.0 || ^2.0.0" + "@babel/core": "^7.0.0-0" } }, - "node_modules/@rollup/plugin-node-resolve": { - "version": "13.1.3", - "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-13.1.3.tgz", - "integrity": "sha512-BdxNk+LtmElRo5d06MGY4zoepyrXX1tkzX2hrnPEZ53k78GuOMWLqmJDGIIOPwVRIFZrLQOo+Yr6KtCuLIA0AQ==", - "dev": true, + "node_modules/@babel/plugin-syntax-async-generators": { + "version": "7.8.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.8.4.tgz", + "integrity": "sha512-tycmZxkGfZaxhMRbXlPXuVFpdWlXpir2W4AMhSJgRKzk/eDlIXOhb2LHWoLpDF7TEHylV5zNhykX6KAgHJmTNw==", + "peer": true, "dependencies": { - "@rollup/pluginutils": "^3.1.0", - "@types/resolve": "1.17.1", - "builtin-modules": "^3.1.0", - "deepmerge": "^4.2.2", - "is-module": "^1.0.0", - "resolve": "^1.19.0" + "@babel/helper-plugin-utils": "^7.8.0" }, - "engines": { - "node": ">= 10.0.0" + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-syntax-class-properties": { + "version": "7.12.13", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-class-properties/-/plugin-syntax-class-properties-7.12.13.tgz", + "integrity": "sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.12.13" }, "peerDependencies": { - "rollup": "^2.42.0" + "@babel/core": "^7.0.0-0" } }, - "node_modules/@rollup/plugin-typescript": { - "version": "8.3.1", - "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-8.3.1.tgz", - "integrity": "sha512-84rExe3ICUBXzqNX48WZV2Jp3OddjTMX97O2Py6D1KJaGSwWp0mDHXj+bCGNJqWHIEKDIT2U0sDjhP4czKi6cA==", - "dev": true, + "node_modules/@babel/plugin-syntax-class-static-block": { + "version": "7.14.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-class-static-block/-/plugin-syntax-class-static-block-7.14.5.tgz", + "integrity": "sha512-b+YyPmr6ldyNnM6sqYeMWE+bgJcJpO6yS4QD7ymxgH34GBPNDM/THBh8iunyvKIZztiwLH4CJZ0RxTk9emgpjw==", + "peer": true, "dependencies": { - "@rollup/pluginutils": "^3.1.0", - "resolve": "^1.17.0" + "@babel/helper-plugin-utils": "^7.14.5" }, "engines": { - "node": ">=8.0.0" + "node": ">=6.9.0" }, "peerDependencies": { - "rollup": "^2.14.0", - "tslib": "*", - "typescript": ">=3.7.0" + "@babel/core": "^7.0.0-0" } }, - "node_modules/@rollup/pluginutils": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.1.0.tgz", - "integrity": "sha512-GksZ6pr6TpIjHm8h9lSQ8pi8BE9VeubNT0OMJ3B5uZJ8pz73NPiqOtCog/x2/QzM1ENChPKxMDhiQuRHsqc+lg==", - "dev": true, + "node_modules/@babel/plugin-syntax-dynamic-import": { + "version": "7.8.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.8.3.tgz", + "integrity": "sha512-5gdGbFon+PszYzqs83S3E5mpi7/y/8M9eC90MRTZfduQOYW76ig6SOSPNe41IG5LoP3FGBn2N0RjVDSQiS94kQ==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.8.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-syntax-export-default-from": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-export-default-from/-/plugin-syntax-export-default-from-7.24.1.tgz", + "integrity": "sha512-cNXSxv9eTkGUtd0PsNMK8Yx5xeScxfpWOUAxE+ZPAXXEcAMOC3fk7LRdXq5fvpra2pLx2p1YtkAhpUbB2SwaRA==", + "peer": true, "dependencies": { - "@types/estree": "0.0.39", - "estree-walker": "^1.0.1", - "picomatch": "^2.2.2" + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { - "node": ">= 8.0.0" + "node": ">=6.9.0" }, "peerDependencies": { - "rollup": "^1.20.0||^2.0.0" + "@babel/core": "^7.0.0-0" } }, - "node_modules/@rollup/pluginutils/node_modules/estree-walker": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", - "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", - "dev": true - }, - "node_modules/@sinonjs/commons": { - "version": "1.8.3", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.3.tgz", - "integrity": "sha512-xkNcLAn/wZaX14RPlwizcKicDk9G3F8m2nU3L7Ukm5zBgTwiT0wsoFAHx9Jq56fJA1z/7uKGtCRu16sOUCLIHQ==", - "dev": true, + "node_modules/@babel/plugin-syntax-export-namespace-from": { + "version": "7.8.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-export-namespace-from/-/plugin-syntax-export-namespace-from-7.8.3.tgz", + "integrity": "sha512-MXf5laXo6c1IbEbegDmzGPwGNTsHZmEy6QGznu5Sh2UCWvueywb2ee+CCE4zQiZstxU9BMoQO9i6zUFSY0Kj0Q==", + "peer": true, "dependencies": { - "type-detect": "4.0.8" + "@babel/helper-plugin-utils": "^7.8.3" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@sinonjs/formatio": { - "version": "3.2.2", - "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.2.2.tgz", - "integrity": "sha512-B8SEsgd8gArBLMD6zpRw3juQ2FVSsmdd7qlevyDqzS9WTCtvF55/gAL+h6gue8ZvPYcdiPdvueM/qm//9XzyTQ==", - "dev": true, + "node_modules/@babel/plugin-syntax-flow": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.24.1.tgz", + "integrity": "sha512-sxi2kLTI5DeW5vDtMUsk4mTPwvlUDbjOnoWayhynCwrw4QXRld4QEYwqzY8JmQXaJUtgUuCIurtSRH5sn4c7mA==", + "peer": true, "dependencies": { - "@sinonjs/commons": "^1", - "@sinonjs/samsam": "^3.1.0" + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@sinonjs/samsam": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.3.3.tgz", - "integrity": "sha512-bKCMKZvWIjYD0BLGnNrxVuw4dkWCYsLqFOUWw8VgKF/+5Y+mE7LfHWPIYoDXowH+3a9LsWDMo0uAP8YDosPvHQ==", - "dev": true, + "node_modules/@babel/plugin-syntax-import-assertions": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.24.1.tgz", + "integrity": "sha512-IuwnI5XnuF189t91XbxmXeCDz3qs6iDRO7GJ++wcfgeXNs/8FmIlKcpDSXNVyuLQxlwvskmI3Ct73wUODkJBlQ==", + "peer": true, "dependencies": { - "@sinonjs/commons": "^1.3.0", - "array-from": "^2.1.1", - "lodash": "^4.17.15" + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@sinonjs/text-encoding": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.1.tgz", - "integrity": "sha512-+iTbntw2IZPb/anVDbypzfQa+ay64MW0Zo8aJ8gZPWMMK6/OubMVb6lUPMagqjOPnmtauXnFCACVl3O7ogjeqQ==", - "dev": true - }, - "node_modules/@tootallnate/quickjs-emscripten": { - "version": "0.23.0", - "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz", - "integrity": "sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==" - }, - "node_modules/@tsconfig/node10": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.8.tgz", - "integrity": "sha512-6XFfSQmMgq0CFLY1MslA/CPUfhIL919M1rMsa5lP2P097N2Wd1sSX0tx1u4olM16fLNhtHZpRhedZJphNJqmZg==", - "dev": true - }, - "node_modules/@tsconfig/node12": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.9.tgz", - "integrity": "sha512-/yBMcem+fbvhSREH+s14YJi18sp7J9jpuhYByADT2rypfajMZZN4WQ6zBGgBKp53NKmqI36wFYDb3yaMPurITw==", - "dev": true - }, - "node_modules/@tsconfig/node14": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.1.tgz", - "integrity": "sha512-509r2+yARFfHHE7T6Puu2jjkoycftovhXRqW328PDXTVGKihlb1P8Z9mMZH04ebyajfRY7dedfGynlrFHJUQCg==", - "dev": true - }, - "node_modules/@tsconfig/node16": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.2.tgz", - "integrity": "sha512-eZxlbI8GZscaGS7kkc/trHTT5xgrjH3/1n2JDwusC9iahPKWMRvRjJSAN5mCXviuTGQ/lHnhvv8Q1YTpnfz9gA==", - "dev": true - }, - "node_modules/@types/chai": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.3.tgz", - "integrity": "sha512-hC7OMnszpxhZPduX+m+nrx+uFoLkWOMiR4oa/AZF3MuSETYTZmFfJAHqZEM8MVlvfG7BEUcgvtwoCTxBp6hm3g==", - "dev": true - }, - "node_modules/@types/cucumber": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@types/cucumber/-/cucumber-7.0.0.tgz", - "integrity": "sha512-cr5NN8/jmbw3vDKTQfGW0cSzDtkvxixu9bUD6po9U6OEF04XLuukTDldFG34ccDscLkA8bYnZ7VjxP79cIC7tg==", - "deprecated": "This is a stub types definition. @cucumber/cucumber provides its own type definitions, so you do not need this installed.", - "dev": true, + "node_modules/@babel/plugin-syntax-import-attributes": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.24.1.tgz", + "integrity": "sha512-zhQTMH0X2nVLnb04tz+s7AMuasX8U0FnpE+nHTOhSOINjWMnopoZTxtIKsd45n4GQ/HIZLyfIpoul8e2m0DnRA==", + "peer": true, "dependencies": { - "@cucumber/cucumber": "*" + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@types/estree": { - "version": "0.0.39", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", - "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", - "dev": true - }, - "node_modules/@types/expect": { - "version": "24.3.0", - "resolved": "https://registry.npmjs.org/@types/expect/-/expect-24.3.0.tgz", - "integrity": "sha512-aq5Z+YFBz5o2b6Sp1jigx5nsmoZMK5Ceurjwy6PZmRv7dEi1jLtkARfvB1ME+OXJUG+7TZUDcv3WoCr/aor6dQ==", - "deprecated": "This is a stub types definition. expect provides its own type definitions, so you do not need this installed.", - "dev": true, + "node_modules/@babel/plugin-syntax-import-meta": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-meta/-/plugin-syntax-import-meta-7.10.4.tgz", + "integrity": "sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==", + "peer": true, "dependencies": { - "expect": "*" + "@babel/helper-plugin-utils": "^7.10.4" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@types/istanbul-lib-coverage": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz", - "integrity": "sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g==", - "dev": true - }, - "node_modules/@types/istanbul-lib-report": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.0.tgz", - "integrity": "sha512-plGgXAPfVKFoYfa9NpYDAkseG+g6Jr294RqeqcqDixSbU34MZVJRi/P+7Y8GDpzkEwLaGZZOpKIEmeVZNtKsrg==", - "dev": true, + "node_modules/@babel/plugin-syntax-json-strings": { + "version": "7.8.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz", + "integrity": "sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA==", + "peer": true, "dependencies": { - "@types/istanbul-lib-coverage": "*" + "@babel/helper-plugin-utils": "^7.8.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@types/istanbul-reports": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.1.tgz", - "integrity": "sha512-c3mAZEuK0lvBp8tmuL74XRKn1+y2dcwOUpH7x4WrF6gk1GIgiluDRgMYQtw2OFcBvAJWlt6ASU3tSqxp0Uu0Aw==", - "dev": true, + "node_modules/@babel/plugin-syntax-jsx": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.1.tgz", + "integrity": "sha512-2eCtxZXf+kbkMIsXS4poTvT4Yu5rXiRa+9xGVT56raghjmBTKMpFNc9R4IDiB4emao9eO22Ox7CxuJG7BgExqA==", + "peer": true, "dependencies": { - "@types/istanbul-lib-report": "*" + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@types/json-schema": { - "version": "7.0.9", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.9.tgz", - "integrity": "sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ==", - "dev": true - }, - "node_modules/@types/json5": { - "version": "0.0.29", - "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", - "integrity": "sha1-7ihweulOEdK4J7y+UnC86n8+ce4=", - "dev": true, - "optional": true - }, - "node_modules/@types/mocha": { - "version": "9.1.0", - "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.0.tgz", - "integrity": "sha512-QCWHkbMv4Y5U9oW10Uxbr45qMMSzl4OzijsozynUAgx3kEHUdXB00udx2dWDQ7f2TU2a2uuiFaRZjCe3unPpeg==", - "dev": true - }, - "node_modules/@types/nock": { - "version": "9.3.1", - "resolved": "https://registry.npmjs.org/@types/nock/-/nock-9.3.1.tgz", - "integrity": "sha512-eOVHXS5RnWOjTVhu3deCM/ruy9E6JCgeix2g7wpFiekQh3AaEAK1cz43tZDukKmtSmQnwvSySq7ubijCA32I7Q==", - "dev": true, + "node_modules/@babel/plugin-syntax-logical-assignment-operators": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz", + "integrity": "sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig==", + "peer": true, "dependencies": { - "@types/node": "*" + "@babel/helper-plugin-utils": "^7.10.4" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@types/node": { - "version": "17.0.21", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.21.tgz", - "integrity": "sha512-DBZCJbhII3r90XbQxI8Y9IjjiiOGlZ0Hr32omXIZvwwZ7p4DMMXGrKXVyPfuoBOri9XNtL0UK69jYIBIsRX3QQ==", - "dev": true - }, - "node_modules/@types/node-fetch": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.3.tgz", - "integrity": "sha512-ETTL1mOEdq/sxUtgtOhKjyB2Irra4cjxksvcMUR5Zr4n+PxVhsCD9WS46oPbHL3et9Zde7CNRr+WUNlcHvsX+w==", - "dev": true, + "node_modules/@babel/plugin-syntax-nullish-coalescing-operator": { + "version": "7.8.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.8.3.tgz", + "integrity": "sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ==", + "peer": true, "dependencies": { - "@types/node": "*", - "form-data": "^3.0.0" + "@babel/helper-plugin-utils": "^7.8.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@types/node-fetch/node_modules/form-data": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", - "integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", - "dev": true, + "node_modules/@babel/plugin-syntax-numeric-separator": { + "version": "7.10.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-numeric-separator/-/plugin-syntax-numeric-separator-7.10.4.tgz", + "integrity": "sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug==", + "peer": true, "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" + "@babel/helper-plugin-utils": "^7.10.4" }, - "engines": { - "node": ">= 6" + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@types/pubnub": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/@types/pubnub/-/pubnub-7.2.0.tgz", - "integrity": "sha512-Ui58Xsn8/4Ty1hFW0t91ED6FKezzipjO+GEJviOdJdqp817+I5/WMfo5zBsDfjbZQWMqcdrktMauKpUqiIF1wA==", - "dev": true - }, - "node_modules/@types/resolve": { - "version": "1.17.1", - "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz", - "integrity": "sha512-yy7HuzQhj0dhGpD8RLXSZWEkLsV9ibvxvi6EiJ3bkqLAO1RGo0WbkWQiwpRlSFymTJRz0d3k5LM3kkx8ArDbLw==", - "dev": true, + "node_modules/@babel/plugin-syntax-object-rest-spread": { + "version": "7.8.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.8.3.tgz", + "integrity": "sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA==", + "peer": true, "dependencies": { - "@types/node": "*" + "@babel/helper-plugin-utils": "^7.8.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@types/stack-utils": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.1.tgz", - "integrity": "sha512-Hl219/BT5fLAaz6NDkSuhzasy49dwQS/DSdu4MdggFB8zcXv7vflBI3xp7FEmkmdDkBUI2bPUNeMttp2knYdxw==", - "dev": true - }, - "node_modules/@types/uuid": { - "version": "8.3.4", - "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-8.3.4.tgz", - "integrity": "sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==", - "dev": true, - "peer": true - }, - "node_modules/@types/yargs": { - "version": "16.0.4", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-16.0.4.tgz", - "integrity": "sha512-T8Yc9wt/5LbJyCaLiHPReJa0kApcIgJ7Bn735GjItUfh08Z1pJvu8QZqb9s+mMvKV6WUQRV7K2R46YbjMXTTJw==", - "dev": true, + "node_modules/@babel/plugin-syntax-optional-catch-binding": { + "version": "7.8.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-catch-binding/-/plugin-syntax-optional-catch-binding-7.8.3.tgz", + "integrity": "sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q==", + "peer": true, "dependencies": { - "@types/yargs-parser": "*" + "@babel/helper-plugin-utils": "^7.8.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@types/yargs-parser": { - "version": "20.2.1", - "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-20.2.1.tgz", - "integrity": "sha512-7tFImggNeNBVMsn0vLrpn1H1uPrUBdnARPTpZoitY37ZrdJREzf7I16tMrlK3hen349gr1NYh8CmZQa7CTG6Aw==", - "dev": true + "node_modules/@babel/plugin-syntax-optional-chaining": { + "version": "7.8.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.8.3.tgz", + "integrity": "sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.8.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } }, - "node_modules/@typescript-eslint/eslint-plugin": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.12.1.tgz", - "integrity": "sha512-M499lqa8rnNK7mUv74lSFFttuUsubIRdAbHcVaP93oFcKkEmHmLqy2n7jM9C8DVmFMYK61ExrZU6dLYhQZmUpw==", - "dev": true, + "node_modules/@babel/plugin-syntax-private-property-in-object": { + "version": "7.14.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-private-property-in-object/-/plugin-syntax-private-property-in-object-7.14.5.tgz", + "integrity": "sha512-0wVnp9dxJ72ZUJDV27ZfbSj6iHLoytYZmh3rFcxNnvsJF3ktkzLDZPy/mA17HGsaQT3/DQsWYX1f1QGWkCoVUg==", + "peer": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.12.1", - "@typescript-eslint/type-utils": "5.12.1", - "@typescript-eslint/utils": "5.12.1", - "debug": "^4.3.2", - "functional-red-black-tree": "^1.0.1", - "ignore": "^5.1.8", - "regexpp": "^3.2.0", - "semver": "^7.3.5", - "tsutils": "^3.21.0" + "@babel/helper-plugin-utils": "^7.14.5" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" + "node": ">=6.9.0" }, "peerDependencies": { - "@typescript-eslint/parser": "^5.0.0", - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } + "@babel/core": "^7.0.0-0" } }, - "node_modules/@typescript-eslint/parser": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.12.1.tgz", - "integrity": "sha512-6LuVUbe7oSdHxUWoX/m40Ni8gsZMKCi31rlawBHt7VtW15iHzjbpj2WLiToG2758KjtCCiLRKZqfrOdl3cNKuw==", - "dev": true, + "node_modules/@babel/plugin-syntax-top-level-await": { + "version": "7.14.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.14.5.tgz", + "integrity": "sha512-hx++upLv5U1rgYfwe1xBQUhRmU41NEvpUvrp8jkrSCdvGSnM5/qdRMtylJ6PG5OFkBaHkbTAKTnd3/YyESRHFw==", + "peer": true, "dependencies": { - "@typescript-eslint/scope-manager": "5.12.1", - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/typescript-estree": "5.12.1", - "debug": "^4.3.2" + "@babel/helper-plugin-utils": "^7.14.5" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" + "node": ">=6.9.0" }, "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } + "@babel/core": "^7.0.0-0" } }, - "node_modules/@typescript-eslint/scope-manager": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-5.12.1.tgz", - "integrity": "sha512-J0Wrh5xS6XNkd4TkOosxdpObzlYfXjAFIm9QxYLCPOcHVv1FyyFCPom66uIh8uBr0sZCrtS+n19tzufhwab8ZQ==", - "dev": true, + "node_modules/@babel/plugin-syntax-typescript": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.1.tgz", + "integrity": "sha512-Yhnmvy5HZEnHUty6i++gcfH1/l68AHnItFHnaCv6hn9dNh0hQvvQJsxpi4BMBFN5DLeHBuucT/0DgzXif/OyRw==", + "peer": true, "dependencies": { - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/visitor-keys": "5.12.1" + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": ">=6.9.0" }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@typescript-eslint/type-utils": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.12.1.tgz", - "integrity": "sha512-Gh8feEhsNLeCz6aYqynh61Vsdy+tiNNkQtc+bN3IvQvRqHkXGUhYkUi+ePKzP0Mb42se7FDb+y2SypTbpbR/Sg==", - "dev": true, + "node_modules/@babel/plugin-syntax-unicode-sets-regex": { + "version": "7.18.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-unicode-sets-regex/-/plugin-syntax-unicode-sets-regex-7.18.6.tgz", + "integrity": "sha512-727YkEAPwSIQTv5im8QHz3upqp92JTWhidIC81Tdx4VJYIte/VndKf1qKrfnnhPLiPghStWfvC/iFaMCQu7Nqg==", + "peer": true, "dependencies": { - "@typescript-eslint/utils": "5.12.1", - "debug": "^4.3.2", - "tsutils": "^3.21.0" + "@babel/helper-create-regexp-features-plugin": "^7.18.6", + "@babel/helper-plugin-utils": "^7.18.6" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" + "node": ">=6.9.0" }, "peerDependencies": { - "eslint": "*" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } + "@babel/core": "^7.0.0" } }, - "node_modules/@typescript-eslint/types": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.12.1.tgz", - "integrity": "sha512-hfcbq4qVOHV1YRdhkDldhV9NpmmAu2vp6wuFODL71Y0Ixak+FLeEU4rnPxgmZMnGreGEghlEucs9UZn5KOfHJA==", - "dev": true, + "node_modules/@babel/plugin-transform-arrow-functions": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.24.1.tgz", + "integrity": "sha512-ngT/3NkRhsaep9ck9uj2Xhv9+xB1zShY3tM3g6om4xxCELwCDN4g4Aq5dRn48+0hasAql7s2hdBOysCfNpr4fw==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": ">=6.9.0" }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@typescript-eslint/typescript-estree": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.12.1.tgz", - "integrity": "sha512-ahOdkIY9Mgbza7L9sIi205Pe1inCkZWAHE1TV1bpxlU4RZNPtXaDZfiiFWcL9jdxvW1hDYZJXrFm+vlMkXRbBw==", - "dev": true, + "node_modules/@babel/plugin-transform-async-generator-functions": { + "version": "7.24.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-generator-functions/-/plugin-transform-async-generator-functions-7.24.3.tgz", + "integrity": "sha512-Qe26CMYVjpQxJ8zxM1340JFNjZaF+ISWpr1Kt/jGo+ZTUzKkfw/pphEWbRCb+lmSM6k/TOgfYLvmbHkUQ0asIg==", + "peer": true, "dependencies": { - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/visitor-keys": "5.12.1", - "debug": "^4.3.2", - "globby": "^11.0.4", - "is-glob": "^4.0.3", - "semver": "^7.3.5", - "tsutils": "^3.21.0" + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-remap-async-to-generator": "^7.22.20", + "@babel/plugin-syntax-async-generators": "^7.8.4" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" + "node": ">=6.9.0" }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@typescript-eslint/utils": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.12.1.tgz", - "integrity": "sha512-Qq9FIuU0EVEsi8fS6pG+uurbhNTtoYr4fq8tKjBupsK5Bgbk2I32UGm0Sh+WOyjOPgo/5URbxxSNV6HYsxV4MQ==", - "dev": true, + "node_modules/@babel/plugin-transform-async-to-generator": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.24.1.tgz", + "integrity": "sha512-AawPptitRXp1y0n4ilKcGbRYWfbbzFWz2NqNu7dacYDtFtz0CMjG64b3LQsb3KIgnf4/obcUL78hfaOS7iCUfw==", + "peer": true, "dependencies": { - "@types/json-schema": "^7.0.9", - "@typescript-eslint/scope-manager": "5.12.1", - "@typescript-eslint/types": "5.12.1", - "@typescript-eslint/typescript-estree": "5.12.1", - "eslint-scope": "^5.1.1", - "eslint-utils": "^3.0.0" + "@babel/helper-module-imports": "^7.24.1", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-remap-async-to-generator": "^7.22.20" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" + "node": ">=6.9.0" }, "peerDependencies": { - "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0" + "@babel/core": "^7.0.0-0" } }, - "node_modules/@typescript-eslint/utils/node_modules/eslint-scope": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-5.1.1.tgz", - "integrity": "sha512-2NxwbF/hZ0KpepYN0cNbo+FN6XoK7GaHlQhgx/hIZl6Va0bF45RQOOwhLIy8lQDbuCiadSLCBnH2CFYquit5bw==", - "dev": true, + "node_modules/@babel/plugin-transform-block-scoped-functions": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.24.1.tgz", + "integrity": "sha512-TWWC18OShZutrv9C6mye1xwtam+uNi2bnTOCBUd5sZxyHOiWbU6ztSROofIMrK84uweEZC219POICK/sTYwfgg==", + "peer": true, "dependencies": { - "esrecurse": "^4.3.0", - "estraverse": "^4.1.1" + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { - "node": ">=8.0.0" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@typescript-eslint/utils/node_modules/estraverse": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", - "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==", - "dev": true, + "node_modules/@babel/plugin-transform-block-scoping": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.24.4.tgz", + "integrity": "sha512-nIFUZIpGKDf9O9ttyRXpHFpKC+X3Y5mtshZONuEUYBomAKoM4y029Jr+uB1bHGPhNmK8YXHevDtKDOLmtRrp6g==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, "engines": { - "node": ">=4.0" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@typescript-eslint/visitor-keys": { - "version": "5.12.1", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-5.12.1.tgz", - "integrity": "sha512-l1KSLfupuwrXx6wc0AuOmC7Ko5g14ZOQ86wJJqRbdLbXLK02pK/DPiDDqCc7BqqiiA04/eAA6ayL0bgOrAkH7A==", - "dev": true, + "node_modules/@babel/plugin-transform-class-properties": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-class-properties/-/plugin-transform-class-properties-7.24.1.tgz", + "integrity": "sha512-OMLCXi0NqvJfORTaPQBwqLXHhb93wkBKZ4aNwMl6WtehO7ar+cmp+89iPEQPqxAnxsOKTaMcs3POz3rKayJ72g==", + "peer": true, "dependencies": { - "@typescript-eslint/types": "5.12.1", - "eslint-visitor-keys": "^3.0.0" + "@babel/helper-create-class-features-plugin": "^7.24.1", + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": ">=6.9.0" }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/typescript-eslint" + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/@ungap/promise-all-settled": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz", - "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", - "dev": true - }, - "node_modules/accepts": { - "version": "1.3.8", - "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", - "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", - "dev": true, + "node_modules/@babel/plugin-transform-class-static-block": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-class-static-block/-/plugin-transform-class-static-block-7.24.4.tgz", + "integrity": "sha512-B8q7Pz870Hz/q9UgP8InNpY01CSLDSCyqX7zcRuv3FcPl87A2G17lASroHWaCtbdIcbYzOZ7kWmXFKbijMSmFg==", + "peer": true, "dependencies": { - "mime-types": "~2.1.34", - "negotiator": "0.6.3" + "@babel/helper-create-class-features-plugin": "^7.24.4", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-class-static-block": "^7.14.5" }, "engines": { - "node": ">= 0.6" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.12.0" } }, - "node_modules/acorn": { - "version": "8.8.2", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", - "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", - "dev": true, - "bin": { - "acorn": "bin/acorn" + "node_modules/@babel/plugin-transform-classes": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-classes/-/plugin-transform-classes-7.24.1.tgz", + "integrity": "sha512-ZTIe3W7UejJd3/3R4p7ScyyOoafetUShSf4kCqV0O7F/RiHxVj/wRaRnQlrGwflvcehNA8M42HkAiEDYZu2F1Q==", + "peer": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-compilation-targets": "^7.23.6", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-replace-supers": "^7.24.1", + "@babel/helper-split-export-declaration": "^7.22.6", + "globals": "^11.1.0" }, "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/acorn-jsx": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", - "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", - "dev": true, + "node": ">=6.9.0" + }, "peerDependencies": { - "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + "@babel/core": "^7.0.0-0" } }, - "node_modules/acorn-walk": { - "version": "8.2.0", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.2.0.tgz", - "integrity": "sha512-k+iyHEuPgSw6SbuDpGQM+06HQUa04DZ3o+F6CSzXMvvI5KMvnaEqXe+YVe555R9nn6GPt404fos4wcgpw12SDA==", - "dev": true, + "node_modules/@babel/plugin-transform-classes/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "peer": true, "engines": { - "node": ">=0.4.0" + "node": ">=4" } }, - "node_modules/after": { - "version": "0.8.2", - "resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz", - "integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=", - "dev": true - }, - "node_modules/agent-base": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz", - "integrity": "sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==", + "node_modules/@babel/plugin-transform-computed-properties": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.24.1.tgz", + "integrity": "sha512-5pJGVIUfJpOS+pAqBQd+QMaTD2vCL/HcePooON6pDpHgRp4gNRmzyHTPIkXntwKsq3ayUFVfJaIKPw2pOkOcTw==", + "peer": true, "dependencies": { - "debug": "^4.3.4" + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/template": "^7.24.0" }, "engines": { - "node": ">= 14" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/agent-base/node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "node_modules/@babel/plugin-transform-destructuring": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.24.1.tgz", + "integrity": "sha512-ow8jciWqNxR3RYbSNVuF4U2Jx130nwnBnhRw6N6h1bOejNkABmcI5X5oz29K4alWX7vf1C+o6gtKXikzRKkVdw==", + "peer": true, "dependencies": { - "ms": "2.1.2" + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { - "node": ">=6.0" + "node": ">=6.9.0" }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/agentkeepalive": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-3.5.2.tgz", - "integrity": "sha512-e0L/HNe6qkQ7H19kTlRRqUibEAwDK5AFk6y3PtMsuut2VAH6+Q4xZml1tNDJD7kSAyqmbG/K08K5WEJYtUrSlQ==", + "node_modules/@babel/plugin-transform-dotall-regex": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.24.1.tgz", + "integrity": "sha512-p7uUxgSoZwZ2lPNMzUkqCts3xlp8n+o05ikjy7gbtFJSt9gdU88jAmtfmOxHM14noQXBxfgzf2yRWECiNVhTCw==", + "peer": true, "dependencies": { - "humanize-ms": "^1.2.1" + "@babel/helper-create-regexp-features-plugin": "^7.22.15", + "@babel/helper-plugin-utils": "^7.24.0" }, "engines": { - "node": ">= 4.0.0" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/ajv": { - "version": "6.12.6", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", - "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", - "dev": true, + "node_modules/@babel/plugin-transform-duplicate-keys": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.24.1.tgz", + "integrity": "sha512-msyzuUnvsjsaSaocV6L7ErfNsa5nDWL1XKNnDePLgmz+WdU4w/J8+AxBMrWfi9m4IxfL5sZQKUPQKDQeeAT6lA==", + "peer": true, "dependencies": { - "fast-deep-equal": "^3.1.1", - "fast-json-stable-stringify": "^2.0.0", - "json-schema-traverse": "^0.4.1", - "uri-js": "^4.2.2" + "@babel/helper-plugin-utils": "^7.24.0" }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/epoberezkin" + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/ansi-colors": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", - "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", - "dev": true, + "node_modules/@babel/plugin-transform-dynamic-import": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-dynamic-import/-/plugin-transform-dynamic-import-7.24.1.tgz", + "integrity": "sha512-av2gdSTyXcJVdI+8aFZsCAtR29xJt0S5tas+Ef8NvBNmD1a+N/3ecMLeMBgfcK+xzsjdLDT6oHt+DFPyeqUbDA==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-dynamic-import": "^7.8.3" + }, "engines": { - "node": ">=6" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, + "node_modules/@babel/plugin-transform-exponentiation-operator": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.24.1.tgz", + "integrity": "sha512-U1yX13dVBSwS23DEAqU+Z/PkwE9/m7QQy8Y9/+Tdb8UWYaGNDYwTLi19wqIAiROr8sXVum9A/rtiH5H0boUcTw==", + "peer": true, + "dependencies": { + "@babel/helper-builder-binary-assignment-operator-visitor": "^7.22.15", + "@babel/helper-plugin-utils": "^7.24.0" + }, "engines": { - "node": ">=8" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dev": true, + "node_modules/@babel/plugin-transform-export-namespace-from": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-export-namespace-from/-/plugin-transform-export-namespace-from-7.24.1.tgz", + "integrity": "sha512-Ft38m/KFOyzKw2UaJFkWG9QnHPG/Q/2SkOrRk4pNBPg5IPZ+dOxcmkK5IyuBcxiNPyyYowPGUReyBvrvZs7IlQ==", + "peer": true, "dependencies": { - "color-convert": "^1.9.0" + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-export-namespace-from": "^7.8.3" }, "engines": { - "node": ">=4" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/any-promise": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", - "integrity": "sha1-q8av7tzqUugJzcA3au0845Y10X8=", - "dev": true + "node_modules/@babel/plugin-transform-flow-strip-types": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.24.1.tgz", + "integrity": "sha512-iIYPIWt3dUmUKKE10s3W+jsQ3icFkw0JyRVyY1B7G4yK/nngAOHLVx8xlhA6b/Jzl/Y0nis8gjqhqKtRDQqHWQ==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-flow": "^7.24.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } }, - "node_modules/anymatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.2.tgz", - "integrity": "sha512-P43ePfOAIupkguHUycrc4qJ9kz8ZiuOUijaETwX7THt0Y/GNK7v0aa8rY816xWjZ7rJdA5XdMcpVFTKMq+RvWg==", - "dev": true, + "node_modules/@babel/plugin-transform-for-of": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.24.1.tgz", + "integrity": "sha512-OxBdcnF04bpdQdR3i4giHZNZQn7cm8RQKcSwA17wAAqEELo1ZOwp5FFgeptWUQXFyT9kwHo10aqqauYkRZPCAg==", + "peer": true, "dependencies": { - "normalize-path": "^3.0.0", - "picomatch": "^2.0.4" + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5" }, "engines": { - "node": ">= 8" + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" } }, - "node_modules/arg": { - "version": "4.1.3", + "node_modules/@babel/plugin-transform-function-name": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-function-name/-/plugin-transform-function-name-7.24.1.tgz", + "integrity": "sha512-BXmDZpPlh7jwicKArQASrj8n22/w6iymRnvHYYd2zO30DbE277JO20/7yXJT3QxDPtiQiOxQBbZH4TpivNXIxA==", + "peer": true, + "dependencies": { + "@babel/helper-compilation-targets": "^7.23.6", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-json-strings": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-json-strings/-/plugin-transform-json-strings-7.24.1.tgz", + "integrity": "sha512-U7RMFmRvoasscrIFy5xA4gIp8iWnWubnKkKuUGJjsuOH7GfbMkB+XZzeslx2kLdEGdOJDamEmCqOks6e8nv8DQ==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-json-strings": "^7.8.3" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-literals": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-literals/-/plugin-transform-literals-7.24.1.tgz", + "integrity": "sha512-zn9pwz8U7nCqOYIiBaOxoQOtYmMODXTJnkxG4AtX8fPmnCRYWBOHD0qcpwS9e2VDSp1zNJYpdnFMIKb8jmwu6g==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-logical-assignment-operators": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-logical-assignment-operators/-/plugin-transform-logical-assignment-operators-7.24.1.tgz", + "integrity": "sha512-OhN6J4Bpz+hIBqItTeWJujDOfNP+unqv/NJgyhlpSqgBTPm37KkMmZV6SYcOj+pnDbdcl1qRGV/ZiIjX9Iy34w==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-logical-assignment-operators": "^7.10.4" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-member-expression-literals": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-member-expression-literals/-/plugin-transform-member-expression-literals-7.24.1.tgz", + "integrity": "sha512-4ojai0KysTWXzHseJKa1XPNXKRbuUrhkOPY4rEGeR+7ChlJVKxFa3H3Bz+7tWaGKgJAXUWKOGmltN+u9B3+CVg==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-modules-amd": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.24.1.tgz", + "integrity": "sha512-lAxNHi4HVtjnHd5Rxg3D5t99Xm6H7b04hUS7EHIXcUl2EV4yl1gWdqZrNzXnSrHveL9qMdbODlLF55mvgjAfaQ==", + "peer": true, + "dependencies": { + "@babel/helper-module-transforms": "^7.23.3", + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-modules-commonjs": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.24.1.tgz", + "integrity": "sha512-szog8fFTUxBfw0b98gEWPaEqF42ZUD/T3bkynW/wtgx2p/XCP55WEsb+VosKceRSd6njipdZvNogqdtI4Q0chw==", + "peer": true, + "dependencies": { + "@babel/helper-module-transforms": "^7.23.3", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-simple-access": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-modules-systemjs": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.24.1.tgz", + "integrity": "sha512-mqQ3Zh9vFO1Tpmlt8QPnbwGHzNz3lpNEMxQb1kAemn/erstyqw1r9KeOlOfo3y6xAnFEcOv2tSyrXfmMk+/YZA==", + "peer": true, + "dependencies": { + "@babel/helper-hoist-variables": "^7.22.5", + "@babel/helper-module-transforms": "^7.23.3", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-validator-identifier": "^7.22.20" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-modules-umd": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-umd/-/plugin-transform-modules-umd-7.24.1.tgz", + "integrity": "sha512-tuA3lpPj+5ITfcCluy6nWonSL7RvaG0AOTeAuvXqEKS34lnLzXpDb0dcP6K8jD0zWZFNDVly90AGFJPnm4fOYg==", + "peer": true, + "dependencies": { + "@babel/helper-module-transforms": "^7.23.3", + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-named-capturing-groups-regex": { + "version": "7.22.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.22.5.tgz", + "integrity": "sha512-YgLLKmS3aUBhHaxp5hi1WJTgOUb/NCuDHzGT9z9WTt3YG+CPRhJs6nprbStx6DnWM4dh6gt7SU3sZodbZ08adQ==", + "peer": true, + "dependencies": { + "@babel/helper-create-regexp-features-plugin": "^7.22.5", + "@babel/helper-plugin-utils": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } + }, + "node_modules/@babel/plugin-transform-new-target": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-new-target/-/plugin-transform-new-target-7.24.1.tgz", + "integrity": "sha512-/rurytBM34hYy0HKZQyA0nHbQgQNFm4Q/BOc9Hflxi2X3twRof7NaE5W46j4kQitm7SvACVRXsa6N/tSZxvPug==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-nullish-coalescing-operator": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.24.1.tgz", + "integrity": "sha512-iQ+caew8wRrhCikO5DrUYx0mrmdhkaELgFa+7baMcVuhxIkN7oxt06CZ51D65ugIb1UWRQ8oQe+HXAVM6qHFjw==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-numeric-separator": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-numeric-separator/-/plugin-transform-numeric-separator-7.24.1.tgz", + "integrity": "sha512-7GAsGlK4cNL2OExJH1DzmDeKnRv/LXq0eLUSvudrehVA5Rgg4bIrqEUW29FbKMBRT0ztSqisv7kjP+XIC4ZMNw==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-numeric-separator": "^7.10.4" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-object-rest-spread": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-rest-spread/-/plugin-transform-object-rest-spread-7.24.1.tgz", + "integrity": "sha512-XjD5f0YqOtebto4HGISLNfiNMTTs6tbkFf2TOqJlYKYmbo+mN9Dnpl4SRoofiziuOWMIyq3sZEUqLo3hLITFEA==", + "peer": true, + "dependencies": { + "@babel/helper-compilation-targets": "^7.23.6", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-object-rest-spread": "^7.8.3", + "@babel/plugin-transform-parameters": "^7.24.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-object-super": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.24.1.tgz", + "integrity": "sha512-oKJqR3TeI5hSLRxudMjFQ9re9fBVUU0GICqM3J1mi8MqlhVr6hC/ZN4ttAyMuQR6EZZIY6h/exe5swqGNNIkWQ==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-replace-supers": "^7.24.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-optional-catch-binding": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-optional-catch-binding/-/plugin-transform-optional-catch-binding-7.24.1.tgz", + "integrity": "sha512-oBTH7oURV4Y+3EUrf6cWn1OHio3qG/PVwO5J03iSJmBg6m2EhKjkAu/xuaXaYwWW9miYtvbWv4LNf0AmR43LUA==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-optional-catch-binding": "^7.8.3" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-optional-chaining": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-optional-chaining/-/plugin-transform-optional-chaining-7.24.1.tgz", + "integrity": "sha512-n03wmDt+987qXwAgcBlnUUivrZBPZ8z1plL0YvgQalLm+ZE5BMhGm94jhxXtA1wzv1Cu2aaOv1BM9vbVttrzSg==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5", + "@babel/plugin-syntax-optional-chaining": "^7.8.3" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-parameters": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.24.1.tgz", + "integrity": "sha512-8Jl6V24g+Uw5OGPeWNKrKqXPDw2YDjLc53ojwfMcKwlEoETKU9rU0mHUtcg9JntWI/QYzGAXNWEcVHZ+fR+XXg==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-private-methods": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-private-methods/-/plugin-transform-private-methods-7.24.1.tgz", + "integrity": "sha512-tGvisebwBO5em4PaYNqt4fkw56K2VALsAbAakY0FjTYqJp7gfdrgr7YX76Or8/cpik0W6+tj3rZ0uHU9Oil4tw==", + "peer": true, + "dependencies": { + "@babel/helper-create-class-features-plugin": "^7.24.1", + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-private-property-in-object": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-private-property-in-object/-/plugin-transform-private-property-in-object-7.24.1.tgz", + "integrity": "sha512-pTHxDVa0BpUbvAgX3Gat+7cSciXqUcY9j2VZKTbSB6+VQGpNgNO9ailxTGHSXlqOnX1Hcx1Enme2+yv7VqP9bg==", + "peer": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-create-class-features-plugin": "^7.24.1", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-private-property-in-object": "^7.14.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-property-literals": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-property-literals/-/plugin-transform-property-literals-7.24.1.tgz", + "integrity": "sha512-LetvD7CrHmEx0G442gOomRr66d7q8HzzGGr4PMHGr+5YIm6++Yke+jxj246rpvsbyhJwCLxcTn6zW1P1BSenqA==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-react-display-name": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.24.1.tgz", + "integrity": "sha512-mvoQg2f9p2qlpDQRBC7M3c3XTr0k7cp/0+kFKKO/7Gtu0LSw16eKB+Fabe2bDT/UpsyasTBBkAnbdsLrkD5XMw==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-react-jsx": { + "version": "7.23.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.23.4.tgz", + "integrity": "sha512-5xOpoPguCZCRbo/JeHlloSkTA8Bld1J/E1/kLfD1nsuiW1m8tduTA1ERCgIZokDflX/IBzKcqR3l7VlRgiIfHA==", + "peer": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-module-imports": "^7.22.15", + "@babel/helper-plugin-utils": "^7.22.5", + "@babel/plugin-syntax-jsx": "^7.23.3", + "@babel/types": "^7.23.4" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-react-jsx-self": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.24.1.tgz", + "integrity": "sha512-kDJgnPujTmAZ/9q2CN4m2/lRsUUPDvsG3+tSHWUJIzMGTt5U/b/fwWd3RO3n+5mjLrsBrVa5eKFRVSQbi3dF1w==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-react-jsx-source": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.24.1.tgz", + "integrity": "sha512-1v202n7aUq4uXAieRTKcwPzNyphlCuqHHDcdSNc+vdhoTEZcFMh+L5yZuCmGaIO7bs1nJUNfHB89TZyoL48xNA==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-regenerator": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.24.1.tgz", + "integrity": "sha512-sJwZBCzIBE4t+5Q4IGLaaun5ExVMRY0lYwos/jNecjMrVCygCdph3IKv0tkP5Fc87e/1+bebAmEAGBfnRD+cnw==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "regenerator-transform": "^0.15.2" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-reserved-words": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-reserved-words/-/plugin-transform-reserved-words-7.24.1.tgz", + "integrity": "sha512-JAclqStUfIwKN15HrsQADFgeZt+wexNQ0uLhuqvqAUFoqPMjEcFCYZBhq0LUdz6dZK/mD+rErhW71fbx8RYElg==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-runtime": { + "version": "7.24.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.24.3.tgz", + "integrity": "sha512-J0BuRPNlNqlMTRJ72eVptpt9VcInbxO6iP3jaxr+1NPhC0UkKL+6oeX6VXMEYdADnuqmMmsBspt4d5w8Y/TCbQ==", + "peer": true, + "dependencies": { + "@babel/helper-module-imports": "^7.24.3", + "@babel/helper-plugin-utils": "^7.24.0", + "babel-plugin-polyfill-corejs2": "^0.4.10", + "babel-plugin-polyfill-corejs3": "^0.10.1", + "babel-plugin-polyfill-regenerator": "^0.6.1", + "semver": "^6.3.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-runtime/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "peer": true, + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/@babel/plugin-transform-shorthand-properties": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.24.1.tgz", + "integrity": "sha512-LyjVB1nsJ6gTTUKRjRWx9C1s9hE7dLfP/knKdrfeH9UPtAGjYGgxIbFfx7xyLIEWs7Xe1Gnf8EWiUqfjLhInZA==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-spread": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-spread/-/plugin-transform-spread-7.24.1.tgz", + "integrity": "sha512-KjmcIM+fxgY+KxPVbjelJC6hrH1CgtPmTvdXAfn3/a9CnWGSTY7nH4zm5+cjmWJybdcPSsD0++QssDsjcpe47g==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-sticky-regex": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.24.1.tgz", + "integrity": "sha512-9v0f1bRXgPVcPrngOQvLXeGNNVLc8UjMVfebo9ka0WF3/7+aVUHmaJVT3sa0XCzEFioPfPHZiOcYG9qOsH63cw==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-template-literals": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.24.1.tgz", + "integrity": "sha512-WRkhROsNzriarqECASCNu/nojeXCDTE/F2HmRgOzi7NGvyfYGq1NEjKBK3ckLfRgGc6/lPAqP0vDOSw3YtG34g==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-typeof-symbol": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.24.1.tgz", + "integrity": "sha512-CBfU4l/A+KruSUoW+vTQthwcAdwuqbpRNB8HQKlZABwHRhsdHZ9fezp4Sn18PeAlYxTNiLMlx4xUBV3AWfg1BA==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-typescript": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.24.4.tgz", + "integrity": "sha512-79t3CQ8+oBGk/80SQ8MN3Bs3obf83zJ0YZjDmDaEZN8MqhMI760apl5z6a20kFeMXBwJX99VpKT8CKxEBp5H1g==", + "peer": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.22.5", + "@babel/helper-create-class-features-plugin": "^7.24.4", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/plugin-syntax-typescript": "^7.24.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-unicode-escapes": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.24.1.tgz", + "integrity": "sha512-RlkVIcWT4TLI96zM660S877E7beKlQw7Ig+wqkKBiWfj0zH5Q4h50q6er4wzZKRNSYpfo6ILJ+hrJAGSX2qcNw==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-unicode-property-regex": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-property-regex/-/plugin-transform-unicode-property-regex-7.24.1.tgz", + "integrity": "sha512-Ss4VvlfYV5huWApFsF8/Sq0oXnGO+jB+rijFEFugTd3cwSObUSnUi88djgR5528Csl0uKlrI331kRqe56Ov2Ng==", + "peer": true, + "dependencies": { + "@babel/helper-create-regexp-features-plugin": "^7.22.15", + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-unicode-regex": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.24.1.tgz", + "integrity": "sha512-2A/94wgZgxfTsiLaQ2E36XAOdcZmGAaEEgVmxQWwZXWkGhvoHbaqXcKnU8zny4ycpu3vNqg0L/PcCiYtHtA13g==", + "peer": true, + "dependencies": { + "@babel/helper-create-regexp-features-plugin": "^7.22.15", + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-transform-unicode-sets-regex": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-sets-regex/-/plugin-transform-unicode-sets-regex-7.24.1.tgz", + "integrity": "sha512-fqj4WuzzS+ukpgerpAoOnMfQXwUHFxXUZUE84oL2Kao2N8uSlvcpnAidKASgsNgzZHBsHWvcm8s9FPWUhAb8fA==", + "peer": true, + "dependencies": { + "@babel/helper-create-regexp-features-plugin": "^7.22.15", + "@babel/helper-plugin-utils": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } + }, + "node_modules/@babel/preset-env": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.24.4.tgz", + "integrity": "sha512-7Kl6cSmYkak0FK/FXjSEnLJ1N9T/WA2RkMhu17gZ/dsxKJUuTYNIylahPTzqpLyJN4WhDif8X0XK1R8Wsguo/A==", + "peer": true, + "dependencies": { + "@babel/compat-data": "^7.24.4", + "@babel/helper-compilation-targets": "^7.23.6", + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-validator-option": "^7.23.5", + "@babel/plugin-bugfix-firefox-class-in-computed-class-key": "^7.24.4", + "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": "^7.24.1", + "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "^7.24.1", + "@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly": "^7.24.1", + "@babel/plugin-proposal-private-property-in-object": "7.21.0-placeholder-for-preset-env.2", + "@babel/plugin-syntax-async-generators": "^7.8.4", + "@babel/plugin-syntax-class-properties": "^7.12.13", + "@babel/plugin-syntax-class-static-block": "^7.14.5", + "@babel/plugin-syntax-dynamic-import": "^7.8.3", + "@babel/plugin-syntax-export-namespace-from": "^7.8.3", + "@babel/plugin-syntax-import-assertions": "^7.24.1", + "@babel/plugin-syntax-import-attributes": "^7.24.1", + "@babel/plugin-syntax-import-meta": "^7.10.4", + "@babel/plugin-syntax-json-strings": "^7.8.3", + "@babel/plugin-syntax-logical-assignment-operators": "^7.10.4", + "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3", + "@babel/plugin-syntax-numeric-separator": "^7.10.4", + "@babel/plugin-syntax-object-rest-spread": "^7.8.3", + "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", + "@babel/plugin-syntax-optional-chaining": "^7.8.3", + "@babel/plugin-syntax-private-property-in-object": "^7.14.5", + "@babel/plugin-syntax-top-level-await": "^7.14.5", + "@babel/plugin-syntax-unicode-sets-regex": "^7.18.6", + "@babel/plugin-transform-arrow-functions": "^7.24.1", + "@babel/plugin-transform-async-generator-functions": "^7.24.3", + "@babel/plugin-transform-async-to-generator": "^7.24.1", + "@babel/plugin-transform-block-scoped-functions": "^7.24.1", + "@babel/plugin-transform-block-scoping": "^7.24.4", + "@babel/plugin-transform-class-properties": "^7.24.1", + "@babel/plugin-transform-class-static-block": "^7.24.4", + "@babel/plugin-transform-classes": "^7.24.1", + "@babel/plugin-transform-computed-properties": "^7.24.1", + "@babel/plugin-transform-destructuring": "^7.24.1", + "@babel/plugin-transform-dotall-regex": "^7.24.1", + "@babel/plugin-transform-duplicate-keys": "^7.24.1", + "@babel/plugin-transform-dynamic-import": "^7.24.1", + "@babel/plugin-transform-exponentiation-operator": "^7.24.1", + "@babel/plugin-transform-export-namespace-from": "^7.24.1", + "@babel/plugin-transform-for-of": "^7.24.1", + "@babel/plugin-transform-function-name": "^7.24.1", + "@babel/plugin-transform-json-strings": "^7.24.1", + "@babel/plugin-transform-literals": "^7.24.1", + "@babel/plugin-transform-logical-assignment-operators": "^7.24.1", + "@babel/plugin-transform-member-expression-literals": "^7.24.1", + "@babel/plugin-transform-modules-amd": "^7.24.1", + "@babel/plugin-transform-modules-commonjs": "^7.24.1", + "@babel/plugin-transform-modules-systemjs": "^7.24.1", + "@babel/plugin-transform-modules-umd": "^7.24.1", + "@babel/plugin-transform-named-capturing-groups-regex": "^7.22.5", + "@babel/plugin-transform-new-target": "^7.24.1", + "@babel/plugin-transform-nullish-coalescing-operator": "^7.24.1", + "@babel/plugin-transform-numeric-separator": "^7.24.1", + "@babel/plugin-transform-object-rest-spread": "^7.24.1", + "@babel/plugin-transform-object-super": "^7.24.1", + "@babel/plugin-transform-optional-catch-binding": "^7.24.1", + "@babel/plugin-transform-optional-chaining": "^7.24.1", + "@babel/plugin-transform-parameters": "^7.24.1", + "@babel/plugin-transform-private-methods": "^7.24.1", + "@babel/plugin-transform-private-property-in-object": "^7.24.1", + "@babel/plugin-transform-property-literals": "^7.24.1", + "@babel/plugin-transform-regenerator": "^7.24.1", + "@babel/plugin-transform-reserved-words": "^7.24.1", + "@babel/plugin-transform-shorthand-properties": "^7.24.1", + "@babel/plugin-transform-spread": "^7.24.1", + "@babel/plugin-transform-sticky-regex": "^7.24.1", + "@babel/plugin-transform-template-literals": "^7.24.1", + "@babel/plugin-transform-typeof-symbol": "^7.24.1", + "@babel/plugin-transform-unicode-escapes": "^7.24.1", + "@babel/plugin-transform-unicode-property-regex": "^7.24.1", + "@babel/plugin-transform-unicode-regex": "^7.24.1", + "@babel/plugin-transform-unicode-sets-regex": "^7.24.1", + "@babel/preset-modules": "0.1.6-no-external-plugins", + "babel-plugin-polyfill-corejs2": "^0.4.10", + "babel-plugin-polyfill-corejs3": "^0.10.4", + "babel-plugin-polyfill-regenerator": "^0.6.1", + "core-js-compat": "^3.31.0", + "semver": "^6.3.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/preset-env/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "peer": true, + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/@babel/preset-flow": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/preset-flow/-/preset-flow-7.24.1.tgz", + "integrity": "sha512-sWCV2G9pcqZf+JHyv/RyqEIpFypxdCSxWIxQjpdaQxenNog7cN1pr76hg8u0Fz8Qgg0H4ETkGcJnXL8d4j0PPA==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-validator-option": "^7.23.5", + "@babel/plugin-transform-flow-strip-types": "^7.24.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/preset-modules": { + "version": "0.1.6-no-external-plugins", + "resolved": "https://registry.npmjs.org/@babel/preset-modules/-/preset-modules-0.1.6-no-external-plugins.tgz", + "integrity": "sha512-HrcgcIESLm9aIR842yhJ5RWan/gebQUJ6E/E5+rf0y9o6oj7w0Br+sWuL6kEQ/o/AdfvR1Je9jG18/gnpwjEyA==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.0.0", + "@babel/types": "^7.4.4", + "esutils": "^2.0.2" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0 || ^8.0.0-0 <8.0.0" + } + }, + "node_modules/@babel/preset-typescript": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.24.1.tgz", + "integrity": "sha512-1DBaMmRDpuYQBPWD8Pf/WEwCrtgRHxsZnP4mIy9G/X+hFfbI47Q2G4t1Paakld84+qsk2fSsUPMKg71jkoOOaQ==", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-validator-option": "^7.23.5", + "@babel/plugin-syntax-jsx": "^7.24.1", + "@babel/plugin-transform-modules-commonjs": "^7.24.1", + "@babel/plugin-transform-typescript": "^7.24.1" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/register": { + "version": "7.23.7", + "resolved": "https://registry.npmjs.org/@babel/register/-/register-7.23.7.tgz", + "integrity": "sha512-EjJeB6+kvpk+Y5DAkEAmbOBEFkh9OASx0huoEkqYTFxAZHzOAX2Oh5uwAUuL2rUddqfM0SA+KPXV2TbzoZ2kvQ==", + "peer": true, + "dependencies": { + "clone-deep": "^4.0.1", + "find-cache-dir": "^2.0.0", + "make-dir": "^2.1.0", + "pirates": "^4.0.6", + "source-map-support": "^0.5.16" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/regjsgen": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/@babel/regjsgen/-/regjsgen-0.8.0.tgz", + "integrity": "sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA==", + "peer": true + }, + "node_modules/@babel/runtime": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.4.tgz", + "integrity": "sha512-dkxf7+hn8mFBwKjs9bvBlArzLVxVbS8usaPUDd5p2a9JCL9tB8OaOVN1isD4+Xyk4ns89/xeOmbQvgdK7IIVdA==", + "peer": true, + "dependencies": { + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/runtime-corejs3": { + "version": "7.24.4", + "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.24.4.tgz", + "integrity": "sha512-VOQOexSilscN24VEY810G/PqtpFvx/z6UqDIjIWbDe2368HhDLkYN5TYwaEz/+eRCUkhJ2WaNLLmQAlxzfWj4w==", + "dev": true, + "peer": true, + "dependencies": { + "core-js-pure": "^3.30.2", + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/template": { + "version": "7.24.0", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.24.0.tgz", + "integrity": "sha512-Bkf2q8lMB0AFpX0NFEqSbx1OkTHf0f+0j82mkw+ZpzBnkk7e9Ql0891vlfgi+kHwOk8tQjiQHpqh4LaSa0fKEA==", + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.23.5", + "@babel/parser": "^7.24.0", + "@babel/types": "^7.24.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/traverse": { + "version": "7.24.1", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.1.tgz", + "integrity": "sha512-xuU6o9m68KeqZbQuDt2TcKSxUw/mrsvavlEqQ1leZ/B+C9tk6E4sRWy97WaXgvq5E+nU3cXMxv3WKOCanVMCmQ==", + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.24.1", + "@babel/generator": "^7.24.1", + "@babel/helper-environment-visitor": "^7.22.20", + "@babel/helper-function-name": "^7.23.0", + "@babel/helper-hoist-variables": "^7.22.5", + "@babel/helper-split-export-declaration": "^7.22.6", + "@babel/parser": "^7.24.1", + "@babel/types": "^7.24.0", + "debug": "^4.3.1", + "globals": "^11.1.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@babel/traverse/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "peer": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/@babel/types": { + "version": "7.24.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.0.tgz", + "integrity": "sha512-+j7a5c253RfKh8iABBhywc8NSfP5LURe7Uh4qpsh6jc+aLJguvmIUBdjSdEMQv2bENrCR5MfRdjGo7vzS/ob7w==", + "peer": true, + "dependencies": { + "@babel/helper-string-parser": "^7.23.4", + "@babel/helper-validator-identifier": "^7.22.20", + "to-fast-properties": "^2.0.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, + "node_modules/@colors/colors": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", + "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", + "dev": true, + "engines": { + "node": ">=0.1.90" + } + }, + "node_modules/@cspotcode/source-map-support": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", + "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", + "dev": true, + "dependencies": { + "@jridgewell/trace-mapping": "0.3.9" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { + "version": "0.3.9", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", + "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", + "dev": true, + "dependencies": { + "@jridgewell/resolve-uri": "^3.0.3", + "@jridgewell/sourcemap-codec": "^1.4.10" + } + }, + "node_modules/@cucumber/ci-environment": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/@cucumber/ci-environment/-/ci-environment-10.0.1.tgz", + "integrity": "sha512-/+ooDMPtKSmvcPMDYnMZt4LuoipfFfHaYspStI4shqw8FyKcfQAmekz6G+QKWjQQrvM+7Hkljwx58MEwPCwwzg==", + "dev": true + }, + "node_modules/@cucumber/cucumber": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/@cucumber/cucumber/-/cucumber-10.4.0.tgz", + "integrity": "sha512-pFPu4tCzHJUm1S4GfWUlhJYYqfbVPCmYCADehuhNU+MR29mvy49DQE6WS6aVdwABPawzpBs0H8EuQYA8Vh9Yqw==", + "dev": true, + "dependencies": { + "@cucumber/ci-environment": "10.0.1", + "@cucumber/cucumber-expressions": "17.1.0", + "@cucumber/gherkin": "28.0.0", + "@cucumber/gherkin-streams": "5.0.1", + "@cucumber/gherkin-utils": "9.0.0", + "@cucumber/html-formatter": "21.3.1", + "@cucumber/message-streams": "4.0.1", + "@cucumber/messages": "24.1.0", + "@cucumber/tag-expressions": "6.1.0", + "assertion-error-formatter": "^3.0.0", + "capital-case": "^1.0.4", + "chalk": "^4.1.2", + "cli-table3": "0.6.3", + "commander": "^10.0.0", + "debug": "^4.3.4", + "error-stack-parser": "^2.1.4", + "figures": "^3.2.0", + "glob": "^10.3.10", + "has-ansi": "^4.0.1", + "indent-string": "^4.0.0", + "is-installed-globally": "^0.4.0", + "is-stream": "^2.0.0", + "knuth-shuffle-seeded": "^1.0.6", + "lodash.merge": "^4.6.2", + "lodash.mergewith": "^4.6.2", + "luxon": "3.2.1", + "mkdirp": "^2.1.5", + "mz": "^2.7.0", + "progress": "^2.0.3", + "read-pkg-up": "^7.0.1", + "resolve-pkg": "^2.0.0", + "semver": "7.5.3", + "string-argv": "0.3.1", + "strip-ansi": "6.0.1", + "supports-color": "^8.1.1", + "tmp": "0.2.3", + "type-fest": "^4.8.3", + "util-arity": "^1.1.0", + "xmlbuilder": "^15.1.1", + "yaml": "^2.2.2", + "yup": "1.2.0" + }, + "bin": { + "cucumber-js": "bin/cucumber.js" + }, + "engines": { + "node": "18 || >=20" + }, + "funding": { + "url": "https://opencollective.com/cucumber" + } + }, + "node_modules/@cucumber/cucumber-expressions": { + "version": "17.1.0", + "resolved": "https://registry.npmjs.org/@cucumber/cucumber-expressions/-/cucumber-expressions-17.1.0.tgz", + "integrity": "sha512-PCv/ppsPynniKPWJr5v566daCVe+pbxQpHGrIu/Ev57cCH9Rv+X0F6lio4Id3Z64TaG7btCRLUGewIgLwmrwOA==", + "dev": true, + "dependencies": { + "regexp-match-indices": "1.0.2" + } + }, + "node_modules/@cucumber/gherkin": { + "version": "28.0.0", + "resolved": "https://registry.npmjs.org/@cucumber/gherkin/-/gherkin-28.0.0.tgz", + "integrity": "sha512-Ee6zJQq0OmIUPdW0mSnsCsrWA2PZAELNDPICD2pLfs0Oz7RAPgj80UsD2UCtqyAhw2qAR62aqlktKUlai5zl/A==", + "dev": true, + "dependencies": { + "@cucumber/messages": ">=19.1.4 <=24" + } + }, + "node_modules/@cucumber/gherkin-streams": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@cucumber/gherkin-streams/-/gherkin-streams-5.0.1.tgz", + "integrity": "sha512-/7VkIE/ASxIP/jd4Crlp4JHXqdNFxPGQokqWqsaCCiqBiu5qHoKMxcWNlp9njVL/n9yN4S08OmY3ZR8uC5x74Q==", + "dev": true, + "dependencies": { + "commander": "9.1.0", + "source-map-support": "0.5.21" + }, + "bin": { + "gherkin-javascript": "bin/gherkin" + }, + "peerDependencies": { + "@cucumber/gherkin": ">=22.0.0", + "@cucumber/message-streams": ">=4.0.0", + "@cucumber/messages": ">=17.1.1" + } + }, + "node_modules/@cucumber/gherkin-streams/node_modules/commander": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.1.0.tgz", + "integrity": "sha512-i0/MaqBtdbnJ4XQs4Pmyb+oFQl+q0lsAmokVUH92SlSw4fkeAcG3bVon+Qt7hmtF+u3Het6o4VgrcY3qAoEB6w==", + "dev": true, + "engines": { + "node": "^12.20.0 || >=14" + } + }, + "node_modules/@cucumber/gherkin-utils": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@cucumber/gherkin-utils/-/gherkin-utils-9.0.0.tgz", + "integrity": "sha512-clk4q39uj7pztZuZtyI54V8lRsCUz0Y/p8XRjIeHh7ExeEztpWkp4ca9q1FjUOPfQQ8E7OgqFbqoQQXZ1Bx7fw==", + "dev": true, + "dependencies": { + "@cucumber/gherkin": "^28.0.0", + "@cucumber/messages": "^24.0.0", + "@teppeis/multimaps": "3.0.0", + "commander": "12.0.0", + "source-map-support": "^0.5.21" + }, + "bin": { + "gherkin-utils": "bin/gherkin-utils" + } + }, + "node_modules/@cucumber/gherkin-utils/node_modules/commander": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.0.0.tgz", + "integrity": "sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==", + "dev": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/@cucumber/html-formatter": { + "version": "21.3.1", + "resolved": "https://registry.npmjs.org/@cucumber/html-formatter/-/html-formatter-21.3.1.tgz", + "integrity": "sha512-M1zbre7e8MsecXheqNv62BKY5J06YJSv1LmsD7sJ3mu5t1jirLjj2It1HqPsX5CQAfg9n69xFRugPgLMSte9TA==", + "dev": true, + "peerDependencies": { + "@cucumber/messages": ">=18" + } + }, + "node_modules/@cucumber/message-streams": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@cucumber/message-streams/-/message-streams-4.0.1.tgz", + "integrity": "sha512-Kxap9uP5jD8tHUZVjTWgzxemi/0uOsbGjd4LBOSxcJoOCRbESFwemUzilJuzNTB8pcTQUh8D5oudUyxfkJOKmA==", + "dev": true, + "peerDependencies": { + "@cucumber/messages": ">=17.1.1" + } + }, + "node_modules/@cucumber/messages": { + "version": "24.1.0", + "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-24.1.0.tgz", + "integrity": "sha512-hxVHiBurORcobhVk80I9+JkaKaNXkW6YwGOEFIh/2aO+apAN+5XJgUUWjng9NwqaQrW1sCFuawLB1AuzmBaNdQ==", + "dev": true, + "dependencies": { + "@types/uuid": "9.0.8", + "class-transformer": "0.5.1", + "reflect-metadata": "0.2.1", + "uuid": "9.0.1" + } + }, + "node_modules/@cucumber/pretty-formatter": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@cucumber/pretty-formatter/-/pretty-formatter-1.0.1.tgz", + "integrity": "sha512-A1lU4VVP0aUWdOTmpdzvXOyEYuPtBDI0xYwYJnmoMDplzxMdhcHk86lyyvYDoMoPzzq6OkOE3isuosvUU4X7IQ==", + "dev": true, + "dependencies": { + "ansi-styles": "^5.0.0", + "cli-table3": "^0.6.0", + "figures": "^3.2.0", + "ts-dedent": "^2.0.0" + }, + "peerDependencies": { + "@cucumber/cucumber": ">=7.0.0", + "@cucumber/messages": "*" + } + }, + "node_modules/@cucumber/tag-expressions": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@cucumber/tag-expressions/-/tag-expressions-6.1.0.tgz", + "integrity": "sha512-+3DwRumrCJG27AtzCIL37A/X+A/gSfxOPLg8pZaruh5SLumsTmpvilwroVWBT2fPzmno/tGXypeK5a7NHU4RzA==", + "dev": true + }, + "node_modules/@esbuild/aix-ppc64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.19.12.tgz", + "integrity": "sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "aix" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.12.tgz", + "integrity": "sha512-qg/Lj1mu3CdQlDEEiWrlC4eaPZ1KztwGJ9B6J+/6G+/4ewxJg7gqj8eVYWvao1bXrqGiW2rsBZFSX3q2lcW05w==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.12.tgz", + "integrity": "sha512-P0UVNGIienjZv3f5zq0DP3Nt2IE/3plFzuaS96vihvD0Hd6H/q4WXUGpCxD/E8YrSXfNyRPbpTq+T8ZQioSuPA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/android-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.12.tgz", + "integrity": "sha512-3k7ZoUW6Q6YqhdhIaq/WZ7HwBpnFBlW905Fa4s4qWJyiNOgT1dOqDiVAQFwBH7gBRZr17gLrlFCRzF6jFh7Kew==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.12.tgz", + "integrity": "sha512-B6IeSgZgtEzGC42jsI+YYu9Z3HKRxp8ZT3cqhvliEHovq8HSX2YX8lNocDn79gCKJXOSaEot9MVYky7AKjCs8g==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/darwin-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.12.tgz", + "integrity": "sha512-hKoVkKzFiToTgn+41qGhsUJXFlIjxI/jSYeZf3ugemDYZldIXIxhvwN6erJGlX4t5h417iFuheZ7l+YVn05N3A==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.12.tgz", + "integrity": "sha512-4aRvFIXmwAcDBw9AueDQ2YnGmz5L6obe5kmPT8Vd+/+x/JMVKCgdcRwH6APrbpNXsPz+K653Qg8HB/oXvXVukA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/freebsd-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.12.tgz", + "integrity": "sha512-EYoXZ4d8xtBoVN7CEwWY2IN4ho76xjYXqSXMNccFSx2lgqOG/1TBPW0yPx1bJZk94qu3tX0fycJeeQsKovA8gg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.12.tgz", + "integrity": "sha512-J5jPms//KhSNv+LO1S1TX1UWp1ucM6N6XuL6ITdKWElCu8wXP72l9MM0zDTzzeikVyqFE6U8YAV9/tFyj0ti+w==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.12.tgz", + "integrity": "sha512-EoTjyYyLuVPfdPLsGVVVC8a0p1BFFvtpQDB/YLEhaXyf/5bczaGeN15QkR+O4S5LeJ92Tqotve7i1jn35qwvdA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ia32": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.12.tgz", + "integrity": "sha512-Thsa42rrP1+UIGaWz47uydHSBOgTUnwBwNq59khgIwktK6x60Hivfbux9iNR0eHCHzOLjLMLfUMLCypBkZXMHA==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-loong64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.12.tgz", + "integrity": "sha512-LiXdXA0s3IqRRjm6rV6XaWATScKAXjI4R4LoDlvO7+yQqFdlr1Bax62sRwkVvRIrwXxvtYEHHI4dm50jAXkuAA==", + "cpu": [ + "loong64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-mips64el": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.12.tgz", + "integrity": "sha512-fEnAuj5VGTanfJ07ff0gOA6IPsvrVHLVb6Lyd1g2/ed67oU1eFzL0r9WL7ZzscD+/N6i3dWumGE1Un4f7Amf+w==", + "cpu": [ + "mips64el" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-ppc64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.12.tgz", + "integrity": "sha512-nYJA2/QPimDQOh1rKWedNOe3Gfc8PabU7HT3iXWtNUbRzXS9+vgB0Fjaqr//XNbd82mCxHzik2qotuI89cfixg==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-riscv64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.12.tgz", + "integrity": "sha512-2MueBrlPQCw5dVJJpQdUYgeqIzDQgw3QtiAHUC4RBz9FXPrskyyU3VI1hw7C0BSKB9OduwSJ79FTCqtGMWqJHg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-s390x": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.12.tgz", + "integrity": "sha512-+Pil1Nv3Umes4m3AZKqA2anfhJiVmNCYkPchwFJNEJN5QxmTs1uzyy4TvmDrCRNT2ApwSari7ZIgrPeUx4UZDg==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/linux-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.12.tgz", + "integrity": "sha512-B71g1QpxfwBvNrfyJdVDexenDIt1CiDN1TIXLbhOw0KhJzE78KIFGX6OJ9MrtC0oOqMWf+0xop4qEU8JrJTwCg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/netbsd-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.12.tgz", + "integrity": "sha512-3ltjQ7n1owJgFbuC61Oj++XhtzmymoCihNFgT84UAmJnxJfm4sYCiSLTXZtE00VWYpPMYc+ZQmB6xbSdVh0JWA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/openbsd-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.12.tgz", + "integrity": "sha512-RbrfTB9SWsr0kWmb9srfF+L933uMDdu9BIzdA7os2t0TXhCRjrQyCeOt6wVxr79CKD4c+p+YhCj31HBkYcXebw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/sunos-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.12.tgz", + "integrity": "sha512-HKjJwRrW8uWtCQnQOz9qcU3mUZhTUQvi56Q8DPTLLB+DawoiQdjsYq+j+D3s9I8VFtDr+F9CjgXKKC4ss89IeA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "sunos" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-arm64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.12.tgz", + "integrity": "sha512-URgtR1dJnmGvX864pn1B2YUYNzjmXkuJOIqG2HdU62MVS4EHpU2946OZoTMnRUHklGtJdJZ33QfzdjGACXhn1A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-ia32": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.12.tgz", + "integrity": "sha512-+ZOE6pUkMOJfmxmBZElNOx72NKpIa/HFOMGzu8fqzQJ5kgf6aTGrcJaFsNiVMH4JKpMipyK+7k0n2UXN7a8YKQ==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@esbuild/win32-x64": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.12.tgz", + "integrity": "sha512-T1QyPSDCyMXaO3pzBkF96E8xMkiRYbUEZADd29SyPGabqxMViNoii+NcK7eWJAEoU6RZyEm5lVSIjTmcdoB9HA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, + "node_modules/@eslint-community/eslint-utils": { + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", + "integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==", + "dev": true, + "dependencies": { + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "peerDependencies": { + "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" + } + }, + "node_modules/@eslint-community/regexpp": { + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.0.tgz", + "integrity": "sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==", + "dev": true, + "engines": { + "node": "^12.0.0 || ^14.0.0 || >=16.0.0" + } + }, + "node_modules/@eslint/eslintrc": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.4.tgz", + "integrity": "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==", + "dev": true, + "dependencies": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^9.6.0", + "globals": "^13.19.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@eslint/eslintrc/node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "node_modules/@eslint/eslintrc/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@eslint/eslintrc/node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/@eslint/eslintrc/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@eslint/js": { + "version": "8.57.0", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", + "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/@hapi/hoek": { + "version": "9.3.0", + "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", + "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==", + "peer": true + }, + "node_modules/@hapi/topo": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", + "integrity": "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==", + "peer": true, + "dependencies": { + "@hapi/hoek": "^9.0.0" + } + }, + "node_modules/@humanwhocodes/config-array": { + "version": "0.11.14", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", + "integrity": "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==", + "dev": true, + "dependencies": { + "@humanwhocodes/object-schema": "^2.0.2", + "debug": "^4.3.1", + "minimatch": "^3.0.5" + }, + "engines": { + "node": ">=10.10.0" + } + }, + "node_modules/@humanwhocodes/config-array/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@humanwhocodes/config-array/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@humanwhocodes/module-importer": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", + "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", + "dev": true, + "engines": { + "node": ">=12.22" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/nzakas" + } + }, + "node_modules/@humanwhocodes/object-schema": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", + "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", + "dev": true + }, + "node_modules/@isaacs/cliui": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", + "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", + "dev": true, + "dependencies": { + "string-width": "^5.1.2", + "string-width-cjs": "npm:string-width@^4.2.0", + "strip-ansi": "^7.0.1", + "strip-ansi-cjs": "npm:strip-ansi@^6.0.1", + "wrap-ansi": "^8.1.0", + "wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@isaacs/cliui/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/@isaacs/cliui/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true + }, + "node_modules/@isaacs/cliui/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@isaacs/cliui/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, + "node_modules/@isaacs/ttlcache": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/@isaacs/ttlcache/-/ttlcache-1.4.1.tgz", + "integrity": "sha512-RQgQ4uQ+pLbqXfOmieB91ejmLwvSgv9nLx6sT6sD83s7umBypgg+OIBOBbEUiJXrfpnp9j0mRhYYdzp9uqq3lA==", + "peer": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/@jest/create-cache-key-function": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/create-cache-key-function/-/create-cache-key-function-29.7.0.tgz", + "integrity": "sha512-4QqS3LY5PBmTRHj9sAg1HLoPzqAI0uOX6wI/TRqHIcOxlFidy6YEmCQJk6FSZjNLGCeubDMfmkWL+qaLKhSGQA==", + "peer": true, + "dependencies": { + "@jest/types": "^29.6.3" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/@jest/environment": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.7.0.tgz", + "integrity": "sha512-aQIfHDq33ExsN4jP1NWGXhxgQ/wixs60gDiKO+XVMd8Mn0NWPWgc34ZQDTb2jKaUWQ7MuwoitXAsN2XVXNMpAw==", + "peer": true, + "dependencies": { + "@jest/fake-timers": "^29.7.0", + "@jest/types": "^29.6.3", + "@types/node": "*", + "jest-mock": "^29.7.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/@jest/expect-utils": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.7.0.tgz", + "integrity": "sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==", + "dev": true, + "dependencies": { + "jest-get-type": "^29.6.3" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/@jest/fake-timers": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.7.0.tgz", + "integrity": "sha512-q4DH1Ha4TTFPdxLsqDXK1d3+ioSL7yL5oCMJZgDYm6i+6CygW5E5xVr/D1HdsGxjt1ZWSfUAs9OxSB/BNelWrQ==", + "peer": true, + "dependencies": { + "@jest/types": "^29.6.3", + "@sinonjs/fake-timers": "^10.0.2", + "@types/node": "*", + "jest-message-util": "^29.7.0", + "jest-mock": "^29.7.0", + "jest-util": "^29.7.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/@jest/schemas": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", + "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==", + "dependencies": { + "@sinclair/typebox": "^0.27.8" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/@jest/types": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", + "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", + "dependencies": { + "@jest/schemas": "^29.6.3", + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^3.0.0", + "@types/node": "*", + "@types/yargs": "^17.0.8", + "chalk": "^4.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", + "integrity": "sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==", + "dependencies": { + "@jridgewell/set-array": "^1.2.1", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.24" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/resolve-uri": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", + "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/set-array": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz", + "integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/source-map": { + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz", + "integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==", + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.5", + "@jridgewell/trace-mapping": "^0.3.25" + } + }, + "node_modules/@jridgewell/sourcemap-codec": { + "version": "1.4.15", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", + "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" + }, + "node_modules/@jridgewell/trace-mapping": { + "version": "0.3.25", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", + "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", + "dependencies": { + "@jridgewell/resolve-uri": "^3.1.0", + "@jridgewell/sourcemap-codec": "^1.4.14" + } + }, + "node_modules/@nodelib/fs.scandir": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", + "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", + "dev": true, + "dependencies": { + "@nodelib/fs.stat": "2.0.5", + "run-parallel": "^1.1.9" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.stat": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", + "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", + "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@nodelib/fs.walk": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", + "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", + "dev": true, + "dependencies": { + "@nodelib/fs.scandir": "2.1.5", + "fastq": "^1.6.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/@pkgjs/parseargs": { + "version": "0.11.0", + "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", + "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", + "dev": true, + "optional": true, + "engines": { + "node": ">=14" + } + }, + "node_modules/@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "dev": true, + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, + "node_modules/@react-native-community/cli": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-12.3.6.tgz", + "integrity": "sha512-647OSi6xBb8FbwFqX9zsJxOzu685AWtrOUWHfOkbKD+5LOpGORw+GQo0F9rWZnB68rLQyfKUZWJeaD00pGv5fw==", + "peer": true, + "dependencies": { + "@react-native-community/cli-clean": "12.3.6", + "@react-native-community/cli-config": "12.3.6", + "@react-native-community/cli-debugger-ui": "12.3.6", + "@react-native-community/cli-doctor": "12.3.6", + "@react-native-community/cli-hermes": "12.3.6", + "@react-native-community/cli-plugin-metro": "12.3.6", + "@react-native-community/cli-server-api": "12.3.6", + "@react-native-community/cli-tools": "12.3.6", + "@react-native-community/cli-types": "12.3.6", + "chalk": "^4.1.2", + "commander": "^9.4.1", + "deepmerge": "^4.3.0", + "execa": "^5.0.0", + "find-up": "^4.1.0", + "fs-extra": "^8.1.0", + "graceful-fs": "^4.1.3", + "prompts": "^2.4.2", + "semver": "^7.5.2" + }, + "bin": { + "react-native": "build/bin.js" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@react-native-community/cli-clean": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-clean/-/cli-clean-12.3.6.tgz", + "integrity": "sha512-gUU29ep8xM0BbnZjwz9MyID74KKwutq9x5iv4BCr2im6nly4UMf1B1D+V225wR7VcDGzbgWjaezsJShLLhC5ig==", + "peer": true, + "dependencies": { + "@react-native-community/cli-tools": "12.3.6", + "chalk": "^4.1.2", + "execa": "^5.0.0" + } + }, + "node_modules/@react-native-community/cli-config": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-config/-/cli-config-12.3.6.tgz", + "integrity": "sha512-JGWSYQ9EAK6m2v0abXwFLEfsqJ1zkhzZ4CV261QZF9MoUNB6h57a274h1MLQR9mG6Tsh38wBUuNfEPUvS1vYew==", + "peer": true, + "dependencies": { + "@react-native-community/cli-tools": "12.3.6", + "chalk": "^4.1.2", + "cosmiconfig": "^5.1.0", + "deepmerge": "^4.3.0", + "glob": "^7.1.3", + "joi": "^17.2.1" + } + }, + "node_modules/@react-native-community/cli-config/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "peer": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@react-native-community/cli-config/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "peer": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@react-native-community/cli-config/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "peer": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@react-native-community/cli-debugger-ui": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-debugger-ui/-/cli-debugger-ui-12.3.6.tgz", + "integrity": "sha512-SjUKKsx5FmcK9G6Pb6UBFT0s9JexVStK5WInmANw75Hm7YokVvHEgtprQDz2Uvy5znX5g2ujzrkIU//T15KQzA==", + "peer": true, + "dependencies": { + "serve-static": "^1.13.1" + } + }, + "node_modules/@react-native-community/cli-doctor": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-doctor/-/cli-doctor-12.3.6.tgz", + "integrity": "sha512-fvBDv2lTthfw4WOQKkdTop2PlE9GtfrlNnpjB818MhcdEnPjfQw5YaTUcnNEGsvGomdCs1MVRMgYXXwPSN6OvQ==", + "peer": true, + "dependencies": { + "@react-native-community/cli-config": "12.3.6", + "@react-native-community/cli-platform-android": "12.3.6", + "@react-native-community/cli-platform-ios": "12.3.6", + "@react-native-community/cli-tools": "12.3.6", + "chalk": "^4.1.2", + "command-exists": "^1.2.8", + "deepmerge": "^4.3.0", + "envinfo": "^7.10.0", + "execa": "^5.0.0", + "hermes-profile-transformer": "^0.0.6", + "node-stream-zip": "^1.9.1", + "ora": "^5.4.1", + "semver": "^7.5.2", + "strip-ansi": "^5.2.0", + "wcwidth": "^1.0.1", + "yaml": "^2.2.1" + } + }, + "node_modules/@react-native-community/cli-doctor/node_modules/strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "peer": true, + "dependencies": { + "ansi-regex": "^4.1.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/@react-native-community/cli-hermes": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-hermes/-/cli-hermes-12.3.6.tgz", + "integrity": "sha512-sNGwfOCl8OAIjWCkwuLpP8NZbuO0dhDI/2W7NeOGDzIBsf4/c4MptTrULWtGIH9okVPLSPX0NnRyGQ+mSwWyuQ==", + "peer": true, + "dependencies": { + "@react-native-community/cli-platform-android": "12.3.6", + "@react-native-community/cli-tools": "12.3.6", + "chalk": "^4.1.2", + "hermes-profile-transformer": "^0.0.6" + } + }, + "node_modules/@react-native-community/cli-platform-android": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-platform-android/-/cli-platform-android-12.3.6.tgz", + "integrity": "sha512-DeDDAB8lHpuGIAPXeeD9Qu2+/wDTFPo99c8uSW49L0hkmZJixzvvvffbGQAYk32H0TmaI7rzvzH+qzu7z3891g==", + "peer": true, + "dependencies": { + "@react-native-community/cli-tools": "12.3.6", + "chalk": "^4.1.2", + "execa": "^5.0.0", + "fast-xml-parser": "^4.2.4", + "glob": "^7.1.3", + "logkitty": "^0.7.1" + } + }, + "node_modules/@react-native-community/cli-platform-android/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "peer": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@react-native-community/cli-platform-android/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "peer": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@react-native-community/cli-platform-android/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "peer": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@react-native-community/cli-platform-ios": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-platform-ios/-/cli-platform-ios-12.3.6.tgz", + "integrity": "sha512-3eZ0jMCkKUO58wzPWlvAPRqezVKm9EPZyaPyHbRPWU8qw7JqkvnRlWIaYDGpjCJgVW4k2hKsEursLtYKb188tg==", + "peer": true, + "dependencies": { + "@react-native-community/cli-tools": "12.3.6", + "chalk": "^4.1.2", + "execa": "^5.0.0", + "fast-xml-parser": "^4.0.12", + "glob": "^7.1.3", + "ora": "^5.4.1" + } + }, + "node_modules/@react-native-community/cli-platform-ios/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "peer": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@react-native-community/cli-platform-ios/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "peer": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@react-native-community/cli-platform-ios/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "peer": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@react-native-community/cli-plugin-metro": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-plugin-metro/-/cli-plugin-metro-12.3.6.tgz", + "integrity": "sha512-3jxSBQt4fkS+KtHCPSyB5auIT+KKIrPCv9Dk14FbvOaEh9erUWEm/5PZWmtboW1z7CYeNbFMeXm9fM2xwtVOpg==", + "peer": true + }, + "node_modules/@react-native-community/cli-server-api": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-server-api/-/cli-server-api-12.3.6.tgz", + "integrity": "sha512-80NIMzo8b2W+PL0Jd7NjiJW9mgaT8Y8wsIT/lh6mAvYH7mK0ecDJUYUTAAv79Tbo1iCGPAr3T295DlVtS8s4yQ==", + "peer": true, + "dependencies": { + "@react-native-community/cli-debugger-ui": "12.3.6", + "@react-native-community/cli-tools": "12.3.6", + "compression": "^1.7.1", + "connect": "^3.6.5", + "errorhandler": "^1.5.1", + "nocache": "^3.0.1", + "pretty-format": "^26.6.2", + "serve-static": "^1.13.1", + "ws": "^7.5.1" + } + }, + "node_modules/@react-native-community/cli-server-api/node_modules/@jest/types": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", + "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", + "peer": true, + "dependencies": { + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^3.0.0", + "@types/node": "*", + "@types/yargs": "^15.0.0", + "chalk": "^4.0.0" + }, + "engines": { + "node": ">= 10.14.2" + } + }, + "node_modules/@react-native-community/cli-server-api/node_modules/@types/yargs": { + "version": "15.0.19", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.19.tgz", + "integrity": "sha512-2XUaGVmyQjgyAZldf0D0c14vvo/yv0MhQBSTJcejMMaitsn3nxCB6TmH4G0ZQf+uxROOa9mpanoSm8h6SG/1ZA==", + "peer": true, + "dependencies": { + "@types/yargs-parser": "*" + } + }, + "node_modules/@react-native-community/cli-server-api/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/@react-native-community/cli-server-api/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "peer": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/@react-native-community/cli-server-api/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "peer": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/@react-native-community/cli-server-api/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "peer": true + }, + "node_modules/@react-native-community/cli-server-api/node_modules/pretty-format": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", + "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", + "peer": true, + "dependencies": { + "@jest/types": "^26.6.2", + "ansi-regex": "^5.0.0", + "ansi-styles": "^4.0.0", + "react-is": "^17.0.1" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/@react-native-community/cli-server-api/node_modules/react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", + "peer": true + }, + "node_modules/@react-native-community/cli-server-api/node_modules/ws": { + "version": "7.5.9", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", + "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", + "peer": true, + "engines": { + "node": ">=8.3.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/@react-native-community/cli-tools": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-tools/-/cli-tools-12.3.6.tgz", + "integrity": "sha512-FPEvZn19UTMMXUp/piwKZSh8cMEfO8G3KDtOwo53O347GTcwNrKjgZGtLSPELBX2gr+YlzEft3CoRv2Qmo83fQ==", + "peer": true, + "dependencies": { + "appdirsjs": "^1.2.4", + "chalk": "^4.1.2", + "find-up": "^5.0.0", + "mime": "^2.4.1", + "node-fetch": "^2.6.0", + "open": "^6.2.0", + "ora": "^5.4.1", + "semver": "^7.5.2", + "shell-quote": "^1.7.3", + "sudo-prompt": "^9.0.0" + } + }, + "node_modules/@react-native-community/cli-types": { + "version": "12.3.6", + "resolved": "https://registry.npmjs.org/@react-native-community/cli-types/-/cli-types-12.3.6.tgz", + "integrity": "sha512-xPqTgcUtZowQ8WKOkI9TLGBwH2bGggOC4d2FFaIRST3gTcjrEeGRNeR5aXCzJFIgItIft8sd7p2oKEdy90+01Q==", + "peer": true, + "dependencies": { + "joi": "^17.2.1" + } + }, + "node_modules/@react-native-community/cli/node_modules/commander": { + "version": "9.5.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", + "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", + "peer": true, + "engines": { + "node": "^12.20.0 || >=14" + } + }, + "node_modules/@react-native-community/cli/node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "peer": true, + "dependencies": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@react-native-community/cli/node_modules/fs-extra": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "peer": true, + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + }, + "engines": { + "node": ">=6 <7 || >=8" + } + }, + "node_modules/@react-native-community/cli/node_modules/jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", + "peer": true, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/@react-native-community/cli/node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "peer": true, + "dependencies": { + "p-locate": "^4.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@react-native-community/cli/node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "peer": true, + "dependencies": { + "p-try": "^2.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@react-native-community/cli/node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "peer": true, + "dependencies": { + "p-limit": "^2.2.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@react-native-community/cli/node_modules/universalify": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "peer": true, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/@react-native/assets-registry": { + "version": "0.73.1", + "resolved": "https://registry.npmjs.org/@react-native/assets-registry/-/assets-registry-0.73.1.tgz", + "integrity": "sha512-2FgAbU7uKM5SbbW9QptPPZx8N9Ke2L7bsHb+EhAanZjFZunA9PaYtyjUQ1s7HD+zDVqOQIvjkpXSv7Kejd2tqg==", + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/@react-native/babel-plugin-codegen": { + "version": "0.73.4", + "resolved": "https://registry.npmjs.org/@react-native/babel-plugin-codegen/-/babel-plugin-codegen-0.73.4.tgz", + "integrity": "sha512-XzRd8MJGo4Zc5KsphDHBYJzS1ryOHg8I2gOZDAUCGcwLFhdyGu1zBNDJYH2GFyDrInn9TzAbRIf3d4O+eltXQQ==", + "peer": true, + "dependencies": { + "@react-native/codegen": "0.73.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@react-native/babel-preset": { + "version": "0.73.21", + "resolved": "https://registry.npmjs.org/@react-native/babel-preset/-/babel-preset-0.73.21.tgz", + "integrity": "sha512-WlFttNnySKQMeujN09fRmrdWqh46QyJluM5jdtDNrkl/2Hx6N4XeDUGhABvConeK95OidVO7sFFf7sNebVXogA==", + "peer": true, + "dependencies": { + "@babel/core": "^7.20.0", + "@babel/plugin-proposal-async-generator-functions": "^7.0.0", + "@babel/plugin-proposal-class-properties": "^7.18.0", + "@babel/plugin-proposal-export-default-from": "^7.0.0", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.0", + "@babel/plugin-proposal-numeric-separator": "^7.0.0", + "@babel/plugin-proposal-object-rest-spread": "^7.20.0", + "@babel/plugin-proposal-optional-catch-binding": "^7.0.0", + "@babel/plugin-proposal-optional-chaining": "^7.20.0", + "@babel/plugin-syntax-dynamic-import": "^7.8.0", + "@babel/plugin-syntax-export-default-from": "^7.0.0", + "@babel/plugin-syntax-flow": "^7.18.0", + "@babel/plugin-syntax-nullish-coalescing-operator": "^7.0.0", + "@babel/plugin-syntax-optional-chaining": "^7.0.0", + "@babel/plugin-transform-arrow-functions": "^7.0.0", + "@babel/plugin-transform-async-to-generator": "^7.20.0", + "@babel/plugin-transform-block-scoping": "^7.0.0", + "@babel/plugin-transform-classes": "^7.0.0", + "@babel/plugin-transform-computed-properties": "^7.0.0", + "@babel/plugin-transform-destructuring": "^7.20.0", + "@babel/plugin-transform-flow-strip-types": "^7.20.0", + "@babel/plugin-transform-function-name": "^7.0.0", + "@babel/plugin-transform-literals": "^7.0.0", + "@babel/plugin-transform-modules-commonjs": "^7.0.0", + "@babel/plugin-transform-named-capturing-groups-regex": "^7.0.0", + "@babel/plugin-transform-parameters": "^7.0.0", + "@babel/plugin-transform-private-methods": "^7.22.5", + "@babel/plugin-transform-private-property-in-object": "^7.22.11", + "@babel/plugin-transform-react-display-name": "^7.0.0", + "@babel/plugin-transform-react-jsx": "^7.0.0", + "@babel/plugin-transform-react-jsx-self": "^7.0.0", + "@babel/plugin-transform-react-jsx-source": "^7.0.0", + "@babel/plugin-transform-runtime": "^7.0.0", + "@babel/plugin-transform-shorthand-properties": "^7.0.0", + "@babel/plugin-transform-spread": "^7.0.0", + "@babel/plugin-transform-sticky-regex": "^7.0.0", + "@babel/plugin-transform-typescript": "^7.5.0", + "@babel/plugin-transform-unicode-regex": "^7.0.0", + "@babel/template": "^7.0.0", + "@react-native/babel-plugin-codegen": "0.73.4", + "babel-plugin-transform-flow-enums": "^0.0.2", + "react-refresh": "^0.14.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@babel/core": "*" + } + }, + "node_modules/@react-native/codegen": { + "version": "0.73.3", + "resolved": "https://registry.npmjs.org/@react-native/codegen/-/codegen-0.73.3.tgz", + "integrity": "sha512-sxslCAAb8kM06vGy9Jyh4TtvjhcP36k/rvj2QE2Jdhdm61KvfafCATSIsOfc0QvnduWFcpXUPvAVyYwuv7PYDg==", + "peer": true, + "dependencies": { + "@babel/parser": "^7.20.0", + "flow-parser": "^0.206.0", + "glob": "^7.1.1", + "invariant": "^2.2.4", + "jscodeshift": "^0.14.0", + "mkdirp": "^0.5.1", + "nullthrows": "^1.1.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@babel/preset-env": "^7.1.6" + } + }, + "node_modules/@react-native/codegen/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "peer": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/@react-native/codegen/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "peer": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@react-native/codegen/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "peer": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/@react-native/codegen/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "peer": true, + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/@react-native/community-cli-plugin": { + "version": "0.73.17", + "resolved": "https://registry.npmjs.org/@react-native/community-cli-plugin/-/community-cli-plugin-0.73.17.tgz", + "integrity": "sha512-F3PXZkcHg+1ARIr6FRQCQiB7ZAA+MQXGmq051metRscoLvgYJwj7dgC8pvgy0kexzUkHu5BNKrZeySzUft3xuQ==", + "peer": true, + "dependencies": { + "@react-native-community/cli-server-api": "12.3.6", + "@react-native-community/cli-tools": "12.3.6", + "@react-native/dev-middleware": "0.73.8", + "@react-native/metro-babel-transformer": "0.73.15", + "chalk": "^4.0.0", + "execa": "^5.1.1", + "metro": "^0.80.3", + "metro-config": "^0.80.3", + "metro-core": "^0.80.3", + "node-fetch": "^2.2.0", + "readline": "^1.3.0" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@react-native/debugger-frontend": { + "version": "0.73.3", + "resolved": "https://registry.npmjs.org/@react-native/debugger-frontend/-/debugger-frontend-0.73.3.tgz", + "integrity": "sha512-RgEKnWuoo54dh7gQhV7kvzKhXZEhpF9LlMdZolyhGxHsBqZ2gXdibfDlfcARFFifPIiaZ3lXuOVVa4ei+uPgTw==", + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/@react-native/dev-middleware": { + "version": "0.73.8", + "resolved": "https://registry.npmjs.org/@react-native/dev-middleware/-/dev-middleware-0.73.8.tgz", + "integrity": "sha512-oph4NamCIxkMfUL/fYtSsE+JbGOnrlawfQ0kKtDQ5xbOjPKotKoXqrs1eGwozNKv7FfQ393stk1by9a6DyASSg==", + "peer": true, + "dependencies": { + "@isaacs/ttlcache": "^1.4.1", + "@react-native/debugger-frontend": "0.73.3", + "chrome-launcher": "^0.15.2", + "chromium-edge-launcher": "^1.0.0", + "connect": "^3.6.5", + "debug": "^2.2.0", + "node-fetch": "^2.2.0", + "open": "^7.0.3", + "serve-static": "^1.13.1", + "temp-dir": "^2.0.0", + "ws": "^6.2.2" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/@react-native/dev-middleware/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "peer": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/@react-native/dev-middleware/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "peer": true + }, + "node_modules/@react-native/dev-middleware/node_modules/open": { + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz", + "integrity": "sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==", + "peer": true, + "dependencies": { + "is-docker": "^2.0.0", + "is-wsl": "^2.1.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@react-native/dev-middleware/node_modules/ws": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", + "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", + "peer": true, + "dependencies": { + "async-limiter": "~1.0.0" + } + }, + "node_modules/@react-native/gradle-plugin": { + "version": "0.73.4", + "resolved": "https://registry.npmjs.org/@react-native/gradle-plugin/-/gradle-plugin-0.73.4.tgz", + "integrity": "sha512-PMDnbsZa+tD55Ug+W8CfqXiGoGneSSyrBZCMb5JfiB3AFST3Uj5e6lw8SgI/B6SKZF7lG0BhZ6YHZsRZ5MlXmg==", + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/@react-native/js-polyfills": { + "version": "0.73.1", + "resolved": "https://registry.npmjs.org/@react-native/js-polyfills/-/js-polyfills-0.73.1.tgz", + "integrity": "sha512-ewMwGcumrilnF87H4jjrnvGZEaPFCAC4ebraEK+CurDDmwST/bIicI4hrOAv+0Z0F7DEK4O4H7r8q9vH7IbN4g==", + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/@react-native/metro-babel-transformer": { + "version": "0.73.15", + "resolved": "https://registry.npmjs.org/@react-native/metro-babel-transformer/-/metro-babel-transformer-0.73.15.tgz", + "integrity": "sha512-LlkSGaXCz+xdxc9819plmpsl4P4gZndoFtpjN3GMBIu6f7TBV0GVbyJAU4GE8fuAWPVSVL5ArOcdkWKSbI1klw==", + "peer": true, + "dependencies": { + "@babel/core": "^7.20.0", + "@react-native/babel-preset": "0.73.21", + "hermes-parser": "0.15.0", + "nullthrows": "^1.1.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@babel/core": "*" + } + }, + "node_modules/@react-native/normalize-colors": { + "version": "0.73.2", + "resolved": "https://registry.npmjs.org/@react-native/normalize-colors/-/normalize-colors-0.73.2.tgz", + "integrity": "sha512-bRBcb2T+I88aG74LMVHaKms2p/T8aQd8+BZ7LuuzXlRfog1bMWWn/C5i0HVuvW4RPtXQYgIlGiXVDy9Ir1So/w==", + "peer": true + }, + "node_modules/@react-native/virtualized-lists": { + "version": "0.73.4", + "resolved": "https://registry.npmjs.org/@react-native/virtualized-lists/-/virtualized-lists-0.73.4.tgz", + "integrity": "sha512-HpmLg1FrEiDtrtAbXiwCgXFYyloK/dOIPIuWW3fsqukwJEWAiTzm1nXGJ7xPU5XTHiWZ4sKup5Ebaj8z7iyWog==", + "peer": true, + "dependencies": { + "invariant": "^2.2.4", + "nullthrows": "^1.1.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "react-native": "*" + } + }, + "node_modules/@rollup/plugin-commonjs": { + "version": "25.0.7", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.7.tgz", + "integrity": "sha512-nEvcR+LRjEjsaSsc4x3XZfCCvZIaSMenZu/OiwOKGN2UhQpAYI7ru7czFvyWbErlpoGjnSX3D5Ch5FcMA3kRWQ==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "commondir": "^1.0.1", + "estree-walker": "^2.0.2", + "glob": "^8.0.3", + "is-reference": "1.2.1", + "magic-string": "^0.30.3" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.68.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-commonjs/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "dev": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@rollup/plugin-commonjs/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@rollup/plugin-json": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.1.0.tgz", + "integrity": "sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.1.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-node-resolve": { + "version": "15.2.3", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.3.tgz", + "integrity": "sha512-j/lym8nf5E21LwBT4Df1VD6hRO2L2iwUeUmP7litikRsVp1H6NWx20NEp0Y7su+7XGc476GnXXc4kFeZNGmaSQ==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "@types/resolve": "1.20.2", + "deepmerge": "^4.2.2", + "is-builtin-module": "^3.2.1", + "is-module": "^1.0.0", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.78.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-replace": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.5.tgz", + "integrity": "sha512-rYO4fOi8lMaTg/z5Jb+hKnrHHVn8j2lwkqwyS4kTRhKyWOLf2wST2sWXr4WzWiTcoHTp2sTjqUbqIj2E39slKQ==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "magic-string": "^0.30.3" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-terser": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/@rollup/plugin-terser/-/plugin-terser-0.4.4.tgz", + "integrity": "sha512-XHeJC5Bgvs8LfukDwWZp7yeqin6ns8RTl2B9avbejt6tZqsqvVoWI7ZTQrcNsfKEDWBTnTxM8nMDkO2IFFbd0A==", + "dev": true, + "dependencies": { + "serialize-javascript": "^6.0.1", + "smob": "^1.0.0", + "terser": "^5.17.4" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/plugin-typescript": { + "version": "11.1.6", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz", + "integrity": "sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.1.0", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.14.0||^3.0.0||^4.0.0", + "tslib": "*", + "typescript": ">=3.7.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + }, + "tslib": { + "optional": true + } + } + }, + "node_modules/@rollup/pluginutils": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", + "integrity": "sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==", + "dev": true, + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.14.3.tgz", + "integrity": "sha512-X9alQ3XM6I9IlSlmC8ddAvMSyG1WuHk5oUnXGw+yUBs3BFoTizmG1La/Gr8fVJvDWAq+zlYTZ9DBgrlKRVY06g==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.14.3.tgz", + "integrity": "sha512-eQK5JIi+POhFpzk+LnjKIy4Ks+pwJ+NXmPxOCSvOKSNRPONzKuUvWE+P9JxGZVxrtzm6BAYMaL50FFuPe0oWMQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.14.3.tgz", + "integrity": "sha512-Od4vE6f6CTT53yM1jgcLqNfItTsLt5zE46fdPaEmeFHvPs5SjZYlLpHrSiHEKR1+HdRfxuzXHjDOIxQyC3ptBA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.14.3.tgz", + "integrity": "sha512-0IMAO21axJeNIrvS9lSe/PGthc8ZUS+zC53O0VhF5gMxfmcKAP4ESkKOCwEi6u2asUrt4mQv2rjY8QseIEb1aw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.14.3.tgz", + "integrity": "sha512-ge2DC7tHRHa3caVEoSbPRJpq7azhG+xYsd6u2MEnJ6XzPSzQsTKyXvh6iWjXRf7Rt9ykIUWHtl0Uz3T6yXPpKw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.14.3.tgz", + "integrity": "sha512-ljcuiDI4V3ySuc7eSk4lQ9wU8J8r8KrOUvB2U+TtK0TiW6OFDmJ+DdIjjwZHIw9CNxzbmXY39wwpzYuFDwNXuw==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.14.3.tgz", + "integrity": "sha512-Eci2us9VTHm1eSyn5/eEpaC7eP/mp5n46gTRB3Aar3BgSvDQGJZuicyq6TsH4HngNBgVqC5sDYxOzTExSU+NjA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.14.3.tgz", + "integrity": "sha512-UrBoMLCq4E92/LCqlh+blpqMz5h1tJttPIniwUgOFJyjWI1qrtrDhhpHPuFxULlUmjFHfloWdixtDhSxJt5iKw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.14.3.tgz", + "integrity": "sha512-5aRjvsS8q1nWN8AoRfrq5+9IflC3P1leMoy4r2WjXyFqf3qcqsxRCfxtZIV58tCxd+Yv7WELPcO9mY9aeQyAmw==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.14.3.tgz", + "integrity": "sha512-sk/Qh1j2/RJSX7FhEpJn8n0ndxy/uf0kI/9Zc4b1ELhqULVdTfN6HL31CDaTChiBAOgLcsJ1sgVZjWv8XNEsAQ==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.14.3.tgz", + "integrity": "sha512-jOO/PEaDitOmY9TgkxF/TQIjXySQe5KVYB57H/8LRP/ux0ZoO8cSHCX17asMSv3ruwslXW/TLBcxyaUzGRHcqg==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.14.3.tgz", + "integrity": "sha512-8ybV4Xjy59xLMyWo3GCfEGqtKV5M5gCSrZlxkPGvEPCGDLNla7v48S662HSGwRd6/2cSneMQWiv+QzcttLrrOA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.14.3.tgz", + "integrity": "sha512-s+xf1I46trOY10OqAtZ5Rm6lzHre/UiLA1J2uOhCFXWkbZrJRkYBPO6FhvGfHmdtQ3Bx793MNa7LvoWFAm93bg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.14.3.tgz", + "integrity": "sha512-+4h2WrGOYsOumDQ5S2sYNyhVfrue+9tc9XcLWLh+Kw3UOxAvrfOrSMFon60KspcDdytkNDh7K2Vs6eMaYImAZg==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.14.3.tgz", + "integrity": "sha512-T1l7y/bCeL/kUwh9OD4PQT4aM7Bq43vX05htPJJ46RTI4r5KNt6qJRzAfNfM+OYMNEVBWQzR2Gyk+FXLZfogGw==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-x64-msvc": { + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.14.3.tgz", + "integrity": "sha512-/BypzV0H1y1HzgYpxqRaXGBRqfodgoBBCcsrujT6QRcakDQdfU+Lq9PENPh5jB4I44YWq+0C2eHsHya+nZY1sA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@sideway/address": { + "version": "4.1.5", + "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.5.tgz", + "integrity": "sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==", + "peer": true, + "dependencies": { + "@hapi/hoek": "^9.0.0" + } + }, + "node_modules/@sideway/formula": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.1.tgz", + "integrity": "sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg==", + "peer": true + }, + "node_modules/@sideway/pinpoint": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz", + "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==", + "peer": true + }, + "node_modules/@sinclair/typebox": { + "version": "0.27.8", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", + "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==" + }, + "node_modules/@sinonjs/commons": { + "version": "1.8.6", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", + "integrity": "sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==", + "dev": true, + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/fake-timers": { + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", + "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", + "peer": true, + "dependencies": { + "@sinonjs/commons": "^3.0.0" + } + }, + "node_modules/@sinonjs/fake-timers/node_modules/@sinonjs/commons": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", + "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==", + "peer": true, + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/formatio": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.2.2.tgz", + "integrity": "sha512-B8SEsgd8gArBLMD6zpRw3juQ2FVSsmdd7qlevyDqzS9WTCtvF55/gAL+h6gue8ZvPYcdiPdvueM/qm//9XzyTQ==", + "dev": true, + "dependencies": { + "@sinonjs/commons": "^1", + "@sinonjs/samsam": "^3.1.0" + } + }, + "node_modules/@sinonjs/samsam": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.3.3.tgz", + "integrity": "sha512-bKCMKZvWIjYD0BLGnNrxVuw4dkWCYsLqFOUWw8VgKF/+5Y+mE7LfHWPIYoDXowH+3a9LsWDMo0uAP8YDosPvHQ==", + "dev": true, + "dependencies": { + "@sinonjs/commons": "^1.3.0", + "array-from": "^2.1.1", + "lodash": "^4.17.15" + } + }, + "node_modules/@sinonjs/text-encoding": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", + "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", + "dev": true + }, + "node_modules/@socket.io/component-emitter": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.1.tgz", + "integrity": "sha512-dzJtaDAAoXx4GCOJpbB2eG/Qj8VDpdwkLsWGzGm+0L7E8/434RyMbAHmk9ubXWVAb9nXmc44jUf8GKqVDiKezg==", + "dev": true + }, + "node_modules/@teppeis/multimaps": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/@teppeis/multimaps/-/multimaps-3.0.0.tgz", + "integrity": "sha512-ID7fosbc50TbT0MK0EG12O+gAP3W3Aa/Pz4DaTtQtEvlc9Odaqi0de+xuZ7Li2GtK4HzEX7IuRWS/JmZLksR3Q==", + "dev": true, + "engines": { + "node": ">=14" + } + }, + "node_modules/@tootallnate/quickjs-emscripten": { + "version": "0.23.0", + "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz", + "integrity": "sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==" + }, + "node_modules/@tsconfig/node10": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", + "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", + "dev": true + }, + "node_modules/@tsconfig/node12": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", + "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", + "dev": true + }, + "node_modules/@tsconfig/node14": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", + "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", + "dev": true + }, + "node_modules/@tsconfig/node16": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", + "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", + "dev": true + }, + "node_modules/@types/cbor-js": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@types/cbor-js/-/cbor-js-0.1.1.tgz", + "integrity": "sha512-pfCx/EZC7VNBThwAQ0XvGPOXYm8BUk+gSVonaIGcEKBuqGJHTdcwAGW8WZkdRs/u9n9yOt1pBoPTCS1s8ZYpEQ==", + "dev": true + }, + "node_modules/@types/chai": { + "version": "4.3.14", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.14.tgz", + "integrity": "sha512-Wj71sXE4Q4AkGdG9Tvq1u/fquNz9EdG4LIJMwVVII7ashjD/8cf8fyIfJAjRr6YcsXnSE8cOGQPq1gqeR8z+3w==", + "dev": true + }, + "node_modules/@types/chai-as-promised": { + "version": "7.1.8", + "resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.8.tgz", + "integrity": "sha512-ThlRVIJhr69FLlh6IctTXFkmhtP3NpMZ2QGq69StYLyKZFp/HOp1VdKZj7RvfNWYYcJ1xlbLGLLWj1UvP5u/Gw==", + "dev": true, + "dependencies": { + "@types/chai": "*" + } + }, + "node_modules/@types/cookie": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz", + "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==", + "dev": true + }, + "node_modules/@types/cors": { + "version": "2.8.17", + "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", + "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/cucumber": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/@types/cucumber/-/cucumber-7.0.0.tgz", + "integrity": "sha512-cr5NN8/jmbw3vDKTQfGW0cSzDtkvxixu9bUD6po9U6OEF04XLuukTDldFG34ccDscLkA8bYnZ7VjxP79cIC7tg==", + "deprecated": "This is a stub types definition. @cucumber/cucumber provides its own type definitions, so you do not need this installed.", + "dev": true, + "dependencies": { + "@cucumber/cucumber": "*" + } + }, + "node_modules/@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true + }, + "node_modules/@types/expect": { + "version": "24.3.0", + "resolved": "https://registry.npmjs.org/@types/expect/-/expect-24.3.0.tgz", + "integrity": "sha512-aq5Z+YFBz5o2b6Sp1jigx5nsmoZMK5Ceurjwy6PZmRv7dEi1jLtkARfvB1ME+OXJUG+7TZUDcv3WoCr/aor6dQ==", + "deprecated": "This is a stub types definition. expect provides its own type definitions, so you do not need this installed.", + "dev": true, + "dependencies": { + "expect": "*" + } + }, + "node_modules/@types/istanbul-lib-coverage": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", + "integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==" + }, + "node_modules/@types/istanbul-lib-report": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.3.tgz", + "integrity": "sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA==", + "dependencies": { + "@types/istanbul-lib-coverage": "*" + } + }, + "node_modules/@types/istanbul-reports": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.4.tgz", + "integrity": "sha512-pk2B1NWalF9toCRu6gjBzR69syFjP4Od8WRAX+0mmf9lAjCRicLOWc+ZrxZHx/0XRjotgkF9t6iaMJ+aXcOdZQ==", + "dependencies": { + "@types/istanbul-lib-report": "*" + } + }, + "node_modules/@types/json-schema": { + "version": "7.0.15", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", + "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", + "dev": true + }, + "node_modules/@types/json5": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", + "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", + "dev": true, + "optional": true + }, + "node_modules/@types/lil-uuid": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@types/lil-uuid/-/lil-uuid-0.1.3.tgz", + "integrity": "sha512-UozexIWHw7bnQtbfdMqv1u82JmMl63t7lrCXpX6kByNH1F77j+Cdeqx28djuveoFvan9YUYrvK+ys1/hKIOgeA==", + "dev": true + }, + "node_modules/@types/mocha": { + "version": "9.1.1", + "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.1.tgz", + "integrity": "sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==", + "dev": true + }, + "node_modules/@types/nock": { + "version": "9.3.1", + "resolved": "https://registry.npmjs.org/@types/nock/-/nock-9.3.1.tgz", + "integrity": "sha512-eOVHXS5RnWOjTVhu3deCM/ruy9E6JCgeix2g7wpFiekQh3AaEAK1cz43tZDukKmtSmQnwvSySq7ubijCA32I7Q==", + "dev": true, + "dependencies": { + "@types/node": "*" + } + }, + "node_modules/@types/node": { + "version": "20.12.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", + "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", + "dependencies": { + "undici-types": "~5.26.4" + } + }, + "node_modules/@types/node-fetch": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", + "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "dev": true, + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } + }, + "node_modules/@types/normalize-package-data": { + "version": "2.4.4", + "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz", + "integrity": "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==", + "dev": true + }, + "node_modules/@types/pubnub": { + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/@types/pubnub/-/pubnub-7.4.2.tgz", + "integrity": "sha512-Vjkol3ix8IMrFdwtrLP9XkWc93cWDYpfs4tK6pvOUi8/G5+og2NRJ0AcGhMAQ4wuciHxDzJNkpPIGpRAgYAa4A==", + "dev": true + }, + "node_modules/@types/resolve": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", + "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", + "dev": true + }, + "node_modules/@types/semver": { + "version": "7.5.8", + "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", + "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==", + "dev": true + }, + "node_modules/@types/sinon": { + "version": "17.0.3", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.3.tgz", + "integrity": "sha512-j3uovdn8ewky9kRBG19bOwaZbexJu/XjtkHyjvUgt4xfPFz18dcORIMqnYh66Fx3Powhcr85NT5+er3+oViapw==", + "dev": true, + "dependencies": { + "@types/sinonjs__fake-timers": "*" + } + }, + "node_modules/@types/sinonjs__fake-timers": { + "version": "8.1.5", + "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.5.tgz", + "integrity": "sha512-mQkU2jY8jJEF7YHjHvsQO8+3ughTL1mcnn96igfhONmR+fUPSKIkefQYpSe8bsly2Ep7oQbn/6VG5/9/0qcArQ==", + "dev": true + }, + "node_modules/@types/stack-utils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", + "integrity": "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==" + }, + "node_modules/@types/text-encoding": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/text-encoding/-/text-encoding-0.0.39.tgz", + "integrity": "sha512-gRPvgL1aMgP6Pv92Rs310cJvVQ86DSF62E7K30g1FoGmmYWXoNuXT8PV835iAVeiAZkRwr2IW37KuyDn9ljmeA==", + "dev": true + }, + "node_modules/@types/underscore": { + "version": "1.11.15", + "resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.11.15.tgz", + "integrity": "sha512-HP38xE+GuWGlbSRq9WrZkousaQ7dragtZCruBVMi0oX1migFZavZ3OROKHSkNp/9ouq82zrWtZpg18jFnVN96g==", + "dev": true + }, + "node_modules/@types/uuid": { + "version": "9.0.8", + "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz", + "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==", + "dev": true + }, + "node_modules/@types/yargs": { + "version": "17.0.32", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", + "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", + "dependencies": { + "@types/yargs-parser": "*" + } + }, + "node_modules/@types/yargs-parser": { + "version": "21.0.3", + "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz", + "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==" + }, + "node_modules/@typescript-eslint/eslint-plugin": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.7.0.tgz", + "integrity": "sha512-GJWR0YnfrKnsRoluVO3PRb9r5aMZriiMMM/RHj5nnTrBy1/wIgk76XCtCKcnXGjpZQJQRFtGV9/0JJ6n30uwpQ==", + "dev": true, + "dependencies": { + "@eslint-community/regexpp": "^4.10.0", + "@typescript-eslint/scope-manager": "7.7.0", + "@typescript-eslint/type-utils": "7.7.0", + "@typescript-eslint/utils": "7.7.0", + "@typescript-eslint/visitor-keys": "7.7.0", + "debug": "^4.3.4", + "graphemer": "^1.4.0", + "ignore": "^5.3.1", + "natural-compare": "^1.4.0", + "semver": "^7.6.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "@typescript-eslint/parser": "^7.0.0", + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/eslint-plugin/node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/parser": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.7.0.tgz", + "integrity": "sha512-fNcDm3wSwVM8QYL4HKVBggdIPAy9Q41vcvC/GtDobw3c4ndVT3K6cqudUmjHPw8EAp4ufax0o58/xvWaP2FmTg==", + "dev": true, + "dependencies": { + "@typescript-eslint/scope-manager": "7.7.0", + "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/typescript-estree": "7.7.0", + "@typescript-eslint/visitor-keys": "7.7.0", + "debug": "^4.3.4" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/scope-manager": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.0.tgz", + "integrity": "sha512-/8INDn0YLInbe9Wt7dK4cXLDYp0fNHP5xKLHvZl3mOT5X17rK/YShXaiNmorl+/U4VKCVIjJnx4Ri5b0y+HClw==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/visitor-keys": "7.7.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/type-utils": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.7.0.tgz", + "integrity": "sha512-bOp3ejoRYrhAlnT/bozNQi3nio9tIgv3U5C0mVDdZC7cpcQEDZXvq8inrHYghLVwuNABRqrMW5tzAv88Vy77Sg==", + "dev": true, + "dependencies": { + "@typescript-eslint/typescript-estree": "7.7.0", + "@typescript-eslint/utils": "7.7.0", + "debug": "^4.3.4", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/types": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.0.tgz", + "integrity": "sha512-G01YPZ1Bd2hn+KPpIbrAhEWOn5lQBrjxkzHkWvP6NucMXFtfXoevK82hzQdpfuQYuhkvFDeQYbzXCjR1z9Z03w==", + "dev": true, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@typescript-eslint/typescript-estree": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.0.tgz", + "integrity": "sha512-8p71HQPE6CbxIBy2kWHqM1KGrC07pk6RJn40n0DSc6bMOBBREZxSDJ+BmRzc8B5OdaMh1ty3mkuWRg4sCFiDQQ==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/visitor-keys": "7.7.0", + "debug": "^4.3.4", + "globby": "^11.1.0", + "is-glob": "^4.0.3", + "minimatch": "^9.0.4", + "semver": "^7.6.0", + "ts-api-utils": "^1.3.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/utils": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.7.0.tgz", + "integrity": "sha512-LKGAXMPQs8U/zMRFXDZOzmMKgFv3COlxUQ+2NMPhbqgVm6R1w+nU1i4836Pmxu9jZAuIeyySNrN/6Rc657ggig==", + "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.4.0", + "@types/json-schema": "^7.0.15", + "@types/semver": "^7.5.8", + "@typescript-eslint/scope-manager": "7.7.0", + "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/typescript-estree": "7.7.0", + "semver": "^7.6.0" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + }, + "peerDependencies": { + "eslint": "^8.56.0" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/utils/node_modules/semver": { + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", + "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@typescript-eslint/visitor-keys": { + "version": "7.7.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.0.tgz", + "integrity": "sha512-h0WHOj8MhdhY8YWkzIF30R379y0NqyOHExI9N9KCzvmu05EgG4FumeYa3ccfKUSphyWkWQE1ybVrgz/Pbam6YA==", + "dev": true, + "dependencies": { + "@typescript-eslint/types": "7.7.0", + "eslint-visitor-keys": "^3.4.3" + }, + "engines": { + "node": "^18.18.0 || >=20.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/typescript-eslint" + } + }, + "node_modules/@ungap/structured-clone": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", + "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", + "dev": true + }, + "node_modules/abort-controller": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", + "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "peer": true, + "dependencies": { + "event-target-shim": "^5.0.0" + }, + "engines": { + "node": ">=6.5" + } + }, + "node_modules/accepts": { + "version": "1.3.8", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", + "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "dependencies": { + "mime-types": "~2.1.34", + "negotiator": "0.6.3" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/acorn": { + "version": "8.11.3", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", + "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, + "node_modules/acorn-walk": { + "version": "8.3.2", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", + "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/agent-base": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", + "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "dependencies": { + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/agentkeepalive": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-3.5.2.tgz", + "integrity": "sha512-e0L/HNe6qkQ7H19kTlRRqUibEAwDK5AFk6y3PtMsuut2VAH6+Q4xZml1tNDJD7kSAyqmbG/K08K5WEJYtUrSlQ==", + "dependencies": { + "humanize-ms": "^1.2.1" + }, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/anser": { + "version": "1.4.10", + "resolved": "https://registry.npmjs.org/anser/-/anser-1.4.10.tgz", + "integrity": "sha512-hCv9AqTQ8ycjpSd3upOJd7vFwW1JaoYQ7tpham03GJ1ca8/65rqn0RpaWpItOAd6ylW9wAw6luXYPJIyPFVOww==", + "peer": true + }, + "node_modules/ansi-colors": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", + "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/ansi-fragments": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/ansi-fragments/-/ansi-fragments-0.2.1.tgz", + "integrity": "sha512-DykbNHxuXQwUDRv5ibc2b0x7uw7wmwOGLBUd5RmaQ5z8Lhx19vwvKV+FAsM5rEA6dEcHxX+/Ad5s9eF2k2bB+w==", + "peer": true, + "dependencies": { + "colorette": "^1.0.7", + "slice-ansi": "^2.0.0", + "strip-ansi": "^5.0.0" + } + }, + "node_modules/ansi-fragments/node_modules/strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "peer": true, + "dependencies": { + "ansi-regex": "^4.1.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/ansi-regex": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", + "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", + "engines": { + "node": ">=6" + } + }, + "node_modules/ansi-styles": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/any-promise": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", + "integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==", + "dev": true + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/appdirsjs": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/appdirsjs/-/appdirsjs-1.2.7.tgz", + "integrity": "sha512-Quji6+8kLBC3NnBeo14nPDq0+2jUs5s3/xEye+udFHumHhRk4M7aAMXp/PBJqkKYGuuyR9M/6Dq7d2AViiGmhw==", + "peer": true + }, + "node_modules/arg": { + "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", "dev": true }, - "node_modules/argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "node_modules/argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dependencies": { + "sprintf-js": "~1.0.2" + } + }, + "node_modules/array-from": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", + "integrity": "sha512-GQTc6Uupx1FCavi5mPzBvVT7nEOeWMmUA9P95wpfpW1XwMSKs+KaymD5C2Up7KAUKg/mYwbsUYzdZWcoajlNZg==", + "dev": true + }, + "node_modules/array-union": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", + "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/arrify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", + "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", + "peer": true + }, + "node_modules/asn1": { + "version": "0.2.6", + "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", + "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==", + "dev": true, + "dependencies": { + "safer-buffer": "~2.1.0" + } + }, + "node_modules/assert-plus": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", + "integrity": "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==", + "dev": true, + "engines": { + "node": ">=0.8" + } + }, + "node_modules/assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/assertion-error-formatter": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/assertion-error-formatter/-/assertion-error-formatter-3.0.0.tgz", + "integrity": "sha512-6YyAVLrEze0kQ7CmJfUgrLHb+Y7XghmL2Ie7ijVa2Y9ynP3LV+VDiwFk62Dn0qtqbmY0BT0ss6p1xxpiF2PYbQ==", + "dev": true, + "dependencies": { + "diff": "^4.0.1", + "pad-right": "^0.2.2", + "repeat-string": "^1.6.1" + } + }, + "node_modules/ast-types": { + "version": "0.13.4", + "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.13.4.tgz", + "integrity": "sha512-x1FCFnFifvYDDzTaLII71vG5uvDwgtmDTEVWAxrgeiR8VjMONcCXJx7E+USjDtHlwFmt9MysbqgF9b9Vjr6w+w==", + "dependencies": { + "tslib": "^2.0.1" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/astral-regex": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", + "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", + "peer": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/async-limiter": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", + "peer": true + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/aws-sign2": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", + "integrity": "sha512-08kcGqnYf/YmjoRhfxyu+CLxBjUtHLXLXX/vUfx9l2LYzG3c1m61nrpyFUZI6zeS+Li/wWMMidD9KgrqtGq3mA==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/aws4": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.12.0.tgz", + "integrity": "sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg==", + "dev": true + }, + "node_modules/babel-core": { + "version": "7.0.0-bridge.0", + "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz", + "integrity": "sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==", + "peer": true, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/babel-plugin-polyfill-corejs2": { + "version": "0.4.10", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.10.tgz", + "integrity": "sha512-rpIuu//y5OX6jVU+a5BCn1R5RSZYWAl2Nar76iwaOdycqb6JPxediskWFMMl7stfwNJR4b7eiQvh5fB5TEQJTQ==", + "peer": true, + "dependencies": { + "@babel/compat-data": "^7.22.6", + "@babel/helper-define-polyfill-provider": "^0.6.1", + "semver": "^6.3.1" + }, + "peerDependencies": { + "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" + } + }, + "node_modules/babel-plugin-polyfill-corejs2/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "peer": true, + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/babel-plugin-polyfill-corejs3": { + "version": "0.10.4", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs3/-/babel-plugin-polyfill-corejs3-0.10.4.tgz", + "integrity": "sha512-25J6I8NGfa5YkCDogHRID3fVCadIR8/pGl1/spvCkzb6lVn6SR3ojpx9nOn9iEBcUsjY24AmdKm5khcfKdylcg==", + "peer": true, + "dependencies": { + "@babel/helper-define-polyfill-provider": "^0.6.1", + "core-js-compat": "^3.36.1" + }, + "peerDependencies": { + "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" + } + }, + "node_modules/babel-plugin-polyfill-regenerator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.6.1.tgz", + "integrity": "sha512-JfTApdE++cgcTWjsiCQlLyFBMbTUft9ja17saCc93lgV33h4tuCVj7tlvu//qpLwaG+3yEz7/KhahGrUMkVq9g==", + "peer": true, + "dependencies": { + "@babel/helper-define-polyfill-provider": "^0.6.1" + }, + "peerDependencies": { + "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" + } + }, + "node_modules/babel-plugin-transform-flow-enums": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/babel-plugin-transform-flow-enums/-/babel-plugin-transform-flow-enums-0.0.2.tgz", + "integrity": "sha512-g4aaCrDDOsWjbm0PUUeVnkcVd6AKJsVc/MbnPhEotEpkeJQP6b8nzewohQi7+QS8UyPehOhGWn0nOwjvWpmMvQ==", + "peer": true, + "dependencies": { + "@babel/plugin-syntax-flow": "^7.12.1" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/base64-js": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", + "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/base64id": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", + "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==", + "dev": true, + "engines": { + "node": "^4.5.0 || >= 5.9" + } + }, + "node_modules/basic-ftp": { + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.0.5.tgz", + "integrity": "sha512-4Bcg1P8xhUuqcii/S0Z9wiHIrQVPMermM1any+MX5GeGD7faD3/msQUDGLol9wOcz4/jbg/WJnGqoJF6LiBdtg==", + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/bcrypt-pbkdf": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", + "integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==", + "dev": true, + "dependencies": { + "tweetnacl": "^0.14.3" + } + }, + "node_modules/becke-ch--regex--s0-0-v1--base--pl--lib": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/becke-ch--regex--s0-0-v1--base--pl--lib/-/becke-ch--regex--s0-0-v1--base--pl--lib-1.4.0.tgz", + "integrity": "sha512-FnWonOyaw7Vivg5nIkrUll9HSS5TjFbyuURAiDssuL6VxrBe3ERzudRxOcWRhZYlP89UArMDikz7SapRPQpmZQ==", + "dev": true, + "peer": true + }, + "node_modules/binary-extensions": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", + "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/bl": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", + "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", + "peer": true, + "dependencies": { + "buffer": "^5.5.0", + "inherits": "^2.0.4", + "readable-stream": "^3.4.0" + } + }, + "node_modules/bl/node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "peer": true, + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/bl/node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "peer": true, + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/bluebird": { + "version": "3.7.2", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", + "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", + "dev": true, + "peer": true + }, + "node_modules/body-parser": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", + "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", + "dev": true, + "dependencies": { + "bytes": "3.1.2", + "content-type": "~1.0.5", + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "on-finished": "2.4.1", + "qs": "6.11.0", + "raw-body": "2.5.2", + "type-is": "~1.6.18", + "unpipe": "1.0.0" + }, + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/body-parser/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/body-parser/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "dev": true + }, + "node_modules/brace-expansion": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", + "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", + "dev": true + }, + "node_modules/browserslist": { + "version": "4.23.0", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.0.tgz", + "integrity": "sha512-QW8HiM1shhT2GuzkvklfjcKDiWFXHOeFCIA/huJPwHsslwcydgk7X+z2zXpEijP98UCY7HbubZt5J2Zgvf0CaQ==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "peer": true, + "dependencies": { + "caniuse-lite": "^1.0.30001587", + "electron-to-chromium": "^1.4.668", + "node-releases": "^2.0.14", + "update-browserslist-db": "^1.0.13" + }, + "bin": { + "browserslist": "cli.js" + }, + "engines": { + "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" + } + }, + "node_modules/bser": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", + "integrity": "sha512-gQxTNE/GAfIIrmHLUE3oJyp5FO6HRBfhjnw4/wMmA63ZGDJnWBmgY/lyQBpnDUkGmAhbSe39tx2d/iTOAfglwQ==", + "peer": true, + "dependencies": { + "node-int64": "^0.4.0" + } + }, + "node_modules/buffer": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", + "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.2.1" + } + }, + "node_modules/buffer-crc32": { + "version": "0.2.13", + "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", + "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" + }, + "node_modules/builtin-modules": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", + "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", + "dev": true, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dev": true, + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/caller-callsite": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/caller-callsite/-/caller-callsite-2.0.0.tgz", + "integrity": "sha512-JuG3qI4QOftFsZyOn1qq87fq5grLIyk1JYd5lJmdA+fG7aQ9pA/i3JIJGcO3q0MrRcHlOt1U+ZeHW8Dq9axALQ==", + "peer": true, + "dependencies": { + "callsites": "^2.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/caller-callsite/node_modules/callsites": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz", + "integrity": "sha512-ksWePWBloaWPxJYQ8TL0JHvtci6G5QTKwQ95RcWAa/lzoAKuAOflGdAK92hpHXjkwb8zLxoLNUoNYZgVsaJzvQ==", + "peer": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/caller-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-2.0.0.tgz", + "integrity": "sha512-MCL3sf6nCSXOwCTzvPKhN18TU7AHTvdtam8DAogxcrJ8Rjfbbg7Lgng64H9Iy+vUV6VGFClN/TyxBkAebLRR4A==", + "peer": true, + "dependencies": { + "caller-callsite": "^2.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/caniuse-lite": { + "version": "1.0.30001611", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001611.tgz", + "integrity": "sha512-19NuN1/3PjA3QI8Eki55N8my4LzfkMCRLgCVfrl/slbSAchQfV0+GwjPrK3rq37As4UCLlM/DHajbKkAqbv92Q==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/caniuse-lite" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "peer": true + }, + "node_modules/capital-case": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/capital-case/-/capital-case-1.0.4.tgz", + "integrity": "sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A==", + "dev": true, + "dependencies": { + "no-case": "^3.0.4", + "tslib": "^2.0.3", + "upper-case-first": "^2.0.2" + } + }, + "node_modules/caseless": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", + "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==", + "dev": true + }, + "node_modules/cbor-js": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/cbor-js/-/cbor-js-0.1.0.tgz", + "integrity": "sha512-7sQ/TvDZPl7csT1Sif9G0+MA0I0JOVah8+wWlJVQdVEgIbCzlN/ab3x+uvMNsc34TUvO6osQTAmB2ls80JX6tw==" + }, + "node_modules/cbor-sync": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/cbor-sync/-/cbor-sync-1.0.4.tgz", + "integrity": "sha512-GWlXN4wiz0vdWWXBU71Dvc1q3aBo0HytqwAZnXF1wOwjqNnDWA1vZ1gDMFLlqohak31VQzmhiYfiCX5QSSfagA==" + }, + "node_modules/chai": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.4.1.tgz", + "integrity": "sha512-13sOfMv2+DWduEU+/xbun3LScLoqN17nBeTLUsmDfKdoiC1fr0n9PU4guu4AhRcOVFk/sW8LyZWHuhWtQZiF+g==", + "dev": true, + "dependencies": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.3", + "deep-eql": "^4.1.3", + "get-func-name": "^2.0.2", + "loupe": "^2.3.6", + "pathval": "^1.1.1", + "type-detect": "^4.0.8" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/chai-as-promised": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz", + "integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==", + "dev": true, + "dependencies": { + "check-error": "^1.0.2" + }, + "peerDependencies": { + "chai": ">= 2.1.2 < 5" + } + }, + "node_modules/chai-nock": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/chai-nock/-/chai-nock-1.3.0.tgz", + "integrity": "sha512-O3j1bW3ACoUu/sLGYSoX50c1p8dbTkCjw3/dereqzl9BL2XsQAUVC18sJpg3hVwpCk71rjWGumCmHy87t5W+Pg==", + "dev": true, + "dependencies": { + "chai": "^4.2.0", + "deep-equal": "^1.0.1" + } + }, + "node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/chalk/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/chalk/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/chalk/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" + }, + "node_modules/chalk/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/check-error": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", + "integrity": "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==", + "dev": true, + "dependencies": { + "get-func-name": "^2.0.2" + }, + "engines": { + "node": "*" + } + }, + "node_modules/chokidar": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", + "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", + "dev": true, + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/chokidar/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/chrome-launcher": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/chrome-launcher/-/chrome-launcher-0.15.2.tgz", + "integrity": "sha512-zdLEwNo3aUVzIhKhTtXfxhdvZhUghrnmkvcAq2NoDd+LeOHKf03H5jwZ8T/STsAlzyALkBVK552iaG1fGf1xVQ==", + "peer": true, + "dependencies": { + "@types/node": "*", + "escape-string-regexp": "^4.0.0", + "is-wsl": "^2.2.0", + "lighthouse-logger": "^1.0.0" + }, + "bin": { + "print-chrome-path": "bin/print-chrome-path.js" + }, + "engines": { + "node": ">=12.13.0" + } + }, + "node_modules/chrome-launcher/node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/chromium-edge-launcher": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/chromium-edge-launcher/-/chromium-edge-launcher-1.0.0.tgz", + "integrity": "sha512-pgtgjNKZ7i5U++1g1PWv75umkHvhVTDOQIZ+sjeUX9483S7Y6MUvO0lrd7ShGlQlFHMN4SwKTCq/X8hWrbv2KA==", + "peer": true, + "dependencies": { + "@types/node": "*", + "escape-string-regexp": "^4.0.0", + "is-wsl": "^2.2.0", + "lighthouse-logger": "^1.0.0", + "mkdirp": "^1.0.4", + "rimraf": "^3.0.2" + } + }, + "node_modules/chromium-edge-launcher/node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/chromium-edge-launcher/node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "peer": true, + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/ci-info": { + "version": "3.9.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-3.9.0.tgz", + "integrity": "sha512-NIxF55hv4nSqQswkAeiOi1r83xy8JldOFDTWiug55KBu9Jnblncd2U6ViHmYgHf01TPZS77NJBhBMKdWj9HQMQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/sibiraj-s" + } + ], + "engines": { + "node": ">=8" + } + }, + "node_modules/class-transformer": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", + "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", + "dev": true + }, + "node_modules/cli-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", + "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", + "peer": true, + "dependencies": { + "restore-cursor": "^3.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cli-spinners": { + "version": "2.9.2", + "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", + "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", + "peer": true, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/cli-table3": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.3.tgz", + "integrity": "sha512-w5Jac5SykAeZJKntOxJCrm63Eg5/4dhMWIcuTbo9rpE+brgaSZo0RuNJZeOyMgsUdhDeojvgyQLmjI+K50ZGyg==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0" + }, + "engines": { + "node": "10.* || >= 12.*" + }, + "optionalDependencies": { + "@colors/colors": "1.5.0" + } + }, + "node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dev": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" + } + }, + "node_modules/cliui/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/cliui/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/cliui/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/cliui/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/clone": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", + "integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==", + "peer": true, + "engines": { + "node": ">=0.8" + } + }, + "node_modules/clone-deep": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz", + "integrity": "sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==", + "peer": true, + "dependencies": { + "is-plain-object": "^2.0.4", + "kind-of": "^6.0.2", + "shallow-clone": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "dependencies": { + "color-name": "1.1.3" + } + }, + "node_modules/color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" + }, + "node_modules/colorette": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.4.0.tgz", + "integrity": "sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==", + "peer": true + }, + "node_modules/colors": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", + "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", + "dev": true, + "engines": { + "node": ">=0.1.90" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/command-exists": { + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", + "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==", + "peer": true + }, + "node_modules/commander": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", + "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", + "dev": true, + "engines": { + "node": ">=14" + } + }, + "node_modules/commondir": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==" + }, + "node_modules/compressible": { + "version": "2.0.18", + "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz", + "integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==", + "peer": true, + "dependencies": { + "mime-db": ">= 1.43.0 < 2" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/compression": { + "version": "1.7.4", + "resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz", + "integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==", + "peer": true, + "dependencies": { + "accepts": "~1.3.5", + "bytes": "3.0.0", + "compressible": "~2.0.16", + "debug": "2.6.9", + "on-headers": "~1.0.2", + "safe-buffer": "5.1.2", + "vary": "~1.1.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/compression/node_modules/bytes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", + "integrity": "sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==", + "peer": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/compression/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "peer": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/compression/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "peer": true + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "node_modules/concat-stream": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", + "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "dev": true, + "engines": [ + "node >= 0.8" + ], + "dependencies": { + "buffer-from": "^1.0.0", + "inherits": "^2.0.3", + "readable-stream": "^2.2.2", + "typedarray": "^0.0.6" + } + }, + "node_modules/connect": { + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/connect/-/connect-3.7.0.tgz", + "integrity": "sha512-ZqRXc+tZukToSNmh5C2iWMSoV3X1YUcPbqEM4DkEG5tNQXrQUZCNVGGv3IuicnkMtPfGf3Xtp8WCXs295iQ1pQ==", + "dependencies": { + "debug": "2.6.9", + "finalhandler": "1.1.2", + "parseurl": "~1.3.3", + "utils-merge": "1.0.1" + }, + "engines": { + "node": ">= 0.10.0" + } + }, + "node_modules/connect/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/connect/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/convert-source-map": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", + "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", + "peer": true + }, + "node_modules/cookie": { + "version": "0.4.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", + "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", + "dev": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/core-js-compat": { + "version": "3.37.0", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.37.0.tgz", + "integrity": "sha512-vYq4L+T8aS5UuFg4UwDhc7YNRWVeVZwltad9C/jV3R2LgVOpS9BDr7l/WL6BN0dbV3k1XejPTHqqEzJgsa0frA==", + "peer": true, + "dependencies": { + "browserslist": "^4.23.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, + "node_modules/core-js-pure": { + "version": "3.37.0", + "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.37.0.tgz", + "integrity": "sha512-d3BrpyFr5eD4KcbRvQ3FTUx/KWmaDesr7+a3+1+P46IUnNoEt+oiLijPINZMEon7w9oGkIINWxrBAU9DEciwFQ==", + "dev": true, + "hasInstallScript": true, + "peer": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, + "node_modules/core-util-is": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" + }, + "node_modules/cors": { + "version": "2.8.5", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", + "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", + "dev": true, + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/cosmiconfig": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.2.1.tgz", + "integrity": "sha512-H65gsXo1SKjf8zmrJ67eJk8aIRKV5ff2D4uKZIBZShbhGSpEmsQOPW/SKMKYhSTrqR7ufy6RP69rPogdaPh/kA==", + "peer": true, + "dependencies": { + "import-fresh": "^2.0.0", + "is-directory": "^0.3.1", + "js-yaml": "^3.13.1", + "parse-json": "^4.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/cosmiconfig/node_modules/import-fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-2.0.0.tgz", + "integrity": "sha512-eZ5H8rcgYazHbKC3PG4ClHNykCSxtAhxSSEM+2mb+7evD2CKF5V7c0dNum7AdpDh0ZdICwZY9sRSn8f+KH96sg==", + "peer": true, + "dependencies": { + "caller-path": "^2.0.0", + "resolve-from": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/cosmiconfig/node_modules/parse-json": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", + "integrity": "sha512-aOIos8bujGN93/8Ox/jPLh7RwVnPEysynVFE+fQZyg6jKELEHwzgKdLRFHUgXJL6kylijVSBC4BvN9OmsB48Rw==", + "peer": true, + "dependencies": { + "error-ex": "^1.3.1", + "json-parse-better-errors": "^1.0.1" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/cosmiconfig/node_modules/resolve-from": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz", + "integrity": "sha512-GnlH6vxLymXJNMBo7XP1fJIzBFbdYt49CuTwmB/6N53t+kMPRMFKz783LlQ4tv28XoQfMWinAJX6WCGf2IlaIw==", + "peer": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "dev": true + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/cucumber": { + "version": "6.0.7", + "resolved": "https://registry.npmjs.org/cucumber/-/cucumber-6.0.7.tgz", + "integrity": "sha512-pN3AgWxHx8rOi+wOlqjASNETOjf3TgeyqhMNLQam7nSTXgQzju1oAmXkleRQRcXvpVvejcDHiZBLFSfBkqbYpA==", + "deprecated": "Cucumber is publishing new releases under @cucumber/cucumber", + "dev": true, + "peer": true, + "dependencies": { + "assertion-error-formatter": "^3.0.0", + "bluebird": "^3.4.1", + "cli-table3": "^0.5.1", + "colors": "^1.1.2", + "commander": "^3.0.1", + "cucumber-expressions": "^8.1.0", + "cucumber-tag-expressions": "^2.0.2", + "duration": "^0.2.1", + "escape-string-regexp": "^2.0.0", + "figures": "^3.0.0", + "gherkin": "5.0.0", + "glob": "^7.1.3", + "indent-string": "^4.0.0", + "is-generator": "^1.0.2", + "is-stream": "^2.0.0", + "knuth-shuffle-seeded": "^1.0.6", + "lodash": "^4.17.14", + "mz": "^2.4.0", + "progress": "^2.0.0", + "resolve": "^1.3.3", + "serialize-error": "^4.1.0", + "stack-chain": "^2.0.0", + "stacktrace-js": "^2.0.0", + "string-argv": "^0.3.0", + "title-case": "^2.1.1", + "util-arity": "^1.0.2", + "verror": "^1.9.0" + }, + "bin": { + "cucumber-js": "bin/cucumber-js" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/cucumber-expressions": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/cucumber-expressions/-/cucumber-expressions-8.3.0.tgz", + "integrity": "sha512-cP2ya0EiorwXBC7Ll7Cj7NELYbasNv9Ty42L4u7sso9KruWemWG1ZiTq4PMqir3SNDSrbykoqI5wZgMbLEDjLQ==", + "deprecated": "This package is now published under @cucumber/cucumber-expressions", + "dev": true, + "peer": true, + "dependencies": { + "becke-ch--regex--s0-0-v1--base--pl--lib": "^1.4.0", + "xregexp": "^4.2.4" + } + }, + "node_modules/cucumber-pretty": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/cucumber-pretty/-/cucumber-pretty-6.0.1.tgz", + "integrity": "sha512-9uOIZ8x3lgCPROqYc7kqe2e7UrH5TZPZCdj5fVPze1XViG9yv8/8MnFsAnVINDYWVhiql8DJHb3UrZfIPHYH/A==", + "dev": true, + "dependencies": { + "cli-table3": "^0.6.0", + "colors": "^1.4.0", + "figures": "^3.2.0" + }, + "peerDependencies": { + "cucumber": ">=6.0.0 <7.0.0" + } + }, + "node_modules/cucumber-tag-expressions": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/cucumber-tag-expressions/-/cucumber-tag-expressions-2.0.3.tgz", + "integrity": "sha512-+x5j1IfZrBtbvYHuoUX0rl4nUGxaey6Do9sM0CABmZfDCcWXuuRm1fQeCaklIYQgOFHQ6xOHvDSdkMHHpni6tQ==", + "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.", + "dev": true, + "peer": true + }, + "node_modules/cucumber-tsflow": { + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/cucumber-tsflow/-/cucumber-tsflow-4.4.4.tgz", + "integrity": "sha512-oe2fPcAxWljZTc4+u0whbXIxZvjWzXfsieoY/TGuHY4aDLLOCFVLOVIxV8bKEI53PQhxJH809VugWHe2DB+nJg==", + "dev": true, + "dependencies": { + "callsites": "^3.1.0", + "log4js": "^6.3.0", + "source-map-support": "^0.5.19", + "underscore": "^1.8.3" + }, + "peerDependencies": { + "@cucumber/cucumber": "^7 || ^8 || ^9 || ^10" + } + }, + "node_modules/cucumber/node_modules/ansi-regex": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", + "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==", + "dev": true, + "peer": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/cucumber/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "peer": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/cucumber/node_modules/cli-table3": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.5.1.tgz", + "integrity": "sha512-7Qg2Jrep1S/+Q3EceiZtQcDPWxhAvBw+ERf1162v4sikJrvojMHFqXt8QIVha8UlH9rgU0BeWPytZ9/TzYqlUw==", + "dev": true, + "peer": true, + "dependencies": { + "object-assign": "^4.1.0", + "string-width": "^2.1.1" + }, + "engines": { + "node": ">=6" + }, + "optionalDependencies": { + "colors": "^1.1.2" + } + }, + "node_modules/cucumber/node_modules/commander": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/commander/-/commander-3.0.2.tgz", + "integrity": "sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==", + "dev": true, + "peer": true + }, + "node_modules/cucumber/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, + "peer": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/cucumber/node_modules/is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==", + "dev": true, + "peer": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/cucumber/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "peer": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/cucumber/node_modules/string-width": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", + "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "dev": true, + "peer": true, + "dependencies": { + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^4.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/cucumber/node_modules/strip-ansi": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", + "integrity": "sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==", + "dev": true, + "peer": true, + "dependencies": { + "ansi-regex": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/custom-event": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/custom-event/-/custom-event-1.0.1.tgz", + "integrity": "sha512-GAj5FOq0Hd+RsCGVJxZuKaIDXDf3h6GQoNEjFgbLLI/trgtavwUbSnZ5pVfg27DVCaWjIohryS0JFwIJyT2cMg==", + "dev": true + }, + "node_modules/d": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", + "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", + "dev": true, + "peer": true, + "dependencies": { + "es5-ext": "^0.10.64", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.12" + } + }, + "node_modules/dashdash": { + "version": "1.14.1", + "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", + "integrity": "sha512-jRFi8UDGo6j+odZiEpjazZaWqEal3w/basFjQHQEwVtZJGDpxbH1MeYluwCS8Xq5wmLJooDlMgvVarmWfGM44g==", + "dev": true, + "dependencies": { + "assert-plus": "^1.0.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/data-uri-to-buffer": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz", + "integrity": "sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==", + "engines": { + "node": ">= 14" + } + }, + "node_modules/date-format": { + "version": "4.0.14", + "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", + "integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/dayjs": { + "version": "1.11.10", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", + "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==", + "peer": true + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/decamelize": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", + "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/deep-eql": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", + "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", + "dev": true, + "dependencies": { + "type-detect": "^4.0.0" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/deep-equal": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.2.tgz", + "integrity": "sha512-5tdhKF6DbU7iIzrIOa1AOUt39ZRm13cmL1cGEh//aqR8x9+tNfbywRf0n5FD/18OKMdo7DNEtrX2t22ZAkI+eg==", + "dev": true, + "dependencies": { + "is-arguments": "^1.1.1", + "is-date-object": "^1.0.5", + "is-regex": "^1.1.4", + "object-is": "^1.1.5", + "object-keys": "^1.1.1", + "regexp.prototype.flags": "^1.5.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true + }, + "node_modules/deepmerge": { + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", + "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/defaults": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.4.tgz", + "integrity": "sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==", + "peer": true, + "dependencies": { + "clone": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dev": true, + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/define-properties": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", + "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", + "dev": true, + "dependencies": { + "define-data-property": "^1.0.1", + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/degenerator": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/degenerator/-/degenerator-5.0.1.tgz", + "integrity": "sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ==", + "dependencies": { + "ast-types": "^0.13.4", + "escodegen": "^2.1.0", + "esprima": "^4.0.1" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/denodeify": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/denodeify/-/denodeify-1.2.1.tgz", + "integrity": "sha512-KNTihKNmQENUZeKu5fzfpzRqR5S2VMp4gl9RFHiWzj9DfvYQPMJ6XHKNaQxaGCXwPk6y9yme3aUoaiAe+KX+vg==", + "peer": true + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/deprecated-react-native-prop-types": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/deprecated-react-native-prop-types/-/deprecated-react-native-prop-types-5.0.0.tgz", + "integrity": "sha512-cIK8KYiiGVOFsKdPMmm1L3tA/Gl+JopXL6F5+C7x39MyPsQYnP57Im/D6bNUzcborD7fcMwiwZqcBdBXXZucYQ==", + "peer": true, + "dependencies": { + "@react-native/normalize-colors": "^0.73.0", + "invariant": "^2.2.4", + "prop-types": "^15.8.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/destroy": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", + "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "engines": { + "node": ">= 0.8", + "npm": "1.2.8000 || >= 1.4.16" + } + }, + "node_modules/di": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/di/-/di-0.0.1.tgz", + "integrity": "sha512-uJaamHkagcZtHPqCIHZxnFrXlunQXgBOsZSUOWwFw31QJCAbyTBoHMW75YOTur5ZNx8pIeAKgf6GWIgaqqiLhA==", + "dev": true + }, + "node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/diff-sequences": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", + "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==", + "dev": true, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/dir-glob": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", + "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "dev": true, + "dependencies": { + "path-type": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "dependencies": { + "esutils": "^2.0.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/dom-serialize": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/dom-serialize/-/dom-serialize-2.2.1.tgz", + "integrity": "sha512-Yra4DbvoW7/Z6LBN560ZwXMjoNOSAN2wRsKFGc4iBeso+mpIA6qj1vfdf9HpMaKAqG6wXTy+1SYEzmNpKXOSsQ==", + "dev": true, + "dependencies": { + "custom-event": "~1.0.0", + "ent": "~2.2.0", + "extend": "^3.0.0", + "void-elements": "^2.0.0" + } + }, + "node_modules/duration": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/duration/-/duration-0.2.2.tgz", + "integrity": "sha512-06kgtea+bGreF5eKYgI/36A6pLXggY7oR4p1pq4SmdFBn1ReOL5D8RhG64VrqfTTKNucqqtBAwEj8aB88mcqrg==", + "dev": true, + "peer": true, + "dependencies": { + "d": "1", + "es5-ext": "~0.10.46" + } + }, + "node_modules/eastasianwidth": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", + "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", + "dev": true + }, + "node_modules/ecc-jsbn": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==", + "dev": true, + "dependencies": { + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" + } + }, + "node_modules/ecc-jsbn/node_modules/jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==", + "dev": true + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" + }, + "node_modules/electron-to-chromium": { + "version": "1.4.740", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.740.tgz", + "integrity": "sha512-Yvg5i+iyv7Xm18BRdVPVm8lc7kgxM3r6iwqCH2zB7QZy1kZRNmd0Zqm0zcD9XoFREE5/5rwIuIAOT+/mzGcnZg==", + "peer": true + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/engine.io": { + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.4.tgz", + "integrity": "sha512-KdVSDKhVKyOi+r5uEabrDLZw2qXStVvCsEB/LN3mw4WFi6Gx50jTyuxYVCwAAC0U46FdnzP/ScKRBTXb/NiEOg==", + "dev": true, + "dependencies": { + "@types/cookie": "^0.4.1", + "@types/cors": "^2.8.12", + "@types/node": ">=10.0.0", + "accepts": "~1.3.4", + "base64id": "2.0.0", + "cookie": "~0.4.1", + "cors": "~2.8.5", + "debug": "~4.3.1", + "engine.io-parser": "~5.2.1", + "ws": "~8.11.0" + }, + "engines": { + "node": ">=10.2.0" + } + }, + "node_modules/engine.io-parser": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.2.tgz", + "integrity": "sha512-RcyUFKA93/CXH20l4SoVvzZfrSDMOTUS3bWVpTt2FuFP+XYrL8i8oonHP7WInRyVHXh0n/ORtoeiE1os+8qkSw==", + "dev": true, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/ent": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/ent/-/ent-2.2.0.tgz", + "integrity": "sha512-GHrMyVZQWvTIdDtpiEXdHZnFQKzeO09apj8Cbl4pKWy4i0Oprcq17usfDt5aO63swf0JOeMWjWQE/LzgSRuWpA==", + "dev": true + }, + "node_modules/envinfo": { + "version": "7.12.0", + "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.12.0.tgz", + "integrity": "sha512-Iw9rQJBGpJRd3rwXm9ft/JiGoAZmLxxJZELYDQoPRZ4USVhkKtIcNBPw6U+/K2mBpaqM25JSV6Yl4Az9vO2wJg==", + "peer": true, + "bin": { + "envinfo": "dist/cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/error-ex": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", + "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "dependencies": { + "is-arrayish": "^0.2.1" + } + }, + "node_modules/error-stack-parser": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-2.1.4.tgz", + "integrity": "sha512-Sk5V6wVazPhq5MhpO+AUxJn5x7XSXGl1R93Vn7i+zS15KDVxQijejNCrz8340/2bgLBjR9GtEG8ZVKONDjcqGQ==", + "dependencies": { + "stackframe": "^1.3.4" + } + }, + "node_modules/errorhandler": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/errorhandler/-/errorhandler-1.5.1.tgz", + "integrity": "sha512-rcOwbfvP1WTViVoUjcfZicVzjhjTuhSMntHh6mW3IrEiyE6mJyXvsToJUJGlGlw/2xU9P5whlWNGlIDVeCiT4A==", + "peer": true, + "dependencies": { + "accepts": "~1.3.7", + "escape-html": "~1.0.3" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", "dev": true, "dependencies": { - "sprintf-js": "~1.0.2" + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" } }, - "node_modules/array-from": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", - "integrity": "sha1-z+nYwmYoudxa7MYqn12PHzUsEZU=", - "dev": true - }, - "node_modules/array-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", - "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", "dev": true, "engines": { - "node": ">=8" + "node": ">= 0.4" } }, - "node_modules/arraybuffer.slice": { - "version": "0.0.7", - "resolved": "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.7.tgz", - "integrity": "sha512-wGUIVQXuehL5TCqQun8OW81jGzAWycqzFF8lFp+GOM5BXLYj3bKNsYC4daB7n6XjCqxQA/qgTJ+8ANR3acjrog==", - "dev": true - }, - "node_modules/arrify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", - "integrity": "sha1-iYUI2iIm84DfkEcoRWhJwVAaSw0=", + "node_modules/es5-ext": { + "version": "0.10.64", + "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", + "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", "dev": true, + "hasInstallScript": true, + "peer": true, + "dependencies": { + "es6-iterator": "^2.0.3", + "es6-symbol": "^3.1.3", + "esniff": "^2.0.1", + "next-tick": "^1.1.0" + }, "engines": { - "node": ">=0.10.0" + "node": ">=0.10" } }, - "node_modules/asap": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", - "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==" - }, - "node_modules/asn1": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", - "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==", + "node_modules/es6-iterator": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", + "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", "dev": true, + "peer": true, "dependencies": { - "safer-buffer": "~2.1.0" + "d": "1", + "es5-ext": "^0.10.35", + "es6-symbol": "^3.1.1" } }, - "node_modules/assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha1-8S4PPF13sLHN2RRpQuTpbB5N1SU=", + "node_modules/es6-promise": { + "version": "4.2.8", + "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", + "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", + "dev": true + }, + "node_modules/es6-shim": { + "version": "0.35.8", + "resolved": "https://registry.npmjs.org/es6-shim/-/es6-shim-0.35.8.tgz", + "integrity": "sha512-Twf7I2v4/1tLoIXMT8HlqaBSS5H2wQTs2wx3MNYCI8K1R1/clXyCazrcVCPm/FuO9cyV8+leEaZOWD5C253NDg==", + "dev": true + }, + "node_modules/es6-symbol": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", + "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", "dev": true, + "peer": true, + "dependencies": { + "d": "^1.0.2", + "ext": "^1.7.0" + }, "engines": { - "node": ">=0.8" + "node": ">=0.12" } }, - "node_modules/assertion-error": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", - "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "node_modules/esbuild": { + "version": "0.19.12", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.12.tgz", + "integrity": "sha512-aARqgq8roFBj054KvQr5f1sFu0D65G+miZRCuJyJ0G13Zwx7vRar5Zhn2tkQNzIXcBrNVsv/8stehpj+GAjgbg==", "dev": true, + "hasInstallScript": true, + "bin": { + "esbuild": "bin/esbuild" + }, "engines": { - "node": "*" + "node": ">=12" + }, + "optionalDependencies": { + "@esbuild/aix-ppc64": "0.19.12", + "@esbuild/android-arm": "0.19.12", + "@esbuild/android-arm64": "0.19.12", + "@esbuild/android-x64": "0.19.12", + "@esbuild/darwin-arm64": "0.19.12", + "@esbuild/darwin-x64": "0.19.12", + "@esbuild/freebsd-arm64": "0.19.12", + "@esbuild/freebsd-x64": "0.19.12", + "@esbuild/linux-arm": "0.19.12", + "@esbuild/linux-arm64": "0.19.12", + "@esbuild/linux-ia32": "0.19.12", + "@esbuild/linux-loong64": "0.19.12", + "@esbuild/linux-mips64el": "0.19.12", + "@esbuild/linux-ppc64": "0.19.12", + "@esbuild/linux-riscv64": "0.19.12", + "@esbuild/linux-s390x": "0.19.12", + "@esbuild/linux-x64": "0.19.12", + "@esbuild/netbsd-x64": "0.19.12", + "@esbuild/openbsd-x64": "0.19.12", + "@esbuild/sunos-x64": "0.19.12", + "@esbuild/win32-arm64": "0.19.12", + "@esbuild/win32-ia32": "0.19.12", + "@esbuild/win32-x64": "0.19.12" } }, - "node_modules/assertion-error-formatter": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/assertion-error-formatter/-/assertion-error-formatter-3.0.0.tgz", - "integrity": "sha512-6YyAVLrEze0kQ7CmJfUgrLHb+Y7XghmL2Ie7ijVa2Y9ynP3LV+VDiwFk62Dn0qtqbmY0BT0ss6p1xxpiF2PYbQ==", - "dev": true, - "dependencies": { - "diff": "^4.0.1", - "pad-right": "^0.2.2", - "repeat-string": "^1.6.1" + "node_modules/escalade": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", + "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==", + "engines": { + "node": ">=6" } }, - "node_modules/ast-types": { - "version": "0.13.4", - "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.13.4.tgz", - "integrity": "sha512-x1FCFnFifvYDDzTaLII71vG5uvDwgtmDTEVWAxrgeiR8VjMONcCXJx7E+USjDtHlwFmt9MysbqgF9b9Vjr6w+w==", + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" + }, + "node_modules/escape-string-regexp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", + "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", + "engines": { + "node": ">=8" + } + }, + "node_modules/escodegen": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.1.0.tgz", + "integrity": "sha512-2NlIDTwUWJN0mRPQOdtQBzbUHvdGY2P1VXSyU83Q3xKxM7WHX2Ql8dKq782Q9TgQUNOLEzEYu9bzLNj1q88I5w==", "dependencies": { - "tslib": "^2.0.1" + "esprima": "^4.0.1", + "estraverse": "^5.2.0", + "esutils": "^2.0.2" + }, + "bin": { + "escodegen": "bin/escodegen.js", + "esgenerate": "bin/esgenerate.js" }, "engines": { - "node": ">=4" + "node": ">=6.0" + }, + "optionalDependencies": { + "source-map": "~0.6.1" } }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" - }, - "node_modules/aws-sign2": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", - "integrity": "sha1-tG6JCTSpWR8tL2+G1+ap8bP+dqg=", + "node_modules/eslint": { + "version": "8.57.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", + "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", "dev": true, + "dependencies": { + "@eslint-community/eslint-utils": "^4.2.0", + "@eslint-community/regexpp": "^4.6.1", + "@eslint/eslintrc": "^2.1.4", + "@eslint/js": "8.57.0", + "@humanwhocodes/config-array": "^0.11.14", + "@humanwhocodes/module-importer": "^1.0.1", + "@nodelib/fs.walk": "^1.2.8", + "@ungap/structured-clone": "^1.2.0", + "ajv": "^6.12.4", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.3.2", + "doctrine": "^3.0.0", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^7.2.2", + "eslint-visitor-keys": "^3.4.3", + "espree": "^9.6.1", + "esquery": "^1.4.2", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^6.0.1", + "find-up": "^5.0.0", + "glob-parent": "^6.0.2", + "globals": "^13.19.0", + "graphemer": "^1.4.0", + "ignore": "^5.2.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "is-path-inside": "^3.0.3", + "js-yaml": "^4.1.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.1.2", + "natural-compare": "^1.4.0", + "optionator": "^0.9.3", + "strip-ansi": "^6.0.1", + "text-table": "^0.2.0" + }, + "bin": { + "eslint": "bin/eslint.js" + }, "engines": { - "node": "*" + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, - "node_modules/aws4": { - "version": "1.11.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.11.0.tgz", - "integrity": "sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==", - "dev": true - }, - "node_modules/backo2": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", - "integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc=", - "dev": true - }, - "node_modules/balanced-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", - "dev": true - }, - "node_modules/base64-arraybuffer": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.4.tgz", - "integrity": "sha1-mBjHngWbE1X5fgQooBfIOOkLqBI=", + "node_modules/eslint-plugin-mocha": { + "version": "10.4.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.4.2.tgz", + "integrity": "sha512-cur4dVYnSEWTBwdqIBQFxa/9siAhesu0TX+lbJ4ClE9j0eNMNe6BSx3vkFFNz6tGoveyMyELFXa30f3fvuAVDg==", "dev": true, + "dependencies": { + "eslint-utils": "^3.0.0", + "globals": "^13.24.0", + "rambda": "^7.4.0" + }, "engines": { - "node": ">= 0.6.0" + "node": ">=14.0.0" + }, + "peerDependencies": { + "eslint": ">=7.0.0" } }, - "node_modules/base64-js": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", - "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" + "node_modules/eslint-plugin-prettier": { + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz", + "integrity": "sha512-C9GCVAs4Eq7ZC/XFQHITLiHJxQngdtraXaM+LoUFoFp/lHNl2Zn8f3WQbe9HvTBBQ9YnKFB0/2Ajdqwo5D1EAw==", + "dev": true, + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.8.6" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint-plugin-prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "eslint-config-prettier": "*", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true }, - { - "type": "consulting", - "url": "https://feross.org/support" + "eslint-config-prettier": { + "optional": true } - ] + } }, - "node_modules/base64id": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", - "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==", + "node_modules/eslint-scope": { + "version": "7.2.2", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", + "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/eslint-utils": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", + "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", + "dev": true, + "dependencies": { + "eslint-visitor-keys": "^2.0.0" + }, + "engines": { + "node": "^10.0.0 || ^12.0.0 || >= 14.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + }, + "peerDependencies": { + "eslint": ">=5" + } + }, + "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", "dev": true, "engines": { - "node": "^4.5.0 || >= 5.9" + "node": ">=10" } }, - "node_modules/basic-ftp": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.0.4.tgz", - "integrity": "sha512-8PzkB0arJFV4jJWSGOYR+OEic6aeKMu/osRhBULN6RY0ykby6LKhbmuQ5ublvaas5BOwboah5D87nrHyuh8PPA==", + "node_modules/eslint-visitor-keys": { + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", + "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", + "dev": true, "engines": { - "node": ">=10.0.0" + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, - "node_modules/bcrypt-pbkdf": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", - "integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=", + "node_modules/eslint/node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "node_modules/eslint/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, "dependencies": { - "tweetnacl": "^0.14.3" + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" } }, - "node_modules/becke-ch--regex--s0-0-v1--base--pl--lib": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/becke-ch--regex--s0-0-v1--base--pl--lib/-/becke-ch--regex--s0-0-v1--base--pl--lib-1.4.0.tgz", - "integrity": "sha512-FnWonOyaw7Vivg5nIkrUll9HSS5TjFbyuURAiDssuL6VxrBe3ERzudRxOcWRhZYlP89UArMDikz7SapRPQpmZQ==", - "dev": true, - "peer": true - }, - "node_modules/binary-extensions": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", - "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "node_modules/eslint/node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true, "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/blob": { - "version": "0.0.5", - "resolved": "https://registry.npmjs.org/blob/-/blob-0.0.5.tgz", - "integrity": "sha512-gaqbzQPqOoamawKg0LGVd7SzLgXS+JH61oWprSLH+P+abTczqJbhTR8CmJ2u9/bUYNmHTGJx/UEmn6doAvvuig==", - "dev": true - }, - "node_modules/bluebird": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", - "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", - "dev": true - }, - "node_modules/body-parser": { - "version": "1.19.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.19.2.tgz", - "integrity": "sha512-SAAwOxgoCKMGs9uUAUFHygfLAyaniaoun6I8mFY9pRAJL9+Kec34aU+oIjDhTycub1jozEfEwx1W1IuOYxVSFw==", + "node_modules/eslint/node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, "dependencies": { - "bytes": "3.1.2", - "content-type": "~1.0.4", - "debug": "2.6.9", - "depd": "~1.1.2", - "http-errors": "1.8.1", - "iconv-lite": "0.4.24", - "on-finished": "~2.3.0", - "qs": "6.9.7", - "raw-body": "2.4.3", - "type-is": "~1.6.18" + "argparse": "^2.0.1" }, - "engines": { - "node": ">= 0.8" + "bin": { + "js-yaml": "bin/js-yaml.js" } }, - "node_modules/body-parser/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "node_modules/eslint/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, "dependencies": { - "ms": "2.0.0" + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" } }, - "node_modules/body-parser/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - }, - "node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "node_modules/esniff": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", + "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", "dev": true, + "peer": true, "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" + "d": "^1.0.1", + "es5-ext": "^0.10.62", + "event-emitter": "^0.3.5", + "type": "^2.7.2" + }, + "engines": { + "node": ">=0.10" } }, - "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "node_modules/espree": { + "version": "9.6.1", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", + "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "acorn": "^8.9.0", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^3.4.1" }, "engines": { - "node": ">=8" + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, - "node_modules/browser-stdout": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", - "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", - "dev": true + "node_modules/esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "bin": { + "esparse": "bin/esparse.js", + "esvalidate": "bin/esvalidate.js" + }, + "engines": { + "node": ">=4" + } }, - "node_modules/buffer": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], + "node_modules/esquery": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", + "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", + "dev": true, "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.2.1" + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" } }, - "node_modules/buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=", + "node_modules/esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, + "dependencies": { + "estraverse": "^5.2.0" + }, "engines": { - "node": "*" + "node": ">=4.0" } }, - "node_modules/buffer-from": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estree-walker": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", + "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "dev": true }, - "node_modules/builtin-modules": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.2.0.tgz", - "integrity": "sha512-lGzLKcioL90C7wMczpkY0n/oART3MbBa8R9OFGE1rJxoVI86u4WAGfEk8Wjv10eKSyTHVGkSo3bvBylCEtk7LA==", - "dev": true, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=0.10.0" } }, - "node_modules/bytes": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", - "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "peer": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/event-emitter": { + "version": "0.3.5", + "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", + "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", "dev": true, + "peer": true, + "dependencies": { + "d": "1", + "es5-ext": "~0.10.14" + } + }, + "node_modules/event-target-shim": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", + "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "peer": true, "engines": { - "node": ">= 0.8" + "node": ">=6" } }, - "node_modules/call-bind": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", - "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "node_modules/eventemitter3": { + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", + "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", + "dev": true + }, + "node_modules/execa": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", + "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "peer": true, "dependencies": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" + "cross-spawn": "^7.0.3", + "get-stream": "^6.0.0", + "human-signals": "^2.1.0", + "is-stream": "^2.0.0", + "merge-stream": "^2.0.0", + "npm-run-path": "^4.0.1", + "onetime": "^5.1.2", + "signal-exit": "^3.0.3", + "strip-final-newline": "^2.0.0" + }, + "engines": { + "node": ">=10" }, "funding": { - "url": "https://github.com/sponsors/ljharb" + "url": "https://github.com/sindresorhus/execa?sponsor=1" } }, - "node_modules/callsites": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", - "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "node_modules/execa/node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "peer": true + }, + "node_modules/expect": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/expect/-/expect-29.7.0.tgz", + "integrity": "sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==", "dev": true, + "dependencies": { + "@jest/expect-utils": "^29.7.0", + "jest-get-type": "^29.6.3", + "jest-matcher-utils": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-util": "^29.7.0" + }, "engines": { - "node": ">=6" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "node_modules/ext": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", + "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", "dev": true, - "engines": { - "node": ">=6" + "peer": true, + "dependencies": { + "type": "^2.7.2" } }, - "node_modules/capital-case": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/capital-case/-/capital-case-1.0.4.tgz", - "integrity": "sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A==", + "node_modules/extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "dev": true + }, + "node_modules/extract-zip": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz", + "integrity": "sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==", "dev": true, "dependencies": { - "no-case": "^3.0.4", - "tslib": "^2.0.3", - "upper-case-first": "^2.0.2" + "concat-stream": "^1.6.2", + "debug": "^2.6.9", + "mkdirp": "^0.5.4", + "yauzl": "^2.10.0" + }, + "bin": { + "extract-zip": "cli.js" } }, - "node_modules/caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=", - "dev": true - }, - "node_modules/cbor-js": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/cbor-js/-/cbor-js-0.1.0.tgz", - "integrity": "sha1-yAzmEg84fo+qdDcN/aIdlluPx/k=" - }, - "node_modules/cbor-sync": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/cbor-sync/-/cbor-sync-1.0.4.tgz", - "integrity": "sha512-GWlXN4wiz0vdWWXBU71Dvc1q3aBo0HytqwAZnXF1wOwjqNnDWA1vZ1gDMFLlqohak31VQzmhiYfiCX5QSSfagA==" - }, - "node_modules/chai": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.3.4.tgz", - "integrity": "sha512-yS5H68VYOCtN1cjfwumDSuzn/9c+yza4f3reKXlE5rUg7SFcCEy90gJvydNgOYtblyf4Zi6jIWRnXOgErta0KA==", + "node_modules/extract-zip/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "dev": true, "dependencies": { - "assertion-error": "^1.1.0", - "check-error": "^1.0.2", - "deep-eql": "^3.0.1", - "get-func-name": "^2.0.0", - "pathval": "^1.1.1", - "type-detect": "^4.0.5" - }, - "engines": { - "node": ">=4" + "ms": "2.0.0" } }, - "node_modules/chai-as-promised": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz", - "integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==", + "node_modules/extract-zip/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", "dev": true, "dependencies": { - "check-error": "^1.0.2" + "minimist": "^1.2.6" }, - "peerDependencies": { - "chai": ">= 2.1.2 < 5" + "bin": { + "mkdirp": "bin/cmd.js" } }, - "node_modules/chai-nock": { + "node_modules/extract-zip/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "dev": true + }, + "node_modules/extsprintf": { "version": "1.3.0", - "resolved": "https://registry.npmjs.org/chai-nock/-/chai-nock-1.3.0.tgz", - "integrity": "sha512-O3j1bW3ACoUu/sLGYSoX50c1p8dbTkCjw3/dereqzl9BL2XsQAUVC18sJpg3hVwpCk71rjWGumCmHy87t5W+Pg==", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha512-11Ndz7Nv+mvAC1j0ktTa7fAb0vLyGGX+rMHNBYQviQDGU0Hw7lhctJANqbPhu9nV9/izT/IntTgZ7Im/9LJs9g==", "dev": true, - "dependencies": { - "chai": "^4.2.0", - "deep-equal": "^1.0.1" - } + "engines": [ + "node >=0.6.0" + ] }, - "node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true + }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true + }, + "node_modules/fast-glob": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", + "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", "dev": true, "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" + "@nodelib/fs.stat": "^2.0.2", + "@nodelib/fs.walk": "^1.2.3", + "glob-parent": "^5.1.2", + "merge2": "^1.3.0", + "micromatch": "^4.0.4" }, "engines": { - "node": ">=4" + "node": ">=8.6.0" } }, - "node_modules/check-error": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", - "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "node_modules/fast-glob/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, + "dependencies": { + "is-glob": "^4.0.1" + }, "engines": { - "node": "*" + "node": ">= 6" } }, - "node_modules/chokidar": { - "version": "3.5.3", - "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", - "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", - "dev": true, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true + }, + "node_modules/fast-xml-parser": { + "version": "4.3.6", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.3.6.tgz", + "integrity": "sha512-M2SovcRxD4+vC493Uc2GZVcZaj66CCJhWurC4viynVSTvrpErCShNcDz1lAho6n9REQKvL/ll4A4/fw6Y9z8nw==", "funding": [ { - "type": "individual", - "url": "https://paulmillr.com/funding/" + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + }, + { + "type": "paypal", + "url": "https://paypal.me/naturalintelligence" } ], + "peer": true, "dependencies": { - "anymatch": "~3.1.2", - "braces": "~3.0.2", - "glob-parent": "~5.1.2", - "is-binary-path": "~2.1.0", - "is-glob": "~4.0.1", - "normalize-path": "~3.0.0", - "readdirp": "~3.6.0" - }, - "engines": { - "node": ">= 8.10.0" + "strnum": "^1.0.5" }, - "optionalDependencies": { - "fsevents": "~2.3.2" + "bin": { + "fxparser": "src/cli/cli.js" } }, - "node_modules/class-transformer": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", - "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", - "dev": true, - "peer": true - }, - "node_modules/cli-table3": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.3.tgz", - "integrity": "sha512-w5Jac5SykAeZJKntOxJCrm63Eg5/4dhMWIcuTbo9rpE+brgaSZo0RuNJZeOyMgsUdhDeojvgyQLmjI+K50ZGyg==", + "node_modules/fastq": { + "version": "1.17.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", + "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", "dev": true, "dependencies": { - "string-width": "^4.2.0" - }, - "engines": { - "node": "10.* || >= 12.*" - }, - "optionalDependencies": { - "@colors/colors": "1.5.0" + "reusify": "^1.0.4" } }, - "node_modules/cliui": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", - "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", - "dev": true, + "node_modules/fb-watchman": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.2.tgz", + "integrity": "sha512-p5161BqbuCaSnB8jIbzQHOlpgsPmK5rJVDfDKO91Axs5NC1uu3HRQm6wt9cd9/+GtQQIO53JdGXXoyDpTAsgYA==", + "peer": true, "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^6.2.0" + "bser": "2.1.1" } }, - "node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "node_modules/fd-slicer": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", + "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", "dev": true, "dependencies": { - "color-name": "1.1.3" + "pend": "~1.2.0" } }, - "node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", - "dev": true - }, - "node_modules/colors": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", - "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", + "node_modules/figures": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", + "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", "dev": true, - "engines": { - "node": ">=0.1.90" - } - }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", "dependencies": { - "delayed-stream": "~1.0.0" + "escape-string-regexp": "^1.0.5" }, "engines": { - "node": ">= 0.8" + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/commander": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-7.2.0.tgz", - "integrity": "sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==", + "node_modules/figures/node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", "dev": true, "engines": { - "node": ">= 10" + "node": ">=0.8.0" } }, - "node_modules/commondir": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha1-3dgA2gxmEnOTzKWVDqloo6rxJTs=", - "dev": true - }, - "node_modules/component-bind": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz", - "integrity": "sha1-AMYIq33Nk4l8AAllGx06jh5zu9E=", - "dev": true - }, - "node_modules/component-emitter": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.3.0.tgz", - "integrity": "sha512-Rd3se6QB+sO1TwqZjscQrurpEPIfO0/yYnSin6Q/rD3mOutHvUrCAhJub3r90uNb+SESBuE0QYoB90YdfatsRg==" - }, - "node_modules/component-inherit": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz", - "integrity": "sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM=", - "dev": true - }, - "node_modules/concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true - }, - "node_modules/concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", + "node_modules/file-entry-cache": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", + "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", "dev": true, - "engines": [ - "node >= 0.8" - ], "dependencies": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" + "flat-cache": "^3.0.4" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" } }, - "node_modules/connect": { - "version": "3.7.0", - "resolved": "https://registry.npmjs.org/connect/-/connect-3.7.0.tgz", - "integrity": "sha512-ZqRXc+tZukToSNmh5C2iWMSoV3X1YUcPbqEM4DkEG5tNQXrQUZCNVGGv3IuicnkMtPfGf3Xtp8WCXs295iQ1pQ==", - "dev": true, + "node_modules/finalhandler": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", + "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", "dependencies": { "debug": "2.6.9", - "finalhandler": "1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "~2.3.0", "parseurl": "~1.3.3", - "utils-merge": "1.0.1" + "statuses": "~1.5.0", + "unpipe": "~1.0.0" }, "engines": { - "node": ">= 0.10.0" + "node": ">= 0.8" } }, - "node_modules/connect/node_modules/debug": { + "node_modules/finalhandler/node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, "dependencies": { "ms": "2.0.0" } }, - "node_modules/connect/node_modules/ms": { + "node_modules/finalhandler/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" }, - "node_modules/content-type": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", - "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==", - "dev": true, + "node_modules/finalhandler/node_modules/on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", + "dependencies": { + "ee-first": "1.1.1" + }, "engines": { - "node": ">= 0.6" + "node": ">= 0.8" } }, - "node_modules/cookie": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", - "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", - "dev": true, + "node_modules/find-cache-dir": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.1.0.tgz", + "integrity": "sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ==", + "peer": true, + "dependencies": { + "commondir": "^1.0.1", + "make-dir": "^2.0.0", + "pkg-dir": "^3.0.0" + }, "engines": { - "node": ">= 0.6" + "node": ">=6" } }, - "node_modules/cookiejar": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/cookiejar/-/cookiejar-2.1.4.tgz", - "integrity": "sha512-LDx6oHrK+PhzLKJU9j5S7/Y3jM/mUHvD/DeI1WQmJn652iPC5Y4TBzC9l+5OMOXlyTTA+SmVUPm0HQUwpD5Jqw==" + "node_modules/find-up": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", + "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dependencies": { + "locate-path": "^6.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } }, - "node_modules/core-js-pure": { - "version": "3.26.0", - "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.26.0.tgz", - "integrity": "sha512-LiN6fylpVBVwT8twhhluD9TzXmZQQsr2I2eIKtWNbZI1XMfBT7CV18itaN6RA7EtQd/SDdRx/wzvAShX2HvhQA==", + "node_modules/flat": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", + "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", "dev": true, - "hasInstallScript": true, - "peer": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/core-js" + "bin": { + "flat": "cli.js" } }, - "node_modules/core-util-is": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", - "dev": true + "node_modules/flat-cache": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", + "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", + "dev": true, + "dependencies": { + "flatted": "^3.2.9", + "keyv": "^4.5.3", + "rimraf": "^3.0.2" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } }, - "node_modules/create-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", - "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", + "node_modules/flatted": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", + "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", "dev": true }, - "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "node_modules/flow-enums-runtime": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/flow-enums-runtime/-/flow-enums-runtime-0.0.6.tgz", + "integrity": "sha512-3PYnM29RFXwvAN6Pc/scUfkI7RwhQ/xqyLUyPNlXUp9S40zI8nup9tUSrTLSVnWGBN38FNiGWbwZOB6uR4OGdw==", + "peer": true + }, + "node_modules/flow-parser": { + "version": "0.206.0", + "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.206.0.tgz", + "integrity": "sha512-HVzoK3r6Vsg+lKvlIZzaWNBVai+FXTX1wdYhz/wVlH13tb/gOdLXmlTqy6odmTBhT5UoWUbq0k8263Qhr9d88w==", + "peer": true, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/follow-redirects": { + "version": "1.15.6", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", + "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", "dev": true, - "dependencies": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - }, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/RubenVerborgh" + } + ], "engines": { - "node": ">= 8" + "node": ">=4.0" + }, + "peerDependenciesMeta": { + "debug": { + "optional": true + } } }, - "node_modules/cross-spawn/node_modules/which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "node_modules/foreground-child": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", + "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", "dev": true, "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" }, "engines": { - "node": ">= 8" + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/cucumber": { - "version": "6.0.7", - "resolved": "https://registry.npmjs.org/cucumber/-/cucumber-6.0.7.tgz", - "integrity": "sha512-pN3AgWxHx8rOi+wOlqjASNETOjf3TgeyqhMNLQam7nSTXgQzju1oAmXkleRQRcXvpVvejcDHiZBLFSfBkqbYpA==", - "deprecated": "Cucumber is publishing new releases under @cucumber/cucumber", + "node_modules/forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==", "dev": true, - "peer": true, + "engines": { + "node": "*" + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", "dependencies": { - "assertion-error-formatter": "^3.0.0", - "bluebird": "^3.4.1", - "cli-table3": "^0.5.1", - "colors": "^1.1.2", - "commander": "^3.0.1", - "cucumber-expressions": "^8.1.0", - "cucumber-tag-expressions": "^2.0.2", - "duration": "^0.2.1", - "escape-string-regexp": "^2.0.0", - "figures": "^3.0.0", - "gherkin": "5.0.0", - "glob": "^7.1.3", - "indent-string": "^4.0.0", - "is-generator": "^1.0.2", - "is-stream": "^2.0.0", - "knuth-shuffle-seeded": "^1.0.6", - "lodash": "^4.17.14", - "mz": "^2.4.0", - "progress": "^2.0.0", - "resolve": "^1.3.3", - "serialize-error": "^4.1.0", - "stack-chain": "^2.0.0", - "stacktrace-js": "^2.0.0", - "string-argv": "^0.3.0", - "title-case": "^2.1.1", - "util-arity": "^1.0.2", - "verror": "^1.9.0" - }, - "bin": { - "cucumber-js": "bin/cucumber-js" + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" }, "engines": { - "node": ">=8" + "node": ">= 6" } }, - "node_modules/cucumber-expressions": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/cucumber-expressions/-/cucumber-expressions-8.3.0.tgz", - "integrity": "sha512-cP2ya0EiorwXBC7Ll7Cj7NELYbasNv9Ty42L4u7sso9KruWemWG1ZiTq4PMqir3SNDSrbykoqI5wZgMbLEDjLQ==", - "deprecated": "This package is now published under @cucumber/cucumber-expressions", - "dev": true, + "node_modules/fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", "peer": true, - "dependencies": { - "becke-ch--regex--s0-0-v1--base--pl--lib": "^1.4.0", - "xregexp": "^4.2.4" + "engines": { + "node": ">= 0.6" } }, - "node_modules/cucumber-expressions/node_modules/xregexp": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.4.1.tgz", - "integrity": "sha512-2u9HwfadaJaY9zHtRRnH6BY6CQVNQKkYm3oLtC9gJXXzfsbACg5X5e4EZZGVAH+YIfa+QA9lsFQTTe3HURF3ag==", + "node_modules/fs-extra": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-1.0.0.tgz", + "integrity": "sha512-VerQV6vEKuhDWD2HGOybV6v5I73syoc/cXAbKlgTC7M/oFVEtklWlp9QH2Ijw3IaWDOQcMkldSPa7zXy79Z/UQ==", "dev": true, - "peer": true, "dependencies": { - "@babel/runtime-corejs3": "^7.12.1" + "graceful-fs": "^4.1.2", + "jsonfile": "^2.1.0", + "klaw": "^1.0.0" } }, - "node_modules/cucumber-pretty": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/cucumber-pretty/-/cucumber-pretty-6.0.1.tgz", - "integrity": "sha512-9uOIZ8x3lgCPROqYc7kqe2e7UrH5TZPZCdj5fVPze1XViG9yv8/8MnFsAnVINDYWVhiql8DJHb3UrZfIPHYH/A==", - "dev": true, - "dependencies": { - "cli-table3": "^0.6.0", - "colors": "^1.4.0", - "figures": "^3.2.0" - }, - "peerDependencies": { - "cucumber": ">=6.0.0 <7.0.0" + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, + "node_modules/fsevents": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", + "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, - "node_modules/cucumber-tag-expressions": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/cucumber-tag-expressions/-/cucumber-tag-expressions-2.0.3.tgz", - "integrity": "sha512-+x5j1IfZrBtbvYHuoUX0rl4nUGxaey6Do9sM0CABmZfDCcWXuuRm1fQeCaklIYQgOFHQ6xOHvDSdkMHHpni6tQ==", + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/functions-have-names": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", + "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", "dev": true, - "peer": true + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gensync": { + "version": "1.0.0-beta.2", + "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", + "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", + "peer": true, + "engines": { + "node": ">=6.9.0" + } }, - "node_modules/cucumber-tsflow": { - "version": "4.0.0-rc.11", - "resolved": "https://registry.npmjs.org/cucumber-tsflow/-/cucumber-tsflow-4.0.0-rc.11.tgz", - "integrity": "sha512-VK/RhJOOxS4KAH6UIkfLsDE2+H7OtP/+cwzx139gldqHP08hoYk/fMwOoXlGWXOOX2O3amJ6RTS0YMF2xCA8Bw==", - "dev": true, - "dependencies": { - "callsites": "^3.1.0", - "log4js": "^6.3.0", - "source-map-support": "^0.5.19", - "underscore": "^1.8.3" - }, - "peerDependencies": { - "@cucumber/cucumber": ">7.0.0-rc || >7.0.0" + "node_modules/get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "engines": { + "node": "6.* || 8.* || >= 10.*" } }, - "node_modules/cucumber/node_modules/ansi-regex": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", - "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==", + "node_modules/get-func-name": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", + "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", "dev": true, - "peer": true, "engines": { - "node": ">=4" + "node": "*" } }, - "node_modules/cucumber/node_modules/cli-table3": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.5.1.tgz", - "integrity": "sha512-7Qg2Jrep1S/+Q3EceiZtQcDPWxhAvBw+ERf1162v4sikJrvojMHFqXt8QIVha8UlH9rgU0BeWPytZ9/TzYqlUw==", + "node_modules/get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", "dev": true, - "peer": true, "dependencies": { - "object-assign": "^4.1.0", - "string-width": "^2.1.1" + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" }, "engines": { - "node": ">=6" + "node": ">= 0.4" }, - "optionalDependencies": { - "colors": "^1.1.2" + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/cucumber/node_modules/commander": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/commander/-/commander-3.0.2.tgz", - "integrity": "sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==", - "dev": true, - "peer": true - }, - "node_modules/cucumber/node_modules/escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "dev": true, + "node_modules/get-stream": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", + "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", "peer": true, "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/cucumber/node_modules/is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==", + "node_modules/get-tsconfig": { + "version": "4.7.3", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.7.3.tgz", + "integrity": "sha512-ZvkrzoUA0PQZM6fy6+/Hce561s+faD1rsNwhnO5FelNjyy7EMGJ3Rz1AQ8GYDWjhRs/7dBLOEJvhK8MiEJOAFg==", "dev": true, - "peer": true, - "engines": { - "node": ">=4" + "dependencies": { + "resolve-pkg-maps": "^1.0.0" + }, + "funding": { + "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" } }, - "node_modules/cucumber/node_modules/string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", - "dev": true, - "peer": true, + "node_modules/get-uri": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/get-uri/-/get-uri-6.0.3.tgz", + "integrity": "sha512-BzUrJBS9EcUb4cFol8r4W3v1cPsSyajLSthNkz5BxbpDcHN5tIrM10E2eNvfnvBn3DaT3DUgx0OpsBKkaOpanw==", "dependencies": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" + "basic-ftp": "^5.0.2", + "data-uri-to-buffer": "^6.0.2", + "debug": "^4.3.4", + "fs-extra": "^11.2.0" }, "engines": { - "node": ">=4" + "node": ">= 14" } }, - "node_modules/cucumber/node_modules/strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==", - "dev": true, - "peer": true, + "node_modules/get-uri/node_modules/fs-extra": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", + "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", "dependencies": { - "ansi-regex": "^3.0.0" + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" }, "engines": { - "node": ">=4" + "node": ">=14.14" } }, - "node_modules/custom-event": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/custom-event/-/custom-event-1.0.1.tgz", - "integrity": "sha1-XQKkaFCt8bSjF5RqOSj8y1v9BCU=", - "dev": true - }, - "node_modules/d": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.1.tgz", - "integrity": "sha512-m62ShEObQ39CfralilEQRjH6oAMtNCV1xJyEx5LpRYUVN+EviphDgUc/F3hnYbADmkiNs67Y+3ylmlG7Lnu+FA==", - "dev": true, + "node_modules/get-uri/node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", "dependencies": { - "es5-ext": "^0.10.50", - "type": "^1.0.1" + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" } }, - "node_modules/dashdash": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "integrity": "sha1-hTz6D3y+L+1d4gMmuN1YEDX24vA=", + "node_modules/getpass": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", + "integrity": "sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==", "dev": true, "dependencies": { "assert-plus": "^1.0.0" - }, - "engines": { - "node": ">=0.10" - } - }, - "node_modules/data-uri-to-buffer": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.1.tgz", - "integrity": "sha512-MZd3VlchQkp8rdend6vrx7MmVDJzSNTBvghvKjirLkD+WTChA3KUf0jkE68Q4UyctNqI11zZO9/x2Yx+ub5Cvg==", - "engines": { - "node": ">= 14" } }, - "node_modules/date-format": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.3.tgz", - "integrity": "sha512-7P3FyqDcfeznLZp2b+OMitV9Sz2lUnsT87WaTat9nVwqsBkTzPG3lPLNwW3en6F4pHUiWzr6vb8CLhjdK9bcxQ==", + "node_modules/gherkin": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/gherkin/-/gherkin-5.0.0.tgz", + "integrity": "sha512-Y+93z2Nh+TNIKuKEf+6M0FQrX/z0Yv9C2LFfc5NlcGJWRrrTeI/jOg2374y1FOw6ZYQ3RgJBezRkli7CLDubDA==", + "deprecated": "This package is now published under @cucumber/gherkin", "dev": true, - "engines": { - "node": ">=4.0" + "peer": true, + "bin": { + "gherkin-javascript": "bin/gherkin" } }, - "node_modules/debug": { - "version": "4.3.3", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.3.tgz", - "integrity": "sha512-/zxw5+vh1Tfv+4Qn7a5nsbcJKPaSvCDhojn6FEl9vupwK2VCSDtEiEtqr8DFtzYFOdz63LBkxec7DYuc2jon6Q==", + "node_modules/glob": { + "version": "10.3.12", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.12.tgz", + "integrity": "sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg==", + "dev": true, "dependencies": { - "ms": "2.1.2" + "foreground-child": "^3.1.0", + "jackspeak": "^2.3.6", + "minimatch": "^9.0.1", + "minipass": "^7.0.4", + "path-scurry": "^1.10.2" + }, + "bin": { + "glob": "dist/esm/bin.mjs" }, "engines": { - "node": ">=6.0" + "node": ">=16 || 14 >=14.17" }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=", + "node_modules/glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", "dev": true, + "dependencies": { + "is-glob": "^4.0.3" + }, "engines": { - "node": ">=0.10.0" + "node": ">=10.13.0" } }, - "node_modules/deep-eql": { + "node_modules/global-dirs": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", - "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-3.0.1.tgz", + "integrity": "sha512-NBcGGFbBA9s1VzD41QXDG+3++t9Mn5t1FpLdhESY6oKY4gYTFpX4wO3sqGUa0Srjtbfj3szX0RnemmrVRUdULA==", "dev": true, "dependencies": { - "type-detect": "^4.0.0" + "ini": "2.0.0" }, "engines": { - "node": ">=0.12" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/deep-equal": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.1.tgz", - "integrity": "sha512-yd9c5AdiqVcR+JjcwUQb9DkhJc8ngNr0MahEBGvDiJw8puWab2yZlh+nkasOnZP+EGTAP6rRp2JzJhJZzvNF8g==", + "node_modules/globals": { + "version": "13.24.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", + "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, "dependencies": { - "is-arguments": "^1.0.4", - "is-date-object": "^1.0.1", - "is-regex": "^1.0.4", - "object-is": "^1.0.1", - "object-keys": "^1.1.1", - "regexp.prototype.flags": "^1.2.0" + "type-fest": "^0.20.2" + }, + "engines": { + "node": ">=8" }, "funding": { - "url": "https://github.com/sponsors/ljharb" + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/deep-is": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", - "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", - "dev": true - }, - "node_modules/deepmerge": { - "version": "4.2.2", - "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", - "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", + "node_modules/globals/node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true, "engines": { - "node": ">=0.10.0" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/define-properties": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", - "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "node_modules/globby": { + "version": "11.1.0", + "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", + "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", "dev": true, "dependencies": { - "object-keys": "^1.0.12" + "array-union": "^2.1.0", + "dir-glob": "^3.0.1", + "fast-glob": "^3.2.9", + "ignore": "^5.2.0", + "merge2": "^1.4.1", + "slash": "^3.0.0" }, "engines": { - "node": ">= 0.4" - } - }, - "node_modules/degenerator": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/degenerator/-/degenerator-5.0.1.tgz", - "integrity": "sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ==", - "dependencies": { - "ast-types": "^0.13.4", - "escodegen": "^2.1.0", - "esprima": "^4.0.1" + "node": ">=10" }, - "engines": { - "node": ">= 14" - } - }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=", - "engines": { - "node": ">=0.4.0" + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/depd": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", - "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=", + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", "dev": true, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/dezalgo": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.4.tgz", - "integrity": "sha512-rXSP0bf+5n0Qonsb+SVVfNfIsimO4HEtmnIpPHY8Q1UCzKlQrDMfdobr8nJOOsRgWCyMRqeSBQzmWUMq7zvVig==", "dependencies": { - "asap": "^2.0.0", - "wrappy": "1" + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/di": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/di/-/di-0.0.1.tgz", - "integrity": "sha1-gGZJMmzqp8qjMG112YXqJ0i6kTw=", - "dev": true + "node_modules/graceful-fs": { + "version": "4.2.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" }, - "node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true, - "engines": { - "node": ">=0.3.1" - } + "node_modules/graphemer": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", + "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", + "dev": true }, - "node_modules/diff-sequences": { - "version": "27.5.1", - "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.5.1.tgz", - "integrity": "sha512-k1gCAXAsNgLwEL+Y8Wvl+M6oEFj5bgazfZULpS5CneoPPXRaCCW7dm+q21Ky2VEE5X+VeRDBVg1Pcvvsr4TtNQ==", + "node_modules/har-schema": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", + "integrity": "sha512-Oqluz6zhGX8cyRaTQlFMPw80bSJVG2x/cFb8ZPhUILGgHka9SsokCCOQgpveePerqidZOrT14ipqfJb7ILcW5Q==", "dev": true, "engines": { - "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + "node": ">=4" } }, - "node_modules/dir-glob": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", - "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", + "node_modules/har-validator": { + "version": "5.1.5", + "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz", + "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", + "deprecated": "this library is no longer supported", "dev": true, "dependencies": { - "path-type": "^4.0.0" + "ajv": "^6.12.3", + "har-schema": "^2.0.0" }, "engines": { - "node": ">=8" + "node": ">=6" } }, - "node_modules/doctrine": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", - "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "node_modules/has-ansi": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-4.0.1.tgz", + "integrity": "sha512-Qr4RtTm30xvEdqUXbSBVWDu+PrTokJOwe/FU+VdfJPk+MXAPoeOzKpRyrDTnZIJwAkQ4oBLTU53nu0HrkF/Z2A==", "dev": true, "dependencies": { - "esutils": "^2.0.2" + "ansi-regex": "^4.1.0" }, "engines": { - "node": ">=6.0.0" + "node": ">=8" } }, - "node_modules/dom-serialize": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/dom-serialize/-/dom-serialize-2.2.1.tgz", - "integrity": "sha1-ViromZ9Evl6jB29UGdzVnrQ6yVs=", - "dev": true, - "dependencies": { - "custom-event": "~1.0.0", - "ent": "~2.2.0", - "extend": "^3.0.0", - "void-elements": "^2.0.0" + "node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "engines": { + "node": ">=8" } }, - "node_modules/duration": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/duration/-/duration-0.2.2.tgz", - "integrity": "sha512-06kgtea+bGreF5eKYgI/36A6pLXggY7oR4p1pq4SmdFBn1ReOL5D8RhG64VrqfTTKNucqqtBAwEj8aB88mcqrg==", + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", "dev": true, "dependencies": { - "d": "1", - "es5-ext": "~0.10.46" + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/durations": { - "version": "3.4.2", - "resolved": "https://registry.npmjs.org/durations/-/durations-3.4.2.tgz", - "integrity": "sha512-V/lf7y33dGaypZZetVI1eu7BmvkbC4dItq12OElLRpKuaU5JxQstV2zHwLv8P7cNbQ+KL1WD80zMCTx5dNC4dg==", + "node_modules/has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", "dev": true, "engines": { - "node": ">=0.10.0" + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/ecc-jsbn": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", - "integrity": "sha1-OoOpBOVDUyh4dMVkt1SThoSamMk=", + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", "dev": true, - "dependencies": { - "jsbn": "~0.1.0", - "safer-buffer": "^2.1.0" + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/ee-first": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=", - "dev": true - }, - "node_modules/encodeurl": { + "node_modules/has-tostringtag": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", - "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", "dev": true, + "dependencies": { + "has-symbols": "^1.0.3" + }, "engines": { - "node": ">= 0.8" + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/engine.io": { - "version": "3.5.0", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-3.5.0.tgz", - "integrity": "sha512-21HlvPUKaitDGE4GXNtQ7PLP0Sz4aWLddMPw2VTyFz1FVZqu/kZsJUO8WNpKuE/OCL7nkfRaOui2ZCJloGznGA==", + "node_modules/hasha": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/hasha/-/hasha-2.2.0.tgz", + "integrity": "sha512-jZ38TU/EBiGKrmyTNNZgnvCZHNowiRI4+w/I9noMlekHTZH3KyGgvJLmhSgykeAQ9j2SYPDosM0Bg3wHfzibAQ==", "dev": true, "dependencies": { - "accepts": "~1.3.4", - "base64id": "2.0.0", - "cookie": "~0.4.1", - "debug": "~4.1.0", - "engine.io-parser": "~2.2.0", - "ws": "~7.4.2" + "is-stream": "^1.0.1", + "pinkie-promise": "^2.0.0" }, "engines": { - "node": ">=8.0.0" + "node": ">=0.10.0" } }, - "node_modules/engine.io-client": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-3.5.2.tgz", - "integrity": "sha512-QEqIp+gJ/kMHeUun7f5Vv3bteRHppHH/FMBQX/esFj/fuYfjyUKWGMo3VCvIP/V8bE9KcjHmRZrhIz2Z9oNsDA==", + "node_modules/hasha/node_modules/is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==", "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", "dependencies": { - "component-emitter": "~1.3.0", - "component-inherit": "0.0.3", - "debug": "~3.1.0", - "engine.io-parser": "~2.2.0", - "has-cors": "1.1.0", - "indexof": "0.0.1", - "parseqs": "0.0.6", - "parseuri": "0.0.6", - "ws": "~7.4.2", - "xmlhttprequest-ssl": "~1.6.2", - "yeast": "0.1.2" + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" } }, - "node_modules/engine.io-client/node_modules/debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "node_modules/he": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", + "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true, - "dependencies": { - "ms": "2.0.0" + "bin": { + "he": "bin/he" } }, - "node_modules/engine.io-client/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "node_modules/hermes-estree": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.15.0.tgz", + "integrity": "sha512-lLYvAd+6BnOqWdnNbP/Q8xfl8LOGw4wVjfrNd9Gt8eoFzhNBRVD95n4l2ksfMVOoxuVyegs85g83KS9QOsxbVQ==", + "peer": true }, - "node_modules/engine.io-parser": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-2.2.1.tgz", - "integrity": "sha512-x+dN/fBH8Ro8TFwJ+rkB2AmuVw9Yu2mockR/p3W8f8YtExwFgDvBDi0GWyb4ZLkpahtDGZgtr3zLovanJghPqg==", - "dev": true, + "node_modules/hermes-parser": { + "version": "0.15.0", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.15.0.tgz", + "integrity": "sha512-Q1uks5rjZlE9RjMMjSUCkGrEIPI5pKJILeCtK1VmTj7U4pf3wVPoo+cxfu+s4cBAPy2JzikIIdCZgBoR6x7U1Q==", + "peer": true, "dependencies": { - "after": "0.8.2", - "arraybuffer.slice": "~0.0.7", - "base64-arraybuffer": "0.1.4", - "blob": "0.0.5", - "has-binary2": "~1.0.2" + "hermes-estree": "0.15.0" } }, - "node_modules/engine.io/node_modules/debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "deprecated": "Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)", - "dev": true, + "node_modules/hermes-profile-transformer": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/hermes-profile-transformer/-/hermes-profile-transformer-0.0.6.tgz", + "integrity": "sha512-cnN7bQUm65UWOy6cbGcCcZ3rpwW8Q/j4OP5aWRhEry4Z2t2aR1cjrbp0BS+KiBN0smvP1caBgAuxutvyvJILzQ==", + "peer": true, "dependencies": { - "ms": "^2.1.1" + "source-map": "^0.7.3" + }, + "engines": { + "node": ">=8" } }, - "node_modules/ent": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/ent/-/ent-2.2.0.tgz", - "integrity": "sha1-6WQhkyWiHQX0RGai9obtbOX13R0=", + "node_modules/hermes-profile-transformer/node_modules/source-map": { + "version": "0.7.4", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", + "integrity": "sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==", + "peer": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/hosted-git-info": { + "version": "2.8.9", + "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", + "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", "dev": true }, - "node_modules/error-stack-parser": { - "version": "2.1.4", - "resolved": "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-2.1.4.tgz", - "integrity": "sha512-Sk5V6wVazPhq5MhpO+AUxJn5x7XSXGl1R93Vn7i+zS15KDVxQijejNCrz8340/2bgLBjR9GtEG8ZVKONDjcqGQ==", - "dev": true, + "node_modules/http-errors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", + "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", "dependencies": { - "stackframe": "^1.3.4" + "depd": "2.0.0", + "inherits": "2.0.4", + "setprototypeof": "1.2.0", + "statuses": "2.0.1", + "toidentifier": "1.0.1" + }, + "engines": { + "node": ">= 0.8" } }, - "node_modules/es5-ext": { - "version": "0.10.53", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.53.tgz", - "integrity": "sha512-Xs2Stw6NiNHWypzRTY1MtaG/uJlwCk8kH81920ma8mvN8Xq1gsfhZvpkImLQArw8AHnv8MT2I45J3c0R8slE+Q==", + "node_modules/http-errors/node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/http-proxy": { + "version": "1.18.1", + "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", + "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", "dev": true, "dependencies": { - "es6-iterator": "~2.0.3", - "es6-symbol": "~3.1.3", - "next-tick": "~1.0.0" + "eventemitter3": "^4.0.0", + "follow-redirects": "^1.0.0", + "requires-port": "^1.0.0" + }, + "engines": { + "node": ">=8.0.0" } }, - "node_modules/es6-iterator": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", - "integrity": "sha1-p96IkUGgWpSwhUQDstCg+/qY87c=", + "node_modules/http-proxy-agent": { + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", + "integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==", + "dependencies": { + "agent-base": "^7.1.0", + "debug": "^4.3.4" + }, + "engines": { + "node": ">= 14" + } + }, + "node_modules/http-signature": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", + "integrity": "sha512-CAbnr6Rz4CYQkLYUtSNXxQPUH2gK8f3iWexVlsnMeD+GjlsQ0Xsy1cOX+mN3dtxYomRy21CiOzU8Uhw6OwncEQ==", "dev": true, "dependencies": { - "d": "1", - "es5-ext": "^0.10.35", - "es6-symbol": "^3.1.1" + "assert-plus": "^1.0.0", + "jsprim": "^1.2.2", + "sshpk": "^1.7.0" + }, + "engines": { + "node": ">=0.8", + "npm": ">=1.3.7" } }, - "node_modules/es6-promise": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", - "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", - "dev": true + "node_modules/https-proxy-agent": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz", + "integrity": "sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==", + "dependencies": { + "agent-base": "^7.0.2", + "debug": "4" + }, + "engines": { + "node": ">= 14" + } }, - "node_modules/es6-shim": { - "version": "0.35.6", - "resolved": "https://registry.npmjs.org/es6-shim/-/es6-shim-0.35.6.tgz", - "integrity": "sha512-EmTr31wppcaIAgblChZiuN/l9Y7DPyw8Xtbg7fIVngn6zMW+IEBJDJngeKC3x6wr0V/vcA2wqeFnaw1bFJbDdA==", - "dev": true + "node_modules/human-signals": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", + "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "peer": true, + "engines": { + "node": ">=10.17.0" + } }, - "node_modules/es6-symbol": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.3.tgz", - "integrity": "sha512-NJ6Yn3FuDinBaBRWl/q5X/s4koRHBrgKAu+yGI6JCBeiu3qrcbJhwT2GeR/EXVfylRk8dpQVJoLEFhK+Mu31NA==", - "dev": true, + "node_modules/humanize-ms": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", + "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", "dependencies": { - "d": "^1.0.1", - "ext": "^1.1.2" + "ms": "^2.0.0" } }, - "node_modules/escalade": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", - "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==", + "node_modules/iconv-lite": { + "version": "0.4.24", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", + "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "dev": true, + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3" + }, "engines": { - "node": ">=6" + "node": ">=0.10.0" } }, - "node_modules/escape-html": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=", - "dev": true + "node_modules/ieee754": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", + "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] }, - "node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "node_modules/ignore": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", + "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", "dev": true, "engines": { - "node": ">=0.8.0" + "node": ">= 4" } }, - "node_modules/escodegen": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.1.0.tgz", - "integrity": "sha512-2NlIDTwUWJN0mRPQOdtQBzbUHvdGY2P1VXSyU83Q3xKxM7WHX2Ql8dKq782Q9TgQUNOLEzEYu9bzLNj1q88I5w==", + "node_modules/image-size": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/image-size/-/image-size-1.1.1.tgz", + "integrity": "sha512-541xKlUw6jr/6gGuk92F+mYM5zaFAc5ahphvkqvNe2bQ6gVBkd6bfrmVJ2t4KDAfikAYZyIqTnktX3i6/aQDrQ==", + "peer": true, "dependencies": { - "esprima": "^4.0.1", - "estraverse": "^5.2.0", - "esutils": "^2.0.2" + "queue": "6.0.2" }, "bin": { - "escodegen": "bin/escodegen.js", - "esgenerate": "bin/esgenerate.js" + "image-size": "bin/image-size.js" }, "engines": { - "node": ">=6.0" - }, - "optionalDependencies": { - "source-map": "~0.6.1" + "node": ">=16.x" } }, - "node_modules/eslint": { - "version": "8.37.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.37.0.tgz", - "integrity": "sha512-NU3Ps9nI05GUoVMxcZx1J8CNR6xOvUT4jAUMH5+z8lpp3aEdPVCImKw6PWG4PY+Vfkpr+jvMpxs/qoE7wq0sPw==", + "node_modules/import-fresh": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", "dev": true, "dependencies": { - "@eslint-community/eslint-utils": "^4.2.0", - "@eslint-community/regexpp": "^4.4.0", - "@eslint/eslintrc": "^2.0.2", - "@eslint/js": "8.37.0", - "@humanwhocodes/config-array": "^0.11.8", - "@humanwhocodes/module-importer": "^1.0.1", - "@nodelib/fs.walk": "^1.2.8", - "ajv": "^6.10.0", - "chalk": "^4.0.0", - "cross-spawn": "^7.0.2", - "debug": "^4.3.2", - "doctrine": "^3.0.0", - "escape-string-regexp": "^4.0.0", - "eslint-scope": "^7.1.1", - "eslint-visitor-keys": "^3.4.0", - "espree": "^9.5.1", - "esquery": "^1.4.2", - "esutils": "^2.0.2", - "fast-deep-equal": "^3.1.3", - "file-entry-cache": "^6.0.1", - "find-up": "^5.0.0", - "glob-parent": "^6.0.2", - "globals": "^13.19.0", - "grapheme-splitter": "^1.0.4", - "ignore": "^5.2.0", - "import-fresh": "^3.0.0", - "imurmurhash": "^0.1.4", - "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", - "js-sdsl": "^4.1.4", - "js-yaml": "^4.1.0", - "json-stable-stringify-without-jsonify": "^1.0.1", - "levn": "^0.4.1", - "lodash.merge": "^4.6.2", - "minimatch": "^3.1.2", - "natural-compare": "^1.4.0", - "optionator": "^0.9.1", - "strip-ansi": "^6.0.1", - "strip-json-comments": "^3.1.0", - "text-table": "^0.2.0" - }, - "bin": { - "eslint": "bin/eslint.js" + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": ">=6" }, "funding": { - "url": "https://opencollective.com/eslint" + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/eslint-plugin-mocha": { - "version": "10.0.3", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.0.3.tgz", - "integrity": "sha512-9mM7PZGxfejpjey+MrG0Cu3Lc8MyA5E2s7eUCdHXgS4SY/H9zLuwa7wVAjnEaoDjbBilA+0bPEB+iMO7lBUPcg==", - "dev": true, - "dependencies": { - "eslint-utils": "^3.0.0", - "ramda": "^0.27.1" - }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "eslint": ">=7.0.0" + "node": ">=0.8.19" } }, - "node_modules/eslint-plugin-prettier": { + "node_modules/indent-string": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-4.0.0.tgz", - "integrity": "sha512-98MqmCJ7vJodoQK359bqQWaxOE0CS8paAz/GgjaZLyex4TTk3g9HugoO89EqWCrFiOqn9EVvcoo7gZzONCWVwQ==", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", "dev": true, - "dependencies": { - "prettier-linter-helpers": "^1.0.0" - }, "engines": { - "node": ">=6.0.0" - }, - "peerDependencies": { - "eslint": ">=7.28.0", - "prettier": ">=2.0.0" - }, - "peerDependenciesMeta": { - "eslint-config-prettier": { - "optional": true - } + "node": ">=8" } }, - "node_modules/eslint-scope": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", - "integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/ini": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ini/-/ini-2.0.0.tgz", + "integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==", "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/invariant": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", + "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", + "peer": true, "dependencies": { - "esrecurse": "^4.3.0", - "estraverse": "^5.2.0" + "loose-envify": "^1.0.0" + } + }, + "node_modules/ip-address": { + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz", + "integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==", + "dependencies": { + "jsbn": "1.1.0", + "sprintf-js": "^1.1.3" }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": ">= 12" } }, - "node_modules/eslint-utils": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", - "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", + "node_modules/ip-address/node_modules/sprintf-js": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz", + "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==" + }, + "node_modules/is-arguments": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", + "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", "dev": true, "dependencies": { - "eslint-visitor-keys": "^2.0.0" + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" }, "engines": { - "node": "^10.0.0 || ^12.0.0 || >= 14.0.0" + "node": ">= 0.4" }, "funding": { - "url": "https://github.com/sponsors/mysticatea" - }, - "peerDependencies": { - "eslint": ">=5" + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { + "node_modules/is-arrayish": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", + "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==" + }, + "node_modules/is-binary-path": { "version": "2.1.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", - "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", "dev": true, + "dependencies": { + "binary-extensions": "^2.0.0" + }, "engines": { - "node": ">=10" + "node": ">=8" } }, - "node_modules/eslint-visitor-keys": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.0.tgz", - "integrity": "sha512-HPpKPUBQcAsZOsHAFwTtIKcYlCje62XB7SEAcxjtmW6TD1WVpkS6i6/hOVtTZIl4zGj/mBqpFVGvaDneik+VoQ==", + "node_modules/is-builtin-module": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", + "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", "dev": true, + "dependencies": { + "builtin-modules": "^3.3.0" + }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + "node": ">=6" }, "funding": { - "url": "https://opencollective.com/eslint" + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/eslint/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, + "node_modules/is-core-module": { + "version": "2.13.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", + "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" + "hasown": "^2.0.0" }, "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/eslint/node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, - "node_modules/eslint/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "node_modules/is-date-object": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", + "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", "dev": true, "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "has-tostringtag": "^1.0.0" }, "engines": { - "node": ">=10" + "node": ">= 0.4" }, "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/eslint/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "dependencies": { - "color-name": "~1.1.4" - }, + "node_modules/is-directory": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz", + "integrity": "sha512-yVChGzahRFvbkscn2MlwGismPO12i9+znNruC5gVEntG3qu0xQMzsGg/JFbrsqDOHtHFPci+V5aP5T9I+yeKqw==", + "peer": true, "engines": { - "node": ">=7.0.0" + "node": ">=0.10.0" } }, - "node_modules/eslint/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "node_modules/eslint/node_modules/escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true, + "node_modules/is-docker": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", + "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", + "peer": true, + "bin": { + "is-docker": "cli.js" + }, "engines": { - "node": ">=10" + "node": ">=8" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/eslint/node_modules/glob-parent": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", - "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true, - "dependencies": { - "is-glob": "^4.0.3" - }, "engines": { - "node": ">=10.13.0" + "node": ">=0.10.0" } }, - "node_modules/eslint/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", "engines": { "node": ">=8" } }, - "node_modules/eslint/node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "node_modules/is-generator": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/is-generator/-/is-generator-1.0.3.tgz", + "integrity": "sha512-G56jBpbJeg7ds83HW1LuShNs8J73Fv3CPz/bmROHOHlnKkN8sWb9ujiagjmxxMUywftgq48HlBZELKKqFLk0oA==", "dev": true, - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } + "peer": true }, - "node_modules/eslint/node_modules/levn": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", - "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, "dependencies": { - "prelude-ls": "^1.2.1", - "type-check": "~0.4.0" + "is-extglob": "^2.1.1" }, "engines": { - "node": ">= 0.8.0" + "node": ">=0.10.0" } }, - "node_modules/eslint/node_modules/optionator": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", - "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "node_modules/is-installed-globally": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.4.0.tgz", + "integrity": "sha512-iwGqO3J21aaSkC7jWnHP/difazwS7SFeIqxv6wEtLU8Y5KlzFTjyqcSIT0d8s4+dDhKytsk9PJZ2BkS5eZwQRQ==", "dev": true, "dependencies": { - "deep-is": "^0.1.3", - "fast-levenshtein": "^2.0.6", - "levn": "^0.4.1", - "prelude-ls": "^1.2.1", - "type-check": "^0.4.0", - "word-wrap": "^1.2.3" + "global-dirs": "^3.0.0", + "is-path-inside": "^3.0.2" }, "engines": { - "node": ">= 0.8.0" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/eslint/node_modules/prelude-ls": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", - "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", - "dev": true, + "node_modules/is-interactive": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz", + "integrity": "sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==", + "peer": true, "engines": { - "node": ">= 0.8.0" + "node": ">=8" } }, - "node_modules/eslint/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, - "dependencies": { - "has-flag": "^4.0.0" - }, + "node_modules/is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", + "dev": true + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", "engines": { - "node": ">=8" + "node": ">=0.12.0" } }, - "node_modules/eslint/node_modules/type-check": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", - "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "node_modules/is-path-inside": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", + "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", "dev": true, - "dependencies": { - "prelude-ls": "^1.2.1" - }, "engines": { - "node": ">= 0.8.0" + "node": ">=8" } }, - "node_modules/espree": { - "version": "9.5.1", - "resolved": "https://registry.npmjs.org/espree/-/espree-9.5.1.tgz", - "integrity": "sha512-5yxtHSZXRSW5pvv3hAlXM5+/Oswi1AUFqBmbibKb5s6bp3rGIDkyXU6xCoyuuLhijr4SFwPrXRoZjz0AZDN9tg==", + "node_modules/is-plain-obj": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", + "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", "dev": true, - "dependencies": { - "acorn": "^8.8.0", - "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^3.4.0" - }, "engines": { - "node": "^12.22.0 || ^14.17.0 || >=16.0.0" - }, - "funding": { - "url": "https://opencollective.com/eslint" + "node": ">=8" } }, - "node_modules/esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", - "bin": { - "esparse": "bin/esparse.js", - "esvalidate": "bin/esvalidate.js" + "node_modules/is-plain-object": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", + "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "peer": true, + "dependencies": { + "isobject": "^3.0.1" }, "engines": { - "node": ">=4" + "node": ">=0.10.0" } }, - "node_modules/esquery": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", - "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", + "node_modules/is-reference": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", + "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", "dev": true, "dependencies": { - "estraverse": "^5.1.0" - }, - "engines": { - "node": ">=0.10" + "@types/estree": "*" } }, - "node_modules/esrecurse": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", - "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "node_modules/is-regex": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", + "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", "dev": true, "dependencies": { - "estraverse": "^5.2.0" + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" }, "engines": { - "node": ">=4.0" + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/estraverse": { - "version": "5.3.0", - "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", - "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "node_modules/is-stream": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", + "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", "engines": { - "node": ">=4.0" + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/estree-walker": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", - "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", + "node_modules/is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==", "dev": true }, - "node_modules/esutils": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", - "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "node_modules/is-unicode-supported": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", + "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", "engines": { - "node": ">=0.10.0" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/eventemitter3": { - "version": "4.0.7", - "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", - "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", - "dev": true - }, - "node_modules/expect": { - "version": "27.5.1", - "resolved": "https://registry.npmjs.org/expect/-/expect-27.5.1.tgz", - "integrity": "sha512-E1q5hSUG2AmYQwQJ041nvgpkODHQvB+RKlB4IYdru6uJsyFTRyZAP463M+1lINorwbqAmUggi6+WwkD8lCS/Dw==", - "dev": true, + "node_modules/is-wsl": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", + "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "peer": true, "dependencies": { - "@jest/types": "^27.5.1", - "jest-get-type": "^27.5.1", - "jest-matcher-utils": "^27.5.1", - "jest-message-util": "^27.5.1" + "is-docker": "^2.0.0" }, "engines": { - "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + "node": ">=8" } }, - "node_modules/ext": { - "version": "1.6.0", - "resolved": "https://registry.npmjs.org/ext/-/ext-1.6.0.tgz", - "integrity": "sha512-sdBImtzkq2HpkdRLtlLWDa6w4DX22ijZLKx8BMPUuKe1c5lbN6xwQDQCxSfxBQnHZ13ls/FH0MQZx/q/gr6FQg==", + "node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" + }, + "node_modules/isbinaryfile": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.10.tgz", + "integrity": "sha512-iHrqe5shvBUcFbmZq9zOQHBoeOhZJu6RQGrDpBgenUm/Am+F3JM2MgQj+rK3Z601fzrL5gLZWtAPH2OBaSVcyw==", "dev": true, - "dependencies": { - "type": "^2.5.0" + "engines": { + "node": ">= 8.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/gjtorikian/" } }, - "node_modules/ext/node_modules/type": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/type/-/type-2.6.0.tgz", - "integrity": "sha512-eiDBDOmkih5pMbo9OqsqPRGMljLodLcwd5XD5JbtNB0o89xZAwynY9EdCDsJU7LtcVCClu9DvM7/0Ep1hYX3EQ==", - "dev": true + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" }, - "node_modules/extend": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "node_modules/isobject": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", + "integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==", + "peer": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/isstream": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", + "integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==", "dev": true }, - "node_modules/extract-zip": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz", - "integrity": "sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==", + "node_modules/jackspeak": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", + "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", "dev": true, "dependencies": { - "concat-stream": "^1.6.2", - "debug": "^2.6.9", - "mkdirp": "^0.5.4", - "yauzl": "^2.10.0" + "@isaacs/cliui": "^8.0.2" }, - "bin": { - "extract-zip": "cli.js" + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + }, + "optionalDependencies": { + "@pkgjs/parseargs": "^0.11.0" } }, - "node_modules/extract-zip/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "node_modules/jest-diff": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.7.0.tgz", + "integrity": "sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==", "dev": true, "dependencies": { - "ms": "2.0.0" + "chalk": "^4.0.0", + "diff-sequences": "^29.6.3", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.7.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/extract-zip/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true - }, - "node_modules/extsprintf": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha1-lpGEQOMEGnpBT4xS48V06zw+HgU=", - "dev": true, - "engines": [ - "node >=0.6.0" - ] - }, - "node_modules/fast-deep-equal": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true - }, - "node_modules/fast-diff": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.2.0.tgz", - "integrity": "sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==", - "dev": true - }, - "node_modules/fast-glob": { - "version": "3.2.11", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.2.11.tgz", - "integrity": "sha512-xrO3+1bxSo3ZVHAnqzyuewYT6aMFHRAd4Kcs92MAonjwQZLsK9d0SF1IyQ3k5PoirxTW0Oe/RqFgMQ6TcNE5Ew==", - "dev": true, + "node_modules/jest-environment-node": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-29.7.0.tgz", + "integrity": "sha512-DOSwCRqXirTOyheM+4d5YZOrWcdu0LNZ87ewUoywbcb2XR4wKgqiG8vNeYwhjFMbEkfju7wx2GYH0P2gevGvFw==", + "peer": true, "dependencies": { - "@nodelib/fs.stat": "^2.0.2", - "@nodelib/fs.walk": "^1.2.3", - "glob-parent": "^5.1.2", - "merge2": "^1.3.0", - "micromatch": "^4.0.4" + "@jest/environment": "^29.7.0", + "@jest/fake-timers": "^29.7.0", + "@jest/types": "^29.6.3", + "@types/node": "*", + "jest-mock": "^29.7.0", + "jest-util": "^29.7.0" }, "engines": { - "node": ">=8.6.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/fast-json-stable-stringify": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true - }, - "node_modules/fast-levenshtein": { - "version": "2.0.6", - "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", - "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=", - "dev": true - }, - "node_modules/fast-safe-stringify": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.1.1.tgz", - "integrity": "sha512-W+KJc2dmILlPplD/H4K9l9LcAHAfPtP6BY84uVLXQ6Evcz9Lcg33Y2z1IVblT6xdY54PXYVHEv+0Wpq8Io6zkA==" + "node_modules/jest-get-type": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.6.3.tgz", + "integrity": "sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw==", + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } }, - "node_modules/fastq": { - "version": "1.13.0", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.13.0.tgz", - "integrity": "sha512-YpkpUnK8od0o1hmeSc7UUs/eB/vIPWJYjKck2QKIzAf71Vm1AAQ3EbuZB3g2JIy+pg+ERD0vqI79KyZiB2e2Nw==", + "node_modules/jest-matcher-utils": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz", + "integrity": "sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g==", "dev": true, "dependencies": { - "reusify": "^1.0.4" + "chalk": "^4.0.0", + "jest-diff": "^29.7.0", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.7.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/fd-slicer": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", - "integrity": "sha1-JcfInLH5B3+IkbvmHY85Dq4lbx4=", - "dev": true, + "node_modules/jest-message-util": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.7.0.tgz", + "integrity": "sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w==", "dependencies": { - "pend": "~1.2.0" + "@babel/code-frame": "^7.12.13", + "@jest/types": "^29.6.3", + "@types/stack-utils": "^2.0.0", + "chalk": "^4.0.0", + "graceful-fs": "^4.2.9", + "micromatch": "^4.0.4", + "pretty-format": "^29.7.0", + "slash": "^3.0.0", + "stack-utils": "^2.0.3" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/figures": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", - "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", - "dev": true, + "node_modules/jest-mock": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.7.0.tgz", + "integrity": "sha512-ITOMZn+UkYS4ZFh83xYAOzWStloNzJFO2s8DWrE4lhtGD+AorgnbkiKERe4wQVBydIGPx059g6riW5Btp6Llnw==", + "peer": true, "dependencies": { - "escape-string-regexp": "^1.0.5" + "@jest/types": "^29.6.3", + "@types/node": "*", + "jest-util": "^29.7.0" }, "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/file-entry-cache": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", - "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", - "dev": true, + "node_modules/jest-util": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", + "integrity": "sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==", "dependencies": { - "flat-cache": "^3.0.4" + "@jest/types": "^29.6.3", + "@types/node": "*", + "chalk": "^4.0.0", + "ci-info": "^3.2.0", + "graceful-fs": "^4.2.9", + "picomatch": "^2.2.3" }, "engines": { - "node": "^10.12.0 || >=12.0.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", - "dev": true, + "node_modules/jest-validate": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-29.7.0.tgz", + "integrity": "sha512-ZB7wHqaRGVw/9hST/OuFUReG7M8vKeq0/J2egIGLdvjHCmYqGARhzXmtgi+gVeZ5uXFF219aOc3Ls2yLg27tkw==", + "peer": true, "dependencies": { - "to-regex-range": "^5.0.1" + "@jest/types": "^29.6.3", + "camelcase": "^6.2.0", + "chalk": "^4.0.0", + "jest-get-type": "^29.6.3", + "leven": "^3.1.0", + "pretty-format": "^29.7.0" }, "engines": { - "node": ">=8" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/finalhandler": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", - "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", - "dev": true, + "node_modules/jest-worker": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.7.0.tgz", + "integrity": "sha512-eIz2msL/EzL9UFTFFx7jBTkeZfku0yUAyZZZmJ93H2TYEiroIx2PQjEXcwYtYl8zXCxb+PAmA2hLIt/6ZEkPHw==", + "peer": true, "dependencies": { - "debug": "2.6.9", - "encodeurl": "~1.0.2", - "escape-html": "~1.0.3", - "on-finished": "~2.3.0", - "parseurl": "~1.3.3", - "statuses": "~1.5.0", - "unpipe": "~1.0.0" + "@types/node": "*", + "jest-util": "^29.7.0", + "merge-stream": "^2.0.0", + "supports-color": "^8.0.0" }, "engines": { - "node": ">= 0.8" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/finalhandler/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, + "node_modules/joi": { + "version": "17.12.3", + "resolved": "https://registry.npmjs.org/joi/-/joi-17.12.3.tgz", + "integrity": "sha512-2RRziagf555owrm9IRVtdKynOBeITiDpuZqIpgwqXShPncPKNiRQoiGsl/T8SQdq+8ugRzH2LqY67irr2y/d+g==", + "peer": true, "dependencies": { - "ms": "2.0.0" + "@hapi/hoek": "^9.3.0", + "@hapi/topo": "^5.1.0", + "@sideway/address": "^4.1.5", + "@sideway/formula": "^3.0.1", + "@sideway/pinpoint": "^2.0.0" } }, - "node_modules/finalhandler/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "node_modules/js-tokens": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, - "node_modules/find-up": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", - "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", - "dev": true, + "node_modules/js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", "dependencies": { - "locate-path": "^6.0.0", - "path-exists": "^4.0.0" + "argparse": "^1.0.7", + "esprima": "^4.0.0" }, - "engines": { - "node": ">=10" + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, + "node_modules/jsbn": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==" + }, + "node_modules/jsc-android": { + "version": "250231.0.0", + "resolved": "https://registry.npmjs.org/jsc-android/-/jsc-android-250231.0.0.tgz", + "integrity": "sha512-rS46PvsjYmdmuz1OAWXY/1kCYG7pnf1TBqeTiOJr1iDz7s5DLxxC9n/ZMknLDxzYzNVfI7R95MH10emSSG1Wuw==", + "peer": true + }, + "node_modules/jsc-safe-url": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/jsc-safe-url/-/jsc-safe-url-0.2.4.tgz", + "integrity": "sha512-0wM3YBWtYePOjfyXQH5MWQ8H7sdk5EXSwZvmSLKk2RboVQ2Bu239jycHDz5J/8Blf3K0Qnoy2b6xD+z10MFB+Q==", + "peer": true + }, + "node_modules/jscodeshift": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/jscodeshift/-/jscodeshift-0.14.0.tgz", + "integrity": "sha512-7eCC1knD7bLUPuSCwXsMZUH51O8jIcoVyKtI6P0XM0IVzlGjckPy3FIwQlorzbN0Sg79oK+RlohN32Mqf/lrYA==", + "peer": true, + "dependencies": { + "@babel/core": "^7.13.16", + "@babel/parser": "^7.13.16", + "@babel/plugin-proposal-class-properties": "^7.13.0", + "@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8", + "@babel/plugin-proposal-optional-chaining": "^7.13.12", + "@babel/plugin-transform-modules-commonjs": "^7.13.8", + "@babel/preset-flow": "^7.13.13", + "@babel/preset-typescript": "^7.13.0", + "@babel/register": "^7.13.16", + "babel-core": "^7.0.0-bridge.0", + "chalk": "^4.1.2", + "flow-parser": "0.*", + "graceful-fs": "^4.2.4", + "micromatch": "^4.0.4", + "neo-async": "^2.5.0", + "node-dir": "^0.1.17", + "recast": "^0.21.0", + "temp": "^0.8.4", + "write-file-atomic": "^2.3.0" }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "bin": { + "jscodeshift": "bin/jscodeshift.js" + }, + "peerDependencies": { + "@babel/preset-env": "^7.1.6" } }, - "node_modules/flat": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", - "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", + "node_modules/jsesc": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", + "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "peer": true, + "bin": { + "jsesc": "bin/jsesc" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/json-buffer": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", + "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", + "dev": true + }, + "node_modules/json-parse-better-errors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", + "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", + "peer": true + }, + "node_modules/json-parse-even-better-errors": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", + "dev": true + }, + "node_modules/json-schema": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", + "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", + "dev": true + }, + "node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true + }, + "node_modules/json-stringify-safe": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", + "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==", + "dev": true + }, + "node_modules/json5": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", "dev": true, + "optional": true, + "dependencies": { + "minimist": "^1.2.0" + }, "bin": { - "flat": "cli.js" + "json5": "lib/cli.js" } }, - "node_modules/flat-cache": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", - "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", + "node_modules/jsonfile": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", + "integrity": "sha512-PKllAqbgLgxHaj8TElYymKCAgrASebJrWpTnEkOaTowt23VKXXN0sUeriJ+eh7y6ufb/CC5ap11pz71/cM0hUw==", + "dev": true, + "optionalDependencies": { + "graceful-fs": "^4.1.6" + } + }, + "node_modules/jsprim": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", + "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", "dev": true, "dependencies": { - "flatted": "^3.1.0", - "rimraf": "^3.0.2" + "assert-plus": "1.0.0", + "extsprintf": "1.3.0", + "json-schema": "0.4.0", + "verror": "1.10.0" }, "engines": { - "node": "^10.12.0 || >=12.0.0" + "node": ">=0.6.0" } }, - "node_modules/flatted": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.5.tgz", - "integrity": "sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==", + "node_modules/jsprim/node_modules/core-util-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", + "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", "dev": true }, - "node_modules/follow-redirects": { - "version": "1.15.4", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.4.tgz", - "integrity": "sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==", + "node_modules/jsprim/node_modules/verror": { + "version": "1.10.0", + "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", + "integrity": "sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==", "dev": true, - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } + "engines": [ + "node >=0.6.0" ], - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } + "dependencies": { + "assert-plus": "^1.0.0", + "core-util-is": "1.0.2", + "extsprintf": "^1.2.0" } }, - "node_modules/forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha1-+8cfDEGt6zf5bFd60e1C2P2sypE=", + "node_modules/just-extend": { + "version": "4.2.1", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", + "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", + "dev": true + }, + "node_modules/karma": { + "version": "6.4.3", + "resolved": "https://registry.npmjs.org/karma/-/karma-6.4.3.tgz", + "integrity": "sha512-LuucC/RE92tJ8mlCwqEoRWXP38UMAqpnq98vktmS9SznSoUPPUJQbc91dHcxcunROvfQjdORVA/YFviH+Xci9Q==", "dev": true, + "dependencies": { + "@colors/colors": "1.5.0", + "body-parser": "^1.19.0", + "braces": "^3.0.2", + "chokidar": "^3.5.1", + "connect": "^3.7.0", + "di": "^0.0.1", + "dom-serialize": "^2.2.1", + "glob": "^7.1.7", + "graceful-fs": "^4.2.6", + "http-proxy": "^1.18.1", + "isbinaryfile": "^4.0.8", + "lodash": "^4.17.21", + "log4js": "^6.4.1", + "mime": "^2.5.2", + "minimatch": "^3.0.4", + "mkdirp": "^0.5.5", + "qjobs": "^1.2.0", + "range-parser": "^1.2.1", + "rimraf": "^3.0.2", + "socket.io": "^4.7.2", + "source-map": "^0.6.1", + "tmp": "^0.2.1", + "ua-parser-js": "^0.7.30", + "yargs": "^16.1.1" + }, + "bin": { + "karma": "bin/karma" + }, "engines": { - "node": "*" + "node": ">= 10" + } + }, + "node_modules/karma-chai": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/karma-chai/-/karma-chai-0.1.0.tgz", + "integrity": "sha512-mqKCkHwzPMhgTYca10S90aCEX9+HjVjjrBFAsw36Zj7BlQNbokXXCAe6Ji04VUMsxcY5RLP7YphpfO06XOubdg==", + "dev": true, + "peerDependencies": { + "chai": "*", + "karma": ">=0.10.9" } }, - "node_modules/form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "node_modules/karma-chrome-launcher": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-3.2.0.tgz", + "integrity": "sha512-rE9RkUPI7I9mAxByQWkGJFXfFD6lE4gC5nPuZdobf/QdTEJI6EU4yIay/cfU/xV4ZxlM5JiTv7zWYgA64NpS5Q==", "dev": true, "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 0.12" + "which": "^1.2.1" } }, - "node_modules/formidable": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/formidable/-/formidable-2.1.2.tgz", - "integrity": "sha512-CM3GuJ57US06mlpQ47YcunuUZ9jpm8Vx+P2CGt2j7HpgkKZO/DJYQ0Bobim8G6PFQmK5lOqOOdUXboU+h73A4g==", + "node_modules/karma-chrome-launcher/node_modules/which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", + "dev": true, "dependencies": { - "dezalgo": "^1.0.4", - "hexoid": "^1.0.0", - "once": "^1.4.0", - "qs": "^6.11.0" + "isexe": "^2.0.0" }, - "funding": { - "url": "https://ko-fi.com/tunnckoCore/commissions" + "bin": { + "which": "bin/which" } }, - "node_modules/formidable/node_modules/qs": { - "version": "6.11.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", - "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", + "node_modules/karma-mocha": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-2.0.1.tgz", + "integrity": "sha512-Tzd5HBjm8his2OA4bouAsATYEpZrp9vC7z5E5j4C5Of5Rrs1jY67RAwXNcVmd/Bnk1wgvQRou0zGVLey44G4tQ==", + "dev": true, "dependencies": { - "side-channel": "^1.0.4" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "minimist": "^1.2.3" } }, - "node_modules/fs-extra": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-1.0.0.tgz", - "integrity": "sha1-zTzl9+fLYUWIP8rjGR6Yd/hYeVA=", + "node_modules/karma-phantomjs-launcher": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/karma-phantomjs-launcher/-/karma-phantomjs-launcher-1.0.4.tgz", + "integrity": "sha512-tf4P3plsE7wb5Pqh8GJ6RnElxfI/UM4MtVnjbSIZFpdFJlKnjRzfIx8MLCcSYJBwZ1+qSKFz4uBe3XNoq2t3KA==", + "deprecated": "PhantomJS development have stopped, use puppeteer or similar", "dev": true, "dependencies": { - "graceful-fs": "^4.1.2", - "jsonfile": "^2.1.0", - "klaw": "^1.0.0" + "lodash": "^4.0.1", + "phantomjs-prebuilt": "^2.1.7" + }, + "peerDependencies": { + "karma": ">=0.9" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true - }, - "node_modules/fsevents": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", - "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "node_modules/karma-sinon-chai": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/karma-sinon-chai/-/karma-sinon-chai-2.0.2.tgz", + "integrity": "sha512-SDgh6V0CUd+7ruL1d3yG6lFzmJNGRNQuEuCYXLaorruNP9nwQfA7hpsp4clx4CbOo5Gsajh3qUOT7CrVStUKMw==", "dev": true, - "hasInstallScript": true, - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + "peerDependencies": { + "chai": ">=3.5.0", + "sinon": ">=2.1.0", + "sinon-chai": ">=2.9.0" } }, - "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" - }, - "node_modules/functional-red-black-tree": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", - "integrity": "sha1-GwqzvVU7Kg1jmdKcDj6gslIHgyc=", - "dev": true + "node_modules/karma-sourcemap-loader": { + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/karma-sourcemap-loader/-/karma-sourcemap-loader-0.3.8.tgz", + "integrity": "sha512-zorxyAakYZuBcHRJE+vbrK2o2JXLFWK8VVjiT/6P+ltLBUGUvqTEkUiQ119MGdOrK7mrmxXHZF1/pfT6GgIZ6g==", + "dev": true, + "dependencies": { + "graceful-fs": "^4.1.2" + } }, - "node_modules/get-caller-file": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", - "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "node_modules/karma-spec-reporter": { + "version": "0.0.32", + "resolved": "https://registry.npmjs.org/karma-spec-reporter/-/karma-spec-reporter-0.0.32.tgz", + "integrity": "sha512-ZXsYERZJMTNRR2F3QN11OWF5kgnT/K2dzhM+oY3CDyMrDI3TjIWqYGG7c15rR9wjmy9lvdC+CCshqn3YZqnNrA==", "dev": true, - "engines": { - "node": "6.* || 8.* || >= 10.*" + "dependencies": { + "colors": "^1.1.2" + }, + "peerDependencies": { + "karma": ">=0.9" } }, - "node_modules/get-func-name": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", - "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "node_modules/karma/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, - "engines": { - "node": "*" + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" } }, - "node_modules/get-intrinsic": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", - "integrity": "sha512-kWZrnVM42QCiEA2Ig1bG8zjoIMOgxWwYCEeNdwY6Tv/cOSeGpcoX4pXHfKUxNKVoArnrEr2e9srnAxxGIraS9Q==", + "node_modules/karma/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dev": true, "dependencies": { - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-symbols": "^1.0.1" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" }, "funding": { - "url": "https://github.com/sponsors/ljharb" + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/get-uri": { - "version": "6.0.2", - "resolved": "https://registry.npmjs.org/get-uri/-/get-uri-6.0.2.tgz", - "integrity": "sha512-5KLucCJobh8vBY1K07EFV4+cPZH3mrV9YeAruUseCQKHB58SGjjT2l9/eA9LD082IiuMjSlFJEcdJ27TXvbZNw==", + "node_modules/karma/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, "dependencies": { - "basic-ftp": "^5.0.2", - "data-uri-to-buffer": "^6.0.0", - "debug": "^4.3.4", - "fs-extra": "^8.1.0" + "brace-expansion": "^1.1.7" }, "engines": { - "node": ">= 14" + "node": "*" } }, - "node_modules/get-uri/node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "node_modules/karma/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, "dependencies": { - "ms": "2.1.2" + "minimist": "^1.2.6" }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } + "bin": { + "mkdirp": "bin/cmd.js" } }, - "node_modules/get-uri/node_modules/fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", - "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "node_modules/kew": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz", + "integrity": "sha512-IG6nm0+QtAMdXt9KvbgbGdvY50RSrw+U4sGZg+KlrSKPJEwVE5JVoI3d7RWfSMdBQneRheeAOj3lIjX5VL/9RQ==", + "dev": true + }, + "node_modules/keyv": { + "version": "4.5.4", + "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", + "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", + "dev": true, "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" - }, + "json-buffer": "3.0.1" + } + }, + "node_modules/kind-of": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", + "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", + "peer": true, "engines": { - "node": ">=6 <7 || >=8" + "node": ">=0.10.0" } }, - "node_modules/get-uri/node_modules/jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", - "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", + "node_modules/klaw": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", + "integrity": "sha512-TED5xi9gGQjGpNnvRWknrwAB1eL5GciPfVFOt3Vk1OJCVDQbzuSfrF3hkUQKlsgKrG1F+0t5W0m+Fje1jIt8rw==", + "dev": true, "optionalDependencies": { - "graceful-fs": "^4.1.6" + "graceful-fs": "^4.1.9" } }, - "node_modules/getpass": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "integrity": "sha1-Xv+OPmhNVprkyysSgmBOi6YhSfo=", + "node_modules/kleur": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", + "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", + "peer": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/knuth-shuffle-seeded": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/knuth-shuffle-seeded/-/knuth-shuffle-seeded-1.0.6.tgz", + "integrity": "sha512-9pFH0SplrfyKyojCLxZfMcvkhf5hH0d+UwR9nTVJ/DDQJGuzcXjTwB7TP7sDfehSudlGGaOLblmEWqv04ERVWg==", "dev": true, "dependencies": { - "assert-plus": "^1.0.0" + "seed-random": "~2.2.0" } }, - "node_modules/gherkin": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/gherkin/-/gherkin-5.0.0.tgz", - "integrity": "sha512-Y+93z2Nh+TNIKuKEf+6M0FQrX/z0Yv9C2LFfc5NlcGJWRrrTeI/jOg2374y1FOw6ZYQ3RgJBezRkli7CLDubDA==", - "deprecated": "This package is now published under @cucumber/gherkin", - "dev": true, + "node_modules/leven": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", + "integrity": "sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==", "peer": true, - "bin": { - "gherkin-javascript": "bin/gherkin" + "engines": { + "node": ">=6" } }, - "node_modules/glob": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.0.tgz", - "integrity": "sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==", + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", "dev": true, "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" }, "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "node": ">= 0.8.0" } }, - "node_modules/glob-parent": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", - "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", - "dev": true, + "node_modules/lighthouse-logger": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/lighthouse-logger/-/lighthouse-logger-1.4.2.tgz", + "integrity": "sha512-gPWxznF6TKmUHrOQjlVo2UbaL2EJ71mb2CCeRs/2qBpi4L/g4LUVc9+3lKQ6DTUZwJswfM7ainGrLO1+fOqa2g==", + "peer": true, "dependencies": { - "is-glob": "^4.0.1" - }, - "engines": { - "node": ">= 6" + "debug": "^2.6.9", + "marky": "^1.2.2" } }, - "node_modules/globals": { - "version": "13.20.0", - "resolved": "https://registry.npmjs.org/globals/-/globals-13.20.0.tgz", - "integrity": "sha512-Qg5QtVkCy/kv3FUSlu4ukeZDVf9ee0iXLAUYX13gbR17bnejFTzr4iS9bY7kwCf1NztRNm1t91fjOiyx4CSwPQ==", - "dev": true, + "node_modules/lighthouse-logger/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "peer": true, "dependencies": { - "type-fest": "^0.20.2" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "ms": "2.0.0" } }, - "node_modules/globby": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", - "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", - "dev": true, + "node_modules/lighthouse-logger/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "peer": true + }, + "node_modules/lil-uuid": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/lil-uuid/-/lil-uuid-0.1.1.tgz", + "integrity": "sha512-GhWI8f61tBlMeqULZ1QWhFiiyFIFdPlg//S8Udq1wjq1FJhpFKTfnbduSxAQjueofeUtpr7UvQ/lIK/sKUF8dg==" + }, + "node_modules/lines-and-columns": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", + "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", + "dev": true + }, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", "dependencies": { - "array-union": "^2.1.0", - "dir-glob": "^3.0.1", - "fast-glob": "^3.2.9", - "ignore": "^5.2.0", - "merge2": "^1.4.1", - "slash": "^3.0.0" + "p-locate": "^5.0.0" }, "engines": { "node": ">=10" @@ -3730,578 +9809,698 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/graceful-fs": { - "version": "4.2.9", - "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz", - "integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==" + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true }, - "node_modules/grapheme-splitter": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/grapheme-splitter/-/grapheme-splitter-1.0.4.tgz", - "integrity": "sha512-bzh50DW9kTPM00T8y4o8vQg89Di9oLJVLW/KaOGIXJWP/iqCN6WKYkbNOF04vFLJhwcpYUh9ydh/+5vpOqV4YQ==", + "node_modules/lodash.debounce": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", + "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==", + "peer": true + }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", "dev": true }, - "node_modules/growl": { - "version": "1.10.5", - "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", - "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", - "dev": true, - "engines": { - "node": ">=4.x" - } + "node_modules/lodash.mergewith": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz", + "integrity": "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==", + "dev": true }, - "node_modules/har-schema": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", - "integrity": "sha1-qUwiJOvKwEeCoNkDVSHyRzW37JI=", - "dev": true, - "engines": { - "node": ">=4" - } + "node_modules/lodash.throttle": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz", + "integrity": "sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==", + "peer": true }, - "node_modules/har-validator": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz", - "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", - "deprecated": "this library is no longer supported", - "dev": true, + "node_modules/log-symbols": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", "dependencies": { - "ajv": "^6.12.3", - "har-schema": "^2.0.0" + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" }, "engines": { - "node": ">=6" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/has": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", - "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "node_modules/log4js": { + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/log4js/-/log4js-6.9.1.tgz", + "integrity": "sha512-1somDdy9sChrr9/f4UlzhdaGfDR2c/SaD2a4T7qEkG4jTS57/B3qmnjLYePwQ8cqWnUHZI0iAKxMBpCZICiZ2g==", + "dev": true, "dependencies": { - "function-bind": "^1.1.1" + "date-format": "^4.0.14", + "debug": "^4.3.4", + "flatted": "^3.2.7", + "rfdc": "^1.3.0", + "streamroller": "^3.1.5" }, "engines": { - "node": ">= 0.4.0" + "node": ">=8.0" } }, - "node_modules/has-binary2": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-binary2/-/has-binary2-1.0.3.tgz", - "integrity": "sha512-G1LWKhDSvhGeAQ8mPVQlqNcOB2sJdwATtZKl2pDKKHfpf/rYj24lkinxf69blJbnsvtqqNU+L3SL50vzZhXOnw==", - "dev": true, + "node_modules/logkitty": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/logkitty/-/logkitty-0.7.1.tgz", + "integrity": "sha512-/3ER20CTTbahrCrpYfPn7Xavv9diBROZpoXGVZDWMw4b/X4uuUwAC0ki85tgsdMRONURyIJbcOvS94QsUBYPbQ==", + "peer": true, "dependencies": { - "isarray": "2.0.1" + "ansi-fragments": "^0.2.1", + "dayjs": "^1.8.15", + "yargs": "^15.1.0" + }, + "bin": { + "logkitty": "bin/logkitty.js" } }, - "node_modules/has-binary2/node_modules/isarray": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz", - "integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4=", - "dev": true - }, - "node_modules/has-cors": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz", - "integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=", - "dev": true - }, - "node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", - "dev": true, + "node_modules/logkitty/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "peer": true, + "dependencies": { + "color-convert": "^2.0.1" + }, "engines": { - "node": ">=4" + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/has-symbols": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.2.tgz", - "integrity": "sha512-chXa79rL/UC2KlX17jo3vRGz0azaWEx5tGqZg5pO3NUyEJVB17dMruQlzCCOfUvElghKcm5194+BCRvi2Rv/Gw==", + "node_modules/logkitty/node_modules/camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "peer": true, "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node": ">=6" } }, - "node_modules/has-tostringtag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", - "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", - "dev": true, + "node_modules/logkitty/node_modules/cliui": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", + "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", + "peer": true, "dependencies": { - "has-symbols": "^1.0.2" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^6.2.0" } }, - "node_modules/hasha": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/hasha/-/hasha-2.2.0.tgz", - "integrity": "sha1-eNfL/B5tZjA/55g3NlmEUXsvbuE=", - "dev": true, + "node_modules/logkitty/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "peer": true, "dependencies": { - "is-stream": "^1.0.1", - "pinkie-promise": "^2.0.0" + "color-name": "~1.1.4" }, "engines": { - "node": ">=0.10.0" + "node": ">=7.0.0" } }, - "node_modules/hasha/node_modules/is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=", - "dev": true, - "engines": { - "node": ">=0.10.0" - } + "node_modules/logkitty/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "peer": true }, - "node_modules/he": { + "node_modules/logkitty/node_modules/decamelize": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", - "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", - "dev": true, - "bin": { - "he": "bin/he" + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", + "peer": true, + "engines": { + "node": ">=0.10.0" } }, - "node_modules/hexoid": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/hexoid/-/hexoid-1.0.0.tgz", - "integrity": "sha512-QFLV0taWQOZtvIRIAdBChesmogZrtuXvVWsFHZTk2SU+anspqZ2vMnoLg7IE1+Uk16N19APic1BuF8bC8c2m5g==", + "node_modules/logkitty/node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "peer": true, + "dependencies": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, "engines": { "node": ">=8" } }, - "node_modules/http-errors": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.8.1.tgz", - "integrity": "sha512-Kpk9Sm7NmI+RHhnj6OIWDI1d6fIoFAtFt9RLaTMRlg/8w49juAStsrBgp0Dp4OdxdVbRIeKhtCUvoi/RuAhO4g==", - "dev": true, + "node_modules/logkitty/node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "peer": true, "dependencies": { - "depd": "~1.1.2", - "inherits": "2.0.4", - "setprototypeof": "1.2.0", - "statuses": ">= 1.5.0 < 2", - "toidentifier": "1.0.1" + "p-locate": "^4.1.0" }, "engines": { - "node": ">= 0.6" + "node": ">=8" } }, - "node_modules/http-proxy": { - "version": "1.18.1", - "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", - "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", - "dev": true, + "node_modules/logkitty/node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "peer": true, "dependencies": { - "eventemitter3": "^4.0.0", - "follow-redirects": "^1.0.0", - "requires-port": "^1.0.0" + "p-try": "^2.0.0" }, "engines": { - "node": ">=8.0.0" + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/http-proxy-agent": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.0.tgz", - "integrity": "sha512-+ZT+iBxVUQ1asugqnD6oWoRiS25AkjNfG085dKJGtGxkdwLQrMKU5wJr2bOOFAXzKcTuqq+7fZlTMgG3SRfIYQ==", + "node_modules/logkitty/node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "peer": true, "dependencies": { - "agent-base": "^7.1.0", - "debug": "^4.3.4" + "p-limit": "^2.2.0" }, "engines": { - "node": ">= 14" + "node": ">=8" } }, - "node_modules/http-proxy-agent/node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "node_modules/logkitty/node_modules/wrap-ansi": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", + "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "peer": true, "dependencies": { - "ms": "2.1.2" + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" }, "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } + "node": ">=8" } }, - "node_modules/http-signature": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", - "integrity": "sha1-muzZJRFHcvPZW2WmCruPfBj7rOE=", - "dev": true, + "node_modules/logkitty/node_modules/y18n": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", + "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "peer": true + }, + "node_modules/logkitty/node_modules/yargs": { + "version": "15.4.1", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", + "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "peer": true, "dependencies": { - "assert-plus": "^1.0.0", - "jsprim": "^1.2.2", - "sshpk": "^1.7.0" + "cliui": "^6.0.0", + "decamelize": "^1.2.0", + "find-up": "^4.1.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^4.2.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^18.1.2" }, "engines": { - "node": ">=0.8", - "npm": ">=1.3.7" + "node": ">=8" } }, - "node_modules/https-proxy-agent": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.2.tgz", - "integrity": "sha512-NmLNjm6ucYwtcUmL7JQC1ZQ57LmHP4lT15FQ8D61nak1rO6DH+fz5qNK2Ap5UN4ZapYICE3/0KodcLYSPsPbaA==", + "node_modules/logkitty/node_modules/yargs-parser": { + "version": "18.1.3", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", + "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "peer": true, "dependencies": { - "agent-base": "^7.0.2", - "debug": "4" + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" }, "engines": { - "node": ">= 14" + "node": ">=6" } }, - "node_modules/humanize-ms": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", - "integrity": "sha1-xG4xWaKT9riW2ikxbYtv6Lt5u+0=", + "node_modules/lolex": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/lolex/-/lolex-4.2.0.tgz", + "integrity": "sha512-gKO5uExCXvSm6zbF562EvM+rd1kQDnB9AZBbiQVzf1ZmdDpxUSvpnAaVOP83N/31mRK8Ml8/VE8DMvsAZQ+7wg==", + "dev": true + }, + "node_modules/loose-envify": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", + "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "peer": true, "dependencies": { - "ms": "^2.0.0" + "js-tokens": "^3.0.0 || ^4.0.0" + }, + "bin": { + "loose-envify": "cli.js" } }, - "node_modules/iconv-lite": { - "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "node_modules/loupe": { + "version": "2.3.7", + "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", + "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", "dev": true, "dependencies": { - "safer-buffer": ">= 2.1.2 < 3" - }, - "engines": { - "node": ">=0.10.0" + "get-func-name": "^2.0.1" } }, - "node_modules/ieee754": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", - "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/ignore": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", - "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", + "node_modules/lower-case": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", + "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", "dev": true, - "engines": { - "node": ">= 4" + "dependencies": { + "tslib": "^2.0.3" } }, - "node_modules/import-fresh": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", - "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "node_modules/lru-cache": { + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz", + "integrity": "sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==", "dev": true, - "dependencies": { - "parent-module": "^1.0.0", - "resolve-from": "^4.0.0" - }, "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": "14 || >=16.14" } }, - "node_modules/imurmurhash": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", - "integrity": "sha1-khi5srkoojixPcT7a21XbyMUU+o=", + "node_modules/luxon": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.2.1.tgz", + "integrity": "sha512-QrwPArQCNLAKGO/C+ZIilgIuDnEnKx5QYODdDtbFaxzsbZcc/a7WFq7MhsVYgRlwawLtvOUESTlfJ+hc/USqPg==", "dev": true, "engines": { - "node": ">=0.8.19" + "node": ">=12" } }, - "node_modules/indent-string": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", - "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "node_modules/magic-string": { + "version": "0.30.10", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz", + "integrity": "sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==", "dev": true, + "dependencies": { + "@jridgewell/sourcemap-codec": "^1.4.15" + } + }, + "node_modules/make-dir": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", + "integrity": "sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==", + "peer": true, + "dependencies": { + "pify": "^4.0.1", + "semver": "^5.6.0" + }, "engines": { - "node": ">=8" + "node": ">=6" } }, - "node_modules/indexof": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz", - "integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=", + "node_modules/make-dir/node_modules/semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "peer": true, + "bin": { + "semver": "bin/semver" + } + }, + "node_modules/make-error": { + "version": "1.3.6", + "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", + "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", "dev": true }, - "node_modules/inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, + "node_modules/makeerror": { + "version": "1.0.12", + "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", + "integrity": "sha512-JmqCvUhmt43madlpFzG4BQzG2Z3m6tvQDNKdClZnO3VbIudJYmxsT0FNJMeiB2+JTSlTQTSbU8QdesVmwJcmLg==", + "peer": true, "dependencies": { - "once": "^1.3.0", - "wrappy": "1" + "tmpl": "1.0.5" } }, - "node_modules/inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true + "node_modules/marky": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/marky/-/marky-1.2.5.tgz", + "integrity": "sha512-q9JtQJKjpsVxCRVgQ+WapguSbKC3SQ5HEzFGPAJMStgh3QjCawp00UKv3MTTAArTmGmmPUvllHZoNbZ3gs0I+Q==", + "peer": true + }, + "node_modules/media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", + "dev": true, + "engines": { + "node": ">= 0.6" + } }, - "node_modules/ip": { - "version": "1.1.9", - "resolved": "https://registry.npmjs.org/ip/-/ip-1.1.9.tgz", - "integrity": "sha512-cyRxvOEpNHNtchU3Ln9KC/auJgup87llfQpQ+t5ghoC/UhL16SWzbueiCsdTnWmqAWl7LadfuwhlqmtOaqMHdQ==" + "node_modules/memoize-one": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz", + "integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==", + "peer": true }, - "node_modules/is-arguments": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", - "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "node_modules/merge-stream": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", + "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", + "peer": true + }, + "node_modules/merge2": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", + "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", "dev": true, + "engines": { + "node": ">= 8" + } + }, + "node_modules/metro": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro/-/metro-0.80.8.tgz", + "integrity": "sha512-in7S0W11mg+RNmcXw+2d9S3zBGmCARDxIwoXJAmLUQOQoYsRP3cpGzyJtc7WOw8+FXfpgXvceD0u+PZIHXEL7g==", + "peer": true, "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" + "@babel/code-frame": "^7.0.0", + "@babel/core": "^7.20.0", + "@babel/generator": "^7.20.0", + "@babel/parser": "^7.20.0", + "@babel/template": "^7.0.0", + "@babel/traverse": "^7.20.0", + "@babel/types": "^7.20.0", + "accepts": "^1.3.7", + "chalk": "^4.0.0", + "ci-info": "^2.0.0", + "connect": "^3.6.5", + "debug": "^2.2.0", + "denodeify": "^1.2.1", + "error-stack-parser": "^2.0.6", + "graceful-fs": "^4.2.4", + "hermes-parser": "0.20.1", + "image-size": "^1.0.2", + "invariant": "^2.2.4", + "jest-worker": "^29.6.3", + "jsc-safe-url": "^0.2.2", + "lodash.throttle": "^4.1.1", + "metro-babel-transformer": "0.80.8", + "metro-cache": "0.80.8", + "metro-cache-key": "0.80.8", + "metro-config": "0.80.8", + "metro-core": "0.80.8", + "metro-file-map": "0.80.8", + "metro-resolver": "0.80.8", + "metro-runtime": "0.80.8", + "metro-source-map": "0.80.8", + "metro-symbolicate": "0.80.8", + "metro-transform-plugins": "0.80.8", + "metro-transform-worker": "0.80.8", + "mime-types": "^2.1.27", + "node-fetch": "^2.2.0", + "nullthrows": "^1.1.1", + "rimraf": "^3.0.2", + "serialize-error": "^2.1.0", + "source-map": "^0.5.6", + "strip-ansi": "^6.0.0", + "throat": "^5.0.0", + "ws": "^7.5.1", + "yargs": "^17.6.2" }, - "engines": { - "node": ">= 0.4" + "bin": { + "metro": "src/cli.js" }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "engines": { + "node": ">=18" } }, - "node_modules/is-binary-path": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", - "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", - "dev": true, + "node_modules/metro-babel-transformer": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-babel-transformer/-/metro-babel-transformer-0.80.8.tgz", + "integrity": "sha512-TTzNwRZb2xxyv4J/+yqgtDAP2qVqH3sahsnFu6Xv4SkLqzrivtlnyUbaeTdJ9JjtADJUEjCbgbFgUVafrXdR9Q==", + "peer": true, "dependencies": { - "binary-extensions": "^2.0.0" + "@babel/core": "^7.20.0", + "hermes-parser": "0.20.1", + "nullthrows": "^1.1.1" }, "engines": { - "node": ">=8" + "node": ">=18" } }, - "node_modules/is-core-module": { - "version": "2.8.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.8.1.tgz", - "integrity": "sha512-SdNCUs284hr40hFTFP6l0IfZ/RSrMXF3qgoRHd3/79unUTvrFO/JoXwkGm+5J/Oe3E/b5GsnG330uUNgRpu1PA==", - "dev": true, + "node_modules/metro-babel-transformer/node_modules/hermes-estree": { + "version": "0.20.1", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.20.1.tgz", + "integrity": "sha512-SQpZK4BzR48kuOg0v4pb3EAGNclzIlqMj3Opu/mu7bbAoFw6oig6cEt/RAi0zTFW/iW6Iz9X9ggGuZTAZ/yZHg==", + "peer": true + }, + "node_modules/metro-babel-transformer/node_modules/hermes-parser": { + "version": "0.20.1", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.20.1.tgz", + "integrity": "sha512-BL5P83cwCogI8D7rrDCgsFY0tdYUtmFP9XaXtl2IQjC+2Xo+4okjfXintlTxcIwl4qeGddEl28Z11kbVIw0aNA==", + "peer": true, "dependencies": { - "has": "^1.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "hermes-estree": "0.20.1" } }, - "node_modules/is-date-object": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", - "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", - "dev": true, + "node_modules/metro-cache": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-cache/-/metro-cache-0.80.8.tgz", + "integrity": "sha512-5svz+89wSyLo7BxdiPDlwDTgcB9kwhNMfNhiBZPNQQs1vLFXxOkILwQiV5F2EwYT9DEr6OPZ0hnJkZfRQ8lDYQ==", + "peer": true, "dependencies": { - "has-tostringtag": "^1.0.0" + "metro-core": "0.80.8", + "rimraf": "^3.0.2" }, "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node": ">=18" } }, - "node_modules/is-extglob": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", - "integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI=", - "dev": true, + "node_modules/metro-cache-key": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-cache-key/-/metro-cache-key-0.80.8.tgz", + "integrity": "sha512-qWKzxrLsRQK5m3oH8ePecqCc+7PEhR03cJE6Z6AxAj0idi99dHOSitTmY0dclXVB9vP2tQIAE8uTd8xkYGk8fA==", + "peer": true, "engines": { - "node": ">=0.10.0" + "node": ">=18" } }, - "node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", - "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", - "dev": true, + "node_modules/metro-config": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-config/-/metro-config-0.80.8.tgz", + "integrity": "sha512-VGQJpfJawtwRzGzGXVUoohpIkB0iPom4DmSbAppKfumdhtLA8uVeEPp2GM61kL9hRvdbMhdWA7T+hZFDlo4mJA==", + "peer": true, + "dependencies": { + "connect": "^3.6.5", + "cosmiconfig": "^5.0.5", + "jest-validate": "^29.6.3", + "metro": "0.80.8", + "metro-cache": "0.80.8", + "metro-core": "0.80.8", + "metro-runtime": "0.80.8" + }, "engines": { - "node": ">=8" + "node": ">=18" } }, - "node_modules/is-generator": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/is-generator/-/is-generator-1.0.3.tgz", - "integrity": "sha1-wUwhBX7TbjKNuANHlmxpP4hjifM=", - "dev": true - }, - "node_modules/is-glob": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", - "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", - "dev": true, + "node_modules/metro-core": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-core/-/metro-core-0.80.8.tgz", + "integrity": "sha512-g6lud55TXeISRTleW6SHuPFZHtYrpwNqbyFIVd9j9Ofrb5IReiHp9Zl8xkAfZQp8v6ZVgyXD7c130QTsCz+vBw==", + "peer": true, "dependencies": { - "is-extglob": "^2.1.1" + "lodash.throttle": "^4.1.1", + "metro-resolver": "0.80.8" }, "engines": { - "node": ">=0.10.0" + "node": ">=18" } }, - "node_modules/is-module": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", - "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", - "dev": true - }, - "node_modules/is-number": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", - "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", - "dev": true, + "node_modules/metro-file-map": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-file-map/-/metro-file-map-0.80.8.tgz", + "integrity": "sha512-eQXMFM9ogTfDs2POq7DT2dnG7rayZcoEgRbHPXvhUWkVwiKkro2ngcBE++ck/7A36Cj5Ljo79SOkYwHaWUDYDw==", + "peer": true, + "dependencies": { + "anymatch": "^3.0.3", + "debug": "^2.2.0", + "fb-watchman": "^2.0.0", + "graceful-fs": "^4.2.4", + "invariant": "^2.2.4", + "jest-worker": "^29.6.3", + "micromatch": "^4.0.4", + "node-abort-controller": "^3.1.1", + "nullthrows": "^1.1.1", + "walker": "^1.0.7" + }, "engines": { - "node": ">=0.12.0" + "node": ">=18" + }, + "optionalDependencies": { + "fsevents": "^2.3.2" } }, - "node_modules/is-path-inside": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", - "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", - "dev": true, + "node_modules/metro-file-map/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "peer": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/metro-file-map/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "peer": true + }, + "node_modules/metro-minify-terser": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-minify-terser/-/metro-minify-terser-0.80.8.tgz", + "integrity": "sha512-y8sUFjVvdeUIINDuW1sejnIjkZfEF+7SmQo0EIpYbWmwh+kq/WMj74yVaBWuqNjirmUp1YNfi3alT67wlbBWBQ==", + "peer": true, + "dependencies": { + "terser": "^5.15.0" + }, "engines": { - "node": ">=8" + "node": ">=18" } }, - "node_modules/is-plain-obj": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", - "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", - "dev": true, + "node_modules/metro-resolver": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.80.8.tgz", + "integrity": "sha512-JdtoJkP27GGoZ2HJlEsxs+zO7jnDUCRrmwXJozTlIuzLHMRrxgIRRby9fTCbMhaxq+iA9c+wzm3iFb4NhPmLbQ==", + "peer": true, "engines": { - "node": ">=8" + "node": ">=18" } }, - "node_modules/is-reference": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", - "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", - "dev": true, + "node_modules/metro-runtime": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-runtime/-/metro-runtime-0.80.8.tgz", + "integrity": "sha512-2oScjfv6Yb79PelU1+p8SVrCMW9ZjgEiipxq7jMRn8mbbtWzyv3g8Mkwr+KwOoDFI/61hYPUbY8cUnu278+x1g==", + "peer": true, "dependencies": { - "@types/estree": "*" + "@babel/runtime": "^7.0.0" + }, + "engines": { + "node": ">=18" } }, - "node_modules/is-regex": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", - "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", - "dev": true, + "node_modules/metro-source-map": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-source-map/-/metro-source-map-0.80.8.tgz", + "integrity": "sha512-+OVISBkPNxjD4eEKhblRpBf463nTMk3KMEeYS8Z4xM/z3qujGJGSsWUGRtH27+c6zElaSGtZFiDMshEb8mMKQg==", + "peer": true, "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" + "@babel/traverse": "^7.20.0", + "@babel/types": "^7.20.0", + "invariant": "^2.2.4", + "metro-symbolicate": "0.80.8", + "nullthrows": "^1.1.1", + "ob1": "0.80.8", + "source-map": "^0.5.6", + "vlq": "^1.0.0" }, "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node": ">=18" } }, - "node_modules/is-stream": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", - "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", - "dev": true, + "node_modules/metro-source-map/node_modules/source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "peer": true, "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=0.10.0" } }, - "node_modules/is-typedarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=", - "dev": true - }, - "node_modules/is-unicode-supported": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", - "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", - "dev": true, - "engines": { - "node": ">=10" + "node_modules/metro-symbolicate": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-symbolicate/-/metro-symbolicate-0.80.8.tgz", + "integrity": "sha512-nwhYySk79jQhwjL9QmOUo4wS+/0Au9joEryDWw7uj4kz2yvw1uBjwmlql3BprQCBzRdB3fcqOP8kO8Es+vE31g==", + "peer": true, + "dependencies": { + "invariant": "^2.2.4", + "metro-source-map": "0.80.8", + "nullthrows": "^1.1.1", + "source-map": "^0.5.6", + "through2": "^2.0.1", + "vlq": "^1.0.0" }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "bin": { + "metro-symbolicate": "src/index.js" + }, + "engines": { + "node": ">=18" } }, - "node_modules/isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", - "dev": true - }, - "node_modules/isbinaryfile": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.8.tgz", - "integrity": "sha512-53h6XFniq77YdW+spoRrebh0mnmTxRPTlcuIArO57lmMdq4uBKFKaeTjnb92oYWrSn/LVL+LT+Hap2tFQj8V+w==", - "dev": true, + "node_modules/metro-symbolicate/node_modules/source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "peer": true, "engines": { - "node": ">= 8.0.0" - }, - "funding": { - "url": "https://github.com/sponsors/gjtorikian/" + "node": ">=0.10.0" } }, - "node_modules/isexe": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha1-6PvzdNxVb/iUehDcsFctYz8s+hA=", - "dev": true - }, - "node_modules/isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo=", - "dev": true + "node_modules/metro-transform-plugins": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-transform-plugins/-/metro-transform-plugins-0.80.8.tgz", + "integrity": "sha512-sSu8VPL9Od7w98MftCOkQ1UDeySWbsIAS5I54rW22BVpPnI3fQ42srvqMLaJUQPjLehUanq8St6OMBCBgH/UWw==", + "peer": true, + "dependencies": { + "@babel/core": "^7.20.0", + "@babel/generator": "^7.20.0", + "@babel/template": "^7.0.0", + "@babel/traverse": "^7.20.0", + "nullthrows": "^1.1.1" + }, + "engines": { + "node": ">=18" + } }, - "node_modules/jest-diff": { - "version": "27.5.1", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-27.5.1.tgz", - "integrity": "sha512-m0NvkX55LDt9T4mctTEgnZk3fmEg3NRYutvMPWM/0iPnkFj2wIeF45O1718cMSOFO1vINkqmxqD8vE37uTEbqw==", - "dev": true, + "node_modules/metro-transform-worker": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/metro-transform-worker/-/metro-transform-worker-0.80.8.tgz", + "integrity": "sha512-+4FG3TQk3BTbNqGkFb2uCaxYTfsbuFOCKMMURbwu0ehCP8ZJuTUramkaNZoATS49NSAkRgUltgmBa4YaKZ5mqw==", + "peer": true, "dependencies": { - "chalk": "^4.0.0", - "diff-sequences": "^27.5.1", - "jest-get-type": "^27.5.1", - "pretty-format": "^27.5.1" + "@babel/core": "^7.20.0", + "@babel/generator": "^7.20.0", + "@babel/parser": "^7.20.0", + "@babel/types": "^7.20.0", + "metro": "0.80.8", + "metro-babel-transformer": "0.80.8", + "metro-cache": "0.80.8", + "metro-cache-key": "0.80.8", + "metro-minify-terser": "0.80.8", + "metro-source-map": "0.80.8", + "metro-transform-plugins": "0.80.8", + "nullthrows": "^1.1.1" }, "engines": { - "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + "node": ">=18" } }, - "node_modules/jest-diff/node_modules/ansi-styles": { + "node_modules/metro/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, + "peer": true, "dependencies": { "color-convert": "^2.0.1" }, @@ -4312,27 +10511,31 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/jest-diff/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, + "node_modules/metro/node_modules/ci-info": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", + "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", + "peer": true + }, + "node_modules/metro/node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "peer": true, "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "node": ">=12" } }, - "node_modules/jest-diff/node_modules/color-convert": { + "node_modules/metro/node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, + "peer": true, "dependencies": { "color-name": "~1.1.4" }, @@ -4340,1718 +10543,1827 @@ "node": ">=7.0.0" } }, - "node_modules/jest-diff/node_modules/color-name": { + "node_modules/metro/node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "peer": true }, - "node_modules/jest-diff/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, - "engines": { - "node": ">=8" + "node_modules/metro/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "peer": true, + "dependencies": { + "ms": "2.0.0" } }, - "node_modules/jest-diff/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, + "node_modules/metro/node_modules/hermes-estree": { + "version": "0.20.1", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.20.1.tgz", + "integrity": "sha512-SQpZK4BzR48kuOg0v4pb3EAGNclzIlqMj3Opu/mu7bbAoFw6oig6cEt/RAi0zTFW/iW6Iz9X9ggGuZTAZ/yZHg==", + "peer": true + }, + "node_modules/metro/node_modules/hermes-parser": { + "version": "0.20.1", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.20.1.tgz", + "integrity": "sha512-BL5P83cwCogI8D7rrDCgsFY0tdYUtmFP9XaXtl2IQjC+2Xo+4okjfXintlTxcIwl4qeGddEl28Z11kbVIw0aNA==", + "peer": true, "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" + "hermes-estree": "0.20.1" } }, - "node_modules/jest-get-type": { - "version": "27.5.1", - "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-27.5.1.tgz", - "integrity": "sha512-2KY95ksYSaK7DMBWQn6dQz3kqAf3BB64y2udeG+hv4KfSOb9qwcYQstTJc1KCbsix+wLZWZYN8t7nwX3GOBLRw==", - "dev": true, + "node_modules/metro/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "peer": true + }, + "node_modules/metro/node_modules/serialize-error": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-2.1.0.tgz", + "integrity": "sha512-ghgmKt5o4Tly5yEG/UJp8qTd0AN7Xalw4XBtDEKP655B699qMEtra1WlXeE6WIvdEG481JvRxULKsInq/iNysw==", + "peer": true, "engines": { - "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + "node": ">=0.10.0" } }, - "node_modules/jest-matcher-utils": { - "version": "27.5.1", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-27.5.1.tgz", - "integrity": "sha512-z2uTx/T6LBaCoNWNFWwChLBKYxTMcGBRjAt+2SbP929/Fflb9aa5LGma654Rz8z9HLxsrUaYzxE9T/EFIL/PAw==", - "dev": true, - "dependencies": { - "chalk": "^4.0.0", - "jest-diff": "^27.5.1", - "jest-get-type": "^27.5.1", - "pretty-format": "^27.5.1" - }, + "node_modules/metro/node_modules/source-map": { + "version": "0.5.7", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", + "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "peer": true, "engines": { - "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + "node": ">=0.10.0" } }, - "node_modules/jest-matcher-utils/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, + "node_modules/metro/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "peer": true, "dependencies": { - "color-convert": "^2.0.1" + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" }, "engines": { - "node": ">=8" + "node": ">=10" }, "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/jest-matcher-utils/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, + "node_modules/metro/node_modules/ws": { + "version": "7.5.9", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", + "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", + "peer": true, + "engines": { + "node": ">=8.3.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/metro/node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "peer": true, "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "node": ">=12" } }, - "node_modules/jest-matcher-utils/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, + "node_modules/metro/node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "peer": true, + "engines": { + "node": ">=12" + } + }, + "node_modules/micromatch": { + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", + "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", "dependencies": { - "color-name": "~1.1.4" + "braces": "^3.0.2", + "picomatch": "^2.3.1" }, "engines": { - "node": ">=7.0.0" + "node": ">=8.6" } }, - "node_modules/jest-matcher-utils/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "node_modules/mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } }, - "node_modules/jest-matcher-utils/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", "engines": { - "node": ">=8" + "node": ">= 0.6" } }, - "node_modules/jest-matcher-utils/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mimic-fn": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", + "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "peer": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/minimatch": { + "version": "9.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", + "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", "dev": true, "dependencies": { - "has-flag": "^4.0.0" + "brace-expansion": "^2.0.1" }, "engines": { - "node": ">=8" + "node": ">=16 || 14 >=14.17" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/jest-message-util": { - "version": "27.5.1", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-27.5.1.tgz", - "integrity": "sha512-rMyFe1+jnyAAf+NHwTclDz0eAaLkVDdKVHHBFWsBWHnnh5YeJMNWWsv7AbFYXfK3oTqvL7VTWkhNLu1jX24D+g==", + "node_modules/minimist": { + "version": "1.2.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", + "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/minipass": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", + "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", "dev": true, - "dependencies": { - "@babel/code-frame": "^7.12.13", - "@jest/types": "^27.5.1", - "@types/stack-utils": "^2.0.0", - "chalk": "^4.0.0", - "graceful-fs": "^4.2.9", - "micromatch": "^4.0.4", - "pretty-format": "^27.5.1", - "slash": "^3.0.0", - "stack-utils": "^2.0.3" - }, "engines": { - "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + "node": ">=16 || 14 >=14.17" } }, - "node_modules/jest-message-util/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "node_modules/mkdirp": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.6.tgz", + "integrity": "sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==", "dev": true, - "dependencies": { - "color-convert": "^2.0.1" + "bin": { + "mkdirp": "dist/cjs/src/bin.js" }, "engines": { - "node": ">=8" + "node": ">=10" }, "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/jest-message-util/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "node_modules/mocha": { + "version": "10.4.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.4.0.tgz", + "integrity": "sha512-eqhGB8JKapEYcC4ytX/xrzKforgEc3j1pGlAXVy3eRwrtAy5/nIfT1SvgGzfN0XZZxeLq0aQWkOUAmqIJiv+bA==", "dev": true, "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "ansi-colors": "4.1.1", + "browser-stdout": "1.3.1", + "chokidar": "3.5.3", + "debug": "4.3.4", + "diff": "5.0.0", + "escape-string-regexp": "4.0.0", + "find-up": "5.0.0", + "glob": "8.1.0", + "he": "1.2.0", + "js-yaml": "4.1.0", + "log-symbols": "4.1.0", + "minimatch": "5.0.1", + "ms": "2.1.3", + "serialize-javascript": "6.0.0", + "strip-json-comments": "3.1.1", + "supports-color": "8.1.1", + "workerpool": "6.2.1", + "yargs": "16.2.0", + "yargs-parser": "20.2.4", + "yargs-unparser": "2.0.0" }, - "engines": { - "node": ">=10" + "bin": { + "_mocha": "bin/_mocha", + "mocha": "bin/mocha.js" }, - "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "engines": { + "node": ">= 14.0.0" } }, - "node_modules/jest-message-util/node_modules/color-convert": { + "node_modules/mocha/node_modules/argparse": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true + }, + "node_modules/mocha/node_modules/chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], "dependencies": { - "color-name": "~1.1.4" + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" }, "engines": { - "node": ">=7.0.0" + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" } }, - "node_modules/jest-message-util/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "node_modules/mocha/node_modules/diff": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "dev": true, + "engines": { + "node": ">=0.3.1" + } }, - "node_modules/jest-message-util/node_modules/has-flag": { + "node_modules/mocha/node_modules/escape-string-regexp": { "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true, "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/jest-message-util/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "node_modules/mocha/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", "dev": true, "dependencies": { - "has-flag": "^4.0.0" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" }, "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/jest-worker": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-26.6.2.tgz", - "integrity": "sha512-KWYVV1c4i+jbMpaBC+U++4Va0cp8OisU185o73T1vo99hqi7w8tSJfUXYswwqqrjzwxa6KpRK54WhPvwf5w6PQ==", + "node_modules/mocha/node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, "dependencies": { - "@types/node": "*", - "merge-stream": "^2.0.0", - "supports-color": "^7.0.0" + "is-glob": "^4.0.1" }, "engines": { - "node": ">= 10.13.0" + "node": ">= 6" } }, - "node_modules/jest-worker/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "node_modules/mocha/node_modules/js-yaml": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, - "engines": { - "node": ">=8" + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" } }, - "node_modules/jest-worker/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "node_modules/mocha/node_modules/minimatch": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", + "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", "dev": true, "dependencies": { - "has-flag": "^4.0.0" + "brace-expansion": "^2.0.1" }, "engines": { - "node": ">=8" + "node": ">=10" } }, - "node_modules/js-sdsl": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/js-sdsl/-/js-sdsl-4.4.0.tgz", - "integrity": "sha512-FfVSdx6pJ41Oa+CF7RDaFmTnCaFhua+SNYQX74riGOpl96x+2jQCqEfQ2bnXu/5DPCqlRuiqyvTJM0Qjz26IVg==", + "node_modules/mocha/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "dev": true + }, + "node_modules/mocha/node_modules/serialize-javascript": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", + "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", "dev": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/js-sdsl" + "dependencies": { + "randombytes": "^2.1.0" } }, - "node_modules/js-tokens": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", - "dev": true + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, - "node_modules/js-yaml": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", - "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "node_modules/mz": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", + "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", "dev": true, "dependencies": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" + "any-promise": "^1.0.0", + "object-assign": "^4.0.1", + "thenify-all": "^1.0.0" } }, - "node_modules/jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha1-peZUwuWi3rXyAdls77yoDA7y9RM=", + "node_modules/natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", "dev": true }, - "node_modules/json-schema": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", - "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", - "dev": true + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "engines": { + "node": ">= 0.6" + } }, - "node_modules/json-schema-traverse": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", - "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true + "node_modules/neo-async": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", + "peer": true }, - "node_modules/json-stable-stringify-without-jsonify": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", - "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", - "dev": true + "node_modules/netmask": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz", + "integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg==", + "engines": { + "node": ">= 0.4.0" + } }, - "node_modules/json-stringify-safe": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", - "integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus=", - "dev": true + "node_modules/next-tick": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", + "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==", + "dev": true, + "peer": true }, - "node_modules/jsonfile": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", - "integrity": "sha1-NzaitCi4e72gzIO1P6PWM6NcKug=", + "node_modules/nise": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/nise/-/nise-1.5.3.tgz", + "integrity": "sha512-Ymbac/94xeIrMf59REBPOv0thr+CJVFMhrlAkW/gjCIE58BGQdCj0x7KRCb3yz+Ga2Rz3E9XXSvUyyxqqhjQAQ==", "dev": true, - "optionalDependencies": { - "graceful-fs": "^4.1.6" + "dependencies": { + "@sinonjs/formatio": "^3.2.1", + "@sinonjs/text-encoding": "^0.7.1", + "just-extend": "^4.0.2", + "lolex": "^5.0.1", + "path-to-regexp": "^1.7.0" } }, - "node_modules/jsprim": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", - "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", + "node_modules/nise/node_modules/lolex": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/lolex/-/lolex-5.1.2.tgz", + "integrity": "sha512-h4hmjAvHTmd+25JSwrtTIuwbKdwg5NzZVRMLn9saij4SZaepCrTCxPr35H/3bjwfMJtN+t3CX8672UIkglz28A==", "dev": true, "dependencies": { - "assert-plus": "1.0.0", - "extsprintf": "1.3.0", - "json-schema": "0.4.0", - "verror": "1.10.0" - }, - "engines": { - "node": ">=0.6.0" + "@sinonjs/commons": "^1.7.0" } }, - "node_modules/jsprim/node_modules/core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true - }, - "node_modules/jsprim/node_modules/verror": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", - "integrity": "sha1-OhBcoXBTr1XW4nDB+CiGguGNpAA=", + "node_modules/no-case": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", + "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", "dev": true, - "engines": [ - "node >=0.6.0" - ], "dependencies": { - "assert-plus": "^1.0.0", - "core-util-is": "1.0.2", - "extsprintf": "^1.2.0" + "lower-case": "^2.0.2", + "tslib": "^2.0.3" } }, - "node_modules/just-extend": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", - "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", - "dev": true + "node_modules/nocache": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/nocache/-/nocache-3.0.4.tgz", + "integrity": "sha512-WDD0bdg9mbq6F4mRxEYcPWwfA1vxd0mrvKOyxI7Xj/atfRHVeutzuWByG//jfm4uPzp0y4Kj051EORCBSQMycw==", + "peer": true, + "engines": { + "node": ">=12.0.0" + } }, - "node_modules/karma": { - "version": "5.2.3", - "resolved": "https://registry.npmjs.org/karma/-/karma-5.2.3.tgz", - "integrity": "sha512-tHdyFADhVVPBorIKCX8A37iLHxc6RBRphkSoQ+MLKdAtFn1k97tD8WUGi1KlEtDZKL3hui0qhsY9HXUfSNDYPQ==", + "node_modules/nock": { + "version": "14.0.0-beta.5", + "resolved": "https://registry.npmjs.org/nock/-/nock-14.0.0-beta.5.tgz", + "integrity": "sha512-u255tf4DYvyErTlPZA9uTfXghiZZy+NflUOFONPVKZ5tP0yaHwKig28zyFOLhu8y5YcCRC+V5vDk4HHileh2iw==", "dev": true, "dependencies": { - "body-parser": "^1.19.0", - "braces": "^3.0.2", - "chokidar": "^3.4.2", - "colors": "^1.4.0", - "connect": "^3.7.0", - "di": "^0.0.1", - "dom-serialize": "^2.2.1", - "glob": "^7.1.6", - "graceful-fs": "^4.2.4", - "http-proxy": "^1.18.1", - "isbinaryfile": "^4.0.6", - "lodash": "^4.17.19", - "log4js": "^6.2.1", - "mime": "^2.4.5", - "minimatch": "^3.0.4", - "qjobs": "^1.2.0", - "range-parser": "^1.2.1", - "rimraf": "^3.0.2", - "socket.io": "^2.3.0", - "source-map": "^0.6.1", - "tmp": "0.2.1", - "ua-parser-js": "0.7.22", - "yargs": "^15.3.1" - }, - "bin": { - "karma": "bin/karma" + "json-stringify-safe": "^5.0.1", + "propagate": "^2.0.0" }, "engines": { - "node": ">= 10" + "node": ">= 18" } }, - "node_modules/karma-chai": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/karma-chai/-/karma-chai-0.1.0.tgz", - "integrity": "sha1-vuWtQEAFF4Ea40u5RfdikJEIt5o=", - "dev": true, - "peerDependencies": { - "chai": "*", - "karma": ">=0.10.9" + "node_modules/node-abort-controller": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.1.1.tgz", + "integrity": "sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==", + "peer": true + }, + "node_modules/node-dir": { + "version": "0.1.17", + "resolved": "https://registry.npmjs.org/node-dir/-/node-dir-0.1.17.tgz", + "integrity": "sha512-tmPX422rYgofd4epzrNoOXiE8XFZYOcCq1vD7MAXCDO+O+zndlA2ztdKKMa+EeuBG5tHETpr4ml4RGgpqDCCAg==", + "peer": true, + "dependencies": { + "minimatch": "^3.0.2" + }, + "engines": { + "node": ">= 0.10.5" } }, - "node_modules/karma-chrome-launcher": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-3.1.0.tgz", - "integrity": "sha512-3dPs/n7vgz1rxxtynpzZTvb9y/GIaW8xjAwcIGttLbycqoFtI7yo1NGnQi6oFTherRE+GIhCAHZC4vEqWGhNvg==", - "dev": true, + "node_modules/node-dir/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "peer": true, "dependencies": { - "which": "^1.2.1" + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" } }, - "node_modules/karma-mocha": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-2.0.1.tgz", - "integrity": "sha512-Tzd5HBjm8his2OA4bouAsATYEpZrp9vC7z5E5j4C5Of5Rrs1jY67RAwXNcVmd/Bnk1wgvQRou0zGVLey44G4tQ==", - "dev": true, + "node_modules/node-dir/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "peer": true, "dependencies": { - "minimist": "^1.2.3" + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" } }, - "node_modules/karma-phantomjs-launcher": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/karma-phantomjs-launcher/-/karma-phantomjs-launcher-1.0.4.tgz", - "integrity": "sha1-0jyjSAG9qYY60xjju0vUBisTrNI=", - "dev": true, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dependencies": { - "lodash": "^4.0.1", - "phantomjs-prebuilt": "^2.1.7" + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" }, "peerDependencies": { - "karma": ">=0.9" + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } } }, - "node_modules/karma-sinon-chai": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/karma-sinon-chai/-/karma-sinon-chai-2.0.2.tgz", - "integrity": "sha512-SDgh6V0CUd+7ruL1d3yG6lFzmJNGRNQuEuCYXLaorruNP9nwQfA7hpsp4clx4CbOo5Gsajh3qUOT7CrVStUKMw==", - "dev": true, - "peerDependencies": { - "chai": ">=3.5.0", - "sinon": ">=2.1.0", - "sinon-chai": ">=2.9.0" + "node_modules/node-int64": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", + "integrity": "sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==", + "peer": true + }, + "node_modules/node-releases": { + "version": "2.0.14", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz", + "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==", + "peer": true + }, + "node_modules/node-stream-zip": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.15.0.tgz", + "integrity": "sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw==", + "peer": true, + "engines": { + "node": ">=0.12.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/antelle" } }, - "node_modules/karma-sourcemap-loader": { - "version": "0.3.8", - "resolved": "https://registry.npmjs.org/karma-sourcemap-loader/-/karma-sourcemap-loader-0.3.8.tgz", - "integrity": "sha512-zorxyAakYZuBcHRJE+vbrK2o2JXLFWK8VVjiT/6P+ltLBUGUvqTEkUiQ119MGdOrK7mrmxXHZF1/pfT6GgIZ6g==", + "node_modules/normalize-package-data": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", + "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", "dev": true, "dependencies": { - "graceful-fs": "^4.1.2" + "hosted-git-info": "^2.1.4", + "resolve": "^1.10.0", + "semver": "2 || 3 || 4 || 5", + "validate-npm-package-license": "^3.0.1" } }, - "node_modules/karma-spec-reporter": { - "version": "0.0.32", - "resolved": "https://registry.npmjs.org/karma-spec-reporter/-/karma-spec-reporter-0.0.32.tgz", - "integrity": "sha1-LpxyB+pyZ3EmAln4K+y1QyCeRAo=", + "node_modules/normalize-package-data/node_modules/semver": { + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", + "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true, - "dependencies": { - "colors": "^1.1.2" - }, - "peerDependencies": { - "karma": ">=0.9" + "bin": { + "semver": "bin/semver" } }, - "node_modules/kew": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz", - "integrity": "sha1-edk9LTM2PW/dKXCzNdkUGtWR15s=", - "dev": true - }, - "node_modules/klaw": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", - "integrity": "sha1-QIhDO0azsbolnXh4XY6W9zugJDk=", - "dev": true, - "optionalDependencies": { - "graceful-fs": "^4.1.9" + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "engines": { + "node": ">=0.10.0" } }, - "node_modules/knuth-shuffle-seeded": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/knuth-shuffle-seeded/-/knuth-shuffle-seeded-1.0.6.tgz", - "integrity": "sha1-AfG2VzOqdUDuCNiwF0Fk0iCB5OE=", - "dev": true, + "node_modules/npm-run-path": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", + "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "peer": true, "dependencies": { - "seed-random": "~2.2.0" + "path-key": "^3.0.0" + }, + "engines": { + "node": ">=8" } }, - "node_modules/lil-uuid": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/lil-uuid/-/lil-uuid-0.1.1.tgz", - "integrity": "sha1-+e3PI/AOQr9D8PhD2Y2LU/M0HxY=" + "node_modules/nullthrows": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/nullthrows/-/nullthrows-1.1.1.tgz", + "integrity": "sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==", + "peer": true }, - "node_modules/locate-path": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", - "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "node_modules/oauth-sign": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", + "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", "dev": true, - "dependencies": { - "p-locate": "^5.0.0" - }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": "*" } }, - "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true - }, - "node_modules/lodash.merge": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", - "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "dev": true + "node_modules/ob1": { + "version": "0.80.8", + "resolved": "https://registry.npmjs.org/ob1/-/ob1-0.80.8.tgz", + "integrity": "sha512-QHJQk/lXMmAW8I7AIM3in1MSlwe1umR72Chhi8B7Xnq6mzjhBKkA6Fy/zAhQnGkA4S912EPCEvTij5yh+EQTAA==", + "peer": true, + "engines": { + "node": ">=18" + } }, - "node_modules/log-symbols": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", - "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", - "dev": true, - "dependencies": { - "chalk": "^4.1.0", - "is-unicode-supported": "^0.1.0" - }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=0.10.0" } }, - "node_modules/log-symbols/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "node_modules/object-inspect": { + "version": "1.13.1", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", + "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", "dev": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/log-symbols/node_modules/chalk": { - "version": "4.1.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "node_modules/object-is": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz", + "integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==", "dev": true, "dependencies": { - "ansi-styles": "^4.1.0", - "supports-color": "^7.1.0" + "call-bind": "^1.0.7", + "define-properties": "^1.2.1" }, "engines": { - "node": ">=10" + "node": ">= 0.4" }, "funding": { - "url": "https://github.com/chalk/chalk?sponsor=1" + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/log-symbols/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "node_modules/object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", "dev": true, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/on-finished": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", + "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", "dependencies": { - "color-name": "~1.1.4" + "ee-first": "1.1.1" }, "engines": { - "node": ">=7.0.0" + "node": ">= 0.8" } }, - "node_modules/log-symbols/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "node_modules/log-symbols/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, + "node_modules/on-headers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", + "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==", + "peer": true, "engines": { - "node": ">=8" + "node": ">= 0.8" } }, - "node_modules/log-symbols/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" + "wrappy": "1" } }, - "node_modules/log4js": { - "version": "6.4.1", - "resolved": "https://registry.npmjs.org/log4js/-/log4js-6.4.1.tgz", - "integrity": "sha512-iUiYnXqAmNKiIZ1XSAitQ4TmNs8CdZYTAWINARF3LjnsLN8tY5m0vRwd6uuWj/yNY0YHxeZodnbmxKFUOM2rMg==", - "dev": true, + "node_modules/onetime": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", + "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "peer": true, "dependencies": { - "date-format": "^4.0.3", - "debug": "^4.3.3", - "flatted": "^3.2.4", - "rfdc": "^1.3.0", - "streamroller": "^3.0.2" + "mimic-fn": "^2.1.0" }, "engines": { - "node": ">=8.0" + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/lolex": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/lolex/-/lolex-4.2.0.tgz", - "integrity": "sha512-gKO5uExCXvSm6zbF562EvM+rd1kQDnB9AZBbiQVzf1ZmdDpxUSvpnAaVOP83N/31mRK8Ml8/VE8DMvsAZQ+7wg==", - "dev": true - }, - "node_modules/lower-case": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", - "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", - "dev": true, + "node_modules/open": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/open/-/open-6.4.0.tgz", + "integrity": "sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==", + "peer": true, "dependencies": { - "tslib": "^2.0.3" + "is-wsl": "^1.1.0" + }, + "engines": { + "node": ">=8" } }, - "node_modules/lru-cache": { - "version": "7.18.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", - "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "node_modules/open/node_modules/is-wsl": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-1.1.0.tgz", + "integrity": "sha512-gfygJYZ2gLTDlmbWMI0CE2MwnFzSN/2SZfkMlItC4K/JBlsWVDB0bO6XhqcY13YXE7iMcAJnzTCJjPiTeJJ0Mw==", + "peer": true, "engines": { - "node": ">=12" + "node": ">=4" } }, - "node_modules/magic-string": { - "version": "0.25.7", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", - "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", + "node_modules/optionator": { + "version": "0.9.3", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", + "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", "dev": true, "dependencies": { - "sourcemap-codec": "^1.4.4" - } - }, - "node_modules/make-error": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", - "dev": true - }, - "node_modules/media-typer": { - "version": "0.3.0", - "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", - "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=", - "dev": true, + "@aashutoshrathi/word-wrap": "^1.2.3", + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0" + }, "engines": { - "node": ">= 0.6" + "node": ">= 0.8.0" } }, - "node_modules/merge-stream": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", - "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", - "dev": true - }, - "node_modules/merge2": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", - "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", - "dev": true, + "node_modules/ora": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/ora/-/ora-5.4.1.tgz", + "integrity": "sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==", + "peer": true, + "dependencies": { + "bl": "^4.1.0", + "chalk": "^4.1.0", + "cli-cursor": "^3.1.0", + "cli-spinners": "^2.5.0", + "is-interactive": "^1.0.0", + "is-unicode-supported": "^0.1.0", + "log-symbols": "^4.1.0", + "strip-ansi": "^6.0.0", + "wcwidth": "^1.0.1" + }, "engines": { - "node": ">= 8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/methods": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", - "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=", + "node_modules/p-limit": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", + "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dependencies": { + "yocto-queue": "^0.1.0" + }, "engines": { - "node": ">= 0.6" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/micromatch": { - "version": "4.0.4", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.4.tgz", - "integrity": "sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg==", - "dev": true, + "node_modules/p-locate": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", + "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", "dependencies": { - "braces": "^3.0.1", - "picomatch": "^2.2.3" + "p-limit": "^3.0.2" }, "engines": { - "node": ">=8.6" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/mime": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", - "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", - "bin": { - "mime": "cli.js" - }, + "node_modules/p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", "engines": { - "node": ">=4.0.0" + "node": ">=6" } }, - "node_modules/mime-db": { - "version": "1.51.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz", - "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==", + "node_modules/pac-proxy-agent": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.0.1.tgz", + "integrity": "sha512-ASV8yU4LLKBAjqIPMbrgtaKIvxQri/yh2OpI+S6hVa9JRkUI3Y3NPFbfngDtY7oFtSMD3w31Xns89mDa3Feo5A==", + "dependencies": { + "@tootallnate/quickjs-emscripten": "^0.23.0", + "agent-base": "^7.0.2", + "debug": "^4.3.4", + "get-uri": "^6.0.1", + "http-proxy-agent": "^7.0.0", + "https-proxy-agent": "^7.0.2", + "pac-resolver": "^7.0.0", + "socks-proxy-agent": "^8.0.2" + }, "engines": { - "node": ">= 0.6" + "node": ">= 14" } }, - "node_modules/mime-types": { - "version": "2.1.34", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz", - "integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==", + "node_modules/pac-resolver": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/pac-resolver/-/pac-resolver-7.0.1.tgz", + "integrity": "sha512-5NPgf87AT2STgwa2ntRMr45jTKrYBGkVU36yT0ig/n/GMAa3oPqhZfIQ2kMEimReg0+t9kZViDVZ83qfVUlckg==", "dependencies": { - "mime-db": "1.51.0" + "degenerator": "^5.0.0", + "netmask": "^2.0.2" }, "engines": { - "node": ">= 0.6" + "node": ">= 14" } }, - "node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "node_modules/pad-right": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/pad-right/-/pad-right-0.2.2.tgz", + "integrity": "sha512-4cy8M95ioIGolCoMmm2cMntGR1lPLEbOMzOKu8bzjuJP6JpzEMQcDHmh7hHLYGgob+nKe1YHFMaG4V59HQa89g==", "dev": true, "dependencies": { - "brace-expansion": "^1.1.7" + "repeat-string": "^1.5.2" }, "engines": { - "node": "*" + "node": ">=0.10.0" } }, - "node_modules/minimist": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true - }, - "node_modules/mkdirp": { - "version": "0.5.5", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz", - "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==", + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", "dev": true, "dependencies": { - "minimist": "^1.2.5" + "callsites": "^3.0.0" }, - "bin": { - "mkdirp": "bin/cmd.js" + "engines": { + "node": ">=6" } }, - "node_modules/mocha": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/mocha/-/mocha-9.2.1.tgz", - "integrity": "sha512-T7uscqjJVS46Pq1XDXyo9Uvey9gd3huT/DD9cYBb4K2Xc/vbKRPUWK067bxDQRK0yIz6Jxk73IrnimvASzBNAQ==", + "node_modules/parse-json": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", + "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==", "dev": true, "dependencies": { - "@ungap/promise-all-settled": "1.1.2", - "ansi-colors": "4.1.1", - "browser-stdout": "1.3.1", - "chokidar": "3.5.3", - "debug": "4.3.3", - "diff": "5.0.0", - "escape-string-regexp": "4.0.0", - "find-up": "5.0.0", - "glob": "7.2.0", - "growl": "1.10.5", - "he": "1.2.0", - "js-yaml": "4.1.0", - "log-symbols": "4.1.0", - "minimatch": "3.0.4", - "ms": "2.1.3", - "nanoid": "3.2.0", - "serialize-javascript": "6.0.0", - "strip-json-comments": "3.1.1", - "supports-color": "8.1.1", - "which": "2.0.2", - "workerpool": "6.2.0", - "yargs": "16.2.0", - "yargs-parser": "20.2.4", - "yargs-unparser": "2.0.0" + "@babel/code-frame": "^7.0.0", + "error-ex": "^1.3.1", + "json-parse-even-better-errors": "^2.3.0", + "lines-and-columns": "^1.1.6" }, - "bin": { - "_mocha": "bin/_mocha", - "mocha": "bin/mocha" + "engines": { + "node": ">=8" }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-exists": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", + "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", "engines": { - "node": ">= 12.0.0" - }, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/mochajs" + "node": ">=0.10.0" } }, - "node_modules/mocha/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + }, + "node_modules/path-scurry": { + "version": "1.10.2", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.2.tgz", + "integrity": "sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==", "dev": true, "dependencies": { - "color-convert": "^2.0.1" + "lru-cache": "^10.2.0", + "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" }, "engines": { - "node": ">=8" + "node": ">=16 || 14 >=14.17" }, "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/mocha/node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "node_modules/path-to-regexp": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", + "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "dev": true, + "dependencies": { + "isarray": "0.0.1" + } + }, + "node_modules/path-to-regexp/node_modules/isarray": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", "dev": true }, - "node_modules/mocha/node_modules/cliui": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", - "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "node_modules/path-type": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", + "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", "dev": true, - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" + "engines": { + "node": ">=8" } }, - "node_modules/mocha/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "node_modules/pathval": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", + "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", "dev": true, - "dependencies": { - "color-name": "~1.1.4" - }, "engines": { - "node": ">=7.0.0" + "node": "*" } }, - "node_modules/mocha/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "node_modules/pend": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", + "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", "dev": true }, - "node_modules/mocha/node_modules/diff": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", - "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "node_modules/performance-now": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", + "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==", + "dev": true + }, + "node_modules/phantomjs-prebuilt": { + "version": "2.1.16", + "resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.16.tgz", + "integrity": "sha512-PIiRzBhW85xco2fuj41FmsyuYHKjKuXWmhjy3A/Y+CMpN/63TV+s9uzfVhsUwFe0G77xWtHBG8xmXf5BqEUEuQ==", + "deprecated": "this package is now deprecated", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "es6-promise": "^4.0.3", + "extract-zip": "^1.6.5", + "fs-extra": "^1.0.0", + "hasha": "^2.2.0", + "kew": "^0.7.0", + "progress": "^1.1.8", + "request": "^2.81.0", + "request-progress": "^2.0.1", + "which": "^1.2.10" + }, + "bin": { + "phantomjs": "bin/phantomjs" + } + }, + "node_modules/phantomjs-prebuilt/node_modules/progress": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz", + "integrity": "sha512-UdA8mJ4weIkUBO224tIarHzuHs4HuYiJvsuGT7j/SPQiUJVjYvNDBIPa0hAorduOfjGohB/qHWRa/lrrWX/mXw==", "dev": true, "engines": { - "node": ">=0.3.1" + "node": ">=0.4.0" } }, - "node_modules/mocha/node_modules/escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "node_modules/phantomjs-prebuilt/node_modules/which": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", + "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "which": "bin/which" + } + }, + "node_modules/picocolors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", + "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", "engines": { - "node": ">=10" + "node": ">=8.6" }, "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "url": "https://github.com/sponsors/jonschlinkert" } }, - "node_modules/mocha/node_modules/has-flag": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", - "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, + "node_modules/pify": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", + "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", + "peer": true, "engines": { - "node": ">=8" + "node": ">=6" } }, - "node_modules/mocha/node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "node_modules/pinkie": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", + "integrity": "sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==", "dev": true, - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" + "engines": { + "node": ">=0.10.0" } }, - "node_modules/mocha/node_modules/minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "node_modules/pinkie-promise": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", + "integrity": "sha512-0Gni6D4UcLTbv9c57DfxDGdr41XfgUjqWZu492f0cIGr16zDU06BWP/RAEvOuo7CQ0CNjHaLlM59YJJFm3NWlw==", "dev": true, "dependencies": { - "brace-expansion": "^1.1.7" + "pinkie": "^2.0.0" }, "engines": { - "node": "*" + "node": ">=0.10.0" } }, - "node_modules/mocha/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true + "node_modules/pirates": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.6.tgz", + "integrity": "sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==", + "peer": true, + "engines": { + "node": ">= 6" + } }, - "node_modules/mocha/node_modules/serialize-javascript": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", - "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", - "dev": true, + "node_modules/pkg-dir": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", + "integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==", + "peer": true, "dependencies": { - "randombytes": "^2.1.0" + "find-up": "^3.0.0" + }, + "engines": { + "node": ">=6" } }, - "node_modules/mocha/node_modules/supports-color": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", - "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", - "dev": true, + "node_modules/pkg-dir/node_modules/find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "peer": true, "dependencies": { - "has-flag": "^4.0.0" + "locate-path": "^3.0.0" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/supports-color?sponsor=1" + "node": ">=6" } }, - "node_modules/mocha/node_modules/which": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", - "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", - "dev": true, + "node_modules/pkg-dir/node_modules/locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "peer": true, "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "node-which": "bin/node-which" + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" }, "engines": { - "node": ">= 8" + "node": ">=6" } }, - "node_modules/mocha/node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "dev": true, + "node_modules/pkg-dir/node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "peer": true, "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" + "p-try": "^2.0.0" }, "engines": { - "node": ">=10" + "node": ">=6" }, "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, - "node_modules/mocha/node_modules/y18n": { - "version": "5.0.8", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", - "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", - "dev": true, - "engines": { - "node": ">=10" + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/mocha/node_modules/yargs": { - "version": "16.2.0", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", - "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", - "dev": true, + "node_modules/pkg-dir/node_modules/p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "peer": true, "dependencies": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.0", - "y18n": "^5.0.5", - "yargs-parser": "^20.2.2" + "p-limit": "^2.0.0" }, "engines": { - "node": ">=10" + "node": ">=6" } }, - "node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "node_modules/pkg-dir/node_modules/path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", + "peer": true, + "engines": { + "node": ">=4" + } }, - "node_modules/mz": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", - "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true, - "dependencies": { - "any-promise": "^1.0.0", - "object-assign": "^4.0.1", - "thenify-all": "^1.0.0" + "engines": { + "node": ">= 0.8.0" } }, - "node_modules/nanoid": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.2.0.tgz", - "integrity": "sha512-fmsZYa9lpn69Ad5eDn7FMcnnSR+8R34W9qJEijxYhTbfOWzr22n1QxCMzXLK+ODyW2973V3Fux959iQoUxzUIA==", + "node_modules/prettier": { + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", + "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", "dev": true, "bin": { - "nanoid": "bin/nanoid.cjs" + "prettier": "bin/prettier.cjs" }, "engines": { - "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" } }, - "node_modules/natural-compare": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", - "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", - "dev": true - }, - "node_modules/negotiator": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", - "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", "dev": true, + "dependencies": { + "fast-diff": "^1.1.2" + }, "engines": { - "node": ">= 0.6" + "node": ">=6.0.0" } }, - "node_modules/netmask": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz", - "integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg==", + "node_modules/pretty-format": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", + "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", + "dependencies": { + "@jest/schemas": "^29.6.3", + "ansi-styles": "^5.0.0", + "react-is": "^18.0.0" + }, "engines": { - "node": ">= 0.4.0" + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/next-tick": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.0.0.tgz", - "integrity": "sha1-yobR/ogoFpsBICCOPchCS524NCw=", - "dev": true + "node_modules/process-nextick-args": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" }, - "node_modules/nise": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/nise/-/nise-1.5.3.tgz", - "integrity": "sha512-Ymbac/94xeIrMf59REBPOv0thr+CJVFMhrlAkW/gjCIE58BGQdCj0x7KRCb3yz+Ga2Rz3E9XXSvUyyxqqhjQAQ==", + "node_modules/progress": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", + "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true, - "dependencies": { - "@sinonjs/formatio": "^3.2.1", - "@sinonjs/text-encoding": "^0.7.1", - "just-extend": "^4.0.2", - "lolex": "^5.0.1", - "path-to-regexp": "^1.7.0" + "engines": { + "node": ">=0.4.0" } }, - "node_modules/nise/node_modules/lolex": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/lolex/-/lolex-5.1.2.tgz", - "integrity": "sha512-h4hmjAvHTmd+25JSwrtTIuwbKdwg5NzZVRMLn9saij4SZaepCrTCxPr35H/3bjwfMJtN+t3CX8672UIkglz28A==", - "dev": true, + "node_modules/promise": { + "version": "8.3.0", + "resolved": "https://registry.npmjs.org/promise/-/promise-8.3.0.tgz", + "integrity": "sha512-rZPNPKTOYVNEEKFaq1HqTgOwZD+4/YHS5ukLzQCypkj+OkYx7iv0mA91lJlpPPZ8vMau3IIGj5Qlwrx+8iiSmg==", + "peer": true, "dependencies": { - "@sinonjs/commons": "^1.7.0" + "asap": "~2.0.6" } }, - "node_modules/no-case": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", - "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", - "dev": true, + "node_modules/prompts": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", + "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", + "peer": true, "dependencies": { - "lower-case": "^2.0.2", - "tslib": "^2.0.3" + "kleur": "^3.0.3", + "sisteransi": "^1.0.5" + }, + "engines": { + "node": ">= 6" } }, - "node_modules/nock": { - "version": "9.6.1", - "resolved": "https://registry.npmjs.org/nock/-/nock-9.6.1.tgz", - "integrity": "sha512-EDgl/WgNQ0C1BZZlASOQkQdE6tAWXJi8QQlugqzN64JJkvZ7ILijZuG24r4vCC7yOfnm6HKpne5AGExLGCeBWg==", - "dev": true, - "engines": [ - "node >= 4.0" - ], + "node_modules/prop-types": { + "version": "15.8.1", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", + "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", + "peer": true, "dependencies": { - "chai": "^4.1.2", - "debug": "^3.1.0", - "deep-equal": "^1.0.0", - "json-stringify-safe": "^5.0.1", - "lodash": "^4.17.5", - "mkdirp": "^0.5.0", - "propagate": "^1.0.0", - "qs": "^6.5.1", - "semver": "^5.5.0" + "loose-envify": "^1.4.0", + "object-assign": "^4.1.1", + "react-is": "^16.13.1" } }, - "node_modules/nock/node_modules/debug": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", - "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", - "dev": true, - "dependencies": { - "ms": "^2.1.1" - } + "node_modules/prop-types/node_modules/react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", + "peer": true }, - "node_modules/nock/node_modules/semver": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", - "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "node_modules/propagate": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", + "integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==", "dev": true, - "bin": { - "semver": "bin/semver" + "engines": { + "node": ">= 8" } }, - "node_modules/node-fetch": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", - "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", - "dev": true, + "node_modules/property-expr": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.6.tgz", + "integrity": "sha512-SVtmxhRE/CGkn3eZY1T6pC8Nln6Fr/lu1mKSgRud0eC73whjGfoAogbn78LkD8aFL0zz3bAFerKSnOl7NlErBA==", + "dev": true + }, + "node_modules/proxy-agent": { + "version": "6.4.0", + "resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-6.4.0.tgz", + "integrity": "sha512-u0piLU+nCOHMgGjRbimiXmA9kM/L9EHh3zL81xCdp7m+Y2pHIsnmbdDoEDoAz5geaonNR6q6+yOPQs6n4T6sBQ==", "dependencies": { - "whatwg-url": "^5.0.0" + "agent-base": "^7.0.2", + "debug": "^4.3.4", + "http-proxy-agent": "^7.0.1", + "https-proxy-agent": "^7.0.3", + "lru-cache": "^7.14.1", + "pac-proxy-agent": "^7.0.1", + "proxy-from-env": "^1.1.0", + "socks-proxy-agent": "^8.0.2" }, "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } + "node": ">= 14" } }, - "node_modules/normalize-path": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", - "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", - "dev": true, + "node_modules/proxy-agent/node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", "engines": { - "node": ">=0.10.0" + "node": ">=12" } }, - "node_modules/oauth-sign": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", - "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", - "dev": true, + "node_modules/proxy-from-env": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, + "node_modules/psl": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", + "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==", + "dev": true + }, + "node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", "engines": { - "node": "*" + "node": ">=6" } }, - "node_modules/object-assign": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "node_modules/qjobs": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", + "integrity": "sha512-8YOJEHtxpySA3fFDyCRxA+UUV+fA+rTWnuWvylOK/NCjhY+b4ocCtmu8TtsWb+mYeU+GCHf/S66KZF/AsteKHg==", "dev": true, "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/object-inspect": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", - "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node": ">=0.9" } }, - "node_modules/object-is": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.5.tgz", - "integrity": "sha512-3cyDsyHgtmi7I7DfSSI2LDp6SK2lwvtbg0p0R1e0RvTqF5ceGx+K2dfSjm1bKDMVCFEDAQvy+o8c6a7VujOddw==", + "node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", "dev": true, "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3" + "side-channel": "^1.0.4" }, "engines": { - "node": ">= 0.4" + "node": ">=0.6" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/object-keys": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", - "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true, - "engines": { - "node": ">= 0.4" + "node_modules/queue": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/queue/-/queue-6.0.2.tgz", + "integrity": "sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==", + "peer": true, + "dependencies": { + "inherits": "~2.0.3" } }, - "node_modules/on-finished": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", - "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "node_modules/queue-microtask": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", + "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", "dev": true, - "dependencies": { - "ee-first": "1.1.1" - }, - "engines": { - "node": ">= 0.8" - } + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] }, - "node_modules/once": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dependencies": { - "wrappy": "1" - } + "node_modules/rambda": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/rambda/-/rambda-7.5.0.tgz", + "integrity": "sha512-y/M9weqWAH4iopRd7EHDEQQvpFPHj1AA3oHozE9tfITHUtTR7Z9PSlIRRG2l1GuW7sefC1cXFfIcF+cgnShdBA==", + "dev": true }, - "node_modules/p-limit": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", - "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "node_modules/randombytes": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", + "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", "dev": true, "dependencies": { - "yocto-queue": "^0.1.0" - }, + "safe-buffer": "^5.1.0" + } + }, + "node_modules/range-parser": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", + "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">= 0.6" } }, - "node_modules/p-locate": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", - "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "node_modules/raw-body": { + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", + "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", "dev": true, "dependencies": { - "p-limit": "^3.0.2" - }, - "engines": { - "node": ">=10" + "bytes": "3.1.2", + "http-errors": "2.0.0", + "iconv-lite": "0.4.24", + "unpipe": "1.0.0" }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "engines": { + "node": ">= 0.8" } }, - "node_modules/pac-proxy-agent": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.0.1.tgz", - "integrity": "sha512-ASV8yU4LLKBAjqIPMbrgtaKIvxQri/yh2OpI+S6hVa9JRkUI3Y3NPFbfngDtY7oFtSMD3w31Xns89mDa3Feo5A==", + "node_modules/react": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", + "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", + "peer": true, "dependencies": { - "@tootallnate/quickjs-emscripten": "^0.23.0", - "agent-base": "^7.0.2", - "debug": "^4.3.4", - "get-uri": "^6.0.1", - "http-proxy-agent": "^7.0.0", - "https-proxy-agent": "^7.0.2", - "pac-resolver": "^7.0.0", - "socks-proxy-agent": "^8.0.2" + "loose-envify": "^1.1.0" }, "engines": { - "node": ">= 14" + "node": ">=0.10.0" } }, - "node_modules/pac-proxy-agent/node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "node_modules/react-devtools-core": { + "version": "4.28.5", + "resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-4.28.5.tgz", + "integrity": "sha512-cq/o30z9W2Wb4rzBefjv5fBalHU0rJGZCHAkf/RHSBWSSYwh8PlQTqqOJmgIIbBtpj27T6FIPXeomIjZtCNVqA==", + "peer": true, "dependencies": { - "ms": "2.1.2" - }, + "shell-quote": "^1.6.1", + "ws": "^7" + } + }, + "node_modules/react-devtools-core/node_modules/ws": { + "version": "7.5.9", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", + "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", + "peer": true, "engines": { - "node": ">=6.0" + "node": ">=8.3.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" }, "peerDependenciesMeta": { - "supports-color": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { "optional": true } } }, - "node_modules/pac-resolver": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/pac-resolver/-/pac-resolver-7.0.0.tgz", - "integrity": "sha512-Fd9lT9vJbHYRACT8OhCbZBbxr6KRSawSovFpy8nDGshaK99S/EBhVIHp9+crhxrsZOuvLpgL1n23iyPg6Rl2hg==", + "node_modules/react-is": { + "version": "18.2.0", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", + "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==" + }, + "node_modules/react-native": { + "version": "0.73.6", + "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.73.6.tgz", + "integrity": "sha512-oqmZe8D2/VolIzSPZw+oUd6j/bEmeRHwsLn1xLA5wllEYsZ5zNuMsDus235ONOnCRwexqof/J3aztyQswSmiaA==", + "peer": true, "dependencies": { - "degenerator": "^5.0.0", - "ip": "^1.1.8", - "netmask": "^2.0.2" + "@jest/create-cache-key-function": "^29.6.3", + "@react-native-community/cli": "12.3.6", + "@react-native-community/cli-platform-android": "12.3.6", + "@react-native-community/cli-platform-ios": "12.3.6", + "@react-native/assets-registry": "0.73.1", + "@react-native/codegen": "0.73.3", + "@react-native/community-cli-plugin": "0.73.17", + "@react-native/gradle-plugin": "0.73.4", + "@react-native/js-polyfills": "0.73.1", + "@react-native/normalize-colors": "0.73.2", + "@react-native/virtualized-lists": "0.73.4", + "abort-controller": "^3.0.0", + "anser": "^1.4.9", + "ansi-regex": "^5.0.0", + "base64-js": "^1.5.1", + "chalk": "^4.0.0", + "deprecated-react-native-prop-types": "^5.0.0", + "event-target-shim": "^5.0.1", + "flow-enums-runtime": "^0.0.6", + "invariant": "^2.2.4", + "jest-environment-node": "^29.6.3", + "jsc-android": "^250231.0.0", + "memoize-one": "^5.0.0", + "metro-runtime": "^0.80.3", + "metro-source-map": "^0.80.3", + "mkdirp": "^0.5.1", + "nullthrows": "^1.1.1", + "pretty-format": "^26.5.2", + "promise": "^8.3.0", + "react-devtools-core": "^4.27.7", + "react-refresh": "^0.14.0", + "react-shallow-renderer": "^16.15.0", + "regenerator-runtime": "^0.13.2", + "scheduler": "0.24.0-canary-efb381bbf-20230505", + "stacktrace-parser": "^0.1.10", + "whatwg-fetch": "^3.0.0", + "ws": "^6.2.2", + "yargs": "^17.6.2" + }, + "bin": { + "react-native": "cli.js" }, "engines": { - "node": ">= 14" + "node": ">=18" + }, + "peerDependencies": { + "react": "18.2.0" } }, - "node_modules/pad-right": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/pad-right/-/pad-right-0.2.2.tgz", - "integrity": "sha1-b7ySQEXSRPKiokRQMGDTv8YAl3Q=", - "dev": true, + "node_modules/react-native-url-polyfill": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/react-native-url-polyfill/-/react-native-url-polyfill-2.0.0.tgz", + "integrity": "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA==", "dependencies": { - "repeat-string": "^1.5.2" + "whatwg-url-without-unicode": "8.0.0-3" }, - "engines": { - "node": ">=0.10.0" + "peerDependencies": { + "react-native": "*" } }, - "node_modules/parent-module": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", - "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", - "dev": true, + "node_modules/react-native/node_modules/@jest/types": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", + "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", + "peer": true, "dependencies": { - "callsites": "^3.0.0" + "@types/istanbul-lib-coverage": "^2.0.0", + "@types/istanbul-reports": "^3.0.0", + "@types/node": "*", + "@types/yargs": "^15.0.0", + "chalk": "^4.0.0" }, "engines": { - "node": ">=6" + "node": ">= 10.14.2" } }, - "node_modules/parseqs": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.6.tgz", - "integrity": "sha512-jeAGzMDbfSHHA091hr0r31eYfTig+29g3GKKE/PPbEQ65X0lmMwlEoqmhzu0iztID5uJpZsFlUPDP8ThPL7M8w==", - "dev": true - }, - "node_modules/parseuri": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/parseuri/-/parseuri-0.0.6.tgz", - "integrity": "sha512-AUjen8sAkGgao7UyCX6Ahv0gIK2fABKmYjvP4xmy5JaKvcbTRueIqIPHLAfq30xJddqSE033IOMUSOMCcK3Sow==", - "dev": true - }, - "node_modules/parseurl": { - "version": "1.3.3", - "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", - "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", - "dev": true, - "engines": { - "node": ">= 0.8" + "node_modules/react-native/node_modules/@types/yargs": { + "version": "15.0.19", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.19.tgz", + "integrity": "sha512-2XUaGVmyQjgyAZldf0D0c14vvo/yv0MhQBSTJcejMMaitsn3nxCB6TmH4G0ZQf+uxROOa9mpanoSm8h6SG/1ZA==", + "peer": true, + "dependencies": { + "@types/yargs-parser": "*" } }, - "node_modules/path-exists": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", - "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", - "dev": true, + "node_modules/react-native/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "peer": true, "engines": { "node": ">=8" } }, - "node_modules/path-is-absolute": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/path-key": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", - "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", - "dev": true, + "node_modules/react-native/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "peer": true, + "dependencies": { + "color-convert": "^2.0.1" + }, "engines": { "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/path-parse": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", - "dev": true - }, - "node_modules/path-to-regexp": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", - "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", - "dev": true, + "node_modules/react-native/node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "peer": true, "dependencies": { - "isarray": "0.0.1" - } - }, - "node_modules/path-to-regexp/node_modules/isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8=", - "dev": true - }, - "node_modules/path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true, + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, "engines": { - "node": ">=8" + "node": ">=12" } }, - "node_modules/pathval": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", - "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", - "dev": true, + "node_modules/react-native/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "peer": true, + "dependencies": { + "color-name": "~1.1.4" + }, "engines": { - "node": "*" + "node": ">=7.0.0" } }, - "node_modules/pend": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", - "integrity": "sha1-elfrVQpng/kRUzH89GY9XI4AelA=", - "dev": true - }, - "node_modules/performance-now": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", - "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=", - "dev": true + "node_modules/react-native/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "peer": true }, - "node_modules/phantomjs-prebuilt": { - "version": "2.1.16", - "resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.16.tgz", - "integrity": "sha1-79ISpKOWbTZHaE6ouniFSb4q7+8=", - "deprecated": "this package is now deprecated", - "dev": true, - "hasInstallScript": true, + "node_modules/react-native/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "peer": true, "dependencies": { - "es6-promise": "^4.0.3", - "extract-zip": "^1.6.5", - "fs-extra": "^1.0.0", - "hasha": "^2.2.0", - "kew": "^0.7.0", - "progress": "^1.1.8", - "request": "^2.81.0", - "request-progress": "^2.0.1", - "which": "^1.2.10" + "minimist": "^1.2.6" }, "bin": { - "phantomjs": "bin/phantomjs" + "mkdirp": "bin/cmd.js" } }, - "node_modules/phantomjs-prebuilt/node_modules/progress": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz", - "integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=", - "dev": true, + "node_modules/react-native/node_modules/pretty-format": { + "version": "26.6.2", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", + "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", + "peer": true, + "dependencies": { + "@jest/types": "^26.6.2", + "ansi-regex": "^5.0.0", + "ansi-styles": "^4.0.0", + "react-is": "^17.0.1" + }, "engines": { - "node": ">=0.4.0" + "node": ">= 10" } }, - "node_modules/picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, - "engines": { - "node": ">=8.6" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } + "node_modules/react-native/node_modules/react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", + "peer": true }, - "node_modules/pinkie": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", - "integrity": "sha1-clVrgM+g1IqXToDnckjoDtT3+HA=", - "dev": true, - "engines": { - "node": ">=0.10.0" - } + "node_modules/react-native/node_modules/regenerator-runtime": { + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", + "peer": true }, - "node_modules/pinkie-promise": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", - "integrity": "sha1-ITXW36ejWMBprJsXh3YogihFD/o=", - "dev": true, + "node_modules/react-native/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "peer": true, "dependencies": { - "pinkie": "^2.0.0" + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" }, "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/prettier": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz", - "integrity": "sha512-vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==", - "dev": true, - "bin": { - "prettier": "bin-prettier.js" + "node": ">=10" }, - "engines": { - "node": ">=10.13.0" + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/prettier-linter-helpers": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", - "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", - "dev": true, + "node_modules/react-native/node_modules/ws": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", + "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", + "peer": true, "dependencies": { - "fast-diff": "^1.1.2" - }, - "engines": { - "node": ">=6.0.0" + "async-limiter": "~1.0.0" } }, - "node_modules/pretty-format": { - "version": "27.5.1", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz", - "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==", - "dev": true, + "node_modules/react-native/node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "peer": true, "dependencies": { - "ansi-regex": "^5.0.1", - "ansi-styles": "^5.0.0", - "react-is": "^17.0.1" + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" }, "engines": { - "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0" + "node": ">=12" } }, - "node_modules/pretty-format/node_modules/ansi-styles": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", - "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", - "dev": true, + "node_modules/react-native/node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "peer": true, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "node": ">=12" } }, - "node_modules/pretty-format/node_modules/react-is": { - "version": "17.0.2", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", - "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", - "dev": true - }, - "node_modules/process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", - "dev": true - }, - "node_modules/progress": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", - "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", - "dev": true, + "node_modules/react-refresh": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz", + "integrity": "sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==", + "peer": true, "engines": { - "node": ">=0.4.0" + "node": ">=0.10.0" } }, - "node_modules/propagate": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/propagate/-/propagate-1.0.0.tgz", - "integrity": "sha1-AMLa7t2iDofjeCs0Stuhzd1q1wk=", - "dev": true, - "engines": [ - "node >= 0.8.1" - ] + "node_modules/react-shallow-renderer": { + "version": "16.15.0", + "resolved": "https://registry.npmjs.org/react-shallow-renderer/-/react-shallow-renderer-16.15.0.tgz", + "integrity": "sha512-oScf2FqQ9LFVQgA73vr86xl2NaOIX73rh+YFqcOp68CWj56tSfgtGKrEbyhCj0rSijyG9M1CYprTh39fBi5hzA==", + "peer": true, + "dependencies": { + "object-assign": "^4.1.1", + "react-is": "^16.12.0 || ^17.0.0 || ^18.0.0" + }, + "peerDependencies": { + "react": "^16.0.0 || ^17.0.0 || ^18.0.0" + } }, - "node_modules/proxy-agent": { - "version": "6.3.1", - "resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-6.3.1.tgz", - "integrity": "sha512-Rb5RVBy1iyqOtNl15Cw/llpeLH8bsb37gM1FUfKQ+Wck6xHlbAhWGUFiTRHtkjqGTA5pSHz6+0hrPW/oECihPQ==", + "node_modules/read-pkg": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", + "integrity": "sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==", + "dev": true, "dependencies": { - "agent-base": "^7.0.2", - "debug": "^4.3.4", - "http-proxy-agent": "^7.0.0", - "https-proxy-agent": "^7.0.2", - "lru-cache": "^7.14.1", - "pac-proxy-agent": "^7.0.1", - "proxy-from-env": "^1.1.0", - "socks-proxy-agent": "^8.0.2" + "@types/normalize-package-data": "^2.4.0", + "normalize-package-data": "^2.5.0", + "parse-json": "^5.0.0", + "type-fest": "^0.6.0" }, "engines": { - "node": ">= 14" + "node": ">=8" } }, - "node_modules/proxy-agent/node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "node_modules/read-pkg-up": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz", + "integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==", + "dev": true, "dependencies": { - "ms": "2.1.2" + "find-up": "^4.1.0", + "read-pkg": "^5.2.0", + "type-fest": "^0.8.1" }, "engines": { - "node": ">=6.0" + "node": ">=8" }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" - }, - "node_modules/psl": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", - "integrity": "sha512-RIdOzyoavK+hA18OGGWDqUTsCLhtA7IcZ/6NCs4fFJaHBDab+pDDmDIByWFRQJq2Cd7r1OoQxBGKOaztq+hjIQ==", - "dev": true - }, - "node_modules/punycode": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", + "node_modules/read-pkg-up/node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", "dev": true, + "dependencies": { + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, "engines": { - "node": ">=6" + "node": ">=8" } }, - "node_modules/qjobs": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", - "integrity": "sha512-8YOJEHtxpySA3fFDyCRxA+UUV+fA+rTWnuWvylOK/NCjhY+b4ocCtmu8TtsWb+mYeU+GCHf/S66KZF/AsteKHg==", + "node_modules/read-pkg-up/node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", "dev": true, + "dependencies": { + "p-locate": "^4.1.0" + }, "engines": { - "node": ">=0.9" + "node": ">=8" } }, - "node_modules/qs": { - "version": "6.9.7", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.7.tgz", - "integrity": "sha512-IhMFgUmuNpyRfxA90umL7ByLlgRXu6tIfKPpF5TmcfRLlLCckfP/g3IQmju6jjpu+Hh8rA+2p6A27ZSPOOHdKw==", + "node_modules/read-pkg-up/node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", "dev": true, + "dependencies": { + "p-try": "^2.0.0" + }, "engines": { - "node": ">=0.6" + "node": ">=6" }, "funding": { - "url": "https://github.com/sponsors/ljharb" + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/queue-microtask": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/queue-microtask/-/queue-microtask-1.2.3.tgz", - "integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==", - "dev": true, - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ] - }, - "node_modules/ramda": { - "version": "0.27.2", - "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.27.2.tgz", - "integrity": "sha512-SbiLPU40JuJniHexQSAgad32hfwd+DRUdwF2PlVuI5RZD0/vahUco7R8vD86J/tcEKKF9vZrUVwgtmGCqlCKyA==", - "dev": true - }, - "node_modules/randombytes": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", - "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", + "node_modules/read-pkg-up/node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", "dev": true, "dependencies": { - "safe-buffer": "^5.1.0" + "p-limit": "^2.2.0" + }, + "engines": { + "node": ">=8" } }, - "node_modules/range-parser": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", - "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "node_modules/read-pkg-up/node_modules/type-fest": { + "version": "0.8.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", + "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", "dev": true, "engines": { - "node": ">= 0.6" + "node": ">=8" } }, - "node_modules/raw-body": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.4.3.tgz", - "integrity": "sha512-UlTNLIcu0uzb4D2f4WltY6cVjLi+/jEN4lgEUj3E04tpMDpUlkBo/eSn6zou9hum2VMNpCCUone0O0WeJim07g==", + "node_modules/read-pkg/node_modules/type-fest": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", + "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", "dev": true, - "dependencies": { - "bytes": "3.1.2", - "http-errors": "1.8.1", - "iconv-lite": "0.4.24", - "unpipe": "1.0.0" - }, "engines": { - "node": ">= 0.8" + "node": ">=8" } }, "node_modules/readable-stream": { - "version": "2.3.7", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.7.tgz", - "integrity": "sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw==", - "dev": true, + "version": "2.3.8", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", + "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -6074,19 +12386,79 @@ "node": ">=8.10.0" } }, + "node_modules/readline": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", + "integrity": "sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg==", + "peer": true + }, + "node_modules/recast": { + "version": "0.21.5", + "resolved": "https://registry.npmjs.org/recast/-/recast-0.21.5.tgz", + "integrity": "sha512-hjMmLaUXAm1hIuTqOdeYObMslq/q+Xff6QE3Y2P+uoHAg2nmVlLBps2hzh1UJDdMtDTMXOFewK6ky51JQIeECg==", + "peer": true, + "dependencies": { + "ast-types": "0.15.2", + "esprima": "~4.0.0", + "source-map": "~0.6.1", + "tslib": "^2.0.1" + }, + "engines": { + "node": ">= 4" + } + }, + "node_modules/recast/node_modules/ast-types": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.15.2.tgz", + "integrity": "sha512-c27loCv9QkZinsa5ProX751khO9DJl/AcB5c2KNtA6NRvHKS0PgLfcftz72KVq504vB0Gku5s2kUZzDBvQWvHg==", + "peer": true, + "dependencies": { + "tslib": "^2.0.1" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/reflect-metadata": { - "version": "0.1.13", - "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", - "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==", + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.1.tgz", + "integrity": "sha512-i5lLI6iw9AU3Uu4szRNPPEkomnkjRTaVt9hy/bn5g/oSzekBSMeLZblcjP74AW0vBabqERLLIrz+gR8QYR54Tw==", + "deprecated": "This version has a critical bug in fallback handling. Please upgrade to reflect-metadata@0.2.2 or newer.", "dev": true }, + "node_modules/regenerate": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", + "integrity": "sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==", + "peer": true + }, + "node_modules/regenerate-unicode-properties": { + "version": "10.1.1", + "resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-10.1.1.tgz", + "integrity": "sha512-X007RyZLsCJVVrjgEFVpLUTZwyOZk3oiL75ZcuYjlIWd6rNJtOjkBwQc5AsRrpbKVkxN6sklw/k/9m2jJYOf8Q==", + "peer": true, + "dependencies": { + "regenerate": "^1.4.2" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/regenerator-runtime": { - "version": "0.13.11", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", - "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", - "dev": true, + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", "peer": true }, + "node_modules/regenerator-transform": { + "version": "0.15.2", + "resolved": "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.15.2.tgz", + "integrity": "sha512-hfMp2BoF0qOk3uc5V20ALGDS2ddjQaLrdl7xrGXvAIow7qeWRM2VA2HuCHkUKk9slq3VwEwLNK3DFBqDfPGYtg==", + "peer": true, + "dependencies": { + "@babel/runtime": "^7.8.4" + } + }, "node_modules/regexp-match-indices": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/regexp-match-indices/-/regexp-match-indices-1.0.2.tgz", @@ -6097,22 +12469,24 @@ } }, "node_modules/regexp-tree": { - "version": "0.1.24", - "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.24.tgz", - "integrity": "sha512-s2aEVuLhvnVJW6s/iPgEGK6R+/xngd2jNQ+xy4bXNDKxZKJH6jpPHY6kVeVv1IeLCHgswRj+Kl3ELaDjG6V1iw==", + "version": "0.1.27", + "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.27.tgz", + "integrity": "sha512-iETxpjK6YoRWJG5o6hXLwvjYAoW+FEZn9os0PD/b6AP6xQwsa/Y7lCVgIixBbUPMfhu+i2LtdeAqVTgGlQarfA==", "dev": true, "bin": { "regexp-tree": "bin/regexp-tree" } }, "node_modules/regexp.prototype.flags": { - "version": "1.4.1", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.1.tgz", - "integrity": "sha512-pMR7hBVUUGI7PMA37m2ofIdQCsomVnas+Jn5UPGAHQ+/LlwKm/aTLJHdasmHRzlfeZwHiAOaRSo2rbBDm3nNUQ==", + "version": "1.5.2", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", + "integrity": "sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==", "dev": true, "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3" + "call-bind": "^1.0.6", + "define-properties": "^1.2.1", + "es-errors": "^1.3.0", + "set-function-name": "^2.0.1" }, "engines": { "node": ">= 0.4" @@ -6121,22 +12495,48 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/regexpp": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", - "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", - "dev": true, + "node_modules/regexpu-core": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-5.3.2.tgz", + "integrity": "sha512-RAM5FlZz+Lhmo7db9L298p2vHP5ZywrVXmVXpmAD9GuL5MPH6t9ROw1iA/wfHkQ76Qe7AaPF0nGuim96/IrQMQ==", + "peer": true, + "dependencies": { + "@babel/regjsgen": "^0.8.0", + "regenerate": "^1.4.2", + "regenerate-unicode-properties": "^10.1.0", + "regjsparser": "^0.9.1", + "unicode-match-property-ecmascript": "^2.0.0", + "unicode-match-property-value-ecmascript": "^2.1.0" + }, "engines": { - "node": ">=8" + "node": ">=4" + } + }, + "node_modules/regjsparser": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.9.1.tgz", + "integrity": "sha512-dQUtn90WanSNl+7mQKcXAgZxvUe7Z0SqXlgzv0za4LwiUhyzBC58yQO3liFoUgu8GiJVInAhJjkj1N0EtQ5nkQ==", + "peer": true, + "dependencies": { + "jsesc": "~0.5.0" }, - "funding": { - "url": "https://github.com/sponsors/mysticatea" + "bin": { + "regjsparser": "bin/parser" + } + }, + "node_modules/regjsparser/node_modules/jsesc": { + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", + "integrity": "sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==", + "peer": true, + "bin": { + "jsesc": "bin/jsesc" } }, "node_modules/repeat-string": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", - "integrity": "sha1-jcrkcOHIirwtYA//Sndihtp15jc=", + "integrity": "sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==", "dev": true, "engines": { "node": ">=0.10" @@ -6177,12 +12577,26 @@ "node_modules/request-progress": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/request-progress/-/request-progress-2.0.1.tgz", - "integrity": "sha1-XTa7V5YcZzqlt4jbyBQf3yO0Tgg=", + "integrity": "sha512-dxdraeZVUNEn9AvLrxkgB2k6buTlym71dJk1fk4v8j3Ou3RKNm07BcgbHdj2lLgYGfqX71F+awb1MR+tWPFJzA==", "dev": true, "dependencies": { "throttleit": "^1.0.0" } }, + "node_modules/request/node_modules/form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 0.12" + } + }, "node_modules/request/node_modules/qs": { "version": "6.5.3", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", @@ -6205,8 +12619,7 @@ "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", - "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=", - "dev": true, + "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", "engines": { "node": ">=0.10.0" } @@ -6215,21 +12628,20 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", - "dev": true + "peer": true }, "node_modules/requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", - "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=", + "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", "dev": true }, "node_modules/resolve": { - "version": "1.22.0", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz", - "integrity": "sha512-Hhtrw0nLeSrFQ7phPp4OOcVjLPIeMnRlr5mcnVuMe7M/7eBn98A3hmFRLoFo3DLZkivSYwhRUJTyPyWAk56WLw==", - "dev": true, + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", "dependencies": { - "is-core-module": "^2.8.1", + "is-core-module": "^2.13.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, @@ -6261,6 +12673,15 @@ "node": ">=8" } }, + "node_modules/resolve-pkg-maps": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", + "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", + "dev": true, + "funding": { + "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" + } + }, "node_modules/resolve-pkg/node_modules/resolve-from": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", @@ -6270,6 +12691,25 @@ "node": ">=8" } }, + "node_modules/restore-cursor": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", + "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", + "peer": true, + "dependencies": { + "onetime": "^5.1.0", + "signal-exit": "^3.0.2" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/restore-cursor/node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "peer": true + }, "node_modules/reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -6281,16 +12721,15 @@ } }, "node_modules/rfdc": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.0.tgz", - "integrity": "sha512-V2hovdzFbOi77/WajaSMXk2OLm+xNIeQdMMuB7icj7bk6zi2F8GGAxigcnDFpJHbNyNcgyJDiP+8nOrY5cZGrA==", + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.1.tgz", + "integrity": "sha512-r5a3l5HzYlIC68TpmYKlxWjmOP6wiPJ1vWv2HeLhNsRZMrCkxeqxiHlQ21oXmQ4F3SiryXBHhAD7JZqvOJjFmg==", "dev": true }, "node_modules/rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", - "dev": true, "dependencies": { "glob": "^7.1.3" }, @@ -6301,25 +12740,84 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/rimraf/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/rimraf/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/rimraf/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/rollup": { - "version": "2.68.0", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.68.0.tgz", - "integrity": "sha512-XrMKOYK7oQcTio4wyTz466mucnd8LzkiZLozZ4Rz0zQD+HeX4nUK4B8GrTX/2EvN2/vBF/i2WnaXboPxo0JylA==", + "version": "4.14.3", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.14.3.tgz", + "integrity": "sha512-ag5tTQKYsj1bhrFC9+OEWqb5O6VYgtQDO9hPDBMmIbePwhfSr+ExlcU741t8Dhw5DkPCQf6noz0jb36D6W9/hw==", "dev": true, + "dependencies": { + "@types/estree": "1.0.5" + }, "bin": { "rollup": "dist/bin/rollup" }, "engines": { - "node": ">=10.0.0" + "node": ">=18.0.0", + "npm": ">=8.0.0" }, "optionalDependencies": { + "@rollup/rollup-android-arm-eabi": "4.14.3", + "@rollup/rollup-android-arm64": "4.14.3", + "@rollup/rollup-darwin-arm64": "4.14.3", + "@rollup/rollup-darwin-x64": "4.14.3", + "@rollup/rollup-linux-arm-gnueabihf": "4.14.3", + "@rollup/rollup-linux-arm-musleabihf": "4.14.3", + "@rollup/rollup-linux-arm64-gnu": "4.14.3", + "@rollup/rollup-linux-arm64-musl": "4.14.3", + "@rollup/rollup-linux-powerpc64le-gnu": "4.14.3", + "@rollup/rollup-linux-riscv64-gnu": "4.14.3", + "@rollup/rollup-linux-s390x-gnu": "4.14.3", + "@rollup/rollup-linux-x64-gnu": "4.14.3", + "@rollup/rollup-linux-x64-musl": "4.14.3", + "@rollup/rollup-win32-arm64-msvc": "4.14.3", + "@rollup/rollup-win32-ia32-msvc": "4.14.3", + "@rollup/rollup-win32-x64-msvc": "4.14.3", "fsevents": "~2.3.2" } }, "node_modules/rollup-plugin-gzip": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/rollup-plugin-gzip/-/rollup-plugin-gzip-3.0.1.tgz", - "integrity": "sha512-yzyrbe5cn/3yTqtGpVb+0kQXiqKLZpNpRTGpItc11b8c9IhawpjZPPLMkh1Q7gl6UsHIVjcw9LeEdvom9H3klw==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/rollup-plugin-gzip/-/rollup-plugin-gzip-3.1.2.tgz", + "integrity": "sha512-9xemMyvCjkklgNpu6jCYqQAbvCLJzA2nilkiOGzFuXTUX3cXEFMwIhsIBRF7kTKD/SnZ1tNPcxFm4m4zJ3VfNQ==", "dev": true, "engines": { "node": ">=10.0.0" @@ -6328,21 +12826,30 @@ "rollup": ">=2.0.0" } }, - "node_modules/rollup-plugin-terser": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-7.0.2.tgz", - "integrity": "sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==", + "node_modules/rollup-plugin-string": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-string/-/rollup-plugin-string-3.0.0.tgz", + "integrity": "sha512-vqyzgn9QefAgeKi+Y4A7jETeIAU1zQmS6VotH6bzm/zmUQEnYkpIGRaOBPY41oiWYV4JyBoGAaBjYMYuv+6wVw==", "dev": true, "dependencies": { - "@babel/code-frame": "^7.10.4", - "jest-worker": "^26.2.1", - "serialize-javascript": "^4.0.0", - "terser": "^5.0.0" - }, - "peerDependencies": { - "rollup": "^2.0.0" + "rollup-pluginutils": "^2.4.1" } }, + "node_modules/rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "dependencies": { + "estree-walker": "^0.6.1" + } + }, + "node_modules/rollup-pluginutils/node_modules/estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -6369,8 +12876,7 @@ "node_modules/safe-buffer": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "dev": true + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "node_modules/safer-buffer": { "version": "2.1.2", @@ -6378,16 +12884,25 @@ "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", "dev": true }, + "node_modules/scheduler": { + "version": "0.24.0-canary-efb381bbf-20230505", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.24.0-canary-efb381bbf-20230505.tgz", + "integrity": "sha512-ABvovCDe/k9IluqSh4/ISoq8tIJnW8euVAWYt5j/bg6dRnqwQwiGO1F/V4AyK96NGF/FB04FhOUDuWj8IKfABA==", + "peer": true, + "dependencies": { + "loose-envify": "^1.1.0" + } + }, "node_modules/seed-random": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/seed-random/-/seed-random-2.2.0.tgz", - "integrity": "sha1-KpsZ4lCoFwmSMaW5mk2vgLf77VQ=", + "integrity": "sha512-34EQV6AAHQGhoc0tn/96a9Fsi6v2xdqe/dMUwljGRaFOzR3EgRmECvD0O8vi8X+/uQ50LGHfkNu/Eue5TPKZkQ==", "dev": true }, "node_modules/semver": { - "version": "7.3.8", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", - "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", "dependencies": { "lru-cache": "^6.0.0" }, @@ -6409,10 +12924,71 @@ "node": ">=10" } }, - "node_modules/semver/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "node_modules/send": { + "version": "0.18.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", + "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "peer": true, + "dependencies": { + "debug": "2.6.9", + "depd": "2.0.0", + "destroy": "1.2.0", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "2.0.0", + "mime": "1.6.0", + "ms": "2.1.3", + "on-finished": "2.4.1", + "range-parser": "~1.2.1", + "statuses": "2.0.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/send/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "peer": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/send/node_modules/debug/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "peer": true + }, + "node_modules/send/node_modules/mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "peer": true, + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/send/node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "peer": true + }, + "node_modules/send/node_modules/statuses": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", + "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "peer": true, + "engines": { + "node": ">= 0.8" + } }, "node_modules/serialize-error": { "version": "4.1.0", @@ -6438,31 +13014,88 @@ } }, "node_modules/serialize-javascript": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-4.0.0.tgz", - "integrity": "sha512-GaNA54380uFefWghODBWEGisLZFj00nS5ACs6yHa9nLqlLpVLO8ChDGeKRjZnV4Nh4n0Qi7nhYZD/9fCPzEqkw==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", + "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", "dev": true, "dependencies": { "randombytes": "^2.1.0" } }, + "node_modules/serve-static": { + "version": "1.15.0", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", + "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", + "peer": true, + "dependencies": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.3", + "send": "0.18.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/set-blocking": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", - "dev": true + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "peer": true + }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dev": true, + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/set-function-name": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.2.tgz", + "integrity": "sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==", + "dev": true, + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "functions-have-names": "^1.2.3", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } }, "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", - "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", - "dev": true + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + }, + "node_modules/shallow-clone": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz", + "integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==", + "peer": true, + "dependencies": { + "kind-of": "^6.0.2" + }, + "engines": { + "node": ">=8" + } }, "node_modules/shebang-command": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", - "dev": true, "dependencies": { "shebang-regex": "^3.0.0" }, @@ -6474,28 +13107,54 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", - "dev": true, "engines": { "node": ">=8" } }, + "node_modules/shell-quote": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", + "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", + "peer": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/side-channel": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", - "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", + "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "dev": true, "dependencies": { - "call-bind": "^1.0.0", - "get-intrinsic": "^1.0.2", - "object-inspect": "^1.9.0" + "call-bind": "^1.0.7", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/sinon": { "version": "7.5.0", "resolved": "https://registry.npmjs.org/sinon/-/sinon-7.5.0.tgz", "integrity": "sha512-AoD0oJWerp0/rY9czP/D6hDTTUYGpObhZjMpd7Cl/A6+j0xBE+ayL/ldfggkBXUs0IkvIiM1ljM8+WkOc5k78Q==", + "deprecated": "16.1.1", "dev": true, "dependencies": { "@sinonjs/commons": "^1.4.0", @@ -6526,157 +13185,151 @@ "node": ">=0.3.1" } }, - "node_modules/slash": { + "node_modules/sinon/node_modules/has-flag": { "version": "3.0.0", - "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", - "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", "dev": true, "engines": { - "node": ">=8" - } - }, - "node_modules/smart-buffer": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", - "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", - "engines": { - "node": ">= 6.0.0", - "npm": ">= 3.0.0" + "node": ">=4" } }, - "node_modules/socket.io": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-2.4.1.tgz", - "integrity": "sha512-Si18v0mMXGAqLqCVpTxBa8MGqriHGQh8ccEOhmsmNS3thNCGBwO8WGrwMibANsWtQQ5NStdZwHqZR3naJVFc3w==", + "node_modules/sinon/node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "dev": true, "dependencies": { - "debug": "~4.1.0", - "engine.io": "~3.5.0", - "has-binary2": "~1.0.2", - "socket.io-adapter": "~1.1.0", - "socket.io-client": "2.4.0", - "socket.io-parser": "~3.4.0" + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" } }, - "node_modules/socket.io-adapter": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-1.1.2.tgz", - "integrity": "sha512-WzZRUj1kUjrTIrUKpZLEzFZ1OLj5FwLlAFQs9kuZJzJi5DKdU7FsWc36SNmA8iDOtwBQyT8FkrriRM8vXLYz8g==", - "dev": true + "node_modules/sisteransi": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", + "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", + "peer": true }, - "node_modules/socket.io-client": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-2.4.0.tgz", - "integrity": "sha512-M6xhnKQHuuZd4Ba9vltCLT9oa+YvTsP8j9NcEiLElfIg8KeYPyhWOes6x4t+LTAC8enQbE/995AdTem2uNyKKQ==", - "dev": true, - "dependencies": { - "backo2": "1.0.2", - "component-bind": "1.0.0", - "component-emitter": "~1.3.0", - "debug": "~3.1.0", - "engine.io-client": "~3.5.0", - "has-binary2": "~1.0.2", - "indexof": "0.0.1", - "parseqs": "0.0.6", - "parseuri": "0.0.6", - "socket.io-parser": "~3.3.0", - "to-array": "0.1.4" + "node_modules/slash": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", + "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "engines": { + "node": ">=8" } }, - "node_modules/socket.io-client/node_modules/debug": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", - "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", - "dev": true, + "node_modules/slice-ansi": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", + "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", + "peer": true, "dependencies": { - "ms": "2.0.0" + "ansi-styles": "^3.2.0", + "astral-regex": "^1.0.0", + "is-fullwidth-code-point": "^2.0.0" + }, + "engines": { + "node": ">=6" } }, - "node_modules/socket.io-client/node_modules/isarray": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz", - "integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4=", - "dev": true + "node_modules/slice-ansi/node_modules/ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "peer": true, + "dependencies": { + "color-convert": "^1.9.0" + }, + "engines": { + "node": ">=4" + } }, - "node_modules/socket.io-client/node_modules/ms": { + "node_modules/slice-ansi/node_modules/is-fullwidth-code-point": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=", - "dev": true + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==", + "peer": true, + "engines": { + "node": ">=4" + } }, - "node_modules/socket.io-client/node_modules/socket.io-parser": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.3.2.tgz", - "integrity": "sha512-FJvDBuOALxdCI9qwRrO/Rfp9yfndRtc1jSgVgV8FDraihmSP/MLGD5PEuJrNfjALvcQ+vMDM/33AWOYP/JSjDg==", - "dev": true, - "dependencies": { - "component-emitter": "~1.3.0", - "debug": "~3.1.0", - "isarray": "2.0.1" + "node_modules/smart-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", + "engines": { + "node": ">= 6.0.0", + "npm": ">= 3.0.0" } }, - "node_modules/socket.io-parser": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.4.1.tgz", - "integrity": "sha512-11hMgzL+WCLWf1uFtHSNvliI++tcRUWdoeYuwIl+Axvwy9z2gQM+7nJyN3STj1tLj5JyIUH8/gpDGxzAlDdi0A==", + "node_modules/smob": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/smob/-/smob-1.5.0.tgz", + "integrity": "sha512-g6T+p7QO8npa+/hNx9ohv1E5pVCmWrVCUzUXJyLdMmftX6ER0oiWY/w9knEonLpnOp6b6FenKnMfR8gqwWdwig==", + "dev": true + }, + "node_modules/socket.io": { + "version": "4.7.5", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.5.tgz", + "integrity": "sha512-DmeAkF6cwM9jSfmp6Dr/5/mfMwb5Z5qRrSXLpo3Fq5SqyU8CMF15jIN4ZhfSwu35ksM1qmHZDQ/DK5XTccSTvA==", "dev": true, "dependencies": { - "component-emitter": "1.2.1", - "debug": "~4.1.0", - "isarray": "2.0.1" + "accepts": "~1.3.4", + "base64id": "~2.0.0", + "cors": "~2.8.5", + "debug": "~4.3.2", + "engine.io": "~6.5.2", + "socket.io-adapter": "~2.5.2", + "socket.io-parser": "~4.2.4" + }, + "engines": { + "node": ">=10.2.0" } }, - "node_modules/socket.io-parser/node_modules/component-emitter": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz", - "integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=", - "dev": true - }, - "node_modules/socket.io-parser/node_modules/debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "deprecated": "Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)", + "node_modules/socket.io-adapter": { + "version": "2.5.4", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.4.tgz", + "integrity": "sha512-wDNHGXGewWAjQPt3pyeYBtpWSq9cLE5UW1ZUPL/2eGK9jtse/FpXib7epSTsz0Q0m+6sg6Y4KtcFTlah1bdOVg==", "dev": true, "dependencies": { - "ms": "^2.1.1" + "debug": "~4.3.4", + "ws": "~8.11.0" } }, - "node_modules/socket.io-parser/node_modules/isarray": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz", - "integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4=", - "dev": true - }, - "node_modules/socket.io/node_modules/debug": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", - "deprecated": "Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/debug/issues/797)", + "node_modules/socket.io-parser": { + "version": "4.2.4", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", + "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", "dev": true, "dependencies": { - "ms": "^2.1.1" + "@socket.io/component-emitter": "~3.1.0", + "debug": "~4.3.1" + }, + "engines": { + "node": ">=10.0.0" } }, "node_modules/socks": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", - "integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==", + "version": "2.8.3", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz", + "integrity": "sha512-l5x7VUUWbjVFbafGLxPWkYsHIhEvmF85tbIeFZWc8ZPtoMyybuEhL7Jye/ooC4/d48FgOjSJXgsF/AJPYCW8Zw==", "dependencies": { - "ip": "^2.0.0", + "ip-address": "^9.0.5", "smart-buffer": "^4.2.0" }, "engines": { - "node": ">= 10.13.0", + "node": ">= 10.0.0", "npm": ">= 3.0.0" } }, "node_modules/socks-proxy-agent": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.2.tgz", - "integrity": "sha512-8zuqoLv1aP/66PHF5TqwJ7Czm3Yv32urJQHrVyhD7mmA6d61Zv8cIXQYPTWwmg6qlupnPvs/QKDmfa4P/qct2g==", + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.3.tgz", + "integrity": "sha512-VNegTZKhuGq5vSD6XNKlbqWhyt/40CgoEw8XxD6dhnm8Jq9IEa3nIa4HwnM8XOqU0CdB0BwWVXusqiFXfHB3+A==", "dependencies": { - "agent-base": "^7.0.2", + "agent-base": "^7.1.1", "debug": "^4.3.4", "socks": "^2.7.1" }, @@ -6684,32 +13337,10 @@ "node": ">= 14" } }, - "node_modules/socks-proxy-agent/node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", - "dependencies": { - "ms": "2.1.2" - }, - "engines": { - "node": ">=6.0" - }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } - } - }, - "node_modules/socks/node_modules/ip": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.1.tgz", - "integrity": "sha512-lJUL9imLTNi1ZfXT+DU6rBBdbiKGBuay9B6xGSPVjUeQwaH1RIGqef8RZkUtHioLmSNpPR5M4HVKJGm1j8FWVQ==" - }, "node_modules/source-map": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", - "devOptional": true, "engines": { "node": ">=0.10.0" } @@ -6718,28 +13349,52 @@ "version": "0.5.21", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", - "dev": true, "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" } }, - "node_modules/sourcemap-codec": { - "version": "1.4.8", - "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", - "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "node_modules/spdx-correct": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.2.0.tgz", + "integrity": "sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==", + "dev": true, + "dependencies": { + "spdx-expression-parse": "^3.0.0", + "spdx-license-ids": "^3.0.0" + } + }, + "node_modules/spdx-exceptions": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.5.0.tgz", + "integrity": "sha512-PiU42r+xO4UbUS1buo3LPJkjlO7430Xn5SVAhdpzzsPHsjbYVflnnFdATgabnLude+Cqu25p6N+g2lw/PFsa4w==", + "dev": true + }, + "node_modules/spdx-expression-parse": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", + "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", + "dev": true, + "dependencies": { + "spdx-exceptions": "^2.1.0", + "spdx-license-ids": "^3.0.0" + } + }, + "node_modules/spdx-license-ids": { + "version": "3.0.17", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.17.tgz", + "integrity": "sha512-sh8PWc/ftMqAAdFiBu6Fy6JUOYjqDJBJvIhpfDMyHrr0Rbp5liZqd4TjtQ/RgfLjKFZb+LMx5hpml5qOWy0qvg==", "dev": true }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw=", - "dev": true + "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==" }, "node_modules/sshpk": { - "version": "1.17.0", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.17.0.tgz", - "integrity": "sha512-/9HIEs1ZXGhSPE8X6Ccm7Nam1z8KcoCqPdI7ecm1N33EzAetWahvQWVqLZtaZQ+IDKX4IyA2o0gBzqIMkAagHQ==", + "version": "1.18.0", + "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.18.0.tgz", + "integrity": "sha512-2p2KJZTSqQ/I3+HX42EpYOa2l3f8Erv8MWKsy2I9uf4wA7yFIkXRffYdsx86y6z4vHtV8u7g+pPlr8/4ouAxsQ==", "dev": true, "dependencies": { "asn1": "~0.2.3", @@ -6761,26 +13416,33 @@ "node": ">=0.10.0" } }, + "node_modules/sshpk/node_modules/jsbn": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", + "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==", + "dev": true + }, "node_modules/stack-chain": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/stack-chain/-/stack-chain-2.0.0.tgz", "integrity": "sha512-GGrHXePi305aW7XQweYZZwiRwR7Js3MWoK/EHzzB9ROdc75nCnjSJVi21rdAGxFl+yCx2L2qdfl5y7NO4lTyqg==", - "dev": true + "dev": true, + "peer": true }, "node_modules/stack-generator": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.5.tgz", - "integrity": "sha512-/t1ebrbHkrLrDuNMdeAcsvynWgoH/i4o8EGGfX7dEYDoTXOYVAkEpFdtshlvabzc6JlJ8Kf9YdFEoz7JkzGN9Q==", + "version": "2.0.10", + "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.10.tgz", + "integrity": "sha512-mwnua/hkqM6pF4k8SnmZ2zfETsRUpWXREfA/goT8SLCV4iOFa4bzOX2nDipWAZFPTjLvQB82f5yaodMVhK0yJQ==", "dev": true, + "peer": true, "dependencies": { - "stackframe": "^1.1.1" + "stackframe": "^1.3.4" } }, "node_modules/stack-utils": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.5.tgz", - "integrity": "sha512-xrQcmYhOsn/1kX+Vraq+7j4oE2j/6BFscZ0etmYg81xuM8Gq0022Pxb8+IqgOFUIaxHs0KaSb7T1+OegiNrNFA==", - "dev": true, + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.6.tgz", + "integrity": "sha512-XlkWvfIm6RmsWtNJx+uqtKLS8eqFbxUg0ZzLXqY0caEy9l7hruX8IpiDnjsLavoBgqCCR71TqWO8MaXYheJ3RQ==", "dependencies": { "escape-string-regexp": "^2.0.0" }, @@ -6788,36 +13450,28 @@ "node": ">=10" } }, - "node_modules/stack-utils/node_modules/escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/stackframe": { "version": "1.3.4", "resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.3.4.tgz", - "integrity": "sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==", - "dev": true + "integrity": "sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==" }, "node_modules/stacktrace-gps": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/stacktrace-gps/-/stacktrace-gps-3.0.4.tgz", - "integrity": "sha512-qIr8x41yZVSldqdqe6jciXEaSCKw1U8XTXpjDuy0ki/apyTn/r3w9hDAAQOhZdxvsC93H+WwwEu5cq5VemzYeg==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/stacktrace-gps/-/stacktrace-gps-3.1.2.tgz", + "integrity": "sha512-GcUgbO4Jsqqg6RxfyTHFiPxdPqF+3LFmQhm7MgCuYQOYuWyqxo5pwRPz5d/u6/WYJdEnWfK4r+jGbyD8TSggXQ==", "dev": true, + "peer": true, "dependencies": { "source-map": "0.5.6", - "stackframe": "^1.1.1" + "stackframe": "^1.3.4" } }, "node_modules/stacktrace-gps/node_modules/source-map": { "version": "0.5.6", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz", - "integrity": "sha1-dc449SvwczxafwwRjYEzSiu19BI=", + "integrity": "sha512-MjZkVp0NHr5+TPihLcadqnlVoGIoWo4IBHptutGh9wI3ttUYvCG26HkSuDi+K6lsZ25syXJXcctwgyVCt//xqA==", "dev": true, + "peer": true, "engines": { "node": ">=0.10.0" } @@ -6827,75 +13481,92 @@ "resolved": "https://registry.npmjs.org/stacktrace-js/-/stacktrace-js-2.0.2.tgz", "integrity": "sha512-Je5vBeY4S1r/RnLydLl0TBTi3F2qdfWmYsGvtfZgEI+SCprPppaIhQf5nGcal4gI4cGpCV/duLcAzT1np6sQqg==", "dev": true, + "peer": true, "dependencies": { "error-stack-parser": "^2.0.6", "stack-generator": "^2.0.5", "stacktrace-gps": "^3.0.4" } }, + "node_modules/stacktrace-parser": { + "version": "0.1.10", + "resolved": "https://registry.npmjs.org/stacktrace-parser/-/stacktrace-parser-0.1.10.tgz", + "integrity": "sha512-KJP1OCML99+8fhOHxwwzyWrlUuVX5GQ0ZpJTd1DFXhdkrvg1szxfHhawXUZ3g9TkXORQd4/WG68jMlQZ2p8wlg==", + "peer": true, + "dependencies": { + "type-fest": "^0.7.1" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/stacktrace-parser/node_modules/type-fest": { + "version": "0.7.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.7.1.tgz", + "integrity": "sha512-Ne2YiiGN8bmrmJJEuTWTLJR32nh/JdL1+PSicowtNb0WFpn59GK8/lfD61bVtzguz7b3PBt74nxpv/Pw5po5Rg==", + "peer": true, + "engines": { + "node": ">=8" + } + }, "node_modules/statuses": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", - "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=", - "dev": true, + "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", "engines": { "node": ">= 0.6" } }, "node_modules/streamroller": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-3.0.2.tgz", - "integrity": "sha512-ur6y5S5dopOaRXBuRIZ1u6GC5bcEXHRZKgfBjfCglMhmIf+roVCECjvkEYzNQOXIN2/JPnkMPW/8B3CZoKaEPA==", + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-3.1.5.tgz", + "integrity": "sha512-KFxaM7XT+irxvdqSP1LGLgNWbYN7ay5owZ3r/8t77p+EtSUAfUgtl7be3xtqtOmGUl9K9YPO2ca8133RlTjvKw==", "dev": true, "dependencies": { - "date-format": "^4.0.3", - "debug": "^4.1.1", - "fs-extra": "^10.0.0" + "date-format": "^4.0.14", + "debug": "^4.3.4", + "fs-extra": "^8.1.0" }, "engines": { "node": ">=8.0" } }, "node_modules/streamroller/node_modules/fs-extra": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.1.tgz", - "integrity": "sha512-NbdoVMZso2Lsrn/QwLXOy6rm0ufY2zEOKCDzJR/0kBsb0E6qed0P3iYK+Ath3BfvXEeu4JhEtXLgILx5psUfag==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", "dev": true, "dependencies": { "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" }, "engines": { - "node": ">=12" + "node": ">=6 <7 || >=8" } }, "node_modules/streamroller/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", "dev": true, - "dependencies": { - "universalify": "^2.0.0" - }, "optionalDependencies": { "graceful-fs": "^4.1.6" } }, "node_modules/streamroller/node_modules/universalify": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz", - "integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", "dev": true, "engines": { - "node": ">= 10.0.0" + "node": ">= 4.0.0" } }, "node_modules/string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "dev": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -6913,7 +13584,6 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", - "dev": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -6923,13 +13593,34 @@ "node": ">=8" } }, - "node_modules/string-width/node_modules/emoji-regex": { - "version": "8.0.0", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", - "dev": true + "node_modules/string-width-cjs": { + "name": "string-width", + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dev": true, + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } }, "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi-cjs": { + "name": "strip-ansi", "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", @@ -6941,16 +13632,42 @@ "node": ">=8" } }, + "node_modules/strip-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", - "integrity": "sha1-IzTBjpx1n3vdVv3vfprj1YjmjtM=", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", "dev": true, "optional": true, "engines": { "node": ">=4" } }, + "node_modules/strip-final-newline": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", + "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "peer": true, + "engines": { + "node": ">=6" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -6963,102 +13680,142 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/superagent": { - "version": "8.1.2", - "resolved": "https://registry.npmjs.org/superagent/-/superagent-8.1.2.tgz", - "integrity": "sha512-6WTxW1EB6yCxV5VFOIPQruWGHqc3yI7hEmZK6h+pyk69Lk/Ut7rLUY6W/ONF2MjBuGjvmMiIpsrVJ2vjrHlslA==", + "node_modules/strnum": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz", + "integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==", + "peer": true + }, + "node_modules/sudo-prompt": { + "version": "9.2.1", + "resolved": "https://registry.npmjs.org/sudo-prompt/-/sudo-prompt-9.2.1.tgz", + "integrity": "sha512-Mu7R0g4ig9TUuGSxJavny5Rv0egCEtpZRNMrZaYS1vxkiIxGiGUwoezU3LazIQ+KE04hTrTfNPgxU5gzi7F5Pw==", + "peer": true + }, + "node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", "dependencies": { - "component-emitter": "^1.3.0", - "cookiejar": "^2.1.4", - "debug": "^4.3.4", - "fast-safe-stringify": "^2.1.1", - "form-data": "^4.0.0", - "formidable": "^2.1.2", - "methods": "^1.1.2", - "mime": "2.6.0", - "qs": "^6.11.0", - "semver": "^7.3.8" + "has-flag": "^4.0.0" }, "engines": { - "node": ">=6.4.0 <13 || >=14" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/superagent/node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "node_modules/synckit": { + "version": "0.8.8", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.8.tgz", + "integrity": "sha512-HwOKAP7Wc5aRGYdKH+dw0PRRpbO841v2DENBtjnR5HFWoiNByAl7vrx3p0G/rCyYXQsrxqtX48TImFtPcIHSpQ==", + "dev": true, "dependencies": { - "ms": "2.1.2" + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" }, "engines": { - "node": ">=6.0" + "node": "^14.18.0 || >=16.0.0" }, - "peerDependenciesMeta": { - "supports-color": { - "optional": true - } + "funding": { + "url": "https://opencollective.com/unts" } }, - "node_modules/superagent/node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "node_modules/temp": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/temp/-/temp-0.8.4.tgz", + "integrity": "sha512-s0ZZzd0BzYv5tLSptZooSjK8oj6C+c19p7Vqta9+6NPOf7r+fxq0cJe6/oN4LTC79sy5NY8ucOJNgwsKCSbfqg==", + "peer": true, "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "mime-types": "^2.1.12" + "rimraf": "~2.6.2" }, "engines": { - "node": ">= 6" + "node": ">=6.0.0" + } + }, + "node_modules/temp-dir": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-2.0.0.tgz", + "integrity": "sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg==", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/temp/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "peer": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" } }, - "node_modules/superagent/node_modules/qs": { - "version": "6.11.2", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", - "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", + "node_modules/temp/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "peer": true, "dependencies": { - "side-channel": "^1.0.4" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" }, "engines": { - "node": ">=0.6" + "node": "*" }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dev": true, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/temp/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "peer": true, "dependencies": { - "has-flag": "^3.0.0" + "brace-expansion": "^1.1.7" }, "engines": { - "node": ">=4" + "node": "*" } }, - "node_modules/supports-preserve-symlinks-flag": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", - "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", - "dev": true, - "engines": { - "node": ">= 0.4" + "node_modules/temp/node_modules/rimraf": { + "version": "2.6.3", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", + "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "peer": true, + "dependencies": { + "glob": "^7.1.3" }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "bin": { + "rimraf": "bin.js" } }, "node_modules/terser": { - "version": "5.11.0", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.11.0.tgz", - "integrity": "sha512-uCA9DLanzzWSsN1UirKwylhhRz3aKPInlfmpGfw8VN6jHsAtu8HJtIpeeHHK23rxnE/cDc+yvmq5wqkIC6Kn0A==", - "dev": true, + "version": "5.30.3", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.30.3.tgz", + "integrity": "sha512-STdUgOUx8rLbMGO9IOwHLpCqolkDITFFQSMYYwKE1N2lY6MVSaeoi10z/EhWxRc6ybqoVmKSkhKYH/XUpl7vSA==", "dependencies": { - "acorn": "^8.5.0", + "@jridgewell/source-map": "^0.3.3", + "acorn": "^8.8.2", "commander": "^2.20.0", - "source-map": "~0.7.2", "source-map-support": "~0.5.20" }, "bin": { @@ -7071,22 +13828,18 @@ "node_modules/terser/node_modules/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, - "node_modules/terser/node_modules/source-map": { - "version": "0.7.3", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", - "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", - "dev": true, - "engines": { - "node": ">= 8" - } + "node_modules/text-encoding": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.7.0.tgz", + "integrity": "sha512-oJQ3f1hrOnbRLOcwKz0Liq2IcrvDeZRHXhd9RgLrsT+DjWY/nty1Hi7v3dtkaEYbPYe0mUoOfzRrMwfXXwgPUA==", + "deprecated": "no longer maintained" }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", - "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "dev": true }, "node_modules/thenify": { @@ -7101,7 +13854,7 @@ "node_modules/thenify-all": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", - "integrity": "sha1-GhkY1ALY/D+Y+/I02wvMjMEOlyY=", + "integrity": "sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==", "dev": true, "dependencies": { "thenify": ">= 3.1.0 < 4" @@ -7110,10 +13863,35 @@ "node": ">=0.8" } }, + "node_modules/throat": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/throat/-/throat-5.0.0.tgz", + "integrity": "sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==", + "peer": true + }, "node_modules/throttleit": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/throttleit/-/throttleit-1.0.0.tgz", - "integrity": "sha1-nnhYNtr0Z0MUWlmEtiaNgoUorGw=", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/throttleit/-/throttleit-1.0.1.tgz", + "integrity": "sha512-vDZpf9Chs9mAdfY046mcPt8fg5QSZr37hEH4TXYBnDF+izxgrbRGUAAaBvIk/fJm9aOFCGFd1EsNg5AZCbnQCQ==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/through2": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", + "integrity": "sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==", + "peer": true, + "dependencies": { + "readable-stream": "~2.3.6", + "xtend": "~4.0.1" + } + }, + "node_modules/tiny-case": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tiny-case/-/tiny-case-1.0.3.tgz", + "integrity": "sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==", "dev": true }, "node_modules/title-case": { @@ -7145,28 +13923,33 @@ } }, "node_modules/tmp": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.1.tgz", - "integrity": "sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==", + "version": "0.2.3", + "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", + "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==", "dev": true, - "dependencies": { - "rimraf": "^3.0.0" - }, "engines": { - "node": ">=8.17.0" + "node": ">=14.14" } }, - "node_modules/to-array": { - "version": "0.1.4", - "resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz", - "integrity": "sha1-F+bBH3PdTz10zaek/zI46a2b+JA=", - "dev": true + "node_modules/tmpl": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", + "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", + "peer": true + }, + "node_modules/to-fast-properties": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", + "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", + "peer": true, + "engines": { + "node": ">=4" + } }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", - "dev": true, "dependencies": { "is-number": "^7.0.0" }, @@ -7178,11 +13961,16 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", - "dev": true, "engines": { "node": ">=0.6" } }, + "node_modules/toposort": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz", + "integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==", + "dev": true + }, "node_modules/tough-cookie": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", @@ -7199,8 +13987,19 @@ "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=", - "dev": true + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/ts-api-utils": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", + "integrity": "sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==", + "dev": true, + "engines": { + "node": ">=16" + }, + "peerDependencies": { + "typescript": ">=4.2.0" + } }, "node_modules/ts-dedent": { "version": "2.2.0", @@ -7212,9 +14011,9 @@ } }, "node_modules/ts-mocha": { - "version": "9.0.2", - "resolved": "https://registry.npmjs.org/ts-mocha/-/ts-mocha-9.0.2.tgz", - "integrity": "sha512-WyQjvnzwrrubl0JT7EC1yWmNpcsU3fOuBFfdps30zbmFBgKniSaSOyZMZx+Wq7kytUs5CY+pEbSYEbGfIKnXTw==", + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/ts-mocha/-/ts-mocha-10.0.0.tgz", + "integrity": "sha512-VRfgDO+iiuJFlNB18tzOfypJ21xn2xbuZyDvJvqpTbWgkAgD17ONGr8t+Tl8rcBtOBdjXp5e/Rk+d39f7XBHRw==", "dev": true, "dependencies": { "ts-node": "7.0.1" @@ -7229,7 +14028,7 @@ "tsconfig-paths": "^3.5.0" }, "peerDependencies": { - "mocha": "^3.X.X || ^4.X.X || ^5.X.X || ^6.X.X || ^7.X.X || ^8.X.X || ^9.X.X" + "mocha": "^3.X.X || ^4.X.X || ^5.X.X || ^6.X.X || ^7.X.X || ^8.X.X || ^9.X.X || ^10.X.X" } }, "node_modules/ts-mocha/node_modules/diff": { @@ -7241,6 +14040,18 @@ "node": ">=0.3.1" } }, + "node_modules/ts-mocha/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/ts-mocha/node_modules/ts-node": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", @@ -7266,16 +14077,16 @@ "node_modules/ts-mocha/node_modules/yn": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", - "integrity": "sha1-5a2ryKz0CPY4X8dklWhMiOavaJo=", + "integrity": "sha512-uTv8J/wiWTgUTg+9vLTi//leUl5vDQS6uii/emeTb2ssY7vl6QWf2fFbIIGjnhjvbdKlU0ed7QPgY1htTC86jQ==", "dev": true, "engines": { "node": ">=4" } }, "node_modules/ts-node": { - "version": "10.9.1", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.1.tgz", - "integrity": "sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==", + "version": "10.9.2", + "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", + "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "dev": true, "dependencies": { "@cspotcode/source-map-support": "^0.8.0", @@ -7316,61 +14127,46 @@ } }, "node_modules/tsconfig-paths": { - "version": "3.12.0", - "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.12.0.tgz", - "integrity": "sha512-e5adrnOYT6zqVnWqZu7i/BQ3BnhzvGbjEjejFXO20lKIKpwTaupkCPgEfv4GZK1IBciJUEhYs3J3p75FdaTFVg==", + "version": "3.15.0", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", + "integrity": "sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==", "dev": true, "optional": true, "dependencies": { "@types/json5": "^0.0.29", - "json5": "^1.0.1", - "minimist": "^1.2.0", + "json5": "^1.0.2", + "minimist": "^1.2.6", "strip-bom": "^3.0.0" } }, - "node_modules/tsconfig-paths/node_modules/json5": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", - "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", - "dev": true, - "optional": true, - "dependencies": { - "minimist": "^1.2.0" - }, - "bin": { - "json5": "lib/cli.js" - } - }, "node_modules/tslib": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz", - "integrity": "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", + "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" }, - "node_modules/tsutils": { - "version": "3.21.0", - "resolved": "https://registry.npmjs.org/tsutils/-/tsutils-3.21.0.tgz", - "integrity": "sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==", + "node_modules/tsx": { + "version": "4.7.2", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.7.2.tgz", + "integrity": "sha512-BCNd4kz6fz12fyrgCTEdZHGJ9fWTGeUzXmQysh0RVocDY3h4frk05ZNCXSy4kIenF7y/QnrdiVpTsyNRn6vlAw==", "dev": true, "dependencies": { - "tslib": "^1.8.1" + "esbuild": "~0.19.10", + "get-tsconfig": "^4.7.2" + }, + "bin": { + "tsx": "dist/cli.mjs" }, "engines": { - "node": ">= 6" + "node": ">=18.0.0" }, - "peerDependencies": { - "typescript": ">=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta" + "optionalDependencies": { + "fsevents": "~2.3.3" } }, - "node_modules/tsutils/node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", - "dev": true - }, "node_modules/tunnel-agent": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha1-J6XeoGs2sEoKmWZ3SykIaPD8QP0=", + "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", "dev": true, "dependencies": { "safe-buffer": "^5.0.1" @@ -7382,31 +14178,43 @@ "node_modules/tweetnacl": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=", + "integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==", "dev": true }, "node_modules/type": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz", - "integrity": "sha512-+5nt5AAniqsCnu2cEQQdpzCAh33kVx8n0VoFidKpB1dVVLAN/F+bgVOqOJqOnEnrhp222clB5p3vUlD+1QAnfg==", - "dev": true + "version": "2.7.2", + "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", + "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==", + "dev": true, + "peer": true + }, + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } }, "node_modules/type-detect": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true, "engines": { "node": ">=4" } }, "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "version": "4.15.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.15.0.tgz", + "integrity": "sha512-tB9lu0pQpX5KJq54g+oHOLumOx+pMep4RaM6liXh2PKmVRFF+/vAtUP0ZaJ0kOySfVNjF6doBWPHhBhISKdlIA==", "dev": true, "engines": { - "node": ">=10" + "node": ">=16" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -7428,54 +14236,142 @@ "node_modules/typedarray": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", + "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", "dev": true }, "node_modules/typescript": { - "version": "4.8.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", - "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", "dev": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=4.2.0" + "node": ">=14.17" } }, "node_modules/ua-parser-js": { - "version": "0.7.22", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.22.tgz", - "integrity": "sha512-YUxzMjJ5T71w6a8WWVcMGM6YWOTX27rCoIQgLXiWaxqXSx9D7DNjiGWn1aJIRSQ5qr0xuhra77bSIh6voR/46Q==", + "version": "0.7.37", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.37.tgz", + "integrity": "sha512-xV8kqRKM+jhMvcHWUKthV9fNebIzrNy//2O9ZwWcfiBFR5f25XVZPLlEajk/sf3Ra15V92isyQqnIEXRDaZWEA==", "dev": true, + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/ua-parser-js" + }, + { + "type": "paypal", + "url": "https://paypal.me/faisalman" + }, + { + "type": "github", + "url": "https://github.com/sponsors/faisalman" + } + ], "engines": { "node": "*" } }, "node_modules/underscore": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.2.tgz", - "integrity": "sha512-ekY1NhRzq0B08g4bGuX4wd2jZx5GnKz6mKSqFL4nqBlfyMGiG10gDFhDTMEfYmDL6Jy0FUIZp7wiRB+0BP7J2g==", + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz", + "integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==", "dev": true }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + }, + "node_modules/unicode-canonical-property-names-ecmascript": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", + "integrity": "sha512-yY5PpDlfVIU5+y/BSCxAJRBIS1Zc2dDG3Ujq+sR0U+JjUevW2JhocOF+soROYDSaAezOzOKuyyixhD6mBknSmQ==", + "peer": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/unicode-match-property-ecmascript": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-2.0.0.tgz", + "integrity": "sha512-5kaZCrbp5mmbz5ulBkDkbY0SsPOjKqVS35VpL9ulMPfSl0J0Xsm+9Evphv9CoIZFwre7aJoa94AY6seMKGVN5Q==", + "peer": true, + "dependencies": { + "unicode-canonical-property-names-ecmascript": "^2.0.0", + "unicode-property-aliases-ecmascript": "^2.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/unicode-match-property-value-ecmascript": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-2.1.0.tgz", + "integrity": "sha512-qxkjQt6qjg/mYscYMC0XKRn3Rh0wFPlfxB0xkt9CfyTvpX1Ra0+rAmdX2QyAobptSEvuy4RtpPRui6XkV+8wjA==", + "peer": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/unicode-property-aliases-ecmascript": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-2.1.0.tgz", + "integrity": "sha512-6t3foTQI9qne+OZoVQB/8x8rk2k1eVy1gRXhV3oFQ5T6R1dqQ1xtin3XqSlx3+ATBkliTaR/hHyJBm+LVPNM8w==", + "peer": true, + "engines": { + "node": ">=4" + } + }, "node_modules/universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", + "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", "engines": { - "node": ">= 4.0.0" + "node": ">= 10.0.0" } }, "node_modules/unpipe": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", - "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=", - "dev": true, + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", "engines": { "node": ">= 0.8" } }, + "node_modules/update-browserslist-db": { + "version": "1.0.13", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", + "integrity": "sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg==", + "funding": [ + { + "type": "opencollective", + "url": "https://opencollective.com/browserslist" + }, + { + "type": "tidelift", + "url": "https://tidelift.com/funding/github/npm/browserslist" + }, + { + "type": "github", + "url": "https://github.com/sponsors/ai" + } + ], + "peer": true, + "dependencies": { + "escalade": "^3.1.1", + "picocolors": "^1.0.0" + }, + "bin": { + "update-browserslist-db": "cli.js" + }, + "peerDependencies": { + "browserslist": ">= 4.21.0" + } + }, "node_modules/upper-case": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz", @@ -7504,30 +14400,31 @@ "node_modules/util-arity": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/util-arity/-/util-arity-1.1.0.tgz", - "integrity": "sha1-WdAa8f2z/t4KxOYysKtfbOl8kzA=", + "integrity": "sha512-kkyIsXKwemfSy8ZEoaIz06ApApnWsk5hQO0vLjZS6UkBiGiW++Jsyb8vSBoc0WKlffGoGs5yYy/j5pp8zckrFA==", "dev": true }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", - "dev": true + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, "node_modules/utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", - "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=", - "dev": true, + "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", "engines": { "node": ">= 0.4.0" } }, "node_modules/uuid": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.0.tgz", - "integrity": "sha512-MXcSTerfPa4uqyzStbRoTgt5XIe3x5+42+q1sDuy3R5MDk66URdLMOZe5aPX/SQd+kuYAh0FdP/pO28IkQyTeg==", + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", "dev": true, - "peer": true, + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], "bin": { "uuid": "dist/bin/uuid" } @@ -7538,11 +14435,30 @@ "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", "dev": true }, + "node_modules/validate-npm-package-license": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", + "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", + "dev": true, + "dependencies": { + "spdx-correct": "^3.0.0", + "spdx-expression-parse": "^3.0.0" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "engines": { + "node": ">= 0.8" + } + }, "node_modules/verror": { "version": "1.10.1", "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.1.tgz", "integrity": "sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==", "dev": true, + "peer": true, "dependencies": { "assert-plus": "^1.0.0", "core-util-is": "1.0.2", @@ -7555,71 +14471,155 @@ "node_modules/verror/node_modules/core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", - "dev": true + "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", + "dev": true, + "peer": true + }, + "node_modules/vlq": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/vlq/-/vlq-1.0.1.tgz", + "integrity": "sha512-gQpnTgkubC6hQgdIcRdYGDSDc+SaujOdyesZQMv6JlfQee/9Mp0Qhnys6WxDWvQnL5WZdT7o2Ul187aSt0Rq+w==", + "peer": true }, "node_modules/void-elements": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-2.0.1.tgz", - "integrity": "sha1-wGavtYK7HLQSjWDqkjkulNXp2+w=", + "integrity": "sha512-qZKX4RnBzH2ugr8Lxa7x+0V6XD9Sb/ouARtiasEQCHB1EVU4NXtmHsDDrx1dO4ne5fc3J6EW05BP1Dl0z0iung==", "dev": true, "engines": { "node": ">=0.10.0" } }, + "node_modules/walker": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", + "integrity": "sha512-ts/8E8l5b7kY0vlWLewOkDXMmPdLcVV4GmOQLyxuSswIJsweeFZtAsMF7k1Nszz+TYBQrlYRmzOnr398y1JemQ==", + "peer": true, + "dependencies": { + "makeerror": "1.0.12" + } + }, + "node_modules/wcwidth": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", + "integrity": "sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==", + "peer": true, + "dependencies": { + "defaults": "^1.0.3" + } + }, "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=", - "dev": true + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/whatwg-fetch": { + "version": "3.6.20", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz", + "integrity": "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==", + "peer": true }, "node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha1-lmRU6HZUYuN2RNNib2dCzotwll0=", - "dev": true, + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" } }, - "node_modules/which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "dev": true, + "node_modules/whatwg-url-without-unicode": { + "version": "8.0.0-3", + "resolved": "https://registry.npmjs.org/whatwg-url-without-unicode/-/whatwg-url-without-unicode-8.0.0-3.tgz", + "integrity": "sha512-HoKuzZrUlgpz35YO27XgD28uh/WJH4B0+3ttFqRo//lmq+9T/mIOJ6kqmINI9HpUpz1imRC/nR/lxKpJiv0uig==", + "dependencies": { + "buffer": "^5.4.3", + "punycode": "^2.1.1", + "webidl-conversions": "^5.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/whatwg-url-without-unicode/node_modules/buffer": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", + "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "dependencies": { + "base64-js": "^1.3.1", + "ieee754": "^1.1.13" + } + }, + "node_modules/whatwg-url-without-unicode/node_modules/webidl-conversions": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-5.0.0.tgz", + "integrity": "sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==", + "engines": { + "node": ">=8" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", "dependencies": { "isexe": "^2.0.0" }, "bin": { - "which": "bin/which" + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" } }, "node_modules/which-module": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", - "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz", + "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==", + "peer": true + }, + "node_modules/workerpool": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz", + "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", "dev": true }, - "node_modules/word-wrap": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", - "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", "dev": true, + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, "engines": { - "node": ">=0.10.0" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/workerpool": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.0.tgz", - "integrity": "sha512-Rsk5qQHJ9eowMH28Jwhe8HEbmdYDX4lwoMWshiCXugjtHqMD9ZbiqSDLxcsfdqsETPzVUtX5s1Z5kStiIM6l4A==", - "dev": true - }, - "node_modules/wrap-ansi": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", - "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", + "node_modules/wrap-ansi-cjs": { + "name": "wrap-ansi", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dev": true, "dependencies": { "ansi-styles": "^4.0.0", @@ -7627,10 +14627,13 @@ "strip-ansi": "^6.0.0" }, "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/wrap-ansi/node_modules/ansi-styles": { + "node_modules/wrap-ansi-cjs/node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", @@ -7645,7 +14648,7 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/wrap-ansi/node_modules/color-convert": { + "node_modules/wrap-ansi-cjs/node_modules/color-convert": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", @@ -7657,213 +14660,221 @@ "node": ">=7.0.0" } }, - "node_modules/wrap-ansi/node_modules/color-name": { + "node_modules/wrap-ansi-cjs/node_modules/color-name": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "dev": true }, - "node_modules/wrappy": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" - }, - "node_modules/ws": { - "version": "7.4.6", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.4.6.tgz", - "integrity": "sha512-YmhHDO4MzaDLB+M9ym/mDA5z0naX8j7SIlT8f8z+I0VtzsRbekxEutHSme7NPS2qE8StCYQNUnfWdXta/Yu85A==", + "node_modules/wrap-ansi/node_modules/ansi-regex": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", + "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", "dev": true, "engines": { - "node": ">=8.3.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" + "node": ">=12" }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, - "node_modules/xmlhttprequest-ssl": { - "version": "1.6.3", - "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.6.3.tgz", - "integrity": "sha512-3XfeQE/wNkvrIktn2Kf0869fC0BN6UpydVasGIeSm2B1Llihf7/0UfZM+eCkOw3P7bP4+qPgqhm7ZoxuJtFU0Q==", + "node_modules/wrap-ansi/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", "dev": true, "engines": { - "node": ">=0.4.0" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/y18n": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "node_modules/wrap-ansi/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", "dev": true }, - "node_modules/yargs": { - "version": "15.4.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", - "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", + "node_modules/wrap-ansi/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", "dev": true, "dependencies": { - "cliui": "^6.0.0", - "decamelize": "^1.2.0", - "find-up": "^4.1.0", - "get-caller-file": "^2.0.1", - "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^4.2.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^18.1.2" + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" }, "engines": { - "node": ">=8" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/yargs-parser": { - "version": "20.2.4", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", - "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", + "node_modules/wrap-ansi/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", "dev": true, + "dependencies": { + "ansi-regex": "^6.0.1" + }, "engines": { - "node": ">=10" + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, - "node_modules/yargs-unparser": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", - "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", - "dev": true, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + }, + "node_modules/write-file-atomic": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.3.tgz", + "integrity": "sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==", + "peer": true, "dependencies": { - "camelcase": "^6.0.0", - "decamelize": "^4.0.0", - "flat": "^5.0.2", - "is-plain-obj": "^2.1.0" - }, - "engines": { - "node": ">=10" + "graceful-fs": "^4.1.11", + "imurmurhash": "^0.1.4", + "signal-exit": "^3.0.2" } }, - "node_modules/yargs-unparser/node_modules/camelcase": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", - "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "node_modules/write-file-atomic/node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "peer": true + }, + "node_modules/ws": { + "version": "8.11.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", + "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", "dev": true, "engines": { - "node": ">=10" + "node": ">=10.0.0" }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": "^5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } } }, - "node_modules/yargs-unparser/node_modules/decamelize": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", - "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", + "node_modules/xmlbuilder": { + "version": "15.1.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz", + "integrity": "sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==", "dev": true, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=8.0" } }, - "node_modules/yargs/node_modules/find-up": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", - "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "node_modules/xregexp": { + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.4.1.tgz", + "integrity": "sha512-2u9HwfadaJaY9zHtRRnH6BY6CQVNQKkYm3oLtC9gJXXzfsbACg5X5e4EZZGVAH+YIfa+QA9lsFQTTe3HURF3ag==", "dev": true, + "peer": true, "dependencies": { - "locate-path": "^5.0.0", - "path-exists": "^4.0.0" - }, + "@babel/runtime-corejs3": "^7.12.1" + } + }, + "node_modules/xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "peer": true, "engines": { - "node": ">=8" + "node": ">=0.4" } }, - "node_modules/yargs/node_modules/locate-path": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", - "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "dev": true, - "dependencies": { - "p-locate": "^4.1.0" - }, + "node_modules/y18n": { + "version": "5.0.8", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", + "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", "engines": { - "node": ">=8" + "node": ">=10" } }, - "node_modules/yargs/node_modules/p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", - "dev": true, - "dependencies": { - "p-try": "^2.0.0" + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + }, + "node_modules/yaml": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.1.tgz", + "integrity": "sha512-pIXzoImaqmfOrL7teGUBt/T7ZDnyeGBWyXQBvOVhLkWLN37GXv8NMLK406UY6dS51JfcQHsmcW5cJ441bHg6Lg==", + "bin": { + "yaml": "bin.mjs" }, "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">= 14" } }, - "node_modules/yargs/node_modules/p-locate": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", - "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "node_modules/yargs": { + "version": "16.2.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", + "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", "dev": true, "dependencies": { - "p-limit": "^2.2.0" + "cliui": "^7.0.2", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.0", + "y18n": "^5.0.5", + "yargs-parser": "^20.2.2" }, "engines": { - "node": ">=8" + "node": ">=10" } }, - "node_modules/yargs/node_modules/p-try": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", - "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "node_modules/yargs-parser": { + "version": "20.2.4", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", + "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", "dev": true, "engines": { - "node": ">=6" + "node": ">=10" } }, - "node_modules/yargs/node_modules/yargs-parser": { - "version": "18.1.3", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", - "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", + "node_modules/yargs-unparser": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", + "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", "dev": true, "dependencies": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" + "camelcase": "^6.0.0", + "decamelize": "^4.0.0", + "flat": "^5.0.2", + "is-plain-obj": "^2.1.0" }, "engines": { - "node": ">=6" + "node": ">=10" } }, "node_modules/yauzl": { "version": "2.10.0", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", - "integrity": "sha1-x+sXyT4RLLEIb6bY5R+wZnt5pfk=", + "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", "dev": true, "dependencies": { "buffer-crc32": "~0.2.3", "fd-slicer": "~1.1.0" } }, - "node_modules/yeast": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz", - "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=", - "dev": true - }, "node_modules/yn": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", @@ -7877,13 +14888,36 @@ "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", - "dev": true, "engines": { "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/yup": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/yup/-/yup-1.2.0.tgz", + "integrity": "sha512-PPqYKSAXjpRCgLgLKVGPA33v5c/WgEx3wi6NFjIiegz90zSwyMpvTFp/uGcVnnbx6to28pgnzp/q8ih3QRjLMQ==", + "dev": true, + "dependencies": { + "property-expr": "^2.0.5", + "tiny-case": "^1.0.3", + "toposort": "^2.0.2", + "type-fest": "^2.19.0" + } + }, + "node_modules/yup/node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", + "dev": true, + "engines": { + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } } } } diff --git a/package.json b/package.json index ac243ddc9..c28f88b83 100644 --- a/package.json +++ b/package.json @@ -1,25 +1,26 @@ { "name": "pubnub", - "version": "7.6.3", + "version": "8.0.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { "build": "npm run build:node && npm run build:web", - "build:web": "rollup -c rollup.config.js", + "build:web": "rollup -c ./rollup.config.js --bundleConfigAsCjs", "build:node": "tsc -p tsconfig.json", "test": "npm run test:web && npm run test:node", - "test:web": "karma start ./karma/web.config.js", - "test:node": "ts-mocha -p tsconfig.mocha.json --config .mocharc.yml", + "test:web": "karma start karma/web.config.cjs", + "test:node": "TS_NODE_PROJECT='./tsconfig.json' mocha --project tsconfig.mocha.json", "clean": "rimraf lib dist upload", - "lint": "eslint \"src/**/*\" --config .eslintrc.js", + "lint": "eslint \"src/**/*\" --config .eslintrc.cjs", "ci": "npm run clean && npm run build && npm run lint && npm run test", - "ci:web": "npm run clean && npm run build && npm run lint && npm run test:web", - "ci:node": "npm run clean && npm run build && npm run lint && npm run test:node", - "test:feature:objectsv2:node": "ts-mocha -p tsconfig.mocha.json --no-config --require test/setup.js --reporter spec test/dist/objectsv2.test.js", - "test:feature:fileupload:node": "ts-mocha -p tsconfig.mocha.json --no-config --require test/setup.js --reporter spec test/feature/file_upload.node.test.js", + "ci:web": "npm run clean && npm run build:web && npm run lint && npm run test:web", + "ci:node": "npm run clean && npm run build:node && npm run lint && npm run test:node", + "test:feature:objectsv2:node": "NODE_ENV=test TS_NODE_PROJECT='./tsconfig.json' mocha --project tsconfig.mocha.json --require tsx --no-config --reporter spec test/dist/objectsv2.test.ts", + "test:feature:fileupload:node": "NODE_ENV=test TS_NODE_PROJECT='./tsconfig.json' mocha --project tsconfig.mocha.json --require tsx --no-config --reporter spec test/feature/file_upload.node.test.ts", "test:contract": "npm run test:contract:prepare && npm run test:contract:start", "test:contract:prepare": "rimraf test/specs && git clone --branch master --depth 1 git@github.com:pubnub/sdk-specifications.git test/specs", - "test:contract:start": "cucumber-js -p default --tags 'not @na=js'", + "test:contract:specific": "TS_NODE_PROJECT='./test/contract/tsconfig.json' cucumber-js --require test/contract/definitions/grant.ts dist/contract/contract/features --tags '@featureSet=eventEngine and @contract=subscribeReceivingRecovery and not @na=js'", + "test:contract:start": "cucumber-js -p default --tags '@featureSet=access and @contract=grantAllPermissions and not @na=js and not @skip'", "test:contract:beta": "cucumber-js -p default --tags 'not @na=js and @beta and not @skip'", "contract:refresh": "rimraf dist/contract && git clone --branch master git@github.com:pubnub/service-contract-mock.git dist/contract && npm install --prefix dist/contract && npm run refresh-files --prefix dist/contract", "contract:server": "npm start --prefix dist/contract consumer", @@ -55,37 +56,47 @@ "buffer": "^6.0.3", "cbor-js": "^0.1.0", "cbor-sync": "^1.0.4", + "form-data": "^4.0.0", "lil-uuid": "^0.1.1", - "superagent": "^8.1.2", - "proxy-agent": "^6.3.0" + "node-fetch": "^2.7.0", + "proxy-agent": "^6.3.0", + "react-native-url-polyfill": "^2.0.0", + "text-encoding": "^0.7.0" }, "devDependencies": { - "@cucumber/cucumber": "^7.3.1", + "@cucumber/cucumber": "^10.4.0", "@cucumber/pretty-formatter": "^1.0.0", - "@rollup/plugin-commonjs": "^21.0.2", - "@rollup/plugin-json": "^4.1.0", - "@rollup/plugin-node-resolve": "^13.1.3", - "@rollup/plugin-typescript": "^8.3.1", - "@types/chai": "^4.3.3", + "@rollup/plugin-commonjs": "^25.0.7", + "@rollup/plugin-json": "^6.1.0", + "@rollup/plugin-node-resolve": "^15.2.3", + "@rollup/plugin-replace": "^5.0.5", + "@rollup/plugin-terser": "^0.4.4", + "@rollup/plugin-typescript": "^11.1.6", + "@types/cbor-js": "^0.1.1", + "@types/chai": "^4.3.14", + "@types/chai-as-promised": "^7.1.8", "@types/cucumber": "^7.0.0", "@types/expect": "^24.3.0", + "@types/lil-uuid": "^0.1.3", "@types/mocha": "^9.1.0", "@types/nock": "^9.3.1", - "@types/node-fetch": "^2.6.3", - "@types/pubnub": "^7.2.0", - "@typescript-eslint/eslint-plugin": "^5.12.1", - "@typescript-eslint/parser": "^5.12.1", - "chai": "^4.3.4", + "@types/node-fetch": "^2.6.11", + "@types/sinon": "^17.0.3", + "@types/text-encoding": "^0.0.39", + "@types/underscore": "^1.11.15", + "@typescript-eslint/eslint-plugin": "^7.4.0", + "@typescript-eslint/parser": "^7.4.0", + "chai": "^4.4.1", "chai-as-promised": "^7.1.1", "chai-nock": "^1.2.0", "cucumber-pretty": "^6.0.1", - "cucumber-tsflow": "^4.0.0-rc.11", - "es6-shim": "^0.35.6", - "eslint": "^8.9.0", - "eslint-plugin-mocha": "^10.0.3", - "eslint-plugin-prettier": "^4.0.0", + "cucumber-tsflow": "^4.4.4", + "es6-shim": "^0.35.8", + "eslint": "^8.57.0", + "eslint-plugin-mocha": "^10.4.1", + "eslint-plugin-prettier": "^5.1.3", "js-yaml": "^3.13.1", - "karma": "^5.0.3", + "karma": "6.4.3", "karma-chai": "^0.1.0", "karma-chrome-launcher": "^3.1.0", "karma-mocha": "^2.0.1", @@ -93,25 +104,25 @@ "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.32", - "mocha": "^9.2.1", - "nock": "^9.6.1", - "node-fetch": "^2.6.9", + "mocha": "10.4.0", + "nock": "^14.0.0-beta.5", "phantomjs-prebuilt": "^2.1.16", - "prettier": "^2.5.1", + "prettier": "^3.2.5", "rimraf": "^3.0.2", - "rollup": "^2.68.0", - "rollup-plugin-gzip": "^3.0.1", - "rollup-plugin-terser": "^7.0.2", + "rollup": "^4.13.2", + "rollup-plugin-gzip": "^3.1.2", + "rollup-plugin-string": "^3.0.0", "sinon": "^7.5.0", "sinon-chai": "^3.3.0", "source-map-support": "^0.5.21", - "ts-mocha": "^9.0.2", - "ts-node": "^10.9.1", - "typescript": "^4.8.4", + "ts-mocha": "^10.0.0", + "ts-node": "^10.9.2", + "tsx": "^4.7.1", + "typescript": "^5.4.5", "underscore": "^1.9.2" }, "license": "SEE LICENSE IN LICENSE", "engine": { - "node": ">=0.8" + "node": ">=18" } -} \ No newline at end of file +} diff --git a/rollup.config.js b/rollup.config.js index 2892fe84e..9eeb322f3 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,37 +1,84 @@ import { join, basename, dirname } from 'path'; import typescript from '@rollup/plugin-typescript'; -import commonjs from '@rollup/plugin-commonjs'; import resolve from '@rollup/plugin-node-resolve'; +import commonjs from '@rollup/plugin-commonjs'; +import replace from '@rollup/plugin-replace'; import json from '@rollup/plugin-json'; -import { terser } from 'rollup-plugin-terser'; -import gzipPlugin from 'rollup-plugin-gzip'; +const gzipPlugin = require('rollup-plugin-gzip').default; +import terser from '@rollup/plugin-terser'; import { browser, version } from './package.json'; -import tsConfig from './tsconfig.rollup.json'; + +const SERVICE_WORKER_CDN = 'https://cdn.pubnub.com/sdk/javascript'; export default [ { - input: 'src/web/index.js', + input: 'src/web/index.ts', output: { file: browser, format: 'umd', name: 'PubNub', }, - plugins: [json(), resolve({ browser: true }), commonjs(), typescript(tsConfig), terser()], + plugins: [ + json(), + resolve({ browser: true }), + replace({ + SERVICE_WORKER_FILE_PLACEHOLDER: join(dirname(browser), basename(browser, '.min.js') + '.worker.min.js'), + SERVICE_WORKER_CDN, + preventAssignment: true, + }), + commonjs(), + typescript({ tsconfig: 'tsconfig.rollup.json' }), + terser(), + ], }, { - input: 'src/web/index.js', + input: 'src/web/index.ts', output: { file: join(dirname(browser), basename(browser, '.min.js') + '.js'), format: 'umd', name: 'PubNub', }, - plugins: [json(), resolve({ browser: true }), commonjs(), typescript(tsConfig)], + plugins: [ + json(), + resolve({ browser: true }), + replace({ + SERVICE_WORKER_FILE_PLACEHOLDER: join(dirname(browser), basename(browser, '.min.js') + '.worker.js'), + SERVICE_WORKER_CDN, + preventAssignment: true, + }), + commonjs(), + typescript({ tsconfig: 'tsconfig.rollup.json' }), + ], + }, + { + input: 'src/transport/service-worker/subscription-service-worker.ts', + output: { + file: join(dirname(browser), basename(browser, '.min.js') + '.worker.min.js'), + format: 'umd', + name: 'PubNub', + }, + plugins: [ + json(), + resolve({ browser: true }), + commonjs(), + typescript({ tsconfig: 'tsconfig.rollup.json' }), + terser(), + ], + }, + { + input: 'src/transport/service-worker/subscription-service-worker.ts', + output: { + file: join(dirname(browser), basename(browser, '.min.js') + '.worker.js'), + format: 'umd', + name: 'PubNub', + }, + plugins: [json(), resolve({ browser: true }), commonjs(), typescript({ tsconfig: 'tsconfig.rollup.json' })], }, { - input: 'src/web/index.js', + input: 'src/web/index.ts', output: { file: `upload/gzip/pubnub.${version}.min.js`, format: 'umd', @@ -40,37 +87,129 @@ export default [ plugins: [ json(), resolve({ browser: true }), + replace({ + SERVICE_WORKER_FILE_PLACEHOLDER: `pubnub.worker.${version}.min.js`, + SERVICE_WORKER_CDN, + preventAssignment: true, + }), commonjs(), - typescript(tsConfig), + typescript({ tsconfig: 'tsconfig.rollup.json' }), terser(), gzipPlugin({ fileName: '' }), ], }, { - input: 'src/web/index.js', + input: 'src/web/index.ts', output: { file: `upload/gzip/pubnub.${version}.js`, format: 'umd', name: 'PubNub', }, - plugins: [json(), resolve({ browser: true }), commonjs(), typescript(tsConfig), gzipPlugin({ fileName: '' })], + plugins: [ + json(), + resolve({ browser: true }), + replace({ + SERVICE_WORKER_FILE_PLACEHOLDER: `pubnub.worker.${version}.js`, + SERVICE_WORKER_CDN, + preventAssignment: true, + }), + commonjs(), + typescript({ tsconfig: 'tsconfig.rollup.json' }), + gzipPlugin({ fileName: '' }), + ], }, { - input: 'src/web/index.js', + input: 'src/web/index.ts', output: { file: `upload/normal/pubnub.${version}.min.js`, format: 'umd', name: 'PubNub', }, - plugins: [json(), resolve({ browser: true }), commonjs(), typescript(tsConfig), terser()], + plugins: [ + json(), + resolve({ browser: true }), + replace({ + SERVICE_WORKER_FILE_PLACEHOLDER: `pubnub.worker.${version}.min.js`, + SERVICE_WORKER_CDN, + preventAssignment: true, + }), + commonjs(), + typescript({ tsconfig: 'tsconfig.rollup.json' }), + terser(), + ], }, { - input: 'src/web/index.js', + input: 'src/web/index.ts', output: { file: `upload/normal/pubnub.${version}.js`, format: 'umd', name: 'PubNub', }, - plugins: [json(), resolve({ browser: true }), commonjs(), typescript(tsConfig)], + plugins: [ + json(), + resolve({ browser: true }), + replace({ + SERVICE_WORKER_FILE_PLACEHOLDER: `pubnub.worker.${version}.js`, + SERVICE_WORKER_CDN, + preventAssignment: true, + }), + commonjs(), + typescript({ tsconfig: 'tsconfig.rollup.json' }), + ], + }, + { + input: 'src/transport/service-worker/subscription-service-worker.ts', + output: { + file: `upload/gzip/pubnub.worker.${version}.min.js`, + format: 'umd', + name: 'PubNub', + }, + plugins: [ + json(), + resolve({ browser: true }), + commonjs(), + typescript({ tsconfig: 'tsconfig.rollup.json' }), + terser(), + gzipPlugin({ fileName: '' }), + ], + }, + { + input: 'src/transport/service-worker/subscription-service-worker.ts', + output: { + file: `upload/gzip/pubnub.worker.${version}.js`, + format: 'umd', + name: 'PubNub', + }, + plugins: [ + json(), + resolve({ browser: true }), + commonjs(), + typescript({ tsconfig: 'tsconfig.rollup.json' }), + gzipPlugin({ fileName: '' }), + ], + }, + { + input: 'src/transport/service-worker/subscription-service-worker.ts', + output: { + file: `upload/normal/pubnub.worker.${version}.min.js`, + format: 'umd', + name: 'PubNub', + }, + plugins: [ + json(), + resolve({ browser: true }), + commonjs(), + typescript({ tsconfig: 'tsconfig.rollup.json' }), + terser(), + ], + }, + { + input: 'src/transport/service-worker/subscription-service-worker.ts', + output: { + file: `upload/normal/pubnub.worker.${version}.js`, + format: 'umd', + name: 'PubNub', + }, + plugins: [json(), resolve({ browser: true }), commonjs(), typescript({ tsconfig: 'tsconfig.rollup.json' })], }, ]; diff --git a/src/cbor/common.js b/src/cbor/common.js deleted file mode 100644 index 4ada3eb24..000000000 --- a/src/cbor/common.js +++ /dev/null @@ -1,29 +0,0 @@ -export default class { - _base64ToBinary; - - _cborReader; - - constructor(decode, base64ToBinary) { - this._base64ToBinary = base64ToBinary; - this._decode = decode; - } - - decodeToken(tokenString) { - let padding = ''; - - if (tokenString.length % 4 === 3) { - padding = '='; - } else if (tokenString.length % 4 === 2) { - padding = '=='; - } - - const cleaned = tokenString.replace(/-/gi, '+').replace(/_/gi, '/') + padding; - const result = this._decode(this._base64ToBinary(cleaned)); - - if (typeof result === 'object') { - return result; - } - - return undefined; - } -} diff --git a/src/cbor/common.ts b/src/cbor/common.ts new file mode 100644 index 000000000..a4149ca82 --- /dev/null +++ b/src/cbor/common.ts @@ -0,0 +1,32 @@ +/** + * Cbor decoder module. + */ + +/** + * CBOR data decoder. + */ +export default class Cbor { + constructor( + private readonly decode: (arrayBuffer: ArrayBuffer) => Record, + private readonly base64ToBinary: (paddedInput: string) => ArrayBuffer, + ) {} + + /** + * Decode CBOR base64-encoded object. + * + * @param tokenString - Base64-encoded token. + * + * @returns Token object decoded from CBOR. + */ + decodeToken(tokenString: string): Record | undefined { + let padding = ''; + + if (tokenString.length % 4 === 3) padding = '='; + else if (tokenString.length % 4 === 2) padding = '=='; + + const cleaned = tokenString.replace(/-/gi, '+').replace(/_/gi, '/') + padding; + const result = this.decode(this.base64ToBinary(cleaned)); + + return typeof result === 'object' ? result : undefined; + } +} diff --git a/src/core/components/config.js b/src/core/components/config.js deleted file mode 100644 index 7b7cb1840..000000000 --- a/src/core/components/config.js +++ /dev/null @@ -1,386 +0,0 @@ -/* */ -/* global location */ - -import uuidGenerator from './uuid'; - -const PRESENCE_TIMEOUT_MINIMUM = 20; -const PRESENCE_TIMEOUT_DEFAULT = 300; - -const makeDefaultOrigins = () => Array.from({ length: 20 }, (_, i) => `ps${i + 1}.pndsn.com`); - -export default class { - subscribeKey; - publishKey; - secretKey; - cipherKey; - authKey; - UUID; - proxy; - - /* - if _useInstanceId is true, this instanceId will be added to all requests - */ - instanceId; - - /* - If the SDK is running as part of another SDK built atop of it, allow a custom pnsdk with name and version. - */ - sdkName; - - /* - keep track of the SDK family for identifier generator - */ - sdkFamily; - - /* - If the SDK is operated by a partner, allow a custom pnsdk item for them. - */ - partnerId; - - /* - filter expression to pass along when subscribing. - */ - filterExpression; - - /* - configuration to supress leave events; when a presence leave is performed - this configuration will disallow the leave event from happening - */ - suppressLeaveEvents; - - /* - use SSL for http requests? - */ - secure; - - // Custom optional origin. - origin; - - // log verbosity: true to output lots of info - logVerbosity; - - // if instanceId config is true, the SDK will pass the unique instance identifier to the server as instanceId= - useInstanceId; - - // if requestId config is true, the SDK will pass a unique request identifier with each request as request_id= - useRequestId; - - // use connection keep-alive for http requests - keepAlive; - - keepAliveSettings; - - // if autoNetworkDetection config is true, the SDK will emit NetworkUp and NetworkDown - // when there changes in the networking - autoNetworkDetection; - - // configure retry policy configuration. - retryConfiguration; - - // alert when a heartbeat works out. - announceSuccessfulHeartbeats; - - announceFailedHeartbeats; - - /* - how long the server will wait before declaring that the client is gone. - */ - _presenceTimeout; - - /* - how often (in seconds) the client should announce its presence to server - */ - _heartbeatInterval; - - /* - how long to wait for the server when running the subscribe loop - */ - _subscribeRequestTimeout; - - /* - how long to wait for the server when making transactional requests - */ - _transactionalRequestTimeout; - - /* - use send beacon API when unsubscribing. - https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon - */ - _useSendBeacon; - - /* - allow frameworks to append to the PNSDK parameter - the key should be an identifier for the specific framework to prevent duplicates - */ - _PNSDKSuffix; - - /* - if set, the SDK will alert if more messages arrive in one subscribe than the theshold - */ - requestMessageCountThreshold; - - /* - Restore subscription list on disconnection. - */ - restore; - - /* - support for client deduping - */ - dedupeOnSubscribe; - - maximumCacheSize; - - /* - support custom encryption and decryption functions. - */ - customEncrypt; // function to support custome encryption of messages - - customDecrypt; // function used to decrypt old version messages - - // File Upload - - // How many times the publish-file should be retried before giving up - fileUploadPublishRetryLimit; - useRandomIVs; - enableEventEngine; - maintainPresenceState; - - /* - set cryptoModule to encrypt/decrypt messages and files. - */ - cryptoModule; - - constructor({ setup }) { - this._PNSDKSuffix = {}; - - this.instanceId = `pn-${uuidGenerator.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.cryptoModule = setup.cryptoModule; - - this.setFilterExpression(setup.filterExpression); - - if (typeof setup.origin !== 'string' && !Array.isArray(setup.origin) && setup.origin !== undefined) { - throw new Error('Origin must be either undefined, a string or a list of strings.'); - } - - this.origin = setup.origin || makeDefaultOrigins(); - 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.fileUploadPublishRetryLimit ?? 5; - this.useRandomIVs = setup.useRandomIVs ?? true; - - this.enableEventEngine = setup.enableEventEngine ?? false; - this.maintainPresenceState = setup.maintainPresenceState ?? true; - - // if location config exist and we are in https, force secure to 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; - - if (setup.retryConfiguration) { - this._setRetryConfiguration(setup.retryConfiguration); - } - - // set timeout to how long a transaction request will wait for the server (default 15 seconds) - this.setTransactionTimeout(setup.transactionalRequestTimeout || 15 * 1000); - // set timeout to how long a subscribe event loop will run (default 310 seconds) - this.setSubscribeTimeout(setup.subscribeRequestTimeout || 310 * 1000); - // set config on beacon (https://developer.mozilla.org/en-US/docs/Web/API/Navigator/sendBeacon) usage - this.setSendBeaconConfig(setup.useSendBeacon || true); - // how long the SDK will report the client to be alive before issuing a timeout - if (setup.presenceTimeout) { - this.setPresenceTimeout(setup.presenceTimeout); - } else { - this._presenceTimeout = PRESENCE_TIMEOUT_DEFAULT; - } - - if (setup.heartbeatInterval != null) { - this.setHeartbeatInterval(setup.heartbeatInterval); - } - - if (typeof setup.userId === 'string') { - if (typeof setup.uuid === 'string') { - throw new Error('Only one of the following configuration options has to be provided: `uuid` or `userId`'); - } - - this.setUserId(setup.userId); - } else { - if (typeof setup.uuid !== 'string') { - throw new Error('One of the following configuration options has to be provided: `uuid` or `userId`'); - } - - this.setUUID(setup.uuid); - } - this.setCipherKey(setup.cipherKey, setup); - } - - // exposed setters - getAuthKey() { - return this.authKey; - } - - setAuthKey(val) { - this.authKey = val; - return this; - } - - setCipherKey(val, setup, modules) { - this.cipherKey = val; - if (this.cipherKey) { - this.cryptoModule = - setup.cryptoModule ?? setup.initCryptoModule({ cipherKey: this.cipherKey, useRandomIVs: this.useRandomIVs }); - if (modules) modules.cryptoModule = this.cryptoModule; - } - return this; - } - - getUUID() { - return this.UUID; - } - - setUUID(val) { - if (!val || typeof val !== 'string' || val.trim().length === 0) { - throw new Error('Missing uuid parameter. Provide a valid string uuid'); - } - this.UUID = val; - return this; - } - - getUserId() { - return this.UUID; - } - - setUserId(value) { - if (!value || typeof value !== 'string' || value.trim().length === 0) { - throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); - } - - this.UUID = value; - return this; - } - - getFilterExpression() { - return this.filterExpression; - } - - setFilterExpression(val) { - this.filterExpression = val; - return this; - } - - getPresenceTimeout() { - return this._presenceTimeout; - } - - setPresenceTimeout(val) { - if (val >= PRESENCE_TIMEOUT_MINIMUM) { - this._presenceTimeout = val; - } else { - this._presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; - - // eslint-disable-next-line no-console - console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', this._presenceTimeout); - } - - this.setHeartbeatInterval(this._presenceTimeout / 2 - 1); - - return this; - } - - setProxy(proxy) { - this.proxy = proxy; - } - - getHeartbeatInterval() { - return this._heartbeatInterval; - } - - setHeartbeatInterval(val) { - this._heartbeatInterval = val; - return this; - } - - // deprecated setters. - getSubscribeTimeout() { - return this._subscribeRequestTimeout; - } - - setSubscribeTimeout(val) { - this._subscribeRequestTimeout = val; - return this; - } - - getTransactionTimeout() { - return this._transactionalRequestTimeout; - } - - setTransactionTimeout(val) { - this._transactionalRequestTimeout = val; - return this; - } - - isSendBeaconEnabled() { - return this._useSendBeacon; - } - - setSendBeaconConfig(val) { - this._useSendBeacon = val; - return this; - } - - getVersion() { - return '7.6.3'; - } - - _setRetryConfiguration(configuration) { - if (configuration.minimumdelay < 2) { - throw new Error('Minimum delay can not be set less than 2 seconds for retry'); - } - if (configuration.maximumDelay > 150) { - throw new Error('Maximum delay can not be set more than 150 seconds for retry'); - } - if (configuration.maximumDelay && maximumRetry > 6) { - throw new Error('Maximum retry for exponential retry policy can not be more than 6'); - } else if (configuration.maximumRetry > 10) { - throw new Error('Maximum retry for linear retry policy can not be more than 10'); - } - this.retryConfiguration = configuration; - } - - _addPnsdkSuffix(name, suffix) { - this._PNSDKSuffix[name] = suffix; - } - - _getPnsdkSuffix(separator) { - return Object.keys(this._PNSDKSuffix).reduce((result, key) => result + separator + this._PNSDKSuffix[key], ''); - } -} diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts new file mode 100644 index 000000000..7bf76b8d6 --- /dev/null +++ b/src/core/components/configuration.ts @@ -0,0 +1,220 @@ +/** + * {@link PubNub} client configuration module. + */ + +import { ExtendedConfiguration, PlatformConfiguration, PrivateClientConfiguration } from '../interfaces/configuration'; +import { CryptoModule, CryptorConfiguration } from '../interfaces/crypto-module'; +import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; +import uuidGenerator from './uuid'; +import { Payload } from '../types/api'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether encryption (if set) should use random initialization vector or not. + */ +const USE_RANDOM_INITIALIZATION_VECTOR = true; +// endregion + +/** + * Crypto Module instance configuration function. + * + * Function will be used each time when `cipherKey` will be changed. + */ +type SetupCryptoModule = (configuration: CryptorConfiguration) => CryptoModule | undefined; + +/** + * Internal state of the {@link PrivateClientConfiguration} to store temporarily information. + */ +type PrivateConfigurationFields = { + /** + * Frameworks suffixes. + * + * Frameworks built atop of PubNub SDK can add key/value pairs which will be added to the + * `pnsdk` query parameter. + * @private + */ + _pnsdkSuffix: Record; + + /** + * Unique PubNub client instance identifier. + */ + _instanceId: string; + + /** + * Crypto Module configuration callback. + * + * Callback allow to setup Crypto Module in platform-independent way. + */ + _setupCryptoModule?: SetupCryptoModule; + + /** + * Configured crypto module. + */ + _cryptoModule?: CryptoModule; + + /** + * Currently used data encryption / decryption key. + */ + _cipherKey: string | undefined; +}; + +/** + * Create {@link PubNub} client private configuration object. + * + * @param base - User- and platform-provided configuration. + * @param setupCryptoModule - Platform-provided {@link CryptoModule} configuration block. + * + * @returns `PubNub` client private configuration. + */ +export const makeConfiguration = ( + base: ExtendedConfiguration & PlatformConfiguration, + setupCryptoModule?: SetupCryptoModule, +): PrivateClientConfiguration & PrivateConfigurationFields => { + // Ensure that retry policy has proper configuration (if has been set). + base.retryConfiguration?.validate(); + + base.useRandomIVs ??= USE_RANDOM_INITIALIZATION_VECTOR; + // Override origin value. + base.origin = standardOrigin(base.ssl ?? false, base.origin!); + + const cryptoModule = base.cryptoModule; + if (cryptoModule) delete base.cryptoModule; + + const clientConfiguration: PrivateClientConfiguration & PrivateConfigurationFields = { + ...base, + _pnsdkSuffix: {}, + _instanceId: `pn-${uuidGenerator.createUUID()}`, + _cryptoModule: undefined, + _cipherKey: undefined, + _setupCryptoModule: setupCryptoModule, + get instanceId(): string | undefined { + if (this.useInstanceId) return this._instanceId; + return undefined; + }, + getUserId() { + return this.userId!; + }, + setUserId(value: string) { + if (!value || typeof value !== 'string' || value.trim().length === 0) + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); + + this.userId = value; + }, + getAuthKey() { + return this.authKey; + }, + setAuthKey(authKey: string | null) { + this.authKey = authKey; + }, + getFilterExpression() { + return this.filterExpression; + }, + setFilterExpression(expression: string | null | undefined) { + this.filterExpression = expression; + }, + getCipherKey(): string | undefined { + return this._cipherKey; + }, + setCipherKey(key: string) { + this._cipherKey = key; + + if (!key && this._cryptoModule) { + this._cryptoModule = undefined; + return; + } else if (!key || !this._setupCryptoModule) return; + + this._cryptoModule = this._setupCryptoModule({ + cipherKey: key, + useRandomIVs: base.useRandomIVs, + customEncrypt: this.getCustomEncrypt(), + customDecrypt: this.getCustomDecrypt(), + }); + }, + getCryptoModule(): CryptoModule | undefined { + return this._cryptoModule; + }, + getUseRandomIVs(): boolean | undefined { + return base.useRandomIVs; + }, + setPresenceTimeout(value: number): void { + this.heartbeatInterval = value / 2 - 1; + this.presenceTimeout = value; + }, + getPresenceTimeout(): number { + return this.presenceTimeout!; + }, + getHeartbeatInterval(): number | undefined { + return this.heartbeatInterval; + }, + setHeartbeatInterval(interval: number) { + this.heartbeatInterval = interval; + }, + getTransactionTimeout(): number { + return this.transactionalRequestTimeout!; + }, + getSubscribeTimeout(): number { + return this.subscribeRequestTimeout!; + }, + get PubNubFile(): PubNubFileConstructor | undefined { + return base.PubNubFile; + }, + get version(): string { + return '8.0.0'; + }, + getVersion(): string { + return this.version; + }, + _addPnsdkSuffix(name: string, suffix: string | number) { + this._pnsdkSuffix[name] = `${suffix}`; + }, + _getPnsdkSuffix(separator: string): string { + const sdk = Object.values(this._pnsdkSuffix).join(separator); + return sdk.length > 0 ? separator + sdk : ''; + }, + + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + + getUUID(): string { + return this.getUserId(); + }, + setUUID(value: string) { + this.setUserId(value); + }, + getCustomEncrypt(): ((data: string | Payload) => string) | undefined { + return base.customEncrypt; + }, + getCustomDecrypt(): ((data: string) => string) | undefined { + return base.customDecrypt; + }, + // endregion + }; + + // Setup `CryptoModule` if possible. + if (base.cipherKey) clientConfiguration.setCipherKey(base.cipherKey); + else if (cryptoModule) clientConfiguration._cryptoModule = cryptoModule; + + return clientConfiguration; +}; + +/** + * Decide {@lin PubNub} service REST API origin. + * + * @param secure - Whether preferred to use secured connection or not. + * @param origin - User-provided or default origin. + * + * @returns `PubNub` REST API endpoints origin. + */ +const standardOrigin = (secure: boolean, origin: string | string[]): string => { + const protocol = secure ? 'https://' : 'http://'; + + if (typeof origin === 'string') return `${protocol}${origin}`; + + return `${protocol}${origin[Math.floor(Math.random() * origin.length)]}`; +}; diff --git a/src/core/components/cryptography/index.js b/src/core/components/cryptography/index.js deleted file mode 100644 index 8d6b400e3..000000000 --- a/src/core/components/cryptography/index.js +++ /dev/null @@ -1,173 +0,0 @@ -import { decode } from '../base64_codec'; -import CryptoJS from './hmac-sha256'; - -function bufferToWordArray(b) { - const wa = []; - let i; - for (i = 0; i < b.length; i += 1) { - wa[(i / 4) | 0] |= b[i] << (24 - 8 * i); - } - - return CryptoJS.lib.WordArray.create(wa, b.length); -} - -export default class { - _config; - - _iv; - - _allowedKeyEncodings; - - _allowedKeyLengths; - - _allowedModes; - - _defaultOptions; - - constructor({ config }) { - 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', - }; - } - - HMACSHA256(data) { - const hash = CryptoJS.HmacSHA256(data, this._config.secretKey); - return hash.toString(CryptoJS.enc.Base64); - } - - SHA256(s) { - return CryptoJS.SHA256(s).toString(CryptoJS.enc.Hex); - } - - _parseOptions(incomingOptions) { - // Defaults - const 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; - - // Validation - 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; - } - - _decodeKey(key, options) { - if (options.keyEncoding === 'base64') { - return CryptoJS.enc.Base64.parse(key); - } - if (options.keyEncoding === 'hex') { - return CryptoJS.enc.Hex.parse(key); - } - return key; - } - - _getPaddedKey(key, options) { - key = this._decodeKey(key, options); - if (options.encryptKey) { - return CryptoJS.enc.Utf8.parse(this.SHA256(key).slice(0, 32)); - } - return key; - } - - _getMode(options) { - if (options.mode === 'ecb') { - return CryptoJS.mode.ECB; - } - return CryptoJS.mode.CBC; - } - - _getIV(options) { - return options.mode === 'cbc' ? CryptoJS.enc.Utf8.parse(this._iv) : null; - } - - _getRandomIV() { - return CryptoJS.lib.WordArray.random(16); - } - - encrypt(data, customCipherKey, options) { - if (this._config.customEncrypt) { - return this._config.customEncrypt(data); - } - return this.pnEncrypt(data, customCipherKey, options); - } - - decrypt(data, customCipherKey, options) { - if (this._config.customDecrypt) { - return this._config.customDecrypt(data); - } - return this.pnDecrypt(data, customCipherKey, options); - } - - pnEncrypt(data, customCipherKey, options) { - if (!customCipherKey && !this._config.cipherKey) return data; - options = this._parseOptions(options); - const mode = this._getMode(options); - const cipherKey = this._getPaddedKey(customCipherKey || this._config.cipherKey, options); - - if (this._config.useRandomIVs) { - const waIv = this._getRandomIV(); - const waPayload = CryptoJS.AES.encrypt(data, cipherKey, { iv: waIv, mode }).ciphertext; - - return waIv.clone().concat(waPayload.clone()).toString(CryptoJS.enc.Base64); - } - const iv = this._getIV(options); - const encryptedHexArray = CryptoJS.AES.encrypt(data, cipherKey, { iv, mode }).ciphertext; - const base64Encrypted = encryptedHexArray.toString(CryptoJS.enc.Base64); - return base64Encrypted || data; - } - - pnDecrypt(data, customCipherKey, options) { - if (!customCipherKey && !this._config.cipherKey) return data; - options = this._parseOptions(options); - const mode = this._getMode(options); - const cipherKey = this._getPaddedKey(customCipherKey || this._config.cipherKey, options); - if (this._config.useRandomIVs) { - const ciphertext = new Uint8ClampedArray(decode(data)); - - const iv = bufferToWordArray(ciphertext.slice(0, 16)); - const payload = bufferToWordArray(ciphertext.slice(16)); - - try { - const plainJSON = CryptoJS.AES.decrypt({ ciphertext: payload }, cipherKey, { iv, mode }).toString( - CryptoJS.enc.Utf8, - ); - const plaintext = JSON.parse(plainJSON); - return plaintext; - } catch (e) { - return null; - } - } else { - const iv = this._getIV(options); - try { - const ciphertext = CryptoJS.enc.Base64.parse(data); - const plainJSON = CryptoJS.AES.decrypt({ ciphertext }, cipherKey, { iv, mode }).toString(CryptoJS.enc.Utf8); - const plaintext = JSON.parse(plainJSON); - return plaintext; - } catch (e) { - return null; - } - } - } -} diff --git a/src/core/components/cryptography/index.ts b/src/core/components/cryptography/index.ts new file mode 100644 index 000000000..98215f205 --- /dev/null +++ b/src/core/components/cryptography/index.ts @@ -0,0 +1,309 @@ +/** + * Legacy cryptography module. + */ + +import { CryptorConfiguration } from '../../interfaces/crypto-module'; +import { Payload } from '../../types/api'; +import { decode } from '../base64_codec'; +import CryptoJS from './hmac-sha256'; + +/** + * Convert bytes array to words array. + * + * @param b - Bytes array (buffer) which should be converted. + * + * @returns Word sized array. + */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +function bufferToWordArray(b: string | any[] | Uint8ClampedArray) { + const wa: number[] = []; + let i; + for (i = 0; i < b.length; i += 1) { + wa[(i / 4) | 0] |= b[i] << (24 - 8 * i); + } + + // @ts-expect-error Bundled library without types. + return CryptoJS.lib.WordArray.create(wa, b.length); +} + +/** + * Legacy cryptor configuration options. + */ +type CryptoConfiguration = { + encryptKey?: boolean; + keyEncoding?: 'hex' | 'utf8' | 'base64' | 'binary'; + keyLength?: 128 | 256; + mode?: 'ecb' | 'cbc'; +}; + +export default class { + /** + * Crypto initialization vector. + */ + private iv = '0123456789012345'; + + /** + * List os allowed cipher key encodings. + */ + private allowedKeyEncodings = ['hex', 'utf8', 'base64', 'binary']; + + /** + * Allowed cipher key lengths. + */ + private allowedKeyLengths = [128, 256]; + + /** + * Allowed crypto modes. + */ + private allowedModes = ['ecb', 'cbc']; + + /** + * Default cryptor configuration options. + */ + private readonly defaultOptions: Required; + + constructor(private readonly configuration: CryptorConfiguration) { + this.defaultOptions = { + encryptKey: true, + keyEncoding: 'utf8', + keyLength: 256, + mode: 'cbc', + }; + } + + /** + * Generate HMAC-SHA256 hash from input data. + * + * @param data - Data from which hash should be generated. + * + * @returns HMAC-SHA256 hash from provided `data`. + */ + public HMACSHA256(data: string): string { + // @ts-expect-error Bundled library without types. + const hash = CryptoJS.HmacSHA256(data, this.configuration.secretKey); + // @ts-expect-error Bundled library without types. + return hash.toString(CryptoJS.enc.Base64); + } + + /** + * Generate SHA256 hash from input data. + * + * @param data - Data from which hash should be generated. + * + * @returns SHA256 hash from provided `data`. + */ + public SHA256(data: string): string { + // @ts-expect-error Bundled library without types. + return CryptoJS.SHA256(data).toString(CryptoJS.enc.Hex); + } + + /** + * Encrypt provided data. + * + * @param data - Source data which should be encrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Encrypted `data`. + */ + public encrypt(data: string | Payload, customCipherKey?: string, options?: CryptoConfiguration) { + if (this.configuration.customEncrypt) return this.configuration.customEncrypt(data); + + return this.pnEncrypt(data as string, customCipherKey, options); + } + + /** + * Decrypt provided data. + * + * @param data - Encrypted data which should be decrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Decrypted `data`. + */ + public decrypt(data: string, customCipherKey?: string, options?: CryptoConfiguration) { + if (this.configuration.customDecrypt) return this.configuration.customDecrypt(data); + + return this.pnDecrypt(data, customCipherKey, options); + } + + /** + * Encrypt provided data. + * + * @param data - Source data which should be encrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Encrypted `data` as string. + */ + private pnEncrypt(data: string, customCipherKey?: string, options?: CryptoConfiguration): string { + const decidedCipherKey = customCipherKey ?? this.configuration.cipherKey; + if (!decidedCipherKey) return data; + + options = this.parseOptions(options); + const mode = this.getMode(options); + const cipherKey = this.getPaddedKey(decidedCipherKey, options); + + if (this.configuration.useRandomIVs) { + const waIv = this.getRandomIV(); + // @ts-expect-error Bundled library without types. + const waPayload = CryptoJS.AES.encrypt(data, cipherKey, { iv: waIv, mode }).ciphertext; + + // @ts-expect-error Bundled library without types. + return waIv.clone().concat(waPayload.clone()).toString(CryptoJS.enc.Base64); + } + + const iv = this.getIV(options); + // @ts-expect-error Bundled library without types. + const encryptedHexArray = CryptoJS.AES.encrypt(data, cipherKey, { iv, mode }).ciphertext; + // @ts-expect-error Bundled library without types. + const base64Encrypted = encryptedHexArray.toString(CryptoJS.enc.Base64); + + return base64Encrypted || data; + } + + /** + * Decrypt provided data. + * + * @param data - Encrypted data which should be decrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Decrypted `data`. + */ + private pnDecrypt(data: string, customCipherKey?: string, options?: CryptoConfiguration): Payload | null { + const decidedCipherKey = customCipherKey ?? this.configuration.cipherKey; + if (!decidedCipherKey) return data; + + options = this.parseOptions(options); + const mode = this.getMode(options); + const cipherKey = this.getPaddedKey(decidedCipherKey, options); + + if (this.configuration.useRandomIVs) { + const ciphertext = new Uint8ClampedArray(decode(data)); + + const iv = bufferToWordArray(ciphertext.slice(0, 16)); + const payload = bufferToWordArray(ciphertext.slice(16)); + + try { + // @ts-expect-error Bundled library without types. + const plainJSON = CryptoJS.AES.decrypt({ ciphertext: payload }, cipherKey, { iv, mode }).toString( + // @ts-expect-error Bundled library without types. + CryptoJS.enc.Utf8, + ); + return JSON.parse(plainJSON); + } catch (e) { + return null; + } + } else { + const iv = this.getIV(options); + try { + // @ts-expect-error Bundled library without types. + const ciphertext = CryptoJS.enc.Base64.parse(data); + // @ts-expect-error Bundled library without types. + const plainJSON = CryptoJS.AES.decrypt({ ciphertext }, cipherKey, { iv, mode }).toString(CryptoJS.enc.Utf8); + return JSON.parse(plainJSON); + } catch (e) { + return null; + } + } + } + + /** + * Pre-process provided custom crypto configuration. + * + * @param incomingOptions - Configuration which should be pre-processed before use. + * + * @returns Normalized crypto configuration options. + */ + private parseOptions(incomingOptions?: CryptoConfiguration): Required { + if (!incomingOptions) return this.defaultOptions; + + // Defaults + const options = { + encryptKey: incomingOptions.encryptKey ?? this.defaultOptions.encryptKey, + keyEncoding: incomingOptions.keyEncoding ?? this.defaultOptions.keyEncoding, + keyLength: incomingOptions.keyLength ?? this.defaultOptions.keyLength, + mode: incomingOptions.mode ?? this.defaultOptions.mode, + }; + + // Validation + if (this.allowedKeyEncodings.indexOf(options.keyEncoding!.toLowerCase()) === -1) + options.keyEncoding = this.defaultOptions.keyEncoding; + if (this.allowedKeyLengths.indexOf(options.keyLength!) === -1) options.keyLength = this.defaultOptions.keyLength; + if (this.allowedModes.indexOf(options.mode!.toLowerCase()) === -1) options.mode = this.defaultOptions.mode; + + return options; + } + + /** + * Decode provided cipher key. + * + * @param key - Key in `encoding` provided by `options`. + * @param options - Crypto configuration options with cipher key details. + * + * @returns Array buffer with decoded key. + */ + private decodeKey(key: string, options: CryptoConfiguration) { + // @ts-expect-error Bundled library without types. + if (options.keyEncoding === 'base64') return CryptoJS.enc.Base64.parse(key); + // @ts-expect-error Bundled library without types. + if (options.keyEncoding === 'hex') return CryptoJS.enc.Hex.parse(key); + + return key; + } + + /** + * Add padding to the cipher key. + * + * @param key - Key which should be padded. + * @param options - Crypto configuration options with cipher key details. + * + * @returns Properly padded cipher key. + */ + private getPaddedKey(key: string, options: CryptoConfiguration) { + key = this.decodeKey(key, options); + + // @ts-expect-error Bundled library without types. + if (options.encryptKey) return CryptoJS.enc.Utf8.parse(this.SHA256(key).slice(0, 32)); + + return key; + } + + /** + * Cipher mode. + * + * @param options - Crypto configuration with information about cipher mode. + * + * @returns Crypto cipher mode. + */ + private getMode(options: CryptoConfiguration) { + // @ts-expect-error Bundled library without types. + if (options.mode === 'ecb') return CryptoJS.mode.ECB; + + // @ts-expect-error Bundled library without types. + return CryptoJS.mode.CBC; + } + + /** + * Cipher initialization vector. + * + * @param options - Crypto configuration with information about cipher mode. + * + * @returns Initialization vector. + */ + private getIV(options: CryptoConfiguration) { + // @ts-expect-error Bundled library without types. + return options.mode === 'cbc' ? CryptoJS.enc.Utf8.parse(this.iv) : null; + } + + /** + * Random initialization vector. + * + * @returns Generated random initialization vector. + */ + private getRandomIV() { + // @ts-expect-error Bundled library without types. + return CryptoJS.lib.WordArray.random(16); + } +} diff --git a/src/core/components/deduping_manager.js b/src/core/components/deduping_manager.js index 7ac8aa613..ab8aa9607 100644 --- a/src/core/components/deduping_manager.js +++ b/src/core/components/deduping_manager.js @@ -1,7 +1,5 @@ /* */ -import Config from './config'; - const hashCode = (payload) => { let hash = 0; if (payload.length === 0) return hash; @@ -24,8 +22,8 @@ export default class { } getKey(message) { - const hashedPayload = hashCode(JSON.stringify(message.payload)).toString(); - const timetoken = message.publishMetaData.publishTimetoken; + const hashedPayload = hashCode(JSON.stringify(message.message)).toString(); + const timetoken = message.timetoken; return `${timetoken}-${hashedPayload}`; } diff --git a/src/core/components/endpoint.js b/src/core/components/endpoint.js deleted file mode 100644 index 0cce04a57..000000000 --- a/src/core/components/endpoint.js +++ /dev/null @@ -1,280 +0,0 @@ -import uuidGenerator from './uuid'; -import utils from '../utils'; -import operationConstants from '../constants/operations'; -import categoryConstants from '../constants/categories'; - -export class PubNubError extends Error { - constructor(message, status) { - super(message); - this.name = this.constructor.name; - this.status = status; - this.message = message; - - Object.setPrototypeOf(this, new.target.prototype); - } -} - -function createError(errorPayload, type) { - errorPayload.type = type; - errorPayload.error = true; - return errorPayload; -} - -export function createValidationError(message) { - return createError({ message }, 'validationError'); -} - -function decideURL(endpoint, modules, incomingParams) { - if (endpoint.usePost && endpoint.usePost(modules, incomingParams)) { - return endpoint.postURL(modules, incomingParams); - } - if (endpoint.usePatch && endpoint.usePatch(modules, incomingParams)) { - return endpoint.patchURL(modules, incomingParams); - } - if (endpoint.useGetFile && endpoint.useGetFile(modules, incomingParams)) { - return endpoint.getFileURL(modules, incomingParams); - } - return endpoint.getURL(modules, incomingParams); -} - -export function generatePNSDK(config) { - if (config.sdkName) { - return config.sdkName; - } - - let base = `PubNub-JS-${config.sdkFamily}`; - - if (config.partnerId) { - base += `-${config.partnerId}`; - } - - base += `/${config.getVersion()}`; - - const 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'; - } - if (endpoint.usePatch && endpoint.usePatch(modules, incomingParams)) { - return 'PATCH'; - } - if (endpoint.useDelete && endpoint.useDelete(modules, incomingParams)) { - return 'DELETE'; - } - if (endpoint.useGetFile && endpoint.useGetFile(modules, incomingParams)) { - return 'GETFILE'; - } - return 'GET'; -} - -export function signRequest(modules, url, outgoingParams, incomingParams, endpoint) { - const { config, crypto } = modules; - - let httpMethod = getHttpMethod(modules, endpoint, incomingParams); - - outgoingParams.timestamp = Math.floor(new Date().getTime() / 1000); - - // This is because of a server-side bug, old publish using post should be deprecated - if ( - endpoint.getOperation() === 'PNPublishOperation' && - endpoint.usePost && - endpoint.usePost(modules, incomingParams) - ) { - httpMethod = 'GET'; - } - - if (httpMethod === 'GETFILE') { - httpMethod = 'GET'; - } - - let signInput = `${httpMethod}\n${config.publishKey}\n${url}\n${utils.signPamFromParams(outgoingParams)}\n`; - - if (httpMethod === 'POST') { - const payload = endpoint.postPayload(modules, incomingParams); - if (typeof payload === 'string') { - signInput += payload; - } else { - signInput += JSON.stringify(payload); - } - } else if (httpMethod === 'PATCH') { - const payload = endpoint.patchPayload(modules, incomingParams); - if (typeof payload === 'string') { - signInput += payload; - } else { - signInput += JSON.stringify(payload); - } - } - - let signature = `v2.${crypto.HMACSHA256(signInput)}`; - signature = signature.replace(/\+/g, '-'); - signature = signature.replace(/\//g, '_'); - signature = signature.replace(/=+$/, ''); - - outgoingParams.signature = signature; -} - -export default function (modules, endpoint, ...args) { - const { networking, config, telemetryManager, tokenManager } = modules; - const requestId = uuidGenerator.createUUID(); - let callback = null; - let promiseComponent = null; - let incomingParams = {}; - - if ( - endpoint.getOperation() === operationConstants.PNTimeOperation || - endpoint.getOperation() === operationConstants.PNChannelGroupsOperation - ) { - callback = args[0]; - } else { - incomingParams = args[0]; - callback = args[1]; - } - - // bridge in Promise support. - if (typeof Promise !== 'undefined' && !callback) { - promiseComponent = utils.createPromise(); - } - - const validationResult = endpoint.validateParams(modules, incomingParams); - - if (validationResult) { - if (callback) { - return callback(createValidationError(validationResult)); - } - if (promiseComponent) { - promiseComponent.reject( - new PubNubError('Validation failed, check status for details', createValidationError(validationResult)), - ); - return promiseComponent.promise; - } - return; - } - - let outgoingParams = endpoint.prepareParams(modules, incomingParams); - const url = decideURL(endpoint, modules, incomingParams); - let callInstance; - const networkingParams = { - 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, - abortSignal: - typeof endpoint.getAbortSignal === 'function' ? endpoint.getAbortSignal(modules, incomingParams) : null, - }; - - outgoingParams.uuid = config.UUID; - outgoingParams.pnsdk = generatePNSDK(config); - - // Add telemetry information (if there is any available). - const telemetryLatencies = telemetryManager.operationsLatencyForRequest(); - if (Object.keys(telemetryLatencies).length) { - outgoingParams = { ...outgoingParams, ...telemetryLatencies }; - } - - if (config.useInstanceId) { - outgoingParams.instanceid = config.instanceId; - } - - if (config.useRequestId) { - outgoingParams.requestid = requestId; - } - - if (endpoint.isAuthSupported()) { - const tokenOrKey = tokenManager.getToken() || config.getAuthKey(); - - if (tokenOrKey) { - outgoingParams.auth = tokenOrKey; - } - } - - if (config.secretKey) { - signRequest(modules, url, outgoingParams, incomingParams, endpoint); - } - - const onResponse = (status, payload) => { - 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; - } - - // Stop endpoint latency tracking. - telemetryManager.stopLatencyMeasure(endpoint.getOperation(), requestId); - - let responseP = endpoint.handleResponse(modules, payload, incomingParams); - - if (typeof responseP?.then !== 'function') { - responseP = Promise.resolve(responseP); - } - - responseP - .then((result) => { - if (callback) { - callback(status, result); - } else if (promiseComponent) { - promiseComponent.fulfill(result); - } - }) - .catch((e) => { - if (callback) { - let errorData = e; - - if (endpoint.getOperation() === operationConstants.PNSubscribeOperation) { - errorData = { - statusCode: 400, - error: true, - operation: endpoint.getOperation(), - errorData: e, - category: categoryConstants.PNUnknownCategory, - }; - } - - callback(errorData, null); - } else if (promiseComponent) { - promiseComponent.reject(new PubNubError('PubNub call failed, check status for details', e)); - } - }); - }; - - // Start endpoint latency tracking. - telemetryManager.startLatencyMeasure(endpoint.getOperation(), requestId); - - if (getHttpMethod(modules, endpoint, incomingParams) === 'POST') { - const payload = endpoint.postPayload(modules, incomingParams); - callInstance = networking.POST(outgoingParams, payload, networkingParams, onResponse); - } else if (getHttpMethod(modules, endpoint, incomingParams) === 'PATCH') { - const payload = endpoint.patchPayload(modules, incomingParams); - callInstance = networking.PATCH(outgoingParams, payload, 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() === operationConstants.PNSubscribeOperation) { - return callInstance; - } - - if (promiseComponent) { - return promiseComponent.promise; - } -} diff --git a/src/core/components/eventEmitter.js b/src/core/components/eventEmitter.js deleted file mode 100644 index 6dde752b8..000000000 --- a/src/core/components/eventEmitter.js +++ /dev/null @@ -1,289 +0,0 @@ -export default class EventEmitter { - modules; - listenerManager; - getFileUrl; - - _channelListenerMap; - _groupListenerMap; - _decoder; - constructor({ modules, listenerManager, getFileUrl }) { - this.modules = modules; - this.listenerManager = listenerManager; - this.getFileUrl = getFileUrl; - this._channelListenerMap = new Map(); - this._groupListenerMap = new Map(); - if (modules.cryptoModule) this._decoder = new TextDecoder(); - } - emitEvent(e) { - const { channel, publishMetaData } = e; - let { subscriptionMatch } = e; - if (channel === subscriptionMatch) { - subscriptionMatch = null; - } - - if (e.channel.endsWith('-pnpres')) { - const announce = {}; - announce.channel = null; - announce.subscription = null; - - if (channel) { - announce.channel = channel.substring(0, channel.lastIndexOf('-pnpres')); - } - - if (subscriptionMatch) { - announce.subscription = subscriptionMatch.substring(0, subscriptionMatch.lastIndexOf('-pnpres')); - } - - announce.action = e.payload.action; - announce.state = e.payload.data; - announce.timetoken = publishMetaData.timetoken; - announce.occupancy = e.payload.occupancy; - announce.uuid = e.payload.uuid; - announce.timestamp = e.payload.timestamp; - - if (e.payload.join) { - announce.join = e.payload.join; - } - - if (e.payload.leave) { - announce.leave = e.payload.leave; - } - - if (e.payload.timeout) { - announce.timeout = e.payload.timeout; - } - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - - this.listenerManager.announcePresence(announce); - this._announce('presence', announce, announce.channel, announce.subscription); - } else if (e.messageType === 1) { - const announce = {}; - announce.channel = null; - announce.subscription = null; - - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - - announce.message = e.payload; - - this.listenerManager.announceSignal(announce); - this._announce('signal', announce, announce.channel, announce.subscription); - } else if (e.messageType === 2) { - const announce = {}; - announce.channel = null; - announce.subscription = null; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - announce.message = { - event: e.payload.event, - type: e.payload.type, - data: e.payload.data, - }; - this.listenerManager.announceObjects(announce); - this._announce('objects', announce, announce.channel, announce.subscription); - if (e.payload.type === 'uuid') { - const eventData = this._renameChannelField(announce); - const userEvent = { - ...eventData, - message: { - ...eventData.message, - event: this._renameEvent(eventData.message.event), - type: 'user', - }, - }; - this.listenerManager.announceUser(userEvent); - this._announce('user', userEvent, announce.channel, announce.subscription); - } else if (e.payload.type === 'channel') { - const eventData = this._renameChannelField(announce); - const spaceEvent = { - ...eventData, - message: { - ...eventData.message, - event: this._renameEvent(eventData.message.event), - type: 'space', - }, - }; - this.listenerManager.announceSpace(spaceEvent); - this._announce('space', spaceEvent, announce.channel, announce.subscription); - } else if (e.payload.type === 'membership') { - const eventData = this._renameChannelField(announce); - const { uuid: user, channel: space, ...membershipData } = eventData.message.data; - membershipData.user = user; - membershipData.space = space; - const membershipEvent = { - ...eventData, - message: { - ...eventData.message, - event: this._renameEvent(eventData.message.event), - data: membershipData, - }, - }; - this.listenerManager.announceMembership(membershipEvent); - this._announce('membership', membershipEvent, announce.channel, announce.subscription); - } - } else if (e.messageType === 3) { - const announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - announce.data = { - messageTimetoken: e.payload.data.messageTimetoken, - actionTimetoken: e.payload.data.actionTimetoken, - type: e.payload.data.type, - uuid: e.issuingClientId, - value: e.payload.data.value, - }; - announce.event = e.payload.event; - this.listenerManager.announceMessageAction(announce); - this._announce('messageAction', announce, announce.channel, announce.subscription); - } else if (e.messageType === 4) { - const announce = {}; - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - - let msgPayload = e.payload; - - if (this.modules.cryptoModule) { - let decryptedPayload; - try { - const decryptedData = this.modules.cryptoModule.decrypt(e.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData; - } catch (e) { - decryptedPayload = null; - announce.error = `Error while decrypting message content: ${e.message}`; - } - if (decryptedPayload !== null) { - msgPayload = decryptedPayload; - } - } - - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - - announce.message = msgPayload.message; - - announce.file = { - id: msgPayload.file.id, - name: msgPayload.file.name, - url: this.getFileUrl({ - id: msgPayload.file.id, - name: msgPayload.file.name, - channel, - }), - }; - - this.listenerManager.announceFile(announce); - this._announce('file', announce, announce.channel, announce.subscription); - } else { - const announce = {}; - announce.channel = null; - announce.subscription = null; - - announce.channel = channel; - announce.subscription = subscriptionMatch; - announce.timetoken = publishMetaData.timetoken; - announce.publisher = e.issuingClientId; - - if (e.userMetadata) { - announce.userMetadata = e.userMetadata; - } - - if (this.modules.cryptoModule) { - let decryptedPayload; - try { - const decryptedData = this.modules.cryptoModule.decrypt(e.payload); - decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(this._decoder.decode(decryptedData)) : decryptedData; - } catch (e) { - decryptedPayload = null; - announce.error = `Error while decrypting message content: ${e.message}`; - } - if (decryptedPayload != null) { - announce.message = decryptedPayload; - } else { - announce.message = e.payload; - } - } else { - announce.message = e.payload; - } - // deprecated --> - announce.actualChannel = subscriptionMatch != null ? channel : null; - announce.subscribedChannel = subscriptionMatch != null ? subscriptionMatch : channel; - // <-- deprecated - - this.listenerManager.announceMessage(announce); - this._announce('message', announce, announce.channel, announce.subscription); - } - } - - addListener(l, channels, groups) { - if (!(channels && groups)) { - this.listenerManager.addListener(l); - } else { - channels?.forEach((c) => { - if (this._channelListenerMap[c]) { - if (!this._channelListenerMap[c].includes(l)) this._channelListenerMap[c].push(l); - } else { - this._channelListenerMap[c] = [l]; - } - }); - groups?.forEach((g) => { - if (this._groupListenerMap[g]) { - if (!this._groupListenerMap[g].includes(l)) this._groupListenerMap[g].push(l); - } else { - this._groupListenerMap[g] = [l]; - } - }); - } - } - - removeListener(listener, channels, groups) { - if (!(channels && groups)) { - this.listenerManager.removeListener(listener); - } else { - channels?.forEach((c) => { - this._channelListenerMap[c] = this._channelListenerMap[c]?.filter((l) => l !== listener); - }); - groups?.forEach((g) => { - this._groupListenerMap[g] = this._groupListenerMap[g]?.filter((l) => l !== listener); - }); - } - } - - removeAllListeners() { - this.listenerManager.removeAllListeners(); - } - - _renameEvent(e) { - return e === 'set' ? 'updated' : 'removed'; - } - - _renameChannelField(announce) { - const { channel, ...eventData } = announce; - eventData.spaceId = channel; - return eventData; - } - - _announce(type, event, channel, group) { - this._channelListenerMap[channel]?.forEach((l) => l[type] && l[type](event)); - this._groupListenerMap[group]?.forEach((l) => l[type] && l[type](event)); - } -} diff --git a/src/core/components/eventEmitter.ts b/src/core/components/eventEmitter.ts new file mode 100644 index 000000000..7f10d3112 --- /dev/null +++ b/src/core/components/eventEmitter.ts @@ -0,0 +1,197 @@ +import { Listener, ListenerManager } from './listener_manager'; +import * as Subscription from '../types/api/subscription'; +import { PubNubEventType } from '../endpoints/subscribe'; + +export default class EventEmitter { + /** + * Map of channels to listener callbacks for them. + */ + private readonly channelListenerMap: Map = new Map(); + + /** + * Map of channel group names to the listener callbacks for them. + */ + private readonly groupListenerMap: Map = new Map(); + + constructor(private readonly listenerManager: ListenerManager) {} + + /** + * Emit specific real-time event. + * + * Proper listener will be notified basing on event `type`. + * + * @param event - Received real-time event. + */ + emitEvent(event: Subscription.SubscriptionResponse['messages'][number]) { + if (event.type === PubNubEventType.Message) { + this.listenerManager.announceMessage(event.data); + this.announce('message', event.data, event.data.channel, event.data.subscription); + } else if (event.type === PubNubEventType.Signal) { + this.listenerManager.announceSignal(event.data); + this.announce('signal', event.data, event.data.channel, event.data.subscription); + } else if (event.type === PubNubEventType.Presence) { + this.listenerManager.announcePresence(event.data); + this.announce('presence', event.data, event.data.channel, event.data.subscription); + } else if (event.type === PubNubEventType.AppContext) { + const { data: objectEvent } = event; + const { message: object } = objectEvent; + this.listenerManager.announceObjects(objectEvent); + this.announce('objects', objectEvent, objectEvent.channel, objectEvent.subscription); + + if (object.type === 'uuid') { + const { message, channel, ...restEvent } = objectEvent; + const { event, type, ...restObject } = object; + const userEvent: Subscription.UserAppContextObject = { + ...restEvent, + spaceId: channel, + message: { + ...restObject, + event: event === 'set' ? 'updated' : 'removed', + type: 'user', + }, + }; + + this.listenerManager.announceUser(userEvent); + this.announce('user', userEvent, userEvent.spaceId, userEvent.subscription); + } else if (object.type === 'channel') { + const { message, channel, ...restEvent } = objectEvent; + const { event, type, ...restObject } = object; + const spaceEvent: Subscription.SpaceAppContextObject = { + ...restEvent, + spaceId: channel, + message: { + ...restObject, + event: event === 'set' ? 'updated' : 'removed', + type: 'space', + }, + }; + + this.listenerManager.announceSpace(spaceEvent); + this.announce('space', spaceEvent, spaceEvent.spaceId, spaceEvent.subscription); + } else if (object.type === 'membership') { + const { message, channel, ...restEvent } = objectEvent; + const { event, data, ...restObject } = object; + const { uuid, channel: channelMeta, ...restData } = data; + const membershipEvent: Subscription.VSPMembershipAppContextObject = { + ...restEvent, + spaceId: channel, + message: { + ...restObject, + event: event === 'set' ? 'updated' : 'removed', + data: { + ...restData, + user: uuid, + space: channelMeta, + }, + }, + }; + + this.listenerManager.announceMembership(membershipEvent); + this.announce('membership', membershipEvent, membershipEvent.spaceId, membershipEvent.subscription); + } + } else if (event.type === PubNubEventType.MessageAction) { + this.listenerManager.announceMessageAction(event.data); + this.announce('messageAction', event.data, event.data.channel, event.data.subscription); + } else if (event.type === PubNubEventType.Files) { + this.listenerManager.announceFile(event.data); + this.announce('file', event.data, event.data.channel, event.data.subscription); + } + } + + /** + * Register real-time event listener for specific channels and groups. + * + * @param listener - Listener with event callbacks to handle different types of events. + * @param channels - List of channels for which listener should be registered. + * @param groups - List of channel groups for which listener should be registered. + */ + public addListener(listener: Listener, channels?: string[], groups?: string[]) { + // Register event-listener listener globally. + if (!(channels && groups)) { + this.listenerManager.addListener(listener); + } else { + channels?.forEach((channel) => { + if (this.channelListenerMap.has(channel)) { + const channelListeners = this.channelListenerMap.get(channel)!; + if (!channelListeners.includes(listener)) channelListeners.push(listener); + } else this.channelListenerMap.set(channel, [listener]); + }); + + groups?.forEach((group) => { + if (this.groupListenerMap.has(group)) { + const groupListeners = this.groupListenerMap.get(group)!; + if (!groupListeners.includes(listener)) groupListeners.push(listener); + } else this.groupListenerMap.set(group, [listener]); + }); + } + } + + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + * @param channels - List of channels for which listener should be removed. + * @param groups - List of channel groups for which listener should be removed. + */ + public removeListener(listener: Listener, channels?: string[], groups?: string[]) { + if (!(channels && groups)) { + this.listenerManager.removeListener(listener); + } else { + channels?.forEach((channel) => { + if (this.channelListenerMap.has(channel)) { + this.channelListenerMap.set( + channel, + this.channelListenerMap.get(channel)!.filter((channelListener) => channelListener !== listener), + ); + } + }); + + groups?.forEach((group) => { + if (this.groupListenerMap.has(group)) { + this.groupListenerMap.set( + group, + this.groupListenerMap.get(group)!.filter((groupListener) => groupListener !== listener), + ); + } + }); + } + } + + /** + * Clear all real-time event listeners. + */ + public removeAllListeners() { + this.listenerManager.removeAllListeners(); + this.channelListenerMap.clear(); + this.groupListenerMap.clear(); + } + + /** + * Announce real-time event to all listeners. + * + * @param type - Type of event which should be announced. + * @param event - Announced real-time event payload. + * @param channel - Name of the channel for which registered listeners should be notified. + * @param group - Name of the channel group for which registered listeners should be notified. + */ + private announce( + type: T, + event: Listener[T] extends ((arg: infer P) => void) | undefined ? P : never, + channel: string, + group?: string | null, + ) { + if (event && this.channelListenerMap.has(channel)) + this.channelListenerMap.get(channel)!.forEach((listener) => { + const typedListener = listener[type]; + // @ts-expect-error Dynamic events mapping. + if (typedListener) typedListener(event); + }); + + if (group && this.groupListenerMap.has(group)) + this.groupListenerMap.get(group)!.forEach((listener) => { + const typedListener = listener[type]; + // @ts-expect-error Dynamic events mapping. + if (typedListener) typedListener(event); + }); + } +} diff --git a/src/core/components/listener_manager.js b/src/core/components/listener_manager.js deleted file mode 100644 index fb41c1f2d..000000000 --- a/src/core/components/listener_manager.js +++ /dev/null @@ -1,102 +0,0 @@ -import categoryConstants from '../constants/categories'; - -export default class { - _listeners; - - constructor() { - this._listeners = []; - } - - addListener(newListener) { - if (this._listeners.includes(newListener)) { - return; - } - this._listeners.push(newListener); - } - - removeListener(deprecatedListener) { - const newListeners = []; - - this._listeners.forEach((listener) => { - if (listener !== deprecatedListener) newListeners.push(listener); - }); - - this._listeners = newListeners; - } - - removeAllListeners() { - this._listeners = []; - } - - announcePresence(announce) { - this._listeners.forEach((listener) => { - if (listener.presence) listener.presence(announce); - }); - } - - announceStatus(announce) { - this._listeners.forEach((listener) => { - if (listener.status) listener.status(announce); - }); - } - - announceMessage(announce) { - this._listeners.forEach((listener) => { - if (listener.message) listener.message(announce); - }); - } - - announceSignal(announce) { - this._listeners.forEach((listener) => { - if (listener.signal) listener.signal(announce); - }); - } - - announceMessageAction(announce) { - this._listeners.forEach((listener) => { - if (listener.messageAction) listener.messageAction(announce); - }); - } - - announceFile(announce) { - this._listeners.forEach((listener) => { - if (listener.file) listener.file(announce); - }); - } - - announceObjects(announce) { - this._listeners.forEach((listener) => { - if (listener.objects) listener.objects(announce); - }); - } - - announceUser(announce) { - this._listeners.forEach((listener) => { - if (listener.user) listener.user(announce); - }); - } - - announceSpace(announce) { - this._listeners.forEach((listener) => { - if (listener.space) listener.space(announce); - }); - } - - announceMembership(announce) { - this._listeners.forEach((listener) => { - if (listener.membership) listener.membership(announce); - }); - } - - announceNetworkUp() { - const networkStatus = {}; - networkStatus.category = categoryConstants.PNNetworkUpCategory; - this.announceStatus(networkStatus); - } - - announceNetworkDown() { - const networkStatus = {}; - networkStatus.category = categoryConstants.PNNetworkDownCategory; - this.announceStatus(networkStatus); - } -} diff --git a/src/core/components/listener_manager.ts b/src/core/components/listener_manager.ts new file mode 100644 index 000000000..49e4c47d5 --- /dev/null +++ b/src/core/components/listener_manager.ts @@ -0,0 +1,279 @@ +/** + * Events listener manager module. + */ + +import * as Subscription from '../types/api/subscription'; +import StatusCategory from '../constants/categories'; +import { Status, StatusEvent } from '../types/api'; + +/** + * Real-time events listener. + */ +export type Listener = { + /** + * Real-time message events listener. + * + * @param message - Received message. + */ + message?: (message: Subscription.Message) => void; + + /** + * Real-time message signal listener. + * + * @param signal - Received signal. + */ + signal?: (signal: Subscription.Signal) => void; + + /** + * Real-time presence change events listener. + * + * @param presence - Received presence chane information. + */ + presence?: (presence: Subscription.Presence) => void; + + /** + * Real-time App Context Objects change events listener. + * + * @param object - Changed App Context Object information. + */ + objects?: (object: Subscription.AppContextObject) => void; + + /** + * Real-time message actions events listener. + * + * @param action - Message action information. + */ + messageAction?: (action: Subscription.MessageAction) => void; + + /** + * Real-time file share events listener. + * + * @param file - Shared file information. + */ + file?: (file: Subscription.File) => void; + + /** + * Real-time PubNub client status change event. + * + * @param status - PubNub client status information + */ + status?: (status: Status | StatusEvent) => void; + + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + + /** + * Real-time User App Context Objects change events listener. + * + * @param user - User App Context Object information. + * + * @deprecated Use {@link objects} listener callback instead. + */ + user?: (user: Subscription.UserAppContextObject) => void; + + /** + * Real-time Space App Context Objects change events listener. + * + * @param space - Space App Context Object information. + * + * @deprecated Use {@link objects} listener callback instead. + */ + space?: (space: Subscription.SpaceAppContextObject) => void; + + /** + * Real-time VSP Membership App Context Objects change events listener. + * + * @param membership - VSP Membership App Context Object information. + * + * @deprecated Use {@link objects} listener callback instead. + */ + membership?: (membership: Subscription.VSPMembershipAppContextObject) => void; + // endregion +}; + +/** + * Real-time listeners' manager. + */ +export class ListenerManager { + /** + * List of registered event listeners. + */ + private listeners: Listener[] = []; + + /** + * Register new real-time events listener. + * + * @param listener - Listener with event callbacks to handle different types of events. + */ + public addListener(listener: Listener) { + if (this.listeners.includes(listener)) return; + + this.listeners.push(listener); + } + + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + */ + public removeListener(listener: Listener) { + this.listeners = this.listeners.filter((storedListener) => storedListener !== listener); + } + + /** + * Clear all real-time event listeners. + */ + public removeAllListeners() { + this.listeners = []; + } + + /** + * Announce PubNub client status change event. + * + * @param status - PubNub client status. + */ + public announceStatus(status: Status | StatusEvent) { + this.listeners.forEach((listener) => { + if (listener.status) listener.status(status); + }); + } + + /** + * Announce channel presence change event. + * + * @param presence - Channel presence change information. + */ + public announcePresence(presence: Subscription.Presence) { + this.listeners.forEach((listener) => { + if (listener.presence) listener.presence(presence); + }); + } + + /** + * Announce real-time message event. + * + * @param message - Received real-time message. + */ + public announceMessage(message: Subscription.Message) { + this.listeners.forEach((listener) => { + if (listener.message) listener.message(message); + }); + } + + /** + * Announce real-time signal event. + * + * @param signal - Received real-time signal. + */ + public announceSignal(signal: Subscription.Signal) { + this.listeners.forEach((listener) => { + if (listener.signal) listener.signal(signal); + }); + } + + /** + * Announce message actions change event. + * + * @param messageAction - Message action change information. + */ + public announceMessageAction(messageAction: Subscription.MessageAction) { + this.listeners.forEach((listener) => { + if (listener.messageAction) listener.messageAction(messageAction); + }); + } + + /** + * Announce fie share event. + * + * @param file - Shared file information. + */ + public announceFile(file: Subscription.File) { + this.listeners.forEach((listener) => { + if (listener.file) listener.file(file); + }); + } + + /** + * Announce App Context Object change event. + * + * @param object - App Context change information. + */ + public announceObjects(object: Subscription.AppContextObject) { + this.listeners.forEach((listener) => { + if (listener.objects) listener.objects(object); + }); + } + + /** + * Announce network up status. + */ + public announceNetworkUp() { + this.listeners.forEach((listener) => { + if (listener.status) { + listener.status({ + category: StatusCategory.PNNetworkUpCategory, + }); + } + }); + } + + /** + * Announce network down status. + */ + public announceNetworkDown() { + this.listeners.forEach((listener) => { + if (listener.status) { + listener.status({ + category: StatusCategory.PNNetworkDownCategory, + }); + } + }); + } + + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + + /** + * Announce User App Context Object change event. + * + * @param user - User App Context change information. + * + * @deprecated Use {@link announceObjects} method instead. + */ + public announceUser(user: Subscription.UserAppContextObject) { + this.listeners.forEach((listener) => { + if (listener.user) listener.user(user); + }); + } + + /** + * Announce Space App Context Object change event. + * + * @param space - Space App Context change information. + * + * @deprecated Use {@link announceObjects} method instead. + */ + public announceSpace(space: Subscription.SpaceAppContextObject) { + this.listeners.forEach((listener) => { + if (listener.space) listener.space(space); + }); + } + + /** + * Announce VSP Membership App Context Object change event. + * + * @param membership - VSP Membership App Context change information. + * + * @deprecated Use {@link announceObjects} method instead. + */ + public announceMembership(membership: Subscription.VSPMembershipAppContextObject) { + this.listeners.forEach((listener) => { + if (listener.membership) listener.membership(membership); + }); + } + // endregion +} diff --git a/src/core/components/push_payload.js b/src/core/components/push_payload.js deleted file mode 100644 index c9ab4fc85..000000000 --- a/src/core/components/push_payload.js +++ /dev/null @@ -1,545 +0,0 @@ -/* */ -/* eslint max-classes-per-file: ["error", 5] */ - -class BaseNotificationPayload { - _subtitle; - - _payload; - - _badge; - - _sound; - - _title; - - _body; - - get payload() { - return this._payload; - } - - set title(value) { - this._title = value; - } - - set subtitle(value) { - this._subtitle = value; - } - - set body(value) { - this._body = value; - } - - set badge(value) { - this._badge = value; - } - - set sound(value) { - this._sound = value; - } - - constructor(payload, title, body) { - this._payload = payload; - - this._setDefaultPayloadStructure(); - this.title = title; - this.body = body; - } - - _setDefaultPayloadStructure() { - // Empty. - } - - toObject() { - return {}; - } -} - -export class APNSNotificationPayload extends BaseNotificationPayload { - _configurations; - - _apnsPushType; - - _isSilent; - - set configurations(value) { - if (!value || !value.length) return; - - this._configurations = value; - } - - get notification() { - return this._payload.aps; - } - - get title() { - return this._title; - } - - set title(value) { - if (!value || !value.length) return; - - this._payload.aps.alert.title = value; - this._title = value; - } - - get subtitle() { - return this._subtitle; - } - - set subtitle(value) { - if (!value || !value.length) return; - - this._payload.aps.alert.subtitle = value; - this._subtitle = value; - } - - get body() { - return this._body; - } - - set body(value) { - if (!value || !value.length) return; - - this._payload.aps.alert.body = value; - this._body = value; - } - - get badge() { - return this._badge; - } - - set badge(value) { - if (value === undefined || value === null) return; - - this._payload.aps.badge = value; - this._badge = value; - } - - get sound() { - return this._sound; - } - - set sound(value) { - if (!value || !value.length) return; - - this._payload.aps.sound = value; - this._sound = value; - } - - set silent(value) { - this._isSilent = value; - } - - _setDefaultPayloadStructure() { - this._payload.aps = { alert: {} }; - } - - toObject() { - const payload = { ...this._payload }; - /** @type {{alert: Object, badge: number, sound: string}} */ - const { aps } = payload; - let { alert } = aps; - - if (this._isSilent) { - aps['content-available'] = 1; - } - - if (this._apnsPushType === 'apns2') { - if (!this._configurations || !this._configurations.length) { - throw new ReferenceError('APNS2 configuration is missing'); - } - - const configurations = []; - this._configurations.forEach((configuration) => { - configurations.push(this._objectFromAPNS2Configuration(configuration)); - }); - - if (configurations.length) { - payload.pn_push = configurations; - } - } - - if (!alert || !Object.keys(alert).length) { - delete aps.alert; - } - - if (this._isSilent) { - delete aps.alert; - delete aps.badge; - delete aps.sound; - alert = {}; - } - - return this._isSilent || Object.keys(alert).length ? payload : null; - } - - _objectFromAPNS2Configuration(configuration) { - if (!configuration.targets || !configuration.targets.length) { - throw new ReferenceError('At least one APNS2 target should be provided'); - } - - const targets = []; - configuration.targets.forEach((target) => { - targets.push(this._objectFromAPNSTarget(target)); - }); - - const { collapseId, expirationDate } = configuration; - const objectifiedConfiguration = { auth_method: 'token', targets, version: 'v2' }; - - if (collapseId && collapseId.length) { - objectifiedConfiguration.collapse_id = collapseId; - } - - if (expirationDate) { - objectifiedConfiguration.expiration = expirationDate.toISOString(); - } - - return objectifiedConfiguration; - } - - _objectFromAPNSTarget(target) { - if (!target.topic || !target.topic.length) { - throw new TypeError("Target 'topic' undefined."); - } - - const { topic, environment = 'development', excludedDevices = [] } = target; - - const objectifiedTarget = { topic, environment }; - - if (excludedDevices.length) { - objectifiedTarget.excluded_devices = excludedDevices; - } - - return objectifiedTarget; - } -} - -export class MPNSNotificationPayload extends BaseNotificationPayload { - _backContent; - - _backTitle; - - _count; - - _type; - - get backContent() { - return this._backContent; - } - - set backContent(value) { - if (!value || !value.length) return; - - this._payload.back_content = value; - this._backContent = value; - } - - get backTitle() { - return this._backTitle; - } - - set backTitle(value) { - if (!value || !value.length) return; - - this._payload.back_title = value; - this._backTitle = value; - } - - get count() { - return this._count; - } - - set count(value) { - if (value === undefined || value === null) return; - - this._payload.count = value; - this._count = value; - } - - get title() { - return this._title; - } - - set title(value) { - if (!value || !value.length) return; - - this._payload.title = value; - this._title = value; - } - - get type() { - return this._type; - } - - set type(value) { - if (!value || !value.length) return; - - this._payload.type = value; - this._type = value; - } - - get subtitle() { - return this.backTitle; - } - - set subtitle(value) { - this.backTitle = value; - } - - get body() { - return this.backContent; - } - - set body(value) { - this.backContent = value; - } - - get badge() { - return this.count; - } - - set badge(value) { - this.count = value; - } - - toObject() { - return Object.keys(this._payload).length ? { ...this._payload } : null; - } -} - -export class FCMNotificationPayload extends BaseNotificationPayload { - _isSilent; - - _icon; - - _tag; - - get notification() { - return this._payload.notification; - } - - get data() { - return this._payload.data; - } - - get title() { - return this._title; - } - - set title(value) { - if (!value || !value.length) return; - - this._payload.notification.title = value; - this._title = value; - } - - get body() { - return this._body; - } - - set body(value) { - if (!value || !value.length) return; - - this._payload.notification.body = value; - this._body = value; - } - - get sound() { - return this._sound; - } - - set sound(value) { - if (!value || !value.length) return; - - this._payload.notification.sound = value; - this._sound = value; - } - - get icon() { - return this._icon; - } - - set icon(value) { - if (!value || !value.length) return; - - this._payload.notification.icon = value; - this._icon = value; - } - - get tag() { - return this._tag; - } - - set tag(value) { - if (!value || !value.length) return; - - this._payload.notification.tag = value; - this._tag = value; - } - - set silent(value) { - this._isSilent = value; - } - - _setDefaultPayloadStructure() { - this._payload.notification = {}; - this._payload.data = {}; - } - - toObject() { - let data = { ...this._payload.data }; - let notification = null; - const payload = {}; - - /** - * Check whether additional data has been passed outside of 'data' object - * and put it into it if required. - */ - if (Object.keys(this._payload).length > 2) { - const { notification: initialNotification, data: initialData, ...additionalData } = this._payload; - - data = { ...data, ...additionalData }; - } - - if (this._isSilent) { - data.notification = this._payload.notification; - } else { - notification = this._payload.notification; - } - - if (Object.keys(data).length) { - payload.data = data; - } - - if (notification && Object.keys(notification).length) { - payload.notification = notification; - } - - return Object.keys(payload).length ? payload : null; - } -} - -class NotificationsPayload { - _payload; - - _debugging; - - _subtitle; - - _badge; - - _sound; - - _title; - - _body; - - apns; - - mpns; - - fcm; - - set debugging(value) { - this._debugging = value; - } - - get title() { - return this._title; - } - - get body() { - return this._body; - } - - get subtitle() { - return this._subtitle; - } - - set subtitle(value) { - this._subtitle = value; - this.apns.subtitle = value; - this.mpns.subtitle = value; - this.fcm.subtitle = value; - } - - get badge() { - return this._badge; - } - - set badge(value) { - this._badge = value; - this.apns.badge = value; - this.mpns.badge = value; - this.fcm.badge = value; - } - - get sound() { - return this._sound; - } - - set sound(value) { - this._sound = value; - this.apns.sound = value; - this.mpns.sound = value; - this.fcm.sound = value; - } - - constructor(title, body) { - this._payload = { apns: {}, mpns: {}, fcm: {} }; - this._title = title; - this._body = body; - - this.apns = new APNSNotificationPayload(this._payload.apns, title, body); - this.mpns = new MPNSNotificationPayload(this._payload.mpns, title, body); - this.fcm = new FCMNotificationPayload(this._payload.fcm, title, body); - } - - /** - * Build notifications platform for requested platforms. - * - * @param {Array} platforms - List of platforms for which payload - * should be added to final dictionary. Supported values: gcm, apns, apns2, - * mpns. - * - * @returns {Object} Object with data, which can be sent with publish method - * call and trigger remote notifications for specified platforms. - */ - buildPayload(platforms) { - const payload = {}; - - if (platforms.includes('apns') || platforms.includes('apns2')) { - this.apns._apnsPushType = platforms.includes('apns') ? 'apns' : 'apns2'; - const apnsPayload = this.apns.toObject(); - - if (apnsPayload && Object.keys(apnsPayload).length) { - payload.pn_apns = apnsPayload; - } - } - - if (platforms.includes('mpns')) { - const mpnsPayload = this.mpns.toObject(); - - if (mpnsPayload && Object.keys(mpnsPayload).length) { - payload.pn_mpns = mpnsPayload; - } - } - - if (platforms.includes('fcm')) { - const fcmPayload = this.fcm.toObject(); - - if (fcmPayload && Object.keys(fcmPayload).length) { - payload.pn_gcm = fcmPayload; - } - } - - if (Object.keys(payload).length && this._debugging) { - payload.pn_debug = true; - } - - return payload; - } -} - -export default NotificationsPayload; diff --git a/src/core/components/push_payload.ts b/src/core/components/push_payload.ts new file mode 100644 index 000000000..4f0cee394 --- /dev/null +++ b/src/core/components/push_payload.ts @@ -0,0 +1,893 @@ +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +// region APNS2 +/** + * Payload for `pn_apns` field in published message. + */ +type APNSPayload = { + /** + * Payload for Apple Push Notification Service. + */ + aps: { + /** + * Configuration of visual notification representation. + */ + alert?: { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string; + + /** + * Second line title. + * + * Subtitle which is shown under main title with smaller font. + */ + subtitle?: string; + + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string; + }; + + /** + * Unread notifications count badge value. + */ + badge?: number | null; + + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string; + + /** + * Silent notification flag. + */ + 'content-available'?: 1; + }; + + /** + * APNS2 payload recipients information. + */ + pn_push: PubNubAPNS2Configuration[]; +}; + +/** + * APNS2 configuration type. + */ +type APNS2Configuration = { + /** + * Notification group / collapse identifier. Value will be used in APNS POST request as `apns-collapse-id` header + * value. + */ + collapseId?: string; + + /** + * Date till which APNS will try to deliver notification to target device. Value will be used in APNS POST request as + * `apns-expiration` header value. + */ + expirationDate?: Date; + + /** + * List of topics which should receive this notification. + */ + targets: APNS2Target[]; +}; + +/** + * Preformatted for PubNub service `APNS2` configuration type. + */ +type PubNubAPNS2Configuration = { + /** + * PubNub service authentication method for APNS. + */ + auth_method: 'token'; + + /** + * Target entities which should receive notification. + */ + targets: PubNubAPNS2Target[]; + + /** + * Notifications group collapse identifier. + */ + collapse_id?: string; + + /** + * Notification receive expiration date. + * + * Date after which notification won't be delivered. + */ + expiration?: string; + + /** + * APNS protocol version. + */ + version: 'v2'; +}; + +/** + * APNS2 configuration target type. + */ +type APNS2Target = { + /** + * Notifications topic name (usually it is bundle identifier of application for Apple platform). + * + * **Important:** Required only if `pushGateway` is set to `apns2`. + */ + topic: string; + + /** + * Environment within which registered devices to which notifications should be delivered. + * + * Available: + * - `development` + * - `production` + * + * @default `development` + */ + environment?: 'development' | 'production'; + + /** + * List of devices (their push tokens) to which this notification shouldn't be delivered. + */ + excludedDevices?: string[]; +}; + +/** + * Preformatted for PubNub service `APNS2` configuration target type. + */ +type PubNubAPNS2Target = Omit & { + /** + * List of devices (their push tokens) to which this notification shouldn't be delivered. + */ + excluded_devices?: string[]; +}; +// endregion + +// region FCM +/** + * Payload for `pn_gcm` field in published message. + */ +type FCMPayload = { + /** + * Configuration of visual notification representation. + */ + notification?: { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string; + + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string; + + /** + * Name of the icon file from resource bundle which should be shown on notification. + */ + icon?: string; + + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string; + + tag?: string; + }; + + /** + * Configuration of data notification. + * + * Silent notification configuration. + */ + data?: { notification?: FCMPayload['notification'] }; +}; +// endregion +// endregion + +/** + * Base notification payload object. + */ +class BaseNotificationPayload { + /** + * Notification main title. + */ + protected _title?: string; + + /** + * Notification second-line title. + */ + protected _subtitle?: string; + + /** + * Name of the sound which should be played for received notification. + */ + protected _sound?: string; + + /** + * Value which should be placed on application badge (if required). + */ + protected _badge?: number | null; + + /** + * Notification main body message. + */ + protected _body?: string; + + /** + * Object in resulting message where notification payload should be added. + */ + protected _payload: unknown; + + constructor(payload: unknown, title?: string, body?: string) { + this._payload = payload; + + this.setDefaultPayloadStructure(); + this.title = title; + this.body = body; + } + + /** + * Retrieve resulting notification payload content for message. + * + * @returns Preformatted push notification payload data. + */ + get payload(): unknown { + return this._payload; + } + + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value: string | undefined) { + this._title = value; + } + + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value: string | undefined) { + this._subtitle = value; + } + + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value: string | undefined) { + this._body = value; + } + + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value: number | null | undefined) { + this._badge = value; + } + + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value: string | undefined) { + this._sound = value; + } + + /** + * Platform-specific structure initialization. + */ + protected setDefaultPayloadStructure() {} + + /** + * Translate data object into PubNub push notification payload object. + * + * @returns Preformatted push notification payload. + */ + public toObject(): unknown { + return {}; + } +} + +/** + * Message payload for Apple Push Notification Service. + */ +export class APNSNotificationPayload extends BaseNotificationPayload { + /** + * List with notification receivers information. + */ + private _configurations?: APNS2Configuration[]; + + /** + * Type of push notification service for which payload will be created. + */ + private _apnsPushType: 'apns' | 'apns2' = 'apns'; + + /** + * Whether resulting payload should trigger silent notification or not. + */ + private _isSilent: boolean = false; + + get payload(): APNSPayload { + return this._payload as APNSPayload; + } + + /** + * Update notification receivers configuration. + * + * @param value - New APNS2 configurations. + */ + set configurations(value: APNS2Configuration[]) { + if (!value || !value.length) return; + + this._configurations = value; + } + + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ + get notification() { + return this.payload.aps; + } + + /** + * Notification title. + * + * @returns Main notification title. + */ + get title() { + return this._title; + } + + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value) { + if (!value || !value.length) return; + + this.payload.aps.alert!.title = value; + this._title = value; + } + + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ + get subtitle() { + return this._subtitle; + } + + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value) { + if (!value || !value.length) return; + + this.payload.aps.alert!.subtitle = value; + this._subtitle = value; + } + + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body() { + return this._body; + } + + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value) { + if (!value || !value.length) return; + + this.payload.aps.alert!.body = value; + this._body = value; + } + + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ + get badge() { + return this._badge; + } + + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value) { + if (value === undefined || value === null) return; + + this.payload.aps.badge = value; + this._badge = value; + } + + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound() { + return this._sound; + } + + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value) { + if (!value || !value.length) return; + + this.payload.aps.sound = value; + this._sound = value; + } + + /** + * Set whether notification should be silent or not. + * + * `content-available` notification type will be used to deliver silent notification if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ + set silent(value: boolean) { + this._isSilent = value; + } + + protected setDefaultPayloadStructure() { + this.payload.aps = { alert: {} }; + } + + public toObject(): APNSPayload | null { + const payload = { ...this.payload }; + const { aps } = payload; + let { alert } = aps; + + if (this._isSilent) aps['content-available'] = 1; + + if (this._apnsPushType === 'apns2') { + if (!this._configurations || !this._configurations.length) + throw new ReferenceError('APNS2 configuration is missing'); + + const configurations: PubNubAPNS2Configuration[] = []; + this._configurations.forEach((configuration) => { + configurations.push(this.objectFromAPNS2Configuration(configuration)); + }); + + if (configurations.length) payload.pn_push = configurations; + } + + if (!alert || !Object.keys(alert).length) delete aps.alert; + + if (this._isSilent) { + delete aps.alert; + delete aps.badge; + delete aps.sound; + alert = {}; + } + + return this._isSilent || (alert && Object.keys(alert).length) ? payload : null; + } + + /** + * Create PubNub push notification service APNS2 configuration information object. + * + * @param configuration - Source user-provided APNS2 configuration. + * + * @returns Preformatted for PubNub service APNS2 configuration information. + */ + private objectFromAPNS2Configuration(configuration: APNS2Configuration): PubNubAPNS2Configuration { + if (!configuration.targets || !configuration.targets.length) + throw new ReferenceError('At least one APNS2 target should be provided'); + + const { collapseId, expirationDate } = configuration; + const objectifiedConfiguration: PubNubAPNS2Configuration = { + auth_method: 'token', + targets: configuration.targets.map((target) => this.objectFromAPNSTarget(target)), + version: 'v2', + }; + + if (collapseId && collapseId.length) objectifiedConfiguration.collapse_id = collapseId; + if (expirationDate) objectifiedConfiguration.expiration = expirationDate.toISOString(); + + return objectifiedConfiguration; + } + + /** + * Create PubNub push notification service APNS2 target information object. + * + * @param target - Source user-provided data. + * + * @returns Preformatted for PubNub service APNS2 target information. + */ + private objectFromAPNSTarget(target: APNS2Target): PubNubAPNS2Target { + if (!target.topic || !target.topic.length) throw new TypeError("Target 'topic' undefined."); + + const { topic, environment = 'development', excludedDevices = [] } = target; + const objectifiedTarget: PubNubAPNS2Target = { topic, environment }; + + if (excludedDevices.length) objectifiedTarget.excluded_devices = excludedDevices; + + return objectifiedTarget; + } +} + +/** + * Message payload for Firebase Clouse Messaging service. + */ +export class FCMNotificationPayload extends BaseNotificationPayload { + /** + * Whether resulting payload should trigger silent notification or not. + */ + private _isSilent?: boolean; + + /** + * Name of the icon file from resource bundle which should be shown on notification. + */ + private _icon?: string; + + private _tag?: string; + + get payload(): FCMPayload { + return this._payload as FCMPayload; + } + + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ + get notification() { + return this.payload.notification; + } + + /** + * Silent notification payload. + * + * @returns Silent notification payload (data notification). + */ + get data() { + return this.payload.data; + } + + /** + * Notification title. + * + * @returns Main notification title. + */ + get title() { + return this._title; + } + + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value) { + if (!value || !value.length) return; + + this.payload.notification!.title = value; + this._title = value; + } + + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body() { + return this._body; + } + + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value) { + if (!value || !value.length) return; + + this.payload.notification!.body = value; + this._body = value; + } + + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound() { + return this._sound; + } + + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value) { + if (!value || !value.length) return; + + this.payload.notification!.sound = value; + this._sound = value; + } + + /** + * Retrieve notification icon file. + * + * @returns Notification icon file name from resource bundle. + */ + get icon() { + return this._icon; + } + + /** + * Update notification icon. + * + * @param value - Name of the icon file which should be shown on notification. + */ + set icon(value) { + if (!value || !value.length) return; + + this.payload.notification!.icon = value; + this._icon = value; + } + + get tag() { + return this._tag; + } + + set tag(value) { + if (!value || !value.length) return; + + this.payload.notification!.tag = value; + this._tag = value; + } + + /** + * Set whether notification should be silent or not. + * + * All notification data will be sent under `data` field if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ + set silent(value: boolean) { + this._isSilent = value; + } + + protected setDefaultPayloadStructure() { + this.payload.notification = {}; + this.payload.data = {}; + } + + public toObject(): FCMPayload | null { + let data = { ...this.payload.data }; + let notification = null; + const payload: FCMPayload = {}; + + // Check whether additional data has been passed outside 'data' object and put it into it if required. + if (Object.keys(this.payload).length > 2) { + const { notification: initialNotification, data: initialData, ...additionalData } = this.payload; + + data = { ...data, ...additionalData }; + } + + if (this._isSilent) data.notification = this.payload.notification; + else notification = this.payload.notification; + + if (Object.keys(data).length) payload.data = data; + if (notification && Object.keys(notification).length) payload.notification = notification; + + return Object.keys(payload).length ? payload : null; + } +} + +class NotificationsPayload { + /** + * Resulting message payload for notification services. + */ + private readonly _payload; + + /** + * Whether notifications debugging session should be used or not. + */ + private _debugging?: boolean; + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + private readonly _title: string; + + /** + * Second line title. + * + * Subtitle which is shown under main title with smaller font. + */ + private _subtitle?: string; + + /** + * Notification main body message. + */ + private readonly _body: string; + + /** + * Value which should be placed on application badge (if required). + */ + private _badge?: number; + + /** + * Name of the file from resource bundle which should be played when notification received. + */ + private _sound?: string; + + /** + * APNS-specific message payload. + */ + public apns; + + /** + * FCM-specific message payload. + */ + public fcm; + + constructor(title: string, body: string) { + this._payload = { apns: {}, fcm: {} }; + this._title = title; + this._body = body; + + this.apns = new APNSNotificationPayload(this._payload.apns, title, body); + this.fcm = new FCMNotificationPayload(this._payload.fcm, title, body); + } + + set debugging(value: boolean) { + this._debugging = value; + } + + /** + * Notification title. + * + * @returns Main notification title. + */ + get title() { + return this._title; + } + + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ + get subtitle() { + return this._subtitle; + } + + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value) { + this._subtitle = value; + this.apns.subtitle = value; + this.fcm.subtitle = value; + } + + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body() { + return this._body; + } + + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ + get badge() { + return this._badge; + } + + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value: number | undefined) { + this._badge = value; + this.apns.badge = value; + this.fcm.badge = value; + } + + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound() { + return this._sound; + } + + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value) { + this._sound = value; + this.apns.sound = value; + this.fcm.sound = value; + } + + /** + * Build notifications platform for requested platforms. + * + * @param platforms - List of platforms for which payload should be added to final dictionary. Supported values: + * gcm, apns, and apns2. + * + * @returns Object with data, which can be sent with publish method call and trigger remote notifications for + * specified platforms. + */ + buildPayload(platforms: string[]) { + const payload: { pn_apns?: APNSPayload; pn_gcm?: FCMPayload; pn_debug?: boolean } = {}; + + if (platforms.includes('apns') || platforms.includes('apns2')) { + // @ts-expect-error Override APNS version. + this.apns._apnsPushType = platforms.includes('apns') ? 'apns' : 'apns2'; + const apnsPayload = this.apns.toObject(); + + if (apnsPayload && Object.keys(apnsPayload).length) payload.pn_apns = apnsPayload; + } + + if (platforms.includes('fcm')) { + const fcmPayload = this.fcm.toObject(); + + if (fcmPayload && Object.keys(fcmPayload).length) payload.pn_gcm = fcmPayload; + } + + if (Object.keys(payload).length && this._debugging) payload.pn_debug = true; + + return payload; + } +} + +export default NotificationsPayload; diff --git a/src/core/components/reconnection_manager.js b/src/core/components/reconnection_manager.js deleted file mode 100644 index 6d221bd01..000000000 --- a/src/core/components/reconnection_manager.js +++ /dev/null @@ -1,34 +0,0 @@ -import TimeEndpoint from '../endpoints/time'; - -export default class { - _reconnectionCallback; - - _timeEndpoint; - - _timeTimer; - - constructor({ timeEndpoint }) { - this._timeEndpoint = timeEndpoint; - } - - onReconnection(reconnectionCallback) { - this._reconnectionCallback = reconnectionCallback; - } - - startPolling() { - this._timeTimer = setInterval(this._performTimeLoop.bind(this), 3000); - } - - stopPolling() { - clearInterval(this._timeTimer); - } - - _performTimeLoop() { - this._timeEndpoint((status) => { - if (!status.error) { - clearInterval(this._timeTimer); - this._reconnectionCallback(); - } - }); - } -} diff --git a/src/core/components/reconnection_manager.ts b/src/core/components/reconnection_manager.ts new file mode 100644 index 000000000..eac22539b --- /dev/null +++ b/src/core/components/reconnection_manager.ts @@ -0,0 +1,56 @@ +/** + * Subscription reconnection-manager. + * + * **Note:** Reconnection manger rely on legacy time-based availability check. + */ + +import { PubNubCore } from '../pubnub-common'; + +export class ReconnectionManager { + /** + * Successful availability check callback. + * + * @private + */ + private callback?: () => void; + + /** + * Time REST API call timer. + */ + private timeTimer?: number | null; + + constructor(private readonly time: typeof PubNubCore.prototype.time) {} + + /** + * Configure reconnection handler. + * + * @param callback - Successful availability check notify callback. + */ + public onReconnect(callback: () => void) { + this.callback = callback; + } + + /** + * Start periodic "availability" check. + */ + public startPolling() { + this.timeTimer = setInterval(() => this.callTime(), 3000) as unknown as number; + } + + /** + * Stop periodic "availability" check. + */ + public stopPolling() { + if (this.timeTimer) clearInterval(this.timeTimer); + this.timeTimer = null; + } + + private callTime() { + this.time((status) => { + if (!status.error) { + this.stopPolling(); + if (this.callback) this.callback(); + } + }); + } +} diff --git a/src/core/components/request.ts b/src/core/components/request.ts new file mode 100644 index 000000000..c0f328c73 --- /dev/null +++ b/src/core/components/request.ts @@ -0,0 +1,182 @@ +import { CancellationController, TransportMethod, TransportRequest } from '../types/transport-request'; +import { TransportResponse } from '../types/transport-response'; +import RequestOperation from '../constants/operations'; +import { PubNubFileInterface } from '../types/file'; +import { Request } from '../interfaces/request'; +import { Query } from '../types/api'; +import uuidGenerator from './uuid'; + +/** + * Base REST API request class. + */ +export abstract class AbstractRequest implements Request { + /** + * Service `ArrayBuffer` response decoder. + */ + protected static decoder = new TextDecoder(); + + /** + * Request cancellation controller. + */ + private _cancellationController: CancellationController | null; + + /** + * Unique request identifier. + */ + requestIdentifier = uuidGenerator.createUUID(); + + /** + * Construct base request. + * + * Constructed request by default won't be cancellable and performed using `GET` HTTP method. + * + * @param params - Request configuration parameters. + */ + protected constructor(private readonly params?: { method?: TransportMethod; cancellable?: boolean }) { + this._cancellationController = null; + } + + /** + * Retrieve configured cancellation controller. + * + * @returns Cancellation controller. + */ + public get cancellationController(): CancellationController | null { + return this._cancellationController; + } + + /** + * Update request cancellation controller. + * + * Controller itself provided by transport provider implementation and set only when request + * sending has been scheduled. + * + * @param controller - Cancellation controller or `null` to reset it. + */ + public set cancellationController(controller: CancellationController | null) { + this._cancellationController = controller; + } + /** + * Abort request if possible. + */ + abort(): void { + if (this && this.cancellationController) this.cancellationController.abort(); + } + + /** + * Target REST API endpoint operation type. + */ + operation(): RequestOperation { + throw Error('Should be implemented by subclass.'); + } + + /** + * Validate user-provided data before scheduling request. + * + * @returns Error message if request can't be sent without missing or malformed parameters. + */ + validate(): string | undefined { + return undefined; + } + + /** + * Parse service response. + * + * @param _response - Raw service response which should be parsed. + */ + async parse(_response: TransportResponse): Promise { + throw Error('Should be implemented by subclass.'); + } + + /** + * Create platform-agnostic request object. + * + * @returns Request object which can be processed using platform-specific requirements. + */ + request(): TransportRequest { + const request: TransportRequest = { + method: this.params?.method ?? TransportMethod.GET, + path: this.path, + queryParameters: this.queryParameters, + cancellable: this.params?.cancellable ?? false, + timeout: 10000, + identifier: this.requestIdentifier, + }; + + // Attach headers (if required). + const headers = this.headers; + if (headers) request.headers = headers; + + // Attach body (if required). + if (request.method === TransportMethod.POST || request.method === TransportMethod.PATCH) { + const [body, formData] = [this.body, this.formData]; + if (formData) request.formData = formData; + if (body) request.body = body; + } + + return request; + } + + /** + * Target REST API endpoint request headers getter. + * + * @returns Key/value headers which should be used with request. + */ + protected get headers(): Record | undefined { + return undefined; + } + + /** + * Target REST API endpoint request path getter. + * + * @returns REST API path. + */ + protected get path(): string { + throw Error('`path` getter should be implemented by subclass.'); + } + + /** + * Target REST API endpoint request query parameters getter. + * + * @returns Key/value pairs which should be appended to the REST API path. + */ + protected get queryParameters(): Query { + return {}; + } + + protected get formData(): Record[] | undefined { + return undefined; + } + + /** + * Target REST API Request body payload getter. + * + * @returns Buffer of stringified data which should be sent with `POST` or `PATCH` request. + */ + protected get body(): ArrayBuffer | PubNubFileInterface | string | undefined { + return undefined; + } + + /** + * Deserialize service response. + * + * @param response - Transparent response object with headers and body information. + * + * @returns Deserialized data or `undefined` in case of `JSON.parse(..)` error. + */ + protected deserializeResponse(response: TransportResponse): ServiceResponse | undefined { + const contentType = response.headers['content-type']; + if (!contentType || (contentType.indexOf('javascript') === -1 && contentType.indexOf('json') === -1)) + return undefined; + + const json = AbstractRequest.decoder.decode(response.body); + + try { + const parsedJson = JSON.parse(json); + return parsedJson as ServiceResponse; + } catch (error) { + console.error('Error parsing JSON response:', error); + return undefined; + } + } +} diff --git a/src/core/components/stringify_buffer_keys.js b/src/core/components/stringify_buffer_keys.js deleted file mode 100644 index 379318f57..000000000 --- a/src/core/components/stringify_buffer_keys.js +++ /dev/null @@ -1,32 +0,0 @@ -export function stringifyBufferKeys(obj) { - const isObject = (value) => value && typeof value === 'object' && value.constructor === Object; - const isString = (value) => typeof value === 'string' || value instanceof String; - const isNumber = (value) => typeof value === 'number' && isFinite(value); - - if (!isObject(obj)) { - return obj; - } - - const normalizedObject = {}; - - Object.keys(obj).forEach((key) => { - const keyIsString = isString(key); - let stringifiedKey = key; - const value = obj[key]; - - if (Array.isArray(key) || (keyIsString && key.indexOf(',') >= 0)) { - const bytes = keyIsString ? key.split(',') : key; - - stringifiedKey = bytes.reduce((string, byte) => { - string += String.fromCharCode(byte); - return string; - }, ''); - } else if (isNumber(key) || (keyIsString && !isNaN(key))) { - stringifiedKey = String.fromCharCode(keyIsString ? parseInt(key, 10) : 10); - } - - normalizedObject[stringifiedKey] = isObject(value) ? stringifyBufferKeys(value) : value; - }); - - return normalizedObject; -} diff --git a/src/core/components/stringify_buffer_keys.ts b/src/core/components/stringify_buffer_keys.ts new file mode 100644 index 000000000..2b9247ff1 --- /dev/null +++ b/src/core/components/stringify_buffer_keys.ts @@ -0,0 +1,30 @@ +export function stringifyBufferKeys(obj: unknown): Record { + const isObject = (value: unknown): value is Record => + typeof value === 'object' && value !== null && value.constructor === Object; + const isString = (value: unknown): value is string => typeof value === 'string' || value instanceof String; + const isNumber = (value: unknown): value is number => typeof value === 'number' && isFinite(value); + + if (!isObject(obj)) return obj as Record; + + const normalizedObject: Record = {}; + + Object.keys(obj).forEach((key) => { + const keyIsString = isString(key); + let stringifiedKey = key; + const value = obj[key]; + + if (keyIsString && key.indexOf(',') >= 0) { + const bytes = key.split(',').map(Number); + + stringifiedKey = bytes.reduce((string, byte) => { + return string + String.fromCharCode(byte); + }, ''); + } else if (isNumber(key) || (keyIsString && !isNaN(Number(key)))) { + stringifiedKey = String.fromCharCode(isNumber(key) ? key : parseInt(key, 10)); + } + + normalizedObject[stringifiedKey] = isObject(value) ? stringifyBufferKeys(value) : value; + }); + + return normalizedObject; +} diff --git a/src/core/components/subscription-manager.ts b/src/core/components/subscription-manager.ts new file mode 100644 index 000000000..3f295c200 --- /dev/null +++ b/src/core/components/subscription-manager.ts @@ -0,0 +1,569 @@ +/** + * Subscription manager module. + */ + +import { Payload, ResultCallback, Status, StatusCallback, StatusEvent } from '../types/api'; +import { RequestParameters as SubscribeRequestParameters } from '../endpoints/subscribe'; +import { PrivateClientConfiguration } from '../interfaces/configuration'; +import { HeartbeatRequest } from '../endpoints/presence/heartbeat'; +import { ReconnectionManager } from './reconnection_manager'; +import * as Subscription from '../types/api/subscription'; +import { ListenerManager } from './listener_manager'; +import StatusCategory from '../constants/categories'; +import Categories from '../constants/categories'; +import * as Presence from '../types/api/presence'; +import DedupingManager from './deduping_manager'; +import { PubNubCore } from '../pubnub-common'; +import EventEmitter from './eventEmitter'; + +/** + * Subscription loop manager. + */ +export class SubscriptionManager { + /** + * Connection availability check manager. + */ + private readonly reconnectionManager: ReconnectionManager; + + /** + * Real-time events deduplication manager. + */ + private readonly dedupingManager: DedupingManager; + + /** + * Map between channel / group name and `state` associated with `uuid` there. + */ + private readonly presenceState: Record; + + /** + * List of channel groups for which heartbeat calls should be performed. + */ + private readonly heartbeatChannelGroups: Record>; + + /** + * List of channels for which heartbeat calls should be performed. + */ + private readonly heartbeatChannels: Record>; + + /** + * List of channel groups for which real-time presence change events should be observed. + */ + private readonly presenceChannelGroups: Record>; + + /** + * List of channels for which real-time presence change events should be observed. + */ + private readonly presenceChannels: Record>; + + /** + * New list of channel groups to which manager will try to subscribe, + */ + private pendingChannelGroupSubscriptions: Set; + + /** + * New list of channels to which manager will try to subscribe, + */ + private pendingChannelSubscriptions: Set; + + /** + * List of channel groups for which real-time events should be observed. + */ + private readonly channelGroups: Record>; + + /** + * List of channels for which real-time events should be observed. + */ + private readonly channels: Record>; + + /** + * Timetoken which is used by the current subscription loop. + */ + private currentTimetoken: string | number; + + /** + * Timetoken which has been used with previous subscription loop. + */ + private lastTimetoken: string | number; + + /** + * User-provided timetoken or timetoken for catch up. + */ + private storedTimetoken: string | number | null; + + /** + * Timetoken's region. + */ + private region?: number | null; + + private heartbeatTimer: number | null; + + /** + * Whether subscription status change has been announced or not. + */ + private subscriptionStatusAnnounced: boolean; + + /** + * Whether PubNub client is online right now. + */ + private isOnline: boolean; + + /** + * Active subscription request abort method. + * + * **Note:** Reference updated with each subscribe call. + */ + private _subscribeAbort?: { + /** + * Request abort caller. + */ + (): void; + + /** + * Abort controller owner identifier. + */ + identifier: string; + } | null; + + constructor( + private readonly configuration: PrivateClientConfiguration, + private readonly listenerManager: ListenerManager, + private readonly eventEmitter: EventEmitter, + private readonly subscribeCall: ( + parameters: Omit, + callback: ResultCallback, + ) => void, + private readonly heartbeatCall: ( + parameters: Presence.PresenceHeartbeatParameters, + callback: StatusCallback, + ) => void, + private readonly leaveCall: (parameters: Presence.PresenceLeaveParameters, callback: StatusCallback) => void, + time: typeof PubNubCore.prototype.time, + ) { + this.reconnectionManager = new ReconnectionManager(time); + this.dedupingManager = new DedupingManager({ config: this.configuration }); + this.heartbeatChannelGroups = {}; + this.heartbeatChannels = {}; + this.presenceChannelGroups = {}; + this.presenceChannels = {}; + this.heartbeatTimer = null; + this.presenceState = {}; + this.pendingChannelGroupSubscriptions = new Set(); + this.pendingChannelSubscriptions = new Set(); + this.channelGroups = {}; + this.channels = {}; + + this.currentTimetoken = '0'; + this.lastTimetoken = '0'; + this.storedTimetoken = null; + + this.subscriptionStatusAnnounced = false; + this.isOnline = true; + } + + // region Information + get subscribedChannels(): string[] { + return Object.keys(this.channels); + } + + get subscribedChannelGroups(): string[] { + return Object.keys(this.channelGroups); + } + + get abort() { + return this._subscribeAbort; + } + + set abort(call: typeof this._subscribeAbort) { + this._subscribeAbort = call; + } + // endregion + + // region Subscription + + public disconnect() { + this.stopSubscribeLoop(); + this.stopHeartbeatTimer(); + this.reconnectionManager.stopPolling(); + } + + public reconnect() { + this.startSubscribeLoop(); + this.startHeartbeatTimer(); + } + + /** + * Update channels and groups used in subscription loop. + * + * @param parameters - Subscribe configuration parameters. + */ + public subscribe(parameters: Subscription.SubscribeParameters) { + const { channels, channelGroups, timetoken, withPresence = false, withHeartbeats = false } = parameters; + + if (timetoken) { + this.lastTimetoken = this.currentTimetoken; + this.currentTimetoken = timetoken; + } + + if (this.currentTimetoken !== '0' && this.currentTimetoken !== 0) { + this.storedTimetoken = this.currentTimetoken; + this.currentTimetoken = 0; + } + + channels?.forEach((channel) => { + this.pendingChannelSubscriptions.add(channel); + this.channels[channel] = {}; + + if (withPresence) this.presenceChannels[channel] = {}; + if (withHeartbeats || this.configuration.getHeartbeatInterval()) this.heartbeatChannels[channel] = {}; + }); + + channelGroups?.forEach((group) => { + this.pendingChannelGroupSubscriptions.add(group); + this.channelGroups[group] = {}; + + if (withPresence) this.presenceChannelGroups[group] = {}; + if (withHeartbeats || this.configuration.getHeartbeatInterval()) this.heartbeatChannelGroups[group] = {}; + }); + + this.subscriptionStatusAnnounced = false; + this.reconnect(); + } + + public unsubscribe(parameters: Presence.PresenceLeaveParameters, isOffline?: boolean) { + let { channels, channelGroups } = parameters; + + const actualChannelGroups: Set = new Set(); + const actualChannels: Set = new Set(); + + channels?.forEach((channel) => { + if (channel in this.channels) { + delete this.channels[channel]; + actualChannels.add(channel); + + if (channel in this.heartbeatChannels) delete this.heartbeatChannels[channel]; + } + + if (channel in this.presenceState) delete this.presenceState[channel]; + if (channel in this.presenceChannels) { + delete this.presenceChannels[channel]; + actualChannels.add(channel); + } + }); + + channelGroups?.forEach((group) => { + if (group in this.channelGroups) { + delete this.channelGroups[group]; + actualChannelGroups.add(group); + + if (group in this.heartbeatChannelGroups) delete this.heartbeatChannelGroups[group]; + } + + if (group in this.presenceState) delete this.presenceState[group]; + if (group in this.presenceChannelGroups) { + delete this.presenceChannelGroups[group]; + actualChannelGroups.add(group); + } + }); + + // There is no need to unsubscribe to empty list of data sources. + if (actualChannels.size === 0 && actualChannelGroups.size === 0) return; + + if (this.configuration.suppressLeaveEvents === false && !isOffline) { + channelGroups = Array.from(actualChannelGroups); + channels = Array.from(actualChannels); + + this.leaveCall({ channels, channelGroups }, (status) => { + const { error, ...restOfStatus } = status; + let errorMessage: string | undefined; + + if (error) { + if ( + status.errorData && + typeof status.errorData === 'object' && + 'message' in status.errorData && + typeof status.errorData.message === 'string' + ) + errorMessage = status.errorData.message; + else if ('message' in status && typeof status.message === 'string') errorMessage = status.message; + } + + this.listenerManager.announceStatus({ + ...restOfStatus, + error: errorMessage ?? false, + affectedChannels: channels, + affectedChannelGroups: channelGroups, + currentTimetoken: this.currentTimetoken, + lastTimetoken: this.lastTimetoken, + } as StatusEvent); + }); + } + + if ( + Object.keys(this.channels).length === 0 && + Object.keys(this.presenceChannels).length === 0 && + Object.keys(this.channelGroups).length === 0 && + Object.keys(this.presenceChannelGroups).length === 0 + ) { + this.lastTimetoken = 0; + this.currentTimetoken = 0; + this.storedTimetoken = null; + this.region = null; + this.reconnectionManager.stopPolling(); + } + + this.reconnect(); + } + + public unsubscribeAll(isOffline?: boolean) { + this.unsubscribe( + { + channels: this.subscribedChannels, + channelGroups: this.subscribedChannelGroups, + }, + isOffline, + ); + } + + private startSubscribeLoop() { + this.stopSubscribeLoop(); + const channelGroups = [...Object.keys(this.channelGroups)]; + const channels = [...Object.keys(this.channels)]; + + Object.keys(this.presenceChannelGroups).forEach((group) => channelGroups.push(`${group}-pnpres`)); + Object.keys(this.presenceChannels).forEach((channel) => channels.push(`${channel}-pnpres`)); + + // There is no need to start subscription loop for empty list of data sources. + if (channels.length === 0 && channelGroups.length === 0) return; + + this.subscribeCall( + { + channels, + channelGroups, + state: this.presenceState, + heartbeat: this.configuration.getPresenceTimeout(), + timetoken: this.currentTimetoken, + region: this.region !== null ? this.region : undefined, + filterExpression: this.configuration.filterExpression, + }, + (status, result) => { + this.processSubscribeResponse(status, result); + }, + ); + } + + private stopSubscribeLoop() { + if (this._subscribeAbort) { + this._subscribeAbort(); + this._subscribeAbort = null; + } + } + + /** + * Process subscribe REST API endpoint response. + */ + private processSubscribeResponse(status: Status, result: Subscription.SubscriptionResponse | null) { + if (status.error) { + // Ignore aborted request. + if ( + (typeof status.errorData === 'object' && + 'name' in status.errorData && + status.errorData.name === 'AbortError') || + status.category === StatusCategory.PNCancelledCategory + ) + return; + + if (status.category === Categories.PNTimeoutCategory) { + this.startSubscribeLoop(); + } else if (status.category === Categories.PNNetworkIssuesCategory) { + this.disconnect(); + + if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { + this.isOnline = false; + this.listenerManager.announceNetworkDown(); + } + + this.reconnectionManager.onReconnect(() => { + if (this.configuration.autoNetworkDetection && !this.isOnline) { + this.isOnline = true; + this.listenerManager.announceNetworkUp(); + } + + this.reconnect(); + this.subscriptionStatusAnnounced = true; + + const reconnectedAnnounce = { + category: Categories.PNReconnectedCategory, + operation: status.operation, + lastTimetoken: this.lastTimetoken, + currentTimetoken: this.currentTimetoken, + }; + this.listenerManager.announceStatus(reconnectedAnnounce); + }); + + this.reconnectionManager.startPolling(); + this.listenerManager.announceStatus(status); + } else if (status.category === Categories.PNBadRequestCategory) { + this.stopHeartbeatTimer(); + this.listenerManager.announceStatus(status); + } else { + this.listenerManager.announceStatus(status); + } + + return; + } + + if (this.storedTimetoken) { + this.currentTimetoken = this.storedTimetoken; + this.storedTimetoken = null; + } else { + this.lastTimetoken = this.currentTimetoken; + this.currentTimetoken = result!.cursor.timetoken; + } + + if (!this.subscriptionStatusAnnounced) { + const connected: StatusEvent = { + category: StatusCategory.PNConnectedCategory, + operation: status.operation, + affectedChannels: Array.from(this.pendingChannelSubscriptions), + subscribedChannels: this.subscribedChannels, + affectedChannelGroups: Array.from(this.pendingChannelGroupSubscriptions), + lastTimetoken: this.lastTimetoken, + currentTimetoken: this.currentTimetoken, + }; + + this.subscriptionStatusAnnounced = true; + this.listenerManager.announceStatus(connected); + + // Clear pending channels and groups. + this.pendingChannelGroupSubscriptions.clear(); + this.pendingChannelSubscriptions.clear(); + } + + const { messages } = result!; + const { requestMessageCountThreshold, dedupeOnSubscribe } = this.configuration; + + if (requestMessageCountThreshold && messages.length >= requestMessageCountThreshold) { + this.listenerManager.announceStatus({ + category: StatusCategory.PNRequestMessageCountExceededCategory, + operation: status.operation, + }); + } + + try { + messages.forEach((message) => { + if (dedupeOnSubscribe) { + if (this.dedupingManager.isDuplicate(message.data)) return; + this.dedupingManager.addEntry(message.data); + } + + this.eventEmitter.emitEvent(message); + }); + } catch (e) { + const errorStatus: Status = { + error: true, + category: StatusCategory.PNUnknownCategory, + errorData: e as Error, + statusCode: 0, + }; + this.listenerManager.announceStatus(errorStatus); + } + + this.region = result!.cursor.region; + this.startSubscribeLoop(); + } + // endregion + + // region Presence + /** + * Update `uuid` state which should be sent with subscribe request. + * + * @param parameters - Channels and groups with state which should be associated to `uuid`. + */ + public setState(parameters: { state: Payload; channels?: string[]; channelGroups?: string[] }) { + const { state, channels, channelGroups } = parameters; + channels?.forEach((channel) => channel in this.channels && (this.presenceState[channel] = state)); + channelGroups?.forEach((group) => group in this.channelGroups && (this.presenceState[group] = state)); + } + + /** + * Manual presence management. + * + * @param parameters - Desired presence state for provided list of channels and groups. + */ + public changePresence(parameters: { connected: boolean; channels?: string[]; channelGroups?: string[] }) { + const { connected, channels, channelGroups } = parameters; + + if (connected) { + channels?.forEach((channel) => (this.heartbeatChannels[channel] = {})); + channelGroups?.forEach((group) => (this.heartbeatChannelGroups[group] = {})); + } else { + channels?.forEach((channel) => { + if (channel in this.heartbeatChannels) delete this.heartbeatChannels[channel]; + }); + channelGroups?.forEach((group) => { + if (group in this.heartbeatChannelGroups) delete this.heartbeatChannelGroups[group]; + }); + + if (this.configuration.suppressLeaveEvents === false) { + this.leaveCall({ channels, channelGroups }, (status) => this.listenerManager.announceStatus(status)); + } + } + + this.reconnect(); + } + + private startHeartbeatTimer() { + this.stopHeartbeatTimer(); + + const heartbeatInterval = this.configuration.getHeartbeatInterval(); + if (!heartbeatInterval || heartbeatInterval === 0) return; + + this.sendHeartbeat(); + this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), heartbeatInterval * 1000) as unknown as number; + } + + /** + * Stop heartbeat. + * + * Stop timer which trigger {@link HeartbeatRequest} sending with configured presence intervals. + */ + private stopHeartbeatTimer() { + if (!this.heartbeatTimer) return; + + clearInterval(this.heartbeatTimer); + this.heartbeatTimer = null; + } + + /** + * Send heartbeat request. + */ + private sendHeartbeat() { + const heartbeatChannelGroups = Object.keys(this.heartbeatChannelGroups); + const heartbeatChannels = Object.keys(this.heartbeatChannels); + + // There is no need to start heartbeat loop if there is no channels and groups to use. + if (heartbeatChannels.length === 0 && heartbeatChannelGroups.length === 0) return; + + this.heartbeatCall( + { + channels: heartbeatChannels, + channelGroups: heartbeatChannelGroups, + heartbeat: this.configuration.getPresenceTimeout(), + state: this.presenceState, + }, + (status) => { + if (status.error && this.configuration.announceFailedHeartbeats) this.listenerManager.announceStatus(status); + if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { + this.isOnline = false; + this.disconnect(); + this.listenerManager.announceNetworkDown(); + this.reconnect(); + } + + if (!status.error && this.configuration.announceSuccessfulHeartbeats) + this.listenerManager.announceStatus(status); + }, + ); + } + // endregion +} diff --git a/src/core/components/subscription_manager.js b/src/core/components/subscription_manager.js deleted file mode 100644 index 1dd6fbed2..000000000 --- a/src/core/components/subscription_manager.js +++ /dev/null @@ -1,579 +0,0 @@ -import ReconnectionManager from './reconnection_manager'; -import DedupingManager from './deduping_manager'; -import utils from '../utils'; -import categoryConstants from '../constants/categories'; - -export default class { - _crypto; - - _config; - - _listenerManager; - - _reconnectionManager; - - _leaveEndpoint; - - _heartbeatEndpoint; - - _setStateEndpoint; - - _subscribeEndpoint; - - _getFileUrl; - - _channels; - - _presenceChannels; - - _heartbeatChannels; - - _heartbeatChannelGroups; - - _channelGroups; - - _presenceChannelGroups; - - _currentTimetoken; - - _lastTimetoken; - - _storedTimetoken; - - _region; - - _subscribeCall; - - _heartbeatTimer; - - _subscriptionStatusAnnounced; - - _autoNetworkDetection; - - _isOnline; - - // store pending connection elements - _pendingChannelSubscriptions; - - _pendingChannelGroupSubscriptions; - // - - _cryptoModule; - - _decoder; - - _dedupingManager; - - _eventEmitter; - - constructor({ - subscribeEndpoint, - leaveEndpoint, - heartbeatEndpoint, - setStateEndpoint, - timeEndpoint, - getFileUrl, - config, - crypto, - listenerManager, - cryptoModule, - eventEmitter, - }) { - this._listenerManager = listenerManager; - this._config = config; - - this._leaveEndpoint = leaveEndpoint; - this._heartbeatEndpoint = heartbeatEndpoint; - this._setStateEndpoint = setStateEndpoint; - this._subscribeEndpoint = subscribeEndpoint; - this._getFileUrl = getFileUrl; - - this._crypto = crypto; - this._cryptoModule = cryptoModule; - - this._channels = {}; - this._presenceChannels = {}; - - this._heartbeatChannels = {}; - this._heartbeatChannelGroups = {}; - - this._channelGroups = {}; - this._presenceChannelGroups = {}; - - this._pendingChannelSubscriptions = []; - this._pendingChannelGroupSubscriptions = []; - - this._currentTimetoken = 0; - this._lastTimetoken = 0; - this._storedTimetoken = null; - - this._subscriptionStatusAnnounced = false; - - this._isOnline = true; - - this._reconnectionManager = new ReconnectionManager({ timeEndpoint }); - this._dedupingManager = new DedupingManager({ config }); - - if (this._cryptoModule) this._decoder = new TextDecoder(); - - this._eventEmitter = eventEmitter; - } - - adaptStateChange(args, callback) { - const { state, channels = [], channelGroups = [], withHeartbeat = false } = args; - - channels.forEach((channel) => { - if (channel in this._channels) this._channels[channel].state = state; - }); - - channelGroups.forEach((channelGroup) => { - if (channelGroup in this._channelGroups) { - this._channelGroups[channelGroup].state = state; - } - }); - - if (withHeartbeat) { - let presenceState = {}; - channels.forEach((channel) => (presenceState[channel] = state)); - channelGroups.forEach((group) => (presenceState[group] = state)); - return this._heartbeatEndpoint( - { channels: channels, channelGroups: channelGroups, state: presenceState }, - callback, - ); - } - - return this._setStateEndpoint({ state, channels, channelGroups }, callback); - } - - adaptPresenceChange(args) { - const { connected, channels = [], channelGroups = [] } = args; - - if (connected) { - channels.forEach((channel) => { - this._heartbeatChannels[channel] = { state: {} }; - }); - - channelGroups.forEach((channelGroup) => { - this._heartbeatChannelGroups[channelGroup] = { state: {} }; - }); - } else { - channels.forEach((channel) => { - if (channel in this._heartbeatChannels) { - delete this._heartbeatChannels[channel]; - } - }); - - channelGroups.forEach((channelGroup) => { - if (channelGroup in this._heartbeatChannelGroups) { - delete this._heartbeatChannelGroups[channelGroup]; - } - }); - - if (this._config.suppressLeaveEvents === false) { - this._leaveEndpoint({ channels, channelGroups }, (status) => { - this._listenerManager.announceStatus(status); - }); - } - } - - this.reconnect(); - } - - adaptSubscribeChange(args) { - const { timetoken, channels = [], channelGroups = [], withPresence = false, withHeartbeats = false } = args; - - if (!this._config.subscribeKey || this._config.subscribeKey === '') { - // eslint-disable-next-line - if (console && console.log) { - console.log('subscribe key missing; aborting subscribe'); //eslint-disable-line - } - return; - } - - if (timetoken) { - this._lastTimetoken = this._currentTimetoken; - this._currentTimetoken = timetoken; - } - - // reset the current timetoken to get a connect event. - // $FlowFixMe - if (this._currentTimetoken !== '0' && this._currentTimetoken !== 0) { - this._storedTimetoken = this._currentTimetoken; - this._currentTimetoken = 0; - } - - channels.forEach((channel) => { - this._channels[channel] = { state: {} }; - if (withPresence) this._presenceChannels[channel] = {}; - if (withHeartbeats || this._config.getHeartbeatInterval()) this._heartbeatChannels[channel] = {}; - - this._pendingChannelSubscriptions.push(channel); - }); - - channelGroups.forEach((channelGroup) => { - this._channelGroups[channelGroup] = { state: {} }; - if (withPresence) this._presenceChannelGroups[channelGroup] = {}; - if (withHeartbeats || this._config.getHeartbeatInterval()) this._heartbeatChannelGroups[channelGroup] = {}; - - this._pendingChannelGroupSubscriptions.push(channelGroup); - }); - - this._subscriptionStatusAnnounced = false; - this.reconnect(); - } - - adaptUnsubscribeChange(args, isOffline) { - const { channels = [], channelGroups = [] } = args; - - // keep track of which channels and channel groups - // we are going to unsubscribe from. - const actualChannels = []; - const actualChannelGroups = []; - // - - channels.forEach((channel) => { - if (channel in this._channels) { - delete this._channels[channel]; - actualChannels.push(channel); - - if (channel in this._heartbeatChannels) { - delete this._heartbeatChannels[channel]; - } - } - if (channel in this._presenceChannels) { - delete this._presenceChannels[channel]; - actualChannels.push(channel); - } - }); - - channelGroups.forEach((channelGroup) => { - if (channelGroup in this._channelGroups) { - delete this._channelGroups[channelGroup]; - actualChannelGroups.push(channelGroup); - - if (channelGroup in this._heartbeatChannelGroups) { - delete this._heartbeatChannelGroups[channelGroup]; - } - } - if (channelGroup in this._presenceChannelGroups) { - delete this._presenceChannelGroups[channelGroup]; - actualChannelGroups.push(channelGroup); - } - }); - - // no-op if there are no channels and cg's to unsubscribe from. - if (actualChannels.length === 0 && actualChannelGroups.length === 0) { - return; - } - - if (this._config.suppressLeaveEvents === false && !isOffline) { - this._leaveEndpoint({ channels: actualChannels, channelGroups: actualChannelGroups }, (status) => { - status.affectedChannels = actualChannels; - status.affectedChannelGroups = actualChannelGroups; - status.currentTimetoken = this._currentTimetoken; - status.lastTimetoken = this._lastTimetoken; - this._listenerManager.announceStatus(status); - }); - } - - // if we have nothing to subscribe to, reset the timetoken. - if ( - Object.keys(this._channels).length === 0 && - Object.keys(this._presenceChannels).length === 0 && - Object.keys(this._channelGroups).length === 0 && - Object.keys(this._presenceChannelGroups).length === 0 - ) { - this._lastTimetoken = 0; - this._currentTimetoken = 0; - this._storedTimetoken = null; - this._region = null; - this._reconnectionManager.stopPolling(); - } - - this.reconnect(); - } - - unsubscribeAll(isOffline) { - this.adaptUnsubscribeChange( - { - channels: this.getSubscribedChannels(), - channelGroups: this.getSubscribedChannelGroups(), - }, - isOffline, - ); - } - - getHeartbeatChannels() { - return Object.keys(this._heartbeatChannels); - } - - getHeartbeatChannelGroups() { - return Object.keys(this._heartbeatChannelGroups); - } - - getSubscribedChannels() { - return Object.keys(this._channels); - } - - getSubscribedChannelGroups() { - return Object.keys(this._channelGroups); - } - - reconnect() { - this._startSubscribeLoop(); - this._registerHeartbeatTimer(); - } - - disconnect() { - this._stopSubscribeLoop(); - this._stopHeartbeatTimer(); - this._reconnectionManager.stopPolling(); - } - - _registerHeartbeatTimer() { - this._stopHeartbeatTimer(); - - // if the interval is 0 or undefined, do not queue up heartbeating - if (this._config.getHeartbeatInterval() === 0 || this._config.getHeartbeatInterval() === undefined) { - return; - } - - this._performHeartbeatLoop(); - // $FlowFixMe - this._heartbeatTimer = setInterval( - this._performHeartbeatLoop.bind(this), - this._config.getHeartbeatInterval() * 1000, - ); - } - - _stopHeartbeatTimer() { - if (this._heartbeatTimer) { - // $FlowFixMe - clearInterval(this._heartbeatTimer); - this._heartbeatTimer = null; - } - } - - _performHeartbeatLoop() { - const heartbeatChannels = this.getHeartbeatChannels(); - - const heartbeatChannelGroups = this.getHeartbeatChannelGroups(); - - const presenceState = {}; - - if (heartbeatChannels.length === 0 && heartbeatChannelGroups.length === 0) { - return; - } - - this.getSubscribedChannels().forEach((channel) => { - const channelState = this._channels[channel].state; - if (Object.keys(channelState).length) { - presenceState[channel] = channelState; - } - }); - - this.getSubscribedChannelGroups().forEach((channelGroup) => { - const channelGroupState = this._channelGroups[channelGroup].state; - if (Object.keys(channelGroupState).length) { - presenceState[channelGroup] = channelGroupState; - } - }); - - const onHeartbeat = (status) => { - if (status.error && this._config.announceFailedHeartbeats) { - this._listenerManager.announceStatus(status); - } - - if (status.error && this._config.autoNetworkDetection && this._isOnline) { - this._isOnline = false; - this.disconnect(); - this._listenerManager.announceNetworkDown(); - this.reconnect(); - } - - if (!status.error && this._config.announceSuccessfulHeartbeats) { - this._listenerManager.announceStatus(status); - } - }; - - this._heartbeatEndpoint( - { - channels: heartbeatChannels, - channelGroups: heartbeatChannelGroups, - state: presenceState, - }, - onHeartbeat.bind(this), - ); - } - - _startSubscribeLoop() { - this._stopSubscribeLoop(); - const presenceState = {}; - const channels = []; - const channelGroups = []; - - Object.keys(this._channels).forEach((channel) => { - const channelState = this._channels[channel].state; - - if (Object.keys(channelState).length) { - presenceState[channel] = channelState; - } - - channels.push(channel); - }); - Object.keys(this._presenceChannels).forEach((channel) => { - channels.push(`${channel}-pnpres`); - }); - - Object.keys(this._channelGroups).forEach((channelGroup) => { - const channelGroupState = this._channelGroups[channelGroup].state; - - if (Object.keys(channelGroupState).length) { - presenceState[channelGroup] = channelGroupState; - } - - channelGroups.push(channelGroup); - }); - Object.keys(this._presenceChannelGroups).forEach((channelGroup) => { - channelGroups.push(`${channelGroup}-pnpres`); - }); - - if (channels.length === 0 && channelGroups.length === 0) { - return; - } - - const subscribeArgs = { - channels, - channelGroups, - state: presenceState, - timetoken: this._currentTimetoken, - filterExpression: this._config.filterExpression, - region: this._region, - }; - - this._subscribeCall = this._subscribeEndpoint(subscribeArgs, this._processSubscribeResponse.bind(this)); - } - - _processSubscribeResponse(status, payload) { - if (status.error) { - // if error comes from request abort, ignore - if (status.errorData && status.errorData.message === 'Aborted') { - return; - } - - // if we timeout from server, restart the loop. - if (status.category === categoryConstants.PNTimeoutCategory) { - this._startSubscribeLoop(); - } else if (status.category === categoryConstants.PNNetworkIssuesCategory) { - // we lost internet connection, alert the reconnection manager and terminate all loops - this.disconnect(); - - if (status.error && this._config.autoNetworkDetection && this._isOnline) { - this._isOnline = false; - this._listenerManager.announceNetworkDown(); - } - - this._reconnectionManager.onReconnection(() => { - if (this._config.autoNetworkDetection && !this._isOnline) { - this._isOnline = true; - this._listenerManager.announceNetworkUp(); - } - this.reconnect(); - this._subscriptionStatusAnnounced = true; - const reconnectedAnnounce = { - category: categoryConstants.PNReconnectedCategory, - operation: status.operation, - lastTimetoken: this._lastTimetoken, - currentTimetoken: this._currentTimetoken, - }; - this._listenerManager.announceStatus(reconnectedAnnounce); - }); - - this._reconnectionManager.startPolling(); - this._listenerManager.announceStatus(status); - } else if (status.category === categoryConstants.PNBadRequestCategory) { - this._stopHeartbeatTimer(); - this._listenerManager.announceStatus(status); - } else { - this._listenerManager.announceStatus(status); - } - - return; - } - - if (this._storedTimetoken) { - this._currentTimetoken = this._storedTimetoken; - this._storedTimetoken = null; - } else { - this._lastTimetoken = this._currentTimetoken; - this._currentTimetoken = payload.metadata.timetoken; - } - - if (!this._subscriptionStatusAnnounced) { - const connectedAnnounce = {}; - connectedAnnounce.category = categoryConstants.PNConnectedCategory; - connectedAnnounce.operation = status.operation; - connectedAnnounce.affectedChannels = this._pendingChannelSubscriptions; - connectedAnnounce.subscribedChannels = this.getSubscribedChannels(); - connectedAnnounce.affectedChannelGroups = this._pendingChannelGroupSubscriptions; - connectedAnnounce.lastTimetoken = this._lastTimetoken; - connectedAnnounce.currentTimetoken = this._currentTimetoken; - this._subscriptionStatusAnnounced = true; - this._listenerManager.announceStatus(connectedAnnounce); - - // clear the pending connections list - this._pendingChannelSubscriptions = []; - this._pendingChannelGroupSubscriptions = []; - } - - const messages = payload.messages || []; - const { requestMessageCountThreshold, dedupeOnSubscribe } = this._config; - - if (requestMessageCountThreshold && messages.length >= requestMessageCountThreshold) { - const countAnnouncement = {}; - countAnnouncement.category = categoryConstants.PNRequestMessageCountExceededCategory; - countAnnouncement.operation = status.operation; - this._listenerManager.announceStatus(countAnnouncement); - } - - messages.forEach((message) => { - const { channel } = message; - let { subscriptionMatch } = message; - - if (channel === subscriptionMatch) { - subscriptionMatch = null; - } - - if (dedupeOnSubscribe) { - if (this._dedupingManager.isDuplicate(message)) { - return; - } - this._dedupingManager.addEntry(message); - } - - this._eventEmitter.emitEvent(message); - }); - - this._region = payload.metadata.region; - this._startSubscribeLoop(); - } - - _stopSubscribeLoop() { - if (this._subscribeCall) { - if (typeof this._subscribeCall.abort === 'function') { - this._subscribeCall.abort(); - } - this._subscribeCall = null; - } - } - - _renameEvent(e) { - return e === 'set' ? 'updated' : 'removed'; - } - - _renameChannelField(announce) { - const { channel, ...eventData } = announce; - eventData.spaceId = channel; - return eventData; - } -} diff --git a/src/core/components/telemetry_manager.js b/src/core/components/telemetry_manager.js deleted file mode 100644 index fa4392df4..000000000 --- a/src/core/components/telemetry_manager.js +++ /dev/null @@ -1,151 +0,0 @@ -/* */ -import operationConstants from '../constants/operations'; - -export default class { - _maximumSamplesCount = 100; - - _trackedLatencies = {}; - - _latencies = {}; - - _telemetryExcludeOperations = [ - operationConstants.PNSubscribeOperation, - operationConstants.PNReceiveMessagesOperation, - operationConstants.PNHandshakeOperation, - ]; - - constructor(configuration) { - this._maximumSamplesCount = configuration.maximumSamplesCount || this._maximumSamplesCount; - } - - /** - * Compose object with latency information of recently used API endpoints. - * - * @return {Object} Object with request query key/value pairs. - */ - operationsLatencyForRequest() { - const latencies = {}; - - Object.keys(this._latencies).forEach((endpointName) => { - const operationLatencies = this._latencies[endpointName]; - const averageLatency = this._averageLatency(operationLatencies); - - if (averageLatency > 0) { - latencies[`l_${endpointName}`] = averageLatency; - } - }); - - return latencies; - } - - startLatencyMeasure(operationType, identifier) { - if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { - return; - } - - this._trackedLatencies[identifier] = Date.now(); - } - - stopLatencyMeasure(operationType, identifier) { - if (this._telemetryExcludeOperations.includes(operationType) || !identifier) { - return; - } - - const endpointName = this._endpointName(operationType); - /** @type Array */ - let endpointLatencies = this._latencies[endpointName]; - const startDate = this._trackedLatencies[identifier]; - - if (!endpointLatencies) { - this._latencies[endpointName] = []; - endpointLatencies = this._latencies[endpointName]; - } - - endpointLatencies.push(Date.now() - startDate); - - // Truncate samples count if there is more then configured. - if (endpointLatencies.length > this._maximumSamplesCount) { - endpointLatencies.splice(0, endpointLatencies.length - this._maximumSamplesCount); - } - - delete this._trackedLatencies[identifier]; - } - - _averageLatency(latencies) { - const arrayReduce = (accumulatedLatency, latency) => accumulatedLatency + latency; - - return Math.floor(latencies.reduce(arrayReduce, 0) / latencies.length); - } - - _endpointName(operationType) { - let operation = null; - - switch (operationType) { - case operationConstants.PNPublishOperation: - operation = 'pub'; - break; - case operationConstants.PNSignalOperation: - operation = 'sig'; - break; - case operationConstants.PNHistoryOperation: - case operationConstants.PNFetchMessagesOperation: - case operationConstants.PNDeleteMessagesOperation: - case operationConstants.PNMessageCounts: - operation = 'hist'; - break; - case operationConstants.PNUnsubscribeOperation: - case operationConstants.PNWhereNowOperation: - case operationConstants.PNHereNowOperation: - case operationConstants.PNHeartbeatOperation: - case operationConstants.PNSetStateOperation: - case operationConstants.PNGetStateOperation: - operation = 'pres'; - break; - case operationConstants.PNAddChannelsToGroupOperation: - case operationConstants.PNRemoveChannelsFromGroupOperation: - case operationConstants.PNChannelGroupsOperation: - case operationConstants.PNRemoveGroupOperation: - case operationConstants.PNChannelsForGroupOperation: - operation = 'cg'; - break; - case operationConstants.PNPushNotificationEnabledChannelsOperation: - case operationConstants.PNRemoveAllPushNotificationsOperation: - operation = 'push'; - break; - case operationConstants.PNCreateUserOperation: - case operationConstants.PNUpdateUserOperation: - case operationConstants.PNDeleteUserOperation: - case operationConstants.PNGetUserOperation: - case operationConstants.PNGetUsersOperation: - case operationConstants.PNCreateSpaceOperation: - case operationConstants.PNUpdateSpaceOperation: - case operationConstants.PNDeleteSpaceOperation: - case operationConstants.PNGetSpaceOperation: - case operationConstants.PNGetSpacesOperation: - case operationConstants.PNGetMembersOperation: - case operationConstants.PNUpdateMembersOperation: - case operationConstants.PNGetMembershipsOperation: - case operationConstants.PNUpdateMembershipsOperation: - operation = 'obj'; - break; - case operationConstants.PNAddMessageActionOperation: - case operationConstants.PNRemoveMessageActionOperation: - case operationConstants.PNGetMessageActionsOperation: - operation = 'msga'; - break; - case operationConstants.PNAccessManagerGrant: - case operationConstants.PNAccessManagerAudit: - operation = 'pam'; - break; - case operationConstants.PNAccessManagerGrantToken: - case operationConstants.PNAccessManagerRevokeToken: - operation = 'pamv3'; - break; - default: - operation = 'time'; - break; - } - - return operation; - } -} diff --git a/src/core/components/token_manager.js b/src/core/components/token_manager.js deleted file mode 100644 index 72dfa8617..000000000 --- a/src/core/components/token_manager.js +++ /dev/null @@ -1,157 +0,0 @@ -export default class { - _config; - - _cbor; - - _token; - - constructor(config, cbor) { - this._config = config; - this._cbor = cbor; - } - - setToken(token) { - if (token && token.length > 0) { - this._token = token; - } else { - this._token = undefined; - } - } - - getToken() { - return this._token; - } - - extractPermissions(permissions) { - const permissionsResult = { - read: false, - write: false, - manage: false, - delete: false, - get: false, - update: false, - join: false, - }; - - /* eslint-disable */ - - if ((permissions & 128) === 128) { - permissionsResult.join = true; - } - - if ((permissions & 64) === 64) { - permissionsResult.update = true; - } - - if ((permissions & 32) === 32) { - permissionsResult.get = true; - } - - if ((permissions & 8) === 8) { - permissionsResult.delete = true; - } - - if ((permissions & 4) === 4) { - permissionsResult.manage = true; - } - - if ((permissions & 2) === 2) { - permissionsResult.write = true; - } - - if ((permissions & 1) === 1) { - permissionsResult.read = true; - } - - /* eslint-enable */ - - return permissionsResult; - } - - parseToken(tokenString) { - const parsed = this._cbor.decodeToken(tokenString); - - if (parsed !== undefined) { - const uuidResourcePermissions = parsed.res.uuid ? Object.keys(parsed.res.uuid) : []; - const channelResourcePermissions = Object.keys(parsed.res.chan); - const groupResourcePermissions = Object.keys(parsed.res.grp); - const uuidPatternPermissions = parsed.pat.uuid ? Object.keys(parsed.pat.uuid) : []; - const channelPatternPermissions = Object.keys(parsed.pat.chan); - const groupPatternPermissions = Object.keys(parsed.pat.grp); - - const result = { - version: parsed.v, - timestamp: parsed.t, - ttl: parsed.ttl, - authorized_uuid: parsed.uuid, - }; - - const uuidResources = uuidResourcePermissions.length > 0; - const channelResources = channelResourcePermissions.length > 0; - const groupResources = groupResourcePermissions.length > 0; - - if (uuidResources || channelResources || groupResources) { - result.resources = {}; - - if (uuidResources) { - result.resources.uuids = {}; - uuidResourcePermissions.forEach((id) => { - result.resources.uuids[id] = this.extractPermissions(parsed.res.uuid[id]); - }); - } - - if (channelResources) { - result.resources.channels = {}; - channelResourcePermissions.forEach((id) => { - result.resources.channels[id] = this.extractPermissions(parsed.res.chan[id]); - }); - } - - if (groupResources) { - result.resources.groups = {}; - groupResourcePermissions.forEach((id) => { - result.resources.groups[id] = this.extractPermissions(parsed.res.grp[id]); - }); - } - } - - const uuidPatterns = uuidPatternPermissions.length > 0; - const channelPatterns = channelPatternPermissions.length > 0; - const groupPatterns = groupPatternPermissions.length > 0; - - if (uuidPatterns || channelPatterns || groupPatterns) { - result.patterns = {}; - - if (uuidPatterns) { - result.patterns.uuids = {}; - uuidPatternPermissions.forEach((id) => { - result.patterns.uuids[id] = this.extractPermissions(parsed.pat.uuid[id]); - }); - } - - if (channelPatterns) { - result.patterns.channels = {}; - channelPatternPermissions.forEach((id) => { - result.patterns.channels[id] = this.extractPermissions(parsed.pat.chan[id]); - }); - } - - if (groupPatterns) { - result.patterns.groups = {}; - groupPatternPermissions.forEach((id) => { - result.patterns.groups[id] = this.extractPermissions(parsed.pat.grp[id]); - }); - } - } - - if (Object.keys(parsed.meta).length > 0) { - result.meta = parsed.meta; - } - - result.signature = parsed.sig; - - return result; - } - return undefined; - } -} diff --git a/src/core/components/token_manager.ts b/src/core/components/token_manager.ts new file mode 100644 index 000000000..97c5944d3 --- /dev/null +++ b/src/core/components/token_manager.ts @@ -0,0 +1,333 @@ +/** + * PubNub Access Token Manager module. + */ + +import Cbor from '../../cbor/common'; +import { Payload } from '../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +type Token = { + /** + * Token version. + */ + version: number; + + /** + * Token generation date time. + */ + timestamp: number; + + /** + * Maximum duration (in minutes) during which token will be valid. + */ + ttl: number; + + /** + * Permissions granted to specific resources. + */ + resources?: Partial>>; + + /** + * Permissions granted to resources which match specified regular expression. + */ + patterns?: Partial>>; + + /** + * The uuid that is exclusively authorized to use this token to make API requests. + */ + authorized_uuid?: string; + + /** + * PAM token content signature. + */ + signature: ArrayBuffer; + + /** + * Additional information which has been added to the token. + */ + meta?: Payload; +}; + +/** + * Granted resource permissions. + * + * **Note:** Following operations doesn't require any permissions: + * - unsubscribe from channel / channel group + * - where now + */ +type Permissions = { + /** + * Resource read permission. + * + * Read permission required for: + * - subscribe to channel / channel group (including presence versions `-pnpres`) + * - here now + * - get presence state + * - set presence state + * - fetch history + * - fetch messages count + * - list shared files + * - download shared file + * - enable / disable push notifications + * - get message actions + * - get history with message actions + */ + read: boolean; + + /** + * Resource write permission. + * + * Write permission required for: + * - publish message / signal + * - share file + * - add message actions + */ + write: boolean; + + /** + * Resource manage permission. + * + * Manage permission required for: + * - add / remove channels to / from the channel group + * - list channels in group + * - remove channel group + * - set / remove channel members + */ + manage: boolean; + + /** + * Resource delete permission. + * + * Delete permission required for: + * - delete messages from history + * - delete shared file + * - delete user metadata + * - delete channel metadata + * - remove message action + */ + delete: boolean; + + /** + * Resource get permission. + * + * Get permission required for: + * - get user metadata + * - get channel metadata + * - get channel members + */ + get: boolean; + + /** + * Resource update permission. + * + * Update permissions required for: + * - set user metadata + * - set channel metadata + * - set / remove user membership + */ + update: boolean; + + /** + * Resource `join` permission. + * + * `Join` permission required for: + * - set / remove channel members + */ + join: boolean; +}; + +/** + * Raw parsed token. + * + * Representation of data stored in base64-encoded access token. + */ +type RawToken = { + /** + * Token version. + */ + v: number; + + /** + * Token generation date time. + */ + t: number; + + /** + * Maximum duration (in minutes) during which token will be valid. + */ + ttl: number; + + /** + * Permissions granted to specific resources. + */ + res: Record<'chan' | 'grp' | 'uuid', Record>; + + /** + * Permissions granted to resources which match specified regular expression. + */ + pat: Record<'chan' | 'grp' | 'uuid', Record>; + + /** + * The uuid that is exclusively authorized to use this token to make API requests. + */ + uuid?: string; + + /** + * PAM token content signature. + */ + sig: ArrayBuffer; + + /** + * Additional information which has been added to the token. + */ + meta?: Payload; +}; +// endregion + +/** + * REST API access token manager. + * + * Manager maintains active access token and let parse it to get information about permissions. + */ +export class TokenManager { + /** + * Currently used REST API Access token. + */ + private token?: string; + + constructor(private readonly cbor: Cbor) {} + + /** + * Update REST API access token. + * + * **Note:** Token will be applied only for next requests and won't affect ongoing requests. + * + * @param [token] - Access token which should be used to access PubNub REST API. + */ + public setToken(token?: string) { + if (token && token.length > 0) this.token = token; + else this.token = undefined; + } + + /** + * REST API access token. + * + * @returns Previously configured REST API access token. + */ + public getToken() { + return this.token; + } + + /** + * Parse Base64-encoded access token. + * + * @param tokenString - Base64-encoded access token. + * + * @returns Information about resources and permissions which has been granted for them. + */ + public parseToken(tokenString: string) { + const parsed = this.cbor.decodeToken(tokenString) as RawToken; + + if (parsed !== undefined) { + const uuidResourcePermissions = parsed.res.uuid ? Object.keys(parsed.res.uuid) : []; + const channelResourcePermissions = Object.keys(parsed.res.chan); + const groupResourcePermissions = Object.keys(parsed.res.grp); + const uuidPatternPermissions = parsed.pat.uuid ? Object.keys(parsed.pat.uuid) : []; + const channelPatternPermissions = Object.keys(parsed.pat.chan); + const groupPatternPermissions = Object.keys(parsed.pat.grp); + + const result: Token = { + version: parsed.v, + timestamp: parsed.t, + ttl: parsed.ttl, + authorized_uuid: parsed.uuid, + signature: parsed.sig, + }; + + const uuidResources = uuidResourcePermissions.length > 0; + const channelResources = channelResourcePermissions.length > 0; + const groupResources = groupResourcePermissions.length > 0; + + if (uuidResources || channelResources || groupResources) { + result.resources = {}; + + if (uuidResources) { + const uuids: typeof result.resources.uuids = (result.resources.uuids = {}); + uuidResourcePermissions.forEach((id) => (uuids[id] = this.extractPermissions(parsed.res.uuid[id]))); + } + + if (channelResources) { + const channels: typeof result.resources.channels = (result.resources.channels = {}); + channelResourcePermissions.forEach((id) => (channels[id] = this.extractPermissions(parsed.res.chan[id]))); + } + + if (groupResources) { + const groups: typeof result.resources.groups = (result.resources.groups = {}); + groupResourcePermissions.forEach((id) => (groups[id] = this.extractPermissions(parsed.res.grp[id]))); + } + } + + const uuidPatterns = uuidPatternPermissions.length > 0; + const channelPatterns = channelPatternPermissions.length > 0; + const groupPatterns = groupPatternPermissions.length > 0; + + if (uuidPatterns || channelPatterns || groupPatterns) { + result.patterns = {}; + + if (uuidPatterns) { + const uuids: typeof result.patterns.uuids = (result.patterns.uuids = {}); + uuidPatternPermissions.forEach((id) => (uuids[id] = this.extractPermissions(parsed.pat.uuid[id]))); + } + + if (channelPatterns) { + const channels: typeof result.patterns.channels = (result.patterns.channels = {}); + channelPatternPermissions.forEach((id) => (channels[id] = this.extractPermissions(parsed.pat.chan[id]))); + } + + if (groupPatterns) { + const groups: typeof result.patterns.groups = (result.patterns.groups = {}); + groupPatternPermissions.forEach((id) => (groups[id] = this.extractPermissions(parsed.pat.grp[id]))); + } + } + + if (parsed.meta && Object.keys(parsed.meta).length > 0) result.meta = parsed.meta; + + return result; + } + + return undefined; + } + + /** + * Extract resource access permission information. + * + * @param permissions - Bit-encoded resource permissions. + * + * @returns Human-readable resource permissions. + */ + private extractPermissions(permissions: number) { + const permissionsResult: Permissions = { + read: false, + write: false, + manage: false, + delete: false, + get: false, + update: false, + join: false, + }; + + if ((permissions & 128) === 128) permissionsResult.join = true; + if ((permissions & 64) === 64) permissionsResult.update = true; + if ((permissions & 32) === 32) permissionsResult.get = true; + if ((permissions & 8) === 8) permissionsResult.delete = true; + if ((permissions & 4) === 4) permissionsResult.manage = true; + if ((permissions & 2) === 2) permissionsResult.write = true; + if ((permissions & 1) === 1) permissionsResult.read = true; + + return permissionsResult; + } +} diff --git a/src/core/components/uuid.js b/src/core/components/uuid.ts similarity index 72% rename from src/core/components/uuid.js rename to src/core/components/uuid.ts index a22f987f7..023de232a 100644 --- a/src/core/components/uuid.js +++ b/src/core/components/uuid.ts @@ -5,6 +5,7 @@ export default { if (uuidGenerator.uuid) { return uuidGenerator.uuid(); } + // @ts-expect-error Depending on module type it may be callable. return uuidGenerator(); }, }; diff --git a/src/core/constants/categories.js b/src/core/constants/categories.js deleted file mode 100644 index bf48a79d1..000000000 --- a/src/core/constants/categories.js +++ /dev/null @@ -1,36 +0,0 @@ -/* */ -export default { - // SDK will announce when the network appears to be connected again. - PNNetworkUpCategory: 'PNNetworkUpCategory', - - // SDK will announce when the network appears to down. - PNNetworkDownCategory: 'PNNetworkDownCategory', - - // call failed when network was unable to complete the call. - PNNetworkIssuesCategory: 'PNNetworkIssuesCategory', - - // network call timed out - PNTimeoutCategory: 'PNTimeoutCategory', - - // server responded with bad response - PNBadRequestCategory: 'PNBadRequestCategory', - - // server responded with access denied - PNAccessDeniedCategory: 'PNAccessDeniedCategory', - - // something strange happened; please check the logs. - PNUnknownCategory: 'PNUnknownCategory', - - // on reconnection - PNReconnectedCategory: 'PNReconnectedCategory', - - PNConnectedCategory: 'PNConnectedCategory', - - PNRequestMessageCountExceededCategory: 'PNRequestMessageCountExceededCategory', - - PNDisconnectedCategory: 'PNDisconnectedCategory', - - PNConnectionErrorCategory: 'PNConnectionErrorCategory', - - PNDisconnectedUnexpectedlyCategory: 'PNDisconnectedUnexpectedlyCategory', -}; diff --git a/src/core/constants/categories.ts b/src/core/constants/categories.ts new file mode 100644 index 000000000..6550b4538 --- /dev/null +++ b/src/core/constants/categories.ts @@ -0,0 +1,99 @@ +/** + * Request processing status categories. + */ +enum StatusCategory { + /** + * Call failed when network was unable to complete the call. + */ + PNNetworkIssuesCategory = 'PNNetworkIssuesCategory', + + /** + * Network call timed out. + */ + PNTimeoutCategory = 'PNTimeoutCategory', + + /** + * Request has been cancelled. + */ + PNCancelledCategory = 'PNCancelledCategory', + + /** + * Server responded with bad response. + */ + PNBadRequestCategory = 'PNBadRequestCategory', + + /** + * Server responded with access denied. + */ + PNAccessDeniedCategory = 'PNAccessDeniedCategory', + + /** + * Incomplete parameters provided for used endpoint. + */ + PNValidationErrorCategory = 'PNValidationErrorCategory', + + /** + * PubNub request acknowledgment status. + * + * Some API endpoints respond with request processing status w/o useful data. + */ + PNAcknowledgmentCategory = 'PNAcknowledgmentCategory', + + /** + * Something strange happened; please check the logs. + */ + PNUnknownCategory = 'PNUnknownCategory', + + // -------------------------------------------------------- + // --------------------- Network status ------------------- + // -------------------------------------------------------- + + /** + * SDK will announce when the network appears to be connected again. + */ + PNNetworkUpCategory = 'PNNetworkUpCategory', + + /** + * SDK will announce when the network appears to down. + */ + PNNetworkDownCategory = 'PNNetworkDownCategory', + + // -------------------------------------------------------- + // -------------------- Real-time events ------------------ + // -------------------------------------------------------- + + /** + * PubNub client reconnected to the real-time updates stream. + */ + PNReconnectedCategory = 'PNReconnectedCategory', + + /** + * PubNub client connected to the real-time updates stream. + */ + PNConnectedCategory = 'PNConnectedCategory', + + /** + * Received real-time updates exceed specified threshold. + * + * After temporary disconnection and catchup, this category means that potentially some + * real-time updates have been pushed into `storage` and need to be requested separately. + */ + PNRequestMessageCountExceededCategory = 'PNRequestMessageCountExceededCategory', + + /** + * PubNub client disconnected from the real-time updates streams. + */ + PNDisconnectedCategory = 'PNDisconnectedCategory', + + /** + * PubNub client wasn't able to connect to the real-time updates streams. + */ + PNConnectionErrorCategory = 'PNConnectionErrorCategory', + + /** + * PubNub client unexpectedly disconnected from the real-time updates streams. + */ + PNDisconnectedUnexpectedlyCategory = 'PNDisconnectedUnexpectedlyCategory', +} + +export default StatusCategory; diff --git a/src/core/constants/operations.js b/src/core/constants/operations.js deleted file mode 100644 index 7d1ffcaca..000000000 --- a/src/core/constants/operations.js +++ /dev/null @@ -1,92 +0,0 @@ -/* */ -export default { - PNTimeOperation: 'PNTimeOperation', - - PNHistoryOperation: 'PNHistoryOperation', - PNDeleteMessagesOperation: 'PNDeleteMessagesOperation', - PNFetchMessagesOperation: 'PNFetchMessagesOperation', - PNMessageCounts: 'PNMessageCountsOperation', - - // pubsub - PNSubscribeOperation: 'PNSubscribeOperation', - PNUnsubscribeOperation: 'PNUnsubscribeOperation', - PNPublishOperation: 'PNPublishOperation', - PNSignalOperation: 'PNSignalOperation', - - // Actions API - PNAddMessageActionOperation: 'PNAddActionOperation', - PNRemoveMessageActionOperation: 'PNRemoveMessageActionOperation', - PNGetMessageActionsOperation: 'PNGetMessageActionsOperation', - - // Objects API - 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', - - // File Upload API v1 - PNListFilesOperation: 'PNListFilesOperation', - PNGenerateUploadUrlOperation: 'PNGenerateUploadUrlOperation', - PNPublishFileOperation: 'PNPublishFileOperation', - PNGetFileUrlOperation: 'PNGetFileUrlOperation', - PNDownloadFileOperation: 'PNDownloadFileOperation', - - // Objects API v2 - // UUID - PNGetAllUUIDMetadataOperation: 'PNGetAllUUIDMetadataOperation', - PNGetUUIDMetadataOperation: 'PNGetUUIDMetadataOperation', - PNSetUUIDMetadataOperation: 'PNSetUUIDMetadataOperation', - PNRemoveUUIDMetadataOperation: 'PNRemoveUUIDMetadataOperation', - // channel - PNGetAllChannelMetadataOperation: 'PNGetAllChannelMetadataOperation', - PNGetChannelMetadataOperation: 'PNGetChannelMetadataOperation', - PNSetChannelMetadataOperation: 'PNSetChannelMetadataOperation', - PNRemoveChannelMetadataOperation: 'PNRemoveChannelMetadataOperation', - // member - // PNGetMembersOperation: 'PNGetMembersOperation', - PNSetMembersOperation: 'PNSetMembersOperation', - // PNGetMembershipsOperation: 'PNGetMembersOperation', - PNSetMembershipsOperation: 'PNSetMembershipsOperation', - - // push - PNPushNotificationEnabledChannelsOperation: 'PNPushNotificationEnabledChannelsOperation', - PNRemoveAllPushNotificationsOperation: 'PNRemoveAllPushNotificationsOperation', - // - - // presence - PNWhereNowOperation: 'PNWhereNowOperation', - PNSetStateOperation: 'PNSetStateOperation', - PNHereNowOperation: 'PNHereNowOperation', - PNGetStateOperation: 'PNGetStateOperation', - PNHeartbeatOperation: 'PNHeartbeatOperation', - // - - // channel group - PNChannelGroupsOperation: 'PNChannelGroupsOperation', - PNRemoveGroupOperation: 'PNRemoveGroupOperation', - PNChannelsForGroupOperation: 'PNChannelsForGroupOperation', - PNAddChannelsToGroupOperation: 'PNAddChannelsToGroupOperation', - PNRemoveChannelsFromGroupOperation: 'PNRemoveChannelsFromGroupOperation', - // - - // PAM - PNAccessManagerGrant: 'PNAccessManagerGrant', - PNAccessManagerGrantToken: 'PNAccessManagerGrantToken', - PNAccessManagerAudit: 'PNAccessManagerAudit', - PNAccessManagerRevokeToken: 'PNAccessManagerRevokeToken', - // - - // subscription utilities - PNHandshakeOperation: 'PNHandshakeOperation', - PNReceiveMessagesOperation: 'PNReceiveMessagesOperation', -}; diff --git a/src/core/constants/operations.ts b/src/core/constants/operations.ts new file mode 100644 index 000000000..196dc98cd --- /dev/null +++ b/src/core/constants/operations.ts @@ -0,0 +1,298 @@ +/* */ +enum RequestOperation { + // -------------------------------------------------------- + // ---------------------- Publish API --------------------- + // -------------------------------------------------------- + /** + * Data publish REST API operation. + */ + PNPublishOperation = 'PNPublishOperation', + + /** + * Signal sending REST API operation. + */ + PNSignalOperation = 'PNSignalOperation', + + // -------------------------------------------------------- + // --------------------- Subscribe API -------------------- + // -------------------------------------------------------- + /** + * Subscribe for real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `join` event. + */ + PNSubscribeOperation = 'PNSubscribeOperation', + + /** + * Unsubscribe from real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `leave` event. + */ + PNUnsubscribeOperation = 'PNUnsubscribeOperation', + + // -------------------------------------------------------- + // --------------------- Presence API --------------------- + // -------------------------------------------------------- + + /** + * Fetch user's presence information REST API operation. + */ + PNWhereNowOperation = 'PNWhereNowOperation', + + /** + * Fetch channel's presence information REST API operation. + */ + PNHereNowOperation = 'PNHereNowOperation', + + /** + * Fetch global presence information REST API operation. + */ + PNGlobalHereNowOperation = 'PNGlobalHereNowOperation', + + /** + * Update user's information associated with specified channel REST API operation. + */ + PNSetStateOperation = 'PNSetStateOperation', + + /** + * Fetch user's information associated with the specified channel REST API operation. + */ + PNGetStateOperation = 'PNGetStateOperation', + + /** + * Announce presence on managed channels REST API operation. + */ + PNHeartbeatOperation = 'PNHeartbeatOperation', + + // -------------------------------------------------------- + // ----------------- Message Reaction API ----------------- + // -------------------------------------------------------- + + /** + * Add a reaction to the specified message REST API operation. + */ + PNAddMessageActionOperation = 'PNAddActionOperation', + + /** + * Remove reaction from the specified message REST API operation. + */ + PNRemoveMessageActionOperation = 'PNRemoveMessageActionOperation', + + /** + * Fetch reactions for specific message REST API operation. + */ + PNGetMessageActionsOperation = 'PNGetMessageActionsOperation', + + PNTimeOperation = 'PNTimeOperation', + + // -------------------------------------------------------- + // ---------------------- Storage API --------------------- + // -------------------------------------------------------- + + /** + * Channel history REST API operation. + */ + PNHistoryOperation = 'PNHistoryOperation', + + /** + * Delete messages from channel history REST API operation. + */ + PNDeleteMessagesOperation = 'PNDeleteMessagesOperation', + + /** + * History for channels REST API operation. + */ + PNFetchMessagesOperation = 'PNFetchMessagesOperation', + + /** + * Number of messages for channels in specified time frame REST API operation. + */ + PNMessageCounts = 'PNMessageCountsOperation', + + // -------------------------------------------------------- + // -------------------- App Context API ------------------- + // -------------------------------------------------------- + + /** + * Fetch users metadata REST API operation. + */ + PNGetAllUUIDMetadataOperation = 'PNGetAllUUIDMetadataOperation', + + /** + * Fetch user metadata REST API operation. + */ + PNGetUUIDMetadataOperation = 'PNGetUUIDMetadataOperation', + + /** + * Set user metadata REST API operation. + */ + PNSetUUIDMetadataOperation = 'PNSetUUIDMetadataOperation', + + /** + * Remove user metadata REST API operation. + */ + PNRemoveUUIDMetadataOperation = 'PNRemoveUUIDMetadataOperation', + + /** + * Fetch channels metadata REST API operation. + */ + PNGetAllChannelMetadataOperation = 'PNGetAllChannelMetadataOperation', + + /** + * Fetch channel metadata REST API operation. + */ + PNGetChannelMetadataOperation = 'PNGetChannelMetadataOperation', + + /** + * Set channel metadata REST API operation. + */ + PNSetChannelMetadataOperation = 'PNSetChannelMetadataOperation', + + /** + * Remove channel metadata REST API operation. + */ + PNRemoveChannelMetadataOperation = 'PNRemoveChannelMetadataOperation', + + /** + * Fetch channel members REST API operation. + */ + PNGetMembersOperation = 'PNGetMembersOperation', + + /** + * Update channel members REST API operation. + */ + PNSetMembersOperation = 'PNSetMembersOperation', + + /** + * Fetch channel memberships REST API operation. + */ + PNGetMembershipsOperation = 'PNGetMembershipsOperation', + + /** + * Update channel memberships REST API operation. + */ + PNSetMembershipsOperation = 'PNSetMembershipsOperation', + + // -------------------------------------------------------- + // -------------------- File Upload API ------------------- + // -------------------------------------------------------- + + /** + * Fetch list of files sent to the channel REST API operation. + */ + PNListFilesOperation = 'PNListFilesOperation', + + /** + * Retrieve file upload URL REST API operation. + */ + PNGenerateUploadUrlOperation = 'PNGenerateUploadUrlOperation', + + /** + * Upload file to the channel REST API operation. + */ + PNPublishFileOperation = 'PNPublishFileOperation', + + /** + * Publish File Message to the channel REST API operation. + */ + PNPublishFileMessageOperation = 'PNPublishFileMessageOperation', + + /** + * Retrieve file download URL REST API operation. + */ + PNGetFileUrlOperation = 'PNGetFileUrlOperation', + + /** + * Download file from the channel REST API operation. + */ + PNDownloadFileOperation = 'PNDownloadFileOperation', + + /** + * Delete file sent to the channel REST API operation. + */ + PNDeleteFileOperation = 'PNDeleteFileOperation', + + // -------------------------------------------------------- + // -------------------- Mobile Push API ------------------- + // -------------------------------------------------------- + + /** + * Register channels with device push notifications REST API operation. + */ + PNAddPushNotificationEnabledChannelsOperation = 'PNAddPushNotificationEnabledChannelsOperation', + + /** + * Unregister channels with device push notifications REST API operation. + */ + PNRemovePushNotificationEnabledChannelsOperation = 'PNRemovePushNotificationEnabledChannelsOperation', + + /** + * Fetch list of channels with enabled push notifications for device REST API operation. + */ + PNPushNotificationEnabledChannelsOperation = 'PNPushNotificationEnabledChannelsOperation', + + /** + * Disable push notifications for device REST API operation. + */ + PNRemoveAllPushNotificationsOperation = 'PNRemoveAllPushNotificationsOperation', + + // -------------------------------------------------------- + // ------------------ Channel Groups API ------------------ + // -------------------------------------------------------- + + /** + * Fetch channels groups list REST API operation. + */ + PNChannelGroupsOperation = 'PNChannelGroupsOperation', + + /** + * Remove specified channel group REST API operation. + */ + PNRemoveGroupOperation = 'PNRemoveGroupOperation', + + /** + * Fetch list of channels for the specified channel group REST API operation. + */ + PNChannelsForGroupOperation = 'PNChannelsForGroupOperation', + + /** + * Add list of channels to the specified channel group REST API operation. + */ + PNAddChannelsToGroupOperation = 'PNAddChannelsToGroupOperation', + + /** + * Remove list of channels from the specified channel group REST API operation. + */ + PNRemoveChannelsFromGroupOperation = 'PNRemoveChannelsFromGroupOperation', + + // -------------------------------------------------------- + // ----------------------- PAM API ------------------------ + // -------------------------------------------------------- + + /** + * Generate authorized token REST API operation. + */ + PNAccessManagerGrant = 'PNAccessManagerGrant', + + /** + * Generate authorized token REST API operation. + */ + PNAccessManagerGrantToken = 'PNAccessManagerGrantToken', + + PNAccessManagerAudit = 'PNAccessManagerAudit', + + /** + * Revoke authorized token REST API operation. + */ + PNAccessManagerRevokeToken = 'PNAccessManagerRevokeToken', + // + + // -------------------------------------------------------- + // ---------------- Subscription Utility ------------------ + // -------------------------------------------------------- + + PNHandshakeOperation = 'PNHandshakeOperation', + PNReceiveMessagesOperation = 'PNReceiveMessagesOperation', +} + +export default RequestOperation; diff --git a/src/core/endpoints/access_manager/audit.js b/src/core/endpoints/access_manager/audit.js deleted file mode 100644 index dcbab0a74..000000000 --- a/src/core/endpoints/access_manager/audit.js +++ /dev/null @@ -1,49 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; - -export function getOperation() { - return operationConstants.PNAccessManagerAudit; -} - -export function validateParams(modules) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules) { - const { config } = modules; - return `/v2/auth/audit/sub-key/${config.subscribeKey}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return false; -} - -export function prepareParams(modules, incomingParams) { - const { channel, channelGroup, authKeys = [] } = incomingParams; - const params = {}; - - if (channel) { - params.channel = channel; - } - - if (channelGroup) { - params['channel-group'] = channelGroup; - } - - if (authKeys.length > 0) { - params.auth = authKeys.join(','); - } - - return params; -} - -export function handleResponse(modules, serverResponse) { - return serverResponse.payload; -} diff --git a/src/core/endpoints/access_manager/audit.ts b/src/core/endpoints/access_manager/audit.ts new file mode 100644 index 000000000..e9aa8b8fd --- /dev/null +++ b/src/core/endpoints/access_manager/audit.ts @@ -0,0 +1,110 @@ +/** + * PAM Audit REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import * as PAM from '../../types/api/access-panager'; +import { KeySet, Query } from '../../types/api'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Auth keys for which permissions should be audited. + */ +const AUTH_KEYS: string[] = []; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = PAM.AuditParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Permissions audit human-readable result. + */ + message: string; + + /** + * Retrieved permissions information. + */ + payload: PAM.PermissionsResponse; + + /** + * Name of the service which provided response. + */ + service: string; +}; +// endregion + +/** + * Permissions audit request. + */ +export class AuditRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply default request parameters. + this.parameters.authKeys ??= AUTH_KEYS; + } + + operation(): RequestOperation { + return RequestOperation.PNAccessManagerAudit; + } + + validate(): string | undefined { + if (!this.parameters.keySet.subscribeKey) return 'Missing Subscribe Key'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse.payload; + } + + protected get path(): string { + return `/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`; + } + + protected get queryParameters(): Query { + const { channel, channelGroup, authKeys } = this.parameters; + + return { + ...(channel ? { channel } : {}), + ...(channelGroup ? { 'channel-group': channelGroup } : {}), + ...(authKeys && authKeys.length ? { auth: authKeys.join(',') } : {}), + }; + } +} diff --git a/src/core/endpoints/access_manager/grant.js b/src/core/endpoints/access_manager/grant.js deleted file mode 100644 index 9d63f84a8..000000000 --- a/src/core/endpoints/access_manager/grant.js +++ /dev/null @@ -1,84 +0,0 @@ -/* */ -import operationConstants from '../../constants/operations'; - -export function getOperation() { - return operationConstants.PNAccessManagerGrant; -} - -export function validateParams(modules, incomingParams) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; - if (!config.publishKey) return 'Missing Publish Key'; - if (!config.secretKey) return 'Missing Secret Key'; - if (incomingParams.uuids != null && !incomingParams.authKeys) { - return 'authKeys are required for grant request on uuids'; - } - if (incomingParams.uuids != null && (incomingParams.channels != null || incomingParams.channelGroups != null)) { - return 'Both channel/channelgroup and uuid cannot be used in the same request'; - } -} - -export function getURL(modules) { - const { config } = modules; - return `/v2/auth/grant/sub-key/${config.subscribeKey}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return false; -} - -export function prepareParams(modules, incomingParams) { - const { - channels = [], - channelGroups = [], - uuids = [], - ttl, - read = false, - write = false, - manage = false, - get = false, - join = false, - update = false, - authKeys = [], - } = incomingParams; - const deleteParam = incomingParams.delete; - const params = {}; - - params.r = read ? '1' : '0'; - params.w = write ? '1' : '0'; - params.m = manage ? '1' : '0'; - params.d = deleteParam ? '1' : '0'; - params.g = get ? '1' : '0'; - params.j = join ? '1' : '0'; - params.u = update ? '1' : '0'; - - if (channels.length > 0) { - params.channel = channels.join(','); - } - - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - - if (authKeys.length > 0) { - params.auth = authKeys.join(','); - } - - if (uuids.length > 0) { - params['target-uuid'] = uuids.join(','); - } - - if (ttl || ttl === 0) { - params.ttl = ttl; - } - return params; -} - -export function handleResponse() { - return {}; -} diff --git a/src/core/endpoints/access_manager/grant.ts b/src/core/endpoints/access_manager/grant.ts new file mode 100644 index 000000000..43b98208d --- /dev/null +++ b/src/core/endpoints/access_manager/grant.ts @@ -0,0 +1,186 @@ +/** + * PAM Grant REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import * as PAM from '../../types/api/access-panager'; +import { KeySet, Query } from '../../types/api'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Resources `read` permission. + */ +const READ_PERMISSION = false; + +/** + * Resources `write` permission. + */ +const WRITE_PERMISSION = false; + +/** + * Resources `delete` permission. + */ +const DELETE_PERMISSION = false; + +/** + * Resources `get` permission. + */ +const GET_PERMISSION = false; + +/** + * Resources `update` permission. + */ +const UPDATE_PERMISSION = false; + +/** + * Resources `manage` permission. + */ +const MANAGE_PERMISSION = false; + +/** + * Resources `join` permission. + */ +const JOIN_PERMISSION = false; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = PAM.GrantParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Permissions grant human-readable result. + */ + message: string; + + /** + * Granted permissions' information. + */ + payload: PAM.PermissionsResponse; + + /** + * Name of the service which provided response. + */ + service: string; +}; +// endregion + +/** + * Grant permissions request. + */ +export class GrantRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply defaults. + this.parameters.channels ??= []; + this.parameters.channelGroups ??= []; + this.parameters.uuids ??= []; + this.parameters.read ??= READ_PERMISSION; + this.parameters.write ??= WRITE_PERMISSION; + this.parameters.delete ??= DELETE_PERMISSION; + this.parameters.get ??= GET_PERMISSION; + this.parameters.update ??= UPDATE_PERMISSION; + this.parameters.manage ??= MANAGE_PERMISSION; + this.parameters.join ??= JOIN_PERMISSION; + } + + operation(): RequestOperation { + return RequestOperation.PNAccessManagerGrant; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey, publishKey, secretKey }, + uuids = [], + channels = [], + channelGroups = [], + authKeys = [], + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!publishKey) return 'Missing Publish Key'; + if (!secretKey) return 'Missing Secret Key'; + + if (uuids.length !== 0 && authKeys.length === 0) return 'authKeys are required for grant request on uuids'; + + if (uuids.length && (channels.length !== 0 || channelGroups.length !== 0)) + return 'Both channel/channel group and uuid cannot be used in the same request'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse.payload; + } + + protected get path(): string { + return `/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`; + } + + protected get queryParameters(): Query { + const { + channels, + channelGroups, + authKeys, + uuids, + read, + write, + manage, + delete: del, + get, + join, + update, + ttl, + } = this.parameters; + + return { + ...(channels && channels?.length > 0 ? { channel: channels.join(',') } : {}), + ...(channelGroups && channelGroups?.length > 0 ? { 'channel-group': channelGroups.join(',') } : {}), + ...(authKeys && authKeys?.length > 0 ? { auth: authKeys.join(',') } : {}), + ...(uuids && uuids?.length > 0 ? { 'target-uuid': uuids.join(',') } : {}), + r: read ? '1' : '0', + w: write ? '1' : '0', + m: manage ? '1' : '0', + d: del ? '1' : '0', + g: get ? '1' : '0', + j: join ? '1' : '0', + u: update ? '1' : '0', + ...(ttl || ttl === 0 ? { ttl } : {}), + }; + } +} diff --git a/src/core/endpoints/access_manager/grant_token.js b/src/core/endpoints/access_manager/grant_token.js deleted file mode 100644 index 1e0ae8e25..000000000 --- a/src/core/endpoints/access_manager/grant_token.js +++ /dev/null @@ -1,299 +0,0 @@ -import operationConstants from '../../constants/operations'; - -export function getOperation() { - return operationConstants.PNAccessManagerGrantToken; -} - -function hasVspTerms(incomingParams) { - const hasAuthorizedUserId = incomingParams?.authorizedUserId !== undefined; - const hasUserResources = incomingParams?.resources?.users !== undefined; - const hasSpaceResources = incomingParams?.resources?.spaces !== undefined; - const hasUserPatterns = incomingParams?.patterns?.users !== undefined; - const hasSpacePatterns = incomingParams?.patterns?.spaces !== undefined; - - return hasUserPatterns || hasUserResources || hasSpacePatterns || hasSpaceResources || hasAuthorizedUserId; -} - -export function extractPermissions(permissions) { - let permissionsResult = 0; - - if (permissions.join) { - permissionsResult |= 128; - } - - if (permissions.update) { - permissionsResult |= 64; - } - - if (permissions.get) { - permissionsResult |= 32; - } - - if (permissions.delete) { - permissionsResult |= 8; - } - - if (permissions.manage) { - permissionsResult |= 4; - } - - if (permissions.write) { - permissionsResult |= 2; - } - - if (permissions.read) { - permissionsResult |= 1; - } - - return permissionsResult; -} - -function prepareMessagePayloadVsp(_modules, { ttl, resources, patterns, meta, authorizedUserId }) { - const params = { - ttl: 0, - permissions: { - resources: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, // not used, needed for api backward compatibility - spaces: {}, // not used, needed for api backward compatibility - }, - patterns: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, // not used, needed for api backward compatibility - spaces: {}, // not used, needed for api backward compatibility - }, - meta: {}, - }, - }; - - if (resources) { - const { users, spaces, groups } = resources; - - if (users) { - Object.keys(users).forEach((userID) => { - params.permissions.resources.uuids[userID] = extractPermissions(users[userID]); - }); - } - - if (spaces) { - Object.keys(spaces).forEach((spaceId) => { - params.permissions.resources.channels[spaceId] = extractPermissions(spaces[spaceId]); - }); - } - - if (groups) { - Object.keys(groups).forEach((group) => { - params.permissions.resources.groups[group] = extractPermissions(groups[group]); - }); - } - } - - if (patterns) { - const { users, spaces, groups } = patterns; - - if (users) { - Object.keys(users).forEach((userId) => { - params.permissions.patterns.uuids[userId] = extractPermissions(users[userId]); - }); - } - - if (spaces) { - Object.keys(spaces).forEach((spaceId) => { - params.permissions.patterns.channels[spaceId] = extractPermissions(spaces[spaceId]); - }); - } - - if (groups) { - Object.keys(groups).forEach((group) => { - params.permissions.patterns.groups[group] = extractPermissions(groups[group]); - }); - } - } - - if (ttl || ttl === 0) { - params.ttl = ttl; - } - - if (meta) { - params.permissions.meta = meta; - } - - if (authorizedUserId) { - params.permissions.uuid = `${authorizedUserId}`; // ensure this is a string - } - - return params; -} - -function prepareMessagePayload(_modules, incomingParams) { - if (hasVspTerms(incomingParams)) { - return prepareMessagePayloadVsp(_modules, incomingParams); - } - - const { ttl, resources, patterns, meta, authorized_uuid } = incomingParams; - - const params = { - ttl: 0, - permissions: { - resources: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, // not used, needed for api backward compatibility - spaces: {}, // not used, needed for api backward compatibility - }, - patterns: { - channels: {}, - groups: {}, - uuids: {}, - users: {}, // not used, needed for api backward compatibility - spaces: {}, // not used, needed for api backward compatibility - }, - meta: {}, - }, - }; - - if (resources) { - const { uuids, channels, groups } = resources; - - if (uuids) { - Object.keys(uuids).forEach((uuid) => { - params.permissions.resources.uuids[uuid] = extractPermissions(uuids[uuid]); - }); - } - - if (channels) { - Object.keys(channels).forEach((channel) => { - params.permissions.resources.channels[channel] = extractPermissions(channels[channel]); - }); - } - - if (groups) { - Object.keys(groups).forEach((group) => { - params.permissions.resources.groups[group] = extractPermissions(groups[group]); - }); - } - } - - if (patterns) { - const { uuids, channels, groups } = patterns; - - if (uuids) { - Object.keys(uuids).forEach((uuid) => { - params.permissions.patterns.uuids[uuid] = extractPermissions(uuids[uuid]); - }); - } - - if (channels) { - Object.keys(channels).forEach((channel) => { - params.permissions.patterns.channels[channel] = extractPermissions(channels[channel]); - }); - } - - if (groups) { - Object.keys(groups).forEach((group) => { - params.permissions.patterns.groups[group] = extractPermissions(groups[group]); - }); - } - } - - if (ttl || ttl === 0) { - params.ttl = ttl; - } - - if (meta) { - params.permissions.meta = meta; - } - - if (authorized_uuid) { - params.permissions.uuid = `${authorized_uuid}`; // ensure this is a string - } - - return params; -} - -export function validateParams(modules, incomingParams) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; - if (!config.publishKey) return 'Missing Publish Key'; - if (!config.secretKey) return 'Missing Secret Key'; - - if (!incomingParams.resources && !incomingParams.patterns) return 'Missing either Resources or Patterns.'; - - const hasAuthorizedUuid = incomingParams?.authorized_uuid !== undefined; - const hasUuidResources = incomingParams?.resources?.uuids !== undefined; - const hasChannelResources = incomingParams?.resources?.channels !== undefined; - const hasGroupResources = incomingParams?.resources?.groups !== undefined; - const hasUuidPatterns = incomingParams?.patterns?.uuids !== undefined; - const hasChannelPatterns = incomingParams?.patterns?.channels !== undefined; - const hasGroupPatterns = incomingParams?.patterns?.groups !== undefined; - - const hasLegacyTerms = - hasAuthorizedUuid || - hasUuidResources || - hasUuidPatterns || - hasChannelResources || - hasChannelPatterns || - hasGroupResources || - hasGroupPatterns; - - if (hasVspTerms(incomingParams) && hasLegacyTerms) { - return ( - 'Cannot mix `users`, `spaces` and `authorizedUserId` ' + - 'with `uuids`, `channels`, `groups` and `authorized_uuid`' - ); - } - - if ( - (incomingParams.resources && - (!incomingParams.resources.uuids || Object.keys(incomingParams.resources.uuids).length === 0) && - (!incomingParams.resources.channels || Object.keys(incomingParams.resources.channels).length === 0) && - (!incomingParams.resources.groups || Object.keys(incomingParams.resources.groups).length === 0) && - (!incomingParams.resources.users || Object.keys(incomingParams.resources.users).length === 0) && - (!incomingParams.resources.spaces || Object.keys(incomingParams.resources.spaces).length === 0)) || - (incomingParams.patterns && - (!incomingParams.patterns.uuids || Object.keys(incomingParams.patterns.uuids).length === 0) && - (!incomingParams.patterns.channels || Object.keys(incomingParams.patterns.channels).length === 0) && - (!incomingParams.patterns.groups || Object.keys(incomingParams.patterns.groups).length === 0) && - (!incomingParams.patterns.users || Object.keys(incomingParams.patterns.users).length === 0) && - (!incomingParams.patterns.spaces || Object.keys(incomingParams.patterns.spaces).length === 0)) - ) { - return 'Missing values for either Resources or Patterns.'; - } -} - -export function postURL(modules) { - const { config } = modules; - return `/v3/pam/${config.subscribeKey}/grant`; -} - -export function usePost() { - return true; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return false; -} - -export function prepareParams() { - return {}; -} - -export function postPayload(modules, incomingParams) { - return prepareMessagePayload(modules, incomingParams); -} - -export function handleResponse(modules, response) { - const { token } = response.data; - - return token; -} diff --git a/src/core/endpoints/access_manager/grant_token.ts b/src/core/endpoints/access_manager/grant_token.ts new file mode 100644 index 000000000..cd9b898dd --- /dev/null +++ b/src/core/endpoints/access_manager/grant_token.ts @@ -0,0 +1,271 @@ +/** + * PAM Grant Token REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../types/transport-request'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import * as PAM from '../../types/api/access-panager'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = (PAM.GrantTokenParameters | PAM.ObjectsGrantTokenParameters) & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Permissions group payload. + * + * User can configure permissions per-resource or per-resource which match RegExp. + */ +type PermissionPayload = { + /** + * Object containing `uuid` metadata permissions. + */ + uuids?: Record; + + /** + * Object containing `channel` permissions. + */ + channels?: Record; + + /** + * Object containing `channel group` permissions. + */ + groups?: Record; + + /** + * Extra metadata to be published with the request. + * + * **Important:** Values must be scalar only; `arrays` or `objects` aren't supported. + */ + meta?: PAM.Metadata; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Request processing result data. + */ + data: { + /** + * Permissions token grant human-readable result. + */ + message: string; + + /** + * Generate token with requested permissions. + */ + token: string; + }; + + /** + * Name of the service which provided response. + */ + service: string; +}; +// endregion + +/** + * Grant token permissions request. + */ +export class GrantTokenRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.POST }); + + // Apply defaults. + this.parameters.resources ??= {}; + this.parameters.patterns ??= {}; + } + + operation(): RequestOperation { + return RequestOperation.PNAccessManagerGrantToken; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey, publishKey, secretKey }, + resources, + patterns, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!publishKey) return 'Missing Publish Key'; + if (!secretKey) return 'Missing Secret Key'; + if (!resources && !patterns) return 'Missing either Resources or Patterns'; + + if ( + this.isVspPermissions(this.parameters) && + ('channels' in (this.parameters.resources ?? {}) || + 'uuids' in (this.parameters.resources ?? {}) || + 'groups' in (this.parameters.resources ?? {}) || + 'channels' in (this.parameters.patterns ?? {}) || + 'uuids' in (this.parameters.patterns ?? {}) || + 'groups' in (this.parameters.patterns ?? {})) + ) + return ( + 'Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`,' + + ' `groups` and `authorized_uuid`' + ); + + let permissionsEmpty = true; + [this.parameters.resources, this.parameters.patterns].forEach((refPerm) => { + Object.keys(refPerm ?? {}).forEach((scope) => { + // @ts-expect-error Permissions with backward compatibility. + if (refPerm && permissionsEmpty && Object.keys(refPerm[scope] ?? {}).length > 0) { + permissionsEmpty = false; + } + }); + }); + + if (permissionsEmpty) return 'Missing values for either Resources or Patterns'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse.data.token; + } + + protected get path(): string { + return `/v3/pam/${this.parameters.keySet.subscribeKey}/grant`; + } + + protected get body(): string { + const { ttl, meta } = this.parameters; + const body: Record = { ...(ttl || ttl === 0 ? { ttl } : {}) }; + const uuid = this.isVspPermissions(this.parameters) + ? this.parameters.authorizedUserId + : this.parameters.authorized_uuid; + + const permissions: Record> = {}; + const resourcePermissions: PermissionPayload = {}; + const patternPermissions: PermissionPayload = {}; + const mapPermissions = ( + name: string, + permissionBit: number, + type: keyof PermissionPayload, + permissions: PermissionPayload, + ) => { + if (!permissions[type]) permissions[type] = {}; + permissions[type]![name] = permissionBit; + }; + + const { resources, patterns } = this.parameters; + [resources, patterns].forEach((refPerm, idx) => { + const target = idx === 0 ? resourcePermissions : patternPermissions; + let channelsPermissions: Record = {}; + let channelGroupsPermissions: Record = {}; + let uuidsPermissions: Record = {}; + + if (!target.channels) target.channels = {}; + if (!target.groups) target.groups = {}; + if (!target.uuids) target.uuids = {}; + // @ts-expect-error Not used, needed for api backward compatibility + if (!target.users) target.users = {}; + // @ts-expect-error Not used, needed for api backward compatibility + if (!target.spaces) target.spaces = {}; + + if (refPerm) { + // Check whether working with legacy Objects permissions. + if ('spaces' in refPerm || 'users' in refPerm) { + channelsPermissions = refPerm.spaces ?? {}; + uuidsPermissions = refPerm.users ?? {}; + } else if ('channels' in refPerm || 'uuids' in refPerm || 'groups' in refPerm) { + channelsPermissions = refPerm.channels ?? {}; + channelGroupsPermissions = refPerm.groups ?? {}; + uuidsPermissions = refPerm.uuids ?? {}; + } + } + + Object.keys(channelsPermissions).forEach((channel) => + mapPermissions(channel, this.extractPermissions(channelsPermissions[channel]), 'channels', target), + ); + + Object.keys(channelGroupsPermissions).forEach((groups) => + mapPermissions(groups, this.extractPermissions(channelGroupsPermissions[groups]), 'groups', target), + ); + + Object.keys(uuidsPermissions).forEach((uuids) => + mapPermissions(uuids, this.extractPermissions(uuidsPermissions[uuids]), 'uuids', target), + ); + }); + + if (uuid) permissions.uuid = `${uuid}`; + permissions.resources = resourcePermissions; + permissions.patterns = patternPermissions; + permissions.meta = meta ?? {}; + body.permissions = permissions; + + return JSON.stringify(body); + } + + /** + * Extract permissions bit from permission configuration object. + * + * @param permissions - User provided scope-based permissions. + * + * @returns Permissions bit. + */ + private extractPermissions( + permissions: PAM.UuidTokenPermissions | PAM.ChannelTokenPermissions | PAM.ChannelGroupTokenPermissions, + ): number { + let permissionsResult = 0; + + if ('join' in permissions && permissions.join) permissionsResult |= 128; + if ('update' in permissions && permissions.update) permissionsResult |= 64; + if ('get' in permissions && permissions.get) permissionsResult |= 32; + if ('delete' in permissions && permissions.delete) permissionsResult |= 8; + if ('manage' in permissions && permissions.manage) permissionsResult |= 4; + if ('write' in permissions && permissions.write) permissionsResult |= 2; + if ('read' in permissions && permissions.read) permissionsResult |= 1; + + return permissionsResult; + } + + /** + * Check whether provided parameters is part of legacy VSP access token configuration. + * + * @param parameters - Parameters which should be checked. + * + * @returns VSP request parameters if it is legacy configuration. + */ + private isVspPermissions( + parameters: PAM.GrantTokenParameters | PAM.ObjectsGrantTokenParameters, + ): parameters is PAM.ObjectsGrantTokenParameters { + return ( + 'authorizedUserId' in parameters || + 'spaces' in (parameters.resources ?? {}) || + 'users' in (parameters.resources ?? {}) || + 'spaces' in (parameters.patterns ?? {}) || + 'users' in (parameters.patterns ?? {}) + ); + } +} diff --git a/src/core/endpoints/access_manager/revoke_token.js b/src/core/endpoints/access_manager/revoke_token.js deleted file mode 100644 index ab457f2db..000000000 --- a/src/core/endpoints/access_manager/revoke_token.js +++ /dev/null @@ -1,37 +0,0 @@ -/** */ - -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNAccessManagerRevokeToken, - - validateParams: (modules, token) => { - const { secretKey } = modules.config; - if (!secretKey) { - return 'Missing Secret Key'; - } - - if (!token) { - return "token can't be empty"; - } - }, - - getURL: ({ config }, token) => `/v3/pam/${config.subscribeKey}/grant/${utils.encodeString(token)}`, - useDelete: () => true, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => false, - - prepareParams: ({ config }) => ({ - uuid: config.getUUID(), - }), - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/access_manager/revoke_token.ts b/src/core/endpoints/access_manager/revoke_token.ts new file mode 100644 index 000000000..da4d95578 --- /dev/null +++ b/src/core/endpoints/access_manager/revoke_token.ts @@ -0,0 +1,91 @@ +/** + * PAM Revoke Token REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../types/transport-request'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import * as PAM from '../../types/api/access-panager'; +import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = PAM.RevokeParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Request processing result data. + */ + data: Record; + + /** + * Name of the service which provided response. + */ + service: string; +}; +// endregion + +/** + * Access token revoke request. + * + * Invalidate token and permissions which has been granted for it. + */ +export class RevokeTokenRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.DELETE }); + } + + operation(): RequestOperation { + return RequestOperation.PNAccessManagerRevokeToken; + } + + validate(): string | undefined { + if (!this.parameters.keySet.secretKey) return 'Missing Secret Key'; + if (!this.parameters.token) return "token can't be empty"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return {}; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + token, + } = this.parameters; + + return `/v3/pam/${subscribeKey}/grant/${encodeString(token)}`; + } +} diff --git a/src/core/endpoints/actions/add_message_action.js b/src/core/endpoints/actions/add_message_action.js deleted file mode 100644 index e07ebb6cc..000000000 --- a/src/core/endpoints/actions/add_message_action.js +++ /dev/null @@ -1,56 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNAddMessageActionOperation; -} - -export function validateParams({ config }, incomingParams) { - const { action, channel, messageTimetoken } = incomingParams; - - if (!messageTimetoken) return 'Missing message timetoken'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; - if (!channel) return 'Missing message channel'; - if (!action) return 'Missing Action'; - if (!action.value) return 'Missing Action.value'; - if (!action.type) return 'Missing Action.type'; - if (action.type.length > 15) return 'Action.type value exceed maximum length of 15'; -} - -export function usePost() { - return true; -} - -export function postURL({ config }, incomingParams) { - const { channel, messageTimetoken } = incomingParams; - - return `/v1/message-actions/${config.subscribeKey}/channel/${utils.encodeString( - channel, - )}/message/${messageTimetoken}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function getRequestHeaders() { - return { 'Content-Type': 'application/json' }; -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams() { - return {}; -} - -export function postPayload(modules, incomingParams) { - return incomingParams.action; -} - -export function handleResponse(modules, addMessageActionResponse) { - return { data: addMessageActionResponse.data }; -} diff --git a/src/core/endpoints/actions/add_message_action.ts b/src/core/endpoints/actions/add_message_action.ts new file mode 100644 index 000000000..e14a4142a --- /dev/null +++ b/src/core/endpoints/actions/add_message_action.ts @@ -0,0 +1,105 @@ +/** + * Add Message Action REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../types/transport-request'; +import * as MessageAction from '../../types/api/message-action'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = MessageAction.AddMessageActionParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Request processing result data. + */ + data: MessageAction.MessageAction; +}; +// endregion + +/** + * Add Message Reaction request. + */ +export class AddMessageActionRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.POST }); + } + + operation(): RequestOperation { + return RequestOperation.PNAddMessageActionOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + action, + channel, + messageTimetoken, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!channel) return 'Missing message channel'; + if (!messageTimetoken) return 'Missing message timetoken'; + if (!action) return 'Missing Action'; + if (!action.value) return 'Missing Action.value'; + if (!action.type) return 'Missing Action.type'; + if (action.type.length > 15) return 'Action.type value exceed maximum length of 15'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return { data: serviceResponse.data }; + } + + protected get headers(): Record | undefined { + return { 'Content-Type': 'application/json' }; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + messageTimetoken, + } = this.parameters; + + return `/v1/message-actions/${subscribeKey}/channel/${encodeString(channel)}/message/${messageTimetoken}`; + } + + protected get body(): ArrayBuffer | string | undefined { + return JSON.stringify(this.parameters.action); + } +} diff --git a/src/core/endpoints/actions/get_message_actions.js b/src/core/endpoints/actions/get_message_actions.js deleted file mode 100644 index ebe4fbb7d..000000000 --- a/src/core/endpoints/actions/get_message_actions.js +++ /dev/null @@ -1,51 +0,0 @@ -/* */ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNGetMessageActionsOperation; -} - -export function validateParams({ config }, incomingParams) { - const { channel } = incomingParams; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; - if (!channel) return 'Missing message channel'; -} - -export function getURL({ config }, incomingParams) { - const { channel } = incomingParams; - - return `/v1/message-actions/${config.subscribeKey}/channel/${utils.encodeString(channel)}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { limit, start, end } = incomingParams; - const outgoingParams = {}; - - if (limit) outgoingParams.limit = limit; - if (start) outgoingParams.start = start; - if (end) outgoingParams.end = end; - - return outgoingParams; -} - -export function handleResponse(modules, getMessageActionsResponse) { - /** @type GetMessageActionsResponse */ - const response = { data: getMessageActionsResponse.data, start: null, end: null }; - - if (response.data.length) { - response.end = response.data[response.data.length - 1].actionTimetoken; - response.start = response.data[0].actionTimetoken; - } - - return response; -} diff --git a/src/core/endpoints/actions/get_message_actions.ts b/src/core/endpoints/actions/get_message_actions.ts new file mode 100644 index 000000000..60a729830 --- /dev/null +++ b/src/core/endpoints/actions/get_message_actions.ts @@ -0,0 +1,111 @@ +/** + * Get Message Actions REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import * as MessageAction from '../../types/api/message-action'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Query } from '../../types/api'; +import { encodeString } from '../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = MessageAction.GetMessageActionsParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Retrieved list of message actions. + */ + data: MessageAction.MessageAction[]; + + /** + * More message actions fetch information. + */ + more?: MessageAction.MoreMessageActions; +}; +// endregion + +/** + * Fetch channel message actions request. + */ +export class GetMessageActionsRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNGetMessageActionsOperation; + } + + validate(): string | undefined { + if (!this.parameters.keySet.subscribeKey) return 'Missing Subscribe Key'; + if (!this.parameters.channel) return 'Missing message channel'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + let start: string | null = null; + let end: string | null = null; + + if (serviceResponse.data.length > 0) { + start = serviceResponse.data[0].actionTimetoken; + end = serviceResponse.data[serviceResponse.data.length - 1].actionTimetoken; + } + + return { + data: serviceResponse.data, + more: serviceResponse.more, + start, + end, + }; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v1/message-actions/${subscribeKey}/channel/${encodeString(channel)}`; + } + + protected get queryParameters(): Query { + const { limit, start, end } = this.parameters; + + return { + ...(start ? { start } : {}), + ...(end ? { end } : {}), + ...(limit ? { limit } : {}), + }; + } +} diff --git a/src/core/endpoints/actions/remove_message_action.js b/src/core/endpoints/actions/remove_message_action.js deleted file mode 100644 index 479cfb2e6..000000000 --- a/src/core/endpoints/actions/remove_message_action.js +++ /dev/null @@ -1,45 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNRemoveMessageActionOperation; -} - -export function validateParams({ config }, incomingParams) { - const { channel, actionTimetoken, messageTimetoken } = incomingParams; - - if (!messageTimetoken) return 'Missing message timetoken'; - if (!actionTimetoken) return 'Missing action timetoken'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; - if (!channel) return 'Missing message channel'; -} - -export function useDelete() { - return true; -} - -export function getURL({ config }, incomingParams) { - const { channel, actionTimetoken, messageTimetoken } = incomingParams; - - return `/v1/message-actions/${config.subscribeKey}/channel/${utils.encodeString( - channel, - )}/message/${messageTimetoken}/action/${actionTimetoken}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams() { - return {}; -} - -export function handleResponse(modules, removeMessageActionResponse) { - return { data: removeMessageActionResponse.data }; -} diff --git a/src/core/endpoints/actions/remove_message_action.ts b/src/core/endpoints/actions/remove_message_action.ts new file mode 100644 index 000000000..a7b397d7c --- /dev/null +++ b/src/core/endpoints/actions/remove_message_action.ts @@ -0,0 +1,97 @@ +/** + * Remove Message Action REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../types/transport-request'; +import * as MessageAction from '../../types/api/message-action'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = MessageAction.RemoveMessageActionParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Request processing result data. + */ + data: Record; +}; +// endregion + +/** + * Remove specific message action request. + */ +export class RemoveMessageAction extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.DELETE }); + } + + operation(): RequestOperation { + return RequestOperation.PNRemoveMessageActionOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + channel, + messageTimetoken, + actionTimetoken, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!channel) return 'Missing message action channel'; + if (!messageTimetoken) return 'Missing message timetoken'; + if (!actionTimetoken) return 'Missing action timetoken'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return { data: serviceResponse.data }; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + actionTimetoken, + messageTimetoken, + } = this.parameters; + + return `/v1/message-actions/${subscribeKey}/channel/${encodeString( + channel, + )}/message/${messageTimetoken}/action/${actionTimetoken}`; + } +} diff --git a/src/core/endpoints/channel_groups/add_channels.js b/src/core/endpoints/channel_groups/add_channels.js deleted file mode 100644 index 804decdf6..000000000 --- a/src/core/endpoints/channel_groups/add_channels.js +++ /dev/null @@ -1,42 +0,0 @@ -/* */ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNAddChannelsToGroupOperation; -} - -export function validateParams(modules, incomingParams) { - const { channels, channelGroup } = incomingParams; - const { config } = modules; - - if (!channelGroup) return 'Missing Channel Group'; - if (!channels || channels.length === 0) return 'Missing Channels'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { channelGroup } = incomingParams; - const { config } = modules; - return `/v1/channel-registration/sub-key/${config.subscribeKey}/channel-group/${utils.encodeString(channelGroup)}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { channels = [] } = incomingParams; - - return { - add: channels.join(','), - }; -} - -export function handleResponse() { - return {}; -} diff --git a/src/core/endpoints/channel_groups/add_channels.ts b/src/core/endpoints/channel_groups/add_channels.ts new file mode 100644 index 000000000..326e742c9 --- /dev/null +++ b/src/core/endpoints/channel_groups/add_channels.ts @@ -0,0 +1,104 @@ +/** + * Add channel group channels REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import * as ChannelGroups from '../../types/api/channel-groups'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Query } from '../../types/api'; +import { encodeString } from '../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = ChannelGroups.ManageChannelGroupChannelsParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Channel group channels addition human-readable result. + */ + message: string; + + /** + * Name of the service which provided response. + */ + service: string; + + /** + * Whether response represent service error or not. + */ + error: boolean; +}; +// endregion + +/** + * Add channel group channels request. + */ +export class AddChannelGroupChannelsRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNAddChannelsToGroupOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + channels, + channelGroup, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!channelGroup) return 'Missing Channel Group'; + if (!channels) return 'Missing channels'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return {}; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channelGroup, + } = this.parameters; + + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${encodeString(channelGroup)}`; + } + + protected get queryParameters(): Query { + return { add: this.parameters.channels.join(',') }; + } +} diff --git a/src/core/endpoints/channel_groups/delete_group.js b/src/core/endpoints/channel_groups/delete_group.js deleted file mode 100644 index 1dff624d6..000000000 --- a/src/core/endpoints/channel_groups/delete_group.js +++ /dev/null @@ -1,40 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNRemoveGroupOperation; -} - -export function validateParams(modules, incomingParams) { - const { channelGroup } = incomingParams; - const { config } = modules; - - if (!channelGroup) return 'Missing Channel Group'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { channelGroup } = incomingParams; - const { config } = modules; - return `/v1/channel-registration/sub-key/${config.subscribeKey}/channel-group/${utils.encodeString( - channelGroup, - )}/remove`; -} - -export function isAuthSupported() { - return true; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function prepareParams() { - return {}; -} - -export function handleResponse() { - return {}; -} diff --git a/src/core/endpoints/channel_groups/delete_group.ts b/src/core/endpoints/channel_groups/delete_group.ts new file mode 100644 index 000000000..e06a68c28 --- /dev/null +++ b/src/core/endpoints/channel_groups/delete_group.ts @@ -0,0 +1,93 @@ +/** + * Delete channel group REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import * as ChannelGroups from '../../types/api/channel-groups'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet } from '../../types/api'; +import { encodeString } from '../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = ChannelGroups.DeleteChannelGroupParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Delete channel group human-readable result. + */ + message: string; + + /** + * Name of the service which provided response. + */ + service: string; + + /** + * Whether response represent service error or not. + */ + error: boolean; +}; +// endregion + +/** + * Channel group delete request. + */ +export class DeleteChannelGroupRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNRemoveGroupOperation; + } + + validate(): string | undefined { + if (!this.parameters.keySet.subscribeKey) return 'Missing Subscribe Key'; + if (!this.parameters.channelGroup) return 'Missing Channel Group'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return {}; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channelGroup, + } = this.parameters; + + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${encodeString(channelGroup)}/remove`; + } +} diff --git a/src/core/endpoints/channel_groups/list_channels.js b/src/core/endpoints/channel_groups/list_channels.js deleted file mode 100644 index 245857d5e..000000000 --- a/src/core/endpoints/channel_groups/list_channels.js +++ /dev/null @@ -1,39 +0,0 @@ -/* */ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNChannelsForGroupOperation; -} - -export function validateParams(modules, incomingParams) { - const { channelGroup } = incomingParams; - const { config } = modules; - - if (!channelGroup) return 'Missing Channel Group'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { channelGroup } = incomingParams; - const { config } = modules; - return `/v1/channel-registration/sub-key/${config.subscribeKey}/channel-group/${utils.encodeString(channelGroup)}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams() { - return {}; -} - -export function handleResponse(modules, serverResponse) { - return { - channels: serverResponse.payload.channels, - }; -} diff --git a/src/core/endpoints/channel_groups/list_channels.ts b/src/core/endpoints/channel_groups/list_channels.ts new file mode 100644 index 000000000..d5bf3b8fa --- /dev/null +++ b/src/core/endpoints/channel_groups/list_channels.ts @@ -0,0 +1,108 @@ +/** + * List channel group channels REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import * as ChannelGroups from '../../types/api/channel-groups'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = ChannelGroups.ListChannelGroupChannelsParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * List channel group channels human-readable result. + */ + message: string; + + /** + * Name of the service which provided response. + */ + service: string; + + /** + * Whether response represent service error or not. + */ + error: boolean; + + /** + * Retrieved registered channels information. + */ + payload: { + /** + * Channel group for which channels has been received. + */ + group: string; + + /** + * List of channels registered in channel {@link group}. + */ + channels: string[]; + }; +}; +// endregion + +/** + * List Channel Group Channels request. + */ +export class ListChannelGroupChannels extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNChannelsForGroupOperation; + } + + validate(): string | undefined { + if (!this.parameters.keySet.subscribeKey) return 'Missing Subscribe Key'; + if (!this.parameters.channelGroup) return 'Missing Channel Group'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return { channels: serviceResponse.payload.channels }; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channelGroup, + } = this.parameters; + + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${encodeString(channelGroup)}`; + } +} diff --git a/src/core/endpoints/channel_groups/list_groups.js b/src/core/endpoints/channel_groups/list_groups.js deleted file mode 100644 index 8642f397f..000000000 --- a/src/core/endpoints/channel_groups/list_groups.js +++ /dev/null @@ -1,36 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; - -export function getOperation() { - return operationConstants.PNChannelGroupsOperation; -} - -export function validateParams(modules) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules) { - const { config } = modules; - return `/v1/channel-registration/sub-key/${config.subscribeKey}/channel-group`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams() { - return {}; -} - -export function handleResponse(modules, serverResponse) { - return { - groups: serverResponse.payload.groups, - }; -} diff --git a/src/core/endpoints/channel_groups/list_groups.ts b/src/core/endpoints/channel_groups/list_groups.ts new file mode 100644 index 000000000..2d4ef4a02 --- /dev/null +++ b/src/core/endpoints/channel_groups/list_groups.ts @@ -0,0 +1,101 @@ +/** + * List All Channel Groups REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import * as ChannelGroups from '../../types/api/channel-groups'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * List all channel groups human-readable result. + */ + message: string; + + /** + * Name of the service which provided response. + */ + service: string; + + /** + * Whether response represent service error or not. + */ + error: boolean; + + /** + * Retrieved registered channels information. + */ + payload: { + /** + * Subscription key for which list of channel groups has been received. + */ + sub_key: string; + + /** + * List of channel groups created for {@link sub_key}. + */ + groups: string[]; + }; +}; +// endregion + +/** + * List all channel groups request. + */ +export class ListChannelGroupsRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNChannelGroupsOperation; + } + + validate(): string | undefined { + if (!this.parameters.keySet.subscribeKey) return 'Missing Subscribe Key'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return { groups: serviceResponse.payload.groups }; + } + + protected get path(): string { + return `/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`; + } +} diff --git a/src/core/endpoints/channel_groups/remove_channels.js b/src/core/endpoints/channel_groups/remove_channels.js deleted file mode 100644 index 54c664f55..000000000 --- a/src/core/endpoints/channel_groups/remove_channels.js +++ /dev/null @@ -1,42 +0,0 @@ -/* */ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNRemoveChannelsFromGroupOperation; -} - -export function validateParams(modules, incomingParams) { - const { channels, channelGroup } = incomingParams; - const { config } = modules; - - if (!channelGroup) return 'Missing Channel Group'; - if (!channels || channels.length === 0) return 'Missing Channels'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { channelGroup } = incomingParams; - const { config } = modules; - return `/v1/channel-registration/sub-key/${config.subscribeKey}/channel-group/${utils.encodeString(channelGroup)}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { channels = [] } = incomingParams; - - return { - remove: channels.join(','), - }; -} - -export function handleResponse() { - return {}; -} diff --git a/src/core/endpoints/channel_groups/remove_channels.ts b/src/core/endpoints/channel_groups/remove_channels.ts new file mode 100644 index 000000000..0301d36e5 --- /dev/null +++ b/src/core/endpoints/channel_groups/remove_channels.ts @@ -0,0 +1,107 @@ +/** + * Remove channel group channels REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import * as ChannelGroups from '../../types/api/channel-groups'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Query } from '../../types/api'; +import { encodeString } from '../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = ChannelGroups.ManageChannelGroupChannelsParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Channel group channels manage human-readable result. + */ + message: string; + + /** + * Name of the service which provided response. + */ + service: string; + + /** + * Whether response represent service error or not. + */ + error: boolean; +}; +// endregion + +/** + * Remove channel group channels request. + */ +// prettier-ignore +export class RemoveChannelGroupChannelsRequest extends AbstractRequest< + ChannelGroups.ManageChannelGroupChannelsResponse +> { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNRemoveChannelsFromGroupOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + channels, + channelGroup, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!channelGroup) return 'Missing Channel Group'; + if (!channels) return 'Missing channels'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return {}; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channelGroup, + } = this.parameters; + + return `/v1/channel-registration/sub-key/${subscribeKey}/channel-group/${encodeString(channelGroup)}`; + } + + protected get queryParameters(): Query { + return { remove: this.parameters.channels.join(',') }; + } +} diff --git a/src/core/endpoints/endpoint.js b/src/core/endpoints/endpoint.js deleted file mode 100644 index cead0ebfb..000000000 --- a/src/core/endpoints/endpoint.js +++ /dev/null @@ -1,3 +0,0 @@ -/** */ - -// endpoint definition structure diff --git a/src/core/endpoints/fetch_messages.js b/src/core/endpoints/fetch_messages.js deleted file mode 100644 index bb4c0d3be..000000000 --- a/src/core/endpoints/fetch_messages.js +++ /dev/null @@ -1,127 +0,0 @@ -/* */ -import operationConstants from '../constants/operations'; -import utils from '../utils'; - -function __processMessage(modules, message) { - const result = {}; - if (!modules.cryptoModule) { - result.payload = message; - return result; - } - try { - const decryptedData = modules.cryptoModule.decrypt(message); - const decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decryptedData)) : decryptedData; - result.payload = decryptedPayload; - return result; - } catch (e) { - if (modules.config.logVerbosity && console && console.log) console.log('decryption error', e.message); - result.payload = message; - result.error = `Error while decrypting message content: ${e.message}`; - } - return result; -} - -export function getOperation() { - return operationConstants.PNFetchMessagesOperation; -} - -export function validateParams(modules, incomingParams) { - const { channels, includeMessageActions = false } = incomingParams; - const { config } = modules; - - if (!channels || channels.length === 0) return 'Missing channels'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; - - if (includeMessageActions && channels.length > 1) { - throw new TypeError( - 'History can return actions data for a single channel only. ' + - 'Either pass a single channel or disable the includeMessageActions flag.', - ); - } -} - -export function getURL(modules, incomingParams) { - const { channels = [], includeMessageActions = false } = incomingParams; - const { config } = modules; - const endpoint = !includeMessageActions ? 'history' : 'history-with-actions'; - - const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return `/v3/${endpoint}/sub-key/${config.subscribeKey}/channel/${utils.encodeString(stringifiedChannels)}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { - channels, - start, - end, - includeMessageActions, - count, - stringifiedTimeToken = false, - includeMeta = false, - includeUuid, - includeUUID = true, - includeMessageType = true, - } = incomingParams; - const outgoingParams = {}; - - if (count) { - outgoingParams.max = count; - } else { - outgoingParams.max = channels.length > 1 || includeMessageActions === true ? 25 : 100; - } - if (start) outgoingParams.start = start; - if (end) outgoingParams.end = end; - if (stringifiedTimeToken) outgoingParams.string_message_token = 'true'; - if (includeMeta) outgoingParams.include_meta = 'true'; - if (includeUUID && includeUuid !== false) outgoingParams.include_uuid = 'true'; - if (includeMessageType) outgoingParams.include_message_type = 'true'; - - return outgoingParams; -} - -export function handleResponse(modules, serverResponse) { - const response = { - channels: {}, - }; - - Object.keys(serverResponse.channels || {}).forEach((channelName) => { - response.channels[channelName] = []; - - (serverResponse.channels[channelName] || []).forEach((messageEnvelope) => { - const announce = {}; - const processedMessgeResult = __processMessage(modules, messageEnvelope.message); - announce.channel = channelName; - announce.timetoken = messageEnvelope.timetoken; - announce.message = processedMessgeResult.payload; - announce.messageType = messageEnvelope.message_type; - announce.uuid = messageEnvelope.uuid; - - if (messageEnvelope.actions) { - announce.actions = messageEnvelope.actions; - - // This should be kept for few updates for existing clients consistency. - announce.data = messageEnvelope.actions; - } - if (messageEnvelope.meta) { - announce.meta = messageEnvelope.meta; - } - if (processedMessgeResult.error) announce.error = processedMessgeResult.error; - - response.channels[channelName].push(announce); - }); - }); - if (serverResponse.more) { - response.more = serverResponse.more; - } - - return response; -} diff --git a/src/core/endpoints/fetch_messages.ts b/src/core/endpoints/fetch_messages.ts new file mode 100644 index 000000000..cb5927495 --- /dev/null +++ b/src/core/endpoints/fetch_messages.ts @@ -0,0 +1,347 @@ +/** + * Fetch messages REST API module. + */ + +import { createValidationError, PubNubError } from '../../errors/pubnub-error'; +import { TransportResponse } from '../types/transport-response'; +import { PubNubAPIError } from '../../errors/pubnub-api-error'; +import { CryptoModule } from '../interfaces/crypto-module'; +import { AbstractRequest } from '../components/request'; +import * as FileSharing from '../types/api/file-sharing'; +import RequestOperation from '../constants/operations'; +import { KeySet, Payload, Query } from '../types/api'; +import * as History from '../types/api/history'; +import { encodeNames } from '../utils'; + +// -------------------------------------------------------- +// ---------------------- Defaults ------------------------ +// -------------------------------------------------------- +// region Defaults + +/** + * Whether verbose logging enabled or not. + */ +const LOG_VERBOSITY = false; + +/** + * Whether message type should be returned or not. + */ +const INCLUDE_MESSAGE_TYPE = true; + +/** + * Whether timetokens should be returned as strings by default or not. + */ +const STRINGIFY_TIMETOKENS = false; + +/** + * Whether message publisher `uuid` should be returned or not. + */ +const INCLUDE_UUID = true; + +/** + * Default number of messages which can be returned for single channel, and it is maximum as well. + */ +const SINGLE_CHANNEL_MESSAGES_COUNT = 100; + +/** + * Default number of messages which can be returned for multiple channels or when fetched + * message actions. + */ +const MULTIPLE_CHANNELS_MESSAGES_COUNT = 25; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = History.FetchMessagesParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; + + /** + * Published data encryption module. + */ + crypto?: CryptoModule; + + /** + * File download Url generation function. + * + * @param parameters - File download Url request configuration parameters. + * + * @returns File download Url. + */ + getFileUrl: (parameters: FileSharing.FileUrlParameters) => string; + + /** + * Whether verbose logging enabled or not. + * + * @default `false` + */ + logVerbosity?: boolean; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Whether service response represent error or not. + */ + error: boolean; + + /** + * Human-readable error explanation. + */ + error_message: string; + + /** + * List of previously published messages per requested channel. + */ + channels: { + [p: string]: { + /** + * Message payload (decrypted). + */ + message: History.FetchedMessage['message']; + + /** + * When message has been received by PubNub service. + */ + timetoken: string; + + /** + * Message publisher unique identifier. + */ + uuid?: string; + + /** + * PubNub-defined message type. + */ + message_type?: History.PubNubMessageType | null; + + /** + * Additional data which has been published along with message to be used with real-time + * events filter expression. + */ + meta?: Payload; + + /** + * List of message reactions. + */ + actions?: History.Actions; + + /** + * Custom published data type (user-provided). + */ + type?: string; + + /** + * Space in which message has been received. + */ + space_id?: string; + }[]; + }; + + /** + * Additional message actions fetch information. + */ + more?: History.MoreActions; +}; +// endregion + +/** + * Fetch messages from channels request. + */ +export class FetchMessagesRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply defaults. + const includeMessageActions = parameters.includeMessageActions ?? false; + const defaultCount = + parameters.channels.length > 1 || includeMessageActions + ? MULTIPLE_CHANNELS_MESSAGES_COUNT + : SINGLE_CHANNEL_MESSAGES_COUNT; + if (!parameters.count) parameters.count = defaultCount; + else parameters.count = Math.min(parameters.count, defaultCount); + + if (parameters.includeUuid) parameters.includeUUID = parameters.includeUuid; + else parameters.includeUUID ??= INCLUDE_UUID; + parameters.stringifiedTimeToken ??= STRINGIFY_TIMETOKENS; + parameters.includeMessageType ??= INCLUDE_MESSAGE_TYPE; + parameters.logVerbosity ??= LOG_VERBOSITY; + } + + operation(): RequestOperation { + return RequestOperation.PNFetchMessagesOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + channels, + includeMessageActions, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!channels) return 'Missing channels'; + if (includeMessageActions !== undefined && includeMessageActions && channels.length > 1) + return ( + 'History can return actions data for a single channel only. Either pass a single channel ' + + 'or disable the includeMessageActions flag.' + ); + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + const responseChannels = serviceResponse.channels ?? {}; + const channels: History.FetchMessagesResponse['channels'] = {}; + + Object.keys(responseChannels).forEach((channel) => { + // Map service response to expected data object type structure. + channels[channel] = responseChannels[channel].map((payload) => { + // `null` message type means regular message. + if (payload.message_type === null) payload.message_type = History.PubNubMessageType.Message; + const processedPayload = this.processPayload(channel, payload); + + const item = { + channel, + timetoken: payload.timetoken, + message: processedPayload.payload, + messageType: payload.message_type, + uuid: payload.uuid, + }; + + if (payload.actions) { + const itemWithActions = item as unknown as History.FetchedMessageWithActions; + itemWithActions.actions = payload.actions; + + // Backward compatibility for existing users. + // TODO: Remove in next release. + itemWithActions.data = payload.actions; + } + + if (payload.meta) (item as History.FetchedMessage).meta = payload.meta; + if (processedPayload.error) (item as History.FetchedMessage).error = processedPayload.error; + + return item as History.FetchedMessage; + }); + }); + + if (serviceResponse.more) + return { channels, more: serviceResponse.more } as History.FetchMessagesWithActionsResponse; + + return { channels } as History.FetchMessagesResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channels, + includeMessageActions, + } = this.parameters; + const endpoint = !includeMessageActions! ? 'history' : 'history-with-actions'; + + return `/v3/${endpoint}/sub-key/${subscribeKey}/channel/${encodeNames(channels)}`; + } + + protected get queryParameters(): Query { + const { start, end, count, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken } = this.parameters; + + return { + max: count!, + ...(start ? { start } : {}), + ...(end ? { end } : {}), + ...(stringifiedTimeToken! ? { string_message_token: 'true' } : {}), + ...(includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {}), + ...(includeUUID! ? { include_uuid: 'true' } : {}), + ...(includeMessageType! ? { include_message_type: 'true' } : {}), + }; + } + + /** + * Parse single channel data entry. + * + * @param channel - Channel for which {@link payload} should be processed. + * @param payload - Source payload which should be processed and parsed to expected type. + * + * @returns + */ + private processPayload( + channel: string, + payload: ServiceResponse['channels'][string][number], + ): { + payload: History.FetchedMessage['message']; + error?: string; + } { + const { crypto, logVerbosity } = this.parameters; + if (!crypto || typeof payload.message !== 'string') return { payload: payload.message }; + + let decryptedPayload: History.FetchedMessage['message']; + let error: string | undefined; + + try { + const decryptedData = crypto.decrypt(payload.message); + decryptedPayload = + decryptedData instanceof ArrayBuffer + ? JSON.parse(FetchMessagesRequest.decoder.decode(decryptedData)) + : decryptedData; + } catch (err) { + if (logVerbosity!) console.log(`decryption error`, (err as Error).message); + decryptedPayload = payload.message; + error = `Error while decrypting message content: ${(err as Error).message}`; + } + + if ( + !error && + decryptedPayload && + payload.message_type == History.PubNubMessageType.Files && + typeof decryptedPayload === 'object' && + this.isFileMessage(decryptedPayload) + ) { + const fileMessage = decryptedPayload; + return { + payload: { + message: fileMessage.message, + file: { + ...fileMessage.file, + url: this.parameters.getFileUrl({ channel, id: fileMessage.file.id, name: fileMessage.file.name }), + }, + }, + error, + }; + } + + return { payload: decryptedPayload, error }; + } + + /** + * Check whether `payload` potentially represents file message. + * + * @param payload - Fetched message payload. + * + * @returns `true` if payload can be {@link History#FileMessage|FileMessage}. + */ + private isFileMessage(payload: History.FetchedMessage['message']): payload is History.FileMessage['message'] { + return (payload as History.FileMessage['message']).file !== undefined; + } +} diff --git a/src/core/endpoints/file_upload/delete_file.js b/src/core/endpoints/file_upload/delete_file.js deleted file mode 100644 index 3d3d8f88a..000000000 --- a/src/core/endpoints/file_upload/delete_file.js +++ /dev/null @@ -1,39 +0,0 @@ -/** */ - -import operationConstants from '../../constants/operations'; - -import utils from '../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNListFilesOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return "channel can't be empty"; - } - - if (!params?.id) { - return "file id can't be empty"; - } - - if (!params?.name) { - return "file name can't be empty"; - } - }, - - useDelete: () => true, - getURL: ({ config }, params) => - `/v1/files/${config.subscribeKey}/channels/${utils.encodeString(params.channel)}/files/${params.id}/${params.name}`, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: () => ({}), - - handleResponse: (_, response) => ({ - status: response.status, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/file_upload/delete_file.ts b/src/core/endpoints/file_upload/delete_file.ts new file mode 100644 index 000000000..7ccacb914 --- /dev/null +++ b/src/core/endpoints/file_upload/delete_file.ts @@ -0,0 +1,84 @@ +/** + * Delete file REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../types/transport-request'; +import { AbstractRequest } from '../../components/request'; +import * as FileSharing from '../../types/api/file-sharing'; +import RequestOperation from '../../constants/operations'; +import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = FileSharing.DeleteFileParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request processing result status code. + */ + status: number; +}; +// endregion + +/** + * Delete File request. + */ +export class DeleteFileRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.DELETE }); + } + + operation(): RequestOperation { + return RequestOperation.PNDeleteFileOperation; + } + + validate(): string | undefined { + const { channel, id, name } = this.parameters; + + if (!channel) return "channel can't be empty"; + if (!id) return "file id can't be empty"; + if (!name) return "file name can't be empty"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + id, + channel, + name, + } = this.parameters; + + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files/${id}/${name}`; + } +} diff --git a/src/core/endpoints/file_upload/download_file.js b/src/core/endpoints/file_upload/download_file.js deleted file mode 100644 index 3668f6336..000000000 --- a/src/core/endpoints/file_upload/download_file.js +++ /dev/null @@ -1,56 +0,0 @@ -// Download_file.js - -/** */ - -import operationConstants from '../../constants/operations'; - -import utils from '../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNDownloadFileOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return "channel can't be empty"; - } - - if (!params?.name) { - return "name can't be empty"; - } - - if (!params?.id) { - return "id can't be empty"; - } - }, - - useGetFile: () => true, - - getFileURL: ({ config }, params) => - `/v1/files/${config.subscribeKey}/channels/${utils.encodeString(params.channel)}/files/${params.id}/${params.name}`, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - ignoreBody: () => true, - forceBuffered: () => true, - - prepareParams: () => ({}), - - handleResponse: async ({ PubNubFile, config, cryptography, cryptoModule }, res, params) => { - let { body } = res.response; - if (PubNubFile.supportsEncryptFile && (params.cipherKey || cryptoModule)) { - body = - params.cipherKey == null - ? (await cryptoModule.decryptFile(PubNubFile.create({ data: body, name: params.name }), PubNubFile)).data - : await cryptography.decrypt(params.cipherKey ?? config.cipherKey, body); - } - - return PubNubFile.create({ - data: body, - name: res.response.name ?? params.name, - mimeType: res.response.type, - }); - }, -}; - -export default endpoint; diff --git a/src/core/endpoints/file_upload/download_file.ts b/src/core/endpoints/file_upload/download_file.ts new file mode 100644 index 000000000..6f91ec76a --- /dev/null +++ b/src/core/endpoints/file_upload/download_file.ts @@ -0,0 +1,101 @@ +/** + * Download File REST API module. + */ + +import { PubNubBasicFileParameters, PubNubFileConstructor, PubNubFileInterface } from '../../types/file'; +import { TransportResponse } from '../../types/transport-response'; +import { CryptoModule } from '../../interfaces/crypto-module'; +import { Cryptography } from '../../interfaces/cryptography'; +import { AbstractRequest } from '../../components/request'; +import * as FileSharing from '../../types/api/file-sharing'; +import RequestOperation from '../../constants/operations'; +import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = FileSharing.DownloadFileParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; + + /** + * File object constructor. + */ + PubNubFile: PubNubFileConstructor; + + /** + * Send file decryption module. + */ + crypto?: CryptoModule; + + /** + * Legacy cryptography module. + */ + cryptography?: Cryptography; +}; +// endregion + +/** + * Download File request. + */ +export class DownloadFileRequest< + PlatformFile extends Partial = Record, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNDownloadFileOperation; + } + + validate(): string | undefined { + const { channel, id, name } = this.parameters; + + if (!channel) return "channel can't be empty"; + if (!id) return "file id can't be empty"; + if (!name) return "file name can't be empty"; + } + + async parse(response: TransportResponse): Promise { + const { cipherKey, crypto, cryptography, name, PubNubFile } = this.parameters; + const mimeType = response.headers['content-type']; + let decryptedFile: PubNubFileInterface | undefined; + let body = response.body!; + + if (PubNubFile.supportsEncryptFile && (cipherKey || crypto)) { + if (cipherKey && cryptography) body = await cryptography.decrypt(cipherKey, body); + else if (!cipherKey && crypto) + decryptedFile = await crypto.decryptFile(PubNubFile.create({ data: body, name: name, mimeType }), PubNubFile); + } + + return ( + decryptedFile + ? decryptedFile + : PubNubFile.create({ + data: body, + name, + mimeType, + }) + ) as PlatformFile; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + id, + name, + } = this.parameters; + + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files/${id}/${name}`; + } +} diff --git a/src/core/endpoints/file_upload/generate_upload_url.js b/src/core/endpoints/file_upload/generate_upload_url.js deleted file mode 100644 index cb7861978..000000000 --- a/src/core/endpoints/file_upload/generate_upload_url.js +++ /dev/null @@ -1,41 +0,0 @@ -/** */ - -import operationConstants from '../../constants/operations'; - -import utils from '../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNGenerateUploadUrlOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return "channel can't be empty"; - } - - if (!params?.name) { - return "name can't be empty"; - } - }, - - usePost: () => true, - postURL: ({ config }, params) => - `/v1/files/${config.subscribeKey}/channels/${utils.encodeString(params.channel)}/generate-upload-url`, - - postPayload: (_, params) => ({ - name: params.name, - }), - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: () => ({}), - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - file_upload_request: response.file_upload_request, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/file_upload/generate_upload_url.ts b/src/core/endpoints/file_upload/generate_upload_url.ts new file mode 100644 index 000000000..8f1b43b1c --- /dev/null +++ b/src/core/endpoints/file_upload/generate_upload_url.ts @@ -0,0 +1,148 @@ +/** + * Generate file upload URL REST API request. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../types/transport-request'; +import { AbstractRequest } from '../../components/request'; +import * as FileSharing from '../../types/api/file-sharing'; +import RequestOperation from '../../constants/operations'; +import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = FileSharing.GenerateFileUploadUrlParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * File upload URL generation result status code. + */ + status: number; + + /** + * PubNub Service response. + */ + data: { + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; + }; + + /** + * PubNub service response extension. + */ + file_upload_request: { + /** + * Pre-signed URL for file upload. + */ + url: string; + + /** + * HTTP method which should be used for file upload. + */ + method: string; + + /** + * Expiration date (ISO 8601 format) for the pre-signed upload request. + */ + expiration_date: string; + + /** + * An array of form fields to be used in the pre-signed POST request. + * + * **Important:** Form data fields should be passed in exact same order as received from + * the PubNub service. + */ + form_fields: { + /** + * Form data field name. + */ + name: string; + /** + * Form data field value. + */ + value: string; + }[]; + }; +}; +// endregion + +/** + * Generate File Upload Url request. + */ +export class GenerateFileUploadUrlRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.POST }); + } + + operation(): RequestOperation { + return RequestOperation.PNGenerateUploadUrlOperation; + } + + validate(): string | undefined { + if (!this.parameters.channel) return "channel can't be empty"; + if (!this.parameters.name) return "'name' can't be empty"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return { + id: serviceResponse.data.id, + name: serviceResponse.data.name, + url: serviceResponse.file_upload_request.url, + formFields: serviceResponse.file_upload_request.form_fields, + }; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/generate-upload-url`; + } + + protected get body(): ArrayBuffer | string | undefined { + return JSON.stringify({ name: this.parameters.name }); + } +} diff --git a/src/core/endpoints/file_upload/get_file_url.js b/src/core/endpoints/file_upload/get_file_url.js deleted file mode 100644 index 01169563b..000000000 --- a/src/core/endpoints/file_upload/get_file_url.js +++ /dev/null @@ -1,63 +0,0 @@ -/** */ - -import { PubNubError, createValidationError, signRequest, generatePNSDK } from '../../components/endpoint'; - -import utils from '../../utils'; - -export default (modules, { channel, id, name }) => { - const { config, networking, tokenManager } = modules; - - if (!channel) { - throw new PubNubError( - 'Validation failed, check status for details', - createValidationError("channel can't be empty"), - ); - } - - if (!id) { - throw new PubNubError( - 'Validation failed, check status for details', - createValidationError("file id can't be empty"), - ); - } - - if (!name) { - throw new PubNubError( - 'Validation failed, check status for details', - createValidationError("file name can't be empty"), - ); - } - - const url = `/v1/files/${config.subscribeKey}/channels/${utils.encodeString(channel)}/files/${id}/${name}`; - const params = {}; - - params.uuid = config.getUUID(); - params.pnsdk = generatePNSDK(config); - - const tokenOrKey = tokenManager.getToken() || config.getAuthKey(); - if (tokenOrKey) { - params.auth = tokenOrKey; - } - - if (config.secretKey) { - signRequest( - modules, - url, - params, - {}, - { - getOperation: () => 'PubNubGetFileUrlOperation', - }, - ); - } - - const queryParams = Object.keys(params) - .map((key) => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`) - .join('&'); - - if (queryParams !== '') { - return `${networking.getStandardOrigin()}${url}?${queryParams}`; - } - - return `${networking.getStandardOrigin()}${url}`; -}; diff --git a/src/core/endpoints/file_upload/get_file_url.ts b/src/core/endpoints/file_upload/get_file_url.ts new file mode 100644 index 000000000..300ed96d6 --- /dev/null +++ b/src/core/endpoints/file_upload/get_file_url.ts @@ -0,0 +1,70 @@ +/** + * File sharing REST API module. + */ + +import { TransportResponse } from '../../types/transport-response'; +import { TransportMethod } from '../../types/transport-request'; +import { AbstractRequest } from '../../components/request'; +import * as FileSharing from '../../types/api/file-sharing'; +import RequestOperation from '../../constants/operations'; +import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = FileSharing.FileUrlParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * File download Url generation request. + * + * Local request which generates Url to download shared file from the specific channel. + */ +export class GetFileDownloadUrlRequest extends AbstractRequest { + /** + * Construct file download Url generation request. + * + * @param parameters - Request configuration. + */ + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.LOCAL }); + } + + operation(): RequestOperation { + return RequestOperation.PNGetFileUrlOperation; + } + + validate(): string | undefined { + const { channel, id, name } = this.parameters; + + if (!channel) return "channel can't be empty"; + if (!id) return "file id can't be empty"; + if (!name) return "file name can't be empty"; + } + + async parse(response: TransportResponse): Promise { + return response.url; + } + + protected get path(): string { + const { + channel, + id, + name, + keySet: { subscribeKey }, + } = this.parameters; + + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files/${id}/${name}`; + } +} diff --git a/src/core/endpoints/file_upload/list_files.js b/src/core/endpoints/file_upload/list_files.js deleted file mode 100644 index 5a04502c6..000000000 --- a/src/core/endpoints/file_upload/list_files.js +++ /dev/null @@ -1,45 +0,0 @@ -/** */ - -import operationConstants from '../../constants/operations'; - -import utils from '../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNListFilesOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return "channel can't be empty"; - } - }, - - getURL: ({ config }, params) => - `/v1/files/${config.subscribeKey}/channels/${utils.encodeString(params.channel)}/files`, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_, params) => { - const outParams = {}; - - if (params.limit) { - outParams.limit = params.limit; - } - - if (params.next) { - outParams.next = params.next; - } - - return outParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - next: response.next, - count: response.count, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/file_upload/list_files.ts b/src/core/endpoints/file_upload/list_files.ts new file mode 100644 index 000000000..0d1f95304 --- /dev/null +++ b/src/core/endpoints/file_upload/list_files.ts @@ -0,0 +1,112 @@ +/** + * List Files REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import * as FileSharing from '../../types/api/file-sharing'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Query } from '../../types/api'; +import { encodeString } from '../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Number of files to return in response. + */ +const LIMIT = 100; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = FileSharing.ListFilesParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request processing result status code. + */ + status: number; + + /** + * List of shared files for specified channel. + */ + data: FileSharing.SharedFile[]; + + /** + * Next files list page token. + */ + next: string; + + /** + * Number of returned files. + */ + count: number; +}; +// endregion + +/** + * Files List request. + */ +export class FilesListRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply default request parameters. + this.parameters.limit ??= LIMIT; + } + + operation(): RequestOperation { + return RequestOperation.PNListFilesOperation; + } + + validate(): string | undefined { + if (!this.parameters.channel) return "channel can't be empty"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files`; + } + + protected get queryParameters(): Query { + const { limit, next } = this.parameters; + + return { limit: limit!, ...(next ? { next } : {}) }; + } +} diff --git a/src/core/endpoints/file_upload/publish_file.js b/src/core/endpoints/file_upload/publish_file.js deleted file mode 100644 index 3a111935f..000000000 --- a/src/core/endpoints/file_upload/publish_file.js +++ /dev/null @@ -1,79 +0,0 @@ -/** */ - -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; -import { encode } from '../../components/base64_codec'; - -const preparePayload = (modules, payload) => { - let stringifiedPayload = JSON.stringify(payload); - if (modules.cryptoModule) { - const encrypted = modules.cryptoModule.encrypt(stringifiedPayload); - stringifiedPayload = typeof encrypted === 'string' ? encrypted : encode(encrypted); - stringifiedPayload = JSON.stringify(stringifiedPayload); - } - return stringifiedPayload || ''; -}; - -const endpoint = { - getOperation: () => operationConstants.PNPublishFileOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return "channel can't be empty"; - } - - if (!params?.fileId) { - return "file id can't be empty"; - } - - if (!params?.fileName) { - return "file name can't be empty"; - } - }, - - getURL: (modules, params) => { - const { publishKey, subscribeKey } = modules.config; - - const message = { - message: params.message, - file: { - name: params.fileName, - id: params.fileId, - }, - }; - - const payload = preparePayload(modules, message); - - return `/v1/files/publish-file/${publishKey}/${subscribeKey}/0/${utils.encodeString( - params.channel, - )}/0/${utils.encodeString(payload)}`; - }, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_, params) => { - const outParams = {}; - - if (params.ttl) { - outParams.ttl = params.ttl; - } - - if (params.storeInHistory !== undefined) { - outParams.store = params.storeInHistory ? '1' : '0'; - } - - if (params.meta && typeof params.meta === 'object') { - outParams.meta = JSON.stringify(params.meta); - } - - return outParams; - }, - - handleResponse: (_, response) => ({ - timetoken: response['2'], - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/file_upload/publish_file.ts b/src/core/endpoints/file_upload/publish_file.ts new file mode 100644 index 000000000..a88fd5682 --- /dev/null +++ b/src/core/endpoints/file_upload/publish_file.ts @@ -0,0 +1,134 @@ +/** + * Publish File Message REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { CryptoModule } from '../../interfaces/crypto-module'; +import { AbstractRequest } from '../../components/request'; +import * as FileSharing from '../../types/api/file-sharing'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Payload, Query } from '../../types/api'; +import { encode } from '../../components/base64_codec'; +import { encodeString } from '../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether published file messages should be stored in the channel's history. + */ +const STORE_IN_HISTORY = true; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = FileSharing.PublishFileMessageParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; + + /** + * Published data encryption module. + */ + crypto?: CryptoModule; +}; + +/** + * Service success response. + */ +type ServiceResponse = [0 | 1, string, string]; +// endregion + +export class PublishFileMessageRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply default request parameters. + this.parameters.storeInHistory ??= STORE_IN_HISTORY; + } + + operation(): RequestOperation { + return RequestOperation.PNPublishFileMessageOperation; + } + + validate(): string | undefined { + const { channel, fileId, fileName } = this.parameters; + + if (!channel) return "channel can't be empty"; + if (!fileId) return "file id can't be empty"; + if (!fileName) return "file name can't be empty"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + + return { timetoken: serviceResponse[2] }; + } + + protected get path(): string { + const { + message, + channel, + keySet: { publishKey, subscribeKey }, + fileId, + fileName, + } = this.parameters; + + const fileMessage = { + file: { + name: fileName, + id: fileId, + }, + ...(message ? { message } : {}), + }; + + return `/v1/files/publish-file/${publishKey}/${subscribeKey}/0/${encodeString(channel)}/0/${encodeString( + this.prepareMessagePayload(fileMessage), + )}`; + } + + protected get queryParameters(): Query { + const { storeInHistory, ttl, meta } = this.parameters; + return { + store: storeInHistory! ? '1' : '0', + ...(ttl ? { ttl } : {}), + ...(meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {}), + }; + } + + /** + * Pre-process provided data. + * + * Data will be "normalized" and encrypted if `cryptoModule` has been provided. + * + * @param payload - User-provided data which should be pre-processed before use. + * + * @returns Payload which can be used as part of request URL or body. + * + * @throws {Error} in case if provided `payload` or results of `encryption` can't be stringified. + */ + private prepareMessagePayload(payload: Payload): string { + const { crypto } = this.parameters; + if (!crypto) return JSON.stringify(payload) || ''; + + const encrypted = crypto.encrypt(JSON.stringify(payload)); + + return JSON.stringify(typeof encrypted === 'string' ? encrypted : encode(encrypted)); + } +} diff --git a/src/core/endpoints/file_upload/send_file.js b/src/core/endpoints/file_upload/send_file.js deleted file mode 100644 index f2d2fb810..000000000 --- a/src/core/endpoints/file_upload/send_file.js +++ /dev/null @@ -1,130 +0,0 @@ -import { PubNubError, createValidationError } from '../../components/endpoint'; - -const sendFile = function ({ - generateUploadUrl, - publishFile, - modules: { PubNubFile, config, cryptography, cryptoModule, networking }, -}) { - return async ({ channel, file: input, message, cipherKey, meta, ttl, storeInHistory }) => { - if (!channel) { - throw new PubNubError( - 'Validation failed, check status for details', - createValidationError("channel can't be empty"), - ); - } - - if (!input) { - throw new PubNubError( - 'Validation failed, check status for details', - createValidationError("file can't be empty"), - ); - } - - let file = PubNubFile.create(input); - - const { - file_upload_request: { url, form_fields: formFields }, - data: { id, name }, - } = await generateUploadUrl({ channel, name: file.name }); - - if (PubNubFile.supportsEncryptFile && (cipherKey || cryptoModule)) { - file = - cipherKey == null - ? await cryptoModule.encryptFile(file, PubNubFile) - : await cryptography.encryptFile(cipherKey, file, PubNubFile); - } - - let formFieldsWithMimeType = formFields; - - if (file.mimeType) { - formFieldsWithMimeType = formFields.map((entry) => { - if (entry.key === 'Content-Type') return { key: entry.key, value: file.mimeType }; - return entry; - }); - } - - let result; - - try { - if (PubNubFile.supportsFileUri && input.uri) { - result = await networking.POSTFILE(url, formFieldsWithMimeType, await file.toFileUri()); - } else if (PubNubFile.supportsFile) { - result = await networking.POSTFILE(url, formFieldsWithMimeType, await file.toFile()); - } else if (PubNubFile.supportsBuffer) { - result = await networking.POSTFILE(url, formFieldsWithMimeType, await file.toBuffer()); - } else if (PubNubFile.supportsBlob) { - result = await networking.POSTFILE(url, formFieldsWithMimeType, await file.toBlob()); - } else { - throw new Error('Unsupported environment'); - } - } catch (e) { - if (e.response && typeof e.response.text === 'string') { - const errorBody = e.response.text; - const reason = /(.*)<\/Message>/gi.exec(errorBody); - throw new PubNubError(reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.', e); - } else { - throw new PubNubError('Upload to bucket failed.', e); - } - } - - if (result.status !== 204) { - throw new PubNubError('Upload to bucket was unsuccessful', result); - } - - let retries = config.fileUploadPublishRetryLimit; - let wasSuccessful = false; - - let publishResult = { timetoken: '0' }; - - do { - try { - /* eslint-disable-next-line no-await-in-loop */ - publishResult = await publishFile({ - channel, - message, - fileId: id, - fileName: name, - meta, - storeInHistory, - ttl, - }); - - wasSuccessful = true; - } catch (e) { - retries -= 1; - } - } while (!wasSuccessful && retries > 0); - - if (!wasSuccessful) { - throw new PubNubError( - 'Publish failed. You may want to execute that operation manually using pubnub.publishFile', - { - channel, - id, - name, - }, - ); - } else { - return { - timetoken: publishResult.timetoken, - id, - name, - }; - } - }; -}; - -export default (deps) => { - const f = sendFile(deps); - - return (params, cb) => { - const resultP = f(params); - - if (typeof cb === 'function') { - resultP.then((result) => cb(null, result)).catch((error) => cb(error, null)); - - return resultP; - } - return resultP; - }; -}; diff --git a/src/core/endpoints/file_upload/send_file.ts b/src/core/endpoints/file_upload/send_file.ts new file mode 100644 index 000000000..0c50dfae6 --- /dev/null +++ b/src/core/endpoints/file_upload/send_file.ts @@ -0,0 +1,197 @@ +import { PubNubFileConstructor, PubNubFileInterface } from '../../types/file'; +import { GenerateFileUploadUrlRequest } from './generate_upload_url'; +import { CryptoModule } from '../../interfaces/crypto-module'; +import { Cryptography } from '../../interfaces/cryptography'; +import { AbstractRequest } from '../../components/request'; +import * as FileSharing from '../../types/api/file-sharing'; +import { PubNubError } from '../../../errors/pubnub-error'; +import RequestOperation from '../../constants/operations'; +import { UploadFileRequest } from './upload-file'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { KeySet } from '../../types/api'; +import StatusCategory from '../../constants/categories'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = FileSharing.SendFileParameters & { + /** + * How many times should retry file message publish. + */ + fileUploadPublishRetryLimit: number; + + /** + * PubNub REST API access key set. + */ + keySet: KeySet; + + /** + * {@link PubNub} File object constructor. + */ + PubNubFile: PubNubFileConstructor; + + /** + * Request sending method. + * + * @param request - Request which should be processed. + */ + sendRequest: (request: AbstractRequest) => Promise; + + /** + * File message publish method. + * + * @param parameters - File message request parameters. + */ + publishFile: ( + parameters: FileSharing.PublishFileMessageParameters, + ) => Promise; + + /** + * If passed, will encrypt the payloads. + * + * @deprecated Pass it to {@link crypto} module instead. + */ + cipherKey?: string; + + /** + * Published data encryption module. + */ + crypto?: CryptoModule; + + /** + * Legacy cryptography module. + */ + cryptography?: Cryptography; +}; +// endregion + +/** + * Send file composed request. + */ +export class SendFileRequest { + /** + * File object for upload. + */ + private file?: PubNubFileInterface; + + constructor(private readonly parameters: RequestParameters) { + this.file = this.parameters.PubNubFile?.create(parameters.file); + + if (!this.file) throw new Error('File upload error: unable to create File object.'); + } + + /** + * Process user-input and upload file. + * + * @returns File upload request response. + */ + public async process(): Promise { + let fileName: string | undefined; + let fileId: string | undefined; + + return this.generateFileUploadUrl() + .then((result) => { + fileName = result.name; + fileId = result.id; + return this.uploadFile(result); + }) + .then((result) => { + if (result.status !== 204) { + throw new PubNubError('Upload to bucket was unsuccessful', { + error: true, + statusCode: result.status, + category: StatusCategory.PNUnknownCategory, + operation: RequestOperation.PNPublishFileOperation, + errorData: { message: result.message }, + }); + } + }) + .then(() => this.publishFileMessage(fileId!, fileName!)) + .catch((error: Error) => { + if (error instanceof PubNubError) throw error; + + const apiError = !(error instanceof PubNubAPIError) ? PubNubAPIError.create(error) : error; + throw new PubNubError('File upload error.', apiError.toStatus(RequestOperation.PNPublishFileOperation)); + }); + } + + /** + * Generate pre-signed file upload Url. + * + * @returns File upload credentials. + */ + private async generateFileUploadUrl(): Promise { + const request = new GenerateFileUploadUrlRequest({ + ...this.parameters, + name: this.file!.name, + keySet: this.parameters.keySet, + }); + + return this.parameters.sendRequest(request); + } + + /** + * Prepare and upload {@link PubNub} File object to remote storage. + * + * @param uploadParameters - File upload request parameters. + * + * @returns + */ + private async uploadFile(uploadParameters: FileSharing.GenerateFileUploadUrlResponse) { + const { cipherKey, PubNubFile, crypto, cryptography } = this.parameters; + const { id, name, url, formFields } = uploadParameters; + + // Encrypt file if possible. + if (this.parameters.PubNubFile!.supportsEncryptFile) { + if (!cipherKey && crypto) this.file = (await crypto.encryptFile(this.file!, PubNubFile!))!; + else if (cipherKey && cryptography) + this.file = (await cryptography.encryptFile(cipherKey, this.file!, PubNubFile!))!; + } + + return this.parameters.sendRequest( + new UploadFileRequest({ + fileId: id, + fileName: name, + file: this.file!, + uploadUrl: url, + formFields, + }), + ); + } + + private async publishFileMessage(fileId: string, fileName: string): Promise { + let result: FileSharing.PublishFileMessageResponse = { timetoken: '0' }; + let retries = this.parameters.fileUploadPublishRetryLimit; + let publishError: PubNubError | undefined; + let wasSuccessful = false; + + do { + try { + result = await this.parameters.publishFile({ ...this.parameters, fileId, fileName }); + wasSuccessful = true; + } catch (error: unknown) { + if (error instanceof PubNubError) publishError = error; + retries -= 1; + } + } while (!wasSuccessful && retries > 0); + + if (!wasSuccessful) { + throw new PubNubError( + 'Publish failed. You may want to execute that operation manually using pubnub.publishFile', + { + error: true, + category: publishError!.status?.category ?? StatusCategory.PNUnknownCategory, + statusCode: publishError!.status?.statusCode ?? 0, + channel: this.parameters.channel, + id: fileId, + name: fileName, + }, + ); + } else return { status: 200, timetoken: result.timetoken, id: fileId, name: fileName }; + } +} diff --git a/src/core/endpoints/file_upload/types.js b/src/core/endpoints/file_upload/types.js deleted file mode 100644 index 0975b9062..000000000 --- a/src/core/endpoints/file_upload/types.js +++ /dev/null @@ -1 +0,0 @@ -/** */ diff --git a/src/core/endpoints/file_upload/upload-file.ts b/src/core/endpoints/file_upload/upload-file.ts new file mode 100644 index 000000000..7147e819c --- /dev/null +++ b/src/core/endpoints/file_upload/upload-file.ts @@ -0,0 +1,70 @@ +/** + * Upload file REST API request. + */ + +import { TransportResponse } from '../../types/transport-response'; +import { TransportMethod, TransportRequest } from '../../types/transport-request'; +import { AbstractRequest } from '../../components/request'; +import * as FileSharing from '../../types/api/file-sharing'; +import RequestOperation from '../../constants/operations'; +import { PubNubFileInterface } from '../../types/file'; + +/** + * File Upload request. + */ +export class UploadFileRequest extends AbstractRequest { + constructor(private readonly parameters: FileSharing.UploadFileParameters) { + super({ method: TransportMethod.POST }); + + // Use file's actual mime type if available. + const mimeType = parameters.file.mimeType; + if (mimeType) { + parameters.formFields = parameters.formFields.map((entry) => { + if (entry.name === 'Content-Type') return { name: entry.name, value: mimeType }; + return entry; + }); + } + } + + operation(): RequestOperation { + return RequestOperation.PNPublishFileOperation; + } + + validate(): string | undefined { + const { fileId, fileName, file, uploadUrl } = this.parameters; + + if (!fileId) return "Validation failed: file 'id' can't be empty"; + if (!fileName) return "Validation failed: file 'name' can't be empty"; + if (!file) return "Validation failed: 'file' can't be empty"; + if (!uploadUrl) return "Validation failed: file upload 'url' can't be empty"; + } + + async parse(response: TransportResponse): Promise { + return { + status: response.status, + message: response.body ? UploadFileRequest.decoder.decode(response.body) : 'OK', + }; + } + + request(): TransportRequest { + return { + ...super.request(), + origin: new URL(this.parameters.uploadUrl).origin, + timeout: 300, + }; + } + + protected get path(): string { + const { pathname, search } = new URL(this.parameters.uploadUrl); + + return `${pathname}${search}`; + } + + protected get body(): ArrayBuffer | PubNubFileInterface | string | undefined { + return this.parameters.file; + } + + protected get formData(): Record[] | undefined { + return this.parameters.formFields; + } +} diff --git a/src/core/endpoints/history/delete_messages.js b/src/core/endpoints/history/delete_messages.js deleted file mode 100644 index aaf8b12d7..000000000 --- a/src/core/endpoints/history/delete_messages.js +++ /dev/null @@ -1,50 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNDeleteMessagesOperation; -} - -export function validateParams(modules, incomingParams) { - const { channel } = incomingParams; - const { config } = modules; - - if (!channel) return 'Missing channel'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function useDelete() { - return true; -} - -export function getURL(modules, incomingParams) { - const { channel } = incomingParams; - const { config } = modules; - - return `/v3/history/sub-key/${config.subscribeKey}/channel/${utils.encodeString(channel)}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { start, end } = incomingParams; - - const outgoingParams = {}; - - if (start) outgoingParams.start = start; - if (end) outgoingParams.end = end; - - return outgoingParams; -} - -export function handleResponse(modules, serverResponse) { - return serverResponse.payload; -} diff --git a/src/core/endpoints/history/delete_messages.ts b/src/core/endpoints/history/delete_messages.ts new file mode 100644 index 000000000..f2a4f8269 --- /dev/null +++ b/src/core/endpoints/history/delete_messages.ts @@ -0,0 +1,98 @@ +/** + * Delete messages REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import type { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../types/transport-request'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import * as History from '../../types/api/history'; +import { KeySet, Query } from '../../types/api'; +import { encodeString } from '../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = History.DeleteMessagesParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Whether service response represent error or not. + */ + error: boolean; + + /** + * Human-readable error explanation. + */ + error_message: string; +}; +// endregion + +/** + * Delete messages from channel history. + */ +export class DeleteMessageRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.DELETE }); + } + + operation(): RequestOperation { + return RequestOperation.PNDeleteMessagesOperation; + } + + validate(): string | undefined { + if (!this.parameters.keySet.subscribeKey) return 'Missing Subscribe Key'; + if (!this.parameters.channel) return 'Missing channel'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return {}; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v3/history/sub-key/${subscribeKey}/channel/${encodeString(channel)}`; + } + + protected get queryParameters(): Query { + const { start, end } = this.parameters; + + return { + ...(start ? { start } : {}), + ...(end ? { end } : {}), + }; + } +} diff --git a/src/core/endpoints/history/get_history.js b/src/core/endpoints/history/get_history.js deleted file mode 100644 index bf76c52a2..000000000 --- a/src/core/endpoints/history/get_history.js +++ /dev/null @@ -1,92 +0,0 @@ -/* */ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -function __processMessage(modules, message) { - const result = {}; - if (!modules.cryptoModule) { - result.payload = message; - return result; - } - try { - const decryptedData = modules.cryptoModule.decrypt(message); - const decryptedPayload = - decryptedData instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decryptedData)) : decryptedData; - result.payload = decryptedPayload; - return result; - } catch (e) { - if (modules.config.logVerbosity && console && console.log) console.log('decryption error', e.message); - result.payload = message; - result.error = `Error while decrypting message content: ${e.message}`; - } - return result; -} - -export function getOperation() { - return operationConstants.PNHistoryOperation; -} - -export function validateParams(modules, incomingParams) { - const { channel } = incomingParams; - const { config } = modules; - - if (!channel) return 'Missing channel'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { channel } = incomingParams; - const { config } = modules; - return `/v2/history/sub-key/${config.subscribeKey}/channel/${utils.encodeString(channel)}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { start, end, reverse, count = 100, stringifiedTimeToken = false, includeMeta = false } = incomingParams; - const outgoingParams = { - include_token: 'true', - }; - - outgoingParams.count = count; - if (start) outgoingParams.start = start; - if (end) outgoingParams.end = end; - if (stringifiedTimeToken) outgoingParams.string_message_token = 'true'; - if (reverse != null) outgoingParams.reverse = reverse.toString(); - if (includeMeta) outgoingParams.include_meta = 'true'; - - return outgoingParams; -} - -export function handleResponse(modules, serverResponse) { - const response = { - messages: [], - startTimeToken: serverResponse[1], - endTimeToken: serverResponse[2], - }; - - if (Array.isArray(serverResponse[0])) { - serverResponse[0].forEach((serverHistoryItem) => { - const processedMessgeResult = __processMessage(modules, serverHistoryItem.message); - const item = { - timetoken: serverHistoryItem.timetoken, - entry: processedMessgeResult.payload, - }; - - if (serverHistoryItem.meta) { - item.meta = serverHistoryItem.meta; - } - if (processedMessgeResult.error) item.error = processedMessgeResult.error; - - response.messages.push(item); - }); - } - - return response; -} diff --git a/src/core/endpoints/history/get_history.ts b/src/core/endpoints/history/get_history.ts new file mode 100644 index 000000000..206a05b57 --- /dev/null +++ b/src/core/endpoints/history/get_history.ts @@ -0,0 +1,210 @@ +/** + * Get history REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { CryptoModule } from '../../interfaces/crypto-module'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Payload, Query } from '../../types/api'; +import * as History from '../../types/api/history'; +import { encodeString } from '../../utils'; + +// -------------------------------------------------------- +// ---------------------- Defaults ------------------------ +// -------------------------------------------------------- +// region Defaults + +/** + * Whether verbose logging enabled or not. + */ +const LOG_VERBOSITY = false; + +/** + * Whether associated message metadata should be returned or not. + */ +const INCLUDE_METADATA = false; + +/** + * Whether timetokens should be returned as strings by default or not. + */ +const STRINGIFY_TIMETOKENS = false; + +/** + * Default and maximum number of messages which should be returned. + */ +const MESSAGES_COUNT = 100; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = History.GetHistoryParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; + + /** + * Published data encryption module. + */ + crypto?: CryptoModule; + + /** + * Whether verbose logging enabled or not. + * + * @default `false` + */ + logVerbosity?: boolean; +}; + +/** + * Service success response. + */ +type ServiceResponse = [ + /** + * List of previously published messages. + */ + { + /** + * Message payload (decrypted). + */ + message: Payload; + + /** + * When message has been received by PubNub service. + */ + timetoken: string | number; + + /** + * Additional data which has been published along with message to be used with real-time + * events filter expression. + */ + meta?: Payload; + }[], + + /** + * Received messages timeline start. + */ + string | number, + + /** + * Received messages timeline end. + */ + string | number, +]; +// endregion + +/** + * Get single channel messages request. + */ +export class GetHistoryRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply defaults. + if (parameters.count) parameters.count = Math.min(parameters.count, MESSAGES_COUNT); + else parameters.count = MESSAGES_COUNT; + + parameters.stringifiedTimeToken ??= STRINGIFY_TIMETOKENS; + parameters.includeMeta ??= INCLUDE_METADATA; + parameters.logVerbosity ??= LOG_VERBOSITY; + } + + operation(): RequestOperation { + return RequestOperation.PNHistoryOperation; + } + + validate(): string | undefined { + if (!this.parameters.keySet.subscribeKey) return 'Missing Subscribe Key'; + if (!this.parameters.channel) return 'Missing channel'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + + const messages = serviceResponse[0]; + const startTimeToken = serviceResponse[1]; + const endTimeToken = serviceResponse[2]; + + // Handle malformed get history response. + if (!Array.isArray(messages)) return { messages: [], startTimeToken, endTimeToken }; + + return { + messages: messages.map((payload) => { + const processedPayload = this.processPayload(payload.message); + const item: History.GetHistoryResponse['messages'][number] = { + entry: processedPayload.payload, + timetoken: payload.timetoken, + }; + + if (processedPayload.error) item.error = processedPayload.error; + if (payload.meta) item.meta = payload.meta; + + return item; + }), + startTimeToken, + endTimeToken, + }; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v2/history/sub-key/${subscribeKey}/channel/${encodeString(channel)}`; + } + + protected get queryParameters(): Query { + const { start, end, reverse, count, stringifiedTimeToken, includeMeta } = this.parameters; + + return { + count: count!, + include_token: 'true', + ...(start ? { start } : {}), + ...(end ? { end } : {}), + ...(stringifiedTimeToken! ? { string_message_token: 'true' } : {}), + ...(reverse !== undefined && reverse !== null ? { reverse: reverse.toString() } : {}), + ...(includeMeta! ? { include_meta: 'true' } : {}), + }; + } + + private processPayload(payload: Payload): { payload: Payload; error?: string } { + const { crypto, logVerbosity } = this.parameters; + if (!crypto || typeof payload !== 'string') return { payload }; + + let decryptedPayload: string; + let error: string | undefined; + + try { + const decryptedData = crypto.decrypt(payload); + decryptedPayload = + decryptedData instanceof ArrayBuffer + ? JSON.parse(GetHistoryRequest.decoder.decode(decryptedData)) + : decryptedData; + } catch (err) { + if (logVerbosity!) console.log(`decryption error`, (err as Error).message); + decryptedPayload = payload; + error = `Error while decrypting message content: ${(err as Error).message}`; + } + + return { + payload: decryptedPayload, + error, + }; + } +} diff --git a/src/core/endpoints/history/message_counts.js b/src/core/endpoints/history/message_counts.js deleted file mode 100644 index 6e00cfcc7..000000000 --- a/src/core/endpoints/history/message_counts.js +++ /dev/null @@ -1,55 +0,0 @@ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNMessageCounts; -} - -export function validateParams(modules, incomingParams) { - const { channels, timetoken, channelTimetokens } = incomingParams; - const { config } = modules; - - if (!channels) return 'Missing channel'; - if (timetoken && channelTimetokens) return 'timetoken and channelTimetokens are incompatible together'; - if (channelTimetokens && channelTimetokens.length > 1 && channels.length !== channelTimetokens.length) { - return 'Length of channelTimetokens and channels do not match'; - } - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { channels } = incomingParams; - const { config } = modules; - - const stringifiedChannels = channels.join(','); - - return `/v3/history/sub-key/${config.subscribeKey}/message-counts/${utils.encodeString(stringifiedChannels)}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { timetoken, channelTimetokens } = incomingParams; - const outgoingParams = {}; - - if (channelTimetokens && channelTimetokens.length === 1) { - const [tt] = channelTimetokens; - outgoingParams.timetoken = tt; - } else if (channelTimetokens) { - outgoingParams.channelsTimetoken = channelTimetokens.join(','); - } else if (timetoken) { - outgoingParams.timetoken = timetoken; - } - - return outgoingParams; -} - -export function handleResponse(modules, serverResponse) { - return { channels: serverResponse.channels }; -} diff --git a/src/core/endpoints/history/message_counts.ts b/src/core/endpoints/history/message_counts.ts new file mode 100644 index 000000000..6672fe8e4 --- /dev/null +++ b/src/core/endpoints/history/message_counts.ts @@ -0,0 +1,124 @@ +/** + * Messages count REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import * as History from '../../types/api/history'; +import { KeySet, Query } from '../../types/api'; +import { encodeNames } from '../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = History.MessageCountParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Whether service response represent error or not. + */ + error: boolean; + + /** + * Human-readable error explanation. + */ + error_message: string; + + /** + * Map of channel names to the number of counted messages. + */ + channels: Record; + + /** + * Map of channel names to pre-computed REST API paths to fetch more. + */ + more: { + [p: string]: { + /** + * Pre-computed message count REST API url to fetch more information. + */ + url: string; + /** + * Whether there is more information available or not. + */ + is_more: boolean; + }; + }; +}; +// endregion + +export class MessageCountRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNMessageCounts; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + channels, + timetoken, + channelTimetokens, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!channels) return 'Missing channels'; + if (timetoken && channelTimetokens) return '`timetoken` and `channelTimetokens` are incompatible together'; + if (!timetoken && !channelTimetokens) return '`timetoken` or `channelTimetokens` need to be set'; + if (channelTimetokens && channelTimetokens.length > 1 && channelTimetokens.length !== channels.length) + return 'Length of `channelTimetokens` and `channels` do not match'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return { channels: serviceResponse.channels }; + } + + protected get path(): string { + return `/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${encodeNames( + this.parameters.channels, + )}`; + } + + protected get queryParameters(): Query { + let { channelTimetokens } = this.parameters; + if (this.parameters.timetoken) channelTimetokens = [this.parameters.timetoken]; + + return { + ...(channelTimetokens!.length === 1 ? { timetoken: channelTimetokens![0] } : {}), + ...(channelTimetokens!.length > 1 ? { channelsTimetoken: channelTimetokens!.join(',') } : {}), + }; + } +} diff --git a/src/core/endpoints/objects/channel/get.js b/src/core/endpoints/objects/channel/get.js deleted file mode 100644 index e5f6f6fb2..000000000 --- a/src/core/endpoints/objects/channel/get.js +++ /dev/null @@ -1,40 +0,0 @@ -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNGetChannelMetadataOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return 'Channel cannot be empty'; - } - }, - - getURL: ({ config }, params) => `/v2/objects/${config.subscribeKey}/channels/${utils.encodeString(params.channel)}`, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_, params) => { - const queryParams = {}; - queryParams.include = ['status', 'type', 'custom']; - - if (params?.include) { - if (params.include?.customFields === false) { - queryParams.include.pop(); - } - } - queryParams.include = queryParams.include.join(','); - - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/channel/get.ts b/src/core/endpoints/objects/channel/get.ts new file mode 100644 index 000000000..3c1534218 --- /dev/null +++ b/src/core/endpoints/objects/channel/get.ts @@ -0,0 +1,91 @@ +/** + * Get Channel Metadata REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; +import { encodeString } from '../../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `Channel` custom field should be included by default or not. + */ +const INCLUDE_CUSTOM_FIELDS = true; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.GetChannelMetadataParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Get Channel Metadata request. + */ +export class GetChannelMetadataRequest< + Response extends AppContext.GetChannelMetadataResponse, + Custom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + } + + operation(): RequestOperation { + return RequestOperation.PNGetChannelMetadataOperation; + } + + validate(): string | undefined { + if (!this.parameters.channel) return 'Channel cannot be empty'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}`; + } + + protected get queryParameters(): Query { + return { + include: ['status', 'type', ...(this.parameters.include!.customFields ? ['custom'] : [])].join(','), + }; + } +} diff --git a/src/core/endpoints/objects/channel/get_all.js b/src/core/endpoints/objects/channel/get_all.js deleted file mode 100644 index 79ced13ef..000000000 --- a/src/core/endpoints/objects/channel/get_all.js +++ /dev/null @@ -1,66 +0,0 @@ -import operationConstants from '../../../constants/operations'; - -const endpoint = { - getOperation: () => operationConstants.PNGetAllChannelMetadataOperation, - - validateParams: () => { - // No required parameters. - }, - - getURL: ({ config }) => `/v2/objects/${config.subscribeKey}/channels`, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_modules, params) => { - const queryParams = {}; - queryParams.include = ['status', 'type']; - - if (params?.include) { - if (params.include?.customFields) { - queryParams.include.push('custom'); - } - } - queryParams.include = queryParams.include.join(','); - - if (params?.include?.totalCount) { - queryParams.count = params.include?.totalCount; - } - - if (params?.page?.next) { - queryParams.start = params.page?.next; - } - - if (params?.page?.prev) { - queryParams.end = params.page?.prev; - } - - if (params?.filter) { - queryParams.filter = params.filter; - } - - queryParams.limit = params?.limit ?? 100; - - if (params?.sort) { - queryParams.sort = Object.entries(params.sort ?? {}).map(([key, value]) => { - if (value === 'asc' || value === 'desc') { - return `${key}:${value}`; - } - return key; - }); - } - - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/channel/get_all.ts b/src/core/endpoints/objects/channel/get_all.ts new file mode 100644 index 000000000..cd442c42f --- /dev/null +++ b/src/core/endpoints/objects/channel/get_all.ts @@ -0,0 +1,105 @@ +/** + * Get All Channel Metadata REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `Channel` custom fields should be included in response or not. + */ +const INCLUDE_CUSTOM_FIELDS = false; + +/** + * Whether total number of channels should be included in response or not. + */ +const INCLUDE_TOTAL_COUNT = false; + +/** + * Number of objects to return in response. + */ +const LIMIT = 100; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- + +// region Types +/** + * Request configuration parameters. + */ +type RequestParameters = + AppContext.GetAllMetadataParameters> & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; + }; +// endregion + +/** + * Get All Channels Metadata request. + */ +export class GetAllChannelsMetadataRequest< + Response extends AppContext.GetAllChannelMetadataResponse, + Custom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + parameters.include.totalCount ??= INCLUDE_TOTAL_COUNT; + parameters.limit ??= LIMIT; + } + + operation(): RequestOperation { + return RequestOperation.PNGetAllChannelMetadataOperation; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + return `/v2/objects/${this.parameters.keySet.subscribeKey}/channels`; + } + + protected get queryParameters(): Query { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort ?? {}).map(([option, order]) => + order !== null ? `${option}:${order}` : option, + ); + + return { + include: ['status', 'type', ...(include!.customFields ? ['custom'] : [])].join(','), + count: `${include!.totalCount!}`, + ...(filter ? { filter } : {}), + ...(page?.next ? { start: page.next } : {}), + ...(page?.prev ? { end: page.prev } : {}), + ...(limit ? { limit } : {}), + ...(sorting.length ? { sort: sorting } : {}), + }; + } +} diff --git a/src/core/endpoints/objects/channel/remove.js b/src/core/endpoints/objects/channel/remove.js deleted file mode 100644 index a05026494..000000000 --- a/src/core/endpoints/objects/channel/remove.js +++ /dev/null @@ -1,31 +0,0 @@ -/** */ - -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNRemoveChannelMetadataOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return 'Channel cannot be empty'; - } - }, - - getURL: ({ config }, params) => `/v2/objects/${config.subscribeKey}/channels/${utils.encodeString(params.channel)}`, - useDelete: () => true, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: () => ({}), - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/channel/remove.ts b/src/core/endpoints/objects/channel/remove.ts new file mode 100644 index 000000000..50918491d --- /dev/null +++ b/src/core/endpoints/objects/channel/remove.ts @@ -0,0 +1,70 @@ +/** + * Remove Channel Metadata REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../../types/transport-request'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { encodeString } from '../../../utils'; +import { KeySet } from '../../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.RemoveChannelMetadataParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Remove Channel Metadata request. + */ +export class RemoveChannelMetadataRequest< + Response extends AppContext.RemoveChannelMetadataResponse, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.DELETE }); + } + + operation(): RequestOperation { + return RequestOperation.PNRemoveChannelMetadataOperation; + } + + validate(): string | undefined { + if (!this.parameters.channel) return 'Channel cannot be empty'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}`; + } +} diff --git a/src/core/endpoints/objects/channel/set.js b/src/core/endpoints/objects/channel/set.js deleted file mode 100644 index 7f3d4f78c..000000000 --- a/src/core/endpoints/objects/channel/set.js +++ /dev/null @@ -1,49 +0,0 @@ -/** */ - -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNSetChannelMetadataOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return 'Channel cannot be empty'; - } - - if (!params?.data) { - return 'Data cannot be empty'; - } - }, - - usePatch: () => true, - - patchURL: ({ config }, params) => `/v2/objects/${config.subscribeKey}/channels/${utils.encodeString(params.channel)}`, - - patchPayload: (_, params) => params.data, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_, params) => { - const queryParams = {}; - queryParams.include = ['status', 'type', 'custom']; - - if (params?.include) { - if (params.include?.customFields === false) { - queryParams.include.pop(); - } - } - queryParams.include = queryParams.include.join(','); - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/channel/set.ts b/src/core/endpoints/objects/channel/set.ts new file mode 100644 index 000000000..555604d2c --- /dev/null +++ b/src/core/endpoints/objects/channel/set.ts @@ -0,0 +1,97 @@ +/** + * Set Channel Metadata REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../../types/transport-request'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; +import { encodeString } from '../../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `Channel` custom field should be included by default or not. + */ +const INCLUDE_CUSTOM_FIELDS = true; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.SetChannelMetadataParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Set Channel Metadata request. + */ +export class SetChannelMetadataRequest< + Response extends AppContext.SetChannelMetadataResponse, + Custom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.PATCH }); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + } + + operation(): RequestOperation { + return RequestOperation.PNSetChannelMetadataOperation; + } + + validate(): string | undefined { + if (!this.parameters.channel) return 'Channel cannot be empty'; + if (!this.parameters.data) return 'Data cannot be empty'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}`; + } + + protected get queryParameters(): Query { + return { + include: ['status', 'type', ...(this.parameters.include!.customFields ? ['custom'] : [])].join(','), + }; + } + + protected get body(): ArrayBuffer | string | undefined { + return JSON.stringify(this.parameters.data); + } +} diff --git a/src/core/endpoints/objects/member/get.js b/src/core/endpoints/objects/member/get.js deleted file mode 100644 index 5ce830599..000000000 --- a/src/core/endpoints/objects/member/get.js +++ /dev/null @@ -1,93 +0,0 @@ -/** */ - -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNGetMembersOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return 'channel cannot be empty'; - } - }, - - getURL: ({ config }, params) => - `/v2/objects/${config.subscribeKey}/channels/${utils.encodeString(params.channel)}/uuids`, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_modules, params) => { - const queryParams = {}; - queryParams.include = []; - - if (params?.include) { - if (params.include?.statusField) { - queryParams.include.push('status'); - } - - if (params.include?.customFields) { - queryParams.include.push('custom'); - } - - if (params.include?.UUIDFields) { - queryParams.include.push('uuid'); - } - - if (params.include?.customUUIDFields) { - queryParams.include.push('uuid.custom'); - } - - if (params.include?.UUIDStatusField) { - queryParams.include.push('uuid.status'); - } - - if (params.include?.UUIDTypeField) { - queryParams.include.push('uuid.type'); - } - } - queryParams.include = queryParams.include.join(','); - - if (params?.include?.totalCount) { - queryParams.count = params.include?.totalCount; - } - - if (params?.page?.next) { - queryParams.start = params.page?.next; - } - - if (params?.page?.prev) { - queryParams.end = params.page?.prev; - } - - if (params?.filter) { - queryParams.filter = params.filter; - } - - queryParams.limit = params?.limit ?? 100; - - if (params?.sort) { - queryParams.sort = Object.entries(params.sort ?? {}).map(([key, value]) => { - if (value === 'asc' || value === 'desc') { - return `${key}:${value}`; - } - return key; - }); - } - - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/member/get.ts b/src/core/endpoints/objects/member/get.ts new file mode 100644 index 000000000..1b80c78b8 --- /dev/null +++ b/src/core/endpoints/objects/member/get.ts @@ -0,0 +1,153 @@ +/** + * Get Channel Members REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; +import { encodeString } from '../../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `Member` custom field should be included in response or not. + */ +const INCLUDE_CUSTOM_FIELDS = false; + +/** + * Whether member's status field should be included in response or not. + */ +const INCLUDE_STATUS = false; + +/** + * Whether total number of members should be included in response or not. + */ +const INCLUDE_TOTAL_COUNT = false; + +/** + * Whether `UUID` fields should be included in response or not. + */ +const INCLUDE_UUID_FIELDS = false; + +/** + * Whether `UUID` status field should be included in response or not. + */ +const INCLUDE_UUID_STATUS_FIELD = false; + +/** + * Whether `UUID` type field should be included in response or not. + */ +const INCLUDE_UUID_TYPE_FIELD = false; + +/** + * Whether `UUID` custom field should be included in response or not. + */ +const INCLUDE_UUID_CUSTOM_FIELDS = false; + +/** + * Number of objects to return in response. + */ +const LIMIT = 100; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.GetMembersParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Get Channel Members request. + */ +export class GetChannelMembersRequest< + Response extends AppContext.GetMembersResponse, + MembersCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + parameters.include.totalCount ??= INCLUDE_TOTAL_COUNT; + parameters.include.statusField ??= INCLUDE_STATUS; + parameters.include.UUIDFields ??= INCLUDE_UUID_FIELDS; + parameters.include.customUUIDFields ??= INCLUDE_UUID_CUSTOM_FIELDS; + parameters.include.UUIDStatusField ??= INCLUDE_UUID_STATUS_FIELD; + parameters.include.UUIDTypeField ??= INCLUDE_UUID_TYPE_FIELD; + parameters.limit ??= LIMIT; + } + + operation(): RequestOperation { + return RequestOperation.PNSetMembersOperation; + } + + validate(): string | undefined { + if (!this.parameters.channel) return 'Channel cannot be empty'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}/uuids`; + } + + protected get queryParameters(): Query { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort ?? {}).map(([option, order]) => + order !== null ? `${option}:${order}` : option, + ); + const includeFlags: string[] = []; + + if (include!.statusField) includeFlags.push('status'); + if (include!.customFields) includeFlags.push('custom'); + if (include!.UUIDFields) includeFlags.push('uuid'); + if (include!.UUIDStatusField) includeFlags.push('uuid.status'); + if (include!.UUIDTypeField) includeFlags.push('uuid.type'); + if (include!.customUUIDFields) includeFlags.push('uuid.custom'); + + return { + count: `${include!.totalCount!}`, + ...(includeFlags.length > 0 ? { include: includeFlags.join(',') } : {}), + ...(filter ? { filter } : {}), + ...(page?.next ? { start: page.next } : {}), + ...(page?.prev ? { end: page.prev } : {}), + ...(limit ? { limit } : {}), + ...(sorting.length ? { sort: sorting } : {}), + }; + } +} diff --git a/src/core/endpoints/objects/member/set.js b/src/core/endpoints/objects/member/set.js deleted file mode 100644 index e80f3163e..000000000 --- a/src/core/endpoints/objects/member/set.js +++ /dev/null @@ -1,107 +0,0 @@ -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNSetMembersOperation, - - validateParams: (_, params) => { - if (!params?.channel) { - return 'Channel cannot be empty'; - } - - if (!params?.uuids || params?.uuids.length === 0) { - return 'UUIDs cannot be empty'; - } - }, - - usePatch: () => true, - - patchURL: ({ config }, params) => - `/v2/objects/${config.subscribeKey}/channels/${utils.encodeString(params.channel)}/uuids`, - - patchPayload: (_, params) => ({ - set: [], - delete: [], - [params.type]: params.uuids.map((uuid) => { - if (typeof uuid === 'string') { - return { - uuid: { - id: uuid, - }, - }; - } - return { - uuid: { id: uuid.id }, - custom: uuid.custom, - status: uuid.status, - }; - }), - }), - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_modules, params) => { - const queryParams = {}; - queryParams.include = ['uuid.status', 'uuid.type', 'type']; - - if (params?.include) { - if (params.include?.customFields) { - queryParams.include.push('custom'); - } - - if (params.include?.customUUIDFields) { - queryParams.include.push('uuid.custom'); - } - - if (params.include?.UUIDFields) { - queryParams.include.push('uuid'); - } - } - - queryParams.include = queryParams.include.join(','); - - if (params?.include?.totalCount) { - queryParams.count = true; - } - - if (params?.page?.next) { - queryParams.start = params.page?.next; - } - - if (params?.page?.prev) { - queryParams.end = params.page?.prev; - } - - if (params?.filter) { - queryParams.filter = params.filter; - } - - if (params.limit != null) { - queryParams.limit = params.limit; - } - - if (params?.sort) { - queryParams.sort = Object.entries(params.sort ?? {}).map(([key, value]) => { - if (value === 'asc' || value === 'desc') { - return `${key}:${value}`; - } - return key; - }); - } - - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/member/set.ts b/src/core/endpoints/objects/member/set.ts new file mode 100644 index 000000000..c5bb2500d --- /dev/null +++ b/src/core/endpoints/objects/member/set.ts @@ -0,0 +1,155 @@ +/** + * Set Channel Members REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../../types/transport-request'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; +import { encodeString } from '../../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `Member` custom field should be included in response or not. + */ +const INCLUDE_CUSTOM_FIELDS = false; + +/** + * Whether total number of members should be included in response or not. + */ +const INCLUDE_TOTAL_COUNT = false; + +/** + * Whether `UUID` fields should be included in response or not. + */ +const INCLUDE_UUID_FIELDS = false; + +/** + * Whether `UUID` custom field should be included in response or not. + */ +const INCLUDE_UUID_CUSTOM_FIELDS = false; + +/** + * Number of objects to return in response. + */ +const LIMIT = 100; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.SetChannelMembersParameters & { + /** + * Type of change in channel members list. + */ + type: 'set' | 'delete'; + + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Set Channel Members request. + */ +export class SetChannelMembersRequest< + Response extends AppContext.SetMembersResponse, + MembersCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.PATCH }); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + parameters.include.totalCount ??= INCLUDE_TOTAL_COUNT; + parameters.include.UUIDFields ??= INCLUDE_UUID_FIELDS; + parameters.include.customUUIDFields ??= INCLUDE_UUID_CUSTOM_FIELDS; + parameters.limit ??= LIMIT; + } + + operation(): RequestOperation { + return RequestOperation.PNSetMembersOperation; + } + + validate(): string | undefined { + const { channel, uuids } = this.parameters; + + if (!channel) return 'Channel cannot be empty'; + if (!uuids || uuids.length === 0) return 'UUIDs cannot be empty'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channel, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}/uuids`; + } + + protected get queryParameters(): Query { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort ?? {}).map(([option, order]) => + order !== null ? `${option}:${order}` : option, + ); + const includeFlags: string[] = ['uuid.status', 'uuid.type', 'type']; + + if (include!.customFields) includeFlags.push('custom'); + if (include!.UUIDFields) includeFlags.push('uuid'); + if (include!.customUUIDFields) includeFlags.push('uuid.custom'); + + return { + count: `${include!.totalCount!}`, + ...(includeFlags.length > 0 ? { include: includeFlags.join(',') } : {}), + ...(filter ? { filter } : {}), + ...(page?.next ? { start: page.next } : {}), + ...(page?.prev ? { end: page.prev } : {}), + ...(limit ? { limit } : {}), + ...(sorting.length ? { sort: sorting } : {}), + }; + } + + protected get body(): string { + const { uuids, type } = this.parameters; + + return JSON.stringify({ + [`${type}`]: uuids.map((uuid) => { + if (typeof uuid === 'string') { + return { uuid: { id: uuid } }; + } else { + return { uuid: { id: uuid.id }, status: uuid.status, custom: uuid.custom }; + } + }), + }); + } +} diff --git a/src/core/endpoints/objects/membership/get.js b/src/core/endpoints/objects/membership/get.js deleted file mode 100644 index 3f3dc94dd..000000000 --- a/src/core/endpoints/objects/membership/get.js +++ /dev/null @@ -1,89 +0,0 @@ -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNGetMembershipsOperation, - - validateParams: () => { - // No required parameters. - }, - - getURL: ({ config }, params) => - `/v2/objects/${config.subscribeKey}/uuids/${utils.encodeString(params?.uuid ?? config.getUUID())}/channels`, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_modules, params) => { - const queryParams = {}; - queryParams.include = []; - - if (params?.include) { - if (params.include?.statusField) { - queryParams.include.push('status'); - } - - if (params.include?.customFields) { - queryParams.include.push('custom'); - } - - if (params.include?.channelFields) { - queryParams.include.push('channel'); - } - - if (params.include?.customChannelFields) { - queryParams.include.push('channel.custom'); - } - - if (params.include?.channelStatusField) { - queryParams.include.push('channel.status'); - } - - if (params.include?.channelTypeField) { - queryParams.include.push('channel.type'); - } - } - queryParams.include = queryParams.include.join(','); - - if (params?.include?.totalCount) { - queryParams.count = params.include?.totalCount; - } - - if (params?.page?.next) { - queryParams.start = params.page?.next; - } - - if (params?.page?.prev) { - queryParams.end = params.page?.prev; - } - - if (params?.filter) { - queryParams.filter = params.filter; - } - - queryParams.limit = params?.limit ?? 100; - - if (params?.sort) { - queryParams.sort = Object.entries(params.sort ?? {}).map(([key, value]) => { - if (value === 'asc' || value === 'desc') { - return `${key}:${value}`; - } - return key; - }); - } - - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/membership/get.ts b/src/core/endpoints/objects/membership/get.ts new file mode 100644 index 000000000..34e2b6dab --- /dev/null +++ b/src/core/endpoints/objects/membership/get.ts @@ -0,0 +1,156 @@ +/** + * Get UUID Memberships REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; +import { encodeString } from '../../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `Membership` custom field should be included in response or not. + */ +const INCLUDE_CUSTOM_FIELDS = false; + +/** + * Whether membership's status field should be included in response or not. + */ +const INCLUDE_STATUS = false; + +/** + * Whether total number of memberships should be included in response or not. + */ +const INCLUDE_TOTAL_COUNT = false; + +/** + * Whether `Channel` fields should be included in response or not. + */ +const INCLUDE_CHANNEL_FIELDS = false; + +/** + * Whether `Channel` status field should be included in response or not. + */ +const INCLUDE_CHANNEL_STATUS_FIELD = false; + +/** + * Whether `Channel` type field should be included in response or not. + */ +const INCLUDE_CHANNEL_TYPE_FIELD = false; + +/** + * Whether `Channel` custom field should be included in response or not. + */ +const INCLUDE_CHANNEL_CUSTOM_FIELDS = false; + +/** + * Number of objects to return in response. + */ +const LIMIT = 100; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.GetMembershipsParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Get UUID Memberships request. + */ +export class GetUUIDMembershipsRequest< + Response extends AppContext.GetMembershipsResponse, + MembersCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + parameters.include.totalCount ??= INCLUDE_TOTAL_COUNT; + parameters.include.statusField ??= INCLUDE_STATUS; + parameters.include.channelFields ??= INCLUDE_CHANNEL_FIELDS; + parameters.include.customChannelFields ??= INCLUDE_CHANNEL_CUSTOM_FIELDS; + parameters.include.channelStatusField ??= INCLUDE_CHANNEL_STATUS_FIELD; + parameters.include.channelTypeField ??= INCLUDE_CHANNEL_TYPE_FIELD; + parameters.limit ??= LIMIT; + + // Remap for backward compatibility. + if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; + } + + operation(): RequestOperation { + return RequestOperation.PNGetMembershipsOperation; + } + + validate(): string | undefined { + if (!this.parameters.uuid) return "'uuid' cannot be empty"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + uuid, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid!)}/channels`; + } + + protected get queryParameters(): Query { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort ?? {}).map(([option, order]) => + order !== null ? `${option}:${order}` : option, + ); + const includeFlags: string[] = []; + + if (include!.statusField) includeFlags.push('status'); + if (include!.customFields) includeFlags.push('custom'); + if (include!.channelFields) includeFlags.push('channel'); + if (include!.channelStatusField) includeFlags.push('channel.status'); + if (include!.channelTypeField) includeFlags.push('channel.type'); + if (include!.customChannelFields) includeFlags.push('channel.custom'); + + return { + count: `${include!.totalCount!}`, + ...(includeFlags.length > 0 ? { include: includeFlags.join(',') } : {}), + ...(filter ? { filter } : {}), + ...(page?.next ? { start: page.next } : {}), + ...(page?.prev ? { end: page.prev } : {}), + ...(limit ? { limit } : {}), + ...(sorting.length ? { sort: sorting } : {}), + }; + } +} diff --git a/src/core/endpoints/objects/membership/set.js b/src/core/endpoints/objects/membership/set.js deleted file mode 100644 index f801d7c2a..000000000 --- a/src/core/endpoints/objects/membership/set.js +++ /dev/null @@ -1,105 +0,0 @@ -/** */ - -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNSetMembershipsOperation, - - validateParams: (_, params) => { - if (!params?.channels || params?.channels.length === 0) { - return 'Channels cannot be empty'; - } - }, - - usePatch: () => true, - - patchURL: ({ config }, params) => - `/v2/objects/${config.subscribeKey}/uuids/${utils.encodeString(params.uuid ?? config.getUUID())}/channels`, - - patchPayload: (_, params) => ({ - set: [], - delete: [], - [params.type]: params.channels.map((channel) => { - if (typeof channel === 'string') { - return { - channel: { - id: channel, - }, - }; - } - return { - channel: { id: channel.id }, - custom: channel.custom, - status: channel.status, - }; - }), - }), - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_modules, params) => { - const queryParams = {}; - queryParams.include = ['channel.status', 'channel.type', 'status']; - - if (params?.include) { - if (params.include?.customFields) { - queryParams.include.push('custom'); - } - - if (params.include?.customChannelFields) { - queryParams.include.push('channel.custom'); - } - - if (params.include?.channelFields) { - queryParams.include.push('channel'); - } - } - - queryParams.include = queryParams.include.join(','); - - if (params?.include?.totalCount) { - queryParams.count = true; - } - - if (params?.page?.next) { - queryParams.start = params.page?.next; - } - - if (params?.page?.prev) { - queryParams.end = params.page?.prev; - } - - if (params?.filter) { - queryParams.filter = params.filter; - } - - if (params.limit != null) { - queryParams.limit = params.limit; - } - - if (params?.sort) { - queryParams.sort = Object.entries(params.sort ?? {}).map(([key, value]) => { - if (value === 'asc' || value === 'desc') { - return `${key}:${value}`; - } - return key; - }); - } - - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - prev: response.prev, - next: response.next, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/membership/set.ts b/src/core/endpoints/objects/membership/set.ts new file mode 100644 index 000000000..1633dcce1 --- /dev/null +++ b/src/core/endpoints/objects/membership/set.ts @@ -0,0 +1,158 @@ +/** + * Set UUID Memberships REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../../types/transport-request'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; +import { encodeString } from '../../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `Membership` custom field should be included in response or not. + */ +const INCLUDE_CUSTOM_FIELDS = false; + +/** + * Whether total number of memberships should be included in response or not. + */ +const INCLUDE_TOTAL_COUNT = false; + +/** + * Whether `Channel` fields should be included in response or not. + */ +const INCLUDE_CHANNEL_FIELDS = false; + +/** + * Whether `Channel` custom field should be included in response or not. + */ +const INCLUDE_CHANNEL_CUSTOM_FIELDS = false; + +/** + * Number of objects to return in response. + */ +const LIMIT = 100; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.SetMembershipsParameters & { + /** + * Type of change in UUID memberships list. + */ + type: 'set' | 'delete'; + + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Set UUID Memberships request. + */ +export class SetUUIDMembershipsRequest< + Response extends AppContext.SetMembershipsResponse, + MembersCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.PATCH }); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + parameters.include.totalCount ??= INCLUDE_TOTAL_COUNT; + parameters.include.channelFields ??= INCLUDE_CHANNEL_FIELDS; + parameters.include.customChannelFields ??= INCLUDE_CHANNEL_CUSTOM_FIELDS; + parameters.limit ??= LIMIT; + + // Remap for backward compatibility. + if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; + } + + operation(): RequestOperation { + return RequestOperation.PNSetMembershipsOperation; + } + + validate(): string | undefined { + const { uuid, channels } = this.parameters; + + if (!uuid) return "'uuid' cannot be empty"; + if (!channels || channels.length === 0) return 'Channels cannot be empty'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + uuid, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid!)}/channels`; + } + + protected get queryParameters(): Query { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort ?? {}).map(([option, order]) => + order !== null ? `${option}:${order}` : option, + ); + const includeFlags: string[] = ['channel.status', 'channel.type', 'status']; + + if (include!.customFields) includeFlags.push('custom'); + if (include!.channelFields) includeFlags.push('channel'); + if (include!.customChannelFields) includeFlags.push('channel.custom'); + + return { + count: `${include!.totalCount!}`, + ...(includeFlags.length > 0 ? { include: includeFlags.join(',') } : {}), + ...(filter ? { filter } : {}), + ...(page?.next ? { start: page.next } : {}), + ...(page?.prev ? { end: page.prev } : {}), + ...(limit ? { limit } : {}), + ...(sorting.length ? { sort: sorting } : {}), + }; + } + + protected get body(): string { + const { channels, type } = this.parameters; + + return JSON.stringify({ + [`${type}`]: channels.map((channel) => { + if (typeof channel === 'string') { + return { channel: { id: channel } }; + } else { + return { channel: { id: channel.id }, status: channel.status, custom: channel.custom }; + } + }), + }); + } +} diff --git a/src/core/endpoints/objects/uuid/get.js b/src/core/endpoints/objects/uuid/get.js deleted file mode 100644 index 1721489d8..000000000 --- a/src/core/endpoints/objects/uuid/get.js +++ /dev/null @@ -1,44 +0,0 @@ -/** */ - -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNGetUUIDMetadataOperation, - - validateParams: () => { - // No required parameters. - }, - - getURL: ({ config }, params) => - `/v2/objects/${config.subscribeKey}/uuids/${utils.encodeString(params?.uuid ?? config.getUUID())}`, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: ({ config }, params) => { - const queryParams = {}; - - queryParams.uuid = params?.uuid ?? config.getUUID(); - queryParams.include = ['status', 'type', 'custom']; - - if (params?.include) { - if (params.include?.customFields === false) { - queryParams.include.pop(); - } - } - - queryParams.include = queryParams.include.join(','); - - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/uuid/get.ts b/src/core/endpoints/objects/uuid/get.ts new file mode 100644 index 000000000..7a93648aa --- /dev/null +++ b/src/core/endpoints/objects/uuid/get.ts @@ -0,0 +1,94 @@ +/** + * Get UUID Metadata REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; +import { encodeString } from '../../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether UUID custom field should be included by default or not. + */ +const INCLUDE_CUSTOM_FIELDS = true; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.GetUUIDMetadataParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Get UUID Metadata request. + */ +export class GetUUIDMetadataRequest< + Response extends AppContext.GetUUIDMetadataResponse, + Custom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + + // Remap for backward compatibility. + if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; + } + + operation(): RequestOperation { + return RequestOperation.PNGetUUIDMetadataOperation; + } + + validate(): string | undefined { + if (!this.parameters.uuid) return "'uuid' cannot be empty"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + uuid, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid!)}`; + } + + protected get queryParameters(): Query { + const { include } = this.parameters; + + return { include: ['status', 'type', ...(include!.customFields ? ['custom'] : [])].join(',') }; + } +} diff --git a/src/core/endpoints/objects/uuid/get_all.js b/src/core/endpoints/objects/uuid/get_all.js deleted file mode 100644 index 1c3ef9d86..000000000 --- a/src/core/endpoints/objects/uuid/get_all.js +++ /dev/null @@ -1,67 +0,0 @@ -import operationConstants from '../../../constants/operations'; - -const endpoint = { - getOperation: () => operationConstants.PNGetAllUUIDMetadataOperation, - - validateParams: () => { - // No required parameters. - }, - - getURL: ({ config }) => `/v2/objects/${config.subscribeKey}/uuids`, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_modules, params) => { - const queryParams = {}; - queryParams.include = ['status', 'type']; - - if (params?.include) { - if (params.include?.customFields) { - queryParams.include.push('custom'); - } - } - - queryParams.include = queryParams.include.join(','); - - if (params?.include?.totalCount) { - queryParams.count = params.include?.totalCount; - } - - if (params?.page?.next) { - queryParams.start = params.page?.next; - } - - if (params?.page?.prev) { - queryParams.end = params.page?.prev; - } - - if (params?.filter) { - queryParams.filter = params.filter; - } - - queryParams.limit = params?.limit ?? 100; - - if (params?.sort) { - queryParams.sort = Object.entries(params.sort ?? {}).map(([key, value]) => { - if (value === 'asc' || value === 'desc') { - return `${key}:${value}`; - } - return key; - }); - } - - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - totalCount: response.totalCount, - next: response.next, - prev: response.prev, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/uuid/get_all.ts b/src/core/endpoints/objects/uuid/get_all.ts new file mode 100644 index 000000000..c7b5efca8 --- /dev/null +++ b/src/core/endpoints/objects/uuid/get_all.ts @@ -0,0 +1,96 @@ +/** + * Get All UUID Metadata REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `Channel` custom field should be included by default or not. + */ +const INCLUDE_CUSTOM_FIELDS = false; + +/** + * Number of objects to return in response. + */ +const LIMIT = 100; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = + AppContext.GetAllMetadataParameters> & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; + }; +// endregion + +export class GetAllUUIDMetadataRequest< + Response extends AppContext.GetAllUUIDMetadataResponse, + Custom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + parameters.limit ??= LIMIT; + } + + operation(): RequestOperation { + return RequestOperation.PNGetAllUUIDMetadataOperation; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + return `/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`; + } + + protected get queryParameters(): Query { + const { include, page, filter, sort, limit } = this.parameters; + const sorting = Object.entries(sort ?? {}).map(([option, order]) => + order !== null ? `${option}:${order}` : option, + ); + + return { + include: ['status', 'type', ...(include!.customFields ? ['custom'] : [])].join(','), + ...(include!.totalCount !== undefined ? { count: `${include!.totalCount}` } : {}), + ...(filter ? { filter } : {}), + ...(page?.next ? { start: page.next } : {}), + ...(page?.prev ? { end: page.prev } : {}), + ...(limit ? { limit } : {}), + ...(sorting.length ? { sort: sorting } : {}), + }; + } +} diff --git a/src/core/endpoints/objects/uuid/remove.js b/src/core/endpoints/objects/uuid/remove.js deleted file mode 100644 index a441c92db..000000000 --- a/src/core/endpoints/objects/uuid/remove.js +++ /dev/null @@ -1,32 +0,0 @@ -/** */ - -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNRemoveUUIDMetadataOperation, - - validateParams: () => { - // No required parameters. - }, - - getURL: ({ config }, params) => - `/v2/objects/${config.subscribeKey}/uuids/${utils.encodeString(params?.uuid ?? config.getUUID())}`, - useDelete: () => true, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: ({ config }, params) => ({ - uuid: params?.uuid ?? config.getUUID(), - }), - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/uuid/remove.ts b/src/core/endpoints/objects/uuid/remove.ts new file mode 100644 index 000000000..2bc521d6f --- /dev/null +++ b/src/core/endpoints/objects/uuid/remove.ts @@ -0,0 +1,73 @@ +/** + * Remove UUID Metadata REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../../types/transport-request'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet } from '../../../types/api'; +import { encodeString } from '../../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.RemoveUUIDMetadataParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Remove UUID Metadata request. + */ +export class RemoveUUIDMetadataRequest< + Response extends AppContext.RemoveUUIDMetadataResponse, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.DELETE }); + + // Remap for backward compatibility. + if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; + } + + operation(): RequestOperation { + return RequestOperation.PNRemoveUUIDMetadataOperation; + } + + validate(): string | undefined { + if (!this.parameters.uuid) return "'uuid' cannot be empty"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + uuid, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid!)}`; + } +} diff --git a/src/core/endpoints/objects/uuid/set.js b/src/core/endpoints/objects/uuid/set.js deleted file mode 100644 index ca111373c..000000000 --- a/src/core/endpoints/objects/uuid/set.js +++ /dev/null @@ -1,50 +0,0 @@ -/** */ - -import operationConstants from '../../../constants/operations'; - -import utils from '../../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNSetUUIDMetadataOperation, - - validateParams: (_, params) => { - if (!params?.data) { - return 'Data cannot be empty'; - } - }, - - usePatch: () => true, - - patchURL: ({ config }, params) => - `/v2/objects/${config.subscribeKey}/uuids/${utils.encodeString(params.uuid ?? config.getUUID())}`, - - patchPayload: (_, params) => params.data, - - getRequestTimeout: ({ config }) => config.getTransactionTimeout(), - - isAuthSupported: () => true, - - prepareParams: ({ config }, params) => { - const queryParams = {}; - - queryParams.uuid = params?.uuid ?? config.getUUID(); - queryParams.include = ['status', 'type', 'custom']; - - if (params?.include) { - if (params.include?.customFields === false) { - queryParams.include.pop(); - } - } - - queryParams.include = queryParams.include.join(','); - - return queryParams; - }, - - handleResponse: (_, response) => ({ - status: response.status, - data: response.data, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/objects/uuid/set.ts b/src/core/endpoints/objects/uuid/set.ts new file mode 100644 index 000000000..9ba8736c7 --- /dev/null +++ b/src/core/endpoints/objects/uuid/set.ts @@ -0,0 +1,100 @@ +/** + * Set UUID Metadata REST API module. + */ + +import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; +import { TransportResponse } from '../../../types/transport-response'; +import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; +import { TransportMethod } from '../../../types/transport-request'; +import { AbstractRequest } from '../../../components/request'; +import RequestOperation from '../../../constants/operations'; +import * as AppContext from '../../../types/api/app-context'; +import { KeySet, Query } from '../../../types/api'; +import { encodeString } from '../../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `Channel` custom field should be included by default or not. + */ +const INCLUDE_CUSTOM_FIELDS = true; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = AppContext.SetUUIDMetadataParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Set UUID Metadata request. + */ +export class SetUUIDMetadataRequest< + Response extends AppContext.SetUUIDMetadataResponse, + Custom extends AppContext.CustomData = AppContext.CustomData, +> extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super({ method: TransportMethod.PATCH }); + + // Apply default request parameters. + parameters.include ??= {}; + parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; + + // Remap for backward compatibility. + if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; + } + + operation(): RequestOperation { + return RequestOperation.PNSetUUIDMetadataOperation; + } + + validate(): string | undefined { + if (!this.parameters.uuid) return "'uuid' cannot be empty"; + if (!this.parameters.data) return 'Data cannot be empty'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return serviceResponse; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + uuid, + } = this.parameters; + + return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid!)}`; + } + + protected get queryParameters(): Query { + return { + include: ['status', 'type', ...(this.parameters.include!.customFields ? ['custom'] : [])].join(','), + }; + } + + protected get body(): ArrayBuffer | string | undefined { + return JSON.stringify(this.parameters.data); + } +} diff --git a/src/core/endpoints/presence/get_state.js b/src/core/endpoints/presence/get_state.js deleted file mode 100644 index c75caa82a..000000000 --- a/src/core/endpoints/presence/get_state.js +++ /dev/null @@ -1,53 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNGetStateOperation; -} - -export function validateParams(modules) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { config } = modules; - const { uuid = config.UUID, channels = [] } = incomingParams; - const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return `/v2/presence/sub-key/${config.subscribeKey}/channel/${utils.encodeString(stringifiedChannels)}/uuid/${uuid}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { channelGroups = [] } = incomingParams; - const params = {}; - - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - - return params; -} - -export function handleResponse(modules, serverResponse, incomingParams) { - const { channels = [], channelGroups = [] } = incomingParams; - let channelsResponse = {}; - - if (channels.length === 1 && channelGroups.length === 0) { - channelsResponse[channels[0]] = serverResponse.payload; - } else { - channelsResponse = serverResponse.payload; - } - - return { channels: channelsResponse }; -} diff --git a/src/core/endpoints/presence/get_state.ts b/src/core/endpoints/presence/get_state.ts new file mode 100644 index 000000000..ede87639e --- /dev/null +++ b/src/core/endpoints/presence/get_state.ts @@ -0,0 +1,121 @@ +/** + * Get Presence State REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Payload, Query } from '../../types/api'; +import * as Presence from '../../types/api/presence'; +import { encodeNames } from '../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Presence.GetPresenceStateParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Get presence state human-readable result. + */ + message: string; + + /** + * Name of the service which provided response. + */ + service: string; + + /** + * Whether response represent service error or not. + */ + uuid: string; + + /** + * Retrieved {@link uuid} per-channel associated presence state. + */ + payload: Record | Payload; +}; +// endregion + +/** + * Get `uuid` presence state request. + */ +export class GetPresenceStateRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply defaults. + this.parameters.channels ??= []; + this.parameters.channelGroups ??= []; + } + + operation(): RequestOperation { + return RequestOperation.PNGetStateOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + channels, + channelGroups, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + const { channels = [], channelGroups = [] } = this.parameters; + const state: { channels: Record } = { channels: {} }; + + if (channels.length === 1 && channelGroups.length === 0) state.channels[channels[0]] = serviceResponse.payload; + else state.channels = serviceResponse.payload as Record; + + return state; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + uuid, + channels, + } = this.parameters; + + return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels ?? [], ',')}/uuid/${uuid}`; + } + + protected get queryParameters(): Query { + const { channelGroups } = this.parameters; + if (!channelGroups || channelGroups.length === 0) return {}; + + return { 'channel-group': channelGroups.join(',') }; + } +} diff --git a/src/core/endpoints/presence/heartbeat.js b/src/core/endpoints/presence/heartbeat.js deleted file mode 100644 index b5b0b7627..000000000 --- a/src/core/endpoints/presence/heartbeat.js +++ /dev/null @@ -1,49 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNHeartbeatOperation; -} - -export function validateParams(modules) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { config } = modules; - const { channels = [] } = incomingParams; - const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return `/v2/presence/sub-key/${config.subscribeKey}/channel/${utils.encodeString(stringifiedChannels)}/heartbeat`; -} - -export function isAuthSupported() { - return true; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function prepareParams(modules, incomingParams) { - const { channelGroups = [], state } = incomingParams; - const { config } = modules; - const params = {}; - - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - - if (state) { - params.state = JSON.stringify(state); - } - params.heartbeat = config.getPresenceTimeout(); - return params; -} - -export function handleResponse() { - return {}; -} diff --git a/src/core/endpoints/presence/heartbeat.ts b/src/core/endpoints/presence/heartbeat.ts new file mode 100644 index 000000000..80c26f1d3 --- /dev/null +++ b/src/core/endpoints/presence/heartbeat.ts @@ -0,0 +1,102 @@ +/** + * Announce heartbeat REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import * as Presence from '../../types/api/presence'; +import { KeySet, Query } from '../../types/api'; +import { encodeNames } from '../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Presence.PresenceHeartbeatParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Presence heartbeat announce human-readable result. + */ + message: string; + + /** + * Name of the service which provided response. + */ + service: string; +}; +// endregion + +export class HeartbeatRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNHeartbeatOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + channels = [], + channelGroups = [], + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (channels.length === 0 && channelGroups.length === 0) + return 'Please provide a list of channels and/or channel-groups'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return {}; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channels, + } = this.parameters; + + return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels ?? [], ',')}/heartbeat`; + } + + protected get queryParameters(): Query { + const { channelGroups, state, heartbeat } = this.parameters; + const query: Record = { heartbeat: `${heartbeat}` }; + + if (channelGroups && channelGroups.length !== 0) query['channel-group'] = channelGroups.join(','); + if (state) query.state = JSON.stringify(state); + + return query; + } +} diff --git a/src/core/endpoints/presence/here_now.js b/src/core/endpoints/presence/here_now.js deleted file mode 100644 index 53d707c1e..000000000 --- a/src/core/endpoints/presence/here_now.js +++ /dev/null @@ -1,133 +0,0 @@ -/* */ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNHereNowOperation; -} - -export function validateParams(modules) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { config } = modules; - const { channels = [], channelGroups = [] } = incomingParams; - let baseURL = `/v2/presence/sub-key/${config.subscribeKey}`; - - if (channels.length > 0 || channelGroups.length > 0) { - const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - baseURL += `/channel/${utils.encodeString(stringifiedChannels)}`; - } - - return baseURL; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { channelGroups = [], includeUUIDs = true, includeState = false, queryParameters = {} } = incomingParams; - let params = {}; - - if (!includeUUIDs) params.disable_uuids = 1; - if (includeState) params.state = 1; - - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - - params = { ...params, ...queryParameters }; - - return params; -} - -export function handleResponse(modules, serverResponse, incomingParams) { - const { channels = [], channelGroups = [], includeUUIDs = true, includeState = false } = incomingParams; - - const prepareSingularChannel = () => { - const response = {}; - const occupantsList = []; - response.totalChannels = 1; - response.totalOccupancy = serverResponse.occupancy; - response.channels = {}; - response.channels[channels[0]] = { - occupants: occupantsList, - name: channels[0], - occupancy: serverResponse.occupancy, - }; - - // We have had issues in the past with server returning responses - // that contain no uuids array - if (includeUUIDs && serverResponse.uuids) { - serverResponse.uuids.forEach((uuidEntry) => { - if (includeState) { - occupantsList.push({ state: uuidEntry.state, uuid: uuidEntry.uuid }); - } else { - occupantsList.push({ state: null, uuid: uuidEntry }); - } - }); - } - - return response; - }; - - const prepareMultipleChannel = () => { - const response = {}; - response.totalChannels = serverResponse.payload.total_channels; - response.totalOccupancy = serverResponse.payload.total_occupancy; - response.channels = {}; - - Object.keys(serverResponse.payload.channels).forEach((channelName) => { - const channelEntry = serverResponse.payload.channels[channelName]; - const occupantsList = []; - response.channels[channelName] = { - occupants: occupantsList, - name: channelName, - occupancy: channelEntry.occupancy, - }; - - if (includeUUIDs) { - channelEntry.uuids.forEach((uuidEntry) => { - if (includeState) { - occupantsList.push({ - state: uuidEntry.state, - uuid: uuidEntry.uuid, - }); - } else { - occupantsList.push({ state: null, uuid: uuidEntry }); - } - }); - } - - return response; - }); - - return response; - }; - - let response; - if (channels.length > 1 || channelGroups.length > 0 || (channelGroups.length === 0 && channels.length === 0)) { - response = prepareMultipleChannel(); - } else { - response = prepareSingularChannel(); - } - - return response; -} - -export function handleError(modules, params, status) { - if (status.statusCode === 402 && !this.getURL(modules, params).includes('channel')) { - status.errorData.message = - 'You have tried to perform a Global Here Now operation, ' + - 'your keyset configuration does not support that. Please provide a channel, ' + - 'or enable the Global Here Now feature from the Portal.'; - } -} diff --git a/src/core/endpoints/presence/here_now.ts b/src/core/endpoints/presence/here_now.ts new file mode 100644 index 000000000..79eaa7af3 --- /dev/null +++ b/src/core/endpoints/presence/here_now.ts @@ -0,0 +1,216 @@ +/** + * Channels / channel groups presence REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Payload, Query } from '../../types/api'; +import * as Presence from '../../types/api/presence'; +import { encodeNames } from '../../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether `uuid` should be included in response or not. + */ +const INCLUDE_UUID = true; + +/** + * Whether state associated with `uuid` should be included in response or not. + */ +const INCLUDE_STATE = false; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Presence.HereNowParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type BasicServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Here now human-readable result. + */ + message: string; + + /** + * Name of the service which provided response. + */ + service: string; +}; + +/** + * Single channel here now service response. + */ +type SingleChannelServiceResponse = BasicServiceResponse & { + /** + * List of received channel subscribers. + * + * **Note:** Field is missing if `uuid` and `state` not included. + */ + uuids?: (string | { uuid: string; state?: Payload })[]; + + /** + * Total number of active subscribers. + */ + occupancy: number; +}; + +/** + * Multiple channels / channel groups here now service response. + */ +type MultipleChannelServiceResponse = BasicServiceResponse & { + /** + * Retrieved channels' presence. + */ + payload: { + /** + * Total number of channels for which presence information received. + */ + total_channels: number; + + /** + * Total occupancy for all retrieved channels. + */ + total_occupancy: number; + + /** + * List of channels to which `uuid` currently subscribed. + */ + channels?: { + [p: string]: { + /** + * List of received channel subscribers. + * + * **Note:** Field is missing if `uuid` and `state` not included. + */ + uuids: (string | { uuid: string; state?: Payload })[]; + + /** + * Total number of active subscribers in single channel. + */ + occupancy: number; + }; + }; + }; +}; + +/** + * Here now REST API service success response. + */ +type ServiceResponse = SingleChannelServiceResponse | MultipleChannelServiceResponse; +// endregion + +export class HereNowRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply defaults. + this.parameters.queryParameters ??= {}; + this.parameters.includeUUIDs ??= INCLUDE_UUID; + this.parameters.includeState ??= INCLUDE_STATE; + } + + operation(): RequestOperation { + const { channels = [], channelGroups = [] } = this.parameters; + return channels.length === 0 && channelGroups.length === 0 + ? RequestOperation.PNGlobalHereNowOperation + : RequestOperation.PNHereNowOperation; + } + + validate(): string | undefined { + if (!this.parameters.keySet.subscribeKey) return 'Missing Subscribe Key'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + // Extract general presence information. + const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; + const totalOccupancy = + 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_channels; + const channelsPresence: Presence.HereNowResponse['channels'] = {}; + let channels: Required['channels'] = {}; + + // Remap single channel presence to multiple channels presence response. + if ('occupancy' in serviceResponse) { + const channel = this.parameters.channels![0]; + channels[channel] = { uuids: serviceResponse.uuids ?? [], occupancy: totalOccupancy }; + } else channels = serviceResponse.payload.channels ?? {}; + + Object.keys(channels).forEach((channel) => { + const channelEntry = channels[channel]; + channelsPresence[channel] = { + occupants: this.parameters.includeUUIDs! + ? channelEntry.uuids.map((uuid) => { + if (typeof uuid === 'string') return { uuid, state: null }; + return uuid; + }) + : [], + name: channel, + occupancy: channelEntry.occupancy, + }; + }); + + return { + totalChannels, + totalOccupancy, + channels: channelsPresence, + }; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channels, + channelGroups, + } = this.parameters; + let path = `/v2/presence/sub-key/${subscribeKey}`; + + if ((channels && channels.length > 0) || (channelGroups && channelGroups.length > 0)) + path += `/channel/${encodeNames(channels ?? [], ',')}`; + + return path; + } + + protected get queryParameters(): Query { + const { channelGroups, includeUUIDs, includeState, queryParameters } = this.parameters; + + return { + ...(!includeUUIDs! ? { disable_uuids: '1' } : {}), + ...(includeState ?? false ? { state: '1' } : {}), + ...(channelGroups && channelGroups.length > 0 ? { 'channel-group': channelGroups.join(',') } : {}), + ...queryParameters!, + }; + } +} diff --git a/src/core/endpoints/presence/leave.js b/src/core/endpoints/presence/leave.js deleted file mode 100644 index ed8962603..000000000 --- a/src/core/endpoints/presence/leave.js +++ /dev/null @@ -1,44 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNUnsubscribeOperation; -} - -export function validateParams(modules) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { config } = modules; - const { channels = [] } = incomingParams; - const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return `/v2/presence/sub-key/${config.subscribeKey}/channel/${utils.encodeString(stringifiedChannels)}/leave`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { channelGroups = [] } = incomingParams; - const params = {}; - - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - - return params; -} - -export function handleResponse() { - return {}; -} diff --git a/src/core/endpoints/presence/leave.ts b/src/core/endpoints/presence/leave.ts new file mode 100644 index 000000000..4dfb32194 --- /dev/null +++ b/src/core/endpoints/presence/leave.ts @@ -0,0 +1,108 @@ +/** + * Announce leave REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import * as Presence from '../../types/api/presence'; +import { KeySet, Query } from '../../types/api'; +import { encodeNames } from '../../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Presence.PresenceLeaveParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Leave presence human-readable result. + */ + message: string; + + /** + * Performed presence action. + */ + action: 'leave'; + + /** + * Name of the service which provided response. + */ + service: string; +}; +// endregion + +export class PresenceLeaveRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + if (this.parameters.channelGroups) + this.parameters.channelGroups = Array.from(new Set(this.parameters.channelGroups)); + if (this.parameters.channels) this.parameters.channels = Array.from(new Set(this.parameters.channels)); + } + + operation(): RequestOperation { + return RequestOperation.PNUnsubscribeOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + channels = [], + channelGroups = [], + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (channels.length === 0 && channelGroups.length === 0) + return 'At least one `channel` or `channel group` should be provided.'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return {}; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channels, + } = this.parameters; + + return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames(channels?.sort() ?? [], ',')}/leave`; + } + + protected get queryParameters(): Query { + const { channelGroups } = this.parameters; + if (!channelGroups || channelGroups.length === 0) return {}; + + return { 'channel-group': channelGroups.sort().join(',') }; + } +} diff --git a/src/core/endpoints/presence/set_state.js b/src/core/endpoints/presence/set_state.js deleted file mode 100644 index 53f419a5d..000000000 --- a/src/core/endpoints/presence/set_state.js +++ /dev/null @@ -1,50 +0,0 @@ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNSetStateOperation; -} - -export function validateParams(modules, incomingParams) { - const { config } = modules; - const { state, channels = [], channelGroups = [] } = incomingParams; - - if (!state) return 'Missing State'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; - if (channels.length === 0 && channelGroups.length === 0) { - return 'Please provide a list of channels and/or channel-groups'; - } -} - -export function getURL(modules, incomingParams) { - const { config } = modules; - const { channels = [] } = incomingParams; - const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return `/v2/presence/sub-key/${config.subscribeKey}/channel/${utils.encodeString( - stringifiedChannels, - )}/uuid/${utils.encodeString(config.UUID)}/data`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { state, channelGroups = [] } = incomingParams; - const params = {}; - - params.state = JSON.stringify(state); - - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - return params; -} - -export function handleResponse(modules, serverResponse) { - return { state: serverResponse.payload }; -} diff --git a/src/core/endpoints/presence/set_state.ts b/src/core/endpoints/presence/set_state.ts new file mode 100644 index 000000000..583ff2343 --- /dev/null +++ b/src/core/endpoints/presence/set_state.ts @@ -0,0 +1,119 @@ +/** + * Set Presence State REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Payload, Query } from '../../types/api'; +import { encodeNames, encodeString } from '../../utils'; +import * as Presence from '../../types/api/presence'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Presence.SetPresenceStateParameters & { + /** + * The subscriber uuid to associate state with. + */ + uuid: string; + + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Set presence state human-readable result. + */ + message: string; + + /** + * Name of the service which provided response. + */ + service: string; + + /** + * Associated presence state. + */ + payload: Payload; +}; +// endregion + +/** + * Set `uuid` presence state request. + */ +export class SetPresenceStateRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNSetStateOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + state, + channels = [], + channelGroups = [], + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!state) return 'Missing State'; + if (channels?.length === 0 && channelGroups?.length === 0) + return 'Please provide a list of channels and/or channel-groups'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + return { state: serviceResponse.payload }; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + uuid, + channels, + } = this.parameters; + return `/v2/presence/sub-key/${subscribeKey}/channel/${encodeNames( + channels ?? [], + ',', + )}/uuid/${encodeString(uuid)}/data`; + } + + protected get queryParameters(): Query { + const { channelGroups, state } = this.parameters; + const query: Query = { state: JSON.stringify(state) }; + + if (channelGroups && channelGroups.length !== 0) query['channel-group'] = channelGroups.join(','); + + return query; + } +} diff --git a/src/core/endpoints/presence/where_now.js b/src/core/endpoints/presence/where_now.js deleted file mode 100644 index bc6daeb93..000000000 --- a/src/core/endpoints/presence/where_now.js +++ /dev/null @@ -1,40 +0,0 @@ -/* */ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -export function getOperation() { - return operationConstants.PNWhereNowOperation; -} - -export function validateParams(modules) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { config } = modules; - const { uuid = config.UUID } = incomingParams; - return `/v2/presence/sub-key/${config.subscribeKey}/uuid/${utils.encodeString(uuid)}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams() { - return {}; -} - -export function handleResponse(modules, serverResponse) { - // This is a quick fix for when the server does not include a payload - // in where now responses - if (!serverResponse.payload) { - return { channels: [] }; - } - return { channels: serverResponse.payload.channels }; -} diff --git a/src/core/endpoints/presence/where_now.ts b/src/core/endpoints/presence/where_now.ts new file mode 100644 index 000000000..379b578a3 --- /dev/null +++ b/src/core/endpoints/presence/where_now.ts @@ -0,0 +1,95 @@ +/** + * `uuid` presence REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import * as Presence from '../../types/api/presence'; +import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Required & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = { + /** + * Request result status code. + */ + status: number; + + /** + * Where now human-readable result. + */ + message: string; + + /** + * Retrieved channels with `uuid` subscriber. + */ + payload?: { + /** + * List of channels to which `uuid` currently subscribed. + */ + channels: string[]; + }; + + /** + * Name of the service which provided response. + */ + service: string; +}; +// endregion + +export class WhereNowRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNWhereNowOperation; + } + + validate(): string | undefined { + if (!this.parameters.keySet.subscribeKey) return 'Missing Subscribe Key'; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + + if (!serviceResponse.payload) return { channels: [] }; + + return { channels: serviceResponse.payload.channels }; + } + protected get path(): string { + const { + keySet: { subscribeKey }, + uuid, + } = this.parameters; + + return `/v2/presence/sub-key/${subscribeKey}/uuid/${encodeString(uuid)}`; + } +} diff --git a/src/core/endpoints/publish.js b/src/core/endpoints/publish.js deleted file mode 100644 index 5fddd7d21..000000000 --- a/src/core/endpoints/publish.js +++ /dev/null @@ -1,91 +0,0 @@ -/* */ -import operationConstants from '../constants/operations'; -import utils from '../utils'; -import { encode } from '../components/base64_codec'; - -function prepareMessagePayload(modules, messagePayload) { - let stringifiedPayload = JSON.stringify(messagePayload); - - if (modules.cryptoModule) { - const encrypted = modules.cryptoModule.encrypt(stringifiedPayload); - stringifiedPayload = typeof encrypted === 'string' ? encrypted : encode(encrypted); - stringifiedPayload = JSON.stringify(stringifiedPayload); - } - return stringifiedPayload || ''; -} - -export function getOperation() { - return operationConstants.PNPublishOperation; -} - -export function validateParams({ config }, incomingParams) { - const { message, channel } = incomingParams; - - if (!channel) return 'Missing Channel'; - if (!message) return 'Missing Message'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function usePost(modules, incomingParams) { - const { sendByPost = false } = incomingParams; - return sendByPost; -} - -export function getURL(modules, incomingParams) { - const { config } = modules; - const { channel, message } = incomingParams; - const stringifiedPayload = prepareMessagePayload(modules, message); - return `/publish/${config.publishKey}/${config.subscribeKey}/0/${utils.encodeString(channel)}/0/${utils.encodeString( - stringifiedPayload, - )}`; -} - -export function postURL(modules, incomingParams) { - const { config } = modules; - const { channel } = incomingParams; - return `/publish/${config.publishKey}/${config.subscribeKey}/0/${utils.encodeString(channel)}/0`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function postPayload(modules, incomingParams) { - const { message } = incomingParams; - return prepareMessagePayload(modules, message); -} - -export function prepareParams(modules, incomingParams) { - const { meta, replicate = true, storeInHistory, ttl } = incomingParams; - const params = {}; - - if (storeInHistory != null) { - if (storeInHistory) { - params.store = '1'; - } else { - params.store = '0'; - } - } - - if (ttl) { - params.ttl = ttl; - } - - if (replicate === false) { - params.norep = 'true'; - } - - if (meta && typeof meta === 'object') { - params.meta = JSON.stringify(meta); - } - - return params; -} - -export function handleResponse(modules, serverResponse) { - return { timetoken: serverResponse[2] }; -} diff --git a/src/core/endpoints/publish.ts b/src/core/endpoints/publish.ts new file mode 100644 index 000000000..93f369c8b --- /dev/null +++ b/src/core/endpoints/publish.ts @@ -0,0 +1,220 @@ +/** + * Publish REST API module. + */ + +import { createValidationError, PubNubError } from '../../errors/pubnub-error'; +import { TransportResponse } from '../types/transport-response'; +import { TransportMethod } from '../types/transport-request'; +import { CryptoModule } from '../interfaces/crypto-module'; +import { AbstractRequest } from '../components/request'; +import RequestOperation from '../constants/operations'; +import { KeySet, Payload, Query } from '../types/api'; +import { encode } from '../components/base64_codec'; +import { encodeString } from '../utils'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether data is published used `POST` body or not. + */ +const SEND_BY_POST = false; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +export type PublishParameters = { + /** + * Channel name to publish messages to. + */ + channel: string; + + /** + * Data which should be sent to the `channel`. + * + * The message may be any valid JSON type including objects, arrays, strings, and numbers. + */ + message: Payload; + + /** + * Whether published data should be available with `Storage API` later or not. + * + * @default `true` + */ + storeInHistory?: boolean; + + /** + * Whether message should be sent as part of request POST body or not. + * + * @default `false` + */ + sendByPost?: boolean; + + /** + * Metadata, which should be associated with published data. + * + * Associated metadata can be utilized by message filtering feature. + */ + meta?: Payload; + + /** + * Specify duration during which data will be available with `Storage API`. + * + * - If `storeInHistory` = `true`, and `ttl` = `0`, the `message` is stored with no expiry time. + * - If `storeInHistory` = `true` and `ttl` = `X` (`X` is an Integer value), the `message` is + * stored with an expiry time of `X` hours. + * - If `storeInHistory` = `false`, the `ttl` parameter is ignored. + * - If `ttl` is not specified, then expiration of the `message` defaults back to the expiry value + * for the key. + */ + ttl?: number; + + /** + * Whether published data should be replicated across all data centers or not. + * + * @default `true` + * @deprecated + */ + replicate?: boolean; + + /** + * Indexed signature for deprecated parameters. + */ + [key: string]: string | number | boolean | undefined | Payload | CryptoModule; +}; + +/** + * Service success response. + */ +export type PublishResponse = { + /** + * High-precision time when published data has been received by the PubNub service. + */ + timetoken: string; +}; + +/** + * Request configuration parameters. + */ +type RequestParameters = PublishParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; + + /** + * Published data encryption module. + */ + crypto?: CryptoModule; +}; + +/** + * Service success response. + */ +type ServiceResponse = [0 | 1, string, string]; +// endregion + +/** + * Data publish request. + * + * Request will normalize and encrypt (if required) provided data and push it to the specified + * channel. + */ +export class PublishRequest extends AbstractRequest { + /** + * Construct data publish request. + * + * @param parameters - Request configuration. + */ + constructor(private readonly parameters: RequestParameters) { + super({ method: parameters.sendByPost ? TransportMethod.POST : TransportMethod.GET }); + + // Apply default request parameters. + this.parameters.sendByPost ??= SEND_BY_POST; + } + + operation(): RequestOperation { + return RequestOperation.PNPublishOperation; + } + + validate(): string | undefined { + const { + message, + channel, + keySet: { publishKey }, + } = this.parameters; + + if (!channel) return "Missing 'channel'"; + if (!message) return "Missing 'message'"; + if (!publishKey) return "Missing 'publishKey'"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + + return { timetoken: serviceResponse[2] }; + } + + protected get path(): string { + const { message, channel, keySet } = this.parameters; + const stringifiedPayload = this.prepareMessagePayload(message); + + return `/publish/${keySet.publishKey}/${keySet.subscribeKey}/0/${encodeString(channel)}/0${ + !this.parameters.sendByPost ? `/${encodeString(stringifiedPayload)}` : '' + }`; + } + + protected get queryParameters(): Query { + const { meta, replicate, storeInHistory, ttl } = this.parameters; + const query: Query = {}; + + if (storeInHistory !== undefined) query.store = storeInHistory ? '1' : '0'; + if (ttl !== undefined) query.ttl = ttl; + if (replicate !== undefined && !replicate) query.norep = 'true'; + if (meta && typeof meta === 'object') query.meta = JSON.stringify(meta); + + return query; + } + + protected get headers(): Record | undefined { + return { 'Content-Type': 'application/json' }; + } + + protected get body(): ArrayBuffer | string | undefined { + return this.prepareMessagePayload(this.parameters.message); + } + + /** + * Pre-process provided data. + * + * Data will be "normalized" and encrypted if `cryptoModule` has been provided. + * + * @param payload - User-provided data which should be pre-processed before use. + * + * @returns Payload which can be used as part of request URL or body. + * + * @throws {Error} in case if provided `payload` or results of `encryption` can't be stringified. + */ + private prepareMessagePayload(payload: Payload): string { + const { crypto } = this.parameters; + if (!crypto) return JSON.stringify(payload) || ''; + + const encrypted = crypto.encrypt(JSON.stringify(payload)); + + return JSON.stringify(typeof encrypted === 'string' ? encrypted : encode(encrypted)); + } +} diff --git a/src/core/endpoints/push/add_push_channels.js b/src/core/endpoints/push/add_push_channels.js deleted file mode 100644 index 759a8ce63..000000000 --- a/src/core/endpoints/push/add_push_channels.js +++ /dev/null @@ -1,53 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; - -export function getOperation() { - return operationConstants.PNPushNotificationEnabledChannelsOperation; -} - -export function validateParams(modules, incomingParams) { - const { device, pushGateway, channels, topic } = incomingParams; - const { config } = modules; - - if (!device) return 'Missing Device ID (device)'; - if (!pushGateway) return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) return 'Missing APNS2 topic'; - if (!channels || channels.length === 0) return 'Missing Channels'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { device, pushGateway } = incomingParams; - const { config } = modules; - - if (pushGateway === 'apns2') { - return `/v2/push/sub-key/${config.subscribeKey}/devices-apns2/${device}`; - } - - return `/v1/push/sub-key/${config.subscribeKey}/devices/${device}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { pushGateway, channels = [], environment = 'development', topic } = incomingParams; - let parameters = { type: pushGateway, add: channels.join(',') }; - - if (pushGateway === 'apns2') { - parameters = { ...parameters, environment, topic }; - delete parameters.type; - } - - return parameters; -} - -export function handleResponse() { - return {}; -} diff --git a/src/core/endpoints/push/add_push_channels.ts b/src/core/endpoints/push/add_push_channels.ts new file mode 100644 index 000000000..8692f4b50 --- /dev/null +++ b/src/core/endpoints/push/add_push_channels.ts @@ -0,0 +1,59 @@ +/** + * Register Channels with Device push REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { BasePushNotificationChannelsRequest } from './push'; +import RequestOperation from '../../constants/operations'; +import * as Push from '../../types/api/push'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Push.ManageDeviceChannelsParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = [0 | 1, string]; +// endregion + +/** + * Register channels with device push request. + */ +// prettier-ignore +export class AddDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest< + Push.ManageDeviceChannelsResponse +> { + constructor(parameters: RequestParameters) { + super({ ...parameters, action: 'add' }); + } + + operation(): RequestOperation { + return RequestOperation.PNAddPushNotificationEnabledChannelsOperation; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + + return {}; + } +} diff --git a/src/core/endpoints/push/list_push_channels.js b/src/core/endpoints/push/list_push_channels.js deleted file mode 100644 index 2241407d7..000000000 --- a/src/core/endpoints/push/list_push_channels.js +++ /dev/null @@ -1,54 +0,0 @@ -/* */ -import operationConstants from '../../constants/operations'; - -export function getOperation() { - return operationConstants.PNPushNotificationEnabledChannelsOperation; -} - -export function validateParams(modules, incomingParams) { - const { device, pushGateway, topic } = incomingParams; - const { config } = modules; - - if (!device) return 'Missing Device ID (device)'; - if (!pushGateway) return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) return 'Missing APNS2 topic'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { device, pushGateway } = incomingParams; - const { config } = modules; - - if (pushGateway === 'apns2') { - return `/v2/push/sub-key/${config.subscribeKey}/devices-apns2/${device}`; - } - - return `/v1/push/sub-key/${config.subscribeKey}/devices/${device}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { pushGateway, environment = 'development', topic, start, count } = incomingParams; - let parameters = { type: pushGateway }; - - if (pushGateway === 'apns2') { - parameters = { ...parameters, environment, topic }; - delete parameters.type; - } - - if (start) parameters.start = start; - if (count && count > 0) parameters.count = count; - - return parameters; -} - -export function handleResponse(modules, serverResponse) { - return { channels: serverResponse }; -} diff --git a/src/core/endpoints/push/list_push_channels.ts b/src/core/endpoints/push/list_push_channels.ts new file mode 100644 index 000000000..725bbbefc --- /dev/null +++ b/src/core/endpoints/push/list_push_channels.ts @@ -0,0 +1,59 @@ +/** + * List Device push enabled channels REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { BasePushNotificationChannelsRequest } from './push'; +import RequestOperation from '../../constants/operations'; +import * as Push from '../../types/api/push'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Push.ListDeviceChannelsParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = string[]; +// endregion + +/** + * List device push enabled channels request. + */ +// prettier-ignore +export class ListDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest< + Push.ListDeviceChannelsResponse +> { + constructor(parameters: RequestParameters) { + super({ ...parameters, action: 'list' }); + } + + operation(): RequestOperation { + return RequestOperation.PNPushNotificationEnabledChannelsOperation; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + + return { channels: serviceResponse }; + } +} diff --git a/src/core/endpoints/push/push.ts b/src/core/endpoints/push/push.ts new file mode 100644 index 000000000..20e231d62 --- /dev/null +++ b/src/core/endpoints/push/push.ts @@ -0,0 +1,121 @@ +/** + * Manage channels enabled for device push REST API module. + */ + +import { TransportResponse } from '../../types/transport-response'; +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import { KeySet, Query } from '../../types/api'; +import * as Push from '../../types/api/push'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Environment for which APNS2 notifications + */ +const ENVIRONMENT = 'development'; + +/** + * Maximum number of channels in `list` response. + */ +const MAX_COUNT = 1000; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = (Push.ManageDeviceChannelsParameters | Push.RemoveDeviceParameters) & { + /** + * Action which should be performed. + */ + action: 'add' | 'remove' | 'remove-device' | 'list'; + + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; +// endregion + +/** + * Base push notification request. + */ +export class BasePushNotificationChannelsRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + + // Apply request defaults + if (this.parameters.pushGateway === 'apns2') this.parameters.environment ??= ENVIRONMENT; + if (this.parameters.count && this.parameters.count > MAX_COUNT) this.parameters.count = MAX_COUNT; + } + + operation(): RequestOperation { + throw Error('Should be implemented in subclass.'); + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + action, + device, + pushGateway, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!device) return 'Missing Device ID (device)'; + if ( + (action === 'add' || action === 'remove') && + (!('channels' in this.parameters) || this.parameters.channels.length === 0) + ) + return 'Missing Channels'; + + if (!pushGateway) return 'Missing GW Type (pushGateway: gcm or apns2)'; + if (this.parameters.pushGateway === 'apns2' && !this.parameters.topic) return 'Missing APNS2 topic'; + } + + async parse(_response: TransportResponse): Promise { + throw Error('Should be implemented in subclass.'); + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + action, + device, + pushGateway, + } = this.parameters; + + let path = + pushGateway === 'apns2' + ? `/v2/push/sub-key/${subscribeKey}/devices-apns2/${device}` + : `/v1/push/sub-key/${subscribeKey}/devices/${device}`; + if (action === 'remove-device') path = `${path}/remove`; + + return path; + } + + protected get queryParameters(): Query { + const { start, count } = this.parameters; + let query: Query = { + type: this.parameters.pushGateway, + ...(start ? { start } : {}), + ...(count && count > 0 ? { count } : {}), + }; + + if ('channels' in this.parameters) query[this.parameters.action] = this.parameters.channels.join(','); + if (this.parameters.pushGateway === 'apns2') { + const { environment, topic } = this.parameters; + query = { ...query, environment: environment!, topic }; + } + + return query; + } +} diff --git a/src/core/endpoints/push/remove_device.js b/src/core/endpoints/push/remove_device.js deleted file mode 100644 index 1f1d350fb..000000000 --- a/src/core/endpoints/push/remove_device.js +++ /dev/null @@ -1,52 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; - -export function getOperation() { - return operationConstants.PNRemoveAllPushNotificationsOperation; -} - -export function validateParams(modules, incomingParams) { - const { device, pushGateway, topic } = incomingParams; - const { config } = modules; - - if (!device) return 'Missing Device ID (device)'; - if (!pushGateway) return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) return 'Missing APNS2 topic'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { device, pushGateway } = incomingParams; - const { config } = modules; - - if (pushGateway === 'apns2') { - return `/v2/push/sub-key/${config.subscribeKey}/devices-apns2/${device}/remove`; - } - - return `/v1/push/sub-key/${config.subscribeKey}/devices/${device}/remove`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { pushGateway, environment = 'development', topic } = incomingParams; - let parameters = { type: pushGateway }; - - if (pushGateway === 'apns2') { - parameters = { ...parameters, environment, topic }; - delete parameters.type; - } - - return parameters; -} - -export function handleResponse() { - return {}; -} diff --git a/src/core/endpoints/push/remove_device.ts b/src/core/endpoints/push/remove_device.ts new file mode 100644 index 000000000..5fd4235f3 --- /dev/null +++ b/src/core/endpoints/push/remove_device.ts @@ -0,0 +1,59 @@ +/** + * Unregister Device push REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { BasePushNotificationChannelsRequest } from './push'; +import RequestOperation from '../../constants/operations'; +import * as Push from '../../types/api/push'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Push.RemoveDeviceParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = [0 | 1, string]; +// endregion + +/** + * Unregister device push notifications request. + */ +// prettier-ignore +export class RemoveDevicePushNotificationRequest extends BasePushNotificationChannelsRequest< + Push.RemoveDeviceResponse +> { + constructor(parameters: RequestParameters) { + super({ ...parameters, action: 'remove-device' }); + } + + operation(): RequestOperation { + return RequestOperation.PNRemoveAllPushNotificationsOperation; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + + return {}; + } +} diff --git a/src/core/endpoints/push/remove_push_channels.js b/src/core/endpoints/push/remove_push_channels.js deleted file mode 100644 index 16cc9bcfd..000000000 --- a/src/core/endpoints/push/remove_push_channels.js +++ /dev/null @@ -1,53 +0,0 @@ -/* */ - -import operationConstants from '../../constants/operations'; - -export function getOperation() { - return operationConstants.PNPushNotificationEnabledChannelsOperation; -} - -export function validateParams(modules, incomingParams) { - const { device, pushGateway, channels, topic } = incomingParams; - const { config } = modules; - - if (!device) return 'Missing Device ID (device)'; - if (!pushGateway) return 'Missing GW Type (pushGateway: gcm, apns or apns2)'; - if (pushGateway === 'apns2' && !topic) return 'Missing APNS2 topic'; - if (!channels || channels.length === 0) return 'Missing Channels'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { device, pushGateway } = incomingParams; - const { config } = modules; - - if (pushGateway === 'apns2') { - return `/v2/push/sub-key/${config.subscribeKey}/devices-apns2/${device}`; - } - - return `/v1/push/sub-key/${config.subscribeKey}/devices/${device}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams(modules, incomingParams) { - const { pushGateway, channels = [], environment = 'development', topic } = incomingParams; - let parameters = { type: pushGateway, remove: channels.join(',') }; - - if (pushGateway === 'apns2') { - parameters = { ...parameters, environment, topic }; - delete parameters.type; - } - - return parameters; -} - -export function handleResponse() { - return {}; -} diff --git a/src/core/endpoints/push/remove_push_channels.ts b/src/core/endpoints/push/remove_push_channels.ts new file mode 100644 index 000000000..69a939045 --- /dev/null +++ b/src/core/endpoints/push/remove_push_channels.ts @@ -0,0 +1,59 @@ +/** + * Unregister Channels from Device push REST API module. + */ + +import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; +import { TransportResponse } from '../../types/transport-response'; +import { BasePushNotificationChannelsRequest } from './push'; +import RequestOperation from '../../constants/operations'; +import * as Push from '../../types/api/push'; +import { KeySet } from '../../types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +type RequestParameters = Push.ManageDeviceChannelsParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = [0 | 1, string]; +// endregion + +/** + * Unregister channels from device push request. + */ +// prettier-ignore +export class RemoveDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest< + Push.ManageDeviceChannelsResponse +> { + constructor(parameters: RequestParameters) { + super({ ...parameters, action: 'remove' }); + } + + operation(): RequestOperation { + return RequestOperation.PNRemovePushNotificationEnabledChannelsOperation; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + + return {}; + } +} diff --git a/src/core/endpoints/signal.js b/src/core/endpoints/signal.js deleted file mode 100644 index ff7aa4802..000000000 --- a/src/core/endpoints/signal.js +++ /dev/null @@ -1,49 +0,0 @@ -/* */ - -import operationConstants from '../constants/operations'; -import utils from '../utils'; - -function prepareMessagePayload(modules, messagePayload) { - const stringifiedPayload = JSON.stringify(messagePayload); - - return stringifiedPayload; -} - -export function getOperation() { - return operationConstants.PNSignalOperation; -} - -export function validateParams({ config }, incomingParams) { - const { message, channel } = incomingParams; - - if (!channel) return 'Missing Channel'; - if (!message) return 'Missing Message'; - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { config } = modules; - const { channel, message } = incomingParams; - const stringifiedPayload = prepareMessagePayload(modules, message); - return `/signal/${config.publishKey}/${config.subscribeKey}/0/${utils.encodeString(channel)}/0/${utils.encodeString( - stringifiedPayload, - )}`; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams() { - const params = {}; - - return params; -} - -export function handleResponse(modules, serverResponse) { - return { timetoken: serverResponse[2] }; -} diff --git a/src/core/endpoints/signal.ts b/src/core/endpoints/signal.ts new file mode 100644 index 000000000..b17379d89 --- /dev/null +++ b/src/core/endpoints/signal.ts @@ -0,0 +1,103 @@ +/** + * Signal REST API module. + */ + +import { createValidationError, PubNubError } from '../../errors/pubnub-error'; +import { TransportResponse } from '../types/transport-response'; +import { AbstractRequest } from '../components/request'; +import RequestOperation from '../constants/operations'; +import { KeySet, Payload } from '../types/api'; +import { encodeString } from '../utils'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Request configuration parameters. + */ +export type SignalParameters = { + /** + * Channel name to publish signal to. + */ + channel: string; + + /** + * Data which should be sent to the `channel`. + * + * The message may be any valid JSON type including objects, arrays, strings, and numbers. + */ + message: Payload; +}; + +/** + * Service success response. + */ +export type SignalResponse = { + /** + * High-precision time when published data has been received by the PubNub service. + */ + timetoken: string; +}; + +/** + * Request configuration parameters. + */ +type RequestParameters = SignalParameters & { + /** + * PubNub REST API access key set. + */ + keySet: KeySet; +}; + +/** + * Service success response. + */ +type ServiceResponse = [0 | 1, string, string]; +// endregion + +export class SignalRequest extends AbstractRequest { + constructor(private readonly parameters: RequestParameters) { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNSignalOperation; + } + + validate(): string | undefined { + const { + message, + channel, + keySet: { publishKey }, + } = this.parameters; + + if (!channel) return "Missing 'channel'"; + if (!message) return "Missing 'message'"; + if (!publishKey) return "Missing 'publishKey'"; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + + return { timetoken: serviceResponse[2] }; + } + + protected get path(): string { + const { + keySet: { publishKey, subscribeKey }, + channel, + message, + } = this.parameters; + const stringifiedPayload = JSON.stringify(message); + + return `/signal/${publishKey}/${subscribeKey}/0/${encodeString(channel)}/0/${encodeString(stringifiedPayload)}`; + } +} diff --git a/src/core/endpoints/subscribe.js b/src/core/endpoints/subscribe.js deleted file mode 100644 index 8058b094e..000000000 --- a/src/core/endpoints/subscribe.js +++ /dev/null @@ -1,89 +0,0 @@ -/* */ -import operationConstants from '../constants/operations'; -import utils from '../utils'; - -export function getOperation() { - return operationConstants.PNSubscribeOperation; -} - -export function validateParams(modules) { - const { config } = modules; - - if (!config.subscribeKey) return 'Missing Subscribe Key'; -} - -export function getURL(modules, incomingParams) { - const { config } = modules; - const { channels = [] } = incomingParams; - const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return `/v2/subscribe/${config.subscribeKey}/${utils.encodeString(stringifiedChannels)}/0`; -} - -export function getRequestTimeout({ config }) { - return config.getSubscribeTimeout(); -} - -export function isAuthSupported() { - return true; -} - -export function prepareParams({ config }, incomingParams) { - const { state, channelGroups = [], timetoken, filterExpression, region } = incomingParams; - const params = { - heartbeat: config.getPresenceTimeout(), - }; - - if (channelGroups.length > 0) { - params['channel-group'] = channelGroups.join(','); - } - - if (filterExpression && filterExpression.length > 0) { - params['filter-expr'] = filterExpression; - } - - if (Object.keys(state).length) { - params.state = JSON.stringify(state); - } - - if (timetoken) { - params.tt = timetoken; - } - - if (region) { - params.tr = region; - } - - return params; -} - -export function handleResponse(modules, serverResponse) { - const messages = []; - - serverResponse.m.forEach((rawMessage) => { - const publishMetaData = { - timetoken: rawMessage.p.t, - region: rawMessage.p.r, - }; - const parsedMessage = { - shard: parseInt(rawMessage.a, 10), - subscriptionMatch: rawMessage.b, - channel: rawMessage.c, - messageType: rawMessage.e, - payload: rawMessage.d, - flags: rawMessage.f, - issuingClientId: rawMessage.i, - subscribeKey: rawMessage.k, - originationTimetoken: rawMessage.o, - userMetadata: rawMessage.u, - publishMetaData, - }; - messages.push(parsedMessage); - }); - - const metadata = { - timetoken: serverResponse.t.t, - region: serverResponse.t.r, - }; - - return { messages, metadata }; -} diff --git a/src/core/endpoints/subscribe.ts b/src/core/endpoints/subscribe.ts new file mode 100644 index 000000000..d31302ce5 --- /dev/null +++ b/src/core/endpoints/subscribe.ts @@ -0,0 +1,870 @@ +/** + * Subscription REST API module. + */ + +import { createValidationError, PubNubError } from '../../errors/pubnub-error'; +import { TransportResponse } from '../types/transport-response'; +import { CryptoModule } from '../interfaces/crypto-module'; +import * as Subscription from '../types/api/subscription'; +import { AbstractRequest } from '../components/request'; +import * as FileSharing from '../types/api/file-sharing'; +import RequestOperation from '../constants/operations'; +import * as AppContext from '../types/api/app-context'; +import { KeySet, Payload, Query } from '../types/api'; +import { encodeNames } from '../utils'; + +// -------------------------------------------------------- +// ---------------------- Defaults ------------------------ +// -------------------------------------------------------- +// region Defaults + +/** + * Whether should subscribe to channels / groups presence announcements or not. + */ +const WITH_PRESENCE = false; + +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * PubNub-defined event types by payload. + */ +export enum PubNubEventType { + /** + * Presence change event. + */ + Presence = -2, + + /** + * Regular message event. + * + * **Note:** This is default type assigned for non-presence events if `e` field is missing. + */ + Message = -1, + + /** + * Signal data event. + */ + Signal = 1, + + /** + * App Context object event. + */ + AppContext, + + /** + * Message reaction event. + */ + MessageAction, + + /** + * Files event. + */ + Files, +} + +/** + * Time cursor. + * + * Cursor used by subscription loop to identify point in time after which updates will be + * delivered. + */ +type SubscriptionCursor = { + /** + * PubNub high-precision timestamp. + * + * Aside of specifying exact time of receiving data / event this token used to catchup / + * follow on real-time updates. + */ + t: string; + + /** + * Data center region for which `timetoken` has been generated. + */ + r: number; +}; + +// endregion + +// region Presence service response +/** + * Periodical presence change service response. + */ +type PresenceIntervalData = { + /** + * Periodical subscribed channels and groups presence change announcement. + */ + action: 'interval'; + + /** + * Unix timestamp when presence event has been triggered. + */ + timestamp: number; + + /** + * The current occupancy after the presence change is updated. + */ + occupancy: number; + + /** + * The list of unique user identifiers that `joined` the channel since the last interval + * presence update. + */ + join?: string[]; + + /** + * The list of unique user identifiers that `left` the channel since the last interval + * presence update. + */ + leave?: string[]; + + /** + * The list of unique user identifiers that `timeout` the channel since the last interval + * presence update. + */ + timeout?: string[]; +}; + +/** + * Subscribed user presence information change service response. + */ +type PresenceChangeData = { + /** + * Change if user's presence. + * + * User's presence may change between: `join`, `leave` and `timeout`. + */ + action: 'join' | 'leave' | 'timeout'; + + /** + * Unix timestamp when presence event has been triggered. + */ + timestamp: number; + + /** + * Unique identification of the user for whom presence information changed. + */ + uuid: string; + + /** + * The current occupancy after the presence change is updated. + */ + occupancy: number; + + /** + * The user's state associated with the channel has been updated. + * + * @deprecated Use set state methods to specify associated user's data instead of passing to + * subscribe. + */ + data?: { [p: string]: Payload }; +}; + +/** + * Associated user presence state change service response. + */ +type PresenceStateChangeData = { + /** + * Subscribed user associated presence state change. + */ + action: 'state-change'; + + /** + * Unix timestamp when presence event has been triggered. + */ + timestamp: number; + + /** + * Unique identification of the user for whom associated presence state has been changed. + */ + uuid: string; + + /** + * The user's state associated with the channel has been updated. + */ + state: { [p: string]: Payload }; +}; + +/** + * Channel presence service response. + */ +export type PresenceData = PresenceIntervalData | PresenceChangeData | PresenceStateChangeData; +// endregion + +// region Message Actions service response +/** + * Message reaction change service response. + */ +export type MessageActionData = { + /** + * The type of event that happened during the message action update. + * + * Possible values are: + * - `added` - action has been added to the message + * - `removed` - action has been removed from message + */ + event: 'added' | 'removed'; + + /** + * Information about message action for which update has been generated. + */ + data: { + /** + * Timetoken of message for which action has been added / removed. + */ + messageTimetoken: string; + + /** + * Timetoken of message action which has been added / removed. + */ + actionTimetoken: string; + + /** + * Message action type. + */ + type: string; + + /** + * Value associated with message action {@link type}. + */ + value: string; + }; + + /** + * Name of service which generated update for message action. + */ + source: string; + + /** + * Version of service which generated update for message action. + */ + version: string; +}; +// endregion + +// region App Context service data +/** + * VSP Objects change events. + */ +type AppContextVSPEvents = 'updated' | 'removed'; + +/** + * App Context Objects change events. + */ +type AppContextEvents = 'set' | 'delete'; + +/** + * Common real-time App Context Object service response. + */ +type ObjectData = { + /** + * The type of event that happened during the object update. + */ + event: Event; + + /** + * App Context object type. + */ + type: Type; + + /** + * App Context object information. + * + * App Context object can be one of: + * - `channel` / `space` + * - `uuid` / `user` + * - `membership` + */ + data: AppContextObject; + + /** + * Name of service which generated update for object. + */ + source: string; + + /** + * Version of service which generated update for object. + */ + version: string; +}; + +/** + * `Channel` object change real-time service response. + */ +type ChannelObjectData = ObjectData< + AppContextEvents, + 'channel', + AppContext.ChannelMetadataObject +>; + +/** + * `Space` object change real-time service response. + */ +export type SpaceObjectData = ObjectData< + AppContextVSPEvents, + 'space', + AppContext.ChannelMetadataObject +>; + +/** + * `Uuid` object change real-time service response. + */ +type UuidObjectData = ObjectData>; + +/** + * `User` object change real-time service response. + */ +export type UserObjectData = ObjectData< + AppContextVSPEvents, + 'user', + AppContext.UUIDMetadataObject +>; + +/** + * `Membership` object change real-time service response. + */ +type MembershipObjectData = ObjectData< + AppContextEvents, + 'membership', + Omit, 'id'> & { + /** + * `Uuid` object which has been used to create relationship with `channel`. + */ + uuid: { + /** + * Unique `user` object identifier. + */ + id: string; + }; + + /** + * `Channel` object which has been used to create relationship with `uuid`. + */ + channel: { + /** + * Unique `channel` object identifier. + */ + id: string; + }; + } +>; + +/** + * VSP `Membership` object change real-time service response. + */ +export type VSPMembershipObjectData = ObjectData< + AppContextVSPEvents, + 'membership', + Omit, 'id'> & { + /** + * `User` object which has been used to create relationship with `space`. + */ + user: { + /** + * Unique `user` object identifier. + */ + id: string; + }; + + /** + * `Space` object which has been used to create relationship with `user`. + */ + space: { + /** + * Unique `channel` object identifier. + */ + id: string; + }; + } +>; + +/** + * App Context service response. + */ +export type AppContextObjectData = ChannelObjectData | UuidObjectData | MembershipObjectData; +// endregion + +// region File service response +/** + * File service response. + */ +export type FileData = { + /** + * Message which has been associated with uploaded file. + */ + message?: Payload; + + /** + * Information about uploaded file. + */ + file: { + /** + * Unique identifier of uploaded file. + */ + id: string; + + /** + * Actual name with which file has been stored. + */ + name: string; + }; +}; +// endregion + +/** + * Service response data envelope. + * + * Each entry from `m` list wrapped into this object. + */ +type Envelope = { + /** + * Shard number on which the event has been stored. + */ + a: string; + + /** + * A numeric representation of enabled debug flags. + */ + f: number; + + /** + * PubNub defined event type. + */ + e?: PubNubEventType; + + /** + * Identifier of client which sent message (set only when Publish REST API endpoint called with + * `uuid`). + */ + i?: string; + + /** + * Sequence number (set only when Publish REST API endpoint called with `seqn`). + */ + s?: number; + + /** + * Event "publish" time. + * + * This is the time when message has been received by {@link https://www.pubnub.com|PubNub} network. + */ + p: SubscriptionCursor; + + /** + * User-defined (local) "publish" time. + */ + o?: SubscriptionCursor; + + /** + * Name of channel where update received. + */ + c: string; + + /** + * Event payload. + * + * **Note:** One more type not mentioned here to keep type system working ({@link Payload}). + */ + d: PresenceData | MessageActionData | AppContextObjectData | FileData | string; + + /** + * Actual name of subscription through which event has been delivered. + * + * PubNub client can be used to subscribe to the group of channels to receive updates and + * (group name will be set for field). With this approach there will be no need to separately + * add *N* number of channels to `subscribe` method call. + */ + b?: string; + + /** + * User-provided metadata during `publish` method usage. + */ + u?: { [p: string]: Payload }; + + /** + * User provided message type (set only when `publish` called with `type`). + */ + mt?: string; + + /** + * Identifier of space into which message has been published (set only when `publish` called + * with `space_id`). + */ + si?: string; +}; + +/** + * Subscribe REST API service success response. + */ +type ServiceResponse = { + /** + * Next subscription cursor. + * + * The cursor contains information about the start of the next real-time update timeframe. + */ + t: SubscriptionCursor; + + /** + * List of updates. + * + * Contains list of real-time updates received using previous subscription cursor. + */ + m: Envelope[]; +}; + +/** + * Request configuration parameters. + */ +export type RequestParameters = Subscription.SubscribeParameters & { + /** + * Timetoken's region identifier. + */ + region?: number; + + /** + * Subscriber `userId` presence timeout. + * + * For how long (in seconds) user will be `online` without sending any new subscribe or + * heartbeat requests. + */ + heartbeat?: number; + + /** + * Real-time events filtering expression. + */ + filterExpression?: string | null; + + /** + * PubNub REST API access key set. + */ + keySet: KeySet; + + /** + * Received data decryption module. + */ + crypto?: CryptoModule; + + /** + * File download Url generation function. + * + * @param id - Unique identifier of the file which should be downloaded. + * @param name - Name with which file has been stored. + * @param channel - Name of the channel from which file should be downloaded. + */ + getFileUrl: (parameters: FileSharing.FileUrlParameters) => string; +}; +// endregion + +/** + * Base subscription request implementation. + * + * Subscription request used in small variations in two cases: + * - subscription manager + * - event engine + */ +export class BaseSubscribeRequest extends AbstractRequest { + constructor(protected readonly parameters: RequestParameters) { + super({ cancellable: true }); + + // Apply default request parameters. + this.parameters.withPresence ??= WITH_PRESENCE; + this.parameters.channelGroups ??= []; + this.parameters.channels ??= []; + } + + operation(): RequestOperation { + return RequestOperation.PNSubscribeOperation; + } + + validate(): string | undefined { + const { + keySet: { subscribeKey }, + channels, + channelGroups, + } = this.parameters; + + if (!subscribeKey) return 'Missing Subscribe Key'; + if (!channels && !channelGroups) return '`channels` and `channelGroups` both should not be empty'; + } + + async parse(response: TransportResponse): Promise { + let serviceResponse: ServiceResponse | undefined; + + try { + const json = AbstractRequest.decoder.decode(response.body); + const parsedJson = JSON.parse(json); + serviceResponse = parsedJson as ServiceResponse; + } catch (error) { + console.error('Error parsing JSON response:', error); + } + + if (!serviceResponse) { + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + } + + const events: Subscription.SubscriptionResponse['messages'] = serviceResponse.m.map((envelope) => { + let { e: eventType } = envelope; + + // Resolve missing event type. + eventType ??= envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message; + + // Check whether payload is string (potentially encrypted data). + if (typeof envelope.d === 'string') { + if (eventType == PubNubEventType.Message) { + return { + type: PubNubEventType.Message, + data: this.messageFromEnvelope(envelope), + }; + } + + return { + type: PubNubEventType.Files, + data: this.fileFromEnvelope(envelope), + }; + } else if (eventType == PubNubEventType.Message) { + return { + type: PubNubEventType.Message, + data: this.messageFromEnvelope(envelope), + }; + } else if (eventType === PubNubEventType.Presence) { + return { + type: PubNubEventType.Presence, + data: this.presenceEventFromEnvelope(envelope), + }; + } else if (eventType == PubNubEventType.Signal) { + return { + type: PubNubEventType.Signal, + data: this.signalFromEnvelope(envelope), + }; + } else if (eventType === PubNubEventType.AppContext) { + return { + type: PubNubEventType.AppContext, + data: this.appContextFromEnvelope(envelope), + }; + } else if (eventType === PubNubEventType.MessageAction) { + return { + type: PubNubEventType.MessageAction, + data: this.messageActionFromEnvelope(envelope), + }; + } + + return { + type: PubNubEventType.Files, + data: this.fileFromEnvelope(envelope), + }; + }); + + return { + cursor: { timetoken: serviceResponse.t.t, region: serviceResponse.t.r }, + messages: events, + }; + } + + protected get headers(): Record | undefined { + return { accept: 'text/javascript' }; + } + + // -------------------------------------------------------- + // ------------------ Envelope parsing -------------------- + // -------------------------------------------------------- + // region Envelope parsing + + private presenceEventFromEnvelope(envelope: Envelope): Subscription.Presence { + const { d: payload } = envelope; + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + + // Clean up channel and subscription name from presence suffix. + const trimmedChannel = channel.replace('-pnpres', ''); + + // Backward compatibility with deprecated properties. + const actualChannel = subscription !== null ? trimmedChannel : null; + const subscribedChannel = subscription !== null ? subscription : trimmedChannel; + + if (typeof payload !== 'string' && 'data' in payload) { + // @ts-expect-error This is `state-change` object which should have `state` field. + payload['state'] = payload.data; + delete payload.data; + } + + return { + channel: trimmedChannel, + subscription, + actualChannel, + subscribedChannel, + timetoken: envelope.p.t, + ...(payload as PresenceData), + }; + } + + private messageFromEnvelope(envelope: Envelope): Subscription.Message { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const [message, decryptionError] = this.decryptedData(envelope.d); + + // Backward compatibility with deprecated properties. + const actualChannel = subscription !== null ? channel : null; + const subscribedChannel = subscription !== null ? subscription : channel; + + // Basic message event payload. + const event: Subscription.Message = { + channel, + subscription, + actualChannel, + subscribedChannel, + timetoken: envelope.p.t, + publisher: envelope.i, + message, + }; + + if (envelope.u) event.userMetadata = envelope.u; + if (decryptionError) event.error = decryptionError; + + return event; + } + + private signalFromEnvelope(envelope: Envelope): Subscription.Signal { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + + const event: Subscription.Signal = { + channel, + subscription, + timetoken: envelope.p.t, + publisher: envelope.i, + message: envelope.d, + }; + + if (envelope.u) event.userMetadata = envelope.u; + + return event; + } + + private messageActionFromEnvelope(envelope: Envelope): Subscription.MessageAction { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const action = envelope.d as MessageActionData; + + return { + channel, + subscription, + timetoken: envelope.p.t, + publisher: envelope.i, + event: action.event, + data: { + ...action.data, + uuid: envelope.i!, + }, + }; + } + + private appContextFromEnvelope(envelope: Envelope): Subscription.AppContextObject { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const object = envelope.d as AppContextObjectData; + + return { + channel, + subscription, + timetoken: envelope.p.t, + message: object, + }; + } + + private fileFromEnvelope(envelope: Envelope): Subscription.File { + const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + const [file, decryptionError] = this.decryptedData(envelope.d); + let errorMessage = decryptionError; + + // Basic file event payload. + const event: Subscription.File = { + channel, + subscription, + timetoken: envelope.p.t, + publisher: envelope.i, + }; + + if (envelope.u) event.userMetadata = envelope.u; + if (!file) errorMessage ??= `File information payload is missing.`; + else if (typeof file === 'string') errorMessage ??= `Unexpected file information payload data type.`; + else { + event.message = file.message; + if (file.file) { + event.file = { + id: file.file.id, + name: file.file.name, + url: this.parameters.getFileUrl({ id: file.file.id, name: file.file.name, channel }), + }; + } + } + + if (errorMessage) event.error = errorMessage; + + return event; + } + // endregion + + private subscriptionChannelFromEnvelope(envelope: Envelope): [string, string | null] { + return [envelope.c, envelope.b === undefined ? envelope.c : envelope.b]; + } + + /** + * Decrypt provided `data`. + * + * @param [data] - Message or file information which should be decrypted if possible. + * + * @returns Tuple with decrypted data and decryption error (if any). + */ + private decryptedData(data: Payload): [T, string | undefined] { + if (!this.parameters.crypto || typeof data !== 'string') return [data as T, undefined]; + + let payload: Payload | null; + let error: string | undefined; + + try { + const decryptedData = this.parameters.crypto.decrypt(data); + payload = + decryptedData instanceof ArrayBuffer + ? JSON.parse(SubscribeRequest.decoder.decode(decryptedData)) + : decryptedData; + } catch (err) { + payload = null; + error = `Error while decrypting message content: ${(err as Error).message}`; + } + + return [(payload ?? data) as T, error]; + } +} + +/** + * Subscribe request. + */ +export class SubscribeRequest extends BaseSubscribeRequest { + protected get path(): string { + const { + keySet: { subscribeKey }, + channels, + } = this.parameters; + + return `/v2/subscribe/${subscribeKey}/${encodeNames(channels?.sort() ?? [], ',')}/0`; + } + + protected get queryParameters(): Query { + const { channelGroups, filterExpression, heartbeat, state, timetoken, region } = this.parameters; + const query: Query = {}; + + if (channelGroups && channelGroups.length > 0) query['channel-group'] = channelGroups.sort().join(','); + if (filterExpression && filterExpression.length > 0) query['filter-expr'] = filterExpression; + if (heartbeat) query.heartbeat = heartbeat; + if (state && Object.keys(state).length > 0) query['state'] = JSON.stringify(state); + if (timetoken !== undefined && typeof timetoken === 'string') { + if (timetoken.length > 0 && timetoken !== '0') query['tt'] = timetoken; + } else if (timetoken !== undefined && timetoken > 0) query['tt'] = timetoken; + + if (region) query['tr'] = region; + + return query; + } +} diff --git a/src/core/endpoints/subscriptionUtils/handshake.js b/src/core/endpoints/subscriptionUtils/handshake.js deleted file mode 100644 index 68487c68d..000000000 --- a/src/core/endpoints/subscriptionUtils/handshake.js +++ /dev/null @@ -1,45 +0,0 @@ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNHandshakeOperation, - - validateParams: (_, params) => { - if (!params?.channels && !params?.channelGroups) { - return 'channels and channleGroups both should not be empty'; - } - }, - - getURL: ({ config }, params) => { - const { channels = [] } = params; - const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return `/v2/subscribe/${config.subscribeKey}/${utils.encodeString(stringifiedChannels)}/0`; - }, - - getRequestTimeout: ({ config }) => config.getSubscribeTimeout(), - - isAuthSupported: () => true, - - prepareParams: (_, params) => { - const outParams = {}; - if (params.channelGroups && params.channelGroups.length > 0) { - outParams['channel-group'] = params.channelGroups.join(','); - } - outParams.tt = 0; - if (params.state) { - outParams.state = JSON.stringify(params.state); - } - if (params.filterExpression && params.filterExpression.length > 0) { - outParams['filter-expr'] = params.filterExpression; - } - outParams.ee = ''; - return outParams; - }, - - handleResponse: (_, response) => ({ - region: response.t.r, - timetoken: response.t.t, - }), -}; - -export default endpoint; diff --git a/src/core/endpoints/subscriptionUtils/handshake.ts b/src/core/endpoints/subscriptionUtils/handshake.ts new file mode 100644 index 000000000..cf3b70b87 --- /dev/null +++ b/src/core/endpoints/subscriptionUtils/handshake.ts @@ -0,0 +1,39 @@ +/** + * Handshake subscribe REST API module. + */ + +import RequestOperation from '../../constants/operations'; +import { BaseSubscribeRequest } from '../subscribe'; +import { encodeNames } from '../../utils'; +import { Query } from '../../types/api'; + +/** + * Handshake subscribe request. + * + * Separate subscribe request required by Event Engine. + */ +export class HandshakeSubscribeRequest extends BaseSubscribeRequest { + operation(): RequestOperation { + return RequestOperation.PNHandshakeOperation; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channels = [], + } = this.parameters; + + return `/v2/subscribe/${subscribeKey}/${encodeNames(channels.sort(), ',')}/0`; + } + + protected get queryParameters(): Query { + const { channelGroups, filterExpression, state } = this.parameters; + const query: Query = { tt: 0, ee: '' }; + + if (channelGroups && channelGroups.length > 0) query['channel-group'] = channelGroups.sort().join(','); + if (filterExpression && filterExpression.length > 0) query['filter-expr'] = filterExpression; + if (state && Object.keys(state).length > 0) query['state'] = JSON.stringify(state); + + return query; + } +} diff --git a/src/core/endpoints/subscriptionUtils/receiveMessages.js b/src/core/endpoints/subscriptionUtils/receiveMessages.js deleted file mode 100644 index 6558af81c..000000000 --- a/src/core/endpoints/subscriptionUtils/receiveMessages.js +++ /dev/null @@ -1,77 +0,0 @@ -import operationConstants from '../../constants/operations'; -import utils from '../../utils'; - -const endpoint = { - getOperation: () => operationConstants.PNReceiveMessagesOperation, - - validateParams: (_, params) => { - if (!params?.channels && !params?.channelGroups) { - return 'channels and channleGroups both should not be empty'; - } - if (!params?.timetoken) { - return 'timetoken can not be empty'; - } - if (!params?.region) { - return 'region can not be empty'; - } - }, - - getURL: ({ config }, params) => { - const { channels = [] } = params; - const stringifiedChannels = channels.length > 0 ? channels.join(',') : ','; - return `/v2/subscribe/${config.subscribeKey}/${utils.encodeString(stringifiedChannels)}/0`; - }, - - getRequestTimeout: ({ config }) => config.getSubscribeTimeout(), - - isAuthSupported: () => true, - - getAbortSignal: (_, params) => params.abortSignal, - - prepareParams: (_, params) => { - const outParams = {}; - if (params.channelGroups && params.channelGroups.length > 0) { - outParams['channel-group'] = params.channelGroups.join(','); - } - if (params.filterExpression && params.filterExpression.length > 0) { - outParams['filter-expr'] = params.filterExpression; - } - outParams.tt = params.timetoken; - outParams.tr = params.region; - outParams.ee = ''; - return outParams; - }, - - handleResponse: (_, response) => { - const parsedMessages = []; - - response.m.forEach((envelope) => { - const parsedMessage = { - shard: parseInt(envelope.a, 10), - subscriptionMatch: envelope.b, - channel: envelope.c, - messageType: envelope.e, - payload: envelope.d, - flags: envelope.f, - issuingClientId: envelope.i, - subscribeKey: envelope.k, - originationTimetoken: envelope.o, - userMetadata: envelope.u, - publishMetaData: { - timetoken: envelope.p.t, - region: envelope.p.r, - }, - }; - parsedMessages.push(parsedMessage); - }); - return { - messages: parsedMessages, - metadata: { - region: response.t.r, - timetoken: response.t.t, - }, - }; - }, -}; - -export default endpoint; diff --git a/src/core/endpoints/subscriptionUtils/receiveMessages.ts b/src/core/endpoints/subscriptionUtils/receiveMessages.ts new file mode 100644 index 000000000..66286f57b --- /dev/null +++ b/src/core/endpoints/subscriptionUtils/receiveMessages.ts @@ -0,0 +1,48 @@ +/** + * Receive messages subscribe REST API module. + */ + +import RequestOperation from '../../constants/operations'; +import { BaseSubscribeRequest } from '../subscribe'; +import { encodeNames } from '../../utils'; +import { Query } from '../../types/api'; + +/** + * Receive messages subscribe request. + */ +export class ReceiveMessagesSubscribeRequest extends BaseSubscribeRequest { + operation(): RequestOperation { + return RequestOperation.PNReceiveMessagesOperation; + } + + validate(): string | undefined { + const validationResult = super.validate(); + + if (validationResult) return validationResult; + if (!this.parameters.timetoken) return 'timetoken can not be empty'; + if (!this.parameters.region) return 'region can not be empty'; + } + + protected get path(): string { + const { + keySet: { subscribeKey }, + channels = [], + } = this.parameters; + + return `/v2/subscribe/${subscribeKey}/${encodeNames(channels.sort(), ',')}/0`; + } + + protected get queryParameters(): Query { + const { channelGroups, filterExpression, timetoken, region } = this.parameters; + const query: Query = { ee: '' }; + + if (channelGroups && channelGroups.length > 0) query['channel-group'] = channelGroups.sort().join(','); + if (filterExpression && filterExpression.length > 0) query['filter-expr'] = filterExpression; + if (typeof timetoken === 'string') { + if (timetoken && timetoken.length > 0) query['tt'] = timetoken; + } else if (timetoken && timetoken > 0) query['tt'] = timetoken; + if (region) query['tr'] = region; + + return query; + } +} diff --git a/src/core/endpoints/time.js b/src/core/endpoints/time.js deleted file mode 100644 index f5996c0e4..000000000 --- a/src/core/endpoints/time.js +++ /dev/null @@ -1,32 +0,0 @@ -/* */ -import operationConstants from '../constants/operations'; - -export function getOperation() { - return operationConstants.PNTimeOperation; -} - -export function getURL() { - return '/time/0'; -} - -export function getRequestTimeout({ config }) { - return config.getTransactionTimeout(); -} - -export function prepareParams() { - return {}; -} - -export function isAuthSupported() { - return false; -} - -export function handleResponse(modules, serverResponse) { - return { - timetoken: serverResponse[0], - }; -} - -export function validateParams() { - // pass -} diff --git a/src/core/endpoints/time.ts b/src/core/endpoints/time.ts new file mode 100644 index 000000000..564f6d84a --- /dev/null +++ b/src/core/endpoints/time.ts @@ -0,0 +1,55 @@ +/** + * Time REST API module. + */ + +import { createValidationError, PubNubError } from '../../errors/pubnub-error'; +import { TransportResponse } from '../types/transport-response'; +import { AbstractRequest } from '../components/request'; +import RequestOperation from '../constants/operations'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * Service success response. + */ +export type TimeResponse = { + /** + * High-precision time when published data has been received by the PubNub service. + */ + timetoken: string; +}; + +/** + * Service success response. + */ +type ServiceResponse = [string]; +// endregion + +export class TimeRequest extends AbstractRequest { + constructor() { + super(); + } + + operation(): RequestOperation { + return RequestOperation.PNTimeOperation; + } + + async parse(response: TransportResponse): Promise { + const serviceResponse = this.deserializeResponse(response); + + if (!serviceResponse) + throw new PubNubError( + 'Service response error, check status for details', + createValidationError('Unable to deserialize service response'), + ); + + return { timetoken: serviceResponse[0] }; + } + + protected get path(): string { + return '/time/0'; + } +} diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts new file mode 100644 index 000000000..4003f427b --- /dev/null +++ b/src/core/interfaces/configuration.ts @@ -0,0 +1,789 @@ +/** + * {@link PubNub} client configuration module. + */ + +import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; +import { RequestRetryPolicy } from '../../event-engine/core/retryPolicy'; +import { CryptoModule } from './crypto-module'; +import { KeySet, Payload } from '../types/api'; +import { PubNubError } from '../../errors/pubnub-error'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- + +// region Defaults +/** + * Whether secured connection should be used by or not. + */ +const USE_SSL = true; + +/** + * Whether PubNub client should catch up subscription after network issues. + */ +const RESTORE = false; + +/** + * Whether network availability change should be announced with `PNNetworkDownCategory` and + * `PNNetworkUpCategory` state or not. + */ +const AUTO_NETWORK_DETECTION = false; + +/** + * Whether messages should be de-duplicated before announcement or not. + */ +const DEDUPE_ON_SUBSCRIBE = false; + +/** + * Maximum cache which should be used for message de-duplication functionality. + */ +const DEDUPE_CACHE_SIZE = 100; + +/** + * Maximum number of file message publish retries. + */ +const FILE_PUBLISH_RETRY_LIMIT = 5; + +/** + * Whether subscription event engine should be used or not. + */ +const ENABLE_EVENT_ENGINE = false; + +/** + * Whether configured user presence state should be maintained by the PubNub client or not. + */ +const MAINTAIN_PRESENCE_STATE = true; + +/** + * Whether PubNub client should try to utilize existing TCP connection for new requests or not. + */ +const KEEP_ALIVE = false; + +/** + * Whether verbose logging should be enabled or not. + */ +const USE_VERBOSE_LOGGING = false; + +/** + * Whether leave events should be suppressed or not. + */ +const SUPPRESS_LEAVE_EVENTS = false; + +/** + * Whether heartbeat request failure should be announced or not. + */ +const ANNOUNCE_HEARTBEAT_FAILURE = true; + +/** + * Whether heartbeat request success should be announced or not. + */ +const ANNOUNCE_HEARTBEAT_SUCCESS = false; + +/** + * Whether PubNub client instance id should be added to the requests or not. + */ +const USE_INSTANCE_ID = false; + +/** + * Whether unique identifier should be added to the request or not. + */ +const USE_REQUEST_ID = true; + +/** + * Transactional requests timeout. + */ +const TRANSACTIONAL_REQUEST_TIMEOUT = 15; + +/** + * Subscription request timeout. + */ +const SUBSCRIBE_REQUEST_TIMEOUT = 310; + +/** + * Default user presence timeout. + */ +const PRESENCE_TIMEOUT = 300; + +/** + * Minimum user presence timeout. + */ +const PRESENCE_TIMEOUT_MINIMUM = 20; +// endregion + +/** + * Base user-provided PubNub client configuration. + */ +export type UserConfiguration = { + /** + * Specifies the `subscribeKey` to be used for subscribing to a channel and message publishing. + */ + subscribeKey: string; + + /** + * Specifies the `subscribe_key` to be used for subscribing to a channel and message publishing. + * + * @deprecated Use the {@link subscribeKey} instead. + */ + subscribe_key?: string; + + /** + * Specifies the `publishKey` to be used for publishing messages to a channel. + */ + publishKey?: string; + + /** + * Specifies the `publish_key` to be used for publishing messages to a channel. + * + * @deprecated Use the {@link publishKey} instead. + */ + publish_key?: string; + + /** + * Specifies the `secretKey` to be used for request signatures computation. + */ + secretKey?: string; + + /** + * Specifies the `secret_key` to be used for request signatures computation. + * + * @deprecated Use the {@link secretKey} instead. + */ + secret_key?: string; + + /** + * Unique PubNub client user identifier. + * + * Unique `userId` to identify the user or the device that connects to PubNub. + * It's a UTF-8 encoded string of up to 64 alphanumeric characters. + * + * If you don't set the `userId`, you won't be able to connect to PubNub. + */ + userId?: string; + + /** + * If Access Manager enabled, this key will be used on all requests. + */ + authKey?: string | null; + + /** + * Log HTTP information. + * + * @default `false` + */ + logVerbosity?: boolean; + + /** + * If set to true, requests will be made over HTTPS. + * + * @default `true` for v4.20.0 onwards, `false` before v4.20.0 + */ + ssl?: boolean; + + /** + * If a custom domain is required, SDK accepts it here. + * + * @default `ps.pndsn.com` + */ + origin?: string | string[]; + + /** + * How long the server will consider the client alive for presence.The value is in seconds. + * + * @default `300` + */ + presenceTimeout?: number; + + /** + * How often the client will announce itself to server.The value is in seconds. + * + * @default `not set` + */ + heartbeatInterval?: number; + + /** + * Transactional requests timeout in milliseconds. + * + * Maximum duration for which PubNub client should wait for transactional request completion. + * + * @default `15` seconds + */ + transactionalRequestTimeout?: number; + + /** + * Subscription requests timeout in milliseconds. + * + * Maximum duration for which PubNub client should wait for subscription request completion. + * + * @default `310` seconds + */ + subscribeRequestTimeout?: number; + + /** + * `true` to allow catch up on the front-end applications. + * + * @default `false` + */ + restore?: boolean; + + /** + * Whether to include the PubNub object instance ID in outgoing requests. + * + * @default `false` + */ + useInstanceId?: boolean; + + /** + * When `true` the SDK doesn't send out the leave requests. + * + * @default `false` + */ + suppressLeaveEvents?: boolean; + + /** + * `PNRequestMessageCountExceededCategory` is thrown when the number of messages into the + * payload is above of `requestMessageCountThreshold`. + * + * @default `100` + */ + requestMessageCountThreshold?: number; + + /** + * This flag announces when the network is down or up using the states `PNNetworkDownCategory` + * and `PNNetworkUpCategory`. + * + * @default `false` + */ + autoNetworkDetection?: boolean; + + /** + * Whether to use the standardized workflows for subscribe and presence. + * + * Note that the `maintainPresenceState` parameter is set to true by default, so make sure to + * disable it if you don't need to maintain presence state. For more information, refer to the + * param description in this table. + * + * + * @default `false` + */ + enableEventEngine?: boolean; + + /** + * Custom reconnection configuration parameters. + * + * `retryConfiguration: policy` is the type of policy to be used. + * + * Available values: + * - `PubNub.LinearRetryPolicy({ delay, maximumRetry })` + * - `PubNub.ExponentialRetryPolicy({ minimumDelay, maximumDelay, maximumRetry })` + * + * For more information, refer to + * {@link /docs/general/setup/connection-management#reconnection-policy|Reconnection Policy}. JavaScript doesn't + * support excluding endpoints. + * + * @default `not set` + */ + retryConfiguration?: RequestRetryPolicy; + + /** + * Whether the `state` set using `setState()` should be maintained for the current `userId`. + * This option works only when `enableEventEngine` is set to `true`. + * + * @default `true` + */ + maintainPresenceState?: boolean; + + /** + * `UUID` to use. You should set a unique `UUID` to identify the user or the device that + * connects to PubNub. + * If you don't set the `UUID`, you won't be able to connect to PubNub. + * + * @deprecated Use {@link userId} instead. + */ + uuid?: string; + + /** + * If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of + * opening a new one for each new request. + * + * @default `false` + */ + keepAlive?: boolean; + + /** + * If the SDK is running as part of another SDK built atop of it, allow a custom `pnsdk` with + * name and version. + */ + sdkName?: string; + + /** + * If the SDK is operated by a partner, allow a custom `pnsdk` item for them. + */ + partnerId?: string; +}; + +/** + * Extended client configuration. + * + * Extended configuration contains unannounced configuration options. + */ +export type ExtendedConfiguration = UserConfiguration & { + /** + * PubNub Account key set. + */ + keySet: KeySet; + + /** + * Real-time updates filtering expression. + */ + filterExpression?: string | null; + + /** + * Whether messages should be de-duplicated on subscribe before announcement or not. + * + * @default `false` + */ + dedupeOnSubscribe: boolean; + + /** + * Maximum size of deduplication manager cache. + */ + maximumCacheSize: number; + + /** + * Whether unique request identifier should be used in request query or not. + * + * @default `false` + */ + useRequestId?: boolean; + + /** + * Whether heartbeat request success should be announced or not. + * + * @default `false` + */ + announceSuccessfulHeartbeats: boolean; + + /** + * Whether heartbeat request failure should be announced or not. + * + * @default `true` + */ + announceFailedHeartbeats: boolean; + + /** + * How many times file message publish attempt should be retried. + * + * @default `5` + */ + fileUploadPublishRetryLimit: number; +}; + +/** + * Platform-specific PubNub client configuration. + * + * Part of configuration which is added by platform-specific PubNub client initialization code. + */ +export type PlatformConfiguration = { + /** + * Track of the SDK family for identifier generator. + */ + sdkFamily: string; + + /** + * The cryptography module used for encryption and decryption of messages and files. Takes the + * {@link cipherKey} and {@link useRandomIVs} parameters as arguments. + * + * For more information, refer to the + * {@link /docs/sdks/javascript/api-reference/configuration#cryptomodule|cryptoModule} section. + * + * @default `not set` + */ + cryptoModule?: CryptoModule; + + /** + * Platform-specific file representation + */ + /* eslint-disable @typescript-eslint/no-explicit-any */ + PubNubFile?: PubNubFileConstructor; + + // region Deprecated parameters + /** + * If passed, will encrypt the payloads. + * + * @deprecated Pass it to `cryptoModule` instead. + */ + cipherKey?: string; + + /** + * When `true` the initialization vector (IV) is random for all requests (not just for file + * upload). + * When `false` the IV is hard-coded for all requests except for file upload. + * + * @default `true` + * + * @deprecated Pass it to `cryptoModule` instead. + */ + useRandomIVs?: boolean; + + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + customEncrypt?: (data: string | Payload) => string; + + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + customDecrypt?: (data: string) => string; + // endregion +}; + +/** + * User-provided configuration object interface. + * + * Interface contains limited set of settings manipulation and access. + */ +export interface ClientConfiguration { + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + getUserId(): string; + + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + setUserId(value: string): void; + + /** + * Change REST API endpoint access authorization key. + * + * @param authKey - New authorization key which should be used with new requests. + */ + setAuthKey(authKey: string | null): void; + + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + getFilterExpression(): string | undefined | null; + + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + setFilterExpression(expression: string | null | undefined): void; + + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + setCipherKey(key: string | undefined): void; + + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + get version(): string; + + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + getVersion(): string; + + /** + * Add framework's prefix. + * + * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. + * @param suffix - Suffix with information about framework. + */ + _addPnsdkSuffix(name: string, suffix: string | number): void; + + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + * + * @deprecated Use the {@link getUserId} or {@link userId} getter instead. + */ + getUUID(): string; + + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @returns {Configuration} Reference to the configuration instance for easier chaining. + * + * @throws Error empty user identifier has been provided. + * + * @deprecated Use the {@link setUserId} or {@link userId} setter instead. + */ + setUUID(value: string): void; + // endregion +} + +/** + * Internal PubNub client configuration object interface. + */ +export interface PrivateClientConfiguration + extends ClientConfiguration, + Omit { + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ + getAuthKey(): string | undefined | null; + + /** + * Data encryption / decryption module. + * + * @returns Data processing crypto module (if set). + */ + getCryptoModule(): CryptoModule | undefined; + + /** + * Retrieve user's presence timeout. + * + * @returns User's presence timeout value. + */ + getPresenceTimeout(): number; + + /** + * Change user's presence timeout. + * + * @param timeout - New timeout for user's presence. + */ + setPresenceTimeout(timeout: number): void; + + /** + * Retrieve heartbeat requests interval. + * + * @returns Heartbeat requests interval. + */ + getHeartbeatInterval(): number | undefined; + + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ + setHeartbeatInterval(interval: number): void; + + /** + * Transactional request timeout. + * + * @returns Maximum duration in milliseconds for which PubNub client should wait for + * transactional request completion. + */ + getTransactionTimeout(): number; + + /** + * Subscription requests timeout. + * + * @returns Maximum duration in milliseconds for which PubNub client should wait for + * subscription request completion. + */ + getSubscribeTimeout(): number; + + /** + * PubNub file object constructor. + */ + get PubNubFile(): PubNubFileConstructor | undefined; + + /** + * Get PubNub client instance identifier. + * + * @returns Current PubNub client instance identifier. + */ + get instanceId(): string | undefined; + + /** + * Get SDK family identifier. + * + * @returns Current SDK family identifier. + */ + get sdkFamily(): string; + + /** + * Compose `pnsdk` suffix string. + * + * @param separator - String which will be used to join registered suffixes. + * + * @returns Concatenated `pnsdk` suffix string. + */ + _getPnsdkSuffix(separator: string): string; + + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + + /** + * If passed, will encrypt the payloads. + * + * @deprecated Pass it to `cryptoModule` instead. + */ + getCipherKey(): string | undefined; + + /** + * When `true` the initialization vector (IV) is random for all requests (not just for file + * upload). + * When `false` the IV is hard-coded for all requests except for file upload. + * + * @default `true` + * + * @deprecated Pass it to `cryptoModule` instead. + */ + getUseRandomIVs(): boolean | undefined; + + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + getCustomEncrypt(): ((data: string | Payload) => string) | undefined; + + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + getCustomDecrypt(): ((data: string) => string) | undefined; + // endregion +} + +/** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + */ +export const setDefaults = (configuration: UserConfiguration): ExtendedConfiguration => { + // Copy configuration. + const configurationCopy = { ...configuration }; + configurationCopy.logVerbosity ??= USE_VERBOSE_LOGGING; + configurationCopy.ssl ??= USE_SSL; + configurationCopy.transactionalRequestTimeout ??= TRANSACTIONAL_REQUEST_TIMEOUT; + configurationCopy.subscribeRequestTimeout ??= SUBSCRIBE_REQUEST_TIMEOUT; + configurationCopy.restore ??= RESTORE; + configurationCopy.useInstanceId ??= USE_INSTANCE_ID; + configurationCopy.suppressLeaveEvents ??= SUPPRESS_LEAVE_EVENTS; + configurationCopy.requestMessageCountThreshold ??= DEDUPE_CACHE_SIZE; + configurationCopy.autoNetworkDetection ??= AUTO_NETWORK_DETECTION; + configurationCopy.enableEventEngine ??= ENABLE_EVENT_ENGINE; + configurationCopy.maintainPresenceState ??= MAINTAIN_PRESENCE_STATE; + configurationCopy.keepAlive ??= KEEP_ALIVE; + + if (configurationCopy.userId && configurationCopy.uuid) + throw new PubNubError("PubNub client configuration error: use only 'userId'"); + + configurationCopy.userId ??= configurationCopy.uuid; + + if (!configurationCopy.userId) throw new PubNubError("PubNub client configuration error: 'userId' not set"); + else if (configurationCopy.userId?.trim().length === 0) + throw new PubNubError("PubNub client configuration error: 'userId' is empty"); + + // Generate default origin subdomains. + if (!configurationCopy.origin) + configurationCopy.origin = Array.from({ length: 20 }, (_, i) => `ps${i + 1}.pndsn.com`); + + const keySet: KeySet = { + subscribeKey: configurationCopy.subscribeKey, + publishKey: configurationCopy.publishKey, + secretKey: configurationCopy.secretKey, + }; + + if (configurationCopy.presenceTimeout !== undefined && configurationCopy.presenceTimeout < PRESENCE_TIMEOUT_MINIMUM) { + configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; + // eslint-disable-next-line no-console + console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); + } + + configurationCopy.presenceTimeout ??= PRESENCE_TIMEOUT; + + // Apply extended configuration defaults. + let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS; + let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE; + let fileUploadPublishRetryLimit = FILE_PUBLISH_RETRY_LIMIT; + let dedupeOnSubscribe = DEDUPE_ON_SUBSCRIBE; + const maximumCacheSize = DEDUPE_CACHE_SIZE; + let useRequestId = USE_REQUEST_ID; + + // @ts-expect-error Not documented legacy configuration options. + if (configurationCopy.dedupeOnSubscribe !== undefined && typeof configurationCopy.dedupeOnSubscribe === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. + dedupeOnSubscribe = configurationCopy.dedupeOnSubscribe; + } + + // @ts-expect-error Not documented legacy configuration options. + if (configurationCopy.useRequestId !== undefined && typeof configurationCopy.useRequestId === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. + useRequestId = configurationCopy.useRequestId; + } + + if ( + // @ts-expect-error Not documented legacy configuration options. + configurationCopy.announceSuccessfulHeartbeats !== undefined && + // @ts-expect-error Not documented legacy configuration options. + typeof configurationCopy.announceSuccessfulHeartbeats === 'boolean' + ) { + // @ts-expect-error Not documented legacy configuration options. + announceSuccessfulHeartbeats = configurationCopy.announceSuccessfulHeartbeats; + } + + if ( + // @ts-expect-error Not documented legacy configuration options. + configurationCopy.announceFailedHeartbeats !== undefined && + // @ts-expect-error Not documented legacy configuration options. + typeof configurationCopy.announceFailedHeartbeats === 'boolean' + ) { + // @ts-expect-error Not documented legacy configuration options. + announceFailedHeartbeats = configurationCopy.announceFailedHeartbeats; + } + + if ( + // @ts-expect-error Not documented legacy configuration options. + configurationCopy.fileUploadPublishRetryLimit !== undefined && + // @ts-expect-error Not documented legacy configuration options. + typeof configurationCopy.fileUploadPublishRetryLimit === 'number' + ) { + // @ts-expect-error Not documented legacy configuration options. + fileUploadPublishRetryLimit = configurationCopy.fileUploadPublishRetryLimit; + } + + return { + ...configurationCopy, + keySet, + dedupeOnSubscribe, + maximumCacheSize, + useRequestId, + announceSuccessfulHeartbeats, + announceFailedHeartbeats, + fileUploadPublishRetryLimit, + }; +}; diff --git a/src/core/interfaces/crypto-module.ts b/src/core/interfaces/crypto-module.ts new file mode 100644 index 000000000..29e173118 --- /dev/null +++ b/src/core/interfaces/crypto-module.ts @@ -0,0 +1,235 @@ +/** + * Crypto module. + */ + +import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; +import { Payload } from '../types/api'; + +/** + * Crypto module configuration. + */ +export type CryptoModuleConfiguration = { + default: C; + cryptors?: C[]; +}; + +export type CryptorConfiguration = { + /** + * Data encryption / decryption key. + */ + cipherKey?: string; + + /** + * Request sign secret key. + */ + secretKey?: string; + + /** + * Whether random initialization vector should be used or not. + * + * @default `true` + */ + useRandomIVs?: boolean; + + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + customEncrypt?: (data: string | Payload) => string; + + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + customDecrypt?: (data: string) => string; +}; + +/** + * Base crypto module interface. + */ +export interface CryptoModule { + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption + + /** + * Encrypt data. + * + * @param data - Data which should be encrypted using `CryptoModule`. + * + * @returns Data encryption result. + */ + encrypt(data: ArrayBuffer | string): ArrayBuffer | string; + + /** + * Encrypt file object. + * + * @param file - File object with data for encryption. + * @param File - File object constructor to create instance for encrypted data representation. + * + * @returns Asynchronous file encryption result. + */ + encryptFile( + file: PubNubFileInterface, + /* eslint-disable @typescript-eslint/no-explicit-any */ + File: PubNubFileConstructor, + ): Promise; + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + + /** + * Encrypt data. + * + * @param data - Dta which should be encrypted using `CryptoModule`. + * + * @returns Data decryption result. + */ + decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null; + + /** + * Decrypt file object. + * + * @param file - Encrypted file object with data for decryption. + * @param File - File object constructor to create instance for decrypted data representation. + * + * @returns Asynchronous file decryption result. + */ + decryptFile( + file: PubNubFileInterface, + /* eslint-disable @typescript-eslint/no-explicit-any */ + File: PubNubFileConstructor, + ): Promise; + // endregion +} + +export abstract class AbstractCryptoModule implements CryptoModule { + /** + * `String` to {@link ArrayBuffer} response decoder. + */ + protected static encoder = new TextEncoder(); + + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + protected static decoder = new TextDecoder(); + + defaultCryptor: C; + cryptors: C[]; + + // -------------------------------------------------------- + // --------------- Convenience functions ------------------ + // -------------------------------------------------------- + // region Convenience functions + + /** + * Construct crypto module with legacy cryptor for encryption and both legacy and AES-CBC + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using legacy cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ + static legacyCryptoModule(config: CryptorConfiguration): CryptoModule { + throw new Error('Should be implemented by concrete crypto module implementation.'); + } + + /** + * Construct crypto module with AES-CBC cryptor for encryption and both AES-CBC and legacy + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using AES-CBC cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ + static aesCbcCryptoModule(config: CryptorConfiguration): CryptoModule { + throw new Error('Should be implemented by concrete crypto module implementation.'); + } + // endregion + + constructor(configuration: CryptoModuleConfiguration) { + this.defaultCryptor = configuration.default; + this.cryptors = configuration.cryptors ?? []; + } + + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption + + /** + * Encrypt data. + * + * @param data - Data which should be encrypted using {@link CryptoModule}. + * + * @returns Data encryption result. + */ + abstract encrypt(data: ArrayBuffer | string): ArrayBuffer | string; + + /** + * Encrypt file object. + * + * @param file - File object with data for encryption. + * @param File - File object constructor to create instance for encrypted data representation. + * + * @returns Asynchronous file encryption result. + */ + abstract encryptFile( + file: PubNubFileInterface, + /* eslint-disable @typescript-eslint/no-explicit-any */ + File: PubNubFileConstructor, + ): Promise; + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + + /** + * Encrypt data. + * + * @param data - Dta which should be encrypted using `CryptoModule`. + * + * @returns Data decryption result. + */ + abstract decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null; + + /** + * Decrypt file object. + * + * @param file - Encrypted file object with data for decryption. + * @param File - File object constructor to create instance for decrypted data representation. + * + * @returns Asynchronous file decryption result. + */ + abstract decryptFile( + file: PubNubFileInterface, + /* eslint-disable @typescript-eslint/no-explicit-any */ + File: PubNubFileConstructor, + ): Promise; + // endregion + + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + + /** + * Retrieve list of module's cryptors. + */ + protected getAllCryptors() { + return [this.defaultCryptor, ...this.cryptors]; + } + // endregion +} diff --git a/src/core/interfaces/cryptography.ts b/src/core/interfaces/cryptography.ts new file mode 100644 index 000000000..5e859c656 --- /dev/null +++ b/src/core/interfaces/cryptography.ts @@ -0,0 +1,70 @@ +/** + * Legacy Cryptography module interface. + */ + +import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; + +export interface Cryptography { + // region Encryption + /** + * Encrypt provided source data using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` data. + * @param input - Source data for encryption. + * + * @returns Encrypted data as object or stream (depending on from source data type). + * + * @throws Error if unknown data type has been passed. + */ + encrypt(key: string, input: Types): Promise; + + /** + * Decrypt provided encrypted data using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` data. + * @param input - Encrypted data for decryption. + * + * @returns Decrypted data as object or stream (depending on from encrypted data type). + * + * @throws Error if unknown data type has been passed. + */ + decrypt(key: string, input: Types): Promise; + + /** + * Encrypt provided `PubNub` File object using specific encryption {@link key}. + * + * @param key - Key for `PubNub` File object encryption.
**Note:** Same key should be + * used to `decrypt` data. + * @param file - Source `PubNub` File object for encryption. + * @param File - Class constructor for `PubNub` File object. + * + * @returns Encrypted data as `PubNub` File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + encryptFile( + key: string, + file: PubNubFileInterface, + /* eslint-disable @typescript-eslint/no-explicit-any */ + File: PubNubFileConstructor, + ): Promise; + + /** + * Decrypt provided `PubNub` File object using specific decryption {@link key}. + * + * @param key - Key for `PubNub` File object decryption.
**Note:** Should be the same + * as used to `encrypt` data. + * @param file - Encrypted `PubNub` File object for decryption. + * @param File - Class constructor for `PubNub` File object. + * + * @returns Decrypted data as `PubNub` File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + decryptFile( + key: string, + file: PubNubFileInterface, + /* eslint-disable @typescript-eslint/no-explicit-any */ + File: PubNubFileConstructor, + ): Promise; +} diff --git a/src/core/interfaces/request.ts b/src/core/interfaces/request.ts new file mode 100644 index 000000000..77168006f --- /dev/null +++ b/src/core/interfaces/request.ts @@ -0,0 +1,38 @@ +import { TransportResponse } from '../types/transport-response'; +import { TransportRequest } from '../types/transport-request'; +import RequestOperation from '../constants/operations'; + +/** + * General REST API call request interface. + */ +export interface Request { + /** + * Type of request operation. + * + * PubNub REST API endpoint which will be called with request. + */ + operation(): RequestOperation; + + /** + * Validate provided request parameters. + * + * @returns Error message if request can't be sent without missing or malformed parameters. + */ + validate(): string | undefined; + + /** + * Compile all parameters into transparent data type. + * + * @returns Transport request which can be processed by the network layer. + */ + request(): TransportRequest; + + /** + * Process service response. + * + * @param [response] Successful request response from the service. + * + * @returns Service response mapped to the expected data type or `undefined` in case of error. + */ + parse(response: TransportResponse): Promise; +} diff --git a/src/core/interfaces/transport.ts b/src/core/interfaces/transport.ts new file mode 100644 index 000000000..701053900 --- /dev/null +++ b/src/core/interfaces/transport.ts @@ -0,0 +1,67 @@ +import { CancellationController, TransportRequest } from '../types/transport-request'; +import { TransportResponse } from '../types/transport-response'; + +/** + * Represents the configuration options for keeping the transport connection alive. + */ +export type TransportKeepAlive = { + /** + * The time interval in milliseconds for keeping the connection alive. + * + * @default 1000 + */ + keepAliveMsecs?: number; + + /** + * The maximum number of sockets allowed per host. + * + * @default Infinity + */ + maxSockets?: number; + + /** + * The maximum number of open and free sockets in the pool per host. + * + * @default 256 + */ + maxFreeSockets?: number; + + /** + * Timeout in milliseconds, after which the `idle` socket will be closed. + * + * @default 30000 + */ + timeout?: number; +}; + +/** + * This interface is used to send requests to the PubNub API. + * + * You can implement this interface for your types, or use one of the provided modules to use a + * transport library. + * + * @interface + */ +export interface Transport { + /** + * Make request sendable. + * + * @param req - The transport request to be processed. + * + * @returns - A promise that resolves to a transport response and request cancellation + * controller (if required). + */ + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; + + /** + * Pre-processed request. + * + * Transport implementation may pre-process original transport requests before making + * platform-specific request objects from it. + * + * @param req - Transport request provided by the PubNub client. + * + * @returns Transport request with updated properties (if it was required). + */ + request(req: TransportRequest): TransportRequest; +} diff --git a/src/core/pubnub-channel-groups.ts b/src/core/pubnub-channel-groups.ts new file mode 100644 index 000000000..ea50e1ea1 --- /dev/null +++ b/src/core/pubnub-channel-groups.ts @@ -0,0 +1,222 @@ +/** + * PubNub Channel Groups API module. + */ + +import { RemoveChannelGroupChannelsRequest } from './endpoints/channel_groups/remove_channels'; +import { KeySet, ResultCallback, SendRequestFunction, StatusCallback } from './types/api'; +import { AddChannelGroupChannelsRequest } from './endpoints/channel_groups/add_channels'; +import { ListChannelGroupChannels } from './endpoints/channel_groups/list_channels'; +import { DeleteChannelGroupRequest } from './endpoints/channel_groups/delete_group'; +import { ListChannelGroupsRequest } from './endpoints/channel_groups/list_groups'; +import * as ChannelGroups from './types/api/channel-groups'; + +export default class PubnubChannelGroups { + constructor( + private readonly keySet: KeySet, + /* eslint-disable @typescript-eslint/no-explicit-any */ + private readonly sendRequest: SendRequestFunction, + ) {} + + // -------------------------------------------------------- + // ---------------------- Audit API ----------------------- + // -------------------------------------------------------- + // region Audit API + + /** + * Fetch channel group channels. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public listChannels( + parameters: ChannelGroups.ListChannelGroupChannelsParameters, + callback: ResultCallback, + ): void; + + /** + * Fetch channel group channels. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get channel group channels response. + */ + public async listChannels( + parameters: ChannelGroups.ListChannelGroupChannelsParameters, + ): Promise; + + /** + * Fetch channel group channels. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get channel group channels response or `void` in case if `callback` + * provided. + */ + public async listChannels( + parameters: ChannelGroups.ListChannelGroupChannelsParameters, + callback?: ResultCallback, + ): Promise { + const request = new ListChannelGroupChannels({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + + // region Deprecated + /** + * Fetch all channel groups. + * + * @param callback - Request completion handler callback. + * + * @deprecated + */ + public listGroups(callback: ResultCallback): void; + + /** + * Fetch all channel groups. + * + * @returns Asynchronous get all channel groups response. + * + * @deprecated + */ + public async listGroups(): Promise; + + /** + * Fetch all channel groups. + * + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all channel groups response or `void` in case if `callback` provided. + * + * @deprecated + */ + public async listGroups( + callback?: ResultCallback, + ): Promise { + const request = new ListChannelGroupsRequest({ keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + // endregion + + // -------------------------------------------------------- + // ---------------------- Manage API ---------------------- + // -------------------------------------------------------- + // region Manage API + + /** + * Add channels to the channel group. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public addChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters, callback: StatusCallback): void; + + /** + * Add channels to the channel group. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous add channels to the channel group response. + */ + public async addChannels( + parameters: ChannelGroups.ManageChannelGroupChannelsParameters, + ): Promise>; + + /** + * Add channels to the channel group. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add channels to the channel group response or `void` in case if + * `callback` provided. + */ + public async addChannels( + parameters: ChannelGroups.ManageChannelGroupChannelsParameters, + callback?: StatusCallback, + ): Promise | void> { + const request = new AddChannelGroupChannelsRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + + /** + * Remove channels from the channel group. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public removeChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters, callback: StatusCallback): void; + + /** + * Remove channels from the channel group. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous remove channels from the channel group response. + */ + public async removeChannels( + parameters: ChannelGroups.ManageChannelGroupChannelsParameters, + ): Promise>; + + /** + * Remove channels from the channel group. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous remove channels from the channel group response or `void` in + * case if `callback` provided. + */ + public async removeChannels( + parameters: ChannelGroups.ManageChannelGroupChannelsParameters, + callback?: StatusCallback, + ): Promise | void> { + const request = new RemoveChannelGroupChannelsRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + + /** + * Remove channel group. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public deleteGroup(parameters: ChannelGroups.DeleteChannelGroupParameters, callback: StatusCallback): void; + + /** + * Remove channel group. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous remove channel group response. + */ + public async deleteGroup(parameters: ChannelGroups.DeleteChannelGroupParameters): Promise>; + + /** + * Remove channel group. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous remove channel group response or `void` in case if `callback` provided. + */ + public async deleteGroup( + parameters: ChannelGroups.DeleteChannelGroupParameters, + callback?: StatusCallback, + ): Promise | void> { + const request = new DeleteChannelGroupRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + + // endregion +} diff --git a/src/core/pubnub-common.js b/src/core/pubnub-common.js deleted file mode 100644 index 3aa12932e..000000000 --- a/src/core/pubnub-common.js +++ /dev/null @@ -1,847 +0,0 @@ -import Config from './components/config'; -import Crypto from './components/cryptography/index'; -import { encode } from './components/base64_codec'; -import SubscriptionManager from './components/subscription_manager'; -import TelemetryManager from './components/telemetry_manager'; -import NotificationsPayload from './components/push_payload'; -import ListenerManager from './components/listener_manager'; -import TokenManager from './components/token_manager'; - -import endpointCreator from './components/endpoint'; - -import * as addChannelsChannelGroupConfig from './endpoints/channel_groups/add_channels'; -import * as removeChannelsChannelGroupConfig from './endpoints/channel_groups/remove_channels'; -import * as deleteChannelGroupConfig from './endpoints/channel_groups/delete_group'; -import * as listChannelGroupsConfig from './endpoints/channel_groups/list_groups'; -import * as listChannelsInChannelGroupConfig from './endpoints/channel_groups/list_channels'; - -import * as addPushChannelsConfig from './endpoints/push/add_push_channels'; -import * as removePushChannelsConfig from './endpoints/push/remove_push_channels'; -import * as listPushChannelsConfig from './endpoints/push/list_push_channels'; -import * as removeDevicePushConfig from './endpoints/push/remove_device'; - -import * as presenceLeaveEndpointConfig from './endpoints/presence/leave'; -import * as presenceWhereNowEndpointConfig from './endpoints/presence/where_now'; -import * as presenceHeartbeatEndpointConfig from './endpoints/presence/heartbeat'; -import * as presenceGetStateConfig from './endpoints/presence/get_state'; -import * as presenceSetStateConfig from './endpoints/presence/set_state'; -import * as presenceHereNowConfig from './endpoints/presence/here_now'; - -// Actions API - -import * as addMessageActionEndpointConfig from './endpoints/actions/add_message_action'; -import * as removeMessageActionEndpointConfig from './endpoints/actions/remove_message_action'; -import * as getMessageActionEndpointConfig from './endpoints/actions/get_message_actions'; - -// File Upload API v1 - -import listFilesEndpointConfig from './endpoints/file_upload/list_files'; -import generateUploadUrlEndpointConfig from './endpoints/file_upload/generate_upload_url'; -import publishFileEndpointConfig from './endpoints/file_upload/publish_file'; -import sendFileFunction from './endpoints/file_upload/send_file'; -import getFileUrlFunction from './endpoints/file_upload/get_file_url'; -import downloadFileEndpointConfig from './endpoints/file_upload/download_file'; -import deleteFileEndpointConfig from './endpoints/file_upload/delete_file'; - -// Object API v2 -import getAllUUIDMetadataEndpointConfig from './endpoints/objects/uuid/get_all'; - -import getUUIDMetadataEndpointConfig from './endpoints/objects/uuid/get'; - -import setUUIDMetadataEndpointConfig from './endpoints/objects/uuid/set'; - -import removeUUIDMetadataEndpointConfig from './endpoints/objects/uuid/remove'; - -import getAllChannelMetadataEndpointConfig from './endpoints/objects/channel/get_all'; - -import getChannelMetadataEndpointConfig from './endpoints/objects/channel/get'; - -import setChannelMetadataEndpointConfig from './endpoints/objects/channel/set'; - -import removeChannelMetadataEndpointConfig from './endpoints/objects/channel/remove'; - -import getMembersV2EndpointConfig from './endpoints/objects/member/get'; - -import setMembersV2EndpointConfig from './endpoints/objects/member/set'; - -import getMembershipsV2EndpointConfig from './endpoints/objects/membership/get'; - -import setMembershipsV2EndpointConfig from './endpoints/objects/membership/set'; - -import * as auditEndpointConfig from './endpoints/access_manager/audit'; -import * as grantEndpointConfig from './endpoints/access_manager/grant'; -import * as grantTokenEndpointConfig from './endpoints/access_manager/grant_token'; -import revokeTokenEndpointConfig from './endpoints/access_manager/revoke_token'; - -import * as publishEndpointConfig from './endpoints/publish'; -import * as signalEndpointConfig from './endpoints/signal'; -import * as historyEndpointConfig from './endpoints/history/get_history'; -import * as deleteMessagesEndpointConfig from './endpoints/history/delete_messages'; -import * as messageCountsEndpointConfig from './endpoints/history/message_counts'; -import * as fetchMessagesEndpointConfig from './endpoints/fetch_messages'; -import * as timeEndpointConfig from './endpoints/time'; -import * as subscribeEndpointConfig from './endpoints/subscribe'; - -// subscription utilities -import handshakeEndpointConfig from './endpoints/subscriptionUtils/handshake'; -import receiveMessagesConfig from './endpoints/subscriptionUtils/receiveMessages'; - -import OPERATIONS from './constants/operations'; -import CATEGORIES from './constants/categories'; - -import uuidGenerator from './components/uuid'; -import { EventEngine } from '../event-engine'; -import { PresenceEventEngine } from '../event-engine/presence/presence'; -import { RetryPolicy } from '../event-engine/core/retryPolicy'; -import EventEmitter from './components/eventEmitter'; - -import { Channel } from '../entities/Channel'; -import { ChannelGroup } from '../entities/ChannelGroup'; -import { ChannelMetadata } from '../entities/ChannelMetadata'; -import { UserMetadata } from '../entities/UserMetadata'; -import { SubscriptionSet } from '../entities/SubscriptionSet'; - -export default class { - _config; - - _telemetryManager; - - _listenerManager; - - _tokenManager; - - // tell flow about the mounted endpoint - time; - - publish; - - fire; - - history; - - deleteMessages; - - messageCounts; - - fetchMessages; - - // - channelGroups; - - // - push; - - // - hereNow; - - whereNow; - - getState; - - setState; - // presence utility methods - iAmHere; - iAmAway; - setPresenceState; - - // subscription utility methods - handshake; - receiveMessages; - - // - grant; - - grantToken; - - audit; - - revokeToken; - - // - subscribe; - - signal; - - presence; - - unsubscribe; - - unsubscribeAll; - - // Actions API - addMessageAction; - - removeMessageAction; - - getMessageActions; - - // File Upload API v1 - - File; - - encryptFile; - - decryptFile; - - listFiles; - - sendFile; - - downloadFile; - - getFileUrl; - - deleteFile; - - publishFile; - - // Objects API v2 - - objects; - - // User - createUser; - - updateUser; - - fetchUser; - - removeUser; - - fetchUsers; - - // Space - createSpace; - - updateSpace; - - fetchSpace; - - removeSpace; - - fetchSpaces; - - // Membership - addMemberships; - - updateMemberships; - - fetchMemberships; - - removeMemberships; - - disconnect; - - reconnect; - - destroy; - - stop; - - getSubscribedChannels; - - getSubscribedChannelGroups; - - addListener; - - removeListener; - - removeAllListeners; - - parseToken; - - setToken; - - getToken; - - getAuthKey; - - setAuthKey; - - setCipherKey; - - setUUID; - - getUUID; - - setUserId; - - getUserId; - - getFilterExpression; - - setFilterExpression; - - setHeartbeatInterval; - - setProxy; - - encrypt; - - decrypt; - - _eventEmitter; - - constructor(setup) { - const { networking, cbor } = setup; - - const config = new Config({ setup }); - this._config = config; - const crypto = new Crypto({ config }); // LEGACY - - const { cryptography } = setup; - - networking.init(config); - - const tokenManager = new TokenManager(config, cbor); - this._tokenManager = tokenManager; - - const telemetryManager = new TelemetryManager({ - maximumSamplesCount: 60000, - }); - - this._telemetryManager = telemetryManager; - const cryptoModule = this._config.cryptoModule; - - const modules = { - config, - networking, - crypto, - cryptography, - tokenManager, - telemetryManager, - PubNubFile: setup.PubNubFile, - cryptoModule: cryptoModule, - }; - - this.File = setup.PubNubFile; - - this.encryptFile = function (key, file) { - if (arguments.length == 1 && typeof key != 'string' && modules.cryptoModule) { - file = key; - return modules.cryptoModule.encryptFile(file, this.File); - } - return cryptography.encryptFile(key, file, this.File); - }; - this.decryptFile = function (key, file) { - if (arguments.length == 1 && typeof key != 'string' && modules.cryptoModule) { - file = key; - return modules.cryptoModule.decryptFile(file, this.File); - } - return cryptography.decryptFile(key, file, this.File); - }; - - const timeEndpoint = endpointCreator.bind(this, modules, timeEndpointConfig); - const leaveEndpoint = endpointCreator.bind(this, modules, presenceLeaveEndpointConfig); - const heartbeatEndpoint = endpointCreator.bind(this, modules, presenceHeartbeatEndpointConfig); - const setStateEndpoint = endpointCreator.bind(this, modules, presenceSetStateConfig); - const subscribeEndpoint = endpointCreator.bind(this, modules, subscribeEndpointConfig); - - // managers - const listenerManager = new ListenerManager(); - this._listenerManager = listenerManager; - - this.iAmHere = endpointCreator.bind(this, modules, presenceHeartbeatEndpointConfig); - this.iAmAway = endpointCreator.bind(this, modules, presenceLeaveEndpointConfig); - this.setPresenceState = endpointCreator.bind(this, modules, presenceSetStateConfig); - this.handshake = endpointCreator.bind(this, modules, handshakeEndpointConfig); - this.receiveMessages = endpointCreator.bind(this, modules, receiveMessagesConfig); - - this._eventEmitter = new EventEmitter({ - modules: modules, - listenerManager: this._listenerManager, - getFileUrl: (params) => getFileUrlFunction(modules, params), - }); - if (config.enableEventEngine === true) { - if (config.maintainPresenceState) { - this.presenceState = {}; - this.setState = (args) => { - args.channels?.forEach((channel) => (this.presenceState[channel] = args.state)); - args.channelGroups?.forEach((group) => (this.presenceState[group] = args.state)); - return this.setPresenceState({ - channels: args.channels, - channelGroups: args.channelGroups, - state: this.presenceState, - }); - }; - } - - if (config.getHeartbeatInterval()) { - const presenceEventEngine = new PresenceEventEngine({ - heartbeat: this.iAmHere, - leave: this.iAmAway, - heartbeatDelay: () => - new Promise((resolve) => setTimeout(resolve, modules.config.getHeartbeatInterval() * 1000)), - retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), - config: modules.config, - presenceState: this.presenceState, - emitStatus: (status) => { - listenerManager.announceStatus(status); - }, - }); - this.presenceEventEngine = presenceEventEngine; - this.join = this.presenceEventEngine.join.bind(presenceEventEngine); - this.leave = this.presenceEventEngine.leave.bind(presenceEventEngine); - this.leaveAll = this.presenceEventEngine.leaveAll.bind(presenceEventEngine); - } - const eventEngine = new EventEngine({ - handshake: this.handshake, - receiveMessages: this.receiveMessages, - delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), - join: this.join, - leave: this.leave, - leaveAll: this.leaveAll, - presenceState: this.presenceState, - config: modules.config, - emitMessages: (events) => { - for (const event of events) { - this._eventEmitter.emitEvent(event); - } - }, - emitStatus: (status) => { - listenerManager.announceStatus(status); - }, - }); - - this.subscribe = eventEngine.subscribe.bind(eventEngine); - this.unsubscribe = eventEngine.unsubscribe.bind(eventEngine); - this.unsubscribeAll = eventEngine.unsubscribeAll.bind(eventEngine); - this.reconnect = eventEngine.reconnect.bind(eventEngine); - this.disconnect = eventEngine.disconnect.bind(eventEngine); - this.destroy = eventEngine.dispose.bind(eventEngine); - this.getSubscribedChannels = eventEngine.getSubscribedChannels.bind(eventEngine); - this.getSubscribedChannelGroups = eventEngine.getSubscribedChannelGroups.bind(eventEngine); - this.eventEngine = eventEngine; - } else { - const subscriptionManager = new SubscriptionManager({ - timeEndpoint, - leaveEndpoint, - heartbeatEndpoint, - setStateEndpoint, - subscribeEndpoint, - crypto: modules.crypto, - config: modules.config, - listenerManager, - getFileUrl: (params) => getFileUrlFunction(modules, params), - cryptoModule: modules.cryptoModule, - eventEmitter: this._eventEmitter, - }); - - this.subscribe = subscriptionManager.adaptSubscribeChange.bind(subscriptionManager); - this.unsubscribe = subscriptionManager.adaptUnsubscribeChange.bind(subscriptionManager); - this.disconnect = subscriptionManager.disconnect.bind(subscriptionManager); - this.reconnect = subscriptionManager.reconnect.bind(subscriptionManager); - this.unsubscribeAll = subscriptionManager.unsubscribeAll.bind(subscriptionManager); - this.getSubscribedChannels = subscriptionManager.getSubscribedChannels.bind(subscriptionManager); - this.getSubscribedChannelGroups = subscriptionManager.getSubscribedChannelGroups.bind(subscriptionManager); - - this.setState = subscriptionManager.adaptStateChange.bind(subscriptionManager); - this.presence = subscriptionManager.adaptPresenceChange.bind(subscriptionManager); - - this.destroy = (isOffline) => { - subscriptionManager.unsubscribeAll(isOffline); - subscriptionManager.disconnect(); - }; - } - - this.addListener = this._eventEmitter.addListener.bind(this._eventEmitter); - this.removeListener = this._eventEmitter.removeListener.bind(this._eventEmitter); - this.removeAllListeners = this._eventEmitter.removeAllListeners.bind(this._eventEmitter); - - this.parseToken = tokenManager.parseToken.bind(tokenManager); - this.setToken = tokenManager.setToken.bind(tokenManager); - this.getToken = tokenManager.getToken.bind(tokenManager); - - /* channel groups */ - this.channelGroups = { - listGroups: endpointCreator.bind(this, modules, listChannelGroupsConfig), - listChannels: endpointCreator.bind(this, modules, listChannelsInChannelGroupConfig), - addChannels: endpointCreator.bind(this, modules, addChannelsChannelGroupConfig), - removeChannels: endpointCreator.bind(this, modules, removeChannelsChannelGroupConfig), - deleteGroup: endpointCreator.bind(this, modules, deleteChannelGroupConfig), - }; - /* push */ - this.push = { - addChannels: endpointCreator.bind(this, modules, addPushChannelsConfig), - removeChannels: endpointCreator.bind(this, modules, removePushChannelsConfig), - deleteDevice: endpointCreator.bind(this, modules, removeDevicePushConfig), - listChannels: endpointCreator.bind(this, modules, listPushChannelsConfig), - }; - /* presence */ - this.hereNow = endpointCreator.bind(this, modules, presenceHereNowConfig); - this.whereNow = endpointCreator.bind(this, modules, presenceWhereNowEndpointConfig); - this.getState = endpointCreator.bind(this, modules, presenceGetStateConfig); - /* PAM */ - this.grant = endpointCreator.bind(this, modules, grantEndpointConfig); - this.grantToken = endpointCreator.bind(this, modules, grantTokenEndpointConfig); - this.audit = endpointCreator.bind(this, modules, auditEndpointConfig); - this.revokeToken = endpointCreator.bind(this, modules, revokeTokenEndpointConfig); - this.publish = endpointCreator.bind(this, modules, publishEndpointConfig); - - this.fire = (args, callback) => { - args.replicate = false; - args.storeInHistory = false; - return this.publish(args, callback); - }; - - this.signal = endpointCreator.bind(this, modules, signalEndpointConfig); - - this.history = endpointCreator.bind(this, modules, historyEndpointConfig); - this.deleteMessages = endpointCreator.bind(this, modules, deleteMessagesEndpointConfig); - this.messageCounts = endpointCreator.bind(this, modules, messageCountsEndpointConfig); - this.fetchMessages = endpointCreator.bind(this, modules, fetchMessagesEndpointConfig); - - // Actions API - - this.addMessageAction = endpointCreator.bind(this, modules, addMessageActionEndpointConfig); - - this.removeMessageAction = endpointCreator.bind(this, modules, removeMessageActionEndpointConfig); - - this.getMessageActions = endpointCreator.bind(this, modules, getMessageActionEndpointConfig); - - // File Upload API v1 - - this.listFiles = endpointCreator.bind(this, modules, listFilesEndpointConfig); - - const generateUploadUrl = endpointCreator.bind(this, modules, generateUploadUrlEndpointConfig); - this.publishFile = endpointCreator.bind(this, modules, publishFileEndpointConfig); - - this.sendFile = sendFileFunction({ - generateUploadUrl, - publishFile: this.publishFile, - modules, - }); - - this.getFileUrl = (params) => getFileUrlFunction(modules, params); - - this.downloadFile = endpointCreator.bind(this, modules, downloadFileEndpointConfig); - - this.deleteFile = endpointCreator.bind(this, modules, deleteFileEndpointConfig); - - // entities - - this.channel = (name) => new Channel(name, this._eventEmitter, this); - this.channelGroup = (name) => new ChannelGroup(name, this._eventEmitter, this); - this.channelMetadata = (id) => new ChannelMetadata(id, this._eventEmitter, this); - this.userMetadata = (id) => new UserMetadata(id, this._eventEmitter, this); - this.subscriptionSet = (args) => - new SubscriptionSet({ - channels: args.channels, - channelGroups: args.channelGroups, - subscriptionOptions: args.subscriptionOptions, - eventEmitter: this._eventEmitter, - pubnub: this, - }); - - // Objects API v2 - - this.objects = { - getAllUUIDMetadata: endpointCreator.bind(this, modules, getAllUUIDMetadataEndpointConfig), - getUUIDMetadata: endpointCreator.bind(this, modules, getUUIDMetadataEndpointConfig), - setUUIDMetadata: endpointCreator.bind(this, modules, setUUIDMetadataEndpointConfig), - removeUUIDMetadata: endpointCreator.bind(this, modules, removeUUIDMetadataEndpointConfig), - - getAllChannelMetadata: endpointCreator.bind(this, modules, getAllChannelMetadataEndpointConfig), - getChannelMetadata: endpointCreator.bind(this, modules, getChannelMetadataEndpointConfig), - setChannelMetadata: endpointCreator.bind(this, modules, setChannelMetadataEndpointConfig), - removeChannelMetadata: endpointCreator.bind(this, modules, removeChannelMetadataEndpointConfig), - - getChannelMembers: endpointCreator.bind(this, modules, getMembersV2EndpointConfig), - setChannelMembers: (parameters, ...rest) => - endpointCreator.call( - this, - modules, - setMembersV2EndpointConfig, - { - type: 'set', - ...parameters, - }, - ...rest, - ), - removeChannelMembers: (parameters, ...rest) => - endpointCreator.call( - this, - modules, - setMembersV2EndpointConfig, - { - type: 'delete', - ...parameters, - }, - ...rest, - ), - - getMemberships: endpointCreator.bind(this, modules, getMembershipsV2EndpointConfig), - setMemberships: (parameters, ...rest) => - endpointCreator.call( - this, - modules, - setMembershipsV2EndpointConfig, - { - type: 'set', - ...parameters, - }, - ...rest, - ), - removeMemberships: (parameters, ...rest) => - endpointCreator.call( - this, - modules, - setMembershipsV2EndpointConfig, - { - type: 'delete', - ...parameters, - }, - ...rest, - ), - }; - - // User Apis - this.createUser = (args) => - this.objects.setUUIDMetadata({ - uuid: args.userId, - data: args.data, - include: args.include, - }); - - this.updateUser = this.createUser; - - this.removeUser = (args) => - this.objects.removeUUIDMetadata({ - uuid: args?.userId, - }); - - this.fetchUser = (args) => - this.objects.getUUIDMetadata({ - uuid: args?.userId, - include: args?.include, - }); - - this.fetchUsers = this.objects.getAllUUIDMetadata; - - // Space apis - this.createSpace = (args) => - this.objects.setChannelMetadata({ - channel: args.spaceId, - data: args.data, - include: args.include, - }); - - this.updateSpace = this.createSpace; - - this.removeSpace = (args) => - this.objects.removeChannelMetadata({ - channel: args.spaceId, - }); - - this.fetchSpace = (args) => - this.objects.getChannelMetadata({ - channel: args.spaceId, - include: args.include, - }); - - this.fetchSpaces = this.objects.getAllChannelMetadata; - - // Membership apis - this.addMemberships = (parameters) => { - if (typeof parameters.spaceId === 'string') { - return this.objects.setChannelMembers({ - channel: parameters.spaceId, - uuids: parameters.users?.map((user) => { - if (typeof user === 'string') { - return user; - } - return { - id: user.userId, - custom: user.custom, - status: user.status, - }; - }), - limit: 0, - }); - } else { - return this.objects.setMemberships({ - uuid: parameters.userId, - channels: parameters.spaces?.map((space) => { - if (typeof space === 'string') { - return space; - } - return { - id: space.spaceId, - custom: space.custom, - status: space.status, - }; - }), - limit: 0, - }); - } - }; - - this.updateMemberships = this.addMemberships; - - this.removeMemberships = (parameters) => { - if (typeof parameters.spaceId === 'string') { - return this.objects.removeChannelMembers({ - channel: parameters.spaceId, - uuids: parameters.userIds, - limit: 0, - }); - } else { - return this.objects.removeMemberships({ - uuid: parameters.userId, - channels: parameters.spaceIds, - limit: 0, - }); - } - }; - - this.fetchMemberships = (params) => { - if (typeof params.spaceId === 'string') { - return this.objects - .getChannelMembers({ - channel: params.spaceId, - filter: params.filter, - limit: params.limit, - page: params.page, - include: { - customFields: params.include.customFields, - UUIDFields: params.include.userFields, - customUUIDFields: params.include.customUserFields, - statusField: params.include.statusField, - UUIDStatusField: params.include.userStatusField, - UUIDTypeField: params.include.userTypeField, - totalCount: params.include.totalCount, - }, - sort: - params.sort != null - ? Object.fromEntries(Object.entries(params.sort).map(([k, v]) => [k.replace('user', 'uuid'), v])) - : null, - }) - .then((res) => { - res.data = res.data?.map((m) => { - return { - user: m.uuid, - custom: m.custom, - updated: m.updated, - eTag: m.eTag, - }; - }); - return res; - }); - } else { - return this.objects - .getMemberships({ - uuid: params.userId, - filter: params.filter, - limit: params.limit, - page: params.page, - include: { - customFields: params.include.customFields, - channelFields: params.include.spaceFields, - customChannelFields: params.include.customSpaceFields, - statusField: params.include.statusField, - channelStatusField: params.include.spaceStatusField, - channelTypeField: params.include.spaceTypeField, - totalCount: params.include.totalCount, - }, - sort: - params.sort != null - ? Object.fromEntries(Object.entries(params.sort).map(([k, v]) => [k.replace('space', 'channel'), v])) - : null, - }) - .then((res) => { - res.data = res.data?.map((m) => { - return { - space: m.channel, - custom: m.custom, - updated: m.updated, - eTag: m.eTag, - }; - }); - return res; - }); - } - }; - - this.time = timeEndpoint; - - // --- deprecated ------------------ - this.stop = this.destroy; // -------- - // --- deprecated ------------------ - - // mount crypto - this.encrypt = function (data, key) { - if (typeof key === 'undefined' && modules.cryptoModule) { - const encrypted = modules.cryptoModule.encrypt(data); - return typeof encrypted === 'string' ? encrypted : encode(encrypted); - } else { - return crypto.encrypt(data, key); - } - }; - this.decrypt = function (data, key) { - if (typeof key === 'undefined' && cryptoModule) { - const decrypted = modules.cryptoModule.decrypt(data); - return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted; - } else { - return crypto.decrypt(data, key); - } - }; - - /* config */ - this.getAuthKey = modules.config.getAuthKey.bind(modules.config); - this.setAuthKey = modules.config.setAuthKey.bind(modules.config); - this.getUUID = modules.config.getUUID.bind(modules.config); - this.setUUID = modules.config.setUUID.bind(modules.config); - this.getUserId = modules.config.getUserId.bind(modules.config); - this.setUserId = modules.config.setUserId.bind(modules.config); - this.getFilterExpression = modules.config.getFilterExpression.bind(modules.config); - this.setFilterExpression = modules.config.setFilterExpression.bind(modules.config); - this.setCipherKey = (key) => modules.config.setCipherKey(key, setup, modules); - this.setHeartbeatInterval = modules.config.setHeartbeatInterval.bind(modules.config); - - if (networking.hasModule('proxy')) { - this.setProxy = (proxy) => { - modules.config.setProxy(proxy); - this.reconnect(); - }; - } - } - - getVersion() { - return this._config.getVersion(); - } - - _addPnsdkSuffix(name, suffix) { - this._config._addPnsdkSuffix(name, suffix); - } - - // network hooks to indicate network changes - networkDownDetected() { - this._listenerManager.announceNetworkDown(); - - if (this._config.restore) { - this.disconnect(); - } else { - this.destroy(true); - } - } - - networkUpDetected() { - this._listenerManager.announceNetworkUp(); - this.reconnect(); - } - - static notificationPayload(title, body) { - return new NotificationsPayload(title, body); - } - - static generateUUID() { - return uuidGenerator.createUUID(); - } - - static OPERATIONS = OPERATIONS; - - static CATEGORIES = CATEGORIES; - - static LinearRetryPolicy = RetryPolicy.LinearRetryPolicy; - static ExponentialRetryPolicy = RetryPolicy.ExponentialRetryPolicy; -} diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts new file mode 100644 index 000000000..bfac679c0 --- /dev/null +++ b/src/core/pubnub-common.ts @@ -0,0 +1,3271 @@ +// region Imports +// region Components +import { Listener, ListenerManager } from './components/listener_manager'; +import { SubscriptionManager } from './components/subscription-manager'; +import NotificationsPayload from './components/push_payload'; +import { TokenManager } from './components/token_manager'; +import { AbstractRequest } from './components/request'; +import Crypto from './components/cryptography/index'; +import EventEmitter from './components/eventEmitter'; +import { encode } from './components/base64_codec'; +import uuidGenerator from './components/uuid'; +// endregion + +// region Types +import { Payload, ResultCallback, Status, StatusCallback } from './types/api'; +// endregion + +// region Component Interfaces +import { ClientConfiguration, PrivateClientConfiguration } from './interfaces/configuration'; +import { Cryptography } from './interfaces/cryptography'; +import { Transport } from './interfaces/transport'; +// endregion + +// region Constants +import RequestOperation from './constants/operations'; +import StatusCategory from './constants/categories'; +// endregion + +import { createValidationError, PubNubError } from '../errors/pubnub-error'; +import { PubNubAPIError } from '../errors/pubnub-api-error'; + +// region Event Engine +import { PresenceEventEngine } from '../event-engine/presence/presence'; +import { RetryPolicy } from '../event-engine/core/retryPolicy'; +import { EventEngine } from '../event-engine'; +// endregion +// region Publish & Signal +import * as Publish from './endpoints/publish'; +import * as Signal from './endpoints/signal'; +// endregion +// region Subscription +import { RequestParameters as SubscribeRequestParameters, SubscribeRequest } from './endpoints/subscribe'; +import { ReceiveMessagesSubscribeRequest } from './endpoints/subscriptionUtils/receiveMessages'; +import { HandshakeSubscribeRequest } from './endpoints/subscriptionUtils/handshake'; +import * as Subscription from './types/api/subscription'; +// endregion +// region Presence +import { GetPresenceStateRequest } from './endpoints/presence/get_state'; +import { SetPresenceStateRequest } from './endpoints/presence/set_state'; +import { HeartbeatRequest } from './endpoints/presence/heartbeat'; +import { PresenceLeaveRequest } from './endpoints/presence/leave'; +import { WhereNowRequest } from './endpoints/presence/where_now'; +import { HereNowRequest } from './endpoints/presence/here_now'; +import * as Presence from './types/api/presence'; +// endregion +// region Message Storage +import { DeleteMessageRequest } from './endpoints/history/delete_messages'; +import { MessageCountRequest } from './endpoints/history/message_counts'; +import { GetHistoryRequest } from './endpoints/history/get_history'; +import { FetchMessagesRequest } from './endpoints/fetch_messages'; +import * as History from './types/api/history'; +// endregion +// region Message Actions +import { GetMessageActionsRequest } from './endpoints/actions/get_message_actions'; +import { AddMessageActionRequest } from './endpoints/actions/add_message_action'; +import { RemoveMessageAction } from './endpoints/actions/remove_message_action'; +import * as MessageAction from './types/api/message-action'; +// endregion +// region File sharing +import { PublishFileMessageRequest } from './endpoints/file_upload/publish_file'; +import { GetFileDownloadUrlRequest } from './endpoints/file_upload/get_file_url'; +import { DeleteFileRequest } from './endpoints/file_upload/delete_file'; +import { FilesListRequest } from './endpoints/file_upload/list_files'; +import { SendFileRequest } from './endpoints/file_upload/send_file'; +import * as FileSharing from './types/api/file-sharing'; +import { PubNubFileInterface } from './types/file'; +// endregion +// region PubNub Access Manager +import { RevokeTokenRequest } from './endpoints/access_manager/revoke_token'; +import { GrantTokenRequest } from './endpoints/access_manager/grant_token'; +import { GrantRequest } from './endpoints/access_manager/grant'; +import { AuditRequest } from './endpoints/access_manager/audit'; +import * as PAM from './types/api/access-panager'; +// endregion +// region Entities +import { SubscriptionOptions } from '../entities/commonTypes'; +import { ChannelMetadata } from '../entities/ChannelMetadata'; +import { SubscriptionSet } from '../entities/SubscriptionSet'; +import { ChannelGroup } from '../entities/ChannelGroup'; +import { UserMetadata } from '../entities/UserMetadata'; +import { Channel } from '../entities/Channel'; +// endregion +// region Channel Groups +import PubNubChannelGroups from './pubnub-channel-groups'; +// endregion +// region Push Notifications +import PubNubPushNotifications from './pubnub-push'; +// endregion +// region App Context +import * as AppContext from './types/api/app-context'; +import PubNubObjects from './pubnub-objects'; +// endregion +// region Time +import * as Time from './endpoints/time'; +// endregion +import { encodeString } from './utils'; +import { DownloadFileRequest } from './endpoints/file_upload/download_file'; +// endregion + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +type ClientInstanceConfiguration = { + /** + * Client-provided configuration. + */ + configuration: PrivateClientConfiguration; + + /** + * Transport provider for requests execution. + */ + transport: Transport; + + /** + * REST API endpoints access tokens manager. + */ + tokenManager: TokenManager; + + /** + * Legacy crypto module implementation. + */ + cryptography?: Cryptography; + + /** + * Legacy crypto (legacy data encryption / decryption and request signature support). + */ + crypto?: Crypto; +}; +// endregion + +/** + * Platform-agnostic PubNub client core. + */ +export class PubNubCore< + CryptographyTypes, + FileConstructorParameters, + PlatformFile extends Partial = Record, +> { + /** + * PubNub client configuration. + */ + protected readonly _configuration: PrivateClientConfiguration; + + /** + * Subscription loop manager. + * + * **Note:** Manager created when EventEngine is off. + */ + private readonly subscriptionManager?: SubscriptionManager; + + /** + * Transport for network requests processing. + */ + protected readonly transport: Transport; + + /** + * REST API endpoints access tokens manager. + */ + private readonly tokenManager: TokenManager; + + /** + * Legacy crypto module implementation. + */ + private readonly cryptography?: Cryptography; + + /** + * Legacy crypto (legacy data encryption / decryption and request signature support). + */ + private readonly crypto?: Crypto; + + /** + * Real-time event listeners manager. + */ + protected readonly listenerManager: ListenerManager; + + /** + * User's presence event engine. + */ + private presenceEventEngine?: PresenceEventEngine; + + /** + * Subscription event engine. + */ + private readonly eventEngine?: EventEngine; + + /** + * Client-managed presence information. + */ + private readonly presenceState?: Record; + + /** + * Real-time events emitter. + */ + private readonly eventEmitter: EventEmitter; + + /** + * PubNub App Context REST API entry point. + */ + private readonly _objects: PubNubObjects; + + /** + * PubNub Channel Group REST API entry point. + */ + private readonly _channelGroups: PubNubChannelGroups; + + /** + * PubNub Push Notification REST API entry point. + */ + private readonly _push: PubNubPushNotifications; + + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + private static decoder = new TextDecoder(); + + // -------------------------------------------------------- + // ----------------------- Static ------------------------- + // -------------------------------------------------------- + + // region Static + /** + * Type of REST API endpoint which reported status. + */ + static OPERATIONS = RequestOperation; + + /** + * API call status category. + */ + static CATEGORIES = StatusCategory; + + /** + * Exponential retry policy constructor. + */ + static ExponentialRetryPolicy = RetryPolicy.ExponentialRetryPolicy; + + /** + * Linear retry policy constructor. + */ + static LinearRetryPolicy = RetryPolicy.LinearRetryPolicy; + + /** + * Construct notification payload which will trigger push notification. + * + * @param title - Title which will be shown on notification. + * @param body - Payload which will be sent as part of notification. + * + * @returns Pre-formatted message payload which will trigger push notification. + */ + static notificationPayload(title: string, body: string) { + return new NotificationsPayload(title, body); + } + + /** + * Generate unique identifier. + * + * @returns Unique identifier. + */ + static generateUUID() { + return uuidGenerator.createUUID(); + } + // endregion + + constructor(configuration: ClientInstanceConfiguration) { + this._configuration = configuration.configuration; + this.cryptography = configuration.cryptography; + this.tokenManager = configuration.tokenManager; + this.transport = configuration.transport; + this.crypto = configuration.crypto; + + // API group entry points initialization. + this._objects = new PubNubObjects(this._configuration, this.sendRequest.bind(this)); + this._channelGroups = new PubNubChannelGroups(this._configuration.keySet, this.sendRequest.bind(this)); + this._push = new PubNubPushNotifications(this._configuration.keySet, this.sendRequest.bind(this)); + + // Prepare for real-time events announcement. + this.listenerManager = new ListenerManager(); + this.eventEmitter = new EventEmitter(this.listenerManager); + + if (this._configuration.enableEventEngine) { + let heartbeatInterval = this._configuration.getHeartbeatInterval(); + this.presenceState = {}; + + if (heartbeatInterval) { + this.presenceEventEngine = new PresenceEventEngine({ + heartbeat: this.heartbeat.bind(this), + leave: (parameters) => this.makeUnsubscribe(parameters, () => {}), + heartbeatDelay: () => + new Promise((resolve, reject) => { + heartbeatInterval = this._configuration.getHeartbeatInterval(); + if (!heartbeatInterval) reject(new PubNubError('Heartbeat interval has been reset.')); + else setTimeout(resolve, heartbeatInterval * 1000); + }), + retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + emitStatus: (status) => this.listenerManager.announceStatus(status), + config: this._configuration, + presenceState: this.presenceState, + }); + } + + this.eventEngine = new EventEngine({ + handshake: this.subscribeHandshake.bind(this), + receiveMessages: this.subscribeReceiveMessages.bind(this), + delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + join: this.join.bind(this), + leave: this.leave.bind(this), + leaveAll: this.leaveAll.bind(this), + presenceState: this.presenceState, + config: this._configuration, + emitMessages: (events) => { + try { + events.forEach((event) => this.eventEmitter.emitEvent(event)); + } catch (e) { + const errorStatus: Status = { + error: true, + category: StatusCategory.PNUnknownCategory, + errorData: e as Error, + statusCode: 0, + }; + this.listenerManager.announceStatus(errorStatus); + } + }, + emitStatus: (status) => this.listenerManager.announceStatus(status), + }); + } else { + this.subscriptionManager = new SubscriptionManager( + this._configuration, + this.listenerManager, + this.eventEmitter, + this.makeSubscribe.bind(this), + this.heartbeat.bind(this), + this.makeUnsubscribe.bind(this), + this.time.bind(this), + ); + } + } + + // -------------------------------------------------------- + // -------------------- Configuration ---------------------- + // -------------------------------------------------------- + // region Configuration + + /** + * PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + */ + public get configuration(): ClientConfiguration { + return this._configuration; + } + + /** + * Current PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + * + * @deprecated Use {@link configuration} getter instead. + */ + public get _config(): ClientConfiguration { + return this.configuration; + } + + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ + get authKey(): string | undefined { + return this._configuration.authKey ?? undefined; + } + + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ + getAuthKey(): string | undefined { + return this.authKey; + } + + /** + * Change REST API endpoint access authorization key. + * + * @param authKey - New authorization key which should be used with new requests. + */ + setAuthKey(authKey: string): void { + this._configuration.setAuthKey(authKey); + } + + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + get userId(): string { + return this._configuration.userId!; + } + + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + set userId(value: string) { + if (!value || typeof value !== 'string' || value.trim().length === 0) + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); + this._configuration.userId = value; + } + + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + getUserId(): string { + return this._configuration.userId!; + } + + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + setUserId(value: string): void { + if (!value || typeof value !== 'string' || value.trim().length === 0) + throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); + this._configuration.userId = value; + } + + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + get filterExpression(): string | undefined { + return this._configuration.getFilterExpression() ?? undefined; + } + + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + getFilterExpression(): string | undefined { + return this.filterExpression; + } + + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + set filterExpression(expression: string | null | undefined) { + this._configuration.setFilterExpression(expression); + } + + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + setFilterExpression(expression: string | null): void { + this.filterExpression = expression; + } + + /** + * Dta encryption / decryption key. + * + * @returns Currently used key for data encryption / decryption. + */ + get cipherKey(): string | undefined { + return this._configuration.getCipherKey(); + } + + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + set cipherKey(key: string | undefined) { + this._configuration.setCipherKey(key); + } + + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + setCipherKey(key: string): void { + this.cipherKey = key; + } + + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ + set heartbeatInterval(interval: number) { + this._configuration.setHeartbeatInterval(interval); + } + + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ + setHeartbeatInterval(interval: number): void { + this.heartbeatInterval = interval; + } + + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + getVersion(): string { + return this._configuration.getVersion(); + } + + /** + * Add framework's prefix. + * + * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. + * @param suffix - Suffix with information about framework. + */ + _addPnsdkSuffix(name: string, suffix: string | number) { + this._configuration._addPnsdkSuffix(name, suffix); + } + + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + * + * @deprecated Use the {@link getUserId} or {@link userId} getter instead. + */ + getUUID(): string { + return this.userId; + } + + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + * + * @deprecated Use the {@link PubNubCore#setUserId} or {@link PubNubCore#userId} setter instead. + */ + setUUID(value: string) { + this.userId = value; + } + + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + get customEncrypt(): ((data: string) => string) | undefined { + return this._configuration.getCustomEncrypt(); + } + + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + get customDecrypt(): ((data: string) => string) | undefined { + return this._configuration.getCustomDecrypt(); + } + // endregion + // endregion + + // -------------------------------------------------------- + // ---------------------- Entities ------------------------ + // -------------------------------------------------------- + // region Entities + + /** + * Create a `Channel` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel name. + * @returns `Channel` entity. + */ + public channel(name: string): Channel { + return new Channel(name, this.eventEmitter, this); + } + + /** + * Create a `ChannelGroup` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel group name. + * @returns `ChannelGroup` entity. + */ + public channelGroup(name: string): ChannelGroup { + return new ChannelGroup(name, this.eventEmitter, this); + } + + /** + * Create a `ChannelMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique channel metadata object identifier. + * @returns `ChannelMetadata` entity. + */ + public channelMetadata(id: string): ChannelMetadata { + return new ChannelMetadata(id, this.eventEmitter, this); + } + + /** + * Create a `UserMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique user metadata object identifier. + * @returns `UserMetadata` entity. + */ + public userMetadata(id: string): UserMetadata { + return new UserMetadata(id, this.eventEmitter, this); + } + + /** + * Create subscriptions set object. + * + * @param parameters - Subscriptions set configuration parameters. + */ + public subscriptionSet(parameters: { + channels?: string[]; + channelGroups?: string[]; + subscriptionOptions?: SubscriptionOptions; + }): SubscriptionSet { + return new SubscriptionSet({ ...parameters, eventEmitter: this.eventEmitter, pubnub: this }); + } + // endregion + + // -------------------------------------------------------- + // ----------------------- Common ------------------------- + // -------------------------------------------------------- + + // region Common + /** + * Schedule request execution. + * + * @param request - REST API request. + * @param callback - Request completion handler callback. + * + * @returns Asynchronous request execution and response parsing result. + */ + private sendRequest( + request: AbstractRequest, + callback: ResultCallback, + ): void; + + /** + * Schedule request execution. + * + * @param request - REST API request. + * + * @returns Asynchronous request execution and response parsing result. + */ + private async sendRequest(request: AbstractRequest): Promise; + + /** + * Schedule request execution. + * + * @param request - REST API request. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous request execution and response parsing result or `void` in case if + * `callback` provided. + * + * @throws PubNubError in case of request processing error. + */ + private async sendRequest( + request: AbstractRequest, + callback?: ResultCallback, + ): Promise { + // Validate user-input. + const validationResult = request.validate(); + if (validationResult) { + if (callback) return callback(createValidationError(validationResult), null); + throw new PubNubError('Validation failed, check status for details', createValidationError(validationResult)); + } + + // Complete request configuration. + const transportRequest = request.request(); + if (transportRequest.formData && transportRequest.formData.length > 0) { + // Set 300 seconds file upload request delay. + transportRequest.timeout = 300; + } else { + if (request.operation() === RequestOperation.PNSubscribeOperation) + transportRequest.timeout = this._configuration.getSubscribeTimeout(); + else transportRequest.timeout = this._configuration.getTransactionTimeout(); + } + + // API request processing status. + const status: Status = { + error: false, + operation: request.operation(), + category: StatusCategory.PNAcknowledgmentCategory, + statusCode: 0, + }; + + const [sendableRequest, cancellationController] = this.transport.makeSendable(transportRequest); + + /** + * **Important:** Because of multiple environments where JS SDK can be used control over + * cancellation had to be inverted to let transport provider solve request cancellation task + * more efficiently. As result, cancellation controller can be retrieved and used only after + * request will be scheduled by transport provider. + */ + request.cancellationController = cancellationController ? cancellationController : null; + + return sendableRequest + .then((response) => { + status.statusCode = response.status; + + // Handle special case when request completed but not fully processed by PubNub service. + if (response.status !== 200 && response.status !== 204) { + const contentType = response.headers['content-type']; + if (contentType || contentType.indexOf('javascript') !== -1 || contentType.indexOf('json') !== -1) { + const json = JSON.parse(PubNubCore.decoder.decode(response.body)) as Payload; + if (typeof json === 'object' && 'error' in json && json.error && typeof json.error === 'object') + status.errorData = json.error; + } + } + + return request.parse(response); + }) + .then((parsed) => { + // Notify callback (if possible). + if (callback) return callback(status, parsed); + + return parsed; + }) + .catch((error: Error) => { + const apiError = !(error instanceof PubNubAPIError) ? PubNubAPIError.create(error) : error; + + // Notify callback (if possible). + if (callback) return callback(apiError.toStatus(request.operation()), null); + + throw apiError.toPubNubError( + request.operation(), + 'REST API request processing error, check status for details', + ); + }); + } + + /** + * Unsubscribe from all channels and groups. + * + * @param [isOffline] - Whether `offline` presence should be notified or not. + */ + public destroy(isOffline?: boolean): void { + if (this.subscriptionManager) { + this.subscriptionManager.unsubscribeAll(isOffline); + this.subscriptionManager.disconnect(); + } else if (this.eventEngine) this.eventEngine.dispose(); + } + + /** + * Unsubscribe from all channels and groups. + * + * @deprecated Use {@link destroy} method instead. + */ + public stop(): void { + this.destroy(); + } + // endregion + + // -------------------------------------------------------- + // ----------------------- Listener ----------------------- + // -------------------------------------------------------- + // region Listener + + /** + * Register real-time events listener. + * + * @param listener - Listener with event callbacks to handle different types of events. + */ + public addListener(listener: Listener): void { + this.listenerManager.addListener(listener); + } + + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + */ + public removeListener(listener: Listener): void { + this.listenerManager.removeListener(listener); + } + + /** + * Clear all real-time event listeners. + */ + public removeAllListeners(): void { + this.listenerManager.removeAllListeners(); + } + + // endregion + + // -------------------------------------------------------- + // ---------------------- Publish API --------------------- + // -------------------------------------------------------- + // region Publish API + + /** + * Publish data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public publish(parameters: Publish.PublishParameters, callback: ResultCallback): void; + + /** + * Publish data to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous publish data response. + */ + public async publish(parameters: Publish.PublishParameters): Promise; + + /** + * Publish data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous publish data response or `void` in case if `callback` provided. + */ + async publish( + parameters: Publish.PublishParameters, + callback?: ResultCallback, + ): Promise { + const request = new Publish.PublishRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // -------------------------------------------------------- + // ---------------------- Signal API ---------------------- + // -------------------------------------------------------- + // region Signal API + + /** + * Signal data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public signal(parameters: Signal.SignalParameters, callback: ResultCallback): void; + + /** + * Signal data to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous signal data response. + */ + public async signal(parameters: Signal.SignalParameters): Promise; + + /** + * Signal data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous signal data response or `void` in case if `callback` provided. + */ + async signal( + parameters: Signal.SignalParameters, + callback?: ResultCallback, + ): Promise { + const request = new Signal.SignalRequest({ + ...parameters, + keySet: this._configuration.keySet, + }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // -------------------------------------------------------- + // ----------------------- Fire API ---------------------- + // -------------------------------------------------------- + // region Fire API + + /** + * `Fire` a data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link publish} method instead. + */ + public fire(parameters: Publish.PublishParameters, callback: ResultCallback): void; + + /** + * `Fire` a data to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous signal data response. + * + * @deprecated Use {@link publish} method instead. + */ + public async fire(parameters: Publish.PublishParameters): Promise; + + /** + * `Fire` a data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous signal data response or `void` in case if `callback` provided. + * + * @deprecated Use {@link publish} method instead. + */ + async fire( + parameters: Publish.PublishParameters, + callback?: ResultCallback, + ): Promise { + callback ??= () => {}; + return this.publish({ ...parameters, replicate: false, storeInHistory: false }, callback); + } + // endregion + + // -------------------------------------------------------- + // -------------------- Subscribe API --------------------- + // -------------------------------------------------------- + // region Subscribe API + + /** + * Get list of channels on which PubNub client currently subscribed. + * + * @returns List of active channels. + */ + public getSubscribedChannels(): string[] { + if (this.subscriptionManager) return this.subscriptionManager.subscribedChannels; + else if (this.eventEngine) return this.eventEngine.getSubscribedChannels(); + + return []; + } + + /** + * Get list of channel groups on which PubNub client currently subscribed. + * + * @returns List of active channel groups. + */ + public getSubscribedChannelGroups(): string[] { + if (this.subscriptionManager) return this.subscriptionManager.subscribedChannelGroups; + else if (this.eventEngine) return this.eventEngine.getSubscribedChannelGroups(); + + return []; + } + + /** + * Subscribe to specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ + public subscribe(parameters: Subscription.SubscribeParameters): void { + if (this.subscriptionManager) this.subscriptionManager.subscribe(parameters); + else if (this.eventEngine) this.eventEngine.subscribe(parameters); + } + + /** + * Perform subscribe request. + * + * **Note:** Method passed into managers to let them use it when required. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + private makeSubscribe( + parameters: Omit, + callback: ResultCallback, + ): void { + const request = new SubscribeRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + getFileUrl: this.getFileUrl.bind(this), + }); + + this.sendRequest(request, (status, result) => { + if (this.subscriptionManager && this.subscriptionManager.abort?.identifier === request.requestIdentifier) + this.subscriptionManager.abort = null; + + callback(status, result); + }); + + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + if (this.subscriptionManager) { + // Creating identifiable abort caller. + const callableAbort = () => request.abort(); + callableAbort.identifier = request.requestIdentifier; + + this.subscriptionManager.abort = callableAbort; + } + } + + /** + * Unsubscribe from specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ + public unsubscribe(parameters: Presence.PresenceLeaveParameters): void { + if (this.subscriptionManager) this.subscriptionManager.unsubscribe(parameters); + else if (this.eventEngine) this.eventEngine.unsubscribe(parameters); + } + + /** + * Perform unsubscribe request. + * + * **Note:** Method passed into managers to let them use it when required. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + private makeUnsubscribe(parameters: Presence.PresenceLeaveParameters, callback: StatusCallback): void { + this.sendRequest( + new PresenceLeaveRequest({ + ...parameters, + keySet: this._configuration.keySet, + }), + callback, + ); + } + + /** + * Unsubscribe from all channels and groups. + */ + public unsubscribeAll() { + if (this.subscriptionManager) this.subscriptionManager.unsubscribeAll(); + else if (this.eventEngine) this.eventEngine.unsubscribeAll(); + } + + /** + * Temporarily disconnect from real-time events stream. + */ + public disconnect(): void { + if (this.subscriptionManager) this.subscriptionManager.disconnect(); + else if (this.eventEngine) this.eventEngine.disconnect(); + } + + /** + * Restore connection to the real-time events stream. + * + * @param parameters - Reconnection catch up configuration. **Note:** available only with + * enabled event engine. + */ + public reconnect(parameters?: { timetoken?: string; region?: number }): void { + if (this.subscriptionManager) this.subscriptionManager.reconnect(); + else if (this.eventEngine) this.eventEngine.reconnect(parameters ?? {}); + } + + /** + * Event engine handshake subscribe. + * + * @param parameters - Request configuration parameters. + */ + private async subscribeHandshake(parameters: Subscription.CancelableSubscribeParameters) { + const request = new HandshakeSubscribeRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + getFileUrl: this.getFileUrl.bind(this), + }); + + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); + + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response.cursor; + }); + } + + /** + * Event engine receive messages subscribe. + * + * @param parameters - Request configuration parameters. + */ + private async subscribeReceiveMessages(parameters: Subscription.CancelableSubscribeParameters) { + const request = new ReceiveMessagesSubscribeRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + getFileUrl: this.getFileUrl.bind(this), + }); + + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); + + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response; + }); + } + // endregion + + // -------------------------------------------------------- + // ------------------ Message Action API ------------------ + // -------------------------------------------------------- + // region Message Action API + + // region List + /** + * Get reactions to a specific message. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public getMessageActions( + parameters: MessageAction.GetMessageActionsParameters, + callback: ResultCallback, + ): void; + + /** + * Get reactions to a specific message. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get reactions response. + */ + public async getMessageActions( + parameters: MessageAction.GetMessageActionsParameters, + ): Promise; + + /** + * Get reactions to a specific message. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get reactions response or `void` in case if `callback` provided. + */ + async getMessageActions( + parameters: MessageAction.GetMessageActionsParameters, + callback?: ResultCallback, + ): Promise { + const request = new GetMessageActionsRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Add + /** + * Add a reaction to a specific message. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public addMessageAction( + parameters: MessageAction.AddMessageActionParameters, + callback: ResultCallback, + ): void; + + /** + * Add a reaction to a specific message. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous add a reaction response. + */ + public async addMessageAction( + parameters: MessageAction.AddMessageActionParameters, + ): Promise; + + /** + * Add a reaction to a specific message. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add a reaction response or `void` in case if `callback` provided. + */ + async addMessageAction( + parameters: MessageAction.AddMessageActionParameters, + callback?: ResultCallback, + ): Promise { + const request = new AddMessageActionRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Remove + /** + * Remove a reaction from a specific message. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public removeMessageAction( + parameters: MessageAction.RemoveMessageActionParameters, + callback: ResultCallback, + ): void; + + /** + * Remove a reaction from a specific message. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous remove a reaction response. + */ + public async removeMessageAction( + parameters: MessageAction.RemoveMessageActionParameters, + ): Promise; + + /** + * Remove a reaction from a specific message. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous remove a reaction response or `void` in case if `callback` provided. + */ + async removeMessageAction( + parameters: MessageAction.RemoveMessageActionParameters, + callback?: ResultCallback, + ): Promise { + const request = new RemoveMessageAction({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + // endregion + + // -------------------------------------------------------- + // --------------- Message Persistence API ---------------- + // -------------------------------------------------------- + // region Message Persistence API + + // region Fetch Messages + /** + * Fetch messages history for channels. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public fetchMessages( + parameters: History.FetchMessagesParameters, + callback: ResultCallback, + ): void; + + /** + * Fetch messages history for channels. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous fetch messages response. + */ + public async fetchMessages(parameters: History.FetchMessagesParameters): Promise; + + /** + * Fetch messages history for channels. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous fetch messages response or `void` in case if `callback` provided. + */ + async fetchMessages( + parameters: History.FetchMessagesParameters, + callback?: ResultCallback, + ): Promise { + const request = new FetchMessagesRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + getFileUrl: this.getFileUrl.bind(this), + }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Delete Messages + /** + * Delete messages from the channel history. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated + */ + public deleteMessages( + parameters: History.DeleteMessagesParameters, + callback: ResultCallback, + ): void; + + /** + * Delete messages from the channel history. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous delete messages response. + * + * @deprecated + */ + public async deleteMessages(parameters: History.DeleteMessagesParameters): Promise; + + /** + * Delete messages from the channel history. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous delete messages response or `void` in case if `callback` provided. + * + * @deprecated + */ + async deleteMessages( + parameters: History.DeleteMessagesParameters, + callback?: ResultCallback, + ): Promise { + const request = new DeleteMessageRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Count Messages + /** + * Count messages from the channels' history. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public messageCounts( + parameters: History.MessageCountParameters, + callback: ResultCallback, + ): void; + + /** + * Count messages from the channels' history. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous count messages response. + */ + public async messageCounts(parameters: History.MessageCountParameters): Promise; + + /** + * Count messages from the channels' history. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous count messages response or `void` in case if `callback` provided. + */ + async messageCounts( + parameters: History.MessageCountParameters, + callback?: ResultCallback, + ): Promise { + const request = new MessageCountRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Deprecated + // region Fetch History + /** + * Fetch single channel history. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated + */ + public history(parameters: History.GetHistoryParameters, callback: ResultCallback): void; + + /** + * Fetch single channel history. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous fetch channel history response. + * + * @deprecated + */ + public async history(parameters: History.GetHistoryParameters): Promise; + + /** + * Fetch single channel history. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous fetch channel history response or `void` in case if `callback` provided. + * + * @deprecated + */ + async history( + parameters: History.GetHistoryParameters, + callback?: ResultCallback, + ): Promise { + const request = new GetHistoryRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + // endregion + // endregion + + // -------------------------------------------------------- + // --------------------- Presence API --------------------- + // -------------------------------------------------------- + // region Presence API + + // region Here Now + /** + * Get channel's presence information. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public hereNow(parameters: Presence.HereNowParameters, callback: ResultCallback): void; + + /** + * Get channel presence information. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get channel's presence response. + */ + public async hereNow(parameters: Presence.HereNowParameters): Promise; + + /** + * Get channel's presence information. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get channel's presence response or `void` in case if `callback` provided. + */ + async hereNow( + parameters: Presence.HereNowParameters, + callback?: ResultCallback, + ): Promise { + const request = new HereNowRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Where Now + /** + * Get user's presence information. + * + * Get list of channels to which `uuid` currently subscribed. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public whereNow(parameters: Presence.WhereNowParameters, callback: ResultCallback): void; + + /** + * Get user's presence information. + * + * Get list of channels to which `uuid` currently subscribed. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get user's presence response. + */ + public async whereNow(parameters: Presence.WhereNowParameters): Promise; + + /** + * Get user's presence information. + * + * Get list of channels to which `uuid` currently subscribed. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get user's presence response or `void` in case if `callback` provided. + */ + async whereNow( + parameters: Presence.WhereNowParameters, + callback?: ResultCallback, + ): Promise { + const request = new WhereNowRequest({ + uuid: parameters.uuid ?? this._configuration.userId!, + keySet: this._configuration.keySet, + }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Get Presence State + /** + * Get associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public getState( + parameters: Presence.GetPresenceStateParameters, + callback: ResultCallback, + ): void; + + /** + * Get associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get associated user's data response. + */ + public async getState(parameters: Presence.GetPresenceStateParameters): Promise; + + /** + * Get associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get user's data response or `void` in case if `callback` provided. + */ + async getState( + parameters: Presence.GetPresenceStateParameters, + callback?: ResultCallback, + ): Promise { + const request = new GetPresenceStateRequest({ + ...parameters, + uuid: parameters.uuid ?? this._configuration.userId, + keySet: this._configuration.keySet, + }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Set Presence State + /** + * Set associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public setState( + parameters: Presence.SetPresenceStateParameters | Presence.SetPresenceStateWithHeartbeatParameters, + callback: ResultCallback, + ): void; + + /** + * Set associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous set associated user's data response. + */ + public async setState( + parameters: Presence.SetPresenceStateParameters | Presence.SetPresenceStateWithHeartbeatParameters, + ): Promise; + + /** + * Set associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set user's data response or `void` in case if `callback` provided. + */ + async setState( + parameters: Presence.SetPresenceStateParameters | Presence.SetPresenceStateWithHeartbeatParameters, + callback?: ResultCallback, + ): Promise { + const { keySet, userId: userId } = this._configuration; + const heartbeat = this._configuration.getPresenceTimeout(); + let request: AbstractRequest; + + // Maintain presence information (if required). + if (this._configuration.enableEventEngine && this.presenceState) { + const presenceState = this.presenceState; + parameters.channels?.forEach((channel) => (presenceState[channel] = parameters.state)); + + if ('channelGroups' in parameters) { + parameters.channelGroups?.forEach((group) => (presenceState[group] = parameters.state)); + } + } + + // Check whether state should be set with heartbeat or not. + if ('withHeartbeat' in parameters) { + request = new HeartbeatRequest({ ...parameters, keySet, heartbeat }); + } else { + request = new SetPresenceStateRequest({ ...parameters, keySet, uuid: userId! }); + } + + // Update state used by subscription manager. + if (this.subscriptionManager) this.subscriptionManager.setState(parameters); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Change presence state + /** + * Manual presence management. + * + * @param parameters - Desired presence state for provided list of channels and groups. + */ + public presence(parameters: { connected: boolean; channels?: string[]; channelGroups?: string[] }) { + this.subscriptionManager?.changePresence(parameters); + } + // endregion + + // region Heartbeat + /** + * Announce user presence + * + * @param parameters - Desired presence state for provided list of channels and groups. + * @param callback - Request completion handler callback. + */ + private async heartbeat( + parameters: Presence.PresenceHeartbeatParameters, + callback?: ResultCallback, + ) { + const request = new HeartbeatRequest({ + ...parameters, + keySet: this._configuration.keySet, + }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Join + /** + * Announce user `join` on specified list of channels and groups. + * + * @param parameters - List of channels and groups where `join` event should be sent. + */ + private join(parameters: { channels?: string[]; groups?: string[] }) { + this.presenceEventEngine?.join(parameters); + } + // endregion + + // region Leave + /** + * Announce user `leave` on specified list of channels and groups. + * + * @param parameters - List of channels and groups where `leave` event should be sent. + */ + private leave(parameters: { channels?: string[]; groups?: string[] }) { + this.presenceEventEngine?.leave(parameters); + } + + /** + * Announce user `leave` on all subscribed channels. + */ + private leaveAll() { + this.presenceEventEngine?.leaveAll(); + } + // endregion + // endregion + + // -------------------------------------------------------- + // ------------------------ PAM API ----------------------- + // -------------------------------------------------------- + // region PAM API + + // region Grant + /** + * Grant token permission. + * + * Generate access token with requested permissions. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public grantToken(parameters: PAM.GrantTokenParameters, callback: ResultCallback): void; + + /** + * Grant token permission. + * + * Generate access token with requested permissions. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous grant token response. + */ + public async grantToken(parameters: PAM.GrantTokenParameters): Promise; + + /** + * Grant token permission. + * + * Generate access token with requested permissions. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous grant token response or `void` in case if `callback` provided. + */ + async grantToken( + parameters: PAM.GrantTokenParameters, + callback?: ResultCallback, + ): Promise { + const request = new GrantTokenRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Revoke + /** + * Revoke token permission. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public revokeToken(parameters: PAM.RevokeParameters, callback: ResultCallback): void; + + /** + * Revoke token permission. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous revoke token response. + */ + public async revokeToken(parameters: PAM.RevokeParameters): Promise; + + /** + * Revoke token permission. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous revoke token response or `void` in case if `callback` provided. + */ + async revokeToken( + parameters: PAM.RevokeParameters, + callback?: ResultCallback, + ): Promise { + const request = new RevokeTokenRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Token Manipulation + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ + public get token(): string | undefined { + return this.tokenManager.getToken(); + } + + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ + public getToken(): string | undefined { + return this.token; + } + + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ + public set token(token: string | undefined) { + this.tokenManager.setToken(token); + } + + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ + public setToken(token: string | undefined): void { + this.token = token; + } + + /** + * Parse access token. + * + * Parse token to see what permissions token owner has. + * + * @param token - Token which should be parsed. + * + * @returns Token's permissions information for the resources. + */ + public parseToken(token: string) { + return this.tokenManager.parseToken(token); + } + // endregion + + // region Deprecated + // region Grant Auth Permissions + /** + * Grant auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + public grant(parameters: PAM.GrantParameters, callback: ResultCallback): void; + + /** + * Grant auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous grant auth key(s) permissions response. + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + public async grant(parameters: PAM.GrantParameters): Promise; + + /** + * Grant auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous grant auth key(s) permissions or `void` in case if `callback` provided. + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + async grant( + parameters: PAM.GrantParameters, + callback?: ResultCallback, + ): Promise { + const request = new GrantRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Audit Permissions + /** + * Audit auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated + */ + public audit(parameters: PAM.AuditParameters, callback: ResultCallback): void; + + /** + * Audit auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous audit auth key(s) permissions response. + * + * @deprecated + */ + public async audit(parameters: PAM.AuditParameters): Promise; + + /** + * Audit auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @deprecated + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + async audit( + parameters: PAM.AuditParameters, + callback?: ResultCallback, + ): Promise { + const request = new AuditRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + // endregion + // endregion + + // -------------------------------------------------------- + // ------------------- App Context API -------------------- + // -------------------------------------------------------- + // region App Context API + + /** + * PubNub App Context API group. + */ + get objects(): PubNubObjects { + return this._objects; + } + + // region Deprecated API + /** + * Fetch a paginated list of User objects. + * + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + public fetchUsers( + callback: ResultCallback>, + ): void; + + /** + * Fetch a paginated list of User objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + public fetchUsers( + parameters: AppContext.GetAllMetadataParameters>, + callback: ResultCallback>, + ): void; + + /** + * Fetch a paginated list of User objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all User objects response. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + public async fetchUsers( + parameters?: AppContext.GetAllMetadataParameters>, + ): Promise>; + + /** + Fetch a paginated list of User objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all User objects response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + public async fetchUsers( + parametersOrCallback?: + | AppContext.GetAllMetadataParameters> + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + return this.objects._getAllUUIDMetadata(parametersOrCallback, callback); + } + + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + public fetchUser( + callback: ResultCallback>, + ): void; + + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param parameters - Request configuration parameters. Will fetch User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + public fetchUser( + parameters: AppContext.GetUUIDMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param [parameters] - Request configuration parameters. Will fetch User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous get User object response. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + public async fetchUser( + parameters?: AppContext.GetUUIDMetadataParameters, + ): Promise>; + + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get User object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + async fetchUser( + parametersOrCallback?: + | AppContext.GetUUIDMetadataParameters + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + return this.objects._getUUIDMetadata(parametersOrCallback, callback); + } + + /** + * Create User object. + * + * @param parameters - Request configuration parameters. Will create User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + public createUser( + parameters: AppContext.SetUUIDMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Create User object. + * + * @param parameters - Request configuration parameters. Will create User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous create User object response. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + public async createUser( + parameters: AppContext.SetUUIDMetadataParameters, + ): Promise>; + + /** + * Create User object. + * + * @param parameters - Request configuration parameters. Will create User object for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous create User object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + async createUser( + parameters: AppContext.SetUUIDMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + return this.objects._setUUIDMetadata(parameters, callback); + } + + /** + * Update User object. + * + * @param parameters - Request configuration parameters. Will update User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + public updateUser( + parameters: AppContext.SetUUIDMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Update User object. + * + * @param parameters - Request configuration parameters. Will update User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous update User object response. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + public async updateUser( + parameters: AppContext.SetUUIDMetadataParameters, + ): Promise>; + + /** + * Update User object. + * + * @param parameters - Request configuration parameters. Will update User object for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update User object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + async updateUser( + parameters: AppContext.SetUUIDMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + return this.objects._setUUIDMetadata(parameters, callback); + } + + /** + * Remove a specific User object. + * + * @param callback - Request completion handler callback. Will remove User object for currently + * configured PubNub client `uuid` if not set. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + public removeUser(callback: ResultCallback): void; + + /** + * Remove a specific User object. + * + * @param parameters - Request configuration parameters. Will remove User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + public removeUser( + parameters: AppContext.RemoveUUIDMetadataParameters, + callback: ResultCallback, + ): void; + + /** + * Remove a specific User object. + * + * @param [parameters] - Request configuration parameters. Will remove User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous User object remove response. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + public async removeUser( + parameters?: AppContext.RemoveUUIDMetadataParameters, + ): Promise; + + /** + * Remove a specific User object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous User object remove response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + public async removeUser( + parametersOrCallback?: + | AppContext.RemoveUUIDMetadataParameters + | ResultCallback, + callback?: ResultCallback, + ): Promise { + return this.objects._removeUUIDMetadata(parametersOrCallback, callback); + } + + /** + * Fetch a paginated list of Space objects. + * + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + public fetchSpaces( + callback: ResultCallback>, + ): void; + + /** + * Fetch a paginated list of Space objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + public fetchSpaces( + parameters: AppContext.GetAllMetadataParameters>, + callback: ResultCallback>, + ): void; + + /** + * Fetch a paginated list of Space objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all Space objects response. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + public async fetchSpaces( + parameters?: AppContext.GetAllMetadataParameters>, + ): Promise>; + + /** + * Fetch a paginated list of Space objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Space objects response or `void` in case if `callback` + * provided. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + async fetchSpaces( + parametersOrCallback?: + | AppContext.GetAllMetadataParameters> + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + return this.objects._getAllChannelMetadata(parametersOrCallback, callback); + } + + /** + * Fetch a specific Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. + */ + public fetchSpace( + parameters: AppContext.GetChannelMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Fetch a specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get Channel metadata response. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. + */ + public async fetchSpace( + parameters: AppContext.GetChannelMetadataParameters, + ): Promise>; + + /** + * Fetch a specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Space object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. + */ + async fetchSpace( + parameters: AppContext.GetChannelMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + return this.objects._getChannelMetadata(parameters, callback); + } + + /** + * Create specific Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + public createSpace( + parameters: AppContext.SetChannelMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Create specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous create Space object response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + public async createSpace( + parameters: AppContext.SetChannelMetadataParameters, + ): Promise>; + + /** + * Create specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous create Space object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + async createSpace( + parameters: AppContext.SetChannelMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + return this.objects._setChannelMetadata(parameters, callback); + } + + /** + * Update specific Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + public updateSpace( + parameters: AppContext.SetChannelMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Update specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous update Space object response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + public async updateSpace( + parameters: AppContext.SetChannelMetadataParameters, + ): Promise>; + + /** + * Update specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update Space object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + async updateSpace( + parameters: AppContext.SetChannelMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + return this.objects._setChannelMetadata(parameters, callback); + } + + /** + * Remove Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. + */ + public removeSpace( + parameters: AppContext.RemoveChannelMetadataParameters, + callback: ResultCallback, + ): void; + + /** + * Remove a specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous Space object remove response. + * + * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. + */ + public async removeSpace( + parameters: AppContext.RemoveChannelMetadataParameters, + ): Promise; + + /** + * Remove a specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Space object remove response or `void` in case if `callback` + * provided. + * + * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. + */ + async removeSpace( + parameters: AppContext.RemoveChannelMetadataParameters, + callback?: ResultCallback, + ): Promise { + return this.objects._removeChannelMetadata(parameters, callback); + } + + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} + * methods instead. + */ + public fetchMemberships< + RelationCustom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters, + callback: ResultCallback< + | AppContext.SpaceMembershipsResponse + | AppContext.UserMembersResponse + >, + ): void; + + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get specific Space members or specific User memberships response. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} + * methods instead. + */ + public async fetchMemberships< + RelationCustom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters, + ): Promise< + | AppContext.SpaceMembershipsResponse + | AppContext.UserMembersResponse + >; + + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get specific Space members or specific User memberships response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} + * methods instead. + */ + public async fetchMemberships< + RelationCustom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters, + callback?: ResultCallback< + | AppContext.SpaceMembershipsResponse + | AppContext.UserMembersResponse + >, + ): Promise< + | AppContext.SpaceMembershipsResponse + | AppContext.UserMembersResponse + | void + > { + return this.objects.fetchMemberships(parameters, callback); + } + + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + public addMemberships< + Custom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, + callback: ResultCallback< + AppContext.SetMembershipsResponse | AppContext.SetMembersResponse + >, + ): void; + + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous add members to specific Space or memberships specific User response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + public async addMemberships< + Custom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, + ): Promise< + AppContext.SetMembershipsResponse | AppContext.SetMembersResponse + >; + + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add members to specific Space or memberships specific User response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + async addMemberships< + Custom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, + callback?: ResultCallback< + AppContext.SetMembershipsResponse | AppContext.SetMembersResponse + >, + ) { + return this.objects.addMemberships(parameters, callback); + } + + /** + * Update specific Space members or User memberships. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + public updateMemberships< + Custom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, + callback: ResultCallback< + AppContext.SetMembershipsResponse | AppContext.SetMembersResponse + >, + ): void; + + /** + * Update specific Space members or User memberships. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous update Space members or User memberships response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + public async updateMemberships< + Custom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, + ): Promise< + AppContext.SetMembershipsResponse | AppContext.SetMembersResponse + >; + + /** + * Update specific Space members or User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update Space members or User memberships response or `void` in case + * if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + async updateMemberships< + Custom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, + callback?: ResultCallback< + AppContext.SetMembershipsResponse | AppContext.SetMembersResponse + >, + ) { + return this.objects.addMemberships(parameters, callback); + } + + /** + * Remove User membership. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} + * methods instead + * from `objects` API group.. + */ + public removeMemberships< + RelationCustom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembersParameters | AppContext.RemoveMembershipsParameters, + callback: ResultCallback< + | AppContext.RemoveMembersResponse + | AppContext.RemoveMembershipsResponse + >, + ): void; + + /** + * Remove User membership. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous memberships modification response. + * + * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} + * methods instead + * from `objects` API group.. + */ + public async removeMemberships< + RelationCustom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembersParameters | AppContext.RemoveMembershipsParameters, + ): Promise>; + + /** + * Remove User membership. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous memberships modification response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} + * methods instead + * from `objects` API group.. + */ + public async removeMemberships< + RelationCustom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembersParameters | AppContext.RemoveMembershipsParameters, + callback?: ResultCallback< + | AppContext.RemoveMembersResponse + | AppContext.RemoveMembershipsResponse + >, + ): Promise< + | AppContext.RemoveMembersResponse + | AppContext.RemoveMembershipsResponse + | void + > { + if ('spaceId' in parameters) { + const spaceParameters = parameters as AppContext.RemoveMembersParameters; + const requestParameters = { + channel: spaceParameters.spaceId ?? spaceParameters.channel, + uuids: spaceParameters.userIds ?? spaceParameters.uuids, + limit: 0, + }; + if (callback) return this.objects.removeChannelMembers(requestParameters, callback); + return this.objects.removeChannelMembers(requestParameters); + } + + const userParameters = parameters as AppContext.RemoveMembershipsParameters; + const requestParameters = { + uuid: userParameters.userId, + channels: userParameters.spaceIds ?? userParameters.channels, + limit: 0, + }; + if (callback) return this.objects.removeMemberships(requestParameters, callback); + return this.objects.removeMemberships(requestParameters); + } + // endregion + // endregion + + // -------------------------------------------------------- + // ----------------- Channel Groups API ------------------- + // -------------------------------------------------------- + // region Channel Groups API + + /** + * PubNub Channel Groups API group. + */ + get channelGroups(): PubNubChannelGroups { + return this._channelGroups; + } + // endregion + + // -------------------------------------------------------- + // ---------------- Push Notifications API ----------------- + // -------------------------------------------------------- + // region Push Notifications API + + /** + * PubNub Push Notifications API group. + */ + get push(): PubNubPushNotifications { + return this._push; + } + // endregion + + // -------------------------------------------------------- + // ------------------ File sharing API -------------------- + // -------------------------------------------------------- + // region File sharing API + + // region Send + /** + * Share file to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public sendFile( + parameters: FileSharing.SendFileParameters, + callback: ResultCallback, + ): void; + + /** + * Share file to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous file sharing response. + */ + public async sendFile( + parameters: FileSharing.SendFileParameters, + ): Promise; + + /** + * Share file to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous file sharing response or `void` in case if `callback` provided. + */ + public async sendFile( + parameters: FileSharing.SendFileParameters, + callback?: ResultCallback, + ): Promise { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + + const sendFileRequest = new SendFileRequest({ + ...parameters, + keySet: this._configuration.keySet, + PubNubFile: this._configuration.PubNubFile, + fileUploadPublishRetryLimit: this._configuration.fileUploadPublishRetryLimit, + file: parameters.file, + sendRequest: this.sendRequest.bind(this), + publishFile: this.publishFile.bind(this), + crypto: this._configuration.getCryptoModule(), + cryptography: this.cryptography ? (this.cryptography as Cryptography) : undefined, + }); + + const status: Status = { + error: false, + operation: RequestOperation.PNPublishFileOperation, + category: StatusCategory.PNAcknowledgmentCategory, + statusCode: 0, + }; + + return sendFileRequest + .process() + .then((response) => { + status.statusCode = response.status; + + if (callback) return callback(status, response); + return response; + }) + .catch((error: unknown) => { + let errorStatus: Status | undefined; + if (error instanceof PubNubError) errorStatus = error.status; + else if (error instanceof PubNubAPIError) errorStatus = error.toStatus(status.operation!); + + // Notify callback (if possible). + if (callback && errorStatus) callback(errorStatus, null); + + throw new PubNubError('REST API request processing error, check status for details', errorStatus); + }); + } + // endregion + + // region Publish File Message + /** + * Publish file message to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public publishFile( + parameters: FileSharing.PublishFileMessageParameters, + callback: ResultCallback, + ): void; + + /** + * Publish file message to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous publish file message response. + */ + public async publishFile( + parameters: FileSharing.PublishFileMessageParameters, + ): Promise; + + /** + * Publish file message to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous publish file message response or `void` in case if `callback` provided. + */ + public async publishFile( + parameters: FileSharing.PublishFileMessageParameters, + callback?: ResultCallback, + ): Promise { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + + const request = new PublishFileMessageRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region List + /** + * Retrieve list of shared files in specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public listFiles( + parameters: FileSharing.ListFilesParameters, + callback: ResultCallback, + ): void; + + /** + * Retrieve list of shared files in specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous shared files list response. + */ + public async listFiles(parameters: FileSharing.ListFilesParameters): Promise; + + /** + * Retrieve list of shared files in specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous shared files list response or `void` in case if `callback` provided. + */ + public async listFiles( + parameters: FileSharing.ListFilesParameters, + callback?: ResultCallback, + ): Promise { + const request = new FilesListRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Get Download Url + /** + * Get file download Url. + * + * @param parameters - Request configuration parameters. + * + * @returns File download Url. + */ + public getFileUrl(parameters: FileSharing.FileUrlParameters): FileSharing.FileUrlResponse { + const request = this.transport.request( + new GetFileDownloadUrlRequest({ ...parameters, keySet: this._configuration.keySet }).request(), + ); + const query = request.queryParameters ?? {}; + const queryString = Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) return `${key}=${encodeString(queryValue)}`; + + return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); + }) + .join('&'); + + return `${request.origin}${request.path}?${queryString}`; + } + // endregion + + // region Download + /** + * Download shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public downloadFile(parameters: FileSharing.DownloadFileParameters, callback: ResultCallback): void; + + /** + * Download shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous download shared file response. + */ + public async downloadFile(parameters: FileSharing.DownloadFileParameters): Promise; + + /** + * Download shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous download shared file response or `void` in case if `callback` provided. + */ + public async downloadFile( + parameters: FileSharing.DownloadFileParameters, + callback?: ResultCallback, + ): Promise { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + + const request = new DownloadFileRequest({ + ...parameters, + keySet: this._configuration.keySet, + PubNubFile: this._configuration.PubNubFile, + cryptography: this.cryptography ? (this.cryptography as Cryptography) : undefined, + crypto: this._configuration.getCryptoModule(), + }); + + if (callback) return this.sendRequest(request, callback); + return (await this.sendRequest(request)) as PlatformFile; + } + // endregion + + // region Delete + /** + * Delete shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public deleteFile( + parameters: FileSharing.DeleteFileParameters, + callback: ResultCallback, + ): void; + + /** + * Delete shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous delete shared file response. + */ + public async deleteFile(parameters: FileSharing.DeleteFileParameters): Promise; + + /** + * Delete shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous delete shared file response or `void` in case if `callback` provided. + */ + public async deleteFile( + parameters: FileSharing.DeleteFileParameters, + callback?: ResultCallback, + ): Promise { + const request = new DeleteFileRequest({ ...parameters, keySet: this._configuration.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + // endregion + + // -------------------------------------------------------- + // ---------------------- Time API ------------------------ + // -------------------------------------------------------- + // region Time API + + /** + Get current high-precision timetoken. + * + * @param callback - Request completion handler callback. + */ + public time(callback: ResultCallback): void; + + /** + * Get current high-precision timetoken. + * + * @returns Asynchronous get current timetoken response. + */ + public async time(): Promise; + + /** + Get current high-precision timetoken. + * + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get current timetoken response or `void` in case if `callback` provided. + */ + async time(callback?: ResultCallback): Promise { + const request = new Time.TimeRequest(); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // -------------------------------------------------------- + // ------------------ Cryptography API -------------------- + // -------------------------------------------------------- + // region Cryptography + // region Common + + /** + * Encrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @deprecated + * @param [customCipherKey] - Cipher key which should be used to encrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data encryption result as a string. + */ + public encrypt(data: string | Payload, customCipherKey?: string): string { + const cryptoModule = this._configuration.getCryptoModule(); + + if (!customCipherKey && cryptoModule && typeof data === 'string') { + const encrypted = cryptoModule.encrypt(data); + + return typeof encrypted === 'string' ? encrypted : encode(encrypted); + } + + if (!this.crypto) throw new Error('Encryption error: cypher key not set'); + + return this.crypto.encrypt(data, customCipherKey); + } + + /** + * Decrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @param [customCipherKey] - Cipher key which should be used to decrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data decryption result as an object. + */ + public decrypt(data: string, customCipherKey?: string): Payload | null { + const cryptoModule = this._configuration.getCryptoModule(); + if (!customCipherKey && cryptoModule) { + const decrypted = cryptoModule.decrypt(data); + + return decrypted instanceof ArrayBuffer ? JSON.parse(new TextDecoder().decode(decrypted)) : decrypted; + } + + if (!this.crypto) throw new Error('Decryption error: cypher key not set'); + + return this.crypto.decrypt(data, customCipherKey); + } + // endregion + + // region File + /** + * Encrypt file content. + * + * @param file - File which should be encrypted using `CryptoModule`. + * + * @returns Asynchronous file encryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + public async encryptFile(file: PubNubFileInterface): Promise; + + /** + * Encrypt file content. + * + * @param key - Cipher key which should be used to encrypt data. + * @param file - File which should be encrypted using legacy cryptography. + * + * @returns Asynchronous file encryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + public async encryptFile(key: string, file: PubNubFileInterface): Promise; + + /** + * Encrypt file content. + * + * @param keyOrFile - Cipher key which should be used to encrypt data or file which should be + * encrypted using `CryptoModule`. + * @param [file] - File which should be encrypted using legacy cryptography. + * + * @returns Asynchronous file encryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + public async encryptFile(keyOrFile: string | PubNubFileInterface, file?: PubNubFileInterface) { + if (typeof keyOrFile !== 'string') file = keyOrFile; + + if (!file) throw new Error('File encryption error. Source file is missing.'); + if (!this._configuration.PubNubFile) throw new Error('File encryption error. File constructor not configured.'); + if (typeof keyOrFile !== 'string' && !this._configuration.getCryptoModule()) + throw new Error('File encryption error. Crypto module not configured.'); + + if (typeof keyOrFile === 'string') { + if (!this.cryptography) throw new Error('File encryption error. File encryption not available'); + return this.cryptography.encryptFile(keyOrFile, file, this._configuration.PubNubFile); + } + + return this._configuration.getCryptoModule()?.encryptFile(file, this._configuration.PubNubFile); + } + + /** + * Decrypt file content. + * + * @param file - File which should be decrypted using legacy cryptography. + * + * @returns Asynchronous file decryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + public async decryptFile(file: PubNubFileInterface): Promise; + + /** + * Decrypt file content. + * + * @param key - Cipher key which should be used to decrypt data. + * @param [file] - File which should be decrypted using legacy cryptography. + * + * @returns Asynchronous file decryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + public async decryptFile(key: string | PubNubFileInterface, file?: PubNubFileInterface): Promise; + + /** + * Decrypt file content. + * + * @param keyOrFile - Cipher key which should be used to decrypt data or file which should be + * decrypted using `CryptoModule`. + * @param [file] - File which should be decrypted using legacy cryptography. + * + * @returns Asynchronous file decryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + public async decryptFile(keyOrFile: string | PubNubFileInterface, file?: PubNubFileInterface) { + if (typeof keyOrFile !== 'string') file = keyOrFile; + + if (!file) throw new Error('File encryption error. Source file is missing.'); + if (!this._configuration.PubNubFile) + throw new Error('File decryption error. File constructor' + ' not configured.'); + if (typeof keyOrFile === 'string' && !this._configuration.getCryptoModule()) + throw new Error('File decryption error. Crypto module not configured.'); + + if (typeof keyOrFile === 'string') { + if (!this.cryptography) throw new Error('File decryption error. File decryption not available'); + return this.cryptography.decryptFile(keyOrFile, file, this._configuration.PubNubFile); + } + + return this._configuration.getCryptoModule()?.decryptFile(file, this._configuration.PubNubFile); + } + // endregion + // endregion +} diff --git a/src/core/pubnub-objects.ts b/src/core/pubnub-objects.ts new file mode 100644 index 000000000..5d4a2152f --- /dev/null +++ b/src/core/pubnub-objects.ts @@ -0,0 +1,1096 @@ +/** + * PubNub Objects API module. + */ + +import { GetAllChannelsMetadataRequest } from './endpoints/objects/channel/get_all'; +import { RemoveChannelMetadataRequest } from './endpoints/objects/channel/remove'; +import { GetUUIDMembershipsRequest } from './endpoints/objects/membership/get'; +import { SetUUIDMembershipsRequest } from './endpoints/objects/membership/set'; +import { GetAllUUIDMetadataRequest } from './endpoints/objects/uuid/get_all'; +import { GetChannelMetadataRequest } from './endpoints/objects/channel/get'; +import { SetChannelMetadataRequest } from './endpoints/objects/channel/set'; +import { RemoveUUIDMetadataRequest } from './endpoints/objects/uuid/remove'; +import { GetChannelMembersRequest } from './endpoints/objects/member/get'; +import { SetChannelMembersRequest } from './endpoints/objects/member/set'; +import { KeySet, ResultCallback, SendRequestFunction } from './types/api'; +import { GetUUIDMetadataRequest } from './endpoints/objects/uuid/get'; +import { PrivateClientConfiguration } from './interfaces/configuration'; +import * as AppContext from './types/api/app-context'; +import { ChannelMetadataObject } from './types/api/app-context'; +import { SetUUIDMetadataRequest } from './endpoints/objects/uuid/set'; + +export default class PubNubObjects { + /** + * REST API endpoints access credentials. + */ + private readonly keySet: KeySet; + constructor( + private readonly configuration: PrivateClientConfiguration, + /* eslint-disable @typescript-eslint/no-explicit-any */ + private readonly sendRequest: SendRequestFunction, + ) { + this.keySet = configuration.keySet; + } + + // -------------------------------------------------------- + // ----------------------- UUID API ----------------------- + // -------------------------------------------------------- + // region UUID API + // region Get Metadata + + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param callback - Request completion handler callback. + */ + public getAllUUIDMetadata( + callback: ResultCallback>, + ): void; + + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public getAllUUIDMetadata( + parameters: AppContext.GetAllMetadataParameters>, + callback: ResultCallback>, + ): void; + + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all UUID metadata response. + */ + public async getAllUUIDMetadata( + parameters?: AppContext.GetAllMetadataParameters>, + ): Promise>; + + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + */ + async getAllUUIDMetadata( + parametersOrCallback?: + | AppContext.GetAllMetadataParameters> + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + return this._getAllUUIDMetadata(parametersOrCallback, callback); + } + + /** + * Fetch a paginated list of UUID Metadata objects. + * + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + */ + async _getAllUUIDMetadata( + parametersOrCallback?: + | AppContext.GetAllMetadataParameters> + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + // Get user request parameters. + const parameters: AppContext.GetAllMetadataParameters> = + parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback ??= typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined; + + const request = new GetAllUUIDMetadataRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + + /** + * Fetch UUID Metadata object for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + */ + public getUUIDMetadata( + callback: ResultCallback>, + ): void; + + /** + * Fetch a specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will fetch UUID metadata object for + * currently configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + */ + public getUUIDMetadata( + parameters: AppContext.GetUUIDMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Fetch a specific UUID Metadata object. + * + * @param [parameters] - Request configuration parameters. Will fetch UUID Metadata object for + * currently configured PubNub client `uuid` if not set. + * + * @returns Asynchronous get UUID metadata response. + */ + public async getUUIDMetadata( + parameters?: AppContext.GetUUIDMetadataParameters, + ): Promise>; + + /** + * Fetch a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + */ + async getUUIDMetadata( + parametersOrCallback?: + | AppContext.GetUUIDMetadataParameters + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + return this._getUUIDMetadata(parametersOrCallback, callback); + } + + /** + * Fetch a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + */ + async _getUUIDMetadata( + parametersOrCallback?: + | AppContext.GetUUIDMetadataParameters + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + // Get user request parameters. + const parameters: AppContext.GetUUIDMetadataParameters = + parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback ??= typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined; + if (parameters.userId) parameters.uuid = parameters.userId; + parameters.uuid ??= this.configuration.userId; + + const request = new GetUUIDMetadataRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Set Metadata + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + */ + public setUUIDMetadata( + parameters: AppContext.SetUUIDMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous set UUID metadata response. + */ + public async setUUIDMetadata( + parameters: AppContext.SetUUIDMetadataParameters, + ): Promise>; + + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set UUID metadata response or `void` in case if `callback` provided. + */ + async setUUIDMetadata( + parameters: AppContext.SetUUIDMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + return this._setUUIDMetadata(parameters, callback); + } + + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set UUID metadata response or `void` in case if `callback` provided. + */ + async _setUUIDMetadata( + parameters: AppContext.SetUUIDMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + if (parameters.userId) parameters.uuid = parameters.userId; + parameters.uuid ??= this.configuration.userId; + + const request = new SetUUIDMetadataRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Remove Metadata + /** + * Remove UUID Metadata object for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + */ + public removeUUIDMetadata(callback: ResultCallback): void; + + /** + * Remove a specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will remove UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + */ + public removeUUIDMetadata( + parameters: AppContext.RemoveUUIDMetadataParameters, + callback: ResultCallback, + ): void; + + /** + * Remove a specific UUID Metadata object. + * + * @param [parameters] - Request configuration parameters. Will remove UUID metadata for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous UUID metadata remove response. + */ + public async removeUUIDMetadata( + parameters?: AppContext.RemoveUUIDMetadataParameters, + ): Promise; + + /** + * Remove a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID metadata remove response or `void` in case if `callback` provided. + */ + public async removeUUIDMetadata( + parametersOrCallback?: + | AppContext.RemoveUUIDMetadataParameters + | ResultCallback, + callback?: ResultCallback, + ): Promise { + return this._removeUUIDMetadata(parametersOrCallback, callback); + } + + /** + * Remove a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID metadata remove response or `void` in case if `callback` provided. + */ + public async _removeUUIDMetadata( + parametersOrCallback?: + | AppContext.RemoveUUIDMetadataParameters + | ResultCallback, + callback?: ResultCallback, + ): Promise { + // Get user request parameters. + const parameters: AppContext.RemoveUUIDMetadataParameters = + parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback ??= typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined; + if (parameters.userId) parameters.uuid = parameters.userId; + parameters.uuid ??= this.configuration.userId; + + const request = new RemoveUUIDMetadataRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + // endregion + + // -------------------------------------------------------- + // --------------------- Channel API ---------------------- + // -------------------------------------------------------- + // region Channel API + // region Get Metadata + + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param callback - Request completion handler callback. + */ + public getAllChannelMetadata( + callback: ResultCallback>, + ): void; + + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public getAllChannelMetadata( + parameters: AppContext.GetAllMetadataParameters>, + callback: ResultCallback>, + ): void; + + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all Channel metadata response. + */ + public async getAllChannelMetadata( + parameters?: AppContext.GetAllMetadataParameters>, + ): Promise>; + + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Channel metadata response or `void` in case if `callback` + * provided. + */ + async getAllChannelMetadata( + parametersOrCallback?: + | AppContext.GetAllMetadataParameters> + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + return this._getAllChannelMetadata(parametersOrCallback, callback); + } + + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Channel metadata response or `void` in case if `callback` + * provided. + */ + async _getAllChannelMetadata( + parametersOrCallback?: + | AppContext.GetAllMetadataParameters> + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + // Get user request parameters. + const parameters: AppContext.GetAllMetadataParameters> = + parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback ??= typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined; + + const request = new GetAllChannelsMetadataRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public getChannelMetadata( + parameters: AppContext.GetChannelMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Fetch a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get Channel metadata response. + */ + public async getChannelMetadata( + parameters: AppContext.GetChannelMetadataParameters, + ): Promise>; + + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel metadata response or `void` in case if `callback` provided. + */ + async getChannelMetadata( + parameters: AppContext.GetChannelMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + return this._getChannelMetadata(parameters, callback); + } + + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel metadata response or `void` in case if `callback` provided. + */ + async _getChannelMetadata( + parameters: AppContext.GetChannelMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + const request = new GetChannelMetadataRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Set Metadata + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public setChannelMetadata( + parameters: AppContext.SetChannelMetadataParameters, + callback: ResultCallback>, + ): void; + + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous set Channel metadata response. + */ + public async setChannelMetadata( + parameters: AppContext.SetChannelMetadataParameters, + ): Promise>; + + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set Channel metadata response or `void` in case if `callback` provided. + */ + async setChannelMetadata( + parameters: AppContext.SetChannelMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + return this._setChannelMetadata(parameters, callback); + } + + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set Channel metadata response or `void` in case if `callback` provided. + */ + async _setChannelMetadata( + parameters: AppContext.SetChannelMetadataParameters, + callback?: ResultCallback>, + ): Promise | void> { + const request = new SetChannelMetadataRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Remove Metadata + /** + * Remove Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public removeChannelMetadata( + parameters: AppContext.RemoveChannelMetadataParameters, + callback: ResultCallback, + ): void; + + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous Channel metadata remove response. + */ + public async removeChannelMetadata( + parameters: AppContext.RemoveChannelMetadataParameters, + ): Promise; + + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel metadata remove response or `void` in case if `callback` + * provided. + */ + async removeChannelMetadata( + parameters: AppContext.RemoveChannelMetadataParameters, + callback?: ResultCallback, + ): Promise { + return this._removeChannelMetadata(parameters, callback); + } + + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel metadata remove response or `void` in case if `callback` + * provided. + */ + async _removeChannelMetadata( + parameters: AppContext.RemoveChannelMetadataParameters, + callback?: ResultCallback, + ): Promise { + const request = new RemoveChannelMetadataRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + // endregion + + // -------------------------------------------------------- + // -------------- Members / Membership API ---------------- + // -------------------------------------------------------- + // region Members API + // region Get Members + + /** + * Fetch a paginated list of Channel Member objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public getChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembersParameters, + callback: ResultCallback>, + ): void; + + /** + * Fetch a paginated list of Channel Member objects. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get Channel Members response. + */ + public async getChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >(parameters: AppContext.GetMembersParameters): Promise>; + + /** + * Fetch a paginated list of Channel Member objects. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel Members response or `void` in case if `callback` provided. + */ + async getChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembersParameters, + callback?: ResultCallback>, + ): Promise | void> { + const request = new GetChannelMembersRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Set Members + /** + * Update specific Channel Members list. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public setChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetChannelMembersParameters, + callback: ResultCallback>, + ): void; + + /** + * Update specific Channel Members list. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous update Channel Members list response. + */ + public async setChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetChannelMembersParameters, + ): Promise>; + + /** + * Update specific Channel Members list. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update Channel members list response or `void` in case if `callback` + * provided. + */ + async setChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetChannelMembersParameters, + callback?: ResultCallback>, + ): Promise | void> { + const request = new SetChannelMembersRequest({ ...parameters, type: 'set', keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Remove Members + /** + * Remove Members from the Channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public removeChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembersParameters, + callback: ResultCallback>, + ): void; + + /** + * Remove Members from the Channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous Channel Members remove response. + */ + public async removeChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembersParameters, + ): Promise>; + + /** + * Remove Members from the Channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel Members remove response or `void` in case if `callback` provided. + */ + async removeChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembersParameters, + callback?: ResultCallback>, + ): Promise | void> { + const request = new SetChannelMembersRequest({ ...parameters, type: 'delete', keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + // endregion + + // region Membership API + // region Get Membership + /** + * Fetch a specific UUID Memberships list for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + * + * @returns Asynchronous get UUID Memberships list response or `void` in case if `callback` + * provided. + */ + public getMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >(callback: ResultCallback>): void; + + /** + * Fetch a specific UUID Memberships list. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public getMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembershipsParameters, + callback: ResultCallback>, + ): void; + + /** + * Fetch a specific UUID Memberships list. + * + * @param [parameters] - Request configuration parameters. Will fetch UUID Memberships list for + * currently configured PubNub client `uuid` if not set. + * + * @returns Asynchronous get UUID Memberships list response. + */ + public async getMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters?: AppContext.GetMembershipsParameters, + ): Promise>; + + /** + * Fetch a specific UUID Memberships list. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID Memberships response or `void` in case if `callback` provided. + */ + async getMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parametersOrCallback?: + | AppContext.GetMembershipsParameters + | ResultCallback>, + callback?: ResultCallback>, + ): Promise | void> { + // Get user request parameters. + const parameters: AppContext.GetMembershipsParameters = + parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; + callback ??= typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined; + if (parameters.userId) parameters.uuid = parameters.userId; + parameters.uuid ??= this.configuration.userId; + + const request = new GetUUIDMembershipsRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Set Membership + /** + * Update specific UUID Memberships list. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public setMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters, + callback: ResultCallback>, + ): void; + + /** + * Update specific UUID Memberships list. + * + * @param parameters - Request configuration parameters or callback from overload. + * + * @returns Asynchronous update UUID Memberships list response. + */ + public async setMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters, + ): Promise>; + + /** + * Update specific UUID Memberships list. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update UUID Memberships list response or `void` in case if `callback` + * provided. + */ + async setMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters, + callback?: ResultCallback>, + ): Promise | void> { + if (parameters.userId) parameters.uuid = parameters.userId; + parameters.uuid ??= this.configuration.userId; + + const request = new SetUUIDMembershipsRequest({ ...parameters, type: 'set', keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // region Remove Membership + /** + * Remove a specific UUID Memberships. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public removeMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembershipsParameters, + callback: ResultCallback>, + ): void; + + /** + * Remove a specific UUID Memberships. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous UUID Memberships remove response. + */ + public async removeMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembershipsParameters, + ): Promise>; + + /** + * Remove a specific UUID Memberships. + * + * @param parameters - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID Memberships remove response or `void` in case if `callback` + * provided. + */ + async removeMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembershipsParameters, + callback?: ResultCallback>, + ): Promise | void> { + if (parameters.userId) parameters.uuid = parameters.userId; + parameters.uuid ??= this.configuration.userId; + + const request = new SetUUIDMembershipsRequest({ ...parameters, type: 'delete', keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + // endregion + + // -------------------------------------------------------- + // --------------------- Deprecated API ------------------- + // -------------------------------------------------------- + // region Deprecated + + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get specific Space members or specific User memberships response. + * + * @deprecated Use {@link PubNubObjects#getChannelMembers} or {@link PubNubObjects#getMemberships} methods instead. + */ + public async fetchMemberships< + RelationCustom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters, + callback?: ResultCallback< + | AppContext.SpaceMembershipsResponse + | AppContext.UserMembersResponse + >, + ): Promise< + | AppContext.SpaceMembershipsResponse + | AppContext.UserMembersResponse + | void + > { + if ('spaceId' in parameters) { + const spaceParameters = parameters as AppContext.GetMembersParameters; + const mappedParameters = { + channel: spaceParameters.spaceId ?? spaceParameters.channel, + filter: spaceParameters.filter, + limit: spaceParameters.limit, + page: spaceParameters.page, + include: { ...spaceParameters.include }, + sort: spaceParameters.sort + ? Object.fromEntries( + Object.entries(spaceParameters.sort).map(([key, value]) => [key.replace('user', 'uuid'), value]), + ) + : undefined, + } as AppContext.GetMembersParameters; + + // Map Members object to the older version. + const mapMembers = (response: AppContext.GetMembersResponse) => + ({ + status: response.status, + data: response.data.map((members) => ({ + user: members.uuid, + custom: members.custom, + updated: members.updated, + eTag: members.eTag, + })), + totalCount: response.totalCount, + next: response.next, + prev: response.prev, + }) as AppContext.UserMembersResponse; + + if (callback) + return this.getChannelMembers(mappedParameters, (status, result) => { + callback(status, result ? mapMembers(result) : result); + }); + return this.getChannelMembers(mappedParameters).then(mapMembers); + } + + const userParameters = parameters as AppContext.GetMembershipsParameters; + const mappedParameters = { + uuid: userParameters.userId ?? userParameters.uuid, + filter: userParameters.filter, + limit: userParameters.limit, + page: userParameters.page, + include: { ...userParameters.include }, + sort: userParameters.sort + ? Object.fromEntries( + Object.entries(userParameters.sort).map(([key, value]) => [key.replace('space', 'channel'), value]), + ) + : undefined, + } as AppContext.GetMembershipsParameters; + + // Map Memberships object to the older version. + const mapMemberships = ( + response: AppContext.GetMembershipsResponse, + ) => + ({ + status: response.status, + data: response.data.map((membership) => ({ + space: membership.channel, + custom: membership.custom, + updated: membership.updated, + eTag: membership.eTag, + })), + totalCount: response.totalCount, + next: response.next, + prev: response.prev, + }) as AppContext.SpaceMembershipsResponse; + + if (callback) + return this.getMemberships(mappedParameters, (status, result) => { + callback(status, result ? mapMemberships(result) : result); + }); + return this.getMemberships(mappedParameters).then(mapMemberships); + } + + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add members to specific Space or memberships specific User response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubObjects#setChannelMembers} or {@link PubNubObjects#setMemberships} methods instead. + */ + async addMemberships< + Custom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, + callback?: ResultCallback< + AppContext.SetMembershipsResponse | AppContext.SetMembersResponse + >, + ): Promise< + | AppContext.SetMembershipsResponse + | AppContext.SetMembersResponse + | void + > { + if ('spaceId' in parameters) { + const spaceParameters = parameters as AppContext.SetChannelMembersParameters; + const mappedParameters = { + channel: spaceParameters.spaceId ?? spaceParameters.channel, + uuids: + spaceParameters.users?.map((user) => { + if (typeof user === 'string') return user; + user.userId; + return { id: user.userId, custom: user.custom }; + }) ?? spaceParameters.uuids, + limit: 0, + }; + + if (callback) return this.setChannelMembers(mappedParameters, callback); + return this.setChannelMembers(mappedParameters); + } + + const userParameters = parameters as AppContext.SetMembershipsParameters; + const mappedParameters = { + uuid: userParameters.userId ?? userParameters.uuid, + channels: + userParameters.spaces?.map((space) => { + if (typeof space === 'string') return space; + return { + id: space.spaceId, + custom: space.custom, + }; + }) ?? userParameters.channels, + limit: 0, + }; + + if (callback) return this.setMemberships(mappedParameters, callback); + return this.setMemberships(mappedParameters); + } + // endregion +} diff --git a/src/core/pubnub-push.ts b/src/core/pubnub-push.ts new file mode 100644 index 000000000..cc8e37b06 --- /dev/null +++ b/src/core/pubnub-push.ts @@ -0,0 +1,157 @@ +/** + * PubNub Push Notifications API module. + */ + +import { RemoveDevicePushNotificationChannelsRequest } from './endpoints/push/remove_push_channels'; +import { ListDevicePushNotificationChannelsRequest } from './endpoints/push/list_push_channels'; +import { AddDevicePushNotificationChannelsRequest } from './endpoints/push/add_push_channels'; +import { KeySet, ResultCallback, SendRequestFunction, StatusCallback } from './types/api'; +import { RemoveDevicePushNotificationRequest } from './endpoints/push/remove_device'; +import * as PushNotifications from './types/api/push-notifications'; +import * as Push from './types/api/push'; + +export default class PubNubPushNotifications { + constructor( + private readonly keySet: KeySet, + /* eslint-disable @typescript-eslint/no-explicit-any */ + private readonly sendRequest: SendRequestFunction, + ) {} + + // -------------------------------------------------------- + // ---------------------- Audit API ----------------------- + // -------------------------------------------------------- + // region Audit API + + /** + * Fetch device's push notification enabled channels. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public listChannels( + parameters: Push.ListDeviceChannelsParameters, + callback: ResultCallback, + ): void; + + /** + * Fetch device's push notification enabled channels. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get device channels response. + */ + public async listChannels(parameters: Push.ListDeviceChannelsParameters): Promise; + + /** + * Fetch device's push notification enabled channels. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get device channels response or `void` in case if `callback` provided. + */ + public async listChannels( + parameters: Push.ListDeviceChannelsParameters, + callback?: ResultCallback, + ): Promise { + const request = new ListDevicePushNotificationChannelsRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + // endregion + + // -------------------------------------------------------- + // ---------------------- Manage API ---------------------- + // -------------------------------------------------------- + // region Manage API + + /** + * Enable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public addChannels(parameters: Push.ManageDeviceChannelsParameters, callback: StatusCallback): void; + + /** + * Enable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + */ + public async addChannels(parameters: Push.ManageDeviceChannelsParameters): Promise; + + /** + * Enable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + */ + public async addChannels(parameters: Push.ManageDeviceChannelsParameters, callback?: StatusCallback): Promise { + const request = new AddDevicePushNotificationChannelsRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + + /** + * Disable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public removeChannels(parameters: Push.ManageDeviceChannelsParameters, callback: StatusCallback): void; + + /** + * Disable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + */ + public async removeChannels(parameters: Push.ManageDeviceChannelsParameters): Promise; + + /** + * Disable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + */ + public async removeChannels( + parameters: Push.ManageDeviceChannelsParameters, + callback?: StatusCallback, + ): Promise { + const request = new RemoveDevicePushNotificationChannelsRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + + /** + * Disable push notifications for device. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + public deleteDevice(parameters: Push.RemoveDeviceParameters, callback: StatusCallback): void; + + /** + * Disable push notifications for device. + * + * @param parameters - Request configuration parameters. + */ + public async deleteDevice(parameters: Push.RemoveDeviceParameters): Promise; + + /** + * Disable push notifications for device. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + */ + public async deleteDevice(parameters: Push.RemoveDeviceParameters, callback?: StatusCallback): Promise { + const request = new RemoveDevicePushNotificationRequest({ ...parameters, keySet: this.keySet }); + + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } + + // endregion +} diff --git a/src/core/types/api/access-panager.ts b/src/core/types/api/access-panager.ts new file mode 100644 index 000000000..068d1afe2 --- /dev/null +++ b/src/core/types/api/access-panager.ts @@ -0,0 +1,564 @@ +// region Grant token +/** + * Metadata which will be associated with access token. + */ +export type Metadata = Record; + +/** + * Channel-specific token permissions. + */ +export type ChannelTokenPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + read?: boolean; + + /** + * Whether `write` operations are permitted for corresponding level or not. + */ + write?: boolean; + + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + get?: boolean; + + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + manage?: boolean; + + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + update?: boolean; + + /** + * Whether `join` operations are permitted for corresponding level or not. + */ + join?: boolean; + + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + delete?: boolean; +}; + +/** + * Space-specific token permissions. + */ +type SpaceTokenPermissions = ChannelTokenPermissions; + +/** + * Channel group-specific token permissions. + */ +export type ChannelGroupTokenPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + read?: boolean; + + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + manage?: boolean; +}; + +/** + * Uuid-specific token permissions. + */ +export type UuidTokenPermissions = { + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + get?: boolean; + + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + update?: boolean; + + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + delete?: boolean; +}; + +/** + * User-specific token permissions. + */ +type UserTokenPermissions = UuidTokenPermissions; + +/** + * Generate access token with permissions. + * + * Generate time-limited access token with required permissions for App Context objects. + */ +export type ObjectsGrantTokenParameters = { + /** + * Total number of minutes for which the token is valid. + * + * The minimum allowed value is `1`. + * The maximum is `43,200` minutes (`30` days). + */ + ttl: number; + + /** + * Object containing resource permissions. + */ + resources?: { + /** + * Object containing `spaces` metadata permissions. + */ + spaces?: Record; + + /** + * Object containing `users` permissions. + */ + users?: Record; + }; + + /** + * Object containing permissions to multiple resources specified by a RegEx pattern. + */ + patterns?: { + /** + * Object containing `spaces` metadata permissions. + */ + spaces?: Record; + + /** + * Object containing `users` permissions. + */ + users?: Record; + }; + + /** + * Extra metadata to be published with the request. + * + * **Important:** Values must be scalar only; `arrays` or `objects` aren't supported. + */ + meta?: Metadata; + + /** + * Single `userId` which is authorized to use the token to make API requests to PubNub. + */ + authorizedUserId?: string; +}; + +/** + * Generate token with permissions. + * + * Generate time-limited access token with required permissions for resources. + */ +export type GrantTokenParameters = { + /** + * Total number of minutes for which the token is valid. + * + * The minimum allowed value is `1`. + * The maximum is `43,200` minutes (`30` days). + */ + ttl: number; + + /** + * Object containing resource permissions. + */ + resources?: { + /** + * Object containing `uuid` metadata permissions. + */ + uuids?: Record; + + /** + * Object containing `channel` permissions. + */ + channels?: Record; + + /** + * Object containing `channel group` permissions. + */ + groups?: Record; + }; + + /** + * Object containing permissions to multiple resources specified by a RegEx pattern. + */ + patterns?: { + /** + * Object containing `uuid` metadata permissions to apply to all `uuids` matching the RegEx + * pattern. + */ + uuids?: Record; + + /** + * Object containing `channel` permissions to apply to all `channels` matching the RegEx + * pattern. + */ + channels?: Record; + + /** + * Object containing `channel group` permissions to apply to all `channel groups` matching the + * RegEx pattern. + */ + groups?: Record; + }; + + /** + * Extra metadata to be published with the request. + * + * **Important:** Values must be scalar only; `arrays` or `objects` aren't supported. + */ + meta?: Metadata; + + /** + * Single `uuid` which is authorized to use the token to make API requests to PubNub. + */ + authorized_uuid?: string; +}; + +/** + * Response with generated access token. + */ +export type GrantTokenResponse = string; +// endregion + +// region Revoke +export type RevokeParameters = { + /** + * Access token for which permissions should be revoked. + */ + token: string; +}; + +/** + * Response with revoked access token. + */ +export type RevokeTokenResponse = Record; +// endregion + +// -------------------------------------------------------- +// --------------------- Deprecated ----------------------- +// -------------------------------------------------------- +// region Deprecated + +/** + * Channel-specific permissions. + * + * Permissions include objects to the App Context Channel object as well. + */ +type ChannelPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + r?: 0 | 1; + + /** + * Whether `write` operations are permitted for corresponding level or not. + */ + w?: 0 | 1; + + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + d?: 0 | 1; + + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + g?: 0 | 1; + + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + u?: 0 | 1; + + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + m?: 0 | 1; + + /** + * Whether `join` operations are permitted for corresponding level or not. + */ + j?: 0 | 1; + + /** + * Duration for which permissions has been granted. + */ + ttl?: number; +}; + +/** + * Channel group-specific permissions. + */ +type ChannelGroupPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + r?: 0 | 1; + + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + m?: 0 | 1; + + /** + * Duration for which permissions has been granted. + */ + ttl?: number; +}; + +/** + * App Context User-specific permissions. + */ +type UserPermissions = { + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + g?: 0 | 1; + + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + u?: 0 | 1; + + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + d?: 0 | 1; + + /** + * Duration for which permissions has been granted. + */ + ttl?: number; +}; + +/** + * Common permissions audit response content. + */ +type BaseAuditResponse< + Level extends 'channel' | 'channel+auth' | 'channel-group' | 'channel-group+auth' | 'user' | 'subkey', +> = { + /** + * Permissions level. + */ + level: Level; + + /** + * Subscription key at which permissions has been granted. + */ + subscribe_key: string; + + /** + * Duration for which permissions has been granted. + */ + ttl?: number; +}; + +/** + * Auth keys permissions for specified `level`. + */ +type AuthKeysPermissions = { + /** + * Auth keys-based permissions for specified `level` permission. + */ + auths: Record; +}; + +/** + * Single channel permissions audit result. + */ +type ChannelPermissionsResponse = BaseAuditResponse<'channel+auth'> & { + /** + * Name of channel for which permissions audited. + */ + channel: string; +} & AuthKeysPermissions; + +/** + * Multiple channels permissions audit result. + */ +type ChannelsPermissionsResponse = BaseAuditResponse<'channel'> & { + /** + * Per-channel permissions. + */ + channels: Record>; +}; + +/** + * Single channel group permissions result. + */ +type ChannelGroupPermissionsResponse = BaseAuditResponse<'channel-group+auth'> & { + /** + * Name of channel group for which permissions audited. + */ + 'channel-group': string; +} & AuthKeysPermissions; + +/** + * Multiple channel groups permissions audit result. + */ +type ChannelGroupsPermissionsResponse = BaseAuditResponse<'channel'> & { + /** + * Per-channel group permissions. + */ + 'channel-groups': Record>; +}; + +/** + * App Context User permissions audit result. + */ +type UserPermissionsResponse = BaseAuditResponse<'user'> & { + /** + * Name of channel for which `user` permissions audited. + */ + channel: string; +} & AuthKeysPermissions; + +/** + * Global sub-key level permissions audit result. + */ +type SubKeyPermissionsResponse = BaseAuditResponse<'subkey'> & { + /** + * Per-channel permissions. + */ + channels: Record>; + + /** + * Per-channel group permissions. + */ + 'channel-groups': Record>; + + /** + * Per-object permissions. + */ + objects: Record>; +}; + +/** + * Response with permission information. + */ +export type PermissionsResponse = + | ChannelPermissionsResponse + | ChannelsPermissionsResponse + | ChannelGroupPermissionsResponse + | ChannelGroupsPermissionsResponse + | UserPermissionsResponse + | SubKeyPermissionsResponse; + +// region Audit +/** + * Audit permissions for provided auth keys / global permissions. + * + * Audit permissions on specific channel and / or channel group for the set of auth keys. + */ +export type AuditParameters = { + /** + * Name of channel for which channel-based permissions should be checked for {@link authKeys}. + */ + channel?: string; + + /** + * Name of channel group for which channel group-based permissions should be checked for {@link authKeys}. + */ + channelGroup?: string; + + /** + * List of auth keys for which permissions should be checked. + * + * Leave this empty to check channel / group -based permissions or global permissions. + * + * @default `[]` + */ + authKeys?: string[]; +}; +// endregion + +// region Grant +/** + * Grant permissions for provided auth keys / global permissions. + * + * Grant permissions on specific channel and / or channel group for the set of auth keys. + */ +export type GrantParameters = { + /** + * List of channels for which permissions should be granted. + */ + channels?: string[]; + + /** + * List of channel groups for which permissions should be granted. + */ + channelGroups?: string[]; + + /** + * List of App Context UUID for which permissions should be granted. + */ + uuids?: string[]; + + /** + * List of auth keys for which permissions should be granted on specified objects. + * + * Leave this empty to grant channel / group -based permissions or global permissions. + */ + authKeys?: string[]; + + /** + * Whether `read` operations are permitted for corresponding level or not. + * + * @default `false` + */ + read?: boolean; + + /** + * Whether `write` operations are permitted for corresponding level or not. + * + * @default `false` + */ + write?: boolean; + + /** + * Whether `delete` operations are permitted for corresponding level or not. + * + * @default `false` + */ + delete?: boolean; + + /** + * Whether `get` operations are permitted for corresponding level or not. + * + * @default `false` + */ + get?: boolean; + + /** + * Whether `update` operations are permitted for corresponding level or not. + * + * @default `false` + */ + update?: boolean; + + /** + * Whether `manage` operations are permitted for corresponding level or not. + * + * @default `false` + */ + manage?: boolean; + + /** + * Whether `join` operations are permitted for corresponding level or not. + * + * @default `false` + */ + join?: boolean; + + /** + * For how long permissions should be effective (in minutes). + * + * @default `1440` + */ + ttl?: number; +}; +// endregion + +// endregion diff --git a/src/core/types/api/app-context.ts b/src/core/types/api/app-context.ts new file mode 100644 index 000000000..ce5c5c51a --- /dev/null +++ b/src/core/types/api/app-context.ts @@ -0,0 +1,1104 @@ +/** + * Partial nullability helper type. + */ +type PartialNullable = { + [P in keyof T]?: T[P] | null; +}; + +/** + * Custom data which should be associated with metadata objects or their relation. + */ +export type CustomData = { + [key: string]: string | number | boolean | null; +}; + +/** + * Type provides shape of App Context parameters which is common to the all objects types to + * be updated. + */ +type ObjectParameters = { + custom?: Custom; +}; + +/** + * Type provides shape of App Context object which is common to the all objects types received + * from the PubNub service. + */ +export type ObjectData = { + /** + * Unique App Context object identifier. + * + * **Important:** For channel it is different from the channel metadata object name. + */ + id: string; + + /** + * Last date and time when App Context object has been updated. + * + * String built from date using ISO 8601. + */ + updated: string; + + /** + * App Context version hash. + */ + eTag: string; + + /** + * Additional data associated with App Context object. + * + * **Important:** Values must be scalars; only arrays or objects are supported. + * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|App Context + * filtering language} doesn’t support filtering by custom properties. + */ + custom?: Custom | null; +}; + +/** + * Type provides shape of object which let establish relation between metadata objects. + */ +type ObjectsRelation = { + /** + * App Context object unique identifier. + */ + id: string; + + /** + * App Context objects relation status. + */ + status?: string; + + /** + * Additional data associated with App Context object relation (membership or members). + * + * **Important:** Values must be scalars; only arrays or objects are supported. + * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|App Context + * filtering language} doesn’t support filtering by custom properties. + */ + custom?: Custom; +}; + +/** + * Response page cursor. + */ +type Page = { + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for forward pagination, it fetches the next page, allowing you to continue from where + * you left off. + */ + next?: string; + + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for backward pagination, it fetches the previous page, enabling access to earlier + * data. + * + * **Important:** Ignored if the `next` parameter is supplied. + */ + prev?: string; +}; + +/** + * Metadata objects include options. + * + * Allows to configure what additional information should be included into service response. + */ +type IncludeOptions = { + /** + * Whether to include total number of App Context objects in the response. + * + * @default `false` + */ + totalCount?: boolean; + + /** + * Whether to include App Context object `custom` field in the response. + * + * @default `false` + */ + customFields?: boolean; +}; + +/** + * Membership objects include options. + * + * Allows to configure what additional information should be included into service response. + */ +type MembershipsIncludeOptions = IncludeOptions & { + /** + * Whether to include all {@link ChannelMetadata} fields in the response. + * + * @default `false` + */ + channelFields?: boolean; + + /** + * Whether to include {@link ChannelMetadata} `custom` field in the response. + * + * @default `false` + */ + customChannelFields?: boolean; + + /** + * Whether to include the membership's status field in the response. + * + * @default `false` + */ + statusField?: boolean; + + /** + * Whether to include the channel's status field in the response. + * + * @default `false` + */ + channelStatusField?: boolean; + + /** + * Whether to include channel's type fields in the response. + * + * @default `false` + */ + channelTypeField?: boolean; +}; + +/** + * Members objects include options. + * + * Allows to configure what additional information should be included into service response. + */ +type MembersIncludeOptions = IncludeOptions & { + /** + * Whether to include all {@link UUIMetadata} fields in the response. + * + * @default `false` + */ + UUIDFields?: boolean; + + /** + * Whether to include {@link UUIMetadata} `custom` field in the response. + * + * @default `false` + */ + customUUIDFields?: boolean; + + /** + * Whether to include the members's status field in the response. + * + * @default `false` + */ + statusField?: boolean; + + /** + * Whether to include the user's status field in the response. + * + * @default `false` + */ + UUIDStatusField?: boolean; + + /** + * Whether to include user's type fields in the response. + * + * @default `false` + */ + UUIDTypeField?: boolean; +}; + +/** + * Type provides shape of App Context parameters which is common to the all objects types to + * fetch them by pages. + */ +type PagedRequestParameters = { + /** + * Fields which can be additionally included into response. + */ + include?: Include; + + /** + * Expression used to filter the results. + * + * Only objects whose properties satisfy the given expression are returned. The filter language is + * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|defined here}. + */ + filter?: string; + + /** + * Fetched App Context objects sorting options. + */ + sort?: Sort; + + /** + * Number of objects to return in response. + * + * **Important:** Maximum for this API is `100` objects per-response. + * + * @default `100` + */ + limit?: number; + + /** + * Response pagination configuration. + */ + page?: Page; +}; + +/** + * Type provides shape of App Context object fetch response which is common to the all objects + * types received from the PubNub service. + */ +type ObjectResponse = { + /** + * App Context objects list fetch result status code. + */ + status: number; + + /** + * Received App Context object information. + */ + data: ObjectType; +}; + +/** + * Type provides shape of App Context objects fetch response which is common to the all + * objects types received from the PubNub service. + */ +type PagedResponse = ObjectResponse & { + /** + * Total number of App Context objects in the response. + */ + totalCount?: number; + + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for forward pagination, it fetches the next page, allowing you to continue from where + * you left off. + */ + next?: string; + + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for backward pagination, it fetches the previous page, enabling access to earlier + * data. + * + * **Important:** Ignored if the `next` parameter is supplied. + */ + prev?: string; +}; + +/** + * Key-value pair of a property to sort by, and a sort direction. + */ +type MetadataSortingOptions = + | keyof Omit + | ({ [K in keyof Omit]?: 'asc' | 'desc' | null } & { + [key: `custom.${string}`]: 'asc' | 'desc' | null; + }); + +type RelationSortingOptions = { + [K in keyof Omit as `${O}.${string & K}`]: 'asc' | 'desc' | null; +}; + +/** + * Key-value pair of a property to sort by, and a sort direction. + */ +type MembershipsSortingOptions2 = + | keyof RelationSortingOptions + | keyof RelationSortingOptions + | (RelationSortingOptions & + RelationSortingOptions & { + [key: `channel.custom.${string}`]: 'asc' | 'desc' | null; + [key: `space.custom.${string}`]: 'asc' | 'desc' | null; + }); + +/** + * Key-value pair of a property to sort by, and a sort direction. + */ +type MembershipsSortingOptions = + | 'channel.id' + | 'channel.name' + | 'channel.description' + | 'channel.updated' + | 'space.id' + | 'space.name' + | 'space.description' + | 'space.updated' + | 'updated' + | { + /** + * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.id'?: 'asc' | 'desc' | null; + + /** + * Sort results by channel's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.name'?: 'asc' | 'desc' | null; + + /** + * Sort results by channel's `description` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.description'?: 'asc' | 'desc' | null; + + /** + * Sort results by channel's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.updated'?: 'asc' | 'desc' | null; + + /** + * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.id` instead. + */ + 'space.id'?: 'asc' | 'desc' | null; + + /** + * Sort results by channel's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.name` instead. + */ + 'space.name'?: 'asc' | 'desc' | null; + + /** + * Sort results by channel's `description` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.name` instead. + */ + 'space.description'?: 'asc' | 'desc' | null; + + /** + * Sort results by channel's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.updated` instead. + */ + 'space.updated'?: 'asc' | 'desc' | null; + + /** + * Sort results by `updated` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + updated?: 'asc' | 'desc' | null; + }; + +/** + * Key-value pair of a property to sort by, and a sort direction. + */ +type MembersSortingOptions = + | 'uuid.id' + | 'uuid.name' + | 'uuid.updated' + | 'user.id' + | 'user.name' + | 'user.updated' + | 'updated' + | { + /** + * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.id'?: 'asc' | 'desc' | null; + + /** + * Sort results by user's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.name'?: 'asc' | 'desc' | null; + + /** + * Sort results by user's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.updated'?: 'asc' | 'desc' | null; + + /** + * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `uuid.id` instead. + */ + 'user.id'?: 'asc' | 'desc' | null; + + /** + * Sort results by user's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `uuid.name` instead. + */ + 'user.name'?: 'asc' | 'desc' | null; + + /** + * Sort results by user's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `uuid.updated` instead. + */ + 'user.updated'?: 'asc' | 'desc' | null; + + /** + * Sort results by `updated` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + updated?: 'asc' | 'desc' | null; + }; + +// -------------------------------------------------------- +// --------------------- Common API ----------------------- +// -------------------------------------------------------- + +/** + * Fetch All UUID or Channel Metadata request parameters. + */ +export type GetAllMetadataParameters = PagedRequestParameters< + IncludeOptions, + MetadataSortingOptions +>; + +// -------------------------------------------------------- +// ---------------------- UUID API ------------------------ +// -------------------------------------------------------- + +/** + * Type which describes own UUID metadata object fields. + */ +type UUIDMetadataFields = { + /** + * Display name for the user. + */ + name?: string; + + /** + * The user's email address. + */ + email?: string; + + /** + * User's identifier in an external system. + */ + externalId?: string; + + /** + * The URL of the user's profile picture. + */ + profileUrl?: string; + + /** + * User's object type information. + */ + type?: string; + + /** + * User's object status. + */ + status?: string; +}; + +/** + * Updated UUID metadata object. + * + * Type represents updated UUID metadata object which will be pushed to the PubNub service. + */ +type UUIDMetadata = ObjectParameters & Partial; + +/** + * Received UUID metadata object. + * + * Type represents UUID metadata retrieved from the PubNub service. + */ +export type UUIDMetadataObject = ObjectData & PartialNullable; + +/** + * Response with fetched page of UUID metadata objects. + */ +export type GetAllUUIDMetadataResponse = PagedResponse>; + +/** + * Fetch UUID Metadata request parameters. + */ +export type GetUUIDMetadataParameters = { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `getUUIDMetadata()` method instead. + */ + userId?: string; + + /** + * Fields which can be additionally included into response. + */ + include?: Omit; +}; + +/** + * Response with requested UUID metadata object. + */ +export type GetUUIDMetadataResponse = ObjectResponse>; + +/** + * Update UUID Metadata request parameters. + */ +export type SetUUIDMetadataParameters = { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `setUUIDMetadata()` method instead. + */ + userId?: string; + + /** + * Metadata, which should be associated with UUID. + */ + data: UUIDMetadata; + + /** + * Fields which can be additionally included into response. + */ + include?: Omit; +}; + +/** + * Response with result of the UUID metadata object update. + */ +export type SetUUIDMetadataResponse = ObjectResponse>; + +/** + * Remove UUID Metadata request parameters. + */ +export type RemoveUUIDMetadataParameters = { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `removeUUIDMetadata()` method instead. + */ + userId?: string; +}; + +/** + * Response with result of the UUID metadata removal. + */ +export type RemoveUUIDMetadataResponse = ObjectResponse>; + +// -------------------------------------------------------- +// --------------------- Channel API ---------------------- +// -------------------------------------------------------- + +/** + * Type which describes own Channel metadata object fields. + */ +type ChannelMetadataFields = { + /** + * Name of a channel. + */ + name?: string; + + /** + * Description of a channel. + */ + description?: string; + + /** + * Channel's object type information. + */ + type?: string; + + /** + * Channel's object status. + */ + status?: string; +}; + +/** + * Updated channel metadata object. + * + * Type represents updated channel metadata object which will be pushed to the PubNub service. + */ +type ChannelMetadata = ObjectParameters & Partial; + +/** + * Received channel metadata object. + * + * Type represents chanel metadata retrieved from the PubNub service. + */ +export type ChannelMetadataObject = ObjectData & + PartialNullable; + +/** + * Response with fetched page of channel metadata objects. + */ +export type GetAllChannelMetadataResponse = PagedResponse>; + +/** + * Fetch Channel Metadata request parameters. + */ +export type GetChannelMetadataParameters = { + /** + * Channel name. + */ + channel: string; + + /** + * Space identifier. + * + * @deprecated Use `getChannelMetadata()` method instead. + */ + spaceId?: string; + + /** + * Fields which can be additionally included into response. + */ + include?: Omit; +}; + +/** + * Response with requested channel metadata object. + */ +export type GetChannelMetadataResponse = ObjectResponse>; + +/** + * Update Channel Metadata request parameters. + */ +export type SetChannelMetadataParameters = { + /** + * Channel name. + */ + channel: string; + + /** + * Space identifier. + * + * @deprecated Use `setChannelMetadata()` method instead. + */ + spaceId?: string; + + /** + * Metadata, which should be associated with UUID. + */ + data: ChannelMetadata; + + /** + * Fields which can be additionally included into response. + */ + include?: Omit; +}; + +/** + * Response with result of the channel metadata object update. + */ +export type SetChannelMetadataResponse = ObjectResponse>; + +/** + * Remove Channel Metadata request parameters. + */ +export type RemoveChannelMetadataParameters = { + /** + * Channel name. + */ + channel: string; + + /** + * Space identifier. + * + * @deprecated Use `removeChannelMetadata()` method instead. + */ + spaceId?: string; +}; + +/** + * Response with result of the channel metadata removal. + */ +export type RemoveChannelMetadataResponse = ObjectResponse>; + +// -------------------------------------------------------- +// ------------------ Memberships API --------------------- +// -------------------------------------------------------- + +/** + * Related channel metadata object. + * + * Type represents chanel metadata which has been used to create membership relation with UUID. + */ +type MembershipsObject = Omit< + ObjectData, + 'id' +> & { + channel: ChannelMetadataObject | { id: string }; +}; + +/** + * Response with fetched page of UUID membership objects. + */ +type MembershipsResponse = PagedResponse< + MembershipsObject +>; + +/** + * Fetch Memberships request parameters. + */ +export type GetMembershipsParameters = PagedRequestParameters & { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuidId`. + * + * @deprecated Use `uuid` field instead. + */ + userId?: string; +}; + +/** + * Response with requested channel memberships information. + */ +export type GetMembershipsResponse< + MembershipCustom extends CustomData, + ChannelCustom extends CustomData, +> = MembershipsResponse; + +/** + * Update Memberships request parameters. + */ +export type SetMembershipsParameters = PagedRequestParameters< + Omit, + MembershipsSortingOptions +> & { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `uuid` field instead. + */ + userId?: string; + + /** + * List of channels with which UUID membership should be established. + */ + channels: Array>; + + /** + * List of channels with which UUID membership should be established. + * + * @deprecated Use `channels` field instead. + */ + spaces?: Array< + | string + | (Omit, 'id'> & { + /** + * Unique Space object identifier. + */ + spaceId: string; + }) + >; +}; + +/** + * Response with requested channel memberships information change. + */ +export type SetMembershipsResponse< + MembershipCustom extends CustomData, + ChannelCustom extends CustomData, +> = MembershipsResponse; + +/** + * Remove Memberships request parameters. + */ +export type RemoveMembershipsParameters = PagedRequestParameters< + MembershipsIncludeOptions, + MembershipsSortingOptions +> & { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use {@link uuid} field instead. + */ + userId?: string; + + /** + * List of channels for which membership which UUID should be removed. + */ + channels: string[]; + + /** + * List of space names for which membership which UUID should be removed. + * + * @deprecated Use {@link channels} field instead. + */ + spaceIds?: string[]; +}; + +/** + * Response with remaining memberships. + */ +export type RemoveMembershipsResponse< + MembershipCustom extends CustomData, + ChannelCustom extends CustomData, +> = MembershipsResponse; + +// -------------------------------------------------------- +// -------------------- Members API ----------------------- +// -------------------------------------------------------- + +/** + * Related UUID metadata object. + * + * Type represents UUID metadata which has been used to when added members to the channel. + */ +type MembersObject = Omit< + ObjectData, + 'id' +> & { + uuid: UUIDMetadataObject | { id: string }; +}; + +/** + * Response with fetched page of channel member objects. + */ +type MembersResponse = PagedResponse< + MembersObject +>; + +/** + * Fetch Members request parameters. + */ +export type GetMembersParameters = PagedRequestParameters & { + /** + * Channel name. + */ + channel: string; + + /** + * Space identifier. + * + * @deprecated Use `channel` field instead. + */ + spaceId?: string; +}; + +/** + * Response with requested channel memberships information. + */ +export type GetMembersResponse = MembersResponse< + MembersCustom, + UUIDCustom +>; + +/** + * Update Members request parameters. + */ +export type SetChannelMembersParameters = PagedRequestParameters< + Omit, + MembersSortingOptions +> & { + /** + * Channel name. + */ + channel: string; + + /** + * Space identifier. + * + * @deprecated Use `channel` field instead. + */ + spaceId?: string; + + /** + * List of UUIDs which should be added as `channel` members. + */ + uuids: Array>; + + /** + * List of UUIDs which should be added as `channel` members. + * + * @deprecated Use `uuids` field instead. + */ + users?: Array< + | string + | (Omit, 'id'> & { + /** + * Unique User object identifier. + */ + userId: string; + }) + >; +}; + +/** + * Response with requested channel members information change. + */ +export type SetMembersResponse = MembersResponse< + MemberCustom, + UUIDCustom +>; +/** + * Remove Members request parameters. + */ +export type RemoveMembersParameters = PagedRequestParameters & { + /** + * Channel name. + */ + channel: string; + + /** + * Space identifier. + * + * @deprecated Use {@link channel} field instead. + */ + spaceId?: string; + + /** + * List of UUIDs which should be removed from the `channel` members list. + * removed. + */ + uuids: string[]; + + /** + * List of user identifiers which should be removed from the `channel` members list. + * removed. + * + * @deprecated Use {@link uuids} field instead. + */ + userIds?: string[]; +}; + +/** + * Response with remaining members. + */ +export type RemoveMembersResponse = MembersResponse< + MemberCustom, + UUIDCustom +>; + +// region Deprecated +/** + * Related User metadata object. + * + * Type represents User metadata which has been used to when added members to the Space. + */ +type UserMembersObject = Omit< + ObjectData, + 'id' +> & { + user: UUIDMetadataObject | { id: string }; +}; + +/** + * Response with fetched page of Space member objects. + */ +export type UserMembersResponse = PagedResponse< + UserMembersObject +>; + +type SpaceMembershipObject = Omit< + ObjectData, + 'id' +> & { + space: ChannelMetadataObject | { id: string }; +}; + +/** + * Response with fetched page of User membership objects. + */ +export type SpaceMembershipsResponse< + MembershipCustom extends CustomData, + ChannelCustom extends CustomData, +> = PagedResponse>; +// endregion diff --git a/src/core/types/api/channel-groups.ts b/src/core/types/api/channel-groups.ts new file mode 100644 index 000000000..79ea23091 --- /dev/null +++ b/src/core/types/api/channel-groups.ts @@ -0,0 +1,64 @@ +/** + * Add or remove Channels to the channel group request parameters. + */ +export type ManageChannelGroupChannelsParameters = { + /** + * Name of the channel group for which channels list should be changed. + */ + channelGroup: string; + + /** + * List of channels to be added or removed. + */ + channels: string[]; +}; + +/** + * Channel group channels list manage response. + */ +export type ManageChannelGroupChannelsResponse = Record; + +/** + * Response with result of the all channel groups list. + */ +export type ListAllChannelGroupsResponse = { + /** + * All channel groups with channels. + */ + groups: string[]; +}; + +/** + * List Channel Group Channels request parameters. + */ +export type ListChannelGroupChannelsParameters = { + /** + * Name of the channel group for which list of channels should be retrieved. + */ + channelGroup: string; +}; + +/** + * Response with result of the list channel group channels. + */ +export type ListChannelGroupChannelsResponse = { + /** + * List of the channels registered withing specified channel group. + */ + channels: string[]; +}; + +/** + * Delete Channel Group request parameters. + */ +export type DeleteChannelGroupParameters = { + /** + * Name of the channel group which should be removed. + */ + channelGroup: string; +}; + +/** + * Delete channel group response. + */ +export type DeleteChannelGroupResponse = Record; diff --git a/src/core/types/api/file-sharing.ts b/src/core/types/api/file-sharing.ts new file mode 100644 index 000000000..90200f69a --- /dev/null +++ b/src/core/types/api/file-sharing.ts @@ -0,0 +1,454 @@ +/** + * File Sharing REST API module. + */ + +import { PubNubFileInterface } from '../file'; +import { Payload } from './index'; + +// -------------------------------------------------------- +// ----------------------- Common ------------------------- +// -------------------------------------------------------- +// region Common + +/** + * Shared file object. + */ +export type SharedFile = { + /** + * Name with which file has been stored. + */ + name: string; + + /** + * Unique service-assigned file identifier. + */ + id: string; + + /** + * Shared file size. + */ + size: number; + + /** + * ISO 8601 time string when file has been shared. + */ + created: string; +}; +// endregion + +// -------------------------------------------------------- +// --------------------- List Files ----------------------- +// -------------------------------------------------------- +// region List Files + +/** + * List Files request parameters. + */ +export type ListFilesParameters = { + /** + * Name of channel for which list of files should be requested. + */ + channel: string; + + /** + * How many entries return with single response. + */ + limit?: number; + + /** + * Next files list page token. + */ + next?: string; +}; + +/** + * List Files request response. + */ +export type ListFilesResponse = { + /** + * Files list fetch result status code. + */ + status: number; + + /** + * List of fetched file objects. + */ + data: SharedFile[]; + + /** + * Next files list page token. + */ + next: string; + + /** + * Number of retrieved files. + */ + count: number; +}; +// endregion + +// -------------------------------------------------------- +// --------------------- Send File ------------------------ +// -------------------------------------------------------- +// region Send File + +/** + * Send File request parameters. + */ +export type SendFileParameters = Omit & { + /** + * Channel to send the file to. + */ + channel: string; + + /** + * File to send. + */ + file: FileParameters; +}; + +/** + * Send File request response. + */ +export type SendFileResponse = PublishFileMessageResponse & { + /** + * Send file request processing status code. + */ + status: number; + + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Important:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; + + /** + * Unique file identifier. + * + * Unique file identifier and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; +}; + +/** + * Upload File request parameters. + */ +export type UploadFileParameters = { + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link fileName} can be used to download file from the channel + * later. + */ + fileId: string; + + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link fileId} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + fileName: string; + + /** + * File which should be uploaded. + */ + file: PubNubFileInterface; + + /** + * Pre-signed file upload Url. + */ + uploadUrl: string; + + /** + * An array of form fields to be used in the pre-signed POST request. + * + * **Important:** Form data fields should be passed in exact same order as received from + * the PubNub service. + */ + formFields: { + /** + * Form data field name. + */ + name: string; + + /** + * Form data field value. + */ + value: string; + }[]; +}; + +/** + * Upload File request response. + */ +export type UploadFileResponse = { + /** + * Upload File request processing status code. + */ + status: number; + + /** + * Service processing result response. + */ + message: Payload; +}; +// endregion + +// -------------------------------------------------------- +// -------------- Generate File Upload Url ---------------- +// -------------------------------------------------------- +// region Generate File Upload Url + +/** + * Generate File Upload URL request parameters. + */ +export type GenerateFileUploadUrlParameters = { + /** + * Name of channel to which file should be uploaded. + */ + channel: string; + + /** + * Actual name of the file which should be uploaded. + */ + name: string; +}; + +/** + * Generation File Upload URL request response. + */ +export type GenerateFileUploadUrlResponse = { + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; + + /** + * Pre-signed URL for file upload. + */ + url: string; + + /** + * An array of form fields to be used in the pre-signed POST request. + * + * **Important:** Form data fields should be passed in exact same order as received from + * the PubNub service. + */ + formFields: { + /** + * Form data field name. + */ + name: string; + + /** + * Form data field value. + */ + value: string; + }[]; +}; +// endregion + +// -------------------------------------------------------- +// ---------------- Publish File Message ------------------ +// -------------------------------------------------------- +// region Publish File Message + +/** + * Publish File Message request parameters. + */ +export type PublishFileMessageParameters = { + /** + * Name of channel to which file has been sent. + */ + channel: string; + + /** + * File annotation message. + */ + message?: Payload; + + /** + * Custom file and message encryption key. + * + * @deprecated Use {@link Configuration#cryptoModule|cryptoModule} configured for PubNub client + * instance or encrypt file prior {@link PubNub#sendFile|sendFile} method call. + */ + cipherKey?: string; + + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link fileName} can be used to download file from the channel + * later. + */ + fileId: string; + + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link fileId} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + fileName: string; + + /** + * Whether published file messages should be stored in the channel's history. + * + * **Note:** If `storeInHistory` not specified, then the history configuration on the key is + * used. + * + * @default `true` + */ + storeInHistory?: boolean; + + /** + * How long the message should be stored in the channel's history. + * + * **Note:** If not specified, defaults to the key set's retention value. + * + * @default `0` + */ + ttl?: number; + + /** + * Metadata, which should be associated with published file. + * + * Associated metadata can be utilized by message filtering feature. + */ + meta?: Payload; +}; + +/** + * Publish File Message request response. + */ +export type PublishFileMessageResponse = { + /** + * High-precision time when published file message has been received by the PubNub service. + */ + timetoken: string; +}; +// endregion + +// -------------------------------------------------------- +// -------------------- Download File --------------------- +// -------------------------------------------------------- +// region Download File +/** + * Download File request parameters. + */ +export type DownloadFileParameters = FileUrlParameters & { + /** + * Custom file and message encryption key. + * + * @deprecated Use {@link Configuration#cryptoModule|cryptoModule} configured for PubNub client + * instance or encrypt file prior {@link PubNub#sendFile|sendFile} method call. + */ + cipherKey?: string; +}; +// endregion + +// -------------------------------------------------------- +// ------------- Generate File Download Url --------------- +// -------------------------------------------------------- +// region Generate File Download Url + +/** + * Generate File download Url request parameters. + */ +export type FileUrlParameters = { + /** + * Name of channel where file has been sent. + */ + channel: string; + + /** + * Unique file identifier. + * + * Unique file identifier and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Important:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; +}; + +/** + * Generate File Download Url response. + */ +export type FileUrlResponse = string; +// endregion + +// -------------------------------------------------------- +// --------------------- Delete File ---------------------- +// -------------------------------------------------------- +// region Delete File + +/** + * Delete File request parameters. + */ +export type DeleteFileParameters = { + /** + * Name of channel where file has been sent. + */ + channel: string; + + /** + * Unique file identifier. + * + * Unique file identifier and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Important:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; +}; + +/** + * Delete File request response. + */ +export type DeleteFileResponse = { + /** + * Delete File request processing status code. + */ + status: number; +}; +// endregion diff --git a/src/core/types/api/history.ts b/src/core/types/api/history.ts new file mode 100644 index 000000000..6bea6b7eb --- /dev/null +++ b/src/core/types/api/history.ts @@ -0,0 +1,475 @@ +import { Payload } from './index'; + +// -------------------------------------------------------- +// --------------------- Get History ---------------------- +// -------------------------------------------------------- +// region Get History + +/** + * Get history request parameters. + */ +export type GetHistoryParameters = { + /** + * Channel to return history messages from. + */ + channel: string; + + /** + * Specifies the number of historical messages to return. + * + * **Note:** Maximum `100` messages can be returned in single response. + * + * @default `100` + */ + count?: number; + + /** + * Whether message `meta` information should be fetched or not. + * + * @default `false` + */ + includeMeta?: boolean; + + /** + * Timetoken delimiting the `start` of `time` slice (exclusive) to pull messages from. + */ + start?: string; + + /** + * Timetoken delimiting the `end` of `time` slice (inclusive) to pull messages from. + */ + end?: string; + + /** + * Whether timeline should traverse in reverse starting with the oldest message first or not. + * + * If both `start` and `end` arguments are provided, `reverse` is ignored and messages are + * returned starting with the newest message. + */ + reverse?: boolean; + + /** + * Whether message timetokens should be stringified or not. + * + * @default `false` + */ + stringifiedTimeToken?: boolean; +}; + +/** + * Get history response. + */ +export type GetHistoryResponse = { + /** + * List of previously published messages. + */ + messages: { + /** + * Message payload (decrypted). + */ + entry: Payload; + + /** + * When message has been received by PubNub service. + */ + timetoken: string | number; + + /** + * Additional data which has been published along with message to be used with real-time + * events filter expression. + */ + meta?: Payload; + + /** + * Message decryption error (if attempt has been done). + */ + error?: string; + }[]; + + /** + * Received messages timeline start. + */ + startTimeToken: string | number; + + /** + * Received messages timeline end. + */ + endTimeToken: string | number; +}; +// endregion + +// -------------------------------------------------------- +// -------------------- Fetch Messages -------------------- +// -------------------------------------------------------- +// region Fetch Messages + +/** + * PubNub-defined message type. + * + * Types of messages which can be retrieved with fetch messages REST API. + */ +export enum PubNubMessageType { + /** + * Regular message. + */ + Message = -1, + + /** + * File message. + */ + Files = 4, +} + +/** + * Per-message actions information. + */ +export type Actions = { + /** + * Message action type. + */ + [t: string]: { + /** + * Message action value. + */ + [v: string]: { + /** + * Unique identifier of the user which reacted on message. + */ + uuid: string; + + /** + * High-precision PubNub timetoken with time when {@link uuid} reacted on message. + */ + actionTimetoken: string; + }; + }; +}; + +/** + * Additional message actions fetch information. + */ +export type MoreActions = { + /** + * Prepared fetch messages with actions REST API URL. + */ + url: string; + + /** + * Next page time offset. + */ + start: string; + + /** + * Number of messages to retrieve with next page. + */ + max: number; +}; + +/** + * Common content of the fetched message. + */ +type BaseFetchedMessage = { + /** + * Name of channel for which message has been retrieved. + */ + channel: string; + + /** + * When message has been received by PubNub service. + */ + timetoken: string | number; + + /** + * Message publisher unique identifier. + */ + uuid?: string; + + /** + * Additional data which has been published along with message to be used with real-time + * events filter expression. + */ + meta?: Payload; + + /** + * Message decryption error (if attempt has been done). + */ + error?: string; +}; + +/** + * Regular message published to the channel. + */ +export type RegularMessage = BaseFetchedMessage & { + /** + * Message payload (decrypted). + */ + message: Payload; + + /** + * PubNub-defined message type. + */ + messageType?: PubNubMessageType.Message; +}; + +/** + * File message published to the channel. + */ +export type FileMessage = BaseFetchedMessage & { + /** + * Message payload (decrypted). + */ + message: { + /** + * File annotation message. + */ + message?: Payload; + + /** + * File information. + */ + file: { + /** + * Unique file identifier. + */ + id: string; + + /** + * Name with which file has been stored. + */ + name: string; + + /** + * File's content mime-type. + */ + 'mime-type': string; + + /** + * Stored file size. + */ + size: number; + + /** + * Pre-computed file download Url. + */ + url: string; + }; + }; + + /** + * PubNub-defined message type. + */ + messageType?: PubNubMessageType.Files; +}; + +/** + * Fetched message entry in channel messages list. + */ +export type FetchedMessage = RegularMessage | FileMessage; + +/** + * Fetched with actions message entry in channel messages list. + */ +export type FetchedMessageWithActions = FetchedMessage & { + /** + * List of message reactions. + */ + actions?: Actions; + /** + * List of message reactions. + * + * @deprecated Use {@link actions} field instead. + */ + data?: Actions; +}; + +/** + * Fetch messages request parameters. + */ +export type FetchMessagesParameters = { + /** + * Specifies channels to return history messages from. + * + * **Note:** Maximum of `500` channels are allowed. + */ + channels: string[]; + + /** + * Specifies the number of historical messages to return per channel. + * + * **Note:** Default is `100` per single channel and `25` per multiple channels or per + * single channel if {@link includeMessageActions} is used. + * + * @default `100` or `25` + */ + count?: number; + + /** + * Whether message type should be returned with each history message or not. + * + * @default `true` + */ + includeMessageType?: boolean; + + /** + * Whether publisher `uuid` should be returned with each history message or not. + * + * @default `true` + */ + includeUUID?: boolean; + + /** + * Whether publisher `uuid` should be returned with each history message or not. + * + * @deprecated Use {@link includeUUID} property instead. + */ + includeUuid?: boolean; + + /** + * Whether message `meta` information should be fetched or not. + * + * @default `false` + */ + includeMeta?: boolean; + + /** + * Whether message-added message actions should be fetched or not. + * + * If used, the limit of messages retrieved will be `25` per single channel. + * + * Each message can have a maximum of `25000` actions attached to it. Consider the example of + * querying for 10 messages. The first five messages have 5000 actions attached to each of + * them. The API will return the first 5 messages and all their 25000 actions. The response + * will also include a `more` link to get the remaining 5 messages. + * + * **Important:** Truncation will happen if the number of actions on the messages returned + * is > 25000. + * + * @default `false` + * + * @throws Exception if API is called with more than one channel. + */ + includeMessageActions?: boolean; + + /** + * Timetoken delimiting the `start` of `time` slice (exclusive) to pull messages from. + */ + start?: string; + + /** + * Timetoken delimiting the `end` of `time` slice (inclusive) to pull messages from. + */ + end?: string; + + /** + * Whether message timetokens should be stringified or not. + * + * @default `false` + */ + stringifiedTimeToken?: boolean; +}; + +/** + * Fetch messages response. + */ +export type FetchMessagesForChannelsResponse = { + /** + * List of previously published messages per requested channel. + */ + channels: { + [p: string]: FetchedMessage[]; + }; +}; + +/** + * Fetch messages with reactions response. + */ +export type FetchMessagesWithActionsResponse = { + channels: { + [p: string]: FetchedMessageWithActions[]; + }; + + /** + * Additional message actions fetch information. + */ + more: MoreActions; +}; + +/** + * Fetch messages response. + */ +export type FetchMessagesResponse = FetchMessagesForChannelsResponse | FetchMessagesWithActionsResponse; +// endregion + +// -------------------------------------------------------- +// ------------------- Messages Count --------------------- +// -------------------------------------------------------- +// region Messages Count + +/** + * Message count request parameters. + */ +export type MessageCountParameters = { + /** + * The channels to fetch the message count. + */ + channels: string[]; + + /** + * List of timetokens, in order of the {@link channels} list. + * + * Specify a single timetoken to apply it to all channels. Otherwise, the list of timetokens + * must be the same length as the list of {@link channels}, or the function returns an error + * flag. + */ + channelTimetokens?: string[]; + + /** + * High-precision PubNub timetoken starting from which number of messages should be counted. + * + * Same timetoken will be used to count messages for each passed {@link channels}. + * + * @deprecated Use {@link channelTimetokens} field instead. + */ + timetoken?: string; +}; +/** + * Message count response. + */ +export type MessageCountResponse = { + /** + * Map of channel names to the number of counted messages. + */ + channels: Record; +}; +// endregion + +// -------------------------------------------------------- +// ------------------- Delete Messages -------------------- +// -------------------------------------------------------- +// region Delete Messages + +/** + * Delete messages from channel parameters. + */ +export type DeleteMessagesParameters = { + /** + * Specifies channel messages to be deleted from history. + */ + channel: string; + + /** + * Timetoken delimiting the start of time slice (exclusive) to delete messages from. + */ + start?: string; + + /** + * Timetoken delimiting the end of time slice (inclusive) to delete messages from. + */ + end?: string; +}; + +/** + * Delete messages from channel response. + */ +export type DeleteMessagesResponse = Record; +// endregion diff --git a/src/core/types/api/index.ts b/src/core/types/api/index.ts new file mode 100644 index 000000000..dd3a51e1f --- /dev/null +++ b/src/core/types/api/index.ts @@ -0,0 +1,145 @@ +// PubNub client API common types. + +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import StatusCategory from '../../constants/categories'; + +/** + * PubNub account keyset. + */ +export type KeySet = { + /** + * Specifies the `subscribeKey` to be used for subscribing to a channel and message publishing. + */ + subscribeKey: string; + + /** + * Specifies the `publishKey` to be used for publishing messages to a channel. + */ + publishKey?: string; + + /** + * Specifies the `secretKey` to be used for request signatures computation. + */ + secretKey?: string; +}; + +/** + * REST API request processing function. + */ +export type SendRequestFunction = ( + request: AbstractRequest, + callback?: ResultCallback, +) => Promise; + +/** + * Endpoint call completion block with result. + * + * **Note:** Endpoints which return consumable data use this callback. + */ +export type ResultCallback = (status: Status, response: ResponseType | null) => void; + +/** + * Endpoint acknowledgment completion block. + * + * **Note:** Endpoints which return only acknowledgment or error status use this callback. + */ +export type StatusCallback = (status: Status) => void; + +/** + * REST API endpoint processing status. + * + * **Note:** Used as {@link ResultCallback} and {@link StatusCallback} callbacks first argument type and + * {@link PubNubError} instance `status` field value type. + */ +export type Status = { + /** + * Whether status represent error or not. + */ + error: boolean; + /** + * API call status category. + */ + category: StatusCategory; + + /** + * Type of REST API endpoint which reported status. + */ + operation?: RequestOperation; + + /** + * REST API response status code. + */ + statusCode: number; + + /** + * Error data provided by REST API. + */ + errorData?: Error | Payload; + + /** + * Additional status information. + */ + [p: string]: Payload | Error | undefined; +}; + +/** + * Real-time PubNub client status change event. + */ +export type StatusEvent = { + /** + * API call status category. + */ + category: StatusCategory; + + /** + * Type of REST API endpoint which reported status. + */ + operation?: RequestOperation; + + /** + * Information about error. + */ + error?: string | boolean; + + /** + * List of channels for which status update announced. + */ + affectedChannels?: string[]; + + /** + * List of currently subscribed channels. + * + * List of channels from which PubNub client receives real-time updates. + */ + subscribedChannels?: string[]; + + /** + * List of channel groups for which status update announced. + */ + affectedChannelGroups?: string[]; + + /** + * High-precision timetoken which has been used with previous subscription loop. + */ + lastTimetoken?: number | string; + + /** + * High-precision timetoken which is used for current subscription loop. + */ + currentTimetoken?: number | string; +}; + +/** + * {@link TransportRequest} query parameter type. + */ +export type Query = Record; + +/** + * General payload type. + * + * Type should be used for: + * * generic messages and signals content, + * * published message metadata. + */ +export type Payload = string | number | boolean | { [key: string]: Payload | null } | Payload[]; diff --git a/src/core/types/api/message-action.ts b/src/core/types/api/message-action.ts new file mode 100644 index 000000000..125d3a3e0 --- /dev/null +++ b/src/core/types/api/message-action.ts @@ -0,0 +1,175 @@ +/** + * Message reaction object type. + */ +export type MessageAction = { + /** + * What feature this message action represents. + */ + type: string; + + /** + * Value which should be stored along with message action. + */ + value: string; + + /** + * Unique identifier of the user which added message action. + */ + uuid: string; + + /** + * Timetoken of when message reaction has been added. + * + * **Note:** This token required when it will be required to remove raction. + */ + actionTimetoken: string; + + /** + * Timetoken of message to which `action` has been added. + */ + messageTimetoken: string; +}; + +/** + * More message actions fetch information. + */ +export type MoreMessageActions = { + /** + * Prepared REST API url to fetch next page with message actions. + */ + url: string; + + /** + * Message action timetoken denoting the start of the range requested with next page. + * + * **Note:** Return values will be less than {@link start}. + */ + start: string; + + /** + * Message action timetoken denoting the end of the range requested with next page. + * + * **Note:** Return values will be greater than or equal to {@link end}. + */ + end: string; + /** + * Number of message actions to return in next response. + */ + limit: number; +}; + +/** + * Add Message Action request parameters. + */ +export type AddMessageActionParameters = { + /** + * Name of channel which stores the message for which {@link action} should be added. + */ + channel: string; + + /** + * Timetoken of message for which {@link action} should be added. + */ + messageTimetoken: string; + + /** + * Message `action` information. + */ + action: { + /** + * What feature this message action represents. + */ + type: string; + + /** + * Value which should be stored along with message action. + */ + value: string; + }; +}; + +/** + * Response with added message action object. + */ +export type AddMessageActionResponse = { data: MessageAction }; + +/** + * Get Message Actions request parameters. + */ +export type GetMessageActionsParameters = { + /** + * Name of channel from which list of messages `actions` should be retrieved. + */ + channel: string; + + /** + * Message action timetoken denoting the start of the range requested. + * + * **Note:** Return values will be less than {@link start}. + */ + start?: string; + + /** + * Message action timetoken denoting the end of the range requested. + * + * **Note:** Return values will be greater than or equal to {@link end}. + */ + end?: string; + + /** + * Number of message actions to return in response. + */ + limit?: number; +}; + +/** + * Response with message actions in specific `channel`. + */ +export type GetMessageActionsResponse = { + /** + * Retrieved list of message actions. + */ + data: MessageAction[]; + + /** + * Received message actions time frame start. + */ + start: string | null; + + /** + * Received message actions time frame end. + */ + end: string | null; + + /** + * More message actions fetch information. + */ + more?: MoreMessageActions; +}; + +/** + * Remove Message Action request parameters. + */ +export type RemoveMessageActionParameters = { + /** + * Name of channel which store message for which `action` should be removed. + */ + channel: string; + + /** + * Timetoken of message for which `action` should be removed. + */ + messageTimetoken: string; + + /** + * Action addition timetoken. + */ + actionTimetoken: string; +}; + +/** + * Response with message remove result. + */ +export type RemoveMessageActionResponse = { + data: Record; +}; diff --git a/src/core/types/api/presence.ts b/src/core/types/api/presence.ts new file mode 100644 index 000000000..16d9e2f33 --- /dev/null +++ b/src/core/types/api/presence.ts @@ -0,0 +1,250 @@ +import { Payload } from './index'; + +// region Get Presence State +/** + * Associated presence state fetch parameters. + */ +export type GetPresenceStateParameters = { + /** + * The subscriber uuid to get the current state. + * + * @default `current uuid` + */ + uuid?: string; + + /** + * List of channels for which state associated with {@link uuid} should be retrieved. + * + * **Important:** Either {@link channels} or {@link channelGroups} should be provided; + */ + channels?: string[]; + + /** + * List of channel groups for which state associated with {@link uuid} should be retrieved. + * + * **Important:** Either {@link channels} or {@link channelGroups} should be provided; + */ + channelGroups?: string[]; +}; + +/** + * Associated presence state fetch response. + */ +export type GetPresenceStateResponse = { + /** + * Channels map to state which `uuid` has associated with them. + */ + channels: Record; +}; +// endregion + +// region Set Presence State +/** + * Associate presence state parameters. + */ +export type SetPresenceStateParameters = { + /** + * List of channels for which state should be associated with {@link uuid}. + */ + channels?: string[]; + + /** + * List of channel groups for which state should be associated with {@link uuid}. + */ + channelGroups?: string[]; + + /** + * State which should be associated with `uuid` on provided list of {@link channels} and {@link channelGroups}. + */ + state: Payload; +}; + +/** + * Associate presence state parameters using heartbeat. + */ +export type SetPresenceStateWithHeartbeatParameters = { + /** + * List of channels for which state should be associated with {@link uuid}. + */ + channels?: string[]; + + /** + * State which should be associated with `uuid` on provided list of {@link channels}. + */ + state: Payload; + + /** + * Whether `presence/heartbeat` REST API should be used to manage state or not. + * + * @default `false` + */ + withHeartbeat: boolean; +}; + +/** + * Associate presence state response. + */ +export type SetPresenceStateResponse = { + /** + * State which has been associated with `uuid` on provided list of channels and groups. + */ + state: Payload; +}; +// endregion + +// region Heartbeat announce +/** + * Announce heartbeat parameters. + */ +export type PresenceHeartbeatParameters = { + /** + * How long the server will consider the client alive for presence.The value is in seconds. + */ + heartbeat: number; + + /** + * List of channels for which heartbeat should be announced for {@link uuid}. + */ + channels?: string[]; + + /** + * List of channel groups for which heartbeat should be announced for {@link uuid}. + */ + channelGroups?: string[]; + + /** + * State which should be associated with `uuid` on provided list of {@link channels} and {@link channelGroups}. + */ + state?: Payload; +}; + +/** + * Announce heartbeat response. + */ +export type PresenceHeartbeatResponse = Record; +// endregion + +// region Get Presence State +/** + * Presence leave parameters. + */ +export type PresenceLeaveParameters = { + /** + * List of channels for which `uuid` should be marked as `offline`. + */ + channels?: string[]; + + /** + /** + * List of channel groups for which `uuid` should be marked as `offline`. + */ + channelGroups?: string[]; +}; + +/** + * Presence leave response. + */ +export type PresenceLeaveResponse = Record; +// endregion + +// region Here now +/** + * Channel / channel group presence fetch parameters.. + */ +export type HereNowParameters = { + /** + * List of channels for which presence should be retrieved. + */ + channels?: string[]; + + /** + * List of channel groups for which presence should be retrieved. + */ + channelGroups?: string[]; + + /** + * Whether `uuid` information should be included in response or not. + * + * **Note:** Only occupancy information will be returned if both {@link includeUUIDs} and {@link includeState} is + * set to `false`. + * + * @default `true` + */ + includeUUIDs?: boolean; + + /** + * Whether state associated with `uuid` should be included in response or not. + * + * @default `false`. + */ + includeState?: boolean; + + /** + * Additional query parameters. + */ + queryParameters?: Record; +}; + +/** + * `uuid` where now response. + */ +export type HereNowResponse = { + /** + * Total number of channels for which presence information received. + */ + totalChannels: number; + + /** + * Total occupancy for all retrieved channels. + */ + totalOccupancy: number; + + /** + * List of channels to which `uuid` currently subscribed. + */ + channels: { + [p: string]: { + /** + * List of received channel subscribers. + * + * **Note:** Field is missing if `uuid` and `state` not included. + */ + occupants: { uuid: string; state?: Payload | null }[]; + + /** + * Name of channel for which presence information retrieved. + */ + name: string; + + /** + * Total number of active subscribers in single channel. + */ + occupancy: number; + }; + }; +}; +// endregion + +// region Where now +/** + * `uuid` where now parameters. + */ +export type WhereNowParameters = { + /** + * The subscriber uuid to get the current state. + * + * @default `current uuid` + */ + uuid?: string; +}; + +/** + * `uuid` where now response. + */ +export type WhereNowResponse = { + /** + * Channels map to state which `uuid` has associated with them. + */ + channels: string[]; +}; +// endregion diff --git a/src/core/types/api/push-notifications.ts b/src/core/types/api/push-notifications.ts new file mode 100644 index 000000000..8dd0dadcf --- /dev/null +++ b/src/core/types/api/push-notifications.ts @@ -0,0 +1,53 @@ +/** + * Type of Push Notifications gateway which should be used with Push Notifications REST API. + */ +type PushGateway = 'apns2' | 'gcm'; + +/** + * Basic information required by Push Notifications REST API about device. + */ +type DevicePush = { + /** + * Device ID for which list of registered channel push notifications will be changed. + */ + device: string; + + /** + * Push Notifications gateway to use. + * + * **Important:** Depends from the source of `device` token and can be `apns2` (for token + * provided during device registration using Apple's framework) or `gcm` (when used Firebase + * or similar framework to receive token). + */ + pushGateway: PushGateway; +}; + +/** + * Register and unregister push notifications for device request parameters. + */ +export type ManageDeviceChannelsParameters = { + /** + * List of channels to be added or removed. + */ + channels: string[]; +} & DevicePush; + +/** + * List Device Channels request parameters. + */ +export type ListDeviceChannelsParameters = DevicePush; + +/** + * Response with result of the list device channels. + */ +export type ListDeviceChannelsResponse = { + /** + * List of the channels for which `device` will receive push notifications. + */ + channels: string[]; +}; + +/** + * Delete Push Notification for device request parameters. + */ +export type DeleteDeviceParameters = DevicePush; diff --git a/src/core/types/api/push.ts b/src/core/types/api/push.ts new file mode 100644 index 000000000..f4fe04edf --- /dev/null +++ b/src/core/types/api/push.ts @@ -0,0 +1,156 @@ +/** + * Common managed channels push notification parameters. + */ +type ManagedDeviceChannels = { + /** + * Channels to register or unregister with mobile push notifications. + */ + channels: string[]; + + /** + * The device ID to associate with mobile push notifications. + */ + device: string; + + /** + * Starting channel for pagination. + * + * **Note:** Use the last channel from the previous page request. + */ + start?: string; + + /** + * Number of channels to return for pagination. + * + * **Note:** maximum of 1000 tokens at a time. + * + * @default `500` + */ + count?: number; +}; + +// region List channels +/** + * List all FCM device push notification enabled channels parameters. + */ +type ListFCMDeviceChannelsParameters = Omit; + +/** + * List all APNS device push notification enabled channels parameters. + * + * @deprecated Use `APNS2`-based endpoints. + */ +type ListAPNSDeviceChannelsParameters = Omit; + +/** + * List all APNS2 device push notification enabled channels parameters. + */ +type ListAPNS2DeviceChannelsParameters = Omit; + +/** + * List all device push notification enabled channels parameters. + */ +export type ListDeviceChannelsParameters = + | ListFCMDeviceChannelsParameters + | ListAPNSDeviceChannelsParameters + | ListAPNS2DeviceChannelsParameters; + +/** + * List all device push notification enabled channels response. + */ +export type ListDeviceChannelsResponse = { + /** + * List of channels registered for device push notifications. + */ + channels: string[]; +}; +// endregion + +// region Add / Remove channels +/** + * Manage FCM device push notification enabled channels parameters. + */ +type ManageFCMDeviceChannelsParameters = ManagedDeviceChannels & { + /** + * Push Notifications gateway type. + */ + pushGateway: 'gcm'; +}; + +/** + * Manage APNS device push notification enabled channels parameters. + * + * @deprecated Use `APNS2`-based endpoints. + */ +type ManageAPNSDeviceChannelsParameters = ManagedDeviceChannels & { + /** + * Push Notifications gateway type. + */ + pushGateway: 'apns'; +}; + +/** + * Manage APNS2 device push notification enabled channels parameters. + */ +type ManageAPNS2DeviceChannelsParameters = ManagedDeviceChannels & { + /** + * Push Notifications gateway type. + */ + pushGateway: 'apns2'; + + /** + * Environment within which device should manage list of channels with enabled notifications. + */ + environment?: 'development' | 'production'; + + /** + * Notifications topic name (usually it is bundle identifier of application for Apple platform). + */ + topic: string; +}; + +/** + * Manage device push notification enabled channels parameters. + */ +export type ManageDeviceChannelsParameters = + | ManageFCMDeviceChannelsParameters + | ManageAPNSDeviceChannelsParameters + | ManageAPNS2DeviceChannelsParameters; + +/** + * Manage device push notification enabled channels response. + */ +export type ManageDeviceChannelsResponse = Record; +// endregion + +// region Remove device +/** + * Remove all FCM device push notification enabled channels parameters. + */ +type RemoveFCMDeviceParameters = Omit; + +/** + * Manage APNS device push notification enabled channels parameters. + * + * @deprecated Use `APNS2`-based endpoints. + */ +type RemoveAPNSDeviceParameters = Omit; + +/** + * Manage APNS2 device push notification enabled channels parameters. + */ +type RemoveAPNS2DeviceParameters = Omit; + +/** + * Remove all device push notification enabled channels parameters. + */ +export type RemoveDeviceParameters = + | RemoveFCMDeviceParameters + | RemoveAPNSDeviceParameters + | RemoveAPNS2DeviceParameters; + +/** + * Remove all device push notification enabled channels response. + */ +export type RemoveDeviceResponse = Record; +// endregion diff --git a/src/core/types/api/subscription.ts b/src/core/types/api/subscription.ts new file mode 100644 index 000000000..5cdab91fe --- /dev/null +++ b/src/core/types/api/subscription.ts @@ -0,0 +1,371 @@ +import { + RequestParameters as SubscribeRequestParameters, + VSPMembershipObjectData, + AppContextObjectData, + MessageActionData, + PubNubEventType, + SpaceObjectData, + UserObjectData, + PresenceData, + FileData, +} from '../../endpoints/subscribe'; +import { AbortSignal } from '../../components/abort_signal'; +import { Payload } from './index'; + +// -------------------------------------------------------- +// --------------------- Event types ---------------------- +// -------------------------------------------------------- +// region Even types + +/** + * Time cursor. + * + * Cursor used by subscription loop to identify point in time after which updates will be + * delivered. + */ +export type SubscriptionCursor = { + /** + * PubNub high-precision timestamp. + * + * Aside of specifying exact time of receiving data / event this token used to catchup / + * follow on real-time updates. + */ + timetoken: string | number; + + /** + * Data center region for which `timetoken` has been generated. + */ + region?: number; +}; + +/** + * Common real-time event. + */ +type Event = { + /** + * Channel to which real-time event has been sent. + */ + channel: string; + + /** + * Actual subscription at which real-time event has been received. + * + * PubNub client provide various ways to subscribe to the real-time stream: channel groups, + * wildcard subscription, and spaces. + * + * **Note:** Value will be `null` if it is the same as {@link channel}. + */ + subscription: string | null; + + /** + * High-precision PubNub timetoken with time when event has been received by PubNub services. + */ + timetoken: string; +}; + +/** + * Common legacy real-time event for backward compatibility. + */ +type LegacyEvent = Event & { + /** + * Channel to which real-time event has been sent. + * + * @deprecated Use {@link channel} field instead. + */ + actualChannel?: string | null; + + /** + * Actual subscription at which real-time event has been received. + * + * @deprecated Use {@link subscription} field instead. + */ + subscribedChannel?: string; +}; + +// region Presence event +/** + * Presence change real-time event. + */ +export type Presence = LegacyEvent & PresenceData; + +/** + * Extended presence real-time event. + * + * Type extended for listener manager support. + */ +type PresenceEvent = { + type: PubNubEventType.Presence; + data: Presence; +}; +// endregion + +// region Data publish event +/** + * Common published data information. + */ +type PublishedData = { + /** + * Unique identifier of the user which sent data. + */ + publisher?: string; + + /** + * Additional user-provided metadata which can be used with real-time filtering expression. + */ + userMetadata?: { [p: string]: Payload }; + + /** + * Sent data. + */ + message: Payload; +}; + +/** + * Real-time message event. + */ +export type Message = LegacyEvent & + PublishedData & { + /** + * Decryption error message in case of failure. + */ + error?: string; + }; + +/** + * Extended real-time message event. + * + * Type extended for listener manager support. + */ +type MessageEvent = { + type: PubNubEventType.Message; + data: Message; +}; + +/** + * Real-time signal event. + */ +export type Signal = Event & PublishedData; + +/** + * Extended real-time signal event. + * + * Type extended for listener manager support. + */ +type SignalEvent = { + type: PubNubEventType.Signal; + data: Signal; +}; +// endregion + +// region Message action event + +/** + * Message action real-time event. + */ +export type MessageAction = Event & + Omit & { + /** + * Unique identifier of the user which added message reaction. + * + * @deprecated Use `data.uuid` field instead. + */ + publisher?: string; + + data: MessageActionData['data'] & { + /** + * Unique identifier of the user which added message reaction. + */ + uuid: string; + }; + }; + +/** + * Extended message action real-time event. + * + * Type extended for listener manager support. + */ +type MessageActionEvent = { + type: PubNubEventType.MessageAction; + data: MessageAction; +}; +// endregion + +// region App Context event +/** + * App Context Object change real-time event. + */ +export type AppContextObject = Event & { + /** + * Information about App Context object for which event received. + */ + message: AppContextObjectData; +}; + +/** + * `User` App Context Object change real-time event. + */ +export type UserAppContextObject = Omit & { + /** + * Space to which real-time event has been sent. + */ + spaceId: string; + + /** + * Information about User Object for which event received. + */ + message: UserObjectData; +}; + +/** + * `Space` App Context Object change real-time event. + */ +export type SpaceAppContextObject = Omit & { + /** + * Space to which real-time event has been sent. + */ + spaceId: string; + + /** + * Information about `Space` Object for which event received. + */ + message: SpaceObjectData; +}; + +/** + * VSP `Membership` App Context Object change real-time event. + */ +export type VSPMembershipAppContextObject = Omit & { + /** + * Space to which real-time event has been sent. + */ + spaceId: string; + + /** + * Information about `Membership` Object for which event received. + */ + message: VSPMembershipObjectData; +}; + +/** + * Extended App Context Object change real-time event. + * + * Type extended for listener manager support. + */ +type AppContextEvent = { + type: PubNubEventType.AppContext; + data: AppContextObject; +}; +// endregion + +// region File event +/** + * File real-time event. + */ +export type File = Event & + Omit & + Omit & { + /** + * Message which has been associated with uploaded file. + */ + message?: Payload; + + /** + * Information about uploaded file. + */ + file?: FileData['file'] & { + /** + * File download url. + */ + url: string; + }; + + /** + * Decryption error message in case of failure. + */ + error?: string; + }; + +/** + * Extended File real-time event. + * + * Type extended for listener manager support. + */ +type FileEvent = { + type: PubNubEventType.Files; + data: File; +}; +// endregion + +// -------------------------------------------------------- +// -------------------- Request types --------------------- +// -------------------------------------------------------- + +/** + * Cancelable subscribe request parameters. + */ +export type CancelableSubscribeParameters = Omit< + SubscribeRequestParameters, + 'crypto' | 'timeout' | 'keySet' | 'getFileUrl' +> & { + /** + * Long-poll request termination signal. + */ + abortSignal: AbortSignal; +}; + +/** + * Subscribe request parameters. + */ +export type SubscribeParameters = { + /** + * List of channels from which real-time events should be delivered. + * + * @default `,` if {@link channelGroups} is set. + */ + channels?: string[]; + + /** + * List of channel groups from which real-time events should be retrieved. + */ + channelGroups?: string[]; + + /** + * Next subscription loop timetoken. + */ + timetoken?: string | number; + + /** + * Whether should subscribe to channels / groups presence announcements or not. + * + * @default `false` + */ + withPresence?: boolean; + + // region Deprecated + /** + * Presence information which should be associated with `userId`. + * + * `state` information will be associated with `userId` on channels mentioned as keys in + * this object. + * + * @deprecated Use set state methods to specify associated user's data instead of passing to + * subscribe. + */ + state?: Record; + + /** + * Whether should subscribe to channels / groups presence announcements or not. + * + * @default `false` + */ + withHeartbeats?: boolean; + // endregion +}; + +/** + * Service success response. + */ +export type SubscriptionResponse = { + cursor: SubscriptionCursor; + messages: (PresenceEvent | MessageEvent | SignalEvent | MessageActionEvent | AppContextEvent | FileEvent)[]; +}; diff --git a/src/core/types/file.ts b/src/core/types/file.ts new file mode 100644 index 000000000..0423b5151 --- /dev/null +++ b/src/core/types/file.ts @@ -0,0 +1,120 @@ +/** + * {@link PubNub} File object interface module. + */ + +/** + * Base file constructor parameters. + * + * Minimum set of parameters which can be p + */ +export type PubNubBasicFileParameters = { + data: string | ArrayBuffer; + name: string; + mimeType?: string; +}; + +/** + * Platform-agnostic {@link PubNub} File object. + * + * Interface describes share of {@link PubNub} File which is required by {@link PubNub} core to + * perform required actions. + */ +export interface PubNubFileInterface { + /** + * Actual file name. + */ + name: string; + + /** + * File mime-type. + */ + mimeType?: string; + + /** + * File content length. + */ + contentLength?: number; + + /** + * Convert {@link PubNub} file object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toArrayBuffer(): Promise; + + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @returns Asynchronous results of conversion to file `Uri`. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toFileUri(): Promise>; +} + +/** + * {@link PubNub} File object class interface. + */ +export interface PubNubFileConstructor { + /** + * Whether {@link Blob} data supported by platform or not. + */ + supportsBlob: boolean; + + /** + * Whether {@link File} data supported by platform or not. + */ + supportsFile: boolean; + + /** + * Whether {@link Buffer} data supported by platform or not. + */ + supportsBuffer: boolean; + + /** + * Whether {@link Stream} data supported by platform or not. + */ + supportsStream: boolean; + + /** + * Whether {@link String} data supported by platform or not. + */ + supportsString: boolean; + + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + supportsArrayBuffer: boolean; + + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + supportsEncryptFile: boolean; + + /** + * Whether `File Uri` data supported by platform or not. + */ + supportsFileUri: boolean; + + /** + * {@link PubNub} File object constructor. + * + * @param file - File instantiation parameters (can be raw data or structured object). + * + * @returns Constructed platform-specific {@link PubNub} File object. + */ + create(file: ConstructorParameters): File; + + /** + * {@link PubNub} File object constructor. + * + * @param file - File instantiation parameters (can be raw data or structured object). + * + * @returns Constructed platform-specific {@link PubNub} File object. + */ + new (file: ConstructorParameters): File; +} diff --git a/src/core/types/transport-request.ts b/src/core/types/transport-request.ts new file mode 100644 index 000000000..22ea0c521 --- /dev/null +++ b/src/core/types/transport-request.ts @@ -0,0 +1,110 @@ +import { PubNubFileInterface } from './file'; +import { Query } from './api'; + +/** + * Enum representing possible transport methods for HTTP requests. + * + * @enum {number} + */ +export enum TransportMethod { + /** + * Request will be sent using `GET` method. + */ + GET = 'GET', + /** + * Request will be sent using `POST` method. + */ + POST = 'POST', + /** + * Request will be sent using `PATCH` method. + */ + PATCH = 'PATCH', + /** + * Request will be sent using `DELETE` method. + */ + DELETE = 'DELETE', + + /** + * Local request. + * + * Request won't be sent to the service and probably used to compute URL. + */ + LOCAL = 'LOCAL', +} + +/** + * Request cancellation controller. + */ +export type CancellationController = { + /** + * Request cancellation / abort function. + */ + abort: () => void; +}; + +/** + * This object represents a request to be sent to the PubNub API. + * + * This struct represents a request to be sent to the PubNub API. It is used by the transport + * provider which implements {@link Transport} interface. + * + * All fields are representing certain parts of the request that can be used to prepare one. + */ +export type TransportRequest = { + /** + * Remote host name. + */ + origin?: string; + + /** + * Remote resource path. + */ + path: string; + + /** + * Query parameters to be sent with the request. + */ + queryParameters?: Query; + + /** + * Transport request HTTP method. + */ + method: TransportMethod; + + /** + * Headers to be sent with the request. + */ + headers?: Record; + + /** + * Multipart form data fields. + * + * **Important:** `Content-Type` header should be sent the {@link body} data type when + * `multipart/form-data` should request should be sent. + */ + formData?: Record[]; + + /** + * Body to be sent with the request. + */ + body?: ArrayBuffer | PubNubFileInterface | string; + + /** + * For how long request should wait response from the server. + * + * @default `10` seconds. + */ + timeout: number; + + /** + * Whether request can be cancelled or not. + * + * @default `false`. + */ + cancellable: boolean; + + /** + * Unique request identifier. + */ + identifier: string; +}; diff --git a/src/core/types/transport-response.ts b/src/core/types/transport-response.ts new file mode 100644 index 000000000..22dc20ef4 --- /dev/null +++ b/src/core/types/transport-response.ts @@ -0,0 +1,26 @@ +/** + * Represents a transport response from a service. + */ +export type TransportResponse = { + /** + * Full remote resource URL used to retrieve response. + */ + url: string; + + /** + * Service response status code. + */ + status: number; + + /** + * Service response headers. + * + * **Important:** Header names are in lowercase. + */ + headers: Record; + + /** + * Service response body. + */ + body?: ArrayBuffer; +}; diff --git a/src/core/utils.js b/src/core/utils.js deleted file mode 100644 index 668845dd6..000000000 --- a/src/core/utils.js +++ /dev/null @@ -1,71 +0,0 @@ -function objectToList(o) { - const l = []; - Object.keys(o).forEach((key) => l.push(key)); - return l; -} - -function encodeString(input) { - return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); -} - -function objectToListSorted(o) { - return objectToList(o).sort(); -} - -function signPamFromParams(params) { - const l = objectToListSorted(params); - return l.map((paramKey) => `${paramKey}=${encodeString(params[paramKey])}`).join('&'); -} - -function endsWith(searchString, suffix) { - return searchString.indexOf(suffix, this.length - suffix.length) !== -1; -} - -function createPromise() { - let successResolve; - let failureResolve; - const promise = new Promise((fulfill, reject) => { - successResolve = fulfill; - failureResolve = reject; - }); - - return { promise, reject: failureResolve, fulfill: successResolve }; -} - -function stringToArrayBuffer(str) { - var buf = new ArrayBuffer(str.length * 2); - var bufView = new Uint16Array(buf); - for (var i = 0, strLen = str.length; i < strLen; i++) { - bufView[i] = str.charCodeAt(i); - } - return buf; -} - -function removeSingleOccurance(source, elementsToRemove) { - let removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); - - return source.filter((e) => { - if (elementsToRemove.includes(e) && !removed[e]) { - removed[e] = true; - return false; - } - return true; - }); -} - -function findUniqueCommonElements(a, b) { - return [...a].filter( - (value) => - b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value), - ); -} - -module.exports = { - signPamFromParams, - endsWith, - createPromise, - encodeString, - stringToArrayBuffer, - removeSingleOccurance, - findUniqueCommonElements, -}; diff --git a/src/core/utils.ts b/src/core/utils.ts new file mode 100644 index 000000000..dc65d95b4 --- /dev/null +++ b/src/core/utils.ts @@ -0,0 +1,65 @@ +import { Query } from './types/api'; + +/** + * Percent-encode input string. + * + * **Note:** Encode content in accordance of the `PubNub` service requirements. + * + * @param input - Source string or number for encoding. + * + * @returns Percent-encoded string. + */ +export const encodeString = (input: string | number) => { + return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); +}; + +/** + * Percent-encode list of names (channels). + * + * @param names - List of names which should be encoded. + * + * @param [defaultString] - String which should be used in case if {@link names} is empty. + * + * @returns String which contains encoded names joined by non-encoded `,`. + */ +export const encodeNames = (names: string[], defaultString?: string) => { + const encodedNames = names.map((name) => encodeString(name)); + return encodedNames.length ? encodedNames.join(',') : defaultString ?? ''; +}; + +export const removeSingleOccurance = (source: string[], elementsToRemove: string[]) => { + const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); + + return source.filter((e) => { + if (elementsToRemove.includes(e) && !removed[e]) { + removed[e] = true; + return false; + } + return true; + }); +}; + +export const findUniqueCommonElements = (a: string[], b: string[]) => { + return [...a].filter( + (value) => + b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value), + ); +}; + +/** + * Transform query key / value pairs to the string. + * + * @param query - Key / value pairs of the request query parameters. + * + * @returns Stringified query key / value pairs. + */ +export const queryStringFromObject = (query: Query) => { + return Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) return `${key}=${encodeString(queryValue)}`; + + return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); + }) + .join('&'); +}; diff --git a/src/crypto/modules/NodeCryptoModule/ICryptor.ts b/src/crypto/modules/NodeCryptoModule/ICryptor.ts index 5e73cee31..63860b300 100644 --- a/src/crypto/modules/NodeCryptoModule/ICryptor.ts +++ b/src/crypto/modules/NodeCryptoModule/ICryptor.ts @@ -1,19 +1,106 @@ +/** + * Cryptor module. + */ + +/** + * Data encrypted by {@link CryptoModule}. + */ export type EncryptedDataType = { + /** + * Encrypted data. + */ data: Buffer | string; + + /** + * Used cryptor's metadata. + */ metadata: Buffer | null; }; +/** + * {@link Readable} stream encrypted by {@link CryptoModule}. + */ export type EncryptedStream = { + /** + * Stream with encrypted content. + */ stream: NodeJS.ReadableStream; + + /** + * Length of encrypted data in {@link Readable} stream. + */ metadataLength: number; + + /** + * Used cryptor's metadata. + */ metadata?: Buffer | undefined; }; +/** + * Cryptor algorithm interface. + */ export interface ICryptor { + /** + * Cryptor unique identifier. + * + * @returns Cryptor identifier. + */ get identifier(): string; + + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + + // region Encryption + /** + * Encrypt provided source data. + * + * @param data - Source data for encryption. + * + * @returns Encrypted data object. + * + * @throws Error if unknown data type has been passed. + */ encrypt(data: BufferSource | string): EncryptedDataType; - decrypt(data: EncryptedDataType): ArrayBuffer; + /** + * Encrypt provided source {@link Readable} stream. + * + * @param stream - Stream for encryption. + * + * @returns Encrypted stream object. + * + * @throws Error if unknown data type has been passed. + */ encryptStream(stream: NodeJS.ReadableStream): Promise; - decryptStream(encryptedStream: EncryptedStream): Promise; + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + + // region Decryption + /** + * Decrypt provided encrypted data object. + * + * @param data - Encrypted data object for decryption. + * + * @returns Decrypted data. + * + * @throws Error if unknown data type has been passed. + */ + decrypt(data: EncryptedDataType): ArrayBuffer; + + /** + * Decrypt provided encrypted stream object. + * + * @param stream - Encrypted stream object for decryption. + * + * @returns Decrypted data as {@link Readable} stream. + * + * @throws Error if unknown data type has been passed. + */ + decryptStream(stream: EncryptedStream): Promise; + // endregion } diff --git a/src/crypto/modules/NodeCryptoModule/ILegacyCryptor.ts b/src/crypto/modules/NodeCryptoModule/ILegacyCryptor.ts index 9a63aa455..8fd6ae953 100644 --- a/src/crypto/modules/NodeCryptoModule/ILegacyCryptor.ts +++ b/src/crypto/modules/NodeCryptoModule/ILegacyCryptor.ts @@ -1,26 +1,84 @@ +/** + * Legacy cryptor module. + */ + +import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; +import { PubNubFileConstructor } from '../../../core/types/file'; +import { Payload } from '../../../core/types/api'; import { EncryptedDataType } from './ICryptor'; -export type PubNubFileType = { - stream: NodeJS.ReadStream; - data: NodeJS.ReadStream | Buffer; - name: string; - mimeType: string; - contentLength: number; +/** + * Legacy cryptor algorithm interface. + */ +export interface ILegacyCryptor { + /** + * Cryptor unique identifier. + */ + get identifier(): string; + + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- - create(config: any): PubNubFileType; + // region Encryption + /** + * Encrypt provided source data. + * + * @param data - Source data for encryption. + * + * @returns Encrypted data object. + * + * @throws Error if unknown data type has been passed. + */ + encrypt(data: string): EncryptedDataType; - toBuffer(): Buffer; - toArrayBuffer(): ArrayBuffer; - toString(): string; - toStream(): NodeJS.ReadStream; -}; + /** + * Encrypt provided source {@link PubNub} File object. + * + * @param file - Source {@link PubNub} File object for encryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Encrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + * @throws Error if cipher key not set. + */ + encryptFile( + file: PubNubFile, + File: PubNubFileConstructor, + ): Promise; + // endregion -export interface ILegacyCryptor { - get identifier(): string; + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- - encrypt(data: string | ArrayBuffer): EncryptedDataType; - decrypt(data: EncryptedDataType): BufferSource | string; + // region Decryption + /** + * Decrypt provided encrypted data object. + * + * @param data - Encrypted data object for decryption. + * + * @returns Decrypted data. + * + * @throws Error if unknown data type has been passed. + */ + decrypt(data: EncryptedDataType): Payload | null; - encryptFile(file: T, File: T): Promise; - decryptFile(file: T, File: T): Promise; + /** + * Decrypt provided encrypted {@link PubNub} File object. + * + * @param file - Encrypted {@link PubNub} File object for decryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + * @throws Error if cipher key not set. + */ + decryptFile( + file: PubNubFile, + File: PubNubFileConstructor, + ): Promise; + // endregion } diff --git a/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts b/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts index 68cfb89a6..024b4e188 100644 --- a/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts +++ b/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts @@ -1,39 +1,50 @@ -import { PassThrough } from 'stream'; +/** + * AES-CBC cryptor module. + */ + import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'crypto'; +import { PassThrough } from 'stream'; + import { ICryptor, EncryptedDataType, EncryptedStream } from './ICryptor'; +/** + * AES-CBC cryptor. + * + * AES-CBC cryptor with enhanced cipher strength. + */ export default class AesCbcCryptor implements ICryptor { + /** + * Cryptor block size. + */ static BLOCK_SIZE = 16; - cipherKey: string; - constructor(configuration: { cipherKey: string }) { - this.cipherKey = configuration.cipherKey; - } + /** + * {@link string|String} to {@link ArrayBuffer} response decoder. + */ + static encoder = new TextEncoder(); - get algo() { - return 'aes-256-cbc'; - } + /** + * Data encryption / decryption cipher key. + */ + cipherKey: string; - get identifier() { - return 'ACRH'; + constructor({ cipherKey }: { cipherKey: string }) { + this.cipherKey = cipherKey; } - getIv() { - return randomBytes(AesCbcCryptor.BLOCK_SIZE); - } + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption - getKey() { - const sha = createHash('sha256'); - sha.update(Buffer.from(this.cipherKey, 'utf8')); - return Buffer.from(sha.digest()); - } - - encrypt(data: ArrayBuffer | string) { + encrypt(data: ArrayBuffer | string): EncryptedDataType { const iv = this.getIv(); const key = this.getKey(); - const plainData = typeof data === 'string' ? new TextEncoder().encode(data) : data; + const plainData = typeof data === 'string' ? AesCbcCryptor.encoder.encode(data) : data; const bPlain = Buffer.from(plainData); - if (bPlain.byteLength === 0) throw new Error('encryption error. empty content'); + + if (bPlain.byteLength === 0) throw new Error('Encryption error: empty content'); + const aes = createCipheriv(this.algo, key, iv); return { @@ -42,37 +53,53 @@ export default class AesCbcCryptor implements ICryptor { }; } - decrypt(encryptedData: EncryptedDataType) { - const data = - typeof encryptedData.data === 'string' ? new TextEncoder().encode(encryptedData.data) : encryptedData.data; - if (data.byteLength <= 0) throw new Error('decryption error: empty content'); - const aes = createDecipheriv(this.algo, this.getKey(), encryptedData.metadata); - return Uint8Array.from(Buffer.concat([aes.update(data), aes.final()])).buffer; - } - async encryptStream(stream: NodeJS.ReadableStream) { + if (!stream.readable) throw new Error('Encryption error: empty stream'); + const output = new PassThrough(); const bIv = this.getIv(); - if (stream.readable === false) throw new Error('encryption error. empty stream'); const aes = createCipheriv(this.algo, this.getKey(), bIv); stream.pipe(aes).pipe(output); + return { stream: output, metadata: bIv, metadataLength: AesCbcCryptor.BLOCK_SIZE, }; } + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + + decrypt(input: EncryptedDataType) { + const data = typeof input.data === 'string' ? new TextEncoder().encode(input.data) : input.data; + + if (data.byteLength <= 0) throw new Error('Decryption error: empty content'); + const aes = createDecipheriv(this.algo, this.getKey(), input.metadata!); + const decryptedDataBuffer = Buffer.concat([aes.update(data), aes.final()]); + + return decryptedDataBuffer.buffer.slice( + decryptedDataBuffer.byteOffset, + decryptedDataBuffer.byteOffset + decryptedDataBuffer.length, + ); + } - async decryptStream(encryptedStream: EncryptedStream) { + async decryptStream(stream: EncryptedStream) { const decryptedStream = new PassThrough(); let bIv = Buffer.alloc(0); - let aes: any = null; + let aes: ReturnType | null = null; + const onReadable = () => { - let data = encryptedStream.stream.read(); + let data = stream.stream.read(); + while (data !== null) { if (data) { const bChunk = Buffer.from(data); - const sliceLen = encryptedStream.metadataLength - bIv.byteLength; + const sliceLen = stream.metadataLength - bIv.byteLength; + if (bChunk.byteLength < sliceLen) { bIv = Buffer.concat([bIv, bChunk]); } else { @@ -82,16 +109,55 @@ export default class AesCbcCryptor implements ICryptor { aes.write(bChunk.slice(sliceLen)); } } - data = encryptedStream.stream.read(); + data = stream.stream.read(); } }; - encryptedStream.stream.on('readable', onReadable); - encryptedStream.stream.on('end', () => { - if (aes) { - aes.end(); - } + stream.stream.on('readable', onReadable); + stream.stream.on('end', () => { + if (aes) aes.end(); decryptedStream.end(); }); + return decryptedStream; } + // endregion + + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + + get identifier() { + return 'ACRH'; + } + + /** + * Cryptor algorithm. + * + * @returns Cryptor module algorithm. + */ + private get algo() { + return 'aes-256-cbc'; + } + + /** + * Generate random initialization vector. + * + * @returns Random initialization vector. + */ + private getIv() { + return randomBytes(AesCbcCryptor.BLOCK_SIZE); + } + + /** + * Convert cipher key to the {@link Buffer}. + * + * @returns SHA256 encoded cipher key {@link Buffer}. + */ + private getKey() { + const sha = createHash('sha256'); + sha.update(Buffer.from(this.cipherKey, 'utf8')); + return Buffer.from(sha.digest()); + } + // endregion } diff --git a/src/crypto/modules/NodeCryptoModule/legacyCryptor.ts b/src/crypto/modules/NodeCryptoModule/legacyCryptor.ts index c8a28fc6b..4aa44e4e4 100644 --- a/src/crypto/modules/NodeCryptoModule/legacyCryptor.ts +++ b/src/crypto/modules/NodeCryptoModule/legacyCryptor.ts @@ -1,41 +1,88 @@ +/** + * Legacy cryptor module. + */ + +import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; +import { CryptorConfiguration } from '../../../core/interfaces/crypto-module'; import Crypto from '../../../core/components/cryptography/index'; +import { PubNubFileConstructor } from '../../../core/types/file'; import { encode } from '../../../core/components/base64_codec'; -import FileCryptor from '../node'; +import { PubNubError } from '../../../errors/pubnub-error'; +import { ILegacyCryptor } from './ILegacyCryptor'; import { EncryptedDataType } from './ICryptor'; -import { ILegacyCryptor, PubNubFileType } from './ILegacyCryptor'; +import FileCryptor from '../node'; -export default class LegacyCryptor implements ILegacyCryptor { +/** + * Legacy cryptor. + */ +export default class LegacyCryptor implements ILegacyCryptor { + /** + * Legacy cryptor configuration. + */ config; - cryptor; + /** + * Configured file cryptor. + */ fileCryptor; - constructor(config: any) { + /** + * Configured legacy cryptor. + */ + cryptor; + + constructor(config: CryptorConfiguration) { this.config = config; - this.cryptor = new Crypto({ config }); + this.cryptor = new Crypto({ ...config }); this.fileCryptor = new FileCryptor(); } - get identifier() { - return ''; - } - encrypt(data: string) { - if (data.length === 0) throw new Error('encryption error. empty content'); + + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption + + encrypt(data: string): EncryptedDataType { + if (data.length === 0) throw new Error('Encryption error: empty content'); + return { data: this.cryptor.encrypt(data), metadata: null, }; } + async encryptFile(file: PubNubFile, File: PubNubFileConstructor) { + if (!this.config.cipherKey) throw new PubNubError('File encryption error: cipher key not set.'); + + return this.fileCryptor.encryptFile(this.config.cipherKey, file, File); + } + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + decrypt(encryptedData: EncryptedDataType) { const data = typeof encryptedData.data === 'string' ? encryptedData.data : encode(encryptedData.data); + return this.cryptor.decrypt(data); } - async encryptFile(file: PubNubFileType, File: PubNubFileType) { - return this.fileCryptor.encryptFile(this.config.cipherKey, file, File); - } + async decryptFile(file: PubNubFile, File: PubNubFileConstructor) { + if (!this.config.cipherKey) throw new PubNubError('File decryption error: cipher key not set.'); - async decryptFile(file: PubNubFileType, File: PubNubFileType) { return this.fileCryptor.decryptFile(this.config.cipherKey, file, File); } + // endregion + + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + + get identifier() { + return ''; + } + // endregion } diff --git a/src/crypto/modules/NodeCryptoModule/nodeCryptoModule.ts b/src/crypto/modules/NodeCryptoModule/nodeCryptoModule.ts index a1d218946..a98176b5d 100644 --- a/src/crypto/modules/NodeCryptoModule/nodeCryptoModule.ts +++ b/src/crypto/modules/NodeCryptoModule/nodeCryptoModule.ts @@ -1,123 +1,147 @@ +/** + * Node.js crypto module. + */ + import { Readable, PassThrough } from 'stream'; +import { Buffer } from 'buffer'; + +import { AbstractCryptoModule, CryptorConfiguration } from '../../../core/interfaces/crypto-module'; +import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; +import { PubNubFileConstructor } from '../../../core/types/file'; import { decode } from '../../../core/components/base64_codec'; -import LegacyCryptor from './legacyCryptor'; +import { PubNubError } from '../../../errors/pubnub-error'; +import { EncryptedDataType, ICryptor } from './ICryptor'; +import { ILegacyCryptor } from './ILegacyCryptor'; import AesCbcCryptor from './aesCbcCryptor'; -import { ICryptor } from './ICryptor'; -import { ILegacyCryptor, PubNubFileType } from './ILegacyCryptor'; +import LegacyCryptor from './legacyCryptor'; +/** + * Re-export bundled cryptors. + */ export { LegacyCryptor, AesCbcCryptor }; -type CryptorType = ICryptor | ILegacyCryptor; - -type CryptoModuleConfiguration = { - default: CryptorType; - cryptors?: Array; -}; - -export class CryptoModule { +/** + * Crypto module cryptors interface. + */ +type CryptorType = ICryptor | ILegacyCryptor; + +/** + * CryptoModule for Node.js platform. + */ +export class CryptoModule extends AbstractCryptoModule { + /** + * {@link LegacyCryptor|Legacy} cryptor identifier. + */ static LEGACY_IDENTIFIER = ''; - defaultCryptor: CryptorType; - cryptors: Array; + // -------------------------------------------------------- + // --------------- Convenience functions ------------------ + // ------------------------------------------------------- + // region Convenience functions - constructor(cryptoModuleConfiguration: CryptoModuleConfiguration) { - this.defaultCryptor = cryptoModuleConfiguration.default; - this.cryptors = cryptoModuleConfiguration.cryptors ?? []; - } + static legacyCryptoModule(config: CryptorConfiguration) { + if (!config.cipherKey) throw new PubNubError('Crypto module error: cipher key not set.'); - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore: type detection issue with old Config type assignment - static legacyCryptoModule(config) { return new this({ default: new LegacyCryptor({ - cipherKey: config.cipherKey, + ...config, useRandomIVs: config.useRandomIVs ?? true, }), cryptors: [new AesCbcCryptor({ cipherKey: config.cipherKey })], }); } - static aesCbcCryptoModule(config: any) { + static aesCbcCryptoModule(config: CryptorConfiguration) { + if (!config.cipherKey) throw new PubNubError('Crypto module error: cipher key not set.'); + return new this({ default: new AesCbcCryptor({ cipherKey: config.cipherKey }), cryptors: [ new LegacyCryptor({ - cipherKey: config.cipherKey, + ...config, useRandomIVs: config.useRandomIVs ?? true, }), ], }); } + + /** + * Construct crypto module with `cryptor` as default for data encryption and decryption. + * + * @param defaultCryptor - Default cryptor for data encryption and decryption. + * + * @returns Crypto module with pre-configured default cryptor. + */ static withDefaultCryptor(defaultCryptor: CryptorType) { return new this({ default: defaultCryptor }); } + // endregion - private getAllCryptors() { - return [this.defaultCryptor, ...this.cryptors]; - } - - private getLegacyCryptor() { - return this.getAllCryptors().find((c) => c.identifier === ''); - } + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption encrypt(data: ArrayBuffer | string) { - const encrypted = this.defaultCryptor.encrypt(data); + // Encrypt data. + const encrypted = + data instanceof ArrayBuffer && this.defaultCryptor.identifier === CryptoModule.LEGACY_IDENTIFIER + ? (this.defaultCryptor as ILegacyCryptor).encrypt(CryptoModule.decoder.decode(data)) + : (this.defaultCryptor as ICryptor).encrypt(data); + if (!encrypted.metadata) return encrypted.data; - const header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); + const headerData = this.getHeaderData(encrypted)!; - const headerData = new Uint8Array(header!.length); - let pos = 0; - headerData.set(header!.data, pos); - pos = header!.length - encrypted.metadata.length; - headerData.set(encrypted.metadata, pos); - return Buffer.concat([headerData, Buffer.from(encrypted.data)]); - } + // Write encrypted data payload content. + const encryptedData = + typeof encrypted.data === 'string' + ? CryptoModule.encoder.encode(encrypted.data).buffer + : encrypted.data.buffer.slice(encrypted.data.byteOffset, encrypted.data.byteOffset + encrypted.data.length); - decrypt(data: ArrayBuffer | string) { - const encryptedData = Buffer.from(typeof data === 'string' ? decode(data) : data); - const header = CryptorHeader.tryParse(encryptedData); - const cryptor = this.getCryptor(header); - const metadata = - header.length > 0 - ? encryptedData.slice(header.length - (header as CryptorHeaderV1).metadataLength, header.length) - : null; - if (encryptedData.slice(header.length).byteLength <= 0) throw new Error('decryption error. empty content'); - return cryptor!.decrypt({ - data: encryptedData.slice(header.length), - metadata: metadata, - }); + return this.concatArrayBuffer(headerData, encryptedData); } - async encryptFile(file: PubNubFileType, File: PubNubFileType) { + async encryptFile(file: PubNubFile, File: PubNubFileConstructor) { /** * Files handled differently in case of Legacy cryptor. - * (as long as we support legacy need to check on intsance type) + * (as long as we support legacy need to check on instance type) */ if (this.defaultCryptor.identifier === CryptorHeader.LEGACY_IDENTIFIER) - return (this.defaultCryptor as ILegacyCryptor).encryptFile(file, File); + return (this.defaultCryptor as ILegacyCryptor).encryptFile(file, File); + if (file.data instanceof Buffer) { + const encryptedData = this.encrypt(file.data); + return File.create({ name: file.name, mimeType: 'application/octet-stream', - data: Buffer.from(this.encrypt(file.data!) as Buffer), + data: Buffer.from( + typeof encryptedData === 'string' ? CryptoModule.encoder.encode(encryptedData) : encryptedData, + ), }); } + if (file.data instanceof Readable) { - if (file.contentLength === 0) throw new Error('encryption error. empty content'); + if (!file.contentLength || file.contentLength === 0) throw new Error('Encryption error: empty content'); + const encryptedStream = await (this.defaultCryptor as ICryptor).encryptStream(file.data); const header = CryptorHeader.from(this.defaultCryptor.identifier, encryptedStream.metadata!); const payload = new Uint8Array(header!.length); let pos = 0; payload.set(header!.data, pos); pos += header!.length; + if (encryptedStream.metadata) { - pos -= encryptedStream.metadata.length; - payload.set(encryptedStream.metadata, pos); + const metadata = new Uint8Array(encryptedStream.metadata); + pos -= encryptedStream.metadata.byteLength; + payload.set(metadata, pos); } + const output = new PassThrough(); output.write(payload); encryptedStream.stream.pipe(output); + return File.create({ name: file.name, mimeType: 'application/octet-stream', @@ -125,172 +149,307 @@ export class CryptoModule { }); } } + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption - async decryptFile(file: PubNubFileType, File: PubNubFileType) { - if (file?.data instanceof Buffer) { - const header = CryptorHeader.tryParse(file.data); + decrypt(data: ArrayBuffer | string) { + const encryptedData = Buffer.from(typeof data === 'string' ? decode(data) : data); + const header = CryptorHeader.tryParse( + encryptedData.buffer.slice(encryptedData.byteOffset, encryptedData.byteOffset + encryptedData.length), + ); + const cryptor = this.getCryptor(header); + const metadata = + header.length > 0 + ? encryptedData.slice(header.length - (header as CryptorHeaderV1).metadataLength, header.length) + : null; + + if (encryptedData.slice(header.length).byteLength <= 0) throw new Error('Decryption error: empty content'); + + return cryptor!.decrypt({ + data: encryptedData.slice(header.length), + metadata: metadata, + }); + } + + async decryptFile( + file: PubNubFile, + File: PubNubFileConstructor, + ): Promise { + if (file.data && file.data instanceof Buffer) { + const header = CryptorHeader.tryParse( + file.data.buffer.slice(file.data.byteOffset, file.data.byteOffset + file.data.length), + ); const cryptor = this.getCryptor(header); /** - * If It's legacyone then redirect it. + * If It's legacy one then redirect it. * (as long as we support legacy need to check on instance type) */ if (cryptor?.identifier === CryptoModule.LEGACY_IDENTIFIER) - return (cryptor as ILegacyCryptor).decryptFile(file, File); + return (cryptor as ILegacyCryptor).decryptFile(file, File); + return File.create({ name: file.name, - data: Buffer.from(this.decrypt(file?.data) as ArrayBuffer), + data: Buffer.from(this.decrypt(file.data) as ArrayBuffer), }); } - if (file.data instanceof Readable) { + if (file.data && file.data instanceof Readable) { const stream = file.data; return new Promise((resolve) => { stream.on('readable', () => resolve(this.onStreamReadable(stream, file, File))); }); } } + // endregion + + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + + /** + * Retrieve registered legacy cryptor. + * + * @returns Previously registered {@link ILegacyCryptor|legacy} cryptor. + * + * @throws Error if legacy cryptor not registered. + */ + private getLegacyCryptor(): ILegacyCryptor | undefined { + return this.getCryptorFromId(CryptoModule.LEGACY_IDENTIFIER) as ILegacyCryptor; + } + + /** + * Retrieve registered cryptor by its identifier. + * + * @param id - Unique cryptor identifier. + * + * @returns Registered cryptor with specified identifier. + * + * @throws Error if cryptor with specified {@link id} can't be found. + */ + private getCryptorFromId(id: string) { + const cryptor = this.getAllCryptors().find((cryptor) => id === cryptor.identifier); + if (cryptor) return cryptor; + + throw new Error('Unknown cryptor error'); + } + + /** + * Retrieve cryptor by its identifier. + * + * @param header - Header with cryptor-defined data or raw cryptor identifier. + * + * @returns Cryptor which correspond to provided {@link header}. + */ + private getCryptor(header: CryptorHeader | string) { + if (typeof header === 'string') { + const cryptor = this.getAllCryptors().find((c) => c.identifier === header); + if (cryptor) return cryptor; + + throw new Error('Unknown cryptor error'); + } else if (header instanceof CryptorHeaderV1) { + return this.getCryptorFromId(header.identifier); + } + } + + /** + * Create cryptor header data. + * + * @param encrypted - Encryption data object as source for header data. + * + * @returns Binary representation of the cryptor header data. + */ + private getHeaderData(encrypted: EncryptedDataType) { + if (!encrypted.metadata) return; + const header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); + const headerData = new Uint8Array(header!.length); + let pos = 0; + headerData.set(header!.data, pos); + pos += header!.length - encrypted.metadata.byteLength; + headerData.set(new Uint8Array(encrypted.metadata), pos); - private async onStreamReadable(stream: NodeJS.ReadableStream, file: PubNubFileType, File: PubNubFileType) { + return headerData.buffer; + } + + /** + * Merge two {@link ArrayBuffer} instances. + * + * @param ab1 - First {@link ArrayBuffer}. + * @param ab2 - Second {@link ArrayBuffer}. + * + * @returns Merged data as {@link ArrayBuffer}. + */ + private concatArrayBuffer(ab1: ArrayBuffer, ab2: ArrayBuffer): ArrayBuffer { + const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); + + tmp.set(new Uint8Array(ab1), 0); + tmp.set(new Uint8Array(ab2), ab1.byteLength); + + return tmp.buffer; + } + + /** + * {@link Readable} stream event handler. + * + * @param stream - Stream which can be used to read data for decryption. + * @param file - File object which has been created with {@link stream}. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + private async onStreamReadable( + stream: NodeJS.ReadableStream, + file: PubNubFile, + File: PubNubFileConstructor, + ) { stream.removeAllListeners('readable'); const magicBytes = stream.read(4); + if (!CryptorHeader.isSentinel(magicBytes as Buffer)) { - if (magicBytes === null) throw new Error('decryption error. empty content'); + if (magicBytes === null) throw new Error('Decryption error: empty content'); stream.unshift(magicBytes); + return this.decryptLegacyFileStream(stream, file, File); } + const versionByte = stream.read(1); CryptorHeader.validateVersion(versionByte[0] as number); const identifier = stream.read(4); const cryptor = this.getCryptorFromId(CryptorHeader.tryGetIdentifier(identifier as Buffer)); const headerSize = CryptorHeader.tryGetMetadataSizeFromStream(stream); - if (file.contentLength <= CryptorHeader.MIN_HEADER_LEGTH + headerSize) - throw new Error('decryption error. empty content'); + + if (!file.contentLength || file.contentLength <= CryptorHeader.MIN_HEADER_LENGTH + headerSize) + throw new Error('Decryption error: empty content'); + return File.create({ name: file.name, mimeType: 'application/octet-stream', - stream: await (cryptor as ICryptor).decryptStream({ stream: stream, metadataLength: headerSize as number }), + stream: (await (cryptor as ICryptor).decryptStream({ + stream: stream, + metadataLength: headerSize as number, + })) as Readable, }); } - private async decryptLegacyFileStream(stream: NodeJS.ReadableStream, file: PubNubFileType, File: PubNubFileType) { - if (file.contentLength <= 16) throw new Error('decryption error: empty content'); + /** + * Decrypt {@link Readable} stream using legacy cryptor. + * + * @param stream - Stream which can be used to read data for decryption. + * @param file - File object which has been created with {@link stream}. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + private async decryptLegacyFileStream( + stream: NodeJS.ReadableStream, + file: PubNubFile, + File: PubNubFileConstructor, + ) { + if (!file.contentLength || file.contentLength <= 16) throw new Error('Decryption error: empty content'); + const cryptor = this.getLegacyCryptor(); + if (cryptor) { - return (cryptor as ILegacyCryptor).decryptFile( + return cryptor.decryptFile( File.create({ name: file.name, - stream: stream, + stream: stream as Readable, }), File, ); - } else { - throw new Error('unknown cryptor error'); - } - } - - private getCryptor(header: CryptorHeader) { - if (header === '') { - const cryptor = this.getAllCryptors().find((c) => c.identifier === ''); - if (cryptor) return cryptor; - throw new Error('unknown cryptor error'); - } else if (header instanceof CryptorHeaderV1) { - return this.getCryptorFromId(header.identifier); - } - } - - private getCryptorFromId(id: string) { - const cryptor = this.getAllCryptors().find((c) => id === c.identifier); - if (cryptor) { - return cryptor; - } - throw new Error('unknown cryptor error'); + } else throw new Error('unknown cryptor error'); } + // endregion } -// CryptorHeader Utility +/** + * CryptorHeader Utility + */ class CryptorHeader { + static decoder = new TextDecoder(); static SENTINEL = 'PNED'; static LEGACY_IDENTIFIER = ''; static IDENTIFIER_LENGTH = 4; static VERSION = 1; static MAX_VERSION = 1; - static MIN_HEADER_LEGTH = 10; + static MIN_HEADER_LENGTH = 10; - static from(id: string, metadata: Buffer) { + static from(id: string, metadata: ArrayBuffer) { if (id === CryptorHeader.LEGACY_IDENTIFIER) return; - return new CryptorHeaderV1(id, metadata.length); + return new CryptorHeaderV1(id, metadata.byteLength); } - static isSentinel(bytes: Buffer) { - if (bytes && bytes.byteLength >= 4) { - if (bytes.toString('utf8') == CryptorHeader.SENTINEL) return true; - } + static isSentinel(bytes: ArrayBuffer) { + return bytes && bytes.byteLength >= 4 && CryptorHeader.decoder.decode(bytes) == CryptorHeader.SENTINEL; } static validateVersion(data: number) { - if (data && data > CryptorHeader.MAX_VERSION) throw new Error('decryption error. invalid header version'); + if (data && data > CryptorHeader.MAX_VERSION) throw new Error('Decryption error: invalid header version'); return data; } - static tryGetIdentifier(data: Buffer) { - if (data.byteLength < 4) { - throw new Error('unknown cryptor error. decryption failed'); - } else { - return data.toString('utf8'); - } + static tryGetIdentifier(data: ArrayBuffer) { + if (data.byteLength < 4) throw new Error('Decryption error: unknown cryptor error'); + else return CryptorHeader.decoder.decode(data); } static tryGetMetadataSizeFromStream(stream: NodeJS.ReadableStream) { const sizeBuf = stream.read(1); - if (sizeBuf && (sizeBuf[0] as number) < 255) { - return sizeBuf[0] as number; - } + + if (sizeBuf && (sizeBuf[0] as number) < 255) return sizeBuf[0] as number; if ((sizeBuf[0] as number) === 255) { const nextBuf = stream.read(2); + if (nextBuf.length >= 2) { return new Uint16Array([nextBuf[0] as number, nextBuf[1] as number]).reduce((acc, val) => (acc << 8) + val, 0); } } - throw new Error('decryption error. Invalid metadata size'); + + throw new Error('Decryption error: invalid metadata size'); } - static tryParse(encryptedData: Buffer) { - let sentinel: any = ''; + + static tryParse(encryptedData: ArrayBuffer) { + const encryptedDataView = new DataView(encryptedData); + let sentinel: ArrayBuffer; let version = null; - if (encryptedData.length >= 4) { + if (encryptedData.byteLength >= 4) { sentinel = encryptedData.slice(0, 4); - if (sentinel.toString('utf8') !== CryptorHeader.SENTINEL) return ''; + if (!this.isSentinel(sentinel)) return CryptoModule.LEGACY_IDENTIFIER; } - if (encryptedData.length >= 5) { - version = encryptedData[4]; - } else { - throw new Error('decryption error. invalid header version'); - } + if (encryptedData.byteLength >= 5) version = encryptedDataView.getInt8(4); + else throw new Error('Decryption error: invalid header version'); if (version > CryptorHeader.MAX_VERSION) throw new Error('unknown cryptor error'); - let identifier: Buffer; + let identifier: ArrayBuffer; let pos = 5 + CryptorHeader.IDENTIFIER_LENGTH; - if (encryptedData.length >= pos) { - identifier = encryptedData.slice(5, pos); - } else { - throw new Error('decryption error. invalid crypto identifier'); - } + if (encryptedData.byteLength >= pos) identifier = encryptedData.slice(5, pos); + else throw new Error('Decryption error: invalid crypto identifier'); + let metadataLength = null; - if (encryptedData.length >= pos + 1) { - metadataLength = encryptedData[pos]; - } else { - throw new Error('decryption error. invalid metadata length'); - } + if (encryptedData.byteLength >= pos + 1) metadataLength = encryptedDataView.getInt8(pos); + else throw new Error('Decryption error: invalid metadata length'); + pos += 1; - if (metadataLength === 255 && encryptedData.length >= pos + 2) { + if (metadataLength === 255 && encryptedData.byteLength >= pos + 2) { metadataLength = new Uint16Array(encryptedData.slice(pos, pos + 2)).reduce((acc, val) => (acc << 8) + val, 0); - pos += 2; } - return new CryptorHeaderV1(identifier.toString('utf8'), metadataLength); + + return new CryptorHeaderV1(CryptorHeader.decoder.decode(identifier), metadataLength); } } -// v1 CryptorHeader +/** + * Cryptor header (v1). + */ class CryptorHeaderV1 { _identifier; _metadataLength; @@ -337,14 +496,15 @@ class CryptorHeaderV1 { pos += CryptorHeader.SENTINEL.length; header[pos] = this.version; pos++; + if (this.identifier) header.set(Buffer.from(this.identifier), pos); - pos += CryptorHeader.IDENTIFIER_LENGTH; + const metadataLength = this.metadataLength; - if (metadataLength < 255) { - header[pos] = metadataLength; - } else { - header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); - } + pos += CryptorHeader.IDENTIFIER_LENGTH; + + if (metadataLength < 255) header[pos] = metadataLength; + else header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); + return header; } } diff --git a/src/crypto/modules/WebCryptoModule/ICryptor.ts b/src/crypto/modules/WebCryptoModule/ICryptor.ts index b15709c75..aa6080ce9 100644 --- a/src/crypto/modules/WebCryptoModule/ICryptor.ts +++ b/src/crypto/modules/WebCryptoModule/ICryptor.ts @@ -1,13 +1,86 @@ +/** + * Cryptor module. + */ + +/** + * Data encrypted by {@link CryptoModule}. + */ export type EncryptedDataType = { - data: ArrayBuffer; + /** + * Encrypted data. + */ + data: ArrayBuffer | string; + + /** + * Used cryptor's metadata. + */ metadata: ArrayBuffer | null; }; +/** + * Cryptor algorithm interface. + */ export interface ICryptor { + /** + * Cryptor unique identifier. + * + * @returns Cryptor identifier. + */ get identifier(): string; + + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + + // region Encryption + /** + * Encrypt provided source data. + * + * @param data - Source data for encryption. + * + * @returns Encrypted data object. + * + * @throws Error if unknown data type has been passed. + */ encrypt(data: ArrayBuffer | string): EncryptedDataType; - decrypt(data: EncryptedDataType): ArrayBuffer; + /** + * Encrypt provided source {@link ArrayBuffer}. + * + * @param data - Source {@link ArrayBuffer} for encryption. + * + * @returns Encrypted data object. + * + * @throws Error if unknown data type has been passed. + */ encryptFileData(data: ArrayBuffer): Promise; - decryptFileData(data: EncryptedDataType): Promise; + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + + // region Decryption + /** + * Decrypt provided encrypted data object. + * + * @param data - Encrypted data object for decryption. + * + * @returns Decrypted data. + * + * @throws Error if unknown data type has been passed. + */ + decrypt(data: EncryptedDataType): ArrayBuffer; + + /** + * Decrypt provided encrypted {@link ArrayBuffer} File object. + * + * @param file - Encrypted {@link ArrayBuffer} for decryption. + * + * @returns Decrypted data as {@link ArrayBuffer}. + * + * @throws Error if unknown data type has been passed. + */ + decryptFileData(file: EncryptedDataType): Promise; + // endregion } diff --git a/src/crypto/modules/WebCryptoModule/ILegacyCryptor.ts b/src/crypto/modules/WebCryptoModule/ILegacyCryptor.ts index c9ae022c0..a0afa95e5 100644 --- a/src/crypto/modules/WebCryptoModule/ILegacyCryptor.ts +++ b/src/crypto/modules/WebCryptoModule/ILegacyCryptor.ts @@ -1,24 +1,86 @@ +/** + * Legacy cryptor module. + */ + +import { PubNubFile, PubNubFileParameters } from '../../../file/modules/web'; +import { PubNubFileConstructor } from '../../../core/types/file'; +import { Payload } from '../../../core/types/api'; import { EncryptedDataType } from './ICryptor'; -export type PubNubFileType = { - data: File | Blob; - name: string; - mimeType: string; +/** + * Legacy cryptor algorithm interface. + */ +export interface ILegacyCryptor { + /** + * Cryptor unique identifier. + * + * @returns Cryptor identifier. + */ + get identifier(): string; + + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- - create(config: any): PubNubFileType; + // region Encryption + /** + * Encrypt provided source data. + * + * @param data - Source data for encryption. + * + * @returns Encrypted data object. + * + * @throws Error if unknown data type has been passed. + */ + encrypt(data: ArrayBuffer | string): EncryptedDataType; - toArrayBuffer(): ArrayBuffer; - toBlob(): Blob; - toString(): string; - toFile(): File; -}; + /** + * Encrypt provided source {@link PubNub} File object. + * + * @param file - Source {@link PubNub} File object for encryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Encrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + * @throws Error if cipher key not set. + */ + encryptFile( + file: PubNubFile, + File: PubNubFileConstructor, + ): Promise; + // endregion -export interface ILegacyCryptor { - get identifier(): string; + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- - encrypt(data: ArrayBuffer | string): EncryptedDataType; - decrypt(data: EncryptedDataType): ArrayBuffer | string; + // region Decryption + /** + * Decrypt provided encrypted data object. + * + * @param data - Encrypted data object for decryption. + * + * @returns Decrypted data. + * + * @throws Error if unknown data type has been passed. + */ + decrypt(data: EncryptedDataType): Payload | null; - encryptFile(file: T, File: T): Promise; - decryptFile(file: T, File: T): Promise; + /** + * Decrypt provided encrypted {@link PubNub} File object. + * + * @param file - Encrypted {@link PubNub} File object for decryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + * @throws Error if cipher key not set. + */ + decryptFile( + file: PubNubFile, + File: PubNubFileConstructor, + ): Promise; + // endregion } diff --git a/src/crypto/modules/WebCryptoModule/aesCbcCryptor.ts b/src/crypto/modules/WebCryptoModule/aesCbcCryptor.ts index 78bda2175..6aed65a1b 100644 --- a/src/crypto/modules/WebCryptoModule/aesCbcCryptor.ts +++ b/src/crypto/modules/WebCryptoModule/aesCbcCryptor.ts @@ -1,44 +1,58 @@ -import { ICryptor, EncryptedDataType } from './ICryptor'; +/** + * AES-CBC cryptor module. + */ + import cryptoJS from '../../../core/components/cryptography/hmac-sha256'; import { decode } from '../../../core/components/base64_codec'; +import { ICryptor, EncryptedDataType } from './ICryptor'; +/** + * AES-CBC cryptor. + * + * AES-CBC cryptor with enhanced cipher strength. + */ export default class AesCbcCryptor implements ICryptor { + /** + * Cryptor block size. + */ static BLOCK_SIZE = 16; + + /** + * {@link string|String} to {@link ArrayBuffer} response decoder. + */ static encoder = new TextEncoder(); + + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ static decoder = new TextDecoder(); + /** + * Data encryption / decryption cipher key. + */ cipherKey: string; + + /* eslint-disable @typescript-eslint/no-explicit-any */ encryptedKey: any; + /* eslint-disable @typescript-eslint/no-explicit-any */ CryptoJS: any; - constructor(configuration: { cipherKey: string }) { - this.cipherKey = configuration.cipherKey; + constructor({ cipherKey }: { cipherKey: string }) { + this.cipherKey = cipherKey; this.CryptoJS = cryptoJS; - this.encryptedKey = this.CryptoJS.SHA256(this.cipherKey); + this.encryptedKey = this.CryptoJS.SHA256(cipherKey); } - get algo() { - return 'AES-CBC'; - } + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption - get identifier() { - return 'ACRH'; - } - - private getIv() { - return crypto.getRandomValues(new Uint8Array(AesCbcCryptor.BLOCK_SIZE)); - } - - private async getKey() { - const bKey = AesCbcCryptor.encoder.encode(this.cipherKey); - const abHash = await crypto.subtle.digest('SHA-256', bKey.buffer); - return crypto.subtle.importKey('raw', abHash, this.algo, true, ['encrypt', 'decrypt']); - } - - encrypt(data: ArrayBuffer | string) { + encrypt(data: ArrayBuffer | string): EncryptedDataType { const stringData = typeof data === 'string' ? data : AesCbcCryptor.decoder.decode(data); if (stringData.length === 0) throw new Error('encryption error. empty content'); const abIv = this.getIv(); + return { metadata: abIv, data: decode( @@ -50,9 +64,28 @@ export default class AesCbcCryptor implements ICryptor { }; } + async encryptFileData(data: ArrayBuffer): Promise { + const key = await this.getKey(); + const iv = this.getIv(); + return { + data: await crypto.subtle.encrypt({ name: this.algo, iv: iv }, key, data), + metadata: iv, + }; + } + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + decrypt(encryptedData: EncryptedDataType) { + if (typeof encryptedData.data === 'string') + throw new Error('Decryption error: data for decryption should be ArrayBuffed.'); + const iv = this.bufferToWordArray(new Uint8ClampedArray(encryptedData.metadata!)); const data = this.bufferToWordArray(new Uint8ClampedArray(encryptedData.data)); + return AesCbcCryptor.encoder.encode( this.CryptoJS.AES.decrypt({ ciphertext: data }, this.encryptedKey, { iv, @@ -61,26 +94,69 @@ export default class AesCbcCryptor implements ICryptor { ).buffer; } - async encryptFileData(data: ArrayBuffer): Promise { - const key = await this.getKey(); - const iv = this.getIv(); - return { - data: await crypto.subtle.encrypt({ name: this.algo, iv: iv }, key, data), - metadata: iv, - }; - } - async decryptFileData(encryptedData: EncryptedDataType): Promise { + if (typeof encryptedData.data === 'string') + throw new Error('Decryption error: data for decryption should be ArrayBuffed.'); + const key = await this.getKey(); return crypto.subtle.decrypt({ name: this.algo, iv: encryptedData.metadata! }, key, encryptedData.data); } + // endregion + + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + + get identifier() { + return 'ACRH'; + } - private bufferToWordArray(b: any) { - const wa: any[] = []; + /** + * Cryptor algorithm. + * + * @returns Cryptor module algorithm. + */ + private get algo() { + return 'AES-CBC'; + } + + /** + * Generate random initialization vector. + * + * @returns Random initialization vector. + */ + + private getIv() { + return crypto.getRandomValues(new Uint8Array(AesCbcCryptor.BLOCK_SIZE)); + } + + /** + * Convert cipher key to the {@link Buffer}. + * + * @returns SHA256 encoded cipher key {@link Buffer}. + */ + private async getKey() { + const bKey = AesCbcCryptor.encoder.encode(this.cipherKey); + const abHash = await crypto.subtle.digest('SHA-256', bKey.buffer); + return crypto.subtle.importKey('raw', abHash, this.algo, true, ['encrypt', 'decrypt']); + } + + /** + * Convert bytes array to words array. + * + * @param b - Bytes array (buffer) which should be converted. + * + * @returns Word sized array. + */ + private bufferToWordArray(b: string | any[] | Uint8Array | Uint8ClampedArray) { + const wa: number[] = []; let i; + for (i = 0; i < b.length; i += 1) { wa[(i / 4) | 0] |= b[i] << (24 - 8 * i); } + return this.CryptoJS.lib.WordArray.create(wa, b.length); } } diff --git a/src/crypto/modules/WebCryptoModule/legacyCryptor.ts b/src/crypto/modules/WebCryptoModule/legacyCryptor.ts index db4b96bed..3f0a07704 100644 --- a/src/crypto/modules/WebCryptoModule/legacyCryptor.ts +++ b/src/crypto/modules/WebCryptoModule/legacyCryptor.ts @@ -1,46 +1,98 @@ +/** + * Legacy cryptor module. + */ + +import { CryptorConfiguration } from '../../../core/interfaces/crypto-module'; +import { PubNubFile, PubNubFileParameters } from '../../../file/modules/web'; import Crypto from '../../../core/components/cryptography/index'; -import FileCryptor from '../web'; -import { EncryptedDataType } from './ICryptor'; -import { ILegacyCryptor, PubNubFileType } from './ILegacyCryptor'; +import { PubNubFileConstructor } from '../../../core/types/file'; import { encode } from '../../../core/components/base64_codec'; +import { PubNubError } from '../../../errors/pubnub-error'; +import { ILegacyCryptor } from './ILegacyCryptor'; +import { EncryptedDataType } from './ICryptor'; +import FileCryptor from '../web'; + +/** + * Legacy cryptor. + */ +export default class LegacyCryptor implements ILegacyCryptor { + /** + * `string` to {@link ArrayBuffer} response decoder. + */ + static encoder = new TextEncoder(); + + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + static decoder = new TextDecoder(); -export default class LegacyCryptor implements ILegacyCryptor { + /** + * Legacy cryptor configuration. + */ config; - cryptor; + /** + * Configured file cryptor. + */ fileCryptor; - constructor(config: any) { + /** + * Configured legacy cryptor. + */ + cryptor; + + constructor(config: CryptorConfiguration) { this.config = config; - this.cryptor = new Crypto({ config }); + this.cryptor = new Crypto({ ...config }); this.fileCryptor = new FileCryptor(); } - get identifier() { - return ''; - } + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption + encrypt(data: ArrayBuffer | string) { - const stringData = typeof data === 'string' ? data : new TextDecoder().decode(data); + const stringData = typeof data === 'string' ? data : LegacyCryptor.decoder.decode(data); + return { data: this.cryptor.encrypt(stringData), metadata: null, }; } + async encryptFile(file: PubNubFile, File: PubNubFileConstructor) { + if (!this.config.cipherKey) throw new PubNubError('File encryption error: cipher key not set.'); + + return this.fileCryptor.encryptFile(this.config?.cipherKey, file, File); + } + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + decrypt(encryptedData: EncryptedDataType) { const data = typeof encryptedData.data === 'string' ? encryptedData.data : encode(encryptedData.data); + return this.cryptor.decrypt(data); } - async encryptFile(file: PubNubFileType, File: PubNubFileType) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore: can not detect cipherKey from old Config - return this.fileCryptor.encryptFile(this.config?.cipherKey, file, File); - } + async decryptFile(file: PubNubFile, File: PubNubFileConstructor) { + if (!this.config.cipherKey) throw new PubNubError('File encryption error: cipher key not set.'); - async decryptFile(file: PubNubFileType, File: PubNubFileType) { - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore: can not detect cipherKey from old Config return this.fileCryptor.decryptFile(this.config.cipherKey, file, File); } + // endregion + + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + + get identifier() { + return ''; + } + // endregion } diff --git a/src/crypto/modules/WebCryptoModule/webCryptoModule.ts b/src/crypto/modules/WebCryptoModule/webCryptoModule.ts index 5b5217dad..b58b615c2 100644 --- a/src/crypto/modules/WebCryptoModule/webCryptoModule.ts +++ b/src/crypto/modules/WebCryptoModule/webCryptoModule.ts @@ -1,69 +1,125 @@ -import LegacyCryptor from './legacyCryptor'; -import AesCbcCryptor from './aesCbcCryptor'; -import { EncryptedDataType, ICryptor } from './ICryptor'; -import { ILegacyCryptor, PubNubFileType } from './ILegacyCryptor'; +/** + * Browser crypto module. + */ + +import { AbstractCryptoModule, CryptorConfiguration } from '../../../core/interfaces/crypto-module'; +import { PubNubFile, PubNubFileParameters } from '../../../file/modules/web'; +import { PubNubFileConstructor } from '../../../core/types/file'; import { decode } from '../../../core/components/base64_codec'; +import { PubNubError } from '../../../errors/pubnub-error'; +import { EncryptedDataType, ICryptor } from './ICryptor'; +import { ILegacyCryptor } from './ILegacyCryptor'; +import AesCbcCryptor from './aesCbcCryptor'; +import LegacyCryptor from './legacyCryptor'; +/** + * Re-export bundled cryptors. + */ export { LegacyCryptor, AesCbcCryptor }; -type CryptorType = ICryptor | ILegacyCryptor; - -type CryptoModuleConfiguration = { - default: CryptorType; - cryptors?: Array; -}; - -export class CryptoModule { +/** + * Crypto module cryptors interface. + */ +type CryptorType = ICryptor | ILegacyCryptor; + +/** + * CryptoModule for browser platform. + */ +export class WebCryptoModule extends AbstractCryptoModule { + /** + * {@link LegacyCryptor|Legacy} cryptor identifier. + */ static LEGACY_IDENTIFIER = ''; - static encoder = new TextEncoder(); - static decoder = new TextDecoder(); - defaultCryptor: CryptorType; - cryptors: Array; - constructor(cryptoModuleConfiguration: CryptoModuleConfiguration) { - this.defaultCryptor = cryptoModuleConfiguration.default; - this.cryptors = cryptoModuleConfiguration.cryptors ?? []; - } + // -------------------------------------------------------- + // --------------- Convenience functions ------------------ + // ------------------------------------------------------- + // region Convenience functions - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - //@ts-ignore: type detection issue with old Config type assignment - static legacyCryptoModule(config) { - return new this({ + static legacyCryptoModule(config: CryptorConfiguration) { + if (!config.cipherKey) throw new PubNubError('Crypto module error: cipher key not set.'); + + return new WebCryptoModule({ default: new LegacyCryptor({ - cipherKey: config.cipherKey, + ...config, useRandomIVs: config.useRandomIVs ?? true, }), cryptors: [new AesCbcCryptor({ cipherKey: config.cipherKey })], }); } - static aesCbcCryptoModule(config: any) { - return new this({ + static aesCbcCryptoModule(config: CryptorConfiguration) { + if (!config.cipherKey) throw new PubNubError('Crypto module error: cipher key not set.'); + + return new WebCryptoModule({ default: new AesCbcCryptor({ cipherKey: config.cipherKey }), cryptors: [ new LegacyCryptor({ - cipherKey: config.cipherKey, + ...config, useRandomIVs: config.useRandomIVs ?? true, }), ], }); } + /** + * Construct crypto module with `cryptor` as default for data encryption and decryption. + * + * @param defaultCryptor - Default cryptor for data encryption and decryption. + * + * @returns Crypto module with pre-configured default cryptor. + */ static withDefaultCryptor(defaultCryptor: CryptorType) { return new this({ default: defaultCryptor }); } + // endregion - private getAllCryptors() { - return [this.defaultCryptor, ...this.cryptors]; - } + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption encrypt(data: ArrayBuffer | string) { - const encrypted = (this.defaultCryptor as ICryptor).encrypt(data); + // Encrypt data. + const encrypted = + data instanceof ArrayBuffer && this.defaultCryptor.identifier === WebCryptoModule.LEGACY_IDENTIFIER + ? (this.defaultCryptor as ILegacyCryptor).encrypt(WebCryptoModule.decoder.decode(data)) + : (this.defaultCryptor as ICryptor).encrypt(data); + if (!encrypted.metadata) return encrypted.data; + else if (typeof encrypted.data === 'string') + throw new Error('Encryption error: encrypted data should be ArrayBuffed.'); + const headerData = this.getHeaderData(encrypted); + return this.concatArrayBuffer(headerData!, encrypted.data); } + async encryptFile(file: PubNubFile, File: PubNubFileConstructor) { + /** + * Files handled differently in case of Legacy cryptor. + * (as long as we support legacy need to check on instance type) + */ + if (this.defaultCryptor.identifier === CryptorHeader.LEGACY_IDENTIFIER) + return (this.defaultCryptor as ILegacyCryptor).encryptFile(file, File); + + const fileData = await this.getFileData(file); + const encrypted = await (this.defaultCryptor as ICryptor).encryptFileData(fileData); + if (typeof encrypted.data === 'string') throw new Error('Encryption error: encrypted data should be ArrayBuffed.'); + + return File.create({ + name: file.name, + mimeType: 'application/octet-stream', + data: this.concatArrayBuffer(this.getHeaderData(encrypted)!, encrypted.data), + }); + } + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + decrypt(data: ArrayBuffer | string) { const encryptedData = typeof data === 'string' ? decode(data) : data; const header = CryptorHeader.tryParse(encryptedData); @@ -72,34 +128,29 @@ export class CryptoModule { header.length > 0 ? encryptedData.slice(header.length - (header as CryptorHeaderV1).metadataLength, header.length) : null; - if (encryptedData.slice(header.length).byteLength <= 0) throw new Error('decryption error. empty content'); + + if (encryptedData.slice(header.length).byteLength <= 0) throw new Error('Decryption error: empty content'); + return cryptor!.decrypt({ data: encryptedData.slice(header.length), metadata: metadata, }); } - async encryptFile(file: PubNubFileType, File: PubNubFileType) { - if (this.defaultCryptor.identifier === CryptorHeader.LEGACY_IDENTIFIER) - return (this.defaultCryptor as ILegacyCryptor).encryptFile(file, File); - const fileData = await this.getFileData(file.data); - const encrypted = await (this.defaultCryptor as ICryptor).encryptFileData(fileData); - return File.create({ - name: file.name, - mimeType: 'application/octet-stream', - data: this.concatArrayBuffer(this.getHeaderData(encrypted)!, encrypted.data), - }); - } - - async decryptFile(file: PubNubFileType, File: PubNubFileType) { + async decryptFile(file: PubNubFile, File: PubNubFileConstructor) { const data = await file.data.arrayBuffer(); const header = CryptorHeader.tryParse(data); const cryptor = this.getCryptor(header); - if (cryptor?.identifier === CryptoModule.LEGACY_IDENTIFIER) { - return (cryptor as ILegacyCryptor).decryptFile(file, File); - } + /** + * Files handled differently in case of Legacy cryptor. + * (as long as we support legacy need to check on instance type) + */ + if (cryptor?.identifier === CryptorHeader.LEGACY_IDENTIFIER) + return (cryptor as ILegacyCryptor).decryptFile(file, File); + const fileData = await this.getFileData(data); const metadata = fileData.slice(header.length - (header as CryptorHeaderV1).metadataLength, header.length); + return File.create({ name: file.name, data: await (this.defaultCryptor as ICryptor).decryptFileData({ @@ -108,34 +159,54 @@ export class CryptoModule { }), }); } + // endregion + + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + + /** + * Retrieve registered cryptor by its identifier. + * + * @param id - Unique cryptor identifier. + * + * @returns Registered cryptor with specified identifier. + * + * @throws Error if cryptor with specified {@link id} can't be found. + */ + private getCryptorFromId(id: string) { + const cryptor = this.getAllCryptors().find((cryptor) => id === cryptor.identifier); + if (cryptor) return cryptor; - private getCryptor(header: string | CryptorHeaderV1) { - if (header === '') { - const cryptor = this.getAllCryptors().find((c) => c.identifier === ''); + throw Error('Unknown cryptor error'); + } + + /** + * Retrieve cryptor by its identifier. + * + * @param header - Header with cryptor-defined data or raw cryptor identifier. + * + * @returns Cryptor which correspond to provided {@link header}. + */ + private getCryptor(header: CryptorHeader | string) { + if (typeof header === 'string') { + const cryptor = this.getAllCryptors().find((cryptor) => cryptor.identifier === header); if (cryptor) return cryptor; - throw new Error('unknown cryptor error'); + + throw new Error('Unknown cryptor error'); } else if (header instanceof CryptorHeaderV1) { return this.getCryptorFromId(header.identifier); } } - private getCryptorFromId(id: string) { - const cryptor = this.getAllCryptors().find((c) => id === c.identifier); - if (cryptor) { - return cryptor; - } - throw Error('unknown cryptor error'); - } - - private concatArrayBuffer(ab1: ArrayBuffer, ab2: ArrayBuffer) { - const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); - - tmp.set(new Uint8Array(ab1), 0); - tmp.set(new Uint8Array(ab2), ab1.byteLength); - - return tmp.buffer; - } - + /** + * Create cryptor header data. + * + * @param encrypted - Encryption data object as source for header data. + * + * @returns Binary representation of the cryptor header data. + */ private getHeaderData(encrypted: EncryptedDataType) { if (!encrypted.metadata) return; const header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); @@ -147,24 +218,43 @@ export class CryptoModule { return headerData.buffer; } - private async getFileData(input: any) { - if (input instanceof Blob) { - const fileData = await input.arrayBuffer(); - return fileData; - } - if (input instanceof ArrayBuffer) { - return input; - } - if (typeof input === 'string') { - return CryptoModule.encoder.encode(input); - } + /** + * Merge two {@link ArrayBuffer} instances. + * + * @param ab1 - First {@link ArrayBuffer}. + * @param ab2 - Second {@link ArrayBuffer}. + * + * @returns Merged data as {@link ArrayBuffer}. + */ + private concatArrayBuffer(ab1: ArrayBuffer, ab2: ArrayBuffer): ArrayBuffer { + const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); + + tmp.set(new Uint8Array(ab1), 0); + tmp.set(new Uint8Array(ab2), ab1.byteLength); + + return tmp.buffer; + } + + /** + * Retrieve file content. + * + * @param file - Content of the {@link PubNub} File object. + * + * @returns Normalized file {@link data} as {@link ArrayBuffer}; + */ + private async getFileData(file: PubNubFile | ArrayBuffer) { + if (file instanceof ArrayBuffer) return file; + else if (file instanceof PubNubFile) return file.toArrayBuffer(); + throw new Error( 'Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob', ); } } -// CryptorHeader Utility +/** + * CryptorHeader Utility + */ class CryptorHeader { static SENTINEL = 'PNED'; static LEGACY_IDENTIFIER = ''; @@ -180,37 +270,33 @@ class CryptorHeader { static tryParse(data: ArrayBuffer) { const encryptedData = new Uint8Array(data); - let sentinel: any = ''; + let sentinel: Uint8Array; let version = null; + if (encryptedData.byteLength >= 4) { sentinel = encryptedData.slice(0, 4); - if (this.decoder.decode(sentinel) !== CryptorHeader.SENTINEL) return ''; + if (this.decoder.decode(sentinel) !== CryptorHeader.SENTINEL) return WebCryptoModule.LEGACY_IDENTIFIER; } - if (encryptedData.byteLength >= 5) { - version = (encryptedData as Uint8Array)[4] as number; - } else { - throw new Error('decryption error. invalid header version'); - } - if (version > CryptorHeader.MAX_VERSION) throw new Error('unknown cryptor error'); - let identifier: any = ''; + if (encryptedData.byteLength >= 5) version = (encryptedData as Uint8Array)[4] as number; + else throw new Error('Decryption error: invalid header version'); + + if (version > CryptorHeader.MAX_VERSION) throw new Error('Decryption error: Unknown cryptor error'); + + let identifier: Uint8Array; let pos = 5 + CryptorHeader.IDENTIFIER_LENGTH; - if (encryptedData.byteLength >= pos) { - identifier = encryptedData.slice(5, pos); - } else { - throw new Error('decryption error. invalid crypto identifier'); - } + if (encryptedData.byteLength >= pos) identifier = encryptedData.slice(5, pos); + else throw new Error('Decryption error: invalid crypto identifier'); + let metadataLength = null; - if (encryptedData.byteLength >= pos + 1) { - metadataLength = (encryptedData as Uint8Array)[pos]; - } else { - throw new Error('decryption error. invalid metadata length'); - } + if (encryptedData.byteLength >= pos + 1) metadataLength = (encryptedData as Uint8Array)[pos]; + else throw new Error('Decryption error: invalid metadata length'); + pos += 1; if (metadataLength === 255 && encryptedData.byteLength >= pos + 2) { metadataLength = new Uint16Array(encryptedData.slice(pos, pos + 2)).reduce((acc, val) => (acc << 8) + val, 0); - pos += 2; } + return new CryptorHeaderV1(this.decoder.decode(identifier), metadataLength); } } @@ -266,14 +352,15 @@ class CryptorHeaderV1 { pos += CryptorHeader.SENTINEL.length; header[pos] = this.version; pos++; + if (this.identifier) header.set(encoder.encode(this.identifier), pos); - pos += CryptorHeader.IDENTIFIER_LENGTH; + const metadataLength = this.metadataLength; - if (metadataLength < 255) { - header[pos] = metadataLength; - } else { - header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); - } + pos += CryptorHeader.IDENTIFIER_LENGTH; + + if (metadataLength < 255) header[pos] = metadataLength; + else header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); + return header; } } diff --git a/src/crypto/modules/node.js b/src/crypto/modules/node.js deleted file mode 100644 index 11055962c..000000000 --- a/src/crypto/modules/node.js +++ /dev/null @@ -1,191 +0,0 @@ -/** */ -import { Readable, PassThrough, Transform } from 'stream'; -import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'crypto'; - -export default class NodeCryptography { - static IV_LENGTH = 16; - - get algo() { - return 'aes-256-cbc'; - } - - async encrypt(key, input) { - const bKey = this.getKey(key); - if (input instanceof Buffer) { - return this.encryptBuffer(bKey, input); - } - if (input instanceof Readable) { - return this.encryptStream(bKey, input); - } - if (typeof input === 'string') { - return this.encryptString(bKey, input); - } - throw new Error('Unsupported input format'); - } - - async decrypt(key, input) { - const bKey = this.getKey(key); - if (input instanceof Buffer) { - return this.decryptBuffer(bKey, input); - } - if (input instanceof Readable) { - return this.decryptStream(bKey, input); - } - if (typeof input === 'string') { - return this.decryptString(bKey, input); - } - throw new Error('Unsupported input format'); - } - - async encryptFile(key, file, File) { - const bKey = this.getKey(key); - - if (file.data instanceof Buffer) { - if (file.data.byteLength <= 0) throw new Error('encryption error. empty content'); - return File.create({ - name: file.name, - mimeType: 'application/octet-stream', - data: await this.encryptBuffer(bKey, file.data), - }); - } - if (file.data instanceof Readable) { - if (file.contentLength === 0) throw new Error('encryption error. empty content'); - return File.create({ - name: file.name, - mimeType: 'application/octet-stream', - stream: await this.encryptStream(bKey, file.data), - }); - } - throw new Error('Cannot encrypt this file. In Node.js file encryption supports only string, Buffer or Stream.'); - } - - async decryptFile(key, file, File) { - const bKey = this.getKey(key); - - if (file.data instanceof Buffer) { - return File.create({ - name: file.name, - data: await this.decryptBuffer(bKey, file.data), - }); - } - if (file.data instanceof Readable) { - return File.create({ - name: file.name, - stream: await this.decryptStream(bKey, file.data), - }); - } - throw new Error('Cannot decrypt this file. In Node.js file decryption supports only string, Buffer or Stream.'); - } - - getKey(key) { - const sha = createHash('sha256'); - - sha.update(Buffer.from(key, 'utf8')); - - return Buffer.from(sha.digest('hex').slice(0, 32), 'utf8'); - } - - getIv() { - return randomBytes(NodeCryptography.IV_LENGTH); - } - - encryptString(key, plaintext) { - const bIv = this.getIv(); - - const bPlaintext = Buffer.from(plaintext); - - const aes = createCipheriv(this.algo, key, bIv); - - return Buffer.concat([bIv, aes.update(bPlaintext), aes.final()]).toString('utf8'); - } - - decryptString(key, sCiphertext) { - const ciphertext = Buffer.from(sCiphertext); - const bIv = ciphertext.slice(0, NodeCryptography.IV_LENGTH); - const bCiphertext = ciphertext.slice(NodeCryptography.IV_LENGTH); - - const aes = createDecipheriv(this.algo, key, bIv); - - return Buffer.concat([aes.update(bCiphertext), aes.final()]).toString('utf8'); - } - - encryptBuffer(key, plaintext) { - const bIv = this.getIv(); - - const aes = createCipheriv(this.algo, key, bIv); - - return Buffer.concat([bIv, aes.update(plaintext), aes.final()]); - } - - decryptBuffer(key, ciphertext) { - const bIv = ciphertext.slice(0, NodeCryptography.IV_LENGTH); - const bCiphertext = ciphertext.slice(NodeCryptography.IV_LENGTH); - if (bCiphertext.byteLength <= 0) throw new Error('decryption error: empty content'); - const aes = createDecipheriv(this.algo, key, bIv); - - return Buffer.concat([aes.update(bCiphertext), aes.final()]); - } - - async encryptStream(key, stream) { - const bIv = this.getIv(); - const aes = createCipheriv('aes-256-cbc', key, bIv).setAutoPadding(true); - let inited = false; - return stream.pipe(aes).pipe( - new Transform({ - transform(chunk, _, cb) { - if (!inited) { - inited = true; - this.push(Buffer.concat([bIv, chunk])); - } else { - this.push(chunk); - } - cb(); - }, - }), - ); - } - - decryptStream(key, stream) { - const output = new PassThrough(); - - let bIv = Buffer.alloc(0); - let aes = null; - - const getIv = () => { - let data = stream.read(); - - while (data !== null) { - if (data) { - const bChunk = Buffer.from(data); - const sliceLen = NodeCryptography.IV_LENGTH - bIv.byteLength; - - if (bChunk.byteLength < sliceLen) { - bIv = Buffer.concat([bIv, bChunk]); - } else { - bIv = Buffer.concat([bIv, bChunk.slice(0, sliceLen)]); - - aes = createDecipheriv(this.algo, key, bIv); - - aes.pipe(output); - - aes.write(bChunk.slice(sliceLen)); - } - } - - data = stream.read(); - } - }; - - stream.on('readable', getIv); - - stream.on('end', () => { - if (aes) { - aes.end(); - } - - output.end(); - }); - - return output; - } -} diff --git a/src/crypto/modules/node.ts b/src/crypto/modules/node.ts new file mode 100644 index 000000000..e0eacbd77 --- /dev/null +++ b/src/crypto/modules/node.ts @@ -0,0 +1,300 @@ +/** + * Legacy Node.js cryptography module. + */ + +import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'crypto'; +import { Readable, PassThrough, Transform } from 'stream'; +import { Buffer } from 'buffer'; + +import PubNubFile, { PubNubFileParameters } from '../../file/modules/node'; +import { Cryptography } from '../../core/interfaces/cryptography'; +import { PubNubFileConstructor } from '../../core/types/file'; + +/** + * Legacy cryptography implementation for Node.js-based {@link PubNub} client. + */ +export default class NodeCryptography implements Cryptography { + /** + * Random initialization vector size. + */ + static IV_LENGTH = 16; + + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption + + public async encrypt( + key: string, + input: string | ArrayBuffer | Buffer | Readable, + ): Promise { + const bKey = this.getKey(key); + + if (input instanceof Buffer) return this.encryptBuffer(bKey, input); + if (input instanceof Readable) return this.encryptStream(bKey, input); + if (typeof input === 'string') return this.encryptString(bKey, input); + + throw new Error('Encryption error: unsupported input format'); + } + + /** + * Encrypt provided source {@link Buffer} using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link Buffer}. + * @param buffer - Source {@link Buffer} for encryption. + * + * @returns Encrypted data as {@link Buffer} object. + */ + private encryptBuffer(key: Buffer, buffer: Buffer) { + const bIv = this.getIv(); + const aes = createCipheriv(this.algo, key, bIv); + + return Buffer.concat([bIv, aes.update(buffer), aes.final()]); + } + + /** + * Encrypt provided source {@link Readable} stream using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link Readable} stream. + * @param stream - Source {@link Readable} stream for encryption. + * + * @returns Encrypted data as {@link Transform} object. + */ + private async encryptStream(key: Buffer, stream: Readable) { + const bIv = this.getIv(); + const aes = createCipheriv(this.algo, key, bIv).setAutoPadding(true); + let initiated = false; + + return stream.pipe(aes).pipe( + new Transform({ + transform(chunk, _, cb) { + if (!initiated) { + initiated = true; + this.push(Buffer.concat([bIv, chunk])); + } else this.push(chunk); + + cb(); + }, + }), + ); + } + + /** + * Encrypt provided source {@link string} using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link string}. + * @param text - Source {@link string} for encryption. + * + * @returns Encrypted data as byte {@link string}. + */ + private encryptString(key: Buffer, text: string) { + const bIv = this.getIv(); + const bPlaintext = Buffer.from(text); + const aes = createCipheriv(this.algo, key, bIv); + + return Buffer.concat([bIv, aes.update(bPlaintext), aes.final()]).toString('utf8'); + } + + public async encryptFile( + key: string, + file: PubNubFile, + File: PubNubFileConstructor, + ) { + const bKey = this.getKey(key); + + /** + * Buffer type check also covers `string` which converted to the `Buffer` during file object creation. + */ + if (file.data instanceof Buffer) { + if (file.data.byteLength <= 0) throw new Error('Encryption error: empty content.'); + + return File.create({ + name: file.name, + mimeType: file.mimeType, + data: this.encryptBuffer(bKey, file.data), + }); + } + + if (file.data instanceof Readable) { + if (!file.contentLength || file.contentLength === 0) throw new Error('Encryption error: empty content.'); + + return File.create({ + name: file.name, + mimeType: file.mimeType, + stream: await this.encryptStream(bKey, file.data), + }); + } + + throw new Error('Cannot encrypt this file. In Node.js file encryption supports only string, Buffer or Stream.'); + } + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption + + public async decrypt(key: string, input: string | ArrayBuffer | Buffer | Readable) { + const bKey = this.getKey(key); + if (input instanceof ArrayBuffer) { + const decryptedBuffer = this.decryptBuffer(bKey, Buffer.from(input)); + + return decryptedBuffer.buffer.slice( + decryptedBuffer.byteOffset, + decryptedBuffer.byteOffset + decryptedBuffer.length, + ); + } + if (input instanceof Buffer) return this.decryptBuffer(bKey, input); + if (input instanceof Readable) return this.decryptStream(bKey, input); + if (typeof input === 'string') return this.decryptString(bKey, input); + + throw new Error('Decryption error: unsupported input format'); + } + + /** + * Decrypt provided encrypted {@link Buffer} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link Buffer}. + * @param buffer - Encrypted {@link Buffer} for decryption. + * + * @returns Decrypted data as {@link Buffer} object. + */ + private decryptBuffer(key: Buffer, buffer: Buffer) { + const bIv = buffer.slice(0, NodeCryptography.IV_LENGTH); + const bCiphertext = buffer.slice(NodeCryptography.IV_LENGTH); + + if (bCiphertext.byteLength <= 0) throw new Error('Decryption error: empty content'); + + const aes = createDecipheriv(this.algo, key, bIv); + + return Buffer.concat([aes.update(bCiphertext), aes.final()]); + } + + /** + * Decrypt provided encrypted {@link Readable} stream using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link Readable} stream. + * @param stream - Encrypted {@link Readable} stream for decryption. + * + * @returns Decrypted data as {@link Readable} object. + */ + private decryptStream(key: Buffer, stream: Readable) { + let aes: ReturnType | null = null; + const output = new PassThrough(); + let bIv = Buffer.alloc(0); + + const getIv = () => { + let data = stream.read(); + + while (data !== null) { + if (data) { + const bChunk = Buffer.from(data); + const sliceLen = NodeCryptography.IV_LENGTH - bIv.byteLength; + + if (bChunk.byteLength < sliceLen) bIv = Buffer.concat([bIv, bChunk]); + else { + bIv = Buffer.concat([bIv, bChunk.slice(0, sliceLen)]); + aes = createDecipheriv(this.algo, key, bIv); + aes.pipe(output); + aes.write(bChunk.slice(sliceLen)); + } + } + + data = stream.read(); + } + }; + + stream.on('readable', getIv); + stream.on('end', () => { + if (aes) aes.end(); + output.end(); + }); + + return output; + } + + /** + * Decrypt provided encrypted {@link string} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link string}. + * @param text - Encrypted {@link string} for decryption. + * + * @returns Decrypted data as byte {@link string}. + */ + private decryptString(key: Buffer, text: string) { + const ciphertext = Buffer.from(text); + const bIv = ciphertext.slice(0, NodeCryptography.IV_LENGTH); + const bCiphertext = ciphertext.slice(NodeCryptography.IV_LENGTH); + const aes = createDecipheriv(this.algo, key, bIv); + + return Buffer.concat([aes.update(bCiphertext), aes.final()]).toString('utf8'); + } + + public async decryptFile( + key: string, + file: PubNubFile, + File: PubNubFileConstructor, + ) { + const bKey = this.getKey(key); + + /** + * Buffer type check also covers `string` which converted to the `Buffer` during file object creation. + */ + if (file.data instanceof Buffer) { + return File.create({ + name: file.name, + mimeType: file.mimeType, + data: this.decryptBuffer(bKey, file.data), + }); + } + + if (file.data instanceof Readable) { + return File.create({ + name: file.name, + mimeType: file.mimeType, + stream: this.decryptStream(bKey, file.data), + }); + } + + throw new Error('Cannot decrypt this file. In Node.js file decryption supports only string, Buffer or Stream.'); + } + // endregion + + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + + // region Helpers + /** + * Cryptography algorithm. + * + * @returns Cryptography module algorithm. + */ + private get algo() { + return 'aes-256-cbc'; + } + + /** + * Convert cipher key to the {@link Buffer}. + * + * @param key - String cipher key. + * + * @returns SHA256 HEX encoded cipher key {@link Buffer}. + */ + private getKey(key: string) { + const sha = createHash('sha256'); + sha.update(Buffer.from(key, 'utf8')); + + return Buffer.from(sha.digest('hex').slice(0, 32), 'utf8'); + } + + /** + * Generate random initialization vector. + * + * @returns Random initialization vector. + */ + private getIv() { + return randomBytes(NodeCryptography.IV_LENGTH); + } + // endregion +} diff --git a/src/crypto/modules/web.js b/src/crypto/modules/web.js deleted file mode 100644 index 20e1a274b..000000000 --- a/src/crypto/modules/web.js +++ /dev/null @@ -1,117 +0,0 @@ -/* global crypto */ - -function concatArrayBuffer(ab1, ab2) { - const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); - - tmp.set(new Uint8Array(ab1), 0); - tmp.set(new Uint8Array(ab2), ab1.byteLength); - - return tmp.buffer; -} - -export default class WebCryptography { - static IV_LENGTH = 16; - static encoder = new TextEncoder(); - static decoder = new TextDecoder(); - - get algo() { - return 'aes-256-cbc'; - } - - async encrypt(key, input) { - const cKey = await this.getKey(key); - - if (input instanceof ArrayBuffer) { - return this.encryptArrayBuffer(cKey, input); - } - if (typeof input === 'string') { - return this.encryptString(cKey, input); - } - throw new Error('Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer'); - } - - async decrypt(key, input) { - const cKey = await this.getKey(key); - if (input instanceof ArrayBuffer) { - return this.decryptArrayBuffer(cKey, input); - } - if (typeof input === 'string') { - return this.decryptString(cKey, input); - } - throw new Error('Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer'); - } - - async encryptFile(key, file, File) { - if (file.data.byteLength <= 0) throw new Error('encryption error. empty content'); - const bKey = await this.getKey(key); - - const abPlaindata = await file.data.arrayBuffer(); - - const abCipherdata = await this.encryptArrayBuffer(bKey, abPlaindata); - - return File.create({ - name: file.name, - mimeType: 'application/octet-stream', - data: abCipherdata, - }); - } - - async decryptFile(key, file, File) { - const bKey = await this.getKey(key); - - const abCipherdata = await file.data.arrayBuffer(); - const abPlaindata = await this.decryptArrayBuffer(bKey, abCipherdata); - - return File.create({ - name: file.name, - data: abPlaindata, - }); - } - - async getKey(key) { - const digest = await crypto.subtle.digest('SHA-256', WebCryptography.encoder.encode(key)); - const hashHex = Array.from(new Uint8Array(digest)) - .map((b) => b.toString(16).padStart(2, '0')) - .join(''); - const abKey = WebCryptography.encoder.encode(hashHex.slice(0, 32)).buffer; - return crypto.subtle.importKey('raw', abKey, 'AES-CBC', true, ['encrypt', 'decrypt']); - } - - async encryptArrayBuffer(key, plaintext) { - const abIv = crypto.getRandomValues(new Uint8Array(16)); - - return concatArrayBuffer(abIv.buffer, await crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, plaintext)); - } - - async decryptArrayBuffer(key, ciphertext) { - const abIv = ciphertext.slice(0, 16); - if (ciphertext.slice(WebCryptography.IV_LENGTH).byteLength <= 0) throw new Error('decryption error: empty content'); - const data = await crypto.subtle.decrypt( - { name: 'AES-CBC', iv: abIv }, - key, - ciphertext.slice(WebCryptography.IV_LENGTH), - ); - return data; - } - - async encryptString(key, plaintext) { - const abIv = crypto.getRandomValues(new Uint8Array(16)); - - const abPlaintext = WebCryptography.encoder.encode(plaintext).buffer; - const abPayload = await crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, abPlaintext); - - const ciphertext = concatArrayBuffer(abIv.buffer, abPayload); - - return WebCryptography.decoder.decode(ciphertext); - } - - async decryptString(key, ciphertext) { - const abCiphertext = WebCryptography.encoder.encode(ciphertext).buffer; - const abIv = abCiphertext.slice(0, 16); - const abPayload = abCiphertext.slice(16); - - const abPlaintext = await crypto.subtle.decrypt({ name: 'AES-CBC', iv: abIv }, key, abPayload); - - return WebCryptography.decoder.decode(abPlaintext); - } -} diff --git a/src/crypto/modules/web.ts b/src/crypto/modules/web.ts new file mode 100644 index 000000000..e971fab6f --- /dev/null +++ b/src/crypto/modules/web.ts @@ -0,0 +1,233 @@ +/* global crypto */ +/** + * Legacy browser cryptography module. + */ + +import { PubNubFile, PubNubFileParameters } from '../../file/modules/web'; +import { Cryptography } from '../../core/interfaces/cryptography'; +import { PubNubFileConstructor } from '../../core/types/file'; + +function concatArrayBuffer(ab1: ArrayBuffer, ab2: ArrayBuffer) { + const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); + + tmp.set(new Uint8Array(ab1), 0); + tmp.set(new Uint8Array(ab2), ab1.byteLength); + + return tmp.buffer; +} + +/** + * Legacy cryptography implementation for browser-based {@link PubNub} client. + */ +export default class WebCryptography implements Cryptography { + /** + * Random initialization vector size. + */ + static IV_LENGTH = 16; + + /** + * {@link string|String} to {@link ArrayBuffer} response decoder. + */ + static encoder = new TextEncoder(); + + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + static decoder = new TextDecoder(); + + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + + // region Encryption + /** + * Encrypt provided source data using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` data. + * @param input - Source data for encryption. + * + * @returns Encrypted data as object or stream (depending on from source data type). + * + * @throws Error if unknown data type has been passed. + */ + public async encrypt(key: string, input: ArrayBuffer | string) { + if (!(input instanceof ArrayBuffer) && typeof input !== 'string') + throw new Error('Cannot encrypt this file. In browsers file encryption supports only string or ArrayBuffer'); + + const cKey = await this.getKey(key); + + return input instanceof ArrayBuffer ? this.encryptArrayBuffer(cKey, input) : this.encryptString(cKey, input); + } + + /** + * Encrypt provided source {@link Buffer} using specific encryption {@link ArrayBuffer}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link ArrayBuffer}. + * @param buffer - Source {@link ArrayBuffer} for encryption. + * + * @returns Encrypted data as {@link ArrayBuffer} object. + */ + private async encryptArrayBuffer(key: CryptoKey, buffer: ArrayBuffer) { + const abIv = crypto.getRandomValues(new Uint8Array(16)); + + return concatArrayBuffer(abIv.buffer, await crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, buffer)); + } + + /** + * Encrypt provided source {@link string} using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link string}. + * @param text - Source {@link string} for encryption. + * + * @returns Encrypted data as byte {@link string}. + */ + private async encryptString(key: CryptoKey, text: string) { + const abIv = crypto.getRandomValues(new Uint8Array(16)); + + const abPlaintext = WebCryptography.encoder.encode(text).buffer; + const abPayload = await crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, abPlaintext); + + const ciphertext = concatArrayBuffer(abIv.buffer, abPayload); + + return WebCryptography.decoder.decode(ciphertext); + } + + /** + * Encrypt provided {@link PubNub} File object using specific encryption {@link key}. + * + * @param key - Key for {@link PubNub} File object encryption.
**Note:** Same key should be + * used to `decrypt` data. + * @param file - Source {@link PubNub} File object for encryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Encrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + public async encryptFile( + key: string, + file: PubNubFile, + File: PubNubFileConstructor, + ) { + if ((file.contentLength ?? 0) <= 0) throw new Error('encryption error. empty content'); + const bKey = await this.getKey(key); + const abPlaindata = await file.toArrayBuffer(); + const abCipherdata = await this.encryptArrayBuffer(bKey, abPlaindata); + + return File.create({ + name: file.name, + mimeType: file.mimeType ?? 'application/octet-stream', + data: abCipherdata, + }); + } + // endregion + + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + + // region Decryption + /** + * Decrypt provided encrypted data using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` data. + * @param input - Encrypted data for decryption. + * + * @returns Decrypted data as object or stream (depending on from encrypted data type). + * + * @throws Error if unknown data type has been passed. + */ + public async decrypt(key: string, input: ArrayBuffer | string) { + if (!(input instanceof ArrayBuffer) && typeof input !== 'string') + throw new Error('Cannot decrypt this file. In browsers file decryption supports only string or ArrayBuffer'); + + const cKey = await this.getKey(key); + + return input instanceof ArrayBuffer ? this.decryptArrayBuffer(cKey, input) : this.decryptString(cKey, input); + } + + /** + * Decrypt provided encrypted {@link ArrayBuffer} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link ArrayBuffer}. + * @param buffer - Encrypted {@link ArrayBuffer} for decryption. + * + * @returns Decrypted data as {@link ArrayBuffer} object. + */ + private async decryptArrayBuffer(key: CryptoKey, buffer: ArrayBuffer) { + const abIv = buffer.slice(0, 16); + if (buffer.slice(WebCryptography.IV_LENGTH).byteLength <= 0) throw new Error('decryption error: empty content'); + + return await crypto.subtle.decrypt({ name: 'AES-CBC', iv: abIv }, key, buffer.slice(WebCryptography.IV_LENGTH)); + } + + /** + * Decrypt provided encrypted {@link string} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link string}. + * @param text - Encrypted {@link string} for decryption. + * + * @returns Decrypted data as byte {@link string}. + */ + private async decryptString(key: CryptoKey, text: string) { + const abCiphertext = WebCryptography.encoder.encode(text).buffer; + const abIv = abCiphertext.slice(0, 16); + const abPayload = abCiphertext.slice(16); + const abPlaintext = await crypto.subtle.decrypt({ name: 'AES-CBC', iv: abIv }, key, abPayload); + + return WebCryptography.decoder.decode(abPlaintext); + } + + /** + * Decrypt provided {@link PubNub} File object using specific decryption {@link key}. + * + * @param key - Key for {@link PubNub} File object decryption.
**Note:** Should be the same + * as used to `encrypt` data. + * @param file - Encrypted {@link PubNub} File object for decryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + public async decryptFile( + key: string, + file: PubNubFile, + File: PubNubFileConstructor, + ) { + const bKey = await this.getKey(key); + + const abCipherdata = await file.toArrayBuffer(); + const abPlaindata = await this.decryptArrayBuffer(bKey, abCipherdata); + + return File.create({ + name: file.name, + mimeType: file.mimeType, + data: abPlaindata, + }); + } + // endregion + + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + + // region Helpers + /** + * Convert cipher key to the {@link Buffer}. + * + * @param key - String cipher key. + * + * @returns SHA256 HEX encoded cipher key {@link CryptoKey}. + */ + private async getKey(key: string) { + const digest = await crypto.subtle.digest('SHA-256', WebCryptography.encoder.encode(key)); + const hashHex = Array.from(new Uint8Array(digest)) + .map((b) => b.toString(16).padStart(2, '0')) + .join(''); + const abKey = WebCryptography.encoder.encode(hashHex.slice(0, 32)).buffer; + + return crypto.subtle.importKey('raw', abKey, 'AES-CBC', true, ['encrypt', 'decrypt']); + } + // endregion +} diff --git a/src/entities/Channel.ts b/src/entities/Channel.ts index e3ad72904..5e09713a0 100644 --- a/src/entities/Channel.ts +++ b/src/entities/Channel.ts @@ -1,17 +1,19 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; import { Subscription } from './Subscription'; -import { SubscriptionOptions, EventEmitter } from './commonTypes'; -import type PubNub from '../core/pubnub-common'; export class Channel { - private name: string; - private eventEmitter: EventEmitter; - private pubnub: PubNub; + private readonly name: string; - constructor(channelName: string, eventEmitter: EventEmitter, pubnub: PubNub) { + constructor( + channelName: string, + private readonly eventEmitter: EventEmitter, + private readonly pubnub: PubNub, + ) { this.name = channelName; - this.eventEmitter = eventEmitter; - this.pubnub = pubnub; } + subscription(subscriptionOptions?: SubscriptionOptions) { return new Subscription({ channels: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name], diff --git a/src/entities/ChannelGroup.ts b/src/entities/ChannelGroup.ts index f668e79c9..ff6671ba8 100644 --- a/src/entities/ChannelGroup.ts +++ b/src/entities/ChannelGroup.ts @@ -1,17 +1,19 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; import { Subscription } from './Subscription'; -import { SubscriptionOptions, EventEmitter } from './commonTypes'; -import type PubNub from '../core/pubnub-common'; export class ChannelGroup { - private name: string; - private eventEmitter: EventEmitter; - private pubnub: PubNub; + private readonly name: string; - constructor(channelGroup: string, eventEmitter: EventEmitter, pubnub: PubNub) { + constructor( + channelGroup: string, + private readonly eventEmitter: EventEmitter, + private readonly pubnub: PubNub, + ) { this.name = channelGroup; - this.eventEmitter = eventEmitter; - this.pubnub = pubnub; } + subscription(subscriptionOptions?: SubscriptionOptions) { return new Subscription({ channels: [], diff --git a/src/entities/ChannelMetadata.ts b/src/entities/ChannelMetadata.ts index 78020d988..a06bfffa1 100644 --- a/src/entities/ChannelMetadata.ts +++ b/src/entities/ChannelMetadata.ts @@ -1,17 +1,15 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; import { Subscription } from './Subscription'; -import { SubscriptionOptions, EventEmitter } from './commonTypes'; -import type PubNub from '../core/pubnub-common'; export class ChannelMetadata { - private id: string; - private eventEmitter: EventEmitter; - private pubnub: PubNub; + constructor( + private readonly id: string, + private readonly eventEmitter: EventEmitter, + private readonly pubnub: PubNub, + ) {} - constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub) { - this.id = id; - this.eventEmitter = eventEmitter; - this.pubnub = pubnub; - } subscription(subscriptionOptions?: SubscriptionOptions) { return new Subscription({ channels: [this.id], diff --git a/src/entities/SubscribeCapable.ts b/src/entities/SubscribeCapable.ts index 93d2e7ebf..b6cdcc84d 100644 --- a/src/entities/SubscribeCapable.ts +++ b/src/entities/SubscribeCapable.ts @@ -1,13 +1,15 @@ -import { EventEmitter, Listener, SubscriptionOptions } from './commonTypes'; -import PubNubType from 'pubnub'; -import type PubNub from '../core/pubnub-common'; +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import { Listener } from '../core/components/listener_manager'; +import * as Subscription from '../core/types/api/subscription'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; export abstract class SubscribeCapable { protected abstract channelNames: string[]; protected abstract groupNames: string[]; protected abstract listener: Listener; protected abstract eventEmitter: EventEmitter; - protected abstract pubnub: PubNub; + protected abstract pubnub: PubNub; protected abstract options?: SubscriptionOptions; subscribe() { @@ -24,27 +26,27 @@ export abstract class SubscribeCapable { }); } - set onMessage(onMessagelistener: (messageEvent: PubNubType.MessageEvent) => void) { - this.listener.message = onMessagelistener; + set onMessage(onMessageListener: (messageEvent: Subscription.Message) => void) { + this.listener.message = onMessageListener; } - set onPresence(onPresencelistener: (presenceEvent: PubNubType.PresenceEvent) => void) { - this.listener.presence = onPresencelistener; + set onPresence(onPresenceListener: (presenceEvent: Subscription.Presence) => void) { + this.listener.presence = onPresenceListener; } - set onSignal(onSignalListener: (signalEvent: PubNubType.SignalEvent) => void) { + set onSignal(onSignalListener: (signalEvent: Subscription.Signal) => void) { this.listener.signal = onSignalListener; } - set onObjects(onObjectsListener: (objectsEvent: PubNubType.ObjectsEvent) => void) { + set onObjects(onObjectsListener: (objectsEvent: Subscription.AppContextObject) => void) { this.listener.objects = onObjectsListener; } - set onMessageAction(messageActionEventListener: (messageActionEvent: PubNubType.MessageActionEvent) => void) { + set onMessageAction(messageActionEventListener: (messageActionEvent: Subscription.MessageAction) => void) { this.listener.messageAction = messageActionEventListener; } - set onFile(fileEventListener: (fileEvent: PubNubType.FileEvent) => void) { + set onFile(fileEventListener: (fileEvent: Subscription.File) => void) { this.listener.file = fileEventListener; } diff --git a/src/entities/Subscription.ts b/src/entities/Subscription.ts index 6e2a17aa3..2002313e5 100644 --- a/src/entities/Subscription.ts +++ b/src/entities/Subscription.ts @@ -1,13 +1,15 @@ -import { SubscriptionSet } from './SubscriptionSet'; -import { SubscriptionOptions, EventEmitter, Listener } from './commonTypes'; -import type PubNub from '../core/pubnub-common'; +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import { Listener } from '../core/components/listener_manager'; +import EventEmitter from '../core/components/eventEmitter'; import { SubscribeCapable } from './SubscribeCapable'; +import { SubscriptionOptions } from './commonTypes'; +import { SubscriptionSet } from './SubscriptionSet'; export class Subscription extends SubscribeCapable { protected channelNames: string[] = []; protected groupNames: string[] = []; protected options?: SubscriptionOptions; - protected pubnub: PubNub; + protected pubnub: PubNub; protected eventEmitter: EventEmitter; protected listener: Listener; @@ -22,7 +24,7 @@ export class Subscription extends SubscribeCapable { channelGroups: string[]; subscriptionOptions?: SubscriptionOptions; eventEmitter: EventEmitter; - pubnub: PubNub; + pubnub: PubNub; }) { super(); this.channelNames = channels; diff --git a/src/entities/SubscriptionSet.ts b/src/entities/SubscriptionSet.ts index d824e682b..970ff7754 100644 --- a/src/entities/SubscriptionSet.ts +++ b/src/entities/SubscriptionSet.ts @@ -1,13 +1,15 @@ -import { Subscription } from './Subscription'; -import { SubscriptionOptions, EventEmitter, Listener } from './commonTypes'; -import type PubNub from '../core/pubnub-common'; +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import { Listener } from '../core/components/listener_manager'; +import EventEmitter from '../core/components/eventEmitter'; import { SubscribeCapable } from './SubscribeCapable'; +import { SubscriptionOptions } from './commonTypes'; +import { Subscription } from './Subscription'; export class SubscriptionSet extends SubscribeCapable { protected channelNames: string[] = []; protected groupNames: string[] = []; - protected options: SubscriptionOptions; - protected pubnub: PubNub; + protected options?: SubscriptionOptions; + protected pubnub: PubNub; protected eventEmitter: EventEmitter; protected subscriptionList: Subscription[] = []; protected listener: Listener; @@ -19,11 +21,11 @@ export class SubscriptionSet extends SubscribeCapable { eventEmitter, pubnub, }: { - channels: string[]; - channelGroups: string[]; - subscriptionOptions: SubscriptionOptions; + channels?: string[]; + channelGroups?: string[]; + subscriptionOptions?: SubscriptionOptions; eventEmitter: EventEmitter; - pubnub: PubNub; + pubnub: PubNub; }) { super(); this.options = subscriptionOptions; diff --git a/src/entities/UserMetadata.ts b/src/entities/UserMetadata.ts index 3364374f0..abc11abac 100644 --- a/src/entities/UserMetadata.ts +++ b/src/entities/UserMetadata.ts @@ -1,17 +1,15 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; import { Subscription } from './Subscription'; -import { SubscriptionOptions, EventEmitter } from './commonTypes'; -import type PubNub from '../core/pubnub-common'; export class UserMetadata { - private id: string; - private eventEmitter: EventEmitter; - private pubnub: PubNub; + constructor( + private readonly id: string, + private readonly eventEmitter: EventEmitter, + private readonly pubnub: PubNub, + ) {} - constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub) { - this.id = id; - this.eventEmitter = eventEmitter; - this.pubnub = pubnub; - } subscription(subscriptionOptions?: SubscriptionOptions) { return new Subscription({ channels: [this.id], diff --git a/src/entities/commonTypes.ts b/src/entities/commonTypes.ts index 496d5047d..cd30c0c61 100644 --- a/src/entities/commonTypes.ts +++ b/src/entities/commonTypes.ts @@ -1,31 +1,4 @@ -import PubNub from 'pubnub'; - export type SubscriptionOptions = { cursor?: { timetoken?: string; region?: number }; receivePresenceEvents?: boolean; }; - -export type EventEmitter = { - emitEvent(e: Event): void; - addListener(l: Listener, channels?: string[], groups?: string[]): void; - removeListener(listener: Listener, channels?: string[], groups?: string[]): void; - removeAllListeners(): void; -}; - -export type Listener = { - message?(m: PubNub.MessageEvent): void; - presence?(p: PubNub.PresenceEvent): void; - signal?(s: PubNub.SignalEvent): void; - objects?(o: PubNub.ObjectsEvent): void; - messageAction?(ma: PubNub.MessageActionEvent): void; - file?(f: PubNub.FileEvent): void; - status?(s: PubNub.StatusEvent): void; -}; - -type Event = - | PubNub.MessageEvent - | PubNub.PresenceEvent - | PubNub.SignalEvent - | PubNub.ObjectsEvent - | PubNub.MessageActionEvent - | PubNub.FileEvent; diff --git a/src/errors/pubnub-api-error.ts b/src/errors/pubnub-api-error.ts new file mode 100644 index 000000000..793deb1bb --- /dev/null +++ b/src/errors/pubnub-api-error.ts @@ -0,0 +1,194 @@ +/** + * REST API endpoint use error module. + */ + +import { TransportResponse } from '../core/types/transport-response'; +import RequestOperation from '../core/constants/operations'; +import StatusCategory from '../core/constants/categories'; +import { Payload, Status } from '../core/types/api'; +import { PubNubError } from './pubnub-error'; + +/** + * PubNub REST API call error. + */ +export class PubNubAPIError extends Error { + /** + * Construct API from known error object or {@link PubNub} service error response. + * + * @param errorOrResponse - `Error` or service error response object from which error information + * should be extracted. + * @param data - Preprocessed service error response. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + static create(errorOrResponse: Error | TransportResponse, data?: ArrayBuffer): PubNubAPIError { + if (errorOrResponse instanceof Error) return PubNubAPIError.createFromError(errorOrResponse); + else return PubNubAPIError.createFromServiceResponse(errorOrResponse, data); + } + + /** + * Create API error instance from other error object. + * + * @param error - `Error` object provided by network provider (mostly) or other {@link PubNub} client components. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + private static createFromError(error: unknown): PubNubAPIError { + let category: StatusCategory = StatusCategory.PNUnknownCategory; + let message = 'Unknown error'; + let errorName = 'Error'; + + if (!error) return new PubNubAPIError(message, category, 0); + else if (error instanceof PubNubAPIError) return error; + + if (error instanceof Error) { + message = error.message; + errorName = error.name; + } + + if (errorName === 'AbortError' || message.indexOf('Aborted') !== -1) { + category = StatusCategory.PNCancelledCategory; + message = 'Request cancelled'; + } else if (message.indexOf('timeout') !== -1) { + category = StatusCategory.PNTimeoutCategory; + message = 'Request timeout'; + } else if (message.indexOf('network') !== -1) { + category = StatusCategory.PNNetworkIssuesCategory; + message = 'Network issues'; + } else if (errorName === 'TypeError') { + category = StatusCategory.PNBadRequestCategory; + } else if (errorName === 'FetchError') { + const errorCode = (error as Record).code; + + if (['ECONNREFUSED', 'ENETUNREACH', 'ENOTFOUND', 'ECONNRESET', 'EAI_AGAIN'].includes(errorCode)) + category = StatusCategory.PNNetworkIssuesCategory; + if (errorCode === 'ECONNREFUSED') message = 'Connection refused'; + else if (errorCode === 'ENETUNREACH') message = 'Network not reachable'; + else if (errorCode === 'ENOTFOUND') message = 'Server not found'; + else if (errorCode === 'ECONNRESET') message = 'Connection reset by peer'; + else if (errorCode === 'EAI_AGAIN') message = 'Name resolution error'; + else if (errorCode === 'ETIMEDOUT') { + category = StatusCategory.PNTimeoutCategory; + message = 'Request timeout'; + } else message = `Unknown system error: ${error}`; + } else if (message === 'Request timeout') category = StatusCategory.PNTimeoutCategory; + + return new PubNubAPIError(message, category, 0, error as Error); + } + + /** + * Construct API from known {@link PubNub} service error response. + * + * @param response - Service error response object from which error information should be + * extracted. + * @param data - Preprocessed service error response. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + private static createFromServiceResponse(response: TransportResponse, data?: ArrayBuffer): PubNubAPIError { + let category: StatusCategory = StatusCategory.PNUnknownCategory; + let errorData: Error | Payload | undefined; + let message = 'Unknown error'; + let { status } = response; + data ??= response.body; + + if (status === 402) message = 'Not available for used key set. Contact support@pubnub.com'; + else if (status === 400) { + category = StatusCategory.PNBadRequestCategory; + message = 'Bad request'; + } else if (status === 403) { + category = StatusCategory.PNAccessDeniedCategory; + message = 'Access denied'; + } + + // Try to get more information about error from service response. + if (data && data.byteLength > 0) { + const decoded = new TextDecoder().decode(data); + + if ( + response.headers['content-type']!.indexOf('text/javascript') !== -1 || + response.headers['content-type']!.indexOf('application/json') !== -1 + ) { + try { + const errorResponse: Payload = JSON.parse(decoded); + + if (typeof errorResponse === 'object' && !Array.isArray(errorResponse)) { + if ( + 'error' in errorResponse && + (errorResponse.error === 1 || errorResponse.error === true) && + 'status' in errorResponse && + typeof errorResponse.status === 'number' && + 'message' in errorResponse && + 'service' in errorResponse + ) { + errorData = errorResponse; + status = errorResponse.status; + } else errorData = errorResponse; + + if ('error' in errorResponse && errorResponse.error instanceof Error) errorData = errorResponse.error; + } + } catch (_) { + errorData = decoded; + } + } else if (response.headers['content-type']!.indexOf('xml') !== -1) { + const reason = /(.*)<\/Message>/gi.exec(decoded); + message = reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.'; + } else { + errorData = decoded; + } + } + + return new PubNubAPIError(message, category, status, errorData); + } + + /** + * Construct PubNub endpoint error. + * + * @param message - Short API call error description. + * @param category - Error category. + * @param statusCode - Response HTTP status code. + * @param errorData - Error information. + */ + constructor( + message: string, + public readonly category: StatusCategory, + public readonly statusCode: number, + public readonly errorData?: Error | Payload, + ) { + super(message); + + this.name = 'PubNubAPIError'; + } + + /** + * Convert API error object to API callback status object. + * + * @param operation - Request operation during which error happened. + * + * @returns Pre-formatted API callback status object. + */ + public toStatus(operation: RequestOperation): Status { + return { + error: true, + category: this.category, + operation, + statusCode: this.statusCode, + errorData: this.errorData, + }; + } + + /** + * Convert API error object to PubNub client error object. + * + * @param operation - Request operation during which error happened. + * @param message - Custom error message. + * + * @returns Client-facing pre-formatted endpoint call error. + */ + public toPubNubError(operation: RequestOperation, message?: string): PubNubError { + return new PubNubError(message ?? this.message, this.toStatus(operation)); + } +} diff --git a/src/errors/pubnub-error.ts b/src/errors/pubnub-error.ts new file mode 100644 index 000000000..435352aa8 --- /dev/null +++ b/src/errors/pubnub-error.ts @@ -0,0 +1,30 @@ +import { Status } from '../core/types/api'; +import StatusCategory from '../core/constants/categories'; + +export class PubNubError extends Error { + constructor( + message: string, + public status?: Status, + ) { + super(message); + this.name = 'PubNubError'; + this.message = message; + + Object.setPrototypeOf(this, new.target.prototype); + } +} + +function createError(errorPayload: { message: string; statusCode?: number }): Status { + errorPayload.statusCode ??= 0; + + return { + ...errorPayload, + statusCode: errorPayload.statusCode!, + category: StatusCategory.PNValidationErrorCategory, + error: true, + }; +} + +export function createValidationError(message: string, statusCode?: number) { + return createError({ message, ...(statusCode !== undefined ? { statusCode } : {}) }); +} diff --git a/src/event-engine/core/handler.ts b/src/event-engine/core/handler.ts index 041eba17b..338a922f9 100644 --- a/src/event-engine/core/handler.ts +++ b/src/event-engine/core/handler.ts @@ -1,7 +1,10 @@ import { AbortSignal } from '../../core/components/abort_signal'; export abstract class Handler { - constructor(protected payload: Payload, protected readonly dependencies: Dependencies) {} + constructor( + protected payload: Payload, + protected readonly dependencies: Dependencies, + ) {} abstract start(): void; abstract cancel(): void; diff --git a/src/event-engine/core/retryPolicy.ts b/src/event-engine/core/retryPolicy.ts index a1692ca75..ebc515ad9 100644 --- a/src/event-engine/core/retryPolicy.ts +++ b/src/event-engine/core/retryPolicy.ts @@ -1,18 +1,24 @@ +import { PubNubError } from '../../errors/pubnub-error'; + export class RetryPolicy { - static LinearRetryPolicy(configuration: LinearRetryPolicyConfiguration) { + static LinearRetryPolicy( + configuration: LinearRetryPolicyConfiguration, + ): RequestRetryPolicy & LinearRetryPolicyConfiguration { return { delay: configuration.delay, maximumRetry: configuration.maximumRetry, + /* eslint-disable @typescript-eslint/no-explicit-any */ shouldRetry(error: any, attempt: number) { if (error?.status?.statusCode === 403) { return false; } return this.maximumRetry > attempt; }, - getDelay(_: number, reason: any) { + getDelay(_, reason) { const delay = reason.retryAfter ?? this.delay; return (delay + Math.random()) * 1000; }, + /* eslint-disable @typescript-eslint/no-explicit-any */ getGiveupReason(error: any, attempt: number) { if (this.maximumRetry <= attempt) { return 'retry attempts exhaused.'; @@ -22,40 +28,94 @@ export class RetryPolicy { } return 'unknown error'; }, + validate() { + if (this.maximumRetry > 10) throw new Error('Maximum retry for linear retry policy can not be more than 10'); + }, }; } - static ExponentialRetryPolicy(configuration: ExponentialRetryPolicyConfiguration) { + static ExponentialRetryPolicy( + configuration: ExponentialRetryPolicyConfiguration, + ): RequestRetryPolicy & ExponentialRetryPolicyConfiguration { return { minimumDelay: configuration.minimumDelay, maximumDelay: configuration.maximumDelay, maximumRetry: configuration.maximumRetry, - shouldRetry(error: any, attempt: number) { - if (error?.status?.statusCode === 403) { + shouldRetry(reason, attempt) { + if (reason?.status?.statusCode === 403) { return false; } return this.maximumRetry > attempt; }, - getDelay(attempt: number, reason: any) { + getDelay(attempt, reason) { const delay = reason.retryAfter ?? Math.min(Math.pow(2, attempt), this.maximumDelay); return (delay + Math.random()) * 1000; }, - getGiveupReason(error: any, attempt: number) { + getGiveupReason(reason, attempt) { if (this.maximumRetry <= attempt) { - return 'retry attempts exhaused.'; + return 'retry attempts exhausted.'; } - if (error?.status?.statusCode === 403) { + if (reason?.status?.statusCode === 403) { return 'forbidden operation.'; } return 'unknown error'; }, + + validate() { + if (this.minimumDelay < 2) throw new Error('Minimum delay can not be set less than 2 seconds for retry'); + else if (this.maximumDelay) throw new Error('Maximum delay can not be set more than 150 seconds for retry'); + else if (this.maximumRetry > 6) + throw new Error('Maximum retry for exponential retry policy can not be more than 6'); + }, }; } } +export type RequestRetryPolicy = { + /** + * Check whether failed request can be retried. + * + * @param reason - Request processing failure reason. + * @param attempt - Number of consequent failure. + * + * @returns `true` if another request retry attempt can be done. + */ + shouldRetry(reason: PubNubError & { retryAfter?: number }, attempt: number): boolean; + + /** + * Computed delay for next request retry attempt. + * + * @param attempt - Number of consequent failure. + * @param reason - Request processing failure reason. + * + * @returns Delay before next request retry attempt in milliseconds. + */ + getDelay(attempt: number, reason: PubNubError & { retryAfter?: number }): number; + + /** + * Identify reason why another retry attempt can't be made. + * + * @param reason - Request processing failure reason. + * @param attempt - Number of consequent failure. + * + * @returns Give up reason. + */ + getGiveupReason(reason: PubNubError & { retryAfter?: number }, attempt: number): string; + + /** + * Validate retry policy parameters. + * + * @throws Error if `minimum` delay is smaller than 2 seconds for `exponential` retry policy. + * @throws Error if `maximum` delay is larger than 150 seconds for `exponential` retry policy. + * @throws Error if `maximumRetry` attempts is larger than 6 for `exponential` retry policy. + * @throws Error if `maximumRetry` attempts is larger than 10 for `linear` retry policy. + */ + validate(): void; +}; + export type LinearRetryPolicyConfiguration = { delay: number; maximumRetry: number; diff --git a/src/event-engine/core/types.ts b/src/event-engine/core/types.ts index e5c6f7f2b..a10f31336 100644 --- a/src/event-engine/core/types.ts +++ b/src/event-engine/core/types.ts @@ -1,7 +1,5 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ -import { State } from './state'; - export type Event = { type: T; payload: P }; export type Invocation = { type: T; payload: P; managed: boolean }; diff --git a/src/event-engine/dispatcher.ts b/src/event-engine/dispatcher.ts index 3054d5ee2..5d9c7c064 100644 --- a/src/event-engine/dispatcher.ts +++ b/src/event-engine/dispatcher.ts @@ -1,21 +1,27 @@ -import { PubNubError } from '../core/components/endpoint'; +import { PrivateClientConfiguration } from '../core/interfaces/configuration'; +import * as Subscription from '../core/types/api/subscription'; +import { PubNubError } from '../errors/pubnub-error'; import { asyncHandler, Dispatcher, Engine } from './core'; import * as effects from './effects'; import * as events from './events'; +import { Payload, StatusEvent } from '../core/types/api'; +import StatusCategory from '../core/constants/categories'; export type Dependencies = { - handshake: any; - receiveMessages: any; - join: any; - leave: any; - leaveAll: any; - presenceState: any; - config: any; + handshake: (parameters: Subscription.CancelableSubscribeParameters) => Promise; + receiveMessages: ( + parameters: Subscription.CancelableSubscribeParameters, + ) => Promise; + join?: (parameters: { channels?: string[]; groups?: string[] }) => void; + leave?: (parameters: { channels?: string[]; groups?: string[] }) => void; + leaveAll?: () => void; + presenceState: Record; + config: PrivateClientConfiguration; delay: (milliseconds: number) => Promise; - emitMessages: (events: any[]) => void; - emitStatus: (status: any) => void; + emitMessages: (events: Subscription.SubscriptionResponse['messages']) => void; + emitStatus: (status: StatusEvent) => void; }; export class EventEngineDispatcher extends Dispatcher { @@ -37,11 +43,8 @@ export class EventEngineDispatcher extends Dispatcher ({ channels, @@ -10,12 +11,15 @@ export const handshake = createManagedEffect('HANDSHAKE', (channels: string[], g export const receiveMessages = createManagedEffect( 'RECEIVE_MESSAGES', - (channels: string[], groups: string[], cursor: Cursor) => ({ channels, groups, cursor }), + (channels: string[], groups: string[], cursor: Subscription.SubscriptionCursor) => ({ channels, groups, cursor }), ); -export const emitMessages = createEffect('EMIT_MESSAGES', (events: any[]) => events); +export const emitMessages = createEffect( + 'EMIT_MESSAGES', + (events: Subscription.SubscriptionResponse['messages']) => events, +); -export const emitStatus = createEffect('EMIT_STATUS', (status: any) => status); +export const emitStatus = createEffect('EMIT_STATUS', (status: StatusEvent) => status); export const receiveReconnect = createManagedEffect( 'RECEIVE_RECONNECT', diff --git a/src/event-engine/events.ts b/src/event-engine/events.ts index c0341d8f0..70fa68b3b 100644 --- a/src/event-engine/events.ts +++ b/src/event-engine/events.ts @@ -1,5 +1,5 @@ -import { PubNubError } from '../core/components/endpoint'; -import { Cursor } from '../models/Cursor'; +import * as Subscription from '../core/types/api/subscription'; +import { PubNubError } from '../errors/pubnub-error'; import { createEvent, MapOf } from './core'; export const subscriptionChange = createEvent('SUBSCRIPTION_CHANGED', (channels: string[], groups: string[]) => ({ @@ -9,7 +9,7 @@ export const subscriptionChange = createEvent('SUBSCRIPTION_CHANGED', (channels: export const restore = createEvent( 'SUBSCRIPTION_RESTORED', - (channels: string[], groups: string[], timetoken: string, region?: number) => ({ + (channels: string[], groups: string[], timetoken: string | number, region?: number) => ({ channels, groups, cursor: { @@ -19,25 +19,34 @@ export const restore = createEvent( }), ); -export const handshakeSuccess = createEvent('HANDSHAKE_SUCCESS', (cursor: Cursor) => cursor); +export const handshakeSuccess = createEvent('HANDSHAKE_SUCCESS', (cursor: Subscription.SubscriptionCursor) => cursor); export const handshakeFailure = createEvent('HANDSHAKE_FAILURE', (error: PubNubError) => error); -export const handshakeReconnectSuccess = createEvent('HANDSHAKE_RECONNECT_SUCCESS', (cursor: Cursor) => ({ - cursor, -})); +export const handshakeReconnectSuccess = createEvent( + 'HANDSHAKE_RECONNECT_SUCCESS', + (cursor: Subscription.SubscriptionCursor) => ({ + cursor, + }), +); export const handshakeReconnectFailure = createEvent('HANDSHAKE_RECONNECT_FAILURE', (error: PubNubError) => error); export const handshakeReconnectGiveup = createEvent('HANDSHAKE_RECONNECT_GIVEUP', (error: PubNubError) => error); -export const receiveSuccess = createEvent('RECEIVE_SUCCESS', (cursor: Cursor, events: any[]) => ({ - cursor, - events, -})); +export const receiveSuccess = createEvent( + 'RECEIVE_SUCCESS', + (cursor: Subscription.SubscriptionCursor, events: Subscription.SubscriptionResponse['messages']) => ({ + cursor, + events, + }), +); export const receiveFailure = createEvent('RECEIVE_FAILURE', (error: PubNubError) => error); -export const receiveReconnectSuccess = createEvent('RECEIVE_RECONNECT_SUCCESS', (cursor: Cursor, events: any[]) => ({ - cursor, - events, -})); +export const receiveReconnectSuccess = createEvent( + 'RECEIVE_RECONNECT_SUCCESS', + (cursor: Subscription.SubscriptionCursor, events: Subscription.SubscriptionResponse['messages']) => ({ + cursor, + events, + }), +); export const receiveReconnectFailure = createEvent('RECEIVE_RECONNECT_FAILURE', (error: PubNubError) => error); export const receiveReconnectGiveup = createEvent('RECEIVING_RECONNECT_GIVEUP', (error: PubNubError) => error); export const disconnect = createEvent('DISCONNECT', () => ({})); diff --git a/src/event-engine/index.ts b/src/event-engine/index.ts index 5e948e769..871d78c7e 100644 --- a/src/event-engine/index.ts +++ b/src/event-engine/index.ts @@ -15,7 +15,7 @@ export class EventEngine { return this.engine; } - private _unsubscribeEngine!: () => void; + private readonly _unsubscribeEngine!: () => void; constructor(dependencies: Dependencies) { this.dependencies = dependencies; @@ -41,11 +41,12 @@ export class EventEngine { }: { channels?: string[]; channelGroups?: string[]; - timetoken?: string; + timetoken?: string | number; withPresence?: boolean; }): void { this.channels = [...this.channels, ...(channels ?? [])]; this.groups = [...this.groups, ...(channelGroups ?? [])]; + if (withPresence) { this.channels.map((c) => this.channels.push(`${c}-pnpres`)); this.groups.map((g) => this.groups.push(`${g}-pnpres`)); @@ -79,6 +80,7 @@ export class EventEngine { ...channels, ...channels.map((c) => `${c}-pnpres`), ]); + const filteredGroups = utils.removeSingleOccurance(this.groups, [ ...channelGroups, ...channelGroups.map((c) => `${c}-pnpres`), @@ -116,7 +118,9 @@ export class EventEngine { this.groups = []; if (this.dependencies.presenceState) { - this.dependencies.presenceState = {}; + Object.keys(this.dependencies.presenceState).forEach((objectName) => { + delete this.dependencies.presenceState[objectName]; + }); } this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0))); if (this.dependencies.leaveAll) { @@ -136,11 +140,11 @@ export class EventEngine { } getSubscribedChannels(): string[] { - return Array.from(new Set(this.channels)); + return Array.from(new Set(this.channels.slice(0))); } getSubscribedChannelGroups(): string[] { - return Array.from(new Set(this.groups)); + return Array.from(new Set(this.groups.slice(0))); } dispose(): void { diff --git a/src/event-engine/presence/dispatcher.ts b/src/event-engine/presence/dispatcher.ts index 39c455362..f2dfa0571 100644 --- a/src/event-engine/presence/dispatcher.ts +++ b/src/event-engine/presence/dispatcher.ts @@ -1,18 +1,26 @@ -import { PubNubError } from '../../core/components/endpoint'; +import { PrivateClientConfiguration } from '../../core/interfaces/configuration'; import { asyncHandler, Dispatcher, Engine } from '../core'; import PNOperations from '../../core/constants/operations'; +import * as Presence from '../../core/types/api/presence'; +import { PubNubError } from '../../errors/pubnub-error'; +import { Payload, ResultCallback } from '../../core/types/api'; import * as effects from './effects'; import * as events from './events'; +import StatusCategory from '../../core/constants/categories'; export type Dependencies = { - heartbeat: any; - leave: any; + heartbeat: ( + parameters: Presence.PresenceHeartbeatParameters, + callback?: ResultCallback, + ) => Promise; + leave: (parameters: Presence.PresenceLeaveParameters) => void; heartbeatDelay: () => Promise; retryDelay: (milliseconds: number) => Promise; - config: any; - presenceState: any; + config: PrivateClientConfiguration; + presenceState: Record; + /* eslint-disable @typescript-eslint/no-explicit-any */ emitStatus: (status: any) => void; }; @@ -28,10 +36,12 @@ export class PresenceEventEngineDispatcher extends Dispatcher { if (!config.suppressLeaveEvents) { try { - const result = await leave({ + leave({ channels: payload.channels, channelGroups: payload.groups, }); @@ -70,21 +80,21 @@ export class PresenceEventEngineDispatcher extends Dispatcher { if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { abortSignal.throwIfAborted(); + await retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); + abortSignal.throwIfAborted(); try { const result = await heartbeat({ channels: payload.channels, channelGroups: payload.groups, ...(config.maintainPresenceState && { state: presenceState }), + heartbeat: config.presenceTimeout!, }); return engine.transition(events.heartbeatSuccess(200)); } catch (e) { - if (e instanceof Error && e.message === 'Aborted') { - return; - } - if (e instanceof PubNubError) { + if (e.status && e.status.category == StatusCategory.PNCancelledCategory) return; return engine.transition(events.heartbeatFailure(e)); } } diff --git a/src/event-engine/presence/effects.ts b/src/event-engine/presence/effects.ts index e60579f5f..0eddde4d5 100644 --- a/src/event-engine/presence/effects.ts +++ b/src/event-engine/presence/effects.ts @@ -1,5 +1,6 @@ import { createEffect, createManagedEffect, MapOf } from '../core'; import { HeartbeatReconnectingStateContext } from './states/heartbeat_reconnecting'; +import { Status } from '../../core/types/api'; export const heartbeat = createEffect('HEARTBEAT', (channels: string[], groups: string[]) => ({ channels, @@ -11,6 +12,7 @@ export const leave = createEffect('LEAVE', (channels: string[], groups: string[] groups, })); +/* eslint-disable @typescript-eslint/no-explicit-any */ export const emitStatus = createEffect('EMIT_STATUS', (status: any) => status); export const wait = createManagedEffect('WAIT', () => ({})); diff --git a/src/event-engine/presence/events.ts b/src/event-engine/presence/events.ts index d25642967..9607a44d7 100644 --- a/src/event-engine/presence/events.ts +++ b/src/event-engine/presence/events.ts @@ -1,4 +1,4 @@ -import { PubNubError } from '../../core/components/endpoint'; +import { PubNubError } from '../../errors/pubnub-error'; import { createEvent, MapOf } from '../core'; export const reconnect = createEvent('RECONNECT', () => ({})); diff --git a/src/event-engine/presence/presence.ts b/src/event-engine/presence/presence.ts index 05cb03500..768fbed1e 100644 --- a/src/event-engine/presence/presence.ts +++ b/src/event-engine/presence/presence.ts @@ -8,7 +8,6 @@ import { HeartbeatInactiveState } from './states/heartbeat_inactive'; export class PresenceEventEngine { private engine: Engine = new Engine(); private dispatcher: Dispatcher; - private dependencies: any; get _engine() { return this.engine; @@ -16,9 +15,8 @@ export class PresenceEventEngine { private _unsubscribeEngine!: () => void; - constructor(dependencies: Dependencies) { + constructor(private dependencies: Dependencies) { this.dispatcher = new PresenceEventEngineDispatcher(this.engine, dependencies); - this.dependencies = dependencies; this._unsubscribeEngine = this.engine.subscribe((change) => { if (change.type === 'invocationDispatched') { diff --git a/src/event-engine/presence/states/heartbeat_reconnecting.ts b/src/event-engine/presence/states/heartbeat_reconnecting.ts index 099a05e4d..a665004ab 100644 --- a/src/event-engine/presence/states/heartbeat_reconnecting.ts +++ b/src/event-engine/presence/states/heartbeat_reconnecting.ts @@ -1,5 +1,5 @@ +import { PubNubError } from '../../../errors/pubnub-error'; import { State } from '../../core/state'; -import { PubNubError } from '../../../core/components/endpoint'; import { Events, disconnect, diff --git a/src/event-engine/states/handshake_failed.ts b/src/event-engine/states/handshake_failed.ts index dd86cd552..7b86933a4 100644 --- a/src/event-engine/states/handshake_failed.ts +++ b/src/event-engine/states/handshake_failed.ts @@ -1,15 +1,15 @@ import { State } from '../core/state'; import { Effects } from '../effects'; import { Events, reconnect, restore, subscriptionChange, unsubscribeAll } from '../events'; -import { PubNubError } from '../../core/components/endpoint'; +import { PubNubError } from '../../errors/pubnub-error'; import { HandshakingState } from './handshaking'; import { UnsubscribedState } from './unsubscribed'; -import { Cursor } from '../../models/Cursor'; +import * as Subscription from '../../core/types/api/subscription'; export type HandshakeFailedStateContext = { channels: string[]; groups: string[]; - cursor?: Cursor; + cursor?: Subscription.SubscriptionCursor; reason: PubNubError; }; diff --git a/src/event-engine/states/handshake_reconnecting.ts b/src/event-engine/states/handshake_reconnecting.ts index 75a2fe6d3..6c82a348d 100644 --- a/src/event-engine/states/handshake_reconnecting.ts +++ b/src/event-engine/states/handshake_reconnecting.ts @@ -1,4 +1,4 @@ -import { PubNubError } from '../../core/components/endpoint'; +import { PubNubError } from '../../errors/pubnub-error'; import { State } from '../core/state'; import { Effects, emitStatus, handshakeReconnect } from '../effects'; import { @@ -17,12 +17,12 @@ import { HandshakingState } from './handshaking'; import { ReceivingState } from './receiving'; import { UnsubscribedState } from './unsubscribed'; import categoryConstants from '../../core/constants/categories'; -import { Cursor } from '../../models/Cursor'; +import * as Subscription from '../../core/types/api/subscription'; export type HandshakeReconnectingStateContext = { channels: string[]; groups: string[]; - cursor?: Cursor; + cursor?: Subscription.SubscriptionCursor; attempts: number; reason: PubNubError; diff --git a/src/event-engine/states/handshake_stopped.ts b/src/event-engine/states/handshake_stopped.ts index 133451f93..e7040c417 100644 --- a/src/event-engine/states/handshake_stopped.ts +++ b/src/event-engine/states/handshake_stopped.ts @@ -1,14 +1,14 @@ -import { Cursor } from '../../models/Cursor'; import { State } from '../core/state'; import { Effects } from '../effects'; import { Events, reconnect, restore, subscriptionChange, unsubscribeAll } from '../events'; import { HandshakingState } from './handshaking'; import { UnsubscribedState } from './unsubscribed'; +import * as Subscription from '../../core/types/api/subscription'; type HandshakeStoppedStateContext = { channels: string[]; groups: string[]; - cursor?: Cursor; + cursor?: Subscription.SubscriptionCursor; }; export const HandshakeStoppedState = new State('HANDSHAKE_STOPPED'); diff --git a/src/event-engine/states/handshaking.ts b/src/event-engine/states/handshaking.ts index 14ea66adc..c2dcdb7b5 100644 --- a/src/event-engine/states/handshaking.ts +++ b/src/event-engine/states/handshaking.ts @@ -14,12 +14,12 @@ import { HandshakeStoppedState } from './handshake_stopped'; import { ReceivingState } from './receiving'; import { UnsubscribedState } from './unsubscribed'; import categoryConstants from '../../core/constants/categories'; -import { Cursor } from '../../models/Cursor'; +import * as Subscription from '../../core/types/api/subscription'; export type HandshakingStateContext = { channels: string[]; groups: string[]; - cursor?: Cursor; + cursor?: Subscription.SubscriptionCursor; }; export const HandshakingState = new State('HANDSHAKING'); diff --git a/src/event-engine/states/receive_failed.ts b/src/event-engine/states/receive_failed.ts index 91de8e787..5b3db90be 100644 --- a/src/event-engine/states/receive_failed.ts +++ b/src/event-engine/states/receive_failed.ts @@ -1,15 +1,15 @@ import { State } from '../core/state'; -import { Cursor } from '../../models/Cursor'; import { Effects } from '../effects'; import { Events, reconnect, restore, subscriptionChange, unsubscribeAll } from '../events'; -import { PubNubError } from '../../core/components/endpoint'; +import { PubNubError } from '../../errors/pubnub-error'; import { HandshakingState } from './handshaking'; import { UnsubscribedState } from './unsubscribed'; +import * as Subscription from '../../core/types/api/subscription'; export type ReceiveFailedStateContext = { channels: string[]; groups: string[]; - cursor: Cursor; + cursor: Subscription.SubscriptionCursor; reason: PubNubError; }; diff --git a/src/event-engine/states/receive_reconnecting.ts b/src/event-engine/states/receive_reconnecting.ts index 69b550558..133a44bfe 100644 --- a/src/event-engine/states/receive_reconnecting.ts +++ b/src/event-engine/states/receive_reconnecting.ts @@ -1,5 +1,4 @@ -import { PubNubError } from '../../core/components/endpoint'; -import { Cursor } from '../../models/Cursor'; +import { PubNubError } from '../../errors/pubnub-error'; import { State } from '../core/state'; import { Effects, emitMessages, receiveReconnect, emitStatus } from '../effects'; import { @@ -17,11 +16,12 @@ import { ReceiveFailedState } from './receive_failed'; import { ReceiveStoppedState } from './receive_stopped'; import { UnsubscribedState } from './unsubscribed'; import categoryConstants from '../../core/constants/categories'; +import * as Subscription from '../../core/types/api/subscription'; export type ReceiveReconnectingStateContext = { channels: string[]; groups: string[]; - cursor: Cursor; + cursor: Subscription.SubscriptionCursor; attempts: number; reason: PubNubError; diff --git a/src/event-engine/states/receive_stopped.ts b/src/event-engine/states/receive_stopped.ts index 20993b80f..49027d275 100644 --- a/src/event-engine/states/receive_stopped.ts +++ b/src/event-engine/states/receive_stopped.ts @@ -1,14 +1,14 @@ -import { Cursor } from '../../models/Cursor'; import { State } from '../core/state'; import { Effects } from '../effects'; import { Events, reconnect, restore, subscriptionChange, unsubscribeAll } from '../events'; import { HandshakingState } from './handshaking'; import { UnsubscribedState } from './unsubscribed'; +import * as Subscription from '../../core/types/api/subscription'; type ReceiveStoppedStateContext = { channels: string[]; groups: string[]; - cursor: Cursor; + cursor: Subscription.SubscriptionCursor; }; export const ReceiveStoppedState = new State('RECEIVE_STOPPED'); diff --git a/src/event-engine/states/receiving.ts b/src/event-engine/states/receiving.ts index e7789debc..7219f0bf3 100644 --- a/src/event-engine/states/receiving.ts +++ b/src/event-engine/states/receiving.ts @@ -1,5 +1,4 @@ import { State } from '../core/state'; -import { Cursor } from '../../models/Cursor'; import { Effects, emitMessages, emitStatus, receiveMessages } from '../effects'; import { disconnect, @@ -14,11 +13,12 @@ import { UnsubscribedState } from './unsubscribed'; import { ReceiveReconnectingState } from './receive_reconnecting'; import { ReceiveStoppedState } from './receive_stopped'; import categoryConstants from '../../core/constants/categories'; +import * as Subscription from '../../core/types/api/subscription'; export type ReceivingStateContext = { channels: string[]; groups: string[]; - cursor: Cursor; + cursor: Subscription.SubscriptionCursor; }; export const ReceivingState = new State('RECEIVING'); diff --git a/src/file/index.js b/src/file/index.js deleted file mode 100644 index 0975b9062..000000000 --- a/src/file/index.js +++ /dev/null @@ -1 +0,0 @@ -/** */ diff --git a/src/file/modules/node.js b/src/file/modules/node.js deleted file mode 100644 index 9b51c6e27..000000000 --- a/src/file/modules/node.js +++ /dev/null @@ -1,136 +0,0 @@ -import { Readable, PassThrough } from 'stream'; -import fs from 'fs'; -import { basename } from 'path'; - -const PubNubFile = class PubNubFile { - static supportsBlob = false; - - static supportsFile = false; - - static supportsBuffer = typeof Buffer !== 'undefined'; - - static supportsStream = true; - - static supportsString = true; - - static supportsArrayBuffer = false; - - static supportsEncryptFile = true; - - static supportsFileUri = false; - - data; - - name; - - mimeType; - - contentLength; - - static create(config) { - return new this(config); - } - - constructor({ stream, data, encoding, name, mimeType }) { - if (stream instanceof Readable) { - this.data = stream; - - if (stream instanceof fs.ReadStream) { - // $FlowFixMe: incomplete flow node definitions - this.name = basename(stream.path); - this.contentLength = fs.statSync(stream.path).size; - } - } else if (data instanceof Buffer) { - this.data = Buffer.from(data); - } else if (typeof data === 'string') { - // $FlowFixMe: incomplete flow node definitions - this.data = Buffer.from(data, encoding ?? 'utf8'); - } - - if (name) { - this.name = basename(name); - } - - if (mimeType) { - this.mimeType = mimeType; - } - - if (this.data === undefined) { - throw new Error("Couldn't construct a file out of supplied options."); - } - - if (this.name === undefined) { - throw new Error("Couldn't guess filename out of the options. Please provide one."); - } - } - - toBuffer() { - if (this.data instanceof Buffer) { - return Promise.resolve(Buffer.from(this.data)); - } - - if (this.data instanceof Readable) { - const stream = this.data; - return new Promise((resolve, reject) => { - const chunks = []; - - stream.on('data', (chunk) => chunks.push(chunk)); - stream.once('error', reject); - stream.once('end', () => { - resolve(Buffer.concat(chunks)); - }); - }); - } - - if (typeof this.data === 'string') { - return Promise.resolve(Buffer.from(this.data)); - } - - throw new Error("Can't cast to 'buffer'."); - } - - async toArrayBuffer() { - throw new Error('This feature is only supported in browser environments.'); - } - - async toString(encoding = 'utf8') { - const buffer = await this.toBuffer(); - - return buffer.toString(encoding); - } - - async toStream() { - if (!(this.data instanceof Readable)) { - const input = this.data; - - return new Readable({ - read() { - this.push(Buffer.from(input)); - this.push(null); - }, - }); - } - - const stream = new PassThrough(); - - if (this.data instanceof Readable) { - this.data.pipe(stream); - } - - return stream; - } - - async toFile() { - throw new Error('This feature is only supported in browser environments.'); - } - - async toFileUri() { - throw new Error('This feature is only supported in react native environments.'); - } - - async toBlob() { - throw new Error('This feature is only supported in browser environments.'); - } -}; - -export default PubNubFile; diff --git a/src/file/modules/node.ts b/src/file/modules/node.ts new file mode 100644 index 000000000..ae2fde560 --- /dev/null +++ b/src/file/modules/node.ts @@ -0,0 +1,257 @@ +/** + * Node.js {@link PubNub} File object module. + */ + +import { Readable, PassThrough } from 'stream'; +import { Buffer } from 'buffer'; +import { basename } from 'path'; +import fs from 'fs'; + +import { PubNubFileInterface } from '../../core/types/file'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- + +// region Types +/** + * PubNub File instance creation parameters. + */ +export type PubNubFileParameters = { + /** + * Readable stream represents file object content. + */ + stream?: Readable; + + /** + * Buffer or string represents file object content. + */ + data?: Buffer | ArrayBuffer | string; + + /** + * String {@link PubNubFileParameters#data|data} encoding. + * + * @default `utf8` + */ + encoding?: StringEncoding; + + /** + * File object name. + */ + name: string; + + /** + * File object content type. + */ + mimeType?: string; +}; +// endregion + +/** + * Node.js implementation for {@link PubNub} File object. + * + * **Important:** Class should implement constructor and class fields from {@link PubNubFileConstructor}. + */ +export default class PubNubFile implements PubNubFileInterface { + // region Class properties + /** + * Whether {@link Blob} data supported by platform or not. + */ + static supportsBlob = false; + + /** + * Whether {@link File} data supported by platform or not. + */ + static supportsFile = false; + + /** + * Whether {@link Buffer} data supported by platform or not. + */ + static supportsBuffer = true; + + /** + * Whether {@link Stream} data supported by platform or not. + */ + static supportsStream = true; + + /** + * Whether {@link String} data supported by platform or not. + */ + static supportsString = true; + + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + static supportsArrayBuffer = true; + + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + static supportsEncryptFile = true; + + /** + * Whether `File Uri` data supported by platform or not. + */ + static supportsFileUri = false; + // endregion + + // region Instance properties + /** + * File object content source. + */ + readonly data: Readable | Buffer; + + /** + * File object content length. + */ + contentLength?: number; + + /** + * File object content type. + */ + mimeType: string; + + /** + * File object name. + */ + name: string; + // endregion + + static create(file: PubNubFileParameters) { + return new PubNubFile(file); + } + + constructor(file: PubNubFileParameters) { + const { stream, data, encoding, name, mimeType } = file; + let fileData: Readable | Buffer | undefined; + let contentLength: number | undefined; + let fileMimeType: string | undefined; + let fileName: string | undefined; + + if (stream && stream instanceof Readable) { + fileData = stream; + + if (stream instanceof fs.ReadStream) { + const streamFilePath = stream.path instanceof Buffer ? new TextDecoder().decode(stream.path) : stream.path; + fileName = basename(streamFilePath); + contentLength = fs.statSync(streamFilePath).size; + } + } else if (data instanceof Buffer) { + contentLength = data.length; + // Copy content of the source Buffer. + fileData = Buffer.alloc(contentLength!); + data.copy(fileData); + } else if (data instanceof ArrayBuffer) { + contentLength = data.byteLength; + fileData = Buffer.from(data); + } else if (typeof data === 'string') { + fileData = Buffer.from(data, encoding ?? 'utf8'); + contentLength = fileData.length; + } + + if (contentLength) this.contentLength = contentLength; + if (mimeType) fileMimeType = mimeType; + else fileMimeType = 'application/octet-stream'; + if (name) fileName = basename(name); + + if (fileData === undefined) throw new Error("Couldn't construct a file out of supplied options."); + if (fileName === undefined) throw new Error("Couldn't guess filename out of the options. Please provide one."); + + this.mimeType = fileMimeType; + this.data = fileData; + this.name = fileName; + } + + /** + * Convert {@link PubNub} File object content to {@link Buffer}. + * + * @returns Asynchronous results of conversion to the {@link Buffer}. + */ + async toBuffer(): Promise { + if (this.data instanceof Buffer) return this.data; + + const stream = this.data; + return new Promise((resolve, reject) => { + const chunks: Uint8Array[] = []; + + stream.on('data', (chunk) => { + chunks.push(chunk); + }); + stream.on('end', () => { + resolve(Buffer.concat(chunks)); + }); + + // Handle any errors during streaming + stream.on('error', (error) => reject(error)); + }); + } + + /** + * Convert {@link PubNub} File object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + */ + async toArrayBuffer(): Promise { + return this.toBuffer().then((buffer) => buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.length)); + } + + /** + * Convert {@link PubNub} File object content to {@link string}. + * + * @returns Asynchronous results of conversion to the {@link string}. + */ + async toString(encoding: BufferEncoding = 'utf8'): Promise { + return this.toBuffer().then((buffer) => buffer.toString(encoding)); + } + + /** + * Convert {@link PubNub} File object content to {@link Readable} stream. + * + * @returns Asynchronous results of conversion to the {@link Readable} stream. + */ + async toStream() { + if (this.data instanceof Readable) { + const stream = new PassThrough(); + this.data.pipe(stream); + + return stream; + } + + return this.toBuffer().then( + (buffer) => + new Readable({ + read() { + this.push(buffer); + this.push(null); + }, + }), + ); + } + + /** + * Convert {@link PubNub} File object content to {@link File}. + * + * @throws Error because {@link File} not available in Node.js environment. + */ + async toFile() { + throw new Error('This feature is only supported in browser environments.'); + } + + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @throws Error because file `Uri` not available in Node.js environment. + */ + async toFileUri(): Promise> { + throw new Error('This feature is only supported in React Native environments.'); + } + + /** + * Convert {@link PubNub} File object content to {@link Blob}. + * + * @throws Error because {@link Blob} not available in Node.js environment. + */ + async toBlob() { + throw new Error('This feature is only supported in browser environments.'); + } +} diff --git a/src/file/modules/react-native.js b/src/file/modules/react-native.js deleted file mode 100644 index 4d9921862..000000000 --- a/src/file/modules/react-native.js +++ /dev/null @@ -1,167 +0,0 @@ -/* global File, FileReader */ - -import { IFile, FileClass } from '..'; - -const PubNubFile = class PubNubFile { - static supportsFile = typeof File !== 'undefined'; - - static supportsBlob = typeof Blob !== 'undefined'; - - static supportsArrayBuffer = typeof ArrayBuffer !== 'undefined'; - - static supportsBuffer = false; - - static supportsStream = false; - - static supportsString = true; - - static supportsEncryptFile = false; - - static supportsFileUri = true; - - static create(config) { - return new this(config); - } - - data; - - name; - - mimeType; - - constructor(config) { - if (config instanceof File) { - this.data = config; - - this.name = this.data.name; - this.mimeType = this.data.type; - } else if (config.uri) { - // uri upload for react native - this.data = { - uri: config.uri, - name: config.name, - type: config.mimeType, - }; - - this.name = config.name; - - if (config.mimeType) { - this.mimeType = config.mimeType; - } - } else if (config.data) { - this.data = config.data; - this.name = config.name; - - if (config.mimeType) { - this.mimeType = config.mimeType; - } - } else { - throw new Error("Couldn't construct a file out of supplied options. URI or file data required."); - } - - if (this.data === undefined) { - throw new Error("Couldn't construct a file out of supplied options."); - } - - if (this.name === undefined) { - throw new Error("Couldn't guess filename out of the options. Please provide one."); - } - } - - async toBuffer() { - throw new Error('This feature is only supported in Node.js environments.'); - } - - async toStream() { - throw new Error('This feature is only supported in Node.js environments.'); - } - - async toBlob() { - if (this.data && this.data.uri) { - throw new Error('This file contains a file URI and does not contain the file contents.'); - } else if (this.data instanceof File) { - return this.data; - } else { - // data must be a fetch response - return this.data.blob(); - } - } - - async toArrayBuffer() { - if (this.data && this.data.uri) { - throw new Error('This file contains a file URI and does not contain the file contents.'); - } else if (this.data instanceof File) { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - - reader.addEventListener('load', () => { - if (reader.result instanceof ArrayBuffer) { - return resolve(reader.result); - } - }); - - reader.addEventListener('error', () => { - reject(reader.error); - }); - - reader.readAsArrayBuffer(this.data); - }); - } else { - // data must be a fetch response - let result; - - try { - result = await this.data.arrayBuffer(); - } catch (e) { - throw new Error(`Unable to support toArrayBuffer in ReactNative environment: ${e}`); - } - - return result; - } - } - - async toString() { - if (this.data && this.data.uri) { - return JSON.stringify(this.data); - } - if (this.data instanceof File) { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - - reader.addEventListener('load', () => { - if (typeof reader.result === 'string') { - return resolve(reader.result); - } - }); - - reader.addEventListener('error', () => { - reject(reader.error); - }); - - reader.readAsBinaryString(this.data); - }); - } - // data must be a fetch response - return this.data.text(); - } - - async toFile() { - if (this.data.uri) { - throw new Error('This file contains a file URI and does not contain the file contents.'); - } else if (this.data instanceof File) { - return this.data; - } else { - // data must be a fetch response - return this.data.blob(); - } - } - - async toFileUri() { - if (this.data && this.data.uri) { - return this.data; - } - throw new Error('This file does not contain a file URI'); - } -}; - -export default PubNubFile; diff --git a/src/file/modules/react-native.ts b/src/file/modules/react-native.ts new file mode 100644 index 000000000..7c036a76e --- /dev/null +++ b/src/file/modules/react-native.ts @@ -0,0 +1,265 @@ +/* global File, FileReader */ +/** + * React Native {@link PubNub} File object module. + */ + +import { PubNubFileInterface } from '../../core/types/file'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- + +// region Types +/** + * File path-based file. + */ +type FileUri = { uri: string; name: string; mimeType?: string }; + +/** + * Asynchronously fetched file content. + */ +type ReadableFile = { arrayBuffer: () => Promise; blob: () => Promise; text: () => Promise }; + +/** + * PubNub File instance creation parameters. + */ +export type PubNubFileParameters = + | File + | FileUri + | ReadableFile + | { data: string | Blob | ArrayBuffer | ArrayBufferView; name: string; mimeType?: string }; +// endregion + +export class PubNubFile implements PubNubFileInterface { + // region Class properties + /** + * Whether {@link Blob} data supported by platform or not. + */ + static supportsBlob = typeof Blob !== 'undefined'; + + /** + * Whether {@link File} data supported by platform or not. + */ + static supportsFile = typeof File !== 'undefined'; + + /** + * Whether {@link Buffer} data supported by platform or not. + */ + static supportsBuffer = false; + + /** + * Whether {@link Stream} data supported by platform or not. + */ + static supportsStream = false; + + /** + * Whether {@link String} data supported by platform or not. + */ + static supportsString = true; + + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + static supportsArrayBuffer = true; + + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + static supportsEncryptFile = false; + + /** + * Whether `File Uri` data supported by platform or not. + */ + static supportsFileUri = true; + // endregion + + // region Instance properties + /** + * File object content source. + */ + readonly data: File | FileUri | ReadableFile; + + /** + * File object content length. + */ + contentLength?: number; + + /** + * File object content type. + */ + mimeType: string; + + /** + * File object name. + */ + name: string; + // endregion + + static create(file: PubNubFileParameters) { + return new PubNubFile(file); + } + + constructor(file: PubNubFileParameters) { + let fileData: PubNubFile['data'] | undefined; + let contentLength: number | undefined; + let fileMimeType: string | undefined; + let fileName: string | undefined; + + if (file instanceof File) { + fileData = file; + + fileName = file.name; + fileMimeType = file.type; + contentLength = file.size; + } else if ('data' in file) { + const contents = file.data; + + fileMimeType = file.mimeType; + fileName = file.name; + fileData = new File([contents], fileName, { type: fileMimeType }); + contentLength = fileData.size; + } else if ('uri' in file) { + fileMimeType = file.mimeType; + fileName = file.name; + fileData = { + uri: file.uri, + name: file.name, + type: file.mimeType!, + }; + } else throw new Error("Couldn't construct a file out of supplied options. URI or file data required."); + + if (fileData === undefined) throw new Error("Couldn't construct a file out of supplied options."); + if (fileName === undefined) throw new Error("Couldn't guess filename out of the options. Please provide one."); + + if (contentLength) this.contentLength = contentLength; + this.mimeType = fileMimeType!; + this.data = fileData; + this.name = fileName; + } + + /** + * Convert {@link PubNub} File object content to {@link Buffer}. + * + * @throws Error because {@link Buffer} not available in React Native environment. + */ + async toBuffer() { + throw new Error('This feature is only supported in Node.js environments.'); + } + + /** + * Convert {@link PubNub} File object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + async toArrayBuffer(): Promise { + if (this.data && this.data instanceof File) { + const data = this.data; + + return new Promise((resolve, reject) => { + const reader = new FileReader(); + + reader.addEventListener('load', () => { + if (reader.result instanceof ArrayBuffer) return resolve(reader.result); + }); + reader.addEventListener('error', () => reject(reader.error)); + reader.readAsArrayBuffer(data); + }); + } else if (this.data && 'uri' in this.data) { + throw new Error('This file contains a file URI and does not contain the file contents.'); + } else if (this.data) { + let result: ArrayBuffer | undefined; + + try { + result = await this.data.arrayBuffer(); + } catch (error) { + throw new Error(`Unable to support toArrayBuffer in ReactNative environment: ${error}`); + } + + return result; + } + + throw new Error('Unable convert provided file content type to ArrayBuffer'); + } + + /** + * Convert {@link PubNub} File object content to {@link string}. + * + * @returns Asynchronous results of conversion to the {@link string}. + */ + async toString(): Promise { + if (this.data && 'uri' in this.data) return JSON.stringify(this.data); + else if (this.data && this.data instanceof File) { + const data = this.data; + + return new Promise((resolve, reject) => { + const reader = new FileReader(); + + reader.addEventListener('load', () => { + if (typeof reader.result === 'string') return resolve(reader.result); + }); + reader.addEventListener('error', () => reject(reader.error)); + reader.readAsBinaryString(data); + }); + } + + return this.data.text(); + } + + /** + * Convert {@link PubNub} File object content to {@link Readable} stream. + * + * @throws Error because {@link Readable} stream not available in React Native environment. + */ + async toStream() { + throw new Error('This feature is only supported in Node.js environments.'); + } + + /** + * Convert {@link PubNub} File object content to {@link File}. + * + * @returns Asynchronous results of conversion to the {@link File}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + async toFile() { + if (this.data instanceof File) return this.data; + else if ('uri' in this.data) + throw new Error('This file contains a file URI and does not contain the file contents.'); + else return this.data.blob(); + } + + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @returns Asynchronous results of conversion to file `Uri`. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + async toFileUri() { + if (this.data && 'uri' in this.data) return this.data; + + throw new Error('This file does not contain a file URI'); + } + + /** + * Convert {@link PubNub} File object content to {@link Blob}. + * + * @returns Asynchronous results of conversion to the {@link Blob}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + async toBlob() { + if (this.data instanceof File) return this.data; + else if (this.data && 'uri' in this.data) + throw new Error('This file contains a file URI and does not contain the file contents.'); + else return this.data.blob(); + } +} + +export default PubNubFile; diff --git a/src/file/modules/web.js b/src/file/modules/web.js deleted file mode 100644 index 0f741a619..000000000 --- a/src/file/modules/web.js +++ /dev/null @@ -1,116 +0,0 @@ -/* global File, FileReader */ - -import { IFile, FileClass } from '..'; - -const PubNubFile = class PubNubFile { - static supportsFile = typeof File !== 'undefined'; - - static supportsBlob = typeof Blob !== 'undefined'; - - static supportsArrayBuffer = typeof ArrayBuffer !== 'undefined'; - - static supportsBuffer = false; - - static supportsStream = false; - - static supportsString = true; - - static supportsEncryptFile = true; - - static supportsFileUri = false; - - static create(config) { - return new this(config); - } - - data; - - name; - - mimeType; - - constructor(config) { - if (config instanceof File) { - this.data = config; - - this.name = this.data.name; - this.mimeType = this.data.type; - } else if (config.data) { - const contents = config.data; - - this.data = new File([contents], config.name, { type: config.mimeType }); - - this.name = config.name; - - if (config.mimeType) { - this.mimeType = config.mimeType; - } - } - - if (this.data === undefined) { - throw new Error("Couldn't construct a file out of supplied options."); - } - - if (this.name === undefined) { - throw new Error("Couldn't guess filename out of the options. Please provide one."); - } - } - - async toBuffer() { - throw new Error('This feature is only supported in Node.js environments.'); - } - - async toStream() { - throw new Error('This feature is only supported in Node.js environments.'); - } - - async toFileUri() { - throw new Error('This feature is only supported in react native environments.'); - } - - async toBlob() { - return this.data; - } - - async toArrayBuffer() { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - - reader.addEventListener('load', () => { - if (reader.result instanceof ArrayBuffer) { - return resolve(reader.result); - } - }); - - reader.addEventListener('error', () => { - reject(reader.error); - }); - - reader.readAsArrayBuffer(this.data); - }); - } - - async toString() { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - - reader.addEventListener('load', () => { - if (typeof reader.result === 'string') { - return resolve(reader.result); - } - }); - - reader.addEventListener('error', () => { - reject(reader.error); - }); - - reader.readAsBinaryString(this.data); - }); - } - - async toFile() { - return this.data; - } -}; - -export default PubNubFile; diff --git a/src/file/modules/web.ts b/src/file/modules/web.ts new file mode 100644 index 000000000..b3a5e13ed --- /dev/null +++ b/src/file/modules/web.ts @@ -0,0 +1,209 @@ +/* global File, FileReader */ +/** + * Browser {@link PubNub} File object module. + */ + +import { PubNubFileInterface } from '../../core/types/file'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- + +// region Types +/** + * PubNub File instance creation parameters. + */ +export type PubNubFileParameters = + | File + | { data: string | Blob | ArrayBuffer | ArrayBufferView; name: string; mimeType?: string }; +// endregion + +/** + * Web implementation for {@link PubNub} File object. + * + * **Important:** Class should implement constructor and class fields from {@link PubNubFileConstructor}. + */ +export class PubNubFile implements PubNubFileInterface { + // region Class properties + /** + * Whether {@link Blob} data supported by platform or not. + */ + static supportsBlob = typeof Blob !== 'undefined'; + + /** + * Whether {@link File} data supported by platform or not. + */ + static supportsFile = typeof File !== 'undefined'; + + /** + * Whether {@link Buffer} data supported by platform or not. + */ + static supportsBuffer = false; + + /** + * Whether {@link Stream} data supported by platform or not. + */ + static supportsStream = false; + + /** + * Whether {@link String} data supported by platform or not. + */ + static supportsString = true; + + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + static supportsArrayBuffer = true; + + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + static supportsEncryptFile = true; + + /** + * Whether `File Uri` data supported by platform or not. + */ + static supportsFileUri = false; + // endregion + + // region Instance properties + /** + * File object content source. + */ + readonly data: File; + + /** + * File object content length. + */ + contentLength?: number; + + /** + * File object content type. + */ + mimeType: string; + + /** + * File object name. + */ + name: string; + // endregion + + static create(file: PubNubFileParameters) { + return new PubNubFile(file); + } + + constructor(file: PubNubFileParameters) { + let contentLength: number | undefined; + let fileMimeType: string | undefined; + let fileName: string | undefined; + let fileData: File | undefined; + + if (file instanceof File) { + fileData = file; + + fileName = file.name; + fileMimeType = file.type; + contentLength = file.size; + } else if ('data' in file) { + const contents = file.data; + + fileMimeType = file.mimeType; + fileName = file.name; + fileData = new File([contents], fileName, { type: fileMimeType }); + contentLength = fileData.size; + } + + if (fileData === undefined) throw new Error("Couldn't construct a file out of supplied options."); + if (fileName === undefined) throw new Error("Couldn't guess filename out of the options. Please provide one."); + + if (contentLength) this.contentLength = contentLength; + this.mimeType = fileMimeType!; + this.data = fileData; + this.name = fileName; + } + + /** + * Convert {@link PubNub} File object content to {@link Buffer}. + * + * @throws Error because {@link Buffer} not available in browser environment. + */ + async toBuffer() { + throw new Error('This feature is only supported in Node.js environments.'); + } + + /** + * Convert {@link PubNub} File object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + */ + async toArrayBuffer(): Promise { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + + reader.addEventListener('load', () => { + if (reader.result instanceof ArrayBuffer) return resolve(reader.result); + }); + reader.addEventListener('error', () => reject(reader.error)); + reader.readAsArrayBuffer(this.data); + }); + } + + /** + * Convert {@link PubNub} File object content to {@link string}. + * + * @returns Asynchronous results of conversion to the {@link string}. + */ + async toString(): Promise { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + + reader.addEventListener('load', () => { + if (typeof reader.result === 'string') { + return resolve(reader.result); + } + }); + + reader.addEventListener('error', () => { + reject(reader.error); + }); + + reader.readAsBinaryString(this.data); + }); + } + + /** + * Convert {@link PubNub} File object content to {@link Readable} stream. + * + * @throws Error because {@link Readable} stream not available in browser environment. + */ + async toStream() { + throw new Error('This feature is only supported in Node.js environments.'); + } + + /** + * Convert {@link PubNub} File object content to {@link File}. + * + * @returns Asynchronous results of conversion to the {@link File}. + */ + async toFile() { + return this.data; + } + + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @throws Error because file `Uri` not available in browser environment. + */ + async toFileUri(): Promise> { + throw new Error('This feature is only supported in React Native environments.'); + } + + /** + * Convert {@link PubNub} File object content to {@link Blob}. + * + * @returns Asynchronous results of conversion to the {@link Blob}. + */ + async toBlob() { + return this.data; + } +} diff --git a/src/networking/index.js b/src/networking/index.js deleted file mode 100644 index 74d666294..000000000 --- a/src/networking/index.js +++ /dev/null @@ -1,135 +0,0 @@ -/* */ - -import Config from '../core/components/config'; -import categoryConstants from '../core/constants/categories'; - -export default class { - _modules; - - _config; - - _currentSubDomain; - - _standardOrigin; - - _subscribeOrigin; - - _requestTimeout; - - _coreParams; /* items that must be passed with each request. */ - - constructor(modules) { - this._modules = {}; - - Object.keys(modules).forEach((key) => { - this._modules[key] = modules[key].bind(this); - }); - } - - init(config) { - this._config = config; - - if (Array.isArray(this._config.origin)) { - this._currentSubDomain = Math.floor(Math.random() * this._config.origin.length); - } else { - this._currentSubDomain = 0; - } - - this._coreParams = {}; - - // create initial origins - this.shiftStandardOrigin(); - } - - nextOrigin() { - const protocol = this._config.secure ? 'https://' : 'http://'; - - if (typeof this._config.origin === 'string') { - return `${protocol}${this._config.origin}`; - } - - this._currentSubDomain += 1; - - if (this._currentSubDomain >= this._config.origin.length) { - this._currentSubDomain = 0; - } - - const origin = this._config.origin[this._currentSubDomain]; - - return `${protocol}${origin}`; - } - - hasModule(name) { - return name in this._modules; - } - - // origin operations - shiftStandardOrigin() { - this._standardOrigin = this.nextOrigin(); - - return this._standardOrigin; - } - - getStandardOrigin() { - return this._standardOrigin; - } - - POSTFILE(url, fields, file) { - return this._modules.postfile(url, fields, file); - } - - GETFILE(params, endpoint, callback) { - return this._modules.getfile(params, endpoint, callback); - } - - POST(params, body, endpoint, callback) { - return this._modules.post(params, body, endpoint, callback); - } - - PATCH(params, body, endpoint, callback) { - return this._modules.patch(params, body, endpoint, callback); - } - - GET(params, endpoint, callback) { - return this._modules.get(params, endpoint, callback); - } - - DELETE(params, endpoint, callback) { - return this._modules.del(params, endpoint, callback); - } - - _detectErrorCategory(err) { - if (err.code === 'ENOTFOUND') { - return categoryConstants.PNNetworkIssuesCategory; - } - if (err.code === 'ECONNREFUSED') { - return categoryConstants.PNNetworkIssuesCategory; - } - if (err.code === 'ECONNRESET') { - return categoryConstants.PNNetworkIssuesCategory; - } - if (err.code === 'EAI_AGAIN') { - return categoryConstants.PNNetworkIssuesCategory; - } - - if (err.status === 0 || (err.hasOwnProperty('status') && typeof err.status === 'undefined')) { - return categoryConstants.PNNetworkIssuesCategory; - } - if (err.timeout) return categoryConstants.PNTimeoutCategory; - - if (err.code === 'ETIMEDOUT') { - return categoryConstants.PNNetworkIssuesCategory; - } - - if (err.response) { - if (err.response.badRequest) { - return categoryConstants.PNBadRequestCategory; - } - if (err.response.forbidden) { - return categoryConstants.PNAccessDeniedCategory; - } - } - - return categoryConstants.PNUnknownCategory; - } -} diff --git a/src/networking/modules/nativescript.js b/src/networking/modules/nativescript.js deleted file mode 100644 index b86fe7719..000000000 --- a/src/networking/modules/nativescript.js +++ /dev/null @@ -1,85 +0,0 @@ -/* */ - -import { request as HttpRequest } from 'http'; -import { buildUrl } from '../utils'; - -function log(url, qs, res) { - const _pickLogger = () => { - if (console && console.log) return console; // eslint-disable-line no-console - return console; - }; - - const start = new Date().getTime(); - const timestamp = new Date().toISOString(); - const logger = _pickLogger(); - logger.log('<<<<<'); // eslint-disable-line no-console - logger.log(`[${timestamp}]`, '\n', url, '\n', qs); // eslint-disable-line no-console - logger.log('-----'); // eslint-disable-line no-console - - const now = new Date().getTime(); - const elapsed = now - start; - const timestampDone = new Date().toISOString(); - - logger.log('>>>>>>'); // eslint-disable-line no-console - logger.log(`[${timestampDone} / ${elapsed}]`, '\n', url, '\n', qs, '\n', res); // eslint-disable-line no-console - logger.log('-----'); // eslint-disable-line no-console -} - -function xdr(method, url, params, body, endpoint, callback) { - const status = {}; - status.operation = endpoint.operation; - - const httpConfig = { - method, - url: buildUrl(url, params), - timeout: endpoint.timeout, - content: body, - }; - - // $FlowFixMe - return HttpRequest(httpConfig) - .then((response) => { - status.error = false; - - if (response.statusCode) { - status.statusCode = response.statusCode; - } - - return response.content.toJSON(); - }) - .then((response) => { - const resp = response; - - if (this._config.logVerbosity) { - log(url, params, resp); - } - - callback(status, resp); - }) - .catch((e) => { - status.error = true; - status.errorData = e; - status.category = this._detectErrorCategory(e); - callback(status, null); - }); -} - -export function get(params, endpoint, callback) { - const url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, 'GET', url, params, '', endpoint, callback); -} - -export function post(params, body, endpoint, callback) { - const url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, 'POST', url, params, body, endpoint, callback); -} - -export function patch(params, body, endpoint, callback) { - const url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, 'PATCH', url, params, body, endpoint, callback); -} - -export function del(params, endpoint, callback) { - const url = this.getStandardOrigin() + endpoint.url; - return xdr.call(this, 'DELETE', url, params, '', endpoint, callback); -} diff --git a/src/networking/modules/node.js b/src/networking/modules/node.js deleted file mode 100644 index b5d272044..000000000 --- a/src/networking/modules/node.js +++ /dev/null @@ -1,27 +0,0 @@ -import superagent from 'superagent'; -import AgentKeepAlive from 'agentkeepalive'; -import superagentProxy from '../proxyAgent'; - -let keepAliveAgent = null; -let keepAliveSecureAgent = null; - -superagentProxy(superagent); - -export function proxy(superagentConstruct) { - return superagentConstruct.proxy(this._config.proxy); -} - -export function keepAlive(superagentConstruct) { - let agent = this._config.secure ? keepAliveSecureAgent : keepAliveAgent; - if (agent === null) { - const AgentClass = this._config.secure ? AgentKeepAlive.HttpsAgent : AgentKeepAlive; - agent = new AgentClass(this._config.keepAliveSettings); - if (this._config.secure) { - keepAliveSecureAgent = agent; - } else { - keepAliveAgent = agent; - } - } - - return superagentConstruct.agent(agent); -} diff --git a/src/networking/modules/react_native.js b/src/networking/modules/react_native.js deleted file mode 100644 index 40cd28f83..000000000 --- a/src/networking/modules/react_native.js +++ /dev/null @@ -1,119 +0,0 @@ -/* */ -/* global FormData */ -/* global fetch */ - -import { EndpointDefinition, StatusAnnouncement } from '../../core/flow_interfaces'; -import { postfile as postfilewebnode } from './web-node'; - -async function postfileuri(url, fields, fileInput) { - const formData = new FormData(); - - fields.forEach(({ key, value }) => { - formData.append(key, value); - }); - - formData.append('file', fileInput); - - const result = await fetch(url, { - method: 'POST', - body: formData, - }); - - return result; -} - -export async function postfile(url, fields, fileInput) { - if (!fileInput.uri) { - return postfilewebnode(url, fields, fileInput); - } - return postfileuri(url, fields, fileInput); -} - -export function getfile(params, endpoint, callback) { - let url = this.getStandardOrigin() + endpoint.url; - - if (params && Object.keys(params).length > 0) { - const searchParams = new URLSearchParams(params); - - if (endpoint.url.indexOf('?') > -1) { - url += '&'; - } else { - url += '?'; - } - - url += searchParams.toString(); - } - - const fetchResult = fetch(url, { method: 'GET', headers: endpoint.headers }); - - fetchResult.then(async (resp) => { - let parsedResponse; - const status = {}; - status.error = false; - status.operation = endpoint.operation; - - if (resp && resp.status) { - status.statusCode = resp.status; - } - - if (endpoint.ignoreBody) { - parsedResponse = { - headers: resp.headers, - redirects: [], - response: resp, - }; - } else { - try { - parsedResponse = JSON.parse(await resp.text()); - } catch (e) { - status.errorData = resp; - status.error = true; - return callback(status, null); - } - } - - if ( - parsedResponse.error && - parsedResponse.error === 1 && - parsedResponse.status && - parsedResponse.message && - parsedResponse.service - ) { - status.errorData = parsedResponse; - status.statusCode = parsedResponse.status; - status.error = true; - status.category = this._detectErrorCategory(status); - return callback(status, null); - } - if (parsedResponse.error && parsedResponse.error.message) { - status.errorData = parsedResponse.error; - } - - // returning the entire response in order to use response methods for - // reading the body in react native because the response.body - // is a ReadableStream which doesn't seem to be reliable on ios and android - return callback(status, { response: { body: resp } }); - }); - - fetchResult.catch((err) => { - const status = {}; - status.error = true; - status.operation = endpoint.operation; - - if (err.response && err.response.text && !this._config.logVerbosity) { - try { - status.errorData = JSON.parse(err.response.text); - } catch (e) { - status.errorData = err; - } - } else { - status.errorData = err; - } - - status.category = this._detectErrorCategory(err); - - return callback(status, null); - }); - - return fetchResult; -} diff --git a/src/networking/modules/titanium.js b/src/networking/modules/titanium.js deleted file mode 100644 index af496373d..000000000 --- a/src/networking/modules/titanium.js +++ /dev/null @@ -1,107 +0,0 @@ -/* */ -/* global XMLHttpRequest, Ti */ - -import { buildUrl } from '../utils'; - -function log(url, qs, res) { - const _pickLogger = () => { - if (Ti && Ti.API && Ti.API.log) return Ti.API; - return console; - }; - - const start = new Date().getTime(); - const timestamp = new Date().toISOString(); - const logger = _pickLogger(); - logger.log('<<<<<'); // eslint-disable-line no-console - logger.log(`[${timestamp}]`, '\n', url, '\n', qs); // eslint-disable-line no-console - logger.log('-----'); // eslint-disable-line no-console - - const now = new Date().getTime(); - const elapsed = now - start; - const timestampDone = new Date().toISOString(); - - logger.log('>>>>>>'); // eslint-disable-line no-console - logger.log(`[${timestampDone} / ${elapsed}]`, '\n', url, '\n', qs, '\n', res); // eslint-disable-line no-console - logger.log('-----'); -} - -function getHttpClient() { - if (Ti.Platform.osname === 'mobileweb') { - return new XMLHttpRequest(); - } - return Ti.Network.createHTTPClient(); -} - -function keepAlive(xhr) { - if (Ti.Platform.osname !== 'mobileweb' && this._config.keepAlive) { - xhr.enableKeepAlive = true; - } -} - -function xdr(xhr, method, url, params, body, endpoint, callback) { - const status = {}; - status.operation = endpoint.operation; - - xhr.open(method, buildUrl(url, params), true); - - keepAlive.call(this, xhr); - - xhr.onload = () => { - status.error = false; - - if (xhr.status) { - status.statusCode = xhr.status; - } - - const resp = JSON.parse(xhr.responseText); - - if (this._config.logVerbosity) { - log(url, params, xhr.responseText); - } - - return callback(status, resp); - }; - - xhr.onerror = (e) => { - status.error = true; - status.errorData = e.error; - status.category = this._detectErrorCategory(e.error); - return callback(status, null); - }; - - xhr.timeout = Ti.Platform.osname === 'android' ? 2147483647 : Infinity; - - xhr.send(body); -} - -export function get(params, endpoint, callback) { - const xhr = getHttpClient(); - - const url = this.getStandardOrigin() + endpoint.url; - - return xdr.call(this, xhr, 'GET', url, params, {}, endpoint, callback); -} - -export function post(params, body, endpoint, callback) { - const xhr = getHttpClient(); - - const url = this.getStandardOrigin() + endpoint.url; - - return xdr.call(this, xhr, 'POST', url, params, JSON.parse(body), endpoint, callback); -} - -export function patch(params, body, endpoint, callback) { - const xhr = getHttpClient(); - - const url = this.getStandardOrigin() + endpoint.url; - - return xdr.call(this, xhr, 'PATCH', url, params, JSON.parse(body), endpoint, callback); -} - -export function del(params, endpoint, callback) { - const xhr = getHttpClient(); - - const url = this.getStandardOrigin() + endpoint.url; - - return xdr.call(this, xhr, 'DELETE', url, params, {}, endpoint, callback); -} diff --git a/src/networking/modules/web-node.js b/src/networking/modules/web-node.js deleted file mode 100644 index ce80930a1..000000000 --- a/src/networking/modules/web-node.js +++ /dev/null @@ -1,196 +0,0 @@ -/* */ -/* global window */ - -import superagent from 'superagent'; -import categories from '../../core/constants/categories'; - -function log(req) { - const _pickLogger = () => { - if (console && console.log) return console; // eslint-disable-line no-console - if (window && window.console && window.console.log) return window.console; - return console; - }; - - const start = new Date().getTime(); - const timestamp = new Date().toISOString(); - const logger = _pickLogger(); - logger.log('<<<<<'); - logger.log(`[${timestamp}]`, '\n', req.url, '\n', req.qs); - logger.log('-----'); - - req.on('response', (res) => { - const now = new Date().getTime(); - const elapsed = now - start; - const timestampDone = new Date().toISOString(); - - logger.log('>>>>>>'); - - logger.log(`[${timestampDone} / ${elapsed}]`, '\n', req.url, '\n', req.qs, '\n', res.text); - logger.log('-----'); - }); -} - -function xdr(superagentConstruct, endpoint, callback) { - if (this._config.logVerbosity) { - superagentConstruct = superagentConstruct.use(log); - } - - if (this._config.proxy && this._modules.proxy) { - superagentConstruct = this._modules.proxy.call(this, superagentConstruct); - } - - if (this._config.keepAlive && this._modules.keepAlive) { - superagentConstruct = this._modules.keepAlive(superagentConstruct); - } - - let sc = superagentConstruct; - - if (endpoint.abortSignal) { - const unsubscribe = endpoint.abortSignal.subscribe(() => { - sc.abort(); - unsubscribe(); - }); - } - - if (endpoint.forceBuffered === true) { - if (typeof Blob === 'undefined') { - sc = sc.buffer().responseType('arraybuffer'); - } else { - sc = sc.responseType('arraybuffer'); - } - } else if (endpoint.forceBuffered === false) { - sc = sc.buffer(false); - } - - sc = sc.timeout(endpoint.timeout); - - sc.on('abort', () => { - return callback( - { - category: categories.PNUnknownCategory, - error: true, - operation: endpoint.operation, - errorData: new Error('Aborted'), - }, - null, - ); - }); - - sc.end((err, resp) => { - let parsedResponse; - const status = {}; - status.error = err !== null; - status.operation = endpoint.operation; - - if (resp && resp.status) { - status.statusCode = resp.status; - } - - if (err) { - if (err.response && err.response.text && !this._config.logVerbosity) { - try { - status.errorData = JSON.parse(err.response.text); - } catch (e) { - status.errorData = err; - } - } else { - status.errorData = err; - } - status.category = this._detectErrorCategory(err); - return callback(status, null); - } - - if (endpoint.ignoreBody) { - parsedResponse = { - headers: resp.headers, - redirects: resp.redirects, - response: resp, - }; - } else { - try { - parsedResponse = JSON.parse(resp.text); - } catch (e) { - status.errorData = resp; - status.error = true; - return callback(status, null); - } - } - - if ( - parsedResponse.error && - parsedResponse.error === 1 && - parsedResponse.status && - parsedResponse.message && - parsedResponse.service - ) { - status.errorData = parsedResponse; - status.statusCode = parsedResponse.status; - status.error = true; - status.category = this._detectErrorCategory(status); - return callback(status, null); - } - if (parsedResponse.error && parsedResponse.error.message) { - status.errorData = parsedResponse.error; - } - - return callback(status, parsedResponse); - }); - - return sc; -} - -export async function postfile(url, fields, fileInput) { - let agent = superagent.post(url); - - fields.forEach(({ key, value }) => { - agent = agent.field(key, value); - }); - - agent.attach('file', fileInput, { contentType: 'application/octet-stream' }); - - const result = await agent; - - return result; -} - -export function getfile(params, endpoint, callback) { - const superagentConstruct = superagent - .get(this.getStandardOrigin() + endpoint.url) - .set(endpoint.headers) - .query(params); - return xdr.call(this, superagentConstruct, endpoint, callback); -} - -export function get(params, endpoint, callback) { - const superagentConstruct = superagent - .get(this.getStandardOrigin() + endpoint.url) - .set(endpoint.headers) - .query(params); - return xdr.call(this, superagentConstruct, endpoint, callback); -} - -export function post(params, body, endpoint, callback) { - const superagentConstruct = superagent - .post(this.getStandardOrigin() + endpoint.url) - .query(params) - .set(endpoint.headers) - .send(body); - return xdr.call(this, superagentConstruct, endpoint, callback); -} - -export function patch(params, body, endpoint, callback) { - const superagentConstruct = superagent - .patch(this.getStandardOrigin() + endpoint.url) - .query(params) - .set(endpoint.headers) - .send(body); - return xdr.call(this, superagentConstruct, endpoint, callback); -} - -export function del(params, endpoint, callback) { - const superagentConstruct = superagent - .delete(this.getStandardOrigin() + endpoint.url) - .set(endpoint.headers) - .query(params); - return xdr.call(this, superagentConstruct, endpoint, callback); -} diff --git a/src/networking/proxyAgent.js b/src/networking/proxyAgent.js deleted file mode 100644 index ebee260ea..000000000 --- a/src/networking/proxyAgent.js +++ /dev/null @@ -1,15 +0,0 @@ -import { ProxyAgent } from 'proxy-agent'; - -export default function (superagent) { - var Request = superagent.Request; - Request.prototype.proxy = proxy; - return superagent; -} - -function proxy(proxyConfiguration) { - var agent = new ProxyAgent(proxyConfiguration); - - if (agent) this.agent(agent); - - return this; -} diff --git a/src/networking/utils.js b/src/networking/utils.js deleted file mode 100644 index 0d1733599..000000000 --- a/src/networking/utils.js +++ /dev/null @@ -1,29 +0,0 @@ -/* */ - -export function encodedKeyValuePair(pairs, key, value) { - if (value != null) { - if (Array.isArray(value)) { - value.forEach((item) => { - encodedKeyValuePair(pairs, key, item); - }); - } else if (typeof value === 'object') { - Object.keys(value).forEach((subkey) => { - encodedKeyValuePair(pairs, `${key}[${subkey}]`, value[subkey]); - }); - } else { - pairs.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`); - } - } else if (value === null) { - pairs.push(encodeURIComponent(`${encodeURIComponent(key)}`)); - } -} - -export function buildUrl(url, params) { - const pairs = []; - - Object.keys(params).forEach((key) => { - encodedKeyValuePair(pairs, key, params[key]); - }); - - return `${url}?${pairs.join('&')}`; -} diff --git a/src/node/configuration.ts b/src/node/configuration.ts new file mode 100644 index 000000000..a3c5d2b99 --- /dev/null +++ b/src/node/configuration.ts @@ -0,0 +1,94 @@ +/** + * Node.js specific {@link PubNub} client configuration module. + */ + +import { + UserConfiguration, + ExtendedConfiguration, + setDefaults as setBaseDefaults, +} from '../core/interfaces/configuration'; +import { CryptoModule } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; +import { TransportKeepAlive } from '../core/interfaces/transport'; +import { Payload } from '../core/types/api'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- + +// region Defaults +/** + * Whether PubNub client should try utilize existing TCP connection for new requests or not. + */ +const KEEP_ALIVE = false; +// endregion + +/** + * NodeJS platform PubNub client configuration. + */ +export type PubNubConfiguration = UserConfiguration & { + /** + * Set a custom parameters for setting your connection `keepAlive` if this is set to `true`. + */ + keepAliveSettings?: TransportKeepAlive; + + /** + * The cryptography module used for encryption and decryption of messages and files. Takes the + * {@link cipherKey} and {@link useRandomIVs} parameters as arguments. + * + * For more information, refer to the + * {@link /docs/sdks/javascript/api-reference/configuration#cryptomodule|cryptoModule} section. + * + * @default `not set` + */ + cryptoModule?: CryptoModule; + + // region Deprecated parameters + /** + * If passed, will encrypt the payloads. + * + * @deprecated Pass it to {@link cryptoModule} instead. + */ + cipherKey?: string; + + /** + * When `true` the initialization vector (IV) is random for all requests (not just for file + * upload). + * When `false` the IV is hard-coded for all requests except for file upload. + * + * @default `true` + * + * @deprecated Pass it to {@link cryptoModule} instead. + */ + useRandomIVs?: boolean; + + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + customEncrypt?: (data: string | Payload) => string; + + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + customDecrypt?: (data: string) => string; + // endregion +}; + +/** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + * + * @returns Extended {@link PubNub} client configuration object pre-filled with default values. + */ +export const setDefaults = (configuration: PubNubConfiguration): PubNubConfiguration & ExtendedConfiguration => { + return { + // Set base configuration defaults. + ...setBaseDefaults(configuration), + // Set platform-specific options. + keepAlive: configuration.keepAlive ?? KEEP_ALIVE, + }; +}; diff --git a/src/node/index.ts b/src/node/index.ts index c95b77ae3..a3ac1273b 100755 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -1,48 +1,107 @@ +import { ProxyAgentOptions } from 'proxy-agent'; import CborReader from 'cbor-sync'; -import PubNubCore from '../core/pubnub-common'; -import Networking from '../networking'; -import Cbor from '../cbor/common'; -import { decode } from '../core/components/base64_codec'; -import { del, get, patch, post, getfile, postfile } from '../networking/modules/web-node'; -import { keepAlive, proxy } from '../networking/modules/node'; +import { Readable } from 'stream'; +import { Buffer } from 'buffer'; -import NodeCryptography from '../crypto/modules/node'; -import PubNubFile from '../file/modules/node'; import { CryptoModule, LegacyCryptor, AesCbcCryptor } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; +import PubNubFile, { PubNubFileParameters } from '../file/modules/node'; +import { CryptorConfiguration } from '../core/interfaces/crypto-module'; +import { makeConfiguration } from '../core/components/configuration'; +import { PubNubConfiguration, setDefaults } from './configuration'; +import { TokenManager } from '../core/components/token_manager'; +import { NodeTransport } from '../transport/node-transport'; +import { PubNubMiddleware } from '../transport/middleware'; +import { PubNubFileConstructor } from '../core/types/file'; +import { decode } from '../core/components/base64_codec'; +import NodeCryptography from '../crypto/modules/node'; +import Crypto from '../core/components/cryptography'; +import { PubNubError } from '../errors/pubnub-error'; +import { PubNubCore } from '../core/pubnub-common'; +import Cbor from '../cbor/common'; -export = class extends PubNubCore { +/** + * PubNub client for Node.js platform. + */ +export = class PubNub extends PubNubCore { + /** + * Data encryption / decryption module constructor. + */ static CryptoModule = CryptoModule; - constructor(setup: any) { - setup.cbor = new Cbor((buffer: ArrayBuffer) => CborReader.decode(Buffer.from(buffer)), decode); - setup.networking = new Networking({ - keepAlive, - del, - get, - post, - patch, - proxy, - getfile, - postfile, + + /** + * PubNub File constructor. + */ + public File: PubNubFileConstructor = PubNubFile; + + /** + * Actual underlying transport provider. + */ + private nodeTransport: NodeTransport; + + constructor(configuration: PubNubConfiguration) { + const configurationCopy = setDefaults(configuration); + const platformConfiguration = { ...configurationCopy, sdkFamily: 'Nodejs', PubNubFile }; + + // Prepare full client configuration. + const clientConfiguration = makeConfiguration( + platformConfiguration, + (cryptoConfiguration: CryptorConfiguration) => { + if (!cryptoConfiguration.cipherKey) return undefined; + + return new CryptoModule({ + default: new LegacyCryptor({ ...cryptoConfiguration }), + cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], + }); + }, + ); + + // Prepare Token manager. + const tokenManager = new TokenManager( + new Cbor((buffer: ArrayBuffer) => CborReader.decode(Buffer.from(buffer)), decode), + ); + + // Legacy crypto (legacy data encryption / decryption and request signature support). + const crypto = new Crypto({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + + // Setup transport provider. + const transport = new NodeTransport(configuration.keepAlive, configuration.keepAliveSettings); + const transportMiddleware = new PubNubMiddleware({ + clientConfiguration, + tokenManager, + transport, + shaHMAC: crypto?.HMACSHA256.bind(crypto), + }); + + super({ + configuration: clientConfiguration, + transport: transportMiddleware, + cryptography: new NodeCryptography(), + tokenManager, + crypto, }); - setup.sdkFamily = 'Nodejs'; - - setup.PubNubFile = PubNubFile; - setup.cryptography = new NodeCryptography(); - - setup.initCryptoModule = (cryptoConfiguration: any) => { - return new CryptoModule({ - default: new LegacyCryptor({ - cipherKey: cryptoConfiguration.cipherKey, - useRandomIVs: cryptoConfiguration.useRandomIVs, - }), - cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], - }); - }; - - if (!('ssl' in setup)) { - setup.ssl = true; - } - - super(setup); + + this.nodeTransport = transport; + } + + /** + * Update request proxy configuration. + * + * @param configuration - Updated request proxy configuration. + * + * @throws An error if {@link PubNub} client already configured to use `keepAlive`. + * `keepAlive` and `proxy` can't be used simultaneously. + */ + public setProxy(configuration?: ProxyAgentOptions) { + if (configuration && (this._configuration.keepAlive ?? false)) + throw new PubNubError("Can't set 'proxy' because already configured for 'keepAlive'"); + + this.nodeTransport.setProxy(configuration); + this.reconnect(); } }; diff --git a/src/react_native/configuration.ts b/src/react_native/configuration.ts new file mode 100644 index 000000000..1cbfae42f --- /dev/null +++ b/src/react_native/configuration.ts @@ -0,0 +1,19 @@ +import { + setDefaults as setBaseDefaults, + ExtendedConfiguration, + UserConfiguration, +} from '../core/interfaces/configuration'; + +/** + * React Native platform PubNub client configuration. + */ +export type PubNubConfiguration = UserConfiguration; + +/** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + */ +export const setDefaults = (configuration: PubNubConfiguration): PubNubConfiguration & ExtendedConfiguration => { + return setBaseDefaults(configuration); +}; diff --git a/src/react_native/index.js b/src/react_native/index.js deleted file mode 100644 index 921477ec3..000000000 --- a/src/react_native/index.js +++ /dev/null @@ -1,35 +0,0 @@ -import CborReader from 'cbor-js'; -import { Buffer } from 'buffer'; -import PubNubCore from '../core/pubnub-common'; -import Networking from '../networking'; -import { decode } from '../core/components/base64_codec'; -import { stringifyBufferKeys } from '../core/components/stringify_buffer_keys'; -import Cbor from '../cbor/common'; -import { del, get, post, patch } from '../networking/modules/web-node'; -import { getfile, postfile } from '../networking/modules/react_native'; - -import PubNubFile from '../file/modules/react-native'; -import { stringifyBufferKeys } from '../web'; - -global.Buffer = global.Buffer || Buffer; - -export default class extends PubNubCore { - constructor(setup) { - setup.cbor = new Cbor((arrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode); - - setup.PubNubFile = PubNubFile; - - setup.networking = new Networking({ - del, - get, - post, - patch, - getfile, - postfile, - }); - setup.sdkFamily = 'ReactNative'; - setup.ssl = true; - - super(setup); - } -} diff --git a/src/react_native/index.ts b/src/react_native/index.ts new file mode 100644 index 000000000..07bd18331 --- /dev/null +++ b/src/react_native/index.ts @@ -0,0 +1,67 @@ +import { TextEncoder, TextDecoder } from 'text-encoding'; +import 'react-native-url-polyfill/auto'; +import CborReader from 'cbor-js'; +import { Buffer } from 'buffer'; + +import { WebReactNativeTransport } from '../transport/web-react-native-transport'; +import { stringifyBufferKeys } from '../core/components/stringify_buffer_keys'; +import { makeConfiguration } from '../core/components/configuration'; +import { PubNubFileParameters } from '../file/modules/react-native'; +import { TokenManager } from '../core/components/token_manager'; +import { PubNubMiddleware } from '../transport/middleware'; +import { decode } from '../core/components/base64_codec'; +import PubNubFile from '../file/modules/react-native'; +import { PubNubConfiguration } from './configuration'; +import Crypto from '../core/components/cryptography'; +import { PubNubCore } from '../core/pubnub-common'; +import { setDefaults } from './configuration'; +import Cbor from '../cbor/common'; + +// Polyfill global environment +global.TextEncoder = global.TextEncoder || TextEncoder; +global.TextDecoder = global.TextDecoder || TextDecoder; +global.Buffer = global.Buffer || Buffer; + +/** + * PubNub client for React Native platform. + */ +export default class PubNub extends PubNubCore { + constructor(configuration: PubNubConfiguration) { + const configurationCopy = setDefaults(configuration); + const platformConfiguration = { ...configurationCopy, sdkFamily: 'ReactNative', PubNubFile }; + + // Prepare full client configuration. + const clientConfiguration = makeConfiguration(platformConfiguration); + + // Prepare Token manager. + const tokenManager = new TokenManager( + new Cbor((arrayBuffer: ArrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode), + ); + + // Legacy crypto (legacy data encryption / decryption and request signature support). + let crypto: Crypto | undefined; + if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { + crypto = new Crypto({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } + + // Setup transport layer. + const transportMiddleware = new PubNubMiddleware({ + clientConfiguration, + tokenManager, + transport: new WebReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity!), + }); + + super({ + configuration: clientConfiguration, + transport: transportMiddleware, + tokenManager, + crypto, + }); + } +} diff --git a/src/titanium/configuration.ts b/src/titanium/configuration.ts new file mode 100644 index 000000000..4cf016114 --- /dev/null +++ b/src/titanium/configuration.ts @@ -0,0 +1,43 @@ +import { + setDefaults as setBaseDefaults, + ExtendedConfiguration, + UserConfiguration, +} from '../core/interfaces/configuration'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether PubNub client should try to utilize existing TCP connection for new requests or not. + */ +const KEEP_ALIVE = true; +// endregion + +/** + * Titanium platform PubNub client configuration. + */ +export type PubNubConfiguration = UserConfiguration & { + /** + * If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of + * opening a new one for each new request. + * + * @default `true` + */ + keepAlive?: boolean; +}; + +/** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + */ +export const setDefaults = (configuration: PubNubConfiguration): PubNubConfiguration & ExtendedConfiguration => { + return { + // Set base configuration defaults. + ...setBaseDefaults(configuration), + // Set platform-specific options. + keepAlive: configuration.keepAlive ?? KEEP_ALIVE, + }; +}; diff --git a/src/titanium/index.js b/src/titanium/index.js deleted file mode 100644 index 88c350f96..000000000 --- a/src/titanium/index.js +++ /dev/null @@ -1,22 +0,0 @@ -import CborReader from 'cbor-sync'; -import PubNubCore from '../core/pubnub-common'; -import Networking from '../networking'; -import Cbor from '../cbor/common'; -import { del, get, post, patch } from '../networking/modules/titanium'; - -class PubNub extends PubNubCore { - constructor(setup) { - setup.cbor = new Cbor(CborReader.decode, (base64String) => Buffer.from(base64String, 'base64')); - setup.sdkFamily = 'TitaniumSDK'; - setup.networking = new Networking({ - del, - get, - post, - patch, - }); - - super(setup); - } -} - -export { PubNub as default }; diff --git a/src/titanium/index.ts b/src/titanium/index.ts new file mode 100644 index 000000000..36b890d91 --- /dev/null +++ b/src/titanium/index.ts @@ -0,0 +1,42 @@ +import CborReader from 'cbor-sync'; + +import { makeConfiguration } from '../core/components/configuration'; +import { TitaniumTransport } from '../transport/titanium-transport'; +import { PubNubConfiguration, setDefaults } from './configuration'; +import { TokenManager } from '../core/components/token_manager'; +import { PubNubMiddleware } from '../transport/middleware'; +import { PubNubCore } from '../core/pubnub-common'; +import Cbor from '../cbor/common'; + +/** + * PubNub client for Titanium. + */ +export class PubNub extends PubNubCore { + constructor(configuration: PubNubConfiguration) { + const configurationCopy = setDefaults(configuration); + const platformConfiguration = { ...configurationCopy, sdkFamily: 'TitaniumSDK' }; + + // Prepare full client configuration. + const clientConfiguration = makeConfiguration(platformConfiguration); + + // Prepare Token manager. + const tokenManager = new TokenManager( + new Cbor(CborReader.decode, (base64String: string) => Buffer.from(base64String, 'base64')), + ); + + // Setup transport layer. + const transportMiddleware = new PubNubMiddleware({ + clientConfiguration, + tokenManager, + transport: new TitaniumTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity), + }); + + super({ + configuration: clientConfiguration, + transport: transportMiddleware, + tokenManager, + }); + } +} + +export { PubNub as default }; diff --git a/src/transport/middleware.ts b/src/transport/middleware.ts new file mode 100644 index 000000000..dacbd336f --- /dev/null +++ b/src/transport/middleware.ts @@ -0,0 +1,177 @@ +import { TransportMethod, TransportRequest } from '../core/types/transport-request'; +import { PrivateClientConfiguration } from '../core/interfaces/configuration'; +import { TokenManager } from '../core/components/token_manager'; +import { Transport } from '../core/interfaces/transport'; +import { encodeString } from '../core/utils'; +import { Query } from '../core/types/api'; + +/** + * Transport middleware configuration options. + */ +type PubNubMiddlewareConfiguration = { + /** + * Private client configuration. + */ + clientConfiguration: PrivateClientConfiguration; + + /** + * REST API endpoints access tokens manager. + */ + tokenManager: TokenManager; + + /** + * HMAC-SHA256 hash generator from provided `data`. + */ + shaHMAC?: (data: string) => string; + + /** + * Platform-specific transport for requests processing. + */ + transport: Transport; +}; + +export class RequestSignature { + private static textDecoder = new TextDecoder('utf-8'); + constructor( + private publishKey: string, + private secretKey: string, + private hasher: (input: string, secret: string) => string, + ) {} + + /** + * Compute request signature. + * + * @param req - Request which will be used to compute signature. + * @returns {string} `v2` request signature. + */ + public signature(req: TransportRequest): string { + const method = req.path.startsWith('/publish') ? TransportMethod.GET : req.method; + + let signatureInput = `${method}\n${this.publishKey}\n${req.path}\n${this.queryParameters(req.queryParameters!)}\n`; + if (method === TransportMethod.POST || method === TransportMethod.PATCH) { + const body = req.body; + let payload: string | undefined; + + if (body && body instanceof ArrayBuffer) { + payload = RequestSignature.textDecoder.decode(body); + } else if (body && typeof body !== 'object') { + payload = body; + } + + if (payload) signatureInput += payload; + } + + return `v2.${this.hasher(signatureInput, this.secretKey)}` + .replace(/\+/g, '-') + .replace(/\//g, '_') + .replace(/=+$/, ''); + } + + /** + * Prepare request query parameters for signature. + * + * @param query - Key / value pair of the request query parameters. + * @private + */ + private queryParameters(query: Query) { + return Object.keys(query) + .sort() + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) return `${key}=${encodeString(queryValue)}`; + + return queryValue + .sort() + .map((value) => `${key}=${encodeString(value)}`) + .join('&'); + }) + .join('&'); + } +} + +export class PubNubMiddleware implements Transport { + /** + * Request signature generator. + */ + signatureGenerator?: RequestSignature; + + constructor(private configuration: PubNubMiddlewareConfiguration) { + const { + clientConfiguration: { keySet }, + shaHMAC, + } = configuration; + + if (keySet.secretKey && shaHMAC) + this.signatureGenerator = new RequestSignature(keySet.publishKey!, keySet.secretKey, shaHMAC); + } + + makeSendable(req: TransportRequest) { + return this.configuration.transport.makeSendable(this.request(req)); + } + + request(req: TransportRequest): TransportRequest { + const { clientConfiguration } = this.configuration; + + // Get request patched by transport provider. + req = this.configuration.transport.request(req); + if (!req.queryParameters) req.queryParameters = {}; + + // Modify request with required information. + if (clientConfiguration.useInstanceId) req.queryParameters['instanceid'] = clientConfiguration.instanceId!; + if (!req.queryParameters['uuid']) req.queryParameters['uuid'] = clientConfiguration.userId!; + if (clientConfiguration.useRequestId) req.queryParameters['requestid'] = req.identifier; + req.queryParameters['pnsdk'] = this.generatePNSDK(); + req.origin ??= clientConfiguration.origin as string; + + // Authenticate request if required. + this.authenticateRequest(req); + + // Sign request if it is required. + this.signRequest(req); + + return req; + } + + private authenticateRequest(req: TransportRequest) { + // Access management endpoints doesn't need authentication (signature required instead). + if (req.path.startsWith('/v2/auth/') || req.path.startsWith('/v3/pam/') || req.path.startsWith('/time')) return; + + const { clientConfiguration, tokenManager } = this.configuration; + const accessKey = tokenManager.getToken() ?? clientConfiguration.authKey; + if (accessKey) req.queryParameters!['auth'] = accessKey; + } + + /** + * Compute and append request signature. + * + * @param req - Transport request with information which should be used to generate signature. + */ + private signRequest(req: TransportRequest) { + if (!this.signatureGenerator || req.path.startsWith('/time')) return; + + req.queryParameters!['timestamp'] = String(Math.floor(new Date().getTime() / 1000)); + req.queryParameters!['signature'] = this.signatureGenerator.signature(req); + } + + /** + * Compose `pnsdk` query parameter. + * + * SDK provides ability to set custom name or append vendor information to the `pnsdk` query + * parameter. + * + * @returns Finalized `pnsdk` query parameter value. + */ + private generatePNSDK() { + const { clientConfiguration } = this.configuration; + if (clientConfiguration.sdkName) return clientConfiguration.sdkName; + + let base = `PubNub-JS-${clientConfiguration.sdkFamily}`; + if (clientConfiguration.partnerId) base += `-${clientConfiguration.partnerId}`; + base += `/${clientConfiguration.getVersion()}`; + + const pnsdkSuffix = clientConfiguration._getPnsdkSuffix(' '); + if (pnsdkSuffix.length > 0) base += pnsdkSuffix; + + return base; + } +} diff --git a/src/transport/node-transport.ts b/src/transport/node-transport.ts new file mode 100644 index 000000000..ed6de5a44 --- /dev/null +++ b/src/transport/node-transport.ts @@ -0,0 +1,218 @@ +import fetch, { Request, Response, RequestInit } from 'node-fetch'; +import { ProxyAgent, ProxyAgentOptions } from 'proxy-agent'; +import { Agent as HttpsAgent } from 'https'; +import { Agent as HttpAgent } from 'http'; +import FormData from 'form-data'; +import { Buffer } from 'buffer'; + +import { CancellationController, TransportRequest } from '../core/types/transport-request'; +import { Transport, TransportKeepAlive } from '../core/interfaces/transport'; +import { TransportResponse } from '../core/types/transport-response'; +import { PubNubAPIError } from '../errors/pubnub-api-error'; +import { PubNubFileInterface } from '../core/types/file'; +import { queryStringFromObject } from '../core/utils'; + +/** + * Class representing a fetch-based Node.js transport provider. + */ +export class NodeTransport implements Transport { + /** + * Service {@link ArrayBuffer} response decoder. + */ + protected static decoder = new TextDecoder(); + + /** + * Request proxy configuration. + */ + private proxyConfiguration?: ProxyAgentOptions; + + private proxyAgent?: ProxyAgent; + private httpsAgent?: HttpsAgent; + private httpAgent?: HttpAgent; + + /** + * Creates a new `fetch`-based transport instance. + * + * @param keepAlive - Indicates whether keep-alive should be enabled. + * @param [keepAliveSettings] - Optional settings for keep-alive. + * @param [logVerbosity] - Whether verbose logging enabled or not. + * + * @returns Transport for performing network requests. + */ + constructor( + private readonly keepAlive: boolean = false, + private readonly keepAliveSettings: TransportKeepAlive = { timeout: 30000 }, + private readonly logVerbosity: boolean = false, + ) {} + + /** + * Update request proxy configuration. + * + * @param configuration - New proxy configuration. + */ + public setProxy(configuration?: ProxyAgentOptions) { + this.proxyConfiguration = configuration; + } + + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { + let controller: CancellationController | undefined = undefined; + let abortController: AbortController | undefined; + + if (req.cancellable) { + abortController = new AbortController(); + controller = { + // Storing controller inside to prolong object lifetime. + abortController, + abort: () => abortController?.abort(), + } as CancellationController; + } + + return [ + this.requestFromTransportRequest(req).then((request) => { + const start = new Date().getTime(); + + this.logRequestProcessProgress(request); + + return fetch(request, { + signal: abortController?.signal, + timeout: req.timeout * 1000, + } as RequestInit) + .then((response): Promise<[Response, ArrayBuffer]> | [Response, ArrayBuffer] => + response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer]), + ) + .then((response) => { + const responseBody = response[1].byteLength > 0 ? response[1] : undefined; + const { status, headers: requestHeaders } = response[0]; + const headers: Record = {}; + + // Copy Headers object content into plain Record. + requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); + + const transportResponse: TransportResponse = { + status, + url: request.url, + headers, + body: responseBody, + }; + + if (status >= 400) throw PubNubAPIError.create(transportResponse); + + this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + + return transportResponse; + }) + .catch((error) => { + throw PubNubAPIError.create(error); + }); + }), + controller, + ]; + } + + request(req: TransportRequest): TransportRequest { + return req; + } + + /** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + */ + private async requestFromTransportRequest(req: TransportRequest): Promise { + let headers: Record | undefined = req.headers; + let body: string | ArrayBuffer | FormData | undefined; + let path = req.path; + + // Create multipart request body. + if (req.formData && req.formData.length > 0) { + // Reset query parameters to conform to signed URL + req.queryParameters = {}; + + const file = req.body as PubNubFileInterface; + const fileData = await file.toArrayBuffer(); + const formData = new FormData(); + for (const { key, value } of req.formData) formData.append(key, value); + + formData.append('file', Buffer.from(fileData), { contentType: 'application/octet-stream', filename: file.name }); + body = formData; + + headers = formData.getHeaders(headers ?? {}); + } + // Handle regular body payload (if passed). + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) body = req.body; + + if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) + path = `${path}?${queryStringFromObject(req.queryParameters)}`; + + return new Request(`${req.origin!}${path}`, { + agent: this.agentForTransportRequest(req), + method: req.method, + headers, + redirect: 'follow', + body, + } as RequestInit); + } + + /** + * Determines and returns the appropriate agent for a given transport request. + * + * If keep alive is not requested, returns undefined. + * + * @param req - The transport request object. + * + * @returns {HttpAgent | HttpsAgent | undefined} - The appropriate agent for the request, or + * undefined if keep alive or proxy not requested. + */ + private agentForTransportRequest(req: TransportRequest): HttpAgent | HttpsAgent | undefined { + // Don't configure any agents if keep alive not requested. + if (!this.keepAlive && !this.proxyConfiguration) return undefined; + + // Create proxy agent (if possible). + if (this.proxyConfiguration) + return this.proxyAgent ? this.proxyAgent : (this.proxyAgent = new ProxyAgent(this.proxyConfiguration)); + + // Create keep alive agent. + const useSecureAgent = req.origin!.startsWith('https:'); + + if (useSecureAgent && this.httpsAgent === undefined) + this.httpsAgent = new HttpsAgent({ keepAlive: true, ...this.keepAliveSettings }); + else if (!useSecureAgent && this.httpAgent === undefined) { + this.httpAgent = new HttpAgent({ keepAlive: true, ...this.keepAliveSettings }); + } + + return useSecureAgent ? this.httpsAgent : this.httpAgent; + } + + /** + * Log out request processing progress and result. + * + * @param request - Platform-specific request object. + * @param [elapsed] - How many times passed since request processing started. + * @param [body] - Service response (if available). + */ + protected logRequestProcessProgress(request: Request, elapsed?: number, body?: ArrayBuffer) { + if (!this.logVerbosity) return; + + const { protocol, host, pathname, search } = new URL(request.url); + const timestamp = new Date().toISOString(); + + if (!elapsed) { + console.log('<<<<<'); + console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + console.log('-----'); + } else { + const stringifiedBody = body ? NodeTransport.decoder.decode(body) : undefined; + + console.log('>>>>>>'); + console.log( + `[${timestamp} / ${elapsed}]`, + `\n${protocol}//${host}${pathname}`, + `\n${search}`, + `\n${stringifiedBody}`, + ); + console.log('-----'); + } + } +} diff --git a/src/transport/service-worker/subscription-service-worker-middleware.ts b/src/transport/service-worker/subscription-service-worker-middleware.ts new file mode 100644 index 000000000..7e03303e1 --- /dev/null +++ b/src/transport/service-worker/subscription-service-worker-middleware.ts @@ -0,0 +1,304 @@ +/** + * Subscription Service Worker transport middleware module. + * + * Middleware optimize subscription feature requests utilizing `Subscription Service Worker` if available and not + * disabled by user. + */ + +import { CancellationController, TransportRequest } from '../../core/types/transport-request'; +import * as PubNubSubscriptionServiceWorker from './subscription-service-worker'; +import { TransportResponse } from '../../core/types/transport-response'; +import { Transport } from '../../core/interfaces/transport'; +import { PubNubAPIError } from '../../errors/pubnub-api-error'; +import StatusCategory from '../../core/constants/categories'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +type PubNubMiddlewareConfiguration = { + /** + * Unique PubNub SDK client identifier. + */ + clientIdentifier: string; + + /** + * Subscribe REST API access key. + */ + subscriptionKey: string; + + /** + * Current PubNub client version. + */ + sdkVersion: string; + + /** + * Whether verbose logging enabled or not. + */ + logVerbosity: boolean; + + /** + * Platform-specific transport for requests processing. + */ + transport: Transport; +}; + +// endregion + +/** + * Subscription Service Worker transport middleware. + */ +export class SubscriptionServiceWorkerMiddleware implements Transport { + /** + * Scheduled requests result handling callback. + */ + callbacks?: Map void; reject: (value: Error) => void }>; + + /** + * Subscription service worker. + * + * **Note:** Web PubNub SDK Transport provider adjustment for explicit subscription feature support. + */ + serviceWorkerRegistration?: ServiceWorkerRegistration; + + /** + * Queue of events for service worker. + * + * Keep list of events which should be sent to the worker after its activation. + */ + serviceWorkerEventsQueue: PubNubSubscriptionServiceWorker.ClientEvent[]; + + constructor(private readonly configuration: PubNubMiddlewareConfiguration) { + this.serviceWorkerEventsQueue = []; + this.callbacks = new Map(); + + this.setupServiceWorker(); + } + + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { + // Use default request flow for non-subscribe / presence leave requests. + if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/leave')) + return this.configuration.transport.makeSendable(req); + + let controller: CancellationController | undefined; + const sendRequestEvent: PubNubSubscriptionServiceWorker.SendRequestEvent = { + type: 'send-request', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + logVerbosity: this.configuration.logVerbosity, + request: req, + }; + + if (req.cancellable) { + controller = { + abort: () => { + const cancelRequest: PubNubSubscriptionServiceWorker.CancelRequestEvent = { + type: 'cancel-request', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + logVerbosity: this.configuration.logVerbosity, + identifier: req.identifier, + }; + + // Cancel active request with specified identifier. + this.scheduleEventPost(cancelRequest); + }, + }; + } + + return [ + new Promise((resolve, reject) => { + // Associate Promise resolution / reject with request identifier for future usage in + // `onmessage` handler block to return results. + this.callbacks!.set(req.identifier, { resolve, reject }); + + // Trigger request processing by Service Worker. + this.scheduleEventPost(sendRequestEvent); + }), + controller, + ]; + } + + request(req: TransportRequest): TransportRequest { + return req; + } + + /** + * Schedule {@link event} publish to the service worker. + * + * Service worker may not be ready for events processing and this method build queue for the time when worker will be + * ready. + * + * @param event - Event payload for service worker. + * @param outOfOrder - Whether event should be processed first then enqueued queue. + */ + private scheduleEventPost(event: PubNubSubscriptionServiceWorker.ClientEvent, outOfOrder: boolean = false) { + // Trigger request processing by Web Worker. + const serviceWorker = this.serviceWorker; + if (serviceWorker) serviceWorker.postMessage(event); + else { + if (outOfOrder) this.serviceWorkerEventsQueue.splice(0, 0, event); + else this.serviceWorkerEventsQueue.push(event); + } + } + + /** + * Dequeue and post events from the queue to the service worker. + */ + private flushScheduledEvents(): void { + // Trigger request processing by Web Worker. + const serviceWorker = this.serviceWorker; + if (!serviceWorker || this.serviceWorkerEventsQueue.length === 0) return; + + // Clean up from cancelled events. + const outdatedEvents: PubNubSubscriptionServiceWorker.ClientEvent[] = []; + for (let i = 0; i < this.serviceWorkerEventsQueue.length; i++) { + const event = this.serviceWorkerEventsQueue[i]; + + // Check whether found request cancel event to search for request send event it cancels. + if (event.type !== 'cancel-request' || i === 0) continue; + + for (let j = 0; j < i; j++) { + const otherEvent = this.serviceWorkerEventsQueue[j]; + if (otherEvent.type !== 'send-request') continue; + + // Collect outdated events if identifiers match. + if (otherEvent.request.identifier === event.identifier) { + outdatedEvents.push(event, otherEvent); + break; + } + } + } + + // Actualizing events queue. + this.serviceWorkerEventsQueue = this.serviceWorkerEventsQueue.filter((event) => !outdatedEvents.includes(event)); + this.serviceWorkerEventsQueue.forEach((event) => serviceWorker.postMessage(event)); + this.serviceWorkerEventsQueue = []; + } + + /** + * Subscription service worker. + * + * @returns Service worker which has been registered by the PubNub SDK. + */ + private get serviceWorker() { + return this.serviceWorkerRegistration ? this.serviceWorkerRegistration.active : null; + } + + private setupServiceWorker(): void { + if (!('serviceWorker' in navigator)) return; + const serviceWorkerContainer = navigator.serviceWorker as ServiceWorkerContainer; + serviceWorkerContainer + .register(`SERVICE_WORKER_CDN/SERVICE_WORKER_FILE_PLACEHOLDER`, { + scope: `/pubnub-${this.configuration.sdkVersion}`, + }) + .then((registration) => { + this.serviceWorkerRegistration = registration; + + // Flush any pending service worker events. + if (registration.active) this.flushScheduledEvents(); + + /** + * Listening for service worker code update. + * + * It is possible that one of the tabs will open with newer SDK version and Subscription Service Worker + * will be re-installed - in this case we need to "rehydrate" it. + * + * After re-installation of new service worker it will lose all accumulated state and client need to + * re-introduce itself and its state. + */ + this.serviceWorkerRegistration.addEventListener('updatefound', () => { + if (!this.serviceWorkerRegistration) return; + + // New service installing right now. + const serviceWorker = this.serviceWorkerRegistration.installing!; + + const stateChangeListener = () => { + // Flush any pending service worker events. + if (serviceWorker.state === 'activated') { + // Flush any pending service worker events. + this.flushScheduledEvents(); + } else if (serviceWorker.state === 'redundant') { + // Clean up listener from deprecated service worker version. + serviceWorker.removeEventListener('statechange', stateChangeListener); + } + }; + + serviceWorker.addEventListener('statechange', stateChangeListener); + }); + }); + + serviceWorkerContainer.addEventListener('message', (event) => this.handleServiceWorkerEvent(event)); + } + + private handleServiceWorkerEvent(event: MessageEvent) { + const { data } = event; + + // Ignoring updates not related to this instance. + if (data.clientIdentifier !== this.configuration.clientIdentifier) return; + + if (data.type === 'request-progress-start' || data.type === 'request-progress-end') { + this.logRequestProgress(data); + } else if (data.type === 'request-process-success' || data.type === 'request-process-error') { + const { resolve, reject } = this.callbacks!.get(data.identifier)!; + + if (data.type === 'request-process-success') { + resolve({ + status: data.response.status, + url: data.url, + headers: data.response.headers, + body: data.response.body, + }); + } else { + let category: StatusCategory = StatusCategory.PNUnknownCategory; + let message = 'Unknown error'; + + // Handle client-side issues (if any). + if (data.error) { + if (data.error.type === 'NETWORK_ISSUE') category = StatusCategory.PNNetworkIssuesCategory; + else if (data.error.type === 'TIMEOUT') category = StatusCategory.PNTimeoutCategory; + else if (data.error.type === 'ABORTED') category = StatusCategory.PNCancelledCategory; + message = `${data.error.message} (${data.identifier})`; + } + // Handle service error response. + else if (data.response) { + return reject( + PubNubAPIError.create( + { + url: data.url, + headers: data.response.headers, + body: data.response.body, + status: data.response.status, + }, + data.response.body, + ), + ); + } + + reject(new PubNubAPIError(message, category, 0, new Error(message))); + } + } + } + + /** + * Print request progress information. + * + * @param information - Request progress information from Web Worker. + */ + private logRequestProgress(information: PubNubSubscriptionServiceWorker.RequestSendingProgress) { + if (information.type === 'request-progress-start') { + console.log('<<<<<'); + console.log(`[${information.timestamp}] ${information.url}\n${JSON.stringify(information.query ?? {})}`); + console.log('-----'); + } else { + console.log('>>>>>>'); + console.log( + `[${information.timestamp} / ${information.duration}] ${information.url}\n${JSON.stringify( + information.query ?? {}, + )}\n${information.response}`, + ); + console.log('-----'); + } + } +} diff --git a/src/transport/service-worker/subscription-service-worker.ts b/src/transport/service-worker/subscription-service-worker.ts new file mode 100644 index 000000000..970ded65a --- /dev/null +++ b/src/transport/service-worker/subscription-service-worker.ts @@ -0,0 +1,1390 @@ +/// +/** + * Subscription Service Worker Transport provider. + * + * Service worker provides support for PubNub subscription feature to give better user experience across + * multiple opened pages. + */ + +import { TransportRequest } from '../../core/types/transport-request'; +import uuidGenerator from '../../core/components/uuid'; +import { Payload, Query } from '../../core/types/api'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types +// region Client-side + +/** + * Basic information for client and request group identification. + */ +type BasicEvent = { + /** + * Unique PubNub SDK client identifier for which setup is done. + */ + clientIdentifier: string; + + /** + * Subscribe REST API access key. + */ + subscriptionKey: string; + + /** + * Whether verbose logging enabled or not. + */ + logVerbosity: boolean; +}; + +/** + * Send HTTP request event. + * + * Request from Web Worker to schedule {@link Request} using provided {@link SendRequestSignal#request|request} data. + */ +export type SendRequestEvent = BasicEvent & { + type: 'send-request'; + + /** + * Instruction to construct actual {@link Request}. + */ + request: TransportRequest; +}; + +/** + * Cancel HTTP request event. + */ +export type CancelRequestEvent = BasicEvent & { + type: 'cancel-request'; + + /** + * Identifier of request which should be cancelled. + */ + identifier: string; +}; + +/** + * List of known events from the PubNub Core. + */ +export type ClientEvent = SendRequestEvent | CancelRequestEvent; +// endregion + +// region Service Worker +/** + * {@link Request} processing start event. + * + * This event will be sent if {@link logVerbosity} set to `true` when worker will receive + * {@link SendRequestEvent}. + */ +export type RequestSendingStart = { + type: 'request-progress-start'; + + /** + * Receiving PubNub client unique identifier. + */ + clientIdentifier: string; + + /** + * Url of request which has been sent. + */ + url: string; + + /** + * Key / value pairs of request which has been sent. + */ + query?: Query; + + /** + * When request processing started. + */ + timestamp: string; +}; +/** + * {@link Request} processing completion event. + * + * This event will be sent if {@link logVerbosity} set to `true` when worker will receive + * response from service or error. + */ +export type RequestSendingEnd = { + type: 'request-progress-end'; + + /** + * Receiving PubNub client unique identifier. + */ + clientIdentifier: string; + + /** + * Url of request which has been sent. + */ + url: string; + + /** + * Key / value pairs of request which has been sent. + */ + query?: Query; + + /** + * Stringified service response (if `Content-Type` allows it). + */ + response: string | undefined; + + /** + * How long it took to perform request. + */ + duration: number; + + /** + * When request processing ended. + */ + timestamp: string; +}; + +/** + * Request processing progress. + */ +export type RequestSendingProgress = RequestSendingStart | RequestSendingEnd; + +/** + * Request processing error. + * + * Object may include either service error response or client-side processing error object. + */ +export type RequestSendingError = { + type: 'request-process-error'; + + /** + * Receiving PubNub client unique identifier. + */ + clientIdentifier: string; + + /** + * Failed request identifier. + */ + identifier: string; + + /** + * Url which has been used to perform request. + */ + url: string; + + /** + * Service error response. + */ + response?: RequestSendingSuccess['response']; + + /** + * Client side request processing error. + */ + error?: { + /** + * Name of error object which has been received. + */ + name: string; + + /** + * Available client-side errors. + */ + type: 'NETWORK_ISSUE' | 'ABORTED' | 'TIMEOUT'; + + /** + * Triggered error message. + */ + message: string; + }; +}; + +/** + * Request processing success. + */ +export type RequestSendingSuccess = { + type: 'request-process-success'; + + /** + * Receiving PubNub client unique identifier. + */ + clientIdentifier: string; + + /** + * Processed request identifier. + */ + identifier: string; + + /** + * Url which has been used to perform request. + */ + url: string; + + /** + * Service success response. + */ + response: { + /** + * Received {@link RequestSendingSuccess#response.body|body} content type. + */ + contentType: string; + + /** + * Received {@link RequestSendingSuccess#response.body|body} content length. + */ + contentLength: number; + + /** + * Response headers key / value pairs. + */ + headers: Record; + + /** + * Response status code. + */ + status: number; + + /** + * Service response. + */ + body?: ArrayBuffer; + }; +}; + +/** + * Request processing results. + */ +export type RequestSendingResult = RequestSendingError | RequestSendingSuccess; + +/** + * List of known events from the PubNub Subscription Service Worker. + */ +export type ServiceWorkerEvent = RequestSendingProgress | RequestSendingResult; + +/** + * PubNub client state representation in Service Worker. + */ +type PubNubClientState = { + /** + * Unique PubNub client identifier. + */ + clientIdentifier: string; + + /** + * Subscribe REST API access key. + */ + subscriptionKey: string; + + /** + * Unique identifier of the user currently configured for the PubNub client. + */ + userId: string; + + /** + * Authorization key or access token which is used to access provided list of + * {@link subscription.channels|channels} and {@link subscription.channelGroups|channelGroups}. + */ + authKey?: string; + + /** + * Whether verbose logging enabled or not. + */ + logVerbosity: boolean; + + /** + * Current subscription session information. + * + * **Note:** Information updated each time when PubNub client instance schedule `subscribe` or + * `unsubscribe` requests. + */ + subscription: { + /** + * Subscription REST API uri path. + * + * **Note:** Keeping it for faster check whether client state should be updated or not. + */ + path: string; + + /** + * Channel groups list representation from request query parameters. + * + * **Note:** Keeping it for faster check whether client state should be updated or not. + */ + channelGroupQuery: string; + + /** + * List of channels used in current subscription session. + */ + channels: string[]; + + /** + * List of channel groups used in current subscription session. + */ + channelGroups: string[]; + + /** + * Timetoken which used has been used with previous subscription session loop. + */ + previousTimetoken: string; + + /** + * Timetoken which used in current subscription session loop. + */ + timetoken: string; + + /** + * List of channel and / or channel group names for which state has been assigned. + * + * Information used during client information update to identify entries which should be removed. + */ + objectsWithState: string[]; + + /** + * Subscribe request which has been emitted by PubNub client. + * + * Value will be reset when current request processing completed or client "disconnected" (not interested in + * real-time updates). + */ + request?: TransportRequest; + + /** + * Identifier of subscribe request which has been actually sent by Service Worker. + * + * **Note:** Value not set if client not interested in any real-time updates. + */ + serviceRequestId?: string; + + /** + * Real-time events filtering expression. + */ + filterExpression?: string; + }; +}; +// endregion +// endregion + +// -------------------------------------------------------- +// ------------------- Service Worker --------------------- +// -------------------------------------------------------- +// region Service Worker + +declare const self: ServiceWorkerGlobalScope; + +// region State +/** + * Service `ArrayBuffer` response decoder. + */ +const decoder = new TextDecoder(); + +/** + * Map of identifiers, scheduled by the Service Worker, to their abort controllers. + * + * **Note:** Because of message-based nature of interaction it will be impossible to pass actual {@link AbortController} + * to the transport provider code. + */ +const abortControllers: Map = new Map(); + +/** + * Map of PubNub client identifiers to their state in the current Service Worker. + */ +const pubNubClients: Record = {}; + +/** + * Per-subscription key list of PubNub client state. + */ +const pubNubClientsBySubscriptionKey: { [subscriptionKey: string]: PubNubClientState[] | undefined } = {}; + +/** + * Per-subscription key presence state associated with unique user identifiers with which {@link pubNubClients|clients} + * scheduled subscription request. + */ +const presenceState: { + [subscriptionKey: string]: + | { + [userId: string]: Record | undefined; + } + | undefined; +} = {}; + +/** + * Per-subscription key map of client identifiers to the Service Worker {@link Client} identifier. + * + * Service Worker {@link Client} represent pages at which PubNub clients registered Service Workers. + */ +const serviceWorkerClients: { + [subscriptionKey: string]: { [clientId: string]: string | undefined } | undefined; +} = {}; + +/** + * List of ongoing subscription requests. + * + * **Node:** Identifiers differ from request identifiers received in {@link SendRequestEvent} object. + */ +const serviceRequests: { + [requestId: string]: { + /** + * Unique active request identifier. + */ + requestId: string; + + /** + * Timetoken which is used for subscription loop. + */ + timetoken: string; + + /** + * List of channels used in current subscription session. + */ + channels: string[]; + + /** + * List of channel groups used in current subscription session. + */ + channelGroups: string[]; + }; +} = {}; +// endregion + +// -------------------------------------------------------- +// ------------------- Event Handlers --------------------- +// -------------------------------------------------------- +// region Event Handlers + +/** + * Listen for Service Worker activation. + */ +self.addEventListener('activate', (event) => { + event.waitUntil(self.clients.claim()); +}); + +/** + * Listen for events from the client. + */ +self.addEventListener('message', (event) => { + // Ignoring requests sent from other service workers. + if (!validateEventPayload(event)) return; + + const data = event.data as ClientEvent; + + if (data.type === 'send-request') { + if (data.request.path.startsWith('/v2/subscribe')) { + registerClientIfRequired(event); + handleSendSubscribeRequestEvent(data); + } else { + if (!pubNubClients[data.clientIdentifier]) registerClientIfRequired(event); + handleSendLeaveRequestEvent(event); + } + } else if (data.type === 'cancel-request') handleCancelRequestEvent(data); +}); + +/** + * Handle client request to send subscription request. + * + * @param event - Subscription event details. + */ +const handleSendSubscribeRequestEvent = (event: SendRequestEvent) => { + const requestOrId = subscribeTransportRequestFromEvent(event); + const client = pubNubClients[event.clientIdentifier]; + + if (client) notifyRequestProcessing('start', [client], new Date().toISOString()); + + if (typeof requestOrId === 'string') { + if (client) { + // Updating client timetoken information. + client.subscription.previousTimetoken = client.subscription.timetoken; + client.subscription.timetoken = serviceRequests[requestOrId].timetoken; + client.subscription.serviceRequestId = requestOrId; + } + return; + } + + if (event.request.cancellable) abortControllers.set(requestOrId.identifier, new AbortController()); + + sendRequest( + requestOrId, + () => clientsForRequest(requestOrId.identifier), + (clients, response) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, response); + + // Clean up scheduled request and client references to it. + markRequestCompleted(clients, requestOrId.identifier); + }, + (clients, error) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, null, requestOrId, requestProcessingError(error)); + + // Clean up scheduled request and client references to it. + markRequestCompleted(clients, requestOrId.identifier); + }, + ); +}; + +/** + * Handle client request to leave request. + * + * @param event - Leave event details. + */ +const handleSendLeaveRequestEvent = (event: ExtendableMessageEvent) => { + const data = event.data as SendRequestEvent; + const request = leaveTransportRequestFromEvent(data); + const client = pubNubClients[data.clientIdentifier]; + + if (!client) return; + if (!request) { + const body = new TextEncoder().encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'); + const headers = new Headers({ 'Content-Type': 'text/javascript; charset="UTF-8"', 'Content-Length': '74' }); + const response = new Response(body, { status: 200, headers }); + const result = requestProcessingSuccess([response, body]); + result.url = `${data.request.origin}${data.request.path}`; + result.clientIdentifier = data.clientIdentifier; + result.identifier = data.request.identifier; + + publishClientEvent((event.source! as Client).id, result).then((sent) => { + if (sent) invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); + }); + return; + } + + sendRequest( + request, + () => [client], + (clients, response) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, response, data.request); + }, + (clients, error) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, null, data.request, requestProcessingError(error)); + }, + ); +}; + +/** + * Handle cancel request event. + * + * Try cancel request if there is no other observers. + * + * @param event - Request cancellation event details. + */ +const handleCancelRequestEvent = (event: CancelRequestEvent) => { + const client = pubNubClients[event.clientIdentifier]; + const serviceRequestId = client ? client.subscription.serviceRequestId : undefined; + if (!client || !serviceRequestId) return; + + // Unset awaited requests. + delete client.subscription.serviceRequestId; + delete client.subscription.request; + + if (clientsForRequest(serviceRequestId).length === 0) { + const controller = abortControllers.get(serviceRequestId); + abortControllers.delete(serviceRequestId); + + // Clean up scheduled requests. + delete serviceRequests[serviceRequestId]; + + // Abort request if possible. + if (controller) controller.abort(); + } +}; +// endregion + +// -------------------------------------------------------- +// ------------------------ Common ------------------------ +// -------------------------------------------------------- +// region Common + +/** + * Process transport request. + * + * @param request - Transport request with required information for {@link Request} creation. + * @param getClients - Request completion PubNub client observers getter. + * @param success - Request success completion handler. + * @param failure - Request failure handler. + */ +const sendRequest = ( + request: TransportRequest, + getClients: () => PubNubClientState[], + success: (clients: PubNubClientState[], response: [Response, ArrayBuffer]) => void, + failure: (clients: PubNubClientState[], error: unknown) => void, +) => { + (async () => { + // Request progress support. + const start = new Date().getTime(); + + Promise.race([ + fetch(requestFromTransportRequest(request), { + signal: abortControllers.get(request.identifier)?.signal, + keepalive: true, + }), + requestTimeoutTimer(request.identifier, request.timeout), + ]) + .then((response): Promise<[Response, ArrayBuffer]> | [Response, ArrayBuffer] => + response.arrayBuffer().then((buffer) => [response, buffer]), + ) + .then((response) => { + const responseBody = response[1].byteLength > 0 ? response[1] : undefined; + + const clients = getClients(); + if (clients.length === 0) return; + + notifyRequestProcessing( + 'end', + clients, + new Date().toISOString(), + request, + responseBody, + response[0].headers.get('Content-Type'), + new Date().getTime() - start, + ); + + success(clients, response); + }) + .catch((error) => { + const clients = getClients(); + if (clients.length === 0) return; + + failure(clients, error); + }); + })(); +}; + +/** + * Create request timeout timer. + * + * **Note:** Native Fetch API doesn't support `timeout` out-of-box and {@link Promise} used to emulate it. + * + * @param requestId - Unique identifier of request which will time out after {@link requestTimeout} seconds. + * @param requestTimeout - Number of seconds after which request with specified identifier will time out. + * + * @returns Promise which rejects after time out will fire. + */ +const requestTimeoutTimer = (requestId: string, requestTimeout: number) => + new Promise((_, reject) => { + const timeoutId = setTimeout(() => { + // Clean up. + abortControllers.delete(requestId); + clearTimeout(timeoutId); + + reject(new Error('Request timeout')); + }, requestTimeout * 1000); + }); + +/** + * Retrieve list of PubNub clients which is pending for service worker request completion. + * + * @param identifier - Identifier of the subscription request which has been scheduled by the Service Worker. + * + * @returns List of PubNub client state objects for Service Worker. + */ +const clientsForRequest = (identifier: string) => { + return Object.values(pubNubClients).filter( + (client): client is PubNubClientState => + client !== undefined && client.subscription.serviceRequestId === identifier, + ); +}; + +/** + * Clean up PubNub client states from ongoing request. + * + * Reset requested and scheduled request information to make PubNub client "free" for neext requests. + * + * @param clients - List of PubNub clients which awaited for scheduled request completion. + * @param requestId - Unique subscribe request identifier for which {@link clients} has been provided. + */ +const markRequestCompleted = (clients: PubNubClientState[], requestId: string) => { + delete serviceRequests[requestId]; + + clients.forEach((client) => { + delete client.subscription.request; + delete client.subscription.serviceRequestId; + }); +}; + +/** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns `Request` object generated from the {@link TransportRequest} object or `undefined` if no request + * should be sent. + */ +const requestFromTransportRequest = (req: TransportRequest): Request => { + let headers: Record | undefined = undefined; + const queryParameters = req.queryParameters; + let path = req.path; + + if (req.headers) { + headers = {}; + for (const [key, value] of Object.entries(req.headers)) headers[key] = value; + } + + if (queryParameters && Object.keys(queryParameters).length !== 0) + path = `${path}?${queryStringFromObject(queryParameters)}`; + + return new Request(`${req.origin!}${path}`, { + method: req.method, + headers, + redirect: 'follow', + }); +}; + +/** + * Construct transport request from send subscription request event. + * + * Update transport request to aggregate channels and groups if possible. + * + * @param event - Client's send subscription event request. + * + * @returns Final transport request or identifier from active request which will provide response to required + * channels and groups. + */ +const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportRequest | string => { + const client = pubNubClients[event.clientIdentifier]!; + const clients = clientsForSendSubscribeRequestEvent(client.subscription.previousTimetoken, event); + const serviceRequestId = uuidGenerator.createUUID(); + const request = { ...event.request }; + + if (clients.length > 1) { + const activeRequestId = activeSubscriptionForEvent(clients, event); + + // Return identifier of the ongoing request. + if (activeRequestId) return activeRequestId; + + const state = (presenceState[client.subscriptionKey] ?? {})[client.userId]; + const aggregatedState: Record = {}; + const channelGroups = new Set(client.subscription.channelGroups); + const channels = new Set(client.subscription.channels); + + if (state && client.subscription.objectsWithState.length) { + client.subscription.objectsWithState.forEach((name) => { + const objectState = state[name]; + if (objectState) aggregatedState[name] = objectState; + }); + } + + for (const client of clients) { + const { subscription } = client!; + // Skip clients which already have active subscription request. + if (subscription.serviceRequestId) continue; + + subscription.channelGroups.forEach(channelGroups.add, channelGroups); + subscription.channels.forEach(channels.add, channels); + + // Set awaited service worker request identifier. + subscription.serviceRequestId = serviceRequestId; + + if (!state) continue; + + subscription.objectsWithState.forEach((name) => { + const objectState = state[name]; + + if (objectState && !aggregatedState[name]) aggregatedState[name] = objectState; + }); + } + + const serviceRequest = (serviceRequests[serviceRequestId] ??= { + requestId: serviceRequestId, + timetoken: (request.queryParameters!.tt as string) ?? '0', + channelGroups: [], + channels: [], + }); + + // Update request channels list (if required). + if (channels.size) { + serviceRequest.channels = Array.from(channels).sort(); + const pathComponents = request.path.split('/'); + pathComponents[4] = serviceRequest.channels.join(','); + request.path = pathComponents.join('/'); + } + + // Update request channel groups list (if required). + if (channelGroups.size) { + serviceRequest.channelGroups = Array.from(channelGroups).sort(); + request.queryParameters!['channel-group'] = serviceRequest.channelGroups.join(','); + } + + // Update request `state` (if required). + if (Object.keys(aggregatedState).length) request.queryParameters!['state'] = JSON.stringify(aggregatedState); + } else { + serviceRequests[serviceRequestId] = { + requestId: serviceRequestId, + timetoken: (request.queryParameters!.tt as string) ?? '0', + channelGroups: client.subscription.channelGroups, + channels: client.subscription.channels, + }; + } + + client.subscription.serviceRequestId = serviceRequestId; + request.identifier = serviceRequestId; + + return request; +}; + +/** + * Construct transport request from send leave request event. + * + * Filter out channels and groups, which is still in use by other PubNub client instances from leave request. + * + * @param event - Client's send leave event request. + * + * @returns Final transport request or `undefined` in case if there is no channels and groups for which request can be + * done. + */ +const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportRequest | undefined => { + const client = pubNubClients[event.clientIdentifier]; + const clients = clientsForSendLeaveRequestEvent(event); + let channelGroups = channelGroupsFromRequest(event.request); + let channels = channelsFromRequest(event.request); + const request = { ...event.request }; + + if (client) { + const { subscription } = client; + if (channels.length) subscription.channels = subscription.channels.filter((channel) => !channels.includes(channel)); + if (channelGroups.length) { + subscription.channelGroups = subscription.channelGroups.filter((group) => !channelGroups.includes(group)); + } + } + + // Filter out channels and groups which is still in use by the other PubNub client instances. + for (const client of clients) { + if (client.clientIdentifier === event.clientIdentifier) continue; + if (channels.length) channels = channels.filter((channel) => !client.subscription.channels.includes(channel)); + if (channelGroups.length) + channelGroups = channelGroups.filter((group) => !client.subscription.channelGroups.includes(group)); + } + + if (channels.length === 0 && channelGroups.length === 0) return undefined; + + // Update request channels list (if required). + if (channels.length) { + const pathComponents = request.path.split('/'); + pathComponents[4] = channels.join(','); + request.path = pathComponents.join('/'); + } + + // Update request channel groups list (if required). + if (channelGroups.length) request.queryParameters!['channel-group'] = channelGroups.join(','); + + return request; +}; + +/** + * Send event to all service worker clients. + * + * @param identifier - Service Worker receiving {@link Client} identifier. + * @param event - Service worker event object. + */ +const publishClientEvent = (identifier: string, event: ServiceWorkerEvent) => { + return self.clients.get(identifier).then((client) => { + if (!client) return false; + + client.postMessage(event); + return true; + }); +}; + +/** + * Send request processing update. + * + * @param type - Type of processing event. + * @param clients - List of PubNub clients which should be notified about request progress. + * @param timestamp - Date and time when request processing update happened. + * @param [request] - Processed request information. + * @param [responseBody] - PubNub service response. + * @param [contentType] - PubNub service response content type. + * @param [duration] - How long it took to complete request. + */ +const notifyRequestProcessing = ( + type: 'start' | 'end', + clients: PubNubClientState[], + timestamp: string, + request?: TransportRequest, + responseBody?: ArrayBuffer, + contentType?: string | null, + duration?: number, +) => { + if (clients.length === 0) return; + + const clientIds = serviceWorkerClients[clients[0].subscriptionKey] ?? {}; + let event: RequestSendingProgress; + + if (type === 'start') { + event = { + type: 'request-progress-start', + clientIdentifier: '', + url: '', + timestamp, + }; + } else { + let response: string | undefined; + if ( + responseBody && + contentType && + (contentType.indexOf('text/javascript') !== -1 || + contentType.indexOf('application/json') !== -1 || + contentType.indexOf('text/plain') !== -1 || + contentType.indexOf('text/html') !== -1) + ) { + response = decoder.decode(responseBody); + } + + event = { + type: 'request-progress-end', + clientIdentifier: '', + url: '', + response, + timestamp, + duration: duration!, + }; + } + + clients.forEach((client) => { + const serviceWorkerClientId = clientIds[client.clientIdentifier]; + const { request: clientRequest } = client.subscription; + const decidedRequest = clientRequest ?? request; + + if (client.logVerbosity && serviceWorkerClientId && decidedRequest) { + publishClientEvent(serviceWorkerClientId, { + ...event, + clientIdentifier: client.clientIdentifier, + url: `${decidedRequest.origin}${decidedRequest.path}`, + query: decidedRequest.queryParameters, + }).then((sent) => { + if (sent) invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); + }); + } + }); +}; + +/** + * Send request processing result event. + * + * @param clients - List of PubNub clients which should be notified about request result. + * @param [response] - PubNub service response. + * @param [request] - Processed request information. + * @param [result] - Explicit request processing result which should be notified. + */ +const notifyRequestProcessingResult = ( + clients: PubNubClientState[], + response: [Response, ArrayBuffer] | null, + request?: TransportRequest, + result?: RequestSendingResult, +) => { + if (clients.length === 0) return; + if (!result && !response) return; + + const clientIds = serviceWorkerClients[clients[0].subscriptionKey] ?? {}; + + if (!result && response) { + result = + response[0].status >= 400 + ? // Treat 4xx and 5xx status codes as errors. + requestProcessingError(undefined, response) + : requestProcessingSuccess(response); + } + + clients.forEach((client) => { + const serviceWorkerClientId = clientIds[client.clientIdentifier]; + const { request: clientRequest } = client.subscription; + const decidedRequest = clientRequest ?? request; + + if (serviceWorkerClientId && decidedRequest) { + publishClientEvent(serviceWorkerClientId, { + ...result!, + clientIdentifier: client.clientIdentifier, + identifier: decidedRequest.identifier, + url: `${decidedRequest.origin}${decidedRequest.path}`, + }).then((sent) => { + if (sent) invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); + }); + } + }); +}; + +/** + * Create processing success event from service response. + * + * **Note:** The rest of information like `clientIdentifier`,`identifier`, and `url` will be added later for each + * specific PubNub client state. + * + * @param res - Service response for used REST API endpoint along with response body. + * + * @returns Request processing success event object. + */ +const requestProcessingSuccess = (res: [Response, ArrayBuffer]): RequestSendingSuccess => { + const [response, body] = res; + const responseBody = body.byteLength > 0 ? body : undefined; + const contentLength = parseInt(response.headers.get('Content-Length') ?? '0', 10); + const contentType = response.headers.get('Content-Type')!; + const headers: Record = {}; + + // Copy Headers object content into plain Record. + response.headers.forEach((value, key) => (headers[key] = value.toLowerCase())); + + return { + type: 'request-process-success', + clientIdentifier: '', + identifier: '', + url: '', + response: { + contentLength, + contentType, + headers, + status: response.status, + body: responseBody, + }, + }; +}; + +/** + * Create processing error event from service response. + * + * **Note:** The rest of information like `clientIdentifier`,`identifier`, and `url` will be added later for each + * specific PubNub client state. + * + * @param [error] - Client-side request processing error (for example network issues). + * @param [res] - Service error response (for example permissions error or malformed + * payload) along with service body. + * + * @returns Request processing error event object. + */ +const requestProcessingError = (error?: unknown, res?: [Response, ArrayBuffer]): RequestSendingError => { + // User service response as error information source. + if (res) { + return { + ...requestProcessingSuccess(res), + type: 'request-process-error', + }; + } + + let type: NonNullable['type'] = 'NETWORK_ISSUE'; + let message = 'Unknown error'; + let name = 'Error'; + + if (error && error instanceof Error) { + message = error.message; + name = error.name; + } + + if (name === 'AbortError') { + message = 'Request aborted'; + type = 'ABORTED'; + } else if (message === 'Request timeout') type = 'TIMEOUT'; + + return { + type: 'request-process-error', + clientIdentifier: '', + identifier: '', + url: '', + error: { name, type, message }, + }; +}; +// endregion + +// -------------------------------------------------------- +// ----------------------- Helpers ------------------------ +// -------------------------------------------------------- +// region Helpers + +/** + * Register client if it didn't use Service Worker before. + * + * The registration process updates the Service Worker state with information about channels and groups in which + * particular PubNub clients are interested, and uses this information when another subscribe request is made to build + * shared requests. + * + * @param event - Base information about PubNub client instance and Service Worker {@link Client}. + */ +const registerClientIfRequired = (event: ExtendableMessageEvent) => { + const information = event.data as SendRequestEvent; + const { clientIdentifier } = information; + const query = information.request.queryParameters!; + + let client = pubNubClients[clientIdentifier]; + + if (!client) { + const isPresenceLeave = !information.request.path.startsWith('/v2/subscribe'); + const channelGroupQuery = !isPresenceLeave ? ((query!['channel-group'] ?? '') as string) : ''; + const state = !isPresenceLeave ? ((query.state ?? '') as string) : ''; + + client = pubNubClients[clientIdentifier] = { + clientIdentifier, + subscriptionKey: information.subscriptionKey, + userId: query.uuid as string, + authKey: (query.auth ?? '') as string, + logVerbosity: information.logVerbosity, + subscription: { + path: !isPresenceLeave ? information.request.path : '', + channelGroupQuery: !isPresenceLeave ? channelGroupQuery : '', + channels: !isPresenceLeave ? channelsFromRequest(information.request) : [], + channelGroups: !isPresenceLeave ? channelGroupsFromRequest(information.request) : [], + previousTimetoken: !isPresenceLeave ? ((query.tt ?? '0') as string) : '0', + timetoken: !isPresenceLeave ? ((query.tt ?? '0') as string) : '0', + request: !isPresenceLeave ? information.request : undefined, + objectsWithState: [], + filterExpression: !isPresenceLeave ? ((query['filter-expr'] ?? '') as string) : undefined, + }, + }; + + if (!isPresenceLeave && state.length > 0) { + const parsedState = JSON.parse(state) as Record; + const userState = ((presenceState[client.subscriptionKey] ??= {})[client.userId] ??= {}); + + Object.entries(parsedState).forEach(([objectName, value]) => (userState[objectName] = value)); + client.subscription.objectsWithState = Object.keys(parsedState); + } + + // Map registered PubNub client to its subscription key. + const clientsBySubscriptionKey = (pubNubClientsBySubscriptionKey[information.subscriptionKey] ??= []); + if (clientsBySubscriptionKey.every((entry) => entry.clientIdentifier !== clientIdentifier)) + clientsBySubscriptionKey.push(client); + + // Binding PubNub client to the page (Service Worker Client). + (serviceWorkerClients[information.subscriptionKey] ??= {})[clientIdentifier] = (event.source! as Client).id; + } else { + const channelGroupQuery = (query!['channel-group'] ?? '') as string; + const state = (query.state ?? '') as string; + client.subscription.filterExpression = (query['filter-expr'] ?? '') as string; + client.subscription.previousTimetoken = client.subscription.timetoken; + client.subscription.timetoken = (query.tt ?? '0') as string; + client.subscription.request = information.request; + client.authKey = (query.auth ?? '') as string; + client.userId = query.uuid as string; + + if (client.subscription.path !== information.request.path) { + client.subscription.path = information.request.path; + client.subscription.channels = channelsFromRequest(information.request); + } + + if (client.subscription.channelGroupQuery !== channelGroupQuery) { + client.subscription.channelGroupQuery = channelGroupQuery; + client.subscription.channelGroups = channelGroupsFromRequest(information.request); + } + + if (state.length > 0) { + const parsedState = JSON.parse(state) as Record; + const userState = ((presenceState[client.subscriptionKey] ??= {})[client.userId] ??= {}); + Object.entries(parsedState).forEach(([objectName, value]) => (userState[objectName] = value)); + + // Clean up state for objects where presence state has been reset. + for (const objectName of client.subscription.objectsWithState) + if (!parsedState[objectName]) delete userState[objectName]; + client.subscription.objectsWithState = Object.keys(parsedState); + } + // Handle potential presence state reset. + else if (client.subscription.objectsWithState.length) { + const userState = ((presenceState[client.subscriptionKey] ??= {})[client.userId] ??= {}); + + for (const objectName of client.subscription.objectsWithState) delete userState[objectName]; + client.subscription.objectsWithState = []; + } + } +}; + +/** + * Clean up resources used by registered PubNub client instance. + * + * @param subscriptionKey - Subscription key which has been used by the + * invalidated instance. + * @param clientId - Unique PubNub client identifier. + * @param userId - Unique identifier of the user used by PubNub client instance. + */ +const invalidateClient = (subscriptionKey: string, clientId: string, userId: string) => { + delete pubNubClients[clientId]; + let clients = pubNubClientsBySubscriptionKey[subscriptionKey]; + + if (clients) { + // Clean up linkage between client and subscription key. + clients = clients.filter((client) => client.clientIdentifier !== clientId); + if (clients.length > 0) pubNubClientsBySubscriptionKey[subscriptionKey] = clients; + else delete pubNubClientsBySubscriptionKey[subscriptionKey]; + + // Clean up presence state information if not in use anymore. + if (clients.length === 0) delete presenceState[subscriptionKey]; + + // Clean up service workers client linkage to PubNub clients. + if (clients.length > 0) { + const workerClients = serviceWorkerClients[subscriptionKey]; + if (workerClients) { + delete workerClients[clientId]; + + if (Object.keys(workerClients).length === 0) delete serviceWorkerClients[subscriptionKey]; + } + } else delete serviceWorkerClients[subscriptionKey]; + } +}; + +/** + * Validate received event payload. + */ +const validateEventPayload = (event: ExtendableMessageEvent): boolean => { + if (!event.source || !(event.source instanceof Client)) return false; + const data = event.data as ClientEvent; + + const { clientIdentifier, subscriptionKey, logVerbosity } = data as ClientEvent; + if (logVerbosity === undefined || typeof logVerbosity !== 'boolean') return false; + if (!clientIdentifier || typeof clientIdentifier !== 'string') return false; + + return !(!subscriptionKey || typeof subscriptionKey !== 'string'); +}; + +/** + * Search for active subscription for one of the passed {@link serviceWorkerClients}. + * + * @param activeClients - List of suitable registered PubNub clients. + * @param event - Send Subscriber Request event data. + * + * @returns Unique identifier of the active request which will receive real-time updates for channels and groups + * requested in received subscription request or `undefined` if none of active (or not scheduled) request can be used. + */ +const activeSubscriptionForEvent = ( + activeClients: PubNubClientState[], + event: SendRequestEvent, +): string | undefined => { + const query = event.request.queryParameters!; + const channelGroupQuery = (query['channel-group'] ?? '') as string; + const requestPath = event.request.path; + let channelGroups: string[] | undefined; + let channels: string[] | undefined; + + for (const client of activeClients) { + const { subscription } = client; + // Skip PubNub clients which doesn't await for subscription response. + if (!subscription.serviceRequestId) continue; + + if (subscription.path === requestPath && subscription.channelGroupQuery === channelGroupQuery) { + return subscription.serviceRequestId; + } else { + const scheduledRequest = serviceRequests[subscription.serviceRequestId]; + if (!channelGroups) channelGroups = channelGroupsFromRequest(event.request); + if (!channels) channels = channelsFromRequest(event.request); + + // Checking whether all required channels and groups are handled already by active request or not. + if (channels.length && !includesStrings(scheduledRequest.channels, channels)) continue; + if (channelGroups.length && !includesStrings(scheduledRequest.channelGroups, channelGroups)) continue; + + return subscription.serviceRequestId; + } + } + + return undefined; +}; + +/** + * Find PubNub client states with configuration compatible with the one in request. + * + * Method allow to find information about all PubNub client instances which use same: + * - subscription key + * - `userId` + * - `auth` key + * - `filter expression` + * - `timetoken` (compare should be done against previous timetoken of the client which requested new subscribe). + * + * @param timetoken - Previous timetoken used by the PubNub client which requested to send new subscription request + * (it will be the same as 'current' timetoken of the other PubNub clients). + * @param event - Send subscribe request event information. + * + * @returns List of PubNub client states which works from other pages for the same user. + */ +const clientsForSendSubscribeRequestEvent = (timetoken: string, event: SendRequestEvent) => { + const query = event.request.queryParameters!; + const filterExpression = (query['filter-expr'] ?? '') as string; + const authKey = (query.auth ?? '') as string; + const userId = query.uuid! as string; + + return (pubNubClientsBySubscriptionKey[event.subscriptionKey] ?? []).filter( + (client) => + client.userId === userId && + client.authKey === authKey && + client.subscription.filterExpression === filterExpression && + (timetoken === '0' || + client.subscription.previousTimetoken === '0' || + client.subscription.previousTimetoken === timetoken), + ); +}; + +/** + * Find PubNub client states with configuration compatible with the one in request. + * + * Method allow to find information about all PubNub client instances which use same: + * - subscription key + * - `userId` + * - `auth` key + * + * @param event - Send leave request event information. + * + * @returns List of PubNub client states which works from other pages for the same user. + */ +const clientsForSendLeaveRequestEvent = (event: SendRequestEvent) => { + const query = event.request.queryParameters!; + const authKey = (query.auth ?? '') as string; + const userId = query.uuid! as string; + + return (pubNubClientsBySubscriptionKey[event.subscriptionKey] ?? []).filter( + (client) => client.userId === userId && client.authKey === authKey, + ); +}; + +/** + * Extract list of channels from request URI path. + * + * @param request - Transport request which should provide `path` for parsing. + * + * @returns List of channel names (not percent-decoded) for which `subscribe` or `leave` has been called. + */ +const channelsFromRequest = (request: TransportRequest): string[] => { + const channels = request.path.split('/')[request.path.startsWith('/v2/subscribe/') ? 4 : 6]; + return channels === ',' ? [] : channels.split(',').filter((name) => name.length > 0); +}; + +/** + * Extract list of channel groups from request query. + * + * @param request - Transport request which should provide `query` for parsing. + * + * @returns List of channel group names (not percent-decoded) for which `subscribe` or `leave` has been called. + */ +const channelGroupsFromRequest = (request: TransportRequest): string[] => { + const group = (request.queryParameters!['channel-group'] ?? '') as string; + return group.length === 0 ? [] : group.split(',').filter((name) => name.length > 0); +}; + +/** + * Check whether {@link main} array contains all entries from {@link sub} array. + * + * @param main - Main array with which `intersection` with {@link sub} should be checked. + * @param sub - Sub-array whose values should be checked in {@link main}. + * + * @returns `true` if all entries from {@link sub} is present in {@link main}. + */ +const includesStrings = (main: string[], sub: string[]) => { + const set = new Set(main); + return sub.every(set.has, set); +}; + +/** + * Stringify request query key / value pairs. + * + * @param query - Request query object. + * + * @returns Stringified query object. + */ +const queryStringFromObject = (query: Query) => { + return Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) return `${key}=${encodeString(queryValue)}`; + + return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); + }) + .join('&'); +}; + +/** + * Percent-encode input string. + * + * **Note:** Encode content in accordance of the `PubNub` service requirements. + * + * @param input - Source string or number for encoding. + * + * @returns Percent-encoded string. + */ +const encodeString = (input: string | number) => { + return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); +}; +// endregion +// endregion diff --git a/src/transport/titanium-transport.ts b/src/transport/titanium-transport.ts new file mode 100644 index 000000000..8836dbcec --- /dev/null +++ b/src/transport/titanium-transport.ts @@ -0,0 +1,173 @@ +/** global Ti */ + +/** + * Titanium Transport provider module. + */ + +import { CancellationController, TransportRequest } from '../core/types/transport-request'; +import { TransportResponse } from '../core/types/transport-response'; +import { PubNubAPIError } from '../errors/pubnub-api-error'; +import { Transport } from '../core/interfaces/transport'; +import { queryStringFromObject } from '../core/utils'; + +/** + * Class representing a {@link Ti.Network.HTTPClient|HTTPClient}-based Titanium transport provider. + */ +export class TitaniumTransport implements Transport { + /** + * Service {@link ArrayBuffer} response decoder. + */ + protected static decoder = new TextDecoder(); + + /** + * Create a new `Ti.Network.HTTPClient`-based transport instance. + * + * @param keepAlive - Indicates whether keep-alive should be enabled. + * @param [logVerbosity] - Whether verbose logging enabled or not. + * + * @returns Transport for performing network requests. + */ + constructor( + private readonly keepAlive: boolean = false, + private readonly logVerbosity: boolean = false, + ) {} + + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { + const [xhr, url, body] = this.requestFromTransportRequest(req); + let controller: CancellationController | undefined; + let aborted = false; + + if (req.cancellable) { + controller = { + abort: () => { + aborted = true; + xhr.abort(); + }, + }; + } + + return [ + new Promise((resolve, reject) => { + const start = new Date().getTime(); + + this.logRequestProcessProgress(url); + + xhr.onload = () => { + const response = this.transportResponseFromXHR(url, xhr); + + this.logRequestProcessProgress(url, new Date().getTime() - start, response.body); + resolve(response); + }; + + xhr.onerror = () => { + const elapsed = new Date().getTime() - start; + let body: ArrayBuffer | undefined; + let error: PubNubAPIError; + + if (aborted) { + error = PubNubAPIError.create(new Error('Aborted')); + } else if (xhr.timeout >= elapsed - 100) { + error = PubNubAPIError.create(new Error('Request timeout')); + } else if (xhr.status === 0) { + error = PubNubAPIError.create(new Error('Request failed because of network issues')); + } else { + const response = this.transportResponseFromXHR(url, xhr); + error = PubNubAPIError.create(response); + body = response.body; + } + + this.logRequestProcessProgress(url, elapsed, body); + + reject(error); + }; + + xhr.send(body); + }), + controller, + ]; + } + + request(req: TransportRequest): TransportRequest { + return req; + } + + /** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param request - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + */ + private requestFromTransportRequest( + request: TransportRequest, + ): [Ti.Network.HTTPClient, string, string | ArrayBuffer | undefined] { + const xhr = Ti.Network.createHTTPClient({ timeout: request.timeout * 1000, enableKeepAlive: this.keepAlive }); + let body: string | ArrayBuffer | undefined; + let path = request.path; + + if (request.queryParameters && Object.keys(request.queryParameters).length !== 0) + path = `${path}?${queryStringFromObject(request.queryParameters)}`; + const url = `${request.origin!}${path}`; + + // Initiate XHR request. + xhr.open(request.method, url, true); + + // Append HTTP headers (if required). + for (const [key, value] of Object.entries(request.headers ?? {})) xhr.setRequestHeader(key, value); + + if (request.body && (typeof request.body === 'string' || request.body instanceof ArrayBuffer)) body = request.body; + + return [xhr, url, body]; + } + + /** + * Create service response from {@link Ti.Network.HTTPClient|HTTPClient} processing result. + * + * @param url - Used endpoint url. + * @param xhr - `HTTPClient` which has been used to make a request. + * + * @returns Pre-processed transport response. + */ + private transportResponseFromXHR(url: string, xhr: Ti.Network.HTTPClient): TransportResponse { + const allHeaders = xhr.getAllResponseHeaders().split('\n'); + const headers: Record = {}; + + for (const header of allHeaders) { + const [key, value] = header.trim().split(':'); + if (key && value) headers[key.toLowerCase()] = value.trim(); + } + + return { status: xhr.status, url, headers, body: xhr.responseData.toArrayBuffer() }; + } + + /** + * Log out request processing progress and result. + * + * @param url - Endpoint Url used by {@link Ti.Network.HTTPClient|HTTPClient}. + * @param [elapsed] - How many times passed since request processing started. + * @param [body] - Service response (if available). + */ + private logRequestProcessProgress(url: string, elapsed?: number, body?: ArrayBuffer) { + if (!this.logVerbosity) return; + + const { protocol, host, pathname, search } = new URL(url); + const timestamp = new Date().toISOString(); + + if (!elapsed) { + Ti.API.info('<<<<<'); + Ti.API.info([`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`]); + Ti.API.info('-----'); + } else { + const stringifiedBody = body ? TitaniumTransport.decoder.decode(body) : undefined; + + Ti.API.info('>>>>>>'); + Ti.API.info([ + `[${timestamp} / ${elapsed}]`, + `\n${protocol}//${host}${pathname}`, + `\n${search}`, + `\n${stringifiedBody}`, + ]); + Ti.API.info('-----'); + } + } +} diff --git a/src/transport/web-react-native-transport.ts b/src/transport/web-react-native-transport.ts new file mode 100644 index 000000000..39b8dc686 --- /dev/null +++ b/src/transport/web-react-native-transport.ts @@ -0,0 +1,172 @@ +/** + * Common browser and React Native Transport provider module. + */ + +import { CancellationController, TransportRequest } from '../core/types/transport-request'; +import { TransportResponse } from '../core/types/transport-response'; +import { PubNubAPIError } from '../errors/pubnub-api-error'; +import { Transport } from '../core/interfaces/transport'; +import { PubNubFileInterface } from '../core/types/file'; +import { queryStringFromObject } from '../core/utils'; + +/** + * Class representing a `fetch`-based browser and React Native transport provider. + */ +export class WebReactNativeTransport implements Transport { + /** + * Service {@link ArrayBuffer} response decoder. + */ + protected static decoder = new TextDecoder(); + + constructor( + private keepAlive: boolean = false, + private readonly logVerbosity: boolean, + ) {} + + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { + let controller: CancellationController | undefined; + let abortController: AbortController | undefined; + + if (req.cancellable) { + abortController = new AbortController(); + controller = { + // Storing controller inside to prolong object lifetime. + abortController, + abort: () => abortController?.abort(), + } as CancellationController; + } + + return [ + this.requestFromTransportRequest(req).then((request) => { + const start = new Date().getTime(); + + this.logRequestProcessProgress(request); + + /** + * Setup request timeout promise. + * + * **Note:** Native Fetch API doesn't support `timeout` out-of-box. + */ + const requestTimeout = new Promise((_, reject) => { + const timeoutId = setTimeout(() => { + // Clean up. + clearTimeout(timeoutId); + + reject(new Error('Request timeout')); + }, req.timeout * 1000); + }); + + return Promise.race([fetch(request, { signal: abortController?.signal }), requestTimeout]) + .then((response): Promise<[Response, ArrayBuffer]> | [Response, ArrayBuffer] => + response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer]), + ) + .then((response) => { + const responseBody = response[1].byteLength > 0 ? response[1] : undefined; + const { status, headers: requestHeaders } = response[0]; + const headers: Record = {}; + + // Copy Headers object content into plain Record. + requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); + + const transportResponse: TransportResponse = { + status, + url: request.url, + headers, + body: responseBody, + }; + + if (status >= 400) throw PubNubAPIError.create(transportResponse); + + this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + + return transportResponse; + }) + .catch((error) => { + throw PubNubAPIError.create(error); + }); + }), + controller, + ]; + } + + request(req: TransportRequest): TransportRequest { + return req; + } + + /** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + */ + private async requestFromTransportRequest(req: TransportRequest): Promise { + let body: string | ArrayBuffer | FormData | undefined; + let path = req.path; + + // Create multipart request body. + if (req.formData && req.formData.length > 0) { + // Reset query parameters to conform to signed URL + req.queryParameters = {}; + + const file = req.body as PubNubFileInterface; + const formData = new FormData(); + for (const { key, value } of req.formData) formData.append(key, value); + try { + const fileData = await file.toArrayBuffer(); + formData.append('file', new Blob([fileData], { type: 'application/octet-stream' }), file.name); + } catch (_) { + try { + const fileData = await file.toFileUri(); + // @ts-expect-error React Native File Uri support. + formData.append('file', fileData, file.name); + } catch (_) {} + } + + body = formData; + } + // Handle regular body payload (if passed). + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) body = req.body; + + if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) + path = `${path}?${queryStringFromObject(req.queryParameters)}`; + + return new Request(`${req.origin!}${path}`, { + method: req.method, + headers: req.headers, + redirect: 'follow', + body, + }); + } + + /** + * Log out request processing progress and result. + * + * @param request - Platform-specific + * @param [elapsed] - How many seconds passed since request processing started. + * @param [body] - Service response (if available). + */ + protected logRequestProcessProgress(request: Request, elapsed?: number, body?: ArrayBuffer) { + if (!this.logVerbosity) return; + + const { protocol, host, pathname, search } = new URL(request.url); + const timestamp = new Date().toISOString(); + + if (!elapsed) { + console.log('<<<<<'); + console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + console.log('-----'); + } else { + const stringifiedBody = body ? WebReactNativeTransport.decoder.decode(body) : undefined; + + console.log('>>>>>>'); + console.log( + `[${timestamp} / ${elapsed}]`, + `\n${protocol}//${host}${pathname}`, + `\n${search}`, + `\n${stringifiedBody}`, + ); + console.log('-----'); + } + } +} diff --git a/src/web/components/configuration.ts b/src/web/components/configuration.ts new file mode 100644 index 000000000..583c0361b --- /dev/null +++ b/src/web/components/configuration.ts @@ -0,0 +1,80 @@ +import { + UserConfiguration, + ExtendedConfiguration, + setDefaults as setBaseDefaults, +} from '../../core/interfaces/configuration'; + +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults + +/** + * Whether PubNub client should update its state using browser's reachability events or not. + * + * If the browser fails to detect the network changes from Wi-Fi to LAN and vice versa, or you get + * reconnection issues, set the flag to `false`. This allows the SDK reconnection logic to take over. + */ +const LISTEN_TO_BROWSER_NETWORK_EVENTS = true; + +/** + * Whether PubNub client should spawn `Subscription` service worker for better user presence + * experience or not. + */ +const ENABLE_SERVICE_WORKER = false; + +/** + * Whether PubNub client should try to utilize existing TCP connection for new requests or not. + */ +const KEEP_ALIVE = true; +// endregion + +/** + * Browser platform PubNub client configuration. + */ +export type PubNubConfiguration = UserConfiguration & { + /** + * If the browser fails to detect the network changes from Wi-Fi to LAN and vice versa, or you + * get reconnection issues, set the flag to `false`. This allows the SDK reconnection logic to + * take over. + * + * @default `true` + */ + listenToBrowserNetworkEvents?: boolean; + + /** + * Whether PubNub client should spawn `Subscription` service worker for better user presence + * experience or not. + * + * @default `true` (if supported) + */ + enableServiceWorker?: boolean; + + /** + * If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of + * opening a new one for each new request. + * + * @default `true` + */ + keepAlive?: boolean; +}; + +/** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + */ +export const setDefaults = (configuration: PubNubConfiguration): PubNubConfiguration & ExtendedConfiguration => { + // Force disable service workers if environment doesn't support them. + if ((configuration.enableServiceWorker ?? ENABLE_SERVICE_WORKER) && !('serviceWorker' in navigator)) + configuration.enableServiceWorker = false; + + return { + // Set base configuration defaults. + ...setBaseDefaults(configuration), + // Set platform-specific options. + listenToBrowserNetworkEvents: configuration.listenToBrowserNetworkEvents ?? LISTEN_TO_BROWSER_NETWORK_EVENTS, + enableServiceWorker: configuration.enableServiceWorker ?? ENABLE_SERVICE_WORKER, + keepAlive: configuration.keepAlive ?? KEEP_ALIVE, + }; +}; diff --git a/src/web/index.js b/src/web/index.js deleted file mode 100644 index 24008da2e..000000000 --- a/src/web/index.js +++ /dev/null @@ -1,67 +0,0 @@ -/* eslint no-bitwise: ["error", { "allow": ["~", "&", ">>"] }] */ -/* global navigator, window */ - -import CborReader from 'cbor-js'; -import PubNubCore from '../core/pubnub-common'; -import Networking from '../networking'; -import { decode } from '../core/components/base64_codec'; -import { stringifyBufferKeys } from '../core/components/stringify_buffer_keys'; -import Cbor from '../cbor/common'; -import { del, get, post, patch, getfile, postfile } from '../networking/modules/web-node'; - -import WebCryptography from '../crypto/modules/web'; -import PubNubFile from '../file/modules/web'; -import { CryptoModule, LegacyCryptor, AesCbcCryptor } from '../crypto/modules/WebCryptoModule/webCryptoModule'; - -function sendBeacon(url) { - if (navigator && navigator.sendBeacon) { - navigator.sendBeacon(url); - } else { - return false; - } -} - -export default class extends PubNubCore { - static CryptoModule = CryptoModule; - constructor(setup) { - // extract config. - const { listenToBrowserNetworkEvents = true } = setup; - setup.sdkFamily = 'Web'; - setup.networking = new Networking({ - del, - get, - post, - patch, - sendBeacon, - getfile, - postfile, - }); - setup.cbor = new Cbor((arrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode); - - setup.PubNubFile = PubNubFile; - setup.cryptography = new WebCryptography(); - - setup.initCryptoModule = (cryptoConfiguration) => { - return new CryptoModule({ - default: new LegacyCryptor({ - cipherKey: cryptoConfiguration.cipherKey, - useRandomIVs: cryptoConfiguration.useRandomIVs, - }), - cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], - }); - }; - - super(setup); - - if (listenToBrowserNetworkEvents) { - // mount network events. - window.addEventListener('offline', () => { - this.networkDownDetected(); - }); - - window.addEventListener('online', () => { - this.networkUpDetected(); - }); - } - } -} diff --git a/src/web/index.ts b/src/web/index.ts new file mode 100644 index 000000000..3d3c5f05c --- /dev/null +++ b/src/web/index.ts @@ -0,0 +1,119 @@ +/* eslint no-bitwise: ["error", { "allow": ["~", "&", ">>"] }] */ +/* global navigator */ + +import CborReader from 'cbor-js'; + +// eslint-disable-next-line max-len +import { SubscriptionServiceWorkerMiddleware } from '../transport/service-worker/subscription-service-worker-middleware'; +import { AesCbcCryptor, LegacyCryptor, WebCryptoModule } from '../crypto/modules/WebCryptoModule/webCryptoModule'; +import { WebReactNativeTransport } from '../transport/web-react-native-transport'; +import { stringifyBufferKeys } from '../core/components/stringify_buffer_keys'; +import { PubNubConfiguration, setDefaults } from './components/configuration'; +import { CryptorConfiguration } from '../core/interfaces/crypto-module'; +import { PubNubFile, PubNubFileParameters } from '../file/modules/web'; +import { makeConfiguration } from '../core/components/configuration'; +import { TokenManager } from '../core/components/token_manager'; +import { PubNubMiddleware } from '../transport/middleware'; +import { decode } from '../core/components/base64_codec'; +import { Transport } from '../core/interfaces/transport'; +import Crypto from '../core/components/cryptography'; +import WebCryptography from '../crypto/modules/web'; +import { PubNubCore } from '../core/pubnub-common'; +import Cbor from '../cbor/common'; + +/** + * PubNub client for browser platform. + */ +export default class PubNub extends PubNubCore { + /** + * Data encryption / decryption module constructor. + */ + static CryptoModule = WebCryptoModule; + + constructor(configuration: PubNubConfiguration) { + const configurationCopy = setDefaults(configuration); + const platformConfiguration = { ...configurationCopy, sdkFamily: 'Web', PubNubFile }; + + // Prepare full client configuration. + const clientConfiguration = makeConfiguration( + platformConfiguration, + (cryptoConfiguration: CryptorConfiguration) => { + if (!cryptoConfiguration.cipherKey) return undefined; + + return new WebCryptoModule({ + default: new LegacyCryptor({ ...cryptoConfiguration }), + cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], + }); + }, + ); + + // Prepare Token manager. + const tokenManager = new TokenManager( + new Cbor((arrayBuffer: ArrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode), + ); + + // Legacy crypto (legacy data encryption / decryption and request signature support). + let crypto: Crypto | undefined; + if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { + crypto = new Crypto({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } + + // Setup transport provider. + let transport: Transport = new WebReactNativeTransport( + clientConfiguration.keepAlive, + clientConfiguration.logVerbosity!, + ); + if (configurationCopy.enableServiceWorker) { + // Inject subscription service worker into transport provider stack. + transport = new SubscriptionServiceWorkerMiddleware({ + clientIdentifier: clientConfiguration._instanceId, + subscriptionKey: clientConfiguration.subscribeKey, + sdkVersion: clientConfiguration.getVersion(), + logVerbosity: clientConfiguration.logVerbosity!, + transport, + }); + } + + const transportMiddleware = new PubNubMiddleware({ + clientConfiguration, + tokenManager, + transport, + }); + + super({ + configuration: clientConfiguration, + transport: transportMiddleware, + cryptography: new WebCryptography(), + tokenManager, + crypto, + }); + + if (configuration.listenToBrowserNetworkEvents ?? true) { + window.addEventListener('offline', () => { + this.networkDownDetected(); + }); + + window.addEventListener('online', () => { + this.networkUpDetected(); + }); + } + } + + private networkDownDetected() { + this.listenerManager.announceNetworkDown(); + + if (this._configuration.restore) this.disconnect(); + else this.destroy(true); + } + + private networkUpDetected() { + this.listenerManager.announceNetworkUp(); + this.reconnect(); + } +} diff --git a/test/contract/definitions/auth.ts b/test/contract/definitions/auth.ts index a91dd2731..41c44627d 100644 --- a/test/contract/definitions/auth.ts +++ b/test/contract/definitions/auth.ts @@ -19,7 +19,10 @@ class AuthSteps { private token?: string; - constructor(private manager: PubNubManager, private keyset: AccessManagerKeyset) {} + constructor( + private manager: PubNubManager, + private keyset: AccessManagerKeyset, + ) {} @when('I publish a message using that auth token with channel {string}') public publishMessage() { diff --git a/test/contract/definitions/event-engine.ts b/test/contract/definitions/event-engine.ts index 34eed878f..ef02e4925 100644 --- a/test/contract/definitions/event-engine.ts +++ b/test/contract/definitions/event-engine.ts @@ -36,7 +36,10 @@ class EventEngineSteps { private changelog: Change[] = []; private configuration: any = {}; - constructor(private manager: PubNubManager, private keyset: DemoKeyset) {} + constructor( + private manager: PubNubManager, + private keyset: DemoKeyset, + ) {} private async testDelay(time: number) { return new Promise((resolve) => setTimeout(resolve, time * 1000)); @@ -114,7 +117,7 @@ class EventEngineSteps { @then('I observe the following Events and Invocations of the Presence EE:') async thenIObservePresenceEE(dataTable: DataTable) { const expectedChangelog = dataTable.hashes(); - const actualChangelog = []; + const actualChangelog: { type: string; name: string }[] = []; for (const entry of this.changelog) { if (entry.type === 'eventReceived') { actualChangelog.push({ type: 'event', name: entry.event.type }); @@ -170,10 +173,10 @@ class EventEngineSteps { this.messagePromise = new Promise((resolveMessage) => { this.pubnub?.addListener({ message(messageEvent) { - resolveMessage(messageEvent); + setTimeout(() => resolveMessage(messageEvent), 100); }, status(statusEvent) { - resolveStatus(statusEvent); + setTimeout(() => resolveStatus(statusEvent), 100); }, }); @@ -182,16 +185,16 @@ class EventEngineSteps { }); } - @when('I subscribe with timetoken {int}') + @when(/I subscribe with timetoken (\d*)/) async whenISubscribeWithTimetoken(timetoken: number) { this.statusPromise = new Promise((resolveStatus) => { this.messagePromise = new Promise((resolveMessage) => { this.pubnub?.addListener({ message(messageEvent) { - resolveMessage(messageEvent); + setTimeout(() => resolveMessage(messageEvent), 100); }, status(statusEvent) { - resolveStatus(statusEvent); + setTimeout(() => resolveStatus(statusEvent), 100); }, }); @@ -225,7 +228,7 @@ class EventEngineSteps { thenIObserve(dataTable: DataTable) { const expectedChangelog = dataTable.hashes(); - const actualChangelog = []; + const actualChangelog: { type: string; name: string }[] = []; for (const entry of this.changelog) { if (entry.type === 'eventReceived') { actualChangelog.push({ type: 'event', name: entry.event.type }); @@ -242,7 +245,7 @@ class EventEngineSteps { @then("I don't observe any Events and Invocations of the Presence EE") noeventInvocations() { - const actualChangelog = []; + const actualChangelog: { type: string; name: string }[] = []; for (const entry of this.changelog) { if (entry.type === 'eventReceived') { actualChangelog.push({ type: 'event', name: entry.event.type }); @@ -258,7 +261,9 @@ class EventEngineSteps { @after() dispose() { - (this.pubnub as any).removeAllListeners(); - (this.pubnub as any).eventEngine.dispose(); + if (this.pubnub) { + (this.pubnub as any).removeAllListeners(); + (this.pubnub as any).eventEngine.dispose(); + } } } diff --git a/test/contract/definitions/grant.ts b/test/contract/definitions/grant.ts index dc4cf9365..a0a655f0f 100644 --- a/test/contract/definitions/grant.ts +++ b/test/contract/definitions/grant.ts @@ -26,7 +26,10 @@ class GrantTokenSteps { private resourceName?: string; private resourceType?: ResourceType; - constructor(private manager: PubNubManager, private keyset: AccessManagerKeyset) {} + constructor( + private manager: PubNubManager, + private keyset: AccessManagerKeyset, + ) {} @given('the authorized UUID {string}') public givenAuthorizedUUID(authorizedUUID: string) { diff --git a/test/contract/shared/keysets.ts b/test/contract/shared/keysets.ts index bcdbd5840..fe38c4cff 100644 --- a/test/contract/shared/keysets.ts +++ b/test/contract/shared/keysets.ts @@ -1,9 +1,9 @@ import { Keyset } from './pubnub'; export class AccessManagerKeyset implements Keyset { - publishKey = process.env.PUBLISH_KEY_ACCESS || 'pub-key'; - subscribeKey = process.env.SUBSCRIBE_KEY_ACCESS || 'sub-key'; - secretKey = process.env.SECRET_KEY_ACCESS || 'secret-key'; + subscribeKey = process.env.PAM_SUBSCRIBE_KEY || 'sub-key'; + secretKey = process.env.PAM_SECRET_KEY || 'secret-key'; + publishKey = process.env.PAM_PUBLISH_KEY || 'pub-key'; } export class DemoKeyset implements Keyset { diff --git a/test/contract/shared/pubnub.ts b/test/contract/shared/pubnub.ts index d8d46ad8e..1c0fdbee0 100644 --- a/test/contract/shared/pubnub.ts +++ b/test/contract/shared/pubnub.ts @@ -1,5 +1,4 @@ -import type PubNubType from 'pubnub'; -import PubNub from '../../../lib/node/index.js'; +import PubNubCore from '../../../lib/node/index.js'; export interface Keyset { subscribeKey?: string; @@ -35,8 +34,8 @@ const defaultConfig: Config = { export class PubNubManager { getInstance(config: Config = {}) { - return new (PubNub as any)({ ...defaultConfig, ...config }); + return new (PubNubCore as any)({ ...defaultConfig, ...config }); } } -export type PubNub = PubNubType; +export type PubNub = PubNubCore; diff --git a/test/contract/tsconfig.json b/test/contract/tsconfig.json index 88f3844ab..80e527d98 100644 --- a/test/contract/tsconfig.json +++ b/test/contract/tsconfig.json @@ -1,15 +1,20 @@ { "compilerOptions": { - "module": "commonjs", - "moduleResolution": "node", + "module": "CommonJS", + "moduleResolution": "Node", "resolveJsonModule": true, "experimentalDecorators": true, - "target": "es5", + "emitDecoratorMetadata": true, + "noStrictGenericChecks": true, + "target": "es6", "sourceMap": true, "esModuleInterop": true, "strict": true, "allowJs": true, - "noEmit": true + "noEmit": true, + "noImplicitAny": false }, - "exclude": ["../../lib"] + "exclude": [ + "../../lib" + ] } diff --git a/test/dist/objectsv2.test.js b/test/dist/objectsv2.test.ts similarity index 75% rename from test/dist/objectsv2.test.js rename to test/dist/objectsv2.test.ts index 9b8346a2a..dec3002af 100644 --- a/test/dist/objectsv2.test.js +++ b/test/dist/objectsv2.test.ts @@ -1,36 +1,41 @@ /** */ -import util from 'util' -import PubNub from '../../src/node' +import chaiAsPromised from 'chai-as-promised'; +import chai, { expect } from 'chai'; +import chaiNock from 'chai-nock'; +import assert from 'assert'; -describe('Objects V2 system tests', () => { - const SUBSCRIBE_KEY = 'sub-c-d86a1698-889e-11ea-b883-d2d532c9a1bf'; - const PUBLISH_KEY = 'pub-c-5397272a-7664-4b57-bc91-944977fb3f25'; +import { Listener } from '../../src/core/components/listener_manager'; +import PubNub from '../../src/node'; + +chai.use(chaiAsPromised); +chai.use(chaiNock); +describe('Objects V2 system tests', () => { const TEST_PREFIX = 'objectsV2tests'; const UUID = `${TEST_PREFIX}-main`; const UUID_1 = `${TEST_PREFIX}-uuid-1`; const CHANNEL_1 = `${TEST_PREFIX}-channel-1`; - let pubnub ; + let pubnub: PubNub; const events = []; - const listener = { + const listener: Listener = { objects: (event) => { events.push(event); - } + }, }; before(() => { pubnub = new PubNub({ - subscribeKey: SUBSCRIBE_KEY, - publishKey: PUBLISH_KEY, + subscribeKey: process.env.SUBSCRIBE_KEY || 'demo', + publishKey: process.env.PUBLISH_KEY || 'demo', uuid: UUID, // logVerbosity: true }); - pubnub.subscribe({ channels: [UUID_1] }) + pubnub.subscribe({ channels: [UUID_1] }); pubnub.addListener(listener); }); @@ -58,8 +63,7 @@ describe('Objects V2 system tests', () => { }); it('should get all uuids', async () => { - const result = await pubnub.objects.getAllUUIDMetadata({ include: { totalCount: true }}); - + const result = await pubnub.objects.getAllUUIDMetadata({ include: { totalCount: true } }); expect(result.status).to.equal(200); expect(result.data[0].name).to.equal(USER_NAME); @@ -70,8 +74,8 @@ describe('Objects V2 system tests', () => { channel: CHANNEL_1, data: { name: CHANNEL_NAME, - custom: { foo: true } - } + custom: { foo: true }, + }, }); expect(result.status).to.equal(200); @@ -104,7 +108,7 @@ describe('Objects V2 system tests', () => { it('should get channel members', async () => { const result = await pubnub.objects.getChannelMembers({ channel: CHANNEL_1, - include: { customFields: true } + include: { customFields: true }, }); expect(result.status).to.equal(200); @@ -118,20 +122,20 @@ describe('Objects V2 system tests', () => { customFields: true, customChannelFields: true, channelFields: true, - } + }, }); expect(result.status).to.equal(200); - expect(result.data[0]?.custom?.myData).to.equal(42); - expect(result.data[0]?.channel?.name).to.equal(CHANNEL_NAME); - expect(result.data[0]?.channel?.custom?.foo).to.be.true; + expect(result.data[0].custom?.myData).to.equal(42); + assert('name' in result.data[0].channel); + expect(result.data[0].channel?.name).to.equal(CHANNEL_NAME); + expect(result.data[0].channel?.custom?.foo).to.be.true; }); it('should remove memberships', async () => { - const result = pubnub.objects.removeMemberships({ uuid: UUID_1, channels: [CHANNEL_1] }, (status, result) => { - expect(result.status).to.equal(200); - }); - }) + const result = await pubnub.objects.removeMemberships({ uuid: UUID_1, channels: [CHANNEL_1] }); + expect(result.status).to.equal(200); + }); it('should remove uuid', async () => { const result = await pubnub.objects.removeUUIDMetadata({ uuid: UUID_1 }); diff --git a/test/dist/react-native.test.js b/test/dist/react-native.test.js index 949168e22..ac9da0d05 100644 --- a/test/dist/react-native.test.js +++ b/test/dist/react-native.test.js @@ -31,9 +31,13 @@ describe('#distribution test (rkt-native)', function () { it('should have to subscribe a channel', (done) => { pubnub.addListener({ status: (st) => { - expect(st.operation).to.be.equal('PNSubscribeOperation'); - pubnub.unsubscribeAll() - done(); + try { + expect(st.operation).to.be.equal('PNSubscribeOperation'); + pubnub.unsubscribeAll() + done(); + } catch (error) { + done(error); + } } }); pubnub.subscribe({channels: [myChannel1]}); @@ -47,10 +51,14 @@ describe('#distribution test (rkt-native)', function () { } }, message: (m) => { - expect(m.channel).to.be.equal(myChannel2); - expect(m.message.text).to.be.equal('hello React-Native SDK'); - pubnub.unsubscribeAll() - done(); + try { + expect(m.channel).to.be.equal(myChannel2); + expect(m.message.text).to.be.equal('hello React-Native SDK'); + pubnub.unsubscribeAll() + done(); + } catch (error) { + done(error); + } } }); pubnub.subscribe({channels: [myChannel2]}); @@ -58,17 +66,25 @@ describe('#distribution test (rkt-native)', function () { it('should have to set state', (done) => { pubnub.setState({ channels: [myChannel1], state: { hello: 'there' } }, (status, response) => { - expect(status.error).to.be.equal(false); - expect(response.state.hello).to.be.equal('there'); - done(); + try { + expect(status.error).to.be.equal(false); + expect(response.state.hello).to.be.equal("there"); + done(); + } catch (error) { + done(error); + } }); }); it('should have to get the time', (done) => { pubnub.time((status) => { - expect(status.operation).to.be.equal('PNTimeOperation'); - expect(status.statusCode).to.be.equal(200); - done(); + try { + expect(status.operation).to.be.equal("PNTimeOperation"); + expect(status.statusCode).to.be.equal(200); + done(); + } catch (error) { + done(error); + } }); }); @@ -80,8 +96,12 @@ describe('#distribution test (rkt-native)', function () { count: 1, reverse: false }, function(status, response) { - expect(response.messages).to.have.length(1); - done(); + try { + expect(response.messages).to.have.length(1); + done(); + } catch (error) { + done(error); + } }); }, 3000); }); diff --git a/test/dist/web-titanium.test.js b/test/dist/web-titanium.test.js index 00d1a8e59..862a4bf68 100644 --- a/test/dist/web-titanium.test.js +++ b/test/dist/web-titanium.test.js @@ -13,9 +13,12 @@ var myChannel2 = 'mychannel2' + channelSuffix; var myChanneGroup1 = 'myChannelGroup1' + channelSuffix; describe('#distribution test (titanium)', function () { - before(function () { - pubnub = new PubNub({ subscribeKey: 'demo', publishKey: 'demo', uuid: 'myUUID' }); + pubnub = new PubNub({ + subscribeKey: 'demo', + publishKey: 'demo', + uuid: 'myUUID', + }); }); after(function () { @@ -25,13 +28,17 @@ describe('#distribution test (titanium)', function () { it('should have to subscribe a channel', function (done) { listener = { status: function (st) { - expect(st.operation).to.be.equal('PNSubscribeOperation'); - done(); - } + try { + expect(st.operation).to.be.equal("PNSubscribeOperation"); + done(); + } catch (error) { + done(error); + } + }, }; pubnub.addListener(listener); - pubnub.subscribe({channels: [myChannel1]}); + pubnub.subscribe({ channels: [myChannel1] }); }); it('should have to receive message from a channel', function (done) { @@ -41,43 +48,64 @@ describe('#distribution test (titanium)', function () { listener = pubnub.addListener({ message: function (m) { - expect(m.channel).to.be.equal(myChannel2); - expect(m.message.text).to.be.equal('hello Titanium SDK'); - done(); - } + try { + expect(m.channel).to.be.equal(myChannel2); + expect(m.message.text).to.be.equal("hello Titanium SDK"); + done(); + } catch (error) { + done(error); + } + }, }); - pubnub.subscribe({channels: [myChannel2]}); - pubnub.publish({ channel: myChannel2, message: { text: 'hello Titanium SDK' }}); + pubnub.subscribe({ channels: [myChannel2] }); + setTimeout(function () { + pubnub.publish({ channel: myChannel2, message: { text: 'hello Titanium SDK' } }); + }, 1000); }); it('should have to set state', function (done) { pubnub.setState({ channels: [myChannel1], state: { hello: 'there' } }, function (status, response) { - expect(status.error).to.be.equal(false); - expect(response.state.hello).to.be.equal('there'); - done(); + try { + expect(status.error).to.be.equal(false); + expect(response.state.hello).to.be.equal("there"); + done(); + } catch (error) { + done(error); + } }); }); it('should have to get the time', function (done) { pubnub.time(function (status) { - expect(status.operation).to.be.equal('PNTimeOperation'); - expect(status.statusCode).to.be.equal(200); - done(); + try { + expect(status.operation).to.be.equal("PNTimeOperation"); + expect(status.statusCode).to.be.equal(200); + done(); + } catch (error) { + done(error); + } }); }); it('should have to get the last message', function (done) { // add delay to ensure publish completes setTimeout(function () { - pubnub.history({ - channel: myChannel2, - count: 1, - reverse: false - }, function(status, response) { - expect(response.messages).to.have.length(1); - done(); - }); + pubnub.history( + { + channel: myChannel2, + count: 1, + reverse: false, + }, + function (status, response) { + try { + expect(response.messages).to.have.length(1); + done(); + } catch (error) { + done(error); + } + }, + ); }, 3000); }); @@ -111,10 +139,14 @@ describe('#distribution test (titanium)', function () { // }); it('should have to change the UUID', function (done) { - pubnub.setUUID("CustomUUID"); + pubnub.setUUID('CustomUUID'); - expect(pubnub.getUUID()).to.be.equal("CustomUUID"); - done(); + try { + expect(pubnub.getUUID()).to.be.equal("CustomUUID"); + done(); + } catch (error) { + done(error); + } }); it('should have to unsubscribe', function (done) { @@ -126,15 +158,19 @@ describe('#distribution test (titanium)', function () { pubnub.addListener({ status: function (st) { - expect(st.operation).to.be.equal('PNUnsubscribeOperation'); - - if (!finished) { - // prevent calling done twice - finished = true; - done(); + try { + expect(st.operation).to.be.equal("PNUnsubscribeOperation"); + + if (!finished) { + // prevent calling done twice + finished = true; + done(); + } + } catch (error) { + done(error); } - } + }, }); - pubnub.unsubscribe({channels: [myChannel1]}); + pubnub.unsubscribe({ channels: [myChannel1] }); }); -}); \ No newline at end of file +}); diff --git a/test/feature/file_upload.node.test.js b/test/feature/file_upload.node.test.ts similarity index 71% rename from test/feature/file_upload.node.test.js rename to test/feature/file_upload.node.test.ts index e8a6c3c4e..85cdeb29f 100644 --- a/test/feature/file_upload.node.test.js +++ b/test/feature/file_upload.node.test.ts @@ -1,16 +1,17 @@ /** */ -import util from 'util'; -import { Readable } from 'stream'; +import chaiAsPromised from 'chai-as-promised'; +import chai, { expect } from 'chai'; +import chaiNock from 'chai-nock'; +import assert from 'assert'; +import fs from 'fs'; import PubNub from '../../src/node'; -import fs from 'fs'; +chai.use(chaiAsPromised); +chai.use(chaiNock); describe('File Upload API v1 tests', () => { - const SUBSCRIBE_KEY = 'demo'; - const PUBLISH_KEY = 'demo'; - const ORIGIN = undefined; const TEST_PREFIX = 'javascript-fileUploadApiV1-tests'; @@ -21,12 +22,12 @@ describe('File Upload API v1 tests', () => { const FILE_1 = `${TEST_PREFIX}-file-1`; - let pubnub; + let pubnub: PubNub; describe('with encryption', () => { pubnub = new PubNub({ - subscribeKey: SUBSCRIBE_KEY, - publishKey: PUBLISH_KEY, + subscribeKey: process.env.SUBSCRIBE_KEY || 'demo', + publishKey: process.env.PUBLISH_KEY || 'demo', uuid: UUID, origin: ORIGIN, cipherKey: 'abcdef', @@ -38,8 +39,8 @@ describe('File Upload API v1 tests', () => { describe('without encryption', () => { pubnub = new PubNub({ - subscribeKey: SUBSCRIBE_KEY, - publishKey: PUBLISH_KEY, + subscribeKey: process.env.SUBSCRIBE_KEY || 'demo', + publishKey: process.env.PUBLISH_KEY || 'demo', origin: ORIGIN, uuid: UUID, }); @@ -47,7 +48,7 @@ describe('File Upload API v1 tests', () => { runTests(pubnub); }); - function runTests(pubnub) { + function runTests(pubnub: PubNub) { it('should export File class in PubNub instance', async () => { expect(pubnub.File).to.exist; }); @@ -100,8 +101,8 @@ describe('File Upload API v1 tests', () => { expect(output.toString('utf8')).to.equal(testContent); }).timeout(10000); - let fileId; - let fileName; + let fileId: string; + let fileName: string; it('should handle strings', (done) => { const testContent = `Hello world! ${new Date().toLocaleString()}`; @@ -112,9 +113,15 @@ describe('File Upload API v1 tests', () => { file: { data: testContent, name: 'someFile.txt', mimeType: 'text/plain' }, }, (err, result) => { - expect(err).to.be.null; + try { + expect(err.error).to.be.false; - expect(result.name).to.equal('someFile.txt'); + assert(result !== null); + expect(result.name).to.equal('someFile.txt'); + } catch (error) { + done(error); + return; + } pubnub.downloadFile( { @@ -126,14 +133,19 @@ describe('File Upload API v1 tests', () => { fileId = result.id; fileName = result.name; + assert(file !== null); const output = file.toString('utf8').then((output) => { - expect(output).to.equal(testContent); + try { + expect(output).to.equal(testContent); - done(); + done(); + } catch (error) { + done(error); + } }); - } + }, ); - } + }, ); }).timeout(10000); @@ -156,32 +168,42 @@ describe('File Upload API v1 tests', () => { { channel: CHANNEL_1, file: { data: testContent, name: 'someFile.txt', mimeType: 'text/plain' }, - cipherKey: 'cipherKey' + cipherKey: 'cipherKey', }, (err, result) => { - expect(err).to.be.null; + try { + expect(err.error).to.be.false; - expect(result.name).to.equal('someFile.txt'); + assert(result !== null); + expect(result.name).to.equal('someFile.txt'); + } catch (error) { + done(error); + } pubnub.downloadFile( { channel: CHANNEL_1, - id: result.id, - name: result.name, - cipherKey: 'cipherKey' + id: result!.id, + name: result!.name, + cipherKey: 'cipherKey', }, (err2, file) => { - fileId = result.id; - fileName = result.name; + fileId = result!.id; + fileName = result!.name; + assert(file !== null); const output = file.toString('utf8').then((output) => { - expect(output).to.equal(testContent); + try { + expect(output).to.equal(testContent); - done(); + done(); + } catch (error) { + done(error); + } }); - } + }, ); - } + }, ); }).timeout(10000); } diff --git a/test/feature/file_upload.web.test.js b/test/feature/file_upload.web.test.js index daa68d336..4802981a3 100644 --- a/test/feature/file_upload.web.test.js +++ b/test/feature/file_upload.web.test.js @@ -13,9 +13,6 @@ function urlToFile(url, filename, mimeType) { } describe('test', () => { - const SUBSCRIBE_KEY = 'demo-36'; - const PUBLISH_KEY = 'demo-36'; - const TEST_PREFIX = 'javascript-fileUploadApiV1-tests'; const UUID = `${TEST_PREFIX}-main`; const UUID_1 = `${TEST_PREFIX}-uuid-1`; @@ -24,7 +21,7 @@ describe('test', () => { const FILE_1 = `${TEST_PREFIX}-file-1`; - let pubnub ; + let pubnub; after(() => { pubnub.unsubscribeAll(); @@ -33,8 +30,8 @@ describe('test', () => { describe('with encryption', () => { pubnub = new PubNub({ - subscribeKey: SUBSCRIBE_KEY, - publishKey: PUBLISH_KEY, + subscribeKey: process.env.SUBSCRIBE_KEY || 'demo', + publishKey: process.env.PUBLISH_KEY || 'demo', uuid: UUID, cipherKey: 'abcdef', }); @@ -44,8 +41,8 @@ describe('test', () => { describe('without encryption', () => { pubnub = new PubNub({ - subscribeKey: SUBSCRIBE_KEY, - publishKey: PUBLISH_KEY, + subscribeKey: process.env.SUBSCRIBE_KEY || 'demo', + publishKey: process.env.PUBLISH_KEY || 'demo', uuid: UUID, }); @@ -166,7 +163,7 @@ describe('test', () => { const result = await pubnub.sendFile({ channel: CHANNEL_1, file: { data: testContent, name: 'someFile.txt', mimeType: 'text/plain' }, - cipherKey: 'cipherKey' + cipherKey: 'cipherKey', }); expect(result.name).to.equal('someFile.txt'); @@ -175,7 +172,7 @@ describe('test', () => { channel: CHANNEL_1, id: result.id, name: result.name, - cipherKey: 'cipherKey' + cipherKey: 'cipherKey', }); fileId = result.id; diff --git a/test/integration/components/config.test.js b/test/integration/components/config.test.ts similarity index 86% rename from test/integration/components/config.test.js rename to test/integration/components/config.test.ts index a639494a3..fcdbc6c3b 100644 --- a/test/integration/components/config.test.js +++ b/test/integration/components/config.test.ts @@ -7,11 +7,11 @@ import PubNub from '../../../src/node/index'; describe('components/config', () => { describe('AuthKey parameter', () => { it('get/set', () => { - let pubnub = new PubNub({ + const pubnub = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', authKey: 'authKey1', - uuid: 'myUUID', + userId: 'myUUID', }); assert.equal(pubnub.getAuthKey(), 'authKey1'); pubnub.setAuthKey('authKey2'); @@ -21,7 +21,7 @@ describe('components/config', () => { describe('uuid Parameter', () => { it('throws when not provided value', () => { - let config = { + const config = { subscribeKey: 'mySubKey', publishKey: 'myPublishKey', authKey: 'authKey1', @@ -32,7 +32,7 @@ describe('components/config', () => { }); it('get/set', () => { - let pubnub = new PubNub({ + const pubnub = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'uuid1', @@ -43,7 +43,7 @@ describe('components/config', () => { }); it('get/set userId', () => { - let pubnub = new PubNub({ + const pubnub = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', userId: 'userId1', @@ -54,7 +54,7 @@ describe('components/config', () => { }); it('throws when both userId and uuid are provided', () => { - let config = { subscribeKey: 'demo', publishKey: 'demo', uuid: 'myUuid', userId: 'myUserId' }; + const config = { subscribeKey: 'demo', publishKey: 'demo', uuid: 'myUuid', userId: 'myUserId' }; assert.throws(() => { new PubNub(config); @@ -62,7 +62,7 @@ describe('components/config', () => { }); it('throws when invalid value provided', () => { - let config = { + const config = { subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: ' ', @@ -73,7 +73,7 @@ describe('components/config', () => { }); it('setUUID throws while trying to set invalid uuid', () => { - let pubnub = new PubNub({ + const pubnub = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', diff --git a/test/integration/components/crypto.test.js b/test/integration/components/crypto.test.ts similarity index 83% rename from test/integration/components/crypto.test.js rename to test/integration/components/crypto.test.ts index b425c55ff..d7373805c 100644 --- a/test/integration/components/crypto.test.js +++ b/test/integration/components/crypto.test.ts @@ -1,4 +1,5 @@ /** */ +import { expect } from 'chai'; import PubNub from '../../../src/node'; @@ -8,7 +9,7 @@ describe('components/crypto useRandomIVs', () => { publishKey: 'demo-36', useRandomIVs: true, cipherKey: 'abcdef', - uuid: 'myUUID' + uuid: 'myUUID', }); it('should be able to encrypt and decrypt a message', () => { @@ -21,19 +22,19 @@ describe('components/crypto useRandomIVs', () => { const decrypted = pubnub.decrypt(ciphertext); - expect(decrypted).to.deep.equal(data); + expect(decrypted).to.deep.equal(data, JSON.stringify(decrypted)); }); it('should be able to encrypt and decrypt a message with CryptoModule', () => { - const pubnub = new PubNub({ - subscribeKey: 'demo-36', - publishKey: 'demo-36', - useRandomIVs: true, - cryptoModule: PubNub.CryptoModule.aesCbcCryptoModule({ - cipherKey: 'abcd' - }), - uuid: 'myUUID', - }); + const pubnub = new PubNub({ + subscribeKey: 'demo-36', + publishKey: 'demo-36', + useRandomIVs: true, + cryptoModule: PubNub.CryptoModule.aesCbcCryptoModule({ + cipherKey: 'abcd', + }), + uuid: 'myUUID', + }); const data = { message: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', diff --git a/test/integration/components/listeners.test.js b/test/integration/components/listeners.test.ts similarity index 61% rename from test/integration/components/listeners.test.js rename to test/integration/components/listeners.test.ts index ef54a7d5b..d576d728a 100644 --- a/test/integration/components/listeners.test.js +++ b/test/integration/components/listeners.test.ts @@ -1,10 +1,11 @@ +import { expect } from 'chai'; import nock from 'nock'; -import _ from 'underscore'; -import utils from '../../utils'; +import * as Subscription from '../../../src/core/types/api/subscription'; import PubNub from '../../../src/node/index'; +import utils from '../../utils'; -let pubnub; +let pubnub: PubNub; describe('#listeners', () => { before(() => { @@ -20,14 +21,16 @@ describe('#listeners', () => { pubnub = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', + origin: 'ps.pndsn.com', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, enableEventEngine: true, autoNetworkDetection: false, }); }); afterEach(() => { - pubnub.stop(); pubnub.destroy(); }); @@ -39,27 +42,21 @@ describe('#listeners', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() .get('/v2/subscribe/mySubKey/ch1/0') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - ee: '', - tt: '3', - tr: 1, - }) + .query((object) => object.tt === '3') .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); - var channel = pubnub.channel('ch1'); - var subscription = channel.subscription(); - var messagePromise = new Promise((resolveMessage) => + const channel = pubnub.channel('ch1'); + const subscription = channel.subscription(); + const messagePromise = new Promise((resolveMessage) => subscription.addListener({ message: (m) => resolveMessage(m), }), @@ -68,21 +65,21 @@ describe('#listeners', () => { const actual = await messagePromise; expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); }); + it('should subscribed to channel and presence channels', async () => { utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -93,11 +90,13 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); + nock.enableNetConnect(); const channel = pubnub.channel('ch1'); const subscription = channel.subscription({ receivePresenceEvents: true }); - const messagePromise = new Promise((resolveMessage) => + const messagePromise = new Promise((resolveMessage) => subscription.addListener({ message: (m) => resolveMessage(m), }), @@ -110,18 +109,17 @@ describe('#listeners', () => { it('should work with subscriptionSet', async () => { utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .get('/v2/subscribe/mySubKey/ch1,ch2/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .get('/v2/subscribe/mySubKey/ch1,ch2/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -132,12 +130,13 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); const channel = pubnub.channel('ch1'); const subscription = channel.subscription(); const subscriptionSet = subscription.addSubscription(pubnub.channel('ch2').subscription()); - const messagePromise = new Promise((resolveMessage) => + const messagePromise = new Promise((resolveMessage) => subscriptionSet.addListener({ message: (m) => resolveMessage(m), }), @@ -150,18 +149,17 @@ describe('#listeners', () => { it('should able to create subscriptionSet', async () => { utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .get('/v2/subscribe/mySubKey/ch1,ch2/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .get('/v2/subscribe/mySubKey/ch1,ch2/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -172,11 +170,12 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); const subscriptionSet = pubnub.subscriptionSet({ channels: ['ch1', 'ch2'] }); - const messagePromise = new Promise((resolveMessage) => + const messagePromise = new Promise((resolveMessage) => subscriptionSet.addListener({ message: (m) => resolveMessage(m), }), @@ -189,18 +188,17 @@ describe('#listeners', () => { it('subscriptionSet works with add/remove with set', async () => { utils .createNock() - .get('/v2/subscribe/mySubKey/ch3%2Cch4/0') + .get('/v2/subscribe/mySubKey/ch3,ch4/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() - .get('/v2/subscribe/mySubKey/ch3%2Cch4/0') + .get('/v2/subscribe/mySubKey/ch3,ch4/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -211,6 +209,7 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch3","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); const subscriptionSetCh34 = pubnub.subscriptionSet({ channels: ['ch3', 'ch4'] }); @@ -223,7 +222,7 @@ describe('#listeners', () => { subscriptionSetCh34.addSubscriptionSet(subscriptionSetCh12); subscriptionSetCh34.removeSubscriptionSet(subscriptionSetCh12); - const messagePromise = new Promise((resolveMessage) => + const messagePromise = new Promise((resolveMessage) => subscriptionSetCh34.addListener({ message: (m) => resolveMessage(m), }), @@ -232,21 +231,21 @@ describe('#listeners', () => { const actual = await messagePromise; expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); }); + it('listener should route presence event to registered handler', async () => { utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -257,19 +256,21 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"17070458535164862","r":31},"m":[{"a":"0","f":0,"p":{"t":"17070458535164862","r":31},"k":"mySubKey","c":"ch1-pnpres","u":{"pn_action":"join","pn_uuid":"dartClient","pn_timestamp":1707045853,"pn_precise_timestamp":1707045853513,"pn_occupancy":2,"pn_ispresence":1,"pn_channel":"ch1"},"d":{"action":"join","uuid":"p2","timestamp":1707045853,"precise_timestamp":1707045853513,"occupancy":2},"b":"ch1-pnpres"}]}', + { 'content-type': 'text/javascript' }, ); const channel = pubnub.channel('ch1'); const subscription = channel.subscription({ receivePresenceEvents: true }); - const presencePromise = new Promise((resolvePresence) => + const presencePromise = new Promise((resolvePresence) => subscription.addListener({ presence: (p) => resolvePresence(p), }), ); subscription.subscribe(); const actual = await presencePromise; - expect(actual.action).to.equal('join'); - expect(actual.occupancy).to.equal(2); + if (actual.action === 'join') { + expect(actual.occupancy).to.equal(2); + } else throw new Error('Unexpected presence event'); }); it('add/remove listener should work on subscription', async () => { @@ -280,10 +281,9 @@ describe('#listeners', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() .get('/v2/subscribe/mySubKey/ch1/0') @@ -297,13 +297,14 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); - const messages = []; + const messages: Subscription.Message[] = []; const channel = pubnub.channel('ch1'); const subscription = channel.subscription(); - const listener = { message: (m) => messages.push(m) }; + const listener = { message: (m: Subscription.Message) => messages.push(m) }; subscription.addListener(listener); - const messagePromise = new Promise((resolveMessage) => + const messagePromise = new Promise((resolveMessage) => subscription.addListener({ message: (m) => resolveMessage(m), }), @@ -318,19 +319,18 @@ describe('#listeners', () => { it('should work with channel groups and their presence', async () => { utils .createNock() - .get('/v2/subscribe/mySubKey/%2C/0') + .get('/v2/subscribe/mySubKey/,/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, 'channel-group': 'cg1,cg1-pnpres', }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() - .get('/v2/subscribe/mySubKey/%2C/0') + .get('/v2/subscribe/mySubKey/,/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -342,10 +342,11 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"17070655215847224","r":33},"m":[{"a":"0","f":0,"i":"cl1","p":{"t":"17070655215847224","r":31},"k":"mySubKey","c":"ch1","d":{"message":"My message!"},"b":"cg1"}]}', + { 'content-type': 'text/javascript' }, ); - var channelGroup = pubnub.channelGroup('cg1'); - var subscription = channelGroup.subscription({ receivePresenceEvents: true }); - var messagePromise = new Promise((resolveMessage) => + const channelGroup = pubnub.channelGroup('cg1'); + const subscription = channelGroup.subscription({ receivePresenceEvents: true }); + const messagePromise = new Promise((resolveMessage) => subscription.addListener({ message: (m) => resolveMessage(m), }), @@ -363,10 +364,9 @@ describe('#listeners', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() .get('/v2/subscribe/mySubKey/ch1/0') @@ -380,24 +380,20 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); utils .createNock() .get('/v2/subscribe/mySubKey/ch1/0') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - ee: '', - tt: '10', - tr: 1, - }) + .query((object) => object.tt === '10') .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2/0') + .get('/v2/subscribe/mySubKey/ch1,ch2/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -408,10 +404,11 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch3/0') + .get('/v2/subscribe/mySubKey/ch1,ch2,ch3/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -422,10 +419,11 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); utils .createNock() - .get('/v2/subscribe/mySubKey/ch2%2Cch3/0') + .get('/v2/subscribe/mySubKey/ch2,ch3/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -436,39 +434,38 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"12","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch2","d":{"ch2":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); - const messages = []; + const messages: Subscription.Message[] = []; const channel = pubnub.channel('ch1'); const subscription = channel.subscription(); - const listener = { message: (m) => messages.push(m) }; + const listener = { message: (m: Subscription.Message) => messages.push(m) }; subscription.addListener(listener); - const messagePromise = new Promise((resolveMessage) => + const messagePromise = new Promise((resolveMessage) => subscription.addListener({ message: (m) => resolveMessage(m), }), ); subscription.removeListener(listener); subscription.subscribe(); - expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch1']); const actual = await messagePromise; expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); expect(messages.length).to.equal(0); - const subscriptionCh2 = pubnub.channel('ch2').subscription(); subscriptionCh2.subscribe(); - expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch1', 'ch2']); - const subscriptionCh3 = pubnub.channel('ch3').subscription(); const subscriptionSetCh23 = subscriptionCh3.addSubscription(pubnub.channel('ch2').subscription()); + const messagePromiseChannel2 = new Promise((resolveMessage) => + subscriptionSetCh23.addListener({ + message: (m) => resolveMessage(m), + }), + ); subscriptionSetCh23.subscribe(); - expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch1', 'ch2', 'ch3']); - subscription.unsubscribe(); - expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch2', 'ch3']); - subscriptionCh2.unsubscribe(); - expect(pubnub.getSubscribedChannels()).to.deep.equal(['ch2', 'ch3']); + const actualChannel2MessageAfterOneUnsubCh2 = await messagePromiseChannel2; pubnub.destroy(); + expect(JSON.stringify(actualChannel2MessageAfterOneUnsubCh2.message)).to.equal('{"ch2":"My message!"}'); }); it('should work with event type specific listener registraction', async () => { @@ -479,10 +476,9 @@ describe('#listeners', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() .get('/v2/subscribe/mySubKey/ch1/0') @@ -496,30 +492,32 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"3","f":514,"i":"demo","p":{"t":"17069673079697201","r":33},"k":"demo","c":"ch1","d":{"message":"My message!"}}]}', + { 'content-type': 'text/javascript' }, ); - var channel = pubnub.channel('ch1'); - var subscription = channel.subscription(); - var messagePromise = new Promise((resolveMessage) => (subscription.onMessage = (m) => resolveMessage(m))); + const channel = pubnub.channel('ch1'); + const subscription = channel.subscription(); + const messagePromise = new Promise( + (resolveMessage) => (subscription.onMessage = (m) => resolveMessage(m)), + ); subscription.subscribe(); const actual = await messagePromise; expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); }); - it('with presence should work with event type specific listener registraction', async () => { + it('with presence should work with event type specific listener registration', async () => { utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', ee: '', - state: '{}', tt: 0, }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -530,137 +528,26 @@ describe('#listeners', () => { .reply( 200, '{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"p":{"t":"8","r":2},"k":"subKey","c":"ch1-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "testid", "occupancy": 1},"b":"ch1-pnpres"}]}', + { 'content-type': 'text/javascript' }, ); const channel = pubnub.channel('ch1'); const subscription = channel.subscription({ receivePresenceEvents: true }); - const presencePromise = new Promise( + const presencePromise = new Promise( (resolvePresenceEvent) => (subscription.onPresence = (p) => resolvePresenceEvent(p)), ); subscription.subscribe(); const actual = await presencePromise; - expect(JSON.stringify(actual)).to.equal( - '{"channel":"ch1","subscription":null,"action":"join","timetoken":"8","occupancy":1,"uuid":"testid","timestamp":1461451222,"actualChannel":null,"subscribedChannel":"ch1-pnpres"}', - ); - }); - - it('should work with objects data - membership', async () => { - utils - .createNock() - .get('/v2/subscribe/mySubKey/ch1/0') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - ee: '', - state: '{}', - tt: 0, - }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); - utils - .createNock() - .get('/v2/subscribe/mySubKey/ch1/0') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - ee: '', - tt: '3', - tr: 1, - }) - .reply( - 200, - `{"t":{"t":"17087917617921775","r":31},"m":[{"a":"0","f":0,"e":2,"p":{"t":"17087917617921775","r":31},"k":"mySubKey","c":"ch1","d":{"source":"objects","version":"2.0","event":"set","type":"membership","data":{"channel":{"id":"c1"},"eTag":"AZO/t53al7m8fw","updated":"2024-02-24T16:22:41.786844939Z","uuid":{"id":"userIdTest"}}},"b":"ch1"}]}`, - ); - var channel = pubnub.channel('ch1'); - var subscription = channel.subscription(); - var membershipPromise = new Promise((resolveObjects) => - subscription.addListener({ - objects: (objectsEvent) => resolveObjects(objectsEvent), - }), - ); - subscription.subscribe(); - const actual = await membershipPromise; - expect(JSON.stringify(actual)).to.equal( - `{"channel":"ch1","subscription":null,"timetoken":"17087917617921775","message":{"event":"set","type":"membership","data":{"channel":{"id":"c1"},"eTag":"AZO/t53al7m8fw","updated":"2024-02-24T16:22:41.786844939Z","uuid":{"id":"userIdTest"}}}}`, - ); - }); - - it('should work with objects data - channel', async () => { - utils - .createNock() - .get('/v2/subscribe/mySubKey/ch1/0') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - ee: '', - state: '{}', - tt: 0, - }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); - utils - .createNock() - .get('/v2/subscribe/mySubKey/ch1/0') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - ee: '', - tt: '3', - tr: 1, - }) - .reply( - 200, - `{"t":{"t":"17087625097482155","r":33},"m":[{"a":"0","f":0,"e":2,"p":{"t":"17087625097482155","r":33},"k":"mySubKey","c":"ch1","d":{"source":"objects","version":"2.0","event":"set","type":"channel","data":{"custom":{"occupancy":1},"eTag":"125aasww","id":"user-1","updated":"2024-02-24T08:15:09.744661Z"}},"b":"ch1"}]}`, - ); - var channel = pubnub.channel('ch1'); - var subscription = channel.subscription(); - var objectsEventPromise = new Promise((resolveObjects) => - subscription.addListener({ - objects: (objectsEvent) => resolveObjects(objectsEvent), - }), - ); - subscription.subscribe(); - const actual = await objectsEventPromise; - expect(JSON.stringify(actual)).to.equal( - '{"channel":"ch1","subscription":null,"timetoken":"17087625097482155","message":{"event":"set","type":"channel","data":{"custom":{"occupancy":1},"eTag":"125aasww","id":"user-1","updated":"2024-02-24T08:15:09.744661Z"}}}', - ); - }); - - it('should work with message actions', async () => { - utils - .createNock() - .get('/v2/subscribe/mySubKey/ch1/0') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - ee: '', - state: '{}', - tt: 0, - }) - .reply(200, '{"t":{"t":"3","r":1},"m":[]}'); - utils - .createNock() - .get('/v2/subscribe/mySubKey/ch1/0') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - ee: '', - tt: '3', - tr: 1, - }) - .reply( - 200, - `{"t":{"t":"17087942541729876","r":31},"m":[{"a":"0","f":0,"e":3,"i":"userIdTest","p":{"t":"17087942541729876","r":31},"k":"mySubKey","c":"ch1","d":{"source":"actions","version":"1.0","data":{"messageTimetoken":"17087942466262824","type":"reaction","value":"smiley","actionTimetoken":"17087942541639760"},"event":"added"},"b":"ch1"}]}`, - ); - var channel = pubnub.channel('ch1'); - var subscription = channel.subscription(); - var messageActionPromise = new Promise((resolveMessageActionEvent) => - subscription.addListener({ - messageAction: (messageActionEvent) => resolveMessageActionEvent(messageActionEvent), - }), - ); - subscription.subscribe(); - const actual = await messageActionPromise; - expect(JSON.stringify(actual)).to.equal( - '{"channel":"ch1","subscription":null,"timetoken":"17087942541729876","publisher":"userIdTest","data":{"messageTimetoken":"17087942466262824","actionTimetoken":"17087942541639760","type":"reaction","uuid":"userIdTest","value":"smiley"},"event":"added"}', - ); + expect(actual).to.deep.equal({ + channel: 'ch1', + subscription: 'ch1-pnpres', + action: 'join', + occupancy: 1, + uuid: 'testid', + timestamp: 1461451222, + actualChannel: 'ch1', + subscribedChannel: 'ch1-pnpres', + timetoken: '8', + }); }); }); diff --git a/test/integration/components/networking.test.js b/test/integration/components/networking.test.ts similarity index 54% rename from test/integration/components/networking.test.js rename to test/integration/components/networking.test.ts index 3713d3995..bf27209d1 100644 --- a/test/integration/components/networking.test.js +++ b/test/integration/components/networking.test.ts @@ -3,14 +3,16 @@ import assert from 'assert'; import nock from 'nock'; -import utils from '../../utils'; -import PubNub from '../../../src/node/index'; + +// @ts-expect-error Loading package information. import packageJSON from '../../../package.json'; +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; describe('#components/networking', () => { - let pubnub; - let pubnubPartner; - let pubnubSDKName; + let pubnub: PubNub; + let pubnubPartner: PubNub; + let pubnubSDKName: PubNub; before(() => { nock.disableNetConnect(); @@ -26,17 +28,23 @@ describe('#components/networking', () => { subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, }); pubnubPartner = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', partnerId: 'alligator', + // @ts-expect-error Force override default value. + useRequestId: false, }); pubnubSDKName = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, sdkName: 'custom-sdk/1.0.0', }); }); @@ -50,12 +58,16 @@ describe('#components/networking', () => { uuid: 'myUUID', pnsdk: `PubNub-JS-Nodejs-alligator/${packageJSON.version}`, }) - .reply(200, [14570763868573725]); + .reply(200, ['14570763868573725'], { 'content-type': 'text/javascript' }); pubnubPartner.time((status) => { - assert.equal(status.error, false); - assert.equal(status.statusCode, 200); - done(); + try { + assert.equal(status.error, false); + assert.equal(status.statusCode, 200); + done(); + } catch (error) { + done(error); + } }); }); }); @@ -66,12 +78,16 @@ describe('#components/networking', () => { .createNock() .get('/time/0') .query({ uuid: 'myUUID', pnsdk: 'custom-sdk/1.0.0' }) - .reply(200, [14570763868573725]); + .reply(200, ['14570763868573725'], { 'content-type': 'text/javascript' }); pubnubSDKName.time((status) => { - assert.equal(status.error, false); - assert.equal(status.statusCode, 200); - done(); + try { + assert.equal(status.error, false); + assert.equal(status.statusCode, 200); + done(); + } catch (error) { + done(error); + } }); }); }); @@ -82,12 +98,16 @@ describe('#components/networking', () => { .createNock() .get('/time/0') .query(true) - .reply(200, [14570763868573725]); + .reply(200, ['14570763868573725'], { 'content-type': 'text/javascript' }); pubnub.time((status) => { - assert.equal(status.error, false); - assert.equal(status.statusCode, 200); - done(); + try { + assert.equal(status.error, false); + assert.equal(status.statusCode, 200); + done(); + } catch (error) { + done(error); + } }); }); @@ -96,13 +116,17 @@ describe('#components/networking', () => { .createNock() .get('/time/0') .query(true) - .reply(403, [14570763868573725]); + .reply(403, ['14570763868573725'], { 'content-type': 'text/javascript' }); pubnub.time((status) => { - assert.equal(status.error, true); - assert.equal(status.statusCode, 403); - assert.equal(status.category, 'PNAccessDeniedCategory'); - done(); + try { + assert.equal(status.error, true); + assert.equal(status.statusCode, 403); + assert.equal(status.category, 'PNAccessDeniedCategory'); + done(); + } catch (error) { + done(error); + } }); }); @@ -111,13 +135,17 @@ describe('#components/networking', () => { .createNock() .get('/time/0') .query(true) - .reply(400, [14570763868573725]); + .reply(400, ['14570763868573725'], { 'content-type': 'text/javascript' }); pubnub.time((status) => { - assert.equal(status.error, true); - assert.equal(status.statusCode, 400); - assert.equal(status.category, 'PNBadRequestCategory'); - done(); + try { + assert.equal(status.error, true); + assert.equal(status.statusCode, 400); + assert.equal(status.category, 'PNBadRequestCategory'); + done(); + } catch (error) { + done(error); + } }); }); }); diff --git a/test/integration/components/reconnection_manager.test.js b/test/integration/components/reconnection_manager.test.js deleted file mode 100644 index 632f565b8..000000000 --- a/test/integration/components/reconnection_manager.test.js +++ /dev/null @@ -1,128 +0,0 @@ -/* global describe, beforeEach, it, before, afterEach, after */ -/* eslint no-console: 0 */ - -import assert from 'assert'; -import sinon from 'sinon'; -import nock from 'nock'; -import _ from 'underscore'; - -import utils from '../../utils'; -import PubNub from '../../../src/node/index'; - -describe('#components/reconnection_manger', () => { - let pubnub; - let clock; - - before(() => { - nock.disableNetConnect(); - }); - - after(() => { - nock.enableNetConnect(); - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - subscribeKey: 'mySubKey', - publishKey: 'myPublishKey', - uuid: 'myUUID', - heartbeatInterval: 149, - }); - clock = sinon.useFakeTimers(); - }); - - afterEach(() => { - pubnub.stop(); - clock.restore(); - }); - - it('reports when the network is unreachable', (done) => { - utils - .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') - .query(true) - .replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' }); - - utils - .createNock() - .get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat') - .query(true) - .replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' }); - - pubnub.addListener({ - status(statusPayload) { - if (statusPayload.operation !== 'PNSubscribeOperation') return; - let statusWithoutError = _.omit(statusPayload, 'errorData'); - assert.deepEqual( - { - category: 'PNNetworkIssuesCategory', - error: true, - operation: 'PNSubscribeOperation', - }, - statusWithoutError, - ); - done(); - }, - }); - - pubnub.subscribe({ channels: ['ch1', 'ch2'], withPresence: true }); - }); - - it('begins polling and reports reconnects when subscribe is again successful', (done) => { - utils - .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') - .query(true) - .replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' }); - - utils - .createNock() - .get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat') - .query(true) - .replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' }); - - utils.createNock().get('/time/0').query(true).reply(200, [14570763868573725]); - - pubnub.addListener({ - status(statusPayload) { - if (statusPayload.category === 'PNNetworkIssuesCategory') { - utils - .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') - .query(true) - .reply( - 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', - ); - - utils - .createNock() - .get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat') - .query(true) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); - - // Advance the clock so that _performTimeLoop() executes - clock.tick(3500); - } else if (statusPayload.category === 'PNReconnectedCategory') { - assert.deepEqual( - { - category: 'PNReconnectedCategory', - operation: 'PNSubscribeOperation', - currentTimetoken: 0, - lastTimetoken: 0, - }, - statusPayload, - ); - done(); - } - }, - }); - - pubnub.subscribe({ - channels: ['ch1', 'ch2'], - withPresence: true, - withHeathbeats: true, - }); - }); -}); diff --git a/test/integration/components/reconnection_manager.test.ts b/test/integration/components/reconnection_manager.test.ts new file mode 100644 index 000000000..d2afe707a --- /dev/null +++ b/test/integration/components/reconnection_manager.test.ts @@ -0,0 +1,164 @@ +/* global describe, beforeEach, it, before, afterEach, after */ +/* eslint no-console: 0 */ + +import assert from 'assert'; +import _ from 'underscore'; +import sinon from 'sinon'; +import nock from 'nock'; + +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; + +describe('#components/reconnection_manger', () => { + let clock: sinon.SinonFakeTimers; + let pubnub: PubNub; + + before(() => { + nock.disableNetConnect(); + }); + + after(() => { + nock.enableNetConnect(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + origin: 'ps.pndsn.com', + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, + heartbeatInterval: 149, + }); + clock = sinon.useFakeTimers(); + }); + + afterEach(() => { + pubnub.destroy(); + clock.restore(); + }); + + it('reports when the network is unreachable', (done) => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') + .query(true) + .replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' }); + + utils + .createNock() + .get('/v2/presence/sub-key/mySubKey/channel/ch1,ch2/heartbeat') + .query(true) + .replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' }); + + pubnub.addListener({ + status(statusPayload) { + if (statusPayload.operation !== PubNub.OPERATIONS.PNSubscribeOperation) return; + let statusWithoutError = _.omit(statusPayload, ['errorData', 'statusCode']); + try { + assert.deepEqual( + { + category: PubNub.CATEGORIES.PNNetworkIssuesCategory, + error: true, + operation: PubNub.OPERATIONS.PNSubscribeOperation + }, + statusWithoutError + ); + + utils + .createNock() + .get("/v2/presence/sub-key/mySubKey/channel/ch1,ch2/leave") + .query(true) + .reply(200, "{\"status\": 200, \"message\": \"OK\", \"service\": \"Presence\"}", { + "content-type": "text/javascript" + }); + + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnub.subscribe({ channels: ['ch1', 'ch2'], withPresence: true }); + }); + + it('begins polling and reports reconnects when subscribe is again successful', (done) => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') + .query(true) + .replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' }); + + utils + .createNock() + .get('/v2/presence/sub-key/mySubKey/channel/ch1,ch2/heartbeat') + .query(true) + .replyWithError({ message: 'Network unavailable', code: 'ENOTFOUND' }); + + utils + .createNock() + .get('/time/0') + .query(true) + .reply(200, [14570763868573725], { 'content-type': 'text/javascript' }); + + pubnub.addListener({ + status(statusPayload) { + if (statusPayload.category === PubNub.CATEGORIES.PNNetworkIssuesCategory) { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') + .query(true) + .reply( + 200, + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, + ); + + utils + .createNock() + .get('/v2/presence/sub-key/mySubKey/channel/ch1,ch2/heartbeat') + .query(true) + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { + 'content-type': 'text/javascript', + }); + + // Advance the clock so that _performTimeLoop() executes + clock.tick(3500); + } else if (statusPayload.category === PubNub.CATEGORIES.PNReconnectedCategory) { + try { + assert.deepEqual( + { + category: PubNub.CATEGORIES.PNReconnectedCategory, + operation: PubNub.OPERATIONS.PNSubscribeOperation, + currentTimetoken: 0, + lastTimetoken: 0 + }, + statusPayload + ); + + utils + .createNock() + .get("/v2/presence/sub-key/mySubKey/channel/ch1,ch2/leave") + .query(true) + .reply(200, "{\"status\": 200, \"message\": \"OK\", \"service\": \"Presence\"}", { + "content-type": "text/javascript" + }); + + done(); + } catch (error) { + done(error); + } + } + }, + }); + + pubnub.subscribe({ + channels: ['ch1', 'ch2'], + withPresence: true, + withHeartbeats: true, + }); + }); +}); diff --git a/test/integration/components/subscription_manager.test.js b/test/integration/components/subscription_manager.test.ts similarity index 55% rename from test/integration/components/subscription_manager.test.js rename to test/integration/components/subscription_manager.test.ts index dfc871aaf..3a8ebb9c1 100644 --- a/test/integration/components/subscription_manager.test.js +++ b/test/integration/components/subscription_manager.test.ts @@ -2,17 +2,17 @@ /* eslint no-console: 0 */ import assert from 'assert'; -import nock from 'nock'; import _ from 'underscore'; +import nock from 'nock'; -import utils from '../../utils'; import PubNub from '../../../src/node/index'; +import utils from '../../utils'; describe('#components/subscription_manager', () => { - let pubnub; - let pubnubWithPassingHeartbeats; - let pubnubWithLimitedQueue; - let pubnubWithCrypto; + let pubnub: PubNub; + let pubnubWithPassingHeartbeats: PubNub; + let pubnubWithLimitedQueue: PubNub; + let pubnubWithCrypto: PubNub; before(() => { nock.disableNetConnect(); @@ -27,22 +27,31 @@ describe('#components/subscription_manager', () => { pubnub = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', + origin: 'ps.pndsn.com', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, autoNetworkDetection: false, heartbeatInterval: 149, }); pubnubWithPassingHeartbeats = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', + origin: 'ps.pndsn.com', uuid: 'myUUID', + // @ts-expect-error: This configuration option normally is hidden. announceSuccessfulHeartbeats: true, + useRequestId: false, autoNetworkDetection: false, heartbeatInterval: 149, }); pubnubWithLimitedQueue = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', + origin: 'ps.pndsn.com', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, requestMessageCountThreshold: 1, autoNetworkDetection: false, heartbeatInterval: 149, @@ -50,7 +59,10 @@ describe('#components/subscription_manager', () => { pubnubWithCrypto = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', + origin: 'ps.pndsn.com', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, cryptoModule: PubNub.CryptoModule.aesCbcCryptoModule({ cipherKey: 'cipherKey' }), }); }); @@ -64,7 +76,7 @@ describe('#components/subscription_manager', () => { it('passes the correct message information', (done) => { const scope1 = utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -72,12 +84,13 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); const scope2 = utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -87,12 +100,13 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client2", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message3"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client2", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message3"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); const scope3 = utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -102,8 +116,14 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"20","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client3", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message10"},"b":"coolChan-bnel", "u": {"cool": "meta"}}]}' + '{"t":{"t":"20","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client3", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message10"},"b":"coolChan-bnel", "u": {"cool": "meta"}}]}', + { 'content-type': 'text/javascript' }, ); + utils + .createNock() + .get(/heartbeat$/) + .query(true) + .reply(200, '{"status": 200,"message":"OK","service":"Presence"}', { 'content-type': 'text/javascript' }); let incomingPayloads = []; @@ -112,48 +132,53 @@ describe('#components/subscription_manager', () => { incomingPayloads.push(messagePayload); if (incomingPayloads.length === 3) { - assert.equal(scope1.isDone(), true); - assert.equal(scope2.isDone(), true); - assert.equal(scope3.isDone(), true); - assert.deepEqual(incomingPayloads, [ - { - actualChannel: 'coolChannel', - message: { - text: 'Message', + try { + assert.equal(scope1.isDone(), true); + assert.equal(scope2.isDone(), true); + assert.equal(scope3.isDone(), true); + assert.deepEqual(incomingPayloads, [ + { + actualChannel: "coolChannel", + message: { + text: "Message" + }, + subscribedChannel: "coolChan-bnel", + channel: "coolChannel", + subscription: "coolChan-bnel", + timetoken: "14607577960925503", + publisher: "client1" }, - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', - timetoken: '14607577960925503', - publisher: 'client1', - }, - { - actualChannel: 'coolChannel', - message: { - text: 'Message3', + { + actualChannel: "coolChannel", + message: { + text: "Message3" + }, + subscribedChannel: "coolChan-bnel", + channel: "coolChannel", + subscription: "coolChan-bnel", + timetoken: "14607577960925503", + publisher: "client2" }, - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', - timetoken: '14607577960925503', - publisher: 'client2', - }, - { - actualChannel: 'coolChannel', - message: { - text: 'Message10', - }, - userMetadata: { - cool: 'meta', - }, - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', - timetoken: '14607577960925503', - publisher: 'client3', - }, - ]); - done(); + { + actualChannel: "coolChannel", + message: { + text: "Message10" + }, + userMetadata: { + cool: "meta" + }, + subscribedChannel: "coolChan-bnel", + channel: "coolChannel", + subscription: "coolChan-bnel", + timetoken: "14607577960925503", + publisher: "client3" + } + ]); + + done(); + } catch (error) { + done(error); + } } }, }); @@ -164,7 +189,7 @@ describe('#components/subscription_manager', () => { it('passes the correct presence information', (done) => { const scope = utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -172,28 +197,32 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}' + '{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}', + { 'content-type': 'text/javascript' }, ); pubnub.addListener({ presence(presencePayload) { - assert.equal(scope.isDone(), true); - assert.deepEqual( - { - channel: 'coolChannel', - subscription: null, - actualChannel: null, - occupancy: 1, - subscribedChannel: 'coolChannel-pnpres', - timestamp: 1461451222, - timetoken: '14614512228418349', - uuid: '4a6d5df7-e301-4e73-a7b7-6af9ab484eb0', - action: 'join', - state: undefined, - }, - presencePayload - ); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual( + { + channel: "coolChannel", + subscription: "coolChannel-pnpres", + actualChannel: "coolChannel", + occupancy: 1, + subscribedChannel: "coolChannel-pnpres", + timestamp: 1461451222, + timetoken: "14614512228418349", + uuid: "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", + action: "join" + }, + presencePayload + ); + done(); + } catch (error) { + done(error); + } }, }); @@ -201,9 +230,10 @@ describe('#components/subscription_manager', () => { }); it('Unknown category status returned when user trigger TypeError in subscription handler', (done) => { - const scope1 = utils + let callDone = false; + utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch1-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -211,48 +241,67 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"ch1","d":{"text":"Message"},"b":"ch1"}]}' + '{"t":{"t":"6","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"ch1","d":{"text":"Message"},"b":"ch1"}]}', + { 'content-type': 'text/javascript' }, ); - const scope2 = utils + utils .createNock() .get(/heartbeat$/) .query(true) - .reply(200, '{"status": 200,"message":"OK","service":"Presence"}'); - const scope3 = utils + .reply(200, '{"status": 200,"message":"OK","service":"Presence"}', { 'content-type': 'text/javascript' }); + utils .createNock() .get(/leave$/) .query(true) - .reply(200, '{"status": 200,"message":"OK","action":"leave","service":"Presence"}'); - const scope4 = utils + .reply(200, '{"status": 200,"message":"OK","action":"leave","service":"Presence"}', { + 'content-type': 'text/javascript', + }); + utils .createNock() .get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') .query(true) - .reply(200, '[1,"Sent","14647523059145592"]'); + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + heartbeat: 300, + tt: 6, + }) + .reply(200, '{"t":{"t":"9","r":1},"m":[]}', { 'content-type': 'text/javascript' }); pubnub.addListener({ - message(message) { + message(_) { + // @ts-expect-error Intentional exception. null.test; }, status(status) { - if (status.category === "PNUnknownCategory") { - assert.equal(status.errorData instanceof Error, true); - done(); - } else if (status.category === "PNConnectedCategory") { - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1' }, - (status, response) => { } - ); + if (status.category === PubNub.CATEGORIES.PNUnknownCategory && 'statusCode' in status) { + try { + assert.equal(status.errorData instanceof Error, true); + if (!callDone) { + callDone = true; + done(); + } + } catch (error) { + done(error); + } + } else if (status.category === PubNub.CATEGORIES.PNConnectedCategory) { + pubnub.publish({ message: { such: 'object' }, channel: 'ch1' }, () => {}); } - } + }, }); pubnub.subscribe({ channels: ['ch1'], withPresence: true }); }); it('passes the correct presence information when state is changed', (done) => { - const scope = utils + const scope1 = utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -260,30 +309,46 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14637536741734954","r":1},"m":[{"a":"4","f":512,"p":{"t":"14637536740940378","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "join", "timestamp": 1463753674, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"},{"a":"4","f":512,"p":{"t":"14637536741726901","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "state-change", "timestamp": 1463753674, "data": {"state": "cool"}, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"}]}' + '{"t":{"t":"14637536741734954","r":1},"m":[{"a":"4","f":512,"p":{"t":"14637536740940378","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "join", "timestamp": 1463753674, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"},{"a":"4","f":512,"p":{"t":"14637536741726901","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "state-change", "timestamp": 1463753674, "data": {"state": "cool"}, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"}]}', + { 'content-type': 'text/javascript' }, ); + utils + .createNock() + .get(/heartbeat$/) + .query(true) + .reply(200, '{"status": 200,"message":"OK","service":"Presence"}'); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + heartbeat: 300, + tt: '14637536741734954', + }) + .reply(200, '{"t":{"t":"9","r":1},"m":[]}', { 'content-type': 'text/javascript' }); pubnub.addListener({ presence(presencePayload) { if (presencePayload.action !== 'state-change') return; - - assert.equal(scope.isDone(), true); - assert.deepEqual( - { - channel: 'ch10', - subscription: null, - actualChannel: null, + try { + assert.equal(scope1.isDone(), true); + assert.deepEqual(presencePayload, { + channel: "ch10", + subscription: "ch10-pnpres", + actualChannel: "ch10", occupancy: 3, - subscribedChannel: 'ch10-pnpres', + subscribedChannel: "ch10-pnpres", timestamp: 1463753674, - timetoken: '14637536741726901', - uuid: '24c9bb19-1fcd-4c40-a6f1-522a8a1329ef', - action: 'state-change', - state: { state: 'cool' }, - }, - presencePayload - ); - done(); + timetoken: "14637536741726901", + uuid: "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", + action: "state-change", + state: { state: "cool" } + }); + done(); + } catch (error) { + done(error); + } }, }); @@ -291,23 +356,34 @@ describe('#components/subscription_manager', () => { }); it('reports when heartbeats failed', (done) => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + heartbeat: 300, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); + pubnub.addListener({ status(statusPayload) { - if ( - statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation - ) { - return; + if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + + let statusWithoutError = _.omit(statusPayload, 'errorData', 'statusCode'); + try { + assert.deepEqual( + { + category: PubNub.CATEGORIES.PNUnknownCategory, + error: true, + operation: PubNub.OPERATIONS.PNHeartbeatOperation + }, + statusWithoutError + ); + done(); + } catch (error) { + done(error); } - let statusWithoutError = _.omit(statusPayload, 'errorData'); - assert.deepEqual( - { - category: 'PNUnknownCategory', - error: true, - operation: 'PNHeartbeatOperation', - }, - statusWithoutError - ); - done(); }, }); @@ -321,34 +397,35 @@ describe('#components/subscription_manager', () => { it('reports when heartbeats fail with error code', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat') + .get('/v2/presence/sub-key/mySubKey/channel/ch1,ch2/heartbeat') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, state: '{}', }) - .reply(400, '{"status": 400, "message": "OK", "service": "Presence"}'); + .reply(400, '{"status": 400, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnub.addListener({ status(statusPayload) { - if ( - statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation - ) { - return; - } + if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + let statusWithoutError = _.omit(statusPayload, 'errorData'); - assert.equal(scope.isDone(), true); - assert.deepEqual( - { - category: 'PNBadRequestCategory', - error: true, - operation: 'PNHeartbeatOperation', - statusCode: 400, - }, - statusWithoutError - ); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual( + { + category: PubNub.CATEGORIES.PNBadRequestCategory, + error: true, + operation: PubNub.OPERATIONS.PNHeartbeatOperation, + statusCode: 400 + }, + statusWithoutError + ); + done(); + } catch (error) { + done(error); + } }, }); @@ -362,33 +439,34 @@ describe('#components/subscription_manager', () => { it('reports when heartbeats pass', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat') + .get('/v2/presence/sub-key/mySubKey/channel/ch1,ch2/heartbeat') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, state: '{}', }) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnubWithPassingHeartbeats.addListener({ status(statusPayload) { - if ( - statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation - ) { - return; - } + if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; - assert.equal(scope.isDone(), true); - assert.deepEqual( - { - error: false, - operation: 'PNHeartbeatOperation', - statusCode: 200, - }, - statusPayload - ); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual( + { + error: false, + operation: PubNub.OPERATIONS.PNHeartbeatOperation, + category: PubNub.CATEGORIES.PNAcknowledgmentCategory, + statusCode: 200 + }, + statusPayload + ); + done(); + } catch (error) { + done(error); + } }, }); @@ -402,33 +480,34 @@ describe('#components/subscription_manager', () => { it('reports when heartbeats pass with heartbeatChannels', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubKey/channel/ch1%2Cch2/heartbeat') + .get('/v2/presence/sub-key/mySubKey/channel/ch1,ch2/heartbeat') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: 300, state: '{}', }) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnubWithPassingHeartbeats.addListener({ status(statusPayload) { - if ( - statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation - ) { - return; - } + if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; - assert.equal(scope.isDone(), true); - assert.deepEqual( - { - error: false, - operation: 'PNHeartbeatOperation', - statusCode: 200, - }, - statusPayload - ); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual( + { + error: false, + operation: PubNub.OPERATIONS.PNHeartbeatOperation, + category: PubNub.CATEGORIES.PNAcknowledgmentCategory, + statusCode: 200 + }, + statusPayload + ); + done(); + } catch (error) { + done(error); + } }, }); @@ -441,7 +520,7 @@ describe('#components/subscription_manager', () => { it('reports when heartbeats pass with heartbeatChannelGroups', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubKey/channel/%2C/heartbeat') + .get('/v2/presence/sub-key/mySubKey/channel/,/heartbeat') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -449,26 +528,27 @@ describe('#components/subscription_manager', () => { state: '{}', 'channel-group': 'cg1', }) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnubWithPassingHeartbeats.addListener({ status(statusPayload) { - if ( - statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation - ) { - return; - } + if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; - assert.equal(scope.isDone(), true); - assert.deepEqual( - { - error: false, - operation: 'PNHeartbeatOperation', - statusCode: 200, - }, - statusPayload - ); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual( + { + error: false, + operation: PubNub.OPERATIONS.PNHeartbeatOperation, + category: PubNub.CATEGORIES.PNAcknowledgmentCategory, + statusCode: 200 + }, + statusPayload + ); + done(); + } catch (error) { + done(error); + } }, }); @@ -481,7 +561,7 @@ describe('#components/subscription_manager', () => { it('reports when the queue is beyond set threshold', (done) => { const scope = utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -489,28 +569,32 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}' + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}', + { 'content-type': 'text/javascript' }, ); + utils + .createNock() + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + heartbeat: 300, + tt: 3, + }) + .reply(200, '{"t":{"t":"3","r":1},"m":[]}', { 'content-type': 'text/javascript' }); pubnubWithLimitedQueue.addListener({ status(statusPayload) { - if ( - statusPayload.category !== - PubNub.CATEGORIES.PNRequestMessageCountExceededCategory - ) { - return; - } + if (statusPayload.category !== PubNub.CATEGORIES.PNRequestMessageCountExceededCategory) return; - assert.equal(scope.isDone(), true); - assert.equal( - statusPayload.category, - PubNub.CATEGORIES.PNRequestMessageCountExceededCategory - ); - assert.equal( - statusPayload.operation, - PubNub.OPERATIONS.PNSubscribeOperation - ); - done(); + try { + assert.equal(scope.isDone(), true); + assert.equal(statusPayload.category, PubNub.CATEGORIES.PNRequestMessageCountExceededCategory); + assert.equal(statusPayload.operation, PubNub.OPERATIONS.PNSubscribeOperation); + done(); + } catch (error) { + done(error); + } }, }); @@ -521,12 +605,13 @@ describe('#components/subscription_manager', () => { }); it('supports deduping on duplicates', (done) => { + // @ts-expect-error: This configuration option normally is hidden. pubnub._config.dedupeOnSubscribe = true; let messageCount = 0; utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -534,12 +619,13 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -549,7 +635,8 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}', + { 'content-type': 'text/javascript' }, ); pubnub.addListener({ @@ -563,7 +650,7 @@ describe('#components/subscription_manager', () => { setTimeout(() => { if (messageCount === 1) { done(); - } + } else done(new Error(`Received unexpected number of messages: ${messageCount} (expected: 1)`)); }, 250); }); @@ -572,7 +659,7 @@ describe('#components/subscription_manager', () => { utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -580,12 +667,13 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -595,7 +683,8 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}', + { 'content-type': 'text/javascript' }, ); pubnub.addListener({ @@ -609,18 +698,20 @@ describe('#components/subscription_manager', () => { setTimeout(() => { if (messageCount === 3) { done(); - } + } else done(new Error(`Received unexpected number of messages: ${messageCount} (expected: 3)`)); }, 250); }); it('supports deduping on shallow queue', (done) => { + // @ts-expect-error: This configuration option normally is hidden. pubnub._config.dedupeOnSubscribe = true; + // @ts-expect-error: This configuration option normally is hidden. pubnub._config.maximumCacheSize = 1; let messageCount = 0; utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -628,12 +719,13 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); utils .createNock() - .get('/v2/subscribe/mySubKey/ch1%2Cch2%2Cch1-pnpres%2Cch2-pnpres/0') + .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -643,7 +735,8 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message2"},"b":"coolChannel"}, {"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message2"},"b":"coolChannel"}, {"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"}]}', + { 'content-type': 'text/javascript' }, ); pubnub.addListener({ @@ -657,10 +750,10 @@ describe('#components/subscription_manager', () => { setTimeout(() => { if (messageCount === 4) { done(); - } + } else done(new Error(`Received unexpected number of messages: ${messageCount} (expected: 4)`)); }, 250); }); - + it('handles unencrypted message when cryptoModule is configured', (done) => { const scope = utils .createNock() @@ -673,6 +766,7 @@ describe('#components/subscription_manager', () => { .reply( 200, '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":"hello","b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); let incomingPayloads = []; @@ -681,20 +775,24 @@ describe('#components/subscription_manager', () => { message(messagePayload) { incomingPayloads.push(messagePayload); if (incomingPayloads.length === 1) { - assert.equal(scope.isDone(), true); - assert.deepEqual(incomingPayloads, [ - { - actualChannel: 'coolChannel', - message: 'hello', - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', - timetoken: '14607577960925503', - publisher: 'client1', - error: 'Error while decrypting message content: decryption error. invalid header version', - }, - ]); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual(incomingPayloads, [ + { + actualChannel: "coolChannel", + message: "hello", + subscribedChannel: "coolChan-bnel", + channel: "coolChannel", + subscription: "coolChan-bnel", + timetoken: "14607577960925503", + publisher: "client1", + error: "Error while decrypting message content: Decryption error: invalid header version" + } + ]); + done(); + } catch (error) { + done(error); + } } }, }); @@ -715,6 +813,7 @@ describe('#components/subscription_manager', () => { .reply( 200, '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":"hello","b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); let incomingPayloads = []; @@ -723,20 +822,24 @@ describe('#components/subscription_manager', () => { message(messagePayload) { incomingPayloads.push(messagePayload); if (incomingPayloads.length === 1) { - assert.equal(scope.isDone(), true); - assert.deepEqual(incomingPayloads, [ - { - actualChannel: 'coolChannel', - message: 'hello', - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', - timetoken: '14607577960925503', - publisher: 'client1', - error: 'Error while decrypting message content: decryption error. invalid header version', - }, - ]); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual(incomingPayloads, [ + { + actualChannel: "coolChannel", + message: "hello", + subscribedChannel: "coolChan-bnel", + channel: "coolChannel", + subscription: "coolChan-bnel", + timetoken: "14607577960925503", + publisher: "client1", + error: "Error while decrypting message content: Decryption error: invalid header version" + } + ]); + done(); + } catch (error) { + done(error); + } } }, }); @@ -756,6 +859,7 @@ describe('#components/subscription_manager', () => { .reply( 200, '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":"UE5FRAFBQ1JIEIocqA6BfaybN/3U0WJRam0v3bPwfAXezgeCeGp+MztQ","b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); let incomingPayloads = []; @@ -764,19 +868,23 @@ describe('#components/subscription_manager', () => { message(messagePayload) { incomingPayloads.push(messagePayload); if (incomingPayloads.length === 1) { - assert.equal(scope.isDone(), true); - assert.deepEqual(incomingPayloads, [ - { - actualChannel: 'coolChannel', - message: 'hello', - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', - timetoken: '14607577960925503', - publisher: 'client1', - }, - ]); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual(incomingPayloads, [ + { + actualChannel: "coolChannel", + message: "hello", + subscribedChannel: "coolChan-bnel", + channel: "coolChannel", + subscription: "coolChan-bnel", + timetoken: "14607577960925503", + publisher: "client1" + } + ]); + done(); + } catch (error) { + done(error); + } } }, }); diff --git a/test/integration/components/token_manager.test.js b/test/integration/components/token_manager.test.ts similarity index 60% rename from test/integration/components/token_manager.test.js rename to test/integration/components/token_manager.test.ts index 3dd26f60c..99751afa4 100644 --- a/test/integration/components/token_manager.test.js +++ b/test/integration/components/token_manager.test.ts @@ -2,16 +2,19 @@ /* eslint no-console: 0 */ import assert from 'assert'; + import PubNub from '../../../src/node/index'; describe('#components/token_manager', () => { - let pubnub; + let pubnub: PubNub; beforeEach(() => { pubnub = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', - uuid: 'myUUID' + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, }); }); @@ -23,8 +26,9 @@ describe('#components/token_manager', () => { }); it('contains correct permissions', () => { - let tokenWithAll = 'p0F2AkF0GmEK-4NDdHRsGDxDcmVzpURjaGFuoWhjaGFubmVsMQFDZ3JwoWZncm91cDEBQ3VzcqBDc3BjoER1dWlkoWV1c2VyMQFDcGF0pURjaGFuoWIuKgFDZ3JwoWIuKgFDdXNyoENzcGOgRHV1aWShYi4qAURtZXRhoENzaWdYII5bQpWLi6Z-l5jbShWxZ7QL6o8Dz6_vxluhxrMGzQCN'; - let permissions = pubnub.parseToken(tokenWithAll); + let tokenWithAll = + 'p0F2AkF0GmEK-4NDdHRsGDxDcmVzpURjaGFuoWhjaGFubmVsMQFDZ3JwoWZncm91cDEBQ3VzcqBDc3BjoER1dWlkoWV1c2VyMQFDcGF0pURjaGFuoWIuKgFDZ3JwoWIuKgFDdXNyoENzcGOgRHV1aWShYi4qAURtZXRhoENzaWdYII5bQpWLi6Z-l5jbShWxZ7QL6o8Dz6_vxluhxrMGzQCN'; + let permissions = pubnub.parseToken(tokenWithAll)!; assert(permissions.version === 2); assert(permissions.timestamp === 1628109699); @@ -32,6 +36,7 @@ describe('#components/token_manager', () => { assert(permissions.meta === undefined); assert(permissions.signature instanceof Buffer); + assert(permissions.resources !== undefined); assert(typeof permissions.resources === 'object'); assert(typeof permissions.resources.uuids === 'object'); assert(typeof permissions.resources.channels === 'object'); @@ -42,19 +47,26 @@ describe('#components/token_manager', () => { assert(typeof permissions.patterns.channels === 'object'); assert(typeof permissions.patterns.groups === 'object'); + assert(permissions.resources.uuids.user1 !== undefined); assert(permissions.resources.uuids.user1.read === true); + assert(permissions.resources.channels.channel1 !== undefined); assert(permissions.resources.channels.channel1.read === true); + assert(permissions.resources.groups.group1 !== undefined); assert(permissions.resources.groups.group1.read === true); + assert(permissions.patterns.uuids['.*'] !== undefined); assert(permissions.patterns.uuids['.*'].read === true); + assert(permissions.patterns.channels['.*'] !== undefined); assert(permissions.patterns.channels['.*'].read === true); + assert(permissions.patterns.groups['.*'] !== undefined); assert(permissions.patterns.groups['.*'].read === true); }); }); describe('supports token update', () => { it('support get and set token', () => { - let token = 'p0F2AkF0GmEK8NZDdHRsGDxDcmVzpURjaGFuoENncnCgQ3VzcqBDc3BjoER1dWlkoWV1c2VyMRhoQ3BhdKVEY2hhbqBDZ3JwoEN1c3KgQ3NwY6BEdXVpZKBEbWV0YaBDc2lnWCB6sYaT3ZbNVV6TBxDKGvdOk6TSQRMoRZir4cwoN9-_dA=='; + let token = + 'p0F2AkF0GmEK8NZDdHRsGDxDcmVzpURjaGFuoENncnCgQ3VzcqBDc3BjoER1dWlkoWV1c2VyMRhoQ3BhdKVEY2hhbqBDZ3JwoEN1c3KgQ3NwY6BEdXVpZKBEbWV0YaBDc2lnWCB6sYaT3ZbNVV6TBxDKGvdOk6TSQRMoRZir4cwoN9-_dA=='; // has uuid id 'user1' pubnub.setToken(token); @@ -65,8 +77,10 @@ describe('#components/token_manager', () => { }); it('adding new token replaces previous', () => { - let token = 'p0F2AkF0GmEK8NZDdHRsGDxDcmVzpURjaGFuoENncnCgQ3VzcqBDc3BjoER1dWlkoWV1c2VyMRhoQ3BhdKVEY2hhbqBDZ3JwoEN1c3KgQ3NwY6BEdXVpZKBEbWV0YaBDc2lnWCB6sYaT3ZbNVV6TBxDKGvdOk6TSQRMoRZir4cwoN9-_dA=='; - let token2 = 'p0F2AkF0GmEK8LFDdHRsGDxDcmVzpURjaGFuoENncnCgQ3VzcqBDc3BjoER1dWlkoWV1c2VyMhhoQ3BhdKVEY2hhbqBDZ3JwoEN1c3KgQ3NwY6BEdXVpZKBEbWV0YaBDc2lnWCDq63hdreA9JbHVnHLDJuHzK-AWSdcVFZKG0nse79JMZw=='; + let token = + 'p0F2AkF0GmEK8NZDdHRsGDxDcmVzpURjaGFuoENncnCgQ3VzcqBDc3BjoER1dWlkoWV1c2VyMRhoQ3BhdKVEY2hhbqBDZ3JwoEN1c3KgQ3NwY6BEdXVpZKBEbWV0YaBDc2lnWCB6sYaT3ZbNVV6TBxDKGvdOk6TSQRMoRZir4cwoN9-_dA=='; + let token2 = + 'p0F2AkF0GmEK8LFDdHRsGDxDcmVzpURjaGFuoENncnCgQ3VzcqBDc3BjoER1dWlkoWV1c2VyMhhoQ3BhdKVEY2hhbqBDZ3JwoEN1c3KgQ3NwY6BEdXVpZKBEbWV0YaBDc2lnWCDq63hdreA9JbHVnHLDJuHzK-AWSdcVFZKG0nse79JMZw=='; // has uuid id 'uuid1' pubnub.setToken(token); diff --git a/test/integration/endpoints/access.test.js b/test/integration/endpoints/access.test.ts similarity index 53% rename from test/integration/endpoints/access.test.js rename to test/integration/endpoints/access.test.ts index b98e4ff8d..75f40c5f6 100644 --- a/test/integration/endpoints/access.test.js +++ b/test/integration/endpoints/access.test.ts @@ -2,21 +2,19 @@ /* eslint no-console: 0 */ import assert from 'assert'; -import nock from 'nock'; import sinon from 'sinon'; +import nock from 'nock'; -import utils from '../../utils'; import PubNub from '../../../src/node/index'; +import utils from '../../utils'; describe('access endpoints', () => { - let pubnub; - let clock; + let clock: sinon.SinonFakeTimers; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); - clock = sinon.useFakeTimers( - new Date(Date.UTC(2011, 9, 1, 0, 0, 0)).getTime() - ); + clock = sinon.useFakeTimers(new Date(Date.UTC(2011, 9, 1, 0, 0, 0)).getTime()); }); after(() => { @@ -30,6 +28,9 @@ describe('access endpoints', () => { subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', secretKey: 'mySecretKey', + origin: 'ps.pndsn.com', + // @ts-expect-error Remove request identifier to match with hardcoded test signature + useRequestId: false, uuid: 'myUUID', }); pubnub._config.getVersion = () => 'suchJavascript'; @@ -49,26 +50,31 @@ describe('access endpoints', () => { }) .reply( 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}' + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, ); pubnub.audit({ channel: 'ch1' }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response, { - level: 'channel-group+auth', - subscribe_key: 'mySubscribeKey', - 'channel-group': 'cg2', - auths: { - key1: { - r: 1, - m: 1, - w: 1, - d: 1, - }, - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert.deepEqual(response, { + level: "channel-group+auth", + subscribe_key: "mySubscribeKey", + "channel-group": "cg2", + auths: { + key1: { + r: 1, + m: 1, + w: 1, + d: 1 + } + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -85,26 +91,31 @@ describe('access endpoints', () => { }) .reply( 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}' + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, ); pubnub.audit({ channelGroup: 'cg1' }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response, { - level: 'channel-group+auth', - subscribe_key: 'mySubscribeKey', - 'channel-group': 'cg2', - auths: { - key1: { - r: 1, - m: 1, - w: 1, - d: 1, - }, - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert.deepEqual(response, { + level: "channel-group+auth", + subscribe_key: "mySubscribeKey", + "channel-group": "cg2", + auths: { + key1: { + r: 1, + m: 1, + w: 1, + d: 1 + } + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -121,26 +132,31 @@ describe('access endpoints', () => { }) .reply( 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}' + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, ); pubnub.audit({ authKeys: ['key1', 'key2'] }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response, { - level: 'channel-group+auth', - subscribe_key: 'mySubscribeKey', - 'channel-group': 'cg2', - auths: { - key1: { - r: 1, - m: 1, - w: 1, - d: 1, - }, - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert.deepEqual(response, { + level: "channel-group+auth", + subscribe_key: "mySubscribeKey", + "channel-group": "cg2", + auths: { + key1: { + r: 1, + m: 1, + w: 1, + d: 1 + } + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); }); @@ -163,21 +179,23 @@ describe('access endpoints', () => { d: 0, g: 0, j: 0, - u: 0 + u: 0, }) .reply( 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":0,"m":0,"w":0,"d":0}}},"service":"Access Manager","status":200}' + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":0,"m":0,"w":0,"d":0}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, ); - pubnub.grant( - { channels: ['ch1', 'ch2'], authKeys: ['key1', 'key2'] }, - (status) => { + pubnub.grant({ channels: ['ch1', 'ch2'], authKeys: ['key1', 'key2'] }, (status) => { + try { assert.equal(status.error, false); assert.equal(scope.isDone(), true); done(); + } catch (error) { + done(error); } - ); + }); }); it('issues the correct RESTful request for channels groups', (done) => { @@ -197,11 +215,12 @@ describe('access endpoints', () => { d: 0, g: 0, j: 0, - u: 0 + u: 0, }) .reply( 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}' + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, ); pubnub.grant( @@ -212,10 +231,14 @@ describe('access endpoints', () => { write: true, }, (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, ); }); @@ -237,11 +260,12 @@ describe('access endpoints', () => { ttl: 1337, g: 0, j: 0, - u: 0 + u: 0, }) .reply( 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":0,"w":1,"d":0}}},"service":"Access Manager","status":200}' + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":0,"w":1,"d":0}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, ); pubnub.grant( @@ -253,10 +277,14 @@ describe('access endpoints', () => { ttl: 1337, }, (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, ); }); @@ -277,26 +305,27 @@ describe('access endpoints', () => { d: 1, g: 1, j: 0, - u: 1 + u: 1, }) .reply( 200, - '{"message":"Success","payload":{"level":"uuid","subscribe_key":"mySubscribeKey","target-uuid":"uuid-1,uuid-2","auths":{"key1":{"r":0,"m":0,"w":0,"d":0}}},"service":"Access Manager","status":200}' + '{"message":"Success","payload":{"level":"uuid","subscribe_key":"mySubscribeKey","target-uuid":"uuid-1,uuid-2","auths":{"key1":{"r":0,"m":0,"w":0,"d":0}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, ); pubnub.grant( - { uuids: ['uuid-1', 'uuid-2'], - authKeys: ['key1', 'key2'], - get: true, - update: true, - delete: true}, + { uuids: ['uuid-1', 'uuid-2'], authKeys: ['key1', 'key2'], get: true, update: true, delete: true }, (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, ); - }); + }); it('issues the correct RESTful request for uuids w/ ttl', (done) => { const scope = utils .createNock() @@ -315,11 +344,12 @@ describe('access endpoints', () => { ttl: 1337, g: 1, j: 0, - u: 1 + u: 1, }) .reply( 200, - '{"message":"Success","payload":{"level":"uuid","subscribe_key":"mySubscribeKey","target-uuid":"uuid-1,uuid-2","auths":{"key1":{"r":0,"m":0,"w":0,"d":1,"j":0,"g":1,"u":1}}},"service":"Access Manager","status":200}' + '{"message":"Success","payload":{"level":"uuid","subscribe_key":"mySubscribeKey","target-uuid":"uuid-1,uuid-2","auths":{"key1":{"r":0,"m":0,"w":0,"d":1,"j":0,"g":1,"u":1}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, ); pubnub.grant( @@ -332,139 +362,163 @@ describe('access endpoints', () => { ttl: 1337, }, (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, ); }); - describe('##validation', () => { - it('channelGroups and uuids in single request', (done) => { - const scope = utils - .createNock() - .get('/v2/auth/grant/sub-key/mySubscribeKey') - .query({ - timestamp: 1317427200, - 'channel-group': 'cg1,cg2', - 'target-uuid': 'uuid-1, uuid-2', - auth: 'key1,key2', - uuid: 'myUUID', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - signature: 'v2.zneRpaqzdxJPegBrJHWMzj-mD8QVBxqh8Zl15N7n2d4', - r: 1, - w: 1, - m: 0, - d: 0, - ttl: 1337, - g: 0, - j: 0, - u: 0 - }) - .reply( - 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":0,"w":1,"d":0}}},"service":"Access Manager","status":200}' - ); - pubnub.grant( - { - channelGroups: ['cg1', 'cg2'], - uuids: ['uuid-1', 'uuid-2'], - authKeys: ['key1', 'key2'], - read: true, - write: true, - ttl: 1337, - } - ).catch((error) => { - assert.equal(scope.isDone(), false); - assert.equal(error.status.message, 'Both channel/channelgroup and uuid cannot be used in the same request'); - done(); + describe('##validation', () => { + it('channelGroups and uuids in single request', (done) => { + const scope = utils + .createNock() + .get('/v2/auth/grant/sub-key/mySubscribeKey') + .query({ + timestamp: 1317427200, + 'channel-group': 'cg1,cg2', + 'target-uuid': 'uuid-1, uuid-2', + auth: 'key1,key2', + uuid: 'myUUID', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + signature: 'v2.zneRpaqzdxJPegBrJHWMzj-mD8QVBxqh8Zl15N7n2d4', + r: 1, + w: 1, + m: 0, + d: 0, + ttl: 1337, + g: 0, + j: 0, + u: 0, + }) + .reply( + 200, + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":0,"w":1,"d":0}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, + ); + + pubnub + .grant({ + channelGroups: ['cg1', 'cg2'], + uuids: ['uuid-1', 'uuid-2'], + authKeys: ['key1', 'key2'], + read: true, + write: true, + ttl: 1337, + }) + .catch((error) => { + try { + assert.equal(scope.isDone(), false); + assert.equal( + error.status.message, + "Both channel/channel group and uuid cannot be used in the same request" + ); + done(); + } catch (error) { + done(error); + } + }); }); - }); - it('channels and uuids in single request', (done) => { - const scope = utils - .createNock() - .get('/v2/auth/grant/sub-key/mySubscribeKey') - .query({ - timestamp: 1317427200, - 'channel': 'ch1,ch2', - 'target-uuid': 'uuid-1, uuid-2', - auth: 'key1,key2', - uuid: 'myUUID', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - signature: 'v2.zneRpaqzdxJPegBrJHWMzj-mD8QVBxqh8Zl15N7n2d4', - r: 1, - w: 1, - m: 0, - d: 0, - ttl: 1337, - g: 0, - j: 0, - u: 0 - }) - .reply( - 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":0,"w":1,"d":0}}},"service":"Access Manager","status":200}' - ); - pubnub.grant( - { - channels: ['ch1', 'ch2'], - uuids: ['uuid-1', 'uuid-2'], - authKeys: ['key1', 'key2'], - read: true, - write: true, - ttl: 1337, - } - ).catch((error) => { - assert.equal(scope.isDone(), false); - assert.equal(error.status.message, 'Both channel/channelgroup and uuid cannot be used in the same request'); - done(); + it('channels and uuids in single request', (done) => { + const scope = utils + .createNock() + .get('/v2/auth/grant/sub-key/mySubscribeKey') + .query({ + timestamp: 1317427200, + channel: 'ch1,ch2', + 'target-uuid': 'uuid-1, uuid-2', + auth: 'key1,key2', + uuid: 'myUUID', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + signature: 'v2.zneRpaqzdxJPegBrJHWMzj-mD8QVBxqh8Zl15N7n2d4', + r: 1, + w: 1, + m: 0, + d: 0, + ttl: 1337, + g: 0, + j: 0, + u: 0, + }) + .reply( + 200, + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":0,"w":1,"d":0}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, + ); + pubnub + .grant({ + channels: ['ch1', 'ch2'], + uuids: ['uuid-1', 'uuid-2'], + authKeys: ['key1', 'key2'], + read: true, + write: true, + ttl: 1337, + }) + .catch((error) => { + try { + assert.equal(scope.isDone(), false); + assert.equal( + error.status.message, + "Both channel/channel group and uuid cannot be used in the same request" + ); + done(); + } catch (error) { + done(error); + } + }); }); - }); - it('uuids and empty authKeys', (done) => { - const scope = utils - .createNock() - .get('/v2/auth/grant/sub-key/mySubscribeKey') - .query({ - timestamp: 1317427200, - 'target-uuid': 'uuid-1, uuid-2', - uuid: 'myUUID', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - signature: 'v2.zneRpaqzdxJPegBrJHWMzj-mD8QVBxqh8Zl15N7n2d4', - r: 1, - w: 1, - m: 0, - d: 0, - ttl: 1337, - g: 0, - j: 0, - u: 0 - }) - .reply( - 200, - '{"message":"Success","payload":{"level":"uuid","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":0,"w":1,"d":0}}},"service":"Access Manager","status":200}' - ); - pubnub.grant( - { - uuids: ['uuid-1', 'uuid-2'], - read: true, - write: true, - ttl: 1337, - } - ).catch((error) => { - assert.equal(scope.isDone(), false); - assert.equal(error.status.message, 'authKeys are required for grant request on uuids'); - done(); + it('uuids and empty authKeys', (done) => { + const scope = utils + .createNock() + .get('/v2/auth/grant/sub-key/mySubscribeKey') + .query({ + timestamp: 1317427200, + 'target-uuid': 'uuid-1,uuid-2', + uuid: 'myUUID', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + signature: 'v2.zneRpaqzdxJPegBrJHWMzj-mD8QVBxqh8Zl15N7n2d4', + r: 1, + w: 1, + m: 0, + d: 0, + ttl: 1337, + g: 0, + j: 0, + u: 0, + }) + .reply( + 200, + '{"message":"Success","payload":{"level":"uuid","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":0,"w":1,"d":0}}},"service":"Access Manager","status":200}', + { 'content-type': 'text/javascript' }, + ); + pubnub + .grant({ + uuids: ['uuid-1', 'uuid-2'], + read: true, + write: true, + ttl: 1337, + }) + .catch((error) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(error.status.message, "authKeys are required for grant request on uuids"); + done(); + } catch (error) { + done(error); + } + }); }); }); - - }); - }); }); describe('access endpoints telemetry', () => { - let pubnub; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); @@ -481,6 +535,8 @@ describe('access endpoints telemetry', () => { publishKey: 'myPublishKey', secretKey: 'mySecretKey', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, }); pubnub._config.getVersion = () => 'suchJavascript'; }); @@ -493,18 +549,19 @@ describe('access endpoints telemetry', () => { const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); const leeway = 50; - utils.runAPIWithResponseDelays(scope, - 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}', - delays, - (completion) => { - pubnub.audit( - { channel: 'ch1' }, - () => { completion(); } - ); - }) + utils + .runAPIWithResponseDelays( + scope, + 200, + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}', + delays, + (completion) => { + pubnub.audit({ channel: 'ch1' }, () => { + completion(); + }); + }, + ) .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_pam', average, leeway); done(); }); }).timeout(20000); @@ -518,18 +575,19 @@ describe('access endpoints telemetry', () => { const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); const leeway = 50; - utils.runAPIWithResponseDelays(scope, - 200, - '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}', - delays, - (completion) => { - pubnub.grant( - { channels: ['ch1', 'ch2'], authKeys: ['key1', 'key2'] }, - () => { completion(); } - ); - }) + utils + .runAPIWithResponseDelays( + scope, + 200, + '{"message":"Success","payload":{"level":"channel-group+auth","subscribe_key":"mySubscribeKey","channel-group":"cg2","auths":{"key1":{"r":1,"m":1,"w":1,"d":1}}},"service":"Access Manager","status":200}', + delays, + (completion) => { + pubnub.grant({ channels: ['ch1', 'ch2'], authKeys: ['key1', 'key2'] }, () => { + completion(); + }); + }, + ) .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_pam', average, leeway); done(); }); }).timeout(20000); diff --git a/test/integration/endpoints/channel_groups.test.js b/test/integration/endpoints/channel_groups.test.js deleted file mode 100644 index dec7ee82a..000000000 --- a/test/integration/endpoints/channel_groups.test.js +++ /dev/null @@ -1,265 +0,0 @@ -/* global describe, beforeEach, it, before, after */ -/* eslint no-console: 0 */ - -import assert from 'assert'; -import nock from 'nock'; -import utils from '../../utils'; -import PubNub from '../../../src/node/index'; - -describe('channel group endpoints', () => { - let pubnub; - - before(() => { - nock.disableNetConnect(); - }); - - after(() => { - nock.enableNetConnect(); - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - subscribeKey: 'mySubKey', - publishKey: 'myPublishKey', - uuid: 'myUUID', - }); - }); - - describe('adding channels to channel group', () => { - it('supports addition of multiple channels', (done) => { - const scope = utils - .createNock() - .get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1') - .query({ - add: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "message": "OK", "payload": {} , "service": "ChannelGroups"}' - ); - - pubnub.channelGroups.addChannels( - { channels: ['a', 'b'], channelGroup: 'cg1' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('should add channels add API telemetry information', (done) => { - let scope = utils.createNock().get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '{"status": 200, "message": "OK", "payload": {} , "service": "ChannelGroups"}', - delays, - (completion) => { - pubnub.channelGroups.addChannels( - { channels: ['a', 'b'], channelGroup: 'cg1' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_cg', average, leeway); - done(); - }); - }).timeout(60000); - }); - - describe('removal of channel group', () => { - it('supports deletion of group', (done) => { - const scope = utils - .createNock() - .get( - '/v1/channel-registration/sub-key/mySubKey/channel-group/cg1/remove' - ) - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "message": "OK", "payload": {} , "service": "ChannelGroups"}' - ); - - pubnub.channelGroups.deleteGroup({ channelGroup: 'cg1' }, (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - }); - }); - - it('should add channel group remove API telemetry information', (done) => { - let scope = utils.createNock().get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1/remove').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '{"status": 200, "message": "OK", "payload": {} , "service": "ChannelGroups"}', - delays, - (completion) => { - pubnub.channelGroups.deleteGroup( - { channelGroup: 'cg1' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_cg', average, leeway); - done(); - }); - }).timeout(60000); - }); - - describe('listing of channel groups', () => { - it('returns a list of all channel groups', (done) => { - const scope = utils - .createNock() - .get('/v1/channel-registration/sub-key/mySubKey/channel-group') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "message": "OK", "payload": {"groups": ["a","b"]}, "service": "ChannelGroups"}' - ); - - pubnub.channelGroups.listGroups((status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.groups, ['a', 'b']); - assert.equal(scope.isDone(), true); - done(); - }); - }); - - it('should add channel groups list API telemetry information', (done) => { - let scope = utils.createNock().get('/v1/channel-registration/sub-key/mySubKey/channel-group').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '{"status": 200, "message": "OK", "payload": {"groups": ["a","b"]}, "service": "ChannelGroups"}', - delays, - (completion) => { - pubnub.channelGroups.listGroups(() => { completion(); }); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_cg', average, leeway); - done(); - }); - }).timeout(60000); - }); - - describe('listing of channels inside channel group', () => { - it('returns a list of all channel groups', (done) => { - const scope = utils - .createNock() - .get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "ChannelGroups"}' - ); - - pubnub.channelGroups.listChannels( - { channelGroup: 'cg1' }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['a', 'b']); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('should add channel group channels list API telemetry information', (done) => { - let scope = utils.createNock().get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "ChannelGroups"}', - delays, - (completion) => { - pubnub.channelGroups.listChannels( - { channelGroup: 'cg1' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_cg', average, leeway); - done(); - }); - }).timeout(60000); - }); - - describe('deletion of channels from channel group', () => { - it('works as expected', (done) => { - const scope = utils - .createNock() - .get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1') - .query({ - remove: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "message": "OK", "payload": {} , "service": "ChannelGroups"}' - ); - - pubnub.channelGroups.removeChannels( - { channels: ['a', 'b'], channelGroup: 'cg1' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('should add channels remove API telemetry information', (done) => { - let scope = utils.createNock().get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '{"status": 200, "message": "OK", "payload": {} , "service": "ChannelGroups"}', - delays, - (completion) => { - pubnub.channelGroups.removeChannels( - { channels: ['a', 'b'], channelGroup: 'cg1' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_cg', average, leeway); - done(); - }); - }).timeout(60000); - }); -}); diff --git a/test/integration/endpoints/channel_groups.test.ts b/test/integration/endpoints/channel_groups.test.ts new file mode 100644 index 000000000..abe20a179 --- /dev/null +++ b/test/integration/endpoints/channel_groups.test.ts @@ -0,0 +1,167 @@ +/* global describe, beforeEach, it, before, after */ +/* eslint no-console: 0 */ + +import assert from 'assert'; +import nock from 'nock'; + +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; + + +describe('channel group endpoints', () => { + let pubnub: PubNub; + + before(() => { + nock.disableNetConnect(); + }); + + after(() => { + nock.enableNetConnect(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, + }); + }); + + describe('adding channels to channel group', () => { + it('supports addition of multiple channels', (done) => { + const scope = utils + .createNock() + .get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1') + .query({ + add: 'a,b', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{"status": 200, "message": "OK", "payload": {} , "service": "ChannelGroups"}', { + 'content-type': 'text/javascript', + }); + + pubnub.channelGroups.addChannels({ channels: ['a', 'b'], channelGroup: 'cg1' }, (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + describe('removal of channel group', () => { + it('supports deletion of group', (done) => { + const scope = utils + .createNock() + .get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1/remove') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{"status": 200, "message": "OK", "payload": {} , "service": "ChannelGroups"}', { + 'content-type': 'text/javascript', + }); + + pubnub.channelGroups.deleteGroup({ channelGroup: 'cg1' }, (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + describe('listing of channel groups', () => { + it('returns a list of all channel groups', (done) => { + const scope = utils + .createNock() + .get('/v1/channel-registration/sub-key/mySubKey/channel-group') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{"status": 200, "message": "OK", "payload": {"groups": ["a","b"]}, "service": "ChannelGroups"}', { + 'content-type': 'text/javascript', + }); + + pubnub.channelGroups.listGroups((status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.groups, ["a", "b"]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + describe('listing of channels inside channel group', () => { + it('returns a list of all channel groups', (done) => { + const scope = utils + .createNock() + .get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply( + 200, + '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "ChannelGroups"}', + { + 'content-type': 'text/javascript', + }, + ); + + pubnub.channelGroups.listChannels({ channelGroup: 'cg1' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, ["a", "b"]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + describe('deletion of channels from channel group', () => { + it('works as expected', (done) => { + const scope = utils + .createNock() + .get('/v1/channel-registration/sub-key/mySubKey/channel-group/cg1') + .query({ + remove: 'a,b', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{"status": 200, "message": "OK", "payload": {} , "service": "ChannelGroups"}', { + 'content-type': 'text/javascript', + }); + + pubnub.channelGroups.removeChannels({ channels: ['a', 'b'], channelGroup: 'cg1' }, (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + }); +}); diff --git a/test/integration/endpoints/fetch_messages.test.js b/test/integration/endpoints/fetch_messages.test.js deleted file mode 100644 index 9ca8fb9df..000000000 --- a/test/integration/endpoints/fetch_messages.test.js +++ /dev/null @@ -1,606 +0,0 @@ -/* global describe, beforeEach, afterEach, it, after */ -/* eslint no-console: 0 */ - -import assert from 'assert'; -import nock from 'nock'; -import utils from '../../utils'; -import PubNub from '../../../src/node/index'; - -function publishMessagesToChannel(client, count, channel, completion) { - let publishCompleted = 0; - let messages = []; - - const publish = (messageIdx) => { - let payload = { message: { messageIdx: [channel, messageIdx].join(': '), time: Date.now() }, channel }; - - if (messageIdx % 2 === 0) { - payload.meta = { time: payload.message.time }; - } - - client.publish(payload, (status, response) => { - publishCompleted += 1; - - if (!status.error) { - messages.push({ message: payload.message, timetoken: response.timetoken }); - messages = messages.sort((left, right) => left.timetoken - right.timetoken); - } else { - console.error('Publish did fail:', status); - } - - if (publishCompleted < count) { - publish(publishCompleted); - } else if (publishCompleted === count) { - completion(messages); - } - }); - }; - - publish(publishCompleted); -} - -function addActionsInChannel(client, count, messageTimetokens, channel, completion) { - const types = ['reaction', 'receipt', 'custom']; - const values = [ - PubNub.generateUUID(), - PubNub.generateUUID(), - PubNub.generateUUID(), - PubNub.generateUUID(), - PubNub.generateUUID(), - PubNub.generateUUID(), - PubNub.generateUUID(), - PubNub.generateUUID(), - PubNub.generateUUID(), - PubNub.generateUUID(), - ]; - let actionsToAdd = []; - let actionsAdded = 0; - let actions = []; - - for (let messageIdx = 0; messageIdx < messageTimetokens.length; messageIdx += 1) { - const messageTimetoken = messageTimetokens[messageIdx]; - - for (let messageActionIdx = 0; messageActionIdx < count; messageActionIdx += 1) { - /** @type MessageAction */ - const action = { type: types[(messageActionIdx + 1) % 3], value: values[(messageActionIdx + 1) % 10] }; - - actionsToAdd.push({ messageTimetoken, action }); - } - } - - const addAction = (actionIdx) => { - const { messageTimetoken, action } = actionsToAdd[actionIdx]; - - client.addMessageAction({ channel, messageTimetoken, action }, (status, response) => { - actionsAdded += 1; - - if (!status.error) { - actions.push(response.data); - actions = actions.sort((left, right) => left.actionTimetoken - right.actionTimetoken); - } else { - console.error('Action add did fail:', status); - } - - if (actionsAdded < actionsToAdd.length) { - addAction(actionsAdded); - } else if (actionsAdded === actionsToAdd.length) { - completion(actions); - } - }); - }; - - addAction(actionsAdded); -} - -describe('fetch messages endpoints', () => { - const subscribeKey = process.env.SUBSCRIBE_KEY || 'demo'; - const publishKey = process.env.PUBLISH_KEY || 'demo'; - let pubnub; - - after(() => { - nock.enableNetConnect(); - }); - - afterEach(() => { - nock.enableNetConnect(); - pubnub.removeAllListeners(); - pubnub.unsubscribeAll(); - pubnub.stop(); - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - subscribeKey, - publishKey, - uuid: 'myUUID', - useRandomIVs: false - }); - }); - - it('supports payload', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1%2Cch2`) - .query({ - max: '10', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - include_uuid: 'true', - include_message_type: 'true', - }) - .reply( - 200, - '{ "channels": { "ch1": [{"message":{"text":"hey1"},"timetoken":"11"}, {"message":{"text":"hey2"},"timetoken":"12"}], "ch2": [{"message":{"text":"hey3"},"timetoken":"21"}, {"message":{"text":"hey2"},"timetoken":"22"}] } }' - ); - - pubnub.fetchMessages({ channels: ['ch1', 'ch2'], count: 10 }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response, { - channels: { - ch1: [ - { - channel: 'ch1', - message: { - text: 'hey1', - }, - timetoken: '11', - messageType: undefined, - uuid: undefined, - }, - { - channel: 'ch1', - message: { - text: 'hey2', - }, - timetoken: '12', - messageType: undefined, - uuid: undefined, - }, - ], - ch2: [ - { - channel: 'ch2', - message: { - text: 'hey3', - }, - timetoken: '21', - messageType: undefined, - uuid: undefined, - }, - { - channel: 'ch2', - message: { - text: 'hey2', - }, - timetoken: '22', - messageType: undefined, - uuid: undefined, - }, - ], - }, - }); - assert.equal(scope.isDone(), true); - done(); - }); - }); - - it('supports encrypted payload', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1%2Cch2`) - .query({ - max: '10', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - include_uuid: 'true', - include_message_type: 'true', - }) - .reply( - 200, - '{ "channels": { "ch1": [{"message":"zFJeF9BVABL80GUiQEBjLg==","timetoken":"11"}, {"message":"zFJeF9BVABL80GUiQEBjLg==","timetoken":"12"}], "ch2": [{"message":"HIq4MTi9nk/KEYlHOKpMCaH78ZXppGynDHrgY9nAd3s=","timetoken":"21"}, {"message":"HIq4MTi9nk/KEYlHOKpMCaH78ZXppGynDHrgY9nAd3s=","timetoken":"22"}] } }' - ); - - pubnub.setCipherKey('cipherKey'); - pubnub.fetchMessages({ channels: ['ch1', 'ch2'], count: 10 }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response, { - channels: { - ch1: [ - { - channel: 'ch1', - message: { - text: 'hey', - }, - timetoken: '11', - messageType: undefined, - uuid: undefined, - }, - { - channel: 'ch1', - message: { - text: 'hey', - }, - timetoken: '12', - messageType: undefined, - uuid: undefined, - }, - ], - ch2: [ - { - channel: 'ch2', - message: { - text2: 'hey2', - }, - timetoken: '21', - messageType: undefined, - uuid: undefined, - }, - { - channel: 'ch2', - message: { - text2: 'hey2', - }, - timetoken: '22', - messageType: undefined, - uuid: undefined, - }, - ], - }, - }); - assert.equal(scope.isDone(), true); - done(); - }); - }); - - it('supports metadata', (done) => { - const channel = PubNub.generateUUID(); - const expectedMessagesCount = 10; - - publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { - pubnub.fetchMessages({ channels: [channel], count: 25, includeMeta: true }, (status, response) => { - const channelMessages = response.channels[channel]; - - assert.deepEqual(channelMessages[0].meta, { time: messages[0].message.time }); - assert(!channelMessages[1].meta); - done(); - }); - }); - }).timeout(60000); - - it('throws when requested actions for multiple channels', () => { - let errorCatched = false; - - try { - pubnub.fetchMessages({ channels: ['channelA', 'channelB'], includeMessageActions: true }, () => {}); - } catch (error) { - assert.equal( - error.message, - 'History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.' - ); - errorCatched = true; - } - - assert(errorCatched); - }); - - it("supports actions (stored as 'data' field)", (done) => { - const channel = PubNub.generateUUID(); - const expectedMessagesCount = 2; - const expectedActionsCount = 4; - - publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { - const messageTimetokens = messages.map((message) => message.timetoken); - - addActionsInChannel(pubnub, expectedActionsCount, messageTimetokens, channel, (actions) => { - setTimeout(() => { - pubnub.fetchMessages({ channels: [channel], includeMessageActions: true }, (status, response) => { - assert.equal(status.error, false); - const fetchedMessages = response.channels[channel]; - const actionsByType = fetchedMessages[0].data; - let historyActionsCount = 0; - - Object.keys(actionsByType).forEach((actionType) => { - Object.keys(actionsByType[actionType]).forEach((actionValue) => { - let actionFound = false; - historyActionsCount += 1; - - actions.forEach((action) => { - if (action.value === actionValue) { - actionFound = true; - } - }); - - assert.equal(actionFound, true); - }); - }); - - assert.equal(historyActionsCount, expectedActionsCount); - assert.equal(fetchedMessages[0].timetoken, messageTimetokens[0]); - assert.equal( - fetchedMessages[fetchedMessages.length - 1].timetoken, - messageTimetokens[messageTimetokens.length - 1] - ); - - done(); - }); - }, 2000); - }); - }); - }).timeout(60000); - - it("supports actions (stored as 'actions' field)", (done) => { - const channel = PubNub.generateUUID(); - const expectedMessagesCount = 2; - const expectedActionsCount = 4; - - publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { - const messageTimetokens = messages.map((message) => message.timetoken); - - addActionsInChannel(pubnub, expectedActionsCount, messageTimetokens, channel, (actions) => { - setTimeout(() => { - pubnub.fetchMessages({ channels: [channel], includeMessageActions: true }, (status, response) => { - assert.equal(status.error, false); - const fetchedMessages = response.channels[channel]; - const actionsByType = fetchedMessages[0].actions; - let historyActionsCount = 0; - - Object.keys(actionsByType).forEach((actionType) => { - Object.keys(actionsByType[actionType]).forEach((actionValue) => { - let actionFound = false; - historyActionsCount += 1; - - actions.forEach((action) => { - if (action.value === actionValue) { - actionFound = true; - } - }); - - assert.equal(actionFound, true); - }); - }); - - assert.equal(historyActionsCount, expectedActionsCount); - assert.equal(fetchedMessages[0].timetoken, messageTimetokens[0]); - assert.equal( - fetchedMessages[fetchedMessages.length - 1].timetoken, - messageTimetokens[messageTimetokens.length - 1] - ); - - done(); - }); - }, 2000); - }); - }); - }).timeout(60000); - - it('should add fetch messages API telemetry information', (done) => { - nock.disableNetConnect(); - let scope = utils.createNock().get(`/v3/history/sub-key/${subscribeKey}/channel/ch1%2Cch2`).query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils - .runAPIWithResponseDelays( - scope, - 200, - '{ "channels": { "ch1": [{"message":{"text":"hey1"},"timetoken":"11"}, {"message":{"text":"hey2"},"timetoken":"12"}], "ch2": [{"message":{"text":"hey3"},"timetoken":"21"}, {"message":{"text":"hey2"},"timetoken":"22"}] } }', - delays, - (completion) => { - pubnub.fetchMessages({ channels: ['ch1', 'ch2'], count: 10 }, () => { - completion(); - }); - } - ) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_hist', average, leeway); - done(); - }); - }).timeout(60000); - - it('should return "more" field when server sends it', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history-with-actions/sub-key/${subscribeKey}/channel/ch1`) - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - max: '25', - include_uuid: 'true', - include_message_type: 'true' - }) - .reply( - 200, - '{"status":200,"error":false,"error_message":"","channels":{"demo-channel":[{"message":"Hi","timetoken":15610547826970040,"actions":{"receipt":{"read":[{"uuid":"user-7","actionTimetoken":15610547826970044}]}}},{"message":"Hello","timetoken":15610547826970000,"actions":{"reaction":{"smiley_face":[{"uuid":"user-456","actionTimetoken":15610547826970050}]}}}]},"more":{"url":"/v3/history-with-actions/sub-key/s/channel/c?start=15610547826970000&max=98","start":"15610547826970000","max":98}}' - ); - pubnub.fetchMessages({ channels: ['ch1'], includeMessageActions: true}, (status, response) => { - assert.equal(status.error, false); - assert.equal(response.more.url, '/v3/history-with-actions/sub-key/s/channel/c?start=15610547826970000&max=98'); - assert.equal(response.more.start, '15610547826970000'); - assert.equal(response.more.max, 98); - done(); - }); - }); - it('should request 100 messages when count not provided with single channel', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1`) - .query({ - max: '100', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - include_uuid: 'true', - include_message_type: 'true', - }) - .reply( - 200, - '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }' - ); - pubnub.fetchMessages({ channels: ['ch1'] }, (status, response) => { - assert.equal(status.error, false); - done(); - }); - }); - - it('should request 25 messages when count not provided with multiple channels', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1%2Cch2`) - .query({ - max: '25', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - include_uuid: 'true', - include_message_type: 'true', - }) - .reply( - 200, - '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }' - ); - pubnub.fetchMessages({ channels: ['ch1', 'ch2'] }, (status, response) => { - assert.equal(status.error, false); - done(); - }); - }); - - it('should request 25 messages when count not provided for history-with-actions', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history-with-actions/sub-key/${subscribeKey}/channel/ch1`) - .query({ - max: '25', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - include_uuid: 'true', - include_message_type: 'true' - }) - .reply( - 200, - '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }' - ); - pubnub.fetchMessages({ channels: ['ch1'], includeMessageActions: true}, (status, response) => { - assert.equal(status.error, false); - done(); - }); - }); - - it('should request provided number of messages when count is specified for history-with-actions', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history-with-actions/sub-key/${subscribeKey}/channel/ch1`) - .query({ - max: '10', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - include_uuid: 'true', - include_message_type: 'true' - }) - .reply( - 200, - '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }' - ); - pubnub.fetchMessages({ channels: ['ch1'], includeMessageActions: true, count: 10}, (status, response) => { - assert.equal(status.error, false); - done(); - }); - }); - - it('should request provided number of messages when count is specified for batch history with single channel', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1`) - .query({ - max: '10', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - include_uuid: 'true', - include_message_type: 'true' - }) - .reply( - 200, - '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }' - ); - pubnub.fetchMessages({ channels: ['ch1'], count: 10}, (status, response) => { - assert.equal(status.error, false); - done(); - }); - }); - - it('should request provided number of messages when count is specified for batch history with multiple channels', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1%2Cch2`) - .query({ - max: '10', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - include_uuid: 'true', - include_message_type: 'true' - }) - .reply( - 200, - '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }' - ); - pubnub.fetchMessages({ channels: ['ch1', 'ch2'], count: 10}, (status, response) => { - assert.equal(status.error, false); - done(); - }); - }); - - it('handles unencrypted payload when cryptomodule configured', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1`) - .query({ - max: '10', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - include_uuid: 'true', - include_message_type: 'true', - }) - .reply( - 200, - '{ "channels": { "ch1": [{"message":"hello","timetoken":"11"}, {"message":"hey","timetoken":"12"}] } }', - ); - - pubnub.setCipherKey('cipherKey'); - pubnub.fetchMessages({ channels: ['ch1'], count: 10 }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response, { - channels: { - ch1: [ - { - channel: 'ch1', - message: 'hello', - timetoken: '11', - messageType: undefined, - uuid: undefined, - error: 'Error while decrypting message content: decryption error. invalid header version', - }, - { - channel: 'ch1', - message: 'hey', - timetoken: '12', - messageType: undefined, - uuid: undefined, - error: 'Error while decrypting message content: decryption error. invalid header version', - }, - ], - }, - }); - assert.equal(scope.isDone(), true); - done(); - }); - }); -}); diff --git a/test/integration/endpoints/fetch_messages.test.ts b/test/integration/endpoints/fetch_messages.test.ts new file mode 100644 index 000000000..7b328a630 --- /dev/null +++ b/test/integration/endpoints/fetch_messages.test.ts @@ -0,0 +1,709 @@ +/* global describe, beforeEach, afterEach, it, after */ +/* eslint no-console: 0 */ + +import assert from 'assert'; +import nock from 'nock'; + +import * as MessageActions from '../../../src/core/types/api/message-action'; +import { Payload } from '../../../src/core/types/api'; +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; +import { PubNubError } from '../../../src/errors/pubnub-error'; + +/** + * Published test message shape. + */ +type TestMessage = { messageIdx: string; time: number }; + +/** + * Prepare messages history. + * + * @param client - PubNub client instance which will be used to publish messages. + * @param count - How many messages should be published. + * @param channel - Name of the channel into which messages should be published. + * @param completion - Messages set publish completion function. + */ +function publishMessagesToChannel( + client: PubNub, + count: number, + channel: string, + completion: (published: { message: TestMessage; timetoken: string }[]) => void, +) { + let messages: { message: TestMessage; timetoken: string }[] = []; + let publishCompleted = 0; + + const publish = (messageIdx: number) => { + let payload: { channel: string; message: TestMessage; meta?: Payload } = { + message: { messageIdx: [channel, messageIdx].join(': '), time: Date.now() }, + channel, + }; + + if (messageIdx % 2 === 0) payload.meta = { time: payload.message.time }; + + client.publish(payload, (status, response) => { + publishCompleted += 1; + + if (!status.error && response) { + messages.push({ message: payload.message, timetoken: response.timetoken }); + messages = messages.sort((left, right) => parseInt(left.timetoken, 10) - parseInt(right.timetoken, 10)); + } else { + console.error('Publish did fail:', status); + } + + if (publishCompleted < count) { + publish(publishCompleted); + } else if (publishCompleted === count) { + completion(messages); + } + }); + }; + + publish(publishCompleted); +} + +/** + * Attach message actions to the previously published messages. + * + * @param client - PubNub client instance which should be used to add message action to the message. + * @param count - How many message actions should be added to each referenced message. + * @param messageTimetokens - List of referenced messages' timetokens. + * @param channel - Name of the channel where referenced messages has been published. + * @param completion - Message actions addition completion function. + */ +function addActionsInChannel( + client: PubNub, + count: number, + messageTimetokens: string[], + channel: string, + completion: (added: MessageActions.MessageAction[]) => void, +) { + const types = ['reaction', 'receipt', 'custom']; + const values = [ + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + ]; + let actions: MessageActions.MessageAction[] = []; + let actionsToAdd: { + messageTimetoken: string; + action: Pick; + }[] = []; + let actionsAdded = 0; + + for (let messageIdx = 0; messageIdx < messageTimetokens.length; messageIdx += 1) { + const messageTimetoken = messageTimetokens[messageIdx]; + + for (let messageActionIdx = 0; messageActionIdx < count; messageActionIdx += 1) { + const action = { type: types[(messageActionIdx + 1) % 3], value: values[(messageActionIdx + 1) % 10] }; + + actionsToAdd.push({ messageTimetoken, action }); + } + } + + /** + * Attach set of message actions. + * + * @param actionIdx - Index of currently adding message action. + */ + const addAction = (actionIdx: number) => { + const { messageTimetoken, action } = actionsToAdd[actionIdx]; + + client.addMessageAction({ channel, messageTimetoken, action }, (status, response) => { + actionsAdded += 1; + + if (!status.error && response) { + actions.push(response.data); + actions = actions.sort( + (left, right) => parseInt(left.actionTimetoken, 10) - parseInt(right.actionTimetoken, 10), + ); + } else { + console.error('Action add did fail:', status); + } + + if (actionsAdded < actionsToAdd.length) { + addAction(actionsAdded); + } else if (actionsAdded === actionsToAdd.length) { + completion(actions); + } + }); + }; + + addAction(actionsAdded); +} + +describe('fetch messages endpoints', () => { + const subscribeKey = process.env.SUBSCRIBE_KEY || 'demo'; + const publishKey = process.env.PUBLISH_KEY || 'demo'; + let pubnub: PubNub; + + after(() => { + nock.enableNetConnect(); + }); + + afterEach(() => { + nock.enableNetConnect(); + pubnub.removeAllListeners(); + pubnub.unsubscribeAll(); + pubnub.stop(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + subscribeKey, + publishKey, + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, + useRandomIVs: false, + }); + }); + + it('supports payload', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1,ch2`) + .query({ + max: '10', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{ "channels": { "ch1": [{"message":{"text":"hey1"},"timetoken":"11"}, {"message":{"text":"hey2"},"timetoken":"12"}], "ch2": [{"message":{"text":"hey3"},"timetoken":"21"}, {"message":{"text":"hey2"},"timetoken":"22"}] } }', + { 'content-type': 'text/javascript' }, + ); + + pubnub.fetchMessages({ channels: ['ch1', 'ch2'], count: 10 }, (status, response) => { + try { + assert.equal(status.error, false); + assert.deepEqual(response, { + channels: { + ch1: [ + { + channel: 'ch1', + message: { + text: 'hey1', + }, + timetoken: '11', + messageType: undefined, + uuid: undefined, + }, + { + channel: 'ch1', + message: { + text: 'hey2', + }, + timetoken: '12', + messageType: undefined, + uuid: undefined, + }, + ], + ch2: [ + { + channel: 'ch2', + message: { + text: 'hey3', + }, + timetoken: '21', + messageType: undefined, + uuid: undefined, + }, + { + channel: 'ch2', + message: { + text: 'hey2', + }, + timetoken: '22', + messageType: undefined, + uuid: undefined, + }, + ], + }, + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports encrypted payload', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1,ch2`) + .query({ + max: '10', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{ "channels": { "ch1": [{"message":"zFJeF9BVABL80GUiQEBjLg==","timetoken":"11"}, {"message":"zFJeF9BVABL80GUiQEBjLg==","timetoken":"12"}], "ch2": [{"message":"HIq4MTi9nk/KEYlHOKpMCaH78ZXppGynDHrgY9nAd3s=","timetoken":"21"}, {"message":"HIq4MTi9nk/KEYlHOKpMCaH78ZXppGynDHrgY9nAd3s=","timetoken":"22"}] } }', + { 'content-type': 'text/javascript' }, + ); + + pubnub.setCipherKey('cipherKey'); + pubnub.fetchMessages({ channels: ['ch1', 'ch2'], count: 10 }, (status, response) => { + try { + assert.equal(status.error, false); + assert.deepEqual(response, { + channels: { + ch1: [ + { + channel: 'ch1', + message: { + text: 'hey', + }, + timetoken: '11', + messageType: undefined, + uuid: undefined, + }, + { + channel: 'ch1', + message: { + text: 'hey', + }, + timetoken: '12', + messageType: undefined, + uuid: undefined, + }, + ], + ch2: [ + { + channel: 'ch2', + message: { + text2: 'hey2', + }, + timetoken: '21', + messageType: undefined, + uuid: undefined, + }, + { + channel: 'ch2', + message: { + text2: 'hey2', + }, + timetoken: '22', + messageType: undefined, + uuid: undefined, + }, + ], + }, + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports metadata', (done) => { + const channel = PubNub.generateUUID(); + const expectedMessagesCount = 10; + + publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { + pubnub.fetchMessages({ channels: [channel], count: 25, includeMeta: true }, (_, response) => { + try { + assert(response !== null); + const channelMessages = response.channels[channel]; + + assert.deepEqual(channelMessages[0].meta, { time: messages[0].message.time }); + assert(!channelMessages[1].meta); + done(); + } catch (error) { + done(error); + } + }); + }); + }).timeout(60000); + + it('throws when requested actions for multiple channels', async () => { + let errorCatched = false; + + try { + await pubnub.fetchMessages({ channels: ['channelA', 'channelB'], includeMessageActions: true }); + } catch (error) { + assert(error instanceof PubNubError); + assert.equal( + error.status!.message, + 'History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.', + ); + errorCatched = true; + } + + assert(errorCatched); + }); + + it("supports actions (stored as 'data' field)", (done) => { + const channel = PubNub.generateUUID(); + const expectedMessagesCount = 2; + const expectedActionsCount = 4; + + publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { + const messageTimetokens = messages.map((message) => message.timetoken); + + addActionsInChannel(pubnub, expectedActionsCount, messageTimetokens, channel, (actions) => { + setTimeout(() => { + pubnub.fetchMessages({ channels: [channel], includeMessageActions: true }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + const fetchedMessages = response.channels[channel]; + // TypeScript types system now requires to figure out type of object before using it. + assert('actions' in fetchedMessages[0]); + const actionsByType = fetchedMessages[0].data ?? {}; + let historyActionsCount = 0; + + Object.keys(actionsByType).forEach((actionType) => { + Object.keys(actionsByType[actionType]).forEach((actionValue) => { + let actionFound = false; + historyActionsCount += 1; + + actions.forEach((action) => { + if (action.value === actionValue) actionFound = true; + }); + + assert.equal(actionFound, true); + }); + }); + + assert.equal(historyActionsCount, expectedActionsCount); + assert.equal(fetchedMessages[0].timetoken, messageTimetokens[0]); + assert.equal( + fetchedMessages[fetchedMessages.length - 1].timetoken, + messageTimetokens[messageTimetokens.length - 1], + ); + + done(); + } catch (error) { + done(error); + } + }); + }, 2000); + }); + }); + }).timeout(60000); + + it("supports actions (stored as 'actions' field)", (done) => { + const channel = PubNub.generateUUID(); + const expectedMessagesCount = 2; + const expectedActionsCount = 4; + + publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { + const messageTimetokens = messages.map((message) => message.timetoken); + + addActionsInChannel(pubnub, expectedActionsCount, messageTimetokens, channel, (actions) => { + setTimeout(() => { + pubnub.fetchMessages({ channels: [channel], includeMessageActions: true }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + const fetchedMessages = response.channels[channel]; + // TypeScript types system now requires to figure out type of object before using it. + assert('actions' in fetchedMessages[0]); + const actionsByType = fetchedMessages[0].actions ?? {}; + let historyActionsCount = 0; + + Object.keys(actionsByType).forEach((actionType) => { + Object.keys(actionsByType[actionType]).forEach((actionValue) => { + let actionFound = false; + historyActionsCount += 1; + + actions.forEach((action) => { + if (action.value === actionValue) { + actionFound = true; + } + }); + + assert.equal(actionFound, true); + }); + }); + + assert.equal(historyActionsCount, expectedActionsCount); + assert.equal(fetchedMessages[0].timetoken, messageTimetokens[0]); + assert.equal( + fetchedMessages[fetchedMessages.length - 1].timetoken, + messageTimetokens[messageTimetokens.length - 1], + ); + + done(); + } catch (error) { + done(error); + } + }); + }, 2000); + }); + }); + }).timeout(60000); + + it('should return "more" field when server sends it', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history-with-actions/sub-key/${subscribeKey}/channel/ch1`) + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + max: '25', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{"status":200,"error":false,"error_message":"","channels":{"demo-channel":[{"message":"Hi","timetoken":15610547826970040,"actions":{"receipt":{"read":[{"uuid":"user-7","actionTimetoken":15610547826970044}]}}},{"message":"Hello","timetoken":15610547826970000,"actions":{"reaction":{"smiley_face":[{"uuid":"user-456","actionTimetoken":15610547826970050}]}}}]},"more":{"url":"/v3/history-with-actions/sub-key/s/channel/c?start=15610547826970000&max=98","start":"15610547826970000","max":98}}', + { 'content-type': 'text/javascript' }, + ); + + pubnub.fetchMessages({ channels: ['ch1'], includeMessageActions: true }, (status, response) => { + try { + assert.equal(scope.isDone(), true); + assert.equal(status.error, false); + assert(response !== null); + // TypeScript types system now requires to figure out type of object before using it. + assert('more' in response); + assert.equal(response.more.url, '/v3/history-with-actions/sub-key/s/channel/c?start=15610547826970000&max=98'); + assert.equal(response.more.start, '15610547826970000'); + assert.equal(response.more.max, 98); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('should request 100 messages when count not provided with single channel', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1`) + .query({ + max: '100', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }', + { 'content-type': 'text/javascript' }, + ); + pubnub.fetchMessages({ channels: ['ch1'] }, (status) => { + try { + assert.equal(scope.isDone(), true); + assert.equal(status.error, false); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('should request 25 messages when count not provided with multiple channels', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1,ch2`) + .query({ + max: '25', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }', + { 'content-type': 'text/javascript' }, + ); + pubnub.fetchMessages({ channels: ['ch1', 'ch2'] }, (status) => { + try { + assert.equal(scope.isDone(), true); + assert.equal(status.error, false); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('should request 25 messages when count not provided for history-with-actions', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history-with-actions/sub-key/${subscribeKey}/channel/ch1`) + .query({ + max: '25', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }', + { 'content-type': 'text/javascript' }, + ); + pubnub.fetchMessages({ channels: ['ch1'], includeMessageActions: true }, (status) => { + try { + assert.equal(scope.isDone(), true); + assert.equal(status.error, false); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('should request provided number of messages when count is specified for history-with-actions', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history-with-actions/sub-key/${subscribeKey}/channel/ch1`) + .query({ + max: '10', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }', + { 'content-type': 'text/javascript' }, + ); + pubnub.fetchMessages({ channels: ['ch1'], includeMessageActions: true, count: 10 }, (status) => { + try { + assert.equal(scope.isDone(), true); + assert.equal(status.error, false); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('should request provided number of messages when count is specified for batch history with single channel', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1`) + .query({ + max: '10', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }', + { 'content-type': 'text/javascript' }, + ); + pubnub.fetchMessages({ channels: ['ch1'], count: 10 }, (status) => { + try { + assert.equal(scope.isDone(), true); + assert.equal(status.error, false); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('should request provided number of messages when count is specified for batch history with multiple channels', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1,ch2`) + .query({ + max: '10', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{ "error": false, "error_message": "", "channels": { "ch1": [ { "message_type": null, "message": "hello world", "timetoken": "16048329933709932", "uuid": "test-uuid"} ] } }', + { 'content-type': 'text/javascript' }, + ); + pubnub.fetchMessages({ channels: ['ch1', 'ch2'], count: 10 }, (status) => { + try { + assert.equal(scope.isDone(), true); + assert.equal(status.error, false); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('handles unencrypted payload when cryptomodule configured', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .get(`/v3/history/sub-key/${subscribeKey}/channel/ch1`) + .query({ + max: '10', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + include_uuid: 'true', + include_message_type: 'true', + }) + .reply( + 200, + '{ "channels": { "ch1": [{"message":"hello","timetoken":"11"}, {"message":"hey","timetoken":"12"}] } }', + { 'content-type': 'text/javascript' }, + ); + + pubnub.setCipherKey('cipherKey'); + pubnub.fetchMessages({ channels: ['ch1'], count: 10 }, (status, response) => { + try { + assert.equal(status.error, false); + assert.deepEqual(response, { + channels: { + ch1: [ + { + channel: 'ch1', + message: 'hello', + timetoken: '11', + messageType: undefined, + uuid: undefined, + error: 'Error while decrypting message content: Decryption error: invalid header version', + }, + { + channel: 'ch1', + message: 'hey', + timetoken: '12', + messageType: undefined, + uuid: undefined, + error: 'Error while decrypting message content: Decryption error: invalid header version', + }, + ], + }, + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); +}); diff --git a/test/integration/endpoints/get_file_url.test.js b/test/integration/endpoints/get_file_url.test.ts similarity index 66% rename from test/integration/endpoints/get_file_url.test.js rename to test/integration/endpoints/get_file_url.test.ts index e6a6607a3..a0d8c0a0b 100644 --- a/test/integration/endpoints/get_file_url.test.js +++ b/test/integration/endpoints/get_file_url.test.ts @@ -2,6 +2,7 @@ /* eslint no-console: 0 */ import assert from 'assert'; + import PubNub from '../../../src/node/index'; describe('getFileUrl', () => { @@ -10,12 +11,15 @@ describe('getFileUrl', () => { subscribeKey: 'demo', publishKey: 'demo', uuid: 'myUUID', - origin: 'example.com' + // @ts-expect-error Force override default value. + useRequestId: false, + origin: 'example.com', }); const url = pubnub.getFileUrl({ channel: 'channel', id: 'id', name: 'name' }); + // @ts-expect-error Access to the `sdkFamily` required for test purpose. const pnsdk = `PubNub-JS-${pubnub._config.sdkFamily}%2F${pubnub._config.getVersion()}`; - + assert.equal(url, `https://example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}`); }); @@ -24,14 +28,19 @@ describe('getFileUrl', () => { subscribeKey: 'demo', publishKey: 'demo', uuid: 'myUUID', - origin: ['test1.example.com', 'test2.example.com'] + // @ts-expect-error Force override default value. + useRequestId: false, + origin: ['test1.example.com', 'test2.example.com'], }); const url = pubnub.getFileUrl({ channel: 'channel', id: 'id', name: 'name' }); + // @ts-expect-error Access to the `sdkFamily` required for test purpose. const pnsdk = `PubNub-JS-${pubnub._config.sdkFamily}%2F${pubnub._config.getVersion()}`; - - assert(url === `https://test1.example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}` - || url === `https://test2.example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}`); + + assert( + url === `https://test1.example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}` || + url === `https://test2.example.com/v1/files/demo/channels/channel/files/id/name?uuid=myUUID&pnsdk=${pnsdk}`, + ); }); it('constructs proper url when token is set', () => { @@ -39,12 +48,15 @@ describe('getFileUrl', () => { subscribeKey: 'demo', publishKey: 'demo', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, origin: 'example.com', }); pubnub.setToken('tokenString'); const url = pubnub.getFileUrl({ channel: 'channel', id: 'id', name: 'name' }); + // @ts-expect-error Access to the `sdkFamily` required for test purpose. const pnsdk = `PubNub-JS-${pubnub._config.sdkFamily}%2F${pubnub._config.getVersion()}`; assert.equal( diff --git a/test/integration/endpoints/grant_token.test.js b/test/integration/endpoints/grant_token.test.ts similarity index 62% rename from test/integration/endpoints/grant_token.test.js rename to test/integration/endpoints/grant_token.test.ts index 61e163ad0..0ae467d84 100644 --- a/test/integration/endpoints/grant_token.test.js +++ b/test/integration/endpoints/grant_token.test.ts @@ -3,11 +3,12 @@ import nock from 'nock'; import sinon from 'sinon'; import utils from '../../utils'; import PubNub from '../../../src/node/index'; +import { PubNubError } from '../../../src/errors/pubnub-error'; describe('grant token endpoint', () => { - let originalVersionFunction = null; - let pubnub; - let clock; + let originalVersionFunction: (() => string) | null = null; + let clock: sinon.SinonFakeTimers; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); @@ -17,7 +18,7 @@ describe('grant token endpoint', () => { after(() => { clock.restore(); nock.enableNetConnect(); - pubnub._config.getVersion = originalVersionFunction; + pubnub._config.getVersion = originalVersionFunction!; }); beforeEach(() => { @@ -27,15 +28,15 @@ describe('grant token endpoint', () => { publishKey: 'myPublishKey', secretKey: 'mySecretKey', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, autoNetworkDetection: false, }); - pubnub._config.getVersion = () => 'testVersion'; - if (originalVersionFunction === null) { originalVersionFunction = pubnub._config.getVersion; pubnub._config.getVersion = () => 'testVersion'; - } + } else pubnub._config.getVersion = () => 'testVersion'; }); describe('#grantToken', () => { @@ -62,9 +63,13 @@ describe('grant token endpoint', () => { ttl: 1440, }) .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing either Resources or Patterns.'); - done(); + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing values for either Resources or Patterns"); + done(); + } catch (error) { + done(error); + } }); }); @@ -95,9 +100,13 @@ describe('grant token endpoint', () => { }, }) .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing values for either Resources or Patterns.'); - done(); + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing values for either Resources or Patterns"); + done(); + } catch (error) { + done(error); + } }); }); @@ -128,9 +137,13 @@ describe('grant token endpoint', () => { }, }) .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing values for either Resources or Patterns.'); - done(); + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing values for either Resources or Patterns"); + done(); + } catch (error) { + done(error); + } }); }); @@ -139,6 +152,7 @@ describe('grant token endpoint', () => { await pubnub.grantToken({ ttl: 1440, resources: { + // @ts-expect-error It is not allowed to mix in VSP and new permissions type. users: { user1: { read: true } }, }, patterns: { @@ -146,8 +160,9 @@ describe('grant token endpoint', () => { }, }); } catch (e) { + assert(e instanceof PubNubError); assert.strictEqual( - e.status.message, + e.status!.message, // eslint-disable-next-line max-len 'Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`', ); @@ -179,13 +194,16 @@ describe('grant token endpoint', () => { await pubnub.grantToken({ ttl: 1440, resources: { + // @ts-expect-error Intentianally using VSP types. users: { user1: { read: true } }, }, patterns: { + // @ts-expect-error Intentianally using VSP types. users: { '.*': { read: true } }, }, }); } catch (e) { + assert(e instanceof PubNubError); console.log(e.status); } @@ -194,81 +212,3 @@ describe('grant token endpoint', () => { }); }); }); - -describe('grant token endpoint telemetry', () => { - let originalVersionFunction = null; - let pubnub; - - before(() => { - nock.disableNetConnect(); - }); - - after(() => { - nock.enableNetConnect(); - pubnub._config.getVersion = originalVersionFunction; - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - subscribeKey: 'mySubscribeKey', - publishKey: 'myPublishKey', - secretKey: 'mySecretKey', - uuid: 'myUUID', - autoNetworkDetection: false, - }); - - if (originalVersionFunction === null) { - originalVersionFunction = pubnub._config.getVersion; - pubnub._config.getVersion = () => 'testVersion'; - } - }); - - describe('#grantToken', () => { - it('should add PAM grant token API telemetry information', (done) => { - let scope = utils - .createNock() - .post( - '/v3/pam/mySubscribeKey/grant', - '{"ttl":1440,"permissions":{"resources":{"channels":{},"groups":{},"uuids":{"user1":1},"users":{},"spaces":{}},"patterns":{"channels":{},"groups":{},"uuids":{".*":1},"users":{},"spaces":{}},"meta":{}}}', - ) - .query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils - .runAPIWithResponseDelays( - scope, - 200, - { message: 'Success', data: { token: 'token' } }, - delays, - (completion) => { - pubnub.grantToken( - { - ttl: 1440, - resources: { - channels: {}, - groups: {}, - uuids: { user1: { read: true } }, - }, - patterns: { - channels: {}, - groups: {}, - uuids: { '.*': { read: true } }, - }, - }, - () => { - completion(); - }, - ); - }, - ) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_pamv3', average, leeway); - done(); - }); - }).timeout(60000); - }); -}); diff --git a/test/integration/endpoints/history.test.js b/test/integration/endpoints/history.test.ts similarity index 51% rename from test/integration/endpoints/history.test.js rename to test/integration/endpoints/history.test.ts index 34897b3c4..d2d55a111 100644 --- a/test/integration/endpoints/history.test.js +++ b/test/integration/endpoints/history.test.ts @@ -3,26 +3,47 @@ import assert from 'assert'; import nock from 'nock'; -import utils from '../../utils'; + +import { Payload } from '../../../src/core/types/api'; import PubNub from '../../../src/node/index'; +import utils from '../../utils'; -function publishMessagesToChannel(client, count, channel, completion) { +/** + * Published test message shape. + */ +type TestMessage = { messageIdx: string; time: number }; + +/** + * Prepare messages history. + * + * @param client - PubNub client instance which will be used to publish messages. + * @param count - How many messages should be published. + * @param channel - Name of the channel into which messages should be published. + * @param completion - Messages set publish completion function. + */ +function publishMessagesToChannel( + client: PubNub, + count: number, + channel: string, + completion: (published: { message: TestMessage; timetoken: string }[]) => void, +) { + let messages: { message: TestMessage; timetoken: string }[] = []; let publishCompleted = 0; - let messages = []; - const publish = (messageIdx) => { - let payload = { message: { messageIdx: [channel, messageIdx].join(': '), time: Date.now() }, channel }; + const publish = (messageIdx: number) => { + let payload: { channel: string; message: TestMessage; meta?: Payload } = { + message: { messageIdx: [channel, messageIdx].join(': '), time: Date.now() }, + channel, + }; - if (messageIdx % 2 === 0) { - payload.meta = { time: payload.message.time }; - } + if (messageIdx % 2 === 0) payload.meta = { time: payload.message.time }; client.publish(payload, (status, response) => { publishCompleted += 1; - if (!status.error) { + if (!status.error && response) { messages.push({ message: payload.message, timetoken: response.timetoken }); - messages = messages.sort((left, right) => left.timetoken - right.timetoken); + messages = messages.sort((left, right) => parseInt(left.timetoken, 10) - parseInt(right.timetoken, 10)); } else { console.error('Publish did fail:', status); } @@ -41,7 +62,7 @@ function publishMessagesToChannel(client, count, channel, completion) { describe('history endpoints', () => { const subscribeKey = process.env.SUBSCRIBE_KEY || 'demo'; const publishKey = process.env.PUBLISH_KEY || 'demo'; - let pubnub; + let pubnub: PubNub; after(() => { nock.enableNetConnect(); @@ -60,6 +81,8 @@ describe('history endpoints', () => { subscribeKey, publishKey, uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, useRandomIVs: false, }); }); @@ -79,18 +102,24 @@ describe('history endpoints', () => { .reply( 200, '[[{"message":{"text":"hey"},"timetoken":"14648503433058358"},{"message":{"text2":"hey2"},"timetoken":"14648503433058359"}],"14648503433058358","14649346364851578"]', + { 'content-type': 'text/javascript' }, ); pubnub.history({ channel: 'ch1', stringifiedTimeToken: true }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.startTimeToken, '14648503433058358'); - assert.deepEqual(response.endTimeToken, '14649346364851578'); - assert.deepEqual(response.messages, [ - { timetoken: '14648503433058358', entry: { text: 'hey' } }, - { timetoken: '14648503433058359', entry: { text2: 'hey2' } }, - ]); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.startTimeToken, "14648503433058358"); + assert.deepEqual(response.endTimeToken, "14649346364851578"); + assert.deepEqual(response.messages, [ + { timetoken: "14648503433058358", entry: { text: "hey" } }, + { timetoken: "14648503433058359", entry: { text2: "hey2" } } + ]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -109,19 +138,25 @@ describe('history endpoints', () => { .reply( 200, '[[{"message":"zFJeF9BVABL80GUiQEBjLg==","timetoken":"14649369736959785"},{"message":"HIq4MTi9nk/KEYlHOKpMCaH78ZXppGynDHrgY9nAd3s=","timetoken":"14649369766426772"}],"14649369736959785","14649369766426772"]', + { 'content-type': 'text/javascript' }, ); pubnub.setCipherKey('cipherKey'); pubnub.history({ channel: 'ch1', stringifiedTimeToken: true }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.startTimeToken, '14649369736959785'); - assert.deepEqual(response.endTimeToken, '14649369766426772'); - assert.deepEqual(response.messages, [ - { timetoken: '14649369736959785', entry: { text: 'hey' } }, - { timetoken: '14649369766426772', entry: { text2: 'hey2' } }, - ]); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.startTimeToken, "14649369736959785"); + assert.deepEqual(response.endTimeToken, "14649369766426772"); + assert.deepEqual(response.messages, [ + { timetoken: "14649369736959785", entry: { text: "hey" } }, + { timetoken: "14649369766426772", entry: { text2: "hey2" } } + ]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -130,40 +165,19 @@ describe('history endpoints', () => { const expectedMessagesCount = 10; publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { - pubnub.history({ channel, includeMeta: true }, (status, response) => { - assert.deepEqual(response.messages[0].meta, { time: messages[0].message.time }); - assert(!response.messages[1].meta); - done(); + pubnub.history({ channel, includeMeta: true }, (_, response) => { + try { + assert(response !== null); + assert.deepEqual(response.messages[0].meta, { time: messages[0].message.time }); + assert(!response.messages[1].meta); + done(); + } catch (error) { + done(error); + } }); }); }).timeout(60000); - it('should add history API telemetry information', (done) => { - nock.disableNetConnect(); - let scope = utils.createNock().get(`/v2/history/sub-key/${subscribeKey}/channel/ch1`).query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils - .runAPIWithResponseDelays( - scope, - 200, - '[[{"message":{"text":"hey"},"timetoken":"14648503433058358"},{"message":{"text2":"hey2"},"timetoken":"14648503433058359"}],"14648503433058358","14649346364851578"]', - delays, - (completion) => { - pubnub.history({ channel: 'ch1', stringifiedTimeToken: true }, () => { - completion(); - }); - }, - ) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_hist', average, leeway); - done(); - }); - }).timeout(60000); - it('handles unencrypted payload with cryptoModule', (done) => { nock.disableNetConnect(); const scope = utils @@ -179,22 +193,28 @@ describe('history endpoints', () => { .reply( 200, '[[{"message":"zFJeF9BVABL80GUiQEBjLg==","timetoken":"14648503433058358"},{"message":"hello","timetoken":"14648503433058359"}],"14648503433058358","14649346364851578"]', + { 'content-type': 'text/javascript' }, ); pubnub.setCipherKey('cipherKey'); pubnub.history({ channel: 'ch1', stringifiedTimeToken: true }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.startTimeToken, '14648503433058358'); - assert.deepEqual(response.endTimeToken, '14649346364851578'); - assert.deepEqual(response.messages, [ - { timetoken: '14648503433058358', entry: { text: 'hey' } }, - { - timetoken: '14648503433058359', - entry: 'hello', - error: 'Error while decrypting message content: decryption error. invalid header version', - }, - ]); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.startTimeToken, "14648503433058358"); + assert.deepEqual(response.endTimeToken, "14649346364851578"); + assert.deepEqual(response.messages, [ + { timetoken: "14648503433058358", entry: { text: "hey" } }, + { + timetoken: "14648503433058359", + entry: "hello", + error: "Error while decrypting message content: Decryption error: invalid header version" + } + ]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); }); diff --git a/test/integration/endpoints/message_actions.test.js b/test/integration/endpoints/message_actions.test.js deleted file mode 100644 index 8b8725c66..000000000 --- a/test/integration/endpoints/message_actions.test.js +++ /dev/null @@ -1,612 +0,0 @@ -/* global describe, beforeEach, afterEach, it, after */ -/* eslint no-console: 0 */ - -import assert from 'assert'; -import nock from 'nock'; -import PubNub from '../../../src/node/index'; -import utils from '../../utils'; - - -function publishMessages(client , count , channel , completion ) { - let publishCompleted = 0; - let timetokens = []; - - const publish = (messageIdx) => { - const message = { messageIdx, time: Date.now() }; - - client.publish( - { message, channel }, - (status, response) => { - publishCompleted += 1; - - if (!status.error) { - timetokens.push(response.timetoken); - } else { - console.error('Publish did fail:', status); - } - - if (publishCompleted < count) { - publish(publishCompleted); - } else if (publishCompleted === count) { - completion(timetokens.sort((left, right) => left - right)); - } - } - ); - }; - - publish(publishCompleted); -} - -function addActions(client , count , messageTimetokens , channel , completion ) { - const types = ['reaction', 'receipt', 'custom']; - const values = [ - PubNub.generateUUID(), PubNub.generateUUID(), PubNub.generateUUID(), PubNub.generateUUID(), PubNub.generateUUID(), - PubNub.generateUUID(), PubNub.generateUUID(), PubNub.generateUUID(), PubNub.generateUUID(), PubNub.generateUUID() - ]; - let actionsToAdd = []; - let actionsAdded = 0; - let timetokens = []; - - for (let messageIdx = 0; messageIdx < messageTimetokens.length; messageIdx += 1) { - const messageTimetoken = messageTimetokens[messageIdx]; - - for (let messageActionIdx = 0; messageActionIdx < count; messageActionIdx += 1) { - /** @type MessageAction */ - const action = { type: types[(messageActionIdx + 1) % 3], value: values[(messageActionIdx + 1) % 10] }; - - actionsToAdd.push({ messageTimetoken, action }); - } - } - - const addAction = (actionIdx) => { - const { messageTimetoken, action } = actionsToAdd[actionIdx]; - - client.addMessageAction( - { channel, messageTimetoken, action }, - (status, response) => { - actionsAdded += 1; - - if (!status.error) { - timetokens.push(response.data.actionTimetoken); - } else { - console.error('Action add did fail:', action, '\n', status); - } - - if (actionsAdded < actionsToAdd.length) { - addAction(actionsAdded); - } else if (actionsAdded === actionsToAdd.length) { - completion(timetokens.sort((left, right) => left - right)); - } - } - ); - }; - - addAction(actionsAdded); -} - - -describe('message actions endpoints', () => { - const subscribeKey = process.env.SUBSCRIBE_KEY || 'demo'; - const publishKey = process.env.PUBLISH_KEY || 'demo'; - let pubnub; - - after(() => { - nock.enableNetConnect(); - }); - - afterEach(() => { - nock.enableNetConnect(); - pubnub.removeAllListeners(); - pubnub.unsubscribeAll(); - pubnub.stop(); - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - subscribeKey, - publishKey, - uuid: 'myUUID', - authKey: 'myAuthKey', - }); - }); - - describe('addMessageAction', () => { - describe('##validation', () => { - it('fails if \'action\' is missing', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) - .reply(200, {}); - - pubnub.addMessageAction({ - channel: 'test-channel', - messageTimetoken: '1234567890', - }) - .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing Action'); - done(); - }); - }); - - it('fails if \'type\' is missing', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) - .reply(200, {}); - const action = { value: 'test value' }; - - pubnub.addMessageAction({ - channel: 'test-channel', - messageTimetoken: '1234567890', - action, - }) - .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing Action.type'); - done(); - }); - }); - - it('fails if \'type\' is too long', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) - .reply(200, {}); - const action = { type: PubNub.generateUUID(), value: 'test value' }; - - pubnub.addMessageAction({ - channel: 'test-channel', - messageTimetoken: '1234567890', - action, - }) - .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Action.type value exceed maximum length of 15'); - done(); - }); - }); - - it('fails if \'value\' is missing', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) - .reply(200, {}); - const action = { type: 'custom' }; - - pubnub.addMessageAction({ - channel: 'test-channel', - messageTimetoken: '1234567890', - action, - }) - .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing Action.value'); - done(); - }); - }); - - it('fails if \'messageTimetoken\' is missing', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/`) - .reply(200, {}); - const action = { type: 'custom', value: 'test value' }; - - pubnub.addMessageAction({ - channel: 'test-channel', - action, - }) - .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing message timetoken'); - done(); - }); - }); - - it('fails if \'channel\' is missing', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) - .reply(200, {}); - const action = { type: 'custom', value: 'test value' }; - - pubnub.addMessageAction({ - messageTimetoken: '1234567890', - action, - }) - .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing message channel'); - done(); - }); - }); - }); - - it('add message action', (done) => { - /** @type MessageAction */ - const messageAction = { type: 'custom', value: PubNub.generateUUID() }; - const channel = PubNub.generateUUID(); - - publishMessages(pubnub, 1, channel, (timetokens) => { - pubnub.addMessageAction( - { channel, messageTimetoken: timetokens[0], action: messageAction }, - (status, response) => { - assert.equal(status.error, false); - assert.equal(response.data.type, messageAction.type); - assert.equal(response.data.value, messageAction.value); - assert.equal(response.data.uuid, pubnub.getUUID()); - assert.equal(response.data.messageTimetoken, timetokens[0]); - assert(response.data.actionTimetoken); - - done(); - } - ); - }); - }).timeout(60000); - - it('add message action with encoded channel', (done) => { - /** @type MessageAction */ - const messageAction = { type: 'custom', value: PubNub.generateUUID() }; - const channel = `${PubNub.generateUUID()}#1`; - - publishMessages(pubnub, 1, channel, (timetokens) => { - pubnub.addMessageAction( - { channel, messageTimetoken: timetokens[0], action: messageAction }, - (status, response) => { - assert.equal(status.error, false); - assert.equal(response.data.type, messageAction.type); - assert.equal(response.data.value, messageAction.value); - assert.equal(response.data.uuid, pubnub.getUUID()); - assert.equal(response.data.messageTimetoken, timetokens[0]); - assert(response.data.actionTimetoken); - - done(); - } - ); - }); - }).timeout(60000); - - it('add message action and 207 status code', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey' - }) - .reply(207, { - status: 207, - data: { - type: 'reaction', - value: 'smiley_face', - uuid: 'user-456', - actionTimetoken: '15610547826970050', - messageTimetoken: '15610547826969050' - }, - error: { - message: 'Stored but failed to publish message action.', - source: 'actions' - } - }); - - pubnub.addMessageAction( - { channel: 'test-channel', messageTimetoken: '1234567890', action: { type: 'custom', value: 'test' } }, - (status) => { - assert.equal(scope.isDone(), true); - assert.equal(status.statusCode, 207); - assert(status.errorData.message); - - done(); - } - ); - }); - - it('add message action should trigger event', (done) => { - /** @type MessageAction */ - const messageAction = { type: 'custom', value: PubNub.generateUUID() }; - const channel = PubNub.generateUUID(); - let messageTimetoken = null; - - pubnub.addListener({ - status: (status) => { - if (status.category === 'PNConnectedCategory') { - pubnub.publish( - { channel, message: { hello: 'test' }, sendByPost: true }, - (publishStatus, response) => { - messageTimetoken = response.timetoken; - - pubnub.addMessageAction( - { channel, messageTimetoken, action: messageAction } - ); - } - ); - } - }, - messageAction: (messageActionEvent) => { - assert(messageActionEvent.data); - assert.equal(messageActionEvent.data.type, messageAction.type); - assert.equal(messageActionEvent.data.value, messageAction.value); - assert.equal(messageActionEvent.data.uuid, pubnub.getUUID()); - assert.equal(messageActionEvent.data.messageTimetoken, messageTimetoken); - assert(messageActionEvent.data.actionTimetoken); - assert.equal(messageActionEvent.event, 'added'); - pubnub.unsubscribeAll() - - done(); - } - }); - - pubnub.subscribe({ channels: [channel] }); - }).timeout(60000); - }); - - describe('removeMessageAction', () => { - describe('##validation', () => { - it('fails if \'messageTimetoken\' is missing', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .delete(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890/action/12345678901`) - .reply(200, {}); - - pubnub.removeMessageAction({ - channel: 'test-channel', - actionTimetoken: '1234567890', - }) - .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing message timetoken'); - - done(); - }); - }); - - it('fails if \'actionTimetoken\' is missing', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .delete(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890/action/12345678901`) - .reply(200, {}); - - pubnub.removeMessageAction({ - channel: 'test-channel', - messageTimetoken: '1234567890', - }) - .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing action timetoken'); - - done(); - }); - }); - - it('fails if \'channel\' is missing', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .delete(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890/action/12345678901`) - .reply(200, {}); - - pubnub.removeMessageAction({ - messageTimetoken: '1234567890', - actionTimetoken: '12345678901', - }) - .catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing message channel'); - - done(); - }); - }); - }); - - it('remove message action', (done) => { - const channel = PubNub.generateUUID(); - - publishMessages(pubnub, 1, channel, (messageTimetokens) => { - addActions(pubnub, 1, messageTimetokens, channel, (actionTimetokens) => { - pubnub.getMessageActions({ channel }, (status, response) => { - assert.equal(status.error, false); - assert.equal(response.data.length, actionTimetokens.length); - - pubnub.removeMessageAction( - { channel, actionTimetoken: actionTimetokens[0], messageTimetoken: messageTimetokens[0] }, - (removeMessageStatus) => { - assert.equal(removeMessageStatus.error, false); - - setTimeout(() => { - pubnub.getMessageActions({ channel }, (getMessagesStatus, getMessagesResponse) => { - assert.equal(getMessagesStatus.error, false); - assert.equal(getMessagesResponse.data.length, 0); - - done(); - }); - }, 2000); - } - ); - }); - }); - }); - }).timeout(60000); - - it('remove message action with encoded channel', (done) => { - const channel = `${PubNub.generateUUID()}#1`; - - publishMessages(pubnub, 1, channel, (messageTimetokens) => { - addActions(pubnub, 1, messageTimetokens, channel, (actionTimetokens) => { - pubnub.getMessageActions({ channel }, (status, response) => { - assert.equal(status.error, false); - assert.equal(response.data.length, actionTimetokens.length); - - pubnub.removeMessageAction( - { channel, actionTimetoken: actionTimetokens[0], messageTimetoken: messageTimetokens[0] }, - (removeMessageStatus) => { - assert.equal(removeMessageStatus.error, false); - - setTimeout(() => { - pubnub.getMessageActions({ channel }, (getMessagesStatus, getMessagesResponse) => { - assert.equal(getMessagesStatus.error, false); - assert.equal(getMessagesResponse.data.length, 0); - - done(); - }); - }, 2000); - } - ); - }); - }); - }); - }).timeout(60000); - - it('remove message action should trigger event', (done) => { - const channel = PubNub.generateUUID(); - - publishMessages(pubnub, 1, channel, (messageTimetokens) => { - addActions(pubnub, 1, messageTimetokens, channel, (actionTimetokens) => { - pubnub.addListener({ - status: (status) => { - if (status.category === 'PNConnectedCategory') { - pubnub.removeMessageAction( - { channel, actionTimetoken: actionTimetokens[0], messageTimetoken: messageTimetokens[0] }, - (removeMessagesStatus) => { - assert.equal(removeMessagesStatus.error, false); - } - ); - } - }, - messageAction: (messageActionEvent) => { - assert(messageActionEvent.data); - assert.equal(messageActionEvent.data.uuid, pubnub.getUUID()); - assert.equal(messageActionEvent.data.messageTimetoken, messageTimetokens[0]); - assert.equal(messageActionEvent.data.actionTimetoken, actionTimetokens[0]); - assert.equal(messageActionEvent.event, 'removed'); - pubnub.unsubscribeAll() - - done(); - } - }); - - pubnub.subscribe({ channels: [channel] }); - }); - }); - }).timeout(60000); - }); - - describe('getMessageAction', () => { - describe('##validation', () => { - it('fails if \'channel\' is missing', (done) => { - nock.disableNetConnect(); - const scope = utils - .createNock() - .get(`/v1/message-actions/${subscribeKey}/channel/test-channel`) - .reply(200, {}); - - pubnub.getMessageActions({}).catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing message channel'); - - done(); - }); - }); - }); - - it('fetch message actions', (done) => { - const channel = PubNub.generateUUID(); - - publishMessages(pubnub, 2, channel, (messageTimetokens) => { - addActions(pubnub, 3, messageTimetokens, channel, (actionTimetokens) => { - const lastPublishedActionTimetoken = actionTimetokens[actionTimetokens.length - 1]; - const firstPublishedActionTimetoken = actionTimetokens[0]; - - pubnub.getMessageActions({ channel }, (status, response) => { - assert.equal(status.error, false); - const firstFetchedActionTimetoken = response.data[0].actionTimetoken; - const lastFetchedActionTimetoken = response.data[response.data.length - 1].actionTimetoken; - assert.equal(firstFetchedActionTimetoken, firstPublishedActionTimetoken); - assert.equal(lastFetchedActionTimetoken, lastPublishedActionTimetoken); - assert.equal(response.data.length, actionTimetokens.length); - assert.equal(response.start, firstPublishedActionTimetoken); - assert.equal(response.end, lastPublishedActionTimetoken); - - done(); - }); - }); - }); - }).timeout(60000); - - it('fetch message actions with encoded channel', (done) => { - const channel = `${PubNub.generateUUID()}#1`; - - publishMessages(pubnub, 2, channel, (messageTimetokens) => { - addActions(pubnub, 3, messageTimetokens, channel, (actionTimetokens) => { - const lastPublishedActionTimetoken = actionTimetokens[actionTimetokens.length - 1]; - const firstPublishedActionTimetoken = actionTimetokens[0]; - - pubnub.getMessageActions({ channel }, (status, response) => { - assert.equal(status.error, false); - const firstFetchedActionTimetoken = response.data[0].actionTimetoken; - const lastFetchedActionTimetoken = response.data[response.data.length - 1].actionTimetoken; - assert.equal(firstFetchedActionTimetoken, firstPublishedActionTimetoken); - assert.equal(lastFetchedActionTimetoken, lastPublishedActionTimetoken); - assert.equal(response.data.length, actionTimetokens.length); - assert.equal(response.start, firstPublishedActionTimetoken); - assert.equal(response.end, lastPublishedActionTimetoken); - - done(); - }); - }); - }); - }).timeout(60000); - - it('fetch next message actions page', (done) => { - const channel = PubNub.generateUUID(); - - publishMessages(pubnub, 2, channel, (messageTimetokens) => { - addActions(pubnub, 5, messageTimetokens, channel, (actionTimetokens) => { - const lastPublishedActionTimetoken = actionTimetokens[actionTimetokens.length - 1]; - const halfSize = Math.floor(actionTimetokens.length * 0.5); - const firstPublishedActionTimetoken = actionTimetokens[0]; - const middleMinusOnePublishedActionTimetoken = actionTimetokens[halfSize - 1]; - const middlePublishedActionTimetoken = actionTimetokens[halfSize]; - - pubnub.getMessageActions({ channel, limit: halfSize }, (status, response) => { - assert.equal(status.error, false); - let firstFetchedActionTimetoken = response.data[0].actionTimetoken; - let lastFetchedActionTimetoken = response.data[response.data.length - 1].actionTimetoken; - assert.equal(firstFetchedActionTimetoken, middlePublishedActionTimetoken); - assert.equal(lastFetchedActionTimetoken, lastPublishedActionTimetoken); - assert.equal(response.data.length, halfSize); - assert.equal(response.start, middlePublishedActionTimetoken); - assert.equal(response.end, lastPublishedActionTimetoken); - - pubnub.getMessageActions( - { channel, start: middlePublishedActionTimetoken, limit: halfSize }, - (getMessageActionsStatus, getMessageActionsResponse) => { - assert.equal(getMessageActionsStatus.error, false); - firstFetchedActionTimetoken = getMessageActionsResponse.data[0].actionTimetoken; - lastFetchedActionTimetoken = getMessageActionsResponse.data[getMessageActionsResponse.data.length - 1].actionTimetoken; - assert.equal(firstFetchedActionTimetoken, firstPublishedActionTimetoken); - assert.equal(lastFetchedActionTimetoken, middleMinusOnePublishedActionTimetoken); - assert.equal(getMessageActionsResponse.data.length, halfSize); - assert.equal(getMessageActionsResponse.start, firstPublishedActionTimetoken); - assert.equal(getMessageActionsResponse.end, middleMinusOnePublishedActionTimetoken); - - done(); - } - ); - }); - }); - }); - }).timeout(60000); - }); -}); diff --git a/test/integration/endpoints/message_actions.test.ts b/test/integration/endpoints/message_actions.test.ts new file mode 100644 index 000000000..ab3bcf4a9 --- /dev/null +++ b/test/integration/endpoints/message_actions.test.ts @@ -0,0 +1,752 @@ +/* global describe, beforeEach, afterEach, it, after */ +/* eslint no-console: 0 */ + +import assert from 'assert'; +import nock from 'nock'; + +import * as MessageActions from '../../../src/core/types/api/message-action'; +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; + +/** + * Message action object. + */ +type MessageAction = MessageActions.AddMessageActionParameters['action']; + +/** + * Prepare messages history. + * + * @param client - PubNub client instance which will be used to publish messages. + * @param count - How many messages should be published. + * @param channel - Name of the channel into which messages should be published. + * @param completion - Messages set publish completion function. + */ +function publishMessages(client: PubNub, count: number, channel: string, completion: (timetokens: string[]) => void) { + let publishCompleted = 0; + let timetokens: string[] = []; + + const publish = (messageIdx: number) => { + const message = { messageIdx, time: Date.now() }; + + client.publish({ message, channel }, (status, response) => { + publishCompleted += 1; + + if (!status.error && response) { + timetokens.push(response.timetoken); + } else { + console.error('Publish did fail:', status); + } + + if (publishCompleted < count) { + publish(publishCompleted); + } else if (publishCompleted === count) { + completion(timetokens.sort((left, right) => parseInt(left, 10) - parseInt(right, 10))); + } + }); + }; + + publish(publishCompleted); +} + +/** + * Attach message actions to the previously published messages. + * + * @param client - PubNub client instance which should be used to add message action to the message. + * @param count - How many message actions should be added to each referenced message. + * @param messageTimetokens - List of referenced messages' timetokens. + * @param channel - Name of the channel where referenced messages has been published. + * @param completion - Message actions addition completion function. + */ +function addActions( + client: PubNub, + count: number, + messageTimetokens: string[], + channel: string, + completion: (timetokens: string[]) => void, +) { + const types = ['reaction', 'receipt', 'custom']; + const values = [ + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + PubNub.generateUUID(), + ]; + let actionsToAdd: { messageTimetoken: string; action: MessageAction }[] = []; + let timetokens: string[] = []; + let actionsAdded = 0; + + for (let messageIdx = 0; messageIdx < messageTimetokens.length; messageIdx += 1) { + const messageTimetoken = messageTimetokens[messageIdx]; + + for (let messageActionIdx = 0; messageActionIdx < count; messageActionIdx += 1) { + const action: MessageAction = { + type: types[(messageActionIdx + 1) % 3], + value: values[(messageActionIdx + 1) % 10], + }; + + actionsToAdd.push({ messageTimetoken, action }); + } + } + + /** + * Attach set of message actions. + * + * @param actionIdx - Index of currently adding message action. + */ + const addAction = (actionIdx: number) => { + const { messageTimetoken, action } = actionsToAdd[actionIdx]; + + client.addMessageAction({ channel, messageTimetoken, action }, (status, response) => { + actionsAdded += 1; + + if (!status.error && response) { + timetokens.push(response.data.actionTimetoken); + } else { + console.error('Action add did fail:', action, '\n', status); + } + + if (actionsAdded < actionsToAdd.length) { + addAction(actionsAdded); + } else if (actionsAdded === actionsToAdd.length) { + completion(timetokens.sort((left, right) => parseInt(left, 10) - parseInt(right, 10))); + } + }); + }; + + addAction(actionsAdded); +} + +describe('message actions endpoints', () => { + const subscribeKey = process.env.SUBSCRIBE_KEY || 'demo'; + const publishKey = process.env.PUBLISH_KEY || 'demo'; + let pubnub: PubNub; + + after(() => { + nock.enableNetConnect(); + }); + + afterEach(() => { + nock.enableNetConnect(); + pubnub.removeAllListeners(); + pubnub.unsubscribeAll(); + pubnub.stop(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + subscribeKey, + publishKey, + uuid: 'myUUID', + authKey: 'myAuthKey', + // @ts-expect-error Force override default value. + useRequestId: false, + }); + }); + + describe('addMessageAction', () => { + describe('##validation', () => { + it("fails if 'action' is missing", (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) + .reply(200, {}); + + pubnub + // @ts-expect-error Intentionally don't include `action`. + .addMessageAction({ + channel: 'test-channel', + messageTimetoken: '1234567890', + }) + .catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing Action"); + done(); + } catch (error) { + done(error); + } + }); + }); + + it("fails if 'type' is missing", (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) + .reply(200, {}); + const action = { value: 'test value' }; + + pubnub + .addMessageAction({ + channel: 'test-channel', + messageTimetoken: '1234567890', + // @ts-expect-error Intentionally don't include `type` field into `action`. + action, + }) + .catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing Action.type"); + done(); + } catch (error) { + done(error); + } + }); + }); + + it("fails if 'type' is too long", (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) + .reply(200, {}); + const action: MessageAction = { type: PubNub.generateUUID(), value: 'test value' }; + + pubnub + .addMessageAction({ + channel: 'test-channel', + messageTimetoken: '1234567890', + action, + }) + .catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Action.type value exceed maximum length of 15"); + done(); + } catch (error) { + done(error); + } + }); + }); + + it("fails if 'value' is missing", (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) + .reply(200, {}); + const action = { type: 'custom' }; + + pubnub + .addMessageAction({ + channel: 'test-channel', + messageTimetoken: '1234567890', + // @ts-expect-error Intentionally don't include `value` field into `action`. + action, + }) + .catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing Action.value"); + done(); + } catch (error) { + done(error); + } + }); + }); + + it("fails if 'messageTimetoken' is missing", (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/`) + .reply(200, {}); + const action: MessageAction = { type: 'custom', value: 'test value' }; + + pubnub + // @ts-expect-error Intentionally don't include `messageTimetoken`. + .addMessageAction({ + channel: 'test-channel', + action, + }) + .catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing message timetoken"); + done(); + } catch (error) { + done(error); + } + }); + }); + + it("fails if 'channel' is missing", (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) + .reply(200, {}); + const action: MessageAction = { type: 'custom', value: 'test value' }; + + pubnub + // @ts-expect-error Intentionally don't include `channel`. + .addMessageAction({ + messageTimetoken: '1234567890', + action, + }) + .catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing message channel"); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + it('add message action', (done) => { + const messageAction: MessageAction = { type: 'custom', value: PubNub.generateUUID() }; + const channel = PubNub.generateUUID(); + + publishMessages(pubnub, 1, channel, (timetokens) => { + pubnub.addMessageAction( + { channel, messageTimetoken: timetokens[0], action: messageAction }, + (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.equal(response.data.type, messageAction.type); + assert.equal(response.data.value, messageAction.value); + assert.equal(response.data.uuid, pubnub.getUUID()); + assert.equal(response.data.messageTimetoken, timetokens[0]); + assert(response.data.actionTimetoken); + + done(); + } catch (error) { + done(error); + } + }, + ); + }); + }).timeout(60000); + + it('add message action with encoded channel', (done) => { + const messageAction: MessageAction = { type: 'custom', value: PubNub.generateUUID() }; + const channel = `${PubNub.generateUUID()}#1`; + + publishMessages(pubnub, 1, channel, (timetokens) => { + pubnub.addMessageAction( + { channel, messageTimetoken: timetokens[0], action: messageAction }, + (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.equal(response.data.type, messageAction.type); + assert.equal(response.data.value, messageAction.value); + assert.equal(response.data.uuid, pubnub.getUUID()); + assert.equal(response.data.messageTimetoken, timetokens[0]); + assert(response.data.actionTimetoken); + + done(); + } catch (error) { + done(error); + } + }, + ); + }); + }).timeout(60000); + + it('add message action and 207 status code', (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .post(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890`) + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + }) + .reply(207, { + status: 207, + data: { + type: 'reaction', + value: 'smiley_face', + uuid: 'user-456', + actionTimetoken: '15610547826970050', + messageTimetoken: '15610547826969050', + }, + error: { + message: 'Stored but failed to publish message action.', + source: 'actions', + }, + }); + + pubnub.addMessageAction( + { channel: 'test-channel', messageTimetoken: '1234567890', action: { type: 'custom', value: 'test' } }, + (status) => { + try { + assert.equal(scope.isDone(), true); + assert.equal(status.statusCode, 207); + + // @ts-expect-error `errorData` may contain a dictionary (Payload) with an arbitrary set of fields. + assert(status.errorData!.message); + + done(); + } catch (error) { + done(error); + } + }, + ); + }); + + it('add message action should trigger event', (done) => { + const messageAction: MessageAction = { type: 'custom', value: PubNub.generateUUID() }; + const channel = PubNub.generateUUID(); + let messageTimetoken: string | null = null; + + pubnub.addListener({ + status: (status) => { + if (status.category === 'PNConnectedCategory') { + pubnub.publish({ channel, message: { hello: 'test' }, sendByPost: true }, (publishStatus, response) => { + assert(response !== null); + messageTimetoken = response.timetoken; + + pubnub.addMessageAction({ channel, messageTimetoken, action: messageAction }); + }); + } + }, + messageAction: (messageActionEvent) => { + try { + assert(messageActionEvent.data); + assert.equal(messageActionEvent.data.type, messageAction.type); + assert.equal(messageActionEvent.data.value, messageAction.value); + assert.equal(messageActionEvent.data.uuid, pubnub.getUUID()); + assert.equal(messageActionEvent.data.messageTimetoken, messageTimetoken); + assert(messageActionEvent.data.actionTimetoken); + assert.equal(messageActionEvent.event, "added"); + pubnub.unsubscribeAll(); + + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnub.subscribe({ channels: [channel] }); + }).timeout(60000); + }); + + describe('removeMessageAction', () => { + describe('##validation', () => { + it("fails if 'messageTimetoken' is missing", (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .delete(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890/action/12345678901`) + .reply(200, {}); + + pubnub + // @ts-expect-error Intentionally don't include `messageTimetoken`. + .removeMessageAction({ + channel: 'test-channel', + actionTimetoken: '1234567890', + }) + .catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing message timetoken"); + + done(); + } catch (error) { + done(error); + } + }); + }); + + it("fails if 'actionTimetoken' is missing", (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .delete(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890/action/12345678901`) + .reply(200, {}); + + pubnub + // @ts-expect-error Intentionally don't include `actionTimetoken`. + .removeMessageAction({ + channel: 'test-channel', + messageTimetoken: '1234567890', + }) + .catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing action timetoken"); + + done(); + } catch (error) { + done(error); + } + }); + }); + + it("fails if 'channel' is missing", (done) => { + nock.disableNetConnect(); + const scope = utils + .createNock() + .delete(`/v1/message-actions/${subscribeKey}/channel/test-channel/message/1234567890/action/12345678901`) + .reply(200, {}); + + pubnub + // @ts-expect-error Intentionally don't include `channel`. + .removeMessageAction({ + messageTimetoken: '1234567890', + actionTimetoken: '12345678901', + }) + .catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing message action channel"); + + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + it('remove message action', (done) => { + const channel = PubNub.generateUUID(); + + publishMessages(pubnub, 1, channel, (messageTimetokens) => { + addActions(pubnub, 1, messageTimetokens, channel, (actionTimetokens) => { + pubnub.getMessageActions({ channel }, (status, response) => { + assert.equal(status.error, false); + assert(response !== null); + assert.equal(response.data.length, actionTimetokens.length); + + pubnub.removeMessageAction( + { channel, actionTimetoken: actionTimetokens[0], messageTimetoken: messageTimetokens[0] }, + (removeMessageStatus) => { + assert.equal(removeMessageStatus.error, false); + + setTimeout(() => { + pubnub.getMessageActions({ channel }, (getMessagesStatus, getMessagesResponse) => { + try { + assert.equal(getMessagesStatus.error, false); + assert(getMessagesResponse !== null); + assert.equal(getMessagesResponse.data.length, 0); + + done(); + } catch (error) { + done(error); + } + }); + }, 2000); + }, + ); + }); + }); + }); + }).timeout(60000); + + it('remove message action with encoded channel', (done) => { + const channel = `${PubNub.generateUUID()}#1`; + + publishMessages(pubnub, 1, channel, (messageTimetokens) => { + addActions(pubnub, 1, messageTimetokens, channel, (actionTimetokens) => { + pubnub.getMessageActions({ channel }, (status, response) => { + assert.equal(status.error, false); + assert(response !== null); + assert.equal(response.data.length, actionTimetokens.length); + + pubnub.removeMessageAction( + { channel, actionTimetoken: actionTimetokens[0], messageTimetoken: messageTimetokens[0] }, + (removeMessageStatus) => { + assert.equal(removeMessageStatus.error, false); + + setTimeout(() => { + pubnub.getMessageActions({ channel }, (getMessagesStatus, getMessagesResponse) => { + try { + assert.equal(getMessagesStatus.error, false); + assert(getMessagesResponse !== null); + assert.equal(getMessagesResponse.data.length, 0); + + done(); + } catch (error) { + done(error); + } + }); + }, 2000); + }, + ); + }); + }); + }); + }).timeout(60000); + + it('remove message action should trigger event', (done) => { + const channel = PubNub.generateUUID(); + + publishMessages(pubnub, 1, channel, (messageTimetokens) => { + addActions(pubnub, 1, messageTimetokens, channel, (actionTimetokens) => { + pubnub.addListener({ + status: (status) => { + if (status.category === 'PNConnectedCategory') { + pubnub.removeMessageAction( + { channel, actionTimetoken: actionTimetokens[0], messageTimetoken: messageTimetokens[0] }, + (removeMessagesStatus) => { + assert.equal(removeMessagesStatus.error, false); + }, + ); + } + }, + messageAction: (messageActionEvent) => { + try { + assert(messageActionEvent.data); + assert.equal(messageActionEvent.data.uuid, pubnub.getUUID()); + assert.equal(messageActionEvent.data.messageTimetoken, messageTimetokens[0]); + assert.equal(messageActionEvent.data.actionTimetoken, actionTimetokens[0]); + assert.equal(messageActionEvent.event, "removed"); + pubnub.unsubscribeAll(); + + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnub.subscribe({ channels: [channel] }); + }); + }); + }).timeout(60000); + }); + + describe('getMessageAction', () => { + describe('##validation', () => { + it("fails if 'channel' is missing", (done) => { + nock.disableNetConnect(); + const scope = utils.createNock().get(`/v1/message-actions/${subscribeKey}/channel/test-channel`).reply(200, {}); + + // @ts-expect-error Intentionally don't include `channel`. + pubnub.getMessageActions({}).catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing message channel"); + + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + it('fetch message actions', (done) => { + const channel = PubNub.generateUUID(); + + publishMessages(pubnub, 2, channel, (messageTimetokens) => { + addActions(pubnub, 3, messageTimetokens, channel, (actionTimetokens) => { + const lastPublishedActionTimetoken = actionTimetokens[actionTimetokens.length - 1]; + const firstPublishedActionTimetoken = actionTimetokens[0]; + + pubnub.getMessageActions({ channel }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + const firstFetchedActionTimetoken = response.data[0].actionTimetoken; + const lastFetchedActionTimetoken = response.data[response.data.length - 1].actionTimetoken; + assert.equal(firstFetchedActionTimetoken, firstPublishedActionTimetoken); + assert.equal(lastFetchedActionTimetoken, lastPublishedActionTimetoken); + assert.equal(response.data.length, actionTimetokens.length); + assert.equal(response.start, firstPublishedActionTimetoken); + assert.equal(response.end, lastPublishedActionTimetoken); + + done(); + } catch (error) { + done(error); + } + }); + }); + }); + }).timeout(60000); + + it('fetch message actions with encoded channel', (done) => { + const channel = `${PubNub.generateUUID()}#1`; + + publishMessages(pubnub, 2, channel, (messageTimetokens) => { + addActions(pubnub, 3, messageTimetokens, channel, (actionTimetokens) => { + const lastPublishedActionTimetoken = actionTimetokens[actionTimetokens.length - 1]; + const firstPublishedActionTimetoken = actionTimetokens[0]; + + pubnub.getMessageActions({ channel }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + const firstFetchedActionTimetoken = response.data[0].actionTimetoken; + const lastFetchedActionTimetoken = response.data[response.data.length - 1].actionTimetoken; + assert.equal(firstFetchedActionTimetoken, firstPublishedActionTimetoken); + assert.equal(lastFetchedActionTimetoken, lastPublishedActionTimetoken); + assert.equal(response.data.length, actionTimetokens.length); + assert.equal(response.start, firstPublishedActionTimetoken); + assert.equal(response.end, lastPublishedActionTimetoken); + + done(); + } catch (error) { + done(error); + } + }); + }); + }); + }).timeout(60000); + + it('fetch next message actions page', (done) => { + const channel = PubNub.generateUUID(); + + publishMessages(pubnub, 2, channel, (messageTimetokens) => { + addActions(pubnub, 5, messageTimetokens, channel, (actionTimetokens) => { + const lastPublishedActionTimetoken = actionTimetokens[actionTimetokens.length - 1]; + const halfSize = Math.floor(actionTimetokens.length * 0.5); + const firstPublishedActionTimetoken = actionTimetokens[0]; + const middleMinusOnePublishedActionTimetoken = actionTimetokens[halfSize - 1]; + const middlePublishedActionTimetoken = actionTimetokens[halfSize]; + + pubnub.getMessageActions({ channel, limit: halfSize }, (status, response) => { + assert.equal(status.error, false); + assert(response !== null); + let firstFetchedActionTimetoken = response.data[0].actionTimetoken; + let lastFetchedActionTimetoken = response.data[response.data.length - 1].actionTimetoken; + assert.equal(firstFetchedActionTimetoken, middlePublishedActionTimetoken); + assert.equal(lastFetchedActionTimetoken, lastPublishedActionTimetoken); + assert.equal(response.data.length, halfSize); + assert.equal(response.start, middlePublishedActionTimetoken); + assert.equal(response.end, lastPublishedActionTimetoken); + + pubnub.getMessageActions( + { channel, start: middlePublishedActionTimetoken, limit: halfSize }, + (getMessageActionsStatus, getMessageActionsResponse) => { + try { + assert.equal(getMessageActionsStatus.error, false); + assert(getMessageActionsResponse !== null); + firstFetchedActionTimetoken = getMessageActionsResponse.data[0].actionTimetoken; + lastFetchedActionTimetoken = + getMessageActionsResponse.data[getMessageActionsResponse.data.length - 1].actionTimetoken; + assert.equal(firstFetchedActionTimetoken, firstPublishedActionTimetoken); + assert.equal(lastFetchedActionTimetoken, middleMinusOnePublishedActionTimetoken); + assert.equal(getMessageActionsResponse.data.length, halfSize); + assert.equal(getMessageActionsResponse.start, firstPublishedActionTimetoken); + assert.equal(getMessageActionsResponse.end, middleMinusOnePublishedActionTimetoken); + + done(); + } catch (error) { + done(error); + } + }, + ); + }); + }); + }); + }).timeout(60000); + }); +}); diff --git a/test/integration/endpoints/message_counts.test.js b/test/integration/endpoints/message_counts.test.js deleted file mode 100644 index 3d8af1e59..000000000 --- a/test/integration/endpoints/message_counts.test.js +++ /dev/null @@ -1,187 +0,0 @@ -/* global describe, beforeEach, it, before, after */ -/* eslint no-console: 0 */ - -import assert from 'assert'; -import nock from 'nock'; -import utils from '../../utils'; -import PubNub from '../../../src/node/index'; - -describe('message counts', () => { - let pubnub; - - before(() => { - nock.disableNetConnect(); - }); - - after(() => { - nock.enableNetConnect(); - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - subscribeKey: 'mySubKey', - publishKey: 'myPublishKey', - uuid: 'myUUID', - }); - }); - - it('get history with messages for a channel', (done) => { - const scope = utils - .createNock() - .get('/v3/history/sub-key/mySubKey/message-counts/ch1') - .query({ - timetoken: 15495750401727535, - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":0}}' - ); - - pubnub.messageCounts( - { channels: ['ch1'], timetoken: 15495750401727535 }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { ch1: 0 }); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('get history with messages for multiple channels using timetoken', (done) => { - const scope = utils - .createNock() - .get('/v3/history/sub-key/mySubKey/message-counts/ch1%2Cch2%2Cch3') - .query({ - timetoken: 15495750401727535, - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":0,"ch2":0,"ch3":0}}' - ); - - pubnub.messageCounts( - { channels: ['ch1', 'ch2', 'ch3'], timetoken: 15495750401727535 }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { ch1: 0, ch2: 0, ch3: 0 }); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('get history with messages for a channel using channelTimetokens', (done) => { - const scope = utils - .createNock() - .get('/v3/history/sub-key/mySubKey/message-counts/ch1') - .query({ - timetoken: '15495750401727535', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":2}}' - ); - - pubnub.messageCounts( - { channels: ['ch1'], channelTimetokens: ['15495750401727535'] }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { ch1: 2 }); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('get history with messages for multiple channels using channelTimetokens', (done) => { - const scope = utils - .createNock() - .get('/v3/history/sub-key/mySubKey/message-counts/ch1%2Cch2%2Cch3') - .query({ - timetoken: '15495750401727535', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":0,"ch2":3,"ch3":0}}' - ); - - pubnub.messageCounts( - { - channels: ['ch1', 'ch2', 'ch3'], - channelTimetokens: ['15495750401727535'], - }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { ch1: 0, ch2: 3, ch3: 0 }); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('get history with messages for multiple channels using multiple channelTimetokens', (done) => { - const scope = utils - .createNock() - .get('/v3/history/sub-key/mySubKey/message-counts/ch1%2Cch2%2Cch3') - .query({ - channelsTimetoken: - '15495750401727535,15495750401727536,15495750401727537', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - }) - .reply( - 200, - '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":0,"ch2":0,"ch3":4}}' - ); - - pubnub.messageCounts( - { - channels: ['ch1', 'ch2', 'ch3'], - channelTimetokens: [ - '15495750401727535', - '15495750401727536', - '15495750401727537', - ], - }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { ch1: 0, ch2: 0, ch3: 4 }); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('should add message count API telemetry information', (done) => { - let scope = utils.createNock().get('/v3/history/sub-key/mySubKey/message-counts/ch1').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":0}}', - delays, - (completion) => { - pubnub.messageCounts( - { channels: ['ch1'], timetoken: 15495750401727535 }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_hist', average, leeway); - done(); - }); - }).timeout(60000); -}); diff --git a/test/integration/endpoints/message_counts.test.ts b/test/integration/endpoints/message_counts.test.ts new file mode 100644 index 000000000..19f66d255 --- /dev/null +++ b/test/integration/endpoints/message_counts.test.ts @@ -0,0 +1,173 @@ +/* global describe, beforeEach, it, before, after */ +/* eslint no-console: 0 */ + +import assert from 'assert'; +import nock from 'nock'; + +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; + +describe('message counts', () => { + let pubnub: PubNub; + + before(() => { + nock.disableNetConnect(); + }); + + after(() => { + nock.enableNetConnect(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, + }); + }); + + it('get history with messages for a channel', (done) => { + const scope = utils + .createNock() + .get('/v3/history/sub-key/mySubKey/message-counts/ch1') + .query({ + timetoken: '15495750401727535', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":0}}', { + 'content-type': 'text/javascript', + }); + + pubnub.messageCounts({ channels: ['ch1'], timetoken: '15495750401727535' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { ch1: 0 }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('get history with messages for multiple channels using timetoken', (done) => { + const scope = utils + .createNock() + .get('/v3/history/sub-key/mySubKey/message-counts/ch1,ch2,ch3') + .query({ + timetoken: '15495750401727535', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":0,"ch2":0,"ch3":0}}', { + 'content-type': 'text/javascript', + }); + + pubnub.messageCounts({ channels: ['ch1', 'ch2', 'ch3'], timetoken: '15495750401727535' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { ch1: 0, ch2: 0, ch3: 0 }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('get history with messages for a channel using channelTimetokens', (done) => { + const scope = utils + .createNock() + .get('/v3/history/sub-key/mySubKey/message-counts/ch1') + .query({ + timetoken: '15495750401727535', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":2}}', { + 'content-type': 'text/javascript', + }); + + pubnub.messageCounts({ channels: ['ch1'], channelTimetokens: ['15495750401727535'] }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { ch1: 2 }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('get history with messages for multiple channels using channelTimetokens', (done) => { + const scope = utils + .createNock() + .get('/v3/history/sub-key/mySubKey/message-counts/ch1,ch2,ch3') + .query({ + timetoken: '15495750401727535', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":0,"ch2":3,"ch3":0}}', { + 'content-type': 'text/javascript', + }); + + pubnub.messageCounts( + { + channels: ['ch1', 'ch2', 'ch3'], + channelTimetokens: ['15495750401727535'], + }, + (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { ch1: 0, ch2: 3, ch3: 0 }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); + }); + + it('get history with messages for multiple channels using multiple channelTimetokens', (done) => { + const scope = utils + .createNock() + .get('/v3/history/sub-key/mySubKey/message-counts/ch1,ch2,ch3') + .query({ + channelsTimetoken: '15495750401727535,15495750401727536,15495750401727537', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{"status": 200, "error": false, "error_message": "", "channels": {"ch1":0,"ch2":0,"ch3":4}}', { + 'content-type': 'text/javascript', + }); + + pubnub.messageCounts( + { + channels: ['ch1', 'ch2', 'ch3'], + channelTimetokens: ['15495750401727535', '15495750401727536', '15495750401727537'], + }, + (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { ch1: 0, ch2: 0, ch3: 4 }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); + }); +}); diff --git a/test/integration/endpoints/objects/channel.test.js b/test/integration/endpoints/objects/channel.test.ts similarity index 92% rename from test/integration/endpoints/objects/channel.test.js rename to test/integration/endpoints/objects/channel.test.ts index d343c9b4f..1bd25182a 100644 --- a/test/integration/endpoints/objects/channel.test.js +++ b/test/integration/endpoints/objects/channel.test.ts @@ -1,17 +1,18 @@ +import { expect } from 'chai'; import nock from 'nock'; -import utils from '../../../utils'; -import PubNub from '../../../../src/node/index'; -import { asResponse, allChannels, channel1 } from './fixtures'; +import { asResponse, allChannels, channel1 } from './fixtures.js'; +import PubNub from '../../../../src/node/index'; +import utils from '../../../utils'; describe('objects channel', () => { - const SUBSCRIBE_KEY = 'mySubKey'; const PUBLISH_KEY = 'myPublishKey'; - const UUID = 'myUUID'; + const SUBSCRIBE_KEY = 'mySubKey'; const AUTH_KEY = 'myAuthKey'; + const UUID = 'myUUID'; - let pubnub; - let PNSDK; + let pubnub: PubNub; + let PNSDK: string; before(() => { nock.disableNetConnect(); @@ -27,6 +28,8 @@ describe('objects channel', () => { subscribeKey: SUBSCRIBE_KEY, publishKey: PUBLISH_KEY, uuid: UUID, + // @ts-expect-error Force override default value. + useRequestId: false, authKey: AUTH_KEY, }); PNSDK = `PubNub-JS-Nodejs/${pubnub.getVersion()}`; @@ -75,9 +78,6 @@ describe('objects channel', () => { await expect(resultP).to.eventually.deep.equal({ status: 200, data: allChannels.map(asResponse), - next: undefined, - prev: undefined, - totalCount: undefined, }); }); }); @@ -135,7 +135,7 @@ describe('objects channel', () => { }); it('should reject if channel is empty', async () => { - // $FlowFixMe This is intentional to suppress Flow error + // @ts-expect-error Intentionally don't include `channel`. const resultP = pubnub.objects.getChannelMetadata(); await expect(resultP).to.be.rejected; @@ -195,8 +195,8 @@ describe('objects channel', () => { }); it('should reject if data is missing', async () => { - // $FlowFixMe This is intentional to suppress Flow error - const resultP = pubnub.objects.setChannelMetadata(); + // @ts-expect-error Intentionally don't include `data`. + const resultP = pubnub.objects.setChannelMetadata({ channel: 'test' }); await expect(resultP).to.be.rejected; }); @@ -248,8 +248,8 @@ describe('objects channel', () => { }); }); - it('should reject if uuid is missing', async () => { - // $FlowFixMe This is intentional to suppress Flow error + it('should reject if channel is missing', async () => { + // @ts-expect-error Intentionally don't include `channel`. const resultP = pubnub.objects.removeChannelMetadata(); await expect(resultP).to.be.rejected; diff --git a/test/integration/endpoints/objects/fixtures.js b/test/integration/endpoints/objects/fixtures.ts similarity index 92% rename from test/integration/endpoints/objects/fixtures.js rename to test/integration/endpoints/objects/fixtures.ts index e534a2e26..b07091260 100644 --- a/test/integration/endpoints/objects/fixtures.js +++ b/test/integration/endpoints/objects/fixtures.ts @@ -1,6 +1,6 @@ /** */ -export const asResponse = (fixture ) => ({ +export const asResponse = (fixture: Record) => ({ ...fixture.data, update: fixture.updated, eTag: fixture.eTag, diff --git a/test/integration/endpoints/objects/membership.test.js b/test/integration/endpoints/objects/membership.test.ts similarity index 84% rename from test/integration/endpoints/objects/membership.test.js rename to test/integration/endpoints/objects/membership.test.ts index 304422089..626f66659 100644 --- a/test/integration/endpoints/objects/membership.test.js +++ b/test/integration/endpoints/objects/membership.test.ts @@ -1,8 +1,9 @@ /** */ import nock from 'nock'; -import utils from '../../../utils'; + import PubNub from '../../../../src/node/index'; +import utils from '../../../utils'; // import {} from './fixtures'; @@ -12,8 +13,8 @@ describe('objects membership', () => { const UUID = 'myUUID'; const AUTH_KEY = 'myAuthKey'; - let pubnub ; - let PNSDK ; + let pubnub: PubNub; + let PNSDK: string; before(() => { nock.disableNetConnect(); @@ -29,6 +30,8 @@ describe('objects membership', () => { subscribeKey: SUBSCRIBE_KEY, publishKey: PUBLISH_KEY, uuid: UUID, + // @ts-expect-error Force override default value. + useRequestId: false, authKey: AUTH_KEY, }); PNSDK = `PubNub-JS-Nodejs/${pubnub.getVersion()}`; diff --git a/test/integration/endpoints/objects/uuid.test.js b/test/integration/endpoints/objects/uuid.test.ts similarity index 95% rename from test/integration/endpoints/objects/uuid.test.js rename to test/integration/endpoints/objects/uuid.test.ts index 19215af50..e51a9a765 100644 --- a/test/integration/endpoints/objects/uuid.test.js +++ b/test/integration/endpoints/objects/uuid.test.ts @@ -1,17 +1,18 @@ +import { expect } from 'chai'; import nock from 'nock'; -import utils from '../../../utils'; -import PubNub from '../../../../src/node/index'; import { asResponse, allUsers, user1 } from './fixtures'; +import PubNub from '../../../../src/node/index'; +import utils from '../../../utils'; describe('objects UUID', () => { - const SUBSCRIBE_KEY = 'mySubKey'; const PUBLISH_KEY = 'myPublishKey'; - const UUID = 'myUUID'; + const SUBSCRIBE_KEY = 'mySubKey'; const AUTH_KEY = 'myAuthKey'; + const UUID = 'myUUID'; - let pubnub; - let PNSDK; + let pubnub: PubNub; + let PNSDK: string; before(() => { nock.disableNetConnect(); @@ -27,6 +28,8 @@ describe('objects UUID', () => { subscribeKey: SUBSCRIBE_KEY, publishKey: PUBLISH_KEY, uuid: UUID, + // @ts-expect-error Force override default value. + useRequestId: false, authKey: AUTH_KEY, }); PNSDK = `PubNub-JS-Nodejs/${pubnub.getVersion()}`; @@ -55,9 +58,6 @@ describe('objects UUID', () => { await expect(resultP).to.eventually.deep.equal({ status: 200, data: allUsers.map(asResponse), - prev: undefined, - next: undefined, - totalCount: undefined, }); }); @@ -249,7 +249,7 @@ describe('objects UUID', () => { }); it('should reject if data is missing', async () => { - // $FlowFixMe This is intentional to suppress Flow error + // @ts-expect-error Intentionally don't include `data`. const resultP = pubnub.objects.setUUIDMetadata(); await expect(resultP).to.be.rejected; @@ -321,12 +321,5 @@ describe('objects UUID', () => { data: {}, }); }); - - it('should reject if uuid is missing', async () => { - // $FlowFixMe This is intentional to suppress Flow error - const resultP = pubnub.objects.removeUUIDMetadata(); - - await expect(resultP).to.be.rejected; - }); }); }); diff --git a/test/integration/endpoints/presence.test.js b/test/integration/endpoints/presence.test.ts similarity index 54% rename from test/integration/endpoints/presence.test.js rename to test/integration/endpoints/presence.test.ts index 53ac17efe..139e7a726 100644 --- a/test/integration/endpoints/presence.test.js +++ b/test/integration/endpoints/presence.test.ts @@ -2,12 +2,12 @@ import assert from 'assert'; import nock from 'nock'; -import utils from '../../utils'; + import PubNub from '../../../src/node/index'; +import utils from '../../utils'; describe('presence endpoints', () => { - let pubnubOther; - let pubnub; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); @@ -23,6 +23,8 @@ describe('presence endpoints', () => { subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, }); }); @@ -35,13 +37,20 @@ describe('presence endpoints', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', }) - .reply(200, '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.whereNow({}, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['a', 'b']); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, ["a", "b"]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -53,19 +62,28 @@ describe('presence endpoints', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID#1', }) - .reply(200, '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "Presence"}', { + 'content-type': 'text/javascript', + }); const pubnubClient = new PubNub({ subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', uuid: 'myUUID#1', + // @ts-expect-error Force override default value. + useRequestId: false, }); pubnubClient.whereNow({}, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['a', 'b']); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, ["a", "b"]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -77,13 +95,20 @@ describe('presence endpoints', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', }) - .reply(200, '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.whereNow({ uuid: 'otherUUID' }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['a', 'b']); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, ["a", "b"]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -95,40 +120,22 @@ describe('presence endpoints', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', }) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.whereNow({ uuid: '' }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, []); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, []); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); - - it('should add where now API telemetry information', (done) => { - let scope = utils.createNock().get('/v2/presence/sub-key/mySubscribeKey/uuid/myUUID').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils - .runAPIWithResponseDelays( - scope, - 200, - '{"status": 200, "message": "OK", "payload": {"channels": ["a","b"]}, "service": "Presence"}', - delays, - (completion) => { - pubnub.whereNow({}, () => { - completion(); - }); - }, - ) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_pres', average, leeway); - done(); - }); - }).timeout(60000); }); describe('#setState', () => { @@ -144,13 +151,19 @@ describe('presence endpoints', () => { .reply( 200, '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online"}, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.setState({ channels: ['testChannel'], state: { new: 'state' } }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.state, { age: 20, status: 'online' }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -166,26 +179,35 @@ describe('presence endpoints', () => { .reply( 200, '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online"}, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); const pubnubClient = new PubNub({ subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', uuid: 'myUUID#1', + // @ts-expect-error Force override default value. + useRequestId: false, }); pubnubClient.setState({ channels: ['testChannel#1'], state: { new: 'state' } }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.state, { age: 20, status: 'online' }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); it('sets presence data for multiple channels', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/uuid/myUUID/data') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/uuid/myUUID/data') + .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -194,23 +216,29 @@ describe('presence endpoints', () => { .reply( 200, '{ "status": 200, "message": "OK", "payload": { "ch1": { "age" : 20, "status" : "online"}, "ch2": { "age": 100, "status": "offline" } }, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.setState({ channels: ['ch1', 'ch2'], state: { new: 'state' } }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.state, { - ch1: { age: 20, status: 'online' }, - ch2: { age: 100, status: 'offline' }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.state, { + ch1: { age: 20, status: "online" }, + ch2: { age: 100, status: "offline" } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); it('sets state for multiple channels / channel groups', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/uuid/myUUID/data') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/uuid/myUUID/data') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -220,6 +248,7 @@ describe('presence endpoints', () => { .reply( 200, '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online"}, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.setState( @@ -229,41 +258,18 @@ describe('presence endpoints', () => { state: { new: 'state' }, }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.state, { age: 20, status: 'online' }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }, ); }); - - it('should add set state API telemetry information', (done) => { - let scope = utils - .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/testChannel/uuid/myUUID/data') - .query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils - .runAPIWithResponseDelays( - scope, - 200, - '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online"}, "service": "Presence"}', - delays, - (completion) => { - pubnub.setState({ channels: ['testChannel'], state: { new: 'state' } }, () => { - completion(); - }); - }, - ) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_pres', average, leeway); - done(); - }); - }).timeout(60000); }); describe('#getState', () => { @@ -278,15 +284,21 @@ describe('presence endpoints', () => { .reply( 200, '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online"}, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.getState({ channels: ['testChannel'] }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - testChannel: { age: 20, status: 'online' }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + testChannel: { age: 20, status: "online" } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -301,22 +313,28 @@ describe('presence endpoints', () => { .reply( 200, '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online"}, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.getState({ uuid: 'otherUUID', channels: ['testChannel'] }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - testChannel: { age: 20, status: 'online' }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + testChannel: { age: 20, status: "online" } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); it('returns the requested for multiple channels', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/uuid/myUUID') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/uuid/myUUID') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -324,23 +342,29 @@ describe('presence endpoints', () => { .reply( 200, '{ "status": 200, "message": "OK", "payload": { "ch1": { "age" : 20, "status" : "online"}, "ch2": { "age": 100, "status": "offline" } }, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.getState({ channels: ['ch1', 'ch2'] }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - ch1: { age: 20, status: 'online' }, - ch2: { age: 100, status: 'offline' }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + ch1: { age: 20, status: "online" }, + ch2: { age: 100, status: "offline" } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); it('returns the requested for multiple channels', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/uuid/myUUID') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/uuid/myUUID') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -349,46 +373,24 @@ describe('presence endpoints', () => { .reply( 200, '{ "status": 200, "message": "OK", "payload": { "ch1": { "age" : 20, "status" : "online"}, "ch2": { "age": 100, "status": "offline" } }, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.getState({ channels: ['ch1', 'ch2'], channelGroups: ['cg1', 'cg2'] }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - ch1: { age: 20, status: 'online' }, - ch2: { age: 100, status: 'offline' }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + ch1: { age: 20, status: "online" }, + ch2: { age: 100, status: "offline" } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); - - it('should add get state API telemetry information', (done) => { - let scope = utils - .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/testChannel/uuid/myUUID') - .query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils - .runAPIWithResponseDelays( - scope, - 200, - '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online"}, "service": "Presence"}', - delays, - (completion) => { - pubnub.getState({ channels: ['testChannel'] }, () => { - completion(); - }); - }, - ) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_pres', average, leeway); - done(); - }); - }).timeout(60000); }); describe('#hereNow', () => { @@ -403,24 +405,30 @@ describe('presence endpoints', () => { .reply( 200, '{"status": 200, "message": "OK", "uuids": ["a3ffd012-a3b9-478c-8705-64089f24d71e"], "occupancy": 1, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.hereNow({ channels: ['game1'] }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - game1: { - name: 'game1', - occupancy: 1, - occupants: [ - { - state: null, - uuid: 'a3ffd012-a3b9-478c-8705-64089f24d71e', - }, - ], - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + game1: { + name: "game1", + occupancy: 1, + occupants: [ + { + state: null, + uuid: "a3ffd012-a3b9-478c-8705-64089f24d71e" + } + ] + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -432,26 +440,33 @@ describe('presence endpoints', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', }) - .reply(200, '{"status": 200, "message": "OK", "occupancy": 1, "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "occupancy": 1, "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.hereNow({ channels: ['game1'] }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - game1: { - name: 'game1', - occupancy: 1, - occupants: [], - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + game1: { + name: "game1", + occupancy: 1, + occupants: [] + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); it('returns response for multiple channels', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -459,31 +474,37 @@ describe('presence endpoints', () => { .reply( 200, '{"status": 200, "message": "OK", "payload": {"channels": {"game1": {"uuids": ["a3ffd012-a3b9-478c-8705-64089f24d71e"], "occupancy": 1}}, "total_channels": 1, "total_occupancy": 1}, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.hereNow({ channels: ['ch1', 'ch2'] }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - game1: { - name: 'game1', - occupancy: 1, - occupants: [ - { - state: null, - uuid: 'a3ffd012-a3b9-478c-8705-64089f24d71e', - }, - ], - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + game1: { + name: "game1", + occupancy: 1, + occupants: [ + { + state: null, + uuid: "a3ffd012-a3b9-478c-8705-64089f24d71e" + } + ] + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); it('returns response for multiple channel with state', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -492,45 +513,48 @@ describe('presence endpoints', () => { .reply( 200, '{"status":200,"message":"OK","payload":{"total_occupancy":3,"total_channels":2,"channels":{"ch1":{"occupancy":1,"uuids":[{"uuid":"user1"}]},"ch2":{"occupancy":2,"uuids":[{"uuid":"user1"},{"uuid":"user3"}]}}},"service":"Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.hereNow({ channels: ['ch1', 'ch2'], includeState: true }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - ch1: { - name: 'ch1', - occupancy: 1, - occupants: [ - { - state: undefined, - uuid: 'user1', - }, - ], - }, - ch2: { - name: 'ch2', - occupancy: 2, - occupants: [ - { - state: undefined, - uuid: 'user1', - }, - { - state: undefined, - uuid: 'user3', - }, - ], - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + ch1: { + name: "ch1", + occupancy: 1, + occupants: [ + { + uuid: "user1" + } + ] + }, + ch2: { + name: "ch2", + occupancy: 2, + occupants: [ + { + uuid: "user1" + }, + { + uuid: "user3" + } + ] + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); it('returns response for multiple channel here now without UUIDS', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -539,31 +563,37 @@ describe('presence endpoints', () => { .reply( 200, '{"status":200,"message":"OK","payload":{"total_occupancy":3,"total_channels":2,"channels":{"ch1":{"occupancy":1,"uuids":[{"uuid":"user1"}]},"ch2":{"occupancy":2,"uuids":[{"uuid":"user1"},{"uuid":"user3"}]}}},"service":"Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.hereNow({ channels: ['ch1', 'ch2'], includeUUIDs: false }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - ch1: { - name: 'ch1', - occupancy: 1, - occupants: [], - }, - ch2: { - name: 'ch2', - occupancy: 2, - occupants: [], - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + ch1: { + name: "ch1", + occupancy: 1, + occupants: [] + }, + ch2: { + name: "ch2", + occupancy: 2, + occupants: [] + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); it('returns response for channel group', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/%2C') + .get('/v2/presence/sub-key/mySubscribeKey/channel/,') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -572,24 +602,30 @@ describe('presence endpoints', () => { .reply( 200, ' {"status": 200, "message": "OK", "payload": {"channels": {"ch1": {"uuids": ["a581c974-e2f9-4088-9cc8-9632708e012d"], "occupancy": 1}}, "total_channels": 1, "total_occupancy": 1}, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.hereNow({ channelGroups: ['cg1'] }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - ch1: { - name: 'ch1', - occupancy: 1, - occupants: [ - { - state: null, - uuid: 'a581c974-e2f9-4088-9cc8-9632708e012d', - }, - ], - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + ch1: { + name: "ch1", + occupancy: 1, + occupants: [ + { + state: null, + uuid: "a581c974-e2f9-4088-9cc8-9632708e012d" + } + ] + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -604,34 +640,40 @@ describe('presence endpoints', () => { .reply( 200, '{"status": 200, "message": "OK", "payload": {"channels": {"ch10": {"uuids": ["2c3b136e-dc9e-4e97-939c-752dbb47acbd"], "occupancy": 1}, "bot_object": {"uuids": ["fb49e109-756f-483e-92dc-d966d73a119d"], "occupancy": 1}}, "total_channels": 2, "total_occupancy": 2}, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.hereNow({}, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - bot_object: { - name: 'bot_object', - occupancy: 1, - occupants: [ - { - state: null, - uuid: 'fb49e109-756f-483e-92dc-d966d73a119d', - }, - ], - }, - ch10: { - name: 'ch10', - occupancy: 1, - occupants: [ - { - state: null, - uuid: '2c3b136e-dc9e-4e97-939c-752dbb47acbd', - }, - ], - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + bot_object: { + name: "bot_object", + occupancy: 1, + occupants: [ + { + state: null, + uuid: "fb49e109-756f-483e-92dc-d966d73a119d" + } + ] + }, + ch10: { + name: "ch10", + occupancy: 1, + occupants: [ + { + state: null, + uuid: "2c3b136e-dc9e-4e97-939c-752dbb47acbd" + } + ] + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -647,24 +689,30 @@ describe('presence endpoints', () => { .reply( 200, '{"status": 200, "message": "OK", "payload": {"channels": {"ch10": {"occupancy": 1}, "bot_object": {"occupancy": 1}}, "total_channels": 2, "total_occupancy": 2}, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.hereNow({ includeUUIDs: false }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - bot_object: { - name: 'bot_object', - occupancy: 1, - occupants: [], - }, - ch10: { - name: 'ch10', - occupancy: 1, - occupants: [], - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + bot_object: { + name: "bot_object", + occupancy: 1, + occupants: [] + }, + ch10: { + name: "ch10", + occupancy: 1, + occupants: [] + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -677,12 +725,18 @@ describe('presence endpoints', () => { uuid: 'myUUID', disable_uuids: 1, }) - .reply(200, '{"status": 503, "message": "Service Unavailable", "error": 1, "service": "Presence"}'); + .reply(200, '{"status": 503, "message": "Service Unavailable", "error": 1, "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.hereNow({ includeUUIDs: false }, (status) => { - assert.equal(status.error, true); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, true); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -697,14 +751,24 @@ describe('presence endpoints', () => { .reply( 200, '{"status": 402, "error": 1, "message": "This feature is not turned on for this account. Contact support@pubnub.com to activate this feature.", "service": "Presence"}', + { + 'content-type': 'text/javascript', + }, ); + let expected = - 'You have tried to perform a Global Here Now operation, your keyset configuration does not support that. Please provide a channel, or enable the Global Here Now feature from the Portal.'; - pubnub.hereNow({ channles: [] }, (status) => { - assert.equal(status.error, true); - assert.equal(status.errorData.message, expected); - assert.equal(scope.isDone(), true); - done(); + 'This feature is not turned on for this account. Contact support@pubnub.com to activate this feature.'; + pubnub.hereNow({ channels: [] }, (status) => { + try { + assert.equal(status.error, true); + assert(status.errorData); + // @ts-expect-error `errorData` may contain a dictionary (Payload) with an arbitrary set of fields. + assert.equal(status.errorData.message, expected); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); @@ -720,50 +784,31 @@ describe('presence endpoints', () => { .reply( 200, '{"status": 200, "message": "OK", "uuids": ["a3ffd012-a3b9-478c-8705-64089f24d71e"], "occupancy": 1, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); pubnub.hereNow({ channels: ['game1'], queryParameters: { test: 'param' } }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, { - game1: { - name: 'game1', - occupancy: 1, - occupants: [ - { - state: null, - uuid: 'a3ffd012-a3b9-478c-8705-64089f24d71e', - }, - ], - }, - }); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, { + game1: { + name: "game1", + occupancy: 1, + occupants: [ + { + state: null, + uuid: "a3ffd012-a3b9-478c-8705-64089f24d71e" + } + ] + } + }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } }); }); - - it('should add here now API telemetry information', (done) => { - let scope = utils.createNock().get('/v2/presence/sub-key/mySubscribeKey/channel/game1').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils - .runAPIWithResponseDelays( - scope, - 200, - '{"status": 200, "message": "OK", "uuids": ["a3ffd012-a3b9-478c-8705-64089f24d71e"], "occupancy": 1, "service": "Presence"}', - delays, - (completion) => { - pubnub.hereNow({ channels: ['game1'] }, () => { - completion(); - }); - }, - ) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_pres', average, leeway); - done(); - }); - }).timeout(60000); }); }); diff --git a/test/integration/endpoints/publish.test.js b/test/integration/endpoints/publish.test.js deleted file mode 100644 index 8b2138846..000000000 --- a/test/integration/endpoints/publish.test.js +++ /dev/null @@ -1,300 +0,0 @@ -/* global describe, beforeEach, it, before, after */ -/* eslint no-console: 0 */ - -import assert from 'assert'; -import nock from 'nock'; -import utils from '../../utils'; -import PubNub from '../../../src/node/index'; - -describe('publish endpoints', () => { - let pubnub; - - before(() => { - nock.disableNetConnect(); - }); - - after(() => { - nock.enableNetConnect(); - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - subscribeKey: 'mySubKey', - publishKey: 'myPublishKey', - uuid: 'myUUID', - authKey: 'myAuthKey', - useRandomIVs: false - }); - }); - - describe('##validation', () => { - it('fails if channel is missing', (done) => { - const scope = utils - .createNock() - .get('/publish/*') - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.publish({ message: { such: 'object' } }).catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing Channel'); - done(); - }); - }); - }); - - it('publishes a complex object via GET', (done) => { - const scope = utils - .createNock() - .get( - '/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D' - ) - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey', - }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1' }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('publishes without replication via GET', (done) => { - const scope = utils - .createNock() - .get( - '/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D' - ) - .query({ - norep: true, - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey', - }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1', replicate: false }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('publishes a complex object via GET with encryption', (done) => { - const scope = utils - .createNock() - .get( - '/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22' - ) - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey', - }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.setCipherKey('myCipherKey'); - - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1' }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports ttl param', (done) => { - const scope = utils - .createNock() - .get( - '/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22' - ) - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey', - ttl: '10', - }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.setCipherKey('myCipherKey'); - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1', ttl: 10 }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports storeInHistory=0', (done) => { - const scope = utils - .createNock() - .get( - '/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22' - ) - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey', - store: '0', - }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.setCipherKey('myCipherKey'); - - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1', storeInHistory: false }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports storeInHistory=1', (done) => { - const scope = utils - .createNock() - .get( - '/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22' - ) - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey', - store: '1', - }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.setCipherKey('myCipherKey'); - - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1', storeInHistory: true }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('publishes a complex object via POST', (done) => { - const scope = utils - .createNock() - .post('/publish/myPublishKey/mySubKey/0/ch1/0', '{"such":"object"}') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey', - }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1', sendByPost: true }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('publishes a complex object via POST with encryption', (done) => { - const scope = utils - .createNock() - .post( - '/publish/myPublishKey/mySubKey/0/ch1/0', - '"toDEeIZkmIyoiLpSojGu7n3+2t1rn7/DsrEZ1r8JKR4="' - ) - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey', - }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.setCipherKey('myCipherKey'); - - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1', sendByPost: true }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('should add publish API telemetry information', (done) => { - let scope = utils.createNock().get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '[1,"Sent","14647523059145592"]', - delays, - (completion) => { - pubnub.publish( - { message: { such: 'object' }, channel: 'ch1' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_pub', average, leeway); - done(); - }); - }).timeout(60000); - - describe('#fire', () => { - it('publishes a complex object via GET', (done) => { - const scope = utils - .createNock() - .get( - '/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D' - ) - .query({ - norep: true, - store: 0, - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - uuid: 'myUUID', - auth: 'myAuthKey', - }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.fire( - { message: { such: 'object' }, channel: 'ch1' }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - }); -}); diff --git a/test/integration/endpoints/publish.test.ts b/test/integration/endpoints/publish.test.ts new file mode 100644 index 000000000..cc113b55b --- /dev/null +++ b/test/integration/endpoints/publish.test.ts @@ -0,0 +1,286 @@ +/* global describe, beforeEach, it, before, after */ +/* eslint no-console: 0 */ + +import assert from 'assert'; +import nock from 'nock'; + +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; + +describe('publish endpoints', () => { + let pubnub: PubNub; + + before(() => { + nock.disableNetConnect(); + }); + + after(() => { + nock.enableNetConnect(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + uuid: 'myUUID', + authKey: 'myAuthKey', + // @ts-expect-error Force override default value. + useRequestId: false, + useRandomIVs: false, + }); + }); + + describe('##validation', () => { + it('fails if channel is missing', (done) => { + const scope = utils + .createNock() + .get('/publish/*') + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + // @ts-expect-error Intentionally don't include `channel`. + pubnub.publish({ message: { such: 'object' } }).catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing 'channel'"); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + it('publishes a complex object via GET', (done) => { + const scope = utils + .createNock() + .get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.publish({ message: { such: 'object' }, channel: 'ch1' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('publishes without replication via GET', (done) => { + const scope = utils + .createNock() + .get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') + .query({ + norep: true, + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.publish({ message: { such: 'object' }, channel: 'ch1', replicate: false }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('publishes a complex object via GET with encryption', (done) => { + const scope = utils + .createNock() + .get('/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.setCipherKey('myCipherKey'); + + pubnub.publish({ message: { such: 'object' }, channel: 'ch1' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports ttl param', (done) => { + const scope = utils + .createNock() + .get('/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + ttl: '10', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.setCipherKey('myCipherKey'); + pubnub.publish({ message: { such: 'object' }, channel: 'ch1', ttl: 10 }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports storeInHistory=0', (done) => { + const scope = utils + .createNock() + .get('/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + store: '0', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.setCipherKey('myCipherKey'); + + pubnub.publish({ message: { such: 'object' }, channel: 'ch1', storeInHistory: false }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports storeInHistory=1', (done) => { + const scope = utils + .createNock() + .get('/publish/myPublishKey/mySubKey/0/ch1/0/%22toDEeIZkmIyoiLpSojGu7n3%2B2t1rn7%2FDsrEZ1r8JKR4%3D%22') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + store: '1', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.setCipherKey('myCipherKey'); + + pubnub.publish({ message: { such: 'object' }, channel: 'ch1', storeInHistory: true }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('publishes a complex object via POST', (done) => { + const scope = utils + .createNock() + .post('/publish/myPublishKey/mySubKey/0/ch1/0', '{"such":"object"}') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.publish({ message: { such: 'object' }, channel: 'ch1', sendByPost: true }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('publishes a complex object via POST with encryption', (done) => { + const scope = utils + .createNock() + .post('/publish/myPublishKey/mySubKey/0/ch1/0', '"toDEeIZkmIyoiLpSojGu7n3+2t1rn7/DsrEZ1r8JKR4="') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.setCipherKey('myCipherKey'); + + pubnub.publish({ message: { such: 'object' }, channel: 'ch1', sendByPost: true }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + describe('#fire', () => { + it('publishes a complex object via GET', (done) => { + const scope = utils + .createNock() + .get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') + .query({ + norep: true, + store: 0, + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.fire({ message: { such: 'object' }, channel: 'ch1' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + }); +}); diff --git a/test/integration/endpoints/push.test.js b/test/integration/endpoints/push.test.js deleted file mode 100644 index a3c163e8b..000000000 --- a/test/integration/endpoints/push.test.js +++ /dev/null @@ -1,632 +0,0 @@ -/* global describe, beforeEach, it, before, after */ -/* eslint no-console: 0 */ - -import assert from 'assert'; -import nock from 'nock'; -import utils from '../../utils'; -import PubNub from '../../../src/node/index'; - -describe('push endpoints', () => { - let pubnub; - - before(() => { - nock.disableNetConnect(); - }); - - after(() => { - nock.enableNetConnect(); - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - subscribeKey: 'mySubKey', - publishKey: 'myPublishKey', - uuid: 'myUUID', - }); - }); - - describe('adding channels to device', () => { - it('supports addition of multiple channels for apple', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/niceDevice') - .query({ - add: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'apns', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.addChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports addition of multiple channels for apple (APNS2)', (done) => { - const scope = utils - .createNock() - .get('/v2/push/sub-key/mySubKey/devices-apns2/niceDevice') - .query({ - add: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - environment: 'development', - topic: 'com.test.apns', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.addChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns2', topic: 'com.test.apns' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports addition of multiple channels for microsoft', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/niceDevice') - .query({ - add: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'mpns', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.addChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'mpns' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports addition of multiple channels for google', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/niceDevice') - .query({ - add: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'gcm', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.addChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'gcm' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('should add push enabled for channels API telemetry information', (done) => { - let scope = utils.createNock().get('/v1/push/sub-key/mySubKey/devices/niceDevice').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '[1, "Modified Channels"]', - delays, - (completion) => { - pubnub.push.addChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_push', average, leeway); - done(); - }); - }).timeout(60000); - - it('should add APNS2 enabled for channels API telemetry information', (done) => { - let scope = utils.createNock().get('/v2/push/sub-key/mySubKey/devices-apns2/niceDevice').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '[1, "Modified Channels"]', - delays, - (completion) => { - pubnub.push.addChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns2', topic: 'com.test.apns' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_push', average, leeway); - done(); - }); - }).timeout(60000); - }); - - describe('listing channels for device', () => { - it('supports channel listing for apple', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/coolDevice') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'apns', - uuid: 'myUUID', - }) - .reply(200, '["ch1", "ch2", "ch3"]'); - - pubnub.push.listChannels( - { device: 'coolDevice', pushGateway: 'apns' }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports channel listing for apple (APNS2)', (done) => { - const scope = utils - .createNock() - .get('/v2/push/sub-key/mySubKey/devices-apns2/coolDevice') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - environment: 'production', - topic: 'com.test.apns', - uuid: 'myUUID', - }) - .reply(200, '["ch1", "ch2", "ch3"]'); - - pubnub.push.listChannels( - { device: 'coolDevice', pushGateway: 'apns2', environment: 'production', topic: 'com.test.apns' }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports channel listing for microsoft', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/coolDevice') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'mpns', - uuid: 'myUUID', - }) - .reply(200, '["ch1", "ch2", "ch3"]'); - - pubnub.push.listChannels( - { device: 'coolDevice', pushGateway: 'mpns' }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports channel listing for google', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/coolDevice') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'gcm', - uuid: 'myUUID', - }) - .reply(200, '["ch1", "ch2", "ch3"]'); - - pubnub.push.listChannels( - { device: 'coolDevice', pushGateway: 'gcm' }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('should add push audit API telemetry information', (done) => { - let scope = utils.createNock().get('/v1/push/sub-key/mySubKey/devices/coolDevice').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '["ch1", "ch2", "ch3"]', - delays, - (completion) => { - pubnub.push.listChannels( - { device: 'coolDevice', pushGateway: 'apns' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_push', average, leeway); - done(); - }); - }).timeout(60000); - - it('should add APNS2 audit API telemetry information', (done) => { - let scope = utils.createNock().get('/v2/push/sub-key/mySubKey/devices-apns2/coolDevice').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '["ch1", "ch2", "ch3"]', - delays, - (completion) => { - pubnub.push.listChannels( - { device: 'coolDevice', pushGateway: 'apns2', environment: 'production', topic: 'com.test.apns' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_push', average, leeway); - done(); - }); - }).timeout(60000); - }); - - describe('supports deletion of channels', () => { - it('supports removal of multiple channels for apple', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/niceDevice') - .query({ - remove: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'apns', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.removeChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports removal of multiple channels for apple (APNS2)', (done) => { - const scope = utils - .createNock() - .get('/v2/push/sub-key/mySubKey/devices-apns2/niceDevice') - .query({ - remove: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - environment: 'development', - topic: 'com.test.apns', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.removeChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns2', topic: 'com.test.apns' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports removal of multiple channels for microsoft', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/niceDevice') - .query({ - remove: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'mpns', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.removeChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'mpns' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports removal of multiple channels for google', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/niceDevice') - .query({ - remove: 'a,b', - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'gcm', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.removeChannels( - { - channels: ['a', 'b'], - device: 'niceDevice', - pushGateway: 'gcm', - uuid: 'myUUID', - }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports channel listing with start and count params', async () => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/coolDevice') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'apns', - uuid: 'myUUID', - start: 'ch1', - count: 10, - }) - .reply(200, '["ch1", "ch2", "ch3"]'); - - var res = await pubnub.push.listChannels( - { device: 'coolDevice', pushGateway: 'apns', start: 'ch1', count: 10 }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); - assert.equal(scope.isDone(), true); - done(); - }, - ); - }); - - it('supports channel listing with(APNS2) start and count params', async () => { - const scope = utils - .createNock() - .get('/v2/push/sub-key/mySubKey/devices-apns2/coolDevice') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - environment: 'production', - topic: 'com.test.apns', - uuid: 'myUUID', - start: 'ch1', - count: 10, - }) - .reply(200, '["ch1", "ch2", "ch3"]'); - pubnub.push.listChannels( - { - device: 'coolDevice', - pushGateway: 'apns2', - environment: 'production', - topic: 'com.test.apns', - start: 'ch1', - count: 10, - }, - (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); - assert.equal(scope.isDone(), true); - done(); - }, - ); - }); - - it('should add push disable for channels API telemetry information', (done) => { - let scope = utils.createNock().get('/v1/push/sub-key/mySubKey/devices/niceDevice').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '[1, "Modified Channels"]', - delays, - (completion) => { - pubnub.push.removeChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_push', average, leeway); - done(); - }); - }).timeout(60000); - - it('should add APNS2 disable for channels API telemetry information', (done) => { - let scope = utils.createNock().get('/v2/push/sub-key/mySubKey/devices-apns2/niceDevice').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '[1, "Modified Channels"]', - delays, - (completion) => { - pubnub.push.removeChannels( - { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns2', topic: 'com.test.apns' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_push', average, leeway); - done(); - }); - }).timeout(60000); - }); - - describe('supports removal of device', () => { - it('supports removal of device for apple', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/niceDevice/remove') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'apns', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.deleteDevice( - { device: 'niceDevice', pushGateway: 'apns' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports removal of device for apple (APNS2)', (done) => { - const scope = utils - .createNock() - .get('/v2/push/sub-key/mySubKey/devices-apns2/niceDevice/remove') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - environment: 'production', - topic: 'com.test.apns', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.deleteDevice( - { device: 'niceDevice', pushGateway: 'apns2', environment: 'production', topic: 'com.test.apns' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports removal of device for microsoft', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/niceDevice/remove') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'mpns', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.deleteDevice( - { device: 'niceDevice', pushGateway: 'mpns' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('supports removal of device for google', (done) => { - const scope = utils - .createNock() - .get('/v1/push/sub-key/mySubKey/devices/niceDevice/remove') - .query({ - pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, - type: 'gcm', - uuid: 'myUUID', - }) - .reply(200, '[1, "Modified Channels"]'); - - pubnub.push.deleteDevice( - { device: 'niceDevice', pushGateway: 'gcm' }, - (status) => { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); - } - ); - }); - - it('should add push disable for device API telemetry information', (done) => { - let scope = utils.createNock().get('/v1/push/sub-key/mySubKey/devices/niceDevice/remove').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '[1, "Modified Channels"]', - delays, - (completion) => { - pubnub.push.deleteDevice( - { device: 'niceDevice', pushGateway: 'apns' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_push', average, leeway); - done(); - }); - }).timeout(60000); - - it('should add APNS2 disable for device API telemetry information', (done) => { - let scope = utils.createNock().get('/v2/push/sub-key/mySubKey/devices-apns2/niceDevice/remove').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '[1, "Modified Channels"]', - delays, - (completion) => { - pubnub.push.deleteDevice( - { device: 'niceDevice', pushGateway: 'apns2', environment: 'production', topic: 'com.test.apns' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_push', average, leeway); - done(); - }); - }).timeout(60000); - }); -}); diff --git a/test/integration/endpoints/push.test.ts b/test/integration/endpoints/push.test.ts new file mode 100644 index 000000000..3cb11089d --- /dev/null +++ b/test/integration/endpoints/push.test.ts @@ -0,0 +1,342 @@ +/* global describe, beforeEach, it, before, after */ +/* eslint no-console: 0 */ + +import assert from 'assert'; +import nock from 'nock'; + +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; + +describe('push endpoints', () => { + let pubnub: PubNub; + + before(() => { + nock.disableNetConnect(); + }); + + after(() => { + nock.enableNetConnect(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + // @ts-expect-error Force override default value. + useRequestId: false, + uuid: 'myUUID', + }); + }); + + describe('adding channels to device', () => { + it('supports addition of multiple channels for apple', (done) => { + const scope = utils + .createNock() + .get('/v1/push/sub-key/mySubKey/devices/niceDevice') + .query({ + add: 'a,b', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + type: 'apns', + uuid: 'myUUID', + }) + .reply(200, '[1, "Modified Channels"]', { 'content-type': 'text/javascript' }); + + pubnub.push.addChannels({ channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns' }, (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports addition of multiple channels for apple (APNS2)', (done) => { + const scope = utils + .createNock() + .get('/v2/push/sub-key/mySubKey/devices-apns2/niceDevice') + .query({ + add: 'a,b', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + environment: 'development', + topic: 'com.test.apns', + type: 'apns2', + uuid: 'myUUID', + }) + .reply(200, '[1, "Modified Channels"]', { 'content-type': 'text/javascript' }); + + pubnub.push.addChannels( + { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns2', topic: 'com.test.apns' }, + (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); + }); + + it('supports addition of multiple channels for google', (done) => { + const scope = utils + .createNock() + .get('/v1/push/sub-key/mySubKey/devices/niceDevice') + .query({ + add: 'a,b', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + type: 'gcm', + uuid: 'myUUID', + }) + .reply(200, '[1, "Modified Channels"]', { 'content-type': 'text/javascript' }); + + pubnub.push.addChannels({ channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'gcm' }, (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + describe('listing channels for device', () => { + it('supports channel listing for apple', (done) => { + const scope = utils + .createNock() + .get('/v1/push/sub-key/mySubKey/devices/coolDevice') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + type: 'apns', + uuid: 'myUUID', + }) + .reply(200, '["ch1", "ch2", "ch3"]', { 'content-type': 'text/javascript' }); + + pubnub.push.listChannels({ device: 'coolDevice', pushGateway: 'apns' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, ["ch1", "ch2", "ch3"]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports channel listing for apple (APNS2)', (done) => { + const scope = utils + .createNock() + .get('/v2/push/sub-key/mySubKey/devices-apns2/coolDevice') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + environment: 'production', + topic: 'com.test.apns', + type: 'apns2', + uuid: 'myUUID', + }) + .reply(200, '["ch1", "ch2", "ch3"]', { 'content-type': 'text/javascript' }); + + pubnub.push.listChannels( + { device: 'coolDevice', pushGateway: 'apns2', environment: 'production', topic: 'com.test.apns' }, + (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, ["ch1", "ch2", "ch3"]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); + }); + + it('supports channel listing for google', (done) => { + const scope = utils + .createNock() + .get('/v1/push/sub-key/mySubKey/devices/coolDevice') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + type: 'gcm', + uuid: 'myUUID', + }) + .reply(200, '["ch1", "ch2", "ch3"]', { 'content-type': 'text/javascript' }); + + pubnub.push.listChannels({ device: 'coolDevice', pushGateway: 'gcm' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.channels, ["ch1", "ch2", "ch3"]); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + describe('supports deletion of channels', () => { + it('supports removal of multiple channels for apple', (done) => { + const scope = utils + .createNock() + .get('/v1/push/sub-key/mySubKey/devices/niceDevice') + .query({ + remove: 'a,b', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + type: 'apns', + uuid: 'myUUID', + }) + .reply(200, '[1, "Modified Channels"]', { 'content-type': 'text/javascript' }); + + pubnub.push.removeChannels({ channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns' }, (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports removal of multiple channels for apple (APNS2)', (done) => { + const scope = utils + .createNock() + .get('/v2/push/sub-key/mySubKey/devices-apns2/niceDevice') + .query({ + remove: 'a,b', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + environment: 'development', + topic: 'com.test.apns', + type: 'apns2', + uuid: 'myUUID', + }) + .reply(200, '[1, "Modified Channels"]', { 'content-type': 'text/javascript' }); + + pubnub.push.removeChannels( + { channels: ['a', 'b'], device: 'niceDevice', pushGateway: 'apns2', topic: 'com.test.apns' }, + (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); + }); + + it('supports removal of multiple channels for google', (done) => { + const scope = utils + .createNock() + .get('/v1/push/sub-key/mySubKey/devices/niceDevice') + .query({ + remove: 'a,b', + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + type: 'gcm', + uuid: 'myUUID', + }) + .reply(200, '[1, "Modified Channels"]', { 'content-type': 'text/javascript' }); + + pubnub.push.removeChannels( + { + channels: ['a', 'b'], + device: 'niceDevice', + pushGateway: 'gcm', + }, + (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); + }); + }); + + describe('supports removal of device', () => { + it('supports removal of device for apple', (done) => { + const scope = utils + .createNock() + .get('/v1/push/sub-key/mySubKey/devices/niceDevice/remove') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + type: 'apns', + uuid: 'myUUID', + }) + .reply(200, '[1, "Modified Channels"]', { 'content-type': 'text/javascript' }); + + pubnub.push.deleteDevice({ device: 'niceDevice', pushGateway: 'apns' }, (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports removal of device for apple (APNS2)', (done) => { + const scope = utils + .createNock() + .get('/v2/push/sub-key/mySubKey/devices-apns2/niceDevice/remove') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + environment: 'production', + topic: 'com.test.apns', + type: 'apns2', + uuid: 'myUUID', + }) + .reply(200, '[1, "Modified Channels"]', { 'content-type': 'text/javascript' }); + + pubnub.push.deleteDevice( + { device: 'niceDevice', pushGateway: 'apns2', environment: 'production', topic: 'com.test.apns' }, + (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); + }); + + it('supports removal of device for google', (done) => { + const scope = utils + .createNock() + .get('/v1/push/sub-key/mySubKey/devices/niceDevice/remove') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + type: 'gcm', + uuid: 'myUUID', + }) + .reply(200, '[1, "Modified Channels"]', { 'content-type': 'text/javascript' }); + + pubnub.push.deleteDevice({ device: 'niceDevice', pushGateway: 'gcm' }, (status) => { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + }); +}); diff --git a/test/integration/endpoints/signal.test.js b/test/integration/endpoints/signal.test.js deleted file mode 100644 index ebc8b213c..000000000 --- a/test/integration/endpoints/signal.test.js +++ /dev/null @@ -1,80 +0,0 @@ -/* global describe, beforeEach, it, before, after */ -/* eslint no-console: 0 */ - -import assert from 'assert'; -import nock from 'nock'; -import utils from '../../utils'; -import PubNub from '../../../src/node/index'; - -describe('signal endpoints', () => { - let pubnub; - - before(() => { - nock.disableNetConnect(); - }); - - after(() => { - nock.enableNetConnect(); - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - subscribeKey: 'mySubKey', - publishKey: 'myPublishKey', - uuid: 'myUUID', - authKey: 'myAuthKey', - }); - }); - - describe('##validation', () => { - it('fails if channel is missing', (done) => { - const scope = utils - .createNock() - .get('/signal/*') - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.signal({ message: { such: 'object' } }).catch((err) => { - assert.equal(scope.isDone(), false); - assert.equal(err.status.message, 'Missing Channel'); - done(); - }); - }); - }); - - it('publishes a complex object via GET', (done) => { - const scope = utils.createNock().get('/signal/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') - .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', auth: 'myAuthKey' }) - .reply(200, '[1,"Sent","14647523059145592"]'); - - pubnub.signal({ message: { such: 'object' }, channel: 'ch1' }, (status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14647523059145592); - assert.equal(scope.isDone(), true); - done(); - }); - }); - - it('should add signal API telemetry information', (done) => { - let scope = utils.createNock().get('/signal/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - '[1,"Sent","14647523059145592"]', - delays, - (completion) => { - pubnub.signal( - { message: { such: 'object' }, channel: 'ch1' }, - () => { completion(); } - ); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_sig', average, leeway); - done(); - }); - }).timeout(60000); -}); diff --git a/test/integration/endpoints/signal.test.ts b/test/integration/endpoints/signal.test.ts new file mode 100644 index 000000000..4aca88ebe --- /dev/null +++ b/test/integration/endpoints/signal.test.ts @@ -0,0 +1,72 @@ +/* global describe, beforeEach, it, before, after */ +/* eslint no-console: 0 */ + +import assert from 'assert'; +import nock from 'nock'; + +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; + +describe('signal endpoints', () => { + let pubnub: PubNub; + + before(() => { + nock.disableNetConnect(); + }); + + after(() => { + nock.enableNetConnect(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, + authKey: 'myAuthKey', + }); + }); + + describe('##validation', () => { + it('fails if channel is missing', (done) => { + const scope = utils + .createNock() + .get('/signal/*') + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + // @ts-expect-error Intentionally don't include `channel`. + pubnub.signal({ message: { such: 'object' } }).catch((err) => { + try { + assert.equal(scope.isDone(), false); + assert.equal(err.status.message, "Missing 'channel'"); + done(); + } catch (error) { + done(error); + } + }); + }); + }); + + it('publishes a complex object via GET', (done) => { + const scope = utils + .createNock() + .get('/signal/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') + .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', auth: 'myAuthKey' }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.signal({ message: { such: 'object' }, channel: 'ch1' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14647523059145592"); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); +}); diff --git a/test/integration/endpoints/subscribe.test.js b/test/integration/endpoints/subscribe.test.ts similarity index 57% rename from test/integration/endpoints/subscribe.test.js rename to test/integration/endpoints/subscribe.test.ts index 5949d722d..9e4c6bd2f 100644 --- a/test/integration/endpoints/subscribe.test.js +++ b/test/integration/endpoints/subscribe.test.ts @@ -3,12 +3,13 @@ import assert from 'assert'; import nock from 'nock'; -import utils from '../../utils'; + import PubNub from '../../../src/node/index'; +import utils from '../../utils'; describe('subscribe endpoints', () => { - let pubnub; - let pubnubWithFiltering; + let pubnubWithFiltering: PubNub; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); @@ -24,12 +25,16 @@ describe('subscribe endpoints', () => { subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, autoNetworkDetection: false, }); pubnubWithFiltering = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, filterExpression: 'hello!', autoNetworkDetection: false, }); @@ -43,7 +48,7 @@ describe('subscribe endpoints', () => { it('supports addition of multiple channels', (done) => { const scope = utils .createNock() - .get('/v2/subscribe/mySubKey/coolChannel%2CcoolChannel2/0') + .get('/v2/subscribe/mySubKey/coolChannel,coolChannel2/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -51,24 +56,23 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); pubnub.addListener({ status(status) { if (status.category === 'PNConnectedCategory') { - assert.equal(scope.isDone(), true); - assert.deepEqual(pubnub.getSubscribedChannels(), [ - 'coolChannel', - 'coolChannel2', - ]); - assert.deepEqual(pubnub.getSubscribedChannelGroups(), []); - assert.deepEqual(status.affectedChannels, [ - 'coolChannel', - 'coolChannel2', - ]); - assert.deepEqual(status.affectedChannelGroups, []); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual(pubnub.getSubscribedChannels(), ["coolChannel", "coolChannel2"]); + assert.deepEqual(pubnub.getSubscribedChannelGroups(), []); + assert.deepEqual(status.affectedChannels, ["coolChannel", "coolChannel2"]); + assert.deepEqual(status.affectedChannelGroups, []); + done(); + } catch (error) { + done(error); + } } }, }); @@ -79,7 +83,7 @@ describe('subscribe endpoints', () => { it('supports addition of multiple channels / channel groups', (done) => { const scope = utils .createNock() - .get('/v2/subscribe/mySubKey/coolChannel%2CcoolChannel2/0') + .get('/v2/subscribe/mySubKey/coolChannel,coolChannel2/0') .query({ 'channel-group': 'cg1,cg2', pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, @@ -88,24 +92,23 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); pubnub.addListener({ status(status) { if (status.category === 'PNConnectedCategory') { - assert.equal(scope.isDone(), true); - assert.deepEqual(pubnub.getSubscribedChannels(), [ - 'coolChannel', - 'coolChannel2', - ]); - assert.deepEqual(pubnub.getSubscribedChannelGroups(), ['cg1', 'cg2']); - assert.deepEqual(status.affectedChannels, [ - 'coolChannel', - 'coolChannel2', - ]); - assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual(pubnub.getSubscribedChannels(), ["coolChannel", "coolChannel2"]); + assert.deepEqual(pubnub.getSubscribedChannelGroups(), ["cg1", "cg2"]); + assert.deepEqual(status.affectedChannels, ["coolChannel", "coolChannel2"]); + assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]); + done(); + } catch (error) { + done(error); + } } }, }); @@ -119,7 +122,7 @@ describe('subscribe endpoints', () => { it('supports just channel group', (done) => { const scope = utils .createNock() - .get('/v2/subscribe/mySubKey/%2C/0') + .get('/v2/subscribe/mySubKey/,/0') .query({ 'channel-group': 'cg1,cg2', pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, @@ -128,18 +131,23 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); pubnub.addListener({ status(status) { if (status.category === 'PNConnectedCategory') { - assert.equal(scope.isDone(), true); - assert.deepEqual(pubnub.getSubscribedChannels(), []); - assert.deepEqual(pubnub.getSubscribedChannelGroups(), ['cg1', 'cg2']); - assert.deepEqual(status.affectedChannels, []); - assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual(pubnub.getSubscribedChannels(), []); + assert.deepEqual(pubnub.getSubscribedChannelGroups(), ["cg1", "cg2"]); + assert.deepEqual(status.affectedChannels, []); + assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]); + done(); + } catch (error) { + done(error); + } } }, }); @@ -150,7 +158,7 @@ describe('subscribe endpoints', () => { it('supports filter expression', (done) => { const scope = utils .createNock() - .get('/v2/subscribe/mySubKey/coolChannel%2CcoolChannel2/0') + .get('/v2/subscribe/mySubKey/coolChannel,coolChannel2/0') .query({ 'filter-expr': 'hello!', pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, @@ -159,27 +167,23 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ); pubnubWithFiltering.addListener({ status(status) { if (status.category === 'PNConnectedCategory') { - assert.equal(scope.isDone(), true); - assert.deepEqual(pubnubWithFiltering.getSubscribedChannels(), [ - 'coolChannel', - 'coolChannel2', - ]); - assert.deepEqual( - pubnubWithFiltering.getSubscribedChannelGroups(), - [] - ); - assert.deepEqual(status.affectedChannels, [ - 'coolChannel', - 'coolChannel2', - ]); - assert.deepEqual(status.affectedChannelGroups, []); - done(); + try { + assert.equal(scope.isDone(), true); + assert.deepEqual(pubnubWithFiltering.getSubscribedChannels(), ["coolChannel", "coolChannel2"]); + assert.deepEqual(pubnubWithFiltering.getSubscribedChannelGroups(), []); + assert.deepEqual(status.affectedChannels, ["coolChannel", "coolChannel2"]); + assert.deepEqual(status.affectedChannelGroups, []); + done(); + } catch (error) { + done(error); + } } }, }); diff --git a/test/integration/endpoints/time.test.js b/test/integration/endpoints/time.test.js deleted file mode 100644 index f5dafc402..000000000 --- a/test/integration/endpoints/time.test.js +++ /dev/null @@ -1,106 +0,0 @@ -/* global describe, beforeEach, it, before, after */ -/* eslint no-console: 0 */ - -import assert from 'assert'; -import nock from 'nock'; -import utils from '../../utils'; -import PubNub from '../../../src/node/index'; - -describe('time endpoints', () => { - let pubnub; - - before(() => { - nock.disableNetConnect(); - }); - - after(() => { - nock.enableNetConnect(); - }); - - beforeEach(() => { - nock.cleanAll(); - pubnub = new PubNub({ - uuid: 'myUUID', - keepAlive: true, - }); - }); - - it('calls the callback function when time is fetched', (done) => { - utils - .createNock() - .get('/time/0') - .query(true) - .reply(200, [14570763868573725]); - - pubnub.time((status, response) => { - assert.equal(status.error, false); - assert.deepEqual(response.timetoken, 14570763868573725); - done(); - }); - }); - - it('calls the callback function when time is fetched via promise', (done) => { - utils - .createNock() - .get('/time/0') - .query(true) - .reply(200, [14570763868573725]); - - pubnub.time().then((response) => { - assert.deepEqual(response.timetoken, 14570763868573725); - done(); - }); - }); - - it('calls the callback function when fetch failed', (done) => { - utils - .createNock() - .get('/time/0') - .query(true) - .reply(500, null); - - pubnub.time((status, response) => { - assert.equal(response, null); - assert.equal(status.error, true); - done(); - }); - }); - - it('calls the callback function when fetch failed', (done) => { - utils - .createNock() - .get('/time/0') - .query(true) - .reply(500, null); - - pubnub.time().catch((ex) => { - assert(ex instanceof Error); - assert.equal(ex.message, 'PubNub call failed, check status for details'); - assert.equal(ex.status.error, true); - assert.equal(ex.status.statusCode, 500); - done(); - }); - }); - - it('should add time API telemetry information', (done) => { - let scope = utils.createNock().get('/time/0').query(true); - const delays = [100, 200, 300, 400]; - const countedDelays = delays.slice(0, delays.length - 1); - const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); - const leeway = 50; - - utils.runAPIWithResponseDelays(scope, - 200, - [14570763868573725], - delays, - (completion) => { - pubnub.time(() => { - completion(); - }); - }) - .then((lastRequest) => { - utils.verifyRequestTelemetry(lastRequest.path, 'l_time', average, leeway); - done(); - }); - }).timeout(60000); -}); diff --git a/test/integration/endpoints/time.test.ts b/test/integration/endpoints/time.test.ts new file mode 100644 index 000000000..1b71fa05e --- /dev/null +++ b/test/integration/endpoints/time.test.ts @@ -0,0 +1,89 @@ +/* global describe, beforeEach, it, before, after */ +/* eslint no-console: 0 */ + +import assert from 'assert'; +import nock from 'nock'; + +import { PubNubError } from '../../../src/errors/pubnub-error'; +import PubNub from '../../../src/node/index'; +import utils from '../../utils'; + +describe('time endpoints', () => { + let pubnub: PubNub; + + before(() => { + nock.disableNetConnect(); + }); + + after(() => { + nock.enableNetConnect(); + }); + + beforeEach(() => { + nock.cleanAll(); + pubnub = new PubNub({ + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, + keepAlive: true, + }); + }); + + it('calls the callback function when time is fetched', (done) => { + utils.createNock().get('/time/0').query(true).reply(200, ['14570763868573725']); + + pubnub.time((status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, "14570763868573725"); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('calls the callback function when time is fetched via promise', (done) => { + utils.createNock().get('/time/0').query(true).reply(200, ['14570763868573725']); + + pubnub.time().then((response) => { + try { + assert.deepEqual(response.timetoken, '14570763868573725'); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('calls the callback function when fetch failed', (done) => { + utils.createNock().get('/time/0').query(true).reply(500, undefined); + + pubnub.time((status, response) => { + try { + assert.equal(response, null); + assert.equal(status.error, true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('calls the callback function when fetch failed', (done) => { + utils.createNock().get('/time/0').query(true).reply(500, undefined); + + pubnub.time().catch((ex) => { + try { + assert(ex instanceof PubNubError); + assert.equal(ex.message, "REST API request processing error, check status for details"); + assert.equal(ex.status!.error, true); + assert.equal(ex.status!.statusCode, 500); + done(); + } catch (error) { + done(error); + } + }); + }); +}); diff --git a/test/integration/operations/heartbeat.test.js b/test/integration/operations/heartbeat.test.ts similarity index 68% rename from test/integration/operations/heartbeat.test.js rename to test/integration/operations/heartbeat.test.ts index dae373613..1a9939b66 100644 --- a/test/integration/operations/heartbeat.test.js +++ b/test/integration/operations/heartbeat.test.ts @@ -1,13 +1,15 @@ /* global describe, beforeEach, it, before, afterEach, after */ /* eslint no-console: 0 */ +import { expect } from 'chai'; import assert from 'assert'; import nock from 'nock'; -import utils from '../../utils'; + import PubNub from '../../../src/node/index'; +import utils from '../../utils'; describe('heartbeat', () => { - let pubnub; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); @@ -23,8 +25,10 @@ describe('heartbeat', () => { subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', uuid: 'myUUID', - heartbeatInterval :1, // for quick test of heartbeat calls + // @ts-expect-error This configuration option normally is hidden. + useRequestId: false, announceSuccessfulHeartbeats: true, + heartbeatInterval: 1, // for quick test of heartbeat calls }); }); @@ -39,22 +43,25 @@ describe('heartbeat', () => { subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', uuid: 'myUUID', + // @ts-expect-error This configuration option normally is hidden. announceSuccessfulHeartbeats: true, }); const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/heartbeat') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/heartbeat') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: '300', state: '{}', }) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.subscribe({ channels: ['ch1', 'ch2'], withHeartbeats: true }); await expect(scope).to.have.not.been.requested; }); - + it('supports heartbeating for one channel', (done) => { const scope = utils .createNock() @@ -65,14 +72,20 @@ describe('heartbeat', () => { heartbeat: '300', state: '{}', }) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.addListener({ status(status) { if (status.operation === 'PNHeartbeatOperation' && !status.error) { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } } }, }); @@ -83,21 +96,27 @@ describe('heartbeat', () => { it('supports heartbeating for multiple channels', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/heartbeat') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/heartbeat') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', heartbeat: '300', state: '{}', }) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.addListener({ status(status) { if (status.operation === 'PNHeartbeatOperation' && !status.error) { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } } }, }); @@ -108,7 +127,7 @@ describe('heartbeat', () => { it('supports heartbeating for one channel group', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/heartbeat') + .get('/v2/presence/sub-key/mySubscribeKey/channel/,/heartbeat') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -116,14 +135,20 @@ describe('heartbeat', () => { state: '{}', 'channel-group': 'cg1', }) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.addListener({ status(status) { if (status.operation === 'PNHeartbeatOperation' && !status.error) { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } } }, }); @@ -134,7 +159,7 @@ describe('heartbeat', () => { it('supports heartbeating for multiple channel group', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/heartbeat') + .get('/v2/presence/sub-key/mySubscribeKey/channel/,/heartbeat') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -142,14 +167,20 @@ describe('heartbeat', () => { state: '{}', 'channel-group': 'cg1,cg2', }) - .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { + 'content-type': 'text/javascript', + }); pubnub.addListener({ status(status) { if (status.operation === 'PNHeartbeatOperation' && !status.error) { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - done(); + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } } }, }); diff --git a/test/integration/operations/stateSetting.test.js b/test/integration/operations/stateSetting.test.ts similarity index 62% rename from test/integration/operations/stateSetting.test.js rename to test/integration/operations/stateSetting.test.ts index 32e468bd0..ced3d0e7e 100644 --- a/test/integration/operations/stateSetting.test.js +++ b/test/integration/operations/stateSetting.test.ts @@ -3,11 +3,12 @@ import assert from 'assert'; import nock from 'nock'; -import utils from '../../utils'; + import PubNub from '../../../src/node/index'; +import utils from '../../utils'; describe('setting state operation', () => { - let pubnub; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); @@ -23,18 +24,21 @@ describe('setting state operation', () => { subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, }); }); describe('#setState', () => { it('fails if no channels are provided', (done) => { pubnub.setState({ state: { hello: 'there' } }, (status) => { - assert.equal(status.error, true); - assert.equal( - status.message, - 'Please provide a list of channels and/or channel-groups' - ); - done(); + try { + assert.equal(status.error, true); + assert.equal(status.message, "Please provide a list of channels and/or channel-groups"); + done(); + } catch (error) { + done(error); + } }); }); @@ -49,26 +53,27 @@ describe('setting state operation', () => { }) .reply( 200, - '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}' + '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); - pubnub.setState( - { channels: ['ch1'], state: { hello: 'there' } }, - (status, response) => { + pubnub.setState({ channels: ['ch1'], state: { hello: 'there' } }, (status, response) => { + try { assert.equal(status.error, false); - assert.deepEqual(response.state, { age: 20, status: 'online' }); + assert(response !== null); + assert.deepEqual(response.state, { age: 20, status: "online" }); assert.equal(scope.isDone(), true); done(); + } catch (error) { + done(error); } - ); + }); }); it('supports updating for multiple channels', (done) => { const scope = utils .createNock() - .get( - '/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/uuid/myUUID/data' - ) + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/uuid/myUUID/data') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -76,24 +81,27 @@ describe('setting state operation', () => { }) .reply( 200, - '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}' + '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); - pubnub.setState( - { channels: ['ch1', 'ch2'], state: { hello: 'there' } }, - (status, response) => { + pubnub.setState({ channels: ['ch1', 'ch2'], state: { hello: 'there' } }, (status, response) => { + try { assert.equal(status.error, false); - assert.deepEqual(response.state, { age: 20, status: 'online' }); + assert(response !== null); + assert.deepEqual(response.state, { age: 20, status: "online" }); assert.equal(scope.isDone(), true); done(); + } catch (error) { + done(error); } - ); + }); }); it('supports updating for one channel group', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/uuid/myUUID/data') + .get('/v2/presence/sub-key/mySubscribeKey/channel/,/uuid/myUUID/data') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -102,24 +110,27 @@ describe('setting state operation', () => { }) .reply( 200, - '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}' + '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); - pubnub.setState( - { channelGroups: ['cg1'], state: { hello: 'there' } }, - (status, response) => { + pubnub.setState({ channelGroups: ['cg1'], state: { hello: 'there' } }, (status, response) => { + try { assert.equal(status.error, false); - assert.deepEqual(response.state, { age: 20, status: 'online' }); + assert(response !== null); + assert.deepEqual(response.state, { age: 20, status: "online" }); assert.equal(scope.isDone(), true); done(); + } catch (error) { + done(error); } - ); + }); }); it('supports updating for multiple channel group', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/uuid/myUUID/data') + .get('/v2/presence/sub-key/mySubscribeKey/channel/,/uuid/myUUID/data') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -128,18 +139,21 @@ describe('setting state operation', () => { }) .reply( 200, - '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}' + '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); - pubnub.setState( - { channelGroups: ['cg1', 'cg2'], state: { hello: 'there' } }, - (status, response) => { + pubnub.setState({ channelGroups: ['cg1', 'cg2'], state: { hello: 'there' } }, (status, response) => { + try { assert.equal(status.error, false); - assert.deepEqual(response.state, { age: 20, status: 'online' }); + assert(response !== null); + assert.deepEqual(response.state, { age: 20, status: "online" }); assert.equal(scope.isDone(), true); done(); + } catch (error) { + done(error); } - ); + }); }); it('supports promises', (done) => { @@ -153,7 +167,8 @@ describe('setting state operation', () => { }) .reply( 200, - '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}' + '{ "status": 200, "message": "OK", "payload": { "age" : 20, "status" : "online" }, "service": "Presence"}', + { 'content-type': 'text/javascript' }, ); let promise = pubnub.setState({ diff --git a/test/integration/operations/unsubscribe.test.js b/test/integration/operations/unsubscribe.test.ts similarity index 59% rename from test/integration/operations/unsubscribe.test.js rename to test/integration/operations/unsubscribe.test.ts index f866096f9..c4c5de053 100644 --- a/test/integration/operations/unsubscribe.test.js +++ b/test/integration/operations/unsubscribe.test.ts @@ -3,11 +3,12 @@ import assert from 'assert'; import nock from 'nock'; -import utils from '../../utils'; + import PubNub from '../../../src/node/index'; +import utils from '../../utils'; describe('unsubscribe', () => { - let pubnub; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); @@ -23,6 +24,8 @@ describe('unsubscribe', () => { subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, }); pubnub.setHeartbeatInterval(0); }); @@ -44,36 +47,39 @@ describe('unsubscribe', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ) .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1/leave') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', }) - .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnub.addListener({ status(status) { - if (status.category !== 'PNConnectedCategory') { - console.log('status', JSON.stringify(status )) - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, ['ch1']); - assert.deepEqual(status.affectedChannelGroups, []); - done(); - } + if (status.category !== PubNub.CATEGORIES.PNConnectedCategory) { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + assert.deepEqual(status.affectedChannels, ["ch1"]); + assert.deepEqual(status.affectedChannelGroups, []); + done(); + } catch (error) { + done(error); + } + } else pubnub.unsubscribe({ channels: ['ch1'] }); }, }); pubnub.subscribe({ channels: ['ch1'] }); - pubnub.unsubscribe({ channels: ['ch1'] }); }); it('supports leaving for multiple channels', (done) => { const scope = utils .createNock() - .get('/v2/subscribe/mySubscribeKey/ch1%2Cch2/0') + .get('/v2/subscribe/mySubscribeKey/ch1,ch2/0') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -81,35 +87,39 @@ describe('unsubscribe', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ) - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/leave') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/leave') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', }) - .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnub.addListener({ status(status) { - if (status.category !== 'PNConnectedCategory') { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, ['ch1', 'ch2']); - assert.deepEqual(status.affectedChannelGroups, []); - done(); - } + if (status.category !== PubNub.CATEGORIES.PNConnectedCategory) { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + assert.deepEqual(status.affectedChannels, ["ch1", "ch2"]); + assert.deepEqual(status.affectedChannelGroups, []); + done(); + } catch (error) { + done(error); + } + } else pubnub.unsubscribe({ channels: ['ch1', 'ch2'] }); }, }); pubnub.subscribe({ channels: ['ch1', 'ch2'] }); - pubnub.unsubscribe({ channels: ['ch1', 'ch2'] }); }); it('supports leaving for one channel group', (done) => { const scope = utils .createNock() - .get('/v2/subscribe/mySubscribeKey/%2C/0') + .get('/v2/subscribe/mySubscribeKey/,/0') .query({ 'channel-group': 'cg1', pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, @@ -118,36 +128,40 @@ describe('unsubscribe', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ) - .get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/leave') + .get('/v2/presence/sub-key/mySubscribeKey/channel/,/leave') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', 'channel-group': 'cg1', }) - .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnub.addListener({ status(status) { - if (status.category !== 'PNConnectedCategory') { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, []); - assert.deepEqual(status.affectedChannelGroups, ['cg1']); - done(); - } + if (status.category !== PubNub.CATEGORIES.PNConnectedCategory) { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + assert.deepEqual(status.affectedChannels, []); + assert.deepEqual(status.affectedChannelGroups, ["cg1"]); + done(); + } catch (error) { + done(error); + } + } else pubnub.unsubscribe({ channelGroups: ['cg1'] }); }, }); pubnub.subscribe({ channelGroups: ['cg1'] }); - pubnub.unsubscribe({ channelGroups: ['cg1'] }); }); it('supports leaving for multiple channel group', (done) => { const scope = utils .createNock() - .get('/v2/subscribe/mySubscribeKey/%2C/0') + .get('/v2/subscribe/mySubscribeKey/,/0') .query({ 'channel-group': 'cg1,cg2', pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, @@ -156,30 +170,34 @@ describe('unsubscribe', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}' + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, ) - .get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/leave') + .get('/v2/presence/sub-key/mySubscribeKey/channel/,/leave') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', 'channel-group': 'cg1,cg2', }) - .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnub.addListener({ status(status) { - if (status.category !== 'PNConnectedCategory') { - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, []); - assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']); - done(); - } + if (status.category !== PubNub.CATEGORIES.PNConnectedCategory) { + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + assert.deepEqual(status.affectedChannels, []); + assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]); + done(); + } catch (error) { + done(error); + } + } else pubnub.unsubscribe({ channelGroups: ['cg1', 'cg2'] }); }, }); pubnub.subscribe({ channelGroups: ['cg1', 'cg2'] }); - pubnub.unsubscribe({ channelGroups: ['cg1', 'cg2'] }); }); it('supports partial leaving for channels', (done) => { @@ -190,47 +208,60 @@ describe('unsubscribe', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', }) - .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnub.addListener({ status(status) { - if (status.operation !== 'PNUnsubscribeOperation') return; - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, ['ch1']); - assert.deepEqual(status.affectedChannelGroups, []); - done(); + if (status.operation !== PubNub.OPERATIONS.PNUnsubscribeOperation) { + pubnub.unsubscribe({ channels: ['ch1', 'ch3'] }); + return; + } + + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + assert.deepEqual(status.affectedChannels, ["ch1"]); + assert.deepEqual(status.affectedChannelGroups, []); + done(); + } catch (error) { + done(error); + } }, }); pubnub.subscribe({ channels: ['ch1', 'ch2'] }); - pubnub.unsubscribe({ channels: ['ch1', 'ch3'] }); }); it('supports partial leaving for channel groups', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/%2C/leave') + .get('/v2/presence/sub-key/mySubscribeKey/channel/,/leave') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', 'channel-group': 'cg1', }) - .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnub.addListener({ status(status) { - if (status.operation !== 'PNUnsubscribeOperation') return; - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, []); - assert.deepEqual(status.affectedChannelGroups, ['cg1']); - done(); + if (status.operation !== PubNub.OPERATIONS.PNUnsubscribeOperation) { + pubnub.unsubscribe({ channelGroups: ['cg1', 'cg3'] }); + return; + } + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + assert.deepEqual(status.affectedChannels, []); + assert.deepEqual(status.affectedChannelGroups, ["cg1"]); + done(); + } catch (error) { + done(error); + } }, }); pubnub.subscribe({ channelGroups: ['cg1', 'cg2'] }); - pubnub.unsubscribe({ channelGroups: ['cg1', 'cg3'] }); }); }); @@ -238,22 +269,26 @@ describe('unsubscribe', () => { it('supports leaving channels / channel groups', (done) => { const scope = utils .createNock() - .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1%2Cch2/leave') + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/leave') .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', 'channel-group': 'cg1,cg2', }) - .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}'); + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); pubnub.addListener({ status(status) { - if (status.operation !== 'PNUnsubscribeOperation') return; - assert.equal(status.error, false); - assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, ['ch1', 'ch2']); - assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']); - done(); + if (status.operation !== PubNub.OPERATIONS.PNUnsubscribeOperation) return; + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + assert.deepEqual(status.affectedChannels, ["ch1", "ch2"]); + assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]); + done(); + } catch (error) { + done(error); + } }, }); diff --git a/test/old_contract/world.ts b/test/old_contract/world.ts index 79a4577c5..e5c311258 100644 --- a/test/old_contract/world.ts +++ b/test/old_contract/world.ts @@ -39,13 +39,13 @@ class PubnubWorld extends World { subscribeKey: 'demo', }, accessManagerKeyset: { - publishKey: process.env.PUBLISH_KEY_ACCESS || 'pub-key', - subscribeKey: process.env.SUBSCRIBE_KEY_ACCESS || 'sub-key', - secretKey: process.env.SECRET_KEY_ACCESS || 'secret-key', + publishKey: process.env.PAM_PUBLISH_KEY || 'pub-key', + subscribeKey: process.env.PAM_SUBSCRIBE_KEY || 'sub-key', + secretKey: process.env.PAM_SECRET_KEY || 'secret-key', }, accessManagerWithoutSecretKeyKeyset: { - publishKey: process.env.PUBLISH_KEY_ACCESS || 'pub-key', - subscribeKey: process.env.SUBSCRIBE_KEY_ACCESS || 'sub-key', + publishKey: process.env.PAM_PUBLISH_KEY || 'pub-key', + subscribeKey: process.env.PAM_SUBSCRIBE_KEY || 'sub-key', }, tokenWithKnownAuthorizedUUID: 'qEF2AkF0GmEI03xDdHRsGDxDcmVzpURjaGFuoWljaGFubmVsLTEY70NncnChb2NoYW5uZWxfZ3JvdXAtMQVDdXNyoENzcGOgRHV1aWShZnV1aWQtMRhoQ3BhdKVEY2hhbqFtXmNoYW5uZWwtXFMqJBjvQ2dycKF0XjpjaGFubmVsX2dyb3VwLVxTKiQFQ3VzcqBDc3BjoER1dWlkoWpedXVpZC1cUyokGGhEbWV0YaBEdXVpZHR0ZXN0LWF1dGhvcml6ZWQtdXVpZENzaWdYIPpU-vCe9rkpYs87YUrFNWkyNq8CVvmKwEjVinnDrJJc', diff --git a/test/release/release.test.js b/test/release/release.test.ts similarity index 100% rename from test/release/release.test.js rename to test/release/release.test.ts diff --git a/test/setup.js b/test/setup.js deleted file mode 100644 index 1ab47da44..000000000 --- a/test/setup.js +++ /dev/null @@ -1,10 +0,0 @@ -const chai = require('chai'); -const chaiAsPromised = require('chai-as-promised'); -const chaiNock = require('chai-nock'); - -chai.use(chaiAsPromised); -chai.use(chaiNock); - -process.env.NODE_ENV = 'test'; - -global.expect = chai.expect; diff --git a/test/setup.ts b/test/setup.ts new file mode 100644 index 000000000..785f3b3d3 --- /dev/null +++ b/test/setup.ts @@ -0,0 +1,8 @@ +import chaiAsPromised from 'chai-as-promised'; +import chaiNock from 'chai-nock'; +import chai from 'chai'; + +chai.use(chaiAsPromised); +chai.use(chaiNock); + +process.env.NODE_ENV = 'test'; diff --git a/test/unit/base64.test.ts b/test/unit/base64.test.ts index e3daf4357..185358e50 100644 --- a/test/unit/base64.test.ts +++ b/test/unit/base64.test.ts @@ -1,8 +1,8 @@ -import { decode } from '../../src/core/components/base64_codec'; - import assert from 'assert'; -function assertBufferEqual(actual, expected) { +import { decode } from '../../src/core/components/base64_codec'; + +function assertBufferEqual(actual: ArrayBuffer, expected: number[]) { assert.deepStrictEqual(new Uint8Array(actual), Uint8Array.from(expected)); } diff --git a/test/unit/cbor.test.js b/test/unit/cbor.test.ts similarity index 84% rename from test/unit/cbor.test.js rename to test/unit/cbor.test.ts index 46eeeb758..67b3cd273 100644 --- a/test/unit/cbor.test.js +++ b/test/unit/cbor.test.ts @@ -1,14 +1,15 @@ /* global describe, it */ -import assert from 'assert'; import CborReader from 'cbor-sync'; +import assert from 'assert'; import Cbor from '../../src/cbor/common'; describe('cbor', () => { it('should decode token', () => { - const cbor = new Cbor(CborReader.decode, (base64String) => new Buffer.from(base64String, 'base64')); - let token = 'p0F2AkF0Gl043rhDdHRsCkNyZXOkRGNoYW6hZnNlY3JldAFDZ3JwoEN1c3KgQ3NwY6BDcGF0pERjaGFuoENncnCgQ3VzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI-blahPGD9TuKlaW1YQgiB4uR_edmfq-61'; + const cbor = new Cbor(CborReader.decode, (base64String: string) => Buffer.from(base64String, 'base64')); + let token = + 'p0F2AkF0Gl043rhDdHRsCkNyZXOkRGNoYW6hZnNlY3JldAFDZ3JwoEN1c3KgQ3NwY6BDcGF0pERjaGFuoENncnCgQ3VzcqBDc3BjoERtZXRhoENzaWdYIGOAeTyWGJI-blahPGD9TuKlaW1YQgiB4uR_edmfq-61'; let decodedToken = cbor.decodeToken(token); diff --git a/test/unit/common.test.js b/test/unit/common.test.ts similarity index 64% rename from test/unit/common.test.js rename to test/unit/common.test.ts index 901fe5d3a..63bd5f567 100644 --- a/test/unit/common.test.js +++ b/test/unit/common.test.ts @@ -1,37 +1,44 @@ /* global describe, it */ -import assert from 'assert'; import lilUUID from 'lil-uuid'; -import PubNub from '../../src/node/index'; +import assert from 'assert'; + import CryptoJS from '../../src/core/components/cryptography/hmac-sha256'; +import { Payload } from '../../src/core/types/api'; +import PubNub from '../../src/node/index'; describe('#core / mounting point', () => { it('should have default heartbeat interval undefined', () => { - let pn = new PubNub({ uuid: 'myUUID' }); + let pn = new PubNub({ subscribeKey: 'demo', uuid: 'myUUID' }); + // @ts-expect-error Intentional access to the private configuration fields. assert(pn._config.getHeartbeatInterval() === undefined); }); it('should have correct heartbeat interval set when reducing presence timeout', () => { - let pn = new PubNub({ uuid: 'myUUID' }); + let pn = new PubNub({ subscribeKey: 'demo', uuid: 'myUUID' }); let presenceTimeout = 200; let expectedHeartBeat = presenceTimeout / 2 - 1; + + // @ts-expect-error Intentional access to the private configuration fields. pn._config.setPresenceTimeout(presenceTimeout); + // @ts-expect-error Intentional access to the private configuration fields. assert(pn._config.getHeartbeatInterval() === expectedHeartBeat); }); it('should support multiple pnsdk suffix', () => { - let pn = new PubNub({ uuid: 'myUUID' }); + let pn = new PubNub({ subscribeKey: 'demo', uuid: 'myUUID' }); let suffix1 = 'suffix1/0.1'; let suffix2 = 'suffix2/0.2'; pn._addPnsdkSuffix('a', suffix1); pn._addPnsdkSuffix('b', suffix2); + // @ts-expect-error Intentional access to the private configuration fields. assert(pn._config._getPnsdkSuffix(' ') === ' suffix1/0.1 suffix2/0.2'); }); it('should replace duplicate pnsdk suffix by name', () => { - let pn = new PubNub({ uuid: 'myUUID' }); + let pn = new PubNub({ subscribeKey: 'demo', uuid: 'myUUID' }); let suffix1 = 'suffix1/0.1'; let suffix2 = 'suffix2/0.2'; let suffix3 = 'suffix3/0.3'; @@ -40,11 +47,13 @@ describe('#core / mounting point', () => { pn._addPnsdkSuffix('b', suffix2); pn._addPnsdkSuffix('a', suffix3); // duplicate name should replace + // @ts-expect-error Intentional access to the private configuration fields. assert(pn._config._getPnsdkSuffix(' ') === ' suffix3/0.3 suffix2/0.2'); }); it('should default to empty pnsdk suffix', () => { - let pn = new PubNub({ uuid: 'myUUID' }); + let pn = new PubNub({ subscribeKey: 'demo', uuid: 'myUUID' }); + // @ts-expect-error Intentional access to the private configuration fields. assert(pn._config._getPnsdkSuffix(' ') === ''); }); @@ -53,12 +62,21 @@ describe('#core / mounting point', () => { }); it('supports encryption with static IV', () => { - let pn = new PubNub({ cipherKey: 'customKey', useRandomIVs: false, uuid: 'myUUID' }); + let pn = new PubNub({ + subscribeKey: 'demo', + cipherKey: 'customKey', + useRandomIVs: false, + uuid: 'myUUID', + }); assert.equal(pn.encrypt(JSON.stringify({ hi: 'there' })), 'TejX6F2JNqH/gIiGHWN4Cw=='); }); it('supports encryption with random IV', () => { - let pn = new PubNub({ cipherKey: 'customKey', uuid: 'myUUID' }); + let pn = new PubNub({ + subscribeKey: 'demo', + cipherKey: 'customKey', + uuid: 'myUUID', + }); const data1 = pn.encrypt(JSON.stringify({ hi: 'there' })); const data2 = pn.encrypt(JSON.stringify({ hi: 'there' })); @@ -67,12 +85,16 @@ describe('#core / mounting point', () => { }); it('supports encryption with custom key and static IV', () => { - let pn = new PubNub({ useRandomIVs: false, uuid: 'myUUID' }); + let pn = new PubNub({ + subscribeKey: 'demo', + useRandomIVs: false, + uuid: 'myUUID', + }); assert.equal(pn.encrypt(JSON.stringify({ hi: 'there' }), 'customKey'), 'TejX6F2JNqH/gIiGHWN4Cw=='); }); it('supports encryption with custom key and random IV', () => { - let pn = new PubNub({ uuid: 'myUUID' }); + let pn = new PubNub({ subscribeKey: 'demo', uuid: 'myUUID' }); const data1 = pn.encrypt(JSON.stringify({ hi: 'there' }), 'customKey'); const data2 = pn.encrypt(JSON.stringify({ hi: 'there' }), 'customKey'); @@ -81,12 +103,21 @@ describe('#core / mounting point', () => { }); it('supports decryption with static IV', () => { - let pn = new PubNub({ cipherKey: 'customKey', useRandomIVs: false, uuid: 'myUUID' }); + let pn = new PubNub({ + subscribeKey: 'demo', + cipherKey: 'customKey', + useRandomIVs: false, + uuid: 'myUUID', + }); assert.deepEqual(pn.decrypt('TejX6F2JNqH/gIiGHWN4Cw=='), { hi: 'there' }); }); it('supports decryption with random IV', () => { - let pn = new PubNub({ cipherKey: 'customKey', uuid: 'myUUID' }); + let pn = new PubNub({ + subscribeKey: 'demo', + cipherKey: 'customKey', + uuid: 'myUUID', + }); const data = pn.encrypt(JSON.stringify({ hi: 'there2' })); assert.notDeepEqual(pn.decrypt('TejX6F2JNqH/gIiGHWN4Cw=='), { hi: 'there' }); @@ -94,14 +125,18 @@ describe('#core / mounting point', () => { }); it('supports decryption with custom key and static IV', () => { - let pn = new PubNub({ useRandomIVs: false, uuid: 'myUUID' }); + let pn = new PubNub({ + subscribeKey: 'demo', + useRandomIVs: false, + uuid: 'myUUID', + }); assert.deepEqual(pn.decrypt('TejX6F2JNqH/gIiGHWN4Cw==', 'customKey'), { hi: 'there', }); }); it('supports decryption with custom key and random IV', () => { - let pn = new PubNub({ uuid: 'myUUID' }); + let pn = new PubNub({ subscribeKey: 'demo', uuid: 'myUUID' }); const data = pn.encrypt(JSON.stringify({ hi: 'there2' }), 'customKey'); assert.notDeepEqual(pn.decrypt('TejX6F2JNqH/gIiGHWN4Cw==', 'customKey'), { @@ -111,17 +146,25 @@ describe('#core / mounting point', () => { }); it('supports custom encryption/decryption', () => { - let customEncrypt = (data) => { + let customEncrypt = (data: Payload) => { + // @ts-expect-error Bundled library without types. let cipher = CryptoJS.AES.encrypt(JSON.stringify(data), 'customKey'); return cipher.toString(); }; - let customDecrypt = (data) => { + let customDecrypt = (data: Payload) => { + // @ts-expect-error Bundled library without types. let bytes = CryptoJS.AES.decrypt(data, 'customKey'); + // @ts-expect-error Bundled library without types. return JSON.parse(bytes.toString(CryptoJS.enc.Utf8)); }; - let pn = new PubNub({ customEncrypt, customDecrypt, uuid: 'myUUID' }); + let pn = new PubNub({ + subscribeKey: 'demo', + customEncrypt, + customDecrypt, + uuid: 'myUUID', + }); let ciphertext = pn.encrypt({ hi: 'there' }); diff --git a/test/unit/event_engine.test.ts b/test/unit/event_engine.test.ts index b45db4dc6..28dd1edfd 100644 --- a/test/unit/event_engine.test.ts +++ b/test/unit/event_engine.test.ts @@ -1,10 +1,13 @@ import nock from 'nock'; -import utils from '../utils'; + +import { Payload } from '../../src/core/types/api'; import PubNub from '../../src/node/index'; +import utils from '../utils'; describe('EventEngine', () => { - let pubnub: PubNub; + // @ts-expect-error Access event engine core for test purpose. let engine: PubNub['eventEngine']['engine']; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); @@ -14,7 +17,8 @@ describe('EventEngine', () => { nock.enableNetConnect(); }); - let unsub; + let unsub: () => void; + beforeEach(() => { nock.cleanAll(); @@ -25,10 +29,12 @@ describe('EventEngine', () => { enableEventEngine: true, }); - engine = pubnub.eventEngine._engine; + // @ts-expect-error Access event engine core for test purpose. + engine = pubnub.eventEngine!._engine; - unsub = engine.subscribe((change) => { - console.log(change); + unsub = engine.subscribe((_change: Record) => { + // FOR DEBUG + // console.dir(_change); }); }); @@ -38,9 +44,9 @@ describe('EventEngine', () => { function forEvent(eventLabel: string, timeout?: number) { return new Promise((resolve, reject) => { - let timeoutId = null; + let timeoutId: NodeJS.Timeout | null = null; - const unsubscribe = engine.subscribe((change) => { + const unsubscribe = engine.subscribe((change: { type: string; event: { type: string } }) => { if (change.type === 'eventReceived' && change.event.type === eventLabel) { if (timeoutId) clearTimeout(timeoutId); unsubscribe(); @@ -59,9 +65,9 @@ describe('EventEngine', () => { function forState(stateLabel: string, timeout?: number) { return new Promise((resolve, reject) => { - let timeoutId = null; + let timeoutId: NodeJS.Timeout | null = null; - const unsubscribe = engine.subscribe((change) => { + const unsubscribe = engine.subscribe((change: { type: string; toState: { label: string } }) => { if (change.type === 'transitionDone' && change.toState.label === stateLabel) { if (timeoutId) clearTimeout(timeoutId); unsubscribe(); @@ -80,9 +86,9 @@ describe('EventEngine', () => { function forInvocation(invocationLabel: string, timeout?: number) { return new Promise((resolve, reject) => { - let timeoutId = null; + let timeoutId: NodeJS.Timeout | null = null; - const unsubscribe = engine.subscribe((change) => { + const unsubscribe = engine.subscribe((change: { type: string; invocation: { type: string } }) => { if (change.type === 'invocationDispatched' && change.invocation.type === invocationLabel) { if (timeoutId) clearTimeout(timeoutId); unsubscribe(); diff --git a/test/unit/event_engine_presence.test.ts b/test/unit/event_engine_presence.test.ts index 432886e45..5b009eb2f 100644 --- a/test/unit/event_engine_presence.test.ts +++ b/test/unit/event_engine_presence.test.ts @@ -1,10 +1,12 @@ import nock from 'nock'; -import utils from '../utils'; + import PubNub from '../../src/node/index'; +import utils from '../utils'; describe('EventEngine', () => { - let pubnub: PubNub; + // @ts-expect-error Access event engine core for test purpose. let engine: PubNub['presenceEventEngine']['engine']; + let pubnub: PubNub; before(() => { nock.disableNetConnect(); @@ -14,7 +16,8 @@ describe('EventEngine', () => { nock.enableNetConnect(); }); - let unsub; + let unsub: () => void; + beforeEach(() => { nock.cleanAll(); @@ -27,10 +30,12 @@ describe('EventEngine', () => { logVerbosity: true, }); + // @ts-expect-error Access event engine core for test purpose. engine = pubnub.presenceEventEngine._engine; - unsub = engine.subscribe((change) => { - console.log(change); + unsub = engine.subscribe((_change: Record) => { + // FOR DEBUG + // console.dir(change); }); }); @@ -40,9 +45,9 @@ describe('EventEngine', () => { function forEvent(eventLabel: string, timeout?: number) { return new Promise((resolve, reject) => { - let timeoutId = null; + let timeoutId: NodeJS.Timeout | null = null; - const unsubscribe = engine.subscribe((change) => { + const unsubscribe = engine.subscribe((change: { type: string; event: { type: string } }) => { if (change.type === 'eventReceived' && change.event.type === eventLabel) { if (timeoutId) clearTimeout(timeoutId); unsubscribe(); @@ -61,9 +66,9 @@ describe('EventEngine', () => { function forState(stateLabel: string, timeout?: number) { return new Promise((resolve, reject) => { - let timeoutId = null; + let timeoutId: NodeJS.Timeout | null = null; - const unsubscribe = engine.subscribe((change) => { + const unsubscribe = engine.subscribe((change: { type: string; toState: { label: string } }) => { if (change.type === 'transitionDone' && change.toState.label === stateLabel) { if (timeoutId) clearTimeout(timeoutId); unsubscribe(); @@ -82,9 +87,9 @@ describe('EventEngine', () => { function forInvocation(invocationLabel: string, timeout?: number) { return new Promise((resolve, reject) => { - let timeoutId = null; + let timeoutId: NodeJS.Timeout | null = null; - const unsubscribe = engine.subscribe((change) => { + const unsubscribe = engine.subscribe((change: { type: string; invocation: { type: string } }) => { if (change.type === 'invocationDispatched' && change.invocation.type === invocationLabel) { if (timeoutId) clearTimeout(timeoutId); unsubscribe(); @@ -101,13 +106,14 @@ describe('EventEngine', () => { }); } - it(' presence event_engine should work correctly', async () => { + it('presence event_engine should work correctly', async () => { utils .createNock() .get('/v2/presence/sub-key/demo/channel/test/heartbeat') .query(true) - .reply(200, '{"message":"OK", "service":"Presence"}'); + .reply(200, '{"message":"OK", "service":"Presence"}', { 'content-type': 'text/javascript' }); + // @ts-expect-error Intentional access to the private interface. pubnub.join({ channels: ['test'] }); await forEvent('JOINED', 1000); @@ -118,10 +124,9 @@ describe('EventEngine', () => { await forState('HEARTBEAT_COOLDOWN', 1000); + // @ts-expect-error Intentional access to the private interface. pubnub.leaveAll(); await forEvent('LEFT_ALL', 2000); - }); - }); diff --git a/test/unit/listener_manager.test.js b/test/unit/listener_manager.test.ts similarity index 59% rename from test/unit/listener_manager.test.js rename to test/unit/listener_manager.test.ts index 8a86faa1b..bdfd5bb23 100644 --- a/test/unit/listener_manager.test.js +++ b/test/unit/listener_manager.test.ts @@ -1,7 +1,9 @@ /* global describe, it */ import assert from 'assert'; -import ListenerManager from '../../src/core/components/listener_manager'; + +import { Listener, ListenerManager } from '../../src/core/components/listener_manager'; +import PubNub from '../../src/node'; describe('components/ListenerManager', () => { it('supports removal of listeners', () => { @@ -10,18 +12,28 @@ describe('components/ListenerManager', () => { let bool2 = false; let listener1 = { - message() { bool1 = true; } + message() { + bool1 = true; + }, }; let listener2 = { - message() { bool2 = true; } + message() { + bool2 = true; + }, }; listeners.addListener(listener1); listeners.addListener(listener2); listeners.removeListener(listener2); - listeners.announceMessage('hi'); + listeners.announceMessage({ + channel: 'ch', + subscription: 'ch', + message: 'hi', + timetoken: '123', + publisher: 'John', + }); assert(bool1, 'bool1 was triggered'); assert(!bool2, 'bool2 was not triggered'); @@ -34,23 +46,39 @@ describe('components/ListenerManager', () => { let bool3 = false; let listener1 = { - presence() { bool1 = true; } + presence() { + bool1 = true; + }, }; let listener2 = { - presence() { bool2 = true; } + presence() { + bool2 = true; + }, }; let listener3 = { - message() { bool3 = true; }, - status() { bool3 = true; } + message() { + bool3 = true; + }, + status() { + bool3 = true; + }, }; listeners.addListener(listener1); listeners.addListener(listener2); listeners.addListener(listener3); - listeners.announcePresence('hi'); + listeners.announcePresence({ + channel: 'ch', + subscription: 'ch', + action: 'join', + uuid: 'John', + occupancy: 1, + timetoken: '123', + timestamp: 123, + }); assert(bool1, 'bool1 was triggered'); assert(bool2, 'bool2 was triggered'); @@ -64,23 +92,31 @@ describe('components/ListenerManager', () => { let bool3 = false; let listener1 = { - status() { bool1 = true; } + status() { + bool1 = true; + }, }; let listener2 = { - status() { bool2 = true; } + status() { + bool2 = true; + }, }; let listener3 = { - message() { bool3 = true; }, - presence() { bool3 = true; } + message() { + bool3 = true; + }, + presence() { + bool3 = true; + }, }; listeners.addListener(listener1); listeners.addListener(listener2); listeners.addListener(listener3); - listeners.announceStatus('hi'); + listeners.announceStatus({ statusCode: 200, category: PubNub.CATEGORIES.PNConnectedCategory }); assert(bool1, 'bool1 was triggered'); assert(bool2, 'bool2 was triggered'); @@ -94,23 +130,37 @@ describe('components/ListenerManager', () => { let bool3 = false; let listener1 = { - message() { bool1 = true; } + message() { + bool1 = true; + }, }; let listener2 = { - message() { bool2 = true; } + message() { + bool2 = true; + }, }; let listener3 = { - status() { bool3 = true; }, - presence() { bool3 = true; } + status() { + bool3 = true; + }, + presence() { + bool3 = true; + }, }; listeners.addListener(listener1); listeners.addListener(listener2); listeners.addListener(listener3); - listeners.announceMessage('hi'); + listeners.announceMessage({ + channel: 'ch', + subscription: 'ch', + message: 'hi', + timetoken: '123', + publisher: 'John', + }); assert(bool1, 'bool1 was triggered'); assert(bool2, 'bool2 was triggered'); @@ -119,10 +169,10 @@ describe('components/ListenerManager', () => { it('announces network down events', () => { let listeners = new ListenerManager(); - let listener = { + let listener: Listener = { status(status) { - assert.deepEqual(status, { category: 'PNNetworkDownCategory' }); - } + assert.deepEqual(status, { category: PubNub.CATEGORIES.PNNetworkDownCategory }); + }, }; listeners.addListener(listener); @@ -132,10 +182,10 @@ describe('components/ListenerManager', () => { it('announces network up events', () => { let listeners = new ListenerManager(); - let listener = { + let listener: Listener = { status(status) { - assert.deepEqual(status, { category: 'PNNetworkUpCategory' }); - } + assert.deepEqual(status, { category: PubNub.CATEGORIES.PNNetworkUpCategory }); + }, }; listeners.addListener(listener); diff --git a/test/unit/networking.test.js b/test/unit/networking.test.js deleted file mode 100644 index 1ab2654f6..000000000 --- a/test/unit/networking.test.js +++ /dev/null @@ -1,136 +0,0 @@ -/* global describe, it, before, after */ - -import superagent from 'superagent'; -import sinon from 'sinon'; -import nock from 'nock'; -import assert from 'assert'; - -import Config from '../../src/core/components/config'; -import Networking from '../../src/networking'; -import { del, get, post } from '../../src/networking/modules/web-node'; -import { keepAlive, proxy } from '../../src/networking/modules/node'; - -describe('multiple origins', () => { - before(() => nock.disableNetConnect()); - after(() => nock.enableNetConnect()); - - it('should use a random origin from a supplied array of origins', () => { - const origins = ['test1.example.com', 'test2.example.com']; - const config = new Config({ setup: { ssl: true, origin: origins, uuid: 'myUUID' } }) - const networking = new Networking({}); - networking.init(config); - - const origin = networking.getStandardOrigin(); - - assert(origins.some((e) => `https://${e}` === origin), `Supplied origins do not contain "${origin}"`); - }); - - it('should use string origin if a string is supplied', () => { - const config = new Config({ setup: { ssl: true, origin: 'example.com', uuid: 'myUUID' } }) - const networking = new Networking({}); - networking.init(config); - - const origin = networking.getStandardOrigin(); - - assert.equal(origin, 'https://example.com/'); - }); - - describe('shiftStandardOrigin', () => { - it('should use all origins if array is supplied', () => { - const origins = ['test1.example.com', 'test2.example.com']; - const config = new Config({ setup: { ssl: true, origin: origins, uuid: 'myUUID' } }) - const networking = new Networking({}); - networking.init(config); - - const firstOrigin = networking.getStandardOrigin(); - const secondOrigin = networking.shiftStandardOrigin(); - const thirdOrigin = networking.shiftStandardOrigin(); - - assert.equal(firstOrigin, thirdOrigin); - assert.notEqual(firstOrigin, secondOrigin); - }); - - it('should do nothing if string is supplied', () => { - const config = new Config({ setup: { ssl: true, origin: 'example.com', uuid: 'myUUID' } }) - const networking = new Networking({}); - networking.init(config); - - const firstOrigin = networking.getStandardOrigin(); - const secondOrigin = networking.shiftStandardOrigin(); - const thirdOrigin = networking.shiftStandardOrigin(); - - assert.equal(firstOrigin, secondOrigin); - assert.equal(secondOrigin, thirdOrigin); - assert.equal(thirdOrigin, firstOrigin); - }); - }); -}); - -describe('keep-alive agent', () => { - before(() => nock.disableNetConnect()); - after(() => nock.enableNetConnect()); - - const setupNetwork = (shouldSecure, enableKeepAlive) => { - const config = new Config({ setup: { origin: 'ps.pndsn.com', ssl: shouldSecure, keepAlive: enableKeepAlive, logVerbosity: false, uuid: 'myUUID' } }); - const networking = new Networking({ keepAlive, del, get, post, proxy }); - networking.init(config); - - return networking; - }; - - it('should not create if \'keepAlive\' is \'false\'', () => { - const networking = setupNetwork(false, false); - const superagentGetSpy = sinon.spy(superagent, 'get'); - - networking.GET({}, { url: '/time/0', headers: {} }, () => {}); - assert(superagentGetSpy.called, 'superagent not called with get'); - assert(superagentGetSpy.returnValues[0], 'request instance not created'); - assert(!superagentGetSpy.returnValues[0]._agent, 'keep-alive agent should not be created'); - - superagentGetSpy.restore(); - }); - - it('should create agent for insecure connection', () => { - const networking = setupNetwork(false, true); - const superagentGetSpy = sinon.spy(superagent, 'get'); - - networking.GET({}, { url: '/time/0', headers: {} }, () => {}); - assert(superagentGetSpy.returnValues[0]._agent, 'keep-alive agent not created'); - assert(superagentGetSpy.returnValues[0]._agent.defaultPort !== 443, 'keep-alive agent should access TLS (80) port'); - - superagentGetSpy.restore(); - }); - - it('should re-use created agent for insecure connection', () => { - const networking = setupNetwork(false, true); - const superagentGetSpy = sinon.spy(superagent, 'get'); - - networking.GET({}, { url: '/time/0', headers: {} }, () => {}); - networking.GET({}, { url: '/time/0', headers: {} }, () => {}); - assert(superagentGetSpy.returnValues[0]._agent === superagentGetSpy.returnValues[1]._agent, 'same user-agent should be used'); - - superagentGetSpy.restore(); - }); - - it('should create agent for secure connection', () => { - const networking = setupNetwork(true, true); - const superagentGetSpy = sinon.spy(superagent, 'get'); - - networking.GET({}, { url: '/time/0', headers: {} }, () => {}); - assert(superagentGetSpy.returnValues[0]._agent, 'keep-alive agent not created'); - assert(superagentGetSpy.returnValues[0]._agent.defaultPort === 443, 'keep-alive agent should access SSL (443) port'); - - superagentGetSpy.restore(); - }); - - it('should re-use created agent for secure connection', () => { - const networking = setupNetwork(true, true); - const superagentGetSpy = sinon.spy(superagent, 'get'); - - networking.GET({}, { url: '/time/0', headers: {} }, () => {}); - networking.GET({}, { url: '/time/0', headers: {} }, () => {}); - assert(superagentGetSpy.returnValues[0]._agent === superagentGetSpy.returnValues[1]._agent, 'same user-agent should be used'); - - superagentGetSpy.restore(); - }); -}); diff --git a/test/unit/networking.test.ts b/test/unit/networking.test.ts new file mode 100644 index 000000000..fad8a0ac0 --- /dev/null +++ b/test/unit/networking.test.ts @@ -0,0 +1,37 @@ +/* global describe, it, before, after */ + +import assert from 'assert'; +import nock from 'nock'; + +import { makeConfiguration } from '../../src/core/components/configuration'; +import { setDefaults } from '../../src/core/interfaces/configuration'; + +describe('multiple origins', () => { + before(() => nock.disableNetConnect()); + after(() => nock.enableNetConnect()); + + it('should use a random origin from a supplied array of origins', () => { + const origins = ['test1.example.com', 'test2.example.com']; + + const configuration = makeConfiguration({ + ...setDefaults({ subscribeKey: 'demo', ssl: true, origin: origins, uuid: 'myUUID' }), + sdkFamily: 'test', + }); + + assert( + origins.some((e) => `https://${e}` === configuration.origin), + `Supplied origins do not contain "${configuration.origin}"`, + ); + }); + + it('should use string origin if a string is supplied', () => { + const configuration = makeConfiguration({ + ...setDefaults({ subscribeKey: 'demo', ssl: true, origin: 'example.com', uuid: 'myUUID' }), + sdkFamily: 'test', + }); + + assert.equal(configuration.origin, 'https://example.com/'); + }); + + // `shiftStandardOrigin` removed because originally `origin` picked only during PubNub client instance creation. +}); diff --git a/test/unit/notifications_payload.test.js b/test/unit/notifications_payload.test.ts similarity index 62% rename from test/unit/notifications_payload.test.js rename to test/unit/notifications_payload.test.ts index e9e86c795..a1f164e13 100644 --- a/test/unit/notifications_payload.test.js +++ b/test/unit/notifications_payload.test.ts @@ -1,8 +1,9 @@ /* global describe, beforeEach, it */ import assert from 'assert'; + +import { APNSNotificationPayload, FCMNotificationPayload } from '../../src/core/components/push_payload'; import PubNub from '../../src/node/index'; -import { APNSNotificationPayload, MPNSNotificationPayload, FCMNotificationPayload } from '../../src/core/components/push_payload'; describe('#notifications helper', () => { describe('payloads builder', () => { @@ -13,7 +14,6 @@ describe('#notifications helper', () => { let builder = PubNub.notificationPayload(expectedTitle, expectedBody); assert(builder.apns); - assert(builder.mpns); assert(builder.fcm); }); @@ -21,25 +21,34 @@ describe('#notifications helper', () => { let expectedTitle = PubNub.generateUUID(); let expectedBody = PubNub.generateUUID(); - let builder = PubNub.notificationPayload(expectedTitle, expectedBody); + const builder = PubNub.notificationPayload(expectedTitle, expectedBody); + const apnsPayload = builder.apns.toObject(); + const fcmPayload = builder.fcm.toObject(); - assert.equal(builder.apns.toObject().aps.alert.title, expectedTitle); - assert.equal(builder.apns.toObject().aps.alert.body, expectedBody); - assert.equal(builder.mpns.toObject().title, expectedTitle); - assert.equal(builder.mpns.toObject().back_content, expectedBody); - assert.equal(builder.fcm.toObject().notification.title, expectedTitle); - assert.equal(builder.fcm.toObject().notification.body, expectedBody); + assert(apnsPayload); + assert(apnsPayload.aps.alert); + assert.equal(apnsPayload.aps.alert.title, expectedTitle); + assert.equal(apnsPayload.aps.alert.body, expectedBody); + assert(fcmPayload); + assert(fcmPayload.notification); + assert.equal(fcmPayload.notification.title, expectedTitle); + assert.equal(fcmPayload.notification.body, expectedBody); }); it('should pass subtitle to builders', () => { let expectedSubtitle = PubNub.generateUUID(); - let builder = PubNub.notificationPayload(PubNub.generateUUID(), PubNub.generateUUID()); + const builder = PubNub.notificationPayload(PubNub.generateUUID(), PubNub.generateUUID()); builder.subtitle = expectedSubtitle; + const apnsPayload = builder.apns.toObject(); + const fcmPayload = builder.fcm.toObject(); - assert.equal(builder.apns.toObject().aps.alert.subtitle, expectedSubtitle); - assert.equal(builder.mpns.toObject().back_title, expectedSubtitle); - assert.equal(Object.keys(builder.fcm.notification).length, 2); + assert(apnsPayload); + assert(apnsPayload.aps.alert); + assert.equal(apnsPayload.aps.alert.subtitle, expectedSubtitle); + assert(fcmPayload); + assert(fcmPayload.notification); + assert.equal(Object.keys(fcmPayload.notification).length, 2); }); it('should pass badge to builders', () => { @@ -47,10 +56,14 @@ describe('#notifications helper', () => { let builder = PubNub.notificationPayload(PubNub.generateUUID(), PubNub.generateUUID()); builder.badge = expectedBadge; + const apnsPayload = builder.apns.toObject(); + const fcmPayload = builder.fcm.toObject(); - assert.equal(builder.apns.toObject().aps.badge, expectedBadge); - assert.equal(builder.mpns.toObject().count, expectedBadge); - assert.equal(Object.keys(builder.fcm.notification).length, 2); + assert(apnsPayload); + assert.equal(apnsPayload.aps.badge, expectedBadge); + assert(fcmPayload); + assert(fcmPayload.notification); + assert.equal(Object.keys(fcmPayload.notification).length, 2); }); it('should pass sound to builders', () => { @@ -58,10 +71,14 @@ describe('#notifications helper', () => { let builder = PubNub.notificationPayload(PubNub.generateUUID(), PubNub.generateUUID()); builder.sound = expectedSound; + const apnsPayload = builder.apns.toObject(); + const fcmPayload = builder.fcm.toObject(); - assert.equal(builder.apns.toObject().aps.sound, expectedSound); - assert.equal(Object.keys(builder.mpns.payload).length, 2); - assert.equal(builder.fcm.toObject().notification.sound, expectedSound); + assert(apnsPayload); + assert.equal(apnsPayload.aps.sound, expectedSound); + assert(fcmPayload); + assert(fcmPayload.notification); + assert.equal(fcmPayload.notification.sound, expectedSound); }); it('should set debug flag', () => { @@ -76,11 +93,11 @@ describe('#notifications helper', () => { let expectedBody = PubNub.generateUUID(); let expectedPayload = { pn_apns: { - aps: { alert: { title: expectedTitle, body: expectedBody } } + aps: { alert: { title: expectedTitle, body: expectedBody } }, }, pn_gcm: { - notification: { title: expectedTitle, body: expectedBody } - } + notification: { title: expectedTitle, body: expectedBody }, + }, }; let builder = PubNub.notificationPayload(expectedTitle, expectedBody); @@ -99,13 +116,13 @@ describe('#notifications helper', () => { { auth_method: 'token', targets: [{ environment: 'development', topic: expectedTopic }], - version: 'v2' - } - ] + version: 'v2', + }, + ], }, pn_gcm: { - notification: { title: expectedTitle, body: expectedBody } - } + notification: { title: expectedTitle, body: expectedBody }, + }, }; let builder = PubNub.notificationPayload(expectedTitle, expectedBody); @@ -124,7 +141,7 @@ describe('#notifications helper', () => { }); describe('apns builder', () => { - let platformPayloadStorage; + let platformPayloadStorage: Record; beforeEach(() => { platformPayloadStorage = {}; @@ -140,7 +157,7 @@ describe('#notifications helper', () => { assert.equal(Object.keys(platformPayloadStorage.aps.alert).length, 0); }); - it('should set notification \'title\' and \'body\' with constructor', () => { + it("should set notification 'title' and 'body' with constructor", () => { let expectedTitle = PubNub.generateUUID(); let expectedBody = PubNub.generateUUID(); @@ -151,7 +168,7 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.aps.alert.body, expectedBody); }); - it('should set \'subtitle\'', () => { + it("should set 'subtitle'", () => { let expectedSubtitle = PubNub.generateUUID(); let builder = new APNSNotificationPayload(platformPayloadStorage); @@ -160,7 +177,7 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.aps.alert.subtitle, expectedSubtitle); }); - it('should not set \'subtitle\' if value is empty', () => { + it("should not set 'subtitle' if value is empty", () => { let expectedSubtitle = ''; let builder = new APNSNotificationPayload(platformPayloadStorage); @@ -169,7 +186,7 @@ describe('#notifications helper', () => { assert(!platformPayloadStorage.aps.alert.subtitle); }); - it('should set \'body\'', () => { + it("should set 'body'", () => { let expectedBody = PubNub.generateUUID(); let builder = new APNSNotificationPayload(platformPayloadStorage); @@ -178,7 +195,7 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.aps.alert.body, expectedBody); }); - it('should not set \'body\' if value is empty', () => { + it("should not set 'body' if value is empty", () => { let expectedBody = ''; let builder = new APNSNotificationPayload(platformPayloadStorage); @@ -187,7 +204,7 @@ describe('#notifications helper', () => { assert(!platformPayloadStorage.aps.alert.body); }); - it('should set \'badge\'', () => { + it("should set 'badge'", () => { let expectedBadged = 16; let builder = new APNSNotificationPayload(platformPayloadStorage); @@ -196,14 +213,14 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.aps.badge, expectedBadged); }); - it('should not set \'badge\' if value is empty', () => { + it("should not set 'badge' if value is empty", () => { let builder = new APNSNotificationPayload(platformPayloadStorage); builder.badge = null; assert(!platformPayloadStorage.aps.badge); }); - it('should set \'sound\'', () => { + it("should set 'sound'", () => { let expectedSound = PubNub.generateUUID(); let builder = new APNSNotificationPayload(platformPayloadStorage); @@ -212,7 +229,7 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.aps.sound, expectedSound); }); - it('should not set \'sound\' if value is empty', () => { + it("should not set 'sound' if value is empty", () => { let expectedSound = ''; let builder = new APNSNotificationPayload(platformPayloadStorage); @@ -227,16 +244,18 @@ describe('#notifications helper', () => { assert.equal(builder.toObject(), null); }); - it('should set \'content-available\' when set silenced', () => { + it("should set 'content-available' when set silenced", () => { let builder = new APNSNotificationPayload(platformPayloadStorage, PubNub.generateUUID(), PubNub.generateUUID()); builder.sound = PubNub.generateUUID(); builder.badge = 20; builder.silent = true; + const payload = builder.toObject(); - assert.equal(builder.toObject().aps['content-available'], 1); - assert(!builder.toObject().aps.badge); - assert(!builder.toObject().aps.sound); - assert(!builder.toObject().aps.alert); + assert(payload); + assert.equal(payload.aps['content-available'], 1); + assert(!payload.aps.badge); + assert(!payload.aps.sound); + assert(!payload.aps.alert); }); it('should return valid payload object', () => { @@ -249,8 +268,8 @@ describe('#notifications helper', () => { aps: { alert: { title: expectedTitle, subtitle: expectedSubtitle, body: expectedBody }, badge: expectedBadge, - sound: expectedSound - } + sound: expectedSound, + }, }; let builder = new APNSNotificationPayload(platformPayloadStorage, expectedTitle, expectedBody); @@ -272,20 +291,21 @@ describe('#notifications helper', () => { aps: { alert: { title: expectedTitle, subtitle: expectedSubtitle, body: expectedBody }, badge: expectedBadge, - sound: expectedSound + sound: expectedSound, }, pn_push: [ { auth_method: 'token', targets: [{ environment: 'development', topic: expectedTopic }], - version: 'v2' - } - ] + version: 'v2', + }, + ], }; let builder = new APNSNotificationPayload(platformPayloadStorage, expectedTitle, expectedBody); builder.configurations = [{ targets: [{ topic: expectedTopic }] }]; builder.subtitle = expectedSubtitle; + // @ts-expect-error Intentional manual private field override. builder._apnsPushType = 'apns2'; builder.badge = expectedBadge; builder.sound = expectedSound; @@ -294,133 +314,8 @@ describe('#notifications helper', () => { }); }); - describe('mpns builder', () => { - let platformPayloadStorage; - - beforeEach(() => { - platformPayloadStorage = {}; - }); - - it('should set notification \'title\' and \'body\' with constructor', () => { - let expectedTitle = PubNub.generateUUID(); - let expectedBody = PubNub.generateUUID(); - - let builder = new MPNSNotificationPayload(platformPayloadStorage, expectedTitle, expectedBody); - - assert(builder); - assert.equal(platformPayloadStorage.title, expectedTitle); - assert.equal(platformPayloadStorage.back_content, expectedBody); - }); - - it('should set \'back_title\' when \'subtitle\' passed', () => { - let expectedSubtitle = PubNub.generateUUID(); - - let builder = new MPNSNotificationPayload(platformPayloadStorage); - builder.subtitle = expectedSubtitle; - - assert.equal(platformPayloadStorage.back_title, expectedSubtitle); - }); - - it('should set \'back_title\'', () => { - let expectedBackTitle = PubNub.generateUUID(); - - let builder = new MPNSNotificationPayload(platformPayloadStorage); - builder.backTitle = expectedBackTitle; - - assert.equal(platformPayloadStorage.back_title, expectedBackTitle); - }); - - it('should not set \'back_title\' if value is empty', () => { - let expectedBackTitle = ''; - - let builder = new MPNSNotificationPayload(platformPayloadStorage); - builder.backTitle = expectedBackTitle; - - assert(!platformPayloadStorage.back_title); - }); - - it('should set \'back_content\' when \'body\' passed', () => { - let expectedBody = PubNub.generateUUID(); - - let builder = new MPNSNotificationPayload(platformPayloadStorage); - builder.body = expectedBody; - - assert.equal(platformPayloadStorage.back_content, expectedBody); - }); - - it('should set \'back_content\' ', () => { - let expectedBackContent = PubNub.generateUUID(); - - let builder = new MPNSNotificationPayload(platformPayloadStorage); - builder.backContent = expectedBackContent; - - assert.equal(platformPayloadStorage.back_content, expectedBackContent); - }); - - it('should not set \'back_content\' if value is empty', () => { - let expectedBackContent = ''; - - let builder = new MPNSNotificationPayload(platformPayloadStorage); - builder.backContent = expectedBackContent; - - assert(!platformPayloadStorage.back_content); - }); - - it('should set \'count\' when \'badge\' passed', () => { - let expectedBadge = 26; - - let builder = new MPNSNotificationPayload(platformPayloadStorage); - builder.badge = expectedBadge; - - assert.equal(platformPayloadStorage.count, expectedBadge); - }); - - it('should set \'count\' ', () => { - let expectedCount = 26; - - let builder = new MPNSNotificationPayload(platformPayloadStorage); - builder.count = expectedCount; - - assert.equal(platformPayloadStorage.count, expectedCount); - }); - - it('should not set \'count\' if value is empty', () => { - let builder = new MPNSNotificationPayload(platformPayloadStorage); - builder.count = null; - - assert(!platformPayloadStorage.count); - }); - - it('should return null when no data provided', () => { - let builder = new MPNSNotificationPayload(platformPayloadStorage); - - assert.equal(builder.toObject(), null); - }); - - it('should return valid payload object', () => { - let expectedSubtitle = PubNub.generateUUID(); - let expectedTitle = PubNub.generateUUID(); - let expectedBody = PubNub.generateUUID(); - let expectedCount = 26; - let expectedPayload = { - type: 'flip', - title: expectedTitle, - back_title: expectedSubtitle, - back_content: expectedBody, - count: expectedCount - }; - - let builder = new MPNSNotificationPayload(platformPayloadStorage, expectedTitle, expectedBody); - builder.subtitle = expectedSubtitle; - builder.count = expectedCount; - builder.type = 'flip'; - - assert.deepEqual(builder.toObject(), expectedPayload); - }); - }); - describe('fcm builder', () => { - let platformPayloadStorage; + let platformPayloadStorage: Record; beforeEach(() => { platformPayloadStorage = {}; @@ -434,7 +329,7 @@ describe('#notifications helper', () => { assert(platformPayloadStorage.data); }); - it('should set notification \'title\' and \'body\' with constructor', () => { + it("should set notification 'title' and 'body' with constructor", () => { let expectedTitle = PubNub.generateUUID(); let expectedBody = PubNub.generateUUID(); @@ -445,7 +340,7 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.notification.body, expectedBody); }); - it('should not set \'subtitle\' because it is not supported', () => { + it("should not set 'subtitle' because it is not supported", () => { let expectedSubtitle = PubNub.generateUUID(); let builder = new FCMNotificationPayload(platformPayloadStorage); @@ -454,7 +349,7 @@ describe('#notifications helper', () => { assert.equal(Object.keys(platformPayloadStorage.notification).length, 0); }); - it('should set \'body\'', () => { + it("should set 'body'", () => { let expectedBody = PubNub.generateUUID(); let builder = new FCMNotificationPayload(platformPayloadStorage); @@ -463,7 +358,7 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.notification.body, expectedBody); }); - it('should not set \'body\' if value is empty', () => { + it("should not set 'body' if value is empty", () => { let expectedBody = ''; let builder = new FCMNotificationPayload(platformPayloadStorage); @@ -472,14 +367,14 @@ describe('#notifications helper', () => { assert(!platformPayloadStorage.notification.body); }); - it('should not set \'badge\' because it is not supported', () => { + it("should not set 'badge' because it is not supported", () => { let builder = new FCMNotificationPayload(platformPayloadStorage); builder.badge = 30; assert.equal(Object.keys(platformPayloadStorage.notification).length, 0); }); - it('should set \'sound\'', () => { + it("should set 'sound'", () => { let expectedSound = PubNub.generateUUID(); let builder = new FCMNotificationPayload(platformPayloadStorage); @@ -488,7 +383,7 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.notification.sound, expectedSound); }); - it('should not set \'sound\' if value is empty', () => { + it("should not set 'sound' if value is empty", () => { let expectedSound = ''; let builder = new FCMNotificationPayload(platformPayloadStorage); @@ -497,7 +392,7 @@ describe('#notifications helper', () => { assert(!platformPayloadStorage.notification.sound); }); - it('should set \'icon\'', () => { + it("should set 'icon'", () => { let expectedIcon = PubNub.generateUUID(); let builder = new FCMNotificationPayload(platformPayloadStorage); @@ -506,7 +401,7 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.notification.icon, expectedIcon); }); - it('should not set \'icon\' if value is empty', () => { + it("should not set 'icon' if value is empty", () => { let expectedIcon = ''; let builder = new FCMNotificationPayload(platformPayloadStorage); @@ -515,7 +410,7 @@ describe('#notifications helper', () => { assert(!platformPayloadStorage.notification.icon); }); - it('should set \'tag\'', () => { + it("should set 'tag'", () => { let expectedTag = PubNub.generateUUID(); let builder = new FCMNotificationPayload(platformPayloadStorage); @@ -524,7 +419,7 @@ describe('#notifications helper', () => { assert.equal(platformPayloadStorage.notification.tag, expectedTag); }); - it('should not set \'tag\' if value is empty', () => { + it("should not set 'tag' if value is empty", () => { let expectedTag = ''; let builder = new FCMNotificationPayload(platformPayloadStorage); @@ -539,22 +434,25 @@ describe('#notifications helper', () => { assert.equal(builder.toObject(), null); }); - it('should move \'notification\' under \'data\' when set silenced', () => { + it("should move 'notification' under 'data' when set silenced", () => { let expectedTitle = PubNub.generateUUID(); let expectedBody = PubNub.generateUUID(); let expectedSound = PubNub.generateUUID(); let expectedNotification = { title: expectedTitle, body: expectedBody, - sound: expectedSound + sound: expectedSound, }; let builder = new FCMNotificationPayload(platformPayloadStorage, expectedTitle, expectedBody); builder.sound = expectedSound; builder.silent = true; + const payload = builder.toObject(); - assert(!builder.toObject().notification); - assert.deepEqual(builder.toObject().data.notification, expectedNotification); + assert(payload); + assert(!payload.notification); + assert(payload.data); + assert.deepEqual(payload.data.notification, expectedNotification); }); it('should return valid payload object', () => { @@ -565,8 +463,8 @@ describe('#notifications helper', () => { notification: { title: expectedTitle, body: expectedBody, - sound: expectedSound - } + sound: expectedSound, + }, }; let builder = new FCMNotificationPayload(platformPayloadStorage, expectedTitle, expectedBody); diff --git a/test/utils.js b/test/utils.js deleted file mode 100644 index a6bf5e8f8..000000000 --- a/test/utils.js +++ /dev/null @@ -1,47 +0,0 @@ -/** */ - -import assert from 'assert'; -import nock from 'nock'; - -export default { - createNock() { - return nock('http://ps.pndsn.com/', { - filteringScope: () => true, - }); - }, - runAPIWithResponseDelays(scope, statusCode, responseBody, delays, apiCall) { - let lastRequest = null; - - const callAPIWithDelayedResponse = (previousDelay, delay) => - new Promise((resolve) => { - const scopeWithDelay = scope.delay(-previousDelay).delay(delay).reply(statusCode, responseBody); - scopeWithDelay.once('request', (request) => { - lastRequest = request; - }); - - apiCall(() => { - scopeWithDelay.done(); - resolve(); - }); - }); - - let promisesResult = Promise.resolve(); - for (let delayIdx = 0; delayIdx < delays.length; delayIdx += 1) { - let previousDelay = delayIdx > 0 ? delays[delayIdx - 1] : 0; - let delay = delays[delayIdx]; - promisesResult = promisesResult.then(() => callAPIWithDelayedResponse(previousDelay, delay)); - } - - return promisesResult.then(() => lastRequest); - }, - verifyRequestTelemetry(requestPath, latencyKey, expectedLatency, leeway) { - const re = new RegExp(`${latencyKey}=(\\d+)`, 'i'); - const latencyString = (re.exec(requestPath) ?? [])[1]; - const latency = latencyString ? parseInt(latencyString, 10) : 0; - - assert( - latency >= expectedLatency && latency <= expectedLatency + leeway, - `Latency is outside of expected bounds: ${expectedLatency} <= ${latency} <= ${expectedLatency + leeway}`, - ); - }, -}; diff --git a/test/utils.ts b/test/utils.ts new file mode 100644 index 000000000..cce634f9f --- /dev/null +++ b/test/utils.ts @@ -0,0 +1,67 @@ +/** */ + +import nock, { Interceptor } from 'nock'; + +import chaiAsPromised from 'chai-as-promised'; +import chaiNock from 'chai-nock'; +import chai from 'chai'; + +import { Query } from '../src/core/types/api'; + +chai.use(chaiAsPromised); +chai.use(chaiNock); + +process.env.NODE_ENV = 'test'; + +export default { + createNock() { + return nock('https://ps.pndsn.com/', { + filteringScope: (scope) => /ps\d*\.pndsn\.com/.test(scope), + // allowUnmocked: true, + }); + }, + runAPIWithResponseDelays( + scope: Interceptor, + statusCode: number, + responseBody: string, + delays: number[], + apiCall: (completion: () => void) => void, + ) { + let lastRequest: null = null; + + const callAPIWithDelayedResponse = (previousDelay: number, delay: number) => + new Promise((resolve) => { + const scopeWithDelay = scope + .delay(-previousDelay) + .delay(delay) + .reply(statusCode, responseBody, { 'content-type': 'text/javascript' }); + scopeWithDelay.once('request', (request) => { + lastRequest = request; + }); + + apiCall(() => { + scopeWithDelay.done(); + resolve(undefined); + }); + }); + + let promisesResult = Promise.resolve(); + for (let delayIdx = 0; delayIdx < delays.length; delayIdx += 1) { + let previousDelay = delayIdx > 0 ? delays[delayIdx - 1] : 0; + let delay = delays[delayIdx]; + promisesResult = promisesResult.then(() => callAPIWithDelayedResponse(previousDelay, delay)) as Promise; + } + + return promisesResult.then(() => lastRequest); + }, + matchQuery(actualQuery: Query, targetQuery: Query, excludeRequestId: boolean = true): boolean { + const actualKeys = Object.keys(actualQuery).filter((key) => key !== 'requestid' || !excludeRequestId); + const targetKeys = Object.keys(targetQuery); + + if (actualKeys.length !== targetKeys.length) return false; + + for (const key of targetKeys) if (actualQuery[key] !== targetQuery[key]) return false; + + return true; + }, +}; diff --git a/tsconfig.json b/tsconfig.json index 2103f09c5..f0fdf721e 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,20 +1,29 @@ { "$schema": "https://json.schemastore.org/tsconfig", "compilerOptions": { - "target": "ES5", + "target": "ES6", "module": "CommonJS", "moduleResolution": "Node", - "esModuleInterop": true, "allowJs": true, "noEmitOnError": true, "strict": true, + "esModuleInterop": true, "outDir": "./lib", - "downlevelIteration": true + "downlevelIteration": true, + "removeComments": true }, "include": [ "src/**/*" ], "exclude": [ - "node_modules" + "node_modules", + "src/crypto/modules/WebCryptoModule/**/*", + "src/crypto/modules/web.ts", + "src/file/modules/web.ts", + "src/nativescript/**/*", + "src/titanium/**/*", + "src/transport/service-worker/**/*", + "src/transport/titanium-transport.ts", + "src/web/**/*" ] } \ No newline at end of file diff --git a/tsconfig.mocha.json b/tsconfig.mocha.json index 6e2fde3c2..4d9b5b750 100644 --- a/tsconfig.mocha.json +++ b/tsconfig.mocha.json @@ -1,13 +1,11 @@ { + "extends": "./tsconfig.json", "compilerOptions": { - "target": "ES5", - "module": "commonjs", - "moduleResolution": "Node", - "allowJs": true, - "noEmitOnError": true, + "module": "CommonJS", + "esModuleInterop": true, + "noImplicitAny": false, + "noEmit": true, "strict": true, - "esModuleInterop": true }, - "include": ["src/**/*"], - "exclude": ["node_modules"] + "include": ["test/**/*"] } diff --git a/tsconfig.rollup.json b/tsconfig.rollup.json index b72d08c52..e317fb87b 100644 --- a/tsconfig.rollup.json +++ b/tsconfig.rollup.json @@ -1,14 +1,30 @@ { "compilerOptions": { - "target": "ES5", - "module": "ESNext", + "target": "ES6", + "module": "ES6", "moduleResolution": "Node", - "allowJs": true, "noEmitOnError": true, "strict": true, - "outDir": "./lib" + "esModuleInterop": true, + "outDir": "./lib", + "lib": [ + "es6", + "webworker", + "dom" + ] }, "include": ["src/**/*"], - "exclude": ["node_modules", "src/node/**/*"] + "exclude": [ + "node_modules", + "test", + "src/file/modules/node.ts", + "src/file/modules/react-native.ts", + "src/node/**/*", + "src/react_native/**/*", + "src/nativescript/**/*", + "src/titanium/**/*", + "src/transport/node-transport.ts", + "src/transport/titanium-transport.ts" + ] } From 3fff0752e7c85ea0a376b7d08a49c226592ab573 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 23 Apr 2024 13:33:55 +0300 Subject: [PATCH 06/49] Initialize service worker from Url (#369) refactor(service-worker): initialize service worker from Url Provider configuration option to set service worker from the URL (because of browser restrictions for worker files to be registered from the same domain). --- .pubnub.yml | 11 +++++++--- CHANGELOG.md | 6 +++++ README.md | 4 ++-- dist/web/pubnub.js | 20 +++++++---------- dist/web/pubnub.min.js | 4 ++-- lib/core/components/configuration.js | 2 +- package-lock.json | 11 ++-------- package.json | 2 +- src/core/components/configuration.ts | 2 +- .../subscription-service-worker-middleware.ts | 7 +++++- src/web/components/configuration.ts | 22 ++++++++----------- src/web/index.ts | 3 ++- 12 files changed, 48 insertions(+), 46 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index f86467bbe..e84db4641 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-04-23 + version: v8.0.1 + changes: + - type: improvement + text: "Provider configuration option to set service worker from the URL (because of browser restrictions for worker files to be registered from the same domain)." - date: 2024-04-22 version: v8.0.0 changes: @@ -967,7 +972,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.0.0' +version: '8.0.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -983,7 +988,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.0.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.0.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1654,7 +1659,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.0.0/pubnub.8.0.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.0.1/pubnub.8.0.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 8da7ea74d..77d7f99c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.0.1 +April 23 2024 + +#### Modified +- Provider configuration option to set service worker from the URL (because of browser restrictions for worker files to be registered from the same domain). + ## v8.0.0 April 22 2024 diff --git a/README.md b/README.md index b9c208c6e..0aef17301 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.0.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.0.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.0.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.0.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 92b49723d..7ba541855 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -837,7 +837,7 @@ return; const serviceWorkerContainer = navigator.serviceWorker; serviceWorkerContainer - .register(`https://cdn.pubnub.com/sdk/javascript/dist/web/pubnub.worker.js`, { + .register(this.configuration.serviceWorkerUrl, { scope: `/pubnub-${this.configuration.sdkVersion}`, }) .then((registration) => { @@ -3599,11 +3599,6 @@ * reconnection issues, set the flag to `false`. This allows the SDK reconnection logic to take over. */ const LISTEN_TO_BROWSER_NETWORK_EVENTS = true; - /** - * Whether PubNub client should spawn `Subscription` service worker for better user presence - * experience or not. - */ - const ENABLE_SERVICE_WORKER = false; /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -3614,13 +3609,13 @@ * @param configuration - User-provided configuration. */ const setDefaults = (configuration) => { - var _a, _b, _c, _d; + var _a, _b; // Force disable service workers if environment doesn't support them. - if (((_a = configuration.enableServiceWorker) !== null && _a !== void 0 ? _a : ENABLE_SERVICE_WORKER) && !('serviceWorker' in navigator)) - configuration.enableServiceWorker = false; + if (configuration.serviceWorkerUrl && !('serviceWorker' in navigator)) + configuration.serviceWorkerUrl = null; return Object.assign(Object.assign({}, setDefaults$1(configuration)), { // Set platform-specific options. - listenToBrowserNetworkEvents: (_b = configuration.listenToBrowserNetworkEvents) !== null && _b !== void 0 ? _b : LISTEN_TO_BROWSER_NETWORK_EVENTS, enableServiceWorker: (_c = configuration.enableServiceWorker) !== null && _c !== void 0 ? _c : ENABLE_SERVICE_WORKER, keepAlive: (_d = configuration.keepAlive) !== null && _d !== void 0 ? _d : KEEP_ALIVE }); + listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, serviceWorkerUrl: configuration.serviceWorkerUrl, keepAlive: (_b = configuration.keepAlive) !== null && _b !== void 0 ? _b : KEEP_ALIVE }); }; var uuid = {exports: {}}; @@ -3782,7 +3777,7 @@ return base.PubNubFile; }, get version() { - return '7.6.3'; + return '8.0.1'; }, getVersion() { return this.version; @@ -13030,11 +13025,12 @@ } // Setup transport provider. let transport = new WebReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity); - if (configurationCopy.enableServiceWorker) { + if (configurationCopy.serviceWorkerUrl) { // Inject subscription service worker into transport provider stack. transport = new SubscriptionServiceWorkerMiddleware({ clientIdentifier: clientConfiguration._instanceId, subscriptionKey: clientConfiguration.subscribeKey, + serviceWorkerUrl: configurationCopy.serviceWorkerUrl, sdkVersion: clientConfiguration.getVersion(), logVerbosity: clientConfiguration.logVerbosity, transport, diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 4e1a1a155..435b2833f 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,o=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new c(r,n,o,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new o(null!=t?t:this.message,this.toStatus(e))}}class u{constructor(e){this.configuration=e,this.serviceWorkerEventsQueue=[],this.callbacks=new Map,this.setupServiceWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.serviceWorker;s?s.postMessage(e):t?this.serviceWorkerEventsQueue.splice(0,0,e):this.serviceWorkerEventsQueue.push(e)}flushScheduledEvents(){const e=this.serviceWorker;if(!e||0===this.serviceWorkerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.serviceWorkerEventsQueue.forEach((t=>e.postMessage(t))),this.serviceWorkerEventsQueue=[]}get serviceWorker(){return this.serviceWorkerRegistration?this.serviceWorkerRegistration.active:null}setupServiceWorker(){if(!("serviceWorker"in navigator))return;const e=navigator.serviceWorker;e.register("https://cdn.pubnub.com/sdk/javascript/dist/web/pubnub.worker.min.js",{scope:`/pubnub-${this.configuration.sdkVersion}`}).then((e=>{this.serviceWorkerRegistration=e,e.active&&this.flushScheduledEvents(),this.serviceWorkerRegistration.addEventListener("updatefound",(()=>{if(!this.serviceWorkerRegistration)return;const e=this.serviceWorkerRegistration.installing,t=()=>{"activated"===e.state?this.flushScheduledEvents():"redundant"===e.state&&e.removeEventListener("statechange",t)};e.addEventListener("statechange",t)}))})),e.addEventListener("message",(e=>this.handleServiceWorkerEvent(e)))}handleServiceWorkerEvent(e){const{data:t}=e;if(t.clientIdentifier===this.configuration.clientIdentifier)if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=i.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=i.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=i.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=i.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(c.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new c(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}function l(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return h(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return h(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return h(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return h(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return h(this,void 0,void 0,(function*(){return this.data}))}}p.supportsBlob="undefined"!=typeof Blob,p.supportsFile="undefined"!=typeof File,p.supportsBuffer=!1,p.supportsStream=!1,p.supportsString=!0,p.supportsArrayBuffer=!0,p.supportsEncryptFile=!0,p.supportsFileUri=!1;function g(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function y(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var f,m,b,v,w,S=S||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return v.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=S,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=S,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:g(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return h(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return h(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return h(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=P.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:M.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new o("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:y(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return h(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new o("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}M.encoder=new TextEncoder,M.decoder=new TextDecoder;class j extends d{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new o("Crypto module error: cipher key not set.");return new j({default:new M(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new o("Crypto module error: cipher key not set.");return new j({default:new E({cipherKey:e.cipherKey}),cryptors:[new M(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(j.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return h(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?g(e):e,s=_.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return h(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=_.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return h(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof p)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}j.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==_.SENTINEL))return j.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(n),o)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";const R=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>R(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw c.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw c.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return h(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${R(t)}`)).join("&"):`${e}=${R(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=!1,K=e=>{var t,s,n,r;return(null!==(t=e.enableServiceWorker)&&void 0!==t?t:D)&&!("serviceWorker"in navigator)&&(e.enableServiceWorker=!1),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,a,c,u,l,h,d,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.restore)&&void 0!==i||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(d=m.maintainPresenceState)&&void 0!==d||(m.maintainPresenceState=!0),null!==(p=m.keepAlive)&&void 0!==p||(m.keepAlive=!1),m.userId&&m.uuid)throw new o("PubNub client configuration error: use only 'userId'");if(null!==(g=m.userId)&&void 0!==g||(m.userId=m.uuid),!m.userId)throw new o("PubNub client configuration error: 'userId' not set");if(0===(null===(y=m.userId)||void 0===y?void 0:y.trim().length))throw new o("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),null!==(f=m.presenceTimeout)&&void 0!==f||(m.presenceTimeout=300);let v=!1,w=!0,S=5,k=!1,E=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(E=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:100,useRequestId:E,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(s=e.listenToBrowserNetworkEvents)||void 0===s||s,enableServiceWorker:null!==(n=e.enableServiceWorker)&&void 0!==n?n:D,keepAlive:null===(r=e.keepAlive)||void 0===r||r})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),$={createUUID:()=>G.uuid?G.uuid():G()};const L=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=B(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${$.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"7.6.3"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},B=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class H{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var z;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(z||(z={}));class V{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?z.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===z.POST||t===z.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=V.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${R(e)}`)).join("&"):`${t}=${R(s)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:i.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:i.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class Q{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Y{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class X{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new Q(o),this.dedupingManager=new Y({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const r=new Set,i=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],i.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],i.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],r.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],r.add(e))})),0===i.size&&0===r.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(r),s=Array.from(i),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,r=l(e,["error"]);let i;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?i=e.errorData.message:"message"in e&&"string"==typeof e.message&&(i=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},r),{error:null!=i&&i,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===i.PNCancelledCategory)return;return void(e.category===i.PNTimeoutCategory?this.startSubscribeLoop():e.category===i.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:i.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===i.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:i.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:i.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:i.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=l(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class se{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class ne{constructor(e){this.params=e,this.requestIdentifier=$.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return h(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:z.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===z.POST||r.method===z.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=ne.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var re;ne.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var oe;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(oe||(oe={}));class ae extends ne{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){let t;try{const s=ne.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?oe.Presence:oe.Message),"string"==typeof e.d?t==oe.Message?{type:oe.Message,data:this.messageFromEnvelope(e)}:{type:oe.Files,data:this.fileFromEnvelope(e)}:t==oe.Message?{type:oe.Message,data:this.messageFromEnvelope(e)}:t===oe.Presence?{type:oe.Presence,data:this.presenceEventFromEnvelope(e)}:t==oe.Signal?{type:oe.Signal,data:this.signalFromEnvelope(e)}:t===oe.AppContext?{type:oe.AppContext,data:this.appContextFromEnvelope(e)}:t===oe.MessageAction?{type:oe.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:oe.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ce extends ae{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===oe.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===oe.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===oe.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===oe.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,type:o}=s,a=l(s,["event","type"]),c=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",type:"user"})});this.listenerManager.announceUser(c),this.announce("user",c,c.spaceId,c.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,type:o}=s,a=l(s,["event","type"]),c=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(c),this.announce("space",c,c.spaceId,c.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,data:o}=s,a=l(s,["event","data"]),{uuid:c,channel:u}=o,h=l(o,["uuid","channel"]),d=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",data:Object.assign(Object.assign({},h),{user:c,space:u})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===oe.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===oe.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function fe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class me extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class be extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new me}abort(){this._aborted=!0,this.notify(new me)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new be}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,s)=>new we(t,s,e),ke=ge("RECONNECT",(()=>({}))),Ee=ge("DISCONNECT",(()=>({}))),Oe=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),je=ge("HEARTBEAT_GIVEUP",(()=>({}))),_e=ge("TIMES_UP",(()=>({}))),Ae=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Re=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ye("EMIT_STATUS",(e=>e)),Ue=fe("WAIT",(()=>({}))),Te=fe("DELAYED_HEARTBEAT",(e=>e));class Fe extends pe{constructor(e,t){super(t),this.on(Ae.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:a}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:r}),{heartbeat:a.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Re.type,Se(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ue.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Te.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:a,config:c}){if(!c.retryConfiguration||!c.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(je());s.throwIfAborted(),yield r(c.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},c.maintainPresenceState&&{state:a}),{heartbeat:c.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Oe.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Ue())),De.onExit((()=>Ue.cancel)),De.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Re(t.payload.channels,t.payload.groups)]))),De.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Re(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Re(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_FAILED");Ke.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Re(t.payload.channels,t.payload.groups)]))),Ke.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Ke.on(Ee.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Re(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Re(e.channels,e.groups)])));const qe=new he("HEARBEAT_RECONNECTING");qe.onEnter((e=>Te(e))),qe.onExit((()=>Te.cancel)),qe.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Re(t.payload.channels,t.payload.groups)]))),qe.on(Ee.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Re(e.channels,e.groups)])})),qe.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Me.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(je.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Re(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Re(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Re(e.channels,e.groups)]))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Re(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(Oe.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Oe(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),ze=fe("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),Ve=ye("EMIT_MESSAGES",(e=>e)),We=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Qe=fe("HANDSHAKE_RECONNECT",(e=>e)),Ye=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Xe=ge("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),st=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),nt=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),ot=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),at=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:a}){s.throwIfAborted();try{const i=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:r}));return e.transition(Ze(i))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(ze.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;if(!s.aborted)return e.transition(it(t))}}}))))),this.on(Ve.type,Se(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(We.type,Se(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Je.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new o(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:a.filterExpression});return e.transition(ot(r.cursor,r.messages))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(at(t))}}}))))),this.on(Qe.type,Se(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:a,config:c}){if(!c.retryConfiguration||!c.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(nt(new o(c.retryConfiguration?c.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(c.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:c.filterExpression},c.maintainPresenceState&&{state:a}));return e.transition(tt(r))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(st(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Xe.type,((e,t)=>{var s,n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Ye.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Xe.type,((e,t)=>{var s;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var s;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Xe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Xe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var s;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const mt=new he("RECEIVE_RECONNECTING");mt.onEnter((e=>Je(e))),mt.onExit((()=>Je.cancel)),mt.on(ot.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[Ve(t.payload.events)]))),mt.on(at.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(ct.type,((e,t)=>{var s;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:i.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:i.PNDisconnectedCategory})]))),mt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(Ye.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(ht.type,(e=>St.with(void 0,[We({category:i.PNDisconnectedCategory})])));const bt=new he("RECEIVING");bt.onEnter((e=>ze(e.channels,e.groups,e.cursor))),bt.onExit((()=>ze.cancel)),bt.on(rt.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[Ve(t.payload.events)]))),bt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),bt.on(Xe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(it.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:i.PNDisconnectedCategory})]))),bt.on(ht.type,(e=>St.with(void 0,[We({category:i.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Qe(e))),vt.onExit((()=>Qe.cancel)),vt.on(tt.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return bt.with({channels:e.channels,groups:e.groups,cursor:r},[We({category:i.PNConnectedCategory})])})),vt.on(st.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(nt.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:i.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var s,n;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[We({category:i.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Xe.type,((e,t)=>{var s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Xe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Ye(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Ye(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Et extends ne{constructor(e){var t,s;super({method:e.sendByPost?z.POST:z.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${R(t)}/0${this.parameters.sendByPost?"":`/${R(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:y(s))}}class Ot extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${R(s)}/0/${R(r)}`}}class Ct extends ae{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Nt extends ae{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Pt extends ne{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${R(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class jt extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends ne{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${R(t)}`}}class Rt extends ne{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(n.status>=400)throw c.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,u={};let l={};if("occupancy"in n){const e=this.parameters.channels[0];l[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else l=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(l).forEach((e=>{const t=l[e];u[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:u}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ut extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Tt extends ne{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class xt extends ne{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(s.status>=400)throw c.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Kt extends ne{constructor(e){super({method:z.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{data:t.data}}))}get headers(){return{"Content-Type":"application/json"}}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}/message/${s}`}get body(){return JSON.stringify(this.parameters.action)}}class qt extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}/message/${n}/action/${s}`}}class Gt extends ne{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${R(t)}/0/${R(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:y(s))}}class $t extends ne{constructor(e){super({method:z.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${R(e)}/files/${t}/${s}`}}class Lt extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${R(s)}/files/${t}/${n}`}}class Bt extends ne{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends ne{constructor(e){super({method:z.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/generate-upload-url`}get body(){return JSON.stringify({name:this.parameters.name})}}class zt extends ne{constructor(e){super({method:z.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?zt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Vt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return h(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new o("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:i.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof o)throw e;const t=e instanceof c?e:c.create(e);throw new o("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return h(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return h(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new zt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return h(this,void 0,void 0,(function*(){var s,n,r,a;let c,u={timetoken:"0"},l=this.parameters.fileUploadPublishRetryLimit,h=!1;do{try{u=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),h=!0}catch(e){e instanceof o&&(c=e),l-=1}}while(!h&&l>0);if(h)return{status:200,timetoken:u.timetoken,id:e,name:t};throw new o("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=c.status)||void 0===s?void 0:s.category)&&void 0!==n?n:i.PNUnknownCategory,statusCode:null!==(a=null===(r=c.status)||void 0===r?void 0:r.statusCode)&&void 0!==a?a:0,channel:this.parameters.channel,id:e,name:t})}))}}class Wt extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNAccessManagerRevokeToken}validate(){return this.parameters.keySet.secretKey?this.parameters.token?void 0:"token can't be empty":"Missing Secret Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},token:t}=this.parameters;return`/v3/pam/${e}/grant/${R(t)}`}}class Jt extends ne{constructor(e){var t,s,n,r;super({method:z.POST}),this.parameters=e,null!==(t=(n=this.parameters).resources)&&void 0!==t||(n.resources={}),null!==(s=(r=this.parameters).patterns)&&void 0!==s||(r.patterns={})}operation(){return ie.PNAccessManagerGrantToken}validate(){var e,t,s,n,r,i;const{keySet:{subscribeKey:o,publishKey:a,secretKey:c},resources:u,patterns:l}=this.parameters;if(!o)return"Missing Subscribe Key";if(!a)return"Missing Publish Key";if(!c)return"Missing Secret Key";if(!u&&!l)return"Missing either Resources or Patterns";if(this.isVspPermissions(this.parameters)&&("channels"in(null!==(e=this.parameters.resources)&&void 0!==e?e:{})||"uuids"in(null!==(t=this.parameters.resources)&&void 0!==t?t:{})||"groups"in(null!==(s=this.parameters.resources)&&void 0!==s?s:{})||"channels"in(null!==(n=this.parameters.patterns)&&void 0!==n?n:{})||"uuids"in(null!==(r=this.parameters.patterns)&&void 0!==r?r:{})||"groups"in(null!==(i=this.parameters.patterns)&&void 0!==i?i:{})))return"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`";let h=!0;return[this.parameters.resources,this.parameters.patterns].forEach((e=>{Object.keys(null!=e?e:{}).forEach((t=>{var s;e&&h&&Object.keys(null!==(s=e[t])&&void 0!==s?s:{}).length>0&&(h=!1)}))})),h?"Missing values for either Resources or Patterns":void 0}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.data.token}))}get path(){return`/v3/pam/${this.parameters.keySet.subscribeKey}/grant`}get body(){const{ttl:e,meta:t}=this.parameters,s=Object.assign({},e||0===e?{ttl:e}:{}),n=this.isVspPermissions(this.parameters)?this.parameters.authorizedUserId:this.parameters.authorized_uuid,r={},i={},o={},a=(e,t,s,n)=>{n[s]||(n[s]={}),n[s][e]=t},{resources:c,patterns:u}=this.parameters;return[c,u].forEach(((e,t)=>{var s,n,r,c,u;const l=0===t?i:o;let h={},d={},p={};l.channels||(l.channels={}),l.groups||(l.groups={}),l.uuids||(l.uuids={}),l.users||(l.users={}),l.spaces||(l.spaces={}),e&&("spaces"in e||"users"in e?(h=null!==(s=e.spaces)&&void 0!==s?s:{},p=null!==(n=e.users)&&void 0!==n?n:{}):("channels"in e||"uuids"in e||"groups"in e)&&(h=null!==(r=e.channels)&&void 0!==r?r:{},d=null!==(c=e.groups)&&void 0!==c?c:{},p=null!==(u=e.uuids)&&void 0!==u?u:{})),Object.keys(h).forEach((e=>a(e,this.extractPermissions(h[e]),"channels",l))),Object.keys(d).forEach((e=>a(e,this.extractPermissions(d[e]),"groups",l))),Object.keys(p).forEach((e=>a(e,this.extractPermissions(p[e]),"uuids",l)))})),n&&(r.uuid=`${n}`),r.resources=i,r.patterns=o,r.meta=null!=t?t:{},s.permissions=r,JSON.stringify(s)}extractPermissions(e){let t=0;return"join"in e&&e.join&&(t|=128),"update"in e&&e.update&&(t|=64),"get"in e&&e.get&&(t|=32),"delete"in e&&e.delete&&(t|=8),"manage"in e&&e.manage&&(t|=4),"write"in e&&e.write&&(t|=2),"read"in e&&e.read&&(t|=1),t}isVspPermissions(e){var t,s,n,r;return"authorizedUserId"in e||"spaces"in(null!==(t=e.resources)&&void 0!==t?t:{})||"users"in(null!==(s=e.resources)&&void 0!==s?s:{})||"spaces"in(null!==(n=e.patterns)&&void 0!==n?n:{})||"users"in(null!==(r=e.patterns)&&void 0!==r?r:{})}}class Qt extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b,v,w;super(),this.parameters=e,null!==(t=(h=this.parameters).channels)&&void 0!==t||(h.channels=[]),null!==(s=(d=this.parameters).channelGroups)&&void 0!==s||(d.channelGroups=[]),null!==(n=(p=this.parameters).uuids)&&void 0!==n||(p.uuids=[]),null!==(r=(g=this.parameters).read)&&void 0!==r||(g.read=false),null!==(i=(y=this.parameters).write)&&void 0!==i||(y.write=false),null!==(o=(f=this.parameters).delete)&&void 0!==o||(f.delete=false),null!==(a=(m=this.parameters).get)&&void 0!==a||(m.get=false),null!==(c=(b=this.parameters).update)&&void 0!==c||(b.update=false),null!==(u=(v=this.parameters).manage)&&void 0!==u||(v.manage=false),null!==(l=(w=this.parameters).join)&&void 0!==l||(w.join=false)}operation(){return ie.PNAccessManagerGrant}validate(){const{keySet:{subscribeKey:e,publishKey:t,secretKey:s},uuids:n=[],channels:r=[],channelGroups:i=[],authKeys:o=[]}=this.parameters;return e?t?s?0!==n.length&&0===o.length?"authKeys are required for grant request on uuids":!n.length||0===r.length&&0===i.length?void 0:"Both channel/channel group and uuid cannot be used in the same request":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload}))}get path(){return`/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channels:e,channelGroups:t,authKeys:s,uuids:n,read:r,write:i,manage:o,delete:a,get:c,join:u,update:l,ttl:h}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},e&&(null==e?void 0:e.length)>0?{channel:e.join(",")}:{}),t&&(null==t?void 0:t.length)>0?{"channel-group":t.join(",")}:{}),s&&(null==s?void 0:s.length)>0?{auth:s.join(",")}:{}),n&&(null==n?void 0:n.length)>0?{"target-uuid":n.join(",")}:{}),{r:r?"1":"0",w:i?"1":"0",m:o?"1":"0",d:a?"1":"0",g:c?"1":"0",j:u?"1":"0",u:l?"1":"0"}),h||0===h?{ttl:h}:{})}}const Yt=[];class Xt extends ne{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).authKeys)&&void 0!==t||(s.authKeys=Yt)}operation(){return ie.PNAccessManagerAudit}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload}))}get path(){return`/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channel:e,channelGroup:t,authKeys:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},e?{channel:e}:{}),t?{"channel-group":t}:{}),s&&s.length?{auth:s.join(",")}:{})}}class Zt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class es extends Zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class ts extends Zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new es({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ss{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new ts({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ns{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new ts({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class rs{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new ts({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class is{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new ts({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class os extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class as extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class cs extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}}class us extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}/remove`}}class ls extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return h(this,void 0,void 0,(function*(){const t=new ls({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return h(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends ne{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class ps extends ds{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class gs extends ds{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{channels:t}}))}}class ys extends ds{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class fs extends ds{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class ms{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new gs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new ys(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return h(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class bs extends ne{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vs extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}}class ws extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:z.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends ne{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Es extends ne{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class Os extends ne{constructor(e){var t,s,n;super({method:z.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Cs extends ne{constructor(e){super({method:z.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}}class Ns extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ps extends ne{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:z.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ms extends ne{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class js extends ne{constructor(e){var t,s,n;super({method:z.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class _s{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ks(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ms(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new js(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Cs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new bs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new Os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ps(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ps(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ws(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class As extends ne{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Rs extends ne{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/files/${s}/${n}`}}class Is{static notificationPayload(e,t){return new se(e,t)}static generateUUID(){return $.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new _s(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ms(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new o("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:i.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new X(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new is(e,this.eventEmitter,this)}channelGroup(e){return new ns(e,this.eventEmitter,this)}channelMetadata(e){return new ss(e,this.eventEmitter,this)}userMetadata(e){return new rs(e,this.eventEmitter,this)}subscriptionSet(e){return new es(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return h(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(a(s),null);throw new o("Validation failed, check status for details",a(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ie.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:i.PNAcknowledgmentCategory,statusCode:0},[u,l]=this.transport.makeSendable(n);return e.cancellationController=l||null,u.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Is.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof c?s:c.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return h(this,void 0,void 0,(function*(){const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}signal(e,t){return h(this,void 0,void 0,(function*(){const s=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fire(e,t){return h(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){const s=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return h(this,void 0,void 0,(function*(){const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}))}subscribeReceiveMessages(e){return h(this,void 0,void 0,(function*(){const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}))}getMessageActions(e,t){return h(this,void 0,void 0,(function*(){const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addMessageAction(e,t){return h(this,void 0,void 0,(function*(){const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMessageAction(e,t){return h(this,void 0,void 0,(function*(){const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMessages(e,t){return h(this,void 0,void 0,(function*(){const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteMessages(e,t){return h(this,void 0,void 0,(function*(){const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}messageCounts(e,t){return h(this,void 0,void 0,(function*(){const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}history(e,t){return h(this,void 0,void 0,(function*(){const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}hereNow(e,t){return h(this,void 0,void 0,(function*(){const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}whereNow(e,t){return h(this,void 0,void 0,(function*(){var s;const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}))}getState(e,t){return h(this,void 0,void 0,(function*(){var s;const n=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setState(e,t){return h(this,void 0,void 0,(function*(){var s,n;const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new jt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return h(this,void 0,void 0,(function*(){const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return h(this,void 0,void 0,(function*(){const s=new Jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}revokeToken(e,t){return h(this,void 0,void 0,(function*(){const s=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get token(){return this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager.parseToken(e)}grant(e,t){return h(this,void 0,void 0,(function*(){const s=new Qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}audit(e,t){return h(this,void 0,void 0,(function*(){const s=new Xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get objects(){return this._objects}fetchUsers(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n,r;if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Vt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ie.PNPublishFileOperation,category:i.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof o?s=e.status:e instanceof c&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new o("REST API request processing error, check status for details",s)}))}))}publishFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listFiles(e,t){return h(this,void 0,void 0,(function*(){const s=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getFileUrl(e){var t;const s=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${R(t)}`)).join("&"):`${e}=${R(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}downloadFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Rs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}))}deleteFile(e,t){return h(this,void 0,void 0,(function*(){const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}time(e){return h(this,void 0,void 0,(function*(){const t=new As;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:y(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Is.decoder=new TextDecoder,Is.OPERATIONS=ie,Is.CATEGORIES=i,Is.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,Is.LinearRetryPolicy=Be.LinearRetryPolicy;class Us{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ts extends Is{constructor(e){var t;const s=K(e),n=Object.assign(Object.assign({},s),{sdkFamily:"Web",PubNubFile:p}),i=L(n,(e=>{if(e.cipherKey)return new j({default:new M(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})})),o=new H(new Us((e=>x(r.decode(e))),g));let a;(i.getCipherKey()||i.secretKey)&&(a=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()}));let c=new F(i.keepAlive,i.logVerbosity);s.enableServiceWorker&&(c=new u({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,transport:c}));super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:o,transport:c}),cryptography:new P,tokenManager:o,crypto:a}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ts.CryptoModule=j,Ts})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,o=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new c(r,n,o,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new o(null!=t?t:this.message,this.toStatus(e))}}class u{constructor(e){this.configuration=e,this.serviceWorkerEventsQueue=[],this.callbacks=new Map,this.setupServiceWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.serviceWorker;s?s.postMessage(e):t?this.serviceWorkerEventsQueue.splice(0,0,e):this.serviceWorkerEventsQueue.push(e)}flushScheduledEvents(){const e=this.serviceWorker;if(!e||0===this.serviceWorkerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.serviceWorkerEventsQueue.forEach((t=>e.postMessage(t))),this.serviceWorkerEventsQueue=[]}get serviceWorker(){return this.serviceWorkerRegistration?this.serviceWorkerRegistration.active:null}setupServiceWorker(){if(!("serviceWorker"in navigator))return;const e=navigator.serviceWorker;e.register(this.configuration.serviceWorkerUrl,{scope:`/pubnub-${this.configuration.sdkVersion}`}).then((e=>{this.serviceWorkerRegistration=e,e.active&&this.flushScheduledEvents(),this.serviceWorkerRegistration.addEventListener("updatefound",(()=>{if(!this.serviceWorkerRegistration)return;const e=this.serviceWorkerRegistration.installing,t=()=>{"activated"===e.state?this.flushScheduledEvents():"redundant"===e.state&&e.removeEventListener("statechange",t)};e.addEventListener("statechange",t)}))})),e.addEventListener("message",(e=>this.handleServiceWorkerEvent(e)))}handleServiceWorkerEvent(e){const{data:t}=e;if(t.clientIdentifier===this.configuration.clientIdentifier)if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=i.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=i.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=i.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=i.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(c.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new c(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}function l(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return h(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return h(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return h(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return h(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return h(this,void 0,void 0,(function*(){return this.data}))}}p.supportsBlob="undefined"!=typeof Blob,p.supportsFile="undefined"!=typeof File,p.supportsBuffer=!1,p.supportsStream=!1,p.supportsString=!0,p.supportsArrayBuffer=!0,p.supportsEncryptFile=!0,p.supportsFileUri=!1;function g(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function y(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var f,m,b,v,w,S=S||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return v.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=S,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=S,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:g(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return h(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return h(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return h(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=P.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:M.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new o("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:y(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return h(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new o("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}M.encoder=new TextEncoder,M.decoder=new TextDecoder;class j extends d{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new o("Crypto module error: cipher key not set.");return new j({default:new M(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new o("Crypto module error: cipher key not set.");return new j({default:new E({cipherKey:e.cipherKey}),cryptors:[new M(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(j.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return h(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?g(e):e,s=_.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return h(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=_.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return h(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof p)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}j.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==_.SENTINEL))return j.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(n),o)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";const R=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>R(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw c.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw c.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return h(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${R(t)}`)).join("&"):`${e}=${R(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s;return e.serviceWorkerUrl&&!("serviceWorker"in navigator)&&(e.serviceWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,a,c,u,l,h,d,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.restore)&&void 0!==i||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(d=m.maintainPresenceState)&&void 0!==d||(m.maintainPresenceState=!0),null!==(p=m.keepAlive)&&void 0!==p||(m.keepAlive=!1),m.userId&&m.uuid)throw new o("PubNub client configuration error: use only 'userId'");if(null!==(g=m.userId)&&void 0!==g||(m.userId=m.uuid),!m.userId)throw new o("PubNub client configuration error: 'userId' not set");if(0===(null===(y=m.userId)||void 0===y?void 0:y.trim().length))throw new o("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),null!==(f=m.presenceTimeout)&&void 0!==f||(m.presenceTimeout=300);let v=!1,w=!0,S=5,k=!1,E=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(E=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:100,useRequestId:E,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,serviceWorkerUrl:e.serviceWorkerUrl,keepAlive:null===(s=e.keepAlive)||void 0===s||s})};var K={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(K,K.exports);var q=t(K.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.0.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${R(e)}`)).join("&"):`${t}=${R(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:i.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:i.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const r=new Set,i=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],i.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],i.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],r.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],r.add(e))})),0===i.size&&0===r.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(r),s=Array.from(i),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,r=l(e,["error"]);let i;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?i=e.errorData.message:"message"in e&&"string"==typeof e.message&&(i=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},r),{error:null!=i&&i,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===i.PNCancelledCategory)return;return void(e.category===i.PNTimeoutCategory?this.startSubscribeLoop():e.category===i.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:i.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===i.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:i.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:i.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:i.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=l(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return h(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,type:o}=s,a=l(s,["event","type"]),c=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",type:"user"})});this.listenerManager.announceUser(c),this.announce("user",c,c.spaceId,c.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,type:o}=s,a=l(s,["event","type"]),c=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(c),this.announce("space",c,c.spaceId,c.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,data:o}=s,a=l(s,["event","data"]),{uuid:c,channel:u}=o,h=l(o,["uuid","channel"]),d=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",data:Object.assign(Object.assign({},h),{user:c,space:u})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),je=pe("TIMES_UP",(()=>({}))),_e=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Re=ge("EMIT_STATUS",(e=>e)),Ie=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(_e.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:a}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:r}),{heartbeat:a.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ae.type,we(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(je())}))))),this.on(Ue.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:a,config:c}){if(!c.retryConfiguration||!c.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(c.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},c.maintainPresenceState&&{state:a}),{heartbeat:c.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Re.type,we(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ge.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Ie())),xe.onExit((()=>Ie.cancel)),xe.on(je.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ke=new le("HEARBEAT_RECONNECTING");Ke.onEnter((e=>Ue(e))),Ke.onExit((()=>Ue.cancel)),Ke.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Ke.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),Ke.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ke.on(Pe.type,((e,t)=>Ke.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ke.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new le("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new le("HEARTBEAT_INACTIVE");Ge.on(Ee.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:a}){s.throwIfAborted();try{const i=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:r}));return e.transition(Xe(i))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new o(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:a.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:a,config:c}){if(!c.retryConfiguration||!c.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new o(c.retryConfiguration?c.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(c.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:c.filterExpression},c.maintainPresenceState&&{state:a}));return e.transition(et(r))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:i.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:i.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:i.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:i.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:i.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:i.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:i.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:i.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${R(t)}/0${this.parameters.sendByPost?"":`/${R(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:y(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${R(s)}/0/${R(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${R(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${R(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(n.status>=400)throw c.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,u={};let l={};if("occupancy"in n){const e=this.parameters.channels[0];l[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else l=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(l).forEach((e=>{const t=l[e];u[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:u}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class Rt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(s.status>=400)throw c.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{data:t.data}}))}get headers(){return{"Content-Type":"application/json"}}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}/message/${s}`}get body(){return JSON.stringify(this.parameters.action)}}class Kt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${R(t)}/0/${R(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:y(s))}}class Gt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${R(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${R(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/generate-upload-url`}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return h(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new o("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:i.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof o)throw e;const t=e instanceof c?e:c.create(e);throw new o("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return h(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return h(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return h(this,void 0,void 0,(function*(){var s,n,r,a;let c,u={timetoken:"0"},l=this.parameters.fileUploadPublishRetryLimit,h=!1;do{try{u=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),h=!0}catch(e){e instanceof o&&(c=e),l-=1}}while(!h&&l>0);if(h)return{status:200,timetoken:u.timetoken,id:e,name:t};throw new o("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=c.status)||void 0===s?void 0:s.category)&&void 0!==n?n:i.PNUnknownCategory,statusCode:null!==(a=null===(r=c.status)||void 0===r?void 0:r.statusCode)&&void 0!==a?a:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNAccessManagerRevokeToken}validate(){return this.parameters.keySet.secretKey?this.parameters.token?void 0:"token can't be empty":"Missing Secret Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},token:t}=this.parameters;return`/v3/pam/${e}/grant/${R(t)}`}}class Wt extends se{constructor(e){var t,s,n,r;super({method:H.POST}),this.parameters=e,null!==(t=(n=this.parameters).resources)&&void 0!==t||(n.resources={}),null!==(s=(r=this.parameters).patterns)&&void 0!==s||(r.patterns={})}operation(){return re.PNAccessManagerGrantToken}validate(){var e,t,s,n,r,i;const{keySet:{subscribeKey:o,publishKey:a,secretKey:c},resources:u,patterns:l}=this.parameters;if(!o)return"Missing Subscribe Key";if(!a)return"Missing Publish Key";if(!c)return"Missing Secret Key";if(!u&&!l)return"Missing either Resources or Patterns";if(this.isVspPermissions(this.parameters)&&("channels"in(null!==(e=this.parameters.resources)&&void 0!==e?e:{})||"uuids"in(null!==(t=this.parameters.resources)&&void 0!==t?t:{})||"groups"in(null!==(s=this.parameters.resources)&&void 0!==s?s:{})||"channels"in(null!==(n=this.parameters.patterns)&&void 0!==n?n:{})||"uuids"in(null!==(r=this.parameters.patterns)&&void 0!==r?r:{})||"groups"in(null!==(i=this.parameters.patterns)&&void 0!==i?i:{})))return"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`";let h=!0;return[this.parameters.resources,this.parameters.patterns].forEach((e=>{Object.keys(null!=e?e:{}).forEach((t=>{var s;e&&h&&Object.keys(null!==(s=e[t])&&void 0!==s?s:{}).length>0&&(h=!1)}))})),h?"Missing values for either Resources or Patterns":void 0}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.data.token}))}get path(){return`/v3/pam/${this.parameters.keySet.subscribeKey}/grant`}get body(){const{ttl:e,meta:t}=this.parameters,s=Object.assign({},e||0===e?{ttl:e}:{}),n=this.isVspPermissions(this.parameters)?this.parameters.authorizedUserId:this.parameters.authorized_uuid,r={},i={},o={},a=(e,t,s,n)=>{n[s]||(n[s]={}),n[s][e]=t},{resources:c,patterns:u}=this.parameters;return[c,u].forEach(((e,t)=>{var s,n,r,c,u;const l=0===t?i:o;let h={},d={},p={};l.channels||(l.channels={}),l.groups||(l.groups={}),l.uuids||(l.uuids={}),l.users||(l.users={}),l.spaces||(l.spaces={}),e&&("spaces"in e||"users"in e?(h=null!==(s=e.spaces)&&void 0!==s?s:{},p=null!==(n=e.users)&&void 0!==n?n:{}):("channels"in e||"uuids"in e||"groups"in e)&&(h=null!==(r=e.channels)&&void 0!==r?r:{},d=null!==(c=e.groups)&&void 0!==c?c:{},p=null!==(u=e.uuids)&&void 0!==u?u:{})),Object.keys(h).forEach((e=>a(e,this.extractPermissions(h[e]),"channels",l))),Object.keys(d).forEach((e=>a(e,this.extractPermissions(d[e]),"groups",l))),Object.keys(p).forEach((e=>a(e,this.extractPermissions(p[e]),"uuids",l)))})),n&&(r.uuid=`${n}`),r.resources=i,r.patterns=o,r.meta=null!=t?t:{},s.permissions=r,JSON.stringify(s)}extractPermissions(e){let t=0;return"join"in e&&e.join&&(t|=128),"update"in e&&e.update&&(t|=64),"get"in e&&e.get&&(t|=32),"delete"in e&&e.delete&&(t|=8),"manage"in e&&e.manage&&(t|=4),"write"in e&&e.write&&(t|=2),"read"in e&&e.read&&(t|=1),t}isVspPermissions(e){var t,s,n,r;return"authorizedUserId"in e||"spaces"in(null!==(t=e.resources)&&void 0!==t?t:{})||"users"in(null!==(s=e.resources)&&void 0!==s?s:{})||"spaces"in(null!==(n=e.patterns)&&void 0!==n?n:{})||"users"in(null!==(r=e.patterns)&&void 0!==r?r:{})}}class Jt extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b,v,w;super(),this.parameters=e,null!==(t=(h=this.parameters).channels)&&void 0!==t||(h.channels=[]),null!==(s=(d=this.parameters).channelGroups)&&void 0!==s||(d.channelGroups=[]),null!==(n=(p=this.parameters).uuids)&&void 0!==n||(p.uuids=[]),null!==(r=(g=this.parameters).read)&&void 0!==r||(g.read=false),null!==(i=(y=this.parameters).write)&&void 0!==i||(y.write=false),null!==(o=(f=this.parameters).delete)&&void 0!==o||(f.delete=false),null!==(a=(m=this.parameters).get)&&void 0!==a||(m.get=false),null!==(c=(b=this.parameters).update)&&void 0!==c||(b.update=false),null!==(u=(v=this.parameters).manage)&&void 0!==u||(v.manage=false),null!==(l=(w=this.parameters).join)&&void 0!==l||(w.join=false)}operation(){return re.PNAccessManagerGrant}validate(){const{keySet:{subscribeKey:e,publishKey:t,secretKey:s},uuids:n=[],channels:r=[],channelGroups:i=[],authKeys:o=[]}=this.parameters;return e?t?s?0!==n.length&&0===o.length?"authKeys are required for grant request on uuids":!n.length||0===r.length&&0===i.length?void 0:"Both channel/channel group and uuid cannot be used in the same request":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload}))}get path(){return`/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channels:e,channelGroups:t,authKeys:s,uuids:n,read:r,write:i,manage:o,delete:a,get:c,join:u,update:l,ttl:h}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},e&&(null==e?void 0:e.length)>0?{channel:e.join(",")}:{}),t&&(null==t?void 0:t.length)>0?{"channel-group":t.join(",")}:{}),s&&(null==s?void 0:s.length)>0?{auth:s.join(",")}:{}),n&&(null==n?void 0:n.length)>0?{"target-uuid":n.join(",")}:{}),{r:r?"1":"0",w:i?"1":"0",m:o?"1":"0",d:a?"1":"0",g:c?"1":"0",j:u?"1":"0",u:l?"1":"0"}),h||0===h?{ttl:h}:{})}}const Qt=[];class Yt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).authKeys)&&void 0!==t||(s.authKeys=Qt)}operation(){return re.PNAccessManagerAudit}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload}))}get path(){return`/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channel:e,channelGroup:t,authKeys:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},e?{channel:e}:{}),t?{"channel-group":t}:{}),s&&s.length?{auth:s.join(",")}:{})}}class Xt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Zt extends Xt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class es extends Xt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Zt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ts{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new es({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ss{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new es({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ns{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new es({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class rs{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new es({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class is extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class os extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class as extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}}class cs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}/remove`}}class us extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class ls{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return h(this,void 0,void 0,(function*(){const t=new us({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new is(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return h(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class ds extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class ps extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{channels:t}}))}}class gs extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class ys extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class fs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new gs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return h(this,void 0,void 0,(function*(){const s=new ys(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ms extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}}class Cs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ns extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ps extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Ms extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class js{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new Ss(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Os(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ms(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class _s extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class As extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/files/${s}/${n}`}}class Rs{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new js(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new fs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new o("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:i.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new rs(e,this.eventEmitter,this)}channelGroup(e){return new ss(e,this.eventEmitter,this)}channelMetadata(e){return new ts(e,this.eventEmitter,this)}userMetadata(e){return new ns(e,this.eventEmitter,this)}subscriptionSet(e){return new Zt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return h(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(a(s),null);throw new o("Validation failed, check status for details",a(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:i.PNAcknowledgmentCategory,statusCode:0},[u,l]=this.transport.makeSendable(n);return e.cancellationController=l||null,u.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Rs.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof c?s:c.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return h(this,void 0,void 0,(function*(){const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}signal(e,t){return h(this,void 0,void 0,(function*(){const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fire(e,t){return h(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return h(this,void 0,void 0,(function*(){const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}))}subscribeReceiveMessages(e){return h(this,void 0,void 0,(function*(){const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}))}getMessageActions(e,t){return h(this,void 0,void 0,(function*(){const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addMessageAction(e,t){return h(this,void 0,void 0,(function*(){const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMessageAction(e,t){return h(this,void 0,void 0,(function*(){const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMessages(e,t){return h(this,void 0,void 0,(function*(){const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteMessages(e,t){return h(this,void 0,void 0,(function*(){const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}messageCounts(e,t){return h(this,void 0,void 0,(function*(){const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}history(e,t){return h(this,void 0,void 0,(function*(){const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}hereNow(e,t){return h(this,void 0,void 0,(function*(){const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}whereNow(e,t){return h(this,void 0,void 0,(function*(){var s;const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}))}getState(e,t){return h(this,void 0,void 0,(function*(){var s;const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setState(e,t){return h(this,void 0,void 0,(function*(){var s,n;const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return h(this,void 0,void 0,(function*(){const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return h(this,void 0,void 0,(function*(){const s=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}revokeToken(e,t){return h(this,void 0,void 0,(function*(){const s=new Vt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get token(){return this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager.parseToken(e)}grant(e,t){return h(this,void 0,void 0,(function*(){const s=new Jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}audit(e,t){return h(this,void 0,void 0,(function*(){const s=new Yt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get objects(){return this._objects}fetchUsers(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n,r;if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:i.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof o?s=e.status:e instanceof c&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new o("REST API request processing error, check status for details",s)}))}))}publishFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listFiles(e,t){return h(this,void 0,void 0,(function*(){const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getFileUrl(e){var t;const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${R(t)}`)).join("&"):`${e}=${R(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}downloadFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new As(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}))}deleteFile(e,t){return h(this,void 0,void 0,(function*(){const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}time(e){return h(this,void 0,void 0,(function*(){const t=new _s;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:y(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Rs.decoder=new TextDecoder,Rs.OPERATIONS=re,Rs.CATEGORIES=i,Rs.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Rs.LinearRetryPolicy=Le.LinearRetryPolicy;class Is{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Us extends Rs{constructor(e){var t;const s=D(e),n=Object.assign(Object.assign({},s),{sdkFamily:"Web",PubNubFile:p}),i=$(n,(e=>{if(e.cipherKey)return new j({default:new M(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})})),o=new B(new Is((e=>x(r.decode(e))),g));let a;(i.getCipherKey()||i.secretKey)&&(a=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()}));let c=new F(i.keepAlive,i.logVerbosity);s.serviceWorkerUrl&&(c=new u({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,serviceWorkerUrl:s.serviceWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,transport:c}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:c}),cryptography:new P,tokenManager:o,crypto:a}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Us.CryptoModule=j,Us})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 1b564c93b..07ff0840d 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -86,7 +86,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '7.6.3'; + return '8.0.1'; }, getVersion() { return this.version; diff --git a/package-lock.json b/package-lock.json index 089766f5a..a075d7e07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "7.6.3", + "version": "8.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "7.6.3", + "version": "8.0.0", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", @@ -38,7 +38,6 @@ "@types/mocha": "^9.1.0", "@types/nock": "^9.3.1", "@types/node-fetch": "^2.6.11", - "@types/pubnub": "^7.2.0", "@types/sinon": "^17.0.3", "@types/text-encoding": "^0.0.39", "@types/underscore": "^1.11.15", @@ -4815,12 +4814,6 @@ "integrity": "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==", "dev": true }, - "node_modules/@types/pubnub": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/@types/pubnub/-/pubnub-7.4.2.tgz", - "integrity": "sha512-Vjkol3ix8IMrFdwtrLP9XkWc93cWDYpfs4tK6pvOUi8/G5+og2NRJ0AcGhMAQ4wuciHxDzJNkpPIGpRAgYAa4A==", - "dev": true - }, "node_modules/@types/resolve": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", diff --git a/package.json b/package.json index c28f88b83..6eeacb20e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.0.0", + "version": "8.0.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 7bf76b8d6..d46d2c5f1 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -163,7 +163,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.0.0'; + return '8.0.1'; }, getVersion(): string { return this.version; diff --git a/src/transport/service-worker/subscription-service-worker-middleware.ts b/src/transport/service-worker/subscription-service-worker-middleware.ts index 7e03303e1..9e5c82d06 100644 --- a/src/transport/service-worker/subscription-service-worker-middleware.ts +++ b/src/transport/service-worker/subscription-service-worker-middleware.ts @@ -28,6 +28,11 @@ type PubNubMiddlewareConfiguration = { */ subscriptionKey: string; + /** + * Url of the hoster `Subscription` service worker file. + */ + serviceWorkerUrl: string; + /** * Current PubNub client version. */ @@ -190,7 +195,7 @@ export class SubscriptionServiceWorkerMiddleware implements Transport { if (!('serviceWorker' in navigator)) return; const serviceWorkerContainer = navigator.serviceWorker as ServiceWorkerContainer; serviceWorkerContainer - .register(`SERVICE_WORKER_CDN/SERVICE_WORKER_FILE_PLACEHOLDER`, { + .register(this.configuration.serviceWorkerUrl, { scope: `/pubnub-${this.configuration.sdkVersion}`, }) .then((registration) => { diff --git a/src/web/components/configuration.ts b/src/web/components/configuration.ts index 583c0361b..651cd1530 100644 --- a/src/web/components/configuration.ts +++ b/src/web/components/configuration.ts @@ -17,12 +17,6 @@ import { */ const LISTEN_TO_BROWSER_NETWORK_EVENTS = true; -/** - * Whether PubNub client should spawn `Subscription` service worker for better user presence - * experience or not. - */ -const ENABLE_SERVICE_WORKER = false; - /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -43,12 +37,15 @@ export type PubNubConfiguration = UserConfiguration & { listenToBrowserNetworkEvents?: boolean; /** - * Whether PubNub client should spawn `Subscription` service worker for better user presence - * experience or not. + * Path to the hosted PubNub `Subscription` service worker. * - * @default `true` (if supported) + * **Important:** Serving server should add `Service-Worker-Allowed: /` to response on service worker file request to + * make it possible for PubNub SDK use own `scope`. + * **Important:** Service worker file should be server from the same domain where PubNub client will be used. If + * statics provided from `subdomain.main.com` and page loaded from `account.main.com` - then server should be + * configured to serve worker file from `account.main.com`. */ - enableServiceWorker?: boolean; + serviceWorkerUrl?: string | null; /** * If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of @@ -66,15 +63,14 @@ export type PubNubConfiguration = UserConfiguration & { */ export const setDefaults = (configuration: PubNubConfiguration): PubNubConfiguration & ExtendedConfiguration => { // Force disable service workers if environment doesn't support them. - if ((configuration.enableServiceWorker ?? ENABLE_SERVICE_WORKER) && !('serviceWorker' in navigator)) - configuration.enableServiceWorker = false; + if (configuration.serviceWorkerUrl && !('serviceWorker' in navigator)) configuration.serviceWorkerUrl = null; return { // Set base configuration defaults. ...setBaseDefaults(configuration), // Set platform-specific options. listenToBrowserNetworkEvents: configuration.listenToBrowserNetworkEvents ?? LISTEN_TO_BROWSER_NETWORK_EVENTS, - enableServiceWorker: configuration.enableServiceWorker ?? ENABLE_SERVICE_WORKER, + serviceWorkerUrl: configuration.serviceWorkerUrl, keepAlive: configuration.keepAlive ?? KEEP_ALIVE, }; }; diff --git a/src/web/index.ts b/src/web/index.ts index 3d3c5f05c..5fc10654b 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -69,11 +69,12 @@ export default class PubNub extends PubNubCore Date: Thu, 16 May 2024 13:56:42 +0300 Subject: [PATCH 07/49] Migrate to `SharedWorker` (#371) feat(shared-worker): migrate to shared worker Use `SharedWorker` instead of `Service Worker` for better PubNub client instances feedback. feat(shared-worker): add worker log verbosity flag Add configuration option to enable debug log output from the subscription `SharedWorker`. refactor: add declarations generation Create types declaration files. --- .prettierrc | 1 + .pubnub.yml | 15 +- CHANGELOG.md | 10 + README.md | 4 +- dist/web/pubnub.js | 1612 ++++++++++------- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 452 +++-- dist/web/pubnub.worker.min.js | 4 +- lib/cbor/common.js | 15 + lib/core/components/abort_signal.js | 5 + lib/core/components/base64_codec.js | 50 +- lib/core/components/configuration.js | 39 +- .../components/cryptography/hmac-sha256.js | 14 + lib/core/components/cryptography/index.js | 139 +- lib/core/components/deduping_manager.js | 10 +- lib/core/components/eventEmitter.js | 49 + lib/core/components/listener_manager.js | 91 + lib/core/components/push_payload.js | 248 +++ lib/core/components/reconnection_manager.js | 23 + lib/core/components/request.js | 81 + lib/core/components/stringify_buffer_keys.js | 9 + lib/core/components/subject.js | 3 + lib/core/components/subscription-manager.js | 44 + lib/core/components/token_manager.js | 37 + lib/core/components/uuid.js | 1 + lib/core/constants/categories.js | 62 + lib/core/constants/operations.js | 183 ++ lib/core/endpoints/access_manager/audit.js | 17 + lib/core/endpoints/access_manager/grant.js | 35 + .../endpoints/access_manager/grant_token.js | 28 + .../endpoints/access_manager/revoke_token.js | 11 + .../endpoints/actions/add_message_action.js | 9 + .../endpoints/actions/get_message_actions.js | 9 + .../actions/remove_message_action.js | 9 + .../endpoints/channel_groups/add_channels.js | 9 + .../endpoints/channel_groups/delete_group.js | 9 + .../endpoints/channel_groups/list_channels.js | 9 + .../endpoints/channel_groups/list_groups.js | 9 + .../channel_groups/remove_channels.js | 10 + lib/core/endpoints/fetch_messages.js | 52 + lib/core/endpoints/file_upload/delete_file.js | 9 + .../endpoints/file_upload/download_file.js | 9 + .../file_upload/generate_upload_url.js | 9 + .../endpoints/file_upload/get_file_url.js | 16 + lib/core/endpoints/file_upload/list_files.js | 17 + .../endpoints/file_upload/publish_file.js | 28 + lib/core/endpoints/file_upload/send_file.js | 24 + lib/core/endpoints/file_upload/upload-file.js | 9 + lib/core/endpoints/history/delete_messages.js | 9 + lib/core/endpoints/history/get_history.js | 27 + lib/core/endpoints/history/message_counts.js | 9 + lib/core/endpoints/objects/channel/get.js | 17 + lib/core/endpoints/objects/channel/get_all.js | 23 + lib/core/endpoints/objects/channel/remove.js | 9 + lib/core/endpoints/objects/channel/set.js | 17 + lib/core/endpoints/objects/member/get.js | 38 + lib/core/endpoints/objects/member/set.js | 29 + lib/core/endpoints/objects/membership/get.js | 39 + lib/core/endpoints/objects/membership/set.js | 30 + lib/core/endpoints/objects/uuid/get.js | 18 + lib/core/endpoints/objects/uuid/get_all.js | 20 + lib/core/endpoints/objects/uuid/remove.js | 10 + lib/core/endpoints/objects/uuid/set.js | 18 + lib/core/endpoints/presence/get_state.js | 10 + lib/core/endpoints/presence/heartbeat.js | 9 + lib/core/endpoints/presence/here_now.js | 22 + lib/core/endpoints/presence/leave.js | 9 + lib/core/endpoints/presence/set_state.js | 9 + lib/core/endpoints/presence/where_now.js | 9 + lib/core/endpoints/publish.js | 36 + lib/core/endpoints/push/add_push_channels.js | 10 + lib/core/endpoints/push/list_push_channels.js | 10 + lib/core/endpoints/push/push.js | 20 + lib/core/endpoints/push/remove_device.js | 10 + .../endpoints/push/remove_push_channels.js | 10 + lib/core/endpoints/signal.js | 9 + lib/core/endpoints/subscribe.js | 76 + .../endpoints/subscriptionUtils/handshake.js | 10 + .../subscriptionUtils/receiveMessages.js | 8 + lib/core/endpoints/time.js | 9 + lib/core/interfaces/configuration.js | 98 +- lib/core/interfaces/crypto-module.js | 42 + lib/core/interfaces/cryptography.js | 3 + lib/core/pubnub-channel-groups.js | 51 +- lib/core/pubnub-common.js | 909 ++++++++++ lib/core/pubnub-objects.js | 227 ++- lib/core/pubnub-push.js | 33 +- lib/core/types/api/access-panager.js | 2 + lib/core/types/api/app-context.js | 1 + lib/core/types/api/file-sharing.js | 4 + lib/core/types/api/history.js | 17 + lib/core/types/api/index.js | 1 + lib/core/types/api/presence.js | 1 + lib/core/types/api/push.js | 1 + lib/core/types/file.js | 3 + lib/core/types/transport-request.js | 22 + lib/core/utils.js | 31 +- lib/crypto/index.js | 1 + .../modules/NodeCryptoModule/ICryptor.js | 3 + .../NodeCryptoModule/ILegacyCryptor.js | 3 + .../modules/NodeCryptoModule/aesCbcCryptor.js | 43 + .../modules/NodeCryptoModule/legacyCryptor.js | 20 + .../NodeCryptoModule/nodeCryptoModule.js | 111 ++ lib/crypto/modules/node.js | 94 + lib/errors/pubnub-api-error.js | 58 + lib/event-engine/core/change.js | 1 + lib/event-engine/core/dispatcher.js | 1 + lib/event-engine/core/engine.js | 1 + lib/event-engine/core/handler.js | 2 + lib/event-engine/core/retryPolicy.js | 2 + lib/event-engine/core/state.js | 1 + lib/event-engine/core/types.js | 1 + lib/event-engine/index.js | 4 +- lib/event-engine/presence/effects.js | 1 + lib/file/modules/node.js | 72 + lib/file/modules/react-native.js | 78 + lib/node/configuration.js | 23 +- lib/node/index.js | 114 +- lib/react_native/configuration.js | 7 + lib/react_native/index.js | 8 + lib/transport/middleware.js | 30 + lib/transport/node-transport.js | 52 + lib/transport/web-react-native-transport.js | 35 + lib/types/cbor/common.d.ts | 4 + lib/types/core/components/abort_signal.d.ts | 4 + lib/types/core/components/base64_codec.d.ts | 1 + lib/types/core/components/configuration.d.ts | 4 + .../components/cryptography/hmac-sha256.d.ts | 3 + .../core/components/cryptography/index.d.ts | 143 ++ .../core/components/deduping_manager.d.ts | 16 + lib/types/core/components/eventEmitter.d.ts | 1 + .../core/components/listener_manager.d.ts | 76 + lib/types/core/components/push_payload.d.ts | 636 +++++++ .../core/components/reconnection_manager.d.ts | 6 + lib/types/core/components/request.d.ts | 1 + .../components/stringify_buffer_keys.d.ts | 1 + lib/types/core/components/subject.d.ts | 1 + .../core/components/subscription-manager.d.ts | 4 + lib/types/core/components/token_manager.d.ts | 4 + lib/types/core/components/uuid.d.ts | 4 + lib/types/core/constants/categories.d.ts | 75 + lib/types/core/constants/operations.d.ts | 203 +++ .../core/endpoints/access_manager/audit.d.ts | 4 + .../core/endpoints/access_manager/grant.d.ts | 4 + .../endpoints/access_manager/grant_token.d.ts | 4 + .../access_manager/revoke_token.d.ts | 4 + .../endpoints/actions/add_message_action.d.ts | 4 + .../actions/get_message_actions.d.ts | 4 + .../actions/remove_message_action.d.ts | 4 + .../channel_groups/add_channels.d.ts | 4 + .../channel_groups/delete_group.d.ts | 4 + .../channel_groups/list_channels.d.ts | 4 + .../endpoints/channel_groups/list_groups.d.ts | 4 + .../channel_groups/remove_channels.d.ts | 4 + lib/types/core/endpoints/fetch_messages.d.ts | 4 + .../endpoints/file_upload/delete_file.d.ts | 4 + .../endpoints/file_upload/download_file.d.ts | 4 + .../file_upload/generate_upload_url.d.ts | 4 + .../endpoints/file_upload/get_file_url.d.ts | 4 + .../endpoints/file_upload/list_files.d.ts | 4 + .../endpoints/file_upload/publish_file.d.ts | 4 + .../core/endpoints/file_upload/send_file.d.ts | 1 + .../endpoints/file_upload/upload-file.d.ts | 4 + .../endpoints/history/delete_messages.d.ts | 4 + .../core/endpoints/history/get_history.d.ts | 4 + .../endpoints/history/message_counts.d.ts | 4 + .../core/endpoints/objects/channel/get.d.ts | 4 + .../endpoints/objects/channel/get_all.d.ts | 4 + .../endpoints/objects/channel/remove.d.ts | 4 + .../core/endpoints/objects/channel/set.d.ts | 4 + .../core/endpoints/objects/member/get.d.ts | 4 + .../core/endpoints/objects/member/set.d.ts | 4 + .../endpoints/objects/membership/get.d.ts | 4 + .../endpoints/objects/membership/set.d.ts | 4 + .../core/endpoints/objects/uuid/get.d.ts | 4 + .../core/endpoints/objects/uuid/get_all.d.ts | 4 + .../core/endpoints/objects/uuid/remove.d.ts | 4 + .../core/endpoints/objects/uuid/set.d.ts | 4 + .../core/endpoints/presence/get_state.d.ts | 4 + .../core/endpoints/presence/heartbeat.d.ts | 4 + .../core/endpoints/presence/here_now.d.ts | 4 + lib/types/core/endpoints/presence/leave.d.ts | 4 + .../core/endpoints/presence/set_state.d.ts | 4 + .../core/endpoints/presence/where_now.d.ts | 4 + lib/types/core/endpoints/publish.d.ts | 69 + .../endpoints/push/add_push_channels.d.ts | 4 + .../endpoints/push/list_push_channels.d.ts | 4 + lib/types/core/endpoints/push/push.d.ts | 4 + .../core/endpoints/push/remove_device.d.ts | 4 + .../endpoints/push/remove_push_channels.d.ts | 4 + lib/types/core/endpoints/signal.d.ts | 28 + lib/types/core/endpoints/subscribe.d.ts | 4 + .../subscriptionUtils/handshake.d.ts | 4 + .../subscriptionUtils/receiveMessages.d.ts | 4 + lib/types/core/endpoints/time.d.ts | 12 + lib/types/core/interfaces/configuration.d.ts | 276 +++ lib/types/core/interfaces/crypto-module.d.ts | 152 ++ lib/types/core/interfaces/cryptography.d.ts | 54 + lib/types/core/interfaces/request.d.ts | 1 + lib/types/core/interfaces/transport.d.ts | 61 + lib/types/core/pubnub-channel-groups.d.ts | 86 + lib/types/core/pubnub-common.d.ts | 1300 +++++++++++++ lib/types/core/pubnub-objects.d.ts | 364 ++++ lib/types/core/pubnub-push.d.ts | 64 + lib/types/core/types/api/access-panager.d.ts | 466 +++++ lib/types/core/types/api/app-context.d.ts | 875 +++++++++ lib/types/core/types/api/channel-groups.d.ts | 57 + lib/types/core/types/api/file-sharing.d.ts | 357 ++++ lib/types/core/types/api/history.d.ts | 395 ++++ lib/types/core/types/api/index.d.ts | 121 ++ lib/types/core/types/api/message-action.d.ts | 153 ++ lib/types/core/types/api/presence.d.ts | 210 +++ .../core/types/api/push-notifications.d.ts | 48 + lib/types/core/types/api/push.d.ts | 122 ++ lib/types/core/types/api/subscription.d.ts | 296 +++ lib/types/core/types/file.d.ts | 104 ++ lib/types/core/types/transport-request.d.ts | 97 + lib/types/core/types/transport-response.d.ts | 23 + lib/types/core/utils.d.ts | 31 + lib/types/crypto/index.d.ts | 0 .../modules/NodeCryptoModule/ICryptor.d.ts | 86 + .../NodeCryptoModule/ILegacyCryptor.d.ts | 60 + .../NodeCryptoModule/aesCbcCryptor.d.ts | 57 + .../NodeCryptoModule/legacyCryptor.d.ts | 33 + .../NodeCryptoModule/nodeCryptoModule.d.ts | 108 ++ lib/types/crypto/modules/node.d.ts | 97 + lib/types/entities/Channel.d.ts | 11 + lib/types/entities/ChannelGroup.d.ts | 11 + lib/types/entities/ChannelMetadata.d.ts | 11 + lib/types/entities/SubscribeCapable.d.ts | 25 + lib/types/entities/Subscription.d.ts | 22 + lib/types/entities/SubscriptionSet.d.ts | 27 + lib/types/entities/UserMetadata.d.ts | 11 + lib/types/entities/commonTypes.d.ts | 7 + lib/types/errors/pubnub-api-error.d.ts | 73 + lib/types/errors/pubnub-error.d.ts | 6 + lib/types/event-engine/core/change.d.ts | 24 + lib/types/event-engine/core/dispatcher.d.ts | 13 + lib/types/event-engine/core/engine.d.ts | 11 + lib/types/event-engine/core/handler.d.ts | 18 + lib/types/event-engine/core/index.d.ts | 4 + lib/types/event-engine/core/retryPolicy.d.ts | 58 + lib/types/event-engine/core/state.d.ts | 21 + lib/types/event-engine/core/types.d.ts | 45 + lib/types/event-engine/dispatcher.d.ts | 27 + lib/types/event-engine/effects.d.ts | 77 + lib/types/event-engine/events.d.ts | 159 ++ lib/types/event-engine/index.d.ts | 33 + .../event-engine/presence/dispatcher.d.ts | 18 + lib/types/event-engine/presence/effects.d.ts | 31 + lib/types/event-engine/presence/events.d.ts | 47 + lib/types/event-engine/presence/presence.d.ts | 24 + .../presence/states/heartbeat_cooldown.d.ts | 8 + .../presence/states/heartbeat_failed.d.ts | 8 + .../presence/states/heartbeat_inactive.d.ts | 4 + .../states/heartbeat_reconnecting.d.ts | 11 + .../presence/states/heartbeat_stopped.d.ts | 8 + .../presence/states/heartbeating.d.ts | 8 + .../event-engine/states/handshake_failed.d.ts | 12 + .../states/handshake_reconnecting.d.ts | 13 + .../states/handshake_stopped.d.ts | 11 + .../event-engine/states/handshaking.d.ts | 10 + .../event-engine/states/receive_failed.d.ts | 12 + .../states/receive_reconnecting.d.ts | 13 + .../event-engine/states/receive_stopped.d.ts | 11 + lib/types/event-engine/states/receiving.d.ts | 10 + .../event-engine/states/unsubscribed.d.ts | 4 + lib/types/file/modules/node.d.ts | 134 ++ lib/types/file/modules/react-native.d.ts | 135 ++ lib/types/models/Cursor.d.ts | 4 + lib/types/node/configuration.d.ts | 54 + lib/types/node/index.d.ts | 38 + lib/types/react_native/configuration.d.ts | 5 + lib/types/react_native/index.d.ts | 10 + lib/types/transport/middleware.d.ts | 73 + lib/types/transport/node-transport.d.ts | 69 + .../transport/web-react-native-transport.d.ts | 36 + package-lock.json | 4 +- package.json | 3 +- rollup.config.js | 12 +- src/cbor/common.ts | 2 + src/core/components/abort_signal.ts | 5 + src/core/components/base64_codec.ts | 10 + src/core/components/configuration.ts | 8 +- src/core/components/deduping_manager.js | 5 + src/core/components/eventEmitter.ts | 8 + src/core/components/listener_manager.ts | 2 + src/core/components/reconnection_manager.ts | 7 + src/core/components/request.ts | 2 + src/core/components/stringify_buffer_keys.ts | 9 + src/core/components/subject.ts | 3 + src/core/components/subscription-manager.ts | 2 + src/core/components/token_manager.ts | 2 + src/core/endpoints/access_manager/audit.ts | 2 + src/core/endpoints/access_manager/grant.ts | 2 + .../endpoints/access_manager/grant_token.ts | 2 + .../endpoints/access_manager/revoke_token.ts | 2 + .../endpoints/actions/add_message_action.ts | 2 + .../endpoints/actions/get_message_actions.ts | 2 + .../actions/remove_message_action.ts | 2 + .../endpoints/channel_groups/add_channels.ts | 2 + .../endpoints/channel_groups/delete_group.ts | 2 + .../endpoints/channel_groups/list_channels.ts | 2 + .../endpoints/channel_groups/list_groups.ts | 2 + .../channel_groups/remove_channels.ts | 2 + src/core/endpoints/fetch_messages.ts | 2 + src/core/endpoints/file_upload/delete_file.ts | 2 + .../endpoints/file_upload/download_file.ts | 2 + .../file_upload/generate_upload_url.ts | 2 + .../endpoints/file_upload/get_file_url.ts | 2 + src/core/endpoints/file_upload/list_files.ts | 2 + .../endpoints/file_upload/publish_file.ts | 5 + src/core/endpoints/file_upload/send_file.ts | 2 + src/core/endpoints/file_upload/upload-file.ts | 2 + src/core/endpoints/history/delete_messages.ts | 2 + src/core/endpoints/history/get_history.ts | 2 + src/core/endpoints/history/message_counts.ts | 5 + src/core/endpoints/objects/channel/get.ts | 2 + src/core/endpoints/objects/channel/get_all.ts | 2 + src/core/endpoints/objects/channel/remove.ts | 2 + src/core/endpoints/objects/channel/set.ts | 2 + src/core/endpoints/objects/member/get.ts | 2 + src/core/endpoints/objects/member/set.ts | 2 + src/core/endpoints/objects/membership/get.ts | 2 + src/core/endpoints/objects/membership/set.ts | 2 + src/core/endpoints/objects/uuid/get.ts | 2 + src/core/endpoints/objects/uuid/get_all.ts | 5 + src/core/endpoints/objects/uuid/remove.ts | 2 + src/core/endpoints/objects/uuid/set.ts | 2 + src/core/endpoints/presence/get_state.ts | 2 + src/core/endpoints/presence/heartbeat.ts | 5 + src/core/endpoints/presence/here_now.ts | 5 + src/core/endpoints/presence/leave.ts | 5 + src/core/endpoints/presence/set_state.ts | 2 + src/core/endpoints/presence/where_now.ts | 5 + src/core/endpoints/publish.ts | 2 + src/core/endpoints/push/add_push_channels.ts | 2 + src/core/endpoints/push/list_push_channels.ts | 2 + src/core/endpoints/push/push.ts | 2 + src/core/endpoints/push/remove_device.ts | 2 + .../endpoints/push/remove_push_channels.ts | 2 + src/core/endpoints/signal.ts | 5 + src/core/endpoints/subscribe.ts | 22 + .../endpoints/subscriptionUtils/handshake.ts | 2 + .../subscriptionUtils/receiveMessages.ts | 2 + src/core/endpoints/time.ts | 5 + src/core/interfaces/configuration.ts | 8 + src/core/interfaces/request.ts | 2 + src/core/pubnub-common.ts | 31 +- src/core/utils.ts | 2 +- src/event-engine/index.ts | 4 +- src/node/configuration.ts | 4 +- src/node/index.ts | 6 +- src/react_native/configuration.ts | 2 + .../subscription-worker-middleware.ts} | 203 ++- .../subscription-worker.ts} | 597 ++++-- src/web/components/configuration.ts | 53 +- src/web/index.ts | 13 +- tsconfig.json | 6 +- 359 files changed, 15477 insertions(+), 1196 deletions(-) create mode 100644 lib/types/cbor/common.d.ts create mode 100644 lib/types/core/components/abort_signal.d.ts create mode 100644 lib/types/core/components/base64_codec.d.ts create mode 100644 lib/types/core/components/configuration.d.ts create mode 100644 lib/types/core/components/cryptography/hmac-sha256.d.ts create mode 100644 lib/types/core/components/cryptography/index.d.ts create mode 100644 lib/types/core/components/deduping_manager.d.ts create mode 100644 lib/types/core/components/eventEmitter.d.ts create mode 100644 lib/types/core/components/listener_manager.d.ts create mode 100644 lib/types/core/components/push_payload.d.ts create mode 100644 lib/types/core/components/reconnection_manager.d.ts create mode 100644 lib/types/core/components/request.d.ts create mode 100644 lib/types/core/components/stringify_buffer_keys.d.ts create mode 100644 lib/types/core/components/subject.d.ts create mode 100644 lib/types/core/components/subscription-manager.d.ts create mode 100644 lib/types/core/components/token_manager.d.ts create mode 100644 lib/types/core/components/uuid.d.ts create mode 100644 lib/types/core/constants/categories.d.ts create mode 100644 lib/types/core/constants/operations.d.ts create mode 100644 lib/types/core/endpoints/access_manager/audit.d.ts create mode 100644 lib/types/core/endpoints/access_manager/grant.d.ts create mode 100644 lib/types/core/endpoints/access_manager/grant_token.d.ts create mode 100644 lib/types/core/endpoints/access_manager/revoke_token.d.ts create mode 100644 lib/types/core/endpoints/actions/add_message_action.d.ts create mode 100644 lib/types/core/endpoints/actions/get_message_actions.d.ts create mode 100644 lib/types/core/endpoints/actions/remove_message_action.d.ts create mode 100644 lib/types/core/endpoints/channel_groups/add_channels.d.ts create mode 100644 lib/types/core/endpoints/channel_groups/delete_group.d.ts create mode 100644 lib/types/core/endpoints/channel_groups/list_channels.d.ts create mode 100644 lib/types/core/endpoints/channel_groups/list_groups.d.ts create mode 100644 lib/types/core/endpoints/channel_groups/remove_channels.d.ts create mode 100644 lib/types/core/endpoints/fetch_messages.d.ts create mode 100644 lib/types/core/endpoints/file_upload/delete_file.d.ts create mode 100644 lib/types/core/endpoints/file_upload/download_file.d.ts create mode 100644 lib/types/core/endpoints/file_upload/generate_upload_url.d.ts create mode 100644 lib/types/core/endpoints/file_upload/get_file_url.d.ts create mode 100644 lib/types/core/endpoints/file_upload/list_files.d.ts create mode 100644 lib/types/core/endpoints/file_upload/publish_file.d.ts create mode 100644 lib/types/core/endpoints/file_upload/send_file.d.ts create mode 100644 lib/types/core/endpoints/file_upload/upload-file.d.ts create mode 100644 lib/types/core/endpoints/history/delete_messages.d.ts create mode 100644 lib/types/core/endpoints/history/get_history.d.ts create mode 100644 lib/types/core/endpoints/history/message_counts.d.ts create mode 100644 lib/types/core/endpoints/objects/channel/get.d.ts create mode 100644 lib/types/core/endpoints/objects/channel/get_all.d.ts create mode 100644 lib/types/core/endpoints/objects/channel/remove.d.ts create mode 100644 lib/types/core/endpoints/objects/channel/set.d.ts create mode 100644 lib/types/core/endpoints/objects/member/get.d.ts create mode 100644 lib/types/core/endpoints/objects/member/set.d.ts create mode 100644 lib/types/core/endpoints/objects/membership/get.d.ts create mode 100644 lib/types/core/endpoints/objects/membership/set.d.ts create mode 100644 lib/types/core/endpoints/objects/uuid/get.d.ts create mode 100644 lib/types/core/endpoints/objects/uuid/get_all.d.ts create mode 100644 lib/types/core/endpoints/objects/uuid/remove.d.ts create mode 100644 lib/types/core/endpoints/objects/uuid/set.d.ts create mode 100644 lib/types/core/endpoints/presence/get_state.d.ts create mode 100644 lib/types/core/endpoints/presence/heartbeat.d.ts create mode 100644 lib/types/core/endpoints/presence/here_now.d.ts create mode 100644 lib/types/core/endpoints/presence/leave.d.ts create mode 100644 lib/types/core/endpoints/presence/set_state.d.ts create mode 100644 lib/types/core/endpoints/presence/where_now.d.ts create mode 100644 lib/types/core/endpoints/publish.d.ts create mode 100644 lib/types/core/endpoints/push/add_push_channels.d.ts create mode 100644 lib/types/core/endpoints/push/list_push_channels.d.ts create mode 100644 lib/types/core/endpoints/push/push.d.ts create mode 100644 lib/types/core/endpoints/push/remove_device.d.ts create mode 100644 lib/types/core/endpoints/push/remove_push_channels.d.ts create mode 100644 lib/types/core/endpoints/signal.d.ts create mode 100644 lib/types/core/endpoints/subscribe.d.ts create mode 100644 lib/types/core/endpoints/subscriptionUtils/handshake.d.ts create mode 100644 lib/types/core/endpoints/subscriptionUtils/receiveMessages.d.ts create mode 100644 lib/types/core/endpoints/time.d.ts create mode 100644 lib/types/core/interfaces/configuration.d.ts create mode 100644 lib/types/core/interfaces/crypto-module.d.ts create mode 100644 lib/types/core/interfaces/cryptography.d.ts create mode 100644 lib/types/core/interfaces/request.d.ts create mode 100644 lib/types/core/interfaces/transport.d.ts create mode 100644 lib/types/core/pubnub-channel-groups.d.ts create mode 100644 lib/types/core/pubnub-common.d.ts create mode 100644 lib/types/core/pubnub-objects.d.ts create mode 100644 lib/types/core/pubnub-push.d.ts create mode 100644 lib/types/core/types/api/access-panager.d.ts create mode 100644 lib/types/core/types/api/app-context.d.ts create mode 100644 lib/types/core/types/api/channel-groups.d.ts create mode 100644 lib/types/core/types/api/file-sharing.d.ts create mode 100644 lib/types/core/types/api/history.d.ts create mode 100644 lib/types/core/types/api/index.d.ts create mode 100644 lib/types/core/types/api/message-action.d.ts create mode 100644 lib/types/core/types/api/presence.d.ts create mode 100644 lib/types/core/types/api/push-notifications.d.ts create mode 100644 lib/types/core/types/api/push.d.ts create mode 100644 lib/types/core/types/api/subscription.d.ts create mode 100644 lib/types/core/types/file.d.ts create mode 100644 lib/types/core/types/transport-request.d.ts create mode 100644 lib/types/core/types/transport-response.d.ts create mode 100644 lib/types/core/utils.d.ts create mode 100644 lib/types/crypto/index.d.ts create mode 100644 lib/types/crypto/modules/NodeCryptoModule/ICryptor.d.ts create mode 100644 lib/types/crypto/modules/NodeCryptoModule/ILegacyCryptor.d.ts create mode 100644 lib/types/crypto/modules/NodeCryptoModule/aesCbcCryptor.d.ts create mode 100644 lib/types/crypto/modules/NodeCryptoModule/legacyCryptor.d.ts create mode 100644 lib/types/crypto/modules/NodeCryptoModule/nodeCryptoModule.d.ts create mode 100644 lib/types/crypto/modules/node.d.ts create mode 100644 lib/types/entities/Channel.d.ts create mode 100644 lib/types/entities/ChannelGroup.d.ts create mode 100644 lib/types/entities/ChannelMetadata.d.ts create mode 100644 lib/types/entities/SubscribeCapable.d.ts create mode 100644 lib/types/entities/Subscription.d.ts create mode 100644 lib/types/entities/SubscriptionSet.d.ts create mode 100644 lib/types/entities/UserMetadata.d.ts create mode 100644 lib/types/entities/commonTypes.d.ts create mode 100644 lib/types/errors/pubnub-api-error.d.ts create mode 100644 lib/types/errors/pubnub-error.d.ts create mode 100644 lib/types/event-engine/core/change.d.ts create mode 100644 lib/types/event-engine/core/dispatcher.d.ts create mode 100644 lib/types/event-engine/core/engine.d.ts create mode 100644 lib/types/event-engine/core/handler.d.ts create mode 100644 lib/types/event-engine/core/index.d.ts create mode 100644 lib/types/event-engine/core/retryPolicy.d.ts create mode 100644 lib/types/event-engine/core/state.d.ts create mode 100644 lib/types/event-engine/core/types.d.ts create mode 100644 lib/types/event-engine/dispatcher.d.ts create mode 100644 lib/types/event-engine/effects.d.ts create mode 100644 lib/types/event-engine/events.d.ts create mode 100644 lib/types/event-engine/index.d.ts create mode 100644 lib/types/event-engine/presence/dispatcher.d.ts create mode 100644 lib/types/event-engine/presence/effects.d.ts create mode 100644 lib/types/event-engine/presence/events.d.ts create mode 100644 lib/types/event-engine/presence/presence.d.ts create mode 100644 lib/types/event-engine/presence/states/heartbeat_cooldown.d.ts create mode 100644 lib/types/event-engine/presence/states/heartbeat_failed.d.ts create mode 100644 lib/types/event-engine/presence/states/heartbeat_inactive.d.ts create mode 100644 lib/types/event-engine/presence/states/heartbeat_reconnecting.d.ts create mode 100644 lib/types/event-engine/presence/states/heartbeat_stopped.d.ts create mode 100644 lib/types/event-engine/presence/states/heartbeating.d.ts create mode 100644 lib/types/event-engine/states/handshake_failed.d.ts create mode 100644 lib/types/event-engine/states/handshake_reconnecting.d.ts create mode 100644 lib/types/event-engine/states/handshake_stopped.d.ts create mode 100644 lib/types/event-engine/states/handshaking.d.ts create mode 100644 lib/types/event-engine/states/receive_failed.d.ts create mode 100644 lib/types/event-engine/states/receive_reconnecting.d.ts create mode 100644 lib/types/event-engine/states/receive_stopped.d.ts create mode 100644 lib/types/event-engine/states/receiving.d.ts create mode 100644 lib/types/event-engine/states/unsubscribed.d.ts create mode 100644 lib/types/file/modules/node.d.ts create mode 100644 lib/types/file/modules/react-native.d.ts create mode 100644 lib/types/models/Cursor.d.ts create mode 100644 lib/types/node/configuration.d.ts create mode 100644 lib/types/node/index.d.ts create mode 100644 lib/types/react_native/configuration.d.ts create mode 100644 lib/types/react_native/index.d.ts create mode 100644 lib/types/transport/middleware.d.ts create mode 100644 lib/types/transport/node-transport.d.ts create mode 100644 lib/types/transport/web-react-native-transport.d.ts rename src/transport/{service-worker/subscription-service-worker-middleware.ts => subscription-worker/subscription-worker-middleware.ts} (54%) rename src/transport/{service-worker/subscription-service-worker.ts => subscription-worker/subscription-worker.ts} (71%) diff --git a/.prettierrc b/.prettierrc index cb71e61f6..2eccbc62e 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,4 +1,5 @@ { + "parser" : "typescript", "semi": true, "printWidth": 120, "singleQuote": true, diff --git a/.pubnub.yml b/.pubnub.yml index e84db4641..54e9c5656 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,14 @@ --- changelog: + - date: 2024-05-16 + version: v8.1.0 + changes: + - type: feature + text: "Use `SharedWorker` instead of `Service Worker` for better PubNub client instances feedback." + - type: feature + text: "Add configuration option to enable debug log output from the subscription `SharedWorker`." + - type: improvement + text: "Create types declaration files." - date: 2024-04-23 version: v8.0.1 changes: @@ -972,7 +981,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.0.1' +version: '8.1.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -988,7 +997,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.0.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.1.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1659,7 +1668,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.0.1/pubnub.8.0.1.js + location: https://github.com/pubnub/javascript/releases/download/v8.1.0/pubnub.8.1.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 77d7f99c3..e0076703c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## v8.1.0 +May 16 2024 + +#### Added +- Use `SharedWorker` instead of `Service Worker` for better PubNub client instances feedback. +- Add configuration option to enable debug log output from the subscription `SharedWorker`. + +#### Modified +- Create types declaration files. + ## v8.0.1 April 23 2024 diff --git a/README.md b/README.md index 0aef17301..1a7344234 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.0.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.0.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.1.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.1.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 7ba541855..b313fae74 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -423,522 +423,6 @@ var cborExports = cbor.exports; var CborReader = /*@__PURE__*/getDefaultExportFromCjs(cborExports); - /** - * Request processing status categories. - */ - var StatusCategory; - (function (StatusCategory) { - /** - * Call failed when network was unable to complete the call. - */ - StatusCategory["PNNetworkIssuesCategory"] = "PNNetworkIssuesCategory"; - /** - * Network call timed out. - */ - StatusCategory["PNTimeoutCategory"] = "PNTimeoutCategory"; - /** - * Request has been cancelled. - */ - StatusCategory["PNCancelledCategory"] = "PNCancelledCategory"; - /** - * Server responded with bad response. - */ - StatusCategory["PNBadRequestCategory"] = "PNBadRequestCategory"; - /** - * Server responded with access denied. - */ - StatusCategory["PNAccessDeniedCategory"] = "PNAccessDeniedCategory"; - /** - * Incomplete parameters provided for used endpoint. - */ - StatusCategory["PNValidationErrorCategory"] = "PNValidationErrorCategory"; - /** - * PubNub request acknowledgment status. - * - * Some API endpoints respond with request processing status w/o useful data. - */ - StatusCategory["PNAcknowledgmentCategory"] = "PNAcknowledgmentCategory"; - /** - * Something strange happened; please check the logs. - */ - StatusCategory["PNUnknownCategory"] = "PNUnknownCategory"; - // -------------------------------------------------------- - // --------------------- Network status ------------------- - // -------------------------------------------------------- - /** - * SDK will announce when the network appears to be connected again. - */ - StatusCategory["PNNetworkUpCategory"] = "PNNetworkUpCategory"; - /** - * SDK will announce when the network appears to down. - */ - StatusCategory["PNNetworkDownCategory"] = "PNNetworkDownCategory"; - // -------------------------------------------------------- - // -------------------- Real-time events ------------------ - // -------------------------------------------------------- - /** - * PubNub client reconnected to the real-time updates stream. - */ - StatusCategory["PNReconnectedCategory"] = "PNReconnectedCategory"; - /** - * PubNub client connected to the real-time updates stream. - */ - StatusCategory["PNConnectedCategory"] = "PNConnectedCategory"; - /** - * Received real-time updates exceed specified threshold. - * - * After temporary disconnection and catchup, this category means that potentially some - * real-time updates have been pushed into `storage` and need to be requested separately. - */ - StatusCategory["PNRequestMessageCountExceededCategory"] = "PNRequestMessageCountExceededCategory"; - /** - * PubNub client disconnected from the real-time updates streams. - */ - StatusCategory["PNDisconnectedCategory"] = "PNDisconnectedCategory"; - /** - * PubNub client wasn't able to connect to the real-time updates streams. - */ - StatusCategory["PNConnectionErrorCategory"] = "PNConnectionErrorCategory"; - /** - * PubNub client unexpectedly disconnected from the real-time updates streams. - */ - StatusCategory["PNDisconnectedUnexpectedlyCategory"] = "PNDisconnectedUnexpectedlyCategory"; - })(StatusCategory || (StatusCategory = {})); - var StatusCategory$1 = StatusCategory; - - class PubNubError extends Error { - constructor(message, status) { - super(message); - this.status = status; - this.name = 'PubNubError'; - this.message = message; - Object.setPrototypeOf(this, new.target.prototype); - } - } - function createError(errorPayload) { - var _a; - (_a = errorPayload.statusCode) !== null && _a !== void 0 ? _a : (errorPayload.statusCode = 0); - return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: StatusCategory$1.PNValidationErrorCategory, error: true }); - } - function createValidationError(message, statusCode) { - return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {}))); - } - - /** - * REST API endpoint use error module. - */ - /** - * PubNub REST API call error. - */ - class PubNubAPIError extends Error { - /** - * Construct API from known error object or {@link PubNub} service error response. - * - * @param errorOrResponse - `Error` or service error response object from which error information - * should be extracted. - * @param data - Preprocessed service error response. - * - * @returns `PubNubAPIError` object with known error category and additional information (if - * available). - */ - static create(errorOrResponse, data) { - if (errorOrResponse instanceof Error) - return PubNubAPIError.createFromError(errorOrResponse); - else - return PubNubAPIError.createFromServiceResponse(errorOrResponse, data); - } - /** - * Create API error instance from other error object. - * - * @param error - `Error` object provided by network provider (mostly) or other {@link PubNub} client components. - * - * @returns `PubNubAPIError` object with known error category and additional information (if - * available). - */ - static createFromError(error) { - let category = StatusCategory$1.PNUnknownCategory; - let message = 'Unknown error'; - let errorName = 'Error'; - if (!error) - return new PubNubAPIError(message, category, 0); - else if (error instanceof PubNubAPIError) - return error; - if (error instanceof Error) { - message = error.message; - errorName = error.name; - } - if (errorName === 'AbortError' || message.indexOf('Aborted') !== -1) { - category = StatusCategory$1.PNCancelledCategory; - message = 'Request cancelled'; - } - else if (message.indexOf('timeout') !== -1) { - category = StatusCategory$1.PNTimeoutCategory; - message = 'Request timeout'; - } - else if (message.indexOf('network') !== -1) { - category = StatusCategory$1.PNNetworkIssuesCategory; - message = 'Network issues'; - } - else if (errorName === 'TypeError') { - category = StatusCategory$1.PNBadRequestCategory; - } - else if (errorName === 'FetchError') { - const errorCode = error.code; - if (['ECONNREFUSED', 'ENETUNREACH', 'ENOTFOUND', 'ECONNRESET', 'EAI_AGAIN'].includes(errorCode)) - category = StatusCategory$1.PNNetworkIssuesCategory; - if (errorCode === 'ECONNREFUSED') - message = 'Connection refused'; - else if (errorCode === 'ENETUNREACH') - message = 'Network not reachable'; - else if (errorCode === 'ENOTFOUND') - message = 'Server not found'; - else if (errorCode === 'ECONNRESET') - message = 'Connection reset by peer'; - else if (errorCode === 'EAI_AGAIN') - message = 'Name resolution error'; - else if (errorCode === 'ETIMEDOUT') { - category = StatusCategory$1.PNTimeoutCategory; - message = 'Request timeout'; - } - else - message = `Unknown system error: ${error}`; - } - else if (message === 'Request timeout') - category = StatusCategory$1.PNTimeoutCategory; - return new PubNubAPIError(message, category, 0, error); - } - /** - * Construct API from known {@link PubNub} service error response. - * - * @param response - Service error response object from which error information should be - * extracted. - * @param data - Preprocessed service error response. - * - * @returns `PubNubAPIError` object with known error category and additional information (if - * available). - */ - static createFromServiceResponse(response, data) { - let category = StatusCategory$1.PNUnknownCategory; - let errorData; - let message = 'Unknown error'; - let { status } = response; - data !== null && data !== void 0 ? data : (data = response.body); - if (status === 402) - message = 'Not available for used key set. Contact support@pubnub.com'; - else if (status === 400) { - category = StatusCategory$1.PNBadRequestCategory; - message = 'Bad request'; - } - else if (status === 403) { - category = StatusCategory$1.PNAccessDeniedCategory; - message = 'Access denied'; - } - // Try to get more information about error from service response. - if (data && data.byteLength > 0) { - const decoded = new TextDecoder().decode(data); - if (response.headers['content-type'].indexOf('text/javascript') !== -1 || - response.headers['content-type'].indexOf('application/json') !== -1) { - try { - const errorResponse = JSON.parse(decoded); - if (typeof errorResponse === 'object' && !Array.isArray(errorResponse)) { - if ('error' in errorResponse && - (errorResponse.error === 1 || errorResponse.error === true) && - 'status' in errorResponse && - typeof errorResponse.status === 'number' && - 'message' in errorResponse && - 'service' in errorResponse) { - errorData = errorResponse; - status = errorResponse.status; - } - else - errorData = errorResponse; - if ('error' in errorResponse && errorResponse.error instanceof Error) - errorData = errorResponse.error; - } - } - catch (_) { - errorData = decoded; - } - } - else if (response.headers['content-type'].indexOf('xml') !== -1) { - const reason = /(.*)<\/Message>/gi.exec(decoded); - message = reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.'; - } - else { - errorData = decoded; - } - } - return new PubNubAPIError(message, category, status, errorData); - } - /** - * Construct PubNub endpoint error. - * - * @param message - Short API call error description. - * @param category - Error category. - * @param statusCode - Response HTTP status code. - * @param errorData - Error information. - */ - constructor(message, category, statusCode, errorData) { - super(message); - this.category = category; - this.statusCode = statusCode; - this.errorData = errorData; - this.name = 'PubNubAPIError'; - } - /** - * Convert API error object to API callback status object. - * - * @param operation - Request operation during which error happened. - * - * @returns Pre-formatted API callback status object. - */ - toStatus(operation) { - return { - error: true, - category: this.category, - operation, - statusCode: this.statusCode, - errorData: this.errorData, - }; - } - /** - * Convert API error object to PubNub client error object. - * - * @param operation - Request operation during which error happened. - * @param message - Custom error message. - * - * @returns Client-facing pre-formatted endpoint call error. - */ - toPubNubError(operation, message) { - return new PubNubError(message !== null && message !== void 0 ? message : this.message, this.toStatus(operation)); - } - } - - /** - * Subscription Service Worker transport middleware module. - * - * Middleware optimize subscription feature requests utilizing `Subscription Service Worker` if available and not - * disabled by user. - */ - // endregion - /** - * Subscription Service Worker transport middleware. - */ - class SubscriptionServiceWorkerMiddleware { - constructor(configuration) { - this.configuration = configuration; - this.serviceWorkerEventsQueue = []; - this.callbacks = new Map(); - this.setupServiceWorker(); - } - makeSendable(req) { - // Use default request flow for non-subscribe / presence leave requests. - if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/leave')) - return this.configuration.transport.makeSendable(req); - let controller; - const sendRequestEvent = { - type: 'send-request', - clientIdentifier: this.configuration.clientIdentifier, - subscriptionKey: this.configuration.subscriptionKey, - logVerbosity: this.configuration.logVerbosity, - request: req, - }; - if (req.cancellable) { - controller = { - abort: () => { - const cancelRequest = { - type: 'cancel-request', - clientIdentifier: this.configuration.clientIdentifier, - subscriptionKey: this.configuration.subscriptionKey, - logVerbosity: this.configuration.logVerbosity, - identifier: req.identifier, - }; - // Cancel active request with specified identifier. - this.scheduleEventPost(cancelRequest); - }, - }; - } - return [ - new Promise((resolve, reject) => { - // Associate Promise resolution / reject with request identifier for future usage in - // `onmessage` handler block to return results. - this.callbacks.set(req.identifier, { resolve, reject }); - // Trigger request processing by Service Worker. - this.scheduleEventPost(sendRequestEvent); - }), - controller, - ]; - } - request(req) { - return req; - } - /** - * Schedule {@link event} publish to the service worker. - * - * Service worker may not be ready for events processing and this method build queue for the time when worker will be - * ready. - * - * @param event - Event payload for service worker. - * @param outOfOrder - Whether event should be processed first then enqueued queue. - */ - scheduleEventPost(event, outOfOrder = false) { - // Trigger request processing by Web Worker. - const serviceWorker = this.serviceWorker; - if (serviceWorker) - serviceWorker.postMessage(event); - else { - if (outOfOrder) - this.serviceWorkerEventsQueue.splice(0, 0, event); - else - this.serviceWorkerEventsQueue.push(event); - } - } - /** - * Dequeue and post events from the queue to the service worker. - */ - flushScheduledEvents() { - // Trigger request processing by Web Worker. - const serviceWorker = this.serviceWorker; - if (!serviceWorker || this.serviceWorkerEventsQueue.length === 0) - return; - // Clean up from cancelled events. - const outdatedEvents = []; - for (let i = 0; i < this.serviceWorkerEventsQueue.length; i++) { - const event = this.serviceWorkerEventsQueue[i]; - // Check whether found request cancel event to search for request send event it cancels. - if (event.type !== 'cancel-request' || i === 0) - continue; - for (let j = 0; j < i; j++) { - const otherEvent = this.serviceWorkerEventsQueue[j]; - if (otherEvent.type !== 'send-request') - continue; - // Collect outdated events if identifiers match. - if (otherEvent.request.identifier === event.identifier) { - outdatedEvents.push(event, otherEvent); - break; - } - } - } - // Actualizing events queue. - this.serviceWorkerEventsQueue = this.serviceWorkerEventsQueue.filter((event) => !outdatedEvents.includes(event)); - this.serviceWorkerEventsQueue.forEach((event) => serviceWorker.postMessage(event)); - this.serviceWorkerEventsQueue = []; - } - /** - * Subscription service worker. - * - * @returns Service worker which has been registered by the PubNub SDK. - */ - get serviceWorker() { - return this.serviceWorkerRegistration ? this.serviceWorkerRegistration.active : null; - } - setupServiceWorker() { - if (!('serviceWorker' in navigator)) - return; - const serviceWorkerContainer = navigator.serviceWorker; - serviceWorkerContainer - .register(this.configuration.serviceWorkerUrl, { - scope: `/pubnub-${this.configuration.sdkVersion}`, - }) - .then((registration) => { - this.serviceWorkerRegistration = registration; - // Flush any pending service worker events. - if (registration.active) - this.flushScheduledEvents(); - /** - * Listening for service worker code update. - * - * It is possible that one of the tabs will open with newer SDK version and Subscription Service Worker - * will be re-installed - in this case we need to "rehydrate" it. - * - * After re-installation of new service worker it will lose all accumulated state and client need to - * re-introduce itself and its state. - */ - this.serviceWorkerRegistration.addEventListener('updatefound', () => { - if (!this.serviceWorkerRegistration) - return; - // New service installing right now. - const serviceWorker = this.serviceWorkerRegistration.installing; - const stateChangeListener = () => { - // Flush any pending service worker events. - if (serviceWorker.state === 'activated') { - // Flush any pending service worker events. - this.flushScheduledEvents(); - } - else if (serviceWorker.state === 'redundant') { - // Clean up listener from deprecated service worker version. - serviceWorker.removeEventListener('statechange', stateChangeListener); - } - }; - serviceWorker.addEventListener('statechange', stateChangeListener); - }); - }); - serviceWorkerContainer.addEventListener('message', (event) => this.handleServiceWorkerEvent(event)); - } - handleServiceWorkerEvent(event) { - const { data } = event; - // Ignoring updates not related to this instance. - if (data.clientIdentifier !== this.configuration.clientIdentifier) - return; - if (data.type === 'request-progress-start' || data.type === 'request-progress-end') { - this.logRequestProgress(data); - } - else if (data.type === 'request-process-success' || data.type === 'request-process-error') { - const { resolve, reject } = this.callbacks.get(data.identifier); - if (data.type === 'request-process-success') { - resolve({ - status: data.response.status, - url: data.url, - headers: data.response.headers, - body: data.response.body, - }); - } - else { - let category = StatusCategory$1.PNUnknownCategory; - let message = 'Unknown error'; - // Handle client-side issues (if any). - if (data.error) { - if (data.error.type === 'NETWORK_ISSUE') - category = StatusCategory$1.PNNetworkIssuesCategory; - else if (data.error.type === 'TIMEOUT') - category = StatusCategory$1.PNTimeoutCategory; - else if (data.error.type === 'ABORTED') - category = StatusCategory$1.PNCancelledCategory; - message = `${data.error.message} (${data.identifier})`; - } - // Handle service error response. - else if (data.response) { - return reject(PubNubAPIError.create({ - url: data.url, - headers: data.response.headers, - body: data.response.body, - status: data.response.status, - }, data.response.body)); - } - reject(new PubNubAPIError(message, category, 0, new Error(message))); - } - } - } - /** - * Print request progress information. - * - * @param information - Request progress information from Web Worker. - */ - logRequestProgress(information) { - var _a, _b; - if (information.type === 'request-progress-start') { - console.log('<<<<<'); - console.log(`[${information.timestamp}] ${information.url}\n${JSON.stringify((_a = information.query) !== null && _a !== void 0 ? _a : {})}`); - console.log('-----'); - } - else { - console.log('>>>>>>'); - console.log(`[${information.timestamp} / ${information.duration}] ${information.url}\n${JSON.stringify((_b = information.query) !== null && _b !== void 0 ? _b : {})}\n${information.response}`); - console.log('-----'); - } - } - } - /****************************************************************************** Copyright (c) Microsoft Corporation. @@ -1217,6 +701,8 @@ * * @param paddedInput Base64 string with padding * @returns ArrayBuffer with decoded data + * + * @internal */ function decode(paddedInput) { // Remove up to last two equal signs. @@ -1255,46 +741,155 @@ if (sx4 != 64) view[i + 2] = oc3; } - return data; + return data; + } + /** + * Encode `ArrayBuffer` as a Base64 encoded string. + * + * @param input ArrayBuffer with source data. + * @returns Base64 string with padding. + * + * @internal + */ + function encode(input) { + let base64 = ''; + const encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; + const bytes = new Uint8Array(input); + const byteLength = bytes.byteLength; + const byteRemainder = byteLength % 3; + const mainLength = byteLength - byteRemainder; + let a, b, c, d; + let chunk; + // Main loop deals with bytes in chunks of 3 + for (let i = 0; i < mainLength; i = i + 3) { + // Combine the three bytes into a single integer + chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; + // Use bitmasks to extract 6-bit segments from the triplet + a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18 + b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12 + c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6 + d = chunk & 63; // 63 = 2^6 - 1 + // Convert the raw binary segments to the appropriate ASCII encoding + base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]; + } + // Deal with the remaining bytes and padding + if (byteRemainder == 1) { + chunk = bytes[mainLength]; + a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2 + // Set the 4 least significant bits to zero + b = (chunk & 3) << 4; // 3 = 2^2 - 1 + base64 += encodings[a] + encodings[b] + '=='; + } + else if (byteRemainder == 2) { + chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]; + a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10 + b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4 + // Set the 2 least significant bits to zero + c = (chunk & 15) << 2; // 15 = 2^4 - 1 + base64 += encodings[a] + encodings[b] + encodings[c] + '='; + } + return base64; + } + + /** + * Request processing status categories. + */ + var StatusCategory; + (function (StatusCategory) { + /** + * Call failed when network was unable to complete the call. + */ + StatusCategory["PNNetworkIssuesCategory"] = "PNNetworkIssuesCategory"; + /** + * Network call timed out. + */ + StatusCategory["PNTimeoutCategory"] = "PNTimeoutCategory"; + /** + * Request has been cancelled. + */ + StatusCategory["PNCancelledCategory"] = "PNCancelledCategory"; + /** + * Server responded with bad response. + */ + StatusCategory["PNBadRequestCategory"] = "PNBadRequestCategory"; + /** + * Server responded with access denied. + */ + StatusCategory["PNAccessDeniedCategory"] = "PNAccessDeniedCategory"; + /** + * Incomplete parameters provided for used endpoint. + */ + StatusCategory["PNValidationErrorCategory"] = "PNValidationErrorCategory"; + /** + * PubNub request acknowledgment status. + * + * Some API endpoints respond with request processing status w/o useful data. + */ + StatusCategory["PNAcknowledgmentCategory"] = "PNAcknowledgmentCategory"; + /** + * Something strange happened; please check the logs. + */ + StatusCategory["PNUnknownCategory"] = "PNUnknownCategory"; + // -------------------------------------------------------- + // --------------------- Network status ------------------- + // -------------------------------------------------------- + /** + * SDK will announce when the network appears to be connected again. + */ + StatusCategory["PNNetworkUpCategory"] = "PNNetworkUpCategory"; + /** + * SDK will announce when the network appears to down. + */ + StatusCategory["PNNetworkDownCategory"] = "PNNetworkDownCategory"; + // -------------------------------------------------------- + // -------------------- Real-time events ------------------ + // -------------------------------------------------------- + /** + * PubNub client reconnected to the real-time updates stream. + */ + StatusCategory["PNReconnectedCategory"] = "PNReconnectedCategory"; + /** + * PubNub client connected to the real-time updates stream. + */ + StatusCategory["PNConnectedCategory"] = "PNConnectedCategory"; + /** + * Received real-time updates exceed specified threshold. + * + * After temporary disconnection and catchup, this category means that potentially some + * real-time updates have been pushed into `storage` and need to be requested separately. + */ + StatusCategory["PNRequestMessageCountExceededCategory"] = "PNRequestMessageCountExceededCategory"; + /** + * PubNub client disconnected from the real-time updates streams. + */ + StatusCategory["PNDisconnectedCategory"] = "PNDisconnectedCategory"; + /** + * PubNub client wasn't able to connect to the real-time updates streams. + */ + StatusCategory["PNConnectionErrorCategory"] = "PNConnectionErrorCategory"; + /** + * PubNub client unexpectedly disconnected from the real-time updates streams. + */ + StatusCategory["PNDisconnectedUnexpectedlyCategory"] = "PNDisconnectedUnexpectedlyCategory"; + })(StatusCategory || (StatusCategory = {})); + var StatusCategory$1 = StatusCategory; + + class PubNubError extends Error { + constructor(message, status) { + super(message); + this.status = status; + this.name = 'PubNubError'; + this.message = message; + Object.setPrototypeOf(this, new.target.prototype); + } } - function encode(input) { - let base64 = ''; - const encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; - const bytes = new Uint8Array(input); - const byteLength = bytes.byteLength; - const byteRemainder = byteLength % 3; - const mainLength = byteLength - byteRemainder; - let a, b, c, d; - let chunk; - // Main loop deals with bytes in chunks of 3 - for (let i = 0; i < mainLength; i = i + 3) { - // Combine the three bytes into a single integer - chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; - // Use bitmasks to extract 6-bit segments from the triplet - a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18 - b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12 - c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6 - d = chunk & 63; // 63 = 2^6 - 1 - // Convert the raw binary segments to the appropriate ASCII encoding - base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]; - } - // Deal with the remaining bytes and padding - if (byteRemainder == 1) { - chunk = bytes[mainLength]; - a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2 - // Set the 4 least significant bits to zero - b = (chunk & 3) << 4; // 3 = 2^2 - 1 - base64 += encodings[a] + encodings[b] + '=='; - } - else if (byteRemainder == 2) { - chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]; - a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10 - b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4 - // Set the 2 least significant bits to zero - c = (chunk & 15) << 2; // 15 = 2^4 - 1 - base64 += encodings[a] + encodings[b] + encodings[c] + '='; - } - return base64; + function createError(errorPayload) { + var _a; + (_a = errorPayload.statusCode) !== null && _a !== void 0 ? _a : (errorPayload.statusCode = 0); + return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: StatusCategory$1.PNValidationErrorCategory, error: true }); + } + function createValidationError(message, statusCode) { + return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {}))); } /*eslint-disable */ @@ -3020,173 +2615,590 @@ throw Error('Unknown cryptor error'); } /** - * Retrieve cryptor by its identifier. + * Retrieve cryptor by its identifier. + * + * @param header - Header with cryptor-defined data or raw cryptor identifier. + * + * @returns Cryptor which correspond to provided {@link header}. + */ + getCryptor(header) { + if (typeof header === 'string') { + const cryptor = this.getAllCryptors().find((cryptor) => cryptor.identifier === header); + if (cryptor) + return cryptor; + throw new Error('Unknown cryptor error'); + } + else if (header instanceof CryptorHeaderV1) { + return this.getCryptorFromId(header.identifier); + } + } + /** + * Create cryptor header data. + * + * @param encrypted - Encryption data object as source for header data. + * + * @returns Binary representation of the cryptor header data. + */ + getHeaderData(encrypted) { + if (!encrypted.metadata) + return; + const header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); + const headerData = new Uint8Array(header.length); + let pos = 0; + headerData.set(header.data, pos); + pos += header.length - encrypted.metadata.byteLength; + headerData.set(new Uint8Array(encrypted.metadata), pos); + return headerData.buffer; + } + /** + * Merge two {@link ArrayBuffer} instances. + * + * @param ab1 - First {@link ArrayBuffer}. + * @param ab2 - Second {@link ArrayBuffer}. + * + * @returns Merged data as {@link ArrayBuffer}. + */ + concatArrayBuffer(ab1, ab2) { + const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); + tmp.set(new Uint8Array(ab1), 0); + tmp.set(new Uint8Array(ab2), ab1.byteLength); + return tmp.buffer; + } + /** + * Retrieve file content. + * + * @param file - Content of the {@link PubNub} File object. + * + * @returns Normalized file {@link data} as {@link ArrayBuffer}; + */ + getFileData(file) { + return __awaiter(this, void 0, void 0, function* () { + if (file instanceof ArrayBuffer) + return file; + else if (file instanceof PubNubFile) + return file.toArrayBuffer(); + throw new Error('Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob'); + }); + } + } + /** + * {@link LegacyCryptor|Legacy} cryptor identifier. + */ + WebCryptoModule.LEGACY_IDENTIFIER = ''; + /** + * CryptorHeader Utility + */ + class CryptorHeader { + static from(id, metadata) { + if (id === CryptorHeader.LEGACY_IDENTIFIER) + return; + return new CryptorHeaderV1(id, metadata.byteLength); + } + static tryParse(data) { + const encryptedData = new Uint8Array(data); + let sentinel; + let version = null; + if (encryptedData.byteLength >= 4) { + sentinel = encryptedData.slice(0, 4); + if (this.decoder.decode(sentinel) !== CryptorHeader.SENTINEL) + return WebCryptoModule.LEGACY_IDENTIFIER; + } + if (encryptedData.byteLength >= 5) + version = encryptedData[4]; + else + throw new Error('Decryption error: invalid header version'); + if (version > CryptorHeader.MAX_VERSION) + throw new Error('Decryption error: Unknown cryptor error'); + let identifier; + let pos = 5 + CryptorHeader.IDENTIFIER_LENGTH; + if (encryptedData.byteLength >= pos) + identifier = encryptedData.slice(5, pos); + else + throw new Error('Decryption error: invalid crypto identifier'); + let metadataLength = null; + if (encryptedData.byteLength >= pos + 1) + metadataLength = encryptedData[pos]; + else + throw new Error('Decryption error: invalid metadata length'); + pos += 1; + if (metadataLength === 255 && encryptedData.byteLength >= pos + 2) { + metadataLength = new Uint16Array(encryptedData.slice(pos, pos + 2)).reduce((acc, val) => (acc << 8) + val, 0); + } + return new CryptorHeaderV1(this.decoder.decode(identifier), metadataLength); + } + } + CryptorHeader.SENTINEL = 'PNED'; + CryptorHeader.LEGACY_IDENTIFIER = ''; + CryptorHeader.IDENTIFIER_LENGTH = 4; + CryptorHeader.VERSION = 1; + CryptorHeader.MAX_VERSION = 1; + CryptorHeader.decoder = new TextDecoder(); + // v1 CryptorHeader + class CryptorHeaderV1 { + constructor(id, metadataLength) { + this._identifier = id; + this._metadataLength = metadataLength; + } + get identifier() { + return this._identifier; + } + set identifier(value) { + this._identifier = value; + } + get metadataLength() { + return this._metadataLength; + } + set metadataLength(value) { + this._metadataLength = value; + } + get version() { + return CryptorHeader.VERSION; + } + get length() { + return (CryptorHeader.SENTINEL.length + + 1 + + CryptorHeader.IDENTIFIER_LENGTH + + (this.metadataLength < 255 ? 1 : 3) + + this.metadataLength); + } + get data() { + let pos = 0; + const header = new Uint8Array(this.length); + const encoder = new TextEncoder(); + header.set(encoder.encode(CryptorHeader.SENTINEL)); + pos += CryptorHeader.SENTINEL.length; + header[pos] = this.version; + pos++; + if (this.identifier) + header.set(encoder.encode(this.identifier), pos); + const metadataLength = this.metadataLength; + pos += CryptorHeader.IDENTIFIER_LENGTH; + if (metadataLength < 255) + header[pos] = metadataLength; + else + header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); + return header; + } + } + CryptorHeaderV1.IDENTIFIER_LENGTH = 4; + CryptorHeaderV1.SENTINEL = 'PNED'; + + /** + * REST API endpoint use error module. + */ + /** + * PubNub REST API call error. + */ + class PubNubAPIError extends Error { + /** + * Construct API from known error object or {@link PubNub} service error response. + * + * @param errorOrResponse - `Error` or service error response object from which error information + * should be extracted. + * @param data - Preprocessed service error response. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + static create(errorOrResponse, data) { + if (errorOrResponse instanceof Error) + return PubNubAPIError.createFromError(errorOrResponse); + else + return PubNubAPIError.createFromServiceResponse(errorOrResponse, data); + } + /** + * Create API error instance from other error object. + * + * @param error - `Error` object provided by network provider (mostly) or other {@link PubNub} client components. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + static createFromError(error) { + let category = StatusCategory$1.PNUnknownCategory; + let message = 'Unknown error'; + let errorName = 'Error'; + if (!error) + return new PubNubAPIError(message, category, 0); + else if (error instanceof PubNubAPIError) + return error; + if (error instanceof Error) { + message = error.message; + errorName = error.name; + } + if (errorName === 'AbortError' || message.indexOf('Aborted') !== -1) { + category = StatusCategory$1.PNCancelledCategory; + message = 'Request cancelled'; + } + else if (message.indexOf('timeout') !== -1) { + category = StatusCategory$1.PNTimeoutCategory; + message = 'Request timeout'; + } + else if (message.indexOf('network') !== -1) { + category = StatusCategory$1.PNNetworkIssuesCategory; + message = 'Network issues'; + } + else if (errorName === 'TypeError') { + category = StatusCategory$1.PNBadRequestCategory; + } + else if (errorName === 'FetchError') { + const errorCode = error.code; + if (['ECONNREFUSED', 'ENETUNREACH', 'ENOTFOUND', 'ECONNRESET', 'EAI_AGAIN'].includes(errorCode)) + category = StatusCategory$1.PNNetworkIssuesCategory; + if (errorCode === 'ECONNREFUSED') + message = 'Connection refused'; + else if (errorCode === 'ENETUNREACH') + message = 'Network not reachable'; + else if (errorCode === 'ENOTFOUND') + message = 'Server not found'; + else if (errorCode === 'ECONNRESET') + message = 'Connection reset by peer'; + else if (errorCode === 'EAI_AGAIN') + message = 'Name resolution error'; + else if (errorCode === 'ETIMEDOUT') { + category = StatusCategory$1.PNTimeoutCategory; + message = 'Request timeout'; + } + else + message = `Unknown system error: ${error}`; + } + else if (message === 'Request timeout') + category = StatusCategory$1.PNTimeoutCategory; + return new PubNubAPIError(message, category, 0, error); + } + /** + * Construct API from known {@link PubNub} service error response. * - * @param header - Header with cryptor-defined data or raw cryptor identifier. + * @param response - Service error response object from which error information should be + * extracted. + * @param data - Preprocessed service error response. * - * @returns Cryptor which correspond to provided {@link header}. + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). */ - getCryptor(header) { - if (typeof header === 'string') { - const cryptor = this.getAllCryptors().find((cryptor) => cryptor.identifier === header); - if (cryptor) - return cryptor; - throw new Error('Unknown cryptor error'); + static createFromServiceResponse(response, data) { + let category = StatusCategory$1.PNUnknownCategory; + let errorData; + let message = 'Unknown error'; + let { status } = response; + data !== null && data !== void 0 ? data : (data = response.body); + if (status === 402) + message = 'Not available for used key set. Contact support@pubnub.com'; + else if (status === 400) { + category = StatusCategory$1.PNBadRequestCategory; + message = 'Bad request'; } - else if (header instanceof CryptorHeaderV1) { - return this.getCryptorFromId(header.identifier); + else if (status === 403) { + category = StatusCategory$1.PNAccessDeniedCategory; + message = 'Access denied'; + } + // Try to get more information about error from service response. + if (data && data.byteLength > 0) { + const decoded = new TextDecoder().decode(data); + if (response.headers['content-type'].indexOf('text/javascript') !== -1 || + response.headers['content-type'].indexOf('application/json') !== -1) { + try { + const errorResponse = JSON.parse(decoded); + if (typeof errorResponse === 'object' && !Array.isArray(errorResponse)) { + if ('error' in errorResponse && + (errorResponse.error === 1 || errorResponse.error === true) && + 'status' in errorResponse && + typeof errorResponse.status === 'number' && + 'message' in errorResponse && + 'service' in errorResponse) { + errorData = errorResponse; + status = errorResponse.status; + } + else + errorData = errorResponse; + if ('error' in errorResponse && errorResponse.error instanceof Error) + errorData = errorResponse.error; + } + } + catch (_) { + errorData = decoded; + } + } + else if (response.headers['content-type'].indexOf('xml') !== -1) { + const reason = /(.*)<\/Message>/gi.exec(decoded); + message = reason ? `Upload to bucket failed: ${reason[1]}` : 'Upload to bucket failed.'; + } + else { + errorData = decoded; + } } + return new PubNubAPIError(message, category, status, errorData); } /** - * Create cryptor header data. - * - * @param encrypted - Encryption data object as source for header data. + * Construct PubNub endpoint error. * - * @returns Binary representation of the cryptor header data. + * @param message - Short API call error description. + * @param category - Error category. + * @param statusCode - Response HTTP status code. + * @param errorData - Error information. */ - getHeaderData(encrypted) { - if (!encrypted.metadata) - return; - const header = CryptorHeader.from(this.defaultCryptor.identifier, encrypted.metadata); - const headerData = new Uint8Array(header.length); - let pos = 0; - headerData.set(header.data, pos); - pos += header.length - encrypted.metadata.byteLength; - headerData.set(new Uint8Array(encrypted.metadata), pos); - return headerData.buffer; + constructor(message, category, statusCode, errorData) { + super(message); + this.category = category; + this.statusCode = statusCode; + this.errorData = errorData; + this.name = 'PubNubAPIError'; } /** - * Merge two {@link ArrayBuffer} instances. + * Convert API error object to API callback status object. * - * @param ab1 - First {@link ArrayBuffer}. - * @param ab2 - Second {@link ArrayBuffer}. + * @param operation - Request operation during which error happened. * - * @returns Merged data as {@link ArrayBuffer}. + * @returns Pre-formatted API callback status object. */ - concatArrayBuffer(ab1, ab2) { - const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); - tmp.set(new Uint8Array(ab1), 0); - tmp.set(new Uint8Array(ab2), ab1.byteLength); - return tmp.buffer; + toStatus(operation) { + return { + error: true, + category: this.category, + operation, + statusCode: this.statusCode, + errorData: this.errorData, + }; } /** - * Retrieve file content. + * Convert API error object to PubNub client error object. * - * @param file - Content of the {@link PubNub} File object. + * @param operation - Request operation during which error happened. + * @param message - Custom error message. * - * @returns Normalized file {@link data} as {@link ArrayBuffer}; + * @returns Client-facing pre-formatted endpoint call error. */ - getFileData(file) { - return __awaiter(this, void 0, void 0, function* () { - if (file instanceof ArrayBuffer) - return file; - else if (file instanceof PubNubFile) - return file.toArrayBuffer(); - throw new Error('Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob'); - }); + toPubNubError(operation, message) { + return new PubNubError(message !== null && message !== void 0 ? message : this.message, this.toStatus(operation)); } } + /** - * {@link LegacyCryptor|Legacy} cryptor identifier. + * Subscription Worker transport middleware module. + * + * Middleware optimize subscription feature requests utilizing `Subscription Worker` if available and not disabled + * by user. */ - WebCryptoModule.LEGACY_IDENTIFIER = ''; + // endregion /** - * CryptorHeader Utility + * Subscription Worker transport middleware. */ - class CryptorHeader { - static from(id, metadata) { - if (id === CryptorHeader.LEGACY_IDENTIFIER) - return; - return new CryptorHeaderV1(id, metadata.byteLength); - } - static tryParse(data) { - const encryptedData = new Uint8Array(data); - let sentinel; - let version = null; - if (encryptedData.byteLength >= 4) { - sentinel = encryptedData.slice(0, 4); - if (this.decoder.decode(sentinel) !== CryptorHeader.SENTINEL) - return WebCryptoModule.LEGACY_IDENTIFIER; - } - if (encryptedData.byteLength >= 5) - version = encryptedData[4]; - else - throw new Error('Decryption error: invalid header version'); - if (version > CryptorHeader.MAX_VERSION) - throw new Error('Decryption error: Unknown cryptor error'); - let identifier; - let pos = 5 + CryptorHeader.IDENTIFIER_LENGTH; - if (encryptedData.byteLength >= pos) - identifier = encryptedData.slice(5, pos); - else - throw new Error('Decryption error: invalid crypto identifier'); - let metadataLength = null; - if (encryptedData.byteLength >= pos + 1) - metadataLength = encryptedData[pos]; - else - throw new Error('Decryption error: invalid metadata length'); - pos += 1; - if (metadataLength === 255 && encryptedData.byteLength >= pos + 2) { - metadataLength = new Uint16Array(encryptedData.slice(pos, pos + 2)).reduce((acc, val) => (acc << 8) + val, 0); - } - return new CryptorHeaderV1(this.decoder.decode(identifier), metadataLength); + class SubscriptionWorkerMiddleware { + constructor(configuration) { + this.configuration = configuration; + /** + * Whether subscription worker has been initialized and ready to handle events. + */ + this.subscriptionWorkerReady = false; + this.workerEventsQueue = []; + this.callbacks = new Map(); + this.setupSubscriptionWorker(); } - } - CryptorHeader.SENTINEL = 'PNED'; - CryptorHeader.LEGACY_IDENTIFIER = ''; - CryptorHeader.IDENTIFIER_LENGTH = 4; - CryptorHeader.VERSION = 1; - CryptorHeader.MAX_VERSION = 1; - CryptorHeader.decoder = new TextDecoder(); - // v1 CryptorHeader - class CryptorHeaderV1 { - constructor(id, metadataLength) { - this._identifier = id; - this._metadataLength = metadataLength; + makeSendable(req) { + // Use default request flow for non-subscribe / presence leave requests. + if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/leave')) + return this.configuration.transport.makeSendable(req); + let controller; + const sendRequestEvent = { + type: 'send-request', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + logVerbosity: this.configuration.logVerbosity, + request: req, + }; + if (req.cancellable) { + controller = { + abort: () => { + const cancelRequest = { + type: 'cancel-request', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + logVerbosity: this.configuration.logVerbosity, + identifier: req.identifier, + }; + // Cancel active request with specified identifier. + this.scheduleEventPost(cancelRequest); + }, + }; + } + return [ + new Promise((resolve, reject) => { + // Associate Promise resolution / reject with request identifier for future usage in + // `onmessage` handler block to return results. + this.callbacks.set(req.identifier, { resolve, reject }); + // Trigger request processing by Service Worker. + this.scheduleEventPost(sendRequestEvent); + }), + controller, + ]; } - get identifier() { - return this._identifier; + request(req) { + return req; } - set identifier(value) { - this._identifier = value; + /** + * Schedule {@link event} publish to the subscription worker. + * + * Subscription worker may not be ready for events processing and this method build queue for the time when worker + * will be ready. + * + * @param event - Event payload for the subscription worker. + * @param outOfOrder - Whether event should be processed first then enqueued queue. + */ + scheduleEventPost(event, outOfOrder = false) { + // Trigger request processing by subscription worker. + const subscriptionWorker = this.sharedSubscriptionWorker; + if (subscriptionWorker) + subscriptionWorker.port.postMessage(event); + else { + if (outOfOrder) + this.workerEventsQueue.splice(0, 0, event); + else + this.workerEventsQueue.push(event); + } } - get metadataLength() { - return this._metadataLength; + /** + * Dequeue and post events from the queue to the subscription worker. + */ + flushScheduledEvents() { + // Trigger request processing by subscription worker. + const subscriptionWorker = this.sharedSubscriptionWorker; + if (!subscriptionWorker || this.workerEventsQueue.length === 0) + return; + // Clean up from cancelled events. + const outdatedEvents = []; + for (let i = 0; i < this.workerEventsQueue.length; i++) { + const event = this.workerEventsQueue[i]; + // Check whether found request cancel event to search for request send event it cancels. + if (event.type !== 'cancel-request' || i === 0) + continue; + for (let j = 0; j < i; j++) { + const otherEvent = this.workerEventsQueue[j]; + if (otherEvent.type !== 'send-request') + continue; + // Collect outdated events if identifiers match. + if (otherEvent.request.identifier === event.identifier) { + outdatedEvents.push(event, otherEvent); + break; + } + } + } + // Actualizing events queue. + this.workerEventsQueue = this.workerEventsQueue.filter((event) => !outdatedEvents.includes(event)); + this.workerEventsQueue.forEach((event) => subscriptionWorker.port.postMessage(event)); + this.workerEventsQueue = []; } - set metadataLength(value) { - this._metadataLength = value; + /** + * Subscription worker. + * + * @returns Worker which has been registered by the PubNub SDK. + */ + get sharedSubscriptionWorker() { + return this.subscriptionWorkerReady ? this.subscriptionWorker : null; } - get version() { - return CryptorHeader.VERSION; + setupSubscriptionWorker() { + if (typeof SharedWorker === 'undefined') + return; + this.subscriptionWorker = new SharedWorker(this.configuration.workerUrl, `/pubnub-${this.configuration.sdkVersion}`); + this.subscriptionWorker.port.start(); + // Register PubNub client within subscription worker. + this.scheduleEventPost({ + type: 'client-register', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + userId: this.configuration.userId, + logVerbosity: this.configuration.logVerbosity, + workerLogVerbosity: this.configuration.workerLogVerbosity, + }, true); + this.subscriptionWorker.port.onmessage = (event) => this.handleWorkerEvent(event); } - get length() { - return (CryptorHeader.SENTINEL.length + - 1 + - CryptorHeader.IDENTIFIER_LENGTH + - (this.metadataLength < 255 ? 1 : 3) + - this.metadataLength); + handleWorkerEvent(event) { + const { data } = event; + // Ignoring updates not related to this instance. + if (data.type !== 'shared-worker-ping' && + data.type !== 'shared-worker-connected' && + data.type !== 'shared-worker-console-log' && + data.type !== 'shared-worker-console-dir' && + data.clientIdentifier !== this.configuration.clientIdentifier) + return; + if (data.type === 'shared-worker-connected') { + this.subscriptionWorkerReady = true; + this.flushScheduledEvents(); + } + else if (data.type === 'shared-worker-console-log') { + console.log(`[SharedWorker] ${data.message}`); + } + else if (data.type === 'shared-worker-console-dir') { + if (data.message) + console.log(`[SharedWorker] ${data.message}`); + console.dir(data.data); + } + else if (data.type === 'shared-worker-ping') { + const { logVerbosity, subscriptionKey, clientIdentifier } = this.configuration; + this.scheduleEventPost({ + type: 'client-pong', + subscriptionKey, + clientIdentifier, + logVerbosity, + }); + } + else if (data.type === 'request-progress-start' || data.type === 'request-progress-end') { + this.logRequestProgress(data); + } + else if (data.type === 'request-process-success' || data.type === 'request-process-error') { + const { resolve, reject } = this.callbacks.get(data.identifier); + if (data.type === 'request-process-success') { + resolve({ + status: data.response.status, + url: data.url, + headers: data.response.headers, + body: data.response.body, + }); + } + else { + let category = StatusCategory$1.PNUnknownCategory; + let message = 'Unknown error'; + // Handle client-side issues (if any). + if (data.error) { + if (data.error.type === 'NETWORK_ISSUE') + category = StatusCategory$1.PNNetworkIssuesCategory; + else if (data.error.type === 'TIMEOUT') + category = StatusCategory$1.PNTimeoutCategory; + else if (data.error.type === 'ABORTED') + category = StatusCategory$1.PNCancelledCategory; + message = `${data.error.message} (${data.identifier})`; + } + // Handle service error response. + else if (data.response) { + return reject(PubNubAPIError.create({ + url: data.url, + headers: data.response.headers, + body: data.response.body, + status: data.response.status, + }, data.response.body)); + } + reject(new PubNubAPIError(message, category, 0, new Error(message))); + } + } } - get data() { - let pos = 0; - const header = new Uint8Array(this.length); - const encoder = new TextEncoder(); - header.set(encoder.encode(CryptorHeader.SENTINEL)); - pos += CryptorHeader.SENTINEL.length; - header[pos] = this.version; - pos++; - if (this.identifier) - header.set(encoder.encode(this.identifier), pos); - const metadataLength = this.metadataLength; - pos += CryptorHeader.IDENTIFIER_LENGTH; - if (metadataLength < 255) - header[pos] = metadataLength; - else - header.set([255, metadataLength >> 8, metadataLength & 0xff], pos); - return header; + /** + * Print request progress information. + * + * @param information - Request progress information from worker. + */ + logRequestProgress(information) { + var _a, _b; + if (information.type === 'request-progress-start') { + console.log('<<<<<'); + console.log(`[${information.timestamp}] ${information.url}\n${JSON.stringify((_a = information.query) !== null && _a !== void 0 ? _a : {})}`); + console.log('-----'); + } + else { + console.log('>>>>>>'); + console.log(`[${information.timestamp} / ${information.duration}] ${information.url}\n${JSON.stringify((_b = information.query) !== null && _b !== void 0 ? _b : {})}\n${information.response}`); + console.log('-----'); + } } } - CryptorHeaderV1.IDENTIFIER_LENGTH = 4; - CryptorHeaderV1.SENTINEL = 'PNED'; /** * Percent-encode input string. @@ -3213,7 +3225,7 @@ const encodedNames = names.map((name) => encodeString(name)); return encodedNames.length ? encodedNames.join(',') : defaultString !== null && defaultString !== void 0 ? defaultString : ''; }; - const removeSingleOccurance = (source, elementsToRemove) => { + const removeSingleOccurrence = (source, elementsToRemove) => { const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); return source.filter((e) => { if (elementsToRemove.includes(e) && !removed[e]) { @@ -3387,6 +3399,15 @@ */ WebReactNativeTransport.decoder = new TextDecoder(); + /** + * Re-map CBOR object keys from potentially C buffer strings to actual strings. + * + * @param obj CBOR which should be remapped to stringified keys. + * + * @returns Dictionary with stringified keys. + * + * @internal + */ function stringifyBufferKeys(obj) { const isObject = (value) => typeof value === 'object' && value !== null && value.constructor === Object; const isString = (value) => typeof value === 'string' || value instanceof String; @@ -3500,6 +3521,8 @@ * Apply configuration default values. * * @param configuration - User-provided configuration. + * + * @internal */ const setDefaults$1 = (configuration) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; @@ -3599,6 +3622,10 @@ * reconnection issues, set the flag to `false`. This allows the SDK reconnection logic to take over. */ const LISTEN_TO_BROWSER_NETWORK_EVENTS = true; + /** + * Whether verbose logging should be enabled for `Subscription` worker to print debug messages or not. + */ + const SUBSCRIPTION_WORKER_LOG_VERBOSITY = false; /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -3607,15 +3634,17 @@ * Apply configuration default values. * * @param configuration - User-provided configuration. + * + * @internal */ const setDefaults = (configuration) => { - var _a, _b; + var _a, _b, _c; // Force disable service workers if environment doesn't support them. - if (configuration.serviceWorkerUrl && !('serviceWorker' in navigator)) - configuration.serviceWorkerUrl = null; + if (configuration.subscriptionWorkerUrl && typeof SharedWorker === 'undefined') + configuration.subscriptionWorkerUrl = null; return Object.assign(Object.assign({}, setDefaults$1(configuration)), { // Set platform-specific options. - listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, serviceWorkerUrl: configuration.serviceWorkerUrl, keepAlive: (_b = configuration.keepAlive) !== null && _b !== void 0 ? _b : KEEP_ALIVE }); + listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, subscriptionWorkerLogVerbosity: (_b = configuration.subscriptionWorkerLogVerbosity) !== null && _b !== void 0 ? _b : SUBSCRIPTION_WORKER_LOG_VERBOSITY, keepAlive: (_c = configuration.keepAlive) !== null && _c !== void 0 ? _c : KEEP_ALIVE }); }; var uuid = {exports: {}}; @@ -3685,6 +3714,8 @@ // region Defaults /** * Whether encryption (if set) should use random initialization vector or not. + * + * @internal */ const USE_RANDOM_INITIALIZATION_VECTOR = true; /** @@ -3694,6 +3725,8 @@ * @param setupCryptoModule - Platform-provided {@link CryptoModule} configuration block. * * @returns `PubNub` client private configuration. + * + * @internal */ const makeConfiguration = (base, setupCryptoModule) => { var _a, _b, _c; @@ -3777,7 +3810,7 @@ return base.PubNubFile; }, get version() { - return '8.0.1'; + return '8.1.0'; }, getVersion() { return this.version; @@ -3835,6 +3868,8 @@ * REST API access token manager. * * Manager maintains active access token and let parse it to get information about permissions. + * + * @internal */ class TokenManager { constructor(cbor) { @@ -4127,6 +4162,8 @@ */ /** * Real-time listeners' manager. + * + * @internal */ class ListenerManager { constructor() { @@ -4311,6 +4348,13 @@ * * **Note:** Reconnection manger rely on legacy time-based availability check. */ + /** + * Network "discovery" manager. + * + * Manager perform periodic `time` API calls to identify network availability. + * + * @internal + */ class ReconnectionManager { constructor(time) { this.time = time; @@ -4361,6 +4405,11 @@ return hash; }; + /** + * Real-time events deduplication manager. + * + * @internal + */ class DedupingManager { _config; @@ -4399,6 +4448,8 @@ */ /** * Subscription loop manager. + * + * @internal */ class SubscriptionManager { constructor(configuration, listenerManager, eventEmitter, subscribeCall, heartbeatCall, leaveCall, time) { @@ -5309,6 +5360,8 @@ /** * Base REST API request class. + * + * @internal */ class AbstractRequest { /** @@ -5725,6 +5778,8 @@ // region Types /** * PubNub-defined event types by payload. + * + * @internal */ var PubNubEventType; (function (PubNubEventType) { @@ -5762,6 +5817,8 @@ * Subscription request used in small variations in two cases: * - subscription manager * - event engine + * + * @internal */ class BaseSubscribeRequest extends AbstractRequest { constructor(parameters) { @@ -6000,6 +6057,8 @@ } /** * Subscribe request. + * + * @internal */ class SubscribeRequest extends BaseSubscribeRequest { get path() { @@ -6030,6 +6089,14 @@ } } + /** + * Real-time events' emitter. + * + * Emitter responsible for forwarding received real-time events to the closures which has been + * registered for specific events handling. + * + * @internal + */ class EventEmitter { constructor(listenerManager) { this.listenerManager = listenerManager; @@ -6190,6 +6257,9 @@ } } + /** + * @internal + */ class Subject { constructor(sync = false) { this.sync = sync; @@ -6379,6 +6449,11 @@ Object.setPrototypeOf(this, new.target.prototype); } } + /** + * Event Engine stored effect processing cancellation signal. + * + * @internal + */ class AbortSignal extends Subject { constructor() { super(...arguments); @@ -7234,11 +7309,11 @@ } } unsubscribe({ channels = [], channelGroups = [] }) { - const filteredChannels = removeSingleOccurance(this.channels, [ + const filteredChannels = removeSingleOccurrence(this.channels, [ ...channels, ...channels.map((c) => `${c}-pnpres`), ]); - const filteredGroups = removeSingleOccurance(this.groups, [ + const filteredGroups = removeSingleOccurrence(this.groups, [ ...channelGroups, ...channelGroups.map((c) => `${c}-pnpres`), ]); @@ -7313,6 +7388,8 @@ * * Request will normalize and encrypt (if required) provided data and push it to the specified * channel. + * + * @internal */ class PublishRequest extends AbstractRequest { /** @@ -7396,6 +7473,11 @@ * Signal REST API module. */ // endregion + /** + * Signal data (size-limited) publish request. + * + * @internal + */ class SignalRequest extends AbstractRequest { constructor(parameters) { super(); @@ -7433,6 +7515,8 @@ */ /** * Receive messages subscribe request. + * + * @internal */ class ReceiveMessagesSubscribeRequest extends BaseSubscribeRequest { operation() { @@ -7477,6 +7561,8 @@ * Handshake subscribe request. * * Separate subscribe request required by Event Engine. + * + * @internal */ class HandshakeSubscribeRequest extends BaseSubscribeRequest { operation() { @@ -7505,6 +7591,8 @@ // endregion /** * Get `uuid` presence state request. + * + * @internal */ class GetPresenceStateRequest extends AbstractRequest { constructor(parameters) { @@ -7559,6 +7647,8 @@ // endregion /** * Set `uuid` presence state request. + * + * @internal */ class SetPresenceStateRequest extends AbstractRequest { constructor(parameters) { @@ -7605,6 +7695,11 @@ * Announce heartbeat REST API module. */ // endregion + /** + * Announce `uuid` presence request. + * + * @internal + */ class HeartbeatRequest extends AbstractRequest { constructor(parameters) { super(); @@ -7650,6 +7745,11 @@ * Announce leave REST API module. */ // endregion + /** + * Announce user leave request. + * + * @internal + */ class PresenceLeaveRequest extends AbstractRequest { constructor(parameters) { super(); @@ -7697,6 +7797,11 @@ * `uuid` presence REST API module. */ // endregion + /** + * Get `uuid` presence request. + * + * @internal + */ class WhereNowRequest extends AbstractRequest { constructor(parameters) { super(); @@ -7744,6 +7849,11 @@ */ const INCLUDE_STATE = false; // endregion + /** + * Channel presence request. + * + * @internal + */ class HereNowRequest extends AbstractRequest { constructor(parameters) { var _a, _b, _c; @@ -7826,6 +7936,8 @@ // endregion /** * Delete messages from channel history. + * + * @internal */ class DeleteMessageRequest extends AbstractRequest { constructor(parameters) { @@ -7866,6 +7978,11 @@ * Messages count REST API module. */ // endregion + /** + * Count messages request. + * + * @internal + */ class MessageCountRequest extends AbstractRequest { constructor(parameters) { super(); @@ -7935,6 +8052,8 @@ // endregion /** * Get single channel messages request. + * + * @internal */ class GetHistoryRequest extends AbstractRequest { constructor(parameters) { @@ -8080,6 +8199,8 @@ // endregion /** * Fetch messages from channels request. + * + * @internal */ class FetchMessagesRequest extends AbstractRequest { constructor(parameters) { @@ -8230,6 +8351,8 @@ // endregion /** * Fetch channel message actions request. + * + * @internal */ class GetMessageActionsRequest extends AbstractRequest { constructor(parameters) { @@ -8283,6 +8406,8 @@ // endregion /** * Add Message Reaction request. + * + * @internal */ class AddMessageActionRequest extends AbstractRequest { constructor(parameters) { @@ -8338,6 +8463,8 @@ // endregion /** * Remove specific message action request. + * + * @internal */ class RemoveMessageAction extends AbstractRequest { constructor(parameters) { @@ -8387,6 +8514,11 @@ */ const STORE_IN_HISTORY = true; // endregion + /** + * Publish shared file information request. + * + * @internal + */ class PublishFileMessageRequest extends AbstractRequest { constructor(parameters) { var _a; @@ -8456,6 +8588,8 @@ * File download Url generation request. * * Local request which generates Url to download shared file from the specific channel. + * + * @internal */ class GetFileDownloadUrlRequest extends AbstractRequest { /** @@ -8496,6 +8630,8 @@ // endregion /** * Delete File request. + * + * @internal */ class DeleteFileRequest extends AbstractRequest { constructor(parameters) { @@ -8545,6 +8681,8 @@ // endregion /** * Files List request. + * + * @internal */ class FilesListRequest extends AbstractRequest { constructor(parameters) { @@ -8589,6 +8727,8 @@ // endregion /** * Generate File Upload Url request. + * + * @internal */ class GenerateFileUploadUrlRequest extends AbstractRequest { constructor(parameters) { @@ -8634,6 +8774,8 @@ */ /** * File Upload request. + * + * @internal */ class UploadFileRequest extends AbstractRequest { constructor(parameters) { @@ -8689,6 +8831,8 @@ // endregion /** * Send file composed request. + * + * @internal */ class SendFileRequest { constructor(parameters) { @@ -8813,6 +8957,8 @@ * Access token revoke request. * * Invalidate token and permissions which has been granted for it. + * + * @internal */ class RevokeTokenRequest extends AbstractRequest { constructor(parameters) { @@ -8851,6 +8997,8 @@ // endregion /** * Grant token permissions request. + * + * @internal */ class GrantTokenRequest extends AbstractRequest { constructor(parameters) { @@ -9049,6 +9197,8 @@ // endregion /** * Grant permissions request. + * + * @internal */ class GrantRequest extends AbstractRequest { constructor(parameters) { @@ -9118,6 +9268,8 @@ // endregion /** * Permissions audit request. + * + * @internal */ class AuditRequest extends AbstractRequest { constructor(parameters) { @@ -9355,6 +9507,8 @@ // endregion /** * Remove channel group channels request. + * + * @internal */ // prettier-ignore class RemoveChannelGroupChannelsRequest extends AbstractRequest { @@ -9400,6 +9554,8 @@ // endregion /** * Add channel group channels request. + * + * @internal */ class AddChannelGroupChannelsRequest extends AbstractRequest { constructor(parameters) { @@ -9444,6 +9600,8 @@ // endregion /** * List Channel Group Channels request. + * + * @internal */ class ListChannelGroupChannels extends AbstractRequest { constructor(parameters) { @@ -9482,6 +9640,8 @@ // endregion /** * Channel group delete request. + * + * @internal */ class DeleteChannelGroupRequest extends AbstractRequest { constructor(parameters) { @@ -9520,6 +9680,8 @@ // endregion /** * List all channel groups request. + * + * @internal */ class ListChannelGroupsRequest extends AbstractRequest { constructor(parameters) { @@ -9663,6 +9825,8 @@ // endregion /** * Base push notification request. + * + * @internal */ class BasePushNotificationChannelsRequest extends AbstractRequest { constructor(parameters) { @@ -9726,6 +9890,8 @@ // endregion /** * Unregister channels from device push request. + * + * @internal */ // prettier-ignore class RemoveDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest { @@ -9751,6 +9917,8 @@ // endregion /** * List device push enabled channels request. + * + * @internal */ // prettier-ignore class ListDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest { @@ -9776,6 +9944,8 @@ // endregion /** * Register channels with device push request. + * + * @internal */ // prettier-ignore class AddDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest { @@ -9801,6 +9971,8 @@ // endregion /** * Unregister device push notifications request. + * + * @internal */ // prettier-ignore class RemoveDevicePushNotificationRequest extends BasePushNotificationChannelsRequest { @@ -9912,6 +10084,8 @@ // endregion /** * Get All Channels Metadata request. + * + * @internal */ class GetAllChannelsMetadataRequest extends AbstractRequest { constructor(parameters) { @@ -9955,6 +10129,8 @@ // endregion /** * Remove Channel Metadata request. + * + * @internal */ class RemoveChannelMetadataRequest extends AbstractRequest { constructor(parameters) { @@ -10027,6 +10203,8 @@ // endregion /** * Get UUID Memberships request. + * + * @internal */ class GetUUIDMembershipsRequest extends AbstractRequest { constructor(parameters) { @@ -10120,6 +10298,8 @@ // endregion /** * Set UUID Memberships request. + * + * @internal */ class SetUUIDMembershipsRequest extends AbstractRequest { constructor(parameters) { @@ -10206,6 +10386,11 @@ */ const LIMIT$2 = 100; // endregion + /** + * Get All UUIDs Metadata request. + * + * @internal + */ class GetAllUUIDMetadataRequest extends AbstractRequest { constructor(parameters) { var _a, _b, _c; @@ -10255,6 +10440,8 @@ // endregion /** * Get Channel Metadata request. + * + * @internal */ class GetChannelMetadataRequest extends AbstractRequest { constructor(parameters) { @@ -10309,6 +10496,8 @@ // endregion /** * Set Channel Metadata request. + * + * @internal */ class SetChannelMetadataRequest extends AbstractRequest { constructor(parameters) { @@ -10360,6 +10549,8 @@ // endregion /** * Remove UUID Metadata request. + * + * @internal */ class RemoveUUIDMetadataRequest extends AbstractRequest { constructor(parameters) { @@ -10435,6 +10626,8 @@ // endregion /** * Get Channel Members request. + * + * @internal */ class GetChannelMembersRequest extends AbstractRequest { constructor(parameters) { @@ -10525,6 +10718,8 @@ // endregion /** * Set Channel Members request. + * + * @internal */ class SetChannelMembersRequest extends AbstractRequest { constructor(parameters) { @@ -10606,6 +10801,8 @@ // endregion /** * Get UUID Metadata request. + * + * @internal */ class GetUUIDMetadataRequest extends AbstractRequest { constructor(parameters) { @@ -10662,6 +10859,8 @@ // endregion /** * Set UUID Metadata request. + * + * @internal */ class SetUUIDMetadataRequest extends AbstractRequest { constructor(parameters) { @@ -11233,6 +11432,11 @@ * Time REST API module. */ // endregion + /** + * Get current PubNub high-precision time request. + * + * @internal + */ class TimeRequest extends AbstractRequest { constructor() { super(); @@ -11259,6 +11463,8 @@ // endregion /** * Download File request. + * + * @internal */ class DownloadFileRequest extends AbstractRequest { constructor(parameters) { @@ -12937,7 +13143,9 @@ } } /** - * {@link ArrayBuffer} to {@link string} decoder. + * {@link ArrayBuffer} to {@link string} decoder. + * + * @internal */ PubNubCore.decoder = new TextDecoder(); // -------------------------------------------------------- @@ -12966,6 +13174,8 @@ */ /** * CBOR data decoder. + * + * @internal */ class Cbor { constructor(decode, base64ToBinary) { @@ -13025,14 +13235,16 @@ } // Setup transport provider. let transport = new WebReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity); - if (configurationCopy.serviceWorkerUrl) { - // Inject subscription service worker into transport provider stack. - transport = new SubscriptionServiceWorkerMiddleware({ + if (configurationCopy.subscriptionWorkerUrl) { + // Inject subscription worker into transport provider stack. + transport = new SubscriptionWorkerMiddleware({ clientIdentifier: clientConfiguration._instanceId, subscriptionKey: clientConfiguration.subscribeKey, - serviceWorkerUrl: configurationCopy.serviceWorkerUrl, + userId: clientConfiguration.getUserId(), + workerUrl: configurationCopy.subscriptionWorkerUrl, sdkVersion: clientConfiguration.getVersion(), logVerbosity: clientConfiguration.logVerbosity, + workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity, transport, }); } diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 435b2833f..c8962dd2c 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,o=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new c(r,n,o,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new o(null!=t?t:this.message,this.toStatus(e))}}class u{constructor(e){this.configuration=e,this.serviceWorkerEventsQueue=[],this.callbacks=new Map,this.setupServiceWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.serviceWorker;s?s.postMessage(e):t?this.serviceWorkerEventsQueue.splice(0,0,e):this.serviceWorkerEventsQueue.push(e)}flushScheduledEvents(){const e=this.serviceWorker;if(!e||0===this.serviceWorkerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.serviceWorkerEventsQueue.forEach((t=>e.postMessage(t))),this.serviceWorkerEventsQueue=[]}get serviceWorker(){return this.serviceWorkerRegistration?this.serviceWorkerRegistration.active:null}setupServiceWorker(){if(!("serviceWorker"in navigator))return;const e=navigator.serviceWorker;e.register(this.configuration.serviceWorkerUrl,{scope:`/pubnub-${this.configuration.sdkVersion}`}).then((e=>{this.serviceWorkerRegistration=e,e.active&&this.flushScheduledEvents(),this.serviceWorkerRegistration.addEventListener("updatefound",(()=>{if(!this.serviceWorkerRegistration)return;const e=this.serviceWorkerRegistration.installing,t=()=>{"activated"===e.state?this.flushScheduledEvents():"redundant"===e.state&&e.removeEventListener("statechange",t)};e.addEventListener("statechange",t)}))})),e.addEventListener("message",(e=>this.handleServiceWorkerEvent(e)))}handleServiceWorkerEvent(e){const{data:t}=e;if(t.clientIdentifier===this.configuration.clientIdentifier)if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=i.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=i.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=i.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=i.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(c.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new c(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}function l(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(e);r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return h(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return h(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return h(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return h(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return h(this,void 0,void 0,(function*(){return this.data}))}}p.supportsBlob="undefined"!=typeof Blob,p.supportsFile="undefined"!=typeof File,p.supportsBuffer=!1,p.supportsStream=!1,p.supportsString=!0,p.supportsArrayBuffer=!0,p.supportsEncryptFile=!0,p.supportsFileUri=!1;function g(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function y(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var f,m,b,v,w,S=S||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return v.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=S,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=S,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:g(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return h(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return h(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return h(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=P.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:M.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new o("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:y(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return h(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new o("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}M.encoder=new TextEncoder,M.decoder=new TextDecoder;class j extends d{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new o("Crypto module error: cipher key not set.");return new j({default:new M(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new o("Crypto module error: cipher key not set.");return new j({default:new E({cipherKey:e.cipherKey}),cryptors:[new M(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(j.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return h(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?g(e):e,s=_.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return h(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=_.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return h(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof p)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}j.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==_.SENTINEL))return j.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(n),o)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";const R=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>R(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw c.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw c.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return h(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${R(t)}`)).join("&"):`${e}=${R(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s;return e.serviceWorkerUrl&&!("serviceWorker"in navigator)&&(e.serviceWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,a,c,u,l,h,d,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.restore)&&void 0!==i||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(d=m.maintainPresenceState)&&void 0!==d||(m.maintainPresenceState=!0),null!==(p=m.keepAlive)&&void 0!==p||(m.keepAlive=!1),m.userId&&m.uuid)throw new o("PubNub client configuration error: use only 'userId'");if(null!==(g=m.userId)&&void 0!==g||(m.userId=m.uuid),!m.userId)throw new o("PubNub client configuration error: 'userId' not set");if(0===(null===(y=m.userId)||void 0===y?void 0:y.trim().length))throw new o("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),null!==(f=m.presenceTimeout)&&void 0!==f||(m.presenceTimeout=300);let v=!1,w=!0,S=5,k=!1,E=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(E=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:100,useRequestId:E,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,serviceWorkerUrl:e.serviceWorkerUrl,keepAlive:null===(s=e.keepAlive)||void 0===s||s})};var K={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(K,K.exports);var q=t(K.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.0.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${R(e)}`)).join("&"):`${t}=${R(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:i.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:i.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const r=new Set,i=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],i.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],i.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],r.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],r.add(e))})),0===i.size&&0===r.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(r),s=Array.from(i),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,r=l(e,["error"]);let i;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?i=e.errorData.message:"message"in e&&"string"==typeof e.message&&(i=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},r),{error:null!=i&&i,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===i.PNCancelledCategory)return;return void(e.category===i.PNTimeoutCategory?this.startSubscribeLoop():e.category===i.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:i.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===i.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:i.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:i.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:i.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=l(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return h(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,type:o}=s,a=l(s,["event","type"]),c=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",type:"user"})});this.listenerManager.announceUser(c),this.announce("user",c,c.spaceId,c.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,type:o}=s,a=l(s,["event","type"]),c=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(c),this.announce("space",c,c.spaceId,c.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,r=l(t,["message","channel"]),{event:i,data:o}=s,a=l(s,["event","data"]),{uuid:c,channel:u}=o,h=l(o,["uuid","channel"]),d=Object.assign(Object.assign({},r),{spaceId:n,message:Object.assign(Object.assign({},a),{event:"set"===i?"updated":"removed",data:Object.assign(Object.assign({},h),{user:c,space:u})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),je=pe("TIMES_UP",(()=>({}))),_e=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Re=ge("EMIT_STATUS",(e=>e)),Ie=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(_e.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:a}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:r}),{heartbeat:a.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ae.type,we(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(je())}))))),this.on(Ue.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:a,config:c}){if(!c.retryConfiguration||!c.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(c.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},c.maintainPresenceState&&{state:a}),{heartbeat:c.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Re.type,we(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ge.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Ie())),xe.onExit((()=>Ie.cancel)),xe.on(je.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ke=new le("HEARBEAT_RECONNECTING");Ke.onEnter((e=>Ue(e))),Ke.onExit((()=>Ue.cancel)),Ke.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Ke.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),Ke.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ke.on(Pe.type,((e,t)=>Ke.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ke.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new le("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new le("HEARTBEAT_INACTIVE");Ge.on(Ee.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:a}){s.throwIfAborted();try{const i=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:r}));return e.transition(Xe(i))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>h(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new o(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:a.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>h(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:a,config:c}){if(!c.retryConfiguration||!c.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new o(c.retryConfiguration?c.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(c.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:c.filterExpression},c.maintainPresenceState&&{state:a}));return e.transition(et(r))}catch(t){if(t instanceof o){if(t.status&&t.status.category==i.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:i.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:i.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:i.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:i.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:i.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:i.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:i.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:i.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${R(t)}/0${this.parameters.sendByPost?"":`/${R(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:y(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${R(s)}/0/${R(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${R(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${R(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(n.status>=400)throw c.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,u={};let l={};if("occupancy"in n){const e=this.parameters.channels[0];l[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else l=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(l).forEach((e=>{const t=l[e];u[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:u}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class Rt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(s.status>=400)throw c.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{data:t.data}}))}get headers(){return{"Content-Type":"application/json"}}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}/message/${s}`}get body(){return JSON.stringify(this.parameters.action)}}class Kt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${R(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${R(t)}/0/${R(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:y(s))}}class Gt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${R(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${R(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/generate-upload-url`}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return h(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new o("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:i.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof o)throw e;const t=e instanceof c?e:c.create(e);throw new o("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return h(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return h(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return h(this,void 0,void 0,(function*(){var s,n,r,a;let c,u={timetoken:"0"},l=this.parameters.fileUploadPublishRetryLimit,h=!1;do{try{u=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),h=!0}catch(e){e instanceof o&&(c=e),l-=1}}while(!h&&l>0);if(h)return{status:200,timetoken:u.timetoken,id:e,name:t};throw new o("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=c.status)||void 0===s?void 0:s.category)&&void 0!==n?n:i.PNUnknownCategory,statusCode:null!==(a=null===(r=c.status)||void 0===r?void 0:r.statusCode)&&void 0!==a?a:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNAccessManagerRevokeToken}validate(){return this.parameters.keySet.secretKey?this.parameters.token?void 0:"token can't be empty":"Missing Secret Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},token:t}=this.parameters;return`/v3/pam/${e}/grant/${R(t)}`}}class Wt extends se{constructor(e){var t,s,n,r;super({method:H.POST}),this.parameters=e,null!==(t=(n=this.parameters).resources)&&void 0!==t||(n.resources={}),null!==(s=(r=this.parameters).patterns)&&void 0!==s||(r.patterns={})}operation(){return re.PNAccessManagerGrantToken}validate(){var e,t,s,n,r,i;const{keySet:{subscribeKey:o,publishKey:a,secretKey:c},resources:u,patterns:l}=this.parameters;if(!o)return"Missing Subscribe Key";if(!a)return"Missing Publish Key";if(!c)return"Missing Secret Key";if(!u&&!l)return"Missing either Resources or Patterns";if(this.isVspPermissions(this.parameters)&&("channels"in(null!==(e=this.parameters.resources)&&void 0!==e?e:{})||"uuids"in(null!==(t=this.parameters.resources)&&void 0!==t?t:{})||"groups"in(null!==(s=this.parameters.resources)&&void 0!==s?s:{})||"channels"in(null!==(n=this.parameters.patterns)&&void 0!==n?n:{})||"uuids"in(null!==(r=this.parameters.patterns)&&void 0!==r?r:{})||"groups"in(null!==(i=this.parameters.patterns)&&void 0!==i?i:{})))return"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`";let h=!0;return[this.parameters.resources,this.parameters.patterns].forEach((e=>{Object.keys(null!=e?e:{}).forEach((t=>{var s;e&&h&&Object.keys(null!==(s=e[t])&&void 0!==s?s:{}).length>0&&(h=!1)}))})),h?"Missing values for either Resources or Patterns":void 0}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.data.token}))}get path(){return`/v3/pam/${this.parameters.keySet.subscribeKey}/grant`}get body(){const{ttl:e,meta:t}=this.parameters,s=Object.assign({},e||0===e?{ttl:e}:{}),n=this.isVspPermissions(this.parameters)?this.parameters.authorizedUserId:this.parameters.authorized_uuid,r={},i={},o={},a=(e,t,s,n)=>{n[s]||(n[s]={}),n[s][e]=t},{resources:c,patterns:u}=this.parameters;return[c,u].forEach(((e,t)=>{var s,n,r,c,u;const l=0===t?i:o;let h={},d={},p={};l.channels||(l.channels={}),l.groups||(l.groups={}),l.uuids||(l.uuids={}),l.users||(l.users={}),l.spaces||(l.spaces={}),e&&("spaces"in e||"users"in e?(h=null!==(s=e.spaces)&&void 0!==s?s:{},p=null!==(n=e.users)&&void 0!==n?n:{}):("channels"in e||"uuids"in e||"groups"in e)&&(h=null!==(r=e.channels)&&void 0!==r?r:{},d=null!==(c=e.groups)&&void 0!==c?c:{},p=null!==(u=e.uuids)&&void 0!==u?u:{})),Object.keys(h).forEach((e=>a(e,this.extractPermissions(h[e]),"channels",l))),Object.keys(d).forEach((e=>a(e,this.extractPermissions(d[e]),"groups",l))),Object.keys(p).forEach((e=>a(e,this.extractPermissions(p[e]),"uuids",l)))})),n&&(r.uuid=`${n}`),r.resources=i,r.patterns=o,r.meta=null!=t?t:{},s.permissions=r,JSON.stringify(s)}extractPermissions(e){let t=0;return"join"in e&&e.join&&(t|=128),"update"in e&&e.update&&(t|=64),"get"in e&&e.get&&(t|=32),"delete"in e&&e.delete&&(t|=8),"manage"in e&&e.manage&&(t|=4),"write"in e&&e.write&&(t|=2),"read"in e&&e.read&&(t|=1),t}isVspPermissions(e){var t,s,n,r;return"authorizedUserId"in e||"spaces"in(null!==(t=e.resources)&&void 0!==t?t:{})||"users"in(null!==(s=e.resources)&&void 0!==s?s:{})||"spaces"in(null!==(n=e.patterns)&&void 0!==n?n:{})||"users"in(null!==(r=e.patterns)&&void 0!==r?r:{})}}class Jt extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b,v,w;super(),this.parameters=e,null!==(t=(h=this.parameters).channels)&&void 0!==t||(h.channels=[]),null!==(s=(d=this.parameters).channelGroups)&&void 0!==s||(d.channelGroups=[]),null!==(n=(p=this.parameters).uuids)&&void 0!==n||(p.uuids=[]),null!==(r=(g=this.parameters).read)&&void 0!==r||(g.read=false),null!==(i=(y=this.parameters).write)&&void 0!==i||(y.write=false),null!==(o=(f=this.parameters).delete)&&void 0!==o||(f.delete=false),null!==(a=(m=this.parameters).get)&&void 0!==a||(m.get=false),null!==(c=(b=this.parameters).update)&&void 0!==c||(b.update=false),null!==(u=(v=this.parameters).manage)&&void 0!==u||(v.manage=false),null!==(l=(w=this.parameters).join)&&void 0!==l||(w.join=false)}operation(){return re.PNAccessManagerGrant}validate(){const{keySet:{subscribeKey:e,publishKey:t,secretKey:s},uuids:n=[],channels:r=[],channelGroups:i=[],authKeys:o=[]}=this.parameters;return e?t?s?0!==n.length&&0===o.length?"authKeys are required for grant request on uuids":!n.length||0===r.length&&0===i.length?void 0:"Both channel/channel group and uuid cannot be used in the same request":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload}))}get path(){return`/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channels:e,channelGroups:t,authKeys:s,uuids:n,read:r,write:i,manage:o,delete:a,get:c,join:u,update:l,ttl:h}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},e&&(null==e?void 0:e.length)>0?{channel:e.join(",")}:{}),t&&(null==t?void 0:t.length)>0?{"channel-group":t.join(",")}:{}),s&&(null==s?void 0:s.length)>0?{auth:s.join(",")}:{}),n&&(null==n?void 0:n.length)>0?{"target-uuid":n.join(",")}:{}),{r:r?"1":"0",w:i?"1":"0",m:o?"1":"0",d:a?"1":"0",g:c?"1":"0",j:u?"1":"0",u:l?"1":"0"}),h||0===h?{ttl:h}:{})}}const Qt=[];class Yt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).authKeys)&&void 0!==t||(s.authKeys=Qt)}operation(){return re.PNAccessManagerAudit}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t.payload}))}get path(){return`/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channel:e,channelGroup:t,authKeys:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},e?{channel:e}:{}),t?{"channel-group":t}:{}),s&&s.length?{auth:s.join(",")}:{})}}class Xt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Zt extends Xt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class es extends Xt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Zt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ts{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new es({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ss{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new es({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ns{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new es({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class rs{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new es({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class is extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class os extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class as extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}`}}class cs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${R(t)}/remove`}}class us extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class ls{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return h(this,void 0,void 0,(function*(){const t=new us({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new is(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return h(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return h(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class ds extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class ps extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{channels:t}}))}}class gs extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class ys extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return h(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{}}))}}class fs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new gs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return h(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return h(this,void 0,void 0,(function*(){const s=new ys(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ms extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}}class Cs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ns extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${R(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ps extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Ms extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));if(t.status>=400)throw c.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${R(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class js{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new Ss(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Os(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ms(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return h(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return h(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return h(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class _s extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return h(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new o("Service response error, check status for details",a("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class As extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return h(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${R(t)}/files/${s}/${n}`}}class Rs{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new js(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new fs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new o("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:i.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new rs(e,this.eventEmitter,this)}channelGroup(e){return new ss(e,this.eventEmitter,this)}channelMetadata(e){return new ts(e,this.eventEmitter,this)}userMetadata(e){return new ns(e,this.eventEmitter,this)}subscriptionSet(e){return new Zt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return h(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(a(s),null);throw new o("Validation failed, check status for details",a(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:i.PNAcknowledgmentCategory,statusCode:0},[u,l]=this.transport.makeSendable(n);return e.cancellationController=l||null,u.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Rs.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof c?s:c.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return h(this,void 0,void 0,(function*(){const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}signal(e,t){return h(this,void 0,void 0,(function*(){const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fire(e,t){return h(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return h(this,void 0,void 0,(function*(){const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}))}subscribeReceiveMessages(e){return h(this,void 0,void 0,(function*(){const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}))}getMessageActions(e,t){return h(this,void 0,void 0,(function*(){const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addMessageAction(e,t){return h(this,void 0,void 0,(function*(){const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMessageAction(e,t){return h(this,void 0,void 0,(function*(){const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMessages(e,t){return h(this,void 0,void 0,(function*(){const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteMessages(e,t){return h(this,void 0,void 0,(function*(){const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}messageCounts(e,t){return h(this,void 0,void 0,(function*(){const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}history(e,t){return h(this,void 0,void 0,(function*(){const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}hereNow(e,t){return h(this,void 0,void 0,(function*(){const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}whereNow(e,t){return h(this,void 0,void 0,(function*(){var s;const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}))}getState(e,t){return h(this,void 0,void 0,(function*(){var s;const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setState(e,t){return h(this,void 0,void 0,(function*(){var s,n;const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return h(this,void 0,void 0,(function*(){const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return h(this,void 0,void 0,(function*(){const s=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}revokeToken(e,t){return h(this,void 0,void 0,(function*(){const s=new Vt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get token(){return this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager.parseToken(e)}grant(e,t){return h(this,void 0,void 0,(function*(){const s=new Jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}audit(e,t){return h(this,void 0,void 0,(function*(){const s=new Yt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get objects(){return this._objects}fetchUsers(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return h(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return h(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return h(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return h(this,void 0,void 0,(function*(){var s,n,r;if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:i.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof o?s=e.status:e instanceof c&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new o("REST API request processing error, check status for details",s)}))}))}publishFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listFiles(e,t){return h(this,void 0,void 0,(function*(){const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getFileUrl(e){var t;const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${R(t)}`)).join("&"):`${e}=${R(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}downloadFile(e,t){return h(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new As(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}))}deleteFile(e,t){return h(this,void 0,void 0,(function*(){const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}time(e){return h(this,void 0,void 0,(function*(){const t=new _s;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:y(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return h(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Rs.decoder=new TextDecoder,Rs.OPERATIONS=re,Rs.CATEGORIES=i,Rs.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Rs.LinearRetryPolicy=Le.LinearRetryPolicy;class Is{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Us extends Rs{constructor(e){var t;const s=D(e),n=Object.assign(Object.assign({},s),{sdkFamily:"Web",PubNubFile:p}),i=$(n,(e=>{if(e.cipherKey)return new j({default:new M(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})})),o=new B(new Is((e=>x(r.decode(e))),g));let a;(i.getCipherKey()||i.secretKey)&&(a=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()}));let c=new F(i.keepAlive,i.logVerbosity);s.serviceWorkerUrl&&(c=new u({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,serviceWorkerUrl:s.serviceWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,transport:c}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:c}),cryptography:new P,tokenManager:o,crypto:a}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Us.CryptoModule=j,Us})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.restore)&&void 0!==i||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(a=m.suppressLeaveEvents)&&void 0!==a||(m.suppressLeaveEvents=!1),null!==(c=m.requestMessageCountThreshold)&&void 0!==c||(m.requestMessageCountThreshold=100),null!==(u=m.autoNetworkDetection)&&void 0!==u||(m.autoNetworkDetection=!1),null!==(l=m.enableEventEngine)&&void 0!==l||(m.enableEventEngine=!1),null!==(h=m.maintainPresenceState)&&void 0!==h||(m.maintainPresenceState=!0),null!==(p=m.keepAlive)&&void 0!==p||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=m.userId)&&void 0!==g||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=m.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),null!==(f=m.presenceTimeout)&&void 0!==f||(m.presenceTimeout=300);let v=!1,w=!0,S=5,k=!1,E=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(E=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:100,useRequestId:E,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var K={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(K,K.exports);var q=t(K.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.1.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),je=pe("TIMES_UP",(()=>({}))),_e=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(_e.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ae.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(je())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ge.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(je.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ke=new le("HEARBEAT_RECONNECTING");Ke.onEnter((e=>Ue(e))),Ke.onExit((()=>Ue.cancel)),Ke.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Ke.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),Ke.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ke.on(Pe.type,((e,t)=>Ke.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ke.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new le("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new le("HEARTBEAT_INACTIVE");Ge.on(Ee.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get headers(){return{"Content-Type":"application/json"}}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get body(){return JSON.stringify(this.parameters.action)}}class Kt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNAccessManagerRevokeToken}validate(){return this.parameters.keySet.secretKey?this.parameters.token?void 0:"token can't be empty":"Missing Secret Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},token:t}=this.parameters;return`/v3/pam/${e}/grant/${I(t)}`}}class Wt extends se{constructor(e){var t,s,n,r;super({method:H.POST}),this.parameters=e,null!==(t=(n=this.parameters).resources)&&void 0!==t||(n.resources={}),null!==(s=(r=this.parameters).patterns)&&void 0!==s||(r.patterns={})}operation(){return re.PNAccessManagerGrantToken}validate(){var e,t,s,n,r,i;const{keySet:{subscribeKey:o,publishKey:a,secretKey:c},resources:u,patterns:l}=this.parameters;if(!o)return"Missing Subscribe Key";if(!a)return"Missing Publish Key";if(!c)return"Missing Secret Key";if(!u&&!l)return"Missing either Resources or Patterns";if(this.isVspPermissions(this.parameters)&&("channels"in(null!==(e=this.parameters.resources)&&void 0!==e?e:{})||"uuids"in(null!==(t=this.parameters.resources)&&void 0!==t?t:{})||"groups"in(null!==(s=this.parameters.resources)&&void 0!==s?s:{})||"channels"in(null!==(n=this.parameters.patterns)&&void 0!==n?n:{})||"uuids"in(null!==(r=this.parameters.patterns)&&void 0!==r?r:{})||"groups"in(null!==(i=this.parameters.patterns)&&void 0!==i?i:{})))return"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`";let h=!0;return[this.parameters.resources,this.parameters.patterns].forEach((e=>{Object.keys(null!=e?e:{}).forEach((t=>{var s;e&&h&&Object.keys(null!==(s=e[t])&&void 0!==s?s:{}).length>0&&(h=!1)}))})),h?"Missing values for either Resources or Patterns":void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.data.token}))}get path(){return`/v3/pam/${this.parameters.keySet.subscribeKey}/grant`}get body(){const{ttl:e,meta:t}=this.parameters,s=Object.assign({},e||0===e?{ttl:e}:{}),n=this.isVspPermissions(this.parameters)?this.parameters.authorizedUserId:this.parameters.authorized_uuid,r={},i={},o={},a=(e,t,s,n)=>{n[s]||(n[s]={}),n[s][e]=t},{resources:c,patterns:u}=this.parameters;return[c,u].forEach(((e,t)=>{var s,n,r,c,u;const l=0===t?i:o;let h={},d={},p={};l.channels||(l.channels={}),l.groups||(l.groups={}),l.uuids||(l.uuids={}),l.users||(l.users={}),l.spaces||(l.spaces={}),e&&("spaces"in e||"users"in e?(h=null!==(s=e.spaces)&&void 0!==s?s:{},p=null!==(n=e.users)&&void 0!==n?n:{}):("channels"in e||"uuids"in e||"groups"in e)&&(h=null!==(r=e.channels)&&void 0!==r?r:{},d=null!==(c=e.groups)&&void 0!==c?c:{},p=null!==(u=e.uuids)&&void 0!==u?u:{})),Object.keys(h).forEach((e=>a(e,this.extractPermissions(h[e]),"channels",l))),Object.keys(d).forEach((e=>a(e,this.extractPermissions(d[e]),"groups",l))),Object.keys(p).forEach((e=>a(e,this.extractPermissions(p[e]),"uuids",l)))})),n&&(r.uuid=`${n}`),r.resources=i,r.patterns=o,r.meta=null!=t?t:{},s.permissions=r,JSON.stringify(s)}extractPermissions(e){let t=0;return"join"in e&&e.join&&(t|=128),"update"in e&&e.update&&(t|=64),"get"in e&&e.get&&(t|=32),"delete"in e&&e.delete&&(t|=8),"manage"in e&&e.manage&&(t|=4),"write"in e&&e.write&&(t|=2),"read"in e&&e.read&&(t|=1),t}isVspPermissions(e){var t,s,n,r;return"authorizedUserId"in e||"spaces"in(null!==(t=e.resources)&&void 0!==t?t:{})||"users"in(null!==(s=e.resources)&&void 0!==s?s:{})||"spaces"in(null!==(n=e.patterns)&&void 0!==n?n:{})||"users"in(null!==(r=e.patterns)&&void 0!==r?r:{})}}class Jt extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b,v,w;super(),this.parameters=e,null!==(t=(h=this.parameters).channels)&&void 0!==t||(h.channels=[]),null!==(s=(d=this.parameters).channelGroups)&&void 0!==s||(d.channelGroups=[]),null!==(n=(p=this.parameters).uuids)&&void 0!==n||(p.uuids=[]),null!==(r=(g=this.parameters).read)&&void 0!==r||(g.read=false),null!==(i=(y=this.parameters).write)&&void 0!==i||(y.write=false),null!==(o=(f=this.parameters).delete)&&void 0!==o||(f.delete=false),null!==(a=(m=this.parameters).get)&&void 0!==a||(m.get=false),null!==(c=(b=this.parameters).update)&&void 0!==c||(b.update=false),null!==(u=(v=this.parameters).manage)&&void 0!==u||(v.manage=false),null!==(l=(w=this.parameters).join)&&void 0!==l||(w.join=false)}operation(){return re.PNAccessManagerGrant}validate(){const{keySet:{subscribeKey:e,publishKey:t,secretKey:s},uuids:n=[],channels:r=[],channelGroups:i=[],authKeys:o=[]}=this.parameters;return e?t?s?0!==n.length&&0===o.length?"authKeys are required for grant request on uuids":!n.length||0===r.length&&0===i.length?void 0:"Both channel/channel group and uuid cannot be used in the same request":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload}))}get path(){return`/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channels:e,channelGroups:t,authKeys:s,uuids:n,read:r,write:i,manage:o,delete:a,get:c,join:u,update:l,ttl:h}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},e&&(null==e?void 0:e.length)>0?{channel:e.join(",")}:{}),t&&(null==t?void 0:t.length)>0?{"channel-group":t.join(",")}:{}),s&&(null==s?void 0:s.length)>0?{auth:s.join(",")}:{}),n&&(null==n?void 0:n.length)>0?{"target-uuid":n.join(",")}:{}),{r:r?"1":"0",w:i?"1":"0",m:o?"1":"0",d:a?"1":"0",g:c?"1":"0",j:u?"1":"0",u:l?"1":"0"}),h||0===h?{ttl:h}:{})}}const Qt=[];class Yt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).authKeys)&&void 0!==t||(s.authKeys=Qt)}operation(){return re.PNAccessManagerAudit}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload}))}get path(){return`/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channel:e,channelGroup:t,authKeys:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},e?{channel:e}:{}),t?{"channel-group":t}:{}),s&&s.length?{auth:s.join(",")}:{})}}class Xt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Zt extends Xt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class es extends Xt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Zt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ts{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new es({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ss{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new es({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ns{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new es({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class rs{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new es({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class is extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class os extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class as extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class cs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class us extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class ls{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new us({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new is(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class ds extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ps extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class gs extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ys extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class fs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new gs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ys(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ms extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class Cs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ns extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ps extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Ms extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class js{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new Ss(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Os(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ms(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class _s extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class As extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Is{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new js(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new fs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new rs(e,this.eventEmitter,this)}channelGroup(e){return new ss(e,this.eventEmitter,this)}channelMetadata(e){return new ts(e,this.eventEmitter,this)}userMetadata(e){return new ns(e,this.eventEmitter,this)}subscriptionSet(e){return new Zt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Is.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}signal(e,t){return i(this,void 0,void 0,(function*(){const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}history(e,t){return i(this,void 0,void 0,(function*(){const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){const s=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){const s=new Vt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get token(){return this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){const s=new Jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}audit(e,t){return i(this,void 0,void 0,(function*(){const s=new Yt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getFileUrl(e){var t;const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}downloadFile(e,t){return i(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new As(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}time(e){return i(this,void 0,void 0,(function*(){const t=new _s;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Is.decoder=new TextDecoder,Is.OPERATIONS=re,Is.CATEGORIES=h,Is.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Is.LinearRetryPolicy=Le.LinearRetryPolicy;class Rs{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Us extends Is{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web",PubNubFile:a}),i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})})),o=new B(new Rs((e=>x(n.decode(e))),c));let u;(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()}));let l=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(l=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:l}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:l}),cryptography:new C,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Us.CryptoModule=P,Us})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index 31a3ef3ac..b033cf48e 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -106,11 +106,27 @@ * Service worker provides support for PubNub subscription feature to give better user experience across * multiple opened pages. */ + /** + * How often PING request should be sent to the PubNub clients. + */ + const clientPingRequestInterval = 5000; // region State /** * Service `ArrayBuffer` response decoder. */ const decoder = new TextDecoder(); + /** + * Whether `Subscription` worker should print debug information to the console or not. + */ + let logVerbosity = false; + /** + * PubNub clients active ping interval. + */ + let pingInterval; + /** + * Unique shared worker instance identifier. + */ + const sharedWorkerIdentifier = uuidGenerator.createUUID(); /** * Map of identifiers, scheduled by the Service Worker, to their abort controllers. * @@ -132,11 +148,11 @@ */ const presenceState = {}; /** - * Per-subscription key map of client identifiers to the Service Worker {@link Client} identifier. + * Per-subscription key map of client identifiers to the Shared Worker {@link MessagePort}. * - * Service Worker {@link Client} represent pages at which PubNub clients registered Service Workers. + * Shared Worker {@link MessagePort} represent specific PubNub client which connected to the Shared Worker. */ - const serviceWorkerClients = {}; + const sharedWorkerClients = {}; /** * List of ongoing subscription requests. * @@ -149,33 +165,45 @@ // -------------------------------------------------------- // region Event Handlers /** - * Listen for Service Worker activation. - */ - self.addEventListener('activate', (event) => { - event.waitUntil(self.clients.claim()); - }); - /** - * Listen for events from the client. + * Handle new PubNub client 'connection'. + * + * Echo listeners to let `SharedWorker` users that it is ready. + * + * @param event - Remote `SharedWorker` client connection event. */ - self.addEventListener('message', (event) => { - // Ignoring requests sent from other service workers. - if (!validateEventPayload(event)) - return; - const data = event.data; - if (data.type === 'send-request') { - if (data.request.path.startsWith('/v2/subscribe')) { - registerClientIfRequired(event); - handleSendSubscribeRequestEvent(data); - } - else { - if (!pubNubClients[data.clientIdentifier]) - registerClientIfRequired(event); - handleSendLeaveRequestEvent(event); - } - } - else if (data.type === 'cancel-request') - handleCancelRequestEvent(data); - }); + self.onconnect = (event) => { + consoleLog('New PubNub Client connected to the Subscription Shared Worker.'); + event.ports.forEach((receiver) => { + receiver.start(); + receiver.onmessage = (event) => { + // Ignoring unknown event payloads. + if (!validateEventPayload(event)) + return; + const data = event.data; + if (data.type === 'client-register') { + if (!logVerbosity && data.workerLogVerbosity) + logVerbosity = true; + // Appending information about messaging port for responses. + data.port = receiver; + registerClientIfRequired(data); + consoleLog(`Client '${data.clientIdentifier}' registered with '${sharedWorkerIdentifier}' shared worker`); + } + else if (data.type === 'client-pong') + handleClientPong(data); + else if (data.type === 'send-request') { + if (data.request.path.startsWith('/v2/subscribe')) { + updateClientStateIfRequired(data); + handleSendSubscribeRequestEvent(data); + } + else + handleSendLeaveRequestEvent(data); + } + else if (data.type === 'cancel-request') + handleCancelRequestEvent(data); + }; + receiver.postMessage({ type: 'shared-worker-connected' }); + }); + }; /** * Handle client request to send subscription request. * @@ -187,7 +215,7 @@ if (client) notifyRequestProcessing('start', [client], new Date().toISOString()); if (typeof requestOrId === 'string') { - if (client) { + if (client && client.subscription) { // Updating client timetoken information. client.subscription.previousTimetoken = client.subscription.timetoken; client.subscription.timetoken = serviceRequests[requestOrId].timetoken; @@ -208,14 +236,14 @@ // Clean up scheduled request and client references to it. markRequestCompleted(clients, requestOrId.identifier); }); + consoleLog(`'${Object.keys(serviceRequests).length}' subscription request currently active.`); }; /** * Handle client request to leave request. * - * @param event - Leave event details. + * @param data - Leave event details. */ - const handleSendLeaveRequestEvent = (event) => { - const data = event.data; + const handleSendLeaveRequestEvent = (data) => { const request = leaveTransportRequestFromEvent(data); const client = pubNubClients[data.clientIdentifier]; if (!client) @@ -228,10 +256,7 @@ result.url = `${data.request.origin}${data.request.path}`; result.clientIdentifier = data.clientIdentifier; result.identifier = data.request.identifier; - publishClientEvent(event.source.id, result).then((sent) => { - if (sent) - invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); - }); + publishClientEvent(client, result); return; } sendRequest(request, () => [client], (clients, response) => { @@ -241,6 +266,7 @@ // Notify each PubNub client which awaited for response. notifyRequestProcessingResult(clients, null, data.request, requestProcessingError(error)); }); + consoleLog(`Started leave request.`, client); }; /** * Handle cancel request event. @@ -251,7 +277,9 @@ */ const handleCancelRequestEvent = (event) => { const client = pubNubClients[event.clientIdentifier]; - const serviceRequestId = client ? client.subscription.serviceRequestId : undefined; + if (!client || !client.subscription) + return; + const serviceRequestId = client.subscription.serviceRequestId; if (!client || !serviceRequestId) return; // Unset awaited requests. @@ -335,7 +363,7 @@ * @returns List of PubNub client state objects for Service Worker. */ const clientsForRequest = (identifier) => { - return Object.values(pubNubClients).filter((client) => client !== undefined && client.subscription.serviceRequestId === identifier); + return Object.values(pubNubClients).filter((client) => client !== undefined && client.subscription !== undefined && client.subscription.serviceRequestId === identifier); }; /** * Clean up PubNub client states from ongoing request. @@ -348,8 +376,10 @@ const markRequestCompleted = (clients, requestId) => { delete serviceRequests[requestId]; clients.forEach((client) => { - delete client.subscription.request; - delete client.subscription.serviceRequestId; + if (client.subscription) { + delete client.subscription.request; + delete client.subscription.serviceRequestId; + } }); }; /** @@ -390,7 +420,8 @@ const subscribeTransportRequestFromEvent = (event) => { var _a, _b, _c, _d; const client = pubNubClients[event.clientIdentifier]; - const clients = clientsForSendSubscribeRequestEvent(client.subscription.previousTimetoken, event); + const subscription = client.subscription; + const clients = clientsForSendSubscribeRequestEvent(subscription.previousTimetoken, event); const serviceRequestId = uuidGenerator.createUUID(); const request = Object.assign({}, event.request); if (clients.length > 1) { @@ -400,10 +431,10 @@ return activeRequestId; const state = ((_a = presenceState[client.subscriptionKey]) !== null && _a !== void 0 ? _a : {})[client.userId]; const aggregatedState = {}; - const channelGroups = new Set(client.subscription.channelGroups); - const channels = new Set(client.subscription.channels); - if (state && client.subscription.objectsWithState.length) { - client.subscription.objectsWithState.forEach((name) => { + const channelGroups = new Set(subscription.channelGroups); + const channels = new Set(subscription.channels); + if (state && subscription.objectsWithState.length) { + subscription.objectsWithState.forEach((name) => { const objectState = state[name]; if (objectState) aggregatedState[name] = objectState; @@ -412,7 +443,7 @@ for (const client of clients) { const { subscription } = client; // Skip clients which already have active subscription request. - if (subscription.serviceRequestId) + if (!subscription || !subscription.serviceRequestId) continue; subscription.channelGroups.forEach(channelGroups.add, channelGroups); subscription.channels.forEach(channels.add, channels); @@ -452,12 +483,21 @@ serviceRequests[serviceRequestId] = { requestId: serviceRequestId, timetoken: (_d = request.queryParameters.tt) !== null && _d !== void 0 ? _d : '0', - channelGroups: client.subscription.channelGroups, - channels: client.subscription.channels, + channelGroups: subscription.channelGroups, + channels: subscription.channels, }; } - client.subscription.serviceRequestId = serviceRequestId; + subscription.serviceRequestId = serviceRequestId; request.identifier = serviceRequestId; + if (logVerbosity) { + const clientIds = clients + .reduce((identifiers, { clientIdentifier }) => { + identifiers.push(clientIdentifier); + return identifiers; + }, []) + .join(','); + consoleDir(serviceRequests[serviceRequestId], `Started aggregated request for clients: ${clientIds}`); + } return request; }; /** @@ -476,7 +516,7 @@ let channelGroups = channelGroupsFromRequest(event.request); let channels = channelsFromRequest(event.request); const request = Object.assign({}, event.request); - if (client) { + if (client && client.subscription) { const { subscription } = client; if (channels.length) subscription.channels = subscription.channels.filter((channel) => !channels.includes(channel)); @@ -486,15 +526,28 @@ } // Filter out channels and groups which is still in use by the other PubNub client instances. for (const client of clients) { + const subscription = client.subscription; + if (subscription === undefined) + continue; if (client.clientIdentifier === event.clientIdentifier) continue; if (channels.length) - channels = channels.filter((channel) => !client.subscription.channels.includes(channel)); + channels = channels.filter((channel) => !subscription.channels.includes(channel)); if (channelGroups.length) - channelGroups = channelGroups.filter((group) => !client.subscription.channelGroups.includes(group)); + channelGroups = channelGroups.filter((group) => !subscription.channelGroups.includes(group)); } - if (channels.length === 0 && channelGroups.length === 0) + if (channels.length === 0 && channelGroups.length === 0) { + if (logVerbosity && client) { + const clientIds = clients + .reduce((identifiers, { clientIdentifier }) => { + identifiers.push(clientIdentifier); + return identifiers; + }, []) + .join(','); + consoleLog(`Specified channels and groups still in use by other clients: ${clientIds}. Ignoring leave request.`, client); + } return undefined; + } // Update request channels list (if required). if (channels.length) { const pathComponents = request.path.split('/'); @@ -507,18 +560,22 @@ return request; }; /** - * Send event to all service worker clients. + * Send event to the specific PubNub client. * - * @param identifier - Service Worker receiving {@link Client} identifier. - * @param event - Service worker event object. + * @param client - State for the client which should receive {@link event}. + * @param event - Subscription worker event object. */ - const publishClientEvent = (identifier, event) => { - return self.clients.get(identifier).then((client) => { - if (!client) - return false; - client.postMessage(event); + const publishClientEvent = (client, event) => { + var _a; + const receiver = ((_a = sharedWorkerClients[client.subscriptionKey]) !== null && _a !== void 0 ? _a : {})[client.clientIdentifier]; + if (!receiver) + return false; + try { + receiver.postMessage(event); return true; - }); + } + catch (error) { } + return false; }; /** * Send request processing update. @@ -535,7 +592,7 @@ var _a; if (clients.length === 0) return; - const clientIds = (_a = serviceWorkerClients[clients[0].subscriptionKey]) !== null && _a !== void 0 ? _a : {}; + const clientIds = (_a = sharedWorkerClients[clients[0].subscriptionKey]) !== null && _a !== void 0 ? _a : {}; let event; if (type === 'start') { event = { @@ -564,17 +621,17 @@ duration: duration, }; } - clients.forEach((client) => { + for (const client of clients) { + if (client.subscription === undefined) + continue; const serviceWorkerClientId = clientIds[client.clientIdentifier]; const { request: clientRequest } = client.subscription; const decidedRequest = clientRequest !== null && clientRequest !== void 0 ? clientRequest : request; if (client.logVerbosity && serviceWorkerClientId && decidedRequest) { - publishClientEvent(serviceWorkerClientId, Object.assign(Object.assign({}, event), { clientIdentifier: client.clientIdentifier, url: `${decidedRequest.origin}${decidedRequest.path}`, query: decidedRequest.queryParameters })).then((sent) => { - if (sent) - invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); - }); + const payload = Object.assign(Object.assign({}, event), { clientIdentifier: client.clientIdentifier, url: `${decidedRequest.origin}${decidedRequest.path}`, query: decidedRequest.queryParameters }); + publishClientEvent(client, payload); } - }); + } }; /** * Send request processing result event. @@ -590,7 +647,7 @@ return; if (!result && !response) return; - const clientIds = (_a = serviceWorkerClients[clients[0].subscriptionKey]) !== null && _a !== void 0 ? _a : {}; + const clientIds = (_a = sharedWorkerClients[clients[0].subscriptionKey]) !== null && _a !== void 0 ? _a : {}; if (!result && response) { result = response[0].status >= 400 @@ -598,17 +655,17 @@ requestProcessingError(undefined, response) : requestProcessingSuccess(response); } - clients.forEach((client) => { + for (const client of clients) { + if (client.subscription === undefined) + continue; const serviceWorkerClientId = clientIds[client.clientIdentifier]; const { request: clientRequest } = client.subscription; const decidedRequest = clientRequest !== null && clientRequest !== void 0 ? clientRequest : request; if (serviceWorkerClientId && decidedRequest) { - publishClientEvent(serviceWorkerClientId, Object.assign(Object.assign({}, result), { clientIdentifier: client.clientIdentifier, identifier: decidedRequest.identifier, url: `${decidedRequest.origin}${decidedRequest.path}` })).then((sent) => { - if (sent) - invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); - }); + const payload = Object.assign(Object.assign({}, result), { clientIdentifier: client.clientIdentifier, identifier: decidedRequest.identifier, url: `${decidedRequest.origin}${decidedRequest.path}` }); + publishClientEvent(client, payload); } - }); + } }; /** * Create processing success event from service response. @@ -696,82 +753,111 @@ * @param event - Base information about PubNub client instance and Service Worker {@link Client}. */ const registerClientIfRequired = (event) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u; - var _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5; - const information = event.data; - const { clientIdentifier } = information; - const query = information.request.queryParameters; - let client = pubNubClients[clientIdentifier]; - if (!client) { - const isPresenceLeave = !information.request.path.startsWith('/v2/subscribe'); - const channelGroupQuery = !isPresenceLeave ? ((_a = query['channel-group']) !== null && _a !== void 0 ? _a : '') : ''; - const state = !isPresenceLeave ? ((_b = query.state) !== null && _b !== void 0 ? _b : '') : ''; - client = pubNubClients[clientIdentifier] = { - clientIdentifier, - subscriptionKey: information.subscriptionKey, - userId: query.uuid, - authKey: ((_c = query.auth) !== null && _c !== void 0 ? _c : ''), - logVerbosity: information.logVerbosity, - subscription: { - path: !isPresenceLeave ? information.request.path : '', - channelGroupQuery: !isPresenceLeave ? channelGroupQuery : '', - channels: !isPresenceLeave ? channelsFromRequest(information.request) : [], - channelGroups: !isPresenceLeave ? channelGroupsFromRequest(information.request) : [], - previousTimetoken: !isPresenceLeave ? ((_d = query.tt) !== null && _d !== void 0 ? _d : '0') : '0', - timetoken: !isPresenceLeave ? ((_e = query.tt) !== null && _e !== void 0 ? _e : '0') : '0', - request: !isPresenceLeave ? information.request : undefined, - objectsWithState: [], - filterExpression: !isPresenceLeave ? ((_f = query['filter-expr']) !== null && _f !== void 0 ? _f : '') : undefined, - }, + var _a, _b; + var _c, _d; + const { clientIdentifier } = event; + if (pubNubClients[clientIdentifier]) + return; + const client = (pubNubClients[clientIdentifier] = { + clientIdentifier, + subscriptionKey: event.subscriptionKey, + userId: event.userId, + logVerbosity: event.logVerbosity, + }); + // Map registered PubNub client to its subscription key. + const clientsBySubscriptionKey = ((_a = pubNubClientsBySubscriptionKey[_c = event.subscriptionKey]) !== null && _a !== void 0 ? _a : (pubNubClientsBySubscriptionKey[_c] = [])); + if (clientsBySubscriptionKey.every((entry) => entry.clientIdentifier !== clientIdentifier)) + clientsBySubscriptionKey.push(client); + // Binding PubNub client to the MessagePort (receiver). + ((_b = sharedWorkerClients[_d = event.subscriptionKey]) !== null && _b !== void 0 ? _b : (sharedWorkerClients[_d] = {}))[clientIdentifier] = event.port; + consoleLog(`Registered PubNub client with '${clientIdentifier}' identifier. ` + + `'${Object.keys(pubNubClients).length}' clients currently active.`); + if (!pingInterval && Object.keys(pubNubClients).length > 0) { + consoleLog(`Setup PubNub client ping event ${clientPingRequestInterval / 1000} seconds`); + pingInterval = setInterval(() => pingClients(), clientPingRequestInterval); + } + }; + /** + * Update information about previously registered client. + * + * Use information from request to populate list of channels and other useful information. + * + * @param event - Send request. + */ + const updateClientStateIfRequired = (event) => { + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; + var _m, _o, _p, _q, _r, _s, _t, _u, _v; + const query = event.request.queryParameters; + const { clientIdentifier } = event; + const client = pubNubClients[clientIdentifier]; + // This should never happen. + if (!client) + return; + const channelGroupQuery = ((_a = query['channel-group']) !== null && _a !== void 0 ? _a : ''); + const state = ((_b = query.state) !== null && _b !== void 0 ? _b : ''); + let subscription = client.subscription; + if (!subscription) { + subscription = { + path: '', + channelGroupQuery: '', + channels: [], + channelGroups: [], + previousTimetoken: '0', + timetoken: '0', + objectsWithState: [], }; - if (!isPresenceLeave && state.length > 0) { + if (state.length > 0) { const parsedState = JSON.parse(state); - const userState = ((_h = (_w = ((_g = presenceState[_v = client.subscriptionKey]) !== null && _g !== void 0 ? _g : (presenceState[_v] = {})))[_x = client.userId]) !== null && _h !== void 0 ? _h : (_w[_x] = {})); + const userState = ((_d = (_o = ((_c = presenceState[_m = client.subscriptionKey]) !== null && _c !== void 0 ? _c : (presenceState[_m] = {})))[_p = client.userId]) !== null && _d !== void 0 ? _d : (_o[_p] = {})); Object.entries(parsedState).forEach(([objectName, value]) => (userState[objectName] = value)); - client.subscription.objectsWithState = Object.keys(parsedState); + subscription.objectsWithState = Object.keys(parsedState); } - // Map registered PubNub client to its subscription key. - const clientsBySubscriptionKey = ((_j = pubNubClientsBySubscriptionKey[_y = information.subscriptionKey]) !== null && _j !== void 0 ? _j : (pubNubClientsBySubscriptionKey[_y] = [])); - if (clientsBySubscriptionKey.every((entry) => entry.clientIdentifier !== clientIdentifier)) - clientsBySubscriptionKey.push(client); - // Binding PubNub client to the page (Service Worker Client). - ((_k = serviceWorkerClients[_z = information.subscriptionKey]) !== null && _k !== void 0 ? _k : (serviceWorkerClients[_z] = {}))[clientIdentifier] = event.source.id; + client.subscription = subscription; } else { - const channelGroupQuery = ((_l = query['channel-group']) !== null && _l !== void 0 ? _l : ''); - const state = ((_m = query.state) !== null && _m !== void 0 ? _m : ''); - client.subscription.filterExpression = ((_o = query['filter-expr']) !== null && _o !== void 0 ? _o : ''); - client.subscription.previousTimetoken = client.subscription.timetoken; - client.subscription.timetoken = ((_p = query.tt) !== null && _p !== void 0 ? _p : '0'); - client.subscription.request = information.request; - client.authKey = ((_q = query.auth) !== null && _q !== void 0 ? _q : ''); - client.userId = query.uuid; - if (client.subscription.path !== information.request.path) { - client.subscription.path = information.request.path; - client.subscription.channels = channelsFromRequest(information.request); - } - if (client.subscription.channelGroupQuery !== channelGroupQuery) { - client.subscription.channelGroupQuery = channelGroupQuery; - client.subscription.channelGroups = channelGroupsFromRequest(information.request); - } + subscription.previousTimetoken = subscription.timetoken; if (state.length > 0) { const parsedState = JSON.parse(state); - const userState = ((_s = (_1 = ((_r = presenceState[_0 = client.subscriptionKey]) !== null && _r !== void 0 ? _r : (presenceState[_0] = {})))[_2 = client.userId]) !== null && _s !== void 0 ? _s : (_1[_2] = {})); + const userState = ((_f = (_r = ((_e = presenceState[_q = client.subscriptionKey]) !== null && _e !== void 0 ? _e : (presenceState[_q] = {})))[_s = client.userId]) !== null && _f !== void 0 ? _f : (_r[_s] = {})); Object.entries(parsedState).forEach(([objectName, value]) => (userState[objectName] = value)); // Clean up state for objects where presence state has been reset. - for (const objectName of client.subscription.objectsWithState) + for (const objectName of subscription.objectsWithState) if (!parsedState[objectName]) delete userState[objectName]; - client.subscription.objectsWithState = Object.keys(parsedState); + subscription.objectsWithState = Object.keys(parsedState); } // Handle potential presence state reset. - else if (client.subscription.objectsWithState.length) { - const userState = ((_u = (_4 = ((_t = presenceState[_3 = client.subscriptionKey]) !== null && _t !== void 0 ? _t : (presenceState[_3] = {})))[_5 = client.userId]) !== null && _u !== void 0 ? _u : (_4[_5] = {})); - for (const objectName of client.subscription.objectsWithState) + else if (subscription.objectsWithState.length) { + const userState = ((_h = (_u = ((_g = presenceState[_t = client.subscriptionKey]) !== null && _g !== void 0 ? _g : (presenceState[_t] = {})))[_v = client.userId]) !== null && _h !== void 0 ? _h : (_u[_v] = {})); + for (const objectName of subscription.objectsWithState) delete userState[objectName]; - client.subscription.objectsWithState = []; + subscription.objectsWithState = []; } } + if (subscription.path !== event.request.path) { + subscription.path = event.request.path; + subscription.channels = channelsFromRequest(event.request); + } + if (subscription.channelGroupQuery !== channelGroupQuery) { + subscription.channelGroupQuery = channelGroupQuery; + subscription.channelGroups = channelGroupsFromRequest(event.request); + } + subscription.request = event.request; + subscription.filterExpression = ((_j = query['filter-expr']) !== null && _j !== void 0 ? _j : ''); + subscription.timetoken = ((_k = query.tt) !== null && _k !== void 0 ? _k : '0'); + client.authKey = ((_l = query.auth) !== null && _l !== void 0 ? _l : ''); + client.userId = query.uuid; + }; + /** + * Handle PubNub client response on PING request. + * + * @param event - Information about client which responded on PING request. + */ + const handleClientPong = (event) => { + const client = pubNubClients[event.clientIdentifier]; + if (!client) + return; + client.lastPongEvent = new Date().getTime() / 1000; }; /** * Clean up resources used by registered PubNub client instance. @@ -779,9 +865,8 @@ * @param subscriptionKey - Subscription key which has been used by the * invalidated instance. * @param clientId - Unique PubNub client identifier. - * @param userId - Unique identifier of the user used by PubNub client instance. */ - const invalidateClient = (subscriptionKey, clientId, userId) => { + const invalidateClient = (subscriptionKey, clientId) => { delete pubNubClients[clientId]; let clients = pubNubClientsBySubscriptionKey[subscriptionKey]; if (clients) { @@ -796,25 +881,23 @@ delete presenceState[subscriptionKey]; // Clean up service workers client linkage to PubNub clients. if (clients.length > 0) { - const workerClients = serviceWorkerClients[subscriptionKey]; + const workerClients = sharedWorkerClients[subscriptionKey]; if (workerClients) { delete workerClients[clientId]; if (Object.keys(workerClients).length === 0) - delete serviceWorkerClients[subscriptionKey]; + delete sharedWorkerClients[subscriptionKey]; } } else - delete serviceWorkerClients[subscriptionKey]; + delete sharedWorkerClients[subscriptionKey]; } + consoleLog(`Invalidate '${clientId}' client. '${Object.keys(pubNubClients).length}' clients currently active.`); }; /** * Validate received event payload. */ const validateEventPayload = (event) => { - if (!event.source || !(event.source instanceof Client)) - return false; - const data = event.data; - const { clientIdentifier, subscriptionKey, logVerbosity } = data; + const { clientIdentifier, subscriptionKey, logVerbosity } = event.data; if (logVerbosity === undefined || typeof logVerbosity !== 'boolean') return false; if (!clientIdentifier || typeof clientIdentifier !== 'string') @@ -822,7 +905,7 @@ return !(!subscriptionKey || typeof subscriptionKey !== 'string'); }; /** - * Search for active subscription for one of the passed {@link serviceWorkerClients}. + * Search for active subscription for one of the passed {@link sharedWorkerClients}. * * @param activeClients - List of suitable registered PubNub clients. * @param event - Send Subscriber Request event data. @@ -840,9 +923,13 @@ for (const client of activeClients) { const { subscription } = client; // Skip PubNub clients which doesn't await for subscription response. - if (!subscription.serviceRequestId) + if (!subscription || !subscription.serviceRequestId) continue; + const sourceClient = pubNubClients[event.clientIdentifier]; + const requestId = subscription.serviceRequestId; if (subscription.path === requestPath && subscription.channelGroupQuery === channelGroupQuery) { + consoleLog(`Found identical request started by '${client.clientIdentifier}' client. +Waiting for existing '${requestId}' request completion.`, sourceClient); return subscription.serviceRequestId; } else { @@ -856,6 +943,8 @@ continue; if (channelGroups.length && !includesStrings(scheduledRequest.channelGroups, channelGroups)) continue; + consoleDir(scheduledRequest, `'${event.request.identifier}' request channels and groups are subset of ongoing '${requestId}' request +which has started by '${client.clientIdentifier}' client. Waiting for existing '${requestId}' request completion.`, sourceClient); return subscription.serviceRequestId; } } @@ -885,6 +974,7 @@ const userId = query.uuid; return ((_c = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _c !== void 0 ? _c : []).filter((client) => client.userId === userId && client.authKey === authKey && + client.subscription && client.subscription.filterExpression === filterExpression && (timetoken === '0' || client.subscription.previousTimetoken === '0' || @@ -944,6 +1034,74 @@ const set = new Set(main); return sub.every(set.has, set); }; + /** + * Send PubNub client PING request to identify disconnected instances. + */ + const pingClients = () => { + consoleLog(`Pinging clients...`); + const payload = { type: 'shared-worker-ping' }; + Object.values(pubNubClients).forEach((client) => { + let clientInvalidated = false; + if (client && client.lastPingRequest) { + consoleLog(`Checking whether ${client.clientIdentifier} ping has been sent too long ago...`); + // Check whether client never respond or last response was too long time ago. + if (!client.lastPongEvent || + Math.abs(client.lastPongEvent - client.lastPingRequest) > (clientPingRequestInterval / 1000) * 0.5) { + clientInvalidated = true; + consoleLog(`'${client.clientIdentifier}' client is inactive. Invalidating.`); + invalidateClient(client.subscriptionKey, client.clientIdentifier); + } + } + if (client && !clientInvalidated) { + consoleLog(`Sending ping to ${client.clientIdentifier}...`); + client.lastPingRequest = new Date().getTime() / 1000; + publishClientEvent(client, payload); + } + }); + // Cancel interval if there is no active clients. + if (Object.keys(pubNubClients).length === 0 && pingInterval) + clearInterval(pingInterval); + }; + /** + * Print message on the worker's clients console. + * + * @param message - Message which should be printed. + * @param [client] - Target client to which log message should be sent. + */ + const consoleLog = (message, client) => { + if (!logVerbosity) + return; + const clients = client ? [client] : Object.values(pubNubClients); + const payload = { + type: 'shared-worker-console-log', + message, + }; + clients.forEach((client) => { + if (client) + publishClientEvent(client, payload); + }); + }; + /** + * Print message on the worker's clients console. + * + * @param data - Data which should be printed into the console. + * @param [message] - Message which should be printed before {@link data}. + * @param [client] - Target client to which log message should be sent. + */ + const consoleDir = (data, message, client) => { + if (!logVerbosity) + return; + const clients = client ? [client] : Object.values(pubNubClients); + const payload = { + type: 'shared-worker-console-dir', + message, + data, + }; + clients.forEach((client) => { + if (client) + publishClientEvent(client, payload); + }); + }; /** * Stringify request query key / value pairs. * diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index 864385802..17cca5554 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ -!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,i){return new(n||(n=Promise))((function(s,r){function o(e){try{c(i.next(e))}catch(e){r(e)}}function u(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?s(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,u)}c((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,i,s={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function i(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function s(e,t){var i=n[t||"all"];return i&&i.test(e)||!1}i.isUUID=s,i.VERSION=t,e.uuid=i,e.isUUID=s}(i=s.exports),null!==n&&(n.exports=i.uuid);var r=t(s.exports),o={createUUID:()=>r.uuid?r.uuid():r()};const u=new TextDecoder,c=new Map,l={},a={},d={},p={},f={};self.addEventListener("activate",(e=>{e.waitUntil(self.clients.claim())})),self.addEventListener("message",(e=>{if(!K(e))return;const t=e.data;"send-request"===t.type?t.request.path.startsWith("/v2/subscribe")?(k(e),h(t)):(l[t.clientIdentifier]||k(e),b(e)):"cancel-request"===t.type&&v(t)}));const h=e=>{const t=j(e),n=l[e.clientIdentifier];n&&w("start",[n],(new Date).toISOString()),"string"!=typeof t?(e.request.cancellable&&c.set(t.identifier,new AbortController),g(t,(()=>q(t.identifier)),((e,n)=>{E(e,n),I(e,t.identifier)}),((e,n)=>{E(e,null,t,T(n)),I(e,t.identifier)}))):n&&(n.subscription.previousTimetoken=n.subscription.timetoken,n.subscription.timetoken=f[t].timetoken,n.subscription.serviceRequestId=t)},b=e=>{const t=e.data,n=O(t),i=l[t.clientIdentifier];if(i){if(!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),s=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":"74"}),r=new Response(n,{status:200,headers:s}),o=S([r,n]);return o.url=`${t.request.origin}${t.request.path}`,o.clientIdentifier=t.clientIdentifier,o.identifier=t.request.identifier,void A(e.source.id,o).then((e=>{e&&x(i.subscriptionKey,i.clientIdentifier,i.userId)}))}g(n,(()=>[i]),((e,n)=>{E(e,n,t.request)}),((e,n)=>{E(e,null,t.request,T(n))}))}},v=e=>{const t=l[e.clientIdentifier],n=t?t.subscription.serviceRequestId:void 0;if(t&&n&&(delete t.subscription.serviceRequestId,delete t.subscription.request,0===q(n).length)){const e=c.get(n);c.delete(n),delete f[n],e&&e.abort()}},g=(t,n,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const r=(new Date).getTime();Promise.race([fetch(m(t),{signal:null===(e=c.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),y(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,o=n();0!==o.length&&(w("end",o,(new Date).toISOString(),t,s,e[0].headers.get("Content-Type"),(new Date).getTime()-r),i(o,e))})).catch((e=>{const t=n();0!==t.length&&s(t,e)}))}))},y=(e,t)=>new Promise(((n,i)=>{const s=setTimeout((()=>{c.delete(e),clearTimeout(s),i(new Error("Request timeout"))}),1e3*t)})),q=e=>Object.values(l).filter((t=>void 0!==t&&t.subscription.serviceRequestId===e)),I=(e,t)=>{delete f[t],e.forEach((e=>{delete e.subscription.request,delete e.subscription.serviceRequestId}))},m=e=>{let t;const n=e.queryParameters;let i=e.path;if(e.headers){t={};for(const[n,i]of Object.entries(e.headers))t[n]=i}return n&&0!==Object.keys(n).length&&(i=`${i}?${W(n)}`),new Request(`${e.origin}${i}`,{method:e.method,headers:t,redirect:"follow"})},j=e=>{var t,n,i,s;const r=l[e.clientIdentifier],u=R(r.subscription.previousTimetoken,e),c=o.createUUID(),a=Object.assign({},e.request);if(u.length>1){const s=F(u,e);if(s)return s;const o=(null!==(t=d[r.subscriptionKey])&&void 0!==t?t:{})[r.userId],l={},p=new Set(r.subscription.channelGroups),h=new Set(r.subscription.channels);o&&r.subscription.objectsWithState.length&&r.subscription.objectsWithState.forEach((e=>{const t=o[e];t&&(l[e]=t)}));for(const e of u){const{subscription:t}=e;t.serviceRequestId||(t.channelGroups.forEach(p.add,p),t.channels.forEach(h.add,h),t.serviceRequestId=c,o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!l[e]&&(l[e]=t)})))}const b=null!==(n=f[c])&&void 0!==n?n:f[c]={requestId:c,timetoken:null!==(i=a.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(h.size){b.channels=Array.from(h).sort();const e=a.path.split("/");e[4]=b.channels.join(","),a.path=e.join("/")}p.size&&(b.channelGroups=Array.from(p).sort(),a.queryParameters["channel-group"]=b.channelGroups.join(",")),Object.keys(l).length&&(a.queryParameters.state=JSON.stringify(l))}else f[c]={requestId:c,timetoken:null!==(s=a.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:r.subscription.channelGroups,channels:r.subscription.channels};return r.subscription.serviceRequestId=c,a.identifier=c,a},O=e=>{const t=l[e.clientIdentifier],n=$(e);let i=P(e.request),s=G(e.request);const r=Object.assign({},e.request);if(t){const{subscription:e}=t;s.length&&(e.channels=e.channels.filter((e=>!s.includes(e)))),i.length&&(e.channelGroups=e.channelGroups.filter((e=>!i.includes(e))))}for(const t of n)t.clientIdentifier!==e.clientIdentifier&&(s.length&&(s=s.filter((e=>!t.subscription.channels.includes(e)))),i.length&&(i=i.filter((e=>!t.subscription.channelGroups.includes(e)))));if(0!==s.length||0!==i.length){if(s.length){const e=r.path.split("/");e[4]=s.join(","),r.path=e.join("/")}return i.length&&(r.queryParameters["channel-group"]=i.join(",")),r}},A=(e,t)=>self.clients.get(e).then((e=>!!e&&(e.postMessage(t),!0))),w=(e,t,n,i,s,r,o)=>{var c;if(0===t.length)return;const l=null!==(c=p[t[0].subscriptionKey])&&void 0!==c?c:{};let a;if("start"===e)a={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;s&&r&&(-1!==r.indexOf("text/javascript")||-1!==r.indexOf("application/json")||-1!==r.indexOf("text/plain")||-1!==r.indexOf("text/html"))&&(e=u.decode(s)),a={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}t.forEach((e=>{const t=l[e.clientIdentifier],{request:n}=e.subscription,s=null!=n?n:i;e.logVerbosity&&t&&s&&A(t,Object.assign(Object.assign({},a),{clientIdentifier:e.clientIdentifier,url:`${s.origin}${s.path}`,query:s.queryParameters})).then((t=>{t&&x(e.subscriptionKey,e.clientIdentifier,e.userId)}))}))},E=(e,t,n,i)=>{var s;if(0===e.length)return;if(!i&&!t)return;const r=null!==(s=p[e[0].subscriptionKey])&&void 0!==s?s:{};!i&&t&&(i=t[0].status>=400?T(void 0,t):S(t)),e.forEach((e=>{const t=r[e.clientIdentifier],{request:s}=e.subscription,o=null!=s?s:n;t&&o&&A(t,Object.assign(Object.assign({},i),{clientIdentifier:e.clientIdentifier,identifier:o.identifier,url:`${o.origin}${o.path}`})).then((t=>{t&&x(e.subscriptionKey,e.clientIdentifier,e.userId)}))}))},S=e=>{var t;const[n,i]=e,s=i.byteLength>0?i:void 0,r=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),u={};return n.headers.forEach(((e,t)=>u[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:r,contentType:o,headers:u,status:n.status,body:s}}},T=(e,t)=>{if(t)return Object.assign(Object.assign({},S(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",i="Unknown error",s="Error";return e&&e instanceof Error&&(i=e.message,s=e.name),"AbortError"===s?(i="Request aborted",n="ABORTED"):"Request timeout"===i&&(n="TIMEOUT"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:s,type:n,message:i}}},k=e=>{var t,n,i,s,r,o,u,c,f,h,b,v,g,y,q,I,m,j,O,A,w,E,S,T,k,x,K,F,R,$;const U=e.data,{clientIdentifier:W}=U,C=U.request.queryParameters;let D=l[W];if(D){const e=null!==(b=C["channel-group"])&&void 0!==b?b:"",t=null!==(v=C.state)&&void 0!==v?v:"";if(D.subscription.filterExpression=null!==(g=C["filter-expr"])&&void 0!==g?g:"",D.subscription.previousTimetoken=D.subscription.timetoken,D.subscription.timetoken=null!==(y=C.tt)&&void 0!==y?y:"0",D.subscription.request=U.request,D.authKey=null!==(q=C.auth)&&void 0!==q?q:"",D.userId=C.uuid,D.subscription.path!==U.request.path&&(D.subscription.path=U.request.path,D.subscription.channels=G(U.request)),D.subscription.channelGroupQuery!==e&&(D.subscription.channelGroupQuery=e,D.subscription.channelGroups=P(U.request)),t.length>0){const e=JSON.parse(t),n=null!==(m=(x=null!==(I=d[k=D.subscriptionKey])&&void 0!==I?I:d[k]={})[K=D.userId])&&void 0!==m?m:x[K]={};Object.entries(e).forEach((([e,t])=>n[e]=t));for(const t of D.subscription.objectsWithState)e[t]||delete n[t];D.subscription.objectsWithState=Object.keys(e)}else if(D.subscription.objectsWithState.length){const e=null!==(O=(R=null!==(j=d[F=D.subscriptionKey])&&void 0!==j?j:d[F]={})[$=D.userId])&&void 0!==O?O:R[$]={};for(const t of D.subscription.objectsWithState)delete e[t];D.subscription.objectsWithState=[]}}else{const b=!U.request.path.startsWith("/v2/subscribe"),v=b?"":null!==(t=C["channel-group"])&&void 0!==t?t:"",g=b?"":null!==(n=C.state)&&void 0!==n?n:"";if(D=l[W]={clientIdentifier:W,subscriptionKey:U.subscriptionKey,userId:C.uuid,authKey:null!==(i=C.auth)&&void 0!==i?i:"",logVerbosity:U.logVerbosity,subscription:{path:b?"":U.request.path,channelGroupQuery:b?"":v,channels:b?[]:G(U.request),channelGroups:b?[]:P(U.request),previousTimetoken:b?"0":null!==(s=C.tt)&&void 0!==s?s:"0",timetoken:b?"0":null!==(r=C.tt)&&void 0!==r?r:"0",request:b?void 0:U.request,objectsWithState:[],filterExpression:b?void 0:null!==(o=C["filter-expr"])&&void 0!==o?o:""}},!b&&g.length>0){const e=JSON.parse(g),t=null!==(c=(w=null!==(u=d[A=D.subscriptionKey])&&void 0!==u?u:d[A]={})[E=D.userId])&&void 0!==c?c:w[E]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),D.subscription.objectsWithState=Object.keys(e)}const y=null!==(f=a[S=U.subscriptionKey])&&void 0!==f?f:a[S]=[];y.every((e=>e.clientIdentifier!==W))&&y.push(D),(null!==(h=p[T=U.subscriptionKey])&&void 0!==h?h:p[T]={})[W]=e.source.id}},x=(e,t,n)=>{delete l[t];let i=a[e];if(i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?a[e]=i:delete a[e],0===i.length&&delete d[e],i.length>0){const n=p[e];n&&(delete n[t],0===Object.keys(n).length&&delete p[e])}else delete p[e]},K=e=>{if(!(e.source&&e.source instanceof Client))return!1;const t=e.data,{clientIdentifier:n,subscriptionKey:i,logVerbosity:s}=t;return void 0!==s&&"boolean"==typeof s&&(!(!n||"string"!=typeof n)&&!(!i||"string"!=typeof i))},F=(e,t)=>{var n;const i=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",s=t.request.path;let r,o;for(const n of e){const{subscription:e}=n;if(e.serviceRequestId){if(e.path===s&&e.channelGroupQuery===i)return e.serviceRequestId;{const n=f[e.serviceRequestId];if(r||(r=P(t.request)),o||(o=G(t.request)),o.length&&!U(n.channels,o))continue;if(r.length&&!U(n.channelGroups,r))continue;return e.serviceRequestId}}}},R=(e,t)=>{var n,i,s;const r=t.request.queryParameters,o=null!==(n=r["filter-expr"])&&void 0!==n?n:"",u=null!==(i=r.auth)&&void 0!==i?i:"",c=r.uuid;return(null!==(s=a[t.subscriptionKey])&&void 0!==s?s:[]).filter((t=>t.userId===c&&t.authKey===u&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.previousTimetoken||t.subscription.previousTimetoken===e)))},$=e=>{var t,n;const i=e.request.queryParameters,s=null!==(t=i.auth)&&void 0!==t?t:"",r=i.uuid;return(null!==(n=a[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===r&&e.authKey===s))},G=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},P=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},U=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},W=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${C(e)}`)).join("&"):`${t}=${C(n)}`})).join("&"),C=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{u(i.next(e))}catch(e){s(e)}}function c(e){try{u(i.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}u((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,i,r={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=r,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function i(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var i=n[t||"all"];return i&&i.test(e)||!1}i.isUUID=r,i.VERSION=t,e.uuid=i,e.isUUID=r}(i=r.exports),null!==n&&(n.exports=i.uuid);var s=t(r.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=5e3,u=new TextDecoder;let l,a=!1;const d=o.createUUID(),f=new Map,p={},h={},g={},b={},v={};self.onconnect=e=>{V("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!G(t))return;const n=t.data;"client-register"===n.type?(!a&&n.workerLogVerbosity&&(a=!0),n.port=e,x(n),V(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`)):"client-pong"===n.type?K(n):"send-request"===n.type?n.request.path.startsWith("/v2/subscribe")?(F(n),y(n)):q(n):"cancel-request"===n.type&&I(n)},e.postMessage({type:"shared-worker-connected"})}))};const y=e=>{const t=k(e),n=p[e.clientIdentifier];n&&E("start",[n],(new Date).toISOString()),"string"!=typeof t?(e.request.cancellable&&f.set(t.identifier,new AbortController),m(t,(()=>O(t.identifier)),((e,n)=>{P(e,n),w(e,t.identifier)}),((e,n)=>{P(e,null,t,T(n)),w(e,t.identifier)})),V(`'${Object.keys(v).length}' subscription request currently active.`)):n&&n.subscription&&(n.subscription.previousTimetoken=n.subscription.timetoken,n.subscription.timetoken=v[t].timetoken,n.subscription.serviceRequestId=t)},q=e=>{const t=S(e),n=p[e.clientIdentifier];if(n){if(!t){const t=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),i=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":"74"}),r=new Response(t,{status:200,headers:i}),s=R([r,t]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(n,s)}m(t,(()=>[n]),((t,n)=>{P(t,n,e.request)}),((t,n)=>{P(t,null,e.request,T(n))})),V("Started leave request.",n)}},I=e=>{const t=p[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;if(t&&n&&(delete t.subscription.serviceRequestId,delete t.subscription.request,0===O(n).length)){const e=f.get(n);f.delete(n),delete v[n],e&&e.abort()}},m=(t,n,i,r)=>{e(void 0,void 0,void 0,(function*(){var e;const s=(new Date).getTime();Promise.race([fetch($(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),j(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const r=e[1].byteLength>0?e[1]:void 0,o=n();0!==o.length&&(E("end",o,(new Date).toISOString(),t,r,e[0].headers.get("Content-Type"),(new Date).getTime()-s),i(o,e))})).catch((e=>{const t=n();0!==t.length&&r(t,e)}))}))},j=(e,t)=>new Promise(((n,i)=>{const r=setTimeout((()=>{f.delete(e),clearTimeout(r),i(new Error("Request timeout"))}),1e3*t)})),O=e=>Object.values(p).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),w=(e,t)=>{delete v[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},$=e=>{let t;const n=e.queryParameters;let i=e.path;if(e.headers){t={};for(const[n,i]of Object.entries(e.headers))t[n]=i}return n&&0!==Object.keys(n).length&&(i=`${i}?${Q(n)}`),new Request(`${e.origin}${i}`,{method:e.method,headers:t,redirect:"follow"})},k=e=>{var t,n,i,r;const s=p[e.clientIdentifier],c=s.subscription,u=W(c.previousTimetoken,e),l=o.createUUID(),d=Object.assign({},e.request);if(u.length>1){const r=U(u,e);if(r)return r;const o=(null!==(t=g[s.subscriptionKey])&&void 0!==t?t:{})[s.userId],a={},f=new Set(c.channelGroups),p=new Set(c.channels);o&&c.objectsWithState.length&&c.objectsWithState.forEach((e=>{const t=o[e];t&&(a[e]=t)}));for(const e of u){const{subscription:t}=e;t&&t.serviceRequestId&&(t.channelGroups.forEach(f.add,f),t.channels.forEach(p.add,p),t.serviceRequestId=l,o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!a[e]&&(a[e]=t)})))}const h=null!==(n=v[l])&&void 0!==n?n:v[l]={requestId:l,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(p.size){h.channels=Array.from(p).sort();const e=d.path.split("/");e[4]=h.channels.join(","),d.path=e.join("/")}f.size&&(h.channelGroups=Array.from(f).sort(),d.queryParameters["channel-group"]=h.channelGroups.join(",")),Object.keys(a).length&&(d.queryParameters.state=JSON.stringify(a))}else v[l]={requestId:l,timetoken:null!==(r=d.queryParameters.tt)&&void 0!==r?r:"0",channelGroups:c.channelGroups,channels:c.channels};if(c.serviceRequestId=l,d.identifier=l,a){const e=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");B(v[l],`Started aggregated request for clients: ${e}`)}return d},S=e=>{const t=p[e.clientIdentifier],n=C(e);let i=N(e.request),r=D(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;r.length&&(e.channels=e.channels.filter((e=>!r.includes(e)))),i.length&&(e.channelGroups=e.channelGroups.filter((e=>!i.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(r.length&&(r=r.filter((e=>!n.channels.includes(e)))),i.length&&(i=i.filter((e=>!n.channelGroups.includes(e))))))}if(0!==r.length||0!==i.length){if(r.length){const e=s.path.split("/");e[4]=r.join(","),s.path=e.join("/")}return i.length&&(s.queryParameters["channel-group"]=i.join(",")),s}if(a&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");V(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const i=(null!==(n=b[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!i)return!1;try{return i.postMessage(t),!0}catch(e){}return!1},E=(e,t,n,i,r,s,o)=>{var c;if(0===t.length)return;const l=null!==(c=b[t[0].subscriptionKey])&&void 0!==c?c:{};let a;if("start"===e)a={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;r&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(r)),a={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(void 0===e.subscription)continue;const t=l[e.clientIdentifier],{request:n}=e.subscription,r=null!=n?n:i;if(e.logVerbosity&&t&&r){const t=Object.assign(Object.assign({},a),{clientIdentifier:e.clientIdentifier,url:`${r.origin}${r.path}`,query:r.queryParameters});A(e,t)}}},P=(e,t,n,i)=>{var r;if(0===e.length)return;if(!i&&!t)return;const s=null!==(r=b[e[0].subscriptionKey])&&void 0!==r?r:{};!i&&t&&(i=t[0].status>=400?T(void 0,t):R(t));for(const t of e){if(void 0===t.subscription)continue;const e=s[t.clientIdentifier],{request:r}=t.subscription,o=null!=r?r:n;if(e&&o){const e=Object.assign(Object.assign({},i),{clientIdentifier:t.clientIdentifier,identifier:o.identifier,url:`${o.origin}${o.path}`});A(t,e)}}},R=e=>{var t;const[n,i]=e,r=i.byteLength>0?i:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:r}}},T=(e,t)=>{if(t)return Object.assign(Object.assign({},R(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",i="Unknown error",r="Error";return e&&e instanceof Error&&(i=e.message,r=e.name),"AbortError"===r?(i="Request aborted",n="ABORTED"):"Request timeout"===i&&(n="TIMEOUT"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:r,type:n,message:i}}},x=e=>{var t,n,i,r;const{clientIdentifier:s}=e;if(p[s])return;const o=p[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,logVerbosity:e.logVerbosity},u=null!==(t=h[i=e.subscriptionKey])&&void 0!==t?t:h[i]=[];u.every((e=>e.clientIdentifier!==s))&&u.push(o),(null!==(n=b[r=e.subscriptionKey])&&void 0!==n?n:b[r]={})[s]=e.port,V(`Registered PubNub client with '${s}' identifier. '${Object.keys(p).length}' clients currently active.`),!l&&Object.keys(p).length>0&&(V("Setup PubNub client ping event 5 seconds"),l=setInterval((()=>M()),c))},F=e=>{var t,n,i,r,s,o,c,u,l,a,d,f,h,b,v,y,q,I,m,j;const O=e.request.queryParameters,{clientIdentifier:w}=e,$=p[w];if(!$)return;const k=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let A=$.subscription;if(A){if(A.previousTimetoken=A.timetoken,S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=g[v=$.subscriptionKey])&&void 0!==s?s:g[v]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of A.objectsWithState)e[n]||delete t[n];A.objectsWithState=Object.keys(e)}else if(A.objectsWithState.length){const e=null!==(u=(m=null!==(c=g[I=$.subscriptionKey])&&void 0!==c?c:g[I]={})[j=$.userId])&&void 0!==u?u:m[j]={};for(const t of A.objectsWithState)delete e[t];A.objectsWithState=[]}}else{if(A={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(r=(h=null!==(i=g[f=$.subscriptionKey])&&void 0!==i?i:g[f]={})[b=$.userId])&&void 0!==r?r:h[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),A.objectsWithState=Object.keys(e)}$.subscription=A}A.path!==e.request.path&&(A.path=e.request.path,A.channels=D(e.request)),A.channelGroupQuery!==k&&(A.channelGroupQuery=k,A.channelGroups=N(e.request)),A.request=e.request,A.filterExpression=null!==(l=O["filter-expr"])&&void 0!==l?l:"",A.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",$.authKey=null!==(d=O.auth)&&void 0!==d?d:"",$.userId=O.uuid},K=e=>{const t=p[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},G=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:i}=e.data;return void 0!==i&&"boolean"==typeof i&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},U=(e,t)=>{var n;const i=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",r=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=p[t.clientIdentifier],u=e.serviceRequestId;if(e.path===r&&e.channelGroupQuery===i)return V(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${u}' request completion.`,c),e.serviceRequestId;{const i=v[e.serviceRequestId];if(s||(s=N(t.request)),o||(o=D(t.request)),o.length&&!L(i.channels,o))continue;if(s.length&&!L(i.channelGroups,s))continue;return B(i,`'${t.request.identifier}' request channels and groups are subset of ongoing '${u}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${u}' request completion.`,c),e.serviceRequestId}}},W=(e,t)=>{var n,i,r;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(i=s.auth)&&void 0!==i?i:"",u=s.uuid;return(null!==(r=h[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===u&&t.authKey===c&&t.subscription&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.previousTimetoken||t.subscription.previousTimetoken===e)))},C=e=>{var t,n;const i=e.request.queryParameters,r=null!==(t=i.auth)&&void 0!==t?t:"",s=i.uuid;return(null!==(n=h[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===r))},D=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},N=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},L=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},M=()=>{V("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(p).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(V(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>2.5)&&(n=!0,V(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete p[t];let n=h[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?h[e]=n:delete h[e],0===n.length&&delete g[e],n.length>0){const n=b[e];n&&(delete n[t],0===Object.keys(n).length&&delete b[e])}else delete b[e];V(`Invalidate '${t}' client. '${Object.keys(p).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(V(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,A(t,e))})),0===Object.keys(p).length&&l&&clearInterval(l)},V=(e,t)=>{if(!a)return;const n=t?[t]:Object.values(p),i={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,i)}))},B=(e,t,n)=>{if(!a)return;const i=n?[n]:Object.values(p),r={type:"shared-worker-console-dir",message:t,data:e};i.forEach((e=>{e&&A(e,r)}))},Q=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${J(e)}`)).join("&"):`${t}=${J(n)}`})).join("&"),J=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/cbor/common.js b/lib/cbor/common.js index 29a9f2a2c..bd5b2e965 100644 --- a/lib/cbor/common.js +++ b/lib/cbor/common.js @@ -1,10 +1,25 @@ "use strict"; +/** + * Cbor decoder module. + */ Object.defineProperty(exports, "__esModule", { value: true }); +/** + * CBOR data decoder. + * + * @internal + */ class Cbor { constructor(decode, base64ToBinary) { this.decode = decode; this.base64ToBinary = base64ToBinary; } + /** + * Decode CBOR base64-encoded object. + * + * @param tokenString - Base64-encoded token. + * + * @returns Token object decoded from CBOR. + */ decodeToken(tokenString) { let padding = ''; if (tokenString.length % 4 === 3) diff --git a/lib/core/components/abort_signal.js b/lib/core/components/abort_signal.js index 6d51ec546..59ca4f8f3 100644 --- a/lib/core/components/abort_signal.js +++ b/lib/core/components/abort_signal.js @@ -10,6 +10,11 @@ class AbortError extends Error { } } exports.AbortError = AbortError; +/** + * Event Engine stored effect processing cancellation signal. + * + * @internal + */ class AbortSignal extends subject_1.Subject { constructor() { super(...arguments); diff --git a/lib/core/components/base64_codec.js b/lib/core/components/base64_codec.js index 4bac838e0..aa22d1d64 100644 --- a/lib/core/components/base64_codec.js +++ b/lib/core/components/base64_codec.js @@ -2,12 +2,26 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.encode = exports.decode = void 0; const BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; +/** + * Decode a Base64 encoded string. + * + * @param paddedInput Base64 string with padding + * @returns ArrayBuffer with decoded data + * + * @internal + */ function decode(paddedInput) { + // Remove up to last two equal signs. const input = paddedInput.replace(/==?$/, ''); const outputLength = Math.floor((input.length / 4) * 3); + // Prepare output buffer. const data = new ArrayBuffer(outputLength); const view = new Uint8Array(data); let cursor = 0; + /** + * Returns the next integer representation of a sixtet of bytes from the input + * @returns sixtet of bytes + */ function nextSixtet() { const char = input.charAt(cursor++); const index = BASE64_CHARMAP.indexOf(char); @@ -17,14 +31,17 @@ function decode(paddedInput) { return index; } for (let i = 0; i < outputLength; i += 3) { + // Obtain four sixtets const sx1 = nextSixtet(); const sx2 = nextSixtet(); const sx3 = nextSixtet(); const sx4 = nextSixtet(); + // Encode them as three octets const oc1 = ((sx1 & 0b00111111) << 2) | (sx2 >> 4); const oc2 = ((sx2 & 0b00001111) << 4) | (sx3 >> 2); const oc3 = ((sx3 & 0b00000011) << 6) | (sx4 >> 0); view[i] = oc1; + // Skip padding bytes. if (sx3 != 64) view[i + 1] = oc2; if (sx4 != 64) @@ -33,6 +50,14 @@ function decode(paddedInput) { return data; } exports.decode = decode; +/** + * Encode `ArrayBuffer` as a Base64 encoded string. + * + * @param input ArrayBuffer with source data. + * @returns Base64 string with padding. + * + * @internal + */ function encode(input) { let base64 = ''; const encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; @@ -42,25 +67,32 @@ function encode(input) { const mainLength = byteLength - byteRemainder; let a, b, c, d; let chunk; + // Main loop deals with bytes in chunks of 3 for (let i = 0; i < mainLength; i = i + 3) { + // Combine the three bytes into a single integer chunk = (bytes[i] << 16) | (bytes[i + 1] << 8) | bytes[i + 2]; - a = (chunk & 16515072) >> 18; - b = (chunk & 258048) >> 12; - c = (chunk & 4032) >> 6; - d = chunk & 63; + // Use bitmasks to extract 6-bit segments from the triplet + a = (chunk & 16515072) >> 18; // 16515072 = (2^6 - 1) << 18 + b = (chunk & 258048) >> 12; // 258048 = (2^6 - 1) << 12 + c = (chunk & 4032) >> 6; // 4032 = (2^6 - 1) << 6 + d = chunk & 63; // 63 = 2^6 - 1 + // Convert the raw binary segments to the appropriate ASCII encoding base64 += encodings[a] + encodings[b] + encodings[c] + encodings[d]; } + // Deal with the remaining bytes and padding if (byteRemainder == 1) { chunk = bytes[mainLength]; - a = (chunk & 252) >> 2; - b = (chunk & 3) << 4; + a = (chunk & 252) >> 2; // 252 = (2^6 - 1) << 2 + // Set the 4 least significant bits to zero + b = (chunk & 3) << 4; // 3 = 2^2 - 1 base64 += encodings[a] + encodings[b] + '=='; } else if (byteRemainder == 2) { chunk = (bytes[mainLength] << 8) | bytes[mainLength + 1]; - a = (chunk & 64512) >> 10; - b = (chunk & 1008) >> 4; - c = (chunk & 15) << 2; + a = (chunk & 64512) >> 10; // 64512 = (2^6 - 1) << 10 + b = (chunk & 1008) >> 4; // 1008 = (2^6 - 1) << 4 + // Set the 2 least significant bits to zero + c = (chunk & 15) << 2; // 15 = 2^4 - 1 base64 += encodings[a] + encodings[b] + encodings[c] + '='; } return base64; diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 07ff0840d..ef07c7b3a 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -1,15 +1,39 @@ "use strict"; +/** + * {@link PubNub} client configuration module. + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeConfiguration = void 0; const uuid_1 = __importDefault(require("./uuid")); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether encryption (if set) should use random initialization vector or not. + * + * @internal + */ const USE_RANDOM_INITIALIZATION_VECTOR = true; +/** + * Create {@link PubNub} client private configuration object. + * + * @param base - User- and platform-provided configuration. + * @param setupCryptoModule - Platform-provided {@link CryptoModule} configuration block. + * + * @returns `PubNub` client private configuration. + * + * @internal + */ const makeConfiguration = (base, setupCryptoModule) => { var _a, _b, _c; + // Ensure that retry policy has proper configuration (if has been set). (_a = base.retryConfiguration) === null || _a === void 0 ? void 0 : _a.validate(); (_b = base.useRandomIVs) !== null && _b !== void 0 ? _b : (base.useRandomIVs = USE_RANDOM_INITIALIZATION_VECTOR); + // Override origin value. base.origin = standardOrigin((_c = base.ssl) !== null && _c !== void 0 ? _c : false, base.origin); const cryptoModule = base.cryptoModule; if (cryptoModule) @@ -86,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.0.1'; + return '8.1.0'; }, getVersion() { return this.version; @@ -98,6 +122,10 @@ const makeConfiguration = (base, setupCryptoModule) => { const sdk = Object.values(this._pnsdkSuffix).join(separator); return sdk.length > 0 ? separator + sdk : ''; }, + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated getUUID() { return this.getUserId(); }, @@ -110,6 +138,7 @@ const makeConfiguration = (base, setupCryptoModule) => { getCustomDecrypt() { return base.customDecrypt; } }); + // Setup `CryptoModule` if possible. if (base.cipherKey) clientConfiguration.setCipherKey(base.cipherKey); else if (cryptoModule) @@ -117,6 +146,14 @@ const makeConfiguration = (base, setupCryptoModule) => { return clientConfiguration; }; exports.makeConfiguration = makeConfiguration; +/** + * Decide {@lin PubNub} service REST API origin. + * + * @param secure - Whether preferred to use secured connection or not. + * @param origin - User-provided or default origin. + * + * @returns `PubNub` REST API endpoints origin. + */ const standardOrigin = (secure, origin) => { const protocol = secure ? 'https://' : 'http://'; if (typeof origin === 'string') diff --git a/lib/core/components/cryptography/hmac-sha256.js b/lib/core/components/cryptography/hmac-sha256.js index 7f5e5716a..4b8616de3 100644 --- a/lib/core/components/cryptography/hmac-sha256.js +++ b/lib/core/components/cryptography/hmac-sha256.js @@ -1,4 +1,11 @@ "use strict"; +/*eslint-disable */ +/* + CryptoJS v3.1.2 + code.google.com/p/crypto-js + (c) 2009-2013 by Jeff Mott. All rights reserved. + code.google.com/p/crypto-js/wiki/License + */ var CryptoJS = CryptoJS || (function (h, s) { var f = {}, g = (f.lib = {}), q = function () { }, m = (g.Base = { @@ -170,6 +177,7 @@ var CryptoJS = CryptoJS || var t = (f.algo = {}); return f; })(Math); +// SHA256 (function (h) { for (var s = CryptoJS, f = s.lib, g = f.WordArray, q = f.Hasher, f = s.algo, m = [], r = [], l = function (a) { return (4294967296 * (a - (a | 0))) | 0; @@ -248,6 +256,7 @@ var CryptoJS = CryptoJS || s.SHA256 = q._createHelper(f); s.HmacSHA256 = q._createHmacHelper(f); })(Math); +// HMAC SHA256 (function () { var h = CryptoJS, s = h.enc.Utf8; h.algo.HMAC = h.lib.Base.extend({ @@ -279,6 +288,7 @@ var CryptoJS = CryptoJS || }, }); })(); +// Base64 (function () { var u = CryptoJS, p = u.lib.WordArray; u.enc.Base64 = { @@ -310,6 +320,7 @@ var CryptoJS = CryptoJS || _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', }; })(); +// BlockCipher (function (u) { function p(b, n, a, c, e, j, k) { b = b + ((n & a) | (~n & c)) + e + k; @@ -390,6 +401,7 @@ var CryptoJS = CryptoJS || return s.create(p).compute(d, l); }; })(); +// Cipher CryptoJS.lib.Cipher || (function (u) { var p = CryptoJS, d = p.lib, l = d.Base, s = d.WordArray, t = d.BufferedBlockAlgorithm, r = p.enc.Base64, w = p.algo.EvpKDF, v = (d.Cipher = t.extend({ @@ -586,6 +598,7 @@ CryptoJS.lib.Cipher || }, })); })(); +// AES (function () { for (var u = CryptoJS, p = u.lib.BlockCipher, d = u.algo, l = [], s = [], t = [], r = [], w = [], v = [], b = [], x = [], q = [], n = [], a = [], c = 0; 256 > c; c++) a[c] = 128 > c ? c << 1 : (c << 1) ^ 283; @@ -656,6 +669,7 @@ CryptoJS.lib.Cipher || })); u.AES = p._createHelper(d); })(); +// Mode ECB CryptoJS.mode.ECB = (function () { var ECB = CryptoJS.lib.BlockCipherMode.extend(); ECB.Encryptor = ECB.extend({ diff --git a/lib/core/components/cryptography/index.js b/lib/core/components/cryptography/index.js index 434020616..fad0763a5 100644 --- a/lib/core/components/cryptography/index.js +++ b/lib/core/components/cryptography/index.js @@ -1,24 +1,48 @@ "use strict"; +/** + * Legacy cryptography module. + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const base64_codec_1 = require("../base64_codec"); const hmac_sha256_1 = __importDefault(require("./hmac-sha256")); +/** + * Convert bytes array to words array. + * + * @param b - Bytes array (buffer) which should be converted. + * + * @returns Word sized array. + */ +/* eslint-disable @typescript-eslint/no-explicit-any */ function bufferToWordArray(b) { const wa = []; let i; for (i = 0; i < b.length; i += 1) { wa[(i / 4) | 0] |= b[i] << (24 - 8 * i); } + // @ts-expect-error Bundled library without types. return hmac_sha256_1.default.lib.WordArray.create(wa, b.length); } class default_1 { constructor(configuration) { this.configuration = configuration; + /** + * Crypto initialization vector. + */ this.iv = '0123456789012345'; + /** + * List os allowed cipher key encodings. + */ this.allowedKeyEncodings = ['hex', 'utf8', 'base64', 'binary']; + /** + * Allowed cipher key lengths. + */ this.allowedKeyLengths = [128, 256]; + /** + * Allowed crypto modes. + */ this.allowedModes = ['ecb', 'cbc']; this.defaultOptions = { encryptKey: true, @@ -27,23 +51,67 @@ class default_1 { mode: 'cbc', }; } + /** + * Generate HMAC-SHA256 hash from input data. + * + * @param data - Data from which hash should be generated. + * + * @returns HMAC-SHA256 hash from provided `data`. + */ HMACSHA256(data) { + // @ts-expect-error Bundled library without types. const hash = hmac_sha256_1.default.HmacSHA256(data, this.configuration.secretKey); + // @ts-expect-error Bundled library without types. return hash.toString(hmac_sha256_1.default.enc.Base64); } + /** + * Generate SHA256 hash from input data. + * + * @param data - Data from which hash should be generated. + * + * @returns SHA256 hash from provided `data`. + */ SHA256(data) { + // @ts-expect-error Bundled library without types. return hmac_sha256_1.default.SHA256(data).toString(hmac_sha256_1.default.enc.Hex); } + /** + * Encrypt provided data. + * + * @param data - Source data which should be encrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Encrypted `data`. + */ encrypt(data, customCipherKey, options) { if (this.configuration.customEncrypt) return this.configuration.customEncrypt(data); return this.pnEncrypt(data, customCipherKey, options); } + /** + * Decrypt provided data. + * + * @param data - Encrypted data which should be decrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Decrypted `data`. + */ decrypt(data, customCipherKey, options) { if (this.configuration.customDecrypt) return this.configuration.customDecrypt(data); return this.pnDecrypt(data, customCipherKey, options); } + /** + * Encrypt provided data. + * + * @param data - Source data which should be encrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Encrypted `data` as string. + */ pnEncrypt(data, customCipherKey, options) { const decidedCipherKey = customCipherKey !== null && customCipherKey !== void 0 ? customCipherKey : this.configuration.cipherKey; if (!decidedCipherKey) @@ -53,14 +121,27 @@ class default_1 { const cipherKey = this.getPaddedKey(decidedCipherKey, options); if (this.configuration.useRandomIVs) { const waIv = this.getRandomIV(); + // @ts-expect-error Bundled library without types. const waPayload = hmac_sha256_1.default.AES.encrypt(data, cipherKey, { iv: waIv, mode }).ciphertext; + // @ts-expect-error Bundled library without types. return waIv.clone().concat(waPayload.clone()).toString(hmac_sha256_1.default.enc.Base64); } const iv = this.getIV(options); + // @ts-expect-error Bundled library without types. const encryptedHexArray = hmac_sha256_1.default.AES.encrypt(data, cipherKey, { iv, mode }).ciphertext; + // @ts-expect-error Bundled library without types. const base64Encrypted = encryptedHexArray.toString(hmac_sha256_1.default.enc.Base64); return base64Encrypted || data; } + /** + * Decrypt provided data. + * + * @param data - Encrypted data which should be decrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Decrypted `data`. + */ pnDecrypt(data, customCipherKey, options) { const decidedCipherKey = customCipherKey !== null && customCipherKey !== void 0 ? customCipherKey : this.configuration.cipherKey; if (!decidedCipherKey) @@ -73,7 +154,10 @@ class default_1 { const iv = bufferToWordArray(ciphertext.slice(0, 16)); const payload = bufferToWordArray(ciphertext.slice(16)); try { - const plainJSON = hmac_sha256_1.default.AES.decrypt({ ciphertext: payload }, cipherKey, { iv, mode }).toString(hmac_sha256_1.default.enc.Utf8); + // @ts-expect-error Bundled library without types. + const plainJSON = hmac_sha256_1.default.AES.decrypt({ ciphertext: payload }, cipherKey, { iv, mode }).toString( + // @ts-expect-error Bundled library without types. + hmac_sha256_1.default.enc.Utf8); return JSON.parse(plainJSON); } catch (e) { @@ -83,7 +167,9 @@ class default_1 { else { const iv = this.getIV(options); try { + // @ts-expect-error Bundled library without types. const ciphertext = hmac_sha256_1.default.enc.Base64.parse(data); + // @ts-expect-error Bundled library without types. const plainJSON = hmac_sha256_1.default.AES.decrypt({ ciphertext }, cipherKey, { iv, mode }).toString(hmac_sha256_1.default.enc.Utf8); return JSON.parse(plainJSON); } @@ -92,16 +178,25 @@ class default_1 { } } } + /** + * Pre-process provided custom crypto configuration. + * + * @param incomingOptions - Configuration which should be pre-processed before use. + * + * @returns Normalized crypto configuration options. + */ parseOptions(incomingOptions) { var _a, _b, _c, _d; if (!incomingOptions) return this.defaultOptions; + // Defaults const options = { encryptKey: (_a = incomingOptions.encryptKey) !== null && _a !== void 0 ? _a : this.defaultOptions.encryptKey, keyEncoding: (_b = incomingOptions.keyEncoding) !== null && _b !== void 0 ? _b : this.defaultOptions.keyEncoding, keyLength: (_c = incomingOptions.keyLength) !== null && _c !== void 0 ? _c : this.defaultOptions.keyLength, mode: (_d = incomingOptions.mode) !== null && _d !== void 0 ? _d : this.defaultOptions.mode, }; + // Validation if (this.allowedKeyEncodings.indexOf(options.keyEncoding.toLowerCase()) === -1) options.keyEncoding = this.defaultOptions.keyEncoding; if (this.allowedKeyLengths.indexOf(options.keyLength) === -1) @@ -110,28 +205,70 @@ class default_1 { options.mode = this.defaultOptions.mode; return options; } + /** + * Decode provided cipher key. + * + * @param key - Key in `encoding` provided by `options`. + * @param options - Crypto configuration options with cipher key details. + * + * @returns Array buffer with decoded key. + */ decodeKey(key, options) { + // @ts-expect-error Bundled library without types. if (options.keyEncoding === 'base64') return hmac_sha256_1.default.enc.Base64.parse(key); + // @ts-expect-error Bundled library without types. if (options.keyEncoding === 'hex') return hmac_sha256_1.default.enc.Hex.parse(key); return key; } + /** + * Add padding to the cipher key. + * + * @param key - Key which should be padded. + * @param options - Crypto configuration options with cipher key details. + * + * @returns Properly padded cipher key. + */ getPaddedKey(key, options) { key = this.decodeKey(key, options); + // @ts-expect-error Bundled library without types. if (options.encryptKey) return hmac_sha256_1.default.enc.Utf8.parse(this.SHA256(key).slice(0, 32)); return key; } + /** + * Cipher mode. + * + * @param options - Crypto configuration with information about cipher mode. + * + * @returns Crypto cipher mode. + */ getMode(options) { + // @ts-expect-error Bundled library without types. if (options.mode === 'ecb') return hmac_sha256_1.default.mode.ECB; + // @ts-expect-error Bundled library without types. return hmac_sha256_1.default.mode.CBC; } + /** + * Cipher initialization vector. + * + * @param options - Crypto configuration with information about cipher mode. + * + * @returns Initialization vector. + */ getIV(options) { + // @ts-expect-error Bundled library without types. return options.mode === 'cbc' ? hmac_sha256_1.default.enc.Utf8.parse(this.iv) : null; } + /** + * Random initialization vector. + * + * @returns Generated random initialization vector. + */ getRandomIV() { + // @ts-expect-error Bundled library without types. return hmac_sha256_1.default.lib.WordArray.random(16); } } diff --git a/lib/core/components/deduping_manager.js b/lib/core/components/deduping_manager.js index 0f30833c4..ae7904bb3 100644 --- a/lib/core/components/deduping_manager.js +++ b/lib/core/components/deduping_manager.js @@ -1,4 +1,5 @@ "use strict"; +/* */ Object.defineProperty(exports, "__esModule", { value: true }); const hashCode = (payload) => { let hash = 0; @@ -6,11 +7,16 @@ const hashCode = (payload) => { return hash; for (let i = 0; i < payload.length; i += 1) { const character = payload.charCodeAt(i); - hash = (hash << 5) - hash + character; - hash = hash & hash; + hash = (hash << 5) - hash + character; // eslint-disable-line + hash = hash & hash; // eslint-disable-line } return hash; }; +/** + * Real-time events deduplication manager. + * + * @internal + */ class default_1 { constructor({ config }) { this.hashHistory = []; diff --git a/lib/core/components/eventEmitter.js b/lib/core/components/eventEmitter.js index f843210ca..d995bd428 100644 --- a/lib/core/components/eventEmitter.js +++ b/lib/core/components/eventEmitter.js @@ -12,12 +12,33 @@ var __rest = (this && this.__rest) || function (s, e) { }; Object.defineProperty(exports, "__esModule", { value: true }); const subscribe_1 = require("../endpoints/subscribe"); +/** + * Real-time events' emitter. + * + * Emitter responsible for forwarding received real-time events to the closures which has been + * registered for specific events handling. + * + * @internal + */ class EventEmitter { constructor(listenerManager) { this.listenerManager = listenerManager; + /** + * Map of channels to listener callbacks for them. + */ this.channelListenerMap = new Map(); + /** + * Map of channel group names to the listener callbacks for them. + */ this.groupListenerMap = new Map(); } + /** + * Emit specific real-time event. + * + * Proper listener will be notified basing on event `type`. + * + * @param event - Received real-time event. + */ emitEvent(event) { if (event.type === subscribe_1.PubNubEventType.Message) { this.listenerManager.announceMessage(event.data); @@ -68,7 +89,15 @@ class EventEmitter { this.announce('file', event.data, event.data.channel, event.data.subscription); } } + /** + * Register real-time event listener for specific channels and groups. + * + * @param listener - Listener with event callbacks to handle different types of events. + * @param channels - List of channels for which listener should be registered. + * @param groups - List of channel groups for which listener should be registered. + */ addListener(listener, channels, groups) { + // Register event-listener listener globally. if (!(channels && groups)) { this.listenerManager.addListener(listener); } @@ -93,6 +122,13 @@ class EventEmitter { }); } } + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + * @param channels - List of channels for which listener should be removed. + * @param groups - List of channel groups for which listener should be removed. + */ removeListener(listener, channels, groups) { if (!(channels && groups)) { this.listenerManager.removeListener(listener); @@ -110,21 +146,34 @@ class EventEmitter { }); } } + /** + * Clear all real-time event listeners. + */ removeAllListeners() { this.listenerManager.removeAllListeners(); this.channelListenerMap.clear(); this.groupListenerMap.clear(); } + /** + * Announce real-time event to all listeners. + * + * @param type - Type of event which should be announced. + * @param event - Announced real-time event payload. + * @param channel - Name of the channel for which registered listeners should be notified. + * @param group - Name of the channel group for which registered listeners should be notified. + */ announce(type, event, channel, group) { if (event && this.channelListenerMap.has(channel)) this.channelListenerMap.get(channel).forEach((listener) => { const typedListener = listener[type]; + // @ts-expect-error Dynamic events mapping. if (typedListener) typedListener(event); }); if (group && this.groupListenerMap.has(group)) this.groupListenerMap.get(group).forEach((listener) => { const typedListener = listener[type]; + // @ts-expect-error Dynamic events mapping. if (typedListener) typedListener(event); }); diff --git a/lib/core/components/listener_manager.js b/lib/core/components/listener_manager.js index 37778be75..59072e7ed 100644 --- a/lib/core/components/listener_manager.js +++ b/lib/core/components/listener_manager.js @@ -1,67 +1,130 @@ "use strict"; +/** + * Events listener manager module. + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ListenerManager = void 0; const categories_1 = __importDefault(require("../constants/categories")); +/** + * Real-time listeners' manager. + * + * @internal + */ class ListenerManager { constructor() { + /** + * List of registered event listeners. + */ this.listeners = []; + // endregion } + /** + * Register new real-time events listener. + * + * @param listener - Listener with event callbacks to handle different types of events. + */ addListener(listener) { if (this.listeners.includes(listener)) return; this.listeners.push(listener); } + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + */ removeListener(listener) { this.listeners = this.listeners.filter((storedListener) => storedListener !== listener); } + /** + * Clear all real-time event listeners. + */ removeAllListeners() { this.listeners = []; } + /** + * Announce PubNub client status change event. + * + * @param status - PubNub client status. + */ announceStatus(status) { this.listeners.forEach((listener) => { if (listener.status) listener.status(status); }); } + /** + * Announce channel presence change event. + * + * @param presence - Channel presence change information. + */ announcePresence(presence) { this.listeners.forEach((listener) => { if (listener.presence) listener.presence(presence); }); } + /** + * Announce real-time message event. + * + * @param message - Received real-time message. + */ announceMessage(message) { this.listeners.forEach((listener) => { if (listener.message) listener.message(message); }); } + /** + * Announce real-time signal event. + * + * @param signal - Received real-time signal. + */ announceSignal(signal) { this.listeners.forEach((listener) => { if (listener.signal) listener.signal(signal); }); } + /** + * Announce message actions change event. + * + * @param messageAction - Message action change information. + */ announceMessageAction(messageAction) { this.listeners.forEach((listener) => { if (listener.messageAction) listener.messageAction(messageAction); }); } + /** + * Announce fie share event. + * + * @param file - Shared file information. + */ announceFile(file) { this.listeners.forEach((listener) => { if (listener.file) listener.file(file); }); } + /** + * Announce App Context Object change event. + * + * @param object - App Context change information. + */ announceObjects(object) { this.listeners.forEach((listener) => { if (listener.objects) listener.objects(object); }); } + /** + * Announce network up status. + */ announceNetworkUp() { this.listeners.forEach((listener) => { if (listener.status) { @@ -71,6 +134,9 @@ class ListenerManager { } }); } + /** + * Announce network down status. + */ announceNetworkDown() { this.listeners.forEach((listener) => { if (listener.status) { @@ -80,18 +146,43 @@ class ListenerManager { } }); } + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + /** + * Announce User App Context Object change event. + * + * @param user - User App Context change information. + * + * @deprecated Use {@link announceObjects} method instead. + */ announceUser(user) { this.listeners.forEach((listener) => { if (listener.user) listener.user(user); }); } + /** + * Announce Space App Context Object change event. + * + * @param space - Space App Context change information. + * + * @deprecated Use {@link announceObjects} method instead. + */ announceSpace(space) { this.listeners.forEach((listener) => { if (listener.space) listener.space(space); }); } + /** + * Announce VSP Membership App Context Object change event. + * + * @param membership - VSP Membership App Context change information. + * + * @deprecated Use {@link announceObjects} method instead. + */ announceMembership(membership) { this.listeners.forEach((listener) => { if (listener.membership) diff --git a/lib/core/components/push_payload.js b/lib/core/components/push_payload.js index e2196cd9b..005ffd348 100644 --- a/lib/core/components/push_payload.js +++ b/lib/core/components/push_payload.js @@ -1,4 +1,8 @@ "use strict"; +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) @@ -12,6 +16,11 @@ var __rest = (this && this.__rest) || function (s, e) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FCMNotificationPayload = exports.APNSNotificationPayload = void 0; +// endregion +// endregion +/** + * Base notification payload object. + */ class BaseNotificationPayload { constructor(payload, title, body) { this._payload = payload; @@ -19,91 +28,205 @@ class BaseNotificationPayload { this.title = title; this.body = body; } + /** + * Retrieve resulting notification payload content for message. + * + * @returns Preformatted push notification payload data. + */ get payload() { return this._payload; } + /** + * Update notification title. + * + * @param value - New notification title. + */ set title(value) { this._title = value; } + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ set subtitle(value) { this._subtitle = value; } + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ set body(value) { this._body = value; } + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ set badge(value) { this._badge = value; } + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ set sound(value) { this._sound = value; } + /** + * Platform-specific structure initialization. + */ setDefaultPayloadStructure() { } + /** + * Translate data object into PubNub push notification payload object. + * + * @returns Preformatted push notification payload. + */ toObject() { return {}; } } +/** + * Message payload for Apple Push Notification Service. + */ class APNSNotificationPayload extends BaseNotificationPayload { constructor() { super(...arguments); + /** + * Type of push notification service for which payload will be created. + */ this._apnsPushType = 'apns'; + /** + * Whether resulting payload should trigger silent notification or not. + */ this._isSilent = false; } get payload() { return this._payload; } + /** + * Update notification receivers configuration. + * + * @param value - New APNS2 configurations. + */ set configurations(value) { if (!value || !value.length) return; this._configurations = value; } + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ get notification() { return this.payload.aps; } + /** + * Notification title. + * + * @returns Main notification title. + */ get title() { return this._title; } + /** + * Update notification title. + * + * @param value - New notification title. + */ set title(value) { if (!value || !value.length) return; this.payload.aps.alert.title = value; this._title = value; } + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ get subtitle() { return this._subtitle; } + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ set subtitle(value) { if (!value || !value.length) return; this.payload.aps.alert.subtitle = value; this._subtitle = value; } + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ get body() { return this._body; } + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ set body(value) { if (!value || !value.length) return; this.payload.aps.alert.body = value; this._body = value; } + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ get badge() { return this._badge; } + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ set badge(value) { if (value === undefined || value === null) return; this.payload.aps.badge = value; this._badge = value; } + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ get sound() { return this._sound; } + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ set sound(value) { if (!value || !value.length) return; this.payload.aps.sound = value; this._sound = value; } + /** + * Set whether notification should be silent or not. + * + * `content-available` notification type will be used to deliver silent notification if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ set silent(value) { this._isSilent = value; } @@ -136,6 +259,13 @@ class APNSNotificationPayload extends BaseNotificationPayload { } return this._isSilent || (alert && Object.keys(alert).length) ? payload : null; } + /** + * Create PubNub push notification service APNS2 configuration information object. + * + * @param configuration - Source user-provided APNS2 configuration. + * + * @returns Preformatted for PubNub service APNS2 configuration information. + */ objectFromAPNS2Configuration(configuration) { if (!configuration.targets || !configuration.targets.length) throw new ReferenceError('At least one APNS2 target should be provided'); @@ -151,6 +281,13 @@ class APNSNotificationPayload extends BaseNotificationPayload { objectifiedConfiguration.expiration = expirationDate.toISOString(); return objectifiedConfiguration; } + /** + * Create PubNub push notification service APNS2 target information object. + * + * @param target - Source user-provided data. + * + * @returns Preformatted for PubNub service APNS2 target information. + */ objectFromAPNSTarget(target) { if (!target.topic || !target.topic.length) throw new TypeError("Target 'topic' undefined."); @@ -162,46 +299,99 @@ class APNSNotificationPayload extends BaseNotificationPayload { } } exports.APNSNotificationPayload = APNSNotificationPayload; +/** + * Message payload for Firebase Clouse Messaging service. + */ class FCMNotificationPayload extends BaseNotificationPayload { get payload() { return this._payload; } + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ get notification() { return this.payload.notification; } + /** + * Silent notification payload. + * + * @returns Silent notification payload (data notification). + */ get data() { return this.payload.data; } + /** + * Notification title. + * + * @returns Main notification title. + */ get title() { return this._title; } + /** + * Update notification title. + * + * @param value - New notification title. + */ set title(value) { if (!value || !value.length) return; this.payload.notification.title = value; this._title = value; } + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ get body() { return this._body; } + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ set body(value) { if (!value || !value.length) return; this.payload.notification.body = value; this._body = value; } + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ get sound() { return this._sound; } + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ set sound(value) { if (!value || !value.length) return; this.payload.notification.sound = value; this._sound = value; } + /** + * Retrieve notification icon file. + * + * @returns Notification icon file name from resource bundle. + */ get icon() { return this._icon; } + /** + * Update notification icon. + * + * @param value - Name of the icon file which should be shown on notification. + */ set icon(value) { if (!value || !value.length) return; @@ -217,6 +407,13 @@ class FCMNotificationPayload extends BaseNotificationPayload { this.payload.notification.tag = value; this._tag = value; } + /** + * Set whether notification should be silent or not. + * + * All notification data will be sent under `data` field if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ set silent(value) { this._isSilent = value; } @@ -228,6 +425,7 @@ class FCMNotificationPayload extends BaseNotificationPayload { let data = Object.assign({}, this.payload.data); let notification = null; const payload = {}; + // Check whether additional data has been passed outside 'data' object and put it into it if required. if (Object.keys(this.payload).length > 2) { const _a = this.payload, { notification: initialNotification, data: initialData } = _a, additionalData = __rest(_a, ["notification", "data"]); data = Object.assign(Object.assign({}, data), additionalData); @@ -255,39 +453,89 @@ class NotificationsPayload { set debugging(value) { this._debugging = value; } + /** + * Notification title. + * + * @returns Main notification title. + */ get title() { return this._title; } + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ get subtitle() { return this._subtitle; } + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ set subtitle(value) { this._subtitle = value; this.apns.subtitle = value; this.fcm.subtitle = value; } + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ get body() { return this._body; } + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ get badge() { return this._badge; } + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ set badge(value) { this._badge = value; this.apns.badge = value; this.fcm.badge = value; } + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ get sound() { return this._sound; } + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ set sound(value) { this._sound = value; this.apns.sound = value; this.fcm.sound = value; } + /** + * Build notifications platform for requested platforms. + * + * @param platforms - List of platforms for which payload should be added to final dictionary. Supported values: + * gcm, apns, and apns2. + * + * @returns Object with data, which can be sent with publish method call and trigger remote notifications for + * specified platforms. + */ buildPayload(platforms) { const payload = {}; if (platforms.includes('apns') || platforms.includes('apns2')) { + // @ts-expect-error Override APNS version. this.apns._apnsPushType = platforms.includes('apns') ? 'apns' : 'apns2'; const apnsPayload = this.apns.toObject(); if (apnsPayload && Object.keys(apnsPayload).length) diff --git a/lib/core/components/reconnection_manager.js b/lib/core/components/reconnection_manager.js index bc3065231..731bd261e 100644 --- a/lib/core/components/reconnection_manager.js +++ b/lib/core/components/reconnection_manager.js @@ -1,16 +1,39 @@ "use strict"; +/** + * Subscription reconnection-manager. + * + * **Note:** Reconnection manger rely on legacy time-based availability check. + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ReconnectionManager = void 0; +/** + * Network "discovery" manager. + * + * Manager perform periodic `time` API calls to identify network availability. + * + * @internal + */ class ReconnectionManager { constructor(time) { this.time = time; } + /** + * Configure reconnection handler. + * + * @param callback - Successful availability check notify callback. + */ onReconnect(callback) { this.callback = callback; } + /** + * Start periodic "availability" check. + */ startPolling() { this.timeTimer = setInterval(() => this.callTime(), 3000); } + /** + * Stop periodic "availability" check. + */ stopPolling() { if (this.timeTimer) clearInterval(this.timeTimer); diff --git a/lib/core/components/request.js b/lib/core/components/request.js index 9da7e686b..0a2e3af5a 100644 --- a/lib/core/components/request.js +++ b/lib/core/components/request.js @@ -15,33 +15,82 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractRequest = void 0; const transport_request_1 = require("../types/transport-request"); const uuid_1 = __importDefault(require("./uuid")); +/** + * Base REST API request class. + * + * @internal + */ class AbstractRequest { + /** + * Construct base request. + * + * Constructed request by default won't be cancellable and performed using `GET` HTTP method. + * + * @param params - Request configuration parameters. + */ constructor(params) { this.params = params; + /** + * Unique request identifier. + */ this.requestIdentifier = uuid_1.default.createUUID(); this._cancellationController = null; } + /** + * Retrieve configured cancellation controller. + * + * @returns Cancellation controller. + */ get cancellationController() { return this._cancellationController; } + /** + * Update request cancellation controller. + * + * Controller itself provided by transport provider implementation and set only when request + * sending has been scheduled. + * + * @param controller - Cancellation controller or `null` to reset it. + */ set cancellationController(controller) { this._cancellationController = controller; } + /** + * Abort request if possible. + */ abort() { if (this && this.cancellationController) this.cancellationController.abort(); } + /** + * Target REST API endpoint operation type. + */ operation() { throw Error('Should be implemented by subclass.'); } + /** + * Validate user-provided data before scheduling request. + * + * @returns Error message if request can't be sent without missing or malformed parameters. + */ validate() { return undefined; } + /** + * Parse service response. + * + * @param _response - Raw service response which should be parsed. + */ parse(_response) { return __awaiter(this, void 0, void 0, function* () { throw Error('Should be implemented by subclass.'); }); } + /** + * Create platform-agnostic request object. + * + * @returns Request object which can be processed using platform-specific requirements. + */ request() { var _a, _b, _c, _d; const request = { @@ -52,9 +101,11 @@ class AbstractRequest { timeout: 10000, identifier: this.requestIdentifier, }; + // Attach headers (if required). const headers = this.headers; if (headers) request.headers = headers; + // Attach body (if required). if (request.method === transport_request_1.TransportMethod.POST || request.method === transport_request_1.TransportMethod.PATCH) { const [body, formData] = [this.body, this.formData]; if (formData) @@ -64,21 +115,48 @@ class AbstractRequest { } return request; } + /** + * Target REST API endpoint request headers getter. + * + * @returns Key/value headers which should be used with request. + */ get headers() { return undefined; } + /** + * Target REST API endpoint request path getter. + * + * @returns REST API path. + */ get path() { throw Error('`path` getter should be implemented by subclass.'); } + /** + * Target REST API endpoint request query parameters getter. + * + * @returns Key/value pairs which should be appended to the REST API path. + */ get queryParameters() { return {}; } get formData() { return undefined; } + /** + * Target REST API Request body payload getter. + * + * @returns Buffer of stringified data which should be sent with `POST` or `PATCH` request. + */ get body() { return undefined; } + /** + * Deserialize service response. + * + * @param response - Transparent response object with headers and body information. + * + * @returns Deserialized data or `undefined` in case of `JSON.parse(..)` error. + */ deserializeResponse(response) { const contentType = response.headers['content-type']; if (!contentType || (contentType.indexOf('javascript') === -1 && contentType.indexOf('json') === -1)) @@ -95,4 +173,7 @@ class AbstractRequest { } } exports.AbstractRequest = AbstractRequest; +/** + * Service `ArrayBuffer` response decoder. + */ AbstractRequest.decoder = new TextDecoder(); diff --git a/lib/core/components/stringify_buffer_keys.js b/lib/core/components/stringify_buffer_keys.js index 1a0b1692b..c9c405834 100644 --- a/lib/core/components/stringify_buffer_keys.js +++ b/lib/core/components/stringify_buffer_keys.js @@ -1,6 +1,15 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stringifyBufferKeys = void 0; +/** + * Re-map CBOR object keys from potentially C buffer strings to actual strings. + * + * @param obj CBOR which should be remapped to stringified keys. + * + * @returns Dictionary with stringified keys. + * + * @internal + */ function stringifyBufferKeys(obj) { const isObject = (value) => typeof value === 'object' && value !== null && value.constructor === Object; const isString = (value) => typeof value === 'string' || value instanceof String; diff --git a/lib/core/components/subject.js b/lib/core/components/subject.js index fed3f3ade..e483d4954 100644 --- a/lib/core/components/subject.js +++ b/lib/core/components/subject.js @@ -1,6 +1,9 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Subject = void 0; +/** + * @internal + */ class Subject { constructor(sync = false) { this.sync = sync; diff --git a/lib/core/components/subscription-manager.js b/lib/core/components/subscription-manager.js index fa7d37902..1f5139485 100644 --- a/lib/core/components/subscription-manager.js +++ b/lib/core/components/subscription-manager.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Subscription manager module. + */ var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) @@ -19,6 +22,11 @@ const reconnection_manager_1 = require("./reconnection_manager"); const categories_1 = __importDefault(require("../constants/categories")); const categories_2 = __importDefault(require("../constants/categories")); const deduping_manager_1 = __importDefault(require("./deduping_manager")); +/** + * Subscription loop manager. + * + * @internal + */ class SubscriptionManager { constructor(configuration, listenerManager, eventEmitter, subscribeCall, heartbeatCall, leaveCall, time) { this.configuration = configuration; @@ -45,6 +53,7 @@ class SubscriptionManager { this.subscriptionStatusAnnounced = false; this.isOnline = true; } + // region Information get subscribedChannels() { return Object.keys(this.channels); } @@ -57,6 +66,8 @@ class SubscriptionManager { set abort(call) { this._subscribeAbort = call; } + // endregion + // region Subscription disconnect() { this.stopSubscribeLoop(); this.stopHeartbeatTimer(); @@ -66,6 +77,11 @@ class SubscriptionManager { this.startSubscribeLoop(); this.startHeartbeatTimer(); } + /** + * Update channels and groups used in subscription loop. + * + * @param parameters - Subscribe configuration parameters. + */ subscribe(parameters) { const { channels, channelGroups, timetoken, withPresence = false, withHeartbeats = false } = parameters; if (timetoken) { @@ -127,6 +143,7 @@ class SubscriptionManager { actualChannelGroups.add(group); } }); + // There is no need to unsubscribe to empty list of data sources. if (actualChannels.size === 0 && actualChannelGroups.size === 0) return; if (this.configuration.suppressLeaveEvents === false && !isOffline) { @@ -171,6 +188,7 @@ class SubscriptionManager { const channels = [...Object.keys(this.channels)]; Object.keys(this.presenceChannelGroups).forEach((group) => channelGroups.push(`${group}-pnpres`)); Object.keys(this.presenceChannels).forEach((channel) => channels.push(`${channel}-pnpres`)); + // There is no need to start subscription loop for empty list of data sources. if (channels.length === 0 && channelGroups.length === 0) return; this.subscribeCall({ @@ -191,8 +209,12 @@ class SubscriptionManager { this._subscribeAbort = null; } } + /** + * Process subscribe REST API endpoint response. + */ processSubscribeResponse(status, result) { if (status.error) { + // Ignore aborted request. if ((typeof status.errorData === 'object' && 'name' in status.errorData && status.errorData.name === 'AbortError') || @@ -254,6 +276,7 @@ class SubscriptionManager { }; this.subscriptionStatusAnnounced = true; this.listenerManager.announceStatus(connected); + // Clear pending channels and groups. this.pendingChannelGroupSubscriptions.clear(); this.pendingChannelSubscriptions.clear(); } @@ -287,11 +310,23 @@ class SubscriptionManager { this.region = result.cursor.region; this.startSubscribeLoop(); } + // endregion + // region Presence + /** + * Update `uuid` state which should be sent with subscribe request. + * + * @param parameters - Channels and groups with state which should be associated to `uuid`. + */ setState(parameters) { const { state, channels, channelGroups } = parameters; channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => channel in this.channels && (this.presenceState[channel] = state)); channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.forEach((group) => group in this.channelGroups && (this.presenceState[group] = state)); } + /** + * Manual presence management. + * + * @param parameters - Desired presence state for provided list of channels and groups. + */ changePresence(parameters) { const { connected, channels, channelGroups } = parameters; if (connected) { @@ -321,15 +356,24 @@ class SubscriptionManager { this.sendHeartbeat(); this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), heartbeatInterval * 1000); } + /** + * Stop heartbeat. + * + * Stop timer which trigger {@link HeartbeatRequest} sending with configured presence intervals. + */ stopHeartbeatTimer() { if (!this.heartbeatTimer) return; clearInterval(this.heartbeatTimer); this.heartbeatTimer = null; } + /** + * Send heartbeat request. + */ sendHeartbeat() { const heartbeatChannelGroups = Object.keys(this.heartbeatChannelGroups); const heartbeatChannels = Object.keys(this.heartbeatChannels); + // There is no need to start heartbeat loop if there is no channels and groups to use. if (heartbeatChannels.length === 0 && heartbeatChannelGroups.length === 0) return; this.heartbeatCall({ diff --git a/lib/core/components/token_manager.js b/lib/core/components/token_manager.js index 9ada86a34..422a7dd8c 100644 --- a/lib/core/components/token_manager.js +++ b/lib/core/components/token_manager.js @@ -1,19 +1,49 @@ "use strict"; +/** + * PubNub Access Token Manager module. + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TokenManager = void 0; +// endregion +/** + * REST API access token manager. + * + * Manager maintains active access token and let parse it to get information about permissions. + * + * @internal + */ class TokenManager { constructor(cbor) { this.cbor = cbor; } + /** + * Update REST API access token. + * + * **Note:** Token will be applied only for next requests and won't affect ongoing requests. + * + * @param [token] - Access token which should be used to access PubNub REST API. + */ setToken(token) { if (token && token.length > 0) this.token = token; else this.token = undefined; } + /** + * REST API access token. + * + * @returns Previously configured REST API access token. + */ getToken() { return this.token; } + /** + * Parse Base64-encoded access token. + * + * @param tokenString - Base64-encoded access token. + * + * @returns Information about resources and permissions which has been granted for them. + */ parseToken(tokenString) { const parsed = this.cbor.decodeToken(tokenString); if (parsed !== undefined) { @@ -72,6 +102,13 @@ class TokenManager { } return undefined; } + /** + * Extract resource access permission information. + * + * @param permissions - Bit-encoded resource permissions. + * + * @returns Human-readable resource permissions. + */ extractPermissions(permissions) { const permissionsResult = { read: false, diff --git a/lib/core/components/uuid.js b/lib/core/components/uuid.js index deb3c187f..4d1255653 100644 --- a/lib/core/components/uuid.js +++ b/lib/core/components/uuid.js @@ -9,6 +9,7 @@ exports.default = { if (lil_uuid_1.default.uuid) { return lil_uuid_1.default.uuid(); } + // @ts-expect-error Depending on module type it may be callable. return (0, lil_uuid_1.default)(); }, }; diff --git a/lib/core/constants/categories.js b/lib/core/constants/categories.js index de7657670..faab584be 100644 --- a/lib/core/constants/categories.js +++ b/lib/core/constants/categories.js @@ -1,22 +1,84 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Request processing status categories. + */ var StatusCategory; (function (StatusCategory) { + /** + * Call failed when network was unable to complete the call. + */ StatusCategory["PNNetworkIssuesCategory"] = "PNNetworkIssuesCategory"; + /** + * Network call timed out. + */ StatusCategory["PNTimeoutCategory"] = "PNTimeoutCategory"; + /** + * Request has been cancelled. + */ StatusCategory["PNCancelledCategory"] = "PNCancelledCategory"; + /** + * Server responded with bad response. + */ StatusCategory["PNBadRequestCategory"] = "PNBadRequestCategory"; + /** + * Server responded with access denied. + */ StatusCategory["PNAccessDeniedCategory"] = "PNAccessDeniedCategory"; + /** + * Incomplete parameters provided for used endpoint. + */ StatusCategory["PNValidationErrorCategory"] = "PNValidationErrorCategory"; + /** + * PubNub request acknowledgment status. + * + * Some API endpoints respond with request processing status w/o useful data. + */ StatusCategory["PNAcknowledgmentCategory"] = "PNAcknowledgmentCategory"; + /** + * Something strange happened; please check the logs. + */ StatusCategory["PNUnknownCategory"] = "PNUnknownCategory"; + // -------------------------------------------------------- + // --------------------- Network status ------------------- + // -------------------------------------------------------- + /** + * SDK will announce when the network appears to be connected again. + */ StatusCategory["PNNetworkUpCategory"] = "PNNetworkUpCategory"; + /** + * SDK will announce when the network appears to down. + */ StatusCategory["PNNetworkDownCategory"] = "PNNetworkDownCategory"; + // -------------------------------------------------------- + // -------------------- Real-time events ------------------ + // -------------------------------------------------------- + /** + * PubNub client reconnected to the real-time updates stream. + */ StatusCategory["PNReconnectedCategory"] = "PNReconnectedCategory"; + /** + * PubNub client connected to the real-time updates stream. + */ StatusCategory["PNConnectedCategory"] = "PNConnectedCategory"; + /** + * Received real-time updates exceed specified threshold. + * + * After temporary disconnection and catchup, this category means that potentially some + * real-time updates have been pushed into `storage` and need to be requested separately. + */ StatusCategory["PNRequestMessageCountExceededCategory"] = "PNRequestMessageCountExceededCategory"; + /** + * PubNub client disconnected from the real-time updates streams. + */ StatusCategory["PNDisconnectedCategory"] = "PNDisconnectedCategory"; + /** + * PubNub client wasn't able to connect to the real-time updates streams. + */ StatusCategory["PNConnectionErrorCategory"] = "PNConnectionErrorCategory"; + /** + * PubNub client unexpectedly disconnected from the real-time updates streams. + */ StatusCategory["PNDisconnectedUnexpectedlyCategory"] = "PNDisconnectedUnexpectedlyCategory"; })(StatusCategory || (StatusCategory = {})); exports.default = StatusCategory; diff --git a/lib/core/constants/operations.js b/lib/core/constants/operations.js index c30b7e919..dc348150f 100644 --- a/lib/core/constants/operations.js +++ b/lib/core/constants/operations.js @@ -1,57 +1,240 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +/* */ var RequestOperation; (function (RequestOperation) { + // -------------------------------------------------------- + // ---------------------- Publish API --------------------- + // -------------------------------------------------------- + /** + * Data publish REST API operation. + */ RequestOperation["PNPublishOperation"] = "PNPublishOperation"; + /** + * Signal sending REST API operation. + */ RequestOperation["PNSignalOperation"] = "PNSignalOperation"; + // -------------------------------------------------------- + // --------------------- Subscribe API -------------------- + // -------------------------------------------------------- + /** + * Subscribe for real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `join` event. + */ RequestOperation["PNSubscribeOperation"] = "PNSubscribeOperation"; + /** + * Unsubscribe from real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `leave` event. + */ RequestOperation["PNUnsubscribeOperation"] = "PNUnsubscribeOperation"; + // -------------------------------------------------------- + // --------------------- Presence API --------------------- + // -------------------------------------------------------- + /** + * Fetch user's presence information REST API operation. + */ RequestOperation["PNWhereNowOperation"] = "PNWhereNowOperation"; + /** + * Fetch channel's presence information REST API operation. + */ RequestOperation["PNHereNowOperation"] = "PNHereNowOperation"; + /** + * Fetch global presence information REST API operation. + */ RequestOperation["PNGlobalHereNowOperation"] = "PNGlobalHereNowOperation"; + /** + * Update user's information associated with specified channel REST API operation. + */ RequestOperation["PNSetStateOperation"] = "PNSetStateOperation"; + /** + * Fetch user's information associated with the specified channel REST API operation. + */ RequestOperation["PNGetStateOperation"] = "PNGetStateOperation"; + /** + * Announce presence on managed channels REST API operation. + */ RequestOperation["PNHeartbeatOperation"] = "PNHeartbeatOperation"; + // -------------------------------------------------------- + // ----------------- Message Reaction API ----------------- + // -------------------------------------------------------- + /** + * Add a reaction to the specified message REST API operation. + */ RequestOperation["PNAddMessageActionOperation"] = "PNAddActionOperation"; + /** + * Remove reaction from the specified message REST API operation. + */ RequestOperation["PNRemoveMessageActionOperation"] = "PNRemoveMessageActionOperation"; + /** + * Fetch reactions for specific message REST API operation. + */ RequestOperation["PNGetMessageActionsOperation"] = "PNGetMessageActionsOperation"; RequestOperation["PNTimeOperation"] = "PNTimeOperation"; + // -------------------------------------------------------- + // ---------------------- Storage API --------------------- + // -------------------------------------------------------- + /** + * Channel history REST API operation. + */ RequestOperation["PNHistoryOperation"] = "PNHistoryOperation"; + /** + * Delete messages from channel history REST API operation. + */ RequestOperation["PNDeleteMessagesOperation"] = "PNDeleteMessagesOperation"; + /** + * History for channels REST API operation. + */ RequestOperation["PNFetchMessagesOperation"] = "PNFetchMessagesOperation"; + /** + * Number of messages for channels in specified time frame REST API operation. + */ RequestOperation["PNMessageCounts"] = "PNMessageCountsOperation"; + // -------------------------------------------------------- + // -------------------- App Context API ------------------- + // -------------------------------------------------------- + /** + * Fetch users metadata REST API operation. + */ RequestOperation["PNGetAllUUIDMetadataOperation"] = "PNGetAllUUIDMetadataOperation"; + /** + * Fetch user metadata REST API operation. + */ RequestOperation["PNGetUUIDMetadataOperation"] = "PNGetUUIDMetadataOperation"; + /** + * Set user metadata REST API operation. + */ RequestOperation["PNSetUUIDMetadataOperation"] = "PNSetUUIDMetadataOperation"; + /** + * Remove user metadata REST API operation. + */ RequestOperation["PNRemoveUUIDMetadataOperation"] = "PNRemoveUUIDMetadataOperation"; + /** + * Fetch channels metadata REST API operation. + */ RequestOperation["PNGetAllChannelMetadataOperation"] = "PNGetAllChannelMetadataOperation"; + /** + * Fetch channel metadata REST API operation. + */ RequestOperation["PNGetChannelMetadataOperation"] = "PNGetChannelMetadataOperation"; + /** + * Set channel metadata REST API operation. + */ RequestOperation["PNSetChannelMetadataOperation"] = "PNSetChannelMetadataOperation"; + /** + * Remove channel metadata REST API operation. + */ RequestOperation["PNRemoveChannelMetadataOperation"] = "PNRemoveChannelMetadataOperation"; + /** + * Fetch channel members REST API operation. + */ RequestOperation["PNGetMembersOperation"] = "PNGetMembersOperation"; + /** + * Update channel members REST API operation. + */ RequestOperation["PNSetMembersOperation"] = "PNSetMembersOperation"; + /** + * Fetch channel memberships REST API operation. + */ RequestOperation["PNGetMembershipsOperation"] = "PNGetMembershipsOperation"; + /** + * Update channel memberships REST API operation. + */ RequestOperation["PNSetMembershipsOperation"] = "PNSetMembershipsOperation"; + // -------------------------------------------------------- + // -------------------- File Upload API ------------------- + // -------------------------------------------------------- + /** + * Fetch list of files sent to the channel REST API operation. + */ RequestOperation["PNListFilesOperation"] = "PNListFilesOperation"; + /** + * Retrieve file upload URL REST API operation. + */ RequestOperation["PNGenerateUploadUrlOperation"] = "PNGenerateUploadUrlOperation"; + /** + * Upload file to the channel REST API operation. + */ RequestOperation["PNPublishFileOperation"] = "PNPublishFileOperation"; + /** + * Publish File Message to the channel REST API operation. + */ RequestOperation["PNPublishFileMessageOperation"] = "PNPublishFileMessageOperation"; + /** + * Retrieve file download URL REST API operation. + */ RequestOperation["PNGetFileUrlOperation"] = "PNGetFileUrlOperation"; + /** + * Download file from the channel REST API operation. + */ RequestOperation["PNDownloadFileOperation"] = "PNDownloadFileOperation"; + /** + * Delete file sent to the channel REST API operation. + */ RequestOperation["PNDeleteFileOperation"] = "PNDeleteFileOperation"; + // -------------------------------------------------------- + // -------------------- Mobile Push API ------------------- + // -------------------------------------------------------- + /** + * Register channels with device push notifications REST API operation. + */ RequestOperation["PNAddPushNotificationEnabledChannelsOperation"] = "PNAddPushNotificationEnabledChannelsOperation"; + /** + * Unregister channels with device push notifications REST API operation. + */ RequestOperation["PNRemovePushNotificationEnabledChannelsOperation"] = "PNRemovePushNotificationEnabledChannelsOperation"; + /** + * Fetch list of channels with enabled push notifications for device REST API operation. + */ RequestOperation["PNPushNotificationEnabledChannelsOperation"] = "PNPushNotificationEnabledChannelsOperation"; + /** + * Disable push notifications for device REST API operation. + */ RequestOperation["PNRemoveAllPushNotificationsOperation"] = "PNRemoveAllPushNotificationsOperation"; + // -------------------------------------------------------- + // ------------------ Channel Groups API ------------------ + // -------------------------------------------------------- + /** + * Fetch channels groups list REST API operation. + */ RequestOperation["PNChannelGroupsOperation"] = "PNChannelGroupsOperation"; + /** + * Remove specified channel group REST API operation. + */ RequestOperation["PNRemoveGroupOperation"] = "PNRemoveGroupOperation"; + /** + * Fetch list of channels for the specified channel group REST API operation. + */ RequestOperation["PNChannelsForGroupOperation"] = "PNChannelsForGroupOperation"; + /** + * Add list of channels to the specified channel group REST API operation. + */ RequestOperation["PNAddChannelsToGroupOperation"] = "PNAddChannelsToGroupOperation"; + /** + * Remove list of channels from the specified channel group REST API operation. + */ RequestOperation["PNRemoveChannelsFromGroupOperation"] = "PNRemoveChannelsFromGroupOperation"; + // -------------------------------------------------------- + // ----------------------- PAM API ------------------------ + // -------------------------------------------------------- + /** + * Generate authorized token REST API operation. + */ RequestOperation["PNAccessManagerGrant"] = "PNAccessManagerGrant"; + /** + * Generate authorized token REST API operation. + */ RequestOperation["PNAccessManagerGrantToken"] = "PNAccessManagerGrantToken"; RequestOperation["PNAccessManagerAudit"] = "PNAccessManagerAudit"; + /** + * Revoke authorized token REST API operation. + */ RequestOperation["PNAccessManagerRevokeToken"] = "PNAccessManagerRevokeToken"; + // + // -------------------------------------------------------- + // ---------------- Subscription Utility ------------------ + // -------------------------------------------------------- RequestOperation["PNHandshakeOperation"] = "PNHandshakeOperation"; RequestOperation["PNReceiveMessagesOperation"] = "PNReceiveMessagesOperation"; })(RequestOperation || (RequestOperation = {})); diff --git a/lib/core/endpoints/access_manager/audit.js b/lib/core/endpoints/access_manager/audit.js index e39aeb6d0..a405e8010 100644 --- a/lib/core/endpoints/access_manager/audit.js +++ b/lib/core/endpoints/access_manager/audit.js @@ -1,4 +1,7 @@ "use strict"; +/** + * PAM Audit REST API module. + */ 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) { @@ -17,13 +20,27 @@ const pubnub_error_1 = require("../../../errors/pubnub-error"); const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Auth keys for which permissions should be audited. + */ const AUTH_KEYS = []; +// endregion +/** + * Permissions audit request. + * + * @internal + */ class AuditRequest extends request_1.AbstractRequest { constructor(parameters) { var _a; var _b; super(); this.parameters = parameters; + // Apply default request parameters. (_a = (_b = this.parameters).authKeys) !== null && _a !== void 0 ? _a : (_b.authKeys = AUTH_KEYS); } operation() { diff --git a/lib/core/endpoints/access_manager/grant.js b/lib/core/endpoints/access_manager/grant.js index dfb15e873..9ed997fae 100644 --- a/lib/core/endpoints/access_manager/grant.js +++ b/lib/core/endpoints/access_manager/grant.js @@ -1,4 +1,7 @@ "use strict"; +/** + * PAM Grant REST API module. + */ 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) { @@ -17,19 +20,51 @@ const pubnub_error_1 = require("../../../errors/pubnub-error"); const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Resources `read` permission. + */ const READ_PERMISSION = false; +/** + * Resources `write` permission. + */ const WRITE_PERMISSION = false; +/** + * Resources `delete` permission. + */ const DELETE_PERMISSION = false; +/** + * Resources `get` permission. + */ const GET_PERMISSION = false; +/** + * Resources `update` permission. + */ const UPDATE_PERMISSION = false; +/** + * Resources `manage` permission. + */ const MANAGE_PERMISSION = false; +/** + * Resources `join` permission. + */ const JOIN_PERMISSION = false; +// endregion +/** + * Grant permissions request. + * + * @internal + */ class GrantRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; super(); this.parameters = parameters; + // Apply defaults. (_a = (_l = this.parameters).channels) !== null && _a !== void 0 ? _a : (_l.channels = []); (_b = (_m = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_m.channelGroups = []); (_c = (_o = this.parameters).uuids) !== null && _c !== void 0 ? _c : (_o.uuids = []); diff --git a/lib/core/endpoints/access_manager/grant_token.js b/lib/core/endpoints/access_manager/grant_token.js index 2c420331f..0eb0cc788 100644 --- a/lib/core/endpoints/access_manager/grant_token.js +++ b/lib/core/endpoints/access_manager/grant_token.js @@ -1,4 +1,7 @@ "use strict"; +/** + * PAM Grant Token REST API module. + */ 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) { @@ -18,12 +21,19 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); +// endregion +/** + * Grant token permissions request. + * + * @internal + */ class GrantTokenRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b; var _c, _d; super({ method: transport_request_1.TransportMethod.POST }); this.parameters = parameters; + // Apply defaults. (_a = (_c = this.parameters).resources) !== null && _a !== void 0 ? _a : (_c.resources = {}); (_b = (_d = this.parameters).patterns) !== null && _b !== void 0 ? _b : (_d.patterns = {}); } @@ -54,6 +64,7 @@ class GrantTokenRequest extends request_1.AbstractRequest { [this.parameters.resources, this.parameters.patterns].forEach((refPerm) => { Object.keys(refPerm !== null && refPerm !== void 0 ? refPerm : {}).forEach((scope) => { var _a; + // @ts-expect-error Permissions with backward compatibility. if (refPerm && permissionsEmpty && Object.keys((_a = refPerm[scope]) !== null && _a !== void 0 ? _a : {}).length > 0) { permissionsEmpty = false; } @@ -103,11 +114,14 @@ class GrantTokenRequest extends request_1.AbstractRequest { target.groups = {}; if (!target.uuids) target.uuids = {}; + // @ts-expect-error Not used, needed for api backward compatibility if (!target.users) target.users = {}; + // @ts-expect-error Not used, needed for api backward compatibility if (!target.spaces) target.spaces = {}; if (refPerm) { + // Check whether working with legacy Objects permissions. if ('spaces' in refPerm || 'users' in refPerm) { channelsPermissions = (_a = refPerm.spaces) !== null && _a !== void 0 ? _a : {}; uuidsPermissions = (_b = refPerm.users) !== null && _b !== void 0 ? _b : {}; @@ -130,6 +144,13 @@ class GrantTokenRequest extends request_1.AbstractRequest { body.permissions = permissions; return JSON.stringify(body); } + /** + * Extract permissions bit from permission configuration object. + * + * @param permissions - User provided scope-based permissions. + * + * @returns Permissions bit. + */ extractPermissions(permissions) { let permissionsResult = 0; if ('join' in permissions && permissions.join) @@ -148,6 +169,13 @@ class GrantTokenRequest extends request_1.AbstractRequest { permissionsResult |= 1; return permissionsResult; } + /** + * Check whether provided parameters is part of legacy VSP access token configuration. + * + * @param parameters - Parameters which should be checked. + * + * @returns VSP request parameters if it is legacy configuration. + */ isVspPermissions(parameters) { var _a, _b, _c, _d; return ('authorizedUserId' in parameters || diff --git a/lib/core/endpoints/access_manager/revoke_token.js b/lib/core/endpoints/access_manager/revoke_token.js index 648136fcc..03b9e4111 100644 --- a/lib/core/endpoints/access_manager/revoke_token.js +++ b/lib/core/endpoints/access_manager/revoke_token.js @@ -1,4 +1,7 @@ "use strict"; +/** + * PAM Revoke Token REST API module. + */ 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) { @@ -19,6 +22,14 @@ const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Access token revoke request. + * + * Invalidate token and permissions which has been granted for it. + * + * @internal + */ class RevokeTokenRequest extends request_1.AbstractRequest { constructor(parameters) { super({ method: transport_request_1.TransportMethod.DELETE }); diff --git a/lib/core/endpoints/actions/add_message_action.js b/lib/core/endpoints/actions/add_message_action.js index 6f82bd0d5..a44be3601 100644 --- a/lib/core/endpoints/actions/add_message_action.js +++ b/lib/core/endpoints/actions/add_message_action.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Add Message Action REST API module. + */ 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) { @@ -19,6 +22,12 @@ const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Add Message Reaction request. + * + * @internal + */ class AddMessageActionRequest extends request_1.AbstractRequest { constructor(parameters) { super({ method: transport_request_1.TransportMethod.POST }); diff --git a/lib/core/endpoints/actions/get_message_actions.js b/lib/core/endpoints/actions/get_message_actions.js index 3a0ffcd86..caad2356c 100644 --- a/lib/core/endpoints/actions/get_message_actions.js +++ b/lib/core/endpoints/actions/get_message_actions.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Get Message Actions REST API module. + */ 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) { @@ -18,6 +21,12 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Fetch channel message actions request. + * + * @internal + */ class GetMessageActionsRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/actions/remove_message_action.js b/lib/core/endpoints/actions/remove_message_action.js index 95d0a1969..9d3c94661 100644 --- a/lib/core/endpoints/actions/remove_message_action.js +++ b/lib/core/endpoints/actions/remove_message_action.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Remove Message Action REST API module. + */ 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) { @@ -19,6 +22,12 @@ const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Remove specific message action request. + * + * @internal + */ class RemoveMessageAction extends request_1.AbstractRequest { constructor(parameters) { super({ method: transport_request_1.TransportMethod.DELETE }); diff --git a/lib/core/endpoints/channel_groups/add_channels.js b/lib/core/endpoints/channel_groups/add_channels.js index aa4720f56..32eedf351 100644 --- a/lib/core/endpoints/channel_groups/add_channels.js +++ b/lib/core/endpoints/channel_groups/add_channels.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Add channel group channels REST API module. + */ 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) { @@ -18,6 +21,12 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Add channel group channels request. + * + * @internal + */ class AddChannelGroupChannelsRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/channel_groups/delete_group.js b/lib/core/endpoints/channel_groups/delete_group.js index e1def77fa..618024148 100644 --- a/lib/core/endpoints/channel_groups/delete_group.js +++ b/lib/core/endpoints/channel_groups/delete_group.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Delete channel group REST API module. + */ 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) { @@ -18,6 +21,12 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Channel group delete request. + * + * @internal + */ class DeleteChannelGroupRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/channel_groups/list_channels.js b/lib/core/endpoints/channel_groups/list_channels.js index 247359860..83101c9e9 100644 --- a/lib/core/endpoints/channel_groups/list_channels.js +++ b/lib/core/endpoints/channel_groups/list_channels.js @@ -1,4 +1,7 @@ "use strict"; +/** + * List channel group channels REST API module. + */ 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) { @@ -18,6 +21,12 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * List Channel Group Channels request. + * + * @internal + */ class ListChannelGroupChannels extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/channel_groups/list_groups.js b/lib/core/endpoints/channel_groups/list_groups.js index 6e8b8b6b1..06deb4a01 100644 --- a/lib/core/endpoints/channel_groups/list_groups.js +++ b/lib/core/endpoints/channel_groups/list_groups.js @@ -1,4 +1,7 @@ "use strict"; +/** + * List All Channel Groups REST API module. + */ 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) { @@ -17,6 +20,12 @@ const pubnub_error_1 = require("../../../errors/pubnub-error"); const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); +// endregion +/** + * List all channel groups request. + * + * @internal + */ class ListChannelGroupsRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/channel_groups/remove_channels.js b/lib/core/endpoints/channel_groups/remove_channels.js index cca35a99f..2afed498b 100644 --- a/lib/core/endpoints/channel_groups/remove_channels.js +++ b/lib/core/endpoints/channel_groups/remove_channels.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Remove channel group channels REST API module. + */ 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) { @@ -18,6 +21,13 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Remove channel group channels request. + * + * @internal + */ +// prettier-ignore class RemoveChannelGroupChannelsRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/fetch_messages.js b/lib/core/endpoints/fetch_messages.js index f3935c84e..dd94e6824 100644 --- a/lib/core/endpoints/fetch_messages.js +++ b/lib/core/endpoints/fetch_messages.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Fetch messages REST API module. + */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -42,17 +45,47 @@ const request_1 = require("../components/request"); const operations_1 = __importDefault(require("../constants/operations")); const History = __importStar(require("../types/api/history")); const utils_1 = require("../utils"); +// -------------------------------------------------------- +// ---------------------- Defaults ------------------------ +// -------------------------------------------------------- +// region Defaults +/** + * Whether verbose logging enabled or not. + */ const LOG_VERBOSITY = false; +/** + * Whether message type should be returned or not. + */ const INCLUDE_MESSAGE_TYPE = true; +/** + * Whether timetokens should be returned as strings by default or not. + */ const STRINGIFY_TIMETOKENS = false; +/** + * Whether message publisher `uuid` should be returned or not. + */ const INCLUDE_UUID = true; +/** + * Default number of messages which can be returned for single channel, and it is maximum as well. + */ const SINGLE_CHANNEL_MESSAGES_COUNT = 100; +/** + * Default number of messages which can be returned for multiple channels or when fetched + * message actions. + */ const MULTIPLE_CHANNELS_MESSAGES_COUNT = 25; +// endregion +/** + * Fetch messages from channels request. + * + * @internal + */ class FetchMessagesRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c, _d, _e; super(); this.parameters = parameters; + // Apply defaults. const includeMessageActions = (_a = parameters.includeMessageActions) !== null && _a !== void 0 ? _a : false; const defaultCount = parameters.channels.length > 1 || includeMessageActions ? MULTIPLE_CHANNELS_MESSAGES_COUNT @@ -94,7 +127,9 @@ class FetchMessagesRequest extends request_1.AbstractRequest { const responseChannels = (_a = serviceResponse.channels) !== null && _a !== void 0 ? _a : {}; const channels = {}; Object.keys(responseChannels).forEach((channel) => { + // Map service response to expected data object type structure. channels[channel] = responseChannels[channel].map((payload) => { + // `null` message type means regular message. if (payload.message_type === null) payload.message_type = History.PubNubMessageType.Message; const processedPayload = this.processPayload(channel, payload); @@ -108,6 +143,8 @@ class FetchMessagesRequest extends request_1.AbstractRequest { if (payload.actions) { const itemWithActions = item; itemWithActions.actions = payload.actions; + // Backward compatibility for existing users. + // TODO: Remove in next release. itemWithActions.data = payload.actions; } if (payload.meta) @@ -131,6 +168,14 @@ class FetchMessagesRequest extends request_1.AbstractRequest { const { start, end, count, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken } = this.parameters; return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeMessageType ? { include_message_type: 'true' } : {})); } + /** + * Parse single channel data entry. + * + * @param channel - Channel for which {@link payload} should be processed. + * @param payload - Source payload which should be processed and parsed to expected type. + * + * @returns + */ processPayload(channel, payload) { const { crypto, logVerbosity } = this.parameters; if (!crypto || typeof payload.message !== 'string') @@ -166,6 +211,13 @@ class FetchMessagesRequest extends request_1.AbstractRequest { } return { payload: decryptedPayload, error }; } + /** + * Check whether `payload` potentially represents file message. + * + * @param payload - Fetched message payload. + * + * @returns `true` if payload can be {@link History#FileMessage|FileMessage}. + */ isFileMessage(payload) { return payload.file !== undefined; } diff --git a/lib/core/endpoints/file_upload/delete_file.js b/lib/core/endpoints/file_upload/delete_file.js index 00f0a40b5..0721e6f0a 100644 --- a/lib/core/endpoints/file_upload/delete_file.js +++ b/lib/core/endpoints/file_upload/delete_file.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Delete file REST API module. + */ 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) { @@ -19,6 +22,12 @@ const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Delete File request. + * + * @internal + */ class DeleteFileRequest extends request_1.AbstractRequest { constructor(parameters) { super({ method: transport_request_1.TransportMethod.DELETE }); diff --git a/lib/core/endpoints/file_upload/download_file.js b/lib/core/endpoints/file_upload/download_file.js index a5d6fae93..fb99ccc31 100644 --- a/lib/core/endpoints/file_upload/download_file.js +++ b/lib/core/endpoints/file_upload/download_file.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Download File REST API module. + */ 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) { @@ -16,6 +19,12 @@ exports.DownloadFileRequest = void 0; const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Download File request. + * + * @internal + */ class DownloadFileRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/file_upload/generate_upload_url.js b/lib/core/endpoints/file_upload/generate_upload_url.js index 4f89bc5c5..9a107a47d 100644 --- a/lib/core/endpoints/file_upload/generate_upload_url.js +++ b/lib/core/endpoints/file_upload/generate_upload_url.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Generate file upload URL REST API request. + */ 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) { @@ -19,6 +22,12 @@ const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Generate File Upload Url request. + * + * @internal + */ class GenerateFileUploadUrlRequest extends request_1.AbstractRequest { constructor(parameters) { super({ method: transport_request_1.TransportMethod.POST }); diff --git a/lib/core/endpoints/file_upload/get_file_url.js b/lib/core/endpoints/file_upload/get_file_url.js index 91879738f..5a17b3ab1 100644 --- a/lib/core/endpoints/file_upload/get_file_url.js +++ b/lib/core/endpoints/file_upload/get_file_url.js @@ -1,4 +1,7 @@ "use strict"; +/** + * File sharing REST API module. + */ 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) { @@ -17,7 +20,20 @@ const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * File download Url generation request. + * + * Local request which generates Url to download shared file from the specific channel. + * + * @internal + */ class GetFileDownloadUrlRequest extends request_1.AbstractRequest { + /** + * Construct file download Url generation request. + * + * @param parameters - Request configuration. + */ constructor(parameters) { super({ method: transport_request_1.TransportMethod.LOCAL }); this.parameters = parameters; diff --git a/lib/core/endpoints/file_upload/list_files.js b/lib/core/endpoints/file_upload/list_files.js index f258331b8..513fe6525 100644 --- a/lib/core/endpoints/file_upload/list_files.js +++ b/lib/core/endpoints/file_upload/list_files.js @@ -1,4 +1,7 @@ "use strict"; +/** + * List Files REST API module. + */ 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) { @@ -18,13 +21,27 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Number of files to return in response. + */ const LIMIT = 100; +// endregion +/** + * Files List request. + * + * @internal + */ class FilesListRequest extends request_1.AbstractRequest { constructor(parameters) { var _a; var _b; super(); this.parameters = parameters; + // Apply default request parameters. (_a = (_b = this.parameters).limit) !== null && _a !== void 0 ? _a : (_b.limit = LIMIT); } operation() { diff --git a/lib/core/endpoints/file_upload/publish_file.js b/lib/core/endpoints/file_upload/publish_file.js index f69228964..20c6d4c63 100644 --- a/lib/core/endpoints/file_upload/publish_file.js +++ b/lib/core/endpoints/file_upload/publish_file.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Publish File Message REST API module. + */ 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) { @@ -18,13 +21,27 @@ const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const base64_codec_1 = require("../../components/base64_codec"); const utils_1 = require("../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether published file messages should be stored in the channel's history. + */ const STORE_IN_HISTORY = true; +// endregion +/** + * Publish shared file information request. + * + * @internal + */ class PublishFileMessageRequest extends request_1.AbstractRequest { constructor(parameters) { var _a; var _b; super(); this.parameters = parameters; + // Apply default request parameters. (_a = (_b = this.parameters).storeInHistory) !== null && _a !== void 0 ? _a : (_b.storeInHistory = STORE_IN_HISTORY); } operation() { @@ -59,6 +76,17 @@ class PublishFileMessageRequest extends request_1.AbstractRequest { const { storeInHistory, ttl, meta } = this.parameters; return Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {})); } + /** + * Pre-process provided data. + * + * Data will be "normalized" and encrypted if `cryptoModule` has been provided. + * + * @param payload - User-provided data which should be pre-processed before use. + * + * @returns Payload which can be used as part of request URL or body. + * + * @throws {Error} in case if provided `payload` or results of `encryption` can't be stringified. + */ prepareMessagePayload(payload) { const { crypto } = this.parameters; if (!crypto) diff --git a/lib/core/endpoints/file_upload/send_file.js b/lib/core/endpoints/file_upload/send_file.js index ca036ee19..5041464d5 100644 --- a/lib/core/endpoints/file_upload/send_file.js +++ b/lib/core/endpoints/file_upload/send_file.js @@ -19,6 +19,12 @@ const operations_1 = __importDefault(require("../../constants/operations")); const upload_file_1 = require("./upload-file"); const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const categories_1 = __importDefault(require("../../constants/categories")); +// endregion +/** + * Send file composed request. + * + * @internal + */ class SendFileRequest { constructor(parameters) { var _a; @@ -27,6 +33,11 @@ class SendFileRequest { if (!this.file) throw new Error('File upload error: unable to create File object.'); } + /** + * Process user-input and upload file. + * + * @returns File upload request response. + */ process() { return __awaiter(this, void 0, void 0, function* () { let fileName; @@ -57,16 +68,29 @@ class SendFileRequest { }); }); } + /** + * Generate pre-signed file upload Url. + * + * @returns File upload credentials. + */ generateFileUploadUrl() { return __awaiter(this, void 0, void 0, function* () { const request = new generate_upload_url_1.GenerateFileUploadUrlRequest(Object.assign(Object.assign({}, this.parameters), { name: this.file.name, keySet: this.parameters.keySet })); return this.parameters.sendRequest(request); }); } + /** + * Prepare and upload {@link PubNub} File object to remote storage. + * + * @param uploadParameters - File upload request parameters. + * + * @returns + */ uploadFile(uploadParameters) { return __awaiter(this, void 0, void 0, function* () { const { cipherKey, PubNubFile, crypto, cryptography } = this.parameters; const { id, name, url, formFields } = uploadParameters; + // Encrypt file if possible. if (this.parameters.PubNubFile.supportsEncryptFile) { if (!cipherKey && crypto) this.file = (yield crypto.encryptFile(this.file, PubNubFile)); diff --git a/lib/core/endpoints/file_upload/upload-file.js b/lib/core/endpoints/file_upload/upload-file.js index fefdb0f2b..15546c973 100644 --- a/lib/core/endpoints/file_upload/upload-file.js +++ b/lib/core/endpoints/file_upload/upload-file.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Upload file REST API request. + */ 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) { @@ -16,10 +19,16 @@ exports.UploadFileRequest = void 0; const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); +/** + * File Upload request. + * + * @internal + */ class UploadFileRequest extends request_1.AbstractRequest { constructor(parameters) { super({ method: transport_request_1.TransportMethod.POST }); this.parameters = parameters; + // Use file's actual mime type if available. const mimeType = parameters.file.mimeType; if (mimeType) { parameters.formFields = parameters.formFields.map((entry) => { diff --git a/lib/core/endpoints/history/delete_messages.js b/lib/core/endpoints/history/delete_messages.js index 6556ff638..3c4814a80 100644 --- a/lib/core/endpoints/history/delete_messages.js +++ b/lib/core/endpoints/history/delete_messages.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Delete messages REST API module. + */ 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) { @@ -19,6 +22,12 @@ const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Delete messages from channel history. + * + * @internal + */ class DeleteMessageRequest extends request_1.AbstractRequest { constructor(parameters) { super({ method: transport_request_1.TransportMethod.DELETE }); diff --git a/lib/core/endpoints/history/get_history.js b/lib/core/endpoints/history/get_history.js index 02691675a..ff6c28dd7 100644 --- a/lib/core/endpoints/history/get_history.js +++ b/lib/core/endpoints/history/get_history.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Get history REST API module. + */ 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) { @@ -17,15 +20,38 @@ const pubnub_error_1 = require("../../../errors/pubnub-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// -------------------------------------------------------- +// ---------------------- Defaults ------------------------ +// -------------------------------------------------------- +// region Defaults +/** + * Whether verbose logging enabled or not. + */ const LOG_VERBOSITY = false; +/** + * Whether associated message metadata should be returned or not. + */ const INCLUDE_METADATA = false; +/** + * Whether timetokens should be returned as strings by default or not. + */ const STRINGIFY_TIMETOKENS = false; +/** + * Default and maximum number of messages which should be returned. + */ const MESSAGES_COUNT = 100; +// endregion +/** + * Get single channel messages request. + * + * @internal + */ class GetHistoryRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c; super(); this.parameters = parameters; + // Apply defaults. if (parameters.count) parameters.count = Math.min(parameters.count, MESSAGES_COUNT); else @@ -51,6 +77,7 @@ class GetHistoryRequest extends request_1.AbstractRequest { const messages = serviceResponse[0]; const startTimeToken = serviceResponse[1]; const endTimeToken = serviceResponse[2]; + // Handle malformed get history response. if (!Array.isArray(messages)) return { messages: [], startTimeToken, endTimeToken }; return { diff --git a/lib/core/endpoints/history/message_counts.js b/lib/core/endpoints/history/message_counts.js index 66fb9ec0c..d8641eede 100644 --- a/lib/core/endpoints/history/message_counts.js +++ b/lib/core/endpoints/history/message_counts.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Messages count REST API module. + */ 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) { @@ -18,6 +21,12 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Count messages request. + * + * @internal + */ class MessageCountRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/objects/channel/get.js b/lib/core/endpoints/objects/channel/get.js index d7c3b86ed..aa5b1830d 100644 --- a/lib/core/endpoints/objects/channel/get.js +++ b/lib/core/endpoints/objects/channel/get.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Get Channel Metadata REST API module. + */ 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) { @@ -18,13 +21,27 @@ const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `Channel` custom field should be included by default or not. + */ const INCLUDE_CUSTOM_FIELDS = true; +// endregion +/** + * Get Channel Metadata request. + * + * @internal + */ class GetChannelMetadataRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b; var _c; super(); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); } diff --git a/lib/core/endpoints/objects/channel/get_all.js b/lib/core/endpoints/objects/channel/get_all.js index 228568d77..3019266fd 100644 --- a/lib/core/endpoints/objects/channel/get_all.js +++ b/lib/core/endpoints/objects/channel/get_all.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Get All Channel Metadata REST API module. + */ 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) { @@ -17,15 +20,35 @@ const pubnub_error_1 = require("../../../../errors/pubnub-error"); const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `Channel` custom fields should be included in response or not. + */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Whether total number of channels should be included in response or not. + */ const INCLUDE_TOTAL_COUNT = false; +/** + * Number of objects to return in response. + */ const LIMIT = 100; +// endregion +/** + * Get All Channels Metadata request. + * + * @internal + */ class GetAllChannelsMetadataRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c, _d; var _e, _f; super(); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_e = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_e.customFields = INCLUDE_CUSTOM_FIELDS); (_c = (_f = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_f.totalCount = INCLUDE_TOTAL_COUNT); diff --git a/lib/core/endpoints/objects/channel/remove.js b/lib/core/endpoints/objects/channel/remove.js index 725b652ad..2b0db8890 100644 --- a/lib/core/endpoints/objects/channel/remove.js +++ b/lib/core/endpoints/objects/channel/remove.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Remove Channel Metadata REST API module. + */ 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) { @@ -19,6 +22,12 @@ const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// endregion +/** + * Remove Channel Metadata request. + * + * @internal + */ class RemoveChannelMetadataRequest extends request_1.AbstractRequest { constructor(parameters) { super({ method: transport_request_1.TransportMethod.DELETE }); diff --git a/lib/core/endpoints/objects/channel/set.js b/lib/core/endpoints/objects/channel/set.js index 6d903debb..b127ac4c1 100644 --- a/lib/core/endpoints/objects/channel/set.js +++ b/lib/core/endpoints/objects/channel/set.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Set Channel Metadata REST API module. + */ 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) { @@ -19,13 +22,27 @@ const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `Channel` custom field should be included by default or not. + */ const INCLUDE_CUSTOM_FIELDS = true; +// endregion +/** + * Set Channel Metadata request. + * + * @internal + */ class SetChannelMetadataRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b; var _c; super({ method: transport_request_1.TransportMethod.PATCH }); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); } diff --git a/lib/core/endpoints/objects/member/get.js b/lib/core/endpoints/objects/member/get.js index 4329df0fc..348855612 100644 --- a/lib/core/endpoints/objects/member/get.js +++ b/lib/core/endpoints/objects/member/get.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Get Channel Members REST API module. + */ 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) { @@ -18,20 +21,55 @@ const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `Member` custom field should be included in response or not. + */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Whether member's status field should be included in response or not. + */ const INCLUDE_STATUS = false; +/** + * Whether total number of members should be included in response or not. + */ const INCLUDE_TOTAL_COUNT = false; +/** + * Whether `UUID` fields should be included in response or not. + */ const INCLUDE_UUID_FIELDS = false; +/** + * Whether `UUID` status field should be included in response or not. + */ const INCLUDE_UUID_STATUS_FIELD = false; +/** + * Whether `UUID` type field should be included in response or not. + */ const INCLUDE_UUID_TYPE_FIELD = false; +/** + * Whether `UUID` custom field should be included in response or not. + */ const INCLUDE_UUID_CUSTOM_FIELDS = false; +/** + * Number of objects to return in response. + */ const LIMIT = 100; +// endregion +/** + * Get Channel Members request. + * + * @internal + */ class GetChannelMembersRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c, _d, _e, _f, _g, _h, _j; var _k, _l, _m, _o, _p, _q, _r; super(); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS); (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT); diff --git a/lib/core/endpoints/objects/member/set.js b/lib/core/endpoints/objects/member/set.js index 6d6ba7cb5..344469b01 100644 --- a/lib/core/endpoints/objects/member/set.js +++ b/lib/core/endpoints/objects/member/set.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Set Channel Members REST API module. + */ 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) { @@ -19,17 +22,43 @@ const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `Member` custom field should be included in response or not. + */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Whether total number of members should be included in response or not. + */ const INCLUDE_TOTAL_COUNT = false; +/** + * Whether `UUID` fields should be included in response or not. + */ const INCLUDE_UUID_FIELDS = false; +/** + * Whether `UUID` custom field should be included in response or not. + */ const INCLUDE_UUID_CUSTOM_FIELDS = false; +/** + * Number of objects to return in response. + */ const LIMIT = 100; +// endregion +/** + * Set Channel Members request. + * + * @internal + */ class SetChannelMembersRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c, _d, _e, _f; var _g, _h, _j, _k; super({ method: transport_request_1.TransportMethod.PATCH }); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS); (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT); diff --git a/lib/core/endpoints/objects/membership/get.js b/lib/core/endpoints/objects/membership/get.js index bc588f76c..7444536f2 100644 --- a/lib/core/endpoints/objects/membership/get.js +++ b/lib/core/endpoints/objects/membership/get.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Get UUID Memberships REST API module. + */ 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) { @@ -18,20 +21,55 @@ const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `Membership` custom field should be included in response or not. + */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Whether membership's status field should be included in response or not. + */ const INCLUDE_STATUS = false; +/** + * Whether total number of memberships should be included in response or not. + */ const INCLUDE_TOTAL_COUNT = false; +/** + * Whether `Channel` fields should be included in response or not. + */ const INCLUDE_CHANNEL_FIELDS = false; +/** + * Whether `Channel` status field should be included in response or not. + */ const INCLUDE_CHANNEL_STATUS_FIELD = false; +/** + * Whether `Channel` type field should be included in response or not. + */ const INCLUDE_CHANNEL_TYPE_FIELD = false; +/** + * Whether `Channel` custom field should be included in response or not. + */ const INCLUDE_CHANNEL_CUSTOM_FIELDS = false; +/** + * Number of objects to return in response. + */ const LIMIT = 100; +// endregion +/** + * Get UUID Memberships request. + * + * @internal + */ class GetUUIDMembershipsRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c, _d, _e, _f, _g, _h, _j; var _k, _l, _m, _o, _p, _q, _r; super(); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS); (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT); @@ -41,6 +79,7 @@ class GetUUIDMembershipsRequest extends request_1.AbstractRequest { (_g = (_q = parameters.include).channelStatusField) !== null && _g !== void 0 ? _g : (_q.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD); (_h = (_r = parameters.include).channelTypeField) !== null && _h !== void 0 ? _h : (_r.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD); (_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT); + // Remap for backward compatibility. if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; } diff --git a/lib/core/endpoints/objects/membership/set.js b/lib/core/endpoints/objects/membership/set.js index 10aaa32e3..9ed9fcabe 100644 --- a/lib/core/endpoints/objects/membership/set.js +++ b/lib/core/endpoints/objects/membership/set.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Set UUID Memberships REST API module. + */ 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) { @@ -19,23 +22,50 @@ const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `Membership` custom field should be included in response or not. + */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Whether total number of memberships should be included in response or not. + */ const INCLUDE_TOTAL_COUNT = false; +/** + * Whether `Channel` fields should be included in response or not. + */ const INCLUDE_CHANNEL_FIELDS = false; +/** + * Whether `Channel` custom field should be included in response or not. + */ const INCLUDE_CHANNEL_CUSTOM_FIELDS = false; +/** + * Number of objects to return in response. + */ const LIMIT = 100; +// endregion +/** + * Set UUID Memberships request. + * + * @internal + */ class SetUUIDMembershipsRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c, _d, _e, _f; var _g, _h, _j, _k; super({ method: transport_request_1.TransportMethod.PATCH }); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS); (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT); (_d = (_j = parameters.include).channelFields) !== null && _d !== void 0 ? _d : (_j.channelFields = INCLUDE_CHANNEL_FIELDS); (_e = (_k = parameters.include).customChannelFields) !== null && _e !== void 0 ? _e : (_k.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); (_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT); + // Remap for backward compatibility. if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; } diff --git a/lib/core/endpoints/objects/uuid/get.js b/lib/core/endpoints/objects/uuid/get.js index 56383f4dd..b0f5135c8 100644 --- a/lib/core/endpoints/objects/uuid/get.js +++ b/lib/core/endpoints/objects/uuid/get.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Get UUID Metadata REST API module. + */ 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) { @@ -18,15 +21,30 @@ const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether UUID custom field should be included by default or not. + */ const INCLUDE_CUSTOM_FIELDS = true; +// endregion +/** + * Get UUID Metadata request. + * + * @internal + */ class GetUUIDMetadataRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b; var _c; super(); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); + // Remap for backward compatibility. if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; } diff --git a/lib/core/endpoints/objects/uuid/get_all.js b/lib/core/endpoints/objects/uuid/get_all.js index eae9bce3b..778084b0f 100644 --- a/lib/core/endpoints/objects/uuid/get_all.js +++ b/lib/core/endpoints/objects/uuid/get_all.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Get All UUID Metadata REST API module. + */ 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) { @@ -17,14 +20,31 @@ const pubnub_error_1 = require("../../../../errors/pubnub-error"); const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `Channel` custom field should be included by default or not. + */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Number of objects to return in response. + */ const LIMIT = 100; +// endregion +/** + * Get All UUIDs Metadata request. + * + * @internal + */ class GetAllUUIDMetadataRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c; var _d; super(); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_d = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_d.customFields = INCLUDE_CUSTOM_FIELDS); (_c = parameters.limit) !== null && _c !== void 0 ? _c : (parameters.limit = LIMIT); diff --git a/lib/core/endpoints/objects/uuid/remove.js b/lib/core/endpoints/objects/uuid/remove.js index 9268a7792..09025de72 100644 --- a/lib/core/endpoints/objects/uuid/remove.js +++ b/lib/core/endpoints/objects/uuid/remove.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Remove UUID Metadata REST API module. + */ 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) { @@ -19,10 +22,17 @@ const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// endregion +/** + * Remove UUID Metadata request. + * + * @internal + */ class RemoveUUIDMetadataRequest extends request_1.AbstractRequest { constructor(parameters) { super({ method: transport_request_1.TransportMethod.DELETE }); this.parameters = parameters; + // Remap for backward compatibility. if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; } diff --git a/lib/core/endpoints/objects/uuid/set.js b/lib/core/endpoints/objects/uuid/set.js index 075c97b74..cdc3252e0 100644 --- a/lib/core/endpoints/objects/uuid/set.js +++ b/lib/core/endpoints/objects/uuid/set.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Set UUID Metadata REST API module. + */ 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) { @@ -19,15 +22,30 @@ const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `Channel` custom field should be included by default or not. + */ const INCLUDE_CUSTOM_FIELDS = true; +// endregion +/** + * Set UUID Metadata request. + * + * @internal + */ class SetUUIDMetadataRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b; var _c; super({ method: transport_request_1.TransportMethod.PATCH }); this.parameters = parameters; + // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); (_b = (_c = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_c.customFields = INCLUDE_CUSTOM_FIELDS); + // Remap for backward compatibility. if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; } diff --git a/lib/core/endpoints/presence/get_state.js b/lib/core/endpoints/presence/get_state.js index 8373628e2..76f447c62 100644 --- a/lib/core/endpoints/presence/get_state.js +++ b/lib/core/endpoints/presence/get_state.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Get Presence State REST API module. + */ 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) { @@ -18,12 +21,19 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Get `uuid` presence state request. + * + * @internal + */ class GetPresenceStateRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b; var _c, _d; super(); this.parameters = parameters; + // Apply defaults. (_a = (_c = this.parameters).channels) !== null && _a !== void 0 ? _a : (_c.channels = []); (_b = (_d = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_d.channelGroups = []); } diff --git a/lib/core/endpoints/presence/heartbeat.js b/lib/core/endpoints/presence/heartbeat.js index 52de83f8e..d5925a85c 100644 --- a/lib/core/endpoints/presence/heartbeat.js +++ b/lib/core/endpoints/presence/heartbeat.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Announce heartbeat REST API module. + */ 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) { @@ -18,6 +21,12 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Announce `uuid` presence request. + * + * @internal + */ class HeartbeatRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/presence/here_now.js b/lib/core/endpoints/presence/here_now.js index 6900d5929..fd8319701 100644 --- a/lib/core/endpoints/presence/here_now.js +++ b/lib/core/endpoints/presence/here_now.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Channels / channel groups presence REST API module. + */ 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) { @@ -18,14 +21,31 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether `uuid` should be included in response or not. + */ const INCLUDE_UUID = true; +/** + * Whether state associated with `uuid` should be included in response or not. + */ const INCLUDE_STATE = false; +// endregion +/** + * Channel presence request. + * + * @internal + */ class HereNowRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c; var _d, _e, _f; super(); this.parameters = parameters; + // Apply defaults. (_a = (_d = this.parameters).queryParameters) !== null && _a !== void 0 ? _a : (_d.queryParameters = {}); (_b = (_e = this.parameters).includeUUIDs) !== null && _b !== void 0 ? _b : (_e.includeUUIDs = INCLUDE_UUID); (_c = (_f = this.parameters).includeState) !== null && _c !== void 0 ? _c : (_f.includeState = INCLUDE_STATE); @@ -49,10 +69,12 @@ class HereNowRequest extends request_1.AbstractRequest { } else if (serviceResponse.status >= 400) throw pubnub_api_error_1.PubNubAPIError.create(response); + // Extract general presence information. const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; const totalOccupancy = 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_channels; const channelsPresence = {}; let channels = {}; + // Remap single channel presence to multiple channels presence response. if ('occupancy' in serviceResponse) { const channel = this.parameters.channels[0]; channels[channel] = { uuids: (_a = serviceResponse.uuids) !== null && _a !== void 0 ? _a : [], occupancy: totalOccupancy }; diff --git a/lib/core/endpoints/presence/leave.js b/lib/core/endpoints/presence/leave.js index ec29564ba..fd06272b6 100644 --- a/lib/core/endpoints/presence/leave.js +++ b/lib/core/endpoints/presence/leave.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Announce leave REST API module. + */ 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) { @@ -18,6 +21,12 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Announce user leave request. + * + * @internal + */ class PresenceLeaveRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/presence/set_state.js b/lib/core/endpoints/presence/set_state.js index 8ecfd935d..faba64205 100644 --- a/lib/core/endpoints/presence/set_state.js +++ b/lib/core/endpoints/presence/set_state.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Set Presence State REST API module. + */ 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) { @@ -18,6 +21,12 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Set `uuid` presence state request. + * + * @internal + */ class SetPresenceStateRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/presence/where_now.js b/lib/core/endpoints/presence/where_now.js index a536e143b..daa44632f 100644 --- a/lib/core/endpoints/presence/where_now.js +++ b/lib/core/endpoints/presence/where_now.js @@ -1,4 +1,7 @@ "use strict"; +/** + * `uuid` presence REST API module. + */ 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) { @@ -18,6 +21,12 @@ const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); +// endregion +/** + * Get `uuid` presence request. + * + * @internal + */ class WhereNowRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/publish.js b/lib/core/endpoints/publish.js index cd5d55ffb..1a38b0aa9 100644 --- a/lib/core/endpoints/publish.js +++ b/lib/core/endpoints/publish.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Publish REST API module. + */ 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) { @@ -19,13 +22,35 @@ const request_1 = require("../components/request"); const operations_1 = __importDefault(require("../constants/operations")); const base64_codec_1 = require("../components/base64_codec"); const utils_1 = require("../utils"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether data is published used `POST` body or not. + */ const SEND_BY_POST = false; +// endregion +/** + * Data publish request. + * + * Request will normalize and encrypt (if required) provided data and push it to the specified + * channel. + * + * @internal + */ class PublishRequest extends request_1.AbstractRequest { + /** + * Construct data publish request. + * + * @param parameters - Request configuration. + */ constructor(parameters) { var _a; var _b; super({ method: parameters.sendByPost ? transport_request_1.TransportMethod.POST : transport_request_1.TransportMethod.GET }); this.parameters = parameters; + // Apply default request parameters. (_a = (_b = this.parameters).sendByPost) !== null && _a !== void 0 ? _a : (_b.sendByPost = SEND_BY_POST); } operation() { @@ -72,6 +97,17 @@ class PublishRequest extends request_1.AbstractRequest { get body() { return this.prepareMessagePayload(this.parameters.message); } + /** + * Pre-process provided data. + * + * Data will be "normalized" and encrypted if `cryptoModule` has been provided. + * + * @param payload - User-provided data which should be pre-processed before use. + * + * @returns Payload which can be used as part of request URL or body. + * + * @throws {Error} in case if provided `payload` or results of `encryption` can't be stringified. + */ prepareMessagePayload(payload) { const { crypto } = this.parameters; if (!crypto) diff --git a/lib/core/endpoints/push/add_push_channels.js b/lib/core/endpoints/push/add_push_channels.js index 7e6ca21d2..9cc2257b0 100644 --- a/lib/core/endpoints/push/add_push_channels.js +++ b/lib/core/endpoints/push/add_push_channels.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Register Channels with Device push REST API module. + */ 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) { @@ -16,6 +19,13 @@ exports.AddDevicePushNotificationChannelsRequest = void 0; const pubnub_error_1 = require("../../../errors/pubnub-error"); const push_1 = require("./push"); const operations_1 = __importDefault(require("../../constants/operations")); +// endregion +/** + * Register channels with device push request. + * + * @internal + */ +// prettier-ignore class AddDevicePushNotificationChannelsRequest extends push_1.BasePushNotificationChannelsRequest { constructor(parameters) { super(Object.assign(Object.assign({}, parameters), { action: 'add' })); diff --git a/lib/core/endpoints/push/list_push_channels.js b/lib/core/endpoints/push/list_push_channels.js index 355026b81..0f55b55c2 100644 --- a/lib/core/endpoints/push/list_push_channels.js +++ b/lib/core/endpoints/push/list_push_channels.js @@ -1,4 +1,7 @@ "use strict"; +/** + * List Device push enabled channels REST API module. + */ 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) { @@ -16,6 +19,13 @@ exports.ListDevicePushNotificationChannelsRequest = void 0; const pubnub_error_1 = require("../../../errors/pubnub-error"); const push_1 = require("./push"); const operations_1 = __importDefault(require("../../constants/operations")); +// endregion +/** + * List device push enabled channels request. + * + * @internal + */ +// prettier-ignore class ListDevicePushNotificationChannelsRequest extends push_1.BasePushNotificationChannelsRequest { constructor(parameters) { super(Object.assign(Object.assign({}, parameters), { action: 'list' })); diff --git a/lib/core/endpoints/push/push.js b/lib/core/endpoints/push/push.js index 82c63aab4..5bd84beff 100644 --- a/lib/core/endpoints/push/push.js +++ b/lib/core/endpoints/push/push.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Manage channels enabled for device push REST API module. + */ 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) { @@ -11,14 +14,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); exports.BasePushNotificationChannelsRequest = void 0; const request_1 = require("../../components/request"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Environment for which APNS2 notifications + */ const ENVIRONMENT = 'development'; +/** + * Maximum number of channels in `list` response. + */ const MAX_COUNT = 1000; +// endregion +/** + * Base push notification request. + * + * @internal + */ class BasePushNotificationChannelsRequest extends request_1.AbstractRequest { constructor(parameters) { var _a; var _b; super(); this.parameters = parameters; + // Apply request defaults if (this.parameters.pushGateway === 'apns2') (_a = (_b = this.parameters).environment) !== null && _a !== void 0 ? _a : (_b.environment = ENVIRONMENT); if (this.parameters.count && this.parameters.count > MAX_COUNT) diff --git a/lib/core/endpoints/push/remove_device.js b/lib/core/endpoints/push/remove_device.js index 4e71bc5ce..d3857c1fa 100644 --- a/lib/core/endpoints/push/remove_device.js +++ b/lib/core/endpoints/push/remove_device.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Unregister Device push REST API module. + */ 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) { @@ -16,6 +19,13 @@ exports.RemoveDevicePushNotificationRequest = void 0; const pubnub_error_1 = require("../../../errors/pubnub-error"); const push_1 = require("./push"); const operations_1 = __importDefault(require("../../constants/operations")); +// endregion +/** + * Unregister device push notifications request. + * + * @internal + */ +// prettier-ignore class RemoveDevicePushNotificationRequest extends push_1.BasePushNotificationChannelsRequest { constructor(parameters) { super(Object.assign(Object.assign({}, parameters), { action: 'remove-device' })); diff --git a/lib/core/endpoints/push/remove_push_channels.js b/lib/core/endpoints/push/remove_push_channels.js index 96d179ae7..7243bd2bd 100644 --- a/lib/core/endpoints/push/remove_push_channels.js +++ b/lib/core/endpoints/push/remove_push_channels.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Unregister Channels from Device push REST API module. + */ 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) { @@ -16,6 +19,13 @@ exports.RemoveDevicePushNotificationChannelsRequest = void 0; const pubnub_error_1 = require("../../../errors/pubnub-error"); const push_1 = require("./push"); const operations_1 = __importDefault(require("../../constants/operations")); +// endregion +/** + * Unregister channels from device push request. + * + * @internal + */ +// prettier-ignore class RemoveDevicePushNotificationChannelsRequest extends push_1.BasePushNotificationChannelsRequest { constructor(parameters) { super(Object.assign(Object.assign({}, parameters), { action: 'remove' })); diff --git a/lib/core/endpoints/signal.js b/lib/core/endpoints/signal.js index ad60cb35e..e3e5ea344 100644 --- a/lib/core/endpoints/signal.js +++ b/lib/core/endpoints/signal.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Signal REST API module. + */ 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) { @@ -17,6 +20,12 @@ const pubnub_error_1 = require("../../errors/pubnub-error"); const request_1 = require("../components/request"); const operations_1 = __importDefault(require("../constants/operations")); const utils_1 = require("../utils"); +// endregion +/** + * Signal data (size-limited) publish request. + * + * @internal + */ class SignalRequest extends request_1.AbstractRequest { constructor(parameters) { super(); diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index 2588611e4..846186b5f 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Subscription REST API module. + */ 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) { @@ -17,22 +20,70 @@ const pubnub_error_1 = require("../../errors/pubnub-error"); const request_1 = require("../components/request"); const operations_1 = __importDefault(require("../constants/operations")); const utils_1 = require("../utils"); +// -------------------------------------------------------- +// ---------------------- Defaults ------------------------ +// -------------------------------------------------------- +// region Defaults +/** + * Whether should subscribe to channels / groups presence announcements or not. + */ const WITH_PRESENCE = false; +// endregion +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types +/** + * PubNub-defined event types by payload. + * + * @internal + */ var PubNubEventType; (function (PubNubEventType) { + /** + * Presence change event. + */ PubNubEventType[PubNubEventType["Presence"] = -2] = "Presence"; + /** + * Regular message event. + * + * **Note:** This is default type assigned for non-presence events if `e` field is missing. + */ PubNubEventType[PubNubEventType["Message"] = -1] = "Message"; + /** + * Signal data event. + */ PubNubEventType[PubNubEventType["Signal"] = 1] = "Signal"; + /** + * App Context object event. + */ PubNubEventType[PubNubEventType["AppContext"] = 2] = "AppContext"; + /** + * Message reaction event. + */ PubNubEventType[PubNubEventType["MessageAction"] = 3] = "MessageAction"; + /** + * Files event. + */ PubNubEventType[PubNubEventType["Files"] = 4] = "Files"; })(PubNubEventType || (exports.PubNubEventType = PubNubEventType = {})); +// endregion +/** + * Base subscription request implementation. + * + * Subscription request used in small variations in two cases: + * - subscription manager + * - event engine + * + * @internal + */ class BaseSubscribeRequest extends request_1.AbstractRequest { constructor(parameters) { var _a, _b, _c; var _d, _e, _f; super({ cancellable: true }); this.parameters = parameters; + // Apply default request parameters. (_a = (_d = this.parameters).withPresence) !== null && _a !== void 0 ? _a : (_d.withPresence = WITH_PRESENCE); (_b = (_e = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_e.channelGroups = []); (_c = (_f = this.parameters).channels) !== null && _c !== void 0 ? _c : (_f.channels = []); @@ -63,7 +114,9 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { } const events = serviceResponse.m.map((envelope) => { let { e: eventType } = envelope; + // Resolve missing event type. eventType !== null && eventType !== void 0 ? eventType : (eventType = envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message); + // Check whether payload is string (potentially encrypted data). if (typeof envelope.d === 'string') { if (eventType == PubNubEventType.Message) { return { @@ -120,13 +173,20 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { get headers() { return { accept: 'text/javascript' }; } + // -------------------------------------------------------- + // ------------------ Envelope parsing -------------------- + // -------------------------------------------------------- + // region Envelope parsing presenceEventFromEnvelope(envelope) { const { d: payload } = envelope; const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); + // Clean up channel and subscription name from presence suffix. const trimmedChannel = channel.replace('-pnpres', ''); + // Backward compatibility with deprecated properties. const actualChannel = subscription !== null ? trimmedChannel : null; const subscribedChannel = subscription !== null ? subscription : trimmedChannel; if (typeof payload !== 'string' && 'data' in payload) { + // @ts-expect-error This is `state-change` object which should have `state` field. payload['state'] = payload.data; delete payload.data; } @@ -137,8 +197,10 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { messageFromEnvelope(envelope) { const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); const [message, decryptionError] = this.decryptedData(envelope.d); + // Backward compatibility with deprecated properties. const actualChannel = subscription !== null ? channel : null; const subscribedChannel = subscription !== null ? subscription : channel; + // Basic message event payload. const event = { channel, subscription, @@ -193,6 +255,7 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); const [file, decryptionError] = this.decryptedData(envelope.d); let errorMessage = decryptionError; + // Basic file event payload. const event = { channel, subscription, @@ -219,9 +282,17 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { event.error = errorMessage; return event; } + // endregion subscriptionChannelFromEnvelope(envelope) { return [envelope.c, envelope.b === undefined ? envelope.c : envelope.b]; } + /** + * Decrypt provided `data`. + * + * @param [data] - Message or file information which should be decrypted if possible. + * + * @returns Tuple with decrypted data and decryption error (if any). + */ decryptedData(data) { if (!this.parameters.crypto || typeof data !== 'string') return [data, undefined]; @@ -242,6 +313,11 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { } } exports.BaseSubscribeRequest = BaseSubscribeRequest; +/** + * Subscribe request. + * + * @internal + */ class SubscribeRequest extends BaseSubscribeRequest { get path() { var _a; diff --git a/lib/core/endpoints/subscriptionUtils/handshake.js b/lib/core/endpoints/subscriptionUtils/handshake.js index 36e175b4d..fc13544b4 100644 --- a/lib/core/endpoints/subscriptionUtils/handshake.js +++ b/lib/core/endpoints/subscriptionUtils/handshake.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Handshake subscribe REST API module. + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -7,6 +10,13 @@ exports.HandshakeSubscribeRequest = void 0; const operations_1 = __importDefault(require("../../constants/operations")); const subscribe_1 = require("../subscribe"); const utils_1 = require("../../utils"); +/** + * Handshake subscribe request. + * + * Separate subscribe request required by Event Engine. + * + * @internal + */ class HandshakeSubscribeRequest extends subscribe_1.BaseSubscribeRequest { operation() { return operations_1.default.PNHandshakeOperation; diff --git a/lib/core/endpoints/subscriptionUtils/receiveMessages.js b/lib/core/endpoints/subscriptionUtils/receiveMessages.js index c78a73f84..f597d82fd 100644 --- a/lib/core/endpoints/subscriptionUtils/receiveMessages.js +++ b/lib/core/endpoints/subscriptionUtils/receiveMessages.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Receive messages subscribe REST API module. + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -7,6 +10,11 @@ exports.ReceiveMessagesSubscribeRequest = void 0; const operations_1 = __importDefault(require("../../constants/operations")); const subscribe_1 = require("../subscribe"); const utils_1 = require("../../utils"); +/** + * Receive messages subscribe request. + * + * @internal + */ class ReceiveMessagesSubscribeRequest extends subscribe_1.BaseSubscribeRequest { operation() { return operations_1.default.PNReceiveMessagesOperation; diff --git a/lib/core/endpoints/time.js b/lib/core/endpoints/time.js index a09d61681..ce2e5a3a6 100644 --- a/lib/core/endpoints/time.js +++ b/lib/core/endpoints/time.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Time REST API module. + */ 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) { @@ -16,6 +19,12 @@ exports.TimeRequest = void 0; const pubnub_error_1 = require("../../errors/pubnub-error"); const request_1 = require("../components/request"); const operations_1 = __importDefault(require("../constants/operations")); +// endregion +/** + * Get current PubNub high-precision time request. + * + * @internal + */ class TimeRequest extends request_1.AbstractRequest { constructor() { super(); diff --git a/lib/core/interfaces/configuration.js b/lib/core/interfaces/configuration.js index bd776878e..170f986bc 100644 --- a/lib/core/interfaces/configuration.js +++ b/lib/core/interfaces/configuration.js @@ -1,28 +1,101 @@ "use strict"; +/** + * {@link PubNub} client configuration module. + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.setDefaults = void 0; const pubnub_error_1 = require("../../errors/pubnub-error"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether secured connection should be used by or not. + */ const USE_SSL = true; +/** + * Whether PubNub client should catch up subscription after network issues. + */ const RESTORE = false; +/** + * Whether network availability change should be announced with `PNNetworkDownCategory` and + * `PNNetworkUpCategory` state or not. + */ const AUTO_NETWORK_DETECTION = false; +/** + * Whether messages should be de-duplicated before announcement or not. + */ const DEDUPE_ON_SUBSCRIBE = false; +/** + * Maximum cache which should be used for message de-duplication functionality. + */ const DEDUPE_CACHE_SIZE = 100; +/** + * Maximum number of file message publish retries. + */ const FILE_PUBLISH_RETRY_LIMIT = 5; +/** + * Whether subscription event engine should be used or not. + */ const ENABLE_EVENT_ENGINE = false; +/** + * Whether configured user presence state should be maintained by the PubNub client or not. + */ const MAINTAIN_PRESENCE_STATE = true; +/** + * Whether PubNub client should try to utilize existing TCP connection for new requests or not. + */ const KEEP_ALIVE = false; +/** + * Whether verbose logging should be enabled or not. + */ const USE_VERBOSE_LOGGING = false; +/** + * Whether leave events should be suppressed or not. + */ const SUPPRESS_LEAVE_EVENTS = false; +/** + * Whether heartbeat request failure should be announced or not. + */ const ANNOUNCE_HEARTBEAT_FAILURE = true; +/** + * Whether heartbeat request success should be announced or not. + */ const ANNOUNCE_HEARTBEAT_SUCCESS = false; +/** + * Whether PubNub client instance id should be added to the requests or not. + */ const USE_INSTANCE_ID = false; +/** + * Whether unique identifier should be added to the request or not. + */ const USE_REQUEST_ID = true; +/** + * Transactional requests timeout. + */ const TRANSACTIONAL_REQUEST_TIMEOUT = 15; +/** + * Subscription request timeout. + */ const SUBSCRIBE_REQUEST_TIMEOUT = 310; +/** + * Default user presence timeout. + */ const PRESENCE_TIMEOUT = 300; +/** + * Minimum user presence timeout. + */ const PRESENCE_TIMEOUT_MINIMUM = 20; +/** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + * + * @internal + */ const setDefaults = (configuration) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; + // Copy configuration. const configurationCopy = Object.assign({}, configuration); (_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING); (_b = configurationCopy.ssl) !== null && _b !== void 0 ? _b : (configurationCopy.ssl = USE_SSL); @@ -43,6 +116,7 @@ const setDefaults = (configuration) => { throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' not set"); else if (((_p = configurationCopy.userId) === null || _p === void 0 ? void 0 : _p.trim().length) === 0) throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' is empty"); + // Generate default origin subdomains. if (!configurationCopy.origin) configurationCopy.origin = Array.from({ length: 20 }, (_, i) => `ps${i + 1}.pndsn.com`); const keySet = { @@ -52,31 +126,49 @@ const setDefaults = (configuration) => { }; if (configurationCopy.presenceTimeout !== undefined && configurationCopy.presenceTimeout < PRESENCE_TIMEOUT_MINIMUM) { configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; + // eslint-disable-next-line no-console console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); } (_q = configurationCopy.presenceTimeout) !== null && _q !== void 0 ? _q : (configurationCopy.presenceTimeout = PRESENCE_TIMEOUT); + // Apply extended configuration defaults. let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS; let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE; let fileUploadPublishRetryLimit = FILE_PUBLISH_RETRY_LIMIT; let dedupeOnSubscribe = DEDUPE_ON_SUBSCRIBE; const maximumCacheSize = DEDUPE_CACHE_SIZE; let useRequestId = USE_REQUEST_ID; + // @ts-expect-error Not documented legacy configuration options. if (configurationCopy.dedupeOnSubscribe !== undefined && typeof configurationCopy.dedupeOnSubscribe === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. dedupeOnSubscribe = configurationCopy.dedupeOnSubscribe; } + // @ts-expect-error Not documented legacy configuration options. if (configurationCopy.useRequestId !== undefined && typeof configurationCopy.useRequestId === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. useRequestId = configurationCopy.useRequestId; } - if (configurationCopy.announceSuccessfulHeartbeats !== undefined && + if ( + // @ts-expect-error Not documented legacy configuration options. + configurationCopy.announceSuccessfulHeartbeats !== undefined && + // @ts-expect-error Not documented legacy configuration options. typeof configurationCopy.announceSuccessfulHeartbeats === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. announceSuccessfulHeartbeats = configurationCopy.announceSuccessfulHeartbeats; } - if (configurationCopy.announceFailedHeartbeats !== undefined && + if ( + // @ts-expect-error Not documented legacy configuration options. + configurationCopy.announceFailedHeartbeats !== undefined && + // @ts-expect-error Not documented legacy configuration options. typeof configurationCopy.announceFailedHeartbeats === 'boolean') { + // @ts-expect-error Not documented legacy configuration options. announceFailedHeartbeats = configurationCopy.announceFailedHeartbeats; } - if (configurationCopy.fileUploadPublishRetryLimit !== undefined && + if ( + // @ts-expect-error Not documented legacy configuration options. + configurationCopy.fileUploadPublishRetryLimit !== undefined && + // @ts-expect-error Not documented legacy configuration options. typeof configurationCopy.fileUploadPublishRetryLimit === 'number') { + // @ts-expect-error Not documented legacy configuration options. fileUploadPublishRetryLimit = configurationCopy.fileUploadPublishRetryLimit; } return Object.assign(Object.assign({}, configurationCopy), { keySet, diff --git a/lib/core/interfaces/crypto-module.js b/lib/core/interfaces/crypto-module.js index 72ba0823b..d5efe74f4 100644 --- a/lib/core/interfaces/crypto-module.js +++ b/lib/core/interfaces/crypto-module.js @@ -1,22 +1,64 @@ "use strict"; +/** + * Crypto module. + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractCryptoModule = void 0; class AbstractCryptoModule { + // -------------------------------------------------------- + // --------------- Convenience functions ------------------ + // -------------------------------------------------------- + // region Convenience functions + /** + * Construct crypto module with legacy cryptor for encryption and both legacy and AES-CBC + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using legacy cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ static legacyCryptoModule(config) { throw new Error('Should be implemented by concrete crypto module implementation.'); } + /** + * Construct crypto module with AES-CBC cryptor for encryption and both AES-CBC and legacy + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using AES-CBC cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ static aesCbcCryptoModule(config) { throw new Error('Should be implemented by concrete crypto module implementation.'); } + // endregion constructor(configuration) { var _a; this.defaultCryptor = configuration.default; this.cryptors = (_a = configuration.cryptors) !== null && _a !== void 0 ? _a : []; } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + /** + * Retrieve list of module's cryptors. + */ getAllCryptors() { return [this.defaultCryptor, ...this.cryptors]; } } exports.AbstractCryptoModule = AbstractCryptoModule; +/** + * `String` to {@link ArrayBuffer} response decoder. + */ AbstractCryptoModule.encoder = new TextEncoder(); +/** + * {@link ArrayBuffer} to {@link string} decoder. + */ AbstractCryptoModule.decoder = new TextDecoder(); diff --git a/lib/core/interfaces/cryptography.js b/lib/core/interfaces/cryptography.js index c8ad2e549..23aacc798 100644 --- a/lib/core/interfaces/cryptography.js +++ b/lib/core/interfaces/cryptography.js @@ -1,2 +1,5 @@ "use strict"; +/** + * Legacy Cryptography module interface. + */ Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/pubnub-channel-groups.js b/lib/core/pubnub-channel-groups.js index fbab5c9b9..6a15691a5 100644 --- a/lib/core/pubnub-channel-groups.js +++ b/lib/core/pubnub-channel-groups.js @@ -1,4 +1,7 @@ "use strict"; +/** + * PubNub Channel Groups API module. + */ 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) { @@ -15,10 +18,21 @@ const list_channels_1 = require("./endpoints/channel_groups/list_channels"); const delete_group_1 = require("./endpoints/channel_groups/delete_group"); const list_groups_1 = require("./endpoints/channel_groups/list_groups"); class PubnubChannelGroups { - constructor(keySet, sendRequest) { + constructor(keySet, + /* eslint-disable @typescript-eslint/no-explicit-any */ + sendRequest) { this.keySet = keySet; this.sendRequest = sendRequest; } + /** + * Fetch channel group channels. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get channel group channels response or `void` in case if `callback` + * provided. + */ listChannels(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new list_channels_1.ListChannelGroupChannels(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -27,6 +41,15 @@ class PubnubChannelGroups { return this.sendRequest(request); }); } + /** + * Fetch all channel groups. + * + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all channel groups response or `void` in case if `callback` provided. + * + * @deprecated + */ listGroups(callback) { return __awaiter(this, void 0, void 0, function* () { const request = new list_groups_1.ListChannelGroupsRequest({ keySet: this.keySet }); @@ -35,6 +58,15 @@ class PubnubChannelGroups { return this.sendRequest(request); }); } + /** + * Add channels to the channel group. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add channels to the channel group response or `void` in case if + * `callback` provided. + */ addChannels(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new add_channels_1.AddChannelGroupChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -43,6 +75,15 @@ class PubnubChannelGroups { return this.sendRequest(request); }); } + /** + * Remove channels from the channel group. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous remove channels from the channel group response or `void` in + * case if `callback` provided. + */ removeChannels(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new remove_channels_1.RemoveChannelGroupChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -51,6 +92,14 @@ class PubnubChannelGroups { return this.sendRequest(request); }); } + /** + * Remove channel group. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous remove channel group response or `void` in case if `callback` provided. + */ deleteGroup(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new delete_group_1.DeleteChannelGroupRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index e0eed71e2..ae929ffc9 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -36,42 +36,62 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PubNubCore = void 0; +// region Imports +// region Components const listener_manager_1 = require("./components/listener_manager"); const subscription_manager_1 = require("./components/subscription-manager"); const push_payload_1 = __importDefault(require("./components/push_payload")); const eventEmitter_1 = __importDefault(require("./components/eventEmitter")); const base64_codec_1 = require("./components/base64_codec"); const uuid_1 = __importDefault(require("./components/uuid")); +// endregion +// region Constants const operations_1 = __importDefault(require("./constants/operations")); const categories_1 = __importDefault(require("./constants/categories")); +// endregion const pubnub_error_1 = require("../errors/pubnub-error"); const pubnub_api_error_1 = require("../errors/pubnub-api-error"); +// region Event Engine const presence_1 = require("../event-engine/presence/presence"); const retryPolicy_1 = require("../event-engine/core/retryPolicy"); const event_engine_1 = require("../event-engine"); +// endregion +// region Publish & Signal const Publish = __importStar(require("./endpoints/publish")); const Signal = __importStar(require("./endpoints/signal")); +// endregion +// region Subscription const subscribe_1 = require("./endpoints/subscribe"); const receiveMessages_1 = require("./endpoints/subscriptionUtils/receiveMessages"); const handshake_1 = require("./endpoints/subscriptionUtils/handshake"); +// endregion +// region Presence const get_state_1 = require("./endpoints/presence/get_state"); const set_state_1 = require("./endpoints/presence/set_state"); const heartbeat_1 = require("./endpoints/presence/heartbeat"); const leave_1 = require("./endpoints/presence/leave"); const where_now_1 = require("./endpoints/presence/where_now"); const here_now_1 = require("./endpoints/presence/here_now"); +// endregion +// region Message Storage const delete_messages_1 = require("./endpoints/history/delete_messages"); const message_counts_1 = require("./endpoints/history/message_counts"); const get_history_1 = require("./endpoints/history/get_history"); const fetch_messages_1 = require("./endpoints/fetch_messages"); +// endregion +// region Message Actions const get_message_actions_1 = require("./endpoints/actions/get_message_actions"); const add_message_action_1 = require("./endpoints/actions/add_message_action"); const remove_message_action_1 = require("./endpoints/actions/remove_message_action"); +// endregion +// region File sharing const publish_file_1 = require("./endpoints/file_upload/publish_file"); const get_file_url_1 = require("./endpoints/file_upload/get_file_url"); const delete_file_1 = require("./endpoints/file_upload/delete_file"); const list_files_1 = require("./endpoints/file_upload/list_files"); const send_file_1 = require("./endpoints/file_upload/send_file"); +// endregion +// region PubNub Access Manager const revoke_token_1 = require("./endpoints/access_manager/revoke_token"); const grant_token_1 = require("./endpoints/access_manager/grant_token"); const grant_1 = require("./endpoints/access_manager/grant"); @@ -81,28 +101,55 @@ const SubscriptionSet_1 = require("../entities/SubscriptionSet"); const ChannelGroup_1 = require("../entities/ChannelGroup"); const UserMetadata_1 = require("../entities/UserMetadata"); const Channel_1 = require("../entities/Channel"); +// endregion +// region Channel Groups const pubnub_channel_groups_1 = __importDefault(require("./pubnub-channel-groups")); +// endregion +// region Push Notifications const pubnub_push_1 = __importDefault(require("./pubnub-push")); const pubnub_objects_1 = __importDefault(require("./pubnub-objects")); +// endregion +// region Time const Time = __importStar(require("./endpoints/time")); +// endregion const utils_1 = require("./utils"); const download_file_1 = require("./endpoints/file_upload/download_file"); +// endregion +/** + * Platform-agnostic PubNub client core. + */ class PubNubCore { + /** + * Construct notification payload which will trigger push notification. + * + * @param title - Title which will be shown on notification. + * @param body - Payload which will be sent as part of notification. + * + * @returns Pre-formatted message payload which will trigger push notification. + */ static notificationPayload(title, body) { return new push_payload_1.default(title, body); } + /** + * Generate unique identifier. + * + * @returns Unique identifier. + */ static generateUUID() { return uuid_1.default.createUUID(); } + // endregion constructor(configuration) { this._configuration = configuration.configuration; this.cryptography = configuration.cryptography; this.tokenManager = configuration.tokenManager; this.transport = configuration.transport; this.crypto = configuration.crypto; + // API group entry points initialization. this._objects = new pubnub_objects_1.default(this._configuration, this.sendRequest.bind(this)); this._channelGroups = new pubnub_channel_groups_1.default(this._configuration.keySet, this.sendRequest.bind(this)); this._push = new pubnub_push_1.default(this._configuration.keySet, this.sendRequest.bind(this)); + // Prepare for real-time events announcement. this.listenerManager = new listener_manager_1.ListenerManager(); this.eventEmitter = new eventEmitter_1.default(this.listenerManager); if (this._configuration.enableEventEngine) { @@ -155,109 +202,319 @@ class PubNubCore { this.subscriptionManager = new subscription_manager_1.SubscriptionManager(this._configuration, this.listenerManager, this.eventEmitter, this.makeSubscribe.bind(this), this.heartbeat.bind(this), this.makeUnsubscribe.bind(this), this.time.bind(this)); } } + // -------------------------------------------------------- + // -------------------- Configuration ---------------------- + // -------------------------------------------------------- + // region Configuration + /** + * PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + */ get configuration() { return this._configuration; } + /** + * Current PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + * + * @deprecated Use {@link configuration} getter instead. + */ get _config() { return this.configuration; } + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ get authKey() { var _a; return (_a = this._configuration.authKey) !== null && _a !== void 0 ? _a : undefined; } + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ getAuthKey() { return this.authKey; } + /** + * Change REST API endpoint access authorization key. + * + * @param authKey - New authorization key which should be used with new requests. + */ setAuthKey(authKey) { this._configuration.setAuthKey(authKey); } + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ get userId() { return this._configuration.userId; } + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ set userId(value) { if (!value || typeof value !== 'string' || value.trim().length === 0) throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); this._configuration.userId = value; } + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ getUserId() { return this._configuration.userId; } + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ setUserId(value) { if (!value || typeof value !== 'string' || value.trim().length === 0) throw new Error('Missing or invalid userId parameter. Provide a valid string userId'); this._configuration.userId = value; } + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ get filterExpression() { var _a; return (_a = this._configuration.getFilterExpression()) !== null && _a !== void 0 ? _a : undefined; } + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ getFilterExpression() { return this.filterExpression; } + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ set filterExpression(expression) { this._configuration.setFilterExpression(expression); } + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ setFilterExpression(expression) { this.filterExpression = expression; } + /** + * Dta encryption / decryption key. + * + * @returns Currently used key for data encryption / decryption. + */ get cipherKey() { return this._configuration.getCipherKey(); } + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ set cipherKey(key) { this._configuration.setCipherKey(key); } + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ setCipherKey(key) { this.cipherKey = key; } + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ set heartbeatInterval(interval) { this._configuration.setHeartbeatInterval(interval); } + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ setHeartbeatInterval(interval) { this.heartbeatInterval = interval; } + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ getVersion() { return this._configuration.getVersion(); } + /** + * Add framework's prefix. + * + * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. + * @param suffix - Suffix with information about framework. + */ _addPnsdkSuffix(name, suffix) { this._configuration._addPnsdkSuffix(name, suffix); } + // -------------------------------------------------------- + // ---------------------- Deprecated ---------------------- + // -------------------------------------------------------- + // region Deprecated + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + * + * @deprecated Use the {@link getUserId} or {@link userId} getter instead. + */ getUUID() { return this.userId; } + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + * + * @deprecated Use the {@link PubNubCore#setUserId} or {@link PubNubCore#userId} setter instead. + */ setUUID(value) { this.userId = value; } + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ get customEncrypt() { return this._configuration.getCustomEncrypt(); } + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ get customDecrypt() { return this._configuration.getCustomDecrypt(); } + // endregion + // endregion + // -------------------------------------------------------- + // ---------------------- Entities ------------------------ + // -------------------------------------------------------- + // region Entities + /** + * Create a `Channel` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel name. + * @returns `Channel` entity. + */ channel(name) { return new Channel_1.Channel(name, this.eventEmitter, this); } + /** + * Create a `ChannelGroup` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel group name. + * @returns `ChannelGroup` entity. + */ channelGroup(name) { return new ChannelGroup_1.ChannelGroup(name, this.eventEmitter, this); } + /** + * Create a `ChannelMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique channel metadata object identifier. + * @returns `ChannelMetadata` entity. + */ channelMetadata(id) { return new ChannelMetadata_1.ChannelMetadata(id, this.eventEmitter, this); } + /** + * Create a `UserMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique user metadata object identifier. + * @returns `UserMetadata` entity. + */ userMetadata(id) { return new UserMetadata_1.UserMetadata(id, this.eventEmitter, this); } + /** + * Create subscriptions set object. + * + * @param parameters - Subscriptions set configuration parameters. + */ subscriptionSet(parameters) { return new SubscriptionSet_1.SubscriptionSet(Object.assign(Object.assign({}, parameters), { eventEmitter: this.eventEmitter, pubnub: this })); } + /** + * Schedule request execution. + * + * @param request - REST API request. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous request execution and response parsing result or `void` in case if + * `callback` provided. + * + * @throws PubNubError in case of request processing error. + */ sendRequest(request, callback) { return __awaiter(this, void 0, void 0, function* () { + // Validate user-input. const validationResult = request.validate(); if (validationResult) { if (callback) return callback((0, pubnub_error_1.createValidationError)(validationResult), null); throw new pubnub_error_1.PubNubError('Validation failed, check status for details', (0, pubnub_error_1.createValidationError)(validationResult)); } + // Complete request configuration. const transportRequest = request.request(); if (transportRequest.formData && transportRequest.formData.length > 0) { + // Set 300 seconds file upload request delay. transportRequest.timeout = 300; } else { @@ -266,6 +523,7 @@ class PubNubCore { else transportRequest.timeout = this._configuration.getTransactionTimeout(); } + // API request processing status. const status = { error: false, operation: request.operation(), @@ -273,10 +531,17 @@ class PubNubCore { statusCode: 0, }; const [sendableRequest, cancellationController] = this.transport.makeSendable(transportRequest); + /** + * **Important:** Because of multiple environments where JS SDK can be used control over + * cancellation had to be inverted to let transport provider solve request cancellation task + * more efficiently. As result, cancellation controller can be retrieved and used only after + * request will be scheduled by transport provider. + */ request.cancellationController = cancellationController ? cancellationController : null; return sendableRequest .then((response) => { status.statusCode = response.status; + // Handle special case when request completed but not fully processed by PubNub service. if (response.status !== 200 && response.status !== 204) { const contentType = response.headers['content-type']; if (contentType || contentType.indexOf('javascript') !== -1 || contentType.indexOf('json') !== -1) { @@ -288,18 +553,25 @@ class PubNubCore { return request.parse(response); }) .then((parsed) => { + // Notify callback (if possible). if (callback) return callback(status, parsed); return parsed; }) .catch((error) => { const apiError = !(error instanceof pubnub_api_error_1.PubNubAPIError) ? pubnub_api_error_1.PubNubAPIError.create(error) : error; + // Notify callback (if possible). if (callback) return callback(apiError.toStatus(request.operation()), null); throw apiError.toPubNubError(request.operation(), 'REST API request processing error, check status for details'); }); }); } + /** + * Unsubscribe from all channels and groups. + * + * @param [isOffline] - Whether `offline` presence should be notified or not. + */ destroy(isOffline) { if (this.subscriptionManager) { this.subscriptionManager.unsubscribeAll(isOffline); @@ -308,18 +580,49 @@ class PubNubCore { else if (this.eventEngine) this.eventEngine.dispose(); } + /** + * Unsubscribe from all channels and groups. + * + * @deprecated Use {@link destroy} method instead. + */ stop() { this.destroy(); } + // endregion + // -------------------------------------------------------- + // ----------------------- Listener ----------------------- + // -------------------------------------------------------- + // region Listener + /** + * Register real-time events listener. + * + * @param listener - Listener with event callbacks to handle different types of events. + */ addListener(listener) { this.listenerManager.addListener(listener); } + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + */ removeListener(listener) { this.listenerManager.removeListener(listener); } + /** + * Clear all real-time event listeners. + */ removeAllListeners() { this.listenerManager.removeAllListeners(); } + /** + * Publish data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous publish data response or `void` in case if `callback` provided. + */ publish(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new Publish.PublishRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); @@ -328,6 +631,14 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Signal data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous signal data response or `void` in case if `callback` provided. + */ signal(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new Signal.SignalRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -336,12 +647,32 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * `Fire` a data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous signal data response or `void` in case if `callback` provided. + * + * @deprecated Use {@link publish} method instead. + */ fire(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { callback !== null && callback !== void 0 ? callback : (callback = () => { }); return this.publish(Object.assign(Object.assign({}, parameters), { replicate: false, storeInHistory: false }), callback); }); } + // endregion + // -------------------------------------------------------- + // -------------------- Subscribe API --------------------- + // -------------------------------------------------------- + // region Subscribe API + /** + * Get list of channels on which PubNub client currently subscribed. + * + * @returns List of active channels. + */ getSubscribedChannels() { if (this.subscriptionManager) return this.subscriptionManager.subscribedChannels; @@ -349,6 +680,11 @@ class PubNubCore { return this.eventEngine.getSubscribedChannels(); return []; } + /** + * Get list of channel groups on which PubNub client currently subscribed. + * + * @returns List of active channel groups. + */ getSubscribedChannelGroups() { if (this.subscriptionManager) return this.subscriptionManager.subscribedChannelGroups; @@ -356,12 +692,25 @@ class PubNubCore { return this.eventEngine.getSubscribedChannelGroups(); return []; } + /** + * Subscribe to specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ subscribe(parameters) { if (this.subscriptionManager) this.subscriptionManager.subscribe(parameters); else if (this.eventEngine) this.eventEngine.subscribe(parameters); } + /** + * Perform subscribe request. + * + * **Note:** Method passed into managers to let them use it when required. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ makeSubscribe(parameters, callback) { const request = new subscribe_1.SubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); this.sendRequest(request, (status, result) => { @@ -370,45 +719,88 @@ class PubNubCore { this.subscriptionManager.abort = null; callback(status, result); }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ if (this.subscriptionManager) { + // Creating identifiable abort caller. const callableAbort = () => request.abort(); callableAbort.identifier = request.requestIdentifier; this.subscriptionManager.abort = callableAbort; } } + /** + * Unsubscribe from specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ unsubscribe(parameters) { if (this.subscriptionManager) this.subscriptionManager.unsubscribe(parameters); else if (this.eventEngine) this.eventEngine.unsubscribe(parameters); } + /** + * Perform unsubscribe request. + * + * **Note:** Method passed into managers to let them use it when required. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ makeUnsubscribe(parameters, callback) { this.sendRequest(new leave_1.PresenceLeaveRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })), callback); } + /** + * Unsubscribe from all channels and groups. + */ unsubscribeAll() { if (this.subscriptionManager) this.subscriptionManager.unsubscribeAll(); else if (this.eventEngine) this.eventEngine.unsubscribeAll(); } + /** + * Temporarily disconnect from real-time events stream. + */ disconnect() { if (this.subscriptionManager) this.subscriptionManager.disconnect(); else if (this.eventEngine) this.eventEngine.disconnect(); } + /** + * Restore connection to the real-time events stream. + * + * @param parameters - Reconnection catch up configuration. **Note:** available only with + * enabled event engine. + */ reconnect(parameters) { if (this.subscriptionManager) this.subscriptionManager.reconnect(); else if (this.eventEngine) this.eventEngine.reconnect(parameters !== null && parameters !== void 0 ? parameters : {}); } + /** + * Event engine handshake subscribe. + * + * @param parameters - Request configuration parameters. + */ subscribeHandshake(parameters) { return __awaiter(this, void 0, void 0, function* () { const request = new handshake_1.HandshakeSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { request.abort(); }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ const handshakeResponse = this.sendRequest(request); return handshakeResponse.then((response) => { abortUnsubscribe(); @@ -416,12 +808,23 @@ class PubNubCore { }); }); } + /** + * Event engine receive messages subscribe. + * + * @param parameters - Request configuration parameters. + */ subscribeReceiveMessages(parameters) { return __awaiter(this, void 0, void 0, function* () { const request = new receiveMessages_1.ReceiveMessagesSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { request.abort(); }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ const handshakeResponse = this.sendRequest(request); return handshakeResponse.then((response) => { abortUnsubscribe(); @@ -429,6 +832,14 @@ class PubNubCore { }); }); } + /** + * Get reactions to a specific message. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get reactions response or `void` in case if `callback` provided. + */ getMessageActions(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new get_message_actions_1.GetMessageActionsRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -437,6 +848,14 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Add a reaction to a specific message. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add a reaction response or `void` in case if `callback` provided. + */ addMessageAction(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new add_message_action_1.AddMessageActionRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -445,6 +864,14 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Remove a reaction from a specific message. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous remove a reaction response or `void` in case if `callback` provided. + */ removeMessageAction(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new remove_message_action_1.RemoveMessageAction(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -453,6 +880,14 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Fetch messages history for channels. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous fetch messages response or `void` in case if `callback` provided. + */ fetchMessages(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new fetch_messages_1.FetchMessagesRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); @@ -461,6 +896,16 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Delete messages from the channel history. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous delete messages response or `void` in case if `callback` provided. + * + * @deprecated + */ deleteMessages(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new delete_messages_1.DeleteMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -469,6 +914,14 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Count messages from the channels' history. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous count messages response or `void` in case if `callback` provided. + */ messageCounts(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new message_counts_1.MessageCountRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -477,6 +930,16 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Fetch single channel history. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous fetch channel history response or `void` in case if `callback` provided. + * + * @deprecated + */ history(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new get_history_1.GetHistoryRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); @@ -485,6 +948,14 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Get channel's presence information. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get channel's presence response or `void` in case if `callback` provided. + */ hereNow(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new here_now_1.HereNowRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -493,6 +964,16 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Get user's presence information. + * + * Get list of channels to which `uuid` currently subscribed. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get user's presence response or `void` in case if `callback` provided. + */ whereNow(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; @@ -505,6 +986,14 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Get associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get user's data response or `void` in case if `callback` provided. + */ getState(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; @@ -514,12 +1003,21 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Set associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set user's data response or `void` in case if `callback` provided. + */ setState(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const { keySet, userId: userId } = this._configuration; const heartbeat = this._configuration.getPresenceTimeout(); let request; + // Maintain presence information (if required). if (this._configuration.enableEventEngine && this.presenceState) { const presenceState = this.presenceState; (_a = parameters.channels) === null || _a === void 0 ? void 0 : _a.forEach((channel) => (presenceState[channel] = parameters.state)); @@ -527,12 +1025,14 @@ class PubNubCore { (_b = parameters.channelGroups) === null || _b === void 0 ? void 0 : _b.forEach((group) => (presenceState[group] = parameters.state)); } } + // Check whether state should be set with heartbeat or not. if ('withHeartbeat' in parameters) { request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet, heartbeat })); } else { request = new set_state_1.SetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { keySet, uuid: userId })); } + // Update state used by subscription manager. if (this.subscriptionManager) this.subscriptionManager.setState(parameters); if (callback) @@ -540,10 +1040,25 @@ class PubNubCore { return this.sendRequest(request); }); } + // endregion + // region Change presence state + /** + * Manual presence management. + * + * @param parameters - Desired presence state for provided list of channels and groups. + */ presence(parameters) { var _a; (_a = this.subscriptionManager) === null || _a === void 0 ? void 0 : _a.changePresence(parameters); } + // endregion + // region Heartbeat + /** + * Announce user presence + * + * @param parameters - Desired presence state for provided list of channels and groups. + * @param callback - Request completion handler callback. + */ heartbeat(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -552,18 +1067,45 @@ class PubNubCore { return this.sendRequest(request); }); } + // endregion + // region Join + /** + * Announce user `join` on specified list of channels and groups. + * + * @param parameters - List of channels and groups where `join` event should be sent. + */ join(parameters) { var _a; (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.join(parameters); } + // endregion + // region Leave + /** + * Announce user `leave` on specified list of channels and groups. + * + * @param parameters - List of channels and groups where `leave` event should be sent. + */ leave(parameters) { var _a; (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leave(parameters); } + /** + * Announce user `leave` on all subscribed channels. + */ leaveAll() { var _a; (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leaveAll(); } + /** + * Grant token permission. + * + * Generate access token with requested permissions. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous grant token response or `void` in case if `callback` provided. + */ grantToken(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new grant_token_1.GrantTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -572,6 +1114,14 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Revoke token permission. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous revoke token response or `void` in case if `callback` provided. + */ revokeToken(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new revoke_token_1.RevokeTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -580,21 +1130,62 @@ class PubNubCore { return this.sendRequest(request); }); } + // endregion + // region Token Manipulation + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ get token() { return this.tokenManager.getToken(); } + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ getToken() { return this.token; } + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ set token(token) { this.tokenManager.setToken(token); } + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ setToken(token) { this.token = token; } + /** + * Parse access token. + * + * Parse token to see what permissions token owner has. + * + * @param token - Token which should be parsed. + * + * @returns Token's permissions information for the resources. + */ parseToken(token) { return this.tokenManager.parseToken(token); } + /** + * Grant auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous grant auth key(s) permissions or `void` in case if `callback` provided. + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ grant(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new grant_1.GrantRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -603,6 +1194,16 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Audit auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @deprecated + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ audit(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new audit_1.AuditRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -611,74 +1212,236 @@ class PubNubCore { return this.sendRequest(request); }); } + // endregion + // endregion + // endregion + // -------------------------------------------------------- + // ------------------- App Context API -------------------- + // -------------------------------------------------------- + // region App Context API + /** + * PubNub App Context API group. + */ get objects() { return this._objects; } + /** + Fetch a paginated list of User objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all User objects response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ fetchUsers(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._getAllUUIDMetadata(parametersOrCallback, callback); }); } + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get User object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ fetchUser(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._getUUIDMetadata(parametersOrCallback, callback); }); } + /** + * Create User object. + * + * @param parameters - Request configuration parameters. Will create User object for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous create User object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ createUser(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._setUUIDMetadata(parameters, callback); }); } + /** + * Update User object. + * + * @param parameters - Request configuration parameters. Will update User object for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update User object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ updateUser(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._setUUIDMetadata(parameters, callback); }); } + /** + * Remove a specific User object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous User object remove response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ removeUser(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._removeUUIDMetadata(parametersOrCallback, callback); }); } + /** + * Fetch a paginated list of Space objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Space objects response or `void` in case if `callback` + * provided. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ fetchSpaces(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._getAllChannelMetadata(parametersOrCallback, callback); }); } + /** + * Fetch a specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Space object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. + */ fetchSpace(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._getChannelMetadata(parameters, callback); }); } + /** + * Create specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous create Space object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ createSpace(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._setChannelMetadata(parameters, callback); }); } + /** + * Update specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update Space object response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ updateSpace(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._setChannelMetadata(parameters, callback); }); } + /** + * Remove a specific Space object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Space object remove response or `void` in case if `callback` + * provided. + * + * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. + */ removeSpace(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects._removeChannelMetadata(parameters, callback); }); } + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get specific Space members or specific User memberships response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} + * methods instead. + */ fetchMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects.fetchMemberships(parameters, callback); }); } + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add members to specific Space or memberships specific User response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ addMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects.addMemberships(parameters, callback); }); } + /** + * Update specific Space members or User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update Space members or User memberships response or `void` in case + * if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ updateMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this.objects.addMemberships(parameters, callback); }); } + /** + * Remove User membership. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous memberships modification response or `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} + * methods instead + * from `objects` API group.. + */ removeMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; @@ -704,12 +1467,37 @@ class PubNubCore { return this.objects.removeMemberships(requestParameters); }); } + // endregion + // endregion + // -------------------------------------------------------- + // ----------------- Channel Groups API ------------------- + // -------------------------------------------------------- + // region Channel Groups API + /** + * PubNub Channel Groups API group. + */ get channelGroups() { return this._channelGroups; } + // endregion + // -------------------------------------------------------- + // ---------------- Push Notifications API ----------------- + // -------------------------------------------------------- + // region Push Notifications API + /** + * PubNub Push Notifications API group. + */ get push() { return this._push; } + /** + * Share file to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous file sharing response or `void` in case if `callback` provided. + */ sendFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { if (!this._configuration.PubNubFile) @@ -735,12 +1523,21 @@ class PubNubCore { errorStatus = error.status; else if (error instanceof pubnub_api_error_1.PubNubAPIError) errorStatus = error.toStatus(status.operation); + // Notify callback (if possible). if (callback && errorStatus) callback(errorStatus, null); throw new pubnub_error_1.PubNubError('REST API request processing error, check status for details', errorStatus); }); }); } + /** + * Publish file message to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous publish file message response or `void` in case if `callback` provided. + */ publishFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { if (!this._configuration.PubNubFile) @@ -751,6 +1548,14 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + * Retrieve list of shared files in specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous shared files list response or `void` in case if `callback` provided. + */ listFiles(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new list_files_1.FilesListRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -759,6 +1564,15 @@ class PubNubCore { return this.sendRequest(request); }); } + // endregion + // region Get Download Url + /** + * Get file download Url. + * + * @param parameters - Request configuration parameters. + * + * @returns File download Url. + */ getFileUrl(parameters) { var _a; const request = this.transport.request(new get_file_url_1.GetFileDownloadUrlRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })).request()); @@ -773,6 +1587,14 @@ class PubNubCore { .join('&'); return `${request.origin}${request.path}?${queryString}`; } + /** + * Download shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous download shared file response or `void` in case if `callback` provided. + */ downloadFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { if (!this._configuration.PubNubFile) @@ -783,6 +1605,14 @@ class PubNubCore { return (yield this.sendRequest(request)); }); } + /** + * Delete shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous delete shared file response or `void` in case if `callback` provided. + */ deleteFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new delete_file_1.DeleteFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); @@ -791,6 +1621,13 @@ class PubNubCore { return this.sendRequest(request); }); } + /** + Get current high-precision timetoken. + * + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get current timetoken response or `void` in case if `callback` provided. + */ time(callback) { return __awaiter(this, void 0, void 0, function* () { const request = new Time.TimeRequest(); @@ -799,6 +1636,22 @@ class PubNubCore { return this.sendRequest(request); }); } + // endregion + // -------------------------------------------------------- + // ------------------ Cryptography API -------------------- + // -------------------------------------------------------- + // region Cryptography + // region Common + /** + * Encrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @deprecated + * @param [customCipherKey] - Cipher key which should be used to encrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data encryption result as a string. + */ encrypt(data, customCipherKey) { const cryptoModule = this._configuration.getCryptoModule(); if (!customCipherKey && cryptoModule && typeof data === 'string') { @@ -809,6 +1662,15 @@ class PubNubCore { throw new Error('Encryption error: cypher key not set'); return this.crypto.encrypt(data, customCipherKey); } + /** + * Decrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @param [customCipherKey] - Cipher key which should be used to decrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data decryption result as an object. + */ decrypt(data, customCipherKey) { const cryptoModule = this._configuration.getCryptoModule(); if (!customCipherKey && cryptoModule) { @@ -819,6 +1681,19 @@ class PubNubCore { throw new Error('Decryption error: cypher key not set'); return this.crypto.decrypt(data, customCipherKey); } + /** + * Encrypt file content. + * + * @param keyOrFile - Cipher key which should be used to encrypt data or file which should be + * encrypted using `CryptoModule`. + * @param [file] - File which should be encrypted using legacy cryptography. + * + * @returns Asynchronous file encryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ encryptFile(keyOrFile, file) { return __awaiter(this, void 0, void 0, function* () { var _a; @@ -838,6 +1713,19 @@ class PubNubCore { return (_a = this._configuration.getCryptoModule()) === null || _a === void 0 ? void 0 : _a.encryptFile(file, this._configuration.PubNubFile); }); } + /** + * Decrypt file content. + * + * @param keyOrFile - Cipher key which should be used to decrypt data or file which should be + * decrypted using `CryptoModule`. + * @param [file] - File which should be decrypted using legacy cryptography. + * + * @returns Asynchronous file decryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ decryptFile(keyOrFile, file) { return __awaiter(this, void 0, void 0, function* () { var _a; @@ -859,8 +1747,29 @@ class PubNubCore { } } exports.PubNubCore = PubNubCore; +/** + * {@link ArrayBuffer} to {@link string} decoder. + * + * @internal + */ PubNubCore.decoder = new TextDecoder(); +// -------------------------------------------------------- +// ----------------------- Static ------------------------- +// -------------------------------------------------------- +// region Static +/** + * Type of REST API endpoint which reported status. + */ PubNubCore.OPERATIONS = operations_1.default; +/** + * API call status category. + */ PubNubCore.CATEGORIES = categories_1.default; +/** + * Exponential retry policy constructor. + */ PubNubCore.ExponentialRetryPolicy = retryPolicy_1.RetryPolicy.ExponentialRetryPolicy; +/** + * Linear retry policy constructor. + */ PubNubCore.LinearRetryPolicy = retryPolicy_1.RetryPolicy.LinearRetryPolicy; diff --git a/lib/core/pubnub-objects.js b/lib/core/pubnub-objects.js index 79b1e885b..9948ee382 100644 --- a/lib/core/pubnub-objects.js +++ b/lib/core/pubnub-objects.js @@ -1,4 +1,7 @@ "use strict"; +/** + * PubNub Objects API module. + */ 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) { @@ -22,18 +25,38 @@ const set_3 = require("./endpoints/objects/member/set"); const get_4 = require("./endpoints/objects/uuid/get"); const set_4 = require("./endpoints/objects/uuid/set"); class PubNubObjects { - constructor(configuration, sendRequest) { + constructor(configuration, + /* eslint-disable @typescript-eslint/no-explicit-any */ + sendRequest) { this.configuration = configuration; this.sendRequest = sendRequest; this.keySet = configuration.keySet; } + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + */ getAllUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { return this._getAllUUIDMetadata(parametersOrCallback, callback); }); } + /** + * Fetch a paginated list of UUID Metadata objects. + * + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + */ _getAllUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { + // Get user request parameters. const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); const request = new get_all_2.GetAllUUIDMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -42,14 +65,31 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Fetch a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + */ getUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { return this._getUUIDMetadata(parametersOrCallback, callback); }); } + /** + * Fetch a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + */ _getUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; + // Get user request parameters. const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); if (parameters.userId) @@ -61,11 +101,29 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set UUID metadata response or `void` in case if `callback` provided. + */ setUUIDMetadata(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this._setUUIDMetadata(parameters, callback); }); } + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set UUID metadata response or `void` in case if `callback` provided. + */ _setUUIDMetadata(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; @@ -78,14 +136,31 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Remove a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID metadata remove response or `void` in case if `callback` provided. + */ removeUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { return this._removeUUIDMetadata(parametersOrCallback, callback); }); } + /** + * Remove a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID metadata remove response or `void` in case if `callback` provided. + */ _removeUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; + // Get user request parameters. const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); if (parameters.userId) @@ -97,13 +172,32 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Channel metadata response or `void` in case if `callback` + * provided. + */ getAllChannelMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { return this._getAllChannelMetadata(parametersOrCallback, callback); }); } + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Channel metadata response or `void` in case if `callback` + * provided. + */ _getAllChannelMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { + // Get user request parameters. const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); const request = new get_all_1.GetAllChannelsMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -112,11 +206,27 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel metadata response or `void` in case if `callback` provided. + */ getChannelMetadata(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this._getChannelMetadata(parameters, callback); }); } + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel metadata response or `void` in case if `callback` provided. + */ _getChannelMetadata(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new get_2.GetChannelMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -125,11 +235,27 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set Channel metadata response or `void` in case if `callback` provided. + */ setChannelMetadata(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this._setChannelMetadata(parameters, callback); }); } + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set Channel metadata response or `void` in case if `callback` provided. + */ _setChannelMetadata(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new set_2.SetChannelMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -138,11 +264,29 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel metadata remove response or `void` in case if `callback` + * provided. + */ removeChannelMetadata(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { return this._removeChannelMetadata(parameters, callback); }); } + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel metadata remove response or `void` in case if `callback` + * provided. + */ _removeChannelMetadata(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new remove_1.RemoveChannelMetadataRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -151,6 +295,14 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Fetch a paginated list of Channel Member objects. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel Members response or `void` in case if `callback` provided. + */ getChannelMembers(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new get_3.GetChannelMembersRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -159,6 +311,15 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Update specific Channel Members list. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update Channel members list response or `void` in case if `callback` + * provided. + */ setChannelMembers(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new set_3.SetChannelMembersRequest(Object.assign(Object.assign({}, parameters), { type: 'set', keySet: this.keySet })); @@ -167,6 +328,14 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Remove Members from the Channel. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel Members remove response or `void` in case if `callback` provided. + */ removeChannelMembers(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new set_3.SetChannelMembersRequest(Object.assign(Object.assign({}, parameters), { type: 'delete', keySet: this.keySet })); @@ -175,9 +344,18 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Fetch a specific UUID Memberships list. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID Memberships response or `void` in case if `callback` provided. + */ getMemberships(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; + // Get user request parameters. const parameters = parametersOrCallback && typeof parametersOrCallback !== 'function' ? parametersOrCallback : {}; callback !== null && callback !== void 0 ? callback : (callback = typeof parametersOrCallback === 'function' ? parametersOrCallback : undefined); if (parameters.userId) @@ -189,6 +367,15 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Update specific UUID Memberships list. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous update UUID Memberships list response or `void` in case if `callback` + * provided. + */ setMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; @@ -201,6 +388,15 @@ class PubNubObjects { return this.sendRequest(request); }); } + /** + * Remove a specific UUID Memberships. + * + * @param parameters - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID Memberships remove response or `void` in case if `callback` + * provided. + */ removeMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; @@ -213,6 +409,22 @@ class PubNubObjects { return this.sendRequest(request); }); } + // endregion + // endregion + // -------------------------------------------------------- + // --------------------- Deprecated API ------------------- + // -------------------------------------------------------- + // region Deprecated + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get specific Space members or specific User memberships response. + * + * @deprecated Use {@link PubNubObjects#getChannelMembers} or {@link PubNubObjects#getMemberships} methods instead. + */ fetchMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; @@ -228,6 +440,7 @@ class PubNubObjects { ? Object.fromEntries(Object.entries(spaceParameters.sort).map(([key, value]) => [key.replace('user', 'uuid'), value])) : undefined, }; + // Map Members object to the older version. const mapMembers = (response) => ({ status: response.status, data: response.data.map((members) => ({ @@ -257,6 +470,7 @@ class PubNubObjects { ? Object.fromEntries(Object.entries(userParameters.sort).map(([key, value]) => [key.replace('space', 'channel'), value])) : undefined, }; + // Map Memberships object to the older version. const mapMemberships = (response) => ({ status: response.status, data: response.data.map((membership) => ({ @@ -276,6 +490,17 @@ class PubNubObjects { return this.getMemberships(mappedParameters).then(mapMemberships); }); } + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add members to specific Space or memberships specific User response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubObjects#setChannelMembers} or {@link PubNubObjects#setMemberships} methods instead. + */ addMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c, _d, _e, _f; diff --git a/lib/core/pubnub-push.js b/lib/core/pubnub-push.js index 94f135a9c..3fa4911f4 100644 --- a/lib/core/pubnub-push.js +++ b/lib/core/pubnub-push.js @@ -1,4 +1,7 @@ "use strict"; +/** + * PubNub Push Notifications API module. + */ 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) { @@ -14,10 +17,20 @@ const list_push_channels_1 = require("./endpoints/push/list_push_channels"); const add_push_channels_1 = require("./endpoints/push/add_push_channels"); const remove_device_1 = require("./endpoints/push/remove_device"); class PubNubPushNotifications { - constructor(keySet, sendRequest) { + constructor(keySet, + /* eslint-disable @typescript-eslint/no-explicit-any */ + sendRequest) { this.keySet = keySet; this.sendRequest = sendRequest; } + /** + * Fetch device's push notification enabled channels. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get device channels response or `void` in case if `callback` provided. + */ listChannels(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new list_push_channels_1.ListDevicePushNotificationChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -26,6 +39,12 @@ class PubNubPushNotifications { return this.sendRequest(request); }); } + /** + * Enable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + */ addChannels(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new add_push_channels_1.AddDevicePushNotificationChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -34,6 +53,12 @@ class PubNubPushNotifications { return this.sendRequest(request); }); } + /** + * Disable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + */ removeChannels(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new remove_push_channels_1.RemoveDevicePushNotificationChannelsRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); @@ -42,6 +67,12 @@ class PubNubPushNotifications { return this.sendRequest(request); }); } + /** + * Disable push notifications for device. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + */ deleteDevice(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { const request = new remove_device_1.RemoveDevicePushNotificationRequest(Object.assign(Object.assign({}, parameters), { keySet: this.keySet })); diff --git a/lib/core/types/api/access-panager.js b/lib/core/types/api/access-panager.js index c8ad2e549..5bff3536a 100644 --- a/lib/core/types/api/access-panager.js +++ b/lib/core/types/api/access-panager.js @@ -1,2 +1,4 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +// endregion +// endregion diff --git a/lib/core/types/api/app-context.js b/lib/core/types/api/app-context.js index c8ad2e549..6c5bae6f7 100644 --- a/lib/core/types/api/app-context.js +++ b/lib/core/types/api/app-context.js @@ -1,2 +1,3 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +// endregion diff --git a/lib/core/types/api/file-sharing.js b/lib/core/types/api/file-sharing.js index c8ad2e549..35c8b7c01 100644 --- a/lib/core/types/api/file-sharing.js +++ b/lib/core/types/api/file-sharing.js @@ -1,2 +1,6 @@ "use strict"; +/** + * File Sharing REST API module. + */ Object.defineProperty(exports, "__esModule", { value: true }); +// endregion diff --git a/lib/core/types/api/history.js b/lib/core/types/api/history.js index 82e074734..1653ae13f 100644 --- a/lib/core/types/api/history.js +++ b/lib/core/types/api/history.js @@ -1,8 +1,25 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PubNubMessageType = void 0; +// endregion +// -------------------------------------------------------- +// -------------------- Fetch Messages -------------------- +// -------------------------------------------------------- +// region Fetch Messages +/** + * PubNub-defined message type. + * + * Types of messages which can be retrieved with fetch messages REST API. + */ var PubNubMessageType; (function (PubNubMessageType) { + /** + * Regular message. + */ PubNubMessageType[PubNubMessageType["Message"] = -1] = "Message"; + /** + * File message. + */ PubNubMessageType[PubNubMessageType["Files"] = 4] = "Files"; })(PubNubMessageType || (exports.PubNubMessageType = PubNubMessageType = {})); +// endregion diff --git a/lib/core/types/api/index.js b/lib/core/types/api/index.js index c8ad2e549..91a2a321b 100644 --- a/lib/core/types/api/index.js +++ b/lib/core/types/api/index.js @@ -1,2 +1,3 @@ "use strict"; +// PubNub client API common types. Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/api/presence.js b/lib/core/types/api/presence.js index c8ad2e549..6c5bae6f7 100644 --- a/lib/core/types/api/presence.js +++ b/lib/core/types/api/presence.js @@ -1,2 +1,3 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +// endregion diff --git a/lib/core/types/api/push.js b/lib/core/types/api/push.js index c8ad2e549..6c5bae6f7 100644 --- a/lib/core/types/api/push.js +++ b/lib/core/types/api/push.js @@ -1,2 +1,3 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); +// endregion diff --git a/lib/core/types/file.js b/lib/core/types/file.js index c8ad2e549..6e7b7d2bf 100644 --- a/lib/core/types/file.js +++ b/lib/core/types/file.js @@ -1,2 +1,5 @@ "use strict"; +/** + * {@link PubNub} File object interface module. + */ Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/core/types/transport-request.js b/lib/core/types/transport-request.js index d24afce7b..f72b28210 100644 --- a/lib/core/types/transport-request.js +++ b/lib/core/types/transport-request.js @@ -1,11 +1,33 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TransportMethod = void 0; +/** + * Enum representing possible transport methods for HTTP requests. + * + * @enum {number} + */ var TransportMethod; (function (TransportMethod) { + /** + * Request will be sent using `GET` method. + */ TransportMethod["GET"] = "GET"; + /** + * Request will be sent using `POST` method. + */ TransportMethod["POST"] = "POST"; + /** + * Request will be sent using `PATCH` method. + */ TransportMethod["PATCH"] = "PATCH"; + /** + * Request will be sent using `DELETE` method. + */ TransportMethod["DELETE"] = "DELETE"; + /** + * Local request. + * + * Request won't be sent to the service and probably used to compute URL. + */ TransportMethod["LOCAL"] = "LOCAL"; })(TransportMethod || (exports.TransportMethod = TransportMethod = {})); diff --git a/lib/core/utils.js b/lib/core/utils.js index 2bd14eee4..bb200b5c0 100644 --- a/lib/core/utils.js +++ b/lib/core/utils.js @@ -1,16 +1,34 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.queryStringFromObject = exports.findUniqueCommonElements = exports.removeSingleOccurance = exports.encodeNames = exports.encodeString = void 0; +exports.queryStringFromObject = exports.findUniqueCommonElements = exports.removeSingleOccurrence = exports.encodeNames = exports.encodeString = void 0; +/** + * Percent-encode input string. + * + * **Note:** Encode content in accordance of the `PubNub` service requirements. + * + * @param input - Source string or number for encoding. + * + * @returns Percent-encoded string. + */ const encodeString = (input) => { return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); }; exports.encodeString = encodeString; +/** + * Percent-encode list of names (channels). + * + * @param names - List of names which should be encoded. + * + * @param [defaultString] - String which should be used in case if {@link names} is empty. + * + * @returns String which contains encoded names joined by non-encoded `,`. + */ const encodeNames = (names, defaultString) => { const encodedNames = names.map((name) => (0, exports.encodeString)(name)); return encodedNames.length ? encodedNames.join(',') : defaultString !== null && defaultString !== void 0 ? defaultString : ''; }; exports.encodeNames = encodeNames; -const removeSingleOccurance = (source, elementsToRemove) => { +const removeSingleOccurrence = (source, elementsToRemove) => { const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); return source.filter((e) => { if (elementsToRemove.includes(e) && !removed[e]) { @@ -20,11 +38,18 @@ const removeSingleOccurance = (source, elementsToRemove) => { return true; }); }; -exports.removeSingleOccurance = removeSingleOccurance; +exports.removeSingleOccurrence = removeSingleOccurrence; const findUniqueCommonElements = (a, b) => { return [...a].filter((value) => b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value)); }; exports.findUniqueCommonElements = findUniqueCommonElements; +/** + * Transform query key / value pairs to the string. + * + * @param query - Key / value pairs of the request query parameters. + * + * @returns Stringified query key / value pairs. + */ const queryStringFromObject = (query) => { return Object.keys(query) .map((key) => { diff --git a/lib/crypto/index.js b/lib/crypto/index.js index 3918c74e4..1e44d895d 100644 --- a/lib/crypto/index.js +++ b/lib/crypto/index.js @@ -1 +1,2 @@ "use strict"; +/** */ diff --git a/lib/crypto/modules/NodeCryptoModule/ICryptor.js b/lib/crypto/modules/NodeCryptoModule/ICryptor.js index c8ad2e549..e932a515b 100644 --- a/lib/crypto/modules/NodeCryptoModule/ICryptor.js +++ b/lib/crypto/modules/NodeCryptoModule/ICryptor.js @@ -1,2 +1,5 @@ "use strict"; +/** + * Cryptor module. + */ Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/crypto/modules/NodeCryptoModule/ILegacyCryptor.js b/lib/crypto/modules/NodeCryptoModule/ILegacyCryptor.js index c8ad2e549..afefd5492 100644 --- a/lib/crypto/modules/NodeCryptoModule/ILegacyCryptor.js +++ b/lib/crypto/modules/NodeCryptoModule/ILegacyCryptor.js @@ -1,2 +1,5 @@ "use strict"; +/** + * Legacy cryptor module. + */ Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js b/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js index c03ba9b34..b4f71ecd1 100644 --- a/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js +++ b/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js @@ -1,4 +1,7 @@ "use strict"; +/** + * AES-CBC cryptor module. + */ 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) { @@ -11,10 +14,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge Object.defineProperty(exports, "__esModule", { value: true }); const crypto_1 = require("crypto"); const stream_1 = require("stream"); +/** + * AES-CBC cryptor. + * + * AES-CBC cryptor with enhanced cipher strength. + */ class AesCbcCryptor { constructor({ cipherKey }) { this.cipherKey = cipherKey; } + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption encrypt(data) { const iv = this.getIv(); const key = this.getKey(); @@ -43,6 +55,11 @@ class AesCbcCryptor { }; }); } + // endregion + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption decrypt(input) { const data = typeof input.data === 'string' ? new TextEncoder().encode(input.data) : input.data; if (data.byteLength <= 0) @@ -84,21 +101,47 @@ class AesCbcCryptor { return decryptedStream; }); } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers get identifier() { return 'ACRH'; } + /** + * Cryptor algorithm. + * + * @returns Cryptor module algorithm. + */ get algo() { return 'aes-256-cbc'; } + /** + * Generate random initialization vector. + * + * @returns Random initialization vector. + */ getIv() { return (0, crypto_1.randomBytes)(AesCbcCryptor.BLOCK_SIZE); } + /** + * Convert cipher key to the {@link Buffer}. + * + * @returns SHA256 encoded cipher key {@link Buffer}. + */ getKey() { const sha = (0, crypto_1.createHash)('sha256'); sha.update(Buffer.from(this.cipherKey, 'utf8')); return Buffer.from(sha.digest()); } } +/** + * Cryptor block size. + */ AesCbcCryptor.BLOCK_SIZE = 16; +/** + * {@link string|String} to {@link ArrayBuffer} response decoder. + */ AesCbcCryptor.encoder = new TextEncoder(); exports.default = AesCbcCryptor; diff --git a/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js b/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js index e1c348040..a175eab75 100644 --- a/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js +++ b/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Legacy cryptor module. + */ 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) { @@ -16,12 +19,19 @@ const index_1 = __importDefault(require("../../../core/components/cryptography/i const base64_codec_1 = require("../../../core/components/base64_codec"); const pubnub_error_1 = require("../../../errors/pubnub-error"); const node_1 = __importDefault(require("../node")); +/** + * Legacy cryptor. + */ class LegacyCryptor { constructor(config) { this.config = config; this.cryptor = new index_1.default(Object.assign({}, config)); this.fileCryptor = new node_1.default(); } + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption encrypt(data) { if (data.length === 0) throw new Error('Encryption error: empty content'); @@ -37,6 +47,11 @@ class LegacyCryptor { return this.fileCryptor.encryptFile(this.config.cipherKey, file, File); }); } + // endregion + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption decrypt(encryptedData) { const data = typeof encryptedData.data === 'string' ? encryptedData.data : (0, base64_codec_1.encode)(encryptedData.data); return this.cryptor.decrypt(data); @@ -48,6 +63,11 @@ class LegacyCryptor { return this.fileCryptor.decryptFile(this.config.cipherKey, file, File); }); } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers get identifier() { return ''; } diff --git a/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js b/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js index bebd0de80..90e155a27 100644 --- a/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js +++ b/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Node.js crypto module. + */ 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) { @@ -22,7 +25,14 @@ const aesCbcCryptor_1 = __importDefault(require("./aesCbcCryptor")); exports.AesCbcCryptor = aesCbcCryptor_1.default; const legacyCryptor_1 = __importDefault(require("./legacyCryptor")); exports.LegacyCryptor = legacyCryptor_1.default; +/** + * CryptoModule for Node.js platform. + */ class CryptoModule extends crypto_module_1.AbstractCryptoModule { + // -------------------------------------------------------- + // --------------- Convenience functions ------------------ + // ------------------------------------------------------- + // region Convenience functions static legacyCryptoModule(config) { var _a; if (!config.cipherKey) @@ -43,16 +53,30 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { ], }); } + /** + * Construct crypto module with `cryptor` as default for data encryption and decryption. + * + * @param defaultCryptor - Default cryptor for data encryption and decryption. + * + * @returns Crypto module with pre-configured default cryptor. + */ static withDefaultCryptor(defaultCryptor) { return new this({ default: defaultCryptor }); } + // endregion + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption encrypt(data) { + // Encrypt data. const encrypted = data instanceof ArrayBuffer && this.defaultCryptor.identifier === CryptoModule.LEGACY_IDENTIFIER ? this.defaultCryptor.encrypt(CryptoModule.decoder.decode(data)) : this.defaultCryptor.encrypt(data); if (!encrypted.metadata) return encrypted.data; const headerData = this.getHeaderData(encrypted); + // Write encrypted data payload content. const encryptedData = typeof encrypted.data === 'string' ? CryptoModule.encoder.encode(encrypted.data).buffer : encrypted.data.buffer.slice(encrypted.data.byteOffset, encrypted.data.byteOffset + encrypted.data.length); @@ -60,6 +84,10 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { } encryptFile(file, File) { return __awaiter(this, void 0, void 0, function* () { + /** + * Files handled differently in case of Legacy cryptor. + * (as long as we support legacy need to check on instance type) + */ if (this.defaultCryptor.identifier === CryptorHeader.LEGACY_IDENTIFIER) return this.defaultCryptor.encryptFile(file, File); if (file.data instanceof buffer_1.Buffer) { @@ -95,6 +123,11 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { } }); } + // endregion + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption decrypt(data) { const encryptedData = buffer_1.Buffer.from(typeof data === 'string' ? (0, base64_codec_1.decode)(data) : data); const header = CryptorHeader.tryParse(encryptedData.buffer.slice(encryptedData.byteOffset, encryptedData.byteOffset + encryptedData.length)); @@ -114,6 +147,10 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { if (file.data && file.data instanceof buffer_1.Buffer) { const header = CryptorHeader.tryParse(file.data.buffer.slice(file.data.byteOffset, file.data.byteOffset + file.data.length)); const cryptor = this.getCryptor(header); + /** + * If It's legacy one then redirect it. + * (as long as we support legacy need to check on instance type) + */ if ((cryptor === null || cryptor === void 0 ? void 0 : cryptor.identifier) === CryptoModule.LEGACY_IDENTIFIER) return cryptor.decryptFile(file, File); return File.create({ @@ -129,15 +166,43 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { } }); } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + /** + * Retrieve registered legacy cryptor. + * + * @returns Previously registered {@link ILegacyCryptor|legacy} cryptor. + * + * @throws Error if legacy cryptor not registered. + */ getLegacyCryptor() { return this.getCryptorFromId(CryptoModule.LEGACY_IDENTIFIER); } + /** + * Retrieve registered cryptor by its identifier. + * + * @param id - Unique cryptor identifier. + * + * @returns Registered cryptor with specified identifier. + * + * @throws Error if cryptor with specified {@link id} can't be found. + */ getCryptorFromId(id) { const cryptor = this.getAllCryptors().find((cryptor) => id === cryptor.identifier); if (cryptor) return cryptor; throw new Error('Unknown cryptor error'); } + /** + * Retrieve cryptor by its identifier. + * + * @param header - Header with cryptor-defined data or raw cryptor identifier. + * + * @returns Cryptor which correspond to provided {@link header}. + */ getCryptor(header) { if (typeof header === 'string') { const cryptor = this.getAllCryptors().find((c) => c.identifier === header); @@ -149,6 +214,13 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { return this.getCryptorFromId(header.identifier); } } + /** + * Create cryptor header data. + * + * @param encrypted - Encryption data object as source for header data. + * + * @returns Binary representation of the cryptor header data. + */ getHeaderData(encrypted) { if (!encrypted.metadata) return; @@ -160,12 +232,31 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { headerData.set(new Uint8Array(encrypted.metadata), pos); return headerData.buffer; } + /** + * Merge two {@link ArrayBuffer} instances. + * + * @param ab1 - First {@link ArrayBuffer}. + * @param ab2 - Second {@link ArrayBuffer}. + * + * @returns Merged data as {@link ArrayBuffer}. + */ concatArrayBuffer(ab1, ab2) { const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); tmp.set(new Uint8Array(ab1), 0); tmp.set(new Uint8Array(ab2), ab1.byteLength); return tmp.buffer; } + /** + * {@link Readable} stream event handler. + * + * @param stream - Stream which can be used to read data for decryption. + * @param file - File object which has been created with {@link stream}. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ onStreamReadable(stream, file, File) { return __awaiter(this, void 0, void 0, function* () { stream.removeAllListeners('readable'); @@ -193,6 +284,17 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { }); }); } + /** + * Decrypt {@link Readable} stream using legacy cryptor. + * + * @param stream - Stream which can be used to read data for decryption. + * @param file - File object which has been created with {@link stream}. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ decryptLegacyFileStream(stream, file, File) { return __awaiter(this, void 0, void 0, function* () { if (!file.contentLength || file.contentLength <= 16) @@ -210,7 +312,13 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { } } exports.CryptoModule = CryptoModule; +/** + * {@link LegacyCryptor|Legacy} cryptor identifier. + */ CryptoModule.LEGACY_IDENTIFIER = ''; +/** + * CryptorHeader Utility + */ class CryptorHeader { static from(id, metadata) { if (id === CryptorHeader.LEGACY_IDENTIFIER) @@ -283,6 +391,9 @@ CryptorHeader.IDENTIFIER_LENGTH = 4; CryptorHeader.VERSION = 1; CryptorHeader.MAX_VERSION = 1; CryptorHeader.MIN_HEADER_LENGTH = 10; +/** + * Cryptor header (v1). + */ class CryptorHeaderV1 { constructor(id, metadataLength) { this._identifier = id; diff --git a/lib/crypto/modules/node.js b/lib/crypto/modules/node.js index 8e7d36a86..55c7865c2 100644 --- a/lib/crypto/modules/node.js +++ b/lib/crypto/modules/node.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Legacy Node.js cryptography module. + */ 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) { @@ -12,7 +15,14 @@ Object.defineProperty(exports, "__esModule", { value: true }); const crypto_1 = require("crypto"); const stream_1 = require("stream"); const buffer_1 = require("buffer"); +/** + * Legacy cryptography implementation for Node.js-based {@link PubNub} client. + */ class NodeCryptography { + // -------------------------------------------------------- + // --------------------- Encryption ----------------------- + // -------------------------------------------------------- + // region Encryption encrypt(key, input) { return __awaiter(this, void 0, void 0, function* () { const bKey = this.getKey(key); @@ -25,11 +35,27 @@ class NodeCryptography { throw new Error('Encryption error: unsupported input format'); }); } + /** + * Encrypt provided source {@link Buffer} using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link Buffer}. + * @param buffer - Source {@link Buffer} for encryption. + * + * @returns Encrypted data as {@link Buffer} object. + */ encryptBuffer(key, buffer) { const bIv = this.getIv(); const aes = (0, crypto_1.createCipheriv)(this.algo, key, bIv); return buffer_1.Buffer.concat([bIv, aes.update(buffer), aes.final()]); } + /** + * Encrypt provided source {@link Readable} stream using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link Readable} stream. + * @param stream - Source {@link Readable} stream for encryption. + * + * @returns Encrypted data as {@link Transform} object. + */ encryptStream(key, stream) { return __awaiter(this, void 0, void 0, function* () { const bIv = this.getIv(); @@ -48,6 +74,14 @@ class NodeCryptography { })); }); } + /** + * Encrypt provided source {@link string} using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link string}. + * @param text - Source {@link string} for encryption. + * + * @returns Encrypted data as byte {@link string}. + */ encryptString(key, text) { const bIv = this.getIv(); const bPlaintext = buffer_1.Buffer.from(text); @@ -57,6 +91,9 @@ class NodeCryptography { encryptFile(key, file, File) { return __awaiter(this, void 0, void 0, function* () { const bKey = this.getKey(key); + /** + * Buffer type check also covers `string` which converted to the `Buffer` during file object creation. + */ if (file.data instanceof buffer_1.Buffer) { if (file.data.byteLength <= 0) throw new Error('Encryption error: empty content.'); @@ -78,6 +115,11 @@ class NodeCryptography { throw new Error('Cannot encrypt this file. In Node.js file encryption supports only string, Buffer or Stream.'); }); } + // endregion + // -------------------------------------------------------- + // --------------------- Decryption ----------------------- + // -------------------------------------------------------- + // region Decryption decrypt(key, input) { return __awaiter(this, void 0, void 0, function* () { const bKey = this.getKey(key); @@ -94,6 +136,14 @@ class NodeCryptography { throw new Error('Decryption error: unsupported input format'); }); } + /** + * Decrypt provided encrypted {@link Buffer} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link Buffer}. + * @param buffer - Encrypted {@link Buffer} for decryption. + * + * @returns Decrypted data as {@link Buffer} object. + */ decryptBuffer(key, buffer) { const bIv = buffer.slice(0, NodeCryptography.IV_LENGTH); const bCiphertext = buffer.slice(NodeCryptography.IV_LENGTH); @@ -102,6 +152,14 @@ class NodeCryptography { const aes = (0, crypto_1.createDecipheriv)(this.algo, key, bIv); return buffer_1.Buffer.concat([aes.update(bCiphertext), aes.final()]); } + /** + * Decrypt provided encrypted {@link Readable} stream using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link Readable} stream. + * @param stream - Encrypted {@link Readable} stream for decryption. + * + * @returns Decrypted data as {@link Readable} object. + */ decryptStream(key, stream) { let aes = null; const output = new stream_1.PassThrough(); @@ -132,6 +190,14 @@ class NodeCryptography { }); return output; } + /** + * Decrypt provided encrypted {@link string} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link string}. + * @param text - Encrypted {@link string} for decryption. + * + * @returns Decrypted data as byte {@link string}. + */ decryptString(key, text) { const ciphertext = buffer_1.Buffer.from(text); const bIv = ciphertext.slice(0, NodeCryptography.IV_LENGTH); @@ -142,6 +208,9 @@ class NodeCryptography { decryptFile(key, file, File) { return __awaiter(this, void 0, void 0, function* () { const bKey = this.getKey(key); + /** + * Buffer type check also covers `string` which converted to the `Buffer` during file object creation. + */ if (file.data instanceof buffer_1.Buffer) { return File.create({ name: file.name, @@ -159,17 +228,42 @@ class NodeCryptography { throw new Error('Cannot decrypt this file. In Node.js file decryption supports only string, Buffer or Stream.'); }); } + // endregion + // -------------------------------------------------------- + // ----------------------- Helpers ------------------------ + // -------------------------------------------------------- + // region Helpers + /** + * Cryptography algorithm. + * + * @returns Cryptography module algorithm. + */ get algo() { return 'aes-256-cbc'; } + /** + * Convert cipher key to the {@link Buffer}. + * + * @param key - String cipher key. + * + * @returns SHA256 HEX encoded cipher key {@link Buffer}. + */ getKey(key) { const sha = (0, crypto_1.createHash)('sha256'); sha.update(buffer_1.Buffer.from(key, 'utf8')); return buffer_1.Buffer.from(sha.digest('hex').slice(0, 32), 'utf8'); } + /** + * Generate random initialization vector. + * + * @returns Random initialization vector. + */ getIv() { return (0, crypto_1.randomBytes)(NodeCryptography.IV_LENGTH); } } +/** + * Random initialization vector size. + */ NodeCryptography.IV_LENGTH = 16; exports.default = NodeCryptography; diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js index 193fd3562..1f09b98b7 100644 --- a/lib/errors/pubnub-api-error.js +++ b/lib/errors/pubnub-api-error.js @@ -1,4 +1,7 @@ "use strict"; +/** + * REST API endpoint use error module. + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -6,13 +9,34 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.PubNubAPIError = void 0; const categories_1 = __importDefault(require("../core/constants/categories")); const pubnub_error_1 = require("./pubnub-error"); +/** + * PubNub REST API call error. + */ class PubNubAPIError extends Error { + /** + * Construct API from known error object or {@link PubNub} service error response. + * + * @param errorOrResponse - `Error` or service error response object from which error information + * should be extracted. + * @param data - Preprocessed service error response. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ static create(errorOrResponse, data) { if (errorOrResponse instanceof Error) return PubNubAPIError.createFromError(errorOrResponse); else return PubNubAPIError.createFromServiceResponse(errorOrResponse, data); } + /** + * Create API error instance from other error object. + * + * @param error - `Error` object provided by network provider (mostly) or other {@link PubNub} client components. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ static createFromError(error) { let category = categories_1.default.PNUnknownCategory; let message = 'Unknown error'; @@ -65,6 +89,16 @@ class PubNubAPIError extends Error { category = categories_1.default.PNTimeoutCategory; return new PubNubAPIError(message, category, 0, error); } + /** + * Construct API from known {@link PubNub} service error response. + * + * @param response - Service error response object from which error information should be + * extracted. + * @param data - Preprocessed service error response. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ static createFromServiceResponse(response, data) { let category = categories_1.default.PNUnknownCategory; let errorData; @@ -81,6 +115,7 @@ class PubNubAPIError extends Error { category = categories_1.default.PNAccessDeniedCategory; message = 'Access denied'; } + // Try to get more information about error from service response. if (data && data.byteLength > 0) { const decoded = new TextDecoder().decode(data); if (response.headers['content-type'].indexOf('text/javascript') !== -1 || @@ -117,6 +152,14 @@ class PubNubAPIError extends Error { } return new PubNubAPIError(message, category, status, errorData); } + /** + * Construct PubNub endpoint error. + * + * @param message - Short API call error description. + * @param category - Error category. + * @param statusCode - Response HTTP status code. + * @param errorData - Error information. + */ constructor(message, category, statusCode, errorData) { super(message); this.category = category; @@ -124,6 +167,13 @@ class PubNubAPIError extends Error { this.errorData = errorData; this.name = 'PubNubAPIError'; } + /** + * Convert API error object to API callback status object. + * + * @param operation - Request operation during which error happened. + * + * @returns Pre-formatted API callback status object. + */ toStatus(operation) { return { error: true, @@ -133,6 +183,14 @@ class PubNubAPIError extends Error { errorData: this.errorData, }; } + /** + * Convert API error object to PubNub client error object. + * + * @param operation - Request operation during which error happened. + * @param message - Custom error message. + * + * @returns Client-facing pre-formatted endpoint call error. + */ toPubNubError(operation, message) { return new pubnub_error_1.PubNubError(message !== null && message !== void 0 ? message : this.message, this.toStatus(operation)); } diff --git a/lib/event-engine/core/change.js b/lib/event-engine/core/change.js index c8ad2e549..2b5963b5c 100644 --- a/lib/event-engine/core/change.js +++ b/lib/event-engine/core/change.js @@ -1,2 +1,3 @@ "use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/event-engine/core/dispatcher.js b/lib/event-engine/core/dispatcher.js index 4cfc94966..2be9c3fdf 100644 --- a/lib/event-engine/core/dispatcher.js +++ b/lib/event-engine/core/dispatcher.js @@ -1,4 +1,5 @@ "use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Dispatcher = void 0; class Dispatcher { diff --git a/lib/event-engine/core/engine.js b/lib/event-engine/core/engine.js index 351df033f..d94c9c482 100644 --- a/lib/event-engine/core/engine.js +++ b/lib/event-engine/core/engine.js @@ -1,4 +1,5 @@ "use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Engine = void 0; const subject_1 = require("../../core/components/subject"); diff --git a/lib/event-engine/core/handler.js b/lib/event-engine/core/handler.js index 88bead570..de66460b8 100644 --- a/lib/event-engine/core/handler.js +++ b/lib/event-engine/core/handler.js @@ -17,6 +17,8 @@ class AsyncHandler extends Handler { } start() { this.asyncFunction(this.payload, this.abortSignal, this.dependencies).catch((error) => { + // console.log('Unhandled error:', error); + // swallow the error }); } cancel() { diff --git a/lib/event-engine/core/retryPolicy.js b/lib/event-engine/core/retryPolicy.js index a038d25c3..f822b4979 100644 --- a/lib/event-engine/core/retryPolicy.js +++ b/lib/event-engine/core/retryPolicy.js @@ -6,6 +6,7 @@ class RetryPolicy { return { delay: configuration.delay, maximumRetry: configuration.maximumRetry, + /* eslint-disable @typescript-eslint/no-explicit-any */ shouldRetry(error, attempt) { var _a; if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { @@ -18,6 +19,7 @@ class RetryPolicy { const delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : this.delay; return (delay + Math.random()) * 1000; }, + /* eslint-disable @typescript-eslint/no-explicit-any */ getGiveupReason(error, attempt) { var _a; if (this.maximumRetry <= attempt) { diff --git a/lib/event-engine/core/state.js b/lib/event-engine/core/state.js index 88c83cf6a..06d02193c 100644 --- a/lib/event-engine/core/state.js +++ b/lib/event-engine/core/state.js @@ -1,4 +1,5 @@ "use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.State = void 0; class State { diff --git a/lib/event-engine/core/types.js b/lib/event-engine/core/types.js index 85dc4a919..8d5546c4b 100644 --- a/lib/event-engine/core/types.js +++ b/lib/event-engine/core/types.js @@ -1,4 +1,5 @@ "use strict"; +/* eslint-disable @typescript-eslint/no-explicit-any */ Object.defineProperty(exports, "__esModule", { value: true }); exports.createManagedEffect = exports.createEffect = exports.createEvent = void 0; function createEvent(type, fn) { diff --git a/lib/event-engine/index.js b/lib/event-engine/index.js index fd48c7427..697416481 100644 --- a/lib/event-engine/index.js +++ b/lib/event-engine/index.js @@ -67,11 +67,11 @@ class EventEngine { } } unsubscribe({ channels = [], channelGroups = [] }) { - const filteredChannels = utils.removeSingleOccurance(this.channels, [ + const filteredChannels = utils.removeSingleOccurrence(this.channels, [ ...channels, ...channels.map((c) => `${c}-pnpres`), ]); - const filteredGroups = utils.removeSingleOccurance(this.groups, [ + const filteredGroups = utils.removeSingleOccurrence(this.groups, [ ...channelGroups, ...channelGroups.map((c) => `${c}-pnpres`), ]); diff --git a/lib/event-engine/presence/effects.js b/lib/event-engine/presence/effects.js index beab7cbc6..d6f4d5671 100644 --- a/lib/event-engine/presence/effects.js +++ b/lib/event-engine/presence/effects.js @@ -10,6 +10,7 @@ exports.leave = (0, core_1.createEffect)('LEAVE', (channels, groups) => ({ channels, groups, })); +/* eslint-disable @typescript-eslint/no-explicit-any */ exports.emitStatus = (0, core_1.createEffect)('EMIT_STATUS', (status) => status); exports.wait = (0, core_1.createManagedEffect)('WAIT', () => ({})); exports.delayedHeartbeat = (0, core_1.createManagedEffect)('DELAYED_HEARTBEAT', (context) => context); diff --git a/lib/file/modules/node.js b/lib/file/modules/node.js index 5b0c17841..90f4759e6 100644 --- a/lib/file/modules/node.js +++ b/lib/file/modules/node.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Node.js {@link PubNub} File object module. + */ 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) { @@ -16,7 +19,14 @@ const stream_1 = require("stream"); const buffer_1 = require("buffer"); const path_1 = require("path"); const fs_1 = __importDefault(require("fs")); +// endregion +/** + * Node.js implementation for {@link PubNub} File object. + * + * **Important:** Class should implement constructor and class fields from {@link PubNubFileConstructor}. + */ class PubNubFile { + // endregion static create(file) { return new PubNubFile(file); } @@ -36,6 +46,7 @@ class PubNubFile { } else if (data instanceof buffer_1.Buffer) { contentLength = data.length; + // Copy content of the source Buffer. fileData = buffer_1.Buffer.alloc(contentLength); data.copy(fileData); } @@ -63,6 +74,11 @@ class PubNubFile { this.data = fileData; this.name = fileName; } + /** + * Convert {@link PubNub} File object content to {@link Buffer}. + * + * @returns Asynchronous results of conversion to the {@link Buffer}. + */ toBuffer() { return __awaiter(this, void 0, void 0, function* () { if (this.data instanceof buffer_1.Buffer) @@ -76,20 +92,36 @@ class PubNubFile { stream.on('end', () => { resolve(buffer_1.Buffer.concat(chunks)); }); + // Handle any errors during streaming stream.on('error', (error) => reject(error)); }); }); } + /** + * Convert {@link PubNub} File object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + */ toArrayBuffer() { return __awaiter(this, void 0, void 0, function* () { return this.toBuffer().then((buffer) => buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.length)); }); } + /** + * Convert {@link PubNub} File object content to {@link string}. + * + * @returns Asynchronous results of conversion to the {@link string}. + */ toString() { return __awaiter(this, arguments, void 0, function* (encoding = 'utf8') { return this.toBuffer().then((buffer) => buffer.toString(encoding)); }); } + /** + * Convert {@link PubNub} File object content to {@link Readable} stream. + * + * @returns Asynchronous results of conversion to the {@link Readable} stream. + */ toStream() { return __awaiter(this, void 0, void 0, function* () { if (this.data instanceof stream_1.Readable) { @@ -105,28 +137,68 @@ class PubNubFile { })); }); } + /** + * Convert {@link PubNub} File object content to {@link File}. + * + * @throws Error because {@link File} not available in Node.js environment. + */ toFile() { return __awaiter(this, void 0, void 0, function* () { throw new Error('This feature is only supported in browser environments.'); }); } + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @throws Error because file `Uri` not available in Node.js environment. + */ toFileUri() { return __awaiter(this, void 0, void 0, function* () { throw new Error('This feature is only supported in React Native environments.'); }); } + /** + * Convert {@link PubNub} File object content to {@link Blob}. + * + * @throws Error because {@link Blob} not available in Node.js environment. + */ toBlob() { return __awaiter(this, void 0, void 0, function* () { throw new Error('This feature is only supported in browser environments.'); }); } } +// region Class properties +/** + * Whether {@link Blob} data supported by platform or not. + */ PubNubFile.supportsBlob = false; +/** + * Whether {@link File} data supported by platform or not. + */ PubNubFile.supportsFile = false; +/** + * Whether {@link Buffer} data supported by platform or not. + */ PubNubFile.supportsBuffer = true; +/** + * Whether {@link Stream} data supported by platform or not. + */ PubNubFile.supportsStream = true; +/** + * Whether {@link String} data supported by platform or not. + */ PubNubFile.supportsString = true; +/** + * Whether {@link ArrayBuffer} supported by platform or not. + */ PubNubFile.supportsArrayBuffer = true; +/** + * Whether {@link PubNub} File object encryption supported or not. + */ PubNubFile.supportsEncryptFile = true; +/** + * Whether `File Uri` data supported by platform or not. + */ PubNubFile.supportsFileUri = false; exports.default = PubNubFile; diff --git a/lib/file/modules/react-native.js b/lib/file/modules/react-native.js index b66464e3a..4088586dd 100644 --- a/lib/file/modules/react-native.js +++ b/lib/file/modules/react-native.js @@ -1,4 +1,8 @@ "use strict"; +/* global File, FileReader */ +/** + * React Native {@link PubNub} File object module. + */ 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) { @@ -10,7 +14,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PubNubFile = void 0; +// endregion class PubNubFile { + // endregion static create(file) { return new PubNubFile(file); } @@ -53,11 +59,24 @@ class PubNubFile { this.data = fileData; this.name = fileName; } + /** + * Convert {@link PubNub} File object content to {@link Buffer}. + * + * @throws Error because {@link Buffer} not available in React Native environment. + */ toBuffer() { return __awaiter(this, void 0, void 0, function* () { throw new Error('This feature is only supported in Node.js environments.'); }); } + /** + * Convert {@link PubNub} File object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ toArrayBuffer() { return __awaiter(this, void 0, void 0, function* () { if (this.data && this.data instanceof File) { @@ -88,6 +107,11 @@ class PubNubFile { throw new Error('Unable convert provided file content type to ArrayBuffer'); }); } + /** + * Convert {@link PubNub} File object content to {@link string}. + * + * @returns Asynchronous results of conversion to the {@link string}. + */ toString() { return __awaiter(this, void 0, void 0, function* () { if (this.data && 'uri' in this.data) @@ -107,11 +131,24 @@ class PubNubFile { return this.data.text(); }); } + /** + * Convert {@link PubNub} File object content to {@link Readable} stream. + * + * @throws Error because {@link Readable} stream not available in React Native environment. + */ toStream() { return __awaiter(this, void 0, void 0, function* () { throw new Error('This feature is only supported in Node.js environments.'); }); } + /** + * Convert {@link PubNub} File object content to {@link File}. + * + * @returns Asynchronous results of conversion to the {@link File}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ toFile() { return __awaiter(this, void 0, void 0, function* () { if (this.data instanceof File) @@ -122,6 +159,14 @@ class PubNubFile { return this.data.blob(); }); } + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @returns Asynchronous results of conversion to file `Uri`. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ toFileUri() { return __awaiter(this, void 0, void 0, function* () { if (this.data && 'uri' in this.data) @@ -129,6 +174,14 @@ class PubNubFile { throw new Error('This file does not contain a file URI'); }); } + /** + * Convert {@link PubNub} File object content to {@link Blob}. + * + * @returns Asynchronous results of conversion to the {@link Blob}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ toBlob() { return __awaiter(this, void 0, void 0, function* () { if (this.data instanceof File) @@ -141,12 +194,37 @@ class PubNubFile { } } exports.PubNubFile = PubNubFile; +// region Class properties +/** + * Whether {@link Blob} data supported by platform or not. + */ PubNubFile.supportsBlob = typeof Blob !== 'undefined'; +/** + * Whether {@link File} data supported by platform or not. + */ PubNubFile.supportsFile = typeof File !== 'undefined'; +/** + * Whether {@link Buffer} data supported by platform or not. + */ PubNubFile.supportsBuffer = false; +/** + * Whether {@link Stream} data supported by platform or not. + */ PubNubFile.supportsStream = false; +/** + * Whether {@link String} data supported by platform or not. + */ PubNubFile.supportsString = true; +/** + * Whether {@link ArrayBuffer} supported by platform or not. + */ PubNubFile.supportsArrayBuffer = true; +/** + * Whether {@link PubNub} File object encryption supported or not. + */ PubNubFile.supportsEncryptFile = false; +/** + * Whether `File Uri` data supported by platform or not. + */ PubNubFile.supportsFileUri = true; exports.default = PubNubFile; diff --git a/lib/node/configuration.js b/lib/node/configuration.js index 2bdbc0ccc..f0dca5397 100644 --- a/lib/node/configuration.js +++ b/lib/node/configuration.js @@ -1,10 +1,31 @@ "use strict"; +/** + * Node.js specific {@link PubNub} client configuration module. + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.setDefaults = void 0; const configuration_1 = require("../core/interfaces/configuration"); +// -------------------------------------------------------- +// ----------------------- Defaults ----------------------- +// -------------------------------------------------------- +// region Defaults +/** + * Whether PubNub client should try utilize existing TCP connection for new requests or not. + */ const KEEP_ALIVE = false; +/** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + * + * @returns Extended {@link PubNub} client configuration object pre-filled with default values. + * + * @internal + */ const setDefaults = (configuration) => { var _a; - return Object.assign(Object.assign({}, (0, configuration_1.setDefaults)(configuration)), { keepAlive: (_a = configuration.keepAlive) !== null && _a !== void 0 ? _a : KEEP_ALIVE }); + return Object.assign(Object.assign({}, (0, configuration_1.setDefaults)(configuration)), { + // Set platform-specific options. + keepAlive: (_a = configuration.keepAlive) !== null && _a !== void 0 ? _a : KEEP_ALIVE }); }; exports.setDefaults = setDefaults; diff --git a/lib/node/index.js b/lib/node/index.js index 5fd5e321e..eed5fb4a0 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -2,7 +2,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; -var _a; const cbor_sync_1 = __importDefault(require("cbor-sync")); const buffer_1 = require("buffer"); const nodeCryptoModule_1 = require("../crypto/modules/NodeCryptoModule/nodeCryptoModule"); @@ -18,50 +17,71 @@ const cryptography_1 = __importDefault(require("../core/components/cryptography" const pubnub_error_1 = require("../errors/pubnub-error"); const pubnub_common_1 = require("../core/pubnub-common"); const common_1 = __importDefault(require("../cbor/common")); -module.exports = (_a = class PubNub extends pubnub_common_1.PubNubCore { - constructor(configuration) { - const configurationCopy = (0, configuration_2.setDefaults)(configuration); - const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'Nodejs', PubNubFile: node_1.default }); - const clientConfiguration = (0, configuration_1.makeConfiguration)(platformConfiguration, (cryptoConfiguration) => { - if (!cryptoConfiguration.cipherKey) - return undefined; - return new nodeCryptoModule_1.CryptoModule({ - default: new nodeCryptoModule_1.LegacyCryptor(Object.assign({}, cryptoConfiguration)), - cryptors: [new nodeCryptoModule_1.AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], - }); +/** + * PubNub client for Node.js platform. + */ +class PubNub extends pubnub_common_1.PubNubCore { + constructor(configuration) { + const configurationCopy = (0, configuration_2.setDefaults)(configuration); + const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'Nodejs', PubNubFile: node_1.default }); + // Prepare full client configuration. + const clientConfiguration = (0, configuration_1.makeConfiguration)(platformConfiguration, (cryptoConfiguration) => { + if (!cryptoConfiguration.cipherKey) + return undefined; + return new nodeCryptoModule_1.CryptoModule({ + default: new nodeCryptoModule_1.LegacyCryptor(Object.assign({}, cryptoConfiguration)), + cryptors: [new nodeCryptoModule_1.AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], }); - const tokenManager = new token_manager_1.TokenManager(new common_1.default((buffer) => cbor_sync_1.default.decode(buffer_1.Buffer.from(buffer)), base64_codec_1.decode)); - const crypto = new cryptography_1.default({ - secretKey: clientConfiguration.secretKey, - cipherKey: clientConfiguration.getCipherKey(), - useRandomIVs: clientConfiguration.getUseRandomIVs(), - customEncrypt: clientConfiguration.getCustomEncrypt(), - customDecrypt: clientConfiguration.getCustomDecrypt(), - }); - const transport = new node_transport_1.NodeTransport(configuration.keepAlive, configuration.keepAliveSettings); - const transportMiddleware = new middleware_1.PubNubMiddleware({ - clientConfiguration, - tokenManager, - transport, - shaHMAC: crypto === null || crypto === void 0 ? void 0 : crypto.HMACSHA256.bind(crypto), - }); - super({ - configuration: clientConfiguration, - transport: transportMiddleware, - cryptography: new node_2.default(), - tokenManager, - crypto, - }); - this.File = node_1.default; - this.nodeTransport = transport; - } - setProxy(configuration) { - var _b; - if (configuration && ((_b = this._configuration.keepAlive) !== null && _b !== void 0 ? _b : false)) - throw new pubnub_error_1.PubNubError("Can't set 'proxy' because already configured for 'keepAlive'"); - this.nodeTransport.setProxy(configuration); - this.reconnect(); - } - }, - _a.CryptoModule = nodeCryptoModule_1.CryptoModule, - _a); + }); + // Prepare Token manager. + const tokenManager = new token_manager_1.TokenManager(new common_1.default((buffer) => cbor_sync_1.default.decode(buffer_1.Buffer.from(buffer)), base64_codec_1.decode)); + // Legacy crypto (legacy data encryption / decryption and request signature support). + const crypto = new cryptography_1.default({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + // Setup transport provider. + const transport = new node_transport_1.NodeTransport(configuration.keepAlive, configuration.keepAliveSettings); + const transportMiddleware = new middleware_1.PubNubMiddleware({ + clientConfiguration, + tokenManager, + transport, + shaHMAC: crypto === null || crypto === void 0 ? void 0 : crypto.HMACSHA256.bind(crypto), + }); + super({ + configuration: clientConfiguration, + transport: transportMiddleware, + cryptography: new node_2.default(), + tokenManager, + crypto, + }); + /** + * PubNub File constructor. + */ + this.File = node_1.default; + this.nodeTransport = transport; + } + /** + * Update request proxy configuration. + * + * @param configuration - Updated request proxy configuration. + * + * @throws An error if {@link PubNub} client already configured to use `keepAlive`. + * `keepAlive` and `proxy` can't be used simultaneously. + */ + setProxy(configuration) { + var _a; + if (configuration && ((_a = this._configuration.keepAlive) !== null && _a !== void 0 ? _a : false)) + throw new pubnub_error_1.PubNubError("Can't set 'proxy' because already configured for 'keepAlive'"); + this.nodeTransport.setProxy(configuration); + this.reconnect(); + } +} +/** + * Data encryption / decryption module constructor. + */ +PubNub.CryptoModule = nodeCryptoModule_1.CryptoModule; +module.exports = PubNub; diff --git a/lib/react_native/configuration.js b/lib/react_native/configuration.js index 3d4e24615..c88065595 100644 --- a/lib/react_native/configuration.js +++ b/lib/react_native/configuration.js @@ -2,6 +2,13 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.setDefaults = void 0; const configuration_1 = require("../core/interfaces/configuration"); +/** + * Apply configuration default values. + * + * @param configuration - User-provided configuration. + * + * @internal + */ const setDefaults = (configuration) => { return (0, configuration_1.setDefaults)(configuration); }; diff --git a/lib/react_native/index.js b/lib/react_native/index.js index 7345921f2..606e5d543 100644 --- a/lib/react_native/index.js +++ b/lib/react_native/index.js @@ -18,15 +18,22 @@ const cryptography_1 = __importDefault(require("../core/components/cryptography" const pubnub_common_1 = require("../core/pubnub-common"); const configuration_2 = require("./configuration"); const common_1 = __importDefault(require("../cbor/common")); +// Polyfill global environment global.TextEncoder = global.TextEncoder || text_encoding_1.TextEncoder; global.TextDecoder = global.TextDecoder || text_encoding_1.TextDecoder; global.Buffer = global.Buffer || buffer_1.Buffer; +/** + * PubNub client for React Native platform. + */ class PubNub extends pubnub_common_1.PubNubCore { constructor(configuration) { const configurationCopy = (0, configuration_2.setDefaults)(configuration); const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'ReactNative', PubNubFile: react_native_1.default }); + // Prepare full client configuration. const clientConfiguration = (0, configuration_1.makeConfiguration)(platformConfiguration); + // Prepare Token manager. const tokenManager = new token_manager_1.TokenManager(new common_1.default((arrayBuffer) => (0, stringify_buffer_keys_1.stringifyBufferKeys)(cbor_js_1.default.decode(arrayBuffer)), base64_codec_1.decode)); + // Legacy crypto (legacy data encryption / decryption and request signature support). let crypto; if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { crypto = new cryptography_1.default({ @@ -37,6 +44,7 @@ class PubNub extends pubnub_common_1.PubNubCore { customDecrypt: clientConfiguration.getCustomDecrypt(), }); } + // Setup transport layer. const transportMiddleware = new middleware_1.PubNubMiddleware({ clientConfiguration, tokenManager, diff --git a/lib/transport/middleware.js b/lib/transport/middleware.js index 7433a00a1..61519ad44 100644 --- a/lib/transport/middleware.js +++ b/lib/transport/middleware.js @@ -9,6 +9,12 @@ class RequestSignature { this.secretKey = secretKey; this.hasher = hasher; } + /** + * Compute request signature. + * + * @param req - Request which will be used to compute signature. + * @returns {string} `v2` request signature. + */ signature(req) { const method = req.path.startsWith('/publish') ? transport_request_1.TransportMethod.GET : req.method; let signatureInput = `${method}\n${this.publishKey}\n${req.path}\n${this.queryParameters(req.queryParameters)}\n`; @@ -29,6 +35,12 @@ class RequestSignature { .replace(/\//g, '_') .replace(/=+$/, ''); } + /** + * Prepare request query parameters for signature. + * + * @param query - Key / value pair of the request query parameters. + * @private + */ queryParameters(query) { return Object.keys(query) .sort() @@ -59,9 +71,11 @@ class PubNubMiddleware { request(req) { var _a; const { clientConfiguration } = this.configuration; + // Get request patched by transport provider. req = this.configuration.transport.request(req); if (!req.queryParameters) req.queryParameters = {}; + // Modify request with required information. if (clientConfiguration.useInstanceId) req.queryParameters['instanceid'] = clientConfiguration.instanceId; if (!req.queryParameters['uuid']) @@ -70,12 +84,15 @@ class PubNubMiddleware { req.queryParameters['requestid'] = req.identifier; req.queryParameters['pnsdk'] = this.generatePNSDK(); (_a = req.origin) !== null && _a !== void 0 ? _a : (req.origin = clientConfiguration.origin); + // Authenticate request if required. this.authenticateRequest(req); + // Sign request if it is required. this.signRequest(req); return req; } authenticateRequest(req) { var _a; + // Access management endpoints doesn't need authentication (signature required instead). if (req.path.startsWith('/v2/auth/') || req.path.startsWith('/v3/pam/') || req.path.startsWith('/time')) return; const { clientConfiguration, tokenManager } = this.configuration; @@ -83,12 +100,25 @@ class PubNubMiddleware { if (accessKey) req.queryParameters['auth'] = accessKey; } + /** + * Compute and append request signature. + * + * @param req - Transport request with information which should be used to generate signature. + */ signRequest(req) { if (!this.signatureGenerator || req.path.startsWith('/time')) return; req.queryParameters['timestamp'] = String(Math.floor(new Date().getTime() / 1000)); req.queryParameters['signature'] = this.signatureGenerator.signature(req); } + /** + * Compose `pnsdk` query parameter. + * + * SDK provides ability to set custom name or append vendor information to the `pnsdk` query + * parameter. + * + * @returns Finalized `pnsdk` query parameter value. + */ generatePNSDK() { const { clientConfiguration } = this.configuration; if (clientConfiguration.sdkName) diff --git a/lib/transport/node-transport.js b/lib/transport/node-transport.js index 80418e7c2..95a8b911b 100644 --- a/lib/transport/node-transport.js +++ b/lib/transport/node-transport.js @@ -44,12 +44,29 @@ const form_data_1 = __importDefault(require("form-data")); const buffer_1 = require("buffer"); const pubnub_api_error_1 = require("../errors/pubnub-api-error"); const utils_1 = require("../core/utils"); +/** + * Class representing a fetch-based Node.js transport provider. + */ class NodeTransport { + /** + * Creates a new `fetch`-based transport instance. + * + * @param keepAlive - Indicates whether keep-alive should be enabled. + * @param [keepAliveSettings] - Optional settings for keep-alive. + * @param [logVerbosity] - Whether verbose logging enabled or not. + * + * @returns Transport for performing network requests. + */ constructor(keepAlive = false, keepAliveSettings = { timeout: 30000 }, logVerbosity = false) { this.keepAlive = keepAlive; this.keepAliveSettings = keepAliveSettings; this.logVerbosity = logVerbosity; } + /** + * Update request proxy configuration. + * + * @param configuration - New proxy configuration. + */ setProxy(configuration) { this.proxyConfiguration = configuration; } @@ -59,6 +76,7 @@ class NodeTransport { if (req.cancellable) { abortController = new AbortController(); controller = { + // Storing controller inside to prolong object lifetime. abortController, abort: () => abortController === null || abortController === void 0 ? void 0 : abortController.abort(), }; @@ -76,6 +94,7 @@ class NodeTransport { const responseBody = response[1].byteLength > 0 ? response[1] : undefined; const { status, headers: requestHeaders } = response[0]; const headers = {}; + // Copy Headers object content into plain Record. requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); const transportResponse = { status, @@ -98,12 +117,21 @@ class NodeTransport { request(req) { return req; } + /** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + */ requestFromTransportRequest(req) { return __awaiter(this, void 0, void 0, function* () { let headers = req.headers; let body; let path = req.path; + // Create multipart request body. if (req.formData && req.formData.length > 0) { + // Reset query parameters to conform to signed URL req.queryParameters = {}; const file = req.body; const fileData = yield file.toArrayBuffer(); @@ -114,6 +142,7 @@ class NodeTransport { body = formData; headers = formData.getHeaders(headers !== null && headers !== void 0 ? headers : {}); } + // Handle regular body payload (if passed). else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) body = req.body; if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) @@ -127,11 +156,24 @@ class NodeTransport { }); }); } + /** + * Determines and returns the appropriate agent for a given transport request. + * + * If keep alive is not requested, returns undefined. + * + * @param req - The transport request object. + * + * @returns {HttpAgent | HttpsAgent | undefined} - The appropriate agent for the request, or + * undefined if keep alive or proxy not requested. + */ agentForTransportRequest(req) { + // Don't configure any agents if keep alive not requested. if (!this.keepAlive && !this.proxyConfiguration) return undefined; + // Create proxy agent (if possible). if (this.proxyConfiguration) return this.proxyAgent ? this.proxyAgent : (this.proxyAgent = new proxy_agent_1.ProxyAgent(this.proxyConfiguration)); + // Create keep alive agent. const useSecureAgent = req.origin.startsWith('https:'); if (useSecureAgent && this.httpsAgent === undefined) this.httpsAgent = new https_1.Agent(Object.assign({ keepAlive: true }, this.keepAliveSettings)); @@ -140,6 +182,13 @@ class NodeTransport { } return useSecureAgent ? this.httpsAgent : this.httpAgent; } + /** + * Log out request processing progress and result. + * + * @param request - Platform-specific request object. + * @param [elapsed] - How many times passed since request processing started. + * @param [body] - Service response (if available). + */ logRequestProcessProgress(request, elapsed, body) { if (!this.logVerbosity) return; @@ -159,4 +208,7 @@ class NodeTransport { } } exports.NodeTransport = NodeTransport; +/** + * Service {@link ArrayBuffer} response decoder. + */ NodeTransport.decoder = new TextDecoder(); diff --git a/lib/transport/web-react-native-transport.js b/lib/transport/web-react-native-transport.js index bf09f69d2..9c18341a2 100644 --- a/lib/transport/web-react-native-transport.js +++ b/lib/transport/web-react-native-transport.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Common browser and React Native Transport provider module. + */ 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) { @@ -12,6 +15,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.WebReactNativeTransport = void 0; const pubnub_api_error_1 = require("../errors/pubnub-api-error"); const utils_1 = require("../core/utils"); +/** + * Class representing a `fetch`-based browser and React Native transport provider. + */ class WebReactNativeTransport { constructor(keepAlive = false, logVerbosity) { this.keepAlive = keepAlive; @@ -23,6 +29,7 @@ class WebReactNativeTransport { if (req.cancellable) { abortController = new AbortController(); controller = { + // Storing controller inside to prolong object lifetime. abortController, abort: () => abortController === null || abortController === void 0 ? void 0 : abortController.abort(), }; @@ -31,8 +38,14 @@ class WebReactNativeTransport { this.requestFromTransportRequest(req).then((request) => { const start = new Date().getTime(); this.logRequestProcessProgress(request); + /** + * Setup request timeout promise. + * + * **Note:** Native Fetch API doesn't support `timeout` out-of-box. + */ const requestTimeout = new Promise((_, reject) => { const timeoutId = setTimeout(() => { + // Clean up. clearTimeout(timeoutId); reject(new Error('Request timeout')); }, req.timeout * 1000); @@ -43,6 +56,7 @@ class WebReactNativeTransport { const responseBody = response[1].byteLength > 0 ? response[1] : undefined; const { status, headers: requestHeaders } = response[0]; const headers = {}; + // Copy Headers object content into plain Record. requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); const transportResponse = { status, @@ -65,11 +79,20 @@ class WebReactNativeTransport { request(req) { return req; } + /** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + */ requestFromTransportRequest(req) { return __awaiter(this, void 0, void 0, function* () { let body; let path = req.path; + // Create multipart request body. if (req.formData && req.formData.length > 0) { + // Reset query parameters to conform to signed URL req.queryParameters = {}; const file = req.body; const formData = new FormData(); @@ -82,12 +105,14 @@ class WebReactNativeTransport { catch (_) { try { const fileData = yield file.toFileUri(); + // @ts-expect-error React Native File Uri support. formData.append('file', fileData, file.name); } catch (_) { } } body = formData; } + // Handle regular body payload (if passed). else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) body = req.body; if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) @@ -100,6 +125,13 @@ class WebReactNativeTransport { }); }); } + /** + * Log out request processing progress and result. + * + * @param request - Platform-specific + * @param [elapsed] - How many seconds passed since request processing started. + * @param [body] - Service response (if available). + */ logRequestProcessProgress(request, elapsed, body) { if (!this.logVerbosity) return; @@ -119,4 +151,7 @@ class WebReactNativeTransport { } } exports.WebReactNativeTransport = WebReactNativeTransport; +/** + * Service {@link ArrayBuffer} response decoder. + */ WebReactNativeTransport.decoder = new TextDecoder(); diff --git a/lib/types/cbor/common.d.ts b/lib/types/cbor/common.d.ts new file mode 100644 index 000000000..4ccbdd2ba --- /dev/null +++ b/lib/types/cbor/common.d.ts @@ -0,0 +1,4 @@ +/** + * Cbor decoder module. + */ +export {}; diff --git a/lib/types/core/components/abort_signal.d.ts b/lib/types/core/components/abort_signal.d.ts new file mode 100644 index 000000000..926a042d3 --- /dev/null +++ b/lib/types/core/components/abort_signal.d.ts @@ -0,0 +1,4 @@ +export declare class AbortError extends Error { + name: string; + constructor(); +} diff --git a/lib/types/core/components/base64_codec.d.ts b/lib/types/core/components/base64_codec.d.ts new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/lib/types/core/components/base64_codec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/types/core/components/configuration.d.ts b/lib/types/core/components/configuration.d.ts new file mode 100644 index 000000000..2fb4a5f80 --- /dev/null +++ b/lib/types/core/components/configuration.d.ts @@ -0,0 +1,4 @@ +/** + * {@link PubNub} client configuration module. + */ +export {}; diff --git a/lib/types/core/components/cryptography/hmac-sha256.d.ts b/lib/types/core/components/cryptography/hmac-sha256.d.ts new file mode 100644 index 000000000..112f25199 --- /dev/null +++ b/lib/types/core/components/cryptography/hmac-sha256.d.ts @@ -0,0 +1,3 @@ +export namespace mode { + let ECB: any; +} diff --git a/lib/types/core/components/cryptography/index.d.ts b/lib/types/core/components/cryptography/index.d.ts new file mode 100644 index 000000000..b3f187c0b --- /dev/null +++ b/lib/types/core/components/cryptography/index.d.ts @@ -0,0 +1,143 @@ +/** + * Legacy cryptography module. + */ +import { CryptorConfiguration } from '../../interfaces/crypto-module'; +import { Payload } from '../../types/api'; +/** + * Legacy cryptor configuration options. + */ +type CryptoConfiguration = { + encryptKey?: boolean; + keyEncoding?: 'hex' | 'utf8' | 'base64' | 'binary'; + keyLength?: 128 | 256; + mode?: 'ecb' | 'cbc'; +}; +export default class { + private readonly configuration; + /** + * Crypto initialization vector. + */ + private iv; + /** + * List os allowed cipher key encodings. + */ + private allowedKeyEncodings; + /** + * Allowed cipher key lengths. + */ + private allowedKeyLengths; + /** + * Allowed crypto modes. + */ + private allowedModes; + /** + * Default cryptor configuration options. + */ + private readonly defaultOptions; + constructor(configuration: CryptorConfiguration); + /** + * Generate HMAC-SHA256 hash from input data. + * + * @param data - Data from which hash should be generated. + * + * @returns HMAC-SHA256 hash from provided `data`. + */ + HMACSHA256(data: string): string; + /** + * Generate SHA256 hash from input data. + * + * @param data - Data from which hash should be generated. + * + * @returns SHA256 hash from provided `data`. + */ + SHA256(data: string): string; + /** + * Encrypt provided data. + * + * @param data - Source data which should be encrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Encrypted `data`. + */ + encrypt(data: string | Payload, customCipherKey?: string, options?: CryptoConfiguration): string; + /** + * Decrypt provided data. + * + * @param data - Encrypted data which should be decrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Decrypted `data`. + */ + decrypt(data: string, customCipherKey?: string, options?: CryptoConfiguration): Payload | null; + /** + * Encrypt provided data. + * + * @param data - Source data which should be encrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Encrypted `data` as string. + */ + private pnEncrypt; + /** + * Decrypt provided data. + * + * @param data - Encrypted data which should be decrypted. + * @param [customCipherKey] - Custom cipher key (different from defined on client level). + * @param [options] - Specific crypto configuration options. + * + * @returns Decrypted `data`. + */ + private pnDecrypt; + /** + * Pre-process provided custom crypto configuration. + * + * @param incomingOptions - Configuration which should be pre-processed before use. + * + * @returns Normalized crypto configuration options. + */ + private parseOptions; + /** + * Decode provided cipher key. + * + * @param key - Key in `encoding` provided by `options`. + * @param options - Crypto configuration options with cipher key details. + * + * @returns Array buffer with decoded key. + */ + private decodeKey; + /** + * Add padding to the cipher key. + * + * @param key - Key which should be padded. + * @param options - Crypto configuration options with cipher key details. + * + * @returns Properly padded cipher key. + */ + private getPaddedKey; + /** + * Cipher mode. + * + * @param options - Crypto configuration with information about cipher mode. + * + * @returns Crypto cipher mode. + */ + private getMode; + /** + * Cipher initialization vector. + * + * @param options - Crypto configuration with information about cipher mode. + * + * @returns Initialization vector. + */ + private getIV; + /** + * Random initialization vector. + * + * @returns Generated random initialization vector. + */ + private getRandomIV; +} +export {}; diff --git a/lib/types/core/components/deduping_manager.d.ts b/lib/types/core/components/deduping_manager.d.ts new file mode 100644 index 000000000..8c072ad6d --- /dev/null +++ b/lib/types/core/components/deduping_manager.d.ts @@ -0,0 +1,16 @@ +/** + * Real-time events deduplication manager. + * + * @internal + */ +export default class _default { + constructor({ config }: { + config: any; + }); + _config: any; + hashHistory: any[]; + getKey(message: any): string; + isDuplicate(message: any): boolean; + addEntry(message: any): void; + clearHistory(): void; +} diff --git a/lib/types/core/components/eventEmitter.d.ts b/lib/types/core/components/eventEmitter.d.ts new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/lib/types/core/components/eventEmitter.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/types/core/components/listener_manager.d.ts b/lib/types/core/components/listener_manager.d.ts new file mode 100644 index 000000000..054904377 --- /dev/null +++ b/lib/types/core/components/listener_manager.d.ts @@ -0,0 +1,76 @@ +/** + * Events listener manager module. + */ +import * as Subscription from '../types/api/subscription'; +import { Status, StatusEvent } from '../types/api'; +/** + * Real-time events listener. + */ +export type Listener = { + /** + * Real-time message events listener. + * + * @param message - Received message. + */ + message?: (message: Subscription.Message) => void; + /** + * Real-time message signal listener. + * + * @param signal - Received signal. + */ + signal?: (signal: Subscription.Signal) => void; + /** + * Real-time presence change events listener. + * + * @param presence - Received presence chane information. + */ + presence?: (presence: Subscription.Presence) => void; + /** + * Real-time App Context Objects change events listener. + * + * @param object - Changed App Context Object information. + */ + objects?: (object: Subscription.AppContextObject) => void; + /** + * Real-time message actions events listener. + * + * @param action - Message action information. + */ + messageAction?: (action: Subscription.MessageAction) => void; + /** + * Real-time file share events listener. + * + * @param file - Shared file information. + */ + file?: (file: Subscription.File) => void; + /** + * Real-time PubNub client status change event. + * + * @param status - PubNub client status information + */ + status?: (status: Status | StatusEvent) => void; + /** + * Real-time User App Context Objects change events listener. + * + * @param user - User App Context Object information. + * + * @deprecated Use {@link objects} listener callback instead. + */ + user?: (user: Subscription.UserAppContextObject) => void; + /** + * Real-time Space App Context Objects change events listener. + * + * @param space - Space App Context Object information. + * + * @deprecated Use {@link objects} listener callback instead. + */ + space?: (space: Subscription.SpaceAppContextObject) => void; + /** + * Real-time VSP Membership App Context Objects change events listener. + * + * @param membership - VSP Membership App Context Object information. + * + * @deprecated Use {@link objects} listener callback instead. + */ + membership?: (membership: Subscription.VSPMembershipAppContextObject) => void; +}; diff --git a/lib/types/core/components/push_payload.d.ts b/lib/types/core/components/push_payload.d.ts new file mode 100644 index 000000000..677843f48 --- /dev/null +++ b/lib/types/core/components/push_payload.d.ts @@ -0,0 +1,636 @@ +/** + * Payload for `pn_apns` field in published message. + */ +type APNSPayload = { + /** + * Payload for Apple Push Notification Service. + */ + aps: { + /** + * Configuration of visual notification representation. + */ + alert?: { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string; + /** + * Second line title. + * + * Subtitle which is shown under main title with smaller font. + */ + subtitle?: string; + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string; + }; + /** + * Unread notifications count badge value. + */ + badge?: number | null; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string; + /** + * Silent notification flag. + */ + 'content-available'?: 1; + }; + /** + * APNS2 payload recipients information. + */ + pn_push: PubNubAPNS2Configuration[]; +}; +/** + * APNS2 configuration type. + */ +type APNS2Configuration = { + /** + * Notification group / collapse identifier. Value will be used in APNS POST request as `apns-collapse-id` header + * value. + */ + collapseId?: string; + /** + * Date till which APNS will try to deliver notification to target device. Value will be used in APNS POST request as + * `apns-expiration` header value. + */ + expirationDate?: Date; + /** + * List of topics which should receive this notification. + */ + targets: APNS2Target[]; +}; +/** + * Preformatted for PubNub service `APNS2` configuration type. + */ +type PubNubAPNS2Configuration = { + /** + * PubNub service authentication method for APNS. + */ + auth_method: 'token'; + /** + * Target entities which should receive notification. + */ + targets: PubNubAPNS2Target[]; + /** + * Notifications group collapse identifier. + */ + collapse_id?: string; + /** + * Notification receive expiration date. + * + * Date after which notification won't be delivered. + */ + expiration?: string; + /** + * APNS protocol version. + */ + version: 'v2'; +}; +/** + * APNS2 configuration target type. + */ +type APNS2Target = { + /** + * Notifications topic name (usually it is bundle identifier of application for Apple platform). + * + * **Important:** Required only if `pushGateway` is set to `apns2`. + */ + topic: string; + /** + * Environment within which registered devices to which notifications should be delivered. + * + * Available: + * - `development` + * - `production` + * + * @default `development` + */ + environment?: 'development' | 'production'; + /** + * List of devices (their push tokens) to which this notification shouldn't be delivered. + */ + excludedDevices?: string[]; +}; +/** + * Preformatted for PubNub service `APNS2` configuration target type. + */ +type PubNubAPNS2Target = Omit & { + /** + * List of devices (their push tokens) to which this notification shouldn't be delivered. + */ + excluded_devices?: string[]; +}; +/** + * Payload for `pn_gcm` field in published message. + */ +type FCMPayload = { + /** + * Configuration of visual notification representation. + */ + notification?: { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string; + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string; + /** + * Name of the icon file from resource bundle which should be shown on notification. + */ + icon?: string; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string; + tag?: string; + }; + /** + * Configuration of data notification. + * + * Silent notification configuration. + */ + data?: { + notification?: FCMPayload['notification']; + }; +}; +/** + * Base notification payload object. + */ +declare class BaseNotificationPayload { + /** + * Notification main title. + */ + protected _title?: string; + /** + * Notification second-line title. + */ + protected _subtitle?: string; + /** + * Name of the sound which should be played for received notification. + */ + protected _sound?: string; + /** + * Value which should be placed on application badge (if required). + */ + protected _badge?: number | null; + /** + * Notification main body message. + */ + protected _body?: string; + /** + * Object in resulting message where notification payload should be added. + */ + protected _payload: unknown; + constructor(payload: unknown, title?: string, body?: string); + /** + * Retrieve resulting notification payload content for message. + * + * @returns Preformatted push notification payload data. + */ + get payload(): unknown; + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value: string | undefined); + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value: string | undefined); + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value: string | undefined); + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value: number | null | undefined); + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value: string | undefined); + /** + * Platform-specific structure initialization. + */ + protected setDefaultPayloadStructure(): void; + /** + * Translate data object into PubNub push notification payload object. + * + * @returns Preformatted push notification payload. + */ + toObject(): unknown; +} +/** + * Message payload for Apple Push Notification Service. + */ +export declare class APNSNotificationPayload extends BaseNotificationPayload { + /** + * List with notification receivers information. + */ + private _configurations?; + /** + * Type of push notification service for which payload will be created. + */ + private _apnsPushType; + /** + * Whether resulting payload should trigger silent notification or not. + */ + private _isSilent; + get payload(): APNSPayload; + /** + * Update notification receivers configuration. + * + * @param value - New APNS2 configurations. + */ + set configurations(value: APNS2Configuration[]); + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ + get notification(): { + /** + * Configuration of visual notification representation. + */ + alert?: { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string | undefined; + /** + * Second line title. + * + * Subtitle which is shown under main title with smaller font. + */ + subtitle?: string | undefined; + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string | undefined; + } | undefined; + /** + * Unread notifications count badge value. + */ + badge?: number | null | undefined; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string | undefined; + /** + * Silent notification flag. + */ + 'content-available'?: 1 | undefined; + }; + /** + * Notification title. + * + * @returns Main notification title. + */ + get title(): string | undefined; + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value: string | undefined); + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ + get subtitle(): string | undefined; + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value: string | undefined); + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body(): string | undefined; + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value: string | undefined); + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ + get badge(): number | null | undefined; + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value: number | null | undefined); + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound(): string | undefined; + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value: string | undefined); + /** + * Set whether notification should be silent or not. + * + * `content-available` notification type will be used to deliver silent notification if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ + set silent(value: boolean); + protected setDefaultPayloadStructure(): void; + toObject(): APNSPayload | null; + /** + * Create PubNub push notification service APNS2 configuration information object. + * + * @param configuration - Source user-provided APNS2 configuration. + * + * @returns Preformatted for PubNub service APNS2 configuration information. + */ + private objectFromAPNS2Configuration; + /** + * Create PubNub push notification service APNS2 target information object. + * + * @param target - Source user-provided data. + * + * @returns Preformatted for PubNub service APNS2 target information. + */ + private objectFromAPNSTarget; +} +/** + * Message payload for Firebase Clouse Messaging service. + */ +export declare class FCMNotificationPayload extends BaseNotificationPayload { + /** + * Whether resulting payload should trigger silent notification or not. + */ + private _isSilent?; + /** + * Name of the icon file from resource bundle which should be shown on notification. + */ + private _icon?; + private _tag?; + get payload(): FCMPayload; + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ + get notification(): { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string | undefined; + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string | undefined; + /** + * Name of the icon file from resource bundle which should be shown on notification. + */ + icon?: string | undefined; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string | undefined; + tag?: string | undefined; + } | undefined; + /** + * Silent notification payload. + * + * @returns Silent notification payload (data notification). + */ + get data(): { + notification?: { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string | undefined; + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string | undefined; + /** + * Name of the icon file from resource bundle which should be shown on notification. + */ + icon?: string | undefined; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string | undefined; + tag?: string | undefined; + } | undefined; + } | undefined; + /** + * Notification title. + * + * @returns Main notification title. + */ + get title(): string | undefined; + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value: string | undefined); + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body(): string | undefined; + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value: string | undefined); + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound(): string | undefined; + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value: string | undefined); + /** + * Retrieve notification icon file. + * + * @returns Notification icon file name from resource bundle. + */ + get icon(): string | undefined; + /** + * Update notification icon. + * + * @param value - Name of the icon file which should be shown on notification. + */ + set icon(value: string | undefined); + get tag(): string | undefined; + set tag(value: string | undefined); + /** + * Set whether notification should be silent or not. + * + * All notification data will be sent under `data` field if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ + set silent(value: boolean); + protected setDefaultPayloadStructure(): void; + toObject(): FCMPayload | null; +} +declare class NotificationsPayload { + /** + * Resulting message payload for notification services. + */ + private readonly _payload; + /** + * Whether notifications debugging session should be used or not. + */ + private _debugging?; + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + private readonly _title; + /** + * Second line title. + * + * Subtitle which is shown under main title with smaller font. + */ + private _subtitle?; + /** + * Notification main body message. + */ + private readonly _body; + /** + * Value which should be placed on application badge (if required). + */ + private _badge?; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + private _sound?; + /** + * APNS-specific message payload. + */ + apns: APNSNotificationPayload; + /** + * FCM-specific message payload. + */ + fcm: FCMNotificationPayload; + constructor(title: string, body: string); + set debugging(value: boolean); + /** + * Notification title. + * + * @returns Main notification title. + */ + get title(): string; + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ + get subtitle(): string | undefined; + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value: string | undefined); + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body(): string; + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ + get badge(): number | undefined; + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value: number | undefined); + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound(): string | undefined; + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value: string | undefined); + /** + * Build notifications platform for requested platforms. + * + * @param platforms - List of platforms for which payload should be added to final dictionary. Supported values: + * gcm, apns, and apns2. + * + * @returns Object with data, which can be sent with publish method call and trigger remote notifications for + * specified platforms. + */ + buildPayload(platforms: string[]): { + pn_apns?: APNSPayload | undefined; + pn_gcm?: FCMPayload | undefined; + pn_debug?: boolean | undefined; + }; +} +export default NotificationsPayload; diff --git a/lib/types/core/components/reconnection_manager.d.ts b/lib/types/core/components/reconnection_manager.d.ts new file mode 100644 index 000000000..2b32dd6da --- /dev/null +++ b/lib/types/core/components/reconnection_manager.d.ts @@ -0,0 +1,6 @@ +/** + * Subscription reconnection-manager. + * + * **Note:** Reconnection manger rely on legacy time-based availability check. + */ +export {}; diff --git a/lib/types/core/components/request.d.ts b/lib/types/core/components/request.d.ts new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/lib/types/core/components/request.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/types/core/components/stringify_buffer_keys.d.ts b/lib/types/core/components/stringify_buffer_keys.d.ts new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/lib/types/core/components/stringify_buffer_keys.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/types/core/components/subject.d.ts b/lib/types/core/components/subject.d.ts new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/lib/types/core/components/subject.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/types/core/components/subscription-manager.d.ts b/lib/types/core/components/subscription-manager.d.ts new file mode 100644 index 000000000..6807d1c06 --- /dev/null +++ b/lib/types/core/components/subscription-manager.d.ts @@ -0,0 +1,4 @@ +/** + * Subscription manager module. + */ +export {}; diff --git a/lib/types/core/components/token_manager.d.ts b/lib/types/core/components/token_manager.d.ts new file mode 100644 index 000000000..ca862c226 --- /dev/null +++ b/lib/types/core/components/token_manager.d.ts @@ -0,0 +1,4 @@ +/** + * PubNub Access Token Manager module. + */ +export {}; diff --git a/lib/types/core/components/uuid.d.ts b/lib/types/core/components/uuid.d.ts new file mode 100644 index 000000000..0131316e7 --- /dev/null +++ b/lib/types/core/components/uuid.d.ts @@ -0,0 +1,4 @@ +declare const _default: { + createUUID(): any; +}; +export default _default; diff --git a/lib/types/core/constants/categories.d.ts b/lib/types/core/constants/categories.d.ts new file mode 100644 index 000000000..bc372ba22 --- /dev/null +++ b/lib/types/core/constants/categories.d.ts @@ -0,0 +1,75 @@ +/** + * Request processing status categories. + */ +declare enum StatusCategory { + /** + * Call failed when network was unable to complete the call. + */ + PNNetworkIssuesCategory = "PNNetworkIssuesCategory", + /** + * Network call timed out. + */ + PNTimeoutCategory = "PNTimeoutCategory", + /** + * Request has been cancelled. + */ + PNCancelledCategory = "PNCancelledCategory", + /** + * Server responded with bad response. + */ + PNBadRequestCategory = "PNBadRequestCategory", + /** + * Server responded with access denied. + */ + PNAccessDeniedCategory = "PNAccessDeniedCategory", + /** + * Incomplete parameters provided for used endpoint. + */ + PNValidationErrorCategory = "PNValidationErrorCategory", + /** + * PubNub request acknowledgment status. + * + * Some API endpoints respond with request processing status w/o useful data. + */ + PNAcknowledgmentCategory = "PNAcknowledgmentCategory", + /** + * Something strange happened; please check the logs. + */ + PNUnknownCategory = "PNUnknownCategory", + /** + * SDK will announce when the network appears to be connected again. + */ + PNNetworkUpCategory = "PNNetworkUpCategory", + /** + * SDK will announce when the network appears to down. + */ + PNNetworkDownCategory = "PNNetworkDownCategory", + /** + * PubNub client reconnected to the real-time updates stream. + */ + PNReconnectedCategory = "PNReconnectedCategory", + /** + * PubNub client connected to the real-time updates stream. + */ + PNConnectedCategory = "PNConnectedCategory", + /** + * Received real-time updates exceed specified threshold. + * + * After temporary disconnection and catchup, this category means that potentially some + * real-time updates have been pushed into `storage` and need to be requested separately. + */ + PNRequestMessageCountExceededCategory = "PNRequestMessageCountExceededCategory", + /** + * PubNub client disconnected from the real-time updates streams. + */ + PNDisconnectedCategory = "PNDisconnectedCategory", + /** + * PubNub client wasn't able to connect to the real-time updates streams. + */ + PNConnectionErrorCategory = "PNConnectionErrorCategory", + /** + * PubNub client unexpectedly disconnected from the real-time updates streams. + */ + PNDisconnectedUnexpectedlyCategory = "PNDisconnectedUnexpectedlyCategory" +} +export default StatusCategory; diff --git a/lib/types/core/constants/operations.d.ts b/lib/types/core/constants/operations.d.ts new file mode 100644 index 000000000..2684a4880 --- /dev/null +++ b/lib/types/core/constants/operations.d.ts @@ -0,0 +1,203 @@ +declare enum RequestOperation { + /** + * Data publish REST API operation. + */ + PNPublishOperation = "PNPublishOperation", + /** + * Signal sending REST API operation. + */ + PNSignalOperation = "PNSignalOperation", + /** + * Subscribe for real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `join` event. + */ + PNSubscribeOperation = "PNSubscribeOperation", + /** + * Unsubscribe from real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `leave` event. + */ + PNUnsubscribeOperation = "PNUnsubscribeOperation", + /** + * Fetch user's presence information REST API operation. + */ + PNWhereNowOperation = "PNWhereNowOperation", + /** + * Fetch channel's presence information REST API operation. + */ + PNHereNowOperation = "PNHereNowOperation", + /** + * Fetch global presence information REST API operation. + */ + PNGlobalHereNowOperation = "PNGlobalHereNowOperation", + /** + * Update user's information associated with specified channel REST API operation. + */ + PNSetStateOperation = "PNSetStateOperation", + /** + * Fetch user's information associated with the specified channel REST API operation. + */ + PNGetStateOperation = "PNGetStateOperation", + /** + * Announce presence on managed channels REST API operation. + */ + PNHeartbeatOperation = "PNHeartbeatOperation", + /** + * Add a reaction to the specified message REST API operation. + */ + PNAddMessageActionOperation = "PNAddActionOperation", + /** + * Remove reaction from the specified message REST API operation. + */ + PNRemoveMessageActionOperation = "PNRemoveMessageActionOperation", + /** + * Fetch reactions for specific message REST API operation. + */ + PNGetMessageActionsOperation = "PNGetMessageActionsOperation", + PNTimeOperation = "PNTimeOperation", + /** + * Channel history REST API operation. + */ + PNHistoryOperation = "PNHistoryOperation", + /** + * Delete messages from channel history REST API operation. + */ + PNDeleteMessagesOperation = "PNDeleteMessagesOperation", + /** + * History for channels REST API operation. + */ + PNFetchMessagesOperation = "PNFetchMessagesOperation", + /** + * Number of messages for channels in specified time frame REST API operation. + */ + PNMessageCounts = "PNMessageCountsOperation", + /** + * Fetch users metadata REST API operation. + */ + PNGetAllUUIDMetadataOperation = "PNGetAllUUIDMetadataOperation", + /** + * Fetch user metadata REST API operation. + */ + PNGetUUIDMetadataOperation = "PNGetUUIDMetadataOperation", + /** + * Set user metadata REST API operation. + */ + PNSetUUIDMetadataOperation = "PNSetUUIDMetadataOperation", + /** + * Remove user metadata REST API operation. + */ + PNRemoveUUIDMetadataOperation = "PNRemoveUUIDMetadataOperation", + /** + * Fetch channels metadata REST API operation. + */ + PNGetAllChannelMetadataOperation = "PNGetAllChannelMetadataOperation", + /** + * Fetch channel metadata REST API operation. + */ + PNGetChannelMetadataOperation = "PNGetChannelMetadataOperation", + /** + * Set channel metadata REST API operation. + */ + PNSetChannelMetadataOperation = "PNSetChannelMetadataOperation", + /** + * Remove channel metadata REST API operation. + */ + PNRemoveChannelMetadataOperation = "PNRemoveChannelMetadataOperation", + /** + * Fetch channel members REST API operation. + */ + PNGetMembersOperation = "PNGetMembersOperation", + /** + * Update channel members REST API operation. + */ + PNSetMembersOperation = "PNSetMembersOperation", + /** + * Fetch channel memberships REST API operation. + */ + PNGetMembershipsOperation = "PNGetMembershipsOperation", + /** + * Update channel memberships REST API operation. + */ + PNSetMembershipsOperation = "PNSetMembershipsOperation", + /** + * Fetch list of files sent to the channel REST API operation. + */ + PNListFilesOperation = "PNListFilesOperation", + /** + * Retrieve file upload URL REST API operation. + */ + PNGenerateUploadUrlOperation = "PNGenerateUploadUrlOperation", + /** + * Upload file to the channel REST API operation. + */ + PNPublishFileOperation = "PNPublishFileOperation", + /** + * Publish File Message to the channel REST API operation. + */ + PNPublishFileMessageOperation = "PNPublishFileMessageOperation", + /** + * Retrieve file download URL REST API operation. + */ + PNGetFileUrlOperation = "PNGetFileUrlOperation", + /** + * Download file from the channel REST API operation. + */ + PNDownloadFileOperation = "PNDownloadFileOperation", + /** + * Delete file sent to the channel REST API operation. + */ + PNDeleteFileOperation = "PNDeleteFileOperation", + /** + * Register channels with device push notifications REST API operation. + */ + PNAddPushNotificationEnabledChannelsOperation = "PNAddPushNotificationEnabledChannelsOperation", + /** + * Unregister channels with device push notifications REST API operation. + */ + PNRemovePushNotificationEnabledChannelsOperation = "PNRemovePushNotificationEnabledChannelsOperation", + /** + * Fetch list of channels with enabled push notifications for device REST API operation. + */ + PNPushNotificationEnabledChannelsOperation = "PNPushNotificationEnabledChannelsOperation", + /** + * Disable push notifications for device REST API operation. + */ + PNRemoveAllPushNotificationsOperation = "PNRemoveAllPushNotificationsOperation", + /** + * Fetch channels groups list REST API operation. + */ + PNChannelGroupsOperation = "PNChannelGroupsOperation", + /** + * Remove specified channel group REST API operation. + */ + PNRemoveGroupOperation = "PNRemoveGroupOperation", + /** + * Fetch list of channels for the specified channel group REST API operation. + */ + PNChannelsForGroupOperation = "PNChannelsForGroupOperation", + /** + * Add list of channels to the specified channel group REST API operation. + */ + PNAddChannelsToGroupOperation = "PNAddChannelsToGroupOperation", + /** + * Remove list of channels from the specified channel group REST API operation. + */ + PNRemoveChannelsFromGroupOperation = "PNRemoveChannelsFromGroupOperation", + /** + * Generate authorized token REST API operation. + */ + PNAccessManagerGrant = "PNAccessManagerGrant", + /** + * Generate authorized token REST API operation. + */ + PNAccessManagerGrantToken = "PNAccessManagerGrantToken", + PNAccessManagerAudit = "PNAccessManagerAudit", + /** + * Revoke authorized token REST API operation. + */ + PNAccessManagerRevokeToken = "PNAccessManagerRevokeToken", + PNHandshakeOperation = "PNHandshakeOperation", + PNReceiveMessagesOperation = "PNReceiveMessagesOperation" +} +export default RequestOperation; diff --git a/lib/types/core/endpoints/access_manager/audit.d.ts b/lib/types/core/endpoints/access_manager/audit.d.ts new file mode 100644 index 000000000..78b5769e2 --- /dev/null +++ b/lib/types/core/endpoints/access_manager/audit.d.ts @@ -0,0 +1,4 @@ +/** + * PAM Audit REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/access_manager/grant.d.ts b/lib/types/core/endpoints/access_manager/grant.d.ts new file mode 100644 index 000000000..0e51654bd --- /dev/null +++ b/lib/types/core/endpoints/access_manager/grant.d.ts @@ -0,0 +1,4 @@ +/** + * PAM Grant REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/access_manager/grant_token.d.ts b/lib/types/core/endpoints/access_manager/grant_token.d.ts new file mode 100644 index 000000000..6895635ff --- /dev/null +++ b/lib/types/core/endpoints/access_manager/grant_token.d.ts @@ -0,0 +1,4 @@ +/** + * PAM Grant Token REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/access_manager/revoke_token.d.ts b/lib/types/core/endpoints/access_manager/revoke_token.d.ts new file mode 100644 index 000000000..207f87cba --- /dev/null +++ b/lib/types/core/endpoints/access_manager/revoke_token.d.ts @@ -0,0 +1,4 @@ +/** + * PAM Revoke Token REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/actions/add_message_action.d.ts b/lib/types/core/endpoints/actions/add_message_action.d.ts new file mode 100644 index 000000000..e80c018b0 --- /dev/null +++ b/lib/types/core/endpoints/actions/add_message_action.d.ts @@ -0,0 +1,4 @@ +/** + * Add Message Action REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/actions/get_message_actions.d.ts b/lib/types/core/endpoints/actions/get_message_actions.d.ts new file mode 100644 index 000000000..6206ec73f --- /dev/null +++ b/lib/types/core/endpoints/actions/get_message_actions.d.ts @@ -0,0 +1,4 @@ +/** + * Get Message Actions REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/actions/remove_message_action.d.ts b/lib/types/core/endpoints/actions/remove_message_action.d.ts new file mode 100644 index 000000000..51aa42da6 --- /dev/null +++ b/lib/types/core/endpoints/actions/remove_message_action.d.ts @@ -0,0 +1,4 @@ +/** + * Remove Message Action REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/channel_groups/add_channels.d.ts b/lib/types/core/endpoints/channel_groups/add_channels.d.ts new file mode 100644 index 000000000..4d3dfefd8 --- /dev/null +++ b/lib/types/core/endpoints/channel_groups/add_channels.d.ts @@ -0,0 +1,4 @@ +/** + * Add channel group channels REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/channel_groups/delete_group.d.ts b/lib/types/core/endpoints/channel_groups/delete_group.d.ts new file mode 100644 index 000000000..873f58775 --- /dev/null +++ b/lib/types/core/endpoints/channel_groups/delete_group.d.ts @@ -0,0 +1,4 @@ +/** + * Delete channel group REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/channel_groups/list_channels.d.ts b/lib/types/core/endpoints/channel_groups/list_channels.d.ts new file mode 100644 index 000000000..1688a1d49 --- /dev/null +++ b/lib/types/core/endpoints/channel_groups/list_channels.d.ts @@ -0,0 +1,4 @@ +/** + * List channel group channels REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/channel_groups/list_groups.d.ts b/lib/types/core/endpoints/channel_groups/list_groups.d.ts new file mode 100644 index 000000000..2aa05098f --- /dev/null +++ b/lib/types/core/endpoints/channel_groups/list_groups.d.ts @@ -0,0 +1,4 @@ +/** + * List All Channel Groups REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/channel_groups/remove_channels.d.ts b/lib/types/core/endpoints/channel_groups/remove_channels.d.ts new file mode 100644 index 000000000..f46a8e049 --- /dev/null +++ b/lib/types/core/endpoints/channel_groups/remove_channels.d.ts @@ -0,0 +1,4 @@ +/** + * Remove channel group channels REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/fetch_messages.d.ts b/lib/types/core/endpoints/fetch_messages.d.ts new file mode 100644 index 000000000..a58cec3cc --- /dev/null +++ b/lib/types/core/endpoints/fetch_messages.d.ts @@ -0,0 +1,4 @@ +/** + * Fetch messages REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/file_upload/delete_file.d.ts b/lib/types/core/endpoints/file_upload/delete_file.d.ts new file mode 100644 index 000000000..87204dacd --- /dev/null +++ b/lib/types/core/endpoints/file_upload/delete_file.d.ts @@ -0,0 +1,4 @@ +/** + * Delete file REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/file_upload/download_file.d.ts b/lib/types/core/endpoints/file_upload/download_file.d.ts new file mode 100644 index 000000000..8591c0b12 --- /dev/null +++ b/lib/types/core/endpoints/file_upload/download_file.d.ts @@ -0,0 +1,4 @@ +/** + * Download File REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/file_upload/generate_upload_url.d.ts b/lib/types/core/endpoints/file_upload/generate_upload_url.d.ts new file mode 100644 index 000000000..24d09f51a --- /dev/null +++ b/lib/types/core/endpoints/file_upload/generate_upload_url.d.ts @@ -0,0 +1,4 @@ +/** + * Generate file upload URL REST API request. + */ +export {}; diff --git a/lib/types/core/endpoints/file_upload/get_file_url.d.ts b/lib/types/core/endpoints/file_upload/get_file_url.d.ts new file mode 100644 index 000000000..925eee0d8 --- /dev/null +++ b/lib/types/core/endpoints/file_upload/get_file_url.d.ts @@ -0,0 +1,4 @@ +/** + * File sharing REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/file_upload/list_files.d.ts b/lib/types/core/endpoints/file_upload/list_files.d.ts new file mode 100644 index 000000000..a85d9abf5 --- /dev/null +++ b/lib/types/core/endpoints/file_upload/list_files.d.ts @@ -0,0 +1,4 @@ +/** + * List Files REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/file_upload/publish_file.d.ts b/lib/types/core/endpoints/file_upload/publish_file.d.ts new file mode 100644 index 000000000..3bf7b9ebd --- /dev/null +++ b/lib/types/core/endpoints/file_upload/publish_file.d.ts @@ -0,0 +1,4 @@ +/** + * Publish File Message REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/file_upload/send_file.d.ts b/lib/types/core/endpoints/file_upload/send_file.d.ts new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/lib/types/core/endpoints/file_upload/send_file.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/types/core/endpoints/file_upload/upload-file.d.ts b/lib/types/core/endpoints/file_upload/upload-file.d.ts new file mode 100644 index 000000000..6959033bd --- /dev/null +++ b/lib/types/core/endpoints/file_upload/upload-file.d.ts @@ -0,0 +1,4 @@ +/** + * Upload file REST API request. + */ +export {}; diff --git a/lib/types/core/endpoints/history/delete_messages.d.ts b/lib/types/core/endpoints/history/delete_messages.d.ts new file mode 100644 index 000000000..c189fd470 --- /dev/null +++ b/lib/types/core/endpoints/history/delete_messages.d.ts @@ -0,0 +1,4 @@ +/** + * Delete messages REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/history/get_history.d.ts b/lib/types/core/endpoints/history/get_history.d.ts new file mode 100644 index 000000000..485ad476b --- /dev/null +++ b/lib/types/core/endpoints/history/get_history.d.ts @@ -0,0 +1,4 @@ +/** + * Get history REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/history/message_counts.d.ts b/lib/types/core/endpoints/history/message_counts.d.ts new file mode 100644 index 000000000..7985a94f9 --- /dev/null +++ b/lib/types/core/endpoints/history/message_counts.d.ts @@ -0,0 +1,4 @@ +/** + * Messages count REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/channel/get.d.ts b/lib/types/core/endpoints/objects/channel/get.d.ts new file mode 100644 index 000000000..c56a41184 --- /dev/null +++ b/lib/types/core/endpoints/objects/channel/get.d.ts @@ -0,0 +1,4 @@ +/** + * Get Channel Metadata REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/channel/get_all.d.ts b/lib/types/core/endpoints/objects/channel/get_all.d.ts new file mode 100644 index 000000000..777c4ab1c --- /dev/null +++ b/lib/types/core/endpoints/objects/channel/get_all.d.ts @@ -0,0 +1,4 @@ +/** + * Get All Channel Metadata REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/channel/remove.d.ts b/lib/types/core/endpoints/objects/channel/remove.d.ts new file mode 100644 index 000000000..0779bb2c8 --- /dev/null +++ b/lib/types/core/endpoints/objects/channel/remove.d.ts @@ -0,0 +1,4 @@ +/** + * Remove Channel Metadata REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/channel/set.d.ts b/lib/types/core/endpoints/objects/channel/set.d.ts new file mode 100644 index 000000000..e12e2fb2b --- /dev/null +++ b/lib/types/core/endpoints/objects/channel/set.d.ts @@ -0,0 +1,4 @@ +/** + * Set Channel Metadata REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/member/get.d.ts b/lib/types/core/endpoints/objects/member/get.d.ts new file mode 100644 index 000000000..db192f3b6 --- /dev/null +++ b/lib/types/core/endpoints/objects/member/get.d.ts @@ -0,0 +1,4 @@ +/** + * Get Channel Members REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/member/set.d.ts b/lib/types/core/endpoints/objects/member/set.d.ts new file mode 100644 index 000000000..67d6a5133 --- /dev/null +++ b/lib/types/core/endpoints/objects/member/set.d.ts @@ -0,0 +1,4 @@ +/** + * Set Channel Members REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/membership/get.d.ts b/lib/types/core/endpoints/objects/membership/get.d.ts new file mode 100644 index 000000000..3db81e283 --- /dev/null +++ b/lib/types/core/endpoints/objects/membership/get.d.ts @@ -0,0 +1,4 @@ +/** + * Get UUID Memberships REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/membership/set.d.ts b/lib/types/core/endpoints/objects/membership/set.d.ts new file mode 100644 index 000000000..61cb530a7 --- /dev/null +++ b/lib/types/core/endpoints/objects/membership/set.d.ts @@ -0,0 +1,4 @@ +/** + * Set UUID Memberships REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/uuid/get.d.ts b/lib/types/core/endpoints/objects/uuid/get.d.ts new file mode 100644 index 000000000..40e5f4817 --- /dev/null +++ b/lib/types/core/endpoints/objects/uuid/get.d.ts @@ -0,0 +1,4 @@ +/** + * Get UUID Metadata REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/uuid/get_all.d.ts b/lib/types/core/endpoints/objects/uuid/get_all.d.ts new file mode 100644 index 000000000..33e8a18dc --- /dev/null +++ b/lib/types/core/endpoints/objects/uuid/get_all.d.ts @@ -0,0 +1,4 @@ +/** + * Get All UUID Metadata REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/uuid/remove.d.ts b/lib/types/core/endpoints/objects/uuid/remove.d.ts new file mode 100644 index 000000000..74edbb159 --- /dev/null +++ b/lib/types/core/endpoints/objects/uuid/remove.d.ts @@ -0,0 +1,4 @@ +/** + * Remove UUID Metadata REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/objects/uuid/set.d.ts b/lib/types/core/endpoints/objects/uuid/set.d.ts new file mode 100644 index 000000000..d4b96bdf7 --- /dev/null +++ b/lib/types/core/endpoints/objects/uuid/set.d.ts @@ -0,0 +1,4 @@ +/** + * Set UUID Metadata REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/presence/get_state.d.ts b/lib/types/core/endpoints/presence/get_state.d.ts new file mode 100644 index 000000000..dff42db68 --- /dev/null +++ b/lib/types/core/endpoints/presence/get_state.d.ts @@ -0,0 +1,4 @@ +/** + * Get Presence State REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/presence/heartbeat.d.ts b/lib/types/core/endpoints/presence/heartbeat.d.ts new file mode 100644 index 000000000..52b3c35c2 --- /dev/null +++ b/lib/types/core/endpoints/presence/heartbeat.d.ts @@ -0,0 +1,4 @@ +/** + * Announce heartbeat REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/presence/here_now.d.ts b/lib/types/core/endpoints/presence/here_now.d.ts new file mode 100644 index 000000000..7f077a5e2 --- /dev/null +++ b/lib/types/core/endpoints/presence/here_now.d.ts @@ -0,0 +1,4 @@ +/** + * Channels / channel groups presence REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/presence/leave.d.ts b/lib/types/core/endpoints/presence/leave.d.ts new file mode 100644 index 000000000..d6ba4460c --- /dev/null +++ b/lib/types/core/endpoints/presence/leave.d.ts @@ -0,0 +1,4 @@ +/** + * Announce leave REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/presence/set_state.d.ts b/lib/types/core/endpoints/presence/set_state.d.ts new file mode 100644 index 000000000..d18769ae2 --- /dev/null +++ b/lib/types/core/endpoints/presence/set_state.d.ts @@ -0,0 +1,4 @@ +/** + * Set Presence State REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/presence/where_now.d.ts b/lib/types/core/endpoints/presence/where_now.d.ts new file mode 100644 index 000000000..2c4ddd3c0 --- /dev/null +++ b/lib/types/core/endpoints/presence/where_now.d.ts @@ -0,0 +1,4 @@ +/** + * `uuid` presence REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/publish.d.ts b/lib/types/core/endpoints/publish.d.ts new file mode 100644 index 000000000..f313eb4c5 --- /dev/null +++ b/lib/types/core/endpoints/publish.d.ts @@ -0,0 +1,69 @@ +/** + * Publish REST API module. + */ +import { CryptoModule } from '../interfaces/crypto-module'; +import { Payload } from '../types/api'; +/** + * Request configuration parameters. + */ +export type PublishParameters = { + /** + * Channel name to publish messages to. + */ + channel: string; + /** + * Data which should be sent to the `channel`. + * + * The message may be any valid JSON type including objects, arrays, strings, and numbers. + */ + message: Payload; + /** + * Whether published data should be available with `Storage API` later or not. + * + * @default `true` + */ + storeInHistory?: boolean; + /** + * Whether message should be sent as part of request POST body or not. + * + * @default `false` + */ + sendByPost?: boolean; + /** + * Metadata, which should be associated with published data. + * + * Associated metadata can be utilized by message filtering feature. + */ + meta?: Payload; + /** + * Specify duration during which data will be available with `Storage API`. + * + * - If `storeInHistory` = `true`, and `ttl` = `0`, the `message` is stored with no expiry time. + * - If `storeInHistory` = `true` and `ttl` = `X` (`X` is an Integer value), the `message` is + * stored with an expiry time of `X` hours. + * - If `storeInHistory` = `false`, the `ttl` parameter is ignored. + * - If `ttl` is not specified, then expiration of the `message` defaults back to the expiry value + * for the key. + */ + ttl?: number; + /** + * Whether published data should be replicated across all data centers or not. + * + * @default `true` + * @deprecated + */ + replicate?: boolean; + /** + * Indexed signature for deprecated parameters. + */ + [key: string]: string | number | boolean | undefined | Payload | CryptoModule; +}; +/** + * Service success response. + */ +export type PublishResponse = { + /** + * High-precision time when published data has been received by the PubNub service. + */ + timetoken: string; +}; diff --git a/lib/types/core/endpoints/push/add_push_channels.d.ts b/lib/types/core/endpoints/push/add_push_channels.d.ts new file mode 100644 index 000000000..ba565c462 --- /dev/null +++ b/lib/types/core/endpoints/push/add_push_channels.d.ts @@ -0,0 +1,4 @@ +/** + * Register Channels with Device push REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/push/list_push_channels.d.ts b/lib/types/core/endpoints/push/list_push_channels.d.ts new file mode 100644 index 000000000..cb340e6c5 --- /dev/null +++ b/lib/types/core/endpoints/push/list_push_channels.d.ts @@ -0,0 +1,4 @@ +/** + * List Device push enabled channels REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/push/push.d.ts b/lib/types/core/endpoints/push/push.d.ts new file mode 100644 index 000000000..c9f462716 --- /dev/null +++ b/lib/types/core/endpoints/push/push.d.ts @@ -0,0 +1,4 @@ +/** + * Manage channels enabled for device push REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/push/remove_device.d.ts b/lib/types/core/endpoints/push/remove_device.d.ts new file mode 100644 index 000000000..ba3047e70 --- /dev/null +++ b/lib/types/core/endpoints/push/remove_device.d.ts @@ -0,0 +1,4 @@ +/** + * Unregister Device push REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/push/remove_push_channels.d.ts b/lib/types/core/endpoints/push/remove_push_channels.d.ts new file mode 100644 index 000000000..d1343dbc7 --- /dev/null +++ b/lib/types/core/endpoints/push/remove_push_channels.d.ts @@ -0,0 +1,4 @@ +/** + * Unregister Channels from Device push REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/signal.d.ts b/lib/types/core/endpoints/signal.d.ts new file mode 100644 index 000000000..9238bd206 --- /dev/null +++ b/lib/types/core/endpoints/signal.d.ts @@ -0,0 +1,28 @@ +/** + * Signal REST API module. + */ +import { Payload } from '../types/api'; +/** + * Request configuration parameters. + */ +export type SignalParameters = { + /** + * Channel name to publish signal to. + */ + channel: string; + /** + * Data which should be sent to the `channel`. + * + * The message may be any valid JSON type including objects, arrays, strings, and numbers. + */ + message: Payload; +}; +/** + * Service success response. + */ +export type SignalResponse = { + /** + * High-precision time when published data has been received by the PubNub service. + */ + timetoken: string; +}; diff --git a/lib/types/core/endpoints/subscribe.d.ts b/lib/types/core/endpoints/subscribe.d.ts new file mode 100644 index 000000000..a7be65799 --- /dev/null +++ b/lib/types/core/endpoints/subscribe.d.ts @@ -0,0 +1,4 @@ +/** + * Subscription REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/subscriptionUtils/handshake.d.ts b/lib/types/core/endpoints/subscriptionUtils/handshake.d.ts new file mode 100644 index 000000000..2a942a579 --- /dev/null +++ b/lib/types/core/endpoints/subscriptionUtils/handshake.d.ts @@ -0,0 +1,4 @@ +/** + * Handshake subscribe REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/subscriptionUtils/receiveMessages.d.ts b/lib/types/core/endpoints/subscriptionUtils/receiveMessages.d.ts new file mode 100644 index 000000000..640df8780 --- /dev/null +++ b/lib/types/core/endpoints/subscriptionUtils/receiveMessages.d.ts @@ -0,0 +1,4 @@ +/** + * Receive messages subscribe REST API module. + */ +export {}; diff --git a/lib/types/core/endpoints/time.d.ts b/lib/types/core/endpoints/time.d.ts new file mode 100644 index 000000000..cda43e5ea --- /dev/null +++ b/lib/types/core/endpoints/time.d.ts @@ -0,0 +1,12 @@ +/** + * Time REST API module. + */ +/** + * Service success response. + */ +export type TimeResponse = { + /** + * High-precision time when published data has been received by the PubNub service. + */ + timetoken: string; +}; diff --git a/lib/types/core/interfaces/configuration.d.ts b/lib/types/core/interfaces/configuration.d.ts new file mode 100644 index 000000000..63ce7b036 --- /dev/null +++ b/lib/types/core/interfaces/configuration.d.ts @@ -0,0 +1,276 @@ +/** + * {@link PubNub} client configuration module. + */ +import { RequestRetryPolicy } from '../../event-engine/core/retryPolicy'; +/** + * Base user-provided PubNub client configuration. + */ +export type UserConfiguration = { + /** + * Specifies the `subscribeKey` to be used for subscribing to a channel and message publishing. + */ + subscribeKey: string; + /** + * Specifies the `subscribe_key` to be used for subscribing to a channel and message publishing. + * + * @deprecated Use the {@link subscribeKey} instead. + */ + subscribe_key?: string; + /** + * Specifies the `publishKey` to be used for publishing messages to a channel. + */ + publishKey?: string; + /** + * Specifies the `publish_key` to be used for publishing messages to a channel. + * + * @deprecated Use the {@link publishKey} instead. + */ + publish_key?: string; + /** + * Specifies the `secretKey` to be used for request signatures computation. + */ + secretKey?: string; + /** + * Specifies the `secret_key` to be used for request signatures computation. + * + * @deprecated Use the {@link secretKey} instead. + */ + secret_key?: string; + /** + * Unique PubNub client user identifier. + * + * Unique `userId` to identify the user or the device that connects to PubNub. + * It's a UTF-8 encoded string of up to 64 alphanumeric characters. + * + * If you don't set the `userId`, you won't be able to connect to PubNub. + */ + userId?: string; + /** + * If Access Manager enabled, this key will be used on all requests. + */ + authKey?: string | null; + /** + * Log HTTP information. + * + * @default `false` + */ + logVerbosity?: boolean; + /** + * If set to true, requests will be made over HTTPS. + * + * @default `true` for v4.20.0 onwards, `false` before v4.20.0 + */ + ssl?: boolean; + /** + * If a custom domain is required, SDK accepts it here. + * + * @default `ps.pndsn.com` + */ + origin?: string | string[]; + /** + * How long the server will consider the client alive for presence.The value is in seconds. + * + * @default `300` + */ + presenceTimeout?: number; + /** + * How often the client will announce itself to server.The value is in seconds. + * + * @default `not set` + */ + heartbeatInterval?: number; + /** + * Transactional requests timeout in milliseconds. + * + * Maximum duration for which PubNub client should wait for transactional request completion. + * + * @default `15` seconds + */ + transactionalRequestTimeout?: number; + /** + * Subscription requests timeout in milliseconds. + * + * Maximum duration for which PubNub client should wait for subscription request completion. + * + * @default `310` seconds + */ + subscribeRequestTimeout?: number; + /** + * `true` to allow catch up on the front-end applications. + * + * @default `false` + */ + restore?: boolean; + /** + * Whether to include the PubNub object instance ID in outgoing requests. + * + * @default `false` + */ + useInstanceId?: boolean; + /** + * When `true` the SDK doesn't send out the leave requests. + * + * @default `false` + */ + suppressLeaveEvents?: boolean; + /** + * `PNRequestMessageCountExceededCategory` is thrown when the number of messages into the + * payload is above of `requestMessageCountThreshold`. + * + * @default `100` + */ + requestMessageCountThreshold?: number; + /** + * This flag announces when the network is down or up using the states `PNNetworkDownCategory` + * and `PNNetworkUpCategory`. + * + * @default `false` + */ + autoNetworkDetection?: boolean; + /** + * Whether to use the standardized workflows for subscribe and presence. + * + * Note that the `maintainPresenceState` parameter is set to true by default, so make sure to + * disable it if you don't need to maintain presence state. For more information, refer to the + * param description in this table. + * + * + * @default `false` + */ + enableEventEngine?: boolean; + /** + * Custom reconnection configuration parameters. + * + * `retryConfiguration: policy` is the type of policy to be used. + * + * Available values: + * - `PubNub.LinearRetryPolicy({ delay, maximumRetry })` + * - `PubNub.ExponentialRetryPolicy({ minimumDelay, maximumDelay, maximumRetry })` + * + * For more information, refer to + * {@link /docs/general/setup/connection-management#reconnection-policy|Reconnection Policy}. JavaScript doesn't + * support excluding endpoints. + * + * @default `not set` + */ + retryConfiguration?: RequestRetryPolicy; + /** + * Whether the `state` set using `setState()` should be maintained for the current `userId`. + * This option works only when `enableEventEngine` is set to `true`. + * + * @default `true` + */ + maintainPresenceState?: boolean; + /** + * `UUID` to use. You should set a unique `UUID` to identify the user or the device that + * connects to PubNub. + * If you don't set the `UUID`, you won't be able to connect to PubNub. + * + * @deprecated Use {@link userId} instead. + */ + uuid?: string; + /** + * If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of + * opening a new one for each new request. + * + * @default `false` + */ + keepAlive?: boolean; + /** + * If the SDK is running as part of another SDK built atop of it, allow a custom `pnsdk` with + * name and version. + */ + sdkName?: string; + /** + * If the SDK is operated by a partner, allow a custom `pnsdk` item for them. + */ + partnerId?: string; +}; +/** + * User-provided configuration object interface. + * + * Interface contains limited set of settings manipulation and access. + */ +export interface ClientConfiguration { + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + getUserId(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + setUserId(value: string): void; + /** + * Change REST API endpoint access authorization key. + * + * @param authKey - New authorization key which should be used with new requests. + */ + setAuthKey(authKey: string | null): void; + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + getFilterExpression(): string | undefined | null; + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + setFilterExpression(expression: string | null | undefined): void; + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + setCipherKey(key: string | undefined): void; + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + get version(): string; + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + getVersion(): string; + /** + * Add framework's prefix. + * + * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. + * @param suffix - Suffix with information about framework. + */ + _addPnsdkSuffix(name: string, suffix: string | number): void; + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + * + * @deprecated Use the {@link getUserId} or {@link userId} getter instead. + */ + getUUID(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @returns {Configuration} Reference to the configuration instance for easier chaining. + * + * @throws Error empty user identifier has been provided. + * + * @deprecated Use the {@link setUserId} or {@link userId} setter instead. + */ + setUUID(value: string): void; +} diff --git a/lib/types/core/interfaces/crypto-module.d.ts b/lib/types/core/interfaces/crypto-module.d.ts new file mode 100644 index 000000000..621df079a --- /dev/null +++ b/lib/types/core/interfaces/crypto-module.d.ts @@ -0,0 +1,152 @@ +/** + * Crypto module. + */ +import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; +import { Payload } from '../types/api'; +/** + * Crypto module configuration. + */ +export type CryptoModuleConfiguration = { + default: C; + cryptors?: C[]; +}; +export type CryptorConfiguration = { + /** + * Data encryption / decryption key. + */ + cipherKey?: string; + /** + * Request sign secret key. + */ + secretKey?: string; + /** + * Whether random initialization vector should be used or not. + * + * @default `true` + */ + useRandomIVs?: boolean; + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + customEncrypt?: (data: string | Payload) => string; + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + customDecrypt?: (data: string) => string; +}; +/** + * Base crypto module interface. + */ +export interface CryptoModule { + /** + * Encrypt data. + * + * @param data - Data which should be encrypted using `CryptoModule`. + * + * @returns Data encryption result. + */ + encrypt(data: ArrayBuffer | string): ArrayBuffer | string; + /** + * Encrypt file object. + * + * @param file - File object with data for encryption. + * @param File - File object constructor to create instance for encrypted data representation. + * + * @returns Asynchronous file encryption result. + */ + encryptFile(file: PubNubFileInterface, File: PubNubFileConstructor): Promise; + /** + * Encrypt data. + * + * @param data - Dta which should be encrypted using `CryptoModule`. + * + * @returns Data decryption result. + */ + decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null; + /** + * Decrypt file object. + * + * @param file - Encrypted file object with data for decryption. + * @param File - File object constructor to create instance for decrypted data representation. + * + * @returns Asynchronous file decryption result. + */ + decryptFile(file: PubNubFileInterface, File: PubNubFileConstructor): Promise; +} +export declare abstract class AbstractCryptoModule implements CryptoModule { + /** + * `String` to {@link ArrayBuffer} response decoder. + */ + protected static encoder: TextEncoder; + /** + * {@link ArrayBuffer} to {@link string} decoder. + */ + protected static decoder: TextDecoder; + defaultCryptor: C; + cryptors: C[]; + /** + * Construct crypto module with legacy cryptor for encryption and both legacy and AES-CBC + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using legacy cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ + static legacyCryptoModule(config: CryptorConfiguration): CryptoModule; + /** + * Construct crypto module with AES-CBC cryptor for encryption and both AES-CBC and legacy + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using AES-CBC cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ + static aesCbcCryptoModule(config: CryptorConfiguration): CryptoModule; + constructor(configuration: CryptoModuleConfiguration); + /** + * Encrypt data. + * + * @param data - Data which should be encrypted using {@link CryptoModule}. + * + * @returns Data encryption result. + */ + abstract encrypt(data: ArrayBuffer | string): ArrayBuffer | string; + /** + * Encrypt file object. + * + * @param file - File object with data for encryption. + * @param File - File object constructor to create instance for encrypted data representation. + * + * @returns Asynchronous file encryption result. + */ + abstract encryptFile(file: PubNubFileInterface, File: PubNubFileConstructor): Promise; + /** + * Encrypt data. + * + * @param data - Dta which should be encrypted using `CryptoModule`. + * + * @returns Data decryption result. + */ + abstract decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null; + /** + * Decrypt file object. + * + * @param file - Encrypted file object with data for decryption. + * @param File - File object constructor to create instance for decrypted data representation. + * + * @returns Asynchronous file decryption result. + */ + abstract decryptFile(file: PubNubFileInterface, File: PubNubFileConstructor): Promise; + /** + * Retrieve list of module's cryptors. + */ + protected getAllCryptors(): C[]; +} diff --git a/lib/types/core/interfaces/cryptography.d.ts b/lib/types/core/interfaces/cryptography.d.ts new file mode 100644 index 000000000..9b73050a5 --- /dev/null +++ b/lib/types/core/interfaces/cryptography.d.ts @@ -0,0 +1,54 @@ +/** + * Legacy Cryptography module interface. + */ +import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; +export interface Cryptography { + /** + * Encrypt provided source data using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` data. + * @param input - Source data for encryption. + * + * @returns Encrypted data as object or stream (depending on from source data type). + * + * @throws Error if unknown data type has been passed. + */ + encrypt(key: string, input: Types): Promise; + /** + * Decrypt provided encrypted data using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` data. + * @param input - Encrypted data for decryption. + * + * @returns Decrypted data as object or stream (depending on from encrypted data type). + * + * @throws Error if unknown data type has been passed. + */ + decrypt(key: string, input: Types): Promise; + /** + * Encrypt provided `PubNub` File object using specific encryption {@link key}. + * + * @param key - Key for `PubNub` File object encryption.
**Note:** Same key should be + * used to `decrypt` data. + * @param file - Source `PubNub` File object for encryption. + * @param File - Class constructor for `PubNub` File object. + * + * @returns Encrypted data as `PubNub` File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + encryptFile(key: string, file: PubNubFileInterface, File: PubNubFileConstructor): Promise; + /** + * Decrypt provided `PubNub` File object using specific decryption {@link key}. + * + * @param key - Key for `PubNub` File object decryption.
**Note:** Should be the same + * as used to `encrypt` data. + * @param file - Encrypted `PubNub` File object for decryption. + * @param File - Class constructor for `PubNub` File object. + * + * @returns Decrypted data as `PubNub` File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + decryptFile(key: string, file: PubNubFileInterface, File: PubNubFileConstructor): Promise; +} diff --git a/lib/types/core/interfaces/request.d.ts b/lib/types/core/interfaces/request.d.ts new file mode 100644 index 000000000..cb0ff5c3b --- /dev/null +++ b/lib/types/core/interfaces/request.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/lib/types/core/interfaces/transport.d.ts b/lib/types/core/interfaces/transport.d.ts new file mode 100644 index 000000000..82ec357eb --- /dev/null +++ b/lib/types/core/interfaces/transport.d.ts @@ -0,0 +1,61 @@ +import { CancellationController, TransportRequest } from '../types/transport-request'; +import { TransportResponse } from '../types/transport-response'; +/** + * Represents the configuration options for keeping the transport connection alive. + */ +export type TransportKeepAlive = { + /** + * The time interval in milliseconds for keeping the connection alive. + * + * @default 1000 + */ + keepAliveMsecs?: number; + /** + * The maximum number of sockets allowed per host. + * + * @default Infinity + */ + maxSockets?: number; + /** + * The maximum number of open and free sockets in the pool per host. + * + * @default 256 + */ + maxFreeSockets?: number; + /** + * Timeout in milliseconds, after which the `idle` socket will be closed. + * + * @default 30000 + */ + timeout?: number; +}; +/** + * This interface is used to send requests to the PubNub API. + * + * You can implement this interface for your types, or use one of the provided modules to use a + * transport library. + * + * @interface + */ +export interface Transport { + /** + * Make request sendable. + * + * @param req - The transport request to be processed. + * + * @returns - A promise that resolves to a transport response and request cancellation + * controller (if required). + */ + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; + /** + * Pre-processed request. + * + * Transport implementation may pre-process original transport requests before making + * platform-specific request objects from it. + * + * @param req - Transport request provided by the PubNub client. + * + * @returns Transport request with updated properties (if it was required). + */ + request(req: TransportRequest): TransportRequest; +} diff --git a/lib/types/core/pubnub-channel-groups.d.ts b/lib/types/core/pubnub-channel-groups.d.ts new file mode 100644 index 000000000..f9c0dc604 --- /dev/null +++ b/lib/types/core/pubnub-channel-groups.d.ts @@ -0,0 +1,86 @@ +/** + * PubNub Channel Groups API module. + */ +import { KeySet, ResultCallback, SendRequestFunction, StatusCallback } from './types/api'; +import * as ChannelGroups from './types/api/channel-groups'; +export default class PubnubChannelGroups { + private readonly keySet; + private readonly sendRequest; + constructor(keySet: KeySet, sendRequest: SendRequestFunction); + /** + * Fetch channel group channels. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + listChannels(parameters: ChannelGroups.ListChannelGroupChannelsParameters, callback: ResultCallback): void; + /** + * Fetch channel group channels. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get channel group channels response. + */ + listChannels(parameters: ChannelGroups.ListChannelGroupChannelsParameters): Promise; + /** + * Fetch all channel groups. + * + * @param callback - Request completion handler callback. + * + * @deprecated + */ + listGroups(callback: ResultCallback): void; + /** + * Fetch all channel groups. + * + * @returns Asynchronous get all channel groups response. + * + * @deprecated + */ + listGroups(): Promise; + /** + * Add channels to the channel group. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + addChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters, callback: StatusCallback): void; + /** + * Add channels to the channel group. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous add channels to the channel group response. + */ + addChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters): Promise>; + /** + * Remove channels from the channel group. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters, callback: StatusCallback): void; + /** + * Remove channels from the channel group. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous remove channels from the channel group response. + */ + removeChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters): Promise>; + /** + * Remove channel group. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + deleteGroup(parameters: ChannelGroups.DeleteChannelGroupParameters, callback: StatusCallback): void; + /** + * Remove channel group. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous remove channel group response. + */ + deleteGroup(parameters: ChannelGroups.DeleteChannelGroupParameters): Promise>; +} diff --git a/lib/types/core/pubnub-common.d.ts b/lib/types/core/pubnub-common.d.ts new file mode 100644 index 000000000..976ca6564 --- /dev/null +++ b/lib/types/core/pubnub-common.d.ts @@ -0,0 +1,1300 @@ +import { Listener } from './components/listener_manager'; +import NotificationsPayload from './components/push_payload'; +import { TokenManager } from './components/token_manager'; +import Crypto from './components/cryptography/index'; +import { Payload, ResultCallback } from './types/api'; +import { ClientConfiguration, PrivateClientConfiguration } from './interfaces/configuration'; +import { Cryptography } from './interfaces/cryptography'; +import { Transport } from './interfaces/transport'; +import RequestOperation from './constants/operations'; +import StatusCategory from './constants/categories'; +import { RetryPolicy } from '../event-engine/core/retryPolicy'; +import * as Publish from './endpoints/publish'; +import * as Signal from './endpoints/signal'; +import * as Subscription from './types/api/subscription'; +import * as Presence from './types/api/presence'; +import * as History from './types/api/history'; +import * as MessageAction from './types/api/message-action'; +import * as FileSharing from './types/api/file-sharing'; +import { PubNubFileInterface } from './types/file'; +import * as PAM from './types/api/access-panager'; +import { SubscriptionOptions } from '../entities/commonTypes'; +import { ChannelMetadata } from '../entities/ChannelMetadata'; +import { SubscriptionSet } from '../entities/SubscriptionSet'; +import { ChannelGroup } from '../entities/ChannelGroup'; +import { UserMetadata } from '../entities/UserMetadata'; +import { Channel } from '../entities/Channel'; +import PubNubChannelGroups from './pubnub-channel-groups'; +import PubNubPushNotifications from './pubnub-push'; +import * as AppContext from './types/api/app-context'; +import PubNubObjects from './pubnub-objects'; +import * as Time from './endpoints/time'; +type ClientInstanceConfiguration = { + /** + * Client-provided configuration. + */ + configuration: PrivateClientConfiguration; + /** + * Transport provider for requests execution. + */ + transport: Transport; + /** + * REST API endpoints access tokens manager. + */ + tokenManager: TokenManager; + /** + * Legacy crypto module implementation. + */ + cryptography?: Cryptography; + /** + * Legacy crypto (legacy data encryption / decryption and request signature support). + */ + crypto?: Crypto; +}; +/** + * Platform-agnostic PubNub client core. + */ +export declare class PubNubCore = Record> { + /** + * Type of REST API endpoint which reported status. + */ + static OPERATIONS: typeof RequestOperation; + /** + * API call status category. + */ + static CATEGORIES: typeof StatusCategory; + /** + * Exponential retry policy constructor. + */ + static ExponentialRetryPolicy: typeof RetryPolicy.ExponentialRetryPolicy; + /** + * Linear retry policy constructor. + */ + static LinearRetryPolicy: typeof RetryPolicy.LinearRetryPolicy; + /** + * Construct notification payload which will trigger push notification. + * + * @param title - Title which will be shown on notification. + * @param body - Payload which will be sent as part of notification. + * + * @returns Pre-formatted message payload which will trigger push notification. + */ + static notificationPayload(title: string, body: string): NotificationsPayload; + /** + * Generate unique identifier. + * + * @returns Unique identifier. + */ + static generateUUID(): any; + constructor(configuration: ClientInstanceConfiguration); + /** + * PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + */ + get configuration(): ClientConfiguration; + /** + * Current PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + * + * @deprecated Use {@link configuration} getter instead. + */ + get _config(): ClientConfiguration; + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ + get authKey(): string | undefined; + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ + getAuthKey(): string | undefined; + /** + * Change REST API endpoint access authorization key. + * + * @param authKey - New authorization key which should be used with new requests. + */ + setAuthKey(authKey: string): void; + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + get userId(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + set userId(value: string); + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + getUserId(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + setUserId(value: string): void; + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + get filterExpression(): string | undefined; + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + getFilterExpression(): string | undefined; + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + set filterExpression(expression: string | null | undefined); + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + setFilterExpression(expression: string | null): void; + /** + * Dta encryption / decryption key. + * + * @returns Currently used key for data encryption / decryption. + */ + get cipherKey(): string | undefined; + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + set cipherKey(key: string | undefined); + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + setCipherKey(key: string): void; + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ + set heartbeatInterval(interval: number); + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ + setHeartbeatInterval(interval: number): void; + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + getVersion(): string; + /** + * Add framework's prefix. + * + * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. + * @param suffix - Suffix with information about framework. + */ + _addPnsdkSuffix(name: string, suffix: string | number): void; + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + * + * @deprecated Use the {@link getUserId} or {@link userId} getter instead. + */ + getUUID(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + * + * @deprecated Use the {@link PubNubCore#setUserId} or {@link PubNubCore#userId} setter instead. + */ + setUUID(value: string): void; + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + get customEncrypt(): ((data: string) => string) | undefined; + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + get customDecrypt(): ((data: string) => string) | undefined; + /** + * Create a `Channel` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel name. + * @returns `Channel` entity. + */ + channel(name: string): Channel; + /** + * Create a `ChannelGroup` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel group name. + * @returns `ChannelGroup` entity. + */ + channelGroup(name: string): ChannelGroup; + /** + * Create a `ChannelMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique channel metadata object identifier. + * @returns `ChannelMetadata` entity. + */ + channelMetadata(id: string): ChannelMetadata; + /** + * Create a `UserMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique user metadata object identifier. + * @returns `UserMetadata` entity. + */ + userMetadata(id: string): UserMetadata; + /** + * Create subscriptions set object. + * + * @param parameters - Subscriptions set configuration parameters. + */ + subscriptionSet(parameters: { + channels?: string[]; + channelGroups?: string[]; + subscriptionOptions?: SubscriptionOptions; + }): SubscriptionSet; + /** + * Schedule request execution. + * + * @param request - REST API request. + * @param callback - Request completion handler callback. + * + * @returns Asynchronous request execution and response parsing result. + */ + private sendRequest; + /** + * Unsubscribe from all channels and groups. + * + * @param [isOffline] - Whether `offline` presence should be notified or not. + */ + destroy(isOffline?: boolean): void; + /** + * Unsubscribe from all channels and groups. + * + * @deprecated Use {@link destroy} method instead. + */ + stop(): void; + /** + * Register real-time events listener. + * + * @param listener - Listener with event callbacks to handle different types of events. + */ + addListener(listener: Listener): void; + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + */ + removeListener(listener: Listener): void; + /** + * Clear all real-time event listeners. + */ + removeAllListeners(): void; + /** + * Publish data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + publish(parameters: Publish.PublishParameters, callback: ResultCallback): void; + /** + * Publish data to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous publish data response. + */ + publish(parameters: Publish.PublishParameters): Promise; + /** + * Signal data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + signal(parameters: Signal.SignalParameters, callback: ResultCallback): void; + /** + * Signal data to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous signal data response. + */ + signal(parameters: Signal.SignalParameters): Promise; + /** + * `Fire` a data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link publish} method instead. + */ + fire(parameters: Publish.PublishParameters, callback: ResultCallback): void; + /** + * `Fire` a data to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous signal data response. + * + * @deprecated Use {@link publish} method instead. + */ + fire(parameters: Publish.PublishParameters): Promise; + /** + * Get list of channels on which PubNub client currently subscribed. + * + * @returns List of active channels. + */ + getSubscribedChannels(): string[]; + /** + * Get list of channel groups on which PubNub client currently subscribed. + * + * @returns List of active channel groups. + */ + getSubscribedChannelGroups(): string[]; + /** + * Subscribe to specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ + subscribe(parameters: Subscription.SubscribeParameters): void; + /** + * Perform subscribe request. + * + * **Note:** Method passed into managers to let them use it when required. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + private makeSubscribe; + /** + * Unsubscribe from specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ + unsubscribe(parameters: Presence.PresenceLeaveParameters): void; + /** + * Perform unsubscribe request. + * + * **Note:** Method passed into managers to let them use it when required. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + private makeUnsubscribe; + /** + * Unsubscribe from all channels and groups. + */ + unsubscribeAll(): void; + /** + * Temporarily disconnect from real-time events stream. + */ + disconnect(): void; + /** + * Restore connection to the real-time events stream. + * + * @param parameters - Reconnection catch up configuration. **Note:** available only with + * enabled event engine. + */ + reconnect(parameters?: { + timetoken?: string; + region?: number; + }): void; + /** + * Event engine handshake subscribe. + * + * @param parameters - Request configuration parameters. + */ + private subscribeHandshake; + /** + * Event engine receive messages subscribe. + * + * @param parameters - Request configuration parameters. + */ + private subscribeReceiveMessages; + /** + * Get reactions to a specific message. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getMessageActions(parameters: MessageAction.GetMessageActionsParameters, callback: ResultCallback): void; + /** + * Get reactions to a specific message. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get reactions response. + */ + getMessageActions(parameters: MessageAction.GetMessageActionsParameters): Promise; + /** + * Add a reaction to a specific message. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + addMessageAction(parameters: MessageAction.AddMessageActionParameters, callback: ResultCallback): void; + /** + * Add a reaction to a specific message. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous add a reaction response. + */ + addMessageAction(parameters: MessageAction.AddMessageActionParameters): Promise; + /** + * Remove a reaction from a specific message. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeMessageAction(parameters: MessageAction.RemoveMessageActionParameters, callback: ResultCallback): void; + /** + * Remove a reaction from a specific message. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous remove a reaction response. + */ + removeMessageAction(parameters: MessageAction.RemoveMessageActionParameters): Promise; + /** + * Fetch messages history for channels. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + fetchMessages(parameters: History.FetchMessagesParameters, callback: ResultCallback): void; + /** + * Fetch messages history for channels. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous fetch messages response. + */ + fetchMessages(parameters: History.FetchMessagesParameters): Promise; + /** + * Delete messages from the channel history. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated + */ + deleteMessages(parameters: History.DeleteMessagesParameters, callback: ResultCallback): void; + /** + * Delete messages from the channel history. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous delete messages response. + * + * @deprecated + */ + deleteMessages(parameters: History.DeleteMessagesParameters): Promise; + /** + * Count messages from the channels' history. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + messageCounts(parameters: History.MessageCountParameters, callback: ResultCallback): void; + /** + * Count messages from the channels' history. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous count messages response. + */ + messageCounts(parameters: History.MessageCountParameters): Promise; + /** + * Fetch single channel history. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated + */ + history(parameters: History.GetHistoryParameters, callback: ResultCallback): void; + /** + * Fetch single channel history. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous fetch channel history response. + * + * @deprecated + */ + history(parameters: History.GetHistoryParameters): Promise; + /** + * Get channel's presence information. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + hereNow(parameters: Presence.HereNowParameters, callback: ResultCallback): void; + /** + * Get channel presence information. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get channel's presence response. + */ + hereNow(parameters: Presence.HereNowParameters): Promise; + /** + * Get user's presence information. + * + * Get list of channels to which `uuid` currently subscribed. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + whereNow(parameters: Presence.WhereNowParameters, callback: ResultCallback): void; + /** + * Get user's presence information. + * + * Get list of channels to which `uuid` currently subscribed. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get user's presence response. + */ + whereNow(parameters: Presence.WhereNowParameters): Promise; + /** + * Get associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getState(parameters: Presence.GetPresenceStateParameters, callback: ResultCallback): void; + /** + * Get associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get associated user's data response. + */ + getState(parameters: Presence.GetPresenceStateParameters): Promise; + /** + * Set associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + setState(parameters: Presence.SetPresenceStateParameters | Presence.SetPresenceStateWithHeartbeatParameters, callback: ResultCallback): void; + /** + * Set associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous set associated user's data response. + */ + setState(parameters: Presence.SetPresenceStateParameters | Presence.SetPresenceStateWithHeartbeatParameters): Promise; + /** + * Manual presence management. + * + * @param parameters - Desired presence state for provided list of channels and groups. + */ + presence(parameters: { + connected: boolean; + channels?: string[]; + channelGroups?: string[]; + }): void; + /** + * Announce user presence + * + * @param parameters - Desired presence state for provided list of channels and groups. + * @param callback - Request completion handler callback. + */ + private heartbeat; + /** + * Announce user `join` on specified list of channels and groups. + * + * @param parameters - List of channels and groups where `join` event should be sent. + */ + private join; + /** + * Announce user `leave` on specified list of channels and groups. + * + * @param parameters - List of channels and groups where `leave` event should be sent. + */ + private leave; + /** + * Announce user `leave` on all subscribed channels. + */ + private leaveAll; + /** + * Grant token permission. + * + * Generate access token with requested permissions. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + grantToken(parameters: PAM.GrantTokenParameters, callback: ResultCallback): void; + /** + * Grant token permission. + * + * Generate access token with requested permissions. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous grant token response. + */ + grantToken(parameters: PAM.GrantTokenParameters): Promise; + /** + * Revoke token permission. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + revokeToken(parameters: PAM.RevokeParameters, callback: ResultCallback): void; + /** + * Revoke token permission. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous revoke token response. + */ + revokeToken(parameters: PAM.RevokeParameters): Promise; + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ + get token(): string | undefined; + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ + getToken(): string | undefined; + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ + set token(token: string | undefined); + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ + setToken(token: string | undefined): void; + /** + * Parse access token. + * + * Parse token to see what permissions token owner has. + * + * @param token - Token which should be parsed. + * + * @returns Token's permissions information for the resources. + */ + parseToken(token: string): { + version: number; + timestamp: number; + ttl: number; + resources?: Partial>> | undefined; + patterns?: Partial>> | undefined; + authorized_uuid?: string | undefined; + signature: ArrayBuffer; + meta?: Payload | undefined; + } | undefined; + /** + * Grant auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + grant(parameters: PAM.GrantParameters, callback: ResultCallback): void; + /** + * Grant auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous grant auth key(s) permissions response. + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + grant(parameters: PAM.GrantParameters): Promise; + /** + * Audit auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated + */ + audit(parameters: PAM.AuditParameters, callback: ResultCallback): void; + /** + * Audit auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous audit auth key(s) permissions response. + * + * @deprecated + */ + audit(parameters: PAM.AuditParameters): Promise; + /** + * PubNub App Context API group. + */ + get objects(): PubNubObjects; + /** + * Fetch a paginated list of User objects. + * + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + fetchUsers(callback: ResultCallback>): void; + /** + * Fetch a paginated list of User objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + fetchUsers(parameters: AppContext.GetAllMetadataParameters>, callback: ResultCallback>): void; + /** + * Fetch a paginated list of User objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all User objects response. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + fetchUsers(parameters?: AppContext.GetAllMetadataParameters>): Promise>; + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + fetchUser(callback: ResultCallback>): void; + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param parameters - Request configuration parameters. Will fetch User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + fetchUser(parameters: AppContext.GetUUIDMetadataParameters, callback: ResultCallback>): void; + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param [parameters] - Request configuration parameters. Will fetch User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous get User object response. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + fetchUser(parameters?: AppContext.GetUUIDMetadataParameters): Promise>; + /** + * Create User object. + * + * @param parameters - Request configuration parameters. Will create User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + createUser(parameters: AppContext.SetUUIDMetadataParameters, callback: ResultCallback>): void; + /** + * Create User object. + * + * @param parameters - Request configuration parameters. Will create User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous create User object response. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + createUser(parameters: AppContext.SetUUIDMetadataParameters): Promise>; + /** + * Update User object. + * + * @param parameters - Request configuration parameters. Will update User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + updateUser(parameters: AppContext.SetUUIDMetadataParameters, callback: ResultCallback>): void; + /** + * Update User object. + * + * @param parameters - Request configuration parameters. Will update User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous update User object response. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + updateUser(parameters: AppContext.SetUUIDMetadataParameters): Promise>; + /** + * Remove a specific User object. + * + * @param callback - Request completion handler callback. Will remove User object for currently + * configured PubNub client `uuid` if not set. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + removeUser(callback: ResultCallback): void; + /** + * Remove a specific User object. + * + * @param parameters - Request configuration parameters. Will remove User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + removeUser(parameters: AppContext.RemoveUUIDMetadataParameters, callback: ResultCallback): void; + /** + * Remove a specific User object. + * + * @param [parameters] - Request configuration parameters. Will remove User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous User object remove response. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + removeUser(parameters?: AppContext.RemoveUUIDMetadataParameters): Promise; + /** + * Fetch a paginated list of Space objects. + * + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + fetchSpaces(callback: ResultCallback>): void; + /** + * Fetch a paginated list of Space objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + fetchSpaces(parameters: AppContext.GetAllMetadataParameters>, callback: ResultCallback>): void; + /** + * Fetch a paginated list of Space objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all Space objects response. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + fetchSpaces(parameters?: AppContext.GetAllMetadataParameters>): Promise>; + /** + * Fetch a specific Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. + */ + fetchSpace(parameters: AppContext.GetChannelMetadataParameters, callback: ResultCallback>): void; + /** + * Fetch a specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get Channel metadata response. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. + */ + fetchSpace(parameters: AppContext.GetChannelMetadataParameters): Promise>; + /** + * Create specific Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + createSpace(parameters: AppContext.SetChannelMetadataParameters, callback: ResultCallback>): void; + /** + * Create specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous create Space object response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + createSpace(parameters: AppContext.SetChannelMetadataParameters): Promise>; + /** + * Update specific Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + updateSpace(parameters: AppContext.SetChannelMetadataParameters, callback: ResultCallback>): void; + /** + * Update specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous update Space object response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + updateSpace(parameters: AppContext.SetChannelMetadataParameters): Promise>; + /** + * Remove Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. + */ + removeSpace(parameters: AppContext.RemoveChannelMetadataParameters, callback: ResultCallback): void; + /** + * Remove a specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous Space object remove response. + * + * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. + */ + removeSpace(parameters: AppContext.RemoveChannelMetadataParameters): Promise; + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} + * methods instead. + */ + fetchMemberships(parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters, callback: ResultCallback | AppContext.UserMembersResponse>): void; + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get specific Space members or specific User memberships response. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} + * methods instead. + */ + fetchMemberships(parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters): Promise | AppContext.UserMembersResponse>; + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + addMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, callback: ResultCallback | AppContext.SetMembersResponse>): void; + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous add members to specific Space or memberships specific User response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + addMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters): Promise | AppContext.SetMembersResponse>; + /** + * Update specific Space members or User memberships. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + updateMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, callback: ResultCallback | AppContext.SetMembersResponse>): void; + /** + * Update specific Space members or User memberships. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous update Space members or User memberships response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + updateMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters): Promise | AppContext.SetMembersResponse>; + /** + * Remove User membership. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} + * methods instead + * from `objects` API group.. + */ + removeMemberships(parameters: AppContext.RemoveMembersParameters | AppContext.RemoveMembershipsParameters, callback: ResultCallback | AppContext.RemoveMembershipsResponse>): void; + /** + * Remove User membership. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous memberships modification response. + * + * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} + * methods instead + * from `objects` API group.. + */ + removeMemberships(parameters: AppContext.RemoveMembersParameters | AppContext.RemoveMembershipsParameters): Promise>; + /** + * PubNub Channel Groups API group. + */ + get channelGroups(): PubNubChannelGroups; + /** + * PubNub Push Notifications API group. + */ + get push(): PubNubPushNotifications; + /** + * Share file to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + sendFile(parameters: FileSharing.SendFileParameters, callback: ResultCallback): void; + /** + * Share file to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous file sharing response. + */ + sendFile(parameters: FileSharing.SendFileParameters): Promise; + /** + * Publish file message to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + publishFile(parameters: FileSharing.PublishFileMessageParameters, callback: ResultCallback): void; + /** + * Publish file message to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous publish file message response. + */ + publishFile(parameters: FileSharing.PublishFileMessageParameters): Promise; + /** + * Retrieve list of shared files in specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + listFiles(parameters: FileSharing.ListFilesParameters, callback: ResultCallback): void; + /** + * Retrieve list of shared files in specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous shared files list response. + */ + listFiles(parameters: FileSharing.ListFilesParameters): Promise; + /** + * Get file download Url. + * + * @param parameters - Request configuration parameters. + * + * @returns File download Url. + */ + getFileUrl(parameters: FileSharing.FileUrlParameters): FileSharing.FileUrlResponse; + /** + * Download shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + downloadFile(parameters: FileSharing.DownloadFileParameters, callback: ResultCallback): void; + /** + * Download shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous download shared file response. + */ + downloadFile(parameters: FileSharing.DownloadFileParameters): Promise; + /** + * Delete shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + deleteFile(parameters: FileSharing.DeleteFileParameters, callback: ResultCallback): void; + /** + * Delete shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous delete shared file response. + */ + deleteFile(parameters: FileSharing.DeleteFileParameters): Promise; + /** + Get current high-precision timetoken. + * + * @param callback - Request completion handler callback. + */ + time(callback: ResultCallback): void; + /** + * Get current high-precision timetoken. + * + * @returns Asynchronous get current timetoken response. + */ + time(): Promise; + /** + * Encrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @deprecated + * @param [customCipherKey] - Cipher key which should be used to encrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data encryption result as a string. + */ + encrypt(data: string | Payload, customCipherKey?: string): string; + /** + * Decrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @param [customCipherKey] - Cipher key which should be used to decrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data decryption result as an object. + */ + decrypt(data: string, customCipherKey?: string): Payload | null; + /** + * Encrypt file content. + * + * @param file - File which should be encrypted using `CryptoModule`. + * + * @returns Asynchronous file encryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + encryptFile(file: PubNubFileInterface): Promise; + /** + * Encrypt file content. + * + * @param key - Cipher key which should be used to encrypt data. + * @param file - File which should be encrypted using legacy cryptography. + * + * @returns Asynchronous file encryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + encryptFile(key: string, file: PubNubFileInterface): Promise; + /** + * Decrypt file content. + * + * @param file - File which should be decrypted using legacy cryptography. + * + * @returns Asynchronous file decryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + decryptFile(file: PubNubFileInterface): Promise; + /** + * Decrypt file content. + * + * @param key - Cipher key which should be used to decrypt data. + * @param [file] - File which should be decrypted using legacy cryptography. + * + * @returns Asynchronous file decryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + decryptFile(key: string | PubNubFileInterface, file?: PubNubFileInterface): Promise; +} +export {}; diff --git a/lib/types/core/pubnub-objects.d.ts b/lib/types/core/pubnub-objects.d.ts new file mode 100644 index 000000000..75f4f1a7b --- /dev/null +++ b/lib/types/core/pubnub-objects.d.ts @@ -0,0 +1,364 @@ +/** + * PubNub Objects API module. + */ +import { ResultCallback, SendRequestFunction } from './types/api'; +import { PrivateClientConfiguration } from './interfaces/configuration'; +import * as AppContext from './types/api/app-context'; +export default class PubNubObjects { + private readonly configuration; + private readonly sendRequest; + /** + * REST API endpoints access credentials. + */ + private readonly keySet; + constructor(configuration: PrivateClientConfiguration, sendRequest: SendRequestFunction); + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param callback - Request completion handler callback. + */ + getAllUUIDMetadata(callback: ResultCallback>): void; + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getAllUUIDMetadata(parameters: AppContext.GetAllMetadataParameters>, callback: ResultCallback>): void; + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all UUID metadata response. + */ + getAllUUIDMetadata(parameters?: AppContext.GetAllMetadataParameters>): Promise>; + /** + * Fetch a paginated list of UUID Metadata objects. + * + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + */ + _getAllUUIDMetadata(parametersOrCallback?: AppContext.GetAllMetadataParameters> | ResultCallback>, callback?: ResultCallback>): Promise | void>; + /** + * Fetch UUID Metadata object for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + */ + getUUIDMetadata(callback: ResultCallback>): void; + /** + * Fetch a specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will fetch UUID metadata object for + * currently configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + */ + getUUIDMetadata(parameters: AppContext.GetUUIDMetadataParameters, callback: ResultCallback>): void; + /** + * Fetch a specific UUID Metadata object. + * + * @param [parameters] - Request configuration parameters. Will fetch UUID Metadata object for + * currently configured PubNub client `uuid` if not set. + * + * @returns Asynchronous get UUID metadata response. + */ + getUUIDMetadata(parameters?: AppContext.GetUUIDMetadataParameters): Promise>; + /** + * Fetch a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + */ + _getUUIDMetadata(parametersOrCallback?: AppContext.GetUUIDMetadataParameters | ResultCallback>, callback?: ResultCallback>): Promise | void>; + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + */ + setUUIDMetadata(parameters: AppContext.SetUUIDMetadataParameters, callback: ResultCallback>): void; + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous set UUID metadata response. + */ + setUUIDMetadata(parameters: AppContext.SetUUIDMetadataParameters): Promise>; + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set UUID metadata response or `void` in case if `callback` provided. + */ + _setUUIDMetadata(parameters: AppContext.SetUUIDMetadataParameters, callback?: ResultCallback>): Promise | void>; + /** + * Remove UUID Metadata object for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + */ + removeUUIDMetadata(callback: ResultCallback): void; + /** + * Remove a specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will remove UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + */ + removeUUIDMetadata(parameters: AppContext.RemoveUUIDMetadataParameters, callback: ResultCallback): void; + /** + * Remove a specific UUID Metadata object. + * + * @param [parameters] - Request configuration parameters. Will remove UUID metadata for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous UUID metadata remove response. + */ + removeUUIDMetadata(parameters?: AppContext.RemoveUUIDMetadataParameters): Promise; + /** + * Remove a specific UUID Metadata object. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous UUID metadata remove response or `void` in case if `callback` provided. + */ + _removeUUIDMetadata(parametersOrCallback?: AppContext.RemoveUUIDMetadataParameters | ResultCallback, callback?: ResultCallback): Promise; + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param callback - Request completion handler callback. + */ + getAllChannelMetadata(callback: ResultCallback>): void; + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getAllChannelMetadata(parameters: AppContext.GetAllMetadataParameters>, callback: ResultCallback>): void; + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all Channel metadata response. + */ + getAllChannelMetadata(parameters?: AppContext.GetAllMetadataParameters>): Promise>; + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parametersOrCallback] - Request configuration parameters or callback from overload. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get all Channel metadata response or `void` in case if `callback` + * provided. + */ + _getAllChannelMetadata(parametersOrCallback?: AppContext.GetAllMetadataParameters> | ResultCallback>, callback?: ResultCallback>): Promise | void>; + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getChannelMetadata(parameters: AppContext.GetChannelMetadataParameters, callback: ResultCallback>): void; + /** + * Fetch a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get Channel metadata response. + */ + getChannelMetadata(parameters: AppContext.GetChannelMetadataParameters): Promise>; + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get Channel metadata response or `void` in case if `callback` provided. + */ + _getChannelMetadata(parameters: AppContext.GetChannelMetadataParameters, callback?: ResultCallback>): Promise | void>; + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + setChannelMetadata(parameters: AppContext.SetChannelMetadataParameters, callback: ResultCallback>): void; + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous set Channel metadata response. + */ + setChannelMetadata(parameters: AppContext.SetChannelMetadataParameters): Promise>; + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous set Channel metadata response or `void` in case if `callback` provided. + */ + _setChannelMetadata(parameters: AppContext.SetChannelMetadataParameters, callback?: ResultCallback>): Promise | void>; + /** + * Remove Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeChannelMetadata(parameters: AppContext.RemoveChannelMetadataParameters, callback: ResultCallback): void; + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous Channel metadata remove response. + */ + removeChannelMetadata(parameters: AppContext.RemoveChannelMetadataParameters): Promise; + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous Channel metadata remove response or `void` in case if `callback` + * provided. + */ + _removeChannelMetadata(parameters: AppContext.RemoveChannelMetadataParameters, callback?: ResultCallback): Promise; + /** + * Fetch a paginated list of Channel Member objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getChannelMembers(parameters: AppContext.GetMembersParameters, callback: ResultCallback>): void; + /** + * Fetch a paginated list of Channel Member objects. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get Channel Members response. + */ + getChannelMembers(parameters: AppContext.GetMembersParameters): Promise>; + /** + * Update specific Channel Members list. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + setChannelMembers(parameters: AppContext.SetChannelMembersParameters, callback: ResultCallback>): void; + /** + * Update specific Channel Members list. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous update Channel Members list response. + */ + setChannelMembers(parameters: AppContext.SetChannelMembersParameters): Promise>; + /** + * Remove Members from the Channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeChannelMembers(parameters: AppContext.RemoveMembersParameters, callback: ResultCallback>): void; + /** + * Remove Members from the Channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous Channel Members remove response. + */ + removeChannelMembers(parameters: AppContext.RemoveMembersParameters): Promise>; + /** + * Fetch a specific UUID Memberships list for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + * + * @returns Asynchronous get UUID Memberships list response or `void` in case if `callback` + * provided. + */ + getMemberships(callback: ResultCallback>): void; + /** + * Fetch a specific UUID Memberships list. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getMemberships(parameters: AppContext.GetMembershipsParameters, callback: ResultCallback>): void; + /** + * Fetch a specific UUID Memberships list. + * + * @param [parameters] - Request configuration parameters. Will fetch UUID Memberships list for + * currently configured PubNub client `uuid` if not set. + * + * @returns Asynchronous get UUID Memberships list response. + */ + getMemberships(parameters?: AppContext.GetMembershipsParameters): Promise>; + /** + * Update specific UUID Memberships list. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + setMemberships(parameters: AppContext.SetMembershipsParameters, callback: ResultCallback>): void; + /** + * Update specific UUID Memberships list. + * + * @param parameters - Request configuration parameters or callback from overload. + * + * @returns Asynchronous update UUID Memberships list response. + */ + setMemberships(parameters: AppContext.SetMembershipsParameters): Promise>; + /** + * Remove a specific UUID Memberships. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeMemberships(parameters: AppContext.RemoveMembershipsParameters, callback: ResultCallback>): void; + /** + * Remove a specific UUID Memberships. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous UUID Memberships remove response. + */ + removeMemberships(parameters: AppContext.RemoveMembershipsParameters): Promise>; + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get specific Space members or specific User memberships response. + * + * @deprecated Use {@link PubNubObjects#getChannelMembers} or {@link PubNubObjects#getMemberships} methods instead. + */ + fetchMemberships(parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters, callback?: ResultCallback | AppContext.UserMembersResponse>): Promise | AppContext.UserMembersResponse | void>; + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add members to specific Space or memberships specific User response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubObjects#setChannelMembers} or {@link PubNubObjects#setMemberships} methods instead. + */ + addMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, callback?: ResultCallback | AppContext.SetMembersResponse>): Promise | AppContext.SetMembersResponse | void>; +} diff --git a/lib/types/core/pubnub-push.d.ts b/lib/types/core/pubnub-push.d.ts new file mode 100644 index 000000000..33d8c02ea --- /dev/null +++ b/lib/types/core/pubnub-push.d.ts @@ -0,0 +1,64 @@ +/** + * PubNub Push Notifications API module. + */ +import { KeySet, ResultCallback, SendRequestFunction, StatusCallback } from './types/api'; +import * as Push from './types/api/push'; +export default class PubNubPushNotifications { + private readonly keySet; + private readonly sendRequest; + constructor(keySet: KeySet, sendRequest: SendRequestFunction); + /** + * Fetch device's push notification enabled channels. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + listChannels(parameters: Push.ListDeviceChannelsParameters, callback: ResultCallback): void; + /** + * Fetch device's push notification enabled channels. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get device channels response. + */ + listChannels(parameters: Push.ListDeviceChannelsParameters): Promise; + /** + * Enable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + addChannels(parameters: Push.ManageDeviceChannelsParameters, callback: StatusCallback): void; + /** + * Enable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + */ + addChannels(parameters: Push.ManageDeviceChannelsParameters): Promise; + /** + * Disable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeChannels(parameters: Push.ManageDeviceChannelsParameters, callback: StatusCallback): void; + /** + * Disable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + */ + removeChannels(parameters: Push.ManageDeviceChannelsParameters): Promise; + /** + * Disable push notifications for device. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + deleteDevice(parameters: Push.RemoveDeviceParameters, callback: StatusCallback): void; + /** + * Disable push notifications for device. + * + * @param parameters - Request configuration parameters. + */ + deleteDevice(parameters: Push.RemoveDeviceParameters): Promise; +} diff --git a/lib/types/core/types/api/access-panager.d.ts b/lib/types/core/types/api/access-panager.d.ts new file mode 100644 index 000000000..36f4c5ca4 --- /dev/null +++ b/lib/types/core/types/api/access-panager.d.ts @@ -0,0 +1,466 @@ +/** + * Metadata which will be associated with access token. + */ +export type Metadata = Record; +/** + * Channel-specific token permissions. + */ +export type ChannelTokenPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + read?: boolean; + /** + * Whether `write` operations are permitted for corresponding level or not. + */ + write?: boolean; + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + get?: boolean; + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + manage?: boolean; + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + update?: boolean; + /** + * Whether `join` operations are permitted for corresponding level or not. + */ + join?: boolean; + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + delete?: boolean; +}; +/** + * Space-specific token permissions. + */ +type SpaceTokenPermissions = ChannelTokenPermissions; +/** + * Channel group-specific token permissions. + */ +export type ChannelGroupTokenPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + read?: boolean; + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + manage?: boolean; +}; +/** + * Uuid-specific token permissions. + */ +export type UuidTokenPermissions = { + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + get?: boolean; + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + update?: boolean; + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + delete?: boolean; +}; +/** + * User-specific token permissions. + */ +type UserTokenPermissions = UuidTokenPermissions; +/** + * Generate access token with permissions. + * + * Generate time-limited access token with required permissions for App Context objects. + */ +export type ObjectsGrantTokenParameters = { + /** + * Total number of minutes for which the token is valid. + * + * The minimum allowed value is `1`. + * The maximum is `43,200` minutes (`30` days). + */ + ttl: number; + /** + * Object containing resource permissions. + */ + resources?: { + /** + * Object containing `spaces` metadata permissions. + */ + spaces?: Record; + /** + * Object containing `users` permissions. + */ + users?: Record; + }; + /** + * Object containing permissions to multiple resources specified by a RegEx pattern. + */ + patterns?: { + /** + * Object containing `spaces` metadata permissions. + */ + spaces?: Record; + /** + * Object containing `users` permissions. + */ + users?: Record; + }; + /** + * Extra metadata to be published with the request. + * + * **Important:** Values must be scalar only; `arrays` or `objects` aren't supported. + */ + meta?: Metadata; + /** + * Single `userId` which is authorized to use the token to make API requests to PubNub. + */ + authorizedUserId?: string; +}; +/** + * Generate token with permissions. + * + * Generate time-limited access token with required permissions for resources. + */ +export type GrantTokenParameters = { + /** + * Total number of minutes for which the token is valid. + * + * The minimum allowed value is `1`. + * The maximum is `43,200` minutes (`30` days). + */ + ttl: number; + /** + * Object containing resource permissions. + */ + resources?: { + /** + * Object containing `uuid` metadata permissions. + */ + uuids?: Record; + /** + * Object containing `channel` permissions. + */ + channels?: Record; + /** + * Object containing `channel group` permissions. + */ + groups?: Record; + }; + /** + * Object containing permissions to multiple resources specified by a RegEx pattern. + */ + patterns?: { + /** + * Object containing `uuid` metadata permissions to apply to all `uuids` matching the RegEx + * pattern. + */ + uuids?: Record; + /** + * Object containing `channel` permissions to apply to all `channels` matching the RegEx + * pattern. + */ + channels?: Record; + /** + * Object containing `channel group` permissions to apply to all `channel groups` matching the + * RegEx pattern. + */ + groups?: Record; + }; + /** + * Extra metadata to be published with the request. + * + * **Important:** Values must be scalar only; `arrays` or `objects` aren't supported. + */ + meta?: Metadata; + /** + * Single `uuid` which is authorized to use the token to make API requests to PubNub. + */ + authorized_uuid?: string; +}; +/** + * Response with generated access token. + */ +export type GrantTokenResponse = string; +export type RevokeParameters = { + /** + * Access token for which permissions should be revoked. + */ + token: string; +}; +/** + * Response with revoked access token. + */ +export type RevokeTokenResponse = Record; +/** + * Channel-specific permissions. + * + * Permissions include objects to the App Context Channel object as well. + */ +type ChannelPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + r?: 0 | 1; + /** + * Whether `write` operations are permitted for corresponding level or not. + */ + w?: 0 | 1; + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + d?: 0 | 1; + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + g?: 0 | 1; + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + u?: 0 | 1; + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + m?: 0 | 1; + /** + * Whether `join` operations are permitted for corresponding level or not. + */ + j?: 0 | 1; + /** + * Duration for which permissions has been granted. + */ + ttl?: number; +}; +/** + * Channel group-specific permissions. + */ +type ChannelGroupPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + r?: 0 | 1; + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + m?: 0 | 1; + /** + * Duration for which permissions has been granted. + */ + ttl?: number; +}; +/** + * App Context User-specific permissions. + */ +type UserPermissions = { + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + g?: 0 | 1; + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + u?: 0 | 1; + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + d?: 0 | 1; + /** + * Duration for which permissions has been granted. + */ + ttl?: number; +}; +/** + * Common permissions audit response content. + */ +type BaseAuditResponse = { + /** + * Permissions level. + */ + level: Level; + /** + * Subscription key at which permissions has been granted. + */ + subscribe_key: string; + /** + * Duration for which permissions has been granted. + */ + ttl?: number; +}; +/** + * Auth keys permissions for specified `level`. + */ +type AuthKeysPermissions = { + /** + * Auth keys-based permissions for specified `level` permission. + */ + auths: Record; +}; +/** + * Single channel permissions audit result. + */ +type ChannelPermissionsResponse = BaseAuditResponse<'channel+auth'> & { + /** + * Name of channel for which permissions audited. + */ + channel: string; +} & AuthKeysPermissions; +/** + * Multiple channels permissions audit result. + */ +type ChannelsPermissionsResponse = BaseAuditResponse<'channel'> & { + /** + * Per-channel permissions. + */ + channels: Record>; +}; +/** + * Single channel group permissions result. + */ +type ChannelGroupPermissionsResponse = BaseAuditResponse<'channel-group+auth'> & { + /** + * Name of channel group for which permissions audited. + */ + 'channel-group': string; +} & AuthKeysPermissions; +/** + * Multiple channel groups permissions audit result. + */ +type ChannelGroupsPermissionsResponse = BaseAuditResponse<'channel'> & { + /** + * Per-channel group permissions. + */ + 'channel-groups': Record>; +}; +/** + * App Context User permissions audit result. + */ +type UserPermissionsResponse = BaseAuditResponse<'user'> & { + /** + * Name of channel for which `user` permissions audited. + */ + channel: string; +} & AuthKeysPermissions; +/** + * Global sub-key level permissions audit result. + */ +type SubKeyPermissionsResponse = BaseAuditResponse<'subkey'> & { + /** + * Per-channel permissions. + */ + channels: Record>; + /** + * Per-channel group permissions. + */ + 'channel-groups': Record>; + /** + * Per-object permissions. + */ + objects: Record>; +}; +/** + * Response with permission information. + */ +export type PermissionsResponse = ChannelPermissionsResponse | ChannelsPermissionsResponse | ChannelGroupPermissionsResponse | ChannelGroupsPermissionsResponse | UserPermissionsResponse | SubKeyPermissionsResponse; +/** + * Audit permissions for provided auth keys / global permissions. + * + * Audit permissions on specific channel and / or channel group for the set of auth keys. + */ +export type AuditParameters = { + /** + * Name of channel for which channel-based permissions should be checked for {@link authKeys}. + */ + channel?: string; + /** + * Name of channel group for which channel group-based permissions should be checked for {@link authKeys}. + */ + channelGroup?: string; + /** + * List of auth keys for which permissions should be checked. + * + * Leave this empty to check channel / group -based permissions or global permissions. + * + * @default `[]` + */ + authKeys?: string[]; +}; +/** + * Grant permissions for provided auth keys / global permissions. + * + * Grant permissions on specific channel and / or channel group for the set of auth keys. + */ +export type GrantParameters = { + /** + * List of channels for which permissions should be granted. + */ + channels?: string[]; + /** + * List of channel groups for which permissions should be granted. + */ + channelGroups?: string[]; + /** + * List of App Context UUID for which permissions should be granted. + */ + uuids?: string[]; + /** + * List of auth keys for which permissions should be granted on specified objects. + * + * Leave this empty to grant channel / group -based permissions or global permissions. + */ + authKeys?: string[]; + /** + * Whether `read` operations are permitted for corresponding level or not. + * + * @default `false` + */ + read?: boolean; + /** + * Whether `write` operations are permitted for corresponding level or not. + * + * @default `false` + */ + write?: boolean; + /** + * Whether `delete` operations are permitted for corresponding level or not. + * + * @default `false` + */ + delete?: boolean; + /** + * Whether `get` operations are permitted for corresponding level or not. + * + * @default `false` + */ + get?: boolean; + /** + * Whether `update` operations are permitted for corresponding level or not. + * + * @default `false` + */ + update?: boolean; + /** + * Whether `manage` operations are permitted for corresponding level or not. + * + * @default `false` + */ + manage?: boolean; + /** + * Whether `join` operations are permitted for corresponding level or not. + * + * @default `false` + */ + join?: boolean; + /** + * For how long permissions should be effective (in minutes). + * + * @default `1440` + */ + ttl?: number; +}; +export {}; diff --git a/lib/types/core/types/api/app-context.d.ts b/lib/types/core/types/api/app-context.d.ts new file mode 100644 index 000000000..2017fdcf7 --- /dev/null +++ b/lib/types/core/types/api/app-context.d.ts @@ -0,0 +1,875 @@ +/** + * Partial nullability helper type. + */ +type PartialNullable = { + [P in keyof T]?: T[P] | null; +}; +/** + * Custom data which should be associated with metadata objects or their relation. + */ +export type CustomData = { + [key: string]: string | number | boolean | null; +}; +/** + * Type provides shape of App Context parameters which is common to the all objects types to + * be updated. + */ +type ObjectParameters = { + custom?: Custom; +}; +/** + * Type provides shape of App Context object which is common to the all objects types received + * from the PubNub service. + */ +export type ObjectData = { + /** + * Unique App Context object identifier. + * + * **Important:** For channel it is different from the channel metadata object name. + */ + id: string; + /** + * Last date and time when App Context object has been updated. + * + * String built from date using ISO 8601. + */ + updated: string; + /** + * App Context version hash. + */ + eTag: string; + /** + * Additional data associated with App Context object. + * + * **Important:** Values must be scalars; only arrays or objects are supported. + * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|App Context + * filtering language} doesn’t support filtering by custom properties. + */ + custom?: Custom | null; +}; +/** + * Type provides shape of object which let establish relation between metadata objects. + */ +type ObjectsRelation = { + /** + * App Context object unique identifier. + */ + id: string; + /** + * App Context objects relation status. + */ + status?: string; + /** + * Additional data associated with App Context object relation (membership or members). + * + * **Important:** Values must be scalars; only arrays or objects are supported. + * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|App Context + * filtering language} doesn’t support filtering by custom properties. + */ + custom?: Custom; +}; +/** + * Response page cursor. + */ +type Page = { + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for forward pagination, it fetches the next page, allowing you to continue from where + * you left off. + */ + next?: string; + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for backward pagination, it fetches the previous page, enabling access to earlier + * data. + * + * **Important:** Ignored if the `next` parameter is supplied. + */ + prev?: string; +}; +/** + * Metadata objects include options. + * + * Allows to configure what additional information should be included into service response. + */ +type IncludeOptions = { + /** + * Whether to include total number of App Context objects in the response. + * + * @default `false` + */ + totalCount?: boolean; + /** + * Whether to include App Context object `custom` field in the response. + * + * @default `false` + */ + customFields?: boolean; +}; +/** + * Membership objects include options. + * + * Allows to configure what additional information should be included into service response. + */ +type MembershipsIncludeOptions = IncludeOptions & { + /** + * Whether to include all {@link ChannelMetadata} fields in the response. + * + * @default `false` + */ + channelFields?: boolean; + /** + * Whether to include {@link ChannelMetadata} `custom` field in the response. + * + * @default `false` + */ + customChannelFields?: boolean; + /** + * Whether to include the membership's status field in the response. + * + * @default `false` + */ + statusField?: boolean; + /** + * Whether to include the channel's status field in the response. + * + * @default `false` + */ + channelStatusField?: boolean; + /** + * Whether to include channel's type fields in the response. + * + * @default `false` + */ + channelTypeField?: boolean; +}; +/** + * Members objects include options. + * + * Allows to configure what additional information should be included into service response. + */ +type MembersIncludeOptions = IncludeOptions & { + /** + * Whether to include all {@link UUIMetadata} fields in the response. + * + * @default `false` + */ + UUIDFields?: boolean; + /** + * Whether to include {@link UUIMetadata} `custom` field in the response. + * + * @default `false` + */ + customUUIDFields?: boolean; + /** + * Whether to include the members's status field in the response. + * + * @default `false` + */ + statusField?: boolean; + /** + * Whether to include the user's status field in the response. + * + * @default `false` + */ + UUIDStatusField?: boolean; + /** + * Whether to include user's type fields in the response. + * + * @default `false` + */ + UUIDTypeField?: boolean; +}; +/** + * Type provides shape of App Context parameters which is common to the all objects types to + * fetch them by pages. + */ +type PagedRequestParameters = { + /** + * Fields which can be additionally included into response. + */ + include?: Include; + /** + * Expression used to filter the results. + * + * Only objects whose properties satisfy the given expression are returned. The filter language is + * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|defined here}. + */ + filter?: string; + /** + * Fetched App Context objects sorting options. + */ + sort?: Sort; + /** + * Number of objects to return in response. + * + * **Important:** Maximum for this API is `100` objects per-response. + * + * @default `100` + */ + limit?: number; + /** + * Response pagination configuration. + */ + page?: Page; +}; +/** + * Type provides shape of App Context object fetch response which is common to the all objects + * types received from the PubNub service. + */ +type ObjectResponse = { + /** + * App Context objects list fetch result status code. + */ + status: number; + /** + * Received App Context object information. + */ + data: ObjectType; +}; +/** + * Type provides shape of App Context objects fetch response which is common to the all + * objects types received from the PubNub service. + */ +type PagedResponse = ObjectResponse & { + /** + * Total number of App Context objects in the response. + */ + totalCount?: number; + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for forward pagination, it fetches the next page, allowing you to continue from where + * you left off. + */ + next?: string; + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for backward pagination, it fetches the previous page, enabling access to earlier + * data. + * + * **Important:** Ignored if the `next` parameter is supplied. + */ + prev?: string; +}; +/** + * Key-value pair of a property to sort by, and a sort direction. + */ +type MetadataSortingOptions = keyof Omit | ({ + [K in keyof Omit]?: 'asc' | 'desc' | null; +} & { + [key: `custom.${string}`]: 'asc' | 'desc' | null; +}); +/** + * Key-value pair of a property to sort by, and a sort direction. + */ +type MembershipsSortingOptions = 'channel.id' | 'channel.name' | 'channel.description' | 'channel.updated' | 'space.id' | 'space.name' | 'space.description' | 'space.updated' | 'updated' | { + /** + * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.id'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.name'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `description` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.description'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.id` instead. + */ + 'space.id'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.name` instead. + */ + 'space.name'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `description` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.name` instead. + */ + 'space.description'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.updated` instead. + */ + 'space.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by `updated` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + updated?: 'asc' | 'desc' | null; +}; +/** + * Key-value pair of a property to sort by, and a sort direction. + */ +type MembersSortingOptions = 'uuid.id' | 'uuid.name' | 'uuid.updated' | 'user.id' | 'user.name' | 'user.updated' | 'updated' | { + /** + * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.id'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.name'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `uuid.id` instead. + */ + 'user.id'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `uuid.name` instead. + */ + 'user.name'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `uuid.updated` instead. + */ + 'user.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by `updated` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + updated?: 'asc' | 'desc' | null; +}; +/** + * Fetch All UUID or Channel Metadata request parameters. + */ +export type GetAllMetadataParameters = PagedRequestParameters>; +/** + * Type which describes own UUID metadata object fields. + */ +type UUIDMetadataFields = { + /** + * Display name for the user. + */ + name?: string; + /** + * The user's email address. + */ + email?: string; + /** + * User's identifier in an external system. + */ + externalId?: string; + /** + * The URL of the user's profile picture. + */ + profileUrl?: string; + /** + * User's object type information. + */ + type?: string; + /** + * User's object status. + */ + status?: string; +}; +/** + * Updated UUID metadata object. + * + * Type represents updated UUID metadata object which will be pushed to the PubNub service. + */ +type UUIDMetadata = ObjectParameters & Partial; +/** + * Received UUID metadata object. + * + * Type represents UUID metadata retrieved from the PubNub service. + */ +export type UUIDMetadataObject = ObjectData & PartialNullable; +/** + * Response with fetched page of UUID metadata objects. + */ +export type GetAllUUIDMetadataResponse = PagedResponse>; +/** + * Fetch UUID Metadata request parameters. + */ +export type GetUUIDMetadataParameters = { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `getUUIDMetadata()` method instead. + */ + userId?: string; + /** + * Fields which can be additionally included into response. + */ + include?: Omit; +}; +/** + * Response with requested UUID metadata object. + */ +export type GetUUIDMetadataResponse = ObjectResponse>; +/** + * Update UUID Metadata request parameters. + */ +export type SetUUIDMetadataParameters = { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `setUUIDMetadata()` method instead. + */ + userId?: string; + /** + * Metadata, which should be associated with UUID. + */ + data: UUIDMetadata; + /** + * Fields which can be additionally included into response. + */ + include?: Omit; +}; +/** + * Response with result of the UUID metadata object update. + */ +export type SetUUIDMetadataResponse = ObjectResponse>; +/** + * Remove UUID Metadata request parameters. + */ +export type RemoveUUIDMetadataParameters = { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `removeUUIDMetadata()` method instead. + */ + userId?: string; +}; +/** + * Response with result of the UUID metadata removal. + */ +export type RemoveUUIDMetadataResponse = ObjectResponse>; +/** + * Type which describes own Channel metadata object fields. + */ +type ChannelMetadataFields = { + /** + * Name of a channel. + */ + name?: string; + /** + * Description of a channel. + */ + description?: string; + /** + * Channel's object type information. + */ + type?: string; + /** + * Channel's object status. + */ + status?: string; +}; +/** + * Updated channel metadata object. + * + * Type represents updated channel metadata object which will be pushed to the PubNub service. + */ +type ChannelMetadata = ObjectParameters & Partial; +/** + * Received channel metadata object. + * + * Type represents chanel metadata retrieved from the PubNub service. + */ +export type ChannelMetadataObject = ObjectData & PartialNullable; +/** + * Response with fetched page of channel metadata objects. + */ +export type GetAllChannelMetadataResponse = PagedResponse>; +/** + * Fetch Channel Metadata request parameters. + */ +export type GetChannelMetadataParameters = { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `getChannelMetadata()` method instead. + */ + spaceId?: string; + /** + * Fields which can be additionally included into response. + */ + include?: Omit; +}; +/** + * Response with requested channel metadata object. + */ +export type GetChannelMetadataResponse = ObjectResponse>; +/** + * Update Channel Metadata request parameters. + */ +export type SetChannelMetadataParameters = { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `setChannelMetadata()` method instead. + */ + spaceId?: string; + /** + * Metadata, which should be associated with UUID. + */ + data: ChannelMetadata; + /** + * Fields which can be additionally included into response. + */ + include?: Omit; +}; +/** + * Response with result of the channel metadata object update. + */ +export type SetChannelMetadataResponse = ObjectResponse>; +/** + * Remove Channel Metadata request parameters. + */ +export type RemoveChannelMetadataParameters = { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `removeChannelMetadata()` method instead. + */ + spaceId?: string; +}; +/** + * Response with result of the channel metadata removal. + */ +export type RemoveChannelMetadataResponse = ObjectResponse>; +/** + * Related channel metadata object. + * + * Type represents chanel metadata which has been used to create membership relation with UUID. + */ +type MembershipsObject = Omit, 'id'> & { + channel: ChannelMetadataObject | { + id: string; + }; +}; +/** + * Response with fetched page of UUID membership objects. + */ +type MembershipsResponse = PagedResponse>; +/** + * Fetch Memberships request parameters. + */ +export type GetMembershipsParameters = PagedRequestParameters & { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuidId`. + * + * @deprecated Use `uuid` field instead. + */ + userId?: string; +}; +/** + * Response with requested channel memberships information. + */ +export type GetMembershipsResponse = MembershipsResponse; +/** + * Update Memberships request parameters. + */ +export type SetMembershipsParameters = PagedRequestParameters, MembershipsSortingOptions> & { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `uuid` field instead. + */ + userId?: string; + /** + * List of channels with which UUID membership should be established. + */ + channels: Array>; + /** + * List of channels with which UUID membership should be established. + * + * @deprecated Use `channels` field instead. + */ + spaces?: Array, 'id'> & { + /** + * Unique Space object identifier. + */ + spaceId: string; + })>; +}; +/** + * Response with requested channel memberships information change. + */ +export type SetMembershipsResponse = MembershipsResponse; +/** + * Remove Memberships request parameters. + */ +export type RemoveMembershipsParameters = PagedRequestParameters & { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use {@link uuid} field instead. + */ + userId?: string; + /** + * List of channels for which membership which UUID should be removed. + */ + channels: string[]; + /** + * List of space names for which membership which UUID should be removed. + * + * @deprecated Use {@link channels} field instead. + */ + spaceIds?: string[]; +}; +/** + * Response with remaining memberships. + */ +export type RemoveMembershipsResponse = MembershipsResponse; +/** + * Related UUID metadata object. + * + * Type represents UUID metadata which has been used to when added members to the channel. + */ +type MembersObject = Omit, 'id'> & { + uuid: UUIDMetadataObject | { + id: string; + }; +}; +/** + * Response with fetched page of channel member objects. + */ +type MembersResponse = PagedResponse>; +/** + * Fetch Members request parameters. + */ +export type GetMembersParameters = PagedRequestParameters & { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `channel` field instead. + */ + spaceId?: string; +}; +/** + * Response with requested channel memberships information. + */ +export type GetMembersResponse = MembersResponse; +/** + * Update Members request parameters. + */ +export type SetChannelMembersParameters = PagedRequestParameters, MembersSortingOptions> & { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `channel` field instead. + */ + spaceId?: string; + /** + * List of UUIDs which should be added as `channel` members. + */ + uuids: Array>; + /** + * List of UUIDs which should be added as `channel` members. + * + * @deprecated Use `uuids` field instead. + */ + users?: Array, 'id'> & { + /** + * Unique User object identifier. + */ + userId: string; + })>; +}; +/** + * Response with requested channel members information change. + */ +export type SetMembersResponse = MembersResponse; +/** + * Remove Members request parameters. + */ +export type RemoveMembersParameters = PagedRequestParameters & { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use {@link channel} field instead. + */ + spaceId?: string; + /** + * List of UUIDs which should be removed from the `channel` members list. + * removed. + */ + uuids: string[]; + /** + * List of user identifiers which should be removed from the `channel` members list. + * removed. + * + * @deprecated Use {@link uuids} field instead. + */ + userIds?: string[]; +}; +/** + * Response with remaining members. + */ +export type RemoveMembersResponse = MembersResponse; +/** + * Related User metadata object. + * + * Type represents User metadata which has been used to when added members to the Space. + */ +type UserMembersObject = Omit, 'id'> & { + user: UUIDMetadataObject | { + id: string; + }; +}; +/** + * Response with fetched page of Space member objects. + */ +export type UserMembersResponse = PagedResponse>; +type SpaceMembershipObject = Omit, 'id'> & { + space: ChannelMetadataObject | { + id: string; + }; +}; +/** + * Response with fetched page of User membership objects. + */ +export type SpaceMembershipsResponse = PagedResponse>; +export {}; diff --git a/lib/types/core/types/api/channel-groups.d.ts b/lib/types/core/types/api/channel-groups.d.ts new file mode 100644 index 000000000..80cd4717a --- /dev/null +++ b/lib/types/core/types/api/channel-groups.d.ts @@ -0,0 +1,57 @@ +/** + * Add or remove Channels to the channel group request parameters. + */ +export type ManageChannelGroupChannelsParameters = { + /** + * Name of the channel group for which channels list should be changed. + */ + channelGroup: string; + /** + * List of channels to be added or removed. + */ + channels: string[]; +}; +/** + * Channel group channels list manage response. + */ +export type ManageChannelGroupChannelsResponse = Record; +/** + * Response with result of the all channel groups list. + */ +export type ListAllChannelGroupsResponse = { + /** + * All channel groups with channels. + */ + groups: string[]; +}; +/** + * List Channel Group Channels request parameters. + */ +export type ListChannelGroupChannelsParameters = { + /** + * Name of the channel group for which list of channels should be retrieved. + */ + channelGroup: string; +}; +/** + * Response with result of the list channel group channels. + */ +export type ListChannelGroupChannelsResponse = { + /** + * List of the channels registered withing specified channel group. + */ + channels: string[]; +}; +/** + * Delete Channel Group request parameters. + */ +export type DeleteChannelGroupParameters = { + /** + * Name of the channel group which should be removed. + */ + channelGroup: string; +}; +/** + * Delete channel group response. + */ +export type DeleteChannelGroupResponse = Record; diff --git a/lib/types/core/types/api/file-sharing.d.ts b/lib/types/core/types/api/file-sharing.d.ts new file mode 100644 index 000000000..5bc19beee --- /dev/null +++ b/lib/types/core/types/api/file-sharing.d.ts @@ -0,0 +1,357 @@ +/** + * File Sharing REST API module. + */ +import { PubNubFileInterface } from '../file'; +import { Payload } from './index'; +/** + * Shared file object. + */ +export type SharedFile = { + /** + * Name with which file has been stored. + */ + name: string; + /** + * Unique service-assigned file identifier. + */ + id: string; + /** + * Shared file size. + */ + size: number; + /** + * ISO 8601 time string when file has been shared. + */ + created: string; +}; +/** + * List Files request parameters. + */ +export type ListFilesParameters = { + /** + * Name of channel for which list of files should be requested. + */ + channel: string; + /** + * How many entries return with single response. + */ + limit?: number; + /** + * Next files list page token. + */ + next?: string; +}; +/** + * List Files request response. + */ +export type ListFilesResponse = { + /** + * Files list fetch result status code. + */ + status: number; + /** + * List of fetched file objects. + */ + data: SharedFile[]; + /** + * Next files list page token. + */ + next: string; + /** + * Number of retrieved files. + */ + count: number; +}; +/** + * Send File request parameters. + */ +export type SendFileParameters = Omit & { + /** + * Channel to send the file to. + */ + channel: string; + /** + * File to send. + */ + file: FileParameters; +}; +/** + * Send File request response. + */ +export type SendFileResponse = PublishFileMessageResponse & { + /** + * Send file request processing status code. + */ + status: number; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Important:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; + /** + * Unique file identifier. + * + * Unique file identifier and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; +}; +/** + * Upload File request parameters. + */ +export type UploadFileParameters = { + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link fileName} can be used to download file from the channel + * later. + */ + fileId: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link fileId} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + fileName: string; + /** + * File which should be uploaded. + */ + file: PubNubFileInterface; + /** + * Pre-signed file upload Url. + */ + uploadUrl: string; + /** + * An array of form fields to be used in the pre-signed POST request. + * + * **Important:** Form data fields should be passed in exact same order as received from + * the PubNub service. + */ + formFields: { + /** + * Form data field name. + */ + name: string; + /** + * Form data field value. + */ + value: string; + }[]; +}; +/** + * Upload File request response. + */ +export type UploadFileResponse = { + /** + * Upload File request processing status code. + */ + status: number; + /** + * Service processing result response. + */ + message: Payload; +}; +/** + * Generate File Upload URL request parameters. + */ +export type GenerateFileUploadUrlParameters = { + /** + * Name of channel to which file should be uploaded. + */ + channel: string; + /** + * Actual name of the file which should be uploaded. + */ + name: string; +}; +/** + * Generation File Upload URL request response. + */ +export type GenerateFileUploadUrlResponse = { + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; + /** + * Pre-signed URL for file upload. + */ + url: string; + /** + * An array of form fields to be used in the pre-signed POST request. + * + * **Important:** Form data fields should be passed in exact same order as received from + * the PubNub service. + */ + formFields: { + /** + * Form data field name. + */ + name: string; + /** + * Form data field value. + */ + value: string; + }[]; +}; +/** + * Publish File Message request parameters. + */ +export type PublishFileMessageParameters = { + /** + * Name of channel to which file has been sent. + */ + channel: string; + /** + * File annotation message. + */ + message?: Payload; + /** + * Custom file and message encryption key. + * + * @deprecated Use {@link Configuration#cryptoModule|cryptoModule} configured for PubNub client + * instance or encrypt file prior {@link PubNub#sendFile|sendFile} method call. + */ + cipherKey?: string; + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link fileName} can be used to download file from the channel + * later. + */ + fileId: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link fileId} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + fileName: string; + /** + * Whether published file messages should be stored in the channel's history. + * + * **Note:** If `storeInHistory` not specified, then the history configuration on the key is + * used. + * + * @default `true` + */ + storeInHistory?: boolean; + /** + * How long the message should be stored in the channel's history. + * + * **Note:** If not specified, defaults to the key set's retention value. + * + * @default `0` + */ + ttl?: number; + /** + * Metadata, which should be associated with published file. + * + * Associated metadata can be utilized by message filtering feature. + */ + meta?: Payload; +}; +/** + * Publish File Message request response. + */ +export type PublishFileMessageResponse = { + /** + * High-precision time when published file message has been received by the PubNub service. + */ + timetoken: string; +}; +/** + * Download File request parameters. + */ +export type DownloadFileParameters = FileUrlParameters & { + /** + * Custom file and message encryption key. + * + * @deprecated Use {@link Configuration#cryptoModule|cryptoModule} configured for PubNub client + * instance or encrypt file prior {@link PubNub#sendFile|sendFile} method call. + */ + cipherKey?: string; +}; +/** + * Generate File download Url request parameters. + */ +export type FileUrlParameters = { + /** + * Name of channel where file has been sent. + */ + channel: string; + /** + * Unique file identifier. + * + * Unique file identifier and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Important:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; +}; +/** + * Generate File Download Url response. + */ +export type FileUrlResponse = string; +/** + * Delete File request parameters. + */ +export type DeleteFileParameters = { + /** + * Name of channel where file has been sent. + */ + channel: string; + /** + * Unique file identifier. + * + * Unique file identifier and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Important:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; +}; +/** + * Delete File request response. + */ +export type DeleteFileResponse = { + /** + * Delete File request processing status code. + */ + status: number; +}; diff --git a/lib/types/core/types/api/history.d.ts b/lib/types/core/types/api/history.d.ts new file mode 100644 index 000000000..9ae00f1c2 --- /dev/null +++ b/lib/types/core/types/api/history.d.ts @@ -0,0 +1,395 @@ +import { Payload } from './index'; +/** + * Get history request parameters. + */ +export type GetHistoryParameters = { + /** + * Channel to return history messages from. + */ + channel: string; + /** + * Specifies the number of historical messages to return. + * + * **Note:** Maximum `100` messages can be returned in single response. + * + * @default `100` + */ + count?: number; + /** + * Whether message `meta` information should be fetched or not. + * + * @default `false` + */ + includeMeta?: boolean; + /** + * Timetoken delimiting the `start` of `time` slice (exclusive) to pull messages from. + */ + start?: string; + /** + * Timetoken delimiting the `end` of `time` slice (inclusive) to pull messages from. + */ + end?: string; + /** + * Whether timeline should traverse in reverse starting with the oldest message first or not. + * + * If both `start` and `end` arguments are provided, `reverse` is ignored and messages are + * returned starting with the newest message. + */ + reverse?: boolean; + /** + * Whether message timetokens should be stringified or not. + * + * @default `false` + */ + stringifiedTimeToken?: boolean; +}; +/** + * Get history response. + */ +export type GetHistoryResponse = { + /** + * List of previously published messages. + */ + messages: { + /** + * Message payload (decrypted). + */ + entry: Payload; + /** + * When message has been received by PubNub service. + */ + timetoken: string | number; + /** + * Additional data which has been published along with message to be used with real-time + * events filter expression. + */ + meta?: Payload; + /** + * Message decryption error (if attempt has been done). + */ + error?: string; + }[]; + /** + * Received messages timeline start. + */ + startTimeToken: string | number; + /** + * Received messages timeline end. + */ + endTimeToken: string | number; +}; +/** + * PubNub-defined message type. + * + * Types of messages which can be retrieved with fetch messages REST API. + */ +export declare enum PubNubMessageType { + /** + * Regular message. + */ + Message = -1, + /** + * File message. + */ + Files = 4 +} +/** + * Per-message actions information. + */ +export type Actions = { + /** + * Message action type. + */ + [t: string]: { + /** + * Message action value. + */ + [v: string]: { + /** + * Unique identifier of the user which reacted on message. + */ + uuid: string; + /** + * High-precision PubNub timetoken with time when {@link uuid} reacted on message. + */ + actionTimetoken: string; + }; + }; +}; +/** + * Additional message actions fetch information. + */ +export type MoreActions = { + /** + * Prepared fetch messages with actions REST API URL. + */ + url: string; + /** + * Next page time offset. + */ + start: string; + /** + * Number of messages to retrieve with next page. + */ + max: number; +}; +/** + * Common content of the fetched message. + */ +type BaseFetchedMessage = { + /** + * Name of channel for which message has been retrieved. + */ + channel: string; + /** + * When message has been received by PubNub service. + */ + timetoken: string | number; + /** + * Message publisher unique identifier. + */ + uuid?: string; + /** + * Additional data which has been published along with message to be used with real-time + * events filter expression. + */ + meta?: Payload; + /** + * Message decryption error (if attempt has been done). + */ + error?: string; +}; +/** + * Regular message published to the channel. + */ +export type RegularMessage = BaseFetchedMessage & { + /** + * Message payload (decrypted). + */ + message: Payload; + /** + * PubNub-defined message type. + */ + messageType?: PubNubMessageType.Message; +}; +/** + * File message published to the channel. + */ +export type FileMessage = BaseFetchedMessage & { + /** + * Message payload (decrypted). + */ + message: { + /** + * File annotation message. + */ + message?: Payload; + /** + * File information. + */ + file: { + /** + * Unique file identifier. + */ + id: string; + /** + * Name with which file has been stored. + */ + name: string; + /** + * File's content mime-type. + */ + 'mime-type': string; + /** + * Stored file size. + */ + size: number; + /** + * Pre-computed file download Url. + */ + url: string; + }; + }; + /** + * PubNub-defined message type. + */ + messageType?: PubNubMessageType.Files; +}; +/** + * Fetched message entry in channel messages list. + */ +export type FetchedMessage = RegularMessage | FileMessage; +/** + * Fetched with actions message entry in channel messages list. + */ +export type FetchedMessageWithActions = FetchedMessage & { + /** + * List of message reactions. + */ + actions?: Actions; + /** + * List of message reactions. + * + * @deprecated Use {@link actions} field instead. + */ + data?: Actions; +}; +/** + * Fetch messages request parameters. + */ +export type FetchMessagesParameters = { + /** + * Specifies channels to return history messages from. + * + * **Note:** Maximum of `500` channels are allowed. + */ + channels: string[]; + /** + * Specifies the number of historical messages to return per channel. + * + * **Note:** Default is `100` per single channel and `25` per multiple channels or per + * single channel if {@link includeMessageActions} is used. + * + * @default `100` or `25` + */ + count?: number; + /** + * Whether message type should be returned with each history message or not. + * + * @default `true` + */ + includeMessageType?: boolean; + /** + * Whether publisher `uuid` should be returned with each history message or not. + * + * @default `true` + */ + includeUUID?: boolean; + /** + * Whether publisher `uuid` should be returned with each history message or not. + * + * @deprecated Use {@link includeUUID} property instead. + */ + includeUuid?: boolean; + /** + * Whether message `meta` information should be fetched or not. + * + * @default `false` + */ + includeMeta?: boolean; + /** + * Whether message-added message actions should be fetched or not. + * + * If used, the limit of messages retrieved will be `25` per single channel. + * + * Each message can have a maximum of `25000` actions attached to it. Consider the example of + * querying for 10 messages. The first five messages have 5000 actions attached to each of + * them. The API will return the first 5 messages and all their 25000 actions. The response + * will also include a `more` link to get the remaining 5 messages. + * + * **Important:** Truncation will happen if the number of actions on the messages returned + * is > 25000. + * + * @default `false` + * + * @throws Exception if API is called with more than one channel. + */ + includeMessageActions?: boolean; + /** + * Timetoken delimiting the `start` of `time` slice (exclusive) to pull messages from. + */ + start?: string; + /** + * Timetoken delimiting the `end` of `time` slice (inclusive) to pull messages from. + */ + end?: string; + /** + * Whether message timetokens should be stringified or not. + * + * @default `false` + */ + stringifiedTimeToken?: boolean; +}; +/** + * Fetch messages response. + */ +export type FetchMessagesForChannelsResponse = { + /** + * List of previously published messages per requested channel. + */ + channels: { + [p: string]: FetchedMessage[]; + }; +}; +/** + * Fetch messages with reactions response. + */ +export type FetchMessagesWithActionsResponse = { + channels: { + [p: string]: FetchedMessageWithActions[]; + }; + /** + * Additional message actions fetch information. + */ + more: MoreActions; +}; +/** + * Fetch messages response. + */ +export type FetchMessagesResponse = FetchMessagesForChannelsResponse | FetchMessagesWithActionsResponse; +/** + * Message count request parameters. + */ +export type MessageCountParameters = { + /** + * The channels to fetch the message count. + */ + channels: string[]; + /** + * List of timetokens, in order of the {@link channels} list. + * + * Specify a single timetoken to apply it to all channels. Otherwise, the list of timetokens + * must be the same length as the list of {@link channels}, or the function returns an error + * flag. + */ + channelTimetokens?: string[]; + /** + * High-precision PubNub timetoken starting from which number of messages should be counted. + * + * Same timetoken will be used to count messages for each passed {@link channels}. + * + * @deprecated Use {@link channelTimetokens} field instead. + */ + timetoken?: string; +}; +/** + * Message count response. + */ +export type MessageCountResponse = { + /** + * Map of channel names to the number of counted messages. + */ + channels: Record; +}; +/** + * Delete messages from channel parameters. + */ +export type DeleteMessagesParameters = { + /** + * Specifies channel messages to be deleted from history. + */ + channel: string; + /** + * Timetoken delimiting the start of time slice (exclusive) to delete messages from. + */ + start?: string; + /** + * Timetoken delimiting the end of time slice (inclusive) to delete messages from. + */ + end?: string; +}; +/** + * Delete messages from channel response. + */ +export type DeleteMessagesResponse = Record; +export {}; diff --git a/lib/types/core/types/api/index.d.ts b/lib/types/core/types/api/index.d.ts new file mode 100644 index 000000000..a27191168 --- /dev/null +++ b/lib/types/core/types/api/index.d.ts @@ -0,0 +1,121 @@ +import { AbstractRequest } from '../../components/request'; +import RequestOperation from '../../constants/operations'; +import StatusCategory from '../../constants/categories'; +/** + * PubNub account keyset. + */ +export type KeySet = { + /** + * Specifies the `subscribeKey` to be used for subscribing to a channel and message publishing. + */ + subscribeKey: string; + /** + * Specifies the `publishKey` to be used for publishing messages to a channel. + */ + publishKey?: string; + /** + * Specifies the `secretKey` to be used for request signatures computation. + */ + secretKey?: string; +}; +/** + * REST API request processing function. + */ +export type SendRequestFunction = (request: AbstractRequest, callback?: ResultCallback) => Promise; +/** + * Endpoint call completion block with result. + * + * **Note:** Endpoints which return consumable data use this callback. + */ +export type ResultCallback = (status: Status, response: ResponseType | null) => void; +/** + * Endpoint acknowledgment completion block. + * + * **Note:** Endpoints which return only acknowledgment or error status use this callback. + */ +export type StatusCallback = (status: Status) => void; +/** + * REST API endpoint processing status. + * + * **Note:** Used as {@link ResultCallback} and {@link StatusCallback} callbacks first argument type and + * {@link PubNubError} instance `status` field value type. + */ +export type Status = { + /** + * Whether status represent error or not. + */ + error: boolean; + /** + * API call status category. + */ + category: StatusCategory; + /** + * Type of REST API endpoint which reported status. + */ + operation?: RequestOperation; + /** + * REST API response status code. + */ + statusCode: number; + /** + * Error data provided by REST API. + */ + errorData?: Error | Payload; + /** + * Additional status information. + */ + [p: string]: Payload | Error | undefined; +}; +/** + * Real-time PubNub client status change event. + */ +export type StatusEvent = { + /** + * API call status category. + */ + category: StatusCategory; + /** + * Type of REST API endpoint which reported status. + */ + operation?: RequestOperation; + /** + * Information about error. + */ + error?: string | boolean; + /** + * List of channels for which status update announced. + */ + affectedChannels?: string[]; + /** + * List of currently subscribed channels. + * + * List of channels from which PubNub client receives real-time updates. + */ + subscribedChannels?: string[]; + /** + * List of channel groups for which status update announced. + */ + affectedChannelGroups?: string[]; + /** + * High-precision timetoken which has been used with previous subscription loop. + */ + lastTimetoken?: number | string; + /** + * High-precision timetoken which is used for current subscription loop. + */ + currentTimetoken?: number | string; +}; +/** + * {@link TransportRequest} query parameter type. + */ +export type Query = Record; +/** + * General payload type. + * + * Type should be used for: + * * generic messages and signals content, + * * published message metadata. + */ +export type Payload = string | number | boolean | { + [key: string]: Payload | null; +} | Payload[]; diff --git a/lib/types/core/types/api/message-action.d.ts b/lib/types/core/types/api/message-action.d.ts new file mode 100644 index 000000000..7ad1941a8 --- /dev/null +++ b/lib/types/core/types/api/message-action.d.ts @@ -0,0 +1,153 @@ +/** + * Message reaction object type. + */ +export type MessageAction = { + /** + * What feature this message action represents. + */ + type: string; + /** + * Value which should be stored along with message action. + */ + value: string; + /** + * Unique identifier of the user which added message action. + */ + uuid: string; + /** + * Timetoken of when message reaction has been added. + * + * **Note:** This token required when it will be required to remove raction. + */ + actionTimetoken: string; + /** + * Timetoken of message to which `action` has been added. + */ + messageTimetoken: string; +}; +/** + * More message actions fetch information. + */ +export type MoreMessageActions = { + /** + * Prepared REST API url to fetch next page with message actions. + */ + url: string; + /** + * Message action timetoken denoting the start of the range requested with next page. + * + * **Note:** Return values will be less than {@link start}. + */ + start: string; + /** + * Message action timetoken denoting the end of the range requested with next page. + * + * **Note:** Return values will be greater than or equal to {@link end}. + */ + end: string; + /** + * Number of message actions to return in next response. + */ + limit: number; +}; +/** + * Add Message Action request parameters. + */ +export type AddMessageActionParameters = { + /** + * Name of channel which stores the message for which {@link action} should be added. + */ + channel: string; + /** + * Timetoken of message for which {@link action} should be added. + */ + messageTimetoken: string; + /** + * Message `action` information. + */ + action: { + /** + * What feature this message action represents. + */ + type: string; + /** + * Value which should be stored along with message action. + */ + value: string; + }; +}; +/** + * Response with added message action object. + */ +export type AddMessageActionResponse = { + data: MessageAction; +}; +/** + * Get Message Actions request parameters. + */ +export type GetMessageActionsParameters = { + /** + * Name of channel from which list of messages `actions` should be retrieved. + */ + channel: string; + /** + * Message action timetoken denoting the start of the range requested. + * + * **Note:** Return values will be less than {@link start}. + */ + start?: string; + /** + * Message action timetoken denoting the end of the range requested. + * + * **Note:** Return values will be greater than or equal to {@link end}. + */ + end?: string; + /** + * Number of message actions to return in response. + */ + limit?: number; +}; +/** + * Response with message actions in specific `channel`. + */ +export type GetMessageActionsResponse = { + /** + * Retrieved list of message actions. + */ + data: MessageAction[]; + /** + * Received message actions time frame start. + */ + start: string | null; + /** + * Received message actions time frame end. + */ + end: string | null; + /** + * More message actions fetch information. + */ + more?: MoreMessageActions; +}; +/** + * Remove Message Action request parameters. + */ +export type RemoveMessageActionParameters = { + /** + * Name of channel which store message for which `action` should be removed. + */ + channel: string; + /** + * Timetoken of message for which `action` should be removed. + */ + messageTimetoken: string; + /** + * Action addition timetoken. + */ + actionTimetoken: string; +}; +/** + * Response with message remove result. + */ +export type RemoveMessageActionResponse = { + data: Record; +}; diff --git a/lib/types/core/types/api/presence.d.ts b/lib/types/core/types/api/presence.d.ts new file mode 100644 index 000000000..28519378d --- /dev/null +++ b/lib/types/core/types/api/presence.d.ts @@ -0,0 +1,210 @@ +import { Payload } from './index'; +/** + * Associated presence state fetch parameters. + */ +export type GetPresenceStateParameters = { + /** + * The subscriber uuid to get the current state. + * + * @default `current uuid` + */ + uuid?: string; + /** + * List of channels for which state associated with {@link uuid} should be retrieved. + * + * **Important:** Either {@link channels} or {@link channelGroups} should be provided; + */ + channels?: string[]; + /** + * List of channel groups for which state associated with {@link uuid} should be retrieved. + * + * **Important:** Either {@link channels} or {@link channelGroups} should be provided; + */ + channelGroups?: string[]; +}; +/** + * Associated presence state fetch response. + */ +export type GetPresenceStateResponse = { + /** + * Channels map to state which `uuid` has associated with them. + */ + channels: Record; +}; +/** + * Associate presence state parameters. + */ +export type SetPresenceStateParameters = { + /** + * List of channels for which state should be associated with {@link uuid}. + */ + channels?: string[]; + /** + * List of channel groups for which state should be associated with {@link uuid}. + */ + channelGroups?: string[]; + /** + * State which should be associated with `uuid` on provided list of {@link channels} and {@link channelGroups}. + */ + state: Payload; +}; +/** + * Associate presence state parameters using heartbeat. + */ +export type SetPresenceStateWithHeartbeatParameters = { + /** + * List of channels for which state should be associated with {@link uuid}. + */ + channels?: string[]; + /** + * State which should be associated with `uuid` on provided list of {@link channels}. + */ + state: Payload; + /** + * Whether `presence/heartbeat` REST API should be used to manage state or not. + * + * @default `false` + */ + withHeartbeat: boolean; +}; +/** + * Associate presence state response. + */ +export type SetPresenceStateResponse = { + /** + * State which has been associated with `uuid` on provided list of channels and groups. + */ + state: Payload; +}; +/** + * Announce heartbeat parameters. + */ +export type PresenceHeartbeatParameters = { + /** + * How long the server will consider the client alive for presence.The value is in seconds. + */ + heartbeat: number; + /** + * List of channels for which heartbeat should be announced for {@link uuid}. + */ + channels?: string[]; + /** + * List of channel groups for which heartbeat should be announced for {@link uuid}. + */ + channelGroups?: string[]; + /** + * State which should be associated with `uuid` on provided list of {@link channels} and {@link channelGroups}. + */ + state?: Payload; +}; +/** + * Announce heartbeat response. + */ +export type PresenceHeartbeatResponse = Record; +/** + * Presence leave parameters. + */ +export type PresenceLeaveParameters = { + /** + * List of channels for which `uuid` should be marked as `offline`. + */ + channels?: string[]; + /** + /** + * List of channel groups for which `uuid` should be marked as `offline`. + */ + channelGroups?: string[]; +}; +/** + * Presence leave response. + */ +export type PresenceLeaveResponse = Record; +/** + * Channel / channel group presence fetch parameters.. + */ +export type HereNowParameters = { + /** + * List of channels for which presence should be retrieved. + */ + channels?: string[]; + /** + * List of channel groups for which presence should be retrieved. + */ + channelGroups?: string[]; + /** + * Whether `uuid` information should be included in response or not. + * + * **Note:** Only occupancy information will be returned if both {@link includeUUIDs} and {@link includeState} is + * set to `false`. + * + * @default `true` + */ + includeUUIDs?: boolean; + /** + * Whether state associated with `uuid` should be included in response or not. + * + * @default `false`. + */ + includeState?: boolean; + /** + * Additional query parameters. + */ + queryParameters?: Record; +}; +/** + * `uuid` where now response. + */ +export type HereNowResponse = { + /** + * Total number of channels for which presence information received. + */ + totalChannels: number; + /** + * Total occupancy for all retrieved channels. + */ + totalOccupancy: number; + /** + * List of channels to which `uuid` currently subscribed. + */ + channels: { + [p: string]: { + /** + * List of received channel subscribers. + * + * **Note:** Field is missing if `uuid` and `state` not included. + */ + occupants: { + uuid: string; + state?: Payload | null; + }[]; + /** + * Name of channel for which presence information retrieved. + */ + name: string; + /** + * Total number of active subscribers in single channel. + */ + occupancy: number; + }; + }; +}; +/** + * `uuid` where now parameters. + */ +export type WhereNowParameters = { + /** + * The subscriber uuid to get the current state. + * + * @default `current uuid` + */ + uuid?: string; +}; +/** + * `uuid` where now response. + */ +export type WhereNowResponse = { + /** + * Channels map to state which `uuid` has associated with them. + */ + channels: string[]; +}; diff --git a/lib/types/core/types/api/push-notifications.d.ts b/lib/types/core/types/api/push-notifications.d.ts new file mode 100644 index 000000000..57ab65076 --- /dev/null +++ b/lib/types/core/types/api/push-notifications.d.ts @@ -0,0 +1,48 @@ +/** + * Type of Push Notifications gateway which should be used with Push Notifications REST API. + */ +type PushGateway = 'apns2' | 'gcm'; +/** + * Basic information required by Push Notifications REST API about device. + */ +type DevicePush = { + /** + * Device ID for which list of registered channel push notifications will be changed. + */ + device: string; + /** + * Push Notifications gateway to use. + * + * **Important:** Depends from the source of `device` token and can be `apns2` (for token + * provided during device registration using Apple's framework) or `gcm` (when used Firebase + * or similar framework to receive token). + */ + pushGateway: PushGateway; +}; +/** + * Register and unregister push notifications for device request parameters. + */ +export type ManageDeviceChannelsParameters = { + /** + * List of channels to be added or removed. + */ + channels: string[]; +} & DevicePush; +/** + * List Device Channels request parameters. + */ +export type ListDeviceChannelsParameters = DevicePush; +/** + * Response with result of the list device channels. + */ +export type ListDeviceChannelsResponse = { + /** + * List of the channels for which `device` will receive push notifications. + */ + channels: string[]; +}; +/** + * Delete Push Notification for device request parameters. + */ +export type DeleteDeviceParameters = DevicePush; +export {}; diff --git a/lib/types/core/types/api/push.d.ts b/lib/types/core/types/api/push.d.ts new file mode 100644 index 000000000..6d67ed8cf --- /dev/null +++ b/lib/types/core/types/api/push.d.ts @@ -0,0 +1,122 @@ +/** + * Common managed channels push notification parameters. + */ +type ManagedDeviceChannels = { + /** + * Channels to register or unregister with mobile push notifications. + */ + channels: string[]; + /** + * The device ID to associate with mobile push notifications. + */ + device: string; + /** + * Starting channel for pagination. + * + * **Note:** Use the last channel from the previous page request. + */ + start?: string; + /** + * Number of channels to return for pagination. + * + * **Note:** maximum of 1000 tokens at a time. + * + * @default `500` + */ + count?: number; +}; +/** + * List all FCM device push notification enabled channels parameters. + */ +type ListFCMDeviceChannelsParameters = Omit; +/** + * List all APNS device push notification enabled channels parameters. + * + * @deprecated Use `APNS2`-based endpoints. + */ +type ListAPNSDeviceChannelsParameters = Omit; +/** + * List all APNS2 device push notification enabled channels parameters. + */ +type ListAPNS2DeviceChannelsParameters = Omit; +/** + * List all device push notification enabled channels parameters. + */ +export type ListDeviceChannelsParameters = ListFCMDeviceChannelsParameters | ListAPNSDeviceChannelsParameters | ListAPNS2DeviceChannelsParameters; +/** + * List all device push notification enabled channels response. + */ +export type ListDeviceChannelsResponse = { + /** + * List of channels registered for device push notifications. + */ + channels: string[]; +}; +/** + * Manage FCM device push notification enabled channels parameters. + */ +type ManageFCMDeviceChannelsParameters = ManagedDeviceChannels & { + /** + * Push Notifications gateway type. + */ + pushGateway: 'gcm'; +}; +/** + * Manage APNS device push notification enabled channels parameters. + * + * @deprecated Use `APNS2`-based endpoints. + */ +type ManageAPNSDeviceChannelsParameters = ManagedDeviceChannels & { + /** + * Push Notifications gateway type. + */ + pushGateway: 'apns'; +}; +/** + * Manage APNS2 device push notification enabled channels parameters. + */ +type ManageAPNS2DeviceChannelsParameters = ManagedDeviceChannels & { + /** + * Push Notifications gateway type. + */ + pushGateway: 'apns2'; + /** + * Environment within which device should manage list of channels with enabled notifications. + */ + environment?: 'development' | 'production'; + /** + * Notifications topic name (usually it is bundle identifier of application for Apple platform). + */ + topic: string; +}; +/** + * Manage device push notification enabled channels parameters. + */ +export type ManageDeviceChannelsParameters = ManageFCMDeviceChannelsParameters | ManageAPNSDeviceChannelsParameters | ManageAPNS2DeviceChannelsParameters; +/** + * Manage device push notification enabled channels response. + */ +export type ManageDeviceChannelsResponse = Record; +/** + * Remove all FCM device push notification enabled channels parameters. + */ +type RemoveFCMDeviceParameters = Omit; +/** + * Manage APNS device push notification enabled channels parameters. + * + * @deprecated Use `APNS2`-based endpoints. + */ +type RemoveAPNSDeviceParameters = Omit; +/** + * Manage APNS2 device push notification enabled channels parameters. + */ +type RemoveAPNS2DeviceParameters = Omit; +/** + * Remove all device push notification enabled channels parameters. + */ +export type RemoveDeviceParameters = RemoveFCMDeviceParameters | RemoveAPNSDeviceParameters | RemoveAPNS2DeviceParameters; +/** + * Remove all device push notification enabled channels response. + */ +export type RemoveDeviceResponse = Record; +export {}; diff --git a/lib/types/core/types/api/subscription.d.ts b/lib/types/core/types/api/subscription.d.ts new file mode 100644 index 000000000..0c8e1e19e --- /dev/null +++ b/lib/types/core/types/api/subscription.d.ts @@ -0,0 +1,296 @@ +import { RequestParameters as SubscribeRequestParameters, VSPMembershipObjectData, AppContextObjectData, MessageActionData, PubNubEventType, SpaceObjectData, UserObjectData, PresenceData, FileData } from '../../endpoints/subscribe'; +import { AbortSignal } from '../../components/abort_signal'; +import { Payload } from './index'; +/** + * Time cursor. + * + * Cursor used by subscription loop to identify point in time after which updates will be + * delivered. + */ +export type SubscriptionCursor = { + /** + * PubNub high-precision timestamp. + * + * Aside of specifying exact time of receiving data / event this token used to catchup / + * follow on real-time updates. + */ + timetoken: string | number; + /** + * Data center region for which `timetoken` has been generated. + */ + region?: number; +}; +/** + * Common real-time event. + */ +type Event = { + /** + * Channel to which real-time event has been sent. + */ + channel: string; + /** + * Actual subscription at which real-time event has been received. + * + * PubNub client provide various ways to subscribe to the real-time stream: channel groups, + * wildcard subscription, and spaces. + * + * **Note:** Value will be `null` if it is the same as {@link channel}. + */ + subscription: string | null; + /** + * High-precision PubNub timetoken with time when event has been received by PubNub services. + */ + timetoken: string; +}; +/** + * Common legacy real-time event for backward compatibility. + */ +type LegacyEvent = Event & { + /** + * Channel to which real-time event has been sent. + * + * @deprecated Use {@link channel} field instead. + */ + actualChannel?: string | null; + /** + * Actual subscription at which real-time event has been received. + * + * @deprecated Use {@link subscription} field instead. + */ + subscribedChannel?: string; +}; +/** + * Presence change real-time event. + */ +export type Presence = LegacyEvent & PresenceData; +/** + * Extended presence real-time event. + * + * Type extended for listener manager support. + */ +type PresenceEvent = { + type: PubNubEventType.Presence; + data: Presence; +}; +/** + * Common published data information. + */ +type PublishedData = { + /** + * Unique identifier of the user which sent data. + */ + publisher?: string; + /** + * Additional user-provided metadata which can be used with real-time filtering expression. + */ + userMetadata?: { + [p: string]: Payload; + }; + /** + * Sent data. + */ + message: Payload; +}; +/** + * Real-time message event. + */ +export type Message = LegacyEvent & PublishedData & { + /** + * Decryption error message in case of failure. + */ + error?: string; +}; +/** + * Extended real-time message event. + * + * Type extended for listener manager support. + */ +type MessageEvent = { + type: PubNubEventType.Message; + data: Message; +}; +/** + * Real-time signal event. + */ +export type Signal = Event & PublishedData; +/** + * Extended real-time signal event. + * + * Type extended for listener manager support. + */ +type SignalEvent = { + type: PubNubEventType.Signal; + data: Signal; +}; +/** + * Message action real-time event. + */ +export type MessageAction = Event & Omit & { + /** + * Unique identifier of the user which added message reaction. + * + * @deprecated Use `data.uuid` field instead. + */ + publisher?: string; + data: MessageActionData['data'] & { + /** + * Unique identifier of the user which added message reaction. + */ + uuid: string; + }; +}; +/** + * Extended message action real-time event. + * + * Type extended for listener manager support. + */ +type MessageActionEvent = { + type: PubNubEventType.MessageAction; + data: MessageAction; +}; +/** + * App Context Object change real-time event. + */ +export type AppContextObject = Event & { + /** + * Information about App Context object for which event received. + */ + message: AppContextObjectData; +}; +/** + * `User` App Context Object change real-time event. + */ +export type UserAppContextObject = Omit & { + /** + * Space to which real-time event has been sent. + */ + spaceId: string; + /** + * Information about User Object for which event received. + */ + message: UserObjectData; +}; +/** + * `Space` App Context Object change real-time event. + */ +export type SpaceAppContextObject = Omit & { + /** + * Space to which real-time event has been sent. + */ + spaceId: string; + /** + * Information about `Space` Object for which event received. + */ + message: SpaceObjectData; +}; +/** + * VSP `Membership` App Context Object change real-time event. + */ +export type VSPMembershipAppContextObject = Omit & { + /** + * Space to which real-time event has been sent. + */ + spaceId: string; + /** + * Information about `Membership` Object for which event received. + */ + message: VSPMembershipObjectData; +}; +/** + * Extended App Context Object change real-time event. + * + * Type extended for listener manager support. + */ +type AppContextEvent = { + type: PubNubEventType.AppContext; + data: AppContextObject; +}; +/** + * File real-time event. + */ +export type File = Event & Omit & Omit & { + /** + * Message which has been associated with uploaded file. + */ + message?: Payload; + /** + * Information about uploaded file. + */ + file?: FileData['file'] & { + /** + * File download url. + */ + url: string; + }; + /** + * Decryption error message in case of failure. + */ + error?: string; +}; +/** + * Extended File real-time event. + * + * Type extended for listener manager support. + */ +type FileEvent = { + type: PubNubEventType.Files; + data: File; +}; +/** + * Cancelable subscribe request parameters. + */ +export type CancelableSubscribeParameters = Omit & { + /** + * Long-poll request termination signal. + */ + abortSignal: AbortSignal; +}; +/** + * Subscribe request parameters. + */ +export type SubscribeParameters = { + /** + * List of channels from which real-time events should be delivered. + * + * @default `,` if {@link channelGroups} is set. + */ + channels?: string[]; + /** + * List of channel groups from which real-time events should be retrieved. + */ + channelGroups?: string[]; + /** + * Next subscription loop timetoken. + */ + timetoken?: string | number; + /** + * Whether should subscribe to channels / groups presence announcements or not. + * + * @default `false` + */ + withPresence?: boolean; + /** + * Presence information which should be associated with `userId`. + * + * `state` information will be associated with `userId` on channels mentioned as keys in + * this object. + * + * @deprecated Use set state methods to specify associated user's data instead of passing to + * subscribe. + */ + state?: Record; + /** + * Whether should subscribe to channels / groups presence announcements or not. + * + * @default `false` + */ + withHeartbeats?: boolean; +}; +/** + * Service success response. + */ +export type SubscriptionResponse = { + cursor: SubscriptionCursor; + messages: (PresenceEvent | MessageEvent | SignalEvent | MessageActionEvent | AppContextEvent | FileEvent)[]; +}; +export {}; diff --git a/lib/types/core/types/file.d.ts b/lib/types/core/types/file.d.ts new file mode 100644 index 000000000..774a161da --- /dev/null +++ b/lib/types/core/types/file.d.ts @@ -0,0 +1,104 @@ +/** + * {@link PubNub} File object interface module. + */ +/** + * Base file constructor parameters. + * + * Minimum set of parameters which can be p + */ +export type PubNubBasicFileParameters = { + data: string | ArrayBuffer; + name: string; + mimeType?: string; +}; +/** + * Platform-agnostic {@link PubNub} File object. + * + * Interface describes share of {@link PubNub} File which is required by {@link PubNub} core to + * perform required actions. + */ +export interface PubNubFileInterface { + /** + * Actual file name. + */ + name: string; + /** + * File mime-type. + */ + mimeType?: string; + /** + * File content length. + */ + contentLength?: number; + /** + * Convert {@link PubNub} file object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toArrayBuffer(): Promise; + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @returns Asynchronous results of conversion to file `Uri`. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toFileUri(): Promise>; +} +/** + * {@link PubNub} File object class interface. + */ +export interface PubNubFileConstructor { + /** + * Whether {@link Blob} data supported by platform or not. + */ + supportsBlob: boolean; + /** + * Whether {@link File} data supported by platform or not. + */ + supportsFile: boolean; + /** + * Whether {@link Buffer} data supported by platform or not. + */ + supportsBuffer: boolean; + /** + * Whether {@link Stream} data supported by platform or not. + */ + supportsStream: boolean; + /** + * Whether {@link String} data supported by platform or not. + */ + supportsString: boolean; + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + supportsArrayBuffer: boolean; + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + supportsEncryptFile: boolean; + /** + * Whether `File Uri` data supported by platform or not. + */ + supportsFileUri: boolean; + /** + * {@link PubNub} File object constructor. + * + * @param file - File instantiation parameters (can be raw data or structured object). + * + * @returns Constructed platform-specific {@link PubNub} File object. + */ + create(file: ConstructorParameters): File; + /** + * {@link PubNub} File object constructor. + * + * @param file - File instantiation parameters (can be raw data or structured object). + * + * @returns Constructed platform-specific {@link PubNub} File object. + */ + new (file: ConstructorParameters): File; +} diff --git a/lib/types/core/types/transport-request.d.ts b/lib/types/core/types/transport-request.d.ts new file mode 100644 index 000000000..09ddc24f4 --- /dev/null +++ b/lib/types/core/types/transport-request.d.ts @@ -0,0 +1,97 @@ +import { PubNubFileInterface } from './file'; +import { Query } from './api'; +/** + * Enum representing possible transport methods for HTTP requests. + * + * @enum {number} + */ +export declare enum TransportMethod { + /** + * Request will be sent using `GET` method. + */ + GET = "GET", + /** + * Request will be sent using `POST` method. + */ + POST = "POST", + /** + * Request will be sent using `PATCH` method. + */ + PATCH = "PATCH", + /** + * Request will be sent using `DELETE` method. + */ + DELETE = "DELETE", + /** + * Local request. + * + * Request won't be sent to the service and probably used to compute URL. + */ + LOCAL = "LOCAL" +} +/** + * Request cancellation controller. + */ +export type CancellationController = { + /** + * Request cancellation / abort function. + */ + abort: () => void; +}; +/** + * This object represents a request to be sent to the PubNub API. + * + * This struct represents a request to be sent to the PubNub API. It is used by the transport + * provider which implements {@link Transport} interface. + * + * All fields are representing certain parts of the request that can be used to prepare one. + */ +export type TransportRequest = { + /** + * Remote host name. + */ + origin?: string; + /** + * Remote resource path. + */ + path: string; + /** + * Query parameters to be sent with the request. + */ + queryParameters?: Query; + /** + * Transport request HTTP method. + */ + method: TransportMethod; + /** + * Headers to be sent with the request. + */ + headers?: Record; + /** + * Multipart form data fields. + * + * **Important:** `Content-Type` header should be sent the {@link body} data type when + * `multipart/form-data` should request should be sent. + */ + formData?: Record[]; + /** + * Body to be sent with the request. + */ + body?: ArrayBuffer | PubNubFileInterface | string; + /** + * For how long request should wait response from the server. + * + * @default `10` seconds. + */ + timeout: number; + /** + * Whether request can be cancelled or not. + * + * @default `false`. + */ + cancellable: boolean; + /** + * Unique request identifier. + */ + identifier: string; +}; diff --git a/lib/types/core/types/transport-response.d.ts b/lib/types/core/types/transport-response.d.ts new file mode 100644 index 000000000..359aa8712 --- /dev/null +++ b/lib/types/core/types/transport-response.d.ts @@ -0,0 +1,23 @@ +/** + * Represents a transport response from a service. + */ +export type TransportResponse = { + /** + * Full remote resource URL used to retrieve response. + */ + url: string; + /** + * Service response status code. + */ + status: number; + /** + * Service response headers. + * + * **Important:** Header names are in lowercase. + */ + headers: Record; + /** + * Service response body. + */ + body?: ArrayBuffer; +}; diff --git a/lib/types/core/utils.d.ts b/lib/types/core/utils.d.ts new file mode 100644 index 000000000..8f9ab9d64 --- /dev/null +++ b/lib/types/core/utils.d.ts @@ -0,0 +1,31 @@ +import { Query } from './types/api'; +/** + * Percent-encode input string. + * + * **Note:** Encode content in accordance of the `PubNub` service requirements. + * + * @param input - Source string or number for encoding. + * + * @returns Percent-encoded string. + */ +export declare const encodeString: (input: string | number) => string; +/** + * Percent-encode list of names (channels). + * + * @param names - List of names which should be encoded. + * + * @param [defaultString] - String which should be used in case if {@link names} is empty. + * + * @returns String which contains encoded names joined by non-encoded `,`. + */ +export declare const encodeNames: (names: string[], defaultString?: string) => string; +export declare const removeSingleOccurrence: (source: string[], elementsToRemove: string[]) => string[]; +export declare const findUniqueCommonElements: (a: string[], b: string[]) => string[]; +/** + * Transform query key / value pairs to the string. + * + * @param query - Key / value pairs of the request query parameters. + * + * @returns Stringified query key / value pairs. + */ +export declare const queryStringFromObject: (query: Query) => string; diff --git a/lib/types/crypto/index.d.ts b/lib/types/crypto/index.d.ts new file mode 100644 index 000000000..e69de29bb diff --git a/lib/types/crypto/modules/NodeCryptoModule/ICryptor.d.ts b/lib/types/crypto/modules/NodeCryptoModule/ICryptor.d.ts new file mode 100644 index 000000000..30a6c7bee --- /dev/null +++ b/lib/types/crypto/modules/NodeCryptoModule/ICryptor.d.ts @@ -0,0 +1,86 @@ +/** + * Cryptor module. + */ +/// +/// +/** + * Data encrypted by {@link CryptoModule}. + */ +export type EncryptedDataType = { + /** + * Encrypted data. + */ + data: Buffer | string; + /** + * Used cryptor's metadata. + */ + metadata: Buffer | null; +}; +/** + * {@link Readable} stream encrypted by {@link CryptoModule}. + */ +export type EncryptedStream = { + /** + * Stream with encrypted content. + */ + stream: NodeJS.ReadableStream; + /** + * Length of encrypted data in {@link Readable} stream. + */ + metadataLength: number; + /** + * Used cryptor's metadata. + */ + metadata?: Buffer | undefined; +}; +/** + * Cryptor algorithm interface. + */ +export interface ICryptor { + /** + * Cryptor unique identifier. + * + * @returns Cryptor identifier. + */ + get identifier(): string; + /** + * Encrypt provided source data. + * + * @param data - Source data for encryption. + * + * @returns Encrypted data object. + * + * @throws Error if unknown data type has been passed. + */ + encrypt(data: BufferSource | string): EncryptedDataType; + /** + * Encrypt provided source {@link Readable} stream. + * + * @param stream - Stream for encryption. + * + * @returns Encrypted stream object. + * + * @throws Error if unknown data type has been passed. + */ + encryptStream(stream: NodeJS.ReadableStream): Promise; + /** + * Decrypt provided encrypted data object. + * + * @param data - Encrypted data object for decryption. + * + * @returns Decrypted data. + * + * @throws Error if unknown data type has been passed. + */ + decrypt(data: EncryptedDataType): ArrayBuffer; + /** + * Decrypt provided encrypted stream object. + * + * @param stream - Encrypted stream object for decryption. + * + * @returns Decrypted data as {@link Readable} stream. + * + * @throws Error if unknown data type has been passed. + */ + decryptStream(stream: EncryptedStream): Promise; +} diff --git a/lib/types/crypto/modules/NodeCryptoModule/ILegacyCryptor.d.ts b/lib/types/crypto/modules/NodeCryptoModule/ILegacyCryptor.d.ts new file mode 100644 index 000000000..5b3ea2f2f --- /dev/null +++ b/lib/types/crypto/modules/NodeCryptoModule/ILegacyCryptor.d.ts @@ -0,0 +1,60 @@ +/** + * Legacy cryptor module. + */ +import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; +import { PubNubFileConstructor } from '../../../core/types/file'; +import { Payload } from '../../../core/types/api'; +import { EncryptedDataType } from './ICryptor'; +/** + * Legacy cryptor algorithm interface. + */ +export interface ILegacyCryptor { + /** + * Cryptor unique identifier. + */ + get identifier(): string; + /** + * Encrypt provided source data. + * + * @param data - Source data for encryption. + * + * @returns Encrypted data object. + * + * @throws Error if unknown data type has been passed. + */ + encrypt(data: string): EncryptedDataType; + /** + * Encrypt provided source {@link PubNub} File object. + * + * @param file - Source {@link PubNub} File object for encryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Encrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + * @throws Error if cipher key not set. + */ + encryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; + /** + * Decrypt provided encrypted data object. + * + * @param data - Encrypted data object for decryption. + * + * @returns Decrypted data. + * + * @throws Error if unknown data type has been passed. + */ + decrypt(data: EncryptedDataType): Payload | null; + /** + * Decrypt provided encrypted {@link PubNub} File object. + * + * @param file - Encrypted {@link PubNub} File object for decryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + * @throws Error if cipher key not set. + */ + decryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; +} diff --git a/lib/types/crypto/modules/NodeCryptoModule/aesCbcCryptor.d.ts b/lib/types/crypto/modules/NodeCryptoModule/aesCbcCryptor.d.ts new file mode 100644 index 000000000..875bd5d8f --- /dev/null +++ b/lib/types/crypto/modules/NodeCryptoModule/aesCbcCryptor.d.ts @@ -0,0 +1,57 @@ +/** + * AES-CBC cryptor module. + */ +/// +/// +/// +import { PassThrough } from 'stream'; +import { ICryptor, EncryptedDataType, EncryptedStream } from './ICryptor'; +/** + * AES-CBC cryptor. + * + * AES-CBC cryptor with enhanced cipher strength. + */ +export default class AesCbcCryptor implements ICryptor { + /** + * Cryptor block size. + */ + static BLOCK_SIZE: number; + /** + * {@link string|String} to {@link ArrayBuffer} response decoder. + */ + static encoder: TextEncoder; + /** + * Data encryption / decryption cipher key. + */ + cipherKey: string; + constructor({ cipherKey }: { + cipherKey: string; + }); + encrypt(data: ArrayBuffer | string): EncryptedDataType; + encryptStream(stream: NodeJS.ReadableStream): Promise<{ + stream: PassThrough; + metadata: Buffer; + metadataLength: number; + }>; + decrypt(input: EncryptedDataType): ArrayBuffer; + decryptStream(stream: EncryptedStream): Promise; + get identifier(): string; + /** + * Cryptor algorithm. + * + * @returns Cryptor module algorithm. + */ + private get algo(); + /** + * Generate random initialization vector. + * + * @returns Random initialization vector. + */ + private getIv; + /** + * Convert cipher key to the {@link Buffer}. + * + * @returns SHA256 encoded cipher key {@link Buffer}. + */ + private getKey; +} diff --git a/lib/types/crypto/modules/NodeCryptoModule/legacyCryptor.d.ts b/lib/types/crypto/modules/NodeCryptoModule/legacyCryptor.d.ts new file mode 100644 index 000000000..006900d93 --- /dev/null +++ b/lib/types/crypto/modules/NodeCryptoModule/legacyCryptor.d.ts @@ -0,0 +1,33 @@ +/** + * Legacy cryptor module. + */ +import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; +import { CryptorConfiguration } from '../../../core/interfaces/crypto-module'; +import Crypto from '../../../core/components/cryptography/index'; +import { PubNubFileConstructor } from '../../../core/types/file'; +import { ILegacyCryptor } from './ILegacyCryptor'; +import { EncryptedDataType } from './ICryptor'; +import FileCryptor from '../node'; +/** + * Legacy cryptor. + */ +export default class LegacyCryptor implements ILegacyCryptor { + /** + * Legacy cryptor configuration. + */ + config: CryptorConfiguration; + /** + * Configured file cryptor. + */ + fileCryptor: FileCryptor; + /** + * Configured legacy cryptor. + */ + cryptor: Crypto; + constructor(config: CryptorConfiguration); + encrypt(data: string): EncryptedDataType; + encryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; + decrypt(encryptedData: EncryptedDataType): import("../../../core/types/api").Payload | null; + decryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; + get identifier(): string; +} diff --git a/lib/types/crypto/modules/NodeCryptoModule/nodeCryptoModule.d.ts b/lib/types/crypto/modules/NodeCryptoModule/nodeCryptoModule.d.ts new file mode 100644 index 000000000..53f627cad --- /dev/null +++ b/lib/types/crypto/modules/NodeCryptoModule/nodeCryptoModule.d.ts @@ -0,0 +1,108 @@ +/** + * Node.js crypto module. + */ +import { AbstractCryptoModule, CryptorConfiguration } from '../../../core/interfaces/crypto-module'; +import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; +import { PubNubFileConstructor } from '../../../core/types/file'; +import { ICryptor } from './ICryptor'; +import { ILegacyCryptor } from './ILegacyCryptor'; +import AesCbcCryptor from './aesCbcCryptor'; +import LegacyCryptor from './legacyCryptor'; +/** + * Re-export bundled cryptors. + */ +export { LegacyCryptor, AesCbcCryptor }; +/** + * Crypto module cryptors interface. + */ +type CryptorType = ICryptor | ILegacyCryptor; +/** + * CryptoModule for Node.js platform. + */ +export declare class CryptoModule extends AbstractCryptoModule { + /** + * {@link LegacyCryptor|Legacy} cryptor identifier. + */ + static LEGACY_IDENTIFIER: string; + static legacyCryptoModule(config: CryptorConfiguration): CryptoModule; + static aesCbcCryptoModule(config: CryptorConfiguration): CryptoModule; + /** + * Construct crypto module with `cryptor` as default for data encryption and decryption. + * + * @param defaultCryptor - Default cryptor for data encryption and decryption. + * + * @returns Crypto module with pre-configured default cryptor. + */ + static withDefaultCryptor(defaultCryptor: CryptorType): CryptoModule; + encrypt(data: ArrayBuffer | string): string | ArrayBuffer; + encryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; + decrypt(data: ArrayBuffer | string): ArrayBuffer | import("../../../core/types/api").Payload | null; + decryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; + /** + * Retrieve registered legacy cryptor. + * + * @returns Previously registered {@link ILegacyCryptor|legacy} cryptor. + * + * @throws Error if legacy cryptor not registered. + */ + private getLegacyCryptor; + /** + * Retrieve registered cryptor by its identifier. + * + * @param id - Unique cryptor identifier. + * + * @returns Registered cryptor with specified identifier. + * + * @throws Error if cryptor with specified {@link id} can't be found. + */ + private getCryptorFromId; + /** + * Retrieve cryptor by its identifier. + * + * @param header - Header with cryptor-defined data or raw cryptor identifier. + * + * @returns Cryptor which correspond to provided {@link header}. + */ + private getCryptor; + /** + * Create cryptor header data. + * + * @param encrypted - Encryption data object as source for header data. + * + * @returns Binary representation of the cryptor header data. + */ + private getHeaderData; + /** + * Merge two {@link ArrayBuffer} instances. + * + * @param ab1 - First {@link ArrayBuffer}. + * @param ab2 - Second {@link ArrayBuffer}. + * + * @returns Merged data as {@link ArrayBuffer}. + */ + private concatArrayBuffer; + /** + * {@link Readable} stream event handler. + * + * @param stream - Stream which can be used to read data for decryption. + * @param file - File object which has been created with {@link stream}. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + private onStreamReadable; + /** + * Decrypt {@link Readable} stream using legacy cryptor. + * + * @param stream - Stream which can be used to read data for decryption. + * @param file - File object which has been created with {@link stream}. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + */ + private decryptLegacyFileStream; +} diff --git a/lib/types/crypto/modules/node.d.ts b/lib/types/crypto/modules/node.d.ts new file mode 100644 index 000000000..37384f2dc --- /dev/null +++ b/lib/types/crypto/modules/node.d.ts @@ -0,0 +1,97 @@ +/** + * Legacy Node.js cryptography module. + */ +/// +/// +import { Readable, PassThrough, Transform } from 'stream'; +import { Buffer } from 'buffer'; +import PubNubFile, { PubNubFileParameters } from '../../file/modules/node'; +import { Cryptography } from '../../core/interfaces/cryptography'; +import { PubNubFileConstructor } from '../../core/types/file'; +/** + * Legacy cryptography implementation for Node.js-based {@link PubNub} client. + */ +export default class NodeCryptography implements Cryptography { + /** + * Random initialization vector size. + */ + static IV_LENGTH: number; + encrypt(key: string, input: string | ArrayBuffer | Buffer | Readable): Promise; + /** + * Encrypt provided source {@link Buffer} using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link Buffer}. + * @param buffer - Source {@link Buffer} for encryption. + * + * @returns Encrypted data as {@link Buffer} object. + */ + private encryptBuffer; + /** + * Encrypt provided source {@link Readable} stream using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link Readable} stream. + * @param stream - Source {@link Readable} stream for encryption. + * + * @returns Encrypted data as {@link Transform} object. + */ + private encryptStream; + /** + * Encrypt provided source {@link string} using specific encryption {@link key}. + * + * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link string}. + * @param text - Source {@link string} for encryption. + * + * @returns Encrypted data as byte {@link string}. + */ + private encryptString; + encryptFile(key: string, file: PubNubFile, File: PubNubFileConstructor): Promise; + decrypt(key: string, input: string | ArrayBuffer | Buffer | Readable): Promise; + /** + * Decrypt provided encrypted {@link Buffer} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link Buffer}. + * @param buffer - Encrypted {@link Buffer} for decryption. + * + * @returns Decrypted data as {@link Buffer} object. + */ + private decryptBuffer; + /** + * Decrypt provided encrypted {@link Readable} stream using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link Readable} stream. + * @param stream - Encrypted {@link Readable} stream for decryption. + * + * @returns Decrypted data as {@link Readable} object. + */ + private decryptStream; + /** + * Decrypt provided encrypted {@link string} using specific decryption {@link key}. + * + * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link string}. + * @param text - Encrypted {@link string} for decryption. + * + * @returns Decrypted data as byte {@link string}. + */ + private decryptString; + decryptFile(key: string, file: PubNubFile, File: PubNubFileConstructor): Promise; + /** + * Cryptography algorithm. + * + * @returns Cryptography module algorithm. + */ + private get algo(); + /** + * Convert cipher key to the {@link Buffer}. + * + * @param key - String cipher key. + * + * @returns SHA256 HEX encoded cipher key {@link Buffer}. + */ + private getKey; + /** + * Generate random initialization vector. + * + * @returns Random initialization vector. + */ + private getIv; +} diff --git a/lib/types/entities/Channel.d.ts b/lib/types/entities/Channel.d.ts new file mode 100644 index 000000000..fdeb23a76 --- /dev/null +++ b/lib/types/entities/Channel.d.ts @@ -0,0 +1,11 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; +import { Subscription } from './Subscription'; +export declare class Channel { + private readonly eventEmitter; + private readonly pubnub; + private readonly name; + constructor(channelName: string, eventEmitter: EventEmitter, pubnub: PubNub); + subscription(subscriptionOptions?: SubscriptionOptions): Subscription; +} diff --git a/lib/types/entities/ChannelGroup.d.ts b/lib/types/entities/ChannelGroup.d.ts new file mode 100644 index 000000000..a1c383d59 --- /dev/null +++ b/lib/types/entities/ChannelGroup.d.ts @@ -0,0 +1,11 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; +import { Subscription } from './Subscription'; +export declare class ChannelGroup { + private readonly eventEmitter; + private readonly pubnub; + private readonly name; + constructor(channelGroup: string, eventEmitter: EventEmitter, pubnub: PubNub); + subscription(subscriptionOptions?: SubscriptionOptions): Subscription; +} diff --git a/lib/types/entities/ChannelMetadata.d.ts b/lib/types/entities/ChannelMetadata.d.ts new file mode 100644 index 000000000..101562ad0 --- /dev/null +++ b/lib/types/entities/ChannelMetadata.d.ts @@ -0,0 +1,11 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; +import { Subscription } from './Subscription'; +export declare class ChannelMetadata { + private readonly id; + private readonly eventEmitter; + private readonly pubnub; + constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub); + subscription(subscriptionOptions?: SubscriptionOptions): Subscription; +} diff --git a/lib/types/entities/SubscribeCapable.d.ts b/lib/types/entities/SubscribeCapable.d.ts new file mode 100644 index 000000000..b4ca7001d --- /dev/null +++ b/lib/types/entities/SubscribeCapable.d.ts @@ -0,0 +1,25 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import { Listener } from '../core/components/listener_manager'; +import * as Subscription from '../core/types/api/subscription'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; +export declare abstract class SubscribeCapable { + protected abstract channelNames: string[]; + protected abstract groupNames: string[]; + protected abstract listener: Listener; + protected abstract eventEmitter: EventEmitter; + protected abstract pubnub: PubNub; + protected abstract options?: SubscriptionOptions; + subscribe(): void; + unsubscribe(): void; + set onMessage(onMessageListener: (messageEvent: Subscription.Message) => void); + set onPresence(onPresenceListener: (presenceEvent: Subscription.Presence) => void); + set onSignal(onSignalListener: (signalEvent: Subscription.Signal) => void); + set onObjects(onObjectsListener: (objectsEvent: Subscription.AppContextObject) => void); + set onMessageAction(messageActionEventListener: (messageActionEvent: Subscription.MessageAction) => void); + set onFile(fileEventListener: (fileEvent: Subscription.File) => void); + addListener(listener: Listener): void; + removeListener(listener: Listener): void; + get channels(): string[]; + get channelGroups(): string[]; +} diff --git a/lib/types/entities/Subscription.d.ts b/lib/types/entities/Subscription.d.ts new file mode 100644 index 000000000..ca7002a27 --- /dev/null +++ b/lib/types/entities/Subscription.d.ts @@ -0,0 +1,22 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import { Listener } from '../core/components/listener_manager'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscribeCapable } from './SubscribeCapable'; +import { SubscriptionOptions } from './commonTypes'; +import { SubscriptionSet } from './SubscriptionSet'; +export declare class Subscription extends SubscribeCapable { + protected channelNames: string[]; + protected groupNames: string[]; + protected options?: SubscriptionOptions; + protected pubnub: PubNub; + protected eventEmitter: EventEmitter; + protected listener: Listener; + constructor({ channels, channelGroups, subscriptionOptions, eventEmitter, pubnub, }: { + channels: string[]; + channelGroups: string[]; + subscriptionOptions?: SubscriptionOptions; + eventEmitter: EventEmitter; + pubnub: PubNub; + }); + addSubscription(subscription: Subscription): SubscriptionSet; +} diff --git a/lib/types/entities/SubscriptionSet.d.ts b/lib/types/entities/SubscriptionSet.d.ts new file mode 100644 index 000000000..a7e0c2465 --- /dev/null +++ b/lib/types/entities/SubscriptionSet.d.ts @@ -0,0 +1,27 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import { Listener } from '../core/components/listener_manager'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscribeCapable } from './SubscribeCapable'; +import { SubscriptionOptions } from './commonTypes'; +import { Subscription } from './Subscription'; +export declare class SubscriptionSet extends SubscribeCapable { + protected channelNames: string[]; + protected groupNames: string[]; + protected options?: SubscriptionOptions; + protected pubnub: PubNub; + protected eventEmitter: EventEmitter; + protected subscriptionList: Subscription[]; + protected listener: Listener; + constructor({ channels, channelGroups, subscriptionOptions, eventEmitter, pubnub, }: { + channels?: string[]; + channelGroups?: string[]; + subscriptionOptions?: SubscriptionOptions; + eventEmitter: EventEmitter; + pubnub: PubNub; + }); + addSubscription(subscription: Subscription): void; + removeSubscription(subscription: Subscription): void; + addSubscriptionSet(subscriptionSet: SubscriptionSet): void; + removeSubscriptionSet(subscriptionSet: SubscriptionSet): void; + get subscriptions(): Subscription[]; +} diff --git a/lib/types/entities/UserMetadata.d.ts b/lib/types/entities/UserMetadata.d.ts new file mode 100644 index 000000000..354ef437d --- /dev/null +++ b/lib/types/entities/UserMetadata.d.ts @@ -0,0 +1,11 @@ +import type { PubNubCore as PubNub } from '../core/pubnub-common'; +import EventEmitter from '../core/components/eventEmitter'; +import { SubscriptionOptions } from './commonTypes'; +import { Subscription } from './Subscription'; +export declare class UserMetadata { + private readonly id; + private readonly eventEmitter; + private readonly pubnub; + constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub); + subscription(subscriptionOptions?: SubscriptionOptions): Subscription; +} diff --git a/lib/types/entities/commonTypes.d.ts b/lib/types/entities/commonTypes.d.ts new file mode 100644 index 000000000..170abf0d4 --- /dev/null +++ b/lib/types/entities/commonTypes.d.ts @@ -0,0 +1,7 @@ +export type SubscriptionOptions = { + cursor?: { + timetoken?: string; + region?: number; + }; + receivePresenceEvents?: boolean; +}; diff --git a/lib/types/errors/pubnub-api-error.d.ts b/lib/types/errors/pubnub-api-error.d.ts new file mode 100644 index 000000000..1b75e3be8 --- /dev/null +++ b/lib/types/errors/pubnub-api-error.d.ts @@ -0,0 +1,73 @@ +/** + * REST API endpoint use error module. + */ +import { TransportResponse } from '../core/types/transport-response'; +import RequestOperation from '../core/constants/operations'; +import StatusCategory from '../core/constants/categories'; +import { Payload, Status } from '../core/types/api'; +import { PubNubError } from './pubnub-error'; +/** + * PubNub REST API call error. + */ +export declare class PubNubAPIError extends Error { + readonly category: StatusCategory; + readonly statusCode: number; + readonly errorData?: Error | Payload | undefined; + /** + * Construct API from known error object or {@link PubNub} service error response. + * + * @param errorOrResponse - `Error` or service error response object from which error information + * should be extracted. + * @param data - Preprocessed service error response. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + static create(errorOrResponse: Error | TransportResponse, data?: ArrayBuffer): PubNubAPIError; + /** + * Create API error instance from other error object. + * + * @param error - `Error` object provided by network provider (mostly) or other {@link PubNub} client components. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + private static createFromError; + /** + * Construct API from known {@link PubNub} service error response. + * + * @param response - Service error response object from which error information should be + * extracted. + * @param data - Preprocessed service error response. + * + * @returns `PubNubAPIError` object with known error category and additional information (if + * available). + */ + private static createFromServiceResponse; + /** + * Construct PubNub endpoint error. + * + * @param message - Short API call error description. + * @param category - Error category. + * @param statusCode - Response HTTP status code. + * @param errorData - Error information. + */ + constructor(message: string, category: StatusCategory, statusCode: number, errorData?: Error | Payload | undefined); + /** + * Convert API error object to API callback status object. + * + * @param operation - Request operation during which error happened. + * + * @returns Pre-formatted API callback status object. + */ + toStatus(operation: RequestOperation): Status; + /** + * Convert API error object to PubNub client error object. + * + * @param operation - Request operation during which error happened. + * @param message - Custom error message. + * + * @returns Client-facing pre-formatted endpoint call error. + */ + toPubNubError(operation: RequestOperation, message?: string): PubNubError; +} diff --git a/lib/types/errors/pubnub-error.d.ts b/lib/types/errors/pubnub-error.d.ts new file mode 100644 index 000000000..549b195f9 --- /dev/null +++ b/lib/types/errors/pubnub-error.d.ts @@ -0,0 +1,6 @@ +import { Status } from '../core/types/api'; +export declare class PubNubError extends Error { + status?: Status | undefined; + constructor(message: string, status?: Status | undefined); +} +export declare function createValidationError(message: string, statusCode?: number): Status; diff --git a/lib/types/event-engine/core/change.d.ts b/lib/types/event-engine/core/change.d.ts new file mode 100644 index 000000000..7aaf7a029 --- /dev/null +++ b/lib/types/event-engine/core/change.d.ts @@ -0,0 +1,24 @@ +import { State } from './state'; +import { EventTypeFromMap, GenericMap, InvocationTypeFromMap } from './types'; +export type EngineStarted = { + type: 'engineStarted'; + state: State; + context: any; +}; +export type EventReceived = { + type: 'eventReceived'; + event: EventTypeFromMap; +}; +export type TransitionDone = { + type: 'transitionDone'; + event: EventTypeFromMap; + fromState: State; + toState: State; + fromContext: any; + toContext: any; +}; +export type InvocationDispatched = { + type: 'invocationDispatched'; + invocation: InvocationTypeFromMap; +}; +export type Change = TransitionDone | InvocationDispatched | EngineStarted | EventReceived; diff --git a/lib/types/event-engine/core/dispatcher.d.ts b/lib/types/event-engine/core/dispatcher.d.ts new file mode 100644 index 000000000..d70bc9359 --- /dev/null +++ b/lib/types/event-engine/core/dispatcher.d.ts @@ -0,0 +1,13 @@ +import { Handler } from './handler'; +import { GenericInvocation, GenericMap, InvocationTypeFromMap } from './types'; +type HandlerCreator = (payload: Payload, dependencies: Dependencies) => Handler; +export declare class Dispatcher> { + private readonly dependencies; + constructor(dependencies: Dependencies); + private instances; + private handlers; + on(type: K, handlerCreator: HandlerCreator): void; + dispatch(invocation: Invocation): void; + dispose(): void; +} +export {}; diff --git a/lib/types/event-engine/core/engine.d.ts b/lib/types/event-engine/core/engine.d.ts new file mode 100644 index 000000000..ba108d423 --- /dev/null +++ b/lib/types/event-engine/core/engine.d.ts @@ -0,0 +1,11 @@ +import { Subject } from '../../core/components/subject'; +import { Change } from './change'; +import { State } from './state'; +import { GenericMap, Event } from './types'; +export declare class Engine extends Subject> { + describe(label: string): State; + private currentState?; + private currentContext?; + start(initialState: State, initialContext: Context): void; + transition(event: Event): void; +} diff --git a/lib/types/event-engine/core/handler.d.ts b/lib/types/event-engine/core/handler.d.ts new file mode 100644 index 000000000..c8a53c875 --- /dev/null +++ b/lib/types/event-engine/core/handler.d.ts @@ -0,0 +1,18 @@ +import { AbortSignal } from '../../core/components/abort_signal'; +export declare abstract class Handler { + protected payload: Payload; + protected readonly dependencies: Dependencies; + constructor(payload: Payload, dependencies: Dependencies); + abstract start(): void; + abstract cancel(): void; +} +type AsyncHandlerFunction = (payload: Payload, abortSignal: AbortSignal, dependencies: Dependencies) => Promise; +declare class AsyncHandler extends Handler { + private asyncFunction; + abortSignal: AbortSignal; + constructor(payload: Payload, dependencies: Dependencies, asyncFunction: AsyncHandlerFunction); + start(): void; + cancel(): void; +} +export declare const asyncHandler: (handlerFunction: AsyncHandlerFunction) => (payload: Payload, dependencies: Dependencies) => AsyncHandler; +export {}; diff --git a/lib/types/event-engine/core/index.d.ts b/lib/types/event-engine/core/index.d.ts new file mode 100644 index 000000000..b8eab6782 --- /dev/null +++ b/lib/types/event-engine/core/index.d.ts @@ -0,0 +1,4 @@ +export { Engine } from './engine'; +export { Dispatcher } from './dispatcher'; +export { MapOf, createEvent, createEffect, createManagedEffect } from './types'; +export { asyncHandler } from './handler'; diff --git a/lib/types/event-engine/core/retryPolicy.d.ts b/lib/types/event-engine/core/retryPolicy.d.ts new file mode 100644 index 000000000..5aed5de37 --- /dev/null +++ b/lib/types/event-engine/core/retryPolicy.d.ts @@ -0,0 +1,58 @@ +import { PubNubError } from '../../errors/pubnub-error'; +export declare class RetryPolicy { + static LinearRetryPolicy(configuration: LinearRetryPolicyConfiguration): RequestRetryPolicy & LinearRetryPolicyConfiguration; + static ExponentialRetryPolicy(configuration: ExponentialRetryPolicyConfiguration): RequestRetryPolicy & ExponentialRetryPolicyConfiguration; +} +export type RequestRetryPolicy = { + /** + * Check whether failed request can be retried. + * + * @param reason - Request processing failure reason. + * @param attempt - Number of consequent failure. + * + * @returns `true` if another request retry attempt can be done. + */ + shouldRetry(reason: PubNubError & { + retryAfter?: number; + }, attempt: number): boolean; + /** + * Computed delay for next request retry attempt. + * + * @param attempt - Number of consequent failure. + * @param reason - Request processing failure reason. + * + * @returns Delay before next request retry attempt in milliseconds. + */ + getDelay(attempt: number, reason: PubNubError & { + retryAfter?: number; + }): number; + /** + * Identify reason why another retry attempt can't be made. + * + * @param reason - Request processing failure reason. + * @param attempt - Number of consequent failure. + * + * @returns Give up reason. + */ + getGiveupReason(reason: PubNubError & { + retryAfter?: number; + }, attempt: number): string; + /** + * Validate retry policy parameters. + * + * @throws Error if `minimum` delay is smaller than 2 seconds for `exponential` retry policy. + * @throws Error if `maximum` delay is larger than 150 seconds for `exponential` retry policy. + * @throws Error if `maximumRetry` attempts is larger than 6 for `exponential` retry policy. + * @throws Error if `maximumRetry` attempts is larger than 10 for `linear` retry policy. + */ + validate(): void; +}; +export type LinearRetryPolicyConfiguration = { + delay: number; + maximumRetry: number; +}; +export type ExponentialRetryPolicyConfiguration = { + minimumDelay: number; + maximumDelay: number; + maximumRetry: number; +}; diff --git a/lib/types/event-engine/core/state.d.ts b/lib/types/event-engine/core/state.d.ts new file mode 100644 index 000000000..59b3bb534 --- /dev/null +++ b/lib/types/event-engine/core/state.d.ts @@ -0,0 +1,21 @@ +import { Event, EventOfType, GenericInvocation, GenericMap, InvocationTypeFromMap } from './types'; +export type TransitionFunction> = { + (context: Context, event: EventType): Transition | void; +}; +export type Transition = [ + State, + Context, + InvocationTypeFromMap[] +]; +export declare class State { + label: string; + private transitionMap; + transition(context: Context, event: EventOfType): void | Transition; + constructor(label: string); + on(eventType: K, transition: TransitionFunction>): this; + with(context: Context, effects?: InvocationTypeFromMap[]): Transition; + enterEffects: ((context: Context) => InvocationTypeFromMap)[]; + exitEffects: ((context: Context) => InvocationTypeFromMap)[]; + onEnter(effect: (context: Context) => GenericInvocation): this; + onExit(effect: (context: Context) => GenericInvocation): this; +} diff --git a/lib/types/event-engine/core/types.d.ts b/lib/types/event-engine/core/types.d.ts new file mode 100644 index 000000000..14524f0ec --- /dev/null +++ b/lib/types/event-engine/core/types.d.ts @@ -0,0 +1,45 @@ +export type Event = { + type: T; + payload: P; +}; +export type Invocation = { + type: T; + payload: P; + managed: boolean; +}; +export type GenericEvent = Event; +export type GenericInvocation = Invocation; +export type GenericMap = Record; +export type EventTypeFromMap = { + [T in keyof Map & string]: Event; +}[keyof Map & string]; +export type InvocationTypeFromMap = { + [T in keyof Map & string]: Invocation; +}[keyof Map & string]; +export type EventOfType = Event; +export type InvocationOfType = Invocation; +type EventCreator = { + (...args: S): Event; + type: K; +}; +export declare function createEvent(type: K, fn: (...args: S) => P): EventCreator; +export type MapOf { + type: string | number | symbol; + payload: any; +}> = { + [K in ReturnType['type']]: (ReturnType & { + type: K; + })['payload']; +}; +type EffectCreator = { + (...args: S): Invocation; + type: K; +}; +type ManagedEffectCreator = { + (...args: S): Invocation; + type: K; + cancel: Invocation<'CANCEL', K>; +}; +export declare function createEffect(type: K, fn: (...args: S) => P): EffectCreator; +export declare function createManagedEffect(type: K, fn: (...args: S) => P): ManagedEffectCreator; +export {}; diff --git a/lib/types/event-engine/dispatcher.d.ts b/lib/types/event-engine/dispatcher.d.ts new file mode 100644 index 000000000..b2afbeb72 --- /dev/null +++ b/lib/types/event-engine/dispatcher.d.ts @@ -0,0 +1,27 @@ +import { PrivateClientConfiguration } from '../core/interfaces/configuration'; +import * as Subscription from '../core/types/api/subscription'; +import { Dispatcher, Engine } from './core'; +import * as effects from './effects'; +import * as events from './events'; +import { Payload, StatusEvent } from '../core/types/api'; +export type Dependencies = { + handshake: (parameters: Subscription.CancelableSubscribeParameters) => Promise; + receiveMessages: (parameters: Subscription.CancelableSubscribeParameters) => Promise; + join?: (parameters: { + channels?: string[]; + groups?: string[]; + }) => void; + leave?: (parameters: { + channels?: string[]; + groups?: string[]; + }) => void; + leaveAll?: () => void; + presenceState: Record; + config: PrivateClientConfiguration; + delay: (milliseconds: number) => Promise; + emitMessages: (events: Subscription.SubscriptionResponse['messages']) => void; + emitStatus: (status: StatusEvent) => void; +}; +export declare class EventEngineDispatcher extends Dispatcher { + constructor(engine: Engine, dependencies: Dependencies); +} diff --git a/lib/types/event-engine/effects.d.ts b/lib/types/event-engine/effects.d.ts new file mode 100644 index 000000000..803ce383b --- /dev/null +++ b/lib/types/event-engine/effects.d.ts @@ -0,0 +1,77 @@ +import { MapOf } from './core'; +import { HandshakeReconnectingStateContext } from './states/handshake_reconnecting'; +import { ReceiveReconnectingStateContext } from './states/receive_reconnecting'; +import * as Subscription from '../core/types/api/subscription'; +import { StatusEvent } from '../core/types/api'; +export declare const handshake: { + (channels: string[], groups: string[]): import("./core/types").Invocation<"HANDSHAKE", { + channels: string[]; + groups: string[]; + }>; + type: "HANDSHAKE"; + cancel: import("./core/types").Invocation<"CANCEL", "HANDSHAKE">; +}; +export declare const receiveMessages: { + (channels: string[], groups: string[], cursor: Subscription.SubscriptionCursor): import("./core/types").Invocation<"RECEIVE_MESSAGES", { + channels: string[]; + groups: string[]; + cursor: Subscription.SubscriptionCursor; + }>; + type: "RECEIVE_MESSAGES"; + cancel: import("./core/types").Invocation<"CANCEL", "RECEIVE_MESSAGES">; +}; +export declare const emitMessages: { + (events: ({ + type: import("../core/endpoints/subscribe").PubNubEventType.Presence; + data: Subscription.Presence; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Message; + data: Subscription.Message; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Signal; + data: Subscription.Signal; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; + data: Subscription.MessageAction; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; + data: Subscription.AppContextObject; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Files; + data: Subscription.File; + })[]): import("./core/types").Invocation<"EMIT_MESSAGES", ({ + type: import("../core/endpoints/subscribe").PubNubEventType.Presence; + data: Subscription.Presence; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Message; + data: Subscription.Message; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Signal; + data: Subscription.Signal; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; + data: Subscription.MessageAction; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; + data: Subscription.AppContextObject; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Files; + data: Subscription.File; + })[]>; + type: "EMIT_MESSAGES"; +}; +export declare const emitStatus: { + (status: StatusEvent): import("./core/types").Invocation<"EMIT_STATUS", StatusEvent>; + type: "EMIT_STATUS"; +}; +export declare const receiveReconnect: { + (context: ReceiveReconnectingStateContext): import("./core/types").Invocation<"RECEIVE_RECONNECT", ReceiveReconnectingStateContext>; + type: "RECEIVE_RECONNECT"; + cancel: import("./core/types").Invocation<"CANCEL", "RECEIVE_RECONNECT">; +}; +export declare const handshakeReconnect: { + (context: HandshakeReconnectingStateContext): import("./core/types").Invocation<"HANDSHAKE_RECONNECT", HandshakeReconnectingStateContext>; + type: "HANDSHAKE_RECONNECT"; + cancel: import("./core/types").Invocation<"CANCEL", "HANDSHAKE_RECONNECT">; +}; +export type Effects = MapOf; diff --git a/lib/types/event-engine/events.d.ts b/lib/types/event-engine/events.d.ts new file mode 100644 index 000000000..98418cab9 --- /dev/null +++ b/lib/types/event-engine/events.d.ts @@ -0,0 +1,159 @@ +import * as Subscription from '../core/types/api/subscription'; +import { PubNubError } from '../errors/pubnub-error'; +import { MapOf } from './core'; +export declare const subscriptionChange: { + (channels: string[], groups: string[]): import("./core/types").Event<"SUBSCRIPTION_CHANGED", { + channels: string[]; + groups: string[]; + }>; + type: "SUBSCRIPTION_CHANGED"; +}; +export declare const restore: { + (channels: string[], groups: string[], timetoken: string | number, region?: number | undefined): import("./core/types").Event<"SUBSCRIPTION_RESTORED", { + channels: string[]; + groups: string[]; + cursor: { + timetoken: string | number; + region: number; + }; + }>; + type: "SUBSCRIPTION_RESTORED"; +}; +export declare const handshakeSuccess: { + (cursor: Subscription.SubscriptionCursor): import("./core/types").Event<"HANDSHAKE_SUCCESS", Subscription.SubscriptionCursor>; + type: "HANDSHAKE_SUCCESS"; +}; +export declare const handshakeFailure: { + (error: PubNubError): import("./core/types").Event<"HANDSHAKE_FAILURE", PubNubError>; + type: "HANDSHAKE_FAILURE"; +}; +export declare const handshakeReconnectSuccess: { + (cursor: Subscription.SubscriptionCursor): import("./core/types").Event<"HANDSHAKE_RECONNECT_SUCCESS", { + cursor: Subscription.SubscriptionCursor; + }>; + type: "HANDSHAKE_RECONNECT_SUCCESS"; +}; +export declare const handshakeReconnectFailure: { + (error: PubNubError): import("./core/types").Event<"HANDSHAKE_RECONNECT_FAILURE", PubNubError>; + type: "HANDSHAKE_RECONNECT_FAILURE"; +}; +export declare const handshakeReconnectGiveup: { + (error: PubNubError): import("./core/types").Event<"HANDSHAKE_RECONNECT_GIVEUP", PubNubError>; + type: "HANDSHAKE_RECONNECT_GIVEUP"; +}; +export declare const receiveSuccess: { + (cursor: Subscription.SubscriptionCursor, events: ({ + type: import("../core/endpoints/subscribe").PubNubEventType.Presence; + data: Subscription.Presence; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Message; + data: Subscription.Message; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Signal; + data: Subscription.Signal; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; + data: Subscription.MessageAction; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; + data: Subscription.AppContextObject; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Files; + data: Subscription.File; + })[]): import("./core/types").Event<"RECEIVE_SUCCESS", { + cursor: Subscription.SubscriptionCursor; + events: ({ + type: import("../core/endpoints/subscribe").PubNubEventType.Presence; + data: Subscription.Presence; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Message; + data: Subscription.Message; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Signal; + data: Subscription.Signal; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; + data: Subscription.MessageAction; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; + data: Subscription.AppContextObject; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Files; + data: Subscription.File; + })[]; + }>; + type: "RECEIVE_SUCCESS"; +}; +export declare const receiveFailure: { + (error: PubNubError): import("./core/types").Event<"RECEIVE_FAILURE", PubNubError>; + type: "RECEIVE_FAILURE"; +}; +export declare const receiveReconnectSuccess: { + (cursor: Subscription.SubscriptionCursor, events: ({ + type: import("../core/endpoints/subscribe").PubNubEventType.Presence; + data: Subscription.Presence; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Message; + data: Subscription.Message; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Signal; + data: Subscription.Signal; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; + data: Subscription.MessageAction; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; + data: Subscription.AppContextObject; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Files; + data: Subscription.File; + })[]): import("./core/types").Event<"RECEIVE_RECONNECT_SUCCESS", { + cursor: Subscription.SubscriptionCursor; + events: ({ + type: import("../core/endpoints/subscribe").PubNubEventType.Presence; + data: Subscription.Presence; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Message; + data: Subscription.Message; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Signal; + data: Subscription.Signal; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; + data: Subscription.MessageAction; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; + data: Subscription.AppContextObject; + } | { + type: import("../core/endpoints/subscribe").PubNubEventType.Files; + data: Subscription.File; + })[]; + }>; + type: "RECEIVE_RECONNECT_SUCCESS"; +}; +export declare const receiveReconnectFailure: { + (error: PubNubError): import("./core/types").Event<"RECEIVE_RECONNECT_FAILURE", PubNubError>; + type: "RECEIVE_RECONNECT_FAILURE"; +}; +export declare const receiveReconnectGiveup: { + (error: PubNubError): import("./core/types").Event<"RECEIVING_RECONNECT_GIVEUP", PubNubError>; + type: "RECEIVING_RECONNECT_GIVEUP"; +}; +export declare const disconnect: { + (): import("./core/types").Event<"DISCONNECT", {}>; + type: "DISCONNECT"; +}; +export declare const reconnect: { + (timetoken?: string | undefined, region?: number | undefined): import("./core/types").Event<"RECONNECT", { + cursor: { + timetoken: string; + region: number; + }; + }>; + type: "RECONNECT"; +}; +export declare const unsubscribeAll: { + (): import("./core/types").Event<"UNSUBSCRIBE_ALL", {}>; + type: "UNSUBSCRIBE_ALL"; +}; +export type Events = MapOf; diff --git a/lib/types/event-engine/index.d.ts b/lib/types/event-engine/index.d.ts new file mode 100644 index 000000000..2542bfa3b --- /dev/null +++ b/lib/types/event-engine/index.d.ts @@ -0,0 +1,33 @@ +import { Engine } from './core'; +import { Dependencies } from './dispatcher'; +import * as effects from './effects'; +import * as events from './events'; +export declare class EventEngine { + private engine; + private dispatcher; + private dependencies; + get _engine(): Engine; + private readonly _unsubscribeEngine; + constructor(dependencies: Dependencies); + channels: string[]; + groups: string[]; + subscribe({ channels, channelGroups, timetoken, withPresence, }: { + channels?: string[]; + channelGroups?: string[]; + timetoken?: string | number; + withPresence?: boolean; + }): void; + unsubscribe({ channels, channelGroups }: { + channels?: string[]; + channelGroups?: string[]; + }): void; + unsubscribeAll(): void; + reconnect({ timetoken, region }: { + timetoken?: string; + region?: number; + }): void; + disconnect(): void; + getSubscribedChannels(): string[]; + getSubscribedChannelGroups(): string[]; + dispose(): void; +} diff --git a/lib/types/event-engine/presence/dispatcher.d.ts b/lib/types/event-engine/presence/dispatcher.d.ts new file mode 100644 index 000000000..9fdf3de45 --- /dev/null +++ b/lib/types/event-engine/presence/dispatcher.d.ts @@ -0,0 +1,18 @@ +import { PrivateClientConfiguration } from '../../core/interfaces/configuration'; +import { Dispatcher, Engine } from '../core'; +import * as Presence from '../../core/types/api/presence'; +import { Payload, ResultCallback } from '../../core/types/api'; +import * as effects from './effects'; +import * as events from './events'; +export type Dependencies = { + heartbeat: (parameters: Presence.PresenceHeartbeatParameters, callback?: ResultCallback) => Promise; + leave: (parameters: Presence.PresenceLeaveParameters) => void; + heartbeatDelay: () => Promise; + retryDelay: (milliseconds: number) => Promise; + config: PrivateClientConfiguration; + presenceState: Record; + emitStatus: (status: any) => void; +}; +export declare class PresenceEventEngineDispatcher extends Dispatcher { + constructor(engine: Engine, dependencies: Dependencies); +} diff --git a/lib/types/event-engine/presence/effects.d.ts b/lib/types/event-engine/presence/effects.d.ts new file mode 100644 index 000000000..a905c6835 --- /dev/null +++ b/lib/types/event-engine/presence/effects.d.ts @@ -0,0 +1,31 @@ +import { MapOf } from '../core'; +import { HeartbeatReconnectingStateContext } from './states/heartbeat_reconnecting'; +export declare const heartbeat: { + (channels: string[], groups: string[]): import("../core/types").Invocation<"HEARTBEAT", { + channels: string[]; + groups: string[]; + }>; + type: "HEARTBEAT"; +}; +export declare const leave: { + (channels: string[], groups: string[]): import("../core/types").Invocation<"LEAVE", { + channels: string[]; + groups: string[]; + }>; + type: "LEAVE"; +}; +export declare const emitStatus: { + (status: any): import("../core/types").Invocation<"EMIT_STATUS", any>; + type: "EMIT_STATUS"; +}; +export declare const wait: { + (): import("../core/types").Invocation<"WAIT", {}>; + type: "WAIT"; + cancel: import("../core/types").Invocation<"CANCEL", "WAIT">; +}; +export declare const delayedHeartbeat: { + (context: HeartbeatReconnectingStateContext): import("../core/types").Invocation<"DELAYED_HEARTBEAT", HeartbeatReconnectingStateContext>; + type: "DELAYED_HEARTBEAT"; + cancel: import("../core/types").Invocation<"CANCEL", "DELAYED_HEARTBEAT">; +}; +export type Effects = MapOf; diff --git a/lib/types/event-engine/presence/events.d.ts b/lib/types/event-engine/presence/events.d.ts new file mode 100644 index 000000000..cfceec153 --- /dev/null +++ b/lib/types/event-engine/presence/events.d.ts @@ -0,0 +1,47 @@ +import { PubNubError } from '../../errors/pubnub-error'; +import { MapOf } from '../core'; +export declare const reconnect: { + (): import("../core/types").Event<"RECONNECT", {}>; + type: "RECONNECT"; +}; +export declare const disconnect: { + (): import("../core/types").Event<"DISCONNECT", {}>; + type: "DISCONNECT"; +}; +export declare const joined: { + (channels: string[], groups: string[]): import("../core/types").Event<"JOINED", { + channels: string[]; + groups: string[]; + }>; + type: "JOINED"; +}; +export declare const left: { + (channels: string[], groups: string[]): import("../core/types").Event<"LEFT", { + channels: string[]; + groups: string[]; + }>; + type: "LEFT"; +}; +export declare const leftAll: { + (): import("../core/types").Event<"LEFT_ALL", {}>; + type: "LEFT_ALL"; +}; +export declare const heartbeatSuccess: { + (statusCode: number): import("../core/types").Event<"HEARTBEAT_SUCCESS", { + statusCode: number; + }>; + type: "HEARTBEAT_SUCCESS"; +}; +export declare const heartbeatFailure: { + (error: PubNubError): import("../core/types").Event<"HEARTBEAT_FAILURE", PubNubError>; + type: "HEARTBEAT_FAILURE"; +}; +export declare const heartbeatGiveup: { + (): import("../core/types").Event<"HEARTBEAT_GIVEUP", {}>; + type: "HEARTBEAT_GIVEUP"; +}; +export declare const timesUp: { + (): import("../core/types").Event<"TIMES_UP", {}>; + type: "TIMES_UP"; +}; +export type Events = MapOf; diff --git a/lib/types/event-engine/presence/presence.d.ts b/lib/types/event-engine/presence/presence.d.ts new file mode 100644 index 000000000..42f82e750 --- /dev/null +++ b/lib/types/event-engine/presence/presence.d.ts @@ -0,0 +1,24 @@ +import { Engine } from '../core'; +import * as events from './events'; +import * as effects from './effects'; +import { Dependencies } from './dispatcher'; +export declare class PresenceEventEngine { + private dependencies; + private engine; + private dispatcher; + get _engine(): Engine; + private _unsubscribeEngine; + constructor(dependencies: Dependencies); + channels: string[]; + groups: string[]; + join({ channels, groups }: { + channels?: string[]; + groups?: string[]; + }): void; + leave({ channels, groups }: { + channels?: string[]; + groups?: string[]; + }): void; + leaveAll(): void; + dispose(): void; +} diff --git a/lib/types/event-engine/presence/states/heartbeat_cooldown.d.ts b/lib/types/event-engine/presence/states/heartbeat_cooldown.d.ts new file mode 100644 index 000000000..6b2273d2b --- /dev/null +++ b/lib/types/event-engine/presence/states/heartbeat_cooldown.d.ts @@ -0,0 +1,8 @@ +import { State } from '../../core/state'; +import { Events } from '../events'; +import { Effects } from '../effects'; +export type HeartbeatCooldownStateContext = { + channels: string[]; + groups: string[]; +}; +export declare const HeartbeatCooldownState: State; diff --git a/lib/types/event-engine/presence/states/heartbeat_failed.d.ts b/lib/types/event-engine/presence/states/heartbeat_failed.d.ts new file mode 100644 index 000000000..dce365993 --- /dev/null +++ b/lib/types/event-engine/presence/states/heartbeat_failed.d.ts @@ -0,0 +1,8 @@ +import { State } from '../../core/state'; +import { Events } from '../events'; +import { Effects } from '../effects'; +export type HeartbeatFailedStateContext = { + channels: string[]; + groups: string[]; +}; +export declare const HeartbeatFailedState: State; diff --git a/lib/types/event-engine/presence/states/heartbeat_inactive.d.ts b/lib/types/event-engine/presence/states/heartbeat_inactive.d.ts new file mode 100644 index 000000000..d39ebfb4f --- /dev/null +++ b/lib/types/event-engine/presence/states/heartbeat_inactive.d.ts @@ -0,0 +1,4 @@ +import { State } from '../../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +export declare const HeartbeatInactiveState: State; diff --git a/lib/types/event-engine/presence/states/heartbeat_reconnecting.d.ts b/lib/types/event-engine/presence/states/heartbeat_reconnecting.d.ts new file mode 100644 index 000000000..3a3044a0b --- /dev/null +++ b/lib/types/event-engine/presence/states/heartbeat_reconnecting.d.ts @@ -0,0 +1,11 @@ +import { PubNubError } from '../../../errors/pubnub-error'; +import { State } from '../../core/state'; +import { Events } from '../events'; +import { Effects } from '../effects'; +export type HeartbeatReconnectingStateContext = { + channels: string[]; + groups: string[]; + attempts: number; + reason: PubNubError; +}; +export declare const HearbeatReconnectingState: State; diff --git a/lib/types/event-engine/presence/states/heartbeat_stopped.d.ts b/lib/types/event-engine/presence/states/heartbeat_stopped.d.ts new file mode 100644 index 000000000..9df101a87 --- /dev/null +++ b/lib/types/event-engine/presence/states/heartbeat_stopped.d.ts @@ -0,0 +1,8 @@ +import { State } from '../../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +export type HeartbeatStoppedStateContext = { + channels: string[]; + groups: string[]; +}; +export declare const HeartbeatStoppedState: State; diff --git a/lib/types/event-engine/presence/states/heartbeating.d.ts b/lib/types/event-engine/presence/states/heartbeating.d.ts new file mode 100644 index 000000000..57bc59f8f --- /dev/null +++ b/lib/types/event-engine/presence/states/heartbeating.d.ts @@ -0,0 +1,8 @@ +import { State } from '../../core/state'; +import { Events } from '../events'; +import { Effects } from '../effects'; +export type HeartbeatingStateContext = { + channels: string[]; + groups: string[]; +}; +export declare const HeartbeatingState: State; diff --git a/lib/types/event-engine/states/handshake_failed.d.ts b/lib/types/event-engine/states/handshake_failed.d.ts new file mode 100644 index 000000000..be8769ab6 --- /dev/null +++ b/lib/types/event-engine/states/handshake_failed.d.ts @@ -0,0 +1,12 @@ +import { State } from '../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +import { PubNubError } from '../../errors/pubnub-error'; +import * as Subscription from '../../core/types/api/subscription'; +export type HandshakeFailedStateContext = { + channels: string[]; + groups: string[]; + cursor?: Subscription.SubscriptionCursor; + reason: PubNubError; +}; +export declare const HandshakeFailedState: State; diff --git a/lib/types/event-engine/states/handshake_reconnecting.d.ts b/lib/types/event-engine/states/handshake_reconnecting.d.ts new file mode 100644 index 000000000..ed2817320 --- /dev/null +++ b/lib/types/event-engine/states/handshake_reconnecting.d.ts @@ -0,0 +1,13 @@ +import { PubNubError } from '../../errors/pubnub-error'; +import { State } from '../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +import * as Subscription from '../../core/types/api/subscription'; +export type HandshakeReconnectingStateContext = { + channels: string[]; + groups: string[]; + cursor?: Subscription.SubscriptionCursor; + attempts: number; + reason: PubNubError; +}; +export declare const HandshakeReconnectingState: State; diff --git a/lib/types/event-engine/states/handshake_stopped.d.ts b/lib/types/event-engine/states/handshake_stopped.d.ts new file mode 100644 index 000000000..40ffa7c4c --- /dev/null +++ b/lib/types/event-engine/states/handshake_stopped.d.ts @@ -0,0 +1,11 @@ +import { State } from '../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +import * as Subscription from '../../core/types/api/subscription'; +type HandshakeStoppedStateContext = { + channels: string[]; + groups: string[]; + cursor?: Subscription.SubscriptionCursor; +}; +export declare const HandshakeStoppedState: State; +export {}; diff --git a/lib/types/event-engine/states/handshaking.d.ts b/lib/types/event-engine/states/handshaking.d.ts new file mode 100644 index 000000000..cff30ca43 --- /dev/null +++ b/lib/types/event-engine/states/handshaking.d.ts @@ -0,0 +1,10 @@ +import { State } from '../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +import * as Subscription from '../../core/types/api/subscription'; +export type HandshakingStateContext = { + channels: string[]; + groups: string[]; + cursor?: Subscription.SubscriptionCursor; +}; +export declare const HandshakingState: State; diff --git a/lib/types/event-engine/states/receive_failed.d.ts b/lib/types/event-engine/states/receive_failed.d.ts new file mode 100644 index 000000000..925a8f857 --- /dev/null +++ b/lib/types/event-engine/states/receive_failed.d.ts @@ -0,0 +1,12 @@ +import { State } from '../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +import { PubNubError } from '../../errors/pubnub-error'; +import * as Subscription from '../../core/types/api/subscription'; +export type ReceiveFailedStateContext = { + channels: string[]; + groups: string[]; + cursor: Subscription.SubscriptionCursor; + reason: PubNubError; +}; +export declare const ReceiveFailedState: State; diff --git a/lib/types/event-engine/states/receive_reconnecting.d.ts b/lib/types/event-engine/states/receive_reconnecting.d.ts new file mode 100644 index 000000000..399e76ada --- /dev/null +++ b/lib/types/event-engine/states/receive_reconnecting.d.ts @@ -0,0 +1,13 @@ +import { PubNubError } from '../../errors/pubnub-error'; +import { State } from '../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +import * as Subscription from '../../core/types/api/subscription'; +export type ReceiveReconnectingStateContext = { + channels: string[]; + groups: string[]; + cursor: Subscription.SubscriptionCursor; + attempts: number; + reason: PubNubError; +}; +export declare const ReceiveReconnectingState: State; diff --git a/lib/types/event-engine/states/receive_stopped.d.ts b/lib/types/event-engine/states/receive_stopped.d.ts new file mode 100644 index 000000000..85a3986be --- /dev/null +++ b/lib/types/event-engine/states/receive_stopped.d.ts @@ -0,0 +1,11 @@ +import { State } from '../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +import * as Subscription from '../../core/types/api/subscription'; +type ReceiveStoppedStateContext = { + channels: string[]; + groups: string[]; + cursor: Subscription.SubscriptionCursor; +}; +export declare const ReceiveStoppedState: State; +export {}; diff --git a/lib/types/event-engine/states/receiving.d.ts b/lib/types/event-engine/states/receiving.d.ts new file mode 100644 index 000000000..221353f4f --- /dev/null +++ b/lib/types/event-engine/states/receiving.d.ts @@ -0,0 +1,10 @@ +import { State } from '../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +import * as Subscription from '../../core/types/api/subscription'; +export type ReceivingStateContext = { + channels: string[]; + groups: string[]; + cursor: Subscription.SubscriptionCursor; +}; +export declare const ReceivingState: State; diff --git a/lib/types/event-engine/states/unsubscribed.d.ts b/lib/types/event-engine/states/unsubscribed.d.ts new file mode 100644 index 000000000..ad8a2f25a --- /dev/null +++ b/lib/types/event-engine/states/unsubscribed.d.ts @@ -0,0 +1,4 @@ +import { State } from '../core/state'; +import { Effects } from '../effects'; +import { Events } from '../events'; +export declare const UnsubscribedState: State; diff --git a/lib/types/file/modules/node.d.ts b/lib/types/file/modules/node.d.ts new file mode 100644 index 000000000..344f76fe5 --- /dev/null +++ b/lib/types/file/modules/node.d.ts @@ -0,0 +1,134 @@ +/** + * Node.js {@link PubNub} File object module. + */ +/// +/// +import { Readable, PassThrough } from 'stream'; +import { Buffer } from 'buffer'; +import { PubNubFileInterface } from '../../core/types/file'; +/** + * PubNub File instance creation parameters. + */ +export type PubNubFileParameters = { + /** + * Readable stream represents file object content. + */ + stream?: Readable; + /** + * Buffer or string represents file object content. + */ + data?: Buffer | ArrayBuffer | string; + /** + * String {@link PubNubFileParameters#data|data} encoding. + * + * @default `utf8` + */ + encoding?: StringEncoding; + /** + * File object name. + */ + name: string; + /** + * File object content type. + */ + mimeType?: string; +}; +/** + * Node.js implementation for {@link PubNub} File object. + * + * **Important:** Class should implement constructor and class fields from {@link PubNubFileConstructor}. + */ +export default class PubNubFile implements PubNubFileInterface { + /** + * Whether {@link Blob} data supported by platform or not. + */ + static supportsBlob: boolean; + /** + * Whether {@link File} data supported by platform or not. + */ + static supportsFile: boolean; + /** + * Whether {@link Buffer} data supported by platform or not. + */ + static supportsBuffer: boolean; + /** + * Whether {@link Stream} data supported by platform or not. + */ + static supportsStream: boolean; + /** + * Whether {@link String} data supported by platform or not. + */ + static supportsString: boolean; + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + static supportsArrayBuffer: boolean; + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + static supportsEncryptFile: boolean; + /** + * Whether `File Uri` data supported by platform or not. + */ + static supportsFileUri: boolean; + /** + * File object content source. + */ + readonly data: Readable | Buffer; + /** + * File object content length. + */ + contentLength?: number; + /** + * File object content type. + */ + mimeType: string; + /** + * File object name. + */ + name: string; + static create(file: PubNubFileParameters): PubNubFile; + constructor(file: PubNubFileParameters); + /** + * Convert {@link PubNub} File object content to {@link Buffer}. + * + * @returns Asynchronous results of conversion to the {@link Buffer}. + */ + toBuffer(): Promise; + /** + * Convert {@link PubNub} File object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + */ + toArrayBuffer(): Promise; + /** + * Convert {@link PubNub} File object content to {@link string}. + * + * @returns Asynchronous results of conversion to the {@link string}. + */ + toString(encoding?: BufferEncoding): Promise; + /** + * Convert {@link PubNub} File object content to {@link Readable} stream. + * + * @returns Asynchronous results of conversion to the {@link Readable} stream. + */ + toStream(): Promise; + /** + * Convert {@link PubNub} File object content to {@link File}. + * + * @throws Error because {@link File} not available in Node.js environment. + */ + toFile(): Promise; + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @throws Error because file `Uri` not available in Node.js environment. + */ + toFileUri(): Promise>; + /** + * Convert {@link PubNub} File object content to {@link Blob}. + * + * @throws Error because {@link Blob} not available in Node.js environment. + */ + toBlob(): Promise; +} diff --git a/lib/types/file/modules/react-native.d.ts b/lib/types/file/modules/react-native.d.ts new file mode 100644 index 000000000..51531b6ea --- /dev/null +++ b/lib/types/file/modules/react-native.d.ts @@ -0,0 +1,135 @@ +/** + * React Native {@link PubNub} File object module. + */ +import { PubNubFileInterface } from '../../core/types/file'; +/** + * File path-based file. + */ +type FileUri = { + uri: string; + name: string; + mimeType?: string; +}; +/** + * Asynchronously fetched file content. + */ +type ReadableFile = { + arrayBuffer: () => Promise; + blob: () => Promise; + text: () => Promise; +}; +/** + * PubNub File instance creation parameters. + */ +export type PubNubFileParameters = File | FileUri | ReadableFile | { + data: string | Blob | ArrayBuffer | ArrayBufferView; + name: string; + mimeType?: string; +}; +export declare class PubNubFile implements PubNubFileInterface { + /** + * Whether {@link Blob} data supported by platform or not. + */ + static supportsBlob: boolean; + /** + * Whether {@link File} data supported by platform or not. + */ + static supportsFile: boolean; + /** + * Whether {@link Buffer} data supported by platform or not. + */ + static supportsBuffer: boolean; + /** + * Whether {@link Stream} data supported by platform or not. + */ + static supportsStream: boolean; + /** + * Whether {@link String} data supported by platform or not. + */ + static supportsString: boolean; + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + static supportsArrayBuffer: boolean; + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + static supportsEncryptFile: boolean; + /** + * Whether `File Uri` data supported by platform or not. + */ + static supportsFileUri: boolean; + /** + * File object content source. + */ + readonly data: File | FileUri | ReadableFile; + /** + * File object content length. + */ + contentLength?: number; + /** + * File object content type. + */ + mimeType: string; + /** + * File object name. + */ + name: string; + static create(file: PubNubFileParameters): PubNubFile; + constructor(file: PubNubFileParameters); + /** + * Convert {@link PubNub} File object content to {@link Buffer}. + * + * @throws Error because {@link Buffer} not available in React Native environment. + */ + toBuffer(): Promise; + /** + * Convert {@link PubNub} File object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toArrayBuffer(): Promise; + /** + * Convert {@link PubNub} File object content to {@link string}. + * + * @returns Asynchronous results of conversion to the {@link string}. + */ + toString(): Promise; + /** + * Convert {@link PubNub} File object content to {@link Readable} stream. + * + * @throws Error because {@link Readable} stream not available in React Native environment. + */ + toStream(): Promise; + /** + * Convert {@link PubNub} File object content to {@link File}. + * + * @returns Asynchronous results of conversion to the {@link File}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toFile(): Promise; + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @returns Asynchronous results of conversion to file `Uri`. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toFileUri(): Promise; + /** + * Convert {@link PubNub} File object content to {@link Blob}. + * + * @returns Asynchronous results of conversion to the {@link Blob}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toBlob(): Promise; +} +export default PubNubFile; diff --git a/lib/types/models/Cursor.d.ts b/lib/types/models/Cursor.d.ts new file mode 100644 index 000000000..8ba000353 --- /dev/null +++ b/lib/types/models/Cursor.d.ts @@ -0,0 +1,4 @@ +export type Cursor = { + readonly timetoken: string; + readonly region: number; +}; diff --git a/lib/types/node/configuration.d.ts b/lib/types/node/configuration.d.ts new file mode 100644 index 000000000..1d31293bb --- /dev/null +++ b/lib/types/node/configuration.d.ts @@ -0,0 +1,54 @@ +/** + * Node.js specific {@link PubNub} client configuration module. + */ +import { UserConfiguration } from '../core/interfaces/configuration'; +import { TransportKeepAlive } from '../core/interfaces/transport'; +import { Payload } from '../core/types/api'; +import { CryptoModule } from '../core/interfaces/crypto-module'; +/** + * NodeJS platform PubNub client configuration. + */ +export type PubNubConfiguration = UserConfiguration & { + /** + * Set a custom parameters for setting your connection `keepAlive` if this is set to `true`. + */ + keepAliveSettings?: TransportKeepAlive; + /** + * The cryptography module used for encryption and decryption of messages and files. Takes the + * {@link cipherKey} and {@link useRandomIVs} parameters as arguments. + * + * For more information, refer to the + * {@link /docs/sdks/javascript/api-reference/configuration#cryptomodule|cryptoModule} section. + * + * @default `not set` + */ + cryptoModule?: CryptoModule; + /** + * If passed, will encrypt the payloads. + * + * @deprecated Pass it to {@link cryptoModule} instead. + */ + cipherKey?: string; + /** + * When `true` the initialization vector (IV) is random for all requests (not just for file + * upload). + * When `false` the IV is hard-coded for all requests except for file upload. + * + * @default `true` + * + * @deprecated Pass it to {@link cryptoModule} instead. + */ + useRandomIVs?: boolean; + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + customEncrypt?: (data: string | Payload) => string; + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + customDecrypt?: (data: string) => string; +}; diff --git a/lib/types/node/index.d.ts b/lib/types/node/index.d.ts new file mode 100644 index 000000000..71794933a --- /dev/null +++ b/lib/types/node/index.d.ts @@ -0,0 +1,38 @@ +/// +/// +import { ProxyAgentOptions } from 'proxy-agent'; +import { Readable } from 'stream'; +import { Buffer } from 'buffer'; +import { CryptoModule } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; +import PubNubFile, { PubNubFileParameters } from '../file/modules/node'; +import { PubNubConfiguration } from './configuration'; +import { PubNubFileConstructor } from '../core/types/file'; +import { PubNubCore } from '../core/pubnub-common'; +/** + * PubNub client for Node.js platform. + */ +declare class PubNub extends PubNubCore { + /** + * Data encryption / decryption module constructor. + */ + static CryptoModule: typeof CryptoModule; + /** + * PubNub File constructor. + */ + File: PubNubFileConstructor; + /** + * Actual underlying transport provider. + */ + private nodeTransport; + constructor(configuration: PubNubConfiguration); + /** + * Update request proxy configuration. + * + * @param configuration - Updated request proxy configuration. + * + * @throws An error if {@link PubNub} client already configured to use `keepAlive`. + * `keepAlive` and `proxy` can't be used simultaneously. + */ + setProxy(configuration?: ProxyAgentOptions): void; +} +export = PubNub; diff --git a/lib/types/react_native/configuration.d.ts b/lib/types/react_native/configuration.d.ts new file mode 100644 index 000000000..a17ce3370 --- /dev/null +++ b/lib/types/react_native/configuration.d.ts @@ -0,0 +1,5 @@ +import { UserConfiguration } from '../core/interfaces/configuration'; +/** + * React Native platform PubNub client configuration. + */ +export type PubNubConfiguration = UserConfiguration; diff --git a/lib/types/react_native/index.d.ts b/lib/types/react_native/index.d.ts new file mode 100644 index 000000000..3dcb30caf --- /dev/null +++ b/lib/types/react_native/index.d.ts @@ -0,0 +1,10 @@ +import 'react-native-url-polyfill/auto'; +import { PubNubFileParameters } from '../file/modules/react-native'; +import { PubNubConfiguration } from './configuration'; +import { PubNubCore } from '../core/pubnub-common'; +/** + * PubNub client for React Native platform. + */ +export default class PubNub extends PubNubCore { + constructor(configuration: PubNubConfiguration); +} diff --git a/lib/types/transport/middleware.d.ts b/lib/types/transport/middleware.d.ts new file mode 100644 index 000000000..ee25da3f9 --- /dev/null +++ b/lib/types/transport/middleware.d.ts @@ -0,0 +1,73 @@ +import { TransportRequest } from '../core/types/transport-request'; +import { PrivateClientConfiguration } from '../core/interfaces/configuration'; +import { TokenManager } from '../core/components/token_manager'; +import { Transport } from '../core/interfaces/transport'; +/** + * Transport middleware configuration options. + */ +type PubNubMiddlewareConfiguration = { + /** + * Private client configuration. + */ + clientConfiguration: PrivateClientConfiguration; + /** + * REST API endpoints access tokens manager. + */ + tokenManager: TokenManager; + /** + * HMAC-SHA256 hash generator from provided `data`. + */ + shaHMAC?: (data: string) => string; + /** + * Platform-specific transport for requests processing. + */ + transport: Transport; +}; +export declare class RequestSignature { + private publishKey; + private secretKey; + private hasher; + private static textDecoder; + constructor(publishKey: string, secretKey: string, hasher: (input: string, secret: string) => string); + /** + * Compute request signature. + * + * @param req - Request which will be used to compute signature. + * @returns {string} `v2` request signature. + */ + signature(req: TransportRequest): string; + /** + * Prepare request query parameters for signature. + * + * @param query - Key / value pair of the request query parameters. + * @private + */ + private queryParameters; +} +export declare class PubNubMiddleware implements Transport { + private configuration; + /** + * Request signature generator. + */ + signatureGenerator?: RequestSignature; + constructor(configuration: PubNubMiddlewareConfiguration); + makeSendable(req: TransportRequest): [Promise, import("../core/types/transport-request").CancellationController | undefined]; + request(req: TransportRequest): TransportRequest; + private authenticateRequest; + /** + * Compute and append request signature. + * + * @param req - Transport request with information which should be used to generate signature. + */ + private signRequest; + /** + * Compose `pnsdk` query parameter. + * + * SDK provides ability to set custom name or append vendor information to the `pnsdk` query + * parameter. + * + * @returns Finalized `pnsdk` query parameter value. + */ + private generatePNSDK; +} +export {}; diff --git a/lib/types/transport/node-transport.d.ts b/lib/types/transport/node-transport.d.ts new file mode 100644 index 000000000..1e2d7f5b9 --- /dev/null +++ b/lib/types/transport/node-transport.d.ts @@ -0,0 +1,69 @@ +import { Request } from 'node-fetch'; +import { ProxyAgentOptions } from 'proxy-agent'; +import { CancellationController, TransportRequest } from '../core/types/transport-request'; +import { Transport, TransportKeepAlive } from '../core/interfaces/transport'; +import { TransportResponse } from '../core/types/transport-response'; +/** + * Class representing a fetch-based Node.js transport provider. + */ +export declare class NodeTransport implements Transport { + private readonly keepAlive; + private readonly keepAliveSettings; + private readonly logVerbosity; + /** + * Service {@link ArrayBuffer} response decoder. + */ + protected static decoder: TextDecoder; + /** + * Request proxy configuration. + */ + private proxyConfiguration?; + private proxyAgent?; + private httpsAgent?; + private httpAgent?; + /** + * Creates a new `fetch`-based transport instance. + * + * @param keepAlive - Indicates whether keep-alive should be enabled. + * @param [keepAliveSettings] - Optional settings for keep-alive. + * @param [logVerbosity] - Whether verbose logging enabled or not. + * + * @returns Transport for performing network requests. + */ + constructor(keepAlive?: boolean, keepAliveSettings?: TransportKeepAlive, logVerbosity?: boolean); + /** + * Update request proxy configuration. + * + * @param configuration - New proxy configuration. + */ + setProxy(configuration?: ProxyAgentOptions): void; + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; + request(req: TransportRequest): TransportRequest; + /** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + */ + private requestFromTransportRequest; + /** + * Determines and returns the appropriate agent for a given transport request. + * + * If keep alive is not requested, returns undefined. + * + * @param req - The transport request object. + * + * @returns {HttpAgent | HttpsAgent | undefined} - The appropriate agent for the request, or + * undefined if keep alive or proxy not requested. + */ + private agentForTransportRequest; + /** + * Log out request processing progress and result. + * + * @param request - Platform-specific request object. + * @param [elapsed] - How many times passed since request processing started. + * @param [body] - Service response (if available). + */ + protected logRequestProcessProgress(request: Request, elapsed?: number, body?: ArrayBuffer): void; +} diff --git a/lib/types/transport/web-react-native-transport.d.ts b/lib/types/transport/web-react-native-transport.d.ts new file mode 100644 index 000000000..753788bfd --- /dev/null +++ b/lib/types/transport/web-react-native-transport.d.ts @@ -0,0 +1,36 @@ +/** + * Common browser and React Native Transport provider module. + */ +import { CancellationController, TransportRequest } from '../core/types/transport-request'; +import { TransportResponse } from '../core/types/transport-response'; +import { Transport } from '../core/interfaces/transport'; +/** + * Class representing a `fetch`-based browser and React Native transport provider. + */ +export declare class WebReactNativeTransport implements Transport { + private keepAlive; + private readonly logVerbosity; + /** + * Service {@link ArrayBuffer} response decoder. + */ + protected static decoder: TextDecoder; + constructor(keepAlive: boolean, logVerbosity: boolean); + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; + request(req: TransportRequest): TransportRequest; + /** + * Creates a Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + */ + private requestFromTransportRequest; + /** + * Log out request processing progress and result. + * + * @param request - Platform-specific + * @param [elapsed] - How many seconds passed since request processing started. + * @param [body] - Service response (if available). + */ + protected logRequestProcessProgress(request: Request, elapsed?: number, body?: ArrayBuffer): void; +} diff --git a/package-lock.json b/package-lock.json index a075d7e07..22d3060ef 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.0.0", + "version": "8.0.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.0.0", + "version": "8.0.1", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", diff --git a/package.json b/package.json index 6eeacb20e..8081417ba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.0.1", + "version": "8.1.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { @@ -40,6 +40,7 @@ "type": "git", "url": "git://github.com/pubnub/javascript.git" }, + "keywords": [ "cloud", "publish", diff --git a/rollup.config.js b/rollup.config.js index 9eeb322f3..cc481e66e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -54,7 +54,7 @@ export default [ ], }, { - input: 'src/transport/service-worker/subscription-service-worker.ts', + input: 'src/transport/subscription-worker/subscription-worker.ts', output: { file: join(dirname(browser), basename(browser, '.min.js') + '.worker.min.js'), format: 'umd', @@ -69,7 +69,7 @@ export default [ ], }, { - input: 'src/transport/service-worker/subscription-service-worker.ts', + input: 'src/transport/subscription-worker/subscription-worker.ts', output: { file: join(dirname(browser), basename(browser, '.min.js') + '.worker.js'), format: 'umd', @@ -158,7 +158,7 @@ export default [ ], }, { - input: 'src/transport/service-worker/subscription-service-worker.ts', + input: 'src/transport/subscription-worker/subscription-worker.ts', output: { file: `upload/gzip/pubnub.worker.${version}.min.js`, format: 'umd', @@ -174,7 +174,7 @@ export default [ ], }, { - input: 'src/transport/service-worker/subscription-service-worker.ts', + input: 'src/transport/subscription-worker/subscription-worker.ts', output: { file: `upload/gzip/pubnub.worker.${version}.js`, format: 'umd', @@ -189,7 +189,7 @@ export default [ ], }, { - input: 'src/transport/service-worker/subscription-service-worker.ts', + input: 'src/transport/subscription-worker/subscription-worker.ts', output: { file: `upload/normal/pubnub.worker.${version}.min.js`, format: 'umd', @@ -204,7 +204,7 @@ export default [ ], }, { - input: 'src/transport/service-worker/subscription-service-worker.ts', + input: 'src/transport/subscription-worker/subscription-worker.ts', output: { file: `upload/normal/pubnub.worker.${version}.js`, format: 'umd', diff --git a/src/cbor/common.ts b/src/cbor/common.ts index a4149ca82..26c0ba1dd 100644 --- a/src/cbor/common.ts +++ b/src/cbor/common.ts @@ -4,6 +4,8 @@ /** * CBOR data decoder. + * + * @internal */ export default class Cbor { constructor( diff --git a/src/core/components/abort_signal.ts b/src/core/components/abort_signal.ts index ac990b782..caffb93c3 100644 --- a/src/core/components/abort_signal.ts +++ b/src/core/components/abort_signal.ts @@ -10,6 +10,11 @@ export class AbortError extends Error { } } +/** + * Event Engine stored effect processing cancellation signal. + * + * @internal + */ export class AbortSignal extends Subject { private _aborted = false; diff --git a/src/core/components/base64_codec.ts b/src/core/components/base64_codec.ts index 7908d5c75..c447673b7 100644 --- a/src/core/components/base64_codec.ts +++ b/src/core/components/base64_codec.ts @@ -5,6 +5,8 @@ const BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123 * * @param paddedInput Base64 string with padding * @returns ArrayBuffer with decoded data + * + * @internal */ export function decode(paddedInput: string): ArrayBuffer { // Remove up to last two equal signs. @@ -54,6 +56,14 @@ export function decode(paddedInput: string): ArrayBuffer { return data; } +/** + * Encode `ArrayBuffer` as a Base64 encoded string. + * + * @param input ArrayBuffer with source data. + * @returns Base64 string with padding. + * + * @internal + */ export function encode(input: ArrayBuffer): string { let base64 = ''; const encodings = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index d46d2c5f1..212f4c07e 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -15,6 +15,8 @@ import { Payload } from '../types/api'; /** * Whether encryption (if set) should use random initialization vector or not. + * + * @internal */ const USE_RANDOM_INITIALIZATION_VECTOR = true; // endregion @@ -23,6 +25,8 @@ const USE_RANDOM_INITIALIZATION_VECTOR = true; * Crypto Module instance configuration function. * * Function will be used each time when `cipherKey` will be changed. + * + * @internal */ type SetupCryptoModule = (configuration: CryptorConfiguration) => CryptoModule | undefined; @@ -69,6 +73,8 @@ type PrivateConfigurationFields = { * @param setupCryptoModule - Platform-provided {@link CryptoModule} configuration block. * * @returns `PubNub` client private configuration. + * + * @internal */ export const makeConfiguration = ( base: ExtendedConfiguration & PlatformConfiguration, @@ -163,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.0.1'; + return '8.1.0'; }, getVersion(): string { return this.version; diff --git a/src/core/components/deduping_manager.js b/src/core/components/deduping_manager.js index ab8aa9607..7d1503ce8 100644 --- a/src/core/components/deduping_manager.js +++ b/src/core/components/deduping_manager.js @@ -11,6 +11,11 @@ const hashCode = (payload) => { return hash; }; +/** + * Real-time events deduplication manager. + * + * @internal + */ export default class { _config; diff --git a/src/core/components/eventEmitter.ts b/src/core/components/eventEmitter.ts index 7f10d3112..bedc98ac8 100644 --- a/src/core/components/eventEmitter.ts +++ b/src/core/components/eventEmitter.ts @@ -2,6 +2,14 @@ import { Listener, ListenerManager } from './listener_manager'; import * as Subscription from '../types/api/subscription'; import { PubNubEventType } from '../endpoints/subscribe'; +/** + * Real-time events' emitter. + * + * Emitter responsible for forwarding received real-time events to the closures which has been + * registered for specific events handling. + * + * @internal + */ export default class EventEmitter { /** * Map of channels to listener callbacks for them. diff --git a/src/core/components/listener_manager.ts b/src/core/components/listener_manager.ts index 49e4c47d5..dd8d56040 100644 --- a/src/core/components/listener_manager.ts +++ b/src/core/components/listener_manager.ts @@ -95,6 +95,8 @@ export type Listener = { /** * Real-time listeners' manager. + * + * @internal */ export class ListenerManager { /** diff --git a/src/core/components/reconnection_manager.ts b/src/core/components/reconnection_manager.ts index eac22539b..2b3c18ba3 100644 --- a/src/core/components/reconnection_manager.ts +++ b/src/core/components/reconnection_manager.ts @@ -6,6 +6,13 @@ import { PubNubCore } from '../pubnub-common'; +/** + * Network "discovery" manager. + * + * Manager perform periodic `time` API calls to identify network availability. + * + * @internal + */ export class ReconnectionManager { /** * Successful availability check callback. diff --git a/src/core/components/request.ts b/src/core/components/request.ts index c0f328c73..f39499610 100644 --- a/src/core/components/request.ts +++ b/src/core/components/request.ts @@ -8,6 +8,8 @@ import uuidGenerator from './uuid'; /** * Base REST API request class. + * + * @internal */ export abstract class AbstractRequest implements Request { /** diff --git a/src/core/components/stringify_buffer_keys.ts b/src/core/components/stringify_buffer_keys.ts index 2b9247ff1..eff039140 100644 --- a/src/core/components/stringify_buffer_keys.ts +++ b/src/core/components/stringify_buffer_keys.ts @@ -1,3 +1,12 @@ +/** + * Re-map CBOR object keys from potentially C buffer strings to actual strings. + * + * @param obj CBOR which should be remapped to stringified keys. + * + * @returns Dictionary with stringified keys. + * + * @internal + */ export function stringifyBufferKeys(obj: unknown): Record { const isObject = (value: unknown): value is Record => typeof value === 'object' && value !== null && value.constructor === Object; diff --git a/src/core/components/subject.ts b/src/core/components/subject.ts index cad6fdffd..67d53a77a 100644 --- a/src/core/components/subject.ts +++ b/src/core/components/subject.ts @@ -1,5 +1,8 @@ type Listener = (event: T) => void; +/** + * @internal + */ export class Subject { protected listeners: Set> = new Set(); diff --git a/src/core/components/subscription-manager.ts b/src/core/components/subscription-manager.ts index 3f295c200..19b74ffdc 100644 --- a/src/core/components/subscription-manager.ts +++ b/src/core/components/subscription-manager.ts @@ -18,6 +18,8 @@ import EventEmitter from './eventEmitter'; /** * Subscription loop manager. + * + * @internal */ export class SubscriptionManager { /** diff --git a/src/core/components/token_manager.ts b/src/core/components/token_manager.ts index 97c5944d3..e60cf2a3f 100644 --- a/src/core/components/token_manager.ts +++ b/src/core/components/token_manager.ts @@ -192,6 +192,8 @@ type RawToken = { * REST API access token manager. * * Manager maintains active access token and let parse it to get information about permissions. + * + * @internal */ export class TokenManager { /** diff --git a/src/core/endpoints/access_manager/audit.ts b/src/core/endpoints/access_manager/audit.ts index e9aa8b8fd..bfcea42d3 100644 --- a/src/core/endpoints/access_manager/audit.ts +++ b/src/core/endpoints/access_manager/audit.ts @@ -64,6 +64,8 @@ type ServiceResponse = { /** * Permissions audit request. + * + * @internal */ export class AuditRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/access_manager/grant.ts b/src/core/endpoints/access_manager/grant.ts index 43b98208d..bf83c69b1 100644 --- a/src/core/endpoints/access_manager/grant.ts +++ b/src/core/endpoints/access_manager/grant.ts @@ -94,6 +94,8 @@ type ServiceResponse = { /** * Grant permissions request. + * + * @internal */ export class GrantRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/access_manager/grant_token.ts b/src/core/endpoints/access_manager/grant_token.ts index cd9b898dd..5c6d5de6a 100644 --- a/src/core/endpoints/access_manager/grant_token.ts +++ b/src/core/endpoints/access_manager/grant_token.ts @@ -88,6 +88,8 @@ type ServiceResponse = { /** * Grant token permissions request. + * + * @internal */ export class GrantTokenRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/access_manager/revoke_token.ts b/src/core/endpoints/access_manager/revoke_token.ts index da4d95578..0063dab80 100644 --- a/src/core/endpoints/access_manager/revoke_token.ts +++ b/src/core/endpoints/access_manager/revoke_token.ts @@ -52,6 +52,8 @@ type ServiceResponse = { * Access token revoke request. * * Invalidate token and permissions which has been granted for it. + * + * @internal */ export class RevokeTokenRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/actions/add_message_action.ts b/src/core/endpoints/actions/add_message_action.ts index e14a4142a..6f1192b58 100644 --- a/src/core/endpoints/actions/add_message_action.ts +++ b/src/core/endpoints/actions/add_message_action.ts @@ -45,6 +45,8 @@ type ServiceResponse = { /** * Add Message Reaction request. + * + * @internal */ export class AddMessageActionRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/actions/get_message_actions.ts b/src/core/endpoints/actions/get_message_actions.ts index 60a729830..1bd8bb02b 100644 --- a/src/core/endpoints/actions/get_message_actions.ts +++ b/src/core/endpoints/actions/get_message_actions.ts @@ -49,6 +49,8 @@ type ServiceResponse = { /** * Fetch channel message actions request. + * + * @internal */ export class GetMessageActionsRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/actions/remove_message_action.ts b/src/core/endpoints/actions/remove_message_action.ts index a7b397d7c..8c2eed84e 100644 --- a/src/core/endpoints/actions/remove_message_action.ts +++ b/src/core/endpoints/actions/remove_message_action.ts @@ -45,6 +45,8 @@ type ServiceResponse = { /** * Remove specific message action request. + * + * @internal */ export class RemoveMessageAction extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/channel_groups/add_channels.ts b/src/core/endpoints/channel_groups/add_channels.ts index 326e742c9..ad5e5473d 100644 --- a/src/core/endpoints/channel_groups/add_channels.ts +++ b/src/core/endpoints/channel_groups/add_channels.ts @@ -54,6 +54,8 @@ type ServiceResponse = { /** * Add channel group channels request. + * + * @internal */ export class AddChannelGroupChannelsRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/channel_groups/delete_group.ts b/src/core/endpoints/channel_groups/delete_group.ts index e06a68c28..526e91098 100644 --- a/src/core/endpoints/channel_groups/delete_group.ts +++ b/src/core/endpoints/channel_groups/delete_group.ts @@ -54,6 +54,8 @@ type ServiceResponse = { /** * Channel group delete request. + * + * @internal */ export class DeleteChannelGroupRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/channel_groups/list_channels.ts b/src/core/endpoints/channel_groups/list_channels.ts index d5bf3b8fa..a7d66308e 100644 --- a/src/core/endpoints/channel_groups/list_channels.ts +++ b/src/core/endpoints/channel_groups/list_channels.ts @@ -69,6 +69,8 @@ type ServiceResponse = { /** * List Channel Group Channels request. + * + * @internal */ export class ListChannelGroupChannels extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/channel_groups/list_groups.ts b/src/core/endpoints/channel_groups/list_groups.ts index 2d4ef4a02..531da6f4f 100644 --- a/src/core/endpoints/channel_groups/list_groups.ts +++ b/src/core/endpoints/channel_groups/list_groups.ts @@ -68,6 +68,8 @@ type ServiceResponse = { /** * List all channel groups request. + * + * @internal */ export class ListChannelGroupsRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/channel_groups/remove_channels.ts b/src/core/endpoints/channel_groups/remove_channels.ts index 0301d36e5..d8f78d1c9 100644 --- a/src/core/endpoints/channel_groups/remove_channels.ts +++ b/src/core/endpoints/channel_groups/remove_channels.ts @@ -54,6 +54,8 @@ type ServiceResponse = { /** * Remove channel group channels request. + * + * @internal */ // prettier-ignore export class RemoveChannelGroupChannelsRequest extends AbstractRequest< diff --git a/src/core/endpoints/fetch_messages.ts b/src/core/endpoints/fetch_messages.ts index cb5927495..a8b0298b0 100644 --- a/src/core/endpoints/fetch_messages.ts +++ b/src/core/endpoints/fetch_messages.ts @@ -162,6 +162,8 @@ type ServiceResponse = { /** * Fetch messages from channels request. + * + * @internal */ export class FetchMessagesRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/file_upload/delete_file.ts b/src/core/endpoints/file_upload/delete_file.ts index 7ccacb914..fc5dcc976 100644 --- a/src/core/endpoints/file_upload/delete_file.ts +++ b/src/core/endpoints/file_upload/delete_file.ts @@ -40,6 +40,8 @@ type ServiceResponse = { /** * Delete File request. + * + * @internal */ export class DeleteFileRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/file_upload/download_file.ts b/src/core/endpoints/file_upload/download_file.ts index 6f91ec76a..9d1c9bade 100644 --- a/src/core/endpoints/file_upload/download_file.ts +++ b/src/core/endpoints/file_upload/download_file.ts @@ -45,6 +45,8 @@ type RequestParameters = FileSharing.DownloadFileParameters & { /** * Download File request. + * + * @internal */ export class DownloadFileRequest< PlatformFile extends Partial = Record, diff --git a/src/core/endpoints/file_upload/generate_upload_url.ts b/src/core/endpoints/file_upload/generate_upload_url.ts index 8f1b43b1c..264d57365 100644 --- a/src/core/endpoints/file_upload/generate_upload_url.ts +++ b/src/core/endpoints/file_upload/generate_upload_url.ts @@ -100,6 +100,8 @@ type ServiceResponse = { /** * Generate File Upload Url request. + * + * @internal */ export class GenerateFileUploadUrlRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/file_upload/get_file_url.ts b/src/core/endpoints/file_upload/get_file_url.ts index 300ed96d6..449284416 100644 --- a/src/core/endpoints/file_upload/get_file_url.ts +++ b/src/core/endpoints/file_upload/get_file_url.ts @@ -30,6 +30,8 @@ type RequestParameters = FileSharing.FileUrlParameters & { * File download Url generation request. * * Local request which generates Url to download shared file from the specific channel. + * + * @internal */ export class GetFileDownloadUrlRequest extends AbstractRequest { /** diff --git a/src/core/endpoints/file_upload/list_files.ts b/src/core/endpoints/file_upload/list_files.ts index 0d1f95304..7f899f7ea 100644 --- a/src/core/endpoints/file_upload/list_files.ts +++ b/src/core/endpoints/file_upload/list_files.ts @@ -65,6 +65,8 @@ type ServiceResponse = { /** * Files List request. + * + * @internal */ export class FilesListRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/file_upload/publish_file.ts b/src/core/endpoints/file_upload/publish_file.ts index a88fd5682..0c9af86e6 100644 --- a/src/core/endpoints/file_upload/publish_file.ts +++ b/src/core/endpoints/file_upload/publish_file.ts @@ -49,6 +49,11 @@ type RequestParameters = FileSharing.PublishFileMessageParameters & { type ServiceResponse = [0 | 1, string, string]; // endregion +/** + * Publish shared file information request. + * + * @internal + */ export class PublishFileMessageRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); diff --git a/src/core/endpoints/file_upload/send_file.ts b/src/core/endpoints/file_upload/send_file.ts index 0c50dfae6..97fad2f1c 100644 --- a/src/core/endpoints/file_upload/send_file.ts +++ b/src/core/endpoints/file_upload/send_file.ts @@ -72,6 +72,8 @@ type RequestParameters = FileSharing.SendFileParameters { /** diff --git a/src/core/endpoints/file_upload/upload-file.ts b/src/core/endpoints/file_upload/upload-file.ts index 7147e819c..e63e8c6b4 100644 --- a/src/core/endpoints/file_upload/upload-file.ts +++ b/src/core/endpoints/file_upload/upload-file.ts @@ -11,6 +11,8 @@ import { PubNubFileInterface } from '../../types/file'; /** * File Upload request. + * + * @internal */ export class UploadFileRequest extends AbstractRequest { constructor(private readonly parameters: FileSharing.UploadFileParameters) { diff --git a/src/core/endpoints/history/delete_messages.ts b/src/core/endpoints/history/delete_messages.ts index f2a4f8269..4a12022eb 100644 --- a/src/core/endpoints/history/delete_messages.ts +++ b/src/core/endpoints/history/delete_messages.ts @@ -50,6 +50,8 @@ type ServiceResponse = { /** * Delete messages from channel history. + * + * @internal */ export class DeleteMessageRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/history/get_history.ts b/src/core/endpoints/history/get_history.ts index 206a05b57..b340aba49 100644 --- a/src/core/endpoints/history/get_history.ts +++ b/src/core/endpoints/history/get_history.ts @@ -103,6 +103,8 @@ type ServiceResponse = [ /** * Get single channel messages request. + * + * @internal */ export class GetHistoryRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/history/message_counts.ts b/src/core/endpoints/history/message_counts.ts index 6672fe8e4..8413b6b3b 100644 --- a/src/core/endpoints/history/message_counts.ts +++ b/src/core/endpoints/history/message_counts.ts @@ -68,6 +68,11 @@ type ServiceResponse = { }; // endregion +/** + * Count messages request. + * + * @internal + */ export class MessageCountRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); diff --git a/src/core/endpoints/objects/channel/get.ts b/src/core/endpoints/objects/channel/get.ts index 3c1534218..6136f62c9 100644 --- a/src/core/endpoints/objects/channel/get.ts +++ b/src/core/endpoints/objects/channel/get.ts @@ -40,6 +40,8 @@ type RequestParameters = AppContext.GetChannelMetadataParameters & { /** * Get Channel Metadata request. + * + * @internal */ export class GetChannelMetadataRequest< Response extends AppContext.GetChannelMetadataResponse, diff --git a/src/core/endpoints/objects/channel/get_all.ts b/src/core/endpoints/objects/channel/get_all.ts index cd442c42f..b4f97889b 100644 --- a/src/core/endpoints/objects/channel/get_all.ts +++ b/src/core/endpoints/objects/channel/get_all.ts @@ -50,6 +50,8 @@ type RequestParameters, diff --git a/src/core/endpoints/objects/channel/remove.ts b/src/core/endpoints/objects/channel/remove.ts index 50918491d..05148fdc4 100644 --- a/src/core/endpoints/objects/channel/remove.ts +++ b/src/core/endpoints/objects/channel/remove.ts @@ -30,6 +30,8 @@ type RequestParameters = AppContext.RemoveChannelMetadataParameters & { /** * Remove Channel Metadata request. + * + * @internal */ export class RemoveChannelMetadataRequest< Response extends AppContext.RemoveChannelMetadataResponse, diff --git a/src/core/endpoints/objects/channel/set.ts b/src/core/endpoints/objects/channel/set.ts index 555604d2c..57482a05e 100644 --- a/src/core/endpoints/objects/channel/set.ts +++ b/src/core/endpoints/objects/channel/set.ts @@ -41,6 +41,8 @@ type RequestParameters = AppContext.SetChannelMetadataParameters, diff --git a/src/core/endpoints/objects/member/get.ts b/src/core/endpoints/objects/member/get.ts index 1b80c78b8..2425c258e 100644 --- a/src/core/endpoints/objects/member/get.ts +++ b/src/core/endpoints/objects/member/get.ts @@ -75,6 +75,8 @@ type RequestParameters = AppContext.GetMembersParameters & { /** * Get Channel Members request. + * + * @internal */ export class GetChannelMembersRequest< Response extends AppContext.GetMembersResponse, diff --git a/src/core/endpoints/objects/member/set.ts b/src/core/endpoints/objects/member/set.ts index c5bb2500d..f0d5b3ed7 100644 --- a/src/core/endpoints/objects/member/set.ts +++ b/src/core/endpoints/objects/member/set.ts @@ -66,6 +66,8 @@ type RequestParameters = AppContext.SetChannelMembersParameters, diff --git a/src/core/endpoints/objects/membership/get.ts b/src/core/endpoints/objects/membership/get.ts index 34e2b6dab..30048e526 100644 --- a/src/core/endpoints/objects/membership/get.ts +++ b/src/core/endpoints/objects/membership/get.ts @@ -75,6 +75,8 @@ type RequestParameters = AppContext.GetMembershipsParameters & { /** * Get UUID Memberships request. + * + * @internal */ export class GetUUIDMembershipsRequest< Response extends AppContext.GetMembershipsResponse, diff --git a/src/core/endpoints/objects/membership/set.ts b/src/core/endpoints/objects/membership/set.ts index 1633dcce1..5b1edc29e 100644 --- a/src/core/endpoints/objects/membership/set.ts +++ b/src/core/endpoints/objects/membership/set.ts @@ -66,6 +66,8 @@ type RequestParameters = AppContext.SetMembershipsParameters, diff --git a/src/core/endpoints/objects/uuid/get.ts b/src/core/endpoints/objects/uuid/get.ts index 7a93648aa..b58342797 100644 --- a/src/core/endpoints/objects/uuid/get.ts +++ b/src/core/endpoints/objects/uuid/get.ts @@ -40,6 +40,8 @@ type RequestParameters = AppContext.GetUUIDMetadataParameters & { /** * Get UUID Metadata request. + * + * @internal */ export class GetUUIDMetadataRequest< Response extends AppContext.GetUUIDMetadataResponse, diff --git a/src/core/endpoints/objects/uuid/get_all.ts b/src/core/endpoints/objects/uuid/get_all.ts index c7b5efca8..744a4d6e8 100644 --- a/src/core/endpoints/objects/uuid/get_all.ts +++ b/src/core/endpoints/objects/uuid/get_all.ts @@ -43,6 +43,11 @@ type RequestParameters, Custom extends AppContext.CustomData = AppContext.CustomData, diff --git a/src/core/endpoints/objects/uuid/remove.ts b/src/core/endpoints/objects/uuid/remove.ts index 2bc521d6f..b84707fde 100644 --- a/src/core/endpoints/objects/uuid/remove.ts +++ b/src/core/endpoints/objects/uuid/remove.ts @@ -30,6 +30,8 @@ type RequestParameters = AppContext.RemoveUUIDMetadataParameters & { /** * Remove UUID Metadata request. + * + * @internal */ export class RemoveUUIDMetadataRequest< Response extends AppContext.RemoveUUIDMetadataResponse, diff --git a/src/core/endpoints/objects/uuid/set.ts b/src/core/endpoints/objects/uuid/set.ts index 9ba8736c7..403ebd1aa 100644 --- a/src/core/endpoints/objects/uuid/set.ts +++ b/src/core/endpoints/objects/uuid/set.ts @@ -41,6 +41,8 @@ type RequestParameters = AppContext.SetUUIDMetadataParameters, diff --git a/src/core/endpoints/presence/get_state.ts b/src/core/endpoints/presence/get_state.ts index ede87639e..3a00f1893 100644 --- a/src/core/endpoints/presence/get_state.ts +++ b/src/core/endpoints/presence/get_state.ts @@ -59,6 +59,8 @@ type ServiceResponse = { /** * Get `uuid` presence state request. + * + * @internal */ export class GetPresenceStateRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/presence/heartbeat.ts b/src/core/endpoints/presence/heartbeat.ts index 80c26f1d3..71eeece41 100644 --- a/src/core/endpoints/presence/heartbeat.ts +++ b/src/core/endpoints/presence/heartbeat.ts @@ -47,6 +47,11 @@ type ServiceResponse = { }; // endregion +/** + * Announce `uuid` presence request. + * + * @internal + */ export class HeartbeatRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); diff --git a/src/core/endpoints/presence/here_now.ts b/src/core/endpoints/presence/here_now.ts index 79eaa7af3..db494f9ad 100644 --- a/src/core/endpoints/presence/here_now.ts +++ b/src/core/endpoints/presence/here_now.ts @@ -124,6 +124,11 @@ type MultipleChannelServiceResponse = BasicServiceResponse & { type ServiceResponse = SingleChannelServiceResponse | MultipleChannelServiceResponse; // endregion +/** + * Channel presence request. + * + * @internal + */ export class HereNowRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); diff --git a/src/core/endpoints/presence/leave.ts b/src/core/endpoints/presence/leave.ts index 4dfb32194..36ff29c1f 100644 --- a/src/core/endpoints/presence/leave.ts +++ b/src/core/endpoints/presence/leave.ts @@ -52,6 +52,11 @@ type ServiceResponse = { }; // endregion +/** + * Announce user leave request. + * + * @internal + */ export class PresenceLeaveRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); diff --git a/src/core/endpoints/presence/set_state.ts b/src/core/endpoints/presence/set_state.ts index 583ff2343..9e0776bef 100644 --- a/src/core/endpoints/presence/set_state.ts +++ b/src/core/endpoints/presence/set_state.ts @@ -59,6 +59,8 @@ type ServiceResponse = { /** * Set `uuid` presence state request. + * + * @internal */ export class SetPresenceStateRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/presence/where_now.ts b/src/core/endpoints/presence/where_now.ts index 379b578a3..533a3f73b 100644 --- a/src/core/endpoints/presence/where_now.ts +++ b/src/core/endpoints/presence/where_now.ts @@ -57,6 +57,11 @@ type ServiceResponse = { }; // endregion +/** + * Get `uuid` presence request. + * + * @internal + */ export class WhereNowRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); diff --git a/src/core/endpoints/publish.ts b/src/core/endpoints/publish.ts index 93f369c8b..47c9110e2 100644 --- a/src/core/endpoints/publish.ts +++ b/src/core/endpoints/publish.ts @@ -127,6 +127,8 @@ type ServiceResponse = [0 | 1, string, string]; * * Request will normalize and encrypt (if required) provided data and push it to the specified * channel. + * + * @internal */ export class PublishRequest extends AbstractRequest { /** diff --git a/src/core/endpoints/push/add_push_channels.ts b/src/core/endpoints/push/add_push_channels.ts index 8692f4b50..5265071d9 100644 --- a/src/core/endpoints/push/add_push_channels.ts +++ b/src/core/endpoints/push/add_push_channels.ts @@ -32,6 +32,8 @@ type ServiceResponse = [0 | 1, string]; /** * Register channels with device push request. + * + * @internal */ // prettier-ignore export class AddDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest< diff --git a/src/core/endpoints/push/list_push_channels.ts b/src/core/endpoints/push/list_push_channels.ts index 725bbbefc..1892463a3 100644 --- a/src/core/endpoints/push/list_push_channels.ts +++ b/src/core/endpoints/push/list_push_channels.ts @@ -32,6 +32,8 @@ type ServiceResponse = string[]; /** * List device push enabled channels request. + * + * @internal */ // prettier-ignore export class ListDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest< diff --git a/src/core/endpoints/push/push.ts b/src/core/endpoints/push/push.ts index 20e231d62..660435f30 100644 --- a/src/core/endpoints/push/push.ts +++ b/src/core/endpoints/push/push.ts @@ -47,6 +47,8 @@ type RequestParameters = (Push.ManageDeviceChannelsParameters | Push.RemoveDevic /** * Base push notification request. + * + * @internal */ export class BasePushNotificationChannelsRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { diff --git a/src/core/endpoints/push/remove_device.ts b/src/core/endpoints/push/remove_device.ts index 5fd4235f3..e0108d5fe 100644 --- a/src/core/endpoints/push/remove_device.ts +++ b/src/core/endpoints/push/remove_device.ts @@ -32,6 +32,8 @@ type ServiceResponse = [0 | 1, string]; /** * Unregister device push notifications request. + * + * @internal */ // prettier-ignore export class RemoveDevicePushNotificationRequest extends BasePushNotificationChannelsRequest< diff --git a/src/core/endpoints/push/remove_push_channels.ts b/src/core/endpoints/push/remove_push_channels.ts index 69a939045..ce4fac47e 100644 --- a/src/core/endpoints/push/remove_push_channels.ts +++ b/src/core/endpoints/push/remove_push_channels.ts @@ -32,6 +32,8 @@ type ServiceResponse = [0 | 1, string]; /** * Unregister channels from device push request. + * + * @internal */ // prettier-ignore export class RemoveDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest< diff --git a/src/core/endpoints/signal.ts b/src/core/endpoints/signal.ts index b17379d89..5d1c84d05 100644 --- a/src/core/endpoints/signal.ts +++ b/src/core/endpoints/signal.ts @@ -57,6 +57,11 @@ type RequestParameters = SignalParameters & { type ServiceResponse = [0 | 1, string, string]; // endregion +/** + * Signal data (size-limited) publish request. + * + * @internal + */ export class SignalRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); diff --git a/src/core/endpoints/subscribe.ts b/src/core/endpoints/subscribe.ts index d31302ce5..ee179ab24 100644 --- a/src/core/endpoints/subscribe.ts +++ b/src/core/endpoints/subscribe.ts @@ -32,6 +32,8 @@ const WITH_PRESENCE = false; /** * PubNub-defined event types by payload. + * + * @internal */ export enum PubNubEventType { /** @@ -191,6 +193,8 @@ type PresenceStateChangeData = { /** * Channel presence service response. + * + * @internal */ export type PresenceData = PresenceIntervalData | PresenceChangeData | PresenceStateChangeData; // endregion @@ -198,6 +202,8 @@ export type PresenceData = PresenceIntervalData | PresenceChangeData | PresenceS // region Message Actions service response /** * Message reaction change service response. + * + * @internal */ export type MessageActionData = { /** @@ -303,6 +309,8 @@ type ChannelObjectData = ObjectData< /** * `Space` object change real-time service response. + * + * @internal */ export type SpaceObjectData = ObjectData< AppContextVSPEvents, @@ -317,6 +325,8 @@ type UuidObjectData = ObjectData { constructor(protected readonly parameters: RequestParameters) { @@ -840,6 +860,8 @@ export class BaseSubscribeRequest extends AbstractRequest { constructor() { super(); diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index 4003f427b..f1a0cf3e4 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -325,6 +325,8 @@ export type UserConfiguration = { * Extended client configuration. * * Extended configuration contains unannounced configuration options. + * + * @internal */ export type ExtendedConfiguration = UserConfiguration & { /** @@ -382,6 +384,8 @@ export type ExtendedConfiguration = UserConfiguration & { * Platform-specific PubNub client configuration. * * Part of configuration which is added by platform-specific PubNub client initialization code. + * + * @internal */ export type PlatformConfiguration = { /** @@ -548,6 +552,8 @@ export interface ClientConfiguration { /** * Internal PubNub client configuration object interface. + * + * @internal */ export interface PrivateClientConfiguration extends ClientConfiguration, @@ -682,6 +688,8 @@ export interface PrivateClientConfiguration * Apply configuration default values. * * @param configuration - User-provided configuration. + * + * @internal */ export const setDefaults = (configuration: UserConfiguration): ExtendedConfiguration => { // Copy configuration. diff --git a/src/core/interfaces/request.ts b/src/core/interfaces/request.ts index 77168006f..df1e443b7 100644 --- a/src/core/interfaces/request.ts +++ b/src/core/interfaces/request.ts @@ -4,6 +4,8 @@ import RequestOperation from '../constants/operations'; /** * General REST API call request interface. + * + * @internal */ export interface Request { /** diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index bfac679c0..fbde5b550 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -150,6 +150,8 @@ export class PubNubCore< > { /** * PubNub client configuration. + * + * @internal */ protected readonly _configuration: PrivateClientConfiguration; @@ -157,71 +159,98 @@ export class PubNubCore< * Subscription loop manager. * * **Note:** Manager created when EventEngine is off. + * + * @internal */ private readonly subscriptionManager?: SubscriptionManager; /** * Transport for network requests processing. + * + * @internal */ protected readonly transport: Transport; /** * REST API endpoints access tokens manager. + * + * @internal */ private readonly tokenManager: TokenManager; /** * Legacy crypto module implementation. + * + * @internal */ private readonly cryptography?: Cryptography; /** * Legacy crypto (legacy data encryption / decryption and request signature support). + * + * @internal */ private readonly crypto?: Crypto; /** * Real-time event listeners manager. + * + * @internal */ protected readonly listenerManager: ListenerManager; /** * User's presence event engine. + * + * @internal */ private presenceEventEngine?: PresenceEventEngine; /** * Subscription event engine. + * + * @internal */ private readonly eventEngine?: EventEngine; /** * Client-managed presence information. + * + * @internal */ private readonly presenceState?: Record; /** * Real-time events emitter. + * + * @internal */ private readonly eventEmitter: EventEmitter; /** * PubNub App Context REST API entry point. + * + * @internal */ private readonly _objects: PubNubObjects; /** * PubNub Channel Group REST API entry point. */ + // @internal @ts-ignore private readonly _channelGroups: PubNubChannelGroups; /** * PubNub Push Notification REST API entry point. + * + * @internal */ private readonly _push: PubNubPushNotifications; /** - * {@link ArrayBuffer} to {@link string} decoder. + * {@link ArrayBuffer} to {@link string} decoder. + * + * @internal */ private static decoder = new TextDecoder(); diff --git a/src/core/utils.ts b/src/core/utils.ts index dc65d95b4..5cee8bf45 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -27,7 +27,7 @@ export const encodeNames = (names: string[], defaultString?: string) => { return encodedNames.length ? encodedNames.join(',') : defaultString ?? ''; }; -export const removeSingleOccurance = (source: string[], elementsToRemove: string[]) => { +export const removeSingleOccurrence = (source: string[], elementsToRemove: string[]) => { const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); return source.filter((e) => { diff --git a/src/event-engine/index.ts b/src/event-engine/index.ts index 871d78c7e..983a659c5 100644 --- a/src/event-engine/index.ts +++ b/src/event-engine/index.ts @@ -76,12 +76,12 @@ export class EventEngine { } unsubscribe({ channels = [], channelGroups = [] }: { channels?: string[]; channelGroups?: string[] }): void { - const filteredChannels = utils.removeSingleOccurance(this.channels, [ + const filteredChannels = utils.removeSingleOccurrence(this.channels, [ ...channels, ...channels.map((c) => `${c}-pnpres`), ]); - const filteredGroups = utils.removeSingleOccurance(this.groups, [ + const filteredGroups = utils.removeSingleOccurrence(this.groups, [ ...channelGroups, ...channelGroups.map((c) => `${c}-pnpres`), ]); diff --git a/src/node/configuration.ts b/src/node/configuration.ts index a3c5d2b99..38a2eabc4 100644 --- a/src/node/configuration.ts +++ b/src/node/configuration.ts @@ -7,9 +7,9 @@ import { ExtendedConfiguration, setDefaults as setBaseDefaults, } from '../core/interfaces/configuration'; -import { CryptoModule } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; import { TransportKeepAlive } from '../core/interfaces/transport'; import { Payload } from '../core/types/api'; +import { CryptoModule } from '../core/interfaces/crypto-module'; // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -83,6 +83,8 @@ export type PubNubConfiguration = UserConfiguration & { * @param configuration - User-provided configuration. * * @returns Extended {@link PubNub} client configuration object pre-filled with default values. + * + * @internal */ export const setDefaults = (configuration: PubNubConfiguration): PubNubConfiguration & ExtendedConfiguration => { return { diff --git a/src/node/index.ts b/src/node/index.ts index a3ac1273b..63f3b1d4f 100755 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -22,7 +22,7 @@ import Cbor from '../cbor/common'; /** * PubNub client for Node.js platform. */ -export = class PubNub extends PubNubCore { +class PubNub extends PubNubCore { /** * Data encryption / decryption module constructor. */ @@ -104,4 +104,6 @@ export = class PubNub extends PubNubCore { return setBaseDefaults(configuration); diff --git a/src/transport/service-worker/subscription-service-worker-middleware.ts b/src/transport/subscription-worker/subscription-worker-middleware.ts similarity index 54% rename from src/transport/service-worker/subscription-service-worker-middleware.ts rename to src/transport/subscription-worker/subscription-worker-middleware.ts index 9e5c82d06..b1a08e3ec 100644 --- a/src/transport/service-worker/subscription-service-worker-middleware.ts +++ b/src/transport/subscription-worker/subscription-worker-middleware.ts @@ -1,16 +1,16 @@ /** - * Subscription Service Worker transport middleware module. + * Subscription Worker transport middleware module. * - * Middleware optimize subscription feature requests utilizing `Subscription Service Worker` if available and not - * disabled by user. + * Middleware optimize subscription feature requests utilizing `Subscription Worker` if available and not disabled + * by user. */ import { CancellationController, TransportRequest } from '../../core/types/transport-request'; -import * as PubNubSubscriptionServiceWorker from './subscription-service-worker'; import { TransportResponse } from '../../core/types/transport-response'; -import { Transport } from '../../core/interfaces/transport'; +import * as PubNubSubscriptionWorker from './subscription-worker'; import { PubNubAPIError } from '../../errors/pubnub-api-error'; import StatusCategory from '../../core/constants/categories'; +import { Transport } from '../../core/interfaces/transport'; // -------------------------------------------------------- // ------------------------ Types ------------------------- @@ -29,9 +29,14 @@ type PubNubMiddlewareConfiguration = { subscriptionKey: string; /** - * Url of the hoster `Subscription` service worker file. + * Unique identifier of the user for which PubNub SDK client has been created. + */ + userId: string; + + /** + * Url of the hosted `Subscription` worker file. */ - serviceWorkerUrl: string; + workerUrl: string; /** * Current PubNub client version. @@ -43,6 +48,11 @@ type PubNubMiddlewareConfiguration = { */ logVerbosity: boolean; + /** + * Whether verbose logging should be enabled for `Subscription` worker should print debug messages or not. + */ + workerLogVerbosity: boolean; + /** * Platform-specific transport for requests processing. */ @@ -52,33 +62,38 @@ type PubNubMiddlewareConfiguration = { // endregion /** - * Subscription Service Worker transport middleware. + * Subscription Worker transport middleware. */ -export class SubscriptionServiceWorkerMiddleware implements Transport { +export class SubscriptionWorkerMiddleware implements Transport { /** * Scheduled requests result handling callback. */ callbacks?: Map void; reject: (value: Error) => void }>; /** - * Subscription service worker. + * Subscription shared worker. * - * **Note:** Web PubNub SDK Transport provider adjustment for explicit subscription feature support. + * **Note:** Browser PubNub SDK Transport provider adjustment for explicit subscription / leave features support. */ - serviceWorkerRegistration?: ServiceWorkerRegistration; + subscriptionWorker?: SharedWorker; /** * Queue of events for service worker. * * Keep list of events which should be sent to the worker after its activation. */ - serviceWorkerEventsQueue: PubNubSubscriptionServiceWorker.ClientEvent[]; + workerEventsQueue: PubNubSubscriptionWorker.ClientEvent[]; + + /** + * Whether subscription worker has been initialized and ready to handle events. + */ + subscriptionWorkerReady: boolean = false; constructor(private readonly configuration: PubNubMiddlewareConfiguration) { - this.serviceWorkerEventsQueue = []; + this.workerEventsQueue = []; this.callbacks = new Map(); - this.setupServiceWorker(); + this.setupSubscriptionWorker(); } makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { @@ -87,7 +102,7 @@ export class SubscriptionServiceWorkerMiddleware implements Transport { return this.configuration.transport.makeSendable(req); let controller: CancellationController | undefined; - const sendRequestEvent: PubNubSubscriptionServiceWorker.SendRequestEvent = { + const sendRequestEvent: PubNubSubscriptionWorker.SendRequestEvent = { type: 'send-request', clientIdentifier: this.configuration.clientIdentifier, subscriptionKey: this.configuration.subscriptionKey, @@ -98,7 +113,7 @@ export class SubscriptionServiceWorkerMiddleware implements Transport { if (req.cancellable) { controller = { abort: () => { - const cancelRequest: PubNubSubscriptionServiceWorker.CancelRequestEvent = { + const cancelRequest: PubNubSubscriptionWorker.CancelRequestEvent = { type: 'cancel-request', clientIdentifier: this.configuration.clientIdentifier, subscriptionKey: this.configuration.subscriptionKey, @@ -130,42 +145,42 @@ export class SubscriptionServiceWorkerMiddleware implements Transport { } /** - * Schedule {@link event} publish to the service worker. + * Schedule {@link event} publish to the subscription worker. * - * Service worker may not be ready for events processing and this method build queue for the time when worker will be - * ready. + * Subscription worker may not be ready for events processing and this method build queue for the time when worker + * will be ready. * - * @param event - Event payload for service worker. + * @param event - Event payload for the subscription worker. * @param outOfOrder - Whether event should be processed first then enqueued queue. */ - private scheduleEventPost(event: PubNubSubscriptionServiceWorker.ClientEvent, outOfOrder: boolean = false) { - // Trigger request processing by Web Worker. - const serviceWorker = this.serviceWorker; - if (serviceWorker) serviceWorker.postMessage(event); + private scheduleEventPost(event: PubNubSubscriptionWorker.ClientEvent, outOfOrder: boolean = false) { + // Trigger request processing by subscription worker. + const subscriptionWorker = this.sharedSubscriptionWorker; + if (subscriptionWorker) subscriptionWorker.port.postMessage(event); else { - if (outOfOrder) this.serviceWorkerEventsQueue.splice(0, 0, event); - else this.serviceWorkerEventsQueue.push(event); + if (outOfOrder) this.workerEventsQueue.splice(0, 0, event); + else this.workerEventsQueue.push(event); } } /** - * Dequeue and post events from the queue to the service worker. + * Dequeue and post events from the queue to the subscription worker. */ private flushScheduledEvents(): void { - // Trigger request processing by Web Worker. - const serviceWorker = this.serviceWorker; - if (!serviceWorker || this.serviceWorkerEventsQueue.length === 0) return; + // Trigger request processing by subscription worker. + const subscriptionWorker = this.sharedSubscriptionWorker; + if (!subscriptionWorker || this.workerEventsQueue.length === 0) return; // Clean up from cancelled events. - const outdatedEvents: PubNubSubscriptionServiceWorker.ClientEvent[] = []; - for (let i = 0; i < this.serviceWorkerEventsQueue.length; i++) { - const event = this.serviceWorkerEventsQueue[i]; + const outdatedEvents: PubNubSubscriptionWorker.ClientEvent[] = []; + for (let i = 0; i < this.workerEventsQueue.length; i++) { + const event = this.workerEventsQueue[i]; // Check whether found request cancel event to search for request send event it cancels. if (event.type !== 'cancel-request' || i === 0) continue; for (let j = 0; j < i; j++) { - const otherEvent = this.serviceWorkerEventsQueue[j]; + const otherEvent = this.workerEventsQueue[j]; if (otherEvent.type !== 'send-request') continue; // Collect outdated events if identifiers match. @@ -177,73 +192,77 @@ export class SubscriptionServiceWorkerMiddleware implements Transport { } // Actualizing events queue. - this.serviceWorkerEventsQueue = this.serviceWorkerEventsQueue.filter((event) => !outdatedEvents.includes(event)); - this.serviceWorkerEventsQueue.forEach((event) => serviceWorker.postMessage(event)); - this.serviceWorkerEventsQueue = []; + this.workerEventsQueue = this.workerEventsQueue.filter((event) => !outdatedEvents.includes(event)); + this.workerEventsQueue.forEach((event) => subscriptionWorker.port.postMessage(event)); + this.workerEventsQueue = []; } /** - * Subscription service worker. + * Subscription worker. * - * @returns Service worker which has been registered by the PubNub SDK. + * @returns Worker which has been registered by the PubNub SDK. */ - private get serviceWorker() { - return this.serviceWorkerRegistration ? this.serviceWorkerRegistration.active : null; + private get sharedSubscriptionWorker() { + return this.subscriptionWorkerReady ? this.subscriptionWorker : null; } - private setupServiceWorker(): void { - if (!('serviceWorker' in navigator)) return; - const serviceWorkerContainer = navigator.serviceWorker as ServiceWorkerContainer; - serviceWorkerContainer - .register(this.configuration.serviceWorkerUrl, { - scope: `/pubnub-${this.configuration.sdkVersion}`, - }) - .then((registration) => { - this.serviceWorkerRegistration = registration; - - // Flush any pending service worker events. - if (registration.active) this.flushScheduledEvents(); - - /** - * Listening for service worker code update. - * - * It is possible that one of the tabs will open with newer SDK version and Subscription Service Worker - * will be re-installed - in this case we need to "rehydrate" it. - * - * After re-installation of new service worker it will lose all accumulated state and client need to - * re-introduce itself and its state. - */ - this.serviceWorkerRegistration.addEventListener('updatefound', () => { - if (!this.serviceWorkerRegistration) return; - - // New service installing right now. - const serviceWorker = this.serviceWorkerRegistration.installing!; - - const stateChangeListener = () => { - // Flush any pending service worker events. - if (serviceWorker.state === 'activated') { - // Flush any pending service worker events. - this.flushScheduledEvents(); - } else if (serviceWorker.state === 'redundant') { - // Clean up listener from deprecated service worker version. - serviceWorker.removeEventListener('statechange', stateChangeListener); - } - }; - - serviceWorker.addEventListener('statechange', stateChangeListener); - }); - }); - - serviceWorkerContainer.addEventListener('message', (event) => this.handleServiceWorkerEvent(event)); + private setupSubscriptionWorker(): void { + if (typeof SharedWorker === 'undefined') return; + + this.subscriptionWorker = new SharedWorker( + this.configuration.workerUrl, + `/pubnub-${this.configuration.sdkVersion}`, + ); + + this.subscriptionWorker.port.start(); + + // Register PubNub client within subscription worker. + this.scheduleEventPost( + { + type: 'client-register', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + userId: this.configuration.userId, + logVerbosity: this.configuration.logVerbosity, + workerLogVerbosity: this.configuration.workerLogVerbosity, + }, + true, + ); + + this.subscriptionWorker.port.onmessage = (event) => this.handleWorkerEvent(event); } - private handleServiceWorkerEvent(event: MessageEvent) { + private handleWorkerEvent(event: MessageEvent) { const { data } = event; // Ignoring updates not related to this instance. - if (data.clientIdentifier !== this.configuration.clientIdentifier) return; - - if (data.type === 'request-progress-start' || data.type === 'request-progress-end') { + if ( + data.type !== 'shared-worker-ping' && + data.type !== 'shared-worker-connected' && + data.type !== 'shared-worker-console-log' && + data.type !== 'shared-worker-console-dir' && + data.clientIdentifier !== this.configuration.clientIdentifier + ) + return; + + if (data.type === 'shared-worker-connected') { + this.subscriptionWorkerReady = true; + this.flushScheduledEvents(); + } else if (data.type === 'shared-worker-console-log') { + console.log(`[SharedWorker] ${data.message}`); + } else if (data.type === 'shared-worker-console-dir') { + if (data.message) console.log(`[SharedWorker] ${data.message}`); + console.dir(data.data); + } else if (data.type === 'shared-worker-ping') { + const { logVerbosity, subscriptionKey, clientIdentifier } = this.configuration; + + this.scheduleEventPost({ + type: 'client-pong', + subscriptionKey, + clientIdentifier, + logVerbosity, + }); + } else if (data.type === 'request-progress-start' || data.type === 'request-progress-end') { this.logRequestProgress(data); } else if (data.type === 'request-process-success' || data.type === 'request-process-error') { const { resolve, reject } = this.callbacks!.get(data.identifier)!; @@ -289,9 +308,9 @@ export class SubscriptionServiceWorkerMiddleware implements Transport { /** * Print request progress information. * - * @param information - Request progress information from Web Worker. + * @param information - Request progress information from worker. */ - private logRequestProgress(information: PubNubSubscriptionServiceWorker.RequestSendingProgress) { + private logRequestProgress(information: PubNubSubscriptionWorker.RequestSendingProgress) { if (information.type === 'request-progress-start') { console.log('<<<<<'); console.log(`[${information.timestamp}] ${information.url}\n${JSON.stringify(information.query ?? {})}`); diff --git a/src/transport/service-worker/subscription-service-worker.ts b/src/transport/subscription-worker/subscription-worker.ts similarity index 71% rename from src/transport/service-worker/subscription-service-worker.ts rename to src/transport/subscription-worker/subscription-worker.ts index 970ded65a..84fb67c60 100644 --- a/src/transport/service-worker/subscription-service-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -34,6 +34,28 @@ type BasicEvent = { * Whether verbose logging enabled or not. */ logVerbosity: boolean; + + /** + * Whether verbose logging should be enabled for `Subscription` worker should print debug messages or not. + */ + workerLogVerbosity?: boolean; +}; + +/** + * PubNub client registration event. + */ +export type RegisterEvent = BasicEvent & { + type: 'client-register'; + + /** + * Unique identifier of the user for which PubNub SDK client has been created. + */ + userId: string; + + /** + * Specific PubNub client instance communication port. + */ + port?: MessagePort; }; /** @@ -62,13 +84,29 @@ export type CancelRequestEvent = BasicEvent & { identifier: string; }; +/** + * Client response on PING request. + */ +export type PongEvent = BasicEvent & { + type: 'client-pong'; +}; + /** * List of known events from the PubNub Core. */ -export type ClientEvent = SendRequestEvent | CancelRequestEvent; +export type ClientEvent = RegisterEvent | PongEvent | SendRequestEvent | CancelRequestEvent; // endregion -// region Service Worker +// region Subscription Worker +/** + * Shared subscription worker connected event. + * + * Event signal shared worker client that worker can be used. + */ +export type SharedWorkerConnected = { + type: 'shared-worker-connected'; +}; + /** * {@link Request} processing start event. * @@ -249,10 +287,57 @@ export type RequestSendingSuccess = { */ export type RequestSendingResult = RequestSendingError | RequestSendingSuccess; +/** + * Send message to debug console. + */ +export type SharedWorkerConsoleLog = { + type: 'shared-worker-console-log'; + + /** + * Message which should be printed into the console. + */ + message: string; +}; +/** + * Send message to debug console. + */ +export type SharedWorkerConsoleDir = { + type: 'shared-worker-console-dir'; + + /** + * Message which should be printed into the console before {@link data}. + */ + message?: string; + + /** + * Data which should be printed into the console. + */ + data: Payload; +}; + +/** + * Shared worker console output request. + */ +export type SharedWorkerConsole = SharedWorkerConsoleLog | SharedWorkerConsoleDir; + +/** + * Shared worker client ping request. + * + * Ping used to discover disconnected PubNub instances. + */ +export type SharedWorkerPing = { + type: 'shared-worker-ping'; +}; + /** * List of known events from the PubNub Subscription Service Worker. */ -export type ServiceWorkerEvent = RequestSendingProgress | RequestSendingResult; +export type SubscriptionWorkerEvent = + | SharedWorkerConnected + | SharedWorkerConsole + | SharedWorkerPing + | RequestSendingProgress + | RequestSendingResult; /** * PubNub client state representation in Service Worker. @@ -284,13 +369,23 @@ type PubNubClientState = { */ logVerbosity: boolean; + /** + * Last time when PING request has been sent. + */ + lastPingRequest?: number; + + /** + * Last time when PubNub client respond with PONG event. + */ + lastPongEvent?: number; + /** * Current subscription session information. * * **Note:** Information updated each time when PubNub client instance schedule `subscribe` or * `unsubscribe` requests. */ - subscription: { + subscription?: { /** * Subscription REST API uri path. * @@ -361,7 +456,12 @@ type PubNubClientState = { // -------------------------------------------------------- // region Service Worker -declare const self: ServiceWorkerGlobalScope; +declare const self: SharedWorkerGlobalScope; + +/** + * How often PING request should be sent to the PubNub clients. + */ +const clientPingRequestInterval = 5000; // region State /** @@ -369,6 +469,21 @@ declare const self: ServiceWorkerGlobalScope; */ const decoder = new TextDecoder(); +/** + * Whether `Subscription` worker should print debug information to the console or not. + */ +let logVerbosity: boolean = false; + +/** + * PubNub clients active ping interval. + */ +let pingInterval: number | undefined; + +/** + * Unique shared worker instance identifier. + */ +const sharedWorkerIdentifier = uuidGenerator.createUUID(); + /** * Map of identifiers, scheduled by the Service Worker, to their abort controllers. * @@ -400,12 +515,12 @@ const presenceState: { } = {}; /** - * Per-subscription key map of client identifiers to the Service Worker {@link Client} identifier. + * Per-subscription key map of client identifiers to the Shared Worker {@link MessagePort}. * - * Service Worker {@link Client} represent pages at which PubNub clients registered Service Workers. + * Shared Worker {@link MessagePort} represent specific PubNub client which connected to the Shared Worker. */ -const serviceWorkerClients: { - [subscriptionKey: string]: { [clientId: string]: string | undefined } | undefined; +const sharedWorkerClients: { + [subscriptionKey: string]: { [clientId: string]: MessagePort | undefined } | undefined; } = {}; /** @@ -444,31 +559,44 @@ const serviceRequests: { // region Event Handlers /** - * Listen for Service Worker activation. + * Handle new PubNub client 'connection'. + * + * Echo listeners to let `SharedWorker` users that it is ready. + * + * @param event - Remote `SharedWorker` client connection event. */ -self.addEventListener('activate', (event) => { - event.waitUntil(self.clients.claim()); -}); +self.onconnect = (event) => { + consoleLog('New PubNub Client connected to the Subscription Shared Worker.'); -/** - * Listen for events from the client. - */ -self.addEventListener('message', (event) => { - // Ignoring requests sent from other service workers. - if (!validateEventPayload(event)) return; + event.ports.forEach((receiver) => { + receiver.start(); - const data = event.data as ClientEvent; + receiver.onmessage = (event: MessageEvent) => { + // Ignoring unknown event payloads. + if (!validateEventPayload(event)) return; - if (data.type === 'send-request') { - if (data.request.path.startsWith('/v2/subscribe')) { - registerClientIfRequired(event); - handleSendSubscribeRequestEvent(data); - } else { - if (!pubNubClients[data.clientIdentifier]) registerClientIfRequired(event); - handleSendLeaveRequestEvent(event); - } - } else if (data.type === 'cancel-request') handleCancelRequestEvent(data); -}); + const data = event.data as ClientEvent; + + if (data.type === 'client-register') { + if (!logVerbosity && data.workerLogVerbosity) logVerbosity = true; + + // Appending information about messaging port for responses. + data.port = receiver; + registerClientIfRequired(data); + + consoleLog(`Client '${data.clientIdentifier}' registered with '${sharedWorkerIdentifier}' shared worker`); + } else if (data.type === 'client-pong') handleClientPong(data); + else if (data.type === 'send-request') { + if (data.request.path.startsWith('/v2/subscribe')) { + updateClientStateIfRequired(data); + handleSendSubscribeRequestEvent(data); + } else handleSendLeaveRequestEvent(data); + } else if (data.type === 'cancel-request') handleCancelRequestEvent(data); + }; + + receiver.postMessage({ type: 'shared-worker-connected' }); + }); +}; /** * Handle client request to send subscription request. @@ -482,7 +610,7 @@ const handleSendSubscribeRequestEvent = (event: SendRequestEvent) => { if (client) notifyRequestProcessing('start', [client], new Date().toISOString()); if (typeof requestOrId === 'string') { - if (client) { + if (client && client.subscription) { // Updating client timetoken information. client.subscription.previousTimetoken = client.subscription.timetoken; client.subscription.timetoken = serviceRequests[requestOrId].timetoken; @@ -511,15 +639,16 @@ const handleSendSubscribeRequestEvent = (event: SendRequestEvent) => { markRequestCompleted(clients, requestOrId.identifier); }, ); + + consoleLog(`'${Object.keys(serviceRequests).length}' subscription request currently active.`); }; /** * Handle client request to leave request. * - * @param event - Leave event details. + * @param data - Leave event details. */ -const handleSendLeaveRequestEvent = (event: ExtendableMessageEvent) => { - const data = event.data as SendRequestEvent; +const handleSendLeaveRequestEvent = (data: SendRequestEvent) => { const request = leaveTransportRequestFromEvent(data); const client = pubNubClients[data.clientIdentifier]; @@ -533,9 +662,7 @@ const handleSendLeaveRequestEvent = (event: ExtendableMessageEvent) => { result.clientIdentifier = data.clientIdentifier; result.identifier = data.request.identifier; - publishClientEvent((event.source! as Client).id, result).then((sent) => { - if (sent) invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); - }); + publishClientEvent(client, result); return; } @@ -551,6 +678,8 @@ const handleSendLeaveRequestEvent = (event: ExtendableMessageEvent) => { notifyRequestProcessingResult(clients, null, data.request, requestProcessingError(error)); }, ); + + consoleLog(`Started leave request.`, client); }; /** @@ -562,7 +691,9 @@ const handleSendLeaveRequestEvent = (event: ExtendableMessageEvent) => { */ const handleCancelRequestEvent = (event: CancelRequestEvent) => { const client = pubNubClients[event.clientIdentifier]; - const serviceRequestId = client ? client.subscription.serviceRequestId : undefined; + if (!client || !client.subscription) return; + + const serviceRequestId = client.subscription.serviceRequestId; if (!client || !serviceRequestId) return; // Unset awaited requests. @@ -673,7 +804,7 @@ const requestTimeoutTimer = (requestId: string, requestTimeout: number) => const clientsForRequest = (identifier: string) => { return Object.values(pubNubClients).filter( (client): client is PubNubClientState => - client !== undefined && client.subscription.serviceRequestId === identifier, + client !== undefined && client.subscription !== undefined && client.subscription.serviceRequestId === identifier, ); }; @@ -689,8 +820,10 @@ const markRequestCompleted = (clients: PubNubClientState[], requestId: string) = delete serviceRequests[requestId]; clients.forEach((client) => { - delete client.subscription.request; - delete client.subscription.serviceRequestId; + if (client.subscription) { + delete client.subscription.request; + delete client.subscription.serviceRequestId; + } }); }; @@ -734,7 +867,8 @@ const requestFromTransportRequest = (req: TransportRequest): Request => { */ const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportRequest | string => { const client = pubNubClients[event.clientIdentifier]!; - const clients = clientsForSendSubscribeRequestEvent(client.subscription.previousTimetoken, event); + const subscription = client.subscription!; + const clients = clientsForSendSubscribeRequestEvent(subscription.previousTimetoken, event); const serviceRequestId = uuidGenerator.createUUID(); const request = { ...event.request }; @@ -746,11 +880,11 @@ const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportR const state = (presenceState[client.subscriptionKey] ?? {})[client.userId]; const aggregatedState: Record = {}; - const channelGroups = new Set(client.subscription.channelGroups); - const channels = new Set(client.subscription.channels); + const channelGroups = new Set(subscription.channelGroups); + const channels = new Set(subscription.channels); - if (state && client.subscription.objectsWithState.length) { - client.subscription.objectsWithState.forEach((name) => { + if (state && subscription.objectsWithState.length) { + subscription.objectsWithState.forEach((name) => { const objectState = state[name]; if (objectState) aggregatedState[name] = objectState; }); @@ -759,7 +893,7 @@ const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportR for (const client of clients) { const { subscription } = client!; // Skip clients which already have active subscription request. - if (subscription.serviceRequestId) continue; + if (!subscription || !subscription.serviceRequestId) continue; subscription.channelGroups.forEach(channelGroups.add, channelGroups); subscription.channels.forEach(channels.add, channels); @@ -803,14 +937,25 @@ const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportR serviceRequests[serviceRequestId] = { requestId: serviceRequestId, timetoken: (request.queryParameters!.tt as string) ?? '0', - channelGroups: client.subscription.channelGroups, - channels: client.subscription.channels, + channelGroups: subscription.channelGroups, + channels: subscription.channels, }; } - client.subscription.serviceRequestId = serviceRequestId; + subscription.serviceRequestId = serviceRequestId; request.identifier = serviceRequestId; + if (logVerbosity) { + const clientIds = clients + .reduce((identifiers: string[], { clientIdentifier }) => { + identifiers.push(clientIdentifier); + return identifiers; + }, []) + .join(','); + + consoleDir(serviceRequests[serviceRequestId], `Started aggregated request for clients: ${clientIds}`); + } + return request; }; @@ -831,7 +976,7 @@ const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportReque let channels = channelsFromRequest(event.request); const request = { ...event.request }; - if (client) { + if (client && client.subscription) { const { subscription } = client; if (channels.length) subscription.channels = subscription.channels.filter((channel) => !channels.includes(channel)); if (channelGroups.length) { @@ -841,13 +986,31 @@ const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportReque // Filter out channels and groups which is still in use by the other PubNub client instances. for (const client of clients) { + const subscription = client.subscription; + if (subscription === undefined) continue; if (client.clientIdentifier === event.clientIdentifier) continue; - if (channels.length) channels = channels.filter((channel) => !client.subscription.channels.includes(channel)); + if (channels.length) channels = channels.filter((channel) => !subscription.channels.includes(channel)); if (channelGroups.length) - channelGroups = channelGroups.filter((group) => !client.subscription.channelGroups.includes(group)); + channelGroups = channelGroups.filter((group) => !subscription.channelGroups.includes(group)); } - if (channels.length === 0 && channelGroups.length === 0) return undefined; + if (channels.length === 0 && channelGroups.length === 0) { + if (logVerbosity && client) { + const clientIds = clients + .reduce((identifiers: string[], { clientIdentifier }) => { + identifiers.push(clientIdentifier); + return identifiers; + }, []) + .join(','); + + consoleLog( + `Specified channels and groups still in use by other clients: ${clientIds}. Ignoring leave request.`, + client, + ); + } + + return undefined; + } // Update request channels list (if required). if (channels.length) { @@ -863,18 +1026,21 @@ const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportReque }; /** - * Send event to all service worker clients. + * Send event to the specific PubNub client. * - * @param identifier - Service Worker receiving {@link Client} identifier. - * @param event - Service worker event object. + * @param client - State for the client which should receive {@link event}. + * @param event - Subscription worker event object. */ -const publishClientEvent = (identifier: string, event: ServiceWorkerEvent) => { - return self.clients.get(identifier).then((client) => { - if (!client) return false; +const publishClientEvent = (client: PubNubClientState, event: SubscriptionWorkerEvent) => { + const receiver = (sharedWorkerClients[client.subscriptionKey] ?? {})[client.clientIdentifier]; + if (!receiver) return false; - client.postMessage(event); + try { + receiver.postMessage(event); return true; - }); + } catch (error) {} + + return false; }; /** @@ -899,7 +1065,7 @@ const notifyRequestProcessing = ( ) => { if (clients.length === 0) return; - const clientIds = serviceWorkerClients[clients[0].subscriptionKey] ?? {}; + const clientIds = sharedWorkerClients[clients[0].subscriptionKey] ?? {}; let event: RequestSendingProgress; if (type === 'start') { @@ -932,22 +1098,24 @@ const notifyRequestProcessing = ( }; } - clients.forEach((client) => { + for (const client of clients) { + if (client.subscription === undefined) continue; + const serviceWorkerClientId = clientIds[client.clientIdentifier]; const { request: clientRequest } = client.subscription; const decidedRequest = clientRequest ?? request; if (client.logVerbosity && serviceWorkerClientId && decidedRequest) { - publishClientEvent(serviceWorkerClientId, { + const payload = { ...event, clientIdentifier: client.clientIdentifier, url: `${decidedRequest.origin}${decidedRequest.path}`, query: decidedRequest.queryParameters, - }).then((sent) => { - if (sent) invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); - }); + }; + + publishClientEvent(client, payload); } - }); + } }; /** @@ -967,7 +1135,7 @@ const notifyRequestProcessingResult = ( if (clients.length === 0) return; if (!result && !response) return; - const clientIds = serviceWorkerClients[clients[0].subscriptionKey] ?? {}; + const clientIds = sharedWorkerClients[clients[0].subscriptionKey] ?? {}; if (!result && response) { result = @@ -977,22 +1145,24 @@ const notifyRequestProcessingResult = ( : requestProcessingSuccess(response); } - clients.forEach((client) => { + for (const client of clients) { + if (client.subscription === undefined) continue; + const serviceWorkerClientId = clientIds[client.clientIdentifier]; const { request: clientRequest } = client.subscription; const decidedRequest = clientRequest ?? request; if (serviceWorkerClientId && decidedRequest) { - publishClientEvent(serviceWorkerClientId, { + const payload = { ...result!, clientIdentifier: client.clientIdentifier, identifier: decidedRequest.identifier, url: `${decidedRequest.origin}${decidedRequest.path}`, - }).then((sent) => { - if (sent) invalidateClient(client.subscriptionKey, client.clientIdentifier, client.userId); - }); + }; + + publishClientEvent(client, payload); } - }); + } }; /** @@ -1089,71 +1259,79 @@ const requestProcessingError = (error?: unknown, res?: [Response, ArrayBuffer]): * * @param event - Base information about PubNub client instance and Service Worker {@link Client}. */ -const registerClientIfRequired = (event: ExtendableMessageEvent) => { - const information = event.data as SendRequestEvent; - const { clientIdentifier } = information; - const query = information.request.queryParameters!; - - let client = pubNubClients[clientIdentifier]; - - if (!client) { - const isPresenceLeave = !information.request.path.startsWith('/v2/subscribe'); - const channelGroupQuery = !isPresenceLeave ? ((query!['channel-group'] ?? '') as string) : ''; - const state = !isPresenceLeave ? ((query.state ?? '') as string) : ''; - - client = pubNubClients[clientIdentifier] = { - clientIdentifier, - subscriptionKey: information.subscriptionKey, - userId: query.uuid as string, - authKey: (query.auth ?? '') as string, - logVerbosity: information.logVerbosity, - subscription: { - path: !isPresenceLeave ? information.request.path : '', - channelGroupQuery: !isPresenceLeave ? channelGroupQuery : '', - channels: !isPresenceLeave ? channelsFromRequest(information.request) : [], - channelGroups: !isPresenceLeave ? channelGroupsFromRequest(information.request) : [], - previousTimetoken: !isPresenceLeave ? ((query.tt ?? '0') as string) : '0', - timetoken: !isPresenceLeave ? ((query.tt ?? '0') as string) : '0', - request: !isPresenceLeave ? information.request : undefined, - objectsWithState: [], - filterExpression: !isPresenceLeave ? ((query['filter-expr'] ?? '') as string) : undefined, - }, +const registerClientIfRequired = (event: RegisterEvent) => { + const { clientIdentifier } = event; + + if (pubNubClients[clientIdentifier]) return; + + const client = (pubNubClients[clientIdentifier] = { + clientIdentifier, + subscriptionKey: event.subscriptionKey, + userId: event.userId, + logVerbosity: event.logVerbosity, + }); + + // Map registered PubNub client to its subscription key. + const clientsBySubscriptionKey = (pubNubClientsBySubscriptionKey[event.subscriptionKey] ??= []); + if (clientsBySubscriptionKey.every((entry) => entry.clientIdentifier !== clientIdentifier)) + clientsBySubscriptionKey.push(client); + + // Binding PubNub client to the MessagePort (receiver). + (sharedWorkerClients[event.subscriptionKey] ??= {})[clientIdentifier] = event.port; + + consoleLog( + `Registered PubNub client with '${clientIdentifier}' identifier. ` + + `'${Object.keys(pubNubClients).length}' clients currently active.`, + ); + + if (!pingInterval && Object.keys(pubNubClients).length > 0) { + consoleLog(`Setup PubNub client ping event ${clientPingRequestInterval / 1000} seconds`); + pingInterval = setInterval(() => pingClients(), clientPingRequestInterval) as unknown as number; + } +}; + +/** + * Update information about previously registered client. + * + * Use information from request to populate list of channels and other useful information. + * + * @param event - Send request. + */ +const updateClientStateIfRequired = (event: SendRequestEvent) => { + const query = event.request.queryParameters!; + const { clientIdentifier } = event; + + const client = pubNubClients[clientIdentifier]; + + // This should never happen. + if (!client) return; + + const channelGroupQuery = (query!['channel-group'] ?? '') as string; + const state = (query.state ?? '') as string; + + let subscription = client.subscription; + if (!subscription) { + subscription = { + path: '', + channelGroupQuery: '', + channels: [], + channelGroups: [], + previousTimetoken: '0', + timetoken: '0', + objectsWithState: [], }; - if (!isPresenceLeave && state.length > 0) { + if (state.length > 0) { const parsedState = JSON.parse(state) as Record; const userState = ((presenceState[client.subscriptionKey] ??= {})[client.userId] ??= {}); Object.entries(parsedState).forEach(([objectName, value]) => (userState[objectName] = value)); - client.subscription.objectsWithState = Object.keys(parsedState); + subscription.objectsWithState = Object.keys(parsedState); } - // Map registered PubNub client to its subscription key. - const clientsBySubscriptionKey = (pubNubClientsBySubscriptionKey[information.subscriptionKey] ??= []); - if (clientsBySubscriptionKey.every((entry) => entry.clientIdentifier !== clientIdentifier)) - clientsBySubscriptionKey.push(client); - - // Binding PubNub client to the page (Service Worker Client). - (serviceWorkerClients[information.subscriptionKey] ??= {})[clientIdentifier] = (event.source! as Client).id; + client.subscription = subscription; } else { - const channelGroupQuery = (query!['channel-group'] ?? '') as string; - const state = (query.state ?? '') as string; - client.subscription.filterExpression = (query['filter-expr'] ?? '') as string; - client.subscription.previousTimetoken = client.subscription.timetoken; - client.subscription.timetoken = (query.tt ?? '0') as string; - client.subscription.request = information.request; - client.authKey = (query.auth ?? '') as string; - client.userId = query.uuid as string; - - if (client.subscription.path !== information.request.path) { - client.subscription.path = information.request.path; - client.subscription.channels = channelsFromRequest(information.request); - } - - if (client.subscription.channelGroupQuery !== channelGroupQuery) { - client.subscription.channelGroupQuery = channelGroupQuery; - client.subscription.channelGroups = channelGroupsFromRequest(information.request); - } + subscription.previousTimetoken = subscription.timetoken; if (state.length > 0) { const parsedState = JSON.parse(state) as Record; @@ -1161,18 +1339,48 @@ const registerClientIfRequired = (event: ExtendableMessageEvent) => { Object.entries(parsedState).forEach(([objectName, value]) => (userState[objectName] = value)); // Clean up state for objects where presence state has been reset. - for (const objectName of client.subscription.objectsWithState) + for (const objectName of subscription.objectsWithState) if (!parsedState[objectName]) delete userState[objectName]; - client.subscription.objectsWithState = Object.keys(parsedState); + + subscription.objectsWithState = Object.keys(parsedState); } // Handle potential presence state reset. - else if (client.subscription.objectsWithState.length) { + else if (subscription.objectsWithState.length) { const userState = ((presenceState[client.subscriptionKey] ??= {})[client.userId] ??= {}); - for (const objectName of client.subscription.objectsWithState) delete userState[objectName]; - client.subscription.objectsWithState = []; + for (const objectName of subscription.objectsWithState) delete userState[objectName]; + subscription.objectsWithState = []; } } + + if (subscription.path !== event.request.path) { + subscription.path = event.request.path; + subscription.channels = channelsFromRequest(event.request); + } + + if (subscription.channelGroupQuery !== channelGroupQuery) { + subscription.channelGroupQuery = channelGroupQuery; + subscription.channelGroups = channelGroupsFromRequest(event.request); + } + + subscription.request = event.request; + subscription.filterExpression = (query['filter-expr'] ?? '') as string; + subscription.timetoken = (query.tt ?? '0') as string; + client.authKey = (query.auth ?? '') as string; + client.userId = query.uuid as string; +}; + +/** + * Handle PubNub client response on PING request. + * + * @param event - Information about client which responded on PING request. + */ +const handleClientPong = (event: PongEvent) => { + const client = pubNubClients[event.clientIdentifier]; + + if (!client) return; + + client.lastPongEvent = new Date().getTime() / 1000; }; /** @@ -1181,9 +1389,8 @@ const registerClientIfRequired = (event: ExtendableMessageEvent) => { * @param subscriptionKey - Subscription key which has been used by the * invalidated instance. * @param clientId - Unique PubNub client identifier. - * @param userId - Unique identifier of the user used by PubNub client instance. */ -const invalidateClient = (subscriptionKey: string, clientId: string, userId: string) => { +const invalidateClient = (subscriptionKey: string, clientId: string) => { delete pubNubClients[clientId]; let clients = pubNubClientsBySubscriptionKey[subscriptionKey]; @@ -1198,24 +1405,23 @@ const invalidateClient = (subscriptionKey: string, clientId: string, userId: str // Clean up service workers client linkage to PubNub clients. if (clients.length > 0) { - const workerClients = serviceWorkerClients[subscriptionKey]; + const workerClients = sharedWorkerClients[subscriptionKey]; if (workerClients) { delete workerClients[clientId]; - if (Object.keys(workerClients).length === 0) delete serviceWorkerClients[subscriptionKey]; + if (Object.keys(workerClients).length === 0) delete sharedWorkerClients[subscriptionKey]; } - } else delete serviceWorkerClients[subscriptionKey]; + } else delete sharedWorkerClients[subscriptionKey]; } + + consoleLog(`Invalidate '${clientId}' client. '${Object.keys(pubNubClients).length}' clients currently active.`); }; /** * Validate received event payload. */ -const validateEventPayload = (event: ExtendableMessageEvent): boolean => { - if (!event.source || !(event.source instanceof Client)) return false; - const data = event.data as ClientEvent; - - const { clientIdentifier, subscriptionKey, logVerbosity } = data as ClientEvent; +const validateEventPayload = (event: MessageEvent): boolean => { + const { clientIdentifier, subscriptionKey, logVerbosity } = event.data as ClientEvent; if (logVerbosity === undefined || typeof logVerbosity !== 'boolean') return false; if (!clientIdentifier || typeof clientIdentifier !== 'string') return false; @@ -1223,7 +1429,7 @@ const validateEventPayload = (event: ExtendableMessageEvent): boolean => { }; /** - * Search for active subscription for one of the passed {@link serviceWorkerClients}. + * Search for active subscription for one of the passed {@link sharedWorkerClients}. * * @param activeClients - List of suitable registered PubNub clients. * @param event - Send Subscriber Request event data. @@ -1244,9 +1450,17 @@ const activeSubscriptionForEvent = ( for (const client of activeClients) { const { subscription } = client; // Skip PubNub clients which doesn't await for subscription response. - if (!subscription.serviceRequestId) continue; + if (!subscription || !subscription.serviceRequestId) continue; + const sourceClient = pubNubClients[event.clientIdentifier]; + const requestId = subscription.serviceRequestId; if (subscription.path === requestPath && subscription.channelGroupQuery === channelGroupQuery) { + consoleLog( + `Found identical request started by '${client.clientIdentifier}' client. +Waiting for existing '${requestId}' request completion.`, + sourceClient, + ); + return subscription.serviceRequestId; } else { const scheduledRequest = serviceRequests[subscription.serviceRequestId]; @@ -1257,6 +1471,13 @@ const activeSubscriptionForEvent = ( if (channels.length && !includesStrings(scheduledRequest.channels, channels)) continue; if (channelGroups.length && !includesStrings(scheduledRequest.channelGroups, channelGroups)) continue; + consoleDir( + scheduledRequest, + `'${event.request.identifier}' request channels and groups are subset of ongoing '${requestId}' request +which has started by '${client.clientIdentifier}' client. Waiting for existing '${requestId}' request completion.`, + sourceClient, + ); + return subscription.serviceRequestId; } } @@ -1290,6 +1511,7 @@ const clientsForSendSubscribeRequestEvent = (timetoken: string, event: SendReque (client) => client.userId === userId && client.authKey === authKey && + client.subscription && client.subscription.filterExpression === filterExpression && (timetoken === '0' || client.subscription.previousTimetoken === '0' || @@ -1356,6 +1578,83 @@ const includesStrings = (main: string[], sub: string[]) => { return sub.every(set.has, set); }; +/** + * Send PubNub client PING request to identify disconnected instances. + */ +const pingClients = () => { + consoleLog(`Pinging clients...`); + const payload: SharedWorkerPing = { type: 'shared-worker-ping' }; + + Object.values(pubNubClients).forEach((client) => { + let clientInvalidated = false; + + if (client && client.lastPingRequest) { + consoleLog(`Checking whether ${client.clientIdentifier} ping has been sent too long ago...`); + // Check whether client never respond or last response was too long time ago. + if ( + !client.lastPongEvent || + Math.abs(client.lastPongEvent - client.lastPingRequest) > (clientPingRequestInterval / 1000) * 0.5 + ) { + clientInvalidated = true; + + consoleLog(`'${client.clientIdentifier}' client is inactive. Invalidating.`); + invalidateClient(client.subscriptionKey, client.clientIdentifier); + } + } + + if (client && !clientInvalidated) { + consoleLog(`Sending ping to ${client.clientIdentifier}...`); + client.lastPingRequest = new Date().getTime() / 1000; + publishClientEvent(client, payload); + } + }); + + // Cancel interval if there is no active clients. + if (Object.keys(pubNubClients).length === 0 && pingInterval) clearInterval(pingInterval); +}; + +/** + * Print message on the worker's clients console. + * + * @param message - Message which should be printed. + * @param [client] - Target client to which log message should be sent. + */ +const consoleLog = (message: string, client?: PubNubClientState): void => { + if (!logVerbosity) return; + + const clients = client ? [client] : Object.values(pubNubClients); + const payload: SharedWorkerConsoleLog = { + type: 'shared-worker-console-log', + message, + }; + + clients.forEach((client) => { + if (client) publishClientEvent(client, payload); + }); +}; + +/** + * Print message on the worker's clients console. + * + * @param data - Data which should be printed into the console. + * @param [message] - Message which should be printed before {@link data}. + * @param [client] - Target client to which log message should be sent. + */ +const consoleDir = (data: Payload, message?: string, client?: PubNubClientState): void => { + if (!logVerbosity) return; + + const clients = client ? [client] : Object.values(pubNubClients); + const payload: SharedWorkerConsoleDir = { + type: 'shared-worker-console-dir', + message, + data, + }; + + clients.forEach((client) => { + if (client) publishClientEvent(client, payload); + }); +}; + /** * Stringify request query key / value pairs. * diff --git a/src/web/components/configuration.ts b/src/web/components/configuration.ts index 651cd1530..06e65c335 100644 --- a/src/web/components/configuration.ts +++ b/src/web/components/configuration.ts @@ -3,6 +3,7 @@ import { ExtendedConfiguration, setDefaults as setBaseDefaults, } from '../../core/interfaces/configuration'; +import { CryptoModule } from '../../core/interfaces/crypto-module'; // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -17,6 +18,11 @@ import { */ const LISTEN_TO_BROWSER_NETWORK_EVENTS = true; +/** + * Whether verbose logging should be enabled for `Subscription` worker to print debug messages or not. + */ +const SUBSCRIPTION_WORKER_LOG_VERBOSITY = false; + /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -45,7 +51,14 @@ export type PubNubConfiguration = UserConfiguration & { * statics provided from `subdomain.main.com` and page loaded from `account.main.com` - then server should be * configured to serve worker file from `account.main.com`. */ - serviceWorkerUrl?: string | null; + subscriptionWorkerUrl?: string | null; + + /** + * Whether verbose logging should be enabled for `Subscription` worker should print debug messages or not. + * + * @default `false` + */ + subscriptionWorkerLogVerbosity?: boolean; /** * If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of @@ -54,23 +67,57 @@ export type PubNubConfiguration = UserConfiguration & { * @default `true` */ keepAlive?: boolean; + + /** + * The cryptography module used for encryption and decryption of messages and files. Takes the + * {@link cipherKey} and {@link useRandomIVs} parameters as arguments. + * + * For more information, refer to the + * {@link /docs/sdks/javascript/api-reference/configuration#cryptomodule|cryptoModule} section. + * + * @default `not set` + */ + cryptoModule?: CryptoModule; + + // region Deprecated parameters + /** + * If passed, will encrypt the payloads. + * + * @deprecated Pass it to {@link cryptoModule} instead. + */ + cipherKey?: string; + + /** + * When `true` the initialization vector (IV) is random for all requests (not just for file + * upload). + * When `false` the IV is hard-coded for all requests except for file upload. + * + * @default `true` + * + * @deprecated Pass it to {@link cryptoModule} instead. + */ + useRandomIVs?: boolean; }; /** * Apply configuration default values. * * @param configuration - User-provided configuration. + * + * @internal */ export const setDefaults = (configuration: PubNubConfiguration): PubNubConfiguration & ExtendedConfiguration => { // Force disable service workers if environment doesn't support them. - if (configuration.serviceWorkerUrl && !('serviceWorker' in navigator)) configuration.serviceWorkerUrl = null; + if (configuration.subscriptionWorkerUrl && typeof SharedWorker === 'undefined') + configuration.subscriptionWorkerUrl = null; return { // Set base configuration defaults. ...setBaseDefaults(configuration), // Set platform-specific options. listenToBrowserNetworkEvents: configuration.listenToBrowserNetworkEvents ?? LISTEN_TO_BROWSER_NETWORK_EVENTS, - serviceWorkerUrl: configuration.serviceWorkerUrl, + subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, + subscriptionWorkerLogVerbosity: configuration.subscriptionWorkerLogVerbosity ?? SUBSCRIPTION_WORKER_LOG_VERBOSITY, keepAlive: configuration.keepAlive ?? KEEP_ALIVE, }; }; diff --git a/src/web/index.ts b/src/web/index.ts index 5fc10654b..7cf367027 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -4,8 +4,8 @@ import CborReader from 'cbor-js'; // eslint-disable-next-line max-len -import { SubscriptionServiceWorkerMiddleware } from '../transport/service-worker/subscription-service-worker-middleware'; import { AesCbcCryptor, LegacyCryptor, WebCryptoModule } from '../crypto/modules/WebCryptoModule/webCryptoModule'; +import { SubscriptionWorkerMiddleware } from '../transport/subscription-worker/subscription-worker-middleware'; import { WebReactNativeTransport } from '../transport/web-react-native-transport'; import { stringifyBufferKeys } from '../core/components/stringify_buffer_keys'; import { PubNubConfiguration, setDefaults } from './components/configuration'; @@ -69,14 +69,17 @@ export default class PubNub extends PubNubCore Date: Tue, 21 May 2024 10:39:30 +0300 Subject: [PATCH 08/49] Add environment flags to disable modules (#372) feat(tree-shaking): add environment flags to disable modules Add environment flags processing to opt-out feature modules from built bundles. fix(api): add 'Content-Type' headers for endpoints --- .pubnub.yml | 13 +- CHANGELOG.md | 9 + README.md | 4 +- dist/web/pubnub.js | 1198 +++++++---------- dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 2 +- .../endpoints/access_manager/grant_token.js | 3 + .../endpoints/actions/add_message_action.js | 6 +- .../file_upload/generate_upload_url.js | 3 + lib/core/pubnub-common.js | 916 ++++++++----- lib/entities/Channel.js | 18 +- lib/entities/ChannelGroup.js | 18 +- lib/entities/ChannelMetadata.js | 18 +- lib/entities/UserMetadata.js | 18 +- lib/node/index.js | 48 +- lib/react_native/index.js | 27 +- lib/transport/middleware.js | 16 +- lib/types/core/pubnub-common.d.ts | 2 +- lib/types/node/index.d.ts | 4 +- lib/types/transport/middleware.d.ts | 23 +- package.json | 2 +- rollup.config.js | 177 ++- src/core/components/configuration.ts | 2 +- .../endpoints/access_manager/grant_token.ts | 4 + .../endpoints/actions/add_message_action.ts | 8 +- .../file_upload/generate_upload_url.ts | 4 + src/core/pubnub-common.ts | 879 +++++++----- src/entities/Channel.ts | 16 +- src/entities/ChannelGroup.ts | 16 +- src/entities/ChannelMetadata.ts | 16 +- src/entities/UserMetadata.ts | 16 +- src/node/index.ts | 57 +- src/react_native/index.ts | 35 +- src/titanium/index.ts | 10 +- src/transport/middleware.ts | 17 +- src/web/index.ts | 82 +- 36 files changed, 2029 insertions(+), 1662 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 54e9c5656..5b4612835 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2024-05-21 + version: v8.2.0 + changes: + - type: feature + text: "Add environment flags processing to opt-out feature modules from built bundles." + - type: bug + text: "Add `application/json` content type for `Grant Token`, `Add Message Action` and `Generate File Upload URL` endpoints." - date: 2024-05-16 version: v8.1.0 changes: @@ -981,7 +988,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.1.0' +version: '8.2.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -997,7 +1004,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.1.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1668,7 +1675,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.1.0/pubnub.8.1.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.0/pubnub.8.2.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index e0076703c..911e9a8e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v8.2.0 +May 21 2024 + +#### Added +- Add environment flags processing to opt-out feature modules from built bundles. + +#### Fixed +- Add `application/json` content type for `Grant Token`, `Add Message Action` and `Generate File Upload URL` endpoints. Fixed the following issues reported by [@SpaseESG](https://github.com/SpaseESG): [#373](https://github.com/pubnub/javascript/issues/373). + ## v8.1.0 May 16 2024 diff --git a/README.md b/README.md index 1a7344234..dae175213 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.1.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.1.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index b313fae74..7d4b13c81 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3810,7 +3810,7 @@ return base.PubNubFile; }, get version() { - return '8.1.0'; + return '8.2.0'; }, getVersion() { return this.version; @@ -4027,6 +4027,11 @@ TransportMethod["LOCAL"] = "LOCAL"; })(TransportMethod || (TransportMethod = {})); + /** + * Request signature generator. + * + * @internal + */ class RequestSignature { constructor(publishKey, secretKey, hasher) { this.publishKey = publishKey; @@ -4085,8 +4090,10 @@ constructor(configuration) { this.configuration = configuration; const { clientConfiguration: { keySet }, shaHMAC, } = configuration; - if (keySet.secretKey && shaHMAC) - this.signatureGenerator = new RequestSignature(keySet.publishKey, keySet.secretKey, shaHMAC); + { + if (keySet.secretKey && shaHMAC) + this.signatureGenerator = new RequestSignature(keySet.publishKey, keySet.secretKey, shaHMAC); + } } makeSendable(req) { return this.configuration.transport.makeSendable(this.request(req)); @@ -4119,7 +4126,7 @@ if (req.path.startsWith('/v2/auth/') || req.path.startsWith('/v3/pam/') || req.path.startsWith('/time')) return; const { clientConfiguration, tokenManager } = this.configuration; - const accessKey = (_a = tokenManager.getToken()) !== null && _a !== void 0 ? _a : clientConfiguration.authKey; + const accessKey = (_a = (tokenManager && tokenManager.getToken())) !== null && _a !== void 0 ? _a : clientConfiguration.authKey; if (accessKey) req.queryParameters['auth'] = accessKey; } @@ -8445,13 +8452,13 @@ return { data: serviceResponse.data }; }); } - get headers() { - return { 'Content-Type': 'application/json' }; - } get path() { const { keySet: { subscribeKey }, channel, messageTimetoken, } = this.parameters; return `/v1/message-actions/${subscribeKey}/channel/${encodeString(channel)}/message/${messageTimetoken}`; } + get headers() { + return { 'Content-Type': 'application/json' }; + } get body() { return JSON.stringify(this.parameters.action); } @@ -8764,6 +8771,9 @@ const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/generate-upload-url`; } + get headers() { + return { 'Content-Type': 'application/json' }; + } get body() { return JSON.stringify({ name: this.parameters.name }); } @@ -8949,364 +8959,6 @@ } } - /** - * PAM Revoke Token REST API module. - */ - // endregion - /** - * Access token revoke request. - * - * Invalidate token and permissions which has been granted for it. - * - * @internal - */ - class RevokeTokenRequest extends AbstractRequest { - constructor(parameters) { - super({ method: TransportMethod.DELETE }); - this.parameters = parameters; - } - operation() { - return RequestOperation$1.PNAccessManagerRevokeToken; - } - validate() { - if (!this.parameters.keySet.secretKey) - return 'Missing Secret Key'; - if (!this.parameters.token) - return "token can't be empty"; - } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return {}; - }); - } - get path() { - const { keySet: { subscribeKey }, token, } = this.parameters; - return `/v3/pam/${subscribeKey}/grant/${encodeString(token)}`; - } - } - - /** - * PAM Grant Token REST API module. - */ - // endregion - /** - * Grant token permissions request. - * - * @internal - */ - class GrantTokenRequest extends AbstractRequest { - constructor(parameters) { - var _a, _b; - var _c, _d; - super({ method: TransportMethod.POST }); - this.parameters = parameters; - // Apply defaults. - (_a = (_c = this.parameters).resources) !== null && _a !== void 0 ? _a : (_c.resources = {}); - (_b = (_d = this.parameters).patterns) !== null && _b !== void 0 ? _b : (_d.patterns = {}); - } - operation() { - return RequestOperation$1.PNAccessManagerGrantToken; - } - validate() { - var _a, _b, _c, _d, _e, _f; - const { keySet: { subscribeKey, publishKey, secretKey }, resources, patterns, } = this.parameters; - if (!subscribeKey) - return 'Missing Subscribe Key'; - if (!publishKey) - return 'Missing Publish Key'; - if (!secretKey) - return 'Missing Secret Key'; - if (!resources && !patterns) - return 'Missing either Resources or Patterns'; - if (this.isVspPermissions(this.parameters) && - ('channels' in ((_a = this.parameters.resources) !== null && _a !== void 0 ? _a : {}) || - 'uuids' in ((_b = this.parameters.resources) !== null && _b !== void 0 ? _b : {}) || - 'groups' in ((_c = this.parameters.resources) !== null && _c !== void 0 ? _c : {}) || - 'channels' in ((_d = this.parameters.patterns) !== null && _d !== void 0 ? _d : {}) || - 'uuids' in ((_e = this.parameters.patterns) !== null && _e !== void 0 ? _e : {}) || - 'groups' in ((_f = this.parameters.patterns) !== null && _f !== void 0 ? _f : {}))) - return ('Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`,' + - ' `groups` and `authorized_uuid`'); - let permissionsEmpty = true; - [this.parameters.resources, this.parameters.patterns].forEach((refPerm) => { - Object.keys(refPerm !== null && refPerm !== void 0 ? refPerm : {}).forEach((scope) => { - var _a; - // @ts-expect-error Permissions with backward compatibility. - if (refPerm && permissionsEmpty && Object.keys((_a = refPerm[scope]) !== null && _a !== void 0 ? _a : {}).length > 0) { - permissionsEmpty = false; - } - }); - }); - if (permissionsEmpty) - return 'Missing values for either Resources or Patterns'; - } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse.data.token; - }); - } - get path() { - return `/v3/pam/${this.parameters.keySet.subscribeKey}/grant`; - } - get body() { - const { ttl, meta } = this.parameters; - const body = Object.assign({}, (ttl || ttl === 0 ? { ttl } : {})); - const uuid = this.isVspPermissions(this.parameters) - ? this.parameters.authorizedUserId - : this.parameters.authorized_uuid; - const permissions = {}; - const resourcePermissions = {}; - const patternPermissions = {}; - const mapPermissions = (name, permissionBit, type, permissions) => { - if (!permissions[type]) - permissions[type] = {}; - permissions[type][name] = permissionBit; - }; - const { resources, patterns } = this.parameters; - [resources, patterns].forEach((refPerm, idx) => { - var _a, _b, _c, _d, _e; - const target = idx === 0 ? resourcePermissions : patternPermissions; - let channelsPermissions = {}; - let channelGroupsPermissions = {}; - let uuidsPermissions = {}; - if (!target.channels) - target.channels = {}; - if (!target.groups) - target.groups = {}; - if (!target.uuids) - target.uuids = {}; - // @ts-expect-error Not used, needed for api backward compatibility - if (!target.users) - target.users = {}; - // @ts-expect-error Not used, needed for api backward compatibility - if (!target.spaces) - target.spaces = {}; - if (refPerm) { - // Check whether working with legacy Objects permissions. - if ('spaces' in refPerm || 'users' in refPerm) { - channelsPermissions = (_a = refPerm.spaces) !== null && _a !== void 0 ? _a : {}; - uuidsPermissions = (_b = refPerm.users) !== null && _b !== void 0 ? _b : {}; - } - else if ('channels' in refPerm || 'uuids' in refPerm || 'groups' in refPerm) { - channelsPermissions = (_c = refPerm.channels) !== null && _c !== void 0 ? _c : {}; - channelGroupsPermissions = (_d = refPerm.groups) !== null && _d !== void 0 ? _d : {}; - uuidsPermissions = (_e = refPerm.uuids) !== null && _e !== void 0 ? _e : {}; - } - } - Object.keys(channelsPermissions).forEach((channel) => mapPermissions(channel, this.extractPermissions(channelsPermissions[channel]), 'channels', target)); - Object.keys(channelGroupsPermissions).forEach((groups) => mapPermissions(groups, this.extractPermissions(channelGroupsPermissions[groups]), 'groups', target)); - Object.keys(uuidsPermissions).forEach((uuids) => mapPermissions(uuids, this.extractPermissions(uuidsPermissions[uuids]), 'uuids', target)); - }); - if (uuid) - permissions.uuid = `${uuid}`; - permissions.resources = resourcePermissions; - permissions.patterns = patternPermissions; - permissions.meta = meta !== null && meta !== void 0 ? meta : {}; - body.permissions = permissions; - return JSON.stringify(body); - } - /** - * Extract permissions bit from permission configuration object. - * - * @param permissions - User provided scope-based permissions. - * - * @returns Permissions bit. - */ - extractPermissions(permissions) { - let permissionsResult = 0; - if ('join' in permissions && permissions.join) - permissionsResult |= 128; - if ('update' in permissions && permissions.update) - permissionsResult |= 64; - if ('get' in permissions && permissions.get) - permissionsResult |= 32; - if ('delete' in permissions && permissions.delete) - permissionsResult |= 8; - if ('manage' in permissions && permissions.manage) - permissionsResult |= 4; - if ('write' in permissions && permissions.write) - permissionsResult |= 2; - if ('read' in permissions && permissions.read) - permissionsResult |= 1; - return permissionsResult; - } - /** - * Check whether provided parameters is part of legacy VSP access token configuration. - * - * @param parameters - Parameters which should be checked. - * - * @returns VSP request parameters if it is legacy configuration. - */ - isVspPermissions(parameters) { - var _a, _b, _c, _d; - return ('authorizedUserId' in parameters || - 'spaces' in ((_a = parameters.resources) !== null && _a !== void 0 ? _a : {}) || - 'users' in ((_b = parameters.resources) !== null && _b !== void 0 ? _b : {}) || - 'spaces' in ((_c = parameters.patterns) !== null && _c !== void 0 ? _c : {}) || - 'users' in ((_d = parameters.patterns) !== null && _d !== void 0 ? _d : {})); - } - } - - /** - * PAM Grant REST API module. - */ - // -------------------------------------------------------- - // ----------------------- Defaults ----------------------- - // -------------------------------------------------------- - // region Defaults - /** - * Resources `read` permission. - */ - const READ_PERMISSION = false; - /** - * Resources `write` permission. - */ - const WRITE_PERMISSION = false; - /** - * Resources `delete` permission. - */ - const DELETE_PERMISSION = false; - /** - * Resources `get` permission. - */ - const GET_PERMISSION = false; - /** - * Resources `update` permission. - */ - const UPDATE_PERMISSION = false; - /** - * Resources `manage` permission. - */ - const MANAGE_PERMISSION = false; - /** - * Resources `join` permission. - */ - const JOIN_PERMISSION = false; - // endregion - /** - * Grant permissions request. - * - * @internal - */ - class GrantRequest extends AbstractRequest { - constructor(parameters) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; - var _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; - super(); - this.parameters = parameters; - // Apply defaults. - (_a = (_l = this.parameters).channels) !== null && _a !== void 0 ? _a : (_l.channels = []); - (_b = (_m = this.parameters).channelGroups) !== null && _b !== void 0 ? _b : (_m.channelGroups = []); - (_c = (_o = this.parameters).uuids) !== null && _c !== void 0 ? _c : (_o.uuids = []); - (_d = (_p = this.parameters).read) !== null && _d !== void 0 ? _d : (_p.read = READ_PERMISSION); - (_e = (_q = this.parameters).write) !== null && _e !== void 0 ? _e : (_q.write = WRITE_PERMISSION); - (_f = (_r = this.parameters).delete) !== null && _f !== void 0 ? _f : (_r.delete = DELETE_PERMISSION); - (_g = (_s = this.parameters).get) !== null && _g !== void 0 ? _g : (_s.get = GET_PERMISSION); - (_h = (_t = this.parameters).update) !== null && _h !== void 0 ? _h : (_t.update = UPDATE_PERMISSION); - (_j = (_u = this.parameters).manage) !== null && _j !== void 0 ? _j : (_u.manage = MANAGE_PERMISSION); - (_k = (_v = this.parameters).join) !== null && _k !== void 0 ? _k : (_v.join = JOIN_PERMISSION); - } - operation() { - return RequestOperation$1.PNAccessManagerGrant; - } - validate() { - const { keySet: { subscribeKey, publishKey, secretKey }, uuids = [], channels = [], channelGroups = [], authKeys = [], } = this.parameters; - if (!subscribeKey) - return 'Missing Subscribe Key'; - if (!publishKey) - return 'Missing Publish Key'; - if (!secretKey) - return 'Missing Secret Key'; - if (uuids.length !== 0 && authKeys.length === 0) - return 'authKeys are required for grant request on uuids'; - if (uuids.length && (channels.length !== 0 || channelGroups.length !== 0)) - return 'Both channel/channel group and uuid cannot be used in the same request'; - } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse.payload; - }); - } - get path() { - return `/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`; - } - get queryParameters() { - const { channels, channelGroups, authKeys, uuids, read, write, manage, delete: del, get, join, update, ttl, } = this.parameters; - return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (channels && (channels === null || channels === void 0 ? void 0 : channels.length) > 0 ? { channel: channels.join(',') } : {})), (channelGroups && (channelGroups === null || channelGroups === void 0 ? void 0 : channelGroups.length) > 0 ? { 'channel-group': channelGroups.join(',') } : {})), (authKeys && (authKeys === null || authKeys === void 0 ? void 0 : authKeys.length) > 0 ? { auth: authKeys.join(',') } : {})), (uuids && (uuids === null || uuids === void 0 ? void 0 : uuids.length) > 0 ? { 'target-uuid': uuids.join(',') } : {})), { r: read ? '1' : '0', w: write ? '1' : '0', m: manage ? '1' : '0', d: del ? '1' : '0', g: get ? '1' : '0', j: join ? '1' : '0', u: update ? '1' : '0' }), (ttl || ttl === 0 ? { ttl } : {})); - } - } - - /** - * PAM Audit REST API module. - */ - // -------------------------------------------------------- - // ----------------------- Defaults ----------------------- - // -------------------------------------------------------- - // region Defaults - /** - * Auth keys for which permissions should be audited. - */ - const AUTH_KEYS = []; - // endregion - /** - * Permissions audit request. - * - * @internal - */ - class AuditRequest extends AbstractRequest { - constructor(parameters) { - var _a; - var _b; - super(); - this.parameters = parameters; - // Apply default request parameters. - (_a = (_b = this.parameters).authKeys) !== null && _a !== void 0 ? _a : (_b.authKeys = AUTH_KEYS); - } - operation() { - return RequestOperation$1.PNAccessManagerAudit; - } - validate() { - if (!this.parameters.keySet.subscribeKey) - return 'Missing Subscribe Key'; - } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse.payload; - }); - } - get path() { - return `/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`; - } - get queryParameters() { - const { channel, channelGroup, authKeys } = this.parameters; - return Object.assign(Object.assign(Object.assign({}, (channel ? { channel } : {})), (channelGroup ? { 'channel-group': channelGroup } : {})), (authKeys && authKeys.length ? { auth: authKeys.join(',') } : {})); - } - } - class SubscribeCapable { subscribe() { var _a, _b; @@ -9440,13 +9092,15 @@ this.pubnub = pubnub; } subscription(subscriptionOptions) { - return new Subscription({ - channels: [this.id], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } } } @@ -9457,13 +9111,15 @@ this.name = channelGroup; } subscription(subscriptionOptions) { - return new Subscription({ - channels: [], - channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + { + return new Subscription({ + channels: [], + channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } } } @@ -9474,13 +9130,15 @@ this.pubnub = pubnub; } subscription(subscriptionOptions) { - return new Subscription({ - channels: [this.id], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } } } @@ -9491,13 +9149,15 @@ this.name = channelName; } subscription(subscriptionOptions) { - return new Subscription({ - channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + { + return new Subscription({ + channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } } } @@ -11524,7 +11184,9 @@ * @returns Pre-formatted message payload which will trigger push notification. */ static notificationPayload(title, body) { - return new NotificationsPayload(title, body); + { + return new NotificationsPayload(title, body); + } } /** * Generate unique identifier. @@ -11545,57 +11207,65 @@ this._objects = new PubNubObjects(this._configuration, this.sendRequest.bind(this)); this._channelGroups = new PubnubChannelGroups(this._configuration.keySet, this.sendRequest.bind(this)); this._push = new PubNubPushNotifications(this._configuration.keySet, this.sendRequest.bind(this)); - // Prepare for real-time events announcement. - this.listenerManager = new ListenerManager(); - this.eventEmitter = new EventEmitter(this.listenerManager); - if (this._configuration.enableEventEngine) { - let heartbeatInterval = this._configuration.getHeartbeatInterval(); - this.presenceState = {}; - if (heartbeatInterval) { - this.presenceEventEngine = new PresenceEventEngine({ - heartbeat: this.heartbeat.bind(this), - leave: (parameters) => this.makeUnsubscribe(parameters, () => { }), - heartbeatDelay: () => new Promise((resolve, reject) => { - heartbeatInterval = this._configuration.getHeartbeatInterval(); - if (!heartbeatInterval) - reject(new PubNubError('Heartbeat interval has been reset.')); - else - setTimeout(resolve, heartbeatInterval * 1000); - }), - retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), - emitStatus: (status) => this.listenerManager.announceStatus(status), - config: this._configuration, - presenceState: this.presenceState, - }); - } - this.eventEngine = new EventEngine({ - handshake: this.subscribeHandshake.bind(this), - receiveMessages: this.subscribeReceiveMessages.bind(this), - delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), - join: this.join.bind(this), - leave: this.leave.bind(this), - leaveAll: this.leaveAll.bind(this), - presenceState: this.presenceState, - config: this._configuration, - emitMessages: (events) => { - try { - events.forEach((event) => this.eventEmitter.emitEvent(event)); - } - catch (e) { - const errorStatus = { - error: true, - category: StatusCategory$1.PNUnknownCategory, - errorData: e, - statusCode: 0, - }; - this.listenerManager.announceStatus(errorStatus); + { + // Prepare for real-time events announcement. + this.listenerManager = new ListenerManager(); + this.eventEmitter = new EventEmitter(this.listenerManager); + if (this._configuration.enableEventEngine) { + { + let heartbeatInterval = this._configuration.getHeartbeatInterval(); + this.presenceState = {}; + { + if (heartbeatInterval) { + this.presenceEventEngine = new PresenceEventEngine({ + heartbeat: this.heartbeat.bind(this), + leave: (parameters) => this.makeUnsubscribe(parameters, () => { }), + heartbeatDelay: () => new Promise((resolve, reject) => { + heartbeatInterval = this._configuration.getHeartbeatInterval(); + if (!heartbeatInterval) + reject(new PubNubError('Heartbeat interval has been reset.')); + else + setTimeout(resolve, heartbeatInterval * 1000); + }), + retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + emitStatus: (status) => this.listenerManager.announceStatus(status), + config: this._configuration, + presenceState: this.presenceState, + }); + } } - }, - emitStatus: (status) => this.listenerManager.announceStatus(status), - }); - } - else { - this.subscriptionManager = new SubscriptionManager(this._configuration, this.listenerManager, this.eventEmitter, this.makeSubscribe.bind(this), this.heartbeat.bind(this), this.makeUnsubscribe.bind(this), this.time.bind(this)); + this.eventEngine = new EventEngine({ + handshake: this.subscribeHandshake.bind(this), + receiveMessages: this.subscribeReceiveMessages.bind(this), + delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + join: this.join.bind(this), + leave: this.leave.bind(this), + leaveAll: this.leaveAll.bind(this), + presenceState: this.presenceState, + config: this._configuration, + emitMessages: (events) => { + try { + events.forEach((event) => this.eventEmitter.emitEvent(event)); + } + catch (e) { + const errorStatus = { + error: true, + category: StatusCategory$1.PNUnknownCategory, + errorData: e, + statusCode: 0, + }; + this.listenerManager.announceStatus(errorStatus); + } + }, + emitStatus: (status) => this.listenerManager.announceStatus(status), + }); + } + } + else { + { + this.subscriptionManager = new SubscriptionManager(this._configuration, this.listenerManager, this.eventEmitter, this.makeSubscribe.bind(this), this.heartbeat.bind(this), this.makeUnsubscribe.bind(this), this.time.bind(this)); + } + } } } // -------------------------------------------------------- @@ -11885,7 +11555,9 @@ * @param parameters - Subscriptions set configuration parameters. */ subscriptionSet(parameters) { - return new SubscriptionSet(Object.assign(Object.assign({}, parameters), { eventEmitter: this.eventEmitter, pubnub: this })); + { + return new SubscriptionSet(Object.assign(Object.assign({}, parameters), { eventEmitter: this.eventEmitter, pubnub: this })); + } } /** * Schedule request execution. @@ -11969,12 +11641,14 @@ * @param [isOffline] - Whether `offline` presence should be notified or not. */ destroy(isOffline) { - if (this.subscriptionManager) { - this.subscriptionManager.unsubscribeAll(isOffline); - this.subscriptionManager.disconnect(); + { + if (this.subscriptionManager) { + this.subscriptionManager.unsubscribeAll(isOffline); + this.subscriptionManager.disconnect(); + } + else if (this.eventEngine) + this.eventEngine.dispose(); } - else if (this.eventEngine) - this.eventEngine.dispose(); } /** * Unsubscribe from all channels and groups. @@ -12021,10 +11695,12 @@ */ publish(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new PublishRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new PublishRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12037,10 +11713,12 @@ */ signal(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new SignalRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new SignalRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12070,10 +11748,12 @@ * @returns List of active channels. */ getSubscribedChannels() { - if (this.subscriptionManager) - return this.subscriptionManager.subscribedChannels; - else if (this.eventEngine) - return this.eventEngine.getSubscribedChannels(); + { + if (this.subscriptionManager) + return this.subscriptionManager.subscribedChannels; + else if (this.eventEngine) + return this.eventEngine.getSubscribedChannels(); + } return []; } /** @@ -12082,10 +11762,12 @@ * @returns List of active channel groups. */ getSubscribedChannelGroups() { - if (this.subscriptionManager) - return this.subscriptionManager.subscribedChannelGroups; - else if (this.eventEngine) - return this.eventEngine.getSubscribedChannelGroups(); + { + if (this.subscriptionManager) + return this.subscriptionManager.subscribedChannelGroups; + else if (this.eventEngine) + return this.eventEngine.getSubscribedChannelGroups(); + } return []; } /** @@ -12094,10 +11776,12 @@ * @param parameters - Request configuration parameters. */ subscribe(parameters) { - if (this.subscriptionManager) - this.subscriptionManager.subscribe(parameters); - else if (this.eventEngine) - this.eventEngine.subscribe(parameters); + { + if (this.subscriptionManager) + this.subscriptionManager.subscribe(parameters); + else if (this.eventEngine) + this.eventEngine.subscribe(parameters); + } } /** * Perform subscribe request. @@ -12108,24 +11792,26 @@ * @param callback - Request completion handler callback. */ makeSubscribe(parameters, callback) { - const request = new SubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); - this.sendRequest(request, (status, result) => { - var _a; - if (this.subscriptionManager && ((_a = this.subscriptionManager.abort) === null || _a === void 0 ? void 0 : _a.identifier) === request.requestIdentifier) - this.subscriptionManager.abort = null; - callback(status, result); - }); - /** - * Allow subscription cancellation. - * - * **Note:** Had to be done after scheduling because transport provider return cancellation - * controller only when schedule new request. - */ - if (this.subscriptionManager) { - // Creating identifiable abort caller. - const callableAbort = () => request.abort(); - callableAbort.identifier = request.requestIdentifier; - this.subscriptionManager.abort = callableAbort; + { + const request = new SubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + this.sendRequest(request, (status, result) => { + var _a; + if (this.subscriptionManager && ((_a = this.subscriptionManager.abort) === null || _a === void 0 ? void 0 : _a.identifier) === request.requestIdentifier) + this.subscriptionManager.abort = null; + callback(status, result); + }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + if (this.subscriptionManager) { + // Creating identifiable abort caller. + const callableAbort = () => request.abort(); + callableAbort.identifier = request.requestIdentifier; + this.subscriptionManager.abort = callableAbort; + } } } /** @@ -12134,10 +11820,12 @@ * @param parameters - Request configuration parameters. */ unsubscribe(parameters) { - if (this.subscriptionManager) - this.subscriptionManager.unsubscribe(parameters); - else if (this.eventEngine) - this.eventEngine.unsubscribe(parameters); + { + if (this.subscriptionManager) + this.subscriptionManager.unsubscribe(parameters); + else if (this.eventEngine) + this.eventEngine.unsubscribe(parameters); + } } /** * Perform unsubscribe request. @@ -12148,25 +11836,31 @@ * @param callback - Request completion handler callback. */ makeUnsubscribe(parameters, callback) { - this.sendRequest(new PresenceLeaveRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })), callback); + { + this.sendRequest(new PresenceLeaveRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })), callback); + } } /** * Unsubscribe from all channels and groups. */ unsubscribeAll() { - if (this.subscriptionManager) - this.subscriptionManager.unsubscribeAll(); - else if (this.eventEngine) - this.eventEngine.unsubscribeAll(); + { + if (this.subscriptionManager) + this.subscriptionManager.unsubscribeAll(); + else if (this.eventEngine) + this.eventEngine.unsubscribeAll(); + } } /** * Temporarily disconnect from real-time events stream. */ disconnect() { - if (this.subscriptionManager) - this.subscriptionManager.disconnect(); - else if (this.eventEngine) - this.eventEngine.disconnect(); + { + if (this.subscriptionManager) + this.subscriptionManager.disconnect(); + else if (this.eventEngine) + this.eventEngine.disconnect(); + } } /** * Restore connection to the real-time events stream. @@ -12175,10 +11869,12 @@ * enabled event engine. */ reconnect(parameters) { - if (this.subscriptionManager) - this.subscriptionManager.reconnect(); - else if (this.eventEngine) - this.eventEngine.reconnect(parameters !== null && parameters !== void 0 ? parameters : {}); + { + if (this.subscriptionManager) + this.subscriptionManager.reconnect(); + else if (this.eventEngine) + this.eventEngine.reconnect(parameters !== null && parameters !== void 0 ? parameters : {}); + } } /** * Event engine handshake subscribe. @@ -12187,21 +11883,23 @@ */ subscribeHandshake(parameters) { return __awaiter(this, void 0, void 0, function* () { - const request = new HandshakeSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); - const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); - }); - /** - * Allow subscription cancellation. - * - * **Note:** Had to be done after scheduling because transport provider return cancellation - * controller only when schedule new request. - */ - const handshakeResponse = this.sendRequest(request); - return handshakeResponse.then((response) => { - abortUnsubscribe(); - return response.cursor; - }); + { + const request = new HandshakeSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response.cursor; + }); + } }); } /** @@ -12211,21 +11909,23 @@ */ subscribeReceiveMessages(parameters) { return __awaiter(this, void 0, void 0, function* () { - const request = new ReceiveMessagesSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); - const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); - }); - /** - * Allow subscription cancellation. - * - * **Note:** Had to be done after scheduling because transport provider return cancellation - * controller only when schedule new request. - */ - const handshakeResponse = this.sendRequest(request); - return handshakeResponse.then((response) => { - abortUnsubscribe(); - return response; - }); + { + const request = new ReceiveMessagesSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response; + }); + } }); } /** @@ -12238,10 +11938,12 @@ */ getMessageActions(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new GetMessageActionsRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new GetMessageActionsRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12254,10 +11956,12 @@ */ addMessageAction(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new AddMessageActionRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new AddMessageActionRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12270,10 +11974,12 @@ */ removeMessageAction(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new RemoveMessageAction(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new RemoveMessageAction(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12286,10 +11992,12 @@ */ fetchMessages(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new FetchMessagesRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new FetchMessagesRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12304,10 +12012,12 @@ */ deleteMessages(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new DeleteMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new DeleteMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12320,10 +12030,12 @@ */ messageCounts(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new MessageCountRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new MessageCountRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12338,10 +12050,12 @@ */ history(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new GetHistoryRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new GetHistoryRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12354,10 +12068,12 @@ */ hereNow(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new HereNowRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new HereNowRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12373,13 +12089,15 @@ whereNow(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; - const request = new WhereNowRequest({ - uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, - keySet: this._configuration.keySet, - }); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new WhereNowRequest({ + uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, + keySet: this._configuration.keySet, + }); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12393,10 +12111,12 @@ getState(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; - const request = new GetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new GetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12410,30 +12130,32 @@ setState(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; - const { keySet, userId: userId } = this._configuration; - const heartbeat = this._configuration.getPresenceTimeout(); - let request; - // Maintain presence information (if required). - if (this._configuration.enableEventEngine && this.presenceState) { - const presenceState = this.presenceState; - (_a = parameters.channels) === null || _a === void 0 ? void 0 : _a.forEach((channel) => (presenceState[channel] = parameters.state)); - if ('channelGroups' in parameters) { - (_b = parameters.channelGroups) === null || _b === void 0 ? void 0 : _b.forEach((group) => (presenceState[group] = parameters.state)); + { + const { keySet, userId: userId } = this._configuration; + const heartbeat = this._configuration.getPresenceTimeout(); + let request; + // Maintain presence information (if required). + if (this._configuration.enableEventEngine && this.presenceState) { + const presenceState = this.presenceState; + (_a = parameters.channels) === null || _a === void 0 ? void 0 : _a.forEach((channel) => (presenceState[channel] = parameters.state)); + if ('channelGroups' in parameters) { + (_b = parameters.channelGroups) === null || _b === void 0 ? void 0 : _b.forEach((group) => (presenceState[group] = parameters.state)); + } } + // Check whether state should be set with heartbeat or not. + if ('withHeartbeat' in parameters) { + request = new HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet, heartbeat })); + } + else { + request = new SetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { keySet, uuid: userId })); + } + // Update state used by subscription manager. + if (this.subscriptionManager) + this.subscriptionManager.setState(parameters); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); } - // Check whether state should be set with heartbeat or not. - if ('withHeartbeat' in parameters) { - request = new HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet, heartbeat })); - } - else { - request = new SetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { keySet, uuid: userId })); - } - // Update state used by subscription manager. - if (this.subscriptionManager) - this.subscriptionManager.setState(parameters); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); }); } // endregion @@ -12457,10 +12179,12 @@ */ heartbeat(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } // endregion @@ -12504,10 +12228,7 @@ */ grantToken(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new GrantTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + throw new Error('Grant Token error: PAM module disabled'); }); } /** @@ -12520,10 +12241,7 @@ */ revokeToken(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new RevokeTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + throw new Error('Revoke Token error: PAM module disabled'); }); } // endregion @@ -12534,7 +12252,7 @@ * @returns Previously configured access token using {@link setToken} method. */ get token() { - return this.tokenManager.getToken(); + return this.tokenManager && this.tokenManager.getToken(); } /** * Get current access token. @@ -12550,7 +12268,8 @@ * @param token - New access token which should be used with next REST API endpoint calls. */ set token(token) { - this.tokenManager.setToken(token); + if (this.tokenManager) + this.tokenManager.setToken(token); } /** * Set current access token. @@ -12570,7 +12289,7 @@ * @returns Token's permissions information for the resources. */ parseToken(token) { - return this.tokenManager.parseToken(token); + return this.tokenManager && this.tokenManager.parseToken(token); } /** * Grant auth key(s) permission. @@ -12584,10 +12303,7 @@ */ grant(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new GrantRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + throw new Error('Grant error: PAM module disabled'); }); } /** @@ -12602,10 +12318,7 @@ */ audit(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new AuditRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + throw new Error('Grant Permissions error: PAM module disabled'); }); } // endregion @@ -12841,26 +12554,28 @@ removeMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; - if ('spaceId' in parameters) { - const spaceParameters = parameters; + { + if ('spaceId' in parameters) { + const spaceParameters = parameters; + const requestParameters = { + channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, + uuids: (_b = spaceParameters.userIds) !== null && _b !== void 0 ? _b : spaceParameters.uuids, + limit: 0, + }; + if (callback) + return this.objects.removeChannelMembers(requestParameters, callback); + return this.objects.removeChannelMembers(requestParameters); + } + const userParameters = parameters; const requestParameters = { - channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, - uuids: (_b = spaceParameters.userIds) !== null && _b !== void 0 ? _b : spaceParameters.uuids, + uuid: userParameters.userId, + channels: (_c = userParameters.spaceIds) !== null && _c !== void 0 ? _c : userParameters.channels, limit: 0, }; if (callback) - return this.objects.removeChannelMembers(requestParameters, callback); - return this.objects.removeChannelMembers(requestParameters); + return this.objects.removeMemberships(requestParameters, callback); + return this.objects.removeMemberships(requestParameters); } - const userParameters = parameters; - const requestParameters = { - uuid: userParameters.userId, - channels: (_c = userParameters.spaceIds) !== null && _c !== void 0 ? _c : userParameters.channels, - limit: 0, - }; - if (callback) - return this.objects.removeMemberships(requestParameters, callback); - return this.objects.removeMemberships(requestParameters); }); } // endregion @@ -12896,34 +12611,36 @@ */ sendFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - if (!this._configuration.PubNubFile) - throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - const sendFileRequest = new SendFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, fileUploadPublishRetryLimit: this._configuration.fileUploadPublishRetryLimit, file: parameters.file, sendRequest: this.sendRequest.bind(this), publishFile: this.publishFile.bind(this), crypto: this._configuration.getCryptoModule(), cryptography: this.cryptography ? this.cryptography : undefined })); - const status = { - error: false, - operation: RequestOperation$1.PNPublishFileOperation, - category: StatusCategory$1.PNAcknowledgmentCategory, - statusCode: 0, - }; - return sendFileRequest - .process() - .then((response) => { - status.statusCode = response.status; - if (callback) - return callback(status, response); - return response; - }) - .catch((error) => { - let errorStatus; - if (error instanceof PubNubError) - errorStatus = error.status; - else if (error instanceof PubNubAPIError) - errorStatus = error.toStatus(status.operation); - // Notify callback (if possible). - if (callback && errorStatus) - callback(errorStatus, null); - throw new PubNubError('REST API request processing error, check status for details', errorStatus); - }); + { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const sendFileRequest = new SendFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, fileUploadPublishRetryLimit: this._configuration.fileUploadPublishRetryLimit, file: parameters.file, sendRequest: this.sendRequest.bind(this), publishFile: this.publishFile.bind(this), crypto: this._configuration.getCryptoModule(), cryptography: this.cryptography ? this.cryptography : undefined })); + const status = { + error: false, + operation: RequestOperation$1.PNPublishFileOperation, + category: StatusCategory$1.PNAcknowledgmentCategory, + statusCode: 0, + }; + return sendFileRequest + .process() + .then((response) => { + status.statusCode = response.status; + if (callback) + return callback(status, response); + return response; + }) + .catch((error) => { + let errorStatus; + if (error instanceof PubNubError) + errorStatus = error.status; + else if (error instanceof PubNubAPIError) + errorStatus = error.toStatus(status.operation); + // Notify callback (if possible). + if (callback && errorStatus) + callback(errorStatus, null); + throw new PubNubError('REST API request processing error, check status for details', errorStatus); + }); + } }); } /** @@ -12936,12 +12653,14 @@ */ publishFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - if (!this._configuration.PubNubFile) - throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - const request = new PublishFileMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const request = new PublishFileMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -12954,10 +12673,12 @@ */ listFiles(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new FilesListRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new FilesListRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } // endregion @@ -12971,17 +12692,19 @@ */ getFileUrl(parameters) { var _a; - const request = this.transport.request(new GetFileDownloadUrlRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })).request()); - const query = (_a = request.queryParameters) !== null && _a !== void 0 ? _a : {}; - const queryString = Object.keys(query) - .map((key) => { - const queryValue = query[key]; - if (!Array.isArray(queryValue)) - return `${key}=${encodeString(queryValue)}`; - return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); - }) - .join('&'); - return `${request.origin}${request.path}?${queryString}`; + { + const request = this.transport.request(new GetFileDownloadUrlRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })).request()); + const query = (_a = request.queryParameters) !== null && _a !== void 0 ? _a : {}; + const queryString = Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${encodeString(queryValue)}`; + return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); + }) + .join('&'); + return `${request.origin}${request.path}?${queryString}`; + } } /** * Download shared file from specific channel. @@ -12993,12 +12716,14 @@ */ downloadFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - if (!this._configuration.PubNubFile) - throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - const request = new DownloadFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, cryptography: this.cryptography ? this.cryptography : undefined, crypto: this._configuration.getCryptoModule() })); - if (callback) - return this.sendRequest(request, callback); - return (yield this.sendRequest(request)); + { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const request = new DownloadFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, cryptography: this.cryptography ? this.cryptography : undefined, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return (yield this.sendRequest(request)); + } }); } /** @@ -13011,10 +12736,12 @@ */ deleteFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new DeleteFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + { + const request = new DeleteFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } }); } /** @@ -13056,7 +12783,9 @@ } if (!this.crypto) throw new Error('Encryption error: cypher key not set'); - return this.crypto.encrypt(data, customCipherKey); + { + return this.crypto.encrypt(data, customCipherKey); + } } /** * Decrypt data. @@ -13075,7 +12804,9 @@ } if (!this.crypto) throw new Error('Decryption error: cypher key not set'); - return this.crypto.decrypt(data, customCipherKey); + { + return this.crypto.decrypt(data, customCipherKey); + } } /** * Encrypt file content. @@ -13210,43 +12941,55 @@ constructor(configuration) { var _a; const configurationCopy = setDefaults(configuration); - const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'Web', PubNubFile }); + const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'Web' }); + platformConfiguration.PubNubFile = PubNubFile; // Prepare full client configuration. const clientConfiguration = makeConfiguration(platformConfiguration, (cryptoConfiguration) => { if (!cryptoConfiguration.cipherKey) return undefined; - return new WebCryptoModule({ - default: new LegacyCryptor(Object.assign({}, cryptoConfiguration)), - cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], - }); + { + return new WebCryptoModule({ + default: new LegacyCryptor(Object.assign({}, cryptoConfiguration)), + cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], + }); + } }); // Prepare Token manager. - const tokenManager = new TokenManager(new Cbor((arrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode)); + let tokenManager; + { + tokenManager = new TokenManager(new Cbor((arrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode)); + } // Legacy crypto (legacy data encryption / decryption and request signature support). let crypto; - if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { - crypto = new Crypto({ - secretKey: clientConfiguration.secretKey, - cipherKey: clientConfiguration.getCipherKey(), - useRandomIVs: clientConfiguration.getUseRandomIVs(), - customEncrypt: clientConfiguration.getCustomEncrypt(), - customDecrypt: clientConfiguration.getCustomDecrypt(), - }); + { + if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { + crypto = new Crypto({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } } + let cryptography; + cryptography = new WebCryptography(); // Setup transport provider. let transport = new WebReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity); - if (configurationCopy.subscriptionWorkerUrl) { - // Inject subscription worker into transport provider stack. - transport = new SubscriptionWorkerMiddleware({ - clientIdentifier: clientConfiguration._instanceId, - subscriptionKey: clientConfiguration.subscribeKey, - userId: clientConfiguration.getUserId(), - workerUrl: configurationCopy.subscriptionWorkerUrl, - sdkVersion: clientConfiguration.getVersion(), - logVerbosity: clientConfiguration.logVerbosity, - workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity, - transport, - }); + { + if (configurationCopy.subscriptionWorkerUrl) { + // Inject subscription worker into transport provider stack. + transport = new SubscriptionWorkerMiddleware({ + clientIdentifier: clientConfiguration._instanceId, + subscriptionKey: clientConfiguration.subscribeKey, + userId: clientConfiguration.getUserId(), + workerUrl: configurationCopy.subscriptionWorkerUrl, + sdkVersion: clientConfiguration.getVersion(), + logVerbosity: clientConfiguration.logVerbosity, + workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity, + transport, + }); + } } const transportMiddleware = new PubNubMiddleware({ clientConfiguration, @@ -13256,7 +12999,7 @@ super({ configuration: clientConfiguration, transport: transportMiddleware, - cryptography: new WebCryptography(), + cryptography, tokenManager, crypto, }); @@ -13284,7 +13027,8 @@ /** * Data encryption / decryption module constructor. */ - PubNub.CryptoModule = WebCryptoModule; + // @ts-expect-error Allowed to simplify interface when module can be disabled. + PubNub.CryptoModule = WebCryptoModule ; return PubNub; diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index c8962dd2c..59c290431 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.restore)&&void 0!==i||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(a=m.suppressLeaveEvents)&&void 0!==a||(m.suppressLeaveEvents=!1),null!==(c=m.requestMessageCountThreshold)&&void 0!==c||(m.requestMessageCountThreshold=100),null!==(u=m.autoNetworkDetection)&&void 0!==u||(m.autoNetworkDetection=!1),null!==(l=m.enableEventEngine)&&void 0!==l||(m.enableEventEngine=!1),null!==(h=m.maintainPresenceState)&&void 0!==h||(m.maintainPresenceState=!0),null!==(p=m.keepAlive)&&void 0!==p||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=m.userId)&&void 0!==g||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=m.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),null!==(f=m.presenceTimeout)&&void 0!==f||(m.presenceTimeout=300);let v=!1,w=!0,S=5,k=!1,E=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(E=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:100,useRequestId:E,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var K={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(K,K.exports);var q=t(K.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.1.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),je=pe("TIMES_UP",(()=>({}))),_e=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(_e.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ae.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(je())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ge.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(je.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ke=new le("HEARBEAT_RECONNECTING");Ke.onEnter((e=>Ue(e))),Ke.onExit((()=>Ue.cancel)),Ke.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Ke.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),Ke.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ke.on(Pe.type,((e,t)=>Ke.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ke.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new le("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Ce.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new le("HEARTBEAT_INACTIVE");Ge.on(Ee.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get headers(){return{"Content-Type":"application/json"}}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get body(){return JSON.stringify(this.parameters.action)}}class Kt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNAccessManagerRevokeToken}validate(){return this.parameters.keySet.secretKey?this.parameters.token?void 0:"token can't be empty":"Missing Secret Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},token:t}=this.parameters;return`/v3/pam/${e}/grant/${I(t)}`}}class Wt extends se{constructor(e){var t,s,n,r;super({method:H.POST}),this.parameters=e,null!==(t=(n=this.parameters).resources)&&void 0!==t||(n.resources={}),null!==(s=(r=this.parameters).patterns)&&void 0!==s||(r.patterns={})}operation(){return re.PNAccessManagerGrantToken}validate(){var e,t,s,n,r,i;const{keySet:{subscribeKey:o,publishKey:a,secretKey:c},resources:u,patterns:l}=this.parameters;if(!o)return"Missing Subscribe Key";if(!a)return"Missing Publish Key";if(!c)return"Missing Secret Key";if(!u&&!l)return"Missing either Resources or Patterns";if(this.isVspPermissions(this.parameters)&&("channels"in(null!==(e=this.parameters.resources)&&void 0!==e?e:{})||"uuids"in(null!==(t=this.parameters.resources)&&void 0!==t?t:{})||"groups"in(null!==(s=this.parameters.resources)&&void 0!==s?s:{})||"channels"in(null!==(n=this.parameters.patterns)&&void 0!==n?n:{})||"uuids"in(null!==(r=this.parameters.patterns)&&void 0!==r?r:{})||"groups"in(null!==(i=this.parameters.patterns)&&void 0!==i?i:{})))return"Cannot mix `users`, `spaces` and `authorizedUserId` with `uuids`, `channels`, `groups` and `authorized_uuid`";let h=!0;return[this.parameters.resources,this.parameters.patterns].forEach((e=>{Object.keys(null!=e?e:{}).forEach((t=>{var s;e&&h&&Object.keys(null!==(s=e[t])&&void 0!==s?s:{}).length>0&&(h=!1)}))})),h?"Missing values for either Resources or Patterns":void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.data.token}))}get path(){return`/v3/pam/${this.parameters.keySet.subscribeKey}/grant`}get body(){const{ttl:e,meta:t}=this.parameters,s=Object.assign({},e||0===e?{ttl:e}:{}),n=this.isVspPermissions(this.parameters)?this.parameters.authorizedUserId:this.parameters.authorized_uuid,r={},i={},o={},a=(e,t,s,n)=>{n[s]||(n[s]={}),n[s][e]=t},{resources:c,patterns:u}=this.parameters;return[c,u].forEach(((e,t)=>{var s,n,r,c,u;const l=0===t?i:o;let h={},d={},p={};l.channels||(l.channels={}),l.groups||(l.groups={}),l.uuids||(l.uuids={}),l.users||(l.users={}),l.spaces||(l.spaces={}),e&&("spaces"in e||"users"in e?(h=null!==(s=e.spaces)&&void 0!==s?s:{},p=null!==(n=e.users)&&void 0!==n?n:{}):("channels"in e||"uuids"in e||"groups"in e)&&(h=null!==(r=e.channels)&&void 0!==r?r:{},d=null!==(c=e.groups)&&void 0!==c?c:{},p=null!==(u=e.uuids)&&void 0!==u?u:{})),Object.keys(h).forEach((e=>a(e,this.extractPermissions(h[e]),"channels",l))),Object.keys(d).forEach((e=>a(e,this.extractPermissions(d[e]),"groups",l))),Object.keys(p).forEach((e=>a(e,this.extractPermissions(p[e]),"uuids",l)))})),n&&(r.uuid=`${n}`),r.resources=i,r.patterns=o,r.meta=null!=t?t:{},s.permissions=r,JSON.stringify(s)}extractPermissions(e){let t=0;return"join"in e&&e.join&&(t|=128),"update"in e&&e.update&&(t|=64),"get"in e&&e.get&&(t|=32),"delete"in e&&e.delete&&(t|=8),"manage"in e&&e.manage&&(t|=4),"write"in e&&e.write&&(t|=2),"read"in e&&e.read&&(t|=1),t}isVspPermissions(e){var t,s,n,r;return"authorizedUserId"in e||"spaces"in(null!==(t=e.resources)&&void 0!==t?t:{})||"users"in(null!==(s=e.resources)&&void 0!==s?s:{})||"spaces"in(null!==(n=e.patterns)&&void 0!==n?n:{})||"users"in(null!==(r=e.patterns)&&void 0!==r?r:{})}}class Jt extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b,v,w;super(),this.parameters=e,null!==(t=(h=this.parameters).channels)&&void 0!==t||(h.channels=[]),null!==(s=(d=this.parameters).channelGroups)&&void 0!==s||(d.channelGroups=[]),null!==(n=(p=this.parameters).uuids)&&void 0!==n||(p.uuids=[]),null!==(r=(g=this.parameters).read)&&void 0!==r||(g.read=false),null!==(i=(y=this.parameters).write)&&void 0!==i||(y.write=false),null!==(o=(f=this.parameters).delete)&&void 0!==o||(f.delete=false),null!==(a=(m=this.parameters).get)&&void 0!==a||(m.get=false),null!==(c=(b=this.parameters).update)&&void 0!==c||(b.update=false),null!==(u=(v=this.parameters).manage)&&void 0!==u||(v.manage=false),null!==(l=(w=this.parameters).join)&&void 0!==l||(w.join=false)}operation(){return re.PNAccessManagerGrant}validate(){const{keySet:{subscribeKey:e,publishKey:t,secretKey:s},uuids:n=[],channels:r=[],channelGroups:i=[],authKeys:o=[]}=this.parameters;return e?t?s?0!==n.length&&0===o.length?"authKeys are required for grant request on uuids":!n.length||0===r.length&&0===i.length?void 0:"Both channel/channel group and uuid cannot be used in the same request":"Missing Secret Key":"Missing Publish Key":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload}))}get path(){return`/v2/auth/grant/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channels:e,channelGroups:t,authKeys:s,uuids:n,read:r,write:i,manage:o,delete:a,get:c,join:u,update:l,ttl:h}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({},e&&(null==e?void 0:e.length)>0?{channel:e.join(",")}:{}),t&&(null==t?void 0:t.length)>0?{"channel-group":t.join(",")}:{}),s&&(null==s?void 0:s.length)>0?{auth:s.join(",")}:{}),n&&(null==n?void 0:n.length)>0?{"target-uuid":n.join(",")}:{}),{r:r?"1":"0",w:i?"1":"0",m:o?"1":"0",d:a?"1":"0",g:c?"1":"0",j:u?"1":"0",u:l?"1":"0"}),h||0===h?{ttl:h}:{})}}const Qt=[];class Yt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).authKeys)&&void 0!==t||(s.authKeys=Qt)}operation(){return re.PNAccessManagerAudit}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload}))}get path(){return`/v2/auth/audit/sub-key/${this.parameters.keySet.subscribeKey}`}get queryParameters(){const{channel:e,channelGroup:t,authKeys:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},e?{channel:e}:{}),t?{"channel-group":t}:{}),s&&s.length?{auth:s.join(",")}:{})}}class Xt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Zt extends Xt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class es extends Xt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Zt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ts{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new es({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ss{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new es({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class ns{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new es({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class rs{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new es({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class is extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class os extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class as extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class cs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class us extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class ls{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new us({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new is(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class ds extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ps extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class gs extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ys extends hs{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class fs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new gs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ys(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ms extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class Cs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ns extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ps extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Ms extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class js{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new Ss(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Os(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ms(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ns(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class _s extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class As extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Is{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new js(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new fs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new rs(e,this.eventEmitter,this)}channelGroup(e){return new ss(e,this.eventEmitter,this)}channelMetadata(e){return new ts(e,this.eventEmitter,this)}userMetadata(e){return new ns(e,this.eventEmitter,this)}subscriptionSet(e){return new Zt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Is.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}signal(e,t){return i(this,void 0,void 0,(function*(){const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}history(e,t){return i(this,void 0,void 0,(function*(){const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){const s=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){const s=new Vt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get token(){return this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){const s=new Jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}audit(e,t){return i(this,void 0,void 0,(function*(){const s=new Yt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getFileUrl(e){var t;const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}downloadFile(e,t){return i(this,void 0,void 0,(function*(){if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new As(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}time(e){return i(this,void 0,void 0,(function*(){const t=new _s;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Is.decoder=new TextDecoder,Is.OPERATIONS=re,Is.CATEGORIES=h,Is.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Is.LinearRetryPolicy=Le.LinearRetryPolicy;class Rs{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Us extends Is{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web",PubNubFile:a}),i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})})),o=new B(new Rs((e=>x(n.decode(e))),c));let u;(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()}));let l=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(l=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:l}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:l}),cryptography:new C,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Us.CryptoModule=P,Us})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.restore)&&void 0!==i||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(a=m.suppressLeaveEvents)&&void 0!==a||(m.suppressLeaveEvents=!1),null!==(c=m.requestMessageCountThreshold)&&void 0!==c||(m.requestMessageCountThreshold=100),null!==(u=m.autoNetworkDetection)&&void 0!==u||(m.autoNetworkDetection=!1),null!==(l=m.enableEventEngine)&&void 0!==l||(m.enableEventEngine=!1),null!==(h=m.maintainPresenceState)&&void 0!==h||(m.maintainPresenceState=!0),null!==(p=m.keepAlive)&&void 0!==p||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=m.userId)&&void 0!==g||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=m.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),null!==(f=m.presenceTimeout)&&void 0!==f||(m.presenceTimeout=300);let v=!1,w=!0,S=5,k=!1,E=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(E=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:100,useRequestId:E,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index ef07c7b3a..7d1957fb2 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.1.0'; + return '8.2.0'; }, getVersion() { return this.version; diff --git a/lib/core/endpoints/access_manager/grant_token.js b/lib/core/endpoints/access_manager/grant_token.js index 0eb0cc788..8ed978a6d 100644 --- a/lib/core/endpoints/access_manager/grant_token.js +++ b/lib/core/endpoints/access_manager/grant_token.js @@ -87,6 +87,9 @@ class GrantTokenRequest extends request_1.AbstractRequest { get path() { return `/v3/pam/${this.parameters.keySet.subscribeKey}/grant`; } + get headers() { + return { 'Content-Type': 'application/json' }; + } get body() { const { ttl, meta } = this.parameters; const body = Object.assign({}, (ttl || ttl === 0 ? { ttl } : {})); diff --git a/lib/core/endpoints/actions/add_message_action.js b/lib/core/endpoints/actions/add_message_action.js index a44be3601..6003a9d7f 100644 --- a/lib/core/endpoints/actions/add_message_action.js +++ b/lib/core/endpoints/actions/add_message_action.js @@ -64,13 +64,13 @@ class AddMessageActionRequest extends request_1.AbstractRequest { return { data: serviceResponse.data }; }); } - get headers() { - return { 'Content-Type': 'application/json' }; - } get path() { const { keySet: { subscribeKey }, channel, messageTimetoken, } = this.parameters; return `/v1/message-actions/${subscribeKey}/channel/${(0, utils_1.encodeString)(channel)}/message/${messageTimetoken}`; } + get headers() { + return { 'Content-Type': 'application/json' }; + } get body() { return JSON.stringify(this.parameters.action); } diff --git a/lib/core/endpoints/file_upload/generate_upload_url.js b/lib/core/endpoints/file_upload/generate_upload_url.js index 9a107a47d..3a1756610 100644 --- a/lib/core/endpoints/file_upload/generate_upload_url.js +++ b/lib/core/endpoints/file_upload/generate_upload_url.js @@ -62,6 +62,9 @@ class GenerateFileUploadUrlRequest extends request_1.AbstractRequest { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v1/files/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/generate-upload-url`; } + get headers() { + return { 'Content-Type': 'application/json' }; + } get body() { return JSON.stringify({ name: this.parameters.name }); } diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index ae929ffc9..126b2233d 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -128,7 +128,11 @@ class PubNubCore { * @returns Pre-formatted message payload which will trigger push notification. */ static notificationPayload(title, body) { - return new push_payload_1.default(title, body); + if (process.env.PUBLISH_MODULE !== 'disabled') { + return new push_payload_1.default(title, body); + } + else + throw new Error('Notification Payload error: publish module disabled'); } /** * Generate unique identifier. @@ -146,60 +150,75 @@ class PubNubCore { this.transport = configuration.transport; this.crypto = configuration.crypto; // API group entry points initialization. - this._objects = new pubnub_objects_1.default(this._configuration, this.sendRequest.bind(this)); - this._channelGroups = new pubnub_channel_groups_1.default(this._configuration.keySet, this.sendRequest.bind(this)); - this._push = new pubnub_push_1.default(this._configuration.keySet, this.sendRequest.bind(this)); - // Prepare for real-time events announcement. - this.listenerManager = new listener_manager_1.ListenerManager(); - this.eventEmitter = new eventEmitter_1.default(this.listenerManager); - if (this._configuration.enableEventEngine) { - let heartbeatInterval = this._configuration.getHeartbeatInterval(); - this.presenceState = {}; - if (heartbeatInterval) { - this.presenceEventEngine = new presence_1.PresenceEventEngine({ - heartbeat: this.heartbeat.bind(this), - leave: (parameters) => this.makeUnsubscribe(parameters, () => { }), - heartbeatDelay: () => new Promise((resolve, reject) => { - heartbeatInterval = this._configuration.getHeartbeatInterval(); - if (!heartbeatInterval) - reject(new pubnub_error_1.PubNubError('Heartbeat interval has been reset.')); - else - setTimeout(resolve, heartbeatInterval * 1000); - }), - retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), - emitStatus: (status) => this.listenerManager.announceStatus(status), - config: this._configuration, - presenceState: this.presenceState, - }); - } - this.eventEngine = new event_engine_1.EventEngine({ - handshake: this.subscribeHandshake.bind(this), - receiveMessages: this.subscribeReceiveMessages.bind(this), - delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), - join: this.join.bind(this), - leave: this.leave.bind(this), - leaveAll: this.leaveAll.bind(this), - presenceState: this.presenceState, - config: this._configuration, - emitMessages: (events) => { - try { - events.forEach((event) => this.eventEmitter.emitEvent(event)); - } - catch (e) { - const errorStatus = { - error: true, - category: categories_1.default.PNUnknownCategory, - errorData: e, - statusCode: 0, - }; - this.listenerManager.announceStatus(errorStatus); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + this._objects = new pubnub_objects_1.default(this._configuration, this.sendRequest.bind(this)); + if (process.env.CHANNEL_GROUPS_MODULE !== 'disabled') + this._channelGroups = new pubnub_channel_groups_1.default(this._configuration.keySet, this.sendRequest.bind(this)); + if (process.env.MOBILE_PUSH_MODULE !== 'disabled') + this._push = new pubnub_push_1.default(this._configuration.keySet, this.sendRequest.bind(this)); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + // Prepare for real-time events announcement. + this.listenerManager = new listener_manager_1.ListenerManager(); + this.eventEmitter = new eventEmitter_1.default(this.listenerManager); + if (this._configuration.enableEventEngine) { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + let heartbeatInterval = this._configuration.getHeartbeatInterval(); + this.presenceState = {}; + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (heartbeatInterval) { + this.presenceEventEngine = new presence_1.PresenceEventEngine({ + heartbeat: this.heartbeat.bind(this), + leave: (parameters) => this.makeUnsubscribe(parameters, () => { }), + heartbeatDelay: () => new Promise((resolve, reject) => { + heartbeatInterval = this._configuration.getHeartbeatInterval(); + if (!heartbeatInterval) + reject(new pubnub_error_1.PubNubError('Heartbeat interval has been reset.')); + else + setTimeout(resolve, heartbeatInterval * 1000); + }), + retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + emitStatus: (status) => this.listenerManager.announceStatus(status), + config: this._configuration, + presenceState: this.presenceState, + }); + } } - }, - emitStatus: (status) => this.listenerManager.announceStatus(status), - }); - } - else { - this.subscriptionManager = new subscription_manager_1.SubscriptionManager(this._configuration, this.listenerManager, this.eventEmitter, this.makeSubscribe.bind(this), this.heartbeat.bind(this), this.makeUnsubscribe.bind(this), this.time.bind(this)); + this.eventEngine = new event_engine_1.EventEngine({ + handshake: this.subscribeHandshake.bind(this), + receiveMessages: this.subscribeReceiveMessages.bind(this), + delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + join: this.join.bind(this), + leave: this.leave.bind(this), + leaveAll: this.leaveAll.bind(this), + presenceState: this.presenceState, + config: this._configuration, + emitMessages: (events) => { + try { + events.forEach((event) => this.eventEmitter.emitEvent(event)); + } + catch (e) { + const errorStatus = { + error: true, + category: categories_1.default.PNUnknownCategory, + errorData: e, + statusCode: 0, + }; + this.listenerManager.announceStatus(errorStatus); + } + }, + emitStatus: (status) => this.listenerManager.announceStatus(status), + }); + } + else + throw new Error('Event Engine error: subscription event engine module disabled'); + } + else { + if (process.env.SUBSCRIBE_MANAGER_MODULE !== 'disabled') { + this.subscriptionManager = new subscription_manager_1.SubscriptionManager(this._configuration, this.listenerManager, this.eventEmitter, this.makeSubscribe.bind(this), this.heartbeat.bind(this), this.makeUnsubscribe.bind(this), this.time.bind(this)); + } + else + throw new Error('Subscription Manager error: subscription manager module disabled'); + } } } // -------------------------------------------------------- @@ -489,7 +508,11 @@ class PubNubCore { * @param parameters - Subscriptions set configuration parameters. */ subscriptionSet(parameters) { - return new SubscriptionSet_1.SubscriptionSet(Object.assign(Object.assign({}, parameters), { eventEmitter: this.eventEmitter, pubnub: this })); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new SubscriptionSet_1.SubscriptionSet(Object.assign(Object.assign({}, parameters), { eventEmitter: this.eventEmitter, pubnub: this })); + } + else + throw new Error('Subscription error: subscription event engine module disabled'); } /** * Schedule request execution. @@ -573,12 +596,14 @@ class PubNubCore { * @param [isOffline] - Whether `offline` presence should be notified or not. */ destroy(isOffline) { - if (this.subscriptionManager) { - this.subscriptionManager.unsubscribeAll(isOffline); - this.subscriptionManager.disconnect(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) { + this.subscriptionManager.unsubscribeAll(isOffline); + this.subscriptionManager.disconnect(); + } + else if (this.eventEngine) + this.eventEngine.dispose(); } - else if (this.eventEngine) - this.eventEngine.dispose(); } /** * Unsubscribe from all channels and groups. @@ -599,7 +624,10 @@ class PubNubCore { * @param listener - Listener with event callbacks to handle different types of events. */ addListener(listener) { - this.listenerManager.addListener(listener); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') + this.listenerManager.addListener(listener); + else + throw new Error('Subscription error: subscription module disabled'); } /** * Remove real-time event listener. @@ -607,13 +635,19 @@ class PubNubCore { * @param listener - Event listeners which should be removed. */ removeListener(listener) { - this.listenerManager.removeListener(listener); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') + this.listenerManager.removeListener(listener); + else + throw new Error('Subscription error: subscription module disabled'); } /** * Clear all real-time event listeners. */ removeAllListeners() { - this.listenerManager.removeAllListeners(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') + this.listenerManager.removeAllListeners(); + else + throw new Error('Subscription error: subscription module disabled'); } /** * Publish data to a specific channel. @@ -625,10 +659,14 @@ class PubNubCore { */ publish(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new Publish.PublishRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PUBLISH_MODULE !== 'disabled') { + const request = new Publish.PublishRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Publish error: publish module disabled'); }); } /** @@ -641,10 +679,14 @@ class PubNubCore { */ signal(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new Signal.SignalRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PUBLISH_MODULE !== 'disabled') { + const request = new Signal.SignalRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Publish error: publish module disabled'); }); } /** @@ -674,10 +716,14 @@ class PubNubCore { * @returns List of active channels. */ getSubscribedChannels() { - if (this.subscriptionManager) - return this.subscriptionManager.subscribedChannels; - else if (this.eventEngine) - return this.eventEngine.getSubscribedChannels(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) + return this.subscriptionManager.subscribedChannels; + else if (this.eventEngine) + return this.eventEngine.getSubscribedChannels(); + } + else + throw new Error('Subscription error: subscription module disabled'); return []; } /** @@ -686,10 +732,14 @@ class PubNubCore { * @returns List of active channel groups. */ getSubscribedChannelGroups() { - if (this.subscriptionManager) - return this.subscriptionManager.subscribedChannelGroups; - else if (this.eventEngine) - return this.eventEngine.getSubscribedChannelGroups(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) + return this.subscriptionManager.subscribedChannelGroups; + else if (this.eventEngine) + return this.eventEngine.getSubscribedChannelGroups(); + } + else + throw new Error('Subscription error: subscription module disabled'); return []; } /** @@ -698,10 +748,14 @@ class PubNubCore { * @param parameters - Request configuration parameters. */ subscribe(parameters) { - if (this.subscriptionManager) - this.subscriptionManager.subscribe(parameters); - else if (this.eventEngine) - this.eventEngine.subscribe(parameters); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) + this.subscriptionManager.subscribe(parameters); + else if (this.eventEngine) + this.eventEngine.subscribe(parameters); + } + else + throw new Error('Subscription error: subscription module disabled'); } /** * Perform subscribe request. @@ -712,25 +766,29 @@ class PubNubCore { * @param callback - Request completion handler callback. */ makeSubscribe(parameters, callback) { - const request = new subscribe_1.SubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); - this.sendRequest(request, (status, result) => { - var _a; - if (this.subscriptionManager && ((_a = this.subscriptionManager.abort) === null || _a === void 0 ? void 0 : _a.identifier) === request.requestIdentifier) - this.subscriptionManager.abort = null; - callback(status, result); - }); - /** - * Allow subscription cancellation. - * - * **Note:** Had to be done after scheduling because transport provider return cancellation - * controller only when schedule new request. - */ - if (this.subscriptionManager) { - // Creating identifiable abort caller. - const callableAbort = () => request.abort(); - callableAbort.identifier = request.requestIdentifier; - this.subscriptionManager.abort = callableAbort; + if (process.env.SUBSCRIBE_MANAGER_MODULE !== 'disabled') { + const request = new subscribe_1.SubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + this.sendRequest(request, (status, result) => { + var _a; + if (this.subscriptionManager && ((_a = this.subscriptionManager.abort) === null || _a === void 0 ? void 0 : _a.identifier) === request.requestIdentifier) + this.subscriptionManager.abort = null; + callback(status, result); + }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + if (this.subscriptionManager) { + // Creating identifiable abort caller. + const callableAbort = () => request.abort(); + callableAbort.identifier = request.requestIdentifier; + this.subscriptionManager.abort = callableAbort; + } } + else + throw new Error('Subscription error: subscription manager module disabled'); } /** * Unsubscribe from specified channels and groups real-time events. @@ -738,10 +796,14 @@ class PubNubCore { * @param parameters - Request configuration parameters. */ unsubscribe(parameters) { - if (this.subscriptionManager) - this.subscriptionManager.unsubscribe(parameters); - else if (this.eventEngine) - this.eventEngine.unsubscribe(parameters); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) + this.subscriptionManager.unsubscribe(parameters); + else if (this.eventEngine) + this.eventEngine.unsubscribe(parameters); + } + else + throw new Error('Unsubscription error: subscription module disabled'); } /** * Perform unsubscribe request. @@ -752,25 +814,37 @@ class PubNubCore { * @param callback - Request completion handler callback. */ makeUnsubscribe(parameters, callback) { - this.sendRequest(new leave_1.PresenceLeaveRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })), callback); + if (process.env.PRESENCE_MODULE !== 'disabled') { + this.sendRequest(new leave_1.PresenceLeaveRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })), callback); + } + else + throw new Error('Unsubscription error: presence module disabled'); } /** * Unsubscribe from all channels and groups. */ unsubscribeAll() { - if (this.subscriptionManager) - this.subscriptionManager.unsubscribeAll(); - else if (this.eventEngine) - this.eventEngine.unsubscribeAll(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) + this.subscriptionManager.unsubscribeAll(); + else if (this.eventEngine) + this.eventEngine.unsubscribeAll(); + } + else + throw new Error('Unsubscription error: subscription module disabled'); } /** * Temporarily disconnect from real-time events stream. */ disconnect() { - if (this.subscriptionManager) - this.subscriptionManager.disconnect(); - else if (this.eventEngine) - this.eventEngine.disconnect(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) + this.subscriptionManager.disconnect(); + else if (this.eventEngine) + this.eventEngine.disconnect(); + } + else + throw new Error('Disconnection error: subscription module disabled'); } /** * Restore connection to the real-time events stream. @@ -779,10 +853,14 @@ class PubNubCore { * enabled event engine. */ reconnect(parameters) { - if (this.subscriptionManager) - this.subscriptionManager.reconnect(); - else if (this.eventEngine) - this.eventEngine.reconnect(parameters !== null && parameters !== void 0 ? parameters : {}); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) + this.subscriptionManager.reconnect(); + else if (this.eventEngine) + this.eventEngine.reconnect(parameters !== null && parameters !== void 0 ? parameters : {}); + } + else + throw new Error('Reconnection error: subscription module disabled'); } /** * Event engine handshake subscribe. @@ -791,21 +869,25 @@ class PubNubCore { */ subscribeHandshake(parameters) { return __awaiter(this, void 0, void 0, function* () { - const request = new handshake_1.HandshakeSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); - const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); - }); - /** - * Allow subscription cancellation. - * - * **Note:** Had to be done after scheduling because transport provider return cancellation - * controller only when schedule new request. - */ - const handshakeResponse = this.sendRequest(request); - return handshakeResponse.then((response) => { - abortUnsubscribe(); - return response.cursor; - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const request = new handshake_1.HandshakeSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response.cursor; + }); + } + else + throw new Error('Subscription error: subscription event engine module disabled'); }); } /** @@ -815,21 +897,25 @@ class PubNubCore { */ subscribeReceiveMessages(parameters) { return __awaiter(this, void 0, void 0, function* () { - const request = new receiveMessages_1.ReceiveMessagesSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); - const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); - }); - /** - * Allow subscription cancellation. - * - * **Note:** Had to be done after scheduling because transport provider return cancellation - * controller only when schedule new request. - */ - const handshakeResponse = this.sendRequest(request); - return handshakeResponse.then((response) => { - abortUnsubscribe(); - return response; - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const request = new receiveMessages_1.ReceiveMessagesSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response; + }); + } + else + throw new Error('Subscription error: subscription event engine module disabled'); }); } /** @@ -842,10 +928,14 @@ class PubNubCore { */ getMessageActions(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new get_message_actions_1.GetMessageActionsRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.MESSAGE_REACTIONS_MODULE !== 'disabled') { + const request = new get_message_actions_1.GetMessageActionsRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Get Message Actions error: message reactions module disabled'); }); } /** @@ -858,10 +948,14 @@ class PubNubCore { */ addMessageAction(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new add_message_action_1.AddMessageActionRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.MESSAGE_REACTIONS_MODULE !== 'disabled') { + const request = new add_message_action_1.AddMessageActionRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Add Message Action error: message reactions module disabled'); }); } /** @@ -874,10 +968,14 @@ class PubNubCore { */ removeMessageAction(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new remove_message_action_1.RemoveMessageAction(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.MESSAGE_REACTIONS_MODULE !== 'disabled') { + const request = new remove_message_action_1.RemoveMessageAction(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Remove Message Action error: message reactions module disabled'); }); } /** @@ -890,10 +988,14 @@ class PubNubCore { */ fetchMessages(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new fetch_messages_1.FetchMessagesRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.MESSAGE_PERSISTENCE_MODULE !== 'disabled') { + const request = new fetch_messages_1.FetchMessagesRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Fetch Messages History error: message persistence module disabled'); }); } /** @@ -908,10 +1010,14 @@ class PubNubCore { */ deleteMessages(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new delete_messages_1.DeleteMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.MESSAGE_PERSISTENCE_MODULE !== 'disabled') { + const request = new delete_messages_1.DeleteMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Delete Messages error: message persistence module disabled'); }); } /** @@ -924,10 +1030,14 @@ class PubNubCore { */ messageCounts(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new message_counts_1.MessageCountRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.MESSAGE_PERSISTENCE_MODULE !== 'disabled') { + const request = new message_counts_1.MessageCountRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Get Messages Count error: message persistence module disabled'); }); } /** @@ -942,10 +1052,14 @@ class PubNubCore { */ history(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new get_history_1.GetHistoryRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.MESSAGE_PERSISTENCE_MODULE !== 'disabled') { + const request = new get_history_1.GetHistoryRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Get Messages History error: message persistence module disabled'); }); } /** @@ -958,10 +1072,14 @@ class PubNubCore { */ hereNow(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new here_now_1.HereNowRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const request = new here_now_1.HereNowRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Get Channel Here Now error: presence module disabled'); }); } /** @@ -977,13 +1095,17 @@ class PubNubCore { whereNow(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; - const request = new where_now_1.WhereNowRequest({ - uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, - keySet: this._configuration.keySet, - }); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const request = new where_now_1.WhereNowRequest({ + uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, + keySet: this._configuration.keySet, + }); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Get UUID Here Now error: presence module disabled'); }); } /** @@ -997,10 +1119,14 @@ class PubNubCore { getState(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a; - const request = new get_state_1.GetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const request = new get_state_1.GetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { uuid: (_a = parameters.uuid) !== null && _a !== void 0 ? _a : this._configuration.userId, keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Get UUID State error: presence module disabled'); }); } /** @@ -1014,30 +1140,34 @@ class PubNubCore { setState(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a, _b; - const { keySet, userId: userId } = this._configuration; - const heartbeat = this._configuration.getPresenceTimeout(); - let request; - // Maintain presence information (if required). - if (this._configuration.enableEventEngine && this.presenceState) { - const presenceState = this.presenceState; - (_a = parameters.channels) === null || _a === void 0 ? void 0 : _a.forEach((channel) => (presenceState[channel] = parameters.state)); - if ('channelGroups' in parameters) { - (_b = parameters.channelGroups) === null || _b === void 0 ? void 0 : _b.forEach((group) => (presenceState[group] = parameters.state)); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const { keySet, userId: userId } = this._configuration; + const heartbeat = this._configuration.getPresenceTimeout(); + let request; + // Maintain presence information (if required). + if (this._configuration.enableEventEngine && this.presenceState) { + const presenceState = this.presenceState; + (_a = parameters.channels) === null || _a === void 0 ? void 0 : _a.forEach((channel) => (presenceState[channel] = parameters.state)); + if ('channelGroups' in parameters) { + (_b = parameters.channelGroups) === null || _b === void 0 ? void 0 : _b.forEach((group) => (presenceState[group] = parameters.state)); + } } + // Check whether state should be set with heartbeat or not. + if ('withHeartbeat' in parameters) { + request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet, heartbeat })); + } + else { + request = new set_state_1.SetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { keySet, uuid: userId })); + } + // Update state used by subscription manager. + if (this.subscriptionManager) + this.subscriptionManager.setState(parameters); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); } - // Check whether state should be set with heartbeat or not. - if ('withHeartbeat' in parameters) { - request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet, heartbeat })); - } - else { - request = new set_state_1.SetPresenceStateRequest(Object.assign(Object.assign({}, parameters), { keySet, uuid: userId })); - } - // Update state used by subscription manager. - if (this.subscriptionManager) - this.subscriptionManager.setState(parameters); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + else + throw new Error('Set UUID State error: presence module disabled'); }); } // endregion @@ -1049,7 +1179,10 @@ class PubNubCore { */ presence(parameters) { var _a; - (_a = this.subscriptionManager) === null || _a === void 0 ? void 0 : _a.changePresence(parameters); + if (process.env.SUBSCRIBE_MANAGER_MODULE !== 'disabled') + (_a = this.subscriptionManager) === null || _a === void 0 ? void 0 : _a.changePresence(parameters); + else + throw new Error('Change UUID presence error: subscription manager module disabled'); } // endregion // region Heartbeat @@ -1061,10 +1194,14 @@ class PubNubCore { */ heartbeat(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Announce UUID Presence error: presence module disabled'); }); } // endregion @@ -1076,7 +1213,10 @@ class PubNubCore { */ join(parameters) { var _a; - (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.join(parameters); + if (process.env.PRESENCE_MODULE !== 'disabled') + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.join(parameters); + else + throw new Error('Announce UUID Presence error: presence module disabled'); } // endregion // region Leave @@ -1087,14 +1227,20 @@ class PubNubCore { */ leave(parameters) { var _a; - (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leave(parameters); + if (process.env.PRESENCE_MODULE !== 'disabled') + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leave(parameters); + else + throw new Error('Announce UUID Leave error: presence module disabled'); } /** * Announce user `leave` on all subscribed channels. */ leaveAll() { var _a; - (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leaveAll(); + if (process.env.PRESENCE_MODULE !== 'disabled') + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leaveAll(); + else + throw new Error('Announce UUID Leave error: presence module disabled'); } /** * Grant token permission. @@ -1108,10 +1254,14 @@ class PubNubCore { */ grantToken(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new grant_token_1.GrantTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PAM_MODULE !== 'disabled') { + const request = new grant_token_1.GrantTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Grant Token error: PAM module disabled'); }); } /** @@ -1124,10 +1274,14 @@ class PubNubCore { */ revokeToken(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new revoke_token_1.RevokeTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PAM_MODULE !== 'disabled') { + const request = new revoke_token_1.RevokeTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Revoke Token error: PAM module disabled'); }); } // endregion @@ -1138,7 +1292,7 @@ class PubNubCore { * @returns Previously configured access token using {@link setToken} method. */ get token() { - return this.tokenManager.getToken(); + return this.tokenManager && this.tokenManager.getToken(); } /** * Get current access token. @@ -1154,7 +1308,8 @@ class PubNubCore { * @param token - New access token which should be used with next REST API endpoint calls. */ set token(token) { - this.tokenManager.setToken(token); + if (this.tokenManager) + this.tokenManager.setToken(token); } /** * Set current access token. @@ -1174,7 +1329,7 @@ class PubNubCore { * @returns Token's permissions information for the resources. */ parseToken(token) { - return this.tokenManager.parseToken(token); + return this.tokenManager && this.tokenManager.parseToken(token); } /** * Grant auth key(s) permission. @@ -1188,10 +1343,14 @@ class PubNubCore { */ grant(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new grant_1.GrantRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PAM_MODULE !== 'disabled') { + const request = new grant_1.GrantRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Grant error: PAM module disabled'); }); } /** @@ -1206,10 +1365,14 @@ class PubNubCore { */ audit(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new audit_1.AuditRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.PAM_MODULE !== 'disabled') { + const request = new audit_1.AuditRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Grant Permissions error: PAM module disabled'); }); } // endregion @@ -1237,7 +1400,10 @@ class PubNubCore { */ fetchUsers(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._getAllUUIDMetadata(parametersOrCallback, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._getAllUUIDMetadata(parametersOrCallback, callback); + else + throw new Error('Fetch Users Metadata error: App Context module disabled'); }); } /** @@ -1252,7 +1418,10 @@ class PubNubCore { */ fetchUser(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._getUUIDMetadata(parametersOrCallback, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._getUUIDMetadata(parametersOrCallback, callback); + else + throw new Error('Fetch User Metadata error: App Context module disabled'); }); } /** @@ -1268,7 +1437,10 @@ class PubNubCore { */ createUser(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._setUUIDMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._setUUIDMetadata(parameters, callback); + else + throw new Error('Create User Metadata error: App Context module disabled'); }); } /** @@ -1284,7 +1456,10 @@ class PubNubCore { */ updateUser(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._setUUIDMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._setUUIDMetadata(parameters, callback); + else + throw new Error('Update User Metadata error: App Context module disabled'); }); } /** @@ -1299,7 +1474,10 @@ class PubNubCore { */ removeUser(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._removeUUIDMetadata(parametersOrCallback, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._removeUUIDMetadata(parametersOrCallback, callback); + else + throw new Error('Remove User Metadata error: App Context module disabled'); }); } /** @@ -1315,7 +1493,10 @@ class PubNubCore { */ fetchSpaces(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._getAllChannelMetadata(parametersOrCallback, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._getAllChannelMetadata(parametersOrCallback, callback); + else + throw new Error('Fetch Spaces Metadata error: App Context module disabled'); }); } /** @@ -1330,7 +1511,10 @@ class PubNubCore { */ fetchSpace(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._getChannelMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._getChannelMetadata(parameters, callback); + else + throw new Error('Fetch Space Metadata error: App Context module disabled'); }); } /** @@ -1345,7 +1529,10 @@ class PubNubCore { */ createSpace(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._setChannelMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._setChannelMetadata(parameters, callback); + else + throw new Error('Create Space Metadata error: App Context module disabled'); }); } /** @@ -1360,7 +1547,10 @@ class PubNubCore { */ updateSpace(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._setChannelMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._setChannelMetadata(parameters, callback); + else + throw new Error('Update Space Metadata error: App Context module disabled'); }); } /** @@ -1376,7 +1566,10 @@ class PubNubCore { */ removeSpace(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects._removeChannelMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._removeChannelMetadata(parameters, callback); + else + throw new Error('Remove Space Metadata error: App Context module disabled'); }); } /** @@ -1393,7 +1586,10 @@ class PubNubCore { */ fetchMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects.fetchMemberships(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects.fetchMemberships(parameters, callback); + else + throw new Error('Fetch Memberships error: App Context module disabled'); }); } /** @@ -1410,7 +1606,10 @@ class PubNubCore { */ addMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects.addMemberships(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects.addMemberships(parameters, callback); + else + throw new Error('Add Memberships error: App Context module disabled'); }); } /** @@ -1427,7 +1626,10 @@ class PubNubCore { */ updateMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - return this.objects.addMemberships(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects.addMemberships(parameters, callback); + else + throw new Error('Update Memberships error: App Context module disabled'); }); } /** @@ -1445,26 +1647,30 @@ class PubNubCore { removeMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { var _a, _b, _c; - if ('spaceId' in parameters) { - const spaceParameters = parameters; + if (process.env.APP_CONTEXT_MODULE !== 'disabled') { + if ('spaceId' in parameters) { + const spaceParameters = parameters; + const requestParameters = { + channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, + uuids: (_b = spaceParameters.userIds) !== null && _b !== void 0 ? _b : spaceParameters.uuids, + limit: 0, + }; + if (callback) + return this.objects.removeChannelMembers(requestParameters, callback); + return this.objects.removeChannelMembers(requestParameters); + } + const userParameters = parameters; const requestParameters = { - channel: (_a = spaceParameters.spaceId) !== null && _a !== void 0 ? _a : spaceParameters.channel, - uuids: (_b = spaceParameters.userIds) !== null && _b !== void 0 ? _b : spaceParameters.uuids, + uuid: userParameters.userId, + channels: (_c = userParameters.spaceIds) !== null && _c !== void 0 ? _c : userParameters.channels, limit: 0, }; if (callback) - return this.objects.removeChannelMembers(requestParameters, callback); - return this.objects.removeChannelMembers(requestParameters); + return this.objects.removeMemberships(requestParameters, callback); + return this.objects.removeMemberships(requestParameters); } - const userParameters = parameters; - const requestParameters = { - uuid: userParameters.userId, - channels: (_c = userParameters.spaceIds) !== null && _c !== void 0 ? _c : userParameters.channels, - limit: 0, - }; - if (callback) - return this.objects.removeMemberships(requestParameters, callback); - return this.objects.removeMemberships(requestParameters); + else + throw new Error('Remove Memberships error: App Context module disabled'); }); } // endregion @@ -1500,34 +1706,38 @@ class PubNubCore { */ sendFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - if (!this._configuration.PubNubFile) - throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - const sendFileRequest = new send_file_1.SendFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, fileUploadPublishRetryLimit: this._configuration.fileUploadPublishRetryLimit, file: parameters.file, sendRequest: this.sendRequest.bind(this), publishFile: this.publishFile.bind(this), crypto: this._configuration.getCryptoModule(), cryptography: this.cryptography ? this.cryptography : undefined })); - const status = { - error: false, - operation: operations_1.default.PNPublishFileOperation, - category: categories_1.default.PNAcknowledgmentCategory, - statusCode: 0, - }; - return sendFileRequest - .process() - .then((response) => { - status.statusCode = response.status; - if (callback) - return callback(status, response); - return response; - }) - .catch((error) => { - let errorStatus; - if (error instanceof pubnub_error_1.PubNubError) - errorStatus = error.status; - else if (error instanceof pubnub_api_error_1.PubNubAPIError) - errorStatus = error.toStatus(status.operation); - // Notify callback (if possible). - if (callback && errorStatus) - callback(errorStatus, null); - throw new pubnub_error_1.PubNubError('REST API request processing error, check status for details', errorStatus); - }); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const sendFileRequest = new send_file_1.SendFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, fileUploadPublishRetryLimit: this._configuration.fileUploadPublishRetryLimit, file: parameters.file, sendRequest: this.sendRequest.bind(this), publishFile: this.publishFile.bind(this), crypto: this._configuration.getCryptoModule(), cryptography: this.cryptography ? this.cryptography : undefined })); + const status = { + error: false, + operation: operations_1.default.PNPublishFileOperation, + category: categories_1.default.PNAcknowledgmentCategory, + statusCode: 0, + }; + return sendFileRequest + .process() + .then((response) => { + status.statusCode = response.status; + if (callback) + return callback(status, response); + return response; + }) + .catch((error) => { + let errorStatus; + if (error instanceof pubnub_error_1.PubNubError) + errorStatus = error.status; + else if (error instanceof pubnub_api_error_1.PubNubAPIError) + errorStatus = error.toStatus(status.operation); + // Notify callback (if possible). + if (callback && errorStatus) + callback(errorStatus, null); + throw new pubnub_error_1.PubNubError('REST API request processing error, check status for details', errorStatus); + }); + } + else + throw new Error('Send File error: file sharing module disabled'); }); } /** @@ -1540,12 +1750,16 @@ class PubNubCore { */ publishFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - if (!this._configuration.PubNubFile) - throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - const request = new publish_file_1.PublishFileMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const request = new publish_file_1.PublishFileMessageRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Publish File error: file sharing module disabled'); }); } /** @@ -1558,10 +1772,14 @@ class PubNubCore { */ listFiles(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new list_files_1.FilesListRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + const request = new list_files_1.FilesListRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('List Files error: file sharing module disabled'); }); } // endregion @@ -1575,17 +1793,21 @@ class PubNubCore { */ getFileUrl(parameters) { var _a; - const request = this.transport.request(new get_file_url_1.GetFileDownloadUrlRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })).request()); - const query = (_a = request.queryParameters) !== null && _a !== void 0 ? _a : {}; - const queryString = Object.keys(query) - .map((key) => { - const queryValue = query[key]; - if (!Array.isArray(queryValue)) - return `${key}=${(0, utils_1.encodeString)(queryValue)}`; - return queryValue.map((value) => `${key}=${(0, utils_1.encodeString)(value)}`).join('&'); - }) - .join('&'); - return `${request.origin}${request.path}?${queryString}`; + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + const request = this.transport.request(new get_file_url_1.GetFileDownloadUrlRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })).request()); + const query = (_a = request.queryParameters) !== null && _a !== void 0 ? _a : {}; + const queryString = Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${(0, utils_1.encodeString)(queryValue)}`; + return queryValue.map((value) => `${key}=${(0, utils_1.encodeString)(value)}`).join('&'); + }) + .join('&'); + return `${request.origin}${request.path}?${queryString}`; + } + else + throw new Error('Generate File Download Url error: file sharing module disabled'); } /** * Download shared file from specific channel. @@ -1597,12 +1819,16 @@ class PubNubCore { */ downloadFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - if (!this._configuration.PubNubFile) - throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - const request = new download_file_1.DownloadFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, cryptography: this.cryptography ? this.cryptography : undefined, crypto: this._configuration.getCryptoModule() })); - if (callback) - return this.sendRequest(request, callback); - return (yield this.sendRequest(request)); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + const request = new download_file_1.DownloadFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, PubNubFile: this._configuration.PubNubFile, cryptography: this.cryptography ? this.cryptography : undefined, crypto: this._configuration.getCryptoModule() })); + if (callback) + return this.sendRequest(request, callback); + return (yield this.sendRequest(request)); + } + else + throw new Error('Download File error: file sharing module disabled'); }); } /** @@ -1615,10 +1841,14 @@ class PubNubCore { */ deleteFile(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { - const request = new delete_file_1.DeleteFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); - if (callback) - return this.sendRequest(request, callback); - return this.sendRequest(request); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + const request = new delete_file_1.DeleteFileRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + if (callback) + return this.sendRequest(request, callback); + return this.sendRequest(request); + } + else + throw new Error('Delete File error: file sharing module disabled'); }); } /** @@ -1660,7 +1890,11 @@ class PubNubCore { } if (!this.crypto) throw new Error('Encryption error: cypher key not set'); - return this.crypto.encrypt(data, customCipherKey); + if (process.env.CRYPTO_MODULE !== 'disabled') { + return this.crypto.encrypt(data, customCipherKey); + } + else + throw new Error('Encryption error: crypto module disabled'); } /** * Decrypt data. @@ -1679,7 +1913,11 @@ class PubNubCore { } if (!this.crypto) throw new Error('Decryption error: cypher key not set'); - return this.crypto.decrypt(data, customCipherKey); + if (process.env.CRYPTO_MODULE !== 'disabled') { + return this.crypto.decrypt(data, customCipherKey); + } + else + throw new Error('Decryption error: crypto module disabled'); } /** * Encrypt file content. @@ -1708,9 +1946,15 @@ class PubNubCore { if (typeof keyOrFile === 'string') { if (!this.cryptography) throw new Error('File encryption error. File encryption not available'); - return this.cryptography.encryptFile(keyOrFile, file, this._configuration.PubNubFile); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + return this.cryptography.encryptFile(keyOrFile, file, this._configuration.PubNubFile); + else + throw new Error('Encryption error: file sharing module disabled'); } - return (_a = this._configuration.getCryptoModule()) === null || _a === void 0 ? void 0 : _a.encryptFile(file, this._configuration.PubNubFile); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + return (_a = this._configuration.getCryptoModule()) === null || _a === void 0 ? void 0 : _a.encryptFile(file, this._configuration.PubNubFile); + else + throw new Error('Encryption error: file sharing module disabled'); }); } /** @@ -1740,9 +1984,15 @@ class PubNubCore { if (typeof keyOrFile === 'string') { if (!this.cryptography) throw new Error('File decryption error. File decryption not available'); - return this.cryptography.decryptFile(keyOrFile, file, this._configuration.PubNubFile); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + return this.cryptography.decryptFile(keyOrFile, file, this._configuration.PubNubFile); + else + throw new Error('Decryption error: file sharing module disabled'); } - return (_a = this._configuration.getCryptoModule()) === null || _a === void 0 ? void 0 : _a.decryptFile(file, this._configuration.PubNubFile); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + return (_a = this._configuration.getCryptoModule()) === null || _a === void 0 ? void 0 : _a.decryptFile(file, this._configuration.PubNubFile); + else + throw new Error('Decryption error: file sharing module disabled'); }); } } diff --git a/lib/entities/Channel.js b/lib/entities/Channel.js index 2aa39e7cf..6b7958877 100644 --- a/lib/entities/Channel.js +++ b/lib/entities/Channel.js @@ -9,13 +9,17 @@ class Channel { this.name = channelName; } subscription(subscriptionOptions) { - return new Subscription_1.Subscription({ - channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new Subscription_1.Subscription({ + channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } + else + throw new Error('Subscription error: subscription event engine module disabled'); } } exports.Channel = Channel; diff --git a/lib/entities/ChannelGroup.js b/lib/entities/ChannelGroup.js index d4de51cac..1245ca275 100644 --- a/lib/entities/ChannelGroup.js +++ b/lib/entities/ChannelGroup.js @@ -9,13 +9,17 @@ class ChannelGroup { this.name = channelGroup; } subscription(subscriptionOptions) { - return new Subscription_1.Subscription({ - channels: [], - channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new Subscription_1.Subscription({ + channels: [], + channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } + else + throw new Error('Subscription error: subscription event engine module disabled'); } } exports.ChannelGroup = ChannelGroup; diff --git a/lib/entities/ChannelMetadata.js b/lib/entities/ChannelMetadata.js index c1d6fe93e..f5ee7a639 100644 --- a/lib/entities/ChannelMetadata.js +++ b/lib/entities/ChannelMetadata.js @@ -9,13 +9,17 @@ class ChannelMetadata { this.pubnub = pubnub; } subscription(subscriptionOptions) { - return new Subscription_1.Subscription({ - channels: [this.id], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new Subscription_1.Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } + else + throw new Error('Subscription error: subscription module disabled'); } } exports.ChannelMetadata = ChannelMetadata; diff --git a/lib/entities/UserMetadata.js b/lib/entities/UserMetadata.js index d7c03f5f1..b740b04e9 100644 --- a/lib/entities/UserMetadata.js +++ b/lib/entities/UserMetadata.js @@ -9,13 +9,17 @@ class UserMetadata { this.pubnub = pubnub; } subscription(subscriptionOptions) { - return new Subscription_1.Subscription({ - channels: [this.id], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new Subscription_1.Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } + else + throw new Error('Subscription error: subscription event engine module disabled'); } } exports.UserMetadata = UserMetadata; diff --git a/lib/node/index.js b/lib/node/index.js index eed5fb4a0..41ebc06ee 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -23,38 +23,53 @@ const common_1 = __importDefault(require("../cbor/common")); class PubNub extends pubnub_common_1.PubNubCore { constructor(configuration) { const configurationCopy = (0, configuration_2.setDefaults)(configuration); - const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'Nodejs', PubNubFile: node_1.default }); + const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'Nodejs' }); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + platformConfiguration.PubNubFile = node_1.default; // Prepare full client configuration. const clientConfiguration = (0, configuration_1.makeConfiguration)(platformConfiguration, (cryptoConfiguration) => { if (!cryptoConfiguration.cipherKey) return undefined; - return new nodeCryptoModule_1.CryptoModule({ - default: new nodeCryptoModule_1.LegacyCryptor(Object.assign({}, cryptoConfiguration)), - cryptors: [new nodeCryptoModule_1.AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], - }); + if (process.env.CRYPTO_MODULE !== 'disabled') { + return new nodeCryptoModule_1.CryptoModule({ + default: new nodeCryptoModule_1.LegacyCryptor(Object.assign({}, cryptoConfiguration)), + cryptors: [new nodeCryptoModule_1.AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], + }); + } + else + return undefined; }); // Prepare Token manager. - const tokenManager = new token_manager_1.TokenManager(new common_1.default((buffer) => cbor_sync_1.default.decode(buffer_1.Buffer.from(buffer)), base64_codec_1.decode)); + let tokenManager; + if (process.env.CRYPTO_MODULE !== 'disabled') { + tokenManager = new token_manager_1.TokenManager(new common_1.default((buffer) => cbor_sync_1.default.decode(buffer_1.Buffer.from(buffer)), base64_codec_1.decode)); + } // Legacy crypto (legacy data encryption / decryption and request signature support). - const crypto = new cryptography_1.default({ - secretKey: clientConfiguration.secretKey, - cipherKey: clientConfiguration.getCipherKey(), - useRandomIVs: clientConfiguration.getUseRandomIVs(), - customEncrypt: clientConfiguration.getCustomEncrypt(), - customDecrypt: clientConfiguration.getCustomDecrypt(), - }); + let crypto; + if (process.env.CRYPTO_MODULE !== 'disabled') { + crypto = new cryptography_1.default({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } + let cryptography; + if (process.env.CRYPTO_MODULE !== 'disabled') + cryptography = new node_2.default(); // Setup transport provider. const transport = new node_transport_1.NodeTransport(configuration.keepAlive, configuration.keepAliveSettings); const transportMiddleware = new middleware_1.PubNubMiddleware({ clientConfiguration, tokenManager, transport, - shaHMAC: crypto === null || crypto === void 0 ? void 0 : crypto.HMACSHA256.bind(crypto), + shaHMAC: process.env.CRYPTO_MODULE !== 'disabled' ? crypto === null || crypto === void 0 ? void 0 : crypto.HMACSHA256.bind(crypto) : undefined, }); super({ configuration: clientConfiguration, transport: transportMiddleware, - cryptography: new node_2.default(), + cryptography, tokenManager, crypto, }); @@ -83,5 +98,6 @@ class PubNub extends pubnub_common_1.PubNubCore { /** * Data encryption / decryption module constructor. */ -PubNub.CryptoModule = nodeCryptoModule_1.CryptoModule; +// @ts-expect-error Allowed to simplify interface when module can be disabled. +PubNub.CryptoModule = process.env.CRYPTO_MODULE !== 'disabled' ? nodeCryptoModule_1.CryptoModule : undefined; module.exports = PubNub; diff --git a/lib/react_native/index.js b/lib/react_native/index.js index 606e5d543..fb65ba063 100644 --- a/lib/react_native/index.js +++ b/lib/react_native/index.js @@ -28,21 +28,28 @@ global.Buffer = global.Buffer || buffer_1.Buffer; class PubNub extends pubnub_common_1.PubNubCore { constructor(configuration) { const configurationCopy = (0, configuration_2.setDefaults)(configuration); - const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'ReactNative', PubNubFile: react_native_1.default }); + const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'ReactNative' }); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + platformConfiguration.PubNubFile = react_native_1.default; // Prepare full client configuration. const clientConfiguration = (0, configuration_1.makeConfiguration)(platformConfiguration); // Prepare Token manager. - const tokenManager = new token_manager_1.TokenManager(new common_1.default((arrayBuffer) => (0, stringify_buffer_keys_1.stringifyBufferKeys)(cbor_js_1.default.decode(arrayBuffer)), base64_codec_1.decode)); + let tokenManager; + if (process.env.CRYPTO_MODULE !== 'disabled') { + tokenManager = new token_manager_1.TokenManager(new common_1.default((arrayBuffer) => (0, stringify_buffer_keys_1.stringifyBufferKeys)(cbor_js_1.default.decode(arrayBuffer)), base64_codec_1.decode)); + } // Legacy crypto (legacy data encryption / decryption and request signature support). let crypto; - if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { - crypto = new cryptography_1.default({ - secretKey: clientConfiguration.secretKey, - cipherKey: clientConfiguration.getCipherKey(), - useRandomIVs: clientConfiguration.getUseRandomIVs(), - customEncrypt: clientConfiguration.getCustomEncrypt(), - customDecrypt: clientConfiguration.getCustomDecrypt(), - }); + if (process.env.CRYPTO_MODULE !== 'disabled') { + if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { + crypto = new cryptography_1.default({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } } // Setup transport layer. const transportMiddleware = new middleware_1.PubNubMiddleware({ diff --git a/lib/transport/middleware.js b/lib/transport/middleware.js index 61519ad44..c7e60f30c 100644 --- a/lib/transport/middleware.js +++ b/lib/transport/middleware.js @@ -1,8 +1,13 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -exports.PubNubMiddleware = exports.RequestSignature = void 0; +exports.PubNubMiddleware = void 0; const transport_request_1 = require("../core/types/transport-request"); const utils_1 = require("../core/utils"); +/** + * Request signature generator. + * + * @internal + */ class RequestSignature { constructor(publishKey, secretKey, hasher) { this.publishKey = publishKey; @@ -56,14 +61,15 @@ class RequestSignature { .join('&'); } } -exports.RequestSignature = RequestSignature; RequestSignature.textDecoder = new TextDecoder('utf-8'); class PubNubMiddleware { constructor(configuration) { this.configuration = configuration; const { clientConfiguration: { keySet }, shaHMAC, } = configuration; - if (keySet.secretKey && shaHMAC) - this.signatureGenerator = new RequestSignature(keySet.publishKey, keySet.secretKey, shaHMAC); + if (process.env.CRYPTO_MODULE !== 'disabled') { + if (keySet.secretKey && shaHMAC) + this.signatureGenerator = new RequestSignature(keySet.publishKey, keySet.secretKey, shaHMAC); + } } makeSendable(req) { return this.configuration.transport.makeSendable(this.request(req)); @@ -96,7 +102,7 @@ class PubNubMiddleware { if (req.path.startsWith('/v2/auth/') || req.path.startsWith('/v3/pam/') || req.path.startsWith('/time')) return; const { clientConfiguration, tokenManager } = this.configuration; - const accessKey = (_a = tokenManager.getToken()) !== null && _a !== void 0 ? _a : clientConfiguration.authKey; + const accessKey = (_a = (tokenManager && tokenManager.getToken())) !== null && _a !== void 0 ? _a : clientConfiguration.authKey; if (accessKey) req.queryParameters['auth'] = accessKey; } diff --git a/lib/types/core/pubnub-common.d.ts b/lib/types/core/pubnub-common.d.ts index 976ca6564..4f2f2bbc6 100644 --- a/lib/types/core/pubnub-common.d.ts +++ b/lib/types/core/pubnub-common.d.ts @@ -41,7 +41,7 @@ type ClientInstanceConfiguration = { /** * REST API endpoints access tokens manager. */ - tokenManager: TokenManager; + tokenManager?: TokenManager; /** * Legacy crypto module implementation. */ diff --git a/lib/types/node/index.d.ts b/lib/types/node/index.d.ts index 71794933a..b06546497 100644 --- a/lib/types/node/index.d.ts +++ b/lib/types/node/index.d.ts @@ -3,7 +3,7 @@ import { ProxyAgentOptions } from 'proxy-agent'; import { Readable } from 'stream'; import { Buffer } from 'buffer'; -import { CryptoModule } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; +import type { CryptoModule as CryptoModuleType } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; import PubNubFile, { PubNubFileParameters } from '../file/modules/node'; import { PubNubConfiguration } from './configuration'; import { PubNubFileConstructor } from '../core/types/file'; @@ -15,7 +15,7 @@ declare class PubNub extends PubNubCore string); - /** - * Compute request signature. - * - * @param req - Request which will be used to compute signature. - * @returns {string} `v2` request signature. - */ - signature(req: TransportRequest): string; - /** - * Prepare request query parameters for signature. - * - * @param query - Key / value pair of the request query parameters. - * @private - */ - private queryParameters; -} export declare class PubNubMiddleware implements Transport { private configuration; /** diff --git a/package.json b/package.json index 8081417ba..7a4bdf3c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.1.0", + "version": "8.2.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/rollup.config.js b/rollup.config.js index cc481e66e..0e0c2017b 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -11,7 +11,128 @@ import terser from '@rollup/plugin-terser'; import { browser, version } from './package.json'; -const SERVICE_WORKER_CDN = 'https://cdn.pubnub.com/sdk/javascript'; +const enableTreeShaking = false; +const replaceConfiguration = { + /** + * Module contains operations related to cryptors usage (including CBOR). + * + * Set `CRYPTO_MODULE` environment variable to `disabled` during build with Webpack or roll-up to + * exclude module during tree-shaking optimization process. + */ + 'process.env.CRYPTO_MODULE': JSON.stringify(process.env.CRYPTO_MODULE ?? 'enabled'), + + /** + * Module contains functionality related to the browser background subscription requests handling. + * + * Set `SHARED_WORKER` environment variable to `disabled` during build with Webpack or roll-up to + * exclude module during tree-shaking optimization process. + */ + 'process.env.SHARED_WORKER': JSON.stringify(process.env.SHARED_WORKER ?? 'enabled'), + + /** + * Module contains functionality related to message and signals sending. + * + * Set `PUBLISH_MODULE` environment variable to `disabled` during build with Webpack or roll-up to + * exclude module during tree-shaking optimization process. + */ + 'process.env.PUBLISH_MODULE': JSON.stringify(process.env.PUBLISH_MODULE ?? 'enabled'), + + /** + * Module contains functionality related to subscription on real-time updates and their handling. + * + * Set `SUBSCRIBE_MODULE` environment variable to `disabled` during build with Webpack or roll-up + * to exclude module during tree-shaking optimization process. + */ + 'process.env.SUBSCRIBE_MODULE': JSON.stringify(process.env.SUBSCRIBE_MODULE ?? 'enabled'), + + /** + * Module contains functionality to support `SUBSCRIBE_MODULE` using event engine mechanism. + * + * **Important:** If there is no plans to use legacy subscription manager then it will be better + * to disable `SUBSCRIBE_MANAGER_MODULE`. + * + * Set `SUBSCRIBE_EVENT_ENGINE_MODULE` environment variable to `disabled` during build with + * Webpack or roll-up to exclude module during tree-shaking optimization process. + */ + 'process.env.SUBSCRIBE_EVENT_ENGINE_MODULE': JSON.stringify(process.env.SUBSCRIBE_EVENT_ENGINE_MODULE ?? 'enabled'), + + /** + * Module contains functionality to support `SUBSCRIBE_MODULE` using event engine mechanism. + * + * **Important:** If there is no plans to use event engine then it will be better to disable + * `SUBSCRIBE_EVENT_ENGINE_MODULE`. + * + * Set `SUBSCRIBE_MANAGER_MODULE` environment variable to `disabled` during build with Webpack or + * roll-up to exclude module during tree-shaking optimization process. + */ + 'process.env.SUBSCRIBE_MANAGER_MODULE': JSON.stringify(process.env.SUBSCRIBE_MANAGER_MODULE ?? 'enabled'), + + /** + * Module contains functionality related to the user presence and state management. + * + * Set `PRESENCE_MODULE` environment variable to `disabled` during build with Webpack or + * roll-up to exclude module during tree-shaking optimization process. + */ + 'process.env.PRESENCE_MODULE': JSON.stringify(process.env.PRESENCE_MODULE ?? 'enabled'), + + /** + * Module contains functionality related to the access token / auth key permissions management. + * + * **Important:** Module `disabled` by default for browser environment. + */ + 'process.env.PAM_MODULE': JSON.stringify(process.env.PAM_MODULE ?? 'disabled'), + + /** + * Module contains functionality related to the channel group management. + * + * Set `CHANNEL_GROUPS_MODULE` environment variable to `disabled` during build with Webpack or + * roll-up to exclude module during tree-shaking optimization process. + */ + 'process.env.CHANNEL_GROUPS_MODULE': JSON.stringify(process.env.CHANNEL_GROUPS_MODULE ?? 'enabled'), + + /** + * Module contains functionality related to the message persistence (history storage) access and + * management (remove messages). + * + * Set `MESSAGE_PERSISTENCE_MODULE` environment variable to `disabled` during build with Webpack + * or roll-up to exclude module during tree-shaking optimization process. + */ + 'process.env.MESSAGE_PERSISTENCE_MODULE': JSON.stringify(process.env.MESSAGE_PERSISTENCE_MODULE ?? 'enabled'), + + /** + * Module contains functionality related to the mobile push notifications management for channels. + * + * Set `MOBILE_PUSH_MODULE` environment variable to `disabled` during build with Webpack or + * roll-up to exclude module during tree-shaking optimization process. + */ + 'process.env.MOBILE_PUSH_MODULE': JSON.stringify(process.env.MOBILE_PUSH_MODULE ?? 'enabled'), + + /** + * Module contains functionality related to the App Context entities and their relationship + * management. + * + * Set `APP_CONTEXT_MODULE` environment variable to `disabled` during build with Webpack or + * roll-up to exclude module during tree-shaking optimization process. + */ + 'process.env.APP_CONTEXT_MODULE': JSON.stringify(process.env.APP_CONTEXT_MODULE ?? 'enabled'), + + /** + * Module contains functionality related to the file sharing. + * + * Set `FILE_SHARING_MODULE` environment variable to `disabled` during build with Webpack or + * roll-up to exclude module during tree-shaking optimization process. + */ + 'process.env.FILE_SHARING_MODULE': JSON.stringify(process.env.FILE_SHARING_MODULE ?? 'enabled'), + + /** + * Module contains functionality related to the message reactions (message actions). + * + * Set `MESSAGE_REACTIONS_MODULE` environment variable to `disabled` during build with Webpack or + * roll-up to exclude module during tree-shaking optimization process. + */ + 'process.env.MESSAGE_REACTIONS_MODULE': JSON.stringify(process.env.MESSAGE_REACTIONS_MODULE ?? 'enabled'), + preventAssignment: true, +}; export default [ { @@ -24,15 +145,14 @@ export default [ plugins: [ json(), resolve({ browser: true }), - replace({ - SERVICE_WORKER_FILE_PLACEHOLDER: join(dirname(browser), basename(browser, '.min.js') + '.worker.min.js'), - SERVICE_WORKER_CDN, - preventAssignment: true, - }), + replace(replaceConfiguration), commonjs(), typescript({ tsconfig: 'tsconfig.rollup.json' }), terser(), ], + treeshake: { + moduleSideEffects: !enableTreeShaking, + }, }, { input: 'src/web/index.ts', @@ -44,14 +164,13 @@ export default [ plugins: [ json(), resolve({ browser: true }), - replace({ - SERVICE_WORKER_FILE_PLACEHOLDER: join(dirname(browser), basename(browser, '.min.js') + '.worker.js'), - SERVICE_WORKER_CDN, - preventAssignment: true, - }), + replace(replaceConfiguration), commonjs(), typescript({ tsconfig: 'tsconfig.rollup.json' }), ], + treeshake: { + moduleSideEffects: !enableTreeShaking, + }, }, { input: 'src/transport/subscription-worker/subscription-worker.ts', @@ -87,16 +206,15 @@ export default [ plugins: [ json(), resolve({ browser: true }), - replace({ - SERVICE_WORKER_FILE_PLACEHOLDER: `pubnub.worker.${version}.min.js`, - SERVICE_WORKER_CDN, - preventAssignment: true, - }), + replace(replaceConfiguration), commonjs(), typescript({ tsconfig: 'tsconfig.rollup.json' }), terser(), gzipPlugin({ fileName: '' }), ], + treeshake: { + moduleSideEffects: !enableTreeShaking, + }, }, { input: 'src/web/index.ts', @@ -108,15 +226,14 @@ export default [ plugins: [ json(), resolve({ browser: true }), - replace({ - SERVICE_WORKER_FILE_PLACEHOLDER: `pubnub.worker.${version}.js`, - SERVICE_WORKER_CDN, - preventAssignment: true, - }), + replace(replaceConfiguration), commonjs(), typescript({ tsconfig: 'tsconfig.rollup.json' }), gzipPlugin({ fileName: '' }), ], + treeshake: { + moduleSideEffects: !enableTreeShaking, + }, }, { input: 'src/web/index.ts', @@ -128,15 +245,14 @@ export default [ plugins: [ json(), resolve({ browser: true }), - replace({ - SERVICE_WORKER_FILE_PLACEHOLDER: `pubnub.worker.${version}.min.js`, - SERVICE_WORKER_CDN, - preventAssignment: true, - }), + replace(replaceConfiguration), commonjs(), typescript({ tsconfig: 'tsconfig.rollup.json' }), terser(), ], + treeshake: { + moduleSideEffects: !enableTreeShaking, + }, }, { input: 'src/web/index.ts', @@ -148,14 +264,13 @@ export default [ plugins: [ json(), resolve({ browser: true }), - replace({ - SERVICE_WORKER_FILE_PLACEHOLDER: `pubnub.worker.${version}.js`, - SERVICE_WORKER_CDN, - preventAssignment: true, - }), + replace(replaceConfiguration), commonjs(), typescript({ tsconfig: 'tsconfig.rollup.json' }), ], + treeshake: { + moduleSideEffects: !enableTreeShaking, + }, }, { input: 'src/transport/subscription-worker/subscription-worker.ts', diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 212f4c07e..5581bdc30 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.1.0'; + return '8.2.0'; }, getVersion(): string { return this.version; diff --git a/src/core/endpoints/access_manager/grant_token.ts b/src/core/endpoints/access_manager/grant_token.ts index 5c6d5de6a..86a8132c3 100644 --- a/src/core/endpoints/access_manager/grant_token.ts +++ b/src/core/endpoints/access_manager/grant_token.ts @@ -160,6 +160,10 @@ export class GrantTokenRequest extends AbstractRequest { return `/v3/pam/${this.parameters.keySet.subscribeKey}/grant`; } + protected get headers(): Record | undefined { + return { 'Content-Type': 'application/json' }; + } + protected get body(): string { const { ttl, meta } = this.parameters; const body: Record = { ...(ttl || ttl === 0 ? { ttl } : {}) }; diff --git a/src/core/endpoints/actions/add_message_action.ts b/src/core/endpoints/actions/add_message_action.ts index 6f1192b58..355180abd 100644 --- a/src/core/endpoints/actions/add_message_action.ts +++ b/src/core/endpoints/actions/add_message_action.ts @@ -87,10 +87,6 @@ export class AddMessageActionRequest extends AbstractRequest | undefined { - return { 'Content-Type': 'application/json' }; - } - protected get path(): string { const { keySet: { subscribeKey }, @@ -101,6 +97,10 @@ export class AddMessageActionRequest extends AbstractRequest | undefined { + return { 'Content-Type': 'application/json' }; + } + protected get body(): ArrayBuffer | string | undefined { return JSON.stringify(this.parameters.action); } diff --git a/src/core/endpoints/file_upload/generate_upload_url.ts b/src/core/endpoints/file_upload/generate_upload_url.ts index 264d57365..1dde65f35 100644 --- a/src/core/endpoints/file_upload/generate_upload_url.ts +++ b/src/core/endpoints/file_upload/generate_upload_url.ts @@ -144,6 +144,10 @@ export class GenerateFileUploadUrlRequest extends AbstractRequest | undefined { + return { 'Content-Type': 'application/json' }; + } + protected get body(): ArrayBuffer | string | undefined { return JSON.stringify({ name: this.parameters.name }); } diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index fbde5b550..680f337f8 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -126,7 +126,7 @@ type ClientInstanceConfiguration = { /** * REST API endpoints access tokens manager. */ - tokenManager: TokenManager; + tokenManager?: TokenManager; /** * Legacy crypto module implementation. @@ -176,7 +176,7 @@ export class PubNubCore< * * @internal */ - private readonly tokenManager: TokenManager; + private readonly tokenManager?: TokenManager; /** * Legacy crypto module implementation. @@ -197,6 +197,7 @@ export class PubNubCore< * * @internal */ + // @ts-expect-error Allowed to simplify interface when module can be disabled. protected readonly listenerManager: ListenerManager; /** @@ -225,6 +226,7 @@ export class PubNubCore< * * @internal */ + // @ts-expect-error Allowed to simplify interface when module can be disabled. private readonly eventEmitter: EventEmitter; /** @@ -232,12 +234,15 @@ export class PubNubCore< * * @internal */ + // @ts-expect-error Allowed to simplify interface when module can be disabled. private readonly _objects: PubNubObjects; /** * PubNub Channel Group REST API entry point. + * + * @internal */ - // @internal @ts-ignore + // @ts-expect-error Allowed to simplify interface when module can be disabled. private readonly _channelGroups: PubNubChannelGroups; /** @@ -245,6 +250,7 @@ export class PubNubCore< * * @internal */ + // @ts-expect-error Allowed to simplify interface when module can be disabled. private readonly _push: PubNubPushNotifications; /** @@ -288,7 +294,9 @@ export class PubNubCore< * @returns Pre-formatted message payload which will trigger push notification. */ static notificationPayload(title: string, body: string) { - return new NotificationsPayload(title, body); + if (process.env.PUBLISH_MODULE !== 'disabled') { + return new NotificationsPayload(title, body); + } else throw new Error('Notification Payload error: publish module disabled'); } /** @@ -309,69 +317,80 @@ export class PubNubCore< this.crypto = configuration.crypto; // API group entry points initialization. - this._objects = new PubNubObjects(this._configuration, this.sendRequest.bind(this)); - this._channelGroups = new PubNubChannelGroups(this._configuration.keySet, this.sendRequest.bind(this)); - this._push = new PubNubPushNotifications(this._configuration.keySet, this.sendRequest.bind(this)); - - // Prepare for real-time events announcement. - this.listenerManager = new ListenerManager(); - this.eventEmitter = new EventEmitter(this.listenerManager); - - if (this._configuration.enableEventEngine) { - let heartbeatInterval = this._configuration.getHeartbeatInterval(); - this.presenceState = {}; - - if (heartbeatInterval) { - this.presenceEventEngine = new PresenceEventEngine({ - heartbeat: this.heartbeat.bind(this), - leave: (parameters) => this.makeUnsubscribe(parameters, () => {}), - heartbeatDelay: () => - new Promise((resolve, reject) => { - heartbeatInterval = this._configuration.getHeartbeatInterval(); - if (!heartbeatInterval) reject(new PubNubError('Heartbeat interval has been reset.')); - else setTimeout(resolve, heartbeatInterval * 1000); - }), - retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), - emitStatus: (status) => this.listenerManager.announceStatus(status), - config: this._configuration, - presenceState: this.presenceState, - }); - } - - this.eventEngine = new EventEngine({ - handshake: this.subscribeHandshake.bind(this), - receiveMessages: this.subscribeReceiveMessages.bind(this), - delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), - join: this.join.bind(this), - leave: this.leave.bind(this), - leaveAll: this.leaveAll.bind(this), - presenceState: this.presenceState, - config: this._configuration, - emitMessages: (events) => { - try { - events.forEach((event) => this.eventEmitter.emitEvent(event)); - } catch (e) { - const errorStatus: Status = { - error: true, - category: StatusCategory.PNUnknownCategory, - errorData: e as Error, - statusCode: 0, - }; - this.listenerManager.announceStatus(errorStatus); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + this._objects = new PubNubObjects(this._configuration, this.sendRequest.bind(this)); + if (process.env.CHANNEL_GROUPS_MODULE !== 'disabled') + this._channelGroups = new PubNubChannelGroups(this._configuration.keySet, this.sendRequest.bind(this)); + if (process.env.MOBILE_PUSH_MODULE !== 'disabled') + this._push = new PubNubPushNotifications(this._configuration.keySet, this.sendRequest.bind(this)); + + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + // Prepare for real-time events announcement. + this.listenerManager = new ListenerManager(); + this.eventEmitter = new EventEmitter(this.listenerManager); + + if (this._configuration.enableEventEngine) { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + let heartbeatInterval = this._configuration.getHeartbeatInterval(); + this.presenceState = {}; + + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (heartbeatInterval) { + this.presenceEventEngine = new PresenceEventEngine({ + heartbeat: this.heartbeat.bind(this), + leave: (parameters) => this.makeUnsubscribe(parameters, () => {}), + heartbeatDelay: () => + new Promise((resolve, reject) => { + heartbeatInterval = this._configuration.getHeartbeatInterval(); + if (!heartbeatInterval) reject(new PubNubError('Heartbeat interval has been reset.')); + else setTimeout(resolve, heartbeatInterval * 1000); + }), + retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + emitStatus: (status) => this.listenerManager.announceStatus(status), + config: this._configuration, + presenceState: this.presenceState, + }); + } } - }, - emitStatus: (status) => this.listenerManager.announceStatus(status), - }); - } else { - this.subscriptionManager = new SubscriptionManager( - this._configuration, - this.listenerManager, - this.eventEmitter, - this.makeSubscribe.bind(this), - this.heartbeat.bind(this), - this.makeUnsubscribe.bind(this), - this.time.bind(this), - ); + + this.eventEngine = new EventEngine({ + handshake: this.subscribeHandshake.bind(this), + receiveMessages: this.subscribeReceiveMessages.bind(this), + delay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), + join: this.join.bind(this), + leave: this.leave.bind(this), + leaveAll: this.leaveAll.bind(this), + presenceState: this.presenceState, + config: this._configuration, + emitMessages: (events) => { + try { + events.forEach((event) => this.eventEmitter.emitEvent(event)); + } catch (e) { + const errorStatus: Status = { + error: true, + category: StatusCategory.PNUnknownCategory, + errorData: e as Error, + statusCode: 0, + }; + this.listenerManager.announceStatus(errorStatus); + } + }, + emitStatus: (status) => this.listenerManager.announceStatus(status), + }); + } else throw new Error('Event Engine error: subscription event engine module disabled'); + } else { + if (process.env.SUBSCRIBE_MANAGER_MODULE !== 'disabled') { + this.subscriptionManager = new SubscriptionManager( + this._configuration, + this.listenerManager, + this.eventEmitter, + this.makeSubscribe.bind(this), + this.heartbeat.bind(this), + this.makeUnsubscribe.bind(this), + this.time.bind(this), + ); + } else throw new Error('Subscription Manager error: subscription manager module disabled'); + } } } @@ -695,7 +714,9 @@ export class PubNubCore< channelGroups?: string[]; subscriptionOptions?: SubscriptionOptions; }): SubscriptionSet { - return new SubscriptionSet({ ...parameters, eventEmitter: this.eventEmitter, pubnub: this }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new SubscriptionSet({ ...parameters, eventEmitter: this.eventEmitter, pubnub: this }); + } else throw new Error('Subscription error: subscription event engine module disabled'); } // endregion @@ -818,10 +839,12 @@ export class PubNubCore< * @param [isOffline] - Whether `offline` presence should be notified or not. */ public destroy(isOffline?: boolean): void { - if (this.subscriptionManager) { - this.subscriptionManager.unsubscribeAll(isOffline); - this.subscriptionManager.disconnect(); - } else if (this.eventEngine) this.eventEngine.dispose(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) { + this.subscriptionManager.unsubscribeAll(isOffline); + this.subscriptionManager.disconnect(); + } else if (this.eventEngine) this.eventEngine.dispose(); + } } /** @@ -845,7 +868,8 @@ export class PubNubCore< * @param listener - Listener with event callbacks to handle different types of events. */ public addListener(listener: Listener): void { - this.listenerManager.addListener(listener); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') this.listenerManager.addListener(listener); + else throw new Error('Subscription error: subscription module disabled'); } /** @@ -854,14 +878,16 @@ export class PubNubCore< * @param listener - Event listeners which should be removed. */ public removeListener(listener: Listener): void { - this.listenerManager.removeListener(listener); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') this.listenerManager.removeListener(listener); + else throw new Error('Subscription error: subscription module disabled'); } /** * Clear all real-time event listeners. */ public removeAllListeners(): void { - this.listenerManager.removeAllListeners(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') this.listenerManager.removeAllListeners(); + else throw new Error('Subscription error: subscription module disabled'); } // endregion @@ -900,14 +926,16 @@ export class PubNubCore< parameters: Publish.PublishParameters, callback?: ResultCallback, ): Promise { - const request = new Publish.PublishRequest({ - ...parameters, - keySet: this._configuration.keySet, - crypto: this._configuration.getCryptoModule(), - }); + if (process.env.PUBLISH_MODULE !== 'disabled') { + const request = new Publish.PublishRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Publish error: publish module disabled'); } // endregion @@ -945,13 +973,15 @@ export class PubNubCore< parameters: Signal.SignalParameters, callback?: ResultCallback, ): Promise { - const request = new Signal.SignalRequest({ - ...parameters, - keySet: this._configuration.keySet, - }); + if (process.env.PUBLISH_MODULE !== 'disabled') { + const request = new Signal.SignalRequest({ + ...parameters, + keySet: this._configuration.keySet, + }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Publish error: publish module disabled'); } // endregion @@ -1011,8 +1041,10 @@ export class PubNubCore< * @returns List of active channels. */ public getSubscribedChannels(): string[] { - if (this.subscriptionManager) return this.subscriptionManager.subscribedChannels; - else if (this.eventEngine) return this.eventEngine.getSubscribedChannels(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) return this.subscriptionManager.subscribedChannels; + else if (this.eventEngine) return this.eventEngine.getSubscribedChannels(); + } else throw new Error('Subscription error: subscription module disabled'); return []; } @@ -1023,8 +1055,10 @@ export class PubNubCore< * @returns List of active channel groups. */ public getSubscribedChannelGroups(): string[] { - if (this.subscriptionManager) return this.subscriptionManager.subscribedChannelGroups; - else if (this.eventEngine) return this.eventEngine.getSubscribedChannelGroups(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) return this.subscriptionManager.subscribedChannelGroups; + else if (this.eventEngine) return this.eventEngine.getSubscribedChannelGroups(); + } else throw new Error('Subscription error: subscription module disabled'); return []; } @@ -1035,8 +1069,10 @@ export class PubNubCore< * @param parameters - Request configuration parameters. */ public subscribe(parameters: Subscription.SubscribeParameters): void { - if (this.subscriptionManager) this.subscriptionManager.subscribe(parameters); - else if (this.eventEngine) this.eventEngine.subscribe(parameters); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) this.subscriptionManager.subscribe(parameters); + else if (this.eventEngine) this.eventEngine.subscribe(parameters); + } else throw new Error('Subscription error: subscription module disabled'); } /** @@ -1051,33 +1087,35 @@ export class PubNubCore< parameters: Omit, callback: ResultCallback, ): void { - const request = new SubscribeRequest({ - ...parameters, - keySet: this._configuration.keySet, - crypto: this._configuration.getCryptoModule(), - getFileUrl: this.getFileUrl.bind(this), - }); - - this.sendRequest(request, (status, result) => { - if (this.subscriptionManager && this.subscriptionManager.abort?.identifier === request.requestIdentifier) - this.subscriptionManager.abort = null; + if (process.env.SUBSCRIBE_MANAGER_MODULE !== 'disabled') { + const request = new SubscribeRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + getFileUrl: this.getFileUrl.bind(this), + }); - callback(status, result); - }); + this.sendRequest(request, (status, result) => { + if (this.subscriptionManager && this.subscriptionManager.abort?.identifier === request.requestIdentifier) + this.subscriptionManager.abort = null; - /** - * Allow subscription cancellation. - * - * **Note:** Had to be done after scheduling because transport provider return cancellation - * controller only when schedule new request. - */ - if (this.subscriptionManager) { - // Creating identifiable abort caller. - const callableAbort = () => request.abort(); - callableAbort.identifier = request.requestIdentifier; + callback(status, result); + }); - this.subscriptionManager.abort = callableAbort; - } + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + if (this.subscriptionManager) { + // Creating identifiable abort caller. + const callableAbort = () => request.abort(); + callableAbort.identifier = request.requestIdentifier; + + this.subscriptionManager.abort = callableAbort; + } + } else throw new Error('Subscription error: subscription manager module disabled'); } /** @@ -1086,8 +1124,10 @@ export class PubNubCore< * @param parameters - Request configuration parameters. */ public unsubscribe(parameters: Presence.PresenceLeaveParameters): void { - if (this.subscriptionManager) this.subscriptionManager.unsubscribe(parameters); - else if (this.eventEngine) this.eventEngine.unsubscribe(parameters); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) this.subscriptionManager.unsubscribe(parameters); + else if (this.eventEngine) this.eventEngine.unsubscribe(parameters); + } else throw new Error('Unsubscription error: subscription module disabled'); } /** @@ -1099,29 +1139,35 @@ export class PubNubCore< * @param callback - Request completion handler callback. */ private makeUnsubscribe(parameters: Presence.PresenceLeaveParameters, callback: StatusCallback): void { - this.sendRequest( - new PresenceLeaveRequest({ - ...parameters, - keySet: this._configuration.keySet, - }), - callback, - ); + if (process.env.PRESENCE_MODULE !== 'disabled') { + this.sendRequest( + new PresenceLeaveRequest({ + ...parameters, + keySet: this._configuration.keySet, + }), + callback, + ); + } else throw new Error('Unsubscription error: presence module disabled'); } /** * Unsubscribe from all channels and groups. */ public unsubscribeAll() { - if (this.subscriptionManager) this.subscriptionManager.unsubscribeAll(); - else if (this.eventEngine) this.eventEngine.unsubscribeAll(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) this.subscriptionManager.unsubscribeAll(); + else if (this.eventEngine) this.eventEngine.unsubscribeAll(); + } else throw new Error('Unsubscription error: subscription module disabled'); } /** * Temporarily disconnect from real-time events stream. */ public disconnect(): void { - if (this.subscriptionManager) this.subscriptionManager.disconnect(); - else if (this.eventEngine) this.eventEngine.disconnect(); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) this.subscriptionManager.disconnect(); + else if (this.eventEngine) this.eventEngine.disconnect(); + } else throw new Error('Disconnection error: subscription module disabled'); } /** @@ -1131,8 +1177,10 @@ export class PubNubCore< * enabled event engine. */ public reconnect(parameters?: { timetoken?: string; region?: number }): void { - if (this.subscriptionManager) this.subscriptionManager.reconnect(); - else if (this.eventEngine) this.eventEngine.reconnect(parameters ?? {}); + if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (this.subscriptionManager) this.subscriptionManager.reconnect(); + else if (this.eventEngine) this.eventEngine.reconnect(parameters ?? {}); + } else throw new Error('Reconnection error: subscription module disabled'); } /** @@ -1141,28 +1189,30 @@ export class PubNubCore< * @param parameters - Request configuration parameters. */ private async subscribeHandshake(parameters: Subscription.CancelableSubscribeParameters) { - const request = new HandshakeSubscribeRequest({ - ...parameters, - keySet: this._configuration.keySet, - crypto: this._configuration.getCryptoModule(), - getFileUrl: this.getFileUrl.bind(this), - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const request = new HandshakeSubscribeRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + getFileUrl: this.getFileUrl.bind(this), + }); - const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); - }); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); - /** - * Allow subscription cancellation. - * - * **Note:** Had to be done after scheduling because transport provider return cancellation - * controller only when schedule new request. - */ - const handshakeResponse = this.sendRequest(request); - return handshakeResponse.then((response) => { - abortUnsubscribe(); - return response.cursor; - }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response.cursor; + }); + } else throw new Error('Subscription error: subscription event engine module disabled'); } /** @@ -1171,28 +1221,30 @@ export class PubNubCore< * @param parameters - Request configuration parameters. */ private async subscribeReceiveMessages(parameters: Subscription.CancelableSubscribeParameters) { - const request = new ReceiveMessagesSubscribeRequest({ - ...parameters, - keySet: this._configuration.keySet, - crypto: this._configuration.getCryptoModule(), - getFileUrl: this.getFileUrl.bind(this), - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const request = new ReceiveMessagesSubscribeRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + getFileUrl: this.getFileUrl.bind(this), + }); - const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); - }); + const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { + request.abort(); + }); - /** - * Allow subscription cancellation. - * - * **Note:** Had to be done after scheduling because transport provider return cancellation - * controller only when schedule new request. - */ - const handshakeResponse = this.sendRequest(request); - return handshakeResponse.then((response) => { - abortUnsubscribe(); - return response; - }); + /** + * Allow subscription cancellation. + * + * **Note:** Had to be done after scheduling because transport provider return cancellation + * controller only when schedule new request. + */ + const handshakeResponse = this.sendRequest(request); + return handshakeResponse.then((response) => { + abortUnsubscribe(); + return response; + }); + } else throw new Error('Subscription error: subscription event engine module disabled'); } // endregion @@ -1236,10 +1288,12 @@ export class PubNubCore< parameters: MessageAction.GetMessageActionsParameters, callback?: ResultCallback, ): Promise { - const request = new GetMessageActionsRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.MESSAGE_REACTIONS_MODULE !== 'disabled') { + const request = new GetMessageActionsRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Get Message Actions error: message reactions module disabled'); } // endregion @@ -1278,10 +1332,12 @@ export class PubNubCore< parameters: MessageAction.AddMessageActionParameters, callback?: ResultCallback, ): Promise { - const request = new AddMessageActionRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.MESSAGE_REACTIONS_MODULE !== 'disabled') { + const request = new AddMessageActionRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Add Message Action error: message reactions module disabled'); } // endregion @@ -1320,10 +1376,12 @@ export class PubNubCore< parameters: MessageAction.RemoveMessageActionParameters, callback?: ResultCallback, ): Promise { - const request = new RemoveMessageAction({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.MESSAGE_REACTIONS_MODULE !== 'disabled') { + const request = new RemoveMessageAction({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Remove Message Action error: message reactions module disabled'); } // endregion // endregion @@ -1366,15 +1424,17 @@ export class PubNubCore< parameters: History.FetchMessagesParameters, callback?: ResultCallback, ): Promise { - const request = new FetchMessagesRequest({ - ...parameters, - keySet: this._configuration.keySet, - crypto: this._configuration.getCryptoModule(), - getFileUrl: this.getFileUrl.bind(this), - }); + if (process.env.MESSAGE_PERSISTENCE_MODULE !== 'disabled') { + const request = new FetchMessagesRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + getFileUrl: this.getFileUrl.bind(this), + }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Fetch Messages History error: message persistence module disabled'); } // endregion @@ -1417,10 +1477,12 @@ export class PubNubCore< parameters: History.DeleteMessagesParameters, callback?: ResultCallback, ): Promise { - const request = new DeleteMessageRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.MESSAGE_PERSISTENCE_MODULE !== 'disabled') { + const request = new DeleteMessageRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Delete Messages error: message persistence module disabled'); } // endregion @@ -1457,10 +1519,12 @@ export class PubNubCore< parameters: History.MessageCountParameters, callback?: ResultCallback, ): Promise { - const request = new MessageCountRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.MESSAGE_PERSISTENCE_MODULE !== 'disabled') { + const request = new MessageCountRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Get Messages Count error: message persistence module disabled'); } // endregion @@ -1501,14 +1565,16 @@ export class PubNubCore< parameters: History.GetHistoryParameters, callback?: ResultCallback, ): Promise { - const request = new GetHistoryRequest({ - ...parameters, - keySet: this._configuration.keySet, - crypto: this._configuration.getCryptoModule(), - }); + if (process.env.MESSAGE_PERSISTENCE_MODULE !== 'disabled') { + const request = new GetHistoryRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Get Messages History error: message persistence module disabled'); } // endregion // endregion @@ -1549,10 +1615,12 @@ export class PubNubCore< parameters: Presence.HereNowParameters, callback?: ResultCallback, ): Promise { - const request = new HereNowRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const request = new HereNowRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Get Channel Here Now error: presence module disabled'); } // endregion @@ -1592,13 +1660,15 @@ export class PubNubCore< parameters: Presence.WhereNowParameters, callback?: ResultCallback, ): Promise { - const request = new WhereNowRequest({ - uuid: parameters.uuid ?? this._configuration.userId!, - keySet: this._configuration.keySet, - }); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const request = new WhereNowRequest({ + uuid: parameters.uuid ?? this._configuration.userId!, + keySet: this._configuration.keySet, + }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Get UUID Here Now error: presence module disabled'); } // endregion @@ -1635,14 +1705,16 @@ export class PubNubCore< parameters: Presence.GetPresenceStateParameters, callback?: ResultCallback, ): Promise { - const request = new GetPresenceStateRequest({ - ...parameters, - uuid: parameters.uuid ?? this._configuration.userId, - keySet: this._configuration.keySet, - }); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const request = new GetPresenceStateRequest({ + ...parameters, + uuid: parameters.uuid ?? this._configuration.userId, + keySet: this._configuration.keySet, + }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Get UUID State error: presence module disabled'); } // endregion @@ -1681,32 +1753,34 @@ export class PubNubCore< parameters: Presence.SetPresenceStateParameters | Presence.SetPresenceStateWithHeartbeatParameters, callback?: ResultCallback, ): Promise { - const { keySet, userId: userId } = this._configuration; - const heartbeat = this._configuration.getPresenceTimeout(); - let request: AbstractRequest; - - // Maintain presence information (if required). - if (this._configuration.enableEventEngine && this.presenceState) { - const presenceState = this.presenceState; - parameters.channels?.forEach((channel) => (presenceState[channel] = parameters.state)); - - if ('channelGroups' in parameters) { - parameters.channelGroups?.forEach((group) => (presenceState[group] = parameters.state)); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const { keySet, userId: userId } = this._configuration; + const heartbeat = this._configuration.getPresenceTimeout(); + let request: AbstractRequest; + + // Maintain presence information (if required). + if (this._configuration.enableEventEngine && this.presenceState) { + const presenceState = this.presenceState; + parameters.channels?.forEach((channel) => (presenceState[channel] = parameters.state)); + + if ('channelGroups' in parameters) { + parameters.channelGroups?.forEach((group) => (presenceState[group] = parameters.state)); + } } - } - // Check whether state should be set with heartbeat or not. - if ('withHeartbeat' in parameters) { - request = new HeartbeatRequest({ ...parameters, keySet, heartbeat }); - } else { - request = new SetPresenceStateRequest({ ...parameters, keySet, uuid: userId! }); - } + // Check whether state should be set with heartbeat or not. + if ('withHeartbeat' in parameters) { + request = new HeartbeatRequest({ ...parameters, keySet, heartbeat }); + } else { + request = new SetPresenceStateRequest({ ...parameters, keySet, uuid: userId! }); + } - // Update state used by subscription manager. - if (this.subscriptionManager) this.subscriptionManager.setState(parameters); + // Update state used by subscription manager. + if (this.subscriptionManager) this.subscriptionManager.setState(parameters); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Set UUID State error: presence module disabled'); } // endregion @@ -1717,7 +1791,8 @@ export class PubNubCore< * @param parameters - Desired presence state for provided list of channels and groups. */ public presence(parameters: { connected: boolean; channels?: string[]; channelGroups?: string[] }) { - this.subscriptionManager?.changePresence(parameters); + if (process.env.SUBSCRIBE_MANAGER_MODULE !== 'disabled') this.subscriptionManager?.changePresence(parameters); + else throw new Error('Change UUID presence error: subscription manager module disabled'); } // endregion @@ -1732,13 +1807,15 @@ export class PubNubCore< parameters: Presence.PresenceHeartbeatParameters, callback?: ResultCallback, ) { - const request = new HeartbeatRequest({ - ...parameters, - keySet: this._configuration.keySet, - }); + if (process.env.PRESENCE_MODULE !== 'disabled') { + const request = new HeartbeatRequest({ + ...parameters, + keySet: this._configuration.keySet, + }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Announce UUID Presence error: presence module disabled'); } // endregion @@ -1749,7 +1826,8 @@ export class PubNubCore< * @param parameters - List of channels and groups where `join` event should be sent. */ private join(parameters: { channels?: string[]; groups?: string[] }) { - this.presenceEventEngine?.join(parameters); + if (process.env.PRESENCE_MODULE !== 'disabled') this.presenceEventEngine?.join(parameters); + else throw new Error('Announce UUID Presence error: presence module disabled'); } // endregion @@ -1760,14 +1838,16 @@ export class PubNubCore< * @param parameters - List of channels and groups where `leave` event should be sent. */ private leave(parameters: { channels?: string[]; groups?: string[] }) { - this.presenceEventEngine?.leave(parameters); + if (process.env.PRESENCE_MODULE !== 'disabled') this.presenceEventEngine?.leave(parameters); + else throw new Error('Announce UUID Leave error: presence module disabled'); } /** * Announce user `leave` on all subscribed channels. */ private leaveAll() { - this.presenceEventEngine?.leaveAll(); + if (process.env.PRESENCE_MODULE !== 'disabled') this.presenceEventEngine?.leaveAll(); + else throw new Error('Announce UUID Leave error: presence module disabled'); } // endregion // endregion @@ -1813,10 +1893,12 @@ export class PubNubCore< parameters: PAM.GrantTokenParameters, callback?: ResultCallback, ): Promise { - const request = new GrantTokenRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.PAM_MODULE !== 'disabled') { + const request = new GrantTokenRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Grant Token error: PAM module disabled'); } // endregion @@ -1850,10 +1932,12 @@ export class PubNubCore< parameters: PAM.RevokeParameters, callback?: ResultCallback, ): Promise { - const request = new RevokeTokenRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.PAM_MODULE !== 'disabled') { + const request = new RevokeTokenRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Revoke Token error: PAM module disabled'); } // endregion @@ -1864,7 +1948,7 @@ export class PubNubCore< * @returns Previously configured access token using {@link setToken} method. */ public get token(): string | undefined { - return this.tokenManager.getToken(); + return this.tokenManager && this.tokenManager.getToken(); } /** @@ -1882,7 +1966,7 @@ export class PubNubCore< * @param token - New access token which should be used with next REST API endpoint calls. */ public set token(token: string | undefined) { - this.tokenManager.setToken(token); + if (this.tokenManager) this.tokenManager.setToken(token); } /** @@ -1904,7 +1988,7 @@ export class PubNubCore< * @returns Token's permissions information for the resources. */ public parseToken(token: string) { - return this.tokenManager.parseToken(token); + return this.tokenManager && this.tokenManager.parseToken(token); } // endregion @@ -1945,10 +2029,12 @@ export class PubNubCore< parameters: PAM.GrantParameters, callback?: ResultCallback, ): Promise { - const request = new GrantRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.PAM_MODULE !== 'disabled') { + const request = new GrantRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Grant error: PAM module disabled'); } // endregion @@ -1988,10 +2074,12 @@ export class PubNubCore< parameters: PAM.AuditParameters, callback?: ResultCallback, ): Promise { - const request = new AuditRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.PAM_MODULE !== 'disabled') { + const request = new AuditRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Grant Permissions error: PAM module disabled'); } // endregion // endregion @@ -2063,7 +2151,9 @@ export class PubNubCore< | ResultCallback>, callback?: ResultCallback>, ): Promise | void> { - return this.objects._getAllUUIDMetadata(parametersOrCallback, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._getAllUUIDMetadata(parametersOrCallback, callback); + else throw new Error('Fetch Users Metadata error: App Context module disabled'); } /** @@ -2121,7 +2211,9 @@ export class PubNubCore< | ResultCallback>, callback?: ResultCallback>, ): Promise | void> { - return this.objects._getUUIDMetadata(parametersOrCallback, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._getUUIDMetadata(parametersOrCallback, callback); + else throw new Error('Fetch User Metadata error: App Context module disabled'); } /** @@ -2167,7 +2259,8 @@ export class PubNubCore< parameters: AppContext.SetUUIDMetadataParameters, callback?: ResultCallback>, ): Promise | void> { - return this.objects._setUUIDMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') return this.objects._setUUIDMetadata(parameters, callback); + else throw new Error('Create User Metadata error: App Context module disabled'); } /** @@ -2213,7 +2306,8 @@ export class PubNubCore< parameters: AppContext.SetUUIDMetadataParameters, callback?: ResultCallback>, ): Promise | void> { - return this.objects._setUUIDMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') return this.objects._setUUIDMetadata(parameters, callback); + else throw new Error('Update User Metadata error: App Context module disabled'); } /** @@ -2270,7 +2364,9 @@ export class PubNubCore< | ResultCallback, callback?: ResultCallback, ): Promise { - return this.objects._removeUUIDMetadata(parametersOrCallback, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._removeUUIDMetadata(parametersOrCallback, callback); + else throw new Error('Remove User Metadata error: App Context module disabled'); } /** @@ -2327,7 +2423,9 @@ export class PubNubCore< | ResultCallback>, callback?: ResultCallback>, ): Promise | void> { - return this.objects._getAllChannelMetadata(parametersOrCallback, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') + return this.objects._getAllChannelMetadata(parametersOrCallback, callback); + else throw new Error('Fetch Spaces Metadata error: App Context module disabled'); } /** @@ -2370,7 +2468,8 @@ export class PubNubCore< parameters: AppContext.GetChannelMetadataParameters, callback?: ResultCallback>, ): Promise | void> { - return this.objects._getChannelMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') return this.objects._getChannelMetadata(parameters, callback); + else throw new Error('Fetch Space Metadata error: App Context module disabled'); } /** @@ -2413,7 +2512,8 @@ export class PubNubCore< parameters: AppContext.SetChannelMetadataParameters, callback?: ResultCallback>, ): Promise | void> { - return this.objects._setChannelMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') return this.objects._setChannelMetadata(parameters, callback); + else throw new Error('Create Space Metadata error: App Context module disabled'); } /** @@ -2456,7 +2556,8 @@ export class PubNubCore< parameters: AppContext.SetChannelMetadataParameters, callback?: ResultCallback>, ): Promise | void> { - return this.objects._setChannelMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') return this.objects._setChannelMetadata(parameters, callback); + else throw new Error('Update Space Metadata error: App Context module disabled'); } /** @@ -2500,7 +2601,8 @@ export class PubNubCore< parameters: AppContext.RemoveChannelMetadataParameters, callback?: ResultCallback, ): Promise { - return this.objects._removeChannelMetadata(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') return this.objects._removeChannelMetadata(parameters, callback); + else throw new Error('Remove Space Metadata error: App Context module disabled'); } /** @@ -2569,7 +2671,8 @@ export class PubNubCore< | AppContext.UserMembersResponse | void > { - return this.objects.fetchMemberships(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') return this.objects.fetchMemberships(parameters, callback); + else throw new Error('Fetch Memberships error: App Context module disabled'); } /** @@ -2631,7 +2734,8 @@ export class PubNubCore< AppContext.SetMembershipsResponse | AppContext.SetMembersResponse >, ) { - return this.objects.addMemberships(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') return this.objects.addMemberships(parameters, callback); + else throw new Error('Add Memberships error: App Context module disabled'); } /** @@ -2693,7 +2797,8 @@ export class PubNubCore< AppContext.SetMembershipsResponse | AppContext.SetMembersResponse >, ) { - return this.objects.addMemberships(parameters, callback); + if (process.env.APP_CONTEXT_MODULE !== 'disabled') return this.objects.addMemberships(parameters, callback); + else throw new Error('Update Memberships error: App Context module disabled'); } /** @@ -2761,25 +2866,27 @@ export class PubNubCore< | AppContext.RemoveMembershipsResponse | void > { - if ('spaceId' in parameters) { - const spaceParameters = parameters as AppContext.RemoveMembersParameters; + if (process.env.APP_CONTEXT_MODULE !== 'disabled') { + if ('spaceId' in parameters) { + const spaceParameters = parameters as AppContext.RemoveMembersParameters; + const requestParameters = { + channel: spaceParameters.spaceId ?? spaceParameters.channel, + uuids: spaceParameters.userIds ?? spaceParameters.uuids, + limit: 0, + }; + if (callback) return this.objects.removeChannelMembers(requestParameters, callback); + return this.objects.removeChannelMembers(requestParameters); + } + + const userParameters = parameters as AppContext.RemoveMembershipsParameters; const requestParameters = { - channel: spaceParameters.spaceId ?? spaceParameters.channel, - uuids: spaceParameters.userIds ?? spaceParameters.uuids, + uuid: userParameters.userId, + channels: userParameters.spaceIds ?? userParameters.channels, limit: 0, }; - if (callback) return this.objects.removeChannelMembers(requestParameters, callback); - return this.objects.removeChannelMembers(requestParameters); - } - - const userParameters = parameters as AppContext.RemoveMembershipsParameters; - const requestParameters = { - uuid: userParameters.userId, - channels: userParameters.spaceIds ?? userParameters.channels, - limit: 0, - }; - if (callback) return this.objects.removeMemberships(requestParameters, callback); - return this.objects.removeMemberships(requestParameters); + if (callback) return this.objects.removeMemberships(requestParameters, callback); + return this.objects.removeMemberships(requestParameters); + } else throw new Error('Remove Memberships error: App Context module disabled'); } // endregion // endregion @@ -2850,46 +2957,48 @@ export class PubNubCore< parameters: FileSharing.SendFileParameters, callback?: ResultCallback, ): Promise { - if (!this._configuration.PubNubFile) - throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - - const sendFileRequest = new SendFileRequest({ - ...parameters, - keySet: this._configuration.keySet, - PubNubFile: this._configuration.PubNubFile, - fileUploadPublishRetryLimit: this._configuration.fileUploadPublishRetryLimit, - file: parameters.file, - sendRequest: this.sendRequest.bind(this), - publishFile: this.publishFile.bind(this), - crypto: this._configuration.getCryptoModule(), - cryptography: this.cryptography ? (this.cryptography as Cryptography) : undefined, - }); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - const status: Status = { - error: false, - operation: RequestOperation.PNPublishFileOperation, - category: StatusCategory.PNAcknowledgmentCategory, - statusCode: 0, - }; + const sendFileRequest = new SendFileRequest({ + ...parameters, + keySet: this._configuration.keySet, + PubNubFile: this._configuration.PubNubFile, + fileUploadPublishRetryLimit: this._configuration.fileUploadPublishRetryLimit, + file: parameters.file, + sendRequest: this.sendRequest.bind(this), + publishFile: this.publishFile.bind(this), + crypto: this._configuration.getCryptoModule(), + cryptography: this.cryptography ? (this.cryptography as Cryptography) : undefined, + }); - return sendFileRequest - .process() - .then((response) => { - status.statusCode = response.status; + const status: Status = { + error: false, + operation: RequestOperation.PNPublishFileOperation, + category: StatusCategory.PNAcknowledgmentCategory, + statusCode: 0, + }; - if (callback) return callback(status, response); - return response; - }) - .catch((error: unknown) => { - let errorStatus: Status | undefined; - if (error instanceof PubNubError) errorStatus = error.status; - else if (error instanceof PubNubAPIError) errorStatus = error.toStatus(status.operation!); + return sendFileRequest + .process() + .then((response) => { + status.statusCode = response.status; - // Notify callback (if possible). - if (callback && errorStatus) callback(errorStatus, null); + if (callback) return callback(status, response); + return response; + }) + .catch((error: unknown) => { + let errorStatus: Status | undefined; + if (error instanceof PubNubError) errorStatus = error.status; + else if (error instanceof PubNubAPIError) errorStatus = error.toStatus(status.operation!); - throw new PubNubError('REST API request processing error, check status for details', errorStatus); - }); + // Notify callback (if possible). + if (callback && errorStatus) callback(errorStatus, null); + + throw new PubNubError('REST API request processing error, check status for details', errorStatus); + }); + } else throw new Error('Send File error: file sharing module disabled'); } // endregion @@ -2928,17 +3037,19 @@ export class PubNubCore< parameters: FileSharing.PublishFileMessageParameters, callback?: ResultCallback, ): Promise { - if (!this._configuration.PubNubFile) - throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - const request = new PublishFileMessageRequest({ - ...parameters, - keySet: this._configuration.keySet, - crypto: this._configuration.getCryptoModule(), - }); + const request = new PublishFileMessageRequest({ + ...parameters, + keySet: this._configuration.keySet, + crypto: this._configuration.getCryptoModule(), + }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Publish File error: file sharing module disabled'); } // endregion @@ -2975,10 +3086,12 @@ export class PubNubCore< parameters: FileSharing.ListFilesParameters, callback?: ResultCallback, ): Promise { - const request = new FilesListRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + const request = new FilesListRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('List Files error: file sharing module disabled'); } // endregion @@ -2991,20 +3104,22 @@ export class PubNubCore< * @returns File download Url. */ public getFileUrl(parameters: FileSharing.FileUrlParameters): FileSharing.FileUrlResponse { - const request = this.transport.request( - new GetFileDownloadUrlRequest({ ...parameters, keySet: this._configuration.keySet }).request(), - ); - const query = request.queryParameters ?? {}; - const queryString = Object.keys(query) - .map((key) => { - const queryValue = query[key]; - if (!Array.isArray(queryValue)) return `${key}=${encodeString(queryValue)}`; - - return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); - }) - .join('&'); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + const request = this.transport.request( + new GetFileDownloadUrlRequest({ ...parameters, keySet: this._configuration.keySet }).request(), + ); + const query = request.queryParameters ?? {}; + const queryString = Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) return `${key}=${encodeString(queryValue)}`; - return `${request.origin}${request.path}?${queryString}`; + return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); + }) + .join('&'); + + return `${request.origin}${request.path}?${queryString}`; + } else throw new Error('Generate File Download Url error: file sharing module disabled'); } // endregion @@ -3038,19 +3153,21 @@ export class PubNubCore< parameters: FileSharing.DownloadFileParameters, callback?: ResultCallback, ): Promise { - if (!this._configuration.PubNubFile) - throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + if (!this._configuration.PubNubFile) + throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform."); - const request = new DownloadFileRequest({ - ...parameters, - keySet: this._configuration.keySet, - PubNubFile: this._configuration.PubNubFile, - cryptography: this.cryptography ? (this.cryptography as Cryptography) : undefined, - crypto: this._configuration.getCryptoModule(), - }); + const request = new DownloadFileRequest({ + ...parameters, + keySet: this._configuration.keySet, + PubNubFile: this._configuration.PubNubFile, + cryptography: this.cryptography ? (this.cryptography as Cryptography) : undefined, + crypto: this._configuration.getCryptoModule(), + }); - if (callback) return this.sendRequest(request, callback); - return (await this.sendRequest(request)) as PlatformFile; + if (callback) return this.sendRequest(request, callback); + return (await this.sendRequest(request)) as PlatformFile; + } else throw new Error('Download File error: file sharing module disabled'); } // endregion @@ -3087,10 +3204,12 @@ export class PubNubCore< parameters: FileSharing.DeleteFileParameters, callback?: ResultCallback, ): Promise { - const request = new DeleteFileRequest({ ...parameters, keySet: this._configuration.keySet }); + if (process.env.FILE_SHARING_MODULE !== 'disabled') { + const request = new DeleteFileRequest({ ...parameters, keySet: this._configuration.keySet }); - if (callback) return this.sendRequest(request, callback); - return this.sendRequest(request); + if (callback) return this.sendRequest(request, callback); + return this.sendRequest(request); + } else throw new Error('Delete File error: file sharing module disabled'); } // endregion // endregion @@ -3156,7 +3275,9 @@ export class PubNubCore< if (!this.crypto) throw new Error('Encryption error: cypher key not set'); - return this.crypto.encrypt(data, customCipherKey); + if (process.env.CRYPTO_MODULE !== 'disabled') { + return this.crypto.encrypt(data, customCipherKey); + } else throw new Error('Encryption error: crypto module disabled'); } /** @@ -3178,7 +3299,9 @@ export class PubNubCore< if (!this.crypto) throw new Error('Decryption error: cypher key not set'); - return this.crypto.decrypt(data, customCipherKey); + if (process.env.CRYPTO_MODULE !== 'disabled') { + return this.crypto.decrypt(data, customCipherKey); + } else throw new Error('Decryption error: crypto module disabled'); } // endregion @@ -3233,10 +3356,14 @@ export class PubNubCore< if (typeof keyOrFile === 'string') { if (!this.cryptography) throw new Error('File encryption error. File encryption not available'); - return this.cryptography.encryptFile(keyOrFile, file, this._configuration.PubNubFile); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + return this.cryptography.encryptFile(keyOrFile, file, this._configuration.PubNubFile); + else throw new Error('Encryption error: file sharing module disabled'); } - return this._configuration.getCryptoModule()?.encryptFile(file, this._configuration.PubNubFile); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + return this._configuration.getCryptoModule()?.encryptFile(file, this._configuration.PubNubFile); + else throw new Error('Encryption error: file sharing module disabled'); } /** @@ -3290,10 +3417,14 @@ export class PubNubCore< if (typeof keyOrFile === 'string') { if (!this.cryptography) throw new Error('File decryption error. File decryption not available'); - return this.cryptography.decryptFile(keyOrFile, file, this._configuration.PubNubFile); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + return this.cryptography.decryptFile(keyOrFile, file, this._configuration.PubNubFile); + else throw new Error('Decryption error: file sharing module disabled'); } - return this._configuration.getCryptoModule()?.decryptFile(file, this._configuration.PubNubFile); + if (process.env.FILE_SHARING_MODULE !== 'disabled') + return this._configuration.getCryptoModule()?.decryptFile(file, this._configuration.PubNubFile); + else throw new Error('Decryption error: file sharing module disabled'); } // endregion // endregion diff --git a/src/entities/Channel.ts b/src/entities/Channel.ts index 5e09713a0..9816b113c 100644 --- a/src/entities/Channel.ts +++ b/src/entities/Channel.ts @@ -15,12 +15,14 @@ export class Channel { } subscription(subscriptionOptions?: SubscriptionOptions) { - return new Subscription({ - channels: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new Subscription({ + channels: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } else throw new Error('Subscription error: subscription event engine module disabled'); } } diff --git a/src/entities/ChannelGroup.ts b/src/entities/ChannelGroup.ts index ff6671ba8..fa6cba92c 100644 --- a/src/entities/ChannelGroup.ts +++ b/src/entities/ChannelGroup.ts @@ -15,12 +15,14 @@ export class ChannelGroup { } subscription(subscriptionOptions?: SubscriptionOptions) { - return new Subscription({ - channels: [], - channelGroups: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new Subscription({ + channels: [], + channelGroups: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } else throw new Error('Subscription error: subscription event engine module disabled'); } } diff --git a/src/entities/ChannelMetadata.ts b/src/entities/ChannelMetadata.ts index a06bfffa1..14b78666d 100644 --- a/src/entities/ChannelMetadata.ts +++ b/src/entities/ChannelMetadata.ts @@ -11,12 +11,14 @@ export class ChannelMetadata { ) {} subscription(subscriptionOptions?: SubscriptionOptions) { - return new Subscription({ - channels: [this.id], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } else throw new Error('Subscription error: subscription module disabled'); } } diff --git a/src/entities/UserMetadata.ts b/src/entities/UserMetadata.ts index abc11abac..256950823 100644 --- a/src/entities/UserMetadata.ts +++ b/src/entities/UserMetadata.ts @@ -11,12 +11,14 @@ export class UserMetadata { ) {} subscription(subscriptionOptions?: SubscriptionOptions) { - return new Subscription({ - channels: [this.id], - channelGroups: [], - subscriptionOptions: subscriptionOptions, - eventEmitter: this.eventEmitter, - pubnub: this.pubnub, - }); + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + return new Subscription({ + channels: [this.id], + channelGroups: [], + subscriptionOptions: subscriptionOptions, + eventEmitter: this.eventEmitter, + pubnub: this.pubnub, + }); + } else throw new Error('Subscription error: subscription event engine module disabled'); } } diff --git a/src/node/index.ts b/src/node/index.ts index 63f3b1d4f..bd988cabe 100755 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -4,6 +4,8 @@ import { Readable } from 'stream'; import { Buffer } from 'buffer'; import { CryptoModule, LegacyCryptor, AesCbcCryptor } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; +import type { CryptoModule as CryptoModuleType } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; + import PubNubFile, { PubNubFileParameters } from '../file/modules/node'; import { CryptorConfiguration } from '../core/interfaces/crypto-module'; import { makeConfiguration } from '../core/components/configuration'; @@ -18,6 +20,8 @@ import Crypto from '../core/components/cryptography'; import { PubNubError } from '../errors/pubnub-error'; import { PubNubCore } from '../core/pubnub-common'; import Cbor from '../cbor/common'; +import { ExtendedConfiguration, PlatformConfiguration } from '../core/interfaces/configuration'; +import { Cryptography } from '../core/interfaces/cryptography'; /** * PubNub client for Node.js platform. @@ -26,7 +30,8 @@ class PubNub extends PubNubCore { if (!cryptoConfiguration.cipherKey) return undefined; - return new CryptoModule({ - default: new LegacyCryptor({ ...cryptoConfiguration }), - cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], - }); + if (process.env.CRYPTO_MODULE !== 'disabled') { + return new CryptoModule({ + default: new LegacyCryptor({ ...cryptoConfiguration }), + cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], + }); + } else return undefined; }, ); // Prepare Token manager. - const tokenManager = new TokenManager( - new Cbor((buffer: ArrayBuffer) => CborReader.decode(Buffer.from(buffer)), decode), - ); + let tokenManager: TokenManager | undefined; + if (process.env.CRYPTO_MODULE !== 'disabled') { + tokenManager = new TokenManager( + new Cbor((buffer: ArrayBuffer) => CborReader.decode(Buffer.from(buffer)), decode), + ); + } // Legacy crypto (legacy data encryption / decryption and request signature support). - const crypto = new Crypto({ - secretKey: clientConfiguration.secretKey, - cipherKey: clientConfiguration.getCipherKey(), - useRandomIVs: clientConfiguration.getUseRandomIVs(), - customEncrypt: clientConfiguration.getCustomEncrypt(), - customDecrypt: clientConfiguration.getCustomDecrypt(), - }); + let crypto: Crypto | undefined; + if (process.env.CRYPTO_MODULE !== 'disabled') { + crypto = new Crypto({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } + + let cryptography: Cryptography | undefined; + if (process.env.CRYPTO_MODULE !== 'disabled') cryptography = new NodeCryptography(); // Setup transport provider. const transport = new NodeTransport(configuration.keepAlive, configuration.keepAliveSettings); @@ -75,13 +96,13 @@ class PubNub extends PubNubCore { constructor(configuration: PubNubConfiguration) { const configurationCopy = setDefaults(configuration); - const platformConfiguration = { ...configurationCopy, sdkFamily: 'ReactNative', PubNubFile }; + const platformConfiguration: ExtendedConfiguration & PlatformConfiguration = { + ...configurationCopy, + sdkFamily: 'ReactNative', + }; + + if (process.env.FILE_SHARING_MODULE !== 'disabled') platformConfiguration.PubNubFile = PubNubFile; // Prepare full client configuration. const clientConfiguration = makeConfiguration(platformConfiguration); // Prepare Token manager. - const tokenManager = new TokenManager( - new Cbor((arrayBuffer: ArrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode), - ); + let tokenManager: TokenManager | undefined; + if (process.env.CRYPTO_MODULE !== 'disabled') { + tokenManager = new TokenManager( + new Cbor((arrayBuffer: ArrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode), + ); + } // Legacy crypto (legacy data encryption / decryption and request signature support). let crypto: Crypto | undefined; - if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { - crypto = new Crypto({ - secretKey: clientConfiguration.secretKey, - cipherKey: clientConfiguration.getCipherKey(), - useRandomIVs: clientConfiguration.getUseRandomIVs(), - customEncrypt: clientConfiguration.getCustomEncrypt(), - customDecrypt: clientConfiguration.getCustomDecrypt(), - }); + if (process.env.CRYPTO_MODULE !== 'disabled') { + if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { + crypto = new Crypto({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } } // Setup transport layer. diff --git a/src/titanium/index.ts b/src/titanium/index.ts index 36b890d91..008a82735 100644 --- a/src/titanium/index.ts +++ b/src/titanium/index.ts @@ -20,9 +20,13 @@ export class PubNub extends PubNubCore { const clientConfiguration = makeConfiguration(platformConfiguration); // Prepare Token manager. - const tokenManager = new TokenManager( - new Cbor(CborReader.decode, (base64String: string) => Buffer.from(base64String, 'base64')), - ); + + let tokenManager: TokenManager | undefined; + if (process.env.CRYPTO_MODULE !== 'disabled') { + tokenManager = new TokenManager( + new Cbor(CborReader.decode, (base64String: string) => Buffer.from(base64String, 'base64')), + ); + } // Setup transport layer. const transportMiddleware = new PubNubMiddleware({ diff --git a/src/transport/middleware.ts b/src/transport/middleware.ts index dacbd336f..88114e3f8 100644 --- a/src/transport/middleware.ts +++ b/src/transport/middleware.ts @@ -17,7 +17,7 @@ type PubNubMiddlewareConfiguration = { /** * REST API endpoints access tokens manager. */ - tokenManager: TokenManager; + tokenManager?: TokenManager; /** * HMAC-SHA256 hash generator from provided `data`. @@ -30,7 +30,12 @@ type PubNubMiddlewareConfiguration = { transport: Transport; }; -export class RequestSignature { +/** + * Request signature generator. + * + * @internal + */ +class RequestSignature { private static textDecoder = new TextDecoder('utf-8'); constructor( private publishKey: string, @@ -101,8 +106,10 @@ export class PubNubMiddleware implements Transport { shaHMAC, } = configuration; - if (keySet.secretKey && shaHMAC) - this.signatureGenerator = new RequestSignature(keySet.publishKey!, keySet.secretKey, shaHMAC); + if (process.env.CRYPTO_MODULE !== 'disabled') { + if (keySet.secretKey && shaHMAC) + this.signatureGenerator = new RequestSignature(keySet.publishKey!, keySet.secretKey, shaHMAC); + } } makeSendable(req: TransportRequest) { @@ -137,7 +144,7 @@ export class PubNubMiddleware implements Transport { if (req.path.startsWith('/v2/auth/') || req.path.startsWith('/v3/pam/') || req.path.startsWith('/time')) return; const { clientConfiguration, tokenManager } = this.configuration; - const accessKey = tokenManager.getToken() ?? clientConfiguration.authKey; + const accessKey = (tokenManager && tokenManager.getToken()) ?? clientConfiguration.authKey; if (accessKey) req.queryParameters!['auth'] = accessKey; } diff --git a/src/web/index.ts b/src/web/index.ts index 7cf367027..68993eee4 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -5,7 +5,10 @@ import CborReader from 'cbor-js'; // eslint-disable-next-line max-len import { AesCbcCryptor, LegacyCryptor, WebCryptoModule } from '../crypto/modules/WebCryptoModule/webCryptoModule'; +import type { WebCryptoModule as CryptoModuleType } from '../crypto/modules/WebCryptoModule/webCryptoModule'; + import { SubscriptionWorkerMiddleware } from '../transport/subscription-worker/subscription-worker-middleware'; +import { ExtendedConfiguration, PlatformConfiguration } from '../core/interfaces/configuration'; import { WebReactNativeTransport } from '../transport/web-react-native-transport'; import { stringifyBufferKeys } from '../core/components/stringify_buffer_keys'; import { PubNubConfiguration, setDefaults } from './components/configuration'; @@ -13,6 +16,7 @@ import { CryptorConfiguration } from '../core/interfaces/crypto-module'; import { PubNubFile, PubNubFileParameters } from '../file/modules/web'; import { makeConfiguration } from '../core/components/configuration'; import { TokenManager } from '../core/components/token_manager'; +import { Cryptography } from '../core/interfaces/cryptography'; import { PubNubMiddleware } from '../transport/middleware'; import { decode } from '../core/components/base64_codec'; import { Transport } from '../core/interfaces/transport'; @@ -28,11 +32,17 @@ export default class PubNub extends PubNubCore { if (!cryptoConfiguration.cipherKey) return undefined; - return new WebCryptoModule({ - default: new LegacyCryptor({ ...cryptoConfiguration }), - cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], - }); + if (process.env.CRYPTO_MODULE !== 'disabled') { + return new WebCryptoModule({ + default: new LegacyCryptor({ ...cryptoConfiguration }), + cryptors: [new AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], + }); + } else return undefined; }, ); // Prepare Token manager. - const tokenManager = new TokenManager( - new Cbor((arrayBuffer: ArrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode), - ); + let tokenManager: TokenManager | undefined; + if (process.env.CRYPTO_MODULE !== 'disabled') { + tokenManager = new TokenManager( + new Cbor((arrayBuffer: ArrayBuffer) => stringifyBufferKeys(CborReader.decode(arrayBuffer)), decode), + ); + } // Legacy crypto (legacy data encryption / decryption and request signature support). let crypto: Crypto | undefined; - if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { - crypto = new Crypto({ - secretKey: clientConfiguration.secretKey, - cipherKey: clientConfiguration.getCipherKey(), - useRandomIVs: clientConfiguration.getUseRandomIVs(), - customEncrypt: clientConfiguration.getCustomEncrypt(), - customDecrypt: clientConfiguration.getCustomDecrypt(), - }); + if (process.env.CRYPTO_MODULE !== 'disabled') { + if (clientConfiguration.getCipherKey() || clientConfiguration.secretKey) { + crypto = new Crypto({ + secretKey: clientConfiguration.secretKey, + cipherKey: clientConfiguration.getCipherKey(), + useRandomIVs: clientConfiguration.getUseRandomIVs(), + customEncrypt: clientConfiguration.getCustomEncrypt(), + customDecrypt: clientConfiguration.getCustomDecrypt(), + }); + } } + let cryptography: Cryptography | undefined; + if (process.env.CRYPTO_MODULE !== 'disabled') cryptography = new WebCryptography(); + // Setup transport provider. let transport: Transport = new WebReactNativeTransport( clientConfiguration.keepAlive, clientConfiguration.logVerbosity!, ); - if (configurationCopy.subscriptionWorkerUrl) { - // Inject subscription worker into transport provider stack. - transport = new SubscriptionWorkerMiddleware({ - clientIdentifier: clientConfiguration._instanceId, - subscriptionKey: clientConfiguration.subscribeKey, - userId: clientConfiguration.getUserId(), - workerUrl: configurationCopy.subscriptionWorkerUrl, - sdkVersion: clientConfiguration.getVersion(), - logVerbosity: clientConfiguration.logVerbosity!, - workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity!, - transport, - }); + if (process.env.SHARED_WORKER !== 'disabled') { + if (configurationCopy.subscriptionWorkerUrl) { + // Inject subscription worker into transport provider stack. + transport = new SubscriptionWorkerMiddleware({ + clientIdentifier: clientConfiguration._instanceId, + subscriptionKey: clientConfiguration.subscribeKey, + userId: clientConfiguration.getUserId(), + workerUrl: configurationCopy.subscriptionWorkerUrl, + sdkVersion: clientConfiguration.getVersion(), + logVerbosity: clientConfiguration.logVerbosity!, + workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity!, + transport, + }); + } } const transportMiddleware = new PubNubMiddleware({ @@ -93,7 +115,7 @@ export default class PubNub extends PubNubCore Date: Wed, 22 May 2024 22:03:48 +0300 Subject: [PATCH 09/49] Fix revoke token method signature (#375) fix(pam): fix revoke token method signature Fix revoke token method signature where mistakenly expected object with `token` field. refactor(typo): fix typo in PAM types file name --- .pubnub.yml | 11 ++++++++--- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- dist/web/pubnub.js | 6 +++--- dist/web/pubnub.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/pubnub-common.js | 6 +++--- .../api/{access-panager.js => access-manager.js} | 0 lib/types/core/pubnub-common.d.ts | 10 +++++----- .../{access-panager.d.ts => access-manager.d.ts} | 10 ++++------ package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/endpoints/access_manager/audit.ts | 2 +- src/core/endpoints/access_manager/grant.ts | 2 +- src/core/endpoints/access_manager/grant_token.ts | 2 +- .../endpoints/access_manager/revoke_token.ts | 9 +++++++-- src/core/pubnub-common.ts | 16 ++++++++-------- .../api/{access-panager.ts => access-manager.ts} | 10 ++++------ 18 files changed, 57 insertions(+), 45 deletions(-) rename lib/core/types/api/{access-panager.js => access-manager.js} (100%) rename lib/types/core/types/api/{access-panager.d.ts => access-manager.d.ts} (98%) rename src/core/types/api/{access-panager.ts => access-manager.ts} (99%) diff --git a/.pubnub.yml b/.pubnub.yml index 5b4612835..489811ed3 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-05-22 + version: v8.2.1 + changes: + - type: bug + text: "Fix revoke token method signature where mistakenly expected object with `token` field." - date: 2024-05-21 version: v8.2.0 changes: @@ -988,7 +993,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.0' +version: '8.2.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1004,7 +1009,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1675,7 +1680,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.0/pubnub.8.2.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.1/pubnub.8.2.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 911e9a8e3..ac31c1334 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.2.1 +May 22 2024 + +#### Fixed +- Fix revoke token method signature where mistakenly expected object with `token` field. + ## v8.2.0 May 21 2024 diff --git a/README.md b/README.md index dae175213..7207ae881 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 7d4b13c81..dbddf2998 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3810,7 +3810,7 @@ return base.PubNubFile; }, get version() { - return '8.2.0'; + return '8.2.1'; }, getVersion() { return this.version; @@ -12234,12 +12234,12 @@ /** * Revoke token permission. * - * @param parameters - Request configuration parameters. + * @param token - Access token for which permissions should be revoked. * @param [callback] - Request completion handler callback. * * @returns Asynchronous revoke token response or `void` in case if `callback` provided. */ - revokeToken(parameters, callback) { + revokeToken(token, callback) { return __awaiter(this, void 0, void 0, function* () { throw new Error('Revoke Token error: PAM module disabled'); }); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 59c290431..37a11ceb2 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.restore)&&void 0!==i||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(a=m.suppressLeaveEvents)&&void 0!==a||(m.suppressLeaveEvents=!1),null!==(c=m.requestMessageCountThreshold)&&void 0!==c||(m.requestMessageCountThreshold=100),null!==(u=m.autoNetworkDetection)&&void 0!==u||(m.autoNetworkDetection=!1),null!==(l=m.enableEventEngine)&&void 0!==l||(m.enableEventEngine=!1),null!==(h=m.maintainPresenceState)&&void 0!==h||(m.maintainPresenceState=!0),null!==(p=m.keepAlive)&&void 0!==p||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=m.userId)&&void 0!==g||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=m.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),null!==(f=m.presenceTimeout)&&void 0!==f||(m.presenceTimeout=300);let v=!1,w=!0,S=5,k=!1,E=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(E=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:100,useRequestId:E,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 7d1957fb2..308df22b1 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.0'; + return '8.2.1'; }, getVersion() { return this.version; diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 126b2233d..4bf9662d1 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -1267,15 +1267,15 @@ class PubNubCore { /** * Revoke token permission. * - * @param parameters - Request configuration parameters. + * @param token - Access token for which permissions should be revoked. * @param [callback] - Request completion handler callback. * * @returns Asynchronous revoke token response or `void` in case if `callback` provided. */ - revokeToken(parameters, callback) { + revokeToken(token, callback) { return __awaiter(this, void 0, void 0, function* () { if (process.env.PAM_MODULE !== 'disabled') { - const request = new revoke_token_1.RevokeTokenRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + const request = new revoke_token_1.RevokeTokenRequest({ token, keySet: this._configuration.keySet }); if (callback) return this.sendRequest(request, callback); return this.sendRequest(request); diff --git a/lib/core/types/api/access-panager.js b/lib/core/types/api/access-manager.js similarity index 100% rename from lib/core/types/api/access-panager.js rename to lib/core/types/api/access-manager.js diff --git a/lib/types/core/pubnub-common.d.ts b/lib/types/core/pubnub-common.d.ts index 4f2f2bbc6..f9bb4df1c 100644 --- a/lib/types/core/pubnub-common.d.ts +++ b/lib/types/core/pubnub-common.d.ts @@ -17,7 +17,7 @@ import * as History from './types/api/history'; import * as MessageAction from './types/api/message-action'; import * as FileSharing from './types/api/file-sharing'; import { PubNubFileInterface } from './types/file'; -import * as PAM from './types/api/access-panager'; +import * as PAM from './types/api/access-manager'; import { SubscriptionOptions } from '../entities/commonTypes'; import { ChannelMetadata } from '../entities/ChannelMetadata'; import { SubscriptionSet } from '../entities/SubscriptionSet'; @@ -692,18 +692,18 @@ export declare class PubNubCore): void; + revokeToken(token: PAM.RevokeParameters, callback: ResultCallback): void; /** * Revoke token permission. * - * @param parameters - Request configuration parameters. + * @param token - Access token for which permissions should be revoked. * * @returns Asynchronous revoke token response. */ - revokeToken(parameters: PAM.RevokeParameters): Promise; + revokeToken(token: PAM.RevokeParameters): Promise; /** * Get current access token. * diff --git a/lib/types/core/types/api/access-panager.d.ts b/lib/types/core/types/api/access-manager.d.ts similarity index 98% rename from lib/types/core/types/api/access-panager.d.ts rename to lib/types/core/types/api/access-manager.d.ts index 36f4c5ca4..bf85bda51 100644 --- a/lib/types/core/types/api/access-panager.d.ts +++ b/lib/types/core/types/api/access-manager.d.ts @@ -188,12 +188,10 @@ export type GrantTokenParameters = { * Response with generated access token. */ export type GrantTokenResponse = string; -export type RevokeParameters = { - /** - * Access token for which permissions should be revoked. - */ - token: string; -}; +/** + * Access token for which permissions should be revoked. + */ +export type RevokeParameters = string; /** * Response with revoked access token. */ diff --git a/package.json b/package.json index 7a4bdf3c1..c1c1089aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.0", + "version": "8.2.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 5581bdc30..00f926b17 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.0'; + return '8.2.1'; }, getVersion(): string { return this.version; diff --git a/src/core/endpoints/access_manager/audit.ts b/src/core/endpoints/access_manager/audit.ts index bfcea42d3..7229a0e6f 100644 --- a/src/core/endpoints/access_manager/audit.ts +++ b/src/core/endpoints/access_manager/audit.ts @@ -7,7 +7,7 @@ import { TransportResponse } from '../../types/transport-response'; import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; -import * as PAM from '../../types/api/access-panager'; +import * as PAM from '../../types/api/access-manager'; import { KeySet, Query } from '../../types/api'; // -------------------------------------------------------- diff --git a/src/core/endpoints/access_manager/grant.ts b/src/core/endpoints/access_manager/grant.ts index bf83c69b1..687ca08ce 100644 --- a/src/core/endpoints/access_manager/grant.ts +++ b/src/core/endpoints/access_manager/grant.ts @@ -7,7 +7,7 @@ import { TransportResponse } from '../../types/transport-response'; import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; -import * as PAM from '../../types/api/access-panager'; +import * as PAM from '../../types/api/access-manager'; import { KeySet, Query } from '../../types/api'; // -------------------------------------------------------- diff --git a/src/core/endpoints/access_manager/grant_token.ts b/src/core/endpoints/access_manager/grant_token.ts index 86a8132c3..44c9f0089 100644 --- a/src/core/endpoints/access_manager/grant_token.ts +++ b/src/core/endpoints/access_manager/grant_token.ts @@ -8,7 +8,7 @@ import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { TransportMethod } from '../../types/transport-request'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; -import * as PAM from '../../types/api/access-panager'; +import * as PAM from '../../types/api/access-manager'; import { KeySet } from '../../types/api'; // -------------------------------------------------------- diff --git a/src/core/endpoints/access_manager/revoke_token.ts b/src/core/endpoints/access_manager/revoke_token.ts index 0063dab80..74b1d0f2d 100644 --- a/src/core/endpoints/access_manager/revoke_token.ts +++ b/src/core/endpoints/access_manager/revoke_token.ts @@ -8,7 +8,7 @@ import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { TransportMethod } from '../../types/transport-request'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; -import * as PAM from '../../types/api/access-panager'; +import * as PAM from '../../types/api/access-manager'; import { encodeString } from '../../utils'; import { KeySet } from '../../types/api'; @@ -20,7 +20,12 @@ import { KeySet } from '../../types/api'; /** * Request configuration parameters. */ -type RequestParameters = PAM.RevokeParameters & { +type RequestParameters = { + /** + * Access token for which permissions should be revoked. + */ + token: string; + /** * PubNub REST API access key set. */ diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index 680f337f8..4ed0aad14 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -80,7 +80,7 @@ import { RevokeTokenRequest } from './endpoints/access_manager/revoke_token'; import { GrantTokenRequest } from './endpoints/access_manager/grant_token'; import { GrantRequest } from './endpoints/access_manager/grant'; import { AuditRequest } from './endpoints/access_manager/audit'; -import * as PAM from './types/api/access-panager'; +import * as PAM from './types/api/access-manager'; // endregion // region Entities import { SubscriptionOptions } from '../entities/commonTypes'; @@ -1906,34 +1906,34 @@ export class PubNubCore< /** * Revoke token permission. * - * @param parameters - Request configuration parameters. + * @param token - Access token for which permissions should be revoked. * @param callback - Request completion handler callback. */ - public revokeToken(parameters: PAM.RevokeParameters, callback: ResultCallback): void; + public revokeToken(token: PAM.RevokeParameters, callback: ResultCallback): void; /** * Revoke token permission. * - * @param parameters - Request configuration parameters. + * @param token - Access token for which permissions should be revoked. * * @returns Asynchronous revoke token response. */ - public async revokeToken(parameters: PAM.RevokeParameters): Promise; + public async revokeToken(token: PAM.RevokeParameters): Promise; /** * Revoke token permission. * - * @param parameters - Request configuration parameters. + * @param token - Access token for which permissions should be revoked. * @param [callback] - Request completion handler callback. * * @returns Asynchronous revoke token response or `void` in case if `callback` provided. */ async revokeToken( - parameters: PAM.RevokeParameters, + token: PAM.RevokeParameters, callback?: ResultCallback, ): Promise { if (process.env.PAM_MODULE !== 'disabled') { - const request = new RevokeTokenRequest({ ...parameters, keySet: this._configuration.keySet }); + const request = new RevokeTokenRequest({ token, keySet: this._configuration.keySet }); if (callback) return this.sendRequest(request, callback); return this.sendRequest(request); diff --git a/src/core/types/api/access-panager.ts b/src/core/types/api/access-manager.ts similarity index 99% rename from src/core/types/api/access-panager.ts rename to src/core/types/api/access-manager.ts index 068d1afe2..a93b77a32 100644 --- a/src/core/types/api/access-panager.ts +++ b/src/core/types/api/access-manager.ts @@ -223,12 +223,10 @@ export type GrantTokenResponse = string; // endregion // region Revoke -export type RevokeParameters = { - /** - * Access token for which permissions should be revoked. - */ - token: string; -}; +/** + * Access token for which permissions should be revoked. + */ +export type RevokeParameters = string; /** * Response with revoked access token. From 26c4d73a629620c7fdbe16ac72ac4ea495a7d365 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Wed, 29 May 2024 11:02:11 +0300 Subject: [PATCH 10/49] Use large GitHub runner (#376) build(runner): change runners group --- .github/workflows/commands-handler.yml | 7 ++++--- .github/workflows/release.yml | 12 +++++++----- .github/workflows/run-tests.yml | 12 +++++++----- .github/workflows/run-validations.yml | 10 ++++++---- 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.github/workflows/commands-handler.yml b/.github/workflows/commands-handler.yml index 0b5d4702b..48f71d24a 100644 --- a/.github/workflows/commands-handler.yml +++ b/.github/workflows/commands-handler.yml @@ -11,7 +11,8 @@ jobs: process: name: Process command if: github.event.issue.pull_request && endsWith(github.repository, '-private') != true - runs-on: ubuntu-latest + runs-on: + group: Default steps: - name: Check referred user id: user-check @@ -23,12 +24,12 @@ jobs: run: echo -e "\033[38;2;19;181;255mThis is regular commit which should be ignored.\033[0m" - name: Checkout repository if: steps.user-check.outputs.expected-user == 'true' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: token: ${{ secrets.GH_TOKEN }} - name: Checkout release actions if: steps.user-check.outputs.expected-user == 'true' - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: pubnub/client-engineering-deployment-tools ref: v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1d2cc36ba..d70eaa11e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,13 +8,14 @@ on: jobs: check-release: name: Check release required - runs-on: ubuntu-latest if: github.event.pull_request.merged && endsWith(github.repository, '-private') != true + runs-on: + group: Default outputs: release: ${{ steps.check.outputs.ready }} steps: - name: Checkout actions - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: pubnub/client-engineering-deployment-tools ref: v1 @@ -27,17 +28,18 @@ jobs: token: ${{ secrets.GH_TOKEN }} publish: name: Publish package - runs-on: ubuntu-latest needs: check-release if: needs.check-release.outputs.release == 'true' + runs-on: + group: Default steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: # This should be the same as the one specified for on.pull_request.branches ref: master - name: Checkout actions - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: pubnub/client-engineering-deployment-tools ref: v1 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 524b3c68a..0c8f1b0d1 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -20,7 +20,8 @@ env: jobs: tests: name: Integration and Unit tests - runs-on: ubuntu-latest + runs-on: + group: Default strategy: fail-fast: true matrix: @@ -31,16 +32,16 @@ jobs: env: 'ci:web' steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Checkout actions - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: pubnub/client-engineering-deployment-tools ref: v1 token: ${{ secrets.GH_TOKEN }} path: .github/.release/actions - name: Setup NodeJS ${{ matrix.node }} - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: ${{ matrix.node }} cache: 'npm' @@ -54,7 +55,8 @@ jobs: uses: ./.github/.release/actions/actions/utils/fast-jobs-failure all-tests: name: Tests - runs-on: ubuntu-latest + runs-on: + group: Default needs: [tests] steps: - name: Tests summary diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index 7936cc669..859f64d92 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -13,12 +13,13 @@ defaults: jobs: pubnub-yml: name: 'Validate .pubnub.yml' - runs-on: ubuntu-latest + runs-on: + group: Default steps: - name: Checkout project - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Checkout validator action - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: pubnub/client-engineering-deployment-tools ref: v1 @@ -33,7 +34,8 @@ jobs: uses: ./.github/.release/actions/actions/utils/fast-jobs-failure all-validations: name: Validations - runs-on: ubuntu-latest + runs-on: + group: Default needs: [pubnub-yml] steps: - name: Validations summary From 78744e16004aceff22fb789e310d14b3a3a8f853 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Wed, 5 Jun 2024 12:51:45 +0300 Subject: [PATCH 11/49] Fix automatic `heartbeatInterval` set (#378) fix(configuration): fix automatic `heartbeatInterval` set Fix issue because of which `heartbeatInterval` wasn't computed if `presenceTimeout` provided during PubNub client configuration --- .pubnub.yml | 11 ++++++++--- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- dist/web/pubnub.js | 9 ++++++--- dist/web/pubnub.min.js | 4 ++-- lib/core/components/configuration.js | 2 +- lib/core/interfaces/configuration.js | 7 +++++-- package-lock.json | 4 ++-- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/interfaces/configuration.ts | 4 +++- test/integration/components/config.test.ts | 22 ++++++++++++++++++++++ 12 files changed, 59 insertions(+), 18 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 489811ed3..3fb6e228b 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-06-05 + version: v8.2.2 + changes: + - type: bug + text: "Fix issue because of which `heartbeatInterval` wasn't computed if `presenceTimeout` provided during PubNub client configuration." - date: 2024-05-22 version: v8.2.1 changes: @@ -993,7 +998,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.1' +version: '8.2.2' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1009,7 +1014,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.2.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1680,7 +1685,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.1/pubnub.8.2.1.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.2/pubnub.8.2.2.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index ac31c1334..9890a3f58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.2.2 +June 05 2024 + +#### Fixed +- Fix issue because of which `heartbeatInterval` wasn't computed if `presenceTimeout` provided during PubNub client configuration. + ## v8.2.1 May 22 2024 diff --git a/README.md b/README.md index 7207ae881..92fb8e5c8 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.2.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.2.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index dbddf2998..79806be13 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3525,7 +3525,7 @@ * @internal */ const setDefaults$1 = (configuration) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; // Copy configuration. const configurationCopy = Object.assign({}, configuration); (_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING); @@ -3560,7 +3560,10 @@ // eslint-disable-next-line no-console console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); } - (_q = configurationCopy.presenceTimeout) !== null && _q !== void 0 ? _q : (configurationCopy.presenceTimeout = PRESENCE_TIMEOUT); + if (configurationCopy.presenceTimeout !== undefined) + configurationCopy.heartbeatInterval = configurationCopy.presenceTimeout / 2 - 1; + else + configurationCopy.presenceTimeout = PRESENCE_TIMEOUT; // Apply extended configuration defaults. let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS; let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE; @@ -3810,7 +3813,7 @@ return base.PubNubFile; }, get version() { - return '8.2.1'; + return '8.2.2'; }, getVersion() { return this.version; diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 37a11ceb2..3c6f6b774 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.restore)&&void 0!==i||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(a=m.suppressLeaveEvents)&&void 0!==a||(m.suppressLeaveEvents=!1),null!==(c=m.requestMessageCountThreshold)&&void 0!==c||(m.requestMessageCountThreshold=100),null!==(u=m.autoNetworkDetection)&&void 0!==u||(m.autoNetworkDetection=!1),null!==(l=m.enableEventEngine)&&void 0!==l||(m.enableEventEngine=!1),null!==(h=m.maintainPresenceState)&&void 0!==h||(m.maintainPresenceState=!0),null!==(p=m.keepAlive)&&void 0!==p||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=m.userId)&&void 0!==g||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=m.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),null!==(f=m.presenceTimeout)&&void 0!==f||(m.presenceTimeout=300);let v=!1,w=!0,S=5,k=!1,E=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(E=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:100,useRequestId:E,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.2"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 308df22b1..552361994 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.1'; + return '8.2.2'; }, getVersion() { return this.version; diff --git a/lib/core/interfaces/configuration.js b/lib/core/interfaces/configuration.js index 170f986bc..cc1b1d96d 100644 --- a/lib/core/interfaces/configuration.js +++ b/lib/core/interfaces/configuration.js @@ -94,7 +94,7 @@ const PRESENCE_TIMEOUT_MINIMUM = 20; * @internal */ const setDefaults = (configuration) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; // Copy configuration. const configurationCopy = Object.assign({}, configuration); (_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING); @@ -129,7 +129,10 @@ const setDefaults = (configuration) => { // eslint-disable-next-line no-console console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); } - (_q = configurationCopy.presenceTimeout) !== null && _q !== void 0 ? _q : (configurationCopy.presenceTimeout = PRESENCE_TIMEOUT); + if (configurationCopy.presenceTimeout !== undefined) + configurationCopy.heartbeatInterval = configurationCopy.presenceTimeout / 2 - 1; + else + configurationCopy.presenceTimeout = PRESENCE_TIMEOUT; // Apply extended configuration defaults. let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS; let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE; diff --git a/package-lock.json b/package-lock.json index 22d3060ef..f3e0439ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.0.1", + "version": "8.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.0.1", + "version": "8.2.1", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", diff --git a/package.json b/package.json index c1c1089aa..a3ac3d313 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.1", + "version": "8.2.2", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 00f926b17..1602dd87d 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.1'; + return '8.2.2'; }, getVersion(): string { return this.version; diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index f1a0cf3e4..a062b7a75 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -732,7 +732,9 @@ export const setDefaults = (configuration: UserConfiguration): ExtendedConfigura console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); } - configurationCopy.presenceTimeout ??= PRESENCE_TIMEOUT; + if (configurationCopy.presenceTimeout !== undefined) + configurationCopy.heartbeatInterval = configurationCopy.presenceTimeout / 2 - 1; + else configurationCopy.presenceTimeout = PRESENCE_TIMEOUT; // Apply extended configuration defaults. let announceSuccessfulHeartbeats = ANNOUNCE_HEARTBEAT_SUCCESS; diff --git a/test/integration/components/config.test.ts b/test/integration/components/config.test.ts index fcdbc6c3b..462d12c9c 100644 --- a/test/integration/components/config.test.ts +++ b/test/integration/components/config.test.ts @@ -3,6 +3,7 @@ import assert from 'assert'; import PubNub from '../../../src/node/index'; +import { PrivateClientConfiguration } from '../../../src/core/interfaces/configuration'; describe('components/config', () => { describe('AuthKey parameter', () => { @@ -82,5 +83,26 @@ describe('components/config', () => { pubnub.setUUID(' '); }); }); + + it('heartbeatInterval not set if presenceTimeout not set', () => { + const pubnub = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + uuid: 'myUUID', + }); + assert.equal((pubnub.configuration as PrivateClientConfiguration).getPresenceTimeout(), 300); + assert.equal((pubnub.configuration as PrivateClientConfiguration).getHeartbeatInterval(), undefined); + }); + + it('heartbeatInterval is set by formula when presenceTimeout is set', () => { + const pubnub = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + presenceTimeout: 30, + uuid: 'myUUID', + }); + assert.equal((pubnub.configuration as PrivateClientConfiguration).getPresenceTimeout(), 30); + assert.equal((pubnub.configuration as PrivateClientConfiguration).getHeartbeatInterval(), 30 / 2 - 1); + }); }); }); From e4864327ce2aa5ad69ac9de752178c74735f4863 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 6 Jun 2024 18:47:37 +0300 Subject: [PATCH 12/49] Fix `sort` options serialization (#379) fix(app-context): fix `sort` options serialization Fix issue because of which single string sort option wasn't serialized properly. --- .pubnub.yml | 11 ++++-- CHANGELOG.md | 6 +++ README.md | 4 +- dist/web/pubnub.js | 38 +++++++++++++++---- dist/web/pubnub.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/endpoints/objects/channel/get_all.js | 6 ++- lib/core/endpoints/objects/member/get.js | 6 ++- lib/core/endpoints/objects/member/set.js | 6 ++- lib/core/endpoints/objects/membership/get.js | 6 ++- lib/core/endpoints/objects/membership/set.js | 6 ++- lib/core/endpoints/objects/uuid/get_all.js | 6 ++- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/endpoints/objects/channel/get_all.ts | 7 ++-- src/core/endpoints/objects/member/get.ts | 7 ++-- src/core/endpoints/objects/member/set.ts | 7 ++-- src/core/endpoints/objects/membership/get.ts | 7 ++-- src/core/endpoints/objects/membership/set.ts | 7 ++-- src/core/endpoints/objects/uuid/get_all.ts | 7 ++-- 20 files changed, 105 insertions(+), 40 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 3fb6e228b..986fc8684 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-06-06 + version: v8.2.3 + changes: + - type: bug + text: "Fix issue because of which single string sort option wasn't serialized properly." - date: 2024-06-05 version: v8.2.2 changes: @@ -998,7 +1003,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.2' +version: '8.2.3' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1014,7 +1019,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.2.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.3.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1685,7 +1690,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.2/pubnub.8.2.2.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.3/pubnub.8.2.3.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 9890a3f58..9d545c3a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.2.3 +June 06 2024 + +#### Fixed +- Fix issue because of which single string sort option wasn't serialized properly. + ## v8.2.2 June 05 2024 diff --git a/README.md b/README.md index 92fb8e5c8..a3b5f30e0 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.2.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.2.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.3.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.3.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 79806be13..65f05bed4 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3813,7 +3813,7 @@ return base.PubNubFile; }, get version() { - return '8.2.2'; + return '8.2.3'; }, getVersion() { return this.version; @@ -9781,7 +9781,11 @@ } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(','), count: `${include.totalCount}` }, (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); } } @@ -9913,7 +9917,11 @@ } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = []; if (include.statusField) includeFlags.push('status'); @@ -10008,7 +10016,11 @@ } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = ['channel.status', 'channel.type', 'status']; if (include.customFields) includeFlags.push('custom'); @@ -10084,7 +10096,11 @@ } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(',') }, (include.totalCount !== undefined ? { count: `${include.totalCount}` } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); } } @@ -10333,7 +10349,11 @@ } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = []; if (include.statusField) includeFlags.push('status'); @@ -10425,7 +10445,11 @@ } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = ['uuid.status', 'uuid.type', 'type']; if (include.customFields) includeFlags.push('custom'); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 3c6f6b774..08a84a55b 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.2"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters,i=Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.3"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 552361994..6ca4bf8b3 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.2'; + return '8.2.3'; }, getVersion() { return this.version; diff --git a/lib/core/endpoints/objects/channel/get_all.js b/lib/core/endpoints/objects/channel/get_all.js index 3019266fd..133f31b88 100644 --- a/lib/core/endpoints/objects/channel/get_all.js +++ b/lib/core/endpoints/objects/channel/get_all.js @@ -73,7 +73,11 @@ class GetAllChannelsMetadataRequest extends request_1.AbstractRequest { } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(','), count: `${include.totalCount}` }, (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); } } diff --git a/lib/core/endpoints/objects/member/get.js b/lib/core/endpoints/objects/member/get.js index 348855612..b4bb3721d 100644 --- a/lib/core/endpoints/objects/member/get.js +++ b/lib/core/endpoints/objects/member/get.js @@ -104,7 +104,11 @@ class GetChannelMembersRequest extends request_1.AbstractRequest { } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = []; if (include.statusField) includeFlags.push('status'); diff --git a/lib/core/endpoints/objects/member/set.js b/lib/core/endpoints/objects/member/set.js index 344469b01..d70f0c4d1 100644 --- a/lib/core/endpoints/objects/member/set.js +++ b/lib/core/endpoints/objects/member/set.js @@ -93,7 +93,11 @@ class SetChannelMembersRequest extends request_1.AbstractRequest { } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = ['uuid.status', 'uuid.type', 'type']; if (include.customFields) includeFlags.push('custom'); diff --git a/lib/core/endpoints/objects/membership/get.js b/lib/core/endpoints/objects/membership/get.js index 7444536f2..9173f4f39 100644 --- a/lib/core/endpoints/objects/membership/get.js +++ b/lib/core/endpoints/objects/membership/get.js @@ -107,7 +107,11 @@ class GetUUIDMembershipsRequest extends request_1.AbstractRequest { } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = []; if (include.statusField) includeFlags.push('status'); diff --git a/lib/core/endpoints/objects/membership/set.js b/lib/core/endpoints/objects/membership/set.js index 9ed9fcabe..932cd8315 100644 --- a/lib/core/endpoints/objects/membership/set.js +++ b/lib/core/endpoints/objects/membership/set.js @@ -96,7 +96,11 @@ class SetUUIDMembershipsRequest extends request_1.AbstractRequest { } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = ['channel.status', 'channel.type', 'status']; if (include.customFields) includeFlags.push('custom'); diff --git a/lib/core/endpoints/objects/uuid/get_all.js b/lib/core/endpoints/objects/uuid/get_all.js index 778084b0f..957225820 100644 --- a/lib/core/endpoints/objects/uuid/get_all.js +++ b/lib/core/endpoints/objects/uuid/get_all.js @@ -68,7 +68,11 @@ class GetAllUUIDMetadataRequest extends request_1.AbstractRequest { } get queryParameters() { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => order !== null ? `${option}:${order}` : option); + let sorting = ''; + if (typeof sort === 'string') + sorting = sort; + else + sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ include: ['status', 'type', ...(include.customFields ? ['custom'] : [])].join(',') }, (include.totalCount !== undefined ? { count: `${include.totalCount}` } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); } } diff --git a/package.json b/package.json index a3ac3d313..f3d1264d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.2", + "version": "8.2.3", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 1602dd87d..f2cb9e1e9 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.2'; + return '8.2.3'; }, getVersion(): string { return this.version; diff --git a/src/core/endpoints/objects/channel/get_all.ts b/src/core/endpoints/objects/channel/get_all.ts index b4f97889b..ce35825e9 100644 --- a/src/core/endpoints/objects/channel/get_all.ts +++ b/src/core/endpoints/objects/channel/get_all.ts @@ -90,9 +90,10 @@ export class GetAllChannelsMetadataRequest< protected get queryParameters(): Query { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort ?? {}).map(([option, order]) => - order !== null ? `${option}:${order}` : option, - ); + let sorting: string | string[] = ''; + if (typeof sort === 'string') sorting = sort; + else + sorting = Object.entries(sort ?? {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); return { include: ['status', 'type', ...(include!.customFields ? ['custom'] : [])].join(','), diff --git a/src/core/endpoints/objects/member/get.ts b/src/core/endpoints/objects/member/get.ts index 2425c258e..8e344ae3b 100644 --- a/src/core/endpoints/objects/member/get.ts +++ b/src/core/endpoints/objects/member/get.ts @@ -130,9 +130,10 @@ export class GetChannelMembersRequest< protected get queryParameters(): Query { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort ?? {}).map(([option, order]) => - order !== null ? `${option}:${order}` : option, - ); + let sorting: string | string[] = ''; + if (typeof sort === 'string') sorting = sort; + else + sorting = Object.entries(sort ?? {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags: string[] = []; if (include!.statusField) includeFlags.push('status'); diff --git a/src/core/endpoints/objects/member/set.ts b/src/core/endpoints/objects/member/set.ts index f0d5b3ed7..000a3fdac 100644 --- a/src/core/endpoints/objects/member/set.ts +++ b/src/core/endpoints/objects/member/set.ts @@ -121,9 +121,10 @@ export class SetChannelMembersRequest< protected get queryParameters(): Query { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort ?? {}).map(([option, order]) => - order !== null ? `${option}:${order}` : option, - ); + let sorting: string | string[] = ''; + if (typeof sort === 'string') sorting = sort; + else + sorting = Object.entries(sort ?? {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags: string[] = ['uuid.status', 'uuid.type', 'type']; if (include!.customFields) includeFlags.push('custom'); diff --git a/src/core/endpoints/objects/membership/get.ts b/src/core/endpoints/objects/membership/get.ts index 30048e526..7feb46a74 100644 --- a/src/core/endpoints/objects/membership/get.ts +++ b/src/core/endpoints/objects/membership/get.ts @@ -133,9 +133,10 @@ export class GetUUIDMembershipsRequest< protected get queryParameters(): Query { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort ?? {}).map(([option, order]) => - order !== null ? `${option}:${order}` : option, - ); + let sorting: string | string[] = ''; + if (typeof sort === 'string') sorting = sort; + else + sorting = Object.entries(sort ?? {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags: string[] = []; if (include!.statusField) includeFlags.push('status'); diff --git a/src/core/endpoints/objects/membership/set.ts b/src/core/endpoints/objects/membership/set.ts index 5b1edc29e..1056a3a40 100644 --- a/src/core/endpoints/objects/membership/set.ts +++ b/src/core/endpoints/objects/membership/set.ts @@ -124,9 +124,10 @@ export class SetUUIDMembershipsRequest< protected get queryParameters(): Query { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort ?? {}).map(([option, order]) => - order !== null ? `${option}:${order}` : option, - ); + let sorting: string | string[] = ''; + if (typeof sort === 'string') sorting = sort; + else + sorting = Object.entries(sort ?? {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags: string[] = ['channel.status', 'channel.type', 'status']; if (include!.customFields) includeFlags.push('custom'); diff --git a/src/core/endpoints/objects/uuid/get_all.ts b/src/core/endpoints/objects/uuid/get_all.ts index 744a4d6e8..165bd24c5 100644 --- a/src/core/endpoints/objects/uuid/get_all.ts +++ b/src/core/endpoints/objects/uuid/get_all.ts @@ -84,9 +84,10 @@ export class GetAllUUIDMetadataRequest< protected get queryParameters(): Query { const { include, page, filter, sort, limit } = this.parameters; - const sorting = Object.entries(sort ?? {}).map(([option, order]) => - order !== null ? `${option}:${order}` : option, - ); + let sorting: string | string[] = ''; + if (typeof sort === 'string') sorting = sort; + else + sorting = Object.entries(sort ?? {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); return { include: ['status', 'type', ...(include!.customFields ? ['custom'] : [])].join(','), From 07a19e88c749baa4270500fcc99746705ec46c9f Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Wed, 12 Jun 2024 13:04:21 +0530 Subject: [PATCH 13/49] fix: dependabot security alert related to dev-deps (#381) Co-authored-by: Serhii Mamontov --- package-lock.json | 604 ++-------------------------------------------- package.json | 2 - 2 files changed, 15 insertions(+), 591 deletions(-) diff --git a/package-lock.json b/package-lock.json index f3e0439ab..9e0a460d7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.2.1", + "version": "8.2.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.2.1", + "version": "8.2.2", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", @@ -57,13 +57,11 @@ "karma-chai": "^0.1.0", "karma-chrome-launcher": "^3.1.0", "karma-mocha": "^2.0.1", - "karma-phantomjs-launcher": "^1.0.4", "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.32", "mocha": "10.4.0", "nock": "^14.0.0-beta.5", - "phantomjs-prebuilt": "^2.1.16", "prettier": "^3.2.5", "rimraf": "^3.0.2", "rollup": "^4.13.2", @@ -5370,20 +5368,12 @@ "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", "peer": true }, - "node_modules/asn1": { - "version": "0.2.6", - "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", - "integrity": "sha512-ix/FxPn0MDjeyJ7i/yoHGFt/EX6LyNbxSEhPPXODPL+KB0VPk86UYfL0lMdy+KCnv+fmvIzySwaK5COwqVbWTQ==", - "dev": true, - "dependencies": { - "safer-buffer": "~2.1.0" - } - }, "node_modules/assert-plus": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", "integrity": "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==", "dev": true, + "peer": true, "engines": { "node": ">=0.8" } @@ -5439,21 +5429,6 @@ "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" }, - "node_modules/aws-sign2": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz", - "integrity": "sha512-08kcGqnYf/YmjoRhfxyu+CLxBjUtHLXLXX/vUfx9l2LYzG3c1m61nrpyFUZI6zeS+Li/wWMMidD9KgrqtGq3mA==", - "dev": true, - "engines": { - "node": "*" - } - }, - "node_modules/aws4": { - "version": "1.12.0", - "resolved": "https://registry.npmjs.org/aws4/-/aws4-1.12.0.tgz", - "integrity": "sha512-NmWvPnx0F1SfrQbYwOi7OeaNGokp9XhzNioJ/CSBs8Qa4vxug81mhJEAVZwxXuBmYB5KDRfMq/F3RR0BIU7sWg==", - "dev": true - }, "node_modules/babel-core": { "version": "7.0.0-bridge.0", "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz", @@ -5561,15 +5536,6 @@ "node": ">=10.0.0" } }, - "node_modules/bcrypt-pbkdf": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz", - "integrity": "sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==", - "dev": true, - "dependencies": { - "tweetnacl": "^0.14.3" - } - }, "node_modules/becke-ch--regex--s0-0-v1--base--pl--lib": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/becke-ch--regex--s0-0-v1--base--pl--lib/-/becke-ch--regex--s0-0-v1--base--pl--lib-1.4.0.tgz", @@ -5774,15 +5740,6 @@ "ieee754": "^1.2.1" } }, - "node_modules/buffer-crc32": { - "version": "0.2.13", - "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", - "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", @@ -5912,12 +5869,6 @@ "upper-case-first": "^2.0.2" } }, - "node_modules/caseless": { - "version": "0.12.0", - "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", - "integrity": "sha512-4tYFyifaFfGacoiObjJegolkwSU4xQNGbVgUiNYVUxbQ2x2lUsFvY4hVgVzGiIe6WLOPqycWXA40l+PWsxthUw==", - "dev": true - }, "node_modules/cbor-js": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/cbor-js/-/cbor-js-0.1.0.tgz", @@ -6401,21 +6352,6 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, - "node_modules/concat-stream": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", - "integrity": "sha512-27HBghJxjiZtIk3Ycvn/4kbJk/1uZuJFfuPEns6LaEvpvG1f0hTea8lilrouyo9mVc2GWdcEZ8OLoGmSADlrCw==", - "dev": true, - "engines": [ - "node >= 0.8" - ], - "dependencies": { - "buffer-from": "^1.0.0", - "inherits": "^2.0.3", - "readable-stream": "^2.2.2", - "typedarray": "^0.0.6" - } - }, "node_modules/connect": { "version": "3.7.0", "resolved": "https://registry.npmjs.org/connect/-/connect-3.7.0.tgz", @@ -6495,7 +6431,8 @@ "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" + "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "peer": true }, "node_modules/cors": { "version": "2.8.5", @@ -6807,18 +6744,6 @@ "node": ">=0.12" } }, - "node_modules/dashdash": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", - "integrity": "sha512-jRFi8UDGo6j+odZiEpjazZaWqEal3w/basFjQHQEwVtZJGDpxbH1MeYluwCS8Xq5wmLJooDlMgvVarmWfGM44g==", - "dev": true, - "dependencies": { - "assert-plus": "^1.0.0" - }, - "engines": { - "node": ">=0.10" - } - }, "node_modules/data-uri-to-buffer": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz", @@ -7097,22 +7022,6 @@ "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", "dev": true }, - "node_modules/ecc-jsbn": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", - "integrity": "sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==", - "dev": true, - "dependencies": { - "jsbn": "~0.1.0", - "safer-buffer": "^2.1.0" - } - }, - "node_modules/ecc-jsbn/node_modules/jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==", - "dev": true - }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -7264,12 +7173,6 @@ "es6-symbol": "^3.1.1" } }, - "node_modules/es6-promise": { - "version": "4.2.8", - "resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.2.8.tgz", - "integrity": "sha512-HJDGx5daxeIvxdBxvG2cb9g4tEvwIk3i8+nhX0yGrYmZUzbkdg8QbDevheDB8gd0//uPj4c1EQua8Q+MViT0/w==", - "dev": true - }, "node_modules/es6-shim": { "version": "0.35.8", "resolved": "https://registry.npmjs.org/es6-shim/-/es6-shim-0.35.8.tgz", @@ -7765,48 +7668,6 @@ "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", "dev": true }, - "node_modules/extract-zip": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-1.7.0.tgz", - "integrity": "sha512-xoh5G1W/PB0/27lXgMQyIhP5DSY/LhoCsOyZgb+6iMmRtCwVBo55uKaMoEYrDCKQhWvqEip5ZPKAc6eFNyf/MA==", - "dev": true, - "dependencies": { - "concat-stream": "^1.6.2", - "debug": "^2.6.9", - "mkdirp": "^0.5.4", - "yauzl": "^2.10.0" - }, - "bin": { - "extract-zip": "cli.js" - } - }, - "node_modules/extract-zip/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "dev": true, - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/extract-zip/node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "dev": true, - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, - "node_modules/extract-zip/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true - }, "node_modules/extsprintf": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", @@ -7814,7 +7675,8 @@ "dev": true, "engines": [ "node >=0.6.0" - ] + ], + "peer": true }, "node_modules/fast-deep-equal": { "version": "3.1.3", @@ -7908,15 +7770,6 @@ "bser": "2.1.1" } }, - "node_modules/fd-slicer": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz", - "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==", - "dev": true, - "dependencies": { - "pend": "~1.2.0" - } - }, "node_modules/figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", @@ -8114,15 +7967,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/form-data": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", @@ -8145,17 +7989,6 @@ "node": ">= 0.6" } }, - "node_modules/fs-extra": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-1.0.0.tgz", - "integrity": "sha512-VerQV6vEKuhDWD2HGOybV6v5I73syoc/cXAbKlgTC7M/oFVEtklWlp9QH2Ijw3IaWDOQcMkldSPa7zXy79Z/UQ==", - "dev": true, - "dependencies": { - "graceful-fs": "^4.1.2", - "jsonfile": "^2.1.0", - "klaw": "^1.0.0" - } - }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -8298,15 +8131,6 @@ "graceful-fs": "^4.1.6" } }, - "node_modules/getpass": { - "version": "0.1.7", - "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", - "integrity": "sha512-0fzj9JxOLfJ+XGLhR8ze3unN0KZCgZwiSSDz168VERjK8Wl8kVSdcu2kspd4s4wtAa1y/qrVRiAA0WclVsu0ng==", - "dev": true, - "dependencies": { - "assert-plus": "^1.0.0" - } - }, "node_modules/gherkin": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/gherkin/-/gherkin-5.0.0.tgz", @@ -8437,29 +8261,6 @@ "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", "dev": true }, - "node_modules/har-schema": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz", - "integrity": "sha512-Oqluz6zhGX8cyRaTQlFMPw80bSJVG2x/cFb8ZPhUILGgHka9SsokCCOQgpveePerqidZOrT14ipqfJb7ILcW5Q==", - "dev": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/har-validator": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/har-validator/-/har-validator-5.1.5.tgz", - "integrity": "sha512-nmT2T0lljbxdQZfspsno9hgrG3Uir6Ks5afism62poxqBM6sDnMEuPmzTq8XN0OEwqKLLdh1jQI3qyE66Nzb3w==", - "deprecated": "this library is no longer supported", - "dev": true, - "dependencies": { - "ajv": "^6.12.3", - "har-schema": "^2.0.0" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/has-ansi": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-4.0.1.tgz", @@ -8531,28 +8332,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/hasha": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/hasha/-/hasha-2.2.0.tgz", - "integrity": "sha512-jZ38TU/EBiGKrmyTNNZgnvCZHNowiRI4+w/I9noMlekHTZH3KyGgvJLmhSgykeAQ9j2SYPDosM0Bg3wHfzibAQ==", - "dev": true, - "dependencies": { - "is-stream": "^1.0.1", - "pinkie-promise": "^2.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/hasha/node_modules/is-stream": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", - "integrity": "sha512-uQPm8kcs47jx38atAcWTVxyltQYoPT68y9aWYdV6yWXSyW8mzSat0TL6CiWdZeCdF3KrAvpVtnHbTv4RN+rqdQ==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", @@ -8664,21 +8443,6 @@ "node": ">= 14" } }, - "node_modules/http-signature": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", - "integrity": "sha512-CAbnr6Rz4CYQkLYUtSNXxQPUH2gK8f3iWexVlsnMeD+GjlsQ0Xsy1cOX+mN3dtxYomRy21CiOzU8Uhw6OwncEQ==", - "dev": true, - "dependencies": { - "assert-plus": "^1.0.0", - "jsprim": "^1.2.2", - "sshpk": "^1.7.0" - }, - "engines": { - "node": ">=0.8", - "npm": ">=1.3.7" - } - }, "node_modules/https-proxy-agent": { "version": "7.0.4", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz", @@ -9084,12 +8848,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/is-typedarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", - "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==", - "dev": true - }, "node_modules/is-unicode-supported": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", @@ -9116,7 +8874,8 @@ "node_modules/isarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "peer": true }, "node_modules/isbinaryfile": { "version": "4.0.10", @@ -9144,12 +8903,6 @@ "node": ">=0.10.0" } }, - "node_modules/isstream": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", - "integrity": "sha512-Yljz7ffyPbrLpLngrMtZ7NduUgVvi6wG9RJ9IUcyCd59YQ911PBJphODUcbOVbqYfxe1wuYf/LJ8PauMRwsM/g==", - "dev": true - }, "node_modules/jackspeak": { "version": "2.3.6", "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", @@ -9414,12 +9167,6 @@ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", "dev": true }, - "node_modules/json-schema": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", - "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", - "dev": true - }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -9451,50 +9198,6 @@ "json5": "lib/cli.js" } }, - "node_modules/jsonfile": { - "version": "2.4.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz", - "integrity": "sha512-PKllAqbgLgxHaj8TElYymKCAgrASebJrWpTnEkOaTowt23VKXXN0sUeriJ+eh7y6ufb/CC5ap11pz71/cM0hUw==", - "dev": true, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/jsprim": { - "version": "1.4.2", - "resolved": "https://registry.npmjs.org/jsprim/-/jsprim-1.4.2.tgz", - "integrity": "sha512-P2bSOMAc/ciLz6DzgjVlGJP9+BrJWu5UDGK70C2iweC5QBIeFf0ZXRvGjEj2uYgrY2MkAAhsSWHDWlFtEroZWw==", - "dev": true, - "dependencies": { - "assert-plus": "1.0.0", - "extsprintf": "1.3.0", - "json-schema": "0.4.0", - "verror": "1.10.0" - }, - "engines": { - "node": ">=0.6.0" - } - }, - "node_modules/jsprim/node_modules/core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", - "dev": true - }, - "node_modules/jsprim/node_modules/verror": { - "version": "1.10.0", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", - "integrity": "sha512-ZZKSmDAEFOijERBLkmYfJ+vmk3w+7hOLYDNkRCuRuMJGEmqYNCNLyBBFwWKVMhfwaEF3WOd0Zlw86U/WC/+nYw==", - "dev": true, - "engines": [ - "node >=0.6.0" - ], - "dependencies": { - "assert-plus": "^1.0.0", - "core-util-is": "1.0.2", - "extsprintf": "^1.2.0" - } - }, "node_modules/just-extend": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", @@ -9579,20 +9282,6 @@ "minimist": "^1.2.3" } }, - "node_modules/karma-phantomjs-launcher": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/karma-phantomjs-launcher/-/karma-phantomjs-launcher-1.0.4.tgz", - "integrity": "sha512-tf4P3plsE7wb5Pqh8GJ6RnElxfI/UM4MtVnjbSIZFpdFJlKnjRzfIx8MLCcSYJBwZ1+qSKFz4uBe3XNoq2t3KA==", - "deprecated": "PhantomJS development have stopped, use puppeteer or similar", - "dev": true, - "dependencies": { - "lodash": "^4.0.1", - "phantomjs-prebuilt": "^2.1.7" - }, - "peerDependencies": { - "karma": ">=0.9" - } - }, "node_modules/karma-sinon-chai": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/karma-sinon-chai/-/karma-sinon-chai-2.0.2.tgz", @@ -9679,12 +9368,6 @@ "mkdirp": "bin/cmd.js" } }, - "node_modules/kew": { - "version": "0.7.0", - "resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz", - "integrity": "sha512-IG6nm0+QtAMdXt9KvbgbGdvY50RSrw+U4sGZg+KlrSKPJEwVE5JVoI3d7RWfSMdBQneRheeAOj3lIjX5VL/9RQ==", - "dev": true - }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -9703,15 +9386,6 @@ "node": ">=0.10.0" } }, - "node_modules/klaw": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/klaw/-/klaw-1.3.1.tgz", - "integrity": "sha512-TED5xi9gGQjGpNnvRWknrwAB1eL5GciPfVFOt3Vk1OJCVDQbzuSfrF3hkUQKlsgKrG1F+0t5W0m+Fje1jIt8rw==", - "dev": true, - "optionalDependencies": { - "graceful-fs": "^4.1.9" - } - }, "node_modules/kleur": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", @@ -11148,15 +10822,6 @@ "integrity": "sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==", "peer": true }, - "node_modules/oauth-sign": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", - "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", - "dev": true, - "engines": { - "node": "*" - } - }, "node_modules/ob1": { "version": "0.80.8", "resolved": "https://registry.npmjs.org/ob1/-/ob1-0.80.8.tgz", @@ -11506,61 +11171,6 @@ "node": "*" } }, - "node_modules/pend": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", - "integrity": "sha512-F3asv42UuXchdzt+xXqfW1OGlVBe+mxa2mqI0pg5yAHZPvFmY3Y6drSf/GQ1A86WgWEN9Kzh/WrgKa6iGcHXLg==", - "dev": true - }, - "node_modules/performance-now": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", - "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==", - "dev": true - }, - "node_modules/phantomjs-prebuilt": { - "version": "2.1.16", - "resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.16.tgz", - "integrity": "sha512-PIiRzBhW85xco2fuj41FmsyuYHKjKuXWmhjy3A/Y+CMpN/63TV+s9uzfVhsUwFe0G77xWtHBG8xmXf5BqEUEuQ==", - "deprecated": "this package is now deprecated", - "dev": true, - "hasInstallScript": true, - "dependencies": { - "es6-promise": "^4.0.3", - "extract-zip": "^1.6.5", - "fs-extra": "^1.0.0", - "hasha": "^2.2.0", - "kew": "^0.7.0", - "progress": "^1.1.8", - "request": "^2.81.0", - "request-progress": "^2.0.1", - "which": "^1.2.10" - }, - "bin": { - "phantomjs": "bin/phantomjs" - } - }, - "node_modules/phantomjs-prebuilt/node_modules/progress": { - "version": "1.1.8", - "resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz", - "integrity": "sha512-UdA8mJ4weIkUBO224tIarHzuHs4HuYiJvsuGT7j/SPQiUJVjYvNDBIPa0hAorduOfjGohB/qHWRa/lrrWX/mXw==", - "dev": true, - "engines": { - "node": ">=0.4.0" - } - }, - "node_modules/phantomjs-prebuilt/node_modules/which": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", - "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", - "dev": true, - "dependencies": { - "isexe": "^2.0.0" - }, - "bin": { - "which": "bin/which" - } - }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", @@ -11586,27 +11196,6 @@ "node": ">=6" } }, - "node_modules/pinkie": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/pinkie/-/pinkie-2.0.4.tgz", - "integrity": "sha512-MnUuEycAemtSaeFSjXKW/aroV7akBbY+Sv+RkyqFjgAe73F+MR0TBWKBRDkmfWq/HiFmdavfZ1G7h4SPZXaCSg==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/pinkie-promise": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/pinkie-promise/-/pinkie-promise-2.0.1.tgz", - "integrity": "sha512-0Gni6D4UcLTbv9c57DfxDGdr41XfgUjqWZu492f0cIGr16zDU06BWP/RAEvOuo7CQ0CNjHaLlM59YJJFm3NWlw==", - "dev": true, - "dependencies": { - "pinkie": "^2.0.0" - }, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/pirates": { "version": "4.0.6", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.6.tgz", @@ -11741,7 +11330,8 @@ "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" + "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "peer": true }, "node_modules/progress": { "version": "2.0.3", @@ -11837,12 +11427,6 @@ "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" }, - "node_modules/psl": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz", - "integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==", - "dev": true - }, "node_modules/punycode": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", @@ -12357,6 +11941,7 @@ "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "peer": true, "dependencies": { "core-util-is": "~1.0.0", "inherits": "~2.0.3", @@ -12535,80 +12120,6 @@ "node": ">=0.10" } }, - "node_modules/request": { - "version": "2.88.2", - "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", - "integrity": "sha512-MsvtOrfG9ZcrOwAW+Qi+F6HbD0CWXEh9ou77uOb7FM2WPhwT7smM833PzanhJLsgXjN89Ir6V2PczXNnMpwKhw==", - "deprecated": "request has been deprecated, see https://github.com/request/request/issues/3142", - "dev": true, - "dependencies": { - "aws-sign2": "~0.7.0", - "aws4": "^1.8.0", - "caseless": "~0.12.0", - "combined-stream": "~1.0.6", - "extend": "~3.0.2", - "forever-agent": "~0.6.1", - "form-data": "~2.3.2", - "har-validator": "~5.1.3", - "http-signature": "~1.2.0", - "is-typedarray": "~1.0.0", - "isstream": "~0.1.2", - "json-stringify-safe": "~5.0.1", - "mime-types": "~2.1.19", - "oauth-sign": "~0.9.0", - "performance-now": "^2.1.0", - "qs": "~6.5.2", - "safe-buffer": "^5.1.2", - "tough-cookie": "~2.5.0", - "tunnel-agent": "^0.6.0", - "uuid": "^3.3.2" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/request-progress": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/request-progress/-/request-progress-2.0.1.tgz", - "integrity": "sha512-dxdraeZVUNEn9AvLrxkgB2k6buTlym71dJk1fk4v8j3Ou3RKNm07BcgbHdj2lLgYGfqX71F+awb1MR+tWPFJzA==", - "dev": true, - "dependencies": { - "throttleit": "^1.0.0" - } - }, - "node_modules/request/node_modules/form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", - "dev": true, - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 0.12" - } - }, - "node_modules/request/node_modules/qs": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.3.tgz", - "integrity": "sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==", - "dev": true, - "engines": { - "node": ">=0.6" - } - }, - "node_modules/request/node_modules/uuid": { - "version": "3.4.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", - "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", - "deprecated": "Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.", - "dev": true, - "bin": { - "uuid": "bin/uuid" - } - }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -13384,37 +12895,6 @@ "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==" }, - "node_modules/sshpk": { - "version": "1.18.0", - "resolved": "https://registry.npmjs.org/sshpk/-/sshpk-1.18.0.tgz", - "integrity": "sha512-2p2KJZTSqQ/I3+HX42EpYOa2l3f8Erv8MWKsy2I9uf4wA7yFIkXRffYdsx86y6z4vHtV8u7g+pPlr8/4ouAxsQ==", - "dev": true, - "dependencies": { - "asn1": "~0.2.3", - "assert-plus": "^1.0.0", - "bcrypt-pbkdf": "^1.0.0", - "dashdash": "^1.12.0", - "ecc-jsbn": "~0.1.1", - "getpass": "^0.1.1", - "jsbn": "~0.1.0", - "safer-buffer": "^2.0.2", - "tweetnacl": "~0.14.0" - }, - "bin": { - "sshpk-conv": "bin/sshpk-conv", - "sshpk-sign": "bin/sshpk-sign", - "sshpk-verify": "bin/sshpk-verify" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/sshpk/node_modules/jsbn": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-0.1.1.tgz", - "integrity": "sha512-UVU9dibq2JcFWxQPA6KCqj5O42VOmAY3zQUfEKxU0KpTGXwNoCjkX1e13eHNvw/xPynt6pU0rZ1htjWTNTSXsg==", - "dev": true - }, "node_modules/stack-chain": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/stack-chain/-/stack-chain-2.0.0.tgz", @@ -13560,6 +13040,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "peer": true, "dependencies": { "safe-buffer": "~5.1.0" } @@ -13862,15 +13343,6 @@ "integrity": "sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==", "peer": true }, - "node_modules/throttleit": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/throttleit/-/throttleit-1.0.1.tgz", - "integrity": "sha512-vDZpf9Chs9mAdfY046mcPt8fg5QSZr37hEH4TXYBnDF+izxgrbRGUAAaBvIk/fJm9aOFCGFd1EsNg5AZCbnQCQ==", - "dev": true, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", @@ -13964,19 +13436,6 @@ "integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==", "dev": true }, - "node_modules/tough-cookie": { - "version": "2.5.0", - "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", - "integrity": "sha512-nlLsUzgm1kfLXSXfRZMc1KLAugd4hqJHDTvc2hDIwS3mZAfMEuMbc03SujMF+GEcpaX/qboeycw6iO8JwVv2+g==", - "dev": true, - "dependencies": { - "psl": "^1.1.28", - "punycode": "^2.1.1" - }, - "engines": { - "node": ">=0.8" - } - }, "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", @@ -14156,24 +13615,6 @@ "fsevents": "~2.3.3" } }, - "node_modules/tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", - "dev": true, - "dependencies": { - "safe-buffer": "^5.0.1" - }, - "engines": { - "node": "*" - } - }, - "node_modules/tweetnacl": { - "version": "0.14.5", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", - "integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==", - "dev": true - }, "node_modules/type": { "version": "2.7.2", "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", @@ -14226,12 +13667,6 @@ "node": ">= 0.6" } }, - "node_modules/typedarray": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz", - "integrity": "sha512-/aCDEGatGvZ2BIk+HmLf4ifCJFwvKFNb9/JeZPMulfgFracn9QFcAf5GO8B/mweUjSoblS5In0cWhqpfs/5PQA==", - "dev": true - }, "node_modules/typescript": { "version": "5.4.5", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", @@ -14399,7 +13834,8 @@ "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "peer": true }, "node_modules/utils-merge": { "version": "1.0.1", @@ -14858,16 +14294,6 @@ "node": ">=10" } }, - "node_modules/yauzl": { - "version": "2.10.0", - "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", - "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==", - "dev": true, - "dependencies": { - "buffer-crc32": "~0.2.3", - "fd-slicer": "~1.1.0" - } - }, "node_modules/yn": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", diff --git a/package.json b/package.json index f3d1264d0..b27790911 100644 --- a/package.json +++ b/package.json @@ -101,13 +101,11 @@ "karma-chai": "^0.1.0", "karma-chrome-launcher": "^3.1.0", "karma-mocha": "^2.0.1", - "karma-phantomjs-launcher": "^1.0.4", "karma-sinon-chai": "^2.0.2", "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.32", "mocha": "10.4.0", "nock": "^14.0.0-beta.5", - "phantomjs-prebuilt": "^2.1.16", "prettier": "^3.2.5", "rimraf": "^3.0.2", "rollup": "^4.13.2", From 4e18e9d996d829126a998c96b0c655bec17c801a Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:43:06 +0530 Subject: [PATCH 14/49] fix:deps version braces (#382) --- package-lock.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 9e0a460d7..a27430ad6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5994,7 +5994,7 @@ "dev": true, "dependencies": { "anymatch": "~3.1.2", - "braces": "~3.0.2", + "braces": "~3.0.3", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", @@ -9212,7 +9212,7 @@ "dependencies": { "@colors/colors": "1.5.0", "body-parser": "^1.19.0", - "braces": "^3.0.2", + "braces": "^3.0.3", "chokidar": "^3.5.1", "connect": "^3.7.0", "di": "^0.0.1", @@ -10334,7 +10334,7 @@ "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { @@ -10481,7 +10481,7 @@ ], "dependencies": { "anymatch": "~3.1.2", - "braces": "~3.0.2", + "braces": "~3.0.3", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", From 5dc7ec744b77b8b963b1768e273a7d1b8ab28f6d Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Mon, 17 Jun 2024 19:26:00 +0530 Subject: [PATCH 15/49] fix: `Subscription` entity's `subscribe()` signature to accept timetoken (#385) * fix: subscribe() signature to accept timetoken in subscribe() method * fix lint errors * added test for custom timetoken with subscription * format * sync package-lock * PubNub SDK v8.2.4 release. --------- Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> --- .pubnub.yml | 11 ++- CHANGELOG.md | 6 ++ README.md | 4 +- dist/web/pubnub.js | 8 +- dist/web/pubnub.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/entities/SubscribeCapable.js | 6 +- lib/types/entities/SubscribeCapable.d.ts | 4 +- lib/types/entities/commonTypes.d.ts | 4 - package-lock.json | 18 ++--- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/entities/SubscribeCapable.ts | 5 +- src/entities/commonTypes.ts | 1 - test/integration/endpoints/subscribe.test.ts | 78 +++++++++++++++++--- 15 files changed, 109 insertions(+), 44 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 986fc8684..9df9bd580 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-06-17 + version: v8.2.4 + changes: + - type: bug + text: "Subscription/SubscriptionSet's `subscribe()` method accepts `timetoken` parameter. Instead as in subscriptionOption." - date: 2024-06-06 version: v8.2.3 changes: @@ -1003,7 +1008,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.3' +version: '8.2.4' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1019,7 +1024,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.3.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.4.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1690,7 +1695,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.3/pubnub.8.2.3.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.4/pubnub.8.2.4.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d545c3a4..aaa4198e7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.2.4 +June 17 2024 + +#### Fixed +- Subscription/SubscriptionSet's `subscribe()` method accepts `timetoken` parameter. Instead as in subscriptionOption. + ## v8.2.3 June 06 2024 diff --git a/README.md b/README.md index a3b5f30e0..961b9c270 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.3.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.3.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.4.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.4.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 65f05bed4..39e0f27a7 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3813,7 +3813,7 @@ return base.PubNubFile; }, get version() { - return '8.2.3'; + return '8.2.4'; }, getVersion() { return this.version; @@ -8963,9 +8963,9 @@ } class SubscribeCapable { - subscribe() { - var _a, _b; - this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken }))); + subscribe(subscribeParameters) { + const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken; + this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken }))); } unsubscribe() { this.pubnub.unsubscribe({ diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 08a84a55b..dab432ad9 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.3"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(){var e,t;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},(null===(t=null===(e=this.options)||void 0===e?void 0:e.cursor)||void 0===t?void 0:t.timetoken)&&{timetoken:this.options.cursor.timetoken}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.4"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 6ca4bf8b3..820ebc0f2 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.3'; + return '8.2.4'; }, getVersion() { return this.version; diff --git a/lib/entities/SubscribeCapable.js b/lib/entities/SubscribeCapable.js index 3a037f788..d8f93069c 100644 --- a/lib/entities/SubscribeCapable.js +++ b/lib/entities/SubscribeCapable.js @@ -2,9 +2,9 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.SubscribeCapable = void 0; class SubscribeCapable { - subscribe() { - var _a, _b; - this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (((_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.cursor) === null || _b === void 0 ? void 0 : _b.timetoken) && { timetoken: this.options.cursor.timetoken }))); + subscribe(subscribeParameters) { + const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken; + this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken }))); } unsubscribe() { this.pubnub.unsubscribe({ diff --git a/lib/types/entities/SubscribeCapable.d.ts b/lib/types/entities/SubscribeCapable.d.ts index b4ca7001d..31229e1b2 100644 --- a/lib/types/entities/SubscribeCapable.d.ts +++ b/lib/types/entities/SubscribeCapable.d.ts @@ -10,7 +10,9 @@ export declare abstract class SubscribeCapable { protected abstract eventEmitter: EventEmitter; protected abstract pubnub: PubNub; protected abstract options?: SubscriptionOptions; - subscribe(): void; + subscribe(subscribeParameters?: { + timetoken?: string; + }): void; unsubscribe(): void; set onMessage(onMessageListener: (messageEvent: Subscription.Message) => void); set onPresence(onPresenceListener: (presenceEvent: Subscription.Presence) => void); diff --git a/lib/types/entities/commonTypes.d.ts b/lib/types/entities/commonTypes.d.ts index 170abf0d4..c26e12f07 100644 --- a/lib/types/entities/commonTypes.d.ts +++ b/lib/types/entities/commonTypes.d.ts @@ -1,7 +1,3 @@ export type SubscriptionOptions = { - cursor?: { - timetoken?: string; - region?: number; - }; receivePresenceEvents?: boolean; }; diff --git a/package-lock.json b/package-lock.json index a27430ad6..fb656bc4e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.2.2", + "version": "8.2.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.2.2", + "version": "8.2.3", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", @@ -5660,11 +5660,11 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -7807,9 +7807,9 @@ } }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dependencies": { "to-regex-range": "^5.0.1" }, diff --git a/package.json b/package.json index b27790911..a193a337d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.3", + "version": "8.2.4", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index f2cb9e1e9..db9d3a5e2 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.3'; + return '8.2.4'; }, getVersion(): string { return this.version; diff --git a/src/entities/SubscribeCapable.ts b/src/entities/SubscribeCapable.ts index b6cdcc84d..c5ddb7347 100644 --- a/src/entities/SubscribeCapable.ts +++ b/src/entities/SubscribeCapable.ts @@ -12,11 +12,12 @@ export abstract class SubscribeCapable { protected abstract pubnub: PubNub; protected abstract options?: SubscriptionOptions; - subscribe() { + subscribe(subscribeParameters?: { timetoken?: string }) { + const timetoken = subscribeParameters?.timetoken; this.pubnub.subscribe({ channels: this.channelNames, channelGroups: this.groupNames, - ...(this.options?.cursor?.timetoken && { timetoken: this.options.cursor.timetoken }), + ...(timetoken !== null && timetoken !== '' && { timetoken: timetoken }), }); } unsubscribe() { diff --git a/src/entities/commonTypes.ts b/src/entities/commonTypes.ts index cd30c0c61..fe7de30b4 100644 --- a/src/entities/commonTypes.ts +++ b/src/entities/commonTypes.ts @@ -1,4 +1,3 @@ export type SubscriptionOptions = { - cursor?: { timetoken?: string; region?: number }; receivePresenceEvents?: boolean; }; diff --git a/test/integration/endpoints/subscribe.test.ts b/test/integration/endpoints/subscribe.test.ts index 9e4c6bd2f..7a5d9a619 100644 --- a/test/integration/endpoints/subscribe.test.ts +++ b/test/integration/endpoints/subscribe.test.ts @@ -10,6 +10,7 @@ import utils from '../../utils'; describe('subscribe endpoints', () => { let pubnubWithFiltering: PubNub; let pubnub: PubNub; + let pubnubWithEE: PubNub; before(() => { nock.disableNetConnect(); @@ -38,6 +39,14 @@ describe('subscribe endpoints', () => { filterExpression: 'hello!', autoNetworkDetection: false, }); + pubnubWithEE = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, + enableEventEngine: true, + }); }); afterEach(() => { @@ -65,9 +74,9 @@ describe('subscribe endpoints', () => { if (status.category === 'PNConnectedCategory') { try { assert.equal(scope.isDone(), true); - assert.deepEqual(pubnub.getSubscribedChannels(), ["coolChannel", "coolChannel2"]); + assert.deepEqual(pubnub.getSubscribedChannels(), ['coolChannel', 'coolChannel2']); assert.deepEqual(pubnub.getSubscribedChannelGroups(), []); - assert.deepEqual(status.affectedChannels, ["coolChannel", "coolChannel2"]); + assert.deepEqual(status.affectedChannels, ['coolChannel', 'coolChannel2']); assert.deepEqual(status.affectedChannelGroups, []); done(); } catch (error) { @@ -99,12 +108,12 @@ describe('subscribe endpoints', () => { pubnub.addListener({ status(status) { if (status.category === 'PNConnectedCategory') { - try { + try { assert.equal(scope.isDone(), true); - assert.deepEqual(pubnub.getSubscribedChannels(), ["coolChannel", "coolChannel2"]); - assert.deepEqual(pubnub.getSubscribedChannelGroups(), ["cg1", "cg2"]); - assert.deepEqual(status.affectedChannels, ["coolChannel", "coolChannel2"]); - assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]); + assert.deepEqual(pubnub.getSubscribedChannels(), ['coolChannel', 'coolChannel2']); + assert.deepEqual(pubnub.getSubscribedChannelGroups(), ['cg1', 'cg2']); + assert.deepEqual(status.affectedChannels, ['coolChannel', 'coolChannel2']); + assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']); done(); } catch (error) { done(error); @@ -141,9 +150,9 @@ describe('subscribe endpoints', () => { try { assert.equal(scope.isDone(), true); assert.deepEqual(pubnub.getSubscribedChannels(), []); - assert.deepEqual(pubnub.getSubscribedChannelGroups(), ["cg1", "cg2"]); + assert.deepEqual(pubnub.getSubscribedChannelGroups(), ['cg1', 'cg2']); assert.deepEqual(status.affectedChannels, []); - assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]); + assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']); done(); } catch (error) { done(error); @@ -176,9 +185,9 @@ describe('subscribe endpoints', () => { if (status.category === 'PNConnectedCategory') { try { assert.equal(scope.isDone(), true); - assert.deepEqual(pubnubWithFiltering.getSubscribedChannels(), ["coolChannel", "coolChannel2"]); + assert.deepEqual(pubnubWithFiltering.getSubscribedChannels(), ['coolChannel', 'coolChannel2']); assert.deepEqual(pubnubWithFiltering.getSubscribedChannelGroups(), []); - assert.deepEqual(status.affectedChannels, ["coolChannel", "coolChannel2"]); + assert.deepEqual(status.affectedChannels, ['coolChannel', 'coolChannel2']); assert.deepEqual(status.affectedChannelGroups, []); done(); } catch (error) { @@ -192,4 +201,51 @@ describe('subscribe endpoints', () => { channels: ['coolChannel', 'coolChannel2'], }); }); + + it('supports timetoken', (done) => { + const scope0 = utils + .createNock() + .get('/v2/subscribe/mySubKey/c1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: 0, + }) + .reply( + 200, + '{"t":{"t":"14523669555221452","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, + ); + const scope = utils + .createNock() + .get('/v2/subscribe/mySubKey/c1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '1234567890', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"146075779609322","r":1},"m":[{"a":"4","f":0,"i":"test","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"c1","d":{"text":"customttresponse"},"b":"c1"}]}', + { 'content-type': 'text/javascript' }, + ); + + pubnubWithEE.addListener({ + message(message) { + try { + assert.deepEqual(message.message, { text: 'customttresponse' }); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + }); + const channel = pubnubWithEE.channel('c1'); + const subscription = channel.subscription(); + subscription.subscribe({ timetoken: '1234567890' }); + }); }); From e8b22561e8acd6d805a3d149a73948e7b99cc6e8 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 4 Jul 2024 11:20:02 +0300 Subject: [PATCH 16/49] Fix issue with string signals (#388) fix(listener): fix issue with string signals Fix issue because of which signals sent as string not handler properly. --- .pubnub.yml | 11 +- CHANGELOG.md | 6 + README.md | 4 +- dist/web/pubnub.js | 4 +- dist/web/pubnub.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/endpoints/subscribe.js | 2 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/endpoints/subscribe.ts | 2 +- .../components/reconnection_manager.test.ts | 24 +-- .../components/subscription_manager.test.ts | 192 +++++++++--------- test/integration/endpoints/signal.test.ts | 32 ++- test/integration/endpoints/subscribe.test.ts | 52 ++++- .../operations/unsubscribe.test.ts | 24 +-- 15 files changed, 222 insertions(+), 139 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 9df9bd580..0d0762abe 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-07-04 + version: v8.2.5 + changes: + - type: bug + text: "Fix issue because of which `signals` sent as `string` not handler properly." - date: 2024-06-17 version: v8.2.4 changes: @@ -1008,7 +1013,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.4' +version: '8.2.5' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1024,7 +1029,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.4.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.5.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1695,7 +1700,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.4/pubnub.8.2.4.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.5/pubnub.8.2.5.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index aaa4198e7..4aad8a87a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.2.5 +July 04 2024 + +#### Fixed +- Fix issue because of which `signals` sent as `string` not handler properly. Fixed the following issues reported by [@roman-rr](https://github.com/roman-rr): [#387](https://github.com/pubnub/javascript/issues/387). + ## v8.2.4 June 17 2024 diff --git a/README.md b/README.md index 961b9c270..8626e42b0 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.4.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.4.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.5.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.5.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 39e0f27a7..1a5e6c67d 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3813,7 +3813,7 @@ return base.PubNubFile; }, get version() { - return '8.2.4'; + return '8.2.5'; }, getVersion() { return this.version; @@ -5870,7 +5870,7 @@ // Resolve missing event type. eventType !== null && eventType !== void 0 ? eventType : (eventType = envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message); // Check whether payload is string (potentially encrypted data). - if (typeof envelope.d === 'string') { + if (eventType != PubNubEventType.Signal && typeof envelope.d === 'string') { if (eventType == PubNubEventType.Message) { return { type: PubNubEventType.Message, diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index dab432ad9..99e92f2ee 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.4"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.5"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 820ebc0f2..a4a50de87 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.4'; + return '8.2.5'; }, getVersion() { return this.version; diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index 846186b5f..7021e6ae4 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -117,7 +117,7 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { // Resolve missing event type. eventType !== null && eventType !== void 0 ? eventType : (eventType = envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message); // Check whether payload is string (potentially encrypted data). - if (typeof envelope.d === 'string') { + if (eventType != PubNubEventType.Signal && typeof envelope.d === 'string') { if (eventType == PubNubEventType.Message) { return { type: PubNubEventType.Message, diff --git a/package.json b/package.json index a193a337d..f2395b966 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.4", + "version": "8.2.5", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index db9d3a5e2..07fb358cc 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.4'; + return '8.2.5'; }, getVersion(): string { return this.version; diff --git a/src/core/endpoints/subscribe.ts b/src/core/endpoints/subscribe.ts index ee179ab24..043e93a7e 100644 --- a/src/core/endpoints/subscribe.ts +++ b/src/core/endpoints/subscribe.ts @@ -636,7 +636,7 @@ export class BaseSubscribeRequest extends AbstractRequest { pubnub.addListener({ status(statusPayload) { if (statusPayload.operation !== PubNub.OPERATIONS.PNSubscribeOperation) return; - let statusWithoutError = _.omit(statusPayload, ['errorData', 'statusCode']); + const statusWithoutError = _.omit(statusPayload, ['errorData', 'statusCode']); try { assert.deepEqual( { category: PubNub.CATEGORIES.PNNetworkIssuesCategory, error: true, - operation: PubNub.OPERATIONS.PNSubscribeOperation + operation: PubNub.OPERATIONS.PNSubscribeOperation, }, - statusWithoutError + statusWithoutError, ); utils .createNock() - .get("/v2/presence/sub-key/mySubKey/channel/ch1,ch2/leave") + .get('/v2/presence/sub-key/mySubKey/channel/ch1,ch2/leave') .query(true) - .reply(200, "{\"status\": 200, \"message\": \"OK\", \"service\": \"Presence\"}", { - "content-type": "text/javascript" + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { + 'content-type': 'text/javascript', }); done(); @@ -113,7 +113,7 @@ describe('#components/reconnection_manger', () => { .query(true) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -134,17 +134,17 @@ describe('#components/reconnection_manger', () => { category: PubNub.CATEGORIES.PNReconnectedCategory, operation: PubNub.OPERATIONS.PNSubscribeOperation, currentTimetoken: 0, - lastTimetoken: 0 + lastTimetoken: 0, }, - statusPayload + statusPayload, ); utils .createNock() - .get("/v2/presence/sub-key/mySubKey/channel/ch1,ch2/leave") + .get('/v2/presence/sub-key/mySubKey/channel/ch1,ch2/leave') .query(true) - .reply(200, "{\"status\": 200, \"message\": \"OK\", \"service\": \"Presence\"}", { - "content-type": "text/javascript" + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { + 'content-type': 'text/javascript', }); done(); diff --git a/test/integration/components/subscription_manager.test.ts b/test/integration/components/subscription_manager.test.ts index 3a8ebb9c1..a526e0de2 100644 --- a/test/integration/components/subscription_manager.test.ts +++ b/test/integration/components/subscription_manager.test.ts @@ -84,7 +84,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -100,7 +100,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client2", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message3"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client2", "k":"mySubKey","c":"coolChannel","d":{"text":"Message3"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -116,7 +116,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"20","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client3", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message10"},"b":"coolChan-bnel", "u": {"cool": "meta"}}]}', + '{"t":{"t":"20","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client3", "k":"mySubKey","c":"coolChannel","d":{"text":"Message10"},"b":"coolChan-bnel", "u": {"cool": "meta"}}]}', { 'content-type': 'text/javascript' }, ); utils @@ -125,7 +125,7 @@ describe('#components/subscription_manager', () => { .query(true) .reply(200, '{"status": 200,"message":"OK","service":"Presence"}', { 'content-type': 'text/javascript' }); - let incomingPayloads = []; + const incomingPayloads = []; pubnub.addListener({ message(messagePayload) { @@ -138,41 +138,41 @@ describe('#components/subscription_manager', () => { assert.equal(scope3.isDone(), true); assert.deepEqual(incomingPayloads, [ { - actualChannel: "coolChannel", + actualChannel: 'coolChannel', message: { - text: "Message" + text: 'Message', }, - subscribedChannel: "coolChan-bnel", - channel: "coolChannel", - subscription: "coolChan-bnel", - timetoken: "14607577960925503", - publisher: "client1" + subscribedChannel: 'coolChan-bnel', + channel: 'coolChannel', + subscription: 'coolChan-bnel', + timetoken: '14607577960925503', + publisher: 'client1', }, { - actualChannel: "coolChannel", + actualChannel: 'coolChannel', message: { - text: "Message3" + text: 'Message3', }, - subscribedChannel: "coolChan-bnel", - channel: "coolChannel", - subscription: "coolChan-bnel", - timetoken: "14607577960925503", - publisher: "client2" + subscribedChannel: 'coolChan-bnel', + channel: 'coolChannel', + subscription: 'coolChan-bnel', + timetoken: '14607577960925503', + publisher: 'client2', }, { - actualChannel: "coolChannel", + actualChannel: 'coolChannel', message: { - text: "Message10" + text: 'Message10', }, userMetadata: { - cool: "meta" + cool: 'meta', }, - subscribedChannel: "coolChan-bnel", - channel: "coolChannel", - subscription: "coolChan-bnel", - timetoken: "14607577960925503", - publisher: "client3" - } + subscribedChannel: 'coolChan-bnel', + channel: 'coolChannel', + subscription: 'coolChan-bnel', + timetoken: '14607577960925503', + publisher: 'client3', + }, ]); done(); @@ -197,7 +197,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}', + '{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"mySubKey","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}', { 'content-type': 'text/javascript' }, ); @@ -207,17 +207,17 @@ describe('#components/subscription_manager', () => { assert.equal(scope.isDone(), true); assert.deepEqual( { - channel: "coolChannel", - subscription: "coolChannel-pnpres", - actualChannel: "coolChannel", + channel: 'coolChannel', + subscription: 'coolChannel-pnpres', + actualChannel: 'coolChannel', occupancy: 1, - subscribedChannel: "coolChannel-pnpres", + subscribedChannel: 'coolChannel-pnpres', timestamp: 1461451222, - timetoken: "14614512228418349", - uuid: "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", - action: "join" + timetoken: '14614512228418349', + uuid: '4a6d5df7-e301-4e73-a7b7-6af9ab484eb0', + action: 'join', }, - presencePayload + presencePayload, ); done(); } catch (error) { @@ -241,7 +241,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"6","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"ch1","d":{"text":"Message"},"b":"ch1"}]}', + '{"t":{"t":"6","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"ch1","d":{"text":"Message"},"b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); utils @@ -334,16 +334,16 @@ describe('#components/subscription_manager', () => { try { assert.equal(scope1.isDone(), true); assert.deepEqual(presencePayload, { - channel: "ch10", - subscription: "ch10-pnpres", - actualChannel: "ch10", + channel: 'ch10', + subscription: 'ch10-pnpres', + actualChannel: 'ch10', occupancy: 3, - subscribedChannel: "ch10-pnpres", + subscribedChannel: 'ch10-pnpres', timestamp: 1463753674, - timetoken: "14637536741726901", - uuid: "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", - action: "state-change", - state: { state: "cool" } + timetoken: '14637536741726901', + uuid: '24c9bb19-1fcd-4c40-a6f1-522a8a1329ef', + action: 'state-change', + state: { state: 'cool' }, }); done(); } catch (error) { @@ -370,15 +370,15 @@ describe('#components/subscription_manager', () => { status(statusPayload) { if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; - let statusWithoutError = _.omit(statusPayload, 'errorData', 'statusCode'); + const statusWithoutError = _.omit(statusPayload, 'errorData', 'statusCode'); try { assert.deepEqual( { category: PubNub.CATEGORIES.PNUnknownCategory, error: true, - operation: PubNub.OPERATIONS.PNHeartbeatOperation + operation: PubNub.OPERATIONS.PNHeartbeatOperation, }, - statusWithoutError + statusWithoutError, ); done(); } catch (error) { @@ -410,7 +410,7 @@ describe('#components/subscription_manager', () => { status(statusPayload) { if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; - let statusWithoutError = _.omit(statusPayload, 'errorData'); + const statusWithoutError = _.omit(statusPayload, 'errorData'); try { assert.equal(scope.isDone(), true); assert.deepEqual( @@ -418,9 +418,9 @@ describe('#components/subscription_manager', () => { category: PubNub.CATEGORIES.PNBadRequestCategory, error: true, operation: PubNub.OPERATIONS.PNHeartbeatOperation, - statusCode: 400 + statusCode: 400, }, - statusWithoutError + statusWithoutError, ); done(); } catch (error) { @@ -459,9 +459,9 @@ describe('#components/subscription_manager', () => { error: false, operation: PubNub.OPERATIONS.PNHeartbeatOperation, category: PubNub.CATEGORIES.PNAcknowledgmentCategory, - statusCode: 200 + statusCode: 200, }, - statusPayload + statusPayload, ); done(); } catch (error) { @@ -500,9 +500,9 @@ describe('#components/subscription_manager', () => { error: false, operation: PubNub.OPERATIONS.PNHeartbeatOperation, category: PubNub.CATEGORIES.PNAcknowledgmentCategory, - statusCode: 200 + statusCode: 200, }, - statusPayload + statusPayload, ); done(); } catch (error) { @@ -541,9 +541,9 @@ describe('#components/subscription_manager', () => { error: false, operation: PubNub.OPERATIONS.PNHeartbeatOperation, category: PubNub.CATEGORIES.PNAcknowledgmentCategory, - statusCode: 200 + statusCode: 200, }, - statusPayload + statusPayload, ); done(); } catch (error) { @@ -569,7 +569,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"mySubKey","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}', { 'content-type': 'text/javascript' }, ); utils @@ -619,7 +619,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -635,7 +635,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}', { 'content-type': 'text/javascript' }, ); @@ -667,7 +667,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -683,7 +683,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}', { 'content-type': 'text/javascript' }, ); @@ -719,7 +719,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -735,7 +735,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message2"},"b":"coolChannel"}, {"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message2"},"b":"coolChannel"}, {"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"}]}', { 'content-type': 'text/javascript' }, ); @@ -765,11 +765,11 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":"hello","b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":"hello","b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); - let incomingPayloads = []; + const incomingPayloads = []; pubnubWithCrypto.addListener({ message(messagePayload) { @@ -779,15 +779,15 @@ describe('#components/subscription_manager', () => { assert.equal(scope.isDone(), true); assert.deepEqual(incomingPayloads, [ { - actualChannel: "coolChannel", - message: "hello", - subscribedChannel: "coolChan-bnel", - channel: "coolChannel", - subscription: "coolChan-bnel", - timetoken: "14607577960925503", - publisher: "client1", - error: "Error while decrypting message content: Decryption error: invalid header version" - } + actualChannel: 'coolChannel', + message: 'hello', + subscribedChannel: 'coolChan-bnel', + channel: 'coolChannel', + subscription: 'coolChan-bnel', + timetoken: '14607577960925503', + publisher: 'client1', + error: 'Error while decrypting message content: Decryption error: invalid header version', + }, ]); done(); } catch (error) { @@ -812,11 +812,11 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":"hello","b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":"hello","b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); - let incomingPayloads = []; + const incomingPayloads = []; pubnubWithCrypto.addListener({ message(messagePayload) { @@ -826,15 +826,15 @@ describe('#components/subscription_manager', () => { assert.equal(scope.isDone(), true); assert.deepEqual(incomingPayloads, [ { - actualChannel: "coolChannel", - message: "hello", - subscribedChannel: "coolChan-bnel", - channel: "coolChannel", - subscription: "coolChan-bnel", - timetoken: "14607577960925503", - publisher: "client1", - error: "Error while decrypting message content: Decryption error: invalid header version" - } + actualChannel: 'coolChannel', + message: 'hello', + subscribedChannel: 'coolChan-bnel', + channel: 'coolChannel', + subscription: 'coolChan-bnel', + timetoken: '14607577960925503', + publisher: 'client1', + error: 'Error while decrypting message content: Decryption error: invalid header version', + }, ]); done(); } catch (error) { @@ -858,11 +858,11 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":"UE5FRAFBQ1JIEIocqA6BfaybN/3U0WJRam0v3bPwfAXezgeCeGp+MztQ","b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":"UE5FRAFBQ1JIEIocqA6BfaybN/3U0WJRam0v3bPwfAXezgeCeGp+MztQ","b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); - let incomingPayloads = []; + const incomingPayloads = []; pubnubWithCrypto.addListener({ message(messagePayload) { @@ -872,14 +872,14 @@ describe('#components/subscription_manager', () => { assert.equal(scope.isDone(), true); assert.deepEqual(incomingPayloads, [ { - actualChannel: "coolChannel", - message: "hello", - subscribedChannel: "coolChan-bnel", - channel: "coolChannel", - subscription: "coolChan-bnel", - timetoken: "14607577960925503", - publisher: "client1" - } + actualChannel: 'coolChannel', + message: 'hello', + subscribedChannel: 'coolChan-bnel', + channel: 'coolChannel', + subscription: 'coolChan-bnel', + timetoken: '14607577960925503', + publisher: 'client1', + }, ]); done(); } catch (error) { diff --git a/test/integration/endpoints/signal.test.ts b/test/integration/endpoints/signal.test.ts index 4aca88ebe..74e56d6c4 100644 --- a/test/integration/endpoints/signal.test.ts +++ b/test/integration/endpoints/signal.test.ts @@ -61,7 +61,37 @@ describe('signal endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); + assert.deepEqual(response.timetoken, '14647523059145592'); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('send signal and signal listener called', (done) => { + const scope = utils + .createNock() + .get('/signal/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') + .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', auth: 'myAuthKey' }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.addListener({ + signal(signal) { + try { + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnub.signal({ message: { such: 'object' }, channel: 'ch1' }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, '14647523059145592'); assert.equal(scope.isDone(), true); done(); } catch (error) { diff --git a/test/integration/endpoints/subscribe.test.ts b/test/integration/endpoints/subscribe.test.ts index 7a5d9a619..e3c7a4599 100644 --- a/test/integration/endpoints/subscribe.test.ts +++ b/test/integration/endpoints/subscribe.test.ts @@ -65,7 +65,7 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -101,7 +101,7 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -140,7 +140,7 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -176,7 +176,7 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); @@ -214,7 +214,7 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14523669555221452","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14523669555221452","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ); const scope = utils @@ -248,4 +248,46 @@ describe('subscribe endpoints', () => { const subscription = channel.subscription(); subscription.subscribe({ timetoken: '1234567890' }); }); + + it.only('signal listener called for string signal', (done) => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/c1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: 0, + }) + .reply(200, '{"t":{"t":"14523669555221452","r":1},"m":[]}', { 'content-type': 'text/javascript' }); + utils + .createNock() + .get('/v2/subscribe/mySubKey/c1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '14523669555221452', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"14523669555221453","r":1},"m":[{"a":"3","f":0,"e":1,"i":"myUniqueUserId","p":{"t":"17200339136465528","r":41},"k":"mySubKey","c":"c1","d":"typing:start"}]}', + { 'content-type': 'text/javascript' }, + ); + + pubnubWithEE.addListener({ + signal(signal) { + try { + done(); + } catch (error) { + done(error); + } + }, + }); + + const channel = pubnubWithEE.channel('c1'); + const subscription = channel.subscription(); + subscription.subscribe(); + }); }); diff --git a/test/integration/operations/unsubscribe.test.ts b/test/integration/operations/unsubscribe.test.ts index c4c5de053..919c4e7d3 100644 --- a/test/integration/operations/unsubscribe.test.ts +++ b/test/integration/operations/unsubscribe.test.ts @@ -47,7 +47,7 @@ describe('unsubscribe', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ) .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1/leave') @@ -63,7 +63,7 @@ describe('unsubscribe', () => { try { assert.equal(status.error, false); assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, ["ch1"]); + assert.deepEqual(status.affectedChannels, ['ch1']); assert.deepEqual(status.affectedChannelGroups, []); done(); } catch (error) { @@ -87,7 +87,7 @@ describe('unsubscribe', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ) .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1,ch2/leave') @@ -103,7 +103,7 @@ describe('unsubscribe', () => { try { assert.equal(status.error, false); assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, ["ch1", "ch2"]); + assert.deepEqual(status.affectedChannels, ['ch1', 'ch2']); assert.deepEqual(status.affectedChannelGroups, []); done(); } catch (error) { @@ -128,7 +128,7 @@ describe('unsubscribe', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ) .get('/v2/presence/sub-key/mySubscribeKey/channel/,/leave') @@ -146,7 +146,7 @@ describe('unsubscribe', () => { assert.equal(status.error, false); assert.equal(scope.isDone(), true); assert.deepEqual(status.affectedChannels, []); - assert.deepEqual(status.affectedChannelGroups, ["cg1"]); + assert.deepEqual(status.affectedChannelGroups, ['cg1']); done(); } catch (error) { done(error); @@ -170,7 +170,7 @@ describe('unsubscribe', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"sub-c-4cec9f8e-01fa-11e6-8180-0619f8945a4f","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"coolChannel","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', { 'content-type': 'text/javascript' }, ) .get('/v2/presence/sub-key/mySubscribeKey/channel/,/leave') @@ -188,7 +188,7 @@ describe('unsubscribe', () => { assert.equal(status.error, false); assert.equal(scope.isDone(), true); assert.deepEqual(status.affectedChannels, []); - assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]); + assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']); done(); } catch (error) { done(error); @@ -220,7 +220,7 @@ describe('unsubscribe', () => { try { assert.equal(status.error, false); assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, ["ch1"]); + assert.deepEqual(status.affectedChannels, ['ch1']); assert.deepEqual(status.affectedChannelGroups, []); done(); } catch (error) { @@ -253,7 +253,7 @@ describe('unsubscribe', () => { assert.equal(status.error, false); assert.equal(scope.isDone(), true); assert.deepEqual(status.affectedChannels, []); - assert.deepEqual(status.affectedChannelGroups, ["cg1"]); + assert.deepEqual(status.affectedChannelGroups, ['cg1']); done(); } catch (error) { done(error); @@ -283,8 +283,8 @@ describe('unsubscribe', () => { try { assert.equal(status.error, false); assert.equal(scope.isDone(), true); - assert.deepEqual(status.affectedChannels, ["ch1", "ch2"]); - assert.deepEqual(status.affectedChannelGroups, ["cg1", "cg2"]); + assert.deepEqual(status.affectedChannels, ['ch1', 'ch2']); + assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2']); done(); } catch (error) { done(error); From cac7bc7e7c59568df2d10ffe5c36369b9f5e74cd Mon Sep 17 00:00:00 2001 From: Mateusz Wiktor <39187473+techwritermat@users.noreply.github.com> Date: Thu, 18 Jul 2024 14:57:44 +0200 Subject: [PATCH 17/49] Update README.md (#392) docs(readme): fix readme Fix PubNub client configuration and listener documentation. --- .pubnub.yml | 6 +-- CHANGELOG.md | 8 ++-- README.md | 122 +++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 98 insertions(+), 38 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 0d0762abe..3191e25c6 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,10 +1,10 @@ --- changelog: - - date: 2024-07-04 + - date: 2024-07-18 version: v8.2.5 changes: - - type: bug - text: "Fix issue because of which `signals` sent as `string` not handler properly." + - type: improvement + text: "Fix PubNub client configuration and listener documentation." - date: 2024-06-17 version: v8.2.4 changes: diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aad8a87a..bacc110dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,10 @@ ## v8.2.5 -July 04 2024 +July 18 2024 + +#### Modified +- Fix PubNub client configuration and listener documentation. + -#### Fixed -- Fix issue because of which `signals` sent as `string` not handler properly. Fixed the following issues reported by [@roman-rr](https://github.com/roman-rr): [#387](https://github.com/pubnub/javascript/issues/387). ## v8.2.4 June 17 2024 diff --git a/README.md b/README.md index 8626e42b0..7e2758a2b 100644 --- a/README.md +++ b/README.md @@ -35,65 +35,123 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 ```javascript pubnub = new PubNub({ - publishKey : "myPublishKey", - subscribeKey : "mySubscribeKey", - uuid: "myUniqueUUID" - }) + publishKey: 'myPublishKey', + subscribeKey: 'mySubscribeKey', + userId: 'myUniqueUserId', + }); ``` ## Add event listeners ```javascript -pubnub.addListener({ +// create a subscription from a channel entity +const channel = pubnub.channel('my_channel'); +const subscription = channel.subscription(); +subscription.subscribe(); + +// Event-specific listeners +subscription.onMessage = (messageEvent) => { console.log("Message event: ", messageEvent); }; +subscription.onPresence = (presenceEvent) => { console.log("Presence event: ", presenceEvent); }; +subscription.onMessage = (messageEvent) => { console.log("Message event: ", messageEvent); }; +subscription.onPresence = (presenceEvent) => { console.log("Presence event: ", presenceEvent); }; +subscription.onSignal = (signalEvent) => { console.log("Signal event: ", signalEvent); }; +subscription.onObjects = (objectsEvent) => { console.log("Objects event: ", objectsEvent); }; +subscription.onMessageAction = (messageActionEvent) => { console.log("Message Action event: ", messageActionEvent); }; +subscription.onFile = (fileEvent) => { console.log("File event: ", fileEvent); }; + +// Generic listeners +subscription.addListener({ + // Messages message: function (m) { - // handle messages + const channelName = m.channel; // Channel on which the message was published + const channelGroup = m.subscription; // Channel group or wildcard subscription match (if exists) + const pubTT = m.timetoken; // Publish timetoken + const msg = m.message; // Message payload + const publisher = m.publisher; // Message publisher }, + // Presence + // requires a subscription with presence presence: function (p) { - // handle presence + const action = p.action; // Can be join, leave, state-change, or timeout + const channelName = p.channel; // Channel to which the message belongs + const occupancy = p.occupancy; // Number of users subscribed to the channel + const state = p.state; // User state + const channelGroup = p.subscription; // Channel group or wildcard subscription match, if any + const publishTime = p.timestamp; // Publish timetoken + const timetoken = p.timetoken; // Current timetoken + const uuid = p.uuid; // UUIDs of users who are subscribed to the channel }, + // Signals signal: function (s) { - // handle signals + const channelName = s.channel; // Channel to which the signal belongs + const channelGroup = s.subscription; // Channel group or wildcard subscription match, if any + const pubTT = s.timetoken; // Publish timetoken + const msg = s.message; // Payload + const publisher = s.publisher; // Message publisher }, + // App Context objects: (objectEvent) => { - // handle objects + const channel = objectEvent.channel; // Channel to which the event belongs + const channelGroup = objectEvent.subscription; // Channel group + const timetoken = objectEvent.timetoken; // Event timetoken + const publisher = objectEvent.publisher; // UUID that made the call + const event = objectEvent.event; // Name of the event that occurred + const type = objectEvent.type; // Type of the event that occurred + const data = objectEvent.data; // Data from the event that occurred }, + // Message Reactions messageAction: function (ma) { - // handle message actions + const channelName = ma.channel; // Channel to which the message belongs + const publisher = ma.publisher; // Message publisher + const event = ma.event; // Message action added or removed + const type = ma.data.type; // Message action type + const value = ma.data.value; // Message action value + const messageTimetoken = ma.data.messageTimetoken; // Timetoken of the original message + const actionTimetoken = ma.data.actionTimetoken; // Timetoken of the message action }, + // File Sharing file: function (event) { - // handle files - }, - status: function (s) { - // handle status - }, + const channelName = event.channel; // Channel to which the file belongs + const channelGroup = event.subscription; // Channel group or wildcard subscription match (if exists) + const publisher = event.publisher; // File publisher + const timetoken = event.timetoken; // Event timetoken + + const message = event.message; // Optional message attached to the file + const fileId = event.file.id; // File unique id + const fileName = event.file.name;// File name + const fileUrl = event.file.url; // File direct URL + } }); ``` ## Publish/subscribe ```javascript -var publishPayload = { - channel : "hello_world", - message: { - title: "greeting", - description: "This is my first message!" - } +const channel = pubnub.channel('my_channel'); +const subscription = channel.subscription(); +subscription.subscribe(); + +try { + const result = await pubnub.publish({ + message: { + such: "object", + }, + channel: "my_channel", + sendByPost: false, // true to send via post + storeInHistory: false, //override default Message Persistence options + meta: { + cool: "meta", + }, // publish extra meta with the request + }); +} catch (status) { + console.log(status); } - -pubnub.publish(publishPayload, function(status, response) { - console.log(status, response); -}) - -pubnub.subscribe({ - channels: ["hello_world"] -}); ``` ## Documentation -* [Build your first realtime JS app with PubNub](https://www.pubnub.com/docs/platform/quickstarts/javascript) -* [API reference for JavaScript (web)](https://www.pubnub.com/docs/web-javascript/pubnub-javascript-sdk) -* [API reference for JavaScript (Node.js)](https://www.pubnub.com/docs/nodejs-javascript/pubnub-javascript-sdk) +* [Build your first realtime JS app with PubNub](https://www.pubnub.com/tutorials/real-time-data-streaming/) +* [API reference for JavaScript](https://www.pubnub.com/docs/sdks/javascript/api-reference/publish-and-subscribe) ## Support From 44f9d6ca8f6ac45600e472e65b20e35220d864c8 Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Tue, 23 Jul 2024 18:40:04 +0530 Subject: [PATCH 18/49] Support for subscription with presence channels (#393) fix: fix issue with unsubscribe call when presence channels included manually. Resolves the issue of manually included presence channels not being unsubscribed from the subscription set. --- .pubnub.yml | 11 +++-- CHANGELOG.md | 6 +++ README.md | 4 +- dist/web/pubnub.js | 14 +++--- dist/web/pubnub.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/entities/SubscribeCapable.js | 4 +- lib/entities/SubscriptionSet.js | 8 +--- package-lock.json | 4 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/entities/SubscribeCapable.ts | 4 +- src/entities/SubscriptionSet.ts | 24 +++++------ test/integration/endpoints/subscribe.test.ts | 45 +++++++++++++++++++- 14 files changed, 87 insertions(+), 45 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 3191e25c6..2642e8ff5 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-07-23 + version: v8.2.6 + changes: + - type: bug + text: "Resolves the issue of manually included presence channels not being unsubscribed from the subscription set." - date: 2024-07-18 version: v8.2.5 changes: @@ -1013,7 +1018,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.5' +version: '8.2.6' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1029,7 +1034,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.5.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.6.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1700,7 +1705,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.5/pubnub.8.2.5.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.6/pubnub.8.2.6.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index bacc110dd..10845d89c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.2.6 +July 23 2024 + +#### Fixed +- Resolves the issue of manually included presence channels not being unsubscribed from the subscription set. Fixed the following issues reported by [@roman-rr](https://github.com/roman-rr): [#390](https://github.com/pubnub/javascript/issues/390). + ## v8.2.5 July 18 2024 diff --git a/README.md b/README.md index 7e2758a2b..95205e6a7 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.5.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.5.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.6.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.6.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 1a5e6c67d..269540556 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3813,7 +3813,7 @@ return base.PubNubFile; }, get version() { - return '8.2.5'; + return '8.2.6'; }, getVersion() { return this.version; @@ -8969,8 +8969,8 @@ } unsubscribe() { this.pubnub.unsubscribe({ - channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')), - channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), + channels: this.channelNames, + channelGroups: this.groupNames, }); } set onMessage(onMessageListener) { @@ -9014,16 +9014,12 @@ this.options = subscriptionOptions; this.eventEmitter = eventEmitter; this.pubnub = pubnub; - channels - .filter((c) => !c.endsWith('-pnpres')) - .forEach((c) => { + channels.forEach((c) => { const subscription = this.pubnub.channel(c).subscription(this.options); this.channelNames = [...this.channelNames, ...subscription.channels]; this.subscriptionList.push(subscription); }); - channelGroups - .filter((cg) => !cg.endsWith('-pnpres')) - .forEach((cg) => { + channelGroups.forEach((cg) => { const subscription = this.pubnub.channelGroup(cg).subscription(this.options); this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.subscriptionList.push(subscription); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 99e92f2ee..c29c2f0f1 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.5"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames.filter((e=>!e.endsWith("-pnpres"))),channelGroups:this.groupNames.filter((e=>!e.endsWith("-pnpres")))})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.filter((e=>!e.endsWith("-pnpres"))).forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.6"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index a4a50de87..15d1159af 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.5'; + return '8.2.6'; }, getVersion() { return this.version; diff --git a/lib/entities/SubscribeCapable.js b/lib/entities/SubscribeCapable.js index d8f93069c..26d1c379a 100644 --- a/lib/entities/SubscribeCapable.js +++ b/lib/entities/SubscribeCapable.js @@ -8,8 +8,8 @@ class SubscribeCapable { } unsubscribe() { this.pubnub.unsubscribe({ - channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')), - channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), + channels: this.channelNames, + channelGroups: this.groupNames, }); } set onMessage(onMessageListener) { diff --git a/lib/entities/SubscriptionSet.js b/lib/entities/SubscriptionSet.js index 46f048685..2f6c22efe 100644 --- a/lib/entities/SubscriptionSet.js +++ b/lib/entities/SubscriptionSet.js @@ -11,16 +11,12 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.options = subscriptionOptions; this.eventEmitter = eventEmitter; this.pubnub = pubnub; - channels - .filter((c) => !c.endsWith('-pnpres')) - .forEach((c) => { + channels.forEach((c) => { const subscription = this.pubnub.channel(c).subscription(this.options); this.channelNames = [...this.channelNames, ...subscription.channels]; this.subscriptionList.push(subscription); }); - channelGroups - .filter((cg) => !cg.endsWith('-pnpres')) - .forEach((cg) => { + channelGroups.forEach((cg) => { const subscription = this.pubnub.channelGroup(cg).subscription(this.options); this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.subscriptionList.push(subscription); diff --git a/package-lock.json b/package-lock.json index fb656bc4e..912adebdd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.2.3", + "version": "8.2.5", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.2.3", + "version": "8.2.5", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", diff --git a/package.json b/package.json index f2395b966..9ba28b1be 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.5", + "version": "8.2.6", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 07fb358cc..1d046a0dd 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.5'; + return '8.2.6'; }, getVersion(): string { return this.version; diff --git a/src/entities/SubscribeCapable.ts b/src/entities/SubscribeCapable.ts index c5ddb7347..0454a323a 100644 --- a/src/entities/SubscribeCapable.ts +++ b/src/entities/SubscribeCapable.ts @@ -22,8 +22,8 @@ export abstract class SubscribeCapable { } unsubscribe() { this.pubnub.unsubscribe({ - channels: this.channelNames.filter((c) => !c.endsWith('-pnpres')), - channelGroups: this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), + channels: this.channelNames, + channelGroups: this.groupNames, }); } diff --git a/src/entities/SubscriptionSet.ts b/src/entities/SubscriptionSet.ts index 970ff7754..1885d3bef 100644 --- a/src/entities/SubscriptionSet.ts +++ b/src/entities/SubscriptionSet.ts @@ -31,20 +31,16 @@ export class SubscriptionSet extends SubscribeCapable { this.options = subscriptionOptions; this.eventEmitter = eventEmitter; this.pubnub = pubnub; - channels - .filter((c) => !c.endsWith('-pnpres')) - .forEach((c) => { - const subscription = this.pubnub.channel(c).subscription(this.options); - this.channelNames = [...this.channelNames, ...subscription.channels]; - this.subscriptionList.push(subscription); - }); - channelGroups - .filter((cg) => !cg.endsWith('-pnpres')) - .forEach((cg) => { - const subscription = this.pubnub.channelGroup(cg).subscription(this.options); - this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.subscriptionList.push(subscription); - }); + channels.forEach((c) => { + const subscription = this.pubnub.channel(c).subscription(this.options); + this.channelNames = [...this.channelNames, ...subscription.channels]; + this.subscriptionList.push(subscription); + }); + channelGroups.forEach((cg) => { + const subscription = this.pubnub.channelGroup(cg).subscription(this.options); + this.groupNames = [...this.groupNames, ...subscription.channelGroups]; + this.subscriptionList.push(subscription); + }); this.listener = {}; eventEmitter.addListener( this.listener, diff --git a/test/integration/endpoints/subscribe.test.ts b/test/integration/endpoints/subscribe.test.ts index e3c7a4599..f28330e50 100644 --- a/test/integration/endpoints/subscribe.test.ts +++ b/test/integration/endpoints/subscribe.test.ts @@ -249,7 +249,7 @@ describe('subscribe endpoints', () => { subscription.subscribe({ timetoken: '1234567890' }); }); - it.only('signal listener called for string signal', (done) => { + it('signal listener called for string signal', (done) => { utils .createNock() .get('/v2/subscribe/mySubKey/c1/0') @@ -290,4 +290,47 @@ describe('subscribe endpoints', () => { const subscription = channel.subscription(); subscription.subscribe(); }); + + it('supports subscribe() with presence channelnames', () => { + const scope0 = utils + .createNock() + .get('/v2/subscribe/mySubKey/c1,c2-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: 0, + }) + .reply( + 200, + '{"t":{"t":"14523669555221452","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"c1","d":{"text":"Enter Message Here"},"b":"coolChan-bnel"}]}', + { 'content-type': 'text/javascript' }, + ); + const scope = utils + .createNock() + .get('/v2/subscribe/mySubKey/c1,c2-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '1234567890', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"146075779609322","r":1},"m":[{"a":"4","f":0,"i":"test","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"c1","d":{"text":"customttresponse"},"b":"c1"}]}', + { 'content-type': 'text/javascript' }, + ); + + const subsripptionSetWithPresenceChannels = pubnubWithEE.subscriptionSet({ + channels: ['c1', 'c2-pnpres'], + }); + + subsripptionSetWithPresenceChannels.subscribe(); + + assert.deepEqual(pubnubWithEE.getSubscribedChannels(), ['c1', 'c2-pnpres']); + + subsripptionSetWithPresenceChannels.unsubscribe(); + assert.deepEqual(pubnubWithEE.getSubscribedChannels(), []); + }); }); From ba45db4d757415390842b7015202b4db20398c23 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 1 Aug 2024 11:35:20 +0300 Subject: [PATCH 19/49] Fix issue with enforced timeout (#397) fix(transport): fix issue with enforced timeout Fix issue because of which timeout enforced by browser triggered wrong error status category. --- .pubnub.yml | 11 ++++++++--- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- dist/web/pubnub.js | 7 +++++-- dist/web/pubnub.min.js | 4 ++-- lib/core/components/configuration.js | 2 +- lib/errors/pubnub-api-error.js | 5 ++++- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/errors/pubnub-api-error.ts | 4 +++- 10 files changed, 33 insertions(+), 14 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 2642e8ff5..6408e861e 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-08-01 + version: v8.2.7 + changes: + - type: bug + text: "Fix issue because of which timeout enforced by browser triggered wrong error status category." - date: 2024-07-23 version: v8.2.6 changes: @@ -1018,7 +1023,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.6' +version: '8.2.7' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1034,7 +1039,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.6.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.7.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1705,7 +1710,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.6/pubnub.8.2.6.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.7/pubnub.8.2.7.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 10845d89c..cd667a5dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.2.7 +August 01 2024 + +#### Fixed +- Fix issue because of which timeout enforced by browser triggered wrong error status category. Fixed the following issues reported by [@WalrusSoup](https://github.com/WalrusSoup): [#396](https://github.com/pubnub/javascript/issues/396). + ## v8.2.6 July 23 2024 diff --git a/README.md b/README.md index 95205e6a7..3dafbfeec 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.6.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.6.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.7.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.7.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 269540556..be6bfe0c1 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -2839,7 +2839,10 @@ message = 'Network issues'; } else if (errorName === 'TypeError') { - category = StatusCategory$1.PNBadRequestCategory; + if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) + category = StatusCategory$1.PNTimeoutCategory; + else + category = StatusCategory$1.PNBadRequestCategory; } else if (errorName === 'FetchError') { const errorCode = error.code; @@ -3813,7 +3816,7 @@ return base.PubNubFile; }, get version() { - return '8.2.6'; + return '8.2.7'; }, getVersion() { return this.version; diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index c29c2f0f1..b4cf0254a 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.6"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNTimeoutCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.7"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 15d1159af..d0979de6d 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.6'; + return '8.2.7'; }, getVersion() { return this.version; diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js index 1f09b98b7..4ac0d928a 100644 --- a/lib/errors/pubnub-api-error.js +++ b/lib/errors/pubnub-api-error.js @@ -62,7 +62,10 @@ class PubNubAPIError extends Error { message = 'Network issues'; } else if (errorName === 'TypeError') { - category = categories_1.default.PNBadRequestCategory; + if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) + category = categories_1.default.PNTimeoutCategory; + else + category = categories_1.default.PNBadRequestCategory; } else if (errorName === 'FetchError') { const errorCode = error.code; diff --git a/package.json b/package.json index 9ba28b1be..15c83ea45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.6", + "version": "8.2.7", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 1d046a0dd..2f3d24fd7 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.6'; + return '8.2.7'; }, getVersion(): string { return this.version; diff --git a/src/errors/pubnub-api-error.ts b/src/errors/pubnub-api-error.ts index 793deb1bb..c00ce0394 100644 --- a/src/errors/pubnub-api-error.ts +++ b/src/errors/pubnub-api-error.ts @@ -58,7 +58,9 @@ export class PubNubAPIError extends Error { category = StatusCategory.PNNetworkIssuesCategory; message = 'Network issues'; } else if (errorName === 'TypeError') { - category = StatusCategory.PNBadRequestCategory; + if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) + category = StatusCategory.PNTimeoutCategory; + else category = StatusCategory.PNBadRequestCategory; } else if (errorName === 'FetchError') { const errorCode = (error as Record).code; From bc85e1d36dba5c398d9fe861129556dcea718fd8 Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:46:44 +0530 Subject: [PATCH 20/49] update lock file to eliminate dependabot alerts (#402) --- package-lock.json | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 912adebdd..e3f4878d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.2.5", + "version": "8.2.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.2.5", + "version": "8.2.7", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", @@ -5612,9 +5612,9 @@ "peer": true }, "node_modules/body-parser": { - "version": "1.20.2", - "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.2.tgz", - "integrity": "sha512-ml9pReCu3M61kGlqoTm2umSXTlRTuGTx0bfYj+uIUKKYycG5NtSbeetV3faSU6R7ajOPw0g/J1PvK4qNy7s5bA==", + "version": "1.20.3", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz", + "integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==", "dev": true, "dependencies": { "bytes": "3.1.2", @@ -10330,9 +10330,9 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dependencies": { "braces": "^3.0.3", "picomatch": "^2.3.1" @@ -10840,10 +10840,13 @@ } }, "node_modules/object-inspect": { - "version": "1.13.1", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", - "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", + "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", "dev": true, + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -11139,9 +11142,9 @@ } }, "node_modules/path-to-regexp": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", - "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.9.0.tgz", + "integrity": "sha512-xIp7/apCFJuUHdDLWe8O1HIkb0kQrOMb/0u6FXQjemHn/ii5LrIzU6bdECnsiTF/GjZkMEKg1xdiZwNqDYlZ6g==", "dev": true, "dependencies": { "isarray": "0.0.1" @@ -11445,12 +11448,12 @@ } }, "node_modules/qs": { - "version": "6.11.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", "dev": true, "dependencies": { - "side-channel": "^1.0.4" + "side-channel": "^1.0.6" }, "engines": { "node": ">=0.6" From 0beda2cb0b80eba69309111fb27a76d8c6319081 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 1 Oct 2024 02:32:05 +0300 Subject: [PATCH 21/49] Fix subscribe request aggregation in `SharedWorker`. (#403) fix(shared-worker): fix presence leave request preparation Fix issue because of which leave request modified wrong URL path component with actual channels. fix(shared-worker): fix channels / groups list modification issues Fix issue because of which removed channels / groups didn't cancel previous subscribe request to re-subscribe with new set of channels / groups. fix(shared-worker): fix requests aggregation issues Fix issue because of which suitable active PubNub clients subscription not has been used for aggregation and caused additional connections or wrong set of channels / groups. refactor(subscription): process messages only for subscribed Pre-process entries from subscribe response to filter out updates which has been received for channels and groups which are not part of subscription loop (subscription aggregation in shared worker). refactor(package): add `types` entry for Node.js integration Point to the built-in types definition file when package used with npm / yarn. --------- Co-authored-by: Mohit Tejani Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> --- .pubnub.yml | 19 +- CHANGELOG.md | 12 + README.md | 4 +- dist/web/pubnub.js | 10 +- dist/web/pubnub.min.js | 2 +- dist/web/pubnub.worker.js | 274 ++++++++++++--- dist/web/pubnub.worker.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/endpoints/subscribe.js | 8 +- package-lock.json | 37 +- package.json | 4 +- src/core/components/configuration.ts | 2 +- src/core/endpoints/subscribe.ts | 88 ++--- .../subscription-worker.ts | 327 ++++++++++++++++-- .../components/subscription_manager.test.ts | 94 ++--- 15 files changed, 689 insertions(+), 196 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 6408e861e..25f227059 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,18 @@ --- changelog: + - date: 2024-09-30 + version: v8.2.8 + changes: + - type: bug + text: "Fix issue because of which leave request modified wrong URL path component with actual channels." + - type: bug + text: "Fix issue because of which removed channels / groups didn't cancel previous subscribe request to re-subscribe with new set of channels / groups." + - type: bug + text: "Fix issue because of which suitable active PubNub clients subscription not has been used for aggregation and caused additional connections or wrong set of channels / groups." + - type: improvement + text: "Pre-process entries from subscribe response to filter out updates which has been received for channels and groups which are not part of subscription loop (subscription aggregation in shared worker)." + - type: improvement + text: "Point to the built-in types definition file when package used with `npm` / `yarn`." - date: 2024-08-01 version: v8.2.7 changes: @@ -1023,7 +1036,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.7' +version: '8.2.8' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1039,7 +1052,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.7.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.8.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1710,7 +1723,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.7/pubnub.8.2.7.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.8/pubnub.8.2.8.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index cd667a5dd..2b1f64972 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## v8.2.8 +September 30 2024 + +#### Fixed +- Fix issue because of which leave request modified wrong URL path component with actual channels. +- Fix issue because of which removed channels / groups didn't cancel previous subscribe request to re-subscribe with new set of channels / groups. +- Fix issue because of which suitable active PubNub clients subscription not has been used for aggregation and caused additional connections or wrong set of channels / groups. + +#### Modified +- Pre-process entries from subscribe response to filter out updates which has been received for channels and groups which are not part of subscription loop (subscription aggregation in shared worker). +- Point to the built-in types definition file when package used with `npm` / `yarn`. + ## v8.2.7 August 01 2024 diff --git a/README.md b/README.md index 3dafbfeec..091457572 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.7.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.7.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.8.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.8.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index be6bfe0c1..45fefd7dd 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3816,7 +3816,7 @@ return base.PubNubFile; }, get version() { - return '8.2.7'; + return '8.2.8'; }, getVersion() { return this.version; @@ -5868,7 +5868,13 @@ if (!serviceResponse) { throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); } - const events = serviceResponse.m.map((envelope) => { + const events = serviceResponse.m + .filter((envelope) => { + const subscribable = envelope.b === undefined ? envelope.c : envelope.b; + return ((this.parameters.channels && this.parameters.channels.includes(subscribable)) || + (this.parameters.channelGroups && this.parameters.channelGroups.includes(subscribable))); + }) + .map((envelope) => { let { e: eventType } = envelope; // Resolve missing event type. eventType !== null && eventType !== void 0 ? eventType : (eventType = envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index b4cf0254a..34c4dcc6b 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNTimeoutCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.7"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.8"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index b033cf48e..abe7ea21d 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -109,7 +109,18 @@ /** * How often PING request should be sent to the PubNub clients. */ - const clientPingRequestInterval = 5000; + const clientPingRequestInterval = 10000; + /** + * Aggregation timer timeout. + * + * Timeout used by the timer to postpone `handleSendSubscribeRequestEvent` function call and let other clients for + * same subscribe key send next subscribe loop request (to make aggregation more efficient). + */ + const subscribeAggregationTimeout = 50; + /** + * Map of PubNub client subscription keys to the started aggregation timeout timers. + */ + const aggregationTimers = new Map(); // region State /** * Service `ArrayBuffer` response decoder. @@ -193,7 +204,18 @@ else if (data.type === 'send-request') { if (data.request.path.startsWith('/v2/subscribe')) { updateClientStateIfRequired(data); - handleSendSubscribeRequestEvent(data); + const client = pubNubClients[data.clientIdentifier]; + if (client) { + const timerIdentifier = `${client.userId}-${client.subscriptionKey}`; + // Check whether we need to start new aggregation timer or not. + if (!aggregationTimers.has(timerIdentifier)) { + const aggregationTimer = setTimeout(() => { + handleSendSubscribeRequestEvent(data); + aggregationTimers.delete(timerIdentifier); + }, subscribeAggregationTimeout); + aggregationTimers.set(timerIdentifier, aggregationTimer); + } + } } else handleSendLeaveRequestEvent(data); @@ -210,21 +232,45 @@ * @param event - Subscription event details. */ const handleSendSubscribeRequestEvent = (event) => { + var _a; const requestOrId = subscribeTransportRequestFromEvent(event); const client = pubNubClients[event.clientIdentifier]; - if (client) + let isInitialSubscribe = false; + if (client) { + if (client.subscription) + isInitialSubscribe = client.subscription.timetoken === '0'; notifyRequestProcessing('start', [client], new Date().toISOString()); + } if (typeof requestOrId === 'string') { - if (client && client.subscription) { - // Updating client timetoken information. - client.subscription.previousTimetoken = client.subscription.timetoken; - client.subscription.timetoken = serviceRequests[requestOrId].timetoken; - client.subscription.serviceRequestId = requestOrId; + const scheduledRequest = serviceRequests[requestOrId]; + if (client) { + if (client.subscription) { + // Updating client timetoken information. + client.subscription.timetoken = scheduledRequest.timetoken; + client.subscription.region = scheduledRequest.region; + client.subscription.serviceRequestId = requestOrId; + } + if (!isInitialSubscribe) + return; + const body = new TextEncoder().encode(`{"t":{"t":"${scheduledRequest.timetoken}","r":${(_a = scheduledRequest.region) !== null && _a !== void 0 ? _a : '0'}},"m":[]}`); + const headers = new Headers({ + 'Content-Type': 'text/javascript; charset="UTF-8"', + 'Content-Length': `${body.length}`, + }); + const response = new Response(body, { status: 200, headers }); + const result = requestProcessingSuccess([response, body]); + result.url = `${event.request.origin}${event.request.path}`; + result.clientIdentifier = event.clientIdentifier; + result.identifier = event.request.identifier; + notifyRequestProcessing('end', [client], new Date().toISOString(), event.request, body, headers.get('Content-Type'), 0); + publishClientEvent(client, result); } return; } if (event.request.cancellable) abortControllers.set(requestOrId.identifier, new AbortController()); + const scheduledRequest = serviceRequests[requestOrId.identifier]; + const { timetokenOverride, regionOverride } = scheduledRequest; sendRequest(requestOrId, () => clientsForRequest(requestOrId.identifier), (clients, response) => { // Notify each PubNub client which awaited for response. notifyRequestProcessingResult(clients, response); @@ -235,22 +281,84 @@ notifyRequestProcessingResult(clients, null, requestOrId, requestProcessingError(error)); // Clean up scheduled request and client references to it. markRequestCompleted(clients, requestOrId.identifier); + }, (response) => { + let serverResponse = response; + if (isInitialSubscribe && timetokenOverride && timetokenOverride !== '0') { + serviceRequests[requestOrId.identifier]; + serverResponse = patchInitialSubscribeResponse(serverResponse, timetokenOverride, regionOverride); + } + return serverResponse; }); consoleLog(`'${Object.keys(serviceRequests).length}' subscription request currently active.`); }; + const patchInitialSubscribeResponse = (serverResponse, timetoken, region) => { + if (timetoken === undefined || timetoken === '0' || serverResponse[0].status >= 400) { + return serverResponse; + } + let json; + const response = serverResponse[0]; + let decidedResponse = response; + let body = serverResponse[1]; + try { + json = JSON.parse(new TextDecoder().decode(body)); + } + catch (error) { + consoleLog(`Subscribe response parse error: ${error}`); + return serverResponse; + } + // Replace server-provided timetoken. + json.t.t = timetoken; + if (region) + json.t.r = parseInt(region, 10); + try { + body = new TextEncoder().encode(JSON.stringify(json)).buffer; + if (body.byteLength) { + const headers = new Headers(response.headers); + headers.set('Content-Length', `${body.byteLength}`); + // Create a new response with the original response options and modified headers + decidedResponse = new Response(body, { + status: response.status, + statusText: response.statusText, + headers: headers, + }); + } + } + catch (error) { + consoleLog(`Subscribe serialization error: ${error}`); + return serverResponse; + } + return body.byteLength > 0 ? [decidedResponse, body] : serverResponse; + }; /** * Handle client request to leave request. * * @param data - Leave event details. */ const handleSendLeaveRequestEvent = (data) => { - const request = leaveTransportRequestFromEvent(data); const client = pubNubClients[data.clientIdentifier]; + const request = leaveTransportRequestFromEvent(data); if (!client) return; + // Clean up client subscription information if there is no more channels / groups to use. + const { subscription } = client; + const serviceRequestId = subscription === null || subscription === void 0 ? void 0 : subscription.serviceRequestId; + if (subscription) { + if (subscription.channels.length === 0 && subscription.channelGroups.length === 0) { + subscription.channelGroupQuery = ''; + subscription.path = ''; + subscription.previousTimetoken = '0'; + subscription.timetoken = '0'; + delete subscription.region; + delete subscription.serviceRequestId; + delete subscription.request; + } + } if (!request) { const body = new TextEncoder().encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'); - const headers = new Headers({ 'Content-Type': 'text/javascript; charset="UTF-8"', 'Content-Length': '74' }); + const headers = new Headers({ + 'Content-Type': 'text/javascript; charset="UTF-8"', + 'Content-Length': `${body.length}`, + }); const response = new Response(body, { status: 200, headers }); const result = requestProcessingSuccess([response, body]); result.url = `${data.request.origin}${data.request.path}`; @@ -267,6 +375,17 @@ notifyRequestProcessingResult(clients, null, data.request, requestProcessingError(error)); }); consoleLog(`Started leave request.`, client); + // Check whether there were active subscription with channels from this client or not. + if (serviceRequestId === undefined) + return; + // Update ongoing clients + const clients = clientsForRequest(serviceRequestId); + clients.forEach((client) => { + if (client && client.subscription) + delete client.subscription.serviceRequestId; + }); + cancelRequest(serviceRequestId); + restartSubscribeRequestForClients(clients); }; /** * Handle cancel request event. @@ -284,16 +403,44 @@ return; // Unset awaited requests. delete client.subscription.serviceRequestId; - delete client.subscription.request; - if (clientsForRequest(serviceRequestId).length === 0) { - const controller = abortControllers.get(serviceRequestId); - abortControllers.delete(serviceRequestId); - // Clean up scheduled requests. - delete serviceRequests[serviceRequestId]; - // Abort request if possible. - if (controller) - controller.abort(); + if (client.subscription.request && client.subscription.request.identifier === event.identifier) { + delete client.subscription.request; } + cancelRequest(serviceRequestId); + }; + // endregion + // -------------------------------------------------------- + // --------------------- Subscription --------------------- + // -------------------------------------------------------- + // region Subscription + /** + * Try restart subscribe request for the list of clients. + * + * Subscribe restart will use previous timetoken information to schedule new subscription loop. + * + * **Note:** This function mimics behaviour when SharedWorker receives request from PubNub SDK. + * + * @param clients List of PubNub client states for which new aggregated request should be sent. + */ + const restartSubscribeRequestForClients = (clients) => { + let clientWithRequest; + let request; + for (const client of clients) { + if (client.subscription && client.subscription.request) { + request = client.subscription.request; + clientWithRequest = client; + break; + } + } + if (!request || !clientWithRequest) + return; + handleSendSubscribeRequestEvent({ + type: 'send-request', + clientIdentifier: clientWithRequest.clientIdentifier, + subscriptionKey: clientWithRequest.subscriptionKey, + logVerbosity: clientWithRequest.logVerbosity, + request, + }); }; // endregion // -------------------------------------------------------- @@ -307,8 +454,9 @@ * @param getClients - Request completion PubNub client observers getter. * @param success - Request success completion handler. * @param failure - Request failure handler. + * @param responsePreProcess - Raw response pre-processing function which is used before calling handling callbacks. */ - const sendRequest = (request, getClients, success, failure) => { + const sendRequest = (request, getClients, success, failure, responsePreProcess) => { (() => __awaiter(void 0, void 0, void 0, function* () { var _a; // Request progress support. @@ -321,6 +469,7 @@ requestTimeoutTimer(request.identifier, request.timeout), ]) .then((response) => response.arrayBuffer().then((buffer) => [response, buffer])) + .then((response) => (responsePreProcess ? responsePreProcess(response) : response)) .then((response) => { const responseBody = response[1].byteLength > 0 ? response[1] : undefined; const clients = getClients(); @@ -337,6 +486,22 @@ }); }))(); }; + /** + * Cancel (abort) service request by ID. + * + * @param requestId - Unique identifier of request which should be cancelled. + */ + const cancelRequest = (requestId) => { + if (clientsForRequest(requestId).length === 0) { + const controller = abortControllers.get(requestId); + abortControllers.delete(requestId); + // Clean up scheduled requests. + delete serviceRequests[requestId]; + // Abort request if possible. + if (controller) + controller.abort(); + } + }; /** * Create request timeout timer. * @@ -418,18 +583,26 @@ * channels and groups. */ const subscribeTransportRequestFromEvent = (event) => { - var _a, _b, _c, _d; + var _a, _b, _c, _d, _e; const client = pubNubClients[event.clientIdentifier]; const subscription = client.subscription; - const clients = clientsForSendSubscribeRequestEvent(subscription.previousTimetoken, event); + const clients = clientsForSendSubscribeRequestEvent(subscription.timetoken, event); const serviceRequestId = uuidGenerator.createUUID(); const request = Object.assign({}, event.request); + let previousSubscribeTimetoken; + let previousSubscribeRegion; if (clients.length > 1) { const activeRequestId = activeSubscriptionForEvent(clients, event); // Return identifier of the ongoing request. - if (activeRequestId) - return activeRequestId; - const state = ((_a = presenceState[client.subscriptionKey]) !== null && _a !== void 0 ? _a : {})[client.userId]; + if (activeRequestId) { + const scheduledRequest = serviceRequests[activeRequestId]; + const { channels, channelGroups } = (_a = client.subscription) !== null && _a !== void 0 ? _a : { channels: [], channelGroups: [] }; + if ((channels.length > 0 ? includesStrings(scheduledRequest.channels, channels) : true) && + (channelGroups.length > 0 ? includesStrings(scheduledRequest.channelGroups, channelGroups) : true)) { + return activeRequestId; + } + } + const state = ((_b = presenceState[client.subscriptionKey]) !== null && _b !== void 0 ? _b : {})[client.userId]; const aggregatedState = {}; const channelGroups = new Set(subscription.channelGroups); const channels = new Set(subscription.channels); @@ -440,26 +613,35 @@ aggregatedState[name] = objectState; }); } - for (const client of clients) { - const { subscription } = client; - // Skip clients which already have active subscription request. - if (!subscription || !subscription.serviceRequestId) + for (const _client of clients) { + const { subscription: _subscription } = _client; + // Skip clients which doesn't have active subscription request. + if (!_subscription) continue; - subscription.channelGroups.forEach(channelGroups.add, channelGroups); - subscription.channels.forEach(channels.add, channels); + // Keep track of timetoken from previous call to use it for catchup after initial subscribe. + if ((clients.length === 1 || _client.clientIdentifier !== client.clientIdentifier) && _subscription.timetoken) { + previousSubscribeTimetoken = _subscription.timetoken; + previousSubscribeRegion = _subscription.region; + } + _subscription.channelGroups.forEach(channelGroups.add, channelGroups); + _subscription.channels.forEach(channels.add, channels); + const activeServiceRequestId = _subscription.serviceRequestId; + _subscription.serviceRequestId = serviceRequestId; // Set awaited service worker request identifier. - subscription.serviceRequestId = serviceRequestId; + if (activeServiceRequestId && serviceRequests[activeServiceRequestId]) { + cancelRequest(activeServiceRequestId); + } if (!state) continue; - subscription.objectsWithState.forEach((name) => { + _subscription.objectsWithState.forEach((name) => { const objectState = state[name]; if (objectState && !aggregatedState[name]) aggregatedState[name] = objectState; }); } - const serviceRequest = ((_b = serviceRequests[serviceRequestId]) !== null && _b !== void 0 ? _b : (serviceRequests[serviceRequestId] = { + const serviceRequest = ((_c = serviceRequests[serviceRequestId]) !== null && _c !== void 0 ? _c : (serviceRequests[serviceRequestId] = { requestId: serviceRequestId, - timetoken: (_c = request.queryParameters.tt) !== null && _c !== void 0 ? _c : '0', + timetoken: (_d = request.queryParameters.tt) !== null && _d !== void 0 ? _d : '0', channelGroups: [], channels: [], })); @@ -482,11 +664,20 @@ else { serviceRequests[serviceRequestId] = { requestId: serviceRequestId, - timetoken: (_d = request.queryParameters.tt) !== null && _d !== void 0 ? _d : '0', + timetoken: (_e = request.queryParameters.tt) !== null && _e !== void 0 ? _e : '0', channelGroups: subscription.channelGroups, channels: subscription.channels, }; } + if (serviceRequests[serviceRequestId]) { + if (request.queryParameters && + request.queryParameters.tt !== undefined && + request.queryParameters.tr !== undefined) { + serviceRequests[serviceRequestId].region = request.queryParameters.tr; + } + serviceRequests[serviceRequestId].timetokenOverride = previousSubscribeTimetoken; + serviceRequests[serviceRequestId].regionOverride = previousSubscribeRegion; + } subscription.serviceRequestId = serviceRequestId; request.identifier = serviceRequestId; if (logVerbosity) { @@ -551,7 +742,7 @@ // Update request channels list (if required). if (channels.length) { const pathComponents = request.path.split('/'); - pathComponents[4] = channels.join(','); + pathComponents[6] = channels.join(','); request.path = pathComponents.join('/'); } // Update request channel groups list (if required). @@ -815,7 +1006,6 @@ client.subscription = subscription; } else { - subscription.previousTimetoken = subscription.timetoken; if (state.length > 0) { const parsedState = JSON.parse(state); const userState = ((_f = (_r = ((_e = presenceState[_q = client.subscriptionKey]) !== null && _e !== void 0 ? _e : (presenceState[_q] = {})))[_s = client.userId]) !== null && _f !== void 0 ? _f : (_r[_s] = {})); @@ -845,6 +1035,8 @@ subscription.request = event.request; subscription.filterExpression = ((_j = query['filter-expr']) !== null && _j !== void 0 ? _j : ''); subscription.timetoken = ((_k = query.tt) !== null && _k !== void 0 ? _k : '0'); + if (query.tr !== undefined) + subscription.region = query.tr; client.authKey = ((_l = query.auth) !== null && _l !== void 0 ? _l : ''); client.userId = query.uuid; }; @@ -975,10 +1167,10 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' return ((_c = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _c !== void 0 ? _c : []).filter((client) => client.userId === userId && client.authKey === authKey && client.subscription && + // Only clients with active subscription can be used. + (client.subscription.channels.length !== 0 || client.subscription.channelGroups.length !== 0) && client.subscription.filterExpression === filterExpression && - (timetoken === '0' || - client.subscription.previousTimetoken === '0' || - client.subscription.previousTimetoken === timetoken)); + (timetoken === '0' || client.subscription.timetoken === '0' || client.subscription.timetoken === timetoken)); }; /** * Find PubNub client states with configuration compatible with the one in request. diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index 17cca5554..ebea52ae6 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{u(i.next(e))}catch(e){s(e)}}function c(e){try{u(i.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}u((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,i,r={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=r,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function i(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var i=n[t||"all"];return i&&i.test(e)||!1}i.isUUID=r,i.VERSION=t,e.uuid=i,e.isUUID=r}(i=r.exports),null!==n&&(n.exports=i.uuid);var s=t(r.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=5e3,u=new TextDecoder;let l,a=!1;const d=o.createUUID(),f=new Map,p={},h={},g={},b={},v={};self.onconnect=e=>{V("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!G(t))return;const n=t.data;"client-register"===n.type?(!a&&n.workerLogVerbosity&&(a=!0),n.port=e,x(n),V(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`)):"client-pong"===n.type?K(n):"send-request"===n.type?n.request.path.startsWith("/v2/subscribe")?(F(n),y(n)):q(n):"cancel-request"===n.type&&I(n)},e.postMessage({type:"shared-worker-connected"})}))};const y=e=>{const t=k(e),n=p[e.clientIdentifier];n&&E("start",[n],(new Date).toISOString()),"string"!=typeof t?(e.request.cancellable&&f.set(t.identifier,new AbortController),m(t,(()=>O(t.identifier)),((e,n)=>{P(e,n),w(e,t.identifier)}),((e,n)=>{P(e,null,t,T(n)),w(e,t.identifier)})),V(`'${Object.keys(v).length}' subscription request currently active.`)):n&&n.subscription&&(n.subscription.previousTimetoken=n.subscription.timetoken,n.subscription.timetoken=v[t].timetoken,n.subscription.serviceRequestId=t)},q=e=>{const t=S(e),n=p[e.clientIdentifier];if(n){if(!t){const t=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),i=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":"74"}),r=new Response(t,{status:200,headers:i}),s=R([r,t]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(n,s)}m(t,(()=>[n]),((t,n)=>{P(t,n,e.request)}),((t,n)=>{P(t,null,e.request,T(n))})),V("Started leave request.",n)}},I=e=>{const t=p[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;if(t&&n&&(delete t.subscription.serviceRequestId,delete t.subscription.request,0===O(n).length)){const e=f.get(n);f.delete(n),delete v[n],e&&e.abort()}},m=(t,n,i,r)=>{e(void 0,void 0,void 0,(function*(){var e;const s=(new Date).getTime();Promise.race([fetch($(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),j(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const r=e[1].byteLength>0?e[1]:void 0,o=n();0!==o.length&&(E("end",o,(new Date).toISOString(),t,r,e[0].headers.get("Content-Type"),(new Date).getTime()-s),i(o,e))})).catch((e=>{const t=n();0!==t.length&&r(t,e)}))}))},j=(e,t)=>new Promise(((n,i)=>{const r=setTimeout((()=>{f.delete(e),clearTimeout(r),i(new Error("Request timeout"))}),1e3*t)})),O=e=>Object.values(p).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),w=(e,t)=>{delete v[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},$=e=>{let t;const n=e.queryParameters;let i=e.path;if(e.headers){t={};for(const[n,i]of Object.entries(e.headers))t[n]=i}return n&&0!==Object.keys(n).length&&(i=`${i}?${Q(n)}`),new Request(`${e.origin}${i}`,{method:e.method,headers:t,redirect:"follow"})},k=e=>{var t,n,i,r;const s=p[e.clientIdentifier],c=s.subscription,u=W(c.previousTimetoken,e),l=o.createUUID(),d=Object.assign({},e.request);if(u.length>1){const r=U(u,e);if(r)return r;const o=(null!==(t=g[s.subscriptionKey])&&void 0!==t?t:{})[s.userId],a={},f=new Set(c.channelGroups),p=new Set(c.channels);o&&c.objectsWithState.length&&c.objectsWithState.forEach((e=>{const t=o[e];t&&(a[e]=t)}));for(const e of u){const{subscription:t}=e;t&&t.serviceRequestId&&(t.channelGroups.forEach(f.add,f),t.channels.forEach(p.add,p),t.serviceRequestId=l,o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!a[e]&&(a[e]=t)})))}const h=null!==(n=v[l])&&void 0!==n?n:v[l]={requestId:l,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(p.size){h.channels=Array.from(p).sort();const e=d.path.split("/");e[4]=h.channels.join(","),d.path=e.join("/")}f.size&&(h.channelGroups=Array.from(f).sort(),d.queryParameters["channel-group"]=h.channelGroups.join(",")),Object.keys(a).length&&(d.queryParameters.state=JSON.stringify(a))}else v[l]={requestId:l,timetoken:null!==(r=d.queryParameters.tt)&&void 0!==r?r:"0",channelGroups:c.channelGroups,channels:c.channels};if(c.serviceRequestId=l,d.identifier=l,a){const e=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");B(v[l],`Started aggregated request for clients: ${e}`)}return d},S=e=>{const t=p[e.clientIdentifier],n=C(e);let i=N(e.request),r=D(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;r.length&&(e.channels=e.channels.filter((e=>!r.includes(e)))),i.length&&(e.channelGroups=e.channelGroups.filter((e=>!i.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(r.length&&(r=r.filter((e=>!n.channels.includes(e)))),i.length&&(i=i.filter((e=>!n.channelGroups.includes(e))))))}if(0!==r.length||0!==i.length){if(r.length){const e=s.path.split("/");e[4]=r.join(","),s.path=e.join("/")}return i.length&&(s.queryParameters["channel-group"]=i.join(",")),s}if(a&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");V(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const i=(null!==(n=b[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!i)return!1;try{return i.postMessage(t),!0}catch(e){}return!1},E=(e,t,n,i,r,s,o)=>{var c;if(0===t.length)return;const l=null!==(c=b[t[0].subscriptionKey])&&void 0!==c?c:{};let a;if("start"===e)a={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;r&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(r)),a={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(void 0===e.subscription)continue;const t=l[e.clientIdentifier],{request:n}=e.subscription,r=null!=n?n:i;if(e.logVerbosity&&t&&r){const t=Object.assign(Object.assign({},a),{clientIdentifier:e.clientIdentifier,url:`${r.origin}${r.path}`,query:r.queryParameters});A(e,t)}}},P=(e,t,n,i)=>{var r;if(0===e.length)return;if(!i&&!t)return;const s=null!==(r=b[e[0].subscriptionKey])&&void 0!==r?r:{};!i&&t&&(i=t[0].status>=400?T(void 0,t):R(t));for(const t of e){if(void 0===t.subscription)continue;const e=s[t.clientIdentifier],{request:r}=t.subscription,o=null!=r?r:n;if(e&&o){const e=Object.assign(Object.assign({},i),{clientIdentifier:t.clientIdentifier,identifier:o.identifier,url:`${o.origin}${o.path}`});A(t,e)}}},R=e=>{var t;const[n,i]=e,r=i.byteLength>0?i:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:r}}},T=(e,t)=>{if(t)return Object.assign(Object.assign({},R(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",i="Unknown error",r="Error";return e&&e instanceof Error&&(i=e.message,r=e.name),"AbortError"===r?(i="Request aborted",n="ABORTED"):"Request timeout"===i&&(n="TIMEOUT"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:r,type:n,message:i}}},x=e=>{var t,n,i,r;const{clientIdentifier:s}=e;if(p[s])return;const o=p[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,logVerbosity:e.logVerbosity},u=null!==(t=h[i=e.subscriptionKey])&&void 0!==t?t:h[i]=[];u.every((e=>e.clientIdentifier!==s))&&u.push(o),(null!==(n=b[r=e.subscriptionKey])&&void 0!==n?n:b[r]={})[s]=e.port,V(`Registered PubNub client with '${s}' identifier. '${Object.keys(p).length}' clients currently active.`),!l&&Object.keys(p).length>0&&(V("Setup PubNub client ping event 5 seconds"),l=setInterval((()=>M()),c))},F=e=>{var t,n,i,r,s,o,c,u,l,a,d,f,h,b,v,y,q,I,m,j;const O=e.request.queryParameters,{clientIdentifier:w}=e,$=p[w];if(!$)return;const k=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let A=$.subscription;if(A){if(A.previousTimetoken=A.timetoken,S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=g[v=$.subscriptionKey])&&void 0!==s?s:g[v]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of A.objectsWithState)e[n]||delete t[n];A.objectsWithState=Object.keys(e)}else if(A.objectsWithState.length){const e=null!==(u=(m=null!==(c=g[I=$.subscriptionKey])&&void 0!==c?c:g[I]={})[j=$.userId])&&void 0!==u?u:m[j]={};for(const t of A.objectsWithState)delete e[t];A.objectsWithState=[]}}else{if(A={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(r=(h=null!==(i=g[f=$.subscriptionKey])&&void 0!==i?i:g[f]={})[b=$.userId])&&void 0!==r?r:h[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),A.objectsWithState=Object.keys(e)}$.subscription=A}A.path!==e.request.path&&(A.path=e.request.path,A.channels=D(e.request)),A.channelGroupQuery!==k&&(A.channelGroupQuery=k,A.channelGroups=N(e.request)),A.request=e.request,A.filterExpression=null!==(l=O["filter-expr"])&&void 0!==l?l:"",A.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",$.authKey=null!==(d=O.auth)&&void 0!==d?d:"",$.userId=O.uuid},K=e=>{const t=p[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},G=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:i}=e.data;return void 0!==i&&"boolean"==typeof i&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},U=(e,t)=>{var n;const i=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",r=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=p[t.clientIdentifier],u=e.serviceRequestId;if(e.path===r&&e.channelGroupQuery===i)return V(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${u}' request completion.`,c),e.serviceRequestId;{const i=v[e.serviceRequestId];if(s||(s=N(t.request)),o||(o=D(t.request)),o.length&&!L(i.channels,o))continue;if(s.length&&!L(i.channelGroups,s))continue;return B(i,`'${t.request.identifier}' request channels and groups are subset of ongoing '${u}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${u}' request completion.`,c),e.serviceRequestId}}},W=(e,t)=>{var n,i,r;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(i=s.auth)&&void 0!==i?i:"",u=s.uuid;return(null!==(r=h[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===u&&t.authKey===c&&t.subscription&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.previousTimetoken||t.subscription.previousTimetoken===e)))},C=e=>{var t,n;const i=e.request.queryParameters,r=null!==(t=i.auth)&&void 0!==t?t:"",s=i.uuid;return(null!==(n=h[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===r))},D=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},N=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},L=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},M=()=>{V("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(p).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(V(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>2.5)&&(n=!0,V(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete p[t];let n=h[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?h[e]=n:delete h[e],0===n.length&&delete g[e],n.length>0){const n=b[e];n&&(delete n[t],0===Object.keys(n).length&&delete b[e])}else delete b[e];V(`Invalidate '${t}' client. '${Object.keys(p).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(V(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,A(t,e))})),0===Object.keys(p).length&&l&&clearInterval(l)},V=(e,t)=>{if(!a)return;const n=t?[t]:Object.values(p),i={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,i)}))},B=(e,t,n)=>{if(!a)return;const i=n?[n]:Object.values(p),r={type:"shared-worker-console-dir",message:t,data:e};i.forEach((e=>{e&&A(e,r)}))},Q=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${J(e)}`)).join("&"):`${t}=${J(n)}`})).join("&"),J=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=r,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function i(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var i=n[t||"all"];return i&&i.test(e)||!1}i.isUUID=r,i.VERSION=t,e.uuid=i,e.isUUID=r}(i=r.exports),null!==n&&(n.exports=i.uuid);var s=t(r.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=1e4,u=new Map,l=new TextDecoder;let a,d=!1;const f=o.createUUID(),p=new Map,h={},g={},b={},v={},y={};self.onconnect=e=>{z("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!D(t))return;const n=t.data;if("client-register"===n.type)!d&&n.workerLogVerbosity&&(d=!0),n.port=e,C(n),z(`Client '${n.clientIdentifier}' registered with '${f}' shared worker`);else if("client-pong"===n.type)W(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){U(n);const e=h[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!u.has(t)){const e=setTimeout((()=>{q(n),u.delete(t)}),50);u.set(t,e)}}}else m(n);else"cancel-request"===n.type&&j(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=e=>{var t;const n=R(e),i=h[e.clientIdentifier];let r=!1;if(i&&(i.subscription&&(r="0"===i.subscription.timetoken),x("start",[i],(new Date).toISOString())),"string"==typeof n){const s=y[n];if(i){if(i.subscription&&(i.subscription.timetoken=s.timetoken,i.subscription.region=s.region,i.subscription.serviceRequestId=n),!r)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),u=new Response(o,{status:200,headers:c}),l=G([u,o]);l.url=`${e.request.origin}${e.request.path}`,l.clientIdentifier=e.clientIdentifier,l.identifier=e.request.identifier,x("end",[i],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),T(i,l)}return}e.request.cancellable&&p.set(n.identifier,new AbortController);const s=y[n.identifier],{timetokenOverride:o,regionOverride:c}=s;O(n,(()=>S(n.identifier)),((e,t)=>{F(e,t),E(e,n.identifier)}),((e,t)=>{F(e,null,n,K(t)),E(e,n.identifier)}),(e=>{let t=e;return r&&o&&"0"!==o&&(y[n.identifier],t=I(t,o,c)),t})),z(`'${Object.keys(y).length}' subscription request currently active.`)},I=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let i;const r=e[0];let s=r,o=e[1];try{i=JSON.parse((new TextDecoder).decode(o))}catch(t){return z(`Subscribe response parse error: ${t}`),e}i.t.t=t,n&&(i.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(i)).buffer,o.byteLength){const e=new Headers(r.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:r.status,statusText:r.statusText,headers:e})}}catch(t){return z(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},m=e=>{const t=h[e.clientIdentifier],n=A(e);if(!t)return;const{subscription:i}=t,r=null==i?void 0:i.serviceRequestId;if(i&&0===i.channels.length&&0===i.channelGroups.length&&(i.channelGroupQuery="",i.path="",i.previousTimetoken="0",i.timetoken="0",delete i.region,delete i.serviceRequestId,delete i.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),i=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),r=new Response(n,{status:200,headers:i}),s=G([r,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void T(t,s)}if(O(n,(()=>[t]),((t,n)=>{F(t,n,e.request)}),((t,n)=>{F(t,null,e.request,K(n))})),z("Started leave request.",t),void 0===r)return;const s=S(r);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),$(r),w(s)},j=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,$(n))},w=e=>{let t,n;for(const i of e)if(i.subscription&&i.subscription.request){n=i.subscription.request,t=i;break}n&&t&&q({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},O=(t,n,i,r,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(P(t),{signal:null===(e=p.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),k(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const r=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,r,e[0].headers.get("Content-Type"),(new Date).getTime()-o),i(s,e))})).catch((e=>{const t=n();0!==t.length&&r(t,e)}))}))},$=e=>{if(0===S(e).length){const t=p.get(e);p.delete(e),delete y[e],t&&t.abort()}},k=(e,t)=>new Promise(((n,i)=>{const r=setTimeout((()=>{p.delete(e),clearTimeout(r),i(new Error("Request timeout"))}),1e3*t)})),S=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete y[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},P=e=>{let t;const n=e.queryParameters;let i=e.path;if(e.headers){t={};for(const[n,i]of Object.entries(e.headers))t[n]=i}return n&&0!==Object.keys(n).length&&(i=`${i}?${_(n)}`),new Request(`${e.origin}${i}`,{method:e.method,headers:t,redirect:"follow"})},R=e=>{var t,n,i,r,s;const c=h[e.clientIdentifier],u=c.subscription,l=N(u.timetoken,e),a=o.createUUID(),f=Object.assign({},e.request);let p,g;if(l.length>1){const s=L(l,e);if(s){const e=y[s],{channels:n,channelGroups:i}=null!==(t=c.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Q(e.channels,n))&&(!(i.length>0)||Q(e.channelGroups,i)))return s}const o=(null!==(n=b[c.subscriptionKey])&&void 0!==n?n:{})[c.userId],d={},h=new Set(u.channelGroups),v=new Set(u.channels);o&&u.objectsWithState.length&&u.objectsWithState.forEach((e=>{const t=o[e];t&&(d[e]=t)}));for(const e of l){const{subscription:t}=e;if(!t)continue;1!==l.length&&e.clientIdentifier===c.clientIdentifier||!t.timetoken||(p=t.timetoken,g=t.region),t.channelGroups.forEach(h.add,h),t.channels.forEach(v.add,v);const n=t.serviceRequestId;t.serviceRequestId=a,n&&y[n]&&$(n),o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!d[e]&&(d[e]=t)}))}const q=null!==(i=y[a])&&void 0!==i?i:y[a]={requestId:a,timetoken:null!==(r=f.queryParameters.tt)&&void 0!==r?r:"0",channelGroups:[],channels:[]};if(v.size){q.channels=Array.from(v).sort();const e=f.path.split("/");e[4]=q.channels.join(","),f.path=e.join("/")}h.size&&(q.channelGroups=Array.from(h).sort(),f.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(d).length&&(f.queryParameters.state=JSON.stringify(d))}else y[a]={requestId:a,timetoken:null!==(s=f.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:u.channelGroups,channels:u.channels};if(y[a]&&(f.queryParameters&&void 0!==f.queryParameters.tt&&void 0!==f.queryParameters.tr&&(y[a].region=f.queryParameters.tr),y[a].timetokenOverride=p,y[a].regionOverride=g),u.serviceRequestId=a,f.identifier=a,d){const e=l.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");H(y[a],`Started aggregated request for clients: ${e}`)}return f},A=e=>{const t=h[e.clientIdentifier],n=M(e);let i=J(e.request),r=V(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;r.length&&(e.channels=e.channels.filter((e=>!r.includes(e)))),i.length&&(e.channelGroups=e.channelGroups.filter((e=>!i.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(r.length&&(r=r.filter((e=>!n.channels.includes(e)))),i.length&&(i=i.filter((e=>!n.channelGroups.includes(e))))))}if(0!==r.length||0!==i.length){if(r.length){const e=s.path.split("/");e[6]=r.join(","),s.path=e.join("/")}return i.length&&(s.queryParameters["channel-group"]=i.join(",")),s}if(d&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");z(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},T=(e,t)=>{var n;const i=(null!==(n=v[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!i)return!1;try{return i.postMessage(t),!0}catch(e){}return!1},x=(e,t,n,i,r,s,o)=>{var c;if(0===t.length)return;const u=null!==(c=v[t[0].subscriptionKey])&&void 0!==c?c:{};let a;if("start"===e)a={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;r&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=l.decode(r)),a={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(void 0===e.subscription)continue;const t=u[e.clientIdentifier],{request:n}=e.subscription,r=null!=n?n:i;if(e.logVerbosity&&t&&r){const t=Object.assign(Object.assign({},a),{clientIdentifier:e.clientIdentifier,url:`${r.origin}${r.path}`,query:r.queryParameters});T(e,t)}}},F=(e,t,n,i)=>{var r;if(0===e.length)return;if(!i&&!t)return;const s=null!==(r=v[e[0].subscriptionKey])&&void 0!==r?r:{};!i&&t&&(i=t[0].status>=400?K(void 0,t):G(t));for(const t of e){if(void 0===t.subscription)continue;const e=s[t.clientIdentifier],{request:r}=t.subscription,o=null!=r?r:n;if(e&&o){const e=Object.assign(Object.assign({},i),{clientIdentifier:t.clientIdentifier,identifier:o.identifier,url:`${o.origin}${o.path}`});T(t,e)}}},G=e=>{var t;const[n,i]=e,r=i.byteLength>0?i:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:r}}},K=(e,t)=>{if(t)return Object.assign(Object.assign({},G(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",i="Unknown error",r="Error";return e&&e instanceof Error&&(i=e.message,r=e.name),"AbortError"===r?(i="Request aborted",n="ABORTED"):"Request timeout"===i&&(n="TIMEOUT"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:r,type:n,message:i}}},C=e=>{var t,n,i,r;const{clientIdentifier:s}=e;if(h[s])return;const o=h[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,logVerbosity:e.logVerbosity},u=null!==(t=g[i=e.subscriptionKey])&&void 0!==t?t:g[i]=[];u.every((e=>e.clientIdentifier!==s))&&u.push(o),(null!==(n=v[r=e.subscriptionKey])&&void 0!==n?n:v[r]={})[s]=e.port,z(`Registered PubNub client with '${s}' identifier. '${Object.keys(h).length}' clients currently active.`),!a&&Object.keys(h).length>0&&(z("Setup PubNub client ping event 10 seconds"),a=setInterval((()=>B()),c))},U=e=>{var t,n,i,r,s,o,c,u,l,a,d,f,p,g,v,y,q,I,m,j;const w=e.request.queryParameters,{clientIdentifier:O}=e,$=h[O];if(!$)return;const k=null!==(t=w["channel-group"])&&void 0!==t?t:"",S=null!==(n=w.state)&&void 0!==n?n:"";let E=$.subscription;if(E){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=b[v=$.subscriptionKey])&&void 0!==s?s:b[v]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of E.objectsWithState)e[n]||delete t[n];E.objectsWithState=Object.keys(e)}else if(E.objectsWithState.length){const e=null!==(u=(m=null!==(c=b[I=$.subscriptionKey])&&void 0!==c?c:b[I]={})[j=$.userId])&&void 0!==u?u:m[j]={};for(const t of E.objectsWithState)delete e[t];E.objectsWithState=[]}}else{if(E={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(r=(p=null!==(i=b[f=$.subscriptionKey])&&void 0!==i?i:b[f]={})[g=$.userId])&&void 0!==r?r:p[g]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),E.objectsWithState=Object.keys(e)}$.subscription=E}E.path!==e.request.path&&(E.path=e.request.path,E.channels=V(e.request)),E.channelGroupQuery!==k&&(E.channelGroupQuery=k,E.channelGroups=J(e.request)),E.request=e.request,E.filterExpression=null!==(l=w["filter-expr"])&&void 0!==l?l:"",E.timetoken=null!==(a=w.tt)&&void 0!==a?a:"0",void 0!==w.tr&&(E.region=w.tr),$.authKey=null!==(d=w.auth)&&void 0!==d?d:"",$.userId=w.uuid},W=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},D=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:i}=e.data;return void 0!==i&&"boolean"==typeof i&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},L=(e,t)=>{var n;const i=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",r=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],u=e.serviceRequestId;if(e.path===r&&e.channelGroupQuery===i)return z(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${u}' request completion.`,c),e.serviceRequestId;{const i=y[e.serviceRequestId];if(s||(s=J(t.request)),o||(o=V(t.request)),o.length&&!Q(i.channels,o))continue;if(s.length&&!Q(i.channelGroups,s))continue;return H(i,`'${t.request.identifier}' request channels and groups are subset of ongoing '${u}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${u}' request completion.`,c),e.serviceRequestId}}},N=(e,t)=>{var n,i,r;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(i=s.auth)&&void 0!==i?i:"",u=s.uuid;return(null!==(r=g[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===u&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},M=e=>{var t,n;const i=e.request.queryParameters,r=null!==(t=i.auth)&&void 0!==t?t:"",s=i.uuid;return(null!==(n=g[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===r))},V=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},J=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Q=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},B=()=>{z("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(h).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(z(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>5)&&(n=!0,z(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete h[t];let n=g[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?g[e]=n:delete g[e],0===n.length&&delete b[e],n.length>0){const n=v[e];n&&(delete n[t],0===Object.keys(n).length&&delete v[e])}else delete v[e];z(`Invalidate '${t}' client. '${Object.keys(h).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(z(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,T(t,e))})),0===Object.keys(h).length&&a&&clearInterval(a)},z=(e,t)=>{if(!d)return;const n=t?[t]:Object.values(h),i={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&T(e,i)}))},H=(e,t,n)=>{if(!d)return;const i=n?[n]:Object.values(h),r={type:"shared-worker-console-dir",message:t,data:e};i.forEach((e=>{e&&T(e,r)}))},_=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${X(e)}`)).join("&"):`${t}=${X(n)}`})).join("&"),X=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index d0979de6d..bcb2b2652 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.7'; + return '8.2.8'; }, getVersion() { return this.version; diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index 7021e6ae4..1563ff9a8 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -112,7 +112,13 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { if (!serviceResponse) { throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); } - const events = serviceResponse.m.map((envelope) => { + const events = serviceResponse.m + .filter((envelope) => { + const subscribable = envelope.b === undefined ? envelope.c : envelope.b; + return ((this.parameters.channels && this.parameters.channels.includes(subscribable)) || + (this.parameters.channelGroups && this.parameters.channelGroups.includes(subscribable))); + }) + .map((envelope) => { let { e: eventType } = envelope; // Resolve missing event type. eventType !== null && eventType !== void 0 ? eventType : (eventType = envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message); diff --git a/package-lock.json b/package-lock.json index e3f4878d0..e04f847d0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5650,6 +5650,22 @@ "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true }, + "node_modules/body-parser/node_modules/qs": { + "version": "6.11.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", + "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", @@ -7731,9 +7747,9 @@ "dev": true }, "node_modules/fast-xml-parser": { - "version": "4.3.6", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.3.6.tgz", - "integrity": "sha512-M2SovcRxD4+vC493Uc2GZVcZaj66CCJhWurC4viynVSTvrpErCShNcDz1lAho6n9REQKvL/ll4A4/fw6Y9z8nw==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.4.1.tgz", + "integrity": "sha512-xkjOecfnKGkSsOwtZ5Pz7Us/T6mrbPQrq0nh+aCO5V9nk5NLWmasAHumTKjiPJPWANe+kAZ84Jc8ooJkzZ88Sw==", "funding": [ { "type": "github", @@ -11447,21 +11463,6 @@ "node": ">=0.9" } }, - "node_modules/qs": { - "version": "6.13.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", - "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", - "dev": true, - "dependencies": { - "side-channel": "^1.0.6" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/queue": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/queue/-/queue-6.0.2.tgz", diff --git a/package.json b/package.json index 15c83ea45..eb281e717 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.7", + "version": "8.2.8", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { @@ -32,6 +32,7 @@ "contract:test-access-beta": "cucumber-js --require dist/cucumber dist/contract/contract/features --tags '@featureSet=access and not @na=js and @beta'" }, "main": "./lib/node/index.js", + "types": "./lib/types/node/index.d.ts", "react-native": "./lib/react_native/index.js", "metro": "./lib/react_native/index.js", "nativescript": "./lib/nativescript/index.js", @@ -40,7 +41,6 @@ "type": "git", "url": "git://github.com/pubnub/javascript.git" }, - "keywords": [ "cloud", "publish", diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 2f3d24fd7..adde504ab 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.7'; + return '8.2.8'; }, getVersion(): string { return this.version; diff --git a/src/core/endpoints/subscribe.ts b/src/core/endpoints/subscribe.ts index 043e93a7e..964657f7a 100644 --- a/src/core/endpoints/subscribe.ts +++ b/src/core/endpoints/subscribe.ts @@ -629,57 +629,65 @@ export class BaseSubscribeRequest extends AbstractRequest { - let { e: eventType } = envelope; + const events: Subscription.SubscriptionResponse['messages'] = serviceResponse.m + .filter((envelope) => { + const subscribable = envelope.b === undefined ? envelope.c : envelope.b; + return ( + (this.parameters.channels && this.parameters.channels.includes(subscribable)) || + (this.parameters.channelGroups && this.parameters.channelGroups.includes(subscribable)) + ); + }) + .map((envelope) => { + let { e: eventType } = envelope; + + // Resolve missing event type. + eventType ??= envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message; + + // Check whether payload is string (potentially encrypted data). + if (eventType != PubNubEventType.Signal && typeof envelope.d === 'string') { + if (eventType == PubNubEventType.Message) { + return { + type: PubNubEventType.Message, + data: this.messageFromEnvelope(envelope), + }; + } - // Resolve missing event type. - eventType ??= envelope.c.endsWith('-pnpres') ? PubNubEventType.Presence : PubNubEventType.Message; - - // Check whether payload is string (potentially encrypted data). - if (eventType != PubNubEventType.Signal && typeof envelope.d === 'string') { - if (eventType == PubNubEventType.Message) { + return { + type: PubNubEventType.Files, + data: this.fileFromEnvelope(envelope), + }; + } else if (eventType == PubNubEventType.Message) { return { type: PubNubEventType.Message, data: this.messageFromEnvelope(envelope), }; + } else if (eventType === PubNubEventType.Presence) { + return { + type: PubNubEventType.Presence, + data: this.presenceEventFromEnvelope(envelope), + }; + } else if (eventType == PubNubEventType.Signal) { + return { + type: PubNubEventType.Signal, + data: this.signalFromEnvelope(envelope), + }; + } else if (eventType === PubNubEventType.AppContext) { + return { + type: PubNubEventType.AppContext, + data: this.appContextFromEnvelope(envelope), + }; + } else if (eventType === PubNubEventType.MessageAction) { + return { + type: PubNubEventType.MessageAction, + data: this.messageActionFromEnvelope(envelope), + }; } return { type: PubNubEventType.Files, data: this.fileFromEnvelope(envelope), }; - } else if (eventType == PubNubEventType.Message) { - return { - type: PubNubEventType.Message, - data: this.messageFromEnvelope(envelope), - }; - } else if (eventType === PubNubEventType.Presence) { - return { - type: PubNubEventType.Presence, - data: this.presenceEventFromEnvelope(envelope), - }; - } else if (eventType == PubNubEventType.Signal) { - return { - type: PubNubEventType.Signal, - data: this.signalFromEnvelope(envelope), - }; - } else if (eventType === PubNubEventType.AppContext) { - return { - type: PubNubEventType.AppContext, - data: this.appContextFromEnvelope(envelope), - }; - } else if (eventType === PubNubEventType.MessageAction) { - return { - type: PubNubEventType.MessageAction, - data: this.messageActionFromEnvelope(envelope), - }; - } - - return { - type: PubNubEventType.Files, - data: this.fileFromEnvelope(envelope), - }; - }); + }); return { cursor: { timetoken: serviceResponse.t.t, region: serviceResponse.t.r }, diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index 84fb67c60..d520e1770 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -420,6 +420,11 @@ type PubNubClientState = { */ timetoken: string; + /** + * Timetoken region which used in current subscription session loop. + */ + region?: string; + /** * List of channel and / or channel group names for which state has been assigned. * @@ -461,7 +466,20 @@ declare const self: SharedWorkerGlobalScope; /** * How often PING request should be sent to the PubNub clients. */ -const clientPingRequestInterval = 5000; +const clientPingRequestInterval = 10000; + +/** + * Aggregation timer timeout. + * + * Timeout used by the timer to postpone `handleSendSubscribeRequestEvent` function call and let other clients for + * same subscribe key send next subscribe loop request (to make aggregation more efficient). + */ +const subscribeAggregationTimeout = 50; + +/** + * Map of PubNub client subscription keys to the started aggregation timeout timers. + */ +const aggregationTimers: Map = new Map(); // region State /** @@ -484,6 +502,11 @@ let pingInterval: number | undefined; */ const sharedWorkerIdentifier = uuidGenerator.createUUID(); +/** + * FIFO list of events which should be processed by + */ +const eventsQueue: MessageEvent[] = []; + /** * Map of identifiers, scheduled by the Service Worker, to their abort controllers. * @@ -540,6 +563,21 @@ const serviceRequests: { */ timetoken: string; + /** + * Timetoken region which is used for subscription loop. + */ + region?: string; + + /** + * Timetoken override which is used after initial subscription to catch up on previous messages. + */ + timetokenOverride?: string; + + /** + * Timetoken region override which is used after initial subscription to catch up on previous messages. + */ + regionOverride?: string; + /** * List of channels used in current subscription session. */ @@ -589,7 +627,21 @@ self.onconnect = (event) => { else if (data.type === 'send-request') { if (data.request.path.startsWith('/v2/subscribe')) { updateClientStateIfRequired(data); - handleSendSubscribeRequestEvent(data); + + const client = pubNubClients[data.clientIdentifier]; + if (client) { + const timerIdentifier = `${client.userId}-${client.subscriptionKey}`; + + // Check whether we need to start new aggregation timer or not. + if (!aggregationTimers.has(timerIdentifier)) { + const aggregationTimer = setTimeout(() => { + handleSendSubscribeRequestEvent(data); + aggregationTimers.delete(timerIdentifier); + }, subscribeAggregationTimeout); + + aggregationTimers.set(timerIdentifier, aggregationTimer); + } + } } else handleSendLeaveRequestEvent(data); } else if (data.type === 'cancel-request') handleCancelRequestEvent(data); }; @@ -606,20 +658,57 @@ self.onconnect = (event) => { const handleSendSubscribeRequestEvent = (event: SendRequestEvent) => { const requestOrId = subscribeTransportRequestFromEvent(event); const client = pubNubClients[event.clientIdentifier]; + let isInitialSubscribe = false; - if (client) notifyRequestProcessing('start', [client], new Date().toISOString()); + if (client) { + if (client.subscription) isInitialSubscribe = client.subscription.timetoken === '0'; + notifyRequestProcessing('start', [client], new Date().toISOString()); + } if (typeof requestOrId === 'string') { - if (client && client.subscription) { - // Updating client timetoken information. - client.subscription.previousTimetoken = client.subscription.timetoken; - client.subscription.timetoken = serviceRequests[requestOrId].timetoken; - client.subscription.serviceRequestId = requestOrId; + const scheduledRequest = serviceRequests[requestOrId]; + + if (client) { + if (client.subscription) { + // Updating client timetoken information. + client.subscription.timetoken = scheduledRequest.timetoken; + client.subscription.region = scheduledRequest.region; + client.subscription.serviceRequestId = requestOrId; + } + + if (!isInitialSubscribe) return; + + const body = new TextEncoder().encode( + `{"t":{"t":"${scheduledRequest.timetoken}","r":${scheduledRequest.region ?? '0'}},"m":[]}`, + ); + const headers = new Headers({ + 'Content-Type': 'text/javascript; charset="UTF-8"', + 'Content-Length': `${body.length}`, + }); + const response = new Response(body, { status: 200, headers }); + const result = requestProcessingSuccess([response, body]); + result.url = `${event.request.origin}${event.request.path}`; + result.clientIdentifier = event.clientIdentifier; + result.identifier = event.request.identifier; + + notifyRequestProcessing( + 'end', + [client], + new Date().toISOString(), + event.request, + body, + headers.get('Content-Type'), + 0, + ); + + publishClientEvent(client, result); } return; } if (event.request.cancellable) abortControllers.set(requestOrId.identifier, new AbortController()); + const scheduledRequest = serviceRequests[requestOrId.identifier]; + const { timetokenOverride, regionOverride } = scheduledRequest; sendRequest( requestOrId, @@ -638,24 +727,97 @@ const handleSendSubscribeRequestEvent = (event: SendRequestEvent) => { // Clean up scheduled request and client references to it. markRequestCompleted(clients, requestOrId.identifier); }, + (response) => { + let serverResponse = response; + if (isInitialSubscribe && timetokenOverride && timetokenOverride !== '0') { + const scheduledRequest = serviceRequests[requestOrId.identifier]; + serverResponse = patchInitialSubscribeResponse(serverResponse, timetokenOverride, regionOverride); + } + + return serverResponse; + }, ); consoleLog(`'${Object.keys(serviceRequests).length}' subscription request currently active.`); }; +const patchInitialSubscribeResponse = ( + serverResponse: [Response, ArrayBuffer], + timetoken?: string, + region?: string, +): [Response, ArrayBuffer] => { + if (timetoken === undefined || timetoken === '0' || serverResponse[0].status >= 400) { + return serverResponse; + } + + let json: { t: { t: string; r: number }; m: Record[] }; + const response = serverResponse[0]; + let decidedResponse = response; + let body = serverResponse[1]; + + try { + json = JSON.parse(new TextDecoder().decode(body)); + } catch (error) { + consoleLog(`Subscribe response parse error: ${error}`); + return serverResponse; + } + + // Replace server-provided timetoken. + json.t.t = timetoken; + if (region) json.t.r = parseInt(region, 10); + + try { + body = new TextEncoder().encode(JSON.stringify(json)).buffer; + if (body.byteLength) { + const headers = new Headers(response.headers); + headers.set('Content-Length', `${body.byteLength}`); + + // Create a new response with the original response options and modified headers + decidedResponse = new Response(body, { + status: response.status, + statusText: response.statusText, + headers: headers, + }); + } + } catch (error) { + consoleLog(`Subscribe serialization error: ${error}`); + return serverResponse; + } + + return body.byteLength > 0 ? [decidedResponse, body] : serverResponse; +}; + /** * Handle client request to leave request. * * @param data - Leave event details. */ const handleSendLeaveRequestEvent = (data: SendRequestEvent) => { - const request = leaveTransportRequestFromEvent(data); const client = pubNubClients[data.clientIdentifier]; + const request = leaveTransportRequestFromEvent(data); if (!client) return; + // Clean up client subscription information if there is no more channels / groups to use. + const { subscription } = client; + const serviceRequestId = subscription?.serviceRequestId; + if (subscription) { + if (subscription.channels.length === 0 && subscription.channelGroups.length === 0) { + subscription.channelGroupQuery = ''; + subscription.path = ''; + subscription.previousTimetoken = '0'; + subscription.timetoken = '0'; + delete subscription.region; + delete subscription.serviceRequestId; + delete subscription.request; + } + } + if (!request) { const body = new TextEncoder().encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'); - const headers = new Headers({ 'Content-Type': 'text/javascript; charset="UTF-8"', 'Content-Length': '74' }); + const headers = new Headers({ + 'Content-Type': 'text/javascript; charset="UTF-8"', + 'Content-Length': `${body.length}`, + }); const response = new Response(body, { status: 200, headers }); const result = requestProcessingSuccess([response, body]); result.url = `${data.request.origin}${data.request.path}`; @@ -680,6 +842,17 @@ const handleSendLeaveRequestEvent = (data: SendRequestEvent) => { ); consoleLog(`Started leave request.`, client); + + // Check whether there were active subscription with channels from this client or not. + if (serviceRequestId === undefined) return; + + // Update ongoing clients + const clients = clientsForRequest(serviceRequestId); + clients.forEach((client) => { + if (client && client.subscription) delete client.subscription.serviceRequestId; + }); + cancelRequest(serviceRequestId); + restartSubscribeRequestForClients(clients); }; /** @@ -698,18 +871,48 @@ const handleCancelRequestEvent = (event: CancelRequestEvent) => { // Unset awaited requests. delete client.subscription.serviceRequestId; - delete client.subscription.request; + if (client.subscription.request && client.subscription.request.identifier === event.identifier) { + delete client.subscription.request; + } - if (clientsForRequest(serviceRequestId).length === 0) { - const controller = abortControllers.get(serviceRequestId); - abortControllers.delete(serviceRequestId); + cancelRequest(serviceRequestId); +}; +// endregion - // Clean up scheduled requests. - delete serviceRequests[serviceRequestId]; +// -------------------------------------------------------- +// --------------------- Subscription --------------------- +// -------------------------------------------------------- +// region Subscription - // Abort request if possible. - if (controller) controller.abort(); +/** + * Try restart subscribe request for the list of clients. + * + * Subscribe restart will use previous timetoken information to schedule new subscription loop. + * + * **Note:** This function mimics behaviour when SharedWorker receives request from PubNub SDK. + * + * @param clients List of PubNub client states for which new aggregated request should be sent. + */ +const restartSubscribeRequestForClients = (clients: PubNubClientState[]) => { + let clientWithRequest: PubNubClientState | undefined; + let request: TransportRequest | undefined; + + for (const client of clients) { + if (client.subscription && client.subscription.request) { + request = client.subscription.request; + clientWithRequest = client; + break; + } } + if (!request || !clientWithRequest) return; + + handleSendSubscribeRequestEvent({ + type: 'send-request', + clientIdentifier: clientWithRequest.clientIdentifier, + subscriptionKey: clientWithRequest.subscriptionKey, + logVerbosity: clientWithRequest.logVerbosity, + request, + }); }; // endregion @@ -725,17 +928,18 @@ const handleCancelRequestEvent = (event: CancelRequestEvent) => { * @param getClients - Request completion PubNub client observers getter. * @param success - Request success completion handler. * @param failure - Request failure handler. + * @param responsePreProcess - Raw response pre-processing function which is used before calling handling callbacks. */ const sendRequest = ( request: TransportRequest, getClients: () => PubNubClientState[], success: (clients: PubNubClientState[], response: [Response, ArrayBuffer]) => void, failure: (clients: PubNubClientState[], error: unknown) => void, + responsePreProcess?: (response: [Response, ArrayBuffer]) => [Response, ArrayBuffer], ) => { (async () => { // Request progress support. const start = new Date().getTime(); - Promise.race([ fetch(requestFromTransportRequest(request), { signal: abortControllers.get(request.identifier)?.signal, @@ -746,6 +950,7 @@ const sendRequest = ( .then((response): Promise<[Response, ArrayBuffer]> | [Response, ArrayBuffer] => response.arrayBuffer().then((buffer) => [response, buffer]), ) + .then((response) => (responsePreProcess ? responsePreProcess(response) : response)) .then((response) => { const responseBody = response[1].byteLength > 0 ? response[1] : undefined; @@ -773,6 +978,24 @@ const sendRequest = ( })(); }; +/** + * Cancel (abort) service request by ID. + * + * @param requestId - Unique identifier of request which should be cancelled. + */ +const cancelRequest = (requestId: string) => { + if (clientsForRequest(requestId).length === 0) { + const controller = abortControllers.get(requestId); + abortControllers.delete(requestId); + + // Clean up scheduled requests. + delete serviceRequests[requestId]; + + // Abort request if possible. + if (controller) controller.abort(); + } +}; + /** * Create request timeout timer. * @@ -868,15 +1091,26 @@ const requestFromTransportRequest = (req: TransportRequest): Request => { const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportRequest | string => { const client = pubNubClients[event.clientIdentifier]!; const subscription = client.subscription!; - const clients = clientsForSendSubscribeRequestEvent(subscription.previousTimetoken, event); + const clients = clientsForSendSubscribeRequestEvent(subscription.timetoken, event); const serviceRequestId = uuidGenerator.createUUID(); const request = { ...event.request }; + let previousSubscribeTimetoken: string | undefined; + let previousSubscribeRegion: string | undefined; if (clients.length > 1) { const activeRequestId = activeSubscriptionForEvent(clients, event); // Return identifier of the ongoing request. - if (activeRequestId) return activeRequestId; + if (activeRequestId) { + const scheduledRequest = serviceRequests[activeRequestId]; + const { channels, channelGroups } = client.subscription ?? { channels: [], channelGroups: [] }; + if ( + (channels.length > 0 ? includesStrings(scheduledRequest.channels, channels) : true) && + (channelGroups.length > 0 ? includesStrings(scheduledRequest.channelGroups, channelGroups) : true) + ) { + return activeRequestId; + } + } const state = (presenceState[client.subscriptionKey] ?? {})[client.userId]; const aggregatedState: Record = {}; @@ -890,20 +1124,31 @@ const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportR }); } - for (const client of clients) { - const { subscription } = client!; - // Skip clients which already have active subscription request. - if (!subscription || !subscription.serviceRequestId) continue; + for (const _client of clients) { + const { subscription: _subscription } = _client; + // Skip clients which doesn't have active subscription request. + if (!_subscription) continue; + + // Keep track of timetoken from previous call to use it for catchup after initial subscribe. + if ((clients.length === 1 || _client.clientIdentifier !== client.clientIdentifier) && _subscription.timetoken) { + previousSubscribeTimetoken = _subscription.timetoken; + previousSubscribeRegion = _subscription.region; + } + + _subscription.channelGroups.forEach(channelGroups.add, channelGroups); + _subscription.channels.forEach(channels.add, channels); - subscription.channelGroups.forEach(channelGroups.add, channelGroups); - subscription.channels.forEach(channels.add, channels); + const activeServiceRequestId = _subscription.serviceRequestId; + _subscription.serviceRequestId = serviceRequestId; // Set awaited service worker request identifier. - subscription.serviceRequestId = serviceRequestId; + if (activeServiceRequestId && serviceRequests[activeServiceRequestId]) { + cancelRequest(activeServiceRequestId); + } if (!state) continue; - subscription.objectsWithState.forEach((name) => { + _subscription.objectsWithState.forEach((name) => { const objectState = state[name]; if (objectState && !aggregatedState[name]) aggregatedState[name] = objectState; @@ -942,6 +1187,18 @@ const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportR }; } + if (serviceRequests[serviceRequestId]) { + if ( + request.queryParameters && + request.queryParameters.tt !== undefined && + request.queryParameters.tr !== undefined + ) { + serviceRequests[serviceRequestId].region = request.queryParameters.tr as string; + } + serviceRequests[serviceRequestId].timetokenOverride = previousSubscribeTimetoken; + serviceRequests[serviceRequestId].regionOverride = previousSubscribeRegion; + } + subscription.serviceRequestId = serviceRequestId; request.identifier = serviceRequestId; @@ -1015,7 +1272,7 @@ const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportReque // Update request channels list (if required). if (channels.length) { const pathComponents = request.path.split('/'); - pathComponents[4] = channels.join(','); + pathComponents[6] = channels.join(','); request.path = pathComponents.join('/'); } @@ -1300,7 +1557,6 @@ const registerClientIfRequired = (event: RegisterEvent) => { const updateClientStateIfRequired = (event: SendRequestEvent) => { const query = event.request.queryParameters!; const { clientIdentifier } = event; - const client = pubNubClients[clientIdentifier]; // This should never happen. @@ -1331,8 +1587,6 @@ const updateClientStateIfRequired = (event: SendRequestEvent) => { client.subscription = subscription; } else { - subscription.previousTimetoken = subscription.timetoken; - if (state.length > 0) { const parsedState = JSON.parse(state) as Record; const userState = ((presenceState[client.subscriptionKey] ??= {})[client.userId] ??= {}); @@ -1366,6 +1620,7 @@ const updateClientStateIfRequired = (event: SendRequestEvent) => { subscription.request = event.request; subscription.filterExpression = (query['filter-expr'] ?? '') as string; subscription.timetoken = (query.tt ?? '0') as string; + if (query.tr !== undefined) subscription.region = query.tr as string; client.authKey = (query.auth ?? '') as string; client.userId = query.uuid as string; }; @@ -1512,10 +1767,10 @@ const clientsForSendSubscribeRequestEvent = (timetoken: string, event: SendReque client.userId === userId && client.authKey === authKey && client.subscription && + // Only clients with active subscription can be used. + (client.subscription.channels.length !== 0 || client.subscription.channelGroups.length !== 0) && client.subscription.filterExpression === filterExpression && - (timetoken === '0' || - client.subscription.previousTimetoken === '0' || - client.subscription.previousTimetoken === timetoken), + (timetoken === '0' || client.subscription.timetoken === '0' || client.subscription.timetoken === timetoken), ); }; diff --git a/test/integration/components/subscription_manager.test.ts b/test/integration/components/subscription_manager.test.ts index a526e0de2..d68c554f5 100644 --- a/test/integration/components/subscription_manager.test.ts +++ b/test/integration/components/subscription_manager.test.ts @@ -84,7 +84,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"ch1","d":{"text":"Message"},"b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); @@ -100,7 +100,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client2", "k":"mySubKey","c":"coolChannel","d":{"text":"Message3"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"10","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client2", "k":"mySubKey","c":"ch1","d":{"text":"Message3"},"b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); @@ -116,7 +116,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"20","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client3", "k":"mySubKey","c":"coolChannel","d":{"text":"Message10"},"b":"coolChan-bnel", "u": {"cool": "meta"}}]}', + '{"t":{"t":"20","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1},"i": "client3", "k":"mySubKey","c":"ch1","d":{"text":"Message10"},"b":"ch1", "u": {"cool": "meta"}}]}', { 'content-type': 'text/javascript' }, ); utils @@ -138,38 +138,38 @@ describe('#components/subscription_manager', () => { assert.equal(scope3.isDone(), true); assert.deepEqual(incomingPayloads, [ { - actualChannel: 'coolChannel', + actualChannel: 'ch1', message: { text: 'Message', }, - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', + subscribedChannel: 'ch1', + channel: 'ch1', + subscription: 'ch1', timetoken: '14607577960925503', publisher: 'client1', }, { - actualChannel: 'coolChannel', + actualChannel: 'ch1', message: { text: 'Message3', }, - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', + subscribedChannel: 'ch1', + channel: 'ch1', + subscription: 'ch1', timetoken: '14607577960925503', publisher: 'client2', }, { - actualChannel: 'coolChannel', + actualChannel: 'ch1', message: { text: 'Message10', }, userMetadata: { cool: 'meta', }, - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', + subscribedChannel: 'ch1', + channel: 'ch1', + subscription: 'ch1', timetoken: '14607577960925503', publisher: 'client3', }, @@ -197,7 +197,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"mySubKey","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}', + '{"t":{"t":"14614512228786519","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"mySubKey","c":"ch1-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"ch1-pnpres"}]}', { 'content-type': 'text/javascript' }, ); @@ -207,11 +207,11 @@ describe('#components/subscription_manager', () => { assert.equal(scope.isDone(), true); assert.deepEqual( { - channel: 'coolChannel', - subscription: 'coolChannel-pnpres', - actualChannel: 'coolChannel', + channel: 'ch1', + subscription: 'ch1-pnpres', + actualChannel: 'ch1', occupancy: 1, - subscribedChannel: 'coolChannel-pnpres', + subscribedChannel: 'ch1-pnpres', timestamp: 1461451222, timetoken: '14614512228418349', uuid: '4a6d5df7-e301-4e73-a7b7-6af9ab484eb0', @@ -309,7 +309,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14637536741734954","r":1},"m":[{"a":"4","f":512,"p":{"t":"14637536740940378","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "join", "timestamp": 1463753674, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"},{"a":"4","f":512,"p":{"t":"14637536741726901","r":1},"k":"demo-36","c":"ch10-pnpres","d":{"action": "state-change", "timestamp": 1463753674, "data": {"state": "cool"}, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch10-pnpres"}]}', + '{"t":{"t":"14637536741734954","r":1},"m":[{"a":"4","f":512,"p":{"t":"14637536740940378","r":1},"k":"demo-36","c":"ch1-pnpres","d":{"action": "join", "timestamp": 1463753674, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch1-pnpres"},{"a":"4","f":512,"p":{"t":"14637536741726901","r":1},"k":"demo-36","c":"ch1-pnpres","d":{"action": "state-change", "timestamp": 1463753674, "data": {"state": "cool"}, "uuid": "24c9bb19-1fcd-4c40-a6f1-522a8a1329ef", "occupancy": 3},"b":"ch1-pnpres"}]}', { 'content-type': 'text/javascript' }, ); utils @@ -334,11 +334,11 @@ describe('#components/subscription_manager', () => { try { assert.equal(scope1.isDone(), true); assert.deepEqual(presencePayload, { - channel: 'ch10', - subscription: 'ch10-pnpres', - actualChannel: 'ch10', + channel: 'ch1', + subscription: 'ch1-pnpres', + actualChannel: 'ch1', occupancy: 3, - subscribedChannel: 'ch10-pnpres', + subscribedChannel: 'ch1-pnpres', timestamp: 1463753674, timetoken: '14637536741726901', uuid: '24c9bb19-1fcd-4c40-a6f1-522a8a1329ef', @@ -569,7 +569,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"mySubKey","c":"coolChannel-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"coolChannel-pnpres"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"p":{"t":"14614512228418349","r":2},"k":"mySubKey","c":"ch2-pnpres","d":{"action": "join", "timestamp": 1461451222, "uuid": "4a6d5df7-e301-4e73-a7b7-6af9ab484eb0", "occupancy": 1},"b":"ch2-pnpres"}]}', { 'content-type': 'text/javascript' }, ); utils @@ -619,7 +619,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"ch1","d":{"text":"Message"},"b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); @@ -635,7 +635,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"ch1","d":{"text":"Message"},"b":"ch1"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"ch1","d":{"text":"Message"},"b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); @@ -667,7 +667,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"ch2","d":{"text":"Message"},"b":"ch2"}]}', { 'content-type': 'text/javascript' }, ); @@ -683,7 +683,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChannel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"ch2","d":{"text":"Message"},"b":"ch2"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"ch2","d":{"text":"Message"},"b":"ch2"}]}', { 'content-type': 'text/javascript' }, ); @@ -719,7 +719,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":{"text":"Message"},"b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"ch1","d":{"text":"Message"},"b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); @@ -735,7 +735,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message2"},"b":"coolChannel"}, {"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"coolChannel","d":{"text":"Message1"},"b":"coolChannel"}]}', + '{"t":{"t":"14607577960932487","r":1},"m":[{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"ch1","d":{"text":"Message1"},"b":"ch1"},{"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"ch1","d":{"text":"Message2"},"b":"ch1"}, {"a":"4","f":0,"i":"Publisher-A","p":{"t":"14607577960925503","r":1},"o":{"t":"14737141991877032","r":2},"k":"mySubKey","c":"ch1","d":{"text":"Message1"},"b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); @@ -765,7 +765,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":"hello","b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"ch1","d":"hello","b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); @@ -779,11 +779,11 @@ describe('#components/subscription_manager', () => { assert.equal(scope.isDone(), true); assert.deepEqual(incomingPayloads, [ { - actualChannel: 'coolChannel', + actualChannel: 'ch1', message: 'hello', - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', + subscribedChannel: 'ch1', + channel: 'ch1', + subscription: 'ch1', timetoken: '14607577960925503', publisher: 'client1', error: 'Error while decrypting message content: Decryption error: invalid header version', @@ -812,7 +812,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":"hello","b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"ch1","d":"hello","b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); @@ -826,11 +826,11 @@ describe('#components/subscription_manager', () => { assert.equal(scope.isDone(), true); assert.deepEqual(incomingPayloads, [ { - actualChannel: 'coolChannel', + actualChannel: 'ch1', message: 'hello', - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', + subscribedChannel: 'ch1', + channel: 'ch1', + subscription: 'ch1', timetoken: '14607577960925503', publisher: 'client1', error: 'Error while decrypting message content: Decryption error: invalid header version', @@ -858,7 +858,7 @@ describe('#components/subscription_manager', () => { }) .reply( 200, - '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"coolChannel","d":"UE5FRAFBQ1JIEIocqA6BfaybN/3U0WJRam0v3bPwfAXezgeCeGp+MztQ","b":"coolChan-bnel"}]}', + '{"t":{"t":"3","r":1},"m":[{"a":"4","f":0,"i":"Client-g5d4g","p":{"t":"14607577960925503","r":1}, "i": "client1", "k":"mySubKey","c":"ch1","d":"UE5FRAFBQ1JIEIocqA6BfaybN/3U0WJRam0v3bPwfAXezgeCeGp+MztQ","b":"ch1"}]}', { 'content-type': 'text/javascript' }, ); @@ -872,11 +872,11 @@ describe('#components/subscription_manager', () => { assert.equal(scope.isDone(), true); assert.deepEqual(incomingPayloads, [ { - actualChannel: 'coolChannel', + actualChannel: 'ch1', message: 'hello', - subscribedChannel: 'coolChan-bnel', - channel: 'coolChannel', - subscription: 'coolChan-bnel', + subscribedChannel: 'ch1', + channel: 'ch1', + subscription: 'ch1', timetoken: '14607577960925503', publisher: 'client1', }, From e95f8a0708a01578f08714eb7b5445b2ee8025b6 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Fri, 25 Oct 2024 11:41:56 +0300 Subject: [PATCH 22/49] build(workflow): fix organization runner group name (#416) --- .github/workflows/commands-handler.yml | 2 +- .github/workflows/release.yml | 4 ++-- .github/workflows/run-tests.yml | 4 ++-- .github/workflows/run-validations.yml | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/commands-handler.yml b/.github/workflows/commands-handler.yml index 48f71d24a..51f8668fa 100644 --- a/.github/workflows/commands-handler.yml +++ b/.github/workflows/commands-handler.yml @@ -12,7 +12,7 @@ jobs: name: Process command if: github.event.issue.pull_request && endsWith(github.repository, '-private') != true runs-on: - group: Default + group: organization/Default steps: - name: Check referred user id: user-check diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d70eaa11e..b02d37ee8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ jobs: name: Check release required if: github.event.pull_request.merged && endsWith(github.repository, '-private') != true runs-on: - group: Default + group: organization/Default outputs: release: ${{ steps.check.outputs.ready }} steps: @@ -31,7 +31,7 @@ jobs: needs: check-release if: needs.check-release.outputs.release == 'true' runs-on: - group: Default + group: organization/Default steps: - name: Checkout repository uses: actions/checkout@v4 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0c8f1b0d1..5432edf8b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -21,7 +21,7 @@ jobs: tests: name: Integration and Unit tests runs-on: - group: Default + group: organization/Default strategy: fail-fast: true matrix: @@ -56,7 +56,7 @@ jobs: all-tests: name: Tests runs-on: - group: Default + group: organization/Default needs: [tests] steps: - name: Tests summary diff --git a/.github/workflows/run-validations.yml b/.github/workflows/run-validations.yml index 859f64d92..266a04d23 100644 --- a/.github/workflows/run-validations.yml +++ b/.github/workflows/run-validations.yml @@ -14,7 +14,7 @@ jobs: pubnub-yml: name: 'Validate .pubnub.yml' runs-on: - group: Default + group: organization/Default steps: - name: Checkout project uses: actions/checkout@v4 @@ -35,7 +35,7 @@ jobs: all-validations: name: Validations runs-on: - group: Default + group: organization/Default needs: [pubnub-yml] steps: - name: Validations summary From c47f202c2966408e221267ebfd142c64a6ddde85 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Fri, 25 Oct 2024 11:51:17 +0300 Subject: [PATCH 23/49] Fix / revert `fetch` `TypeError` handling (#415) fix(subscribe): fix / revert `fetch` `TypeError` handling Revert fix created to handle browser timeouts (not gracefully). The Web Fetch API doesn't have descriptive error information, and it sends `TypeError` for both cases when connection closed by browser or network issue (blocked domain). --- .pubnub.yml | 11 ++++++++--- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- dist/web/pubnub.js | 7 ++----- dist/web/pubnub.min.js | 4 ++-- lib/core/components/configuration.js | 2 +- lib/errors/pubnub-api-error.js | 5 +---- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/errors/pubnub-api-error.ts | 4 +--- 10 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 25f227059..3970ec71c 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-10-25 + version: v8.2.9 + changes: + - type: bug + text: "Revert fix created to handle browser timeouts (not gracefully). The Web Fetch API doesn't have descriptive error information, and it sends `TypeError` for both cases when connection closed by browser or network issue (blocked domain)." - date: 2024-09-30 version: v8.2.8 changes: @@ -1036,7 +1041,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.8' +version: '8.2.9' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1052,7 +1057,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.8.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.9.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1723,7 +1728,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.8/pubnub.8.2.8.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.9/pubnub.8.2.9.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 2b1f64972..0dfa98a54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.2.9 +October 25 2024 + +#### Fixed +- Revert fix created to handle browser timeouts (not gracefully). The Web Fetch API doesn't have descriptive error information, and it sends `TypeError` for both cases when connection closed by browser or network issue (blocked domain). + ## v8.2.8 September 30 2024 diff --git a/README.md b/README.md index 091457572..1d546fa73 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.8.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.8.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.9.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.9.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 45fefd7dd..7cd3b7f5a 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -2839,10 +2839,7 @@ message = 'Network issues'; } else if (errorName === 'TypeError') { - if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) - category = StatusCategory$1.PNTimeoutCategory; - else - category = StatusCategory$1.PNBadRequestCategory; + category = StatusCategory$1.PNBadRequestCategory; } else if (errorName === 'FetchError') { const errorCode = error.code; @@ -3816,7 +3813,7 @@ return base.PubNubFile; }, get version() { - return '8.2.8'; + return '8.2.9'; }, getVersion() { return this.version; diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 34c4dcc6b..6b073e00d 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNTimeoutCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.8"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.9"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index bcb2b2652..bd79ae66d 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -110,7 +110,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.8'; + return '8.2.9'; }, getVersion() { return this.version; diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js index 4ac0d928a..1f09b98b7 100644 --- a/lib/errors/pubnub-api-error.js +++ b/lib/errors/pubnub-api-error.js @@ -62,10 +62,7 @@ class PubNubAPIError extends Error { message = 'Network issues'; } else if (errorName === 'TypeError') { - if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) - category = categories_1.default.PNTimeoutCategory; - else - category = categories_1.default.PNBadRequestCategory; + category = categories_1.default.PNBadRequestCategory; } else if (errorName === 'FetchError') { const errorCode = error.code; diff --git a/package.json b/package.json index eb281e717..c3552a836 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.8", + "version": "8.2.9", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index adde504ab..2feb65c1e 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -169,7 +169,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.8'; + return '8.2.9'; }, getVersion(): string { return this.version; diff --git a/src/errors/pubnub-api-error.ts b/src/errors/pubnub-api-error.ts index c00ce0394..793deb1bb 100644 --- a/src/errors/pubnub-api-error.ts +++ b/src/errors/pubnub-api-error.ts @@ -58,9 +58,7 @@ export class PubNubAPIError extends Error { category = StatusCategory.PNNetworkIssuesCategory; message = 'Network issues'; } else if (errorName === 'TypeError') { - if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) - category = StatusCategory.PNTimeoutCategory; - else category = StatusCategory.PNBadRequestCategory; + category = StatusCategory.PNBadRequestCategory; } else if (errorName === 'FetchError') { const errorCode = (error as Record).code; From 66520c26d80291bb45961b6b5e71b54ec0a2d50d Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 31 Oct 2024 21:54:36 +0200 Subject: [PATCH 24/49] Fix types definition issues (#417) fix(types): fix `Actions` type definition Fix definition of type which represent message actions received from history and list of users which added action of specific type and value to the message. Closes #407 refactor(types): remove indexed signature for publish Remove redundant indexed signature from publish message parameters type definition. Closes #413 refactor(types): add serializable objects to `Payload` type Extend `Payload` type definition with objects which can be serialized by `JSON.stringify` using `toJSON()` methods. Closes #412 refactor(types): aggregate generated types definitions Aggregate multiple types definitions into single type definition type with proper type names and namespaces. Closes #405 #409 #410 refactor(types): add missing Subscribe Event Engine types Add Subscribe Event Engine and Event Listener types to the bundled types definition file. Closes #377 --- .pubnub.yml | 27 +- .scripts/types-aggregate.ts | 803 ++ CHANGELOG.md | 18 + README.md | 4 +- dist/web/pubnub.js | 1530 ++- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 10 +- lib/cbor/common.js | 2 + lib/core/components/abort_signal.js | 5 + lib/core/components/base64_codec.js | 10 +- lib/core/components/configuration.js | 6 +- .../components/cryptography/hmac-sha256.js | 5 + lib/core/components/cryptography/index.js | 9 + lib/core/components/deduping_manager.js | 75 +- lib/core/components/eventEmitter.js | 5 + lib/core/components/push_payload.js | 73 +- lib/core/components/reconnection_manager.js | 2 + lib/core/components/request.js | 5 + lib/core/components/stringify_buffer_keys.js | 8 +- lib/core/components/subject.js | 5 + lib/core/components/subscription-manager.js | 8 +- lib/core/components/token_manager.js | 2 + lib/core/components/uuid.js | 6 + lib/core/constants/operations.js | 14 +- lib/core/endpoints/access_manager/audit.js | 2 + lib/core/endpoints/access_manager/grant.js | 2 + .../endpoints/access_manager/grant_token.js | 2 + .../endpoints/access_manager/revoke_token.js | 2 + .../endpoints/actions/add_message_action.js | 2 + .../endpoints/actions/get_message_actions.js | 2 + .../actions/remove_message_action.js | 2 + .../endpoints/channel_groups/add_channels.js | 2 + .../endpoints/channel_groups/delete_group.js | 2 + .../endpoints/channel_groups/list_channels.js | 2 + .../endpoints/channel_groups/list_groups.js | 2 + .../channel_groups/remove_channels.js | 2 + lib/core/endpoints/fetch_messages.js | 2 + lib/core/endpoints/file_upload/delete_file.js | 2 + .../endpoints/file_upload/download_file.js | 2 + .../file_upload/generate_upload_url.js | 2 + .../endpoints/file_upload/get_file_url.js | 2 + lib/core/endpoints/file_upload/list_files.js | 2 + .../endpoints/file_upload/publish_file.js | 2 + lib/core/endpoints/file_upload/send_file.js | 5 + lib/core/endpoints/file_upload/upload-file.js | 2 + lib/core/endpoints/history/delete_messages.js | 2 + lib/core/endpoints/history/get_history.js | 2 + lib/core/endpoints/history/message_counts.js | 2 + lib/core/endpoints/objects/channel/get.js | 2 + lib/core/endpoints/objects/channel/get_all.js | 2 + lib/core/endpoints/objects/channel/remove.js | 2 + lib/core/endpoints/objects/channel/set.js | 2 + lib/core/endpoints/objects/member/get.js | 2 + lib/core/endpoints/objects/member/set.js | 2 + lib/core/endpoints/objects/membership/get.js | 2 + lib/core/endpoints/objects/membership/set.js | 2 + lib/core/endpoints/objects/uuid/get.js | 2 + lib/core/endpoints/objects/uuid/get_all.js | 2 + lib/core/endpoints/objects/uuid/remove.js | 2 + lib/core/endpoints/objects/uuid/set.js | 2 + lib/core/endpoints/presence/get_state.js | 2 + lib/core/endpoints/presence/heartbeat.js | 2 + lib/core/endpoints/presence/here_now.js | 2 + lib/core/endpoints/presence/leave.js | 2 + lib/core/endpoints/presence/set_state.js | 2 + lib/core/endpoints/presence/where_now.js | 2 + lib/core/endpoints/push/add_push_channels.js | 2 + lib/core/endpoints/push/list_push_channels.js | 2 + lib/core/endpoints/push/push.js | 2 + lib/core/endpoints/push/remove_device.js | 2 + .../endpoints/push/remove_push_channels.js | 2 + lib/core/endpoints/subscribe.js | 2 - .../endpoints/subscriptionUtils/handshake.js | 2 + .../subscriptionUtils/receiveMessages.js | 2 + lib/core/interfaces/configuration.js | 7 +- lib/core/interfaces/crypto-module.js | 6 + lib/core/pubnub-channel-groups.js | 17 +- lib/core/pubnub-common.js | 32 +- lib/core/pubnub-objects.js | 31 +- lib/core/pubnub-push.js | 13 +- lib/core/utils.js | 19 +- .../modules/NodeCryptoModule/aesCbcCryptor.js | 4 + .../modules/NodeCryptoModule/legacyCryptor.js | 4 + .../NodeCryptoModule/nodeCryptoModule.js | 40 +- lib/crypto/modules/node.js | 4 + lib/entities/Channel.js | 28 +- lib/entities/ChannelGroup.js | 29 +- lib/entities/ChannelMetadata.js | 27 +- lib/entities/SubscribeCapable.js | 68 + lib/entities/Subscription.js | 45 + lib/entities/SubscriptionSet.js | 89 + lib/entities/UserMetadata.js | 27 +- lib/errors/pubnub-api-error.js | 4 + lib/errors/pubnub-error.js | 41 +- lib/event-engine/core/change.js | 6 +- lib/event-engine/core/dispatcher.js | 13 +- lib/event-engine/core/engine.js | 12 +- lib/event-engine/core/handler.js | 26 + lib/event-engine/core/index.js | 9 + lib/event-engine/core/retryPolicy.js | 3 + lib/event-engine/core/state.js | 13 +- lib/event-engine/core/types.js | 28 +- lib/event-engine/dispatcher.js | 22 +- lib/event-engine/effects.js | 48 + lib/event-engine/events.js | 110 + lib/event-engine/index.js | 10 + lib/event-engine/presence/dispatcher.js | 24 +- lib/event-engine/presence/effects.js | 40 + lib/event-engine/presence/events.js | 73 + lib/event-engine/presence/presence.js | 10 + .../presence/states/heartbeat_cooldown.js | 12 + .../presence/states/heartbeat_failed.js | 13 + .../presence/states/heartbeat_inactive.js | 12 + .../presence/states/heartbeat_reconnecting.js | 12 + .../presence/states/heartbeat_stopped.js | 13 + .../presence/states/heartbeating.js | 12 + lib/event-engine/states/handshake_failed.js | 15 +- .../states/handshake_reconnecting.js | 12 + lib/event-engine/states/handshake_stopped.js | 13 + lib/event-engine/states/handshaking.js | 13 + lib/event-engine/states/receive_failed.js | 13 + .../states/receive_reconnecting.js | 12 + lib/event-engine/states/receive_stopped.js | 13 + lib/event-engine/states/receiving.js | 12 + lib/event-engine/states/unsubscribed.js | 12 + lib/node/{ => components}/configuration.js | 2 +- lib/node/index.js | 13 +- lib/react_native/index.js | 7 + lib/transport/middleware.js | 10 + lib/transport/node-transport.js | 17 + lib/transport/web-react-native-transport.js | 23 +- lib/types/cbor/common.d.ts | 4 - lib/types/core/components/abort_signal.d.ts | 4 - lib/types/core/components/base64_codec.d.ts | 1 - lib/types/core/components/configuration.d.ts | 4 - .../components/cryptography/hmac-sha256.d.ts | 3 - .../core/components/cryptography/index.d.ts | 143 - .../core/components/deduping_manager.d.ts | 16 - lib/types/core/components/eventEmitter.d.ts | 1 - .../core/components/listener_manager.d.ts | 76 - lib/types/core/components/push_payload.d.ts | 636 -- .../core/components/reconnection_manager.d.ts | 6 - lib/types/core/components/request.d.ts | 1 - .../components/stringify_buffer_keys.d.ts | 1 - lib/types/core/components/subject.d.ts | 1 - .../core/components/subscription-manager.d.ts | 4 - lib/types/core/components/token_manager.d.ts | 4 - lib/types/core/components/uuid.d.ts | 4 - lib/types/core/constants/categories.d.ts | 75 - lib/types/core/constants/operations.d.ts | 203 - .../core/endpoints/access_manager/audit.d.ts | 4 - .../core/endpoints/access_manager/grant.d.ts | 4 - .../endpoints/access_manager/grant_token.d.ts | 4 - .../access_manager/revoke_token.d.ts | 4 - .../endpoints/actions/add_message_action.d.ts | 4 - .../actions/get_message_actions.d.ts | 4 - .../actions/remove_message_action.d.ts | 4 - .../channel_groups/add_channels.d.ts | 4 - .../channel_groups/delete_group.d.ts | 4 - .../channel_groups/list_channels.d.ts | 4 - .../endpoints/channel_groups/list_groups.d.ts | 4 - .../channel_groups/remove_channels.d.ts | 4 - lib/types/core/endpoints/fetch_messages.d.ts | 4 - .../endpoints/file_upload/delete_file.d.ts | 4 - .../endpoints/file_upload/download_file.d.ts | 4 - .../file_upload/generate_upload_url.d.ts | 4 - .../endpoints/file_upload/get_file_url.d.ts | 4 - .../endpoints/file_upload/list_files.d.ts | 4 - .../endpoints/file_upload/publish_file.d.ts | 4 - .../core/endpoints/file_upload/send_file.d.ts | 1 - .../endpoints/file_upload/upload-file.d.ts | 4 - .../endpoints/history/delete_messages.d.ts | 4 - .../core/endpoints/history/get_history.d.ts | 4 - .../endpoints/history/message_counts.d.ts | 4 - .../core/endpoints/objects/channel/get.d.ts | 4 - .../endpoints/objects/channel/get_all.d.ts | 4 - .../endpoints/objects/channel/remove.d.ts | 4 - .../core/endpoints/objects/channel/set.d.ts | 4 - .../core/endpoints/objects/member/get.d.ts | 4 - .../core/endpoints/objects/member/set.d.ts | 4 - .../endpoints/objects/membership/get.d.ts | 4 - .../endpoints/objects/membership/set.d.ts | 4 - .../core/endpoints/objects/uuid/get.d.ts | 4 - .../core/endpoints/objects/uuid/get_all.d.ts | 4 - .../core/endpoints/objects/uuid/remove.d.ts | 4 - .../core/endpoints/objects/uuid/set.d.ts | 4 - .../core/endpoints/presence/get_state.d.ts | 4 - .../core/endpoints/presence/heartbeat.d.ts | 4 - .../core/endpoints/presence/here_now.d.ts | 4 - lib/types/core/endpoints/presence/leave.d.ts | 4 - .../core/endpoints/presence/set_state.d.ts | 4 - .../core/endpoints/presence/where_now.d.ts | 4 - lib/types/core/endpoints/publish.d.ts | 69 - .../endpoints/push/add_push_channels.d.ts | 4 - .../endpoints/push/list_push_channels.d.ts | 4 - lib/types/core/endpoints/push/push.d.ts | 4 - .../core/endpoints/push/remove_device.d.ts | 4 - .../endpoints/push/remove_push_channels.d.ts | 4 - lib/types/core/endpoints/signal.d.ts | 28 - lib/types/core/endpoints/subscribe.d.ts | 4 - .../subscriptionUtils/handshake.d.ts | 4 - .../subscriptionUtils/receiveMessages.d.ts | 4 - lib/types/core/endpoints/time.d.ts | 12 - lib/types/core/interfaces/configuration.d.ts | 276 - lib/types/core/interfaces/crypto-module.d.ts | 152 - lib/types/core/interfaces/cryptography.d.ts | 54 - lib/types/core/interfaces/request.d.ts | 1 - lib/types/core/interfaces/transport.d.ts | 61 - lib/types/core/pubnub-channel-groups.d.ts | 86 - lib/types/core/pubnub-common.d.ts | 1300 --- lib/types/core/pubnub-objects.d.ts | 364 - lib/types/core/pubnub-push.d.ts | 64 - lib/types/core/types/api/access-manager.d.ts | 464 - lib/types/core/types/api/app-context.d.ts | 875 -- lib/types/core/types/api/channel-groups.d.ts | 57 - lib/types/core/types/api/file-sharing.d.ts | 357 - lib/types/core/types/api/history.d.ts | 395 - lib/types/core/types/api/index.d.ts | 121 - lib/types/core/types/api/message-action.d.ts | 153 - lib/types/core/types/api/presence.d.ts | 210 - .../core/types/api/push-notifications.d.ts | 48 - lib/types/core/types/api/push.d.ts | 122 - lib/types/core/types/api/subscription.d.ts | 296 - lib/types/core/types/file.d.ts | 104 - lib/types/core/types/transport-request.d.ts | 97 - lib/types/core/types/transport-response.d.ts | 23 - lib/types/core/utils.d.ts | 31 - lib/types/crypto/index.d.ts | 0 .../modules/NodeCryptoModule/ICryptor.d.ts | 86 - .../NodeCryptoModule/ILegacyCryptor.d.ts | 60 - .../NodeCryptoModule/aesCbcCryptor.d.ts | 57 - .../NodeCryptoModule/legacyCryptor.d.ts | 33 - .../NodeCryptoModule/nodeCryptoModule.d.ts | 108 - lib/types/crypto/modules/node.d.ts | 97 - lib/types/entities/Channel.d.ts | 11 - lib/types/entities/ChannelGroup.d.ts | 11 - lib/types/entities/ChannelMetadata.d.ts | 11 - lib/types/entities/SubscribeCapable.d.ts | 27 - lib/types/entities/Subscription.d.ts | 22 - lib/types/entities/SubscriptionSet.d.ts | 27 - lib/types/entities/UserMetadata.d.ts | 11 - lib/types/entities/commonTypes.d.ts | 3 - lib/types/errors/pubnub-api-error.d.ts | 73 - lib/types/errors/pubnub-error.d.ts | 6 - lib/types/event-engine/core/change.d.ts | 24 - lib/types/event-engine/core/dispatcher.d.ts | 13 - lib/types/event-engine/core/engine.d.ts | 11 - lib/types/event-engine/core/handler.d.ts | 18 - lib/types/event-engine/core/index.d.ts | 4 - lib/types/event-engine/core/retryPolicy.d.ts | 58 - lib/types/event-engine/core/state.d.ts | 21 - lib/types/event-engine/core/types.d.ts | 45 - lib/types/event-engine/dispatcher.d.ts | 27 - lib/types/event-engine/effects.d.ts | 77 - lib/types/event-engine/events.d.ts | 159 - lib/types/event-engine/index.d.ts | 33 - .../event-engine/presence/dispatcher.d.ts | 18 - lib/types/event-engine/presence/effects.d.ts | 31 - lib/types/event-engine/presence/events.d.ts | 47 - lib/types/event-engine/presence/presence.d.ts | 24 - .../presence/states/heartbeat_cooldown.d.ts | 8 - .../presence/states/heartbeat_failed.d.ts | 8 - .../presence/states/heartbeat_inactive.d.ts | 4 - .../states/heartbeat_reconnecting.d.ts | 11 - .../presence/states/heartbeat_stopped.d.ts | 8 - .../presence/states/heartbeating.d.ts | 8 - .../event-engine/states/handshake_failed.d.ts | 12 - .../states/handshake_reconnecting.d.ts | 13 - .../states/handshake_stopped.d.ts | 11 - .../event-engine/states/handshaking.d.ts | 10 - .../event-engine/states/receive_failed.d.ts | 12 - .../states/receive_reconnecting.d.ts | 13 - .../event-engine/states/receive_stopped.d.ts | 11 - lib/types/event-engine/states/receiving.d.ts | 10 - .../event-engine/states/unsubscribed.d.ts | 4 - lib/types/file/modules/node.d.ts | 134 - lib/types/file/modules/react-native.d.ts | 135 - lib/types/index.d.ts | 8115 +++++++++++++++ lib/types/models/Cursor.d.ts | 4 - lib/types/node/configuration.d.ts | 54 - lib/types/node/index.d.ts | 38 - lib/types/react_native/configuration.d.ts | 5 - lib/types/react_native/index.d.ts | 10 - lib/types/transport/middleware.d.ts | 52 - lib/types/transport/node-transport.d.ts | 69 - .../transport/web-react-native-transport.d.ts | 36 - package-lock.json | 9154 ++++++++--------- package.json | 20 +- src/cbor/common.ts | 2 + src/core/components/abort_signal.ts | 6 + src/core/components/base64_codec.ts | 6 + src/core/components/configuration.ts | 14 +- .../components/cryptography/hmac-sha256.js | 6 + src/core/components/cryptography/index.ts | 11 + src/core/components/deduping_manager.js | 50 - src/core/components/deduping_manager.ts | 96 + src/core/components/eventEmitter.ts | 6 + src/core/components/push_payload.ts | 113 +- src/core/components/reconnection_manager.ts | 2 + src/core/components/request.ts | 6 + src/core/components/stringify_buffer_keys.ts | 6 + src/core/components/subject.ts | 6 + src/core/components/subscription-manager.ts | 10 +- src/core/components/token_manager.ts | 137 +- src/core/components/uuid.ts | 7 + src/core/constants/operations.ts | 15 +- src/core/endpoints/access_manager/audit.ts | 2 + src/core/endpoints/access_manager/grant.ts | 2 + .../endpoints/access_manager/grant_token.ts | 2 + .../endpoints/access_manager/revoke_token.ts | 2 + .../endpoints/actions/add_message_action.ts | 2 + .../endpoints/actions/get_message_actions.ts | 2 + .../actions/remove_message_action.ts | 2 + .../endpoints/channel_groups/add_channels.ts | 2 + .../endpoints/channel_groups/delete_group.ts | 2 + .../endpoints/channel_groups/list_channels.ts | 2 + .../endpoints/channel_groups/list_groups.ts | 2 + .../channel_groups/remove_channels.ts | 2 + src/core/endpoints/fetch_messages.ts | 6 +- src/core/endpoints/file_upload/delete_file.ts | 2 + .../endpoints/file_upload/download_file.ts | 6 +- .../file_upload/generate_upload_url.ts | 2 + .../endpoints/file_upload/get_file_url.ts | 2 + src/core/endpoints/file_upload/list_files.ts | 2 + .../endpoints/file_upload/publish_file.ts | 6 +- src/core/endpoints/file_upload/send_file.ts | 10 +- src/core/endpoints/file_upload/upload-file.ts | 2 + src/core/endpoints/history/delete_messages.ts | 2 + src/core/endpoints/history/get_history.ts | 6 +- src/core/endpoints/history/message_counts.ts | 2 + src/core/endpoints/objects/channel/get.ts | 2 + src/core/endpoints/objects/channel/get_all.ts | 2 + src/core/endpoints/objects/channel/remove.ts | 2 + src/core/endpoints/objects/channel/set.ts | 2 + src/core/endpoints/objects/member/get.ts | 2 + src/core/endpoints/objects/member/set.ts | 2 + src/core/endpoints/objects/membership/get.ts | 2 + src/core/endpoints/objects/membership/set.ts | 2 + src/core/endpoints/objects/uuid/get.ts | 2 + src/core/endpoints/objects/uuid/get_all.ts | 2 + src/core/endpoints/objects/uuid/remove.ts | 2 + src/core/endpoints/objects/uuid/set.ts | 2 + src/core/endpoints/presence/get_state.ts | 2 + src/core/endpoints/presence/heartbeat.ts | 2 + src/core/endpoints/presence/here_now.ts | 4 +- src/core/endpoints/presence/leave.ts | 2 + src/core/endpoints/presence/set_state.ts | 2 + src/core/endpoints/presence/where_now.ts | 2 + src/core/endpoints/publish.ts | 9 +- src/core/endpoints/push/add_push_channels.ts | 2 + src/core/endpoints/push/list_push_channels.ts | 2 + src/core/endpoints/push/push.ts | 2 + src/core/endpoints/push/remove_device.ts | 2 + .../endpoints/push/remove_push_channels.ts | 2 + src/core/endpoints/signal.ts | 2 +- src/core/endpoints/subscribe.ts | 28 +- .../endpoints/subscriptionUtils/handshake.ts | 2 + .../subscriptionUtils/receiveMessages.ts | 2 + src/core/interfaces/configuration.ts | 14 +- src/core/interfaces/crypto-module.ts | 18 +- src/core/pubnub-channel-groups.ts | 37 +- src/core/pubnub-common.ts | 52 +- src/core/pubnub-objects.ts | 52 +- src/core/pubnub-push.ts | 35 +- src/core/types/api/access-manager.ts | 142 + src/core/types/api/file-sharing.ts | 6 +- src/core/types/api/history.ts | 2 +- src/core/types/api/index.ts | 12 +- src/core/types/api/message-action.ts | 2 +- src/core/types/api/push-notifications.ts | 2 +- src/core/types/api/subscription.ts | 4 +- src/core/utils.ts | 20 +- .../modules/NodeCryptoModule/ICryptor.ts | 4 +- .../modules/NodeCryptoModule/aesCbcCryptor.ts | 4 + .../modules/NodeCryptoModule/legacyCryptor.ts | 4 + .../NodeCryptoModule/nodeCryptoModule.ts | 37 +- src/crypto/modules/node.ts | 4 + src/crypto/modules/web.ts | 36 +- src/entities/Channel.ts | 53 +- src/entities/ChannelGroup.ts | 55 +- src/entities/ChannelMetadata.ts | 57 +- src/entities/SubscribeCapable.ts | 112 +- src/entities/Subscription.ts | 73 + src/entities/SubscriptionSet.ts | 118 + src/entities/UserMetadata.ts | 57 +- src/entities/commonTypes.ts | 6 + src/errors/pubnub-api-error.ts | 4 + src/errors/pubnub-error.ts | 38 + src/event-engine/core/change.ts | 11 + src/event-engine/core/dispatcher.ts | 18 + src/event-engine/core/engine.ts | 11 + src/event-engine/core/handler.ts | 32 + src/event-engine/core/index.ts | 10 + src/event-engine/core/retryPolicy.ts | 12 +- src/event-engine/core/state.ts | 15 + src/event-engine/core/types.ts | 34 + src/event-engine/dispatcher.ts | 18 + src/event-engine/effects.ts | 54 + src/event-engine/events.ts | 118 + src/event-engine/index.ts | 11 + src/event-engine/presence/dispatcher.ts | 18 + src/event-engine/presence/effects.ts | 46 + src/event-engine/presence/events.ts | 79 + src/event-engine/presence/presence.ts | 11 + .../presence/states/heartbeat_cooldown.ts | 18 + .../presence/states/heartbeat_failed.ts | 19 + .../presence/states/heartbeat_inactive.ts | 13 + .../presence/states/heartbeat_reconnecting.ts | 18 + .../presence/states/heartbeat_stopped.ts | 19 + .../presence/states/heartbeating.ts | 18 + src/event-engine/states/handshake_failed.ts | 21 +- .../states/handshake_reconnecting.ts | 18 + src/event-engine/states/handshake_stopped.ts | 19 + src/event-engine/states/handshaking.ts | 19 + src/event-engine/states/receive_failed.ts | 19 + .../states/receive_reconnecting.ts | 18 + src/event-engine/states/receive_stopped.ts | 19 + src/event-engine/states/receiving.ts | 18 + src/event-engine/states/unsubscribed.ts | 13 + src/models/Cursor.ts | 16 +- src/node/{ => components}/configuration.ts | 10 +- src/node/index.ts | 20 +- src/react_native/index.ts | 7 + src/titanium/index.ts | 7 + src/transport/middleware.ts | 13 + src/transport/node-transport.ts | 23 + .../subscription-worker-middleware.ts | 2 + .../subscription-worker.ts | 2 + src/transport/web-react-native-transport.ts | 23 +- src/web/components/configuration.ts | 4 +- src/web/index.ts | 7 + test/contract/definitions/auth.ts | 7 - test/contract/definitions/event-engine.ts | 14 +- test/contract/definitions/grant.ts | 8 +- test/integration/components/crypto.test.ts | 2 +- .../components/reconnection_manager.test.ts | 6 +- .../components/subscription_manager.test.ts | 22 +- test/utils.ts | 4 +- tsconfig.json | 6 +- 439 files changed, 18594 insertions(+), 14506 deletions(-) create mode 100644 .scripts/types-aggregate.ts rename lib/node/{ => components}/configuration.js (93%) delete mode 100644 lib/types/cbor/common.d.ts delete mode 100644 lib/types/core/components/abort_signal.d.ts delete mode 100644 lib/types/core/components/base64_codec.d.ts delete mode 100644 lib/types/core/components/configuration.d.ts delete mode 100644 lib/types/core/components/cryptography/hmac-sha256.d.ts delete mode 100644 lib/types/core/components/cryptography/index.d.ts delete mode 100644 lib/types/core/components/deduping_manager.d.ts delete mode 100644 lib/types/core/components/eventEmitter.d.ts delete mode 100644 lib/types/core/components/listener_manager.d.ts delete mode 100644 lib/types/core/components/push_payload.d.ts delete mode 100644 lib/types/core/components/reconnection_manager.d.ts delete mode 100644 lib/types/core/components/request.d.ts delete mode 100644 lib/types/core/components/stringify_buffer_keys.d.ts delete mode 100644 lib/types/core/components/subject.d.ts delete mode 100644 lib/types/core/components/subscription-manager.d.ts delete mode 100644 lib/types/core/components/token_manager.d.ts delete mode 100644 lib/types/core/components/uuid.d.ts delete mode 100644 lib/types/core/constants/categories.d.ts delete mode 100644 lib/types/core/constants/operations.d.ts delete mode 100644 lib/types/core/endpoints/access_manager/audit.d.ts delete mode 100644 lib/types/core/endpoints/access_manager/grant.d.ts delete mode 100644 lib/types/core/endpoints/access_manager/grant_token.d.ts delete mode 100644 lib/types/core/endpoints/access_manager/revoke_token.d.ts delete mode 100644 lib/types/core/endpoints/actions/add_message_action.d.ts delete mode 100644 lib/types/core/endpoints/actions/get_message_actions.d.ts delete mode 100644 lib/types/core/endpoints/actions/remove_message_action.d.ts delete mode 100644 lib/types/core/endpoints/channel_groups/add_channels.d.ts delete mode 100644 lib/types/core/endpoints/channel_groups/delete_group.d.ts delete mode 100644 lib/types/core/endpoints/channel_groups/list_channels.d.ts delete mode 100644 lib/types/core/endpoints/channel_groups/list_groups.d.ts delete mode 100644 lib/types/core/endpoints/channel_groups/remove_channels.d.ts delete mode 100644 lib/types/core/endpoints/fetch_messages.d.ts delete mode 100644 lib/types/core/endpoints/file_upload/delete_file.d.ts delete mode 100644 lib/types/core/endpoints/file_upload/download_file.d.ts delete mode 100644 lib/types/core/endpoints/file_upload/generate_upload_url.d.ts delete mode 100644 lib/types/core/endpoints/file_upload/get_file_url.d.ts delete mode 100644 lib/types/core/endpoints/file_upload/list_files.d.ts delete mode 100644 lib/types/core/endpoints/file_upload/publish_file.d.ts delete mode 100644 lib/types/core/endpoints/file_upload/send_file.d.ts delete mode 100644 lib/types/core/endpoints/file_upload/upload-file.d.ts delete mode 100644 lib/types/core/endpoints/history/delete_messages.d.ts delete mode 100644 lib/types/core/endpoints/history/get_history.d.ts delete mode 100644 lib/types/core/endpoints/history/message_counts.d.ts delete mode 100644 lib/types/core/endpoints/objects/channel/get.d.ts delete mode 100644 lib/types/core/endpoints/objects/channel/get_all.d.ts delete mode 100644 lib/types/core/endpoints/objects/channel/remove.d.ts delete mode 100644 lib/types/core/endpoints/objects/channel/set.d.ts delete mode 100644 lib/types/core/endpoints/objects/member/get.d.ts delete mode 100644 lib/types/core/endpoints/objects/member/set.d.ts delete mode 100644 lib/types/core/endpoints/objects/membership/get.d.ts delete mode 100644 lib/types/core/endpoints/objects/membership/set.d.ts delete mode 100644 lib/types/core/endpoints/objects/uuid/get.d.ts delete mode 100644 lib/types/core/endpoints/objects/uuid/get_all.d.ts delete mode 100644 lib/types/core/endpoints/objects/uuid/remove.d.ts delete mode 100644 lib/types/core/endpoints/objects/uuid/set.d.ts delete mode 100644 lib/types/core/endpoints/presence/get_state.d.ts delete mode 100644 lib/types/core/endpoints/presence/heartbeat.d.ts delete mode 100644 lib/types/core/endpoints/presence/here_now.d.ts delete mode 100644 lib/types/core/endpoints/presence/leave.d.ts delete mode 100644 lib/types/core/endpoints/presence/set_state.d.ts delete mode 100644 lib/types/core/endpoints/presence/where_now.d.ts delete mode 100644 lib/types/core/endpoints/publish.d.ts delete mode 100644 lib/types/core/endpoints/push/add_push_channels.d.ts delete mode 100644 lib/types/core/endpoints/push/list_push_channels.d.ts delete mode 100644 lib/types/core/endpoints/push/push.d.ts delete mode 100644 lib/types/core/endpoints/push/remove_device.d.ts delete mode 100644 lib/types/core/endpoints/push/remove_push_channels.d.ts delete mode 100644 lib/types/core/endpoints/signal.d.ts delete mode 100644 lib/types/core/endpoints/subscribe.d.ts delete mode 100644 lib/types/core/endpoints/subscriptionUtils/handshake.d.ts delete mode 100644 lib/types/core/endpoints/subscriptionUtils/receiveMessages.d.ts delete mode 100644 lib/types/core/endpoints/time.d.ts delete mode 100644 lib/types/core/interfaces/configuration.d.ts delete mode 100644 lib/types/core/interfaces/crypto-module.d.ts delete mode 100644 lib/types/core/interfaces/cryptography.d.ts delete mode 100644 lib/types/core/interfaces/request.d.ts delete mode 100644 lib/types/core/interfaces/transport.d.ts delete mode 100644 lib/types/core/pubnub-channel-groups.d.ts delete mode 100644 lib/types/core/pubnub-common.d.ts delete mode 100644 lib/types/core/pubnub-objects.d.ts delete mode 100644 lib/types/core/pubnub-push.d.ts delete mode 100644 lib/types/core/types/api/access-manager.d.ts delete mode 100644 lib/types/core/types/api/app-context.d.ts delete mode 100644 lib/types/core/types/api/channel-groups.d.ts delete mode 100644 lib/types/core/types/api/file-sharing.d.ts delete mode 100644 lib/types/core/types/api/history.d.ts delete mode 100644 lib/types/core/types/api/index.d.ts delete mode 100644 lib/types/core/types/api/message-action.d.ts delete mode 100644 lib/types/core/types/api/presence.d.ts delete mode 100644 lib/types/core/types/api/push-notifications.d.ts delete mode 100644 lib/types/core/types/api/push.d.ts delete mode 100644 lib/types/core/types/api/subscription.d.ts delete mode 100644 lib/types/core/types/file.d.ts delete mode 100644 lib/types/core/types/transport-request.d.ts delete mode 100644 lib/types/core/types/transport-response.d.ts delete mode 100644 lib/types/core/utils.d.ts delete mode 100644 lib/types/crypto/index.d.ts delete mode 100644 lib/types/crypto/modules/NodeCryptoModule/ICryptor.d.ts delete mode 100644 lib/types/crypto/modules/NodeCryptoModule/ILegacyCryptor.d.ts delete mode 100644 lib/types/crypto/modules/NodeCryptoModule/aesCbcCryptor.d.ts delete mode 100644 lib/types/crypto/modules/NodeCryptoModule/legacyCryptor.d.ts delete mode 100644 lib/types/crypto/modules/NodeCryptoModule/nodeCryptoModule.d.ts delete mode 100644 lib/types/crypto/modules/node.d.ts delete mode 100644 lib/types/entities/Channel.d.ts delete mode 100644 lib/types/entities/ChannelGroup.d.ts delete mode 100644 lib/types/entities/ChannelMetadata.d.ts delete mode 100644 lib/types/entities/SubscribeCapable.d.ts delete mode 100644 lib/types/entities/Subscription.d.ts delete mode 100644 lib/types/entities/SubscriptionSet.d.ts delete mode 100644 lib/types/entities/UserMetadata.d.ts delete mode 100644 lib/types/entities/commonTypes.d.ts delete mode 100644 lib/types/errors/pubnub-api-error.d.ts delete mode 100644 lib/types/errors/pubnub-error.d.ts delete mode 100644 lib/types/event-engine/core/change.d.ts delete mode 100644 lib/types/event-engine/core/dispatcher.d.ts delete mode 100644 lib/types/event-engine/core/engine.d.ts delete mode 100644 lib/types/event-engine/core/handler.d.ts delete mode 100644 lib/types/event-engine/core/index.d.ts delete mode 100644 lib/types/event-engine/core/retryPolicy.d.ts delete mode 100644 lib/types/event-engine/core/state.d.ts delete mode 100644 lib/types/event-engine/core/types.d.ts delete mode 100644 lib/types/event-engine/dispatcher.d.ts delete mode 100644 lib/types/event-engine/effects.d.ts delete mode 100644 lib/types/event-engine/events.d.ts delete mode 100644 lib/types/event-engine/index.d.ts delete mode 100644 lib/types/event-engine/presence/dispatcher.d.ts delete mode 100644 lib/types/event-engine/presence/effects.d.ts delete mode 100644 lib/types/event-engine/presence/events.d.ts delete mode 100644 lib/types/event-engine/presence/presence.d.ts delete mode 100644 lib/types/event-engine/presence/states/heartbeat_cooldown.d.ts delete mode 100644 lib/types/event-engine/presence/states/heartbeat_failed.d.ts delete mode 100644 lib/types/event-engine/presence/states/heartbeat_inactive.d.ts delete mode 100644 lib/types/event-engine/presence/states/heartbeat_reconnecting.d.ts delete mode 100644 lib/types/event-engine/presence/states/heartbeat_stopped.d.ts delete mode 100644 lib/types/event-engine/presence/states/heartbeating.d.ts delete mode 100644 lib/types/event-engine/states/handshake_failed.d.ts delete mode 100644 lib/types/event-engine/states/handshake_reconnecting.d.ts delete mode 100644 lib/types/event-engine/states/handshake_stopped.d.ts delete mode 100644 lib/types/event-engine/states/handshaking.d.ts delete mode 100644 lib/types/event-engine/states/receive_failed.d.ts delete mode 100644 lib/types/event-engine/states/receive_reconnecting.d.ts delete mode 100644 lib/types/event-engine/states/receive_stopped.d.ts delete mode 100644 lib/types/event-engine/states/receiving.d.ts delete mode 100644 lib/types/event-engine/states/unsubscribed.d.ts delete mode 100644 lib/types/file/modules/node.d.ts delete mode 100644 lib/types/file/modules/react-native.d.ts create mode 100644 lib/types/index.d.ts delete mode 100644 lib/types/models/Cursor.d.ts delete mode 100644 lib/types/node/configuration.d.ts delete mode 100644 lib/types/node/index.d.ts delete mode 100644 lib/types/react_native/configuration.d.ts delete mode 100644 lib/types/react_native/index.d.ts delete mode 100644 lib/types/transport/middleware.d.ts delete mode 100644 lib/types/transport/node-transport.d.ts delete mode 100644 lib/types/transport/web-react-native-transport.d.ts delete mode 100644 src/core/components/deduping_manager.js create mode 100644 src/core/components/deduping_manager.ts rename src/node/{ => components}/configuration.ts (90%) diff --git a/.pubnub.yml b/.pubnub.yml index 3970ec71c..057604ff3 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,26 @@ --- changelog: + - date: 2024-10-31 + version: v8.2.10 + changes: + - type: bug + text: "Fix `Actions` type definition." + - type: improvement + text: "Remove indexed signature for publish." + - type: improvement + text: "Add serializable objects to `Payload` type." + - type: improvement + text: "Aggregate generated types definitions." + - type: improvement + text: "Fix definition of type which represents message actions received from history and list of users which added action of specific type and value to the message." + - type: improvement + text: "Remove redundant indexed signature from publish message parameters type definition." + - type: improvement + text: "Extend `Payload` type definition with objects which can be serialized by `JSON.stringify` using `toJSON()` methods." + - type: improvement + text: "Aggregate multiple types definitions into single type definition type with proper type names and namespaces." + - type: improvement + text: "Add the Subscribe Event Engine and Event Listener types to the bundled types definition file." - date: 2024-10-25 version: v8.2.9 changes: @@ -1041,7 +1062,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.9' +version: '8.2.10' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1057,7 +1078,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.9.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.10.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1728,7 +1749,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.9/pubnub.8.2.9.js + location: https://github.com/pubnub/javascript/releases/download/v8.2.10/pubnub.8.2.10.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/.scripts/types-aggregate.ts b/.scripts/types-aggregate.ts new file mode 100644 index 000000000..b6f9c607f --- /dev/null +++ b/.scripts/types-aggregate.ts @@ -0,0 +1,803 @@ +import { program } from 'commander'; +import * as ts from 'typescript'; +import prettier from 'prettier'; +import * as fs from 'fs'; +import path from 'path'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +type BaseSourceFileImport = { + /** Imported type name. */ + value: string; + /** Name or path to the module from which type imported. */ + module: string; + /** Import statement. */ + statement: string; + /** Whether this is package type or not. */ + isPackageType: boolean; +}; + +/** Import created with type name and module path. */ +type NamedSourceFileImport = BaseSourceFileImport & { + /** Import type. */ + type: 'name'; +}; + +/** Import created as alias (namespace) to the `*` and module path. */ +type NamespacedSourceFileImport = BaseSourceFileImport & { + /** Import type. */ + type: 'namespace'; +}; + +/** Import created with type name, name as it imported into the code and module path. */ +type AliasedSourceFileImport = BaseSourceFileImport & { + /** Import type. */ + type: 'alias'; + /** Imported type alias name. */ + alias: string; +}; + +/** Package types imported in source file. */ +type SourceFileImport = NamedSourceFileImport | NamespacedSourceFileImport | AliasedSourceFileImport; +// endregion + +// -------------------------------------------------------- +// ---------------------- Helpers ------------------------- +// -------------------------------------------------------- +// region Helpers + +/** + * Load target project TS configuration. + * + * @param configurationPath - Path to the configuration file to load. + * + * @returns Parsed TS configuration file object. + */ +const loadTSConfiguration = (configurationPath: string) => { + const configFile = ts.readConfigFile(configurationPath, ts.sys.readFile); + + if (configFile.error) { + throw new Error(`${path.basename(configurationPath)} load error: ${configFile.error.messageText}`); + } + + return ts.parseJsonConfigFileContent(configFile.config, ts.sys, path.dirname(configurationPath)); +}; + +/** + * Normalize path of resource relative to the file where it used. + * + * @param workingDirectory - Full path to the working directory. + * @param resourcePath - Source from which another resource accessed relatively. + * @param resourceRelativePath - Path to the target resource which is relative to the source. + * + * @returns Path to the target resource which is relative to the working directory. + */ +const relativeToWorkingDirectoryPath = ( + workingDirectory: string, + resourcePath: string, + resourceRelativePath: string, +) => { + const resourceFullPath = path.resolve(path.dirname(resourcePath), resourceRelativePath); + return `.${resourceFullPath.split(workingDirectory).pop()}`; +}; + +// endregion + +/** + * Project package. + * + * Package used to aggregate definition files in the working directory. + */ +class Package { + /** Package source files with types. */ + private readonly files: SourceFile[] = []; + + /** + * Create package bundle. + * + * Create package object which contains information about types used in public interface. + * + * @param name - Project name. + * @param workingDirectory - Root folder with subfolders which represent project structure and contains types definition files. + * @param tsConfiguration - Loaded project's TS configuration + */ + constructor( + public readonly name: string, + private readonly workingDirectory: string, + private readonly tsConfiguration: ts.ParsedCommandLine, + ) { + this.processTypesInDirectory(workingDirectory); + } + + /** + * Retrieve list of type definition files identified for package. + * + * @returns List of type definition {@link SourceFile} instances. + */ + get typeSourceFiles(): SourceFile[] { + return this.files; + } + + /** + * Retrieve list of all external imports used in the project. + * + * @returns Map of imported module to the module information object. + */ + get externalImports(): Record { + const imports: Record = {}; + this.files.forEach((file) => + Object.entries(file.externalImports).forEach(([module, type]) => (imports[module] ??= type)), + ); + return imports; + } + + /** + * Retrieve source file information for file by its path. + * + * @param filePath - Path to the inside of the project. + * + * @returns SourceFile instance or `undefined` if it can't be found at specified path. + */ + sourceFileAtPath(filePath: string): SourceFile | undefined { + if (filePath.startsWith('./') || filePath.startsWith('../')) + filePath = path.resolve(this.workingDirectory, filePath); + + return this.files.find((file) => file.filePath === filePath); + } + + /** + * Process types in specified directory. + * + * @param directory - Directory inside which types and subfolder should be processed. + */ + private processTypesInDirectory(directory: string) { + if (!fs.existsSync(directory)) return; + + fs.readdirSync(directory).forEach((pathComponent) => { + const resourcePath = path.join(directory, pathComponent); + if (fs.statSync(resourcePath).isDirectory()) this.processTypesInDirectory(resourcePath); + else { + // TODO: IGNORE FILES IN A DIFFERENT WAY + if (pathComponent === 'hmac-sha256.d.ts') return; + if (!fs.existsSync(resourcePath)) return; + + // Filter out internal type definition placeholders. + const fileContent = fs.readFileSync(resourcePath, 'utf8'); + const internalModuleMatch = fileContent.match(/^\/\*\*[\s\S]*?@internal[\s\S]*?\*\//); + if (internalModuleMatch && internalModuleMatch.index !== undefined && internalModuleMatch.index === 0) return; + + this.files.push(new SourceFile(resourcePath, this.workingDirectory, this.tsConfiguration.options)); + } + }); + + // Gather type aliases. + const aliases: Record = {}; + this.files.forEach((file) => { + file.imports + .filter((typeImport) => typeImport.isPackageType && typeImport.type === 'alias') + .forEach((typeImport) => { + const { value, alias } = typeImport as AliasedSourceFileImport; + (aliases[value] ??= []).push(alias); + }); + }); + this.files.forEach((file) => { + file.types + .filter((type) => Object.keys(aliases).includes(type.name)) + .forEach((type) => aliases[type.name].forEach((alias) => type.addAlias(alias))); + }); + } +} + +/** + * Type definition file. + * + * Object contain information about types and imports declared in it. + */ +class SourceFile { + /** List of package type imports in source file */ + private readonly _imports: SourceFileImport[] = []; + private readonly _types: TypeDefinition[] = []; + + /** + * Create source file from type definition file in the package. + * + * @param filePath - Path to the type definition file which will be analyzed. + * @param workingDirectory - Root folder with subfolders which represent project structure and contains types definition files. + * @param tsCompileOptions - Package's TS parsed configuration object. + */ + constructor( + public readonly filePath: string, + private readonly workingDirectory: string, + private readonly tsCompileOptions: ts.CompilerOptions, + ) { + const source = this.tsSourceFile(); + this.processImports(source); + this.processTypes(source); + } + + /** + * Retrieve list of imported types and modules. + * + * @returns List of import description objects with details about type and source file location. + */ + get imports() { + return this._imports; + } + + /** + * Retrieve list of types imported from external dependencies. + * + * @returns List of import description objects with details about type and source file location. + */ + get externalImports() { + const imports: Record = {}; + + this._imports + .filter((importedType) => !importedType.isPackageType) + .forEach((importedType) => { + imports[importedType.value] = importedType; + }); + + return imports; + } + + /** + * Retrieve list of types declared in this source file. + * + * @returns List of pre-processed type definition object instances. + */ + get types() { + return this._types; + } + + /** + * Retrieve type definition by its name. + * + * @param typeName - Name of the type for which type definition should be found. + * + * @returns Type definition object instance or `undefined` if specified type name is not part of source file. + */ + typeByName(typeName: string) { + return this._types.find((type) => type.name === typeName); + } + + /** + * Analyze source file imports for easier types processing during type definition files merge. + * + * @param sourceFile - TypeScript SourceFile object with pre-processed type definition file content. + */ + private processImports(sourceFile: ts.SourceFile) { + const storeImport = ( + type: SourceFileImport['type'], + module: string, + statement: string, + value: string, + alias?: string, + ) => { + const isPackageType = module.startsWith('./') || module.startsWith('../'); + if (isPackageType) module = relativeToWorkingDirectoryPath(this.workingDirectory, this.filePath, module); + if (type !== 'alias') this._imports.push({ type, value, module, statement, isPackageType }); + else if (alias) this._imports.push({ type, value, module, statement, isPackageType, alias }); + else throw new Error('Alias is required for alias import'); + }; + + ts.forEachChild(sourceFile, (node) => { + if (!ts.isImportDeclaration(node)) return; + const { importClause } = node; + if (!importClause) return; + + const moduleName = node.moduleSpecifier.getText(sourceFile).replace(/['"]/g, ''); + const statement = node.getText(sourceFile); + + // Process simple named import (import type specified with default export). + if (importClause.name) storeImport('name', moduleName, statement, importClause.name.getText(sourceFile)); + + // Check whether there is named binding specified for import or not. + const { namedBindings } = importClause; + if (!namedBindings) return; + + if (ts.isNamedImports(namedBindings)) { + namedBindings.elements.forEach((element) => { + const alias = element.name.getText(sourceFile); + const name = element.propertyName ? element.propertyName.getText(sourceFile) : alias; + if (name === alias) storeImport('name', moduleName, statement, name); + else storeImport('alias', moduleName, statement, name, alias); + }); + } else if (ts.isNamespaceImport(namedBindings) && namedBindings.name) { + storeImport('namespace', moduleName, statement, namedBindings.name.getText(sourceFile)); + } + }); + } + + /** + * Analyze source file types for easier types processing during type definition files merge. + * + * @param sourceFile - TypeScript SourceFile object with pre-processed type definition file content. + */ + private processTypes(sourceFile: ts.SourceFile) { + ts.forEachChild(sourceFile, (node) => { + if (!ts.isDeclarationStatement(node)) return; + if ( + !ts.isClassDeclaration(node) && + !ts.isInterfaceDeclaration(node) && + !ts.isTypeAliasDeclaration(node) && + !ts.isEnumDeclaration(node) + ) + return; + if (!node.name) return; + + // Stringify node type. + let type: TypeDefinition['type'] = 'type'; + if (ts.isClassDeclaration(node)) type = 'class'; + else if (ts.isInterfaceDeclaration(node)) type = 'interface'; + else if (ts.isEnumDeclaration(node)) type = 'enum'; + + // Extract type documentation. + const jsDocComments = ts.getJSDocCommentsAndTags(node); + const documentation = jsDocComments.map((comment) => comment.getText(node.getSourceFile())).join('\n'); + this._types.push( + new TypeDefinition( + node.name.getText(sourceFile), + type, + this.tsSourceFile(`${documentation}\n${node.getText(sourceFile)}`), + ), + ); + }); + } + + /** + * Create TypeScript source file with same path as instance but potentially different content (if passed). + * + * @param content - Content which should be used for source file instance instead of current file content. + * @private + */ + private tsSourceFile(content?: string) { + content ??= fs.readFileSync(this.filePath, 'utf8'); + + // Ensure that `default export` will be carried with type definition to the resulting definition type. + if (content && /^export default\s[a-zA-Z]+;/gm.test(content)) { + const matchType = /^export default\s([a-zA-Z]+);/gm.exec(content); + if (matchType && matchType.length > 0) { + const replaceRegexp = new RegExp(`^((declare\\s)?(enum|class|type|interface)\\s${matchType[1]})`, 'gm'); + content = content.replace(replaceRegexp, `export $1`); + } + } + + return ts.createSourceFile(this.filePath, content, this.tsCompileOptions.target ?? ts.ScriptTarget.ES2015, true); + } +} + +/** + * Type definition from the source file. + */ +class TypeDefinition { + public readonly superclass?: string; + /** List of aliases under which type has been imported by other types. */ + private readonly aliases: string[] = []; + + constructor( + public readonly name: string, + public type: 'class' | 'interface' | 'type' | 'enum', + private readonly sourceFile: ts.SourceFile, + ) { + if (type === 'class') { + const match = sourceFile.getText(this.sourceFile).match(/class PubNub extends ([a-zA-Z]+)[\s|<]/) ?? []; + if (match.length > 1) this.superclass = match[1]; + } + } + + get filePath() { + return this.sourceFile.fileName; + } + + addAlias(alias: string) { + if (!this.aliases.includes(alias)) this.aliases.push(alias); + } + + toString(packageTypes: string[], namespace?: string): string { + const isPackageType = (type: string) => { + if (type.indexOf('.') === -1) return packageTypes.includes(type); + else return packageTypes.includes(type.split('.').pop()!); + }; + + const typeReferenceTransformer = (context: ts.TransformationContext) => { + const visit: ts.Visitor = (node) => { + let replacement: ts.TypeReferenceNode | ts.ExpressionWithTypeArguments | undefined; + + if (namespace && ts.isTypeReferenceNode(node) && isPackageType(node.typeName.getText(this.sourceFile))) { + const typeName = node.typeName.getText(this.sourceFile); + if (namespace) { + const reference = ts.factory.createQualifiedName(ts.factory.createIdentifier(namespace), typeName); + + replacement = ts.factory.createTypeReferenceNode( + reference, + node.typeArguments + ?.map((typeArg) => ts.visitNode(typeArg, visit)) + .filter((typeArg): typeArg is ts.TypeNode => typeArg !== undefined), + ); + } + } + + if (ts.isTypeQueryNode(node)) { + if (namespace) { + const qualifiedName = ts.factory.createQualifiedName( + ts.factory.createIdentifier(namespace), + node.exprName as ts.Identifier, + ); + + return ts.factory.createTypeQueryNode(qualifiedName); + } + } + + // Checking whether processing superclass information or not. + if (node.parent && ts.isHeritageClause(node.parent) && ts.isExpressionWithTypeArguments(node)) { + const typeName = node.expression.getText(this.sourceFile); + if (namespace) { + let reference = node.expression; + if (this.superclass !== typeName) { + reference = ts.factory.createPropertyAccessExpression(ts.factory.createIdentifier(namespace), typeName); + } + + replacement = ts.factory.createExpressionWithTypeArguments( + reference, + node.typeArguments + ?.map((typeArg) => ts.visitNode(typeArg, visit)) + .filter((typeArg): typeArg is ts.TypeNode => typeArg !== undefined), + ); + } + } + + return replacement ?? ts.visitEachChild(node, visit, context); + }; + + return (node: T): T => ts.visitNode(node, visit) as T; + }; + + const aliasedTypeStrings: string[] = []; + if (this.aliases.length > 0) { + const matches = this.sourceFile.getText(this.sourceFile).match(/^(\s*(export\s+)?(declare\s+)?(type|class)\s)/gm); + if (!matches) throw new Error(`Unable to match prefix for '${this.name}' ${this.type}`); + + this.aliases.forEach((alias) => { + if (this.type === 'class' || this.type === 'interface' || this.type === 'enum') + aliasedTypeStrings.push(`/** Re-export aliased type. */\nexport {${this.name} as ${alias}};\n`); + else aliasedTypeStrings.push(`${matches[0]}${alias} = ${this.name};`); + }); + } + + const transformed = ts.transform(this.sourceFile, [typeReferenceTransformer]); + const formatted = ts.createPrinter().printFile(transformed.transformed[0] as ts.SourceFile); + return aliasedTypeStrings.length === 0 ? formatted : `${formatted}\n${aliasedTypeStrings.join('\n')}`; + } +} + +class PackageTypesDefinition { + /** Types grouped by namespaces. */ + private readonly namespaces: Record = {}; + /** List of type names which is defined by package. */ + private readonly packageTypes: string[] = []; + /** List of type names which already has been added to the output. */ + private writtenTypes: string[] = []; + private writingPackageNamespace: boolean = false; + + /** + * Create package types definition. + * + * Responsible for merged types definition generation. + * + * @param projectPackage - Project package object with types information. + * @param workingDirectory - Root folder with subfolders which represent project structure and contains types definition files. + * @param entryPoint - Path to the source file which is package's entry point and source of the public interface. + */ + constructor( + private readonly projectPackage: Package, + private readonly workingDirectory: string, + private readonly entryPoint: string, + ) {} + + writeToFile(filePath: string) { + this.writingPackageNamespace = false; + const resultContent: string[] = []; + this.writtenTypes = []; + + this.associateTypesWithNamespaces(); + this.addExternalImports(resultContent); + + // Retrieve reference to the entry point source file. + const entryPoint = this.projectPackage.sourceFileAtPath(this.entryPoint); + if (!entryPoint) throw new Error(`Can't load type for entry point at path: ${this.entryPoint}`); + + // Identify and add root types. + entryPoint.types.forEach((type) => { + this.addTypeDefinition(type, resultContent, this.projectPackage.name); + + if (type.type !== 'class' || !type.superclass) return; + + const superClassImport = entryPoint.imports.find( + (importType) => importType.isPackageType && importType.value === type.superclass, + ); + if (!superClassImport) return; + + const sourceFile = this.sourceFileForModule(superClassImport.module); + if (!sourceFile) return; + + const superclassType = sourceFile.typeByName(superClassImport.value); + if (superclassType) this.addTypeDefinition(superclassType, resultContent, this.projectPackage.name); + }); + + this.writingPackageNamespace = true; + resultContent.push(`declare namespace ${this.projectPackage.name} {`); + + this.typeSourceFiles + .filter((sourceFile) => sourceFile !== entryPoint) + .forEach((sourceFile) => { + sourceFile.types.forEach((type) => { + this.addTypeDefinition(type, resultContent); + }); + }); + + for (const namespace in this.namespaces) { + resultContent.push(`export namespace ${namespace} {`); + this.namespaces[namespace].forEach((type) => { + // Try to retrieve proper source file for imported module. + const sourceFile = this.sourceFileForModule(type.file); + if (!sourceFile) return; + + const typeDefinition = sourceFile.typeByName(type.type); + if (typeDefinition) this.addTypeDefinition(typeDefinition, resultContent, undefined, true); + // if (typeDefinition) this.addTypeDefinition(typeDefinition, resultContent, namespace, true); + }); + resultContent.push(`}\n\n`); + } + + resultContent.push(`}\n\nexport = ${this.projectPackage.name}`); + + prettier + .format(resultContent.join('\n'), { + parser: 'typescript', + semi: true, + printWidth: 120, + singleQuote: true, + trailingComma: 'all', + }) + .then((result) => { + fs.writeFileSync(filePath, result, 'utf-8'); + }); + } + + /** + * Retrieve list of type source files which is specific to the entry point. + */ + private get typeSourceFiles() { + const files: SourceFile[] = []; + const entryPoint = this.sourceFileForModule(this.entryPoint); + if (!entryPoint) throw new Error(`Can't load type for entry point at path: ${this.entryPoint}`); + + const flattenImportedTypes = (sourceFile: SourceFile) => { + sourceFile.imports + .filter((importType) => importType.isPackageType) + .forEach((type) => { + const importedTypeSourceFile = this.sourceFileForModule(type.module); + if (!importedTypeSourceFile) { + console.warn( + `Source file for ${type.module} is missing. File can be ignored as internal, but import is still there.`, + ); + return; + } + + if (!files.includes(importedTypeSourceFile)) { + files.push(importedTypeSourceFile); + flattenImportedTypes(importedTypeSourceFile); + } + }); + }; + flattenImportedTypes(entryPoint); + + return files; + } + + /** + * Aggregate types into corresponding namespaces. + * + * Some types can be imported and used through namespace import syntax and this function allows to bind types to the corresponding namespace. + * + * @returns Record where list of types (name and file path) stored under namespace name as key. + */ + private associateTypesWithNamespaces() { + const project = this.projectPackage; + const namespacedTypes: string[] = []; + + project.typeSourceFiles.forEach((file) => { + file.types.forEach((type) => !this.packageTypes.includes(type.name) && this.packageTypes.push(type.name)); + }); + + project.typeSourceFiles.forEach((file) => { + file.imports + .filter((fileImport) => fileImport.isPackageType) + .forEach((fileImport) => { + if (fileImport.type === 'namespace') { + if (namespacedTypes.includes(fileImport.module)) return; + + // Try to retrieve proper source file for imported module. + const sourceFile = this.sourceFileForModule(fileImport.module); + if (!sourceFile) return; + + namespacedTypes.push(fileImport.module); + sourceFile.types.forEach((sourceFileType) => { + this.namespaces[fileImport.value] = this.namespaces[fileImport.value] ?? []; + this.namespaces[fileImport.value].push({ type: sourceFileType.name, file: fileImport.module }); + }); + } else if (namespacedTypes.includes(fileImport.module)) { + throw new Error(`${fileImport.module} already added as namespace and can't be used separately.`); + } + }); + }); + } + + /** + * Adding external imports required for the package. + * + * @param result - Types definition output lines. + */ + private addExternalImports(result: string[]) { + Object.entries(this.projectPackage.externalImports).forEach(([_, typeImport]) => { + if (!result.includes(typeImport.statement)) result.push(typeImport.statement); + }); + + if (result.length > 1) result.push('\n\n'); + } + + private addPackageImports(imports: SourceFileImport[], result: string[]) { + const processedSourceFiles: SourceFile[] = []; + + imports + .filter((fileImport) => fileImport.isPackageType) + .forEach((type) => { + // Try to retrieve proper source file for imported module. + const sourceFile = this.sourceFileForModule(type.module); + if (!sourceFile) return; + + const typeDefinition = sourceFile.typeByName(type.value); + if (typeDefinition) this.addTypeDefinition(typeDefinition, result); + processedSourceFiles.push(sourceFile); + }); + + processedSourceFiles.forEach((sourceFile) => this.addPackageImports(sourceFile.imports, result)); + } + + private addTypeDefinition( + typeDefinition: TypeDefinition, + result: string[], + namespace?: string, + skipNamespaceCheck: boolean = false, + ) { + const typesCacheId = `${typeDefinition.name}-${typeDefinition.filePath}`; + // Check whether type already has been added to the output or not. + if (this.writtenTypes.includes(typesCacheId)) return; + // Check whether namespace member has been added without namespace name. + if (!skipNamespaceCheck && this.isNamespaceMember(typeDefinition)) return; + + let definition = typeDefinition.toString(this.packageTypes, namespace); + + if (this.writingPackageNamespace) { + definition = definition.replace(/\bexport\s+(default\s+)?class\s+/gm, `export class `); + definition = definition.replace(/\bdeclare\s+class\s+/gm, `class `); + definition = definition.replace(/\bexport\s+declare\s+enum\s+/gm, `export enum `); + definition = definition.replace(/\bexport\s+declare\s+abstract\s+class\s+/gm, `export abstract class `); + } else definition = definition.replace(/\bexport\s+declare/g, 'declare'); + + result.push(definition); + + this.writtenTypes.push(typesCacheId); + } + + /** + * Retrieve module source file. + * + * @param modulePath - Relative path to the module (relative to the working directory). + */ + private sourceFileForModule(modulePath: string) { + const project = this.projectPackage; + + // Try to retrieve proper source file for imported module. + let sourceFile = project.sourceFileAtPath(modulePath); + if (!sourceFile && path.extname(modulePath).length === 0) { + sourceFile = project.sourceFileAtPath(`${modulePath}.d.ts`); + if (!sourceFile) { + let updatedPath = path.join(modulePath, 'index.d.ts'); + if ((modulePath.startsWith('./') || modulePath.startsWith('../')) && !updatedPath.startsWith('.')) + updatedPath = `./${updatedPath}`; + sourceFile = project.sourceFileAtPath(updatedPath); + } + } + + if (!sourceFile) { + console.warn( + `Source file for ${modulePath} is missing. File can be ignored as internal, but import is still there.`, + ); + } + + return sourceFile; + } + + /** + * Check whether specified type is member of any known namespaces. + * + * @param typeDefinition - Type definition which should be checked. + * @returns `true` in case if type has been associated with one of the namespaces. + */ + private isNamespaceMember(typeDefinition: TypeDefinition) { + if (Object.keys(this.namespaces).length === 0) return false; + + // Normalize type source file path. + const extensionMatch = new RegExp(`(.d.ts|${path.extname(typeDefinition.filePath)})$`); + let typeFilePath = typeDefinition.filePath.replace(extensionMatch, ''); + if (!typeFilePath.startsWith('./') && !typeFilePath.startsWith('../')) + typeFilePath = `.${typeFilePath.split(this.workingDirectory).pop()!}`; + + for (const name in this.namespaces) { + const namespace = this.namespaces[name]; + if (namespace.find((type) => type.type === typeDefinition.name && type.file === typeFilePath)) return true; + } + + return false; + } +} + +export function syntaxKindToName(kind: ts.SyntaxKind) { + return (ts).SyntaxKind[kind]; +} + +// -------------------------------------------------------- +// -------------------- Configuration ---------------------- +// -------------------------------------------------------- +// region Configuration + +// Parse script launch arguments +const options = program + .option('--package ', 'Name of the package to aggregate types for.') + .option('--working-dir ', 'Path to the processed definition type files root directory.') + .option('--input ', 'Path to the main type definition file.') + .option('--output ', 'Path to the folder or filepath where aggregated type definition file should be saved.') + .option('--ts-config ', "Path to the project's tsconfig.json file.") + .parse() + .opts(); + +if (options.package === undefined || options.package.length === 0) throw new Error('Package file is missing.'); +if (options.workingDir === undefined || options.workingDir.length === 0) + throw new Error('Working directory is missing.'); +if (options.input === undefined || options.input.length === 0) throw new Error('Entry point file is missing.'); +if (options.output === undefined || options.output.length === 0) throw new Error('Output file is missing.'); +if (options.tsConfig === undefined || options.tsConfig.length === 0) throw new Error('tsconfig.json file is missing.'); + +const fullPathFromRelative = (relativePath: string) => + /^(.\/|..\/)/.test(relativePath) ? path.resolve(process.cwd(), relativePath) : relativePath; + +// Processing input arguments. +const packageName = options.package; +const workingDir = fullPathFromRelative(options.workingDir); +const tsConfigFilePath = fullPathFromRelative(options.tsConfig); +const inputFilePath = fullPathFromRelative(options.input); +let outputFilePath = fullPathFromRelative(options.output); +if (path.extname(outputFilePath).length === 0) + outputFilePath = path.resolve(outputFilePath, inputFilePath.split('/').pop()!); + +// endregion + +// -------------------------------------------------------- +// --------------------- Processing ----------------------- +// -------------------------------------------------------- + +const projectPackage = new Package(packageName, workingDir, loadTSConfiguration(tsConfigFilePath)); +const entryPointSourceFile = projectPackage.sourceFileAtPath(inputFilePath); +if (!entryPointSourceFile) throw new Error('Entry point source file not found.'); + +// Files loaded into the project. Clean up working directory. +fs.rmSync(workingDir, { recursive: true, force: true }); +fs.mkdirSync(workingDir); + +const definition = new PackageTypesDefinition(projectPackage, workingDir, inputFilePath); +definition.writeToFile(outputFilePath); diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dfa98a54..fd6e4f017 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,21 @@ +## v8.2.10 +October 31 2024 + +#### Fixed +- Fix `Actions` type definition. + +#### Modified +- Remove indexed signature for publish. +- Add serializable objects to `Payload` type. +- Aggregate generated types definitions. +- Fix definition of type which represents message actions received from history and list of users which added action of specific type and value to the message. Fixed the following issues reported by [@yo1dog](https://github.com/yo1dog): [#407](https://github.com/pubnub/javascript/issues/407). +- Remove redundant indexed signature from publish message parameters type definition. Fixed the following issues reported by [@yo1dog](https://github.com/yo1dog): [#413](https://github.com/pubnub/javascript/issues/413). +- Extend `Payload` type definition with objects which can be serialized by `JSON.stringify` using `toJSON()` methods. Fixed the following issues reported by [@yo1dog](https://github.com/yo1dog): [#412](https://github.com/pubnub/javascript/issues/412). +- Aggregate multiple types definitions into single type definition type with proper type names and namespaces. Fixed + the following issues reported by [@Tallyb](https://github.com/Tallyb) and [@yo1dog](https://github.com/yo1dog): [#405](https://github.com/pubnub/javascript/issues/405) and [#409](https://github.com/pubnub/javascript/issues/409) and [#410](https://github.com/pubnub/javascript/issues/410). +- Add the Subscribe Event Engine and Event Listener types to the bundled types definition file. Fixed the following + issues reported by [@roman-rr](https://github.com/roman-rr): [#377](https://github.com/pubnub/javascript/issues/377). + ## v8.2.9 October 25 2024 diff --git a/README.md b/README.md index 1d546fa73..06e26471e 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.9.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.9.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.10.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.10.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 7cd3b7f5a..b1a1ebfc0 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -410,9 +410,7 @@ var obj = { encode: encode, decode: decode }; - if (typeof undefined$1 === "function" && undefined$1.amd) - undefined$1("cbor/cbor", obj); - else if (module.exports) + if (module.exports) module.exports = obj; else if (!global.CBOR) global.CBOR = obj; @@ -437,7 +435,7 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ - /* global Reflect, Promise, SuppressedError, Symbol */ + /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function __rest(s, e) { @@ -514,6 +512,8 @@ // region Helpers /** * Retrieve list of module's cryptors. + * + * @internal */ getAllCryptors() { return [this.defaultCryptor, ...this.cryptors]; @@ -521,10 +521,14 @@ } /** * `String` to {@link ArrayBuffer} response decoder. + * + * @internal */ AbstractCryptoModule.encoder = new TextEncoder(); /** * {@link ArrayBuffer} to {@link string} decoder. + * + * @internal */ AbstractCryptoModule.decoder = new TextDecoder(); @@ -695,6 +699,11 @@ */ PubNubFile.supportsFileUri = false; + /** + * Base64 support module. + * + * @internal + */ const BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; /** * Decode a Base64 encoded string. @@ -874,7 +883,25 @@ })(StatusCategory || (StatusCategory = {})); var StatusCategory$1 = StatusCategory; + /** + * PubNub operation error module. + */ + /** + * PubNub operation error. + * + * When an operation can't be performed or there is an error from the server, this object will be returned. + */ class PubNubError extends Error { + /** + * Create PubNub operation error. + * + * @param message - Message with details about why operation failed. + * @param [status] - Additional information about performed operation. + * + * @returns Configured and ready to use PubNub operation error. + * + * @internal + */ constructor(message, status) { super(message); this.status = status; @@ -883,15 +910,40 @@ Object.setPrototypeOf(this, new.target.prototype); } } + /** + * Create error status object. + * + * @param errorPayload - Additional information which should be attached to the error status object. + * + * @returns Error status object. + * + * @internal + */ function createError(errorPayload) { var _a; (_a = errorPayload.statusCode) !== null && _a !== void 0 ? _a : (errorPayload.statusCode = 0); return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: StatusCategory$1.PNValidationErrorCategory, error: true }); } + /** + * Create operation arguments validation error status object. + * + * @param message - Information about failed validation requirement. + * @param [statusCode] - Operation HTTP status code. + * + * @returns Operation validation error status object. + * + * @internal + */ function createValidationError(message, statusCode) { - return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {}))); + return createError(Object.assign({ message }, ({}))); } + /** + * CryptoJS implementation. + * + * @internal + */ + /*eslint-disable */ /* @@ -1935,6 +1987,8 @@ /** * Legacy cryptography module. + * + * @internal */ /** * Convert bytes array to words array. @@ -1942,6 +1996,8 @@ * @param b - Bytes array (buffer) which should be converted. * * @returns Word sized array. + * + * @internal */ /* eslint-disable @typescript-eslint/no-explicit-any */ function bufferToWordArray(b) { @@ -1953,6 +2009,11 @@ // @ts-expect-error Bundled library without types. return CryptoJS$1.lib.WordArray.create(wa, b.length); } + /** + * Legacy cryptography module for files and signature. + * + * @internal + */ class Crypto { constructor(configuration) { this.configuration = configuration; @@ -2201,18 +2262,16 @@ } } - /* global crypto */ /** * Legacy browser cryptography module. + * + * @internal */ - function concatArrayBuffer(ab1, ab2) { - const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); - tmp.set(new Uint8Array(ab1), 0); - tmp.set(new Uint8Array(ab2), ab1.byteLength); - return tmp.buffer; - } + /* global crypto */ /** * Legacy cryptography implementation for browser-based {@link PubNub} client. + * + * @internal */ class WebCryptography { // -------------------------------------------------------- @@ -2248,7 +2307,7 @@ encryptArrayBuffer(key, buffer) { return __awaiter(this, void 0, void 0, function* () { const abIv = crypto.getRandomValues(new Uint8Array(16)); - return concatArrayBuffer(abIv.buffer, yield crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, buffer)); + return this.concatArrayBuffer(abIv.buffer, yield crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, buffer)); }); } /** @@ -2264,7 +2323,7 @@ const abIv = crypto.getRandomValues(new Uint8Array(16)); const abPlaintext = WebCryptography.encoder.encode(text).buffer; const abPayload = yield crypto.subtle.encrypt({ name: 'AES-CBC', iv: abIv }, key, abPlaintext); - const ciphertext = concatArrayBuffer(abIv.buffer, abPayload); + const ciphertext = this.concatArrayBuffer(abIv.buffer, abPayload); return WebCryptography.decoder.decode(ciphertext); }); } @@ -2397,6 +2456,20 @@ return crypto.subtle.importKey('raw', abKey, 'AES-CBC', true, ['encrypt', 'decrypt']); }); } + /** + * Join two `ArrayBuffer`s. + * + * @param ab1 - `ArrayBuffer` to which other buffer should be appended. + * @param ab2 - `ArrayBuffer` which should appended to the other buffer. + * + * @returns Buffer which starts with `ab1` elements and appended `ab2`. + */ + concatArrayBuffer(ab1, ab2) { + const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); + tmp.set(new Uint8Array(ab1), 0); + tmp.set(new Uint8Array(ab2), ab1.byteLength); + return tmp.buffer; + } } /** * Random initialization vector size. @@ -2785,9 +2858,13 @@ /** * REST API endpoint use error module. + * + * @internal */ /** * PubNub REST API call error. + * + * @internal */ class PubNubAPIError extends Error { /** @@ -2978,6 +3055,8 @@ * * Middleware optimize subscription feature requests utilizing `Subscription Worker` if available and not disabled * by user. + * + * @internal */ // endregion /** @@ -3200,6 +3279,11 @@ } } + /** + * PubNub package utilities module. + * + * @internal + */ /** * Percent-encode input string. * @@ -3208,6 +3292,8 @@ * @param input - Source string or number for encoding. * * @returns Percent-encoded string. + * + * @internal */ const encodeString = (input) => { return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); @@ -3220,11 +3306,16 @@ * @param [defaultString] - String which should be used in case if {@link names} is empty. * * @returns String which contains encoded names joined by non-encoded `,`. + * + * @internal */ const encodeNames = (names, defaultString) => { const encodedNames = names.map((name) => encodeString(name)); - return encodedNames.length ? encodedNames.join(',') : defaultString !== null && defaultString !== void 0 ? defaultString : ''; + return encodedNames.length ? encodedNames.join(',') : (defaultString !== null && defaultString !== void 0 ? defaultString : ''); }; + /** + * @internal + */ const removeSingleOccurrence = (source, elementsToRemove) => { const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); return source.filter((e) => { @@ -3235,6 +3326,9 @@ return true; }); }; + /** + * @internal + */ const findUniqueCommonElements = (a, b) => { return [...a].filter((value) => b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value)); }; @@ -3244,6 +3338,8 @@ * @param query - Key / value pairs of the request query parameters. * * @returns Stringified query key / value pairs. + * + * @internal */ const queryStringFromObject = (query) => { return Object.keys(query) @@ -3258,11 +3354,23 @@ /** * Common browser and React Native Transport provider module. + * + * @internal */ /** * Class representing a `fetch`-based browser and React Native transport provider. + * + * @internal */ class WebReactNativeTransport { + /** + * Create and configure transport provider for Web and Rect environments. + * + * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. + * @param logVerbosity - Whether verbose logs should be printed or not. + * + * @internal + */ constructor(keepAlive = false, logVerbosity) { this.keepAlive = keepAlive; this.logVerbosity = logVerbosity; @@ -3294,7 +3402,10 @@ reject(new Error('Request timeout')); }, req.timeout * 1000); }); - return Promise.race([fetch(request, { signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal }), requestTimeout]) + return Promise.race([ + fetch(request, { signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, credentials: 'omit', cache: 'no-cache' }), + requestTimeout, + ]) .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) .then((response) => { const responseBody = response[1].byteLength > 0 ? response[1] : undefined; @@ -3329,6 +3440,8 @@ * @param req - The {@link TransportRequest} object containing request information. * * @returns Request object generated from the {@link TransportRequest} object. + * + * @internal */ requestFromTransportRequest(req) { return __awaiter(this, void 0, void 0, function* () { @@ -3375,6 +3488,8 @@ * @param request - Platform-specific * @param [elapsed] - How many seconds passed since request processing started. * @param [body] - Service response (if available). + * + * @internal */ logRequestProcessProgress(request, elapsed, body) { if (!this.logVerbosity) @@ -3396,9 +3511,16 @@ } /** * Service {@link ArrayBuffer} response decoder. + * + * @internal */ WebReactNativeTransport.decoder = new TextDecoder(); + /** + * CBOR support module. + * + * @internal + */ /** * Re-map CBOR object keys from potentially C buffer strings to actual strings. * @@ -3569,7 +3691,7 @@ let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE; let fileUploadPublishRetryLimit = FILE_PUBLISH_RETRY_LIMIT; let dedupeOnSubscribe = DEDUPE_ON_SUBSCRIBE; - const maximumCacheSize = DEDUPE_CACHE_SIZE; + let maximumCacheSize = DEDUPE_CACHE_SIZE; let useRequestId = USE_REQUEST_ID; // @ts-expect-error Not documented legacy configuration options. if (configurationCopy.dedupeOnSubscribe !== undefined && typeof configurationCopy.dedupeOnSubscribe === 'boolean') { @@ -3577,6 +3699,11 @@ dedupeOnSubscribe = configurationCopy.dedupeOnSubscribe; } // @ts-expect-error Not documented legacy configuration options. + if (configurationCopy.maximumCacheSize !== undefined && typeof configurationCopy.maximumCacheSize === 'number') { + // @ts-expect-error Not documented legacy configuration options. + maximumCacheSize = configurationCopy.maximumCacheSize; + } + // @ts-expect-error Not documented legacy configuration options. if (configurationCopy.useRequestId !== undefined && typeof configurationCopy.useRequestId === 'boolean') { // @ts-expect-error Not documented legacy configuration options. useRequestId = configurationCopy.useRequestId; @@ -3698,6 +3825,12 @@ var uuidExports = uuid.exports; var uuidGenerator$1 = /*@__PURE__*/getDefaultExportFromCjs(uuidExports); + /** + * Random identifier generator helper module. + * + * @internal + */ + /** @internal */ var uuidGenerator = { createUUID() { if (uuidGenerator$1.uuid) { @@ -3710,6 +3843,8 @@ /** * {@link PubNub} client configuration module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -3725,7 +3860,7 @@ * Create {@link PubNub} client private configuration object. * * @param base - User- and platform-provided configuration. - * @param setupCryptoModule - Platform-provided {@link CryptoModule} configuration block. + * @param setupCryptoModule - Platform-provided {@link ICryptoModule} configuration block. * * @returns `PubNub` client private configuration. * @@ -3813,7 +3948,7 @@ return base.PubNubFile; }, get version() { - return '8.2.9'; + return '8.2.10'; }, getVersion() { return this.version; @@ -3865,6 +4000,8 @@ /** * PubNub Access Token Manager module. + * + * @internal */ // endregion /** @@ -4030,6 +4167,11 @@ TransportMethod["LOCAL"] = "LOCAL"; })(TransportMethod || (TransportMethod = {})); + /** + * Common PubNub Network Provider middleware module. + * + * @internal + */ /** * Request signature generator. * @@ -4089,6 +4231,11 @@ } } RequestSignature.textDecoder = new TextDecoder('utf-8'); + /** + * Common PubNub Network Provider middleware. + * + * @internal + */ class PubNubMiddleware { constructor(configuration) { this.configuration = configuration; @@ -4357,6 +4504,8 @@ * Subscription reconnection-manager. * * **Note:** Reconnection manger rely on legacy time-based availability check. + * + * @internal */ /** * Network "discovery" manager. @@ -4402,59 +4551,85 @@ } } - /* */ - - const hashCode = (payload) => { - let hash = 0; - if (payload.length === 0) return hash; - for (let i = 0; i < payload.length; i += 1) { - const character = payload.charCodeAt(i); - hash = (hash << 5) - hash + character; // eslint-disable-line - hash = hash & hash; // eslint-disable-line - } - return hash; - }; - + /** + * Messages de-duplication manager module. + * + * @internal + */ /** * Real-time events deduplication manager. * * @internal */ class DedupingManager { - _config; - - hashHistory; - - constructor({ config }) { - this.hashHistory = []; - this._config = config; - } - - getKey(message) { - const hashedPayload = hashCode(JSON.stringify(message.message)).toString(); - const timetoken = message.timetoken; - return `${timetoken}-${hashedPayload}`; - } - - isDuplicate(message) { - return this.hashHistory.includes(this.getKey(message)); - } - - addEntry(message) { - if (this.hashHistory.length >= this._config.maximumCacheSize) { - this.hashHistory.shift(); + /** + * Create and configure real-time events de-duplication manager. + * + * @param config - PubNub client configuration object. + */ + constructor({ maximumCacheSize }) { + this.maximumCacheSize = maximumCacheSize; + this.hashHistory = []; + } + /** + * Compute unique real-time event payload key. + * + * @param message - Received real-time event payload for which unique key should be computed. + * @returns Unique real-time event payload key in messages cache. + */ + getKey(message) { + var _a; + return `${message.timetoken}-${this.hashCode(JSON.stringify((_a = message.message) !== null && _a !== void 0 ? _a : '')).toString()}`; + } + /** + * Check whether there is similar message already received or not. + * + * @param message - Received real-time event payload which should be checked for duplicates. + * @returns `true` in case if similar payload already has been received before. + */ + isDuplicate(message) { + return this.hashHistory.includes(this.getKey(message)); + } + /** + * Store received message to be used later for duplicate detection. + * + * @param message - Received real-time event payload. + */ + addEntry(message) { + if (this.hashHistory.length >= this.maximumCacheSize) { + this.hashHistory.shift(); + } + this.hashHistory.push(this.getKey(message)); + } + /** + * Clean up cached messages. + */ + clearHistory() { + this.hashHistory = []; + } + /** + * Compute message hash sum. + * + * @param payload - Received payload for which hash sum should be computed. + * @returns {number} - Resulting hash sum. + */ + hashCode(payload) { + let hash = 0; + if (payload.length === 0) + return hash; + for (let i = 0; i < payload.length; i += 1) { + const character = payload.charCodeAt(i); + hash = (hash << 5) - hash + character; // eslint-disable-line + hash = hash & hash; // eslint-disable-line + } + return hash; } - - this.hashHistory.push(this.getKey(message)); - } - - clearHistory() { - this.hashHistory = []; - } } /** * Subscription manager module. + * + * @internal */ /** * Subscription loop manager. @@ -4470,7 +4645,7 @@ this.heartbeatCall = heartbeatCall; this.leaveCall = leaveCall; this.reconnectionManager = new ReconnectionManager(time); - this.dedupingManager = new DedupingManager({ config: this.configuration }); + this.dedupingManager = new DedupingManager(this.configuration); this.heartbeatChannelGroups = {}; this.heartbeatChannels = {}; this.presenceChannelGroups = {}; @@ -4724,7 +4899,7 @@ } try { messages.forEach((message) => { - if (dedupeOnSubscribe) { + if (dedupeOnSubscribe && 'message' in message.data && 'timetoken' in message.data) { if (this.dedupingManager.isDuplicate(message.data)) return; this.dedupingManager.addEntry(message.data); @@ -4840,6 +5015,15 @@ * Base notification payload object. */ class BaseNotificationPayload { + /** + * Base notification provider payload object. + * + * @internal + * + * @param payload - Object which contains vendor-specific preformatted push notification payload. + * @param title - Notification main title. + * @param body - Notification body (main messages). + */ constructor(payload, title, body) { this._payload = payload; this.setDefaultPayloadStructure(); @@ -4896,11 +5080,15 @@ } /** * Platform-specific structure initialization. + * + * @internal */ setDefaultPayloadStructure() { } /** * Translate data object into PubNub push notification payload object. * + * @internal + * * @returns Preformatted push notification payload. */ toObject() { @@ -4915,10 +5103,14 @@ super(...arguments); /** * Type of push notification service for which payload will be created. + * + * @internal */ this._apnsPushType = 'apns'; /** * Whether resulting payload should trigger silent notification or not. + * + * @internal */ this._isSilent = false; } @@ -5048,9 +5240,21 @@ set silent(value) { this._isSilent = value; } + /** + * Setup push notification payload default content. + * + * @internal + */ setDefaultPayloadStructure() { this.payload.aps = { alert: {} }; } + /** + * Translate data object into PubNub push notification payload object. + * + * @internal + * + * @returns Preformatted push notification payload. + */ toObject() { const payload = Object.assign({}, this.payload); const { aps } = payload; @@ -5080,6 +5284,8 @@ /** * Create PubNub push notification service APNS2 configuration information object. * + * @internal + * * @param configuration - Source user-provided APNS2 configuration. * * @returns Preformatted for PubNub service APNS2 configuration information. @@ -5102,6 +5308,8 @@ /** * Create PubNub push notification service APNS2 target information object. * + * @internal + * * @param target - Source user-provided data. * * @returns Preformatted for PubNub service APNS2 target information. @@ -5117,7 +5325,7 @@ } } /** - * Message payload for Firebase Clouse Messaging service. + * Message payload for Firebase Cloud Messaging service. */ class FCMNotificationPayload extends BaseNotificationPayload { get payload() { @@ -5215,9 +5423,19 @@ this.payload.notification.icon = value; this._icon = value; } + /** + * Retrieve notifications grouping tag. + * + * @returns Notifications grouping tag. + */ get tag() { return this._tag; } + /** + * Update notifications grouping tag. + * + * @param value - String which will be used to group similar notifications in notification center. + */ set tag(value) { if (!value || !value.length) return; @@ -5234,10 +5452,22 @@ set silent(value) { this._isSilent = value; } + /** + * Setup push notification payload default content. + * + * @internal + */ setDefaultPayloadStructure() { this.payload.notification = {}; this.payload.data = {}; } + /** + * Translate data object into PubNub push notification payload object. + * + * @internal + * + * @returns Preformatted push notification payload. + */ toObject() { let data = Object.assign({}, this.payload.data); let notification = null; @@ -5259,6 +5489,14 @@ } } class NotificationsPayload { + /** + * Create push notification payload holder. + * + * @internal + * + * @param title - String which will be shown at the top of the notification (below app name). + * @param body - String with message which should be shown when user will check notification. + */ constructor(title, body) { this._payload = { apns: {}, fcm: {} }; this._title = title; @@ -5266,6 +5504,12 @@ this.apns = new APNSNotificationPayload(this._payload.apns, title, body); this.fcm = new FCMNotificationPayload(this._payload.fcm, title, body); } + /** + * Enable or disable push notification debugging message. + * + * @param value - Whether debug message from push notification scheduler should be published to the specific + * channel or not. + */ set debugging(value) { this._debugging = value; } @@ -5343,7 +5587,7 @@ * Build notifications platform for requested platforms. * * @param platforms - List of platforms for which payload should be added to final dictionary. Supported values: - * gcm, apns, and apns2. + * fcm, apns, and apns2. * * @returns Object with data, which can be sent with publish method call and trigger remote notifications for * specified platforms. @@ -5368,6 +5612,11 @@ } } + /** + * Network request module. + * + * @internal + */ /** * Base REST API request class. * @@ -5530,7 +5779,9 @@ */ AbstractRequest.decoder = new TextDecoder(); - /* */ + /** + * Endpoint API operation types. + */ var RequestOperation; (function (RequestOperation) { // -------------------------------------------------------- @@ -5765,7 +6016,17 @@ // -------------------------------------------------------- // ---------------- Subscription Utility ------------------ // -------------------------------------------------------- + /** + * Initial event engine subscription handshake operation. + * + * @internal + */ RequestOperation["PNHandshakeOperation"] = "PNHandshakeOperation"; + /** + * Event engine subscription loop operation. + * + * @internal + */ RequestOperation["PNReceiveMessagesOperation"] = "PNReceiveMessagesOperation"; })(RequestOperation || (RequestOperation = {})); var RequestOperation$1 = RequestOperation; @@ -5788,8 +6049,6 @@ // region Types /** * PubNub-defined event types by payload. - * - * @internal */ var PubNubEventType; (function (PubNubEventType) { @@ -6105,6 +6364,11 @@ } } + /** + * Real-time events emitter module. + * + * @internal + */ /** * Real-time events' emitter. * @@ -6273,6 +6537,11 @@ } } + /** + * Event Engine terminate signal listener module. + * + * @internal + */ /** * @internal */ @@ -6302,7 +6571,18 @@ } } - /* eslint-disable @typescript-eslint/no-explicit-any */ + /** + * Event Engine Core state module. + * + * @internal + */ + /** + * Event engine current state object. + * + * State contains current context and list of invocations which should be performed by the Event Engine. + * + * @internal + */ class State { transition(context, event) { var _a; @@ -6334,7 +6614,17 @@ } } + /** + * Event Engine Core module. + * + * @internal + */ /* eslint-disable @typescript-eslint/no-explicit-any */ + /** + * Generic event engine. + * + * @internal + */ class Engine extends Subject { describe(label) { return new State(label); @@ -6394,7 +6684,18 @@ } } - /* eslint-disable @typescript-eslint/no-explicit-any */ + /** + * Event Engine Core Effects dispatcher module. + * + * @internal + */ + /** + * Event Engine effects dispatcher. + * + * Dispatcher responsible for invocation enqueue and dequeue for processing. + * + * @internal + */ class Dispatcher { constructor(dependencies) { this.dependencies = dependencies; @@ -6431,7 +6732,16 @@ } } - /* eslint-disable @typescript-eslint/no-explicit-any */ + /** + * Event Engine Core types module. + * + * @internal + */ + /** + * Create and configure event engine event. + * + * @internal + */ function createEvent(type, fn) { const creator = function (...args) { return { @@ -6442,6 +6752,11 @@ creator.type = type; return creator; } + /** + * Create and configure short-term effect invocation. + * + * @internal + */ function createEffect(type, fn) { const creator = (...args) => { return { type, payload: fn(...args), managed: false }; @@ -6449,6 +6764,11 @@ creator.type = type; return creator; } + /** + * Create and configure long-running effect invocation. + * + * @internal + */ function createManagedEffect(type, fn) { const creator = (...args) => { return { type, payload: fn(...args), managed: true }; @@ -6458,6 +6778,11 @@ return creator; } + /** + * Event Engine managed effects terminate signal module. + * + * @internal + */ class AbortError extends Error { constructor() { super('The operation was aborted.'); @@ -6489,12 +6814,31 @@ } } + /** + * Event Engine Core Effects handler module. + * + * @internal + */ + /** + * Synchronous (short-term) effect invocation handler. + * + * Handler manages effect execution on behalf of effect dispatcher. + * + * @internal + */ class Handler { constructor(payload, dependencies) { this.payload = payload; this.dependencies = dependencies; } } + /** + * Asynchronous (long-running) effect invocation handler. + * + * Handler manages effect execution on behalf of effect dispatcher. + * + * @internal + */ class AsyncHandler extends Handler { constructor(payload, dependencies, asyncFunction) { super(payload, dependencies); @@ -6511,37 +6855,169 @@ this.abortSignal.abort(); } } + /** + * Asynchronous effect invocation handler constructor. + * + * @param handlerFunction - Function which performs asynchronous action and should be called on `start`. + * + * @internal + */ const asyncHandler = (handlerFunction) => (payload, dependencies) => new AsyncHandler(payload, dependencies, handlerFunction); + /** + * Presence Event Engine events module. + * + * @internal + */ + /** + * Reconnect event. + * + * Event is sent each time when user restores real-time updates processing and notifies other present subscribers + * about joining back. + * + * @internal + */ const reconnect$1 = createEvent('RECONNECT', () => ({})); + /** + * Disconnect event. + * + * Event is sent when user wants to temporarily stop real-time updates processing and notifies other present + * subscribers about leaving. + * + * @internal + */ const disconnect$1 = createEvent('DISCONNECT', () => ({})); + /** + * Channel / group join event. + * + * Event is sent when user adds new channels / groups to the active channels / groups list and notifies other present + * subscribers about joining. + * + * @internal + */ const joined = createEvent('JOINED', (channels, groups) => ({ channels, groups, })); + /** + * Channel / group leave event. + * + * Event is sent when user removes channels / groups from the active channels / groups list and notifies other present + * subscribers about leaving. + * + * @internal + */ const left = createEvent('LEFT', (channels, groups) => ({ channels, groups, })); + /** + * Leave all event. + * + * Event is sent when user doesn't want to receive any real-time updates anymore and notifies other + * subscribers on previously active channels / groups about leaving. + * + * @internal + */ const leftAll = createEvent('LEFT_ALL', () => ({})); + /** + * Presence heartbeat success event. + * + * Event is sent by corresponding effect handler if REST API call was successful. + * + * @internal + */ const heartbeatSuccess = createEvent('HEARTBEAT_SUCCESS', (statusCode) => ({ statusCode })); + /** + * Presence heartbeat did fail event. + * + * Event is sent by corresponding effect handler if REST API call failed. + * + * @internal + */ const heartbeatFailure = createEvent('HEARTBEAT_FAILURE', (error) => error); + /** + * Presence heartbeat impossible event. + * + * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. + * + * @internal + */ const heartbeatGiveup = createEvent('HEARTBEAT_GIVEUP', () => ({})); + /** + * Delayed presence heartbeat event. + * + * Event is sent by corresponding effect handler when delay timer between heartbeat calls fired. + * + * @internal + */ const timesUp = createEvent('TIMES_UP', () => ({})); + /** + * Presence Event Engine effects module. + * + * @internal + */ + /** + * Presence heartbeat effect. + * + * Performs presence heartbeat REST API call. + * + * @internal + */ const heartbeat = createEffect('HEARTBEAT', (channels, groups) => ({ channels, groups, })); + /** + * Presence leave effect. + * + * Performs presence leave REST API call. + * + * @internal + */ const leave = createEffect('LEAVE', (channels, groups) => ({ channels, groups, })); + /** + * Emit presence heartbeat REST API call result status effect. + * + * Notify status change event listeners. + * + * @internal + */ /* eslint-disable @typescript-eslint/no-explicit-any */ const emitStatus$1 = createEffect('EMIT_STATUS', (status) => status); + /** + * Heartbeat delay effect. + * + * Delay of configured length (heartbeat interval) before another heartbeat REST API call will be done. + * + * @internal + */ const wait = createManagedEffect('WAIT', () => ({})); + /** + * Delayed heartbeat effect. + * + * Similar to the {@link wait} effect but used in case if previous heartbeat call did fail. + * + * @internal + */ const delayedHeartbeat = createManagedEffect('DELAYED_HEARTBEAT', (context) => context); + /** + * Presence Event Engine effects dispatcher. + * + * @internal + */ + /** + * Presence Event Engine dispatcher. + * + * Dispatcher responsible for presence events handling and corresponding effects execution. + * + * @internal + */ class PresenceEventEngineDispatcher extends Dispatcher { constructor(engine, dependencies) { super(dependencies); @@ -6558,7 +7034,7 @@ } } }))); - this.on(leave.type, asyncHandler((payload_2, _2, _b) => __awaiter(this, [payload_2, _2, _b], void 0, function* (payload, _, { leave, config }) { + this.on(leave.type, asyncHandler((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { leave, config }) { if (!config.suppressLeaveEvents) { try { leave({ @@ -6569,13 +7045,13 @@ catch (e) { } } }))); - this.on(wait.type, asyncHandler((_3, abortSignal_1, _c) => __awaiter(this, [_3, abortSignal_1, _c], void 0, function* (_, abortSignal, { heartbeatDelay }) { + this.on(wait.type, asyncHandler((_1, abortSignal_1, _a) => __awaiter(this, [_1, abortSignal_1, _a], void 0, function* (_, abortSignal, { heartbeatDelay }) { abortSignal.throwIfAborted(); yield heartbeatDelay(); abortSignal.throwIfAborted(); return engine.transition(timesUp()); }))); - this.on(delayedHeartbeat.type, asyncHandler((payload_3, abortSignal_2, _d) => __awaiter(this, [payload_3, abortSignal_2, _d], void 0, function* (payload, abortSignal, { heartbeat, retryDelay, presenceState, config }) { + this.on(delayedHeartbeat.type, asyncHandler((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { heartbeat, retryDelay, presenceState, config }) { if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { abortSignal.throwIfAborted(); yield retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); @@ -6596,9 +7072,9 @@ return engine.transition(heartbeatGiveup()); } }))); - this.on(emitStatus$1.type, asyncHandler((payload_4, _4, _e) => __awaiter(this, [payload_4, _4, _e], void 0, function* (payload, _, { emitStatus, config }) { - var _f; - if (config.announceFailedHeartbeats && ((_f = payload === null || payload === void 0 ? void 0 : payload.status) === null || _f === void 0 ? void 0 : _f.error) === true) { + this.on(emitStatus$1.type, asyncHandler((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus, config }) { + var _b; + if (config.announceFailedHeartbeats && ((_b = payload === null || payload === void 0 ? void 0 : payload.status) === null || _b === void 0 ? void 0 : _b.error) === true) { emitStatus(payload.status); } else if (config.announceSuccessfulHeartbeats && payload.statusCode === 200) { @@ -6608,6 +7084,19 @@ } } + /** + * Heartbeat stopped state module. + * + * @internal + */ + /** + * Heartbeat stopped state. + * + * State in which Presence Event Engine still has information about active channels / groups, but doesn't wait for + * delayed heartbeat request sending. + * + * @internal + */ const HeartbeatStoppedState = new State('HEARTBEAT_STOPPED'); HeartbeatStoppedState.on(joined.type, (context, event) => HeartbeatStoppedState.with({ channels: [...context.channels, ...event.payload.channels], @@ -6623,6 +7112,18 @@ })); HeartbeatStoppedState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined)); + /** + * Waiting next heartbeat state module. + * + * @internal + */ + /** + * Waiting next heartbeat state. + * + * State in which Presence Event Engine is waiting when delay will run out and next heartbeat call should be done. + * + * @internal + */ const HeartbeatCooldownState = new State('HEARTBEAT_COOLDOWN'); HeartbeatCooldownState.onEnter(() => wait()); HeartbeatCooldownState.onExit(() => wait.cancel); @@ -6644,6 +7145,19 @@ }, [leave(context.channels, context.groups)])); HeartbeatCooldownState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + /** + * Failed to heartbeat state module. + * + * @internal + */ + /** + * Failed to heartbeat state. + * + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. + * + * @internal + */ const HeartbeatFailedState = new State('HEARTBEAT_FAILED'); HeartbeatFailedState.on(joined.type, (context, event) => HeartbeatingState.with({ channels: [...context.channels, ...event.payload.channels], @@ -6663,6 +7177,18 @@ }, [leave(context.channels, context.groups)])); HeartbeatFailedState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + /** + * Retry heartbeat state module. + * + * @internal + */ + /** + * Retry heartbeat state. + * + * State in which Presence Event Engine tries to recover after error which happened before. + * + * @internal + */ const HearbeatReconnectingState = new State('HEARBEAT_RECONNECTING'); HearbeatReconnectingState.onEnter((context) => delayedHeartbeat(context)); HearbeatReconnectingState.onExit(() => delayedHeartbeat.cancel); @@ -6695,6 +7221,18 @@ }); HearbeatReconnectingState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + /** + * Heartbeating state module. + * + * @internal + */ + /** + * Heartbeating state module. + * + * State in which Presence Event Engine send heartbeat REST API call. + * + * @internal + */ const HeartbeatingState = new State('HEARTBEATING'); HeartbeatingState.onEnter((context) => heartbeat(context.channels, context.groups)); HeartbeatingState.on(heartbeatSuccess.type, (context, event) => { @@ -6722,12 +7260,34 @@ }, [leave(context.channels, context.groups)])); HeartbeatingState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + /** + * Inactive heratbeating state module. + * + * @internal + */ + /** + * Inactive heratbeating state + * + * State in which Presence Event Engine doesn't process any heartbeat requests (initial state). + * + * @internal + */ const HeartbeatInactiveState = new State('HEARTBEAT_INACTIVE'); HeartbeatInactiveState.on(joined.type, (_, event) => HeartbeatingState.with({ channels: event.payload.channels, groups: event.payload.groups, })); + /** + * Presence Event Engine module. + * + * @internal + */ + /** + * Presence Event Engine Core. + * + * @internal + */ class PresenceEventEngine { get _engine() { return this.engine; @@ -6766,6 +7326,9 @@ } } + /** + * Failed request retry policy. + */ class RetryPolicy { static LinearRetryPolicy(configuration) { return { @@ -6840,20 +7403,87 @@ } } + /** + * Subscribe Event Engine effects module. + * + * @internal + */ + /** + * Initial subscription effect. + * + * Performs subscribe REST API call with `tt=0`. + * + * @internal + */ const handshake = createManagedEffect('HANDSHAKE', (channels, groups) => ({ channels, groups, })); + /** + * Real-time updates receive effect. + * + * Performs sequential subscribe REST API call with `tt` set to the value received from the previous subscribe + * REST API call. + * + * @internal + */ const receiveMessages = createManagedEffect('RECEIVE_MESSAGES', (channels, groups, cursor) => ({ channels, groups, cursor })); + /** + * Emit real-time updates effect. + * + * Notify event listeners about updates for which listener handlers has been provided. + * + * @internal + */ const emitMessages = createEffect('EMIT_MESSAGES', (events) => events); + /** + * Emit subscription status change effect. + * + * Notify status change event listeners. + * + * @internal + */ const emitStatus = createEffect('EMIT_STATUS', (status) => status); + /** + * Real-time updates receive restore effect. + * + * Performs subscribe REST API call with `tt` which has been received before disconnection or error. + * + * @internal + */ const receiveReconnect = createManagedEffect('RECEIVE_RECONNECT', (context) => context); + /** + * Initial subscription restore effect. + * + * Performs subscribe REST API call with `tt=0` after error. + * + * @internal + */ const handshakeReconnect = createManagedEffect('HANDSHAKE_RECONNECT', (context) => context); + /** + * Subscribe Event Engine events module. + * + * @internal + */ + /** + * Subscription list change event. + * + * Event is sent each time when user would like to change list of active channels / groups. + * + * @internal + */ const subscriptionChange = createEvent('SUBSCRIPTION_CHANGED', (channels, groups) => ({ channels, groups, })); + /** + * Subscription loop restore. + * + * Event is sent when user would like to try catch up on missed updates by providing specific timetoken. + * + * @internal + */ const restore = createEvent('SUBSCRIPTION_RESTORED', (channels, groups, timetoken, region) => ({ channels, groups, @@ -6862,33 +7492,136 @@ region: region !== null && region !== void 0 ? region : 0, }, })); + /** + * Initial subscription handshake success event. + * + * Event is sent by corresponding effect handler if REST API call was successful. + * + * @internal + */ const handshakeSuccess = createEvent('HANDSHAKE_SUCCESS', (cursor) => cursor); + /** + * Initial subscription handshake did fail event. + * + * Event is sent by corresponding effect handler if REST API call failed. + * + * @internal + */ const handshakeFailure = createEvent('HANDSHAKE_FAILURE', (error) => error); + /** + * Initial subscription handshake reconnect success event. + * + * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. + * + * @internal + */ const handshakeReconnectSuccess = createEvent('HANDSHAKE_RECONNECT_SUCCESS', (cursor) => ({ cursor, })); + /** + * Initial subscription handshake reconnect did fail event. + * + * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. + * + * @internal + */ const handshakeReconnectFailure = createEvent('HANDSHAKE_RECONNECT_FAILURE', (error) => error); + /** + * Initial subscription handshake impossible event. + * + * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. + * + * @internal + */ const handshakeReconnectGiveup = createEvent('HANDSHAKE_RECONNECT_GIVEUP', (error) => error); + /** + * Subscription successfully received real-time updates event. + * + * Event is sent by corresponding effect handler if REST API call was successful. + * + * @internal + */ const receiveSuccess = createEvent('RECEIVE_SUCCESS', (cursor, events) => ({ cursor, events, })); + /** + * Subscription did fail to receive real-time updates event. + * + * Event is sent by corresponding effect handler if REST API call failed. + * + * @internal + */ const receiveFailure = createEvent('RECEIVE_FAILURE', (error) => error); + /** + * Subscription successfully received real-time updates on reconnection attempt event. + * + * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. + * + * @internal + */ const receiveReconnectSuccess = createEvent('RECEIVE_RECONNECT_SUCCESS', (cursor, events) => ({ cursor, events, })); + /** + * Subscription did fail to receive real-time updates on reconnection attempt event. + * + * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. + * + * @internal + */ const receiveReconnectFailure = createEvent('RECEIVE_RECONNECT_FAILURE', (error) => error); + /** + * Subscription real-time updates received impossible event. + * + * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. + * + * @internal + */ const receiveReconnectGiveup = createEvent('RECEIVING_RECONNECT_GIVEUP', (error) => error); + /** + * Client disconnect event. + * + * Event is sent when user wants to temporarily stop real-time updates receive. + * + * @internal + */ const disconnect = createEvent('DISCONNECT', () => ({})); + /** + * Client reconnect event. + * + * Event is sent when user wants to restore real-time updates receive. + * + * @internal + */ const reconnect = createEvent('RECONNECT', (timetoken, region) => ({ cursor: { timetoken: timetoken !== null && timetoken !== void 0 ? timetoken : '', region: region !== null && region !== void 0 ? region : 0, }, })); + /** + * Completely stop real-time updates receive event. + * + * Event is sent when user doesn't want to receive any real-time updates anymore. + * + * @internal + */ const unsubscribeAll = createEvent('UNSUBSCRIBE_ALL', () => ({})); + /** + * Subscribe Event Engine effects dispatcher. + * + * @internal + */ + /** + * Subscribe Event Engine dispatcher. + * + * Dispatcher responsible for subscription events handling and corresponding effects execution. + * + * @internal + */ class EventEngineDispatcher extends Dispatcher { constructor(engine, dependencies) { super(dependencies); @@ -6906,7 +7639,7 @@ } } }))); - this.on(receiveMessages.type, asyncHandler((payload_2, abortSignal_2, _b) => __awaiter(this, [payload_2, abortSignal_2, _b], void 0, function* (payload, abortSignal, { receiveMessages, config }) { + this.on(receiveMessages.type, asyncHandler((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { receiveMessages, config }) { abortSignal.throwIfAborted(); try { const result = yield receiveMessages({ @@ -6928,15 +7661,15 @@ } } }))); - this.on(emitMessages.type, asyncHandler((payload_3, _1, _c) => __awaiter(this, [payload_3, _1, _c], void 0, function* (payload, _, { emitMessages }) { + this.on(emitMessages.type, asyncHandler((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitMessages }) { if (payload.length > 0) { emitMessages(payload); } }))); - this.on(emitStatus.type, asyncHandler((payload_4, _2, _d) => __awaiter(this, [payload_4, _2, _d], void 0, function* (payload, _, { emitStatus }) { + this.on(emitStatus.type, asyncHandler((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus }) { emitStatus(payload); }))); - this.on(receiveReconnect.type, asyncHandler((payload_5, abortSignal_3, _e) => __awaiter(this, [payload_5, abortSignal_3, _e], void 0, function* (payload, abortSignal, { receiveMessages, delay, config }) { + this.on(receiveReconnect.type, asyncHandler((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { receiveMessages, delay, config }) { if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { abortSignal.throwIfAborted(); yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); @@ -6966,7 +7699,7 @@ : 'Unable to complete subscribe messages receive.'))); } }))); - this.on(handshakeReconnect.type, asyncHandler((payload_6, abortSignal_4, _f) => __awaiter(this, [payload_6, abortSignal_4, _f], void 0, function* (payload, abortSignal, { handshake, delay, presenceState, config }) { + this.on(handshakeReconnect.type, asyncHandler((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { handshake, delay, presenceState, config }) { if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { abortSignal.throwIfAborted(); yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); @@ -6992,6 +7725,19 @@ } } + /** + * Failed initial subscription handshake (disconnected) state. + * + * @internal + */ + /** + * Failed initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. + * + * @internal + */ const HandshakeFailedState = new State('HANDSHAKE_FAILED'); HandshakeFailedState.on(subscriptionChange.type, (context, event) => HandshakingState.with({ channels: event.payload.channels, @@ -7010,12 +7756,25 @@ groups: event.payload.groups, cursor: { timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region ? event.payload.cursor.region : (_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0, + region: event.payload.cursor.region ? event.payload.cursor.region : ((_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0), }, }); }); HandshakeFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); + /** + * Stopped initial subscription handshake (disconnected) state. + * + * @internal + */ + /** + * Stopped initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine still has information about subscription but doesn't have subscription + * cursor for next sequential subscribe REST API call. + * + * @internal + */ const HandshakeStoppedState = new State('HANDSHAKE_STOPPED'); HandshakeStoppedState.on(subscriptionChange.type, (context, event) => HandshakeStoppedState.with({ channels: event.payload.channels, @@ -7036,6 +7795,19 @@ }); HandshakeStoppedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); + /** + * Failed to receive real-time updates (disconnected) state. + * + * @internal + */ + /** + * Failed to receive real-time updates (disconnected) state. + * + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. + * + * @internal + */ const ReceiveFailedState = new State('RECEIVE_FAILED'); ReceiveFailedState.on(reconnect.type, (context, event) => { var _a; @@ -7063,6 +7835,19 @@ })); ReceiveFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); + /** + * Stopped real-time updates (disconnected) state module. + * + * @internal + */ + /** + * Stopped real-time updates (disconnected) state. + * + * State in which Subscription Event Engine still has information about subscription but doesn't process real-time + * updates. + * + * @internal + */ const ReceiveStoppedState = new State('RECEIVE_STOPPED'); ReceiveStoppedState.on(subscriptionChange.type, (context, event) => ReceiveStoppedState.with({ channels: event.payload.channels, @@ -7090,6 +7875,18 @@ }); ReceiveStoppedState.on(unsubscribeAll.type, () => UnsubscribedState.with(undefined)); + /** + * Reconnect to receive real-time updates (disconnected) state. + * + * @internal + */ + /** + * Reconnect to receive real-time updates (disconnected) state. + * + * State in which Subscription Event Engine tries to recover after error which happened before. + * + * @internal + */ const ReceiveReconnectingState = new State('RECEIVE_RECONNECTING'); ReceiveReconnectingState.onEnter((context) => receiveReconnect(context)); ReceiveReconnectingState.onExit(() => receiveReconnect.cancel); @@ -7128,6 +7925,18 @@ })); ReceiveReconnectingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })])); + /** + * Receiving real-time updates (connected) state module. + * + * @internal + */ + /** + * Receiving real-time updates (connected) state. + * + * State in which Subscription Event Engine processes any real-time updates. + * + * @internal + */ const ReceivingState = new State('RECEIVING'); ReceivingState.onEnter((context) => receiveMessages(context.channels, context.groups, context.cursor)); ReceivingState.onExit(() => receiveMessages.cancel); @@ -7171,6 +7980,18 @@ }); ReceivingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })])); + /** + * Retry initial subscription handshake (disconnected) state. + * + * @internal + */ + /** + * Retry initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine tries to recover after error which happened before. + * + * @internal + */ const HandshakeReconnectingState = new State('HANDSHAKE_RECONNECTING'); HandshakeReconnectingState.onEnter((context) => handshakeReconnect(context)); HandshakeReconnectingState.onExit(() => handshakeReconnect.cancel); @@ -7219,6 +8040,19 @@ }); HandshakeReconnectingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); + /** + * Initial subscription handshake (disconnected) state. + * + * @internal + */ + /** + * Initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine tries to receive subscription cursor for next sequential subscribe REST + * API calls. + * + * @internal + */ const HandshakingState = new State('HANDSHAKING'); HandshakingState.onEnter((context) => handshake(context.channels, context.groups)); HandshakingState.onExit(() => handshake.cancel); @@ -7274,6 +8108,18 @@ }); HandshakingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); + /** + * Unsubscribed / disconnected state module. + * + * @internal + */ + /** + * Unsubscribed / disconnected state. + * + * State in which Subscription Event Engine doesn't process any real-time updates. + * + * @internal + */ const UnsubscribedState = new State('UNSUBSCRIBED'); UnsubscribedState.on(subscriptionChange.type, (_, event) => HandshakingState.with({ channels: event.payload.channels, @@ -7287,6 +8133,16 @@ }); }); + /** + * Subscribe Event Engine module. + * + * @internal + */ + /** + * Subscribe Event Engine Core. + * + * @internal + */ class EventEngine { get _engine() { return this.engine; @@ -7528,6 +8384,8 @@ /** * Receive messages subscribe REST API module. + * + * @internal */ /** * Receive messages subscribe request. @@ -7572,6 +8430,8 @@ /** * Handshake subscribe REST API module. + * + * @internal */ /** * Handshake subscribe request. @@ -7603,6 +8463,8 @@ /** * Get Presence State REST API module. + * + * @internal */ // endregion /** @@ -7659,6 +8521,8 @@ /** * Set Presence State REST API module. + * + * @internal */ // endregion /** @@ -7709,6 +8573,8 @@ /** * Announce heartbeat REST API module. + * + * @internal */ // endregion /** @@ -7759,6 +8625,8 @@ /** * Announce leave REST API module. + * + * @internal */ // endregion /** @@ -7811,6 +8679,8 @@ /** * `uuid` presence REST API module. + * + * @internal */ // endregion /** @@ -7851,6 +8721,8 @@ /** * Channels / channel groups presence REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -7948,6 +8820,8 @@ /** * Delete messages REST API module. + * + * @internal */ // endregion /** @@ -7992,6 +8866,8 @@ /** * Messages count REST API module. + * + * @internal */ // endregion /** @@ -8044,6 +8920,8 @@ /** * Get history REST API module. + * + * @internal */ // -------------------------------------------------------- // ---------------------- Defaults ------------------------ @@ -8182,6 +9060,8 @@ /** * Fetch messages REST API module. + * + * @internal */ // -------------------------------------------------------- // ---------------------- Defaults ------------------------ @@ -8363,6 +9243,8 @@ /** * Get Message Actions REST API module. + * + * @internal */ // endregion /** @@ -8418,6 +9300,8 @@ /** * Add Message Action REST API module. + * + * @internal */ // endregion /** @@ -8475,6 +9359,8 @@ /** * Remove Message Action REST API module. + * + * @internal */ // endregion /** @@ -8520,6 +9406,8 @@ /** * Publish File Message REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -8598,6 +9486,8 @@ /** * File sharing REST API module. + * + * @internal */ // endregion /** @@ -8642,6 +9532,8 @@ /** * Delete file REST API module. + * + * @internal */ // endregion /** @@ -8685,6 +9577,8 @@ /** * List Files REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -8739,6 +9633,8 @@ /** * Generate file upload URL REST API request. + * + * @internal */ // endregion /** @@ -8790,6 +9686,8 @@ /** * Upload file REST API request. + * + * @internal */ /** * File Upload request. @@ -8847,6 +9745,11 @@ } } + /** + * Share File API module. + * + * @internal + */ // endregion /** * Send file composed request. @@ -8969,53 +9872,173 @@ } class SubscribeCapable { + /** + * Start receiving real-time updates. + * + * @param subscribeParameters - Additional subscription configuration options which should be used + * for request. + */ subscribe(subscribeParameters) { const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken; this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken }))); } + /** + * Stop real-time events processing. + */ unsubscribe() { this.pubnub.unsubscribe({ channels: this.channelNames, channelGroups: this.groupNames, }); } + /** + * Set new message handler. + * + * @param onMessageListener - Listener function, which will be called each time when a new message + * is received from the real-time network. + */ set onMessage(onMessageListener) { this.listener.message = onMessageListener; } + /** + * Set new presence events handler. + * + * @param onPresenceListener - Listener function, which will be called each time when a new + * presence event is received from the real-time network. + */ set onPresence(onPresenceListener) { this.listener.presence = onPresenceListener; } + /** + * Set new signal handler. + * + * @param onSignalListener - Listener function, which will be called each time when a new signal + * is received from the real-time network. + */ set onSignal(onSignalListener) { this.listener.signal = onSignalListener; } + /** + * Set new app context event handler. + * + * @param onObjectsListener - Listener function, which will be called each time when a new + * app context event is received from the real-time network. + */ set onObjects(onObjectsListener) { this.listener.objects = onObjectsListener; } + /** + * Set new message reaction event handler. + * + * @param messageActionEventListener - Listener function, which will be called each time when a + * new message reaction event is received from the real-time network. + */ set onMessageAction(messageActionEventListener) { this.listener.messageAction = messageActionEventListener; } + /** + * Set new file handler. + * + * @param fileEventListener - Listener function, which will be called each time when a new file + * is received from the real-time network. + */ set onFile(fileEventListener) { this.listener.file = fileEventListener; } + /** + * Set events handler. + * + * @param listener - Events listener configuration object, which lets specify handlers for multiple + * types of events. + */ addListener(listener) { this.eventEmitter.addListener(listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); } + /** + * Remove events handler. + * + * @param listener - Event listener configuration, which should be removed from the list of notified + * listeners. **Important:** Should be the same object which has been passed to the + * {@link addListener}. + */ removeListener(listener) { this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); } + /** + * Get list of channels which is used for subscription. + * + * @returns List of channel names. + */ get channels() { return this.channelNames.slice(0); } + /** + * Get list of channel groups which is used for subscription. + * + * @returns List of channel group names. + */ get channelGroups() { return this.groupNames.slice(0); } } + /** + * Multiple entities subscription set object which can be used to receive and handle real-time + * updates. + * + * Subscription set object represent collection of per-entity subscription objects and allow + * processing them at once for subscription loop and events handling. + */ class SubscriptionSet extends SubscribeCapable { + /** + * Create entities' subscription set object. + * + * Subscription set object represent collection of per-entity subscription objects and allow + * processing them at once for subscription loop and events handling. + * + * @param channels - List of channels which should be used in subscription loop. + * @param channelGroups - List of channel groups which should be used in subscription loop. + * @param subscriptionOptions - Entities' subscription object configuration. + * @param eventEmitter - Event emitter, which will notify listeners about updates received for + * entities' channels / groups. + * @param pubnub - PubNub instance which will perform subscribe / unsubscribe requests for + * entities. + * + * @returns Ready to use entities' subscription set object. + * + * @internal + */ constructor({ channels = [], channelGroups = [], subscriptionOptions, eventEmitter, pubnub, }) { super(); + /** + * List of channel names for subscription loop. + * + * List of entities' names which can have additional entries depending on from configuration + * options. Presence events observing adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entities' type, they may provide a list of channels which are + * used to receive real-time updates for it. + * + * @internal + */ this.channelNames = []; + /** + * List of channel group names for subscription loop. + * + * List of entities' names which can have additional entries depending on from configuration + * options. Presence events observing adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entities' type, they may provide a list of channels which are + * used to receive real-time updates for it. + * + * @internal + */ this.groupNames = []; + /** + * List of per-entity subscription objects. + * + * @internal + */ this.subscriptionList = []; this.options = subscriptionOptions; this.eventEmitter = eventEmitter; @@ -9033,12 +10056,28 @@ this.listener = {}; eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); } + /** + * Add additional entity's subscription to the subscription set. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#subscribe} call or + * next subscription loop. + * + * @param subscription - Other entity's subscription object, which should be added. + */ addSubscription(subscription) { this.subscriptionList.push(subscription); this.channelNames = [...this.channelNames, ...subscription.channels]; this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); } + /** + * Remove entity's subscription object from the set. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#unsubscribe} call or + * next subscription loop. + * + * @param subscription - Other entity's subscription object, which should be removed. + */ removeSubscription(subscription) { const channelsToRemove = subscription.channels; const groupsToRemove = subscription.channelGroups; @@ -9047,12 +10086,28 @@ this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); } + /** + * Merge with other subscription set object. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#subscribe} call or + * next subscription loop. + * + * @param subscriptionSet - Other entities' subscription set, which should be joined. + */ addSubscriptionSet(subscriptionSet) { this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); } + /** + * Subtract other subscription set object. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#unsubscribe} call or + * next subscription loop. + * + * @param subscriptionSet - Other entities' subscription set, which should be subtracted. + */ removeSubscriptionSet(subscriptionSet) { const channelsToRemove = subscriptionSet.channels; const groupsToRemove = subscriptionSet.channelGroups; @@ -9061,15 +10116,59 @@ this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); } + /** + * Get list of entities' subscription objects registered in subscription set. + * + * @returns Entities' subscription objects list. + */ get subscriptions() { return this.subscriptionList.slice(0); } } + /** + * Single-entity subscription object which can be used to receive and handle real-time updates. + */ class Subscription extends SubscribeCapable { + /** + * Create entity's subscription object. + * + * @param channels - List of channels which should be used in subscription loop. + * @param channelGroups - List of channel groups which should be used in subscription loop. + * @param subscriptionOptions - Per-entity subscription object configuration. + * @param eventEmitter - Event emitter, which will notify listeners about updates received for + * entity channels / groups. + * @param pubnub - PubNub instance which will perform subscribe / unsubscribe requests for entity. + * + * @returns Ready to use entity's subscription object. + * + * @internal + */ constructor({ channels, channelGroups, subscriptionOptions, eventEmitter, pubnub, }) { super(); + /** + * List of channel names for subscription loop. + * + * Entity may have few because of subscription configuration options. Presence events observing + * adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entity type, it may provide a list of channels which are used + * to receive real-time updates for it. + * + * @internal + */ this.channelNames = []; + /** + * List of channel group names for subscription loop. + * + * Entity may have few because of subscription configuration options. Presence events observing + * adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entity type, it may provide a list of channel groups which is + * sed to receive real-time updates for it. + * + * @internal + */ this.groupNames = []; this.channelNames = channels; this.groupNames = channelGroups; @@ -9079,6 +10178,12 @@ this.listener = {}; eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); } + /** + * Merge entities' subscription objects into subscription set. + * + * @param subscription - Other entity's subscription object to be merged with receiver. + * @return Subscription set which contains both receiver and other entities' subscription objects. + */ addSubscription(subscription) { return new SubscriptionSet({ channels: [...this.channelNames, ...subscription.channels], @@ -9090,12 +10195,37 @@ } } + /** + * First-class objects which provides access to the channel app context object-specific APIs. + */ class ChannelMetadata { + /** + * Create channel app context object entity. + * + * @param id - Channel app context object identifier which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use channel app context object entity. + * + * @internal + */ constructor(id, eventEmitter, pubnub) { - this.id = id; this.eventEmitter = eventEmitter; this.pubnub = pubnub; + this.id = id; } + /** + * Create channel's app context subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific channel + * app context object. + * + * @param [subscriptionOptions] - Channel's app context subscription object behavior customization options. + * + * @returns Configured and ready to use channel's app context subscription object. + */ subscription(subscriptionOptions) { { return new Subscription({ @@ -9109,12 +10239,37 @@ } } + /** + * First-class objects which provides access to the channel group-specific APIs. + */ class ChannelGroup { - constructor(channelGroup, eventEmitter, pubnub) { + /** + * Create simple channel entity. + * + * @param name - Name of the channel group which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel group's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use channel group entity. + * + * @internal + */ + constructor(name, eventEmitter, pubnub) { this.eventEmitter = eventEmitter; this.pubnub = pubnub; - this.name = channelGroup; + this.name = name; } + /** + * Create channel group's subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the channels in + * specific channel group. + * + * @param [subscriptionOptions] - Channel group's subscription object behavior customization options. + * + * @returns Configured and ready to use channel group's subscription object. + */ subscription(subscriptionOptions) { { return new Subscription({ @@ -9128,12 +10283,37 @@ } } + /** + * First-class objects which provides access to the user app context object-specific APIs. + */ class UserMetadata { + /** + * Create user app context object entity. + * + * @param id - User app context object identifier which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use user app context object entity. + * + * @internal + */ constructor(id, eventEmitter, pubnub) { - this.id = id; this.eventEmitter = eventEmitter; this.pubnub = pubnub; + this.id = id; } + /** + * Create user's app context subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific user + * app context object. + * + * @param [subscriptionOptions] - User's app context subscription object behavior customization options. + * + * @returns Configured and ready to use user's app context subscription object. + */ subscription(subscriptionOptions) { { return new Subscription({ @@ -9147,12 +10327,36 @@ } } + /** + * First-class objects which provides access to the channel-specific APIs. + */ class Channel { - constructor(channelName, eventEmitter, pubnub) { + /** + * Create simple channel entity. + * + * @param name - Name of the channel which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use channel entity. + * + * @internal + */ + constructor(name, eventEmitter, pubnub) { this.eventEmitter = eventEmitter; this.pubnub = pubnub; - this.name = channelName; + this.name = name; } + /** + * Create channel's subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific channel. + * + * @param [subscriptionOptions] - Channel's subscription object behavior customization options. + * + * @returns Configured and ready to use channel's subscription object. + */ subscription(subscriptionOptions) { { return new Subscription({ @@ -9168,6 +10372,8 @@ /** * Remove channel group channels REST API module. + * + * @internal */ // endregion /** @@ -9215,6 +10421,8 @@ /** * Add channel group channels REST API module. + * + * @internal */ // endregion /** @@ -9261,6 +10469,8 @@ /** * List channel group channels REST API module. + * + * @internal */ // endregion /** @@ -9301,6 +10511,8 @@ /** * Delete channel group REST API module. + * + * @internal */ // endregion /** @@ -9341,6 +10553,8 @@ /** * List All Channel Groups REST API module. + * + * @internal */ // endregion /** @@ -9379,12 +10593,23 @@ /** * PubNub Channel Groups API module. */ - class PubnubChannelGroups { + /** + * PubNub Stream / Channel group API interface. + */ + class PubNubChannelGroups { + /** + * Create stream / channel group API access object. + * + * @param keySet - PubNub account keys set which should be used for REST API calls. + * @param sendRequest - Function which should be used to send REST API calls. + * + * @internal + */ constructor(keySet, /* eslint-disable @typescript-eslint/no-explicit-any */ sendRequest) { - this.keySet = keySet; this.sendRequest = sendRequest; + this.keySet = keySet; } /** * Fetch channel group channels. @@ -9474,6 +10699,8 @@ /** * Manage channels enabled for device push REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -9551,6 +10778,8 @@ /** * Unregister Channels from Device push REST API module. + * + * @internal */ // endregion /** @@ -9578,6 +10807,8 @@ /** * List Device push enabled channels REST API module. + * + * @internal */ // endregion /** @@ -9605,6 +10836,8 @@ /** * Register Channels with Device push REST API module. + * + * @internal */ // endregion /** @@ -9632,6 +10865,8 @@ /** * Unregister Device push REST API module. + * + * @internal */ // endregion /** @@ -9660,12 +10895,23 @@ /** * PubNub Push Notifications API module. */ + /** + * PubNub Push Notifications API interface. + */ class PubNubPushNotifications { + /** + * Create mobile push notifications API access object. + * + * @param keySet - PubNub account keys set which should be used for REST API calls. + * @param sendRequest - Function which should be used to send REST API calls. + * + * @internal + */ constructor(keySet, /* eslint-disable @typescript-eslint/no-explicit-any */ sendRequest) { - this.keySet = keySet; this.sendRequest = sendRequest; + this.keySet = keySet; } /** * Fetch device's push notification enabled channels. @@ -9729,6 +10975,8 @@ /** * Get All Channel Metadata REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -9794,6 +11042,8 @@ /** * Remove Channel Metadata REST API module. + * + * @internal */ // endregion /** @@ -9832,6 +11082,8 @@ /** * Get UUID Memberships REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -9943,6 +11195,8 @@ /** * Set UUID Memberships REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -10049,6 +11303,8 @@ /** * Get All UUID Metadata REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -10109,6 +11365,8 @@ /** * Get Channel Metadata REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -10165,6 +11423,8 @@ /** * Set Channel Metadata REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -10226,6 +11486,8 @@ /** * Remove UUID Metadata REST API module. + * + * @internal */ // endregion /** @@ -10267,6 +11529,8 @@ /** * Get Channel Members REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -10375,6 +11639,8 @@ /** * Set Channel Members REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -10478,6 +11744,8 @@ /** * Get UUID Metadata REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -10536,6 +11804,8 @@ /** * Set UUID Metadata REST API module. + * + * @internal */ // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -10601,13 +11871,24 @@ /** * PubNub Objects API module. */ + /** + * PubNub App Context API interface. + */ class PubNubObjects { + /** + * Create app context API access object. + * + * @param configuration - Extended PubNub client configuration object. + * @param sendRequest - Function which should be used to send REST API calls. + * + * @internal + */ constructor(configuration, /* eslint-disable @typescript-eslint/no-explicit-any */ sendRequest) { + this.keySet = configuration.keySet; this.configuration = configuration; this.sendRequest = sendRequest; - this.keySet = configuration.keySet; } /** * Fetch a paginated list of UUID Metadata objects. @@ -10625,11 +11906,12 @@ /** * Fetch a paginated list of UUID Metadata objects. * - * * @param [parametersOrCallback] - Request configuration parameters or callback from overload. * @param [callback] - Request completion handler callback. * * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + * + * @internal */ _getAllUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { @@ -10662,6 +11944,8 @@ * @param [callback] - Request completion handler callback. * * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + * + * @internal */ _getUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { @@ -10695,6 +11979,8 @@ /** * Update specific UUID Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. Will set UUID metadata for currently * configured PubNub client `uuid` if not set. * @param [callback] - Request completion handler callback. @@ -10729,6 +12015,8 @@ /** * Remove a specific UUID Metadata object. * + * @internal + * * @param [parametersOrCallback] - Request configuration parameters or callback from overload. * @param [callback] - Request completion handler callback. * @@ -10766,6 +12054,8 @@ /** * Fetch a paginated list of Channel Metadata objects. * + * @internal + * * @param [parametersOrCallback] - Request configuration parameters or callback from overload. * @param [callback] - Request completion handler callback. * @@ -10799,6 +12089,8 @@ /** * Fetch Channel Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. * @param [callback] - Request completion handler callback. * @@ -10828,6 +12120,8 @@ /** * Update specific Channel Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. * @param [callback] - Request completion handler callback. * @@ -10858,6 +12152,8 @@ /** * Remove a specific Channel Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. * @param [callback] - Request completion handler callback. * @@ -11088,7 +12384,6 @@ uuids: (_c = (_b = spaceParameters.users) === null || _b === void 0 ? void 0 : _b.map((user) => { if (typeof user === 'string') return user; - user.userId; return { id: user.userId, custom: user.custom }; })) !== null && _c !== void 0 ? _c : spaceParameters.uuids, limit: 0, @@ -11148,6 +12443,8 @@ /** * Download File REST API module. + * + * @internal */ // endregion /** @@ -11199,6 +12496,9 @@ } } + /** + * Core PubNub API module. + */ // endregion /** * Platform-agnostic PubNub client core. @@ -11226,6 +12526,14 @@ return uuidGenerator.createUUID(); } // endregion + /** + * Create and configure PubNub client core. + * + * @param configuration - PubNub client core configuration. + * @returns Configured and ready to use PubNub client. + * + * @internal + */ constructor(configuration) { this._configuration = configuration.configuration; this.cryptography = configuration.cryptography; @@ -11234,7 +12542,7 @@ this.crypto = configuration.crypto; // API group entry points initialization. this._objects = new PubNubObjects(this._configuration, this.sendRequest.bind(this)); - this._channelGroups = new PubnubChannelGroups(this._configuration.keySet, this.sendRequest.bind(this)); + this._channelGroups = new PubNubChannelGroups(this._configuration.keySet, this.sendRequest.bind(this)); this._push = new PubNubPushNotifications(this._configuration.keySet, this.sendRequest.bind(this)); { // Prepare for real-time events announcement. @@ -11591,6 +12899,8 @@ /** * Schedule request execution. * + * @internal + * * @param request - REST API request. * @param [callback] - Request completion handler callback. * @@ -11817,6 +13127,8 @@ * * **Note:** Method passed into managers to let them use it when required. * + * @internal + * * @param parameters - Request configuration parameters. * @param callback - Request completion handler callback. */ @@ -11861,6 +13173,8 @@ * * **Note:** Method passed into managers to let them use it when required. * + * @internal + * * @param parameters - Request configuration parameters. * @param callback - Request completion handler callback. */ @@ -11908,6 +13222,8 @@ /** * Event engine handshake subscribe. * + * @internal + * * @param parameters - Request configuration parameters. */ subscribeHandshake(parameters) { @@ -11934,6 +13250,8 @@ /** * Event engine receive messages subscribe. * + * @internal + * * @param parameters - Request configuration parameters. */ subscribeReceiveMessages(parameters) { @@ -12203,6 +13521,8 @@ /** * Announce user presence * + * @internal + * * @param parameters - Desired presence state for provided list of channels and groups. * @param callback - Request completion handler callback. */ @@ -12221,6 +13541,8 @@ /** * Announce user `join` on specified list of channels and groups. * + * @internal + * * @param parameters - List of channels and groups where `join` event should be sent. */ join(parameters) { @@ -12232,6 +13554,8 @@ /** * Announce user `leave` on specified list of channels and groups. * + * @internal + * * @param parameters - List of channels and groups where `leave` event should be sent. */ leave(parameters) { @@ -12240,6 +13564,8 @@ } /** * Announce user `leave` on all subscribed channels. + * + * @internal */ leaveAll() { var _a; @@ -12577,8 +13903,7 @@ * @returns Asynchronous memberships modification response or `void` in case if `callback` provided. * * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} - * methods instead - * from `objects` API group.. + * methods instead from `objects` API group. */ removeMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { @@ -12931,6 +14256,8 @@ /** * Cbor decoder module. + * + * @internal */ /** * CBOR data decoder. @@ -12967,6 +14294,13 @@ * PubNub client for browser platform. */ class PubNub extends PubNubCore { + /** + * Create and configure PubNub client core. + * + * @param configuration - User-provided PubNub client configuration. + * + * @returns Configured and ready to use PubNub client. + */ constructor(configuration) { var _a; const configurationCopy = setDefaults(configuration); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 6b073e00d..212067905 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},void 0!==t?{statusCode:t}:{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e,t){var s={},n=s.lib={},r=function(){},i=n.Base={extend:function(e){r.prototype=this;var t=new r;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},o=n.WordArray=i.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||c).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=i.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new o.init(s,t/2)}},u=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new o.init(s,t)}},l=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(u.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return u.parse(unescape(encodeURIComponent(e)))}},h=n.BufferedBlockAlgorithm=i.extend({reset:function(){this._data=new o.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=l.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,i=this.blockSize,a=r/(4*i);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*i,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},t.BlockCipher=a.extend({cfg:a.cfg.extend({mode:c,padding:l}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var h=t.CipherParams=s.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),d=(c=(p.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(i)},parse:function(e){var t=(e=i.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return h.create({ciphertext:e,salt:s})}},t.SerializableCipher=s.extend({cfg:s.extend({format:c}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,h.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),p=(p.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=o.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,h.create({key:e,iv:s,salt:r})}},g=t.PasswordBasedCipher=d.extend({cfg:d.cfg.extend({kdf:p}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=d.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,d.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=C.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}}C.IV_LENGTH=16,C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new C}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new P({default:new S({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(P.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=M.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=M.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===M.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=M.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}P.LEGACY_IDENTIFIER="";class M{static from(e,t){if(e!==M.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==M.SENTINEL))return P.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>M.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+M.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(n),o)}}M.SENTINEL="PNED",M.LEGACY_IDENTIFIER="",M.IDENTIFIER_LENGTH=4,M.VERSION=1,M.MAX_VERSION=1,M.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return M.VERSION}get length(){return M.SENTINEL.length+1+M.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(M.SENTINEL)),e+=M.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=M.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class j{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const I=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),R=(e,t)=>{const s=e.map((e=>I(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},T=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class F{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?F.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function x(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?x(a):a})),n}F.decoder=new TextDecoder;const D=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(k=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:100,useRequestId:k,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var q={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(q,q.exports);var G=t(q.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=L(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.9"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},L=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class B{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(H||(H={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?H.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===H.POST||t===H.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${I(e)}`)).join("&"):`${t}=${I(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{_config;hashHistory;constructor({config:e}){this.hashHistory=[],this._config=e}getKey(e){const t=(e=>{let t=0;if(0===e.length)return t;for(let s=0;s=this._config.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}}class Y{constructor(e,t,s,n,r,i,o){this.configuration=e,this.listenerManager=t,this.eventEmitter=s,this.subscribeCall=n,this.heartbeatCall=r,this.leaveCall=i,this.reconnectionManager=new J(o),this.dedupingManager=new Q({config:this.configuration}),this.heartbeatChannelGroups={},this.heartbeatChannels={},this.presenceChannelGroups={},this.presenceChannels={},this.heartbeatTimer=null,this.presenceState={},this.pendingChannelGroupSubscriptions=new Set,this.pendingChannelSubscriptions=new Set,this.channelGroups={},this.channels={},this.currentTimetoken="0",this.lastTimetoken="0",this.storedTimetoken=null,this.subscriptionStatusAnnounced=!1,this.isOnline=!0}get subscribedChannels(){return Object.keys(this.channels)}get subscribedChannelGroups(){return Object.keys(this.channelGroups)}get abort(){return this._subscribeAbort}set abort(e){this._subscribeAbort=e}disconnect(){this.stopSubscribeLoop(),this.stopHeartbeatTimer(),this.reconnectionManager.stopPolling()}reconnect(){this.startSubscribeLoop(),this.startHeartbeatTimer()}subscribe(e){const{channels:t,channelGroups:s,timetoken:n,withPresence:r=!1,withHeartbeats:i=!1}=e;n&&(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=n),"0"!==this.currentTimetoken&&0!==this.currentTimetoken&&(this.storedTimetoken=this.currentTimetoken,this.currentTimetoken=0),null==t||t.forEach((e=>{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:H.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===H.POST||r.method===H.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var ne;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ne||(ne={}));var re=ne;var ie;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ie||(ie={}));class oe extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return re.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ie.Presence:ie.Message),t!=ie.Signal&&"string"==typeof e.d?t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}:t==ie.Message?{type:ie.Message,data:this.messageFromEnvelope(e)}:t===ie.Presence?{type:ie.Presence,data:this.presenceEventFromEnvelope(e)}:t==ie.Signal?{type:ie.Signal,data:this.signalFromEnvelope(e)}:t===ie.AppContext?{type:ie.AppContext,data:this.appContextFromEnvelope(e)}:t===ie.MessageAction?{type:ie.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ie.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(ae.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class ae extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ce{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===ie.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===ie.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ie.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ie.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ue{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class le{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class he extends ue{describe(e){return new le(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class de{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function pe(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ye(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class fe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends ue{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new fe}abort(){this._aborted=!0,this.notify(new fe)}}class be{constructor(e,t){this.payload=e,this.dependencies=t}}class ve extends be{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const we=e=>(t,s)=>new ve(t,s,e),Se=pe("RECONNECT",(()=>({}))),ke=pe("DISCONNECT",(()=>({}))),Ee=pe("JOINED",((e,t)=>({channels:e,groups:t}))),Oe=pe("LEFT",((e,t)=>({channels:e,groups:t}))),Ce=pe("LEFT_ALL",(()=>({}))),Ne=pe("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Pe=pe("HEARTBEAT_FAILURE",(e=>e)),Me=pe("HEARTBEAT_GIVEUP",(()=>({}))),_e=pe("TIMES_UP",(()=>({}))),Ae=ge("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),je=ge("LEAVE",((e,t)=>({channels:e,groups:t}))),Ie=ge("EMIT_STATUS",(e=>e)),Re=ye("WAIT",(()=>({}))),Ue=ye("DELAYED_HEARTBEAT",(e=>e));class Te extends de{constructor(e,t){super(t),this.on(Ae.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(je.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Re.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(_e())}))))),this.on(Ue.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Me());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Pe(t))}}}))))),this.on(Ie.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:re.PNHeartbeatOperation,error:!1}))})))))}}const Fe=new le("HEARTBEAT_STOPPED");Fe.on(Ee.type,((e,t)=>Fe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Oe.type,((e,t)=>Fe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Fe.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),Fe.on(Ce.type,((e,t)=>Ke.with(void 0)));const xe=new le("HEARTBEAT_COOLDOWN");xe.onEnter((()=>Re())),xe.onExit((()=>Re.cancel)),xe.on(_e.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),xe.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),xe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const De=new le("HEARTBEAT_FAILED");De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),De.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const qe=new le("HEARBEAT_RECONNECTING");qe.onEnter((e=>Ue(e))),qe.onExit((()=>Ue.cancel)),qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>{Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)])})),qe.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),qe.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),qe.on(Me.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),qe.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ge=new le("HEARTBEATING");Ge.onEnter((e=>Ae(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[je(t.payload.channels,t.payload.groups)]))),Ge.on(Pe.type,((e,t)=>qe.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>Fe.with({channels:e.channels,groups:e.groups},[je(e.channels,e.groups)]))),Ge.on(Ce.type,((e,t)=>Ke.with(void 0,[je(e.channels,e.groups)])));const Ke=new le("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new he,this.channels=[],this.groups=[],this.dispatcher=new Te(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Oe(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ce())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Le{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Be=ye("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),He=ye("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),ze=ge("EMIT_MESSAGES",(e=>e)),Ve=ge("EMIT_STATUS",(e=>e)),We=ye("RECEIVE_RECONNECT",(e=>e)),Je=ye("HANDSHAKE_RECONNECT",(e=>e)),Qe=pe("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=pe("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Xe=pe("HANDSHAKE_SUCCESS",(e=>e)),Ze=pe("HANDSHAKE_FAILURE",(e=>e)),et=pe("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),tt=pe("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=pe("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),nt=pe("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),rt=pe("RECEIVE_FAILURE",(e=>e)),it=pe("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=pe("RECEIVE_RECONNECT_FAILURE",(e=>e)),at=pe("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ct=pe("DISCONNECT",(()=>({}))),ut=pe("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),lt=pe("UNSUBSCRIBE_ALL",(()=>({})));class ht extends de{constructor(e,t){super(t),this.on(Be.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Xe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(He.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(nt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(rt(t))}}}))))),this.on(ze.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(Ve.type,we(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(We.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(at(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(it(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Je.type,we(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(et(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(tt(t))}}})))))}}const dt=new le("HANDSHAKE_FAILED");dt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ut.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),dt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),dt.on(lt.type,(e=>wt.with()));const pt=new le("HANDSHAKE_STOPPED");pt.on(Qe.type,((e,t)=>pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(ut.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),pt.on(Ye.type,((e,t)=>{var s;return pt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),pt.on(lt.type,(e=>wt.with()));const gt=new le("RECEIVE_FAILED");gt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(lt.type,(e=>wt.with(void 0)));const yt=new le("RECEIVE_STOPPED");yt.on(Qe.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>yt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ut.type,((e,t)=>{var s;return vt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(lt.type,(()=>wt.with(void 0)));const ft=new le("RECEIVE_RECONNECTING");ft.onEnter((e=>We(e))),ft.onExit((()=>We.cancel)),ft.on(it.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),ft.on(ot.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),ft.on(at.type,((e,t)=>{var s;return gt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),ft.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),ft.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const mt=new le("RECEIVING");mt.onEnter((e=>He(e.channels,e.groups,e.cursor))),mt.onExit((()=>He.cancel)),mt.on(nt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(rt.type,((e,t)=>ft.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ct.type,(e=>yt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Ve({category:h.PNDisconnectedCategory})]))),mt.on(lt.type,(e=>wt.with(void 0,[Ve({category:h.PNDisconnectedCategory})])));const bt=new le("HANDSHAKE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(et.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[Ve({category:h.PNConnectedCategory})])})),bt.on(tt.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(st.type,((e,t)=>{var s;return dt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[Ve({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),bt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),bt.on(lt.type,(e=>wt.with(void 0)));const vt=new le("HANDSHAKING");vt.onEnter((e=>Be(e.channels,e.groups))),vt.onExit((()=>Be.cancel)),vt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?wt.with(void 0):vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Xe.type,((e,t)=>{var s,n;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[Ve({category:h.PNConnectedCategory})])})),vt.on(Ze.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),vt.on(ct.type,(e=>pt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var s;return vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(lt.type,(e=>wt.with()));const wt=new le("UNSUBSCRIBED");wt.on(Qe.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups}))),wt.on(Ye.type,((e,t)=>vt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class St{get _engine(){return this.engine}constructor(e){this.engine=new he,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new ht(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(wt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=T(this.channels,e),i=T(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ut(e,t))}disconnect(){this.engine.transition(ct()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t,s;super({method:e.sendByPost?H.POST:H.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return re.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${I(t)}/0${this.parameters.sendByPost?"":`/${I(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${I(s)}/0/${I(r)}`}}class Ot extends oe{operation(){return re.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ct extends oe{operation(){return re.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${R(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Nt extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return re.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=s?s:[],",")}/uuid/${I(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${R(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return re.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${R(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${I(t)}`}}class jt extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?re.PNGlobalHereNowOperation:re.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${R(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class It extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Rt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${R(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return re.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Tt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Tt||(Tt={}));class Ft extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return re.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Tt.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${R(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Tt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class xt extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class Dt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class qt extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${I(t)}/message/${n}/action/${s}`}}class Gt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return re.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${I(t)}/0/${I(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Kt extends se{constructor(e){super({method:H.LOCAL}),this.parameters=e}operation(){return re.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${I(e)}/files/${t}/${s}`}}class $t extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(s)}/files/${t}/${n}`}}class Lt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return re.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Bt extends se{constructor(e){super({method:H.POST}),this.parameters=e}operation(){return re.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Ht extends se{constructor(e){super({method:H.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return re.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Ht.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:re.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(re.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Bt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Ht({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Vt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Wt extends Vt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Jt extends Vt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Wt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.id=e,this.eventEmitter=t,this.pubnub=s}subscription(e){return new Jt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Jt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${I(t)}/remove`}}class rs extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class is{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new rs({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ns(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class os extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class as extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return re.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class cs extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return re.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class us extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return re.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls extends os{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return re.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class hs{constructor(e,t){this.keySet=e,this.sendRequest=t}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new ls(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class ds extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return re.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ps extends se{constructor(e){super({method:H.DELETE}),this.parameters=e}operation(){return re.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ys extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class fs extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return re.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ms extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class bs extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return re.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class vs extends se{constructor(e){super({method:H.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class Ss extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return re.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${I(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class ks extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Es extends se{constructor(e){var t,s,n;super({method:H.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return re.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${I(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Os{constructor(e,t){this.configuration=e,this.sendRequest=t,this.keySet=e.keySet}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new fs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ks(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new Es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new vs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ds(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new bs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ps(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new Ss(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new gs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ys(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:(e.userId,{id:e.userId,custom:e.custom}))))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Cs extends se{constructor(){super()}operation(){return re.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Ns extends se{constructor(e){super(),this.parameters=e}operation(){return re.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${I(t)}/files/${s}/${n}`}}class Ps{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Os(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new is(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new hs(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ce(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new St({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Zt(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Xt(e,this.eventEmitter,this)}subscriptionSet(e){return new Wt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===re.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ps.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new ae(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Mt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Pt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:re.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${I(t)}`)).join("&"):`${e}=${I(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ns(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Cs;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ps.decoder=new TextDecoder,Ps.OPERATIONS=re,Ps.CATEGORIES=h,Ps.ExponentialRetryPolicy=Le.ExponentialRetryPolicy,Ps.LinearRetryPolicy=Le.LinearRetryPolicy;class Ms{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class _s extends Ps{constructor(e){var t;const s=D(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=$(r,(e=>{if(e.cipherKey)return new P({default:new N(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new B(new Ms((e=>x(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new C;let h=new F(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new j({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _s.CryptoModule=P,_s})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class _{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},R=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},U=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class T{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?T.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?F(a):a})),n}T.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.10"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),Ae=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),_e=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(Ae.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(_e.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Fe=new ue("HEARTBEAT_COOLDOWN");Fe.onEnter((()=>Ie())),Fe.onExit((()=>Ie.cancel)),Fe.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[_e(t.payload.channels,t.payload.groups)]))),Fe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[_e(e.channels,e.groups)]))),Fe.on(Oe.type,((e,t)=>Ge.with(void 0,[_e(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[_e(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[_e(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[_e(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[_e(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[_e(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[_e(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>Ae(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[_e(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[_e(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[_e(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=R(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=R(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class _t extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Tt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Wt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Wt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>F(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new T(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new _({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index abe7ea21d..3d8b4ec58 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -17,7 +17,7 @@ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ - /* global Reflect, Promise, SuppressedError, Symbol */ + /* global Reflect, Promise, SuppressedError, Symbol, Iterator */ function __awaiter(thisArg, _arguments, P, generator) { @@ -89,6 +89,12 @@ var uuidExports = uuid.exports; var uuidGenerator$1 = /*@__PURE__*/getDefaultExportFromCjs(uuidExports); + /** + * Random identifier generator helper module. + * + * @internal + */ + /** @internal */ var uuidGenerator = { createUUID() { if (uuidGenerator$1.uuid) { @@ -105,6 +111,8 @@ * * Service worker provides support for PubNub subscription feature to give better user experience across * multiple opened pages. + * + * @internal */ /** * How often PING request should be sent to the PubNub clients. diff --git a/lib/cbor/common.js b/lib/cbor/common.js index bd5b2e965..aa7418d26 100644 --- a/lib/cbor/common.js +++ b/lib/cbor/common.js @@ -1,6 +1,8 @@ "use strict"; /** * Cbor decoder module. + * + * @internal */ Object.defineProperty(exports, "__esModule", { value: true }); /** diff --git a/lib/core/components/abort_signal.js b/lib/core/components/abort_signal.js index 59ca4f8f3..24c7a8dea 100644 --- a/lib/core/components/abort_signal.js +++ b/lib/core/components/abort_signal.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Event Engine managed effects terminate signal module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.AbortSignal = exports.AbortError = void 0; const subject_1 = require("./subject"); diff --git a/lib/core/components/base64_codec.js b/lib/core/components/base64_codec.js index aa22d1d64..817ce0e00 100644 --- a/lib/core/components/base64_codec.js +++ b/lib/core/components/base64_codec.js @@ -1,6 +1,12 @@ "use strict"; +/** + * Base64 support module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.encode = exports.decode = void 0; +exports.decode = decode; +exports.encode = encode; const BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; /** * Decode a Base64 encoded string. @@ -49,7 +55,6 @@ function decode(paddedInput) { } return data; } -exports.decode = decode; /** * Encode `ArrayBuffer` as a Base64 encoded string. * @@ -97,4 +102,3 @@ function encode(input) { } return base64; } -exports.encode = encode; diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index bd79ae66d..c0371ae2b 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -1,6 +1,8 @@ "use strict"; /** * {@link PubNub} client configuration module. + * + * @internal */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; @@ -22,7 +24,7 @@ const USE_RANDOM_INITIALIZATION_VECTOR = true; * Create {@link PubNub} client private configuration object. * * @param base - User- and platform-provided configuration. - * @param setupCryptoModule - Platform-provided {@link CryptoModule} configuration block. + * @param setupCryptoModule - Platform-provided {@link ICryptoModule} configuration block. * * @returns `PubNub` client private configuration. * @@ -110,7 +112,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.9'; + return '8.2.10'; }, getVersion() { return this.version; diff --git a/lib/core/components/cryptography/hmac-sha256.js b/lib/core/components/cryptography/hmac-sha256.js index 4b8616de3..b22f461a1 100644 --- a/lib/core/components/cryptography/hmac-sha256.js +++ b/lib/core/components/cryptography/hmac-sha256.js @@ -1,4 +1,9 @@ "use strict"; +/** + * CryptoJS implementation. + * + * @internal + */ /*eslint-disable */ /* CryptoJS v3.1.2 diff --git a/lib/core/components/cryptography/index.js b/lib/core/components/cryptography/index.js index fad0763a5..bfe47507e 100644 --- a/lib/core/components/cryptography/index.js +++ b/lib/core/components/cryptography/index.js @@ -1,6 +1,8 @@ "use strict"; /** * Legacy cryptography module. + * + * @internal */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; @@ -14,6 +16,8 @@ const hmac_sha256_1 = __importDefault(require("./hmac-sha256")); * @param b - Bytes array (buffer) which should be converted. * * @returns Word sized array. + * + * @internal */ /* eslint-disable @typescript-eslint/no-explicit-any */ function bufferToWordArray(b) { @@ -25,6 +29,11 @@ function bufferToWordArray(b) { // @ts-expect-error Bundled library without types. return hmac_sha256_1.default.lib.WordArray.create(wa, b.length); } +/** + * Legacy cryptography module for files and signature. + * + * @internal + */ class default_1 { constructor(configuration) { this.configuration = configuration; diff --git a/lib/core/components/deduping_manager.js b/lib/core/components/deduping_manager.js index ae7904bb3..c7310bd03 100644 --- a/lib/core/components/deduping_manager.js +++ b/lib/core/components/deduping_manager.js @@ -1,43 +1,78 @@ "use strict"; -/* */ +/** + * Messages de-duplication manager module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); -const hashCode = (payload) => { - let hash = 0; - if (payload.length === 0) - return hash; - for (let i = 0; i < payload.length; i += 1) { - const character = payload.charCodeAt(i); - hash = (hash << 5) - hash + character; // eslint-disable-line - hash = hash & hash; // eslint-disable-line - } - return hash; -}; +exports.DedupingManager = void 0; /** * Real-time events deduplication manager. * * @internal */ -class default_1 { - constructor({ config }) { +class DedupingManager { + /** + * Create and configure real-time events de-duplication manager. + * + * @param config - PubNub client configuration object. + */ + constructor({ maximumCacheSize }) { + this.maximumCacheSize = maximumCacheSize; this.hashHistory = []; - this._config = config; } + /** + * Compute unique real-time event payload key. + * + * @param message - Received real-time event payload for which unique key should be computed. + * @returns Unique real-time event payload key in messages cache. + */ getKey(message) { - const hashedPayload = hashCode(JSON.stringify(message.message)).toString(); - const timetoken = message.timetoken; - return `${timetoken}-${hashedPayload}`; + var _a; + return `${message.timetoken}-${this.hashCode(JSON.stringify((_a = message.message) !== null && _a !== void 0 ? _a : '')).toString()}`; } + /** + * Check whether there is similar message already received or not. + * + * @param message - Received real-time event payload which should be checked for duplicates. + * @returns `true` in case if similar payload already has been received before. + */ isDuplicate(message) { return this.hashHistory.includes(this.getKey(message)); } + /** + * Store received message to be used later for duplicate detection. + * + * @param message - Received real-time event payload. + */ addEntry(message) { - if (this.hashHistory.length >= this._config.maximumCacheSize) { + if (this.hashHistory.length >= this.maximumCacheSize) { this.hashHistory.shift(); } this.hashHistory.push(this.getKey(message)); } + /** + * Clean up cached messages. + */ clearHistory() { this.hashHistory = []; } + /** + * Compute message hash sum. + * + * @param payload - Received payload for which hash sum should be computed. + * @returns {number} - Resulting hash sum. + */ + hashCode(payload) { + let hash = 0; + if (payload.length === 0) + return hash; + for (let i = 0; i < payload.length; i += 1) { + const character = payload.charCodeAt(i); + hash = (hash << 5) - hash + character; // eslint-disable-line + hash = hash & hash; // eslint-disable-line + } + return hash; + } } -exports.default = default_1; +exports.DedupingManager = DedupingManager; diff --git a/lib/core/components/eventEmitter.js b/lib/core/components/eventEmitter.js index d995bd428..3a4146b7e 100644 --- a/lib/core/components/eventEmitter.js +++ b/lib/core/components/eventEmitter.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Real-time events emitter module. + * + * @internal + */ var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) diff --git a/lib/core/components/push_payload.js b/lib/core/components/push_payload.js index 005ffd348..2573a983c 100644 --- a/lib/core/components/push_payload.js +++ b/lib/core/components/push_payload.js @@ -22,6 +22,15 @@ exports.FCMNotificationPayload = exports.APNSNotificationPayload = void 0; * Base notification payload object. */ class BaseNotificationPayload { + /** + * Base notification provider payload object. + * + * @internal + * + * @param payload - Object which contains vendor-specific preformatted push notification payload. + * @param title - Notification main title. + * @param body - Notification body (main messages). + */ constructor(payload, title, body) { this._payload = payload; this.setDefaultPayloadStructure(); @@ -78,11 +87,15 @@ class BaseNotificationPayload { } /** * Platform-specific structure initialization. + * + * @internal */ setDefaultPayloadStructure() { } /** * Translate data object into PubNub push notification payload object. * + * @internal + * * @returns Preformatted push notification payload. */ toObject() { @@ -97,10 +110,14 @@ class APNSNotificationPayload extends BaseNotificationPayload { super(...arguments); /** * Type of push notification service for which payload will be created. + * + * @internal */ this._apnsPushType = 'apns'; /** * Whether resulting payload should trigger silent notification or not. + * + * @internal */ this._isSilent = false; } @@ -230,9 +247,21 @@ class APNSNotificationPayload extends BaseNotificationPayload { set silent(value) { this._isSilent = value; } + /** + * Setup push notification payload default content. + * + * @internal + */ setDefaultPayloadStructure() { this.payload.aps = { alert: {} }; } + /** + * Translate data object into PubNub push notification payload object. + * + * @internal + * + * @returns Preformatted push notification payload. + */ toObject() { const payload = Object.assign({}, this.payload); const { aps } = payload; @@ -262,6 +291,8 @@ class APNSNotificationPayload extends BaseNotificationPayload { /** * Create PubNub push notification service APNS2 configuration information object. * + * @internal + * * @param configuration - Source user-provided APNS2 configuration. * * @returns Preformatted for PubNub service APNS2 configuration information. @@ -284,6 +315,8 @@ class APNSNotificationPayload extends BaseNotificationPayload { /** * Create PubNub push notification service APNS2 target information object. * + * @internal + * * @param target - Source user-provided data. * * @returns Preformatted for PubNub service APNS2 target information. @@ -300,7 +333,7 @@ class APNSNotificationPayload extends BaseNotificationPayload { } exports.APNSNotificationPayload = APNSNotificationPayload; /** - * Message payload for Firebase Clouse Messaging service. + * Message payload for Firebase Cloud Messaging service. */ class FCMNotificationPayload extends BaseNotificationPayload { get payload() { @@ -398,9 +431,19 @@ class FCMNotificationPayload extends BaseNotificationPayload { this.payload.notification.icon = value; this._icon = value; } + /** + * Retrieve notifications grouping tag. + * + * @returns Notifications grouping tag. + */ get tag() { return this._tag; } + /** + * Update notifications grouping tag. + * + * @param value - String which will be used to group similar notifications in notification center. + */ set tag(value) { if (!value || !value.length) return; @@ -417,10 +460,22 @@ class FCMNotificationPayload extends BaseNotificationPayload { set silent(value) { this._isSilent = value; } + /** + * Setup push notification payload default content. + * + * @internal + */ setDefaultPayloadStructure() { this.payload.notification = {}; this.payload.data = {}; } + /** + * Translate data object into PubNub push notification payload object. + * + * @internal + * + * @returns Preformatted push notification payload. + */ toObject() { let data = Object.assign({}, this.payload.data); let notification = null; @@ -443,6 +498,14 @@ class FCMNotificationPayload extends BaseNotificationPayload { } exports.FCMNotificationPayload = FCMNotificationPayload; class NotificationsPayload { + /** + * Create push notification payload holder. + * + * @internal + * + * @param title - String which will be shown at the top of the notification (below app name). + * @param body - String with message which should be shown when user will check notification. + */ constructor(title, body) { this._payload = { apns: {}, fcm: {} }; this._title = title; @@ -450,6 +513,12 @@ class NotificationsPayload { this.apns = new APNSNotificationPayload(this._payload.apns, title, body); this.fcm = new FCMNotificationPayload(this._payload.fcm, title, body); } + /** + * Enable or disable push notification debugging message. + * + * @param value - Whether debug message from push notification scheduler should be published to the specific + * channel or not. + */ set debugging(value) { this._debugging = value; } @@ -527,7 +596,7 @@ class NotificationsPayload { * Build notifications platform for requested platforms. * * @param platforms - List of platforms for which payload should be added to final dictionary. Supported values: - * gcm, apns, and apns2. + * fcm, apns, and apns2. * * @returns Object with data, which can be sent with publish method call and trigger remote notifications for * specified platforms. diff --git a/lib/core/components/reconnection_manager.js b/lib/core/components/reconnection_manager.js index 731bd261e..5804ef9c4 100644 --- a/lib/core/components/reconnection_manager.js +++ b/lib/core/components/reconnection_manager.js @@ -3,6 +3,8 @@ * Subscription reconnection-manager. * * **Note:** Reconnection manger rely on legacy time-based availability check. + * + * @internal */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ReconnectionManager = void 0; diff --git a/lib/core/components/request.js b/lib/core/components/request.js index 0a2e3af5a..e62ba202c 100644 --- a/lib/core/components/request.js +++ b/lib/core/components/request.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Network request module. + * + * @internal + */ 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) { diff --git a/lib/core/components/stringify_buffer_keys.js b/lib/core/components/stringify_buffer_keys.js index c9c405834..4aa394b29 100644 --- a/lib/core/components/stringify_buffer_keys.js +++ b/lib/core/components/stringify_buffer_keys.js @@ -1,6 +1,11 @@ "use strict"; +/** + * CBOR support module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.stringifyBufferKeys = void 0; +exports.stringifyBufferKeys = stringifyBufferKeys; /** * Re-map CBOR object keys from potentially C buffer strings to actual strings. * @@ -34,4 +39,3 @@ function stringifyBufferKeys(obj) { }); return normalizedObject; } -exports.stringifyBufferKeys = stringifyBufferKeys; diff --git a/lib/core/components/subject.js b/lib/core/components/subject.js index e483d4954..950880fcb 100644 --- a/lib/core/components/subject.js +++ b/lib/core/components/subject.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Event Engine terminate signal listener module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Subject = void 0; /** diff --git a/lib/core/components/subscription-manager.js b/lib/core/components/subscription-manager.js index 1f5139485..e653bebae 100644 --- a/lib/core/components/subscription-manager.js +++ b/lib/core/components/subscription-manager.js @@ -1,6 +1,8 @@ "use strict"; /** * Subscription manager module. + * + * @internal */ var __rest = (this && this.__rest) || function (s, e) { var t = {}; @@ -20,8 +22,8 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.SubscriptionManager = void 0; const reconnection_manager_1 = require("./reconnection_manager"); const categories_1 = __importDefault(require("../constants/categories")); +const deduping_manager_1 = require("./deduping_manager"); const categories_2 = __importDefault(require("../constants/categories")); -const deduping_manager_1 = __importDefault(require("./deduping_manager")); /** * Subscription loop manager. * @@ -36,7 +38,7 @@ class SubscriptionManager { this.heartbeatCall = heartbeatCall; this.leaveCall = leaveCall; this.reconnectionManager = new reconnection_manager_1.ReconnectionManager(time); - this.dedupingManager = new deduping_manager_1.default({ config: this.configuration }); + this.dedupingManager = new deduping_manager_1.DedupingManager(this.configuration); this.heartbeatChannelGroups = {}; this.heartbeatChannels = {}; this.presenceChannelGroups = {}; @@ -290,7 +292,7 @@ class SubscriptionManager { } try { messages.forEach((message) => { - if (dedupeOnSubscribe) { + if (dedupeOnSubscribe && 'message' in message.data && 'timetoken' in message.data) { if (this.dedupingManager.isDuplicate(message.data)) return; this.dedupingManager.addEntry(message.data); diff --git a/lib/core/components/token_manager.js b/lib/core/components/token_manager.js index 422a7dd8c..91bac221a 100644 --- a/lib/core/components/token_manager.js +++ b/lib/core/components/token_manager.js @@ -1,6 +1,8 @@ "use strict"; /** * PubNub Access Token Manager module. + * + * @internal */ Object.defineProperty(exports, "__esModule", { value: true }); exports.TokenManager = void 0; diff --git a/lib/core/components/uuid.js b/lib/core/components/uuid.js index 4d1255653..3276fc346 100644 --- a/lib/core/components/uuid.js +++ b/lib/core/components/uuid.js @@ -1,9 +1,15 @@ "use strict"; +/** + * Random identifier generator helper module. + * + * @internal + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const lil_uuid_1 = __importDefault(require("lil-uuid")); +/** @internal */ exports.default = { createUUID() { if (lil_uuid_1.default.uuid) { diff --git a/lib/core/constants/operations.js b/lib/core/constants/operations.js index dc348150f..120c312a9 100644 --- a/lib/core/constants/operations.js +++ b/lib/core/constants/operations.js @@ -1,6 +1,8 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); -/* */ +/** + * Endpoint API operation types. + */ var RequestOperation; (function (RequestOperation) { // -------------------------------------------------------- @@ -235,7 +237,17 @@ var RequestOperation; // -------------------------------------------------------- // ---------------- Subscription Utility ------------------ // -------------------------------------------------------- + /** + * Initial event engine subscription handshake operation. + * + * @internal + */ RequestOperation["PNHandshakeOperation"] = "PNHandshakeOperation"; + /** + * Event engine subscription loop operation. + * + * @internal + */ RequestOperation["PNReceiveMessagesOperation"] = "PNReceiveMessagesOperation"; })(RequestOperation || (RequestOperation = {})); exports.default = RequestOperation; diff --git a/lib/core/endpoints/access_manager/audit.js b/lib/core/endpoints/access_manager/audit.js index a405e8010..e3a78d4bb 100644 --- a/lib/core/endpoints/access_manager/audit.js +++ b/lib/core/endpoints/access_manager/audit.js @@ -1,6 +1,8 @@ "use strict"; /** * PAM Audit REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/access_manager/grant.js b/lib/core/endpoints/access_manager/grant.js index 9ed997fae..d1b0735f8 100644 --- a/lib/core/endpoints/access_manager/grant.js +++ b/lib/core/endpoints/access_manager/grant.js @@ -1,6 +1,8 @@ "use strict"; /** * PAM Grant REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/access_manager/grant_token.js b/lib/core/endpoints/access_manager/grant_token.js index 8ed978a6d..5440ccc4e 100644 --- a/lib/core/endpoints/access_manager/grant_token.js +++ b/lib/core/endpoints/access_manager/grant_token.js @@ -1,6 +1,8 @@ "use strict"; /** * PAM Grant Token REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/access_manager/revoke_token.js b/lib/core/endpoints/access_manager/revoke_token.js index 03b9e4111..270365fda 100644 --- a/lib/core/endpoints/access_manager/revoke_token.js +++ b/lib/core/endpoints/access_manager/revoke_token.js @@ -1,6 +1,8 @@ "use strict"; /** * PAM Revoke Token REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/actions/add_message_action.js b/lib/core/endpoints/actions/add_message_action.js index 6003a9d7f..e9b368f9b 100644 --- a/lib/core/endpoints/actions/add_message_action.js +++ b/lib/core/endpoints/actions/add_message_action.js @@ -1,6 +1,8 @@ "use strict"; /** * Add Message Action REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/actions/get_message_actions.js b/lib/core/endpoints/actions/get_message_actions.js index caad2356c..e4f0eb11e 100644 --- a/lib/core/endpoints/actions/get_message_actions.js +++ b/lib/core/endpoints/actions/get_message_actions.js @@ -1,6 +1,8 @@ "use strict"; /** * Get Message Actions REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/actions/remove_message_action.js b/lib/core/endpoints/actions/remove_message_action.js index 9d3c94661..648d06159 100644 --- a/lib/core/endpoints/actions/remove_message_action.js +++ b/lib/core/endpoints/actions/remove_message_action.js @@ -1,6 +1,8 @@ "use strict"; /** * Remove Message Action REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/channel_groups/add_channels.js b/lib/core/endpoints/channel_groups/add_channels.js index 32eedf351..23468abe8 100644 --- a/lib/core/endpoints/channel_groups/add_channels.js +++ b/lib/core/endpoints/channel_groups/add_channels.js @@ -1,6 +1,8 @@ "use strict"; /** * Add channel group channels REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/channel_groups/delete_group.js b/lib/core/endpoints/channel_groups/delete_group.js index 618024148..adbb517f5 100644 --- a/lib/core/endpoints/channel_groups/delete_group.js +++ b/lib/core/endpoints/channel_groups/delete_group.js @@ -1,6 +1,8 @@ "use strict"; /** * Delete channel group REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/channel_groups/list_channels.js b/lib/core/endpoints/channel_groups/list_channels.js index 83101c9e9..1b0450c9e 100644 --- a/lib/core/endpoints/channel_groups/list_channels.js +++ b/lib/core/endpoints/channel_groups/list_channels.js @@ -1,6 +1,8 @@ "use strict"; /** * List channel group channels REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/channel_groups/list_groups.js b/lib/core/endpoints/channel_groups/list_groups.js index 06deb4a01..405a9a9aa 100644 --- a/lib/core/endpoints/channel_groups/list_groups.js +++ b/lib/core/endpoints/channel_groups/list_groups.js @@ -1,6 +1,8 @@ "use strict"; /** * List All Channel Groups REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/channel_groups/remove_channels.js b/lib/core/endpoints/channel_groups/remove_channels.js index 2afed498b..b4472116b 100644 --- a/lib/core/endpoints/channel_groups/remove_channels.js +++ b/lib/core/endpoints/channel_groups/remove_channels.js @@ -1,6 +1,8 @@ "use strict"; /** * Remove channel group channels REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/fetch_messages.js b/lib/core/endpoints/fetch_messages.js index dd94e6824..be7dc5327 100644 --- a/lib/core/endpoints/fetch_messages.js +++ b/lib/core/endpoints/fetch_messages.js @@ -1,6 +1,8 @@ "use strict"; /** * Fetch messages REST API module. + * + * @internal */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; diff --git a/lib/core/endpoints/file_upload/delete_file.js b/lib/core/endpoints/file_upload/delete_file.js index 0721e6f0a..f916e6653 100644 --- a/lib/core/endpoints/file_upload/delete_file.js +++ b/lib/core/endpoints/file_upload/delete_file.js @@ -1,6 +1,8 @@ "use strict"; /** * Delete file REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/file_upload/download_file.js b/lib/core/endpoints/file_upload/download_file.js index fb99ccc31..b1af54866 100644 --- a/lib/core/endpoints/file_upload/download_file.js +++ b/lib/core/endpoints/file_upload/download_file.js @@ -1,6 +1,8 @@ "use strict"; /** * Download File REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/file_upload/generate_upload_url.js b/lib/core/endpoints/file_upload/generate_upload_url.js index 3a1756610..5c621f062 100644 --- a/lib/core/endpoints/file_upload/generate_upload_url.js +++ b/lib/core/endpoints/file_upload/generate_upload_url.js @@ -1,6 +1,8 @@ "use strict"; /** * Generate file upload URL REST API request. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/file_upload/get_file_url.js b/lib/core/endpoints/file_upload/get_file_url.js index 5a17b3ab1..dd5a9646b 100644 --- a/lib/core/endpoints/file_upload/get_file_url.js +++ b/lib/core/endpoints/file_upload/get_file_url.js @@ -1,6 +1,8 @@ "use strict"; /** * File sharing REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/file_upload/list_files.js b/lib/core/endpoints/file_upload/list_files.js index 513fe6525..614de6471 100644 --- a/lib/core/endpoints/file_upload/list_files.js +++ b/lib/core/endpoints/file_upload/list_files.js @@ -1,6 +1,8 @@ "use strict"; /** * List Files REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/file_upload/publish_file.js b/lib/core/endpoints/file_upload/publish_file.js index 20c6d4c63..81e3e07fe 100644 --- a/lib/core/endpoints/file_upload/publish_file.js +++ b/lib/core/endpoints/file_upload/publish_file.js @@ -1,6 +1,8 @@ "use strict"; /** * Publish File Message REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/file_upload/send_file.js b/lib/core/endpoints/file_upload/send_file.js index 5041464d5..2f4512ea6 100644 --- a/lib/core/endpoints/file_upload/send_file.js +++ b/lib/core/endpoints/file_upload/send_file.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Share File API module. + * + * @internal + */ 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) { diff --git a/lib/core/endpoints/file_upload/upload-file.js b/lib/core/endpoints/file_upload/upload-file.js index 15546c973..ec8604e23 100644 --- a/lib/core/endpoints/file_upload/upload-file.js +++ b/lib/core/endpoints/file_upload/upload-file.js @@ -1,6 +1,8 @@ "use strict"; /** * Upload file REST API request. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/history/delete_messages.js b/lib/core/endpoints/history/delete_messages.js index 3c4814a80..2ded57b82 100644 --- a/lib/core/endpoints/history/delete_messages.js +++ b/lib/core/endpoints/history/delete_messages.js @@ -1,6 +1,8 @@ "use strict"; /** * Delete messages REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/history/get_history.js b/lib/core/endpoints/history/get_history.js index ff6c28dd7..7a8ac874e 100644 --- a/lib/core/endpoints/history/get_history.js +++ b/lib/core/endpoints/history/get_history.js @@ -1,6 +1,8 @@ "use strict"; /** * Get history REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/history/message_counts.js b/lib/core/endpoints/history/message_counts.js index d8641eede..07f236743 100644 --- a/lib/core/endpoints/history/message_counts.js +++ b/lib/core/endpoints/history/message_counts.js @@ -1,6 +1,8 @@ "use strict"; /** * Messages count REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/channel/get.js b/lib/core/endpoints/objects/channel/get.js index aa5b1830d..56caa61d1 100644 --- a/lib/core/endpoints/objects/channel/get.js +++ b/lib/core/endpoints/objects/channel/get.js @@ -1,6 +1,8 @@ "use strict"; /** * Get Channel Metadata REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/channel/get_all.js b/lib/core/endpoints/objects/channel/get_all.js index 133f31b88..d5decf2d9 100644 --- a/lib/core/endpoints/objects/channel/get_all.js +++ b/lib/core/endpoints/objects/channel/get_all.js @@ -1,6 +1,8 @@ "use strict"; /** * Get All Channel Metadata REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/channel/remove.js b/lib/core/endpoints/objects/channel/remove.js index 2b0db8890..3b5a3cdb3 100644 --- a/lib/core/endpoints/objects/channel/remove.js +++ b/lib/core/endpoints/objects/channel/remove.js @@ -1,6 +1,8 @@ "use strict"; /** * Remove Channel Metadata REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/channel/set.js b/lib/core/endpoints/objects/channel/set.js index b127ac4c1..676fffbb8 100644 --- a/lib/core/endpoints/objects/channel/set.js +++ b/lib/core/endpoints/objects/channel/set.js @@ -1,6 +1,8 @@ "use strict"; /** * Set Channel Metadata REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/member/get.js b/lib/core/endpoints/objects/member/get.js index b4bb3721d..b0c5c11e9 100644 --- a/lib/core/endpoints/objects/member/get.js +++ b/lib/core/endpoints/objects/member/get.js @@ -1,6 +1,8 @@ "use strict"; /** * Get Channel Members REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/member/set.js b/lib/core/endpoints/objects/member/set.js index d70f0c4d1..3578095c4 100644 --- a/lib/core/endpoints/objects/member/set.js +++ b/lib/core/endpoints/objects/member/set.js @@ -1,6 +1,8 @@ "use strict"; /** * Set Channel Members REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/membership/get.js b/lib/core/endpoints/objects/membership/get.js index 9173f4f39..76d1831e3 100644 --- a/lib/core/endpoints/objects/membership/get.js +++ b/lib/core/endpoints/objects/membership/get.js @@ -1,6 +1,8 @@ "use strict"; /** * Get UUID Memberships REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/membership/set.js b/lib/core/endpoints/objects/membership/set.js index 932cd8315..86643485e 100644 --- a/lib/core/endpoints/objects/membership/set.js +++ b/lib/core/endpoints/objects/membership/set.js @@ -1,6 +1,8 @@ "use strict"; /** * Set UUID Memberships REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/uuid/get.js b/lib/core/endpoints/objects/uuid/get.js index b0f5135c8..2f9705040 100644 --- a/lib/core/endpoints/objects/uuid/get.js +++ b/lib/core/endpoints/objects/uuid/get.js @@ -1,6 +1,8 @@ "use strict"; /** * Get UUID Metadata REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/uuid/get_all.js b/lib/core/endpoints/objects/uuid/get_all.js index 957225820..e95a18b9a 100644 --- a/lib/core/endpoints/objects/uuid/get_all.js +++ b/lib/core/endpoints/objects/uuid/get_all.js @@ -1,6 +1,8 @@ "use strict"; /** * Get All UUID Metadata REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/uuid/remove.js b/lib/core/endpoints/objects/uuid/remove.js index 09025de72..c97245691 100644 --- a/lib/core/endpoints/objects/uuid/remove.js +++ b/lib/core/endpoints/objects/uuid/remove.js @@ -1,6 +1,8 @@ "use strict"; /** * Remove UUID Metadata REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/objects/uuid/set.js b/lib/core/endpoints/objects/uuid/set.js index cdc3252e0..01af971eb 100644 --- a/lib/core/endpoints/objects/uuid/set.js +++ b/lib/core/endpoints/objects/uuid/set.js @@ -1,6 +1,8 @@ "use strict"; /** * Set UUID Metadata REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/presence/get_state.js b/lib/core/endpoints/presence/get_state.js index 76f447c62..ee37ee086 100644 --- a/lib/core/endpoints/presence/get_state.js +++ b/lib/core/endpoints/presence/get_state.js @@ -1,6 +1,8 @@ "use strict"; /** * Get Presence State REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/presence/heartbeat.js b/lib/core/endpoints/presence/heartbeat.js index d5925a85c..51bd2497c 100644 --- a/lib/core/endpoints/presence/heartbeat.js +++ b/lib/core/endpoints/presence/heartbeat.js @@ -1,6 +1,8 @@ "use strict"; /** * Announce heartbeat REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/presence/here_now.js b/lib/core/endpoints/presence/here_now.js index fd8319701..26db534af 100644 --- a/lib/core/endpoints/presence/here_now.js +++ b/lib/core/endpoints/presence/here_now.js @@ -1,6 +1,8 @@ "use strict"; /** * Channels / channel groups presence REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/presence/leave.js b/lib/core/endpoints/presence/leave.js index fd06272b6..7ed6e2f62 100644 --- a/lib/core/endpoints/presence/leave.js +++ b/lib/core/endpoints/presence/leave.js @@ -1,6 +1,8 @@ "use strict"; /** * Announce leave REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/presence/set_state.js b/lib/core/endpoints/presence/set_state.js index faba64205..eb7648474 100644 --- a/lib/core/endpoints/presence/set_state.js +++ b/lib/core/endpoints/presence/set_state.js @@ -1,6 +1,8 @@ "use strict"; /** * Set Presence State REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/presence/where_now.js b/lib/core/endpoints/presence/where_now.js index daa44632f..f2f5a7724 100644 --- a/lib/core/endpoints/presence/where_now.js +++ b/lib/core/endpoints/presence/where_now.js @@ -1,6 +1,8 @@ "use strict"; /** * `uuid` presence REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/push/add_push_channels.js b/lib/core/endpoints/push/add_push_channels.js index 9cc2257b0..8396d1d91 100644 --- a/lib/core/endpoints/push/add_push_channels.js +++ b/lib/core/endpoints/push/add_push_channels.js @@ -1,6 +1,8 @@ "use strict"; /** * Register Channels with Device push REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/push/list_push_channels.js b/lib/core/endpoints/push/list_push_channels.js index 0f55b55c2..1f62c8ff4 100644 --- a/lib/core/endpoints/push/list_push_channels.js +++ b/lib/core/endpoints/push/list_push_channels.js @@ -1,6 +1,8 @@ "use strict"; /** * List Device push enabled channels REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/push/push.js b/lib/core/endpoints/push/push.js index 5bd84beff..5d12c31c5 100644 --- a/lib/core/endpoints/push/push.js +++ b/lib/core/endpoints/push/push.js @@ -1,6 +1,8 @@ "use strict"; /** * Manage channels enabled for device push REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/push/remove_device.js b/lib/core/endpoints/push/remove_device.js index d3857c1fa..563e091d6 100644 --- a/lib/core/endpoints/push/remove_device.js +++ b/lib/core/endpoints/push/remove_device.js @@ -1,6 +1,8 @@ "use strict"; /** * Unregister Device push REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/push/remove_push_channels.js b/lib/core/endpoints/push/remove_push_channels.js index 7243bd2bd..8d7455b4a 100644 --- a/lib/core/endpoints/push/remove_push_channels.js +++ b/lib/core/endpoints/push/remove_push_channels.js @@ -1,6 +1,8 @@ "use strict"; /** * Unregister Channels from Device push REST API module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index 1563ff9a8..bb2d2e4c7 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -35,8 +35,6 @@ const WITH_PRESENCE = false; // region Types /** * PubNub-defined event types by payload. - * - * @internal */ var PubNubEventType; (function (PubNubEventType) { diff --git a/lib/core/endpoints/subscriptionUtils/handshake.js b/lib/core/endpoints/subscriptionUtils/handshake.js index fc13544b4..82898ad08 100644 --- a/lib/core/endpoints/subscriptionUtils/handshake.js +++ b/lib/core/endpoints/subscriptionUtils/handshake.js @@ -1,6 +1,8 @@ "use strict"; /** * Handshake subscribe REST API module. + * + * @internal */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; diff --git a/lib/core/endpoints/subscriptionUtils/receiveMessages.js b/lib/core/endpoints/subscriptionUtils/receiveMessages.js index f597d82fd..6c87e9aa8 100644 --- a/lib/core/endpoints/subscriptionUtils/receiveMessages.js +++ b/lib/core/endpoints/subscriptionUtils/receiveMessages.js @@ -1,6 +1,8 @@ "use strict"; /** * Receive messages subscribe REST API module. + * + * @internal */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; diff --git a/lib/core/interfaces/configuration.js b/lib/core/interfaces/configuration.js index cc1b1d96d..c11ca0d07 100644 --- a/lib/core/interfaces/configuration.js +++ b/lib/core/interfaces/configuration.js @@ -138,7 +138,7 @@ const setDefaults = (configuration) => { let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE; let fileUploadPublishRetryLimit = FILE_PUBLISH_RETRY_LIMIT; let dedupeOnSubscribe = DEDUPE_ON_SUBSCRIBE; - const maximumCacheSize = DEDUPE_CACHE_SIZE; + let maximumCacheSize = DEDUPE_CACHE_SIZE; let useRequestId = USE_REQUEST_ID; // @ts-expect-error Not documented legacy configuration options. if (configurationCopy.dedupeOnSubscribe !== undefined && typeof configurationCopy.dedupeOnSubscribe === 'boolean') { @@ -146,6 +146,11 @@ const setDefaults = (configuration) => { dedupeOnSubscribe = configurationCopy.dedupeOnSubscribe; } // @ts-expect-error Not documented legacy configuration options. + if (configurationCopy.maximumCacheSize !== undefined && typeof configurationCopy.maximumCacheSize === 'number') { + // @ts-expect-error Not documented legacy configuration options. + maximumCacheSize = configurationCopy.maximumCacheSize; + } + // @ts-expect-error Not documented legacy configuration options. if (configurationCopy.useRequestId !== undefined && typeof configurationCopy.useRequestId === 'boolean') { // @ts-expect-error Not documented legacy configuration options. useRequestId = configurationCopy.useRequestId; diff --git a/lib/core/interfaces/crypto-module.js b/lib/core/interfaces/crypto-module.js index d5efe74f4..934f0a868 100644 --- a/lib/core/interfaces/crypto-module.js +++ b/lib/core/interfaces/crypto-module.js @@ -48,6 +48,8 @@ class AbstractCryptoModule { // region Helpers /** * Retrieve list of module's cryptors. + * + * @internal */ getAllCryptors() { return [this.defaultCryptor, ...this.cryptors]; @@ -56,9 +58,13 @@ class AbstractCryptoModule { exports.AbstractCryptoModule = AbstractCryptoModule; /** * `String` to {@link ArrayBuffer} response decoder. + * + * @internal */ AbstractCryptoModule.encoder = new TextEncoder(); /** * {@link ArrayBuffer} to {@link string} decoder. + * + * @internal */ AbstractCryptoModule.decoder = new TextDecoder(); diff --git a/lib/core/pubnub-channel-groups.js b/lib/core/pubnub-channel-groups.js index 6a15691a5..61e882a89 100644 --- a/lib/core/pubnub-channel-groups.js +++ b/lib/core/pubnub-channel-groups.js @@ -17,12 +17,23 @@ const add_channels_1 = require("./endpoints/channel_groups/add_channels"); const list_channels_1 = require("./endpoints/channel_groups/list_channels"); const delete_group_1 = require("./endpoints/channel_groups/delete_group"); const list_groups_1 = require("./endpoints/channel_groups/list_groups"); -class PubnubChannelGroups { +/** + * PubNub Stream / Channel group API interface. + */ +class PubNubChannelGroups { + /** + * Create stream / channel group API access object. + * + * @param keySet - PubNub account keys set which should be used for REST API calls. + * @param sendRequest - Function which should be used to send REST API calls. + * + * @internal + */ constructor(keySet, /* eslint-disable @typescript-eslint/no-explicit-any */ sendRequest) { - this.keySet = keySet; this.sendRequest = sendRequest; + this.keySet = keySet; } /** * Fetch channel group channels. @@ -109,4 +120,4 @@ class PubnubChannelGroups { }); } } -exports.default = PubnubChannelGroups; +exports.default = PubNubChannelGroups; diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 4bf9662d1..988a5a186 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -1,4 +1,7 @@ "use strict"; +/** + * Core PubNub API module. + */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -143,6 +146,14 @@ class PubNubCore { return uuid_1.default.createUUID(); } // endregion + /** + * Create and configure PubNub client core. + * + * @param configuration - PubNub client core configuration. + * @returns Configured and ready to use PubNub client. + * + * @internal + */ constructor(configuration) { this._configuration = configuration.configuration; this.cryptography = configuration.cryptography; @@ -517,6 +528,8 @@ class PubNubCore { /** * Schedule request execution. * + * @internal + * * @param request - REST API request. * @param [callback] - Request completion handler callback. * @@ -762,6 +775,8 @@ class PubNubCore { * * **Note:** Method passed into managers to let them use it when required. * + * @internal + * * @param parameters - Request configuration parameters. * @param callback - Request completion handler callback. */ @@ -810,6 +825,8 @@ class PubNubCore { * * **Note:** Method passed into managers to let them use it when required. * + * @internal + * * @param parameters - Request configuration parameters. * @param callback - Request completion handler callback. */ @@ -865,6 +882,8 @@ class PubNubCore { /** * Event engine handshake subscribe. * + * @internal + * * @param parameters - Request configuration parameters. */ subscribeHandshake(parameters) { @@ -893,6 +912,8 @@ class PubNubCore { /** * Event engine receive messages subscribe. * + * @internal + * * @param parameters - Request configuration parameters. */ subscribeReceiveMessages(parameters) { @@ -1189,6 +1210,8 @@ class PubNubCore { /** * Announce user presence * + * @internal + * * @param parameters - Desired presence state for provided list of channels and groups. * @param callback - Request completion handler callback. */ @@ -1209,6 +1232,8 @@ class PubNubCore { /** * Announce user `join` on specified list of channels and groups. * + * @internal + * * @param parameters - List of channels and groups where `join` event should be sent. */ join(parameters) { @@ -1223,6 +1248,8 @@ class PubNubCore { /** * Announce user `leave` on specified list of channels and groups. * + * @internal + * * @param parameters - List of channels and groups where `leave` event should be sent. */ leave(parameters) { @@ -1234,6 +1261,8 @@ class PubNubCore { } /** * Announce user `leave` on all subscribed channels. + * + * @internal */ leaveAll() { var _a; @@ -1641,8 +1670,7 @@ class PubNubCore { * @returns Asynchronous memberships modification response or `void` in case if `callback` provided. * * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} - * methods instead - * from `objects` API group.. + * methods instead from `objects` API group. */ removeMemberships(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { diff --git a/lib/core/pubnub-objects.js b/lib/core/pubnub-objects.js index 9948ee382..e269be75a 100644 --- a/lib/core/pubnub-objects.js +++ b/lib/core/pubnub-objects.js @@ -24,13 +24,24 @@ const get_3 = require("./endpoints/objects/member/get"); const set_3 = require("./endpoints/objects/member/set"); const get_4 = require("./endpoints/objects/uuid/get"); const set_4 = require("./endpoints/objects/uuid/set"); +/** + * PubNub App Context API interface. + */ class PubNubObjects { + /** + * Create app context API access object. + * + * @param configuration - Extended PubNub client configuration object. + * @param sendRequest - Function which should be used to send REST API calls. + * + * @internal + */ constructor(configuration, /* eslint-disable @typescript-eslint/no-explicit-any */ sendRequest) { + this.keySet = configuration.keySet; this.configuration = configuration; this.sendRequest = sendRequest; - this.keySet = configuration.keySet; } /** * Fetch a paginated list of UUID Metadata objects. @@ -48,11 +59,12 @@ class PubNubObjects { /** * Fetch a paginated list of UUID Metadata objects. * - * * @param [parametersOrCallback] - Request configuration parameters or callback from overload. * @param [callback] - Request completion handler callback. * * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + * + * @internal */ _getAllUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { @@ -85,6 +97,8 @@ class PubNubObjects { * @param [callback] - Request completion handler callback. * * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + * + * @internal */ _getUUIDMetadata(parametersOrCallback, callback) { return __awaiter(this, void 0, void 0, function* () { @@ -118,6 +132,8 @@ class PubNubObjects { /** * Update specific UUID Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. Will set UUID metadata for currently * configured PubNub client `uuid` if not set. * @param [callback] - Request completion handler callback. @@ -152,6 +168,8 @@ class PubNubObjects { /** * Remove a specific UUID Metadata object. * + * @internal + * * @param [parametersOrCallback] - Request configuration parameters or callback from overload. * @param [callback] - Request completion handler callback. * @@ -189,6 +207,8 @@ class PubNubObjects { /** * Fetch a paginated list of Channel Metadata objects. * + * @internal + * * @param [parametersOrCallback] - Request configuration parameters or callback from overload. * @param [callback] - Request completion handler callback. * @@ -222,6 +242,8 @@ class PubNubObjects { /** * Fetch Channel Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. * @param [callback] - Request completion handler callback. * @@ -251,6 +273,8 @@ class PubNubObjects { /** * Update specific Channel Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. * @param [callback] - Request completion handler callback. * @@ -281,6 +305,8 @@ class PubNubObjects { /** * Remove a specific Channel Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. * @param [callback] - Request completion handler callback. * @@ -511,7 +537,6 @@ class PubNubObjects { uuids: (_c = (_b = spaceParameters.users) === null || _b === void 0 ? void 0 : _b.map((user) => { if (typeof user === 'string') return user; - user.userId; return { id: user.userId, custom: user.custom }; })) !== null && _c !== void 0 ? _c : spaceParameters.uuids, limit: 0, diff --git a/lib/core/pubnub-push.js b/lib/core/pubnub-push.js index 3fa4911f4..08c2a1b5e 100644 --- a/lib/core/pubnub-push.js +++ b/lib/core/pubnub-push.js @@ -16,12 +16,23 @@ const remove_push_channels_1 = require("./endpoints/push/remove_push_channels"); const list_push_channels_1 = require("./endpoints/push/list_push_channels"); const add_push_channels_1 = require("./endpoints/push/add_push_channels"); const remove_device_1 = require("./endpoints/push/remove_device"); +/** + * PubNub Push Notifications API interface. + */ class PubNubPushNotifications { + /** + * Create mobile push notifications API access object. + * + * @param keySet - PubNub account keys set which should be used for REST API calls. + * @param sendRequest - Function which should be used to send REST API calls. + * + * @internal + */ constructor(keySet, /* eslint-disable @typescript-eslint/no-explicit-any */ sendRequest) { - this.keySet = keySet; this.sendRequest = sendRequest; + this.keySet = keySet; } /** * Fetch device's push notification enabled channels. diff --git a/lib/core/utils.js b/lib/core/utils.js index bb200b5c0..d97cdc34b 100644 --- a/lib/core/utils.js +++ b/lib/core/utils.js @@ -1,4 +1,9 @@ "use strict"; +/** + * PubNub package utilities module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.queryStringFromObject = exports.findUniqueCommonElements = exports.removeSingleOccurrence = exports.encodeNames = exports.encodeString = void 0; /** @@ -9,6 +14,8 @@ exports.queryStringFromObject = exports.findUniqueCommonElements = exports.remov * @param input - Source string or number for encoding. * * @returns Percent-encoded string. + * + * @internal */ const encodeString = (input) => { return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); @@ -22,12 +29,17 @@ exports.encodeString = encodeString; * @param [defaultString] - String which should be used in case if {@link names} is empty. * * @returns String which contains encoded names joined by non-encoded `,`. + * + * @internal */ const encodeNames = (names, defaultString) => { const encodedNames = names.map((name) => (0, exports.encodeString)(name)); - return encodedNames.length ? encodedNames.join(',') : defaultString !== null && defaultString !== void 0 ? defaultString : ''; + return encodedNames.length ? encodedNames.join(',') : (defaultString !== null && defaultString !== void 0 ? defaultString : ''); }; exports.encodeNames = encodeNames; +/** + * @internal + */ const removeSingleOccurrence = (source, elementsToRemove) => { const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); return source.filter((e) => { @@ -39,6 +51,9 @@ const removeSingleOccurrence = (source, elementsToRemove) => { }); }; exports.removeSingleOccurrence = removeSingleOccurrence; +/** + * @internal + */ const findUniqueCommonElements = (a, b) => { return [...a].filter((value) => b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value)); }; @@ -49,6 +64,8 @@ exports.findUniqueCommonElements = findUniqueCommonElements; * @param query - Key / value pairs of the request query parameters. * * @returns Stringified query key / value pairs. + * + * @internal */ const queryStringFromObject = (query) => { return Object.keys(query) diff --git a/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js b/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js index b4f71ecd1..65b0093e3 100644 --- a/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js +++ b/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js @@ -1,6 +1,8 @@ "use strict"; /** * AES-CBC cryptor module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } @@ -18,6 +20,8 @@ const stream_1 = require("stream"); * AES-CBC cryptor. * * AES-CBC cryptor with enhanced cipher strength. + * + * @internal */ class AesCbcCryptor { constructor({ cipherKey }) { diff --git a/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js b/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js index a175eab75..0f0ac0fce 100644 --- a/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js +++ b/lib/crypto/modules/NodeCryptoModule/legacyCryptor.js @@ -1,6 +1,8 @@ "use strict"; /** * Legacy cryptor module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } @@ -21,6 +23,8 @@ const pubnub_error_1 = require("../../../errors/pubnub-error"); const node_1 = __importDefault(require("../node")); /** * Legacy cryptor. + * + * @internal */ class LegacyCryptor { constructor(config) { diff --git a/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js b/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js index 90e155a27..0b12321b5 100644 --- a/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js +++ b/lib/crypto/modules/NodeCryptoModule/nodeCryptoModule.js @@ -15,7 +15,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.CryptoModule = exports.AesCbcCryptor = exports.LegacyCryptor = void 0; +exports.NodeCryptoModule = exports.AesCbcCryptor = exports.LegacyCryptor = void 0; const stream_1 = require("stream"); const buffer_1 = require("buffer"); const crypto_module_1 = require("../../../core/interfaces/crypto-module"); @@ -28,7 +28,7 @@ exports.LegacyCryptor = legacyCryptor_1.default; /** * CryptoModule for Node.js platform. */ -class CryptoModule extends crypto_module_1.AbstractCryptoModule { +class NodeCryptoModule extends crypto_module_1.AbstractCryptoModule { // -------------------------------------------------------- // --------------- Convenience functions ------------------ // ------------------------------------------------------- @@ -70,15 +70,15 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { // region Encryption encrypt(data) { // Encrypt data. - const encrypted = data instanceof ArrayBuffer && this.defaultCryptor.identifier === CryptoModule.LEGACY_IDENTIFIER - ? this.defaultCryptor.encrypt(CryptoModule.decoder.decode(data)) + const encrypted = data instanceof ArrayBuffer && this.defaultCryptor.identifier === NodeCryptoModule.LEGACY_IDENTIFIER + ? this.defaultCryptor.encrypt(NodeCryptoModule.decoder.decode(data)) : this.defaultCryptor.encrypt(data); if (!encrypted.metadata) return encrypted.data; const headerData = this.getHeaderData(encrypted); // Write encrypted data payload content. const encryptedData = typeof encrypted.data === 'string' - ? CryptoModule.encoder.encode(encrypted.data).buffer + ? NodeCryptoModule.encoder.encode(encrypted.data).buffer : encrypted.data.buffer.slice(encrypted.data.byteOffset, encrypted.data.byteOffset + encrypted.data.length); return this.concatArrayBuffer(headerData, encryptedData); } @@ -95,7 +95,7 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { return File.create({ name: file.name, mimeType: 'application/octet-stream', - data: buffer_1.Buffer.from(typeof encryptedData === 'string' ? CryptoModule.encoder.encode(encryptedData) : encryptedData), + data: buffer_1.Buffer.from(typeof encryptedData === 'string' ? NodeCryptoModule.encoder.encode(encryptedData) : encryptedData), }); } if (file.data instanceof stream_1.Readable) { @@ -151,7 +151,7 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { * If It's legacy one then redirect it. * (as long as we support legacy need to check on instance type) */ - if ((cryptor === null || cryptor === void 0 ? void 0 : cryptor.identifier) === CryptoModule.LEGACY_IDENTIFIER) + if ((cryptor === null || cryptor === void 0 ? void 0 : cryptor.identifier) === NodeCryptoModule.LEGACY_IDENTIFIER) return cryptor.decryptFile(file, File); return File.create({ name: file.name, @@ -177,9 +177,11 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { * @returns Previously registered {@link ILegacyCryptor|legacy} cryptor. * * @throws Error if legacy cryptor not registered. + * + * @internal */ getLegacyCryptor() { - return this.getCryptorFromId(CryptoModule.LEGACY_IDENTIFIER); + return this.getCryptorFromId(NodeCryptoModule.LEGACY_IDENTIFIER); } /** * Retrieve registered cryptor by its identifier. @@ -189,6 +191,8 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { * @returns Registered cryptor with specified identifier. * * @throws Error if cryptor with specified {@link id} can't be found. + * + * @internal */ getCryptorFromId(id) { const cryptor = this.getAllCryptors().find((cryptor) => id === cryptor.identifier); @@ -202,6 +206,8 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { * @param header - Header with cryptor-defined data or raw cryptor identifier. * * @returns Cryptor which correspond to provided {@link header}. + * + * @internal */ getCryptor(header) { if (typeof header === 'string') { @@ -220,6 +226,8 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { * @param encrypted - Encryption data object as source for header data. * * @returns Binary representation of the cryptor header data. + * + * @internal */ getHeaderData(encrypted) { if (!encrypted.metadata) @@ -239,6 +247,8 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { * @param ab2 - Second {@link ArrayBuffer}. * * @returns Merged data as {@link ArrayBuffer}. + * + * @internal */ concatArrayBuffer(ab1, ab2) { const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); @@ -256,6 +266,8 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { * @returns Decrypted data as {@link PubNub} File object. * * @throws Error if file is empty or contains unsupported data type. + * + * @internal */ onStreamReadable(stream, file, File) { return __awaiter(this, void 0, void 0, function* () { @@ -294,6 +306,8 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { * @returns Decrypted data as {@link PubNub} File object. * * @throws Error if file is empty or contains unsupported data type. + * + * @internal */ decryptLegacyFileStream(stream, file, File) { return __awaiter(this, void 0, void 0, function* () { @@ -311,13 +325,15 @@ class CryptoModule extends crypto_module_1.AbstractCryptoModule { }); } } -exports.CryptoModule = CryptoModule; +exports.NodeCryptoModule = NodeCryptoModule; /** * {@link LegacyCryptor|Legacy} cryptor identifier. */ -CryptoModule.LEGACY_IDENTIFIER = ''; +NodeCryptoModule.LEGACY_IDENTIFIER = ''; /** * CryptorHeader Utility + * + * @internal */ class CryptorHeader { static from(id, metadata) { @@ -358,7 +374,7 @@ class CryptorHeader { if (encryptedData.byteLength >= 4) { sentinel = encryptedData.slice(0, 4); if (!this.isSentinel(sentinel)) - return CryptoModule.LEGACY_IDENTIFIER; + return NodeCryptoModule.LEGACY_IDENTIFIER; } if (encryptedData.byteLength >= 5) version = encryptedDataView.getInt8(4); @@ -393,6 +409,8 @@ CryptorHeader.MAX_VERSION = 1; CryptorHeader.MIN_HEADER_LENGTH = 10; /** * Cryptor header (v1). + * + * @internal */ class CryptorHeaderV1 { constructor(id, metadataLength) { diff --git a/lib/crypto/modules/node.js b/lib/crypto/modules/node.js index 55c7865c2..ac94318ba 100644 --- a/lib/crypto/modules/node.js +++ b/lib/crypto/modules/node.js @@ -1,6 +1,8 @@ "use strict"; /** * Legacy Node.js cryptography module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } @@ -17,6 +19,8 @@ const stream_1 = require("stream"); const buffer_1 = require("buffer"); /** * Legacy cryptography implementation for Node.js-based {@link PubNub} client. + * + * @internal */ class NodeCryptography { // -------------------------------------------------------- diff --git a/lib/entities/Channel.js b/lib/entities/Channel.js index 6b7958877..ceef481af 100644 --- a/lib/entities/Channel.js +++ b/lib/entities/Channel.js @@ -2,12 +2,36 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.Channel = void 0; const Subscription_1 = require("./Subscription"); +/** + * First-class objects which provides access to the channel-specific APIs. + */ class Channel { - constructor(channelName, eventEmitter, pubnub) { + /** + * Create simple channel entity. + * + * @param name - Name of the channel which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use channel entity. + * + * @internal + */ + constructor(name, eventEmitter, pubnub) { this.eventEmitter = eventEmitter; this.pubnub = pubnub; - this.name = channelName; + this.name = name; } + /** + * Create channel's subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific channel. + * + * @param [subscriptionOptions] - Channel's subscription object behavior customization options. + * + * @returns Configured and ready to use channel's subscription object. + */ subscription(subscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { return new Subscription_1.Subscription({ diff --git a/lib/entities/ChannelGroup.js b/lib/entities/ChannelGroup.js index 1245ca275..dfaa4dad8 100644 --- a/lib/entities/ChannelGroup.js +++ b/lib/entities/ChannelGroup.js @@ -2,12 +2,37 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.ChannelGroup = void 0; const Subscription_1 = require("./Subscription"); +/** + * First-class objects which provides access to the channel group-specific APIs. + */ class ChannelGroup { - constructor(channelGroup, eventEmitter, pubnub) { + /** + * Create simple channel entity. + * + * @param name - Name of the channel group which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel group's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use channel group entity. + * + * @internal + */ + constructor(name, eventEmitter, pubnub) { this.eventEmitter = eventEmitter; this.pubnub = pubnub; - this.name = channelGroup; + this.name = name; } + /** + * Create channel group's subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the channels in + * specific channel group. + * + * @param [subscriptionOptions] - Channel group's subscription object behavior customization options. + * + * @returns Configured and ready to use channel group's subscription object. + */ subscription(subscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { return new Subscription_1.Subscription({ diff --git a/lib/entities/ChannelMetadata.js b/lib/entities/ChannelMetadata.js index f5ee7a639..6cf436908 100644 --- a/lib/entities/ChannelMetadata.js +++ b/lib/entities/ChannelMetadata.js @@ -2,12 +2,37 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.ChannelMetadata = void 0; const Subscription_1 = require("./Subscription"); +/** + * First-class objects which provides access to the channel app context object-specific APIs. + */ class ChannelMetadata { + /** + * Create channel app context object entity. + * + * @param id - Channel app context object identifier which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use channel app context object entity. + * + * @internal + */ constructor(id, eventEmitter, pubnub) { - this.id = id; this.eventEmitter = eventEmitter; this.pubnub = pubnub; + this.id = id; } + /** + * Create channel's app context subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific channel + * app context object. + * + * @param [subscriptionOptions] - Channel's app context subscription object behavior customization options. + * + * @returns Configured and ready to use channel's app context subscription object. + */ subscription(subscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { return new Subscription_1.Subscription({ diff --git a/lib/entities/SubscribeCapable.js b/lib/entities/SubscribeCapable.js index 26d1c379a..42766f015 100644 --- a/lib/entities/SubscribeCapable.js +++ b/lib/entities/SubscribeCapable.js @@ -2,43 +2,111 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.SubscribeCapable = void 0; class SubscribeCapable { + /** + * Start receiving real-time updates. + * + * @param subscribeParameters - Additional subscription configuration options which should be used + * for request. + */ subscribe(subscribeParameters) { const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken; this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken }))); } + /** + * Stop real-time events processing. + */ unsubscribe() { this.pubnub.unsubscribe({ channels: this.channelNames, channelGroups: this.groupNames, }); } + /** + * Set new message handler. + * + * @param onMessageListener - Listener function, which will be called each time when a new message + * is received from the real-time network. + */ set onMessage(onMessageListener) { this.listener.message = onMessageListener; } + /** + * Set new presence events handler. + * + * @param onPresenceListener - Listener function, which will be called each time when a new + * presence event is received from the real-time network. + */ set onPresence(onPresenceListener) { this.listener.presence = onPresenceListener; } + /** + * Set new signal handler. + * + * @param onSignalListener - Listener function, which will be called each time when a new signal + * is received from the real-time network. + */ set onSignal(onSignalListener) { this.listener.signal = onSignalListener; } + /** + * Set new app context event handler. + * + * @param onObjectsListener - Listener function, which will be called each time when a new + * app context event is received from the real-time network. + */ set onObjects(onObjectsListener) { this.listener.objects = onObjectsListener; } + /** + * Set new message reaction event handler. + * + * @param messageActionEventListener - Listener function, which will be called each time when a + * new message reaction event is received from the real-time network. + */ set onMessageAction(messageActionEventListener) { this.listener.messageAction = messageActionEventListener; } + /** + * Set new file handler. + * + * @param fileEventListener - Listener function, which will be called each time when a new file + * is received from the real-time network. + */ set onFile(fileEventListener) { this.listener.file = fileEventListener; } + /** + * Set events handler. + * + * @param listener - Events listener configuration object, which lets specify handlers for multiple + * types of events. + */ addListener(listener) { this.eventEmitter.addListener(listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); } + /** + * Remove events handler. + * + * @param listener - Event listener configuration, which should be removed from the list of notified + * listeners. **Important:** Should be the same object which has been passed to the + * {@link addListener}. + */ removeListener(listener) { this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); } + /** + * Get list of channels which is used for subscription. + * + * @returns List of channel names. + */ get channels() { return this.channelNames.slice(0); } + /** + * Get list of channel groups which is used for subscription. + * + * @returns List of channel group names. + */ get channelGroups() { return this.groupNames.slice(0); } diff --git a/lib/entities/Subscription.js b/lib/entities/Subscription.js index e2aa6e8ba..8ce7ab186 100644 --- a/lib/entities/Subscription.js +++ b/lib/entities/Subscription.js @@ -3,10 +3,49 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.Subscription = void 0; const SubscribeCapable_1 = require("./SubscribeCapable"); const SubscriptionSet_1 = require("./SubscriptionSet"); +/** + * Single-entity subscription object which can be used to receive and handle real-time updates. + */ class Subscription extends SubscribeCapable_1.SubscribeCapable { + /** + * Create entity's subscription object. + * + * @param channels - List of channels which should be used in subscription loop. + * @param channelGroups - List of channel groups which should be used in subscription loop. + * @param subscriptionOptions - Per-entity subscription object configuration. + * @param eventEmitter - Event emitter, which will notify listeners about updates received for + * entity channels / groups. + * @param pubnub - PubNub instance which will perform subscribe / unsubscribe requests for entity. + * + * @returns Ready to use entity's subscription object. + * + * @internal + */ constructor({ channels, channelGroups, subscriptionOptions, eventEmitter, pubnub, }) { super(); + /** + * List of channel names for subscription loop. + * + * Entity may have few because of subscription configuration options. Presence events observing + * adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entity type, it may provide a list of channels which are used + * to receive real-time updates for it. + * + * @internal + */ this.channelNames = []; + /** + * List of channel group names for subscription loop. + * + * Entity may have few because of subscription configuration options. Presence events observing + * adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entity type, it may provide a list of channel groups which is + * sed to receive real-time updates for it. + * + * @internal + */ this.groupNames = []; this.channelNames = channels; this.groupNames = channelGroups; @@ -16,6 +55,12 @@ class Subscription extends SubscribeCapable_1.SubscribeCapable { this.listener = {}; eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); } + /** + * Merge entities' subscription objects into subscription set. + * + * @param subscription - Other entity's subscription object to be merged with receiver. + * @return Subscription set which contains both receiver and other entities' subscription objects. + */ addSubscription(subscription) { return new SubscriptionSet_1.SubscriptionSet({ channels: [...this.channelNames, ...subscription.channels], diff --git a/lib/entities/SubscriptionSet.js b/lib/entities/SubscriptionSet.js index 2f6c22efe..ac5816f8a 100644 --- a/lib/entities/SubscriptionSet.js +++ b/lib/entities/SubscriptionSet.js @@ -2,11 +2,63 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.SubscriptionSet = void 0; const SubscribeCapable_1 = require("./SubscribeCapable"); +/** + * Multiple entities subscription set object which can be used to receive and handle real-time + * updates. + * + * Subscription set object represent collection of per-entity subscription objects and allow + * processing them at once for subscription loop and events handling. + */ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { + /** + * Create entities' subscription set object. + * + * Subscription set object represent collection of per-entity subscription objects and allow + * processing them at once for subscription loop and events handling. + * + * @param channels - List of channels which should be used in subscription loop. + * @param channelGroups - List of channel groups which should be used in subscription loop. + * @param subscriptionOptions - Entities' subscription object configuration. + * @param eventEmitter - Event emitter, which will notify listeners about updates received for + * entities' channels / groups. + * @param pubnub - PubNub instance which will perform subscribe / unsubscribe requests for + * entities. + * + * @returns Ready to use entities' subscription set object. + * + * @internal + */ constructor({ channels = [], channelGroups = [], subscriptionOptions, eventEmitter, pubnub, }) { super(); + /** + * List of channel names for subscription loop. + * + * List of entities' names which can have additional entries depending on from configuration + * options. Presence events observing adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entities' type, they may provide a list of channels which are + * used to receive real-time updates for it. + * + * @internal + */ this.channelNames = []; + /** + * List of channel group names for subscription loop. + * + * List of entities' names which can have additional entries depending on from configuration + * options. Presence events observing adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entities' type, they may provide a list of channels which are + * used to receive real-time updates for it. + * + * @internal + */ this.groupNames = []; + /** + * List of per-entity subscription objects. + * + * @internal + */ this.subscriptionList = []; this.options = subscriptionOptions; this.eventEmitter = eventEmitter; @@ -24,12 +76,28 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.listener = {}; eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); } + /** + * Add additional entity's subscription to the subscription set. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#subscribe} call or + * next subscription loop. + * + * @param subscription - Other entity's subscription object, which should be added. + */ addSubscription(subscription) { this.subscriptionList.push(subscription); this.channelNames = [...this.channelNames, ...subscription.channels]; this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); } + /** + * Remove entity's subscription object from the set. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#unsubscribe} call or + * next subscription loop. + * + * @param subscription - Other entity's subscription object, which should be removed. + */ removeSubscription(subscription) { const channelsToRemove = subscription.channels; const groupsToRemove = subscription.channelGroups; @@ -38,12 +106,28 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); } + /** + * Merge with other subscription set object. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#subscribe} call or + * next subscription loop. + * + * @param subscriptionSet - Other entities' subscription set, which should be joined. + */ addSubscriptionSet(subscriptionSet) { this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); } + /** + * Subtract other subscription set object. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#unsubscribe} call or + * next subscription loop. + * + * @param subscriptionSet - Other entities' subscription set, which should be subtracted. + */ removeSubscriptionSet(subscriptionSet) { const channelsToRemove = subscriptionSet.channels; const groupsToRemove = subscriptionSet.channelGroups; @@ -52,6 +136,11 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); } + /** + * Get list of entities' subscription objects registered in subscription set. + * + * @returns Entities' subscription objects list. + */ get subscriptions() { return this.subscriptionList.slice(0); } diff --git a/lib/entities/UserMetadata.js b/lib/entities/UserMetadata.js index b740b04e9..2220983a3 100644 --- a/lib/entities/UserMetadata.js +++ b/lib/entities/UserMetadata.js @@ -2,12 +2,37 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.UserMetadata = void 0; const Subscription_1 = require("./Subscription"); +/** + * First-class objects which provides access to the user app context object-specific APIs. + */ class UserMetadata { + /** + * Create user app context object entity. + * + * @param id - User app context object identifier which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use user app context object entity. + * + * @internal + */ constructor(id, eventEmitter, pubnub) { - this.id = id; this.eventEmitter = eventEmitter; this.pubnub = pubnub; + this.id = id; } + /** + * Create user's app context subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific user + * app context object. + * + * @param [subscriptionOptions] - User's app context subscription object behavior customization options. + * + * @returns Configured and ready to use user's app context subscription object. + */ subscription(subscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { return new Subscription_1.Subscription({ diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js index 1f09b98b7..7ca6c7446 100644 --- a/lib/errors/pubnub-api-error.js +++ b/lib/errors/pubnub-api-error.js @@ -1,6 +1,8 @@ "use strict"; /** * REST API endpoint use error module. + * + * @internal */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; @@ -11,6 +13,8 @@ const categories_1 = __importDefault(require("../core/constants/categories")); const pubnub_error_1 = require("./pubnub-error"); /** * PubNub REST API call error. + * + * @internal */ class PubNubAPIError extends Error { /** diff --git a/lib/errors/pubnub-error.js b/lib/errors/pubnub-error.js index 40c24f8df..97c5938c4 100644 --- a/lib/errors/pubnub-error.js +++ b/lib/errors/pubnub-error.js @@ -1,11 +1,30 @@ "use strict"; +/** + * PubNub operation error module. + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.createValidationError = exports.PubNubError = void 0; +exports.PubNubError = void 0; +exports.createValidationError = createValidationError; const categories_1 = __importDefault(require("../core/constants/categories")); +/** + * PubNub operation error. + * + * When an operation can't be performed or there is an error from the server, this object will be returned. + */ class PubNubError extends Error { + /** + * Create PubNub operation error. + * + * @param message - Message with details about why operation failed. + * @param [status] - Additional information about performed operation. + * + * @returns Configured and ready to use PubNub operation error. + * + * @internal + */ constructor(message, status) { super(message); this.status = status; @@ -15,12 +34,30 @@ class PubNubError extends Error { } } exports.PubNubError = PubNubError; +/** + * Create error status object. + * + * @param errorPayload - Additional information which should be attached to the error status object. + * + * @returns Error status object. + * + * @internal + */ function createError(errorPayload) { var _a; (_a = errorPayload.statusCode) !== null && _a !== void 0 ? _a : (errorPayload.statusCode = 0); return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: categories_1.default.PNValidationErrorCategory, error: true }); } +/** + * Create operation arguments validation error status object. + * + * @param message - Information about failed validation requirement. + * @param [statusCode] - Operation HTTP status code. + * + * @returns Operation validation error status object. + * + * @internal + */ function createValidationError(message, statusCode) { return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {}))); } -exports.createValidationError = createValidationError; diff --git a/lib/event-engine/core/change.js b/lib/event-engine/core/change.js index 2b5963b5c..784342bb6 100644 --- a/lib/event-engine/core/change.js +++ b/lib/event-engine/core/change.js @@ -1,3 +1,7 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Event Engine Core state change module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/lib/event-engine/core/dispatcher.js b/lib/event-engine/core/dispatcher.js index 2be9c3fdf..f8bec4fff 100644 --- a/lib/event-engine/core/dispatcher.js +++ b/lib/event-engine/core/dispatcher.js @@ -1,7 +1,18 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Event Engine Core Effects dispatcher module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Dispatcher = void 0; +/** + * Event Engine effects dispatcher. + * + * Dispatcher responsible for invocation enqueue and dequeue for processing. + * + * @internal + */ class Dispatcher { constructor(dependencies) { this.dependencies = dependencies; diff --git a/lib/event-engine/core/engine.js b/lib/event-engine/core/engine.js index d94c9c482..f179af77d 100644 --- a/lib/event-engine/core/engine.js +++ b/lib/event-engine/core/engine.js @@ -1,9 +1,19 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Event Engine Core module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Engine = void 0; +/* eslint-disable @typescript-eslint/no-explicit-any */ const subject_1 = require("../../core/components/subject"); const state_1 = require("./state"); +/** + * Generic event engine. + * + * @internal + */ class Engine extends subject_1.Subject { describe(label) { return new state_1.State(label); diff --git a/lib/event-engine/core/handler.js b/lib/event-engine/core/handler.js index de66460b8..ef513bd1e 100644 --- a/lib/event-engine/core/handler.js +++ b/lib/event-engine/core/handler.js @@ -1,7 +1,19 @@ "use strict"; +/** + * Event Engine Core Effects handler module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.asyncHandler = exports.Handler = void 0; const abort_signal_1 = require("../../core/components/abort_signal"); +/** + * Synchronous (short-term) effect invocation handler. + * + * Handler manages effect execution on behalf of effect dispatcher. + * + * @internal + */ class Handler { constructor(payload, dependencies) { this.payload = payload; @@ -9,6 +21,13 @@ class Handler { } } exports.Handler = Handler; +/** + * Asynchronous (long-running) effect invocation handler. + * + * Handler manages effect execution on behalf of effect dispatcher. + * + * @internal + */ class AsyncHandler extends Handler { constructor(payload, dependencies, asyncFunction) { super(payload, dependencies); @@ -25,5 +44,12 @@ class AsyncHandler extends Handler { this.abortSignal.abort(); } } +/** + * Asynchronous effect invocation handler constructor. + * + * @param handlerFunction - Function which performs asynchronous action and should be called on `start`. + * + * @internal + */ const asyncHandler = (handlerFunction) => (payload, dependencies) => new AsyncHandler(payload, dependencies, handlerFunction); exports.asyncHandler = asyncHandler; diff --git a/lib/event-engine/core/index.js b/lib/event-engine/core/index.js index cfbd46c15..39a7e92f3 100644 --- a/lib/event-engine/core/index.js +++ b/lib/event-engine/core/index.js @@ -1,13 +1,22 @@ "use strict"; +/** + * Event Engine module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.asyncHandler = exports.createManagedEffect = exports.createEffect = exports.createEvent = exports.Dispatcher = exports.Engine = void 0; +/** @internal */ var engine_1 = require("./engine"); Object.defineProperty(exports, "Engine", { enumerable: true, get: function () { return engine_1.Engine; } }); +/** @internal */ var dispatcher_1 = require("./dispatcher"); Object.defineProperty(exports, "Dispatcher", { enumerable: true, get: function () { return dispatcher_1.Dispatcher; } }); +/** @internal */ var types_1 = require("./types"); Object.defineProperty(exports, "createEvent", { enumerable: true, get: function () { return types_1.createEvent; } }); Object.defineProperty(exports, "createEffect", { enumerable: true, get: function () { return types_1.createEffect; } }); Object.defineProperty(exports, "createManagedEffect", { enumerable: true, get: function () { return types_1.createManagedEffect; } }); +/** @internal */ var handler_1 = require("./handler"); Object.defineProperty(exports, "asyncHandler", { enumerable: true, get: function () { return handler_1.asyncHandler; } }); diff --git a/lib/event-engine/core/retryPolicy.js b/lib/event-engine/core/retryPolicy.js index f822b4979..28cc74b6f 100644 --- a/lib/event-engine/core/retryPolicy.js +++ b/lib/event-engine/core/retryPolicy.js @@ -1,6 +1,9 @@ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RetryPolicy = void 0; +/** + * Failed request retry policy. + */ class RetryPolicy { static LinearRetryPolicy(configuration) { return { diff --git a/lib/event-engine/core/state.js b/lib/event-engine/core/state.js index 06d02193c..f873b0958 100644 --- a/lib/event-engine/core/state.js +++ b/lib/event-engine/core/state.js @@ -1,7 +1,18 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Event Engine Core state module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.State = void 0; +/** + * Event engine current state object. + * + * State contains current context and list of invocations which should be performed by the Event Engine. + * + * @internal + */ class State { transition(context, event) { var _a; diff --git a/lib/event-engine/core/types.js b/lib/event-engine/core/types.js index 8d5546c4b..f9953adf1 100644 --- a/lib/event-engine/core/types.js +++ b/lib/event-engine/core/types.js @@ -1,7 +1,18 @@ "use strict"; -/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Event Engine Core types module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.createManagedEffect = exports.createEffect = exports.createEvent = void 0; +exports.createEvent = createEvent; +exports.createEffect = createEffect; +exports.createManagedEffect = createManagedEffect; +/** + * Create and configure event engine event. + * + * @internal + */ function createEvent(type, fn) { const creator = function (...args) { return { @@ -12,7 +23,11 @@ function createEvent(type, fn) { creator.type = type; return creator; } -exports.createEvent = createEvent; +/** + * Create and configure short-term effect invocation. + * + * @internal + */ function createEffect(type, fn) { const creator = (...args) => { return { type, payload: fn(...args), managed: false }; @@ -20,7 +35,11 @@ function createEffect(type, fn) { creator.type = type; return creator; } -exports.createEffect = createEffect; +/** + * Create and configure long-running effect invocation. + * + * @internal + */ function createManagedEffect(type, fn) { const creator = (...args) => { return { type, payload: fn(...args), managed: true }; @@ -29,4 +48,3 @@ function createManagedEffect(type, fn) { creator.cancel = { type: 'CANCEL', payload: type, managed: false }; return creator; } -exports.createManagedEffect = createManagedEffect; diff --git a/lib/event-engine/dispatcher.js b/lib/event-engine/dispatcher.js index c8e3c2ddb..b09274532 100644 --- a/lib/event-engine/dispatcher.js +++ b/lib/event-engine/dispatcher.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Subscribe Event Engine effects dispatcher. + * + * @internal + */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -41,6 +46,13 @@ const core_1 = require("./core"); const effects = __importStar(require("./effects")); const events = __importStar(require("./events")); const categories_1 = __importDefault(require("../core/constants/categories")); +/** + * Subscribe Event Engine dispatcher. + * + * Dispatcher responsible for subscription events handling and corresponding effects execution. + * + * @internal + */ class EventEngineDispatcher extends core_1.Dispatcher { constructor(engine, dependencies) { super(dependencies); @@ -58,7 +70,7 @@ class EventEngineDispatcher extends core_1.Dispatcher { } } }))); - this.on(effects.receiveMessages.type, (0, core_1.asyncHandler)((payload_2, abortSignal_2, _b) => __awaiter(this, [payload_2, abortSignal_2, _b], void 0, function* (payload, abortSignal, { receiveMessages, config }) { + this.on(effects.receiveMessages.type, (0, core_1.asyncHandler)((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { receiveMessages, config }) { abortSignal.throwIfAborted(); try { const result = yield receiveMessages({ @@ -80,15 +92,15 @@ class EventEngineDispatcher extends core_1.Dispatcher { } } }))); - this.on(effects.emitMessages.type, (0, core_1.asyncHandler)((payload_3, _1, _c) => __awaiter(this, [payload_3, _1, _c], void 0, function* (payload, _, { emitMessages }) { + this.on(effects.emitMessages.type, (0, core_1.asyncHandler)((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitMessages }) { if (payload.length > 0) { emitMessages(payload); } }))); - this.on(effects.emitStatus.type, (0, core_1.asyncHandler)((payload_4, _2, _d) => __awaiter(this, [payload_4, _2, _d], void 0, function* (payload, _, { emitStatus }) { + this.on(effects.emitStatus.type, (0, core_1.asyncHandler)((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus }) { emitStatus(payload); }))); - this.on(effects.receiveReconnect.type, (0, core_1.asyncHandler)((payload_5, abortSignal_3, _e) => __awaiter(this, [payload_5, abortSignal_3, _e], void 0, function* (payload, abortSignal, { receiveMessages, delay, config }) { + this.on(effects.receiveReconnect.type, (0, core_1.asyncHandler)((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { receiveMessages, delay, config }) { if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { abortSignal.throwIfAborted(); yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); @@ -118,7 +130,7 @@ class EventEngineDispatcher extends core_1.Dispatcher { : 'Unable to complete subscribe messages receive.'))); } }))); - this.on(effects.handshakeReconnect.type, (0, core_1.asyncHandler)((payload_6, abortSignal_4, _f) => __awaiter(this, [payload_6, abortSignal_4, _f], void 0, function* (payload, abortSignal, { handshake, delay, presenceState, config }) { + this.on(effects.handshakeReconnect.type, (0, core_1.asyncHandler)((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { handshake, delay, presenceState, config }) { if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { abortSignal.throwIfAborted(); yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); diff --git a/lib/event-engine/effects.js b/lib/event-engine/effects.js index 2c788f77c..96078052c 100644 --- a/lib/event-engine/effects.js +++ b/lib/event-engine/effects.js @@ -1,13 +1,61 @@ "use strict"; +/** + * Subscribe Event Engine effects module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.handshakeReconnect = exports.receiveReconnect = exports.emitStatus = exports.emitMessages = exports.receiveMessages = exports.handshake = void 0; const core_1 = require("./core"); +/** + * Initial subscription effect. + * + * Performs subscribe REST API call with `tt=0`. + * + * @internal + */ exports.handshake = (0, core_1.createManagedEffect)('HANDSHAKE', (channels, groups) => ({ channels, groups, })); +/** + * Real-time updates receive effect. + * + * Performs sequential subscribe REST API call with `tt` set to the value received from the previous subscribe + * REST API call. + * + * @internal + */ exports.receiveMessages = (0, core_1.createManagedEffect)('RECEIVE_MESSAGES', (channels, groups, cursor) => ({ channels, groups, cursor })); +/** + * Emit real-time updates effect. + * + * Notify event listeners about updates for which listener handlers has been provided. + * + * @internal + */ exports.emitMessages = (0, core_1.createEffect)('EMIT_MESSAGES', (events) => events); +/** + * Emit subscription status change effect. + * + * Notify status change event listeners. + * + * @internal + */ exports.emitStatus = (0, core_1.createEffect)('EMIT_STATUS', (status) => status); +/** + * Real-time updates receive restore effect. + * + * Performs subscribe REST API call with `tt` which has been received before disconnection or error. + * + * @internal + */ exports.receiveReconnect = (0, core_1.createManagedEffect)('RECEIVE_RECONNECT', (context) => context); +/** + * Initial subscription restore effect. + * + * Performs subscribe REST API call with `tt=0` after error. + * + * @internal + */ exports.handshakeReconnect = (0, core_1.createManagedEffect)('HANDSHAKE_RECONNECT', (context) => context); diff --git a/lib/event-engine/events.js b/lib/event-engine/events.js index 3725ca704..499e064b0 100644 --- a/lib/event-engine/events.js +++ b/lib/event-engine/events.js @@ -1,11 +1,30 @@ "use strict"; +/** + * Subscribe Event Engine events module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.unsubscribeAll = exports.reconnect = exports.disconnect = exports.receiveReconnectGiveup = exports.receiveReconnectFailure = exports.receiveReconnectSuccess = exports.receiveFailure = exports.receiveSuccess = exports.handshakeReconnectGiveup = exports.handshakeReconnectFailure = exports.handshakeReconnectSuccess = exports.handshakeFailure = exports.handshakeSuccess = exports.restore = exports.subscriptionChange = void 0; const core_1 = require("./core"); +/** + * Subscription list change event. + * + * Event is sent each time when user would like to change list of active channels / groups. + * + * @internal + */ exports.subscriptionChange = (0, core_1.createEvent)('SUBSCRIPTION_CHANGED', (channels, groups) => ({ channels, groups, })); +/** + * Subscription loop restore. + * + * Event is sent when user would like to try catch up on missed updates by providing specific timetoken. + * + * @internal + */ exports.restore = (0, core_1.createEvent)('SUBSCRIPTION_RESTORED', (channels, groups, timetoken, region) => ({ channels, groups, @@ -14,29 +33,120 @@ exports.restore = (0, core_1.createEvent)('SUBSCRIPTION_RESTORED', (channels, gr region: region !== null && region !== void 0 ? region : 0, }, })); +/** + * Initial subscription handshake success event. + * + * Event is sent by corresponding effect handler if REST API call was successful. + * + * @internal + */ exports.handshakeSuccess = (0, core_1.createEvent)('HANDSHAKE_SUCCESS', (cursor) => cursor); +/** + * Initial subscription handshake did fail event. + * + * Event is sent by corresponding effect handler if REST API call failed. + * + * @internal + */ exports.handshakeFailure = (0, core_1.createEvent)('HANDSHAKE_FAILURE', (error) => error); +/** + * Initial subscription handshake reconnect success event. + * + * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. + * + * @internal + */ exports.handshakeReconnectSuccess = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_SUCCESS', (cursor) => ({ cursor, })); +/** + * Initial subscription handshake reconnect did fail event. + * + * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. + * + * @internal + */ exports.handshakeReconnectFailure = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_FAILURE', (error) => error); +/** + * Initial subscription handshake impossible event. + * + * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. + * + * @internal + */ exports.handshakeReconnectGiveup = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_GIVEUP', (error) => error); +/** + * Subscription successfully received real-time updates event. + * + * Event is sent by corresponding effect handler if REST API call was successful. + * + * @internal + */ exports.receiveSuccess = (0, core_1.createEvent)('RECEIVE_SUCCESS', (cursor, events) => ({ cursor, events, })); +/** + * Subscription did fail to receive real-time updates event. + * + * Event is sent by corresponding effect handler if REST API call failed. + * + * @internal + */ exports.receiveFailure = (0, core_1.createEvent)('RECEIVE_FAILURE', (error) => error); +/** + * Subscription successfully received real-time updates on reconnection attempt event. + * + * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. + * + * @internal + */ exports.receiveReconnectSuccess = (0, core_1.createEvent)('RECEIVE_RECONNECT_SUCCESS', (cursor, events) => ({ cursor, events, })); +/** + * Subscription did fail to receive real-time updates on reconnection attempt event. + * + * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. + * + * @internal + */ exports.receiveReconnectFailure = (0, core_1.createEvent)('RECEIVE_RECONNECT_FAILURE', (error) => error); +/** + * Subscription real-time updates received impossible event. + * + * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. + * + * @internal + */ exports.receiveReconnectGiveup = (0, core_1.createEvent)('RECEIVING_RECONNECT_GIVEUP', (error) => error); +/** + * Client disconnect event. + * + * Event is sent when user wants to temporarily stop real-time updates receive. + * + * @internal + */ exports.disconnect = (0, core_1.createEvent)('DISCONNECT', () => ({})); +/** + * Client reconnect event. + * + * Event is sent when user wants to restore real-time updates receive. + * + * @internal + */ exports.reconnect = (0, core_1.createEvent)('RECONNECT', (timetoken, region) => ({ cursor: { timetoken: timetoken !== null && timetoken !== void 0 ? timetoken : '', region: region !== null && region !== void 0 ? region : 0, }, })); +/** + * Completely stop real-time updates receive event. + * + * Event is sent when user doesn't want to receive any real-time updates anymore. + * + * @internal + */ exports.unsubscribeAll = (0, core_1.createEvent)('UNSUBSCRIBE_ALL', () => ({})); diff --git a/lib/event-engine/index.js b/lib/event-engine/index.js index 697416481..255b7bfbd 100644 --- a/lib/event-engine/index.js +++ b/lib/event-engine/index.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Subscribe Event Engine module. + * + * @internal + */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -29,6 +34,11 @@ const dispatcher_1 = require("./dispatcher"); const events = __importStar(require("./events")); const unsubscribed_1 = require("./states/unsubscribed"); const utils = __importStar(require("../core/utils")); +/** + * Subscribe Event Engine Core. + * + * @internal + */ class EventEngine { get _engine() { return this.engine; diff --git a/lib/event-engine/presence/dispatcher.js b/lib/event-engine/presence/dispatcher.js index e38d0f967..c4f0ebef2 100644 --- a/lib/event-engine/presence/dispatcher.js +++ b/lib/event-engine/presence/dispatcher.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Presence Event Engine effects dispatcher. + * + * @internal + */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -42,6 +47,13 @@ const pubnub_error_1 = require("../../errors/pubnub-error"); const effects = __importStar(require("./effects")); const events = __importStar(require("./events")); const categories_1 = __importDefault(require("../../core/constants/categories")); +/** + * Presence Event Engine dispatcher. + * + * Dispatcher responsible for presence events handling and corresponding effects execution. + * + * @internal + */ class PresenceEventEngineDispatcher extends core_1.Dispatcher { constructor(engine, dependencies) { super(dependencies); @@ -58,7 +70,7 @@ class PresenceEventEngineDispatcher extends core_1.Dispatcher { } } }))); - this.on(effects.leave.type, (0, core_1.asyncHandler)((payload_2, _2, _b) => __awaiter(this, [payload_2, _2, _b], void 0, function* (payload, _, { leave, config }) { + this.on(effects.leave.type, (0, core_1.asyncHandler)((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { leave, config }) { if (!config.suppressLeaveEvents) { try { leave({ @@ -69,13 +81,13 @@ class PresenceEventEngineDispatcher extends core_1.Dispatcher { catch (e) { } } }))); - this.on(effects.wait.type, (0, core_1.asyncHandler)((_3, abortSignal_1, _c) => __awaiter(this, [_3, abortSignal_1, _c], void 0, function* (_, abortSignal, { heartbeatDelay }) { + this.on(effects.wait.type, (0, core_1.asyncHandler)((_1, abortSignal_1, _a) => __awaiter(this, [_1, abortSignal_1, _a], void 0, function* (_, abortSignal, { heartbeatDelay }) { abortSignal.throwIfAborted(); yield heartbeatDelay(); abortSignal.throwIfAborted(); return engine.transition(events.timesUp()); }))); - this.on(effects.delayedHeartbeat.type, (0, core_1.asyncHandler)((payload_3, abortSignal_2, _d) => __awaiter(this, [payload_3, abortSignal_2, _d], void 0, function* (payload, abortSignal, { heartbeat, retryDelay, presenceState, config }) { + this.on(effects.delayedHeartbeat.type, (0, core_1.asyncHandler)((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { heartbeat, retryDelay, presenceState, config }) { if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { abortSignal.throwIfAborted(); yield retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); @@ -96,9 +108,9 @@ class PresenceEventEngineDispatcher extends core_1.Dispatcher { return engine.transition(events.heartbeatGiveup()); } }))); - this.on(effects.emitStatus.type, (0, core_1.asyncHandler)((payload_4, _4, _e) => __awaiter(this, [payload_4, _4, _e], void 0, function* (payload, _, { emitStatus, config }) { - var _f; - if (config.announceFailedHeartbeats && ((_f = payload === null || payload === void 0 ? void 0 : payload.status) === null || _f === void 0 ? void 0 : _f.error) === true) { + this.on(effects.emitStatus.type, (0, core_1.asyncHandler)((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus, config }) { + var _b; + if (config.announceFailedHeartbeats && ((_b = payload === null || payload === void 0 ? void 0 : payload.status) === null || _b === void 0 ? void 0 : _b.error) === true) { emitStatus(payload.status); } else if (config.announceSuccessfulHeartbeats && payload.statusCode === 200) { diff --git a/lib/event-engine/presence/effects.js b/lib/event-engine/presence/effects.js index d6f4d5671..16c0a43bb 100644 --- a/lib/event-engine/presence/effects.js +++ b/lib/event-engine/presence/effects.js @@ -1,16 +1,56 @@ "use strict"; +/** + * Presence Event Engine effects module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.delayedHeartbeat = exports.wait = exports.emitStatus = exports.leave = exports.heartbeat = void 0; const core_1 = require("../core"); +/** + * Presence heartbeat effect. + * + * Performs presence heartbeat REST API call. + * + * @internal + */ exports.heartbeat = (0, core_1.createEffect)('HEARTBEAT', (channels, groups) => ({ channels, groups, })); +/** + * Presence leave effect. + * + * Performs presence leave REST API call. + * + * @internal + */ exports.leave = (0, core_1.createEffect)('LEAVE', (channels, groups) => ({ channels, groups, })); +/** + * Emit presence heartbeat REST API call result status effect. + * + * Notify status change event listeners. + * + * @internal + */ /* eslint-disable @typescript-eslint/no-explicit-any */ exports.emitStatus = (0, core_1.createEffect)('EMIT_STATUS', (status) => status); +/** + * Heartbeat delay effect. + * + * Delay of configured length (heartbeat interval) before another heartbeat REST API call will be done. + * + * @internal + */ exports.wait = (0, core_1.createManagedEffect)('WAIT', () => ({})); +/** + * Delayed heartbeat effect. + * + * Similar to the {@link wait} effect but used in case if previous heartbeat call did fail. + * + * @internal + */ exports.delayedHeartbeat = (0, core_1.createManagedEffect)('DELAYED_HEARTBEAT', (context) => context); diff --git a/lib/event-engine/presence/events.js b/lib/event-engine/presence/events.js index 58bdd3e8c..625408642 100644 --- a/lib/event-engine/presence/events.js +++ b/lib/event-engine/presence/events.js @@ -1,19 +1,92 @@ "use strict"; +/** + * Presence Event Engine events module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.timesUp = exports.heartbeatGiveup = exports.heartbeatFailure = exports.heartbeatSuccess = exports.leftAll = exports.left = exports.joined = exports.disconnect = exports.reconnect = void 0; const core_1 = require("../core"); +/** + * Reconnect event. + * + * Event is sent each time when user restores real-time updates processing and notifies other present subscribers + * about joining back. + * + * @internal + */ exports.reconnect = (0, core_1.createEvent)('RECONNECT', () => ({})); +/** + * Disconnect event. + * + * Event is sent when user wants to temporarily stop real-time updates processing and notifies other present + * subscribers about leaving. + * + * @internal + */ exports.disconnect = (0, core_1.createEvent)('DISCONNECT', () => ({})); +/** + * Channel / group join event. + * + * Event is sent when user adds new channels / groups to the active channels / groups list and notifies other present + * subscribers about joining. + * + * @internal + */ exports.joined = (0, core_1.createEvent)('JOINED', (channels, groups) => ({ channels, groups, })); +/** + * Channel / group leave event. + * + * Event is sent when user removes channels / groups from the active channels / groups list and notifies other present + * subscribers about leaving. + * + * @internal + */ exports.left = (0, core_1.createEvent)('LEFT', (channels, groups) => ({ channels, groups, })); +/** + * Leave all event. + * + * Event is sent when user doesn't want to receive any real-time updates anymore and notifies other + * subscribers on previously active channels / groups about leaving. + * + * @internal + */ exports.leftAll = (0, core_1.createEvent)('LEFT_ALL', () => ({})); +/** + * Presence heartbeat success event. + * + * Event is sent by corresponding effect handler if REST API call was successful. + * + * @internal + */ exports.heartbeatSuccess = (0, core_1.createEvent)('HEARTBEAT_SUCCESS', (statusCode) => ({ statusCode })); +/** + * Presence heartbeat did fail event. + * + * Event is sent by corresponding effect handler if REST API call failed. + * + * @internal + */ exports.heartbeatFailure = (0, core_1.createEvent)('HEARTBEAT_FAILURE', (error) => error); +/** + * Presence heartbeat impossible event. + * + * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. + * + * @internal + */ exports.heartbeatGiveup = (0, core_1.createEvent)('HEARTBEAT_GIVEUP', () => ({})); +/** + * Delayed presence heartbeat event. + * + * Event is sent by corresponding effect handler when delay timer between heartbeat calls fired. + * + * @internal + */ exports.timesUp = (0, core_1.createEvent)('TIMES_UP', () => ({})); diff --git a/lib/event-engine/presence/presence.js b/lib/event-engine/presence/presence.js index fbfa7c939..826929e72 100644 --- a/lib/event-engine/presence/presence.js +++ b/lib/event-engine/presence/presence.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Presence Event Engine module. + * + * @internal + */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -28,6 +33,11 @@ const core_1 = require("../core"); const events = __importStar(require("./events")); const dispatcher_1 = require("./dispatcher"); const heartbeat_inactive_1 = require("./states/heartbeat_inactive"); +/** + * Presence Event Engine Core. + * + * @internal + */ class PresenceEventEngine { get _engine() { return this.engine; diff --git a/lib/event-engine/presence/states/heartbeat_cooldown.js b/lib/event-engine/presence/states/heartbeat_cooldown.js index 5dd1a1b8d..061190231 100644 --- a/lib/event-engine/presence/states/heartbeat_cooldown.js +++ b/lib/event-engine/presence/states/heartbeat_cooldown.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Waiting next heartbeat state module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatCooldownState = void 0; const state_1 = require("../../core/state"); @@ -7,6 +12,13 @@ const effects_1 = require("../effects"); const heartbeating_1 = require("./heartbeating"); const heartbeat_stopped_1 = require("./heartbeat_stopped"); const heartbeat_inactive_1 = require("./heartbeat_inactive"); +/** + * Waiting next heartbeat state. + * + * State in which Presence Event Engine is waiting when delay will run out and next heartbeat call should be done. + * + * @internal + */ exports.HeartbeatCooldownState = new state_1.State('HEARTBEAT_COOLDOWN'); exports.HeartbeatCooldownState.onEnter(() => (0, effects_1.wait)()); exports.HeartbeatCooldownState.onExit(() => effects_1.wait.cancel); diff --git a/lib/event-engine/presence/states/heartbeat_failed.js b/lib/event-engine/presence/states/heartbeat_failed.js index 4ea95efa8..a74c72fdf 100644 --- a/lib/event-engine/presence/states/heartbeat_failed.js +++ b/lib/event-engine/presence/states/heartbeat_failed.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Failed to heartbeat state module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatFailedState = void 0; const state_1 = require("../../core/state"); @@ -7,6 +12,14 @@ const effects_1 = require("../effects"); const heartbeating_1 = require("./heartbeating"); const heartbeat_stopped_1 = require("./heartbeat_stopped"); const heartbeat_inactive_1 = require("./heartbeat_inactive"); +/** + * Failed to heartbeat state. + * + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. + * + * @internal + */ exports.HeartbeatFailedState = new state_1.State('HEARTBEAT_FAILED'); exports.HeartbeatFailedState.on(events_1.joined.type, (context, event) => heartbeating_1.HeartbeatingState.with({ channels: [...context.channels, ...event.payload.channels], diff --git a/lib/event-engine/presence/states/heartbeat_inactive.js b/lib/event-engine/presence/states/heartbeat_inactive.js index 7bbb964c7..046029fb2 100644 --- a/lib/event-engine/presence/states/heartbeat_inactive.js +++ b/lib/event-engine/presence/states/heartbeat_inactive.js @@ -1,9 +1,21 @@ "use strict"; +/** + * Inactive heratbeating state module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatInactiveState = void 0; const state_1 = require("../../core/state"); const events_1 = require("../events"); const heartbeating_1 = require("./heartbeating"); +/** + * Inactive heratbeating state + * + * State in which Presence Event Engine doesn't process any heartbeat requests (initial state). + * + * @internal + */ exports.HeartbeatInactiveState = new state_1.State('HEARTBEAT_INACTIVE'); exports.HeartbeatInactiveState.on(events_1.joined.type, (_, event) => heartbeating_1.HeartbeatingState.with({ channels: event.payload.channels, diff --git a/lib/event-engine/presence/states/heartbeat_reconnecting.js b/lib/event-engine/presence/states/heartbeat_reconnecting.js index d26321ccc..cc265a5c0 100644 --- a/lib/event-engine/presence/states/heartbeat_reconnecting.js +++ b/lib/event-engine/presence/states/heartbeat_reconnecting.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Retry heartbeat state module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HearbeatReconnectingState = void 0; const state_1 = require("../../core/state"); @@ -9,6 +14,13 @@ const heartbeat_stopped_1 = require("./heartbeat_stopped"); const heartbeat_cooldown_1 = require("./heartbeat_cooldown"); const heartbeat_inactive_1 = require("./heartbeat_inactive"); const heartbeat_failed_1 = require("./heartbeat_failed"); +/** + * Retry heartbeat state. + * + * State in which Presence Event Engine tries to recover after error which happened before. + * + * @internal + */ exports.HearbeatReconnectingState = new state_1.State('HEARBEAT_RECONNECTING'); exports.HearbeatReconnectingState.onEnter((context) => (0, effects_1.delayedHeartbeat)(context)); exports.HearbeatReconnectingState.onExit(() => effects_1.delayedHeartbeat.cancel); diff --git a/lib/event-engine/presence/states/heartbeat_stopped.js b/lib/event-engine/presence/states/heartbeat_stopped.js index 6c162f433..96f501270 100644 --- a/lib/event-engine/presence/states/heartbeat_stopped.js +++ b/lib/event-engine/presence/states/heartbeat_stopped.js @@ -1,10 +1,23 @@ "use strict"; +/** + * Heartbeat stopped state module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatStoppedState = void 0; const state_1 = require("../../core/state"); const events_1 = require("../events"); const heartbeat_inactive_1 = require("./heartbeat_inactive"); const heartbeating_1 = require("./heartbeating"); +/** + * Heartbeat stopped state. + * + * State in which Presence Event Engine still has information about active channels / groups, but doesn't wait for + * delayed heartbeat request sending. + * + * @internal + */ exports.HeartbeatStoppedState = new state_1.State('HEARTBEAT_STOPPED'); exports.HeartbeatStoppedState.on(events_1.joined.type, (context, event) => exports.HeartbeatStoppedState.with({ channels: [...context.channels, ...event.payload.channels], diff --git a/lib/event-engine/presence/states/heartbeating.js b/lib/event-engine/presence/states/heartbeating.js index 588b414ee..b93059d8e 100644 --- a/lib/event-engine/presence/states/heartbeating.js +++ b/lib/event-engine/presence/states/heartbeating.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Heartbeating state module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatingState = void 0; const state_1 = require("../../core/state"); @@ -8,6 +13,13 @@ const heartbeat_cooldown_1 = require("./heartbeat_cooldown"); const heartbeat_reconnecting_1 = require("./heartbeat_reconnecting"); const heartbeat_stopped_1 = require("./heartbeat_stopped"); const heartbeat_inactive_1 = require("./heartbeat_inactive"); +/** + * Heartbeating state module. + * + * State in which Presence Event Engine send heartbeat REST API call. + * + * @internal + */ exports.HeartbeatingState = new state_1.State('HEARTBEATING'); exports.HeartbeatingState.onEnter((context) => (0, effects_1.heartbeat)(context.channels, context.groups)); exports.HeartbeatingState.on(events_1.heartbeatSuccess.type, (context, event) => { diff --git a/lib/event-engine/states/handshake_failed.js b/lib/event-engine/states/handshake_failed.js index ad658adb6..457940d56 100644 --- a/lib/event-engine/states/handshake_failed.js +++ b/lib/event-engine/states/handshake_failed.js @@ -1,10 +1,23 @@ "use strict"; +/** + * Failed initial subscription handshake (disconnected) state. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HandshakeFailedState = void 0; const state_1 = require("../core/state"); const events_1 = require("../events"); const handshaking_1 = require("./handshaking"); const unsubscribed_1 = require("./unsubscribed"); +/** + * Failed initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. + * + * @internal + */ exports.HandshakeFailedState = new state_1.State('HANDSHAKE_FAILED'); exports.HandshakeFailedState.on(events_1.subscriptionChange.type, (context, event) => handshaking_1.HandshakingState.with({ channels: event.payload.channels, @@ -23,7 +36,7 @@ exports.HandshakeFailedState.on(events_1.restore.type, (context, event) => { groups: event.payload.groups, cursor: { timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region ? event.payload.cursor.region : (_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0, + region: event.payload.cursor.region ? event.payload.cursor.region : ((_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0), }, }); }); diff --git a/lib/event-engine/states/handshake_reconnecting.js b/lib/event-engine/states/handshake_reconnecting.js index 6c95593aa..9f8e61c9f 100644 --- a/lib/event-engine/states/handshake_reconnecting.js +++ b/lib/event-engine/states/handshake_reconnecting.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Retry initial subscription handshake (disconnected) state. + * + * @internal + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -13,6 +18,13 @@ const handshaking_1 = require("./handshaking"); const receiving_1 = require("./receiving"); const unsubscribed_1 = require("./unsubscribed"); const categories_1 = __importDefault(require("../../core/constants/categories")); +/** + * Retry initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine tries to recover after error which happened before. + * + * @internal + */ exports.HandshakeReconnectingState = new state_1.State('HANDSHAKE_RECONNECTING'); exports.HandshakeReconnectingState.onEnter((context) => (0, effects_1.handshakeReconnect)(context)); exports.HandshakeReconnectingState.onExit(() => effects_1.handshakeReconnect.cancel); diff --git a/lib/event-engine/states/handshake_stopped.js b/lib/event-engine/states/handshake_stopped.js index 1cad18d75..d8af1cea1 100644 --- a/lib/event-engine/states/handshake_stopped.js +++ b/lib/event-engine/states/handshake_stopped.js @@ -1,10 +1,23 @@ "use strict"; +/** + * Stopped initial subscription handshake (disconnected) state. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HandshakeStoppedState = void 0; const state_1 = require("../core/state"); const events_1 = require("../events"); const handshaking_1 = require("./handshaking"); const unsubscribed_1 = require("./unsubscribed"); +/** + * Stopped initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine still has information about subscription but doesn't have subscription + * cursor for next sequential subscribe REST API call. + * + * @internal + */ exports.HandshakeStoppedState = new state_1.State('HANDSHAKE_STOPPED'); exports.HandshakeStoppedState.on(events_1.subscriptionChange.type, (context, event) => exports.HandshakeStoppedState.with({ channels: event.payload.channels, diff --git a/lib/event-engine/states/handshaking.js b/lib/event-engine/states/handshaking.js index 13d3c1cca..b4cd08709 100644 --- a/lib/event-engine/states/handshaking.js +++ b/lib/event-engine/states/handshaking.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Initial subscription handshake (disconnected) state. + * + * @internal + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -12,6 +17,14 @@ const handshake_stopped_1 = require("./handshake_stopped"); const receiving_1 = require("./receiving"); const unsubscribed_1 = require("./unsubscribed"); const categories_1 = __importDefault(require("../../core/constants/categories")); +/** + * Initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine tries to receive subscription cursor for next sequential subscribe REST + * API calls. + * + * @internal + */ exports.HandshakingState = new state_1.State('HANDSHAKING'); exports.HandshakingState.onEnter((context) => (0, effects_1.handshake)(context.channels, context.groups)); exports.HandshakingState.onExit(() => effects_1.handshake.cancel); diff --git a/lib/event-engine/states/receive_failed.js b/lib/event-engine/states/receive_failed.js index d6af9bfd3..3794a03b6 100644 --- a/lib/event-engine/states/receive_failed.js +++ b/lib/event-engine/states/receive_failed.js @@ -1,10 +1,23 @@ "use strict"; +/** + * Failed to receive real-time updates (disconnected) state. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ReceiveFailedState = void 0; const state_1 = require("../core/state"); const events_1 = require("../events"); const handshaking_1 = require("./handshaking"); const unsubscribed_1 = require("./unsubscribed"); +/** + * Failed to receive real-time updates (disconnected) state. + * + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. + * + * @internal + */ exports.ReceiveFailedState = new state_1.State('RECEIVE_FAILED'); exports.ReceiveFailedState.on(events_1.reconnect.type, (context, event) => { var _a; diff --git a/lib/event-engine/states/receive_reconnecting.js b/lib/event-engine/states/receive_reconnecting.js index 8f98426f1..428ffc028 100644 --- a/lib/event-engine/states/receive_reconnecting.js +++ b/lib/event-engine/states/receive_reconnecting.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Reconnect to receive real-time updates (disconnected) state. + * + * @internal + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -12,6 +17,13 @@ const receive_failed_1 = require("./receive_failed"); const receive_stopped_1 = require("./receive_stopped"); const unsubscribed_1 = require("./unsubscribed"); const categories_1 = __importDefault(require("../../core/constants/categories")); +/** + * Reconnect to receive real-time updates (disconnected) state. + * + * State in which Subscription Event Engine tries to recover after error which happened before. + * + * @internal + */ exports.ReceiveReconnectingState = new state_1.State('RECEIVE_RECONNECTING'); exports.ReceiveReconnectingState.onEnter((context) => (0, effects_1.receiveReconnect)(context)); exports.ReceiveReconnectingState.onExit(() => effects_1.receiveReconnect.cancel); diff --git a/lib/event-engine/states/receive_stopped.js b/lib/event-engine/states/receive_stopped.js index 1078a2e4b..e608078a5 100644 --- a/lib/event-engine/states/receive_stopped.js +++ b/lib/event-engine/states/receive_stopped.js @@ -1,10 +1,23 @@ "use strict"; +/** + * Stopped real-time updates (disconnected) state module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ReceiveStoppedState = void 0; const state_1 = require("../core/state"); const events_1 = require("../events"); const handshaking_1 = require("./handshaking"); const unsubscribed_1 = require("./unsubscribed"); +/** + * Stopped real-time updates (disconnected) state. + * + * State in which Subscription Event Engine still has information about subscription but doesn't process real-time + * updates. + * + * @internal + */ exports.ReceiveStoppedState = new state_1.State('RECEIVE_STOPPED'); exports.ReceiveStoppedState.on(events_1.subscriptionChange.type, (context, event) => exports.ReceiveStoppedState.with({ channels: event.payload.channels, diff --git a/lib/event-engine/states/receiving.js b/lib/event-engine/states/receiving.js index 66f44e747..381c722fc 100644 --- a/lib/event-engine/states/receiving.js +++ b/lib/event-engine/states/receiving.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Receiving real-time updates (connected) state module. + * + * @internal + */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -11,6 +16,13 @@ const unsubscribed_1 = require("./unsubscribed"); const receive_reconnecting_1 = require("./receive_reconnecting"); const receive_stopped_1 = require("./receive_stopped"); const categories_1 = __importDefault(require("../../core/constants/categories")); +/** + * Receiving real-time updates (connected) state. + * + * State in which Subscription Event Engine processes any real-time updates. + * + * @internal + */ exports.ReceivingState = new state_1.State('RECEIVING'); exports.ReceivingState.onEnter((context) => (0, effects_1.receiveMessages)(context.channels, context.groups, context.cursor)); exports.ReceivingState.onExit(() => effects_1.receiveMessages.cancel); diff --git a/lib/event-engine/states/unsubscribed.js b/lib/event-engine/states/unsubscribed.js index 10f3b2bad..29a2f7748 100644 --- a/lib/event-engine/states/unsubscribed.js +++ b/lib/event-engine/states/unsubscribed.js @@ -1,9 +1,21 @@ "use strict"; +/** + * Unsubscribed / disconnected state module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.UnsubscribedState = void 0; const state_1 = require("../core/state"); const events_1 = require("../events"); const handshaking_1 = require("./handshaking"); +/** + * Unsubscribed / disconnected state. + * + * State in which Subscription Event Engine doesn't process any real-time updates. + * + * @internal + */ exports.UnsubscribedState = new state_1.State('UNSUBSCRIBED'); exports.UnsubscribedState.on(events_1.subscriptionChange.type, (_, event) => handshaking_1.HandshakingState.with({ channels: event.payload.channels, diff --git a/lib/node/configuration.js b/lib/node/components/configuration.js similarity index 93% rename from lib/node/configuration.js rename to lib/node/components/configuration.js index f0dca5397..3a777742a 100644 --- a/lib/node/configuration.js +++ b/lib/node/components/configuration.js @@ -4,7 +4,7 @@ */ Object.defineProperty(exports, "__esModule", { value: true }); exports.setDefaults = void 0; -const configuration_1 = require("../core/interfaces/configuration"); +const configuration_1 = require("../../core/interfaces/configuration"); // -------------------------------------------------------- // ----------------------- Defaults ----------------------- // -------------------------------------------------------- diff --git a/lib/node/index.js b/lib/node/index.js index 41ebc06ee..bd2eb87c7 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -7,7 +7,7 @@ const buffer_1 = require("buffer"); const nodeCryptoModule_1 = require("../crypto/modules/NodeCryptoModule/nodeCryptoModule"); const node_1 = __importDefault(require("../file/modules/node")); const configuration_1 = require("../core/components/configuration"); -const configuration_2 = require("./configuration"); +const configuration_2 = require("./components/configuration"); const token_manager_1 = require("../core/components/token_manager"); const node_transport_1 = require("../transport/node-transport"); const middleware_1 = require("../transport/middleware"); @@ -21,6 +21,13 @@ const common_1 = __importDefault(require("../cbor/common")); * PubNub client for Node.js platform. */ class PubNub extends pubnub_common_1.PubNubCore { + /** + * Create and configure PubNub client core. + * + * @param configuration - User-provided PubNub client configuration. + * + * @returns Configured and ready to use PubNub client. + */ constructor(configuration) { const configurationCopy = (0, configuration_2.setDefaults)(configuration); const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'Nodejs' }); @@ -31,7 +38,7 @@ class PubNub extends pubnub_common_1.PubNubCore { if (!cryptoConfiguration.cipherKey) return undefined; if (process.env.CRYPTO_MODULE !== 'disabled') { - return new nodeCryptoModule_1.CryptoModule({ + return new nodeCryptoModule_1.NodeCryptoModule({ default: new nodeCryptoModule_1.LegacyCryptor(Object.assign({}, cryptoConfiguration)), cryptors: [new nodeCryptoModule_1.AesCbcCryptor({ cipherKey: cryptoConfiguration.cipherKey })], }); @@ -99,5 +106,5 @@ class PubNub extends pubnub_common_1.PubNubCore { * Data encryption / decryption module constructor. */ // @ts-expect-error Allowed to simplify interface when module can be disabled. -PubNub.CryptoModule = process.env.CRYPTO_MODULE !== 'disabled' ? nodeCryptoModule_1.CryptoModule : undefined; +PubNub.CryptoModule = process.env.CRYPTO_MODULE !== 'disabled' ? nodeCryptoModule_1.NodeCryptoModule : undefined; module.exports = PubNub; diff --git a/lib/react_native/index.js b/lib/react_native/index.js index fb65ba063..0f89b88ba 100644 --- a/lib/react_native/index.js +++ b/lib/react_native/index.js @@ -26,6 +26,13 @@ global.Buffer = global.Buffer || buffer_1.Buffer; * PubNub client for React Native platform. */ class PubNub extends pubnub_common_1.PubNubCore { + /** + * Create and configure PubNub client core. + * + * @param configuration - User-provided PubNub client configuration. + * + * @returns Configured and ready to use PubNub client. + */ constructor(configuration) { const configurationCopy = (0, configuration_2.setDefaults)(configuration); const platformConfiguration = Object.assign(Object.assign({}, configurationCopy), { sdkFamily: 'ReactNative' }); diff --git a/lib/transport/middleware.js b/lib/transport/middleware.js index c7e60f30c..178534519 100644 --- a/lib/transport/middleware.js +++ b/lib/transport/middleware.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Common PubNub Network Provider middleware module. + * + * @internal + */ Object.defineProperty(exports, "__esModule", { value: true }); exports.PubNubMiddleware = void 0; const transport_request_1 = require("../core/types/transport-request"); @@ -62,6 +67,11 @@ class RequestSignature { } } RequestSignature.textDecoder = new TextDecoder('utf-8'); +/** + * Common PubNub Network Provider middleware. + * + * @internal + */ class PubNubMiddleware { constructor(configuration) { this.configuration = configuration; diff --git a/lib/transport/node-transport.js b/lib/transport/node-transport.js index 95a8b911b..7778afd02 100644 --- a/lib/transport/node-transport.js +++ b/lib/transport/node-transport.js @@ -1,4 +1,9 @@ "use strict"; +/** + * Node.js Transport provider module. + * + * @internal + */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); @@ -46,6 +51,8 @@ const pubnub_api_error_1 = require("../errors/pubnub-api-error"); const utils_1 = require("../core/utils"); /** * Class representing a fetch-based Node.js transport provider. + * + * @internal */ class NodeTransport { /** @@ -56,6 +63,8 @@ class NodeTransport { * @param [logVerbosity] - Whether verbose logging enabled or not. * * @returns Transport for performing network requests. + * + * @internal */ constructor(keepAlive = false, keepAliveSettings = { timeout: 30000 }, logVerbosity = false) { this.keepAlive = keepAlive; @@ -66,6 +75,8 @@ class NodeTransport { * Update request proxy configuration. * * @param configuration - New proxy configuration. + * + * @internal */ setProxy(configuration) { this.proxyConfiguration = configuration; @@ -123,6 +134,8 @@ class NodeTransport { * @param req - The {@link TransportRequest} object containing request information. * * @returns Request object generated from the {@link TransportRequest} object. + * + * @internal */ requestFromTransportRequest(req) { return __awaiter(this, void 0, void 0, function* () { @@ -165,6 +178,8 @@ class NodeTransport { * * @returns {HttpAgent | HttpsAgent | undefined} - The appropriate agent for the request, or * undefined if keep alive or proxy not requested. + * + * @internal */ agentForTransportRequest(req) { // Don't configure any agents if keep alive not requested. @@ -210,5 +225,7 @@ class NodeTransport { exports.NodeTransport = NodeTransport; /** * Service {@link ArrayBuffer} response decoder. + * + * @internal */ NodeTransport.decoder = new TextDecoder(); diff --git a/lib/transport/web-react-native-transport.js b/lib/transport/web-react-native-transport.js index 9c18341a2..53ce793f6 100644 --- a/lib/transport/web-react-native-transport.js +++ b/lib/transport/web-react-native-transport.js @@ -1,6 +1,8 @@ "use strict"; /** * Common browser and React Native Transport provider module. + * + * @internal */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } @@ -17,8 +19,18 @@ const pubnub_api_error_1 = require("../errors/pubnub-api-error"); const utils_1 = require("../core/utils"); /** * Class representing a `fetch`-based browser and React Native transport provider. + * + * @internal */ class WebReactNativeTransport { + /** + * Create and configure transport provider for Web and Rect environments. + * + * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. + * @param logVerbosity - Whether verbose logs should be printed or not. + * + * @internal + */ constructor(keepAlive = false, logVerbosity) { this.keepAlive = keepAlive; this.logVerbosity = logVerbosity; @@ -50,7 +62,10 @@ class WebReactNativeTransport { reject(new Error('Request timeout')); }, req.timeout * 1000); }); - return Promise.race([fetch(request, { signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal }), requestTimeout]) + return Promise.race([ + fetch(request, { signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, credentials: 'omit', cache: 'no-cache' }), + requestTimeout, + ]) .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) .then((response) => { const responseBody = response[1].byteLength > 0 ? response[1] : undefined; @@ -85,6 +100,8 @@ class WebReactNativeTransport { * @param req - The {@link TransportRequest} object containing request information. * * @returns Request object generated from the {@link TransportRequest} object. + * + * @internal */ requestFromTransportRequest(req) { return __awaiter(this, void 0, void 0, function* () { @@ -131,6 +148,8 @@ class WebReactNativeTransport { * @param request - Platform-specific * @param [elapsed] - How many seconds passed since request processing started. * @param [body] - Service response (if available). + * + * @internal */ logRequestProcessProgress(request, elapsed, body) { if (!this.logVerbosity) @@ -153,5 +172,7 @@ class WebReactNativeTransport { exports.WebReactNativeTransport = WebReactNativeTransport; /** * Service {@link ArrayBuffer} response decoder. + * + * @internal */ WebReactNativeTransport.decoder = new TextDecoder(); diff --git a/lib/types/cbor/common.d.ts b/lib/types/cbor/common.d.ts deleted file mode 100644 index 4ccbdd2ba..000000000 --- a/lib/types/cbor/common.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Cbor decoder module. - */ -export {}; diff --git a/lib/types/core/components/abort_signal.d.ts b/lib/types/core/components/abort_signal.d.ts deleted file mode 100644 index 926a042d3..000000000 --- a/lib/types/core/components/abort_signal.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export declare class AbortError extends Error { - name: string; - constructor(); -} diff --git a/lib/types/core/components/base64_codec.d.ts b/lib/types/core/components/base64_codec.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/lib/types/core/components/base64_codec.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/types/core/components/configuration.d.ts b/lib/types/core/components/configuration.d.ts deleted file mode 100644 index 2fb4a5f80..000000000 --- a/lib/types/core/components/configuration.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * {@link PubNub} client configuration module. - */ -export {}; diff --git a/lib/types/core/components/cryptography/hmac-sha256.d.ts b/lib/types/core/components/cryptography/hmac-sha256.d.ts deleted file mode 100644 index 112f25199..000000000 --- a/lib/types/core/components/cryptography/hmac-sha256.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export namespace mode { - let ECB: any; -} diff --git a/lib/types/core/components/cryptography/index.d.ts b/lib/types/core/components/cryptography/index.d.ts deleted file mode 100644 index b3f187c0b..000000000 --- a/lib/types/core/components/cryptography/index.d.ts +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Legacy cryptography module. - */ -import { CryptorConfiguration } from '../../interfaces/crypto-module'; -import { Payload } from '../../types/api'; -/** - * Legacy cryptor configuration options. - */ -type CryptoConfiguration = { - encryptKey?: boolean; - keyEncoding?: 'hex' | 'utf8' | 'base64' | 'binary'; - keyLength?: 128 | 256; - mode?: 'ecb' | 'cbc'; -}; -export default class { - private readonly configuration; - /** - * Crypto initialization vector. - */ - private iv; - /** - * List os allowed cipher key encodings. - */ - private allowedKeyEncodings; - /** - * Allowed cipher key lengths. - */ - private allowedKeyLengths; - /** - * Allowed crypto modes. - */ - private allowedModes; - /** - * Default cryptor configuration options. - */ - private readonly defaultOptions; - constructor(configuration: CryptorConfiguration); - /** - * Generate HMAC-SHA256 hash from input data. - * - * @param data - Data from which hash should be generated. - * - * @returns HMAC-SHA256 hash from provided `data`. - */ - HMACSHA256(data: string): string; - /** - * Generate SHA256 hash from input data. - * - * @param data - Data from which hash should be generated. - * - * @returns SHA256 hash from provided `data`. - */ - SHA256(data: string): string; - /** - * Encrypt provided data. - * - * @param data - Source data which should be encrypted. - * @param [customCipherKey] - Custom cipher key (different from defined on client level). - * @param [options] - Specific crypto configuration options. - * - * @returns Encrypted `data`. - */ - encrypt(data: string | Payload, customCipherKey?: string, options?: CryptoConfiguration): string; - /** - * Decrypt provided data. - * - * @param data - Encrypted data which should be decrypted. - * @param [customCipherKey] - Custom cipher key (different from defined on client level). - * @param [options] - Specific crypto configuration options. - * - * @returns Decrypted `data`. - */ - decrypt(data: string, customCipherKey?: string, options?: CryptoConfiguration): Payload | null; - /** - * Encrypt provided data. - * - * @param data - Source data which should be encrypted. - * @param [customCipherKey] - Custom cipher key (different from defined on client level). - * @param [options] - Specific crypto configuration options. - * - * @returns Encrypted `data` as string. - */ - private pnEncrypt; - /** - * Decrypt provided data. - * - * @param data - Encrypted data which should be decrypted. - * @param [customCipherKey] - Custom cipher key (different from defined on client level). - * @param [options] - Specific crypto configuration options. - * - * @returns Decrypted `data`. - */ - private pnDecrypt; - /** - * Pre-process provided custom crypto configuration. - * - * @param incomingOptions - Configuration which should be pre-processed before use. - * - * @returns Normalized crypto configuration options. - */ - private parseOptions; - /** - * Decode provided cipher key. - * - * @param key - Key in `encoding` provided by `options`. - * @param options - Crypto configuration options with cipher key details. - * - * @returns Array buffer with decoded key. - */ - private decodeKey; - /** - * Add padding to the cipher key. - * - * @param key - Key which should be padded. - * @param options - Crypto configuration options with cipher key details. - * - * @returns Properly padded cipher key. - */ - private getPaddedKey; - /** - * Cipher mode. - * - * @param options - Crypto configuration with information about cipher mode. - * - * @returns Crypto cipher mode. - */ - private getMode; - /** - * Cipher initialization vector. - * - * @param options - Crypto configuration with information about cipher mode. - * - * @returns Initialization vector. - */ - private getIV; - /** - * Random initialization vector. - * - * @returns Generated random initialization vector. - */ - private getRandomIV; -} -export {}; diff --git a/lib/types/core/components/deduping_manager.d.ts b/lib/types/core/components/deduping_manager.d.ts deleted file mode 100644 index 8c072ad6d..000000000 --- a/lib/types/core/components/deduping_manager.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -/** - * Real-time events deduplication manager. - * - * @internal - */ -export default class _default { - constructor({ config }: { - config: any; - }); - _config: any; - hashHistory: any[]; - getKey(message: any): string; - isDuplicate(message: any): boolean; - addEntry(message: any): void; - clearHistory(): void; -} diff --git a/lib/types/core/components/eventEmitter.d.ts b/lib/types/core/components/eventEmitter.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/lib/types/core/components/eventEmitter.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/types/core/components/listener_manager.d.ts b/lib/types/core/components/listener_manager.d.ts deleted file mode 100644 index 054904377..000000000 --- a/lib/types/core/components/listener_manager.d.ts +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Events listener manager module. - */ -import * as Subscription from '../types/api/subscription'; -import { Status, StatusEvent } from '../types/api'; -/** - * Real-time events listener. - */ -export type Listener = { - /** - * Real-time message events listener. - * - * @param message - Received message. - */ - message?: (message: Subscription.Message) => void; - /** - * Real-time message signal listener. - * - * @param signal - Received signal. - */ - signal?: (signal: Subscription.Signal) => void; - /** - * Real-time presence change events listener. - * - * @param presence - Received presence chane information. - */ - presence?: (presence: Subscription.Presence) => void; - /** - * Real-time App Context Objects change events listener. - * - * @param object - Changed App Context Object information. - */ - objects?: (object: Subscription.AppContextObject) => void; - /** - * Real-time message actions events listener. - * - * @param action - Message action information. - */ - messageAction?: (action: Subscription.MessageAction) => void; - /** - * Real-time file share events listener. - * - * @param file - Shared file information. - */ - file?: (file: Subscription.File) => void; - /** - * Real-time PubNub client status change event. - * - * @param status - PubNub client status information - */ - status?: (status: Status | StatusEvent) => void; - /** - * Real-time User App Context Objects change events listener. - * - * @param user - User App Context Object information. - * - * @deprecated Use {@link objects} listener callback instead. - */ - user?: (user: Subscription.UserAppContextObject) => void; - /** - * Real-time Space App Context Objects change events listener. - * - * @param space - Space App Context Object information. - * - * @deprecated Use {@link objects} listener callback instead. - */ - space?: (space: Subscription.SpaceAppContextObject) => void; - /** - * Real-time VSP Membership App Context Objects change events listener. - * - * @param membership - VSP Membership App Context Object information. - * - * @deprecated Use {@link objects} listener callback instead. - */ - membership?: (membership: Subscription.VSPMembershipAppContextObject) => void; -}; diff --git a/lib/types/core/components/push_payload.d.ts b/lib/types/core/components/push_payload.d.ts deleted file mode 100644 index 677843f48..000000000 --- a/lib/types/core/components/push_payload.d.ts +++ /dev/null @@ -1,636 +0,0 @@ -/** - * Payload for `pn_apns` field in published message. - */ -type APNSPayload = { - /** - * Payload for Apple Push Notification Service. - */ - aps: { - /** - * Configuration of visual notification representation. - */ - alert?: { - /** - * First line title. - * - * Title which is shown in bold on the first line of notification bubble. - */ - title?: string; - /** - * Second line title. - * - * Subtitle which is shown under main title with smaller font. - */ - subtitle?: string; - /** - * Notification body. - * - * Body which is shown to the user after interaction with notification. - */ - body?: string; - }; - /** - * Unread notifications count badge value. - */ - badge?: number | null; - /** - * Name of the file from resource bundle which should be played when notification received. - */ - sound?: string; - /** - * Silent notification flag. - */ - 'content-available'?: 1; - }; - /** - * APNS2 payload recipients information. - */ - pn_push: PubNubAPNS2Configuration[]; -}; -/** - * APNS2 configuration type. - */ -type APNS2Configuration = { - /** - * Notification group / collapse identifier. Value will be used in APNS POST request as `apns-collapse-id` header - * value. - */ - collapseId?: string; - /** - * Date till which APNS will try to deliver notification to target device. Value will be used in APNS POST request as - * `apns-expiration` header value. - */ - expirationDate?: Date; - /** - * List of topics which should receive this notification. - */ - targets: APNS2Target[]; -}; -/** - * Preformatted for PubNub service `APNS2` configuration type. - */ -type PubNubAPNS2Configuration = { - /** - * PubNub service authentication method for APNS. - */ - auth_method: 'token'; - /** - * Target entities which should receive notification. - */ - targets: PubNubAPNS2Target[]; - /** - * Notifications group collapse identifier. - */ - collapse_id?: string; - /** - * Notification receive expiration date. - * - * Date after which notification won't be delivered. - */ - expiration?: string; - /** - * APNS protocol version. - */ - version: 'v2'; -}; -/** - * APNS2 configuration target type. - */ -type APNS2Target = { - /** - * Notifications topic name (usually it is bundle identifier of application for Apple platform). - * - * **Important:** Required only if `pushGateway` is set to `apns2`. - */ - topic: string; - /** - * Environment within which registered devices to which notifications should be delivered. - * - * Available: - * - `development` - * - `production` - * - * @default `development` - */ - environment?: 'development' | 'production'; - /** - * List of devices (their push tokens) to which this notification shouldn't be delivered. - */ - excludedDevices?: string[]; -}; -/** - * Preformatted for PubNub service `APNS2` configuration target type. - */ -type PubNubAPNS2Target = Omit & { - /** - * List of devices (their push tokens) to which this notification shouldn't be delivered. - */ - excluded_devices?: string[]; -}; -/** - * Payload for `pn_gcm` field in published message. - */ -type FCMPayload = { - /** - * Configuration of visual notification representation. - */ - notification?: { - /** - * First line title. - * - * Title which is shown in bold on the first line of notification bubble. - */ - title?: string; - /** - * Notification body. - * - * Body which is shown to the user after interaction with notification. - */ - body?: string; - /** - * Name of the icon file from resource bundle which should be shown on notification. - */ - icon?: string; - /** - * Name of the file from resource bundle which should be played when notification received. - */ - sound?: string; - tag?: string; - }; - /** - * Configuration of data notification. - * - * Silent notification configuration. - */ - data?: { - notification?: FCMPayload['notification']; - }; -}; -/** - * Base notification payload object. - */ -declare class BaseNotificationPayload { - /** - * Notification main title. - */ - protected _title?: string; - /** - * Notification second-line title. - */ - protected _subtitle?: string; - /** - * Name of the sound which should be played for received notification. - */ - protected _sound?: string; - /** - * Value which should be placed on application badge (if required). - */ - protected _badge?: number | null; - /** - * Notification main body message. - */ - protected _body?: string; - /** - * Object in resulting message where notification payload should be added. - */ - protected _payload: unknown; - constructor(payload: unknown, title?: string, body?: string); - /** - * Retrieve resulting notification payload content for message. - * - * @returns Preformatted push notification payload data. - */ - get payload(): unknown; - /** - * Update notification title. - * - * @param value - New notification title. - */ - set title(value: string | undefined); - /** - * Update notification subtitle. - * - * @param value - New second-line notification title. - */ - set subtitle(value: string | undefined); - /** - * Update notification body. - * - * @param value - Update main notification message (shown when expanded). - */ - set body(value: string | undefined); - /** - * Update application badge number. - * - * @param value - Number which should be shown in application badge upon receiving notification. - */ - set badge(value: number | null | undefined); - /** - * Update notification sound. - * - * @param value - Name of the sound file which should be played upon notification receive. - */ - set sound(value: string | undefined); - /** - * Platform-specific structure initialization. - */ - protected setDefaultPayloadStructure(): void; - /** - * Translate data object into PubNub push notification payload object. - * - * @returns Preformatted push notification payload. - */ - toObject(): unknown; -} -/** - * Message payload for Apple Push Notification Service. - */ -export declare class APNSNotificationPayload extends BaseNotificationPayload { - /** - * List with notification receivers information. - */ - private _configurations?; - /** - * Type of push notification service for which payload will be created. - */ - private _apnsPushType; - /** - * Whether resulting payload should trigger silent notification or not. - */ - private _isSilent; - get payload(): APNSPayload; - /** - * Update notification receivers configuration. - * - * @param value - New APNS2 configurations. - */ - set configurations(value: APNS2Configuration[]); - /** - * Notification payload. - * - * @returns Platform-specific part of PubNub notification payload. - */ - get notification(): { - /** - * Configuration of visual notification representation. - */ - alert?: { - /** - * First line title. - * - * Title which is shown in bold on the first line of notification bubble. - */ - title?: string | undefined; - /** - * Second line title. - * - * Subtitle which is shown under main title with smaller font. - */ - subtitle?: string | undefined; - /** - * Notification body. - * - * Body which is shown to the user after interaction with notification. - */ - body?: string | undefined; - } | undefined; - /** - * Unread notifications count badge value. - */ - badge?: number | null | undefined; - /** - * Name of the file from resource bundle which should be played when notification received. - */ - sound?: string | undefined; - /** - * Silent notification flag. - */ - 'content-available'?: 1 | undefined; - }; - /** - * Notification title. - * - * @returns Main notification title. - */ - get title(): string | undefined; - /** - * Update notification title. - * - * @param value - New notification title. - */ - set title(value: string | undefined); - /** - * Notification subtitle. - * - * @returns Second-line notification title. - */ - get subtitle(): string | undefined; - /** - * Update notification subtitle. - * - * @param value - New second-line notification title. - */ - set subtitle(value: string | undefined); - /** - * Notification body. - * - * @returns Main notification message (shown when expanded). - */ - get body(): string | undefined; - /** - * Update notification body. - * - * @param value - Update main notification message (shown when expanded). - */ - set body(value: string | undefined); - /** - * Retrieve unread notifications number. - * - * @returns Number of unread notifications which should be shown on application badge. - */ - get badge(): number | null | undefined; - /** - * Update application badge number. - * - * @param value - Number which should be shown in application badge upon receiving notification. - */ - set badge(value: number | null | undefined); - /** - * Retrieve notification sound file. - * - * @returns Notification sound file name from resource bundle. - */ - get sound(): string | undefined; - /** - * Update notification sound. - * - * @param value - Name of the sound file which should be played upon notification receive. - */ - set sound(value: string | undefined); - /** - * Set whether notification should be silent or not. - * - * `content-available` notification type will be used to deliver silent notification if set to `true`. - * - * @param value - Whether notification should be sent as silent or not. - */ - set silent(value: boolean); - protected setDefaultPayloadStructure(): void; - toObject(): APNSPayload | null; - /** - * Create PubNub push notification service APNS2 configuration information object. - * - * @param configuration - Source user-provided APNS2 configuration. - * - * @returns Preformatted for PubNub service APNS2 configuration information. - */ - private objectFromAPNS2Configuration; - /** - * Create PubNub push notification service APNS2 target information object. - * - * @param target - Source user-provided data. - * - * @returns Preformatted for PubNub service APNS2 target information. - */ - private objectFromAPNSTarget; -} -/** - * Message payload for Firebase Clouse Messaging service. - */ -export declare class FCMNotificationPayload extends BaseNotificationPayload { - /** - * Whether resulting payload should trigger silent notification or not. - */ - private _isSilent?; - /** - * Name of the icon file from resource bundle which should be shown on notification. - */ - private _icon?; - private _tag?; - get payload(): FCMPayload; - /** - * Notification payload. - * - * @returns Platform-specific part of PubNub notification payload. - */ - get notification(): { - /** - * First line title. - * - * Title which is shown in bold on the first line of notification bubble. - */ - title?: string | undefined; - /** - * Notification body. - * - * Body which is shown to the user after interaction with notification. - */ - body?: string | undefined; - /** - * Name of the icon file from resource bundle which should be shown on notification. - */ - icon?: string | undefined; - /** - * Name of the file from resource bundle which should be played when notification received. - */ - sound?: string | undefined; - tag?: string | undefined; - } | undefined; - /** - * Silent notification payload. - * - * @returns Silent notification payload (data notification). - */ - get data(): { - notification?: { - /** - * First line title. - * - * Title which is shown in bold on the first line of notification bubble. - */ - title?: string | undefined; - /** - * Notification body. - * - * Body which is shown to the user after interaction with notification. - */ - body?: string | undefined; - /** - * Name of the icon file from resource bundle which should be shown on notification. - */ - icon?: string | undefined; - /** - * Name of the file from resource bundle which should be played when notification received. - */ - sound?: string | undefined; - tag?: string | undefined; - } | undefined; - } | undefined; - /** - * Notification title. - * - * @returns Main notification title. - */ - get title(): string | undefined; - /** - * Update notification title. - * - * @param value - New notification title. - */ - set title(value: string | undefined); - /** - * Notification body. - * - * @returns Main notification message (shown when expanded). - */ - get body(): string | undefined; - /** - * Update notification body. - * - * @param value - Update main notification message (shown when expanded). - */ - set body(value: string | undefined); - /** - * Retrieve notification sound file. - * - * @returns Notification sound file name from resource bundle. - */ - get sound(): string | undefined; - /** - * Update notification sound. - * - * @param value - Name of the sound file which should be played upon notification receive. - */ - set sound(value: string | undefined); - /** - * Retrieve notification icon file. - * - * @returns Notification icon file name from resource bundle. - */ - get icon(): string | undefined; - /** - * Update notification icon. - * - * @param value - Name of the icon file which should be shown on notification. - */ - set icon(value: string | undefined); - get tag(): string | undefined; - set tag(value: string | undefined); - /** - * Set whether notification should be silent or not. - * - * All notification data will be sent under `data` field if set to `true`. - * - * @param value - Whether notification should be sent as silent or not. - */ - set silent(value: boolean); - protected setDefaultPayloadStructure(): void; - toObject(): FCMPayload | null; -} -declare class NotificationsPayload { - /** - * Resulting message payload for notification services. - */ - private readonly _payload; - /** - * Whether notifications debugging session should be used or not. - */ - private _debugging?; - /** - * First line title. - * - * Title which is shown in bold on the first line of notification bubble. - */ - private readonly _title; - /** - * Second line title. - * - * Subtitle which is shown under main title with smaller font. - */ - private _subtitle?; - /** - * Notification main body message. - */ - private readonly _body; - /** - * Value which should be placed on application badge (if required). - */ - private _badge?; - /** - * Name of the file from resource bundle which should be played when notification received. - */ - private _sound?; - /** - * APNS-specific message payload. - */ - apns: APNSNotificationPayload; - /** - * FCM-specific message payload. - */ - fcm: FCMNotificationPayload; - constructor(title: string, body: string); - set debugging(value: boolean); - /** - * Notification title. - * - * @returns Main notification title. - */ - get title(): string; - /** - * Notification subtitle. - * - * @returns Second-line notification title. - */ - get subtitle(): string | undefined; - /** - * Update notification subtitle. - * - * @param value - New second-line notification title. - */ - set subtitle(value: string | undefined); - /** - * Notification body. - * - * @returns Main notification message (shown when expanded). - */ - get body(): string; - /** - * Retrieve unread notifications number. - * - * @returns Number of unread notifications which should be shown on application badge. - */ - get badge(): number | undefined; - /** - * Update application badge number. - * - * @param value - Number which should be shown in application badge upon receiving notification. - */ - set badge(value: number | undefined); - /** - * Retrieve notification sound file. - * - * @returns Notification sound file name from resource bundle. - */ - get sound(): string | undefined; - /** - * Update notification sound. - * - * @param value - Name of the sound file which should be played upon notification receive. - */ - set sound(value: string | undefined); - /** - * Build notifications platform for requested platforms. - * - * @param platforms - List of platforms for which payload should be added to final dictionary. Supported values: - * gcm, apns, and apns2. - * - * @returns Object with data, which can be sent with publish method call and trigger remote notifications for - * specified platforms. - */ - buildPayload(platforms: string[]): { - pn_apns?: APNSPayload | undefined; - pn_gcm?: FCMPayload | undefined; - pn_debug?: boolean | undefined; - }; -} -export default NotificationsPayload; diff --git a/lib/types/core/components/reconnection_manager.d.ts b/lib/types/core/components/reconnection_manager.d.ts deleted file mode 100644 index 2b32dd6da..000000000 --- a/lib/types/core/components/reconnection_manager.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** - * Subscription reconnection-manager. - * - * **Note:** Reconnection manger rely on legacy time-based availability check. - */ -export {}; diff --git a/lib/types/core/components/request.d.ts b/lib/types/core/components/request.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/lib/types/core/components/request.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/types/core/components/stringify_buffer_keys.d.ts b/lib/types/core/components/stringify_buffer_keys.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/lib/types/core/components/stringify_buffer_keys.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/types/core/components/subject.d.ts b/lib/types/core/components/subject.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/lib/types/core/components/subject.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/types/core/components/subscription-manager.d.ts b/lib/types/core/components/subscription-manager.d.ts deleted file mode 100644 index 6807d1c06..000000000 --- a/lib/types/core/components/subscription-manager.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Subscription manager module. - */ -export {}; diff --git a/lib/types/core/components/token_manager.d.ts b/lib/types/core/components/token_manager.d.ts deleted file mode 100644 index ca862c226..000000000 --- a/lib/types/core/components/token_manager.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * PubNub Access Token Manager module. - */ -export {}; diff --git a/lib/types/core/components/uuid.d.ts b/lib/types/core/components/uuid.d.ts deleted file mode 100644 index 0131316e7..000000000 --- a/lib/types/core/components/uuid.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare const _default: { - createUUID(): any; -}; -export default _default; diff --git a/lib/types/core/constants/categories.d.ts b/lib/types/core/constants/categories.d.ts deleted file mode 100644 index bc372ba22..000000000 --- a/lib/types/core/constants/categories.d.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Request processing status categories. - */ -declare enum StatusCategory { - /** - * Call failed when network was unable to complete the call. - */ - PNNetworkIssuesCategory = "PNNetworkIssuesCategory", - /** - * Network call timed out. - */ - PNTimeoutCategory = "PNTimeoutCategory", - /** - * Request has been cancelled. - */ - PNCancelledCategory = "PNCancelledCategory", - /** - * Server responded with bad response. - */ - PNBadRequestCategory = "PNBadRequestCategory", - /** - * Server responded with access denied. - */ - PNAccessDeniedCategory = "PNAccessDeniedCategory", - /** - * Incomplete parameters provided for used endpoint. - */ - PNValidationErrorCategory = "PNValidationErrorCategory", - /** - * PubNub request acknowledgment status. - * - * Some API endpoints respond with request processing status w/o useful data. - */ - PNAcknowledgmentCategory = "PNAcknowledgmentCategory", - /** - * Something strange happened; please check the logs. - */ - PNUnknownCategory = "PNUnknownCategory", - /** - * SDK will announce when the network appears to be connected again. - */ - PNNetworkUpCategory = "PNNetworkUpCategory", - /** - * SDK will announce when the network appears to down. - */ - PNNetworkDownCategory = "PNNetworkDownCategory", - /** - * PubNub client reconnected to the real-time updates stream. - */ - PNReconnectedCategory = "PNReconnectedCategory", - /** - * PubNub client connected to the real-time updates stream. - */ - PNConnectedCategory = "PNConnectedCategory", - /** - * Received real-time updates exceed specified threshold. - * - * After temporary disconnection and catchup, this category means that potentially some - * real-time updates have been pushed into `storage` and need to be requested separately. - */ - PNRequestMessageCountExceededCategory = "PNRequestMessageCountExceededCategory", - /** - * PubNub client disconnected from the real-time updates streams. - */ - PNDisconnectedCategory = "PNDisconnectedCategory", - /** - * PubNub client wasn't able to connect to the real-time updates streams. - */ - PNConnectionErrorCategory = "PNConnectionErrorCategory", - /** - * PubNub client unexpectedly disconnected from the real-time updates streams. - */ - PNDisconnectedUnexpectedlyCategory = "PNDisconnectedUnexpectedlyCategory" -} -export default StatusCategory; diff --git a/lib/types/core/constants/operations.d.ts b/lib/types/core/constants/operations.d.ts deleted file mode 100644 index 2684a4880..000000000 --- a/lib/types/core/constants/operations.d.ts +++ /dev/null @@ -1,203 +0,0 @@ -declare enum RequestOperation { - /** - * Data publish REST API operation. - */ - PNPublishOperation = "PNPublishOperation", - /** - * Signal sending REST API operation. - */ - PNSignalOperation = "PNSignalOperation", - /** - * Subscribe for real-time updates REST API operation. - * - * User's presence change on specified entities will trigger `join` event. - */ - PNSubscribeOperation = "PNSubscribeOperation", - /** - * Unsubscribe from real-time updates REST API operation. - * - * User's presence change on specified entities will trigger `leave` event. - */ - PNUnsubscribeOperation = "PNUnsubscribeOperation", - /** - * Fetch user's presence information REST API operation. - */ - PNWhereNowOperation = "PNWhereNowOperation", - /** - * Fetch channel's presence information REST API operation. - */ - PNHereNowOperation = "PNHereNowOperation", - /** - * Fetch global presence information REST API operation. - */ - PNGlobalHereNowOperation = "PNGlobalHereNowOperation", - /** - * Update user's information associated with specified channel REST API operation. - */ - PNSetStateOperation = "PNSetStateOperation", - /** - * Fetch user's information associated with the specified channel REST API operation. - */ - PNGetStateOperation = "PNGetStateOperation", - /** - * Announce presence on managed channels REST API operation. - */ - PNHeartbeatOperation = "PNHeartbeatOperation", - /** - * Add a reaction to the specified message REST API operation. - */ - PNAddMessageActionOperation = "PNAddActionOperation", - /** - * Remove reaction from the specified message REST API operation. - */ - PNRemoveMessageActionOperation = "PNRemoveMessageActionOperation", - /** - * Fetch reactions for specific message REST API operation. - */ - PNGetMessageActionsOperation = "PNGetMessageActionsOperation", - PNTimeOperation = "PNTimeOperation", - /** - * Channel history REST API operation. - */ - PNHistoryOperation = "PNHistoryOperation", - /** - * Delete messages from channel history REST API operation. - */ - PNDeleteMessagesOperation = "PNDeleteMessagesOperation", - /** - * History for channels REST API operation. - */ - PNFetchMessagesOperation = "PNFetchMessagesOperation", - /** - * Number of messages for channels in specified time frame REST API operation. - */ - PNMessageCounts = "PNMessageCountsOperation", - /** - * Fetch users metadata REST API operation. - */ - PNGetAllUUIDMetadataOperation = "PNGetAllUUIDMetadataOperation", - /** - * Fetch user metadata REST API operation. - */ - PNGetUUIDMetadataOperation = "PNGetUUIDMetadataOperation", - /** - * Set user metadata REST API operation. - */ - PNSetUUIDMetadataOperation = "PNSetUUIDMetadataOperation", - /** - * Remove user metadata REST API operation. - */ - PNRemoveUUIDMetadataOperation = "PNRemoveUUIDMetadataOperation", - /** - * Fetch channels metadata REST API operation. - */ - PNGetAllChannelMetadataOperation = "PNGetAllChannelMetadataOperation", - /** - * Fetch channel metadata REST API operation. - */ - PNGetChannelMetadataOperation = "PNGetChannelMetadataOperation", - /** - * Set channel metadata REST API operation. - */ - PNSetChannelMetadataOperation = "PNSetChannelMetadataOperation", - /** - * Remove channel metadata REST API operation. - */ - PNRemoveChannelMetadataOperation = "PNRemoveChannelMetadataOperation", - /** - * Fetch channel members REST API operation. - */ - PNGetMembersOperation = "PNGetMembersOperation", - /** - * Update channel members REST API operation. - */ - PNSetMembersOperation = "PNSetMembersOperation", - /** - * Fetch channel memberships REST API operation. - */ - PNGetMembershipsOperation = "PNGetMembershipsOperation", - /** - * Update channel memberships REST API operation. - */ - PNSetMembershipsOperation = "PNSetMembershipsOperation", - /** - * Fetch list of files sent to the channel REST API operation. - */ - PNListFilesOperation = "PNListFilesOperation", - /** - * Retrieve file upload URL REST API operation. - */ - PNGenerateUploadUrlOperation = "PNGenerateUploadUrlOperation", - /** - * Upload file to the channel REST API operation. - */ - PNPublishFileOperation = "PNPublishFileOperation", - /** - * Publish File Message to the channel REST API operation. - */ - PNPublishFileMessageOperation = "PNPublishFileMessageOperation", - /** - * Retrieve file download URL REST API operation. - */ - PNGetFileUrlOperation = "PNGetFileUrlOperation", - /** - * Download file from the channel REST API operation. - */ - PNDownloadFileOperation = "PNDownloadFileOperation", - /** - * Delete file sent to the channel REST API operation. - */ - PNDeleteFileOperation = "PNDeleteFileOperation", - /** - * Register channels with device push notifications REST API operation. - */ - PNAddPushNotificationEnabledChannelsOperation = "PNAddPushNotificationEnabledChannelsOperation", - /** - * Unregister channels with device push notifications REST API operation. - */ - PNRemovePushNotificationEnabledChannelsOperation = "PNRemovePushNotificationEnabledChannelsOperation", - /** - * Fetch list of channels with enabled push notifications for device REST API operation. - */ - PNPushNotificationEnabledChannelsOperation = "PNPushNotificationEnabledChannelsOperation", - /** - * Disable push notifications for device REST API operation. - */ - PNRemoveAllPushNotificationsOperation = "PNRemoveAllPushNotificationsOperation", - /** - * Fetch channels groups list REST API operation. - */ - PNChannelGroupsOperation = "PNChannelGroupsOperation", - /** - * Remove specified channel group REST API operation. - */ - PNRemoveGroupOperation = "PNRemoveGroupOperation", - /** - * Fetch list of channels for the specified channel group REST API operation. - */ - PNChannelsForGroupOperation = "PNChannelsForGroupOperation", - /** - * Add list of channels to the specified channel group REST API operation. - */ - PNAddChannelsToGroupOperation = "PNAddChannelsToGroupOperation", - /** - * Remove list of channels from the specified channel group REST API operation. - */ - PNRemoveChannelsFromGroupOperation = "PNRemoveChannelsFromGroupOperation", - /** - * Generate authorized token REST API operation. - */ - PNAccessManagerGrant = "PNAccessManagerGrant", - /** - * Generate authorized token REST API operation. - */ - PNAccessManagerGrantToken = "PNAccessManagerGrantToken", - PNAccessManagerAudit = "PNAccessManagerAudit", - /** - * Revoke authorized token REST API operation. - */ - PNAccessManagerRevokeToken = "PNAccessManagerRevokeToken", - PNHandshakeOperation = "PNHandshakeOperation", - PNReceiveMessagesOperation = "PNReceiveMessagesOperation" -} -export default RequestOperation; diff --git a/lib/types/core/endpoints/access_manager/audit.d.ts b/lib/types/core/endpoints/access_manager/audit.d.ts deleted file mode 100644 index 78b5769e2..000000000 --- a/lib/types/core/endpoints/access_manager/audit.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * PAM Audit REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/access_manager/grant.d.ts b/lib/types/core/endpoints/access_manager/grant.d.ts deleted file mode 100644 index 0e51654bd..000000000 --- a/lib/types/core/endpoints/access_manager/grant.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * PAM Grant REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/access_manager/grant_token.d.ts b/lib/types/core/endpoints/access_manager/grant_token.d.ts deleted file mode 100644 index 6895635ff..000000000 --- a/lib/types/core/endpoints/access_manager/grant_token.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * PAM Grant Token REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/access_manager/revoke_token.d.ts b/lib/types/core/endpoints/access_manager/revoke_token.d.ts deleted file mode 100644 index 207f87cba..000000000 --- a/lib/types/core/endpoints/access_manager/revoke_token.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * PAM Revoke Token REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/actions/add_message_action.d.ts b/lib/types/core/endpoints/actions/add_message_action.d.ts deleted file mode 100644 index e80c018b0..000000000 --- a/lib/types/core/endpoints/actions/add_message_action.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Add Message Action REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/actions/get_message_actions.d.ts b/lib/types/core/endpoints/actions/get_message_actions.d.ts deleted file mode 100644 index 6206ec73f..000000000 --- a/lib/types/core/endpoints/actions/get_message_actions.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Get Message Actions REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/actions/remove_message_action.d.ts b/lib/types/core/endpoints/actions/remove_message_action.d.ts deleted file mode 100644 index 51aa42da6..000000000 --- a/lib/types/core/endpoints/actions/remove_message_action.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Remove Message Action REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/channel_groups/add_channels.d.ts b/lib/types/core/endpoints/channel_groups/add_channels.d.ts deleted file mode 100644 index 4d3dfefd8..000000000 --- a/lib/types/core/endpoints/channel_groups/add_channels.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Add channel group channels REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/channel_groups/delete_group.d.ts b/lib/types/core/endpoints/channel_groups/delete_group.d.ts deleted file mode 100644 index 873f58775..000000000 --- a/lib/types/core/endpoints/channel_groups/delete_group.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Delete channel group REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/channel_groups/list_channels.d.ts b/lib/types/core/endpoints/channel_groups/list_channels.d.ts deleted file mode 100644 index 1688a1d49..000000000 --- a/lib/types/core/endpoints/channel_groups/list_channels.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * List channel group channels REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/channel_groups/list_groups.d.ts b/lib/types/core/endpoints/channel_groups/list_groups.d.ts deleted file mode 100644 index 2aa05098f..000000000 --- a/lib/types/core/endpoints/channel_groups/list_groups.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * List All Channel Groups REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/channel_groups/remove_channels.d.ts b/lib/types/core/endpoints/channel_groups/remove_channels.d.ts deleted file mode 100644 index f46a8e049..000000000 --- a/lib/types/core/endpoints/channel_groups/remove_channels.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Remove channel group channels REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/fetch_messages.d.ts b/lib/types/core/endpoints/fetch_messages.d.ts deleted file mode 100644 index a58cec3cc..000000000 --- a/lib/types/core/endpoints/fetch_messages.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Fetch messages REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/file_upload/delete_file.d.ts b/lib/types/core/endpoints/file_upload/delete_file.d.ts deleted file mode 100644 index 87204dacd..000000000 --- a/lib/types/core/endpoints/file_upload/delete_file.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Delete file REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/file_upload/download_file.d.ts b/lib/types/core/endpoints/file_upload/download_file.d.ts deleted file mode 100644 index 8591c0b12..000000000 --- a/lib/types/core/endpoints/file_upload/download_file.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Download File REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/file_upload/generate_upload_url.d.ts b/lib/types/core/endpoints/file_upload/generate_upload_url.d.ts deleted file mode 100644 index 24d09f51a..000000000 --- a/lib/types/core/endpoints/file_upload/generate_upload_url.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Generate file upload URL REST API request. - */ -export {}; diff --git a/lib/types/core/endpoints/file_upload/get_file_url.d.ts b/lib/types/core/endpoints/file_upload/get_file_url.d.ts deleted file mode 100644 index 925eee0d8..000000000 --- a/lib/types/core/endpoints/file_upload/get_file_url.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * File sharing REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/file_upload/list_files.d.ts b/lib/types/core/endpoints/file_upload/list_files.d.ts deleted file mode 100644 index a85d9abf5..000000000 --- a/lib/types/core/endpoints/file_upload/list_files.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * List Files REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/file_upload/publish_file.d.ts b/lib/types/core/endpoints/file_upload/publish_file.d.ts deleted file mode 100644 index 3bf7b9ebd..000000000 --- a/lib/types/core/endpoints/file_upload/publish_file.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Publish File Message REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/file_upload/send_file.d.ts b/lib/types/core/endpoints/file_upload/send_file.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/lib/types/core/endpoints/file_upload/send_file.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/types/core/endpoints/file_upload/upload-file.d.ts b/lib/types/core/endpoints/file_upload/upload-file.d.ts deleted file mode 100644 index 6959033bd..000000000 --- a/lib/types/core/endpoints/file_upload/upload-file.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Upload file REST API request. - */ -export {}; diff --git a/lib/types/core/endpoints/history/delete_messages.d.ts b/lib/types/core/endpoints/history/delete_messages.d.ts deleted file mode 100644 index c189fd470..000000000 --- a/lib/types/core/endpoints/history/delete_messages.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Delete messages REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/history/get_history.d.ts b/lib/types/core/endpoints/history/get_history.d.ts deleted file mode 100644 index 485ad476b..000000000 --- a/lib/types/core/endpoints/history/get_history.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Get history REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/history/message_counts.d.ts b/lib/types/core/endpoints/history/message_counts.d.ts deleted file mode 100644 index 7985a94f9..000000000 --- a/lib/types/core/endpoints/history/message_counts.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Messages count REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/channel/get.d.ts b/lib/types/core/endpoints/objects/channel/get.d.ts deleted file mode 100644 index c56a41184..000000000 --- a/lib/types/core/endpoints/objects/channel/get.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Get Channel Metadata REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/channel/get_all.d.ts b/lib/types/core/endpoints/objects/channel/get_all.d.ts deleted file mode 100644 index 777c4ab1c..000000000 --- a/lib/types/core/endpoints/objects/channel/get_all.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Get All Channel Metadata REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/channel/remove.d.ts b/lib/types/core/endpoints/objects/channel/remove.d.ts deleted file mode 100644 index 0779bb2c8..000000000 --- a/lib/types/core/endpoints/objects/channel/remove.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Remove Channel Metadata REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/channel/set.d.ts b/lib/types/core/endpoints/objects/channel/set.d.ts deleted file mode 100644 index e12e2fb2b..000000000 --- a/lib/types/core/endpoints/objects/channel/set.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Set Channel Metadata REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/member/get.d.ts b/lib/types/core/endpoints/objects/member/get.d.ts deleted file mode 100644 index db192f3b6..000000000 --- a/lib/types/core/endpoints/objects/member/get.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Get Channel Members REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/member/set.d.ts b/lib/types/core/endpoints/objects/member/set.d.ts deleted file mode 100644 index 67d6a5133..000000000 --- a/lib/types/core/endpoints/objects/member/set.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Set Channel Members REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/membership/get.d.ts b/lib/types/core/endpoints/objects/membership/get.d.ts deleted file mode 100644 index 3db81e283..000000000 --- a/lib/types/core/endpoints/objects/membership/get.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Get UUID Memberships REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/membership/set.d.ts b/lib/types/core/endpoints/objects/membership/set.d.ts deleted file mode 100644 index 61cb530a7..000000000 --- a/lib/types/core/endpoints/objects/membership/set.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Set UUID Memberships REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/uuid/get.d.ts b/lib/types/core/endpoints/objects/uuid/get.d.ts deleted file mode 100644 index 40e5f4817..000000000 --- a/lib/types/core/endpoints/objects/uuid/get.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Get UUID Metadata REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/uuid/get_all.d.ts b/lib/types/core/endpoints/objects/uuid/get_all.d.ts deleted file mode 100644 index 33e8a18dc..000000000 --- a/lib/types/core/endpoints/objects/uuid/get_all.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Get All UUID Metadata REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/uuid/remove.d.ts b/lib/types/core/endpoints/objects/uuid/remove.d.ts deleted file mode 100644 index 74edbb159..000000000 --- a/lib/types/core/endpoints/objects/uuid/remove.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Remove UUID Metadata REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/objects/uuid/set.d.ts b/lib/types/core/endpoints/objects/uuid/set.d.ts deleted file mode 100644 index d4b96bdf7..000000000 --- a/lib/types/core/endpoints/objects/uuid/set.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Set UUID Metadata REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/presence/get_state.d.ts b/lib/types/core/endpoints/presence/get_state.d.ts deleted file mode 100644 index dff42db68..000000000 --- a/lib/types/core/endpoints/presence/get_state.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Get Presence State REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/presence/heartbeat.d.ts b/lib/types/core/endpoints/presence/heartbeat.d.ts deleted file mode 100644 index 52b3c35c2..000000000 --- a/lib/types/core/endpoints/presence/heartbeat.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Announce heartbeat REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/presence/here_now.d.ts b/lib/types/core/endpoints/presence/here_now.d.ts deleted file mode 100644 index 7f077a5e2..000000000 --- a/lib/types/core/endpoints/presence/here_now.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Channels / channel groups presence REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/presence/leave.d.ts b/lib/types/core/endpoints/presence/leave.d.ts deleted file mode 100644 index d6ba4460c..000000000 --- a/lib/types/core/endpoints/presence/leave.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Announce leave REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/presence/set_state.d.ts b/lib/types/core/endpoints/presence/set_state.d.ts deleted file mode 100644 index d18769ae2..000000000 --- a/lib/types/core/endpoints/presence/set_state.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Set Presence State REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/presence/where_now.d.ts b/lib/types/core/endpoints/presence/where_now.d.ts deleted file mode 100644 index 2c4ddd3c0..000000000 --- a/lib/types/core/endpoints/presence/where_now.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * `uuid` presence REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/publish.d.ts b/lib/types/core/endpoints/publish.d.ts deleted file mode 100644 index f313eb4c5..000000000 --- a/lib/types/core/endpoints/publish.d.ts +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Publish REST API module. - */ -import { CryptoModule } from '../interfaces/crypto-module'; -import { Payload } from '../types/api'; -/** - * Request configuration parameters. - */ -export type PublishParameters = { - /** - * Channel name to publish messages to. - */ - channel: string; - /** - * Data which should be sent to the `channel`. - * - * The message may be any valid JSON type including objects, arrays, strings, and numbers. - */ - message: Payload; - /** - * Whether published data should be available with `Storage API` later or not. - * - * @default `true` - */ - storeInHistory?: boolean; - /** - * Whether message should be sent as part of request POST body or not. - * - * @default `false` - */ - sendByPost?: boolean; - /** - * Metadata, which should be associated with published data. - * - * Associated metadata can be utilized by message filtering feature. - */ - meta?: Payload; - /** - * Specify duration during which data will be available with `Storage API`. - * - * - If `storeInHistory` = `true`, and `ttl` = `0`, the `message` is stored with no expiry time. - * - If `storeInHistory` = `true` and `ttl` = `X` (`X` is an Integer value), the `message` is - * stored with an expiry time of `X` hours. - * - If `storeInHistory` = `false`, the `ttl` parameter is ignored. - * - If `ttl` is not specified, then expiration of the `message` defaults back to the expiry value - * for the key. - */ - ttl?: number; - /** - * Whether published data should be replicated across all data centers or not. - * - * @default `true` - * @deprecated - */ - replicate?: boolean; - /** - * Indexed signature for deprecated parameters. - */ - [key: string]: string | number | boolean | undefined | Payload | CryptoModule; -}; -/** - * Service success response. - */ -export type PublishResponse = { - /** - * High-precision time when published data has been received by the PubNub service. - */ - timetoken: string; -}; diff --git a/lib/types/core/endpoints/push/add_push_channels.d.ts b/lib/types/core/endpoints/push/add_push_channels.d.ts deleted file mode 100644 index ba565c462..000000000 --- a/lib/types/core/endpoints/push/add_push_channels.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Register Channels with Device push REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/push/list_push_channels.d.ts b/lib/types/core/endpoints/push/list_push_channels.d.ts deleted file mode 100644 index cb340e6c5..000000000 --- a/lib/types/core/endpoints/push/list_push_channels.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * List Device push enabled channels REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/push/push.d.ts b/lib/types/core/endpoints/push/push.d.ts deleted file mode 100644 index c9f462716..000000000 --- a/lib/types/core/endpoints/push/push.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Manage channels enabled for device push REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/push/remove_device.d.ts b/lib/types/core/endpoints/push/remove_device.d.ts deleted file mode 100644 index ba3047e70..000000000 --- a/lib/types/core/endpoints/push/remove_device.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Unregister Device push REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/push/remove_push_channels.d.ts b/lib/types/core/endpoints/push/remove_push_channels.d.ts deleted file mode 100644 index d1343dbc7..000000000 --- a/lib/types/core/endpoints/push/remove_push_channels.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Unregister Channels from Device push REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/signal.d.ts b/lib/types/core/endpoints/signal.d.ts deleted file mode 100644 index 9238bd206..000000000 --- a/lib/types/core/endpoints/signal.d.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Signal REST API module. - */ -import { Payload } from '../types/api'; -/** - * Request configuration parameters. - */ -export type SignalParameters = { - /** - * Channel name to publish signal to. - */ - channel: string; - /** - * Data which should be sent to the `channel`. - * - * The message may be any valid JSON type including objects, arrays, strings, and numbers. - */ - message: Payload; -}; -/** - * Service success response. - */ -export type SignalResponse = { - /** - * High-precision time when published data has been received by the PubNub service. - */ - timetoken: string; -}; diff --git a/lib/types/core/endpoints/subscribe.d.ts b/lib/types/core/endpoints/subscribe.d.ts deleted file mode 100644 index a7be65799..000000000 --- a/lib/types/core/endpoints/subscribe.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Subscription REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/subscriptionUtils/handshake.d.ts b/lib/types/core/endpoints/subscriptionUtils/handshake.d.ts deleted file mode 100644 index 2a942a579..000000000 --- a/lib/types/core/endpoints/subscriptionUtils/handshake.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Handshake subscribe REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/subscriptionUtils/receiveMessages.d.ts b/lib/types/core/endpoints/subscriptionUtils/receiveMessages.d.ts deleted file mode 100644 index 640df8780..000000000 --- a/lib/types/core/endpoints/subscriptionUtils/receiveMessages.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Receive messages subscribe REST API module. - */ -export {}; diff --git a/lib/types/core/endpoints/time.d.ts b/lib/types/core/endpoints/time.d.ts deleted file mode 100644 index cda43e5ea..000000000 --- a/lib/types/core/endpoints/time.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Time REST API module. - */ -/** - * Service success response. - */ -export type TimeResponse = { - /** - * High-precision time when published data has been received by the PubNub service. - */ - timetoken: string; -}; diff --git a/lib/types/core/interfaces/configuration.d.ts b/lib/types/core/interfaces/configuration.d.ts deleted file mode 100644 index 63ce7b036..000000000 --- a/lib/types/core/interfaces/configuration.d.ts +++ /dev/null @@ -1,276 +0,0 @@ -/** - * {@link PubNub} client configuration module. - */ -import { RequestRetryPolicy } from '../../event-engine/core/retryPolicy'; -/** - * Base user-provided PubNub client configuration. - */ -export type UserConfiguration = { - /** - * Specifies the `subscribeKey` to be used for subscribing to a channel and message publishing. - */ - subscribeKey: string; - /** - * Specifies the `subscribe_key` to be used for subscribing to a channel and message publishing. - * - * @deprecated Use the {@link subscribeKey} instead. - */ - subscribe_key?: string; - /** - * Specifies the `publishKey` to be used for publishing messages to a channel. - */ - publishKey?: string; - /** - * Specifies the `publish_key` to be used for publishing messages to a channel. - * - * @deprecated Use the {@link publishKey} instead. - */ - publish_key?: string; - /** - * Specifies the `secretKey` to be used for request signatures computation. - */ - secretKey?: string; - /** - * Specifies the `secret_key` to be used for request signatures computation. - * - * @deprecated Use the {@link secretKey} instead. - */ - secret_key?: string; - /** - * Unique PubNub client user identifier. - * - * Unique `userId` to identify the user or the device that connects to PubNub. - * It's a UTF-8 encoded string of up to 64 alphanumeric characters. - * - * If you don't set the `userId`, you won't be able to connect to PubNub. - */ - userId?: string; - /** - * If Access Manager enabled, this key will be used on all requests. - */ - authKey?: string | null; - /** - * Log HTTP information. - * - * @default `false` - */ - logVerbosity?: boolean; - /** - * If set to true, requests will be made over HTTPS. - * - * @default `true` for v4.20.0 onwards, `false` before v4.20.0 - */ - ssl?: boolean; - /** - * If a custom domain is required, SDK accepts it here. - * - * @default `ps.pndsn.com` - */ - origin?: string | string[]; - /** - * How long the server will consider the client alive for presence.The value is in seconds. - * - * @default `300` - */ - presenceTimeout?: number; - /** - * How often the client will announce itself to server.The value is in seconds. - * - * @default `not set` - */ - heartbeatInterval?: number; - /** - * Transactional requests timeout in milliseconds. - * - * Maximum duration for which PubNub client should wait for transactional request completion. - * - * @default `15` seconds - */ - transactionalRequestTimeout?: number; - /** - * Subscription requests timeout in milliseconds. - * - * Maximum duration for which PubNub client should wait for subscription request completion. - * - * @default `310` seconds - */ - subscribeRequestTimeout?: number; - /** - * `true` to allow catch up on the front-end applications. - * - * @default `false` - */ - restore?: boolean; - /** - * Whether to include the PubNub object instance ID in outgoing requests. - * - * @default `false` - */ - useInstanceId?: boolean; - /** - * When `true` the SDK doesn't send out the leave requests. - * - * @default `false` - */ - suppressLeaveEvents?: boolean; - /** - * `PNRequestMessageCountExceededCategory` is thrown when the number of messages into the - * payload is above of `requestMessageCountThreshold`. - * - * @default `100` - */ - requestMessageCountThreshold?: number; - /** - * This flag announces when the network is down or up using the states `PNNetworkDownCategory` - * and `PNNetworkUpCategory`. - * - * @default `false` - */ - autoNetworkDetection?: boolean; - /** - * Whether to use the standardized workflows for subscribe and presence. - * - * Note that the `maintainPresenceState` parameter is set to true by default, so make sure to - * disable it if you don't need to maintain presence state. For more information, refer to the - * param description in this table. - * - * - * @default `false` - */ - enableEventEngine?: boolean; - /** - * Custom reconnection configuration parameters. - * - * `retryConfiguration: policy` is the type of policy to be used. - * - * Available values: - * - `PubNub.LinearRetryPolicy({ delay, maximumRetry })` - * - `PubNub.ExponentialRetryPolicy({ minimumDelay, maximumDelay, maximumRetry })` - * - * For more information, refer to - * {@link /docs/general/setup/connection-management#reconnection-policy|Reconnection Policy}. JavaScript doesn't - * support excluding endpoints. - * - * @default `not set` - */ - retryConfiguration?: RequestRetryPolicy; - /** - * Whether the `state` set using `setState()` should be maintained for the current `userId`. - * This option works only when `enableEventEngine` is set to `true`. - * - * @default `true` - */ - maintainPresenceState?: boolean; - /** - * `UUID` to use. You should set a unique `UUID` to identify the user or the device that - * connects to PubNub. - * If you don't set the `UUID`, you won't be able to connect to PubNub. - * - * @deprecated Use {@link userId} instead. - */ - uuid?: string; - /** - * If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of - * opening a new one for each new request. - * - * @default `false` - */ - keepAlive?: boolean; - /** - * If the SDK is running as part of another SDK built atop of it, allow a custom `pnsdk` with - * name and version. - */ - sdkName?: string; - /** - * If the SDK is operated by a partner, allow a custom `pnsdk` item for them. - */ - partnerId?: string; -}; -/** - * User-provided configuration object interface. - * - * Interface contains limited set of settings manipulation and access. - */ -export interface ClientConfiguration { - /** - * Get a PubNub client user identifier. - * - * @returns Current PubNub client user identifier. - */ - getUserId(): string; - /** - * Change the current PubNub client user identifier. - * - * **Important:** Change won't affect ongoing REST API calls. - * - * @param value - New PubNub client user identifier. - * - * @throws Error empty user identifier has been provided. - */ - setUserId(value: string): void; - /** - * Change REST API endpoint access authorization key. - * - * @param authKey - New authorization key which should be used with new requests. - */ - setAuthKey(authKey: string | null): void; - /** - * Real-time updates filtering expression. - * - * @returns Filtering expression. - */ - getFilterExpression(): string | undefined | null; - /** - * Update real-time updates filtering expression. - * - * @param expression - New expression which should be used or `undefined` to disable filtering. - */ - setFilterExpression(expression: string | null | undefined): void; - /** - * Change data encryption / decryption key. - * - * @param key - New key which should be used for data encryption / decryption. - */ - setCipherKey(key: string | undefined): void; - /** - * Get PubNub SDK version. - * - * @returns Current SDK version. - */ - get version(): string; - /** - * Get PubNub SDK version. - * - * @returns Current SDK version. - */ - getVersion(): string; - /** - * Add framework's prefix. - * - * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. - * @param suffix - Suffix with information about framework. - */ - _addPnsdkSuffix(name: string, suffix: string | number): void; - /** - * Get a PubNub client user identifier. - * - * @returns Current PubNub client user identifier. - * - * @deprecated Use the {@link getUserId} or {@link userId} getter instead. - */ - getUUID(): string; - /** - * Change the current PubNub client user identifier. - * - * **Important:** Change won't affect ongoing REST API calls. - * - * @param value - New PubNub client user identifier. - * - * @returns {Configuration} Reference to the configuration instance for easier chaining. - * - * @throws Error empty user identifier has been provided. - * - * @deprecated Use the {@link setUserId} or {@link userId} setter instead. - */ - setUUID(value: string): void; -} diff --git a/lib/types/core/interfaces/crypto-module.d.ts b/lib/types/core/interfaces/crypto-module.d.ts deleted file mode 100644 index 621df079a..000000000 --- a/lib/types/core/interfaces/crypto-module.d.ts +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Crypto module. - */ -import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; -import { Payload } from '../types/api'; -/** - * Crypto module configuration. - */ -export type CryptoModuleConfiguration = { - default: C; - cryptors?: C[]; -}; -export type CryptorConfiguration = { - /** - * Data encryption / decryption key. - */ - cipherKey?: string; - /** - * Request sign secret key. - */ - secretKey?: string; - /** - * Whether random initialization vector should be used or not. - * - * @default `true` - */ - useRandomIVs?: boolean; - /** - * Custom data encryption method. - * - * @deprecated Instead use {@link cryptoModule} for data encryption. - */ - customEncrypt?: (data: string | Payload) => string; - /** - * Custom data decryption method. - * - * @deprecated Instead use {@link cryptoModule} for data decryption. - */ - customDecrypt?: (data: string) => string; -}; -/** - * Base crypto module interface. - */ -export interface CryptoModule { - /** - * Encrypt data. - * - * @param data - Data which should be encrypted using `CryptoModule`. - * - * @returns Data encryption result. - */ - encrypt(data: ArrayBuffer | string): ArrayBuffer | string; - /** - * Encrypt file object. - * - * @param file - File object with data for encryption. - * @param File - File object constructor to create instance for encrypted data representation. - * - * @returns Asynchronous file encryption result. - */ - encryptFile(file: PubNubFileInterface, File: PubNubFileConstructor): Promise; - /** - * Encrypt data. - * - * @param data - Dta which should be encrypted using `CryptoModule`. - * - * @returns Data decryption result. - */ - decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null; - /** - * Decrypt file object. - * - * @param file - Encrypted file object with data for decryption. - * @param File - File object constructor to create instance for decrypted data representation. - * - * @returns Asynchronous file decryption result. - */ - decryptFile(file: PubNubFileInterface, File: PubNubFileConstructor): Promise; -} -export declare abstract class AbstractCryptoModule implements CryptoModule { - /** - * `String` to {@link ArrayBuffer} response decoder. - */ - protected static encoder: TextEncoder; - /** - * {@link ArrayBuffer} to {@link string} decoder. - */ - protected static decoder: TextDecoder; - defaultCryptor: C; - cryptors: C[]; - /** - * Construct crypto module with legacy cryptor for encryption and both legacy and AES-CBC - * cryptors for decryption. - * - * @param config Cryptors configuration options. - * - * @returns Crypto module which encrypts data using legacy cryptor. - * - * @throws Error if `config.cipherKey` not set. - */ - static legacyCryptoModule(config: CryptorConfiguration): CryptoModule; - /** - * Construct crypto module with AES-CBC cryptor for encryption and both AES-CBC and legacy - * cryptors for decryption. - * - * @param config Cryptors configuration options. - * - * @returns Crypto module which encrypts data using AES-CBC cryptor. - * - * @throws Error if `config.cipherKey` not set. - */ - static aesCbcCryptoModule(config: CryptorConfiguration): CryptoModule; - constructor(configuration: CryptoModuleConfiguration); - /** - * Encrypt data. - * - * @param data - Data which should be encrypted using {@link CryptoModule}. - * - * @returns Data encryption result. - */ - abstract encrypt(data: ArrayBuffer | string): ArrayBuffer | string; - /** - * Encrypt file object. - * - * @param file - File object with data for encryption. - * @param File - File object constructor to create instance for encrypted data representation. - * - * @returns Asynchronous file encryption result. - */ - abstract encryptFile(file: PubNubFileInterface, File: PubNubFileConstructor): Promise; - /** - * Encrypt data. - * - * @param data - Dta which should be encrypted using `CryptoModule`. - * - * @returns Data decryption result. - */ - abstract decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null; - /** - * Decrypt file object. - * - * @param file - Encrypted file object with data for decryption. - * @param File - File object constructor to create instance for decrypted data representation. - * - * @returns Asynchronous file decryption result. - */ - abstract decryptFile(file: PubNubFileInterface, File: PubNubFileConstructor): Promise; - /** - * Retrieve list of module's cryptors. - */ - protected getAllCryptors(): C[]; -} diff --git a/lib/types/core/interfaces/cryptography.d.ts b/lib/types/core/interfaces/cryptography.d.ts deleted file mode 100644 index 9b73050a5..000000000 --- a/lib/types/core/interfaces/cryptography.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Legacy Cryptography module interface. - */ -import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; -export interface Cryptography { - /** - * Encrypt provided source data using specific encryption {@link key}. - * - * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` data. - * @param input - Source data for encryption. - * - * @returns Encrypted data as object or stream (depending on from source data type). - * - * @throws Error if unknown data type has been passed. - */ - encrypt(key: string, input: Types): Promise; - /** - * Decrypt provided encrypted data using specific decryption {@link key}. - * - * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` data. - * @param input - Encrypted data for decryption. - * - * @returns Decrypted data as object or stream (depending on from encrypted data type). - * - * @throws Error if unknown data type has been passed. - */ - decrypt(key: string, input: Types): Promise; - /** - * Encrypt provided `PubNub` File object using specific encryption {@link key}. - * - * @param key - Key for `PubNub` File object encryption.
**Note:** Same key should be - * used to `decrypt` data. - * @param file - Source `PubNub` File object for encryption. - * @param File - Class constructor for `PubNub` File object. - * - * @returns Encrypted data as `PubNub` File object. - * - * @throws Error if file is empty or contains unsupported data type. - */ - encryptFile(key: string, file: PubNubFileInterface, File: PubNubFileConstructor): Promise; - /** - * Decrypt provided `PubNub` File object using specific decryption {@link key}. - * - * @param key - Key for `PubNub` File object decryption.
**Note:** Should be the same - * as used to `encrypt` data. - * @param file - Encrypted `PubNub` File object for decryption. - * @param File - Class constructor for `PubNub` File object. - * - * @returns Decrypted data as `PubNub` File object. - * - * @throws Error if file is empty or contains unsupported data type. - */ - decryptFile(key: string, file: PubNubFileInterface, File: PubNubFileConstructor): Promise; -} diff --git a/lib/types/core/interfaces/request.d.ts b/lib/types/core/interfaces/request.d.ts deleted file mode 100644 index cb0ff5c3b..000000000 --- a/lib/types/core/interfaces/request.d.ts +++ /dev/null @@ -1 +0,0 @@ -export {}; diff --git a/lib/types/core/interfaces/transport.d.ts b/lib/types/core/interfaces/transport.d.ts deleted file mode 100644 index 82ec357eb..000000000 --- a/lib/types/core/interfaces/transport.d.ts +++ /dev/null @@ -1,61 +0,0 @@ -import { CancellationController, TransportRequest } from '../types/transport-request'; -import { TransportResponse } from '../types/transport-response'; -/** - * Represents the configuration options for keeping the transport connection alive. - */ -export type TransportKeepAlive = { - /** - * The time interval in milliseconds for keeping the connection alive. - * - * @default 1000 - */ - keepAliveMsecs?: number; - /** - * The maximum number of sockets allowed per host. - * - * @default Infinity - */ - maxSockets?: number; - /** - * The maximum number of open and free sockets in the pool per host. - * - * @default 256 - */ - maxFreeSockets?: number; - /** - * Timeout in milliseconds, after which the `idle` socket will be closed. - * - * @default 30000 - */ - timeout?: number; -}; -/** - * This interface is used to send requests to the PubNub API. - * - * You can implement this interface for your types, or use one of the provided modules to use a - * transport library. - * - * @interface - */ -export interface Transport { - /** - * Make request sendable. - * - * @param req - The transport request to be processed. - * - * @returns - A promise that resolves to a transport response and request cancellation - * controller (if required). - */ - makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; - /** - * Pre-processed request. - * - * Transport implementation may pre-process original transport requests before making - * platform-specific request objects from it. - * - * @param req - Transport request provided by the PubNub client. - * - * @returns Transport request with updated properties (if it was required). - */ - request(req: TransportRequest): TransportRequest; -} diff --git a/lib/types/core/pubnub-channel-groups.d.ts b/lib/types/core/pubnub-channel-groups.d.ts deleted file mode 100644 index f9c0dc604..000000000 --- a/lib/types/core/pubnub-channel-groups.d.ts +++ /dev/null @@ -1,86 +0,0 @@ -/** - * PubNub Channel Groups API module. - */ -import { KeySet, ResultCallback, SendRequestFunction, StatusCallback } from './types/api'; -import * as ChannelGroups from './types/api/channel-groups'; -export default class PubnubChannelGroups { - private readonly keySet; - private readonly sendRequest; - constructor(keySet: KeySet, sendRequest: SendRequestFunction); - /** - * Fetch channel group channels. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - listChannels(parameters: ChannelGroups.ListChannelGroupChannelsParameters, callback: ResultCallback): void; - /** - * Fetch channel group channels. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get channel group channels response. - */ - listChannels(parameters: ChannelGroups.ListChannelGroupChannelsParameters): Promise; - /** - * Fetch all channel groups. - * - * @param callback - Request completion handler callback. - * - * @deprecated - */ - listGroups(callback: ResultCallback): void; - /** - * Fetch all channel groups. - * - * @returns Asynchronous get all channel groups response. - * - * @deprecated - */ - listGroups(): Promise; - /** - * Add channels to the channel group. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - addChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters, callback: StatusCallback): void; - /** - * Add channels to the channel group. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous add channels to the channel group response. - */ - addChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters): Promise>; - /** - * Remove channels from the channel group. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - removeChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters, callback: StatusCallback): void; - /** - * Remove channels from the channel group. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous remove channels from the channel group response. - */ - removeChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters): Promise>; - /** - * Remove channel group. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - deleteGroup(parameters: ChannelGroups.DeleteChannelGroupParameters, callback: StatusCallback): void; - /** - * Remove channel group. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous remove channel group response. - */ - deleteGroup(parameters: ChannelGroups.DeleteChannelGroupParameters): Promise>; -} diff --git a/lib/types/core/pubnub-common.d.ts b/lib/types/core/pubnub-common.d.ts deleted file mode 100644 index f9bb4df1c..000000000 --- a/lib/types/core/pubnub-common.d.ts +++ /dev/null @@ -1,1300 +0,0 @@ -import { Listener } from './components/listener_manager'; -import NotificationsPayload from './components/push_payload'; -import { TokenManager } from './components/token_manager'; -import Crypto from './components/cryptography/index'; -import { Payload, ResultCallback } from './types/api'; -import { ClientConfiguration, PrivateClientConfiguration } from './interfaces/configuration'; -import { Cryptography } from './interfaces/cryptography'; -import { Transport } from './interfaces/transport'; -import RequestOperation from './constants/operations'; -import StatusCategory from './constants/categories'; -import { RetryPolicy } from '../event-engine/core/retryPolicy'; -import * as Publish from './endpoints/publish'; -import * as Signal from './endpoints/signal'; -import * as Subscription from './types/api/subscription'; -import * as Presence from './types/api/presence'; -import * as History from './types/api/history'; -import * as MessageAction from './types/api/message-action'; -import * as FileSharing from './types/api/file-sharing'; -import { PubNubFileInterface } from './types/file'; -import * as PAM from './types/api/access-manager'; -import { SubscriptionOptions } from '../entities/commonTypes'; -import { ChannelMetadata } from '../entities/ChannelMetadata'; -import { SubscriptionSet } from '../entities/SubscriptionSet'; -import { ChannelGroup } from '../entities/ChannelGroup'; -import { UserMetadata } from '../entities/UserMetadata'; -import { Channel } from '../entities/Channel'; -import PubNubChannelGroups from './pubnub-channel-groups'; -import PubNubPushNotifications from './pubnub-push'; -import * as AppContext from './types/api/app-context'; -import PubNubObjects from './pubnub-objects'; -import * as Time from './endpoints/time'; -type ClientInstanceConfiguration = { - /** - * Client-provided configuration. - */ - configuration: PrivateClientConfiguration; - /** - * Transport provider for requests execution. - */ - transport: Transport; - /** - * REST API endpoints access tokens manager. - */ - tokenManager?: TokenManager; - /** - * Legacy crypto module implementation. - */ - cryptography?: Cryptography; - /** - * Legacy crypto (legacy data encryption / decryption and request signature support). - */ - crypto?: Crypto; -}; -/** - * Platform-agnostic PubNub client core. - */ -export declare class PubNubCore = Record> { - /** - * Type of REST API endpoint which reported status. - */ - static OPERATIONS: typeof RequestOperation; - /** - * API call status category. - */ - static CATEGORIES: typeof StatusCategory; - /** - * Exponential retry policy constructor. - */ - static ExponentialRetryPolicy: typeof RetryPolicy.ExponentialRetryPolicy; - /** - * Linear retry policy constructor. - */ - static LinearRetryPolicy: typeof RetryPolicy.LinearRetryPolicy; - /** - * Construct notification payload which will trigger push notification. - * - * @param title - Title which will be shown on notification. - * @param body - Payload which will be sent as part of notification. - * - * @returns Pre-formatted message payload which will trigger push notification. - */ - static notificationPayload(title: string, body: string): NotificationsPayload; - /** - * Generate unique identifier. - * - * @returns Unique identifier. - */ - static generateUUID(): any; - constructor(configuration: ClientInstanceConfiguration); - /** - * PubNub client configuration. - * - * @returns Currently user PubNub client configuration. - */ - get configuration(): ClientConfiguration; - /** - * Current PubNub client configuration. - * - * @returns Currently user PubNub client configuration. - * - * @deprecated Use {@link configuration} getter instead. - */ - get _config(): ClientConfiguration; - /** - * REST API endpoint access authorization key. - * - * It is required to have `authorization key` with required permissions to access REST API - * endpoints when `PAM` enabled for user key set. - */ - get authKey(): string | undefined; - /** - * REST API endpoint access authorization key. - * - * It is required to have `authorization key` with required permissions to access REST API - * endpoints when `PAM` enabled for user key set. - */ - getAuthKey(): string | undefined; - /** - * Change REST API endpoint access authorization key. - * - * @param authKey - New authorization key which should be used with new requests. - */ - setAuthKey(authKey: string): void; - /** - * Get a PubNub client user identifier. - * - * @returns Current PubNub client user identifier. - */ - get userId(): string; - /** - * Change the current PubNub client user identifier. - * - * **Important:** Change won't affect ongoing REST API calls. - * - * @param value - New PubNub client user identifier. - * - * @throws Error empty user identifier has been provided. - */ - set userId(value: string); - /** - * Get a PubNub client user identifier. - * - * @returns Current PubNub client user identifier. - */ - getUserId(): string; - /** - * Change the current PubNub client user identifier. - * - * **Important:** Change won't affect ongoing REST API calls. - * - * @param value - New PubNub client user identifier. - * - * @throws Error empty user identifier has been provided. - */ - setUserId(value: string): void; - /** - * Real-time updates filtering expression. - * - * @returns Filtering expression. - */ - get filterExpression(): string | undefined; - /** - * Real-time updates filtering expression. - * - * @returns Filtering expression. - */ - getFilterExpression(): string | undefined; - /** - * Update real-time updates filtering expression. - * - * @param expression - New expression which should be used or `undefined` to disable filtering. - */ - set filterExpression(expression: string | null | undefined); - /** - * Update real-time updates filtering expression. - * - * @param expression - New expression which should be used or `undefined` to disable filtering. - */ - setFilterExpression(expression: string | null): void; - /** - * Dta encryption / decryption key. - * - * @returns Currently used key for data encryption / decryption. - */ - get cipherKey(): string | undefined; - /** - * Change data encryption / decryption key. - * - * @param key - New key which should be used for data encryption / decryption. - */ - set cipherKey(key: string | undefined); - /** - * Change data encryption / decryption key. - * - * @param key - New key which should be used for data encryption / decryption. - */ - setCipherKey(key: string): void; - /** - * Change heartbeat requests interval. - * - * @param interval - New presence request heartbeat intervals. - */ - set heartbeatInterval(interval: number); - /** - * Change heartbeat requests interval. - * - * @param interval - New presence request heartbeat intervals. - */ - setHeartbeatInterval(interval: number): void; - /** - * Get PubNub SDK version. - * - * @returns Current SDK version. - */ - getVersion(): string; - /** - * Add framework's prefix. - * - * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. - * @param suffix - Suffix with information about framework. - */ - _addPnsdkSuffix(name: string, suffix: string | number): void; - /** - * Get a PubNub client user identifier. - * - * @returns Current PubNub client user identifier. - * - * @deprecated Use the {@link getUserId} or {@link userId} getter instead. - */ - getUUID(): string; - /** - * Change the current PubNub client user identifier. - * - * **Important:** Change won't affect ongoing REST API calls. - * - * @param value - New PubNub client user identifier. - * - * @throws Error empty user identifier has been provided. - * - * @deprecated Use the {@link PubNubCore#setUserId} or {@link PubNubCore#userId} setter instead. - */ - setUUID(value: string): void; - /** - * Custom data encryption method. - * - * @deprecated Instead use {@link cryptoModule} for data encryption. - */ - get customEncrypt(): ((data: string) => string) | undefined; - /** - * Custom data decryption method. - * - * @deprecated Instead use {@link cryptoModule} for data decryption. - */ - get customDecrypt(): ((data: string) => string) | undefined; - /** - * Create a `Channel` entity. - * - * Entity can be used for the interaction with the following API: - * - `subscribe` - * - * @param name - Unique channel name. - * @returns `Channel` entity. - */ - channel(name: string): Channel; - /** - * Create a `ChannelGroup` entity. - * - * Entity can be used for the interaction with the following API: - * - `subscribe` - * - * @param name - Unique channel group name. - * @returns `ChannelGroup` entity. - */ - channelGroup(name: string): ChannelGroup; - /** - * Create a `ChannelMetadata` entity. - * - * Entity can be used for the interaction with the following API: - * - `subscribe` - * - * @param id - Unique channel metadata object identifier. - * @returns `ChannelMetadata` entity. - */ - channelMetadata(id: string): ChannelMetadata; - /** - * Create a `UserMetadata` entity. - * - * Entity can be used for the interaction with the following API: - * - `subscribe` - * - * @param id - Unique user metadata object identifier. - * @returns `UserMetadata` entity. - */ - userMetadata(id: string): UserMetadata; - /** - * Create subscriptions set object. - * - * @param parameters - Subscriptions set configuration parameters. - */ - subscriptionSet(parameters: { - channels?: string[]; - channelGroups?: string[]; - subscriptionOptions?: SubscriptionOptions; - }): SubscriptionSet; - /** - * Schedule request execution. - * - * @param request - REST API request. - * @param callback - Request completion handler callback. - * - * @returns Asynchronous request execution and response parsing result. - */ - private sendRequest; - /** - * Unsubscribe from all channels and groups. - * - * @param [isOffline] - Whether `offline` presence should be notified or not. - */ - destroy(isOffline?: boolean): void; - /** - * Unsubscribe from all channels and groups. - * - * @deprecated Use {@link destroy} method instead. - */ - stop(): void; - /** - * Register real-time events listener. - * - * @param listener - Listener with event callbacks to handle different types of events. - */ - addListener(listener: Listener): void; - /** - * Remove real-time event listener. - * - * @param listener - Event listeners which should be removed. - */ - removeListener(listener: Listener): void; - /** - * Clear all real-time event listeners. - */ - removeAllListeners(): void; - /** - * Publish data to a specific channel. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - publish(parameters: Publish.PublishParameters, callback: ResultCallback): void; - /** - * Publish data to a specific channel. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous publish data response. - */ - publish(parameters: Publish.PublishParameters): Promise; - /** - * Signal data to a specific channel. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - signal(parameters: Signal.SignalParameters, callback: ResultCallback): void; - /** - * Signal data to a specific channel. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous signal data response. - */ - signal(parameters: Signal.SignalParameters): Promise; - /** - * `Fire` a data to a specific channel. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link publish} method instead. - */ - fire(parameters: Publish.PublishParameters, callback: ResultCallback): void; - /** - * `Fire` a data to a specific channel. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous signal data response. - * - * @deprecated Use {@link publish} method instead. - */ - fire(parameters: Publish.PublishParameters): Promise; - /** - * Get list of channels on which PubNub client currently subscribed. - * - * @returns List of active channels. - */ - getSubscribedChannels(): string[]; - /** - * Get list of channel groups on which PubNub client currently subscribed. - * - * @returns List of active channel groups. - */ - getSubscribedChannelGroups(): string[]; - /** - * Subscribe to specified channels and groups real-time events. - * - * @param parameters - Request configuration parameters. - */ - subscribe(parameters: Subscription.SubscribeParameters): void; - /** - * Perform subscribe request. - * - * **Note:** Method passed into managers to let them use it when required. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - private makeSubscribe; - /** - * Unsubscribe from specified channels and groups real-time events. - * - * @param parameters - Request configuration parameters. - */ - unsubscribe(parameters: Presence.PresenceLeaveParameters): void; - /** - * Perform unsubscribe request. - * - * **Note:** Method passed into managers to let them use it when required. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - private makeUnsubscribe; - /** - * Unsubscribe from all channels and groups. - */ - unsubscribeAll(): void; - /** - * Temporarily disconnect from real-time events stream. - */ - disconnect(): void; - /** - * Restore connection to the real-time events stream. - * - * @param parameters - Reconnection catch up configuration. **Note:** available only with - * enabled event engine. - */ - reconnect(parameters?: { - timetoken?: string; - region?: number; - }): void; - /** - * Event engine handshake subscribe. - * - * @param parameters - Request configuration parameters. - */ - private subscribeHandshake; - /** - * Event engine receive messages subscribe. - * - * @param parameters - Request configuration parameters. - */ - private subscribeReceiveMessages; - /** - * Get reactions to a specific message. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - getMessageActions(parameters: MessageAction.GetMessageActionsParameters, callback: ResultCallback): void; - /** - * Get reactions to a specific message. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get reactions response. - */ - getMessageActions(parameters: MessageAction.GetMessageActionsParameters): Promise; - /** - * Add a reaction to a specific message. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - addMessageAction(parameters: MessageAction.AddMessageActionParameters, callback: ResultCallback): void; - /** - * Add a reaction to a specific message. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous add a reaction response. - */ - addMessageAction(parameters: MessageAction.AddMessageActionParameters): Promise; - /** - * Remove a reaction from a specific message. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - removeMessageAction(parameters: MessageAction.RemoveMessageActionParameters, callback: ResultCallback): void; - /** - * Remove a reaction from a specific message. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous remove a reaction response. - */ - removeMessageAction(parameters: MessageAction.RemoveMessageActionParameters): Promise; - /** - * Fetch messages history for channels. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - fetchMessages(parameters: History.FetchMessagesParameters, callback: ResultCallback): void; - /** - * Fetch messages history for channels. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous fetch messages response. - */ - fetchMessages(parameters: History.FetchMessagesParameters): Promise; - /** - * Delete messages from the channel history. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated - */ - deleteMessages(parameters: History.DeleteMessagesParameters, callback: ResultCallback): void; - /** - * Delete messages from the channel history. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous delete messages response. - * - * @deprecated - */ - deleteMessages(parameters: History.DeleteMessagesParameters): Promise; - /** - * Count messages from the channels' history. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - messageCounts(parameters: History.MessageCountParameters, callback: ResultCallback): void; - /** - * Count messages from the channels' history. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous count messages response. - */ - messageCounts(parameters: History.MessageCountParameters): Promise; - /** - * Fetch single channel history. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated - */ - history(parameters: History.GetHistoryParameters, callback: ResultCallback): void; - /** - * Fetch single channel history. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous fetch channel history response. - * - * @deprecated - */ - history(parameters: History.GetHistoryParameters): Promise; - /** - * Get channel's presence information. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - hereNow(parameters: Presence.HereNowParameters, callback: ResultCallback): void; - /** - * Get channel presence information. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get channel's presence response. - */ - hereNow(parameters: Presence.HereNowParameters): Promise; - /** - * Get user's presence information. - * - * Get list of channels to which `uuid` currently subscribed. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - whereNow(parameters: Presence.WhereNowParameters, callback: ResultCallback): void; - /** - * Get user's presence information. - * - * Get list of channels to which `uuid` currently subscribed. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get user's presence response. - */ - whereNow(parameters: Presence.WhereNowParameters): Promise; - /** - * Get associated user's data for channels and groups. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - getState(parameters: Presence.GetPresenceStateParameters, callback: ResultCallback): void; - /** - * Get associated user's data for channels and groups. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get associated user's data response. - */ - getState(parameters: Presence.GetPresenceStateParameters): Promise; - /** - * Set associated user's data for channels and groups. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - setState(parameters: Presence.SetPresenceStateParameters | Presence.SetPresenceStateWithHeartbeatParameters, callback: ResultCallback): void; - /** - * Set associated user's data for channels and groups. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous set associated user's data response. - */ - setState(parameters: Presence.SetPresenceStateParameters | Presence.SetPresenceStateWithHeartbeatParameters): Promise; - /** - * Manual presence management. - * - * @param parameters - Desired presence state for provided list of channels and groups. - */ - presence(parameters: { - connected: boolean; - channels?: string[]; - channelGroups?: string[]; - }): void; - /** - * Announce user presence - * - * @param parameters - Desired presence state for provided list of channels and groups. - * @param callback - Request completion handler callback. - */ - private heartbeat; - /** - * Announce user `join` on specified list of channels and groups. - * - * @param parameters - List of channels and groups where `join` event should be sent. - */ - private join; - /** - * Announce user `leave` on specified list of channels and groups. - * - * @param parameters - List of channels and groups where `leave` event should be sent. - */ - private leave; - /** - * Announce user `leave` on all subscribed channels. - */ - private leaveAll; - /** - * Grant token permission. - * - * Generate access token with requested permissions. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - grantToken(parameters: PAM.GrantTokenParameters, callback: ResultCallback): void; - /** - * Grant token permission. - * - * Generate access token with requested permissions. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous grant token response. - */ - grantToken(parameters: PAM.GrantTokenParameters): Promise; - /** - * Revoke token permission. - * - * @param token - Access token for which permissions should be revoked. - * @param callback - Request completion handler callback. - */ - revokeToken(token: PAM.RevokeParameters, callback: ResultCallback): void; - /** - * Revoke token permission. - * - * @param token - Access token for which permissions should be revoked. - * - * @returns Asynchronous revoke token response. - */ - revokeToken(token: PAM.RevokeParameters): Promise; - /** - * Get current access token. - * - * @returns Previously configured access token using {@link setToken} method. - */ - get token(): string | undefined; - /** - * Get current access token. - * - * @returns Previously configured access token using {@link setToken} method. - */ - getToken(): string | undefined; - /** - * Set current access token. - * - * @param token - New access token which should be used with next REST API endpoint calls. - */ - set token(token: string | undefined); - /** - * Set current access token. - * - * @param token - New access token which should be used with next REST API endpoint calls. - */ - setToken(token: string | undefined): void; - /** - * Parse access token. - * - * Parse token to see what permissions token owner has. - * - * @param token - Token which should be parsed. - * - * @returns Token's permissions information for the resources. - */ - parseToken(token: string): { - version: number; - timestamp: number; - ttl: number; - resources?: Partial>> | undefined; - patterns?: Partial>> | undefined; - authorized_uuid?: string | undefined; - signature: ArrayBuffer; - meta?: Payload | undefined; - } | undefined; - /** - * Grant auth key(s) permission. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link grantToken} and {@link setToken} methods instead. - */ - grant(parameters: PAM.GrantParameters, callback: ResultCallback): void; - /** - * Grant auth key(s) permission. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous grant auth key(s) permissions response. - * - * @deprecated Use {@link grantToken} and {@link setToken} methods instead. - */ - grant(parameters: PAM.GrantParameters): Promise; - /** - * Audit auth key(s) permission. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated - */ - audit(parameters: PAM.AuditParameters, callback: ResultCallback): void; - /** - * Audit auth key(s) permission. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous audit auth key(s) permissions response. - * - * @deprecated - */ - audit(parameters: PAM.AuditParameters): Promise; - /** - * PubNub App Context API group. - */ - get objects(): PubNubObjects; - /** - * Fetch a paginated list of User objects. - * - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. - */ - fetchUsers(callback: ResultCallback>): void; - /** - * Fetch a paginated list of User objects. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. - */ - fetchUsers(parameters: AppContext.GetAllMetadataParameters>, callback: ResultCallback>): void; - /** - * Fetch a paginated list of User objects. - * - * @param [parameters] - Request configuration parameters. - * - * @returns Asynchronous get all User objects response. - * - * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. - */ - fetchUsers(parameters?: AppContext.GetAllMetadataParameters>): Promise>; - /** - * Fetch User object for currently configured PubNub client `uuid`. - * - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. - */ - fetchUser(callback: ResultCallback>): void; - /** - * Fetch User object for currently configured PubNub client `uuid`. - * - * @param parameters - Request configuration parameters. Will fetch User object for currently - * configured PubNub client `uuid` if not set. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. - */ - fetchUser(parameters: AppContext.GetUUIDMetadataParameters, callback: ResultCallback>): void; - /** - * Fetch User object for currently configured PubNub client `uuid`. - * - * @param [parameters] - Request configuration parameters. Will fetch User object for currently - * configured PubNub client `uuid` if not set. - * - * @returns Asynchronous get User object response. - * - * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. - */ - fetchUser(parameters?: AppContext.GetUUIDMetadataParameters): Promise>; - /** - * Create User object. - * - * @param parameters - Request configuration parameters. Will create User object for currently - * configured PubNub client `uuid` if not set. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. - */ - createUser(parameters: AppContext.SetUUIDMetadataParameters, callback: ResultCallback>): void; - /** - * Create User object. - * - * @param parameters - Request configuration parameters. Will create User object for currently - * configured PubNub client `uuid` if not set. - * - * @returns Asynchronous create User object response. - * - * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. - */ - createUser(parameters: AppContext.SetUUIDMetadataParameters): Promise>; - /** - * Update User object. - * - * @param parameters - Request configuration parameters. Will update User object for currently - * configured PubNub client `uuid` if not set. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. - */ - updateUser(parameters: AppContext.SetUUIDMetadataParameters, callback: ResultCallback>): void; - /** - * Update User object. - * - * @param parameters - Request configuration parameters. Will update User object for currently - * configured PubNub client `uuid` if not set. - * - * @returns Asynchronous update User object response. - * - * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. - */ - updateUser(parameters: AppContext.SetUUIDMetadataParameters): Promise>; - /** - * Remove a specific User object. - * - * @param callback - Request completion handler callback. Will remove User object for currently - * configured PubNub client `uuid` if not set. - * - * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. - */ - removeUser(callback: ResultCallback): void; - /** - * Remove a specific User object. - * - * @param parameters - Request configuration parameters. Will remove User object for currently - * configured PubNub client `uuid` if not set. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. - */ - removeUser(parameters: AppContext.RemoveUUIDMetadataParameters, callback: ResultCallback): void; - /** - * Remove a specific User object. - * - * @param [parameters] - Request configuration parameters. Will remove User object for currently - * configured PubNub client `uuid` if not set. - * - * @returns Asynchronous User object remove response. - * - * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. - */ - removeUser(parameters?: AppContext.RemoveUUIDMetadataParameters): Promise; - /** - * Fetch a paginated list of Space objects. - * - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. - */ - fetchSpaces(callback: ResultCallback>): void; - /** - * Fetch a paginated list of Space objects. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. - */ - fetchSpaces(parameters: AppContext.GetAllMetadataParameters>, callback: ResultCallback>): void; - /** - * Fetch a paginated list of Space objects. - * - * @param [parameters] - Request configuration parameters. - * - * @returns Asynchronous get all Space objects response. - * - * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. - */ - fetchSpaces(parameters?: AppContext.GetAllMetadataParameters>): Promise>; - /** - * Fetch a specific Space object. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. - */ - fetchSpace(parameters: AppContext.GetChannelMetadataParameters, callback: ResultCallback>): void; - /** - * Fetch a specific Space object. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get Channel metadata response. - * - * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. - */ - fetchSpace(parameters: AppContext.GetChannelMetadataParameters): Promise>; - /** - * Create specific Space object. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. - */ - createSpace(parameters: AppContext.SetChannelMetadataParameters, callback: ResultCallback>): void; - /** - * Create specific Space object. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous create Space object response. - * - * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. - */ - createSpace(parameters: AppContext.SetChannelMetadataParameters): Promise>; - /** - * Update specific Space object. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. - */ - updateSpace(parameters: AppContext.SetChannelMetadataParameters, callback: ResultCallback>): void; - /** - * Update specific Space object. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous update Space object response. - * - * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. - */ - updateSpace(parameters: AppContext.SetChannelMetadataParameters): Promise>; - /** - * Remove Space object. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. - */ - removeSpace(parameters: AppContext.RemoveChannelMetadataParameters, callback: ResultCallback): void; - /** - * Remove a specific Space object. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous Space object remove response. - * - * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. - */ - removeSpace(parameters: AppContext.RemoveChannelMetadataParameters): Promise; - /** - * Fetch paginated list of specific Space members or specific User memberships. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} - * methods instead. - */ - fetchMemberships(parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters, callback: ResultCallback | AppContext.UserMembersResponse>): void; - /** - * Fetch paginated list of specific Space members or specific User memberships. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get specific Space members or specific User memberships response. - * - * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} - * methods instead. - */ - fetchMemberships(parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters): Promise | AppContext.UserMembersResponse>; - /** - * Add members to specific Space or memberships specific User. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} - * methods instead. - */ - addMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, callback: ResultCallback | AppContext.SetMembersResponse>): void; - /** - * Add members to specific Space or memberships specific User. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous add members to specific Space or memberships specific User response. - * - * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} - * methods instead. - */ - addMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters): Promise | AppContext.SetMembersResponse>; - /** - * Update specific Space members or User memberships. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} - * methods instead. - */ - updateMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, callback: ResultCallback | AppContext.SetMembersResponse>): void; - /** - * Update specific Space members or User memberships. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous update Space members or User memberships response. - * - * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} - * methods instead. - */ - updateMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters): Promise | AppContext.SetMembersResponse>; - /** - * Remove User membership. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - * - * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} - * methods instead - * from `objects` API group.. - */ - removeMemberships(parameters: AppContext.RemoveMembersParameters | AppContext.RemoveMembershipsParameters, callback: ResultCallback | AppContext.RemoveMembershipsResponse>): void; - /** - * Remove User membership. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous memberships modification response. - * - * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} - * methods instead - * from `objects` API group.. - */ - removeMemberships(parameters: AppContext.RemoveMembersParameters | AppContext.RemoveMembershipsParameters): Promise>; - /** - * PubNub Channel Groups API group. - */ - get channelGroups(): PubNubChannelGroups; - /** - * PubNub Push Notifications API group. - */ - get push(): PubNubPushNotifications; - /** - * Share file to a specific channel. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - sendFile(parameters: FileSharing.SendFileParameters, callback: ResultCallback): void; - /** - * Share file to a specific channel. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous file sharing response. - */ - sendFile(parameters: FileSharing.SendFileParameters): Promise; - /** - * Publish file message to a specific channel. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - publishFile(parameters: FileSharing.PublishFileMessageParameters, callback: ResultCallback): void; - /** - * Publish file message to a specific channel. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous publish file message response. - */ - publishFile(parameters: FileSharing.PublishFileMessageParameters): Promise; - /** - * Retrieve list of shared files in specific channel. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - listFiles(parameters: FileSharing.ListFilesParameters, callback: ResultCallback): void; - /** - * Retrieve list of shared files in specific channel. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous shared files list response. - */ - listFiles(parameters: FileSharing.ListFilesParameters): Promise; - /** - * Get file download Url. - * - * @param parameters - Request configuration parameters. - * - * @returns File download Url. - */ - getFileUrl(parameters: FileSharing.FileUrlParameters): FileSharing.FileUrlResponse; - /** - * Download shared file from specific channel. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - downloadFile(parameters: FileSharing.DownloadFileParameters, callback: ResultCallback): void; - /** - * Download shared file from specific channel. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous download shared file response. - */ - downloadFile(parameters: FileSharing.DownloadFileParameters): Promise; - /** - * Delete shared file from specific channel. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - deleteFile(parameters: FileSharing.DeleteFileParameters, callback: ResultCallback): void; - /** - * Delete shared file from specific channel. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous delete shared file response. - */ - deleteFile(parameters: FileSharing.DeleteFileParameters): Promise; - /** - Get current high-precision timetoken. - * - * @param callback - Request completion handler callback. - */ - time(callback: ResultCallback): void; - /** - * Get current high-precision timetoken. - * - * @returns Asynchronous get current timetoken response. - */ - time(): Promise; - /** - * Encrypt data. - * - * @param data - Stringified data which should be encrypted using `CryptoModule`. - * @deprecated - * @param [customCipherKey] - Cipher key which should be used to encrypt data. **Deprecated:** - * use {@link Configuration#cryptoModule|cryptoModule} instead. - * - * @returns Data encryption result as a string. - */ - encrypt(data: string | Payload, customCipherKey?: string): string; - /** - * Decrypt data. - * - * @param data - Stringified data which should be encrypted using `CryptoModule`. - * @param [customCipherKey] - Cipher key which should be used to decrypt data. **Deprecated:** - * use {@link Configuration#cryptoModule|cryptoModule} instead. - * - * @returns Data decryption result as an object. - */ - decrypt(data: string, customCipherKey?: string): Payload | null; - /** - * Encrypt file content. - * - * @param file - File which should be encrypted using `CryptoModule`. - * - * @returns Asynchronous file encryption result. - * - * @throws Error if source file not provided. - * @throws File constructor not provided. - * @throws Crypto module is missing (if non-legacy flow used). - */ - encryptFile(file: PubNubFileInterface): Promise; - /** - * Encrypt file content. - * - * @param key - Cipher key which should be used to encrypt data. - * @param file - File which should be encrypted using legacy cryptography. - * - * @returns Asynchronous file encryption result. - * - * @throws Error if source file not provided. - * @throws File constructor not provided. - * @throws Crypto module is missing (if non-legacy flow used). - */ - encryptFile(key: string, file: PubNubFileInterface): Promise; - /** - * Decrypt file content. - * - * @param file - File which should be decrypted using legacy cryptography. - * - * @returns Asynchronous file decryption result. - * - * @throws Error if source file not provided. - * @throws File constructor not provided. - * @throws Crypto module is missing (if non-legacy flow used). - */ - decryptFile(file: PubNubFileInterface): Promise; - /** - * Decrypt file content. - * - * @param key - Cipher key which should be used to decrypt data. - * @param [file] - File which should be decrypted using legacy cryptography. - * - * @returns Asynchronous file decryption result. - * - * @throws Error if source file not provided. - * @throws File constructor not provided. - * @throws Crypto module is missing (if non-legacy flow used). - */ - decryptFile(key: string | PubNubFileInterface, file?: PubNubFileInterface): Promise; -} -export {}; diff --git a/lib/types/core/pubnub-objects.d.ts b/lib/types/core/pubnub-objects.d.ts deleted file mode 100644 index 75f4f1a7b..000000000 --- a/lib/types/core/pubnub-objects.d.ts +++ /dev/null @@ -1,364 +0,0 @@ -/** - * PubNub Objects API module. - */ -import { ResultCallback, SendRequestFunction } from './types/api'; -import { PrivateClientConfiguration } from './interfaces/configuration'; -import * as AppContext from './types/api/app-context'; -export default class PubNubObjects { - private readonly configuration; - private readonly sendRequest; - /** - * REST API endpoints access credentials. - */ - private readonly keySet; - constructor(configuration: PrivateClientConfiguration, sendRequest: SendRequestFunction); - /** - * Fetch a paginated list of UUID Metadata objects. - * - * @param callback - Request completion handler callback. - */ - getAllUUIDMetadata(callback: ResultCallback>): void; - /** - * Fetch a paginated list of UUID Metadata objects. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - getAllUUIDMetadata(parameters: AppContext.GetAllMetadataParameters>, callback: ResultCallback>): void; - /** - * Fetch a paginated list of UUID Metadata objects. - * - * @param [parameters] - Request configuration parameters. - * - * @returns Asynchronous get all UUID metadata response. - */ - getAllUUIDMetadata(parameters?: AppContext.GetAllMetadataParameters>): Promise>; - /** - * Fetch a paginated list of UUID Metadata objects. - * - * - * @param [parametersOrCallback] - Request configuration parameters or callback from overload. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. - */ - _getAllUUIDMetadata(parametersOrCallback?: AppContext.GetAllMetadataParameters> | ResultCallback>, callback?: ResultCallback>): Promise | void>; - /** - * Fetch UUID Metadata object for currently configured PubNub client `uuid`. - * - * @param callback - Request completion handler callback. - */ - getUUIDMetadata(callback: ResultCallback>): void; - /** - * Fetch a specific UUID Metadata object. - * - * @param parameters - Request configuration parameters. Will fetch UUID metadata object for - * currently configured PubNub client `uuid` if not set. - * @param callback - Request completion handler callback. - */ - getUUIDMetadata(parameters: AppContext.GetUUIDMetadataParameters, callback: ResultCallback>): void; - /** - * Fetch a specific UUID Metadata object. - * - * @param [parameters] - Request configuration parameters. Will fetch UUID Metadata object for - * currently configured PubNub client `uuid` if not set. - * - * @returns Asynchronous get UUID metadata response. - */ - getUUIDMetadata(parameters?: AppContext.GetUUIDMetadataParameters): Promise>; - /** - * Fetch a specific UUID Metadata object. - * - * @param [parametersOrCallback] - Request configuration parameters or callback from overload. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. - */ - _getUUIDMetadata(parametersOrCallback?: AppContext.GetUUIDMetadataParameters | ResultCallback>, callback?: ResultCallback>): Promise | void>; - /** - * Update specific UUID Metadata object. - * - * @param parameters - Request configuration parameters. Will set UUID metadata for currently - * configured PubNub client `uuid` if not set. - * @param callback - Request completion handler callback. - */ - setUUIDMetadata(parameters: AppContext.SetUUIDMetadataParameters, callback: ResultCallback>): void; - /** - * Update specific UUID Metadata object. - * - * @param parameters - Request configuration parameters. Will set UUID metadata for currently - * configured PubNub client `uuid` if not set. - * - * @returns Asynchronous set UUID metadata response. - */ - setUUIDMetadata(parameters: AppContext.SetUUIDMetadataParameters): Promise>; - /** - * Update specific UUID Metadata object. - * - * @param parameters - Request configuration parameters. Will set UUID metadata for currently - * configured PubNub client `uuid` if not set. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous set UUID metadata response or `void` in case if `callback` provided. - */ - _setUUIDMetadata(parameters: AppContext.SetUUIDMetadataParameters, callback?: ResultCallback>): Promise | void>; - /** - * Remove UUID Metadata object for currently configured PubNub client `uuid`. - * - * @param callback - Request completion handler callback. - */ - removeUUIDMetadata(callback: ResultCallback): void; - /** - * Remove a specific UUID Metadata object. - * - * @param parameters - Request configuration parameters. Will remove UUID metadata for currently - * configured PubNub client `uuid` if not set. - * @param callback - Request completion handler callback. - */ - removeUUIDMetadata(parameters: AppContext.RemoveUUIDMetadataParameters, callback: ResultCallback): void; - /** - * Remove a specific UUID Metadata object. - * - * @param [parameters] - Request configuration parameters. Will remove UUID metadata for currently - * configured PubNub client `uuid` if not set. - * - * @returns Asynchronous UUID metadata remove response. - */ - removeUUIDMetadata(parameters?: AppContext.RemoveUUIDMetadataParameters): Promise; - /** - * Remove a specific UUID Metadata object. - * - * @param [parametersOrCallback] - Request configuration parameters or callback from overload. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous UUID metadata remove response or `void` in case if `callback` provided. - */ - _removeUUIDMetadata(parametersOrCallback?: AppContext.RemoveUUIDMetadataParameters | ResultCallback, callback?: ResultCallback): Promise; - /** - * Fetch a paginated list of Channel Metadata objects. - * - * @param callback - Request completion handler callback. - */ - getAllChannelMetadata(callback: ResultCallback>): void; - /** - * Fetch a paginated list of Channel Metadata objects. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - getAllChannelMetadata(parameters: AppContext.GetAllMetadataParameters>, callback: ResultCallback>): void; - /** - * Fetch a paginated list of Channel Metadata objects. - * - * @param [parameters] - Request configuration parameters. - * - * @returns Asynchronous get all Channel metadata response. - */ - getAllChannelMetadata(parameters?: AppContext.GetAllMetadataParameters>): Promise>; - /** - * Fetch a paginated list of Channel Metadata objects. - * - * @param [parametersOrCallback] - Request configuration parameters or callback from overload. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous get all Channel metadata response or `void` in case if `callback` - * provided. - */ - _getAllChannelMetadata(parametersOrCallback?: AppContext.GetAllMetadataParameters> | ResultCallback>, callback?: ResultCallback>): Promise | void>; - /** - * Fetch Channel Metadata object. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - getChannelMetadata(parameters: AppContext.GetChannelMetadataParameters, callback: ResultCallback>): void; - /** - * Fetch a specific Channel Metadata object. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get Channel metadata response. - */ - getChannelMetadata(parameters: AppContext.GetChannelMetadataParameters): Promise>; - /** - * Fetch Channel Metadata object. - * - * @param parameters - Request configuration parameters. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous get Channel metadata response or `void` in case if `callback` provided. - */ - _getChannelMetadata(parameters: AppContext.GetChannelMetadataParameters, callback?: ResultCallback>): Promise | void>; - /** - * Update specific Channel Metadata object. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - setChannelMetadata(parameters: AppContext.SetChannelMetadataParameters, callback: ResultCallback>): void; - /** - * Update specific Channel Metadata object. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous set Channel metadata response. - */ - setChannelMetadata(parameters: AppContext.SetChannelMetadataParameters): Promise>; - /** - * Update specific Channel Metadata object. - * - * @param parameters - Request configuration parameters. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous set Channel metadata response or `void` in case if `callback` provided. - */ - _setChannelMetadata(parameters: AppContext.SetChannelMetadataParameters, callback?: ResultCallback>): Promise | void>; - /** - * Remove Channel Metadata object. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - removeChannelMetadata(parameters: AppContext.RemoveChannelMetadataParameters, callback: ResultCallback): void; - /** - * Remove a specific Channel Metadata object. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous Channel metadata remove response. - */ - removeChannelMetadata(parameters: AppContext.RemoveChannelMetadataParameters): Promise; - /** - * Remove a specific Channel Metadata object. - * - * @param parameters - Request configuration parameters. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous Channel metadata remove response or `void` in case if `callback` - * provided. - */ - _removeChannelMetadata(parameters: AppContext.RemoveChannelMetadataParameters, callback?: ResultCallback): Promise; - /** - * Fetch a paginated list of Channel Member objects. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - getChannelMembers(parameters: AppContext.GetMembersParameters, callback: ResultCallback>): void; - /** - * Fetch a paginated list of Channel Member objects. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get Channel Members response. - */ - getChannelMembers(parameters: AppContext.GetMembersParameters): Promise>; - /** - * Update specific Channel Members list. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - setChannelMembers(parameters: AppContext.SetChannelMembersParameters, callback: ResultCallback>): void; - /** - * Update specific Channel Members list. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous update Channel Members list response. - */ - setChannelMembers(parameters: AppContext.SetChannelMembersParameters): Promise>; - /** - * Remove Members from the Channel. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - removeChannelMembers(parameters: AppContext.RemoveMembersParameters, callback: ResultCallback>): void; - /** - * Remove Members from the Channel. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous Channel Members remove response. - */ - removeChannelMembers(parameters: AppContext.RemoveMembersParameters): Promise>; - /** - * Fetch a specific UUID Memberships list for currently configured PubNub client `uuid`. - * - * @param callback - Request completion handler callback. - * - * @returns Asynchronous get UUID Memberships list response or `void` in case if `callback` - * provided. - */ - getMemberships(callback: ResultCallback>): void; - /** - * Fetch a specific UUID Memberships list. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - getMemberships(parameters: AppContext.GetMembershipsParameters, callback: ResultCallback>): void; - /** - * Fetch a specific UUID Memberships list. - * - * @param [parameters] - Request configuration parameters. Will fetch UUID Memberships list for - * currently configured PubNub client `uuid` if not set. - * - * @returns Asynchronous get UUID Memberships list response. - */ - getMemberships(parameters?: AppContext.GetMembershipsParameters): Promise>; - /** - * Update specific UUID Memberships list. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - setMemberships(parameters: AppContext.SetMembershipsParameters, callback: ResultCallback>): void; - /** - * Update specific UUID Memberships list. - * - * @param parameters - Request configuration parameters or callback from overload. - * - * @returns Asynchronous update UUID Memberships list response. - */ - setMemberships(parameters: AppContext.SetMembershipsParameters): Promise>; - /** - * Remove a specific UUID Memberships. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - removeMemberships(parameters: AppContext.RemoveMembershipsParameters, callback: ResultCallback>): void; - /** - * Remove a specific UUID Memberships. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous UUID Memberships remove response. - */ - removeMemberships(parameters: AppContext.RemoveMembershipsParameters): Promise>; - /** - * Fetch paginated list of specific Space members or specific User memberships. - * - * @param parameters - Request configuration parameters. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous get specific Space members or specific User memberships response. - * - * @deprecated Use {@link PubNubObjects#getChannelMembers} or {@link PubNubObjects#getMemberships} methods instead. - */ - fetchMemberships(parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters, callback?: ResultCallback | AppContext.UserMembersResponse>): Promise | AppContext.UserMembersResponse | void>; - /** - * Add members to specific Space or memberships specific User. - * - * @param parameters - Request configuration parameters. - * @param [callback] - Request completion handler callback. - * - * @returns Asynchronous add members to specific Space or memberships specific User response or - * `void` in case if `callback` provided. - * - * @deprecated Use {@link PubNubObjects#setChannelMembers} or {@link PubNubObjects#setMemberships} methods instead. - */ - addMemberships(parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, callback?: ResultCallback | AppContext.SetMembersResponse>): Promise | AppContext.SetMembersResponse | void>; -} diff --git a/lib/types/core/pubnub-push.d.ts b/lib/types/core/pubnub-push.d.ts deleted file mode 100644 index 33d8c02ea..000000000 --- a/lib/types/core/pubnub-push.d.ts +++ /dev/null @@ -1,64 +0,0 @@ -/** - * PubNub Push Notifications API module. - */ -import { KeySet, ResultCallback, SendRequestFunction, StatusCallback } from './types/api'; -import * as Push from './types/api/push'; -export default class PubNubPushNotifications { - private readonly keySet; - private readonly sendRequest; - constructor(keySet: KeySet, sendRequest: SendRequestFunction); - /** - * Fetch device's push notification enabled channels. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - listChannels(parameters: Push.ListDeviceChannelsParameters, callback: ResultCallback): void; - /** - * Fetch device's push notification enabled channels. - * - * @param parameters - Request configuration parameters. - * - * @returns Asynchronous get device channels response. - */ - listChannels(parameters: Push.ListDeviceChannelsParameters): Promise; - /** - * Enable push notifications on channels for device. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - addChannels(parameters: Push.ManageDeviceChannelsParameters, callback: StatusCallback): void; - /** - * Enable push notifications on channels for device. - * - * @param parameters - Request configuration parameters. - */ - addChannels(parameters: Push.ManageDeviceChannelsParameters): Promise; - /** - * Disable push notifications on channels for device. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - removeChannels(parameters: Push.ManageDeviceChannelsParameters, callback: StatusCallback): void; - /** - * Disable push notifications on channels for device. - * - * @param parameters - Request configuration parameters. - */ - removeChannels(parameters: Push.ManageDeviceChannelsParameters): Promise; - /** - * Disable push notifications for device. - * - * @param parameters - Request configuration parameters. - * @param callback - Request completion handler callback. - */ - deleteDevice(parameters: Push.RemoveDeviceParameters, callback: StatusCallback): void; - /** - * Disable push notifications for device. - * - * @param parameters - Request configuration parameters. - */ - deleteDevice(parameters: Push.RemoveDeviceParameters): Promise; -} diff --git a/lib/types/core/types/api/access-manager.d.ts b/lib/types/core/types/api/access-manager.d.ts deleted file mode 100644 index bf85bda51..000000000 --- a/lib/types/core/types/api/access-manager.d.ts +++ /dev/null @@ -1,464 +0,0 @@ -/** - * Metadata which will be associated with access token. - */ -export type Metadata = Record; -/** - * Channel-specific token permissions. - */ -export type ChannelTokenPermissions = { - /** - * Whether `read` operations are permitted for corresponding level or not. - */ - read?: boolean; - /** - * Whether `write` operations are permitted for corresponding level or not. - */ - write?: boolean; - /** - * Whether `get` operations are permitted for corresponding level or not. - */ - get?: boolean; - /** - * Whether `manage` operations are permitted for corresponding level or not. - */ - manage?: boolean; - /** - * Whether `update` operations are permitted for corresponding level or not. - */ - update?: boolean; - /** - * Whether `join` operations are permitted for corresponding level or not. - */ - join?: boolean; - /** - * Whether `delete` operations are permitted for corresponding level or not. - */ - delete?: boolean; -}; -/** - * Space-specific token permissions. - */ -type SpaceTokenPermissions = ChannelTokenPermissions; -/** - * Channel group-specific token permissions. - */ -export type ChannelGroupTokenPermissions = { - /** - * Whether `read` operations are permitted for corresponding level or not. - */ - read?: boolean; - /** - * Whether `manage` operations are permitted for corresponding level or not. - */ - manage?: boolean; -}; -/** - * Uuid-specific token permissions. - */ -export type UuidTokenPermissions = { - /** - * Whether `get` operations are permitted for corresponding level or not. - */ - get?: boolean; - /** - * Whether `update` operations are permitted for corresponding level or not. - */ - update?: boolean; - /** - * Whether `delete` operations are permitted for corresponding level or not. - */ - delete?: boolean; -}; -/** - * User-specific token permissions. - */ -type UserTokenPermissions = UuidTokenPermissions; -/** - * Generate access token with permissions. - * - * Generate time-limited access token with required permissions for App Context objects. - */ -export type ObjectsGrantTokenParameters = { - /** - * Total number of minutes for which the token is valid. - * - * The minimum allowed value is `1`. - * The maximum is `43,200` minutes (`30` days). - */ - ttl: number; - /** - * Object containing resource permissions. - */ - resources?: { - /** - * Object containing `spaces` metadata permissions. - */ - spaces?: Record; - /** - * Object containing `users` permissions. - */ - users?: Record; - }; - /** - * Object containing permissions to multiple resources specified by a RegEx pattern. - */ - patterns?: { - /** - * Object containing `spaces` metadata permissions. - */ - spaces?: Record; - /** - * Object containing `users` permissions. - */ - users?: Record; - }; - /** - * Extra metadata to be published with the request. - * - * **Important:** Values must be scalar only; `arrays` or `objects` aren't supported. - */ - meta?: Metadata; - /** - * Single `userId` which is authorized to use the token to make API requests to PubNub. - */ - authorizedUserId?: string; -}; -/** - * Generate token with permissions. - * - * Generate time-limited access token with required permissions for resources. - */ -export type GrantTokenParameters = { - /** - * Total number of minutes for which the token is valid. - * - * The minimum allowed value is `1`. - * The maximum is `43,200` minutes (`30` days). - */ - ttl: number; - /** - * Object containing resource permissions. - */ - resources?: { - /** - * Object containing `uuid` metadata permissions. - */ - uuids?: Record; - /** - * Object containing `channel` permissions. - */ - channels?: Record; - /** - * Object containing `channel group` permissions. - */ - groups?: Record; - }; - /** - * Object containing permissions to multiple resources specified by a RegEx pattern. - */ - patterns?: { - /** - * Object containing `uuid` metadata permissions to apply to all `uuids` matching the RegEx - * pattern. - */ - uuids?: Record; - /** - * Object containing `channel` permissions to apply to all `channels` matching the RegEx - * pattern. - */ - channels?: Record; - /** - * Object containing `channel group` permissions to apply to all `channel groups` matching the - * RegEx pattern. - */ - groups?: Record; - }; - /** - * Extra metadata to be published with the request. - * - * **Important:** Values must be scalar only; `arrays` or `objects` aren't supported. - */ - meta?: Metadata; - /** - * Single `uuid` which is authorized to use the token to make API requests to PubNub. - */ - authorized_uuid?: string; -}; -/** - * Response with generated access token. - */ -export type GrantTokenResponse = string; -/** - * Access token for which permissions should be revoked. - */ -export type RevokeParameters = string; -/** - * Response with revoked access token. - */ -export type RevokeTokenResponse = Record; -/** - * Channel-specific permissions. - * - * Permissions include objects to the App Context Channel object as well. - */ -type ChannelPermissions = { - /** - * Whether `read` operations are permitted for corresponding level or not. - */ - r?: 0 | 1; - /** - * Whether `write` operations are permitted for corresponding level or not. - */ - w?: 0 | 1; - /** - * Whether `delete` operations are permitted for corresponding level or not. - */ - d?: 0 | 1; - /** - * Whether `get` operations are permitted for corresponding level or not. - */ - g?: 0 | 1; - /** - * Whether `update` operations are permitted for corresponding level or not. - */ - u?: 0 | 1; - /** - * Whether `manage` operations are permitted for corresponding level or not. - */ - m?: 0 | 1; - /** - * Whether `join` operations are permitted for corresponding level or not. - */ - j?: 0 | 1; - /** - * Duration for which permissions has been granted. - */ - ttl?: number; -}; -/** - * Channel group-specific permissions. - */ -type ChannelGroupPermissions = { - /** - * Whether `read` operations are permitted for corresponding level or not. - */ - r?: 0 | 1; - /** - * Whether `manage` operations are permitted for corresponding level or not. - */ - m?: 0 | 1; - /** - * Duration for which permissions has been granted. - */ - ttl?: number; -}; -/** - * App Context User-specific permissions. - */ -type UserPermissions = { - /** - * Whether `get` operations are permitted for corresponding level or not. - */ - g?: 0 | 1; - /** - * Whether `update` operations are permitted for corresponding level or not. - */ - u?: 0 | 1; - /** - * Whether `delete` operations are permitted for corresponding level or not. - */ - d?: 0 | 1; - /** - * Duration for which permissions has been granted. - */ - ttl?: number; -}; -/** - * Common permissions audit response content. - */ -type BaseAuditResponse = { - /** - * Permissions level. - */ - level: Level; - /** - * Subscription key at which permissions has been granted. - */ - subscribe_key: string; - /** - * Duration for which permissions has been granted. - */ - ttl?: number; -}; -/** - * Auth keys permissions for specified `level`. - */ -type AuthKeysPermissions = { - /** - * Auth keys-based permissions for specified `level` permission. - */ - auths: Record; -}; -/** - * Single channel permissions audit result. - */ -type ChannelPermissionsResponse = BaseAuditResponse<'channel+auth'> & { - /** - * Name of channel for which permissions audited. - */ - channel: string; -} & AuthKeysPermissions; -/** - * Multiple channels permissions audit result. - */ -type ChannelsPermissionsResponse = BaseAuditResponse<'channel'> & { - /** - * Per-channel permissions. - */ - channels: Record>; -}; -/** - * Single channel group permissions result. - */ -type ChannelGroupPermissionsResponse = BaseAuditResponse<'channel-group+auth'> & { - /** - * Name of channel group for which permissions audited. - */ - 'channel-group': string; -} & AuthKeysPermissions; -/** - * Multiple channel groups permissions audit result. - */ -type ChannelGroupsPermissionsResponse = BaseAuditResponse<'channel'> & { - /** - * Per-channel group permissions. - */ - 'channel-groups': Record>; -}; -/** - * App Context User permissions audit result. - */ -type UserPermissionsResponse = BaseAuditResponse<'user'> & { - /** - * Name of channel for which `user` permissions audited. - */ - channel: string; -} & AuthKeysPermissions; -/** - * Global sub-key level permissions audit result. - */ -type SubKeyPermissionsResponse = BaseAuditResponse<'subkey'> & { - /** - * Per-channel permissions. - */ - channels: Record>; - /** - * Per-channel group permissions. - */ - 'channel-groups': Record>; - /** - * Per-object permissions. - */ - objects: Record>; -}; -/** - * Response with permission information. - */ -export type PermissionsResponse = ChannelPermissionsResponse | ChannelsPermissionsResponse | ChannelGroupPermissionsResponse | ChannelGroupsPermissionsResponse | UserPermissionsResponse | SubKeyPermissionsResponse; -/** - * Audit permissions for provided auth keys / global permissions. - * - * Audit permissions on specific channel and / or channel group for the set of auth keys. - */ -export type AuditParameters = { - /** - * Name of channel for which channel-based permissions should be checked for {@link authKeys}. - */ - channel?: string; - /** - * Name of channel group for which channel group-based permissions should be checked for {@link authKeys}. - */ - channelGroup?: string; - /** - * List of auth keys for which permissions should be checked. - * - * Leave this empty to check channel / group -based permissions or global permissions. - * - * @default `[]` - */ - authKeys?: string[]; -}; -/** - * Grant permissions for provided auth keys / global permissions. - * - * Grant permissions on specific channel and / or channel group for the set of auth keys. - */ -export type GrantParameters = { - /** - * List of channels for which permissions should be granted. - */ - channels?: string[]; - /** - * List of channel groups for which permissions should be granted. - */ - channelGroups?: string[]; - /** - * List of App Context UUID for which permissions should be granted. - */ - uuids?: string[]; - /** - * List of auth keys for which permissions should be granted on specified objects. - * - * Leave this empty to grant channel / group -based permissions or global permissions. - */ - authKeys?: string[]; - /** - * Whether `read` operations are permitted for corresponding level or not. - * - * @default `false` - */ - read?: boolean; - /** - * Whether `write` operations are permitted for corresponding level or not. - * - * @default `false` - */ - write?: boolean; - /** - * Whether `delete` operations are permitted for corresponding level or not. - * - * @default `false` - */ - delete?: boolean; - /** - * Whether `get` operations are permitted for corresponding level or not. - * - * @default `false` - */ - get?: boolean; - /** - * Whether `update` operations are permitted for corresponding level or not. - * - * @default `false` - */ - update?: boolean; - /** - * Whether `manage` operations are permitted for corresponding level or not. - * - * @default `false` - */ - manage?: boolean; - /** - * Whether `join` operations are permitted for corresponding level or not. - * - * @default `false` - */ - join?: boolean; - /** - * For how long permissions should be effective (in minutes). - * - * @default `1440` - */ - ttl?: number; -}; -export {}; diff --git a/lib/types/core/types/api/app-context.d.ts b/lib/types/core/types/api/app-context.d.ts deleted file mode 100644 index 2017fdcf7..000000000 --- a/lib/types/core/types/api/app-context.d.ts +++ /dev/null @@ -1,875 +0,0 @@ -/** - * Partial nullability helper type. - */ -type PartialNullable = { - [P in keyof T]?: T[P] | null; -}; -/** - * Custom data which should be associated with metadata objects or their relation. - */ -export type CustomData = { - [key: string]: string | number | boolean | null; -}; -/** - * Type provides shape of App Context parameters which is common to the all objects types to - * be updated. - */ -type ObjectParameters = { - custom?: Custom; -}; -/** - * Type provides shape of App Context object which is common to the all objects types received - * from the PubNub service. - */ -export type ObjectData = { - /** - * Unique App Context object identifier. - * - * **Important:** For channel it is different from the channel metadata object name. - */ - id: string; - /** - * Last date and time when App Context object has been updated. - * - * String built from date using ISO 8601. - */ - updated: string; - /** - * App Context version hash. - */ - eTag: string; - /** - * Additional data associated with App Context object. - * - * **Important:** Values must be scalars; only arrays or objects are supported. - * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|App Context - * filtering language} doesn’t support filtering by custom properties. - */ - custom?: Custom | null; -}; -/** - * Type provides shape of object which let establish relation between metadata objects. - */ -type ObjectsRelation = { - /** - * App Context object unique identifier. - */ - id: string; - /** - * App Context objects relation status. - */ - status?: string; - /** - * Additional data associated with App Context object relation (membership or members). - * - * **Important:** Values must be scalars; only arrays or objects are supported. - * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|App Context - * filtering language} doesn’t support filtering by custom properties. - */ - custom?: Custom; -}; -/** - * Response page cursor. - */ -type Page = { - /** - * Random string returned from the server, indicating a specific position in a data set. - * - * Used for forward pagination, it fetches the next page, allowing you to continue from where - * you left off. - */ - next?: string; - /** - * Random string returned from the server, indicating a specific position in a data set. - * - * Used for backward pagination, it fetches the previous page, enabling access to earlier - * data. - * - * **Important:** Ignored if the `next` parameter is supplied. - */ - prev?: string; -}; -/** - * Metadata objects include options. - * - * Allows to configure what additional information should be included into service response. - */ -type IncludeOptions = { - /** - * Whether to include total number of App Context objects in the response. - * - * @default `false` - */ - totalCount?: boolean; - /** - * Whether to include App Context object `custom` field in the response. - * - * @default `false` - */ - customFields?: boolean; -}; -/** - * Membership objects include options. - * - * Allows to configure what additional information should be included into service response. - */ -type MembershipsIncludeOptions = IncludeOptions & { - /** - * Whether to include all {@link ChannelMetadata} fields in the response. - * - * @default `false` - */ - channelFields?: boolean; - /** - * Whether to include {@link ChannelMetadata} `custom` field in the response. - * - * @default `false` - */ - customChannelFields?: boolean; - /** - * Whether to include the membership's status field in the response. - * - * @default `false` - */ - statusField?: boolean; - /** - * Whether to include the channel's status field in the response. - * - * @default `false` - */ - channelStatusField?: boolean; - /** - * Whether to include channel's type fields in the response. - * - * @default `false` - */ - channelTypeField?: boolean; -}; -/** - * Members objects include options. - * - * Allows to configure what additional information should be included into service response. - */ -type MembersIncludeOptions = IncludeOptions & { - /** - * Whether to include all {@link UUIMetadata} fields in the response. - * - * @default `false` - */ - UUIDFields?: boolean; - /** - * Whether to include {@link UUIMetadata} `custom` field in the response. - * - * @default `false` - */ - customUUIDFields?: boolean; - /** - * Whether to include the members's status field in the response. - * - * @default `false` - */ - statusField?: boolean; - /** - * Whether to include the user's status field in the response. - * - * @default `false` - */ - UUIDStatusField?: boolean; - /** - * Whether to include user's type fields in the response. - * - * @default `false` - */ - UUIDTypeField?: boolean; -}; -/** - * Type provides shape of App Context parameters which is common to the all objects types to - * fetch them by pages. - */ -type PagedRequestParameters = { - /** - * Fields which can be additionally included into response. - */ - include?: Include; - /** - * Expression used to filter the results. - * - * Only objects whose properties satisfy the given expression are returned. The filter language is - * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|defined here}. - */ - filter?: string; - /** - * Fetched App Context objects sorting options. - */ - sort?: Sort; - /** - * Number of objects to return in response. - * - * **Important:** Maximum for this API is `100` objects per-response. - * - * @default `100` - */ - limit?: number; - /** - * Response pagination configuration. - */ - page?: Page; -}; -/** - * Type provides shape of App Context object fetch response which is common to the all objects - * types received from the PubNub service. - */ -type ObjectResponse = { - /** - * App Context objects list fetch result status code. - */ - status: number; - /** - * Received App Context object information. - */ - data: ObjectType; -}; -/** - * Type provides shape of App Context objects fetch response which is common to the all - * objects types received from the PubNub service. - */ -type PagedResponse = ObjectResponse & { - /** - * Total number of App Context objects in the response. - */ - totalCount?: number; - /** - * Random string returned from the server, indicating a specific position in a data set. - * - * Used for forward pagination, it fetches the next page, allowing you to continue from where - * you left off. - */ - next?: string; - /** - * Random string returned from the server, indicating a specific position in a data set. - * - * Used for backward pagination, it fetches the previous page, enabling access to earlier - * data. - * - * **Important:** Ignored if the `next` parameter is supplied. - */ - prev?: string; -}; -/** - * Key-value pair of a property to sort by, and a sort direction. - */ -type MetadataSortingOptions = keyof Omit | ({ - [K in keyof Omit]?: 'asc' | 'desc' | null; -} & { - [key: `custom.${string}`]: 'asc' | 'desc' | null; -}); -/** - * Key-value pair of a property to sort by, and a sort direction. - */ -type MembershipsSortingOptions = 'channel.id' | 'channel.name' | 'channel.description' | 'channel.updated' | 'space.id' | 'space.name' | 'space.description' | 'space.updated' | 'updated' | { - /** - * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - */ - 'channel.id'?: 'asc' | 'desc' | null; - /** - * Sort results by channel's `name` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - */ - 'channel.name'?: 'asc' | 'desc' | null; - /** - * Sort results by channel's `description` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - */ - 'channel.description'?: 'asc' | 'desc' | null; - /** - * Sort results by channel's `update` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - */ - 'channel.updated'?: 'asc' | 'desc' | null; - /** - * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - * - * @deprecated Use `channel.id` instead. - */ - 'space.id'?: 'asc' | 'desc' | null; - /** - * Sort results by channel's `name` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - * - * @deprecated Use `channel.name` instead. - */ - 'space.name'?: 'asc' | 'desc' | null; - /** - * Sort results by channel's `description` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - * - * @deprecated Use `channel.name` instead. - */ - 'space.description'?: 'asc' | 'desc' | null; - /** - * Sort results by channel's `update` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - * - * @deprecated Use `channel.updated` instead. - */ - 'space.updated'?: 'asc' | 'desc' | null; - /** - * Sort results by `updated` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - */ - updated?: 'asc' | 'desc' | null; -}; -/** - * Key-value pair of a property to sort by, and a sort direction. - */ -type MembersSortingOptions = 'uuid.id' | 'uuid.name' | 'uuid.updated' | 'user.id' | 'user.name' | 'user.updated' | 'updated' | { - /** - * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - */ - 'uuid.id'?: 'asc' | 'desc' | null; - /** - * Sort results by user's `name` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - */ - 'uuid.name'?: 'asc' | 'desc' | null; - /** - * Sort results by user's `update` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - */ - 'uuid.updated'?: 'asc' | 'desc' | null; - /** - * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - * - * @deprecated Use `uuid.id` instead. - */ - 'user.id'?: 'asc' | 'desc' | null; - /** - * Sort results by user's `name` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - * - * @deprecated Use `uuid.name` instead. - */ - 'user.name'?: 'asc' | 'desc' | null; - /** - * Sort results by user's `update` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - * - * @deprecated Use `uuid.updated` instead. - */ - 'user.updated'?: 'asc' | 'desc' | null; - /** - * Sort results by `updated` in ascending (`asc`) or descending (`desc`) order. - * - * Specify `null` for default sorting direction (ascending). - */ - updated?: 'asc' | 'desc' | null; -}; -/** - * Fetch All UUID or Channel Metadata request parameters. - */ -export type GetAllMetadataParameters = PagedRequestParameters>; -/** - * Type which describes own UUID metadata object fields. - */ -type UUIDMetadataFields = { - /** - * Display name for the user. - */ - name?: string; - /** - * The user's email address. - */ - email?: string; - /** - * User's identifier in an external system. - */ - externalId?: string; - /** - * The URL of the user's profile picture. - */ - profileUrl?: string; - /** - * User's object type information. - */ - type?: string; - /** - * User's object status. - */ - status?: string; -}; -/** - * Updated UUID metadata object. - * - * Type represents updated UUID metadata object which will be pushed to the PubNub service. - */ -type UUIDMetadata = ObjectParameters & Partial; -/** - * Received UUID metadata object. - * - * Type represents UUID metadata retrieved from the PubNub service. - */ -export type UUIDMetadataObject = ObjectData & PartialNullable; -/** - * Response with fetched page of UUID metadata objects. - */ -export type GetAllUUIDMetadataResponse = PagedResponse>; -/** - * Fetch UUID Metadata request parameters. - */ -export type GetUUIDMetadataParameters = { - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `uuid`. - */ - uuid?: string; - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `userId`. - * - * @deprecated Use `getUUIDMetadata()` method instead. - */ - userId?: string; - /** - * Fields which can be additionally included into response. - */ - include?: Omit; -}; -/** - * Response with requested UUID metadata object. - */ -export type GetUUIDMetadataResponse = ObjectResponse>; -/** - * Update UUID Metadata request parameters. - */ -export type SetUUIDMetadataParameters = { - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `uuid`. - */ - uuid?: string; - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `userId`. - * - * @deprecated Use `setUUIDMetadata()` method instead. - */ - userId?: string; - /** - * Metadata, which should be associated with UUID. - */ - data: UUIDMetadata; - /** - * Fields which can be additionally included into response. - */ - include?: Omit; -}; -/** - * Response with result of the UUID metadata object update. - */ -export type SetUUIDMetadataResponse = ObjectResponse>; -/** - * Remove UUID Metadata request parameters. - */ -export type RemoveUUIDMetadataParameters = { - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `uuid`. - */ - uuid?: string; - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `userId`. - * - * @deprecated Use `removeUUIDMetadata()` method instead. - */ - userId?: string; -}; -/** - * Response with result of the UUID metadata removal. - */ -export type RemoveUUIDMetadataResponse = ObjectResponse>; -/** - * Type which describes own Channel metadata object fields. - */ -type ChannelMetadataFields = { - /** - * Name of a channel. - */ - name?: string; - /** - * Description of a channel. - */ - description?: string; - /** - * Channel's object type information. - */ - type?: string; - /** - * Channel's object status. - */ - status?: string; -}; -/** - * Updated channel metadata object. - * - * Type represents updated channel metadata object which will be pushed to the PubNub service. - */ -type ChannelMetadata = ObjectParameters & Partial; -/** - * Received channel metadata object. - * - * Type represents chanel metadata retrieved from the PubNub service. - */ -export type ChannelMetadataObject = ObjectData & PartialNullable; -/** - * Response with fetched page of channel metadata objects. - */ -export type GetAllChannelMetadataResponse = PagedResponse>; -/** - * Fetch Channel Metadata request parameters. - */ -export type GetChannelMetadataParameters = { - /** - * Channel name. - */ - channel: string; - /** - * Space identifier. - * - * @deprecated Use `getChannelMetadata()` method instead. - */ - spaceId?: string; - /** - * Fields which can be additionally included into response. - */ - include?: Omit; -}; -/** - * Response with requested channel metadata object. - */ -export type GetChannelMetadataResponse = ObjectResponse>; -/** - * Update Channel Metadata request parameters. - */ -export type SetChannelMetadataParameters = { - /** - * Channel name. - */ - channel: string; - /** - * Space identifier. - * - * @deprecated Use `setChannelMetadata()` method instead. - */ - spaceId?: string; - /** - * Metadata, which should be associated with UUID. - */ - data: ChannelMetadata; - /** - * Fields which can be additionally included into response. - */ - include?: Omit; -}; -/** - * Response with result of the channel metadata object update. - */ -export type SetChannelMetadataResponse = ObjectResponse>; -/** - * Remove Channel Metadata request parameters. - */ -export type RemoveChannelMetadataParameters = { - /** - * Channel name. - */ - channel: string; - /** - * Space identifier. - * - * @deprecated Use `removeChannelMetadata()` method instead. - */ - spaceId?: string; -}; -/** - * Response with result of the channel metadata removal. - */ -export type RemoveChannelMetadataResponse = ObjectResponse>; -/** - * Related channel metadata object. - * - * Type represents chanel metadata which has been used to create membership relation with UUID. - */ -type MembershipsObject = Omit, 'id'> & { - channel: ChannelMetadataObject | { - id: string; - }; -}; -/** - * Response with fetched page of UUID membership objects. - */ -type MembershipsResponse = PagedResponse>; -/** - * Fetch Memberships request parameters. - */ -export type GetMembershipsParameters = PagedRequestParameters & { - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `uuid`. - */ - uuid?: string; - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `uuidId`. - * - * @deprecated Use `uuid` field instead. - */ - userId?: string; -}; -/** - * Response with requested channel memberships information. - */ -export type GetMembershipsResponse = MembershipsResponse; -/** - * Update Memberships request parameters. - */ -export type SetMembershipsParameters = PagedRequestParameters, MembershipsSortingOptions> & { - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `uuid`. - */ - uuid?: string; - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `userId`. - * - * @deprecated Use `uuid` field instead. - */ - userId?: string; - /** - * List of channels with which UUID membership should be established. - */ - channels: Array>; - /** - * List of channels with which UUID membership should be established. - * - * @deprecated Use `channels` field instead. - */ - spaces?: Array, 'id'> & { - /** - * Unique Space object identifier. - */ - spaceId: string; - })>; -}; -/** - * Response with requested channel memberships information change. - */ -export type SetMembershipsResponse = MembershipsResponse; -/** - * Remove Memberships request parameters. - */ -export type RemoveMembershipsParameters = PagedRequestParameters & { - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `uuid`. - */ - uuid?: string; - /** - * Unique user identifier. - * - * **Important:** If not supplied then current user's uuid is used. - * - * @default Current `userId`. - * - * @deprecated Use {@link uuid} field instead. - */ - userId?: string; - /** - * List of channels for which membership which UUID should be removed. - */ - channels: string[]; - /** - * List of space names for which membership which UUID should be removed. - * - * @deprecated Use {@link channels} field instead. - */ - spaceIds?: string[]; -}; -/** - * Response with remaining memberships. - */ -export type RemoveMembershipsResponse = MembershipsResponse; -/** - * Related UUID metadata object. - * - * Type represents UUID metadata which has been used to when added members to the channel. - */ -type MembersObject = Omit, 'id'> & { - uuid: UUIDMetadataObject | { - id: string; - }; -}; -/** - * Response with fetched page of channel member objects. - */ -type MembersResponse = PagedResponse>; -/** - * Fetch Members request parameters. - */ -export type GetMembersParameters = PagedRequestParameters & { - /** - * Channel name. - */ - channel: string; - /** - * Space identifier. - * - * @deprecated Use `channel` field instead. - */ - spaceId?: string; -}; -/** - * Response with requested channel memberships information. - */ -export type GetMembersResponse = MembersResponse; -/** - * Update Members request parameters. - */ -export type SetChannelMembersParameters = PagedRequestParameters, MembersSortingOptions> & { - /** - * Channel name. - */ - channel: string; - /** - * Space identifier. - * - * @deprecated Use `channel` field instead. - */ - spaceId?: string; - /** - * List of UUIDs which should be added as `channel` members. - */ - uuids: Array>; - /** - * List of UUIDs which should be added as `channel` members. - * - * @deprecated Use `uuids` field instead. - */ - users?: Array, 'id'> & { - /** - * Unique User object identifier. - */ - userId: string; - })>; -}; -/** - * Response with requested channel members information change. - */ -export type SetMembersResponse = MembersResponse; -/** - * Remove Members request parameters. - */ -export type RemoveMembersParameters = PagedRequestParameters & { - /** - * Channel name. - */ - channel: string; - /** - * Space identifier. - * - * @deprecated Use {@link channel} field instead. - */ - spaceId?: string; - /** - * List of UUIDs which should be removed from the `channel` members list. - * removed. - */ - uuids: string[]; - /** - * List of user identifiers which should be removed from the `channel` members list. - * removed. - * - * @deprecated Use {@link uuids} field instead. - */ - userIds?: string[]; -}; -/** - * Response with remaining members. - */ -export type RemoveMembersResponse = MembersResponse; -/** - * Related User metadata object. - * - * Type represents User metadata which has been used to when added members to the Space. - */ -type UserMembersObject = Omit, 'id'> & { - user: UUIDMetadataObject | { - id: string; - }; -}; -/** - * Response with fetched page of Space member objects. - */ -export type UserMembersResponse = PagedResponse>; -type SpaceMembershipObject = Omit, 'id'> & { - space: ChannelMetadataObject | { - id: string; - }; -}; -/** - * Response with fetched page of User membership objects. - */ -export type SpaceMembershipsResponse = PagedResponse>; -export {}; diff --git a/lib/types/core/types/api/channel-groups.d.ts b/lib/types/core/types/api/channel-groups.d.ts deleted file mode 100644 index 80cd4717a..000000000 --- a/lib/types/core/types/api/channel-groups.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Add or remove Channels to the channel group request parameters. - */ -export type ManageChannelGroupChannelsParameters = { - /** - * Name of the channel group for which channels list should be changed. - */ - channelGroup: string; - /** - * List of channels to be added or removed. - */ - channels: string[]; -}; -/** - * Channel group channels list manage response. - */ -export type ManageChannelGroupChannelsResponse = Record; -/** - * Response with result of the all channel groups list. - */ -export type ListAllChannelGroupsResponse = { - /** - * All channel groups with channels. - */ - groups: string[]; -}; -/** - * List Channel Group Channels request parameters. - */ -export type ListChannelGroupChannelsParameters = { - /** - * Name of the channel group for which list of channels should be retrieved. - */ - channelGroup: string; -}; -/** - * Response with result of the list channel group channels. - */ -export type ListChannelGroupChannelsResponse = { - /** - * List of the channels registered withing specified channel group. - */ - channels: string[]; -}; -/** - * Delete Channel Group request parameters. - */ -export type DeleteChannelGroupParameters = { - /** - * Name of the channel group which should be removed. - */ - channelGroup: string; -}; -/** - * Delete channel group response. - */ -export type DeleteChannelGroupResponse = Record; diff --git a/lib/types/core/types/api/file-sharing.d.ts b/lib/types/core/types/api/file-sharing.d.ts deleted file mode 100644 index 5bc19beee..000000000 --- a/lib/types/core/types/api/file-sharing.d.ts +++ /dev/null @@ -1,357 +0,0 @@ -/** - * File Sharing REST API module. - */ -import { PubNubFileInterface } from '../file'; -import { Payload } from './index'; -/** - * Shared file object. - */ -export type SharedFile = { - /** - * Name with which file has been stored. - */ - name: string; - /** - * Unique service-assigned file identifier. - */ - id: string; - /** - * Shared file size. - */ - size: number; - /** - * ISO 8601 time string when file has been shared. - */ - created: string; -}; -/** - * List Files request parameters. - */ -export type ListFilesParameters = { - /** - * Name of channel for which list of files should be requested. - */ - channel: string; - /** - * How many entries return with single response. - */ - limit?: number; - /** - * Next files list page token. - */ - next?: string; -}; -/** - * List Files request response. - */ -export type ListFilesResponse = { - /** - * Files list fetch result status code. - */ - status: number; - /** - * List of fetched file objects. - */ - data: SharedFile[]; - /** - * Next files list page token. - */ - next: string; - /** - * Number of retrieved files. - */ - count: number; -}; -/** - * Send File request parameters. - */ -export type SendFileParameters = Omit & { - /** - * Channel to send the file to. - */ - channel: string; - /** - * File to send. - */ - file: FileParameters; -}; -/** - * Send File request response. - */ -export type SendFileResponse = PublishFileMessageResponse & { - /** - * Send file request processing status code. - */ - status: number; - /** - * Actual file name under which file has been stored. - * - * File name and unique {@link id} can be used to download file from the channel later. - * - * **Important:** Actual file name may be different from the one which has been used during file - * upload. - */ - name: string; - /** - * Unique file identifier. - * - * Unique file identifier and it's {@link name} can be used to download file from the channel - * later. - */ - id: string; -}; -/** - * Upload File request parameters. - */ -export type UploadFileParameters = { - /** - * Unique file identifier. - * - * Unique file identifier, and it's {@link fileName} can be used to download file from the channel - * later. - */ - fileId: string; - /** - * Actual file name under which file has been stored. - * - * File name and unique {@link fileId} can be used to download file from the channel later. - * - * **Note:** Actual file name may be different from the one which has been used during file - * upload. - */ - fileName: string; - /** - * File which should be uploaded. - */ - file: PubNubFileInterface; - /** - * Pre-signed file upload Url. - */ - uploadUrl: string; - /** - * An array of form fields to be used in the pre-signed POST request. - * - * **Important:** Form data fields should be passed in exact same order as received from - * the PubNub service. - */ - formFields: { - /** - * Form data field name. - */ - name: string; - /** - * Form data field value. - */ - value: string; - }[]; -}; -/** - * Upload File request response. - */ -export type UploadFileResponse = { - /** - * Upload File request processing status code. - */ - status: number; - /** - * Service processing result response. - */ - message: Payload; -}; -/** - * Generate File Upload URL request parameters. - */ -export type GenerateFileUploadUrlParameters = { - /** - * Name of channel to which file should be uploaded. - */ - channel: string; - /** - * Actual name of the file which should be uploaded. - */ - name: string; -}; -/** - * Generation File Upload URL request response. - */ -export type GenerateFileUploadUrlResponse = { - /** - * Unique file identifier. - * - * Unique file identifier, and it's {@link name} can be used to download file from the channel - * later. - */ - id: string; - /** - * Actual file name under which file has been stored. - * - * File name and unique {@link id} can be used to download file from the channel later. - * - * **Note:** Actual file name may be different from the one which has been used during file - * upload. - */ - name: string; - /** - * Pre-signed URL for file upload. - */ - url: string; - /** - * An array of form fields to be used in the pre-signed POST request. - * - * **Important:** Form data fields should be passed in exact same order as received from - * the PubNub service. - */ - formFields: { - /** - * Form data field name. - */ - name: string; - /** - * Form data field value. - */ - value: string; - }[]; -}; -/** - * Publish File Message request parameters. - */ -export type PublishFileMessageParameters = { - /** - * Name of channel to which file has been sent. - */ - channel: string; - /** - * File annotation message. - */ - message?: Payload; - /** - * Custom file and message encryption key. - * - * @deprecated Use {@link Configuration#cryptoModule|cryptoModule} configured for PubNub client - * instance or encrypt file prior {@link PubNub#sendFile|sendFile} method call. - */ - cipherKey?: string; - /** - * Unique file identifier. - * - * Unique file identifier, and it's {@link fileName} can be used to download file from the channel - * later. - */ - fileId: string; - /** - * Actual file name under which file has been stored. - * - * File name and unique {@link fileId} can be used to download file from the channel later. - * - * **Note:** Actual file name may be different from the one which has been used during file - * upload. - */ - fileName: string; - /** - * Whether published file messages should be stored in the channel's history. - * - * **Note:** If `storeInHistory` not specified, then the history configuration on the key is - * used. - * - * @default `true` - */ - storeInHistory?: boolean; - /** - * How long the message should be stored in the channel's history. - * - * **Note:** If not specified, defaults to the key set's retention value. - * - * @default `0` - */ - ttl?: number; - /** - * Metadata, which should be associated with published file. - * - * Associated metadata can be utilized by message filtering feature. - */ - meta?: Payload; -}; -/** - * Publish File Message request response. - */ -export type PublishFileMessageResponse = { - /** - * High-precision time when published file message has been received by the PubNub service. - */ - timetoken: string; -}; -/** - * Download File request parameters. - */ -export type DownloadFileParameters = FileUrlParameters & { - /** - * Custom file and message encryption key. - * - * @deprecated Use {@link Configuration#cryptoModule|cryptoModule} configured for PubNub client - * instance or encrypt file prior {@link PubNub#sendFile|sendFile} method call. - */ - cipherKey?: string; -}; -/** - * Generate File download Url request parameters. - */ -export type FileUrlParameters = { - /** - * Name of channel where file has been sent. - */ - channel: string; - /** - * Unique file identifier. - * - * Unique file identifier and it's {@link name} can be used to download file from the channel - * later. - */ - id: string; - /** - * Actual file name under which file has been stored. - * - * File name and unique {@link id} can be used to download file from the channel later. - * - * **Important:** Actual file name may be different from the one which has been used during file - * upload. - */ - name: string; -}; -/** - * Generate File Download Url response. - */ -export type FileUrlResponse = string; -/** - * Delete File request parameters. - */ -export type DeleteFileParameters = { - /** - * Name of channel where file has been sent. - */ - channel: string; - /** - * Unique file identifier. - * - * Unique file identifier and it's {@link name} can be used to download file from the channel - * later. - */ - id: string; - /** - * Actual file name under which file has been stored. - * - * File name and unique {@link id} can be used to download file from the channel later. - * - * **Important:** Actual file name may be different from the one which has been used during file - * upload. - */ - name: string; -}; -/** - * Delete File request response. - */ -export type DeleteFileResponse = { - /** - * Delete File request processing status code. - */ - status: number; -}; diff --git a/lib/types/core/types/api/history.d.ts b/lib/types/core/types/api/history.d.ts deleted file mode 100644 index 9ae00f1c2..000000000 --- a/lib/types/core/types/api/history.d.ts +++ /dev/null @@ -1,395 +0,0 @@ -import { Payload } from './index'; -/** - * Get history request parameters. - */ -export type GetHistoryParameters = { - /** - * Channel to return history messages from. - */ - channel: string; - /** - * Specifies the number of historical messages to return. - * - * **Note:** Maximum `100` messages can be returned in single response. - * - * @default `100` - */ - count?: number; - /** - * Whether message `meta` information should be fetched or not. - * - * @default `false` - */ - includeMeta?: boolean; - /** - * Timetoken delimiting the `start` of `time` slice (exclusive) to pull messages from. - */ - start?: string; - /** - * Timetoken delimiting the `end` of `time` slice (inclusive) to pull messages from. - */ - end?: string; - /** - * Whether timeline should traverse in reverse starting with the oldest message first or not. - * - * If both `start` and `end` arguments are provided, `reverse` is ignored and messages are - * returned starting with the newest message. - */ - reverse?: boolean; - /** - * Whether message timetokens should be stringified or not. - * - * @default `false` - */ - stringifiedTimeToken?: boolean; -}; -/** - * Get history response. - */ -export type GetHistoryResponse = { - /** - * List of previously published messages. - */ - messages: { - /** - * Message payload (decrypted). - */ - entry: Payload; - /** - * When message has been received by PubNub service. - */ - timetoken: string | number; - /** - * Additional data which has been published along with message to be used with real-time - * events filter expression. - */ - meta?: Payload; - /** - * Message decryption error (if attempt has been done). - */ - error?: string; - }[]; - /** - * Received messages timeline start. - */ - startTimeToken: string | number; - /** - * Received messages timeline end. - */ - endTimeToken: string | number; -}; -/** - * PubNub-defined message type. - * - * Types of messages which can be retrieved with fetch messages REST API. - */ -export declare enum PubNubMessageType { - /** - * Regular message. - */ - Message = -1, - /** - * File message. - */ - Files = 4 -} -/** - * Per-message actions information. - */ -export type Actions = { - /** - * Message action type. - */ - [t: string]: { - /** - * Message action value. - */ - [v: string]: { - /** - * Unique identifier of the user which reacted on message. - */ - uuid: string; - /** - * High-precision PubNub timetoken with time when {@link uuid} reacted on message. - */ - actionTimetoken: string; - }; - }; -}; -/** - * Additional message actions fetch information. - */ -export type MoreActions = { - /** - * Prepared fetch messages with actions REST API URL. - */ - url: string; - /** - * Next page time offset. - */ - start: string; - /** - * Number of messages to retrieve with next page. - */ - max: number; -}; -/** - * Common content of the fetched message. - */ -type BaseFetchedMessage = { - /** - * Name of channel for which message has been retrieved. - */ - channel: string; - /** - * When message has been received by PubNub service. - */ - timetoken: string | number; - /** - * Message publisher unique identifier. - */ - uuid?: string; - /** - * Additional data which has been published along with message to be used with real-time - * events filter expression. - */ - meta?: Payload; - /** - * Message decryption error (if attempt has been done). - */ - error?: string; -}; -/** - * Regular message published to the channel. - */ -export type RegularMessage = BaseFetchedMessage & { - /** - * Message payload (decrypted). - */ - message: Payload; - /** - * PubNub-defined message type. - */ - messageType?: PubNubMessageType.Message; -}; -/** - * File message published to the channel. - */ -export type FileMessage = BaseFetchedMessage & { - /** - * Message payload (decrypted). - */ - message: { - /** - * File annotation message. - */ - message?: Payload; - /** - * File information. - */ - file: { - /** - * Unique file identifier. - */ - id: string; - /** - * Name with which file has been stored. - */ - name: string; - /** - * File's content mime-type. - */ - 'mime-type': string; - /** - * Stored file size. - */ - size: number; - /** - * Pre-computed file download Url. - */ - url: string; - }; - }; - /** - * PubNub-defined message type. - */ - messageType?: PubNubMessageType.Files; -}; -/** - * Fetched message entry in channel messages list. - */ -export type FetchedMessage = RegularMessage | FileMessage; -/** - * Fetched with actions message entry in channel messages list. - */ -export type FetchedMessageWithActions = FetchedMessage & { - /** - * List of message reactions. - */ - actions?: Actions; - /** - * List of message reactions. - * - * @deprecated Use {@link actions} field instead. - */ - data?: Actions; -}; -/** - * Fetch messages request parameters. - */ -export type FetchMessagesParameters = { - /** - * Specifies channels to return history messages from. - * - * **Note:** Maximum of `500` channels are allowed. - */ - channels: string[]; - /** - * Specifies the number of historical messages to return per channel. - * - * **Note:** Default is `100` per single channel and `25` per multiple channels or per - * single channel if {@link includeMessageActions} is used. - * - * @default `100` or `25` - */ - count?: number; - /** - * Whether message type should be returned with each history message or not. - * - * @default `true` - */ - includeMessageType?: boolean; - /** - * Whether publisher `uuid` should be returned with each history message or not. - * - * @default `true` - */ - includeUUID?: boolean; - /** - * Whether publisher `uuid` should be returned with each history message or not. - * - * @deprecated Use {@link includeUUID} property instead. - */ - includeUuid?: boolean; - /** - * Whether message `meta` information should be fetched or not. - * - * @default `false` - */ - includeMeta?: boolean; - /** - * Whether message-added message actions should be fetched or not. - * - * If used, the limit of messages retrieved will be `25` per single channel. - * - * Each message can have a maximum of `25000` actions attached to it. Consider the example of - * querying for 10 messages. The first five messages have 5000 actions attached to each of - * them. The API will return the first 5 messages and all their 25000 actions. The response - * will also include a `more` link to get the remaining 5 messages. - * - * **Important:** Truncation will happen if the number of actions on the messages returned - * is > 25000. - * - * @default `false` - * - * @throws Exception if API is called with more than one channel. - */ - includeMessageActions?: boolean; - /** - * Timetoken delimiting the `start` of `time` slice (exclusive) to pull messages from. - */ - start?: string; - /** - * Timetoken delimiting the `end` of `time` slice (inclusive) to pull messages from. - */ - end?: string; - /** - * Whether message timetokens should be stringified or not. - * - * @default `false` - */ - stringifiedTimeToken?: boolean; -}; -/** - * Fetch messages response. - */ -export type FetchMessagesForChannelsResponse = { - /** - * List of previously published messages per requested channel. - */ - channels: { - [p: string]: FetchedMessage[]; - }; -}; -/** - * Fetch messages with reactions response. - */ -export type FetchMessagesWithActionsResponse = { - channels: { - [p: string]: FetchedMessageWithActions[]; - }; - /** - * Additional message actions fetch information. - */ - more: MoreActions; -}; -/** - * Fetch messages response. - */ -export type FetchMessagesResponse = FetchMessagesForChannelsResponse | FetchMessagesWithActionsResponse; -/** - * Message count request parameters. - */ -export type MessageCountParameters = { - /** - * The channels to fetch the message count. - */ - channels: string[]; - /** - * List of timetokens, in order of the {@link channels} list. - * - * Specify a single timetoken to apply it to all channels. Otherwise, the list of timetokens - * must be the same length as the list of {@link channels}, or the function returns an error - * flag. - */ - channelTimetokens?: string[]; - /** - * High-precision PubNub timetoken starting from which number of messages should be counted. - * - * Same timetoken will be used to count messages for each passed {@link channels}. - * - * @deprecated Use {@link channelTimetokens} field instead. - */ - timetoken?: string; -}; -/** - * Message count response. - */ -export type MessageCountResponse = { - /** - * Map of channel names to the number of counted messages. - */ - channels: Record; -}; -/** - * Delete messages from channel parameters. - */ -export type DeleteMessagesParameters = { - /** - * Specifies channel messages to be deleted from history. - */ - channel: string; - /** - * Timetoken delimiting the start of time slice (exclusive) to delete messages from. - */ - start?: string; - /** - * Timetoken delimiting the end of time slice (inclusive) to delete messages from. - */ - end?: string; -}; -/** - * Delete messages from channel response. - */ -export type DeleteMessagesResponse = Record; -export {}; diff --git a/lib/types/core/types/api/index.d.ts b/lib/types/core/types/api/index.d.ts deleted file mode 100644 index a27191168..000000000 --- a/lib/types/core/types/api/index.d.ts +++ /dev/null @@ -1,121 +0,0 @@ -import { AbstractRequest } from '../../components/request'; -import RequestOperation from '../../constants/operations'; -import StatusCategory from '../../constants/categories'; -/** - * PubNub account keyset. - */ -export type KeySet = { - /** - * Specifies the `subscribeKey` to be used for subscribing to a channel and message publishing. - */ - subscribeKey: string; - /** - * Specifies the `publishKey` to be used for publishing messages to a channel. - */ - publishKey?: string; - /** - * Specifies the `secretKey` to be used for request signatures computation. - */ - secretKey?: string; -}; -/** - * REST API request processing function. - */ -export type SendRequestFunction = (request: AbstractRequest, callback?: ResultCallback) => Promise; -/** - * Endpoint call completion block with result. - * - * **Note:** Endpoints which return consumable data use this callback. - */ -export type ResultCallback = (status: Status, response: ResponseType | null) => void; -/** - * Endpoint acknowledgment completion block. - * - * **Note:** Endpoints which return only acknowledgment or error status use this callback. - */ -export type StatusCallback = (status: Status) => void; -/** - * REST API endpoint processing status. - * - * **Note:** Used as {@link ResultCallback} and {@link StatusCallback} callbacks first argument type and - * {@link PubNubError} instance `status` field value type. - */ -export type Status = { - /** - * Whether status represent error or not. - */ - error: boolean; - /** - * API call status category. - */ - category: StatusCategory; - /** - * Type of REST API endpoint which reported status. - */ - operation?: RequestOperation; - /** - * REST API response status code. - */ - statusCode: number; - /** - * Error data provided by REST API. - */ - errorData?: Error | Payload; - /** - * Additional status information. - */ - [p: string]: Payload | Error | undefined; -}; -/** - * Real-time PubNub client status change event. - */ -export type StatusEvent = { - /** - * API call status category. - */ - category: StatusCategory; - /** - * Type of REST API endpoint which reported status. - */ - operation?: RequestOperation; - /** - * Information about error. - */ - error?: string | boolean; - /** - * List of channels for which status update announced. - */ - affectedChannels?: string[]; - /** - * List of currently subscribed channels. - * - * List of channels from which PubNub client receives real-time updates. - */ - subscribedChannels?: string[]; - /** - * List of channel groups for which status update announced. - */ - affectedChannelGroups?: string[]; - /** - * High-precision timetoken which has been used with previous subscription loop. - */ - lastTimetoken?: number | string; - /** - * High-precision timetoken which is used for current subscription loop. - */ - currentTimetoken?: number | string; -}; -/** - * {@link TransportRequest} query parameter type. - */ -export type Query = Record; -/** - * General payload type. - * - * Type should be used for: - * * generic messages and signals content, - * * published message metadata. - */ -export type Payload = string | number | boolean | { - [key: string]: Payload | null; -} | Payload[]; diff --git a/lib/types/core/types/api/message-action.d.ts b/lib/types/core/types/api/message-action.d.ts deleted file mode 100644 index 7ad1941a8..000000000 --- a/lib/types/core/types/api/message-action.d.ts +++ /dev/null @@ -1,153 +0,0 @@ -/** - * Message reaction object type. - */ -export type MessageAction = { - /** - * What feature this message action represents. - */ - type: string; - /** - * Value which should be stored along with message action. - */ - value: string; - /** - * Unique identifier of the user which added message action. - */ - uuid: string; - /** - * Timetoken of when message reaction has been added. - * - * **Note:** This token required when it will be required to remove raction. - */ - actionTimetoken: string; - /** - * Timetoken of message to which `action` has been added. - */ - messageTimetoken: string; -}; -/** - * More message actions fetch information. - */ -export type MoreMessageActions = { - /** - * Prepared REST API url to fetch next page with message actions. - */ - url: string; - /** - * Message action timetoken denoting the start of the range requested with next page. - * - * **Note:** Return values will be less than {@link start}. - */ - start: string; - /** - * Message action timetoken denoting the end of the range requested with next page. - * - * **Note:** Return values will be greater than or equal to {@link end}. - */ - end: string; - /** - * Number of message actions to return in next response. - */ - limit: number; -}; -/** - * Add Message Action request parameters. - */ -export type AddMessageActionParameters = { - /** - * Name of channel which stores the message for which {@link action} should be added. - */ - channel: string; - /** - * Timetoken of message for which {@link action} should be added. - */ - messageTimetoken: string; - /** - * Message `action` information. - */ - action: { - /** - * What feature this message action represents. - */ - type: string; - /** - * Value which should be stored along with message action. - */ - value: string; - }; -}; -/** - * Response with added message action object. - */ -export type AddMessageActionResponse = { - data: MessageAction; -}; -/** - * Get Message Actions request parameters. - */ -export type GetMessageActionsParameters = { - /** - * Name of channel from which list of messages `actions` should be retrieved. - */ - channel: string; - /** - * Message action timetoken denoting the start of the range requested. - * - * **Note:** Return values will be less than {@link start}. - */ - start?: string; - /** - * Message action timetoken denoting the end of the range requested. - * - * **Note:** Return values will be greater than or equal to {@link end}. - */ - end?: string; - /** - * Number of message actions to return in response. - */ - limit?: number; -}; -/** - * Response with message actions in specific `channel`. - */ -export type GetMessageActionsResponse = { - /** - * Retrieved list of message actions. - */ - data: MessageAction[]; - /** - * Received message actions time frame start. - */ - start: string | null; - /** - * Received message actions time frame end. - */ - end: string | null; - /** - * More message actions fetch information. - */ - more?: MoreMessageActions; -}; -/** - * Remove Message Action request parameters. - */ -export type RemoveMessageActionParameters = { - /** - * Name of channel which store message for which `action` should be removed. - */ - channel: string; - /** - * Timetoken of message for which `action` should be removed. - */ - messageTimetoken: string; - /** - * Action addition timetoken. - */ - actionTimetoken: string; -}; -/** - * Response with message remove result. - */ -export type RemoveMessageActionResponse = { - data: Record; -}; diff --git a/lib/types/core/types/api/presence.d.ts b/lib/types/core/types/api/presence.d.ts deleted file mode 100644 index 28519378d..000000000 --- a/lib/types/core/types/api/presence.d.ts +++ /dev/null @@ -1,210 +0,0 @@ -import { Payload } from './index'; -/** - * Associated presence state fetch parameters. - */ -export type GetPresenceStateParameters = { - /** - * The subscriber uuid to get the current state. - * - * @default `current uuid` - */ - uuid?: string; - /** - * List of channels for which state associated with {@link uuid} should be retrieved. - * - * **Important:** Either {@link channels} or {@link channelGroups} should be provided; - */ - channels?: string[]; - /** - * List of channel groups for which state associated with {@link uuid} should be retrieved. - * - * **Important:** Either {@link channels} or {@link channelGroups} should be provided; - */ - channelGroups?: string[]; -}; -/** - * Associated presence state fetch response. - */ -export type GetPresenceStateResponse = { - /** - * Channels map to state which `uuid` has associated with them. - */ - channels: Record; -}; -/** - * Associate presence state parameters. - */ -export type SetPresenceStateParameters = { - /** - * List of channels for which state should be associated with {@link uuid}. - */ - channels?: string[]; - /** - * List of channel groups for which state should be associated with {@link uuid}. - */ - channelGroups?: string[]; - /** - * State which should be associated with `uuid` on provided list of {@link channels} and {@link channelGroups}. - */ - state: Payload; -}; -/** - * Associate presence state parameters using heartbeat. - */ -export type SetPresenceStateWithHeartbeatParameters = { - /** - * List of channels for which state should be associated with {@link uuid}. - */ - channels?: string[]; - /** - * State which should be associated with `uuid` on provided list of {@link channels}. - */ - state: Payload; - /** - * Whether `presence/heartbeat` REST API should be used to manage state or not. - * - * @default `false` - */ - withHeartbeat: boolean; -}; -/** - * Associate presence state response. - */ -export type SetPresenceStateResponse = { - /** - * State which has been associated with `uuid` on provided list of channels and groups. - */ - state: Payload; -}; -/** - * Announce heartbeat parameters. - */ -export type PresenceHeartbeatParameters = { - /** - * How long the server will consider the client alive for presence.The value is in seconds. - */ - heartbeat: number; - /** - * List of channels for which heartbeat should be announced for {@link uuid}. - */ - channels?: string[]; - /** - * List of channel groups for which heartbeat should be announced for {@link uuid}. - */ - channelGroups?: string[]; - /** - * State which should be associated with `uuid` on provided list of {@link channels} and {@link channelGroups}. - */ - state?: Payload; -}; -/** - * Announce heartbeat response. - */ -export type PresenceHeartbeatResponse = Record; -/** - * Presence leave parameters. - */ -export type PresenceLeaveParameters = { - /** - * List of channels for which `uuid` should be marked as `offline`. - */ - channels?: string[]; - /** - /** - * List of channel groups for which `uuid` should be marked as `offline`. - */ - channelGroups?: string[]; -}; -/** - * Presence leave response. - */ -export type PresenceLeaveResponse = Record; -/** - * Channel / channel group presence fetch parameters.. - */ -export type HereNowParameters = { - /** - * List of channels for which presence should be retrieved. - */ - channels?: string[]; - /** - * List of channel groups for which presence should be retrieved. - */ - channelGroups?: string[]; - /** - * Whether `uuid` information should be included in response or not. - * - * **Note:** Only occupancy information will be returned if both {@link includeUUIDs} and {@link includeState} is - * set to `false`. - * - * @default `true` - */ - includeUUIDs?: boolean; - /** - * Whether state associated with `uuid` should be included in response or not. - * - * @default `false`. - */ - includeState?: boolean; - /** - * Additional query parameters. - */ - queryParameters?: Record; -}; -/** - * `uuid` where now response. - */ -export type HereNowResponse = { - /** - * Total number of channels for which presence information received. - */ - totalChannels: number; - /** - * Total occupancy for all retrieved channels. - */ - totalOccupancy: number; - /** - * List of channels to which `uuid` currently subscribed. - */ - channels: { - [p: string]: { - /** - * List of received channel subscribers. - * - * **Note:** Field is missing if `uuid` and `state` not included. - */ - occupants: { - uuid: string; - state?: Payload | null; - }[]; - /** - * Name of channel for which presence information retrieved. - */ - name: string; - /** - * Total number of active subscribers in single channel. - */ - occupancy: number; - }; - }; -}; -/** - * `uuid` where now parameters. - */ -export type WhereNowParameters = { - /** - * The subscriber uuid to get the current state. - * - * @default `current uuid` - */ - uuid?: string; -}; -/** - * `uuid` where now response. - */ -export type WhereNowResponse = { - /** - * Channels map to state which `uuid` has associated with them. - */ - channels: string[]; -}; diff --git a/lib/types/core/types/api/push-notifications.d.ts b/lib/types/core/types/api/push-notifications.d.ts deleted file mode 100644 index 57ab65076..000000000 --- a/lib/types/core/types/api/push-notifications.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Type of Push Notifications gateway which should be used with Push Notifications REST API. - */ -type PushGateway = 'apns2' | 'gcm'; -/** - * Basic information required by Push Notifications REST API about device. - */ -type DevicePush = { - /** - * Device ID for which list of registered channel push notifications will be changed. - */ - device: string; - /** - * Push Notifications gateway to use. - * - * **Important:** Depends from the source of `device` token and can be `apns2` (for token - * provided during device registration using Apple's framework) or `gcm` (when used Firebase - * or similar framework to receive token). - */ - pushGateway: PushGateway; -}; -/** - * Register and unregister push notifications for device request parameters. - */ -export type ManageDeviceChannelsParameters = { - /** - * List of channels to be added or removed. - */ - channels: string[]; -} & DevicePush; -/** - * List Device Channels request parameters. - */ -export type ListDeviceChannelsParameters = DevicePush; -/** - * Response with result of the list device channels. - */ -export type ListDeviceChannelsResponse = { - /** - * List of the channels for which `device` will receive push notifications. - */ - channels: string[]; -}; -/** - * Delete Push Notification for device request parameters. - */ -export type DeleteDeviceParameters = DevicePush; -export {}; diff --git a/lib/types/core/types/api/push.d.ts b/lib/types/core/types/api/push.d.ts deleted file mode 100644 index 6d67ed8cf..000000000 --- a/lib/types/core/types/api/push.d.ts +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Common managed channels push notification parameters. - */ -type ManagedDeviceChannels = { - /** - * Channels to register or unregister with mobile push notifications. - */ - channels: string[]; - /** - * The device ID to associate with mobile push notifications. - */ - device: string; - /** - * Starting channel for pagination. - * - * **Note:** Use the last channel from the previous page request. - */ - start?: string; - /** - * Number of channels to return for pagination. - * - * **Note:** maximum of 1000 tokens at a time. - * - * @default `500` - */ - count?: number; -}; -/** - * List all FCM device push notification enabled channels parameters. - */ -type ListFCMDeviceChannelsParameters = Omit; -/** - * List all APNS device push notification enabled channels parameters. - * - * @deprecated Use `APNS2`-based endpoints. - */ -type ListAPNSDeviceChannelsParameters = Omit; -/** - * List all APNS2 device push notification enabled channels parameters. - */ -type ListAPNS2DeviceChannelsParameters = Omit; -/** - * List all device push notification enabled channels parameters. - */ -export type ListDeviceChannelsParameters = ListFCMDeviceChannelsParameters | ListAPNSDeviceChannelsParameters | ListAPNS2DeviceChannelsParameters; -/** - * List all device push notification enabled channels response. - */ -export type ListDeviceChannelsResponse = { - /** - * List of channels registered for device push notifications. - */ - channels: string[]; -}; -/** - * Manage FCM device push notification enabled channels parameters. - */ -type ManageFCMDeviceChannelsParameters = ManagedDeviceChannels & { - /** - * Push Notifications gateway type. - */ - pushGateway: 'gcm'; -}; -/** - * Manage APNS device push notification enabled channels parameters. - * - * @deprecated Use `APNS2`-based endpoints. - */ -type ManageAPNSDeviceChannelsParameters = ManagedDeviceChannels & { - /** - * Push Notifications gateway type. - */ - pushGateway: 'apns'; -}; -/** - * Manage APNS2 device push notification enabled channels parameters. - */ -type ManageAPNS2DeviceChannelsParameters = ManagedDeviceChannels & { - /** - * Push Notifications gateway type. - */ - pushGateway: 'apns2'; - /** - * Environment within which device should manage list of channels with enabled notifications. - */ - environment?: 'development' | 'production'; - /** - * Notifications topic name (usually it is bundle identifier of application for Apple platform). - */ - topic: string; -}; -/** - * Manage device push notification enabled channels parameters. - */ -export type ManageDeviceChannelsParameters = ManageFCMDeviceChannelsParameters | ManageAPNSDeviceChannelsParameters | ManageAPNS2DeviceChannelsParameters; -/** - * Manage device push notification enabled channels response. - */ -export type ManageDeviceChannelsResponse = Record; -/** - * Remove all FCM device push notification enabled channels parameters. - */ -type RemoveFCMDeviceParameters = Omit; -/** - * Manage APNS device push notification enabled channels parameters. - * - * @deprecated Use `APNS2`-based endpoints. - */ -type RemoveAPNSDeviceParameters = Omit; -/** - * Manage APNS2 device push notification enabled channels parameters. - */ -type RemoveAPNS2DeviceParameters = Omit; -/** - * Remove all device push notification enabled channels parameters. - */ -export type RemoveDeviceParameters = RemoveFCMDeviceParameters | RemoveAPNSDeviceParameters | RemoveAPNS2DeviceParameters; -/** - * Remove all device push notification enabled channels response. - */ -export type RemoveDeviceResponse = Record; -export {}; diff --git a/lib/types/core/types/api/subscription.d.ts b/lib/types/core/types/api/subscription.d.ts deleted file mode 100644 index 0c8e1e19e..000000000 --- a/lib/types/core/types/api/subscription.d.ts +++ /dev/null @@ -1,296 +0,0 @@ -import { RequestParameters as SubscribeRequestParameters, VSPMembershipObjectData, AppContextObjectData, MessageActionData, PubNubEventType, SpaceObjectData, UserObjectData, PresenceData, FileData } from '../../endpoints/subscribe'; -import { AbortSignal } from '../../components/abort_signal'; -import { Payload } from './index'; -/** - * Time cursor. - * - * Cursor used by subscription loop to identify point in time after which updates will be - * delivered. - */ -export type SubscriptionCursor = { - /** - * PubNub high-precision timestamp. - * - * Aside of specifying exact time of receiving data / event this token used to catchup / - * follow on real-time updates. - */ - timetoken: string | number; - /** - * Data center region for which `timetoken` has been generated. - */ - region?: number; -}; -/** - * Common real-time event. - */ -type Event = { - /** - * Channel to which real-time event has been sent. - */ - channel: string; - /** - * Actual subscription at which real-time event has been received. - * - * PubNub client provide various ways to subscribe to the real-time stream: channel groups, - * wildcard subscription, and spaces. - * - * **Note:** Value will be `null` if it is the same as {@link channel}. - */ - subscription: string | null; - /** - * High-precision PubNub timetoken with time when event has been received by PubNub services. - */ - timetoken: string; -}; -/** - * Common legacy real-time event for backward compatibility. - */ -type LegacyEvent = Event & { - /** - * Channel to which real-time event has been sent. - * - * @deprecated Use {@link channel} field instead. - */ - actualChannel?: string | null; - /** - * Actual subscription at which real-time event has been received. - * - * @deprecated Use {@link subscription} field instead. - */ - subscribedChannel?: string; -}; -/** - * Presence change real-time event. - */ -export type Presence = LegacyEvent & PresenceData; -/** - * Extended presence real-time event. - * - * Type extended for listener manager support. - */ -type PresenceEvent = { - type: PubNubEventType.Presence; - data: Presence; -}; -/** - * Common published data information. - */ -type PublishedData = { - /** - * Unique identifier of the user which sent data. - */ - publisher?: string; - /** - * Additional user-provided metadata which can be used with real-time filtering expression. - */ - userMetadata?: { - [p: string]: Payload; - }; - /** - * Sent data. - */ - message: Payload; -}; -/** - * Real-time message event. - */ -export type Message = LegacyEvent & PublishedData & { - /** - * Decryption error message in case of failure. - */ - error?: string; -}; -/** - * Extended real-time message event. - * - * Type extended for listener manager support. - */ -type MessageEvent = { - type: PubNubEventType.Message; - data: Message; -}; -/** - * Real-time signal event. - */ -export type Signal = Event & PublishedData; -/** - * Extended real-time signal event. - * - * Type extended for listener manager support. - */ -type SignalEvent = { - type: PubNubEventType.Signal; - data: Signal; -}; -/** - * Message action real-time event. - */ -export type MessageAction = Event & Omit & { - /** - * Unique identifier of the user which added message reaction. - * - * @deprecated Use `data.uuid` field instead. - */ - publisher?: string; - data: MessageActionData['data'] & { - /** - * Unique identifier of the user which added message reaction. - */ - uuid: string; - }; -}; -/** - * Extended message action real-time event. - * - * Type extended for listener manager support. - */ -type MessageActionEvent = { - type: PubNubEventType.MessageAction; - data: MessageAction; -}; -/** - * App Context Object change real-time event. - */ -export type AppContextObject = Event & { - /** - * Information about App Context object for which event received. - */ - message: AppContextObjectData; -}; -/** - * `User` App Context Object change real-time event. - */ -export type UserAppContextObject = Omit & { - /** - * Space to which real-time event has been sent. - */ - spaceId: string; - /** - * Information about User Object for which event received. - */ - message: UserObjectData; -}; -/** - * `Space` App Context Object change real-time event. - */ -export type SpaceAppContextObject = Omit & { - /** - * Space to which real-time event has been sent. - */ - spaceId: string; - /** - * Information about `Space` Object for which event received. - */ - message: SpaceObjectData; -}; -/** - * VSP `Membership` App Context Object change real-time event. - */ -export type VSPMembershipAppContextObject = Omit & { - /** - * Space to which real-time event has been sent. - */ - spaceId: string; - /** - * Information about `Membership` Object for which event received. - */ - message: VSPMembershipObjectData; -}; -/** - * Extended App Context Object change real-time event. - * - * Type extended for listener manager support. - */ -type AppContextEvent = { - type: PubNubEventType.AppContext; - data: AppContextObject; -}; -/** - * File real-time event. - */ -export type File = Event & Omit & Omit & { - /** - * Message which has been associated with uploaded file. - */ - message?: Payload; - /** - * Information about uploaded file. - */ - file?: FileData['file'] & { - /** - * File download url. - */ - url: string; - }; - /** - * Decryption error message in case of failure. - */ - error?: string; -}; -/** - * Extended File real-time event. - * - * Type extended for listener manager support. - */ -type FileEvent = { - type: PubNubEventType.Files; - data: File; -}; -/** - * Cancelable subscribe request parameters. - */ -export type CancelableSubscribeParameters = Omit & { - /** - * Long-poll request termination signal. - */ - abortSignal: AbortSignal; -}; -/** - * Subscribe request parameters. - */ -export type SubscribeParameters = { - /** - * List of channels from which real-time events should be delivered. - * - * @default `,` if {@link channelGroups} is set. - */ - channels?: string[]; - /** - * List of channel groups from which real-time events should be retrieved. - */ - channelGroups?: string[]; - /** - * Next subscription loop timetoken. - */ - timetoken?: string | number; - /** - * Whether should subscribe to channels / groups presence announcements or not. - * - * @default `false` - */ - withPresence?: boolean; - /** - * Presence information which should be associated with `userId`. - * - * `state` information will be associated with `userId` on channels mentioned as keys in - * this object. - * - * @deprecated Use set state methods to specify associated user's data instead of passing to - * subscribe. - */ - state?: Record; - /** - * Whether should subscribe to channels / groups presence announcements or not. - * - * @default `false` - */ - withHeartbeats?: boolean; -}; -/** - * Service success response. - */ -export type SubscriptionResponse = { - cursor: SubscriptionCursor; - messages: (PresenceEvent | MessageEvent | SignalEvent | MessageActionEvent | AppContextEvent | FileEvent)[]; -}; -export {}; diff --git a/lib/types/core/types/file.d.ts b/lib/types/core/types/file.d.ts deleted file mode 100644 index 774a161da..000000000 --- a/lib/types/core/types/file.d.ts +++ /dev/null @@ -1,104 +0,0 @@ -/** - * {@link PubNub} File object interface module. - */ -/** - * Base file constructor parameters. - * - * Minimum set of parameters which can be p - */ -export type PubNubBasicFileParameters = { - data: string | ArrayBuffer; - name: string; - mimeType?: string; -}; -/** - * Platform-agnostic {@link PubNub} File object. - * - * Interface describes share of {@link PubNub} File which is required by {@link PubNub} core to - * perform required actions. - */ -export interface PubNubFileInterface { - /** - * Actual file name. - */ - name: string; - /** - * File mime-type. - */ - mimeType?: string; - /** - * File content length. - */ - contentLength?: number; - /** - * Convert {@link PubNub} file object content to {@link ArrayBuffer}. - * - * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. - * - * @throws Error if provided {@link PubNub} File object content is not supported for this - * operation. - */ - toArrayBuffer(): Promise; - /** - * Convert {@link PubNub} File object content to file `Uri`. - * - * @returns Asynchronous results of conversion to file `Uri`. - * - * @throws Error if provided {@link PubNub} File object content is not supported for this - * operation. - */ - toFileUri(): Promise>; -} -/** - * {@link PubNub} File object class interface. - */ -export interface PubNubFileConstructor { - /** - * Whether {@link Blob} data supported by platform or not. - */ - supportsBlob: boolean; - /** - * Whether {@link File} data supported by platform or not. - */ - supportsFile: boolean; - /** - * Whether {@link Buffer} data supported by platform or not. - */ - supportsBuffer: boolean; - /** - * Whether {@link Stream} data supported by platform or not. - */ - supportsStream: boolean; - /** - * Whether {@link String} data supported by platform or not. - */ - supportsString: boolean; - /** - * Whether {@link ArrayBuffer} supported by platform or not. - */ - supportsArrayBuffer: boolean; - /** - * Whether {@link PubNub} File object encryption supported or not. - */ - supportsEncryptFile: boolean; - /** - * Whether `File Uri` data supported by platform or not. - */ - supportsFileUri: boolean; - /** - * {@link PubNub} File object constructor. - * - * @param file - File instantiation parameters (can be raw data or structured object). - * - * @returns Constructed platform-specific {@link PubNub} File object. - */ - create(file: ConstructorParameters): File; - /** - * {@link PubNub} File object constructor. - * - * @param file - File instantiation parameters (can be raw data or structured object). - * - * @returns Constructed platform-specific {@link PubNub} File object. - */ - new (file: ConstructorParameters): File; -} diff --git a/lib/types/core/types/transport-request.d.ts b/lib/types/core/types/transport-request.d.ts deleted file mode 100644 index 09ddc24f4..000000000 --- a/lib/types/core/types/transport-request.d.ts +++ /dev/null @@ -1,97 +0,0 @@ -import { PubNubFileInterface } from './file'; -import { Query } from './api'; -/** - * Enum representing possible transport methods for HTTP requests. - * - * @enum {number} - */ -export declare enum TransportMethod { - /** - * Request will be sent using `GET` method. - */ - GET = "GET", - /** - * Request will be sent using `POST` method. - */ - POST = "POST", - /** - * Request will be sent using `PATCH` method. - */ - PATCH = "PATCH", - /** - * Request will be sent using `DELETE` method. - */ - DELETE = "DELETE", - /** - * Local request. - * - * Request won't be sent to the service and probably used to compute URL. - */ - LOCAL = "LOCAL" -} -/** - * Request cancellation controller. - */ -export type CancellationController = { - /** - * Request cancellation / abort function. - */ - abort: () => void; -}; -/** - * This object represents a request to be sent to the PubNub API. - * - * This struct represents a request to be sent to the PubNub API. It is used by the transport - * provider which implements {@link Transport} interface. - * - * All fields are representing certain parts of the request that can be used to prepare one. - */ -export type TransportRequest = { - /** - * Remote host name. - */ - origin?: string; - /** - * Remote resource path. - */ - path: string; - /** - * Query parameters to be sent with the request. - */ - queryParameters?: Query; - /** - * Transport request HTTP method. - */ - method: TransportMethod; - /** - * Headers to be sent with the request. - */ - headers?: Record; - /** - * Multipart form data fields. - * - * **Important:** `Content-Type` header should be sent the {@link body} data type when - * `multipart/form-data` should request should be sent. - */ - formData?: Record[]; - /** - * Body to be sent with the request. - */ - body?: ArrayBuffer | PubNubFileInterface | string; - /** - * For how long request should wait response from the server. - * - * @default `10` seconds. - */ - timeout: number; - /** - * Whether request can be cancelled or not. - * - * @default `false`. - */ - cancellable: boolean; - /** - * Unique request identifier. - */ - identifier: string; -}; diff --git a/lib/types/core/types/transport-response.d.ts b/lib/types/core/types/transport-response.d.ts deleted file mode 100644 index 359aa8712..000000000 --- a/lib/types/core/types/transport-response.d.ts +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Represents a transport response from a service. - */ -export type TransportResponse = { - /** - * Full remote resource URL used to retrieve response. - */ - url: string; - /** - * Service response status code. - */ - status: number; - /** - * Service response headers. - * - * **Important:** Header names are in lowercase. - */ - headers: Record; - /** - * Service response body. - */ - body?: ArrayBuffer; -}; diff --git a/lib/types/core/utils.d.ts b/lib/types/core/utils.d.ts deleted file mode 100644 index 8f9ab9d64..000000000 --- a/lib/types/core/utils.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Query } from './types/api'; -/** - * Percent-encode input string. - * - * **Note:** Encode content in accordance of the `PubNub` service requirements. - * - * @param input - Source string or number for encoding. - * - * @returns Percent-encoded string. - */ -export declare const encodeString: (input: string | number) => string; -/** - * Percent-encode list of names (channels). - * - * @param names - List of names which should be encoded. - * - * @param [defaultString] - String which should be used in case if {@link names} is empty. - * - * @returns String which contains encoded names joined by non-encoded `,`. - */ -export declare const encodeNames: (names: string[], defaultString?: string) => string; -export declare const removeSingleOccurrence: (source: string[], elementsToRemove: string[]) => string[]; -export declare const findUniqueCommonElements: (a: string[], b: string[]) => string[]; -/** - * Transform query key / value pairs to the string. - * - * @param query - Key / value pairs of the request query parameters. - * - * @returns Stringified query key / value pairs. - */ -export declare const queryStringFromObject: (query: Query) => string; diff --git a/lib/types/crypto/index.d.ts b/lib/types/crypto/index.d.ts deleted file mode 100644 index e69de29bb..000000000 diff --git a/lib/types/crypto/modules/NodeCryptoModule/ICryptor.d.ts b/lib/types/crypto/modules/NodeCryptoModule/ICryptor.d.ts deleted file mode 100644 index 30a6c7bee..000000000 --- a/lib/types/crypto/modules/NodeCryptoModule/ICryptor.d.ts +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Cryptor module. - */ -/// -/// -/** - * Data encrypted by {@link CryptoModule}. - */ -export type EncryptedDataType = { - /** - * Encrypted data. - */ - data: Buffer | string; - /** - * Used cryptor's metadata. - */ - metadata: Buffer | null; -}; -/** - * {@link Readable} stream encrypted by {@link CryptoModule}. - */ -export type EncryptedStream = { - /** - * Stream with encrypted content. - */ - stream: NodeJS.ReadableStream; - /** - * Length of encrypted data in {@link Readable} stream. - */ - metadataLength: number; - /** - * Used cryptor's metadata. - */ - metadata?: Buffer | undefined; -}; -/** - * Cryptor algorithm interface. - */ -export interface ICryptor { - /** - * Cryptor unique identifier. - * - * @returns Cryptor identifier. - */ - get identifier(): string; - /** - * Encrypt provided source data. - * - * @param data - Source data for encryption. - * - * @returns Encrypted data object. - * - * @throws Error if unknown data type has been passed. - */ - encrypt(data: BufferSource | string): EncryptedDataType; - /** - * Encrypt provided source {@link Readable} stream. - * - * @param stream - Stream for encryption. - * - * @returns Encrypted stream object. - * - * @throws Error if unknown data type has been passed. - */ - encryptStream(stream: NodeJS.ReadableStream): Promise; - /** - * Decrypt provided encrypted data object. - * - * @param data - Encrypted data object for decryption. - * - * @returns Decrypted data. - * - * @throws Error if unknown data type has been passed. - */ - decrypt(data: EncryptedDataType): ArrayBuffer; - /** - * Decrypt provided encrypted stream object. - * - * @param stream - Encrypted stream object for decryption. - * - * @returns Decrypted data as {@link Readable} stream. - * - * @throws Error if unknown data type has been passed. - */ - decryptStream(stream: EncryptedStream): Promise; -} diff --git a/lib/types/crypto/modules/NodeCryptoModule/ILegacyCryptor.d.ts b/lib/types/crypto/modules/NodeCryptoModule/ILegacyCryptor.d.ts deleted file mode 100644 index 5b3ea2f2f..000000000 --- a/lib/types/crypto/modules/NodeCryptoModule/ILegacyCryptor.d.ts +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Legacy cryptor module. - */ -import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; -import { PubNubFileConstructor } from '../../../core/types/file'; -import { Payload } from '../../../core/types/api'; -import { EncryptedDataType } from './ICryptor'; -/** - * Legacy cryptor algorithm interface. - */ -export interface ILegacyCryptor { - /** - * Cryptor unique identifier. - */ - get identifier(): string; - /** - * Encrypt provided source data. - * - * @param data - Source data for encryption. - * - * @returns Encrypted data object. - * - * @throws Error if unknown data type has been passed. - */ - encrypt(data: string): EncryptedDataType; - /** - * Encrypt provided source {@link PubNub} File object. - * - * @param file - Source {@link PubNub} File object for encryption. - * @param File - Class constructor for {@link PubNub} File object. - * - * @returns Encrypted data as {@link PubNub} File object. - * - * @throws Error if file is empty or contains unsupported data type. - * @throws Error if cipher key not set. - */ - encryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; - /** - * Decrypt provided encrypted data object. - * - * @param data - Encrypted data object for decryption. - * - * @returns Decrypted data. - * - * @throws Error if unknown data type has been passed. - */ - decrypt(data: EncryptedDataType): Payload | null; - /** - * Decrypt provided encrypted {@link PubNub} File object. - * - * @param file - Encrypted {@link PubNub} File object for decryption. - * @param File - Class constructor for {@link PubNub} File object. - * - * @returns Decrypted data as {@link PubNub} File object. - * - * @throws Error if file is empty or contains unsupported data type. - * @throws Error if cipher key not set. - */ - decryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; -} diff --git a/lib/types/crypto/modules/NodeCryptoModule/aesCbcCryptor.d.ts b/lib/types/crypto/modules/NodeCryptoModule/aesCbcCryptor.d.ts deleted file mode 100644 index 875bd5d8f..000000000 --- a/lib/types/crypto/modules/NodeCryptoModule/aesCbcCryptor.d.ts +++ /dev/null @@ -1,57 +0,0 @@ -/** - * AES-CBC cryptor module. - */ -/// -/// -/// -import { PassThrough } from 'stream'; -import { ICryptor, EncryptedDataType, EncryptedStream } from './ICryptor'; -/** - * AES-CBC cryptor. - * - * AES-CBC cryptor with enhanced cipher strength. - */ -export default class AesCbcCryptor implements ICryptor { - /** - * Cryptor block size. - */ - static BLOCK_SIZE: number; - /** - * {@link string|String} to {@link ArrayBuffer} response decoder. - */ - static encoder: TextEncoder; - /** - * Data encryption / decryption cipher key. - */ - cipherKey: string; - constructor({ cipherKey }: { - cipherKey: string; - }); - encrypt(data: ArrayBuffer | string): EncryptedDataType; - encryptStream(stream: NodeJS.ReadableStream): Promise<{ - stream: PassThrough; - metadata: Buffer; - metadataLength: number; - }>; - decrypt(input: EncryptedDataType): ArrayBuffer; - decryptStream(stream: EncryptedStream): Promise; - get identifier(): string; - /** - * Cryptor algorithm. - * - * @returns Cryptor module algorithm. - */ - private get algo(); - /** - * Generate random initialization vector. - * - * @returns Random initialization vector. - */ - private getIv; - /** - * Convert cipher key to the {@link Buffer}. - * - * @returns SHA256 encoded cipher key {@link Buffer}. - */ - private getKey; -} diff --git a/lib/types/crypto/modules/NodeCryptoModule/legacyCryptor.d.ts b/lib/types/crypto/modules/NodeCryptoModule/legacyCryptor.d.ts deleted file mode 100644 index 006900d93..000000000 --- a/lib/types/crypto/modules/NodeCryptoModule/legacyCryptor.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Legacy cryptor module. - */ -import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; -import { CryptorConfiguration } from '../../../core/interfaces/crypto-module'; -import Crypto from '../../../core/components/cryptography/index'; -import { PubNubFileConstructor } from '../../../core/types/file'; -import { ILegacyCryptor } from './ILegacyCryptor'; -import { EncryptedDataType } from './ICryptor'; -import FileCryptor from '../node'; -/** - * Legacy cryptor. - */ -export default class LegacyCryptor implements ILegacyCryptor { - /** - * Legacy cryptor configuration. - */ - config: CryptorConfiguration; - /** - * Configured file cryptor. - */ - fileCryptor: FileCryptor; - /** - * Configured legacy cryptor. - */ - cryptor: Crypto; - constructor(config: CryptorConfiguration); - encrypt(data: string): EncryptedDataType; - encryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; - decrypt(encryptedData: EncryptedDataType): import("../../../core/types/api").Payload | null; - decryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; - get identifier(): string; -} diff --git a/lib/types/crypto/modules/NodeCryptoModule/nodeCryptoModule.d.ts b/lib/types/crypto/modules/NodeCryptoModule/nodeCryptoModule.d.ts deleted file mode 100644 index 53f627cad..000000000 --- a/lib/types/crypto/modules/NodeCryptoModule/nodeCryptoModule.d.ts +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Node.js crypto module. - */ -import { AbstractCryptoModule, CryptorConfiguration } from '../../../core/interfaces/crypto-module'; -import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; -import { PubNubFileConstructor } from '../../../core/types/file'; -import { ICryptor } from './ICryptor'; -import { ILegacyCryptor } from './ILegacyCryptor'; -import AesCbcCryptor from './aesCbcCryptor'; -import LegacyCryptor from './legacyCryptor'; -/** - * Re-export bundled cryptors. - */ -export { LegacyCryptor, AesCbcCryptor }; -/** - * Crypto module cryptors interface. - */ -type CryptorType = ICryptor | ILegacyCryptor; -/** - * CryptoModule for Node.js platform. - */ -export declare class CryptoModule extends AbstractCryptoModule { - /** - * {@link LegacyCryptor|Legacy} cryptor identifier. - */ - static LEGACY_IDENTIFIER: string; - static legacyCryptoModule(config: CryptorConfiguration): CryptoModule; - static aesCbcCryptoModule(config: CryptorConfiguration): CryptoModule; - /** - * Construct crypto module with `cryptor` as default for data encryption and decryption. - * - * @param defaultCryptor - Default cryptor for data encryption and decryption. - * - * @returns Crypto module with pre-configured default cryptor. - */ - static withDefaultCryptor(defaultCryptor: CryptorType): CryptoModule; - encrypt(data: ArrayBuffer | string): string | ArrayBuffer; - encryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; - decrypt(data: ArrayBuffer | string): ArrayBuffer | import("../../../core/types/api").Payload | null; - decryptFile(file: PubNubFile, File: PubNubFileConstructor): Promise; - /** - * Retrieve registered legacy cryptor. - * - * @returns Previously registered {@link ILegacyCryptor|legacy} cryptor. - * - * @throws Error if legacy cryptor not registered. - */ - private getLegacyCryptor; - /** - * Retrieve registered cryptor by its identifier. - * - * @param id - Unique cryptor identifier. - * - * @returns Registered cryptor with specified identifier. - * - * @throws Error if cryptor with specified {@link id} can't be found. - */ - private getCryptorFromId; - /** - * Retrieve cryptor by its identifier. - * - * @param header - Header with cryptor-defined data or raw cryptor identifier. - * - * @returns Cryptor which correspond to provided {@link header}. - */ - private getCryptor; - /** - * Create cryptor header data. - * - * @param encrypted - Encryption data object as source for header data. - * - * @returns Binary representation of the cryptor header data. - */ - private getHeaderData; - /** - * Merge two {@link ArrayBuffer} instances. - * - * @param ab1 - First {@link ArrayBuffer}. - * @param ab2 - Second {@link ArrayBuffer}. - * - * @returns Merged data as {@link ArrayBuffer}. - */ - private concatArrayBuffer; - /** - * {@link Readable} stream event handler. - * - * @param stream - Stream which can be used to read data for decryption. - * @param file - File object which has been created with {@link stream}. - * @param File - Class constructor for {@link PubNub} File object. - * - * @returns Decrypted data as {@link PubNub} File object. - * - * @throws Error if file is empty or contains unsupported data type. - */ - private onStreamReadable; - /** - * Decrypt {@link Readable} stream using legacy cryptor. - * - * @param stream - Stream which can be used to read data for decryption. - * @param file - File object which has been created with {@link stream}. - * @param File - Class constructor for {@link PubNub} File object. - * - * @returns Decrypted data as {@link PubNub} File object. - * - * @throws Error if file is empty or contains unsupported data type. - */ - private decryptLegacyFileStream; -} diff --git a/lib/types/crypto/modules/node.d.ts b/lib/types/crypto/modules/node.d.ts deleted file mode 100644 index 37384f2dc..000000000 --- a/lib/types/crypto/modules/node.d.ts +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Legacy Node.js cryptography module. - */ -/// -/// -import { Readable, PassThrough, Transform } from 'stream'; -import { Buffer } from 'buffer'; -import PubNubFile, { PubNubFileParameters } from '../../file/modules/node'; -import { Cryptography } from '../../core/interfaces/cryptography'; -import { PubNubFileConstructor } from '../../core/types/file'; -/** - * Legacy cryptography implementation for Node.js-based {@link PubNub} client. - */ -export default class NodeCryptography implements Cryptography { - /** - * Random initialization vector size. - */ - static IV_LENGTH: number; - encrypt(key: string, input: string | ArrayBuffer | Buffer | Readable): Promise; - /** - * Encrypt provided source {@link Buffer} using specific encryption {@link key}. - * - * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link Buffer}. - * @param buffer - Source {@link Buffer} for encryption. - * - * @returns Encrypted data as {@link Buffer} object. - */ - private encryptBuffer; - /** - * Encrypt provided source {@link Readable} stream using specific encryption {@link key}. - * - * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link Readable} stream. - * @param stream - Source {@link Readable} stream for encryption. - * - * @returns Encrypted data as {@link Transform} object. - */ - private encryptStream; - /** - * Encrypt provided source {@link string} using specific encryption {@link key}. - * - * @param key - Data encryption key.
**Note:** Same key should be used to `decrypt` {@link string}. - * @param text - Source {@link string} for encryption. - * - * @returns Encrypted data as byte {@link string}. - */ - private encryptString; - encryptFile(key: string, file: PubNubFile, File: PubNubFileConstructor): Promise; - decrypt(key: string, input: string | ArrayBuffer | Buffer | Readable): Promise; - /** - * Decrypt provided encrypted {@link Buffer} using specific decryption {@link key}. - * - * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link Buffer}. - * @param buffer - Encrypted {@link Buffer} for decryption. - * - * @returns Decrypted data as {@link Buffer} object. - */ - private decryptBuffer; - /** - * Decrypt provided encrypted {@link Readable} stream using specific decryption {@link key}. - * - * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link Readable} stream. - * @param stream - Encrypted {@link Readable} stream for decryption. - * - * @returns Decrypted data as {@link Readable} object. - */ - private decryptStream; - /** - * Decrypt provided encrypted {@link string} using specific decryption {@link key}. - * - * @param key - Data decryption key.
**Note:** Should be the same as used to `encrypt` {@link string}. - * @param text - Encrypted {@link string} for decryption. - * - * @returns Decrypted data as byte {@link string}. - */ - private decryptString; - decryptFile(key: string, file: PubNubFile, File: PubNubFileConstructor): Promise; - /** - * Cryptography algorithm. - * - * @returns Cryptography module algorithm. - */ - private get algo(); - /** - * Convert cipher key to the {@link Buffer}. - * - * @param key - String cipher key. - * - * @returns SHA256 HEX encoded cipher key {@link Buffer}. - */ - private getKey; - /** - * Generate random initialization vector. - * - * @returns Random initialization vector. - */ - private getIv; -} diff --git a/lib/types/entities/Channel.d.ts b/lib/types/entities/Channel.d.ts deleted file mode 100644 index fdeb23a76..000000000 --- a/lib/types/entities/Channel.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { PubNubCore as PubNub } from '../core/pubnub-common'; -import EventEmitter from '../core/components/eventEmitter'; -import { SubscriptionOptions } from './commonTypes'; -import { Subscription } from './Subscription'; -export declare class Channel { - private readonly eventEmitter; - private readonly pubnub; - private readonly name; - constructor(channelName: string, eventEmitter: EventEmitter, pubnub: PubNub); - subscription(subscriptionOptions?: SubscriptionOptions): Subscription; -} diff --git a/lib/types/entities/ChannelGroup.d.ts b/lib/types/entities/ChannelGroup.d.ts deleted file mode 100644 index a1c383d59..000000000 --- a/lib/types/entities/ChannelGroup.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { PubNubCore as PubNub } from '../core/pubnub-common'; -import EventEmitter from '../core/components/eventEmitter'; -import { SubscriptionOptions } from './commonTypes'; -import { Subscription } from './Subscription'; -export declare class ChannelGroup { - private readonly eventEmitter; - private readonly pubnub; - private readonly name; - constructor(channelGroup: string, eventEmitter: EventEmitter, pubnub: PubNub); - subscription(subscriptionOptions?: SubscriptionOptions): Subscription; -} diff --git a/lib/types/entities/ChannelMetadata.d.ts b/lib/types/entities/ChannelMetadata.d.ts deleted file mode 100644 index 101562ad0..000000000 --- a/lib/types/entities/ChannelMetadata.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { PubNubCore as PubNub } from '../core/pubnub-common'; -import EventEmitter from '../core/components/eventEmitter'; -import { SubscriptionOptions } from './commonTypes'; -import { Subscription } from './Subscription'; -export declare class ChannelMetadata { - private readonly id; - private readonly eventEmitter; - private readonly pubnub; - constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub); - subscription(subscriptionOptions?: SubscriptionOptions): Subscription; -} diff --git a/lib/types/entities/SubscribeCapable.d.ts b/lib/types/entities/SubscribeCapable.d.ts deleted file mode 100644 index 31229e1b2..000000000 --- a/lib/types/entities/SubscribeCapable.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { PubNubCore as PubNub } from '../core/pubnub-common'; -import { Listener } from '../core/components/listener_manager'; -import * as Subscription from '../core/types/api/subscription'; -import EventEmitter from '../core/components/eventEmitter'; -import { SubscriptionOptions } from './commonTypes'; -export declare abstract class SubscribeCapable { - protected abstract channelNames: string[]; - protected abstract groupNames: string[]; - protected abstract listener: Listener; - protected abstract eventEmitter: EventEmitter; - protected abstract pubnub: PubNub; - protected abstract options?: SubscriptionOptions; - subscribe(subscribeParameters?: { - timetoken?: string; - }): void; - unsubscribe(): void; - set onMessage(onMessageListener: (messageEvent: Subscription.Message) => void); - set onPresence(onPresenceListener: (presenceEvent: Subscription.Presence) => void); - set onSignal(onSignalListener: (signalEvent: Subscription.Signal) => void); - set onObjects(onObjectsListener: (objectsEvent: Subscription.AppContextObject) => void); - set onMessageAction(messageActionEventListener: (messageActionEvent: Subscription.MessageAction) => void); - set onFile(fileEventListener: (fileEvent: Subscription.File) => void); - addListener(listener: Listener): void; - removeListener(listener: Listener): void; - get channels(): string[]; - get channelGroups(): string[]; -} diff --git a/lib/types/entities/Subscription.d.ts b/lib/types/entities/Subscription.d.ts deleted file mode 100644 index ca7002a27..000000000 --- a/lib/types/entities/Subscription.d.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { PubNubCore as PubNub } from '../core/pubnub-common'; -import { Listener } from '../core/components/listener_manager'; -import EventEmitter from '../core/components/eventEmitter'; -import { SubscribeCapable } from './SubscribeCapable'; -import { SubscriptionOptions } from './commonTypes'; -import { SubscriptionSet } from './SubscriptionSet'; -export declare class Subscription extends SubscribeCapable { - protected channelNames: string[]; - protected groupNames: string[]; - protected options?: SubscriptionOptions; - protected pubnub: PubNub; - protected eventEmitter: EventEmitter; - protected listener: Listener; - constructor({ channels, channelGroups, subscriptionOptions, eventEmitter, pubnub, }: { - channels: string[]; - channelGroups: string[]; - subscriptionOptions?: SubscriptionOptions; - eventEmitter: EventEmitter; - pubnub: PubNub; - }); - addSubscription(subscription: Subscription): SubscriptionSet; -} diff --git a/lib/types/entities/SubscriptionSet.d.ts b/lib/types/entities/SubscriptionSet.d.ts deleted file mode 100644 index a7e0c2465..000000000 --- a/lib/types/entities/SubscriptionSet.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { PubNubCore as PubNub } from '../core/pubnub-common'; -import { Listener } from '../core/components/listener_manager'; -import EventEmitter from '../core/components/eventEmitter'; -import { SubscribeCapable } from './SubscribeCapable'; -import { SubscriptionOptions } from './commonTypes'; -import { Subscription } from './Subscription'; -export declare class SubscriptionSet extends SubscribeCapable { - protected channelNames: string[]; - protected groupNames: string[]; - protected options?: SubscriptionOptions; - protected pubnub: PubNub; - protected eventEmitter: EventEmitter; - protected subscriptionList: Subscription[]; - protected listener: Listener; - constructor({ channels, channelGroups, subscriptionOptions, eventEmitter, pubnub, }: { - channels?: string[]; - channelGroups?: string[]; - subscriptionOptions?: SubscriptionOptions; - eventEmitter: EventEmitter; - pubnub: PubNub; - }); - addSubscription(subscription: Subscription): void; - removeSubscription(subscription: Subscription): void; - addSubscriptionSet(subscriptionSet: SubscriptionSet): void; - removeSubscriptionSet(subscriptionSet: SubscriptionSet): void; - get subscriptions(): Subscription[]; -} diff --git a/lib/types/entities/UserMetadata.d.ts b/lib/types/entities/UserMetadata.d.ts deleted file mode 100644 index 354ef437d..000000000 --- a/lib/types/entities/UserMetadata.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import type { PubNubCore as PubNub } from '../core/pubnub-common'; -import EventEmitter from '../core/components/eventEmitter'; -import { SubscriptionOptions } from './commonTypes'; -import { Subscription } from './Subscription'; -export declare class UserMetadata { - private readonly id; - private readonly eventEmitter; - private readonly pubnub; - constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub); - subscription(subscriptionOptions?: SubscriptionOptions): Subscription; -} diff --git a/lib/types/entities/commonTypes.d.ts b/lib/types/entities/commonTypes.d.ts deleted file mode 100644 index c26e12f07..000000000 --- a/lib/types/entities/commonTypes.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -export type SubscriptionOptions = { - receivePresenceEvents?: boolean; -}; diff --git a/lib/types/errors/pubnub-api-error.d.ts b/lib/types/errors/pubnub-api-error.d.ts deleted file mode 100644 index 1b75e3be8..000000000 --- a/lib/types/errors/pubnub-api-error.d.ts +++ /dev/null @@ -1,73 +0,0 @@ -/** - * REST API endpoint use error module. - */ -import { TransportResponse } from '../core/types/transport-response'; -import RequestOperation from '../core/constants/operations'; -import StatusCategory from '../core/constants/categories'; -import { Payload, Status } from '../core/types/api'; -import { PubNubError } from './pubnub-error'; -/** - * PubNub REST API call error. - */ -export declare class PubNubAPIError extends Error { - readonly category: StatusCategory; - readonly statusCode: number; - readonly errorData?: Error | Payload | undefined; - /** - * Construct API from known error object or {@link PubNub} service error response. - * - * @param errorOrResponse - `Error` or service error response object from which error information - * should be extracted. - * @param data - Preprocessed service error response. - * - * @returns `PubNubAPIError` object with known error category and additional information (if - * available). - */ - static create(errorOrResponse: Error | TransportResponse, data?: ArrayBuffer): PubNubAPIError; - /** - * Create API error instance from other error object. - * - * @param error - `Error` object provided by network provider (mostly) or other {@link PubNub} client components. - * - * @returns `PubNubAPIError` object with known error category and additional information (if - * available). - */ - private static createFromError; - /** - * Construct API from known {@link PubNub} service error response. - * - * @param response - Service error response object from which error information should be - * extracted. - * @param data - Preprocessed service error response. - * - * @returns `PubNubAPIError` object with known error category and additional information (if - * available). - */ - private static createFromServiceResponse; - /** - * Construct PubNub endpoint error. - * - * @param message - Short API call error description. - * @param category - Error category. - * @param statusCode - Response HTTP status code. - * @param errorData - Error information. - */ - constructor(message: string, category: StatusCategory, statusCode: number, errorData?: Error | Payload | undefined); - /** - * Convert API error object to API callback status object. - * - * @param operation - Request operation during which error happened. - * - * @returns Pre-formatted API callback status object. - */ - toStatus(operation: RequestOperation): Status; - /** - * Convert API error object to PubNub client error object. - * - * @param operation - Request operation during which error happened. - * @param message - Custom error message. - * - * @returns Client-facing pre-formatted endpoint call error. - */ - toPubNubError(operation: RequestOperation, message?: string): PubNubError; -} diff --git a/lib/types/errors/pubnub-error.d.ts b/lib/types/errors/pubnub-error.d.ts deleted file mode 100644 index 549b195f9..000000000 --- a/lib/types/errors/pubnub-error.d.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Status } from '../core/types/api'; -export declare class PubNubError extends Error { - status?: Status | undefined; - constructor(message: string, status?: Status | undefined); -} -export declare function createValidationError(message: string, statusCode?: number): Status; diff --git a/lib/types/event-engine/core/change.d.ts b/lib/types/event-engine/core/change.d.ts deleted file mode 100644 index 7aaf7a029..000000000 --- a/lib/types/event-engine/core/change.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { State } from './state'; -import { EventTypeFromMap, GenericMap, InvocationTypeFromMap } from './types'; -export type EngineStarted = { - type: 'engineStarted'; - state: State; - context: any; -}; -export type EventReceived = { - type: 'eventReceived'; - event: EventTypeFromMap; -}; -export type TransitionDone = { - type: 'transitionDone'; - event: EventTypeFromMap; - fromState: State; - toState: State; - fromContext: any; - toContext: any; -}; -export type InvocationDispatched = { - type: 'invocationDispatched'; - invocation: InvocationTypeFromMap; -}; -export type Change = TransitionDone | InvocationDispatched | EngineStarted | EventReceived; diff --git a/lib/types/event-engine/core/dispatcher.d.ts b/lib/types/event-engine/core/dispatcher.d.ts deleted file mode 100644 index d70bc9359..000000000 --- a/lib/types/event-engine/core/dispatcher.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { Handler } from './handler'; -import { GenericInvocation, GenericMap, InvocationTypeFromMap } from './types'; -type HandlerCreator = (payload: Payload, dependencies: Dependencies) => Handler; -export declare class Dispatcher> { - private readonly dependencies; - constructor(dependencies: Dependencies); - private instances; - private handlers; - on(type: K, handlerCreator: HandlerCreator): void; - dispatch(invocation: Invocation): void; - dispose(): void; -} -export {}; diff --git a/lib/types/event-engine/core/engine.d.ts b/lib/types/event-engine/core/engine.d.ts deleted file mode 100644 index ba108d423..000000000 --- a/lib/types/event-engine/core/engine.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Subject } from '../../core/components/subject'; -import { Change } from './change'; -import { State } from './state'; -import { GenericMap, Event } from './types'; -export declare class Engine extends Subject> { - describe(label: string): State; - private currentState?; - private currentContext?; - start(initialState: State, initialContext: Context): void; - transition(event: Event): void; -} diff --git a/lib/types/event-engine/core/handler.d.ts b/lib/types/event-engine/core/handler.d.ts deleted file mode 100644 index c8a53c875..000000000 --- a/lib/types/event-engine/core/handler.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { AbortSignal } from '../../core/components/abort_signal'; -export declare abstract class Handler { - protected payload: Payload; - protected readonly dependencies: Dependencies; - constructor(payload: Payload, dependencies: Dependencies); - abstract start(): void; - abstract cancel(): void; -} -type AsyncHandlerFunction = (payload: Payload, abortSignal: AbortSignal, dependencies: Dependencies) => Promise; -declare class AsyncHandler extends Handler { - private asyncFunction; - abortSignal: AbortSignal; - constructor(payload: Payload, dependencies: Dependencies, asyncFunction: AsyncHandlerFunction); - start(): void; - cancel(): void; -} -export declare const asyncHandler: (handlerFunction: AsyncHandlerFunction) => (payload: Payload, dependencies: Dependencies) => AsyncHandler; -export {}; diff --git a/lib/types/event-engine/core/index.d.ts b/lib/types/event-engine/core/index.d.ts deleted file mode 100644 index b8eab6782..000000000 --- a/lib/types/event-engine/core/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export { Engine } from './engine'; -export { Dispatcher } from './dispatcher'; -export { MapOf, createEvent, createEffect, createManagedEffect } from './types'; -export { asyncHandler } from './handler'; diff --git a/lib/types/event-engine/core/retryPolicy.d.ts b/lib/types/event-engine/core/retryPolicy.d.ts deleted file mode 100644 index 5aed5de37..000000000 --- a/lib/types/event-engine/core/retryPolicy.d.ts +++ /dev/null @@ -1,58 +0,0 @@ -import { PubNubError } from '../../errors/pubnub-error'; -export declare class RetryPolicy { - static LinearRetryPolicy(configuration: LinearRetryPolicyConfiguration): RequestRetryPolicy & LinearRetryPolicyConfiguration; - static ExponentialRetryPolicy(configuration: ExponentialRetryPolicyConfiguration): RequestRetryPolicy & ExponentialRetryPolicyConfiguration; -} -export type RequestRetryPolicy = { - /** - * Check whether failed request can be retried. - * - * @param reason - Request processing failure reason. - * @param attempt - Number of consequent failure. - * - * @returns `true` if another request retry attempt can be done. - */ - shouldRetry(reason: PubNubError & { - retryAfter?: number; - }, attempt: number): boolean; - /** - * Computed delay for next request retry attempt. - * - * @param attempt - Number of consequent failure. - * @param reason - Request processing failure reason. - * - * @returns Delay before next request retry attempt in milliseconds. - */ - getDelay(attempt: number, reason: PubNubError & { - retryAfter?: number; - }): number; - /** - * Identify reason why another retry attempt can't be made. - * - * @param reason - Request processing failure reason. - * @param attempt - Number of consequent failure. - * - * @returns Give up reason. - */ - getGiveupReason(reason: PubNubError & { - retryAfter?: number; - }, attempt: number): string; - /** - * Validate retry policy parameters. - * - * @throws Error if `minimum` delay is smaller than 2 seconds for `exponential` retry policy. - * @throws Error if `maximum` delay is larger than 150 seconds for `exponential` retry policy. - * @throws Error if `maximumRetry` attempts is larger than 6 for `exponential` retry policy. - * @throws Error if `maximumRetry` attempts is larger than 10 for `linear` retry policy. - */ - validate(): void; -}; -export type LinearRetryPolicyConfiguration = { - delay: number; - maximumRetry: number; -}; -export type ExponentialRetryPolicyConfiguration = { - minimumDelay: number; - maximumDelay: number; - maximumRetry: number; -}; diff --git a/lib/types/event-engine/core/state.d.ts b/lib/types/event-engine/core/state.d.ts deleted file mode 100644 index 59b3bb534..000000000 --- a/lib/types/event-engine/core/state.d.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { Event, EventOfType, GenericInvocation, GenericMap, InvocationTypeFromMap } from './types'; -export type TransitionFunction> = { - (context: Context, event: EventType): Transition | void; -}; -export type Transition = [ - State, - Context, - InvocationTypeFromMap[] -]; -export declare class State { - label: string; - private transitionMap; - transition(context: Context, event: EventOfType): void | Transition; - constructor(label: string); - on(eventType: K, transition: TransitionFunction>): this; - with(context: Context, effects?: InvocationTypeFromMap[]): Transition; - enterEffects: ((context: Context) => InvocationTypeFromMap)[]; - exitEffects: ((context: Context) => InvocationTypeFromMap)[]; - onEnter(effect: (context: Context) => GenericInvocation): this; - onExit(effect: (context: Context) => GenericInvocation): this; -} diff --git a/lib/types/event-engine/core/types.d.ts b/lib/types/event-engine/core/types.d.ts deleted file mode 100644 index 14524f0ec..000000000 --- a/lib/types/event-engine/core/types.d.ts +++ /dev/null @@ -1,45 +0,0 @@ -export type Event = { - type: T; - payload: P; -}; -export type Invocation = { - type: T; - payload: P; - managed: boolean; -}; -export type GenericEvent = Event; -export type GenericInvocation = Invocation; -export type GenericMap = Record; -export type EventTypeFromMap = { - [T in keyof Map & string]: Event; -}[keyof Map & string]; -export type InvocationTypeFromMap = { - [T in keyof Map & string]: Invocation; -}[keyof Map & string]; -export type EventOfType = Event; -export type InvocationOfType = Invocation; -type EventCreator = { - (...args: S): Event; - type: K; -}; -export declare function createEvent(type: K, fn: (...args: S) => P): EventCreator; -export type MapOf { - type: string | number | symbol; - payload: any; -}> = { - [K in ReturnType['type']]: (ReturnType & { - type: K; - })['payload']; -}; -type EffectCreator = { - (...args: S): Invocation; - type: K; -}; -type ManagedEffectCreator = { - (...args: S): Invocation; - type: K; - cancel: Invocation<'CANCEL', K>; -}; -export declare function createEffect(type: K, fn: (...args: S) => P): EffectCreator; -export declare function createManagedEffect(type: K, fn: (...args: S) => P): ManagedEffectCreator; -export {}; diff --git a/lib/types/event-engine/dispatcher.d.ts b/lib/types/event-engine/dispatcher.d.ts deleted file mode 100644 index b2afbeb72..000000000 --- a/lib/types/event-engine/dispatcher.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { PrivateClientConfiguration } from '../core/interfaces/configuration'; -import * as Subscription from '../core/types/api/subscription'; -import { Dispatcher, Engine } from './core'; -import * as effects from './effects'; -import * as events from './events'; -import { Payload, StatusEvent } from '../core/types/api'; -export type Dependencies = { - handshake: (parameters: Subscription.CancelableSubscribeParameters) => Promise; - receiveMessages: (parameters: Subscription.CancelableSubscribeParameters) => Promise; - join?: (parameters: { - channels?: string[]; - groups?: string[]; - }) => void; - leave?: (parameters: { - channels?: string[]; - groups?: string[]; - }) => void; - leaveAll?: () => void; - presenceState: Record; - config: PrivateClientConfiguration; - delay: (milliseconds: number) => Promise; - emitMessages: (events: Subscription.SubscriptionResponse['messages']) => void; - emitStatus: (status: StatusEvent) => void; -}; -export declare class EventEngineDispatcher extends Dispatcher { - constructor(engine: Engine, dependencies: Dependencies); -} diff --git a/lib/types/event-engine/effects.d.ts b/lib/types/event-engine/effects.d.ts deleted file mode 100644 index 803ce383b..000000000 --- a/lib/types/event-engine/effects.d.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { MapOf } from './core'; -import { HandshakeReconnectingStateContext } from './states/handshake_reconnecting'; -import { ReceiveReconnectingStateContext } from './states/receive_reconnecting'; -import * as Subscription from '../core/types/api/subscription'; -import { StatusEvent } from '../core/types/api'; -export declare const handshake: { - (channels: string[], groups: string[]): import("./core/types").Invocation<"HANDSHAKE", { - channels: string[]; - groups: string[]; - }>; - type: "HANDSHAKE"; - cancel: import("./core/types").Invocation<"CANCEL", "HANDSHAKE">; -}; -export declare const receiveMessages: { - (channels: string[], groups: string[], cursor: Subscription.SubscriptionCursor): import("./core/types").Invocation<"RECEIVE_MESSAGES", { - channels: string[]; - groups: string[]; - cursor: Subscription.SubscriptionCursor; - }>; - type: "RECEIVE_MESSAGES"; - cancel: import("./core/types").Invocation<"CANCEL", "RECEIVE_MESSAGES">; -}; -export declare const emitMessages: { - (events: ({ - type: import("../core/endpoints/subscribe").PubNubEventType.Presence; - data: Subscription.Presence; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Message; - data: Subscription.Message; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Signal; - data: Subscription.Signal; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; - data: Subscription.MessageAction; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; - data: Subscription.AppContextObject; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Files; - data: Subscription.File; - })[]): import("./core/types").Invocation<"EMIT_MESSAGES", ({ - type: import("../core/endpoints/subscribe").PubNubEventType.Presence; - data: Subscription.Presence; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Message; - data: Subscription.Message; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Signal; - data: Subscription.Signal; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; - data: Subscription.MessageAction; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; - data: Subscription.AppContextObject; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Files; - data: Subscription.File; - })[]>; - type: "EMIT_MESSAGES"; -}; -export declare const emitStatus: { - (status: StatusEvent): import("./core/types").Invocation<"EMIT_STATUS", StatusEvent>; - type: "EMIT_STATUS"; -}; -export declare const receiveReconnect: { - (context: ReceiveReconnectingStateContext): import("./core/types").Invocation<"RECEIVE_RECONNECT", ReceiveReconnectingStateContext>; - type: "RECEIVE_RECONNECT"; - cancel: import("./core/types").Invocation<"CANCEL", "RECEIVE_RECONNECT">; -}; -export declare const handshakeReconnect: { - (context: HandshakeReconnectingStateContext): import("./core/types").Invocation<"HANDSHAKE_RECONNECT", HandshakeReconnectingStateContext>; - type: "HANDSHAKE_RECONNECT"; - cancel: import("./core/types").Invocation<"CANCEL", "HANDSHAKE_RECONNECT">; -}; -export type Effects = MapOf; diff --git a/lib/types/event-engine/events.d.ts b/lib/types/event-engine/events.d.ts deleted file mode 100644 index 98418cab9..000000000 --- a/lib/types/event-engine/events.d.ts +++ /dev/null @@ -1,159 +0,0 @@ -import * as Subscription from '../core/types/api/subscription'; -import { PubNubError } from '../errors/pubnub-error'; -import { MapOf } from './core'; -export declare const subscriptionChange: { - (channels: string[], groups: string[]): import("./core/types").Event<"SUBSCRIPTION_CHANGED", { - channels: string[]; - groups: string[]; - }>; - type: "SUBSCRIPTION_CHANGED"; -}; -export declare const restore: { - (channels: string[], groups: string[], timetoken: string | number, region?: number | undefined): import("./core/types").Event<"SUBSCRIPTION_RESTORED", { - channels: string[]; - groups: string[]; - cursor: { - timetoken: string | number; - region: number; - }; - }>; - type: "SUBSCRIPTION_RESTORED"; -}; -export declare const handshakeSuccess: { - (cursor: Subscription.SubscriptionCursor): import("./core/types").Event<"HANDSHAKE_SUCCESS", Subscription.SubscriptionCursor>; - type: "HANDSHAKE_SUCCESS"; -}; -export declare const handshakeFailure: { - (error: PubNubError): import("./core/types").Event<"HANDSHAKE_FAILURE", PubNubError>; - type: "HANDSHAKE_FAILURE"; -}; -export declare const handshakeReconnectSuccess: { - (cursor: Subscription.SubscriptionCursor): import("./core/types").Event<"HANDSHAKE_RECONNECT_SUCCESS", { - cursor: Subscription.SubscriptionCursor; - }>; - type: "HANDSHAKE_RECONNECT_SUCCESS"; -}; -export declare const handshakeReconnectFailure: { - (error: PubNubError): import("./core/types").Event<"HANDSHAKE_RECONNECT_FAILURE", PubNubError>; - type: "HANDSHAKE_RECONNECT_FAILURE"; -}; -export declare const handshakeReconnectGiveup: { - (error: PubNubError): import("./core/types").Event<"HANDSHAKE_RECONNECT_GIVEUP", PubNubError>; - type: "HANDSHAKE_RECONNECT_GIVEUP"; -}; -export declare const receiveSuccess: { - (cursor: Subscription.SubscriptionCursor, events: ({ - type: import("../core/endpoints/subscribe").PubNubEventType.Presence; - data: Subscription.Presence; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Message; - data: Subscription.Message; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Signal; - data: Subscription.Signal; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; - data: Subscription.MessageAction; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; - data: Subscription.AppContextObject; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Files; - data: Subscription.File; - })[]): import("./core/types").Event<"RECEIVE_SUCCESS", { - cursor: Subscription.SubscriptionCursor; - events: ({ - type: import("../core/endpoints/subscribe").PubNubEventType.Presence; - data: Subscription.Presence; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Message; - data: Subscription.Message; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Signal; - data: Subscription.Signal; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; - data: Subscription.MessageAction; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; - data: Subscription.AppContextObject; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Files; - data: Subscription.File; - })[]; - }>; - type: "RECEIVE_SUCCESS"; -}; -export declare const receiveFailure: { - (error: PubNubError): import("./core/types").Event<"RECEIVE_FAILURE", PubNubError>; - type: "RECEIVE_FAILURE"; -}; -export declare const receiveReconnectSuccess: { - (cursor: Subscription.SubscriptionCursor, events: ({ - type: import("../core/endpoints/subscribe").PubNubEventType.Presence; - data: Subscription.Presence; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Message; - data: Subscription.Message; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Signal; - data: Subscription.Signal; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; - data: Subscription.MessageAction; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; - data: Subscription.AppContextObject; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Files; - data: Subscription.File; - })[]): import("./core/types").Event<"RECEIVE_RECONNECT_SUCCESS", { - cursor: Subscription.SubscriptionCursor; - events: ({ - type: import("../core/endpoints/subscribe").PubNubEventType.Presence; - data: Subscription.Presence; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Message; - data: Subscription.Message; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Signal; - data: Subscription.Signal; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.MessageAction; - data: Subscription.MessageAction; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.AppContext; - data: Subscription.AppContextObject; - } | { - type: import("../core/endpoints/subscribe").PubNubEventType.Files; - data: Subscription.File; - })[]; - }>; - type: "RECEIVE_RECONNECT_SUCCESS"; -}; -export declare const receiveReconnectFailure: { - (error: PubNubError): import("./core/types").Event<"RECEIVE_RECONNECT_FAILURE", PubNubError>; - type: "RECEIVE_RECONNECT_FAILURE"; -}; -export declare const receiveReconnectGiveup: { - (error: PubNubError): import("./core/types").Event<"RECEIVING_RECONNECT_GIVEUP", PubNubError>; - type: "RECEIVING_RECONNECT_GIVEUP"; -}; -export declare const disconnect: { - (): import("./core/types").Event<"DISCONNECT", {}>; - type: "DISCONNECT"; -}; -export declare const reconnect: { - (timetoken?: string | undefined, region?: number | undefined): import("./core/types").Event<"RECONNECT", { - cursor: { - timetoken: string; - region: number; - }; - }>; - type: "RECONNECT"; -}; -export declare const unsubscribeAll: { - (): import("./core/types").Event<"UNSUBSCRIBE_ALL", {}>; - type: "UNSUBSCRIBE_ALL"; -}; -export type Events = MapOf; diff --git a/lib/types/event-engine/index.d.ts b/lib/types/event-engine/index.d.ts deleted file mode 100644 index 2542bfa3b..000000000 --- a/lib/types/event-engine/index.d.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { Engine } from './core'; -import { Dependencies } from './dispatcher'; -import * as effects from './effects'; -import * as events from './events'; -export declare class EventEngine { - private engine; - private dispatcher; - private dependencies; - get _engine(): Engine; - private readonly _unsubscribeEngine; - constructor(dependencies: Dependencies); - channels: string[]; - groups: string[]; - subscribe({ channels, channelGroups, timetoken, withPresence, }: { - channels?: string[]; - channelGroups?: string[]; - timetoken?: string | number; - withPresence?: boolean; - }): void; - unsubscribe({ channels, channelGroups }: { - channels?: string[]; - channelGroups?: string[]; - }): void; - unsubscribeAll(): void; - reconnect({ timetoken, region }: { - timetoken?: string; - region?: number; - }): void; - disconnect(): void; - getSubscribedChannels(): string[]; - getSubscribedChannelGroups(): string[]; - dispose(): void; -} diff --git a/lib/types/event-engine/presence/dispatcher.d.ts b/lib/types/event-engine/presence/dispatcher.d.ts deleted file mode 100644 index 9fdf3de45..000000000 --- a/lib/types/event-engine/presence/dispatcher.d.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { PrivateClientConfiguration } from '../../core/interfaces/configuration'; -import { Dispatcher, Engine } from '../core'; -import * as Presence from '../../core/types/api/presence'; -import { Payload, ResultCallback } from '../../core/types/api'; -import * as effects from './effects'; -import * as events from './events'; -export type Dependencies = { - heartbeat: (parameters: Presence.PresenceHeartbeatParameters, callback?: ResultCallback) => Promise; - leave: (parameters: Presence.PresenceLeaveParameters) => void; - heartbeatDelay: () => Promise; - retryDelay: (milliseconds: number) => Promise; - config: PrivateClientConfiguration; - presenceState: Record; - emitStatus: (status: any) => void; -}; -export declare class PresenceEventEngineDispatcher extends Dispatcher { - constructor(engine: Engine, dependencies: Dependencies); -} diff --git a/lib/types/event-engine/presence/effects.d.ts b/lib/types/event-engine/presence/effects.d.ts deleted file mode 100644 index a905c6835..000000000 --- a/lib/types/event-engine/presence/effects.d.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { MapOf } from '../core'; -import { HeartbeatReconnectingStateContext } from './states/heartbeat_reconnecting'; -export declare const heartbeat: { - (channels: string[], groups: string[]): import("../core/types").Invocation<"HEARTBEAT", { - channels: string[]; - groups: string[]; - }>; - type: "HEARTBEAT"; -}; -export declare const leave: { - (channels: string[], groups: string[]): import("../core/types").Invocation<"LEAVE", { - channels: string[]; - groups: string[]; - }>; - type: "LEAVE"; -}; -export declare const emitStatus: { - (status: any): import("../core/types").Invocation<"EMIT_STATUS", any>; - type: "EMIT_STATUS"; -}; -export declare const wait: { - (): import("../core/types").Invocation<"WAIT", {}>; - type: "WAIT"; - cancel: import("../core/types").Invocation<"CANCEL", "WAIT">; -}; -export declare const delayedHeartbeat: { - (context: HeartbeatReconnectingStateContext): import("../core/types").Invocation<"DELAYED_HEARTBEAT", HeartbeatReconnectingStateContext>; - type: "DELAYED_HEARTBEAT"; - cancel: import("../core/types").Invocation<"CANCEL", "DELAYED_HEARTBEAT">; -}; -export type Effects = MapOf; diff --git a/lib/types/event-engine/presence/events.d.ts b/lib/types/event-engine/presence/events.d.ts deleted file mode 100644 index cfceec153..000000000 --- a/lib/types/event-engine/presence/events.d.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { PubNubError } from '../../errors/pubnub-error'; -import { MapOf } from '../core'; -export declare const reconnect: { - (): import("../core/types").Event<"RECONNECT", {}>; - type: "RECONNECT"; -}; -export declare const disconnect: { - (): import("../core/types").Event<"DISCONNECT", {}>; - type: "DISCONNECT"; -}; -export declare const joined: { - (channels: string[], groups: string[]): import("../core/types").Event<"JOINED", { - channels: string[]; - groups: string[]; - }>; - type: "JOINED"; -}; -export declare const left: { - (channels: string[], groups: string[]): import("../core/types").Event<"LEFT", { - channels: string[]; - groups: string[]; - }>; - type: "LEFT"; -}; -export declare const leftAll: { - (): import("../core/types").Event<"LEFT_ALL", {}>; - type: "LEFT_ALL"; -}; -export declare const heartbeatSuccess: { - (statusCode: number): import("../core/types").Event<"HEARTBEAT_SUCCESS", { - statusCode: number; - }>; - type: "HEARTBEAT_SUCCESS"; -}; -export declare const heartbeatFailure: { - (error: PubNubError): import("../core/types").Event<"HEARTBEAT_FAILURE", PubNubError>; - type: "HEARTBEAT_FAILURE"; -}; -export declare const heartbeatGiveup: { - (): import("../core/types").Event<"HEARTBEAT_GIVEUP", {}>; - type: "HEARTBEAT_GIVEUP"; -}; -export declare const timesUp: { - (): import("../core/types").Event<"TIMES_UP", {}>; - type: "TIMES_UP"; -}; -export type Events = MapOf; diff --git a/lib/types/event-engine/presence/presence.d.ts b/lib/types/event-engine/presence/presence.d.ts deleted file mode 100644 index 42f82e750..000000000 --- a/lib/types/event-engine/presence/presence.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { Engine } from '../core'; -import * as events from './events'; -import * as effects from './effects'; -import { Dependencies } from './dispatcher'; -export declare class PresenceEventEngine { - private dependencies; - private engine; - private dispatcher; - get _engine(): Engine; - private _unsubscribeEngine; - constructor(dependencies: Dependencies); - channels: string[]; - groups: string[]; - join({ channels, groups }: { - channels?: string[]; - groups?: string[]; - }): void; - leave({ channels, groups }: { - channels?: string[]; - groups?: string[]; - }): void; - leaveAll(): void; - dispose(): void; -} diff --git a/lib/types/event-engine/presence/states/heartbeat_cooldown.d.ts b/lib/types/event-engine/presence/states/heartbeat_cooldown.d.ts deleted file mode 100644 index 6b2273d2b..000000000 --- a/lib/types/event-engine/presence/states/heartbeat_cooldown.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { State } from '../../core/state'; -import { Events } from '../events'; -import { Effects } from '../effects'; -export type HeartbeatCooldownStateContext = { - channels: string[]; - groups: string[]; -}; -export declare const HeartbeatCooldownState: State; diff --git a/lib/types/event-engine/presence/states/heartbeat_failed.d.ts b/lib/types/event-engine/presence/states/heartbeat_failed.d.ts deleted file mode 100644 index dce365993..000000000 --- a/lib/types/event-engine/presence/states/heartbeat_failed.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { State } from '../../core/state'; -import { Events } from '../events'; -import { Effects } from '../effects'; -export type HeartbeatFailedStateContext = { - channels: string[]; - groups: string[]; -}; -export declare const HeartbeatFailedState: State; diff --git a/lib/types/event-engine/presence/states/heartbeat_inactive.d.ts b/lib/types/event-engine/presence/states/heartbeat_inactive.d.ts deleted file mode 100644 index d39ebfb4f..000000000 --- a/lib/types/event-engine/presence/states/heartbeat_inactive.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { State } from '../../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -export declare const HeartbeatInactiveState: State; diff --git a/lib/types/event-engine/presence/states/heartbeat_reconnecting.d.ts b/lib/types/event-engine/presence/states/heartbeat_reconnecting.d.ts deleted file mode 100644 index 3a3044a0b..000000000 --- a/lib/types/event-engine/presence/states/heartbeat_reconnecting.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { PubNubError } from '../../../errors/pubnub-error'; -import { State } from '../../core/state'; -import { Events } from '../events'; -import { Effects } from '../effects'; -export type HeartbeatReconnectingStateContext = { - channels: string[]; - groups: string[]; - attempts: number; - reason: PubNubError; -}; -export declare const HearbeatReconnectingState: State; diff --git a/lib/types/event-engine/presence/states/heartbeat_stopped.d.ts b/lib/types/event-engine/presence/states/heartbeat_stopped.d.ts deleted file mode 100644 index 9df101a87..000000000 --- a/lib/types/event-engine/presence/states/heartbeat_stopped.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { State } from '../../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -export type HeartbeatStoppedStateContext = { - channels: string[]; - groups: string[]; -}; -export declare const HeartbeatStoppedState: State; diff --git a/lib/types/event-engine/presence/states/heartbeating.d.ts b/lib/types/event-engine/presence/states/heartbeating.d.ts deleted file mode 100644 index 57bc59f8f..000000000 --- a/lib/types/event-engine/presence/states/heartbeating.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { State } from '../../core/state'; -import { Events } from '../events'; -import { Effects } from '../effects'; -export type HeartbeatingStateContext = { - channels: string[]; - groups: string[]; -}; -export declare const HeartbeatingState: State; diff --git a/lib/types/event-engine/states/handshake_failed.d.ts b/lib/types/event-engine/states/handshake_failed.d.ts deleted file mode 100644 index be8769ab6..000000000 --- a/lib/types/event-engine/states/handshake_failed.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { State } from '../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -import { PubNubError } from '../../errors/pubnub-error'; -import * as Subscription from '../../core/types/api/subscription'; -export type HandshakeFailedStateContext = { - channels: string[]; - groups: string[]; - cursor?: Subscription.SubscriptionCursor; - reason: PubNubError; -}; -export declare const HandshakeFailedState: State; diff --git a/lib/types/event-engine/states/handshake_reconnecting.d.ts b/lib/types/event-engine/states/handshake_reconnecting.d.ts deleted file mode 100644 index ed2817320..000000000 --- a/lib/types/event-engine/states/handshake_reconnecting.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { PubNubError } from '../../errors/pubnub-error'; -import { State } from '../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -import * as Subscription from '../../core/types/api/subscription'; -export type HandshakeReconnectingStateContext = { - channels: string[]; - groups: string[]; - cursor?: Subscription.SubscriptionCursor; - attempts: number; - reason: PubNubError; -}; -export declare const HandshakeReconnectingState: State; diff --git a/lib/types/event-engine/states/handshake_stopped.d.ts b/lib/types/event-engine/states/handshake_stopped.d.ts deleted file mode 100644 index 40ffa7c4c..000000000 --- a/lib/types/event-engine/states/handshake_stopped.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { State } from '../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -import * as Subscription from '../../core/types/api/subscription'; -type HandshakeStoppedStateContext = { - channels: string[]; - groups: string[]; - cursor?: Subscription.SubscriptionCursor; -}; -export declare const HandshakeStoppedState: State; -export {}; diff --git a/lib/types/event-engine/states/handshaking.d.ts b/lib/types/event-engine/states/handshaking.d.ts deleted file mode 100644 index cff30ca43..000000000 --- a/lib/types/event-engine/states/handshaking.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { State } from '../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -import * as Subscription from '../../core/types/api/subscription'; -export type HandshakingStateContext = { - channels: string[]; - groups: string[]; - cursor?: Subscription.SubscriptionCursor; -}; -export declare const HandshakingState: State; diff --git a/lib/types/event-engine/states/receive_failed.d.ts b/lib/types/event-engine/states/receive_failed.d.ts deleted file mode 100644 index 925a8f857..000000000 --- a/lib/types/event-engine/states/receive_failed.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { State } from '../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -import { PubNubError } from '../../errors/pubnub-error'; -import * as Subscription from '../../core/types/api/subscription'; -export type ReceiveFailedStateContext = { - channels: string[]; - groups: string[]; - cursor: Subscription.SubscriptionCursor; - reason: PubNubError; -}; -export declare const ReceiveFailedState: State; diff --git a/lib/types/event-engine/states/receive_reconnecting.d.ts b/lib/types/event-engine/states/receive_reconnecting.d.ts deleted file mode 100644 index 399e76ada..000000000 --- a/lib/types/event-engine/states/receive_reconnecting.d.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { PubNubError } from '../../errors/pubnub-error'; -import { State } from '../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -import * as Subscription from '../../core/types/api/subscription'; -export type ReceiveReconnectingStateContext = { - channels: string[]; - groups: string[]; - cursor: Subscription.SubscriptionCursor; - attempts: number; - reason: PubNubError; -}; -export declare const ReceiveReconnectingState: State; diff --git a/lib/types/event-engine/states/receive_stopped.d.ts b/lib/types/event-engine/states/receive_stopped.d.ts deleted file mode 100644 index 85a3986be..000000000 --- a/lib/types/event-engine/states/receive_stopped.d.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { State } from '../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -import * as Subscription from '../../core/types/api/subscription'; -type ReceiveStoppedStateContext = { - channels: string[]; - groups: string[]; - cursor: Subscription.SubscriptionCursor; -}; -export declare const ReceiveStoppedState: State; -export {}; diff --git a/lib/types/event-engine/states/receiving.d.ts b/lib/types/event-engine/states/receiving.d.ts deleted file mode 100644 index 221353f4f..000000000 --- a/lib/types/event-engine/states/receiving.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { State } from '../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -import * as Subscription from '../../core/types/api/subscription'; -export type ReceivingStateContext = { - channels: string[]; - groups: string[]; - cursor: Subscription.SubscriptionCursor; -}; -export declare const ReceivingState: State; diff --git a/lib/types/event-engine/states/unsubscribed.d.ts b/lib/types/event-engine/states/unsubscribed.d.ts deleted file mode 100644 index ad8a2f25a..000000000 --- a/lib/types/event-engine/states/unsubscribed.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { State } from '../core/state'; -import { Effects } from '../effects'; -import { Events } from '../events'; -export declare const UnsubscribedState: State; diff --git a/lib/types/file/modules/node.d.ts b/lib/types/file/modules/node.d.ts deleted file mode 100644 index 344f76fe5..000000000 --- a/lib/types/file/modules/node.d.ts +++ /dev/null @@ -1,134 +0,0 @@ -/** - * Node.js {@link PubNub} File object module. - */ -/// -/// -import { Readable, PassThrough } from 'stream'; -import { Buffer } from 'buffer'; -import { PubNubFileInterface } from '../../core/types/file'; -/** - * PubNub File instance creation parameters. - */ -export type PubNubFileParameters = { - /** - * Readable stream represents file object content. - */ - stream?: Readable; - /** - * Buffer or string represents file object content. - */ - data?: Buffer | ArrayBuffer | string; - /** - * String {@link PubNubFileParameters#data|data} encoding. - * - * @default `utf8` - */ - encoding?: StringEncoding; - /** - * File object name. - */ - name: string; - /** - * File object content type. - */ - mimeType?: string; -}; -/** - * Node.js implementation for {@link PubNub} File object. - * - * **Important:** Class should implement constructor and class fields from {@link PubNubFileConstructor}. - */ -export default class PubNubFile implements PubNubFileInterface { - /** - * Whether {@link Blob} data supported by platform or not. - */ - static supportsBlob: boolean; - /** - * Whether {@link File} data supported by platform or not. - */ - static supportsFile: boolean; - /** - * Whether {@link Buffer} data supported by platform or not. - */ - static supportsBuffer: boolean; - /** - * Whether {@link Stream} data supported by platform or not. - */ - static supportsStream: boolean; - /** - * Whether {@link String} data supported by platform or not. - */ - static supportsString: boolean; - /** - * Whether {@link ArrayBuffer} supported by platform or not. - */ - static supportsArrayBuffer: boolean; - /** - * Whether {@link PubNub} File object encryption supported or not. - */ - static supportsEncryptFile: boolean; - /** - * Whether `File Uri` data supported by platform or not. - */ - static supportsFileUri: boolean; - /** - * File object content source. - */ - readonly data: Readable | Buffer; - /** - * File object content length. - */ - contentLength?: number; - /** - * File object content type. - */ - mimeType: string; - /** - * File object name. - */ - name: string; - static create(file: PubNubFileParameters): PubNubFile; - constructor(file: PubNubFileParameters); - /** - * Convert {@link PubNub} File object content to {@link Buffer}. - * - * @returns Asynchronous results of conversion to the {@link Buffer}. - */ - toBuffer(): Promise; - /** - * Convert {@link PubNub} File object content to {@link ArrayBuffer}. - * - * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. - */ - toArrayBuffer(): Promise; - /** - * Convert {@link PubNub} File object content to {@link string}. - * - * @returns Asynchronous results of conversion to the {@link string}. - */ - toString(encoding?: BufferEncoding): Promise; - /** - * Convert {@link PubNub} File object content to {@link Readable} stream. - * - * @returns Asynchronous results of conversion to the {@link Readable} stream. - */ - toStream(): Promise; - /** - * Convert {@link PubNub} File object content to {@link File}. - * - * @throws Error because {@link File} not available in Node.js environment. - */ - toFile(): Promise; - /** - * Convert {@link PubNub} File object content to file `Uri`. - * - * @throws Error because file `Uri` not available in Node.js environment. - */ - toFileUri(): Promise>; - /** - * Convert {@link PubNub} File object content to {@link Blob}. - * - * @throws Error because {@link Blob} not available in Node.js environment. - */ - toBlob(): Promise; -} diff --git a/lib/types/file/modules/react-native.d.ts b/lib/types/file/modules/react-native.d.ts deleted file mode 100644 index 51531b6ea..000000000 --- a/lib/types/file/modules/react-native.d.ts +++ /dev/null @@ -1,135 +0,0 @@ -/** - * React Native {@link PubNub} File object module. - */ -import { PubNubFileInterface } from '../../core/types/file'; -/** - * File path-based file. - */ -type FileUri = { - uri: string; - name: string; - mimeType?: string; -}; -/** - * Asynchronously fetched file content. - */ -type ReadableFile = { - arrayBuffer: () => Promise; - blob: () => Promise; - text: () => Promise; -}; -/** - * PubNub File instance creation parameters. - */ -export type PubNubFileParameters = File | FileUri | ReadableFile | { - data: string | Blob | ArrayBuffer | ArrayBufferView; - name: string; - mimeType?: string; -}; -export declare class PubNubFile implements PubNubFileInterface { - /** - * Whether {@link Blob} data supported by platform or not. - */ - static supportsBlob: boolean; - /** - * Whether {@link File} data supported by platform or not. - */ - static supportsFile: boolean; - /** - * Whether {@link Buffer} data supported by platform or not. - */ - static supportsBuffer: boolean; - /** - * Whether {@link Stream} data supported by platform or not. - */ - static supportsStream: boolean; - /** - * Whether {@link String} data supported by platform or not. - */ - static supportsString: boolean; - /** - * Whether {@link ArrayBuffer} supported by platform or not. - */ - static supportsArrayBuffer: boolean; - /** - * Whether {@link PubNub} File object encryption supported or not. - */ - static supportsEncryptFile: boolean; - /** - * Whether `File Uri` data supported by platform or not. - */ - static supportsFileUri: boolean; - /** - * File object content source. - */ - readonly data: File | FileUri | ReadableFile; - /** - * File object content length. - */ - contentLength?: number; - /** - * File object content type. - */ - mimeType: string; - /** - * File object name. - */ - name: string; - static create(file: PubNubFileParameters): PubNubFile; - constructor(file: PubNubFileParameters); - /** - * Convert {@link PubNub} File object content to {@link Buffer}. - * - * @throws Error because {@link Buffer} not available in React Native environment. - */ - toBuffer(): Promise; - /** - * Convert {@link PubNub} File object content to {@link ArrayBuffer}. - * - * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. - * - * @throws Error if provided {@link PubNub} File object content is not supported for this - * operation. - */ - toArrayBuffer(): Promise; - /** - * Convert {@link PubNub} File object content to {@link string}. - * - * @returns Asynchronous results of conversion to the {@link string}. - */ - toString(): Promise; - /** - * Convert {@link PubNub} File object content to {@link Readable} stream. - * - * @throws Error because {@link Readable} stream not available in React Native environment. - */ - toStream(): Promise; - /** - * Convert {@link PubNub} File object content to {@link File}. - * - * @returns Asynchronous results of conversion to the {@link File}. - * - * @throws Error if provided {@link PubNub} File object content is not supported for this - * operation. - */ - toFile(): Promise; - /** - * Convert {@link PubNub} File object content to file `Uri`. - * - * @returns Asynchronous results of conversion to file `Uri`. - * - * @throws Error if provided {@link PubNub} File object content is not supported for this - * operation. - */ - toFileUri(): Promise; - /** - * Convert {@link PubNub} File object content to {@link Blob}. - * - * @returns Asynchronous results of conversion to the {@link Blob}. - * - * @throws Error if provided {@link PubNub} File object content is not supported for this - * operation. - */ - toBlob(): Promise; -} -export default PubNubFile; diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts new file mode 100644 index 000000000..d8439d47a --- /dev/null +++ b/lib/types/index.d.ts @@ -0,0 +1,8115 @@ +import { Readable, PassThrough } from 'stream'; +import { Buffer } from 'buffer'; +import { ProxyAgentOptions } from 'proxy-agent'; + +/** + * PubNub client for Node.js platform. + */ +declare class PubNub extends PubNubCore< + string | ArrayBuffer | Buffer | Readable, + PubNub.PubNubFileParameters, + PubNub.PubNubFile +> { + /** + * Data encryption / decryption module constructor. + */ + static CryptoModule: typeof PubNub.CryptoModuleType; + /** + * PubNub File constructor. + */ + File: PubNub.PubNubFileConstructor; + /** + * Create and configure PubNub client core. + * + * @param configuration - User-provided PubNub client configuration. + * + * @returns Configured and ready to use PubNub client. + */ + constructor(configuration: PubNub.PubNubConfiguration); + /** + * Update request proxy configuration. + * + * @param configuration - Updated request proxy configuration. + * + * @throws An error if {@link PubNub} client already configured to use `keepAlive`. + * `keepAlive` and `proxy` can't be used simultaneously. + */ + setProxy(configuration?: ProxyAgentOptions): void; +} + +/** + * Platform-agnostic PubNub client core. + */ +declare class PubNubCore< + CryptographyTypes, + FileConstructorParameters, + PlatformFile extends Partial = Record, +> { + /** + * Type of REST API endpoint which reported status. + */ + static OPERATIONS: typeof PubNub.RequestOperation; + /** + * API call status category. + */ + static CATEGORIES: typeof PubNub.StatusCategory; + /** + * Exponential retry policy constructor. + */ + static ExponentialRetryPolicy: typeof PubNub.RetryPolicy.ExponentialRetryPolicy; + /** + * Linear retry policy constructor. + */ + static LinearRetryPolicy: typeof PubNub.RetryPolicy.LinearRetryPolicy; + /** + * Construct notification payload which will trigger push notification. + * + * @param title - Title which will be shown on notification. + * @param body - Payload which will be sent as part of notification. + * + * @returns Pre-formatted message payload which will trigger push notification. + */ + static notificationPayload(title: string, body: string): PubNub.NotificationsPayload; + /** + * Generate unique identifier. + * + * @returns Unique identifier. + */ + static generateUUID(): any; + /** + * PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + */ + get configuration(): PubNub.ClientConfiguration; + /** + * Current PubNub client configuration. + * + * @returns Currently user PubNub client configuration. + * + * @deprecated Use {@link configuration} getter instead. + */ + get _config(): PubNub.ClientConfiguration; + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ + get authKey(): string | undefined; + /** + * REST API endpoint access authorization key. + * + * It is required to have `authorization key` with required permissions to access REST API + * endpoints when `PAM` enabled for user key set. + */ + getAuthKey(): string | undefined; + /** + * Change REST API endpoint access authorization key. + * + * @param authKey - New authorization key which should be used with new requests. + */ + setAuthKey(authKey: string): void; + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + get userId(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + set userId(value: string); + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + getUserId(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + setUserId(value: string): void; + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + get filterExpression(): string | undefined; + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + getFilterExpression(): string | undefined; + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + set filterExpression(expression: string | null | undefined); + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + setFilterExpression(expression: string | null): void; + /** + * Dta encryption / decryption key. + * + * @returns Currently used key for data encryption / decryption. + */ + get cipherKey(): string | undefined; + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + set cipherKey(key: string | undefined); + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + setCipherKey(key: string): void; + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ + set heartbeatInterval(interval: number); + /** + * Change heartbeat requests interval. + * + * @param interval - New presence request heartbeat intervals. + */ + setHeartbeatInterval(interval: number): void; + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + getVersion(): string; + /** + * Add framework's prefix. + * + * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. + * @param suffix - Suffix with information about framework. + */ + _addPnsdkSuffix(name: string, suffix: string | number): void; + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + * + * @deprecated Use the {@link getUserId} or {@link userId} getter instead. + */ + getUUID(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + * + * @deprecated Use the {@link PubNubCore#setUserId} or {@link PubNubCore#userId} setter instead. + */ + setUUID(value: string): void; + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + get customEncrypt(): ((data: string) => string) | undefined; + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + get customDecrypt(): ((data: string) => string) | undefined; + /** + * Create a `Channel` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel name. + * @returns `Channel` entity. + */ + channel(name: string): PubNub.Channel; + /** + * Create a `ChannelGroup` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param name - Unique channel group name. + * @returns `ChannelGroup` entity. + */ + channelGroup(name: string): PubNub.ChannelGroup; + /** + * Create a `ChannelMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique channel metadata object identifier. + * @returns `ChannelMetadata` entity. + */ + channelMetadata(id: string): PubNub.ChannelMetadata; + /** + * Create a `UserMetadata` entity. + * + * Entity can be used for the interaction with the following API: + * - `subscribe` + * + * @param id - Unique user metadata object identifier. + * @returns `UserMetadata` entity. + */ + userMetadata(id: string): PubNub.UserMetadata; + /** + * Create subscriptions set object. + * + * @param parameters - Subscriptions set configuration parameters. + */ + subscriptionSet(parameters: { + channels?: string[]; + channelGroups?: string[]; + subscriptionOptions?: PubNub.SubscriptionOptions; + }): PubNub.SubscriptionSet; + /** + * Unsubscribe from all channels and groups. + * + * @param [isOffline] - Whether `offline` presence should be notified or not. + */ + destroy(isOffline?: boolean): void; + /** + * Unsubscribe from all channels and groups. + * + * @deprecated Use {@link destroy} method instead. + */ + stop(): void; + /** + * Register real-time events listener. + * + * @param listener - Listener with event callbacks to handle different types of events. + */ + addListener(listener: PubNub.Listener): void; + /** + * Remove real-time event listener. + * + * @param listener - Event listeners which should be removed. + */ + removeListener(listener: PubNub.Listener): void; + /** + * Clear all real-time event listeners. + */ + removeAllListeners(): void; + /** + * Publish data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + publish( + parameters: PubNub.Publish.PublishParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Publish data to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous publish data response. + */ + publish(parameters: PubNub.Publish.PublishParameters): Promise; + /** + * Signal data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + signal( + parameters: PubNub.Signal.SignalParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Signal data to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous signal data response. + */ + signal(parameters: PubNub.Signal.SignalParameters): Promise; + /** + * `Fire` a data to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link publish} method instead. + */ + fire( + parameters: PubNub.Publish.PublishParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * `Fire` a data to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous signal data response. + * + * @deprecated Use {@link publish} method instead. + */ + fire(parameters: PubNub.Publish.PublishParameters): Promise; + /** + * Get list of channels on which PubNub client currently subscribed. + * + * @returns List of active channels. + */ + getSubscribedChannels(): string[]; + /** + * Get list of channel groups on which PubNub client currently subscribed. + * + * @returns List of active channel groups. + */ + getSubscribedChannelGroups(): string[]; + /** + * Subscribe to specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ + subscribe(parameters: PubNub.Subscription.SubscribeParameters): void; + /** + * Unsubscribe from specified channels and groups real-time events. + * + * @param parameters - Request configuration parameters. + */ + unsubscribe(parameters: PubNub.Presence.PresenceLeaveParameters): void; + /** + * Unsubscribe from all channels and groups. + */ + unsubscribeAll(): void; + /** + * Temporarily disconnect from real-time events stream. + */ + disconnect(): void; + /** + * Restore connection to the real-time events stream. + * + * @param parameters - Reconnection catch up configuration. **Note:** available only with + * enabled event engine. + */ + reconnect(parameters?: { timetoken?: string; region?: number }): void; + /** + * Get reactions to a specific message. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getMessageActions( + parameters: PubNub.MessageAction.GetMessageActionsParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Get reactions to a specific message. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get reactions response. + */ + getMessageActions( + parameters: PubNub.MessageAction.GetMessageActionsParameters, + ): Promise; + /** + * Add a reaction to a specific message. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + addMessageAction( + parameters: PubNub.MessageAction.AddMessageActionParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Add a reaction to a specific message. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous add a reaction response. + */ + addMessageAction( + parameters: PubNub.MessageAction.AddMessageActionParameters, + ): Promise; + /** + * Remove a reaction from a specific message. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeMessageAction( + parameters: PubNub.MessageAction.RemoveMessageActionParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Remove a reaction from a specific message. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous remove a reaction response. + */ + removeMessageAction( + parameters: PubNub.MessageAction.RemoveMessageActionParameters, + ): Promise; + /** + * Fetch messages history for channels. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + fetchMessages( + parameters: PubNub.History.FetchMessagesParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Fetch messages history for channels. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous fetch messages response. + */ + fetchMessages(parameters: PubNub.History.FetchMessagesParameters): Promise; + /** + * Delete messages from the channel history. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated + */ + deleteMessages( + parameters: PubNub.History.DeleteMessagesParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Delete messages from the channel history. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous delete messages response. + * + * @deprecated + */ + deleteMessages(parameters: PubNub.History.DeleteMessagesParameters): Promise; + /** + * Count messages from the channels' history. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + messageCounts( + parameters: PubNub.History.MessageCountParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Count messages from the channels' history. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous count messages response. + */ + messageCounts(parameters: PubNub.History.MessageCountParameters): Promise; + /** + * Fetch single channel history. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated + */ + history( + parameters: PubNub.History.GetHistoryParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Fetch single channel history. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous fetch channel history response. + * + * @deprecated + */ + history(parameters: PubNub.History.GetHistoryParameters): Promise; + /** + * Get channel's presence information. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + hereNow( + parameters: PubNub.Presence.HereNowParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Get channel presence information. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get channel's presence response. + */ + hereNow(parameters: PubNub.Presence.HereNowParameters): Promise; + /** + * Get user's presence information. + * + * Get list of channels to which `uuid` currently subscribed. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + whereNow( + parameters: PubNub.Presence.WhereNowParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Get user's presence information. + * + * Get list of channels to which `uuid` currently subscribed. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get user's presence response. + */ + whereNow(parameters: PubNub.Presence.WhereNowParameters): Promise; + /** + * Get associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getState( + parameters: PubNub.Presence.GetPresenceStateParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Get associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get associated user's data response. + */ + getState(parameters: PubNub.Presence.GetPresenceStateParameters): Promise; + /** + * Set associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + setState( + parameters: PubNub.Presence.SetPresenceStateParameters | PubNub.Presence.SetPresenceStateWithHeartbeatParameters, + callback: PubNub.ResultCallback< + PubNub.Presence.SetPresenceStateResponse | PubNub.Presence.PresenceHeartbeatResponse + >, + ): void; + /** + * Set associated user's data for channels and groups. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous set associated user's data response. + */ + setState( + parameters: PubNub.Presence.SetPresenceStateParameters | PubNub.Presence.SetPresenceStateWithHeartbeatParameters, + ): Promise; + /** + * Manual presence management. + * + * @param parameters - Desired presence state for provided list of channels and groups. + */ + presence(parameters: { connected: boolean; channels?: string[]; channelGroups?: string[] }): void; + /** + * Grant token permission. + * + * Generate access token with requested permissions. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + grantToken( + parameters: PubNub.PAM.GrantTokenParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Grant token permission. + * + * Generate access token with requested permissions. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous grant token response. + */ + grantToken(parameters: PubNub.PAM.GrantTokenParameters): Promise; + /** + * Revoke token permission. + * + * @param token - Access token for which permissions should be revoked. + * @param callback - Request completion handler callback. + */ + revokeToken( + token: PubNub.PAM.RevokeParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Revoke token permission. + * + * @param token - Access token for which permissions should be revoked. + * + * @returns Asynchronous revoke token response. + */ + revokeToken(token: PubNub.PAM.RevokeParameters): Promise; + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ + get token(): string | undefined; + /** + * Get current access token. + * + * @returns Previously configured access token using {@link setToken} method. + */ + getToken(): string | undefined; + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ + set token(token: string | undefined); + /** + * Set current access token. + * + * @param token - New access token which should be used with next REST API endpoint calls. + */ + setToken(token: string | undefined): void; + /** + * Parse access token. + * + * Parse token to see what permissions token owner has. + * + * @param token - Token which should be parsed. + * + * @returns Token's permissions information for the resources. + */ + parseToken(token: string): PubNub.PAM.Token | undefined; + /** + * Grant auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + grant(parameters: PubNub.PAM.GrantParameters, callback: PubNub.ResultCallback): void; + /** + * Grant auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous grant auth key(s) permissions response. + * + * @deprecated Use {@link grantToken} and {@link setToken} methods instead. + */ + grant(parameters: PubNub.PAM.GrantParameters): Promise; + /** + * Audit auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated + */ + audit(parameters: PubNub.PAM.AuditParameters, callback: PubNub.ResultCallback): void; + /** + * Audit auth key(s) permission. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous audit auth key(s) permissions response. + * + * @deprecated + */ + audit(parameters: PubNub.PAM.AuditParameters): Promise; + /** + * PubNub App Context API group. + */ + get objects(): PubNub.PubNubObjects; + /** + * Fetch a paginated list of User objects. + * + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + fetchUsers( + callback: PubNub.ResultCallback>, + ): void; + /** + * Fetch a paginated list of User objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + fetchUsers( + parameters: PubNub.AppContext.GetAllMetadataParameters>, + callback: PubNub.ResultCallback>, + ): void; + /** + * Fetch a paginated list of User objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all User objects response. + * + * @deprecated Use {@link PubNubCore#objects.getAllUUIDMetadata} method instead. + */ + fetchUsers( + parameters?: PubNub.AppContext.GetAllMetadataParameters>, + ): Promise>; + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + fetchUser( + callback: PubNub.ResultCallback>, + ): void; + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param parameters - Request configuration parameters. Will fetch User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + fetchUser( + parameters: PubNub.AppContext.GetUUIDMetadataParameters, + callback: PubNub.ResultCallback>, + ): void; + /** + * Fetch User object for currently configured PubNub client `uuid`. + * + * @param [parameters] - Request configuration parameters. Will fetch User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous get User object response. + * + * @deprecated Use {@link PubNubCore#objects.getUUIDMetadata} method instead. + */ + fetchUser( + parameters?: PubNub.AppContext.GetUUIDMetadataParameters, + ): Promise>; + /** + * Create User object. + * + * @param parameters - Request configuration parameters. Will create User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + createUser( + parameters: PubNub.AppContext.SetUUIDMetadataParameters, + callback: PubNub.ResultCallback>, + ): void; + /** + * Create User object. + * + * @param parameters - Request configuration parameters. Will create User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous create User object response. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + createUser( + parameters: PubNub.AppContext.SetUUIDMetadataParameters, + ): Promise>; + /** + * Update User object. + * + * @param parameters - Request configuration parameters. Will update User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + updateUser( + parameters: PubNub.AppContext.SetUUIDMetadataParameters, + callback: PubNub.ResultCallback>, + ): void; + /** + * Update User object. + * + * @param parameters - Request configuration parameters. Will update User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous update User object response. + * + * @deprecated Use {@link PubNubCore#objects.setUUIDMetadata} method instead. + */ + updateUser( + parameters: PubNub.AppContext.SetUUIDMetadataParameters, + ): Promise>; + /** + * Remove a specific User object. + * + * @param callback - Request completion handler callback. Will remove User object for currently + * configured PubNub client `uuid` if not set. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + removeUser(callback: PubNub.ResultCallback): void; + /** + * Remove a specific User object. + * + * @param parameters - Request configuration parameters. Will remove User object for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + removeUser( + parameters: PubNub.AppContext.RemoveUUIDMetadataParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Remove a specific User object. + * + * @param [parameters] - Request configuration parameters. Will remove User object for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous User object remove response. + * + * @deprecated Use {@link PubNubCore#objects.removeUUIDMetadata} method instead. + */ + removeUser( + parameters?: PubNub.AppContext.RemoveUUIDMetadataParameters, + ): Promise; + /** + * Fetch a paginated list of Space objects. + * + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + fetchSpaces( + callback: PubNub.ResultCallback>, + ): void; + /** + * Fetch a paginated list of Space objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + fetchSpaces( + parameters: PubNub.AppContext.GetAllMetadataParameters>, + callback: PubNub.ResultCallback>, + ): void; + /** + * Fetch a paginated list of Space objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all Space objects response. + * + * @deprecated Use {@link PubNubCore#objects.getAllChannelMetadata} method instead. + */ + fetchSpaces( + parameters?: PubNub.AppContext.GetAllMetadataParameters>, + ): Promise>; + /** + * Fetch a specific Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. + */ + fetchSpace( + parameters: PubNub.AppContext.GetChannelMetadataParameters, + callback: PubNub.ResultCallback>, + ): void; + /** + * Fetch a specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get Channel metadata response. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMetadata} method instead. + */ + fetchSpace( + parameters: PubNub.AppContext.GetChannelMetadataParameters, + ): Promise>; + /** + * Create specific Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + createSpace( + parameters: PubNub.AppContext.SetChannelMetadataParameters, + callback: PubNub.ResultCallback>, + ): void; + /** + * Create specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous create Space object response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + createSpace( + parameters: PubNub.AppContext.SetChannelMetadataParameters, + ): Promise>; + /** + * Update specific Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + updateSpace( + parameters: PubNub.AppContext.SetChannelMetadataParameters, + callback: PubNub.ResultCallback>, + ): void; + /** + * Update specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous update Space object response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMetadata} method instead. + */ + updateSpace( + parameters: PubNub.AppContext.SetChannelMetadataParameters, + ): Promise>; + /** + * Remove Space object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. + */ + removeSpace( + parameters: PubNub.AppContext.RemoveChannelMetadataParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Remove a specific Space object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous Space object remove response. + * + * @deprecated Use {@link PubNubCore#objects.removeChannelMetadata} method instead. + */ + removeSpace( + parameters: PubNub.AppContext.RemoveChannelMetadataParameters, + ): Promise; + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} + * methods instead. + */ + fetchMemberships< + RelationCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + MetadataCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + >( + parameters: PubNub.AppContext.GetMembershipsParameters | PubNub.AppContext.GetMembersParameters, + callback: PubNub.ResultCallback< + | PubNub.AppContext.SpaceMembershipsResponse + | PubNub.AppContext.UserMembersResponse + >, + ): void; + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get specific Space members or specific User memberships response. + * + * @deprecated Use {@link PubNubCore#objects.getChannelMembers} or {@link PubNubCore#objects.getMemberships} + * methods instead. + */ + fetchMemberships< + RelationCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + MetadataCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + >( + parameters: PubNub.AppContext.GetMembershipsParameters | PubNub.AppContext.GetMembersParameters, + ): Promise< + | PubNub.AppContext.SpaceMembershipsResponse + | PubNub.AppContext.UserMembersResponse + >; + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + addMemberships< + Custom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + MetadataCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + >( + parameters: + | PubNub.AppContext.SetMembershipsParameters + | PubNub.AppContext.SetChannelMembersParameters, + callback: PubNub.ResultCallback< + | PubNub.AppContext.SetMembershipsResponse + | PubNub.AppContext.SetMembersResponse + >, + ): void; + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous add members to specific Space or memberships specific User response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + addMemberships< + Custom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + MetadataCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + >( + parameters: + | PubNub.AppContext.SetMembershipsParameters + | PubNub.AppContext.SetChannelMembersParameters, + ): Promise< + | PubNub.AppContext.SetMembershipsResponse + | PubNub.AppContext.SetMembersResponse + >; + /** + * Update specific Space members or User memberships. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + updateMemberships< + Custom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + MetadataCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + >( + parameters: + | PubNub.AppContext.SetMembershipsParameters + | PubNub.AppContext.SetChannelMembersParameters, + callback: PubNub.ResultCallback< + | PubNub.AppContext.SetMembershipsResponse + | PubNub.AppContext.SetMembersResponse + >, + ): void; + /** + * Update specific Space members or User memberships. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous update Space members or User memberships response. + * + * @deprecated Use {@link PubNubCore#objects.setChannelMembers} or {@link PubNubCore#objects.setMemberships} + * methods instead. + */ + updateMemberships< + Custom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + MetadataCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + >( + parameters: + | PubNub.AppContext.SetMembershipsParameters + | PubNub.AppContext.SetChannelMembersParameters, + ): Promise< + | PubNub.AppContext.SetMembershipsResponse + | PubNub.AppContext.SetMembersResponse + >; + /** + * Remove User membership. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + * + * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} + * methods instead from `objects` API group. + */ + removeMemberships< + RelationCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + MetadataCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + >( + parameters: PubNub.AppContext.RemoveMembersParameters | PubNub.AppContext.RemoveMembershipsParameters, + callback: PubNub.ResultCallback< + | PubNub.AppContext.RemoveMembersResponse + | PubNub.AppContext.RemoveMembershipsResponse + >, + ): void; + /** + * Remove User membership. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous memberships modification response. + * + * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} + * methods instead from `objects` API group. + */ + removeMemberships< + RelationCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + MetadataCustom extends PubNub.AppContext.CustomData = PubNub.AppContext.CustomData, + >( + parameters: PubNub.AppContext.RemoveMembersParameters | PubNub.AppContext.RemoveMembershipsParameters, + ): Promise>; + /** + * PubNub Channel Groups API group. + */ + get channelGroups(): PubNub.PubNubChannelGroups; + /** + * PubNub Push Notifications API group. + */ + get push(): PubNub.PubNubPushNotifications; + /** + * Share file to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + sendFile( + parameters: PubNub.FileSharing.SendFileParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Share file to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous file sharing response. + */ + sendFile( + parameters: PubNub.FileSharing.SendFileParameters, + ): Promise; + /** + * Publish file message to a specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + publishFile( + parameters: PubNub.FileSharing.PublishFileMessageParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Publish file message to a specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous publish file message response. + */ + publishFile( + parameters: PubNub.FileSharing.PublishFileMessageParameters, + ): Promise; + /** + * Retrieve list of shared files in specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + listFiles( + parameters: PubNub.FileSharing.ListFilesParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Retrieve list of shared files in specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous shared files list response. + */ + listFiles(parameters: PubNub.FileSharing.ListFilesParameters): Promise; + /** + * Get file download Url. + * + * @param parameters - Request configuration parameters. + * + * @returns File download Url. + */ + getFileUrl(parameters: PubNub.FileSharing.FileUrlParameters): PubNub.FileSharing.FileUrlResponse; + /** + * Download shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + downloadFile( + parameters: PubNub.FileSharing.DownloadFileParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Download shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous download shared file response. + */ + downloadFile(parameters: PubNub.FileSharing.DownloadFileParameters): Promise; + /** + * Delete shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + deleteFile( + parameters: PubNub.FileSharing.DeleteFileParameters, + callback: PubNub.ResultCallback, + ): void; + /** + * Delete shared file from specific channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous delete shared file response. + */ + deleteFile(parameters: PubNub.FileSharing.DeleteFileParameters): Promise; + /** + Get current high-precision timetoken. + * + * @param callback - Request completion handler callback. + */ + time(callback: PubNub.ResultCallback): void; + /** + * Get current high-precision timetoken. + * + * @returns Asynchronous get current timetoken response. + */ + time(): Promise; + /** + * Encrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @deprecated + * @param [customCipherKey] - Cipher key which should be used to encrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data encryption result as a string. + */ + encrypt(data: string | PubNub.Payload, customCipherKey?: string): string; + /** + * Decrypt data. + * + * @param data - Stringified data which should be encrypted using `CryptoModule`. + * @param [customCipherKey] - Cipher key which should be used to decrypt data. **Deprecated:** + * use {@link Configuration#cryptoModule|cryptoModule} instead. + * + * @returns Data decryption result as an object. + */ + decrypt(data: string, customCipherKey?: string): PubNub.Payload | null; + /** + * Encrypt file content. + * + * @param file - File which should be encrypted using `CryptoModule`. + * + * @returns Asynchronous file encryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + encryptFile(file: PubNub.PubNubFileInterface): Promise; + /** + * Encrypt file content. + * + * @param key - Cipher key which should be used to encrypt data. + * @param file - File which should be encrypted using legacy cryptography. + * + * @returns Asynchronous file encryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + encryptFile(key: string, file: PubNub.PubNubFileInterface): Promise; + /** + * Decrypt file content. + * + * @param file - File which should be decrypted using legacy cryptography. + * + * @returns Asynchronous file decryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + decryptFile(file: PubNub.PubNubFileInterface): Promise; + /** + * Decrypt file content. + * + * @param key - Cipher key which should be used to decrypt data. + * @param [file] - File which should be decrypted using legacy cryptography. + * + * @returns Asynchronous file decryption result. + * + * @throws Error if source file not provided. + * @throws File constructor not provided. + * @throws Crypto module is missing (if non-legacy flow used). + */ + decryptFile( + key: string | PubNub.PubNubFileInterface, + file?: PubNub.PubNubFileInterface, + ): Promise; +} + +declare namespace PubNub { + /** + * Crypto module cryptors interface. + */ + type CryptorType = ICryptor | ILegacyCryptor; + + /** + * CryptoModule for Node.js platform. + */ + export class NodeCryptoModule extends AbstractCryptoModule { + /** + * {@link LegacyCryptor|Legacy} cryptor identifier. + */ + static LEGACY_IDENTIFIER: string; + static legacyCryptoModule(config: CryptorConfiguration): NodeCryptoModule; + static aesCbcCryptoModule(config: CryptorConfiguration): NodeCryptoModule; + /** + * Construct crypto module with `cryptor` as default for data encryption and decryption. + * + * @param defaultCryptor - Default cryptor for data encryption and decryption. + * + * @returns Crypto module with pre-configured default cryptor. + */ + static withDefaultCryptor(defaultCryptor: CryptorType): NodeCryptoModule; + encrypt(data: ArrayBuffer | string): string | ArrayBuffer; + encryptFile( + file: PubNubFile, + File: PubNubFileConstructor, + ): Promise; + decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null; + decryptFile( + file: PubNubFile, + File: PubNubFileConstructor, + ): Promise; + } + + /** Re-export aliased type. */ + export { NodeCryptoModule as CryptoModuleType }; + + /** + * Crypto module configuration. + */ + export type CryptoModuleConfiguration = { + default: C; + cryptors?: C[]; + }; + + export type CryptorConfiguration = { + /** + * Data encryption / decryption key. + */ + cipherKey?: string; + /** + * Request sign secret key. + */ + secretKey?: string; + /** + * Whether random initialization vector should be used or not. + * + * @default `true` + */ + useRandomIVs?: boolean; + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + customEncrypt?: (data: string | Payload) => string; + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + customDecrypt?: (data: string) => string; + }; + + /** + * Base crypto module interface. + */ + export interface ICryptoModule { + /** + * Encrypt data. + * + * @param data - Data which should be encrypted using `CryptoModule`. + * + * @returns Data encryption result. + */ + encrypt(data: ArrayBuffer | string): ArrayBuffer | string; + /** + * Encrypt file object. + * + * @param file - File object with data for encryption. + * @param File - File object constructor to create instance for encrypted data representation. + * + * @returns Asynchronous file encryption result. + */ + encryptFile( + file: PubNubFileInterface, + File: PubNubFileConstructor, + ): Promise; + /** + * Encrypt data. + * + * @param data - Dta which should be encrypted using `CryptoModule`. + * + * @returns Data decryption result. + */ + decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null; + /** + * Decrypt file object. + * + * @param file - Encrypted file object with data for decryption. + * @param File - File object constructor to create instance for decrypted data representation. + * + * @returns Asynchronous file decryption result. + */ + decryptFile( + file: PubNubFileInterface, + File: PubNubFileConstructor, + ): Promise; + } + + export abstract class AbstractCryptoModule implements ICryptoModule { + defaultCryptor: C; + cryptors: C[]; + /** + * Construct crypto module with legacy cryptor for encryption and both legacy and AES-CBC + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using legacy cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ + static legacyCryptoModule(config: CryptorConfiguration): ICryptoModule; + /** + * Construct crypto module with AES-CBC cryptor for encryption and both AES-CBC and legacy + * cryptors for decryption. + * + * @param config Cryptors configuration options. + * + * @returns Crypto module which encrypts data using AES-CBC cryptor. + * + * @throws Error if `config.cipherKey` not set. + */ + static aesCbcCryptoModule(config: CryptorConfiguration): ICryptoModule; + constructor(configuration: CryptoModuleConfiguration); + /** + * Encrypt data. + * + * @param data - Data which should be encrypted using {@link ICryptoModule}. + * + * @returns Data encryption result. + */ + abstract encrypt(data: ArrayBuffer | string): ArrayBuffer | string; + /** + * Encrypt file object. + * + * @param file - File object with data for encryption. + * @param File - File object constructor to create instance for encrypted data representation. + * + * @returns Asynchronous file encryption result. + */ + abstract encryptFile( + file: PubNubFileInterface, + File: PubNubFileConstructor, + ): Promise; + /** + * Encrypt data. + * + * @param data - Dta which should be encrypted using `ICryptoModule`. + * + * @returns Data decryption result. + */ + abstract decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null; + /** + * Decrypt file object. + * + * @param file - Encrypted file object with data for decryption. + * @param File - File object constructor to create instance for decrypted data representation. + * + * @returns Asynchronous file decryption result. + */ + abstract decryptFile( + file: PubNubFileInterface, + File: PubNubFileConstructor, + ): Promise; + } + + /** + * Base file constructor parameters. + * + * Minimum set of parameters which can be p + */ + export type PubNubBasicFileParameters = { + data: string | ArrayBuffer; + name: string; + mimeType?: string; + }; + + /** + * Platform-agnostic {@link PubNub} File object. + * + * Interface describes share of {@link PubNub} File which is required by {@link PubNub} core to + * perform required actions. + */ + export interface PubNubFileInterface { + /** + * Actual file name. + */ + name: string; + /** + * File mime-type. + */ + mimeType?: string; + /** + * File content length. + */ + contentLength?: number; + /** + * Convert {@link PubNub} file object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toArrayBuffer(): Promise; + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @returns Asynchronous results of conversion to file `Uri`. + * + * @throws Error if provided {@link PubNub} File object content is not supported for this + * operation. + */ + toFileUri(): Promise>; + } + + /** + * {@link PubNub} File object class interface. + */ + export interface PubNubFileConstructor { + /** + * Whether {@link Blob} data supported by platform or not. + */ + supportsBlob: boolean; + /** + * Whether {@link File} data supported by platform or not. + */ + supportsFile: boolean; + /** + * Whether {@link Buffer} data supported by platform or not. + */ + supportsBuffer: boolean; + /** + * Whether {@link Stream} data supported by platform or not. + */ + supportsStream: boolean; + /** + * Whether {@link String} data supported by platform or not. + */ + supportsString: boolean; + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + supportsArrayBuffer: boolean; + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + supportsEncryptFile: boolean; + /** + * Whether `File Uri` data supported by platform or not. + */ + supportsFileUri: boolean; + /** + * {@link PubNub} File object constructor. + * + * @param file - File instantiation parameters (can be raw data or structured object). + * + * @returns Constructed platform-specific {@link PubNub} File object. + */ + create(file: ConstructorParameters): File; + /** + * {@link PubNub} File object constructor. + * + * @param file - File instantiation parameters (can be raw data or structured object). + * + * @returns Constructed platform-specific {@link PubNub} File object. + */ + new (file: ConstructorParameters): File; + } + + /** + * Endpoint call completion block with result. + * + * **Note:** Endpoints which return consumable data use this callback. + */ + export type ResultCallback = (status: Status, response: ResponseType | null) => void; + + /** + * Endpoint acknowledgment completion block. + * + * **Note:** Endpoints which return only acknowledgment or error status use this callback. + */ + export type StatusCallback = (status: Status) => void; + + /** + * REST API endpoint processing status. + * + * **Note:** Used as {@link ResultCallback} and {@link StatusCallback} callbacks first argument type and + * {@link PubNubError} instance `status` field value type. + */ + export type Status = { + /** + * Whether status represent error or not. + */ + error: boolean; + /** + * API call status category. + */ + category: StatusCategory; + /** + * Type of REST API endpoint which reported status. + */ + operation?: RequestOperation; + /** + * REST API response status code. + */ + statusCode: number; + /** + * Error data provided by REST API. + */ + errorData?: Error | Payload; + /** + * Additional status information. + */ + [p: string]: Payload | Error | undefined; + }; + + /** + * Real-time PubNub client status change event. + */ + export type StatusEvent = { + /** + * API call status category. + */ + category: StatusCategory; + /** + * Type of REST API endpoint which reported status. + */ + operation?: RequestOperation; + /** + * Information about error. + */ + error?: string | boolean; + /** + * List of channels for which status update announced. + */ + affectedChannels?: string[]; + /** + * List of currently subscribed channels. + * + * List of channels from which PubNub client receives real-time updates. + */ + subscribedChannels?: string[]; + /** + * List of channel groups for which status update announced. + */ + affectedChannelGroups?: string[]; + /** + * High-precision timetoken which has been used with previous subscription loop. + */ + lastTimetoken?: number | string; + /** + * High-precision timetoken which is used for current subscription loop. + */ + currentTimetoken?: number | string; + }; + + /** + * {@link TransportRequest} query parameter type. + */ + export type Query = Record; + + /** + * General payload type. + * + * Type should be used for: + * * generic messages and signals content, + * * published message metadata. + */ + export type Payload = + | string + | number + | boolean + | { + toJSON: () => Payload; + } + | { + [key: string]: Payload | null; + } + | Payload[]; + + /** + * Endpoint API operation types. + */ + export enum RequestOperation { + /** + * Data publish REST API operation. + */ + PNPublishOperation = 'PNPublishOperation', + /** + * Signal sending REST API operation. + */ + PNSignalOperation = 'PNSignalOperation', + /** + * Subscribe for real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `join` event. + */ + PNSubscribeOperation = 'PNSubscribeOperation', + /** + * Unsubscribe from real-time updates REST API operation. + * + * User's presence change on specified entities will trigger `leave` event. + */ + PNUnsubscribeOperation = 'PNUnsubscribeOperation', + /** + * Fetch user's presence information REST API operation. + */ + PNWhereNowOperation = 'PNWhereNowOperation', + /** + * Fetch channel's presence information REST API operation. + */ + PNHereNowOperation = 'PNHereNowOperation', + /** + * Fetch global presence information REST API operation. + */ + PNGlobalHereNowOperation = 'PNGlobalHereNowOperation', + /** + * Update user's information associated with specified channel REST API operation. + */ + PNSetStateOperation = 'PNSetStateOperation', + /** + * Fetch user's information associated with the specified channel REST API operation. + */ + PNGetStateOperation = 'PNGetStateOperation', + /** + * Announce presence on managed channels REST API operation. + */ + PNHeartbeatOperation = 'PNHeartbeatOperation', + /** + * Add a reaction to the specified message REST API operation. + */ + PNAddMessageActionOperation = 'PNAddActionOperation', + /** + * Remove reaction from the specified message REST API operation. + */ + PNRemoveMessageActionOperation = 'PNRemoveMessageActionOperation', + /** + * Fetch reactions for specific message REST API operation. + */ + PNGetMessageActionsOperation = 'PNGetMessageActionsOperation', + PNTimeOperation = 'PNTimeOperation', + /** + * Channel history REST API operation. + */ + PNHistoryOperation = 'PNHistoryOperation', + /** + * Delete messages from channel history REST API operation. + */ + PNDeleteMessagesOperation = 'PNDeleteMessagesOperation', + /** + * History for channels REST API operation. + */ + PNFetchMessagesOperation = 'PNFetchMessagesOperation', + /** + * Number of messages for channels in specified time frame REST API operation. + */ + PNMessageCounts = 'PNMessageCountsOperation', + /** + * Fetch users metadata REST API operation. + */ + PNGetAllUUIDMetadataOperation = 'PNGetAllUUIDMetadataOperation', + /** + * Fetch user metadata REST API operation. + */ + PNGetUUIDMetadataOperation = 'PNGetUUIDMetadataOperation', + /** + * Set user metadata REST API operation. + */ + PNSetUUIDMetadataOperation = 'PNSetUUIDMetadataOperation', + /** + * Remove user metadata REST API operation. + */ + PNRemoveUUIDMetadataOperation = 'PNRemoveUUIDMetadataOperation', + /** + * Fetch channels metadata REST API operation. + */ + PNGetAllChannelMetadataOperation = 'PNGetAllChannelMetadataOperation', + /** + * Fetch channel metadata REST API operation. + */ + PNGetChannelMetadataOperation = 'PNGetChannelMetadataOperation', + /** + * Set channel metadata REST API operation. + */ + PNSetChannelMetadataOperation = 'PNSetChannelMetadataOperation', + /** + * Remove channel metadata REST API operation. + */ + PNRemoveChannelMetadataOperation = 'PNRemoveChannelMetadataOperation', + /** + * Fetch channel members REST API operation. + */ + PNGetMembersOperation = 'PNGetMembersOperation', + /** + * Update channel members REST API operation. + */ + PNSetMembersOperation = 'PNSetMembersOperation', + /** + * Fetch channel memberships REST API operation. + */ + PNGetMembershipsOperation = 'PNGetMembershipsOperation', + /** + * Update channel memberships REST API operation. + */ + PNSetMembershipsOperation = 'PNSetMembershipsOperation', + /** + * Fetch list of files sent to the channel REST API operation. + */ + PNListFilesOperation = 'PNListFilesOperation', + /** + * Retrieve file upload URL REST API operation. + */ + PNGenerateUploadUrlOperation = 'PNGenerateUploadUrlOperation', + /** + * Upload file to the channel REST API operation. + */ + PNPublishFileOperation = 'PNPublishFileOperation', + /** + * Publish File Message to the channel REST API operation. + */ + PNPublishFileMessageOperation = 'PNPublishFileMessageOperation', + /** + * Retrieve file download URL REST API operation. + */ + PNGetFileUrlOperation = 'PNGetFileUrlOperation', + /** + * Download file from the channel REST API operation. + */ + PNDownloadFileOperation = 'PNDownloadFileOperation', + /** + * Delete file sent to the channel REST API operation. + */ + PNDeleteFileOperation = 'PNDeleteFileOperation', + /** + * Register channels with device push notifications REST API operation. + */ + PNAddPushNotificationEnabledChannelsOperation = 'PNAddPushNotificationEnabledChannelsOperation', + /** + * Unregister channels with device push notifications REST API operation. + */ + PNRemovePushNotificationEnabledChannelsOperation = 'PNRemovePushNotificationEnabledChannelsOperation', + /** + * Fetch list of channels with enabled push notifications for device REST API operation. + */ + PNPushNotificationEnabledChannelsOperation = 'PNPushNotificationEnabledChannelsOperation', + /** + * Disable push notifications for device REST API operation. + */ + PNRemoveAllPushNotificationsOperation = 'PNRemoveAllPushNotificationsOperation', + /** + * Fetch channels groups list REST API operation. + */ + PNChannelGroupsOperation = 'PNChannelGroupsOperation', + /** + * Remove specified channel group REST API operation. + */ + PNRemoveGroupOperation = 'PNRemoveGroupOperation', + /** + * Fetch list of channels for the specified channel group REST API operation. + */ + PNChannelsForGroupOperation = 'PNChannelsForGroupOperation', + /** + * Add list of channels to the specified channel group REST API operation. + */ + PNAddChannelsToGroupOperation = 'PNAddChannelsToGroupOperation', + /** + * Remove list of channels from the specified channel group REST API operation. + */ + PNRemoveChannelsFromGroupOperation = 'PNRemoveChannelsFromGroupOperation', + /** + * Generate authorized token REST API operation. + */ + PNAccessManagerGrant = 'PNAccessManagerGrant', + /** + * Generate authorized token REST API operation. + */ + PNAccessManagerGrantToken = 'PNAccessManagerGrantToken', + PNAccessManagerAudit = 'PNAccessManagerAudit', + /** + * Revoke authorized token REST API operation. + */ + PNAccessManagerRevokeToken = 'PNAccessManagerRevokeToken', + } + + /** + * Request processing status categories. + */ + export enum StatusCategory { + /** + * Call failed when network was unable to complete the call. + */ + PNNetworkIssuesCategory = 'PNNetworkIssuesCategory', + /** + * Network call timed out. + */ + PNTimeoutCategory = 'PNTimeoutCategory', + /** + * Request has been cancelled. + */ + PNCancelledCategory = 'PNCancelledCategory', + /** + * Server responded with bad response. + */ + PNBadRequestCategory = 'PNBadRequestCategory', + /** + * Server responded with access denied. + */ + PNAccessDeniedCategory = 'PNAccessDeniedCategory', + /** + * Incomplete parameters provided for used endpoint. + */ + PNValidationErrorCategory = 'PNValidationErrorCategory', + /** + * PubNub request acknowledgment status. + * + * Some API endpoints respond with request processing status w/o useful data. + */ + PNAcknowledgmentCategory = 'PNAcknowledgmentCategory', + /** + * Something strange happened; please check the logs. + */ + PNUnknownCategory = 'PNUnknownCategory', + /** + * SDK will announce when the network appears to be connected again. + */ + PNNetworkUpCategory = 'PNNetworkUpCategory', + /** + * SDK will announce when the network appears to down. + */ + PNNetworkDownCategory = 'PNNetworkDownCategory', + /** + * PubNub client reconnected to the real-time updates stream. + */ + PNReconnectedCategory = 'PNReconnectedCategory', + /** + * PubNub client connected to the real-time updates stream. + */ + PNConnectedCategory = 'PNConnectedCategory', + /** + * Received real-time updates exceed specified threshold. + * + * After temporary disconnection and catchup, this category means that potentially some + * real-time updates have been pushed into `storage` and need to be requested separately. + */ + PNRequestMessageCountExceededCategory = 'PNRequestMessageCountExceededCategory', + /** + * PubNub client disconnected from the real-time updates streams. + */ + PNDisconnectedCategory = 'PNDisconnectedCategory', + /** + * PubNub client wasn't able to connect to the real-time updates streams. + */ + PNConnectionErrorCategory = 'PNConnectionErrorCategory', + /** + * PubNub client unexpectedly disconnected from the real-time updates streams. + */ + PNDisconnectedUnexpectedlyCategory = 'PNDisconnectedUnexpectedlyCategory', + } + + /** + * PubNub File instance creation parameters. + */ + export type PubNubFileParameters = { + /** + * Readable stream represents file object content. + */ + stream?: Readable; + /** + * Buffer or string represents file object content. + */ + data?: Buffer | ArrayBuffer | string; + /** + * String {@link PubNubFileParameters#data|data} encoding. + * + * @default `utf8` + */ + encoding?: StringEncoding; + /** + * File object name. + */ + name: string; + /** + * File object content type. + */ + mimeType?: string; + }; + + /** + * Node.js implementation for {@link PubNub} File object. + * + * **Important:** Class should implement constructor and class fields from {@link PubNubFileConstructor}. + */ + export class PubNubFile implements PubNubFileInterface { + /** + * Whether {@link Blob} data supported by platform or not. + */ + static supportsBlob: boolean; + /** + * Whether {@link File} data supported by platform or not. + */ + static supportsFile: boolean; + /** + * Whether {@link Buffer} data supported by platform or not. + */ + static supportsBuffer: boolean; + /** + * Whether {@link Stream} data supported by platform or not. + */ + static supportsStream: boolean; + /** + * Whether {@link String} data supported by platform or not. + */ + static supportsString: boolean; + /** + * Whether {@link ArrayBuffer} supported by platform or not. + */ + static supportsArrayBuffer: boolean; + /** + * Whether {@link PubNub} File object encryption supported or not. + */ + static supportsEncryptFile: boolean; + /** + * Whether `File Uri` data supported by platform or not. + */ + static supportsFileUri: boolean; + /** + * File object content source. + */ + readonly data: Readable | Buffer; + /** + * File object content length. + */ + contentLength?: number; + /** + * File object content type. + */ + mimeType: string; + /** + * File object name. + */ + name: string; + static create(file: PubNubFileParameters): PubNubFile; + constructor(file: PubNubFileParameters); + /** + * Convert {@link PubNub} File object content to {@link Buffer}. + * + * @returns Asynchronous results of conversion to the {@link Buffer}. + */ + toBuffer(): Promise; + /** + * Convert {@link PubNub} File object content to {@link ArrayBuffer}. + * + * @returns Asynchronous results of conversion to the {@link ArrayBuffer}. + */ + toArrayBuffer(): Promise; + /** + * Convert {@link PubNub} File object content to {@link string}. + * + * @returns Asynchronous results of conversion to the {@link string}. + */ + toString(encoding?: BufferEncoding): Promise; + /** + * Convert {@link PubNub} File object content to {@link Readable} stream. + * + * @returns Asynchronous results of conversion to the {@link Readable} stream. + */ + toStream(): Promise; + /** + * Convert {@link PubNub} File object content to {@link File}. + * + * @throws Error because {@link File} not available in Node.js environment. + */ + toFile(): Promise; + /** + * Convert {@link PubNub} File object content to file `Uri`. + * + * @throws Error because file `Uri` not available in Node.js environment. + */ + toFileUri(): Promise>; + /** + * Convert {@link PubNub} File object content to {@link Blob}. + * + * @throws Error because {@link Blob} not available in Node.js environment. + */ + toBlob(): Promise; + } + + /** + * Data encrypted by {@link NodeCryptoModule}. + */ + export type EncryptedDataType = { + /** + * Encrypted data. + */ + data: Buffer | string; + /** + * Used cryptor's metadata. + */ + metadata: Buffer | null; + }; + + /** + * {@link Readable} stream encrypted by {@link NodeCryptoModule}. + */ + export type EncryptedStream = { + /** + * Stream with encrypted content. + */ + stream: NodeJS.ReadableStream; + /** + * Length of encrypted data in {@link Readable} stream. + */ + metadataLength: number; + /** + * Used cryptor's metadata. + */ + metadata?: Buffer | undefined; + }; + + /** + * Cryptor algorithm interface. + */ + export interface ICryptor { + /** + * Cryptor unique identifier. + * + * @returns Cryptor identifier. + */ + get identifier(): string; + /** + * Encrypt provided source data. + * + * @param data - Source data for encryption. + * + * @returns Encrypted data object. + * + * @throws Error if unknown data type has been passed. + */ + encrypt(data: BufferSource | string): EncryptedDataType; + /** + * Encrypt provided source {@link Readable} stream. + * + * @param stream - Stream for encryption. + * + * @returns Encrypted stream object. + * + * @throws Error if unknown data type has been passed. + */ + encryptStream(stream: NodeJS.ReadableStream): Promise; + /** + * Decrypt provided encrypted data object. + * + * @param data - Encrypted data object for decryption. + * + * @returns Decrypted data. + * + * @throws Error if unknown data type has been passed. + */ + decrypt(data: EncryptedDataType): ArrayBuffer; + /** + * Decrypt provided encrypted stream object. + * + * @param stream - Encrypted stream object for decryption. + * + * @returns Decrypted data as {@link Readable} stream. + * + * @throws Error if unknown data type has been passed. + */ + decryptStream(stream: EncryptedStream): Promise; + } + + /** + * Legacy cryptor algorithm interface. + */ + export interface ILegacyCryptor { + /** + * Cryptor unique identifier. + */ + get identifier(): string; + /** + * Encrypt provided source data. + * + * @param data - Source data for encryption. + * + * @returns Encrypted data object. + * + * @throws Error if unknown data type has been passed. + */ + encrypt(data: string): EncryptedDataType; + /** + * Encrypt provided source {@link PubNub} File object. + * + * @param file - Source {@link PubNub} File object for encryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Encrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + * @throws Error if cipher key not set. + */ + encryptFile( + file: PubNubFile, + File: PubNubFileConstructor, + ): Promise; + /** + * Decrypt provided encrypted data object. + * + * @param data - Encrypted data object for decryption. + * + * @returns Decrypted data. + * + * @throws Error if unknown data type has been passed. + */ + decrypt(data: EncryptedDataType): Payload | null; + /** + * Decrypt provided encrypted {@link PubNub} File object. + * + * @param file - Encrypted {@link PubNub} File object for decryption. + * @param File - Class constructor for {@link PubNub} File object. + * + * @returns Decrypted data as {@link PubNub} File object. + * + * @throws Error if file is empty or contains unsupported data type. + * @throws Error if cipher key not set. + */ + decryptFile( + file: PubNubFile, + File: PubNubFileConstructor, + ): Promise; + } + + /** + * NodeJS platform PubNub client configuration. + */ + export type PubNubConfiguration = UserConfiguration & { + /** + * Set a custom parameters for setting your connection `keepAlive` if this is set to `true`. + */ + keepAliveSettings?: TransportKeepAlive; + /** + * The cryptography module used for encryption and decryption of messages and files. Takes the + * {@link cipherKey} and {@link useRandomIVs} parameters as arguments. + * + * For more information, refer to the + * {@link /docs/sdks/javascript/api-reference/configuration#cryptomodule|cryptoModule} section. + * + * @default `not set` + */ + cryptoModule?: ICryptoModule; + /** + * If passed, will encrypt the payloads. + * + * @deprecated Pass it to {@link cryptoModule} instead. + */ + cipherKey?: string; + /** + * When `true` the initialization vector (IV) is random for all requests (not just for file + * upload). + * When `false` the IV is hard-coded for all requests except for file upload. + * + * @default `true` + * + * @deprecated Pass it to {@link cryptoModule} instead. + */ + useRandomIVs?: boolean; + /** + * Custom data encryption method. + * + * @deprecated Instead use {@link cryptoModule} for data encryption. + */ + customEncrypt?: (data: string | Payload) => string; + /** + * Custom data decryption method. + * + * @deprecated Instead use {@link cryptoModule} for data decryption. + */ + customDecrypt?: (data: string) => string; + }; + + /** + * Base user-provided PubNub client configuration. + */ + export type UserConfiguration = { + /** + * Specifies the `subscribeKey` to be used for subscribing to a channel and message publishing. + */ + subscribeKey: string; + /** + * Specifies the `subscribe_key` to be used for subscribing to a channel and message publishing. + * + * @deprecated Use the {@link subscribeKey} instead. + */ + subscribe_key?: string; + /** + * Specifies the `publishKey` to be used for publishing messages to a channel. + */ + publishKey?: string; + /** + * Specifies the `publish_key` to be used for publishing messages to a channel. + * + * @deprecated Use the {@link publishKey} instead. + */ + publish_key?: string; + /** + * Specifies the `secretKey` to be used for request signatures computation. + */ + secretKey?: string; + /** + * Specifies the `secret_key` to be used for request signatures computation. + * + * @deprecated Use the {@link secretKey} instead. + */ + secret_key?: string; + /** + * Unique PubNub client user identifier. + * + * Unique `userId` to identify the user or the device that connects to PubNub. + * It's a UTF-8 encoded string of up to 64 alphanumeric characters. + * + * If you don't set the `userId`, you won't be able to connect to PubNub. + */ + userId?: string; + /** + * If Access Manager enabled, this key will be used on all requests. + */ + authKey?: string | null; + /** + * Log HTTP information. + * + * @default `false` + */ + logVerbosity?: boolean; + /** + * If set to true, requests will be made over HTTPS. + * + * @default `true` for v4.20.0 onwards, `false` before v4.20.0 + */ + ssl?: boolean; + /** + * If a custom domain is required, SDK accepts it here. + * + * @default `ps.pndsn.com` + */ + origin?: string | string[]; + /** + * How long the server will consider the client alive for presence.The value is in seconds. + * + * @default `300` + */ + presenceTimeout?: number; + /** + * How often the client will announce itself to server.The value is in seconds. + * + * @default `not set` + */ + heartbeatInterval?: number; + /** + * Transactional requests timeout in milliseconds. + * + * Maximum duration for which PubNub client should wait for transactional request completion. + * + * @default `15` seconds + */ + transactionalRequestTimeout?: number; + /** + * Subscription requests timeout in milliseconds. + * + * Maximum duration for which PubNub client should wait for subscription request completion. + * + * @default `310` seconds + */ + subscribeRequestTimeout?: number; + /** + * `true` to allow catch up on the front-end applications. + * + * @default `false` + */ + restore?: boolean; + /** + * Whether to include the PubNub object instance ID in outgoing requests. + * + * @default `false` + */ + useInstanceId?: boolean; + /** + * When `true` the SDK doesn't send out the leave requests. + * + * @default `false` + */ + suppressLeaveEvents?: boolean; + /** + * `PNRequestMessageCountExceededCategory` is thrown when the number of messages into the + * payload is above of `requestMessageCountThreshold`. + * + * @default `100` + */ + requestMessageCountThreshold?: number; + /** + * This flag announces when the network is down or up using the states `PNNetworkDownCategory` + * and `PNNetworkUpCategory`. + * + * @default `false` + */ + autoNetworkDetection?: boolean; + /** + * Whether to use the standardized workflows for subscribe and presence. + * + * Note that the `maintainPresenceState` parameter is set to true by default, so make sure to + * disable it if you don't need to maintain presence state. For more information, refer to the + * param description in this table. + * + * + * @default `false` + */ + enableEventEngine?: boolean; + /** + * Custom reconnection configuration parameters. + * + * `retryConfiguration: policy` is the type of policy to be used. + * + * Available values: + * - `PubNub.LinearRetryPolicy({ delay, maximumRetry })` + * - `PubNub.ExponentialRetryPolicy({ minimumDelay, maximumDelay, maximumRetry })` + * + * For more information, refer to + * {@link /docs/general/setup/connection-management#reconnection-policy|Reconnection Policy}. JavaScript doesn't + * support excluding endpoints. + * + * @default `not set` + */ + retryConfiguration?: RequestRetryPolicy; + /** + * Whether the `state` set using `setState()` should be maintained for the current `userId`. + * This option works only when `enableEventEngine` is set to `true`. + * + * @default `true` + */ + maintainPresenceState?: boolean; + /** + * `UUID` to use. You should set a unique `UUID` to identify the user or the device that + * connects to PubNub. + * If you don't set the `UUID`, you won't be able to connect to PubNub. + * + * @deprecated Use {@link userId} instead. + */ + uuid?: string; + /** + * If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of + * opening a new one for each new request. + * + * @default `false` + */ + keepAlive?: boolean; + /** + * If the SDK is running as part of another SDK built atop of it, allow a custom `pnsdk` with + * name and version. + */ + sdkName?: string; + /** + * If the SDK is operated by a partner, allow a custom `pnsdk` item for them. + */ + partnerId?: string; + }; + + /** + * User-provided configuration object interface. + * + * Interface contains limited set of settings manipulation and access. + */ + export interface ClientConfiguration { + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + */ + getUserId(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @throws Error empty user identifier has been provided. + */ + setUserId(value: string): void; + /** + * Change REST API endpoint access authorization key. + * + * @param authKey - New authorization key which should be used with new requests. + */ + setAuthKey(authKey: string | null): void; + /** + * Real-time updates filtering expression. + * + * @returns Filtering expression. + */ + getFilterExpression(): string | undefined | null; + /** + * Update real-time updates filtering expression. + * + * @param expression - New expression which should be used or `undefined` to disable filtering. + */ + setFilterExpression(expression: string | null | undefined): void; + /** + * Change data encryption / decryption key. + * + * @param key - New key which should be used for data encryption / decryption. + */ + setCipherKey(key: string | undefined): void; + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + get version(): string; + /** + * Get PubNub SDK version. + * + * @returns Current SDK version. + */ + getVersion(): string; + /** + * Add framework's prefix. + * + * @param name - Name of the framework which would want to add own data into `pnsdk` suffix. + * @param suffix - Suffix with information about framework. + */ + _addPnsdkSuffix(name: string, suffix: string | number): void; + /** + * Get a PubNub client user identifier. + * + * @returns Current PubNub client user identifier. + * + * @deprecated Use the {@link getUserId} or {@link userId} getter instead. + */ + getUUID(): string; + /** + * Change the current PubNub client user identifier. + * + * **Important:** Change won't affect ongoing REST API calls. + * + * @param value - New PubNub client user identifier. + * + * @returns {Configuration} Reference to the configuration instance for easier chaining. + * + * @throws Error empty user identifier has been provided. + * + * @deprecated Use the {@link setUserId} or {@link userId} setter instead. + */ + setUUID(value: string): void; + } + + /** + * Failed request retry policy. + */ + export class RetryPolicy { + static LinearRetryPolicy( + configuration: LinearRetryPolicyConfiguration, + ): RequestRetryPolicy & LinearRetryPolicyConfiguration; + static ExponentialRetryPolicy( + configuration: ExponentialRetryPolicyConfiguration, + ): RequestRetryPolicy & ExponentialRetryPolicyConfiguration; + } + + export type RequestRetryPolicy = { + /** + * Check whether failed request can be retried. + * + * @param reason - Request processing failure reason. + * @param attempt - Number of sequential failure. + * + * @returns `true` if another request retry attempt can be done. + */ + shouldRetry( + reason: PubNubError & { + retryAfter?: number; + }, + attempt: number, + ): boolean; + /** + * Computed delay for next request retry attempt. + * + * @param attempt - Number of sequential failure. + * @param reason - Request processing failure reason. + * + * @returns Delay before next request retry attempt in milliseconds. + */ + getDelay( + attempt: number, + reason: PubNubError & { + retryAfter?: number; + }, + ): number; + /** + * Identify reason why another retry attempt can't be made. + * + * @param reason - Request processing failure reason. + * @param attempt - Number of sequential failure. + * + * @returns Give up reason. + */ + getGiveupReason( + reason: PubNubError & { + retryAfter?: number; + }, + attempt: number, + ): string; + /** + * Validate retry policy parameters. + * + * @throws Error if `minimum` delay is smaller than 2 seconds for `exponential` retry policy. + * @throws Error if `maximum` delay is larger than 150 seconds for `exponential` retry policy. + * @throws Error if `maximumRetry` attempts is larger than 6 for `exponential` retry policy. + * @throws Error if `maximumRetry` attempts is larger than 10 for `linear` retry policy. + */ + validate(): void; + }; + + export type LinearRetryPolicyConfiguration = { + delay: number; + maximumRetry: number; + }; + + export type ExponentialRetryPolicyConfiguration = { + minimumDelay: number; + maximumDelay: number; + maximumRetry: number; + }; + + /** + * PubNub operation error. + * + * When an operation can't be performed or there is an error from the server, this object will be returned. + */ + export class PubNubError extends Error { + status?: Status | undefined; + } + + /** + * Represents the configuration options for keeping the transport connection alive. + */ + export type TransportKeepAlive = { + /** + * The time interval in milliseconds for keeping the connection alive. + * + * @default 1000 + */ + keepAliveMsecs?: number; + /** + * The maximum number of sockets allowed per host. + * + * @default Infinity + */ + maxSockets?: number; + /** + * The maximum number of open and free sockets in the pool per host. + * + * @default 256 + */ + maxFreeSockets?: number; + /** + * Timeout in milliseconds, after which the `idle` socket will be closed. + * + * @default 30000 + */ + timeout?: number; + }; + + /** + * This interface is used to send requests to the PubNub API. + * + * You can implement this interface for your types, or use one of the provided modules to use a + * transport library. + * + * @interface + */ + export interface Transport { + /** + * Make request sendable. + * + * @param req - The transport request to be processed. + * + * @returns - A promise that resolves to a transport response and request cancellation + * controller (if required). + */ + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; + /** + * Pre-processed request. + * + * Transport implementation may pre-process original transport requests before making + * platform-specific request objects from it. + * + * @param req - Transport request provided by the PubNub client. + * + * @returns Transport request with updated properties (if it was required). + */ + request(req: TransportRequest): TransportRequest; + } + + /** + * Enum representing possible transport methods for HTTP requests. + * + * @enum {number} + */ + export enum TransportMethod { + /** + * Request will be sent using `GET` method. + */ + GET = 'GET', + /** + * Request will be sent using `POST` method. + */ + POST = 'POST', + /** + * Request will be sent using `PATCH` method. + */ + PATCH = 'PATCH', + /** + * Request will be sent using `DELETE` method. + */ + DELETE = 'DELETE', + /** + * Local request. + * + * Request won't be sent to the service and probably used to compute URL. + */ + LOCAL = 'LOCAL', + } + + /** + * Request cancellation controller. + */ + export type CancellationController = { + /** + * Request cancellation / abort function. + */ + abort: () => void; + }; + + /** + * This object represents a request to be sent to the PubNub API. + * + * This struct represents a request to be sent to the PubNub API. It is used by the transport + * provider which implements {@link Transport} interface. + * + * All fields are representing certain parts of the request that can be used to prepare one. + */ + export type TransportRequest = { + /** + * Remote host name. + */ + origin?: string; + /** + * Remote resource path. + */ + path: string; + /** + * Query parameters to be sent with the request. + */ + queryParameters?: Query; + /** + * Transport request HTTP method. + */ + method: TransportMethod; + /** + * Headers to be sent with the request. + */ + headers?: Record; + /** + * Multipart form data fields. + * + * **Important:** `Content-Type` header should be sent the {@link body} data type when + * `multipart/form-data` should request should be sent. + */ + formData?: Record[]; + /** + * Body to be sent with the request. + */ + body?: ArrayBuffer | PubNubFileInterface | string; + /** + * For how long request should wait response from the server. + * + * @default `10` seconds. + */ + timeout: number; + /** + * Whether request can be cancelled or not. + * + * @default `false`. + */ + cancellable: boolean; + /** + * Unique request identifier. + */ + identifier: string; + }; + + /** + * Represents a transport response from a service. + */ + export type TransportResponse = { + /** + * Full remote resource URL used to retrieve response. + */ + url: string; + /** + * Service response status code. + */ + status: number; + /** + * Service response headers. + * + * **Important:** Header names are in lowercase. + */ + headers: Record; + /** + * Service response body. + */ + body?: ArrayBuffer; + }; + + /** + * Real-time events listener. + */ + export type Listener = { + /** + * Real-time message events listener. + * + * @param message - Received message. + */ + message?: (message: Subscription.Message) => void; + /** + * Real-time message signal listener. + * + * @param signal - Received signal. + */ + signal?: (signal: Subscription.Signal) => void; + /** + * Real-time presence change events listener. + * + * @param presence - Received presence chane information. + */ + presence?: (presence: Subscription.Presence) => void; + /** + * Real-time App Context Objects change events listener. + * + * @param object - Changed App Context Object information. + */ + objects?: (object: Subscription.AppContextObject) => void; + /** + * Real-time message actions events listener. + * + * @param action - Message action information. + */ + messageAction?: (action: Subscription.MessageAction) => void; + /** + * Real-time file share events listener. + * + * @param file - Shared file information. + */ + file?: (file: Subscription.File) => void; + /** + * Real-time PubNub client status change event. + * + * @param status - PubNub client status information + */ + status?: (status: Status | StatusEvent) => void; + /** + * Real-time User App Context Objects change events listener. + * + * @param user - User App Context Object information. + * + * @deprecated Use {@link objects} listener callback instead. + */ + user?: (user: Subscription.UserAppContextObject) => void; + /** + * Real-time Space App Context Objects change events listener. + * + * @param space - Space App Context Object information. + * + * @deprecated Use {@link objects} listener callback instead. + */ + space?: (space: Subscription.SpaceAppContextObject) => void; + /** + * Real-time VSP Membership App Context Objects change events listener. + * + * @param membership - VSP Membership App Context Object information. + * + * @deprecated Use {@link objects} listener callback instead. + */ + membership?: (membership: Subscription.VSPMembershipAppContextObject) => void; + }; + + /** + * PubNub-defined event types by payload. + */ + export enum PubNubEventType { + /** + * Presence change event. + */ + Presence = -2, + /** + * Regular message event. + * + * **Note:** This is default type assigned for non-presence events if `e` field is missing. + */ + Message = -1, + /** + * Signal data event. + */ + Signal = 1, + /** + * App Context object event. + */ + AppContext = 2, + /** + * Message reaction event. + */ + MessageAction = 3, + /** + * Files event. + */ + Files = 4, + } + + /** + * Periodical presence change service response. + */ + type PresenceIntervalData = { + /** + * Periodical subscribed channels and groups presence change announcement. + */ + action: 'interval'; + /** + * Unix timestamp when presence event has been triggered. + */ + timestamp: number; + /** + * The current occupancy after the presence change is updated. + */ + occupancy: number; + /** + * The list of unique user identifiers that `joined` the channel since the last interval + * presence update. + */ + join?: string[]; + /** + * The list of unique user identifiers that `left` the channel since the last interval + * presence update. + */ + leave?: string[]; + /** + * The list of unique user identifiers that `timeout` the channel since the last interval + * presence update. + */ + timeout?: string[]; + }; + + /** + * Subscribed user presence information change service response. + */ + type PresenceChangeData = { + /** + * Change if user's presence. + * + * User's presence may change between: `join`, `leave` and `timeout`. + */ + action: 'join' | 'leave' | 'timeout'; + /** + * Unix timestamp when presence event has been triggered. + */ + timestamp: number; + /** + * Unique identification of the user for whom presence information changed. + */ + uuid: string; + /** + * The current occupancy after the presence change is updated. + */ + occupancy: number; + /** + * The user's state associated with the channel has been updated. + * + * @deprecated Use set state methods to specify associated user's data instead of passing to + * subscribe. + */ + data?: { + [p: string]: Payload; + }; + }; + + /** + * Associated user presence state change service response. + */ + type PresenceStateChangeData = { + /** + * Subscribed user associated presence state change. + */ + action: 'state-change'; + /** + * Unix timestamp when presence event has been triggered. + */ + timestamp: number; + /** + * Unique identification of the user for whom associated presence state has been changed. + */ + uuid: string; + /** + * The user's state associated with the channel has been updated. + */ + state: { + [p: string]: Payload; + }; + }; + + /** + * Channel presence service response. + */ + export type PresenceData = PresenceIntervalData | PresenceChangeData | PresenceStateChangeData; + + /** + * Message reaction change service response. + */ + export type MessageActionData = { + /** + * The type of event that happened during the message action update. + * + * Possible values are: + * - `added` - action has been added to the message + * - `removed` - action has been removed from message + */ + event: 'added' | 'removed'; + /** + * Information about message action for which update has been generated. + */ + data: { + /** + * Timetoken of message for which action has been added / removed. + */ + messageTimetoken: string; + /** + * Timetoken of message action which has been added / removed. + */ + actionTimetoken: string; + /** + * Message action type. + */ + type: string; + /** + * Value associated with message action {@link type}. + */ + value: string; + }; + /** + * Name of service which generated update for message action. + */ + source: string; + /** + * Version of service which generated update for message action. + */ + version: string; + }; + + /** + * VSP Objects change events. + */ + type AppContextVSPEvents = 'updated' | 'removed'; + + /** + * App Context Objects change events. + */ + type AppContextEvents = 'set' | 'delete'; + + /** + * Common real-time App Context Object service response. + */ + type ObjectData = { + /** + * The type of event that happened during the object update. + */ + event: Event; + /** + * App Context object type. + */ + type: Type; + /** + * App Context object information. + * + * App Context object can be one of: + * - `channel` / `space` + * - `uuid` / `user` + * - `membership` + */ + data: AppContextObject; + /** + * Name of service which generated update for object. + */ + source: string; + /** + * Version of service which generated update for object. + */ + version: string; + }; + + /** + * `Channel` object change real-time service response. + */ + type ChannelObjectData = ObjectData< + AppContextEvents, + 'channel', + AppContext.ChannelMetadataObject + >; + + /** + * `Space` object change real-time service response. + */ + export type SpaceObjectData = ObjectData< + AppContextVSPEvents, + 'space', + AppContext.ChannelMetadataObject + >; + + /** + * `Uuid` object change real-time service response. + */ + type UuidObjectData = ObjectData>; + + /** + * `User` object change real-time service response. + */ + export type UserObjectData = ObjectData< + AppContextVSPEvents, + 'user', + AppContext.UUIDMetadataObject + >; + + /** + * `Membership` object change real-time service response. + */ + type MembershipObjectData = ObjectData< + AppContextEvents, + 'membership', + Omit, 'id'> & { + /** + * `Uuid` object which has been used to create relationship with `channel`. + */ + uuid: { + /** + * Unique `user` object identifier. + */ + id: string; + }; + /** + * `Channel` object which has been used to create relationship with `uuid`. + */ + channel: { + /** + * Unique `channel` object identifier. + */ + id: string; + }; + } + >; + + /** + * VSP `Membership` object change real-time service response. + */ + export type VSPMembershipObjectData = ObjectData< + AppContextVSPEvents, + 'membership', + Omit, 'id'> & { + /** + * `User` object which has been used to create relationship with `space`. + */ + user: { + /** + * Unique `user` object identifier. + */ + id: string; + }; + /** + * `Space` object which has been used to create relationship with `user`. + */ + space: { + /** + * Unique `channel` object identifier. + */ + id: string; + }; + } + >; + + /** + * App Context service response. + */ + export type AppContextObjectData = ChannelObjectData | UuidObjectData | MembershipObjectData; + + /** + * File service response. + */ + export type FileData = { + /** + * Message which has been associated with uploaded file. + */ + message?: Payload; + /** + * Information about uploaded file. + */ + file: { + /** + * Unique identifier of uploaded file. + */ + id: string; + /** + * Actual name with which file has been stored. + */ + name: string; + }; + }; + + /** + * Payload for `pn_apns` field in published message. + */ + type APNSPayload = { + /** + * Payload for Apple Push Notification Service. + */ + aps: { + /** + * Configuration of visual notification representation. + */ + alert?: { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string; + /** + * Second line title. + * + * Subtitle which is shown under main title with smaller font. + */ + subtitle?: string; + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string; + }; + /** + * Unread notifications count badge value. + */ + badge?: number | null; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string; + /** + * Silent notification flag. + */ + 'content-available'?: 1; + }; + /** + * APNS2 payload recipients information. + */ + pn_push: PubNubAPNS2Configuration[]; + }; + + /** + * APNS2 configuration type. + */ + type APNS2Configuration = { + /** + * Notification group / collapse identifier. Value will be used in APNS POST request as `apns-collapse-id` header + * value. + */ + collapseId?: string; + /** + * Date till which APNS will try to deliver notification to target device. Value will be used in APNS POST request as + * `apns-expiration` header value. + */ + expirationDate?: Date; + /** + * List of topics which should receive this notification. + */ + targets: APNS2Target[]; + }; + + /** + * Preformatted for PubNub service `APNS2` configuration type. + */ + type PubNubAPNS2Configuration = { + /** + * PubNub service authentication method for APNS. + */ + auth_method: 'token'; + /** + * Target entities which should receive notification. + */ + targets: PubNubAPNS2Target[]; + /** + * Notifications group collapse identifier. + */ + collapse_id?: string; + /** + * Notification receive expiration date. + * + * Date after which notification won't be delivered. + */ + expiration?: string; + /** + * APNS protocol version. + */ + version: 'v2'; + }; + + /** + * APNS2 configuration target type. + */ + type APNS2Target = { + /** + * Notifications topic name (usually it is bundle identifier of application for Apple platform). + * + * **Important:** Required only if `pushGateway` is set to `apns2`. + */ + topic: string; + /** + * Environment within which registered devices to which notifications should be delivered. + * + * Available: + * - `development` + * - `production` + * + * @default `development` + */ + environment?: 'development' | 'production'; + /** + * List of devices (their push tokens) to which this notification shouldn't be delivered. + */ + excludedDevices?: string[]; + }; + + /** + * Preformatted for PubNub service `APNS2` configuration target type. + */ + type PubNubAPNS2Target = Omit & { + /** + * List of devices (their push tokens) to which this notification shouldn't be delivered. + */ + excluded_devices?: string[]; + }; + + /** + * Payload for `pn_gcm` field in published message. + */ + type FCMPayload = { + /** + * Configuration of visual notification representation. + */ + notification?: { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string; + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string; + /** + * Name of the icon file from resource bundle which should be shown on notification. + */ + icon?: string; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string; + tag?: string; + }; + /** + * Configuration of data notification. + * + * Silent notification configuration. + */ + data?: { + notification?: FCMPayload['notification']; + }; + }; + + /** + * Base notification payload object. + */ + class BaseNotificationPayload { + /** + * Retrieve resulting notification payload content for message. + * + * @returns Preformatted push notification payload data. + */ + get payload(): unknown; + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value: string | undefined); + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value: string | undefined); + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value: string | undefined); + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value: number | null | undefined); + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value: string | undefined); + } + + /** + * Message payload for Apple Push Notification Service. + */ + export class APNSNotificationPayload extends BaseNotificationPayload { + get payload(): APNSPayload; + /** + * Update notification receivers configuration. + * + * @param value - New APNS2 configurations. + */ + set configurations(value: APNS2Configuration[]); + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ + get notification(): { + /** + * Configuration of visual notification representation. + */ + alert?: { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string; + /** + * Second line title. + * + * Subtitle which is shown under main title with smaller font. + */ + subtitle?: string; + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string; + }; + /** + * Unread notifications count badge value. + */ + badge?: number | null; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string; + /** + * Silent notification flag. + */ + 'content-available'?: 1; + }; + /** + * Notification title. + * + * @returns Main notification title. + */ + get title(): string | undefined; + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value: string | undefined); + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ + get subtitle(): string | undefined; + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value: string | undefined); + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body(): string | undefined; + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value: string | undefined); + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ + get badge(): number | null | undefined; + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value: number | null | undefined); + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound(): string | undefined; + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value: string | undefined); + /** + * Set whether notification should be silent or not. + * + * `content-available` notification type will be used to deliver silent notification if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ + set silent(value: boolean); + } + + /** + * Message payload for Firebase Cloud Messaging service. + */ + export class FCMNotificationPayload extends BaseNotificationPayload { + get payload(): FCMPayload; + /** + * Notification payload. + * + * @returns Platform-specific part of PubNub notification payload. + */ + get notification(): + | { + /** + * First line title. + * + * Title which is shown in bold on the first line of notification bubble. + */ + title?: string; + /** + * Notification body. + * + * Body which is shown to the user after interaction with notification. + */ + body?: string; + /** + * Name of the icon file from resource bundle which should be shown on notification. + */ + icon?: string; + /** + * Name of the file from resource bundle which should be played when notification received. + */ + sound?: string; + tag?: string; + } + | undefined; + /** + * Silent notification payload. + * + * @returns Silent notification payload (data notification). + */ + get data(): + | { + notification?: FCMPayload['notification']; + } + | undefined; + /** + * Notification title. + * + * @returns Main notification title. + */ + get title(): string | undefined; + /** + * Update notification title. + * + * @param value - New notification title. + */ + set title(value: string | undefined); + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body(): string | undefined; + /** + * Update notification body. + * + * @param value - Update main notification message (shown when expanded). + */ + set body(value: string | undefined); + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound(): string | undefined; + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value: string | undefined); + /** + * Retrieve notification icon file. + * + * @returns Notification icon file name from resource bundle. + */ + get icon(): string | undefined; + /** + * Update notification icon. + * + * @param value - Name of the icon file which should be shown on notification. + */ + set icon(value: string | undefined); + /** + * Retrieve notifications grouping tag. + * + * @returns Notifications grouping tag. + */ + get tag(): string | undefined; + /** + * Update notifications grouping tag. + * + * @param value - String which will be used to group similar notifications in notification center. + */ + set tag(value: string | undefined); + /** + * Set whether notification should be silent or not. + * + * All notification data will be sent under `data` field if set to `true`. + * + * @param value - Whether notification should be sent as silent or not. + */ + set silent(value: boolean); + } + + export class NotificationsPayload { + /** + * APNS-specific message payload. + */ + apns: APNSNotificationPayload; + /** + * FCM-specific message payload. + */ + fcm: FCMNotificationPayload; + /** + * Enable or disable push notification debugging message. + * + * @param value - Whether debug message from push notification scheduler should be published to the specific + * channel or not. + */ + set debugging(value: boolean); + /** + * Notification title. + * + * @returns Main notification title. + */ + get title(): string; + /** + * Notification subtitle. + * + * @returns Second-line notification title. + */ + get subtitle(): string | undefined; + /** + * Update notification subtitle. + * + * @param value - New second-line notification title. + */ + set subtitle(value: string | undefined); + /** + * Notification body. + * + * @returns Main notification message (shown when expanded). + */ + get body(): string; + /** + * Retrieve unread notifications number. + * + * @returns Number of unread notifications which should be shown on application badge. + */ + get badge(): number | undefined; + /** + * Update application badge number. + * + * @param value - Number which should be shown in application badge upon receiving notification. + */ + set badge(value: number | undefined); + /** + * Retrieve notification sound file. + * + * @returns Notification sound file name from resource bundle. + */ + get sound(): string | undefined; + /** + * Update notification sound. + * + * @param value - Name of the sound file which should be played upon notification receive. + */ + set sound(value: string | undefined); + /** + * Build notifications platform for requested platforms. + * + * @param platforms - List of platforms for which payload should be added to final dictionary. Supported values: + * fcm, apns, and apns2. + * + * @returns Object with data, which can be sent with publish method call and trigger remote notifications for + * specified platforms. + */ + buildPayload(platforms: ('apns' | 'apns2' | 'fcm')[]): { + pn_apns?: APNSPayload; + pn_gcm?: FCMPayload; + pn_debug?: boolean; + }; + } + + /** + * PubNub entity subscription configuration options. + */ + export type SubscriptionOptions = { + /** + * Whether presence events for entity should be received or not. + */ + receivePresenceEvents?: boolean; + }; + + /** + * First-class objects which provides access to the channel app context object-specific APIs. + */ + export class ChannelMetadata { + /** + * Create channel's app context subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific channel + * app context object. + * + * @param [subscriptionOptions] - Channel's app context subscription object behavior customization options. + * + * @returns Configured and ready to use channel's app context subscription object. + */ + subscription(subscriptionOptions?: SubscriptionOptions): Subscription; + } + + /** + * Single-entity subscription object which can be used to receive and handle real-time updates. + */ + export class Subscription extends SubscribeCapable { + /** + * Merge entities' subscription objects into subscription set. + * + * @param subscription - Other entity's subscription object to be merged with receiver. + * @return Subscription set which contains both receiver and other entities' subscription objects. + */ + addSubscription(subscription: Subscription): SubscriptionSet; + } + + export abstract class SubscribeCapable { + /** + * Start receiving real-time updates. + * + * @param subscribeParameters - Additional subscription configuration options which should be used + * for request. + */ + subscribe(subscribeParameters?: { timetoken?: string }): void; + /** + * Stop real-time events processing. + */ + unsubscribe(): void; + /** + * Set new message handler. + * + * @param onMessageListener - Listener function, which will be called each time when a new message + * is received from the real-time network. + */ + set onMessage(onMessageListener: (messageEvent: Subscription.Message) => void); + /** + * Set new presence events handler. + * + * @param onPresenceListener - Listener function, which will be called each time when a new + * presence event is received from the real-time network. + */ + set onPresence(onPresenceListener: (presenceEvent: Subscription.Presence) => void); + /** + * Set new signal handler. + * + * @param onSignalListener - Listener function, which will be called each time when a new signal + * is received from the real-time network. + */ + set onSignal(onSignalListener: (signalEvent: Subscription.Signal) => void); + /** + * Set new app context event handler. + * + * @param onObjectsListener - Listener function, which will be called each time when a new + * app context event is received from the real-time network. + */ + set onObjects(onObjectsListener: (objectsEvent: Subscription.AppContextObject) => void); + /** + * Set new message reaction event handler. + * + * @param messageActionEventListener - Listener function, which will be called each time when a + * new message reaction event is received from the real-time network. + */ + set onMessageAction(messageActionEventListener: (messageActionEvent: Subscription.MessageAction) => void); + /** + * Set new file handler. + * + * @param fileEventListener - Listener function, which will be called each time when a new file + * is received from the real-time network. + */ + set onFile(fileEventListener: (fileEvent: Subscription.File) => void); + /** + * Set events handler. + * + * @param listener - Events listener configuration object, which lets specify handlers for multiple + * types of events. + */ + addListener(listener: Listener): void; + /** + * Remove events handler. + * + * @param listener - Event listener configuration, which should be removed from the list of notified + * listeners. **Important:** Should be the same object which has been passed to the + * {@link addListener}. + */ + removeListener(listener: Listener): void; + /** + * Get list of channels which is used for subscription. + * + * @returns List of channel names. + */ + get channels(): string[]; + /** + * Get list of channel groups which is used for subscription. + * + * @returns List of channel group names. + */ + get channelGroups(): string[]; + } + + /** + * Multiple entities subscription set object which can be used to receive and handle real-time + * updates. + * + * Subscription set object represent collection of per-entity subscription objects and allow + * processing them at once for subscription loop and events handling. + */ + export class SubscriptionSet extends SubscribeCapable { + /** + * Add additional entity's subscription to the subscription set. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#subscribe} call or + * next subscription loop. + * + * @param subscription - Other entity's subscription object, which should be added. + */ + addSubscription(subscription: Subscription): void; + /** + * Remove entity's subscription object from the set. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#unsubscribe} call or + * next subscription loop. + * + * @param subscription - Other entity's subscription object, which should be removed. + */ + removeSubscription(subscription: Subscription): void; + /** + * Merge with other subscription set object. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#subscribe} call or + * next subscription loop. + * + * @param subscriptionSet - Other entities' subscription set, which should be joined. + */ + addSubscriptionSet(subscriptionSet: SubscriptionSet): void; + /** + * Subtract other subscription set object. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#unsubscribe} call or + * next subscription loop. + * + * @param subscriptionSet - Other entities' subscription set, which should be subtracted. + */ + removeSubscriptionSet(subscriptionSet: SubscriptionSet): void; + /** + * Get list of entities' subscription objects registered in subscription set. + * + * @returns Entities' subscription objects list. + */ + get subscriptions(): Subscription[]; + } + + /** + * First-class objects which provides access to the channel group-specific APIs. + */ + export class ChannelGroup { + /** + * Create channel group's subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the channels in + * specific channel group. + * + * @param [subscriptionOptions] - Channel group's subscription object behavior customization options. + * + * @returns Configured and ready to use channel group's subscription object. + */ + subscription(subscriptionOptions?: SubscriptionOptions): Subscription; + } + + /** + * First-class objects which provides access to the user app context object-specific APIs. + */ + export class UserMetadata { + /** + * Create user's app context subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific user + * app context object. + * + * @param [subscriptionOptions] - User's app context subscription object behavior customization options. + * + * @returns Configured and ready to use user's app context subscription object. + */ + subscription(subscriptionOptions?: SubscriptionOptions): Subscription; + } + + /** + * First-class objects which provides access to the channel-specific APIs. + */ + export class Channel { + /** + * Create channel's subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific channel. + * + * @param [subscriptionOptions] - Channel's subscription object behavior customization options. + * + * @returns Configured and ready to use channel's subscription object. + */ + subscription(subscriptionOptions?: SubscriptionOptions): Subscription; + } + + /** + * PubNub Stream / Channel group API interface. + */ + export class PubNubChannelGroups { + /** + * Fetch channel group channels. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + listChannels( + parameters: ChannelGroups.ListChannelGroupChannelsParameters, + callback: ResultCallback, + ): void; + /** + * Fetch channel group channels. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get channel group channels response. + */ + listChannels( + parameters: ChannelGroups.ListChannelGroupChannelsParameters, + ): Promise; + /** + * Fetch all channel groups. + * + * @param callback - Request completion handler callback. + * + * @deprecated + */ + listGroups(callback: ResultCallback): void; + /** + * Fetch all channel groups. + * + * @returns Asynchronous get all channel groups response. + * + * @deprecated + */ + listGroups(): Promise; + /** + * Add channels to the channel group. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + addChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters, callback: StatusCallback): void; + /** + * Add channels to the channel group. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous add channels to the channel group response. + */ + addChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters): Promise>; + /** + * Remove channels from the channel group. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters, callback: StatusCallback): void; + /** + * Remove channels from the channel group. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous remove channels from the channel group response. + */ + removeChannels(parameters: ChannelGroups.ManageChannelGroupChannelsParameters): Promise>; + /** + * Remove channel group. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + deleteGroup(parameters: ChannelGroups.DeleteChannelGroupParameters, callback: StatusCallback): void; + /** + * Remove channel group. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous remove channel group response. + */ + deleteGroup(parameters: ChannelGroups.DeleteChannelGroupParameters): Promise>; + } + + /** + * PubNub Push Notifications API interface. + */ + export class PubNubPushNotifications { + /** + * Fetch device's push notification enabled channels. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + listChannels( + parameters: Push.ListDeviceChannelsParameters, + callback: ResultCallback, + ): void; + /** + * Fetch device's push notification enabled channels. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get device channels response. + */ + listChannels(parameters: Push.ListDeviceChannelsParameters): Promise; + /** + * Enable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + addChannels(parameters: Push.ManageDeviceChannelsParameters, callback: StatusCallback): void; + /** + * Enable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + */ + addChannels(parameters: Push.ManageDeviceChannelsParameters): Promise; + /** + * Disable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeChannels(parameters: Push.ManageDeviceChannelsParameters, callback: StatusCallback): void; + /** + * Disable push notifications on channels for device. + * + * @param parameters - Request configuration parameters. + */ + removeChannels(parameters: Push.ManageDeviceChannelsParameters): Promise; + /** + * Disable push notifications for device. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + deleteDevice(parameters: Push.RemoveDeviceParameters, callback: StatusCallback): void; + /** + * Disable push notifications for device. + * + * @param parameters - Request configuration parameters. + */ + deleteDevice(parameters: Push.RemoveDeviceParameters): Promise; + } + + /** + * PubNub App Context API interface. + */ + export class PubNubObjects { + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param callback - Request completion handler callback. + */ + getAllUUIDMetadata( + callback: ResultCallback>, + ): void; + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getAllUUIDMetadata( + parameters: AppContext.GetAllMetadataParameters>, + callback: ResultCallback>, + ): void; + /** + * Fetch a paginated list of UUID Metadata objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all UUID metadata response. + */ + getAllUUIDMetadata( + parameters?: AppContext.GetAllMetadataParameters>, + ): Promise>; + /** + * Fetch UUID Metadata object for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + */ + getUUIDMetadata( + callback: ResultCallback>, + ): void; + /** + * Fetch a specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will fetch UUID metadata object for + * currently configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + */ + getUUIDMetadata( + parameters: AppContext.GetUUIDMetadataParameters, + callback: ResultCallback>, + ): void; + /** + * Fetch a specific UUID Metadata object. + * + * @param [parameters] - Request configuration parameters. Will fetch UUID Metadata object for + * currently configured PubNub client `uuid` if not set. + * + * @returns Asynchronous get UUID metadata response. + */ + getUUIDMetadata( + parameters?: AppContext.GetUUIDMetadataParameters, + ): Promise>; + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + */ + setUUIDMetadata( + parameters: AppContext.SetUUIDMetadataParameters, + callback: ResultCallback>, + ): void; + /** + * Update specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will set UUID metadata for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous set UUID metadata response. + */ + setUUIDMetadata( + parameters: AppContext.SetUUIDMetadataParameters, + ): Promise>; + /** + * Remove UUID Metadata object for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + */ + removeUUIDMetadata(callback: ResultCallback): void; + /** + * Remove a specific UUID Metadata object. + * + * @param parameters - Request configuration parameters. Will remove UUID metadata for currently + * configured PubNub client `uuid` if not set. + * @param callback - Request completion handler callback. + */ + removeUUIDMetadata( + parameters: AppContext.RemoveUUIDMetadataParameters, + callback: ResultCallback, + ): void; + /** + * Remove a specific UUID Metadata object. + * + * @param [parameters] - Request configuration parameters. Will remove UUID metadata for currently + * configured PubNub client `uuid` if not set. + * + * @returns Asynchronous UUID metadata remove response. + */ + removeUUIDMetadata( + parameters?: AppContext.RemoveUUIDMetadataParameters, + ): Promise; + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param callback - Request completion handler callback. + */ + getAllChannelMetadata( + callback: ResultCallback>, + ): void; + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getAllChannelMetadata( + parameters: AppContext.GetAllMetadataParameters>, + callback: ResultCallback>, + ): void; + /** + * Fetch a paginated list of Channel Metadata objects. + * + * @param [parameters] - Request configuration parameters. + * + * @returns Asynchronous get all Channel metadata response. + */ + getAllChannelMetadata( + parameters?: AppContext.GetAllMetadataParameters>, + ): Promise>; + /** + * Fetch Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getChannelMetadata( + parameters: AppContext.GetChannelMetadataParameters, + callback: ResultCallback>, + ): void; + /** + * Fetch a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get Channel metadata response. + */ + getChannelMetadata( + parameters: AppContext.GetChannelMetadataParameters, + ): Promise>; + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + setChannelMetadata( + parameters: AppContext.SetChannelMetadataParameters, + callback: ResultCallback>, + ): void; + /** + * Update specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous set Channel metadata response. + */ + setChannelMetadata( + parameters: AppContext.SetChannelMetadataParameters, + ): Promise>; + /** + * Remove Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeChannelMetadata( + parameters: AppContext.RemoveChannelMetadataParameters, + callback: ResultCallback, + ): void; + /** + * Remove a specific Channel Metadata object. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous Channel metadata remove response. + */ + removeChannelMetadata( + parameters: AppContext.RemoveChannelMetadataParameters, + ): Promise; + /** + * Fetch a paginated list of Channel Member objects. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembersParameters, + callback: ResultCallback>, + ): void; + /** + * Fetch a paginated list of Channel Member objects. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous get Channel Members response. + */ + getChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >(parameters: AppContext.GetMembersParameters): Promise>; + /** + * Update specific Channel Members list. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + setChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetChannelMembersParameters, + callback: ResultCallback>, + ): void; + /** + * Update specific Channel Members list. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous update Channel Members list response. + */ + setChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetChannelMembersParameters, + ): Promise>; + /** + * Remove Members from the Channel. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembersParameters, + callback: ResultCallback>, + ): void; + /** + * Remove Members from the Channel. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous Channel Members remove response. + */ + removeChannelMembers< + MemberCustom extends AppContext.CustomData = AppContext.CustomData, + UUIDCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembersParameters, + ): Promise>; + /** + * Fetch a specific UUID Memberships list for currently configured PubNub client `uuid`. + * + * @param callback - Request completion handler callback. + * + * @returns Asynchronous get UUID Memberships list response or `void` in case if `callback` + * provided. + */ + getMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >(callback: ResultCallback>): void; + /** + * Fetch a specific UUID Memberships list. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + getMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembershipsParameters, + callback: ResultCallback>, + ): void; + /** + * Fetch a specific UUID Memberships list. + * + * @param [parameters] - Request configuration parameters. Will fetch UUID Memberships list for + * currently configured PubNub client `uuid` if not set. + * + * @returns Asynchronous get UUID Memberships list response. + */ + getMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters?: AppContext.GetMembershipsParameters, + ): Promise>; + /** + * Update specific UUID Memberships list. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + setMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters, + callback: ResultCallback>, + ): void; + /** + * Update specific UUID Memberships list. + * + * @param parameters - Request configuration parameters or callback from overload. + * + * @returns Asynchronous update UUID Memberships list response. + */ + setMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters, + ): Promise>; + /** + * Remove a specific UUID Memberships. + * + * @param parameters - Request configuration parameters. + * @param callback - Request completion handler callback. + */ + removeMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembershipsParameters, + callback: ResultCallback>, + ): void; + /** + * Remove a specific UUID Memberships. + * + * @param parameters - Request configuration parameters. + * + * @returns Asynchronous UUID Memberships remove response. + */ + removeMemberships< + MembershipCustom extends AppContext.CustomData = AppContext.CustomData, + ChannelCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.RemoveMembershipsParameters, + ): Promise>; + /** + * Fetch paginated list of specific Space members or specific User memberships. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous get specific Space members or specific User memberships response. + * + * @deprecated Use {@link PubNubObjects#getChannelMembers} or {@link PubNubObjects#getMemberships} methods instead. + */ + fetchMemberships< + RelationCustom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.GetMembershipsParameters | AppContext.GetMembersParameters, + callback?: ResultCallback< + | AppContext.SpaceMembershipsResponse + | AppContext.UserMembersResponse + >, + ): Promise< + | AppContext.SpaceMembershipsResponse + | AppContext.UserMembersResponse + | void + >; + /** + * Add members to specific Space or memberships specific User. + * + * @param parameters - Request configuration parameters. + * @param [callback] - Request completion handler callback. + * + * @returns Asynchronous add members to specific Space or memberships specific User response or + * `void` in case if `callback` provided. + * + * @deprecated Use {@link PubNubObjects#setChannelMembers} or {@link PubNubObjects#setMemberships} methods instead. + */ + addMemberships< + Custom extends AppContext.CustomData = AppContext.CustomData, + MetadataCustom extends AppContext.CustomData = AppContext.CustomData, + >( + parameters: AppContext.SetMembershipsParameters | AppContext.SetChannelMembersParameters, + callback?: ResultCallback< + | AppContext.SetMembershipsResponse + | AppContext.SetMembersResponse + >, + ): Promise< + | AppContext.SetMembershipsResponse + | AppContext.SetMembersResponse + | void + >; + } + + export namespace Subscription { + /** + * Time cursor. + * + * Cursor used by subscription loop to identify point in time after which updates will be + * delivered. + */ + export type SubscriptionCursor = { + /** + * PubNub high-precision timestamp. + * + * Aside of specifying exact time of receiving data / event this token used to catchup / + * follow on real-time updates. + */ + timetoken: string | number; + /** + * Data center region for which `timetoken` has been generated. + */ + region?: number; + }; + + /** + * Common real-time event. + */ + type Event = { + /** + * Channel to which real-time event has been sent. + */ + channel: string; + /** + * Actual subscription at which real-time event has been received. + * + * PubNub client provide various ways to subscribe to the real-time stream: channel groups, + * wildcard subscription, and spaces. + * + * **Note:** Value will be `null` if it is the same as {@link channel}. + */ + subscription: string | null; + /** + * High-precision PubNub timetoken with time when event has been received by PubNub services. + */ + timetoken: string; + }; + + /** + * Common legacy real-time event for backward compatibility. + */ + type LegacyEvent = Event & { + /** + * Channel to which real-time event has been sent. + * + * @deprecated Use {@link channel} field instead. + */ + actualChannel?: string | null; + /** + * Actual subscription at which real-time event has been received. + * + * @deprecated Use {@link subscription} field instead. + */ + subscribedChannel?: string; + }; + + /** + * Presence change real-time event. + */ + export type Presence = LegacyEvent & PresenceData; + + /** + * Extended presence real-time event. + * + * Type extended for listener manager support. + */ + type PresenceEvent = { + type: PubNubEventType.Presence; + data: Presence; + }; + + /** + * Common published data information. + */ + type PublishedData = { + /** + * Unique identifier of the user which sent data. + */ + publisher?: string; + /** + * Additional user-provided metadata which can be used with real-time filtering expression. + */ + userMetadata?: { + [p: string]: Payload; + }; + /** + * Sent data. + */ + message: Payload; + }; + + /** + * Real-time message event. + */ + export type Message = LegacyEvent & + PublishedData & { + /** + * Decryption error message in case of failure. + */ + error?: string; + }; + + /** + * Extended real-time message event. + * + * Type extended for listener manager support. + */ + type MessageEvent = { + type: PubNubEventType.Message; + data: Message; + }; + + /** + * Real-time signal event. + */ + export type Signal = Event & PublishedData; + + /** + * Extended real-time signal event. + * + * Type extended for listener manager support. + */ + type SignalEvent = { + type: PubNubEventType.Signal; + data: Signal; + }; + + /** + * Message action real-time event. + */ + export type MessageAction = Event & + Omit & { + /** + * Unique identifier of the user which added message reaction. + * + * @deprecated Use `data.uuid` field instead. + */ + publisher?: string; + data: MessageActionData['data'] & { + /** + * Unique identifier of the user which added message reaction. + */ + uuid: string; + }; + }; + + /** + * Extended message action real-time event. + * + * Type extended for listener manager support. + */ + type MessageActionEvent = { + type: PubNubEventType.MessageAction; + data: MessageAction; + }; + + /** + * App Context Object change real-time event. + */ + export type AppContextObject = Event & { + /** + * Information about App Context object for which event received. + */ + message: AppContextObjectData; + }; + + /** + * `User` App Context Object change real-time event. + */ + export type UserAppContextObject = Omit & { + /** + * Space to which real-time event has been sent. + */ + spaceId: string; + /** + * Information about User Object for which event received. + */ + message: UserObjectData; + }; + + /** + * `Space` App Context Object change real-time event. + */ + export type SpaceAppContextObject = Omit & { + /** + * Space to which real-time event has been sent. + */ + spaceId: string; + /** + * Information about `Space` Object for which event received. + */ + message: SpaceObjectData; + }; + + /** + * VSP `Membership` App Context Object change real-time event. + */ + export type VSPMembershipAppContextObject = Omit & { + /** + * Space to which real-time event has been sent. + */ + spaceId: string; + /** + * Information about `Membership` Object for which event received. + */ + message: VSPMembershipObjectData; + }; + + /** + * Extended App Context Object change real-time event. + * + * Type extended for listener manager support. + */ + type AppContextEvent = { + type: PubNubEventType.AppContext; + data: AppContextObject; + }; + + /** + * File real-time event. + */ + export type File = Event & + Omit & + Omit & { + /** + * Message which has been associated with uploaded file. + */ + message?: Payload; + /** + * Information about uploaded file. + */ + file?: FileData['file'] & { + /** + * File download url. + */ + url: string; + }; + /** + * Decryption error message in case of failure. + */ + error?: string; + }; + + /** + * Extended File real-time event. + * + * Type extended for listener manager support. + */ + type FileEvent = { + type: PubNubEventType.Files; + data: File; + }; + + /** + * Subscribe request parameters. + */ + export type SubscribeParameters = { + /** + * List of channels from which real-time events should be delivered. + * + * @default `,` if {@link channelGroups} is set. + */ + channels?: string[]; + /** + * List of channel groups from which real-time events should be retrieved. + */ + channelGroups?: string[]; + /** + * Next subscription loop timetoken. + */ + timetoken?: string | number; + /** + * Whether should subscribe to channels / groups presence announcements or not. + * + * @default `false` + */ + withPresence?: boolean; + /** + * Presence information which should be associated with `userId`. + * + * `state` information will be associated with `userId` on channels mentioned as keys in + * this object. + * + * @deprecated Use set state methods to specify associated user's data instead of passing to + * subscribe. + */ + state?: Record; + /** + * Whether should subscribe to channels / groups presence announcements or not. + * + * @default `false` + */ + withHeartbeats?: boolean; + }; + + /** + * Service success response. + */ + export type SubscriptionResponse = { + cursor: SubscriptionCursor; + messages: (PresenceEvent | MessageEvent | SignalEvent | MessageActionEvent | AppContextEvent | FileEvent)[]; + }; + } + + export namespace AppContext { + /** + * Partial nullability helper type. + */ + type PartialNullable = { + [P in keyof T]?: T[P] | null; + }; + + /** + * Custom data which should be associated with metadata objects or their relation. + */ + export type CustomData = { + [key: string]: string | number | boolean | null; + }; + + /** + * Type provides shape of App Context parameters which is common to the all objects types to + * be updated. + */ + type ObjectParameters = { + custom?: Custom; + }; + + /** + * Type provides shape of App Context object which is common to the all objects types received + * from the PubNub service. + */ + export type ObjectData = { + /** + * Unique App Context object identifier. + * + * **Important:** For channel it is different from the channel metadata object name. + */ + id: string; + /** + * Last date and time when App Context object has been updated. + * + * String built from date using ISO 8601. + */ + updated: string; + /** + * App Context version hash. + */ + eTag: string; + /** + * Additional data associated with App Context object. + * + * **Important:** Values must be scalars; only arrays or objects are supported. + * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|App Context + * filtering language} doesn’t support filtering by custom properties. + */ + custom?: Custom | null; + }; + + /** + * Type provides shape of object which let establish relation between metadata objects. + */ + type ObjectsRelation = { + /** + * App Context object unique identifier. + */ + id: string; + /** + * App Context objects relation status. + */ + status?: string; + /** + * Additional data associated with App Context object relation (membership or members). + * + * **Important:** Values must be scalars; only arrays or objects are supported. + * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|App Context + * filtering language} doesn’t support filtering by custom properties. + */ + custom?: Custom; + }; + + /** + * Response page cursor. + */ + type Page = { + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for forward pagination, it fetches the next page, allowing you to continue from where + * you left off. + */ + next?: string; + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for backward pagination, it fetches the previous page, enabling access to earlier + * data. + * + * **Important:** Ignored if the `next` parameter is supplied. + */ + prev?: string; + }; + + /** + * Metadata objects include options. + * + * Allows to configure what additional information should be included into service response. + */ + type IncludeOptions = { + /** + * Whether to include total number of App Context objects in the response. + * + * @default `false` + */ + totalCount?: boolean; + /** + * Whether to include App Context object `custom` field in the response. + * + * @default `false` + */ + customFields?: boolean; + }; + + /** + * Membership objects include options. + * + * Allows to configure what additional information should be included into service response. + */ + type MembershipsIncludeOptions = IncludeOptions & { + /** + * Whether to include all {@link ChannelMetadata} fields in the response. + * + * @default `false` + */ + channelFields?: boolean; + /** + * Whether to include {@link ChannelMetadata} `custom` field in the response. + * + * @default `false` + */ + customChannelFields?: boolean; + /** + * Whether to include the membership's status field in the response. + * + * @default `false` + */ + statusField?: boolean; + /** + * Whether to include the channel's status field in the response. + * + * @default `false` + */ + channelStatusField?: boolean; + /** + * Whether to include channel's type fields in the response. + * + * @default `false` + */ + channelTypeField?: boolean; + }; + + /** + * Members objects include options. + * + * Allows to configure what additional information should be included into service response. + */ + type MembersIncludeOptions = IncludeOptions & { + /** + * Whether to include all {@link UUIMetadata} fields in the response. + * + * @default `false` + */ + UUIDFields?: boolean; + /** + * Whether to include {@link UUIMetadata} `custom` field in the response. + * + * @default `false` + */ + customUUIDFields?: boolean; + /** + * Whether to include the members's status field in the response. + * + * @default `false` + */ + statusField?: boolean; + /** + * Whether to include the user's status field in the response. + * + * @default `false` + */ + UUIDStatusField?: boolean; + /** + * Whether to include user's type fields in the response. + * + * @default `false` + */ + UUIDTypeField?: boolean; + }; + + /** + * Type provides shape of App Context parameters which is common to the all objects types to + * fetch them by pages. + */ + type PagedRequestParameters = { + /** + * Fields which can be additionally included into response. + */ + include?: Include; + /** + * Expression used to filter the results. + * + * Only objects whose properties satisfy the given expression are returned. The filter language is + * {@link /docs/sdks/javascript/api-reference/objects#app-context-filtering-language-definition|defined here}. + */ + filter?: string; + /** + * Fetched App Context objects sorting options. + */ + sort?: Sort; + /** + * Number of objects to return in response. + * + * **Important:** Maximum for this API is `100` objects per-response. + * + * @default `100` + */ + limit?: number; + /** + * Response pagination configuration. + */ + page?: Page; + }; + + /** + * Type provides shape of App Context object fetch response which is common to the all objects + * types received from the PubNub service. + */ + type ObjectResponse = { + /** + * App Context objects list fetch result status code. + */ + status: number; + /** + * Received App Context object information. + */ + data: ObjectType; + }; + + /** + * Type provides shape of App Context objects fetch response which is common to the all + * objects types received from the PubNub service. + */ + type PagedResponse = ObjectResponse & { + /** + * Total number of App Context objects in the response. + */ + totalCount?: number; + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for forward pagination, it fetches the next page, allowing you to continue from where + * you left off. + */ + next?: string; + /** + * Random string returned from the server, indicating a specific position in a data set. + * + * Used for backward pagination, it fetches the previous page, enabling access to earlier + * data. + * + * **Important:** Ignored if the `next` parameter is supplied. + */ + prev?: string; + }; + + /** + * Key-value pair of a property to sort by, and a sort direction. + */ + type MetadataSortingOptions = + | keyof Omit + | ({ + [K in keyof Omit]?: 'asc' | 'desc' | null; + } & { + [key: `custom.${string}`]: 'asc' | 'desc' | null; + }); + + /** + * Key-value pair of a property to sort by, and a sort direction. + */ + type MembershipsSortingOptions = + | 'channel.id' + | 'channel.name' + | 'channel.description' + | 'channel.updated' + | 'space.id' + | 'space.name' + | 'space.description' + | 'space.updated' + | 'updated' + | { + /** + * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.id'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.name'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `description` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.description'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.id` instead. + */ + 'space.id'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.name` instead. + */ + 'space.name'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `description` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.name` instead. + */ + 'space.description'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `channel.updated` instead. + */ + 'space.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by `updated` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + updated?: 'asc' | 'desc' | null; + }; + + /** + * Key-value pair of a property to sort by, and a sort direction. + */ + type MembersSortingOptions = + | 'uuid.id' + | 'uuid.name' + | 'uuid.updated' + | 'user.id' + | 'user.name' + | 'user.updated' + | 'updated' + | { + /** + * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.id'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.name'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `uuid.id` instead. + */ + 'user.id'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `name` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `uuid.name` instead. + */ + 'user.name'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `update` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + * + * @deprecated Use `uuid.updated` instead. + */ + 'user.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by `updated` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + updated?: 'asc' | 'desc' | null; + }; + + /** + * Fetch All UUID or Channel Metadata request parameters. + */ + export type GetAllMetadataParameters = PagedRequestParameters< + IncludeOptions, + MetadataSortingOptions + >; + + /** + * Type which describes own UUID metadata object fields. + */ + type UUIDMetadataFields = { + /** + * Display name for the user. + */ + name?: string; + /** + * The user's email address. + */ + email?: string; + /** + * User's identifier in an external system. + */ + externalId?: string; + /** + * The URL of the user's profile picture. + */ + profileUrl?: string; + /** + * User's object type information. + */ + type?: string; + /** + * User's object status. + */ + status?: string; + }; + + /** + * Updated UUID metadata object. + * + * Type represents updated UUID metadata object which will be pushed to the PubNub service. + */ + type UUIDMetadata = ObjectParameters & Partial; + + /** + * Received UUID metadata object. + * + * Type represents UUID metadata retrieved from the PubNub service. + */ + export type UUIDMetadataObject = ObjectData & + PartialNullable; + + /** + * Response with fetched page of UUID metadata objects. + */ + export type GetAllUUIDMetadataResponse = PagedResponse>; + + /** + * Fetch UUID Metadata request parameters. + */ + export type GetUUIDMetadataParameters = { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `getUUIDMetadata()` method instead. + */ + userId?: string; + /** + * Fields which can be additionally included into response. + */ + include?: Omit; + }; + + /** + * Response with requested UUID metadata object. + */ + export type GetUUIDMetadataResponse = ObjectResponse>; + + /** + * Update UUID Metadata request parameters. + */ + export type SetUUIDMetadataParameters = { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `setUUIDMetadata()` method instead. + */ + userId?: string; + /** + * Metadata, which should be associated with UUID. + */ + data: UUIDMetadata; + /** + * Fields which can be additionally included into response. + */ + include?: Omit; + }; + + /** + * Response with result of the UUID metadata object update. + */ + export type SetUUIDMetadataResponse = ObjectResponse>; + + /** + * Remove UUID Metadata request parameters. + */ + export type RemoveUUIDMetadataParameters = { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `removeUUIDMetadata()` method instead. + */ + userId?: string; + }; + + /** + * Response with result of the UUID metadata removal. + */ + export type RemoveUUIDMetadataResponse = ObjectResponse>; + + /** + * Type which describes own Channel metadata object fields. + */ + type ChannelMetadataFields = { + /** + * Name of a channel. + */ + name?: string; + /** + * Description of a channel. + */ + description?: string; + /** + * Channel's object type information. + */ + type?: string; + /** + * Channel's object status. + */ + status?: string; + }; + + /** + * Updated channel metadata object. + * + * Type represents updated channel metadata object which will be pushed to the PubNub service. + */ + type ChannelMetadata = ObjectParameters & Partial; + + /** + * Received channel metadata object. + * + * Type represents chanel metadata retrieved from the PubNub service. + */ + export type ChannelMetadataObject = ObjectData & + PartialNullable; + + /** + * Response with fetched page of channel metadata objects. + */ + export type GetAllChannelMetadataResponse = PagedResponse>; + + /** + * Fetch Channel Metadata request parameters. + */ + export type GetChannelMetadataParameters = { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `getChannelMetadata()` method instead. + */ + spaceId?: string; + /** + * Fields which can be additionally included into response. + */ + include?: Omit; + }; + + /** + * Response with requested channel metadata object. + */ + export type GetChannelMetadataResponse = ObjectResponse>; + + /** + * Update Channel Metadata request parameters. + */ + export type SetChannelMetadataParameters = { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `setChannelMetadata()` method instead. + */ + spaceId?: string; + /** + * Metadata, which should be associated with UUID. + */ + data: ChannelMetadata; + /** + * Fields which can be additionally included into response. + */ + include?: Omit; + }; + + /** + * Response with result of the channel metadata object update. + */ + export type SetChannelMetadataResponse = ObjectResponse>; + + /** + * Remove Channel Metadata request parameters. + */ + export type RemoveChannelMetadataParameters = { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `removeChannelMetadata()` method instead. + */ + spaceId?: string; + }; + + /** + * Response with result of the channel metadata removal. + */ + export type RemoveChannelMetadataResponse = ObjectResponse>; + + /** + * Related channel metadata object. + * + * Type represents chanel metadata which has been used to create membership relation with UUID. + */ + type MembershipsObject = Omit< + ObjectData, + 'id' + > & { + channel: + | ChannelMetadataObject + | { + id: string; + }; + }; + + /** + * Response with fetched page of UUID membership objects. + */ + type MembershipsResponse = PagedResponse< + MembershipsObject + >; + + /** + * Fetch Memberships request parameters. + */ + export type GetMembershipsParameters = PagedRequestParameters< + MembershipsIncludeOptions, + MembershipsSortingOptions + > & { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuidId`. + * + * @deprecated Use `uuid` field instead. + */ + userId?: string; + }; + + /** + * Response with requested channel memberships information. + */ + export type GetMembershipsResponse< + MembershipCustom extends CustomData, + ChannelCustom extends CustomData, + > = MembershipsResponse; + + /** + * Update Memberships request parameters. + */ + export type SetMembershipsParameters = PagedRequestParameters< + Omit, + MembershipsSortingOptions + > & { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use `uuid` field instead. + */ + userId?: string; + /** + * List of channels with which UUID membership should be established. + */ + channels: Array>; + /** + * List of channels with which UUID membership should be established. + * + * @deprecated Use `channels` field instead. + */ + spaces?: Array< + | string + | (Omit, 'id'> & { + /** + * Unique Space object identifier. + */ + spaceId: string; + }) + >; + }; + + /** + * Response with requested channel memberships information change. + */ + export type SetMembershipsResponse< + MembershipCustom extends CustomData, + ChannelCustom extends CustomData, + > = MembershipsResponse; + + /** + * Remove Memberships request parameters. + */ + export type RemoveMembershipsParameters = PagedRequestParameters< + MembershipsIncludeOptions, + MembershipsSortingOptions + > & { + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `uuid`. + */ + uuid?: string; + /** + * Unique user identifier. + * + * **Important:** If not supplied then current user's uuid is used. + * + * @default Current `userId`. + * + * @deprecated Use {@link uuid} field instead. + */ + userId?: string; + /** + * List of channels for which membership which UUID should be removed. + */ + channels: string[]; + /** + * List of space names for which membership which UUID should be removed. + * + * @deprecated Use {@link channels} field instead. + */ + spaceIds?: string[]; + }; + + /** + * Response with remaining memberships. + */ + export type RemoveMembershipsResponse< + MembershipCustom extends CustomData, + ChannelCustom extends CustomData, + > = MembershipsResponse; + + /** + * Related UUID metadata object. + * + * Type represents UUID metadata which has been used to when added members to the channel. + */ + type MembersObject = Omit< + ObjectData, + 'id' + > & { + uuid: + | UUIDMetadataObject + | { + id: string; + }; + }; + + /** + * Response with fetched page of channel member objects. + */ + type MembersResponse = PagedResponse< + MembersObject + >; + + /** + * Fetch Members request parameters. + */ + export type GetMembersParameters = PagedRequestParameters & { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `channel` field instead. + */ + spaceId?: string; + }; + + /** + * Response with requested channel memberships information. + */ + export type GetMembersResponse = MembersResponse< + MembersCustom, + UUIDCustom + >; + + /** + * Update Members request parameters. + */ + export type SetChannelMembersParameters = PagedRequestParameters< + Omit, + MembersSortingOptions + > & { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use `channel` field instead. + */ + spaceId?: string; + /** + * List of UUIDs which should be added as `channel` members. + */ + uuids: Array>; + /** + * List of UUIDs which should be added as `channel` members. + * + * @deprecated Use `uuids` field instead. + */ + users?: Array< + | string + | (Omit, 'id'> & { + /** + * Unique User object identifier. + */ + userId: string; + }) + >; + }; + + /** + * Response with requested channel members information change. + */ + export type SetMembersResponse = MembersResponse< + MemberCustom, + UUIDCustom + >; + + /** + * Remove Members request parameters. + */ + export type RemoveMembersParameters = PagedRequestParameters & { + /** + * Channel name. + */ + channel: string; + /** + * Space identifier. + * + * @deprecated Use {@link channel} field instead. + */ + spaceId?: string; + /** + * List of UUIDs which should be removed from the `channel` members list. + * removed. + */ + uuids: string[]; + /** + * List of user identifiers which should be removed from the `channel` members list. + * removed. + * + * @deprecated Use {@link uuids} field instead. + */ + userIds?: string[]; + }; + + /** + * Response with remaining members. + */ + export type RemoveMembersResponse = MembersResponse< + MemberCustom, + UUIDCustom + >; + + /** + * Related User metadata object. + * + * Type represents User metadata which has been used to when added members to the Space. + */ + type UserMembersObject = Omit< + ObjectData, + 'id' + > & { + user: + | UUIDMetadataObject + | { + id: string; + }; + }; + + /** + * Response with fetched page of Space member objects. + */ + export type UserMembersResponse = PagedResponse< + UserMembersObject + >; + + type SpaceMembershipObject = Omit< + ObjectData, + 'id' + > & { + space: + | ChannelMetadataObject + | { + id: string; + }; + }; + + /** + * Response with fetched page of User membership objects. + */ + export type SpaceMembershipsResponse< + MembershipCustom extends CustomData, + ChannelCustom extends CustomData, + > = PagedResponse>; + } + + export namespace ChannelGroups { + /** + * Add or remove Channels to the channel group request parameters. + */ + export type ManageChannelGroupChannelsParameters = { + /** + * Name of the channel group for which channels list should be changed. + */ + channelGroup: string; + /** + * List of channels to be added or removed. + */ + channels: string[]; + }; + + /** + * Channel group channels list manage response. + */ + export type ManageChannelGroupChannelsResponse = Record; + + /** + * Response with result of the all channel groups list. + */ + export type ListAllChannelGroupsResponse = { + /** + * All channel groups with channels. + */ + groups: string[]; + }; + + /** + * List Channel Group Channels request parameters. + */ + export type ListChannelGroupChannelsParameters = { + /** + * Name of the channel group for which list of channels should be retrieved. + */ + channelGroup: string; + }; + + /** + * Response with result of the list channel group channels. + */ + export type ListChannelGroupChannelsResponse = { + /** + * List of the channels registered withing specified channel group. + */ + channels: string[]; + }; + + /** + * Delete Channel Group request parameters. + */ + export type DeleteChannelGroupParameters = { + /** + * Name of the channel group which should be removed. + */ + channelGroup: string; + }; + + /** + * Delete channel group response. + */ + export type DeleteChannelGroupResponse = Record; + } + + export namespace Publish { + /** + * Request configuration parameters. + */ + export type PublishParameters = { + /** + * Channel name to publish messages to. + */ + channel: string; + /** + * Data which should be sent to the `channel`. + * + * The message may be any valid JSON type including objects, arrays, strings, and numbers. + */ + message: Payload; + /** + * Whether published data should be available with `Storage API` later or not. + * + * @default `true` + */ + storeInHistory?: boolean; + /** + * Whether message should be sent as part of request POST body or not. + * + * @default `false` + */ + sendByPost?: boolean; + /** + * Metadata, which should be associated with published data. + * + * Associated metadata can be utilized by message filtering feature. + */ + meta?: Payload; + /** + * Specify duration during which data will be available with `Storage API`. + * + * - If `storeInHistory` = `true`, and `ttl` = `0`, the `message` is stored with no expiry time. + * - If `storeInHistory` = `true` and `ttl` = `X` (`X` is an Integer value), the `message` is + * stored with an expiry time of `X` hours. + * - If `storeInHistory` = `false`, the `ttl` parameter is ignored. + * - If `ttl` is not specified, then expiration of the `message` defaults back to the expiry value + * for the key. + */ + ttl?: number; + /** + * Whether published data should be replicated across all data centers or not. + * + * @default `true` + * @deprecated + */ + replicate?: boolean; + }; + + /** + * Service success response. + */ + export type PublishResponse = { + /** + * High-precision time when published data has been received by the PubNub service. + */ + timetoken: string; + }; + } + + export namespace Signal { + /** + * Request configuration parameters. + */ + export type SignalParameters = { + /** + * Channel name to publish signal to. + */ + channel: string; + /** + * Data which should be sent to the `channel`. + * + * The message may be any valid JSON type including objects, arrays, strings, and numbers. + */ + message: Payload; + }; + + /** + * Service success response. + */ + export type SignalResponse = { + /** + * High-precision time when published data has been received by the PubNub service. + */ + timetoken: string; + }; + } + + export namespace Presence { + /** + * Associated presence state fetch parameters. + */ + export type GetPresenceStateParameters = { + /** + * The subscriber uuid to get the current state. + * + * @default `current uuid` + */ + uuid?: string; + /** + * List of channels for which state associated with {@link uuid} should be retrieved. + * + * **Important:** Either {@link channels} or {@link channelGroups} should be provided; + */ + channels?: string[]; + /** + * List of channel groups for which state associated with {@link uuid} should be retrieved. + * + * **Important:** Either {@link channels} or {@link channelGroups} should be provided; + */ + channelGroups?: string[]; + }; + + /** + * Associated presence state fetch response. + */ + export type GetPresenceStateResponse = { + /** + * Channels map to state which `uuid` has associated with them. + */ + channels: Record; + }; + + /** + * Associate presence state parameters. + */ + export type SetPresenceStateParameters = { + /** + * List of channels for which state should be associated with {@link uuid}. + */ + channels?: string[]; + /** + * List of channel groups for which state should be associated with {@link uuid}. + */ + channelGroups?: string[]; + /** + * State which should be associated with `uuid` on provided list of {@link channels} and {@link channelGroups}. + */ + state: Payload; + }; + + /** + * Associate presence state parameters using heartbeat. + */ + export type SetPresenceStateWithHeartbeatParameters = { + /** + * List of channels for which state should be associated with {@link uuid}. + */ + channels?: string[]; + /** + * State which should be associated with `uuid` on provided list of {@link channels}. + */ + state: Payload; + /** + * Whether `presence/heartbeat` REST API should be used to manage state or not. + * + * @default `false` + */ + withHeartbeat: boolean; + }; + + /** + * Associate presence state response. + */ + export type SetPresenceStateResponse = { + /** + * State which has been associated with `uuid` on provided list of channels and groups. + */ + state: Payload; + }; + + /** + * Announce heartbeat parameters. + */ + export type PresenceHeartbeatParameters = { + /** + * How long the server will consider the client alive for presence.The value is in seconds. + */ + heartbeat: number; + /** + * List of channels for which heartbeat should be announced for {@link uuid}. + */ + channels?: string[]; + /** + * List of channel groups for which heartbeat should be announced for {@link uuid}. + */ + channelGroups?: string[]; + /** + * State which should be associated with `uuid` on provided list of {@link channels} and {@link channelGroups}. + */ + state?: Payload; + }; + + /** + * Announce heartbeat response. + */ + export type PresenceHeartbeatResponse = Record; + + /** + * Presence leave parameters. + */ + export type PresenceLeaveParameters = { + /** + * List of channels for which `uuid` should be marked as `offline`. + */ + channels?: string[]; + /** + /** + * List of channel groups for which `uuid` should be marked as `offline`. + */ + channelGroups?: string[]; + }; + + /** + * Presence leave response. + */ + export type PresenceLeaveResponse = Record; + + /** + * Channel / channel group presence fetch parameters.. + */ + export type HereNowParameters = { + /** + * List of channels for which presence should be retrieved. + */ + channels?: string[]; + /** + * List of channel groups for which presence should be retrieved. + */ + channelGroups?: string[]; + /** + * Whether `uuid` information should be included in response or not. + * + * **Note:** Only occupancy information will be returned if both {@link includeUUIDs} and {@link includeState} is + * set to `false`. + * + * @default `true` + */ + includeUUIDs?: boolean; + /** + * Whether state associated with `uuid` should be included in response or not. + * + * @default `false`. + */ + includeState?: boolean; + /** + * Additional query parameters. + */ + queryParameters?: Record; + }; + + /** + * `uuid` where now response. + */ + export type HereNowResponse = { + /** + * Total number of channels for which presence information received. + */ + totalChannels: number; + /** + * Total occupancy for all retrieved channels. + */ + totalOccupancy: number; + /** + * List of channels to which `uuid` currently subscribed. + */ + channels: { + [p: string]: { + /** + * List of received channel subscribers. + * + * **Note:** Field is missing if `uuid` and `state` not included. + */ + occupants: { + uuid: string; + state?: Payload | null; + }[]; + /** + * Name of channel for which presence information retrieved. + */ + name: string; + /** + * Total number of active subscribers in single channel. + */ + occupancy: number; + }; + }; + }; + + /** + * `uuid` where now parameters. + */ + export type WhereNowParameters = { + /** + * The subscriber uuid to get the current state. + * + * @default `current uuid` + */ + uuid?: string; + }; + + /** + * `uuid` where now response. + */ + export type WhereNowResponse = { + /** + * Channels map to state which `uuid` has associated with them. + */ + channels: string[]; + }; + } + + export namespace History { + /** + * Get history request parameters. + */ + export type GetHistoryParameters = { + /** + * Channel to return history messages from. + */ + channel: string; + /** + * Specifies the number of historical messages to return. + * + * **Note:** Maximum `100` messages can be returned in single response. + * + * @default `100` + */ + count?: number; + /** + * Whether message `meta` information should be fetched or not. + * + * @default `false` + */ + includeMeta?: boolean; + /** + * Timetoken delimiting the `start` of `time` slice (exclusive) to pull messages from. + */ + start?: string; + /** + * Timetoken delimiting the `end` of `time` slice (inclusive) to pull messages from. + */ + end?: string; + /** + * Whether timeline should traverse in reverse starting with the oldest message first or not. + * + * If both `start` and `end` arguments are provided, `reverse` is ignored and messages are + * returned starting with the newest message. + */ + reverse?: boolean; + /** + * Whether message timetokens should be stringified or not. + * + * @default `false` + */ + stringifiedTimeToken?: boolean; + }; + + /** + * Get history response. + */ + export type GetHistoryResponse = { + /** + * List of previously published messages. + */ + messages: { + /** + * Message payload (decrypted). + */ + entry: Payload; + /** + * When message has been received by PubNub service. + */ + timetoken: string | number; + /** + * Additional data which has been published along with message to be used with real-time + * events filter expression. + */ + meta?: Payload; + /** + * Message decryption error (if attempt has been done). + */ + error?: string; + }[]; + /** + * Received messages timeline start. + */ + startTimeToken: string | number; + /** + * Received messages timeline end. + */ + endTimeToken: string | number; + }; + + /** + * PubNub-defined message type. + * + * Types of messages which can be retrieved with fetch messages REST API. + */ + export enum PubNubMessageType { + /** + * Regular message. + */ + Message = -1, + /** + * File message. + */ + Files = 4, + } + + /** + * Per-message actions information. + */ + export type Actions = { + /** + * Message action type. + */ + [t: string]: { + /** + * Message action value. + */ + [v: string]: { + /** + * Unique identifier of the user which reacted on message. + */ + uuid: string; + /** + * High-precision PubNub timetoken with time when {@link uuid} reacted on message. + */ + actionTimetoken: string; + }[]; + }; + }; + + /** + * Additional message actions fetch information. + */ + export type MoreActions = { + /** + * Prepared fetch messages with actions REST API URL. + */ + url: string; + /** + * Next page time offset. + */ + start: string; + /** + * Number of messages to retrieve with next page. + */ + max: number; + }; + + /** + * Common content of the fetched message. + */ + type BaseFetchedMessage = { + /** + * Name of channel for which message has been retrieved. + */ + channel: string; + /** + * When message has been received by PubNub service. + */ + timetoken: string | number; + /** + * Message publisher unique identifier. + */ + uuid?: string; + /** + * Additional data which has been published along with message to be used with real-time + * events filter expression. + */ + meta?: Payload; + /** + * Message decryption error (if attempt has been done). + */ + error?: string; + }; + + /** + * Regular message published to the channel. + */ + export type RegularMessage = BaseFetchedMessage & { + /** + * Message payload (decrypted). + */ + message: Payload; + /** + * PubNub-defined message type. + */ + messageType?: PubNubMessageType.Message; + }; + + /** + * File message published to the channel. + */ + export type FileMessage = BaseFetchedMessage & { + /** + * Message payload (decrypted). + */ + message: { + /** + * File annotation message. + */ + message?: Payload; + /** + * File information. + */ + file: { + /** + * Unique file identifier. + */ + id: string; + /** + * Name with which file has been stored. + */ + name: string; + /** + * File's content mime-type. + */ + 'mime-type': string; + /** + * Stored file size. + */ + size: number; + /** + * Pre-computed file download Url. + */ + url: string; + }; + }; + /** + * PubNub-defined message type. + */ + messageType?: PubNubMessageType.Files; + }; + + /** + * Fetched message entry in channel messages list. + */ + export type FetchedMessage = RegularMessage | FileMessage; + + /** + * Fetched with actions message entry in channel messages list. + */ + export type FetchedMessageWithActions = FetchedMessage & { + /** + * List of message reactions. + */ + actions?: Actions; + /** + * List of message reactions. + * + * @deprecated Use {@link actions} field instead. + */ + data?: Actions; + }; + + /** + * Fetch messages request parameters. + */ + export type FetchMessagesParameters = { + /** + * Specifies channels to return history messages from. + * + * **Note:** Maximum of `500` channels are allowed. + */ + channels: string[]; + /** + * Specifies the number of historical messages to return per channel. + * + * **Note:** Default is `100` per single channel and `25` per multiple channels or per + * single channel if {@link includeMessageActions} is used. + * + * @default `100` or `25` + */ + count?: number; + /** + * Whether message type should be returned with each history message or not. + * + * @default `true` + */ + includeMessageType?: boolean; + /** + * Whether publisher `uuid` should be returned with each history message or not. + * + * @default `true` + */ + includeUUID?: boolean; + /** + * Whether publisher `uuid` should be returned with each history message or not. + * + * @deprecated Use {@link includeUUID} property instead. + */ + includeUuid?: boolean; + /** + * Whether message `meta` information should be fetched or not. + * + * @default `false` + */ + includeMeta?: boolean; + /** + * Whether message-added message actions should be fetched or not. + * + * If used, the limit of messages retrieved will be `25` per single channel. + * + * Each message can have a maximum of `25000` actions attached to it. Consider the example of + * querying for 10 messages. The first five messages have 5000 actions attached to each of + * them. The API will return the first 5 messages and all their 25000 actions. The response + * will also include a `more` link to get the remaining 5 messages. + * + * **Important:** Truncation will happen if the number of actions on the messages returned + * is > 25000. + * + * @default `false` + * + * @throws Exception if API is called with more than one channel. + */ + includeMessageActions?: boolean; + /** + * Timetoken delimiting the `start` of `time` slice (exclusive) to pull messages from. + */ + start?: string; + /** + * Timetoken delimiting the `end` of `time` slice (inclusive) to pull messages from. + */ + end?: string; + /** + * Whether message timetokens should be stringified or not. + * + * @default `false` + */ + stringifiedTimeToken?: boolean; + }; + + /** + * Fetch messages response. + */ + export type FetchMessagesForChannelsResponse = { + /** + * List of previously published messages per requested channel. + */ + channels: { + [p: string]: FetchedMessage[]; + }; + }; + + /** + * Fetch messages with reactions response. + */ + export type FetchMessagesWithActionsResponse = { + channels: { + [p: string]: FetchedMessageWithActions[]; + }; + /** + * Additional message actions fetch information. + */ + more: MoreActions; + }; + + /** + * Fetch messages response. + */ + export type FetchMessagesResponse = FetchMessagesForChannelsResponse | FetchMessagesWithActionsResponse; + + /** + * Message count request parameters. + */ + export type MessageCountParameters = { + /** + * The channels to fetch the message count. + */ + channels: string[]; + /** + * List of timetokens, in order of the {@link channels} list. + * + * Specify a single timetoken to apply it to all channels. Otherwise, the list of timetokens + * must be the same length as the list of {@link channels}, or the function returns an error + * flag. + */ + channelTimetokens?: string[]; + /** + * High-precision PubNub timetoken starting from which number of messages should be counted. + * + * Same timetoken will be used to count messages for each passed {@link channels}. + * + * @deprecated Use {@link channelTimetokens} field instead. + */ + timetoken?: string; + }; + + /** + * Message count response. + */ + export type MessageCountResponse = { + /** + * Map of channel names to the number of counted messages. + */ + channels: Record; + }; + + /** + * Delete messages from channel parameters. + */ + export type DeleteMessagesParameters = { + /** + * Specifies channel messages to be deleted from history. + */ + channel: string; + /** + * Timetoken delimiting the start of time slice (exclusive) to delete messages from. + */ + start?: string; + /** + * Timetoken delimiting the end of time slice (inclusive) to delete messages from. + */ + end?: string; + }; + + /** + * Delete messages from channel response. + */ + export type DeleteMessagesResponse = Record; + } + + export namespace MessageAction { + /** + * Message reaction object type. + */ + export type MessageAction = { + /** + * What feature this message action represents. + */ + type: string; + /** + * Value which should be stored along with message action. + */ + value: string; + /** + * Unique identifier of the user which added message action. + */ + uuid: string; + /** + * Timetoken of when message reaction has been added. + * + * **Note:** This token required when it will be required to remove reaction. + */ + actionTimetoken: string; + /** + * Timetoken of message to which `action` has been added. + */ + messageTimetoken: string; + }; + + /** + * More message actions fetch information. + */ + export type MoreMessageActions = { + /** + * Prepared REST API url to fetch next page with message actions. + */ + url: string; + /** + * Message action timetoken denoting the start of the range requested with next page. + * + * **Note:** Return values will be less than {@link start}. + */ + start: string; + /** + * Message action timetoken denoting the end of the range requested with next page. + * + * **Note:** Return values will be greater than or equal to {@link end}. + */ + end: string; + /** + * Number of message actions to return in next response. + */ + limit: number; + }; + + /** + * Add Message Action request parameters. + */ + export type AddMessageActionParameters = { + /** + * Name of channel which stores the message for which {@link action} should be added. + */ + channel: string; + /** + * Timetoken of message for which {@link action} should be added. + */ + messageTimetoken: string; + /** + * Message `action` information. + */ + action: { + /** + * What feature this message action represents. + */ + type: string; + /** + * Value which should be stored along with message action. + */ + value: string; + }; + }; + + /** + * Response with added message action object. + */ + export type AddMessageActionResponse = { + data: MessageAction; + }; + + /** + * Get Message Actions request parameters. + */ + export type GetMessageActionsParameters = { + /** + * Name of channel from which list of messages `actions` should be retrieved. + */ + channel: string; + /** + * Message action timetoken denoting the start of the range requested. + * + * **Note:** Return values will be less than {@link start}. + */ + start?: string; + /** + * Message action timetoken denoting the end of the range requested. + * + * **Note:** Return values will be greater than or equal to {@link end}. + */ + end?: string; + /** + * Number of message actions to return in response. + */ + limit?: number; + }; + + /** + * Response with message actions in specific `channel`. + */ + export type GetMessageActionsResponse = { + /** + * Retrieved list of message actions. + */ + data: MessageAction[]; + /** + * Received message actions time frame start. + */ + start: string | null; + /** + * Received message actions time frame end. + */ + end: string | null; + /** + * More message actions fetch information. + */ + more?: MoreMessageActions; + }; + + /** + * Remove Message Action request parameters. + */ + export type RemoveMessageActionParameters = { + /** + * Name of channel which store message for which `action` should be removed. + */ + channel: string; + /** + * Timetoken of message for which `action` should be removed. + */ + messageTimetoken: string; + /** + * Action addition timetoken. + */ + actionTimetoken: string; + }; + + /** + * Response with message remove result. + */ + export type RemoveMessageActionResponse = { + data: Record; + }; + } + + export namespace FileSharing { + /** + * Shared file object. + */ + export type SharedFile = { + /** + * Name with which file has been stored. + */ + name: string; + /** + * Unique service-assigned file identifier. + */ + id: string; + /** + * Shared file size. + */ + size: number; + /** + * ISO 8601 time string when file has been shared. + */ + created: string; + }; + + /** + * List Files request parameters. + */ + export type ListFilesParameters = { + /** + * Name of channel for which list of files should be requested. + */ + channel: string; + /** + * How many entries return with single response. + */ + limit?: number; + /** + * Next files list page token. + */ + next?: string; + }; + + /** + * List Files request response. + */ + export type ListFilesResponse = { + /** + * Files list fetch result status code. + */ + status: number; + /** + * List of fetched file objects. + */ + data: SharedFile[]; + /** + * Next files list page token. + */ + next: string; + /** + * Number of retrieved files. + */ + count: number; + }; + + /** + * Send File request parameters. + */ + export type SendFileParameters = Omit & { + /** + * Channel to send the file to. + */ + channel: string; + /** + * File to send. + */ + file: FileParameters; + }; + + /** + * Send File request response. + */ + export type SendFileResponse = PublishFileMessageResponse & { + /** + * Send file request processing status code. + */ + status: number; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Important:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + }; + + /** + * Upload File request parameters. + */ + export type UploadFileParameters = { + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link fileName} can be used to download file from the channel + * later. + */ + fileId: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link fileId} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + fileName: string; + /** + * File which should be uploaded. + */ + file: PubNubFileInterface; + /** + * Pre-signed file upload Url. + */ + uploadUrl: string; + /** + * An array of form fields to be used in the pre-signed POST request. + * + * **Important:** Form data fields should be passed in exact same order as received from + * the PubNub service. + */ + formFields: { + /** + * Form data field name. + */ + name: string; + /** + * Form data field value. + */ + value: string; + }[]; + }; + + /** + * Upload File request response. + */ + export type UploadFileResponse = { + /** + * Upload File request processing status code. + */ + status: number; + /** + * Service processing result response. + */ + message: Payload; + }; + + /** + * Generate File Upload URL request parameters. + */ + export type GenerateFileUploadUrlParameters = { + /** + * Name of channel to which file should be uploaded. + */ + channel: string; + /** + * Actual name of the file which should be uploaded. + */ + name: string; + }; + + /** + * Generation File Upload URL request response. + */ + export type GenerateFileUploadUrlResponse = { + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; + /** + * Pre-signed URL for file upload. + */ + url: string; + /** + * An array of form fields to be used in the pre-signed POST request. + * + * **Important:** Form data fields should be passed in exact same order as received from + * the PubNub service. + */ + formFields: { + /** + * Form data field name. + */ + name: string; + /** + * Form data field value. + */ + value: string; + }[]; + }; + + /** + * Publish File Message request parameters. + */ + export type PublishFileMessageParameters = { + /** + * Name of channel to which file has been sent. + */ + channel: string; + /** + * File annotation message. + */ + message?: Payload; + /** + * Custom file and message encryption key. + * + * @deprecated Use {@link Configuration#cryptoModule|cryptoModule} configured for PubNub client + * instance or encrypt file prior {@link PubNub#sendFile|sendFile} method call. + */ + cipherKey?: string; + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link fileName} can be used to download file from the channel + * later. + */ + fileId: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link fileId} can be used to download file from the channel later. + * + * **Note:** Actual file name may be different from the one which has been used during file + * upload. + */ + fileName: string; + /** + * Whether published file messages should be stored in the channel's history. + * + * **Note:** If `storeInHistory` not specified, then the history configuration on the key is + * used. + * + * @default `true` + */ + storeInHistory?: boolean; + /** + * How long the message should be stored in the channel's history. + * + * **Note:** If not specified, defaults to the key set's retention value. + * + * @default `0` + */ + ttl?: number; + /** + * Metadata, which should be associated with published file. + * + * Associated metadata can be utilized by message filtering feature. + */ + meta?: Payload; + }; + + /** + * Publish File Message request response. + */ + export type PublishFileMessageResponse = { + /** + * High-precision time when published file message has been received by the PubNub service. + */ + timetoken: string; + }; + + /** + * Download File request parameters. + */ + export type DownloadFileParameters = FileUrlParameters & { + /** + * Custom file and message encryption key. + * + * @deprecated Use {@link Configuration#cryptoModule|cryptoModule} configured for PubNub client + * instance or encrypt file prior {@link PubNub#sendFile|sendFile} method call. + */ + cipherKey?: string; + }; + + /** + * Generate File download Url request parameters. + */ + export type FileUrlParameters = { + /** + * Name of channel where file has been sent. + */ + channel: string; + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Important:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; + }; + + /** + * Generate File Download Url response. + */ + export type FileUrlResponse = string; + + /** + * Delete File request parameters. + */ + export type DeleteFileParameters = { + /** + * Name of channel where file has been sent. + */ + channel: string; + /** + * Unique file identifier. + * + * Unique file identifier, and it's {@link name} can be used to download file from the channel + * later. + */ + id: string; + /** + * Actual file name under which file has been stored. + * + * File name and unique {@link id} can be used to download file from the channel later. + * + * **Important:** Actual file name may be different from the one which has been used during file + * upload. + */ + name: string; + }; + + /** + * Delete File request response. + */ + export type DeleteFileResponse = { + /** + * Delete File request processing status code. + */ + status: number; + }; + } + + export namespace PAM { + /** + * Metadata which will be associated with access token. + */ + export type Metadata = Record; + + /** + * Channel-specific token permissions. + */ + export type ChannelTokenPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + read?: boolean; + /** + * Whether `write` operations are permitted for corresponding level or not. + */ + write?: boolean; + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + get?: boolean; + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + manage?: boolean; + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + update?: boolean; + /** + * Whether `join` operations are permitted for corresponding level or not. + */ + join?: boolean; + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + delete?: boolean; + }; + + /** + * Space-specific token permissions. + */ + type SpaceTokenPermissions = ChannelTokenPermissions; + + /** + * Channel group-specific token permissions. + */ + export type ChannelGroupTokenPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + read?: boolean; + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + manage?: boolean; + }; + + /** + * Uuid-specific token permissions. + */ + export type UuidTokenPermissions = { + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + get?: boolean; + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + update?: boolean; + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + delete?: boolean; + }; + + /** + * User-specific token permissions. + */ + type UserTokenPermissions = UuidTokenPermissions; + + /** + * Generate access token with permissions. + * + * Generate time-limited access token with required permissions for App Context objects. + */ + export type ObjectsGrantTokenParameters = { + /** + * Total number of minutes for which the token is valid. + * + * The minimum allowed value is `1`. + * The maximum is `43,200` minutes (`30` days). + */ + ttl: number; + /** + * Object containing resource permissions. + */ + resources?: { + /** + * Object containing `spaces` metadata permissions. + */ + spaces?: Record; + /** + * Object containing `users` permissions. + */ + users?: Record; + }; + /** + * Object containing permissions to multiple resources specified by a RegEx pattern. + */ + patterns?: { + /** + * Object containing `spaces` metadata permissions. + */ + spaces?: Record; + /** + * Object containing `users` permissions. + */ + users?: Record; + }; + /** + * Extra metadata to be published with the request. + * + * **Important:** Values must be scalar only; `arrays` or `objects` aren't supported. + */ + meta?: Metadata; + /** + * Single `userId` which is authorized to use the token to make API requests to PubNub. + */ + authorizedUserId?: string; + }; + + /** + * Generate token with permissions. + * + * Generate time-limited access token with required permissions for resources. + */ + export type GrantTokenParameters = { + /** + * Total number of minutes for which the token is valid. + * + * The minimum allowed value is `1`. + * The maximum is `43,200` minutes (`30` days). + */ + ttl: number; + /** + * Object containing resource permissions. + */ + resources?: { + /** + * Object containing `uuid` metadata permissions. + */ + uuids?: Record; + /** + * Object containing `channel` permissions. + */ + channels?: Record; + /** + * Object containing `channel group` permissions. + */ + groups?: Record; + }; + /** + * Object containing permissions to multiple resources specified by a RegEx pattern. + */ + patterns?: { + /** + * Object containing `uuid` metadata permissions to apply to all `uuids` matching the RegEx + * pattern. + */ + uuids?: Record; + /** + * Object containing `channel` permissions to apply to all `channels` matching the RegEx + * pattern. + */ + channels?: Record; + /** + * Object containing `channel group` permissions to apply to all `channel groups` matching the + * RegEx pattern. + */ + groups?: Record; + }; + /** + * Extra metadata to be published with the request. + * + * **Important:** Values must be scalar only; `arrays` or `objects` aren't supported. + */ + meta?: Metadata; + /** + * Single `uuid` which is authorized to use the token to make API requests to PubNub. + */ + authorized_uuid?: string; + }; + + /** + * Response with generated access token. + */ + export type GrantTokenResponse = string; + + /** + * Access token for which permissions should be revoked. + */ + export type RevokeParameters = string; + + /** + * Response with revoked access token. + */ + export type RevokeTokenResponse = Record; + + /** + * Decoded access token representation. + */ + export type Token = { + /** + * Token version. + */ + version: number; + /** + * Token generation date time. + */ + timestamp: number; + /** + * Maximum duration (in minutes) during which token will be valid. + */ + ttl: number; + /** + * Permissions granted to specific resources. + */ + resources?: Partial>>; + /** + * Permissions granted to resources which match specified regular expression. + */ + patterns?: Partial>>; + /** + * The uuid that is exclusively authorized to use this token to make API requests. + */ + authorized_uuid?: string; + /** + * PAM token content signature. + */ + signature: ArrayBuffer; + /** + * Additional information which has been added to the token. + */ + meta?: Payload; + }; + + /** + * Granted resource permissions. + * + * **Note:** Following operations doesn't require any permissions: + * - unsubscribe from channel / channel group + * - where now + */ + export type Permissions = { + /** + * Resource read permission. + * + * Read permission required for: + * - subscribe to channel / channel group (including presence versions `-pnpres`) + * - here now + * - get presence state + * - set presence state + * - fetch history + * - fetch messages count + * - list shared files + * - download shared file + * - enable / disable push notifications + * - get message actions + * - get history with message actions + */ + read: boolean; + /** + * Resource write permission. + * + * Write permission required for: + * - publish message / signal + * - share file + * - add message actions + */ + write: boolean; + /** + * Resource manage permission. + * + * Manage permission required for: + * - add / remove channels to / from the channel group + * - list channels in group + * - remove channel group + * - set / remove channel members + */ + manage: boolean; + /** + * Resource delete permission. + * + * Delete permission required for: + * - delete messages from history + * - delete shared file + * - delete user metadata + * - delete channel metadata + * - remove message action + */ + delete: boolean; + /** + * Resource get permission. + * + * Get permission required for: + * - get user metadata + * - get channel metadata + * - get channel members + */ + get: boolean; + /** + * Resource update permission. + * + * Update permissions required for: + * - set user metadata + * - set channel metadata + * - set / remove user membership + */ + update: boolean; + /** + * Resource `join` permission. + * + * `Join` permission required for: + * - set / remove channel members + */ + join: boolean; + }; + + /** + * Channel-specific permissions. + * + * Permissions include objects to the App Context Channel object as well. + */ + type ChannelPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + r?: 0 | 1; + /** + * Whether `write` operations are permitted for corresponding level or not. + */ + w?: 0 | 1; + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + d?: 0 | 1; + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + g?: 0 | 1; + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + u?: 0 | 1; + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + m?: 0 | 1; + /** + * Whether `join` operations are permitted for corresponding level or not. + */ + j?: 0 | 1; + /** + * Duration for which permissions has been granted. + */ + ttl?: number; + }; + + /** + * Channel group-specific permissions. + */ + type ChannelGroupPermissions = { + /** + * Whether `read` operations are permitted for corresponding level or not. + */ + r?: 0 | 1; + /** + * Whether `manage` operations are permitted for corresponding level or not. + */ + m?: 0 | 1; + /** + * Duration for which permissions has been granted. + */ + ttl?: number; + }; + + /** + * App Context User-specific permissions. + */ + type UserPermissions = { + /** + * Whether `get` operations are permitted for corresponding level or not. + */ + g?: 0 | 1; + /** + * Whether `update` operations are permitted for corresponding level or not. + */ + u?: 0 | 1; + /** + * Whether `delete` operations are permitted for corresponding level or not. + */ + d?: 0 | 1; + /** + * Duration for which permissions has been granted. + */ + ttl?: number; + }; + + /** + * Common permissions audit response content. + */ + type BaseAuditResponse< + Level extends 'channel' | 'channel+auth' | 'channel-group' | 'channel-group+auth' | 'user' | 'subkey', + > = { + /** + * Permissions level. + */ + level: Level; + /** + * Subscription key at which permissions has been granted. + */ + subscribe_key: string; + /** + * Duration for which permissions has been granted. + */ + ttl?: number; + }; + + /** + * Auth keys permissions for specified `level`. + */ + type AuthKeysPermissions = { + /** + * Auth keys-based permissions for specified `level` permission. + */ + auths: Record; + }; + + /** + * Single channel permissions audit result. + */ + type ChannelPermissionsResponse = BaseAuditResponse<'channel+auth'> & { + /** + * Name of channel for which permissions audited. + */ + channel: string; + } & AuthKeysPermissions; + + /** + * Multiple channels permissions audit result. + */ + type ChannelsPermissionsResponse = BaseAuditResponse<'channel'> & { + /** + * Per-channel permissions. + */ + channels: Record>; + }; + + /** + * Single channel group permissions result. + */ + type ChannelGroupPermissionsResponse = BaseAuditResponse<'channel-group+auth'> & { + /** + * Name of channel group for which permissions audited. + */ + 'channel-group': string; + } & AuthKeysPermissions; + + /** + * Multiple channel groups permissions audit result. + */ + type ChannelGroupsPermissionsResponse = BaseAuditResponse<'channel'> & { + /** + * Per-channel group permissions. + */ + 'channel-groups': Record>; + }; + + /** + * App Context User permissions audit result. + */ + type UserPermissionsResponse = BaseAuditResponse<'user'> & { + /** + * Name of channel for which `user` permissions audited. + */ + channel: string; + } & AuthKeysPermissions; + + /** + * Global sub-key level permissions audit result. + */ + type SubKeyPermissionsResponse = BaseAuditResponse<'subkey'> & { + /** + * Per-channel permissions. + */ + channels: Record>; + /** + * Per-channel group permissions. + */ + 'channel-groups': Record>; + /** + * Per-object permissions. + */ + objects: Record>; + }; + + /** + * Response with permission information. + */ + export type PermissionsResponse = + | ChannelPermissionsResponse + | ChannelsPermissionsResponse + | ChannelGroupPermissionsResponse + | ChannelGroupsPermissionsResponse + | UserPermissionsResponse + | SubKeyPermissionsResponse; + + /** + * Audit permissions for provided auth keys / global permissions. + * + * Audit permissions on specific channel and / or channel group for the set of auth keys. + */ + export type AuditParameters = { + /** + * Name of channel for which channel-based permissions should be checked for {@link authKeys}. + */ + channel?: string; + /** + * Name of channel group for which channel group-based permissions should be checked for {@link authKeys}. + */ + channelGroup?: string; + /** + * List of auth keys for which permissions should be checked. + * + * Leave this empty to check channel / group -based permissions or global permissions. + * + * @default `[]` + */ + authKeys?: string[]; + }; + + /** + * Grant permissions for provided auth keys / global permissions. + * + * Grant permissions on specific channel and / or channel group for the set of auth keys. + */ + export type GrantParameters = { + /** + * List of channels for which permissions should be granted. + */ + channels?: string[]; + /** + * List of channel groups for which permissions should be granted. + */ + channelGroups?: string[]; + /** + * List of App Context UUID for which permissions should be granted. + */ + uuids?: string[]; + /** + * List of auth keys for which permissions should be granted on specified objects. + * + * Leave this empty to grant channel / group -based permissions or global permissions. + */ + authKeys?: string[]; + /** + * Whether `read` operations are permitted for corresponding level or not. + * + * @default `false` + */ + read?: boolean; + /** + * Whether `write` operations are permitted for corresponding level or not. + * + * @default `false` + */ + write?: boolean; + /** + * Whether `delete` operations are permitted for corresponding level or not. + * + * @default `false` + */ + delete?: boolean; + /** + * Whether `get` operations are permitted for corresponding level or not. + * + * @default `false` + */ + get?: boolean; + /** + * Whether `update` operations are permitted for corresponding level or not. + * + * @default `false` + */ + update?: boolean; + /** + * Whether `manage` operations are permitted for corresponding level or not. + * + * @default `false` + */ + manage?: boolean; + /** + * Whether `join` operations are permitted for corresponding level or not. + * + * @default `false` + */ + join?: boolean; + /** + * For how long permissions should be effective (in minutes). + * + * @default `1440` + */ + ttl?: number; + }; + } + + export namespace Time { + /** + * Service success response. + */ + export type TimeResponse = { + /** + * High-precision time when published data has been received by the PubNub service. + */ + timetoken: string; + }; + } + + export namespace Push { + /** + * Common managed channels push notification parameters. + */ + type ManagedDeviceChannels = { + /** + * Channels to register or unregister with mobile push notifications. + */ + channels: string[]; + /** + * The device ID to associate with mobile push notifications. + */ + device: string; + /** + * Starting channel for pagination. + * + * **Note:** Use the last channel from the previous page request. + */ + start?: string; + /** + * Number of channels to return for pagination. + * + * **Note:** maximum of 1000 tokens at a time. + * + * @default `500` + */ + count?: number; + }; + + /** + * List all FCM device push notification enabled channels parameters. + */ + type ListFCMDeviceChannelsParameters = Omit; + + /** + * List all APNS device push notification enabled channels parameters. + * + * @deprecated Use `APNS2`-based endpoints. + */ + type ListAPNSDeviceChannelsParameters = Omit; + + /** + * List all APNS2 device push notification enabled channels parameters. + */ + type ListAPNS2DeviceChannelsParameters = Omit; + + /** + * List all device push notification enabled channels parameters. + */ + export type ListDeviceChannelsParameters = + | ListFCMDeviceChannelsParameters + | ListAPNSDeviceChannelsParameters + | ListAPNS2DeviceChannelsParameters; + + /** + * List all device push notification enabled channels response. + */ + export type ListDeviceChannelsResponse = { + /** + * List of channels registered for device push notifications. + */ + channels: string[]; + }; + + /** + * Manage FCM device push notification enabled channels parameters. + */ + type ManageFCMDeviceChannelsParameters = ManagedDeviceChannels & { + /** + * Push Notifications gateway type. + */ + pushGateway: 'gcm'; + }; + + /** + * Manage APNS device push notification enabled channels parameters. + * + * @deprecated Use `APNS2`-based endpoints. + */ + type ManageAPNSDeviceChannelsParameters = ManagedDeviceChannels & { + /** + * Push Notifications gateway type. + */ + pushGateway: 'apns'; + }; + + /** + * Manage APNS2 device push notification enabled channels parameters. + */ + type ManageAPNS2DeviceChannelsParameters = ManagedDeviceChannels & { + /** + * Push Notifications gateway type. + */ + pushGateway: 'apns2'; + /** + * Environment within which device should manage list of channels with enabled notifications. + */ + environment?: 'development' | 'production'; + /** + * Notifications topic name (usually it is bundle identifier of application for Apple platform). + */ + topic: string; + }; + + /** + * Manage device push notification enabled channels parameters. + */ + export type ManageDeviceChannelsParameters = + | ManageFCMDeviceChannelsParameters + | ManageAPNSDeviceChannelsParameters + | ManageAPNS2DeviceChannelsParameters; + + /** + * Manage device push notification enabled channels response. + */ + export type ManageDeviceChannelsResponse = Record; + + /** + * Remove all FCM device push notification enabled channels parameters. + */ + type RemoveFCMDeviceParameters = Omit; + + /** + * Manage APNS device push notification enabled channels parameters. + * + * @deprecated Use `APNS2`-based endpoints. + */ + type RemoveAPNSDeviceParameters = Omit; + + /** + * Manage APNS2 device push notification enabled channels parameters. + */ + type RemoveAPNS2DeviceParameters = Omit; + + /** + * Remove all device push notification enabled channels parameters. + */ + export type RemoveDeviceParameters = + | RemoveFCMDeviceParameters + | RemoveAPNSDeviceParameters + | RemoveAPNS2DeviceParameters; + + /** + * Remove all device push notification enabled channels response. + */ + export type RemoveDeviceResponse = Record; + } +} + +export = PubNub; diff --git a/lib/types/models/Cursor.d.ts b/lib/types/models/Cursor.d.ts deleted file mode 100644 index 8ba000353..000000000 --- a/lib/types/models/Cursor.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type Cursor = { - readonly timetoken: string; - readonly region: number; -}; diff --git a/lib/types/node/configuration.d.ts b/lib/types/node/configuration.d.ts deleted file mode 100644 index 1d31293bb..000000000 --- a/lib/types/node/configuration.d.ts +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Node.js specific {@link PubNub} client configuration module. - */ -import { UserConfiguration } from '../core/interfaces/configuration'; -import { TransportKeepAlive } from '../core/interfaces/transport'; -import { Payload } from '../core/types/api'; -import { CryptoModule } from '../core/interfaces/crypto-module'; -/** - * NodeJS platform PubNub client configuration. - */ -export type PubNubConfiguration = UserConfiguration & { - /** - * Set a custom parameters for setting your connection `keepAlive` if this is set to `true`. - */ - keepAliveSettings?: TransportKeepAlive; - /** - * The cryptography module used for encryption and decryption of messages and files. Takes the - * {@link cipherKey} and {@link useRandomIVs} parameters as arguments. - * - * For more information, refer to the - * {@link /docs/sdks/javascript/api-reference/configuration#cryptomodule|cryptoModule} section. - * - * @default `not set` - */ - cryptoModule?: CryptoModule; - /** - * If passed, will encrypt the payloads. - * - * @deprecated Pass it to {@link cryptoModule} instead. - */ - cipherKey?: string; - /** - * When `true` the initialization vector (IV) is random for all requests (not just for file - * upload). - * When `false` the IV is hard-coded for all requests except for file upload. - * - * @default `true` - * - * @deprecated Pass it to {@link cryptoModule} instead. - */ - useRandomIVs?: boolean; - /** - * Custom data encryption method. - * - * @deprecated Instead use {@link cryptoModule} for data encryption. - */ - customEncrypt?: (data: string | Payload) => string; - /** - * Custom data decryption method. - * - * @deprecated Instead use {@link cryptoModule} for data decryption. - */ - customDecrypt?: (data: string) => string; -}; diff --git a/lib/types/node/index.d.ts b/lib/types/node/index.d.ts deleted file mode 100644 index b06546497..000000000 --- a/lib/types/node/index.d.ts +++ /dev/null @@ -1,38 +0,0 @@ -/// -/// -import { ProxyAgentOptions } from 'proxy-agent'; -import { Readable } from 'stream'; -import { Buffer } from 'buffer'; -import type { CryptoModule as CryptoModuleType } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; -import PubNubFile, { PubNubFileParameters } from '../file/modules/node'; -import { PubNubConfiguration } from './configuration'; -import { PubNubFileConstructor } from '../core/types/file'; -import { PubNubCore } from '../core/pubnub-common'; -/** - * PubNub client for Node.js platform. - */ -declare class PubNub extends PubNubCore { - /** - * Data encryption / decryption module constructor. - */ - static CryptoModule: typeof CryptoModuleType; - /** - * PubNub File constructor. - */ - File: PubNubFileConstructor; - /** - * Actual underlying transport provider. - */ - private nodeTransport; - constructor(configuration: PubNubConfiguration); - /** - * Update request proxy configuration. - * - * @param configuration - Updated request proxy configuration. - * - * @throws An error if {@link PubNub} client already configured to use `keepAlive`. - * `keepAlive` and `proxy` can't be used simultaneously. - */ - setProxy(configuration?: ProxyAgentOptions): void; -} -export = PubNub; diff --git a/lib/types/react_native/configuration.d.ts b/lib/types/react_native/configuration.d.ts deleted file mode 100644 index a17ce3370..000000000 --- a/lib/types/react_native/configuration.d.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { UserConfiguration } from '../core/interfaces/configuration'; -/** - * React Native platform PubNub client configuration. - */ -export type PubNubConfiguration = UserConfiguration; diff --git a/lib/types/react_native/index.d.ts b/lib/types/react_native/index.d.ts deleted file mode 100644 index 3dcb30caf..000000000 --- a/lib/types/react_native/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -import 'react-native-url-polyfill/auto'; -import { PubNubFileParameters } from '../file/modules/react-native'; -import { PubNubConfiguration } from './configuration'; -import { PubNubCore } from '../core/pubnub-common'; -/** - * PubNub client for React Native platform. - */ -export default class PubNub extends PubNubCore { - constructor(configuration: PubNubConfiguration); -} diff --git a/lib/types/transport/middleware.d.ts b/lib/types/transport/middleware.d.ts deleted file mode 100644 index 5cdd75842..000000000 --- a/lib/types/transport/middleware.d.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { TransportRequest } from '../core/types/transport-request'; -import { PrivateClientConfiguration } from '../core/interfaces/configuration'; -import { TokenManager } from '../core/components/token_manager'; -import { Transport } from '../core/interfaces/transport'; -/** - * Transport middleware configuration options. - */ -type PubNubMiddlewareConfiguration = { - /** - * Private client configuration. - */ - clientConfiguration: PrivateClientConfiguration; - /** - * REST API endpoints access tokens manager. - */ - tokenManager?: TokenManager; - /** - * HMAC-SHA256 hash generator from provided `data`. - */ - shaHMAC?: (data: string) => string; - /** - * Platform-specific transport for requests processing. - */ - transport: Transport; -}; -export declare class PubNubMiddleware implements Transport { - private configuration; - /** - * Request signature generator. - */ - signatureGenerator?: RequestSignature; - constructor(configuration: PubNubMiddlewareConfiguration); - makeSendable(req: TransportRequest): [Promise, import("../core/types/transport-request").CancellationController | undefined]; - request(req: TransportRequest): TransportRequest; - private authenticateRequest; - /** - * Compute and append request signature. - * - * @param req - Transport request with information which should be used to generate signature. - */ - private signRequest; - /** - * Compose `pnsdk` query parameter. - * - * SDK provides ability to set custom name or append vendor information to the `pnsdk` query - * parameter. - * - * @returns Finalized `pnsdk` query parameter value. - */ - private generatePNSDK; -} -export {}; diff --git a/lib/types/transport/node-transport.d.ts b/lib/types/transport/node-transport.d.ts deleted file mode 100644 index 1e2d7f5b9..000000000 --- a/lib/types/transport/node-transport.d.ts +++ /dev/null @@ -1,69 +0,0 @@ -import { Request } from 'node-fetch'; -import { ProxyAgentOptions } from 'proxy-agent'; -import { CancellationController, TransportRequest } from '../core/types/transport-request'; -import { Transport, TransportKeepAlive } from '../core/interfaces/transport'; -import { TransportResponse } from '../core/types/transport-response'; -/** - * Class representing a fetch-based Node.js transport provider. - */ -export declare class NodeTransport implements Transport { - private readonly keepAlive; - private readonly keepAliveSettings; - private readonly logVerbosity; - /** - * Service {@link ArrayBuffer} response decoder. - */ - protected static decoder: TextDecoder; - /** - * Request proxy configuration. - */ - private proxyConfiguration?; - private proxyAgent?; - private httpsAgent?; - private httpAgent?; - /** - * Creates a new `fetch`-based transport instance. - * - * @param keepAlive - Indicates whether keep-alive should be enabled. - * @param [keepAliveSettings] - Optional settings for keep-alive. - * @param [logVerbosity] - Whether verbose logging enabled or not. - * - * @returns Transport for performing network requests. - */ - constructor(keepAlive?: boolean, keepAliveSettings?: TransportKeepAlive, logVerbosity?: boolean); - /** - * Update request proxy configuration. - * - * @param configuration - New proxy configuration. - */ - setProxy(configuration?: ProxyAgentOptions): void; - makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; - request(req: TransportRequest): TransportRequest; - /** - * Creates a Request object from a given {@link TransportRequest} object. - * - * @param req - The {@link TransportRequest} object containing request information. - * - * @returns Request object generated from the {@link TransportRequest} object. - */ - private requestFromTransportRequest; - /** - * Determines and returns the appropriate agent for a given transport request. - * - * If keep alive is not requested, returns undefined. - * - * @param req - The transport request object. - * - * @returns {HttpAgent | HttpsAgent | undefined} - The appropriate agent for the request, or - * undefined if keep alive or proxy not requested. - */ - private agentForTransportRequest; - /** - * Log out request processing progress and result. - * - * @param request - Platform-specific request object. - * @param [elapsed] - How many times passed since request processing started. - * @param [body] - Service response (if available). - */ - protected logRequestProcessProgress(request: Request, elapsed?: number, body?: ArrayBuffer): void; -} diff --git a/lib/types/transport/web-react-native-transport.d.ts b/lib/types/transport/web-react-native-transport.d.ts deleted file mode 100644 index 753788bfd..000000000 --- a/lib/types/transport/web-react-native-transport.d.ts +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Common browser and React Native Transport provider module. - */ -import { CancellationController, TransportRequest } from '../core/types/transport-request'; -import { TransportResponse } from '../core/types/transport-response'; -import { Transport } from '../core/interfaces/transport'; -/** - * Class representing a `fetch`-based browser and React Native transport provider. - */ -export declare class WebReactNativeTransport implements Transport { - private keepAlive; - private readonly logVerbosity; - /** - * Service {@link ArrayBuffer} response decoder. - */ - protected static decoder: TextDecoder; - constructor(keepAlive: boolean, logVerbosity: boolean); - makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; - request(req: TransportRequest): TransportRequest; - /** - * Creates a Request object from a given {@link TransportRequest} object. - * - * @param req - The {@link TransportRequest} object containing request information. - * - * @returns Request object generated from the {@link TransportRequest} object. - */ - private requestFromTransportRequest; - /** - * Log out request processing progress and result. - * - * @param request - Platform-specific - * @param [elapsed] - How many seconds passed since request processing started. - * @param [body] - Service response (if available). - */ - protected logRequestProcessProgress(request: Request, elapsed?: number, body?: ArrayBuffer): void; -} diff --git a/package-lock.json b/package-lock.json index e04f847d0..0602ecedf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.2.7", + "version": "8.2.9", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.2.7", + "version": "8.2.9", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", @@ -21,8 +21,6 @@ "text-encoding": "^0.7.0" }, "devDependencies": { - "@cucumber/cucumber": "^10.4.0", - "@cucumber/pretty-formatter": "^1.0.0", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.2.3", @@ -32,7 +30,6 @@ "@types/cbor-js": "^0.1.1", "@types/chai": "^4.3.14", "@types/chai-as-promised": "^7.1.8", - "@types/cucumber": "^7.0.0", "@types/expect": "^24.3.0", "@types/lil-uuid": "^0.1.3", "@types/mocha": "^9.1.0", @@ -41,12 +38,12 @@ "@types/sinon": "^17.0.3", "@types/text-encoding": "^0.0.39", "@types/underscore": "^1.11.15", - "@typescript-eslint/eslint-plugin": "^7.4.0", - "@typescript-eslint/parser": "^7.4.0", + "@typescript-eslint/eslint-plugin": "^8.12.2", + "@typescript-eslint/parser": "^8.12.2", "chai": "^4.4.1", "chai-as-promised": "^7.1.1", "chai-nock": "^1.2.0", - "cucumber-pretty": "^6.0.1", + "commander": "^12.1.0", "cucumber-tsflow": "^4.4.4", "es6-shim": "^0.35.8", "eslint": "^8.57.0", @@ -61,10 +58,10 @@ "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.32", "mocha": "10.4.0", - "nock": "^14.0.0-beta.5", + "nock": "^14.0.0-beta.15", "prettier": "^3.2.5", "rimraf": "^3.0.2", - "rollup": "^4.13.2", + "rollup": "4.22.4", "rollup-plugin-gzip": "^3.1.2", "rollup-plugin-string": "^3.0.0", "sinon": "^7.5.0", @@ -77,19 +74,11 @@ "underscore": "^1.9.2" } }, - "node_modules/@aashutoshrathi/word-wrap": { - "version": "1.2.6", - "resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz", - "integrity": "sha512-1Yjs2SvM8TflER/OD3cOjhWWOZb58A2t7wpE2S9XfBYTiIl+XFhQG2bjy4Pu1I+EAlCNUzRDYDdFwFYUKvXcIA==", - "dev": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/@ampproject/remapping": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", "integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==", + "license": "Apache-2.0", "peer": true, "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", @@ -100,11 +89,13 @@ } }, "node_modules/@babel/code-frame": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.24.2.tgz", - "integrity": "sha512-y5+tLQyV8pg3fsiln67BVLD1P13Eg4lh5RW9mF0zUuvLrv9uIQ4MCL+CRT+FTsBlBjcIan6PGsLcBN0m3ClUyQ==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", + "integrity": "sha512-RJlIHRueQgwWitWgF8OdFYGZX328Ax5BCemNGlqHfplnRT9ESi8JkFlvaVYbS+UubVY6dpv87Fs2u5M29iNFVQ==", + "license": "MIT", "dependencies": { - "@babel/highlight": "^7.24.2", + "@babel/helper-validator-identifier": "^7.25.9", + "js-tokens": "^4.0.0", "picocolors": "^1.0.0" }, "engines": { @@ -112,30 +103,32 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.24.4.tgz", - "integrity": "sha512-vg8Gih2MLK+kOkHJp4gBEIkyaIi00jgWot2D9QOmmfLC8jINSOzmCLta6Bvz/JSBCqnegV0L80jhxkol5GWNfQ==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.26.2.tgz", + "integrity": "sha512-Z0WgzSEa+aUcdiJuCIqgujCshpMWgUpgOxXotrYPSA53hA3qopNaqcJpyr0hVb1FeWdnqFA35/fUtXgBK8srQg==", + "license": "MIT", "peer": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/core": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.24.4.tgz", - "integrity": "sha512-MBVlMXP+kkl5394RBLSxxk/iLTeVGuXTV3cIDXavPpMMqnSnt6apKgan/U8O3USWZCWZT/TbgfEpKa4uMgN4Dg==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.26.0.tgz", + "integrity": "sha512-i1SLeK+DzNnQ3LL/CswPCa/E5u4lh1k6IAEphON8F+cXt0t9euTshDru0q7/IqMa1PMPz5RnHuHscF8/ZJsStg==", + "license": "MIT", "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", - "@babel/code-frame": "^7.24.2", - "@babel/generator": "^7.24.4", - "@babel/helper-compilation-targets": "^7.23.6", - "@babel/helper-module-transforms": "^7.23.3", - "@babel/helpers": "^7.24.4", - "@babel/parser": "^7.24.4", - "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.1", - "@babel/types": "^7.24.0", + "@babel/code-frame": "^7.26.0", + "@babel/generator": "^7.26.0", + "@babel/helper-compilation-targets": "^7.25.9", + "@babel/helper-module-transforms": "^7.26.0", + "@babel/helpers": "^7.26.0", + "@babel/parser": "^7.26.0", + "@babel/template": "^7.25.9", + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.26.0", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -150,75 +143,70 @@ "url": "https://opencollective.com/babel" } }, - "node_modules/@babel/core/node_modules/json5": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", - "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", - "peer": true, - "bin": { - "json5": "lib/cli.js" - }, - "engines": { - "node": ">=6" - } - }, "node_modules/@babel/core/node_modules/semver": { "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", "peer": true, "bin": { "semver": "bin/semver.js" } }, "node_modules/@babel/generator": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.24.4.tgz", - "integrity": "sha512-Xd6+v6SnjWVx/nus+y0l1sxMOTOMBkyL4+BIdbALyatQnAe/SRVjANeDPSCYaX+i1iJmuGSKf3Z+E+V/va1Hvw==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.26.2.tgz", + "integrity": "sha512-zevQbhbau95nkoxSq3f/DC/SC+EEOUZd3DYqfSkMhY2/wfSeaHV1Ew4vk8e+x8lja31IbyuUa2uQ3JONqKbysw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/types": "^7.24.0", + "@babel/parser": "^7.26.2", + "@babel/types": "^7.26.0", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", - "jsesc": "^2.5.1" + "jsesc": "^3.0.2" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-annotate-as-pure": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.22.5.tgz", - "integrity": "sha512-LvBTxu8bQSQkcyKOU+a1btnNFQ1dMAd0R6PyW3arXes06F6QLWLIrd681bxRPIXlrMGR3XYnW9JyML7dP3qgxg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-annotate-as-pure/-/helper-annotate-as-pure-7.25.9.tgz", + "integrity": "sha512-gv7320KBUFJz1RnylIg5WWYPRXKZ884AGkYpgpWW02TH66Dl+HaC1t1CKd0z3R4b6hdYEcmrNZHUmfCP+1u3/g==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/types": "^7.22.5" + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-builder-binary-assignment-operator-visitor": { - "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.22.15.tgz", - "integrity": "sha512-QkBXwGgaoC2GtGZRoma6kv7Szfv06khvhFav67ZExau2RaXzy8MpHSMO2PNoP2XtmQphJQRHFfg77Bq731Yizw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.25.9.tgz", + "integrity": "sha512-C47lC7LIDCnz0h4vai/tpNOI95tCd5ZT3iBt/DBH5lXKHZsyNQv18yf1wIIg2ntiQNgmAvA+DgZ82iW8Qdym8g==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/types": "^7.22.15" + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.23.6", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.23.6.tgz", - "integrity": "sha512-9JB548GZoQVmzrFgp8o7KxdgkTGm6xs9DW0o/Pim72UDjzr5ObUQ6ZzYPqA+g9OTS2bBQoctLJrky0RDCAWRgQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.25.9.tgz", + "integrity": "sha512-j9Db8Suy6yV/VHa4qzrj9yZfZxhLWQdVnRlXxmKLYlhWUVB1sB2G5sxuWYXk/whHD9iW76PmNzxZ4UCnTQTVEQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/compat-data": "^7.23.5", - "@babel/helper-validator-option": "^7.23.5", - "browserslist": "^4.22.2", + "@babel/compat-data": "^7.25.9", + "@babel/helper-validator-option": "^7.25.9", + "browserslist": "^4.24.0", "lru-cache": "^5.1.1", "semver": "^6.3.1" }, @@ -230,6 +218,7 @@ "version": "5.1.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz", "integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==", + "license": "ISC", "peer": true, "dependencies": { "yallist": "^3.0.2" @@ -239,31 +228,25 @@ "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", "peer": true, "bin": { "semver": "bin/semver.js" } }, - "node_modules/@babel/helper-compilation-targets/node_modules/yallist": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", - "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", - "peer": true - }, "node_modules/@babel/helper-create-class-features-plugin": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.24.4.tgz", - "integrity": "sha512-lG75yeuUSVu0pIcbhiYMXBXANHrpUPaOfu7ryAzskCgKUHuAxRQI5ssrtmF0X9UXldPlvT0XM/A4F44OXRt6iQ==", - "peer": true, - "dependencies": { - "@babel/helper-annotate-as-pure": "^7.22.5", - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-function-name": "^7.23.0", - "@babel/helper-member-expression-to-functions": "^7.23.0", - "@babel/helper-optimise-call-expression": "^7.22.5", - "@babel/helper-replace-supers": "^7.24.1", - "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.22.6", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.25.9.tgz", + "integrity": "sha512-UTZQMvt0d/rSz6KI+qdu7GQze5TIajwTS++GUozlw8VBJDEOAqSXwm1WvmYEZwqdqSGQshRocPDqrt4HBZB3fQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.25.9", + "@babel/helper-member-expression-to-functions": "^7.25.9", + "@babel/helper-optimise-call-expression": "^7.25.9", + "@babel/helper-replace-supers": "^7.25.9", + "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9", + "@babel/traverse": "^7.25.9", "semver": "^6.3.1" }, "engines": { @@ -277,19 +260,21 @@ "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", "peer": true, "bin": { "semver": "bin/semver.js" } }, "node_modules/@babel/helper-create-regexp-features-plugin": { - "version": "7.22.15", - "resolved": "https://registry.npmjs.org/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.22.15.tgz", - "integrity": "sha512-29FkPLFjn4TPEa3RE7GpW+qbE8tlsu3jntNYNfcGsc49LphF1PQIiD+vMZ1z1xVOKt+93khA9tc2JBs3kBjA7w==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.25.9.tgz", + "integrity": "sha512-ORPNZ3h6ZRkOyAa/SaHU+XsLZr0UQzRwuDQ0cczIA17nAzZ+85G5cVkOJIj7QavLZGSe8QXUmNFxSZzjcZF9bw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-annotate-as-pure": "^7.22.5", - "regexpu-core": "^5.3.1", + "@babel/helper-annotate-as-pure": "^7.25.9", + "regexpu-core": "^6.1.1", "semver": "^6.3.1" }, "engines": { @@ -303,15 +288,17 @@ "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", "peer": true, "bin": { "semver": "bin/semver.js" } }, "node_modules/@babel/helper-define-polyfill-provider": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/@babel/helper-define-polyfill-provider/-/helper-define-polyfill-provider-0.6.1.tgz", - "integrity": "sha512-o7SDgTJuvx5vLKD6SFvkydkSMBvahDKGiNJzG22IZYXhiqoe9efY7zocICBgzHV4IRg5wdgl2nEL/tulKIEIbA==", + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/@babel/helper-define-polyfill-provider/-/helper-define-polyfill-provider-0.6.2.tgz", + "integrity": "sha512-LV76g+C502biUK6AyZ3LK10vDpDyCzZnhZFXkH1L75zHPj68+qc8Zfpx2th+gzwA2MzyK+1g/3EPl62yFnVttQ==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-compilation-targets": "^7.22.6", @@ -324,75 +311,44 @@ "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, - "node_modules/@babel/helper-environment-visitor": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.20.tgz", - "integrity": "sha512-zfedSIzFhat/gFhWfHtgWvlec0nqB9YEIVrpuwjruLlXfUSnA8cJB0miHKwqDnQ7d32aKo2xt88/xZptwxbfhA==", - "peer": true, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-function-name": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.23.0.tgz", - "integrity": "sha512-OErEqsrxjZTJciZ4Oo+eoZqeW9UIiOcuYKRJA4ZAgV9myA+pOXhhmpfNCKjEH/auVfEYVFJ6y1Tc4r0eIApqiw==", - "peer": true, - "dependencies": { - "@babel/template": "^7.22.15", - "@babel/types": "^7.23.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-hoist-variables": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz", - "integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==", - "peer": true, - "dependencies": { - "@babel/types": "^7.22.5" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/@babel/helper-member-expression-to-functions": { - "version": "7.23.0", - "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.23.0.tgz", - "integrity": "sha512-6gfrPwh7OuT6gZyJZvd6WbTfrqAo7vm4xCzAXOusKqq/vWdKXphTpj5klHKNmRUU6/QRGlBsyU9mAIPaWHlqJA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-member-expression-to-functions/-/helper-member-expression-to-functions-7.25.9.tgz", + "integrity": "sha512-wbfdZ9w5vk0C0oyHqAJbc62+vet5prjj01jjJ8sKn3j9h3MQQlflEdXYvuqRWjHnM12coDEqiC1IRCi0U/EKwQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/types": "^7.23.0" + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-imports": { - "version": "7.24.3", - "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.24.3.tgz", - "integrity": "sha512-viKb0F9f2s0BCS22QSF308z/+1YWKV/76mwt61NBzS5izMzDPwdq1pTrzf+Li3npBWX9KdQbkeCt1jSAM7lZqg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.25.9.tgz", + "integrity": "sha512-tnUA4RsrmflIM6W6RFTLFSXITtl0wKjgpnLgXyowocVPrbYrLUXSBXDgTs8BlbmIzIdlBySRQjINYs2BAkiLtw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/types": "^7.24.0" + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-module-transforms": { - "version": "7.23.3", - "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.23.3.tgz", - "integrity": "sha512-7bBs4ED9OmswdfDzpz4MpWgSrV7FXlc3zIagvLFjS5H+Mk7Snr21vQ6QwrsoCGMfNC4e4LQPdoULEt4ykz0SRQ==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.26.0.tgz", + "integrity": "sha512-xO+xu6B5K2czEnQye6BHA7DolFFmS3LB7stHZFaOLb1pAwO1HWLS8fXA+eh0A2yIvltPVmx3eNNDBJA2SLHXFw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-module-imports": "^7.22.15", - "@babel/helper-simple-access": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/helper-validator-identifier": "^7.22.20" + "@babel/helper-module-imports": "^7.25.9", + "@babel/helper-validator-identifier": "^7.25.9", + "@babel/traverse": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -402,35 +358,38 @@ } }, "node_modules/@babel/helper-optimise-call-expression": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.22.5.tgz", - "integrity": "sha512-HBwaojN0xFRx4yIvpwGqxiV2tUfl7401jlok564NgB9EHS1y6QT17FmKWm4ztqjeVdXLuC4fSvHc5ePpQjoTbw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-optimise-call-expression/-/helper-optimise-call-expression-7.25.9.tgz", + "integrity": "sha512-FIpuNaz5ow8VyrYcnXQTDRGvV6tTjkNtCK/RYNDXGSLlUD6cBuQTSw43CShGxjvfBTfcUA/r6UhUCbtYqkhcuQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/types": "^7.22.5" + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.24.0", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.24.0.tgz", - "integrity": "sha512-9cUznXMG0+FxRuJfvL82QlTqIzhVW9sL0KjMPHhAOOvpQGL8QtdxnBKILjBqxlHyliz0yCa1G903ZXI/FuHy2w==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.25.9.tgz", + "integrity": "sha512-kSMlyUVdWe25rEsRGviIgOWnoT/nfABVWlqt9N19/dIPWViAOW2s9wznP5tURbs/IDuNk4gPy3YdYRgH3uxhBw==", + "license": "MIT", "peer": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-remap-async-to-generator": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.22.20.tgz", - "integrity": "sha512-pBGyV4uBqOns+0UvhsTO8qgl8hO89PmiDYv+/COyp1aeMcmfrfruz+/nCMFiYyFF/Knn0yfrC85ZzNFjembFTw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-remap-async-to-generator/-/helper-remap-async-to-generator-7.25.9.tgz", + "integrity": "sha512-IZtukuUeBbhgOcaW2s06OXTzVNJR0ybm4W5xC1opWFFJMZbwRj5LCk+ByYH7WdZPZTt8KnFwA8pvjN2yqcPlgw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-annotate-as-pure": "^7.22.5", - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-wrap-function": "^7.22.20" + "@babel/helper-annotate-as-pure": "^7.25.9", + "@babel/helper-wrap-function": "^7.25.9", + "@babel/traverse": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -440,14 +399,15 @@ } }, "node_modules/@babel/helper-replace-supers": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.24.1.tgz", - "integrity": "sha512-QCR1UqC9BzG5vZl8BMicmZ28RuUBnHhAMddD8yHFHDRH9lLTZ9uUPehX8ctVPT8l0TKblJidqcgUUKGVrePleQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.25.9.tgz", + "integrity": "sha512-IiDqTOTBQy0sWyeXyGSC5TBJpGFXBkRynjBeXsvbhQFKj2viwJC76Epz35YLU1fpe/Am6Vppb7W7zM4fPQzLsQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-member-expression-to-functions": "^7.23.0", - "@babel/helper-optimise-call-expression": "^7.22.5" + "@babel/helper-member-expression-to-functions": "^7.25.9", + "@babel/helper-optimise-call-expression": "^7.25.9", + "@babel/traverse": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -457,165 +417,100 @@ } }, "node_modules/@babel/helper-simple-access": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.22.5.tgz", - "integrity": "sha512-n0H99E/K+Bika3++WNL17POvo4rKWZ7lZEp1Q+fStVbUi8nxPQEBOlTmCOxW/0JsS56SKKQ+ojAe2pHKJHN35w==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.25.9.tgz", + "integrity": "sha512-c6WHXuiaRsJTyHYLJV75t9IqsmTbItYfdj99PnzYGQZkYKvan5/2jKJ7gu31J3/BJ/A18grImSPModuyG/Eo0Q==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/types": "^7.22.5" + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-skip-transparent-expression-wrappers": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/helper-skip-transparent-expression-wrappers/-/helper-skip-transparent-expression-wrappers-7.22.5.tgz", - "integrity": "sha512-tK14r66JZKiC43p8Ki33yLBVJKlQDFoA8GYN67lWCDCqoL6EMMSuM9b+Iff2jHaM/RRFYl7K+iiru7hbRqNx8Q==", - "peer": true, - "dependencies": { - "@babel/types": "^7.22.5" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/helper-split-export-declaration": { - "version": "7.22.6", - "resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.6.tgz", - "integrity": "sha512-AsUnxuLhRYsisFiaJwvp1QF+I3KjD5FOxut14q/GzovUe6orHLesW2C7d754kRm53h5gqrz6sFl6sxc4BVtE/g==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-skip-transparent-expression-wrappers/-/helper-skip-transparent-expression-wrappers-7.25.9.tgz", + "integrity": "sha512-K4Du3BFa3gvyhzgPcntrkDgZzQaq6uozzcpGbOO1OEJaI+EJdqWIMTLgFgQf6lrfiDFo5FU+BxKepI9RmZqahA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/types": "^7.22.5" + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-string-parser": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.24.1.tgz", - "integrity": "sha512-2ofRCjnnA9y+wk8b9IAREroeUP02KHp431N2mhKniy2yKIDKpbrHv9eXwm8cBeWQYcJmzv5qKCu65P47eCF7CQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz", + "integrity": "sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==", + "license": "MIT", "peer": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-identifier": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.20.tgz", - "integrity": "sha512-Y4OZ+ytlatR8AI+8KZfKuL5urKp7qey08ha31L8b3BwewJAoJamTzyvxPR/5D+KkdJCGPq/+8TukHBlY10FX9A==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz", + "integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==", + "license": "MIT", "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-validator-option": { - "version": "7.23.5", - "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.23.5.tgz", - "integrity": "sha512-85ttAOMLsr53VgXkTbkx8oA6YTfT4q7/HzXSLEYmjcSTJPMPQtvq1BD79Byep5xMUYbGRzEpDsjUf3dyp54IKw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.25.9.tgz", + "integrity": "sha512-e/zv1co8pp55dNdEcCynfj9X7nyUKUXoUEwfXqaZt0omVOmDe9oOTdKStH4GmAw6zxMFs50ZayuMfHDKlO7Tfw==", + "license": "MIT", "peer": true, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helper-wrap-function": { - "version": "7.22.20", - "resolved": "https://registry.npmjs.org/@babel/helper-wrap-function/-/helper-wrap-function-7.22.20.tgz", - "integrity": "sha512-pms/UwkOpnQe/PDAEdV/d7dVCoBbB+R4FvYoHGZz+4VPcg7RtYy2KP7S2lbuWM6FCSgob5wshfGESbC/hzNXZw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/helper-wrap-function/-/helper-wrap-function-7.25.9.tgz", + "integrity": "sha512-ETzz9UTjQSTmw39GboatdymDq4XIQbR8ySgVrylRhPOFpsd+JrKHIuF0de7GCWmem+T4uC5z7EZguod7Wj4A4g==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-function-name": "^7.22.5", - "@babel/template": "^7.22.15", - "@babel/types": "^7.22.19" + "@babel/template": "^7.25.9", + "@babel/traverse": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/helpers": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.24.4.tgz", - "integrity": "sha512-FewdlZbSiwaVGlgT1DPANDuCHaDMiOo+D/IDYRFYjHOuv66xMSJ7fQwwODwRNAPkADIO/z1EoF/l2BCWlWABDw==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.26.0.tgz", + "integrity": "sha512-tbhNuIxNcVb21pInl3ZSjksLCvgdZy9KwJ8brv993QtIVKJBBkYXz4q4ZbAv31GdnC+R90np23L5FbEBlthAEw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/template": "^7.24.0", - "@babel/traverse": "^7.24.1", - "@babel/types": "^7.24.0" - }, - "engines": { - "node": ">=6.9.0" - } - }, - "node_modules/@babel/highlight": { - "version": "7.24.2", - "resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.24.2.tgz", - "integrity": "sha512-Yac1ao4flkTxTteCDZLEvdxg2fZfz1v8M4QpaGypq/WPDqg3ijHYbDfs+LG5hvzSoqaSZ9/Z9lKSP3CjZjv+pA==", - "dependencies": { - "@babel/helper-validator-identifier": "^7.22.20", - "chalk": "^2.4.2", - "js-tokens": "^4.0.0", - "picocolors": "^1.0.0" + "@babel/template": "^7.25.9", + "@babel/types": "^7.26.0" }, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/highlight/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "dependencies": { - "color-convert": "^1.9.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/highlight/node_modules/chalk": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", - "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", - "dependencies": { - "ansi-styles": "^3.2.1", - "escape-string-regexp": "^1.0.5", - "supports-color": "^5.3.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/highlight/node_modules/escape-string-regexp": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", - "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", - "engines": { - "node": ">=0.8.0" - } - }, - "node_modules/@babel/highlight/node_modules/has-flag": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", - "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", - "engines": { - "node": ">=4" - } - }, - "node_modules/@babel/highlight/node_modules/supports-color": { - "version": "5.5.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", - "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", - "dependencies": { - "has-flag": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, "node_modules/@babel/parser": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.4.tgz", - "integrity": "sha512-zTvEBcghmeBma9QIGunWevvBAp4/Qu9Bdq+2k0Ot4fVMD6v3dsC9WOcRSKk7tRRyBM/53yKMJko9xOatGQAwSg==", + "version": "7.26.2", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.2.tgz", + "integrity": "sha512-DWMCZH9WA4Maitz2q21SRKHo9QXZxkDsbNZoVD62gusNtNBBqDg9i7uOhASfTfIGNzW+O+r7+jAlM8dwphcJKQ==", + "license": "MIT", "peer": true, + "dependencies": { + "@babel/types": "^7.26.0" + }, "bin": { "parser": "bin/babel-parser.js" }, @@ -624,13 +519,14 @@ } }, "node_modules/@babel/plugin-bugfix-firefox-class-in-computed-class-key": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-firefox-class-in-computed-class-key/-/plugin-bugfix-firefox-class-in-computed-class-key-7.24.4.tgz", - "integrity": "sha512-qpl6vOOEEzTLLcsuqYYo8yDtrTocmu2xkGvgNebvPjT9DTtfFYGmgDqY+rBYXNlqL4s9qLDn6xkrJv4RxAPiTA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-firefox-class-in-computed-class-key/-/plugin-bugfix-firefox-class-in-computed-class-key-7.25.9.tgz", + "integrity": "sha512-ZkRyVkThtxQ/J6nv3JFYv1RYY+JT5BvU0y3k5bWrmuG4woXypRa4PXmm9RhOwodRkYFWqC0C0cqcJ4OqR7kW+g==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/traverse": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -639,13 +535,14 @@ "@babel/core": "^7.0.0" } }, - "node_modules/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression/-/plugin-bugfix-safari-id-destructuring-collision-in-function-expression-7.24.1.tgz", - "integrity": "sha512-y4HqEnkelJIOQGd+3g1bTeKsA5c6qM7eOn7VggGVbBc0y8MLSKHacwcIE2PplNlQSj0PqS9rrXL/nkPVK+kUNg==", + "node_modules/@babel/plugin-bugfix-safari-class-field-initializer-scope": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-safari-class-field-initializer-scope/-/plugin-bugfix-safari-class-field-initializer-scope-7.25.9.tgz", + "integrity": "sha512-MrGRLZxLD/Zjj0gdU15dfs+HH/OXvnw/U4jJD8vpcP2CJQapPEv1IWwjc/qMg7ItBlPwSv1hRBbb7LeuANdcnw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -654,56 +551,55 @@ "@babel/core": "^7.0.0" } }, - "node_modules/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining/-/plugin-bugfix-v8-spread-parameters-in-optional-chaining-7.24.1.tgz", - "integrity": "sha512-Hj791Ii4ci8HqnaKHAlLNs+zaLXb0EzSDhiAWp5VNlyvCNymYfacs64pxTxbH1znW/NcArSmwpmG9IKE/TUVVQ==", + "node_modules/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression/-/plugin-bugfix-safari-id-destructuring-collision-in-function-expression-7.25.9.tgz", + "integrity": "sha512-2qUwwfAFpJLZqxd02YW9btUCZHl+RFvdDkNfZwaIJrvB8Tesjsk8pEQkTvGwZXLqXUx/2oyY3ySRhm6HOXuCug==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5", - "@babel/plugin-transform-optional-chaining": "^7.24.1" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" }, "peerDependencies": { - "@babel/core": "^7.13.0" + "@babel/core": "^7.0.0" } }, - "node_modules/@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly/-/plugin-bugfix-v8-static-class-fields-redefine-readonly-7.24.1.tgz", - "integrity": "sha512-m9m/fXsXLiHfwdgydIFnpk+7jlVbnvlK5B2EKiPdLUb6WX654ZaaEWJUjk8TftRbZpK0XibovlLWX4KIZhV6jw==", + "node_modules/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining/-/plugin-bugfix-v8-spread-parameters-in-optional-chaining-7.25.9.tgz", + "integrity": "sha512-6xWgLZTJXwilVjlnV7ospI3xi+sl8lN8rXXbBD6vYn3UYDlGsag8wrZkKcSI8G6KgqKP7vNFaDgeDnfAABq61g==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9", + "@babel/plugin-transform-optional-chaining": "^7.25.9" }, "engines": { "node": ">=6.9.0" }, "peerDependencies": { - "@babel/core": "^7.0.0" + "@babel/core": "^7.13.0" } }, - "node_modules/@babel/plugin-proposal-async-generator-functions": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.20.7.tgz", - "integrity": "sha512-xMbiLsn/8RK7Wq7VeVytytS2L6qE69bXPB10YCmMdDZbKF4okCqY74pI/jJQ/8U0b/F6NrT2+14b8/P9/3AMGA==", - "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-async-generator-functions instead.", + "node_modules/@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly/-/plugin-bugfix-v8-static-class-fields-redefine-readonly-7.25.9.tgz", + "integrity": "sha512-aLnMXYPnzwwqhYSCyXfKkIkYgJ8zv9RK+roo9DkTXz38ynIhd9XCbN08s3MGvqL2MYGVUGdRQLL/JqBIeJhJBg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.18.9", - "@babel/helper-plugin-utils": "^7.20.2", - "@babel/helper-remap-async-to-generator": "^7.18.9", - "@babel/plugin-syntax-async-generators": "^7.8.4" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/traverse": "^7.25.9" }, "engines": { "node": ">=6.9.0" }, "peerDependencies": { - "@babel/core": "^7.0.0-0" + "@babel/core": "^7.0.0" } }, "node_modules/@babel/plugin-proposal-class-properties": { @@ -711,6 +607,7 @@ "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.18.6.tgz", "integrity": "sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==", "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-create-class-features-plugin": "^7.18.6", @@ -724,13 +621,13 @@ } }, "node_modules/@babel/plugin-proposal-export-default-from": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-export-default-from/-/plugin-proposal-export-default-from-7.24.1.tgz", - "integrity": "sha512-+0hrgGGV3xyYIjOrD/bUZk/iUwOIGuoANfRfVg1cPhYBxF+TIXSEcc42DqzBICmWsnAQ+SfKedY0bj8QD+LuMg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-export-default-from/-/plugin-proposal-export-default-from-7.25.9.tgz", + "integrity": "sha512-ykqgwNfSnNOB+C8fV5X4mG3AVmvu+WVxcaU9xHHtBb7PCrPeweMmPjGsn8eMaeJg6SJuoUuZENeeSWaarWqonQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-export-default-from": "^7.24.1" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -744,6 +641,7 @@ "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.18.6.tgz", "integrity": "sha512-wQxQzxYeJqHcfppzBDnm1yAY0jSRkUXR2z8RePZYrKwMKgMlE8+Z6LUno+bd6LvbGh8Gltvy74+9pIYkr+XkKA==", "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.18.6", @@ -756,65 +654,12 @@ "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/plugin-proposal-numeric-separator": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-numeric-separator/-/plugin-proposal-numeric-separator-7.18.6.tgz", - "integrity": "sha512-ozlZFogPqoLm8WBr5Z8UckIoE4YQ5KESVcNudyXOR8uqIkliTEgJ3RoketfG6pmzLdeZF0H/wjE9/cCEitBl7Q==", - "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-numeric-separator instead.", - "peer": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.18.6", - "@babel/plugin-syntax-numeric-separator": "^7.10.4" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-proposal-object-rest-spread": { - "version": "7.20.7", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-object-rest-spread/-/plugin-proposal-object-rest-spread-7.20.7.tgz", - "integrity": "sha512-d2S98yCiLxDVmBmE8UjGcfPvNEUbA1U5q5WxaWFUGRzJSVAZqm5W6MbPct0jxnegUZ0niLeNX+IOzEs7wYg9Dg==", - "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-object-rest-spread instead.", - "peer": true, - "dependencies": { - "@babel/compat-data": "^7.20.5", - "@babel/helper-compilation-targets": "^7.20.7", - "@babel/helper-plugin-utils": "^7.20.2", - "@babel/plugin-syntax-object-rest-spread": "^7.8.3", - "@babel/plugin-transform-parameters": "^7.20.7" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-proposal-optional-catch-binding": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-catch-binding/-/plugin-proposal-optional-catch-binding-7.18.6.tgz", - "integrity": "sha512-Q40HEhs9DJQyaZfUjjn6vE8Cv4GmMHCYuMGIWUnlxH6400VGxOuwWsPt4FxXxJkC/5eOzgn0z21M9gMT4MOhbw==", - "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-catch-binding instead.", - "peer": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.18.6", - "@babel/plugin-syntax-optional-catch-binding": "^7.8.3" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, "node_modules/@babel/plugin-proposal-optional-chaining": { "version": "7.21.0", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.21.0.tgz", "integrity": "sha512-p4zeefM72gpmEe2fkUr/OnOXpWEf8nAgk7ZYVqqfFiyIG7oFfVZcCrU64hWn5xp4tQ9LkV4bTIa5rD0KANpKNA==", "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.20.2", @@ -832,6 +677,7 @@ "version": "7.21.0-placeholder-for-preset-env.2", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", "integrity": "sha512-SOSkfJDddaM7mak6cPEpswyTRnuRltl429hMraQEglW+OkovnCzsiszTmsrlY//qLFjCpQDFRvjdm2wA5pPm9w==", + "license": "MIT", "peer": true, "engines": { "node": ">=6.9.0" @@ -844,6 +690,20 @@ "version": "7.8.4", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-async-generators/-/plugin-syntax-async-generators-7.8.4.tgz", "integrity": "sha512-tycmZxkGfZaxhMRbXlPXuVFpdWlXpir2W4AMhSJgRKzk/eDlIXOhb2LHWoLpDF7TEHylV5zNhykX6KAgHJmTNw==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.8.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/@babel/plugin-syntax-bigint": { + "version": "7.8.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-bigint/-/plugin-syntax-bigint-7.8.3.tgz", + "integrity": "sha512-wnTnFlG+YxQm3vDxpGE57Pj0srRU4sHE/mDkt1qv2YJJSeUAec2ma4WLUnUPeKjyrfntVwe/N6dCXpU+zL3Npg==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.8.0" @@ -856,6 +716,7 @@ "version": "7.12.13", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-class-properties/-/plugin-syntax-class-properties-7.12.13.tgz", "integrity": "sha512-fm4idjKla0YahUNgFNLCB0qySdsoPiZP3iQE3rky0mBUtMZ23yDJ9SJdg6dXTSDnulOVqiF3Hgr9nbXvXTQZYA==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.12.13" @@ -868,6 +729,7 @@ "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-class-static-block/-/plugin-syntax-class-static-block-7.14.5.tgz", "integrity": "sha512-b+YyPmr6ldyNnM6sqYeMWE+bgJcJpO6yS4QD7ymxgH34GBPNDM/THBh8iunyvKIZztiwLH4CJZ0RxTk9emgpjw==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.14.5" @@ -883,6 +745,7 @@ "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-dynamic-import/-/plugin-syntax-dynamic-import-7.8.3.tgz", "integrity": "sha512-5gdGbFon+PszYzqs83S3E5mpi7/y/8M9eC90MRTZfduQOYW76ig6SOSPNe41IG5LoP3FGBn2N0RjVDSQiS94kQ==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.8.0" @@ -892,12 +755,13 @@ } }, "node_modules/@babel/plugin-syntax-export-default-from": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-export-default-from/-/plugin-syntax-export-default-from-7.24.1.tgz", - "integrity": "sha512-cNXSxv9eTkGUtd0PsNMK8Yx5xeScxfpWOUAxE+ZPAXXEcAMOC3fk7LRdXq5fvpra2pLx2p1YtkAhpUbB2SwaRA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-export-default-from/-/plugin-syntax-export-default-from-7.25.9.tgz", + "integrity": "sha512-9MhJ/SMTsVqsd69GyQg89lYR4o9T+oDGv5F6IsigxxqFVOyR/IflDLYP8WDI1l8fkhNGGktqkvL5qwNCtGEpgQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -906,25 +770,14 @@ "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/plugin-syntax-export-namespace-from": { - "version": "7.8.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-export-namespace-from/-/plugin-syntax-export-namespace-from-7.8.3.tgz", - "integrity": "sha512-MXf5laXo6c1IbEbegDmzGPwGNTsHZmEy6QGznu5Sh2UCWvueywb2ee+CCE4zQiZstxU9BMoQO9i6zUFSY0Kj0Q==", - "peer": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.8.3" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, "node_modules/@babel/plugin-syntax-flow": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.24.1.tgz", - "integrity": "sha512-sxi2kLTI5DeW5vDtMUsk4mTPwvlUDbjOnoWayhynCwrw4QXRld4QEYwqzY8JmQXaJUtgUuCIurtSRH5sn4c7mA==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-flow/-/plugin-syntax-flow-7.26.0.tgz", + "integrity": "sha512-B+O2DnPc0iG+YXFqOxv2WNuNU97ToWjOomUQ78DouOENWUaM5sVrmet9mcomUGQFwpJd//gvUagXBSdzO1fRKg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -934,12 +787,13 @@ } }, "node_modules/@babel/plugin-syntax-import-assertions": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.24.1.tgz", - "integrity": "sha512-IuwnI5XnuF189t91XbxmXeCDz3qs6iDRO7GJ++wcfgeXNs/8FmIlKcpDSXNVyuLQxlwvskmI3Ct73wUODkJBlQ==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-assertions/-/plugin-syntax-import-assertions-7.26.0.tgz", + "integrity": "sha512-QCWT5Hh830hK5EQa7XzuqIkQU9tT/whqbDz7kuaZMHFl1inRRg7JnuAEOQ0Ur0QUl0NufCk1msK2BeY79Aj/eg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -949,12 +803,13 @@ } }, "node_modules/@babel/plugin-syntax-import-attributes": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.24.1.tgz", - "integrity": "sha512-zhQTMH0X2nVLnb04tz+s7AMuasX8U0FnpE+nHTOhSOINjWMnopoZTxtIKsd45n4GQ/HIZLyfIpoul8e2m0DnRA==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-attributes/-/plugin-syntax-import-attributes-7.26.0.tgz", + "integrity": "sha512-e2dttdsJ1ZTpi3B9UYGLw41hifAubg19AtCu/2I/F1QNVclOBr1dYpTdmdyZ84Xiz43BS/tCUkMAZNLv12Pi+A==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -967,6 +822,7 @@ "version": "7.10.4", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-import-meta/-/plugin-syntax-import-meta-7.10.4.tgz", "integrity": "sha512-Yqfm+XDx0+Prh3VSeEQCPU81yC+JWZ2pDPFSS4ZdpfZhp4MkFMaDC1UqseovEKwSUpnIL7+vK+Clp7bfh0iD7g==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.10.4" @@ -979,6 +835,7 @@ "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-json-strings/-/plugin-syntax-json-strings-7.8.3.tgz", "integrity": "sha512-lY6kdGpWHvjoe2vk4WrAapEuBR69EMxZl+RoGRhrFGNYVK8mOPAW8VfbT/ZgrFbXlDNiiaxQnAtgVCZ6jv30EA==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.8.0" @@ -988,12 +845,13 @@ } }, "node_modules/@babel/plugin-syntax-jsx": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.24.1.tgz", - "integrity": "sha512-2eCtxZXf+kbkMIsXS4poTvT4Yu5rXiRa+9xGVT56raghjmBTKMpFNc9R4IDiB4emao9eO22Ox7CxuJG7BgExqA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.25.9.tgz", + "integrity": "sha512-ld6oezHQMZsZfp6pWtbjaNDF2tiiCYYDqQszHt5VV437lewP9aSi2Of99CK0D0XB21k7FLgnLcmQKyKzynfeAA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1006,6 +864,7 @@ "version": "7.10.4", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz", "integrity": "sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.10.4" @@ -1018,6 +877,7 @@ "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-nullish-coalescing-operator/-/plugin-syntax-nullish-coalescing-operator-7.8.3.tgz", "integrity": "sha512-aSff4zPII1u2QD7y+F8oDsz19ew4IGEJg9SVW+bqwpwtfFleiQDMdzA/R+UlWDzfnHFCxxleFT0PMIrR36XLNQ==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.8.0" @@ -1030,6 +890,7 @@ "version": "7.10.4", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-numeric-separator/-/plugin-syntax-numeric-separator-7.10.4.tgz", "integrity": "sha512-9H6YdfkcK/uOnY/K7/aA2xpzaAgkQn37yzWUMRK7OaPOqOpGS1+n0H5hxT9AUw9EsSjPW8SVyMJwYRtWs3X3ug==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.10.4" @@ -1042,6 +903,7 @@ "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-object-rest-spread/-/plugin-syntax-object-rest-spread-7.8.3.tgz", "integrity": "sha512-XoqMijGZb9y3y2XskN+P1wUGiVwWZ5JmoDRwx5+3GmEplNyVM2s2Dg8ILFQm8rWM48orGy5YpI5Bl8U1y7ydlA==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.8.0" @@ -1054,6 +916,7 @@ "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-catch-binding/-/plugin-syntax-optional-catch-binding-7.8.3.tgz", "integrity": "sha512-6VPD0Pc1lpTqw0aKoeRTMiB+kWhAoT24PA+ksWSBrFtl5SIRVpZlwN3NNPQjehA2E/91FV3RjLWoVTglWcSV3Q==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.8.0" @@ -1066,6 +929,7 @@ "version": "7.8.3", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-optional-chaining/-/plugin-syntax-optional-chaining-7.8.3.tgz", "integrity": "sha512-KoK9ErH1MBlCPxV0VANkXW2/dw4vlbGDrFgz8bmUsBGYkFRcbRwMh6cIJubdPrkxRwuGdtCk0v/wPTKbQgBjkg==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.8.0" @@ -1078,6 +942,7 @@ "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-private-property-in-object/-/plugin-syntax-private-property-in-object-7.14.5.tgz", "integrity": "sha512-0wVnp9dxJ72ZUJDV27ZfbSj6iHLoytYZmh3rFcxNnvsJF3ktkzLDZPy/mA17HGsaQT3/DQsWYX1f1QGWkCoVUg==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.14.5" @@ -1093,6 +958,7 @@ "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-top-level-await/-/plugin-syntax-top-level-await-7.14.5.tgz", "integrity": "sha512-hx++upLv5U1rgYfwe1xBQUhRmU41NEvpUvrp8jkrSCdvGSnM5/qdRMtylJ6PG5OFkBaHkbTAKTnd3/YyESRHFw==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.14.5" @@ -1105,12 +971,13 @@ } }, "node_modules/@babel/plugin-syntax-typescript": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.24.1.tgz", - "integrity": "sha512-Yhnmvy5HZEnHUty6i++gcfH1/l68AHnItFHnaCv6hn9dNh0hQvvQJsxpi4BMBFN5DLeHBuucT/0DgzXif/OyRw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-typescript/-/plugin-syntax-typescript-7.25.9.tgz", + "integrity": "sha512-hjMgRy5hb8uJJjUcdWunWVcoi9bGpJp8p5Ol1229PoN6aytsLwNMgmdftO23wnCLMfVmTwZDWMPNq/D1SY60JQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1123,6 +990,7 @@ "version": "7.18.6", "resolved": "https://registry.npmjs.org/@babel/plugin-syntax-unicode-sets-regex/-/plugin-syntax-unicode-sets-regex-7.18.6.tgz", "integrity": "sha512-727YkEAPwSIQTv5im8QHz3upqp92JTWhidIC81Tdx4VJYIte/VndKf1qKrfnnhPLiPghStWfvC/iFaMCQu7Nqg==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-create-regexp-features-plugin": "^7.18.6", @@ -1136,12 +1004,13 @@ } }, "node_modules/@babel/plugin-transform-arrow-functions": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.24.1.tgz", - "integrity": "sha512-ngT/3NkRhsaep9ck9uj2Xhv9+xB1zShY3tM3g6om4xxCELwCDN4g4Aq5dRn48+0hasAql7s2hdBOysCfNpr4fw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-arrow-functions/-/plugin-transform-arrow-functions-7.25.9.tgz", + "integrity": "sha512-6jmooXYIwn9ca5/RylZADJ+EnSxVUS5sjeJ9UPk6RWRzXCmOJCy6dqItPJFpw2cuCangPK4OYr5uhGKcmrm5Qg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1151,15 +1020,15 @@ } }, "node_modules/@babel/plugin-transform-async-generator-functions": { - "version": "7.24.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-generator-functions/-/plugin-transform-async-generator-functions-7.24.3.tgz", - "integrity": "sha512-Qe26CMYVjpQxJ8zxM1340JFNjZaF+ISWpr1Kt/jGo+ZTUzKkfw/pphEWbRCb+lmSM6k/TOgfYLvmbHkUQ0asIg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-generator-functions/-/plugin-transform-async-generator-functions-7.25.9.tgz", + "integrity": "sha512-RXV6QAzTBbhDMO9fWwOmwwTuYaiPbggWQ9INdZqAYeSHyG7FzQ+nOZaUUjNwKv9pV3aE4WFqFm1Hnbci5tBCAw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-remap-async-to-generator": "^7.22.20", - "@babel/plugin-syntax-async-generators": "^7.8.4" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-remap-async-to-generator": "^7.25.9", + "@babel/traverse": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1169,14 +1038,15 @@ } }, "node_modules/@babel/plugin-transform-async-to-generator": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.24.1.tgz", - "integrity": "sha512-AawPptitRXp1y0n4ilKcGbRYWfbbzFWz2NqNu7dacYDtFtz0CMjG64b3LQsb3KIgnf4/obcUL78hfaOS7iCUfw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-to-generator/-/plugin-transform-async-to-generator-7.25.9.tgz", + "integrity": "sha512-NT7Ejn7Z/LjUH0Gv5KsBCxh7BH3fbLTV0ptHvpeMvrt3cPThHfJfst9Wrb7S8EvJ7vRTFI7z+VAvFVEQn/m5zQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-module-imports": "^7.24.1", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-remap-async-to-generator": "^7.22.20" + "@babel/helper-module-imports": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-remap-async-to-generator": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1186,12 +1056,13 @@ } }, "node_modules/@babel/plugin-transform-block-scoped-functions": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.24.1.tgz", - "integrity": "sha512-TWWC18OShZutrv9C6mye1xwtam+uNi2bnTOCBUd5sZxyHOiWbU6ztSROofIMrK84uweEZC219POICK/sTYwfgg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.25.9.tgz", + "integrity": "sha512-toHc9fzab0ZfenFpsyYinOX0J/5dgJVA2fm64xPewu7CoYHWEivIWKxkK2rMi4r3yQqLnVmheMXRdG+k239CgA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1201,12 +1072,13 @@ } }, "node_modules/@babel/plugin-transform-block-scoping": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.24.4.tgz", - "integrity": "sha512-nIFUZIpGKDf9O9ttyRXpHFpKC+X3Y5mtshZONuEUYBomAKoM4y029Jr+uB1bHGPhNmK8YXHevDtKDOLmtRrp6g==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.25.9.tgz", + "integrity": "sha512-1F05O7AYjymAtqbsFETboN1NvBdcnzMerO+zlMyJBEz6WkMdejvGWw9p05iTSjC85RLlBseHHQpYaM4gzJkBGg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1216,13 +1088,14 @@ } }, "node_modules/@babel/plugin-transform-class-properties": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-class-properties/-/plugin-transform-class-properties-7.24.1.tgz", - "integrity": "sha512-OMLCXi0NqvJfORTaPQBwqLXHhb93wkBKZ4aNwMl6WtehO7ar+cmp+89iPEQPqxAnxsOKTaMcs3POz3rKayJ72g==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-class-properties/-/plugin-transform-class-properties-7.25.9.tgz", + "integrity": "sha512-bbMAII8GRSkcd0h0b4X+36GksxuheLFjP65ul9w6C3KgAamI3JqErNgSrosX6ZPj+Mpim5VvEbawXxJCyEUV3Q==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-create-class-features-plugin": "^7.24.1", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-create-class-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1232,14 +1105,14 @@ } }, "node_modules/@babel/plugin-transform-class-static-block": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-class-static-block/-/plugin-transform-class-static-block-7.24.4.tgz", - "integrity": "sha512-B8q7Pz870Hz/q9UgP8InNpY01CSLDSCyqX7zcRuv3FcPl87A2G17lASroHWaCtbdIcbYzOZ7kWmXFKbijMSmFg==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-class-static-block/-/plugin-transform-class-static-block-7.26.0.tgz", + "integrity": "sha512-6J2APTs7BDDm+UMqP1useWqhcRAXo0WIoVj26N7kPFB6S73Lgvyka4KTZYIxtgYXiN5HTyRObA72N2iu628iTQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-create-class-features-plugin": "^7.24.4", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-class-static-block": "^7.14.5" + "@babel/helper-create-class-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1249,18 +1122,17 @@ } }, "node_modules/@babel/plugin-transform-classes": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-classes/-/plugin-transform-classes-7.24.1.tgz", - "integrity": "sha512-ZTIe3W7UejJd3/3R4p7ScyyOoafetUShSf4kCqV0O7F/RiHxVj/wRaRnQlrGwflvcehNA8M42HkAiEDYZu2F1Q==", - "peer": true, - "dependencies": { - "@babel/helper-annotate-as-pure": "^7.22.5", - "@babel/helper-compilation-targets": "^7.23.6", - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-function-name": "^7.23.0", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-replace-supers": "^7.24.1", - "@babel/helper-split-export-declaration": "^7.22.6", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-classes/-/plugin-transform-classes-7.25.9.tgz", + "integrity": "sha512-mD8APIXmseE7oZvZgGABDyM34GUmK45Um2TXiBUt7PnuAxrgoSVf123qUzPxEr/+/BHrRn5NMZCdE2m/1F8DGg==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/helper-annotate-as-pure": "^7.25.9", + "@babel/helper-compilation-targets": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-replace-supers": "^7.25.9", + "@babel/traverse": "^7.25.9", "globals": "^11.1.0" }, "engines": { @@ -1274,19 +1146,21 @@ "version": "11.12.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "license": "MIT", "peer": true, "engines": { "node": ">=4" } }, "node_modules/@babel/plugin-transform-computed-properties": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.24.1.tgz", - "integrity": "sha512-5pJGVIUfJpOS+pAqBQd+QMaTD2vCL/HcePooON6pDpHgRp4gNRmzyHTPIkXntwKsq3ayUFVfJaIKPw2pOkOcTw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-computed-properties/-/plugin-transform-computed-properties-7.25.9.tgz", + "integrity": "sha512-HnBegGqXZR12xbcTHlJ9HGxw1OniltT26J5YpfruGqtUHlz/xKf/G2ak9e+t0rVqrjXa9WOhvYPz1ERfMj23AA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/template": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/template": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1296,12 +1170,13 @@ } }, "node_modules/@babel/plugin-transform-destructuring": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.24.1.tgz", - "integrity": "sha512-ow8jciWqNxR3RYbSNVuF4U2Jx130nwnBnhRw6N6h1bOejNkABmcI5X5oz29K4alWX7vf1C+o6gtKXikzRKkVdw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-destructuring/-/plugin-transform-destructuring-7.25.9.tgz", + "integrity": "sha512-WkCGb/3ZxXepmMiX101nnGiU+1CAdut8oHyEOHxkKuS1qKpU2SMXE2uSvfz8PBuLd49V6LEsbtyPhWC7fnkgvQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1311,13 +1186,14 @@ } }, "node_modules/@babel/plugin-transform-dotall-regex": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.24.1.tgz", - "integrity": "sha512-p7uUxgSoZwZ2lPNMzUkqCts3xlp8n+o05ikjy7gbtFJSt9gdU88jAmtfmOxHM14noQXBxfgzf2yRWECiNVhTCw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-dotall-regex/-/plugin-transform-dotall-regex-7.25.9.tgz", + "integrity": "sha512-t7ZQ7g5trIgSRYhI9pIJtRl64KHotutUJsh4Eze5l7olJv+mRSg4/MmbZ0tv1eeqRbdvo/+trvJD/Oc5DmW2cA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-create-regexp-features-plugin": "^7.22.15", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-create-regexp-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1327,12 +1203,13 @@ } }, "node_modules/@babel/plugin-transform-duplicate-keys": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.24.1.tgz", - "integrity": "sha512-msyzuUnvsjsaSaocV6L7ErfNsa5nDWL1XKNnDePLgmz+WdU4w/J8+AxBMrWfi9m4IxfL5sZQKUPQKDQeeAT6lA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-duplicate-keys/-/plugin-transform-duplicate-keys-7.25.9.tgz", + "integrity": "sha512-LZxhJ6dvBb/f3x8xwWIuyiAHy56nrRG3PeYTpBkkzkYRRQ6tJLu68lEF5VIqMUZiAV7a8+Tb78nEoMCMcqjXBw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1341,14 +1218,31 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-duplicate-named-capturing-groups-regex": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-duplicate-named-capturing-groups-regex/-/plugin-transform-duplicate-named-capturing-groups-regex-7.25.9.tgz", + "integrity": "sha512-0UfuJS0EsXbRvKnwcLjFtJy/Sxc5J5jhLHnFhy7u4zih97Hz6tJkLU+O+FMMrNZrosUPxDi6sYxJ/EA8jDiAog==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/helper-create-regexp-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } + }, "node_modules/@babel/plugin-transform-dynamic-import": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-dynamic-import/-/plugin-transform-dynamic-import-7.24.1.tgz", - "integrity": "sha512-av2gdSTyXcJVdI+8aFZsCAtR29xJt0S5tas+Ef8NvBNmD1a+N/3ecMLeMBgfcK+xzsjdLDT6oHt+DFPyeqUbDA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-dynamic-import/-/plugin-transform-dynamic-import-7.25.9.tgz", + "integrity": "sha512-GCggjexbmSLaFhqsojeugBpeaRIgWNTcgKVq/0qIteFEqY2A+b9QidYadrWlnbWQUrW5fn+mCvf3tr7OeBFTyg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-dynamic-import": "^7.8.3" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1358,13 +1252,14 @@ } }, "node_modules/@babel/plugin-transform-exponentiation-operator": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.24.1.tgz", - "integrity": "sha512-U1yX13dVBSwS23DEAqU+Z/PkwE9/m7QQy8Y9/+Tdb8UWYaGNDYwTLi19wqIAiROr8sXVum9A/rtiH5H0boUcTw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.25.9.tgz", + "integrity": "sha512-KRhdhlVk2nObA5AYa7QMgTMTVJdfHprfpAk4DjZVtllqRg9qarilstTKEhpVjyt+Npi8ThRyiV8176Am3CodPA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-builder-binary-assignment-operator-visitor": "^7.22.15", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-builder-binary-assignment-operator-visitor": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1374,13 +1269,13 @@ } }, "node_modules/@babel/plugin-transform-export-namespace-from": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-export-namespace-from/-/plugin-transform-export-namespace-from-7.24.1.tgz", - "integrity": "sha512-Ft38m/KFOyzKw2UaJFkWG9QnHPG/Q/2SkOrRk4pNBPg5IPZ+dOxcmkK5IyuBcxiNPyyYowPGUReyBvrvZs7IlQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-export-namespace-from/-/plugin-transform-export-namespace-from-7.25.9.tgz", + "integrity": "sha512-2NsEz+CxzJIVOPx2o9UsW1rXLqtChtLoVnwYHHiB04wS5sgn7mrV45fWMBX0Kk+ub9uXytVYfNP2HjbVbCB3Ww==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-export-namespace-from": "^7.8.3" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1390,13 +1285,14 @@ } }, "node_modules/@babel/plugin-transform-flow-strip-types": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.24.1.tgz", - "integrity": "sha512-iIYPIWt3dUmUKKE10s3W+jsQ3icFkw0JyRVyY1B7G4yK/nngAOHLVx8xlhA6b/Jzl/Y0nis8gjqhqKtRDQqHWQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.25.9.tgz", + "integrity": "sha512-/VVukELzPDdci7UUsWQaSkhgnjIWXnIyRpM02ldxaVoFK96c41So8JcKT3m0gYjyv7j5FNPGS5vfELrWalkbDA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-flow": "^7.24.1" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/plugin-syntax-flow": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1406,13 +1302,14 @@ } }, "node_modules/@babel/plugin-transform-for-of": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.24.1.tgz", - "integrity": "sha512-OxBdcnF04bpdQdR3i4giHZNZQn7cm8RQKcSwA17wAAqEELo1ZOwp5FFgeptWUQXFyT9kwHo10aqqauYkRZPCAg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.25.9.tgz", + "integrity": "sha512-LqHxduHoaGELJl2uhImHwRQudhCM50pT46rIBNvtT/Oql3nqiS3wOwP+5ten7NpYSXrrVLgtZU3DZmPtWZo16A==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1422,14 +1319,15 @@ } }, "node_modules/@babel/plugin-transform-function-name": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-function-name/-/plugin-transform-function-name-7.24.1.tgz", - "integrity": "sha512-BXmDZpPlh7jwicKArQASrj8n22/w6iymRnvHYYd2zO30DbE277JO20/7yXJT3QxDPtiQiOxQBbZH4TpivNXIxA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-function-name/-/plugin-transform-function-name-7.25.9.tgz", + "integrity": "sha512-8lP+Yxjv14Vc5MuWBpJsoUCd3hD6V9DgBon2FVYL4jJgbnVQ9fTgYmonchzZJOVNgzEgbxp4OwAf6xz6M/14XA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-compilation-targets": "^7.23.6", - "@babel/helper-function-name": "^7.23.0", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-compilation-targets": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/traverse": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1439,13 +1337,13 @@ } }, "node_modules/@babel/plugin-transform-json-strings": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-json-strings/-/plugin-transform-json-strings-7.24.1.tgz", - "integrity": "sha512-U7RMFmRvoasscrIFy5xA4gIp8iWnWubnKkKuUGJjsuOH7GfbMkB+XZzeslx2kLdEGdOJDamEmCqOks6e8nv8DQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-json-strings/-/plugin-transform-json-strings-7.25.9.tgz", + "integrity": "sha512-xoTMk0WXceiiIvsaquQQUaLLXSW1KJ159KP87VilruQm0LNNGxWzahxSS6T6i4Zg3ezp4vA4zuwiNUR53qmQAw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-json-strings": "^7.8.3" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1455,12 +1353,13 @@ } }, "node_modules/@babel/plugin-transform-literals": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-literals/-/plugin-transform-literals-7.24.1.tgz", - "integrity": "sha512-zn9pwz8U7nCqOYIiBaOxoQOtYmMODXTJnkxG4AtX8fPmnCRYWBOHD0qcpwS9e2VDSp1zNJYpdnFMIKb8jmwu6g==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-literals/-/plugin-transform-literals-7.25.9.tgz", + "integrity": "sha512-9N7+2lFziW8W9pBl2TzaNht3+pgMIRP74zizeCSrtnSKVdUl8mAjjOP2OOVQAfZ881P2cNjDj1uAMEdeD50nuQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1470,13 +1369,13 @@ } }, "node_modules/@babel/plugin-transform-logical-assignment-operators": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-logical-assignment-operators/-/plugin-transform-logical-assignment-operators-7.24.1.tgz", - "integrity": "sha512-OhN6J4Bpz+hIBqItTeWJujDOfNP+unqv/NJgyhlpSqgBTPm37KkMmZV6SYcOj+pnDbdcl1qRGV/ZiIjX9Iy34w==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-logical-assignment-operators/-/plugin-transform-logical-assignment-operators-7.25.9.tgz", + "integrity": "sha512-wI4wRAzGko551Y8eVf6iOY9EouIDTtPb0ByZx+ktDGHwv6bHFimrgJM/2T021txPZ2s4c7bqvHbd+vXG6K948Q==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-logical-assignment-operators": "^7.10.4" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1486,12 +1385,13 @@ } }, "node_modules/@babel/plugin-transform-member-expression-literals": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-member-expression-literals/-/plugin-transform-member-expression-literals-7.24.1.tgz", - "integrity": "sha512-4ojai0KysTWXzHseJKa1XPNXKRbuUrhkOPY4rEGeR+7ChlJVKxFa3H3Bz+7tWaGKgJAXUWKOGmltN+u9B3+CVg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-member-expression-literals/-/plugin-transform-member-expression-literals-7.25.9.tgz", + "integrity": "sha512-PYazBVfofCQkkMzh2P6IdIUaCEWni3iYEerAsRWuVd8+jlM1S9S9cz1dF9hIzyoZ8IA3+OwVYIp9v9e+GbgZhA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1501,13 +1401,14 @@ } }, "node_modules/@babel/plugin-transform-modules-amd": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.24.1.tgz", - "integrity": "sha512-lAxNHi4HVtjnHd5Rxg3D5t99Xm6H7b04hUS7EHIXcUl2EV4yl1gWdqZrNzXnSrHveL9qMdbODlLF55mvgjAfaQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-amd/-/plugin-transform-modules-amd-7.25.9.tgz", + "integrity": "sha512-g5T11tnI36jVClQlMlt4qKDLlWnG5pP9CSM4GhdRciTNMRgkfpo5cR6b4rGIOYPgRRuFAvwjPQ/Yk+ql4dyhbw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-module-transforms": "^7.23.3", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-module-transforms": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1517,14 +1418,15 @@ } }, "node_modules/@babel/plugin-transform-modules-commonjs": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.24.1.tgz", - "integrity": "sha512-szog8fFTUxBfw0b98gEWPaEqF42ZUD/T3bkynW/wtgx2p/XCP55WEsb+VosKceRSd6njipdZvNogqdtI4Q0chw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.25.9.tgz", + "integrity": "sha512-dwh2Ol1jWwL2MgkCzUSOvfmKElqQcuswAZypBSUsScMXvgdT8Ekq5YA6TtqpTVWH+4903NmboMuH1o9i8Rxlyg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-module-transforms": "^7.23.3", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-simple-access": "^7.22.5" + "@babel/helper-module-transforms": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-simple-access": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1534,15 +1436,16 @@ } }, "node_modules/@babel/plugin-transform-modules-systemjs": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.24.1.tgz", - "integrity": "sha512-mqQ3Zh9vFO1Tpmlt8QPnbwGHzNz3lpNEMxQb1kAemn/erstyqw1r9KeOlOfo3y6xAnFEcOv2tSyrXfmMk+/YZA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-systemjs/-/plugin-transform-modules-systemjs-7.25.9.tgz", + "integrity": "sha512-hyss7iIlH/zLHaehT+xwiymtPOpsiwIIRlCAOwBB04ta5Tt+lNItADdlXw3jAWZ96VJ2jlhl/c+PNIQPKNfvcA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-hoist-variables": "^7.22.5", - "@babel/helper-module-transforms": "^7.23.3", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-validator-identifier": "^7.22.20" + "@babel/helper-module-transforms": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-validator-identifier": "^7.25.9", + "@babel/traverse": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1552,13 +1455,14 @@ } }, "node_modules/@babel/plugin-transform-modules-umd": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-umd/-/plugin-transform-modules-umd-7.24.1.tgz", - "integrity": "sha512-tuA3lpPj+5ITfcCluy6nWonSL7RvaG0AOTeAuvXqEKS34lnLzXpDb0dcP6K8jD0zWZFNDVly90AGFJPnm4fOYg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-umd/-/plugin-transform-modules-umd-7.25.9.tgz", + "integrity": "sha512-bS9MVObUgE7ww36HEfwe6g9WakQ0KF07mQF74uuXdkoziUPfKyu/nIm663kz//e5O1nPInPFx36z7WJmJ4yNEw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-module-transforms": "^7.23.3", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-module-transforms": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1568,13 +1472,14 @@ } }, "node_modules/@babel/plugin-transform-named-capturing-groups-regex": { - "version": "7.22.5", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.22.5.tgz", - "integrity": "sha512-YgLLKmS3aUBhHaxp5hi1WJTgOUb/NCuDHzGT9z9WTt3YG+CPRhJs6nprbStx6DnWM4dh6gt7SU3sZodbZ08adQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-named-capturing-groups-regex/-/plugin-transform-named-capturing-groups-regex-7.25.9.tgz", + "integrity": "sha512-oqB6WHdKTGl3q/ItQhpLSnWWOpjUJLsOCLVyeFgeTktkBSCiurvPOsyt93gibI9CmuKvTUEtWmG5VhZD+5T/KA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-create-regexp-features-plugin": "^7.22.5", - "@babel/helper-plugin-utils": "^7.22.5" + "@babel/helper-create-regexp-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1584,12 +1489,13 @@ } }, "node_modules/@babel/plugin-transform-new-target": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-new-target/-/plugin-transform-new-target-7.24.1.tgz", - "integrity": "sha512-/rurytBM34hYy0HKZQyA0nHbQgQNFm4Q/BOc9Hflxi2X3twRof7NaE5W46j4kQitm7SvACVRXsa6N/tSZxvPug==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-new-target/-/plugin-transform-new-target-7.25.9.tgz", + "integrity": "sha512-U/3p8X1yCSoKyUj2eOBIx3FOn6pElFOKvAAGf8HTtItuPyB+ZeOqfn+mvTtg9ZlOAjsPdK3ayQEjqHjU/yLeVQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1599,13 +1505,13 @@ } }, "node_modules/@babel/plugin-transform-nullish-coalescing-operator": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.24.1.tgz", - "integrity": "sha512-iQ+caew8wRrhCikO5DrUYx0mrmdhkaELgFa+7baMcVuhxIkN7oxt06CZ51D65ugIb1UWRQ8oQe+HXAVM6qHFjw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.25.9.tgz", + "integrity": "sha512-ENfftpLZw5EItALAD4WsY/KUWvhUlZndm5GC7G3evUsVeSJB6p0pBeLQUnRnBCBx7zV0RKQjR9kCuwrsIrjWog==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1615,13 +1521,13 @@ } }, "node_modules/@babel/plugin-transform-numeric-separator": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-numeric-separator/-/plugin-transform-numeric-separator-7.24.1.tgz", - "integrity": "sha512-7GAsGlK4cNL2OExJH1DzmDeKnRv/LXq0eLUSvudrehVA5Rgg4bIrqEUW29FbKMBRT0ztSqisv7kjP+XIC4ZMNw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-numeric-separator/-/plugin-transform-numeric-separator-7.25.9.tgz", + "integrity": "sha512-TlprrJ1GBZ3r6s96Yq8gEQv82s8/5HnCVHtEJScUj90thHQbwe+E5MLhi2bbNHBEJuzrvltXSru+BUxHDoog7Q==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-numeric-separator": "^7.10.4" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1631,15 +1537,15 @@ } }, "node_modules/@babel/plugin-transform-object-rest-spread": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-rest-spread/-/plugin-transform-object-rest-spread-7.24.1.tgz", - "integrity": "sha512-XjD5f0YqOtebto4HGISLNfiNMTTs6tbkFf2TOqJlYKYmbo+mN9Dnpl4SRoofiziuOWMIyq3sZEUqLo3hLITFEA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-rest-spread/-/plugin-transform-object-rest-spread-7.25.9.tgz", + "integrity": "sha512-fSaXafEE9CVHPweLYw4J0emp1t8zYTXyzN3UuG+lylqkvYd7RMrsOQ8TYx5RF231be0vqtFC6jnx3UmpJmKBYg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-compilation-targets": "^7.23.6", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-object-rest-spread": "^7.8.3", - "@babel/plugin-transform-parameters": "^7.24.1" + "@babel/helper-compilation-targets": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/plugin-transform-parameters": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1649,13 +1555,14 @@ } }, "node_modules/@babel/plugin-transform-object-super": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.24.1.tgz", - "integrity": "sha512-oKJqR3TeI5hSLRxudMjFQ9re9fBVUU0GICqM3J1mi8MqlhVr6hC/ZN4ttAyMuQR6EZZIY6h/exe5swqGNNIkWQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-object-super/-/plugin-transform-object-super-7.25.9.tgz", + "integrity": "sha512-Kj/Gh+Rw2RNLbCK1VAWj2U48yxxqL2x0k10nPtSdRa0O2xnHXalD0s+o1A6a0W43gJ00ANo38jxkQreckOzv5A==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-replace-supers": "^7.24.1" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-replace-supers": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1665,13 +1572,13 @@ } }, "node_modules/@babel/plugin-transform-optional-catch-binding": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-optional-catch-binding/-/plugin-transform-optional-catch-binding-7.24.1.tgz", - "integrity": "sha512-oBTH7oURV4Y+3EUrf6cWn1OHio3qG/PVwO5J03iSJmBg6m2EhKjkAu/xuaXaYwWW9miYtvbWv4LNf0AmR43LUA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-optional-catch-binding/-/plugin-transform-optional-catch-binding-7.25.9.tgz", + "integrity": "sha512-qM/6m6hQZzDcZF3onzIhZeDHDO43bkNNlOX0i8n3lR6zLbu0GN2d8qfM/IERJZYauhAHSLHy39NF0Ctdvcid7g==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-optional-catch-binding": "^7.8.3" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1681,14 +1588,14 @@ } }, "node_modules/@babel/plugin-transform-optional-chaining": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-optional-chaining/-/plugin-transform-optional-chaining-7.24.1.tgz", - "integrity": "sha512-n03wmDt+987qXwAgcBlnUUivrZBPZ8z1plL0YvgQalLm+ZE5BMhGm94jhxXtA1wzv1Cu2aaOv1BM9vbVttrzSg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-optional-chaining/-/plugin-transform-optional-chaining-7.25.9.tgz", + "integrity": "sha512-6AvV0FsLULbpnXeBjrY4dmWF8F7gf8QnvTEoO/wX/5xm/xE1Xo8oPuD3MPS+KS9f9XBEAWN7X1aWr4z9HdOr7A==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5", - "@babel/plugin-syntax-optional-chaining": "^7.8.3" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1698,12 +1605,13 @@ } }, "node_modules/@babel/plugin-transform-parameters": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.24.1.tgz", - "integrity": "sha512-8Jl6V24g+Uw5OGPeWNKrKqXPDw2YDjLc53ojwfMcKwlEoETKU9rU0mHUtcg9JntWI/QYzGAXNWEcVHZ+fR+XXg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-parameters/-/plugin-transform-parameters-7.25.9.tgz", + "integrity": "sha512-wzz6MKwpnshBAiRmn4jR8LYz/g8Ksg0o80XmwZDlordjwEk9SxBzTWC7F5ef1jhbrbOW2DJ5J6ayRukrJmnr0g==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1713,13 +1621,14 @@ } }, "node_modules/@babel/plugin-transform-private-methods": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-private-methods/-/plugin-transform-private-methods-7.24.1.tgz", - "integrity": "sha512-tGvisebwBO5em4PaYNqt4fkw56K2VALsAbAakY0FjTYqJp7gfdrgr7YX76Or8/cpik0W6+tj3rZ0uHU9Oil4tw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-private-methods/-/plugin-transform-private-methods-7.25.9.tgz", + "integrity": "sha512-D/JUozNpQLAPUVusvqMxyvjzllRaF8/nSrP1s2YGQT/W4LHK4xxsMcHjhOGTS01mp9Hda8nswb+FblLdJornQw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-create-class-features-plugin": "^7.24.1", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-create-class-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1729,15 +1638,15 @@ } }, "node_modules/@babel/plugin-transform-private-property-in-object": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-private-property-in-object/-/plugin-transform-private-property-in-object-7.24.1.tgz", - "integrity": "sha512-pTHxDVa0BpUbvAgX3Gat+7cSciXqUcY9j2VZKTbSB6+VQGpNgNO9ailxTGHSXlqOnX1Hcx1Enme2+yv7VqP9bg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-private-property-in-object/-/plugin-transform-private-property-in-object-7.25.9.tgz", + "integrity": "sha512-Evf3kcMqzXA3xfYJmZ9Pg1OvKdtqsDMSWBDzZOPLvHiTt36E75jLDQo5w1gtRU95Q4E5PDttrTf25Fw8d/uWLw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-annotate-as-pure": "^7.22.5", - "@babel/helper-create-class-features-plugin": "^7.24.1", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-private-property-in-object": "^7.14.5" + "@babel/helper-annotate-as-pure": "^7.25.9", + "@babel/helper-create-class-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1747,12 +1656,13 @@ } }, "node_modules/@babel/plugin-transform-property-literals": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-property-literals/-/plugin-transform-property-literals-7.24.1.tgz", - "integrity": "sha512-LetvD7CrHmEx0G442gOomRr66d7q8HzzGGr4PMHGr+5YIm6++Yke+jxj246rpvsbyhJwCLxcTn6zW1P1BSenqA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-property-literals/-/plugin-transform-property-literals-7.25.9.tgz", + "integrity": "sha512-IvIUeV5KrS/VPavfSM/Iu+RE6llrHrYIKY1yfCzyO/lMXHQ+p7uGhonmGVisv6tSBSVgWzMBohTcvkC9vQcQFA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1762,12 +1672,13 @@ } }, "node_modules/@babel/plugin-transform-react-display-name": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.24.1.tgz", - "integrity": "sha512-mvoQg2f9p2qlpDQRBC7M3c3XTr0k7cp/0+kFKKO/7Gtu0LSw16eKB+Fabe2bDT/UpsyasTBBkAnbdsLrkD5XMw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.25.9.tgz", + "integrity": "sha512-KJfMlYIUxQB1CJfO3e0+h0ZHWOTLCPP115Awhaz8U0Zpq36Gl/cXlpoyMRnUWlhNUBAzldnCiAZNvCDj7CrKxQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1777,16 +1688,17 @@ } }, "node_modules/@babel/plugin-transform-react-jsx": { - "version": "7.23.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.23.4.tgz", - "integrity": "sha512-5xOpoPguCZCRbo/JeHlloSkTA8Bld1J/E1/kLfD1nsuiW1m8tduTA1ERCgIZokDflX/IBzKcqR3l7VlRgiIfHA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.25.9.tgz", + "integrity": "sha512-s5XwpQYCqGerXl+Pu6VDL3x0j2d82eiV77UJ8a2mDHAW7j9SWRqQ2y1fNo1Z74CdcYipl5Z41zvjj4Nfzq36rw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-annotate-as-pure": "^7.22.5", - "@babel/helper-module-imports": "^7.22.15", - "@babel/helper-plugin-utils": "^7.22.5", - "@babel/plugin-syntax-jsx": "^7.23.3", - "@babel/types": "^7.23.4" + "@babel/helper-annotate-as-pure": "^7.25.9", + "@babel/helper-module-imports": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/plugin-syntax-jsx": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1796,12 +1708,13 @@ } }, "node_modules/@babel/plugin-transform-react-jsx-self": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.24.1.tgz", - "integrity": "sha512-kDJgnPujTmAZ/9q2CN4m2/lRsUUPDvsG3+tSHWUJIzMGTt5U/b/fwWd3RO3n+5mjLrsBrVa5eKFRVSQbi3dF1w==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.25.9.tgz", + "integrity": "sha512-y8quW6p0WHkEhmErnfe58r7x0A70uKphQm8Sp8cV7tjNQwK56sNVK0M73LK3WuYmsuyrftut4xAkjjgU0twaMg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1811,12 +1724,13 @@ } }, "node_modules/@babel/plugin-transform-react-jsx-source": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.24.1.tgz", - "integrity": "sha512-1v202n7aUq4uXAieRTKcwPzNyphlCuqHHDcdSNc+vdhoTEZcFMh+L5yZuCmGaIO7bs1nJUNfHB89TZyoL48xNA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.25.9.tgz", + "integrity": "sha512-+iqjT8xmXhhYv4/uiYd8FNQsraMFZIfxVSqxxVSZP0WbbSAWvBXAul0m/zu+7Vv4O/3WtApy9pmaTMiumEZgfg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1826,12 +1740,13 @@ } }, "node_modules/@babel/plugin-transform-regenerator": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.24.1.tgz", - "integrity": "sha512-sJwZBCzIBE4t+5Q4IGLaaun5ExVMRY0lYwos/jNecjMrVCygCdph3IKv0tkP5Fc87e/1+bebAmEAGBfnRD+cnw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.25.9.tgz", + "integrity": "sha512-vwDcDNsgMPDGP0nMqzahDWE5/MLcX8sv96+wfX7as7LoF/kr97Bo/7fI00lXY4wUXYfVmwIIyG80fGZ1uvt2qg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-plugin-utils": "^7.25.9", "regenerator-transform": "^0.15.2" }, "engines": { @@ -1841,13 +1756,31 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/plugin-transform-regexp-modifiers": { + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regexp-modifiers/-/plugin-transform-regexp-modifiers-7.26.0.tgz", + "integrity": "sha512-vN6saax7lrA2yA/Pak3sCxuD6F5InBjn9IcrIKQPjpsLvuHYLVroTxjdlVRHjjBWxKOqIwpTXDkOssYT4BFdRw==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/helper-create-regexp-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" + }, + "engines": { + "node": ">=6.9.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } + }, "node_modules/@babel/plugin-transform-reserved-words": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-reserved-words/-/plugin-transform-reserved-words-7.24.1.tgz", - "integrity": "sha512-JAclqStUfIwKN15HrsQADFgeZt+wexNQ0uLhuqvqAUFoqPMjEcFCYZBhq0LUdz6dZK/mD+rErhW71fbx8RYElg==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-reserved-words/-/plugin-transform-reserved-words-7.25.9.tgz", + "integrity": "sha512-7DL7DKYjn5Su++4RXu8puKZm2XBPHyjWLUidaPEkCUBbE7IPcsrkRHggAOOKydH1dASWdcUBxrkOGNxUv5P3Jg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1857,15 +1790,16 @@ } }, "node_modules/@babel/plugin-transform-runtime": { - "version": "7.24.3", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.24.3.tgz", - "integrity": "sha512-J0BuRPNlNqlMTRJ72eVptpt9VcInbxO6iP3jaxr+1NPhC0UkKL+6oeX6VXMEYdADnuqmMmsBspt4d5w8Y/TCbQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.25.9.tgz", + "integrity": "sha512-nZp7GlEl+yULJrClz0SwHPqir3lc0zsPrDHQUcxGspSL7AKrexNSEfTbfqnDNJUO13bgKyfuOLMF8Xqtu8j3YQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-module-imports": "^7.24.3", - "@babel/helper-plugin-utils": "^7.24.0", + "@babel/helper-module-imports": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", "babel-plugin-polyfill-corejs2": "^0.4.10", - "babel-plugin-polyfill-corejs3": "^0.10.1", + "babel-plugin-polyfill-corejs3": "^0.10.6", "babel-plugin-polyfill-regenerator": "^0.6.1", "semver": "^6.3.1" }, @@ -1880,18 +1814,20 @@ "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", "peer": true, "bin": { "semver": "bin/semver.js" } }, "node_modules/@babel/plugin-transform-shorthand-properties": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.24.1.tgz", - "integrity": "sha512-LyjVB1nsJ6gTTUKRjRWx9C1s9hE7dLfP/knKdrfeH9UPtAGjYGgxIbFfx7xyLIEWs7Xe1Gnf8EWiUqfjLhInZA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-shorthand-properties/-/plugin-transform-shorthand-properties-7.25.9.tgz", + "integrity": "sha512-MUv6t0FhO5qHnS/W8XCbHmiRWOphNufpE1IVxhK5kuN3Td9FT1x4rx4K42s3RYdMXCXpfWkGSbCSd0Z64xA7Ng==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1901,13 +1837,14 @@ } }, "node_modules/@babel/plugin-transform-spread": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-spread/-/plugin-transform-spread-7.24.1.tgz", - "integrity": "sha512-KjmcIM+fxgY+KxPVbjelJC6hrH1CgtPmTvdXAfn3/a9CnWGSTY7nH4zm5+cjmWJybdcPSsD0++QssDsjcpe47g==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-spread/-/plugin-transform-spread-7.25.9.tgz", + "integrity": "sha512-oNknIB0TbURU5pqJFVbOOFspVlrpVwo2H1+HUIsVDvp5VauGGDP1ZEvO8Nn5xyMEs3dakajOxlmkNW7kNgSm6A==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-skip-transparent-expression-wrappers": "^7.22.5" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1917,12 +1854,13 @@ } }, "node_modules/@babel/plugin-transform-sticky-regex": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.24.1.tgz", - "integrity": "sha512-9v0f1bRXgPVcPrngOQvLXeGNNVLc8UjMVfebo9ka0WF3/7+aVUHmaJVT3sa0XCzEFioPfPHZiOcYG9qOsH63cw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-sticky-regex/-/plugin-transform-sticky-regex-7.25.9.tgz", + "integrity": "sha512-WqBUSgeVwucYDP9U/xNRQam7xV8W5Zf+6Eo7T2SRVUFlhRiMNFdFz58u0KZmCVVqs2i7SHgpRnAhzRNmKfi2uA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1932,12 +1870,13 @@ } }, "node_modules/@babel/plugin-transform-template-literals": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.24.1.tgz", - "integrity": "sha512-WRkhROsNzriarqECASCNu/nojeXCDTE/F2HmRgOzi7NGvyfYGq1NEjKBK3ckLfRgGc6/lPAqP0vDOSw3YtG34g==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.25.9.tgz", + "integrity": "sha512-o97AE4syN71M/lxrCtQByzphAdlYluKPDBzDVzMmfCobUjjhAryZV0AIpRPrxN0eAkxXO6ZLEScmt+PNhj2OTw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1947,12 +1886,13 @@ } }, "node_modules/@babel/plugin-transform-typeof-symbol": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.24.1.tgz", - "integrity": "sha512-CBfU4l/A+KruSUoW+vTQthwcAdwuqbpRNB8HQKlZABwHRhsdHZ9fezp4Sn18PeAlYxTNiLMlx4xUBV3AWfg1BA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.25.9.tgz", + "integrity": "sha512-v61XqUMiueJROUv66BVIOi0Fv/CUuZuZMl5NkRoCVxLAnMexZ0A3kMe7vvZ0nulxMuMp0Mk6S5hNh48yki08ZA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1962,15 +1902,17 @@ } }, "node_modules/@babel/plugin-transform-typescript": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.24.4.tgz", - "integrity": "sha512-79t3CQ8+oBGk/80SQ8MN3Bs3obf83zJ0YZjDmDaEZN8MqhMI760apl5z6a20kFeMXBwJX99VpKT8CKxEBp5H1g==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.25.9.tgz", + "integrity": "sha512-7PbZQZP50tzv2KGGnhh82GSyMB01yKY9scIjf1a+GfZCtInOWqUH5+1EBU4t9fyR5Oykkkc9vFTs4OHrhHXljQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-annotate-as-pure": "^7.22.5", - "@babel/helper-create-class-features-plugin": "^7.24.4", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/plugin-syntax-typescript": "^7.24.1" + "@babel/helper-annotate-as-pure": "^7.25.9", + "@babel/helper-create-class-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9", + "@babel/plugin-syntax-typescript": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1980,12 +1922,13 @@ } }, "node_modules/@babel/plugin-transform-unicode-escapes": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.24.1.tgz", - "integrity": "sha512-RlkVIcWT4TLI96zM660S877E7beKlQw7Ig+wqkKBiWfj0zH5Q4h50q6er4wzZKRNSYpfo6ILJ+hrJAGSX2qcNw==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-escapes/-/plugin-transform-unicode-escapes-7.25.9.tgz", + "integrity": "sha512-s5EDrE6bW97LtxOcGj1Khcx5AaXwiMmi4toFWRDP9/y0Woo6pXC+iyPu/KuhKtfSrNFd7jJB+/fkOtZy6aIC6Q==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1995,13 +1938,14 @@ } }, "node_modules/@babel/plugin-transform-unicode-property-regex": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-property-regex/-/plugin-transform-unicode-property-regex-7.24.1.tgz", - "integrity": "sha512-Ss4VvlfYV5huWApFsF8/Sq0oXnGO+jB+rijFEFugTd3cwSObUSnUi88djgR5528Csl0uKlrI331kRqe56Ov2Ng==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-property-regex/-/plugin-transform-unicode-property-regex-7.25.9.tgz", + "integrity": "sha512-Jt2d8Ga+QwRluxRQ307Vlxa6dMrYEMZCgGxoPR8V52rxPyldHu3hdlHspxaqYmE7oID5+kB+UKUB/eWS+DkkWg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-create-regexp-features-plugin": "^7.22.15", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-create-regexp-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -2011,13 +1955,14 @@ } }, "node_modules/@babel/plugin-transform-unicode-regex": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.24.1.tgz", - "integrity": "sha512-2A/94wgZgxfTsiLaQ2E36XAOdcZmGAaEEgVmxQWwZXWkGhvoHbaqXcKnU8zny4ycpu3vNqg0L/PcCiYtHtA13g==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-regex/-/plugin-transform-unicode-regex-7.25.9.tgz", + "integrity": "sha512-yoxstj7Rg9dlNn9UQxzk4fcNivwv4nUYz7fYXBaKxvw/lnmPuOm/ikoELygbYq68Bls3D/D+NBPHiLwZdZZ4HA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-create-regexp-features-plugin": "^7.22.15", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-create-regexp-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -2027,13 +1972,14 @@ } }, "node_modules/@babel/plugin-transform-unicode-sets-regex": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-sets-regex/-/plugin-transform-unicode-sets-regex-7.24.1.tgz", - "integrity": "sha512-fqj4WuzzS+ukpgerpAoOnMfQXwUHFxXUZUE84oL2Kao2N8uSlvcpnAidKASgsNgzZHBsHWvcm8s9FPWUhAb8fA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-unicode-sets-regex/-/plugin-transform-unicode-sets-regex-7.25.9.tgz", + "integrity": "sha512-8BYqO3GeVNHtx69fdPshN3fnzUNLrWdHhk/icSwigksJGczKSizZ+Z6SBCxTs723Fr5VSNorTIK7a+R2tISvwQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-create-regexp-features-plugin": "^7.22.15", - "@babel/helper-plugin-utils": "^7.24.0" + "@babel/helper-create-regexp-features-plugin": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -2043,91 +1989,80 @@ } }, "node_modules/@babel/preset-env": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.24.4.tgz", - "integrity": "sha512-7Kl6cSmYkak0FK/FXjSEnLJ1N9T/WA2RkMhu17gZ/dsxKJUuTYNIylahPTzqpLyJN4WhDif8X0XK1R8Wsguo/A==", - "peer": true, - "dependencies": { - "@babel/compat-data": "^7.24.4", - "@babel/helper-compilation-targets": "^7.23.6", - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-validator-option": "^7.23.5", - "@babel/plugin-bugfix-firefox-class-in-computed-class-key": "^7.24.4", - "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": "^7.24.1", - "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "^7.24.1", - "@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly": "^7.24.1", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.26.0.tgz", + "integrity": "sha512-H84Fxq0CQJNdPFT2DrfnylZ3cf5K43rGfWK4LJGPpjKHiZlk0/RzwEus3PDDZZg+/Er7lCA03MVacueUuXdzfw==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/compat-data": "^7.26.0", + "@babel/helper-compilation-targets": "^7.25.9", + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-validator-option": "^7.25.9", + "@babel/plugin-bugfix-firefox-class-in-computed-class-key": "^7.25.9", + "@babel/plugin-bugfix-safari-class-field-initializer-scope": "^7.25.9", + "@babel/plugin-bugfix-safari-id-destructuring-collision-in-function-expression": "^7.25.9", + "@babel/plugin-bugfix-v8-spread-parameters-in-optional-chaining": "^7.25.9", + "@babel/plugin-bugfix-v8-static-class-fields-redefine-readonly": "^7.25.9", "@babel/plugin-proposal-private-property-in-object": "7.21.0-placeholder-for-preset-env.2", - "@babel/plugin-syntax-async-generators": "^7.8.4", - "@babel/plugin-syntax-class-properties": "^7.12.13", - "@babel/plugin-syntax-class-static-block": "^7.14.5", - "@babel/plugin-syntax-dynamic-import": "^7.8.3", - "@babel/plugin-syntax-export-namespace-from": "^7.8.3", - "@babel/plugin-syntax-import-assertions": "^7.24.1", - "@babel/plugin-syntax-import-attributes": "^7.24.1", - "@babel/plugin-syntax-import-meta": "^7.10.4", - "@babel/plugin-syntax-json-strings": "^7.8.3", - "@babel/plugin-syntax-logical-assignment-operators": "^7.10.4", - "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3", - "@babel/plugin-syntax-numeric-separator": "^7.10.4", - "@babel/plugin-syntax-object-rest-spread": "^7.8.3", - "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", - "@babel/plugin-syntax-optional-chaining": "^7.8.3", - "@babel/plugin-syntax-private-property-in-object": "^7.14.5", - "@babel/plugin-syntax-top-level-await": "^7.14.5", + "@babel/plugin-syntax-import-assertions": "^7.26.0", + "@babel/plugin-syntax-import-attributes": "^7.26.0", "@babel/plugin-syntax-unicode-sets-regex": "^7.18.6", - "@babel/plugin-transform-arrow-functions": "^7.24.1", - "@babel/plugin-transform-async-generator-functions": "^7.24.3", - "@babel/plugin-transform-async-to-generator": "^7.24.1", - "@babel/plugin-transform-block-scoped-functions": "^7.24.1", - "@babel/plugin-transform-block-scoping": "^7.24.4", - "@babel/plugin-transform-class-properties": "^7.24.1", - "@babel/plugin-transform-class-static-block": "^7.24.4", - "@babel/plugin-transform-classes": "^7.24.1", - "@babel/plugin-transform-computed-properties": "^7.24.1", - "@babel/plugin-transform-destructuring": "^7.24.1", - "@babel/plugin-transform-dotall-regex": "^7.24.1", - "@babel/plugin-transform-duplicate-keys": "^7.24.1", - "@babel/plugin-transform-dynamic-import": "^7.24.1", - "@babel/plugin-transform-exponentiation-operator": "^7.24.1", - "@babel/plugin-transform-export-namespace-from": "^7.24.1", - "@babel/plugin-transform-for-of": "^7.24.1", - "@babel/plugin-transform-function-name": "^7.24.1", - "@babel/plugin-transform-json-strings": "^7.24.1", - "@babel/plugin-transform-literals": "^7.24.1", - "@babel/plugin-transform-logical-assignment-operators": "^7.24.1", - "@babel/plugin-transform-member-expression-literals": "^7.24.1", - "@babel/plugin-transform-modules-amd": "^7.24.1", - "@babel/plugin-transform-modules-commonjs": "^7.24.1", - "@babel/plugin-transform-modules-systemjs": "^7.24.1", - "@babel/plugin-transform-modules-umd": "^7.24.1", - "@babel/plugin-transform-named-capturing-groups-regex": "^7.22.5", - "@babel/plugin-transform-new-target": "^7.24.1", - "@babel/plugin-transform-nullish-coalescing-operator": "^7.24.1", - "@babel/plugin-transform-numeric-separator": "^7.24.1", - "@babel/plugin-transform-object-rest-spread": "^7.24.1", - "@babel/plugin-transform-object-super": "^7.24.1", - "@babel/plugin-transform-optional-catch-binding": "^7.24.1", - "@babel/plugin-transform-optional-chaining": "^7.24.1", - "@babel/plugin-transform-parameters": "^7.24.1", - "@babel/plugin-transform-private-methods": "^7.24.1", - "@babel/plugin-transform-private-property-in-object": "^7.24.1", - "@babel/plugin-transform-property-literals": "^7.24.1", - "@babel/plugin-transform-regenerator": "^7.24.1", - "@babel/plugin-transform-reserved-words": "^7.24.1", - "@babel/plugin-transform-shorthand-properties": "^7.24.1", - "@babel/plugin-transform-spread": "^7.24.1", - "@babel/plugin-transform-sticky-regex": "^7.24.1", - "@babel/plugin-transform-template-literals": "^7.24.1", - "@babel/plugin-transform-typeof-symbol": "^7.24.1", - "@babel/plugin-transform-unicode-escapes": "^7.24.1", - "@babel/plugin-transform-unicode-property-regex": "^7.24.1", - "@babel/plugin-transform-unicode-regex": "^7.24.1", - "@babel/plugin-transform-unicode-sets-regex": "^7.24.1", + "@babel/plugin-transform-arrow-functions": "^7.25.9", + "@babel/plugin-transform-async-generator-functions": "^7.25.9", + "@babel/plugin-transform-async-to-generator": "^7.25.9", + "@babel/plugin-transform-block-scoped-functions": "^7.25.9", + "@babel/plugin-transform-block-scoping": "^7.25.9", + "@babel/plugin-transform-class-properties": "^7.25.9", + "@babel/plugin-transform-class-static-block": "^7.26.0", + "@babel/plugin-transform-classes": "^7.25.9", + "@babel/plugin-transform-computed-properties": "^7.25.9", + "@babel/plugin-transform-destructuring": "^7.25.9", + "@babel/plugin-transform-dotall-regex": "^7.25.9", + "@babel/plugin-transform-duplicate-keys": "^7.25.9", + "@babel/plugin-transform-duplicate-named-capturing-groups-regex": "^7.25.9", + "@babel/plugin-transform-dynamic-import": "^7.25.9", + "@babel/plugin-transform-exponentiation-operator": "^7.25.9", + "@babel/plugin-transform-export-namespace-from": "^7.25.9", + "@babel/plugin-transform-for-of": "^7.25.9", + "@babel/plugin-transform-function-name": "^7.25.9", + "@babel/plugin-transform-json-strings": "^7.25.9", + "@babel/plugin-transform-literals": "^7.25.9", + "@babel/plugin-transform-logical-assignment-operators": "^7.25.9", + "@babel/plugin-transform-member-expression-literals": "^7.25.9", + "@babel/plugin-transform-modules-amd": "^7.25.9", + "@babel/plugin-transform-modules-commonjs": "^7.25.9", + "@babel/plugin-transform-modules-systemjs": "^7.25.9", + "@babel/plugin-transform-modules-umd": "^7.25.9", + "@babel/plugin-transform-named-capturing-groups-regex": "^7.25.9", + "@babel/plugin-transform-new-target": "^7.25.9", + "@babel/plugin-transform-nullish-coalescing-operator": "^7.25.9", + "@babel/plugin-transform-numeric-separator": "^7.25.9", + "@babel/plugin-transform-object-rest-spread": "^7.25.9", + "@babel/plugin-transform-object-super": "^7.25.9", + "@babel/plugin-transform-optional-catch-binding": "^7.25.9", + "@babel/plugin-transform-optional-chaining": "^7.25.9", + "@babel/plugin-transform-parameters": "^7.25.9", + "@babel/plugin-transform-private-methods": "^7.25.9", + "@babel/plugin-transform-private-property-in-object": "^7.25.9", + "@babel/plugin-transform-property-literals": "^7.25.9", + "@babel/plugin-transform-regenerator": "^7.25.9", + "@babel/plugin-transform-regexp-modifiers": "^7.26.0", + "@babel/plugin-transform-reserved-words": "^7.25.9", + "@babel/plugin-transform-shorthand-properties": "^7.25.9", + "@babel/plugin-transform-spread": "^7.25.9", + "@babel/plugin-transform-sticky-regex": "^7.25.9", + "@babel/plugin-transform-template-literals": "^7.25.9", + "@babel/plugin-transform-typeof-symbol": "^7.25.9", + "@babel/plugin-transform-unicode-escapes": "^7.25.9", + "@babel/plugin-transform-unicode-property-regex": "^7.25.9", + "@babel/plugin-transform-unicode-regex": "^7.25.9", + "@babel/plugin-transform-unicode-sets-regex": "^7.25.9", "@babel/preset-modules": "0.1.6-no-external-plugins", "babel-plugin-polyfill-corejs2": "^0.4.10", - "babel-plugin-polyfill-corejs3": "^0.10.4", + "babel-plugin-polyfill-corejs3": "^0.10.6", "babel-plugin-polyfill-regenerator": "^0.6.1", - "core-js-compat": "^3.31.0", + "core-js-compat": "^3.38.1", "semver": "^6.3.1" }, "engines": { @@ -2141,20 +2076,22 @@ "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", "peer": true, "bin": { "semver": "bin/semver.js" } }, "node_modules/@babel/preset-flow": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/preset-flow/-/preset-flow-7.24.1.tgz", - "integrity": "sha512-sWCV2G9pcqZf+JHyv/RyqEIpFypxdCSxWIxQjpdaQxenNog7cN1pr76hg8u0Fz8Qgg0H4ETkGcJnXL8d4j0PPA==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/preset-flow/-/preset-flow-7.25.9.tgz", + "integrity": "sha512-EASHsAhE+SSlEzJ4bzfusnXSHiU+JfAYzj+jbw2vgQKgq5HrUr8qs+vgtiEL5dOH6sEweI+PNt2D7AqrDSHyqQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-validator-option": "^7.23.5", - "@babel/plugin-transform-flow-strip-types": "^7.24.1" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-validator-option": "^7.25.9", + "@babel/plugin-transform-flow-strip-types": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -2167,6 +2104,7 @@ "version": "0.1.6-no-external-plugins", "resolved": "https://registry.npmjs.org/@babel/preset-modules/-/preset-modules-0.1.6-no-external-plugins.tgz", "integrity": "sha512-HrcgcIESLm9aIR842yhJ5RWan/gebQUJ6E/E5+rf0y9o6oj7w0Br+sWuL6kEQ/o/AdfvR1Je9jG18/gnpwjEyA==", + "license": "MIT", "peer": true, "dependencies": { "@babel/helper-plugin-utils": "^7.0.0", @@ -2178,16 +2116,17 @@ } }, "node_modules/@babel/preset-typescript": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.24.1.tgz", - "integrity": "sha512-1DBaMmRDpuYQBPWD8Pf/WEwCrtgRHxsZnP4mIy9G/X+hFfbI47Q2G4t1Paakld84+qsk2fSsUPMKg71jkoOOaQ==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.26.0.tgz", + "integrity": "sha512-NMk1IGZ5I/oHhoXEElcm+xUnL/szL6xflkFZmoEU9xj1qSJXpiS7rsspYo92B4DRCDvZn2erT5LdsCeXAKNCkg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.24.0", - "@babel/helper-validator-option": "^7.23.5", - "@babel/plugin-syntax-jsx": "^7.24.1", - "@babel/plugin-transform-modules-commonjs": "^7.24.1", - "@babel/plugin-transform-typescript": "^7.24.1" + "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-validator-option": "^7.25.9", + "@babel/plugin-syntax-jsx": "^7.25.9", + "@babel/plugin-transform-modules-commonjs": "^7.25.9", + "@babel/plugin-transform-typescript": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -2197,9 +2136,10 @@ } }, "node_modules/@babel/register": { - "version": "7.23.7", - "resolved": "https://registry.npmjs.org/@babel/register/-/register-7.23.7.tgz", - "integrity": "sha512-EjJeB6+kvpk+Y5DAkEAmbOBEFkh9OASx0huoEkqYTFxAZHzOAX2Oh5uwAUuL2rUddqfM0SA+KPXV2TbzoZ2kvQ==", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/register/-/register-7.25.9.tgz", + "integrity": "sha512-8D43jXtGsYmEeDvm4MWHYUpWf8iiXgWYx3fW7E7Wb7Oe6FWqJPl5K6TuFW0dOwNZzEE5rjlaSJYH9JjrUKJszA==", + "license": "MIT", "peer": true, "dependencies": { "clone-deep": "^4.0.1", @@ -2215,16 +2155,11 @@ "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/regjsgen": { - "version": "0.8.0", - "resolved": "https://registry.npmjs.org/@babel/regjsgen/-/regjsgen-0.8.0.tgz", - "integrity": "sha512-x/rqGMdzj+fWZvCOYForTghzbtqPDZ5gPwaoNGHdgDfF2QA/XZbCBp4Moo5scrkAMPhB7z26XM/AaHuIJdgauA==", - "peer": true - }, "node_modules/@babel/runtime": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.4.tgz", - "integrity": "sha512-dkxf7+hn8mFBwKjs9bvBlArzLVxVbS8usaPUDd5p2a9JCL9tB8OaOVN1isD4+Xyk4ns89/xeOmbQvgdK7IIVdA==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.26.0.tgz", + "integrity": "sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==", + "license": "MIT", "peer": true, "dependencies": { "regenerator-runtime": "^0.14.0" @@ -2233,48 +2168,60 @@ "node": ">=6.9.0" } }, - "node_modules/@babel/runtime-corejs3": { - "version": "7.24.4", - "resolved": "https://registry.npmjs.org/@babel/runtime-corejs3/-/runtime-corejs3-7.24.4.tgz", - "integrity": "sha512-VOQOexSilscN24VEY810G/PqtpFvx/z6UqDIjIWbDe2368HhDLkYN5TYwaEz/+eRCUkhJ2WaNLLmQAlxzfWj4w==", - "dev": true, + "node_modules/@babel/runtime/node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "license": "MIT", + "peer": true + }, + "node_modules/@babel/template": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.9.tgz", + "integrity": "sha512-9DGttpmPvIxBb/2uwpVo3dqJ+O6RooAFOS+lB+xDqoE2PVCE8nfoHMdZLpfCQRLwvohzXISPZcgxt80xLfsuwg==", + "license": "MIT", "peer": true, "dependencies": { - "core-js-pure": "^3.30.2", - "regenerator-runtime": "^0.14.0" + "@babel/code-frame": "^7.25.9", + "@babel/parser": "^7.25.9", + "@babel/types": "^7.25.9" }, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/template": { - "version": "7.24.0", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.24.0.tgz", - "integrity": "sha512-Bkf2q8lMB0AFpX0NFEqSbx1OkTHf0f+0j82mkw+ZpzBnkk7e9Ql0891vlfgi+kHwOk8tQjiQHpqh4LaSa0fKEA==", + "node_modules/@babel/traverse": { + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.9.tgz", + "integrity": "sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/code-frame": "^7.23.5", - "@babel/parser": "^7.24.0", - "@babel/types": "^7.24.0" + "@babel/code-frame": "^7.25.9", + "@babel/generator": "^7.25.9", + "@babel/parser": "^7.25.9", + "@babel/template": "^7.25.9", + "@babel/types": "^7.25.9", + "debug": "^4.3.1", + "globals": "^11.1.0" }, "engines": { "node": ">=6.9.0" } }, - "node_modules/@babel/traverse": { - "version": "7.24.1", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.24.1.tgz", - "integrity": "sha512-xuU6o9m68KeqZbQuDt2TcKSxUw/mrsvavlEqQ1leZ/B+C9tk6E4sRWy97WaXgvq5E+nU3cXMxv3WKOCanVMCmQ==", - "peer": true, - "dependencies": { - "@babel/code-frame": "^7.24.1", - "@babel/generator": "^7.24.1", - "@babel/helper-environment-visitor": "^7.22.20", - "@babel/helper-function-name": "^7.23.0", - "@babel/helper-hoist-variables": "^7.22.5", - "@babel/helper-split-export-declaration": "^7.22.6", - "@babel/parser": "^7.24.1", - "@babel/types": "^7.24.0", + "node_modules/@babel/traverse--for-generate-function-map": { + "name": "@babel/traverse", + "version": "7.25.9", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.9.tgz", + "integrity": "sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.25.9", + "@babel/generator": "^7.25.9", + "@babel/parser": "^7.25.9", + "@babel/template": "^7.25.9", + "@babel/types": "^7.25.9", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -2282,24 +2229,35 @@ "node": ">=6.9.0" } }, + "node_modules/@babel/traverse--for-generate-function-map/node_modules/globals": { + "version": "11.12.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", + "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=4" + } + }, "node_modules/@babel/traverse/node_modules/globals": { "version": "11.12.0", "resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz", "integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==", + "license": "MIT", "peer": true, "engines": { "node": ">=4" } }, "node_modules/@babel/types": { - "version": "7.24.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.24.0.tgz", - "integrity": "sha512-+j7a5c253RfKh8iABBhywc8NSfP5LURe7Uh4qpsh6jc+aLJguvmIUBdjSdEMQv2bENrCR5MfRdjGo7vzS/ob7w==", + "version": "7.26.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.0.tgz", + "integrity": "sha512-Z/yiTPj+lDVnF7lWeKCIJzaIkI0vYO87dMpZ4bg4TDrFe4XXLFWL1TbXU27gBP3QccxV9mZICCrnjnYlJjXHOA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-string-parser": "^7.23.4", - "@babel/helper-validator-identifier": "^7.22.20", - "to-fast-properties": "^2.0.0" + "@babel/helper-string-parser": "^7.25.9", + "@babel/helper-validator-identifier": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -2310,6 +2268,7 @@ "resolved": "https://registry.npmjs.org/@colors/colors/-/colors-1.5.0.tgz", "integrity": "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.1.90" } @@ -2319,6 +2278,7 @@ "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", "dev": true, + "license": "MIT", "dependencies": { "@jridgewell/trace-mapping": "0.3.9" }, @@ -2331,6 +2291,7 @@ "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", "dev": true, + "license": "MIT", "dependencies": { "@jridgewell/resolve-uri": "^3.0.3", "@jridgewell/sourcemap-codec": "^1.4.10" @@ -2340,20 +2301,24 @@ "version": "10.0.1", "resolved": "https://registry.npmjs.org/@cucumber/ci-environment/-/ci-environment-10.0.1.tgz", "integrity": "sha512-/+ooDMPtKSmvcPMDYnMZt4LuoipfFfHaYspStI4shqw8FyKcfQAmekz6G+QKWjQQrvM+7Hkljwx58MEwPCwwzg==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/@cucumber/cucumber": { - "version": "10.4.0", - "resolved": "https://registry.npmjs.org/@cucumber/cucumber/-/cucumber-10.4.0.tgz", - "integrity": "sha512-pFPu4tCzHJUm1S4GfWUlhJYYqfbVPCmYCADehuhNU+MR29mvy49DQE6WS6aVdwABPawzpBs0H8EuQYA8Vh9Yqw==", + "version": "10.9.0", + "resolved": "https://registry.npmjs.org/@cucumber/cucumber/-/cucumber-10.9.0.tgz", + "integrity": "sha512-7XHJ6nmr9IkIag0nv6or82HfelbSInrEe3H4aT6dMHyTehwFLUifG6eQQ+uE4LZIOXAnzLPH37YmqygEO67vCA==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "@cucumber/ci-environment": "10.0.1", "@cucumber/cucumber-expressions": "17.1.0", "@cucumber/gherkin": "28.0.0", "@cucumber/gherkin-streams": "5.0.1", "@cucumber/gherkin-utils": "9.0.0", - "@cucumber/html-formatter": "21.3.1", + "@cucumber/html-formatter": "21.6.0", "@cucumber/message-streams": "4.0.1", "@cucumber/messages": "24.1.0", "@cucumber/tag-expressions": "6.1.0", @@ -2374,6 +2339,7 @@ "lodash.merge": "^4.6.2", "lodash.mergewith": "^4.6.2", "luxon": "3.2.1", + "mime": "^3.0.0", "mkdirp": "^2.1.5", "mz": "^2.7.0", "progress": "^2.0.3", @@ -2405,32 +2371,172 @@ "resolved": "https://registry.npmjs.org/@cucumber/cucumber-expressions/-/cucumber-expressions-17.1.0.tgz", "integrity": "sha512-PCv/ppsPynniKPWJr5v566daCVe+pbxQpHGrIu/Ev57cCH9Rv+X0F6lio4Id3Z64TaG7btCRLUGewIgLwmrwOA==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "regexp-match-indices": "1.0.2" } }, - "node_modules/@cucumber/gherkin": { - "version": "28.0.0", - "resolved": "https://registry.npmjs.org/@cucumber/gherkin/-/gherkin-28.0.0.tgz", - "integrity": "sha512-Ee6zJQq0OmIUPdW0mSnsCsrWA2PZAELNDPICD2pLfs0Oz7RAPgj80UsD2UCtqyAhw2qAR62aqlktKUlai5zl/A==", + "node_modules/@cucumber/cucumber/node_modules/commander": { + "version": "10.0.1", + "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", + "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", "dev": true, - "dependencies": { - "@cucumber/messages": ">=19.1.4 <=24" + "license": "MIT", + "peer": true, + "engines": { + "node": ">=14" } }, - "node_modules/@cucumber/gherkin-streams": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/gherkin-streams/-/gherkin-streams-5.0.1.tgz", - "integrity": "sha512-/7VkIE/ASxIP/jd4Crlp4JHXqdNFxPGQokqWqsaCCiqBiu5qHoKMxcWNlp9njVL/n9yN4S08OmY3ZR8uC5x74Q==", + "node_modules/@cucumber/cucumber/node_modules/glob": { + "version": "10.4.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", + "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", "dev": true, + "license": "ISC", + "peer": true, "dependencies": { - "commander": "9.1.0", - "source-map-support": "0.5.21" + "foreground-child": "^3.1.0", + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^1.11.1" }, "bin": { - "gherkin-javascript": "bin/gherkin" + "glob": "dist/esm/bin.mjs" }, - "peerDependencies": { + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@cucumber/cucumber/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "license": "ISC", + "peer": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@cucumber/cucumber/node_modules/mime": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", + "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", + "dev": true, + "license": "MIT", + "peer": true, + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=10.0.0" + } + }, + "node_modules/@cucumber/cucumber/node_modules/mkdirp": { + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.6.tgz", + "integrity": "sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==", + "dev": true, + "license": "MIT", + "peer": true, + "bin": { + "mkdirp": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@cucumber/cucumber/node_modules/semver": { + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "dev": true, + "license": "ISC", + "peer": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@cucumber/cucumber/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, + "node_modules/@cucumber/cucumber/node_modules/type-fest": { + "version": "4.26.1", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.26.1.tgz", + "integrity": "sha512-yOGpmOAL7CkKe/91I5O3gPICmJNLJ1G4zFYVAsRHg7M64biSnPtRj0WNQt++bRkjYOqjWXrhnUw1utzmVErAdg==", + "dev": true, + "license": "(MIT OR CC0-1.0)", + "peer": true, + "engines": { + "node": ">=16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@cucumber/cucumber/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true, + "license": "ISC", + "peer": true + }, + "node_modules/@cucumber/gherkin": { + "version": "28.0.0", + "resolved": "https://registry.npmjs.org/@cucumber/gherkin/-/gherkin-28.0.0.tgz", + "integrity": "sha512-Ee6zJQq0OmIUPdW0mSnsCsrWA2PZAELNDPICD2pLfs0Oz7RAPgj80UsD2UCtqyAhw2qAR62aqlktKUlai5zl/A==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@cucumber/messages": ">=19.1.4 <=24" + } + }, + "node_modules/@cucumber/gherkin-streams": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@cucumber/gherkin-streams/-/gherkin-streams-5.0.1.tgz", + "integrity": "sha512-/7VkIE/ASxIP/jd4Crlp4JHXqdNFxPGQokqWqsaCCiqBiu5qHoKMxcWNlp9njVL/n9yN4S08OmY3ZR8uC5x74Q==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "commander": "9.1.0", + "source-map-support": "0.5.21" + }, + "bin": { + "gherkin-javascript": "bin/gherkin" + }, + "peerDependencies": { "@cucumber/gherkin": ">=22.0.0", "@cucumber/message-streams": ">=4.0.0", "@cucumber/messages": ">=17.1.1" @@ -2441,6 +2547,8 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-9.1.0.tgz", "integrity": "sha512-i0/MaqBtdbnJ4XQs4Pmyb+oFQl+q0lsAmokVUH92SlSw4fkeAcG3bVon+Qt7hmtF+u3Het6o4VgrcY3qAoEB6w==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": "^12.20.0 || >=14" } @@ -2450,6 +2558,8 @@ "resolved": "https://registry.npmjs.org/@cucumber/gherkin-utils/-/gherkin-utils-9.0.0.tgz", "integrity": "sha512-clk4q39uj7pztZuZtyI54V8lRsCUz0Y/p8XRjIeHh7ExeEztpWkp4ca9q1FjUOPfQQ8E7OgqFbqoQQXZ1Bx7fw==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "@cucumber/gherkin": "^28.0.0", "@cucumber/messages": "^24.0.0", @@ -2466,15 +2576,19 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-12.0.0.tgz", "integrity": "sha512-MwVNWlYjDTtOjX5PiD7o5pK0UrFU/OYgcJfjjK4RaHZETNtjJqrZa9Y9ds88+A+f+d5lv+561eZ+yCKoS3gbAA==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=18" } }, "node_modules/@cucumber/html-formatter": { - "version": "21.3.1", - "resolved": "https://registry.npmjs.org/@cucumber/html-formatter/-/html-formatter-21.3.1.tgz", - "integrity": "sha512-M1zbre7e8MsecXheqNv62BKY5J06YJSv1LmsD7sJ3mu5t1jirLjj2It1HqPsX5CQAfg9n69xFRugPgLMSte9TA==", + "version": "21.6.0", + "resolved": "https://registry.npmjs.org/@cucumber/html-formatter/-/html-formatter-21.6.0.tgz", + "integrity": "sha512-Qw1tdObBJrgXgXwVjKVjB3hFhFPI8WhIFb+ULy8g5lDl5AdnKDiyDXAMvAWRX+pphnRMMNdkPCt6ZXEfWvUuAA==", "dev": true, + "license": "MIT", + "peer": true, "peerDependencies": { "@cucumber/messages": ">=18" } @@ -2484,6 +2598,8 @@ "resolved": "https://registry.npmjs.org/@cucumber/message-streams/-/message-streams-4.0.1.tgz", "integrity": "sha512-Kxap9uP5jD8tHUZVjTWgzxemi/0uOsbGjd4LBOSxcJoOCRbESFwemUzilJuzNTB8pcTQUh8D5oudUyxfkJOKmA==", "dev": true, + "license": "MIT", + "peer": true, "peerDependencies": { "@cucumber/messages": ">=17.1.1" } @@ -2493,6 +2609,8 @@ "resolved": "https://registry.npmjs.org/@cucumber/messages/-/messages-24.1.0.tgz", "integrity": "sha512-hxVHiBurORcobhVk80I9+JkaKaNXkW6YwGOEFIh/2aO+apAN+5XJgUUWjng9NwqaQrW1sCFuawLB1AuzmBaNdQ==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "@types/uuid": "9.0.8", "class-transformer": "0.5.1", @@ -2500,416 +2618,447 @@ "uuid": "9.0.1" } }, - "node_modules/@cucumber/pretty-formatter": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/pretty-formatter/-/pretty-formatter-1.0.1.tgz", - "integrity": "sha512-A1lU4VVP0aUWdOTmpdzvXOyEYuPtBDI0xYwYJnmoMDplzxMdhcHk86lyyvYDoMoPzzq6OkOE3isuosvUU4X7IQ==", - "dev": true, - "dependencies": { - "ansi-styles": "^5.0.0", - "cli-table3": "^0.6.0", - "figures": "^3.2.0", - "ts-dedent": "^2.0.0" - }, - "peerDependencies": { - "@cucumber/cucumber": ">=7.0.0", - "@cucumber/messages": "*" - } - }, "node_modules/@cucumber/tag-expressions": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/@cucumber/tag-expressions/-/tag-expressions-6.1.0.tgz", "integrity": "sha512-+3DwRumrCJG27AtzCIL37A/X+A/gSfxOPLg8pZaruh5SLumsTmpvilwroVWBT2fPzmno/tGXypeK5a7NHU4RzA==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/@esbuild/aix-ppc64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.19.12.tgz", - "integrity": "sha512-bmoCYyWdEL3wDQIVbcyzRyeKLgk2WtWLTWz1ZIAZF/EGbNOwSA6ew3PftJ1PqMiOOGu0OyFMzG53L0zqIpPeNA==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", + "integrity": "sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ==", "cpu": [ "ppc64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "aix" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/android-arm": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.19.12.tgz", - "integrity": "sha512-qg/Lj1mu3CdQlDEEiWrlC4eaPZ1KztwGJ9B6J+/6G+/4ewxJg7gqj8eVYWvao1bXrqGiW2rsBZFSX3q2lcW05w==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.23.1.tgz", + "integrity": "sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ==", "cpu": [ "arm" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "android" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/android-arm64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.19.12.tgz", - "integrity": "sha512-P0UVNGIienjZv3f5zq0DP3Nt2IE/3plFzuaS96vihvD0Hd6H/q4WXUGpCxD/E8YrSXfNyRPbpTq+T8ZQioSuPA==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.23.1.tgz", + "integrity": "sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "android" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/android-x64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.19.12.tgz", - "integrity": "sha512-3k7ZoUW6Q6YqhdhIaq/WZ7HwBpnFBlW905Fa4s4qWJyiNOgT1dOqDiVAQFwBH7gBRZr17gLrlFCRzF6jFh7Kew==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.23.1.tgz", + "integrity": "sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "android" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/darwin-arm64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.19.12.tgz", - "integrity": "sha512-B6IeSgZgtEzGC42jsI+YYu9Z3HKRxp8ZT3cqhvliEHovq8HSX2YX8lNocDn79gCKJXOSaEot9MVYky7AKjCs8g==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.1.tgz", + "integrity": "sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "darwin" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.19.12.tgz", - "integrity": "sha512-hKoVkKzFiToTgn+41qGhsUJXFlIjxI/jSYeZf3ugemDYZldIXIxhvwN6erJGlX4t5h417iFuheZ7l+YVn05N3A==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.23.1.tgz", + "integrity": "sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "darwin" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.19.12.tgz", - "integrity": "sha512-4aRvFIXmwAcDBw9AueDQ2YnGmz5L6obe5kmPT8Vd+/+x/JMVKCgdcRwH6APrbpNXsPz+K653Qg8HB/oXvXVukA==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.23.1.tgz", + "integrity": "sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "freebsd" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.19.12.tgz", - "integrity": "sha512-EYoXZ4d8xtBoVN7CEwWY2IN4ho76xjYXqSXMNccFSx2lgqOG/1TBPW0yPx1bJZk94qu3tX0fycJeeQsKovA8gg==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.23.1.tgz", + "integrity": "sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "freebsd" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-arm": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.19.12.tgz", - "integrity": "sha512-J5jPms//KhSNv+LO1S1TX1UWp1ucM6N6XuL6ITdKWElCu8wXP72l9MM0zDTzzeikVyqFE6U8YAV9/tFyj0ti+w==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.23.1.tgz", + "integrity": "sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ==", "cpu": [ "arm" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.19.12.tgz", - "integrity": "sha512-EoTjyYyLuVPfdPLsGVVVC8a0p1BFFvtpQDB/YLEhaXyf/5bczaGeN15QkR+O4S5LeJ92Tqotve7i1jn35qwvdA==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.1.tgz", + "integrity": "sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.19.12.tgz", - "integrity": "sha512-Thsa42rrP1+UIGaWz47uydHSBOgTUnwBwNq59khgIwktK6x60Hivfbux9iNR0eHCHzOLjLMLfUMLCypBkZXMHA==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.23.1.tgz", + "integrity": "sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ==", "cpu": [ "ia32" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.19.12.tgz", - "integrity": "sha512-LiXdXA0s3IqRRjm6rV6XaWATScKAXjI4R4LoDlvO7+yQqFdlr1Bax62sRwkVvRIrwXxvtYEHHI4dm50jAXkuAA==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.23.1.tgz", + "integrity": "sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw==", "cpu": [ "loong64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.19.12.tgz", - "integrity": "sha512-fEnAuj5VGTanfJ07ff0gOA6IPsvrVHLVb6Lyd1g2/ed67oU1eFzL0r9WL7ZzscD+/N6i3dWumGE1Un4f7Amf+w==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.23.1.tgz", + "integrity": "sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q==", "cpu": [ "mips64el" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.19.12.tgz", - "integrity": "sha512-nYJA2/QPimDQOh1rKWedNOe3Gfc8PabU7HT3iXWtNUbRzXS9+vgB0Fjaqr//XNbd82mCxHzik2qotuI89cfixg==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.23.1.tgz", + "integrity": "sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw==", "cpu": [ "ppc64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.19.12.tgz", - "integrity": "sha512-2MueBrlPQCw5dVJJpQdUYgeqIzDQgw3QtiAHUC4RBz9FXPrskyyU3VI1hw7C0BSKB9OduwSJ79FTCqtGMWqJHg==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.23.1.tgz", + "integrity": "sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA==", "cpu": [ "riscv64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.19.12.tgz", - "integrity": "sha512-+Pil1Nv3Umes4m3AZKqA2anfhJiVmNCYkPchwFJNEJN5QxmTs1uzyy4TvmDrCRNT2ApwSari7ZIgrPeUx4UZDg==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.23.1.tgz", + "integrity": "sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw==", "cpu": [ "s390x" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/linux-x64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.19.12.tgz", - "integrity": "sha512-B71g1QpxfwBvNrfyJdVDexenDIt1CiDN1TIXLbhOw0KhJzE78KIFGX6OJ9MrtC0oOqMWf+0xop4qEU8JrJTwCg==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.1.tgz", + "integrity": "sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.19.12.tgz", - "integrity": "sha512-3ltjQ7n1owJgFbuC61Oj++XhtzmymoCihNFgT84UAmJnxJfm4sYCiSLTXZtE00VWYpPMYc+ZQmB6xbSdVh0JWA==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.23.1.tgz", + "integrity": "sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "netbsd" ], "engines": { - "node": ">=12" + "node": ">=18" + } + }, + "node_modules/@esbuild/openbsd-arm64": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.23.1.tgz", + "integrity": "sha512-3x37szhLexNA4bXhLrCC/LImN/YtWis6WXr1VESlfVtVeoFJBRINPJ3f0a/6LV8zpikqoUg4hyXw0sFBt5Cr+Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ], + "engines": { + "node": ">=18" } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.19.12.tgz", - "integrity": "sha512-RbrfTB9SWsr0kWmb9srfF+L933uMDdu9BIzdA7os2t0TXhCRjrQyCeOt6wVxr79CKD4c+p+YhCj31HBkYcXebw==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.23.1.tgz", + "integrity": "sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "openbsd" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/sunos-x64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.19.12.tgz", - "integrity": "sha512-HKjJwRrW8uWtCQnQOz9qcU3mUZhTUQvi56Q8DPTLLB+DawoiQdjsYq+j+D3s9I8VFtDr+F9CjgXKKC4ss89IeA==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.23.1.tgz", + "integrity": "sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "sunos" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.19.12.tgz", - "integrity": "sha512-URgtR1dJnmGvX864pn1B2YUYNzjmXkuJOIqG2HdU62MVS4EHpU2946OZoTMnRUHklGtJdJZ33QfzdjGACXhn1A==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.23.1.tgz", + "integrity": "sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.19.12.tgz", - "integrity": "sha512-+ZOE6pUkMOJfmxmBZElNOx72NKpIa/HFOMGzu8fqzQJ5kgf6aTGrcJaFsNiVMH4JKpMipyK+7k0n2UXN7a8YKQ==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.23.1.tgz", + "integrity": "sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ==", "cpu": [ "ia32" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@esbuild/win32-x64": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.19.12.tgz", - "integrity": "sha512-T1QyPSDCyMXaO3pzBkF96E8xMkiRYbUEZADd29SyPGabqxMViNoii+NcK7eWJAEoU6RZyEm5lVSIjTmcdoB9HA==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.23.1.tgz", + "integrity": "sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "win32" ], "engines": { - "node": ">=12" + "node": ">=18" } }, "node_modules/@eslint-community/eslint-utils": { - "version": "4.4.0", - "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz", - "integrity": "sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA==", + "version": "4.4.1", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz", + "integrity": "sha512-s3O3waFUrMV8P/XaF/+ZTp1X9XBZW1a4B97ZnjQF2KYWaFD2A8KyFBsrsfSjEmjn3RGWAIuvlneuZm3CUK3jbA==", "dev": true, + "license": "MIT", "dependencies": { - "eslint-visitor-keys": "^3.3.0" + "eslint-visitor-keys": "^3.4.3" }, "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, + "funding": { + "url": "https://opencollective.com/eslint" + }, "peerDependencies": { "eslint": "^6.0.0 || ^7.0.0 || >=8.0.0" } }, "node_modules/@eslint-community/regexpp": { - "version": "4.10.0", - "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.10.0.tgz", - "integrity": "sha512-Cu96Sd2By9mCNTx2iyKOmq10v22jUVQv0lQnlGNy16oE9589yE+QADPbrMGCkA51cKZSg3Pu/aTJVTGfL/qjUA==", + "version": "4.12.1", + "resolved": "https://registry.npmjs.org/@eslint-community/regexpp/-/regexpp-4.12.1.tgz", + "integrity": "sha512-CCZCDJuduB9OUkFkY2IgppNZMi2lBQgD2qzwXkEia16cge2pijY/aXi96CJMquDMn3nJdlPV1A5KrJEXwfLNzQ==", "dev": true, + "license": "MIT", "engines": { "node": "^12.0.0 || ^14.0.0 || >=16.0.0" } @@ -2919,6 +3068,7 @@ "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-2.1.4.tgz", "integrity": "sha512-269Z39MS6wVJtsoUl10L60WdkhJVdPG24Q4eZTH3nnF6lpvSShEK3wQjDX9JRWAUPvPh7COouPpU9IrqaZFvtQ==", "dev": true, + "license": "MIT", "dependencies": { "ajv": "^6.12.4", "debug": "^4.3.2", @@ -2941,13 +3091,15 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true + "dev": true, + "license": "Python-2.0" }, "node_modules/@eslint/eslintrc/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, + "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2958,6 +3110,7 @@ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, + "license": "MIT", "dependencies": { "argparse": "^2.0.1" }, @@ -2970,6 +3123,7 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, + "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" }, @@ -2978,36 +3132,24 @@ } }, "node_modules/@eslint/js": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.0.tgz", - "integrity": "sha512-Ys+3g2TaW7gADOJzPt83SJtCDhMjndcDMFVQ/Tj9iA1BfJzFKD9mAUXT3OenpuPHbI6P/myECxRJrofUsDx/5g==", + "version": "8.57.1", + "resolved": "https://registry.npmjs.org/@eslint/js/-/js-8.57.1.tgz", + "integrity": "sha512-d9zaMRSTIKDLhctzH12MtXvJKSSUhaHcjV+2Z+GK+EEY7XKpP5yR4x+N3TAcHTcu963nIr+TMcCb4DBCYX1z6Q==", "dev": true, + "license": "MIT", "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" } }, - "node_modules/@hapi/hoek": { - "version": "9.3.0", - "resolved": "https://registry.npmjs.org/@hapi/hoek/-/hoek-9.3.0.tgz", - "integrity": "sha512-/c6rf4UJlmHlC9b5BaNvzAcFv7HZ2QHaV0D4/HNlBdvFnvQq8RI4kYdhyPCl7Xj+oWvTWQ8ujhqS53LIgAe6KQ==", - "peer": true - }, - "node_modules/@hapi/topo": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@hapi/topo/-/topo-5.1.0.tgz", - "integrity": "sha512-foQZKJig7Ob0BMAYBfcJk8d77QtOe7Wo4ox7ff1lQYoNNAb6jwcY1ncdoy2e9wQZzvNy7ODZCYJkK8kzmcAnAg==", - "peer": true, - "dependencies": { - "@hapi/hoek": "^9.0.0" - } - }, "node_modules/@humanwhocodes/config-array": { - "version": "0.11.14", - "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.11.14.tgz", - "integrity": "sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==", + "version": "0.13.0", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.13.0.tgz", + "integrity": "sha512-DZLEEqFWQFiyK6h5YIeynKx7JlvCYWL0cImfSRXZ9l4Sg2efkFGTuFf6vzXjK1cq6IYkU+Eg/JizXw+TD2vRNw==", + "deprecated": "Use @eslint/config-array instead", "dev": true, + "license": "Apache-2.0", "dependencies": { - "@humanwhocodes/object-schema": "^2.0.2", + "@humanwhocodes/object-schema": "^2.0.3", "debug": "^4.3.1", "minimatch": "^3.0.5" }, @@ -3020,6 +3162,7 @@ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, + "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -3030,6 +3173,7 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, + "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" }, @@ -3042,6 +3186,7 @@ "resolved": "https://registry.npmjs.org/@humanwhocodes/module-importer/-/module-importer-1.0.1.tgz", "integrity": "sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=12.22" }, @@ -3054,13 +3199,17 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-2.0.3.tgz", "integrity": "sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==", - "dev": true + "deprecated": "Use @eslint/object-schema instead", + "dev": true, + "license": "BSD-3-Clause" }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", "integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==", "dev": true, + "license": "ISC", + "peer": true, "dependencies": { "string-width": "^5.1.2", "string-width-cjs": "npm:string-width@^4.2.0", @@ -3074,10 +3223,12 @@ } }, "node_modules/@isaacs/cliui/node_modules/ansi-regex": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", - "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -3085,17 +3236,35 @@ "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, + "node_modules/@isaacs/cliui/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/@isaacs/cliui/node_modules/emoji-regex": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/@isaacs/cliui/node_modules/string-width": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "eastasianwidth": "^0.2.0", "emoji-regex": "^9.2.2", @@ -3113,6 +3282,8 @@ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "ansi-regex": "^6.0.1" }, @@ -3123,37 +3294,152 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/@isaacs/cliui/node_modules/wrap-ansi": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/@isaacs/ttlcache": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/@isaacs/ttlcache/-/ttlcache-1.4.1.tgz", "integrity": "sha512-RQgQ4uQ+pLbqXfOmieB91ejmLwvSgv9nLx6sT6sD83s7umBypgg+OIBOBbEUiJXrfpnp9j0mRhYYdzp9uqq3lA==", + "license": "ISC", "peer": true, "engines": { "node": ">=12" } }, - "node_modules/@jest/create-cache-key-function": { - "version": "29.7.0", - "resolved": "https://registry.npmjs.org/@jest/create-cache-key-function/-/create-cache-key-function-29.7.0.tgz", - "integrity": "sha512-4QqS3LY5PBmTRHj9sAg1HLoPzqAI0uOX6wI/TRqHIcOxlFidy6YEmCQJk6FSZjNLGCeubDMfmkWL+qaLKhSGQA==", + "node_modules/@istanbuljs/load-nyc-config": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", + "integrity": "sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==", + "license": "ISC", "peer": true, "dependencies": { - "@jest/types": "^29.6.3" + "camelcase": "^5.3.1", + "find-up": "^4.1.0", + "get-package-type": "^0.1.0", + "js-yaml": "^3.13.1", + "resolve-from": "^5.0.0" }, "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + "node": ">=8" } }, - "node_modules/@jest/environment": { - "version": "29.7.0", - "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.7.0.tgz", - "integrity": "sha512-aQIfHDq33ExsN4jP1NWGXhxgQ/wixs60gDiKO+XVMd8Mn0NWPWgc34ZQDTb2jKaUWQ7MuwoitXAsN2XVXNMpAw==", + "node_modules/@istanbuljs/load-nyc-config/node_modules/find-up": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", + "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", + "license": "MIT", "peer": true, "dependencies": { - "@jest/fake-timers": "^29.7.0", - "@jest/types": "^29.6.3", - "@types/node": "*", - "jest-mock": "^29.7.0" + "locate-path": "^5.0.0", + "path-exists": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@istanbuljs/load-nyc-config/node_modules/locate-path": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", + "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", + "license": "MIT", + "peer": true, + "dependencies": { + "p-locate": "^4.1.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@istanbuljs/load-nyc-config/node_modules/p-limit": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", + "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "license": "MIT", + "peer": true, + "dependencies": { + "p-try": "^2.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/@istanbuljs/load-nyc-config/node_modules/p-locate": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", + "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", + "license": "MIT", + "peer": true, + "dependencies": { + "p-limit": "^2.2.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/@istanbuljs/load-nyc-config/node_modules/resolve-from": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", + "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/@istanbuljs/schema": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz", + "integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/@jest/create-cache-key-function": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/create-cache-key-function/-/create-cache-key-function-29.7.0.tgz", + "integrity": "sha512-4QqS3LY5PBmTRHj9sAg1HLoPzqAI0uOX6wI/TRqHIcOxlFidy6YEmCQJk6FSZjNLGCeubDMfmkWL+qaLKhSGQA==", + "license": "MIT", + "peer": true, + "dependencies": { + "@jest/types": "^29.6.3" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/@jest/environment": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.7.0.tgz", + "integrity": "sha512-aQIfHDq33ExsN4jP1NWGXhxgQ/wixs60gDiKO+XVMd8Mn0NWPWgc34ZQDTb2jKaUWQ7MuwoitXAsN2XVXNMpAw==", + "license": "MIT", + "peer": true, + "dependencies": { + "@jest/fake-timers": "^29.7.0", + "@jest/types": "^29.6.3", + "@types/node": "*", + "jest-mock": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -3164,6 +3450,7 @@ "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.7.0.tgz", "integrity": "sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==", "dev": true, + "license": "MIT", "dependencies": { "jest-get-type": "^29.6.3" }, @@ -3175,6 +3462,7 @@ "version": "29.7.0", "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.7.0.tgz", "integrity": "sha512-q4DH1Ha4TTFPdxLsqDXK1d3+ioSL7yL5oCMJZgDYm6i+6CygW5E5xVr/D1HdsGxjt1ZWSfUAs9OxSB/BNelWrQ==", + "license": "MIT", "peer": true, "dependencies": { "@jest/types": "^29.6.3", @@ -3192,6 +3480,7 @@ "version": "29.6.3", "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==", + "license": "MIT", "dependencies": { "@sinclair/typebox": "^0.27.8" }, @@ -3199,10 +3488,38 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/@jest/transform": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-29.7.0.tgz", + "integrity": "sha512-ok/BTPFzFKVMwO5eOHRrvnBVHdRy9IrsrW1GpMaQ9MCnilNLXQKmAX8s1YXDFaai9xJpac2ySzV0YeRRECr2Vw==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/core": "^7.11.6", + "@jest/types": "^29.6.3", + "@jridgewell/trace-mapping": "^0.3.18", + "babel-plugin-istanbul": "^6.1.1", + "chalk": "^4.0.0", + "convert-source-map": "^2.0.0", + "fast-json-stable-stringify": "^2.1.0", + "graceful-fs": "^4.2.9", + "jest-haste-map": "^29.7.0", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.7.0", + "micromatch": "^4.0.4", + "pirates": "^4.0.4", + "slash": "^3.0.0", + "write-file-atomic": "^4.0.2" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, "node_modules/@jest/types": { "version": "29.6.3", "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", + "license": "MIT", "dependencies": { "@jest/schemas": "^29.6.3", "@types/istanbul-lib-coverage": "^2.0.0", @@ -3219,6 +3536,7 @@ "version": "0.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", "integrity": "sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==", + "license": "MIT", "dependencies": { "@jridgewell/set-array": "^1.2.1", "@jridgewell/sourcemap-codec": "^1.4.10", @@ -3232,6 +3550,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", + "license": "MIT", "engines": { "node": ">=6.0.0" } @@ -3240,6 +3559,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz", "integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==", + "license": "MIT", "engines": { "node": ">=6.0.0" } @@ -3248,30 +3568,52 @@ "version": "0.3.6", "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.6.tgz", "integrity": "sha512-1ZJTZebgqllO79ue2bm3rIGud/bOe0pP5BjSRCRxxYkEZS8STV7zN84UBbiYu7jy+eCKSnVIUgoWWE/tt+shMQ==", + "license": "MIT", "dependencies": { "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25" } }, "node_modules/@jridgewell/sourcemap-codec": { - "version": "1.4.15", - "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.15.tgz", - "integrity": "sha512-eF2rxCRulEKXHTRiDrDy6erMYWqNw4LPdQ8UQA4huuxaQsVeRPFl2oM8oDGxMFhJUWZf9McpLtJasDDZb/Bpeg==" + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", + "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", + "license": "MIT" }, "node_modules/@jridgewell/trace-mapping": { "version": "0.3.25", "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", + "license": "MIT", "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@mswjs/interceptors": { + "version": "0.36.7", + "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.36.7.tgz", + "integrity": "sha512-sdx02Wlus5hv6Bx7uUDb25gb0WGjCuSgnJB2LVERemoSGuqkZMe3QI6nEXhieFGtYwPrZbYrT2vPbsFN2XfbUw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@open-draft/deferred-promise": "^2.2.0", + "@open-draft/logger": "^0.3.0", + "@open-draft/until": "^2.0.0", + "is-node-process": "^1.2.0", + "outvariant": "^1.4.3", + "strict-event-emitter": "^0.5.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", "integrity": "sha512-vq24Bq3ym5HEQm2NKCr3yXDwjc7vTsEThRDnkp2DK9p1uqLR+DHurm/NOTo0KG7HYHU7eppKZj3MyqYuMBf62g==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.stat": "2.0.5", "run-parallel": "^1.1.9" @@ -3285,6 +3627,7 @@ "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.5.tgz", "integrity": "sha512-RkhPPp2zrqDAQA/2jNhnztcPAlv64XdhIp7a7454A5ovI7Bukxgt7MX7udwAu3zg1DcpPU0rz3VV1SeaqvY4+A==", "dev": true, + "license": "MIT", "engines": { "node": ">= 8" } @@ -3294,6 +3637,7 @@ "resolved": "https://registry.npmjs.org/@nodelib/fs.walk/-/fs.walk-1.2.8.tgz", "integrity": "sha512-oGB+UxlgWcgQkgwo8GcEGwemoTFt3FIO9ababBmaGwXIoBKZ+GTy0pP185beGg7Llih/NSHSV2XAs1lnznocSg==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.scandir": "2.1.5", "fastq": "^1.6.0" @@ -3302,12 +3646,39 @@ "node": ">= 8" } }, + "node_modules/@open-draft/deferred-promise": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@open-draft/deferred-promise/-/deferred-promise-2.2.0.tgz", + "integrity": "sha512-CecwLWx3rhxVQF6V4bAgPS5t+So2sTbPgAzafKkVizyi7tlwpcFpdFqq+wqF2OwNBmqFuu6tOyouTuxgpMfzmA==", + "dev": true, + "license": "MIT" + }, + "node_modules/@open-draft/logger": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/@open-draft/logger/-/logger-0.3.0.tgz", + "integrity": "sha512-X2g45fzhxH238HKO4xbSr7+wBS8Fvw6ixhTDuvLd5mqh6bJJCFAPwU9mPDxbcrRtfxv4u5IHCEH77BmxvXmmxQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "is-node-process": "^1.2.0", + "outvariant": "^1.4.0" + } + }, + "node_modules/@open-draft/until": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/@open-draft/until/-/until-2.1.0.tgz", + "integrity": "sha512-U69T3ItWHvLwGg5eJ0n3I62nWuE6ilHlmz7zM0npLBRvPRd7e6NYmg54vvRtP5mZG7kZqZCFVdsTWo7BPtBujg==", + "dev": true, + "license": "MIT" + }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz", "integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==", "dev": true, + "license": "MIT", "optional": true, + "peer": true, "engines": { "node": ">=14" } @@ -3317,6 +3688,7 @@ "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", "dev": true, + "license": "MIT", "engines": { "node": "^12.20.0 || ^14.18.0 || >=16.0.0" }, @@ -3324,77 +3696,144 @@ "url": "https://opencollective.com/unts" } }, - "node_modules/@react-native-community/cli": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-12.3.6.tgz", - "integrity": "sha512-647OSi6xBb8FbwFqX9zsJxOzu685AWtrOUWHfOkbKD+5LOpGORw+GQo0F9rWZnB68rLQyfKUZWJeaD00pGv5fw==", + "node_modules/@react-native/assets-registry": { + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/assets-registry/-/assets-registry-0.76.1.tgz", + "integrity": "sha512-1mcDjyvC4Z+XYtY+Abl6pW9P49l/9HJmRChX7EHF1SoXe7zPAPBoAqeZsJNtf8dhJR3u/eGvapr1yJq8T/psEg==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=18" + } + }, + "node_modules/@react-native/babel-plugin-codegen": { + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/babel-plugin-codegen/-/babel-plugin-codegen-0.76.1.tgz", + "integrity": "sha512-V9bGLyEdAF39nvn4L5gaJcPX1SvCHPJhaT3qfpVGvCnl7WPhdRyCq++WsN8HXlpo6WOAf6//oruLnLdl3RNM4Q==", + "license": "MIT", "peer": true, "dependencies": { - "@react-native-community/cli-clean": "12.3.6", - "@react-native-community/cli-config": "12.3.6", - "@react-native-community/cli-debugger-ui": "12.3.6", - "@react-native-community/cli-doctor": "12.3.6", - "@react-native-community/cli-hermes": "12.3.6", - "@react-native-community/cli-plugin-metro": "12.3.6", - "@react-native-community/cli-server-api": "12.3.6", - "@react-native-community/cli-tools": "12.3.6", - "@react-native-community/cli-types": "12.3.6", - "chalk": "^4.1.2", - "commander": "^9.4.1", - "deepmerge": "^4.3.0", - "execa": "^5.0.0", - "find-up": "^4.1.0", - "fs-extra": "^8.1.0", - "graceful-fs": "^4.1.3", - "prompts": "^2.4.2", - "semver": "^7.5.2" - }, - "bin": { - "react-native": "build/bin.js" + "@react-native/codegen": "0.76.1" }, "engines": { "node": ">=18" } }, - "node_modules/@react-native-community/cli-clean": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-clean/-/cli-clean-12.3.6.tgz", - "integrity": "sha512-gUU29ep8xM0BbnZjwz9MyID74KKwutq9x5iv4BCr2im6nly4UMf1B1D+V225wR7VcDGzbgWjaezsJShLLhC5ig==", + "node_modules/@react-native/babel-preset": { + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/babel-preset/-/babel-preset-0.76.1.tgz", + "integrity": "sha512-b6YRmA13CmVuTQKHRen/Q0glHwmZFZoEDs+MJ1NL0UNHq9V5ytvdwTW1ntkmjtXuTnPMzkwYvumJBN9UTZjkBA==", + "license": "MIT", "peer": true, "dependencies": { - "@react-native-community/cli-tools": "12.3.6", - "chalk": "^4.1.2", - "execa": "^5.0.0" + "@babel/core": "^7.25.2", + "@babel/plugin-proposal-export-default-from": "^7.24.7", + "@babel/plugin-syntax-dynamic-import": "^7.8.3", + "@babel/plugin-syntax-export-default-from": "^7.24.7", + "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3", + "@babel/plugin-syntax-optional-chaining": "^7.8.3", + "@babel/plugin-transform-arrow-functions": "^7.24.7", + "@babel/plugin-transform-async-generator-functions": "^7.25.4", + "@babel/plugin-transform-async-to-generator": "^7.24.7", + "@babel/plugin-transform-block-scoping": "^7.25.0", + "@babel/plugin-transform-class-properties": "^7.25.4", + "@babel/plugin-transform-classes": "^7.25.4", + "@babel/plugin-transform-computed-properties": "^7.24.7", + "@babel/plugin-transform-destructuring": "^7.24.8", + "@babel/plugin-transform-flow-strip-types": "^7.25.2", + "@babel/plugin-transform-for-of": "^7.24.7", + "@babel/plugin-transform-function-name": "^7.25.1", + "@babel/plugin-transform-literals": "^7.25.2", + "@babel/plugin-transform-logical-assignment-operators": "^7.24.7", + "@babel/plugin-transform-modules-commonjs": "^7.24.8", + "@babel/plugin-transform-named-capturing-groups-regex": "^7.24.7", + "@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7", + "@babel/plugin-transform-numeric-separator": "^7.24.7", + "@babel/plugin-transform-object-rest-spread": "^7.24.7", + "@babel/plugin-transform-optional-catch-binding": "^7.24.7", + "@babel/plugin-transform-optional-chaining": "^7.24.8", + "@babel/plugin-transform-parameters": "^7.24.7", + "@babel/plugin-transform-private-methods": "^7.24.7", + "@babel/plugin-transform-private-property-in-object": "^7.24.7", + "@babel/plugin-transform-react-display-name": "^7.24.7", + "@babel/plugin-transform-react-jsx": "^7.25.2", + "@babel/plugin-transform-react-jsx-self": "^7.24.7", + "@babel/plugin-transform-react-jsx-source": "^7.24.7", + "@babel/plugin-transform-regenerator": "^7.24.7", + "@babel/plugin-transform-runtime": "^7.24.7", + "@babel/plugin-transform-shorthand-properties": "^7.24.7", + "@babel/plugin-transform-spread": "^7.24.7", + "@babel/plugin-transform-sticky-regex": "^7.24.7", + "@babel/plugin-transform-typescript": "^7.25.2", + "@babel/plugin-transform-unicode-regex": "^7.24.7", + "@babel/template": "^7.25.0", + "@react-native/babel-plugin-codegen": "0.76.1", + "babel-plugin-syntax-hermes-parser": "^0.23.1", + "babel-plugin-transform-flow-enums": "^0.0.2", + "react-refresh": "^0.14.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@babel/core": "*" } }, - "node_modules/@react-native-community/cli-config": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-config/-/cli-config-12.3.6.tgz", - "integrity": "sha512-JGWSYQ9EAK6m2v0abXwFLEfsqJ1zkhzZ4CV261QZF9MoUNB6h57a274h1MLQR9mG6Tsh38wBUuNfEPUvS1vYew==", + "node_modules/@react-native/codegen": { + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/codegen/-/codegen-0.76.1.tgz", + "integrity": "sha512-7lE0hk2qq27wVeK5eF654v7XsKoRa7ficrfSwIDEDZ1aLB2xgUzLrsq+glSAP9EuzT6ycHhtD3QyqI+TqnlS/A==", + "license": "MIT", "peer": true, "dependencies": { - "@react-native-community/cli-tools": "12.3.6", - "chalk": "^4.1.2", - "cosmiconfig": "^5.1.0", - "deepmerge": "^4.3.0", - "glob": "^7.1.3", - "joi": "^17.2.1" + "@babel/parser": "^7.25.3", + "glob": "^7.1.1", + "hermes-parser": "0.23.1", + "invariant": "^2.2.4", + "jscodeshift": "^0.14.0", + "mkdirp": "^0.5.1", + "nullthrows": "^1.1.1", + "yargs": "^17.6.2" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@babel/preset-env": "^7.1.6" } }, - "node_modules/@react-native-community/cli-config/node_modules/brace-expansion": { + "node_modules/@react-native/codegen/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "license": "MIT", "peer": true, "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, - "node_modules/@react-native-community/cli-config/node_modules/glob": { + "node_modules/@react-native/codegen/node_modules/cliui": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", + "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "license": "ISC", + "peer": true, + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.1", + "wrap-ansi": "^7.0.0" + }, + "engines": { + "node": ">=12" + } + }, + "node_modules/@react-native/codegen/node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "license": "ISC", "peer": true, "dependencies": { "fs.realpath": "^1.0.0", @@ -3411,10 +3850,11 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/@react-native-community/cli-config/node_modules/minimatch": { + "node_modules/@react-native/codegen/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "license": "ISC", "peer": true, "dependencies": { "brace-expansion": "^1.1.7" @@ -3423,699 +3863,145 @@ "node": "*" } }, - "node_modules/@react-native-community/cli-debugger-ui": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-debugger-ui/-/cli-debugger-ui-12.3.6.tgz", - "integrity": "sha512-SjUKKsx5FmcK9G6Pb6UBFT0s9JexVStK5WInmANw75Hm7YokVvHEgtprQDz2Uvy5znX5g2ujzrkIU//T15KQzA==", - "peer": true, - "dependencies": { - "serve-static": "^1.13.1" - } - }, - "node_modules/@react-native-community/cli-doctor": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-doctor/-/cli-doctor-12.3.6.tgz", - "integrity": "sha512-fvBDv2lTthfw4WOQKkdTop2PlE9GtfrlNnpjB818MhcdEnPjfQw5YaTUcnNEGsvGomdCs1MVRMgYXXwPSN6OvQ==", - "peer": true, - "dependencies": { - "@react-native-community/cli-config": "12.3.6", - "@react-native-community/cli-platform-android": "12.3.6", - "@react-native-community/cli-platform-ios": "12.3.6", - "@react-native-community/cli-tools": "12.3.6", - "chalk": "^4.1.2", - "command-exists": "^1.2.8", - "deepmerge": "^4.3.0", - "envinfo": "^7.10.0", - "execa": "^5.0.0", - "hermes-profile-transformer": "^0.0.6", - "node-stream-zip": "^1.9.1", - "ora": "^5.4.1", - "semver": "^7.5.2", - "strip-ansi": "^5.2.0", - "wcwidth": "^1.0.1", - "yaml": "^2.2.1" - } - }, - "node_modules/@react-native-community/cli-doctor/node_modules/strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "node_modules/@react-native/codegen/node_modules/yargs": { + "version": "17.7.2", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", + "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "license": "MIT", "peer": true, "dependencies": { - "ansi-regex": "^4.1.0" + "cliui": "^8.0.1", + "escalade": "^3.1.1", + "get-caller-file": "^2.0.5", + "require-directory": "^2.1.1", + "string-width": "^4.2.3", + "y18n": "^5.0.5", + "yargs-parser": "^21.1.1" }, "engines": { - "node": ">=6" + "node": ">=12" } }, - "node_modules/@react-native-community/cli-hermes": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-hermes/-/cli-hermes-12.3.6.tgz", - "integrity": "sha512-sNGwfOCl8OAIjWCkwuLpP8NZbuO0dhDI/2W7NeOGDzIBsf4/c4MptTrULWtGIH9okVPLSPX0NnRyGQ+mSwWyuQ==", + "node_modules/@react-native/codegen/node_modules/yargs-parser": { + "version": "21.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", + "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "license": "ISC", "peer": true, - "dependencies": { - "@react-native-community/cli-platform-android": "12.3.6", - "@react-native-community/cli-tools": "12.3.6", - "chalk": "^4.1.2", - "hermes-profile-transformer": "^0.0.6" + "engines": { + "node": ">=12" } }, - "node_modules/@react-native-community/cli-platform-android": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-platform-android/-/cli-platform-android-12.3.6.tgz", - "integrity": "sha512-DeDDAB8lHpuGIAPXeeD9Qu2+/wDTFPo99c8uSW49L0hkmZJixzvvvffbGQAYk32H0TmaI7rzvzH+qzu7z3891g==", + "node_modules/@react-native/community-cli-plugin": { + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/community-cli-plugin/-/community-cli-plugin-0.76.1.tgz", + "integrity": "sha512-dECc1LuleMQDX/WK2oJInrYCpHb3OFBJxYkhPOAXb9HiktMWRA9T93qqpTDshmtLdYqvxeO9AM5eeoSL412WnQ==", + "license": "MIT", "peer": true, "dependencies": { - "@react-native-community/cli-tools": "12.3.6", - "chalk": "^4.1.2", - "execa": "^5.0.0", - "fast-xml-parser": "^4.2.4", - "glob": "^7.1.3", - "logkitty": "^0.7.1" + "@react-native/dev-middleware": "0.76.1", + "@react-native/metro-babel-transformer": "0.76.1", + "chalk": "^4.0.0", + "execa": "^5.1.1", + "invariant": "^2.2.4", + "metro": "^0.81.0", + "metro-config": "^0.81.0", + "metro-core": "^0.81.0", + "node-fetch": "^2.2.0", + "readline": "^1.3.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@react-native-community/cli-server-api": "*" + }, + "peerDependenciesMeta": { + "@react-native-community/cli-server-api": { + "optional": true + } } }, - "node_modules/@react-native-community/cli-platform-android/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "node_modules/@react-native/debugger-frontend": { + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/debugger-frontend/-/debugger-frontend-0.76.1.tgz", + "integrity": "sha512-0gExx7GR8o2ctGfjIZ9+x54iFbg0eP6+kMYzRA6AcgmFAmMGLADMmjtObCN0CqGeZyWtdVVqcv5mAwRwmMlNWA==", + "license": "BSD-3-Clause", "peer": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" + "engines": { + "node": ">=18" } }, - "node_modules/@react-native-community/cli-platform-android/node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "node_modules/@react-native/dev-middleware": { + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/dev-middleware/-/dev-middleware-0.76.1.tgz", + "integrity": "sha512-htaFSN2dwI0CinsMxjRuvIVdSDN6d6TDPeOJczM1bdAYalZX1M58knTKs5LJDComW5tleOCAg5lS5tIeFlM9+Q==", + "license": "MIT", "peer": true, "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "@isaacs/ttlcache": "^1.4.1", + "@react-native/debugger-frontend": "0.76.1", + "chrome-launcher": "^0.15.2", + "chromium-edge-launcher": "^0.2.0", + "connect": "^3.6.5", + "debug": "^2.2.0", + "nullthrows": "^1.1.1", + "open": "^7.0.3", + "selfsigned": "^2.4.1", + "serve-static": "^1.13.1", + "ws": "^6.2.3" }, "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "node": ">=18" } }, - "node_modules/@react-native-community/cli-platform-android/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "node_modules/@react-native/dev-middleware/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", "peer": true, "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/@react-native-community/cli-platform-ios": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-platform-ios/-/cli-platform-ios-12.3.6.tgz", - "integrity": "sha512-3eZ0jMCkKUO58wzPWlvAPRqezVKm9EPZyaPyHbRPWU8qw7JqkvnRlWIaYDGpjCJgVW4k2hKsEursLtYKb188tg==", - "peer": true, - "dependencies": { - "@react-native-community/cli-tools": "12.3.6", - "chalk": "^4.1.2", - "execa": "^5.0.0", - "fast-xml-parser": "^4.0.12", - "glob": "^7.1.3", - "ora": "^5.4.1" - } - }, - "node_modules/@react-native-community/cli-platform-ios/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "peer": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/@react-native-community/cli-platform-ios/node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "peer": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/@react-native-community/cli-platform-ios/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "peer": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/@react-native-community/cli-plugin-metro": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-plugin-metro/-/cli-plugin-metro-12.3.6.tgz", - "integrity": "sha512-3jxSBQt4fkS+KtHCPSyB5auIT+KKIrPCv9Dk14FbvOaEh9erUWEm/5PZWmtboW1z7CYeNbFMeXm9fM2xwtVOpg==", - "peer": true - }, - "node_modules/@react-native-community/cli-server-api": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-server-api/-/cli-server-api-12.3.6.tgz", - "integrity": "sha512-80NIMzo8b2W+PL0Jd7NjiJW9mgaT8Y8wsIT/lh6mAvYH7mK0ecDJUYUTAAv79Tbo1iCGPAr3T295DlVtS8s4yQ==", - "peer": true, - "dependencies": { - "@react-native-community/cli-debugger-ui": "12.3.6", - "@react-native-community/cli-tools": "12.3.6", - "compression": "^1.7.1", - "connect": "^3.6.5", - "errorhandler": "^1.5.1", - "nocache": "^3.0.1", - "pretty-format": "^26.6.2", - "serve-static": "^1.13.1", - "ws": "^7.5.1" - } - }, - "node_modules/@react-native-community/cli-server-api/node_modules/@jest/types": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", - "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", - "peer": true, - "dependencies": { - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^15.0.0", - "chalk": "^4.0.0" - }, - "engines": { - "node": ">= 10.14.2" - } - }, - "node_modules/@react-native-community/cli-server-api/node_modules/@types/yargs": { - "version": "15.0.19", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.19.tgz", - "integrity": "sha512-2XUaGVmyQjgyAZldf0D0c14vvo/yv0MhQBSTJcejMMaitsn3nxCB6TmH4G0ZQf+uxROOa9mpanoSm8h6SG/1ZA==", - "peer": true, - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/@react-native-community/cli-server-api/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "peer": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/@react-native-community/cli-server-api/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "peer": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/@react-native-community/cli-server-api/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "peer": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/@react-native-community/cli-server-api/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "peer": true - }, - "node_modules/@react-native-community/cli-server-api/node_modules/pretty-format": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", - "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", - "peer": true, - "dependencies": { - "@jest/types": "^26.6.2", - "ansi-regex": "^5.0.0", - "ansi-styles": "^4.0.0", - "react-is": "^17.0.1" - }, - "engines": { - "node": ">= 10" - } - }, - "node_modules/@react-native-community/cli-server-api/node_modules/react-is": { - "version": "17.0.2", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", - "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", - "peer": true - }, - "node_modules/@react-native-community/cli-server-api/node_modules/ws": { - "version": "7.5.9", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", - "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", - "peer": true, - "engines": { - "node": ">=8.3.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } - } - }, - "node_modules/@react-native-community/cli-tools": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-tools/-/cli-tools-12.3.6.tgz", - "integrity": "sha512-FPEvZn19UTMMXUp/piwKZSh8cMEfO8G3KDtOwo53O347GTcwNrKjgZGtLSPELBX2gr+YlzEft3CoRv2Qmo83fQ==", - "peer": true, - "dependencies": { - "appdirsjs": "^1.2.4", - "chalk": "^4.1.2", - "find-up": "^5.0.0", - "mime": "^2.4.1", - "node-fetch": "^2.6.0", - "open": "^6.2.0", - "ora": "^5.4.1", - "semver": "^7.5.2", - "shell-quote": "^1.7.3", - "sudo-prompt": "^9.0.0" - } - }, - "node_modules/@react-native-community/cli-types": { - "version": "12.3.6", - "resolved": "https://registry.npmjs.org/@react-native-community/cli-types/-/cli-types-12.3.6.tgz", - "integrity": "sha512-xPqTgcUtZowQ8WKOkI9TLGBwH2bGggOC4d2FFaIRST3gTcjrEeGRNeR5aXCzJFIgItIft8sd7p2oKEdy90+01Q==", - "peer": true, - "dependencies": { - "joi": "^17.2.1" - } - }, - "node_modules/@react-native-community/cli/node_modules/commander": { - "version": "9.5.0", - "resolved": "https://registry.npmjs.org/commander/-/commander-9.5.0.tgz", - "integrity": "sha512-KRs7WVDKg86PWiuAqhDrAQnTXZKraVcCc6vFdL14qrZ/DcWwuRo7VoiYXalXO7S5GKpqYiVEwCbgFDfxNHKJBQ==", - "peer": true, - "engines": { - "node": "^12.20.0 || >=14" - } - }, - "node_modules/@react-native-community/cli/node_modules/find-up": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", - "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", - "peer": true, - "dependencies": { - "locate-path": "^5.0.0", - "path-exists": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/@react-native-community/cli/node_modules/fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", - "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", - "peer": true, - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" - }, - "engines": { - "node": ">=6 <7 || >=8" - } - }, - "node_modules/@react-native-community/cli/node_modules/jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", - "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", - "peer": true, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/@react-native-community/cli/node_modules/locate-path": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", - "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "peer": true, - "dependencies": { - "p-locate": "^4.1.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/@react-native-community/cli/node_modules/p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", - "peer": true, - "dependencies": { - "p-try": "^2.0.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/@react-native-community/cli/node_modules/p-locate": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", - "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "peer": true, - "dependencies": { - "p-limit": "^2.2.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/@react-native-community/cli/node_modules/universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "peer": true, - "engines": { - "node": ">= 4.0.0" - } - }, - "node_modules/@react-native/assets-registry": { - "version": "0.73.1", - "resolved": "https://registry.npmjs.org/@react-native/assets-registry/-/assets-registry-0.73.1.tgz", - "integrity": "sha512-2FgAbU7uKM5SbbW9QptPPZx8N9Ke2L7bsHb+EhAanZjFZunA9PaYtyjUQ1s7HD+zDVqOQIvjkpXSv7Kejd2tqg==", - "peer": true, - "engines": { - "node": ">=18" - } - }, - "node_modules/@react-native/babel-plugin-codegen": { - "version": "0.73.4", - "resolved": "https://registry.npmjs.org/@react-native/babel-plugin-codegen/-/babel-plugin-codegen-0.73.4.tgz", - "integrity": "sha512-XzRd8MJGo4Zc5KsphDHBYJzS1ryOHg8I2gOZDAUCGcwLFhdyGu1zBNDJYH2GFyDrInn9TzAbRIf3d4O+eltXQQ==", - "peer": true, - "dependencies": { - "@react-native/codegen": "0.73.3" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/@react-native/babel-preset": { - "version": "0.73.21", - "resolved": "https://registry.npmjs.org/@react-native/babel-preset/-/babel-preset-0.73.21.tgz", - "integrity": "sha512-WlFttNnySKQMeujN09fRmrdWqh46QyJluM5jdtDNrkl/2Hx6N4XeDUGhABvConeK95OidVO7sFFf7sNebVXogA==", - "peer": true, - "dependencies": { - "@babel/core": "^7.20.0", - "@babel/plugin-proposal-async-generator-functions": "^7.0.0", - "@babel/plugin-proposal-class-properties": "^7.18.0", - "@babel/plugin-proposal-export-default-from": "^7.0.0", - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.0", - "@babel/plugin-proposal-numeric-separator": "^7.0.0", - "@babel/plugin-proposal-object-rest-spread": "^7.20.0", - "@babel/plugin-proposal-optional-catch-binding": "^7.0.0", - "@babel/plugin-proposal-optional-chaining": "^7.20.0", - "@babel/plugin-syntax-dynamic-import": "^7.8.0", - "@babel/plugin-syntax-export-default-from": "^7.0.0", - "@babel/plugin-syntax-flow": "^7.18.0", - "@babel/plugin-syntax-nullish-coalescing-operator": "^7.0.0", - "@babel/plugin-syntax-optional-chaining": "^7.0.0", - "@babel/plugin-transform-arrow-functions": "^7.0.0", - "@babel/plugin-transform-async-to-generator": "^7.20.0", - "@babel/plugin-transform-block-scoping": "^7.0.0", - "@babel/plugin-transform-classes": "^7.0.0", - "@babel/plugin-transform-computed-properties": "^7.0.0", - "@babel/plugin-transform-destructuring": "^7.20.0", - "@babel/plugin-transform-flow-strip-types": "^7.20.0", - "@babel/plugin-transform-function-name": "^7.0.0", - "@babel/plugin-transform-literals": "^7.0.0", - "@babel/plugin-transform-modules-commonjs": "^7.0.0", - "@babel/plugin-transform-named-capturing-groups-regex": "^7.0.0", - "@babel/plugin-transform-parameters": "^7.0.0", - "@babel/plugin-transform-private-methods": "^7.22.5", - "@babel/plugin-transform-private-property-in-object": "^7.22.11", - "@babel/plugin-transform-react-display-name": "^7.0.0", - "@babel/plugin-transform-react-jsx": "^7.0.0", - "@babel/plugin-transform-react-jsx-self": "^7.0.0", - "@babel/plugin-transform-react-jsx-source": "^7.0.0", - "@babel/plugin-transform-runtime": "^7.0.0", - "@babel/plugin-transform-shorthand-properties": "^7.0.0", - "@babel/plugin-transform-spread": "^7.0.0", - "@babel/plugin-transform-sticky-regex": "^7.0.0", - "@babel/plugin-transform-typescript": "^7.5.0", - "@babel/plugin-transform-unicode-regex": "^7.0.0", - "@babel/template": "^7.0.0", - "@react-native/babel-plugin-codegen": "0.73.4", - "babel-plugin-transform-flow-enums": "^0.0.2", - "react-refresh": "^0.14.0" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "@babel/core": "*" - } - }, - "node_modules/@react-native/codegen": { - "version": "0.73.3", - "resolved": "https://registry.npmjs.org/@react-native/codegen/-/codegen-0.73.3.tgz", - "integrity": "sha512-sxslCAAb8kM06vGy9Jyh4TtvjhcP36k/rvj2QE2Jdhdm61KvfafCATSIsOfc0QvnduWFcpXUPvAVyYwuv7PYDg==", - "peer": true, - "dependencies": { - "@babel/parser": "^7.20.0", - "flow-parser": "^0.206.0", - "glob": "^7.1.1", - "invariant": "^2.2.4", - "jscodeshift": "^0.14.0", - "mkdirp": "^0.5.1", - "nullthrows": "^1.1.1" - }, - "engines": { - "node": ">=18" - }, - "peerDependencies": { - "@babel/preset-env": "^7.1.6" - } - }, - "node_modules/@react-native/codegen/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "peer": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/@react-native/codegen/node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "peer": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/@react-native/codegen/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "peer": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/@react-native/codegen/node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "peer": true, - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, - "node_modules/@react-native/community-cli-plugin": { - "version": "0.73.17", - "resolved": "https://registry.npmjs.org/@react-native/community-cli-plugin/-/community-cli-plugin-0.73.17.tgz", - "integrity": "sha512-F3PXZkcHg+1ARIr6FRQCQiB7ZAA+MQXGmq051metRscoLvgYJwj7dgC8pvgy0kexzUkHu5BNKrZeySzUft3xuQ==", - "peer": true, - "dependencies": { - "@react-native-community/cli-server-api": "12.3.6", - "@react-native-community/cli-tools": "12.3.6", - "@react-native/dev-middleware": "0.73.8", - "@react-native/metro-babel-transformer": "0.73.15", - "chalk": "^4.0.0", - "execa": "^5.1.1", - "metro": "^0.80.3", - "metro-config": "^0.80.3", - "metro-core": "^0.80.3", - "node-fetch": "^2.2.0", - "readline": "^1.3.0" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/@react-native/debugger-frontend": { - "version": "0.73.3", - "resolved": "https://registry.npmjs.org/@react-native/debugger-frontend/-/debugger-frontend-0.73.3.tgz", - "integrity": "sha512-RgEKnWuoo54dh7gQhV7kvzKhXZEhpF9LlMdZolyhGxHsBqZ2gXdibfDlfcARFFifPIiaZ3lXuOVVa4ei+uPgTw==", - "peer": true, - "engines": { - "node": ">=18" - } - }, - "node_modules/@react-native/dev-middleware": { - "version": "0.73.8", - "resolved": "https://registry.npmjs.org/@react-native/dev-middleware/-/dev-middleware-0.73.8.tgz", - "integrity": "sha512-oph4NamCIxkMfUL/fYtSsE+JbGOnrlawfQ0kKtDQ5xbOjPKotKoXqrs1eGwozNKv7FfQ393stk1by9a6DyASSg==", - "peer": true, - "dependencies": { - "@isaacs/ttlcache": "^1.4.1", - "@react-native/debugger-frontend": "0.73.3", - "chrome-launcher": "^0.15.2", - "chromium-edge-launcher": "^1.0.0", - "connect": "^3.6.5", - "debug": "^2.2.0", - "node-fetch": "^2.2.0", - "open": "^7.0.3", - "serve-static": "^1.13.1", - "temp-dir": "^2.0.0", - "ws": "^6.2.2" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/@react-native/dev-middleware/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "peer": true, - "dependencies": { - "ms": "2.0.0" + "ms": "2.0.0" } }, "node_modules/@react-native/dev-middleware/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT", "peer": true }, - "node_modules/@react-native/dev-middleware/node_modules/open": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz", - "integrity": "sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==", - "peer": true, - "dependencies": { - "is-docker": "^2.0.0", - "is-wsl": "^2.1.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/@react-native/dev-middleware/node_modules/ws": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", - "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", - "peer": true, - "dependencies": { - "async-limiter": "~1.0.0" - } - }, "node_modules/@react-native/gradle-plugin": { - "version": "0.73.4", - "resolved": "https://registry.npmjs.org/@react-native/gradle-plugin/-/gradle-plugin-0.73.4.tgz", - "integrity": "sha512-PMDnbsZa+tD55Ug+W8CfqXiGoGneSSyrBZCMb5JfiB3AFST3Uj5e6lw8SgI/B6SKZF7lG0BhZ6YHZsRZ5MlXmg==", + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/gradle-plugin/-/gradle-plugin-0.76.1.tgz", + "integrity": "sha512-X7rNFltPa9QYxvYrQGaSCw7U57C+y+DwspXf4AnLZj0bQm9tL6UYpijh5vE3VmPcHn76/RNU2bpFjVvWg6gjqw==", + "license": "MIT", "peer": true, "engines": { "node": ">=18" } }, "node_modules/@react-native/js-polyfills": { - "version": "0.73.1", - "resolved": "https://registry.npmjs.org/@react-native/js-polyfills/-/js-polyfills-0.73.1.tgz", - "integrity": "sha512-ewMwGcumrilnF87H4jjrnvGZEaPFCAC4ebraEK+CurDDmwST/bIicI4hrOAv+0Z0F7DEK4O4H7r8q9vH7IbN4g==", + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/js-polyfills/-/js-polyfills-0.76.1.tgz", + "integrity": "sha512-HO3fzJ0FnrnQGmxdXxh2lcGGAMfaX9h1Pg1Zh38MkVw35/KnZHxHqxg6cruze6iWwZdfqSoIcQoalmMuAHby7Q==", + "license": "MIT", "peer": true, "engines": { "node": ">=18" } }, "node_modules/@react-native/metro-babel-transformer": { - "version": "0.73.15", - "resolved": "https://registry.npmjs.org/@react-native/metro-babel-transformer/-/metro-babel-transformer-0.73.15.tgz", - "integrity": "sha512-LlkSGaXCz+xdxc9819plmpsl4P4gZndoFtpjN3GMBIu6f7TBV0GVbyJAU4GE8fuAWPVSVL5ArOcdkWKSbI1klw==", + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/metro-babel-transformer/-/metro-babel-transformer-0.76.1.tgz", + "integrity": "sha512-LUAKqgsrioXS2a+pE0jak8sutTbLo3T34KWv7mdVUZ5lUACpqkIql1EFtIQlWjIcR4oZE480CkPbRHBI681tkQ==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/core": "^7.20.0", - "@react-native/babel-preset": "0.73.21", - "hermes-parser": "0.15.0", + "@babel/core": "^7.25.2", + "@react-native/babel-preset": "0.76.1", + "hermes-parser": "0.23.1", "nullthrows": "^1.1.1" }, "engines": { @@ -4126,15 +4012,17 @@ } }, "node_modules/@react-native/normalize-colors": { - "version": "0.73.2", - "resolved": "https://registry.npmjs.org/@react-native/normalize-colors/-/normalize-colors-0.73.2.tgz", - "integrity": "sha512-bRBcb2T+I88aG74LMVHaKms2p/T8aQd8+BZ7LuuzXlRfog1bMWWn/C5i0HVuvW4RPtXQYgIlGiXVDy9Ir1So/w==", + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/normalize-colors/-/normalize-colors-0.76.1.tgz", + "integrity": "sha512-/+CUk/wGWIdXbJYVLw/q6Fs8Z0x91zzfXIbNiZUdSW1TNEDmytkF371H8a1/Nx3nWa1RqCMVsaZHCG4zqxeDvg==", + "license": "MIT", "peer": true }, "node_modules/@react-native/virtualized-lists": { - "version": "0.73.4", - "resolved": "https://registry.npmjs.org/@react-native/virtualized-lists/-/virtualized-lists-0.73.4.tgz", - "integrity": "sha512-HpmLg1FrEiDtrtAbXiwCgXFYyloK/dOIPIuWW3fsqukwJEWAiTzm1nXGJ7xPU5XTHiWZ4sKup5Ebaj8z7iyWog==", + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/@react-native/virtualized-lists/-/virtualized-lists-0.76.1.tgz", + "integrity": "sha512-uWJfv0FC3zmlYORr0Sa17ngbAaw6K9yw4MAkBZyFeTM+W6AJRvTVyR1Mes/MU+vIyGFChnTcyaQrQz8jWqADOA==", + "license": "MIT", "peer": true, "dependencies": { "invariant": "^2.2.4", @@ -4144,14 +4032,22 @@ "node": ">=18" }, "peerDependencies": { + "@types/react": "^18.2.6", + "react": "*", "react-native": "*" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } } }, "node_modules/@rollup/plugin-commonjs": { - "version": "25.0.7", - "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.7.tgz", - "integrity": "sha512-nEvcR+LRjEjsaSsc4x3XZfCCvZIaSMenZu/OiwOKGN2UhQpAYI7ru7czFvyWbErlpoGjnSX3D5Ch5FcMA3kRWQ==", + "version": "25.0.8", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-25.0.8.tgz", + "integrity": "sha512-ZEZWTK5n6Qde0to4vS9Mr5x/0UZoqCxPVR9KRUjU4kA2sO7GEUn1fop0DAwpO6z0Nw/kJON9bDmSxdWxO/TT1A==", "dev": true, + "license": "MIT", "dependencies": { "@rollup/pluginutils": "^5.0.1", "commondir": "^1.0.1", @@ -4172,42 +4068,12 @@ } } }, - "node_modules/@rollup/plugin-commonjs/node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/@rollup/plugin-commonjs/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/@rollup/plugin-json": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.1.0.tgz", "integrity": "sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==", "dev": true, + "license": "MIT", "dependencies": { "@rollup/pluginutils": "^5.1.0" }, @@ -4224,15 +4090,15 @@ } }, "node_modules/@rollup/plugin-node-resolve": { - "version": "15.2.3", - "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.3.tgz", - "integrity": "sha512-j/lym8nf5E21LwBT4Df1VD6hRO2L2iwUeUmP7litikRsVp1H6NWx20NEp0Y7su+7XGc476GnXXc4kFeZNGmaSQ==", + "version": "15.3.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.3.0.tgz", + "integrity": "sha512-9eO5McEICxMzJpDW9OnMYSv4Sta3hmt7VtBFz5zR9273suNOydOyq/FrGeGy+KsTRFm8w0SLVhzig2ILFT63Ag==", "dev": true, + "license": "MIT", "dependencies": { "@rollup/pluginutils": "^5.0.1", "@types/resolve": "1.20.2", "deepmerge": "^4.2.2", - "is-builtin-module": "^3.2.1", "is-module": "^1.0.0", "resolve": "^1.22.1" }, @@ -4249,10 +4115,11 @@ } }, "node_modules/@rollup/plugin-replace": { - "version": "5.0.5", - "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.5.tgz", - "integrity": "sha512-rYO4fOi8lMaTg/z5Jb+hKnrHHVn8j2lwkqwyS4kTRhKyWOLf2wST2sWXr4WzWiTcoHTp2sTjqUbqIj2E39slKQ==", + "version": "5.0.7", + "resolved": "https://registry.npmjs.org/@rollup/plugin-replace/-/plugin-replace-5.0.7.tgz", + "integrity": "sha512-PqxSfuorkHz/SPpyngLyg5GCEkOcee9M1bkxiVDr41Pd61mqP1PLOoDPbpl44SB2mQGKwV/In74gqQmGITOhEQ==", "dev": true, + "license": "MIT", "dependencies": { "@rollup/pluginutils": "^5.0.1", "magic-string": "^0.30.3" @@ -4274,6 +4141,7 @@ "resolved": "https://registry.npmjs.org/@rollup/plugin-terser/-/plugin-terser-0.4.4.tgz", "integrity": "sha512-XHeJC5Bgvs8LfukDwWZp7yeqin6ns8RTl2B9avbejt6tZqsqvVoWI7ZTQrcNsfKEDWBTnTxM8nMDkO2IFFbd0A==", "dev": true, + "license": "MIT", "dependencies": { "serialize-javascript": "^6.0.1", "smob": "^1.0.0", @@ -4296,6 +4164,7 @@ "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz", "integrity": "sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA==", "dev": true, + "license": "MIT", "dependencies": { "@rollup/pluginutils": "^5.1.0", "resolve": "^1.22.1" @@ -4318,14 +4187,15 @@ } }, "node_modules/@rollup/pluginutils": { - "version": "5.1.0", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", - "integrity": "sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==", + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.3.tgz", + "integrity": "sha512-Pnsb6f32CD2W3uCaLZIzDmeFyQ2b8UWMFI7xtwUezpcGBDVDW6y9XgAWIlARiGAo6eNF5FK5aQTr0LFyNyqq5A==", "dev": true, + "license": "MIT", "dependencies": { "@types/estree": "^1.0.0", "estree-walker": "^2.0.2", - "picomatch": "^2.3.1" + "picomatch": "^4.0.2" }, "engines": { "node": ">=14.0.0" @@ -4340,304 +4210,349 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.14.3.tgz", - "integrity": "sha512-X9alQ3XM6I9IlSlmC8ddAvMSyG1WuHk5oUnXGw+yUBs3BFoTizmG1La/Gr8fVJvDWAq+zlYTZ9DBgrlKRVY06g==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.22.4.tgz", + "integrity": "sha512-Fxamp4aEZnfPOcGA8KSNEohV8hX7zVHOemC8jVBoBUHu5zpJK/Eu3uJwt6BMgy9fkvzxDaurgj96F/NiLukF2w==", "cpu": [ "arm" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "android" ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.14.3.tgz", - "integrity": "sha512-eQK5JIi+POhFpzk+LnjKIy4Ks+pwJ+NXmPxOCSvOKSNRPONzKuUvWE+P9JxGZVxrtzm6BAYMaL50FFuPe0oWMQ==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.22.4.tgz", + "integrity": "sha512-VXoK5UMrgECLYaMuGuVTOx5kcuap1Jm8g/M83RnCHBKOqvPPmROFJGQaZhGccnsFtfXQ3XYa4/jMCJvZnbJBdA==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "android" ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.14.3.tgz", - "integrity": "sha512-Od4vE6f6CTT53yM1jgcLqNfItTsLt5zE46fdPaEmeFHvPs5SjZYlLpHrSiHEKR1+HdRfxuzXHjDOIxQyC3ptBA==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.22.4.tgz", + "integrity": "sha512-xMM9ORBqu81jyMKCDP+SZDhnX2QEVQzTcC6G18KlTQEzWK8r/oNZtKuZaCcHhnsa6fEeOBionoyl5JsAbE/36Q==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "darwin" ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.14.3.tgz", - "integrity": "sha512-0IMAO21axJeNIrvS9lSe/PGthc8ZUS+zC53O0VhF5gMxfmcKAP4ESkKOCwEi6u2asUrt4mQv2rjY8QseIEb1aw==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.22.4.tgz", + "integrity": "sha512-aJJyYKQwbHuhTUrjWjxEvGnNNBCnmpHDvrb8JFDbeSH3m2XdHcxDd3jthAzvmoI8w/kSjd2y0udT+4okADsZIw==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "darwin" ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.14.3.tgz", - "integrity": "sha512-ge2DC7tHRHa3caVEoSbPRJpq7azhG+xYsd6u2MEnJ6XzPSzQsTKyXvh6iWjXRf7Rt9ykIUWHtl0Uz3T6yXPpKw==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.22.4.tgz", + "integrity": "sha512-j63YtCIRAzbO+gC2L9dWXRh5BFetsv0j0va0Wi9epXDgU/XUi5dJKo4USTttVyK7fGw2nPWK0PbAvyliz50SCQ==", "cpu": [ "arm" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-arm-musleabihf": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.14.3.tgz", - "integrity": "sha512-ljcuiDI4V3ySuc7eSk4lQ9wU8J8r8KrOUvB2U+TtK0TiW6OFDmJ+DdIjjwZHIw9CNxzbmXY39wwpzYuFDwNXuw==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.22.4.tgz", + "integrity": "sha512-dJnWUgwWBX1YBRsuKKMOlXCzh2Wu1mlHzv20TpqEsfdZLb3WoJW2kIEsGwLkroYf24IrPAvOT/ZQ2OYMV6vlrg==", "cpu": [ "arm" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.14.3.tgz", - "integrity": "sha512-Eci2us9VTHm1eSyn5/eEpaC7eP/mp5n46gTRB3Aar3BgSvDQGJZuicyq6TsH4HngNBgVqC5sDYxOzTExSU+NjA==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.22.4.tgz", + "integrity": "sha512-AdPRoNi3NKVLolCN/Sp4F4N1d98c4SBnHMKoLuiG6RXgoZ4sllseuGioszumnPGmPM2O7qaAX/IJdeDU8f26Aw==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.14.3.tgz", - "integrity": "sha512-UrBoMLCq4E92/LCqlh+blpqMz5h1tJttPIniwUgOFJyjWI1qrtrDhhpHPuFxULlUmjFHfloWdixtDhSxJt5iKw==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.22.4.tgz", + "integrity": "sha512-Gl0AxBtDg8uoAn5CCqQDMqAx22Wx22pjDOjBdmG0VIWX3qUBHzYmOKh8KXHL4UpogfJ14G4wk16EQogF+v8hmA==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.14.3.tgz", - "integrity": "sha512-5aRjvsS8q1nWN8AoRfrq5+9IflC3P1leMoy4r2WjXyFqf3qcqsxRCfxtZIV58tCxd+Yv7WELPcO9mY9aeQyAmw==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.22.4.tgz", + "integrity": "sha512-3aVCK9xfWW1oGQpTsYJJPF6bfpWfhbRnhdlyhak2ZiyFLDaayz0EP5j9V1RVLAAxlmWKTDfS9wyRyY3hvhPoOg==", "cpu": [ "ppc64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.14.3.tgz", - "integrity": "sha512-sk/Qh1j2/RJSX7FhEpJn8n0ndxy/uf0kI/9Zc4b1ELhqULVdTfN6HL31CDaTChiBAOgLcsJ1sgVZjWv8XNEsAQ==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.22.4.tgz", + "integrity": "sha512-ePYIir6VYnhgv2C5Xe9u+ico4t8sZWXschR6fMgoPUK31yQu7hTEJb7bCqivHECwIClJfKgE7zYsh1qTP3WHUA==", "cpu": [ "riscv64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-s390x-gnu": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.14.3.tgz", - "integrity": "sha512-jOO/PEaDitOmY9TgkxF/TQIjXySQe5KVYB57H/8LRP/ux0ZoO8cSHCX17asMSv3ruwslXW/TLBcxyaUzGRHcqg==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.22.4.tgz", + "integrity": "sha512-GqFJ9wLlbB9daxhVlrTe61vJtEY99/xB3C8e4ULVsVfflcpmR6c8UZXjtkMA6FhNONhj2eA5Tk9uAVw5orEs4Q==", "cpu": [ "s390x" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.14.3.tgz", - "integrity": "sha512-8ybV4Xjy59xLMyWo3GCfEGqtKV5M5gCSrZlxkPGvEPCGDLNla7v48S662HSGwRd6/2cSneMQWiv+QzcttLrrOA==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.22.4.tgz", + "integrity": "sha512-87v0ol2sH9GE3cLQLNEy0K/R0pz1nvg76o8M5nhMR0+Q+BBGLnb35P0fVz4CQxHYXaAOhE8HhlkaZfsdUOlHwg==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.14.3.tgz", - "integrity": "sha512-s+xf1I46trOY10OqAtZ5Rm6lzHre/UiLA1J2uOhCFXWkbZrJRkYBPO6FhvGfHmdtQ3Bx793MNa7LvoWFAm93bg==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.22.4.tgz", + "integrity": "sha512-UV6FZMUgePDZrFjrNGIWzDo/vABebuXBhJEqrHxrGiU6HikPy0Z3LfdtciIttEUQfuDdCn8fqh7wiFJjCNwO+g==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "linux" ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.14.3.tgz", - "integrity": "sha512-+4h2WrGOYsOumDQ5S2sYNyhVfrue+9tc9XcLWLh+Kw3UOxAvrfOrSMFon60KspcDdytkNDh7K2Vs6eMaYImAZg==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.22.4.tgz", + "integrity": "sha512-BjI+NVVEGAXjGWYHz/vv0pBqfGoUH0IGZ0cICTn7kB9PyjrATSkX+8WkguNjWoj2qSr1im/+tTGRaY+4/PdcQw==", "cpu": [ "arm64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "win32" ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.14.3.tgz", - "integrity": "sha512-T1l7y/bCeL/kUwh9OD4PQT4aM7Bq43vX05htPJJ46RTI4r5KNt6qJRzAfNfM+OYMNEVBWQzR2Gyk+FXLZfogGw==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.22.4.tgz", + "integrity": "sha512-SiWG/1TuUdPvYmzmYnmd3IEifzR61Tragkbx9D3+R8mzQqDBz8v+BvZNDlkiTtI9T15KYZhP0ehn3Dld4n9J5g==", "cpu": [ "ia32" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "win32" ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.14.3.tgz", - "integrity": "sha512-/BypzV0H1y1HzgYpxqRaXGBRqfodgoBBCcsrujT6QRcakDQdfU+Lq9PENPh5jB4I44YWq+0C2eHsHya+nZY1sA==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.22.4.tgz", + "integrity": "sha512-j8pPKp53/lq9lMXN57S8cFz0MynJk8OWNuUnXct/9KCpKU7DgU3bYMJhwWmcqC0UU29p8Lr0/7KEVcaM6bf47Q==", "cpu": [ "x64" ], "dev": true, + "license": "MIT", "optional": true, "os": [ "win32" ] }, - "node_modules/@sideway/address": { - "version": "4.1.5", - "resolved": "https://registry.npmjs.org/@sideway/address/-/address-4.1.5.tgz", - "integrity": "sha512-IqO/DUQHUkPeixNQ8n0JA6102hT9CmaljNTPmQ1u8MEhBo/R4Q8eKLN/vGZxuebwOroDB4cbpjheD4+/sKFK4Q==", - "peer": true, - "dependencies": { - "@hapi/hoek": "^9.0.0" - } - }, - "node_modules/@sideway/formula": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@sideway/formula/-/formula-3.0.1.tgz", - "integrity": "sha512-/poHZJJVjx3L+zVD6g9KgHfYnb443oi7wLu/XKojDviHy6HOEOA6z1Trk5aR1dGcmPenJEgb2sK2I80LeS3MIg==", - "peer": true - }, - "node_modules/@sideway/pinpoint": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sideway/pinpoint/-/pinpoint-2.0.0.tgz", - "integrity": "sha512-RNiOoTPkptFtSVzQevY/yWtZwf/RxyVnPy/OcA9HBM3MlGDnBEYL5B41H0MTn0Uec8Hi+2qUtTfG2WWZBmMejQ==", - "peer": true - }, "node_modules/@sinclair/typebox": { "version": "0.27.8", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", - "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==" + "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==", + "license": "MIT" }, "node_modules/@sinonjs/commons": { - "version": "1.8.6", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", - "integrity": "sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==", - "dev": true, + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", + "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==", + "license": "BSD-3-Clause", + "peer": true, "dependencies": { "type-detect": "4.0.8" } }, + "node_modules/@sinonjs/commons/node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=4" + } + }, "node_modules/@sinonjs/fake-timers": { "version": "10.3.0", "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-10.3.0.tgz", "integrity": "sha512-V4BG07kuYSUkTCSBHG8G8TNhM+F19jXFWnQtzj+we8DrkpSBCee9Z3Ms8yiGer/dlmhe35/Xdgyo3/0rQKg7YA==", + "license": "BSD-3-Clause", "peer": true, "dependencies": { "@sinonjs/commons": "^3.0.0" } }, - "node_modules/@sinonjs/fake-timers/node_modules/@sinonjs/commons": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-3.0.1.tgz", - "integrity": "sha512-K3mCHKQ9sVh8o1C9cxkwxaOmXoAMlDxC1mYyHrjqOWEcBjYr76t96zL2zlj5dUGZ3HSw240X1qgH3Mjf1yJWpQ==", - "peer": true, - "dependencies": { - "type-detect": "4.0.8" - } - }, "node_modules/@sinonjs/formatio": { "version": "3.2.2", "resolved": "https://registry.npmjs.org/@sinonjs/formatio/-/formatio-3.2.2.tgz", "integrity": "sha512-B8SEsgd8gArBLMD6zpRw3juQ2FVSsmdd7qlevyDqzS9WTCtvF55/gAL+h6gue8ZvPYcdiPdvueM/qm//9XzyTQ==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "@sinonjs/commons": "^1", "@sinonjs/samsam": "^3.1.0" } }, + "node_modules/@sinonjs/formatio/node_modules/@sinonjs/commons": { + "version": "1.8.6", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", + "integrity": "sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/formatio/node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/@sinonjs/samsam": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/@sinonjs/samsam/-/samsam-3.3.3.tgz", "integrity": "sha512-bKCMKZvWIjYD0BLGnNrxVuw4dkWCYsLqFOUWw8VgKF/+5Y+mE7LfHWPIYoDXowH+3a9LsWDMo0uAP8YDosPvHQ==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "@sinonjs/commons": "^1.3.0", "array-from": "^2.1.1", "lodash": "^4.17.15" } }, + "node_modules/@sinonjs/samsam/node_modules/@sinonjs/commons": { + "version": "1.8.6", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", + "integrity": "sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "type-detect": "4.0.8" + } + }, + "node_modules/@sinonjs/samsam/node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/@sinonjs/text-encoding": { - "version": "0.7.2", - "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.2.tgz", - "integrity": "sha512-sXXKG+uL9IrKqViTtao2Ws6dy0znu9sOaP1di/jKGW1M6VssO8vlpXCQcpZ+jisQ1tTFAC5Jo/EOzFbggBagFQ==", - "dev": true + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/@sinonjs/text-encoding/-/text-encoding-0.7.3.tgz", + "integrity": "sha512-DE427ROAphMQzU4ENbliGYrBSYPXF+TtLg9S8vzeA+OF4ZKzoDdzfL8sxuMUGS/lgRhM6j1URSk9ghf7Xo1tyA==", + "dev": true, + "license": "(Unlicense OR Apache-2.0)" }, "node_modules/@socket.io/component-emitter": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.1.tgz", - "integrity": "sha512-dzJtaDAAoXx4GCOJpbB2eG/Qj8VDpdwkLsWGzGm+0L7E8/434RyMbAHmk9ubXWVAb9nXmc44jUf8GKqVDiKezg==", - "dev": true + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/@socket.io/component-emitter/-/component-emitter-3.1.2.tgz", + "integrity": "sha512-9BCxFwvbGg/RsZK9tjXd8s4UcwR0MWeFQ1XEKIQVVvAGJyINdrqKMcTRyLoK8Rse1GjzLV9cwjWV1olXRWEXVA==", + "dev": true, + "license": "MIT" }, "node_modules/@teppeis/multimaps": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@teppeis/multimaps/-/multimaps-3.0.0.tgz", "integrity": "sha512-ID7fosbc50TbT0MK0EG12O+gAP3W3Aa/Pz4DaTtQtEvlc9Odaqi0de+xuZ7Li2GtK4HzEX7IuRWS/JmZLksR3Q==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=14" } @@ -4645,49 +4560,102 @@ "node_modules/@tootallnate/quickjs-emscripten": { "version": "0.23.0", "resolved": "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz", - "integrity": "sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==" + "integrity": "sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA==", + "license": "MIT" }, "node_modules/@tsconfig/node10": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@tsconfig/node12": { "version": "1.0.11", "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@tsconfig/node14": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@tsconfig/node16": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", - "dev": true + "dev": true, + "license": "MIT" + }, + "node_modules/@types/babel__core": { + "version": "7.20.5", + "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", + "integrity": "sha512-qoQprZvz5wQFJwMDqeseRXWv3rqMvhgpbXFfVyWhbx9X47POIA6i/+dXefEmZKoAgOaTdaIgNSMqMIU61yRyzA==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/parser": "^7.20.7", + "@babel/types": "^7.20.7", + "@types/babel__generator": "*", + "@types/babel__template": "*", + "@types/babel__traverse": "*" + } + }, + "node_modules/@types/babel__generator": { + "version": "7.6.8", + "resolved": "https://registry.npmjs.org/@types/babel__generator/-/babel__generator-7.6.8.tgz", + "integrity": "sha512-ASsj+tpEDsEiFr1arWrlN6V3mdfjRMZt6LtK/Vp/kreFLnr5QH5+DhvD5nINYZXzwJvXeGq+05iUXcAzVrqWtw==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/types": "^7.0.0" + } + }, + "node_modules/@types/babel__template": { + "version": "7.4.4", + "resolved": "https://registry.npmjs.org/@types/babel__template/-/babel__template-7.4.4.tgz", + "integrity": "sha512-h/NUaSyG5EyxBIp8YRxo4RMe2/qQgvyowRwVMzhYhBCONbW8PUsg4lkFMrhgZhUe5z3L3MiLDuvyJ/CaPa2A8A==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/parser": "^7.1.0", + "@babel/types": "^7.0.0" + } + }, + "node_modules/@types/babel__traverse": { + "version": "7.20.6", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.6.tgz", + "integrity": "sha512-r1bzfrm0tomOI8g1SzvCaQHo6Lcv6zu0EA+W2kHrt8dyrHQxGzBBL4kdkzIS+jBMV+EYcMAEAqXqYaLJq5rOZg==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/types": "^7.20.7" + } }, "node_modules/@types/cbor-js": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/@types/cbor-js/-/cbor-js-0.1.1.tgz", "integrity": "sha512-pfCx/EZC7VNBThwAQ0XvGPOXYm8BUk+gSVonaIGcEKBuqGJHTdcwAGW8WZkdRs/u9n9yOt1pBoPTCS1s8ZYpEQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/chai": { - "version": "4.3.14", - "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.14.tgz", - "integrity": "sha512-Wj71sXE4Q4AkGdG9Tvq1u/fquNz9EdG4LIJMwVVII7ashjD/8cf8fyIfJAjRr6YcsXnSE8cOGQPq1gqeR8z+3w==", - "dev": true + "version": "4.3.20", + "resolved": "https://registry.npmjs.org/@types/chai/-/chai-4.3.20.tgz", + "integrity": "sha512-/pC9HAB5I/xMlc5FP77qjCnI16ChlJfW0tGa0IUcFn38VJrTV6DeZ60NU5KZBtaOZqjdpwTWohz5HU1RrhiYxQ==", + "dev": true, + "license": "MIT" }, "node_modules/@types/chai-as-promised": { "version": "7.1.8", "resolved": "https://registry.npmjs.org/@types/chai-as-promised/-/chai-as-promised-7.1.8.tgz", "integrity": "sha512-ThlRVIJhr69FLlh6IctTXFkmhtP3NpMZ2QGq69StYLyKZFp/HOp1VdKZj7RvfNWYYcJ1xlbLGLLWj1UvP5u/Gw==", "dev": true, + "license": "MIT", "dependencies": { "@types/chai": "*" } @@ -4696,52 +4664,58 @@ "version": "0.4.1", "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz", "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/cors": { "version": "2.8.17", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", "integrity": "sha512-8CGDvrBj1zgo2qE+oS3pOCyYNqCPryMWY2bGfwA0dcfopWGgxs+78df0Rs3rc9THP4JkOhLsAa+15VdpAqkcUA==", "dev": true, + "license": "MIT", "dependencies": { "@types/node": "*" } }, - "node_modules/@types/cucumber": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/@types/cucumber/-/cucumber-7.0.0.tgz", - "integrity": "sha512-cr5NN8/jmbw3vDKTQfGW0cSzDtkvxixu9bUD6po9U6OEF04XLuukTDldFG34ccDscLkA8bYnZ7VjxP79cIC7tg==", - "deprecated": "This is a stub types definition. @cucumber/cucumber provides its own type definitions, so you do not need this installed.", - "dev": true, - "dependencies": { - "@cucumber/cucumber": "*" - } - }, "node_modules/@types/estree": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", - "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", - "dev": true + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", + "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", + "dev": true, + "license": "MIT" }, "node_modules/@types/expect": { - "version": "24.3.0", - "resolved": "https://registry.npmjs.org/@types/expect/-/expect-24.3.0.tgz", - "integrity": "sha512-aq5Z+YFBz5o2b6Sp1jigx5nsmoZMK5Ceurjwy6PZmRv7dEi1jLtkARfvB1ME+OXJUG+7TZUDcv3WoCr/aor6dQ==", + "version": "24.3.2", + "resolved": "https://registry.npmjs.org/@types/expect/-/expect-24.3.2.tgz", + "integrity": "sha512-5ev4tL5eBuX9wyC/SFHku1Sizyerg457LiwMgde3sq61TMHbnKjikzwsBLxLpFMflvKuWXfWVW0w3hZg4qml9w==", "deprecated": "This is a stub types definition. expect provides its own type definitions, so you do not need this installed.", "dev": true, + "license": "MIT", "dependencies": { "expect": "*" } }, + "node_modules/@types/graceful-fs": { + "version": "4.1.9", + "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.9.tgz", + "integrity": "sha512-olP3sd1qOEe5dXTSaFvQG+02VdRXcdytWLAZsAq1PecU8uqQAhkrnbli7DagjtXKW/Bl7YJbUsa8MPcuc8LHEQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/istanbul-lib-coverage": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz", - "integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==" + "integrity": "sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w==", + "license": "MIT" }, "node_modules/@types/istanbul-lib-report": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.3.tgz", "integrity": "sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA==", + "license": "MIT", "dependencies": { "@types/istanbul-lib-coverage": "*" } @@ -4750,50 +4724,50 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/@types/istanbul-reports/-/istanbul-reports-3.0.4.tgz", "integrity": "sha512-pk2B1NWalF9toCRu6gjBzR69syFjP4Od8WRAX+0mmf9lAjCRicLOWc+ZrxZHx/0XRjotgkF9t6iaMJ+aXcOdZQ==", + "license": "MIT", "dependencies": { "@types/istanbul-lib-report": "*" } }, - "node_modules/@types/json-schema": { - "version": "7.0.15", - "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.15.tgz", - "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", - "dev": true - }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true, + "license": "MIT", "optional": true }, "node_modules/@types/lil-uuid": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/@types/lil-uuid/-/lil-uuid-0.1.3.tgz", "integrity": "sha512-UozexIWHw7bnQtbfdMqv1u82JmMl63t7lrCXpX6kByNH1F77j+Cdeqx28djuveoFvan9YUYrvK+ys1/hKIOgeA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/mocha": { "version": "9.1.1", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-9.1.1.tgz", "integrity": "sha512-Z61JK7DKDtdKTWwLeElSEBcWGRLY8g95ic5FoQqI9CMx0ns/Ghep3B4DfcEimiKMvtamNVULVNKEsiwV3aQmXw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/nock": { "version": "9.3.1", "resolved": "https://registry.npmjs.org/@types/nock/-/nock-9.3.1.tgz", "integrity": "sha512-eOVHXS5RnWOjTVhu3deCM/ruy9E6JCgeix2g7wpFiekQh3AaEAK1cz43tZDukKmtSmQnwvSySq7ubijCA32I7Q==", "dev": true, + "license": "MIT", "dependencies": { "@types/node": "*" } }, "node_modules/@types/node": { - "version": "20.12.7", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.7.tgz", - "integrity": "sha512-wq0cICSkRLVaf3UGLMGItu/PtdY7oaXaI/RVU+xliKVOtRna3PRY57ZDfztpDL0n11vfymMUnXv8QwYCO7L1wg==", + "version": "22.8.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.5.tgz", + "integrity": "sha512-5iYk6AMPtsMbkZqCO1UGF9W5L38twq11S2pYWkybGHH2ogPUvXWNlQqJBzuEZWKj/WRH+QTeiv6ySWqJtvIEgA==", + "license": "MIT", "dependencies": { - "undici-types": "~5.26.4" + "undici-types": "~6.19.8" } }, "node_modules/@types/node-fetch": { @@ -4801,34 +4775,43 @@ "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", "dev": true, + "license": "MIT", "dependencies": { "@types/node": "*", "form-data": "^4.0.0" } }, + "node_modules/@types/node-forge": { + "version": "1.3.11", + "resolved": "https://registry.npmjs.org/@types/node-forge/-/node-forge-1.3.11.tgz", + "integrity": "sha512-FQx220y22OKNTqaByeBGqHWYz4cl94tpcxeFdvBo3wjG6XPBuZ0BNgNZRV5J5TFmmcsJ4IzsLkmGRiQbnYsBEQ==", + "license": "MIT", + "peer": true, + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/normalize-package-data": { "version": "2.4.4", "resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.4.tgz", "integrity": "sha512-37i+OaWTh9qeK4LSHPsyRC7NahnGotNuZvjLSgcPzblpHB3rrCJxAOgI5gCdKm7coonsaX1Of0ILiTcnZjbfxA==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/@types/resolve": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", - "dev": true - }, - "node_modules/@types/semver": { - "version": "7.5.8", - "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.8.tgz", - "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/sinon": { "version": "17.0.3", "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.3.tgz", "integrity": "sha512-j3uovdn8ewky9kRBG19bOwaZbexJu/XjtkHyjvUgt4xfPFz18dcORIMqnYh66Fx3Powhcr85NT5+er3+oViapw==", "dev": true, + "license": "MIT", "dependencies": { "@types/sinonjs__fake-timers": "*" } @@ -4837,35 +4820,42 @@ "version": "8.1.5", "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-8.1.5.tgz", "integrity": "sha512-mQkU2jY8jJEF7YHjHvsQO8+3ughTL1mcnn96igfhONmR+fUPSKIkefQYpSe8bsly2Ep7oQbn/6VG5/9/0qcArQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/stack-utils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/stack-utils/-/stack-utils-2.0.3.tgz", - "integrity": "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==" + "integrity": "sha512-9aEbYZ3TbYMznPdcdr3SmIrLXwC/AKZXQeCf9Pgao5CKb8CyHuEX5jzWPTkvregvhRJHcpRO6BFoGW9ycaOkYw==", + "license": "MIT" }, "node_modules/@types/text-encoding": { "version": "0.0.39", "resolved": "https://registry.npmjs.org/@types/text-encoding/-/text-encoding-0.0.39.tgz", "integrity": "sha512-gRPvgL1aMgP6Pv92Rs310cJvVQ86DSF62E7K30g1FoGmmYWXoNuXT8PV835iAVeiAZkRwr2IW37KuyDn9ljmeA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/@types/underscore": { - "version": "1.11.15", - "resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.11.15.tgz", - "integrity": "sha512-HP38xE+GuWGlbSRq9WrZkousaQ7dragtZCruBVMi0oX1migFZavZ3OROKHSkNp/9ouq82zrWtZpg18jFnVN96g==", - "dev": true + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/@types/underscore/-/underscore-1.13.0.tgz", + "integrity": "sha512-L6LBgy1f0EFQZ+7uSA57+n2g/s4Qs5r06Vwrwn0/nuK1de+adz00NWaztRQ30aEqw5qOaWbPI8u2cGQ52lj6VA==", + "dev": true, + "license": "MIT" }, "node_modules/@types/uuid": { "version": "9.0.8", "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz", "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/@types/yargs": { - "version": "17.0.32", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.32.tgz", - "integrity": "sha512-xQ67Yc/laOG5uMfX/093MRlGGCIBzZMarVa+gfNKJxWAIgykYpVGkBdbqEzGDDfCrVUj6Hiff4mTZ5BA6TmAog==", + "version": "17.0.33", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz", + "integrity": "sha512-WpxBCKWPLr4xSsHgz511rFJAM+wS28w2zEO1QDNY5zM/S8ok70NNfztH0xwhqKyaK0OHCbN98LDAZuy1ctxDkA==", + "license": "MIT", "dependencies": { "@types/yargs-parser": "*" } @@ -4873,36 +4863,36 @@ "node_modules/@types/yargs-parser": { "version": "21.0.3", "resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.3.tgz", - "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==" + "integrity": "sha512-I4q9QU9MQv4oEOz4tAHJtNz1cwuLxn2F3xcc2iV5WdqLPpUnj30aUuxt1mAxYTG+oe8CZMV/+6rU4S4gRDzqtQ==", + "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.7.0.tgz", - "integrity": "sha512-GJWR0YnfrKnsRoluVO3PRb9r5aMZriiMMM/RHj5nnTrBy1/wIgk76XCtCKcnXGjpZQJQRFtGV9/0JJ6n30uwpQ==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.12.2.tgz", + "integrity": "sha512-gQxbxM8mcxBwaEmWdtLCIGLfixBMHhQjBqR8sVWNTPpcj45WlYL2IObS/DNMLH1DBP0n8qz+aiiLTGfopPEebw==", "dev": true, + "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/type-utils": "7.7.0", - "@typescript-eslint/utils": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", - "debug": "^4.3.4", + "@typescript-eslint/scope-manager": "8.12.2", + "@typescript-eslint/type-utils": "8.12.2", + "@typescript-eslint/utils": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", - "semver": "^7.6.0", "ts-api-utils": "^1.3.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "@typescript-eslint/parser": "^7.0.0", - "eslint": "^8.56.0" + "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", + "eslint": "^8.57.0 || ^9.0.0" }, "peerDependenciesMeta": { "typescript": { @@ -4910,54 +4900,28 @@ } } }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@typescript-eslint/eslint-plugin/node_modules/semver": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", - "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/@typescript-eslint/parser": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.7.0.tgz", - "integrity": "sha512-fNcDm3wSwVM8QYL4HKVBggdIPAy9Q41vcvC/GtDobw3c4ndVT3K6cqudUmjHPw8EAp4ufax0o58/xvWaP2FmTg==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.12.2.tgz", + "integrity": "sha512-MrvlXNfGPLH3Z+r7Tk+Z5moZAc0dzdVjTgUgwsdGweH7lydysQsnSww3nAmsq8blFuRD5VRlAr9YdEFw3e6PBw==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/typescript-estree": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/scope-manager": "8.12.2", + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/typescript-estree": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2", "debug": "^4.3.4" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.56.0" + "eslint": "^8.57.0 || ^9.0.0" }, "peerDependenciesMeta": { "typescript": { @@ -4966,16 +4930,17 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.7.0.tgz", - "integrity": "sha512-/8INDn0YLInbe9Wt7dK4cXLDYp0fNHP5xKLHvZl3mOT5X17rK/YShXaiNmorl+/U4VKCVIjJnx4Ri5b0y+HClw==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.12.2.tgz", + "integrity": "sha512-gPLpLtrj9aMHOvxJkSbDBmbRuYdtiEbnvO25bCMza3DhMjTQw0u7Y1M+YR5JPbMsXXnSPuCf5hfq0nEkQDL/JQ==", "dev": true, + "license": "MIT", "dependencies": { - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0" + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -4983,26 +4948,24 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.7.0.tgz", - "integrity": "sha512-bOp3ejoRYrhAlnT/bozNQi3nio9tIgv3U5C0mVDdZC7cpcQEDZXvq8inrHYghLVwuNABRqrMW5tzAv88Vy77Sg==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.12.2.tgz", + "integrity": "sha512-bwuU4TAogPI+1q/IJSKuD4shBLc/d2vGcRT588q+jzayQyjVK2X6v/fbR4InY2U2sgf8MEvVCqEWUzYzgBNcGQ==", "dev": true, + "license": "MIT", "dependencies": { - "@typescript-eslint/typescript-estree": "7.7.0", - "@typescript-eslint/utils": "7.7.0", + "@typescript-eslint/typescript-estree": "8.12.2", + "@typescript-eslint/utils": "8.12.2", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, - "peerDependencies": { - "eslint": "^8.56.0" - }, "peerDependenciesMeta": { "typescript": { "optional": true @@ -5010,12 +4973,13 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.7.0.tgz", - "integrity": "sha512-G01YPZ1Bd2hn+KPpIbrAhEWOn5lQBrjxkzHkWvP6NucMXFtfXoevK82hzQdpfuQYuhkvFDeQYbzXCjR1z9Z03w==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.12.2.tgz", + "integrity": "sha512-VwDwMF1SZ7wPBUZwmMdnDJ6sIFk4K4s+ALKLP6aIQsISkPv8jhiw65sAK6SuWODN/ix+m+HgbYDkH+zLjrzvOA==", "dev": true, + "license": "MIT", "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -5023,22 +4987,23 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.7.0.tgz", - "integrity": "sha512-8p71HQPE6CbxIBy2kWHqM1KGrC07pk6RJn40n0DSc6bMOBBREZxSDJ+BmRzc8B5OdaMh1ty3mkuWRg4sCFiDQQ==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.12.2.tgz", + "integrity": "sha512-mME5MDwGe30Pq9zKPvyduyU86PH7aixwqYR2grTglAdB+AN8xXQ1vFGpYaUSJ5o5P/5znsSBeNcs5g5/2aQwow==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/visitor-keys": "7.7.0", + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2", "debug": "^4.3.4", - "globby": "^11.1.0", + "fast-glob": "^3.3.2", "is-glob": "^4.0.3", "minimatch": "^9.0.4", "semver": "^7.6.0", "ts-api-utils": "^1.3.0" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -5050,96 +5015,41 @@ } } }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", - "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/@typescript-eslint/utils": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.7.0.tgz", - "integrity": "sha512-LKGAXMPQs8U/zMRFXDZOzmMKgFv3COlxUQ+2NMPhbqgVm6R1w+nU1i4836Pmxu9jZAuIeyySNrN/6Rc657ggig==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.12.2.tgz", + "integrity": "sha512-UTTuDIX3fkfAz6iSVa5rTuSfWIYZ6ATtEocQ/umkRSyC9O919lbZ8dcH7mysshrCdrAM03skJOEYaBugxN+M6A==", "dev": true, + "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@types/json-schema": "^7.0.15", - "@types/semver": "^7.5.8", - "@typescript-eslint/scope-manager": "7.7.0", - "@typescript-eslint/types": "7.7.0", - "@typescript-eslint/typescript-estree": "7.7.0", - "semver": "^7.6.0" + "@typescript-eslint/scope-manager": "8.12.2", + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/typescript-estree": "8.12.2" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.56.0" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@typescript-eslint/utils/node_modules/semver": { - "version": "7.6.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.0.tgz", - "integrity": "sha512-EnwXhrlwXMk9gKu5/flx5sv/an57AkRplG3hTK68W7FRDN+k+OWBj65M7719OkA82XLBxrcX0KSHj+X5COhOVg==", - "dev": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" + "eslint": "^8.57.0 || ^9.0.0" } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.7.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.7.0.tgz", - "integrity": "sha512-h0WHOj8MhdhY8YWkzIF30R379y0NqyOHExI9N9KCzvmu05EgG4FumeYa3ccfKUSphyWkWQE1ybVrgz/Pbam6YA==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.12.2.tgz", + "integrity": "sha512-PChz8UaKQAVNHghsHcPyx1OMHoFRUEA7rJSK/mDhdq85bk+PLsUHUBqTQTFt18VJZbmxBovM65fezlheQRsSDA==", "dev": true, + "license": "MIT", "dependencies": { - "@typescript-eslint/types": "7.7.0", + "@typescript-eslint/types": "8.12.2", "eslint-visitor-keys": "^3.4.3" }, "engines": { - "node": "^18.18.0 || >=20.0.0" + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" }, "funding": { "type": "opencollective", @@ -5150,12 +5060,14 @@ "version": "1.2.0", "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/abort-controller": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz", "integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==", + "license": "MIT", "peer": true, "dependencies": { "event-target-shim": "^5.0.0" @@ -5168,6 +5080,7 @@ "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", "integrity": "sha512-PYAthTa2m2VKxuvSD3DPC/Gy+U+sOA1LAuT8mkmRuvw+NACSaeXEQ+NHcVF7rONl6qcaxV3Uuemwawk+7+SJLw==", + "license": "MIT", "dependencies": { "mime-types": "~2.1.34", "negotiator": "0.6.3" @@ -5177,9 +5090,10 @@ } }, "node_modules/acorn": { - "version": "8.11.3", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.11.3.tgz", - "integrity": "sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg==", + "version": "8.14.0", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz", + "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==", + "license": "MIT", "bin": { "acorn": "bin/acorn" }, @@ -5192,15 +5106,20 @@ "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", "dev": true, + "license": "MIT", "peerDependencies": { "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" } }, "node_modules/acorn-walk": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.2.tgz", - "integrity": "sha512-cjkyv4OtNCIeqhHrfS81QWXoCBPExR/J62oyEqepVw8WaQeSqpW2uhuLPh1m9eWhDuOo/jUXVTlifvesOWp/4A==", + "version": "8.3.4", + "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", + "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", "dev": true, + "license": "MIT", + "dependencies": { + "acorn": "^8.11.0" + }, "engines": { "node": ">=0.4.0" } @@ -5209,6 +5128,7 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "license": "MIT", "dependencies": { "debug": "^4.3.4" }, @@ -5217,9 +5137,10 @@ } }, "node_modules/agentkeepalive": { - "version": "3.5.2", - "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-3.5.2.tgz", - "integrity": "sha512-e0L/HNe6qkQ7H19kTlRRqUibEAwDK5AFk6y3PtMsuut2VAH6+Q4xZml1tNDJD7kSAyqmbG/K08K5WEJYtUrSlQ==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-3.5.3.tgz", + "integrity": "sha512-yqXL+k5rr8+ZRpOAntkaaRgWgE5o8ESAj5DyRmVTCSoZxXmqemb9Dd7T4i5UzwuERdLAJUy6XzR9zFVuf0kzkw==", + "license": "MIT", "dependencies": { "humanize-ms": "^1.2.1" }, @@ -5232,6 +5153,7 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "dev": true, + "license": "MIT", "dependencies": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -5247,6 +5169,7 @@ "version": "1.4.10", "resolved": "https://registry.npmjs.org/anser/-/anser-1.4.10.tgz", "integrity": "sha512-hCv9AqTQ8ycjpSd3upOJd7vFwW1JaoYQ7tpham03GJ1ca8/65rqn0RpaWpItOAd6ylW9wAw6luXYPJIyPFVOww==", + "license": "MIT", "peer": true }, "node_modules/ansi-colors": { @@ -5254,47 +5177,30 @@ "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.1.tgz", "integrity": "sha512-JoX0apGbHaUJBNl6yF+p6JAFYZ666/hhCGKN5t9QFjbJQKUU/g8MNbFDbvfrgKXvI1QpZplPOnwIo99lX/AAmA==", "dev": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/ansi-fragments": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/ansi-fragments/-/ansi-fragments-0.2.1.tgz", - "integrity": "sha512-DykbNHxuXQwUDRv5ibc2b0x7uw7wmwOGLBUd5RmaQ5z8Lhx19vwvKV+FAsM5rEA6dEcHxX+/Ad5s9eF2k2bB+w==", - "peer": true, - "dependencies": { - "colorette": "^1.0.7", - "slice-ansi": "^2.0.0", - "strip-ansi": "^5.0.0" - } - }, - "node_modules/ansi-fragments/node_modules/strip-ansi": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", - "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", - "peer": true, - "dependencies": { - "ansi-regex": "^4.1.0" - }, + "license": "MIT", "engines": { "node": ">=6" } }, "node_modules/ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", "engines": { - "node": ">=6" + "node": ">=8" } }, "node_modules/ansi-styles": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", - "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "license": "MIT", + "dependencies": { + "color-convert": "^2.0.1" + }, "engines": { - "node": ">=10" + "node": ">=8" }, "funding": { "url": "https://github.com/chalk/ansi-styles?sponsor=1" @@ -5304,12 +5210,15 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/any-promise/-/any-promise-1.3.0.tgz", "integrity": "sha512-7UvmKalWRt1wgjL1RrGxoSJW/0QZFIegpeGvZG9kjp8vrRu55XTHbwnqq2GpXm9uLbcuhxm3IqX9OB4MZR1b2A==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/anymatch": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "license": "ISC", "dependencies": { "normalize-path": "^3.0.0", "picomatch": "^2.0.4" @@ -5318,22 +5227,30 @@ "node": ">= 8" } }, - "node_modules/appdirsjs": { - "version": "1.2.7", - "resolved": "https://registry.npmjs.org/appdirsjs/-/appdirsjs-1.2.7.tgz", - "integrity": "sha512-Quji6+8kLBC3NnBeo14nPDq0+2jUs5s3/xEye+udFHumHhRk4M7aAMXp/PBJqkKYGuuyR9M/6Dq7d2AViiGmhw==", - "peer": true + "node_modules/anymatch/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } }, "node_modules/arg": { "version": "4.1.3", "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "license": "MIT", "dependencies": { "sprintf-js": "~1.0.2" } @@ -5342,22 +5259,15 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/array-from/-/array-from-2.1.1.tgz", "integrity": "sha512-GQTc6Uupx1FCavi5mPzBvVT7nEOeWMmUA9P95wpfpW1XwMSKs+KaymD5C2Up7KAUKg/mYwbsUYzdZWcoajlNZg==", - "dev": true - }, - "node_modules/array-union": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", - "integrity": "sha512-HGyxoOTYUyCM6stUe6EJgnd4EoewAI7zMdfqO+kGjnlZmBDz/cR5pf8r/cR4Wq60sL/p0IkcjUEEPwS3GFrIyw==", "dev": true, - "engines": { - "node": ">=8" - } + "license": "MIT" }, "node_modules/arrify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/arrify/-/arrify-1.0.1.tgz", "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -5366,23 +5276,15 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", "integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA==", + "license": "MIT", "peer": true }, - "node_modules/assert-plus": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/assert-plus/-/assert-plus-1.0.0.tgz", - "integrity": "sha512-NfJ4UzBCcQGLDlQq7nHxH+tv3kyZ0hHQqF5BO6J7tNJeP5do1llPr8dZ8zHonfhAu0PHAdMkSo+8o0wxg9lZWw==", - "dev": true, - "peer": true, - "engines": { - "node": ">=0.8" - } - }, "node_modules/assertion-error": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", "dev": true, + "license": "MIT", "engines": { "node": "*" } @@ -5392,16 +5294,30 @@ "resolved": "https://registry.npmjs.org/assertion-error-formatter/-/assertion-error-formatter-3.0.0.tgz", "integrity": "sha512-6YyAVLrEze0kQ7CmJfUgrLHb+Y7XghmL2Ie7ijVa2Y9ynP3LV+VDiwFk62Dn0qtqbmY0BT0ss6p1xxpiF2PYbQ==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "diff": "^4.0.1", "pad-right": "^0.2.2", "repeat-string": "^1.6.1" } }, + "node_modules/assertion-error-formatter/node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "license": "BSD-3-Clause", + "peer": true, + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/ast-types": { "version": "0.13.4", "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.13.4.tgz", "integrity": "sha512-x1FCFnFifvYDDzTaLII71vG5uvDwgtmDTEVWAxrgeiR8VjMONcCXJx7E+USjDtHlwFmt9MysbqgF9b9Vjr6w+w==", + "license": "MIT", "dependencies": { "tslib": "^2.0.1" }, @@ -5409,43 +5325,93 @@ "node": ">=4" } }, - "node_modules/astral-regex": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/astral-regex/-/astral-regex-1.0.0.tgz", - "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", - "peer": true, - "engines": { - "node": ">=4" - } - }, "node_modules/async-limiter": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==", + "license": "MIT", "peer": true }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "license": "MIT" }, "node_modules/babel-core": { "version": "7.0.0-bridge.0", "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz", "integrity": "sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==", + "license": "MIT", + "peer": true, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + } + }, + "node_modules/babel-jest": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", + "integrity": "sha512-BrvGY3xZSwEcCzKvKsCi2GgHqDqsYkOP4/by5xCgIwGXQxIEh+8ew3gmrE1y7XRR6LHZIj6yLYnUi/mm2KXKBg==", + "license": "MIT", + "peer": true, + "dependencies": { + "@jest/transform": "^29.7.0", + "@types/babel__core": "^7.1.14", + "babel-plugin-istanbul": "^6.1.1", + "babel-preset-jest": "^29.6.3", + "chalk": "^4.0.0", + "graceful-fs": "^4.2.9", + "slash": "^3.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + }, + "peerDependencies": { + "@babel/core": "^7.8.0" + } + }, + "node_modules/babel-plugin-istanbul": { + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/babel-plugin-istanbul/-/babel-plugin-istanbul-6.1.1.tgz", + "integrity": "sha512-Y1IQok9821cC9onCx5otgFfRm7Lm+I+wwxOx738M/WLPZ9Q42m4IG5W0FNX8WLL2gYMZo3JkuXIH2DOpWM+qwA==", + "license": "BSD-3-Clause", + "peer": true, + "dependencies": { + "@babel/helper-plugin-utils": "^7.0.0", + "@istanbuljs/load-nyc-config": "^1.0.0", + "@istanbuljs/schema": "^0.1.2", + "istanbul-lib-instrument": "^5.0.4", + "test-exclude": "^6.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/babel-plugin-jest-hoist": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-29.6.3.tgz", + "integrity": "sha512-ESAc/RJvGTFEzRwOTT4+lNDk/GNHMkKbNzsvT0qKRfDyyYTskxB5rnU2njIDYVxXCBHHEI1c0YwHob3WaYujOg==", + "license": "MIT", "peer": true, - "peerDependencies": { - "@babel/core": "^7.0.0-0" + "dependencies": { + "@babel/template": "^7.3.3", + "@babel/types": "^7.3.3", + "@types/babel__core": "^7.1.14", + "@types/babel__traverse": "^7.0.6" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/babel-plugin-polyfill-corejs2": { - "version": "0.4.10", - "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.10.tgz", - "integrity": "sha512-rpIuu//y5OX6jVU+a5BCn1R5RSZYWAl2Nar76iwaOdycqb6JPxediskWFMMl7stfwNJR4b7eiQvh5fB5TEQJTQ==", + "version": "0.4.11", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.11.tgz", + "integrity": "sha512-sMEJ27L0gRHShOh5G54uAAPaiCOygY/5ratXuiyb2G46FmlSpc9eFCzYVyDiPxfNbwzA7mYahmjQc5q+CZQ09Q==", + "license": "MIT", "peer": true, "dependencies": { "@babel/compat-data": "^7.22.6", - "@babel/helper-define-polyfill-provider": "^0.6.1", + "@babel/helper-define-polyfill-provider": "^0.6.2", "semver": "^6.3.1" }, "peerDependencies": { @@ -5456,49 +5422,108 @@ "version": "6.3.1", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", "peer": true, "bin": { "semver": "bin/semver.js" } }, "node_modules/babel-plugin-polyfill-corejs3": { - "version": "0.10.4", - "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs3/-/babel-plugin-polyfill-corejs3-0.10.4.tgz", - "integrity": "sha512-25J6I8NGfa5YkCDogHRID3fVCadIR8/pGl1/spvCkzb6lVn6SR3ojpx9nOn9iEBcUsjY24AmdKm5khcfKdylcg==", + "version": "0.10.6", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs3/-/babel-plugin-polyfill-corejs3-0.10.6.tgz", + "integrity": "sha512-b37+KR2i/khY5sKmWNVQAnitvquQbNdWy6lJdsr0kmquCKEEUgMKK4SboVM3HtfnZilfjr4MMQ7vY58FVWDtIA==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-define-polyfill-provider": "^0.6.1", - "core-js-compat": "^3.36.1" + "@babel/helper-define-polyfill-provider": "^0.6.2", + "core-js-compat": "^3.38.0" }, "peerDependencies": { "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, "node_modules/babel-plugin-polyfill-regenerator": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.6.1.tgz", - "integrity": "sha512-JfTApdE++cgcTWjsiCQlLyFBMbTUft9ja17saCc93lgV33h4tuCVj7tlvu//qpLwaG+3yEz7/KhahGrUMkVq9g==", + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.6.2.tgz", + "integrity": "sha512-2R25rQZWP63nGwaAswvDazbPXfrM3HwVoBXK6HcqeKrSrL/JqcC/rDcf95l4r7LXLyxDXc8uQDa064GubtCABg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-define-polyfill-provider": "^0.6.1" + "@babel/helper-define-polyfill-provider": "^0.6.2" }, "peerDependencies": { "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, + "node_modules/babel-plugin-syntax-hermes-parser": { + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-hermes-parser/-/babel-plugin-syntax-hermes-parser-0.23.1.tgz", + "integrity": "sha512-uNLD0tk2tLUjGFdmCk+u/3FEw2o+BAwW4g+z2QVlxJrzZYOOPADroEcNtTPt5lNiScctaUmnsTkVEnOwZUOLhA==", + "license": "MIT", + "peer": true, + "dependencies": { + "hermes-parser": "0.23.1" + } + }, "node_modules/babel-plugin-transform-flow-enums": { "version": "0.0.2", "resolved": "https://registry.npmjs.org/babel-plugin-transform-flow-enums/-/babel-plugin-transform-flow-enums-0.0.2.tgz", "integrity": "sha512-g4aaCrDDOsWjbm0PUUeVnkcVd6AKJsVc/MbnPhEotEpkeJQP6b8nzewohQi7+QS8UyPehOhGWn0nOwjvWpmMvQ==", + "license": "MIT", "peer": true, "dependencies": { "@babel/plugin-syntax-flow": "^7.12.1" } }, + "node_modules/babel-preset-current-node-syntax": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/babel-preset-current-node-syntax/-/babel-preset-current-node-syntax-1.1.0.tgz", + "integrity": "sha512-ldYss8SbBlWva1bs28q78Ju5Zq1F+8BrqBZZ0VFhLBvhh6lCpC2o3gDJi/5DRLs9FgYZCnmPYIVFU4lRXCkyUw==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/plugin-syntax-async-generators": "^7.8.4", + "@babel/plugin-syntax-bigint": "^7.8.3", + "@babel/plugin-syntax-class-properties": "^7.12.13", + "@babel/plugin-syntax-class-static-block": "^7.14.5", + "@babel/plugin-syntax-import-attributes": "^7.24.7", + "@babel/plugin-syntax-import-meta": "^7.10.4", + "@babel/plugin-syntax-json-strings": "^7.8.3", + "@babel/plugin-syntax-logical-assignment-operators": "^7.10.4", + "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3", + "@babel/plugin-syntax-numeric-separator": "^7.10.4", + "@babel/plugin-syntax-object-rest-spread": "^7.8.3", + "@babel/plugin-syntax-optional-catch-binding": "^7.8.3", + "@babel/plugin-syntax-optional-chaining": "^7.8.3", + "@babel/plugin-syntax-private-property-in-object": "^7.14.5", + "@babel/plugin-syntax-top-level-await": "^7.14.5" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } + }, + "node_modules/babel-preset-jest": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/babel-preset-jest/-/babel-preset-jest-29.6.3.tgz", + "integrity": "sha512-0B3bhxR6snWXJZtR/RliHTDPRgn1sNHOR0yVtq/IiQFyuOVjFS+wuio/R4gSNkyYmKmJB4wGZv2NZanmKmTnNA==", + "license": "MIT", + "peer": true, + "dependencies": { + "babel-plugin-jest-hoist": "^29.6.3", + "babel-preset-current-node-syntax": "^1.0.0" + }, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + }, + "peerDependencies": { + "@babel/core": "^7.0.0" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", - "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==", + "license": "MIT" }, "node_modules/base64-js": { "version": "1.5.1", @@ -5517,13 +5542,15 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "license": "MIT" }, "node_modules/base64id": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz", "integrity": "sha512-lGe34o6EHj9y3Kts9R4ZYs/Gr+6N7MCaMlIFA3F1R2O5/m7K06AxfSeO5530PEERE6/WyEg3lsuyw4GHlPZHog==", "dev": true, + "license": "MIT", "engines": { "node": "^4.5.0 || >= 5.9" } @@ -5532,22 +5559,17 @@ "version": "5.0.5", "resolved": "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.0.5.tgz", "integrity": "sha512-4Bcg1P8xhUuqcii/S0Z9wiHIrQVPMermM1any+MX5GeGD7faD3/msQUDGLol9wOcz4/jbg/WJnGqoJF6LiBdtg==", + "license": "MIT", "engines": { "node": ">=10.0.0" } }, - "node_modules/becke-ch--regex--s0-0-v1--base--pl--lib": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/becke-ch--regex--s0-0-v1--base--pl--lib/-/becke-ch--regex--s0-0-v1--base--pl--lib-1.4.0.tgz", - "integrity": "sha512-FnWonOyaw7Vivg5nIkrUll9HSS5TjFbyuURAiDssuL6VxrBe3ERzudRxOcWRhZYlP89UArMDikz7SapRPQpmZQ==", - "dev": true, - "peer": true - }, "node_modules/binary-extensions": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz", "integrity": "sha512-Ceh+7ox5qe7LJuLHoY0feh3pHuUDHAcRUeyL2VYghZwfpkNIy/+8Ocg0a3UuSoYzavmylwuLWQOf3hl0jjMMIw==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" }, @@ -5555,67 +5577,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/bl": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/bl/-/bl-4.1.0.tgz", - "integrity": "sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==", - "peer": true, - "dependencies": { - "buffer": "^5.5.0", - "inherits": "^2.0.4", - "readable-stream": "^3.4.0" - } - }, - "node_modules/bl/node_modules/buffer": { - "version": "5.7.1", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz", - "integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/feross" - }, - { - "type": "patreon", - "url": "https://www.patreon.com/feross" - }, - { - "type": "consulting", - "url": "https://feross.org/support" - } - ], - "peer": true, - "dependencies": { - "base64-js": "^1.3.1", - "ieee754": "^1.1.13" - } - }, - "node_modules/bl/node_modules/readable-stream": { - "version": "3.6.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", - "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "peer": true, - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/bluebird": { - "version": "3.7.2", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.2.tgz", - "integrity": "sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg==", - "dev": true, - "peer": true - }, "node_modules/body-parser": { "version": "1.20.3", "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.20.3.tgz", "integrity": "sha512-7rAxByjUMqQ3/bHJy7D6OGXvx/MMc4IqBn/X0fcM1QUcAItpZrBEYhWGem+tzXH90c+G01ypMcYJBO9Y30203g==", "dev": true, + "license": "MIT", "dependencies": { "bytes": "3.1.2", "content-type": "~1.0.5", @@ -5625,7 +5592,7 @@ "http-errors": "2.0.0", "iconv-lite": "0.4.24", "on-finished": "2.4.1", - "qs": "6.11.0", + "qs": "6.13.0", "raw-body": "2.5.2", "type-is": "~1.6.18", "unpipe": "1.0.0" @@ -5640,6 +5607,7 @@ "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", "dev": true, + "license": "MIT", "dependencies": { "ms": "2.0.0" } @@ -5648,29 +5616,15 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "dev": true - }, - "node_modules/body-parser/node_modules/qs": { - "version": "6.11.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.0.tgz", - "integrity": "sha512-MvjoMCJwEarSbUYk5O+nmoSzSutSsTwF85zcHPQ9OrlFoZOYIjaqBAJIqIXjptyD5vThxGq52Xu/MaJzRkIk4Q==", "dev": true, - "license": "BSD-3-Clause", - "dependencies": { - "side-channel": "^1.0.4" - }, - "engines": { - "node": ">=0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } + "license": "MIT" }, "node_modules/brace-expansion": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", "dev": true, + "license": "MIT", "dependencies": { "balanced-match": "^1.0.0" } @@ -5679,6 +5633,7 @@ "version": "3.0.3", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", + "license": "MIT", "dependencies": { "fill-range": "^7.1.1" }, @@ -5690,12 +5645,13 @@ "version": "1.3.1", "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/browserslist": { - "version": "4.23.0", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.23.0.tgz", - "integrity": "sha512-QW8HiM1shhT2GuzkvklfjcKDiWFXHOeFCIA/huJPwHsslwcydgk7X+z2zXpEijP98UCY7HbubZt5J2Zgvf0CaQ==", + "version": "4.24.2", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.2.tgz", + "integrity": "sha512-ZIc+Q62revdMcqC6aChtW4jz3My3klmCO1fEmINZY/8J3EpBg5/A/D0AKmBveUh6pgoeycoMkVMko84tuYS+Gg==", "funding": [ { "type": "opencollective", @@ -5710,12 +5666,13 @@ "url": "https://github.com/sponsors/ai" } ], + "license": "MIT", "peer": true, "dependencies": { - "caniuse-lite": "^1.0.30001587", - "electron-to-chromium": "^1.4.668", - "node-releases": "^2.0.14", - "update-browserslist-db": "^1.0.13" + "caniuse-lite": "^1.0.30001669", + "electron-to-chromium": "^1.5.41", + "node-releases": "^2.0.18", + "update-browserslist-db": "^1.1.1" }, "bin": { "browserslist": "cli.js" @@ -5728,6 +5685,7 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/bser/-/bser-2.1.1.tgz", "integrity": "sha512-gQxTNE/GAfIIrmHLUE3oJyp5FO6HRBfhjnw4/wMmA63ZGDJnWBmgY/lyQBpnDUkGmAhbSe39tx2d/iTOAfglwQ==", + "license": "Apache-2.0", "peer": true, "dependencies": { "node-int64": "^0.4.0" @@ -5751,6 +5709,7 @@ "url": "https://feross.org/support" } ], + "license": "MIT", "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.2.1" @@ -5759,25 +5718,15 @@ "node_modules/buffer-from": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", - "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==" - }, - "node_modules/builtin-modules": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.3.0.tgz", - "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", - "dev": true, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "license": "MIT" }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.8" } @@ -5787,6 +5736,7 @@ "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", "dev": true, + "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -5805,6 +5755,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/caller-callsite/-/caller-callsite-2.0.0.tgz", "integrity": "sha512-JuG3qI4QOftFsZyOn1qq87fq5grLIyk1JYd5lJmdA+fG7aQ9pA/i3JIJGcO3q0MrRcHlOt1U+ZeHW8Dq9axALQ==", + "license": "MIT", "peer": true, "dependencies": { "callsites": "^2.0.0" @@ -5817,6 +5768,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-2.0.0.tgz", "integrity": "sha512-ksWePWBloaWPxJYQ8TL0JHvtci6G5QTKwQ95RcWAa/lzoAKuAOflGdAK92hpHXjkwb8zLxoLNUoNYZgVsaJzvQ==", + "license": "MIT", "peer": true, "engines": { "node": ">=4" @@ -5826,6 +5778,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/caller-path/-/caller-path-2.0.0.tgz", "integrity": "sha512-MCL3sf6nCSXOwCTzvPKhN18TU7AHTvdtam8DAogxcrJ8Rjfbbg7Lgng64H9Iy+vUV6VGFClN/TyxBkAebLRR4A==", + "license": "MIT", "peer": true, "dependencies": { "caller-callsite": "^2.0.0" @@ -5839,25 +5792,25 @@ "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } }, "node_modules/camelcase": { - "version": "6.3.0", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", - "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", + "license": "MIT", + "peer": true, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=6" } }, "node_modules/caniuse-lite": { - "version": "1.0.30001611", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001611.tgz", - "integrity": "sha512-19NuN1/3PjA3QI8Eki55N8my4LzfkMCRLgCVfrl/slbSAchQfV0+GwjPrK3rq37As4UCLlM/DHajbKkAqbv92Q==", + "version": "1.0.30001676", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001676.tgz", + "integrity": "sha512-Qz6zwGCiPghQXGJvgQAem79esjitvJ+CxSbSQkW9H/UX5hg8XM88d4lp2W+MEQ81j+Hip58Il+jGVdazk1z9cw==", "funding": [ { "type": "opencollective", @@ -5872,6 +5825,7 @@ "url": "https://github.com/sponsors/ai" } ], + "license": "CC-BY-4.0", "peer": true }, "node_modules/capital-case": { @@ -5879,6 +5833,8 @@ "resolved": "https://registry.npmjs.org/capital-case/-/capital-case-1.0.4.tgz", "integrity": "sha512-ds37W8CytHgwnhGGTi88pcPyR15qoNkOpYwmMMfnWqqWgESapLqvDx6huFjQ5vqWSn2Z06173XNA7LtMOeUh1A==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "no-case": "^3.0.4", "tslib": "^2.0.3", @@ -5888,18 +5844,21 @@ "node_modules/cbor-js": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/cbor-js/-/cbor-js-0.1.0.tgz", - "integrity": "sha512-7sQ/TvDZPl7csT1Sif9G0+MA0I0JOVah8+wWlJVQdVEgIbCzlN/ab3x+uvMNsc34TUvO6osQTAmB2ls80JX6tw==" + "integrity": "sha512-7sQ/TvDZPl7csT1Sif9G0+MA0I0JOVah8+wWlJVQdVEgIbCzlN/ab3x+uvMNsc34TUvO6osQTAmB2ls80JX6tw==", + "license": "MIT" }, "node_modules/cbor-sync": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/cbor-sync/-/cbor-sync-1.0.4.tgz", - "integrity": "sha512-GWlXN4wiz0vdWWXBU71Dvc1q3aBo0HytqwAZnXF1wOwjqNnDWA1vZ1gDMFLlqohak31VQzmhiYfiCX5QSSfagA==" + "integrity": "sha512-GWlXN4wiz0vdWWXBU71Dvc1q3aBo0HytqwAZnXF1wOwjqNnDWA1vZ1gDMFLlqohak31VQzmhiYfiCX5QSSfagA==", + "license": "MIT" }, "node_modules/chai": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/chai/-/chai-4.4.1.tgz", - "integrity": "sha512-13sOfMv2+DWduEU+/xbun3LScLoqN17nBeTLUsmDfKdoiC1fr0n9PU4guu4AhRcOVFk/sW8LyZWHuhWtQZiF+g==", + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.5.0.tgz", + "integrity": "sha512-RITGBfijLkBddZvnn8jdqoTypxvqbOLYQkGGxXzeFjVHvudaPw0HNFD9x928/eUwYWd2dPCugVqspGALTZZQKw==", "dev": true, + "license": "MIT", "dependencies": { "assertion-error": "^1.1.0", "check-error": "^1.0.3", @@ -5907,22 +5866,23 @@ "get-func-name": "^2.0.2", "loupe": "^2.3.6", "pathval": "^1.1.1", - "type-detect": "^4.0.8" + "type-detect": "^4.1.0" }, "engines": { "node": ">=4" } }, "node_modules/chai-as-promised": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.1.tgz", - "integrity": "sha512-azL6xMoi+uxu6z4rhWQ1jbdUhOMhis2PvscD/xjLqNMkv3BPPp2JyyuTHOrf9BOosGpNQ11v6BKv/g57RXbiaA==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/chai-as-promised/-/chai-as-promised-7.1.2.tgz", + "integrity": "sha512-aBDHZxRzYnUYuIAIPBH2s511DjlKPzXNlXSGFC8CwmroWQLfrW0LtE1nK3MAwwNhJPa9raEjNCmRoFpG0Hurdw==", "dev": true, + "license": "WTFPL", "dependencies": { "check-error": "^1.0.2" }, "peerDependencies": { - "chai": ">= 2.1.2 < 5" + "chai": ">= 2.1.2 < 6" } }, "node_modules/chai-nock": { @@ -5930,6 +5890,7 @@ "resolved": "https://registry.npmjs.org/chai-nock/-/chai-nock-1.3.0.tgz", "integrity": "sha512-O3j1bW3ACoUu/sLGYSoX50c1p8dbTkCjw3/dereqzl9BL2XsQAUVC18sJpg3hVwpCk71rjWGumCmHy87t5W+Pg==", "dev": true, + "license": "MIT", "dependencies": { "chai": "^4.2.0", "deep-equal": "^1.0.1" @@ -5939,6 +5900,7 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "license": "MIT", "dependencies": { "ansi-styles": "^4.1.0", "supports-color": "^7.1.0" @@ -5950,52 +5912,12 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, - "node_modules/chalk/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/chalk/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/chalk/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" - }, - "node_modules/chalk/node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/check-error": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", "integrity": "sha512-iKEoDYaRmd1mxM90a2OEfWhjsjPpYPuQ+lMYsoxB126+t8fw7ySEO48nmDg5COTjxDI65/Y2OWpeEHk3ZOe8zg==", "dev": true, + "license": "MIT", "dependencies": { "get-func-name": "^2.0.2" }, @@ -6008,9 +5930,10 @@ "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", "integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==", "dev": true, + "license": "MIT", "dependencies": { "anymatch": "~3.1.2", - "braces": "~3.0.3", + "braces": "~3.0.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", @@ -6032,6 +5955,7 @@ "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, + "license": "ISC", "dependencies": { "is-glob": "^4.0.1" }, @@ -6043,6 +5967,7 @@ "version": "0.15.2", "resolved": "https://registry.npmjs.org/chrome-launcher/-/chrome-launcher-0.15.2.tgz", "integrity": "sha512-zdLEwNo3aUVzIhKhTtXfxhdvZhUghrnmkvcAq2NoDd+LeOHKf03H5jwZ8T/STsAlzyALkBVK552iaG1fGf1xVQ==", + "license": "Apache-2.0", "peer": true, "dependencies": { "@types/node": "*", @@ -6057,22 +5982,11 @@ "node": ">=12.13.0" } }, - "node_modules/chrome-launcher/node_modules/escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "peer": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/chromium-edge-launcher": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/chromium-edge-launcher/-/chromium-edge-launcher-1.0.0.tgz", - "integrity": "sha512-pgtgjNKZ7i5U++1g1PWv75umkHvhVTDOQIZ+sjeUX9483S7Y6MUvO0lrd7ShGlQlFHMN4SwKTCq/X8hWrbv2KA==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/chromium-edge-launcher/-/chromium-edge-launcher-0.2.0.tgz", + "integrity": "sha512-JfJjUnq25y9yg4FABRRVPmBGWPZZi+AQXT4mxupb67766/0UlhG8PAZCz6xzEMXTbW3CsSoE8PcCWA49n35mKg==", + "license": "Apache-2.0", "peer": true, "dependencies": { "@types/node": "*", @@ -6083,22 +5997,11 @@ "rimraf": "^3.0.2" } }, - "node_modules/chromium-edge-launcher/node_modules/escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "peer": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/chromium-edge-launcher/node_modules/mkdirp": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "license": "MIT", "peer": true, "bin": { "mkdirp": "bin/cmd.js" @@ -6117,129 +6020,53 @@ "url": "https://github.com/sponsors/sibiraj-s" } ], + "license": "MIT", "engines": { "node": ">=8" } }, - "node_modules/class-transformer": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", - "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", - "dev": true - }, - "node_modules/cli-cursor": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", - "integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==", - "peer": true, - "dependencies": { - "restore-cursor": "^3.1.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/cli-spinners": { - "version": "2.9.2", - "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.2.tgz", - "integrity": "sha512-ywqV+5MmyL4E7ybXgKys4DugZbX0FC6LnwrhjuykIjnK9k8OQacQ7axGKnjDXWNhns0xot3bZI5h55H8yo9cJg==", - "peer": true, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/cli-table3": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.3.tgz", - "integrity": "sha512-w5Jac5SykAeZJKntOxJCrm63Eg5/4dhMWIcuTbo9rpE+brgaSZo0RuNJZeOyMgsUdhDeojvgyQLmjI+K50ZGyg==", - "dev": true, - "dependencies": { - "string-width": "^4.2.0" - }, - "engines": { - "node": "10.* || >= 12.*" - }, - "optionalDependencies": { - "@colors/colors": "1.5.0" - } - }, - "node_modules/cliui": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", - "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", - "dev": true, - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, - "node_modules/cliui/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/cliui/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/cliui/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true + "node_modules/class-transformer": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/class-transformer/-/class-transformer-0.5.1.tgz", + "integrity": "sha512-SQa1Ws6hUbfC98vKGxZH3KFY0Y1lm5Zm0SY8XX9zbK7FJCyVEac3ATW0RIpwzW+oOfmHE5PMPufDG9hCfoEOMw==", + "dev": true, + "license": "MIT", + "peer": true }, - "node_modules/cliui/node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "node_modules/cli-table3": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.6.3.tgz", + "integrity": "sha512-w5Jac5SykAeZJKntOxJCrm63Eg5/4dhMWIcuTbo9rpE+brgaSZo0RuNJZeOyMgsUdhDeojvgyQLmjI+K50ZGyg==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" + "string-width": "^4.2.0" }, "engines": { - "node": ">=10" + "node": "10.* || >= 12.*" }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + "optionalDependencies": { + "@colors/colors": "1.5.0" } }, - "node_modules/clone": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", - "integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==", - "peer": true, - "engines": { - "node": ">=0.8" + "node_modules/cliui": { + "version": "7.0.4", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz", + "integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==", + "dev": true, + "license": "ISC", + "dependencies": { + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0", + "wrap-ansi": "^7.0.0" } }, "node_modules/clone-deep": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz", "integrity": "sha512-neHB9xuzh/wk0dIHweyAXv2aPGZIVk3pLMe+/RNzINf17fe0OG96QroktYAUm7SM1PBnzTabaLboqqxDyMU+SQ==", + "license": "MIT", "peer": true, "dependencies": { "is-plain-object": "^2.0.4", @@ -6251,29 +6078,29 @@ } }, "node_modules/color-convert": { - "version": "1.9.3", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", - "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "license": "MIT", "dependencies": { - "color-name": "1.1.3" + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" } }, "node_modules/color-name": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", - "integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==" - }, - "node_modules/colorette": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.4.0.tgz", - "integrity": "sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==", - "peer": true + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "license": "MIT" }, "node_modules/colors": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz", "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.1.90" } @@ -6282,6 +6109,7 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "license": "MIT", "dependencies": { "delayed-stream": "~1.0.0" }, @@ -6289,89 +6117,32 @@ "node": ">= 0.8" } }, - "node_modules/command-exists": { - "version": "1.2.9", - "resolved": "https://registry.npmjs.org/command-exists/-/command-exists-1.2.9.tgz", - "integrity": "sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==", - "peer": true - }, "node_modules/commander": { - "version": "10.0.1", - "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", - "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", - "dev": true, + "version": "12.1.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-12.1.0.tgz", + "integrity": "sha512-Vw8qHK3bZM9y/P10u3Vib8o/DdkvA2OtPtZvD871QKjy74Wj1WSKFILMPRPSdUSx5RFK1arlJzEtA4PkFgnbuA==", + "license": "MIT", "engines": { - "node": ">=14" + "node": ">=18" } }, "node_modules/commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", - "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==" - }, - "node_modules/compressible": { - "version": "2.0.18", - "resolved": "https://registry.npmjs.org/compressible/-/compressible-2.0.18.tgz", - "integrity": "sha512-AF3r7P5dWxL8MxyITRMlORQNaOA2IkAFaTr4k7BUumjPtRpGDTZpl0Pb1XCO6JeDCBdp126Cgs9sMxqSjgYyRg==", - "peer": true, - "dependencies": { - "mime-db": ">= 1.43.0 < 2" - }, - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/compression": { - "version": "1.7.4", - "resolved": "https://registry.npmjs.org/compression/-/compression-1.7.4.tgz", - "integrity": "sha512-jaSIDzP9pZVS4ZfQ+TzvtiWhdpFhE2RDHz8QJkpX9SIpLq88VueF5jJw6t+6CUQcAoA6t+x89MLrWAqpfDE8iQ==", - "peer": true, - "dependencies": { - "accepts": "~1.3.5", - "bytes": "3.0.0", - "compressible": "~2.0.16", - "debug": "2.6.9", - "on-headers": "~1.0.2", - "safe-buffer": "5.1.2", - "vary": "~1.1.2" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/compression/node_modules/bytes": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", - "integrity": "sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==", - "peer": true, - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/compression/node_modules/debug": { - "version": "2.6.9", - "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", - "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", - "peer": true, - "dependencies": { - "ms": "2.0.0" - } - }, - "node_modules/compression/node_modules/ms": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", - "peer": true + "integrity": "sha512-W9pAhw0ja1Edb5GVdIF1mjZw/ASI0AlShXM83UUGe2DVr5TdAPEA1OA8m/g8zWp9x6On7gqufY+FatDbC3MDQg==", + "license": "MIT" }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", + "license": "MIT" }, "node_modules/connect": { "version": "3.7.0", "resolved": "https://registry.npmjs.org/connect/-/connect-3.7.0.tgz", "integrity": "sha512-ZqRXc+tZukToSNmh5C2iWMSoV3X1YUcPbqEM4DkEG5tNQXrQUZCNVGGv3IuicnkMtPfGf3Xtp8WCXs295iQ1pQ==", + "license": "MIT", "dependencies": { "debug": "2.6.9", "finalhandler": "1.1.2", @@ -6386,6 +6157,7 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", "dependencies": { "ms": "2.0.0" } @@ -6393,13 +6165,15 @@ "node_modules/connect/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" }, "node_modules/content-type": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -6408,46 +6182,38 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-2.0.0.tgz", "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", + "license": "MIT", "peer": true }, "node_modules/cookie": { - "version": "0.4.2", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz", - "integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==", + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.6" } }, "node_modules/core-js-compat": { - "version": "3.37.0", - "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.37.0.tgz", - "integrity": "sha512-vYq4L+T8aS5UuFg4UwDhc7YNRWVeVZwltad9C/jV3R2LgVOpS9BDr7l/WL6BN0dbV3k1XejPTHqqEzJgsa0frA==", + "version": "3.39.0", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.39.0.tgz", + "integrity": "sha512-VgEUx3VwlExr5no0tXlBt+silBvhTryPwCXRI2Id1PN8WTKu7MreethvddqOubrYxkFdv/RnYrqlv1sFNAUelw==", + "license": "MIT", "peer": true, "dependencies": { - "browserslist": "^4.23.0" + "browserslist": "^4.24.2" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/core-js" } }, - "node_modules/core-js-pure": { - "version": "3.37.0", - "resolved": "https://registry.npmjs.org/core-js-pure/-/core-js-pure-3.37.0.tgz", - "integrity": "sha512-d3BrpyFr5eD4KcbRvQ3FTUx/KWmaDesr7+a3+1+P46IUnNoEt+oiLijPINZMEon7w9oGkIINWxrBAU9DEciwFQ==", - "dev": true, - "hasInstallScript": true, - "peer": true, - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/core-js" - } - }, "node_modules/core-util-is": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", + "license": "MIT", "peer": true }, "node_modules/cors": { @@ -6455,6 +6221,7 @@ "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", "integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==", "dev": true, + "license": "MIT", "dependencies": { "object-assign": "^4", "vary": "^1" @@ -6467,6 +6234,7 @@ "version": "5.2.1", "resolved": "https://registry.npmjs.org/cosmiconfig/-/cosmiconfig-5.2.1.tgz", "integrity": "sha512-H65gsXo1SKjf8zmrJ67eJk8aIRKV5ff2D4uKZIBZShbhGSpEmsQOPW/SKMKYhSTrqR7ufy6RP69rPogdaPh/kA==", + "license": "MIT", "peer": true, "dependencies": { "import-fresh": "^2.0.0", @@ -6475,295 +6243,82 @@ "parse-json": "^4.0.0" }, "engines": { - "node": ">=4" - } - }, - "node_modules/cosmiconfig/node_modules/import-fresh": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-2.0.0.tgz", - "integrity": "sha512-eZ5H8rcgYazHbKC3PG4ClHNykCSxtAhxSSEM+2mb+7evD2CKF5V7c0dNum7AdpDh0ZdICwZY9sRSn8f+KH96sg==", - "peer": true, - "dependencies": { - "caller-path": "^2.0.0", - "resolve-from": "^3.0.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/cosmiconfig/node_modules/parse-json": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", - "integrity": "sha512-aOIos8bujGN93/8Ox/jPLh7RwVnPEysynVFE+fQZyg6jKELEHwzgKdLRFHUgXJL6kylijVSBC4BvN9OmsB48Rw==", - "peer": true, - "dependencies": { - "error-ex": "^1.3.1", - "json-parse-better-errors": "^1.0.1" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/cosmiconfig/node_modules/resolve-from": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz", - "integrity": "sha512-GnlH6vxLymXJNMBo7XP1fJIzBFbdYt49CuTwmB/6N53t+kMPRMFKz783LlQ4tv28XoQfMWinAJX6WCGf2IlaIw==", - "peer": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/create-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", - "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", - "dev": true - }, - "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", - "dependencies": { - "path-key": "^3.1.0", - "shebang-command": "^2.0.0", - "which": "^2.0.1" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/cucumber": { - "version": "6.0.7", - "resolved": "https://registry.npmjs.org/cucumber/-/cucumber-6.0.7.tgz", - "integrity": "sha512-pN3AgWxHx8rOi+wOlqjASNETOjf3TgeyqhMNLQam7nSTXgQzju1oAmXkleRQRcXvpVvejcDHiZBLFSfBkqbYpA==", - "deprecated": "Cucumber is publishing new releases under @cucumber/cucumber", - "dev": true, - "peer": true, - "dependencies": { - "assertion-error-formatter": "^3.0.0", - "bluebird": "^3.4.1", - "cli-table3": "^0.5.1", - "colors": "^1.1.2", - "commander": "^3.0.1", - "cucumber-expressions": "^8.1.0", - "cucumber-tag-expressions": "^2.0.2", - "duration": "^0.2.1", - "escape-string-regexp": "^2.0.0", - "figures": "^3.0.0", - "gherkin": "5.0.0", - "glob": "^7.1.3", - "indent-string": "^4.0.0", - "is-generator": "^1.0.2", - "is-stream": "^2.0.0", - "knuth-shuffle-seeded": "^1.0.6", - "lodash": "^4.17.14", - "mz": "^2.4.0", - "progress": "^2.0.0", - "resolve": "^1.3.3", - "serialize-error": "^4.1.0", - "stack-chain": "^2.0.0", - "stacktrace-js": "^2.0.0", - "string-argv": "^0.3.0", - "title-case": "^2.1.1", - "util-arity": "^1.0.2", - "verror": "^1.9.0" - }, - "bin": { - "cucumber-js": "bin/cucumber-js" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/cucumber-expressions": { - "version": "8.3.0", - "resolved": "https://registry.npmjs.org/cucumber-expressions/-/cucumber-expressions-8.3.0.tgz", - "integrity": "sha512-cP2ya0EiorwXBC7Ll7Cj7NELYbasNv9Ty42L4u7sso9KruWemWG1ZiTq4PMqir3SNDSrbykoqI5wZgMbLEDjLQ==", - "deprecated": "This package is now published under @cucumber/cucumber-expressions", - "dev": true, - "peer": true, - "dependencies": { - "becke-ch--regex--s0-0-v1--base--pl--lib": "^1.4.0", - "xregexp": "^4.2.4" - } - }, - "node_modules/cucumber-pretty": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/cucumber-pretty/-/cucumber-pretty-6.0.1.tgz", - "integrity": "sha512-9uOIZ8x3lgCPROqYc7kqe2e7UrH5TZPZCdj5fVPze1XViG9yv8/8MnFsAnVINDYWVhiql8DJHb3UrZfIPHYH/A==", - "dev": true, - "dependencies": { - "cli-table3": "^0.6.0", - "colors": "^1.4.0", - "figures": "^3.2.0" - }, - "peerDependencies": { - "cucumber": ">=6.0.0 <7.0.0" - } - }, - "node_modules/cucumber-tag-expressions": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/cucumber-tag-expressions/-/cucumber-tag-expressions-2.0.3.tgz", - "integrity": "sha512-+x5j1IfZrBtbvYHuoUX0rl4nUGxaey6Do9sM0CABmZfDCcWXuuRm1fQeCaklIYQgOFHQ6xOHvDSdkMHHpni6tQ==", - "deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.", - "dev": true, - "peer": true - }, - "node_modules/cucumber-tsflow": { - "version": "4.4.4", - "resolved": "https://registry.npmjs.org/cucumber-tsflow/-/cucumber-tsflow-4.4.4.tgz", - "integrity": "sha512-oe2fPcAxWljZTc4+u0whbXIxZvjWzXfsieoY/TGuHY4aDLLOCFVLOVIxV8bKEI53PQhxJH809VugWHe2DB+nJg==", - "dev": true, - "dependencies": { - "callsites": "^3.1.0", - "log4js": "^6.3.0", - "source-map-support": "^0.5.19", - "underscore": "^1.8.3" - }, - "peerDependencies": { - "@cucumber/cucumber": "^7 || ^8 || ^9 || ^10" - } - }, - "node_modules/cucumber/node_modules/ansi-regex": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-3.0.1.tgz", - "integrity": "sha512-+O9Jct8wf++lXxxFc4hc8LsjaSq0HFzzL7cVsw8pRDIPdjKD2mT4ytDZlLuSBZ4cLKZFXIrMGO7DbQCtMJJMKw==", - "dev": true, - "peer": true, - "engines": { - "node": ">=4" - } - }, - "node_modules/cucumber/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, - "peer": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/cucumber/node_modules/cli-table3": { - "version": "0.5.1", - "resolved": "https://registry.npmjs.org/cli-table3/-/cli-table3-0.5.1.tgz", - "integrity": "sha512-7Qg2Jrep1S/+Q3EceiZtQcDPWxhAvBw+ERf1162v4sikJrvojMHFqXt8QIVha8UlH9rgU0BeWPytZ9/TzYqlUw==", - "dev": true, - "peer": true, - "dependencies": { - "object-assign": "^4.1.0", - "string-width": "^2.1.1" - }, - "engines": { - "node": ">=6" - }, - "optionalDependencies": { - "colors": "^1.1.2" - } - }, - "node_modules/cucumber/node_modules/commander": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/commander/-/commander-3.0.2.tgz", - "integrity": "sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==", - "dev": true, - "peer": true - }, - "node_modules/cucumber/node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "dev": true, - "peer": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "node": ">=4" } }, - "node_modules/cucumber/node_modules/is-fullwidth-code-point": { + "node_modules/cosmiconfig/node_modules/import-fresh": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==", - "dev": true, + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-2.0.0.tgz", + "integrity": "sha512-eZ5H8rcgYazHbKC3PG4ClHNykCSxtAhxSSEM+2mb+7evD2CKF5V7c0dNum7AdpDh0ZdICwZY9sRSn8f+KH96sg==", + "license": "MIT", "peer": true, + "dependencies": { + "caller-path": "^2.0.0", + "resolve-from": "^3.0.0" + }, "engines": { "node": ">=4" } }, - "node_modules/cucumber/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "dev": true, + "node_modules/cosmiconfig/node_modules/resolve-from": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-3.0.0.tgz", + "integrity": "sha512-GnlH6vxLymXJNMBo7XP1fJIzBFbdYt49CuTwmB/6N53t+kMPRMFKz783LlQ4tv28XoQfMWinAJX6WCGf2IlaIw==", + "license": "MIT", "peer": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, "engines": { - "node": "*" + "node": ">=4" } }, - "node_modules/cucumber/node_modules/string-width": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz", - "integrity": "sha512-nOqH59deCq9SRHlxq1Aw85Jnt4w6KvLKqWVik6oA9ZklXLNIOlqg4F2yrT1MVaTjAqvVwdfeZ7w7aCvJD7ugkw==", + "node_modules/create-require": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", + "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", "dev": true, - "peer": true, + "license": "MIT" + }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "license": "MIT", "dependencies": { - "is-fullwidth-code-point": "^2.0.0", - "strip-ansi": "^4.0.0" + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" }, "engines": { - "node": ">=4" + "node": ">= 8" } }, - "node_modules/cucumber/node_modules/strip-ansi": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-4.0.0.tgz", - "integrity": "sha512-4XaJ2zQdCzROZDivEVIDPkcQn8LMFSa8kj8Gxb/Lnwzv9A8VctNZ+lfivC/sV3ivW8ElJTERXZoPBRrZKkNKow==", + "node_modules/cucumber-tsflow": { + "version": "4.4.4", + "resolved": "https://registry.npmjs.org/cucumber-tsflow/-/cucumber-tsflow-4.4.4.tgz", + "integrity": "sha512-oe2fPcAxWljZTc4+u0whbXIxZvjWzXfsieoY/TGuHY4aDLLOCFVLOVIxV8bKEI53PQhxJH809VugWHe2DB+nJg==", "dev": true, - "peer": true, + "license": "MIT", "dependencies": { - "ansi-regex": "^3.0.0" + "callsites": "^3.1.0", + "log4js": "^6.3.0", + "source-map-support": "^0.5.19", + "underscore": "^1.8.3" }, - "engines": { - "node": ">=4" + "peerDependencies": { + "@cucumber/cucumber": "^7 || ^8 || ^9 || ^10" } }, "node_modules/custom-event": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/custom-event/-/custom-event-1.0.1.tgz", "integrity": "sha512-GAj5FOq0Hd+RsCGVJxZuKaIDXDf3h6GQoNEjFgbLLI/trgtavwUbSnZ5pVfg27DVCaWjIohryS0JFwIJyT2cMg==", - "dev": true - }, - "node_modules/d": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/d/-/d-1.0.2.tgz", - "integrity": "sha512-MOqHvMWF9/9MX6nza0KgvFH4HpMU0EF5uUDXqX/BtxtU8NfB0QzRtJ8Oe/6SuS4kbhyzVJwjd97EA4PKrzJ8bw==", "dev": true, - "peer": true, - "dependencies": { - "es5-ext": "^0.10.64", - "type": "^2.7.2" - }, - "engines": { - "node": ">=0.12" - } + "license": "MIT" }, "node_modules/data-uri-to-buffer": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-6.0.2.tgz", "integrity": "sha512-7hvf7/GW8e86rW0ptuwS3OcBGDjIi6SZva7hCyWC0yYry2cOPmLIjXAUHI6DK2HsnwJd9ifmt57i8eV2n4YNpw==", + "license": "MIT", "engines": { "node": ">= 14" } @@ -6773,22 +6328,18 @@ "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", "integrity": "sha512-39BOQLs9ZjKh0/patS9nrT8wc3ioX3/eA/zgbKNopnF2wCqJEoxywwwElATYvRsXdnOxA/OQeQoFZ3rFjVajhg==", "dev": true, + "license": "MIT", "engines": { "node": ">=4.0" } }, - "node_modules/dayjs": { - "version": "1.11.10", - "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.10.tgz", - "integrity": "sha512-vjAczensTgRcqDERK0SR2XMwsF/tSvnvlv6VcF2GIhg6Sx4yOIt/irsr1RDJsKiIyBzJDpCoXiWWq28MqH2cnQ==", - "peer": true - }, "node_modules/debug": { - "version": "4.3.4", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", - "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "license": "MIT", "dependencies": { - "ms": "2.1.2" + "ms": "^2.1.3" }, "engines": { "node": ">=6.0" @@ -6804,6 +6355,7 @@ "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-4.0.0.tgz", "integrity": "sha512-9iE1PgSik9HeIIw2JO94IidnE3eBoQrFJ3w7sFuzSX4DpmZ3v5sZpUiV5Swcf6mQEF+Y0ru8Neo+p+nyh2J+hQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, @@ -6812,10 +6364,11 @@ } }, "node_modules/deep-eql": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.3.tgz", - "integrity": "sha512-WaEtAOpRA1MQ0eohqZjpGD8zdI0Ovsm8mmFhaDN8dvDZzyoUMcYDnf5Y6iu7HTXxf8JDS23qWa4a+hKCDyOPzw==", + "version": "4.1.4", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.4.tgz", + "integrity": "sha512-SUwdGfqdKOwxCPeVYjwSyRpJ7Z+fhpwIAtmCUdZIWZ/YP5R9WAsyuSgpLVDi9bjWoN2LXHNss/dk3urXtdQxGg==", "dev": true, + "license": "MIT", "dependencies": { "type-detect": "^4.0.0" }, @@ -6828,6 +6381,7 @@ "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.2.tgz", "integrity": "sha512-5tdhKF6DbU7iIzrIOa1AOUt39ZRm13cmL1cGEh//aqR8x9+tNfbywRf0n5FD/18OKMdo7DNEtrX2t22ZAkI+eg==", "dev": true, + "license": "MIT", "dependencies": { "is-arguments": "^1.1.1", "is-date-object": "^1.0.5", @@ -6847,33 +6401,25 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/deepmerge": { "version": "4.3.1", "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", + "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } }, - "node_modules/defaults": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.4.tgz", - "integrity": "sha512-eFuaLoy/Rxalv2kr+lqMlUnrDWV+3j4pljOIJgLIhI058IQfWJ7vXhyEIHu+HtC738klGALYxOKDO0bQP3tg8A==", - "peer": true, - "dependencies": { - "clone": "^1.0.2" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/define-data-property": { "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", "dev": true, + "license": "MIT", "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -6891,6 +6437,7 @@ "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", "dev": true, + "license": "MIT", "dependencies": { "define-data-property": "^1.0.1", "has-property-descriptors": "^1.0.0", @@ -6907,6 +6454,7 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/degenerator/-/degenerator-5.0.1.tgz", "integrity": "sha512-TllpMR/t0M5sqCXfj85i4XaAzxmS5tVA16dqvdkMwGmzI+dXLXnw3J+3Vdv7VKw+ThlTMboK6i9rnZ6Nntj5CQ==", + "license": "MIT", "dependencies": { "ast-types": "^0.13.4", "escodegen": "^2.1.0", @@ -6920,6 +6468,7 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "license": "MIT", "engines": { "node": ">=0.4.0" } @@ -6928,34 +6477,23 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/denodeify/-/denodeify-1.2.1.tgz", "integrity": "sha512-KNTihKNmQENUZeKu5fzfpzRqR5S2VMp4gl9RFHiWzj9DfvYQPMJ6XHKNaQxaGCXwPk6y9yme3aUoaiAe+KX+vg==", + "license": "MIT", "peer": true }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", "engines": { "node": ">= 0.8" } }, - "node_modules/deprecated-react-native-prop-types": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/deprecated-react-native-prop-types/-/deprecated-react-native-prop-types-5.0.0.tgz", - "integrity": "sha512-cIK8KYiiGVOFsKdPMmm1L3tA/Gl+JopXL6F5+C7x39MyPsQYnP57Im/D6bNUzcborD7fcMwiwZqcBdBXXZucYQ==", - "peer": true, - "dependencies": { - "@react-native/normalize-colors": "^0.73.0", - "invariant": "^2.2.4", - "prop-types": "^15.8.1" - }, - "engines": { - "node": ">=18" - } - }, "node_modules/destroy": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==", + "license": "MIT", "engines": { "node": ">= 0.8", "npm": "1.2.8000 || >= 1.4.16" @@ -6965,13 +6503,15 @@ "version": "0.0.1", "resolved": "https://registry.npmjs.org/di/-/di-0.0.1.tgz", "integrity": "sha512-uJaamHkagcZtHPqCIHZxnFrXlunQXgBOsZSUOWwFw31QJCAbyTBoHMW75YOTur5ZNx8pIeAKgf6GWIgaqqiLhA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", "dev": true, + "license": "BSD-3-Clause", "engines": { "node": ">=0.3.1" } @@ -6981,27 +6521,17 @@ "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==", "dev": true, + "license": "MIT", "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/dir-glob": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/dir-glob/-/dir-glob-3.0.1.tgz", - "integrity": "sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==", - "dev": true, - "dependencies": { - "path-type": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/doctrine": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", "dev": true, + "license": "Apache-2.0", "dependencies": { "esutils": "^2.0.2" }, @@ -7014,6 +6544,7 @@ "resolved": "https://registry.npmjs.org/dom-serialize/-/dom-serialize-2.2.1.tgz", "integrity": "sha512-Yra4DbvoW7/Z6LBN560ZwXMjoNOSAN2wRsKFGc4iBeso+mpIA6qj1vfdf9HpMaKAqG6wXTy+1SYEzmNpKXOSsQ==", "dev": true, + "license": "MIT", "dependencies": { "custom-event": "~1.0.0", "ent": "~2.2.0", @@ -7021,99 +6552,115 @@ "void-elements": "^2.0.0" } }, - "node_modules/duration": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/duration/-/duration-0.2.2.tgz", - "integrity": "sha512-06kgtea+bGreF5eKYgI/36A6pLXggY7oR4p1pq4SmdFBn1ReOL5D8RhG64VrqfTTKNucqqtBAwEj8aB88mcqrg==", - "dev": true, - "peer": true, - "dependencies": { - "d": "1", - "es5-ext": "~0.10.46" - } - }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", - "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.4.740", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.740.tgz", - "integrity": "sha512-Yvg5i+iyv7Xm18BRdVPVm8lc7kgxM3r6iwqCH2zB7QZy1kZRNmd0Zqm0zcD9XoFREE5/5rwIuIAOT+/mzGcnZg==", + "version": "1.5.49", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.49.tgz", + "integrity": "sha512-ZXfs1Of8fDb6z7WEYZjXpgIRF6MEu8JdeGA0A40aZq6OQbS+eJpnnV49epZRna2DU/YsEjSQuGtQPPtvt6J65A==", + "license": "ISC", "peer": true }, "node_modules/emoji-regex": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", - "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", + "license": "MIT" }, "node_modules/encodeurl": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w==", + "license": "MIT", "engines": { "node": ">= 0.8" } }, "node_modules/engine.io": { - "version": "6.5.4", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.5.4.tgz", - "integrity": "sha512-KdVSDKhVKyOi+r5uEabrDLZw2qXStVvCsEB/LN3mw4WFi6Gx50jTyuxYVCwAAC0U46FdnzP/ScKRBTXb/NiEOg==", + "version": "6.6.2", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.2.tgz", + "integrity": "sha512-gmNvsYi9C8iErnZdVcJnvCpSKbWTt1E8+JZo8b+daLninywUWi5NQ5STSHZ9rFjFO7imNcvb8Pc5pe/wMR5xEw==", "dev": true, + "license": "MIT", "dependencies": { "@types/cookie": "^0.4.1", "@types/cors": "^2.8.12", "@types/node": ">=10.0.0", "accepts": "~1.3.4", "base64id": "2.0.0", - "cookie": "~0.4.1", + "cookie": "~0.7.2", "cors": "~2.8.5", "debug": "~4.3.1", "engine.io-parser": "~5.2.1", - "ws": "~8.11.0" + "ws": "~8.17.1" }, "engines": { "node": ">=10.2.0" } }, "node_modules/engine.io-parser": { - "version": "5.2.2", - "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.2.tgz", - "integrity": "sha512-RcyUFKA93/CXH20l4SoVvzZfrSDMOTUS3bWVpTt2FuFP+XYrL8i8oonHP7WInRyVHXh0n/ORtoeiE1os+8qkSw==", + "version": "5.2.3", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-5.2.3.tgz", + "integrity": "sha512-HqD3yTBfnBxIrbnM1DoD6Pcq8NECnh8d4As1Qgh0z5Gg3jRRIqijury0CL3ghu/edArpUYiYqQiDUQBIs4np3Q==", "dev": true, + "license": "MIT", "engines": { "node": ">=10.0.0" } }, - "node_modules/ent": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/ent/-/ent-2.2.0.tgz", - "integrity": "sha512-GHrMyVZQWvTIdDtpiEXdHZnFQKzeO09apj8Cbl4pKWy4i0Oprcq17usfDt5aO63swf0JOeMWjWQE/LzgSRuWpA==", - "dev": true + "node_modules/engine.io/node_modules/ws": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } }, - "node_modules/envinfo": { - "version": "7.12.0", - "resolved": "https://registry.npmjs.org/envinfo/-/envinfo-7.12.0.tgz", - "integrity": "sha512-Iw9rQJBGpJRd3rwXm9ft/JiGoAZmLxxJZELYDQoPRZ4USVhkKtIcNBPw6U+/K2mBpaqM25JSV6Yl4Az9vO2wJg==", - "peer": true, - "bin": { - "envinfo": "dist/cli.js" + "node_modules/ent": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ent/-/ent-2.2.1.tgz", + "integrity": "sha512-QHuXVeZx9d+tIQAz/XztU0ZwZf2Agg9CcXcgE1rurqvdBeDBrpSwjl8/6XUqMg7tw2Y7uAdKb2sRv+bSEFqQ5A==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^1.4.1" }, "engines": { - "node": ">=4" + "node": ">= 0.4" } }, "node_modules/error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", "integrity": "sha512-7dFHNmqeFSEt2ZBsCriorKnn3Z2pj+fd9kmI6QoWw4//DL+icEBfc0U7qJCisqrTsKTjw4fNFy2pW9OqStD84g==", + "license": "MIT", + "peer": true, "dependencies": { "is-arrayish": "^0.2.1" } @@ -7122,21 +6669,10 @@ "version": "2.1.4", "resolved": "https://registry.npmjs.org/error-stack-parser/-/error-stack-parser-2.1.4.tgz", "integrity": "sha512-Sk5V6wVazPhq5MhpO+AUxJn5x7XSXGl1R93Vn7i+zS15KDVxQijejNCrz8340/2bgLBjR9GtEG8ZVKONDjcqGQ==", - "dependencies": { - "stackframe": "^1.3.4" - } - }, - "node_modules/errorhandler": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/errorhandler/-/errorhandler-1.5.1.tgz", - "integrity": "sha512-rcOwbfvP1WTViVoUjcfZicVzjhjTuhSMntHh6mW3IrEiyE6mJyXvsToJUJGlGlw/2xU9P5whlWNGlIDVeCiT4A==", + "license": "MIT", "peer": true, "dependencies": { - "accepts": "~1.3.7", - "escape-html": "~1.0.3" - }, - "engines": { - "node": ">= 0.8" + "stackframe": "^1.3.4" } }, "node_modules/es-define-property": { @@ -7144,6 +6680,7 @@ "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", "dev": true, + "license": "MIT", "dependencies": { "get-intrinsic": "^1.2.4" }, @@ -7156,101 +6693,63 @@ "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" } }, - "node_modules/es5-ext": { - "version": "0.10.64", - "resolved": "https://registry.npmjs.org/es5-ext/-/es5-ext-0.10.64.tgz", - "integrity": "sha512-p2snDhiLaXe6dahss1LddxqEm+SkuDvV8dnIQG0MWjyHpcMNfXKPE+/Cc0y+PhxJX3A4xGNeFCj5oc0BUh6deg==", - "dev": true, - "hasInstallScript": true, - "peer": true, - "dependencies": { - "es6-iterator": "^2.0.3", - "es6-symbol": "^3.1.3", - "esniff": "^2.0.1", - "next-tick": "^1.1.0" - }, - "engines": { - "node": ">=0.10" - } - }, - "node_modules/es6-iterator": { - "version": "2.0.3", - "resolved": "https://registry.npmjs.org/es6-iterator/-/es6-iterator-2.0.3.tgz", - "integrity": "sha512-zw4SRzoUkd+cl+ZoE15A9o1oQd920Bb0iOJMQkQhl3jNc03YqVjAhG7scf9C5KWRU/R13Orf588uCC6525o02g==", - "dev": true, - "peer": true, - "dependencies": { - "d": "1", - "es5-ext": "^0.10.35", - "es6-symbol": "^3.1.1" - } - }, "node_modules/es6-shim": { "version": "0.35.8", "resolved": "https://registry.npmjs.org/es6-shim/-/es6-shim-0.35.8.tgz", "integrity": "sha512-Twf7I2v4/1tLoIXMT8HlqaBSS5H2wQTs2wx3MNYCI8K1R1/clXyCazrcVCPm/FuO9cyV8+leEaZOWD5C253NDg==", - "dev": true - }, - "node_modules/es6-symbol": { - "version": "3.1.4", - "resolved": "https://registry.npmjs.org/es6-symbol/-/es6-symbol-3.1.4.tgz", - "integrity": "sha512-U9bFFjX8tFiATgtkJ1zg25+KviIXpgRvRHS8sau3GfhVzThRQrOeksPeT0BWW2MNZs1OEWJ1DPXOQMn0KKRkvg==", "dev": true, - "peer": true, - "dependencies": { - "d": "^1.0.2", - "ext": "^1.7.0" - }, - "engines": { - "node": ">=0.12" - } + "license": "MIT" }, "node_modules/esbuild": { - "version": "0.19.12", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.19.12.tgz", - "integrity": "sha512-aARqgq8roFBj054KvQr5f1sFu0D65G+miZRCuJyJ0G13Zwx7vRar5Zhn2tkQNzIXcBrNVsv/8stehpj+GAjgbg==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", + "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", "dev": true, "hasInstallScript": true, + "license": "MIT", "bin": { "esbuild": "bin/esbuild" }, "engines": { - "node": ">=12" + "node": ">=18" }, "optionalDependencies": { - "@esbuild/aix-ppc64": "0.19.12", - "@esbuild/android-arm": "0.19.12", - "@esbuild/android-arm64": "0.19.12", - "@esbuild/android-x64": "0.19.12", - "@esbuild/darwin-arm64": "0.19.12", - "@esbuild/darwin-x64": "0.19.12", - "@esbuild/freebsd-arm64": "0.19.12", - "@esbuild/freebsd-x64": "0.19.12", - "@esbuild/linux-arm": "0.19.12", - "@esbuild/linux-arm64": "0.19.12", - "@esbuild/linux-ia32": "0.19.12", - "@esbuild/linux-loong64": "0.19.12", - "@esbuild/linux-mips64el": "0.19.12", - "@esbuild/linux-ppc64": "0.19.12", - "@esbuild/linux-riscv64": "0.19.12", - "@esbuild/linux-s390x": "0.19.12", - "@esbuild/linux-x64": "0.19.12", - "@esbuild/netbsd-x64": "0.19.12", - "@esbuild/openbsd-x64": "0.19.12", - "@esbuild/sunos-x64": "0.19.12", - "@esbuild/win32-arm64": "0.19.12", - "@esbuild/win32-ia32": "0.19.12", - "@esbuild/win32-x64": "0.19.12" + "@esbuild/aix-ppc64": "0.23.1", + "@esbuild/android-arm": "0.23.1", + "@esbuild/android-arm64": "0.23.1", + "@esbuild/android-x64": "0.23.1", + "@esbuild/darwin-arm64": "0.23.1", + "@esbuild/darwin-x64": "0.23.1", + "@esbuild/freebsd-arm64": "0.23.1", + "@esbuild/freebsd-x64": "0.23.1", + "@esbuild/linux-arm": "0.23.1", + "@esbuild/linux-arm64": "0.23.1", + "@esbuild/linux-ia32": "0.23.1", + "@esbuild/linux-loong64": "0.23.1", + "@esbuild/linux-mips64el": "0.23.1", + "@esbuild/linux-ppc64": "0.23.1", + "@esbuild/linux-riscv64": "0.23.1", + "@esbuild/linux-s390x": "0.23.1", + "@esbuild/linux-x64": "0.23.1", + "@esbuild/netbsd-x64": "0.23.1", + "@esbuild/openbsd-arm64": "0.23.1", + "@esbuild/openbsd-x64": "0.23.1", + "@esbuild/sunos-x64": "0.23.1", + "@esbuild/win32-arm64": "0.23.1", + "@esbuild/win32-ia32": "0.23.1", + "@esbuild/win32-x64": "0.23.1" } }, "node_modules/escalade": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.2.tgz", - "integrity": "sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA==", + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.2.0.tgz", + "integrity": "sha512-WUj2qlxaQtO4g6Pq5c29GTcWGDyd8itL8zTlipgECz3JesAiiOKotd8JU6otB3PACgG6xkJUyVhboMS+bje/jA==", + "license": "MIT", "engines": { "node": ">=6" } @@ -7258,20 +6757,26 @@ "node_modules/escape-html": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", - "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==" + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" }, "node_modules/escape-string-regexp": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", - "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "license": "MIT", "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/escodegen": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/escodegen/-/escodegen-2.1.0.tgz", "integrity": "sha512-2NlIDTwUWJN0mRPQOdtQBzbUHvdGY2P1VXSyU83Q3xKxM7WHX2Ql8dKq782Q9TgQUNOLEzEYu9bzLNj1q88I5w==", + "license": "BSD-2-Clause", "dependencies": { "esprima": "^4.0.1", "estraverse": "^5.2.0", @@ -7289,16 +6794,18 @@ } }, "node_modules/eslint": { - "version": "8.57.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.0.tgz", - "integrity": "sha512-dZ6+mexnaTIbSBZWgou51U6OmzIhYM2VcNdtiTtI7qPNZm35Akpr0f6vtw3w1Kmn5PYo+tZVfh13WrhpS6oLqQ==", + "version": "8.57.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.57.1.tgz", + "integrity": "sha512-ypowyDxpVSYpkXr9WPv2PAZCtNip1Mv5KTW0SCurXv/9iOpcrH9PaqUElksqEB6pChqHGDRCFTyrZlGhnLNGiA==", + "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, + "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", "@eslint/eslintrc": "^2.1.4", - "@eslint/js": "8.57.0", - "@humanwhocodes/config-array": "^0.11.14", + "@eslint/js": "8.57.1", + "@humanwhocodes/config-array": "^0.13.0", "@humanwhocodes/module-importer": "^1.0.1", "@nodelib/fs.walk": "^1.2.8", "@ungap/structured-clone": "^1.2.0", @@ -7344,10 +6851,11 @@ } }, "node_modules/eslint-plugin-mocha": { - "version": "10.4.2", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.4.2.tgz", - "integrity": "sha512-cur4dVYnSEWTBwdqIBQFxa/9siAhesu0TX+lbJ4ClE9j0eNMNe6BSx3vkFFNz6tGoveyMyELFXa30f3fvuAVDg==", + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.5.0.tgz", + "integrity": "sha512-F2ALmQVPT1GoP27O1JTZGrV9Pqg8k79OeIuvw63UxMtQKREZtmkK1NFgkZQ2TW7L2JSSFKHFPTtHu5z8R9QNRw==", "dev": true, + "license": "MIT", "dependencies": { "eslint-utils": "^3.0.0", "globals": "^13.24.0", @@ -7361,13 +6869,14 @@ } }, "node_modules/eslint-plugin-prettier": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.1.3.tgz", - "integrity": "sha512-C9GCVAs4Eq7ZC/XFQHITLiHJxQngdtraXaM+LoUFoFp/lHNl2Zn8f3WQbe9HvTBBQ9YnKFB0/2Ajdqwo5D1EAw==", + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", + "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==", "dev": true, + "license": "MIT", "dependencies": { "prettier-linter-helpers": "^1.0.0", - "synckit": "^0.8.6" + "synckit": "^0.9.1" }, "engines": { "node": "^14.18.0 || >=16.0.0" @@ -7395,6 +6904,7 @@ "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.2.tgz", "integrity": "sha512-dOt21O7lTMhDM+X9mB4GX+DZrZtCUJPL/wlcTqxyrx5IvO0IYtILdtrQGQp+8n5S0gwSVmOf9NQrjMOgfQZlIg==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "esrecurse": "^4.3.0", "estraverse": "^5.2.0" @@ -7411,6 +6921,7 @@ "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", "dev": true, + "license": "MIT", "dependencies": { "eslint-visitor-keys": "^2.0.0" }, @@ -7429,6 +6940,7 @@ "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", "dev": true, + "license": "Apache-2.0", "engines": { "node": ">=10" } @@ -7438,6 +6950,7 @@ "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.4.3.tgz", "integrity": "sha512-wpc+LXeiyiisxPlEkUzU6svyS1frIO3Mgxj1fdy7Pm8Ygzguax2N3Fa/D/ag1WqbOprdI+uY6wMUl8/a2G+iag==", "dev": true, + "license": "Apache-2.0", "engines": { "node": "^12.22.0 || ^14.17.0 || >=16.0.0" }, @@ -7449,35 +6962,26 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true + "dev": true, + "license": "Python-2.0" }, "node_modules/eslint/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, + "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" } }, - "node_modules/eslint/node_modules/escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/eslint/node_modules/js-yaml": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, + "license": "MIT", "dependencies": { "argparse": "^2.0.1" }, @@ -7490,6 +6994,7 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, + "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" }, @@ -7497,27 +7002,12 @@ "node": "*" } }, - "node_modules/esniff": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/esniff/-/esniff-2.0.1.tgz", - "integrity": "sha512-kTUIGKQ/mDPFoJ0oVfcmyJn4iBDRptjNVIzwIFR7tqWXdVI9xfA2RMwY/gbSpJG3lkdWNEjLap/NqVHZiJsdfg==", - "dev": true, - "peer": true, - "dependencies": { - "d": "^1.0.1", - "es5-ext": "^0.10.62", - "event-emitter": "^0.3.5", - "type": "^2.7.2" - }, - "engines": { - "node": ">=0.10" - } - }, "node_modules/espree": { "version": "9.6.1", "resolved": "https://registry.npmjs.org/espree/-/espree-9.6.1.tgz", "integrity": "sha512-oruZaFkjorTpF32kDSI5/75ViwGeZginGGy2NoOSg3Q9bnwlnmDm4HLnkl0RE3n+njDXR037aY1+x58Z/zFdwQ==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.9.0", "acorn-jsx": "^5.3.2", @@ -7534,6 +7024,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "license": "BSD-2-Clause", "bin": { "esparse": "bin/esparse.js", "esvalidate": "bin/esvalidate.js" @@ -7543,10 +7034,11 @@ } }, "node_modules/esquery": { - "version": "1.5.0", - "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", - "integrity": "sha512-YQLXUplAwJgCydQ78IMJywZCceoqk1oH01OERdSAJc/7U2AylwjhSCLDEtqwg811idIS/9fIU5GjG73IgjKMVg==", + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.6.0.tgz", + "integrity": "sha512-ca9pw9fomFcKPvFLXhBKUK90ZvGibiGOvRJNbjljY7s7uq/5YO4BOzcYtJqExdx99rF6aAcnRxHmcUHcz6sQsg==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "estraverse": "^5.1.0" }, @@ -7559,6 +7051,7 @@ "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "estraverse": "^5.2.0" }, @@ -7570,6 +7063,7 @@ "version": "5.3.0", "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "license": "BSD-2-Clause", "engines": { "node": ">=4.0" } @@ -7578,12 +7072,14 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "license": "BSD-2-Clause", "engines": { "node": ">=0.10.0" } @@ -7592,26 +7088,17 @@ "version": "1.8.1", "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", "peer": true, "engines": { "node": ">= 0.6" } }, - "node_modules/event-emitter": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/event-emitter/-/event-emitter-0.3.5.tgz", - "integrity": "sha512-D9rRn9y7kLPnJ+hMq7S/nhvoKwwvVJahBi2BPmx3bvbsEdK3W9ii8cBSGjP+72/LnM4n6fo3+dkCX5FeTQruXA==", - "dev": true, - "peer": true, - "dependencies": { - "d": "1", - "es5-ext": "~0.10.14" - } - }, "node_modules/event-target-shim": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz", "integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==", + "license": "MIT", "peer": true, "engines": { "node": ">=6" @@ -7621,12 +7108,14 @@ "version": "4.0.7", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz", "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/execa": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", + "license": "MIT", "peer": true, "dependencies": { "cross-spawn": "^7.0.3", @@ -7646,17 +7135,12 @@ "url": "https://github.com/sindresorhus/execa?sponsor=1" } }, - "node_modules/execa/node_modules/signal-exit": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "peer": true - }, "node_modules/expect": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/expect/-/expect-29.7.0.tgz", "integrity": "sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==", "dev": true, + "license": "MIT", "dependencies": { "@jest/expect-utils": "^29.7.0", "jest-get-type": "^29.6.3", @@ -7668,49 +7152,40 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/ext": { - "version": "1.7.0", - "resolved": "https://registry.npmjs.org/ext/-/ext-1.7.0.tgz", - "integrity": "sha512-6hxeJYaL110a9b5TEJSj0gojyHQAmA2ch5Os+ySCiA1QGdS697XWY1pzsrSjqA9LDEEgdB/KypIlR59RcLuHYw==", - "dev": true, - "peer": true, - "dependencies": { - "type": "^2.7.2" - } + "node_modules/exponential-backoff": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.1.tgz", + "integrity": "sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==", + "license": "Apache-2.0", + "peer": true }, "node_modules/extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", - "dev": true - }, - "node_modules/extsprintf": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha512-11Ndz7Nv+mvAC1j0ktTa7fAb0vLyGGX+rMHNBYQviQDGU0Hw7lhctJANqbPhu9nV9/izT/IntTgZ7Im/9LJs9g==", "dev": true, - "engines": [ - "node >=0.6.0" - ], - "peer": true + "license": "MIT" }, "node_modules/fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/fast-diff": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", - "dev": true + "dev": true, + "license": "Apache-2.0" }, "node_modules/fast-glob": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", "dev": true, + "license": "MIT", "dependencies": { "@nodelib/fs.stat": "^2.0.2", "@nodelib/fs.walk": "^1.2.3", @@ -7727,6 +7202,7 @@ "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, + "license": "ISC", "dependencies": { "is-glob": "^4.0.1" }, @@ -7738,41 +7214,21 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true + "license": "MIT" }, "node_modules/fast-levenshtein": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", - "dev": true - }, - "node_modules/fast-xml-parser": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.4.1.tgz", - "integrity": "sha512-xkjOecfnKGkSsOwtZ5Pz7Us/T6mrbPQrq0nh+aCO5V9nk5NLWmasAHumTKjiPJPWANe+kAZ84Jc8ooJkzZ88Sw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/NaturalIntelligence" - }, - { - "type": "paypal", - "url": "https://paypal.me/naturalintelligence" - } - ], - "peer": true, - "dependencies": { - "strnum": "^1.0.5" - }, - "bin": { - "fxparser": "src/cli/cli.js" - } + "dev": true, + "license": "MIT" }, "node_modules/fastq": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", "dev": true, + "license": "ISC", "dependencies": { "reusify": "^1.0.4" } @@ -7781,6 +7237,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/fb-watchman/-/fb-watchman-2.0.2.tgz", "integrity": "sha512-p5161BqbuCaSnB8jIbzQHOlpgsPmK5rJVDfDKO91Axs5NC1uu3HRQm6wt9cd9/+GtQQIO53JdGXXoyDpTAsgYA==", + "license": "Apache-2.0", "peer": true, "dependencies": { "bser": "2.1.1" @@ -7791,6 +7248,8 @@ "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", "integrity": "sha512-yaduQFRKLXYOGgEn6AZau90j3ggSOyiqXU0F9JZfeXYhNa+Jk4X+s45A2zg5jns87GAFa34BBm2kXw4XpNcbdg==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "escape-string-regexp": "^1.0.5" }, @@ -7806,6 +7265,8 @@ "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=0.8.0" } @@ -7815,6 +7276,7 @@ "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", "dev": true, + "license": "MIT", "dependencies": { "flat-cache": "^3.0.4" }, @@ -7826,6 +7288,7 @@ "version": "7.1.1", "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", + "license": "MIT", "dependencies": { "to-regex-range": "^5.0.1" }, @@ -7837,6 +7300,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.2.tgz", "integrity": "sha512-aAWcW57uxVNrQZqFXjITpW3sIUQmHGG3qSb9mUah9MgMC4NeWhNOlNjXEYq3HjRAvL6arUviZGGJsBg6z0zsWA==", + "license": "MIT", "dependencies": { "debug": "2.6.9", "encodeurl": "~1.0.2", @@ -7854,6 +7318,7 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", "dependencies": { "ms": "2.0.0" } @@ -7861,12 +7326,14 @@ "node_modules/finalhandler/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", - "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT" }, "node_modules/finalhandler/node_modules/on-finished": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", "integrity": "sha512-ikqdkGAAyf/X/gPhXGvfgAytDZtDbr+bkNUJ0N9h5MI/dmdgCs3l6hoHrcUv41sRKew3jIwrp4qQDXiK99Utww==", + "license": "MIT", "dependencies": { "ee-first": "1.1.1" }, @@ -7878,6 +7345,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-2.1.0.tgz", "integrity": "sha512-Tq6PixE0w/VMFfCgbONnkiQIVol/JJL7nRMi20fqzA4NRs9AfeqMGeRdPi3wIhYkxjeBaWh2rxwapn5Tu3IqOQ==", + "license": "MIT", "peer": true, "dependencies": { "commondir": "^1.0.1", @@ -7892,6 +7360,8 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", "integrity": "sha512-78/PXT1wlLLDgTzDs7sjq9hzz0vXD+zn+7wypEe4fXQxCmdmqfGsEPQxmiCSQI3ajFV91bVSsvNtrJRiW6nGng==", + "dev": true, + "license": "MIT", "dependencies": { "locate-path": "^6.0.0", "path-exists": "^4.0.0" @@ -7908,6 +7378,7 @@ "resolved": "https://registry.npmjs.org/flat/-/flat-5.0.2.tgz", "integrity": "sha512-b6suED+5/3rTpUBdG1gupIl8MPFCAMA0QXwmljLhvCUKcUvdE4gWky9zpuGCcXHOsz4J9wPGNWq6OKpmIzz3hQ==", "dev": true, + "license": "BSD-3-Clause", "bin": { "flat": "cli.js" } @@ -7917,6 +7388,7 @@ "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.2.0.tgz", "integrity": "sha512-CYcENa+FtcUKLmhhqyctpclsq7QF38pKjZHsGNiSQF5r4FtoKDWabFDl3hzaEQMvT1LHEysw5twgLvpYYb4vbw==", "dev": true, + "license": "MIT", "dependencies": { "flatted": "^3.2.9", "keyv": "^4.5.3", @@ -7930,27 +7402,30 @@ "version": "3.3.1", "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/flow-enums-runtime": { "version": "0.0.6", "resolved": "https://registry.npmjs.org/flow-enums-runtime/-/flow-enums-runtime-0.0.6.tgz", "integrity": "sha512-3PYnM29RFXwvAN6Pc/scUfkI7RwhQ/xqyLUyPNlXUp9S40zI8nup9tUSrTLSVnWGBN38FNiGWbwZOB6uR4OGdw==", + "license": "MIT", "peer": true }, "node_modules/flow-parser": { - "version": "0.206.0", - "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.206.0.tgz", - "integrity": "sha512-HVzoK3r6Vsg+lKvlIZzaWNBVai+FXTX1wdYhz/wVlH13tb/gOdLXmlTqy6odmTBhT5UoWUbq0k8263Qhr9d88w==", + "version": "0.251.1", + "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.251.1.tgz", + "integrity": "sha512-8ZuLqJPlL/T9K3zFdr1m88Lx8JOoJluTTdyvN4uH5NT9zoIIFqbCDoXVhkHh022k2lhuAyFF27cu0BYKh5SmDA==", + "license": "MIT", "peer": true, "engines": { "node": ">=0.4.0" } }, "node_modules/follow-redirects": { - "version": "1.15.6", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz", - "integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==", + "version": "1.15.9", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz", + "integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==", "dev": true, "funding": [ { @@ -7958,6 +7433,7 @@ "url": "https://github.com/sponsors/RubenVerborgh" } ], + "license": "MIT", "engines": { "node": ">=4.0" }, @@ -7968,10 +7444,12 @@ } }, "node_modules/foreground-child": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", - "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", + "integrity": "sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==", "dev": true, + "license": "ISC", + "peer": true, "dependencies": { "cross-spawn": "^7.0.0", "signal-exit": "^4.0.1" @@ -7983,10 +7461,25 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/foreground-child/node_modules/signal-exit": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", + "dev": true, + "license": "ISC", + "peer": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/form-data": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", - "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", + "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", @@ -8000,21 +7493,38 @@ "version": "0.5.2", "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", "integrity": "sha512-zJ2mQYM18rEFOudeV4GShTGIQ7RbzA7ozbU9I/XBpm7kqgMywgmylMwXHxZJmkVoYkna9d2pVXVXPdYTP9ej8Q==", + "license": "MIT", "peer": true, "engines": { "node": ">= 0.6" } }, + "node_modules/fs-extra": { + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", + "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "license": "MIT", + "dependencies": { + "graceful-fs": "^4.2.0", + "jsonfile": "^6.0.1", + "universalify": "^2.0.0" + }, + "engines": { + "node": ">=14.14" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", + "license": "ISC" }, "node_modules/fsevents": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", "hasInstallScript": true, + "license": "MIT", "optional": true, "os": [ "darwin" @@ -8027,6 +7537,7 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -8036,6 +7547,7 @@ "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", "dev": true, + "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -8044,6 +7556,7 @@ "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", "integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==", + "license": "MIT", "peer": true, "engines": { "node": ">=6.9.0" @@ -8053,6 +7566,7 @@ "version": "2.0.5", "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", + "license": "ISC", "engines": { "node": "6.* || 8.* || >= 10.*" } @@ -8062,6 +7576,7 @@ "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.2.tgz", "integrity": "sha512-8vXOvuE167CtIc3OyItco7N/dpRtBbYOsPsXCz7X/PMnlGjYjSGuZJgM1Y7mmew7BKf9BqvLX2tnOVy1BBUsxQ==", "dev": true, + "license": "MIT", "engines": { "node": "*" } @@ -8071,6 +7586,7 @@ "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", "dev": true, + "license": "MIT", "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2", @@ -8085,10 +7601,21 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/get-package-type": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", + "integrity": "sha512-pjzuKtY64GYfWizNAJ0fr9VqttZkNiK2iS430LtIHzjBEr6bX8Am2zm4sW4Ro5wjWW5cAlRL1qAMTcXbjNAO2Q==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8.0.0" + } + }, "node_modules/get-stream": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", + "license": "MIT", "peer": true, "engines": { "node": ">=10" @@ -8098,10 +7625,11 @@ } }, "node_modules/get-tsconfig": { - "version": "4.7.3", - "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.7.3.tgz", - "integrity": "sha512-ZvkrzoUA0PQZM6fy6+/Hce561s+faD1rsNwhnO5FelNjyy7EMGJ3Rz1AQ8GYDWjhRs/7dBLOEJvhK8MiEJOAFg==", + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.8.1.tgz", + "integrity": "sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==", "dev": true, + "license": "MIT", "dependencies": { "resolve-pkg-maps": "^1.0.0" }, @@ -8113,6 +7641,7 @@ "version": "6.0.3", "resolved": "https://registry.npmjs.org/get-uri/-/get-uri-6.0.3.tgz", "integrity": "sha512-BzUrJBS9EcUb4cFol8r4W3v1cPsSyajLSthNkz5BxbpDcHN5tIrM10E2eNvfnvBn3DaT3DUgx0OpsBKkaOpanw==", + "license": "MIT", "dependencies": { "basic-ftp": "^5.0.2", "data-uri-to-buffer": "^6.0.2", @@ -8123,58 +7652,22 @@ "node": ">= 14" } }, - "node_modules/get-uri/node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=14.14" - } - }, - "node_modules/get-uri/node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", - "dependencies": { - "universalify": "^2.0.0" - }, - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/gherkin": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/gherkin/-/gherkin-5.0.0.tgz", - "integrity": "sha512-Y+93z2Nh+TNIKuKEf+6M0FQrX/z0Yv9C2LFfc5NlcGJWRrrTeI/jOg2374y1FOw6ZYQ3RgJBezRkli7CLDubDA==", - "deprecated": "This package is now published under @cucumber/gherkin", - "dev": true, - "peer": true, - "bin": { - "gherkin-javascript": "bin/gherkin" - } - }, "node_modules/glob": { - "version": "10.3.12", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.3.12.tgz", - "integrity": "sha512-TCNv8vJ+xz4QiqTpfOJA7HvYv+tNIRHKfUWw/q+v2jdgN4ebz+KY9tGx5J4rHP0o84mNP+ApH66HRX8us3Khqg==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "deprecated": "Glob versions prior to v9 are no longer supported", "dev": true, + "license": "ISC", "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^2.3.6", - "minimatch": "^9.0.1", - "minipass": "^7.0.4", - "path-scurry": "^1.10.2" - }, - "bin": { - "glob": "dist/esm/bin.mjs" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -8185,6 +7678,7 @@ "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", "dev": true, + "license": "ISC", "dependencies": { "is-glob": "^4.0.3" }, @@ -8192,11 +7686,26 @@ "node": ">=10.13.0" } }, + "node_modules/glob/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/global-dirs": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-3.0.1.tgz", "integrity": "sha512-NBcGGFbBA9s1VzD41QXDG+3++t9Mn5t1FpLdhESY6oKY4gYTFpX4wO3sqGUa0Srjtbfj3szX0RnemmrVRUdULA==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "ini": "2.0.0" }, @@ -8212,6 +7721,7 @@ "resolved": "https://registry.npmjs.org/globals/-/globals-13.24.0.tgz", "integrity": "sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==", "dev": true, + "license": "MIT", "dependencies": { "type-fest": "^0.20.2" }, @@ -8222,43 +7732,12 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/globals/node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/globby": { - "version": "11.1.0", - "resolved": "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz", - "integrity": "sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==", - "dev": true, - "dependencies": { - "array-union": "^2.1.0", - "dir-glob": "^3.0.1", - "fast-glob": "^3.2.9", - "ignore": "^5.2.0", - "merge2": "^1.4.1", - "slash": "^3.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/gopd": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", "dev": true, + "license": "MIT", "dependencies": { "get-intrinsic": "^1.1.3" }, @@ -8269,19 +7748,23 @@ "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", - "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==" + "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==", + "license": "ISC" }, "node_modules/graphemer": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/graphemer/-/graphemer-1.4.0.tgz", "integrity": "sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/has-ansi": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-4.0.1.tgz", "integrity": "sha512-Qr4RtTm30xvEdqUXbSBVWDu+PrTokJOwe/FU+VdfJPk+MXAPoeOzKpRyrDTnZIJwAkQ4oBLTU53nu0HrkF/Z2A==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "ansi-regex": "^4.1.0" }, @@ -8289,10 +7772,22 @@ "node": ">=8" } }, + "node_modules/has-ansi/node_modules/ansi-regex": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", + "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=6" + } + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "license": "MIT", "engines": { "node": ">=8" } @@ -8302,6 +7797,7 @@ "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", "dev": true, + "license": "MIT", "dependencies": { "es-define-property": "^1.0.0" }, @@ -8314,6 +7810,7 @@ "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -8326,6 +7823,7 @@ "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -8338,6 +7836,7 @@ "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", "dev": true, + "license": "MIT", "dependencies": { "has-symbols": "^1.0.3" }, @@ -8352,6 +7851,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "license": "MIT", "dependencies": { "function-bind": "^1.1.2" }, @@ -8364,56 +7864,41 @@ "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true, + "license": "MIT", "bin": { "he": "bin/he" } }, "node_modules/hermes-estree": { - "version": "0.15.0", - "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.15.0.tgz", - "integrity": "sha512-lLYvAd+6BnOqWdnNbP/Q8xfl8LOGw4wVjfrNd9Gt8eoFzhNBRVD95n4l2ksfMVOoxuVyegs85g83KS9QOsxbVQ==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.23.1.tgz", + "integrity": "sha512-eT5MU3f5aVhTqsfIReZ6n41X5sYn4IdQL0nvz6yO+MMlPxw49aSARHLg/MSehQftyjnrE8X6bYregzSumqc6cg==", + "license": "MIT", "peer": true }, "node_modules/hermes-parser": { - "version": "0.15.0", - "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.15.0.tgz", - "integrity": "sha512-Q1uks5rjZlE9RjMMjSUCkGrEIPI5pKJILeCtK1VmTj7U4pf3wVPoo+cxfu+s4cBAPy2JzikIIdCZgBoR6x7U1Q==", - "peer": true, - "dependencies": { - "hermes-estree": "0.15.0" - } - }, - "node_modules/hermes-profile-transformer": { - "version": "0.0.6", - "resolved": "https://registry.npmjs.org/hermes-profile-transformer/-/hermes-profile-transformer-0.0.6.tgz", - "integrity": "sha512-cnN7bQUm65UWOy6cbGcCcZ3rpwW8Q/j4OP5aWRhEry4Z2t2aR1cjrbp0BS+KiBN0smvP1caBgAuxutvyvJILzQ==", + "version": "0.23.1", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.23.1.tgz", + "integrity": "sha512-oxl5h2DkFW83hT4DAUJorpah8ou4yvmweUzLJmmr6YV2cezduCdlil1AvU/a/xSsAFo4WUcNA4GoV5Bvq6JffA==", + "license": "MIT", "peer": true, "dependencies": { - "source-map": "^0.7.3" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/hermes-profile-transformer/node_modules/source-map": { - "version": "0.7.4", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.4.tgz", - "integrity": "sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==", - "peer": true, - "engines": { - "node": ">= 8" + "hermes-estree": "0.23.1" } }, "node_modules/hosted-git-info": { "version": "2.8.9", "resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz", "integrity": "sha512-mxIDAb9Lsm6DoOJ7xH+5+X4y1LU/4Hi50L9C5sIswK3JzULS4bwk1FvjdBgvYR4bzT4tuUQiC15FE2f5HbLvYw==", - "dev": true + "dev": true, + "license": "ISC", + "peer": true }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", "integrity": "sha512-FtwrG/euBzaEjYeRqOgly7G0qviiXoJWnvEH2Z1plBdXgbyjv34pHTSb9zoeHMyDy33+DWy5Wt9Wo+TURtOYSQ==", + "license": "MIT", "dependencies": { "depd": "2.0.0", "inherits": "2.0.4", @@ -8429,6 +7914,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "license": "MIT", "engines": { "node": ">= 0.8" } @@ -8438,6 +7924,7 @@ "resolved": "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.1.tgz", "integrity": "sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==", "dev": true, + "license": "MIT", "dependencies": { "eventemitter3": "^4.0.0", "follow-redirects": "^1.0.0", @@ -8451,6 +7938,7 @@ "version": "7.0.2", "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.2.tgz", "integrity": "sha512-T1gkAiYYDWYx3V5Bmyu7HcfcvL7mUrTWiM6yOfa3PIphViJ/gFPbvidQ+veqSOHci/PxBcDabeUNCzpOODJZig==", + "license": "MIT", "dependencies": { "agent-base": "^7.1.0", "debug": "^4.3.4" @@ -8460,9 +7948,10 @@ } }, "node_modules/https-proxy-agent": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.4.tgz", - "integrity": "sha512-wlwpilI7YdjSkWaQ/7omYBMTliDcmCN8OLihO6I9B86g06lMyAoqgoDpV0XqoaPOKj+0DIdAvnsWfyAAhmimcg==", + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz", + "integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==", + "license": "MIT", "dependencies": { "agent-base": "^7.0.2", "debug": "4" @@ -8475,6 +7964,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", + "license": "Apache-2.0", "peer": true, "engines": { "node": ">=10.17.0" @@ -8484,6 +7974,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "license": "MIT", "dependencies": { "ms": "^2.0.0" } @@ -8493,6 +7984,7 @@ "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", "dev": true, + "license": "MIT", "dependencies": { "safer-buffer": ">= 2.1.2 < 3" }, @@ -8517,13 +8009,15 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "license": "BSD-3-Clause" }, "node_modules/ignore": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.1.tgz", - "integrity": "sha512-5Fytz/IraMjqpwfd34ke28PTVMjZjJG2MPn5t7OE4eUCUNf8BAa7b5WUS9/Qvr6mwOQS7Mk6vdsMno5he+T8Xw==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", + "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 4" } @@ -8532,6 +8026,7 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/image-size/-/image-size-1.1.1.tgz", "integrity": "sha512-541xKlUw6jr/6gGuk92F+mYM5zaFAc5ahphvkqvNe2bQ6gVBkd6bfrmVJ2t4KDAfikAYZyIqTnktX3i6/aQDrQ==", + "license": "MIT", "peer": true, "dependencies": { "queue": "6.0.2" @@ -8548,6 +8043,7 @@ "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", "dev": true, + "license": "MIT", "dependencies": { "parent-module": "^1.0.0", "resolve-from": "^4.0.0" @@ -8563,6 +8059,7 @@ "version": "0.1.4", "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "license": "MIT", "engines": { "node": ">=0.8.19" } @@ -8572,6 +8069,8 @@ "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=8" } @@ -8580,6 +8079,8 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "deprecated": "This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.", + "license": "ISC", "dependencies": { "once": "^1.3.0", "wrappy": "1" @@ -8588,13 +8089,16 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" }, "node_modules/ini": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ini/-/ini-2.0.0.tgz", "integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==", "dev": true, + "license": "ISC", + "peer": true, "engines": { "node": ">=10" } @@ -8603,6 +8107,7 @@ "version": "2.2.4", "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", + "license": "MIT", "peer": true, "dependencies": { "loose-envify": "^1.0.0" @@ -8612,6 +8117,7 @@ "version": "9.0.5", "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz", "integrity": "sha512-zHtQzGojZXTwZTHQqra+ETKd4Sn3vgi7uBmlPoXVWZqYvuKmtI0l/VZTjqGmJY9x88GGOaZ9+G9ES8hC4T4X8g==", + "license": "MIT", "dependencies": { "jsbn": "1.1.0", "sprintf-js": "^1.1.3" @@ -8623,13 +8129,15 @@ "node_modules/ip-address/node_modules/sprintf-js": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.1.3.tgz", - "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==" + "integrity": "sha512-Oo+0REFV59/rz3gfJNKQiBlwfHaSESl1pcGyABQsnnIfWOFt6JNj5gCog2U6MLZ//IGYD+nA8nI+mTShREReaA==", + "license": "BSD-3-Clause" }, "node_modules/is-arguments": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", "dev": true, + "license": "MIT", "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -8644,13 +8152,16 @@ "node_modules/is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", - "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==" + "integrity": "sha512-zz06S8t0ozoDXMG+ube26zeCTNXcKIPJZJi8hBrF4idCLms4CG9QtK7qBl1boi5ODzFpjswb5JPmHCbMpjaYzg==", + "license": "MIT", + "peer": true }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", "dev": true, + "license": "MIT", "dependencies": { "binary-extensions": "^2.0.0" }, @@ -8658,27 +8169,16 @@ "node": ">=8" } }, - "node_modules/is-builtin-module": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", - "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", - "dev": true, + "node_modules/is-core-module": { + "version": "2.15.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.1.tgz", + "integrity": "sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ==", + "license": "MIT", "dependencies": { - "builtin-modules": "^3.3.0" + "hasown": "^2.0.2" }, "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/is-core-module": { - "version": "2.13.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", - "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", - "dependencies": { - "hasown": "^2.0.0" + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -8689,6 +8189,7 @@ "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", "dev": true, + "license": "MIT", "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -8703,6 +8204,7 @@ "version": "0.3.1", "resolved": "https://registry.npmjs.org/is-directory/-/is-directory-0.3.1.tgz", "integrity": "sha512-yVChGzahRFvbkscn2MlwGismPO12i9+znNruC5gVEntG3qu0xQMzsGg/JFbrsqDOHtHFPci+V5aP5T9I+yeKqw==", + "license": "MIT", "peer": true, "engines": { "node": ">=0.10.0" @@ -8712,6 +8214,7 @@ "version": "2.2.1", "resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.2.1.tgz", "integrity": "sha512-F+i2BKsFrH66iaUFc0woD8sLy8getkwTwtOBjvs56Cx4CgJDeKQeqfz8wAYiSb8JOprWhHH5p77PbmYCvvUuXQ==", + "license": "MIT", "peer": true, "bin": { "is-docker": "cli.js" @@ -8728,6 +8231,7 @@ "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -8736,22 +8240,17 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "license": "MIT", "engines": { "node": ">=8" } }, - "node_modules/is-generator": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/is-generator/-/is-generator-1.0.3.tgz", - "integrity": "sha512-G56jBpbJeg7ds83HW1LuShNs8J73Fv3CPz/bmROHOHlnKkN8sWb9ujiagjmxxMUywftgq48HlBZELKKqFLk0oA==", - "dev": true, - "peer": true - }, "node_modules/is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, + "license": "MIT", "dependencies": { "is-extglob": "^2.1.1" }, @@ -8764,6 +8263,8 @@ "resolved": "https://registry.npmjs.org/is-installed-globally/-/is-installed-globally-0.4.0.tgz", "integrity": "sha512-iwGqO3J21aaSkC7jWnHP/difazwS7SFeIqxv6wEtLU8Y5KlzFTjyqcSIT0d8s4+dDhKytsk9PJZ2BkS5eZwQRQ==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "global-dirs": "^3.0.0", "is-path-inside": "^3.0.2" @@ -8775,25 +8276,25 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/is-interactive": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-1.0.0.tgz", - "integrity": "sha512-2HvIEKRoqS62guEC+qBjpvRubdX910WCMuJTZ+I9yvqKU2/12eSL549HMwtabb4oupdj2sMP50k+XJfB/8JE6w==", - "peer": true, - "engines": { - "node": ">=8" - } - }, "node_modules/is-module": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", "integrity": "sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==", - "dev": true + "dev": true, + "license": "MIT" + }, + "node_modules/is-node-process": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/is-node-process/-/is-node-process-1.2.0.tgz", + "integrity": "sha512-Vg4o6/fqPxIjtxgUH5QLJhwZ7gW5diGCVlXpuUfELC62CuxM1iHcRe51f2W1FDy04Ai4KJkagKjx3XaqyfRKXw==", + "dev": true, + "license": "MIT" }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "license": "MIT", "engines": { "node": ">=0.12.0" } @@ -8803,6 +8304,7 @@ "resolved": "https://registry.npmjs.org/is-path-inside/-/is-path-inside-3.0.3.tgz", "integrity": "sha512-Fd4gABb+ycGAmKou8eMftCupSir5lRxqf4aD/vd0cD2qc4HL07OjCeuHMr8Ro4CoMaeCKDB0/ECBOVWjTwUvPQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -8812,6 +8314,7 @@ "resolved": "https://registry.npmjs.org/is-plain-obj/-/is-plain-obj-2.1.0.tgz", "integrity": "sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" } @@ -8820,6 +8323,7 @@ "version": "2.0.4", "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", + "license": "MIT", "peer": true, "dependencies": { "isobject": "^3.0.1" @@ -8833,6 +8337,7 @@ "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", "integrity": "sha512-U82MsXXiFIrjCK4otLT+o2NA2Cd2g5MLoOVXUZjIOhLurrRxpEXzI8O0KZHr3IjLvlAH1kTPYSuqer5T9ZVBKQ==", "dev": true, + "license": "MIT", "dependencies": { "@types/estree": "*" } @@ -8842,6 +8347,7 @@ "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", "dev": true, + "license": "MIT", "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -8857,6 +8363,8 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "license": "MIT", + "peer": true, "engines": { "node": ">=8" }, @@ -8868,6 +8376,8 @@ "version": "0.1.0", "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz", "integrity": "sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==", + "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, @@ -8879,6 +8389,7 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz", "integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==", + "license": "MIT", "peer": true, "dependencies": { "is-docker": "^2.0.0" @@ -8888,16 +8399,18 @@ } }, "node_modules/isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", - "peer": true + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", + "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", + "dev": true, + "license": "MIT" }, "node_modules/isbinaryfile": { "version": "4.0.10", "resolved": "https://registry.npmjs.org/isbinaryfile/-/isbinaryfile-4.0.10.tgz", "integrity": "sha512-iHrqe5shvBUcFbmZq9zOQHBoeOhZJu6RQGrDpBgenUm/Am+F3JM2MgQj+rK3Z601fzrL5gLZWtAPH2OBaSVcyw==", "dev": true, + "license": "MIT", "engines": { "node": ">= 8.0.0" }, @@ -8908,28 +8421,66 @@ "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", - "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==" + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "license": "ISC" }, "node_modules/isobject": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", "integrity": "sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==", + "license": "MIT", "peer": true, "engines": { "node": ">=0.10.0" } }, + "node_modules/istanbul-lib-coverage": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", + "integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==", + "license": "BSD-3-Clause", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/istanbul-lib-instrument": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/istanbul-lib-instrument/-/istanbul-lib-instrument-5.2.1.tgz", + "integrity": "sha512-pzqtp31nLv/XFOzXGuvhCb8qhjmTVo5vjVk19XE4CRlSWz0KoeJ3bw9XsA7nOp9YBf4qHjwBxkDzKcME/J29Yg==", + "license": "BSD-3-Clause", + "peer": true, + "dependencies": { + "@babel/core": "^7.12.3", + "@babel/parser": "^7.14.7", + "@istanbuljs/schema": "^0.1.2", + "istanbul-lib-coverage": "^3.2.0", + "semver": "^6.3.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/istanbul-lib-instrument/node_modules/semver": { + "version": "6.3.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.1.tgz", + "integrity": "sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==", + "license": "ISC", + "peer": true, + "bin": { + "semver": "bin/semver.js" + } + }, "node_modules/jackspeak": { - "version": "2.3.6", - "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-2.3.6.tgz", - "integrity": "sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==", + "version": "3.4.3", + "resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz", + "integrity": "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==", "dev": true, + "license": "BlueOak-1.0.0", + "peer": true, "dependencies": { "@isaacs/cliui": "^8.0.2" }, - "engines": { - "node": ">=14" - }, "funding": { "url": "https://github.com/sponsors/isaacs" }, @@ -8942,6 +8493,7 @@ "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.7.0.tgz", "integrity": "sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==", "dev": true, + "license": "MIT", "dependencies": { "chalk": "^4.0.0", "diff-sequences": "^29.6.3", @@ -8956,6 +8508,7 @@ "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-environment-node/-/jest-environment-node-29.7.0.tgz", "integrity": "sha512-DOSwCRqXirTOyheM+4d5YZOrWcdu0LNZ87ewUoywbcb2XR4wKgqiG8vNeYwhjFMbEkfju7wx2GYH0P2gevGvFw==", + "license": "MIT", "peer": true, "dependencies": { "@jest/environment": "^29.7.0", @@ -8973,8 +8526,35 @@ "version": "29.6.3", "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.6.3.tgz", "integrity": "sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw==", + "license": "MIT", + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/jest-haste-map": { + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.7.0.tgz", + "integrity": "sha512-fP8u2pyfqx0K1rGn1R9pyE0/KTn+G7PxktWidOBTqFPLYX0b9ksaMFkhK5vrS3DVun09pckLdlx90QthlW7AmA==", + "license": "MIT", + "peer": true, + "dependencies": { + "@jest/types": "^29.6.3", + "@types/graceful-fs": "^4.1.3", + "@types/node": "*", + "anymatch": "^3.0.3", + "fb-watchman": "^2.0.0", + "graceful-fs": "^4.2.9", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.7.0", + "jest-worker": "^29.7.0", + "micromatch": "^4.0.4", + "walker": "^1.0.8" + }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + }, + "optionalDependencies": { + "fsevents": "^2.3.2" } }, "node_modules/jest-matcher-utils": { @@ -8982,6 +8562,7 @@ "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz", "integrity": "sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g==", "dev": true, + "license": "MIT", "dependencies": { "chalk": "^4.0.0", "jest-diff": "^29.7.0", @@ -8996,6 +8577,7 @@ "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.7.0.tgz", "integrity": "sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w==", + "license": "MIT", "dependencies": { "@babel/code-frame": "^7.12.13", "@jest/types": "^29.6.3", @@ -9015,6 +8597,7 @@ "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.7.0.tgz", "integrity": "sha512-ITOMZn+UkYS4ZFh83xYAOzWStloNzJFO2s8DWrE4lhtGD+AorgnbkiKERe4wQVBydIGPx059g6riW5Btp6Llnw==", + "license": "MIT", "peer": true, "dependencies": { "@jest/types": "^29.6.3", @@ -9025,10 +8608,21 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-regex-util": { + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.6.3.tgz", + "integrity": "sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==", + "license": "MIT", + "peer": true, + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, "node_modules/jest-util": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", "integrity": "sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==", + "license": "MIT", "dependencies": { "@jest/types": "^29.6.3", "@types/node": "*", @@ -9041,10 +8635,23 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/jest-util/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/jest-validate": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-validate/-/jest-validate-29.7.0.tgz", "integrity": "sha512-ZB7wHqaRGVw/9hST/OuFUReG7M8vKeq0/J2egIGLdvjHCmYqGARhzXmtgi+gVeZ5uXFF219aOc3Ls2yLg27tkw==", + "license": "MIT", "peer": true, "dependencies": { "@jest/types": "^29.6.3", @@ -9054,14 +8661,28 @@ "leven": "^3.1.0", "pretty-format": "^29.7.0" }, - "engines": { - "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + "engines": { + "node": "^14.15.0 || ^16.10.0 || >=18.0.0" + } + }, + "node_modules/jest-validate/node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/jest-worker": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.7.0.tgz", "integrity": "sha512-eIz2msL/EzL9UFTFFx7jBTkeZfku0yUAyZZZmJ93H2TYEiroIx2PQjEXcwYtYl8zXCxb+PAmA2hLIt/6ZEkPHw==", + "license": "MIT", "peer": true, "dependencies": { "@types/node": "*", @@ -9073,28 +8694,33 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/joi": { - "version": "17.12.3", - "resolved": "https://registry.npmjs.org/joi/-/joi-17.12.3.tgz", - "integrity": "sha512-2RRziagf555owrm9IRVtdKynOBeITiDpuZqIpgwqXShPncPKNiRQoiGsl/T8SQdq+8ugRzH2LqY67irr2y/d+g==", + "node_modules/jest-worker/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "license": "MIT", "peer": true, "dependencies": { - "@hapi/hoek": "^9.3.0", - "@hapi/topo": "^5.1.0", - "@sideway/address": "^4.1.5", - "@sideway/formula": "^3.0.1", - "@sideway/pinpoint": "^2.0.0" + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" } }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", - "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" + "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", + "license": "MIT" }, "node_modules/js-yaml": { "version": "3.14.1", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "license": "MIT", "dependencies": { "argparse": "^1.0.7", "esprima": "^4.0.0" @@ -9106,24 +8732,28 @@ "node_modules/jsbn": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/jsbn/-/jsbn-1.1.0.tgz", - "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==" + "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", + "license": "MIT" }, "node_modules/jsc-android": { "version": "250231.0.0", "resolved": "https://registry.npmjs.org/jsc-android/-/jsc-android-250231.0.0.tgz", "integrity": "sha512-rS46PvsjYmdmuz1OAWXY/1kCYG7pnf1TBqeTiOJr1iDz7s5DLxxC9n/ZMknLDxzYzNVfI7R95MH10emSSG1Wuw==", + "license": "BSD-2-Clause", "peer": true }, "node_modules/jsc-safe-url": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/jsc-safe-url/-/jsc-safe-url-0.2.4.tgz", "integrity": "sha512-0wM3YBWtYePOjfyXQH5MWQ8H7sdk5EXSwZvmSLKk2RboVQ2Bu239jycHDz5J/8Blf3K0Qnoy2b6xD+z10MFB+Q==", + "license": "0BSD", "peer": true }, "node_modules/jscodeshift": { "version": "0.14.0", "resolved": "https://registry.npmjs.org/jscodeshift/-/jscodeshift-0.14.0.tgz", "integrity": "sha512-7eCC1knD7bLUPuSCwXsMZUH51O8jIcoVyKtI6P0XM0IVzlGjckPy3FIwQlorzbN0Sg79oK+RlohN32Mqf/lrYA==", + "license": "MIT", "peer": true, "dependencies": { "@babel/core": "^7.13.16", @@ -9153,82 +8783,116 @@ "@babel/preset-env": "^7.1.6" } }, + "node_modules/jscodeshift/node_modules/write-file-atomic": { + "version": "2.4.3", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.3.tgz", + "integrity": "sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==", + "license": "ISC", + "peer": true, + "dependencies": { + "graceful-fs": "^4.1.11", + "imurmurhash": "^0.1.4", + "signal-exit": "^3.0.2" + } + }, "node_modules/jsesc": { - "version": "2.5.2", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz", - "integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.0.2.tgz", + "integrity": "sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==", + "license": "MIT", "peer": true, "bin": { "jsesc": "bin/jsesc" }, "engines": { - "node": ">=4" + "node": ">=6" } }, "node_modules/json-buffer": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz", "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/json-parse-better-errors": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/json-parse-better-errors/-/json-parse-better-errors-1.0.2.tgz", "integrity": "sha512-mrqyZKfX5EhL7hvqcV6WG1yYjnjeuYDzDhhcAAUrq8Po85NBQBJP+ZDUT75qZQ98IkUoBqdkExkukOU7Ts2wrw==", + "license": "MIT", "peer": true }, "node_modules/json-parse-even-better-errors": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/json-stable-stringify-without-jsonify": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", "integrity": "sha512-ZClg6AaYvamvYEE82d3Iyd3vSSIjQ+odgjaTzRuO3s7toCdFKczob2i0zCh7JE8kWn17yvAWhUVxvqGwUalsRA==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/json5": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", - "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", - "dev": true, - "optional": true, - "dependencies": { - "minimist": "^1.2.0" - }, + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz", + "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", + "license": "MIT", + "peer": true, "bin": { "json5": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/jsonfile": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", + "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "license": "MIT", + "dependencies": { + "universalify": "^2.0.0" + }, + "optionalDependencies": { + "graceful-fs": "^4.1.6" } }, "node_modules/just-extend": { "version": "4.2.1", "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/karma": { "version": "6.4.3", "resolved": "https://registry.npmjs.org/karma/-/karma-6.4.3.tgz", "integrity": "sha512-LuucC/RE92tJ8mlCwqEoRWXP38UMAqpnq98vktmS9SznSoUPPUJQbc91dHcxcunROvfQjdORVA/YFviH+Xci9Q==", "dev": true, + "license": "MIT", "dependencies": { "@colors/colors": "1.5.0", "body-parser": "^1.19.0", - "braces": "^3.0.3", + "braces": "^3.0.2", "chokidar": "^3.5.1", "connect": "^3.7.0", "di": "^0.0.1", @@ -9263,6 +8927,7 @@ "resolved": "https://registry.npmjs.org/karma-chai/-/karma-chai-0.1.0.tgz", "integrity": "sha512-mqKCkHwzPMhgTYca10S90aCEX9+HjVjjrBFAsw36Zj7BlQNbokXXCAe6Ji04VUMsxcY5RLP7YphpfO06XOubdg==", "dev": true, + "license": "MIT", "peerDependencies": { "chai": "*", "karma": ">=0.10.9" @@ -9273,6 +8938,7 @@ "resolved": "https://registry.npmjs.org/karma-chrome-launcher/-/karma-chrome-launcher-3.2.0.tgz", "integrity": "sha512-rE9RkUPI7I9mAxByQWkGJFXfFD6lE4gC5nPuZdobf/QdTEJI6EU4yIay/cfU/xV4ZxlM5JiTv7zWYgA64NpS5Q==", "dev": true, + "license": "MIT", "dependencies": { "which": "^1.2.1" } @@ -9282,6 +8948,7 @@ "resolved": "https://registry.npmjs.org/which/-/which-1.3.1.tgz", "integrity": "sha512-HxJdYWq1MTIQbJ3nw0cqssHoTNU267KlrDuGZ1WYlxDStUtKUhOaJmh112/TZmHxxUfuJqPXSOm7tDyas0OSIQ==", "dev": true, + "license": "ISC", "dependencies": { "isexe": "^2.0.0" }, @@ -9294,6 +8961,7 @@ "resolved": "https://registry.npmjs.org/karma-mocha/-/karma-mocha-2.0.1.tgz", "integrity": "sha512-Tzd5HBjm8his2OA4bouAsATYEpZrp9vC7z5E5j4C5Of5Rrs1jY67RAwXNcVmd/Bnk1wgvQRou0zGVLey44G4tQ==", "dev": true, + "license": "MIT", "dependencies": { "minimist": "^1.2.3" } @@ -9303,6 +8971,7 @@ "resolved": "https://registry.npmjs.org/karma-sinon-chai/-/karma-sinon-chai-2.0.2.tgz", "integrity": "sha512-SDgh6V0CUd+7ruL1d3yG6lFzmJNGRNQuEuCYXLaorruNP9nwQfA7hpsp4clx4CbOo5Gsajh3qUOT7CrVStUKMw==", "dev": true, + "license": "MIT", "peerDependencies": { "chai": ">=3.5.0", "sinon": ">=2.1.0", @@ -9314,6 +8983,7 @@ "resolved": "https://registry.npmjs.org/karma-sourcemap-loader/-/karma-sourcemap-loader-0.3.8.tgz", "integrity": "sha512-zorxyAakYZuBcHRJE+vbrK2o2JXLFWK8VVjiT/6P+ltLBUGUvqTEkUiQ119MGdOrK7mrmxXHZF1/pfT6GgIZ6g==", "dev": true, + "license": "MIT", "dependencies": { "graceful-fs": "^4.1.2" } @@ -9323,6 +8993,7 @@ "resolved": "https://registry.npmjs.org/karma-spec-reporter/-/karma-spec-reporter-0.0.32.tgz", "integrity": "sha512-ZXsYERZJMTNRR2F3QN11OWF5kgnT/K2dzhM+oY3CDyMrDI3TjIWqYGG7c15rR9wjmy9lvdC+CCshqn3YZqnNrA==", "dev": true, + "license": "MIT", "dependencies": { "colors": "^1.1.2" }, @@ -9335,6 +9006,7 @@ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", "dev": true, + "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -9344,7 +9016,9 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", "dev": true, + "license": "ISC", "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -9365,6 +9039,7 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", "dev": true, + "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" }, @@ -9372,23 +9047,12 @@ "node": "*" } }, - "node_modules/karma/node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "dev": true, - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==", "dev": true, + "license": "MIT", "dependencies": { "json-buffer": "3.0.1" } @@ -9397,25 +9061,19 @@ "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", "integrity": "sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==", + "license": "MIT", "peer": true, "engines": { "node": ">=0.10.0" } }, - "node_modules/kleur": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/kleur/-/kleur-3.0.3.tgz", - "integrity": "sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w==", - "peer": true, - "engines": { - "node": ">=6" - } - }, "node_modules/knuth-shuffle-seeded": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/knuth-shuffle-seeded/-/knuth-shuffle-seeded-1.0.6.tgz", "integrity": "sha512-9pFH0SplrfyKyojCLxZfMcvkhf5hH0d+UwR9nTVJ/DDQJGuzcXjTwB7TP7sDfehSudlGGaOLblmEWqv04ERVWg==", "dev": true, + "license": "Apache-2.0", + "peer": true, "dependencies": { "seed-random": "~2.2.0" } @@ -9424,6 +9082,7 @@ "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", "integrity": "sha512-qsda+H8jTaUaN/x5vzW2rzc+8Rw4TAQ/4KjB46IwK5VH+IlVeeeje/EoZRpiXvIqjFgK84QffqPztGI3VBLG1A==", + "license": "MIT", "peer": true, "engines": { "node": ">=6" @@ -9434,6 +9093,7 @@ "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", "dev": true, + "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1", "type-check": "~0.4.0" @@ -9446,6 +9106,7 @@ "version": "1.4.2", "resolved": "https://registry.npmjs.org/lighthouse-logger/-/lighthouse-logger-1.4.2.tgz", "integrity": "sha512-gPWxznF6TKmUHrOQjlVo2UbaL2EJ71mb2CCeRs/2qBpi4L/g4LUVc9+3lKQ6DTUZwJswfM7ainGrLO1+fOqa2g==", + "license": "Apache-2.0", "peer": true, "dependencies": { "debug": "^2.6.9", @@ -9456,6 +9117,7 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", "peer": true, "dependencies": { "ms": "2.0.0" @@ -9465,287 +9127,121 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT", "peer": true }, "node_modules/lil-uuid": { "version": "0.1.1", "resolved": "https://registry.npmjs.org/lil-uuid/-/lil-uuid-0.1.1.tgz", - "integrity": "sha512-GhWI8f61tBlMeqULZ1QWhFiiyFIFdPlg//S8Udq1wjq1FJhpFKTfnbduSxAQjueofeUtpr7UvQ/lIK/sKUF8dg==" + "integrity": "sha512-GhWI8f61tBlMeqULZ1QWhFiiyFIFdPlg//S8Udq1wjq1FJhpFKTfnbduSxAQjueofeUtpr7UvQ/lIK/sKUF8dg==", + "license": "MIT" }, "node_modules/lines-and-columns": { "version": "1.2.4", "resolved": "https://registry.npmjs.org/lines-and-columns/-/lines-and-columns-1.2.4.tgz", "integrity": "sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==", - "dev": true - }, - "node_modules/locate-path": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", - "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", - "dependencies": { - "p-locate": "^5.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true - }, - "node_modules/lodash.debounce": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", - "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==", - "peer": true - }, - "node_modules/lodash.merge": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", - "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", - "dev": true - }, - "node_modules/lodash.mergewith": { - "version": "4.6.2", - "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz", - "integrity": "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==", - "dev": true - }, - "node_modules/lodash.throttle": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz", - "integrity": "sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==", - "peer": true - }, - "node_modules/log-symbols": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", - "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", - "dependencies": { - "chalk": "^4.1.0", - "is-unicode-supported": "^0.1.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/log4js": { - "version": "6.9.1", - "resolved": "https://registry.npmjs.org/log4js/-/log4js-6.9.1.tgz", - "integrity": "sha512-1somDdy9sChrr9/f4UlzhdaGfDR2c/SaD2a4T7qEkG4jTS57/B3qmnjLYePwQ8cqWnUHZI0iAKxMBpCZICiZ2g==", "dev": true, - "dependencies": { - "date-format": "^4.0.14", - "debug": "^4.3.4", - "flatted": "^3.2.7", - "rfdc": "^1.3.0", - "streamroller": "^3.1.5" - }, - "engines": { - "node": ">=8.0" - } - }, - "node_modules/logkitty": { - "version": "0.7.1", - "resolved": "https://registry.npmjs.org/logkitty/-/logkitty-0.7.1.tgz", - "integrity": "sha512-/3ER20CTTbahrCrpYfPn7Xavv9diBROZpoXGVZDWMw4b/X4uuUwAC0ki85tgsdMRONURyIJbcOvS94QsUBYPbQ==", - "peer": true, - "dependencies": { - "ansi-fragments": "^0.2.1", - "dayjs": "^1.8.15", - "yargs": "^15.1.0" - }, - "bin": { - "logkitty": "bin/logkitty.js" - } - }, - "node_modules/logkitty/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "peer": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/logkitty/node_modules/camelcase": { - "version": "5.3.1", - "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", - "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==", - "peer": true, - "engines": { - "node": ">=6" - } - }, - "node_modules/logkitty/node_modules/cliui": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", - "integrity": "sha512-t6wbgtoCXvAzst7QgXxJYqPt0usEfbgQdftEPbLL/cvv6HPE5VgvqCuAIDR0NgU52ds6rFwqrgakNLrHEjCbrQ==", - "peer": true, - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^6.2.0" - } - }, - "node_modules/logkitty/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "peer": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/logkitty/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "license": "MIT", "peer": true }, - "node_modules/logkitty/node_modules/decamelize": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", - "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==", - "peer": true, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/logkitty/node_modules/find-up": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", - "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", - "peer": true, - "dependencies": { - "locate-path": "^5.0.0", - "path-exists": "^4.0.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/logkitty/node_modules/locate-path": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", - "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", - "peer": true, - "dependencies": { - "p-locate": "^4.1.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/logkitty/node_modules/p-limit": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", - "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", - "peer": true, - "dependencies": { - "p-try": "^2.0.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/logkitty/node_modules/p-locate": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", - "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", - "peer": true, - "dependencies": { - "p-limit": "^2.2.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/logkitty/node_modules/wrap-ansi": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-6.2.0.tgz", - "integrity": "sha512-r6lPcBGxZXlIcymEu7InxDMhdW0KDxpLgoFLcguasxCaJ/SOIZwINatK9KY/tf+ZrlywOKU0UDj3ATXUBfxJXA==", - "peer": true, + "node_modules/locate-path": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", + "integrity": "sha512-iPZK6eYjbxRu3uB4/WZ3EsEIMJFMqAoopl3R+zuq0UjcAm/MO6KCweDgPfP3elTztoKP3KtnVHxTn2NHBSDVUw==", + "dev": true, + "license": "MIT", "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" + "p-locate": "^5.0.0" }, "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/logkitty/node_modules/y18n": { - "version": "4.0.3", - "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.3.tgz", - "integrity": "sha512-JKhqTOwSrqNA1NY5lSztJ1GrBiUodLMmIZuLiDaMRJ+itFd+ABVE8XBjOvIWL+rSqNDC74LCSFmlb/U4UZ4hJQ==", + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.debounce": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", + "integrity": "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow==", + "license": "MIT", "peer": true }, - "node_modules/logkitty/node_modules/yargs": { - "version": "15.4.1", - "resolved": "https://registry.npmjs.org/yargs/-/yargs-15.4.1.tgz", - "integrity": "sha512-aePbxDmcYW++PaqBsJ+HYUFwCdv4LVvdnhBy78E57PIor8/OVvhMrADFFEDh8DHDFRv/O9i3lPhsENjO7QX0+A==", - "peer": true, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true, + "license": "MIT" + }, + "node_modules/lodash.mergewith": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.mergewith/-/lodash.mergewith-4.6.2.tgz", + "integrity": "sha512-GK3g5RPZWTRSeLSpgP8Xhra+pnjBC56q9FZYe1d5RN3TJ35dbkGy3YqBSMbyCrlbi+CM9Z3Jk5yTL7RCsqboyQ==", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/lodash.throttle": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz", + "integrity": "sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==", + "license": "MIT", + "peer": true + }, + "node_modules/log-symbols": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-4.1.0.tgz", + "integrity": "sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==", + "dev": true, + "license": "MIT", "dependencies": { - "cliui": "^6.0.0", - "decamelize": "^1.2.0", - "find-up": "^4.1.0", - "get-caller-file": "^2.0.1", - "require-directory": "^2.1.1", - "require-main-filename": "^2.0.0", - "set-blocking": "^2.0.0", - "string-width": "^4.2.0", - "which-module": "^2.0.0", - "y18n": "^4.0.0", - "yargs-parser": "^18.1.2" + "chalk": "^4.1.0", + "is-unicode-supported": "^0.1.0" }, "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/logkitty/node_modules/yargs-parser": { - "version": "18.1.3", - "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.3.tgz", - "integrity": "sha512-o50j0JeToy/4K6OZcaQmW6lyXXKhq7csREXcDwk2omFPJEwUNOVtJKvmDr9EI1fAJZUyZcRF7kxGBWmRXudrCQ==", - "peer": true, + "node_modules/log4js": { + "version": "6.9.1", + "resolved": "https://registry.npmjs.org/log4js/-/log4js-6.9.1.tgz", + "integrity": "sha512-1somDdy9sChrr9/f4UlzhdaGfDR2c/SaD2a4T7qEkG4jTS57/B3qmnjLYePwQ8cqWnUHZI0iAKxMBpCZICiZ2g==", + "dev": true, + "license": "Apache-2.0", "dependencies": { - "camelcase": "^5.0.0", - "decamelize": "^1.2.0" + "date-format": "^4.0.14", + "debug": "^4.3.4", + "flatted": "^3.2.7", + "rfdc": "^1.3.0", + "streamroller": "^3.1.5" }, "engines": { - "node": ">=6" + "node": ">=8.0" } }, "node_modules/lolex": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/lolex/-/lolex-4.2.0.tgz", "integrity": "sha512-gKO5uExCXvSm6zbF562EvM+rd1kQDnB9AZBbiQVzf1ZmdDpxUSvpnAaVOP83N/31mRK8Ml8/VE8DMvsAZQ+7wg==", - "dev": true + "dev": true, + "license": "BSD-3-Clause" }, "node_modules/loose-envify": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", + "license": "MIT", "peer": true, "dependencies": { "js-tokens": "^3.0.0 || ^4.0.0" @@ -9759,6 +9255,7 @@ "resolved": "https://registry.npmjs.org/loupe/-/loupe-2.3.7.tgz", "integrity": "sha512-zSMINGVYkdpYSOBmLi0D1Uo7JU9nVdQKrHxC8eYlV+9YKK9WePqAlL7lSlorG/U2Fw1w0hTBmaa/jrQ3UbPHtA==", "dev": true, + "license": "MIT", "dependencies": { "get-func-name": "^2.0.1" } @@ -9768,17 +9265,19 @@ "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-2.0.2.tgz", "integrity": "sha512-7fm3l3NAF9WfN6W3JOmf5drwpVqX78JtoGJ3A6W0a6ZnldM41w2fV5D490psKFTpMds8TJse/eHLFFsNHHjHgg==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "tslib": "^2.0.3" } }, "node_modules/lru-cache": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.2.0.tgz", - "integrity": "sha512-2bIM8x+VAf6JT4bKAljS1qUWgMsqZRPGJS6FSahIMPVvctcNhyVp7AJu7quxOW9jwkryBReKZY5tY5JYv2n/7Q==", - "dev": true, + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "license": "ISC", "engines": { - "node": "14 || >=16.14" + "node": ">=12" } }, "node_modules/luxon": { @@ -9786,23 +9285,27 @@ "resolved": "https://registry.npmjs.org/luxon/-/luxon-3.2.1.tgz", "integrity": "sha512-QrwPArQCNLAKGO/C+ZIilgIuDnEnKx5QYODdDtbFaxzsbZcc/a7WFq7MhsVYgRlwawLtvOUESTlfJ+hc/USqPg==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=12" } }, "node_modules/magic-string": { - "version": "0.30.10", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz", - "integrity": "sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==", + "version": "0.30.12", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.12.tgz", + "integrity": "sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==", "dev": true, + "license": "MIT", "dependencies": { - "@jridgewell/sourcemap-codec": "^1.4.15" + "@jridgewell/sourcemap-codec": "^1.5.0" } }, "node_modules/make-dir": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-2.1.0.tgz", "integrity": "sha512-LS9X+dc8KLxXCb8dni79fLIIUA5VyZoyjSMCwTluaXA0o27cCK0bhXkpgw+sTXVpPy/lSO57ilRixqk0vDmtRA==", + "license": "MIT", "peer": true, "dependencies": { "pify": "^4.0.1", @@ -9816,6 +9319,7 @@ "version": "5.7.2", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", + "license": "ISC", "peer": true, "bin": { "semver": "bin/semver" @@ -9825,12 +9329,14 @@ "version": "1.3.6", "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", - "dev": true + "dev": true, + "license": "ISC" }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", "integrity": "sha512-JmqCvUhmt43madlpFzG4BQzG2Z3m6tvQDNKdClZnO3VbIudJYmxsT0FNJMeiB2+JTSlTQTSbU8QdesVmwJcmLg==", + "license": "BSD-3-Clause", "peer": true, "dependencies": { "tmpl": "1.0.5" @@ -9840,6 +9346,7 @@ "version": "1.2.5", "resolved": "https://registry.npmjs.org/marky/-/marky-1.2.5.tgz", "integrity": "sha512-q9JtQJKjpsVxCRVgQ+WapguSbKC3SQ5HEzFGPAJMStgh3QjCawp00UKv3MTTAArTmGmmPUvllHZoNbZ3gs0I+Q==", + "license": "Apache-2.0", "peer": true }, "node_modules/media-typer": { @@ -9847,6 +9354,7 @@ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", "integrity": "sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -9855,12 +9363,14 @@ "version": "5.2.1", "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz", "integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q==", + "license": "MIT", "peer": true }, "node_modules/merge-stream": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/merge-stream/-/merge-stream-2.0.0.tgz", "integrity": "sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w==", + "license": "MIT", "peer": true }, "node_modules/merge2": { @@ -9868,23 +9378,25 @@ "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", "integrity": "sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==", "dev": true, + "license": "MIT", "engines": { "node": ">= 8" } }, "node_modules/metro": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro/-/metro-0.80.8.tgz", - "integrity": "sha512-in7S0W11mg+RNmcXw+2d9S3zBGmCARDxIwoXJAmLUQOQoYsRP3cpGzyJtc7WOw8+FXfpgXvceD0u+PZIHXEL7g==", - "peer": true, - "dependencies": { - "@babel/code-frame": "^7.0.0", - "@babel/core": "^7.20.0", - "@babel/generator": "^7.20.0", - "@babel/parser": "^7.20.0", - "@babel/template": "^7.0.0", - "@babel/traverse": "^7.20.0", - "@babel/types": "^7.20.0", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro/-/metro-0.81.0.tgz", + "integrity": "sha512-kzdzmpL0gKhEthZ9aOV7sTqvg6NuTxDV8SIm9pf9sO8VVEbKrQk5DNcwupOUjgPPFAuKUc2NkT0suyT62hm2xg==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.24.7", + "@babel/core": "^7.25.2", + "@babel/generator": "^7.25.0", + "@babel/parser": "^7.25.3", + "@babel/template": "^7.25.0", + "@babel/traverse": "^7.25.3", + "@babel/types": "^7.25.2", "accepts": "^1.3.7", "chalk": "^4.0.0", "ci-info": "^2.0.0", @@ -9892,134 +9404,149 @@ "debug": "^2.2.0", "denodeify": "^1.2.1", "error-stack-parser": "^2.0.6", + "flow-enums-runtime": "^0.0.6", "graceful-fs": "^4.2.4", - "hermes-parser": "0.20.1", + "hermes-parser": "0.24.0", "image-size": "^1.0.2", "invariant": "^2.2.4", "jest-worker": "^29.6.3", "jsc-safe-url": "^0.2.2", "lodash.throttle": "^4.1.1", - "metro-babel-transformer": "0.80.8", - "metro-cache": "0.80.8", - "metro-cache-key": "0.80.8", - "metro-config": "0.80.8", - "metro-core": "0.80.8", - "metro-file-map": "0.80.8", - "metro-resolver": "0.80.8", - "metro-runtime": "0.80.8", - "metro-source-map": "0.80.8", - "metro-symbolicate": "0.80.8", - "metro-transform-plugins": "0.80.8", - "metro-transform-worker": "0.80.8", + "metro-babel-transformer": "0.81.0", + "metro-cache": "0.81.0", + "metro-cache-key": "0.81.0", + "metro-config": "0.81.0", + "metro-core": "0.81.0", + "metro-file-map": "0.81.0", + "metro-resolver": "0.81.0", + "metro-runtime": "0.81.0", + "metro-source-map": "0.81.0", + "metro-symbolicate": "0.81.0", + "metro-transform-plugins": "0.81.0", + "metro-transform-worker": "0.81.0", "mime-types": "^2.1.27", - "node-fetch": "^2.2.0", "nullthrows": "^1.1.1", - "rimraf": "^3.0.2", "serialize-error": "^2.1.0", "source-map": "^0.5.6", "strip-ansi": "^6.0.0", "throat": "^5.0.0", - "ws": "^7.5.1", + "ws": "^7.5.10", "yargs": "^17.6.2" }, "bin": { "metro": "src/cli.js" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-babel-transformer": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-babel-transformer/-/metro-babel-transformer-0.80.8.tgz", - "integrity": "sha512-TTzNwRZb2xxyv4J/+yqgtDAP2qVqH3sahsnFu6Xv4SkLqzrivtlnyUbaeTdJ9JjtADJUEjCbgbFgUVafrXdR9Q==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-babel-transformer/-/metro-babel-transformer-0.81.0.tgz", + "integrity": "sha512-Dc0QWK4wZIeHnyZ3sevWGTnnSkIDDn/SWyfrn99zbKbDOCoCYy71PAn9uCRrP/hduKLJQOy+tebd63Rr9D8tXg==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/core": "^7.20.0", - "hermes-parser": "0.20.1", + "@babel/core": "^7.25.2", + "flow-enums-runtime": "^0.0.6", + "hermes-parser": "0.24.0", "nullthrows": "^1.1.1" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-babel-transformer/node_modules/hermes-estree": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.20.1.tgz", - "integrity": "sha512-SQpZK4BzR48kuOg0v4pb3EAGNclzIlqMj3Opu/mu7bbAoFw6oig6cEt/RAi0zTFW/iW6Iz9X9ggGuZTAZ/yZHg==", + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.24.0.tgz", + "integrity": "sha512-LyoXLB7IFzeZW0EvAbGZacbxBN7t6KKSDqFJPo3Ydow7wDlrDjXwsdiAHV6XOdvEN9MEuWXsSIFN4tzpyrXIHw==", + "license": "MIT", "peer": true }, "node_modules/metro-babel-transformer/node_modules/hermes-parser": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.20.1.tgz", - "integrity": "sha512-BL5P83cwCogI8D7rrDCgsFY0tdYUtmFP9XaXtl2IQjC+2Xo+4okjfXintlTxcIwl4qeGddEl28Z11kbVIw0aNA==", + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.24.0.tgz", + "integrity": "sha512-IJooSvvu2qNRe7oo9Rb04sUT4omtZqZqf9uq9WM25Tb6v3usmvA93UqfnnoWs5V0uYjEl9Al6MNU10MCGKLwpg==", + "license": "MIT", "peer": true, "dependencies": { - "hermes-estree": "0.20.1" + "hermes-estree": "0.24.0" } }, "node_modules/metro-cache": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-cache/-/metro-cache-0.80.8.tgz", - "integrity": "sha512-5svz+89wSyLo7BxdiPDlwDTgcB9kwhNMfNhiBZPNQQs1vLFXxOkILwQiV5F2EwYT9DEr6OPZ0hnJkZfRQ8lDYQ==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-cache/-/metro-cache-0.81.0.tgz", + "integrity": "sha512-DyuqySicHXkHUDZFVJmh0ygxBSx6pCKUrTcSgb884oiscV/ROt1Vhye+x+OIHcsodyA10gzZtrVtxIFV4l9I4g==", + "license": "MIT", "peer": true, "dependencies": { - "metro-core": "0.80.8", - "rimraf": "^3.0.2" + "exponential-backoff": "^3.1.1", + "flow-enums-runtime": "^0.0.6", + "metro-core": "0.81.0" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-cache-key": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-cache-key/-/metro-cache-key-0.80.8.tgz", - "integrity": "sha512-qWKzxrLsRQK5m3oH8ePecqCc+7PEhR03cJE6Z6AxAj0idi99dHOSitTmY0dclXVB9vP2tQIAE8uTd8xkYGk8fA==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-cache-key/-/metro-cache-key-0.81.0.tgz", + "integrity": "sha512-qX/IwtknP9bQZL78OK9xeSvLM/xlGfrs6SlUGgHvrxtmGTRSsxcyqxR+c+7ch1xr05n62Gin/O44QKg5V70rNQ==", + "license": "MIT", "peer": true, + "dependencies": { + "flow-enums-runtime": "^0.0.6" + }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-config": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-config/-/metro-config-0.80.8.tgz", - "integrity": "sha512-VGQJpfJawtwRzGzGXVUoohpIkB0iPom4DmSbAppKfumdhtLA8uVeEPp2GM61kL9hRvdbMhdWA7T+hZFDlo4mJA==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-config/-/metro-config-0.81.0.tgz", + "integrity": "sha512-6CinEaBe3WLpRlKlYXXu8r1UblJhbwD6Gtnoib5U8j6Pjp7XxMG9h/DGMeNp9aGLDu1OieUqiXpFo7O0/rR5Kg==", + "license": "MIT", "peer": true, "dependencies": { "connect": "^3.6.5", "cosmiconfig": "^5.0.5", + "flow-enums-runtime": "^0.0.6", "jest-validate": "^29.6.3", - "metro": "0.80.8", - "metro-cache": "0.80.8", - "metro-core": "0.80.8", - "metro-runtime": "0.80.8" + "metro": "0.81.0", + "metro-cache": "0.81.0", + "metro-core": "0.81.0", + "metro-runtime": "0.81.0" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-core": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-core/-/metro-core-0.80.8.tgz", - "integrity": "sha512-g6lud55TXeISRTleW6SHuPFZHtYrpwNqbyFIVd9j9Ofrb5IReiHp9Zl8xkAfZQp8v6ZVgyXD7c130QTsCz+vBw==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-core/-/metro-core-0.81.0.tgz", + "integrity": "sha512-CVkM5YCOAFkNMvJai6KzA0RpztzfEKRX62/PFMOJ9J7K0uq/UkOFLxcgpcncMIrfy0PbfEj811b69tjULUQe1Q==", + "license": "MIT", "peer": true, "dependencies": { + "flow-enums-runtime": "^0.0.6", "lodash.throttle": "^4.1.1", - "metro-resolver": "0.80.8" + "metro-resolver": "0.81.0" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-file-map": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-file-map/-/metro-file-map-0.80.8.tgz", - "integrity": "sha512-eQXMFM9ogTfDs2POq7DT2dnG7rayZcoEgRbHPXvhUWkVwiKkro2ngcBE++ck/7A36Cj5Ljo79SOkYwHaWUDYDw==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-file-map/-/metro-file-map-0.81.0.tgz", + "integrity": "sha512-zMDI5uYhQCyxbye/AuFx/pAbsz9K+vKL7h1ShUXdN2fz4VUPiyQYRsRqOoVG1DsiCgzd5B6LW0YW77NFpjDQeg==", + "license": "MIT", "peer": true, "dependencies": { "anymatch": "^3.0.3", "debug": "^2.2.0", "fb-watchman": "^2.0.0", + "flow-enums-runtime": "^0.0.6", "graceful-fs": "^4.2.4", "invariant": "^2.2.4", "jest-worker": "^29.6.3", @@ -10029,7 +9556,7 @@ "walker": "^1.0.7" }, "engines": { - "node": ">=18" + "node": ">=18.18" }, "optionalDependencies": { "fsevents": "^2.3.2" @@ -10039,6 +9566,7 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", "peer": true, "dependencies": { "ms": "2.0.0" @@ -10048,77 +9576,92 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT", "peer": true }, "node_modules/metro-minify-terser": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-minify-terser/-/metro-minify-terser-0.80.8.tgz", - "integrity": "sha512-y8sUFjVvdeUIINDuW1sejnIjkZfEF+7SmQo0EIpYbWmwh+kq/WMj74yVaBWuqNjirmUp1YNfi3alT67wlbBWBQ==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-minify-terser/-/metro-minify-terser-0.81.0.tgz", + "integrity": "sha512-U2ramh3W822ZR1nfXgIk+emxsf5eZSg10GbQrT0ZizImK8IZ5BmJY+BHRIkQgHzWFpExOVxC7kWbGL1bZALswA==", + "license": "MIT", "peer": true, "dependencies": { + "flow-enums-runtime": "^0.0.6", "terser": "^5.15.0" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-resolver": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.80.8.tgz", - "integrity": "sha512-JdtoJkP27GGoZ2HJlEsxs+zO7jnDUCRrmwXJozTlIuzLHMRrxgIRRby9fTCbMhaxq+iA9c+wzm3iFb4NhPmLbQ==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.81.0.tgz", + "integrity": "sha512-Uu2Q+buHhm571cEwpPek8egMbdSTqmwT/5U7ZVNpK6Z2ElQBBCxd7HmFAslKXa7wgpTO2FAn6MqGeERbAtVDUA==", + "license": "MIT", "peer": true, + "dependencies": { + "flow-enums-runtime": "^0.0.6" + }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-runtime": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-runtime/-/metro-runtime-0.80.8.tgz", - "integrity": "sha512-2oScjfv6Yb79PelU1+p8SVrCMW9ZjgEiipxq7jMRn8mbbtWzyv3g8Mkwr+KwOoDFI/61hYPUbY8cUnu278+x1g==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-runtime/-/metro-runtime-0.81.0.tgz", + "integrity": "sha512-6oYB5HOt37RuGz2eV4A6yhcl+PUTwJYLDlY9vhT+aVjbUWI6MdBCf69vc4f5K5Vpt+yOkjy+2LDwLS0ykWFwYw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/runtime": "^7.0.0" + "@babel/runtime": "^7.25.0", + "flow-enums-runtime": "^0.0.6" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-source-map": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-source-map/-/metro-source-map-0.80.8.tgz", - "integrity": "sha512-+OVISBkPNxjD4eEKhblRpBf463nTMk3KMEeYS8Z4xM/z3qujGJGSsWUGRtH27+c6zElaSGtZFiDMshEb8mMKQg==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-source-map/-/metro-source-map-0.81.0.tgz", + "integrity": "sha512-TzsVxhH83dyxg4A4+L1nzNO12I7ps5IHLjKGZH3Hrf549eiZivkdjYiq/S5lOB+p2HiQ+Ykcwtmcja95LIC62g==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/traverse": "^7.20.0", - "@babel/types": "^7.20.0", + "@babel/traverse": "^7.25.3", + "@babel/traverse--for-generate-function-map": "npm:@babel/traverse@^7.25.3", + "@babel/types": "^7.25.2", + "flow-enums-runtime": "^0.0.6", "invariant": "^2.2.4", - "metro-symbolicate": "0.80.8", + "metro-symbolicate": "0.81.0", "nullthrows": "^1.1.1", - "ob1": "0.80.8", + "ob1": "0.81.0", "source-map": "^0.5.6", "vlq": "^1.0.0" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-source-map/node_modules/source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "license": "BSD-3-Clause", "peer": true, "engines": { "node": ">=0.10.0" } }, "node_modules/metro-symbolicate": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-symbolicate/-/metro-symbolicate-0.80.8.tgz", - "integrity": "sha512-nwhYySk79jQhwjL9QmOUo4wS+/0Au9joEryDWw7uj4kz2yvw1uBjwmlql3BprQCBzRdB3fcqOP8kO8Es+vE31g==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-symbolicate/-/metro-symbolicate-0.81.0.tgz", + "integrity": "sha512-C/1rWbNTPYp6yzID8IPuQPpVGzJ2rbWYBATxlvQ9dfK5lVNoxcwz77hjcY8ISLsRRR15hyd/zbjCNKPKeNgE1Q==", + "license": "MIT", "peer": true, "dependencies": { + "flow-enums-runtime": "^0.0.6", "invariant": "^2.2.4", - "metro-source-map": "0.80.8", + "metro-source-map": "0.81.0", "nullthrows": "^1.1.1", "source-map": "^0.5.6", "through2": "^2.0.1", @@ -10128,82 +9671,74 @@ "metro-symbolicate": "src/index.js" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-symbolicate/node_modules/source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "license": "BSD-3-Clause", "peer": true, "engines": { "node": ">=0.10.0" } }, "node_modules/metro-transform-plugins": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-transform-plugins/-/metro-transform-plugins-0.80.8.tgz", - "integrity": "sha512-sSu8VPL9Od7w98MftCOkQ1UDeySWbsIAS5I54rW22BVpPnI3fQ42srvqMLaJUQPjLehUanq8St6OMBCBgH/UWw==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-transform-plugins/-/metro-transform-plugins-0.81.0.tgz", + "integrity": "sha512-uErLAPBvttGCrmGSCa0dNHlOTk3uJFVEVWa5WDg6tQ79PRmuYRwzUgLhVzn/9/kyr75eUX3QWXN79Jvu4txt6Q==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/core": "^7.20.0", - "@babel/generator": "^7.20.0", - "@babel/template": "^7.0.0", - "@babel/traverse": "^7.20.0", + "@babel/core": "^7.25.2", + "@babel/generator": "^7.25.0", + "@babel/template": "^7.25.0", + "@babel/traverse": "^7.25.3", + "flow-enums-runtime": "^0.0.6", "nullthrows": "^1.1.1" }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/metro-transform-worker": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/metro-transform-worker/-/metro-transform-worker-0.80.8.tgz", - "integrity": "sha512-+4FG3TQk3BTbNqGkFb2uCaxYTfsbuFOCKMMURbwu0ehCP8ZJuTUramkaNZoATS49NSAkRgUltgmBa4YaKZ5mqw==", - "peer": true, - "dependencies": { - "@babel/core": "^7.20.0", - "@babel/generator": "^7.20.0", - "@babel/parser": "^7.20.0", - "@babel/types": "^7.20.0", - "metro": "0.80.8", - "metro-babel-transformer": "0.80.8", - "metro-cache": "0.80.8", - "metro-cache-key": "0.80.8", - "metro-minify-terser": "0.80.8", - "metro-source-map": "0.80.8", - "metro-transform-plugins": "0.80.8", - "nullthrows": "^1.1.1" - }, - "engines": { - "node": ">=18" - } - }, - "node_modules/metro/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/metro-transform-worker/-/metro-transform-worker-0.81.0.tgz", + "integrity": "sha512-HrQ0twiruhKy0yA+9nK5bIe3WQXZcC66PXTvRIos61/EASLAP2DzEmW7IxN/MGsfZegN2UzqL2CG38+mOB45vg==", + "license": "MIT", "peer": true, "dependencies": { - "color-convert": "^2.0.1" + "@babel/core": "^7.25.2", + "@babel/generator": "^7.25.0", + "@babel/parser": "^7.25.3", + "@babel/types": "^7.25.2", + "flow-enums-runtime": "^0.0.6", + "metro": "0.81.0", + "metro-babel-transformer": "0.81.0", + "metro-cache": "0.81.0", + "metro-cache-key": "0.81.0", + "metro-minify-terser": "0.81.0", + "metro-source-map": "0.81.0", + "metro-transform-plugins": "0.81.0", + "nullthrows": "^1.1.1" }, "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "node": ">=18.18" } }, "node_modules/metro/node_modules/ci-info": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ci-info/-/ci-info-2.0.0.tgz", "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", + "license": "MIT", "peer": true }, "node_modules/metro/node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "license": "ISC", "peer": true, "dependencies": { "string-width": "^4.2.0", @@ -10214,93 +9749,55 @@ "node": ">=12" } }, - "node_modules/metro/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "peer": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/metro/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "peer": true - }, "node_modules/metro/node_modules/debug": { "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", "peer": true, "dependencies": { "ms": "2.0.0" } }, "node_modules/metro/node_modules/hermes-estree": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.20.1.tgz", - "integrity": "sha512-SQpZK4BzR48kuOg0v4pb3EAGNclzIlqMj3Opu/mu7bbAoFw6oig6cEt/RAi0zTFW/iW6Iz9X9ggGuZTAZ/yZHg==", + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.24.0.tgz", + "integrity": "sha512-LyoXLB7IFzeZW0EvAbGZacbxBN7t6KKSDqFJPo3Ydow7wDlrDjXwsdiAHV6XOdvEN9MEuWXsSIFN4tzpyrXIHw==", + "license": "MIT", "peer": true }, "node_modules/metro/node_modules/hermes-parser": { - "version": "0.20.1", - "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.20.1.tgz", - "integrity": "sha512-BL5P83cwCogI8D7rrDCgsFY0tdYUtmFP9XaXtl2IQjC+2Xo+4okjfXintlTxcIwl4qeGddEl28Z11kbVIw0aNA==", + "version": "0.24.0", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.24.0.tgz", + "integrity": "sha512-IJooSvvu2qNRe7oo9Rb04sUT4omtZqZqf9uq9WM25Tb6v3usmvA93UqfnnoWs5V0uYjEl9Al6MNU10MCGKLwpg==", + "license": "MIT", "peer": true, "dependencies": { - "hermes-estree": "0.20.1" + "hermes-estree": "0.24.0" } }, "node_modules/metro/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT", "peer": true }, - "node_modules/metro/node_modules/serialize-error": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-2.1.0.tgz", - "integrity": "sha512-ghgmKt5o4Tly5yEG/UJp8qTd0AN7Xalw4XBtDEKP655B699qMEtra1WlXeE6WIvdEG481JvRxULKsInq/iNysw==", - "peer": true, - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/metro/node_modules/source-map": { "version": "0.5.7", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.7.tgz", "integrity": "sha512-LbrmJOMUSdEVxIKvdcJzQC+nQhe8FUZQTXQy6+I75skNgn3OoQ0DZA8YnFa7gp8tqtL3KPf1kmo0R5DoApeSGQ==", + "license": "BSD-3-Clause", "peer": true, "engines": { "node": ">=0.10.0" } }, - "node_modules/metro/node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", - "peer": true, - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, "node_modules/metro/node_modules/ws": { - "version": "7.5.9", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", - "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", + "version": "7.5.10", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", + "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", + "license": "MIT", "peer": true, "engines": { "node": ">=8.3.0" @@ -10322,6 +9819,7 @@ "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "license": "MIT", "peer": true, "dependencies": { "cliui": "^8.0.1", @@ -10340,6 +9838,7 @@ "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "license": "ISC", "peer": true, "engines": { "node": ">=12" @@ -10349,6 +9848,7 @@ "version": "4.0.8", "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", + "license": "MIT", "dependencies": { "braces": "^3.0.3", "picomatch": "^2.3.1" @@ -10357,10 +9857,24 @@ "node": ">=8.6" } }, + "node_modules/micromatch/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/mime": { "version": "2.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "dev": true, + "license": "MIT", "bin": { "mime": "cli.js" }, @@ -10372,6 +9886,7 @@ "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -10380,6 +9895,7 @@ "version": "2.1.35", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "license": "MIT", "dependencies": { "mime-db": "1.52.0" }, @@ -10391,16 +9907,18 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", + "license": "MIT", "peer": true, "engines": { "node": ">=6" } }, "node_modules/minimatch": { - "version": "9.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.4.tgz", - "integrity": "sha512-KqWh+VchfxcMNRAJjj2tnsSJdNbHsVgnkBhTNrW7AjVo6OvLtxw8zfT9oLw1JSohlFzJ8jCoTgaoXvJ+kHt6fw==", + "version": "9.0.5", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", + "integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==", "dev": true, + "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" }, @@ -10415,32 +9933,32 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/minipass": { - "version": "7.0.4", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.0.4.tgz", - "integrity": "sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==", + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz", + "integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==", "dev": true, + "license": "ISC", + "peer": true, "engines": { "node": ">=16 || 14 >=14.17" } }, "node_modules/mkdirp": { - "version": "2.1.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.6.tgz", - "integrity": "sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==", - "dev": true, - "bin": { - "mkdirp": "dist/cjs/src/bin.js" - }, - "engines": { - "node": ">=10" + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "license": "MIT", + "dependencies": { + "minimist": "^1.2.6" }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "bin": { + "mkdirp": "bin/cmd.js" } }, "node_modules/mocha": { @@ -10448,6 +9966,7 @@ "resolved": "https://registry.npmjs.org/mocha/-/mocha-10.4.0.tgz", "integrity": "sha512-eqhGB8JKapEYcC4ytX/xrzKforgEc3j1pGlAXVy3eRwrtAy5/nIfT1SvgGzfN0XZZxeLq0aQWkOUAmqIJiv+bA==", "dev": true, + "license": "MIT", "dependencies": { "ansi-colors": "4.1.1", "browser-stdout": "1.3.1", @@ -10482,7 +10001,8 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true + "dev": true, + "license": "Python-2.0" }, "node_modules/mocha/node_modules/chokidar": { "version": "3.5.3", @@ -10495,9 +10015,10 @@ "url": "https://paulmillr.com/funding/" } ], + "license": "MIT", "dependencies": { "anymatch": "~3.1.2", - "braces": "~3.0.3", + "braces": "~3.0.2", "glob-parent": "~5.1.2", "is-binary-path": "~2.1.0", "is-glob": "~4.0.1", @@ -10511,51 +10032,37 @@ "fsevents": "~2.3.2" } }, - "node_modules/mocha/node_modules/diff": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", - "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", - "dev": true, - "engines": { - "node": ">=0.3.1" - } - }, - "node_modules/mocha/node_modules/escape-string-regexp": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", - "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", - "dev": true, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/mocha/node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "node_modules/mocha/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", "dev": true, + "license": "MIT", "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" + "ms": "2.1.2" }, "engines": { - "node": ">=12" + "node": ">=6.0" }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } } }, + "node_modules/mocha/node_modules/debug/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true, + "license": "MIT" + }, "node_modules/mocha/node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", "dev": true, + "license": "ISC", "dependencies": { "is-glob": "^4.0.1" }, @@ -10568,6 +10075,7 @@ "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dev": true, + "license": "MIT", "dependencies": { "argparse": "^2.0.1" }, @@ -10580,6 +10088,7 @@ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.0.1.tgz", "integrity": "sha512-nLDxIFRyhDblz3qMuq+SoRZED4+miJ/G+tdDrjkkkRnjAsBexeGpgjLEQ0blJy7rHhR2b93rhQY4SvyWu9v03g==", "dev": true, + "license": "ISC", "dependencies": { "brace-expansion": "^2.0.1" }, @@ -10587,31 +10096,45 @@ "node": ">=10" } }, - "node_modules/mocha/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "dev": true - }, "node_modules/mocha/node_modules/serialize-javascript": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.0.tgz", "integrity": "sha512-Qr3TosvguFt8ePWqsvRfrKyQXIiW+nGbYpy8XK24NQHE83caxWt+mIymTT19DGFbNWNLfEwsrkSmN64lVWB9ag==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "randombytes": "^2.1.0" } }, + "node_modules/mocha/node_modules/supports-color": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" + } + }, "node_modules/ms": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", - "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" }, "node_modules/mz": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", "integrity": "sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "any-promise": "^1.0.0", "object-assign": "^4.0.1", @@ -10622,12 +10145,14 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/negotiator": { "version": "0.6.3", "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -10636,28 +10161,24 @@ "version": "2.6.2", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", + "license": "MIT", "peer": true }, "node_modules/netmask": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/netmask/-/netmask-2.0.2.tgz", "integrity": "sha512-dBpDMdxv9Irdq66304OLfEmQ9tbNRFnFTuZiLo+bD+r332bBmMJ8GBLXklIXXgxd3+v9+KUnZaUR5PJMa75Gsg==", + "license": "MIT", "engines": { "node": ">= 0.4.0" } }, - "node_modules/next-tick": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/next-tick/-/next-tick-1.1.0.tgz", - "integrity": "sha512-CXdUiJembsNjuToQvxayPZF9Vqht7hewsvy2sOWafLvi2awflj9mOC6bHIg50orX8IJvWKY9wYQ/zB2kogPslQ==", - "dev": true, - "peer": true - }, "node_modules/nise": { "version": "1.5.3", "resolved": "https://registry.npmjs.org/nise/-/nise-1.5.3.tgz", "integrity": "sha512-Ymbac/94xeIrMf59REBPOv0thr+CJVFMhrlAkW/gjCIE58BGQdCj0x7KRCb3yz+Ga2Rz3E9XXSvUyyxqqhjQAQ==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "@sinonjs/formatio": "^3.2.1", "@sinonjs/text-encoding": "^0.7.1", @@ -10666,40 +10187,56 @@ "path-to-regexp": "^1.7.0" } }, + "node_modules/nise/node_modules/@sinonjs/commons": { + "version": "1.8.6", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", + "integrity": "sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "type-detect": "4.0.8" + } + }, "node_modules/nise/node_modules/lolex": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/lolex/-/lolex-5.1.2.tgz", "integrity": "sha512-h4hmjAvHTmd+25JSwrtTIuwbKdwg5NzZVRMLn9saij4SZaepCrTCxPr35H/3bjwfMJtN+t3CX8672UIkglz28A==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "@sinonjs/commons": "^1.7.0" } }, + "node_modules/nise/node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } + }, "node_modules/no-case": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/no-case/-/no-case-3.0.4.tgz", "integrity": "sha512-fgAN3jGAh+RoxUGZHTSOLJIqUc2wmoBwGR4tbpNAKmmovFoWq0OdRkb0VkldReO2a2iBT/OEulG9XSUc10r3zg==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "lower-case": "^2.0.2", "tslib": "^2.0.3" } }, - "node_modules/nocache": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/nocache/-/nocache-3.0.4.tgz", - "integrity": "sha512-WDD0bdg9mbq6F4mRxEYcPWwfA1vxd0mrvKOyxI7Xj/atfRHVeutzuWByG//jfm4uPzp0y4Kj051EORCBSQMycw==", - "peer": true, - "engines": { - "node": ">=12.0.0" - } - }, "node_modules/nock": { - "version": "14.0.0-beta.5", - "resolved": "https://registry.npmjs.org/nock/-/nock-14.0.0-beta.5.tgz", - "integrity": "sha512-u255tf4DYvyErTlPZA9uTfXghiZZy+NflUOFONPVKZ5tP0yaHwKig28zyFOLhu8y5YcCRC+V5vDk4HHileh2iw==", + "version": "14.0.0-beta.15", + "resolved": "https://registry.npmjs.org/nock/-/nock-14.0.0-beta.15.tgz", + "integrity": "sha512-rp72chatxoZbR/2cYHwtb+IX6n6kkanYKGN2PKn4c12JBrj9n4xGUKFykuQHB+Gkz3fynlikFbMH2LI6VoebuQ==", "dev": true, + "license": "MIT", "dependencies": { + "@mswjs/interceptors": "^0.36.4", "json-stringify-safe": "^5.0.1", "propagate": "^2.0.0" }, @@ -10711,12 +10248,14 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.1.1.tgz", "integrity": "sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==", + "license": "MIT", "peer": true }, "node_modules/node-dir": { "version": "0.1.17", "resolved": "https://registry.npmjs.org/node-dir/-/node-dir-0.1.17.tgz", "integrity": "sha512-tmPX422rYgofd4epzrNoOXiE8XFZYOcCq1vD7MAXCDO+O+zndlA2ztdKKMa+EeuBG5tHETpr4ml4RGgpqDCCAg==", + "license": "MIT", "peer": true, "dependencies": { "minimatch": "^3.0.2" @@ -10729,6 +10268,7 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "license": "MIT", "peer": true, "dependencies": { "balanced-match": "^1.0.0", @@ -10739,6 +10279,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "license": "ISC", "peer": true, "dependencies": { "brace-expansion": "^1.1.7" @@ -10751,6 +10292,7 @@ "version": "2.7.0", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "license": "MIT", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -10766,36 +10308,37 @@ } } }, + "node_modules/node-forge": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", + "integrity": "sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==", + "license": "(BSD-3-Clause OR GPL-2.0)", + "peer": true, + "engines": { + "node": ">= 6.13.0" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", "integrity": "sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==", + "license": "MIT", "peer": true }, "node_modules/node-releases": { - "version": "2.0.14", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.14.tgz", - "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==", + "version": "2.0.18", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.18.tgz", + "integrity": "sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g==", + "license": "MIT", "peer": true }, - "node_modules/node-stream-zip": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/node-stream-zip/-/node-stream-zip-1.15.0.tgz", - "integrity": "sha512-LN4fydt9TqhZhThkZIVQnF9cwjU3qmUH9h78Mx/K7d3VvfRqqwthLwJEUOEL0QPZ0XQmNN7be5Ggit5+4dq3Bw==", - "peer": true, - "engines": { - "node": ">=0.12.0" - }, - "funding": { - "type": "github", - "url": "https://github.com/sponsors/antelle" - } - }, "node_modules/normalize-package-data": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.5.0.tgz", "integrity": "sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==", "dev": true, + "license": "BSD-2-Clause", + "peer": true, "dependencies": { "hosted-git-info": "^2.1.4", "resolve": "^1.10.0", @@ -10808,6 +10351,8 @@ "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.2.tgz", "integrity": "sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g==", "dev": true, + "license": "ISC", + "peer": true, "bin": { "semver": "bin/semver" } @@ -10816,6 +10361,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -10824,6 +10370,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", + "license": "MIT", "peer": true, "dependencies": { "path-key": "^3.0.0" @@ -10836,21 +10383,28 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/nullthrows/-/nullthrows-1.1.1.tgz", "integrity": "sha512-2vPPEi+Z7WqML2jZYddDIfy5Dqb0r2fze2zTxNNknZaFpVHU3mFB3R+DWeJWGVx0ecvttSGlJTI+WG+8Z4cDWw==", + "license": "MIT", "peer": true }, "node_modules/ob1": { - "version": "0.80.8", - "resolved": "https://registry.npmjs.org/ob1/-/ob1-0.80.8.tgz", - "integrity": "sha512-QHJQk/lXMmAW8I7AIM3in1MSlwe1umR72Chhi8B7Xnq6mzjhBKkA6Fy/zAhQnGkA4S912EPCEvTij5yh+EQTAA==", + "version": "0.81.0", + "resolved": "https://registry.npmjs.org/ob1/-/ob1-0.81.0.tgz", + "integrity": "sha512-6Cvrkxt1tqaRdWqTAMcVYEiO5i1xcF9y7t06nFdjFqkfPsEloCf8WwhXdwBpNUkVYSQlSGS7cDgVQR86miBfBQ==", + "license": "MIT", "peer": true, + "dependencies": { + "flow-enums-runtime": "^0.0.6" + }, "engines": { - "node": ">=18" + "node": ">=18.18" } }, "node_modules/object-assign": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -10860,6 +10414,7 @@ "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -10872,6 +10427,7 @@ "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz", "integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==", "dev": true, + "license": "MIT", "dependencies": { "call-bind": "^1.0.7", "define-properties": "^1.2.1" @@ -10888,6 +10444,7 @@ "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.4" } @@ -10896,6 +10453,7 @@ "version": "2.4.1", "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.1.tgz", "integrity": "sha512-oVlzkg3ENAhCk2zdv7IJwd/QUD4z2RxRwpkcGY8psCVcCYZNq4wYnVWALHM+brtuJjePWiYF/ClmuDr8Ch5+kg==", + "license": "MIT", "dependencies": { "ee-first": "1.1.1" }, @@ -10903,19 +10461,11 @@ "node": ">= 0.8" } }, - "node_modules/on-headers": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", - "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==", - "peer": true, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", "dependencies": { "wrappy": "1" } @@ -10924,6 +10474,7 @@ "version": "5.1.2", "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", + "license": "MIT", "peer": true, "dependencies": { "mimic-fn": "^2.1.0" @@ -10936,70 +10487,53 @@ } }, "node_modules/open": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/open/-/open-6.4.0.tgz", - "integrity": "sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg==", + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz", + "integrity": "sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==", + "license": "MIT", "peer": true, "dependencies": { - "is-wsl": "^1.1.0" + "is-docker": "^2.0.0", + "is-wsl": "^2.1.1" }, "engines": { "node": ">=8" - } - }, - "node_modules/open/node_modules/is-wsl": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-1.1.0.tgz", - "integrity": "sha512-gfygJYZ2gLTDlmbWMI0CE2MwnFzSN/2SZfkMlItC4K/JBlsWVDB0bO6XhqcY13YXE7iMcAJnzTCJjPiTeJJ0Mw==", - "peer": true, - "engines": { - "node": ">=4" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/optionator": { - "version": "0.9.3", - "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.3.tgz", - "integrity": "sha512-JjCoypp+jKn1ttEFExxhetCKeJt9zhAgAve5FXHixTvFDW/5aEktX9bufBKLRRMdU7bNtpLfcGu94B3cdEJgjg==", + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", + "integrity": "sha512-6IpQ7mKUxRcZNLIObR0hz7lxsapSSIYNZJwXPGeF0mTVqGKFIXj1DQcMoT22S3ROcLyY/rz0PWaWZ9ayWmad9g==", "dev": true, + "license": "MIT", "dependencies": { - "@aashutoshrathi/word-wrap": "^1.2.3", "deep-is": "^0.1.3", "fast-levenshtein": "^2.0.6", "levn": "^0.4.1", "prelude-ls": "^1.2.1", - "type-check": "^0.4.0" + "type-check": "^0.4.0", + "word-wrap": "^1.2.5" }, "engines": { "node": ">= 0.8.0" } }, - "node_modules/ora": { - "version": "5.4.1", - "resolved": "https://registry.npmjs.org/ora/-/ora-5.4.1.tgz", - "integrity": "sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==", - "peer": true, - "dependencies": { - "bl": "^4.1.0", - "chalk": "^4.1.0", - "cli-cursor": "^3.1.0", - "cli-spinners": "^2.5.0", - "is-interactive": "^1.0.0", - "is-unicode-supported": "^0.1.0", - "log-symbols": "^4.1.0", - "strip-ansi": "^6.0.0", - "wcwidth": "^1.0.1" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } + "node_modules/outvariant": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/outvariant/-/outvariant-1.4.3.tgz", + "integrity": "sha512-+Sl2UErvtsoajRDKCE5/dBz4DIvHXQQnAxtQTF04OJxY0+DyZXSo5P5Bb7XYWOh81syohlYL24hbDwxedPUJCA==", + "dev": true, + "license": "MIT" }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", "integrity": "sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==", + "dev": true, + "license": "MIT", "dependencies": { "yocto-queue": "^0.1.0" }, @@ -11014,6 +10548,8 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-5.0.0.tgz", "integrity": "sha512-LaNjtRWUBY++zB5nE/NwcaoMylSPk+S+ZHNB1TzdbMJMny6dynpAGt7X/tl/QYq3TIeE6nxHppbo2LGymrG5Pw==", + "dev": true, + "license": "MIT", "dependencies": { "p-limit": "^3.0.2" }, @@ -11028,23 +10564,26 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==", + "license": "MIT", + "peer": true, "engines": { "node": ">=6" } }, "node_modules/pac-proxy-agent": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.0.1.tgz", - "integrity": "sha512-ASV8yU4LLKBAjqIPMbrgtaKIvxQri/yh2OpI+S6hVa9JRkUI3Y3NPFbfngDtY7oFtSMD3w31Xns89mDa3Feo5A==", + "version": "7.0.2", + "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.0.2.tgz", + "integrity": "sha512-BFi3vZnO9X5Qt6NRz7ZOaPja3ic0PhlsmCRYLOpN11+mWBCR6XJDqW5RF3j8jm4WGGQZtBA+bTfxYzeKW73eHg==", + "license": "MIT", "dependencies": { "@tootallnate/quickjs-emscripten": "^0.23.0", "agent-base": "^7.0.2", "debug": "^4.3.4", "get-uri": "^6.0.1", "http-proxy-agent": "^7.0.0", - "https-proxy-agent": "^7.0.2", - "pac-resolver": "^7.0.0", - "socks-proxy-agent": "^8.0.2" + "https-proxy-agent": "^7.0.5", + "pac-resolver": "^7.0.1", + "socks-proxy-agent": "^8.0.4" }, "engines": { "node": ">= 14" @@ -11054,6 +10593,7 @@ "version": "7.0.1", "resolved": "https://registry.npmjs.org/pac-resolver/-/pac-resolver-7.0.1.tgz", "integrity": "sha512-5NPgf87AT2STgwa2ntRMr45jTKrYBGkVU36yT0ig/n/GMAa3oPqhZfIQ2kMEimReg0+t9kZViDVZ83qfVUlckg==", + "license": "MIT", "dependencies": { "degenerator": "^5.0.0", "netmask": "^2.0.2" @@ -11062,11 +10602,21 @@ "node": ">= 14" } }, + "node_modules/package-json-from-dist": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz", + "integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==", + "dev": true, + "license": "BlueOak-1.0.0", + "peer": true + }, "node_modules/pad-right": { "version": "0.2.2", "resolved": "https://registry.npmjs.org/pad-right/-/pad-right-0.2.2.tgz", "integrity": "sha512-4cy8M95ioIGolCoMmm2cMntGR1lPLEbOMzOKu8bzjuJP6JpzEMQcDHmh7hHLYGgob+nKe1YHFMaG4V59HQa89g==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "repeat-string": "^1.5.2" }, @@ -11079,6 +10629,7 @@ "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", "dev": true, + "license": "MIT", "dependencies": { "callsites": "^3.0.0" }, @@ -11087,27 +10638,24 @@ } }, "node_modules/parse-json": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", - "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==", - "dev": true, + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-4.0.0.tgz", + "integrity": "sha512-aOIos8bujGN93/8Ox/jPLh7RwVnPEysynVFE+fQZyg6jKELEHwzgKdLRFHUgXJL6kylijVSBC4BvN9OmsB48Rw==", + "license": "MIT", + "peer": true, "dependencies": { - "@babel/code-frame": "^7.0.0", "error-ex": "^1.3.1", - "json-parse-even-better-errors": "^2.3.0", - "lines-and-columns": "^1.1.6" + "json-parse-better-errors": "^1.0.1" }, "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=4" } }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", "engines": { "node": ">= 0.8" } @@ -11116,6 +10664,7 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-4.0.0.tgz", "integrity": "sha512-ak9Qy5Q7jYb2Wwcey5Fpvg2KoAc/ZIhLSLOSBmRmygPsGwkVVt0fZa0qrtMz+m6tJTAHfZQ8FnmB4MG4LWy7/w==", + "license": "MIT", "engines": { "node": ">=8" } @@ -11124,6 +10673,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -11132,6 +10682,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "license": "MIT", "engines": { "node": ">=8" } @@ -11139,68 +10690,69 @@ "node_modules/path-parse": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", - "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==" + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "license": "MIT" }, "node_modules/path-scurry": { - "version": "1.10.2", - "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.10.2.tgz", - "integrity": "sha512-7xTavNy5RQXnsjANvVvMkEjvloOinkAjv/Z6Ildz9v2RinZ4SBKTWFOVRbaF8p0vpHnyjV/UwNDdKuUv6M5qcA==", + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz", + "integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==", "dev": true, + "license": "BlueOak-1.0.0", + "peer": true, "dependencies": { "lru-cache": "^10.2.0", "minipass": "^5.0.0 || ^6.0.2 || ^7.0.0" }, "engines": { - "node": ">=16 || 14 >=14.17" + "node": ">=16 || 14 >=14.18" }, "funding": { "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/path-scurry/node_modules/lru-cache": { + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "dev": true, + "license": "ISC", + "peer": true + }, "node_modules/path-to-regexp": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.9.0.tgz", "integrity": "sha512-xIp7/apCFJuUHdDLWe8O1HIkb0kQrOMb/0u6FXQjemHn/ii5LrIzU6bdECnsiTF/GjZkMEKg1xdiZwNqDYlZ6g==", "dev": true, + "license": "MIT", "dependencies": { "isarray": "0.0.1" } }, - "node_modules/path-to-regexp/node_modules/isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", - "dev": true - }, - "node_modules/path-type": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", - "integrity": "sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==", - "dev": true, - "engines": { - "node": ">=8" - } - }, "node_modules/pathval": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.1.tgz", "integrity": "sha512-Dp6zGqpTdETdR63lehJYPeIOqpiNBNtc7BpWSLrOje7UaIsE5aY92r/AunQA7rsXvet3lrJ3JnZX29UPTKXyKQ==", "dev": true, + "license": "MIT", "engines": { "node": "*" } }, "node_modules/picocolors": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", - "integrity": "sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==" + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", + "integrity": "sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==", + "license": "ISC" }, "node_modules/picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-4.0.2.tgz", + "integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==", + "dev": true, + "license": "MIT", "engines": { - "node": ">=8.6" + "node": ">=12" }, "funding": { "url": "https://github.com/sponsors/jonschlinkert" @@ -11210,6 +10762,7 @@ "version": "4.0.1", "resolved": "https://registry.npmjs.org/pify/-/pify-4.0.1.tgz", "integrity": "sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==", + "license": "MIT", "peer": true, "engines": { "node": ">=6" @@ -11219,6 +10772,7 @@ "version": "4.0.6", "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.6.tgz", "integrity": "sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==", + "license": "MIT", "peer": true, "engines": { "node": ">= 6" @@ -11228,6 +10782,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-3.0.0.tgz", "integrity": "sha512-/E57AYkoeQ25qkxMj5PBOVgF8Kiu/h7cYS30Z5+R7WaiCCBfLq58ZI/dSeaEKb9WVJV5n/03QwrN3IeWIFllvw==", + "license": "MIT", "peer": true, "dependencies": { "find-up": "^3.0.0" @@ -11240,6 +10795,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "license": "MIT", "peer": true, "dependencies": { "locate-path": "^3.0.0" @@ -11252,6 +10808,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "license": "MIT", "peer": true, "dependencies": { "p-locate": "^3.0.0", @@ -11265,6 +10822,7 @@ "version": "2.3.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", + "license": "MIT", "peer": true, "dependencies": { "p-try": "^2.0.0" @@ -11280,6 +10838,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "license": "MIT", "peer": true, "dependencies": { "p-limit": "^2.0.0" @@ -11292,6 +10851,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", + "license": "MIT", "peer": true, "engines": { "node": ">=4" @@ -11302,15 +10862,17 @@ "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true, + "license": "MIT", "engines": { "node": ">= 0.8.0" } }, "node_modules/prettier": { - "version": "3.2.5", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.2.5.tgz", - "integrity": "sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", "dev": true, + "license": "MIT", "bin": { "prettier": "bin/prettier.cjs" }, @@ -11326,6 +10888,7 @@ "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", "dev": true, + "license": "MIT", "dependencies": { "fast-diff": "^1.1.2" }, @@ -11337,6 +10900,7 @@ "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", + "license": "MIT", "dependencies": { "@jest/schemas": "^29.6.3", "ansi-styles": "^5.0.0", @@ -11346,10 +10910,23 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, + "node_modules/pretty-format/node_modules/ansi-styles": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz", + "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==", + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, "node_modules/process-nextick-args": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", + "license": "MIT", "peer": true }, "node_modules/progress": { @@ -11357,6 +10934,8 @@ "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=0.4.0" } @@ -11365,46 +10944,18 @@ "version": "8.3.0", "resolved": "https://registry.npmjs.org/promise/-/promise-8.3.0.tgz", "integrity": "sha512-rZPNPKTOYVNEEKFaq1HqTgOwZD+4/YHS5ukLzQCypkj+OkYx7iv0mA91lJlpPPZ8vMau3IIGj5Qlwrx+8iiSmg==", + "license": "MIT", "peer": true, "dependencies": { "asap": "~2.0.6" } }, - "node_modules/prompts": { - "version": "2.4.2", - "resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.2.tgz", - "integrity": "sha512-NxNv/kLguCA7p3jE8oL2aEBsrJWgAakBpgmgK6lpPWV+WuOmY6r2/zbAVnP+T8bQlA0nzHXSJSJW0Hq7ylaD2Q==", - "peer": true, - "dependencies": { - "kleur": "^3.0.3", - "sisteransi": "^1.0.5" - }, - "engines": { - "node": ">= 6" - } - }, - "node_modules/prop-types": { - "version": "15.8.1", - "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", - "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", - "peer": true, - "dependencies": { - "loose-envify": "^1.4.0", - "object-assign": "^4.1.1", - "react-is": "^16.13.1" - } - }, - "node_modules/prop-types/node_modules/react-is": { - "version": "16.13.1", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", - "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==", - "peer": true - }, "node_modules/propagate": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/propagate/-/propagate-2.0.1.tgz", "integrity": "sha512-vGrhOavPSTz4QVNuBNdcNXePNdNMaO1xj9yBeH1ScQPjk/rhg9sSlCXPhMkFuaNNW/syTvYqsnbIJxMBfRbbag==", "dev": true, + "license": "MIT", "engines": { "node": ">= 8" } @@ -11413,12 +10964,15 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/property-expr/-/property-expr-2.0.6.tgz", "integrity": "sha512-SVtmxhRE/CGkn3eZY1T6pC8Nln6Fr/lu1mKSgRud0eC73whjGfoAogbn78LkD8aFL0zz3bAFerKSnOl7NlErBA==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/proxy-agent": { "version": "6.4.0", "resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-6.4.0.tgz", "integrity": "sha512-u0piLU+nCOHMgGjRbimiXmA9kM/L9EHh3zL81xCdp7m+Y2pHIsnmbdDoEDoAz5geaonNR6q6+yOPQs6n4T6sBQ==", + "license": "MIT", "dependencies": { "agent-base": "^7.0.2", "debug": "^4.3.4", @@ -11433,40 +10987,50 @@ "node": ">= 14" } }, - "node_modules/proxy-agent/node_modules/lru-cache": { - "version": "7.18.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", - "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", - "engines": { - "node": ">=12" - } - }, "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", + "license": "MIT" }, "node_modules/punycode": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", - "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", - "engines": { - "node": ">=6" - } + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.4.1.tgz", + "integrity": "sha512-jmYNElW7yvO7TV33CjSmvSiE2yco3bV2czu/OzDKdMNVZQWfxCblURLhf+47syQRBntjfLdd/H0egrzIG+oaFQ==", + "dev": true, + "license": "MIT" }, "node_modules/qjobs": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/qjobs/-/qjobs-1.2.0.tgz", "integrity": "sha512-8YOJEHtxpySA3fFDyCRxA+UUV+fA+rTWnuWvylOK/NCjhY+b4ocCtmu8TtsWb+mYeU+GCHf/S66KZF/AsteKHg==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.9" } }, + "node_modules/qs": { + "version": "6.13.0", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.13.0.tgz", + "integrity": "sha512-+38qI9SOr8tfZ4QmJNplMUxqjbe7LKvvZgWdExBOmd+egZTtjLB67Gu0HRX3u/XOq7UU2Nx6nsjvS16Z9uwfpg==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "side-channel": "^1.0.6" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/queue": { "version": "6.0.2", "resolved": "https://registry.npmjs.org/queue/-/queue-6.0.2.tgz", "integrity": "sha512-iHZWu+q3IdFZFX36ro/lKBkSvfkztY5Y7HMiPlOUjhupPcG2JMfst2KKEpu5XndviX/3UhFbRngUPNKtgvtZiA==", + "license": "MIT", "peer": true, "dependencies": { "inherits": "~2.0.3" @@ -11490,19 +11054,22 @@ "type": "consulting", "url": "https://feross.org/support" } - ] + ], + "license": "MIT" }, "node_modules/rambda": { "version": "7.5.0", "resolved": "https://registry.npmjs.org/rambda/-/rambda-7.5.0.tgz", "integrity": "sha512-y/M9weqWAH4iopRd7EHDEQQvpFPHj1AA3oHozE9tfITHUtTR7Z9PSlIRRG2l1GuW7sefC1cXFfIcF+cgnShdBA==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", "integrity": "sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==", "dev": true, + "license": "MIT", "dependencies": { "safe-buffer": "^5.1.0" } @@ -11511,6 +11078,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz", "integrity": "sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==", + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -11520,6 +11088,7 @@ "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz", "integrity": "sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA==", "dev": true, + "license": "MIT", "dependencies": { "bytes": "3.1.2", "http-errors": "2.0.0", @@ -11531,9 +11100,10 @@ } }, "node_modules/react": { - "version": "18.2.0", - "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", - "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", + "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "license": "MIT", "peer": true, "dependencies": { "loose-envify": "^1.1.0" @@ -11543,9 +11113,10 @@ } }, "node_modules/react-devtools-core": { - "version": "4.28.5", - "resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-4.28.5.tgz", - "integrity": "sha512-cq/o30z9W2Wb4rzBefjv5fBalHU0rJGZCHAkf/RHSBWSSYwh8PlQTqqOJmgIIbBtpj27T6FIPXeomIjZtCNVqA==", + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-5.3.2.tgz", + "integrity": "sha512-crr9HkVrDiJ0A4zot89oS0Cgv0Oa4OG1Em4jit3P3ZxZSKPMYyMjfwMqgcJna9o625g8oN87rBm8SWWrSTBZxg==", + "license": "MIT", "peer": true, "dependencies": { "shell-quote": "^1.6.1", @@ -11553,9 +11124,10 @@ } }, "node_modules/react-devtools-core/node_modules/ws": { - "version": "7.5.9", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.9.tgz", - "integrity": "sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==", + "version": "7.5.10", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", + "integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==", + "license": "MIT", "peer": true, "engines": { "node": ">=8.3.0" @@ -11574,53 +11146,55 @@ } }, "node_modules/react-is": { - "version": "18.2.0", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", - "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==" + "version": "18.3.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.3.1.tgz", + "integrity": "sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==", + "license": "MIT" }, "node_modules/react-native": { - "version": "0.73.6", - "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.73.6.tgz", - "integrity": "sha512-oqmZe8D2/VolIzSPZw+oUd6j/bEmeRHwsLn1xLA5wllEYsZ5zNuMsDus235ONOnCRwexqof/J3aztyQswSmiaA==", + "version": "0.76.1", + "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.76.1.tgz", + "integrity": "sha512-z4KnbrnnAvloRs9NGnah3u6/LK3IbtNMrvByxa3ifigbMlsMY4WPRYV9lvt/hH4Mzt8bfuI+utnOxFyJTTq3lg==", + "license": "MIT", "peer": true, "dependencies": { "@jest/create-cache-key-function": "^29.6.3", - "@react-native-community/cli": "12.3.6", - "@react-native-community/cli-platform-android": "12.3.6", - "@react-native-community/cli-platform-ios": "12.3.6", - "@react-native/assets-registry": "0.73.1", - "@react-native/codegen": "0.73.3", - "@react-native/community-cli-plugin": "0.73.17", - "@react-native/gradle-plugin": "0.73.4", - "@react-native/js-polyfills": "0.73.1", - "@react-native/normalize-colors": "0.73.2", - "@react-native/virtualized-lists": "0.73.4", + "@react-native/assets-registry": "0.76.1", + "@react-native/codegen": "0.76.1", + "@react-native/community-cli-plugin": "0.76.1", + "@react-native/gradle-plugin": "0.76.1", + "@react-native/js-polyfills": "0.76.1", + "@react-native/normalize-colors": "0.76.1", + "@react-native/virtualized-lists": "0.76.1", "abort-controller": "^3.0.0", "anser": "^1.4.9", "ansi-regex": "^5.0.0", + "babel-jest": "^29.7.0", + "babel-plugin-syntax-hermes-parser": "^0.23.1", "base64-js": "^1.5.1", "chalk": "^4.0.0", - "deprecated-react-native-prop-types": "^5.0.0", + "commander": "^12.0.0", "event-target-shim": "^5.0.1", "flow-enums-runtime": "^0.0.6", + "glob": "^7.1.1", "invariant": "^2.2.4", "jest-environment-node": "^29.6.3", "jsc-android": "^250231.0.0", "memoize-one": "^5.0.0", - "metro-runtime": "^0.80.3", - "metro-source-map": "^0.80.3", + "metro-runtime": "^0.81.0", + "metro-source-map": "^0.81.0", "mkdirp": "^0.5.1", "nullthrows": "^1.1.1", - "pretty-format": "^26.5.2", + "pretty-format": "^29.7.0", "promise": "^8.3.0", - "react-devtools-core": "^4.27.7", + "react-devtools-core": "^5.3.1", "react-refresh": "^0.14.0", - "react-shallow-renderer": "^16.15.0", "regenerator-runtime": "^0.13.2", "scheduler": "0.24.0-canary-efb381bbf-20230505", + "semver": "^7.1.3", "stacktrace-parser": "^0.1.10", "whatwg-fetch": "^3.0.0", - "ws": "^6.2.2", + "ws": "^6.2.3", "yargs": "^17.6.2" }, "bin": { @@ -11630,13 +11204,20 @@ "node": ">=18" }, "peerDependencies": { - "react": "18.2.0" + "@types/react": "^18.2.6", + "react": "^18.2.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } } }, "node_modules/react-native-url-polyfill": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/react-native-url-polyfill/-/react-native-url-polyfill-2.0.0.tgz", "integrity": "sha512-My330Do7/DvKnEvwQc0WdcBnFPploYKp9CYlefDXzIdEaA+PAhDYllkvGeEroEzvc4Kzzj2O4yVdz8v6fjRvhA==", + "license": "MIT", "dependencies": { "whatwg-url-without-unicode": "8.0.0-3" }, @@ -11644,59 +11225,22 @@ "react-native": "*" } }, - "node_modules/react-native/node_modules/@jest/types": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-26.6.2.tgz", - "integrity": "sha512-fC6QCp7Sc5sX6g8Tvbmj4XUTbyrik0akgRy03yjXbQaBWWNWGE7SGtJk98m0N8nzegD/7SggrUlivxo5ax4KWQ==", - "peer": true, - "dependencies": { - "@types/istanbul-lib-coverage": "^2.0.0", - "@types/istanbul-reports": "^3.0.0", - "@types/node": "*", - "@types/yargs": "^15.0.0", - "chalk": "^4.0.0" - }, - "engines": { - "node": ">= 10.14.2" - } - }, - "node_modules/react-native/node_modules/@types/yargs": { - "version": "15.0.19", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.19.tgz", - "integrity": "sha512-2XUaGVmyQjgyAZldf0D0c14vvo/yv0MhQBSTJcejMMaitsn3nxCB6TmH4G0ZQf+uxROOa9mpanoSm8h6SG/1ZA==", - "peer": true, - "dependencies": { - "@types/yargs-parser": "*" - } - }, - "node_modules/react-native/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "peer": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/react-native/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "node_modules/react-native/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "license": "MIT", "peer": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" } }, "node_modules/react-native/node_modules/cliui": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz", "integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==", + "license": "ISC", "peer": true, "dependencies": { "string-width": "^4.2.0", @@ -11707,93 +11251,46 @@ "node": ">=12" } }, - "node_modules/react-native/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "node_modules/react-native/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "license": "ISC", "peer": true, "dependencies": { - "color-name": "~1.1.4" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" }, "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/react-native/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "peer": true - }, - "node_modules/react-native/node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "peer": true, - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, - "node_modules/react-native/node_modules/pretty-format": { - "version": "26.6.2", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-26.6.2.tgz", - "integrity": "sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg==", - "peer": true, - "dependencies": { - "@jest/types": "^26.6.2", - "ansi-regex": "^5.0.0", - "ansi-styles": "^4.0.0", - "react-is": "^17.0.1" + "node": "*" }, - "engines": { - "node": ">= 10" + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/react-native/node_modules/react-is": { - "version": "17.0.2", - "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", - "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==", - "peer": true - }, - "node_modules/react-native/node_modules/regenerator-runtime": { - "version": "0.13.11", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", - "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", - "peer": true - }, - "node_modules/react-native/node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "node_modules/react-native/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "license": "ISC", "peer": true, "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" + "brace-expansion": "^1.1.7" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, - "node_modules/react-native/node_modules/ws": { - "version": "6.2.2", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.2.tgz", - "integrity": "sha512-zmhltoSR8u1cnDsD43TX59mzoMZsLKqUweyYBAIvTngR3shc0W6aOZylZmq/7hqyVxPdi+5Ud2QInblgyE72fw==", - "peer": true, - "dependencies": { - "async-limiter": "~1.0.0" + "node": "*" } }, "node_modules/react-native/node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", "integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==", + "license": "MIT", "peer": true, "dependencies": { "cliui": "^8.0.1", @@ -11812,38 +11309,29 @@ "version": "21.1.1", "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz", "integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==", + "license": "ISC", "peer": true, "engines": { "node": ">=12" } }, "node_modules/react-refresh": { - "version": "0.14.0", - "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.0.tgz", - "integrity": "sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==", + "version": "0.14.2", + "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.14.2.tgz", + "integrity": "sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==", + "license": "MIT", "peer": true, "engines": { "node": ">=0.10.0" } }, - "node_modules/react-shallow-renderer": { - "version": "16.15.0", - "resolved": "https://registry.npmjs.org/react-shallow-renderer/-/react-shallow-renderer-16.15.0.tgz", - "integrity": "sha512-oScf2FqQ9LFVQgA73vr86xl2NaOIX73rh+YFqcOp68CWj56tSfgtGKrEbyhCj0rSijyG9M1CYprTh39fBi5hzA==", - "peer": true, - "dependencies": { - "object-assign": "^4.1.1", - "react-is": "^16.12.0 || ^17.0.0 || ^18.0.0" - }, - "peerDependencies": { - "react": "^16.0.0 || ^17.0.0 || ^18.0.0" - } - }, "node_modules/read-pkg": { "version": "5.2.0", "resolved": "https://registry.npmjs.org/read-pkg/-/read-pkg-5.2.0.tgz", "integrity": "sha512-Ug69mNOpfvKDAc2Q8DRpMjjzdtrnv9HcSMX+4VsZxD1aZ6ZzrIE7rlzXBtWTyhULSMKg076AW6WR5iZpD0JiOg==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "@types/normalize-package-data": "^2.4.0", "normalize-package-data": "^2.5.0", @@ -11859,6 +11347,8 @@ "resolved": "https://registry.npmjs.org/read-pkg-up/-/read-pkg-up-7.0.1.tgz", "integrity": "sha512-zK0TB7Xd6JpCLmlLmufqykGE+/TlOePD6qKClNW7hHDKFh/J7/7gCWGR7joEQEW1bKq3a3yUZSObOoWLFQ4ohg==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "find-up": "^4.1.0", "read-pkg": "^5.2.0", @@ -11876,6 +11366,8 @@ "resolved": "https://registry.npmjs.org/find-up/-/find-up-4.1.0.tgz", "integrity": "sha512-PpOwAdQ/YlXQ2vj8a3h8IipDuYRi3wceVQQGYWxNINccq40Anw7BlsEXCMbt1Zt+OLA6Fq9suIpIWD0OsnISlw==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "locate-path": "^5.0.0", "path-exists": "^4.0.0" @@ -11889,6 +11381,8 @@ "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-5.0.0.tgz", "integrity": "sha512-t7hw9pI+WvuwNJXwk5zVHpyhIqzg2qTlklJOf0mVxGSbe3Fp2VieZcduNYjaLDoy6p9uGpQEGWG87WpMKlNq8g==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "p-locate": "^4.1.0" }, @@ -11901,6 +11395,8 @@ "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz", "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "p-try": "^2.0.0" }, @@ -11916,6 +11412,8 @@ "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-4.1.0.tgz", "integrity": "sha512-R79ZZ/0wAxKGu3oYMlz8jy/kbhsNrS7SKZ7PxEHBgJ5+F2mtFW2fK2cOtBh1cHYkQsbzFV7I+EoRKe6Yt0oK7A==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "p-limit": "^2.2.0" }, @@ -11928,8 +11426,30 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.8.1.tgz", "integrity": "sha512-4dbzIzqvjtgiM5rw1k5rEHtBANKmdudhGyBEajN01fEyhaAIhsoKNy6y7+IN93IfpFtwY9iqi7kD+xwKhQsNJA==", "dev": true, + "license": "(MIT OR CC0-1.0)", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/read-pkg/node_modules/parse-json": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/parse-json/-/parse-json-5.2.0.tgz", + "integrity": "sha512-ayCKvm/phCGxOkYRSCM82iDwct8/EonSEgCSxWxD7ve6jHggsFl4fZVQBPRNgQoKiuV/odhFrGzQXZwbifC8Rg==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/code-frame": "^7.0.0", + "error-ex": "^1.3.1", + "json-parse-even-better-errors": "^2.3.0", + "lines-and-columns": "^1.1.6" + }, "engines": { "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/read-pkg/node_modules/type-fest": { @@ -11937,6 +11457,8 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.6.0.tgz", "integrity": "sha512-q+MB8nYR1KDLrgr4G5yemftpMC7/QLqVndBmEEdqzmNj5dcFOO4Oo8qlwZE3ULT3+Zim1F8Kq4cBnikNhlCMlg==", "dev": true, + "license": "(MIT OR CC0-1.0)", + "peer": true, "engines": { "node": ">=8" } @@ -11945,6 +11467,7 @@ "version": "2.3.8", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", + "license": "MIT", "peer": true, "dependencies": { "core-util-is": "~1.0.0", @@ -11956,11 +11479,26 @@ "util-deprecate": "~1.0.1" } }, + "node_modules/readable-stream/node_modules/isarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", + "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", + "license": "MIT", + "peer": true + }, + "node_modules/readable-stream/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT", + "peer": true + }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", "dev": true, + "license": "MIT", "dependencies": { "picomatch": "^2.2.1" }, @@ -11968,16 +11506,31 @@ "node": ">=8.10.0" } }, + "node_modules/readdirp/node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, "node_modules/readline": { "version": "1.3.0", "resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz", "integrity": "sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg==", + "license": "BSD", "peer": true }, "node_modules/recast": { "version": "0.21.5", "resolved": "https://registry.npmjs.org/recast/-/recast-0.21.5.tgz", "integrity": "sha512-hjMmLaUXAm1hIuTqOdeYObMslq/q+Xff6QE3Y2P+uoHAg2nmVlLBps2hzh1UJDdMtDTMXOFewK6ky51JQIeECg==", + "license": "MIT", "peer": true, "dependencies": { "ast-types": "0.15.2", @@ -11993,6 +11546,7 @@ "version": "0.15.2", "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.15.2.tgz", "integrity": "sha512-c27loCv9QkZinsa5ProX751khO9DJl/AcB5c2KNtA6NRvHKS0PgLfcftz72KVq504vB0Gku5s2kUZzDBvQWvHg==", + "license": "MIT", "peer": true, "dependencies": { "tslib": "^2.0.1" @@ -12006,18 +11560,22 @@ "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.2.1.tgz", "integrity": "sha512-i5lLI6iw9AU3Uu4szRNPPEkomnkjRTaVt9hy/bn5g/oSzekBSMeLZblcjP74AW0vBabqERLLIrz+gR8QYR54Tw==", "deprecated": "This version has a critical bug in fallback handling. Please upgrade to reflect-metadata@0.2.2 or newer.", - "dev": true + "dev": true, + "license": "Apache-2.0", + "peer": true }, "node_modules/regenerate": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", "integrity": "sha512-zrceR/XhGYU/d/opr2EKO7aRHUeiBI8qjtfHqADTwZd6Szfy16la6kqD0MIUs5z5hx6AaKa+PixpPrR289+I0A==", + "license": "MIT", "peer": true }, "node_modules/regenerate-unicode-properties": { - "version": "10.1.1", - "resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-10.1.1.tgz", - "integrity": "sha512-X007RyZLsCJVVrjgEFVpLUTZwyOZk3oiL75ZcuYjlIWd6rNJtOjkBwQc5AsRrpbKVkxN6sklw/k/9m2jJYOf8Q==", + "version": "10.2.0", + "resolved": "https://registry.npmjs.org/regenerate-unicode-properties/-/regenerate-unicode-properties-10.2.0.tgz", + "integrity": "sha512-DqHn3DwbmmPVzeKj9woBadqmXxLvQoQIwu7nopMc72ztvxVmVk2SBhSnx67zuye5TP+lJsb/TBQsjLKhnDf3MA==", + "license": "MIT", "peer": true, "dependencies": { "regenerate": "^1.4.2" @@ -12027,15 +11585,17 @@ } }, "node_modules/regenerator-runtime": { - "version": "0.14.1", - "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", - "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "version": "0.13.11", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", + "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", + "license": "MIT", "peer": true }, "node_modules/regenerator-transform": { "version": "0.15.2", "resolved": "https://registry.npmjs.org/regenerator-transform/-/regenerator-transform-0.15.2.tgz", "integrity": "sha512-hfMp2BoF0qOk3uc5V20ALGDS2ddjQaLrdl7xrGXvAIow7qeWRM2VA2HuCHkUKk9slq3VwEwLNK3DFBqDfPGYtg==", + "license": "MIT", "peer": true, "dependencies": { "@babel/runtime": "^7.8.4" @@ -12046,6 +11606,8 @@ "resolved": "https://registry.npmjs.org/regexp-match-indices/-/regexp-match-indices-1.0.2.tgz", "integrity": "sha512-DwZuAkt8NF5mKwGGER1EGh2PRqyvhRhhLviH+R8y8dIuaQROlUfXjt4s9ZTXstIsSkptf06BSvwcEmmfheJJWQ==", "dev": true, + "license": "Apache-2.0", + "peer": true, "dependencies": { "regexp-tree": "^0.1.11" } @@ -12055,20 +11617,23 @@ "resolved": "https://registry.npmjs.org/regexp-tree/-/regexp-tree-0.1.27.tgz", "integrity": "sha512-iETxpjK6YoRWJG5o6hXLwvjYAoW+FEZn9os0PD/b6AP6xQwsa/Y7lCVgIixBbUPMfhu+i2LtdeAqVTgGlQarfA==", "dev": true, + "license": "MIT", + "peer": true, "bin": { "regexp-tree": "bin/regexp-tree" } }, "node_modules/regexp.prototype.flags": { - "version": "1.5.2", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", - "integrity": "sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==", + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.3.tgz", + "integrity": "sha512-vqlC04+RQoFalODCbCumG2xIOvapzVMHwsyIGM/SIE8fRhFFsXeH8/QQ+s0T0kDAhKc4k30s73/0ydkHQz6HlQ==", "dev": true, + "license": "MIT", "dependencies": { - "call-bind": "^1.0.6", + "call-bind": "^1.0.7", "define-properties": "^1.2.1", "es-errors": "^1.3.0", - "set-function-name": "^2.0.1" + "set-function-name": "^2.0.2" }, "engines": { "node": ">= 0.4" @@ -12078,15 +11643,16 @@ } }, "node_modules/regexpu-core": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-5.3.2.tgz", - "integrity": "sha512-RAM5FlZz+Lhmo7db9L298p2vHP5ZywrVXmVXpmAD9GuL5MPH6t9ROw1iA/wfHkQ76Qe7AaPF0nGuim96/IrQMQ==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-6.1.1.tgz", + "integrity": "sha512-k67Nb9jvwJcJmVpw0jPttR1/zVfnKf8Km0IPatrU/zJ5XeG3+Slx0xLXs9HByJSzXzrlz5EDvN6yLNMDc2qdnw==", + "license": "MIT", "peer": true, "dependencies": { - "@babel/regjsgen": "^0.8.0", "regenerate": "^1.4.2", - "regenerate-unicode-properties": "^10.1.0", - "regjsparser": "^0.9.1", + "regenerate-unicode-properties": "^10.2.0", + "regjsgen": "^0.8.0", + "regjsparser": "^0.11.0", "unicode-match-property-ecmascript": "^2.0.0", "unicode-match-property-value-ecmascript": "^2.1.0" }, @@ -12094,32 +11660,33 @@ "node": ">=4" } }, + "node_modules/regjsgen": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/regjsgen/-/regjsgen-0.8.0.tgz", + "integrity": "sha512-RvwtGe3d7LvWiDQXeQw8p5asZUmfU1G/l6WbUXeHta7Y2PEIvBTwH6E2EfmYUK8pxcxEdEmaomqyp0vZZ7C+3Q==", + "license": "MIT", + "peer": true + }, "node_modules/regjsparser": { - "version": "0.9.1", - "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.9.1.tgz", - "integrity": "sha512-dQUtn90WanSNl+7mQKcXAgZxvUe7Z0SqXlgzv0za4LwiUhyzBC58yQO3liFoUgu8GiJVInAhJjkj1N0EtQ5nkQ==", + "version": "0.11.2", + "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.11.2.tgz", + "integrity": "sha512-3OGZZ4HoLJkkAZx/48mTXJNlmqTGOzc0o9OWQPuWpkOlXXPbyN6OafCcoXUnBqE2D3f/T5L+pWc1kdEmnfnRsA==", + "license": "BSD-2-Clause", "peer": true, "dependencies": { - "jsesc": "~0.5.0" + "jsesc": "~3.0.2" }, "bin": { "regjsparser": "bin/parser" } }, - "node_modules/regjsparser/node_modules/jsesc": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-0.5.0.tgz", - "integrity": "sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==", - "peer": true, - "bin": { - "jsesc": "bin/jsesc" - } - }, "node_modules/repeat-string": { "version": "1.6.1", "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", "integrity": "sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=0.10" } @@ -12128,26 +11695,23 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", "integrity": "sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==", + "license": "MIT", "engines": { "node": ">=0.10.0" } }, - "node_modules/require-main-filename": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", - "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==", - "peer": true - }, "node_modules/requires-port": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/requires-port/-/requires-port-1.0.0.tgz", "integrity": "sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/resolve": { "version": "1.22.8", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", + "license": "MIT", "dependencies": { "is-core-module": "^2.13.0", "path-parse": "^1.0.7", @@ -12165,6 +11729,7 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", "dev": true, + "license": "MIT", "engines": { "node": ">=4" } @@ -12174,6 +11739,8 @@ "resolved": "https://registry.npmjs.org/resolve-pkg/-/resolve-pkg-2.0.0.tgz", "integrity": "sha512-+1lzwXehGCXSeryaISr6WujZzowloigEofRB+dj75y9RRa/obVcYgbHJd53tdYw8pvZj8GojXaaENws8Ktw/hQ==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "resolve-from": "^5.0.0" }, @@ -12186,6 +11753,7 @@ "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", "dev": true, + "license": "MIT", "funding": { "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" } @@ -12195,49 +11763,36 @@ "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-5.0.0.tgz", "integrity": "sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==", "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/restore-cursor": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-3.1.0.tgz", - "integrity": "sha512-l+sSefzHpj5qimhFSE5a8nufZYAM3sBSVMAPtYkmC+4EH2anSGaEMXSD0izRQbu9nfyQ9y5JrVmp7E8oZrUjvA==", + "license": "MIT", "peer": true, - "dependencies": { - "onetime": "^5.1.0", - "signal-exit": "^3.0.2" - }, "engines": { "node": ">=8" } }, - "node_modules/restore-cursor/node_modules/signal-exit": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "peer": true - }, "node_modules/reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", "dev": true, + "license": "MIT", "engines": { "iojs": ">=1.0.0", "node": ">=0.10.0" } }, "node_modules/rfdc": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.3.1.tgz", - "integrity": "sha512-r5a3l5HzYlIC68TpmYKlxWjmOP6wiPJ1vWv2HeLhNsRZMrCkxeqxiHlQ21oXmQ4F3SiryXBHhAD7JZqvOJjFmg==", - "dev": true + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.4.1.tgz", + "integrity": "sha512-q1b3N5QkRUWUl7iyylaaj3kOpIT0N2i9MqIEQXP73GVsN9cw3fdx8X63cEmWhJGi2PPCF23Ijp7ktmd39rawIA==", + "dev": true, + "license": "MIT" }, "node_modules/rimraf": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", + "license": "ISC", "dependencies": { "glob": "^7.1.3" }, @@ -12252,6 +11807,7 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "license": "MIT", "dependencies": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -12261,6 +11817,8 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "license": "ISC", "dependencies": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -12280,6 +11838,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "license": "ISC", "dependencies": { "brace-expansion": "^1.1.7" }, @@ -12288,10 +11847,11 @@ } }, "node_modules/rollup": { - "version": "4.14.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.14.3.tgz", - "integrity": "sha512-ag5tTQKYsj1bhrFC9+OEWqb5O6VYgtQDO9hPDBMmIbePwhfSr+ExlcU741t8Dhw5DkPCQf6noz0jb36D6W9/hw==", + "version": "4.22.4", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.22.4.tgz", + "integrity": "sha512-vD8HJ5raRcWOyymsR6Z3o6+RzfEPCnVLMFJ6vRslO1jt4LO6dUo5Qnpg7y4RkZFM2DMe3WUirkI5c16onjrc6A==", "dev": true, + "license": "MIT", "dependencies": { "@types/estree": "1.0.5" }, @@ -12303,22 +11863,22 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.14.3", - "@rollup/rollup-android-arm64": "4.14.3", - "@rollup/rollup-darwin-arm64": "4.14.3", - "@rollup/rollup-darwin-x64": "4.14.3", - "@rollup/rollup-linux-arm-gnueabihf": "4.14.3", - "@rollup/rollup-linux-arm-musleabihf": "4.14.3", - "@rollup/rollup-linux-arm64-gnu": "4.14.3", - "@rollup/rollup-linux-arm64-musl": "4.14.3", - "@rollup/rollup-linux-powerpc64le-gnu": "4.14.3", - "@rollup/rollup-linux-riscv64-gnu": "4.14.3", - "@rollup/rollup-linux-s390x-gnu": "4.14.3", - "@rollup/rollup-linux-x64-gnu": "4.14.3", - "@rollup/rollup-linux-x64-musl": "4.14.3", - "@rollup/rollup-win32-arm64-msvc": "4.14.3", - "@rollup/rollup-win32-ia32-msvc": "4.14.3", - "@rollup/rollup-win32-x64-msvc": "4.14.3", + "@rollup/rollup-android-arm-eabi": "4.22.4", + "@rollup/rollup-android-arm64": "4.22.4", + "@rollup/rollup-darwin-arm64": "4.22.4", + "@rollup/rollup-darwin-x64": "4.22.4", + "@rollup/rollup-linux-arm-gnueabihf": "4.22.4", + "@rollup/rollup-linux-arm-musleabihf": "4.22.4", + "@rollup/rollup-linux-arm64-gnu": "4.22.4", + "@rollup/rollup-linux-arm64-musl": "4.22.4", + "@rollup/rollup-linux-powerpc64le-gnu": "4.22.4", + "@rollup/rollup-linux-riscv64-gnu": "4.22.4", + "@rollup/rollup-linux-s390x-gnu": "4.22.4", + "@rollup/rollup-linux-x64-gnu": "4.22.4", + "@rollup/rollup-linux-x64-musl": "4.22.4", + "@rollup/rollup-win32-arm64-msvc": "4.22.4", + "@rollup/rollup-win32-ia32-msvc": "4.22.4", + "@rollup/rollup-win32-x64-msvc": "4.22.4", "fsevents": "~2.3.2" } }, @@ -12327,6 +11887,7 @@ "resolved": "https://registry.npmjs.org/rollup-plugin-gzip/-/rollup-plugin-gzip-3.1.2.tgz", "integrity": "sha512-9xemMyvCjkklgNpu6jCYqQAbvCLJzA2nilkiOGzFuXTUX3cXEFMwIhsIBRF7kTKD/SnZ1tNPcxFm4m4zJ3VfNQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=10.0.0" }, @@ -12339,6 +11900,7 @@ "resolved": "https://registry.npmjs.org/rollup-plugin-string/-/rollup-plugin-string-3.0.0.tgz", "integrity": "sha512-vqyzgn9QefAgeKi+Y4A7jETeIAU1zQmS6VotH6bzm/zmUQEnYkpIGRaOBPY41oiWYV4JyBoGAaBjYMYuv+6wVw==", "dev": true, + "license": "MIT", "dependencies": { "rollup-pluginutils": "^2.4.1" } @@ -12348,6 +11910,7 @@ "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", "dev": true, + "license": "MIT", "dependencies": { "estree-walker": "^0.6.1" } @@ -12356,7 +11919,15 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", - "dev": true + "dev": true, + "license": "MIT" + }, + "node_modules/rollup/node_modules/@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true, + "license": "MIT" }, "node_modules/run-parallel": { "version": "1.2.0", @@ -12377,25 +11948,44 @@ "url": "https://feross.org/support" } ], + "license": "MIT", "dependencies": { "queue-microtask": "^1.2.2" } }, "node_modules/safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ], + "license": "MIT" }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/scheduler": { "version": "0.24.0-canary-efb381bbf-20230505", "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.24.0-canary-efb381bbf-20230505.tgz", "integrity": "sha512-ABvovCDe/k9IluqSh4/ISoq8tIJnW8euVAWYt5j/bg6dRnqwQwiGO1F/V4AyK96NGF/FB04FhOUDuWj8IKfABA==", + "license": "MIT", "peer": true, "dependencies": { "loose-envify": "^1.1.0" @@ -12405,37 +11995,41 @@ "version": "2.2.0", "resolved": "https://registry.npmjs.org/seed-random/-/seed-random-2.2.0.tgz", "integrity": "sha512-34EQV6AAHQGhoc0tn/96a9Fsi6v2xdqe/dMUwljGRaFOzR3EgRmECvD0O8vi8X+/uQ50LGHfkNu/Eue5TPKZkQ==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, - "node_modules/semver": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", - "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", + "node_modules/selfsigned": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/selfsigned/-/selfsigned-2.4.1.tgz", + "integrity": "sha512-th5B4L2U+eGLq1TVh7zNRGBapioSORUeymIydxgFpwww9d2qyKvtuPU2jJuHvYAwwqi2Y596QBL3eEqcPEYL8Q==", + "license": "MIT", + "peer": true, "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" + "@types/node-forge": "^1.3.0", + "node-forge": "^1" }, "engines": { "node": ">=10" } }, - "node_modules/semver/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dependencies": { - "yallist": "^4.0.0" + "node_modules/semver": { + "version": "7.6.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", + "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "license": "ISC", + "bin": { + "semver": "bin/semver.js" }, "engines": { "node": ">=10" } }, "node_modules/send": { - "version": "0.18.0", - "resolved": "https://registry.npmjs.org/send/-/send-0.18.0.tgz", - "integrity": "sha512-qqWzuOjSFOuqPjFe4NOsMLafToQQwBSOEpS+FwEt3A2V3vKubTquT3vmLTQpFgMXp8AlFWFuP1qKaJZOtPpVXg==", + "version": "0.19.0", + "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", + "integrity": "sha512-dW41u5VfLXu8SJh5bwRmyYUbAoSB3c9uQh6L8h/KtsFREPWpbX1lrljJo186Jc4nmci/sGUZ9a0a0J2zgfq2hw==", + "license": "MIT", "peer": true, "dependencies": { "debug": "2.6.9", @@ -12460,6 +12054,7 @@ "version": "2.6.9", "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", "peer": true, "dependencies": { "ms": "2.0.0" @@ -12469,12 +12064,14 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT", "peer": true }, "node_modules/send/node_modules/mime": { "version": "1.6.0", "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "license": "MIT", "peer": true, "bin": { "mime": "cli.js" @@ -12483,42 +12080,24 @@ "node": ">=4" } }, - "node_modules/send/node_modules/ms": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", - "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", - "peer": true - }, "node_modules/send/node_modules/statuses": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==", + "license": "MIT", "peer": true, "engines": { "node": ">= 0.8" } }, "node_modules/serialize-error": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-4.1.0.tgz", - "integrity": "sha512-5j9GgyGsP9vV9Uj1S0lDCvlsd+gc2LEPVK7HHHte7IyPwOD4lVQFeaX143gx3U5AnoCi+wbcb3mvaxVysjpxEw==", - "dev": true, - "peer": true, - "dependencies": { - "type-fest": "^0.3.0" - }, - "engines": { - "node": ">=8" - } - }, - "node_modules/serialize-error/node_modules/type-fest": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.3.1.tgz", - "integrity": "sha512-cUGJnCdr4STbePCgqNFbpVNCepa+kAVohJs1sLhxzdH+gnEoOd8VhbYa7pD3zZYGiURWM2xzEII3fQcRizDkYQ==", - "dev": true, + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/serialize-error/-/serialize-error-2.1.0.tgz", + "integrity": "sha512-ghgmKt5o4Tly5yEG/UJp8qTd0AN7Xalw4XBtDEKP655B699qMEtra1WlXeE6WIvdEG481JvRxULKsInq/iNysw==", + "license": "MIT", "peer": true, "engines": { - "node": ">=6" + "node": ">=0.10.0" } }, "node_modules/serialize-javascript": { @@ -12526,36 +12105,43 @@ "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "randombytes": "^2.1.0" } }, "node_modules/serve-static": { - "version": "1.15.0", - "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.15.0.tgz", - "integrity": "sha512-XGuRDNjXUijsUL0vl6nSD7cwURuzEgglbOaFuZM9g3kwDXOWVTck0jLzjPzGD+TazWbboZYu52/9/XPdUgne9g==", + "version": "1.16.2", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.16.2.tgz", + "integrity": "sha512-VqpjJZKadQB/PEbEwvFdO43Ax5dFBZ2UECszz8bQ7pi7wt//PWe1P6MN7eCnjsatYtBT6EuiClbjSWP2WrIoTw==", + "license": "MIT", "peer": true, "dependencies": { - "encodeurl": "~1.0.2", + "encodeurl": "~2.0.0", "escape-html": "~1.0.3", "parseurl": "~1.3.3", - "send": "0.18.0" + "send": "0.19.0" }, "engines": { "node": ">= 0.8.0" } }, - "node_modules/set-blocking": { + "node_modules/serve-static/node_modules/encodeurl": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", - "peer": true + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">= 0.8" + } }, "node_modules/set-function-length": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", "dev": true, + "license": "MIT", "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -12573,6 +12159,7 @@ "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.2.tgz", "integrity": "sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==", "dev": true, + "license": "MIT", "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -12586,12 +12173,14 @@ "node_modules/setprototypeof": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", - "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==" + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" }, "node_modules/shallow-clone": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/shallow-clone/-/shallow-clone-3.0.1.tgz", "integrity": "sha512-/6KqX+GVUdqPuPPd2LxDDxzX6CAbjJehAAOKlNpqqUpAqPM6HeL8f+o3a+JsyGjn2lv0WY8UsTgUJjU9Ok55NA==", + "license": "MIT", "peer": true, "dependencies": { "kind-of": "^6.0.2" @@ -12604,6 +12193,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "license": "MIT", "dependencies": { "shebang-regex": "^3.0.0" }, @@ -12615,6 +12205,7 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "license": "MIT", "engines": { "node": ">=8" } @@ -12623,6 +12214,7 @@ "version": "1.8.1", "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", + "license": "MIT", "peer": true, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -12633,37 +12225,34 @@ "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", "dev": true, + "license": "MIT", "dependencies": { "call-bind": "^1.0.7", "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.4", - "object-inspect": "^1.13.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/signal-exit": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", - "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", - "dev": true, + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, "engines": { - "node": ">=14" + "node": ">= 0.4" }, "funding": { - "url": "https://github.com/sponsors/isaacs" + "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "license": "ISC", + "peer": true + }, "node_modules/sinon": { "version": "7.5.0", "resolved": "https://registry.npmjs.org/sinon/-/sinon-7.5.0.tgz", "integrity": "sha512-AoD0oJWerp0/rY9czP/D6hDTTUYGpObhZjMpd7Cl/A6+j0xBE+ayL/ldfggkBXUs0IkvIiM1ljM8+WkOc5k78Q==", "deprecated": "16.1.1", "dev": true, + "license": "BSD-3-Clause", "dependencies": { "@sinonjs/commons": "^1.4.0", "@sinonjs/formatio": "^3.2.1", @@ -12679,16 +12268,28 @@ "resolved": "https://registry.npmjs.org/sinon-chai/-/sinon-chai-3.7.0.tgz", "integrity": "sha512-mf5NURdUaSdnatJx3uhoBOrY9dtL19fiOtAdT1Azxg3+lNJFiuN0uzaU3xX1LeAfL17kHQhTAJgpsfhbMJMY2g==", "dev": true, + "license": "(BSD-2-Clause OR WTFPL)", "peerDependencies": { "chai": "^4.0.0", "sinon": ">=4.0.0" } }, + "node_modules/sinon/node_modules/@sinonjs/commons": { + "version": "1.8.6", + "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", + "integrity": "sha512-Ky+XkAkqPZSm3NLBeUng77EBQl3cmeJhITaGHdYH8kjVB+aun3S4XBRti2zt17mtt0mIUDiNxYeoJm6drVvBJQ==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "type-detect": "4.0.8" + } + }, "node_modules/sinon/node_modules/diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true, + "license": "BSD-3-Clause", "engines": { "node": ">=0.3.1" } @@ -12698,6 +12299,7 @@ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", "dev": true, + "license": "MIT", "engines": { "node": ">=4" } @@ -12707,6 +12309,7 @@ "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "dev": true, + "license": "MIT", "dependencies": { "has-flag": "^3.0.0" }, @@ -12714,59 +12317,30 @@ "node": ">=4" } }, - "node_modules/sisteransi": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", - "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", - "peer": true + "node_modules/sinon/node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=4" + } }, "node_modules/slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", + "license": "MIT", "engines": { "node": ">=8" } }, - "node_modules/slice-ansi": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/slice-ansi/-/slice-ansi-2.1.0.tgz", - "integrity": "sha512-Qu+VC3EwYLldKa1fCxuuvULvSJOKEgk9pi8dZeCVK7TqBfUNTH4sFkk4joj8afVSfAYgJoSOetjx9QWOJ5mYoQ==", - "peer": true, - "dependencies": { - "ansi-styles": "^3.2.0", - "astral-regex": "^1.0.0", - "is-fullwidth-code-point": "^2.0.0" - }, - "engines": { - "node": ">=6" - } - }, - "node_modules/slice-ansi/node_modules/ansi-styles": { - "version": "3.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", - "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", - "peer": true, - "dependencies": { - "color-convert": "^1.9.0" - }, - "engines": { - "node": ">=4" - } - }, - "node_modules/slice-ansi/node_modules/is-fullwidth-code-point": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", - "integrity": "sha512-VHskAKYM8RfSFXwee5t5cbN5PZeq1Wrh6qd5bkyiXIf6UQcN6w/A0eXM9r6t8d+GYOh+o6ZhiEnb88LN/Y8m2w==", - "peer": true, - "engines": { - "node": ">=4" - } - }, "node_modules/smart-buffer": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", + "license": "MIT", "engines": { "node": ">= 6.0.0", "npm": ">= 3.0.0" @@ -12776,19 +12350,21 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/smob/-/smob-1.5.0.tgz", "integrity": "sha512-g6T+p7QO8npa+/hNx9ohv1E5pVCmWrVCUzUXJyLdMmftX6ER0oiWY/w9knEonLpnOp6b6FenKnMfR8gqwWdwig==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/socket.io": { - "version": "4.7.5", - "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.7.5.tgz", - "integrity": "sha512-DmeAkF6cwM9jSfmp6Dr/5/mfMwb5Z5qRrSXLpo3Fq5SqyU8CMF15jIN4ZhfSwu35ksM1qmHZDQ/DK5XTccSTvA==", + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-4.8.1.tgz", + "integrity": "sha512-oZ7iUCxph8WYRHHcjBEc9unw3adt5CmSNlppj/5Q4k2RIrhl8Z5yY2Xr4j9zj0+wzVZ0bxmYoGSzKJnRl6A4yg==", "dev": true, + "license": "MIT", "dependencies": { "accepts": "~1.3.4", "base64id": "~2.0.0", "cors": "~2.8.5", "debug": "~4.3.2", - "engine.io": "~6.5.2", + "engine.io": "~6.6.0", "socket.io-adapter": "~2.5.2", "socket.io-parser": "~4.2.4" }, @@ -12797,13 +12373,36 @@ } }, "node_modules/socket.io-adapter": { - "version": "2.5.4", - "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.4.tgz", - "integrity": "sha512-wDNHGXGewWAjQPt3pyeYBtpWSq9cLE5UW1ZUPL/2eGK9jtse/FpXib7epSTsz0Q0m+6sg6Y4KtcFTlah1bdOVg==", + "version": "2.5.5", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-2.5.5.tgz", + "integrity": "sha512-eLDQas5dzPgOWCk9GuuJC2lBqItuhKI4uxGgo9aIV7MYbk2h9Q6uULEh8WBzThoI7l+qU9Ast9fVUmkqPP9wYg==", "dev": true, + "license": "MIT", "dependencies": { "debug": "~4.3.4", - "ws": "~8.11.0" + "ws": "~8.17.1" + } + }, + "node_modules/socket.io-adapter/node_modules/ws": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } } }, "node_modules/socket.io-parser": { @@ -12811,6 +12410,7 @@ "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-4.2.4.tgz", "integrity": "sha512-/GbIKmo8ioc+NIWIhwdecY0ge+qVBSMdgxGygevmdHj24bsfgtCmcUUcQ5ZzcylGFHsN3k4HB4Cgkl96KVnuew==", "dev": true, + "license": "MIT", "dependencies": { "@socket.io/component-emitter": "~3.1.0", "debug": "~4.3.1" @@ -12823,6 +12423,7 @@ "version": "2.8.3", "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz", "integrity": "sha512-l5x7VUUWbjVFbafGLxPWkYsHIhEvmF85tbIeFZWc8ZPtoMyybuEhL7Jye/ooC4/d48FgOjSJXgsF/AJPYCW8Zw==", + "license": "MIT", "dependencies": { "ip-address": "^9.0.5", "smart-buffer": "^4.2.0" @@ -12833,13 +12434,14 @@ } }, "node_modules/socks-proxy-agent": { - "version": "8.0.3", - "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.3.tgz", - "integrity": "sha512-VNegTZKhuGq5vSD6XNKlbqWhyt/40CgoEw8XxD6dhnm8Jq9IEa3nIa4HwnM8XOqU0CdB0BwWVXusqiFXfHB3+A==", + "version": "8.0.4", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.4.tgz", + "integrity": "sha512-GNAq/eg8Udq2x0eNiFkr9gRg5bA7PXEWagQdeRX4cPSG+X/8V38v637gim9bjFptMk1QWsCTr0ttrJEiXbNnRw==", + "license": "MIT", "dependencies": { "agent-base": "^7.1.1", "debug": "^4.3.4", - "socks": "^2.7.1" + "socks": "^2.8.3" }, "engines": { "node": ">= 14" @@ -12849,6 +12451,7 @@ "version": "0.6.1", "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "license": "BSD-3-Clause", "engines": { "node": ">=0.10.0" } @@ -12857,6 +12460,7 @@ "version": "0.5.21", "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "license": "MIT", "dependencies": { "buffer-from": "^1.0.0", "source-map": "^0.6.0" @@ -12867,6 +12471,8 @@ "resolved": "https://registry.npmjs.org/spdx-correct/-/spdx-correct-3.2.0.tgz", "integrity": "sha512-kN9dJbvnySHULIluDHy32WHRUu3Og7B9sbY7tsFLctQkIqnMh3hErYgdMjTYuqmcXX+lK5T1lnUt3G7zNswmZA==", "dev": true, + "license": "Apache-2.0", + "peer": true, "dependencies": { "spdx-expression-parse": "^3.0.0", "spdx-license-ids": "^3.0.0" @@ -12876,50 +12482,41 @@ "version": "2.5.0", "resolved": "https://registry.npmjs.org/spdx-exceptions/-/spdx-exceptions-2.5.0.tgz", "integrity": "sha512-PiU42r+xO4UbUS1buo3LPJkjlO7430Xn5SVAhdpzzsPHsjbYVflnnFdATgabnLude+Cqu25p6N+g2lw/PFsa4w==", - "dev": true + "dev": true, + "license": "CC-BY-3.0", + "peer": true }, "node_modules/spdx-expression-parse": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/spdx-expression-parse/-/spdx-expression-parse-3.0.1.tgz", "integrity": "sha512-cbqHunsQWnJNE6KhVSMsMeH5H/L9EpymbzqTQ3uLwNCLZ1Q481oWaofqH7nO6V07xlXwY6PhQdQ2IedWx/ZK4Q==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "spdx-exceptions": "^2.1.0", "spdx-license-ids": "^3.0.0" } }, "node_modules/spdx-license-ids": { - "version": "3.0.17", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.17.tgz", - "integrity": "sha512-sh8PWc/ftMqAAdFiBu6Fy6JUOYjqDJBJvIhpfDMyHrr0Rbp5liZqd4TjtQ/RgfLjKFZb+LMx5hpml5qOWy0qvg==", - "dev": true + "version": "3.0.20", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.20.tgz", + "integrity": "sha512-jg25NiDV/1fLtSgEgyvVyDunvaNHbuwF9lfNV17gSmPFAlYzdfNBlLtLzXTevwkPj7DhGbmN9VnmJIgLnhvaBw==", + "dev": true, + "license": "CC0-1.0", + "peer": true }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", - "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==" - }, - "node_modules/stack-chain": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/stack-chain/-/stack-chain-2.0.0.tgz", - "integrity": "sha512-GGrHXePi305aW7XQweYZZwiRwR7Js3MWoK/EHzzB9ROdc75nCnjSJVi21rdAGxFl+yCx2L2qdfl5y7NO4lTyqg==", - "dev": true, - "peer": true - }, - "node_modules/stack-generator": { - "version": "2.0.10", - "resolved": "https://registry.npmjs.org/stack-generator/-/stack-generator-2.0.10.tgz", - "integrity": "sha512-mwnua/hkqM6pF4k8SnmZ2zfETsRUpWXREfA/goT8SLCV4iOFa4bzOX2nDipWAZFPTjLvQB82f5yaodMVhK0yJQ==", - "dev": true, - "peer": true, - "dependencies": { - "stackframe": "^1.3.4" - } + "integrity": "sha512-D9cPgkvLlV3t3IzL0D0YLvGA9Ahk4PcvVwUbN0dSGr1aP0Nrt4AEnTUbuGvquEC0mA64Gqt1fzirlRs5ibXx8g==", + "license": "BSD-3-Clause" }, "node_modules/stack-utils": { "version": "2.0.6", "resolved": "https://registry.npmjs.org/stack-utils/-/stack-utils-2.0.6.tgz", "integrity": "sha512-XlkWvfIm6RmsWtNJx+uqtKLS8eqFbxUg0ZzLXqY0caEy9l7hruX8IpiDnjsLavoBgqCCR71TqWO8MaXYheJ3RQ==", + "license": "MIT", "dependencies": { "escape-string-regexp": "^2.0.0" }, @@ -12927,48 +12524,27 @@ "node": ">=10" } }, - "node_modules/stackframe": { - "version": "1.3.4", - "resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.3.4.tgz", - "integrity": "sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==" - }, - "node_modules/stacktrace-gps": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/stacktrace-gps/-/stacktrace-gps-3.1.2.tgz", - "integrity": "sha512-GcUgbO4Jsqqg6RxfyTHFiPxdPqF+3LFmQhm7MgCuYQOYuWyqxo5pwRPz5d/u6/WYJdEnWfK4r+jGbyD8TSggXQ==", - "dev": true, - "peer": true, - "dependencies": { - "source-map": "0.5.6", - "stackframe": "^1.3.4" - } - }, - "node_modules/stacktrace-gps/node_modules/source-map": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.5.6.tgz", - "integrity": "sha512-MjZkVp0NHr5+TPihLcadqnlVoGIoWo4IBHptutGh9wI3ttUYvCG26HkSuDi+K6lsZ25syXJXcctwgyVCt//xqA==", - "dev": true, - "peer": true, + "node_modules/stack-utils/node_modules/escape-string-regexp": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz", + "integrity": "sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==", + "license": "MIT", "engines": { - "node": ">=0.10.0" + "node": ">=8" } }, - "node_modules/stacktrace-js": { - "version": "2.0.2", - "resolved": "https://registry.npmjs.org/stacktrace-js/-/stacktrace-js-2.0.2.tgz", - "integrity": "sha512-Je5vBeY4S1r/RnLydLl0TBTi3F2qdfWmYsGvtfZgEI+SCprPppaIhQf5nGcal4gI4cGpCV/duLcAzT1np6sQqg==", - "dev": true, - "peer": true, - "dependencies": { - "error-stack-parser": "^2.0.6", - "stack-generator": "^2.0.5", - "stacktrace-gps": "^3.0.4" - } + "node_modules/stackframe": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/stackframe/-/stackframe-1.3.4.tgz", + "integrity": "sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==", + "license": "MIT", + "peer": true }, "node_modules/stacktrace-parser": { "version": "0.1.10", "resolved": "https://registry.npmjs.org/stacktrace-parser/-/stacktrace-parser-0.1.10.tgz", "integrity": "sha512-KJP1OCML99+8fhOHxwwzyWrlUuVX5GQ0ZpJTd1DFXhdkrvg1szxfHhawXUZ3g9TkXORQd4/WG68jMlQZ2p8wlg==", + "license": "MIT", "peer": true, "dependencies": { "type-fest": "^0.7.1" @@ -12981,6 +12557,7 @@ "version": "0.7.1", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.7.1.tgz", "integrity": "sha512-Ne2YiiGN8bmrmJJEuTWTLJR32nh/JdL1+PSicowtNb0WFpn59GK8/lfD61bVtzguz7b3PBt74nxpv/Pw5po5Rg==", + "license": "(MIT OR CC0-1.0)", "peer": true, "engines": { "node": ">=8" @@ -12990,6 +12567,7 @@ "version": "1.5.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "integrity": "sha512-OpZ3zP+jT1PI7I8nemJX4AKmAX070ZkYPVWV/AaKTJl+tXCTGyVdC1a4SL8RUQYEwk/f34ZX8UTykN68FwrqAA==", + "license": "MIT", "engines": { "node": ">= 0.6" } @@ -12999,6 +12577,7 @@ "resolved": "https://registry.npmjs.org/streamroller/-/streamroller-3.1.5.tgz", "integrity": "sha512-KFxaM7XT+irxvdqSP1LGLgNWbYN7ay5owZ3r/8t77p+EtSUAfUgtl7be3xtqtOmGUl9K9YPO2ca8133RlTjvKw==", "dev": true, + "license": "MIT", "dependencies": { "date-format": "^4.0.14", "debug": "^4.3.4", @@ -13013,6 +12592,7 @@ "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", "dev": true, + "license": "MIT", "dependencies": { "graceful-fs": "^4.2.0", "jsonfile": "^4.0.0", @@ -13027,6 +12607,7 @@ "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", "dev": true, + "license": "MIT", "optionalDependencies": { "graceful-fs": "^4.1.6" } @@ -13036,24 +12617,42 @@ "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", "dev": true, + "license": "MIT", "engines": { "node": ">= 4.0.0" } }, + "node_modules/strict-event-emitter": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz", + "integrity": "sha512-vMgjE/GGEPEFnhFub6pa4FmJBRBVOLpIII2hvCZ8Kzb7K0hlHo7mQv6xYrBvCL2LtAIBwFUK8wvuJgTVSQ5MFQ==", + "dev": true, + "license": "MIT" + }, "node_modules/string_decoder": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "license": "MIT", "peer": true, "dependencies": { "safe-buffer": "~5.1.0" } }, + "node_modules/string_decoder/node_modules/safe-buffer": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", + "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "license": "MIT", + "peer": true + }, "node_modules/string-argv": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz", "integrity": "sha512-a1uQGz7IyVy9YwhqjZIZu1c8JO8dNIe20xBmSS6qu9kv++k3JGzCVmprbNN5Kn+BgzD5E7YYwg1CcjuJMRNsvg==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=0.6.19" } @@ -13062,6 +12661,7 @@ "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "license": "MIT", "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -13077,6 +12677,8 @@ "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "emoji-regex": "^8.0.0", "is-fullwidth-code-point": "^3.0.0", @@ -13090,6 +12692,7 @@ "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "license": "MIT", "dependencies": { "ansi-regex": "^5.0.1" }, @@ -13103,6 +12706,8 @@ "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "ansi-regex": "^5.0.1" }, @@ -13110,28 +12715,12 @@ "node": ">=8" } }, - "node_modules/strip-ansi-cjs/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "dev": true, - "engines": { - "node": ">=8" - } - }, - "node_modules/strip-ansi/node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", - "engines": { - "node": ">=8" - } - }, "node_modules/strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", "dev": true, + "license": "MIT", "optional": true, "engines": { "node": ">=4" @@ -13141,6 +12730,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", + "license": "MIT", "peer": true, "engines": { "node": ">=6" @@ -13151,6 +12741,7 @@ "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true, + "license": "MIT", "engines": { "node": ">=8" }, @@ -13158,36 +12749,23 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/strnum": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz", - "integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==", - "peer": true - }, - "node_modules/sudo-prompt": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/sudo-prompt/-/sudo-prompt-9.2.1.tgz", - "integrity": "sha512-Mu7R0g4ig9TUuGSxJavny5Rv0egCEtpZRNMrZaYS1vxkiIxGiGUwoezU3LazIQ+KE04hTrTfNPgxU5gzi7F5Pw==", - "peer": true - }, "node_modules/supports-color": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", - "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "license": "MIT", "dependencies": { "has-flag": "^4.0.0" }, "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/supports-color?sponsor=1" + "node": ">=8" } }, "node_modules/supports-preserve-symlinks-flag": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "license": "MIT", "engines": { "node": ">= 0.4" }, @@ -13196,10 +12774,11 @@ } }, "node_modules/synckit": { - "version": "0.8.8", - "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.8.8.tgz", - "integrity": "sha512-HwOKAP7Wc5aRGYdKH+dw0PRRpbO841v2DENBtjnR5HFWoiNByAl7vrx3p0G/rCyYXQsrxqtX48TImFtPcIHSpQ==", + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.2.tgz", + "integrity": "sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==", "dev": true, + "license": "MIT", "dependencies": { "@pkgr/core": "^0.1.0", "tslib": "^2.6.2" @@ -13215,6 +12794,7 @@ "version": "0.8.4", "resolved": "https://registry.npmjs.org/temp/-/temp-0.8.4.tgz", "integrity": "sha512-s0ZZzd0BzYv5tLSptZooSjK8oj6C+c19p7Vqta9+6NPOf7r+fxq0cJe6/oN4LTC79sy5NY8ucOJNgwsKCSbfqg==", + "license": "MIT", "peer": true, "dependencies": { "rimraf": "~2.6.2" @@ -13223,19 +12803,11 @@ "node": ">=6.0.0" } }, - "node_modules/temp-dir": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/temp-dir/-/temp-dir-2.0.0.tgz", - "integrity": "sha512-aoBAniQmmwtcKp/7BzsH8Cxzv8OL736p7v1ihGb5e9DJ9kTwGWHrQrVB5+lfVDzfGrdRzXch+ig7LHaY1JTOrg==", - "peer": true, - "engines": { - "node": ">=8" - } - }, "node_modules/temp/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "license": "MIT", "peer": true, "dependencies": { "balanced-match": "^1.0.0", @@ -13246,6 +12818,8 @@ "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "license": "ISC", "peer": true, "dependencies": { "fs.realpath": "^1.0.0", @@ -13266,6 +12840,7 @@ "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "license": "ISC", "peer": true, "dependencies": { "brace-expansion": "^1.1.7" @@ -13278,6 +12853,8 @@ "version": "2.6.3", "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "deprecated": "Rimraf versions prior to v4 are no longer supported", + "license": "ISC", "peer": true, "dependencies": { "glob": "^7.1.3" @@ -13287,9 +12864,10 @@ } }, "node_modules/terser": { - "version": "5.30.3", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.30.3.tgz", - "integrity": "sha512-STdUgOUx8rLbMGO9IOwHLpCqolkDITFFQSMYYwKE1N2lY6MVSaeoi10z/EhWxRc6ybqoVmKSkhKYH/XUpl7vSA==", + "version": "5.36.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.36.0.tgz", + "integrity": "sha512-IYV9eNMuFAV4THUspIRXkLakHnV6XO7FEdtKjf/mDyrnqUg9LnlOn6/RwRvM9SZjR4GUq8Nk8zj67FzVARr74w==", + "license": "BSD-2-Clause", "dependencies": { "@jridgewell/source-map": "^0.3.3", "acorn": "^8.8.2", @@ -13306,25 +12884,91 @@ "node_modules/terser/node_modules/commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", + "license": "MIT" + }, + "node_modules/test-exclude": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-6.0.0.tgz", + "integrity": "sha512-cAGWPIyOHU6zlmg88jwm7VRyXnMN7iV68OGAbYDk/Mh/xC/pzVPlQtY6ngoIH/5/tciuhGfvESU8GrHrcxD56w==", + "license": "ISC", + "peer": true, + "dependencies": { + "@istanbuljs/schema": "^0.1.2", + "glob": "^7.1.4", + "minimatch": "^3.0.4" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/test-exclude/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "license": "MIT", + "peer": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/test-exclude/node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "license": "ISC", + "peer": true, + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/test-exclude/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "license": "ISC", + "peer": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } }, "node_modules/text-encoding": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/text-encoding/-/text-encoding-0.7.0.tgz", "integrity": "sha512-oJQ3f1hrOnbRLOcwKz0Liq2IcrvDeZRHXhd9RgLrsT+DjWY/nty1Hi7v3dtkaEYbPYe0mUoOfzRrMwfXXwgPUA==", - "deprecated": "no longer maintained" + "deprecated": "no longer maintained", + "license": "(Unlicense OR Apache-2.0)" }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/thenify": { "version": "3.3.1", "resolved": "https://registry.npmjs.org/thenify/-/thenify-3.3.1.tgz", "integrity": "sha512-RVZSIV5IG10Hk3enotrhvz0T9em6cyHBLkH/YAZuKqd8hRkKhSfCGIcP2KUY0EPxndzANBmNllzWPwak+bheSw==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "any-promise": "^1.0.0" } @@ -13334,6 +12978,8 @@ "resolved": "https://registry.npmjs.org/thenify-all/-/thenify-all-1.6.0.tgz", "integrity": "sha512-RNxQH/qI8/t3thXJDwcstUO4zeqo64+Uy/+sNVRBx4Xn2OX+OZ9oP+iJnNFqplFra2ZUVeKCSa2oVWi3T4uVmA==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "thenify": ">= 3.1.0 < 4" }, @@ -13345,12 +12991,14 @@ "version": "5.0.0", "resolved": "https://registry.npmjs.org/throat/-/throat-5.0.0.tgz", "integrity": "sha512-fcwX4mndzpLQKBS1DVYhGAcYaYt7vsHNIvQV+WXMvnow5cgjPphq5CaayLaGsjRdSCKZFNGt7/GYAuXaNOiYCA==", + "license": "MIT", "peer": true }, "node_modules/through2": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", "integrity": "sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==", + "license": "MIT", "peer": true, "dependencies": { "readable-stream": "~2.3.6", @@ -13361,41 +13009,16 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/tiny-case/-/tiny-case-1.0.3.tgz", "integrity": "sha512-Eet/eeMhkO6TX8mnUteS9zgPbUMQa4I6Kkp5ORiBD5476/m+PIRiumP5tmh5ioJpH7k51Kehawy2UDfsnxxY8Q==", - "dev": true - }, - "node_modules/title-case": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/title-case/-/title-case-2.1.1.tgz", - "integrity": "sha512-EkJoZ2O3zdCz3zJsYCsxyq2OC5hrxR9mfdd5I+w8h/tmFfeOxJ+vvkxsKxdmN0WtS9zLdHEgfgVOiMVgv+Po4Q==", - "dev": true, - "peer": true, - "dependencies": { - "no-case": "^2.2.0", - "upper-case": "^1.0.3" - } - }, - "node_modules/title-case/node_modules/lower-case": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/lower-case/-/lower-case-1.1.4.tgz", - "integrity": "sha512-2Fgx1Ycm599x+WGpIYwJOvsjmXFzTSc34IwDWALRA/8AopUKAVPwfJ+h5+f85BCp0PWmmJcWzEpxOpoXycMpdA==", "dev": true, + "license": "MIT", "peer": true }, - "node_modules/title-case/node_modules/no-case": { - "version": "2.3.2", - "resolved": "https://registry.npmjs.org/no-case/-/no-case-2.3.2.tgz", - "integrity": "sha512-rmTZ9kz+f3rCvK2TD1Ue/oZlns7OGoIWP4fc3llxxRXlOkHKoWPPWJOfFYpITabSow43QJbRIoHQXtt10VldyQ==", - "dev": true, - "peer": true, - "dependencies": { - "lower-case": "^1.1.1" - } - }, "node_modules/tmp": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==", "dev": true, + "license": "MIT", "engines": { "node": ">=14.14" } @@ -13404,21 +13027,14 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz", "integrity": "sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==", + "license": "BSD-3-Clause", "peer": true }, - "node_modules/to-fast-properties": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz", - "integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==", - "peer": true, - "engines": { - "node": ">=4" - } - }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "license": "MIT", "dependencies": { "is-number": "^7.0.0" }, @@ -13430,6 +13046,7 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", "engines": { "node": ">=0.6" } @@ -13438,18 +13055,22 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/toposort/-/toposort-2.0.2.tgz", "integrity": "sha512-0a5EOkAUp8D4moMi2W8ZF8jcga7BgZd91O/yabJCFY8az+XSzeGyTKs0Aoo897iV1Nj6guFq8orWDS96z91oGg==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/tr46": { "version": "0.0.3", "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" }, "node_modules/ts-api-utils": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.3.0.tgz", - "integrity": "sha512-UQMIo7pb8WRomKR1/+MFVLTroIvDVtMX3K6OUir8ynLyzB8Jeriont2bTAtmNPa1ekAgN7YPDyf6V+ygrdU+eQ==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.0.tgz", + "integrity": "sha512-032cPxaEKwM+GT3vA5JXNzIaizx388rhsSW79vGRNGXfRRAdEAn2mvk36PvK5HnOchyWZ7afLEXqYCvPCrzuzQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=16" }, @@ -13457,20 +13078,12 @@ "typescript": ">=4.2.0" } }, - "node_modules/ts-dedent": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/ts-dedent/-/ts-dedent-2.2.0.tgz", - "integrity": "sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==", - "dev": true, - "engines": { - "node": ">=6.10" - } - }, "node_modules/ts-mocha": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/ts-mocha/-/ts-mocha-10.0.0.tgz", "integrity": "sha512-VRfgDO+iiuJFlNB18tzOfypJ21xn2xbuZyDvJvqpTbWgkAgD17ONGr8t+Tl8rcBtOBdjXp5e/Rk+d39f7XBHRw==", "dev": true, + "license": "MIT", "dependencies": { "ts-node": "7.0.1" }, @@ -13492,27 +13105,17 @@ "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", "dev": true, + "license": "BSD-3-Clause", "engines": { "node": ">=0.3.1" } }, - "node_modules/ts-mocha/node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", - "dev": true, - "dependencies": { - "minimist": "^1.2.6" - }, - "bin": { - "mkdirp": "bin/cmd.js" - } - }, "node_modules/ts-mocha/node_modules/ts-node": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", "integrity": "sha512-BVwVbPJRspzNh2yfslyT1PSbl5uIk03EZlb493RKHN4qej/D06n1cEhjlOJG69oFsE7OT8XjpTUcYf6pKTLMhw==", "dev": true, + "license": "MIT", "dependencies": { "arrify": "^1.0.0", "buffer-from": "^1.1.0", @@ -13535,6 +13138,7 @@ "resolved": "https://registry.npmjs.org/yn/-/yn-2.0.0.tgz", "integrity": "sha512-uTv8J/wiWTgUTg+9vLTi//leUl5vDQS6uii/emeTb2ssY7vl6QWf2fFbIIGjnhjvbdKlU0ed7QPgY1htTC86jQ==", "dev": true, + "license": "MIT", "engines": { "node": ">=4" } @@ -13544,6 +13148,7 @@ "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", "dev": true, + "license": "MIT", "dependencies": { "@cspotcode/source-map-support": "^0.8.0", "@tsconfig/node10": "^1.0.7", @@ -13582,11 +13187,22 @@ } } }, + "node_modules/ts-node/node_modules/diff": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, "node_modules/tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", "integrity": "sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==", "dev": true, + "license": "MIT", "optional": true, "dependencies": { "@types/json5": "^0.0.29", @@ -13595,19 +13211,35 @@ "strip-bom": "^3.0.0" } }, + "node_modules/tsconfig-paths/node_modules/json5": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.2.tgz", + "integrity": "sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==", + "dev": true, + "license": "MIT", + "optional": true, + "dependencies": { + "minimist": "^1.2.0" + }, + "bin": { + "json5": "lib/cli.js" + } + }, "node_modules/tslib": { - "version": "2.6.2", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.6.2.tgz", - "integrity": "sha512-AEYxH93jGFPn/a2iVAwW87VuUIkR1FVUKB77NwMF7nBTDkDrrT/Hpt/IrCJ0QXhW27jTBDcf5ZY7w6RiqTMw2Q==" + "version": "2.8.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.0.tgz", + "integrity": "sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==", + "license": "0BSD" }, "node_modules/tsx": { - "version": "4.7.2", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.7.2.tgz", - "integrity": "sha512-BCNd4kz6fz12fyrgCTEdZHGJ9fWTGeUzXmQysh0RVocDY3h4frk05ZNCXSy4kIenF7y/QnrdiVpTsyNRn6vlAw==", + "version": "4.19.2", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.2.tgz", + "integrity": "sha512-pOUl6Vo2LUq/bSa8S5q7b91cgNSjctn9ugq/+Mvow99qW6x/UZYwzxy/3NmqoT66eHYfCVvFvACC58UBPFf28g==", "dev": true, + "license": "MIT", "dependencies": { - "esbuild": "~0.19.10", - "get-tsconfig": "^4.7.2" + "esbuild": "~0.23.0", + "get-tsconfig": "^4.7.5" }, "bin": { "tsx": "dist/cli.mjs" @@ -13619,18 +13251,12 @@ "fsevents": "~2.3.3" } }, - "node_modules/type": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz", - "integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw==", - "dev": true, - "peer": true - }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, + "license": "MIT", "dependencies": { "prelude-ls": "^1.2.1" }, @@ -13639,20 +13265,23 @@ } }, "node_modules/type-detect": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.1.0.tgz", + "integrity": "sha512-Acylog8/luQ8L7il+geoSxhEkazvkslg7PSNKOX59mbB9cOveP5aq9h74Y7YU8yDpJwetzQQrfIwtf4Wp4LKcw==", + "dev": true, + "license": "MIT", "engines": { "node": ">=4" } }, "node_modules/type-fest": { - "version": "4.15.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.15.0.tgz", - "integrity": "sha512-tB9lu0pQpX5KJq54g+oHOLumOx+pMep4RaM6liXh2PKmVRFF+/vAtUP0ZaJ0kOySfVNjF6doBWPHhBhISKdlIA==", + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true, + "license": "(MIT OR CC0-1.0)", "engines": { - "node": ">=16" + "node": ">=10" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -13663,6 +13292,7 @@ "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz", "integrity": "sha512-TkRKr9sUTxEH8MdfuCSP7VizJyzRNMjj2J2do2Jr3Kym598JVdEksuzPQCnlFPW4ky9Q+iA+ma9BGm06XQBy8g==", "dev": true, + "license": "MIT", "dependencies": { "media-typer": "0.3.0", "mime-types": "~2.1.24" @@ -13672,10 +13302,11 @@ } }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.6.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", + "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", "dev": true, + "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -13685,9 +13316,9 @@ } }, "node_modules/ua-parser-js": { - "version": "0.7.37", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.37.tgz", - "integrity": "sha512-xV8kqRKM+jhMvcHWUKthV9fNebIzrNy//2O9ZwWcfiBFR5f25XVZPLlEajk/sf3Ra15V92isyQqnIEXRDaZWEA==", + "version": "0.7.39", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.39.tgz", + "integrity": "sha512-IZ6acm6RhQHNibSt7+c09hhvsKy9WUr4DVbeq9U8o71qxyYtJpQeDxQnMrVqnIFMLcQjHO0I9wgfO2vIahht4w==", "dev": true, "funding": [ { @@ -13703,25 +13334,32 @@ "url": "https://github.com/sponsors/faisalman" } ], + "license": "MIT", + "bin": { + "ua-parser-js": "script/cli.js" + }, "engines": { "node": "*" } }, "node_modules/underscore": { - "version": "1.13.6", - "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.6.tgz", - "integrity": "sha512-+A5Sja4HP1M08MaXya7p5LvjuM7K6q/2EaC0+iovj/wOcMsTzMvDFbasi/oSapiwOlt252IqsKqPjCl7huKS0A==", - "dev": true + "version": "1.13.7", + "resolved": "https://registry.npmjs.org/underscore/-/underscore-1.13.7.tgz", + "integrity": "sha512-GMXzWtsc57XAtguZgaQViUOzs0KTkk8ojr3/xAxXLITqf/3EMwxC0inyETfDFjH/Krbhuep0HNbbjI9i/q3F3g==", + "dev": true, + "license": "MIT" }, "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==" + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "license": "MIT" }, "node_modules/unicode-canonical-property-names-ecmascript": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.0.tgz", - "integrity": "sha512-yY5PpDlfVIU5+y/BSCxAJRBIS1Zc2dDG3Ujq+sR0U+JjUevW2JhocOF+soROYDSaAezOzOKuyyixhD6mBknSmQ==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-2.0.1.tgz", + "integrity": "sha512-dA8WbNeb2a6oQzAQ55YlT5vQAWGV9WXOsi3SskE3bcCdM0P4SDd+24zS/OCacdRq5BkdsRj9q3Pg6YyQoxIGqg==", + "license": "MIT", "peer": true, "engines": { "node": ">=4" @@ -13731,6 +13369,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/unicode-match-property-ecmascript/-/unicode-match-property-ecmascript-2.0.0.tgz", "integrity": "sha512-5kaZCrbp5mmbz5ulBkDkbY0SsPOjKqVS35VpL9ulMPfSl0J0Xsm+9Evphv9CoIZFwre7aJoa94AY6seMKGVN5Q==", + "license": "MIT", "peer": true, "dependencies": { "unicode-canonical-property-names-ecmascript": "^2.0.0", @@ -13741,9 +13380,10 @@ } }, "node_modules/unicode-match-property-value-ecmascript": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-2.1.0.tgz", - "integrity": "sha512-qxkjQt6qjg/mYscYMC0XKRn3Rh0wFPlfxB0xkt9CfyTvpX1Ra0+rAmdX2QyAobptSEvuy4RtpPRui6XkV+8wjA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/unicode-match-property-value-ecmascript/-/unicode-match-property-value-ecmascript-2.2.0.tgz", + "integrity": "sha512-4IehN3V/+kkr5YeSSDDQG8QLqO26XpL2XP3GQtqwlT/QYSECAwFztxVHjlbh0+gjJ3XmNLS0zDsbgs9jWKExLg==", + "license": "MIT", "peer": true, "engines": { "node": ">=4" @@ -13753,6 +13393,7 @@ "version": "2.1.0", "resolved": "https://registry.npmjs.org/unicode-property-aliases-ecmascript/-/unicode-property-aliases-ecmascript-2.1.0.tgz", "integrity": "sha512-6t3foTQI9qne+OZoVQB/8x8rk2k1eVy1gRXhV3oFQ5T6R1dqQ1xtin3XqSlx3+ATBkliTaR/hHyJBm+LVPNM8w==", + "license": "MIT", "peer": true, "engines": { "node": ">=4" @@ -13762,6 +13403,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "license": "MIT", "engines": { "node": ">= 10.0.0" } @@ -13770,14 +13412,15 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", "engines": { "node": ">= 0.8" } }, "node_modules/update-browserslist-db": { - "version": "1.0.13", - "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz", - "integrity": "sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg==", + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz", + "integrity": "sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A==", "funding": [ { "type": "opencollective", @@ -13792,10 +13435,11 @@ "url": "https://github.com/sponsors/ai" } ], + "license": "MIT", "peer": true, "dependencies": { - "escalade": "^3.1.1", - "picocolors": "^1.0.0" + "escalade": "^3.2.0", + "picocolors": "^1.1.0" }, "bin": { "update-browserslist-db": "cli.js" @@ -13804,18 +13448,13 @@ "browserslist": ">= 4.21.0" } }, - "node_modules/upper-case": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/upper-case/-/upper-case-1.1.3.tgz", - "integrity": "sha512-WRbjgmYzgXkCV7zNVpy5YgrHgbBv126rMALQQMrmzOVC4GM2waQ9x7xtm8VU+1yF2kWyPzI9zbZ48n4vSxwfSA==", - "dev": true, - "peer": true - }, "node_modules/upper-case-first": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/upper-case-first/-/upper-case-first-2.0.2.tgz", "integrity": "sha512-514ppYHBaKwfJRK/pNC6c/OxfGa0obSnAl106u97Ed0I625Nin96KAjttZF6ZL3e1XLtphxnqrOi9iWgm+u+bg==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "tslib": "^2.0.3" } @@ -13825,26 +13464,41 @@ "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", "dev": true, + "license": "BSD-2-Clause", "dependencies": { "punycode": "^2.1.0" } }, + "node_modules/uri-js/node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/util-arity": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/util-arity/-/util-arity-1.1.0.tgz", "integrity": "sha512-kkyIsXKwemfSy8ZEoaIz06ApApnWsk5hQO0vLjZS6UkBiGiW++Jsyb8vSBoc0WKlffGoGs5yYy/j5pp8zckrFA==", - "dev": true + "dev": true, + "license": "MIT", + "peer": true }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", + "license": "MIT", "peer": true }, "node_modules/utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", "integrity": "sha512-pMZTvIkT1d+TFGvDOqodOclx0QWkkgi6Tdoa8gC8ffGAAqz9pzPTZWAybbsHHoED/ztMtkv/VoYTYyShUn81hA==", + "license": "MIT", "engines": { "node": ">= 0.4.0" } @@ -13858,6 +13512,8 @@ "https://github.com/sponsors/broofa", "https://github.com/sponsors/ctavan" ], + "license": "MIT", + "peer": true, "bin": { "uuid": "dist/bin/uuid" } @@ -13866,13 +13522,16 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", - "dev": true + "dev": true, + "license": "MIT" }, "node_modules/validate-npm-package-license": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/validate-npm-package-license/-/validate-npm-package-license-3.0.4.tgz", "integrity": "sha512-DpKm2Ui/xN7/HQKCtpZxoRWBhZ9Z0kqtygG8XCgNQ8ZlDnxuQmWhj566j8fN4Cu3/JmbhsDo7fcAJq4s9h27Ew==", "dev": true, + "license": "Apache-2.0", + "peer": true, "dependencies": { "spdx-correct": "^3.0.0", "spdx-expression-parse": "^3.0.0" @@ -13882,36 +13541,17 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", - "engines": { - "node": ">= 0.8" - } - }, - "node_modules/verror": { - "version": "1.10.1", - "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.1.tgz", - "integrity": "sha512-veufcmxri4e3XSrT0xwfUR7kguIkaxBeosDg00yDWhk49wdwkSUrvvsm7nc75e1PUyvIeZj6nS8VQRYz2/S4Xg==", "dev": true, - "peer": true, - "dependencies": { - "assert-plus": "^1.0.0", - "core-util-is": "1.0.2", - "extsprintf": "^1.2.0" - }, + "license": "MIT", "engines": { - "node": ">=0.6.0" + "node": ">= 0.8" } }, - "node_modules/verror/node_modules/core-util-is": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", - "dev": true, - "peer": true - }, "node_modules/vlq": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/vlq/-/vlq-1.0.1.tgz", "integrity": "sha512-gQpnTgkubC6hQgdIcRdYGDSDc+SaujOdyesZQMv6JlfQee/9Mp0Qhnys6WxDWvQnL5WZdT7o2Ul187aSt0Rq+w==", + "license": "MIT", "peer": true }, "node_modules/void-elements": { @@ -13919,6 +13559,7 @@ "resolved": "https://registry.npmjs.org/void-elements/-/void-elements-2.0.1.tgz", "integrity": "sha512-qZKX4RnBzH2ugr8Lxa7x+0V6XD9Sb/ouARtiasEQCHB1EVU4NXtmHsDDrx1dO4ne5fc3J6EW05BP1Dl0z0iung==", "dev": true, + "license": "MIT", "engines": { "node": ">=0.10.0" } @@ -13927,35 +13568,30 @@ "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", "integrity": "sha512-ts/8E8l5b7kY0vlWLewOkDXMmPdLcVV4GmOQLyxuSswIJsweeFZtAsMF7k1Nszz+TYBQrlYRmzOnr398y1JemQ==", + "license": "Apache-2.0", "peer": true, "dependencies": { "makeerror": "1.0.12" } }, - "node_modules/wcwidth": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/wcwidth/-/wcwidth-1.0.1.tgz", - "integrity": "sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==", - "peer": true, - "dependencies": { - "defaults": "^1.0.3" - } - }, "node_modules/webidl-conversions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" }, "node_modules/whatwg-fetch": { "version": "3.6.20", "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.6.20.tgz", "integrity": "sha512-EqhiFU6daOA8kpjOWTL0olhVOF3i7OrFzSYiGsEMB8GcXS+RrzauAERX65xMeNWVqxA6HXH2m69Z9LaKKdisfg==", + "license": "MIT", "peer": true }, "node_modules/whatwg-url": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", "dependencies": { "tr46": "~0.0.3", "webidl-conversions": "^3.0.0" @@ -13965,6 +13601,7 @@ "version": "8.0.0-3", "resolved": "https://registry.npmjs.org/whatwg-url-without-unicode/-/whatwg-url-without-unicode-8.0.0-3.tgz", "integrity": "sha512-HoKuzZrUlgpz35YO27XgD28uh/WJH4B0+3ttFqRo//lmq+9T/mIOJ6kqmINI9HpUpz1imRC/nR/lxKpJiv0uig==", + "license": "MIT", "dependencies": { "buffer": "^5.4.3", "punycode": "^2.1.1", @@ -13992,15 +13629,26 @@ "url": "https://feross.org/support" } ], + "license": "MIT", "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.1.13" } }, + "node_modules/whatwg-url-without-unicode/node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/whatwg-url-without-unicode/node_modules/webidl-conversions": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-5.0.0.tgz", "integrity": "sha512-VlZwKPCkYKxQgeSbH5EyngOmRp7Ww7I9rQLERETtf5ofd9pGeswWiOtogpEO850jziPRarreGxn5QIiTqpb2wA==", + "license": "BSD-2-Clause", "engines": { "node": ">=8" } @@ -14009,6 +13657,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "license": "ISC", "dependencies": { "isexe": "^2.0.0" }, @@ -14019,30 +13668,35 @@ "node": ">= 8" } }, - "node_modules/which-module": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.1.tgz", - "integrity": "sha512-iBdZ57RDvnOR9AGBhML2vFZf7h8vmBjhoaZqODJBFWHVtKkDmKuHai3cx5PgVMrX5YDNp27AofYbAwctSS+vhQ==", - "peer": true + "node_modules/word-wrap": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", + "integrity": "sha512-BN22B5eaMMI9UMtjrGd5g5eCYPpCPDUy0FJXbYsaT5zYxjFOckS53SQDE3pWkVoWpHXVb3BrYcEN4Twa55B5cA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } }, "node_modules/workerpool": { "version": "6.2.1", "resolved": "https://registry.npmjs.org/workerpool/-/workerpool-6.2.1.tgz", "integrity": "sha512-ILEIE97kDZvF9Wb9f6h5aXK4swSlKGUcOEGiIYb2OOu/IrDU9iwj0fD//SsA6E5ibwJxpEvhullJY4Sl4GcpAw==", - "dev": true + "dev": true, + "license": "Apache-2.0" }, "node_modules/wrap-ansi": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", - "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", - "dev": true, + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "license": "MIT", "dependencies": { - "ansi-styles": "^6.1.0", - "string-width": "^5.0.1", - "strip-ansi": "^7.0.1" + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" }, "engines": { - "node": ">=12" + "node": ">=10" }, "funding": { "url": "https://github.com/chalk/wrap-ansi?sponsor=1" @@ -14054,6 +13708,8 @@ "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "ansi-styles": "^4.0.0", "string-width": "^4.1.0", @@ -14066,142 +13722,34 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, - "node_modules/wrap-ansi-cjs/node_modules/ansi-styles": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", - "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", - "dev": true, - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/wrap-ansi-cjs/node_modules/color-convert": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", - "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", - "dev": true, - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/wrap-ansi-cjs/node_modules/color-name": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", - "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", - "dev": true - }, - "node_modules/wrap-ansi/node_modules/ansi-regex": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", - "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/chalk/ansi-regex?sponsor=1" - } - }, - "node_modules/wrap-ansi/node_modules/ansi-styles": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", - "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", - "dev": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, - "node_modules/wrap-ansi/node_modules/emoji-regex": { - "version": "9.2.2", - "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", - "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", - "dev": true - }, - "node_modules/wrap-ansi/node_modules/string-width": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", - "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", - "dev": true, - "dependencies": { - "eastasianwidth": "^0.2.0", - "emoji-regex": "^9.2.2", - "strip-ansi": "^7.0.1" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/wrap-ansi/node_modules/strip-ansi": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", - "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", - "dev": true, - "dependencies": { - "ansi-regex": "^6.0.1" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/chalk/strip-ansi?sponsor=1" - } - }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" }, "node_modules/write-file-atomic": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.3.tgz", - "integrity": "sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-4.0.2.tgz", + "integrity": "sha512-7KxauUdBmSdWnmpaGFg+ppNjKF8uNLry8LyzjauQDOVONfFLNKrKvQOxZ/VuTIcS/gge/YNahf5RIIQWTSarlg==", + "license": "ISC", "peer": true, "dependencies": { - "graceful-fs": "^4.1.11", "imurmurhash": "^0.1.4", - "signal-exit": "^3.0.2" + "signal-exit": "^3.0.7" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, - "node_modules/write-file-atomic/node_modules/signal-exit": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", - "peer": true - }, "node_modules/ws": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-8.11.0.tgz", - "integrity": "sha512-HPG3wQd9sNQoT9xHyNCXoDUa+Xw/VevmY9FoHyQ+g+rrMn4j6FB4np7Z0OhdTgjx6MgQLK7jwSy1YecU1+4Asg==", - "dev": true, - "engines": { - "node": ">=10.0.0" - }, - "peerDependencies": { - "bufferutil": "^4.0.1", - "utf-8-validate": "^5.0.2" - }, - "peerDependenciesMeta": { - "bufferutil": { - "optional": true - }, - "utf-8-validate": { - "optional": true - } + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.3.tgz", + "integrity": "sha512-jmTjYU0j60B+vHey6TfR3Z7RD61z/hmxBS3VMSGIrroOWXQEneK1zNuotOUrGyBHQj0yrpsLHPWtigEFd13ndA==", + "license": "MIT", + "peer": true, + "dependencies": { + "async-limiter": "~1.0.0" } }, "node_modules/xmlbuilder": { @@ -14209,24 +13757,17 @@ "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-15.1.1.tgz", "integrity": "sha512-yMqGBqtXyeN1e3TGYvgNgDVZ3j84W4cwkOXQswghol6APgZWaff9lnbvN7MHYJOiXsvGPXtjTYJEiC9J2wv9Eg==", "dev": true, + "license": "MIT", + "peer": true, "engines": { "node": ">=8.0" } }, - "node_modules/xregexp": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/xregexp/-/xregexp-4.4.1.tgz", - "integrity": "sha512-2u9HwfadaJaY9zHtRRnH6BY6CQVNQKkYm3oLtC9gJXXzfsbACg5X5e4EZZGVAH+YIfa+QA9lsFQTTe3HURF3ag==", - "dev": true, - "peer": true, - "dependencies": { - "@babel/runtime-corejs3": "^7.12.1" - } - }, "node_modules/xtend": { "version": "4.0.2", "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", + "license": "MIT", "peer": true, "engines": { "node": ">=0.4" @@ -14236,19 +13777,25 @@ "version": "5.0.8", "resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz", "integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==", + "license": "ISC", "engines": { "node": ">=10" } }, "node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz", + "integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==", + "license": "ISC", + "peer": true }, "node_modules/yaml": { - "version": "2.4.1", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.4.1.tgz", - "integrity": "sha512-pIXzoImaqmfOrL7teGUBt/T7ZDnyeGBWyXQBvOVhLkWLN37GXv8NMLK406UY6dS51JfcQHsmcW5cJ441bHg6Lg==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.6.0.tgz", + "integrity": "sha512-a6ae//JvKDEra2kdi1qzCyrJW/WZCgFi8ydDV+eXExl95t+5R+ijnqHJbz9tmMh8FUjx3iv2fCQ4dclAQlO2UQ==", + "dev": true, + "license": "ISC", + "peer": true, "bin": { "yaml": "bin.mjs" }, @@ -14261,6 +13808,7 @@ "resolved": "https://registry.npmjs.org/yargs/-/yargs-16.2.0.tgz", "integrity": "sha512-D1mvvtDG0L5ft/jGWkLpG1+m0eQxOfaBvTNELraWj22wSVUMWxZUvYgJYcKh6jGGIkJFhH4IZPQhR4TKpc8mBw==", "dev": true, + "license": "MIT", "dependencies": { "cliui": "^7.0.2", "escalade": "^3.1.1", @@ -14279,6 +13827,7 @@ "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-20.2.4.tgz", "integrity": "sha512-WOkpgNhPTlE73h4VFAFsOnomJVaovO8VqLDzy5saChRBFQFBoMYirowyW+Q9HB4HFF4Z7VZTiG3iSzJJA29yRA==", "dev": true, + "license": "ISC", "engines": { "node": ">=10" } @@ -14288,6 +13837,7 @@ "resolved": "https://registry.npmjs.org/yargs-unparser/-/yargs-unparser-2.0.0.tgz", "integrity": "sha512-7pRTIA9Qc1caZ0bZ6RYRGbHJthJWuakf+WmHK0rVeLkNrrGhfoabBNdue6kdINI6r4if7ocq9aD/n7xwKOdzOA==", "dev": true, + "license": "MIT", "dependencies": { "camelcase": "^6.0.0", "decamelize": "^4.0.0", @@ -14298,11 +13848,25 @@ "node": ">=10" } }, + "node_modules/yargs-unparser/node_modules/camelcase": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz", + "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/yn": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", "dev": true, + "license": "MIT", "engines": { "node": ">=6" } @@ -14311,6 +13875,8 @@ "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", + "dev": true, + "license": "MIT", "engines": { "node": ">=10" }, @@ -14323,6 +13889,8 @@ "resolved": "https://registry.npmjs.org/yup/-/yup-1.2.0.tgz", "integrity": "sha512-PPqYKSAXjpRCgLgLKVGPA33v5c/WgEx3wi6NFjIiegz90zSwyMpvTFp/uGcVnnbx6to28pgnzp/q8ih3QRjLMQ==", "dev": true, + "license": "MIT", + "peer": true, "dependencies": { "property-expr": "^2.0.5", "tiny-case": "^1.0.3", @@ -14335,6 +13903,8 @@ "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", "dev": true, + "license": "(MIT OR CC0-1.0)", + "peer": true, "engines": { "node": ">=12.20" }, diff --git a/package.json b/package.json index c3552a836..fa8f4ecaf 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "name": "pubnub", - "version": "8.2.9", + "version": "8.2.10", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { "build": "npm run build:node && npm run build:web", "build:web": "rollup -c ./rollup.config.js --bundleConfigAsCjs", - "build:node": "tsc -p tsconfig.json", + "build:node": "tsc -p tsconfig.json && npm run build:node-types", + "build:node-types": "ts-node ./.scripts/types-aggregate.ts --ts-config=./tsconfig.json --package=PubNub --working-dir=./lib/types --input=./lib/types/node/index.d.ts --output=./lib/types", "test": "npm run test:web && npm run test:node", "test:web": "karma start karma/web.config.cjs", "test:node": "TS_NODE_PROJECT='./tsconfig.json' mocha --project tsconfig.mocha.json", @@ -32,7 +33,7 @@ "contract:test-access-beta": "cucumber-js --require dist/cucumber dist/contract/contract/features --tags '@featureSet=access and not @na=js and @beta'" }, "main": "./lib/node/index.js", - "types": "./lib/types/node/index.d.ts", + "types": "./lib/types/index.d.ts", "react-native": "./lib/react_native/index.js", "metro": "./lib/react_native/index.js", "nativescript": "./lib/nativescript/index.js", @@ -65,8 +66,6 @@ "text-encoding": "^0.7.0" }, "devDependencies": { - "@cucumber/cucumber": "^10.4.0", - "@cucumber/pretty-formatter": "^1.0.0", "@rollup/plugin-commonjs": "^25.0.7", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.2.3", @@ -76,7 +75,6 @@ "@types/cbor-js": "^0.1.1", "@types/chai": "^4.3.14", "@types/chai-as-promised": "^7.1.8", - "@types/cucumber": "^7.0.0", "@types/expect": "^24.3.0", "@types/lil-uuid": "^0.1.3", "@types/mocha": "^9.1.0", @@ -85,12 +83,12 @@ "@types/sinon": "^17.0.3", "@types/text-encoding": "^0.0.39", "@types/underscore": "^1.11.15", - "@typescript-eslint/eslint-plugin": "^7.4.0", - "@typescript-eslint/parser": "^7.4.0", + "@typescript-eslint/eslint-plugin": "^8.12.2", + "@typescript-eslint/parser": "^8.12.2", "chai": "^4.4.1", "chai-as-promised": "^7.1.1", "chai-nock": "^1.2.0", - "cucumber-pretty": "^6.0.1", + "commander": "^12.1.0", "cucumber-tsflow": "^4.4.4", "es6-shim": "^0.35.8", "eslint": "^8.57.0", @@ -105,10 +103,10 @@ "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.32", "mocha": "10.4.0", - "nock": "^14.0.0-beta.5", + "nock": "^14.0.0-beta.15", "prettier": "^3.2.5", "rimraf": "^3.0.2", - "rollup": "^4.13.2", + "rollup": "4.22.4", "rollup-plugin-gzip": "^3.1.2", "rollup-plugin-string": "^3.0.0", "sinon": "^7.5.0", diff --git a/src/cbor/common.ts b/src/cbor/common.ts index 26c0ba1dd..2dea3a529 100644 --- a/src/cbor/common.ts +++ b/src/cbor/common.ts @@ -1,5 +1,7 @@ /** * Cbor decoder module. + * + * @internal */ /** diff --git a/src/core/components/abort_signal.ts b/src/core/components/abort_signal.ts index caffb93c3..883ac86f7 100644 --- a/src/core/components/abort_signal.ts +++ b/src/core/components/abort_signal.ts @@ -1,3 +1,9 @@ +/** + * Event Engine managed effects terminate signal module. + * + * @internal + */ + import { Subject } from './subject'; export class AbortError extends Error { diff --git a/src/core/components/base64_codec.ts b/src/core/components/base64_codec.ts index c447673b7..d52871bf3 100644 --- a/src/core/components/base64_codec.ts +++ b/src/core/components/base64_codec.ts @@ -1,3 +1,9 @@ +/** + * Base64 support module. + * + * @internal + */ + const BASE64_CHARMAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; /** diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 2feb65c1e..7e70f92ae 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -1,9 +1,11 @@ /** * {@link PubNub} client configuration module. + * + * @internal */ import { ExtendedConfiguration, PlatformConfiguration, PrivateClientConfiguration } from '../interfaces/configuration'; -import { CryptoModule, CryptorConfiguration } from '../interfaces/crypto-module'; +import { ICryptoModule, CryptorConfiguration } from '../interfaces/crypto-module'; import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; import uuidGenerator from './uuid'; import { Payload } from '../types/api'; @@ -28,7 +30,7 @@ const USE_RANDOM_INITIALIZATION_VECTOR = true; * * @internal */ -type SetupCryptoModule = (configuration: CryptorConfiguration) => CryptoModule | undefined; +type SetupCryptoModule = (configuration: CryptorConfiguration) => ICryptoModule | undefined; /** * Internal state of the {@link PrivateClientConfiguration} to store temporarily information. @@ -58,7 +60,7 @@ type PrivateConfigurationFields = { /** * Configured crypto module. */ - _cryptoModule?: CryptoModule; + _cryptoModule?: ICryptoModule; /** * Currently used data encryption / decryption key. @@ -70,7 +72,7 @@ type PrivateConfigurationFields = { * Create {@link PubNub} client private configuration object. * * @param base - User- and platform-provided configuration. - * @param setupCryptoModule - Platform-provided {@link CryptoModule} configuration block. + * @param setupCryptoModule - Platform-provided {@link ICryptoModule} configuration block. * * @returns `PubNub` client private configuration. * @@ -140,7 +142,7 @@ export const makeConfiguration = ( customDecrypt: this.getCustomDecrypt(), }); }, - getCryptoModule(): CryptoModule | undefined { + getCryptoModule(): ICryptoModule | undefined { return this._cryptoModule; }, getUseRandomIVs(): boolean | undefined { @@ -169,7 +171,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.9'; + return '8.2.10'; }, getVersion(): string { return this.version; diff --git a/src/core/components/cryptography/hmac-sha256.js b/src/core/components/cryptography/hmac-sha256.js index 2068b77cc..b0e785b15 100755 --- a/src/core/components/cryptography/hmac-sha256.js +++ b/src/core/components/cryptography/hmac-sha256.js @@ -1,3 +1,9 @@ +/** + * CryptoJS implementation. + * + * @internal + */ + /*eslint-disable */ /* diff --git a/src/core/components/cryptography/index.ts b/src/core/components/cryptography/index.ts index 98215f205..e73f95b59 100644 --- a/src/core/components/cryptography/index.ts +++ b/src/core/components/cryptography/index.ts @@ -1,5 +1,7 @@ /** * Legacy cryptography module. + * + * @internal */ import { CryptorConfiguration } from '../../interfaces/crypto-module'; @@ -13,6 +15,8 @@ import CryptoJS from './hmac-sha256'; * @param b - Bytes array (buffer) which should be converted. * * @returns Word sized array. + * + * @internal */ /* eslint-disable @typescript-eslint/no-explicit-any */ function bufferToWordArray(b: string | any[] | Uint8ClampedArray) { @@ -28,6 +32,8 @@ function bufferToWordArray(b: string | any[] | Uint8ClampedArray) { /** * Legacy cryptor configuration options. + * + * @internal */ type CryptoConfiguration = { encryptKey?: boolean; @@ -36,6 +42,11 @@ type CryptoConfiguration = { mode?: 'ecb' | 'cbc'; }; +/** + * Legacy cryptography module for files and signature. + * + * @internal + */ export default class { /** * Crypto initialization vector. diff --git a/src/core/components/deduping_manager.js b/src/core/components/deduping_manager.js deleted file mode 100644 index 7d1503ce8..000000000 --- a/src/core/components/deduping_manager.js +++ /dev/null @@ -1,50 +0,0 @@ -/* */ - -const hashCode = (payload) => { - let hash = 0; - if (payload.length === 0) return hash; - for (let i = 0; i < payload.length; i += 1) { - const character = payload.charCodeAt(i); - hash = (hash << 5) - hash + character; // eslint-disable-line - hash = hash & hash; // eslint-disable-line - } - return hash; -}; - -/** - * Real-time events deduplication manager. - * - * @internal - */ -export default class { - _config; - - hashHistory; - - constructor({ config }) { - this.hashHistory = []; - this._config = config; - } - - getKey(message) { - const hashedPayload = hashCode(JSON.stringify(message.message)).toString(); - const timetoken = message.timetoken; - return `${timetoken}-${hashedPayload}`; - } - - isDuplicate(message) { - return this.hashHistory.includes(this.getKey(message)); - } - - addEntry(message) { - if (this.hashHistory.length >= this._config.maximumCacheSize) { - this.hashHistory.shift(); - } - - this.hashHistory.push(this.getKey(message)); - } - - clearHistory() { - this.hashHistory = []; - } -} diff --git a/src/core/components/deduping_manager.ts b/src/core/components/deduping_manager.ts new file mode 100644 index 000000000..7fafb97a3 --- /dev/null +++ b/src/core/components/deduping_manager.ts @@ -0,0 +1,96 @@ +/** + * Messages de-duplication manager module. + * + * @internal + */ + +import { Payload } from '../types/api'; + +/** + * Base real-time event payload type required by the manager. + */ +type CachedMessagePayload = { message?: Payload | undefined; timetoken: string }; + +/** + * Real-time events deduplication manager. + * + * @internal + */ +export class DedupingManager { + /** + * Maximum number of caches generated for previously received real-time events. + */ + private readonly maximumCacheSize: number; + + /** + * Processed and cached real-time events' hashes. + */ + private hashHistory: string[]; + + /** + * Create and configure real-time events de-duplication manager. + * + * @param config - PubNub client configuration object. + */ + constructor({ maximumCacheSize }: { maximumCacheSize: number }) { + this.maximumCacheSize = maximumCacheSize; + this.hashHistory = []; + } + + /** + * Compute unique real-time event payload key. + * + * @param message - Received real-time event payload for which unique key should be computed. + * @returns Unique real-time event payload key in messages cache. + */ + getKey(message: CachedMessagePayload): string { + return `${message.timetoken}-${this.hashCode(JSON.stringify(message.message ?? '')).toString()}`; + } + + /** + * Check whether there is similar message already received or not. + * + * @param message - Received real-time event payload which should be checked for duplicates. + * @returns `true` in case if similar payload already has been received before. + */ + isDuplicate(message: CachedMessagePayload): boolean { + return this.hashHistory.includes(this.getKey(message)); + } + + /** + * Store received message to be used later for duplicate detection. + * + * @param message - Received real-time event payload. + */ + addEntry(message: CachedMessagePayload) { + if (this.hashHistory.length >= this.maximumCacheSize) { + this.hashHistory.shift(); + } + + this.hashHistory.push(this.getKey(message)); + } + + /** + * Clean up cached messages. + */ + clearHistory() { + this.hashHistory = []; + } + + /** + * Compute message hash sum. + * + * @param payload - Received payload for which hash sum should be computed. + * @returns {number} - Resulting hash sum. + */ + hashCode(payload: string): number { + let hash = 0; + if (payload.length === 0) return hash; + for (let i = 0; i < payload.length; i += 1) { + const character = payload.charCodeAt(i); + hash = (hash << 5) - hash + character; // eslint-disable-line + hash = hash & hash; // eslint-disable-line + } + return hash; + } +} diff --git a/src/core/components/eventEmitter.ts b/src/core/components/eventEmitter.ts index bedc98ac8..3cfee2220 100644 --- a/src/core/components/eventEmitter.ts +++ b/src/core/components/eventEmitter.ts @@ -1,3 +1,9 @@ +/** + * Real-time events emitter module. + * + * @internal + */ + import { Listener, ListenerManager } from './listener_manager'; import * as Subscription from '../types/api/subscription'; import { PubNubEventType } from '../endpoints/subscribe'; diff --git a/src/core/components/push_payload.ts b/src/core/components/push_payload.ts index 4f0cee394..e74f2ba23 100644 --- a/src/core/components/push_payload.ts +++ b/src/core/components/push_payload.ts @@ -205,34 +205,55 @@ type FCMPayload = { class BaseNotificationPayload { /** * Notification main title. + * + * @internal */ protected _title?: string; /** * Notification second-line title. + * + * @internal */ protected _subtitle?: string; /** * Name of the sound which should be played for received notification. + * + * @internal */ protected _sound?: string; /** * Value which should be placed on application badge (if required). + * + * @internal */ protected _badge?: number | null; /** * Notification main body message. + * + * @internal */ protected _body?: string; /** * Object in resulting message where notification payload should be added. + * + * @internal */ protected _payload: unknown; + /** + * Base notification provider payload object. + * + * @internal + * + * @param payload - Object which contains vendor-specific preformatted push notification payload. + * @param title - Notification main title. + * @param body - Notification body (main messages). + */ constructor(payload: unknown, title?: string, body?: string) { this._payload = payload; @@ -297,12 +318,16 @@ class BaseNotificationPayload { /** * Platform-specific structure initialization. + * + * @internal */ protected setDefaultPayloadStructure() {} /** * Translate data object into PubNub push notification payload object. * + * @internal + * * @returns Preformatted push notification payload. */ public toObject(): unknown { @@ -316,16 +341,22 @@ class BaseNotificationPayload { export class APNSNotificationPayload extends BaseNotificationPayload { /** * List with notification receivers information. + * + * @internal */ private _configurations?: APNS2Configuration[]; /** * Type of push notification service for which payload will be created. + * + * @internal */ private _apnsPushType: 'apns' | 'apns2' = 'apns'; /** * Whether resulting payload should trigger silent notification or not. + * + * @internal */ private _isSilent: boolean = false; @@ -469,10 +500,22 @@ export class APNSNotificationPayload extends BaseNotificationPayload { this._isSilent = value; } + /** + * Setup push notification payload default content. + * + * @internal + */ protected setDefaultPayloadStructure() { this.payload.aps = { alert: {} }; } + /** + * Translate data object into PubNub push notification payload object. + * + * @internal + * + * @returns Preformatted push notification payload. + */ public toObject(): APNSPayload | null { const payload = { ...this.payload }; const { aps } = payload; @@ -507,6 +550,8 @@ export class APNSNotificationPayload extends BaseNotificationPayload { /** * Create PubNub push notification service APNS2 configuration information object. * + * @internal + * * @param configuration - Source user-provided APNS2 configuration. * * @returns Preformatted for PubNub service APNS2 configuration information. @@ -531,6 +576,8 @@ export class APNSNotificationPayload extends BaseNotificationPayload { /** * Create PubNub push notification service APNS2 target information object. * + * @internal + * * @param target - Source user-provided data. * * @returns Preformatted for PubNub service APNS2 target information. @@ -548,19 +595,28 @@ export class APNSNotificationPayload extends BaseNotificationPayload { } /** - * Message payload for Firebase Clouse Messaging service. + * Message payload for Firebase Cloud Messaging service. */ export class FCMNotificationPayload extends BaseNotificationPayload { /** * Whether resulting payload should trigger silent notification or not. + * + * @internal */ private _isSilent?: boolean; /** * Name of the icon file from resource bundle which should be shown on notification. + * + * @internal */ private _icon?: string; + /** + * Notifications grouping tag. + * + * @internal + */ private _tag?: string; get payload(): FCMPayload { @@ -669,10 +725,20 @@ export class FCMNotificationPayload extends BaseNotificationPayload { this._icon = value; } + /** + * Retrieve notifications grouping tag. + * + * @returns Notifications grouping tag. + */ get tag() { return this._tag; } + /** + * Update notifications grouping tag. + * + * @param value - String which will be used to group similar notifications in notification center. + */ set tag(value) { if (!value || !value.length) return; @@ -691,11 +757,23 @@ export class FCMNotificationPayload extends BaseNotificationPayload { this._isSilent = value; } + /** + * Setup push notification payload default content. + * + * @internal + */ protected setDefaultPayloadStructure() { this.payload.notification = {}; this.payload.data = {}; } + /** + * Translate data object into PubNub push notification payload object. + * + * @internal + * + * @returns Preformatted push notification payload. + */ public toObject(): FCMPayload | null { let data = { ...this.payload.data }; let notification = null; @@ -721,17 +799,24 @@ export class FCMNotificationPayload extends BaseNotificationPayload { class NotificationsPayload { /** * Resulting message payload for notification services. + * + * @internal */ private readonly _payload; /** * Whether notifications debugging session should be used or not. + * + * @internal */ private _debugging?: boolean; + /** * First line title. * * Title which is shown in bold on the first line of notification bubble. + * + * @internal */ private readonly _title: string; @@ -739,21 +824,29 @@ class NotificationsPayload { * Second line title. * * Subtitle which is shown under main title with smaller font. + * + * @internal */ private _subtitle?: string; /** * Notification main body message. + * + * @internal */ private readonly _body: string; /** * Value which should be placed on application badge (if required). + * + * @internal */ private _badge?: number; /** * Name of the file from resource bundle which should be played when notification received. + * + * @internal */ private _sound?: string; @@ -767,6 +860,14 @@ class NotificationsPayload { */ public fcm; + /** + * Create push notification payload holder. + * + * @internal + * + * @param title - String which will be shown at the top of the notification (below app name). + * @param body - String with message which should be shown when user will check notification. + */ constructor(title: string, body: string) { this._payload = { apns: {}, fcm: {} }; this._title = title; @@ -776,6 +877,12 @@ class NotificationsPayload { this.fcm = new FCMNotificationPayload(this._payload.fcm, title, body); } + /** + * Enable or disable push notification debugging message. + * + * @param value - Whether debug message from push notification scheduler should be published to the specific + * channel or not. + */ set debugging(value: boolean) { this._debugging = value; } @@ -862,12 +969,12 @@ class NotificationsPayload { * Build notifications platform for requested platforms. * * @param platforms - List of platforms for which payload should be added to final dictionary. Supported values: - * gcm, apns, and apns2. + * fcm, apns, and apns2. * * @returns Object with data, which can be sent with publish method call and trigger remote notifications for * specified platforms. */ - buildPayload(platforms: string[]) { + buildPayload(platforms: ('apns' | 'apns2' | 'fcm')[]) { const payload: { pn_apns?: APNSPayload; pn_gcm?: FCMPayload; pn_debug?: boolean } = {}; if (platforms.includes('apns') || platforms.includes('apns2')) { diff --git a/src/core/components/reconnection_manager.ts b/src/core/components/reconnection_manager.ts index 2b3c18ba3..dbc055ada 100644 --- a/src/core/components/reconnection_manager.ts +++ b/src/core/components/reconnection_manager.ts @@ -2,6 +2,8 @@ * Subscription reconnection-manager. * * **Note:** Reconnection manger rely on legacy time-based availability check. + * + * @internal */ import { PubNubCore } from '../pubnub-common'; diff --git a/src/core/components/request.ts b/src/core/components/request.ts index f39499610..9600663dd 100644 --- a/src/core/components/request.ts +++ b/src/core/components/request.ts @@ -1,3 +1,9 @@ +/** + * Network request module. + * + * @internal + */ + import { CancellationController, TransportMethod, TransportRequest } from '../types/transport-request'; import { TransportResponse } from '../types/transport-response'; import RequestOperation from '../constants/operations'; diff --git a/src/core/components/stringify_buffer_keys.ts b/src/core/components/stringify_buffer_keys.ts index eff039140..32f49216e 100644 --- a/src/core/components/stringify_buffer_keys.ts +++ b/src/core/components/stringify_buffer_keys.ts @@ -1,3 +1,9 @@ +/** + * CBOR support module. + * + * @internal + */ + /** * Re-map CBOR object keys from potentially C buffer strings to actual strings. * diff --git a/src/core/components/subject.ts b/src/core/components/subject.ts index 67d53a77a..9585ef111 100644 --- a/src/core/components/subject.ts +++ b/src/core/components/subject.ts @@ -1,3 +1,9 @@ +/** + * Event Engine terminate signal listener module. + * + * @internal + */ + type Listener = (event: T) => void; /** diff --git a/src/core/components/subscription-manager.ts b/src/core/components/subscription-manager.ts index 19b74ffdc..dc9ee44bf 100644 --- a/src/core/components/subscription-manager.ts +++ b/src/core/components/subscription-manager.ts @@ -1,18 +1,20 @@ /** * Subscription manager module. + * + * @internal */ import { Payload, ResultCallback, Status, StatusCallback, StatusEvent } from '../types/api'; -import { RequestParameters as SubscribeRequestParameters } from '../endpoints/subscribe'; +import { SubscribeRequestParameters as SubscribeRequestParameters } from '../endpoints/subscribe'; import { PrivateClientConfiguration } from '../interfaces/configuration'; import { HeartbeatRequest } from '../endpoints/presence/heartbeat'; import { ReconnectionManager } from './reconnection_manager'; import * as Subscription from '../types/api/subscription'; import { ListenerManager } from './listener_manager'; import StatusCategory from '../constants/categories'; +import { DedupingManager } from './deduping_manager'; import Categories from '../constants/categories'; import * as Presence from '../types/api/presence'; -import DedupingManager from './deduping_manager'; import { PubNubCore } from '../pubnub-common'; import EventEmitter from './eventEmitter'; @@ -142,7 +144,7 @@ export class SubscriptionManager { time: typeof PubNubCore.prototype.time, ) { this.reconnectionManager = new ReconnectionManager(time); - this.dedupingManager = new DedupingManager({ config: this.configuration }); + this.dedupingManager = new DedupingManager(this.configuration); this.heartbeatChannelGroups = {}; this.heartbeatChannels = {}; this.presenceChannelGroups = {}; @@ -453,7 +455,7 @@ export class SubscriptionManager { try { messages.forEach((message) => { - if (dedupeOnSubscribe) { + if (dedupeOnSubscribe && 'message' in message.data && 'timetoken' in message.data) { if (this.dedupingManager.isDuplicate(message.data)) return; this.dedupingManager.addEntry(message.data); } diff --git a/src/core/components/token_manager.ts b/src/core/components/token_manager.ts index e60cf2a3f..d2a734c5f 100644 --- a/src/core/components/token_manager.ts +++ b/src/core/components/token_manager.ts @@ -1,8 +1,11 @@ /** * PubNub Access Token Manager module. + * + * @internal */ import Cbor from '../../cbor/common'; +import * as PAM from '../types/api/access-manager'; import { Payload } from '../types/api'; // -------------------------------------------------------- @@ -10,136 +13,6 @@ import { Payload } from '../types/api'; // -------------------------------------------------------- // region Types -type Token = { - /** - * Token version. - */ - version: number; - - /** - * Token generation date time. - */ - timestamp: number; - - /** - * Maximum duration (in minutes) during which token will be valid. - */ - ttl: number; - - /** - * Permissions granted to specific resources. - */ - resources?: Partial>>; - - /** - * Permissions granted to resources which match specified regular expression. - */ - patterns?: Partial>>; - - /** - * The uuid that is exclusively authorized to use this token to make API requests. - */ - authorized_uuid?: string; - - /** - * PAM token content signature. - */ - signature: ArrayBuffer; - - /** - * Additional information which has been added to the token. - */ - meta?: Payload; -}; - -/** - * Granted resource permissions. - * - * **Note:** Following operations doesn't require any permissions: - * - unsubscribe from channel / channel group - * - where now - */ -type Permissions = { - /** - * Resource read permission. - * - * Read permission required for: - * - subscribe to channel / channel group (including presence versions `-pnpres`) - * - here now - * - get presence state - * - set presence state - * - fetch history - * - fetch messages count - * - list shared files - * - download shared file - * - enable / disable push notifications - * - get message actions - * - get history with message actions - */ - read: boolean; - - /** - * Resource write permission. - * - * Write permission required for: - * - publish message / signal - * - share file - * - add message actions - */ - write: boolean; - - /** - * Resource manage permission. - * - * Manage permission required for: - * - add / remove channels to / from the channel group - * - list channels in group - * - remove channel group - * - set / remove channel members - */ - manage: boolean; - - /** - * Resource delete permission. - * - * Delete permission required for: - * - delete messages from history - * - delete shared file - * - delete user metadata - * - delete channel metadata - * - remove message action - */ - delete: boolean; - - /** - * Resource get permission. - * - * Get permission required for: - * - get user metadata - * - get channel metadata - * - get channel members - */ - get: boolean; - - /** - * Resource update permission. - * - * Update permissions required for: - * - set user metadata - * - set channel metadata - * - set / remove user membership - */ - update: boolean; - - /** - * Resource `join` permission. - * - * `Join` permission required for: - * - set / remove channel members - */ - join: boolean; -}; - /** * Raw parsed token. * @@ -242,7 +115,7 @@ export class TokenManager { const channelPatternPermissions = Object.keys(parsed.pat.chan); const groupPatternPermissions = Object.keys(parsed.pat.grp); - const result: Token = { + const result: PAM.Token = { version: parsed.v, timestamp: parsed.t, ttl: parsed.ttl, @@ -312,7 +185,7 @@ export class TokenManager { * @returns Human-readable resource permissions. */ private extractPermissions(permissions: number) { - const permissionsResult: Permissions = { + const permissionsResult: PAM.Permissions = { read: false, write: false, manage: false, diff --git a/src/core/components/uuid.ts b/src/core/components/uuid.ts index 023de232a..930a0f208 100644 --- a/src/core/components/uuid.ts +++ b/src/core/components/uuid.ts @@ -1,5 +1,12 @@ +/** + * Random identifier generator helper module. + * + * @internal + */ + import uuidGenerator from 'lil-uuid'; +/** @internal */ export default { createUUID() { if (uuidGenerator.uuid) { diff --git a/src/core/constants/operations.ts b/src/core/constants/operations.ts index 196dc98cd..b2167587e 100644 --- a/src/core/constants/operations.ts +++ b/src/core/constants/operations.ts @@ -1,4 +1,6 @@ -/* */ +/** + * Endpoint API operation types. + */ enum RequestOperation { // -------------------------------------------------------- // ---------------------- Publish API --------------------- @@ -291,7 +293,18 @@ enum RequestOperation { // ---------------- Subscription Utility ------------------ // -------------------------------------------------------- + /** + * Initial event engine subscription handshake operation. + * + * @internal + */ PNHandshakeOperation = 'PNHandshakeOperation', + + /** + * Event engine subscription loop operation. + * + * @internal + */ PNReceiveMessagesOperation = 'PNReceiveMessagesOperation', } diff --git a/src/core/endpoints/access_manager/audit.ts b/src/core/endpoints/access_manager/audit.ts index 7229a0e6f..30aef5bfc 100644 --- a/src/core/endpoints/access_manager/audit.ts +++ b/src/core/endpoints/access_manager/audit.ts @@ -1,5 +1,7 @@ /** * PAM Audit REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/access_manager/grant.ts b/src/core/endpoints/access_manager/grant.ts index 687ca08ce..a6eff8629 100644 --- a/src/core/endpoints/access_manager/grant.ts +++ b/src/core/endpoints/access_manager/grant.ts @@ -1,5 +1,7 @@ /** * PAM Grant REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/access_manager/grant_token.ts b/src/core/endpoints/access_manager/grant_token.ts index 44c9f0089..0a6fd0df9 100644 --- a/src/core/endpoints/access_manager/grant_token.ts +++ b/src/core/endpoints/access_manager/grant_token.ts @@ -1,5 +1,7 @@ /** * PAM Grant Token REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/access_manager/revoke_token.ts b/src/core/endpoints/access_manager/revoke_token.ts index 74b1d0f2d..600e350e8 100644 --- a/src/core/endpoints/access_manager/revoke_token.ts +++ b/src/core/endpoints/access_manager/revoke_token.ts @@ -1,5 +1,7 @@ /** * PAM Revoke Token REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/actions/add_message_action.ts b/src/core/endpoints/actions/add_message_action.ts index 355180abd..75d3488e2 100644 --- a/src/core/endpoints/actions/add_message_action.ts +++ b/src/core/endpoints/actions/add_message_action.ts @@ -1,5 +1,7 @@ /** * Add Message Action REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/actions/get_message_actions.ts b/src/core/endpoints/actions/get_message_actions.ts index 1bd8bb02b..5c72a63fc 100644 --- a/src/core/endpoints/actions/get_message_actions.ts +++ b/src/core/endpoints/actions/get_message_actions.ts @@ -1,5 +1,7 @@ /** * Get Message Actions REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/actions/remove_message_action.ts b/src/core/endpoints/actions/remove_message_action.ts index 8c2eed84e..f6d6ee8ca 100644 --- a/src/core/endpoints/actions/remove_message_action.ts +++ b/src/core/endpoints/actions/remove_message_action.ts @@ -1,5 +1,7 @@ /** * Remove Message Action REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/channel_groups/add_channels.ts b/src/core/endpoints/channel_groups/add_channels.ts index ad5e5473d..49be453f2 100644 --- a/src/core/endpoints/channel_groups/add_channels.ts +++ b/src/core/endpoints/channel_groups/add_channels.ts @@ -1,5 +1,7 @@ /** * Add channel group channels REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/channel_groups/delete_group.ts b/src/core/endpoints/channel_groups/delete_group.ts index 526e91098..6426177c9 100644 --- a/src/core/endpoints/channel_groups/delete_group.ts +++ b/src/core/endpoints/channel_groups/delete_group.ts @@ -1,5 +1,7 @@ /** * Delete channel group REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/channel_groups/list_channels.ts b/src/core/endpoints/channel_groups/list_channels.ts index a7d66308e..470594660 100644 --- a/src/core/endpoints/channel_groups/list_channels.ts +++ b/src/core/endpoints/channel_groups/list_channels.ts @@ -1,5 +1,7 @@ /** * List channel group channels REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/channel_groups/list_groups.ts b/src/core/endpoints/channel_groups/list_groups.ts index 531da6f4f..1b3659e23 100644 --- a/src/core/endpoints/channel_groups/list_groups.ts +++ b/src/core/endpoints/channel_groups/list_groups.ts @@ -1,5 +1,7 @@ /** * List All Channel Groups REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/channel_groups/remove_channels.ts b/src/core/endpoints/channel_groups/remove_channels.ts index d8f78d1c9..d960f9275 100644 --- a/src/core/endpoints/channel_groups/remove_channels.ts +++ b/src/core/endpoints/channel_groups/remove_channels.ts @@ -1,5 +1,7 @@ /** * Remove channel group channels REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/fetch_messages.ts b/src/core/endpoints/fetch_messages.ts index a8b0298b0..0b42fd62c 100644 --- a/src/core/endpoints/fetch_messages.ts +++ b/src/core/endpoints/fetch_messages.ts @@ -1,11 +1,13 @@ /** * Fetch messages REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../errors/pubnub-error'; import { TransportResponse } from '../types/transport-response'; import { PubNubAPIError } from '../../errors/pubnub-api-error'; -import { CryptoModule } from '../interfaces/crypto-module'; +import { ICryptoModule } from '../interfaces/crypto-module'; import { AbstractRequest } from '../components/request'; import * as FileSharing from '../types/api/file-sharing'; import RequestOperation from '../constants/operations'; @@ -67,7 +69,7 @@ type RequestParameters = History.FetchMessagesParameters & { /** * Published data encryption module. */ - crypto?: CryptoModule; + crypto?: ICryptoModule; /** * File download Url generation function. diff --git a/src/core/endpoints/file_upload/delete_file.ts b/src/core/endpoints/file_upload/delete_file.ts index fc5dcc976..71617b36a 100644 --- a/src/core/endpoints/file_upload/delete_file.ts +++ b/src/core/endpoints/file_upload/delete_file.ts @@ -1,5 +1,7 @@ /** * Delete file REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/file_upload/download_file.ts b/src/core/endpoints/file_upload/download_file.ts index 9d1c9bade..90055d25d 100644 --- a/src/core/endpoints/file_upload/download_file.ts +++ b/src/core/endpoints/file_upload/download_file.ts @@ -1,10 +1,12 @@ /** * Download File REST API module. + * + * @internal */ import { PubNubBasicFileParameters, PubNubFileConstructor, PubNubFileInterface } from '../../types/file'; import { TransportResponse } from '../../types/transport-response'; -import { CryptoModule } from '../../interfaces/crypto-module'; +import { ICryptoModule } from '../../interfaces/crypto-module'; import { Cryptography } from '../../interfaces/cryptography'; import { AbstractRequest } from '../../components/request'; import * as FileSharing from '../../types/api/file-sharing'; @@ -34,7 +36,7 @@ type RequestParameters = FileSharing.DownloadFileParameters & { /** * Send file decryption module. */ - crypto?: CryptoModule; + crypto?: ICryptoModule; /** * Legacy cryptography module. diff --git a/src/core/endpoints/file_upload/generate_upload_url.ts b/src/core/endpoints/file_upload/generate_upload_url.ts index 1dde65f35..b71ebf798 100644 --- a/src/core/endpoints/file_upload/generate_upload_url.ts +++ b/src/core/endpoints/file_upload/generate_upload_url.ts @@ -1,5 +1,7 @@ /** * Generate file upload URL REST API request. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/file_upload/get_file_url.ts b/src/core/endpoints/file_upload/get_file_url.ts index 449284416..b81f4c91b 100644 --- a/src/core/endpoints/file_upload/get_file_url.ts +++ b/src/core/endpoints/file_upload/get_file_url.ts @@ -1,5 +1,7 @@ /** * File sharing REST API module. + * + * @internal */ import { TransportResponse } from '../../types/transport-response'; diff --git a/src/core/endpoints/file_upload/list_files.ts b/src/core/endpoints/file_upload/list_files.ts index 7f899f7ea..3949e05a4 100644 --- a/src/core/endpoints/file_upload/list_files.ts +++ b/src/core/endpoints/file_upload/list_files.ts @@ -1,5 +1,7 @@ /** * List Files REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/file_upload/publish_file.ts b/src/core/endpoints/file_upload/publish_file.ts index 0c9af86e6..ae2699445 100644 --- a/src/core/endpoints/file_upload/publish_file.ts +++ b/src/core/endpoints/file_upload/publish_file.ts @@ -1,10 +1,12 @@ /** * Publish File Message REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { CryptoModule } from '../../interfaces/crypto-module'; +import { ICryptoModule } from '../../interfaces/crypto-module'; import { AbstractRequest } from '../../components/request'; import * as FileSharing from '../../types/api/file-sharing'; import RequestOperation from '../../constants/operations'; @@ -40,7 +42,7 @@ type RequestParameters = FileSharing.PublishFileMessageParameters & { /** * Published data encryption module. */ - crypto?: CryptoModule; + crypto?: ICryptoModule; }; /** diff --git a/src/core/endpoints/file_upload/send_file.ts b/src/core/endpoints/file_upload/send_file.ts index 97fad2f1c..177dcba73 100644 --- a/src/core/endpoints/file_upload/send_file.ts +++ b/src/core/endpoints/file_upload/send_file.ts @@ -1,6 +1,12 @@ +/** + * Share File API module. + * + * @internal + */ + import { PubNubFileConstructor, PubNubFileInterface } from '../../types/file'; import { GenerateFileUploadUrlRequest } from './generate_upload_url'; -import { CryptoModule } from '../../interfaces/crypto-module'; +import { ICryptoModule } from '../../interfaces/crypto-module'; import { Cryptography } from '../../interfaces/cryptography'; import { AbstractRequest } from '../../components/request'; import * as FileSharing from '../../types/api/file-sharing'; @@ -61,7 +67,7 @@ type RequestParameters = FileSharing.SendFileParameters { return { ...(!includeUUIDs! ? { disable_uuids: '1' } : {}), - ...(includeState ?? false ? { state: '1' } : {}), + ...((includeState ?? false) ? { state: '1' } : {}), ...(channelGroups && channelGroups.length > 0 ? { 'channel-group': channelGroups.join(',') } : {}), ...queryParameters!, }; diff --git a/src/core/endpoints/presence/leave.ts b/src/core/endpoints/presence/leave.ts index 36ff29c1f..471354028 100644 --- a/src/core/endpoints/presence/leave.ts +++ b/src/core/endpoints/presence/leave.ts @@ -1,5 +1,7 @@ /** * Announce leave REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/presence/set_state.ts b/src/core/endpoints/presence/set_state.ts index 9e0776bef..989ddbf1c 100644 --- a/src/core/endpoints/presence/set_state.ts +++ b/src/core/endpoints/presence/set_state.ts @@ -1,5 +1,7 @@ /** * Set Presence State REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/presence/where_now.ts b/src/core/endpoints/presence/where_now.ts index 533a3f73b..dfd12e8d8 100644 --- a/src/core/endpoints/presence/where_now.ts +++ b/src/core/endpoints/presence/where_now.ts @@ -1,5 +1,7 @@ /** * `uuid` presence REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/publish.ts b/src/core/endpoints/publish.ts index 47c9110e2..765d68afa 100644 --- a/src/core/endpoints/publish.ts +++ b/src/core/endpoints/publish.ts @@ -5,7 +5,7 @@ import { createValidationError, PubNubError } from '../../errors/pubnub-error'; import { TransportResponse } from '../types/transport-response'; import { TransportMethod } from '../types/transport-request'; -import { CryptoModule } from '../interfaces/crypto-module'; +import { ICryptoModule } from '../interfaces/crypto-module'; import { AbstractRequest } from '../components/request'; import RequestOperation from '../constants/operations'; import { KeySet, Payload, Query } from '../types/api'; @@ -84,11 +84,6 @@ export type PublishParameters = { * @deprecated */ replicate?: boolean; - - /** - * Indexed signature for deprecated parameters. - */ - [key: string]: string | number | boolean | undefined | Payload | CryptoModule; }; /** @@ -113,7 +108,7 @@ type RequestParameters = PublishParameters & { /** * Published data encryption module. */ - crypto?: CryptoModule; + crypto?: ICryptoModule; }; /** diff --git a/src/core/endpoints/push/add_push_channels.ts b/src/core/endpoints/push/add_push_channels.ts index 5265071d9..9f665b5b3 100644 --- a/src/core/endpoints/push/add_push_channels.ts +++ b/src/core/endpoints/push/add_push_channels.ts @@ -1,5 +1,7 @@ /** * Register Channels with Device push REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/push/list_push_channels.ts b/src/core/endpoints/push/list_push_channels.ts index 1892463a3..f1ad59b02 100644 --- a/src/core/endpoints/push/list_push_channels.ts +++ b/src/core/endpoints/push/list_push_channels.ts @@ -1,5 +1,7 @@ /** * List Device push enabled channels REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/push/push.ts b/src/core/endpoints/push/push.ts index 660435f30..fdbe36d3d 100644 --- a/src/core/endpoints/push/push.ts +++ b/src/core/endpoints/push/push.ts @@ -1,5 +1,7 @@ /** * Manage channels enabled for device push REST API module. + * + * @internal */ import { TransportResponse } from '../../types/transport-response'; diff --git a/src/core/endpoints/push/remove_device.ts b/src/core/endpoints/push/remove_device.ts index e0108d5fe..b1150eeea 100644 --- a/src/core/endpoints/push/remove_device.ts +++ b/src/core/endpoints/push/remove_device.ts @@ -1,5 +1,7 @@ /** * Unregister Device push REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/push/remove_push_channels.ts b/src/core/endpoints/push/remove_push_channels.ts index ce4fac47e..88648952b 100644 --- a/src/core/endpoints/push/remove_push_channels.ts +++ b/src/core/endpoints/push/remove_push_channels.ts @@ -1,5 +1,7 @@ /** * Unregister Channels from Device push REST API module. + * + * @internal */ import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; diff --git a/src/core/endpoints/signal.ts b/src/core/endpoints/signal.ts index 5d1c84d05..942989251 100644 --- a/src/core/endpoints/signal.ts +++ b/src/core/endpoints/signal.ts @@ -6,7 +6,7 @@ import { createValidationError, PubNubError } from '../../errors/pubnub-error'; import { TransportResponse } from '../types/transport-response'; import { AbstractRequest } from '../components/request'; import RequestOperation from '../constants/operations'; -import { KeySet, Payload } from '../types/api'; +import { KeySet, Payload, Query } from '../types/api'; import { encodeString } from '../utils'; // -------------------------------------------------------- diff --git a/src/core/endpoints/subscribe.ts b/src/core/endpoints/subscribe.ts index 964657f7a..f01062176 100644 --- a/src/core/endpoints/subscribe.ts +++ b/src/core/endpoints/subscribe.ts @@ -4,7 +4,7 @@ import { createValidationError, PubNubError } from '../../errors/pubnub-error'; import { TransportResponse } from '../types/transport-response'; -import { CryptoModule } from '../interfaces/crypto-module'; +import { ICryptoModule } from '../interfaces/crypto-module'; import * as Subscription from '../types/api/subscription'; import { AbstractRequest } from '../components/request'; import * as FileSharing from '../types/api/file-sharing'; @@ -32,8 +32,6 @@ const WITH_PRESENCE = false; /** * PubNub-defined event types by payload. - * - * @internal */ export enum PubNubEventType { /** @@ -193,8 +191,6 @@ type PresenceStateChangeData = { /** * Channel presence service response. - * - * @internal */ export type PresenceData = PresenceIntervalData | PresenceChangeData | PresenceStateChangeData; // endregion @@ -202,8 +198,6 @@ export type PresenceData = PresenceIntervalData | PresenceChangeData | PresenceS // region Message Actions service response /** * Message reaction change service response. - * - * @internal */ export type MessageActionData = { /** @@ -309,8 +303,6 @@ type ChannelObjectData = ObjectData< /** * `Space` object change real-time service response. - * - * @internal */ export type SpaceObjectData = ObjectData< AppContextVSPEvents, @@ -325,8 +317,6 @@ type UuidObjectData = ObjectData { - constructor(protected readonly parameters: RequestParameters) { + constructor(protected readonly parameters: SubscribeRequestParameters) { super({ cancellable: true }); // Apply default request parameters. diff --git a/src/core/endpoints/subscriptionUtils/handshake.ts b/src/core/endpoints/subscriptionUtils/handshake.ts index 25ccfac2a..d5a258ff4 100644 --- a/src/core/endpoints/subscriptionUtils/handshake.ts +++ b/src/core/endpoints/subscriptionUtils/handshake.ts @@ -1,5 +1,7 @@ /** * Handshake subscribe REST API module. + * + * @internal */ import RequestOperation from '../../constants/operations'; diff --git a/src/core/endpoints/subscriptionUtils/receiveMessages.ts b/src/core/endpoints/subscriptionUtils/receiveMessages.ts index 382e55500..401734147 100644 --- a/src/core/endpoints/subscriptionUtils/receiveMessages.ts +++ b/src/core/endpoints/subscriptionUtils/receiveMessages.ts @@ -1,5 +1,7 @@ /** * Receive messages subscribe REST API module. + * + * @internal */ import RequestOperation from '../../constants/operations'; diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index a062b7a75..2acb0186f 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -4,7 +4,7 @@ import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; import { RequestRetryPolicy } from '../../event-engine/core/retryPolicy'; -import { CryptoModule } from './crypto-module'; +import { ICryptoModule } from './crypto-module'; import { KeySet, Payload } from '../types/api'; import { PubNubError } from '../../errors/pubnub-error'; @@ -402,7 +402,7 @@ export type PlatformConfiguration = { * * @default `not set` */ - cryptoModule?: CryptoModule; + cryptoModule?: ICryptoModule; /** * Platform-specific file representation @@ -571,7 +571,7 @@ export interface PrivateClientConfiguration * * @returns Data processing crypto module (if set). */ - getCryptoModule(): CryptoModule | undefined; + getCryptoModule(): ICryptoModule | undefined; /** * Retrieve user's presence timeout. @@ -741,7 +741,7 @@ export const setDefaults = (configuration: UserConfiguration): ExtendedConfigura let announceFailedHeartbeats = ANNOUNCE_HEARTBEAT_FAILURE; let fileUploadPublishRetryLimit = FILE_PUBLISH_RETRY_LIMIT; let dedupeOnSubscribe = DEDUPE_ON_SUBSCRIBE; - const maximumCacheSize = DEDUPE_CACHE_SIZE; + let maximumCacheSize = DEDUPE_CACHE_SIZE; let useRequestId = USE_REQUEST_ID; // @ts-expect-error Not documented legacy configuration options. @@ -750,6 +750,12 @@ export const setDefaults = (configuration: UserConfiguration): ExtendedConfigura dedupeOnSubscribe = configurationCopy.dedupeOnSubscribe; } + // @ts-expect-error Not documented legacy configuration options. + if (configurationCopy.maximumCacheSize !== undefined && typeof configurationCopy.maximumCacheSize === 'number') { + // @ts-expect-error Not documented legacy configuration options. + maximumCacheSize = configurationCopy.maximumCacheSize; + } + // @ts-expect-error Not documented legacy configuration options. if (configurationCopy.useRequestId !== undefined && typeof configurationCopy.useRequestId === 'boolean') { // @ts-expect-error Not documented legacy configuration options. diff --git a/src/core/interfaces/crypto-module.ts b/src/core/interfaces/crypto-module.ts index 29e173118..017a3d67d 100644 --- a/src/core/interfaces/crypto-module.ts +++ b/src/core/interfaces/crypto-module.ts @@ -49,7 +49,7 @@ export type CryptorConfiguration = { /** * Base crypto module interface. */ -export interface CryptoModule { +export interface ICryptoModule { // -------------------------------------------------------- // --------------------- Encryption ----------------------- // -------------------------------------------------------- @@ -109,14 +109,18 @@ export interface CryptoModule { // endregion } -export abstract class AbstractCryptoModule implements CryptoModule { +export abstract class AbstractCryptoModule implements ICryptoModule { /** * `String` to {@link ArrayBuffer} response decoder. + * + * @internal */ protected static encoder = new TextEncoder(); /** * {@link ArrayBuffer} to {@link string} decoder. + * + * @internal */ protected static decoder = new TextDecoder(); @@ -138,7 +142,7 @@ export abstract class AbstractCryptoModule implements CryptoModule { * * @throws Error if `config.cipherKey` not set. */ - static legacyCryptoModule(config: CryptorConfiguration): CryptoModule { + static legacyCryptoModule(config: CryptorConfiguration): ICryptoModule { throw new Error('Should be implemented by concrete crypto module implementation.'); } @@ -152,7 +156,7 @@ export abstract class AbstractCryptoModule implements CryptoModule { * * @throws Error if `config.cipherKey` not set. */ - static aesCbcCryptoModule(config: CryptorConfiguration): CryptoModule { + static aesCbcCryptoModule(config: CryptorConfiguration): ICryptoModule { throw new Error('Should be implemented by concrete crypto module implementation.'); } // endregion @@ -170,7 +174,7 @@ export abstract class AbstractCryptoModule implements CryptoModule { /** * Encrypt data. * - * @param data - Data which should be encrypted using {@link CryptoModule}. + * @param data - Data which should be encrypted using {@link ICryptoModule}. * * @returns Data encryption result. */ @@ -199,7 +203,7 @@ export abstract class AbstractCryptoModule implements CryptoModule { /** * Encrypt data. * - * @param data - Dta which should be encrypted using `CryptoModule`. + * @param data - Dta which should be encrypted using `ICryptoModule`. * * @returns Data decryption result. */ @@ -227,6 +231,8 @@ export abstract class AbstractCryptoModule implements CryptoModule { /** * Retrieve list of module's cryptors. + * + * @internal */ protected getAllCryptors() { return [this.defaultCryptor, ...this.cryptors]; diff --git a/src/core/pubnub-channel-groups.ts b/src/core/pubnub-channel-groups.ts index ea50e1ea1..908c60d54 100644 --- a/src/core/pubnub-channel-groups.ts +++ b/src/core/pubnub-channel-groups.ts @@ -10,12 +10,41 @@ import { DeleteChannelGroupRequest } from './endpoints/channel_groups/delete_gro import { ListChannelGroupsRequest } from './endpoints/channel_groups/list_groups'; import * as ChannelGroups from './types/api/channel-groups'; -export default class PubnubChannelGroups { +/** + * PubNub Stream / Channel group API interface. + */ +export default class PubNubChannelGroups { + /** + * PubNub account keys set which should be used for REST API calls. + * + * @internal + */ + private readonly keySet: KeySet; + + /* eslint-disable @typescript-eslint/no-explicit-any */ + /** + * Function which should be used to send REST API calls. + * + * @internal + */ + private readonly sendRequest: SendRequestFunction; + + /** + * Create stream / channel group API access object. + * + * @param keySet - PubNub account keys set which should be used for REST API calls. + * @param sendRequest - Function which should be used to send REST API calls. + * + * @internal + */ constructor( - private readonly keySet: KeySet, + keySet: KeySet, /* eslint-disable @typescript-eslint/no-explicit-any */ - private readonly sendRequest: SendRequestFunction, - ) {} + sendRequest: SendRequestFunction, + ) { + this.sendRequest = sendRequest; + this.keySet = keySet; + } // -------------------------------------------------------- // ---------------------- Audit API ----------------------- diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index 4ed0aad14..41615f1c4 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -1,3 +1,7 @@ +/** + * Core PubNub API module. + */ + // region Imports // region Components import { Listener, ListenerManager } from './components/listener_manager'; @@ -39,7 +43,7 @@ import * as Publish from './endpoints/publish'; import * as Signal from './endpoints/signal'; // endregion // region Subscription -import { RequestParameters as SubscribeRequestParameters, SubscribeRequest } from './endpoints/subscribe'; +import { SubscribeRequestParameters as SubscribeRequestParameters, SubscribeRequest } from './endpoints/subscribe'; import { ReceiveMessagesSubscribeRequest } from './endpoints/subscriptionUtils/receiveMessages'; import { HandshakeSubscribeRequest } from './endpoints/subscriptionUtils/handshake'; import * as Subscription from './types/api/subscription'; @@ -112,6 +116,11 @@ import { DownloadFileRequest } from './endpoints/file_upload/download_file'; // -------------------------------------------------------- // region Types +/** + * Core PubNub client configuration object. + * + * @internal + */ type ClientInstanceConfiguration = { /** * Client-provided configuration. @@ -309,6 +318,14 @@ export class PubNubCore< } // endregion + /** + * Create and configure PubNub client core. + * + * @param configuration - PubNub client core configuration. + * @returns Configured and ready to use PubNub client. + * + * @internal + */ constructor(configuration: ClientInstanceConfiguration) { this._configuration = configuration.configuration; this.cryptography = configuration.cryptography; @@ -732,6 +749,8 @@ export class PubNubCore< * @param callback - Request completion handler callback. * * @returns Asynchronous request execution and response parsing result. + * + * @internal */ private sendRequest( request: AbstractRequest, @@ -741,6 +760,8 @@ export class PubNubCore< /** * Schedule request execution. * + * @internal + * * @param request - REST API request. * * @returns Asynchronous request execution and response parsing result. @@ -750,6 +771,8 @@ export class PubNubCore< /** * Schedule request execution. * + * @internal + * * @param request - REST API request. * @param [callback] - Request completion handler callback. * @@ -1080,6 +1103,8 @@ export class PubNubCore< * * **Note:** Method passed into managers to let them use it when required. * + * @internal + * * @param parameters - Request configuration parameters. * @param callback - Request completion handler callback. */ @@ -1135,6 +1160,8 @@ export class PubNubCore< * * **Note:** Method passed into managers to let them use it when required. * + * @internal + * * @param parameters - Request configuration parameters. * @param callback - Request completion handler callback. */ @@ -1186,6 +1213,8 @@ export class PubNubCore< /** * Event engine handshake subscribe. * + * @internal + * * @param parameters - Request configuration parameters. */ private async subscribeHandshake(parameters: Subscription.CancelableSubscribeParameters) { @@ -1218,6 +1247,8 @@ export class PubNubCore< /** * Event engine receive messages subscribe. * + * @internal + * * @param parameters - Request configuration parameters. */ private async subscribeReceiveMessages(parameters: Subscription.CancelableSubscribeParameters) { @@ -1800,6 +1831,8 @@ export class PubNubCore< /** * Announce user presence * + * @internal + * * @param parameters - Desired presence state for provided list of channels and groups. * @param callback - Request completion handler callback. */ @@ -1823,6 +1856,8 @@ export class PubNubCore< /** * Announce user `join` on specified list of channels and groups. * + * @internal + * * @param parameters - List of channels and groups where `join` event should be sent. */ private join(parameters: { channels?: string[]; groups?: string[] }) { @@ -1835,6 +1870,8 @@ export class PubNubCore< /** * Announce user `leave` on specified list of channels and groups. * + * @internal + * * @param parameters - List of channels and groups where `leave` event should be sent. */ private leave(parameters: { channels?: string[]; groups?: string[] }) { @@ -1844,6 +1881,8 @@ export class PubNubCore< /** * Announce user `leave` on all subscribed channels. + * + * @internal */ private leaveAll() { if (process.env.PRESENCE_MODULE !== 'disabled') this.presenceEventEngine?.leaveAll(); @@ -1987,7 +2026,7 @@ export class PubNubCore< * * @returns Token's permissions information for the resources. */ - public parseToken(token: string) { + public parseToken(token: string): PAM.Token | undefined { return this.tokenManager && this.tokenManager.parseToken(token); } // endregion @@ -2808,8 +2847,7 @@ export class PubNubCore< * @param callback - Request completion handler callback. * * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} - * methods instead - * from `objects` API group.. + * methods instead from `objects` API group. */ public removeMemberships< RelationCustom extends AppContext.CustomData = AppContext.CustomData, @@ -2830,8 +2868,7 @@ export class PubNubCore< * @returns Asynchronous memberships modification response. * * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} - * methods instead - * from `objects` API group.. + * methods instead from `objects` API group. */ public async removeMemberships< RelationCustom extends AppContext.CustomData = AppContext.CustomData, @@ -2849,8 +2886,7 @@ export class PubNubCore< * @returns Asynchronous memberships modification response or `void` in case if `callback` provided. * * @deprecated Use {@link PubNubCore#objects.removeMemberships} or {@link PubNubCore#objects.removeChannelMembers} - * methods instead - * from `objects` API group.. + * methods instead from `objects` API group. */ public async removeMemberships< RelationCustom extends AppContext.CustomData = AppContext.CustomData, diff --git a/src/core/pubnub-objects.ts b/src/core/pubnub-objects.ts index 5d4a2152f..b4587f76f 100644 --- a/src/core/pubnub-objects.ts +++ b/src/core/pubnub-objects.ts @@ -19,17 +19,47 @@ import * as AppContext from './types/api/app-context'; import { ChannelMetadataObject } from './types/api/app-context'; import { SetUUIDMetadataRequest } from './endpoints/objects/uuid/set'; +/** + * PubNub App Context API interface. + */ export default class PubNubObjects { + /** + * Extended PubNub client configuration object. + * + * @internal + */ + private readonly configuration: PrivateClientConfiguration; + + /* eslint-disable @typescript-eslint/no-explicit-any */ + /** + * Function which should be used to send REST API calls. + * + * @internal + */ + private readonly sendRequest: SendRequestFunction; /** * REST API endpoints access credentials. + * + * @internal */ private readonly keySet: KeySet; + + /** + * Create app context API access object. + * + * @param configuration - Extended PubNub client configuration object. + * @param sendRequest - Function which should be used to send REST API calls. + * + * @internal + */ constructor( - private readonly configuration: PrivateClientConfiguration, + configuration: PrivateClientConfiguration, /* eslint-disable @typescript-eslint/no-explicit-any */ - private readonly sendRequest: SendRequestFunction, + sendRequest: SendRequestFunction, ) { this.keySet = configuration.keySet; + this.configuration = configuration; + this.sendRequest = sendRequest; } // -------------------------------------------------------- @@ -89,11 +119,12 @@ export default class PubNubObjects { /** * Fetch a paginated list of UUID Metadata objects. * - * * @param [parametersOrCallback] - Request configuration parameters or callback from overload. * @param [callback] - Request completion handler callback. * * @returns Asynchronous get all UUID metadata response or `void` in case if `callback` provided. + * + * @internal */ async _getAllUUIDMetadata( parametersOrCallback?: @@ -169,6 +200,8 @@ export default class PubNubObjects { * @param [callback] - Request completion handler callback. * * @returns Asynchronous get UUID metadata response or `void` in case if `callback` provided. + * + * @internal */ async _getUUIDMetadata( parametersOrCallback?: @@ -234,6 +267,8 @@ export default class PubNubObjects { /** * Update specific UUID Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. Will set UUID metadata for currently * configured PubNub client `uuid` if not set. * @param [callback] - Request completion handler callback. @@ -306,6 +341,8 @@ export default class PubNubObjects { /** * Remove a specific UUID Metadata object. * + * @internal + * * @param [parametersOrCallback] - Request configuration parameters or callback from overload. * @param [callback] - Request completion handler callback. * @@ -390,6 +427,8 @@ export default class PubNubObjects { /** * Fetch a paginated list of Channel Metadata objects. * + * @internal + * * @param [parametersOrCallback] - Request configuration parameters or callback from overload. * @param [callback] - Request completion handler callback. * @@ -453,6 +492,8 @@ export default class PubNubObjects { /** * Fetch Channel Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. * @param [callback] - Request completion handler callback. * @@ -510,6 +551,8 @@ export default class PubNubObjects { /** * Update specific Channel Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. * @param [callback] - Request completion handler callback. * @@ -568,6 +611,8 @@ export default class PubNubObjects { /** * Remove a specific Channel Metadata object. * + * @internal + * * @param parameters - Request configuration parameters. * @param [callback] - Request completion handler callback. * @@ -1065,7 +1110,6 @@ export default class PubNubObjects { uuids: spaceParameters.users?.map((user) => { if (typeof user === 'string') return user; - user.userId; return { id: user.userId, custom: user.custom }; }) ?? spaceParameters.uuids, limit: 0, diff --git a/src/core/pubnub-push.ts b/src/core/pubnub-push.ts index cc8e37b06..c994533ac 100644 --- a/src/core/pubnub-push.ts +++ b/src/core/pubnub-push.ts @@ -10,12 +10,41 @@ import { RemoveDevicePushNotificationRequest } from './endpoints/push/remove_dev import * as PushNotifications from './types/api/push-notifications'; import * as Push from './types/api/push'; +/** + * PubNub Push Notifications API interface. + */ export default class PubNubPushNotifications { + /** + * PubNub account keys set which should be used for REST API calls. + * + * @internal + */ + private readonly keySet: KeySet; + + /* eslint-disable @typescript-eslint/no-explicit-any */ + /** + * Function which should be used to send REST API calls. + * + * @internal + */ + private readonly sendRequest: SendRequestFunction; + + /** + * Create mobile push notifications API access object. + * + * @param keySet - PubNub account keys set which should be used for REST API calls. + * @param sendRequest - Function which should be used to send REST API calls. + * + * @internal + */ constructor( - private readonly keySet: KeySet, + keySet: KeySet, /* eslint-disable @typescript-eslint/no-explicit-any */ - private readonly sendRequest: SendRequestFunction, - ) {} + sendRequest: SendRequestFunction, + ) { + this.sendRequest = sendRequest; + this.keySet = keySet; + } // -------------------------------------------------------- // ---------------------- Audit API ----------------------- diff --git a/src/core/types/api/access-manager.ts b/src/core/types/api/access-manager.ts index a93b77a32..991c1da3a 100644 --- a/src/core/types/api/access-manager.ts +++ b/src/core/types/api/access-manager.ts @@ -1,4 +1,6 @@ // region Grant token +import { Payload } from './index'; + /** * Metadata which will be associated with access token. */ @@ -234,6 +236,146 @@ export type RevokeParameters = string; export type RevokeTokenResponse = Record; // endregion +// -------------------------------------------------------- +// -------------------- Token parse ----------------------- +// -------------------------------------------------------- +// region Parsed token + +/** + * Decoded access token representation. + */ +export type Token = { + /** + * Token version. + */ + version: number; + + /** + * Token generation date time. + */ + timestamp: number; + + /** + * Maximum duration (in minutes) during which token will be valid. + */ + ttl: number; + + /** + * Permissions granted to specific resources. + */ + resources?: Partial>>; + + /** + * Permissions granted to resources which match specified regular expression. + */ + patterns?: Partial>>; + + /** + * The uuid that is exclusively authorized to use this token to make API requests. + */ + authorized_uuid?: string; + + /** + * PAM token content signature. + */ + signature: ArrayBuffer; + + /** + * Additional information which has been added to the token. + */ + meta?: Payload; +}; + +/** + * Granted resource permissions. + * + * **Note:** Following operations doesn't require any permissions: + * - unsubscribe from channel / channel group + * - where now + */ +export type Permissions = { + /** + * Resource read permission. + * + * Read permission required for: + * - subscribe to channel / channel group (including presence versions `-pnpres`) + * - here now + * - get presence state + * - set presence state + * - fetch history + * - fetch messages count + * - list shared files + * - download shared file + * - enable / disable push notifications + * - get message actions + * - get history with message actions + */ + read: boolean; + + /** + * Resource write permission. + * + * Write permission required for: + * - publish message / signal + * - share file + * - add message actions + */ + write: boolean; + + /** + * Resource manage permission. + * + * Manage permission required for: + * - add / remove channels to / from the channel group + * - list channels in group + * - remove channel group + * - set / remove channel members + */ + manage: boolean; + + /** + * Resource delete permission. + * + * Delete permission required for: + * - delete messages from history + * - delete shared file + * - delete user metadata + * - delete channel metadata + * - remove message action + */ + delete: boolean; + + /** + * Resource get permission. + * + * Get permission required for: + * - get user metadata + * - get channel metadata + * - get channel members + */ + get: boolean; + + /** + * Resource update permission. + * + * Update permissions required for: + * - set user metadata + * - set channel metadata + * - set / remove user membership + */ + update: boolean; + + /** + * Resource `join` permission. + * + * `Join` permission required for: + * - set / remove channel members + */ + join: boolean; +}; + +// endregion + // -------------------------------------------------------- // --------------------- Deprecated ----------------------- // -------------------------------------------------------- diff --git a/src/core/types/api/file-sharing.ts b/src/core/types/api/file-sharing.ts index 90200f69a..809da4934 100644 --- a/src/core/types/api/file-sharing.ts +++ b/src/core/types/api/file-sharing.ts @@ -129,7 +129,7 @@ export type SendFileResponse = PublishFileMessageResponse & { /** * Unique file identifier. * - * Unique file identifier and it's {@link name} can be used to download file from the channel + * Unique file identifier, and it's {@link name} can be used to download file from the channel * later. */ id: string; @@ -387,7 +387,7 @@ export type FileUrlParameters = { /** * Unique file identifier. * - * Unique file identifier and it's {@link name} can be used to download file from the channel + * Unique file identifier, and it's {@link name} can be used to download file from the channel * later. */ id: string; @@ -426,7 +426,7 @@ export type DeleteFileParameters = { /** * Unique file identifier. * - * Unique file identifier and it's {@link name} can be used to download file from the channel + * Unique file identifier, and it's {@link name} can be used to download file from the channel * later. */ id: string; diff --git a/src/core/types/api/history.ts b/src/core/types/api/history.ts index 6bea6b7eb..dac984183 100644 --- a/src/core/types/api/history.ts +++ b/src/core/types/api/history.ts @@ -141,7 +141,7 @@ export type Actions = { * High-precision PubNub timetoken with time when {@link uuid} reacted on message. */ actionTimetoken: string; - }; + }[]; }; }; diff --git a/src/core/types/api/index.ts b/src/core/types/api/index.ts index dd3a51e1f..0f85c95f8 100644 --- a/src/core/types/api/index.ts +++ b/src/core/types/api/index.ts @@ -6,6 +6,8 @@ import StatusCategory from '../../constants/categories'; /** * PubNub account keyset. + * + * @internal */ export type KeySet = { /** @@ -26,6 +28,8 @@ export type KeySet = { /** * REST API request processing function. + * + * @internal */ export type SendRequestFunction = ( request: AbstractRequest, @@ -142,4 +146,10 @@ export type Query = Record; * * generic messages and signals content, * * published message metadata. */ -export type Payload = string | number | boolean | { [key: string]: Payload | null } | Payload[]; +export type Payload = + | string + | number + | boolean + | { toJSON: () => Payload } + | { [key: string]: Payload | null } + | Payload[]; diff --git a/src/core/types/api/message-action.ts b/src/core/types/api/message-action.ts index 125d3a3e0..1eabc3d84 100644 --- a/src/core/types/api/message-action.ts +++ b/src/core/types/api/message-action.ts @@ -20,7 +20,7 @@ export type MessageAction = { /** * Timetoken of when message reaction has been added. * - * **Note:** This token required when it will be required to remove raction. + * **Note:** This token required when it will be required to remove reaction. */ actionTimetoken: string; diff --git a/src/core/types/api/push-notifications.ts b/src/core/types/api/push-notifications.ts index 8dd0dadcf..a0c1541e7 100644 --- a/src/core/types/api/push-notifications.ts +++ b/src/core/types/api/push-notifications.ts @@ -15,7 +15,7 @@ type DevicePush = { /** * Push Notifications gateway to use. * - * **Important:** Depends from the source of `device` token and can be `apns2` (for token + * **Important:** Depends on from the source of `device` token and can be `apns2` (for token * provided during device registration using Apple's framework) or `gcm` (when used Firebase * or similar framework to receive token). */ diff --git a/src/core/types/api/subscription.ts b/src/core/types/api/subscription.ts index 5cdab91fe..a7323ca96 100644 --- a/src/core/types/api/subscription.ts +++ b/src/core/types/api/subscription.ts @@ -1,5 +1,5 @@ import { - RequestParameters as SubscribeRequestParameters, + SubscribeRequestParameters, VSPMembershipObjectData, AppContextObjectData, MessageActionData, @@ -302,6 +302,8 @@ type FileEvent = { /** * Cancelable subscribe request parameters. + * + * @internal */ export type CancelableSubscribeParameters = Omit< SubscribeRequestParameters, diff --git a/src/core/utils.ts b/src/core/utils.ts index 5cee8bf45..017e7a1db 100644 --- a/src/core/utils.ts +++ b/src/core/utils.ts @@ -1,3 +1,9 @@ +/** + * PubNub package utilities module. + * + * @internal + */ + import { Query } from './types/api'; /** @@ -8,6 +14,8 @@ import { Query } from './types/api'; * @param input - Source string or number for encoding. * * @returns Percent-encoded string. + * + * @internal */ export const encodeString = (input: string | number) => { return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); @@ -21,12 +29,17 @@ export const encodeString = (input: string | number) => { * @param [defaultString] - String which should be used in case if {@link names} is empty. * * @returns String which contains encoded names joined by non-encoded `,`. + * + * @internal */ export const encodeNames = (names: string[], defaultString?: string) => { const encodedNames = names.map((name) => encodeString(name)); - return encodedNames.length ? encodedNames.join(',') : defaultString ?? ''; + return encodedNames.length ? encodedNames.join(',') : (defaultString ?? ''); }; +/** + * @internal + */ export const removeSingleOccurrence = (source: string[], elementsToRemove: string[]) => { const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); @@ -39,6 +52,9 @@ export const removeSingleOccurrence = (source: string[], elementsToRemove: strin }); }; +/** + * @internal + */ export const findUniqueCommonElements = (a: string[], b: string[]) => { return [...a].filter( (value) => @@ -52,6 +68,8 @@ export const findUniqueCommonElements = (a: string[], b: string[]) => { * @param query - Key / value pairs of the request query parameters. * * @returns Stringified query key / value pairs. + * + * @internal */ export const queryStringFromObject = (query: Query) => { return Object.keys(query) diff --git a/src/crypto/modules/NodeCryptoModule/ICryptor.ts b/src/crypto/modules/NodeCryptoModule/ICryptor.ts index 63860b300..81cfde5b6 100644 --- a/src/crypto/modules/NodeCryptoModule/ICryptor.ts +++ b/src/crypto/modules/NodeCryptoModule/ICryptor.ts @@ -3,7 +3,7 @@ */ /** - * Data encrypted by {@link CryptoModule}. + * Data encrypted by {@link NodeCryptoModule}. */ export type EncryptedDataType = { /** @@ -18,7 +18,7 @@ export type EncryptedDataType = { }; /** - * {@link Readable} stream encrypted by {@link CryptoModule}. + * {@link Readable} stream encrypted by {@link NodeCryptoModule}. */ export type EncryptedStream = { /** diff --git a/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts b/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts index 024b4e188..934dccd75 100644 --- a/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts +++ b/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts @@ -1,5 +1,7 @@ /** * AES-CBC cryptor module. + * + * @internal */ import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'crypto'; @@ -11,6 +13,8 @@ import { ICryptor, EncryptedDataType, EncryptedStream } from './ICryptor'; * AES-CBC cryptor. * * AES-CBC cryptor with enhanced cipher strength. + * + * @internal */ export default class AesCbcCryptor implements ICryptor { /** diff --git a/src/crypto/modules/NodeCryptoModule/legacyCryptor.ts b/src/crypto/modules/NodeCryptoModule/legacyCryptor.ts index 4aa44e4e4..1deddc2ed 100644 --- a/src/crypto/modules/NodeCryptoModule/legacyCryptor.ts +++ b/src/crypto/modules/NodeCryptoModule/legacyCryptor.ts @@ -1,5 +1,7 @@ /** * Legacy cryptor module. + * + * @internal */ import PubNubFile, { PubNubFileParameters } from '../../../file/modules/node'; @@ -14,6 +16,8 @@ import FileCryptor from '../node'; /** * Legacy cryptor. + * + * @internal */ export default class LegacyCryptor implements ILegacyCryptor { /** diff --git a/src/crypto/modules/NodeCryptoModule/nodeCryptoModule.ts b/src/crypto/modules/NodeCryptoModule/nodeCryptoModule.ts index a98176b5d..220dc590d 100644 --- a/src/crypto/modules/NodeCryptoModule/nodeCryptoModule.ts +++ b/src/crypto/modules/NodeCryptoModule/nodeCryptoModule.ts @@ -14,6 +14,7 @@ import { EncryptedDataType, ICryptor } from './ICryptor'; import { ILegacyCryptor } from './ILegacyCryptor'; import AesCbcCryptor from './aesCbcCryptor'; import LegacyCryptor from './legacyCryptor'; +import { Payload } from '../../../core/types/api'; /** * Re-export bundled cryptors. @@ -28,7 +29,7 @@ type CryptorType = ICryptor | ILegacyCryptor; /** * CryptoModule for Node.js platform. */ -export class CryptoModule extends AbstractCryptoModule { +export class NodeCryptoModule extends AbstractCryptoModule { /** * {@link LegacyCryptor|Legacy} cryptor identifier. */ @@ -85,8 +86,8 @@ export class CryptoModule extends AbstractCryptoModule { encrypt(data: ArrayBuffer | string) { // Encrypt data. const encrypted = - data instanceof ArrayBuffer && this.defaultCryptor.identifier === CryptoModule.LEGACY_IDENTIFIER - ? (this.defaultCryptor as ILegacyCryptor).encrypt(CryptoModule.decoder.decode(data)) + data instanceof ArrayBuffer && this.defaultCryptor.identifier === NodeCryptoModule.LEGACY_IDENTIFIER + ? (this.defaultCryptor as ILegacyCryptor).encrypt(NodeCryptoModule.decoder.decode(data)) : (this.defaultCryptor as ICryptor).encrypt(data); if (!encrypted.metadata) return encrypted.data; @@ -96,7 +97,7 @@ export class CryptoModule extends AbstractCryptoModule { // Write encrypted data payload content. const encryptedData = typeof encrypted.data === 'string' - ? CryptoModule.encoder.encode(encrypted.data).buffer + ? NodeCryptoModule.encoder.encode(encrypted.data).buffer : encrypted.data.buffer.slice(encrypted.data.byteOffset, encrypted.data.byteOffset + encrypted.data.length); return this.concatArrayBuffer(headerData, encryptedData); @@ -117,7 +118,7 @@ export class CryptoModule extends AbstractCryptoModule { name: file.name, mimeType: 'application/octet-stream', data: Buffer.from( - typeof encryptedData === 'string' ? CryptoModule.encoder.encode(encryptedData) : encryptedData, + typeof encryptedData === 'string' ? NodeCryptoModule.encoder.encode(encryptedData) : encryptedData, ), }); } @@ -156,7 +157,7 @@ export class CryptoModule extends AbstractCryptoModule { // -------------------------------------------------------- // region Decryption - decrypt(data: ArrayBuffer | string) { + decrypt(data: ArrayBuffer | string): ArrayBuffer | Payload | null { const encryptedData = Buffer.from(typeof data === 'string' ? decode(data) : data); const header = CryptorHeader.tryParse( encryptedData.buffer.slice(encryptedData.byteOffset, encryptedData.byteOffset + encryptedData.length), @@ -188,7 +189,7 @@ export class CryptoModule extends AbstractCryptoModule { * If It's legacy one then redirect it. * (as long as we support legacy need to check on instance type) */ - if (cryptor?.identifier === CryptoModule.LEGACY_IDENTIFIER) + if (cryptor?.identifier === NodeCryptoModule.LEGACY_IDENTIFIER) return (cryptor as ILegacyCryptor).decryptFile(file, File); return File.create({ @@ -217,9 +218,11 @@ export class CryptoModule extends AbstractCryptoModule { * @returns Previously registered {@link ILegacyCryptor|legacy} cryptor. * * @throws Error if legacy cryptor not registered. + * + * @internal */ private getLegacyCryptor(): ILegacyCryptor | undefined { - return this.getCryptorFromId(CryptoModule.LEGACY_IDENTIFIER) as ILegacyCryptor; + return this.getCryptorFromId(NodeCryptoModule.LEGACY_IDENTIFIER) as ILegacyCryptor; } /** @@ -230,6 +233,8 @@ export class CryptoModule extends AbstractCryptoModule { * @returns Registered cryptor with specified identifier. * * @throws Error if cryptor with specified {@link id} can't be found. + * + * @internal */ private getCryptorFromId(id: string) { const cryptor = this.getAllCryptors().find((cryptor) => id === cryptor.identifier); @@ -244,6 +249,8 @@ export class CryptoModule extends AbstractCryptoModule { * @param header - Header with cryptor-defined data or raw cryptor identifier. * * @returns Cryptor which correspond to provided {@link header}. + * + * @internal */ private getCryptor(header: CryptorHeader | string) { if (typeof header === 'string') { @@ -262,6 +269,8 @@ export class CryptoModule extends AbstractCryptoModule { * @param encrypted - Encryption data object as source for header data. * * @returns Binary representation of the cryptor header data. + * + * @internal */ private getHeaderData(encrypted: EncryptedDataType) { if (!encrypted.metadata) return; @@ -282,6 +291,8 @@ export class CryptoModule extends AbstractCryptoModule { * @param ab2 - Second {@link ArrayBuffer}. * * @returns Merged data as {@link ArrayBuffer}. + * + * @internal */ private concatArrayBuffer(ab1: ArrayBuffer, ab2: ArrayBuffer): ArrayBuffer { const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); @@ -302,6 +313,8 @@ export class CryptoModule extends AbstractCryptoModule { * @returns Decrypted data as {@link PubNub} File object. * * @throws Error if file is empty or contains unsupported data type. + * + * @internal */ private async onStreamReadable( stream: NodeJS.ReadableStream, @@ -347,6 +360,8 @@ export class CryptoModule extends AbstractCryptoModule { * @returns Decrypted data as {@link PubNub} File object. * * @throws Error if file is empty or contains unsupported data type. + * + * @internal */ private async decryptLegacyFileStream( stream: NodeJS.ReadableStream, @@ -372,6 +387,8 @@ export class CryptoModule extends AbstractCryptoModule { /** * CryptorHeader Utility + * + * @internal */ class CryptorHeader { static decoder = new TextDecoder(); @@ -422,7 +439,7 @@ class CryptorHeader { let version = null; if (encryptedData.byteLength >= 4) { sentinel = encryptedData.slice(0, 4); - if (!this.isSentinel(sentinel)) return CryptoModule.LEGACY_IDENTIFIER; + if (!this.isSentinel(sentinel)) return NodeCryptoModule.LEGACY_IDENTIFIER; } if (encryptedData.byteLength >= 5) version = encryptedDataView.getInt8(4); @@ -449,6 +466,8 @@ class CryptorHeader { /** * Cryptor header (v1). + * + * @internal */ class CryptorHeaderV1 { _identifier; diff --git a/src/crypto/modules/node.ts b/src/crypto/modules/node.ts index e0eacbd77..e0d484f31 100644 --- a/src/crypto/modules/node.ts +++ b/src/crypto/modules/node.ts @@ -1,5 +1,7 @@ /** * Legacy Node.js cryptography module. + * + * @internal */ import { createCipheriv, createDecipheriv, createHash, randomBytes } from 'crypto'; @@ -12,6 +14,8 @@ import { PubNubFileConstructor } from '../../core/types/file'; /** * Legacy cryptography implementation for Node.js-based {@link PubNub} client. + * + * @internal */ export default class NodeCryptography implements Cryptography { /** diff --git a/src/crypto/modules/web.ts b/src/crypto/modules/web.ts index e971fab6f..1ba8f0177 100644 --- a/src/crypto/modules/web.ts +++ b/src/crypto/modules/web.ts @@ -1,23 +1,18 @@ -/* global crypto */ /** * Legacy browser cryptography module. + * + * @internal */ +/* global crypto */ import { PubNubFile, PubNubFileParameters } from '../../file/modules/web'; import { Cryptography } from '../../core/interfaces/cryptography'; import { PubNubFileConstructor } from '../../core/types/file'; -function concatArrayBuffer(ab1: ArrayBuffer, ab2: ArrayBuffer) { - const tmp = new Uint8Array(ab1.byteLength + ab2.byteLength); - - tmp.set(new Uint8Array(ab1), 0); - tmp.set(new Uint8Array(ab2), ab1.byteLength); - - return tmp.buffer; -} - /** * Legacy cryptography implementation for browser-based {@link PubNub} client. + * + * @internal */ export default class WebCryptography implements Cryptography { /** @@ -70,7 +65,7 @@ export default class WebCryptography implements Cryptography; + + /** + * Channel entity name. + * + * @internal + */ private readonly name: string; - constructor( - channelName: string, - private readonly eventEmitter: EventEmitter, - private readonly pubnub: PubNub, - ) { - this.name = channelName; + /** + * Create simple channel entity. + * + * @param name - Name of the channel which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use channel entity. + * + * @internal + */ + constructor(name: string, eventEmitter: EventEmitter, pubnub: PubNub) { + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + this.name = name; } + /** + * Create channel's subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific channel. + * + * @param [subscriptionOptions] - Channel's subscription object behavior customization options. + * + * @returns Configured and ready to use channel's subscription object. + */ subscription(subscriptionOptions?: SubscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { return new Subscription({ diff --git a/src/entities/ChannelGroup.ts b/src/entities/ChannelGroup.ts index fa6cba92c..9b3355956 100644 --- a/src/entities/ChannelGroup.ts +++ b/src/entities/ChannelGroup.ts @@ -3,17 +3,60 @@ import EventEmitter from '../core/components/eventEmitter'; import { SubscriptionOptions } from './commonTypes'; import { Subscription } from './Subscription'; +/** + * First-class objects which provides access to the channel group-specific APIs. + */ export class ChannelGroup { + /** + * Event emitter, which will notify listeners about updates received on channel group's + * subscription. + * + * @internal + */ + private readonly eventEmitter: EventEmitter; + + /** + * PubNub instance which will use this entity. + * + * @internal + */ + private readonly pubnub: PubNub; + + /** + * Channel group entity name. + * + * @internal + */ private readonly name: string; - constructor( - channelGroup: string, - private readonly eventEmitter: EventEmitter, - private readonly pubnub: PubNub, - ) { - this.name = channelGroup; + /** + * Create simple channel entity. + * + * @param name - Name of the channel group which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel group's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use channel group entity. + * + * @internal + */ + constructor(name: string, eventEmitter: EventEmitter, pubnub: PubNub) { + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + this.name = name; } + /** + * Create channel group's subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the channels in + * specific channel group. + * + * @param [subscriptionOptions] - Channel group's subscription object behavior customization options. + * + * @returns Configured and ready to use channel group's subscription object. + */ subscription(subscriptionOptions?: SubscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { return new Subscription({ diff --git a/src/entities/ChannelMetadata.ts b/src/entities/ChannelMetadata.ts index 14b78666d..cd7293714 100644 --- a/src/entities/ChannelMetadata.ts +++ b/src/entities/ChannelMetadata.ts @@ -3,13 +3,60 @@ import EventEmitter from '../core/components/eventEmitter'; import { SubscriptionOptions } from './commonTypes'; import { Subscription } from './Subscription'; +/** + * First-class objects which provides access to the channel app context object-specific APIs. + */ export class ChannelMetadata { - constructor( - private readonly id: string, - private readonly eventEmitter: EventEmitter, - private readonly pubnub: PubNub, - ) {} + /** + * Event emitter, which will notify listeners about updates received on channel app context object + * subscription. + * + * @internal + */ + private readonly eventEmitter: EventEmitter; + /** + * PubNub instance which will use this entity. + * + * @internal + */ + private readonly pubnub: PubNub; + + /** + * Channel app context object identifier. + * + * @internal + */ + private readonly id: string; + + /** + * Create channel app context object entity. + * + * @param id - Channel app context object identifier which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use channel app context object entity. + * + * @internal + */ + constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub) { + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + this.id = id; + } + + /** + * Create channel's app context subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific channel + * app context object. + * + * @param [subscriptionOptions] - Channel's app context subscription object behavior customization options. + * + * @returns Configured and ready to use channel's app context subscription object. + */ subscription(subscriptionOptions?: SubscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { return new Subscription({ diff --git a/src/entities/SubscribeCapable.ts b/src/entities/SubscribeCapable.ts index 0454a323a..38bbd6ead 100644 --- a/src/entities/SubscribeCapable.ts +++ b/src/entities/SubscribeCapable.ts @@ -5,13 +5,56 @@ import EventEmitter from '../core/components/eventEmitter'; import { SubscriptionOptions } from './commonTypes'; export abstract class SubscribeCapable { + /** + * List of channel names for subscription loop. + * + * @internal + */ protected abstract channelNames: string[]; + + /** + * List of channel group names for subscription loop. + * + * @internal + */ protected abstract groupNames: string[]; - protected abstract listener: Listener; + + /** + * Subscribable object configuration. + * + * @internal + */ + protected abstract options?: SubscriptionOptions; + + /** + * Event emitter, which will notify listeners about updates received for channels / groups. + * + * @internal + */ protected abstract eventEmitter: EventEmitter; + + /** + * Real-time events listener object associated with entity subscription object. + * + * Listener will be used to notify about updates received from the channels / groups. + * + * @internal + */ + protected abstract listener: Listener; + + /** + * PubNub instance which will perform subscribe / unsubscribe requests. + * + * @internal + */ protected abstract pubnub: PubNub; - protected abstract options?: SubscriptionOptions; + /** + * Start receiving real-time updates. + * + * @param subscribeParameters - Additional subscription configuration options which should be used + * for request. + */ subscribe(subscribeParameters?: { timetoken?: string }) { const timetoken = subscribeParameters?.timetoken; this.pubnub.subscribe({ @@ -20,6 +63,10 @@ export abstract class SubscribeCapable { ...(timetoken !== null && timetoken !== '' && { timetoken: timetoken }), }); } + + /** + * Stop real-time events processing. + */ unsubscribe() { this.pubnub.unsubscribe({ channels: this.channelNames, @@ -27,30 +74,72 @@ export abstract class SubscribeCapable { }); } + /** + * Set new message handler. + * + * @param onMessageListener - Listener function, which will be called each time when a new message + * is received from the real-time network. + */ set onMessage(onMessageListener: (messageEvent: Subscription.Message) => void) { this.listener.message = onMessageListener; } + /** + * Set new presence events handler. + * + * @param onPresenceListener - Listener function, which will be called each time when a new + * presence event is received from the real-time network. + */ set onPresence(onPresenceListener: (presenceEvent: Subscription.Presence) => void) { this.listener.presence = onPresenceListener; } + /** + * Set new signal handler. + * + * @param onSignalListener - Listener function, which will be called each time when a new signal + * is received from the real-time network. + */ set onSignal(onSignalListener: (signalEvent: Subscription.Signal) => void) { this.listener.signal = onSignalListener; } + /** + * Set new app context event handler. + * + * @param onObjectsListener - Listener function, which will be called each time when a new + * app context event is received from the real-time network. + */ set onObjects(onObjectsListener: (objectsEvent: Subscription.AppContextObject) => void) { this.listener.objects = onObjectsListener; } + /** + * Set new message reaction event handler. + * + * @param messageActionEventListener - Listener function, which will be called each time when a + * new message reaction event is received from the real-time network. + */ set onMessageAction(messageActionEventListener: (messageActionEvent: Subscription.MessageAction) => void) { this.listener.messageAction = messageActionEventListener; } + /** + * Set new file handler. + * + * @param fileEventListener - Listener function, which will be called each time when a new file + * is received from the real-time network. + */ set onFile(fileEventListener: (fileEvent: Subscription.File) => void) { this.listener.file = fileEventListener; } + /** + * Set events handler. + * + * @param listener - Events listener configuration object, which lets specify handlers for multiple + * types of events. + */ addListener(listener: Listener) { this.eventEmitter.addListener( listener, @@ -58,13 +147,32 @@ export abstract class SubscribeCapable { this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), ); } + + /** + * Remove events handler. + * + * @param listener - Event listener configuration, which should be removed from the list of notified + * listeners. **Important:** Should be the same object which has been passed to the + * {@link addListener}. + */ removeListener(listener: Listener) { this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); } + /** + * Get list of channels which is used for subscription. + * + * @returns List of channel names. + */ get channels(): string[] { return this.channelNames.slice(0); } + + /** + * Get list of channel groups which is used for subscription. + * + * @returns List of channel group names. + */ get channelGroups(): string[] { return this.groupNames.slice(0); } diff --git a/src/entities/Subscription.ts b/src/entities/Subscription.ts index 2002313e5..2043c4607 100644 --- a/src/entities/Subscription.ts +++ b/src/entities/Subscription.ts @@ -5,14 +5,80 @@ import { SubscribeCapable } from './SubscribeCapable'; import { SubscriptionOptions } from './commonTypes'; import { SubscriptionSet } from './SubscriptionSet'; +/** + * Single-entity subscription object which can be used to receive and handle real-time updates. + */ export class Subscription extends SubscribeCapable { + /** + * List of channel names for subscription loop. + * + * Entity may have few because of subscription configuration options. Presence events observing + * adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entity type, it may provide a list of channels which are used + * to receive real-time updates for it. + * + * @internal + */ protected channelNames: string[] = []; + + /** + * List of channel group names for subscription loop. + * + * Entity may have few because of subscription configuration options. Presence events observing + * adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entity type, it may provide a list of channel groups which is + * sed to receive real-time updates for it. + * + * @internal + */ protected groupNames: string[] = []; + + /** + * Per-entity subscription object configuration. + * + * @internal + */ protected options?: SubscriptionOptions; + + /** + * PubNub instance which will perform subscribe / unsubscribe requests for entity. + * + * @internal + */ protected pubnub: PubNub; + + /** + * Event emitter, which will notify listeners about updates received for entity channels / groups. + * + * @internal + */ protected eventEmitter: EventEmitter; + + /** + * Real-time events listener object associated with entity subscription object. + * + * Listener will be used to notify about updates received from the entity channels / groups. + * + * @internal + */ protected listener: Listener; + /** + * Create entity's subscription object. + * + * @param channels - List of channels which should be used in subscription loop. + * @param channelGroups - List of channel groups which should be used in subscription loop. + * @param subscriptionOptions - Per-entity subscription object configuration. + * @param eventEmitter - Event emitter, which will notify listeners about updates received for + * entity channels / groups. + * @param pubnub - PubNub instance which will perform subscribe / unsubscribe requests for entity. + * + * @returns Ready to use entity's subscription object. + * + * @internal + */ constructor({ channels, channelGroups, @@ -39,6 +105,13 @@ export class Subscription extends SubscribeCapable { this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), ); } + + /** + * Merge entities' subscription objects into subscription set. + * + * @param subscription - Other entity's subscription object to be merged with receiver. + * @return Subscription set which contains both receiver and other entities' subscription objects. + */ addSubscription(subscription: Subscription) { return new SubscriptionSet({ channels: [...this.channelNames, ...subscription.channels], diff --git a/src/entities/SubscriptionSet.ts b/src/entities/SubscriptionSet.ts index 1885d3bef..d1c4d20cf 100644 --- a/src/entities/SubscriptionSet.ts +++ b/src/entities/SubscriptionSet.ts @@ -5,15 +5,96 @@ import { SubscribeCapable } from './SubscribeCapable'; import { SubscriptionOptions } from './commonTypes'; import { Subscription } from './Subscription'; +/** + * Multiple entities subscription set object which can be used to receive and handle real-time + * updates. + * + * Subscription set object represent collection of per-entity subscription objects and allow + * processing them at once for subscription loop and events handling. + */ export class SubscriptionSet extends SubscribeCapable { + /** + * List of channel names for subscription loop. + * + * List of entities' names which can have additional entries depending on from configuration + * options. Presence events observing adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entities' type, they may provide a list of channels which are + * used to receive real-time updates for it. + * + * @internal + */ protected channelNames: string[] = []; + + /** + * List of channel group names for subscription loop. + * + * List of entities' names which can have additional entries depending on from configuration + * options. Presence events observing adds additional name to be used along with entity name. + * + * **Note:** Depending on from the entities' type, they may provide a list of channels which are + * used to receive real-time updates for it. + * + * @internal + */ protected groupNames: string[] = []; + + /** + * Entities' subscription object configuration. + * + * @internal + */ protected options?: SubscriptionOptions; + + /** + * PubNub instance which will perform subscribe / unsubscribe requests for entities. + * + * @internal + */ protected pubnub: PubNub; + + /** + * Event emitter, which will notify listeners about updates received for entities + * channels / groups. + * + * @internal + */ protected eventEmitter: EventEmitter; + + /** + * List of per-entity subscription objects. + * + * @internal + */ protected subscriptionList: Subscription[] = []; + + /** + * Real-time events listener object associated with entities' subscription objects. + * + * Listener will be used to notify about updates received from the entities' channels / groups. + * + * @internal + */ protected listener: Listener; + /** + * Create entities' subscription set object. + * + * Subscription set object represent collection of per-entity subscription objects and allow + * processing them at once for subscription loop and events handling. + * + * @param channels - List of channels which should be used in subscription loop. + * @param channelGroups - List of channel groups which should be used in subscription loop. + * @param subscriptionOptions - Entities' subscription object configuration. + * @param eventEmitter - Event emitter, which will notify listeners about updates received for + * entities' channels / groups. + * @param pubnub - PubNub instance which will perform subscribe / unsubscribe requests for + * entities. + * + * @returns Ready to use entities' subscription set object. + * + * @internal + */ constructor({ channels = [], channelGroups = [], @@ -49,6 +130,14 @@ export class SubscriptionSet extends SubscribeCapable { ); } + /** + * Add additional entity's subscription to the subscription set. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#subscribe} call or + * next subscription loop. + * + * @param subscription - Other entity's subscription object, which should be added. + */ addSubscription(subscription: Subscription) { this.subscriptionList.push(subscription); this.channelNames = [...this.channelNames, ...subscription.channels]; @@ -56,6 +145,14 @@ export class SubscriptionSet extends SubscribeCapable { this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); } + /** + * Remove entity's subscription object from the set. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#unsubscribe} call or + * next subscription loop. + * + * @param subscription - Other entity's subscription object, which should be removed. + */ removeSubscription(subscription: Subscription) { const channelsToRemove = subscription.channels; const groupsToRemove = subscription.channelGroups; @@ -65,6 +162,14 @@ export class SubscriptionSet extends SubscribeCapable { this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); } + /** + * Merge with other subscription set object. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#subscribe} call or + * next subscription loop. + * + * @param subscriptionSet - Other entities' subscription set, which should be joined. + */ addSubscriptionSet(subscriptionSet: SubscriptionSet) { this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; @@ -72,6 +177,14 @@ export class SubscriptionSet extends SubscribeCapable { this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); } + /** + * Subtract other subscription set object. + * + * **Important:** Changes will be effective only after {@link SubscribeCapable#unsubscribe} call or + * next subscription loop. + * + * @param subscriptionSet - Other entities' subscription set, which should be subtracted. + */ removeSubscriptionSet(subscriptionSet: SubscriptionSet) { const channelsToRemove = subscriptionSet.channels; const groupsToRemove = subscriptionSet.channelGroups; @@ -81,6 +194,11 @@ export class SubscriptionSet extends SubscribeCapable { this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); } + /** + * Get list of entities' subscription objects registered in subscription set. + * + * @returns Entities' subscription objects list. + */ get subscriptions(): Subscription[] { return this.subscriptionList.slice(0); } diff --git a/src/entities/UserMetadata.ts b/src/entities/UserMetadata.ts index 256950823..1e7a3b161 100644 --- a/src/entities/UserMetadata.ts +++ b/src/entities/UserMetadata.ts @@ -3,13 +3,60 @@ import EventEmitter from '../core/components/eventEmitter'; import { SubscriptionOptions } from './commonTypes'; import { Subscription } from './Subscription'; +/** + * First-class objects which provides access to the user app context object-specific APIs. + */ export class UserMetadata { - constructor( - private readonly id: string, - private readonly eventEmitter: EventEmitter, - private readonly pubnub: PubNub, - ) {} + /** + * Event emitter, which will notify listeners about updates received on user app context object + * subscription. + * + * @internal + */ + private readonly eventEmitter: EventEmitter; + /** + * PubNub instance which will use this entity. + * + * @internal + */ + private readonly pubnub: PubNub; + + /** + * User app context object identifier. + * + * @internal + */ + private readonly id: string; + + /** + * Create user app context object entity. + * + * @param id - User app context object identifier which will be used with subscription loop. + * @param eventEmitter - Event emitter, which will notify listeners about updates received on + * channel's subscription. + * @param pubnub - PubNub instance which will use this entity. + * + * @returns Ready to use user app context object entity. + * + * @internal + */ + constructor(id: string, eventEmitter: EventEmitter, pubnub: PubNub) { + this.eventEmitter = eventEmitter; + this.pubnub = pubnub; + this.id = id; + } + + /** + * Create user's app context subscription object for real-time updates. + * + * Create subscription object which can be used to subscribe to the real-time updates sent to the specific user + * app context object. + * + * @param [subscriptionOptions] - User's app context subscription object behavior customization options. + * + * @returns Configured and ready to use user's app context subscription object. + */ subscription(subscriptionOptions?: SubscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { return new Subscription({ diff --git a/src/entities/commonTypes.ts b/src/entities/commonTypes.ts index fe7de30b4..33fbf29de 100644 --- a/src/entities/commonTypes.ts +++ b/src/entities/commonTypes.ts @@ -1,3 +1,9 @@ +/** + * PubNub entity subscription configuration options. + */ export type SubscriptionOptions = { + /** + * Whether presence events for entity should be received or not. + */ receivePresenceEvents?: boolean; }; diff --git a/src/errors/pubnub-api-error.ts b/src/errors/pubnub-api-error.ts index 793deb1bb..3c5c5572b 100644 --- a/src/errors/pubnub-api-error.ts +++ b/src/errors/pubnub-api-error.ts @@ -1,5 +1,7 @@ /** * REST API endpoint use error module. + * + * @internal */ import { TransportResponse } from '../core/types/transport-response'; @@ -10,6 +12,8 @@ import { PubNubError } from './pubnub-error'; /** * PubNub REST API call error. + * + * @internal */ export class PubNubAPIError extends Error { /** diff --git a/src/errors/pubnub-error.ts b/src/errors/pubnub-error.ts index 435352aa8..b3fee4d9b 100644 --- a/src/errors/pubnub-error.ts +++ b/src/errors/pubnub-error.ts @@ -1,7 +1,26 @@ +/** + * PubNub operation error module. + */ + import { Status } from '../core/types/api'; import StatusCategory from '../core/constants/categories'; +/** + * PubNub operation error. + * + * When an operation can't be performed or there is an error from the server, this object will be returned. + */ export class PubNubError extends Error { + /** + * Create PubNub operation error. + * + * @param message - Message with details about why operation failed. + * @param [status] - Additional information about performed operation. + * + * @returns Configured and ready to use PubNub operation error. + * + * @internal + */ constructor( message: string, public status?: Status, @@ -14,6 +33,15 @@ export class PubNubError extends Error { } } +/** + * Create error status object. + * + * @param errorPayload - Additional information which should be attached to the error status object. + * + * @returns Error status object. + * + * @internal + */ function createError(errorPayload: { message: string; statusCode?: number }): Status { errorPayload.statusCode ??= 0; @@ -25,6 +53,16 @@ function createError(errorPayload: { message: string; statusCode?: number }): St }; } +/** + * Create operation arguments validation error status object. + * + * @param message - Information about failed validation requirement. + * @param [statusCode] - Operation HTTP status code. + * + * @returns Operation validation error status object. + * + * @internal + */ export function createValidationError(message: string, statusCode?: number) { return createError({ message, ...(statusCode !== undefined ? { statusCode } : {}) }); } diff --git a/src/event-engine/core/change.ts b/src/event-engine/core/change.ts index dbacb32f6..7199af71e 100644 --- a/src/event-engine/core/change.ts +++ b/src/event-engine/core/change.ts @@ -1,8 +1,15 @@ +/** + * Event Engine Core state change module. + * + * @internal + */ + /* eslint-disable @typescript-eslint/no-explicit-any */ import { State } from './state'; import { EventTypeFromMap, GenericMap, InvocationTypeFromMap } from './types'; +/** @internal */ export type EngineStarted = { type: 'engineStarted'; @@ -10,12 +17,14 @@ export type EngineStarted context: any; }; +/** @internal */ export type EventReceived = { type: 'eventReceived'; event: EventTypeFromMap; }; +/** @internal */ export type TransitionDone = { type: 'transitionDone'; event: EventTypeFromMap; @@ -27,11 +36,13 @@ export type TransitionDone = { type: 'invocationDispatched'; invocation: InvocationTypeFromMap; }; +/** @internal */ export type Change = | TransitionDone | InvocationDispatched diff --git a/src/event-engine/core/dispatcher.ts b/src/event-engine/core/dispatcher.ts index 598295d83..637a7d67f 100644 --- a/src/event-engine/core/dispatcher.ts +++ b/src/event-engine/core/dispatcher.ts @@ -1,13 +1,31 @@ +/** + * Event Engine Core Effects dispatcher module. + * + * @internal + */ + /* eslint-disable @typescript-eslint/no-explicit-any */ import { Handler } from './handler'; import { GenericInvocation, GenericMap, InvocationTypeFromMap } from './types'; +/** + * Effects invocation processing handler function definition. + * + * @internal + */ type HandlerCreator = ( payload: Payload, dependencies: Dependencies, ) => Handler; +/** + * Event Engine effects dispatcher. + * + * Dispatcher responsible for invocation enqueue and dequeue for processing. + * + * @internal + */ export class Dispatcher< Effects extends GenericMap, Dependencies, diff --git a/src/event-engine/core/engine.ts b/src/event-engine/core/engine.ts index a2cf11acd..51fbd611d 100644 --- a/src/event-engine/core/engine.ts +++ b/src/event-engine/core/engine.ts @@ -1,3 +1,9 @@ +/** + * Event Engine Core module. + * + * @internal + */ + /* eslint-disable @typescript-eslint/no-explicit-any */ import { Subject } from '../../core/components/subject'; @@ -6,6 +12,11 @@ import { Change } from './change'; import { State } from './state'; import { GenericMap, Event } from './types'; +/** + * Generic event engine. + * + * @internal + */ export class Engine extends Subject> { describe(label: string): State { return new State(label); diff --git a/src/event-engine/core/handler.ts b/src/event-engine/core/handler.ts index 338a922f9..aa93e16da 100644 --- a/src/event-engine/core/handler.ts +++ b/src/event-engine/core/handler.ts @@ -1,5 +1,18 @@ +/** + * Event Engine Core Effects handler module. + * + * @internal + */ + import { AbortSignal } from '../../core/components/abort_signal'; +/** + * Synchronous (short-term) effect invocation handler. + * + * Handler manages effect execution on behalf of effect dispatcher. + * + * @internal + */ export abstract class Handler { constructor( protected payload: Payload, @@ -10,12 +23,24 @@ export abstract class Handler { abstract cancel(): void; } +/** + * Asynchronous effect execution function definition. + * + * @internal + */ type AsyncHandlerFunction = ( payload: Payload, abortSignal: AbortSignal, dependencies: Dependencies, ) => Promise; +/** + * Asynchronous (long-running) effect invocation handler. + * + * Handler manages effect execution on behalf of effect dispatcher. + * + * @internal + */ class AsyncHandler extends Handler { abortSignal = new AbortSignal(); @@ -39,6 +64,13 @@ class AsyncHandler extends Handler } } +/** + * Asynchronous effect invocation handler constructor. + * + * @param handlerFunction - Function which performs asynchronous action and should be called on `start`. + * + * @internal + */ export const asyncHandler = (handlerFunction: AsyncHandlerFunction) => (payload: Payload, dependencies: Dependencies) => diff --git a/src/event-engine/core/index.ts b/src/event-engine/core/index.ts index 3607d8892..75af8ca4f 100644 --- a/src/event-engine/core/index.ts +++ b/src/event-engine/core/index.ts @@ -1,5 +1,15 @@ +/** + * Event Engine module. + * + * @internal + */ + +/** @internal */ export { Engine } from './engine'; +/** @internal */ export { Dispatcher } from './dispatcher'; +/** @internal */ export { MapOf, createEvent, createEffect, createManagedEffect } from './types'; +/** @internal */ export { asyncHandler } from './handler'; diff --git a/src/event-engine/core/retryPolicy.ts b/src/event-engine/core/retryPolicy.ts index ebc515ad9..f47606f80 100644 --- a/src/event-engine/core/retryPolicy.ts +++ b/src/event-engine/core/retryPolicy.ts @@ -1,5 +1,11 @@ +/** + * Failed requests retry module. + */ import { PubNubError } from '../../errors/pubnub-error'; +/** + * Failed request retry policy. + */ export class RetryPolicy { static LinearRetryPolicy( configuration: LinearRetryPolicyConfiguration, @@ -79,7 +85,7 @@ export type RequestRetryPolicy = { * Check whether failed request can be retried. * * @param reason - Request processing failure reason. - * @param attempt - Number of consequent failure. + * @param attempt - Number of sequential failure. * * @returns `true` if another request retry attempt can be done. */ @@ -88,7 +94,7 @@ export type RequestRetryPolicy = { /** * Computed delay for next request retry attempt. * - * @param attempt - Number of consequent failure. + * @param attempt - Number of sequential failure. * @param reason - Request processing failure reason. * * @returns Delay before next request retry attempt in milliseconds. @@ -99,7 +105,7 @@ export type RequestRetryPolicy = { * Identify reason why another retry attempt can't be made. * * @param reason - Request processing failure reason. - * @param attempt - Number of consequent failure. + * @param attempt - Number of sequential failure. * * @returns Give up reason. */ diff --git a/src/event-engine/core/state.ts b/src/event-engine/core/state.ts index 5f32b5300..999f73e3c 100644 --- a/src/event-engine/core/state.ts +++ b/src/event-engine/core/state.ts @@ -1,7 +1,14 @@ +/** + * Event Engine Core state module. + * + * @internal + */ + /* eslint-disable @typescript-eslint/no-explicit-any */ import { Event, EventOfType, GenericInvocation, GenericMap, InvocationTypeFromMap } from './types'; +/** @internal */ export type TransitionFunction< Context, Events extends GenericMap, @@ -11,12 +18,20 @@ export type TransitionFunction< (context: Context, event: EventType): Transition | void; }; +/** @internal */ export type Transition = [ State, Context, InvocationTypeFromMap[], ]; +/** + * Event engine current state object. + * + * State contains current context and list of invocations which should be performed by the Event Engine. + * + * @internal + */ export class State { private transitionMap: Map> = new Map(); diff --git a/src/event-engine/core/types.ts b/src/event-engine/core/types.ts index a10f31336..a98cc1d83 100644 --- a/src/event-engine/core/types.ts +++ b/src/event-engine/core/types.ts @@ -1,30 +1,51 @@ +/** + * Event Engine Core types module. + * + * @internal + */ + /* eslint-disable @typescript-eslint/no-explicit-any */ +/** @internal */ export type Event = { type: T; payload: P }; +/** @internal */ export type Invocation = { type: T; payload: P; managed: boolean }; +/** @internal */ export type GenericEvent = Event; +/** @internal */ export type GenericInvocation = Invocation; +/** @internal */ export type GenericMap = Record; +/** @internal */ export type EventTypeFromMap = { [T in keyof Map & string]: Event; }[keyof Map & string]; +/** @internal */ export type InvocationTypeFromMap = { [T in keyof Map & string]: Invocation; }[keyof Map & string]; +/** @internal */ export type EventOfType = Event; +/** @internal */ export type InvocationOfType = Invocation; +/** @internal */ type EventCreator = { (...args: S): Event; type: K; }; +/** + * Create and configure event engine event. + * + * @internal + */ export function createEvent( type: K, fn: (...args: S) => P, @@ -41,16 +62,19 @@ export function createEvent { type: string | number | symbol; payload: any }> = { [K in ReturnType['type']]: (ReturnType & { type: K })['payload']; }; +/** @internal */ type EffectCreator = { (...args: S): Invocation; type: K; }; +/** @internal */ type ManagedEffectCreator = { (...args: S): Invocation; @@ -58,6 +82,11 @@ type ManagedEffectCreator = { cancel: Invocation<'CANCEL', K>; }; +/** + * Create and configure short-term effect invocation. + * + * @internal + */ export function createEffect( type: K, fn: (...args: S) => P, @@ -71,6 +100,11 @@ export function createEffect( type: K, fn: (...args: S) => P, diff --git a/src/event-engine/dispatcher.ts b/src/event-engine/dispatcher.ts index 5d9c7c064..989bb8ce1 100644 --- a/src/event-engine/dispatcher.ts +++ b/src/event-engine/dispatcher.ts @@ -1,3 +1,9 @@ +/** + * Subscribe Event Engine effects dispatcher. + * + * @internal + */ + import { PrivateClientConfiguration } from '../core/interfaces/configuration'; import * as Subscription from '../core/types/api/subscription'; import { PubNubError } from '../errors/pubnub-error'; @@ -7,6 +13,11 @@ import * as events from './events'; import { Payload, StatusEvent } from '../core/types/api'; import StatusCategory from '../core/constants/categories'; +/** + * Subscription Event Engine dependencies set (configuration). + * + * @internal + */ export type Dependencies = { handshake: (parameters: Subscription.CancelableSubscribeParameters) => Promise; receiveMessages: ( @@ -24,6 +35,13 @@ export type Dependencies = { emitStatus: (status: StatusEvent) => void; }; +/** + * Subscribe Event Engine dispatcher. + * + * Dispatcher responsible for subscription events handling and corresponding effects execution. + * + * @internal + */ export class EventEngineDispatcher extends Dispatcher { constructor(engine: Engine, dependencies: Dependencies) { super(dependencies); diff --git a/src/event-engine/effects.ts b/src/event-engine/effects.ts index 80dcc17f7..8aab8a20a 100644 --- a/src/event-engine/effects.ts +++ b/src/event-engine/effects.ts @@ -1,36 +1,90 @@ +/** + * Subscribe Event Engine effects module. + * + * @internal + */ + import { createEffect, createManagedEffect, MapOf } from './core'; import { HandshakeReconnectingStateContext } from './states/handshake_reconnecting'; import { ReceiveReconnectingStateContext } from './states/receive_reconnecting'; import * as Subscription from '../core/types/api/subscription'; import { StatusEvent } from '../core/types/api'; +/** + * Initial subscription effect. + * + * Performs subscribe REST API call with `tt=0`. + * + * @internal + */ export const handshake = createManagedEffect('HANDSHAKE', (channels: string[], groups: string[]) => ({ channels, groups, })); +/** + * Real-time updates receive effect. + * + * Performs sequential subscribe REST API call with `tt` set to the value received from the previous subscribe + * REST API call. + * + * @internal + */ export const receiveMessages = createManagedEffect( 'RECEIVE_MESSAGES', (channels: string[], groups: string[], cursor: Subscription.SubscriptionCursor) => ({ channels, groups, cursor }), ); +/** + * Emit real-time updates effect. + * + * Notify event listeners about updates for which listener handlers has been provided. + * + * @internal + */ export const emitMessages = createEffect( 'EMIT_MESSAGES', (events: Subscription.SubscriptionResponse['messages']) => events, ); +/** + * Emit subscription status change effect. + * + * Notify status change event listeners. + * + * @internal + */ export const emitStatus = createEffect('EMIT_STATUS', (status: StatusEvent) => status); +/** + * Real-time updates receive restore effect. + * + * Performs subscribe REST API call with `tt` which has been received before disconnection or error. + * + * @internal + */ export const receiveReconnect = createManagedEffect( 'RECEIVE_RECONNECT', (context: ReceiveReconnectingStateContext) => context, ); +/** + * Initial subscription restore effect. + * + * Performs subscribe REST API call with `tt=0` after error. + * + * @internal + */ export const handshakeReconnect = createManagedEffect( 'HANDSHAKE_RECONNECT', (context: HandshakeReconnectingStateContext) => context, ); +/** + * Subscribe Event Engine effects. + * + * @internal + */ export type Effects = MapOf< | typeof receiveMessages | typeof handshake diff --git a/src/event-engine/events.ts b/src/event-engine/events.ts index 70fa68b3b..afd2b7e56 100644 --- a/src/event-engine/events.ts +++ b/src/event-engine/events.ts @@ -1,12 +1,32 @@ +/** + * Subscribe Event Engine events module. + * + * @internal + */ + import * as Subscription from '../core/types/api/subscription'; import { PubNubError } from '../errors/pubnub-error'; import { createEvent, MapOf } from './core'; +/** + * Subscription list change event. + * + * Event is sent each time when user would like to change list of active channels / groups. + * + * @internal + */ export const subscriptionChange = createEvent('SUBSCRIPTION_CHANGED', (channels: string[], groups: string[]) => ({ channels, groups, })); +/** + * Subscription loop restore. + * + * Event is sent when user would like to try catch up on missed updates by providing specific timetoken. + * + * @internal + */ export const restore = createEvent( 'SUBSCRIPTION_RESTORED', (channels: string[], groups: string[], timetoken: string | number, region?: number) => ({ @@ -19,18 +39,61 @@ export const restore = createEvent( }), ); +/** + * Initial subscription handshake success event. + * + * Event is sent by corresponding effect handler if REST API call was successful. + * + * @internal + */ export const handshakeSuccess = createEvent('HANDSHAKE_SUCCESS', (cursor: Subscription.SubscriptionCursor) => cursor); + +/** + * Initial subscription handshake did fail event. + * + * Event is sent by corresponding effect handler if REST API call failed. + * + * @internal + */ export const handshakeFailure = createEvent('HANDSHAKE_FAILURE', (error: PubNubError) => error); +/** + * Initial subscription handshake reconnect success event. + * + * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. + * + * @internal + */ export const handshakeReconnectSuccess = createEvent( 'HANDSHAKE_RECONNECT_SUCCESS', (cursor: Subscription.SubscriptionCursor) => ({ cursor, }), ); +/** + * Initial subscription handshake reconnect did fail event. + * + * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. + * + * @internal + */ export const handshakeReconnectFailure = createEvent('HANDSHAKE_RECONNECT_FAILURE', (error: PubNubError) => error); +/** + * Initial subscription handshake impossible event. + * + * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. + * + * @internal + */ export const handshakeReconnectGiveup = createEvent('HANDSHAKE_RECONNECT_GIVEUP', (error: PubNubError) => error); +/** + * Subscription successfully received real-time updates event. + * + * Event is sent by corresponding effect handler if REST API call was successful. + * + * @internal + */ export const receiveSuccess = createEvent( 'RECEIVE_SUCCESS', (cursor: Subscription.SubscriptionCursor, events: Subscription.SubscriptionResponse['messages']) => ({ @@ -38,8 +101,22 @@ export const receiveSuccess = createEvent( events, }), ); +/** + * Subscription did fail to receive real-time updates event. + * + * Event is sent by corresponding effect handler if REST API call failed. + * + * @internal + */ export const receiveFailure = createEvent('RECEIVE_FAILURE', (error: PubNubError) => error); +/** + * Subscription successfully received real-time updates on reconnection attempt event. + * + * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. + * + * @internal + */ export const receiveReconnectSuccess = createEvent( 'RECEIVE_RECONNECT_SUCCESS', (cursor: Subscription.SubscriptionCursor, events: Subscription.SubscriptionResponse['messages']) => ({ @@ -47,18 +124,59 @@ export const receiveReconnectSuccess = createEvent( events, }), ); +/** + * Subscription did fail to receive real-time updates on reconnection attempt event. + * + * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. + * + * @internal + */ export const receiveReconnectFailure = createEvent('RECEIVE_RECONNECT_FAILURE', (error: PubNubError) => error); +/** + * Subscription real-time updates received impossible event. + * + * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. + * + * @internal + */ export const receiveReconnectGiveup = createEvent('RECEIVING_RECONNECT_GIVEUP', (error: PubNubError) => error); +/** + * Client disconnect event. + * + * Event is sent when user wants to temporarily stop real-time updates receive. + * + * @internal + */ export const disconnect = createEvent('DISCONNECT', () => ({})); +/** + * Client reconnect event. + * + * Event is sent when user wants to restore real-time updates receive. + * + * @internal + */ export const reconnect = createEvent('RECONNECT', (timetoken?: string, region?: number) => ({ cursor: { timetoken: timetoken ?? '', region: region ?? 0, }, })); + +/** + * Completely stop real-time updates receive event. + * + * Event is sent when user doesn't want to receive any real-time updates anymore. + * + * @internal + */ export const unsubscribeAll = createEvent('UNSUBSCRIBE_ALL', () => ({})); +/** + * Subscribe Event Engine events. + * + * @internal + */ export type Events = MapOf< | typeof subscriptionChange | typeof restore diff --git a/src/event-engine/index.ts b/src/event-engine/index.ts index 983a659c5..0dc1dedbe 100644 --- a/src/event-engine/index.ts +++ b/src/event-engine/index.ts @@ -1,3 +1,9 @@ +/** + * Subscribe Event Engine module. + * + * @internal + */ + import { Dispatcher, Engine } from './core'; import { Dependencies, EventEngineDispatcher } from './dispatcher'; import * as effects from './effects'; @@ -6,6 +12,11 @@ import { UnsubscribedState } from './states/unsubscribed'; import * as utils from '../core/utils'; +/** + * Subscribe Event Engine Core. + * + * @internal + */ export class EventEngine { private engine: Engine = new Engine(); private dispatcher: Dispatcher; diff --git a/src/event-engine/presence/dispatcher.ts b/src/event-engine/presence/dispatcher.ts index f2dfa0571..e6d12ba63 100644 --- a/src/event-engine/presence/dispatcher.ts +++ b/src/event-engine/presence/dispatcher.ts @@ -1,3 +1,9 @@ +/** + * Presence Event Engine effects dispatcher. + * + * @internal + */ + import { PrivateClientConfiguration } from '../../core/interfaces/configuration'; import { asyncHandler, Dispatcher, Engine } from '../core'; import PNOperations from '../../core/constants/operations'; @@ -8,6 +14,11 @@ import * as effects from './effects'; import * as events from './events'; import StatusCategory from '../../core/constants/categories'; +/** + * Presence Event Engine dependencies set (configuration). + * + * @internal + */ export type Dependencies = { heartbeat: ( parameters: Presence.PresenceHeartbeatParameters, @@ -24,6 +35,13 @@ export type Dependencies = { emitStatus: (status: any) => void; }; +/** + * Presence Event Engine dispatcher. + * + * Dispatcher responsible for presence events handling and corresponding effects execution. + * + * @internal + */ export class PresenceEventEngineDispatcher extends Dispatcher { constructor(engine: Engine, dependencies: Dependencies) { super(dependencies); diff --git a/src/event-engine/presence/effects.ts b/src/event-engine/presence/effects.ts index 0eddde4d5..1bcfa5c87 100644 --- a/src/event-engine/presence/effects.ts +++ b/src/event-engine/presence/effects.ts @@ -1,27 +1,73 @@ +/** + * Presence Event Engine effects module. + * + * @internal + */ + import { createEffect, createManagedEffect, MapOf } from '../core'; import { HeartbeatReconnectingStateContext } from './states/heartbeat_reconnecting'; import { Status } from '../../core/types/api'; +/** + * Presence heartbeat effect. + * + * Performs presence heartbeat REST API call. + * + * @internal + */ export const heartbeat = createEffect('HEARTBEAT', (channels: string[], groups: string[]) => ({ channels, groups, })); +/** + * Presence leave effect. + * + * Performs presence leave REST API call. + * + * @internal + */ export const leave = createEffect('LEAVE', (channels: string[], groups: string[]) => ({ channels, groups, })); +/** + * Emit presence heartbeat REST API call result status effect. + * + * Notify status change event listeners. + * + * @internal + */ /* eslint-disable @typescript-eslint/no-explicit-any */ export const emitStatus = createEffect('EMIT_STATUS', (status: any) => status); +/** + * Heartbeat delay effect. + * + * Delay of configured length (heartbeat interval) before another heartbeat REST API call will be done. + * + * @internal + */ export const wait = createManagedEffect('WAIT', () => ({})); +/** + * Delayed heartbeat effect. + * + * Similar to the {@link wait} effect but used in case if previous heartbeat call did fail. + * + * @internal + */ export const delayedHeartbeat = createManagedEffect( 'DELAYED_HEARTBEAT', (context: HeartbeatReconnectingStateContext) => context, ); +/** + * Presence Event Engine effects. + * + * @internal + */ export type Effects = MapOf< typeof heartbeat | typeof leave | typeof emitStatus | typeof wait | typeof delayedHeartbeat >; diff --git a/src/event-engine/presence/events.ts b/src/event-engine/presence/events.ts index 9607a44d7..0b3b67a12 100644 --- a/src/event-engine/presence/events.ts +++ b/src/event-engine/presence/events.ts @@ -1,29 +1,108 @@ +/** + * Presence Event Engine events module. + * + * @internal + */ + import { PubNubError } from '../../errors/pubnub-error'; import { createEvent, MapOf } from '../core'; +/** + * Reconnect event. + * + * Event is sent each time when user restores real-time updates processing and notifies other present subscribers + * about joining back. + * + * @internal + */ export const reconnect = createEvent('RECONNECT', () => ({})); +/** + * Disconnect event. + * + * Event is sent when user wants to temporarily stop real-time updates processing and notifies other present + * subscribers about leaving. + * + * @internal + */ export const disconnect = createEvent('DISCONNECT', () => ({})); +/** + * Channel / group join event. + * + * Event is sent when user adds new channels / groups to the active channels / groups list and notifies other present + * subscribers about joining. + * + * @internal + */ export const joined = createEvent('JOINED', (channels: string[], groups: string[]) => ({ channels, groups, })); +/** + * Channel / group leave event. + * + * Event is sent when user removes channels / groups from the active channels / groups list and notifies other present + * subscribers about leaving. + * + * @internal + */ export const left = createEvent('LEFT', (channels: string[], groups: string[]) => ({ channels, groups, })); +/** + * Leave all event. + * + * Event is sent when user doesn't want to receive any real-time updates anymore and notifies other + * subscribers on previously active channels / groups about leaving. + * + * @internal + */ export const leftAll = createEvent('LEFT_ALL', () => ({})); +/** + * Presence heartbeat success event. + * + * Event is sent by corresponding effect handler if REST API call was successful. + * + * @internal + */ export const heartbeatSuccess = createEvent('HEARTBEAT_SUCCESS', (statusCode: number) => ({ statusCode })); +/** + * Presence heartbeat did fail event. + * + * Event is sent by corresponding effect handler if REST API call failed. + * + * @internal + */ export const heartbeatFailure = createEvent('HEARTBEAT_FAILURE', (error: PubNubError) => error); +/** + * Presence heartbeat impossible event. + * + * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. + * + * @internal + */ export const heartbeatGiveup = createEvent('HEARTBEAT_GIVEUP', () => ({})); +/** + * Delayed presence heartbeat event. + * + * Event is sent by corresponding effect handler when delay timer between heartbeat calls fired. + * + * @internal + */ export const timesUp = createEvent('TIMES_UP', () => ({})); +/** + * Presence Event Engine events. + * + * @internal + */ export type Events = MapOf< | typeof reconnect | typeof disconnect diff --git a/src/event-engine/presence/presence.ts b/src/event-engine/presence/presence.ts index 768fbed1e..408a2f329 100644 --- a/src/event-engine/presence/presence.ts +++ b/src/event-engine/presence/presence.ts @@ -1,3 +1,9 @@ +/** + * Presence Event Engine module. + * + * @internal + */ + import { Dispatcher, Engine } from '../core'; import * as events from './events'; import * as effects from './effects'; @@ -5,6 +11,11 @@ import { Dependencies, PresenceEventEngineDispatcher } from './dispatcher'; import { HeartbeatInactiveState } from './states/heartbeat_inactive'; +/** + * Presence Event Engine Core. + * + * @internal + */ export class PresenceEventEngine { private engine: Engine = new Engine(); private dispatcher: Dispatcher; diff --git a/src/event-engine/presence/states/heartbeat_cooldown.ts b/src/event-engine/presence/states/heartbeat_cooldown.ts index 21e0563f3..97faebd7e 100644 --- a/src/event-engine/presence/states/heartbeat_cooldown.ts +++ b/src/event-engine/presence/states/heartbeat_cooldown.ts @@ -1,3 +1,9 @@ +/** + * Waiting next heartbeat state module. + * + * @internal + */ + import { State } from '../../core/state'; import { Events, disconnect, joined, left, leftAll, timesUp } from '../events'; import { Effects, leave, wait } from '../effects'; @@ -5,11 +11,23 @@ import { HeartbeatingState } from './heartbeating'; import { HeartbeatStoppedState } from './heartbeat_stopped'; import { HeartbeatInactiveState } from './heartbeat_inactive'; +/** + * Context which represent current Presence Event Engine data state. + * + * @internal + */ export type HeartbeatCooldownStateContext = { channels: string[]; groups: string[]; }; +/** + * Waiting next heartbeat state. + * + * State in which Presence Event Engine is waiting when delay will run out and next heartbeat call should be done. + * + * @internal + */ export const HeartbeatCooldownState = new State('HEARTBEAT_COOLDOWN'); HeartbeatCooldownState.onEnter(() => wait()); diff --git a/src/event-engine/presence/states/heartbeat_failed.ts b/src/event-engine/presence/states/heartbeat_failed.ts index 14fadf591..b82042d6d 100644 --- a/src/event-engine/presence/states/heartbeat_failed.ts +++ b/src/event-engine/presence/states/heartbeat_failed.ts @@ -1,3 +1,9 @@ +/** + * Failed to heartbeat state module. + * + * @internal + */ + import { State } from '../../core/state'; import { Events, disconnect, heartbeatFailure, heartbeatSuccess, joined, left, leftAll, reconnect } from '../events'; import { Effects, heartbeat, leave } from '../effects'; @@ -5,11 +11,24 @@ import { HeartbeatingState } from './heartbeating'; import { HeartbeatStoppedState } from './heartbeat_stopped'; import { HeartbeatInactiveState } from './heartbeat_inactive'; +/** + * Context which represent current Presence Event Engine data state. + * + * @internal + */ export type HeartbeatFailedStateContext = { channels: string[]; groups: string[]; }; +/** + * Failed to heartbeat state. + * + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. + * + * @internal + */ export const HeartbeatFailedState = new State('HEARTBEAT_FAILED'); HeartbeatFailedState.on(joined.type, (context, event) => diff --git a/src/event-engine/presence/states/heartbeat_inactive.ts b/src/event-engine/presence/states/heartbeat_inactive.ts index a095a3215..397e87e3b 100644 --- a/src/event-engine/presence/states/heartbeat_inactive.ts +++ b/src/event-engine/presence/states/heartbeat_inactive.ts @@ -1,8 +1,21 @@ +/** + * Inactive heratbeating state module. + * + * @internal + */ + import { State } from '../../core/state'; import { Effects } from '../effects'; import { Events, joined } from '../events'; import { HeartbeatingState } from './heartbeating'; +/** + * Inactive heratbeating state + * + * State in which Presence Event Engine doesn't process any heartbeat requests (initial state). + * + * @internal + */ export const HeartbeatInactiveState = new State('HEARTBEAT_INACTIVE'); HeartbeatInactiveState.on(joined.type, (_, event) => diff --git a/src/event-engine/presence/states/heartbeat_reconnecting.ts b/src/event-engine/presence/states/heartbeat_reconnecting.ts index a665004ab..26f3e84e5 100644 --- a/src/event-engine/presence/states/heartbeat_reconnecting.ts +++ b/src/event-engine/presence/states/heartbeat_reconnecting.ts @@ -1,3 +1,9 @@ +/** + * Retry heartbeat state module. + * + * @internal + */ + import { PubNubError } from '../../../errors/pubnub-error'; import { State } from '../../core/state'; import { @@ -17,6 +23,11 @@ import { HeartbeatCooldownState } from './heartbeat_cooldown'; import { HeartbeatInactiveState } from './heartbeat_inactive'; import { HeartbeatFailedState } from './heartbeat_failed'; +/** + * Context which represent current Subscription Event Engine data state. + * + * @internal + */ export type HeartbeatReconnectingStateContext = { channels: string[]; groups: string[]; @@ -25,6 +36,13 @@ export type HeartbeatReconnectingStateContext = { reason: PubNubError; }; +/** + * Retry heartbeat state. + * + * State in which Presence Event Engine tries to recover after error which happened before. + * + * @internal + */ export const HearbeatReconnectingState = new State( 'HEARBEAT_RECONNECTING', ); diff --git a/src/event-engine/presence/states/heartbeat_stopped.ts b/src/event-engine/presence/states/heartbeat_stopped.ts index ea8e85df0..3891f49a6 100644 --- a/src/event-engine/presence/states/heartbeat_stopped.ts +++ b/src/event-engine/presence/states/heartbeat_stopped.ts @@ -1,14 +1,33 @@ +/** + * Heartbeat stopped state module. + * + * @internal + */ + import { State } from '../../core/state'; import { Effects } from '../effects'; import { Events, joined, left, reconnect, leftAll } from '../events'; import { HeartbeatInactiveState } from './heartbeat_inactive'; import { HeartbeatingState } from './heartbeating'; +/** + * Context which represent current Presence Event Engine data state. + * + * @internal + */ export type HeartbeatStoppedStateContext = { channels: string[]; groups: string[]; }; +/** + * Heartbeat stopped state. + * + * State in which Presence Event Engine still has information about active channels / groups, but doesn't wait for + * delayed heartbeat request sending. + * + * @internal + */ export const HeartbeatStoppedState = new State('HEARTBEAT_STOPPED'); HeartbeatStoppedState.on(joined.type, (context, event) => diff --git a/src/event-engine/presence/states/heartbeating.ts b/src/event-engine/presence/states/heartbeating.ts index 1b45b9796..f2e4a1c6b 100644 --- a/src/event-engine/presence/states/heartbeating.ts +++ b/src/event-engine/presence/states/heartbeating.ts @@ -1,3 +1,9 @@ +/** + * Heartbeating state module. + * + * @internal + */ + import { State } from '../../core/state'; import { Events, disconnect, heartbeatFailure, heartbeatSuccess, joined, left, leftAll } from '../events'; import { Effects, emitStatus, heartbeat, leave } from '../effects'; @@ -6,11 +12,23 @@ import { HearbeatReconnectingState } from './heartbeat_reconnecting'; import { HeartbeatStoppedState } from './heartbeat_stopped'; import { HeartbeatInactiveState } from './heartbeat_inactive'; +/** + * Context which represent current Presence Event Engine data state. + * + * @internal + */ export type HeartbeatingStateContext = { channels: string[]; groups: string[]; }; +/** + * Heartbeating state module. + * + * State in which Presence Event Engine send heartbeat REST API call. + * + * @internal + */ export const HeartbeatingState = new State('HEARTBEATING'); HeartbeatingState.onEnter((context) => heartbeat(context.channels, context.groups)); diff --git a/src/event-engine/states/handshake_failed.ts b/src/event-engine/states/handshake_failed.ts index 7b86933a4..5ca187877 100644 --- a/src/event-engine/states/handshake_failed.ts +++ b/src/event-engine/states/handshake_failed.ts @@ -1,3 +1,9 @@ +/** + * Failed initial subscription handshake (disconnected) state. + * + * @internal + */ + import { State } from '../core/state'; import { Effects } from '../effects'; import { Events, reconnect, restore, subscriptionChange, unsubscribeAll } from '../events'; @@ -6,6 +12,11 @@ import { HandshakingState } from './handshaking'; import { UnsubscribedState } from './unsubscribed'; import * as Subscription from '../../core/types/api/subscription'; +/** + * Context which represent current Subscription Event Engine data state. + * + * @internal + */ export type HandshakeFailedStateContext = { channels: string[]; groups: string[]; @@ -14,6 +25,14 @@ export type HandshakeFailedStateContext = { reason: PubNubError; }; +/** + * Failed initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. + * + * @internal + */ export const HandshakeFailedState = new State('HANDSHAKE_FAILED'); HandshakeFailedState.on(subscriptionChange.type, (context, event) => @@ -38,7 +57,7 @@ HandshakeFailedState.on(restore.type, (context, event) => groups: event.payload.groups, cursor: { timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region ? event.payload.cursor.region : context?.cursor?.region ?? 0, + region: event.payload.cursor.region ? event.payload.cursor.region : (context?.cursor?.region ?? 0), }, }), ); diff --git a/src/event-engine/states/handshake_reconnecting.ts b/src/event-engine/states/handshake_reconnecting.ts index 6c82a348d..aece709c3 100644 --- a/src/event-engine/states/handshake_reconnecting.ts +++ b/src/event-engine/states/handshake_reconnecting.ts @@ -1,3 +1,9 @@ +/** + * Retry initial subscription handshake (disconnected) state. + * + * @internal + */ + import { PubNubError } from '../../errors/pubnub-error'; import { State } from '../core/state'; import { Effects, emitStatus, handshakeReconnect } from '../effects'; @@ -19,6 +25,11 @@ import { UnsubscribedState } from './unsubscribed'; import categoryConstants from '../../core/constants/categories'; import * as Subscription from '../../core/types/api/subscription'; +/** + * Context which represent current Subscription Event Engine data state. + * + * @internal + */ export type HandshakeReconnectingStateContext = { channels: string[]; groups: string[]; @@ -28,6 +39,13 @@ export type HandshakeReconnectingStateContext = { reason: PubNubError; }; +/** + * Retry initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine tries to recover after error which happened before. + * + * @internal + */ export const HandshakeReconnectingState = new State( 'HANDSHAKE_RECONNECTING', ); diff --git a/src/event-engine/states/handshake_stopped.ts b/src/event-engine/states/handshake_stopped.ts index e7040c417..a902dda9e 100644 --- a/src/event-engine/states/handshake_stopped.ts +++ b/src/event-engine/states/handshake_stopped.ts @@ -1,3 +1,9 @@ +/** + * Stopped initial subscription handshake (disconnected) state. + * + * @internal + */ + import { State } from '../core/state'; import { Effects } from '../effects'; import { Events, reconnect, restore, subscriptionChange, unsubscribeAll } from '../events'; @@ -5,12 +11,25 @@ import { HandshakingState } from './handshaking'; import { UnsubscribedState } from './unsubscribed'; import * as Subscription from '../../core/types/api/subscription'; +/** + * Context which represent current Subscription Event Engine data state. + * + * @internal + */ type HandshakeStoppedStateContext = { channels: string[]; groups: string[]; cursor?: Subscription.SubscriptionCursor; }; +/** + * Stopped initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine still has information about subscription but doesn't have subscription + * cursor for next sequential subscribe REST API call. + * + * @internal + */ export const HandshakeStoppedState = new State('HANDSHAKE_STOPPED'); HandshakeStoppedState.on(subscriptionChange.type, (context, event) => diff --git a/src/event-engine/states/handshaking.ts b/src/event-engine/states/handshaking.ts index c2dcdb7b5..d856b7e20 100644 --- a/src/event-engine/states/handshaking.ts +++ b/src/event-engine/states/handshaking.ts @@ -1,3 +1,9 @@ +/** + * Initial subscription handshake (disconnected) state. + * + * @internal + */ + import { State } from '../core/state'; import { Effects, handshake, emitStatus } from '../effects'; import { @@ -16,12 +22,25 @@ import { UnsubscribedState } from './unsubscribed'; import categoryConstants from '../../core/constants/categories'; import * as Subscription from '../../core/types/api/subscription'; +/** + * Context which represent current Subscription Event Engine data state. + * + * @internal + */ export type HandshakingStateContext = { channels: string[]; groups: string[]; cursor?: Subscription.SubscriptionCursor; }; +/** + * Initial subscription handshake (disconnected) state. + * + * State in which Subscription Event Engine tries to receive subscription cursor for next sequential subscribe REST + * API calls. + * + * @internal + */ export const HandshakingState = new State('HANDSHAKING'); HandshakingState.onEnter((context) => handshake(context.channels, context.groups)); diff --git a/src/event-engine/states/receive_failed.ts b/src/event-engine/states/receive_failed.ts index 5b3db90be..34d46ed71 100644 --- a/src/event-engine/states/receive_failed.ts +++ b/src/event-engine/states/receive_failed.ts @@ -1,3 +1,9 @@ +/** + * Failed to receive real-time updates (disconnected) state. + * + * @internal + */ + import { State } from '../core/state'; import { Effects } from '../effects'; import { Events, reconnect, restore, subscriptionChange, unsubscribeAll } from '../events'; @@ -6,6 +12,11 @@ import { HandshakingState } from './handshaking'; import { UnsubscribedState } from './unsubscribed'; import * as Subscription from '../../core/types/api/subscription'; +/** + * Context which represent current Subscription Event Engine data state. + * + * @internal + */ export type ReceiveFailedStateContext = { channels: string[]; groups: string[]; @@ -14,6 +25,14 @@ export type ReceiveFailedStateContext = { reason: PubNubError; }; +/** + * Failed to receive real-time updates (disconnected) state. + * + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. + * + * @internal + */ export const ReceiveFailedState = new State('RECEIVE_FAILED'); ReceiveFailedState.on(reconnect.type, (context, event) => diff --git a/src/event-engine/states/receive_reconnecting.ts b/src/event-engine/states/receive_reconnecting.ts index 133a44bfe..91854e2b6 100644 --- a/src/event-engine/states/receive_reconnecting.ts +++ b/src/event-engine/states/receive_reconnecting.ts @@ -1,3 +1,9 @@ +/** + * Reconnect to receive real-time updates (disconnected) state. + * + * @internal + */ + import { PubNubError } from '../../errors/pubnub-error'; import { State } from '../core/state'; import { Effects, emitMessages, receiveReconnect, emitStatus } from '../effects'; @@ -18,6 +24,11 @@ import { UnsubscribedState } from './unsubscribed'; import categoryConstants from '../../core/constants/categories'; import * as Subscription from '../../core/types/api/subscription'; +/** + * Context which represent current Subscription Event Engine data state. + * + * @internal + */ export type ReceiveReconnectingStateContext = { channels: string[]; groups: string[]; @@ -27,6 +38,13 @@ export type ReceiveReconnectingStateContext = { reason: PubNubError; }; +/** + * Reconnect to receive real-time updates (disconnected) state. + * + * State in which Subscription Event Engine tries to recover after error which happened before. + * + * @internal + */ export const ReceiveReconnectingState = new State( 'RECEIVE_RECONNECTING', ); diff --git a/src/event-engine/states/receive_stopped.ts b/src/event-engine/states/receive_stopped.ts index 49027d275..39e13e1d4 100644 --- a/src/event-engine/states/receive_stopped.ts +++ b/src/event-engine/states/receive_stopped.ts @@ -1,3 +1,9 @@ +/** + * Stopped real-time updates (disconnected) state module. + * + * @internal + */ + import { State } from '../core/state'; import { Effects } from '../effects'; import { Events, reconnect, restore, subscriptionChange, unsubscribeAll } from '../events'; @@ -5,12 +11,25 @@ import { HandshakingState } from './handshaking'; import { UnsubscribedState } from './unsubscribed'; import * as Subscription from '../../core/types/api/subscription'; +/** + * Context which represent current Subscription Event Engine data state. + * + * @internal + */ type ReceiveStoppedStateContext = { channels: string[]; groups: string[]; cursor: Subscription.SubscriptionCursor; }; +/** + * Stopped real-time updates (disconnected) state. + * + * State in which Subscription Event Engine still has information about subscription but doesn't process real-time + * updates. + * + * @internal + */ export const ReceiveStoppedState = new State('RECEIVE_STOPPED'); ReceiveStoppedState.on(subscriptionChange.type, (context, event) => diff --git a/src/event-engine/states/receiving.ts b/src/event-engine/states/receiving.ts index 7219f0bf3..84362a694 100644 --- a/src/event-engine/states/receiving.ts +++ b/src/event-engine/states/receiving.ts @@ -1,3 +1,9 @@ +/** + * Receiving real-time updates (connected) state module. + * + * @internal + */ + import { State } from '../core/state'; import { Effects, emitMessages, emitStatus, receiveMessages } from '../effects'; import { @@ -15,12 +21,24 @@ import { ReceiveStoppedState } from './receive_stopped'; import categoryConstants from '../../core/constants/categories'; import * as Subscription from '../../core/types/api/subscription'; +/** + * Context which represent current Subscription Event Engine data state. + * + * @internal + */ export type ReceivingStateContext = { channels: string[]; groups: string[]; cursor: Subscription.SubscriptionCursor; }; +/** + * Receiving real-time updates (connected) state. + * + * State in which Subscription Event Engine processes any real-time updates. + * + * @internal + */ export const ReceivingState = new State('RECEIVING'); ReceivingState.onEnter((context) => receiveMessages(context.channels, context.groups, context.cursor)); diff --git a/src/event-engine/states/unsubscribed.ts b/src/event-engine/states/unsubscribed.ts index 70794694e..8d62499b1 100644 --- a/src/event-engine/states/unsubscribed.ts +++ b/src/event-engine/states/unsubscribed.ts @@ -1,8 +1,21 @@ +/** + * Unsubscribed / disconnected state module. + * + * @internal + */ + import { State } from '../core/state'; import { Effects } from '../effects'; import { Events, subscriptionChange, restore } from '../events'; import { HandshakingState } from './handshaking'; +/** + * Unsubscribed / disconnected state. + * + * State in which Subscription Event Engine doesn't process any real-time updates. + * + * @internal + */ export const UnsubscribedState = new State('UNSUBSCRIBED'); UnsubscribedState.on(subscriptionChange.type, (_, event) => diff --git a/src/models/Cursor.ts b/src/models/Cursor.ts index 60eca78f3..84ab64bac 100644 --- a/src/models/Cursor.ts +++ b/src/models/Cursor.ts @@ -1,4 +1,18 @@ +/** + * Subscription cursor. + * + * Cursor used by {@link PubNub} client as reference point in time after which new real-time events should be + * received and processed. + */ export type Cursor = { + /** + * PubNub high-precision timestamp. + */ readonly timetoken: string; - readonly region: number; + /** + * Data center region for which `timetoken` has been generated. + * + * **Note:** This is an _optional_ value and can be set to `0` if not needed. + */ + readonly region?: number; }; diff --git a/src/node/configuration.ts b/src/node/components/configuration.ts similarity index 90% rename from src/node/configuration.ts rename to src/node/components/configuration.ts index 38a2eabc4..ee6f8731c 100644 --- a/src/node/configuration.ts +++ b/src/node/components/configuration.ts @@ -6,10 +6,10 @@ import { UserConfiguration, ExtendedConfiguration, setDefaults as setBaseDefaults, -} from '../core/interfaces/configuration'; -import { TransportKeepAlive } from '../core/interfaces/transport'; -import { Payload } from '../core/types/api'; -import { CryptoModule } from '../core/interfaces/crypto-module'; +} from '../../core/interfaces/configuration'; +import { TransportKeepAlive } from '../../core/interfaces/transport'; +import { Payload } from '../../core/types/api'; +import { ICryptoModule } from '../../core/interfaces/crypto-module'; // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -40,7 +40,7 @@ export type PubNubConfiguration = UserConfiguration & { * * @default `not set` */ - cryptoModule?: CryptoModule; + cryptoModule?: ICryptoModule; // region Deprecated parameters /** diff --git a/src/node/index.ts b/src/node/index.ts index bd988cabe..1ba9a65a2 100755 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -3,13 +3,13 @@ import CborReader from 'cbor-sync'; import { Readable } from 'stream'; import { Buffer } from 'buffer'; -import { CryptoModule, LegacyCryptor, AesCbcCryptor } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; -import type { CryptoModule as CryptoModuleType } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; +import { NodeCryptoModule, LegacyCryptor, AesCbcCryptor } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; +import type { NodeCryptoModule as CryptoModuleType } from '../crypto/modules/NodeCryptoModule/nodeCryptoModule'; import PubNubFile, { PubNubFileParameters } from '../file/modules/node'; import { CryptorConfiguration } from '../core/interfaces/crypto-module'; import { makeConfiguration } from '../core/components/configuration'; -import { PubNubConfiguration, setDefaults } from './configuration'; +import { PubNubConfiguration, setDefaults } from './components/configuration'; import { TokenManager } from '../core/components/token_manager'; import { NodeTransport } from '../transport/node-transport'; import { PubNubMiddleware } from '../transport/middleware'; @@ -31,7 +31,8 @@ class PubNub extends PubNubCore { + /** + * Create and configure PubNub client core. + * + * @param configuration - User-provided PubNub client configuration. + * + * @returns Configured and ready to use PubNub client. + */ constructor(configuration: PubNubConfiguration) { const configurationCopy = setDefaults(configuration); const platformConfiguration: ExtendedConfiguration & PlatformConfiguration = { diff --git a/src/titanium/index.ts b/src/titanium/index.ts index 008a82735..7742ae512 100644 --- a/src/titanium/index.ts +++ b/src/titanium/index.ts @@ -12,6 +12,13 @@ import Cbor from '../cbor/common'; * PubNub client for Titanium. */ export class PubNub extends PubNubCore { + /** + * Create and configure PubNub client core. + * + * @param configuration - User-provided PubNub client configuration. + * + * @returns Configured and ready to use PubNub client. + */ constructor(configuration: PubNubConfiguration) { const configurationCopy = setDefaults(configuration); const platformConfiguration = { ...configurationCopy, sdkFamily: 'TitaniumSDK' }; diff --git a/src/transport/middleware.ts b/src/transport/middleware.ts index 88114e3f8..8e67bfdc6 100644 --- a/src/transport/middleware.ts +++ b/src/transport/middleware.ts @@ -1,3 +1,9 @@ +/** + * Common PubNub Network Provider middleware module. + * + * @internal + */ + import { TransportMethod, TransportRequest } from '../core/types/transport-request'; import { PrivateClientConfiguration } from '../core/interfaces/configuration'; import { TokenManager } from '../core/components/token_manager'; @@ -7,6 +13,8 @@ import { Query } from '../core/types/api'; /** * Transport middleware configuration options. + * + * @internal */ type PubNubMiddlewareConfiguration = { /** @@ -94,6 +102,11 @@ class RequestSignature { } } +/** + * Common PubNub Network Provider middleware. + * + * @internal + */ export class PubNubMiddleware implements Transport { /** * Request signature generator. diff --git a/src/transport/node-transport.ts b/src/transport/node-transport.ts index ed6de5a44..a77a6fe7e 100644 --- a/src/transport/node-transport.ts +++ b/src/transport/node-transport.ts @@ -1,3 +1,9 @@ +/** + * Node.js Transport provider module. + * + * @internal + */ + import fetch, { Request, Response, RequestInit } from 'node-fetch'; import { ProxyAgent, ProxyAgentOptions } from 'proxy-agent'; import { Agent as HttpsAgent } from 'https'; @@ -14,20 +20,29 @@ import { queryStringFromObject } from '../core/utils'; /** * Class representing a fetch-based Node.js transport provider. + * + * @internal */ export class NodeTransport implements Transport { /** * Service {@link ArrayBuffer} response decoder. + * + * @internal */ protected static decoder = new TextDecoder(); /** * Request proxy configuration. + * + * @internal */ private proxyConfiguration?: ProxyAgentOptions; + /** @internal */ private proxyAgent?: ProxyAgent; + /** @internal */ private httpsAgent?: HttpsAgent; + /** @internal */ private httpAgent?: HttpAgent; /** @@ -38,6 +53,8 @@ export class NodeTransport implements Transport { * @param [logVerbosity] - Whether verbose logging enabled or not. * * @returns Transport for performing network requests. + * + * @internal */ constructor( private readonly keepAlive: boolean = false, @@ -49,6 +66,8 @@ export class NodeTransport implements Transport { * Update request proxy configuration. * * @param configuration - New proxy configuration. + * + * @internal */ public setProxy(configuration?: ProxyAgentOptions) { this.proxyConfiguration = configuration; @@ -119,6 +138,8 @@ export class NodeTransport implements Transport { * @param req - The {@link TransportRequest} object containing request information. * * @returns Request object generated from the {@link TransportRequest} object. + * + * @internal */ private async requestFromTransportRequest(req: TransportRequest): Promise { let headers: Record | undefined = req.headers; @@ -164,6 +185,8 @@ export class NodeTransport implements Transport { * * @returns {HttpAgent | HttpsAgent | undefined} - The appropriate agent for the request, or * undefined if keep alive or proxy not requested. + * + * @internal */ private agentForTransportRequest(req: TransportRequest): HttpAgent | HttpsAgent | undefined { // Don't configure any agents if keep alive not requested. diff --git a/src/transport/subscription-worker/subscription-worker-middleware.ts b/src/transport/subscription-worker/subscription-worker-middleware.ts index b1a08e3ec..0508adacb 100644 --- a/src/transport/subscription-worker/subscription-worker-middleware.ts +++ b/src/transport/subscription-worker/subscription-worker-middleware.ts @@ -3,6 +3,8 @@ * * Middleware optimize subscription feature requests utilizing `Subscription Worker` if available and not disabled * by user. + * + * @internal */ import { CancellationController, TransportRequest } from '../../core/types/transport-request'; diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index d520e1770..8816de9de 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -4,6 +4,8 @@ * * Service worker provides support for PubNub subscription feature to give better user experience across * multiple opened pages. + * + * @internal */ import { TransportRequest } from '../../core/types/transport-request'; diff --git a/src/transport/web-react-native-transport.ts b/src/transport/web-react-native-transport.ts index 39b8dc686..aa25688fe 100644 --- a/src/transport/web-react-native-transport.ts +++ b/src/transport/web-react-native-transport.ts @@ -1,5 +1,7 @@ /** * Common browser and React Native Transport provider module. + * + * @internal */ import { CancellationController, TransportRequest } from '../core/types/transport-request'; @@ -11,13 +13,25 @@ import { queryStringFromObject } from '../core/utils'; /** * Class representing a `fetch`-based browser and React Native transport provider. + * + * @internal */ export class WebReactNativeTransport implements Transport { /** * Service {@link ArrayBuffer} response decoder. + * + * @internal */ protected static decoder = new TextDecoder(); + /** + * Create and configure transport provider for Web and Rect environments. + * + * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. + * @param logVerbosity - Whether verbose logs should be printed or not. + * + * @internal + */ constructor( private keepAlive: boolean = false, private readonly logVerbosity: boolean, @@ -56,7 +70,10 @@ export class WebReactNativeTransport implements Transport { }, req.timeout * 1000); }); - return Promise.race([fetch(request, { signal: abortController?.signal }), requestTimeout]) + return Promise.race([ + fetch(request, { signal: abortController?.signal, credentials: 'omit', cache: 'no-cache' }), + requestTimeout, + ]) .then((response): Promise<[Response, ArrayBuffer]> | [Response, ArrayBuffer] => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer]), ) @@ -99,6 +116,8 @@ export class WebReactNativeTransport implements Transport { * @param req - The {@link TransportRequest} object containing request information. * * @returns Request object generated from the {@link TransportRequest} object. + * + * @internal */ private async requestFromTransportRequest(req: TransportRequest): Promise { let body: string | ArrayBuffer | FormData | undefined; @@ -145,6 +164,8 @@ export class WebReactNativeTransport implements Transport { * @param request - Platform-specific * @param [elapsed] - How many seconds passed since request processing started. * @param [body] - Service response (if available). + * + * @internal */ protected logRequestProcessProgress(request: Request, elapsed?: number, body?: ArrayBuffer) { if (!this.logVerbosity) return; diff --git a/src/web/components/configuration.ts b/src/web/components/configuration.ts index 06e65c335..4f0709836 100644 --- a/src/web/components/configuration.ts +++ b/src/web/components/configuration.ts @@ -3,7 +3,7 @@ import { ExtendedConfiguration, setDefaults as setBaseDefaults, } from '../../core/interfaces/configuration'; -import { CryptoModule } from '../../core/interfaces/crypto-module'; +import { ICryptoModule } from '../../core/interfaces/crypto-module'; // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -77,7 +77,7 @@ export type PubNubConfiguration = UserConfiguration & { * * @default `not set` */ - cryptoModule?: CryptoModule; + cryptoModule?: ICryptoModule; // region Deprecated parameters /** diff --git a/src/web/index.ts b/src/web/index.ts index 68993eee4..4a0c33cd4 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -35,6 +35,13 @@ export default class PubNub extends PubNubCore) { switch (changelog.type) { @@ -30,9 +32,9 @@ function logChangelog(changelog: Change) { class EventEngineSteps { private pubnub?: PubNub; - private messagePromise?: Promise; + private messagePromise?: Promise; private statusPromise?: Promise; - private presencePromise?: Promise; + private presencePromise?: Promise; private changelog: Change[] = []; private configuration: any = {}; @@ -89,7 +91,7 @@ class EventEngineSteps { }); this.statusPromise = new Promise((resolveStatus) => { - this.presencePromise = new Promise((resolvePresence) => { + this.presencePromise = new Promise((resolvePresence) => { this.pubnub?.addListener({ presence(presenceEvent) { resolvePresence(presenceEvent); @@ -170,7 +172,7 @@ class EventEngineSteps { @when('I subscribe') async whenISubscribe() { this.statusPromise = new Promise((resolveStatus) => { - this.messagePromise = new Promise((resolveMessage) => { + this.messagePromise = new Promise((resolveMessage) => { this.pubnub?.addListener({ message(messageEvent) { setTimeout(() => resolveMessage(messageEvent), 100); @@ -188,7 +190,7 @@ class EventEngineSteps { @when(/I subscribe with timetoken (\d*)/) async whenISubscribeWithTimetoken(timetoken: number) { this.statusPromise = new Promise((resolveStatus) => { - this.messagePromise = new Promise((resolveMessage) => { + this.messagePromise = new Promise((resolveMessage) => { this.pubnub?.addListener({ message(messageEvent) { setTimeout(() => resolveMessage(messageEvent), 100); diff --git a/test/contract/definitions/grant.ts b/test/contract/definitions/grant.ts index a0a655f0f..daa690422 100644 --- a/test/contract/definitions/grant.ts +++ b/test/contract/definitions/grant.ts @@ -11,17 +11,17 @@ import { } from '../shared/fixtures'; import { ResourceType, AccessPermission } from '../shared/enums'; -import { ParsedGrantToken, GrantTokenParameters } from 'pubnub'; import { exists } from '../shared/helpers'; +import { PAM } from '../../../lib/types'; @binding([PubNubManager, AccessManagerKeyset]) class GrantTokenSteps { private pubnub?: PubNub; private token?: string; - private parsedToken?: ParsedGrantToken; + private parsedToken?: PAM.Token; - private grantParams: Partial = {}; + private grantParams: Partial = {}; private resourceName?: string; private resourceType?: ResourceType; @@ -133,7 +133,7 @@ class GrantTokenSteps { public async grantToken() { exists(this.grantParams); - const params = this.grantParams as GrantTokenParameters; + const params = this.grantParams as PAM.GrantTokenParameters; const token = await this.pubnub?.grantToken(params); diff --git a/test/integration/components/crypto.test.ts b/test/integration/components/crypto.test.ts index d7373805c..073558bd8 100644 --- a/test/integration/components/crypto.test.ts +++ b/test/integration/components/crypto.test.ts @@ -25,7 +25,7 @@ describe('components/crypto useRandomIVs', () => { expect(decrypted).to.deep.equal(data, JSON.stringify(decrypted)); }); - it('should be able to encrypt and decrypt a message with CryptoModule', () => { + it('should be able to encrypt and decrypt a message with ICryptoModule', () => { const pubnub = new PubNub({ subscribeKey: 'demo-36', publishKey: 'demo-36', diff --git a/test/integration/components/reconnection_manager.test.ts b/test/integration/components/reconnection_manager.test.ts index fcf02cfbb..8dd2ca5ef 100644 --- a/test/integration/components/reconnection_manager.test.ts +++ b/test/integration/components/reconnection_manager.test.ts @@ -40,7 +40,8 @@ describe('#components/reconnection_manger', () => { clock.restore(); }); - it('reports when the network is unreachable', (done) => { + // TODO: Nock doesn't work properly with `fetch` and automated retries. + it.skip('reports when the network is unreachable', (done) => { utils .createNock() .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') @@ -85,7 +86,8 @@ describe('#components/reconnection_manger', () => { pubnub.subscribe({ channels: ['ch1', 'ch2'], withPresence: true }); }); - it('begins polling and reports reconnects when subscribe is again successful', (done) => { + // TODO: Nock doesn't work properly with `fetch` and automated retries. + it.skip('begins polling and reports reconnects when subscribe is again successful', (done) => { utils .createNock() .get('/v2/subscribe/mySubKey/ch1,ch1-pnpres,ch2,ch2-pnpres/0') diff --git a/test/integration/components/subscription_manager.test.ts b/test/integration/components/subscription_manager.test.ts index d68c554f5..802690bf6 100644 --- a/test/integration/components/subscription_manager.test.ts +++ b/test/integration/components/subscription_manager.test.ts @@ -10,6 +10,7 @@ import utils from '../../utils'; describe('#components/subscription_manager', () => { let pubnub: PubNub; + let pubnubWithLimitedDeduplicationQueue: PubNub; let pubnubWithPassingHeartbeats: PubNub; let pubnubWithLimitedQueue: PubNub; let pubnubWithCrypto: PubNub; @@ -34,6 +35,18 @@ describe('#components/subscription_manager', () => { autoNetworkDetection: false, heartbeatInterval: 149, }); + pubnubWithLimitedDeduplicationQueue = new PubNub({ + subscribeKey: 'mySubKey', + publishKey: 'myPublishKey', + origin: 'ps.pndsn.com', + uuid: 'myUUID', + // @ts-expect-error Force override default value. + useRequestId: false, + autoNetworkDetection: false, + maximumCacheSize: 1, + dedupeOnSubscribe: true, + heartbeatInterval: 149, + }); pubnubWithPassingHeartbeats = new PubNub({ subscribeKey: 'mySubKey', publishKey: 'myPublishKey', @@ -69,6 +82,7 @@ describe('#components/subscription_manager', () => { afterEach(() => { pubnub.stop(); + pubnubWithLimitedDeduplicationQueue.stop(); pubnubWithPassingHeartbeats.stop(); pubnubWithLimitedQueue.stop(); }); @@ -703,10 +717,6 @@ describe('#components/subscription_manager', () => { }); it('supports deduping on shallow queue', (done) => { - // @ts-expect-error: This configuration option normally is hidden. - pubnub._config.dedupeOnSubscribe = true; - // @ts-expect-error: This configuration option normally is hidden. - pubnub._config.maximumCacheSize = 1; let messageCount = 0; utils @@ -739,13 +749,13 @@ describe('#components/subscription_manager', () => { { 'content-type': 'text/javascript' }, ); - pubnub.addListener({ + pubnubWithLimitedDeduplicationQueue.addListener({ message() { messageCount += 1; }, }); - pubnub.subscribe({ channels: ['ch1', 'ch2'], withPresence: true }); + pubnubWithLimitedDeduplicationQueue.subscribe({ channels: ['ch1', 'ch2'], withPresence: true }); setTimeout(() => { if (messageCount === 4) { diff --git a/test/utils.ts b/test/utils.ts index cce634f9f..34f6bb475 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -47,8 +47,8 @@ export default { let promisesResult = Promise.resolve(); for (let delayIdx = 0; delayIdx < delays.length; delayIdx += 1) { - let previousDelay = delayIdx > 0 ? delays[delayIdx - 1] : 0; - let delay = delays[delayIdx]; + const previousDelay = delayIdx > 0 ? delays[delayIdx - 1] : 0; + const delay = delays[delayIdx]; promisesResult = promisesResult.then(() => callAPIWithDelayedResponse(previousDelay, delay)) as Promise; } diff --git a/tsconfig.json b/tsconfig.json index 2d6f18753..a8cf9e0c7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,7 +12,7 @@ "downlevelIteration": true, "declaration": true, "declarationDir": "./lib/types", - "stripInternal": true + "stripInternal": true, }, "include": [ "src/**/*" @@ -22,10 +22,10 @@ "src/crypto/modules/WebCryptoModule/**/*", "src/crypto/modules/web.ts", "src/file/modules/web.ts", - "src/nativescript/**/*", - "src/titanium/**/*", "src/transport/subscription-worker/**/*", "src/transport/titanium-transport.ts", + "src/nativescript/**/*", + "src/titanium/**/*", "src/web/**/*" ] } \ No newline at end of file From 2b523b2bb704cb88c7b0fb461b4e5ed7b53c2828 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 14 Nov 2024 17:48:05 +0200 Subject: [PATCH 25/49] Add custom message type support (#418) feat(message-type): add custom message type support Add custom message type support for the following APIs: publish, signal, share file, subscribe and history. --- .pubnub.yml | 11 ++- CHANGELOG.md | 6 ++ README.md | 4 +- dist/web/pubnub.js | 37 ++++++---- dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/core/endpoints/fetch_messages.js | 14 ++-- .../endpoints/file_upload/publish_file.js | 4 +- lib/core/endpoints/publish.js | 4 +- lib/core/endpoints/signal.js | 7 ++ lib/core/endpoints/subscribe.js | 6 ++ lib/types/index.d.ts | 39 +++++++++++ package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/endpoints/fetch_messages.ts | 20 +++++- .../endpoints/file_upload/publish_file.ts | 3 +- src/core/endpoints/publish.ts | 11 ++- src/core/endpoints/signal.ts | 17 +++++ src/core/endpoints/subscribe.ts | 7 +- src/core/types/api/file-sharing.ts | 8 +++ src/core/types/api/history.ts | 17 +++++ src/core/types/api/subscription.ts | 5 ++ .../endpoints/fetch_messages.test.ts | 43 ++++++++++-- test/integration/endpoints/history.test.ts | 32 ++++----- test/integration/endpoints/publish.test.ts | 69 ++++++++++++++----- test/integration/endpoints/signal.test.ts | 28 ++++++++ test/integration/endpoints/subscribe.test.ts | 54 ++++++++++++++- 27 files changed, 372 insertions(+), 84 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 057604ff3..6f6b2b734 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-11-14 + version: v8.3.0 + changes: + - type: feature + text: "Add custom message type support for the following APIs: publish, signal, share file, subscribe and history." - date: 2024-10-31 version: v8.2.10 changes: @@ -1062,7 +1067,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.2.10' +version: '8.3.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1078,7 +1083,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.2.10.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.3.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1749,7 +1754,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.2.10/pubnub.8.2.10.js + location: https://github.com/pubnub/javascript/releases/download/v8.3.0/pubnub.8.3.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index fd6e4f017..b2656bc3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.3.0 +November 14 2024 + +#### Added +- Add custom message type support for the following APIs: publish, signal, share file, subscribe and history. + ## v8.2.10 October 31 2024 diff --git a/README.md b/README.md index 06e26471e..031c6e8d0 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.10.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.2.10.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index b1a1ebfc0..d828d6b6f 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3948,7 +3948,7 @@ return base.PubNubFile; }, get version() { - return '8.2.10'; + return '8.3.0'; }, getVersion() { return this.version; @@ -6230,6 +6230,8 @@ }; if (envelope.u) event.userMetadata = envelope.u; + if (envelope.cmt) + event.customMessageType = envelope.cmt; if (decryptionError) event.error = decryptionError; return event; @@ -6245,6 +6247,8 @@ }; if (envelope.u) event.userMetadata = envelope.u; + if (envelope.cmt) + event.customMessageType = envelope.cmt; return event; } messageActionFromEnvelope(envelope) { @@ -6296,6 +6300,8 @@ }; } } + if (envelope.cmt) + event.customMessageType = envelope.cmt; if (errorMessage) event.error = errorMessage; return event; @@ -8303,8 +8309,10 @@ return `/publish/${keySet.publishKey}/${keySet.subscribeKey}/0/${encodeString(channel)}/0${!this.parameters.sendByPost ? `/${encodeString(stringifiedPayload)}` : ''}`; } get queryParameters() { - const { meta, replicate, storeInHistory, ttl } = this.parameters; + const { customMessageType, meta, replicate, storeInHistory, ttl } = this.parameters; const query = {}; + if (customMessageType) + query.custom_message_type = customMessageType; if (storeInHistory !== undefined) query.store = storeInHistory ? '1' : '0'; if (ttl !== undefined) @@ -8380,6 +8388,13 @@ const stringifiedPayload = JSON.stringify(message); return `/signal/${publishKey}/${subscribeKey}/0/${encodeString(channel)}/0/${encodeString(stringifiedPayload)}`; } + get queryParameters() { + const { customMessageType } = this.parameters; + const query = {}; + if (customMessageType) + query.custom_message_type = customMessageType; + return query; + } } /** @@ -9151,13 +9166,7 @@ if (payload.message_type === null) payload.message_type = PubNubMessageType.Message; const processedPayload = this.processPayload(channel, payload); - const item = { - channel, - timetoken: payload.timetoken, - message: processedPayload.payload, - messageType: payload.message_type, - uuid: payload.uuid, - }; + const item = Object.assign(Object.assign({ channel, timetoken: payload.timetoken, message: processedPayload.payload, messageType: payload.message_type }, (payload.custom_message_type ? { customMessageType: payload.custom_message_type } : {})), { uuid: payload.uuid }); if (payload.actions) { const itemWithActions = item; itemWithActions.actions = payload.actions; @@ -9183,8 +9192,10 @@ return `/v3/${endpoint}/sub-key/${subscribeKey}/channel/${encodeNames(channels)}`; } get queryParameters() { - const { start, end, count, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken } = this.parameters; - return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeMessageType ? { include_message_type: 'true' } : {})); + const { start, end, count, includeCustomMessageType, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken, } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeCustomMessageType !== undefined && includeCustomMessageType !== null + ? { include_custom_message_type: includeCustomMessageType ? 'true' : 'false' } + : {})), (includeMessageType ? { include_message_type: 'true' } : {})); } /** * Parse single channel data entry. @@ -9461,8 +9472,8 @@ return `/v1/files/publish-file/${publishKey}/${subscribeKey}/0/${encodeString(channel)}/0/${encodeString(this.prepareMessagePayload(fileMessage))}`; } get queryParameters() { - const { storeInHistory, ttl, meta } = this.parameters; - return Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {})); + const { customMessageType, storeInHistory, ttl, meta } = this.parameters; + return Object.assign(Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (customMessageType ? { custom_message_type: customMessageType } : {})), (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {})); } /** * Pre-process provided data. diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 212067905..d84bb0780 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new A(s,t,0);if(e instanceof A)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new A(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new A(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class _{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new A(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},R=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},U=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class T{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw A.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw A.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?T.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?F(a):a})),n}T.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.2.10"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),Ae=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),_e=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(Ae.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(_e.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Fe=new ue("HEARTBEAT_COOLDOWN");Fe.onEnter((()=>Ie())),Fe.onExit((()=>Ie.cancel)),Fe.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[_e(t.payload.channels,t.payload.groups)]))),Fe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[_e(e.channels,e.groups)]))),Fe.on(Oe.type,((e,t)=>Ge.with(void 0,[_e(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[_e(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[_e(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[_e(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[_e(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[_e(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[_e(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>Ae(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[_e(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[_e(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[_e(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=R(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=R(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{meta:e,replicate:t,storeInHistory:s,ttl:n}=this.parameters,r={};return void 0!==s&&(r.store=s?"1":"0"),void 0!==n&&(r.ttl=n),void 0===t||t||(r.norep="true"),e&&"object"==typeof e&&(r.meta=JSON.stringify(e)),r}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class _t extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw A.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Tt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw A.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n={channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type,uuid:t.uuid};if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeMessageType:n,includeMeta:r,includeUUID:i,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==r&&r?{include_meta:"true"}:{}),i?{include_uuid:"true"}:{}),n?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{storeInHistory:e,ttl:t,meta:s}=this.parameters;return Object.assign(Object.assign({store:e?"1":"0"},t?{ttl:t}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Wt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Wt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw A.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof A?s:A.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new At({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof A&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>F(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new T(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new _({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},R=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},U=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class T{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?T.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?F(a):a})),n}T.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.3.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Fe=new ue("HEARTBEAT_COOLDOWN");Fe.onEnter((()=>Ie())),Fe.onExit((()=>Ie.cancel)),Fe.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Fe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Fe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=R(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=R(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Tt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Wt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Wt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>F(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new T(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index c0371ae2b..4b4748a7d 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -112,7 +112,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.2.10'; + return '8.3.0'; }, getVersion() { return this.version; diff --git a/lib/core/endpoints/fetch_messages.js b/lib/core/endpoints/fetch_messages.js index be7dc5327..758894a70 100644 --- a/lib/core/endpoints/fetch_messages.js +++ b/lib/core/endpoints/fetch_messages.js @@ -135,13 +135,7 @@ class FetchMessagesRequest extends request_1.AbstractRequest { if (payload.message_type === null) payload.message_type = History.PubNubMessageType.Message; const processedPayload = this.processPayload(channel, payload); - const item = { - channel, - timetoken: payload.timetoken, - message: processedPayload.payload, - messageType: payload.message_type, - uuid: payload.uuid, - }; + const item = Object.assign(Object.assign({ channel, timetoken: payload.timetoken, message: processedPayload.payload, messageType: payload.message_type }, (payload.custom_message_type ? { customMessageType: payload.custom_message_type } : {})), { uuid: payload.uuid }); if (payload.actions) { const itemWithActions = item; itemWithActions.actions = payload.actions; @@ -167,8 +161,10 @@ class FetchMessagesRequest extends request_1.AbstractRequest { return `/v3/${endpoint}/sub-key/${subscribeKey}/channel/${(0, utils_1.encodeNames)(channels)}`; } get queryParameters() { - const { start, end, count, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken } = this.parameters; - return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeMessageType ? { include_message_type: 'true' } : {})); + const { start, end, count, includeCustomMessageType, includeMessageType, includeMeta, includeUUID, stringifiedTimeToken, } = this.parameters; + return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ max: count }, (start ? { start } : {})), (end ? { end } : {})), (stringifiedTimeToken ? { string_message_token: 'true' } : {})), (includeMeta !== undefined && includeMeta ? { include_meta: 'true' } : {})), (includeUUID ? { include_uuid: 'true' } : {})), (includeCustomMessageType !== undefined && includeCustomMessageType !== null + ? { include_custom_message_type: includeCustomMessageType ? 'true' : 'false' } + : {})), (includeMessageType ? { include_message_type: 'true' } : {})); } /** * Parse single channel data entry. diff --git a/lib/core/endpoints/file_upload/publish_file.js b/lib/core/endpoints/file_upload/publish_file.js index 81e3e07fe..82af6dc76 100644 --- a/lib/core/endpoints/file_upload/publish_file.js +++ b/lib/core/endpoints/file_upload/publish_file.js @@ -75,8 +75,8 @@ class PublishFileMessageRequest extends request_1.AbstractRequest { return `/v1/files/publish-file/${publishKey}/${subscribeKey}/0/${(0, utils_1.encodeString)(channel)}/0/${(0, utils_1.encodeString)(this.prepareMessagePayload(fileMessage))}`; } get queryParameters() { - const { storeInHistory, ttl, meta } = this.parameters; - return Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {})); + const { customMessageType, storeInHistory, ttl, meta } = this.parameters; + return Object.assign(Object.assign(Object.assign({ store: storeInHistory ? '1' : '0' }, (customMessageType ? { custom_message_type: customMessageType } : {})), (ttl ? { ttl } : {})), (meta && typeof meta === 'object' ? { meta: JSON.stringify(meta) } : {})); } /** * Pre-process provided data. diff --git a/lib/core/endpoints/publish.js b/lib/core/endpoints/publish.js index 1a38b0aa9..3cdedc0a8 100644 --- a/lib/core/endpoints/publish.js +++ b/lib/core/endpoints/publish.js @@ -79,8 +79,10 @@ class PublishRequest extends request_1.AbstractRequest { return `/publish/${keySet.publishKey}/${keySet.subscribeKey}/0/${(0, utils_1.encodeString)(channel)}/0${!this.parameters.sendByPost ? `/${(0, utils_1.encodeString)(stringifiedPayload)}` : ''}`; } get queryParameters() { - const { meta, replicate, storeInHistory, ttl } = this.parameters; + const { customMessageType, meta, replicate, storeInHistory, ttl } = this.parameters; const query = {}; + if (customMessageType) + query.custom_message_type = customMessageType; if (storeInHistory !== undefined) query.store = storeInHistory ? '1' : '0'; if (ttl !== undefined) diff --git a/lib/core/endpoints/signal.js b/lib/core/endpoints/signal.js index e3e5ea344..a6f34181e 100644 --- a/lib/core/endpoints/signal.js +++ b/lib/core/endpoints/signal.js @@ -56,5 +56,12 @@ class SignalRequest extends request_1.AbstractRequest { const stringifiedPayload = JSON.stringify(message); return `/signal/${publishKey}/${subscribeKey}/0/${(0, utils_1.encodeString)(channel)}/0/${(0, utils_1.encodeString)(stringifiedPayload)}`; } + get queryParameters() { + const { customMessageType } = this.parameters; + const query = {}; + if (customMessageType) + query.custom_message_type = customMessageType; + return query; + } } exports.SignalRequest = SignalRequest; diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index bb2d2e4c7..76f06c2a3 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -216,6 +216,8 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { }; if (envelope.u) event.userMetadata = envelope.u; + if (envelope.cmt) + event.customMessageType = envelope.cmt; if (decryptionError) event.error = decryptionError; return event; @@ -231,6 +233,8 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { }; if (envelope.u) event.userMetadata = envelope.u; + if (envelope.cmt) + event.customMessageType = envelope.cmt; return event; } messageActionFromEnvelope(envelope) { @@ -282,6 +286,8 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { }; } } + if (envelope.cmt) + event.customMessageType = envelope.cmt; if (errorMessage) event.error = errorMessage; return event; diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index d8439d47a..470eb773d 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -4764,6 +4764,10 @@ declare namespace PubNub { userMetadata?: { [p: string]: Payload; }; + /** + * User-provided message type. + */ + customMessageType?: string; /** * Sent data. */ @@ -6086,6 +6090,13 @@ declare namespace PubNub { * The message may be any valid JSON type including objects, arrays, strings, and numbers. */ message: Payload; + /** + * User-specified message type. + * + * **Important:** string limited by **3**-**50** case-sensitive alphanumeric characters with only + * `-` and `_` special characters allowed. + */ + customMessageType?: string; /** * Whether published data should be available with `Storage API` later or not. * @@ -6150,6 +6161,13 @@ declare namespace PubNub { * The message may be any valid JSON type including objects, arrays, strings, and numbers. */ message: Payload; + /** + * User-specified message type. + * + * **Important:** string limited by **3**-**50** case-sensitive alphanumeric characters with only + * `-` and `_` special characters allowed. + */ + customMessageType?: string; }; /** @@ -6566,6 +6584,10 @@ declare namespace PubNub { * PubNub-defined message type. */ messageType?: PubNubMessageType.Message; + /** + * User-provided message type. + */ + customMessageType?: string; }; /** @@ -6610,6 +6632,10 @@ declare namespace PubNub { * PubNub-defined message type. */ messageType?: PubNubMessageType.Files; + /** + * User-provided message type. + */ + customMessageType?: string; }; /** @@ -6652,6 +6678,12 @@ declare namespace PubNub { * @default `100` or `25` */ count?: number; + /** + * Include messages' custom type flag. + * + * Message / signal and file messages may contain user-provided type. + */ + includeCustomMessageType?: boolean; /** * Whether message type should be returned with each history message or not. * @@ -7194,6 +7226,13 @@ declare namespace PubNub { * File annotation message. */ message?: Payload; + /** + * User-specified message type. + * + * **Important:** string limited by **3**-**50** case-sensitive alphanumeric characters with only + * `-` and `_` special characters allowed. + */ + customMessageType?: string; /** * Custom file and message encryption key. * diff --git a/package.json b/package.json index fa8f4ecaf..3be93b13f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.2.10", + "version": "8.3.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 7e70f92ae..385ddef16 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -171,7 +171,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.2.10'; + return '8.3.0'; }, getVersion(): string { return this.version; diff --git a/src/core/endpoints/fetch_messages.ts b/src/core/endpoints/fetch_messages.ts index 0b42fd62c..0ec208996 100644 --- a/src/core/endpoints/fetch_messages.ts +++ b/src/core/endpoints/fetch_messages.ts @@ -127,6 +127,11 @@ type ServiceResponse = { */ uuid?: string; + /** + * User-provided message type. + */ + custom_message_type?: string; + /** * PubNub-defined message type. */ @@ -232,6 +237,7 @@ export class FetchMessagesRequest extends AbstractRequest { } protected get queryParameters(): Query { - const { meta, replicate, storeInHistory, ttl } = this.parameters; + const { customMessageType, meta, replicate, storeInHistory, ttl } = this.parameters; const query: Query = {}; + if (customMessageType) query.custom_message_type = customMessageType; if (storeInHistory !== undefined) query.store = storeInHistory ? '1' : '0'; if (ttl !== undefined) query.ttl = ttl; if (replicate !== undefined && !replicate) query.norep = 'true'; diff --git a/src/core/endpoints/signal.ts b/src/core/endpoints/signal.ts index 942989251..7015c17ae 100644 --- a/src/core/endpoints/signal.ts +++ b/src/core/endpoints/signal.ts @@ -29,6 +29,14 @@ export type SignalParameters = { * The message may be any valid JSON type including objects, arrays, strings, and numbers. */ message: Payload; + + /** + * User-specified message type. + * + * **Important:** string limited by **3**-**50** case-sensitive alphanumeric characters with only + * `-` and `_` special characters allowed. + */ + customMessageType?: string; }; /** @@ -105,4 +113,13 @@ export class SignalRequest extends AbstractRequest { return `/signal/${publishKey}/${subscribeKey}/0/${encodeString(channel)}/0/${encodeString(stringifiedPayload)}`; } + + protected get queryParameters(): Query { + const { customMessageType } = this.parameters; + const query: Query = {}; + + if (customMessageType) query.custom_message_type = customMessageType; + + return query; + } } diff --git a/src/core/endpoints/subscribe.ts b/src/core/endpoints/subscribe.ts index f01062176..9033c9374 100644 --- a/src/core/endpoints/subscribe.ts +++ b/src/core/endpoints/subscribe.ts @@ -488,9 +488,9 @@ type Envelope = { u?: { [p: string]: Payload }; /** - * User provided message type (set only when `publish` called with `type`). + * User-provided message type (set only when `publish` called with `type`). */ - mt?: string; + cmt?: string; /** * Identifier of space into which message has been published (set only when `publish` called @@ -739,6 +739,7 @@ export class BaseSubscribeRequest extends AbstractRequest void, ) { let messages: { message: TestMessage; timetoken: string }[] = []; let publishCompleted = 0; const publish = (messageIdx: number) => { - let payload: { channel: string; message: TestMessage; meta?: Payload } = { + const payload: Publish.PublishParameters = { message: { messageIdx: [channel, messageIdx].join(': '), time: Date.now() }, channel, }; - if (messageIdx % 2 === 0) payload.meta = { time: payload.message.time }; + if (customMessageType.length) payload.customMessageType = customMessageType; + if (messageIdx % 2 === 0) payload.meta = { time: (payload.message as TestMessage).time }; client.publish(payload, (status, response) => { publishCompleted += 1; if (!status.error && response) { - messages.push({ message: payload.message, timetoken: response.timetoken }); + messages.push({ message: payload.message as TestMessage, timetoken: response.timetoken }); messages = messages.sort((left, right) => parseInt(left.timetoken, 10) - parseInt(right.timetoken, 10)); } else { console.error('Publish did fail:', status); @@ -91,7 +96,7 @@ function addActionsInChannel( PubNub.generateUUID(), ]; let actions: MessageActions.MessageAction[] = []; - let actionsToAdd: { + const actionsToAdd: { messageTimetoken: string; action: Pick; }[] = []; @@ -317,7 +322,7 @@ describe('fetch messages endpoints', () => { const channel = PubNub.generateUUID(); const expectedMessagesCount = 10; - publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { + publishMessagesToChannel(pubnub, expectedMessagesCount, channel, '', (messages) => { pubnub.fetchMessages({ channels: [channel], count: 25, includeMeta: true }, (_, response) => { try { assert(response !== null); @@ -350,12 +355,36 @@ describe('fetch messages endpoints', () => { assert(errorCatched); }); + it.only('supports custom message type', (done) => { + const channel = PubNub.generateUUID(); + const expectedMessagesCount = 2; + + publishMessagesToChannel(pubnub, expectedMessagesCount, channel, 'test-message-type', (messages) => { + const messageTimetokens = messages.map((message) => message.timetoken); + + pubnub.fetchMessages({ channels: [channel], includeCustomMessageType: true }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + const fetchedMessages = response.channels[channel]; + fetchedMessages.forEach((message) => { + assert.equal(message.customMessageType, 'test-message-type'); + }); + + done(); + } catch (error) { + done(error); + } + }); + }); + }).timeout(60000); + it("supports actions (stored as 'data' field)", (done) => { const channel = PubNub.generateUUID(); const expectedMessagesCount = 2; const expectedActionsCount = 4; - publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { + publishMessagesToChannel(pubnub, expectedMessagesCount, channel, '', (messages) => { const messageTimetokens = messages.map((message) => message.timetoken); addActionsInChannel(pubnub, expectedActionsCount, messageTimetokens, channel, (actions) => { @@ -405,7 +434,7 @@ describe('fetch messages endpoints', () => { const expectedMessagesCount = 2; const expectedActionsCount = 4; - publishMessagesToChannel(pubnub, expectedMessagesCount, channel, (messages) => { + publishMessagesToChannel(pubnub, expectedMessagesCount, channel, '', (messages) => { const messageTimetokens = messages.map((message) => message.timetoken); addActionsInChannel(pubnub, expectedActionsCount, messageTimetokens, channel, (actions) => { diff --git a/test/integration/endpoints/history.test.ts b/test/integration/endpoints/history.test.ts index d2d55a111..8f879c7c5 100644 --- a/test/integration/endpoints/history.test.ts +++ b/test/integration/endpoints/history.test.ts @@ -31,7 +31,7 @@ function publishMessagesToChannel( let publishCompleted = 0; const publish = (messageIdx: number) => { - let payload: { channel: string; message: TestMessage; meta?: Payload } = { + const payload: { channel: string; message: TestMessage; meta?: Payload } = { message: { messageIdx: [channel, messageIdx].join(': '), time: Date.now() }, channel, }; @@ -109,11 +109,11 @@ describe('history endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.startTimeToken, "14648503433058358"); - assert.deepEqual(response.endTimeToken, "14649346364851578"); + assert.deepEqual(response.startTimeToken, '14648503433058358'); + assert.deepEqual(response.endTimeToken, '14649346364851578'); assert.deepEqual(response.messages, [ - { timetoken: "14648503433058358", entry: { text: "hey" } }, - { timetoken: "14648503433058359", entry: { text2: "hey2" } } + { timetoken: '14648503433058358', entry: { text: 'hey' } }, + { timetoken: '14648503433058359', entry: { text2: 'hey2' } }, ]); assert.equal(scope.isDone(), true); done(); @@ -146,11 +146,11 @@ describe('history endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.startTimeToken, "14649369736959785"); - assert.deepEqual(response.endTimeToken, "14649369766426772"); + assert.deepEqual(response.startTimeToken, '14649369736959785'); + assert.deepEqual(response.endTimeToken, '14649369766426772'); assert.deepEqual(response.messages, [ - { timetoken: "14649369736959785", entry: { text: "hey" } }, - { timetoken: "14649369766426772", entry: { text2: "hey2" } } + { timetoken: '14649369736959785', entry: { text: 'hey' } }, + { timetoken: '14649369766426772', entry: { text2: 'hey2' } }, ]); assert.equal(scope.isDone(), true); done(); @@ -200,15 +200,15 @@ describe('history endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.startTimeToken, "14648503433058358"); - assert.deepEqual(response.endTimeToken, "14649346364851578"); + assert.deepEqual(response.startTimeToken, '14648503433058358'); + assert.deepEqual(response.endTimeToken, '14649346364851578'); assert.deepEqual(response.messages, [ - { timetoken: "14648503433058358", entry: { text: "hey" } }, + { timetoken: '14648503433058358', entry: { text: 'hey' } }, { - timetoken: "14648503433058359", - entry: "hello", - error: "Error while decrypting message content: Decryption error: invalid header version" - } + timetoken: '14648503433058359', + entry: 'hello', + error: 'Error while decrypting message content: Decryption error: invalid header version', + }, ]); assert.equal(scope.isDone(), true); done(); diff --git a/test/integration/endpoints/publish.test.ts b/test/integration/endpoints/publish.test.ts index cc113b55b..ed818b867 100644 --- a/test/integration/endpoints/publish.test.ts +++ b/test/integration/endpoints/publish.test.ts @@ -59,20 +59,24 @@ describe('publish endpoints', () => { pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', auth: 'myAuthKey', + custom_message_type: 'test-message-type', }) .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); - pubnub.publish({ message: { such: 'object' }, channel: 'ch1' }, (status, response) => { - try { - assert.equal(status.error, false); - assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); - assert.equal(scope.isDone(), true); - done(); - } catch (error) { - done(error); - } - }); + pubnub.publish( + { message: { such: 'object' }, customMessageType: 'test-message-type', channel: 'ch1' }, + (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, '14647523059145592'); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); }); it('publishes without replication via GET', (done) => { @@ -91,7 +95,7 @@ describe('publish endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); + assert.deepEqual(response.timetoken, '14647523059145592'); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -117,7 +121,7 @@ describe('publish endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); + assert.deepEqual(response.timetoken, '14647523059145592'); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -143,7 +147,7 @@ describe('publish endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); + assert.deepEqual(response.timetoken, '14647523059145592'); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -170,7 +174,7 @@ describe('publish endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); + assert.deepEqual(response.timetoken, '14647523059145592'); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -197,7 +201,34 @@ describe('publish endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); + assert.deepEqual(response.timetoken, '14647523059145592'); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }); + }); + + it('supports customMessageType', (done) => { + const scope = utils + .createNock() + .get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + store: '0', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.setCipherKey('myCipherKey'); + + pubnub.publish({ message: { such: 'object' }, channel: 'ch1', storeInHistory: false }, (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, '14647523059145592'); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -221,7 +252,7 @@ describe('publish endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); + assert.deepEqual(response.timetoken, '14647523059145592'); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -247,7 +278,7 @@ describe('publish endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); + assert.deepEqual(response.timetoken, '14647523059145592'); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -274,7 +305,7 @@ describe('publish endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14647523059145592"); + assert.deepEqual(response.timetoken, '14647523059145592'); assert.equal(scope.isDone(), true); done(); } catch (error) { diff --git a/test/integration/endpoints/signal.test.ts b/test/integration/endpoints/signal.test.ts index 74e56d6c4..c5c343599 100644 --- a/test/integration/endpoints/signal.test.ts +++ b/test/integration/endpoints/signal.test.ts @@ -70,6 +70,34 @@ describe('signal endpoints', () => { }); }); + it('send signal with custom message type', (done) => { + const scope = utils + .createNock() + .get('/signal/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + auth: 'myAuthKey', + custom_message_type: 'test-message-type', + }) + .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); + + pubnub.signal( + { message: { such: 'object' }, customMessageType: 'test-message-type', channel: 'ch1' }, + (status, response) => { + try { + assert.equal(status.error, false); + assert(response !== null); + assert.deepEqual(response.timetoken, '14647523059145592'); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); + }); + it('send signal and signal listener called', (done) => { const scope = utils .createNock() diff --git a/test/integration/endpoints/subscribe.test.ts b/test/integration/endpoints/subscribe.test.ts index f28330e50..b3bf5cc5a 100644 --- a/test/integration/endpoints/subscribe.test.ts +++ b/test/integration/endpoints/subscribe.test.ts @@ -229,13 +229,14 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"146075779609322","r":1},"m":[{"a":"4","f":0,"i":"test","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"c1","d":{"text":"customttresponse"},"b":"c1"}]}', + '{"t":{"t":"146075779609322","r":1},"m":[{"a":"4","f":0,"cmt":"test-message-type","i":"test","p":{"t":"14607577960925503","r":1},"k":"mySubKey","c":"c1","d":{"text":"customttresponse"},"b":"c1"}]}', { 'content-type': 'text/javascript' }, ); pubnubWithEE.addListener({ message(message) { try { + assert.equal(message.customMessageType, 'test-message-type'); assert.deepEqual(message.message, { text: 'customttresponse' }); assert.equal(scope.isDone(), true); done(); @@ -272,13 +273,62 @@ describe('subscribe endpoints', () => { }) .reply( 200, - '{"t":{"t":"14523669555221453","r":1},"m":[{"a":"3","f":0,"e":1,"i":"myUniqueUserId","p":{"t":"17200339136465528","r":41},"k":"mySubKey","c":"c1","d":"typing:start"}]}', + '{"t":{"t":"14523669555221453","r":1},"m":[{"a":"3","f":0,"e":1,"cmt":"test-message-type","i":"myUniqueUserId","p":{"t":"17200339136465528","r":41},"k":"mySubKey","c":"c1","d":"typing:start"}]}', { 'content-type': 'text/javascript' }, ); pubnubWithEE.addListener({ signal(signal) { try { + assert.equal(signal.customMessageType, 'test-message-type'); + done(); + } catch (error) { + done(error); + } + }, + }); + + const channel = pubnubWithEE.channel('c1'); + const subscription = channel.subscription(); + subscription.subscribe(); + }); + + it('file listener called for shared file', (done) => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/c1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: 0, + }) + .reply(200, '{"t":{"t":"14523669555221452","r":1},"m":[]}', { 'content-type': 'text/javascript' }); + utils + .createNock() + .get('/v2/subscribe/mySubKey/c1/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + ee: '', + tt: '14523669555221452', + tr: 1, + }) + .reply( + 200, + '{"t":{"t":"14523669555221453","r":1},"m":[{"a":"3","f":0,"e":4,"cmt":"test-message-type","i":"myUniqueUserId","p":{"t":"17200339136465528","r":41},"k":"mySubKey","c":"c1","d":{"message":"Hello","file":{"id":"file-id","name":"file-name"}}}]}', + { 'content-type': 'text/javascript' }, + ); + + pubnubWithEE.addListener({ + file(sharedFile) { + try { + assert.equal(sharedFile.customMessageType, 'test-message-type'); + assert.equal(sharedFile.message, 'Hello'); + assert.notEqual(sharedFile.file, undefined); + assert(sharedFile.file !== undefined); + assert.equal(sharedFile.file.id, 'file-id'); + assert.equal(sharedFile.file.name, 'file-name'); done(); } catch (error) { done(error); From cf5aa71f8164f097566d788e403be38f7af02431 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Mon, 18 Nov 2024 16:56:51 +0200 Subject: [PATCH 26/49] Fix missing presence events on subscription (#419) fix(event-engine): fix missing presence events on subscription Fix issue because of which presence events not delivered to the `Subscription` and `SubscriptionSet` objects (only global listeners). --- .pubnub.yml | 11 +++++-- CHANGELOG.md | 6 ++++ README.md | 4 +-- dist/web/pubnub.js | 21 ++++++++----- dist/web/pubnub.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/components/eventEmitter.js | 3 +- lib/entities/Channel.js | 5 +++- lib/entities/ChannelGroup.js | 5 +++- lib/entities/SubscribeCapable.js | 2 +- lib/entities/Subscription.js | 2 +- lib/entities/SubscriptionSet.js | 2 +- package-lock.json | 6 ++-- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/components/eventEmitter.ts | 2 +- src/entities/Channel.ts | 6 +++- src/entities/ChannelGroup.ts | 6 +++- src/entities/SubscribeCapable.ts | 6 +--- src/entities/Subscription.ts | 6 +--- src/entities/SubscriptionSet.ts | 6 +--- .../endpoints/fetch_messages.test.ts | 4 ++- test/integration/endpoints/publish.test.ts | 30 ++++++++++--------- 23 files changed, 83 insertions(+), 58 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 6f6b2b734..dad178d21 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2024-11-18 + version: v8.3.1 + changes: + - type: bug + text: "Fix issue because of which presence events not delivered to the `Subscription` and `SubscriptionSet` objects (only global listeners)." - date: 2024-11-14 version: v8.3.0 changes: @@ -1067,7 +1072,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.3.0' +version: '8.3.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1083,7 +1088,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.3.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.3.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1754,7 +1759,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.3.0/pubnub.8.3.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.3.1/pubnub.8.3.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index b2656bc3e..24a5ef0f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.3.1 +November 18 2024 + +#### Fixed +- Fix issue because of which presence events not delivered to the `Subscription` and `SubscriptionSet` objects (only global listeners). + ## v8.3.0 November 14 2024 diff --git a/README.md b/README.md index 031c6e8d0..ec506a28c 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index d828d6b6f..94fd00418 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3948,7 +3948,7 @@ return base.PubNubFile; }, get version() { - return '8.3.0'; + return '8.3.1'; }, getVersion() { return this.version; @@ -6403,6 +6403,7 @@ * @param event - Received real-time event. */ emitEvent(event) { + var _a; if (event.type === PubNubEventType.Message) { this.listenerManager.announceMessage(event.data); this.announce('message', event.data, event.data.channel, event.data.subscription); @@ -6413,7 +6414,7 @@ } else if (event.type === PubNubEventType.Presence) { this.listenerManager.announcePresence(event.data); - this.announce('presence', event.data, event.data.channel, event.data.subscription); + this.announce('presence', event.data, (_a = event.data.subscription) !== null && _a !== void 0 ? _a : event.data.channel, event.data.subscription); } else if (event.type === PubNubEventType.AppContext) { const { data: objectEvent } = event; @@ -9963,7 +9964,7 @@ * types of events. */ addListener(listener) { - this.eventEmitter.addListener(listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + this.eventEmitter.addListener(listener, this.channelNames, this.groupNames); } /** * Remove events handler. @@ -10065,7 +10066,7 @@ this.subscriptionList.push(subscription); }); this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); } /** * Add additional entity's subscription to the subscription set. @@ -10187,7 +10188,7 @@ this.pubnub = pubnub; this.eventEmitter = eventEmitter; this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); } /** * Merge entities' subscription objects into subscription set. @@ -10283,9 +10284,12 @@ */ subscription(subscriptionOptions) { { + const channelGroups = [this.name]; + if ((subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) && !this.name.endsWith('-pnpres')) + channelGroups.push(`${this.name}-pnpres`); return new Subscription({ channels: [], - channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + channelGroups, subscriptionOptions: subscriptionOptions, eventEmitter: this.eventEmitter, pubnub: this.pubnub, @@ -10370,8 +10374,11 @@ */ subscription(subscriptionOptions) { { + const channels = [this.name]; + if ((subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) && !this.name.endsWith('-pnpres')) + channels.push(`${this.name}-pnpres`); return new Subscription({ - channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + channels, channelGroups: [], subscriptionOptions: subscriptionOptions, eventEmitter: this.eventEmitter, diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index d84bb0780..fcef699a5 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},R=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},U=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class T{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?T.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?F(a):a})),n}T.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.3.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Fe=new ue("HEARTBEAT_COOLDOWN");Fe.onEnter((()=>Ie())),Fe.onExit((()=>Ie.cancel)),Fe.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Fe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Fe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=R(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=R(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Tt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames.filter((e=>!e.endsWith("-pnpres"))),this.groupNames.filter((e=>!e.endsWith("-pnpres"))))}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Wt({channels:[],channelGroups:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){return new Wt({channels:(null==e?void 0:e.receivePresenceEvents)?[this.name,`${this.name}-pnpres`]:[this.name],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>F(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new T(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.3.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Fe=new ue("HEARTBEAT_COOLDOWN");Fe.onEnter((()=>Ie())),Fe.onExit((()=>Ie.cancel)),Fe.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Fe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Fe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=R(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=R(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Tt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>F(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new T(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 4b4748a7d..9265fe676 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -112,7 +112,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.3.0'; + return '8.3.1'; }, getVersion() { return this.version; diff --git a/lib/core/components/eventEmitter.js b/lib/core/components/eventEmitter.js index 3a4146b7e..a16e3097c 100644 --- a/lib/core/components/eventEmitter.js +++ b/lib/core/components/eventEmitter.js @@ -45,6 +45,7 @@ class EventEmitter { * @param event - Received real-time event. */ emitEvent(event) { + var _a; if (event.type === subscribe_1.PubNubEventType.Message) { this.listenerManager.announceMessage(event.data); this.announce('message', event.data, event.data.channel, event.data.subscription); @@ -55,7 +56,7 @@ class EventEmitter { } else if (event.type === subscribe_1.PubNubEventType.Presence) { this.listenerManager.announcePresence(event.data); - this.announce('presence', event.data, event.data.channel, event.data.subscription); + this.announce('presence', event.data, (_a = event.data.subscription) !== null && _a !== void 0 ? _a : event.data.channel, event.data.subscription); } else if (event.type === subscribe_1.PubNubEventType.AppContext) { const { data: objectEvent } = event; diff --git a/lib/entities/Channel.js b/lib/entities/Channel.js index ceef481af..b5c67152e 100644 --- a/lib/entities/Channel.js +++ b/lib/entities/Channel.js @@ -34,8 +34,11 @@ class Channel { */ subscription(subscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const channels = [this.name]; + if ((subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) && !this.name.endsWith('-pnpres')) + channels.push(`${this.name}-pnpres`); return new Subscription_1.Subscription({ - channels: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + channels, channelGroups: [], subscriptionOptions: subscriptionOptions, eventEmitter: this.eventEmitter, diff --git a/lib/entities/ChannelGroup.js b/lib/entities/ChannelGroup.js index dfaa4dad8..324eb58fa 100644 --- a/lib/entities/ChannelGroup.js +++ b/lib/entities/ChannelGroup.js @@ -35,9 +35,12 @@ class ChannelGroup { */ subscription(subscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const channelGroups = [this.name]; + if ((subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) && !this.name.endsWith('-pnpres')) + channelGroups.push(`${this.name}-pnpres`); return new Subscription_1.Subscription({ channels: [], - channelGroups: (subscriptionOptions === null || subscriptionOptions === void 0 ? void 0 : subscriptionOptions.receivePresenceEvents) ? [this.name, `${this.name}-pnpres`] : [this.name], + channelGroups, subscriptionOptions: subscriptionOptions, eventEmitter: this.eventEmitter, pubnub: this.pubnub, diff --git a/lib/entities/SubscribeCapable.js b/lib/entities/SubscribeCapable.js index 42766f015..16a5692be 100644 --- a/lib/entities/SubscribeCapable.js +++ b/lib/entities/SubscribeCapable.js @@ -82,7 +82,7 @@ class SubscribeCapable { * types of events. */ addListener(listener) { - this.eventEmitter.addListener(listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + this.eventEmitter.addListener(listener, this.channelNames, this.groupNames); } /** * Remove events handler. diff --git a/lib/entities/Subscription.js b/lib/entities/Subscription.js index 8ce7ab186..158e0163a 100644 --- a/lib/entities/Subscription.js +++ b/lib/entities/Subscription.js @@ -53,7 +53,7 @@ class Subscription extends SubscribeCapable_1.SubscribeCapable { this.pubnub = pubnub; this.eventEmitter = eventEmitter; this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); } /** * Merge entities' subscription objects into subscription set. diff --git a/lib/entities/SubscriptionSet.js b/lib/entities/SubscriptionSet.js index ac5816f8a..d2a04a69f 100644 --- a/lib/entities/SubscriptionSet.js +++ b/lib/entities/SubscriptionSet.js @@ -74,7 +74,7 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.subscriptionList.push(subscription); }); this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames.filter((c) => !c.endsWith('-pnpres')), this.groupNames.filter((cg) => !cg.endsWith('-pnpres'))); + eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); } /** * Add additional entity's subscription to the subscription set. diff --git a/package-lock.json b/package-lock.json index 0602ecedf..a8247da21 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6278,9 +6278,9 @@ "license": "MIT" }, "node_modules/cross-spawn": { - "version": "7.0.3", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", - "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "version": "7.0.5", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz", + "integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==", "license": "MIT", "dependencies": { "path-key": "^3.1.0", diff --git a/package.json b/package.json index 3be93b13f..e515925ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.3.0", + "version": "8.3.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 385ddef16..db44fcc57 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -171,7 +171,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.3.0'; + return '8.3.1'; }, getVersion(): string { return this.version; diff --git a/src/core/components/eventEmitter.ts b/src/core/components/eventEmitter.ts index 3cfee2220..95d2a495b 100644 --- a/src/core/components/eventEmitter.ts +++ b/src/core/components/eventEmitter.ts @@ -45,7 +45,7 @@ export default class EventEmitter { this.announce('signal', event.data, event.data.channel, event.data.subscription); } else if (event.type === PubNubEventType.Presence) { this.listenerManager.announcePresence(event.data); - this.announce('presence', event.data, event.data.channel, event.data.subscription); + this.announce('presence', event.data, event.data.subscription ?? event.data.channel, event.data.subscription); } else if (event.type === PubNubEventType.AppContext) { const { data: objectEvent } = event; const { message: object } = objectEvent; diff --git a/src/entities/Channel.ts b/src/entities/Channel.ts index 84cf3e5d4..572825971 100644 --- a/src/entities/Channel.ts +++ b/src/entities/Channel.ts @@ -57,8 +57,12 @@ export class Channel { */ subscription(subscriptionOptions?: SubscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const channels = [this.name]; + if (subscriptionOptions?.receivePresenceEvents && !this.name.endsWith('-pnpres')) + channels.push(`${this.name}-pnpres`); + return new Subscription({ - channels: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name], + channels, channelGroups: [], subscriptionOptions: subscriptionOptions, eventEmitter: this.eventEmitter, diff --git a/src/entities/ChannelGroup.ts b/src/entities/ChannelGroup.ts index 9b3355956..d461f6e3f 100644 --- a/src/entities/ChannelGroup.ts +++ b/src/entities/ChannelGroup.ts @@ -59,9 +59,13 @@ export class ChannelGroup { */ subscription(subscriptionOptions?: SubscriptionOptions) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const channelGroups = [this.name]; + if (subscriptionOptions?.receivePresenceEvents && !this.name.endsWith('-pnpres')) + channelGroups.push(`${this.name}-pnpres`); + return new Subscription({ channels: [], - channelGroups: subscriptionOptions?.receivePresenceEvents ? [this.name, `${this.name}-pnpres`] : [this.name], + channelGroups, subscriptionOptions: subscriptionOptions, eventEmitter: this.eventEmitter, pubnub: this.pubnub, diff --git a/src/entities/SubscribeCapable.ts b/src/entities/SubscribeCapable.ts index 38bbd6ead..d3d9a8483 100644 --- a/src/entities/SubscribeCapable.ts +++ b/src/entities/SubscribeCapable.ts @@ -141,11 +141,7 @@ export abstract class SubscribeCapable { * types of events. */ addListener(listener: Listener) { - this.eventEmitter.addListener( - listener, - this.channelNames.filter((c) => !c.endsWith('-pnpres')), - this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), - ); + this.eventEmitter.addListener(listener, this.channelNames, this.groupNames); } /** diff --git a/src/entities/Subscription.ts b/src/entities/Subscription.ts index 2043c4607..384d9625f 100644 --- a/src/entities/Subscription.ts +++ b/src/entities/Subscription.ts @@ -99,11 +99,7 @@ export class Subscription extends SubscribeCapable { this.pubnub = pubnub; this.eventEmitter = eventEmitter; this.listener = {}; - eventEmitter.addListener( - this.listener, - this.channelNames.filter((c) => !c.endsWith('-pnpres')), - this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), - ); + eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); } /** diff --git a/src/entities/SubscriptionSet.ts b/src/entities/SubscriptionSet.ts index d1c4d20cf..438017547 100644 --- a/src/entities/SubscriptionSet.ts +++ b/src/entities/SubscriptionSet.ts @@ -123,11 +123,7 @@ export class SubscriptionSet extends SubscribeCapable { this.subscriptionList.push(subscription); }); this.listener = {}; - eventEmitter.addListener( - this.listener, - this.channelNames.filter((c) => !c.endsWith('-pnpres')), - this.groupNames.filter((cg) => !cg.endsWith('-pnpres')), - ); + eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); } /** diff --git a/test/integration/endpoints/fetch_messages.test.ts b/test/integration/endpoints/fetch_messages.test.ts index 7f8efa488..a9c3ca975 100644 --- a/test/integration/endpoints/fetch_messages.test.ts +++ b/test/integration/endpoints/fetch_messages.test.ts @@ -355,7 +355,7 @@ describe('fetch messages endpoints', () => { assert(errorCatched); }); - it.only('supports custom message type', (done) => { + it('supports custom message type', (done) => { const channel = PubNub.generateUUID(); const expectedMessagesCount = 2; @@ -363,6 +363,8 @@ describe('fetch messages endpoints', () => { const messageTimetokens = messages.map((message) => message.timetoken); pubnub.fetchMessages({ channels: [channel], includeCustomMessageType: true }, (status, response) => { + assert.equal(status.error, false, `Fetch messages error: ${JSON.stringify(status.errorData)}`); + try { assert.equal(status.error, false); assert(response !== null); diff --git a/test/integration/endpoints/publish.test.ts b/test/integration/endpoints/publish.test.ts index ed818b867..4237d9049 100644 --- a/test/integration/endpoints/publish.test.ts +++ b/test/integration/endpoints/publish.test.ts @@ -210,7 +210,7 @@ describe('publish endpoints', () => { }); }); - it('supports customMessageType', (done) => { + it.only('supports customMessageType', (done) => { const scope = utils .createNock() .get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') @@ -219,22 +219,24 @@ describe('publish endpoints', () => { uuid: 'myUUID', auth: 'myAuthKey', store: '0', + custom_message_type: 'test-message-type', }) .reply(200, '[1,"Sent","14647523059145592"]', { 'content-type': 'text/javascript' }); - pubnub.setCipherKey('myCipherKey'); - - pubnub.publish({ message: { such: 'object' }, channel: 'ch1', storeInHistory: false }, (status, response) => { - try { - assert.equal(status.error, false); - assert(response !== null); - assert.deepEqual(response.timetoken, '14647523059145592'); - assert.equal(scope.isDone(), true); - done(); - } catch (error) { - done(error); - } - }); + pubnub.publish( + { message: { such: 'object' }, channel: 'ch1', storeInHistory: false, customMessageType: 'test-message-type' }, + (status, response) => { + try { + assert.equal(status.error, false, `Message publish error: ${JSON.stringify(status.errorData)}`); + assert(response !== null); + assert.deepEqual(response.timetoken, '14647523059145592'); + assert.equal(scope.isDone(), true); + done(); + } catch (error) { + done(error); + } + }, + ); }); it('publishes a complex object via POST', (done) => { From f51f759040aaa2f70a1c69ad0790492c951ba1b7 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 12 Dec 2024 10:58:57 +0200 Subject: [PATCH 27/49] fix(node-fetch): `keepAlive` for Node.js 19+ (#424) Fix issue because of which `node-fetch` used default agent, which after Node.js 19+ has `keepAlive` enabled by default. --- src/transport/node-transport.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/transport/node-transport.ts b/src/transport/node-transport.ts index a77a6fe7e..63526bfd2 100644 --- a/src/transport/node-transport.ts +++ b/src/transport/node-transport.ts @@ -189,9 +189,6 @@ export class NodeTransport implements Transport { * @internal */ private agentForTransportRequest(req: TransportRequest): HttpAgent | HttpsAgent | undefined { - // Don't configure any agents if keep alive not requested. - if (!this.keepAlive && !this.proxyConfiguration) return undefined; - // Create proxy agent (if possible). if (this.proxyConfiguration) return this.proxyAgent ? this.proxyAgent : (this.proxyAgent = new ProxyAgent(this.proxyConfiguration)); @@ -199,11 +196,9 @@ export class NodeTransport implements Transport { // Create keep alive agent. const useSecureAgent = req.origin!.startsWith('https:'); - if (useSecureAgent && this.httpsAgent === undefined) - this.httpsAgent = new HttpsAgent({ keepAlive: true, ...this.keepAliveSettings }); - else if (!useSecureAgent && this.httpAgent === undefined) { - this.httpAgent = new HttpAgent({ keepAlive: true, ...this.keepAliveSettings }); - } + const agentOptions = { keepAlive: this.keepAlive, ...(this.keepAlive ? this.keepAliveSettings : {}) }; + if (useSecureAgent && this.httpsAgent === undefined) this.httpsAgent = new HttpsAgent(agentOptions); + else if (!useSecureAgent && this.httpAgent === undefined) this.httpAgent = new HttpAgent(agentOptions); return useSecureAgent ? this.httpsAgent : this.httpAgent; } From d9af3ec6d2401e43be72a917e093cac8487a0237 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 12 Dec 2024 11:13:33 +0200 Subject: [PATCH 28/49] Fix presence leave call on used channels (#425) fix(presence): fix presence leave call on used channels Fix issue with `Subscription` and `SubscriptionSet` when one can unsubscribe channel / group which is still in use by another. fix(network): fix fetch resource error report as bad request Fix particular `TypeError` emitted when browser forcefully closes long-poll connection before its timeout and reported as bad request. This type of error will be reported as a network error. --- .pubnub.yml | 15 ++++- CHANGELOG.md | 8 +++ README.md | 4 +- dist/web/pubnub.js | 71 ++++++++++++++++++++-- dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/core/pubnub-common.js | 60 ++++++++++++++++++ lib/entities/SubscribeCapable.js | 12 +++- lib/errors/pubnub-api-error.js | 5 +- lib/transport/node-transport.js | 11 ++-- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/pubnub-common.ts | 66 ++++++++++++++++++++ src/entities/SubscribeCapable.ts | 14 ++++- src/errors/pubnub-api-error.ts | 4 +- test/integration/endpoints/publish.test.ts | 2 +- 16 files changed, 254 insertions(+), 28 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index dad178d21..a58fc8fbb 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,14 @@ --- changelog: + - date: 2024-12-12 + version: v8.3.2 + changes: + - type: bug + text: "Fix issue with `Subscription` and `SubscriptionSet` when one can unsubscribe channel / group which is still in use by another." + - type: bug + text: "Fix particular `TypeError` emitted when browser forcefully closes long-poll connection before its timeout and reported as bad request. This type of error will be reported as a network error." + - type: bug + text: "Fix issue because of which `node-fetch` used default agent, which after Node.js 19+ has `keepAlive` enabled by default." - date: 2024-11-18 version: v8.3.1 changes: @@ -1072,7 +1081,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.3.1' +version: '8.3.2' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1088,7 +1097,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.3.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.3.2.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1759,7 +1768,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.3.1/pubnub.8.3.1.js + location: https://github.com/pubnub/javascript/releases/download/v8.3.2/pubnub.8.3.2.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 24a5ef0f1..e796ecb59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## v8.3.2 +December 12 2024 + +#### Fixed +- Fix issue with `Subscription` and `SubscriptionSet` when one can unsubscribe channel / group which is still in use by another. +- Fix particular `TypeError` emitted when browser forcefully closes long-poll connection before its timeout and reported as bad request. This type of error will be reported as a network error. +- Fix issue because of which `node-fetch` used default agent, which after Node.js 19+ has `keepAlive` enabled by default. + ## v8.3.1 November 18 2024 diff --git a/README.md b/README.md index ec506a28c..fbbd54f01 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.2.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.2.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 94fd00418..1bcfdffac 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -2916,7 +2916,10 @@ message = 'Network issues'; } else if (errorName === 'TypeError') { - category = StatusCategory$1.PNBadRequestCategory; + if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) + category = StatusCategory$1.PNNetworkIssuesCategory; + else + category = StatusCategory$1.PNBadRequestCategory; } else if (errorName === 'FetchError') { const errorCode = error.code; @@ -3948,7 +3951,7 @@ return base.PubNubFile; }, get version() { - return '8.3.1'; + return '8.3.2'; }, getVersion() { return this.version; @@ -9892,15 +9895,23 @@ */ subscribe(subscribeParameters) { const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken; + this.pubnub.registerSubscribeCapable(this); this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken }))); } /** * Stop real-time events processing. */ unsubscribe() { + this.pubnub.unregisterSubscribeCapable(this); + const { channels, channelGroups } = this.pubnub.getSubscribeCapableEntities(); + // Identify channels and groups from which PubNub client can safely unsubscribe. + const filteredChannelGroups = this.groupNames.filter((cg) => !channelGroups.includes(cg)); + const filteredChannels = this.channelNames.filter((ch) => !channels.includes(ch)); + if (filteredChannels.length === 0 && filteredChannelGroups.length === 0) + return; this.pubnub.unsubscribe({ - channels: this.channelNames, - channelGroups: this.groupNames, + channels: filteredChannels, + channelGroups: filteredChannelGroups, }); } /** @@ -12566,6 +12577,7 @@ // Prepare for real-time events announcement. this.listenerManager = new ListenerManager(); this.eventEmitter = new EventEmitter(this.listenerManager); + this.subscribeCapable = new Set(); if (this._configuration.enableEventEngine) { { let heartbeatInterval = this._configuration.getHeartbeatInterval(); @@ -12998,7 +13010,9 @@ * @param [isOffline] - Whether `offline` presence should be notified or not. */ destroy(isOffline) { + var _a; { + (_a = this.subscribeCapable) === null || _a === void 0 ? void 0 : _a.clear(); if (this.subscriptionManager) { this.subscriptionManager.unsubscribeAll(isOffline); this.subscriptionManager.disconnect(); @@ -13127,6 +13141,53 @@ } return []; } + /** + * Register subscribe capable object with active subscription. + * + * @param subscribeCapable - {@link Subscription} or {@link SubscriptionSet} object. + * + * @internal + */ + registerSubscribeCapable(subscribeCapable) { + { + if (!this.subscribeCapable || this.subscribeCapable.has(subscribeCapable)) + return; + this.subscribeCapable.add(subscribeCapable); + } + } + /** + * Unregister subscribe capable object with inactive subscription. + * + * @param subscribeCapable - {@link Subscription} or {@link SubscriptionSet} object. + * + * @internal + */ + unregisterSubscribeCapable(subscribeCapable) { + { + if (!this.subscribeCapable || !this.subscribeCapable.has(subscribeCapable)) + return; + this.subscribeCapable.delete(subscribeCapable); + } + } + /** + * Retrieve list of subscribe capable entities currently used in subscription. + * + * @returns Channels and channel groups currently used in subscription. + * + * @internal + */ + getSubscribeCapableEntities() { + { + const entities = { channels: [], channelGroups: [] }; + if (!this.subscribeCapable) + return entities; + for (const subscribeCapable of this.subscribeCapable) { + entities.channelGroups.push(...subscribeCapable.channelGroups); + entities.channels.push(...subscribeCapable.channels); + } + return entities; + } + } /** * Subscribe to specified channels and groups real-time events. * @@ -13205,7 +13266,9 @@ * Unsubscribe from all channels and groups. */ unsubscribeAll() { + var _a; { + (_a = this.subscribeCapable) === null || _a === void 0 ? void 0 : _a.clear(); if (this.subscriptionManager) this.subscriptionManager.unsubscribeAll(); else if (this.eventEngine) diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index fcef699a5..3a896f0c0 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},R=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},U=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class T{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?T.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?F(a):a})),n}T.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.3.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Fe=new ue("HEARTBEAT_COOLDOWN");Fe.onEnter((()=>Ie())),Fe.onExit((()=>Ie.cancel)),Fe.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Fe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Fe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=R(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=R(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Tt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unsubscribe({channels:this.channelNames,channelGroups:this.groupNames})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>F(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new T(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},R=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},U=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class T{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?T.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?F(a):a})),n}T.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.3.2"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Fe=new ue("HEARTBEAT_COOLDOWN");Fe.onEnter((()=>Ie())),Fe.onExit((()=>Ie.cancel)),Fe.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Fe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Fe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=R(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=R(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Tt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>F(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new T(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 9265fe676..3c2f0df29 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -112,7 +112,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.3.1'; + return '8.3.2'; }, getVersion() { return this.version; diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 988a5a186..4dcc4aeaa 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -171,6 +171,7 @@ class PubNubCore { // Prepare for real-time events announcement. this.listenerManager = new listener_manager_1.ListenerManager(); this.eventEmitter = new eventEmitter_1.default(this.listenerManager); + this.subscribeCapable = new Set(); if (this._configuration.enableEventEngine) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { let heartbeatInterval = this._configuration.getHeartbeatInterval(); @@ -609,7 +610,10 @@ class PubNubCore { * @param [isOffline] - Whether `offline` presence should be notified or not. */ destroy(isOffline) { + var _a; if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') + (_a = this.subscribeCapable) === null || _a === void 0 ? void 0 : _a.clear(); if (this.subscriptionManager) { this.subscriptionManager.unsubscribeAll(isOffline); this.subscriptionManager.disconnect(); @@ -755,6 +759,59 @@ class PubNubCore { throw new Error('Subscription error: subscription module disabled'); return []; } + /** + * Register subscribe capable object with active subscription. + * + * @param subscribeCapable - {@link Subscription} or {@link SubscriptionSet} object. + * + * @internal + */ + registerSubscribeCapable(subscribeCapable) { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + if (!this.subscribeCapable || this.subscribeCapable.has(subscribeCapable)) + return; + this.subscribeCapable.add(subscribeCapable); + } + else + throw new Error('Subscription error: subscription event engine module disabled'); + } + /** + * Unregister subscribe capable object with inactive subscription. + * + * @param subscribeCapable - {@link Subscription} or {@link SubscriptionSet} object. + * + * @internal + */ + unregisterSubscribeCapable(subscribeCapable) { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + if (!this.subscribeCapable || !this.subscribeCapable.has(subscribeCapable)) + return; + this.subscribeCapable.delete(subscribeCapable); + } + else + throw new Error('Subscription error: subscription event engine module disabled'); + } + /** + * Retrieve list of subscribe capable entities currently used in subscription. + * + * @returns Channels and channel groups currently used in subscription. + * + * @internal + */ + getSubscribeCapableEntities() { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const entities = { channels: [], channelGroups: [] }; + if (!this.subscribeCapable) + return entities; + for (const subscribeCapable of this.subscribeCapable) { + entities.channelGroups.push(...subscribeCapable.channelGroups); + entities.channels.push(...subscribeCapable.channels); + } + return entities; + } + else + throw new Error('Subscription error: subscription event engine module disabled'); + } /** * Subscribe to specified channels and groups real-time events. * @@ -841,7 +898,10 @@ class PubNubCore { * Unsubscribe from all channels and groups. */ unsubscribeAll() { + var _a; if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') + (_a = this.subscribeCapable) === null || _a === void 0 ? void 0 : _a.clear(); if (this.subscriptionManager) this.subscriptionManager.unsubscribeAll(); else if (this.eventEngine) diff --git a/lib/entities/SubscribeCapable.js b/lib/entities/SubscribeCapable.js index 16a5692be..bd33f979e 100644 --- a/lib/entities/SubscribeCapable.js +++ b/lib/entities/SubscribeCapable.js @@ -10,15 +10,23 @@ class SubscribeCapable { */ subscribe(subscribeParameters) { const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken; + this.pubnub.registerSubscribeCapable(this); this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken }))); } /** * Stop real-time events processing. */ unsubscribe() { + this.pubnub.unregisterSubscribeCapable(this); + const { channels, channelGroups } = this.pubnub.getSubscribeCapableEntities(); + // Identify channels and groups from which PubNub client can safely unsubscribe. + const filteredChannelGroups = this.groupNames.filter((cg) => !channelGroups.includes(cg)); + const filteredChannels = this.channelNames.filter((ch) => !channels.includes(ch)); + if (filteredChannels.length === 0 && filteredChannelGroups.length === 0) + return; this.pubnub.unsubscribe({ - channels: this.channelNames, - channelGroups: this.groupNames, + channels: filteredChannels, + channelGroups: filteredChannelGroups, }); } /** diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js index 7ca6c7446..0e01d8d69 100644 --- a/lib/errors/pubnub-api-error.js +++ b/lib/errors/pubnub-api-error.js @@ -66,7 +66,10 @@ class PubNubAPIError extends Error { message = 'Network issues'; } else if (errorName === 'TypeError') { - category = categories_1.default.PNBadRequestCategory; + if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) + category = categories_1.default.PNNetworkIssuesCategory; + else + category = categories_1.default.PNBadRequestCategory; } else if (errorName === 'FetchError') { const errorCode = error.code; diff --git a/lib/transport/node-transport.js b/lib/transport/node-transport.js index 7778afd02..45dd568b1 100644 --- a/lib/transport/node-transport.js +++ b/lib/transport/node-transport.js @@ -182,19 +182,16 @@ class NodeTransport { * @internal */ agentForTransportRequest(req) { - // Don't configure any agents if keep alive not requested. - if (!this.keepAlive && !this.proxyConfiguration) - return undefined; // Create proxy agent (if possible). if (this.proxyConfiguration) return this.proxyAgent ? this.proxyAgent : (this.proxyAgent = new proxy_agent_1.ProxyAgent(this.proxyConfiguration)); // Create keep alive agent. const useSecureAgent = req.origin.startsWith('https:'); + const agentOptions = Object.assign({ keepAlive: this.keepAlive }, (this.keepAlive ? this.keepAliveSettings : {})); if (useSecureAgent && this.httpsAgent === undefined) - this.httpsAgent = new https_1.Agent(Object.assign({ keepAlive: true }, this.keepAliveSettings)); - else if (!useSecureAgent && this.httpAgent === undefined) { - this.httpAgent = new http_1.Agent(Object.assign({ keepAlive: true }, this.keepAliveSettings)); - } + this.httpsAgent = new https_1.Agent(agentOptions); + else if (!useSecureAgent && this.httpAgent === undefined) + this.httpAgent = new http_1.Agent(agentOptions); return useSecureAgent ? this.httpsAgent : this.httpAgent; } /** diff --git a/package.json b/package.json index e515925ca..a9df7843a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.3.1", + "version": "8.3.2", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index db44fcc57..e9345ee68 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -171,7 +171,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.3.1'; + return '8.3.2'; }, getVersion(): string { return this.version; diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index 41615f1c4..97202a480 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -87,6 +87,7 @@ import { AuditRequest } from './endpoints/access_manager/audit'; import * as PAM from './types/api/access-manager'; // endregion // region Entities +import { SubscribeCapable } from '../entities/SubscribeCapable'; import { SubscriptionOptions } from '../entities/commonTypes'; import { ChannelMetadata } from '../entities/ChannelMetadata'; import { SubscriptionSet } from '../entities/SubscriptionSet'; @@ -216,6 +217,16 @@ export class PubNubCore< */ private presenceEventEngine?: PresenceEventEngine; + /** + * List of subscribe capable objects with active subscriptions. + * + * Track list of {@link Subscription} and {@link SubscriptionSet} objects with active + * subscription. + * + * @internal + */ + private readonly subscribeCapable?: Set; + /** * Subscription event engine. * @@ -345,6 +356,7 @@ export class PubNubCore< // Prepare for real-time events announcement. this.listenerManager = new ListenerManager(); this.eventEmitter = new EventEmitter(this.listenerManager); + this.subscribeCapable = new Set(); if (this._configuration.enableEventEngine) { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { @@ -863,6 +875,8 @@ export class PubNubCore< */ public destroy(isOffline?: boolean): void { if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') this.subscribeCapable?.clear(); + if (this.subscriptionManager) { this.subscriptionManager.unsubscribeAll(isOffline); this.subscriptionManager.disconnect(); @@ -1086,6 +1100,56 @@ export class PubNubCore< return []; } + /** + * Register subscribe capable object with active subscription. + * + * @param subscribeCapable - {@link Subscription} or {@link SubscriptionSet} object. + * + * @internal + */ + public registerSubscribeCapable(subscribeCapable: SubscribeCapable) { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + if (!this.subscribeCapable || this.subscribeCapable.has(subscribeCapable)) return; + + this.subscribeCapable.add(subscribeCapable); + } else throw new Error('Subscription error: subscription event engine module disabled'); + } + + /** + * Unregister subscribe capable object with inactive subscription. + * + * @param subscribeCapable - {@link Subscription} or {@link SubscriptionSet} object. + * + * @internal + */ + public unregisterSubscribeCapable(subscribeCapable: SubscribeCapable) { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + if (!this.subscribeCapable || !this.subscribeCapable.has(subscribeCapable)) return; + + this.subscribeCapable.delete(subscribeCapable); + } else throw new Error('Subscription error: subscription event engine module disabled'); + } + + /** + * Retrieve list of subscribe capable entities currently used in subscription. + * + * @returns Channels and channel groups currently used in subscription. + * + * @internal + */ + public getSubscribeCapableEntities(): { channels: string[]; channelGroups: string[] } { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { + const entities: { channels: string[]; channelGroups: string[] } = { channels: [], channelGroups: [] }; + if (!this.subscribeCapable) return entities; + + for (const subscribeCapable of this.subscribeCapable) { + entities.channelGroups.push(...subscribeCapable.channelGroups); + entities.channels.push(...subscribeCapable.channels); + } + return entities; + } else throw new Error('Subscription error: subscription event engine module disabled'); + } + /** * Subscribe to specified channels and groups real-time events. * @@ -1182,6 +1246,8 @@ export class PubNubCore< */ public unsubscribeAll() { if (process.env.SUBSCRIBE_MODULE !== 'disabled') { + if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') this.subscribeCapable?.clear(); + if (this.subscriptionManager) this.subscriptionManager.unsubscribeAll(); else if (this.eventEngine) this.eventEngine.unsubscribeAll(); } else throw new Error('Unsubscription error: subscription module disabled'); diff --git a/src/entities/SubscribeCapable.ts b/src/entities/SubscribeCapable.ts index d3d9a8483..00d039ace 100644 --- a/src/entities/SubscribeCapable.ts +++ b/src/entities/SubscribeCapable.ts @@ -57,6 +57,7 @@ export abstract class SubscribeCapable { */ subscribe(subscribeParameters?: { timetoken?: string }) { const timetoken = subscribeParameters?.timetoken; + this.pubnub.registerSubscribeCapable(this); this.pubnub.subscribe({ channels: this.channelNames, channelGroups: this.groupNames, @@ -68,9 +69,18 @@ export abstract class SubscribeCapable { * Stop real-time events processing. */ unsubscribe() { + this.pubnub.unregisterSubscribeCapable(this); + const { channels, channelGroups } = this.pubnub.getSubscribeCapableEntities(); + + // Identify channels and groups from which PubNub client can safely unsubscribe. + const filteredChannelGroups = this.groupNames.filter((cg) => !channelGroups.includes(cg)); + const filteredChannels = this.channelNames.filter((ch) => !channels.includes(ch)); + + if (filteredChannels.length === 0 && filteredChannelGroups.length === 0) return; + this.pubnub.unsubscribe({ - channels: this.channelNames, - channelGroups: this.groupNames, + channels: filteredChannels, + channelGroups: filteredChannelGroups, }); } diff --git a/src/errors/pubnub-api-error.ts b/src/errors/pubnub-api-error.ts index 3c5c5572b..6ad50cf5d 100644 --- a/src/errors/pubnub-api-error.ts +++ b/src/errors/pubnub-api-error.ts @@ -62,7 +62,9 @@ export class PubNubAPIError extends Error { category = StatusCategory.PNNetworkIssuesCategory; message = 'Network issues'; } else if (errorName === 'TypeError') { - category = StatusCategory.PNBadRequestCategory; + if (message.indexOf('Load failed') !== -1 || message.indexOf('Failed to fetch') != -1) + category = StatusCategory.PNNetworkIssuesCategory; + else category = StatusCategory.PNBadRequestCategory; } else if (errorName === 'FetchError') { const errorCode = (error as Record).code; diff --git a/test/integration/endpoints/publish.test.ts b/test/integration/endpoints/publish.test.ts index 4237d9049..4df436825 100644 --- a/test/integration/endpoints/publish.test.ts +++ b/test/integration/endpoints/publish.test.ts @@ -210,7 +210,7 @@ describe('publish endpoints', () => { }); }); - it.only('supports customMessageType', (done) => { + it('supports customMessageType', (done) => { const scope = utils .createNock() .get('/publish/myPublishKey/mySubKey/0/ch1/0/%7B%22such%22%3A%22object%22%7D') From 6a9fa7d58c90c62e84d92fdc44badf765d12072f Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 17 Dec 2024 14:41:09 +0200 Subject: [PATCH 29/49] Add membership type field (#426) feat(app-context): add membership type field Add `type` field for members and membership objects and subscribe response. fix(app-context): fix type which limited options setting membership Fixed type, which limited number of options which can be included into response / used in sorting for members / membership setting API. fix(presence): fix missing presence event flag Fix missing `hereNowRefresh` flag from the presence object received from subscribe. refactor(logging): change format and add proper request body output * fix(logger): for logger for Node.js Fix issue because of which `logVerbosity` set to `true` still didn't print logs for Node.js. --- .pubnub.yml | 19 +- CHANGELOG.md | 14 ++ README.md | 4 +- dist/web/pubnub.js | 199 +++++++++++++------ dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/core/endpoints/objects/member/get.js | 29 ++- lib/core/endpoints/objects/member/set.js | 44 +++- lib/core/endpoints/objects/membership/get.js | 29 ++- lib/core/endpoints/objects/membership/set.js | 44 +++- lib/core/endpoints/subscribe.js | 15 +- lib/file/modules/node.js | 7 +- lib/node/index.js | 2 +- lib/transport/node-transport.js | 22 +- lib/transport/web-react-native-transport.js | 24 ++- lib/types/index.d.ts | 119 ++++++++++- package-lock.json | 4 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/endpoints/objects/member/get.ts | 9 +- src/core/endpoints/objects/member/set.ts | 30 ++- src/core/endpoints/objects/membership/get.ts | 9 +- src/core/endpoints/objects/membership/set.ts | 30 ++- src/core/endpoints/subscribe.ts | 42 +++- src/core/types/api/app-context.ts | 117 ++++++++++- src/file/modules/node.ts | 7 +- src/node/index.ts | 6 +- src/transport/node-transport.ts | 30 ++- src/transport/titanium-transport.ts | 32 +-- src/transport/web-react-native-transport.ts | 32 +-- test/dist/objectsv2.test.ts | 6 +- test/integration/endpoints/subscribe.test.ts | 47 ++++- 32 files changed, 796 insertions(+), 186 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index a58fc8fbb..d89b6217a 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,18 @@ --- changelog: + - date: 2024-12-17 + version: v8.4.0 + changes: + - type: feature + text: "Add `type` field for members and membership objects and subscribe response." + - type: bug + text: "Fixed type which limited number of options which can be included into response / used in sorting for members / membership setting API." + - type: bug + text: "Fix missing `hereNowRefresh` flag from the presence object received from subscribe." + - type: bug + text: "Fix issue because of which `logVerbosity` set to `true` still didn't print logs for Node.js." + - type: improvement + text: "Change format and add proper request body output." - date: 2024-12-12 version: v8.3.2 changes: @@ -1081,7 +1094,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.3.2' +version: '8.4.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1097,7 +1110,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.3.2.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.4.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1768,7 +1781,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.3.2/pubnub.8.3.2.js + location: https://github.com/pubnub/javascript/releases/download/v8.4.0/pubnub.8.4.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index e796ecb59..347f6156a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## v8.4.0 +December 17 2024 + +#### Added +- Add `type` field for members and membership objects and subscribe response. + +#### Fixed +- Fixed type which limited number of options which can be included into response / used in sorting for members / membership setting API. +- Fix missing `hereNowRefresh` flag from the presence object received from subscribe. +- Fix issue because of which `logVerbosity` set to `true` still didn't print logs for Node.js. + +#### Modified +- Change format and add proper request body output. + ## v8.3.2 December 12 2024 diff --git a/README.md b/README.md index fbbd54f01..5fbbfd204 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.2.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.3.2.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.4.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.4.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 1bcfdffac..b93bd38f6 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3392,7 +3392,7 @@ return [ this.requestFromTransportRequest(req).then((request) => { const start = new Date().getTime(); - this.logRequestProcessProgress(request); + this.logRequestProcessProgress(request, req.body); /** * Setup request timeout promise. * @@ -3424,7 +3424,7 @@ }; if (status >= 400) throw PubNubAPIError.create(transportResponse); - this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + this.logRequestProcessProgress(request, undefined, new Date().getTime() - start, responseBody); return transportResponse; }) .catch((error) => { @@ -3489,25 +3489,35 @@ * Log out request processing progress and result. * * @param request - Platform-specific + * @param [requestBody] - POST / PATCH body. * @param [elapsed] - How many seconds passed since request processing started. * @param [body] - Service response (if available). * * @internal */ - logRequestProcessProgress(request, elapsed, body) { + logRequestProcessProgress(request, requestBody, elapsed, body) { if (!this.logVerbosity) return; const { protocol, host, pathname, search } = new URL(request.url); const timestamp = new Date().toISOString(); if (!elapsed) { - console.log('<<<<<'); - console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; + if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { + if (typeof requestBody === 'string') + outgoing += `\n\n${requestBody}`; + else + outgoing += `\n\n${WebReactNativeTransport.decoder.decode(requestBody)}`; + } + console.log(`<<<<<`); + console.log(outgoing); console.log('-----'); } else { - const stringifiedBody = body ? WebReactNativeTransport.decoder.decode(body) : undefined; + let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; + if (body) + outgoing += `\n\n${WebReactNativeTransport.decoder.decode(body)}`; console.log('>>>>>>'); - console.log(`[${timestamp} / ${elapsed}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`, `\n${stringifiedBody}`); + console.log(outgoing); console.log('-----'); } } @@ -3951,7 +3961,7 @@ return base.PubNubFile; }, get version() { - return '8.3.2'; + return '8.4.0'; }, getVersion() { return this.version; @@ -6199,6 +6209,7 @@ // -------------------------------------------------------- // region Envelope parsing presenceEventFromEnvelope(envelope) { + var _a; const { d: payload } = envelope; const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); // Clean up channel and subscription name from presence suffix. @@ -6206,10 +6217,16 @@ // Backward compatibility with deprecated properties. const actualChannel = subscription !== null ? trimmedChannel : null; const subscribedChannel = subscription !== null ? subscription : trimmedChannel; - if (typeof payload !== 'string' && 'data' in payload) { - // @ts-expect-error This is `state-change` object which should have `state` field. - payload['state'] = payload.data; - delete payload.data; + if (typeof payload !== 'string') { + if ('data' in payload) { + // @ts-expect-error This is `state-change` object which should have `state` field. + payload['state'] = payload.data; + delete payload.data; + } + else if ('action' in payload && payload.action === 'interval') { + payload.hereNowRefresh = (_a = payload.here_now_refresh) !== null && _a !== void 0 ? _a : false; + delete payload.here_now_refresh; + } } return Object.assign({ channel: trimmedChannel, subscription, actualChannel, @@ -11123,9 +11140,13 @@ */ const INCLUDE_CUSTOM_FIELDS$8 = false; /** - * Whether membership's status field should be included in response or not. + * Whether membership's `status` field should be included in response or not. */ - const INCLUDE_STATUS$1 = false; + const INCLUDE_STATUS$3 = false; + /** + * Whether membership's `type` field should be included in response or not. + */ + const INCLUDE_TYPE$3 = false; /** * Whether total number of memberships should be included in response or not. */ @@ -11137,11 +11158,11 @@ /** * Whether `Channel` status field should be included in response or not. */ - const INCLUDE_CHANNEL_STATUS_FIELD = false; + const INCLUDE_CHANNEL_STATUS_FIELD$1 = false; /** * Whether `Channel` type field should be included in response or not. */ - const INCLUDE_CHANNEL_TYPE_FIELD = false; + const INCLUDE_CHANNEL_TYPE_FIELD$1 = false; /** * Whether `Channel` custom field should be included in response or not. */ @@ -11158,20 +11179,21 @@ */ class GetUUIDMembershipsRequest extends AbstractRequest { constructor(parameters) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var _k, _l, _m, _o, _p, _q, _r; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t; super(); this.parameters = parameters; // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); - (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS$8); - (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT$3); - (_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS$1); - (_e = (_o = parameters.include).channelFields) !== null && _e !== void 0 ? _e : (_o.channelFields = INCLUDE_CHANNEL_FIELDS$1); - (_f = (_p = parameters.include).customChannelFields) !== null && _f !== void 0 ? _f : (_p.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS$1); - (_g = (_q = parameters.include).channelStatusField) !== null && _g !== void 0 ? _g : (_q.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD); - (_h = (_r = parameters.include).channelTypeField) !== null && _h !== void 0 ? _h : (_r.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD); - (_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT$4); + (_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS$8); + (_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT$3); + (_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS$3); + (_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE$3); + (_f = (_q = parameters.include).channelFields) !== null && _f !== void 0 ? _f : (_q.channelFields = INCLUDE_CHANNEL_FIELDS$1); + (_g = (_r = parameters.include).customChannelFields) !== null && _g !== void 0 ? _g : (_r.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS$1); + (_h = (_s = parameters.include).channelStatusField) !== null && _h !== void 0 ? _h : (_s.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD$1); + (_j = (_t = parameters.include).channelTypeField) !== null && _j !== void 0 ? _j : (_t.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD$1); + (_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT$4); // Remap for backward compatibility. if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; @@ -11208,6 +11230,8 @@ const includeFlags = []; if (include.statusField) includeFlags.push('status'); + if (include.typeField) + includeFlags.push('type'); if (include.customFields) includeFlags.push('custom'); if (include.channelFields) @@ -11235,6 +11259,14 @@ * Whether `Membership` custom field should be included in response or not. */ const INCLUDE_CUSTOM_FIELDS$7 = false; + /** + * Whether membership's `status` field should be included in response or not. + */ + const INCLUDE_STATUS$2 = false; + /** + * Whether membership's `type` field should be included in response or not. + */ + const INCLUDE_TYPE$2 = false; /** * Whether total number of memberships should be included in response or not. */ @@ -11243,6 +11275,14 @@ * Whether `Channel` fields should be included in response or not. */ const INCLUDE_CHANNEL_FIELDS = false; + /** + * Whether `Channel` status field should be included in response or not. + */ + const INCLUDE_CHANNEL_STATUS_FIELD = false; + /** + * Whether `Channel` type field should be included in response or not. + */ + const INCLUDE_CHANNEL_TYPE_FIELD = false; /** * Whether `Channel` custom field should be included in response or not. */ @@ -11259,17 +11299,21 @@ */ class SetUUIDMembershipsRequest extends AbstractRequest { constructor(parameters) { - var _a, _b, _c, _d, _e, _f; - var _g, _h, _j, _k; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t; super({ method: TransportMethod.PATCH }); this.parameters = parameters; // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); - (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS$7); - (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT$2); - (_d = (_j = parameters.include).channelFields) !== null && _d !== void 0 ? _d : (_j.channelFields = INCLUDE_CHANNEL_FIELDS); - (_e = (_k = parameters.include).customChannelFields) !== null && _e !== void 0 ? _e : (_k.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); - (_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT$3); + (_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS$7); + (_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT$2); + (_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS$2); + (_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE$2); + (_f = (_q = parameters.include).channelFields) !== null && _f !== void 0 ? _f : (_q.channelFields = INCLUDE_CHANNEL_FIELDS); + (_g = (_r = parameters.include).customChannelFields) !== null && _g !== void 0 ? _g : (_r.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); + (_h = (_s = parameters.include).channelStatusField) !== null && _h !== void 0 ? _h : (_s.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD); + (_j = (_t = parameters.include).channelTypeField) !== null && _j !== void 0 ? _j : (_t.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD); + (_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT$3); // Remap for backward compatibility. if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; @@ -11307,10 +11351,18 @@ else sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = ['channel.status', 'channel.type', 'status']; + if (include.statusField) + includeFlags.push('status'); + if (include.typeField) + includeFlags.push('type'); if (include.customFields) includeFlags.push('custom'); if (include.channelFields) includeFlags.push('channel'); + if (include.channelStatusField) + includeFlags.push('channel.status'); + if (include.channelTypeField) + includeFlags.push('channel.type'); if (include.customChannelFields) includeFlags.push('channel.custom'); return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); @@ -11323,7 +11375,7 @@ return { channel: { id: channel } }; } else { - return { channel: { id: channel.id }, status: channel.status, custom: channel.custom }; + return { channel: { id: channel.id }, status: channel.status, type: channel.type, custom: channel.custom }; } }), }); @@ -11570,9 +11622,13 @@ */ const INCLUDE_CUSTOM_FIELDS$3 = false; /** - * Whether member's status field should be included in response or not. + * Whether member's `status` field should be included in response or not. */ - const INCLUDE_STATUS = false; + const INCLUDE_STATUS$1 = false; + /** + * Whether member's `type` field should be included in response or not. + */ + const INCLUDE_TYPE$1 = false; /** * Whether total number of members should be included in response or not. */ @@ -11584,11 +11640,11 @@ /** * Whether `UUID` status field should be included in response or not. */ - const INCLUDE_UUID_STATUS_FIELD = false; + const INCLUDE_UUID_STATUS_FIELD$1 = false; /** * Whether `UUID` type field should be included in response or not. */ - const INCLUDE_UUID_TYPE_FIELD = false; + const INCLUDE_UUID_TYPE_FIELD$1 = false; /** * Whether `UUID` custom field should be included in response or not. */ @@ -11605,20 +11661,21 @@ */ class GetChannelMembersRequest extends AbstractRequest { constructor(parameters) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var _k, _l, _m, _o, _p, _q, _r; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t; super(); this.parameters = parameters; // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); - (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS$3); - (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT$1); - (_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS); - (_e = (_o = parameters.include).UUIDFields) !== null && _e !== void 0 ? _e : (_o.UUIDFields = INCLUDE_UUID_FIELDS$1); - (_f = (_p = parameters.include).customUUIDFields) !== null && _f !== void 0 ? _f : (_p.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS$1); - (_g = (_q = parameters.include).UUIDStatusField) !== null && _g !== void 0 ? _g : (_q.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD); - (_h = (_r = parameters.include).UUIDTypeField) !== null && _h !== void 0 ? _h : (_r.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD); - (_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT$1); + (_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS$3); + (_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT$1); + (_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS$1); + (_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE$1); + (_f = (_q = parameters.include).UUIDFields) !== null && _f !== void 0 ? _f : (_q.UUIDFields = INCLUDE_UUID_FIELDS$1); + (_g = (_r = parameters.include).customUUIDFields) !== null && _g !== void 0 ? _g : (_r.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS$1); + (_h = (_s = parameters.include).UUIDStatusField) !== null && _h !== void 0 ? _h : (_s.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD$1); + (_j = (_t = parameters.include).UUIDTypeField) !== null && _j !== void 0 ? _j : (_t.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD$1); + (_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT$1); } operation() { return RequestOperation$1.PNSetMembersOperation; @@ -11652,6 +11709,8 @@ const includeFlags = []; if (include.statusField) includeFlags.push('status'); + if (include.typeField) + includeFlags.push('type'); if (include.customFields) includeFlags.push('custom'); if (include.UUIDFields) @@ -11679,6 +11738,14 @@ * Whether `Member` custom field should be included in response or not. */ const INCLUDE_CUSTOM_FIELDS$2 = false; + /** + * Whether member's `status` field should be included in response or not. + */ + const INCLUDE_STATUS = false; + /** + * Whether member's `type` field should be included in response or not. + */ + const INCLUDE_TYPE = false; /** * Whether total number of members should be included in response or not. */ @@ -11687,6 +11754,14 @@ * Whether `UUID` fields should be included in response or not. */ const INCLUDE_UUID_FIELDS = false; + /** + * Whether `UUID` status field should be included in response or not. + */ + const INCLUDE_UUID_STATUS_FIELD = false; + /** + * Whether `UUID` type field should be included in response or not. + */ + const INCLUDE_UUID_TYPE_FIELD = false; /** * Whether `UUID` custom field should be included in response or not. */ @@ -11703,17 +11778,21 @@ */ class SetChannelMembersRequest extends AbstractRequest { constructor(parameters) { - var _a, _b, _c, _d, _e, _f; - var _g, _h, _j, _k; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t; super({ method: TransportMethod.PATCH }); this.parameters = parameters; // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); - (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS$2); - (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT); - (_d = (_j = parameters.include).UUIDFields) !== null && _d !== void 0 ? _d : (_j.UUIDFields = INCLUDE_UUID_FIELDS); - (_e = (_k = parameters.include).customUUIDFields) !== null && _e !== void 0 ? _e : (_k.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS); - (_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT); + (_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS$2); + (_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS); + (_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE); + (_f = (_q = parameters.include).UUIDFields) !== null && _f !== void 0 ? _f : (_q.UUIDFields = INCLUDE_UUID_FIELDS); + (_g = (_r = parameters.include).customUUIDFields) !== null && _g !== void 0 ? _g : (_r.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS); + (_h = (_s = parameters.include).UUIDStatusField) !== null && _h !== void 0 ? _h : (_s.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD); + (_j = (_t = parameters.include).UUIDTypeField) !== null && _j !== void 0 ? _j : (_t.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD); + (_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT); } operation() { return RequestOperation$1.PNSetMembersOperation; @@ -11748,10 +11827,18 @@ else sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = ['uuid.status', 'uuid.type', 'type']; + if (include.statusField) + includeFlags.push('status'); + if (include.typeField) + includeFlags.push('type'); if (include.customFields) includeFlags.push('custom'); if (include.UUIDFields) includeFlags.push('uuid'); + if (include.UUIDStatusField) + includeFlags.push('uuid.status'); + if (include.UUIDTypeField) + includeFlags.push('uuid.type'); if (include.customUUIDFields) includeFlags.push('uuid.custom'); return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); @@ -11764,7 +11851,7 @@ return { uuid: { id: uuid } }; } else { - return { uuid: { id: uuid.id }, status: uuid.status, custom: uuid.custom }; + return { uuid: { id: uuid.id }, status: uuid.status, type: uuid.type, custom: uuid.custom }; } }), }); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 3a896f0c0..6536a6de1 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},R=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},U=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class T{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s){if(!this.logVerbosity)return;const{protocol:n,host:r,pathname:i,search:o}=new URL(e.url),a=(new Date).toISOString();if(t){const e=s?T.decoder.decode(s):void 0;console.log(">>>>>>"),console.log(`[${a} / ${t}]`,`\n${n}//${r}${i}`,`\n${o}`,`\n${e}`),console.log("-----")}else console.log("<<<<<"),console.log(`[${a}]`,`\n${n}//${r}${i}`,`\n${o}`),console.log("-----")}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?F(a):a})),n}T.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.3.2"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){const{d:t}=e,[s,n]=this.subscriptionChannelFromEnvelope(e),r=s.replace("-pnpres",""),i=null!==n?r:null,o=null!==n?n:r;return"string"!=typeof t&&"data"in t&&(t.state=t.data,delete t.data),Object.assign({channel:r,subscription:n,actualChannel:i,subscribedChannel:o,timetoken:e.p.t},t)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Fe=new ue("HEARTBEAT_COOLDOWN");Fe.onEnter((()=>Ie())),Fe.onExit((()=>Ie.cancel)),Fe.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Fe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Fe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Fe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Fe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Fe.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=R(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=R(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Tt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).channelFields)&&void 0!==i||(p.channelFields=false),null!==(o=(g=e.include).customChannelFields)&&void 0!==o||(g.customChannelFields=false),null!==(a=(y=e.include).channelStatusField)&&void 0!==a||(y.channelStatusField=false),null!==(c=(f=e.include).channelTypeField)&&void 0!==c||(f.channelTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).channelFields)&&void 0!==r||(u.channelFields=false),null!==(i=(l=e.include).customChannelFields)&&void 0!==i||(l.customChannelFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(l=e.include).customFields)&&void 0!==s||(l.customFields=false),null!==(n=(h=e.include).totalCount)&&void 0!==n||(h.totalCount=false),null!==(r=(d=e.include).statusField)&&void 0!==r||(d.statusField=false),null!==(i=(p=e.include).UUIDFields)&&void 0!==i||(p.UUIDFields=false),null!==(o=(g=e.include).customUUIDFields)&&void 0!==o||(g.customUUIDFields=false),null!==(a=(y=e.include).UUIDStatusField)&&void 0!==a||(y.UUIDStatusField=false),null!==(c=(f=e.include).UUIDTypeField)&&void 0!==c||(f.UUIDTypeField=false),null!==(u=e.limit)&&void 0!==u||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(a=e.include).customFields)&&void 0!==s||(a.customFields=false),null!==(n=(c=e.include).totalCount)&&void 0!==n||(c.totalCount=false),null!==(r=(u=e.include).UUIDFields)&&void 0!==r||(u.UUIDFields=false),null!==(i=(l=e.include).customUUIDFields)&&void 0!==i||(l.customUUIDFields=false),null!==(o=e.limit)&&void 0!==o||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>F(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new T(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},F=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class R{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${R.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${R.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}R.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.4.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Ue=ge("DELAYED_HEARTBEAT",(e=>e));class Fe extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Ue.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Re=new ue("HEARTBEAT_STOPPED");Re.on(ke.type,((e,t)=>Re.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Re.on(Ee.type,((e,t)=>Re.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Re.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Re.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Ue(e))),De.onExit((()=>Ue.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=F(this.channels,e),i=F(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class Rt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new R(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 3c2f0df29..2e536d49c 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -112,7 +112,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.3.2'; + return '8.4.0'; }, getVersion() { return this.version; diff --git a/lib/core/endpoints/objects/member/get.js b/lib/core/endpoints/objects/member/get.js index b0c5c11e9..170817a08 100644 --- a/lib/core/endpoints/objects/member/get.js +++ b/lib/core/endpoints/objects/member/get.js @@ -32,9 +32,13 @@ const utils_1 = require("../../../utils"); */ const INCLUDE_CUSTOM_FIELDS = false; /** - * Whether member's status field should be included in response or not. + * Whether member's `status` field should be included in response or not. */ const INCLUDE_STATUS = false; +/** + * Whether member's `type` field should be included in response or not. + */ +const INCLUDE_TYPE = false; /** * Whether total number of members should be included in response or not. */ @@ -67,20 +71,21 @@ const LIMIT = 100; */ class GetChannelMembersRequest extends request_1.AbstractRequest { constructor(parameters) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var _k, _l, _m, _o, _p, _q, _r; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t; super(); this.parameters = parameters; // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); - (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS); - (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT); - (_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS); - (_e = (_o = parameters.include).UUIDFields) !== null && _e !== void 0 ? _e : (_o.UUIDFields = INCLUDE_UUID_FIELDS); - (_f = (_p = parameters.include).customUUIDFields) !== null && _f !== void 0 ? _f : (_p.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS); - (_g = (_q = parameters.include).UUIDStatusField) !== null && _g !== void 0 ? _g : (_q.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD); - (_h = (_r = parameters.include).UUIDTypeField) !== null && _h !== void 0 ? _h : (_r.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD); - (_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT); + (_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS); + (_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE); + (_f = (_q = parameters.include).UUIDFields) !== null && _f !== void 0 ? _f : (_q.UUIDFields = INCLUDE_UUID_FIELDS); + (_g = (_r = parameters.include).customUUIDFields) !== null && _g !== void 0 ? _g : (_r.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS); + (_h = (_s = parameters.include).UUIDStatusField) !== null && _h !== void 0 ? _h : (_s.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD); + (_j = (_t = parameters.include).UUIDTypeField) !== null && _j !== void 0 ? _j : (_t.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD); + (_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT); } operation() { return operations_1.default.PNSetMembersOperation; @@ -114,6 +119,8 @@ class GetChannelMembersRequest extends request_1.AbstractRequest { const includeFlags = []; if (include.statusField) includeFlags.push('status'); + if (include.typeField) + includeFlags.push('type'); if (include.customFields) includeFlags.push('custom'); if (include.UUIDFields) diff --git a/lib/core/endpoints/objects/member/set.js b/lib/core/endpoints/objects/member/set.js index 3578095c4..45682cb0c 100644 --- a/lib/core/endpoints/objects/member/set.js +++ b/lib/core/endpoints/objects/member/set.js @@ -32,6 +32,14 @@ const utils_1 = require("../../../utils"); * Whether `Member` custom field should be included in response or not. */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Whether member's `status` field should be included in response or not. + */ +const INCLUDE_STATUS = false; +/** + * Whether member's `type` field should be included in response or not. + */ +const INCLUDE_TYPE = false; /** * Whether total number of members should be included in response or not. */ @@ -40,6 +48,14 @@ const INCLUDE_TOTAL_COUNT = false; * Whether `UUID` fields should be included in response or not. */ const INCLUDE_UUID_FIELDS = false; +/** + * Whether `UUID` status field should be included in response or not. + */ +const INCLUDE_UUID_STATUS_FIELD = false; +/** + * Whether `UUID` type field should be included in response or not. + */ +const INCLUDE_UUID_TYPE_FIELD = false; /** * Whether `UUID` custom field should be included in response or not. */ @@ -56,17 +72,21 @@ const LIMIT = 100; */ class SetChannelMembersRequest extends request_1.AbstractRequest { constructor(parameters) { - var _a, _b, _c, _d, _e, _f; - var _g, _h, _j, _k; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t; super({ method: transport_request_1.TransportMethod.PATCH }); this.parameters = parameters; // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); - (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS); - (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT); - (_d = (_j = parameters.include).UUIDFields) !== null && _d !== void 0 ? _d : (_j.UUIDFields = INCLUDE_UUID_FIELDS); - (_e = (_k = parameters.include).customUUIDFields) !== null && _e !== void 0 ? _e : (_k.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS); - (_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT); + (_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS); + (_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE); + (_f = (_q = parameters.include).UUIDFields) !== null && _f !== void 0 ? _f : (_q.UUIDFields = INCLUDE_UUID_FIELDS); + (_g = (_r = parameters.include).customUUIDFields) !== null && _g !== void 0 ? _g : (_r.customUUIDFields = INCLUDE_UUID_CUSTOM_FIELDS); + (_h = (_s = parameters.include).UUIDStatusField) !== null && _h !== void 0 ? _h : (_s.UUIDStatusField = INCLUDE_UUID_STATUS_FIELD); + (_j = (_t = parameters.include).UUIDTypeField) !== null && _j !== void 0 ? _j : (_t.UUIDTypeField = INCLUDE_UUID_TYPE_FIELD); + (_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT); } operation() { return operations_1.default.PNSetMembersOperation; @@ -101,10 +121,18 @@ class SetChannelMembersRequest extends request_1.AbstractRequest { else sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = ['uuid.status', 'uuid.type', 'type']; + if (include.statusField) + includeFlags.push('status'); + if (include.typeField) + includeFlags.push('type'); if (include.customFields) includeFlags.push('custom'); if (include.UUIDFields) includeFlags.push('uuid'); + if (include.UUIDStatusField) + includeFlags.push('uuid.status'); + if (include.UUIDTypeField) + includeFlags.push('uuid.type'); if (include.customUUIDFields) includeFlags.push('uuid.custom'); return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); @@ -117,7 +145,7 @@ class SetChannelMembersRequest extends request_1.AbstractRequest { return { uuid: { id: uuid } }; } else { - return { uuid: { id: uuid.id }, status: uuid.status, custom: uuid.custom }; + return { uuid: { id: uuid.id }, status: uuid.status, type: uuid.type, custom: uuid.custom }; } }), }); diff --git a/lib/core/endpoints/objects/membership/get.js b/lib/core/endpoints/objects/membership/get.js index 76d1831e3..5b333955b 100644 --- a/lib/core/endpoints/objects/membership/get.js +++ b/lib/core/endpoints/objects/membership/get.js @@ -32,9 +32,13 @@ const utils_1 = require("../../../utils"); */ const INCLUDE_CUSTOM_FIELDS = false; /** - * Whether membership's status field should be included in response or not. + * Whether membership's `status` field should be included in response or not. */ const INCLUDE_STATUS = false; +/** + * Whether membership's `type` field should be included in response or not. + */ +const INCLUDE_TYPE = false; /** * Whether total number of memberships should be included in response or not. */ @@ -67,20 +71,21 @@ const LIMIT = 100; */ class GetUUIDMembershipsRequest extends request_1.AbstractRequest { constructor(parameters) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j; - var _k, _l, _m, _o, _p, _q, _r; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t; super(); this.parameters = parameters; // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); - (_b = (_k = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_k.customFields = INCLUDE_CUSTOM_FIELDS); - (_c = (_l = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_l.totalCount = INCLUDE_TOTAL_COUNT); - (_d = (_m = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_m.statusField = INCLUDE_STATUS); - (_e = (_o = parameters.include).channelFields) !== null && _e !== void 0 ? _e : (_o.channelFields = INCLUDE_CHANNEL_FIELDS); - (_f = (_p = parameters.include).customChannelFields) !== null && _f !== void 0 ? _f : (_p.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); - (_g = (_q = parameters.include).channelStatusField) !== null && _g !== void 0 ? _g : (_q.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD); - (_h = (_r = parameters.include).channelTypeField) !== null && _h !== void 0 ? _h : (_r.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD); - (_j = parameters.limit) !== null && _j !== void 0 ? _j : (parameters.limit = LIMIT); + (_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS); + (_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE); + (_f = (_q = parameters.include).channelFields) !== null && _f !== void 0 ? _f : (_q.channelFields = INCLUDE_CHANNEL_FIELDS); + (_g = (_r = parameters.include).customChannelFields) !== null && _g !== void 0 ? _g : (_r.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); + (_h = (_s = parameters.include).channelStatusField) !== null && _h !== void 0 ? _h : (_s.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD); + (_j = (_t = parameters.include).channelTypeField) !== null && _j !== void 0 ? _j : (_t.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD); + (_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT); // Remap for backward compatibility. if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; @@ -117,6 +122,8 @@ class GetUUIDMembershipsRequest extends request_1.AbstractRequest { const includeFlags = []; if (include.statusField) includeFlags.push('status'); + if (include.typeField) + includeFlags.push('type'); if (include.customFields) includeFlags.push('custom'); if (include.channelFields) diff --git a/lib/core/endpoints/objects/membership/set.js b/lib/core/endpoints/objects/membership/set.js index 86643485e..f4e6f8039 100644 --- a/lib/core/endpoints/objects/membership/set.js +++ b/lib/core/endpoints/objects/membership/set.js @@ -32,6 +32,14 @@ const utils_1 = require("../../../utils"); * Whether `Membership` custom field should be included in response or not. */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Whether membership's `status` field should be included in response or not. + */ +const INCLUDE_STATUS = false; +/** + * Whether membership's `type` field should be included in response or not. + */ +const INCLUDE_TYPE = false; /** * Whether total number of memberships should be included in response or not. */ @@ -40,6 +48,14 @@ const INCLUDE_TOTAL_COUNT = false; * Whether `Channel` fields should be included in response or not. */ const INCLUDE_CHANNEL_FIELDS = false; +/** + * Whether `Channel` status field should be included in response or not. + */ +const INCLUDE_CHANNEL_STATUS_FIELD = false; +/** + * Whether `Channel` type field should be included in response or not. + */ +const INCLUDE_CHANNEL_TYPE_FIELD = false; /** * Whether `Channel` custom field should be included in response or not. */ @@ -56,17 +72,21 @@ const LIMIT = 100; */ class SetUUIDMembershipsRequest extends request_1.AbstractRequest { constructor(parameters) { - var _a, _b, _c, _d, _e, _f; - var _g, _h, _j, _k; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _l, _m, _o, _p, _q, _r, _s, _t; super({ method: transport_request_1.TransportMethod.PATCH }); this.parameters = parameters; // Apply default request parameters. (_a = parameters.include) !== null && _a !== void 0 ? _a : (parameters.include = {}); - (_b = (_g = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_g.customFields = INCLUDE_CUSTOM_FIELDS); - (_c = (_h = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_h.totalCount = INCLUDE_TOTAL_COUNT); - (_d = (_j = parameters.include).channelFields) !== null && _d !== void 0 ? _d : (_j.channelFields = INCLUDE_CHANNEL_FIELDS); - (_e = (_k = parameters.include).customChannelFields) !== null && _e !== void 0 ? _e : (_k.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); - (_f = parameters.limit) !== null && _f !== void 0 ? _f : (parameters.limit = LIMIT); + (_b = (_l = parameters.include).customFields) !== null && _b !== void 0 ? _b : (_l.customFields = INCLUDE_CUSTOM_FIELDS); + (_c = (_m = parameters.include).totalCount) !== null && _c !== void 0 ? _c : (_m.totalCount = INCLUDE_TOTAL_COUNT); + (_d = (_o = parameters.include).statusField) !== null && _d !== void 0 ? _d : (_o.statusField = INCLUDE_STATUS); + (_e = (_p = parameters.include).typeField) !== null && _e !== void 0 ? _e : (_p.typeField = INCLUDE_TYPE); + (_f = (_q = parameters.include).channelFields) !== null && _f !== void 0 ? _f : (_q.channelFields = INCLUDE_CHANNEL_FIELDS); + (_g = (_r = parameters.include).customChannelFields) !== null && _g !== void 0 ? _g : (_r.customChannelFields = INCLUDE_CHANNEL_CUSTOM_FIELDS); + (_h = (_s = parameters.include).channelStatusField) !== null && _h !== void 0 ? _h : (_s.channelStatusField = INCLUDE_CHANNEL_STATUS_FIELD); + (_j = (_t = parameters.include).channelTypeField) !== null && _j !== void 0 ? _j : (_t.channelTypeField = INCLUDE_CHANNEL_TYPE_FIELD); + (_k = parameters.limit) !== null && _k !== void 0 ? _k : (parameters.limit = LIMIT); // Remap for backward compatibility. if (this.parameters.userId) this.parameters.uuid = this.parameters.userId; @@ -104,10 +124,18 @@ class SetUUIDMembershipsRequest extends request_1.AbstractRequest { else sorting = Object.entries(sort !== null && sort !== void 0 ? sort : {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags = ['channel.status', 'channel.type', 'status']; + if (include.statusField) + includeFlags.push('status'); + if (include.typeField) + includeFlags.push('type'); if (include.customFields) includeFlags.push('custom'); if (include.channelFields) includeFlags.push('channel'); + if (include.channelStatusField) + includeFlags.push('channel.status'); + if (include.channelTypeField) + includeFlags.push('channel.type'); if (include.customChannelFields) includeFlags.push('channel.custom'); return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ count: `${include.totalCount}` }, (includeFlags.length > 0 ? { include: includeFlags.join(',') } : {})), (filter ? { filter } : {})), ((page === null || page === void 0 ? void 0 : page.next) ? { start: page.next } : {})), ((page === null || page === void 0 ? void 0 : page.prev) ? { end: page.prev } : {})), (limit ? { limit } : {})), (sorting.length ? { sort: sorting } : {})); @@ -120,7 +148,7 @@ class SetUUIDMembershipsRequest extends request_1.AbstractRequest { return { channel: { id: channel } }; } else { - return { channel: { id: channel.id }, status: channel.status, custom: channel.custom }; + return { channel: { id: channel.id }, status: channel.status, type: channel.type, custom: channel.custom }; } }), }); diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index 76f06c2a3..401ebbda5 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -182,6 +182,7 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { // -------------------------------------------------------- // region Envelope parsing presenceEventFromEnvelope(envelope) { + var _a; const { d: payload } = envelope; const [channel, subscription] = this.subscriptionChannelFromEnvelope(envelope); // Clean up channel and subscription name from presence suffix. @@ -189,10 +190,16 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { // Backward compatibility with deprecated properties. const actualChannel = subscription !== null ? trimmedChannel : null; const subscribedChannel = subscription !== null ? subscription : trimmedChannel; - if (typeof payload !== 'string' && 'data' in payload) { - // @ts-expect-error This is `state-change` object which should have `state` field. - payload['state'] = payload.data; - delete payload.data; + if (typeof payload !== 'string') { + if ('data' in payload) { + // @ts-expect-error This is `state-change` object which should have `state` field. + payload['state'] = payload.data; + delete payload.data; + } + else if ('action' in payload && payload.action === 'interval') { + payload.hereNowRefresh = (_a = payload.here_now_refresh) !== null && _a !== void 0 ? _a : false; + delete payload.here_now_refresh; + } } return Object.assign({ channel: trimmedChannel, subscription, actualChannel, diff --git a/lib/file/modules/node.js b/lib/file/modules/node.js index 90f4759e6..886a205d7 100644 --- a/lib/file/modules/node.js +++ b/lib/file/modules/node.js @@ -38,10 +38,9 @@ class PubNubFile { let fileName; if (stream && stream instanceof stream_1.Readable) { fileData = stream; - if (stream instanceof fs_1.default.ReadStream) { - const streamFilePath = stream.path instanceof buffer_1.Buffer ? new TextDecoder().decode(stream.path) : stream.path; - fileName = (0, path_1.basename)(streamFilePath); - contentLength = fs_1.default.statSync(streamFilePath).size; + if (stream instanceof fs_1.default.ReadStream && !(stream.path instanceof buffer_1.Buffer)) { + fileName = (0, path_1.basename)(stream.path); + contentLength = fs_1.default.statSync(stream.path).size; } } else if (data instanceof buffer_1.Buffer) { diff --git a/lib/node/index.js b/lib/node/index.js index bd2eb87c7..d49294680 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -66,7 +66,7 @@ class PubNub extends pubnub_common_1.PubNubCore { if (process.env.CRYPTO_MODULE !== 'disabled') cryptography = new node_2.default(); // Setup transport provider. - const transport = new node_transport_1.NodeTransport(configuration.keepAlive, configuration.keepAliveSettings); + const transport = new node_transport_1.NodeTransport(configuration.keepAlive, configuration.keepAliveSettings, clientConfiguration.logVerbosity); const transportMiddleware = new middleware_1.PubNubMiddleware({ clientConfiguration, tokenManager, diff --git a/lib/transport/node-transport.js b/lib/transport/node-transport.js index 45dd568b1..ea2aae6b0 100644 --- a/lib/transport/node-transport.js +++ b/lib/transport/node-transport.js @@ -95,7 +95,7 @@ class NodeTransport { return [ this.requestFromTransportRequest(req).then((request) => { const start = new Date().getTime(); - this.logRequestProcessProgress(request); + this.logRequestProcessProgress(request, req.body); return (0, node_fetch_1.default)(request, { signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, timeout: req.timeout * 1000, @@ -115,7 +115,7 @@ class NodeTransport { }; if (status >= 400) throw pubnub_api_error_1.PubNubAPIError.create(transportResponse); - this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + this.logRequestProcessProgress(request, undefined, new Date().getTime() - start, responseBody); return transportResponse; }) .catch((error) => { @@ -198,23 +198,33 @@ class NodeTransport { * Log out request processing progress and result. * * @param request - Platform-specific request object. + * @param [requestBody] - POST / PATCH body. * @param [elapsed] - How many times passed since request processing started. * @param [body] - Service response (if available). */ - logRequestProcessProgress(request, elapsed, body) { + logRequestProcessProgress(request, requestBody, elapsed, body) { if (!this.logVerbosity) return; const { protocol, host, pathname, search } = new URL(request.url); const timestamp = new Date().toISOString(); if (!elapsed) { + let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; + if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { + if (typeof requestBody === 'string') + outgoing += `\n\n${requestBody}`; + else + outgoing += `\n\n${NodeTransport.decoder.decode(requestBody)}`; + } console.log('<<<<<'); - console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + console.log(outgoing); console.log('-----'); } else { - const stringifiedBody = body ? NodeTransport.decoder.decode(body) : undefined; + let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; + if (body) + outgoing += `\n\n${NodeTransport.decoder.decode(body)}`; console.log('>>>>>>'); - console.log(`[${timestamp} / ${elapsed}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`, `\n${stringifiedBody}`); + console.log(outgoing); console.log('-----'); } } diff --git a/lib/transport/web-react-native-transport.js b/lib/transport/web-react-native-transport.js index 53ce793f6..cbef75131 100644 --- a/lib/transport/web-react-native-transport.js +++ b/lib/transport/web-react-native-transport.js @@ -49,7 +49,7 @@ class WebReactNativeTransport { return [ this.requestFromTransportRequest(req).then((request) => { const start = new Date().getTime(); - this.logRequestProcessProgress(request); + this.logRequestProcessProgress(request, req.body); /** * Setup request timeout promise. * @@ -81,7 +81,7 @@ class WebReactNativeTransport { }; if (status >= 400) throw pubnub_api_error_1.PubNubAPIError.create(transportResponse); - this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + this.logRequestProcessProgress(request, undefined, new Date().getTime() - start, responseBody); return transportResponse; }) .catch((error) => { @@ -146,25 +146,35 @@ class WebReactNativeTransport { * Log out request processing progress and result. * * @param request - Platform-specific + * @param [requestBody] - POST / PATCH body. * @param [elapsed] - How many seconds passed since request processing started. * @param [body] - Service response (if available). * * @internal */ - logRequestProcessProgress(request, elapsed, body) { + logRequestProcessProgress(request, requestBody, elapsed, body) { if (!this.logVerbosity) return; const { protocol, host, pathname, search } = new URL(request.url); const timestamp = new Date().toISOString(); if (!elapsed) { - console.log('<<<<<'); - console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; + if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { + if (typeof requestBody === 'string') + outgoing += `\n\n${requestBody}`; + else + outgoing += `\n\n${WebReactNativeTransport.decoder.decode(requestBody)}`; + } + console.log(`<<<<<`); + console.log(outgoing); console.log('-----'); } else { - const stringifiedBody = body ? WebReactNativeTransport.decoder.decode(body) : undefined; + let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; + if (body) + outgoing += `\n\n${WebReactNativeTransport.decoder.decode(body)}`; console.log('>>>>>>'); - console.log(`[${timestamp} / ${elapsed}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`, `\n${stringifiedBody}`); + console.log(outgoing); console.log('-----'); } } diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 470eb773d..2f10643ab 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -3082,6 +3082,15 @@ declare namespace PubNub { * presence update. */ timeout?: string[]; + /** + * Indicates whether presence should be requested manually using {@link PubNubCore.hereNow hereNow()} + * or not. + * + * Depending on from the presence activity, the resulting interval update can be too large to be + * returned as a presence event with subscribe REST API response. The server will set this flag to + * `true` in this case. + */ + hereNowRefresh: boolean; }; /** @@ -3269,6 +3278,14 @@ declare namespace PubNub { AppContextEvents, 'membership', Omit, 'id'> & { + /** + * User membership status. + */ + status?: string; + /** + * User membership type. + */ + type?: string; /** * `Uuid` object which has been used to create relationship with `channel`. */ @@ -5053,6 +5070,10 @@ declare namespace PubNub { * App Context objects relation status. */ status?: string; + /** + * App Context objects relation type. + */ + type?: string; /** * Additional data associated with App Context object relation (membership or members). * @@ -5124,11 +5145,17 @@ declare namespace PubNub { */ customChannelFields?: boolean; /** - * Whether to include the membership's status field in the response. + * Whether to include the membership's `status` field in the response. * * @default `false` */ statusField?: boolean; + /** + * Whether to include the membership's `type` field in the response. + * + * @default `false` + */ + typeField?: boolean; /** * Whether to include the channel's status field in the response. * @@ -5162,11 +5189,17 @@ declare namespace PubNub { */ customUUIDFields?: boolean; /** - * Whether to include the members's status field in the response. + * Whether to include the member's `status` field in the response. * * @default `false` */ statusField?: boolean; + /** + * Whether to include the member's `type` field in the response. + * + * @default `false` + */ + typeField?: boolean; /** * Whether to include the user's status field in the response. * @@ -5276,11 +5309,15 @@ declare namespace PubNub { | 'channel.name' | 'channel.description' | 'channel.updated' + | 'channel.status' + | 'channel.type' | 'space.id' | 'space.name' | 'space.description' | 'space.updated' | 'updated' + | 'status' + | 'type' | { /** * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. @@ -5306,6 +5343,18 @@ declare namespace PubNub { * Specify `null` for default sorting direction (ascending). */ 'channel.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `status` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.status'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `type` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.type'?: 'asc' | 'desc' | null; /** * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. * @@ -5344,6 +5393,18 @@ declare namespace PubNub { * Specify `null` for default sorting direction (ascending). */ updated?: 'asc' | 'desc' | null; + /** + * Sort results by `status` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + status?: 'asc' | 'desc' | null; + /** + * Sort results by `type` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + type?: 'asc' | 'desc' | null; }; /** @@ -5353,10 +5414,14 @@ declare namespace PubNub { | 'uuid.id' | 'uuid.name' | 'uuid.updated' + | 'uuid.status' + | 'uuid.type' | 'user.id' | 'user.name' | 'user.updated' | 'updated' + | 'status' + | 'type' | { /** * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. @@ -5376,6 +5441,18 @@ declare namespace PubNub { * Specify `null` for default sorting direction (ascending). */ 'uuid.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `status` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.status'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `type` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.type'?: 'asc' | 'desc' | null; /** * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. * @@ -5406,6 +5483,18 @@ declare namespace PubNub { * Specify `null` for default sorting direction (ascending). */ updated?: 'asc' | 'desc' | null; + /** + * Sort results by `status` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + status?: 'asc' | 'desc' | null; + /** + * Sort results by `type` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + type?: 'asc' | 'desc' | null; }; /** @@ -5691,6 +5780,17 @@ declare namespace PubNub { ObjectData, 'id' > & { + /** + * User's membership status. + */ + status?: string; + /** + * User's membership type. + */ + type?: string; + /** + * Channel for which `user` has membership. + */ channel: | ChannelMetadataObject | { @@ -5744,7 +5844,7 @@ declare namespace PubNub { * Update Memberships request parameters. */ export type SetMembershipsParameters = PagedRequestParameters< - Omit, + MembershipsIncludeOptions, MembershipsSortingOptions > & { /** @@ -5847,6 +5947,17 @@ declare namespace PubNub { ObjectData, 'id' > & { + /** + * Channel's member status. + */ + status?: string; + /** + * Channel's member type. + */ + type?: string; + /** + * Member of the `channel`. + */ uuid: | UUIDMetadataObject | { @@ -5889,7 +6000,7 @@ declare namespace PubNub { * Update Members request parameters. */ export type SetChannelMembersParameters = PagedRequestParameters< - Omit, + MembersIncludeOptions, MembersSortingOptions > & { /** diff --git a/package-lock.json b/package-lock.json index a8247da21..4b12108a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.2.9", + "version": "8.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.2.9", + "version": "8.3.2", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", diff --git a/package.json b/package.json index a9df7843a..6464acfca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.3.2", + "version": "8.4.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index e9345ee68..f9570d086 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -171,7 +171,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.3.2'; + return '8.4.0'; }, getVersion(): string { return this.version; diff --git a/src/core/endpoints/objects/member/get.ts b/src/core/endpoints/objects/member/get.ts index e6616a71c..da0ffecc5 100644 --- a/src/core/endpoints/objects/member/get.ts +++ b/src/core/endpoints/objects/member/get.ts @@ -24,10 +24,15 @@ import { encodeString } from '../../../utils'; const INCLUDE_CUSTOM_FIELDS = false; /** - * Whether member's status field should be included in response or not. + * Whether member's `status` field should be included in response or not. */ const INCLUDE_STATUS = false; +/** + * Whether member's `type` field should be included in response or not. + */ +const INCLUDE_TYPE = false; + /** * Whether total number of members should be included in response or not. */ @@ -93,6 +98,7 @@ export class GetChannelMembersRequest< parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; parameters.include.totalCount ??= INCLUDE_TOTAL_COUNT; parameters.include.statusField ??= INCLUDE_STATUS; + parameters.include.typeField ??= INCLUDE_TYPE; parameters.include.UUIDFields ??= INCLUDE_UUID_FIELDS; parameters.include.customUUIDFields ??= INCLUDE_UUID_CUSTOM_FIELDS; parameters.include.UUIDStatusField ??= INCLUDE_UUID_STATUS_FIELD; @@ -139,6 +145,7 @@ export class GetChannelMembersRequest< const includeFlags: string[] = []; if (include!.statusField) includeFlags.push('status'); + if (include!.typeField) includeFlags.push('type'); if (include!.customFields) includeFlags.push('custom'); if (include!.UUIDFields) includeFlags.push('uuid'); if (include!.UUIDStatusField) includeFlags.push('uuid.status'); diff --git a/src/core/endpoints/objects/member/set.ts b/src/core/endpoints/objects/member/set.ts index bf110d971..f29889a8a 100644 --- a/src/core/endpoints/objects/member/set.ts +++ b/src/core/endpoints/objects/member/set.ts @@ -24,6 +24,16 @@ import { encodeString } from '../../../utils'; */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Whether member's `status` field should be included in response or not. + */ +const INCLUDE_STATUS = false; + +/** + * Whether member's `type` field should be included in response or not. + */ +const INCLUDE_TYPE = false; + /** * Whether total number of members should be included in response or not. */ @@ -34,6 +44,16 @@ const INCLUDE_TOTAL_COUNT = false; */ const INCLUDE_UUID_FIELDS = false; +/** + * Whether `UUID` status field should be included in response or not. + */ +const INCLUDE_UUID_STATUS_FIELD = false; + +/** + * Whether `UUID` type field should be included in response or not. + */ +const INCLUDE_UUID_TYPE_FIELD = false; + /** * Whether `UUID` custom field should be included in response or not. */ @@ -83,8 +103,12 @@ export class SetChannelMembersRequest< parameters.include ??= {}; parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; parameters.include.totalCount ??= INCLUDE_TOTAL_COUNT; + parameters.include.statusField ??= INCLUDE_STATUS; + parameters.include.typeField ??= INCLUDE_TYPE; parameters.include.UUIDFields ??= INCLUDE_UUID_FIELDS; parameters.include.customUUIDFields ??= INCLUDE_UUID_CUSTOM_FIELDS; + parameters.include.UUIDStatusField ??= INCLUDE_UUID_STATUS_FIELD; + parameters.include.UUIDTypeField ??= INCLUDE_UUID_TYPE_FIELD; parameters.limit ??= LIMIT; } @@ -129,8 +153,12 @@ export class SetChannelMembersRequest< sorting = Object.entries(sort ?? {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags: string[] = ['uuid.status', 'uuid.type', 'type']; + if (include!.statusField) includeFlags.push('status'); + if (include!.typeField) includeFlags.push('type'); if (include!.customFields) includeFlags.push('custom'); if (include!.UUIDFields) includeFlags.push('uuid'); + if (include!.UUIDStatusField) includeFlags.push('uuid.status'); + if (include!.UUIDTypeField) includeFlags.push('uuid.type'); if (include!.customUUIDFields) includeFlags.push('uuid.custom'); return { @@ -152,7 +180,7 @@ export class SetChannelMembersRequest< if (typeof uuid === 'string') { return { uuid: { id: uuid } }; } else { - return { uuid: { id: uuid.id }, status: uuid.status, custom: uuid.custom }; + return { uuid: { id: uuid.id }, status: uuid.status, type: uuid.type, custom: uuid.custom }; } }), }); diff --git a/src/core/endpoints/objects/membership/get.ts b/src/core/endpoints/objects/membership/get.ts index 0177cfabe..89850ec1f 100644 --- a/src/core/endpoints/objects/membership/get.ts +++ b/src/core/endpoints/objects/membership/get.ts @@ -24,10 +24,15 @@ import { encodeString } from '../../../utils'; const INCLUDE_CUSTOM_FIELDS = false; /** - * Whether membership's status field should be included in response or not. + * Whether membership's `status` field should be included in response or not. */ const INCLUDE_STATUS = false; +/** + * Whether membership's `type` field should be included in response or not. + */ +const INCLUDE_TYPE = false; + /** * Whether total number of memberships should be included in response or not. */ @@ -93,6 +98,7 @@ export class GetUUIDMembershipsRequest< parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; parameters.include.totalCount ??= INCLUDE_TOTAL_COUNT; parameters.include.statusField ??= INCLUDE_STATUS; + parameters.include.typeField ??= INCLUDE_TYPE; parameters.include.channelFields ??= INCLUDE_CHANNEL_FIELDS; parameters.include.customChannelFields ??= INCLUDE_CHANNEL_CUSTOM_FIELDS; parameters.include.channelStatusField ??= INCLUDE_CHANNEL_STATUS_FIELD; @@ -142,6 +148,7 @@ export class GetUUIDMembershipsRequest< const includeFlags: string[] = []; if (include!.statusField) includeFlags.push('status'); + if (include!.typeField) includeFlags.push('type'); if (include!.customFields) includeFlags.push('custom'); if (include!.channelFields) includeFlags.push('channel'); if (include!.channelStatusField) includeFlags.push('channel.status'); diff --git a/src/core/endpoints/objects/membership/set.ts b/src/core/endpoints/objects/membership/set.ts index 89fe7a5dc..fa2cecc73 100644 --- a/src/core/endpoints/objects/membership/set.ts +++ b/src/core/endpoints/objects/membership/set.ts @@ -24,6 +24,16 @@ import { encodeString } from '../../../utils'; */ const INCLUDE_CUSTOM_FIELDS = false; +/** + * Whether membership's `status` field should be included in response or not. + */ +const INCLUDE_STATUS = false; + +/** + * Whether membership's `type` field should be included in response or not. + */ +const INCLUDE_TYPE = false; + /** * Whether total number of memberships should be included in response or not. */ @@ -34,6 +44,16 @@ const INCLUDE_TOTAL_COUNT = false; */ const INCLUDE_CHANNEL_FIELDS = false; +/** + * Whether `Channel` status field should be included in response or not. + */ +const INCLUDE_CHANNEL_STATUS_FIELD = false; + +/** + * Whether `Channel` type field should be included in response or not. + */ +const INCLUDE_CHANNEL_TYPE_FIELD = false; + /** * Whether `Channel` custom field should be included in response or not. */ @@ -83,8 +103,12 @@ export class SetUUIDMembershipsRequest< parameters.include ??= {}; parameters.include.customFields ??= INCLUDE_CUSTOM_FIELDS; parameters.include.totalCount ??= INCLUDE_TOTAL_COUNT; + parameters.include.statusField ??= INCLUDE_STATUS; + parameters.include.typeField ??= INCLUDE_TYPE; parameters.include.channelFields ??= INCLUDE_CHANNEL_FIELDS; parameters.include.customChannelFields ??= INCLUDE_CHANNEL_CUSTOM_FIELDS; + parameters.include.channelStatusField ??= INCLUDE_CHANNEL_STATUS_FIELD; + parameters.include.channelTypeField ??= INCLUDE_CHANNEL_TYPE_FIELD; parameters.limit ??= LIMIT; // Remap for backward compatibility. @@ -132,8 +156,12 @@ export class SetUUIDMembershipsRequest< sorting = Object.entries(sort ?? {}).map(([option, order]) => (order !== null ? `${option}:${order}` : option)); const includeFlags: string[] = ['channel.status', 'channel.type', 'status']; + if (include!.statusField) includeFlags.push('status'); + if (include!.typeField) includeFlags.push('type'); if (include!.customFields) includeFlags.push('custom'); if (include!.channelFields) includeFlags.push('channel'); + if (include!.channelStatusField) includeFlags.push('channel.status'); + if (include!.channelTypeField) includeFlags.push('channel.type'); if (include!.customChannelFields) includeFlags.push('channel.custom'); return { @@ -155,7 +183,7 @@ export class SetUUIDMembershipsRequest< if (typeof channel === 'string') { return { channel: { id: channel } }; } else { - return { channel: { id: channel.id }, status: channel.status, custom: channel.custom }; + return { channel: { id: channel.id }, status: channel.status, type: channel.type, custom: channel.custom }; } }), }); diff --git a/src/core/endpoints/subscribe.ts b/src/core/endpoints/subscribe.ts index 9033c9374..4af64fc70 100644 --- a/src/core/endpoints/subscribe.ts +++ b/src/core/endpoints/subscribe.ts @@ -127,6 +127,25 @@ type PresenceIntervalData = { * presence update. */ timeout?: string[]; + + /** + * Indicates whether presence should be requested manually using {@link PubNubCore.hereNow hereNow()} + * or not. + * + * Depending on from the presence activity, the resulting interval update can be too large to be + * returned as a presence event with subscribe REST API response. The server will set this flag to + * `true` in this case. + */ + hereNowRefresh: boolean; + + /** + * Indicates whether presence should be requested manually or not. + * + * **Warning:** This is internal property which will be removed after processing. + * + * @internal + */ + here_now_refresh?: boolean; }; /** @@ -331,6 +350,16 @@ type MembershipObjectData = ObjectData< AppContextEvents, 'membership', Omit, 'id'> & { + /** + * User membership status. + */ + status?: string; + + /** + * User membership type. + */ + type?: string; + /** * `Uuid` object which has been used to create relationship with `channel`. */ @@ -703,10 +732,15 @@ export class BaseSubscribeRequest extends AbstractRequest = { */ status?: string; + /** + * App Context objects relation type. + */ + type?: string; + /** * Additional data associated with App Context object relation (membership or members). * @@ -143,12 +148,19 @@ type MembershipsIncludeOptions = IncludeOptions & { customChannelFields?: boolean; /** - * Whether to include the membership's status field in the response. + * Whether to include the membership's `status` field in the response. * * @default `false` */ statusField?: boolean; + /** + * Whether to include the membership's `type` field in the response. + * + * @default `false` + */ + typeField?: boolean; + /** * Whether to include the channel's status field in the response. * @@ -185,12 +197,19 @@ type MembersIncludeOptions = IncludeOptions & { customUUIDFields?: boolean; /** - * Whether to include the members's status field in the response. + * Whether to include the member's `status` field in the response. * * @default `false` */ statusField?: boolean; + /** + * Whether to include the member's `type` field in the response. + * + * @default `false` + */ + typeField?: boolean; + /** * Whether to include the user's status field in the response. * @@ -322,11 +341,15 @@ type MembershipsSortingOptions = | 'channel.name' | 'channel.description' | 'channel.updated' + | 'channel.status' + | 'channel.type' | 'space.id' | 'space.name' | 'space.description' | 'space.updated' | 'updated' + | 'status' + | 'type' | { /** * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. @@ -356,6 +379,20 @@ type MembershipsSortingOptions = */ 'channel.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by channel's `status` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.status'?: 'asc' | 'desc' | null; + + /** + * Sort results by channel's `type` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'channel.type'?: 'asc' | 'desc' | null; + /** * Sort results by channel's `id` in ascending (`asc`) or descending (`desc`) order. * @@ -398,6 +435,20 @@ type MembershipsSortingOptions = * Specify `null` for default sorting direction (ascending). */ updated?: 'asc' | 'desc' | null; + + /** + * Sort results by `status` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + status?: 'asc' | 'desc' | null; + + /** + * Sort results by `type` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + type?: 'asc' | 'desc' | null; }; /** @@ -407,10 +458,14 @@ type MembersSortingOptions = | 'uuid.id' | 'uuid.name' | 'uuid.updated' + | 'uuid.status' + | 'uuid.type' | 'user.id' | 'user.name' | 'user.updated' | 'updated' + | 'status' + | 'type' | { /** * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. @@ -433,6 +488,20 @@ type MembersSortingOptions = */ 'uuid.updated'?: 'asc' | 'desc' | null; + /** + * Sort results by user's `status` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.status'?: 'asc' | 'desc' | null; + + /** + * Sort results by user's `type` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + 'uuid.type'?: 'asc' | 'desc' | null; + /** * Sort results by user's `id` in ascending (`asc`) or descending (`desc`) order. * @@ -466,6 +535,20 @@ type MembersSortingOptions = * Specify `null` for default sorting direction (ascending). */ updated?: 'asc' | 'desc' | null; + + /** + * Sort results by `status` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + status?: 'asc' | 'desc' | null; + + /** + * Sort results by `type` in ascending (`asc`) or descending (`desc`) order. + * + * Specify `null` for default sorting direction (ascending). + */ + type?: 'asc' | 'desc' | null; }; // -------------------------------------------------------- @@ -786,6 +869,19 @@ type MembershipsObject, 'id' > & { + /** + * User's membership status. + */ + status?: string; + + /** + * User's membership type. + */ + type?: string; + + /** + * Channel for which `user` has membership. + */ channel: ChannelMetadataObject | { id: string }; }; @@ -833,7 +929,7 @@ export type GetMembershipsResponse< * Update Memberships request parameters. */ export type SetMembershipsParameters = PagedRequestParameters< - Omit, + MembershipsIncludeOptions, MembershipsSortingOptions > & { /** @@ -946,6 +1042,19 @@ type MembersObject, 'id' > & { + /** + * Channel's member status. + */ + status?: string; + + /** + * Channel's member type. + */ + type?: string; + + /** + * Member of the `channel`. + */ uuid: UUIDMetadataObject | { id: string }; }; @@ -985,7 +1094,7 @@ export type GetMembersResponse = PagedRequestParameters< - Omit, + MembersIncludeOptions, MembersSortingOptions > & { /** diff --git a/src/file/modules/node.ts b/src/file/modules/node.ts index ae2fde560..4cd56e8d3 100644 --- a/src/file/modules/node.ts +++ b/src/file/modules/node.ts @@ -131,10 +131,9 @@ export default class PubNubFile implements PubNubFileInterface { if (stream && stream instanceof Readable) { fileData = stream; - if (stream instanceof fs.ReadStream) { - const streamFilePath = stream.path instanceof Buffer ? new TextDecoder().decode(stream.path) : stream.path; - fileName = basename(streamFilePath); - contentLength = fs.statSync(streamFilePath).size; + if (stream instanceof fs.ReadStream && !(stream.path instanceof Buffer)) { + fileName = basename(stream.path); + contentLength = fs.statSync(stream.path).size; } } else if (data instanceof Buffer) { contentLength = data.length; diff --git a/src/node/index.ts b/src/node/index.ts index 1ba9a65a2..11a7816ea 100755 --- a/src/node/index.ts +++ b/src/node/index.ts @@ -101,7 +101,11 @@ class PubNub extends PubNubCore { const start = new Date().getTime(); - this.logRequestProcessProgress(request); + this.logRequestProcessProgress(request, req.body); return fetch(request, { signal: abortController?.signal, @@ -116,7 +116,7 @@ export class NodeTransport implements Transport { if (status >= 400) throw PubNubAPIError.create(transportResponse); - this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + this.logRequestProcessProgress(request, undefined, new Date().getTime() - start, responseBody); return transportResponse; }) @@ -207,29 +207,37 @@ export class NodeTransport implements Transport { * Log out request processing progress and result. * * @param request - Platform-specific request object. + * @param [requestBody] - POST / PATCH body. * @param [elapsed] - How many times passed since request processing started. * @param [body] - Service response (if available). */ - protected logRequestProcessProgress(request: Request, elapsed?: number, body?: ArrayBuffer) { + protected logRequestProcessProgress( + request: Request, + requestBody: TransportRequest['body'], + elapsed?: number, + body?: ArrayBuffer, + ) { if (!this.logVerbosity) return; const { protocol, host, pathname, search } = new URL(request.url); const timestamp = new Date().toISOString(); if (!elapsed) { + let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; + if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { + if (typeof requestBody === 'string') outgoing += `\n\n${requestBody}`; + else outgoing += `\n\n${NodeTransport.decoder.decode(requestBody)}`; + } + console.log('<<<<<'); - console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + console.log(outgoing); console.log('-----'); } else { - const stringifiedBody = body ? NodeTransport.decoder.decode(body) : undefined; + let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; + if (body) outgoing += `\n\n${NodeTransport.decoder.decode(body)}`; console.log('>>>>>>'); - console.log( - `[${timestamp} / ${elapsed}]`, - `\n${protocol}//${host}${pathname}`, - `\n${search}`, - `\n${stringifiedBody}`, - ); + console.log(outgoing); console.log('-----'); } } diff --git a/src/transport/titanium-transport.ts b/src/transport/titanium-transport.ts index 8836dbcec..b1296ca70 100644 --- a/src/transport/titanium-transport.ts +++ b/src/transport/titanium-transport.ts @@ -50,12 +50,12 @@ export class TitaniumTransport implements Transport { new Promise((resolve, reject) => { const start = new Date().getTime(); - this.logRequestProcessProgress(url); + this.logRequestProcessProgress(url, req.body); xhr.onload = () => { const response = this.transportResponseFromXHR(url, xhr); - this.logRequestProcessProgress(url, new Date().getTime() - start, response.body); + this.logRequestProcessProgress(url, undefined, new Date().getTime() - start, response.body); resolve(response); }; @@ -76,7 +76,7 @@ export class TitaniumTransport implements Transport { body = response.body; } - this.logRequestProcessProgress(url, elapsed, body); + this.logRequestProcessProgress(url, undefined, elapsed, body); reject(error); }; @@ -144,29 +144,37 @@ export class TitaniumTransport implements Transport { * Log out request processing progress and result. * * @param url - Endpoint Url used by {@link Ti.Network.HTTPClient|HTTPClient}. + * @param [requestBody] - POST / PATCH body. * @param [elapsed] - How many times passed since request processing started. * @param [body] - Service response (if available). */ - private logRequestProcessProgress(url: string, elapsed?: number, body?: ArrayBuffer) { + private logRequestProcessProgress( + url: string, + requestBody: TransportRequest['body'], + elapsed?: number, + body?: ArrayBuffer, + ) { if (!this.logVerbosity) return; const { protocol, host, pathname, search } = new URL(url); const timestamp = new Date().toISOString(); if (!elapsed) { + let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; + if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { + if (typeof requestBody === 'string') outgoing += `\n\n${requestBody}`; + else outgoing += `\n\n${TitaniumTransport.decoder.decode(requestBody)}`; + } + Ti.API.info('<<<<<'); - Ti.API.info([`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`]); + Ti.API.info(outgoing); Ti.API.info('-----'); } else { - const stringifiedBody = body ? TitaniumTransport.decoder.decode(body) : undefined; + let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; + if (body) outgoing += `\n\n${TitaniumTransport.decoder.decode(body)}`; Ti.API.info('>>>>>>'); - Ti.API.info([ - `[${timestamp} / ${elapsed}]`, - `\n${protocol}//${host}${pathname}`, - `\n${search}`, - `\n${stringifiedBody}`, - ]); + Ti.API.info(outgoing); Ti.API.info('-----'); } } diff --git a/src/transport/web-react-native-transport.ts b/src/transport/web-react-native-transport.ts index aa25688fe..a07e0ce52 100644 --- a/src/transport/web-react-native-transport.ts +++ b/src/transport/web-react-native-transport.ts @@ -54,7 +54,7 @@ export class WebReactNativeTransport implements Transport { this.requestFromTransportRequest(req).then((request) => { const start = new Date().getTime(); - this.logRequestProcessProgress(request); + this.logRequestProcessProgress(request, req.body); /** * Setup request timeout promise. @@ -94,7 +94,7 @@ export class WebReactNativeTransport implements Transport { if (status >= 400) throw PubNubAPIError.create(transportResponse); - this.logRequestProcessProgress(request, new Date().getTime() - start, responseBody); + this.logRequestProcessProgress(request, undefined, new Date().getTime() - start, responseBody); return transportResponse; }) @@ -162,31 +162,39 @@ export class WebReactNativeTransport implements Transport { * Log out request processing progress and result. * * @param request - Platform-specific + * @param [requestBody] - POST / PATCH body. * @param [elapsed] - How many seconds passed since request processing started. * @param [body] - Service response (if available). * * @internal */ - protected logRequestProcessProgress(request: Request, elapsed?: number, body?: ArrayBuffer) { + protected logRequestProcessProgress( + request: Request, + requestBody: TransportRequest['body'], + elapsed?: number, + body?: ArrayBuffer, + ) { if (!this.logVerbosity) return; const { protocol, host, pathname, search } = new URL(request.url); const timestamp = new Date().toISOString(); if (!elapsed) { - console.log('<<<<<'); - console.log(`[${timestamp}]`, `\n${protocol}//${host}${pathname}`, `\n${search}`); + let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; + if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { + if (typeof requestBody === 'string') outgoing += `\n\n${requestBody}`; + else outgoing += `\n\n${WebReactNativeTransport.decoder.decode(requestBody)}`; + } + + console.log(`<<<<<`); + console.log(outgoing); console.log('-----'); } else { - const stringifiedBody = body ? WebReactNativeTransport.decoder.decode(body) : undefined; + let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; + if (body) outgoing += `\n\n${WebReactNativeTransport.decoder.decode(body)}`; console.log('>>>>>>'); - console.log( - `[${timestamp} / ${elapsed}]`, - `\n${protocol}//${host}${pathname}`, - `\n${search}`, - `\n${stringifiedBody}`, - ); + console.log(outgoing); console.log('-----'); } } diff --git a/test/dist/objectsv2.test.ts b/test/dist/objectsv2.test.ts index dec3002af..dffa0fc3a 100644 --- a/test/dist/objectsv2.test.ts +++ b/test/dist/objectsv2.test.ts @@ -99,7 +99,7 @@ describe('Objects V2 system tests', () => { it('should set memberships', async () => { const result = await pubnub.objects.setMemberships({ uuid: UUID_1, - channels: [{ id: CHANNEL_1, custom: { myData: 42 } }], + channels: [{ id: CHANNEL_1, custom: { myData: 42 }, status: 'active', type: 'test' }], }); expect(result.status).to.equal(200); @@ -119,6 +119,8 @@ describe('Objects V2 system tests', () => { const result = await pubnub.objects.getMemberships({ uuid: UUID_1, include: { + statusField: true, + typeField: true, customFields: true, customChannelFields: true, channelFields: true, @@ -128,6 +130,8 @@ describe('Objects V2 system tests', () => { expect(result.status).to.equal(200); expect(result.data[0].custom?.myData).to.equal(42); assert('name' in result.data[0].channel); + expect(result.data[0].status).to.equal('active'); + expect(result.data[0].type).to.equal('test'); expect(result.data[0].channel?.name).to.equal(CHANNEL_NAME); expect(result.data[0].channel?.custom?.foo).to.be.true; }); diff --git a/test/integration/endpoints/subscribe.test.ts b/test/integration/endpoints/subscribe.test.ts index b3bf5cc5a..1ba01eca7 100644 --- a/test/integration/endpoints/subscribe.test.ts +++ b/test/integration/endpoints/subscribe.test.ts @@ -202,7 +202,7 @@ describe('subscribe endpoints', () => { }); }); - it('supports timetoken', (done) => { + it.only('supports timetoken', (done) => { const scope0 = utils .createNock() .get('/v2/subscribe/mySubKey/c1/0') @@ -341,6 +341,51 @@ describe('subscribe endpoints', () => { subscription.subscribe(); }); + it('presence listener called for interval / delta update', (done) => { + utils + .createNock() + .get('/v2/subscribe/mySubKey/c1,c1-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + heartbeat: 300, + }) + .reply(200, '{"t":{"t":"14523669555221452","r":1},"m":[]}', { 'content-type': 'text/javascript' }); + utils + .createNock() + .get('/v2/subscribe/mySubKey/c1,c1-pnpres/0') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + tt: '14523669555221452', + tr: 1, + heartbeat: 300, + }) + .reply( + 200, + '{"t":{"t":"14523669555221453","r":1},"m":[{"a":"3","f":0,"i":"myUniqueUserId","p":{"t":"17200339136465528","r":41},"k":"mySubKey","c":"c1-pnpres","d":{"action":"interval","timestamp":"1720033913","occupancy":0,"here_now_refresh":true}}]}', + { 'content-type': 'text/javascript' }, + ); + + pubnub.addListener({ + presence(presence) { + try { + assert.equal(presence.action, 'interval'); + if (presence.action === 'interval') { + assert.equal(presence.hereNowRefresh, true); + done(); + } + } catch (error) { + done(error); + } + }, + }); + + const channel = pubnub.channel('c1'); + const subscription = channel.subscription({ receivePresenceEvents: true }); + subscription.subscribe(); + }); + it('supports subscribe() with presence channelnames', () => { const scope0 = utils .createNock() From 1a2ddeb55fbf56616cdb50972d3dc540e8810b2b Mon Sep 17 00:00:00 2001 From: Mohit Tejani <60129002+mohitpubnub@users.noreply.github.com> Date: Thu, 2 Jan 2025 18:32:18 +0530 Subject: [PATCH 30/49] fix: issue of parsing response for here_now (#427) * fix: issue of parsing response for here_now * test: additional assert for hereNow response parsing test * PubNub SDK v8.4.1 release. --------- Co-authored-by: Mohit Tejani Co-authored-by: PubNub Release Bot <120067856+pubnub-release-bot@users.noreply.github.com> --- .pubnub.yml | 11 ++++++++--- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- dist/web/pubnub.js | 4 ++-- dist/web/pubnub.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/endpoints/presence/here_now.js | 2 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/endpoints/presence/here_now.ts | 2 +- test/integration/endpoints/presence.test.ts | 4 +++- 11 files changed, 27 insertions(+), 14 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index d89b6217a..1a081f56e 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2025-01-02 + version: v8.4.1 + changes: + - type: bug + text: "Fixed issue of hereNow response parsing for `totalOccupancy` field." - date: 2024-12-17 version: v8.4.0 changes: @@ -1094,7 +1099,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.4.0' +version: '8.4.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1110,7 +1115,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.4.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.4.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1781,7 +1786,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.4.0/pubnub.8.4.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.4.1/pubnub.8.4.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 347f6156a..4b08bb8c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.4.1 +January 02 2025 + +#### Fixed +- Fixed issue of hereNow response parsing for `totalOccupancy` field. + ## v8.4.0 December 17 2024 diff --git a/README.md b/README.md index 5fbbfd204..0fe803a03 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.4.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.4.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.4.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.4.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index b93bd38f6..8f17817ac 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3961,7 +3961,7 @@ return base.PubNubFile; }, get version() { - return '8.4.0'; + return '8.4.1'; }, getVersion() { return this.version; @@ -8810,7 +8810,7 @@ throw PubNubAPIError.create(response); // Extract general presence information. const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; - const totalOccupancy = 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_channels; + const totalOccupancy = 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_occupancy; const channelsPresence = {}; let channels = {}; // Remap single channel presence to multiple channels presence response. diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 6536a6de1..0aaa9aa38 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},F=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class R{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${R.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${R.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}R.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.4.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Ue=ge("DELAYED_HEARTBEAT",(e=>e));class Fe extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Ue.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Re=new ue("HEARTBEAT_STOPPED");Re.on(ke.type,((e,t)=>Re.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Re.on(Ee.type,((e,t)=>Re.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Re.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Re.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Ue(e))),De.onExit((()=>Ue.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=F(this.channels,e),i=F(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_channels,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class Rt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new R(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.4.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Ue=ge("DELAYED_HEARTBEAT",(e=>e));class Fe extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Ue.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Re=new ue("HEARTBEAT_STOPPED");Re.on(ke.type,((e,t)=>Re.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Re.on(Ee.type,((e,t)=>Re.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Re.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Re.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Ue(e))),De.onExit((()=>Ue.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=F(this.channels,e),i=F(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class Rt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new R(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 2e536d49c..8af34ebdf 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -112,7 +112,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.4.0'; + return '8.4.1'; }, getVersion() { return this.version; diff --git a/lib/core/endpoints/presence/here_now.js b/lib/core/endpoints/presence/here_now.js index 26db534af..7a2a464c4 100644 --- a/lib/core/endpoints/presence/here_now.js +++ b/lib/core/endpoints/presence/here_now.js @@ -73,7 +73,7 @@ class HereNowRequest extends request_1.AbstractRequest { throw pubnub_api_error_1.PubNubAPIError.create(response); // Extract general presence information. const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; - const totalOccupancy = 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_channels; + const totalOccupancy = 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_occupancy; const channelsPresence = {}; let channels = {}; // Remap single channel presence to multiple channels presence response. diff --git a/package.json b/package.json index 6464acfca..ae0052a7d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.4.0", + "version": "8.4.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index f9570d086..a5cd10c48 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -171,7 +171,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.4.0'; + return '8.4.1'; }, getVersion(): string { return this.version; diff --git a/src/core/endpoints/presence/here_now.ts b/src/core/endpoints/presence/here_now.ts index b9d7eb309..a8dacb4d9 100644 --- a/src/core/endpoints/presence/here_now.ts +++ b/src/core/endpoints/presence/here_now.ts @@ -165,7 +165,7 @@ export class HereNowRequest extends AbstractRequest { // Extract general presence information. const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; const totalOccupancy = - 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_channels; + 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_occupancy; const channelsPresence: Presence.HereNowResponse['channels'] = {}; let channels: Required['channels'] = {}; diff --git a/test/integration/endpoints/presence.test.ts b/test/integration/endpoints/presence.test.ts index 139e7a726..3ff847a3d 100644 --- a/test/integration/endpoints/presence.test.ts +++ b/test/integration/endpoints/presence.test.ts @@ -601,7 +601,7 @@ describe('presence endpoints', () => { }) .reply( 200, - ' {"status": 200, "message": "OK", "payload": {"channels": {"ch1": {"uuids": ["a581c974-e2f9-4088-9cc8-9632708e012d"], "occupancy": 1}}, "total_channels": 1, "total_occupancy": 1}, "service": "Presence"}', + ' {"status": 200, "message": "OK", "payload": {"channels": {"ch1": {"uuids": ["a581c974-e2f9-4088-9cc8-9632708e012d"], "occupancy": 1}}, "total_channels": 3, "total_occupancy": 7}, "service": "Presence"}', { 'content-type': 'text/javascript' }, ); @@ -621,6 +621,8 @@ describe('presence endpoints', () => { ] } }); + assert.equal(response.totalChannels, 3); + assert.equal(response.totalOccupancy, 7); assert.equal(scope.isDone(), true); done(); } catch (error) { From 875e44b4254eefdc7a682d6d390bfec303181b45 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 16 Jan 2025 01:17:19 +0200 Subject: [PATCH 31/49] Add file upload and download timeout configuration (#430) feat(file-share): add file upload and download timeout configuration Add `fileRequestTimeout` client configuration option which is specific only for requests which upload and download files. fix: fix `instanceId` query parameter Fix issue with `instanceId` set to `undefined` for requests with `useInstanceId` configuration flag set to `true`. --- .pubnub.yml | 13 ++++-- CHANGELOG.md | 9 ++++ README.md | 4 +- dist/web/pubnub.js | 46 +++++++++++++------- dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 10 ++++- lib/core/interfaces/configuration.js | 27 +++++++----- lib/core/pubnub-common.js | 7 +-- lib/transport/middleware.js | 2 +- lib/types/index.d.ts | 9 ++++ package.json | 2 +- src/core/components/configuration.ts | 9 +++- src/core/interfaces/configuration.ts | 31 +++++++++++++ src/core/pubnub-common.ts | 9 ++-- src/transport/middleware.ts | 2 +- test/integration/endpoints/subscribe.test.ts | 2 +- 16 files changed, 140 insertions(+), 46 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 1a081f56e..cb2eb6aa7 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2025-01-15 + version: v8.5.0 + changes: + - type: feature + text: "Add `fileRequestTimeout` client configuration option which is specific only for requests which upload and download files." + - type: bug + text: "Fix issue with `instanceId` set to `undefined` for requests with `useInstanceId` configuration flag set to `true`." - date: 2025-01-02 version: v8.4.1 changes: @@ -1099,7 +1106,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.4.1' +version: '8.5.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1115,7 +1122,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.4.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.5.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1786,7 +1793,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.4.1/pubnub.8.4.1.js + location: https://github.com/pubnub/javascript/releases/download/v8.5.0/pubnub.8.5.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b08bb8c9..67b53dc53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v8.5.0 +January 15 2025 + +#### Added +- Add `fileRequestTimeout` client configuration option which is specific only for requests which upload and download files. + +#### Fixed +- Fix issue with `instanceId` set to `undefined` for requests with `useInstanceId` configuration flag set to `true`. + ## v8.4.1 January 02 2025 diff --git a/README.md b/README.md index 0fe803a03..38f352a7a 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.4.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.4.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.5.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.5.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 8f17817ac..5d592686c 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3644,6 +3644,10 @@ * Subscription request timeout. */ const SUBSCRIBE_REQUEST_TIMEOUT = 310; + /** + * File upload / download request timeout. + */ + const FILE_REQUEST_TIMEOUT = 300; /** * Default user presence timeout. */ @@ -3660,27 +3664,28 @@ * @internal */ const setDefaults$1 = (configuration) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; // Copy configuration. const configurationCopy = Object.assign({}, configuration); (_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING); (_b = configurationCopy.ssl) !== null && _b !== void 0 ? _b : (configurationCopy.ssl = USE_SSL); (_c = configurationCopy.transactionalRequestTimeout) !== null && _c !== void 0 ? _c : (configurationCopy.transactionalRequestTimeout = TRANSACTIONAL_REQUEST_TIMEOUT); (_d = configurationCopy.subscribeRequestTimeout) !== null && _d !== void 0 ? _d : (configurationCopy.subscribeRequestTimeout = SUBSCRIBE_REQUEST_TIMEOUT); - (_e = configurationCopy.restore) !== null && _e !== void 0 ? _e : (configurationCopy.restore = RESTORE); - (_f = configurationCopy.useInstanceId) !== null && _f !== void 0 ? _f : (configurationCopy.useInstanceId = USE_INSTANCE_ID); - (_g = configurationCopy.suppressLeaveEvents) !== null && _g !== void 0 ? _g : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS); - (_h = configurationCopy.requestMessageCountThreshold) !== null && _h !== void 0 ? _h : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE); - (_j = configurationCopy.autoNetworkDetection) !== null && _j !== void 0 ? _j : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION); - (_k = configurationCopy.enableEventEngine) !== null && _k !== void 0 ? _k : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE); - (_l = configurationCopy.maintainPresenceState) !== null && _l !== void 0 ? _l : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE); - (_m = configurationCopy.keepAlive) !== null && _m !== void 0 ? _m : (configurationCopy.keepAlive = KEEP_ALIVE$1); + (_e = configurationCopy.fileRequestTimeout) !== null && _e !== void 0 ? _e : (configurationCopy.fileRequestTimeout = FILE_REQUEST_TIMEOUT); + (_f = configurationCopy.restore) !== null && _f !== void 0 ? _f : (configurationCopy.restore = RESTORE); + (_g = configurationCopy.useInstanceId) !== null && _g !== void 0 ? _g : (configurationCopy.useInstanceId = USE_INSTANCE_ID); + (_h = configurationCopy.suppressLeaveEvents) !== null && _h !== void 0 ? _h : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS); + (_j = configurationCopy.requestMessageCountThreshold) !== null && _j !== void 0 ? _j : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE); + (_k = configurationCopy.autoNetworkDetection) !== null && _k !== void 0 ? _k : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION); + (_l = configurationCopy.enableEventEngine) !== null && _l !== void 0 ? _l : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE); + (_m = configurationCopy.maintainPresenceState) !== null && _m !== void 0 ? _m : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE); + (_o = configurationCopy.keepAlive) !== null && _o !== void 0 ? _o : (configurationCopy.keepAlive = KEEP_ALIVE$1); if (configurationCopy.userId && configurationCopy.uuid) throw new PubNubError("PubNub client configuration error: use only 'userId'"); - (_o = configurationCopy.userId) !== null && _o !== void 0 ? _o : (configurationCopy.userId = configurationCopy.uuid); + (_p = configurationCopy.userId) !== null && _p !== void 0 ? _p : (configurationCopy.userId = configurationCopy.uuid); if (!configurationCopy.userId) throw new PubNubError("PubNub client configuration error: 'userId' not set"); - else if (((_p = configurationCopy.userId) === null || _p === void 0 ? void 0 : _p.trim().length) === 0) + else if (((_q = configurationCopy.userId) === null || _q === void 0 ? void 0 : _q.trim().length) === 0) throw new PubNubError("PubNub client configuration error: 'userId' is empty"); // Generate default origin subdomains. if (!configurationCopy.origin) @@ -3894,6 +3899,11 @@ return this._instanceId; return undefined; }, + getInstanceId() { + if (this.useInstanceId) + return this._instanceId; + return undefined; + }, getUserId() { return this.userId; }, @@ -3957,11 +3967,14 @@ getSubscribeTimeout() { return this.subscribeRequestTimeout; }, + getFileTimeout() { + return this.fileRequestTimeout; + }, get PubNubFile() { return base.PubNubFile; }, get version() { - return '8.4.1'; + return '8.5.0'; }, getVersion() { return this.version; @@ -4270,7 +4283,7 @@ req.queryParameters = {}; // Modify request with required information. if (clientConfiguration.useInstanceId) - req.queryParameters['instanceid'] = clientConfiguration.instanceId; + req.queryParameters['instanceid'] = clientConfiguration.getInstanceId(); if (!req.queryParameters['uuid']) req.queryParameters['uuid'] = clientConfiguration.userId; if (clientConfiguration.useRequestId) @@ -13037,9 +13050,10 @@ } // Complete request configuration. const transportRequest = request.request(); - if (transportRequest.formData && transportRequest.formData.length > 0) { - // Set 300 seconds file upload request delay. - transportRequest.timeout = 300; + if ((transportRequest.formData && transportRequest.formData.length > 0) || + request.operation() === RequestOperation$1.PNDownloadFileOperation) { + // Set file upload / download request delay. + transportRequest.timeout = this._configuration.getFileTimeout(); } else { if (request.operation() === RequestOperation$1.PNSubscribeOperation) diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 0aaa9aa38..1b9eff100 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},U=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},F=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class R{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${R.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${R.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}R.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y;const f=Object.assign({},e);if(null!==(t=f.logVerbosity)&&void 0!==t||(f.logVerbosity=!1),null!==(s=f.ssl)&&void 0!==s||(f.ssl=!0),null!==(n=f.transactionalRequestTimeout)&&void 0!==n||(f.transactionalRequestTimeout=15),null!==(r=f.subscribeRequestTimeout)&&void 0!==r||(f.subscribeRequestTimeout=310),null!==(i=f.restore)&&void 0!==i||(f.restore=!1),null!==(o=f.useInstanceId)&&void 0!==o||(f.useInstanceId=!1),null!==(a=f.suppressLeaveEvents)&&void 0!==a||(f.suppressLeaveEvents=!1),null!==(c=f.requestMessageCountThreshold)&&void 0!==c||(f.requestMessageCountThreshold=100),null!==(u=f.autoNetworkDetection)&&void 0!==u||(f.autoNetworkDetection=!1),null!==(l=f.enableEventEngine)&&void 0!==l||(f.enableEventEngine=!1),null!==(h=f.maintainPresenceState)&&void 0!==h||(f.maintainPresenceState=!0),null!==(p=f.keepAlive)&&void 0!==p||(f.keepAlive=!1),f.userId&&f.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(g=f.userId)&&void 0!==g||(f.userId=f.uuid),!f.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(y=f.userId)||void 0===y?void 0:y.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");f.origin||(f.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const m={subscribeKey:f.subscribeKey,publishKey:f.publishKey,secretKey:f.secretKey};void 0!==f.presenceTimeout&&f.presenceTimeout<20&&(f.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==f.presenceTimeout?f.heartbeatInterval=f.presenceTimeout/2-1:f.presenceTimeout=300;let b=!1,v=!0,w=5,S=!1,k=100,E=!0;return void 0!==f.dedupeOnSubscribe&&"boolean"==typeof f.dedupeOnSubscribe&&(S=f.dedupeOnSubscribe),void 0!==f.maximumCacheSize&&"number"==typeof f.maximumCacheSize&&(k=f.maximumCacheSize),void 0!==f.useRequestId&&"boolean"==typeof f.useRequestId&&(E=f.useRequestId),void 0!==f.announceSuccessfulHeartbeats&&"boolean"==typeof f.announceSuccessfulHeartbeats&&(b=f.announceSuccessfulHeartbeats),void 0!==f.announceFailedHeartbeats&&"boolean"==typeof f.announceFailedHeartbeats&&(v=f.announceFailedHeartbeats),void 0!==f.fileUploadPublishRetryLimit&&"number"==typeof f.fileUploadPublishRetryLimit&&(w=f.fileUploadPublishRetryLimit),Object.assign(Object.assign({},f),{keySet:m,dedupeOnSubscribe:S,maximumCacheSize:k,useRequestId:E,announceSuccessfulHeartbeats:b,announceFailedHeartbeats:v,fileUploadPublishRetryLimit:w})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.4.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.instanceId),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Ue=ge("DELAYED_HEARTBEAT",(e=>e));class Fe extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Ue.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Re=new ue("HEARTBEAT_STOPPED");Re.on(ke.type,((e,t)=>Re.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Re.on(Ee.type,((e,t)=>Re.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Re.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Re.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Ue(e))),De.onExit((()=>Ue.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=U(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=U(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=F(this.channels,e),i=F(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ut extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class Rt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0?n.timeout=300:e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new R(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},F=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},R=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class U{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${U.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${U.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}U.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.5.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Fe=ge("DELAYED_HEARTBEAT",(e=>e));class Re extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Fe.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Ue=new ue("HEARTBEAT_STOPPED");Ue.on(ke.type,((e,t)=>Ue.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>Ue.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Ue.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Fe(e))),De.onExit((()=>Fe.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Re(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=F(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=F(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=R(this.channels,e),i=R(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ft extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Rt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Rt||(Rt={}));class Ut extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Rt.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Rt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0||e.operation()===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new U(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 8af34ebdf..b90846c3f 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -45,6 +45,11 @@ const makeConfiguration = (base, setupCryptoModule) => { return this._instanceId; return undefined; }, + getInstanceId() { + if (this.useInstanceId) + return this._instanceId; + return undefined; + }, getUserId() { return this.userId; }, @@ -108,11 +113,14 @@ const makeConfiguration = (base, setupCryptoModule) => { getSubscribeTimeout() { return this.subscribeRequestTimeout; }, + getFileTimeout() { + return this.fileRequestTimeout; + }, get PubNubFile() { return base.PubNubFile; }, get version() { - return '8.4.1'; + return '8.5.0'; }, getVersion() { return this.version; diff --git a/lib/core/interfaces/configuration.js b/lib/core/interfaces/configuration.js index c11ca0d07..9749f38ac 100644 --- a/lib/core/interfaces/configuration.js +++ b/lib/core/interfaces/configuration.js @@ -78,6 +78,10 @@ const TRANSACTIONAL_REQUEST_TIMEOUT = 15; * Subscription request timeout. */ const SUBSCRIBE_REQUEST_TIMEOUT = 310; +/** + * File upload / download request timeout. + */ +const FILE_REQUEST_TIMEOUT = 300; /** * Default user presence timeout. */ @@ -94,27 +98,28 @@ const PRESENCE_TIMEOUT_MINIMUM = 20; * @internal */ const setDefaults = (configuration) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; // Copy configuration. const configurationCopy = Object.assign({}, configuration); (_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING); (_b = configurationCopy.ssl) !== null && _b !== void 0 ? _b : (configurationCopy.ssl = USE_SSL); (_c = configurationCopy.transactionalRequestTimeout) !== null && _c !== void 0 ? _c : (configurationCopy.transactionalRequestTimeout = TRANSACTIONAL_REQUEST_TIMEOUT); (_d = configurationCopy.subscribeRequestTimeout) !== null && _d !== void 0 ? _d : (configurationCopy.subscribeRequestTimeout = SUBSCRIBE_REQUEST_TIMEOUT); - (_e = configurationCopy.restore) !== null && _e !== void 0 ? _e : (configurationCopy.restore = RESTORE); - (_f = configurationCopy.useInstanceId) !== null && _f !== void 0 ? _f : (configurationCopy.useInstanceId = USE_INSTANCE_ID); - (_g = configurationCopy.suppressLeaveEvents) !== null && _g !== void 0 ? _g : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS); - (_h = configurationCopy.requestMessageCountThreshold) !== null && _h !== void 0 ? _h : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE); - (_j = configurationCopy.autoNetworkDetection) !== null && _j !== void 0 ? _j : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION); - (_k = configurationCopy.enableEventEngine) !== null && _k !== void 0 ? _k : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE); - (_l = configurationCopy.maintainPresenceState) !== null && _l !== void 0 ? _l : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE); - (_m = configurationCopy.keepAlive) !== null && _m !== void 0 ? _m : (configurationCopy.keepAlive = KEEP_ALIVE); + (_e = configurationCopy.fileRequestTimeout) !== null && _e !== void 0 ? _e : (configurationCopy.fileRequestTimeout = FILE_REQUEST_TIMEOUT); + (_f = configurationCopy.restore) !== null && _f !== void 0 ? _f : (configurationCopy.restore = RESTORE); + (_g = configurationCopy.useInstanceId) !== null && _g !== void 0 ? _g : (configurationCopy.useInstanceId = USE_INSTANCE_ID); + (_h = configurationCopy.suppressLeaveEvents) !== null && _h !== void 0 ? _h : (configurationCopy.suppressLeaveEvents = SUPPRESS_LEAVE_EVENTS); + (_j = configurationCopy.requestMessageCountThreshold) !== null && _j !== void 0 ? _j : (configurationCopy.requestMessageCountThreshold = DEDUPE_CACHE_SIZE); + (_k = configurationCopy.autoNetworkDetection) !== null && _k !== void 0 ? _k : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION); + (_l = configurationCopy.enableEventEngine) !== null && _l !== void 0 ? _l : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE); + (_m = configurationCopy.maintainPresenceState) !== null && _m !== void 0 ? _m : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE); + (_o = configurationCopy.keepAlive) !== null && _o !== void 0 ? _o : (configurationCopy.keepAlive = KEEP_ALIVE); if (configurationCopy.userId && configurationCopy.uuid) throw new pubnub_error_1.PubNubError("PubNub client configuration error: use only 'userId'"); - (_o = configurationCopy.userId) !== null && _o !== void 0 ? _o : (configurationCopy.userId = configurationCopy.uuid); + (_p = configurationCopy.userId) !== null && _p !== void 0 ? _p : (configurationCopy.userId = configurationCopy.uuid); if (!configurationCopy.userId) throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' not set"); - else if (((_p = configurationCopy.userId) === null || _p === void 0 ? void 0 : _p.trim().length) === 0) + else if (((_q = configurationCopy.userId) === null || _q === void 0 ? void 0 : _q.trim().length) === 0) throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' is empty"); // Generate default origin subdomains. if (!configurationCopy.origin) diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 4dcc4aeaa..d8c093a99 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -550,9 +550,10 @@ class PubNubCore { } // Complete request configuration. const transportRequest = request.request(); - if (transportRequest.formData && transportRequest.formData.length > 0) { - // Set 300 seconds file upload request delay. - transportRequest.timeout = 300; + if ((transportRequest.formData && transportRequest.formData.length > 0) || + request.operation() === operations_1.default.PNDownloadFileOperation) { + // Set file upload / download request delay. + transportRequest.timeout = this._configuration.getFileTimeout(); } else { if (request.operation() === operations_1.default.PNSubscribeOperation) diff --git a/lib/transport/middleware.js b/lib/transport/middleware.js index 178534519..c677faef7 100644 --- a/lib/transport/middleware.js +++ b/lib/transport/middleware.js @@ -93,7 +93,7 @@ class PubNubMiddleware { req.queryParameters = {}; // Modify request with required information. if (clientConfiguration.useInstanceId) - req.queryParameters['instanceid'] = clientConfiguration.instanceId; + req.queryParameters['instanceid'] = clientConfiguration.getInstanceId(); if (!req.queryParameters['uuid']) req.queryParameters['uuid'] = clientConfiguration.userId; if (clientConfiguration.useRequestId) diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 2f10643ab..d4861090a 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -2497,6 +2497,15 @@ declare namespace PubNub { * @default `310` seconds */ subscribeRequestTimeout?: number; + /** + * File upload / download request timeout in milliseconds. + * + * Maximum duration for which PubNub client should wait for file upload / download request + * completion. + * + * @default `300` seconds + */ + fileRequestTimeout?: number; /** * `true` to allow catch up on the front-end applications. * diff --git a/package.json b/package.json index ae0052a7d..512356e35 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.4.1", + "version": "8.5.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index a5cd10c48..6e88468a6 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -103,6 +103,10 @@ export const makeConfiguration = ( if (this.useInstanceId) return this._instanceId; return undefined; }, + getInstanceId(): string | undefined { + if (this.useInstanceId) return this._instanceId; + return undefined; + }, getUserId() { return this.userId!; }, @@ -167,11 +171,14 @@ export const makeConfiguration = ( getSubscribeTimeout(): number { return this.subscribeRequestTimeout!; }, + getFileTimeout(): number { + return this.fileRequestTimeout!; + }, get PubNubFile(): PubNubFileConstructor | undefined { return base.PubNubFile; }, get version(): string { - return '8.4.1'; + return '8.5.0'; }, getVersion(): string { return this.version; diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index 2acb0186f..d0817a50b 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -99,6 +99,11 @@ const TRANSACTIONAL_REQUEST_TIMEOUT = 15; */ const SUBSCRIBE_REQUEST_TIMEOUT = 310; +/** + * File upload / download request timeout. + */ +const FILE_REQUEST_TIMEOUT = 300; + /** * Default user presence timeout. */ @@ -218,6 +223,16 @@ export type UserConfiguration = { */ subscribeRequestTimeout?: number; + /** + * File upload / download request timeout in milliseconds. + * + * Maximum duration for which PubNub client should wait for file upload / download request + * completion. + * + * @default `300` seconds + */ + fileRequestTimeout?: number; + /** * `true` to allow catch up on the front-end applications. * @@ -617,6 +632,14 @@ export interface PrivateClientConfiguration */ getSubscribeTimeout(): number; + /** + * File requests timeout. + * + * @returns Maximum duration in milliseconds for which PubNub client should wait for + * file upload / download request completion. + */ + getFileTimeout(): number; + /** * PubNub file object constructor. */ @@ -629,6 +652,13 @@ export interface PrivateClientConfiguration */ get instanceId(): string | undefined; + /** + * Get PubNub client instance identifier. + * + * @returns Current PubNub client instance identifier. + */ + getInstanceId(): string | undefined; + /** * Get SDK family identifier. * @@ -698,6 +728,7 @@ export const setDefaults = (configuration: UserConfiguration): ExtendedConfigura configurationCopy.ssl ??= USE_SSL; configurationCopy.transactionalRequestTimeout ??= TRANSACTIONAL_REQUEST_TIMEOUT; configurationCopy.subscribeRequestTimeout ??= SUBSCRIBE_REQUEST_TIMEOUT; + configurationCopy.fileRequestTimeout ??= FILE_REQUEST_TIMEOUT; configurationCopy.restore ??= RESTORE; configurationCopy.useInstanceId ??= USE_INSTANCE_ID; configurationCopy.suppressLeaveEvents ??= SUPPRESS_LEAVE_EVENTS; diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index 97202a480..28071acb2 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -806,9 +806,12 @@ export class PubNubCore< // Complete request configuration. const transportRequest = request.request(); - if (transportRequest.formData && transportRequest.formData.length > 0) { - // Set 300 seconds file upload request delay. - transportRequest.timeout = 300; + if ( + (transportRequest.formData && transportRequest.formData.length > 0) || + request.operation() === RequestOperation.PNDownloadFileOperation + ) { + // Set file upload / download request delay. + transportRequest.timeout = this._configuration.getFileTimeout(); } else { if (request.operation() === RequestOperation.PNSubscribeOperation) transportRequest.timeout = this._configuration.getSubscribeTimeout(); diff --git a/src/transport/middleware.ts b/src/transport/middleware.ts index 8e67bfdc6..9ef69c0a4 100644 --- a/src/transport/middleware.ts +++ b/src/transport/middleware.ts @@ -137,7 +137,7 @@ export class PubNubMiddleware implements Transport { if (!req.queryParameters) req.queryParameters = {}; // Modify request with required information. - if (clientConfiguration.useInstanceId) req.queryParameters['instanceid'] = clientConfiguration.instanceId!; + if (clientConfiguration.useInstanceId) req.queryParameters['instanceid'] = clientConfiguration.getInstanceId()!; if (!req.queryParameters['uuid']) req.queryParameters['uuid'] = clientConfiguration.userId!; if (clientConfiguration.useRequestId) req.queryParameters['requestid'] = req.identifier; req.queryParameters['pnsdk'] = this.generatePNSDK(); diff --git a/test/integration/endpoints/subscribe.test.ts b/test/integration/endpoints/subscribe.test.ts index 1ba01eca7..2b4b3bad5 100644 --- a/test/integration/endpoints/subscribe.test.ts +++ b/test/integration/endpoints/subscribe.test.ts @@ -202,7 +202,7 @@ describe('subscribe endpoints', () => { }); }); - it.only('supports timetoken', (done) => { + it('supports timetoken', (done) => { const scope0 = utils .createNock() .get('/v2/subscribe/mySubKey/c1/0') From f5f96705a1c97e81867040b5e79d8752958a5047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojtek=20Kalici=C5=84ski?= <146713236+wkal-pubnub@users.noreply.github.com> Date: Tue, 21 Jan 2025 15:52:59 +0100 Subject: [PATCH 32/49] Preliminary If-Match ETag support for User and Channel (#432) Preliminary If-Match ETag support for User and Channel --------- Co-authored-by: Mohit Tejani --- .pubnub.yml | 11 ++++++++--- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- dist/web/pubnub.js | 18 +++++++++++++++++- dist/web/pubnub.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/endpoints/objects/channel/set.js | 8 ++++++++ lib/core/endpoints/objects/uuid/set.js | 8 ++++++++ lib/types/index.d.ts | 10 ++++++++++ package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/endpoints/objects/channel/set.ts | 8 ++++++++ src/core/endpoints/objects/uuid/set.ts | 8 ++++++++ src/core/types/api/app-context.ts | 12 ++++++++++++ 14 files changed, 91 insertions(+), 10 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index cb2eb6aa7..2bca576a4 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2025-01-21 + version: v8.6.0 + changes: + - type: feature + text: "A new optional parameter `ifMatchesEtag` is added to `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the ETag on the server and if they don't match a HTTP 412 error is returned." - date: 2025-01-15 version: v8.5.0 changes: @@ -1106,7 +1111,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.5.0' +version: '8.6.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1122,7 +1127,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.5.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.6.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1793,7 +1798,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.5.0/pubnub.8.5.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.6.0/pubnub.8.6.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 67b53dc53..c5637e2f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.6.0 +January 21 2025 + +#### Added +- A new optional parameter `ifMatchesEtag` is added to `setUUIDMetadata` and `setChannelMetadata`. When provided, the server compares the argument value with the ETag on the server and if they don't match a HTTP 412 error is returned. + ## v8.5.0 January 15 2025 diff --git a/README.md b/README.md index 38f352a7a..c7d5830b4 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.5.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.5.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.6.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.6.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 5d592686c..25532581c 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3974,7 +3974,7 @@ return base.PubNubFile; }, get version() { - return '8.5.0'; + return '8.6.0'; }, getVersion() { return this.version; @@ -11553,6 +11553,14 @@ if (!this.parameters.data) return 'Data cannot be empty'; } + get headers() { + if (this.parameters.ifMatchesEtag) { + return { 'If-Match': this.parameters.ifMatchesEtag }; + } + else { + return undefined; + } + } parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); @@ -11972,6 +11980,14 @@ if (!this.parameters.data) return 'Data cannot be empty'; } + get headers() { + if (this.parameters.ifMatchesEtag) { + return { 'If-Match': this.parameters.ifMatchesEtag }; + } + else { + return undefined; + } + } parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 1b9eff100..f49c6dee8 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},F=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},R=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class U{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${U.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${U.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}U.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.5.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Fe=ge("DELAYED_HEARTBEAT",(e=>e));class Re extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Fe.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Ue=new ue("HEARTBEAT_STOPPED");Ue.on(ke.type,((e,t)=>Ue.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>Ue.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Ue.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Fe(e))),De.onExit((()=>Fe.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Re(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=F(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=F(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=R(this.channels,e),i=R(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ft extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Rt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Rt||(Rt={}));class Ut extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Rt.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Rt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0||e.operation()===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new U(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.6.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Fe=ge("DELAYED_HEARTBEAT",(e=>e));class Re extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Fe.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Ue=new ue("HEARTBEAT_STOPPED");Ue.on(ke.type,((e,t)=>Ue.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>Ue.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Ue.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Fe(e))),De.onExit((()=>Fe.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Re(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=F(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=F(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=R(this.channels,e),i=R(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ft extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Rt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Rt||(Rt={}));class Ut extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Rt.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Rt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0||e.operation()===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new U(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index b90846c3f..f6be7f6d3 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.5.0'; + return '8.6.0'; }, getVersion() { return this.version; diff --git a/lib/core/endpoints/objects/channel/set.js b/lib/core/endpoints/objects/channel/set.js index 676fffbb8..9868323f0 100644 --- a/lib/core/endpoints/objects/channel/set.js +++ b/lib/core/endpoints/objects/channel/set.js @@ -57,6 +57,14 @@ class SetChannelMetadataRequest extends request_1.AbstractRequest { if (!this.parameters.data) return 'Data cannot be empty'; } + get headers() { + if (this.parameters.ifMatchesEtag) { + return { 'If-Match': this.parameters.ifMatchesEtag }; + } + else { + return undefined; + } + } parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); diff --git a/lib/core/endpoints/objects/uuid/set.js b/lib/core/endpoints/objects/uuid/set.js index 01af971eb..48680a812 100644 --- a/lib/core/endpoints/objects/uuid/set.js +++ b/lib/core/endpoints/objects/uuid/set.js @@ -60,6 +60,14 @@ class SetUUIDMetadataRequest extends request_1.AbstractRequest { if (!this.parameters.data) return 'Data cannot be empty'; } + get headers() { + if (this.parameters.ifMatchesEtag) { + return { 'If-Match': this.parameters.ifMatchesEtag }; + } + else { + return undefined; + } + } parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index d4861090a..a660f5a14 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -5627,6 +5627,11 @@ declare namespace PubNub { * Fields which can be additionally included into response. */ include?: Omit; + /** + * Optional entity tag from a previously received `PNUUIDMetadata`. The request + * will fail if this parameter is specified and the ETag value on the server doesn't match. + */ + ifMatchesEtag?: string; }; /** @@ -5752,6 +5757,11 @@ declare namespace PubNub { * Fields which can be additionally included into response. */ include?: Omit; + /** + * Optional entity tag from a previously received `PNUUIDMetadata`. The request + * will fail if this parameter is specified and the ETag value on the server doesn't match. + */ + ifMatchesEtag?: string; }; /** diff --git a/package.json b/package.json index 512356e35..f36dbfe8a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.5.0", + "version": "8.6.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 6e88468a6..eb5875612 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.5.0'; + return '8.6.0'; }, getVersion(): string { return this.version; diff --git a/src/core/endpoints/objects/channel/set.ts b/src/core/endpoints/objects/channel/set.ts index bdd07897d..dd82075b6 100644 --- a/src/core/endpoints/objects/channel/set.ts +++ b/src/core/endpoints/objects/channel/set.ts @@ -67,6 +67,14 @@ export class SetChannelMetadataRequest< if (!this.parameters.data) return 'Data cannot be empty'; } + protected get headers(): Record | undefined { + if (this.parameters.ifMatchesEtag) { + return { 'If-Match': this.parameters.ifMatchesEtag }; + } else { + return undefined; + } + } + async parse(response: TransportResponse): Promise { const serviceResponse = this.deserializeResponse(response); diff --git a/src/core/endpoints/objects/uuid/set.ts b/src/core/endpoints/objects/uuid/set.ts index 5a5b29789..879689a76 100644 --- a/src/core/endpoints/objects/uuid/set.ts +++ b/src/core/endpoints/objects/uuid/set.ts @@ -70,6 +70,14 @@ export class SetUUIDMetadataRequest< if (!this.parameters.data) return 'Data cannot be empty'; } + protected get headers(): Record | undefined { + if (this.parameters.ifMatchesEtag) { + return { 'If-Match': this.parameters.ifMatchesEtag }; + } else { + return undefined; + } + } + async parse(response: TransportResponse): Promise { const serviceResponse = this.deserializeResponse(response); diff --git a/src/core/types/api/app-context.ts b/src/core/types/api/app-context.ts index 5fa8d0ce2..5feeb707d 100644 --- a/src/core/types/api/app-context.ts +++ b/src/core/types/api/app-context.ts @@ -689,6 +689,12 @@ export type SetUUIDMetadataParameters = { * Fields which can be additionally included into response. */ include?: Omit; + + /** + * Optional entity tag from a previously received `PNUUIDMetadata`. The request + * will fail if this parameter is specified and the ETag value on the server doesn't match. + */ + ifMatchesEtag?: string; }; /** @@ -827,6 +833,12 @@ export type SetChannelMetadataParameters = { * Fields which can be additionally included into response. */ include?: Omit; + + /** + * Optional entity tag from a previously received `PNUUIDMetadata`. The request + * will fail if this parameter is specified and the ETag value on the server doesn't match. + */ + ifMatchesEtag?: string; }; /** From 0d424f980f03ce5fee0c5c02cf34aef50cf943ef Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 30 Jan 2025 20:06:49 +0200 Subject: [PATCH 33/49] Move heartbeat call into `SharedWorker` (#433) feat(shared-worker): move heartbeat call into `SharedWorker` Pass heartbeat request through `SharedWorker` (if used) to optimize the number of requests for clients opened in few tabs and subscribed to the same channels / groups list. refactor(heartbeat): remove redundant `heartbeat` from unsubscribe Don't send `heartbeat` request on unsubscribe. --- .pubnub.yml | 13 +- CHANGELOG.md | 9 + README.md | 4 +- dist/web/pubnub.js | 21 +- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 258 +++++++++++++- dist/web/pubnub.worker.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/core/components/subscription-manager.js | 13 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/components/subscription-manager.ts | 12 +- .../subscription-worker-middleware.ts | 12 +- .../subscription-worker.ts | 337 +++++++++++++++++- src/web/index.ts | 1 + 15 files changed, 635 insertions(+), 59 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 2bca576a4..9fb6eedd4 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2025-01-30 + version: v8.7.0 + changes: + - type: feature + text: "Pass heartbeat request through `SharedWorker` (if used) to optimize the number of requests for clients opened in few tabs and subscribed on same channels / groups list." + - type: improvement + text: "Don't send `heartbeat` request to unsubscribe." - date: 2025-01-21 version: v8.6.0 changes: @@ -1111,7 +1118,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.6.0' +version: '8.7.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1127,7 +1134,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.6.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.7.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1798,7 +1805,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.6.0/pubnub.8.6.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.7.0/pubnub.8.7.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index c5637e2f7..b886b9fe8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v8.7.0 +January 30 2025 + +#### Added +- Pass heartbeat request through `SharedWorker` (if used) to optimize the number of requests for clients opened in few tabs and subscribed on same channels / groups list. + +#### Modified +- Don't send `heartbeat` request to unsubscribe. + ## v8.6.0 January 21 2025 diff --git a/README.md b/README.md index c7d5830b4..124b6026d 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.6.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.6.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 25532581c..d4205ef77 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3078,7 +3078,7 @@ } makeSendable(req) { // Use default request flow for non-subscribe / presence leave requests. - if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/leave')) + if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/heartbeat') && !req.path.endsWith('/leave')) return this.configuration.transport.makeSendable(req); let controller; const sendRequestEvent = { @@ -3188,6 +3188,7 @@ clientIdentifier: this.configuration.clientIdentifier, subscriptionKey: this.configuration.subscriptionKey, userId: this.configuration.userId, + heartbeatInterval: this.configuration.heartbeatInterval, logVerbosity: this.configuration.logVerbosity, workerLogVerbosity: this.configuration.workerLogVerbosity, }, true); @@ -3212,7 +3213,7 @@ else if (data.type === 'shared-worker-console-dir') { if (data.message) console.log(`[SharedWorker] ${data.message}`); - console.dir(data.data); + console.dir(data.data, { depth: 10 }); } else if (data.type === 'shared-worker-ping') { const { logVerbosity, subscriptionKey, clientIdentifier } = this.configuration; @@ -3974,7 +3975,7 @@ return base.PubNubFile; }, get version() { - return '8.6.0'; + return '8.7.0'; }, getVersion() { return this.version; @@ -4708,9 +4709,16 @@ this.stopHeartbeatTimer(); this.reconnectionManager.stopPolling(); } - reconnect() { + /** + * Restart subscription loop with current state. + * + * @param forUnsubscribe - Whether restarting subscription loop as part of channels list change on + * unsubscribe or not. + */ + reconnect(forUnsubscribe = false) { this.startSubscribeLoop(); - this.startHeartbeatTimer(); + if (!forUnsubscribe) + this.startHeartbeatTimer(); } /** * Update channels and groups used in subscription loop. @@ -4809,7 +4817,7 @@ this.region = null; this.reconnectionManager.stopPolling(); } - this.reconnect(); + this.reconnect(true); } unsubscribeAll(isOffline) { this.unsubscribe({ @@ -14546,6 +14554,7 @@ userId: clientConfiguration.getUserId(), workerUrl: configurationCopy.subscriptionWorkerUrl, sdkVersion: clientConfiguration.getVersion(), + heartbeatInterval: clientConfiguration.getHeartbeatInterval(), logVerbosity: clientConfiguration.logVerbosity, workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity, transport, diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index f49c6dee8..2e2ed8010 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data);else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},F=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},R=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class U{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${U.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${U.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}U.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.6.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect())}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Fe=ge("DELAYED_HEARTBEAT",(e=>e));class Re extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Fe.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Ue=new ue("HEARTBEAT_STOPPED");Ue.on(ke.type,((e,t)=>Ue.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>Ue.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Ue.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Fe(e))),De.onExit((()=>Fe.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Re(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=F(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=F(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=R(this.channels,e),i=R(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ft extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Rt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Rt||(Rt={}));class Ut extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Rt.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Rt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0||e.operation()===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new U(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},F=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},R=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class U{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${U.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${U.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}U.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.7.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Fe=ge("DELAYED_HEARTBEAT",(e=>e));class Re extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Fe.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Ue=new ue("HEARTBEAT_STOPPED");Ue.on(ke.type,((e,t)=>Ue.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>Ue.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Ue.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Fe(e))),De.onExit((()=>Fe.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Re(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=F(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=F(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=R(this.channels,e),i=R(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ft extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Rt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Rt||(Rt={}));class Ut extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Rt.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Rt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0||e.operation()===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new U(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index 3d8b4ec58..b3a5f56b5 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -161,6 +161,10 @@ * Per-subscription key list of PubNub client state. */ const pubNubClientsBySubscriptionKey = {}; + /** + * Per-subscription key map of heartbeat request configurations recently used for user. + */ + const serviceHeartbeatRequests = {}; /** * Per-subscription key presence state associated with unique user identifiers with which {@link pubNubClients|clients} * scheduled subscription request. @@ -211,7 +215,7 @@ handleClientPong(data); else if (data.type === 'send-request') { if (data.request.path.startsWith('/v2/subscribe')) { - updateClientStateIfRequired(data); + updateClientSubscribeStateIfRequired(data); const client = pubNubClients[data.clientIdentifier]; if (client) { const timerIdentifier = `${client.userId}-${client.subscriptionKey}`; @@ -225,6 +229,10 @@ } } } + else if (data.request.path.endsWith('/heartbeat')) { + updateClientHeartbeatState(data); + handleHeartbeatRequestEvent(data); + } else handleSendLeaveRequestEvent(data); } @@ -247,7 +255,7 @@ if (client) { if (client.subscription) isInitialSubscribe = client.subscription.timetoken === '0'; - notifyRequestProcessing('start', [client], new Date().toISOString()); + notifyRequestProcessing('start', [client], new Date().toISOString(), event.request); } if (typeof requestOrId === 'string') { const scheduledRequest = serviceRequests[requestOrId]; @@ -281,12 +289,12 @@ const { timetokenOverride, regionOverride } = scheduledRequest; sendRequest(requestOrId, () => clientsForRequest(requestOrId.identifier), (clients, response) => { // Notify each PubNub client which awaited for response. - notifyRequestProcessingResult(clients, response); + notifyRequestProcessingResult(clients, response, event.request); // Clean up scheduled request and client references to it. markRequestCompleted(clients, requestOrId.identifier); }, (clients, error) => { // Notify each PubNub client which awaited for response. - notifyRequestProcessingResult(clients, null, requestOrId, requestProcessingError(error)); + notifyRequestProcessingResult(clients, null, event.request, requestProcessingError(error)); // Clean up scheduled request and client references to it. markRequestCompleted(clients, requestOrId.identifier); }, (response) => { @@ -337,6 +345,55 @@ } return body.byteLength > 0 ? [decidedResponse, body] : serverResponse; }; + /** + * Handle client heartbeat request. + * + * @param event - Heartbeat event details. + */ + const handleHeartbeatRequestEvent = (event) => { + var _a; + const client = pubNubClients[event.clientIdentifier]; + const request = heartbeatTransportRequestFromEvent(event); + if (!client) + return; + const heartbeatRequestKey = `${client.userId}_${(_a = client.authKey) !== null && _a !== void 0 ? _a : ''}`; + const hbRequestsBySubscriptionKey = serviceHeartbeatRequests[client.subscriptionKey]; + const hbRequests = (hbRequestsBySubscriptionKey !== null && hbRequestsBySubscriptionKey !== void 0 ? hbRequestsBySubscriptionKey : {})[heartbeatRequestKey]; + notifyRequestProcessing('start', [client], new Date().toISOString(), request); + if (!request) { + consoleLog(`Previous heartbeat request has been sent less than ${client.heartbeatInterval} seconds ago. Skipping...`); + let response; + let body; + // Pulling out previous response. + if (hbRequests && hbRequests.response) + [response, body] = hbRequests.response; + if (!response) { + body = new TextEncoder().encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer; + const headers = new Headers({ + 'Content-Type': 'text/javascript; charset="UTF-8"', + 'Content-Length': `${body.byteLength}`, + }); + response = new Response(body, { status: 200, headers }); + } + const result = requestProcessingSuccess([response, body]); + result.url = `${event.request.origin}${event.request.path}`; + result.clientIdentifier = event.clientIdentifier; + result.identifier = event.request.identifier; + notifyRequestProcessing('end', [client], new Date().toISOString(), event.request, body, response.headers.get('Content-Type'), 0); + publishClientEvent(client, result); + return; + } + sendRequest(request, () => [client], (clients, response) => { + if (hbRequests) + hbRequests.response = response; + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, response, event.request); + }, (clients, error) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, null, event.request, requestProcessingError(error)); + }); + consoleLog(`Started heartbeat request.`, client); + }; /** * Handle client request to leave request. * @@ -699,6 +756,93 @@ } return request; }; + /** + * Construct transport request from send heartbeat request event. + * + * Update transport request to aggregate channels and groups if possible. + * + * @param event - Client's send heartbeat event request. + * + * @returns Final transport request or identifier from active request which will provide response to required + * channels and groups. + */ + const heartbeatTransportRequestFromEvent = (event) => { + var _a, _b, _c, _d; + var _e; + const client = pubNubClients[event.clientIdentifier]; + const clients = clientsForSendHeartbeatRequestEvent(event); + const request = Object.assign({}, event.request); + if (!client || !client.heartbeat) + return undefined; + const hbRequestsBySubscriptionKey = ((_a = serviceHeartbeatRequests[_e = client.subscriptionKey]) !== null && _a !== void 0 ? _a : (serviceHeartbeatRequests[_e] = {})); + const heartbeatRequestKey = `${client.userId}_${(_b = client.authKey) !== null && _b !== void 0 ? _b : ''}`; + const channelGroupsForAnnouncement = client.heartbeat.channelGroups; + const channelsForAnnouncement = client.heartbeat.channels; + let aggregatedState = {}; + let failedPreviousRequest = false; + let aggregated = true; + if (!hbRequestsBySubscriptionKey[heartbeatRequestKey]) { + hbRequestsBySubscriptionKey[heartbeatRequestKey] = { + channels: channelsForAnnouncement, + channelGroups: channelGroupsForAnnouncement, + timestamp: Date.now(), + }; + aggregatedState = (_c = client.heartbeat.presenceState) !== null && _c !== void 0 ? _c : {}; + aggregated = false; + } + else { + const { channels, channelGroups, response } = hbRequestsBySubscriptionKey[heartbeatRequestKey]; + aggregatedState = (_d = client.heartbeat.presenceState) !== null && _d !== void 0 ? _d : {}; + aggregated = + includesStrings(channels, client.heartbeat.channels) && + includesStrings(channelGroups, client.heartbeat.channelGroups); + if (response) + failedPreviousRequest = response[0].status >= 400; + } + if (aggregated) { + const expectedTimestamp = hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp + client.heartbeatInterval * 1000; + const currentTimestamp = Date.now(); + // Check whether it is too soon to send request or not (5 is leeway which let send request a bit earlier). + // Request should be sent if previous attempt failed. + if (!failedPreviousRequest && currentTimestamp < expectedTimestamp && expectedTimestamp - currentTimestamp > 5000) + return undefined; + delete hbRequestsBySubscriptionKey[heartbeatRequestKey].response; + // Aggregate channels for similar clients which is pending for heartbeat. + for (const client of clients) { + const { heartbeat } = client; + if (heartbeat === undefined || client.clientIdentifier === event.clientIdentifier) + continue; + // Append presence state from the client (will override previously set value if already set). + if (heartbeat.presenceState) + aggregatedState = Object.assign(Object.assign({}, aggregatedState), heartbeat.presenceState); + channelGroupsForAnnouncement.push(...heartbeat.channelGroups.filter((channel) => !channelGroupsForAnnouncement.includes(channel))); + channelsForAnnouncement.push(...heartbeat.channels.filter((channel) => !channelsForAnnouncement.includes(channel))); + } + } + hbRequestsBySubscriptionKey[heartbeatRequestKey].channels = channelsForAnnouncement; + hbRequestsBySubscriptionKey[heartbeatRequestKey].channelGroups = channelGroupsForAnnouncement; + hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp = Date.now(); + // Remove presence state for objects which is not part of heartbeat. + for (const objectName in Object.keys(aggregatedState)) { + if (!channelsForAnnouncement.includes(objectName) && !channelGroupsForAnnouncement.includes(objectName)) + delete aggregatedState[objectName]; + } + // Update request channels list (if required). + if (channelsForAnnouncement.length) { + const pathComponents = request.path.split('/'); + pathComponents[6] = channelsForAnnouncement.join(','); + request.path = pathComponents.join('/'); + } + // Update request channel groups list (if required). + if (channelGroupsForAnnouncement.length) + request.queryParameters['channel-group'] = channelGroupsForAnnouncement.join(','); + // Update request `state` (if required). + if (Object.keys(aggregatedState).length) + request.queryParameters['state'] = JSON.stringify(aggregatedState); + else + delete request.queryParameters['state']; + return request; + }; /** * Construct transport request from send leave request event. * @@ -715,13 +859,21 @@ let channelGroups = channelGroupsFromRequest(event.request); let channels = channelsFromRequest(event.request); const request = Object.assign({}, event.request); + // Remove channels / groups from active client's subscription. if (client && client.subscription) { const { subscription } = client; if (channels.length) subscription.channels = subscription.channels.filter((channel) => !channels.includes(channel)); - if (channelGroups.length) { + if (channelGroups.length) subscription.channelGroups = subscription.channelGroups.filter((group) => !channelGroups.includes(group)); - } + } + // Remove channels / groups from client's presence heartbeat state. + if (client && client.heartbeat) { + const { heartbeat } = client; + if (channels.length) + heartbeat.channels = heartbeat.channels.filter((channel) => !channels.includes(channel)); + if (channelGroups.length) + heartbeat.channelGroups = heartbeat.channelGroups.filter((channel) => !channelGroups.includes(channel)); } // Filter out channels and groups which is still in use by the other PubNub client instances. for (const client of clients) { @@ -788,10 +940,11 @@ * @param [duration] - How long it took to complete request. */ const notifyRequestProcessing = (type, clients, timestamp, request, responseBody, contentType, duration) => { - var _a; + var _a, _b; if (clients.length === 0) return; const clientIds = (_a = sharedWorkerClients[clients[0].subscriptionKey]) !== null && _a !== void 0 ? _a : {}; + const isSubscribeRequest = request && request.path.startsWith('/v2/subscribe'); let event; if (type === 'start') { event = { @@ -821,11 +974,13 @@ }; } for (const client of clients) { - if (client.subscription === undefined) + if (isSubscribeRequest && !client.subscription) continue; const serviceWorkerClientId = clientIds[client.clientIdentifier]; - const { request: clientRequest } = client.subscription; - const decidedRequest = clientRequest !== null && clientRequest !== void 0 ? clientRequest : request; + const { request: clientRequest } = (_b = client.subscription) !== null && _b !== void 0 ? _b : {}; + let decidedRequest = clientRequest !== null && clientRequest !== void 0 ? clientRequest : request; + if (!isSubscribeRequest) + decidedRequest = request; if (client.logVerbosity && serviceWorkerClientId && decidedRequest) { const payload = Object.assign(Object.assign({}, event), { clientIdentifier: client.clientIdentifier, url: `${decidedRequest.origin}${decidedRequest.path}`, query: decidedRequest.queryParameters }); publishClientEvent(client, payload); @@ -841,12 +996,13 @@ * @param [result] - Explicit request processing result which should be notified. */ const notifyRequestProcessingResult = (clients, response, request, result) => { - var _a; + var _a, _b; if (clients.length === 0) return; if (!result && !response) return; const clientIds = (_a = sharedWorkerClients[clients[0].subscriptionKey]) !== null && _a !== void 0 ? _a : {}; + const isSubscribeRequest = request && request.path.startsWith('/v2/subscribe'); if (!result && response) { result = response[0].status >= 400 @@ -855,11 +1011,13 @@ : requestProcessingSuccess(response); } for (const client of clients) { - if (client.subscription === undefined) + if (isSubscribeRequest && !client.subscription) continue; const serviceWorkerClientId = clientIds[client.clientIdentifier]; - const { request: clientRequest } = client.subscription; - const decidedRequest = clientRequest !== null && clientRequest !== void 0 ? clientRequest : request; + const { request: clientRequest } = (_b = client.subscription) !== null && _b !== void 0 ? _b : {}; + let decidedRequest = clientRequest !== null && clientRequest !== void 0 ? clientRequest : request; + if (!isSubscribeRequest) + decidedRequest = request; if (serviceWorkerClientId && decidedRequest) { const payload = Object.assign(Object.assign({}, result), { clientIdentifier: client.clientIdentifier, identifier: decidedRequest.identifier, url: `${decidedRequest.origin}${decidedRequest.path}` }); publishClientEvent(client, payload); @@ -912,7 +1070,7 @@ * @returns Request processing error event object. */ const requestProcessingError = (error, res) => { - // User service response as error information source. + // Use service response as error information source. if (res) { return Object.assign(Object.assign({}, requestProcessingSuccess(res)), { type: 'request-process-error' }); } @@ -961,6 +1119,7 @@ clientIdentifier, subscriptionKey: event.subscriptionKey, userId: event.userId, + heartbeatInterval: event.heartbeatInterval, logVerbosity: event.logVerbosity, }); // Map registered PubNub client to its subscription key. @@ -983,7 +1142,7 @@ * * @param event - Send request. */ - const updateClientStateIfRequired = (event) => { + const updateClientSubscribeStateIfRequired = (event) => { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; var _m, _o, _p, _q, _r, _s, _t, _u, _v; const query = event.request.queryParameters; @@ -1040,6 +1199,7 @@ subscription.channelGroupQuery = channelGroupQuery; subscription.channelGroups = channelGroupsFromRequest(event.request); } + const { authKey, userId } = client; subscription.request = event.request; subscription.filterExpression = ((_j = query['filter-expr']) !== null && _j !== void 0 ? _j : ''); subscription.timetoken = ((_k = query.tt) !== null && _k !== void 0 ? _k : '0'); @@ -1047,6 +1207,53 @@ subscription.region = query.tr; client.authKey = ((_l = query.auth) !== null && _l !== void 0 ? _l : ''); client.userId = query.uuid; + handleClientIdentityChangeIfRequired(client, userId, authKey); + }; + /** + * Update presence heartbeat information for previously registered client. + * + * Use information from request to populate list of channels / groups and presence state information. + * + * @param event - Send heartbeat request event. + */ + const updateClientHeartbeatState = (event) => { + var _a, _b; + const client = pubNubClients[event.clientIdentifier]; + const { request } = event; + // This should never happen. + if (!client) + return; + const _clientHeartbeat = ((_a = client.heartbeat) !== null && _a !== void 0 ? _a : (client.heartbeat = { + channels: [], + channelGroups: [], + })); + // Update presence heartbeat information about client. + _clientHeartbeat.channelGroups = channelGroupsFromRequest(request).filter((group) => !group.endsWith('-pnpres')); + _clientHeartbeat.channels = channelsFromRequest(request).filter((channel) => !channel.endsWith('-pnpres')); + const state = ((_b = request.queryParameters.state) !== null && _b !== void 0 ? _b : ''); + if (state.length > 0) { + const userPresenceState = JSON.parse(state); + for (const objectName of Object.keys(userPresenceState)) + if (!_clientHeartbeat.channels.includes(objectName) && !_clientHeartbeat.channelGroups.includes(objectName)) + delete userPresenceState[objectName]; + _clientHeartbeat.presenceState = userPresenceState; + } + }; + /** + * Check whether PubNub client identity has been changed between state refresh or not. + * + * @param client - PubNub client state which will be checked. + * @param userId - `userId` which has been used by `PubNub` client before state refresh. + * @param authKey - `authKey` which has been used by `PubNub` client before state refresh. + */ + const handleClientIdentityChangeIfRequired = (client, userId, authKey) => { + var _a, _b; + if (!client || (userId === client.userId && (authKey !== null && authKey !== void 0 ? authKey : '') === ((_a = client.authKey) !== null && _a !== void 0 ? _a : ''))) + return; + const _heartbeatRequests = (_b = serviceHeartbeatRequests[client.subscriptionKey]) !== null && _b !== void 0 ? _b : {}; + const heartbeatRequestKey = `${userId}_${authKey !== null && authKey !== void 0 ? authKey : ''}`; + if (_heartbeatRequests[heartbeatRequestKey] !== undefined) + delete _heartbeatRequests[heartbeatRequestKey]; }; /** * Handle PubNub client response on PING request. @@ -1074,8 +1281,10 @@ clients = clients.filter((client) => client.clientIdentifier !== clientId); if (clients.length > 0) pubNubClientsBySubscriptionKey[subscriptionKey] = clients; - else + else { delete pubNubClientsBySubscriptionKey[subscriptionKey]; + delete serviceHeartbeatRequests[subscriptionKey]; + } // Clean up presence state information if not in use anymore. if (clients.length === 0) delete presenceState[subscriptionKey]; @@ -1180,6 +1389,21 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' client.subscription.filterExpression === filterExpression && (timetoken === '0' || client.subscription.timetoken === '0' || client.subscription.timetoken === timetoken)); }; + /** + * Find PubNub client state with configuration compatible with toe one in request. + * + * Method allow to find information about all PubNub client instances which use same: + * - subscription key + * - `userId` + * - `auth` key + * + * @param event - Send heartbeat request event information. + * + * @returns List of PubNub client states which works from other pages for the same user. + */ + const clientsForSendHeartbeatRequestEvent = (event) => { + return clientsForSendLeaveRequestEvent(event); + }; /** * Find PubNub client states with configuration compatible with the one in request. * diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index ebea52ae6..9c9f4f1cd 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ -!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{u(i.next(e))}catch(e){s(e)}}function c(e){try{u(i.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}u((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,i,r={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=r,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function i(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var i=n[t||"all"];return i&&i.test(e)||!1}i.isUUID=r,i.VERSION=t,e.uuid=i,e.isUUID=r}(i=r.exports),null!==n&&(n.exports=i.uuid);var s=t(r.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=1e4,u=new Map,l=new TextDecoder;let a,d=!1;const f=o.createUUID(),p=new Map,h={},g={},b={},v={},y={};self.onconnect=e=>{z("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!D(t))return;const n=t.data;if("client-register"===n.type)!d&&n.workerLogVerbosity&&(d=!0),n.port=e,C(n),z(`Client '${n.clientIdentifier}' registered with '${f}' shared worker`);else if("client-pong"===n.type)W(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){U(n);const e=h[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!u.has(t)){const e=setTimeout((()=>{q(n),u.delete(t)}),50);u.set(t,e)}}}else m(n);else"cancel-request"===n.type&&j(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=e=>{var t;const n=R(e),i=h[e.clientIdentifier];let r=!1;if(i&&(i.subscription&&(r="0"===i.subscription.timetoken),x("start",[i],(new Date).toISOString())),"string"==typeof n){const s=y[n];if(i){if(i.subscription&&(i.subscription.timetoken=s.timetoken,i.subscription.region=s.region,i.subscription.serviceRequestId=n),!r)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),u=new Response(o,{status:200,headers:c}),l=G([u,o]);l.url=`${e.request.origin}${e.request.path}`,l.clientIdentifier=e.clientIdentifier,l.identifier=e.request.identifier,x("end",[i],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),T(i,l)}return}e.request.cancellable&&p.set(n.identifier,new AbortController);const s=y[n.identifier],{timetokenOverride:o,regionOverride:c}=s;O(n,(()=>S(n.identifier)),((e,t)=>{F(e,t),E(e,n.identifier)}),((e,t)=>{F(e,null,n,K(t)),E(e,n.identifier)}),(e=>{let t=e;return r&&o&&"0"!==o&&(y[n.identifier],t=I(t,o,c)),t})),z(`'${Object.keys(y).length}' subscription request currently active.`)},I=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let i;const r=e[0];let s=r,o=e[1];try{i=JSON.parse((new TextDecoder).decode(o))}catch(t){return z(`Subscribe response parse error: ${t}`),e}i.t.t=t,n&&(i.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(i)).buffer,o.byteLength){const e=new Headers(r.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:r.status,statusText:r.statusText,headers:e})}}catch(t){return z(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},m=e=>{const t=h[e.clientIdentifier],n=A(e);if(!t)return;const{subscription:i}=t,r=null==i?void 0:i.serviceRequestId;if(i&&0===i.channels.length&&0===i.channelGroups.length&&(i.channelGroupQuery="",i.path="",i.previousTimetoken="0",i.timetoken="0",delete i.region,delete i.serviceRequestId,delete i.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),i=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),r=new Response(n,{status:200,headers:i}),s=G([r,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void T(t,s)}if(O(n,(()=>[t]),((t,n)=>{F(t,n,e.request)}),((t,n)=>{F(t,null,e.request,K(n))})),z("Started leave request.",t),void 0===r)return;const s=S(r);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),$(r),w(s)},j=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,$(n))},w=e=>{let t,n;for(const i of e)if(i.subscription&&i.subscription.request){n=i.subscription.request,t=i;break}n&&t&&q({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},O=(t,n,i,r,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(P(t),{signal:null===(e=p.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),k(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const r=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,r,e[0].headers.get("Content-Type"),(new Date).getTime()-o),i(s,e))})).catch((e=>{const t=n();0!==t.length&&r(t,e)}))}))},$=e=>{if(0===S(e).length){const t=p.get(e);p.delete(e),delete y[e],t&&t.abort()}},k=(e,t)=>new Promise(((n,i)=>{const r=setTimeout((()=>{p.delete(e),clearTimeout(r),i(new Error("Request timeout"))}),1e3*t)})),S=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete y[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},P=e=>{let t;const n=e.queryParameters;let i=e.path;if(e.headers){t={};for(const[n,i]of Object.entries(e.headers))t[n]=i}return n&&0!==Object.keys(n).length&&(i=`${i}?${_(n)}`),new Request(`${e.origin}${i}`,{method:e.method,headers:t,redirect:"follow"})},R=e=>{var t,n,i,r,s;const c=h[e.clientIdentifier],u=c.subscription,l=N(u.timetoken,e),a=o.createUUID(),f=Object.assign({},e.request);let p,g;if(l.length>1){const s=L(l,e);if(s){const e=y[s],{channels:n,channelGroups:i}=null!==(t=c.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Q(e.channels,n))&&(!(i.length>0)||Q(e.channelGroups,i)))return s}const o=(null!==(n=b[c.subscriptionKey])&&void 0!==n?n:{})[c.userId],d={},h=new Set(u.channelGroups),v=new Set(u.channels);o&&u.objectsWithState.length&&u.objectsWithState.forEach((e=>{const t=o[e];t&&(d[e]=t)}));for(const e of l){const{subscription:t}=e;if(!t)continue;1!==l.length&&e.clientIdentifier===c.clientIdentifier||!t.timetoken||(p=t.timetoken,g=t.region),t.channelGroups.forEach(h.add,h),t.channels.forEach(v.add,v);const n=t.serviceRequestId;t.serviceRequestId=a,n&&y[n]&&$(n),o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!d[e]&&(d[e]=t)}))}const q=null!==(i=y[a])&&void 0!==i?i:y[a]={requestId:a,timetoken:null!==(r=f.queryParameters.tt)&&void 0!==r?r:"0",channelGroups:[],channels:[]};if(v.size){q.channels=Array.from(v).sort();const e=f.path.split("/");e[4]=q.channels.join(","),f.path=e.join("/")}h.size&&(q.channelGroups=Array.from(h).sort(),f.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(d).length&&(f.queryParameters.state=JSON.stringify(d))}else y[a]={requestId:a,timetoken:null!==(s=f.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:u.channelGroups,channels:u.channels};if(y[a]&&(f.queryParameters&&void 0!==f.queryParameters.tt&&void 0!==f.queryParameters.tr&&(y[a].region=f.queryParameters.tr),y[a].timetokenOverride=p,y[a].regionOverride=g),u.serviceRequestId=a,f.identifier=a,d){const e=l.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");H(y[a],`Started aggregated request for clients: ${e}`)}return f},A=e=>{const t=h[e.clientIdentifier],n=M(e);let i=J(e.request),r=V(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;r.length&&(e.channels=e.channels.filter((e=>!r.includes(e)))),i.length&&(e.channelGroups=e.channelGroups.filter((e=>!i.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(r.length&&(r=r.filter((e=>!n.channels.includes(e)))),i.length&&(i=i.filter((e=>!n.channelGroups.includes(e))))))}if(0!==r.length||0!==i.length){if(r.length){const e=s.path.split("/");e[6]=r.join(","),s.path=e.join("/")}return i.length&&(s.queryParameters["channel-group"]=i.join(",")),s}if(d&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");z(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},T=(e,t)=>{var n;const i=(null!==(n=v[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!i)return!1;try{return i.postMessage(t),!0}catch(e){}return!1},x=(e,t,n,i,r,s,o)=>{var c;if(0===t.length)return;const u=null!==(c=v[t[0].subscriptionKey])&&void 0!==c?c:{};let a;if("start"===e)a={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;r&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=l.decode(r)),a={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(void 0===e.subscription)continue;const t=u[e.clientIdentifier],{request:n}=e.subscription,r=null!=n?n:i;if(e.logVerbosity&&t&&r){const t=Object.assign(Object.assign({},a),{clientIdentifier:e.clientIdentifier,url:`${r.origin}${r.path}`,query:r.queryParameters});T(e,t)}}},F=(e,t,n,i)=>{var r;if(0===e.length)return;if(!i&&!t)return;const s=null!==(r=v[e[0].subscriptionKey])&&void 0!==r?r:{};!i&&t&&(i=t[0].status>=400?K(void 0,t):G(t));for(const t of e){if(void 0===t.subscription)continue;const e=s[t.clientIdentifier],{request:r}=t.subscription,o=null!=r?r:n;if(e&&o){const e=Object.assign(Object.assign({},i),{clientIdentifier:t.clientIdentifier,identifier:o.identifier,url:`${o.origin}${o.path}`});T(t,e)}}},G=e=>{var t;const[n,i]=e,r=i.byteLength>0?i:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:r}}},K=(e,t)=>{if(t)return Object.assign(Object.assign({},G(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",i="Unknown error",r="Error";return e&&e instanceof Error&&(i=e.message,r=e.name),"AbortError"===r?(i="Request aborted",n="ABORTED"):"Request timeout"===i&&(n="TIMEOUT"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:r,type:n,message:i}}},C=e=>{var t,n,i,r;const{clientIdentifier:s}=e;if(h[s])return;const o=h[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,logVerbosity:e.logVerbosity},u=null!==(t=g[i=e.subscriptionKey])&&void 0!==t?t:g[i]=[];u.every((e=>e.clientIdentifier!==s))&&u.push(o),(null!==(n=v[r=e.subscriptionKey])&&void 0!==n?n:v[r]={})[s]=e.port,z(`Registered PubNub client with '${s}' identifier. '${Object.keys(h).length}' clients currently active.`),!a&&Object.keys(h).length>0&&(z("Setup PubNub client ping event 10 seconds"),a=setInterval((()=>B()),c))},U=e=>{var t,n,i,r,s,o,c,u,l,a,d,f,p,g,v,y,q,I,m,j;const w=e.request.queryParameters,{clientIdentifier:O}=e,$=h[O];if(!$)return;const k=null!==(t=w["channel-group"])&&void 0!==t?t:"",S=null!==(n=w.state)&&void 0!==n?n:"";let E=$.subscription;if(E){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=b[v=$.subscriptionKey])&&void 0!==s?s:b[v]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of E.objectsWithState)e[n]||delete t[n];E.objectsWithState=Object.keys(e)}else if(E.objectsWithState.length){const e=null!==(u=(m=null!==(c=b[I=$.subscriptionKey])&&void 0!==c?c:b[I]={})[j=$.userId])&&void 0!==u?u:m[j]={};for(const t of E.objectsWithState)delete e[t];E.objectsWithState=[]}}else{if(E={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(r=(p=null!==(i=b[f=$.subscriptionKey])&&void 0!==i?i:b[f]={})[g=$.userId])&&void 0!==r?r:p[g]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),E.objectsWithState=Object.keys(e)}$.subscription=E}E.path!==e.request.path&&(E.path=e.request.path,E.channels=V(e.request)),E.channelGroupQuery!==k&&(E.channelGroupQuery=k,E.channelGroups=J(e.request)),E.request=e.request,E.filterExpression=null!==(l=w["filter-expr"])&&void 0!==l?l:"",E.timetoken=null!==(a=w.tt)&&void 0!==a?a:"0",void 0!==w.tr&&(E.region=w.tr),$.authKey=null!==(d=w.auth)&&void 0!==d?d:"",$.userId=w.uuid},W=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},D=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:i}=e.data;return void 0!==i&&"boolean"==typeof i&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},L=(e,t)=>{var n;const i=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",r=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],u=e.serviceRequestId;if(e.path===r&&e.channelGroupQuery===i)return z(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${u}' request completion.`,c),e.serviceRequestId;{const i=y[e.serviceRequestId];if(s||(s=J(t.request)),o||(o=V(t.request)),o.length&&!Q(i.channels,o))continue;if(s.length&&!Q(i.channelGroups,s))continue;return H(i,`'${t.request.identifier}' request channels and groups are subset of ongoing '${u}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${u}' request completion.`,c),e.serviceRequestId}}},N=(e,t)=>{var n,i,r;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(i=s.auth)&&void 0!==i?i:"",u=s.uuid;return(null!==(r=g[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===u&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},M=e=>{var t,n;const i=e.request.queryParameters,r=null!==(t=i.auth)&&void 0!==t?t:"",s=i.uuid;return(null!==(n=g[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===r))},V=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},J=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Q=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},B=()=>{z("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(h).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(z(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>5)&&(n=!0,z(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete h[t];let n=g[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?g[e]=n:delete g[e],0===n.length&&delete b[e],n.length>0){const n=v[e];n&&(delete n[t],0===Object.keys(n).length&&delete v[e])}else delete v[e];z(`Invalidate '${t}' client. '${Object.keys(h).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(z(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,T(t,e))})),0===Object.keys(h).length&&a&&clearInterval(a)},z=(e,t)=>{if(!d)return;const n=t?[t]:Object.values(h),i={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&T(e,i)}))},H=(e,t,n)=>{if(!d)return;const i=n?[n]:Object.values(h),r={type:"shared-worker-console-dir",message:t,data:e};i.forEach((e=>{e&&T(e,r)}))},_=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${X(e)}`)).join("&"):`${t}=${X(n)}`})).join("&"),X=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{u(r.next(e))}catch(e){s(e)}}function c(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}u((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,r,i={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=i,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(r=i.exports),null!==n&&(n.exports=r.uuid);var s=t(i.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=1e4,u=new Map,l=new TextDecoder;let a,d=!1;const h=o.createUUID(),p=new Map,f={},b={},g={},v={},y={},q={};self.onconnect=e=>{ee("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)!d&&n.workerLogVerbosity&&(d=!0),n.port=e,U(n),ee(`Client '${n.clientIdentifier}' registered with '${h}' shared worker`);else if("client-pong"===n.type)V(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){L(n);const e=f[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!u.has(t)){const e=setTimeout((()=>{I(n),u.delete(t)}),50);u.set(t,e)}}}else n.request.path.endsWith("/heartbeat")?(N(n),j(n)):O(n);else"cancel-request"===n.type&&$(n)},e.postMessage({type:"shared-worker-connected"})}))};const I=e=>{var t;const n=R(e),r=f[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),F("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=q[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),u=new Response(o,{status:200,headers:c}),l=C([u,o]);l.url=`${e.request.origin}${e.request.path}`,l.clientIdentifier=e.clientIdentifier,l.identifier=e.request.identifier,F("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),A(r,l)}return}e.request.cancellable&&p.set(n.identifier,new AbortController);const s=q[n.identifier],{timetokenOverride:o,regionOverride:c}=s;S(n,(()=>G(n.identifier)),((t,r)=>{W(t,r,e.request),T(t,n.identifier)}),((t,r)=>{W(t,null,e.request,D(r)),T(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(q[n.identifier],t=m(t,o,c)),t})),ee(`'${Object.keys(q).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ee(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ee(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},j=e=>{var t;const n=f[e.clientIdentifier],r=K(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=g[n.subscriptionKey],o=(null!=s?s:{})[i];if(F("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ee(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=C([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,F("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}S(r,(()=>[n]),((t,n)=>{o&&(o.response=n),W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),ee("Started heartbeat request.",n)},O=e=>{const t=f[e.clientIdentifier],n=x(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=C([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(S(n,(()=>[t]),((t,n)=>{W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),ee("Started leave request.",t),void 0===i)return;const s=G(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),w(s)},$=e=>{const t=f[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},w=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&I({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},S=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(E(t),{signal:null===(e=p.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),P(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(F("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();0!==t.length&&i(t,e)}))}))},k=e=>{if(0===G(e).length){const t=p.get(e);p.delete(e),delete q[e],t&&t.abort()}},P=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{p.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),G=e=>Object.values(f).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),T=(e,t)=>{delete q[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},E=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ne(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},R=e=>{var t,n,r,i,s;const c=f[e.clientIdentifier],u=c.subscription,l=Q(u.timetoken,e),a=o.createUUID(),h=Object.assign({},e.request);let p,b;if(l.length>1){const s=_(l,e);if(s){const e=q[s],{channels:n,channelGroups:r}=null!==(t=c.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Y(e.channels,n))&&(!(r.length>0)||Y(e.channelGroups,r)))return s}const o=(null!==(n=v[c.subscriptionKey])&&void 0!==n?n:{})[c.userId],d={},f=new Set(u.channelGroups),g=new Set(u.channels);o&&u.objectsWithState.length&&u.objectsWithState.forEach((e=>{const t=o[e];t&&(d[e]=t)}));for(const e of l){const{subscription:t}=e;if(!t)continue;1!==l.length&&e.clientIdentifier===c.clientIdentifier||!t.timetoken||(p=t.timetoken,b=t.region),t.channelGroups.forEach(f.add,f),t.channels.forEach(g.add,g);const n=t.serviceRequestId;t.serviceRequestId=a,n&&q[n]&&k(n),o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!d[e]&&(d[e]=t)}))}const y=null!==(r=q[a])&&void 0!==r?r:q[a]={requestId:a,timetoken:null!==(i=h.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(g.size){y.channels=Array.from(g).sort();const e=h.path.split("/");e[4]=y.channels.join(","),h.path=e.join("/")}f.size&&(y.channelGroups=Array.from(f).sort(),h.queryParameters["channel-group"]=y.channelGroups.join(",")),Object.keys(d).length&&(h.queryParameters.state=JSON.stringify(d))}else q[a]={requestId:a,timetoken:null!==(s=h.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:u.channelGroups,channels:u.channels};if(q[a]&&(h.queryParameters&&void 0!==h.queryParameters.tt&&void 0!==h.queryParameters.tr&&(q[a].region=h.queryParameters.tr),q[a].timetokenOverride=p,q[a].regionOverride=b),u.serviceRequestId=a,h.identifier=a,d){const e=l.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");te(q[a],`Started aggregated request for clients: ${e}`)}return h},K=e=>{var t,n,r,i,s;const o=f[e.clientIdentifier],c=B(e),u=Object.assign({},e.request);if(!o||!o.heartbeat)return;const l=null!==(t=g[s=o.subscriptionKey])&&void 0!==t?t:g[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,h=o.heartbeat.channels;let p={},b=!1,v=!0;if(l[a]){const{channels:e,channelGroups:t,response:n}=l[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},v=Y(e,o.heartbeat.channels)&&Y(t,o.heartbeat.channelGroups),n&&(b=n[0].status>=400)}else l[a]={channels:h,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},v=!1;if(v){const t=l[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!b&&n5e3)return;delete l[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),h.push(...n.channels.filter((e=>!h.includes(e)))))}}l[a].channels=h,l[a].channelGroups=d,l[a].timestamp=Date.now();for(const e in Object.keys(p))h.includes(e)||d.includes(e)||delete p[e];if(h.length){const e=u.path.split("/");e[6]=h.join(","),u.path=e.join("/")}return d.length&&(u.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?u.queryParameters.state=JSON.stringify(p):delete u.queryParameters.state,u},x=e=>{const t=f[e.clientIdentifier],n=H(e);let r=X(e.request),i=z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(d&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");ee(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(e){}return!1},F=(e,t,n,r,i,s,o)=>{var c,u;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let h;if("start"===e)h={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=l.decode(i)),h={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(u=e.subscription)&&void 0!==u?u:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},h),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},W=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},c=n&&n.path.startsWith("/v2/subscribe");!r&&t&&(r=t[0].status>=400?D(void 0,t):C(t));for(const t of e){if(c&&!t.subscription)continue;const e=o[t.clientIdentifier],{request:i}=null!==(s=t.subscription)&&void 0!==s?s:{};let u=null!=i?i:n;if(c||(u=n),e&&u){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:u.identifier,url:`${u.origin}${u.path}`});A(t,e)}}},C=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},C(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";return e&&e instanceof Error&&(r=e.message,i=e.name),"AbortError"===i?(r="Request aborted",n="ABORTED"):"Request timeout"===r&&(n="TIMEOUT"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},U=e=>{var t,n,r,i;const{clientIdentifier:s}=e;if(f[s])return;const o=f[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity},u=null!==(t=b[r=e.subscriptionKey])&&void 0!==t?t:b[r]=[];u.every((e=>e.clientIdentifier!==s))&&u.push(o),(null!==(n=y[i=e.subscriptionKey])&&void 0!==n?n:y[i]={})[s]=e.port,ee(`Registered PubNub client with '${s}' identifier. '${Object.keys(f).length}' clients currently active.`),!a&&Object.keys(f).length>0&&(ee("Setup PubNub client ping event 10 seconds"),a=setInterval((()=>Z()),c))},L=e=>{var t,n,r,i,s,o,c,u,l,a,d,h,p,b,g,y,q,I,m,j;const O=e.request.queryParameters,{clientIdentifier:$}=e,w=f[$];if(!w)return;const S=null!==(t=O["channel-group"])&&void 0!==t?t:"",k=null!==(n=O.state)&&void 0!==n?n:"";let P=w.subscription;if(P){if(k.length>0){const e=JSON.parse(k),t=null!==(o=(y=null!==(s=v[g=w.subscriptionKey])&&void 0!==s?s:v[g]={})[q=w.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of P.objectsWithState)e[n]||delete t[n];P.objectsWithState=Object.keys(e)}else if(P.objectsWithState.length){const e=null!==(u=(m=null!==(c=v[I=w.subscriptionKey])&&void 0!==c?c:v[I]={})[j=w.userId])&&void 0!==u?u:m[j]={};for(const t of P.objectsWithState)delete e[t];P.objectsWithState=[]}}else{if(P={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},k.length>0){const e=JSON.parse(k),t=null!==(i=(p=null!==(r=v[h=w.subscriptionKey])&&void 0!==r?r:v[h]={})[b=w.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),P.objectsWithState=Object.keys(e)}w.subscription=P}P.path!==e.request.path&&(P.path=e.request.path,P.channels=z(e.request)),P.channelGroupQuery!==S&&(P.channelGroupQuery=S,P.channelGroups=X(e.request));const{authKey:G,userId:T}=w;P.request=e.request,P.filterExpression=null!==(l=O["filter-expr"])&&void 0!==l?l:"",P.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(P.region=O.tr),w.authKey=null!==(d=O.auth)&&void 0!==d?d:"",w.userId=O.uuid,M(w,T,G)},N=e=>{var t,n;const r=f[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=X(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=g[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},V=e=>{const t=f[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},_=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=f[t.clientIdentifier],u=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ee(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${u}' request completion.`,c),e.serviceRequestId;{const r=q[e.serviceRequestId];if(s||(s=X(t.request)),o||(o=z(t.request)),o.length&&!Y(r.channels,o))continue;if(s.length&&!Y(r.channelGroups,s))continue;return te(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${u}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${u}' request completion.`,c),e.serviceRequestId}}},Q=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",u=s.uuid;return(null!==(i=b[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===u&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>H(e),H=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=b[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},X=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Y=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},Z=()=>{ee("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(f).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(ee(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>5)&&(n=!0,ee(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete f[t];let n=b[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?b[e]=n:(delete b[e],delete g[e]),0===n.length&&delete v[e],n.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];ee(`Invalidate '${t}' client. '${Object.keys(f).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(ee(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,A(t,e))})),0===Object.keys(f).length&&a&&clearInterval(a)},ee=(e,t)=>{if(!d)return;const n=t?[t]:Object.values(f),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},te=(e,t,n)=>{if(!d)return;const r=n?[n]:Object.values(f),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},ne=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${re(e)}`)).join("&"):`${t}=${re(n)}`})).join("&"),re=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index f6be7f6d3..feb36f0fa 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.6.0'; + return '8.7.0'; }, getVersion() { return this.version; diff --git a/lib/core/components/subscription-manager.js b/lib/core/components/subscription-manager.js index e653bebae..d8b1dcd49 100644 --- a/lib/core/components/subscription-manager.js +++ b/lib/core/components/subscription-manager.js @@ -75,9 +75,16 @@ class SubscriptionManager { this.stopHeartbeatTimer(); this.reconnectionManager.stopPolling(); } - reconnect() { + /** + * Restart subscription loop with current state. + * + * @param forUnsubscribe - Whether restarting subscription loop as part of channels list change on + * unsubscribe or not. + */ + reconnect(forUnsubscribe = false) { this.startSubscribeLoop(); - this.startHeartbeatTimer(); + if (!forUnsubscribe) + this.startHeartbeatTimer(); } /** * Update channels and groups used in subscription loop. @@ -176,7 +183,7 @@ class SubscriptionManager { this.region = null; this.reconnectionManager.stopPolling(); } - this.reconnect(); + this.reconnect(true); } unsubscribeAll(isOffline) { this.unsubscribe({ diff --git a/package.json b/package.json index f36dbfe8a..9c6ff6785 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.6.0", + "version": "8.7.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index eb5875612..8fa7c7d72 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.6.0'; + return '8.7.0'; }, getVersion(): string { return this.version; diff --git a/src/core/components/subscription-manager.ts b/src/core/components/subscription-manager.ts index dc9ee44bf..df0db8bc4 100644 --- a/src/core/components/subscription-manager.ts +++ b/src/core/components/subscription-manager.ts @@ -190,9 +190,15 @@ export class SubscriptionManager { this.reconnectionManager.stopPolling(); } - public reconnect() { + /** + * Restart subscription loop with current state. + * + * @param forUnsubscribe - Whether restarting subscription loop as part of channels list change on + * unsubscribe or not. + */ + public reconnect(forUnsubscribe: boolean = false) { this.startSubscribeLoop(); - this.startHeartbeatTimer(); + if (!forUnsubscribe) this.startHeartbeatTimer(); } /** @@ -315,7 +321,7 @@ export class SubscriptionManager { this.reconnectionManager.stopPolling(); } - this.reconnect(); + this.reconnect(true); } public unsubscribeAll(isOffline?: boolean) { diff --git a/src/transport/subscription-worker/subscription-worker-middleware.ts b/src/transport/subscription-worker/subscription-worker-middleware.ts index 0508adacb..b1c5acf4c 100644 --- a/src/transport/subscription-worker/subscription-worker-middleware.ts +++ b/src/transport/subscription-worker/subscription-worker-middleware.ts @@ -55,6 +55,13 @@ type PubNubMiddlewareConfiguration = { */ workerLogVerbosity: boolean; + /** + * How often the client will announce itself to server. The value is in seconds. + * + * @default `not set` + */ + heartbeatInterval?: number; + /** * Platform-specific transport for requests processing. */ @@ -100,7 +107,7 @@ export class SubscriptionWorkerMiddleware implements Transport { makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { // Use default request flow for non-subscribe / presence leave requests. - if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/leave')) + if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/heartbeat') && !req.path.endsWith('/leave')) return this.configuration.transport.makeSendable(req); let controller: CancellationController | undefined; @@ -225,6 +232,7 @@ export class SubscriptionWorkerMiddleware implements Transport { clientIdentifier: this.configuration.clientIdentifier, subscriptionKey: this.configuration.subscriptionKey, userId: this.configuration.userId, + heartbeatInterval: this.configuration.heartbeatInterval, logVerbosity: this.configuration.logVerbosity, workerLogVerbosity: this.configuration.workerLogVerbosity, }, @@ -254,7 +262,7 @@ export class SubscriptionWorkerMiddleware implements Transport { console.log(`[SharedWorker] ${data.message}`); } else if (data.type === 'shared-worker-console-dir') { if (data.message) console.log(`[SharedWorker] ${data.message}`); - console.dir(data.data); + console.dir(data.data, { depth: 10 }); } else if (data.type === 'shared-worker-ping') { const { logVerbosity, subscriptionKey, clientIdentifier } = this.configuration; diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index 8816de9de..8b3b2d358 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -54,6 +54,13 @@ export type RegisterEvent = BasicEvent & { */ userId: string; + /** + * How often the client will announce itself to server. The value is in seconds. + * + * @default `not set` + */ + heartbeatInterval?: number; + /** * Specific PubNub client instance communication port. */ @@ -342,7 +349,7 @@ export type SubscriptionWorkerEvent = | RequestSendingResult; /** - * PubNub client state representation in Service Worker. + * PubNub client state representation in Shared Worker. */ type PubNubClientState = { /** @@ -366,6 +373,13 @@ type PubNubClientState = { */ authKey?: string; + /** + * How often the client will announce itself to server. The value is in seconds. + * + * @default `not set` + */ + heartbeatInterval?: number; + /** * Whether verbose logging enabled or not. */ @@ -454,6 +468,25 @@ type PubNubClientState = { */ filterExpression?: string; }; + + heartbeat?: { + /** + * List of channels for which user's presence has been announced by the PubNub client. + */ + channels: string[]; + + /** + * List of channel groups for which user's presence has been announced by the PubNub client. + */ + channelGroups: string[]; + + /** + * Presence state associated with user at specified list of channels and groups. + * + * Per-channel/group state associated with specific user. + */ + presenceState?: Record; + }; }; // endregion // endregion @@ -527,6 +560,19 @@ const pubNubClients: Record = {}; */ const pubNubClientsBySubscriptionKey: { [subscriptionKey: string]: PubNubClientState[] | undefined } = {}; +/** + * Per-subscription key map of heartbeat request configurations recently used for user. + */ +const serviceHeartbeatRequests: { + [subscriptionKey: string]: + | { + [userId: string]: + | { channels: string[]; channelGroups: string[]; timestamp: number; response?: [Response, ArrayBuffer] } + | undefined; + } + | undefined; +} = {}; + /** * Per-subscription key presence state associated with unique user identifiers with which {@link pubNubClients|clients} * scheduled subscription request. @@ -628,7 +674,7 @@ self.onconnect = (event) => { } else if (data.type === 'client-pong') handleClientPong(data); else if (data.type === 'send-request') { if (data.request.path.startsWith('/v2/subscribe')) { - updateClientStateIfRequired(data); + updateClientSubscribeStateIfRequired(data); const client = pubNubClients[data.clientIdentifier]; if (client) { @@ -644,6 +690,9 @@ self.onconnect = (event) => { aggregationTimers.set(timerIdentifier, aggregationTimer); } } + } else if (data.request.path.endsWith('/heartbeat')) { + updateClientHeartbeatState(data); + handleHeartbeatRequestEvent(data); } else handleSendLeaveRequestEvent(data); } else if (data.type === 'cancel-request') handleCancelRequestEvent(data); }; @@ -664,7 +713,7 @@ const handleSendSubscribeRequestEvent = (event: SendRequestEvent) => { if (client) { if (client.subscription) isInitialSubscribe = client.subscription.timetoken === '0'; - notifyRequestProcessing('start', [client], new Date().toISOString()); + notifyRequestProcessing('start', [client], new Date().toISOString(), event.request); } if (typeof requestOrId === 'string') { @@ -717,14 +766,14 @@ const handleSendSubscribeRequestEvent = (event: SendRequestEvent) => { () => clientsForRequest(requestOrId.identifier), (clients, response) => { // Notify each PubNub client which awaited for response. - notifyRequestProcessingResult(clients, response); + notifyRequestProcessingResult(clients, response, event.request); // Clean up scheduled request and client references to it. markRequestCompleted(clients, requestOrId.identifier); }, (clients, error) => { // Notify each PubNub client which awaited for response. - notifyRequestProcessingResult(clients, null, requestOrId, requestProcessingError(error)); + notifyRequestProcessingResult(clients, null, event.request, requestProcessingError(error)); // Clean up scheduled request and client references to it. markRequestCompleted(clients, requestOrId.identifier); @@ -789,6 +838,79 @@ const patchInitialSubscribeResponse = ( return body.byteLength > 0 ? [decidedResponse, body] : serverResponse; }; +/** + * Handle client heartbeat request. + * + * @param event - Heartbeat event details. + */ +const handleHeartbeatRequestEvent = (event: SendRequestEvent) => { + const client = pubNubClients[event.clientIdentifier]; + const request = heartbeatTransportRequestFromEvent(event); + + if (!client) return; + const heartbeatRequestKey = `${client.userId}_${client.authKey ?? ''}`; + const hbRequestsBySubscriptionKey = serviceHeartbeatRequests[client.subscriptionKey]; + const hbRequests = (hbRequestsBySubscriptionKey ?? {})[heartbeatRequestKey]; + notifyRequestProcessing('start', [client], new Date().toISOString(), request); + + if (!request) { + consoleLog( + `Previous heartbeat request has been sent less than ${client.heartbeatInterval} seconds ago. Skipping...`, + ); + + let response: Response | undefined; + let body: ArrayBuffer | undefined; + + // Pulling out previous response. + if (hbRequests && hbRequests.response) [response, body] = hbRequests.response; + + if (!response) { + body = new TextEncoder().encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer; + const headers = new Headers({ + 'Content-Type': 'text/javascript; charset="UTF-8"', + 'Content-Length': `${body.byteLength}`, + }); + + response = new Response(body, { status: 200, headers }); + } + + const result = requestProcessingSuccess([response, body!]); + result.url = `${event.request.origin}${event.request.path}`; + result.clientIdentifier = event.clientIdentifier; + result.identifier = event.request.identifier; + + notifyRequestProcessing( + 'end', + [client], + new Date().toISOString(), + event.request, + body, + response.headers.get('Content-Type'), + 0, + ); + + publishClientEvent(client, result); + return; + } + + sendRequest( + request, + () => [client], + (clients, response) => { + if (hbRequests) hbRequests.response = response; + + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, response, event.request); + }, + (clients, error) => { + // Notify each PubNub client which awaited for response. + notifyRequestProcessingResult(clients, null, event.request, requestProcessingError(error)); + }, + ); + + consoleLog(`Started heartbeat request.`, client); +}; + /** * Handle client request to leave request. * @@ -1218,6 +1340,105 @@ const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportR return request; }; +/** + * Construct transport request from send heartbeat request event. + * + * Update transport request to aggregate channels and groups if possible. + * + * @param event - Client's send heartbeat event request. + * + * @returns Final transport request or identifier from active request which will provide response to required + * channels and groups. + */ +const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportRequest | undefined => { + const client = pubNubClients[event.clientIdentifier]; + const clients = clientsForSendHeartbeatRequestEvent(event); + const request = { ...event.request }; + + if (!client || !client.heartbeat) return undefined; + + const hbRequestsBySubscriptionKey = (serviceHeartbeatRequests[client.subscriptionKey] ??= {}); + const heartbeatRequestKey = `${client.userId}_${client.authKey ?? ''}`; + const channelGroupsForAnnouncement: string[] = client.heartbeat.channelGroups; + const channelsForAnnouncement: string[] = client.heartbeat.channels; + let aggregatedState: Record = {}; + let failedPreviousRequest = false; + let aggregated = true; + + if (!hbRequestsBySubscriptionKey[heartbeatRequestKey]) { + hbRequestsBySubscriptionKey[heartbeatRequestKey] = { + channels: channelsForAnnouncement, + channelGroups: channelGroupsForAnnouncement, + timestamp: Date.now(), + }; + aggregatedState = client.heartbeat.presenceState ?? {}; + aggregated = false; + } else { + const { channels, channelGroups, response } = hbRequestsBySubscriptionKey[heartbeatRequestKey]; + aggregatedState = client.heartbeat.presenceState ?? {}; + aggregated = + includesStrings(channels, client.heartbeat.channels) && + includesStrings(channelGroups, client.heartbeat.channelGroups); + if (response) failedPreviousRequest = response[0].status >= 400; + } + + if (aggregated) { + const expectedTimestamp = + hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp + client.heartbeatInterval! * 1000; + const currentTimestamp = Date.now(); + + // Check whether it is too soon to send request or not (5 is leeway which let send request a bit earlier). + // Request should be sent if previous attempt failed. + if (!failedPreviousRequest && currentTimestamp < expectedTimestamp && expectedTimestamp - currentTimestamp > 5000) + return undefined; + + delete hbRequestsBySubscriptionKey[heartbeatRequestKey].response; + + // Aggregate channels for similar clients which is pending for heartbeat. + for (const client of clients) { + const { heartbeat } = client; + if (heartbeat === undefined || client.clientIdentifier === event.clientIdentifier) continue; + + // Append presence state from the client (will override previously set value if already set). + if (heartbeat.presenceState) aggregatedState = { ...aggregatedState, ...heartbeat.presenceState }; + + channelGroupsForAnnouncement.push( + ...heartbeat.channelGroups.filter((channel) => !channelGroupsForAnnouncement.includes(channel)), + ); + channelsForAnnouncement.push( + ...heartbeat.channels.filter((channel) => !channelsForAnnouncement.includes(channel)), + ); + } + } + + hbRequestsBySubscriptionKey[heartbeatRequestKey].channels = channelsForAnnouncement; + hbRequestsBySubscriptionKey[heartbeatRequestKey].channelGroups = channelGroupsForAnnouncement; + hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp = Date.now(); + + // Remove presence state for objects which is not part of heartbeat. + for (const objectName in Object.keys(aggregatedState)) { + if (!channelsForAnnouncement.includes(objectName) && !channelGroupsForAnnouncement.includes(objectName)) + delete aggregatedState[objectName]; + } + + // Update request channels list (if required). + if (channelsForAnnouncement.length) { + const pathComponents = request.path.split('/'); + pathComponents[6] = channelsForAnnouncement.join(','); + request.path = pathComponents.join('/'); + } + + // Update request channel groups list (if required). + if (channelGroupsForAnnouncement.length) + request.queryParameters!['channel-group'] = channelGroupsForAnnouncement.join(','); + + // Update request `state` (if required). + if (Object.keys(aggregatedState).length) request.queryParameters!['state'] = JSON.stringify(aggregatedState); + else delete request.queryParameters!['state']; + + return request; +}; + /** * Construct transport request from send leave request event. * @@ -1235,12 +1456,20 @@ const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportReque let channels = channelsFromRequest(event.request); const request = { ...event.request }; + // Remove channels / groups from active client's subscription. if (client && client.subscription) { const { subscription } = client; if (channels.length) subscription.channels = subscription.channels.filter((channel) => !channels.includes(channel)); - if (channelGroups.length) { + if (channelGroups.length) subscription.channelGroups = subscription.channelGroups.filter((group) => !channelGroups.includes(group)); - } + } + + // Remove channels / groups from client's presence heartbeat state. + if (client && client.heartbeat) { + const { heartbeat } = client; + if (channels.length) heartbeat.channels = heartbeat.channels.filter((channel) => !channels.includes(channel)); + if (channelGroups.length) + heartbeat.channelGroups = heartbeat.channelGroups.filter((channel) => !channelGroups.includes(channel)); } // Filter out channels and groups which is still in use by the other PubNub client instances. @@ -1325,6 +1554,7 @@ const notifyRequestProcessing = ( if (clients.length === 0) return; const clientIds = sharedWorkerClients[clients[0].subscriptionKey] ?? {}; + const isSubscribeRequest = request && request.path.startsWith('/v2/subscribe'); let event: RequestSendingProgress; if (type === 'start') { @@ -1358,11 +1588,12 @@ const notifyRequestProcessing = ( } for (const client of clients) { - if (client.subscription === undefined) continue; + if (isSubscribeRequest && !client.subscription) continue; const serviceWorkerClientId = clientIds[client.clientIdentifier]; - const { request: clientRequest } = client.subscription; - const decidedRequest = clientRequest ?? request; + const { request: clientRequest } = client.subscription ?? {}; + let decidedRequest = clientRequest ?? request; + if (!isSubscribeRequest) decidedRequest = request; if (client.logVerbosity && serviceWorkerClientId && decidedRequest) { const payload = { @@ -1395,6 +1626,7 @@ const notifyRequestProcessingResult = ( if (!result && !response) return; const clientIds = sharedWorkerClients[clients[0].subscriptionKey] ?? {}; + const isSubscribeRequest = request && request.path.startsWith('/v2/subscribe'); if (!result && response) { result = @@ -1405,11 +1637,12 @@ const notifyRequestProcessingResult = ( } for (const client of clients) { - if (client.subscription === undefined) continue; + if (isSubscribeRequest && !client.subscription) continue; const serviceWorkerClientId = clientIds[client.clientIdentifier]; - const { request: clientRequest } = client.subscription; - const decidedRequest = clientRequest ?? request; + const { request: clientRequest } = client.subscription ?? {}; + let decidedRequest = clientRequest ?? request; + if (!isSubscribeRequest) decidedRequest = request; if (serviceWorkerClientId && decidedRequest) { const payload = { @@ -1472,7 +1705,7 @@ const requestProcessingSuccess = (res: [Response, ArrayBuffer]): RequestSendingS * @returns Request processing error event object. */ const requestProcessingError = (error?: unknown, res?: [Response, ArrayBuffer]): RequestSendingError => { - // User service response as error information source. + // Use service response as error information source. if (res) { return { ...requestProcessingSuccess(res), @@ -1527,6 +1760,7 @@ const registerClientIfRequired = (event: RegisterEvent) => { clientIdentifier, subscriptionKey: event.subscriptionKey, userId: event.userId, + heartbeatInterval: event.heartbeatInterval, logVerbosity: event.logVerbosity, }); @@ -1556,7 +1790,7 @@ const registerClientIfRequired = (event: RegisterEvent) => { * * @param event - Send request. */ -const updateClientStateIfRequired = (event: SendRequestEvent) => { +const updateClientSubscribeStateIfRequired = (event: SendRequestEvent) => { const query = event.request.queryParameters!; const { clientIdentifier } = event; const client = pubNubClients[clientIdentifier]; @@ -1619,12 +1853,64 @@ const updateClientStateIfRequired = (event: SendRequestEvent) => { subscription.channelGroups = channelGroupsFromRequest(event.request); } + const { authKey, userId } = client; subscription.request = event.request; subscription.filterExpression = (query['filter-expr'] ?? '') as string; subscription.timetoken = (query.tt ?? '0') as string; if (query.tr !== undefined) subscription.region = query.tr as string; client.authKey = (query.auth ?? '') as string; client.userId = query.uuid as string; + + handleClientIdentityChangeIfRequired(client, userId, authKey); +}; + +/** + * Update presence heartbeat information for previously registered client. + * + * Use information from request to populate list of channels / groups and presence state information. + * + * @param event - Send heartbeat request event. + */ +const updateClientHeartbeatState = (event: SendRequestEvent) => { + const client = pubNubClients[event.clientIdentifier]; + const { request } = event; + + // This should never happen. + if (!client) return; + + const _clientHeartbeat = (client.heartbeat ??= { + channels: [], + channelGroups: [], + }); + + // Update presence heartbeat information about client. + _clientHeartbeat.channelGroups = channelGroupsFromRequest(request).filter((group) => !group.endsWith('-pnpres')); + _clientHeartbeat.channels = channelsFromRequest(request).filter((channel) => !channel.endsWith('-pnpres')); + + const state = (request.queryParameters!.state ?? '') as string; + if (state.length > 0) { + const userPresenceState = JSON.parse(state) as Record; + for (const objectName of Object.keys(userPresenceState)) + if (!_clientHeartbeat.channels.includes(objectName) && !_clientHeartbeat.channelGroups.includes(objectName)) + delete userPresenceState[objectName]; + _clientHeartbeat.presenceState = userPresenceState; + } +}; + +/** + * Check whether PubNub client identity has been changed between state refresh or not. + * + * @param client - PubNub client state which will be checked. + * @param userId - `userId` which has been used by `PubNub` client before state refresh. + * @param authKey - `authKey` which has been used by `PubNub` client before state refresh. + */ +const handleClientIdentityChangeIfRequired = (client: PubNubClientState, userId: string, authKey?: string) => { + if (!client || (userId === client.userId && (authKey ?? '') === (client.authKey ?? ''))) return; + + const _heartbeatRequests = serviceHeartbeatRequests[client.subscriptionKey] ?? {}; + + const heartbeatRequestKey = `${userId}_${authKey ?? ''}`; + if (_heartbeatRequests[heartbeatRequestKey] !== undefined) delete _heartbeatRequests[heartbeatRequestKey]; }; /** @@ -1655,7 +1941,10 @@ const invalidateClient = (subscriptionKey: string, clientId: string) => { // Clean up linkage between client and subscription key. clients = clients.filter((client) => client.clientIdentifier !== clientId); if (clients.length > 0) pubNubClientsBySubscriptionKey[subscriptionKey] = clients; - else delete pubNubClientsBySubscriptionKey[subscriptionKey]; + else { + delete pubNubClientsBySubscriptionKey[subscriptionKey]; + delete serviceHeartbeatRequests[subscriptionKey]; + } // Clean up presence state information if not in use anymore. if (clients.length === 0) delete presenceState[subscriptionKey]; @@ -1776,6 +2065,22 @@ const clientsForSendSubscribeRequestEvent = (timetoken: string, event: SendReque ); }; +/** + * Find PubNub client state with configuration compatible with toe one in request. + * + * Method allow to find information about all PubNub client instances which use same: + * - subscription key + * - `userId` + * - `auth` key + * + * @param event - Send heartbeat request event information. + * + * @returns List of PubNub client states which works from other pages for the same user. + */ +const clientsForSendHeartbeatRequestEvent = (event: SendRequestEvent) => { + return clientsForSendLeaveRequestEvent(event); +}; + /** * Find PubNub client states with configuration compatible with the one in request. * diff --git a/src/web/index.ts b/src/web/index.ts index 4a0c33cd4..b634b51c6 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -106,6 +106,7 @@ export default class PubNub extends PubNubCore Date: Fri, 31 Jan 2025 08:23:59 +0200 Subject: [PATCH 34/49] Fix long-poll request cancellation (#434) fix(subscribe): fix long-poll request cancellation Fix long-poll request cancellation caused by APM packages monkey patching 'fetch' and try to use 'native' implementation instead of patched. --- .pubnub.yml | 11 +++-- CHANGELOG.md | 6 +++ README.md | 4 +- dist/web/pubnub.js | 46 ++++++++++++++++++-- dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/react_native/index.js | 2 +- lib/transport/web-react-native-transport.js | 29 ++++++++++++- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/react_native/index.ts | 2 +- src/transport/web-react-native-transport.ts | 47 +++++++++++++++++++-- src/web/index.ts | 16 +++++++ 13 files changed, 152 insertions(+), 21 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 9fb6eedd4..4e2f70134 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2025-01-31 + version: v8.7.1 + changes: + - type: bug + text: "Fix long-poll request cancellation caused by APM packages monkey patching 'fetch' and try to use 'native' implementation instead of patched." - date: 2025-01-30 version: v8.7.0 changes: @@ -1118,7 +1123,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.7.0' +version: '8.7.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1134,7 +1139,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.7.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.7.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1805,7 +1810,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.7.0/pubnub.8.7.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.7.1/pubnub.8.7.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index b886b9fe8..22788d20d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.7.1 +January 31 2025 + +#### Fixed +- Fix long-poll request cancellation caused by APM packages monkey patching 'fetch' and try to use 'native' implementation instead of patched. + ## v8.7.0 January 30 2025 diff --git a/README.md b/README.md index 124b6026d..903fa2bd0 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index d4205ef77..2a1a26886 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3370,14 +3370,24 @@ /** * Create and configure transport provider for Web and Rect environments. * + * @param originalFetch - Pointer to the original (not monkey patched) `fetch` implementation. * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. * @param logVerbosity - Whether verbose logs should be printed or not. * * @internal */ - constructor(keepAlive = false, logVerbosity) { + constructor(originalFetch, keepAlive = false, logVerbosity = false) { this.keepAlive = keepAlive; this.logVerbosity = logVerbosity; + WebReactNativeTransport.originalFetch = originalFetch; + // Check whether `fetch` has been monkey patched or not. + if (logVerbosity && this.isFetchMonkeyPatched()) { + console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); + if (!this.isFetchMonkeyPatched(WebReactNativeTransport.originalFetch)) + console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); + else + console.warn('[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation'); + } } makeSendable(req) { let controller; @@ -3407,7 +3417,11 @@ }, req.timeout * 1000); }); return Promise.race([ - fetch(request, { signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, credentials: 'omit', cache: 'no-cache' }), + WebReactNativeTransport.originalFetch(request, { + signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, + credentials: 'omit', + cache: 'no-cache', + }), requestTimeout, ]) .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) @@ -3522,6 +3536,17 @@ console.log('-----'); } } + /** + * Check whether original `fetch` has been monkey patched or not. + * + * @returns `true` if original `fetch` has been patched. + * + * @internal + */ + isFetchMonkeyPatched(oFetch) { + const fetchString = (oFetch !== null && oFetch !== void 0 ? oFetch : fetch).toString(); + return !fetchString.includes('[native code]') && fetch.name !== 'fetch'; + } } /** * Service {@link ArrayBuffer} response decoder. @@ -3975,7 +4000,7 @@ return base.PubNubFile; }, get version() { - return '8.7.0'; + return '8.7.1'; }, getVersion() { return this.version; @@ -14544,7 +14569,7 @@ let cryptography; cryptography = new WebCryptography(); // Setup transport provider. - let transport = new WebReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity); + let transport = new WebReactNativeTransport(PubNub.originalFetch(), clientConfiguration.keepAlive, clientConfiguration.logVerbosity); { if (configurationCopy.subscriptionWorkerUrl) { // Inject subscription worker into transport provider stack. @@ -14593,6 +14618,19 @@ this.listenerManager.announceNetworkUp(); this.reconnect(); } + static originalFetch() { + let iframe = document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]'); + if (!iframe) { + iframe = document.createElement('iframe'); + iframe.style.display = 'none'; + iframe.name = 'pubnub-context-unpatched-fetch'; + iframe.src = 'about:blank'; + document.body.appendChild(iframe); + } + if (iframe.contentWindow) + return iframe.contentWindow.fetch.bind(iframe.contentWindow); + return fetch; + } } /** * Data encryption / decryption module constructor. diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 2e2ed8010..15e6caa87 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},F=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},R=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class U{constructor(e=!1,t){this.keepAlive=e,this.logVerbosity=t}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([fetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${U.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${U.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}U.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.7.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Fe=ge("DELAYED_HEARTBEAT",(e=>e));class Re extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Fe.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Ue=new ue("HEARTBEAT_STOPPED");Ue.on(ke.type,((e,t)=>Ue.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>Ue.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Ue.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Fe(e))),De.onExit((()=>Fe.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Ue.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Re(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=F(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=F(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=R(this.channels,e),i=R(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ft extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Rt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Rt||(Rt={}));class Ut extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Rt.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Ut.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Rt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0||e.operation()===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new U(i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},F=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},U=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class R{constructor(e,t=!1,s=!1){this.keepAlive=t,this.logVerbosity=s,R.originalFetch=e,s&&this.isFetchMonkeyPatched()&&(console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(R.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."))}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([R.originalFetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${R.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${R.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}R.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.7.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Fe=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Fe.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Re=new ue("HEARTBEAT_STOPPED");Re.on(ke.type,((e,t)=>Re.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Re.on(Ee.type,((e,t)=>Re.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Re.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Re.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Fe(e))),De.onExit((()=>Fe.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=F(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=F(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ft extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Rt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0||e.operation()===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new R(Ms.originalFetch(),i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}static originalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index feb36f0fa..b5954945a 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.7.0'; + return '8.7.1'; }, getVersion() { return this.version; diff --git a/lib/react_native/index.js b/lib/react_native/index.js index 0f89b88ba..4f3af28e2 100644 --- a/lib/react_native/index.js +++ b/lib/react_native/index.js @@ -62,7 +62,7 @@ class PubNub extends pubnub_common_1.PubNubCore { const transportMiddleware = new middleware_1.PubNubMiddleware({ clientConfiguration, tokenManager, - transport: new web_react_native_transport_1.WebReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity), + transport: new web_react_native_transport_1.WebReactNativeTransport(fetch, clientConfiguration.keepAlive, clientConfiguration.logVerbosity), }); super({ configuration: clientConfiguration, diff --git a/lib/transport/web-react-native-transport.js b/lib/transport/web-react-native-transport.js index cbef75131..1741abb91 100644 --- a/lib/transport/web-react-native-transport.js +++ b/lib/transport/web-react-native-transport.js @@ -26,14 +26,24 @@ class WebReactNativeTransport { /** * Create and configure transport provider for Web and Rect environments. * + * @param originalFetch - Pointer to the original (not monkey patched) `fetch` implementation. * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. * @param logVerbosity - Whether verbose logs should be printed or not. * * @internal */ - constructor(keepAlive = false, logVerbosity) { + constructor(originalFetch, keepAlive = false, logVerbosity = false) { this.keepAlive = keepAlive; this.logVerbosity = logVerbosity; + WebReactNativeTransport.originalFetch = originalFetch; + // Check whether `fetch` has been monkey patched or not. + if (logVerbosity && this.isFetchMonkeyPatched()) { + console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); + if (!this.isFetchMonkeyPatched(WebReactNativeTransport.originalFetch)) + console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); + else + console.warn('[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation'); + } } makeSendable(req) { let controller; @@ -63,7 +73,11 @@ class WebReactNativeTransport { }, req.timeout * 1000); }); return Promise.race([ - fetch(request, { signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, credentials: 'omit', cache: 'no-cache' }), + WebReactNativeTransport.originalFetch(request, { + signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, + credentials: 'omit', + cache: 'no-cache', + }), requestTimeout, ]) .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) @@ -178,6 +192,17 @@ class WebReactNativeTransport { console.log('-----'); } } + /** + * Check whether original `fetch` has been monkey patched or not. + * + * @returns `true` if original `fetch` has been patched. + * + * @internal + */ + isFetchMonkeyPatched(oFetch) { + const fetchString = (oFetch !== null && oFetch !== void 0 ? oFetch : fetch).toString(); + return !fetchString.includes('[native code]') && fetch.name !== 'fetch'; + } } exports.WebReactNativeTransport = WebReactNativeTransport; /** diff --git a/package.json b/package.json index 9c6ff6785..cd3489858 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.7.0", + "version": "8.7.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 8fa7c7d72..416536c1d 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.7.0'; + return '8.7.1'; }, getVersion(): string { return this.version; diff --git a/src/react_native/index.ts b/src/react_native/index.ts index dc05e882a..c0a3125be 100644 --- a/src/react_native/index.ts +++ b/src/react_native/index.ts @@ -72,7 +72,7 @@ export default class PubNub extends PubNubCore { const transportMiddleware = new PubNubMiddleware({ clientConfiguration, tokenManager, - transport: new WebReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity!), + transport: new WebReactNativeTransport(fetch, clientConfiguration.keepAlive, clientConfiguration.logVerbosity!), }); super({ diff --git a/src/transport/web-react-native-transport.ts b/src/transport/web-react-native-transport.ts index a07e0ce52..e3b0e9ef3 100644 --- a/src/transport/web-react-native-transport.ts +++ b/src/transport/web-react-native-transport.ts @@ -17,6 +17,15 @@ import { queryStringFromObject } from '../core/utils'; * @internal */ export class WebReactNativeTransport implements Transport { + /** + * Pointer to the "clean" `fetch` function. + * + * This protects against APM which overload implementation and may break crucial functionality. + * + * @internal + */ + private static originalFetch: typeof fetch; + /** * Service {@link ArrayBuffer} response decoder. * @@ -27,15 +36,30 @@ export class WebReactNativeTransport implements Transport { /** * Create and configure transport provider for Web and Rect environments. * + * @param originalFetch - Pointer to the original (not monkey patched) `fetch` implementation. * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. * @param logVerbosity - Whether verbose logs should be printed or not. * * @internal */ constructor( + originalFetch: unknown, private keepAlive: boolean = false, - private readonly logVerbosity: boolean, - ) {} + private readonly logVerbosity: boolean = false, + ) { + WebReactNativeTransport.originalFetch = originalFetch as typeof fetch; + + // Check whether `fetch` has been monkey patched or not. + if (logVerbosity && this.isFetchMonkeyPatched()) { + console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); + if (!this.isFetchMonkeyPatched(WebReactNativeTransport.originalFetch)) + console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); + else + console.warn( + '[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation', + ); + } + } makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { let controller: CancellationController | undefined; @@ -71,7 +95,11 @@ export class WebReactNativeTransport implements Transport { }); return Promise.race([ - fetch(request, { signal: abortController?.signal, credentials: 'omit', cache: 'no-cache' }), + WebReactNativeTransport.originalFetch(request, { + signal: abortController?.signal, + credentials: 'omit', + cache: 'no-cache', + }), requestTimeout, ]) .then((response): Promise<[Response, ArrayBuffer]> | [Response, ArrayBuffer] => @@ -198,4 +226,17 @@ export class WebReactNativeTransport implements Transport { console.log('-----'); } } + + /** + * Check whether original `fetch` has been monkey patched or not. + * + * @returns `true` if original `fetch` has been patched. + * + * @internal + */ + private isFetchMonkeyPatched(oFetch?: typeof fetch): boolean { + const fetchString = (oFetch ?? fetch).toString(); + + return !fetchString.includes('[native code]') && fetch.name !== 'fetch'; + } } diff --git a/src/web/index.ts b/src/web/index.ts index b634b51c6..638f3bb51 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -93,6 +93,7 @@ export default class PubNub extends PubNubCore('iframe[name="pubnub-context-unpatched-fetch"]'); + + if (!iframe) { + iframe = document.createElement('iframe'); + iframe.style.display = 'none'; + iframe.name = 'pubnub-context-unpatched-fetch'; + iframe.src = 'about:blank'; + document.body.appendChild(iframe); + } + + if (iframe.contentWindow) return iframe.contentWindow.fetch.bind(iframe.contentWindow); + return fetch; + } } From 07b34184f7b9bcb7baaff230813b8b33a287d2df Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Wed, 5 Feb 2025 12:28:46 +0200 Subject: [PATCH 35/49] Add the ability to switch transport API (#435) feat(transport): add the ability to switch transport API For the browser version of PubNub SDK, add the ability to switch between `fetch` and `xhr` APIs (`transport` configuration option). fix(event-engine): handshake/receive requests timeout Fix issue because of which, in Event Engine mode, wrong timeout values have been set for requests which creates long-poll request. refactor(request): make sure request cancels on timeout Refactor `timeout` implementation for `fetch` transport to properly cancel request when the timeout timer will fire. --- .pubnub.yml | 15 +- CHANGELOG.md | 12 + README.md | 4 +- dist/web/pubnub.js | 691 ++++++++++-------- dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/core/components/request.js | 2 +- lib/core/pubnub-common.js | 12 +- lib/errors/pubnub-api-error.js | 4 +- lib/react_native/index.js | 4 +- ...transport.js => react-native-transport.js} | 67 +- lib/types/index.d.ts | 23 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/components/request.ts | 2 +- src/core/pubnub-common.ts | 17 +- src/core/types/transport-request.ts | 2 +- src/errors/pubnub-api-error.ts | 4 +- src/event-engine/core/retryPolicy.ts | 24 + src/react_native/index.ts | 4 +- ...transport.ts => react-native-transport.ts} | 78 +- src/transport/web-transport.ts | 389 ++++++++++ src/web/components/configuration.ts | 15 + src/web/index.ts | 21 +- tsconfig.json | 3 +- tsconfig.rollup.json | 3 +- 26 files changed, 954 insertions(+), 452 deletions(-) rename lib/transport/{web-react-native-transport.js => react-native-transport.js} (74%) rename src/transport/{web-react-native-transport.ts => react-native-transport.ts} (72%) create mode 100644 src/transport/web-transport.ts diff --git a/.pubnub.yml b/.pubnub.yml index 4e2f70134..6e3d617c6 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,14 @@ --- changelog: + - date: 2025-02-05 + version: v8.8.0 + changes: + - type: feature + text: "For the browser version of PubNub SDK, add the ability to switch between `fetch` and `xhr` APIs (`transport` configuration option)." + - type: bug + text: "Fix issue because of which, in Event Engine mode, wrong timeout values have been set for requests which create long-poll request." + - type: improvement + text: "Refactor `timeout` implementation for `fetch` transport to properly cancel request when the timeout timer will fire." - date: 2025-01-31 version: v8.7.1 changes: @@ -1123,7 +1132,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.7.1' +version: '8.8.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1139,7 +1148,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.7.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.8.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1810,7 +1819,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.7.1/pubnub.8.7.1.js + location: https://github.com/pubnub/javascript/releases/download/v8.8.0/pubnub.8.8.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 22788d20d..b258f85da 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## v8.8.0 +February 05 2025 + +#### Added +- For the browser version of PubNub SDK, add the ability to switch between `fetch` and `xhr` APIs (`transport` configuration option). + +#### Fixed +- Fix issue because of which, in Event Engine mode, wrong timeout values have been set for requests which create long-poll request. + +#### Modified +- Refactor `timeout` implementation for `fetch` transport to properly cancel request when the timeout timer will fire. + ## v8.7.1 January 31 2025 diff --git a/README.md b/README.md index 903fa2bd0..dfd7f7b13 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.7.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.8.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.8.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 2a1a26886..7ad0bbbec 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -2907,11 +2907,11 @@ category = StatusCategory$1.PNCancelledCategory; message = 'Request cancelled'; } - else if (message.indexOf('timeout') !== -1) { + else if (message.toLowerCase().indexOf('timeout') !== -1) { category = StatusCategory$1.PNTimeoutCategory; message = 'Request timeout'; } - else if (message.indexOf('network') !== -1) { + else if (message.toLowerCase().indexOf('network') !== -1) { category = StatusCategory$1.PNNetworkIssuesCategory; message = 'Network issues'; } @@ -3283,278 +3283,6 @@ } } - /** - * PubNub package utilities module. - * - * @internal - */ - /** - * Percent-encode input string. - * - * **Note:** Encode content in accordance of the `PubNub` service requirements. - * - * @param input - Source string or number for encoding. - * - * @returns Percent-encoded string. - * - * @internal - */ - const encodeString = (input) => { - return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); - }; - /** - * Percent-encode list of names (channels). - * - * @param names - List of names which should be encoded. - * - * @param [defaultString] - String which should be used in case if {@link names} is empty. - * - * @returns String which contains encoded names joined by non-encoded `,`. - * - * @internal - */ - const encodeNames = (names, defaultString) => { - const encodedNames = names.map((name) => encodeString(name)); - return encodedNames.length ? encodedNames.join(',') : (defaultString !== null && defaultString !== void 0 ? defaultString : ''); - }; - /** - * @internal - */ - const removeSingleOccurrence = (source, elementsToRemove) => { - const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); - return source.filter((e) => { - if (elementsToRemove.includes(e) && !removed[e]) { - removed[e] = true; - return false; - } - return true; - }); - }; - /** - * @internal - */ - const findUniqueCommonElements = (a, b) => { - return [...a].filter((value) => b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value)); - }; - /** - * Transform query key / value pairs to the string. - * - * @param query - Key / value pairs of the request query parameters. - * - * @returns Stringified query key / value pairs. - * - * @internal - */ - const queryStringFromObject = (query) => { - return Object.keys(query) - .map((key) => { - const queryValue = query[key]; - if (!Array.isArray(queryValue)) - return `${key}=${encodeString(queryValue)}`; - return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); - }) - .join('&'); - }; - - /** - * Common browser and React Native Transport provider module. - * - * @internal - */ - /** - * Class representing a `fetch`-based browser and React Native transport provider. - * - * @internal - */ - class WebReactNativeTransport { - /** - * Create and configure transport provider for Web and Rect environments. - * - * @param originalFetch - Pointer to the original (not monkey patched) `fetch` implementation. - * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. - * @param logVerbosity - Whether verbose logs should be printed or not. - * - * @internal - */ - constructor(originalFetch, keepAlive = false, logVerbosity = false) { - this.keepAlive = keepAlive; - this.logVerbosity = logVerbosity; - WebReactNativeTransport.originalFetch = originalFetch; - // Check whether `fetch` has been monkey patched or not. - if (logVerbosity && this.isFetchMonkeyPatched()) { - console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); - if (!this.isFetchMonkeyPatched(WebReactNativeTransport.originalFetch)) - console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); - else - console.warn('[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation'); - } - } - makeSendable(req) { - let controller; - let abortController; - if (req.cancellable) { - abortController = new AbortController(); - controller = { - // Storing controller inside to prolong object lifetime. - abortController, - abort: () => abortController === null || abortController === void 0 ? void 0 : abortController.abort(), - }; - } - return [ - this.requestFromTransportRequest(req).then((request) => { - const start = new Date().getTime(); - this.logRequestProcessProgress(request, req.body); - /** - * Setup request timeout promise. - * - * **Note:** Native Fetch API doesn't support `timeout` out-of-box. - */ - const requestTimeout = new Promise((_, reject) => { - const timeoutId = setTimeout(() => { - // Clean up. - clearTimeout(timeoutId); - reject(new Error('Request timeout')); - }, req.timeout * 1000); - }); - return Promise.race([ - WebReactNativeTransport.originalFetch(request, { - signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, - credentials: 'omit', - cache: 'no-cache', - }), - requestTimeout, - ]) - .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) - .then((response) => { - const responseBody = response[1].byteLength > 0 ? response[1] : undefined; - const { status, headers: requestHeaders } = response[0]; - const headers = {}; - // Copy Headers object content into plain Record. - requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); - const transportResponse = { - status, - url: request.url, - headers, - body: responseBody, - }; - if (status >= 400) - throw PubNubAPIError.create(transportResponse); - this.logRequestProcessProgress(request, undefined, new Date().getTime() - start, responseBody); - return transportResponse; - }) - .catch((error) => { - throw PubNubAPIError.create(error); - }); - }), - controller, - ]; - } - request(req) { - return req; - } - /** - * Creates a Request object from a given {@link TransportRequest} object. - * - * @param req - The {@link TransportRequest} object containing request information. - * - * @returns Request object generated from the {@link TransportRequest} object. - * - * @internal - */ - requestFromTransportRequest(req) { - return __awaiter(this, void 0, void 0, function* () { - let body; - let path = req.path; - // Create multipart request body. - if (req.formData && req.formData.length > 0) { - // Reset query parameters to conform to signed URL - req.queryParameters = {}; - const file = req.body; - const formData = new FormData(); - for (const { key, value } of req.formData) - formData.append(key, value); - try { - const fileData = yield file.toArrayBuffer(); - formData.append('file', new Blob([fileData], { type: 'application/octet-stream' }), file.name); - } - catch (_) { - try { - const fileData = yield file.toFileUri(); - // @ts-expect-error React Native File Uri support. - formData.append('file', fileData, file.name); - } - catch (_) { } - } - body = formData; - } - // Handle regular body payload (if passed). - else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) - body = req.body; - if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) - path = `${path}?${queryStringFromObject(req.queryParameters)}`; - return new Request(`${req.origin}${path}`, { - method: req.method, - headers: req.headers, - redirect: 'follow', - body, - }); - }); - } - /** - * Log out request processing progress and result. - * - * @param request - Platform-specific - * @param [requestBody] - POST / PATCH body. - * @param [elapsed] - How many seconds passed since request processing started. - * @param [body] - Service response (if available). - * - * @internal - */ - logRequestProcessProgress(request, requestBody, elapsed, body) { - if (!this.logVerbosity) - return; - const { protocol, host, pathname, search } = new URL(request.url); - const timestamp = new Date().toISOString(); - if (!elapsed) { - let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; - if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { - if (typeof requestBody === 'string') - outgoing += `\n\n${requestBody}`; - else - outgoing += `\n\n${WebReactNativeTransport.decoder.decode(requestBody)}`; - } - console.log(`<<<<<`); - console.log(outgoing); - console.log('-----'); - } - else { - let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; - if (body) - outgoing += `\n\n${WebReactNativeTransport.decoder.decode(body)}`; - console.log('>>>>>>'); - console.log(outgoing); - console.log('-----'); - } - } - /** - * Check whether original `fetch` has been monkey patched or not. - * - * @returns `true` if original `fetch` has been patched. - * - * @internal - */ - isFetchMonkeyPatched(oFetch) { - const fetchString = (oFetch !== null && oFetch !== void 0 ? oFetch : fetch).toString(); - return !fetchString.includes('[native code]') && fetch.name !== 'fetch'; - } - } - /** - * Service {@link ArrayBuffer} response decoder. - * - * @internal - */ - WebReactNativeTransport.decoder = new TextDecoder(); - /** * CBOR support module. * @@ -3800,6 +3528,10 @@ * Whether verbose logging should be enabled for `Subscription` worker to print debug messages or not. */ const SUBSCRIPTION_WORKER_LOG_VERBOSITY = false; + /** + * Use modern Web Fetch API for network requests by default. + */ + const TRANSPORT = 'fetch'; /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -3812,13 +3544,13 @@ * @internal */ const setDefaults = (configuration) => { - var _a, _b, _c; + var _a, _b, _c, _d; // Force disable service workers if environment doesn't support them. if (configuration.subscriptionWorkerUrl && typeof SharedWorker === 'undefined') configuration.subscriptionWorkerUrl = null; return Object.assign(Object.assign({}, setDefaults$1(configuration)), { // Set platform-specific options. - listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, subscriptionWorkerLogVerbosity: (_b = configuration.subscriptionWorkerLogVerbosity) !== null && _b !== void 0 ? _b : SUBSCRIPTION_WORKER_LOG_VERBOSITY, keepAlive: (_c = configuration.keepAlive) !== null && _c !== void 0 ? _c : KEEP_ALIVE }); + listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, subscriptionWorkerLogVerbosity: (_b = configuration.subscriptionWorkerLogVerbosity) !== null && _b !== void 0 ? _b : SUBSCRIPTION_WORKER_LOG_VERBOSITY, transport: (_c = configuration.transport) !== null && _c !== void 0 ? _c : TRANSPORT, keepAlive: (_d = configuration.keepAlive) !== null && _d !== void 0 ? _d : KEEP_ALIVE }); }; var uuid = {exports: {}}; @@ -4000,7 +3732,7 @@ return base.PubNubFile; }, get version() { - return '8.7.1'; + return '8.8.0'; }, getVersion() { return this.version; @@ -4219,6 +3951,79 @@ TransportMethod["LOCAL"] = "LOCAL"; })(TransportMethod || (TransportMethod = {})); + /** + * PubNub package utilities module. + * + * @internal + */ + /** + * Percent-encode input string. + * + * **Note:** Encode content in accordance of the `PubNub` service requirements. + * + * @param input - Source string or number for encoding. + * + * @returns Percent-encoded string. + * + * @internal + */ + const encodeString = (input) => { + return encodeURIComponent(input).replace(/[!~*'()]/g, (x) => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); + }; + /** + * Percent-encode list of names (channels). + * + * @param names - List of names which should be encoded. + * + * @param [defaultString] - String which should be used in case if {@link names} is empty. + * + * @returns String which contains encoded names joined by non-encoded `,`. + * + * @internal + */ + const encodeNames = (names, defaultString) => { + const encodedNames = names.map((name) => encodeString(name)); + return encodedNames.length ? encodedNames.join(',') : (defaultString !== null && defaultString !== void 0 ? defaultString : ''); + }; + /** + * @internal + */ + const removeSingleOccurrence = (source, elementsToRemove) => { + const removed = Object.fromEntries(elementsToRemove.map((prop) => [prop, false])); + return source.filter((e) => { + if (elementsToRemove.includes(e) && !removed[e]) { + removed[e] = true; + return false; + } + return true; + }); + }; + /** + * @internal + */ + const findUniqueCommonElements = (a, b) => { + return [...a].filter((value) => b.includes(value) && a.indexOf(value) === a.lastIndexOf(value) && b.indexOf(value) === b.lastIndexOf(value)); + }; + /** + * Transform query key / value pairs to the string. + * + * @param query - Key / value pairs of the request query parameters. + * + * @returns Stringified query key / value pairs. + * + * @internal + */ + const queryStringFromObject = (query) => { + return Object.keys(query) + .map((key) => { + const queryValue = query[key]; + if (!Array.isArray(queryValue)) + return `${key}=${encodeString(queryValue)}`; + return queryValue.map((value) => `${key}=${encodeString(value)}`).join('&'); + }) + .join('&'); + }; + /** * Common PubNub Network Provider middleware module. * @@ -4366,6 +4171,309 @@ } } + /** + * Common browser and React Native Transport provider module. + * + * @internal + */ + /** + * Class representing a `fetch`-based browser and React Native transport provider. + * + * @internal + */ + class WebTransport { + /** + * Create and configure transport provider for Web and Rect environments. + * + * @param [transport] - API which should be used to make network requests. + * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. + * @param logVerbosity - Whether verbose logs should be printed or not. + * + * @internal + */ + constructor(transport = 'fetch', keepAlive = false, logVerbosity = false) { + this.transport = transport; + this.keepAlive = keepAlive; + this.logVerbosity = logVerbosity; + if (transport === 'fetch' && (!window || !window.fetch)) + this.transport = 'xhr'; + if (this.transport !== 'fetch') + return; + // Keeping reference on current `window.fetch` function. + WebTransport.originalFetch = fetch.bind(window); + // Check whether `fetch` has been monkey patched or not. + if (logVerbosity && this.isFetchMonkeyPatched()) { + console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); + WebTransport.originalFetch = WebTransport.getOriginalFetch(); + if (!this.isFetchMonkeyPatched(WebTransport.originalFetch)) + console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); + else + console.warn('[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation'); + } + } + makeSendable(req) { + const abortController = new AbortController(); + const cancellation = { + abortController, + abort: () => !abortController.signal.aborted && abortController.abort(), + }; + return [ + this.webTransportRequestFromTransportRequest(req).then((request) => { + const start = new Date().getTime(); + this.logRequestProcessProgress(request, req.body); + return this.sendRequest(request, cancellation) + .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) + .then((response) => { + const responseBody = response[1].byteLength > 0 ? response[1] : undefined; + const { status, headers: requestHeaders } = response[0]; + const headers = {}; + // Copy Headers object content into plain Record. + requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); + const transportResponse = { + status, + url: request.url, + headers, + body: responseBody, + }; + if (status >= 400) + throw PubNubAPIError.create(transportResponse); + this.logRequestProcessProgress(request, undefined, new Date().getTime() - start, responseBody); + return transportResponse; + }) + .catch((error) => { + throw PubNubAPIError.create(error); + }); + }), + cancellation, + ]; + } + request(req) { + return req; + } + /** + * Send network request using preferred API. + * + * @param req - Transport API agnostic request object with prepared body and URL. + * @param controller - Request cancellation controller (for long-poll requests). + * + * @returns Promise which will be resolved or rejected at the end of network request processing. + * + * @internal + */ + sendRequest(req, controller) { + return __awaiter(this, void 0, void 0, function* () { + if (this.transport === 'fetch') + return this.sendFetchRequest(req, controller); + return this.sendXHRRequest(req, controller); + }); + } + /** + * Send network request using legacy XMLHttpRequest API. + * + * @param req - Transport API agnostic request object with prepared body and URL. + * @param controller - Request cancellation controller (for long-poll requests). + * + * @returns Promise which will be resolved or rejected at the end of network request processing. + * + * @internal + */ + sendFetchRequest(req, controller) { + return __awaiter(this, void 0, void 0, function* () { + let timeoutId; + const requestTimeout = new Promise((_, reject) => { + timeoutId = setTimeout(() => { + clearTimeout(timeoutId); + reject(new Error('Request timeout')); + controller.abort(); + }, req.timeout * 1000); + }); + const request = new Request(req.url, { + method: req.method, + headers: req.headers, + redirect: 'follow', + body: req.body, + }); + return Promise.race([ + WebTransport.originalFetch(request, { + signal: controller.abortController.signal, + credentials: 'omit', + cache: 'no-cache', + }).then((response) => { + if (timeoutId) + clearTimeout(timeoutId); + return response; + }), + requestTimeout, + ]); + }); + } + /** + * Send network request using legacy XMLHttpRequest API. + * + * @param req - Transport API agnostic request object with prepared body and URL. + * @param controller - Request cancellation controller (for long-poll requests). + * + * @returns Promise which will be resolved or rejected at the end of network request processing. + * + * @internal + */ + sendXHRRequest(req, controller) { + return __awaiter(this, void 0, void 0, function* () { + return new Promise((resolve, reject) => { + var _a; + const xhr = new XMLHttpRequest(); + xhr.open(req.method, req.url, true); + // Setup request + xhr.responseType = 'arraybuffer'; + xhr.timeout = req.timeout * 1000; + controller.abortController.signal.onabort = () => { + if (xhr.readyState == XMLHttpRequest.DONE || xhr.readyState == XMLHttpRequest.UNSENT) + return; + xhr.abort(); + }; + Object.entries((_a = req.headers) !== null && _a !== void 0 ? _a : {}).forEach(([key, value]) => xhr.setRequestHeader(key, value)); + // Setup handlers to match `fetch` results handling. + xhr.onabort = () => reject(new Error('Aborted')); + xhr.ontimeout = () => reject(new Error('Request timeout')); + xhr.onerror = () => reject(new Error('Request timeout')); + xhr.onload = () => { + const headers = new Headers(); + xhr + .getAllResponseHeaders() + .split('\r\n') + .forEach((header) => { + const [key, value] = header.split(': '); + if (key.length > 1 && value.length > 1) + headers.append(key, value); + }); + resolve(new Response(xhr.response, { status: xhr.status, headers, statusText: xhr.statusText })); + }; + xhr.send(req.body); + }); + }); + } + /** + * Creates a Web Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + * + * @internal + */ + webTransportRequestFromTransportRequest(req) { + return __awaiter(this, void 0, void 0, function* () { + let body; + let path = req.path; + // Create multipart request body. + if (req.formData && req.formData.length > 0) { + // Reset query parameters to conform to signed URL + req.queryParameters = {}; + const file = req.body; + const formData = new FormData(); + for (const { key, value } of req.formData) + formData.append(key, value); + try { + const fileData = yield file.toArrayBuffer(); + formData.append('file', new Blob([fileData], { type: 'application/octet-stream' }), file.name); + } + catch (_) { + try { + const fileData = yield file.toFileUri(); + // @ts-expect-error React Native File Uri support. + formData.append('file', fileData, file.name); + } + catch (_) { } + } + body = formData; + } + // Handle regular body payload (if passed). + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) + body = req.body; + if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) + path = `${path}?${queryStringFromObject(req.queryParameters)}`; + return { + url: `${req.origin}${path}`, + method: req.method, + headers: req.headers, + timeout: req.timeout, + body, + }; + }); + } + /** + * Log out request processing progress and result. + * + * @param request - Platform-specific + * @param [requestBody] - POST / PATCH body. + * @param [elapsed] - How many seconds passed since request processing started. + * @param [body] - Service response (if available). + * + * @internal + */ + logRequestProcessProgress(request, requestBody, elapsed, body) { + if (!this.logVerbosity) + return; + const { protocol, host, pathname, search } = new URL(request.url); + const timestamp = new Date().toISOString(); + if (!elapsed) { + let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; + if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { + if (typeof requestBody === 'string') + outgoing += `\n\n${requestBody}`; + else + outgoing += `\n\n${WebTransport.decoder.decode(requestBody)}`; + } + console.log(`<<<<<`); + console.log(outgoing); + console.log('-----'); + } + else { + let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; + if (body) + outgoing += `\n\n${WebTransport.decoder.decode(body)}`; + console.log('>>>>>>'); + console.log(outgoing); + console.log('-----'); + } + } + /** + * Check whether original `fetch` has been monkey patched or not. + * + * @returns `true` if original `fetch` has been patched. + */ + isFetchMonkeyPatched(oFetch) { + const fetchString = (oFetch !== null && oFetch !== void 0 ? oFetch : fetch).toString(); + return !fetchString.includes('[native code]') && fetch.name !== 'fetch'; + } + /** + * Retrieve original `fetch` implementation. + * + * Retrieve implementation which hasn't been patched by APM tools. + * + * @returns Reference to the `fetch` function. + */ + static getOriginalFetch() { + let iframe = document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]'); + if (!iframe) { + iframe = document.createElement('iframe'); + iframe.style.display = 'none'; + iframe.name = 'pubnub-context-unpatched-fetch'; + iframe.src = 'about:blank'; + document.body.appendChild(iframe); + } + if (iframe.contentWindow) + return iframe.contentWindow.fetch.bind(iframe.contentWindow); + return fetch; + } + } + /** + * Service {@link ArrayBuffer} response decoder. + * + * @internal + */ + WebTransport.decoder = new TextDecoder(); + /** * Events listener manager module. */ @@ -5759,7 +5867,7 @@ path: this.path, queryParameters: this.queryParameters, cancellable: (_d = (_c = this.params) === null || _c === void 0 ? void 0 : _c.cancellable) !== null && _d !== void 0 ? _d : false, - timeout: 10000, + timeout: 10, identifier: this.requestIdentifier, }; // Attach headers (if required). @@ -13099,13 +13207,15 @@ } // Complete request configuration. const transportRequest = request.request(); + const operation = request.operation(); if ((transportRequest.formData && transportRequest.formData.length > 0) || - request.operation() === RequestOperation$1.PNDownloadFileOperation) { + operation === RequestOperation$1.PNDownloadFileOperation) { // Set file upload / download request delay. transportRequest.timeout = this._configuration.getFileTimeout(); } else { - if (request.operation() === RequestOperation$1.PNSubscribeOperation) + if (operation === RequestOperation$1.PNSubscribeOperation || + operation === RequestOperation$1.PNReceiveMessagesOperation) transportRequest.timeout = this._configuration.getSubscribeTimeout(); else transportRequest.timeout = this._configuration.getTransactionTimeout(); @@ -13113,7 +13223,7 @@ // API request processing status. const status = { error: false, - operation: request.operation(), + operation, category: StatusCategory$1.PNAcknowledgmentCategory, statusCode: 0, }; @@ -13149,8 +13259,8 @@ const apiError = !(error instanceof PubNubAPIError) ? PubNubAPIError.create(error) : error; // Notify callback (if possible). if (callback) - return callback(apiError.toStatus(request.operation()), null); - throw apiError.toPubNubError(request.operation(), 'REST API request processing error, check status for details'); + return callback(apiError.toStatus(operation), null); + throw apiError.toPubNubError(operation, 'REST API request processing error, check status for details'); }); }); } @@ -14569,7 +14679,7 @@ let cryptography; cryptography = new WebCryptography(); // Setup transport provider. - let transport = new WebReactNativeTransport(PubNub.originalFetch(), clientConfiguration.keepAlive, clientConfiguration.logVerbosity); + let transport = new WebTransport(platformConfiguration.transport, clientConfiguration.keepAlive, clientConfiguration.logVerbosity); { if (configurationCopy.subscriptionWorkerUrl) { // Inject subscription worker into transport provider stack. @@ -14618,19 +14728,6 @@ this.listenerManager.announceNetworkUp(); this.reconnect(); } - static originalFetch() { - let iframe = document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]'); - if (!iframe) { - iframe = document.createElement('iframe'); - iframe.style.display = 'none'; - iframe.name = 'pubnub-context-unpatched-fetch'; - iframe.src = 'about:blank'; - document.body.appendChild(iframe); - } - if (iframe.contentWindow) - return iframe.contentWindow.fetch.bind(iframe.contentWindow); - return fetch; - } } /** * Data encryption / decryption module constructor. diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 15e6caa87..2735878d0 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}const j=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),I=(e,t)=>{const s=e.map((e=>j(e)));return s.length?s.join(","):null!=t?t:""},F=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},U=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class R{constructor(e,t=!1,s=!1){this.keepAlive=t,this.logVerbosity=s,R.originalFetch=e,s&&this.isFetchMonkeyPatched()&&(console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(R.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."))}makeSendable(e){let t,s;return e.cancellable&&(s=new AbortController,t={abortController:s,abort:()=>null==s?void 0:s.abort()}),[this.requestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();this.logRequestProcessProgress(t,e.body);const r=new Promise(((t,s)=>{const n=setTimeout((()=>{clearTimeout(n),s(new Error("Request timeout"))}),1e3*e.timeout)}));return Promise.race([R.originalFetch(t,{signal:null==s?void 0:s.signal,credentials:"omit",cache:"no-cache"}),r]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),t]}request(e){return e}requestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&")}`),new Request(`${e.origin}${s}`,{method:e.method,headers:e.headers,redirect:"follow",body:t})}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${R.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${R.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?T(a):a})),n}R.decoder=new TextDecoder;const x=e=>{var t,s,n;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,keepAlive:null===(n=e.keepAlive)||void 0===n||n})};var D={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(D,D.exports);var q=t(D.exports),G={createUUID:()=>q.uuid?q.uuid():q()};const K=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=$(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${G.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.7.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},$=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var B,H;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(B||(B={}));class z{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?B.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===B.POST||t===B.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=z.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${j(e)}`)).join("&"):`${t}=${j(s)}`})).join("&")}}z.textDecoder=new TextDecoder("utf-8");class V{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new z(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class W{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class J{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class X{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Z extends X{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class ee extends X{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class te{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Z(this._payload.apns,e,t),this.fcm=new ee(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=G.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:B.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:1e4,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===B.POST||r.method===B.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=se.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(H||(H={}));var ne=H;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends se{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=se.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Fe=ge("DELAYED_HEARTBEAT",(e=>e));class Ue extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Fe.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Re=new ue("HEARTBEAT_STOPPED");Re.on(ke.type,((e,t)=>Re.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Re.on(Ee.type,((e,t)=>Re.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Re.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Re.on(Oe.type,((e,t)=>Ge.with(void 0)));const Te=new ue("HEARTBEAT_COOLDOWN");Te.onEnter((()=>Ie())),Te.onExit((()=>Ie.cancel)),Te.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Te.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Te.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Fe(e))),De.onExit((()=>Fe.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Re.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Ye=de("HANDSHAKE_SUCCESS",(e=>e)),Xe=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Xe(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Qe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Qe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Ye.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Xe.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=F(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=F(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=U(this.channels,e),i=U(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends se{constructor(e){var t,s;super({method:e.sendByPost?B.POST:B.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${j(t)}/0${this.parameters.sendByPost?"":`/${j(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${j(s)}/0/${j(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${I(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=s?s:[],",")}/uuid/${j(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${I(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${I(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${j(t)}`}}class At extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${I(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${I(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Ft extends se{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${j(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Ft.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class Rt extends se{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${I(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${j(t)}/message/${n}/action/${s}`}}class qt extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${j(t)}/0/${j(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends se{constructor(e){super({method:B.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${j(e)}/files/${t}/${s}`}}class Kt extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(s)}/files/${t}/${n}`}}class $t extends se{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends se{constructor(e){super({method:B.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends se{constructor(e){super({method:B.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}`}}class ss extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${j(t)}/remove`}}class ns extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends se{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends se{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends se{constructor(e){super({method:B.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}}class ps extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends se{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends se{constructor(e){super({method:B.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}}class vs extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends se{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${j(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends se{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends se{constructor(e){var t,s,n;super({method:B.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${j(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends se{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends se{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${j(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new te(e,t)}static generateUUID(){return G.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new W,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Xt(e,this.eventEmitter,this)}channelGroup(e){return new Qt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Yt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request();n.formData&&n.formData.length>0||e.operation()===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():e.operation()===ne.PNSubscribeOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const r={error:!1,operation:e.operation(),category:h.PNAcknowledgmentCategory,statusCode:0},[i,o]=this.transport.makeSendable(n);return e.cancellationController=o||null,i.then((t=>{if(r.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(r.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(r,e):e)).catch((s=>{const n=s instanceof _?s:_.create(s);if(t)return t(n.toStatus(e.operation()),null);throw n.toPubNubError(e.operation(),"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${j(t)}`)).join("&"):`${e}=${j(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=x(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=K(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new L(new Ps((e=>T(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new R(Ms.originalFetch(),i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new V({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}static originalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}return Ms.CryptoModule=N,Ms})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}function j(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?j(a):a})),n}const I=e=>{var t,s,n,r;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,transport:null!==(n=e.transport)&&void 0!==n?n:"fetch",keepAlive:null===(r=e.keepAlive)||void 0===r||r})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var F=t(R.exports),T={createUUID:()=>F.uuid?F.uuid():F()};const U=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=x(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${T.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.8.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},x=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class D{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var q;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(q||(q={}));const G=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),K=(e,t)=>{const s=e.map((e=>G(e)));return s.length?s.join(","):null!=t?t:""},$=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},L=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class B{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?q.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===q.POST||t===q.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=B.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${G(e)}`)).join("&"):`${t}=${G(s)}`})).join("&")}}B.textDecoder=new TextDecoder("utf-8");class H{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new B(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class z{constructor(e="fetch",t=!1,s=!1){this.transport=e,this.keepAlive=t,this.logVerbosity=s,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),s&&this.isFetchMonkeyPatched()&&(console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),z.originalFetch=z.getOriginalFetch(),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")))}makeSendable(e){const t=new AbortController,s={abortController:t,abort:()=>!t.signal.aborted&&t.abort()};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,s).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),s]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let s;const n=new Promise(((n,r)=>{s=setTimeout((()=>{clearTimeout(s),r(new Error("Request timeout")),t.abort()}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(s&&clearTimeout(s),e))),n])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((s,n)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>n(new Error("Aborted")),i.ontimeout=()=>n(new Error("Request timeout")),i.onerror=()=>n(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[s,n]=t.split(": ");s.length>1&&n.length>1&&e.append(s,n)})),s(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${G(t)}`)).join("&"):`${e}=${G(t)}`})).join("&")}`),{url:`${e.origin}${s}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${z.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class V{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class W{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class J{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Q{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Y extends Q{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class Z extends Q{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class ee{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Y(this._payload.apns,e,t),this.fcm=new Z(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class te{constructor(e){this.params=e,this.requestIdentifier=T.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:q.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===q.POST||r.method===q.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=te.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var se;te.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(se||(se={}));var ne=se;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends te{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=te.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${K(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Fe extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Ue=new ue("HEARTBEAT_COOLDOWN");Ue.onEnter((()=>Ie())),Ue.onExit((()=>Ie.cancel)),Ue.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Ue.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Xe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Qe=de("HANDSHAKE_SUCCESS",(e=>e)),Ye=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Qe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ye(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Xe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Xe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Xe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Xe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Xe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Xe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Ye.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Xe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=$(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=$(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=L(this.channels,e),i=L(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends te{constructor(e){var t,s;super({method:e.sendByPost?q.POST:q.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${G(t)}/0${this.parameters.sendByPost?"":`/${G(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${G(s)}/0/${G(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${K(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${K(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends te{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=s?s:[],",")}/uuid/${G(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends te{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${K(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${G(t)}`}}class At extends te{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${K(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${G(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${K(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends te{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${G(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class Tt extends te{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ut extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends te{constructor(e){super({method:q.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}/message/${n}/action/${s}`}}class qt extends te{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${G(t)}/0/${G(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends te{constructor(e){super({method:q.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${G(e)}/files/${t}/${s}`}}class Kt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${G(s)}/files/${t}/${n}`}}class $t extends te{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends te{constructor(e){super({method:q.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends te{constructor(e){super({method:q.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}}class ss extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}/remove`}}class ns extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends te{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends te{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}}class ps extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends te{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends te{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends te{constructor(e){var t,s,n;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends te{constructor(e){super({method:q.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}}class vs extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends te{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends te{constructor(e){var t,s,n;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends te{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new ee(e,t)}static generateUUID(){return T.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new V,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new X(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Yt(e,this.eventEmitter,this)}channelGroup(e){return new Xt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Qt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request(),r=e.operation();n.formData&&n.formData.length>0||r===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():r===ne.PNSubscribeOperation||r===ne.PNReceiveMessagesOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[o,a]=this.transport.makeSendable(n);return e.cancellationController=a||null,o.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(i.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const s=e instanceof _?e:_.create(e);if(t)return t(s.toStatus(r),null);throw s.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${G(t)}`)).join("&"):`${e}=${G(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=I(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=U(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new D(new Ps((e=>j(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new z(r.transport,i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new H({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index b5954945a..48be7b42c 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.7.1'; + return '8.8.0'; }, getVersion() { return this.version; diff --git a/lib/core/components/request.js b/lib/core/components/request.js index e62ba202c..b3d050940 100644 --- a/lib/core/components/request.js +++ b/lib/core/components/request.js @@ -103,7 +103,7 @@ class AbstractRequest { path: this.path, queryParameters: this.queryParameters, cancellable: (_d = (_c = this.params) === null || _c === void 0 ? void 0 : _c.cancellable) !== null && _d !== void 0 ? _d : false, - timeout: 10000, + timeout: 10, identifier: this.requestIdentifier, }; // Attach headers (if required). diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index d8c093a99..6059ec9fc 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -550,13 +550,15 @@ class PubNubCore { } // Complete request configuration. const transportRequest = request.request(); + const operation = request.operation(); if ((transportRequest.formData && transportRequest.formData.length > 0) || - request.operation() === operations_1.default.PNDownloadFileOperation) { + operation === operations_1.default.PNDownloadFileOperation) { // Set file upload / download request delay. transportRequest.timeout = this._configuration.getFileTimeout(); } else { - if (request.operation() === operations_1.default.PNSubscribeOperation) + if (operation === operations_1.default.PNSubscribeOperation || + operation === operations_1.default.PNReceiveMessagesOperation) transportRequest.timeout = this._configuration.getSubscribeTimeout(); else transportRequest.timeout = this._configuration.getTransactionTimeout(); @@ -564,7 +566,7 @@ class PubNubCore { // API request processing status. const status = { error: false, - operation: request.operation(), + operation, category: categories_1.default.PNAcknowledgmentCategory, statusCode: 0, }; @@ -600,8 +602,8 @@ class PubNubCore { const apiError = !(error instanceof pubnub_api_error_1.PubNubAPIError) ? pubnub_api_error_1.PubNubAPIError.create(error) : error; // Notify callback (if possible). if (callback) - return callback(apiError.toStatus(request.operation()), null); - throw apiError.toPubNubError(request.operation(), 'REST API request processing error, check status for details'); + return callback(apiError.toStatus(operation), null); + throw apiError.toPubNubError(operation, 'REST API request processing error, check status for details'); }); }); } diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js index 0e01d8d69..1a9b41e2e 100644 --- a/lib/errors/pubnub-api-error.js +++ b/lib/errors/pubnub-api-error.js @@ -57,11 +57,11 @@ class PubNubAPIError extends Error { category = categories_1.default.PNCancelledCategory; message = 'Request cancelled'; } - else if (message.indexOf('timeout') !== -1) { + else if (message.toLowerCase().indexOf('timeout') !== -1) { category = categories_1.default.PNTimeoutCategory; message = 'Request timeout'; } - else if (message.indexOf('network') !== -1) { + else if (message.toLowerCase().indexOf('network') !== -1) { category = categories_1.default.PNNetworkIssuesCategory; message = 'Network issues'; } diff --git a/lib/react_native/index.js b/lib/react_native/index.js index 4f3af28e2..ff7e89315 100644 --- a/lib/react_native/index.js +++ b/lib/react_native/index.js @@ -7,8 +7,8 @@ const text_encoding_1 = require("text-encoding"); require("react-native-url-polyfill/auto"); const cbor_js_1 = __importDefault(require("cbor-js")); const buffer_1 = require("buffer"); -const web_react_native_transport_1 = require("../transport/web-react-native-transport"); const stringify_buffer_keys_1 = require("../core/components/stringify_buffer_keys"); +const react_native_transport_1 = require("../transport/react-native-transport"); const configuration_1 = require("../core/components/configuration"); const token_manager_1 = require("../core/components/token_manager"); const middleware_1 = require("../transport/middleware"); @@ -62,7 +62,7 @@ class PubNub extends pubnub_common_1.PubNubCore { const transportMiddleware = new middleware_1.PubNubMiddleware({ clientConfiguration, tokenManager, - transport: new web_react_native_transport_1.WebReactNativeTransport(fetch, clientConfiguration.keepAlive, clientConfiguration.logVerbosity), + transport: new react_native_transport_1.ReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity), }); super({ configuration: clientConfiguration, diff --git a/lib/transport/web-react-native-transport.js b/lib/transport/react-native-transport.js similarity index 74% rename from lib/transport/web-react-native-transport.js rename to lib/transport/react-native-transport.js index 1741abb91..d738dbde8 100644 --- a/lib/transport/web-react-native-transport.js +++ b/lib/transport/react-native-transport.js @@ -14,48 +14,34 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }); }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.WebReactNativeTransport = void 0; +exports.ReactNativeTransport = void 0; const pubnub_api_error_1 = require("../errors/pubnub-api-error"); const utils_1 = require("../core/utils"); /** - * Class representing a `fetch`-based browser and React Native transport provider. + * Class representing a React Native transport provider. * * @internal */ -class WebReactNativeTransport { +class ReactNativeTransport { /** * Create and configure transport provider for Web and Rect environments. * - * @param originalFetch - Pointer to the original (not monkey patched) `fetch` implementation. * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. * @param logVerbosity - Whether verbose logs should be printed or not. * * @internal */ - constructor(originalFetch, keepAlive = false, logVerbosity = false) { + constructor(keepAlive = false, logVerbosity = false) { this.keepAlive = keepAlive; this.logVerbosity = logVerbosity; - WebReactNativeTransport.originalFetch = originalFetch; - // Check whether `fetch` has been monkey patched or not. - if (logVerbosity && this.isFetchMonkeyPatched()) { - console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); - if (!this.isFetchMonkeyPatched(WebReactNativeTransport.originalFetch)) - console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); - else - console.warn('[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation'); - } } makeSendable(req) { - let controller; - let abortController; - if (req.cancellable) { - abortController = new AbortController(); - controller = { - // Storing controller inside to prolong object lifetime. - abortController, - abort: () => abortController === null || abortController === void 0 ? void 0 : abortController.abort(), - }; - } + const abortController = new AbortController(); + const controller = { + // Storing controller inside to prolong object lifetime. + abortController, + abort: () => !abortController.signal.aborted && abortController.abort(), + }; return [ this.requestFromTransportRequest(req).then((request) => { const start = new Date().getTime(); @@ -65,21 +51,27 @@ class WebReactNativeTransport { * * **Note:** Native Fetch API doesn't support `timeout` out-of-box. */ + let timeoutId; const requestTimeout = new Promise((_, reject) => { - const timeoutId = setTimeout(() => { - // Clean up. + timeoutId = setTimeout(() => { clearTimeout(timeoutId); reject(new Error('Request timeout')); + controller.abort(); }, req.timeout * 1000); }); return Promise.race([ - WebReactNativeTransport.originalFetch(request, { - signal: abortController === null || abortController === void 0 ? void 0 : abortController.signal, + fetch(request, { + signal: abortController.signal, credentials: 'omit', cache: 'no-cache', }), requestTimeout, ]) + .then((response) => { + if (timeoutId) + clearTimeout(timeoutId); + return response; + }) .then((response) => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer])) .then((response) => { const responseBody = response[1].byteLength > 0 ? response[1] : undefined; @@ -177,7 +169,7 @@ class WebReactNativeTransport { if (typeof requestBody === 'string') outgoing += `\n\n${requestBody}`; else - outgoing += `\n\n${WebReactNativeTransport.decoder.decode(requestBody)}`; + outgoing += `\n\n${ReactNativeTransport.decoder.decode(requestBody)}`; } console.log(`<<<<<`); console.log(outgoing); @@ -186,28 +178,17 @@ class WebReactNativeTransport { else { let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; if (body) - outgoing += `\n\n${WebReactNativeTransport.decoder.decode(body)}`; + outgoing += `\n\n${ReactNativeTransport.decoder.decode(body)}`; console.log('>>>>>>'); console.log(outgoing); console.log('-----'); } } - /** - * Check whether original `fetch` has been monkey patched or not. - * - * @returns `true` if original `fetch` has been patched. - * - * @internal - */ - isFetchMonkeyPatched(oFetch) { - const fetchString = (oFetch !== null && oFetch !== void 0 ? oFetch : fetch).toString(); - return !fetchString.includes('[native code]') && fetch.name !== 'fetch'; - } } -exports.WebReactNativeTransport = WebReactNativeTransport; +exports.ReactNativeTransport = ReactNativeTransport; /** * Service {@link ArrayBuffer} response decoder. * * @internal */ -WebReactNativeTransport.decoder = new TextDecoder(); +ReactNativeTransport.decoder = new TextDecoder(); diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index a660f5a14..7730d19b3 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -2753,14 +2753,35 @@ declare namespace PubNub { validate(): void; }; + /** + * Policy, which uses linear formula to calculate next request retry attempt time. + */ export type LinearRetryPolicyConfiguration = { + /** + * Delay between retry attempt (in seconds). + */ delay: number; + /** + * Maximum number of retry attempts. + */ maximumRetry: number; }; + /** + * Policy, which uses exponential formula to calculate next request retry attempt time. + */ export type ExponentialRetryPolicyConfiguration = { + /** + * Minimum delay between retry attempts (in seconds). + */ minimumDelay: number; + /** + * Maximum delay between retry attempts (in seconds). + */ maximumDelay: number; + /** + * Maximum number of retry attempts. + */ maximumRetry: number; }; @@ -2915,7 +2936,7 @@ declare namespace PubNub { */ body?: ArrayBuffer | PubNubFileInterface | string; /** - * For how long request should wait response from the server. + * For how long (in seconds) request should wait response from the server. * * @default `10` seconds. */ diff --git a/package.json b/package.json index cd3489858..3e61d294b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.7.1", + "version": "8.8.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 416536c1d..6261013f0 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.7.1'; + return '8.8.0'; }, getVersion(): string { return this.version; diff --git a/src/core/components/request.ts b/src/core/components/request.ts index 9600663dd..50b028140 100644 --- a/src/core/components/request.ts +++ b/src/core/components/request.ts @@ -107,7 +107,7 @@ export abstract class AbstractRequest implements Request 0) || - request.operation() === RequestOperation.PNDownloadFileOperation + operation === RequestOperation.PNDownloadFileOperation ) { // Set file upload / download request delay. transportRequest.timeout = this._configuration.getFileTimeout(); } else { - if (request.operation() === RequestOperation.PNSubscribeOperation) + if ( + operation === RequestOperation.PNSubscribeOperation || + operation === RequestOperation.PNReceiveMessagesOperation + ) transportRequest.timeout = this._configuration.getSubscribeTimeout(); else transportRequest.timeout = this._configuration.getTransactionTimeout(); } @@ -821,7 +825,7 @@ export class PubNubCore< // API request processing status. const status: Status = { error: false, - operation: request.operation(), + operation, category: StatusCategory.PNAcknowledgmentCategory, statusCode: 0, }; @@ -862,12 +866,9 @@ export class PubNubCore< const apiError = !(error instanceof PubNubAPIError) ? PubNubAPIError.create(error) : error; // Notify callback (if possible). - if (callback) return callback(apiError.toStatus(request.operation()), null); + if (callback) return callback(apiError.toStatus(operation), null); - throw apiError.toPubNubError( - request.operation(), - 'REST API request processing error, check status for details', - ); + throw apiError.toPubNubError(operation, 'REST API request processing error, check status for details'); }); } diff --git a/src/core/types/transport-request.ts b/src/core/types/transport-request.ts index 22ea0c521..582dc640c 100644 --- a/src/core/types/transport-request.ts +++ b/src/core/types/transport-request.ts @@ -90,7 +90,7 @@ export type TransportRequest = { body?: ArrayBuffer | PubNubFileInterface | string; /** - * For how long request should wait response from the server. + * For how long (in seconds) request should wait response from the server. * * @default `10` seconds. */ diff --git a/src/errors/pubnub-api-error.ts b/src/errors/pubnub-api-error.ts index 6ad50cf5d..6f7c4d3de 100644 --- a/src/errors/pubnub-api-error.ts +++ b/src/errors/pubnub-api-error.ts @@ -55,10 +55,10 @@ export class PubNubAPIError extends Error { if (errorName === 'AbortError' || message.indexOf('Aborted') !== -1) { category = StatusCategory.PNCancelledCategory; message = 'Request cancelled'; - } else if (message.indexOf('timeout') !== -1) { + } else if (message.toLowerCase().indexOf('timeout') !== -1) { category = StatusCategory.PNTimeoutCategory; message = 'Request timeout'; - } else if (message.indexOf('network') !== -1) { + } else if (message.toLowerCase().indexOf('network') !== -1) { category = StatusCategory.PNNetworkIssuesCategory; message = 'Network issues'; } else if (errorName === 'TypeError') { diff --git a/src/event-engine/core/retryPolicy.ts b/src/event-engine/core/retryPolicy.ts index f47606f80..289f15abb 100644 --- a/src/event-engine/core/retryPolicy.ts +++ b/src/event-engine/core/retryPolicy.ts @@ -122,13 +122,37 @@ export type RequestRetryPolicy = { validate(): void; }; +/** + * Policy, which uses linear formula to calculate next request retry attempt time. + */ export type LinearRetryPolicyConfiguration = { + /** + * Delay between retry attempt (in seconds). + */ delay: number; + + /** + * Maximum number of retry attempts. + */ maximumRetry: number; }; +/** + * Policy, which uses exponential formula to calculate next request retry attempt time. + */ export type ExponentialRetryPolicyConfiguration = { + /** + * Minimum delay between retry attempts (in seconds). + */ minimumDelay: number; + + /** + * Maximum delay between retry attempts (in seconds). + */ maximumDelay: number; + + /** + * Maximum number of retry attempts. + */ maximumRetry: number; }; diff --git a/src/react_native/index.ts b/src/react_native/index.ts index c0a3125be..7652007fd 100644 --- a/src/react_native/index.ts +++ b/src/react_native/index.ts @@ -4,8 +4,8 @@ import CborReader from 'cbor-js'; import { Buffer } from 'buffer'; import { ExtendedConfiguration, PlatformConfiguration } from '../core/interfaces/configuration'; -import { WebReactNativeTransport } from '../transport/web-react-native-transport'; import { stringifyBufferKeys } from '../core/components/stringify_buffer_keys'; +import { ReactNativeTransport } from '../transport/react-native-transport'; import { makeConfiguration } from '../core/components/configuration'; import { PubNubFileParameters } from '../file/modules/react-native'; import { TokenManager } from '../core/components/token_manager'; @@ -72,7 +72,7 @@ export default class PubNub extends PubNubCore { const transportMiddleware = new PubNubMiddleware({ clientConfiguration, tokenManager, - transport: new WebReactNativeTransport(fetch, clientConfiguration.keepAlive, clientConfiguration.logVerbosity!), + transport: new ReactNativeTransport(clientConfiguration.keepAlive, clientConfiguration.logVerbosity!), }); super({ diff --git a/src/transport/web-react-native-transport.ts b/src/transport/react-native-transport.ts similarity index 72% rename from src/transport/web-react-native-transport.ts rename to src/transport/react-native-transport.ts index e3b0e9ef3..a6fd22e42 100644 --- a/src/transport/web-react-native-transport.ts +++ b/src/transport/react-native-transport.ts @@ -12,20 +12,11 @@ import { PubNubFileInterface } from '../core/types/file'; import { queryStringFromObject } from '../core/utils'; /** - * Class representing a `fetch`-based browser and React Native transport provider. + * Class representing a React Native transport provider. * * @internal */ -export class WebReactNativeTransport implements Transport { - /** - * Pointer to the "clean" `fetch` function. - * - * This protects against APM which overload implementation and may break crucial functionality. - * - * @internal - */ - private static originalFetch: typeof fetch; - +export class ReactNativeTransport implements Transport { /** * Service {@link ArrayBuffer} response decoder. * @@ -36,43 +27,23 @@ export class WebReactNativeTransport implements Transport { /** * Create and configure transport provider for Web and Rect environments. * - * @param originalFetch - Pointer to the original (not monkey patched) `fetch` implementation. * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. * @param logVerbosity - Whether verbose logs should be printed or not. * * @internal */ constructor( - originalFetch: unknown, private keepAlive: boolean = false, private readonly logVerbosity: boolean = false, - ) { - WebReactNativeTransport.originalFetch = originalFetch as typeof fetch; - - // Check whether `fetch` has been monkey patched or not. - if (logVerbosity && this.isFetchMonkeyPatched()) { - console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); - if (!this.isFetchMonkeyPatched(WebReactNativeTransport.originalFetch)) - console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); - else - console.warn( - '[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation', - ); - } - } + ) {} makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { - let controller: CancellationController | undefined; - let abortController: AbortController | undefined; - - if (req.cancellable) { - abortController = new AbortController(); - controller = { - // Storing controller inside to prolong object lifetime. - abortController, - abort: () => abortController?.abort(), - } as CancellationController; - } + const abortController = new AbortController(); + const controller = { + // Storing controller inside to prolong object lifetime. + abortController, + abort: () => !abortController.signal.aborted && abortController.abort(), + } as CancellationController; return [ this.requestFromTransportRequest(req).then((request) => { @@ -85,23 +56,29 @@ export class WebReactNativeTransport implements Transport { * * **Note:** Native Fetch API doesn't support `timeout` out-of-box. */ + let timeoutId: ReturnType | undefined; + const requestTimeout = new Promise((_, reject) => { - const timeoutId = setTimeout(() => { - // Clean up. + timeoutId = setTimeout(() => { clearTimeout(timeoutId); reject(new Error('Request timeout')); + controller.abort(); }, req.timeout * 1000); }); return Promise.race([ - WebReactNativeTransport.originalFetch(request, { - signal: abortController?.signal, + fetch(request, { + signal: abortController.signal, credentials: 'omit', cache: 'no-cache', }), requestTimeout, ]) + .then((response) => { + if (timeoutId) clearTimeout(timeoutId); + return response; + }) .then((response): Promise<[Response, ArrayBuffer]> | [Response, ArrayBuffer] => response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer]), ) @@ -211,7 +188,7 @@ export class WebReactNativeTransport implements Transport { let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { if (typeof requestBody === 'string') outgoing += `\n\n${requestBody}`; - else outgoing += `\n\n${WebReactNativeTransport.decoder.decode(requestBody)}`; + else outgoing += `\n\n${ReactNativeTransport.decoder.decode(requestBody)}`; } console.log(`<<<<<`); @@ -219,24 +196,11 @@ export class WebReactNativeTransport implements Transport { console.log('-----'); } else { let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; - if (body) outgoing += `\n\n${WebReactNativeTransport.decoder.decode(body)}`; + if (body) outgoing += `\n\n${ReactNativeTransport.decoder.decode(body)}`; console.log('>>>>>>'); console.log(outgoing); console.log('-----'); } } - - /** - * Check whether original `fetch` has been monkey patched or not. - * - * @returns `true` if original `fetch` has been patched. - * - * @internal - */ - private isFetchMonkeyPatched(oFetch?: typeof fetch): boolean { - const fetchString = (oFetch ?? fetch).toString(); - - return !fetchString.includes('[native code]') && fetch.name !== 'fetch'; - } } diff --git a/src/transport/web-transport.ts b/src/transport/web-transport.ts new file mode 100644 index 000000000..1dc75e49e --- /dev/null +++ b/src/transport/web-transport.ts @@ -0,0 +1,389 @@ +/** + * Common browser and React Native Transport provider module. + * + * @internal + */ + +import { CancellationController, TransportRequest } from '../core/types/transport-request'; +import { TransportResponse } from '../core/types/transport-response'; +import { PubNubAPIError } from '../errors/pubnub-api-error'; +import { Transport } from '../core/interfaces/transport'; +import { PubNubFileInterface } from '../core/types/file'; +import { queryStringFromObject } from '../core/utils'; + +/** + * Object represent a request to be sent with API available in browser. + * + * @internal + */ +type WebTransportRequest = { + /** + * Full URL to the remote resource. + */ + url: string; + + /** + * For how long (in seconds) request should wait response from the server. + */ + timeout: number; + + /** + * Transport request HTTP method. + */ + method: TransportRequest['method']; + + /** + * Headers to be sent with the request. + */ + headers?: Record | undefined; + + /** + * Body to be sent with the request. + */ + body: string | ArrayBuffer | FormData | undefined; +}; + +/** + * Web request cancellation controller. + */ +type WebCancellationController = CancellationController & { + /** + * Abort controller object which provides abort signal. + */ + abortController: AbortController; +}; + +/** + * Class representing a `fetch`-based browser and React Native transport provider. + * + * @internal + */ +export class WebTransport implements Transport { + /** + * Pointer to the "clean" `fetch` function. + * + * This protects against APM which overload implementation and may break crucial functionality. + * + * @internal + */ + private static originalFetch: typeof fetch; + + /** + * Service {@link ArrayBuffer} response decoder. + * + * @internal + */ + protected static decoder = new TextDecoder(); + + /** + * Create and configure transport provider for Web and Rect environments. + * + * @param [transport] - API which should be used to make network requests. + * @param [keepAlive] - Whether client should try to keep connections open for reuse or not. + * @param logVerbosity - Whether verbose logs should be printed or not. + * + * @internal + */ + constructor( + private readonly transport: 'fetch' | 'xhr' = 'fetch', + private keepAlive: boolean = false, + private readonly logVerbosity: boolean = false, + ) { + if (transport === 'fetch' && (!window || !window.fetch)) this.transport = 'xhr'; + if (this.transport !== 'fetch') return; + + // Keeping reference on current `window.fetch` function. + WebTransport.originalFetch = fetch.bind(window); + + // Check whether `fetch` has been monkey patched or not. + if (logVerbosity && this.isFetchMonkeyPatched()) { + console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); + WebTransport.originalFetch = WebTransport.getOriginalFetch(); + + if (!this.isFetchMonkeyPatched(WebTransport.originalFetch)) + console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); + else + console.warn( + '[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation', + ); + } + } + + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { + const abortController = new AbortController(); + const cancellation: WebCancellationController = { + abortController, + abort: () => !abortController.signal.aborted && abortController.abort(), + }; + + return [ + this.webTransportRequestFromTransportRequest(req).then((request) => { + const start = new Date().getTime(); + + this.logRequestProcessProgress(request, req.body); + + return this.sendRequest(request, cancellation) + .then((response): Promise<[Response, ArrayBuffer]> | [Response, ArrayBuffer] => + response.arrayBuffer().then((arrayBuffer) => [response, arrayBuffer]), + ) + .then((response) => { + const responseBody = response[1].byteLength > 0 ? response[1] : undefined; + const { status, headers: requestHeaders } = response[0]; + const headers: Record = {}; + + // Copy Headers object content into plain Record. + requestHeaders.forEach((value, key) => (headers[key] = value.toLowerCase())); + + const transportResponse: TransportResponse = { + status, + url: request.url, + headers, + body: responseBody, + }; + + if (status >= 400) throw PubNubAPIError.create(transportResponse); + + this.logRequestProcessProgress(request, undefined, new Date().getTime() - start, responseBody); + + return transportResponse; + }) + .catch((error) => { + throw PubNubAPIError.create(error); + }); + }), + cancellation, + ]; + } + + request(req: TransportRequest): TransportRequest { + return req; + } + + /** + * Send network request using preferred API. + * + * @param req - Transport API agnostic request object with prepared body and URL. + * @param controller - Request cancellation controller (for long-poll requests). + * + * @returns Promise which will be resolved or rejected at the end of network request processing. + * + * @internal + */ + private async sendRequest(req: WebTransportRequest, controller: WebCancellationController): Promise { + if (this.transport === 'fetch') return this.sendFetchRequest(req, controller); + return this.sendXHRRequest(req, controller); + } + + /** + * Send network request using legacy XMLHttpRequest API. + * + * @param req - Transport API agnostic request object with prepared body and URL. + * @param controller - Request cancellation controller (for long-poll requests). + * + * @returns Promise which will be resolved or rejected at the end of network request processing. + * + * @internal + */ + private async sendFetchRequest(req: WebTransportRequest, controller: WebCancellationController): Promise { + let timeoutId: ReturnType | undefined; + + const requestTimeout = new Promise((_, reject) => { + timeoutId = setTimeout(() => { + clearTimeout(timeoutId); + + reject(new Error('Request timeout')); + controller.abort(); + }, req.timeout * 1000); + }); + + const request = new Request(req.url, { + method: req.method, + headers: req.headers, + redirect: 'follow', + body: req.body, + }); + + return Promise.race([ + WebTransport.originalFetch(request, { + signal: controller.abortController.signal, + credentials: 'omit', + cache: 'no-cache', + }).then((response) => { + if (timeoutId) clearTimeout(timeoutId); + return response; + }), + requestTimeout, + ]); + } + + /** + * Send network request using legacy XMLHttpRequest API. + * + * @param req - Transport API agnostic request object with prepared body and URL. + * @param controller - Request cancellation controller (for long-poll requests). + * + * @returns Promise which will be resolved or rejected at the end of network request processing. + * + * @internal + */ + private async sendXHRRequest(req: WebTransportRequest, controller: WebCancellationController): Promise { + return new Promise((resolve, reject) => { + const xhr = new XMLHttpRequest(); + xhr.open(req.method, req.url, true); + + // Setup request + xhr.responseType = 'arraybuffer'; + xhr.timeout = req.timeout * 1000; + + controller.abortController.signal.onabort = () => { + if (xhr.readyState == XMLHttpRequest.DONE || xhr.readyState == XMLHttpRequest.UNSENT) return; + xhr.abort(); + }; + + Object.entries(req.headers ?? {}).forEach(([key, value]) => xhr.setRequestHeader(key, value)); + + // Setup handlers to match `fetch` results handling. + xhr.onabort = () => reject(new Error('Aborted')); + xhr.ontimeout = () => reject(new Error('Request timeout')); + xhr.onerror = () => reject(new Error('Request timeout')); + + xhr.onload = () => { + const headers = new Headers(); + xhr + .getAllResponseHeaders() + .split('\r\n') + .forEach((header) => { + const [key, value] = header.split(': '); + if (key.length > 1 && value.length > 1) headers.append(key, value); + }); + + resolve(new Response(xhr.response, { status: xhr.status, headers, statusText: xhr.statusText })); + }; + + xhr.send(req.body); + }); + } + + /** + * Creates a Web Request object from a given {@link TransportRequest} object. + * + * @param req - The {@link TransportRequest} object containing request information. + * + * @returns Request object generated from the {@link TransportRequest} object. + * + * @internal + */ + private async webTransportRequestFromTransportRequest(req: TransportRequest): Promise { + let body: string | ArrayBuffer | FormData | undefined; + let path = req.path; + + // Create multipart request body. + if (req.formData && req.formData.length > 0) { + // Reset query parameters to conform to signed URL + req.queryParameters = {}; + + const file = req.body as PubNubFileInterface; + const formData = new FormData(); + for (const { key, value } of req.formData) formData.append(key, value); + try { + const fileData = await file.toArrayBuffer(); + formData.append('file', new Blob([fileData], { type: 'application/octet-stream' }), file.name); + } catch (_) { + try { + const fileData = await file.toFileUri(); + // @ts-expect-error React Native File Uri support. + formData.append('file', fileData, file.name); + } catch (_) {} + } + + body = formData; + } + // Handle regular body payload (if passed). + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) body = req.body; + + if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) + path = `${path}?${queryStringFromObject(req.queryParameters)}`; + + return { + url: `${req.origin!}${path}`, + method: req.method, + headers: req.headers, + timeout: req.timeout, + body, + }; + } + + /** + * Log out request processing progress and result. + * + * @param request - Platform-specific + * @param [requestBody] - POST / PATCH body. + * @param [elapsed] - How many seconds passed since request processing started. + * @param [body] - Service response (if available). + * + * @internal + */ + protected logRequestProcessProgress( + request: WebTransportRequest, + requestBody: TransportRequest['body'], + elapsed?: number, + body?: ArrayBuffer, + ) { + if (!this.logVerbosity) return; + + const { protocol, host, pathname, search } = new URL(request.url); + const timestamp = new Date().toISOString(); + + if (!elapsed) { + let outgoing = `[${timestamp}]\n${protocol}//${host}${pathname}\n${search}`; + if (requestBody && (typeof requestBody === 'string' || requestBody instanceof ArrayBuffer)) { + if (typeof requestBody === 'string') outgoing += `\n\n${requestBody}`; + else outgoing += `\n\n${WebTransport.decoder.decode(requestBody)}`; + } + + console.log(`<<<<<`); + console.log(outgoing); + console.log('-----'); + } else { + let outgoing = `[${timestamp} / ${elapsed}]\n${protocol}//${host}${pathname}\n${search}`; + if (body) outgoing += `\n\n${WebTransport.decoder.decode(body)}`; + + console.log('>>>>>>'); + console.log(outgoing); + console.log('-----'); + } + } + + /** + * Check whether original `fetch` has been monkey patched or not. + * + * @returns `true` if original `fetch` has been patched. + */ + private isFetchMonkeyPatched(oFetch?: typeof fetch): boolean { + const fetchString = (oFetch ?? fetch).toString(); + + return !fetchString.includes('[native code]') && fetch.name !== 'fetch'; + } + + /** + * Retrieve original `fetch` implementation. + * + * Retrieve implementation which hasn't been patched by APM tools. + * + * @returns Reference to the `fetch` function. + */ + private static getOriginalFetch(): typeof fetch { + let iframe = document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]'); + + if (!iframe) { + iframe = document.createElement('iframe'); + iframe.style.display = 'none'; + iframe.name = 'pubnub-context-unpatched-fetch'; + iframe.src = 'about:blank'; + document.body.appendChild(iframe); + } + + if (iframe.contentWindow) return iframe.contentWindow.fetch.bind(iframe.contentWindow); + return fetch; + } +} diff --git a/src/web/components/configuration.ts b/src/web/components/configuration.ts index 4f0709836..e9ae3363f 100644 --- a/src/web/components/configuration.ts +++ b/src/web/components/configuration.ts @@ -23,6 +23,11 @@ const LISTEN_TO_BROWSER_NETWORK_EVENTS = true; */ const SUBSCRIPTION_WORKER_LOG_VERBOSITY = false; +/** + * Use modern Web Fetch API for network requests by default. + */ +const TRANSPORT: PubNubConfiguration['transport'] = 'fetch'; + /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -60,6 +65,15 @@ export type PubNubConfiguration = UserConfiguration & { */ subscriptionWorkerLogVerbosity?: boolean; + /** + * API which should be used to make network requests. + * + * **Important:** `Shared Worker` always use `fetch` API. + * + * @default `fetch` + */ + transport?: 'fetch' | 'xhr'; + /** * If set to `true`, SDK will use the same TCP connection for each HTTP request, instead of * opening a new one for each new request. @@ -118,6 +132,7 @@ export const setDefaults = (configuration: PubNubConfiguration): PubNubConfigura listenToBrowserNetworkEvents: configuration.listenToBrowserNetworkEvents ?? LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, subscriptionWorkerLogVerbosity: configuration.subscriptionWorkerLogVerbosity ?? SUBSCRIPTION_WORKER_LOG_VERBOSITY, + transport: configuration.transport ?? TRANSPORT, keepAlive: configuration.keepAlive ?? KEEP_ALIVE, }; }; diff --git a/src/web/index.ts b/src/web/index.ts index 638f3bb51..f24ffb924 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -9,7 +9,6 @@ import type { WebCryptoModule as CryptoModuleType } from '../crypto/modules/WebC import { SubscriptionWorkerMiddleware } from '../transport/subscription-worker/subscription-worker-middleware'; import { ExtendedConfiguration, PlatformConfiguration } from '../core/interfaces/configuration'; -import { WebReactNativeTransport } from '../transport/web-react-native-transport'; import { stringifyBufferKeys } from '../core/components/stringify_buffer_keys'; import { PubNubConfiguration, setDefaults } from './components/configuration'; import { CryptorConfiguration } from '../core/interfaces/crypto-module'; @@ -18,6 +17,7 @@ import { makeConfiguration } from '../core/components/configuration'; import { TokenManager } from '../core/components/token_manager'; import { Cryptography } from '../core/interfaces/cryptography'; import { PubNubMiddleware } from '../transport/middleware'; +import { WebTransport } from '../transport/web-transport'; import { decode } from '../core/components/base64_codec'; import { Transport } from '../core/interfaces/transport'; import Crypto from '../core/components/cryptography'; @@ -92,8 +92,8 @@ export default class PubNub extends PubNubCore('iframe[name="pubnub-context-unpatched-fetch"]'); - - if (!iframe) { - iframe = document.createElement('iframe'); - iframe.style.display = 'none'; - iframe.name = 'pubnub-context-unpatched-fetch'; - iframe.src = 'about:blank'; - document.body.appendChild(iframe); - } - - if (iframe.contentWindow) return iframe.contentWindow.fetch.bind(iframe.contentWindow); - return fetch; - } } diff --git a/tsconfig.json b/tsconfig.json index a8cf9e0c7..463c69f39 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -24,8 +24,9 @@ "src/file/modules/web.ts", "src/transport/subscription-worker/**/*", "src/transport/titanium-transport.ts", + "src/transport/web-transport.ts", "src/nativescript/**/*", "src/titanium/**/*", "src/web/**/*" ] -} \ No newline at end of file +} diff --git a/tsconfig.rollup.json b/tsconfig.rollup.json index e317fb87b..6858ce22c 100644 --- a/tsconfig.rollup.json +++ b/tsconfig.rollup.json @@ -25,6 +25,7 @@ "src/nativescript/**/*", "src/titanium/**/*", "src/transport/node-transport.ts", - "src/transport/titanium-transport.ts" + "src/transport/titanium-transport.ts", + "src/transport/react-native-transport.ts" ] } From 2a0535caefc8821aa797ce6196335ee1dc942dc1 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Mon, 10 Feb 2025 12:18:25 +0200 Subject: [PATCH 36/49] Fix issue with misplaced condition (#436) fix(web-transport): fix issue with misplaced condition Fix issue because of which APM fix worked only when the client has been configured with `logVerbosity: true`. --- .pubnub.yml | 11 ++++++++--- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- dist/web/pubnub.js | 8 +++++--- dist/web/pubnub.min.js | 2 +- lib/core/components/configuration.js | 2 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/transport/web-transport.ts | 7 +++++-- 9 files changed, 30 insertions(+), 14 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 6e3d617c6..ee947b1e8 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2025-02-10 + version: v8.8.1 + changes: + - type: bug + text: "Fix issue because of which APM fix worked only when the client has been configured with `logVerbosity: true`." - date: 2025-02-05 version: v8.8.0 changes: @@ -1132,7 +1137,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.8.0' +version: '8.8.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1148,7 +1153,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.8.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.8.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1819,7 +1824,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.8.0/pubnub.8.8.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.8.1/pubnub.8.8.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index b258f85da..7fcecbabf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v8.8.1 +February 10 2025 + +#### Fixed +- Fix issue because of which APM fix worked only when the client has been configured with `logVerbosity: true`. + ## v8.8.0 February 05 2025 diff --git a/README.md b/README.md index dfd7f7b13..d998aaa07 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.8.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.8.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.8.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.8.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 7ad0bbbec..3db1a262a 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3732,7 +3732,7 @@ return base.PubNubFile; }, get version() { - return '8.8.0'; + return '8.8.1'; }, getVersion() { return this.version; @@ -4202,9 +4202,11 @@ // Keeping reference on current `window.fetch` function. WebTransport.originalFetch = fetch.bind(window); // Check whether `fetch` has been monkey patched or not. - if (logVerbosity && this.isFetchMonkeyPatched()) { - console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); + if (this.isFetchMonkeyPatched()) { WebTransport.originalFetch = WebTransport.getOriginalFetch(); + if (!logVerbosity) + return; + console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); if (!this.isFetchMonkeyPatched(WebTransport.originalFetch)) console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); else diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 2735878d0..9c4f63683 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}function j(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?j(a):a})),n}const I=e=>{var t,s,n,r;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,transport:null!==(n=e.transport)&&void 0!==n?n:"fetch",keepAlive:null===(r=e.keepAlive)||void 0===r||r})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var F=t(R.exports),T={createUUID:()=>F.uuid?F.uuid():F()};const U=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=x(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${T.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.8.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},x=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class D{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var q;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(q||(q={}));const G=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),K=(e,t)=>{const s=e.map((e=>G(e)));return s.length?s.join(","):null!=t?t:""},$=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},L=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class B{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?q.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===q.POST||t===q.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=B.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${G(e)}`)).join("&"):`${t}=${G(s)}`})).join("&")}}B.textDecoder=new TextDecoder("utf-8");class H{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new B(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class z{constructor(e="fetch",t=!1,s=!1){this.transport=e,this.keepAlive=t,this.logVerbosity=s,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),s&&this.isFetchMonkeyPatched()&&(console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),z.originalFetch=z.getOriginalFetch(),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")))}makeSendable(e){const t=new AbortController,s={abortController:t,abort:()=>!t.signal.aborted&&t.abort()};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,s).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),s]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let s;const n=new Promise(((n,r)=>{s=setTimeout((()=>{clearTimeout(s),r(new Error("Request timeout")),t.abort()}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(s&&clearTimeout(s),e))),n])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((s,n)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>n(new Error("Aborted")),i.ontimeout=()=>n(new Error("Request timeout")),i.onerror=()=>n(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[s,n]=t.split(": ");s.length>1&&n.length>1&&e.append(s,n)})),s(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${G(t)}`)).join("&"):`${e}=${G(t)}`})).join("&")}`),{url:`${e.origin}${s}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${z.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class V{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class W{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class J{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Q{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Y extends Q{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class Z extends Q{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class ee{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Y(this._payload.apns,e,t),this.fcm=new Z(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class te{constructor(e){this.params=e,this.requestIdentifier=T.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:q.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===q.POST||r.method===q.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=te.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var se;te.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(se||(se={}));var ne=se;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends te{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=te.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${K(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Fe extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Ue=new ue("HEARTBEAT_COOLDOWN");Ue.onEnter((()=>Ie())),Ue.onExit((()=>Ie.cancel)),Ue.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Ue.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Xe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Qe=de("HANDSHAKE_SUCCESS",(e=>e)),Ye=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Qe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ye(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Xe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Xe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Xe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Xe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Xe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Xe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Ye.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Xe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=$(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=$(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=L(this.channels,e),i=L(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends te{constructor(e){var t,s;super({method:e.sendByPost?q.POST:q.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${G(t)}/0${this.parameters.sendByPost?"":`/${G(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${G(s)}/0/${G(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${K(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${K(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends te{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=s?s:[],",")}/uuid/${G(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends te{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${K(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${G(t)}`}}class At extends te{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${K(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${G(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${K(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends te{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${G(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class Tt extends te{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ut extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends te{constructor(e){super({method:q.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}/message/${n}/action/${s}`}}class qt extends te{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${G(t)}/0/${G(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends te{constructor(e){super({method:q.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${G(e)}/files/${t}/${s}`}}class Kt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${G(s)}/files/${t}/${n}`}}class $t extends te{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends te{constructor(e){super({method:q.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends te{constructor(e){super({method:q.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}}class ss extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}/remove`}}class ns extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends te{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends te{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}}class ps extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends te{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends te{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends te{constructor(e){var t,s,n;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends te{constructor(e){super({method:q.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}}class vs extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends te{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends te{constructor(e){var t,s,n;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends te{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new ee(e,t)}static generateUUID(){return T.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new V,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new X(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Yt(e,this.eventEmitter,this)}channelGroup(e){return new Xt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Qt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request(),r=e.operation();n.formData&&n.formData.length>0||r===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():r===ne.PNSubscribeOperation||r===ne.PNReceiveMessagesOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[o,a]=this.transport.makeSendable(n);return e.cancellationController=a||null,o.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(i.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const s=e instanceof _?e:_.create(e);if(t)return t(s.toStatus(r),null);throw s.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${G(t)}`)).join("&"):`${e}=${G(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=I(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=U(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new D(new Ps((e=>j(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new z(r.transport,i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new H({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var F=t(R.exports),T={createUUID:()=>F.uuid?F.uuid():F()};const U=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=x(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${T.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.8.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},x=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class D{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var q;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(q||(q={}));const G=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),K=(e,t)=>{const s=e.map((e=>G(e)));return s.length?s.join(","):null!=t?t:""},$=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},L=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class B{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?q.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===q.POST||t===q.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=B.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${G(e)}`)).join("&"):`${t}=${G(s)}`})).join("&")}}B.textDecoder=new TextDecoder("utf-8");class H{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new B(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class z{constructor(e="fetch",t=!1,s=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=s,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!s)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,s={abortController:t,abort:()=>!t.signal.aborted&&t.abort()};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,s).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),s]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let s;const n=new Promise(((n,r)=>{s=setTimeout((()=>{clearTimeout(s),r(new Error("Request timeout")),t.abort()}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(s&&clearTimeout(s),e))),n])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((s,n)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>n(new Error("Aborted")),i.ontimeout=()=>n(new Error("Request timeout")),i.onerror=()=>n(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[s,n]=t.split(": ");s.length>1&&n.length>1&&e.append(s,n)})),s(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${G(t)}`)).join("&"):`${e}=${G(t)}`})).join("&")}`),{url:`${e.origin}${s}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${z.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class V{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class W{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class J{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Q{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Y extends Q{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class Z extends Q{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class ee{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Y(this._payload.apns,e,t),this.fcm=new Z(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class te{constructor(e){this.params=e,this.requestIdentifier=T.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:q.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===q.POST||r.method===q.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=te.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var se;te.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(se||(se={}));var ne=se;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends te{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=te.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${K(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Fe extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Ue=new ue("HEARTBEAT_COOLDOWN");Ue.onEnter((()=>Ie())),Ue.onExit((()=>Ie.cancel)),Ue.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Ue.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Xe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Qe=de("HANDSHAKE_SUCCESS",(e=>e)),Ye=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Qe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ye(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Xe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Xe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Xe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Xe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Xe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Xe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Ye.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Xe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=$(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=$(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=L(this.channels,e),i=L(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends te{constructor(e){var t,s;super({method:e.sendByPost?q.POST:q.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${G(t)}/0${this.parameters.sendByPost?"":`/${G(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${G(s)}/0/${G(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${K(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${K(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends te{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=s?s:[],",")}/uuid/${G(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends te{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${K(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${G(t)}`}}class At extends te{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${K(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${G(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${K(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends te{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${G(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class Tt extends te{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ut extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends te{constructor(e){super({method:q.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}/message/${n}/action/${s}`}}class qt extends te{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${G(t)}/0/${G(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends te{constructor(e){super({method:q.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${G(e)}/files/${t}/${s}`}}class Kt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${G(s)}/files/${t}/${n}`}}class $t extends te{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends te{constructor(e){super({method:q.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends te{constructor(e){super({method:q.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}}class ss extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}/remove`}}class ns extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends te{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends te{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}}class ps extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends te{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends te{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends te{constructor(e){var t,s,n;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends te{constructor(e){super({method:q.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}}class vs extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends te{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends te{constructor(e){var t,s,n;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends te{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new ee(e,t)}static generateUUID(){return T.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new V,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new X(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Yt(e,this.eventEmitter,this)}channelGroup(e){return new Xt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Qt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request(),r=e.operation();n.formData&&n.formData.length>0||r===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():r===ne.PNSubscribeOperation||r===ne.PNReceiveMessagesOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[o,a]=this.transport.makeSendable(n);return e.cancellationController=a||null,o.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(i.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const s=e instanceof _?e:_.create(e);if(t)return t(s.toStatus(r),null);throw s.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${G(t)}`)).join("&"):`${e}=${G(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=I(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=U(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new D(new Ps((e=>j(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new z(r.transport,i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new H({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 48be7b42c..7a695af9e 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.8.0'; + return '8.8.1'; }, getVersion() { return this.version; diff --git a/package.json b/package.json index 3e61d294b..504b4d8ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.8.0", + "version": "8.8.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 6261013f0..e53d26192 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.8.0'; + return '8.8.1'; }, getVersion(): string { return this.version; diff --git a/src/transport/web-transport.ts b/src/transport/web-transport.ts index 1dc75e49e..1fac8c14f 100644 --- a/src/transport/web-transport.ts +++ b/src/transport/web-transport.ts @@ -96,10 +96,13 @@ export class WebTransport implements Transport { WebTransport.originalFetch = fetch.bind(window); // Check whether `fetch` has been monkey patched or not. - if (logVerbosity && this.isFetchMonkeyPatched()) { - console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); + if (this.isFetchMonkeyPatched()) { WebTransport.originalFetch = WebTransport.getOriginalFetch(); + if (!logVerbosity) return; + + console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."); + if (!this.isFetchMonkeyPatched(WebTransport.originalFetch)) console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround."); else From bd69c80cc1af7e77ea47bd8432acd32789ed1e18 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 18 Feb 2025 16:06:00 +0200 Subject: [PATCH 37/49] Emit `PNDisconnectedUnexpectedlyCategory` (#438) feat(subscribe): emit `PNDisconnectedUnexpectedlyCategory` Emit 'PNDisconnectedUnexpectedlyCategory' in cases when client receives bad request or unexpected / malformed service response. refactor(request): move deserialized error parse into abstract request Move error / malformed response handling into `AbstractRequest` to simplify actual endpoint classes. --- .pubnub.yml | 13 +- CHANGELOG.md | 9 + README.md | 4 +- dist/web/pubnub.js | 502 ++++++------------ dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 18 +- dist/web/pubnub.worker.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/core/components/request.js | 33 +- lib/core/components/subscription-manager.js | 19 +- lib/core/constants/categories.js | 8 + lib/core/endpoints/access_manager/audit.js | 10 +- lib/core/endpoints/access_manager/grant.js | 10 +- .../endpoints/access_manager/grant_token.js | 10 +- .../endpoints/access_manager/revoke_token.js | 13 +- .../endpoints/actions/add_message_action.js | 13 +- .../endpoints/actions/get_message_actions.js | 7 - .../actions/remove_message_action.js | 13 +- .../endpoints/channel_groups/add_channels.js | 13 +- .../endpoints/channel_groups/delete_group.js | 13 +- .../endpoints/channel_groups/list_channels.js | 10 +- .../endpoints/channel_groups/list_groups.js | 10 +- .../channel_groups/remove_channels.js | 13 +- lib/core/endpoints/fetch_messages.js | 7 - lib/core/endpoints/file_upload/delete_file.js | 22 - .../file_upload/generate_upload_url.js | 7 - lib/core/endpoints/file_upload/list_files.js | 22 - .../endpoints/file_upload/publish_file.js | 6 +- lib/core/endpoints/file_upload/send_file.js | 4 +- lib/core/endpoints/history/delete_messages.js | 13 +- lib/core/endpoints/history/get_history.js | 3 - lib/core/endpoints/history/message_counts.js | 10 +- lib/core/endpoints/objects/channel/get.js | 22 - lib/core/endpoints/objects/channel/get_all.js | 22 - lib/core/endpoints/objects/channel/remove.js | 22 - lib/core/endpoints/objects/channel/set.js | 22 - lib/core/endpoints/objects/member/get.js | 22 - lib/core/endpoints/objects/member/set.js | 22 - lib/core/endpoints/objects/membership/get.js | 22 - lib/core/endpoints/objects/membership/set.js | 22 - lib/core/endpoints/objects/uuid/get.js | 22 - lib/core/endpoints/objects/uuid/get_all.js | 22 - lib/core/endpoints/objects/uuid/remove.js | 22 - lib/core/endpoints/objects/uuid/set.js | 22 - lib/core/endpoints/presence/get_state.js | 7 - lib/core/endpoints/presence/heartbeat.js | 13 +- lib/core/endpoints/presence/here_now.js | 7 - lib/core/endpoints/presence/leave.js | 13 +- lib/core/endpoints/presence/set_state.js | 10 +- lib/core/endpoints/presence/where_now.js | 7 - lib/core/endpoints/publish.js | 8 +- lib/core/endpoints/push/add_push_channels.js | 9 +- lib/core/endpoints/push/list_push_channels.js | 6 +- lib/core/endpoints/push/push.js | 14 - lib/core/endpoints/push/remove_device.js | 9 +- .../endpoints/push/remove_push_channels.js | 9 +- lib/core/endpoints/signal.js | 6 +- lib/core/endpoints/subscribe.js | 7 +- lib/core/endpoints/time.js | 6 +- lib/core/pubnub-common.js | 15 +- lib/errors/pubnub-api-error.js | 35 +- lib/errors/pubnub-error.js | 17 +- lib/transport/node-transport.js | 16 +- lib/transport/react-native-transport.js | 16 +- lib/types/index.d.ts | 10 +- package-lock.json | 4 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/components/request.ts | 48 +- src/core/components/subscription-manager.ts | 23 +- src/core/constants/categories.ts | 9 + src/core/endpoints/access_manager/audit.ts | 15 +- src/core/endpoints/access_manager/grant.ts | 15 +- .../endpoints/access_manager/grant_token.ts | 15 +- .../endpoints/access_manager/revoke_token.ts | 15 +- .../endpoints/actions/add_message_action.ts | 15 +- .../endpoints/actions/get_message_actions.ts | 17 +- .../actions/remove_message_action.ts | 15 +- .../endpoints/channel_groups/add_channels.ts | 18 +- .../endpoints/channel_groups/delete_group.ts | 20 +- .../endpoints/channel_groups/list_channels.ts | 18 +- .../endpoints/channel_groups/list_groups.ts | 18 +- .../channel_groups/remove_channels.ts | 16 +- src/core/endpoints/fetch_messages.ts | 14 +- src/core/endpoints/file_upload/delete_file.ts | 18 +- .../endpoints/file_upload/download_file.ts | 2 +- .../file_upload/generate_upload_url.ts | 16 +- .../endpoints/file_upload/get_file_url.ts | 2 +- src/core/endpoints/file_upload/list_files.ts | 18 +- .../endpoints/file_upload/publish_file.ts | 16 +- src/core/endpoints/file_upload/send_file.ts | 6 +- src/core/endpoints/file_upload/upload-file.ts | 4 +- src/core/endpoints/history/delete_messages.ts | 15 +- src/core/endpoints/history/get_history.ts | 12 +- src/core/endpoints/history/message_counts.ts | 15 +- src/core/endpoints/objects/channel/get.ts | 18 +- src/core/endpoints/objects/channel/get_all.ts | 18 +- src/core/endpoints/objects/channel/remove.ts | 18 +- src/core/endpoints/objects/channel/set.ts | 18 +- src/core/endpoints/objects/member/get.ts | 18 +- src/core/endpoints/objects/member/set.ts | 18 +- src/core/endpoints/objects/membership/get.ts | 18 +- src/core/endpoints/objects/membership/set.ts | 18 +- src/core/endpoints/objects/uuid/get.ts | 18 +- src/core/endpoints/objects/uuid/get_all.ts | 18 +- src/core/endpoints/objects/uuid/remove.ts | 23 +- src/core/endpoints/objects/uuid/set.ts | 18 +- src/core/endpoints/presence/get_state.ts | 14 +- src/core/endpoints/presence/heartbeat.ts | 15 +- src/core/endpoints/presence/here_now.ts | 14 +- src/core/endpoints/presence/leave.ts | 15 +- src/core/endpoints/presence/set_state.ts | 15 +- src/core/endpoints/presence/where_now.ts | 14 +- src/core/endpoints/publish.ts | 14 +- src/core/endpoints/push/add_push_channels.ts | 14 +- src/core/endpoints/push/list_push_channels.ts | 14 +- src/core/endpoints/push/push.ts | 7 +- src/core/endpoints/push/remove_device.ts | 14 +- .../endpoints/push/remove_push_channels.ts | 14 +- src/core/endpoints/signal.ts | 13 +- src/core/endpoints/subscribe.ts | 11 +- src/core/endpoints/time.ts | 13 +- src/core/pubnub-channel-groups.ts | 4 +- src/core/pubnub-common.ts | 32 +- src/core/pubnub-objects.ts | 4 +- src/core/pubnub-push.ts | 4 +- src/core/types/api/index.ts | 4 +- src/core/types/transport-request.ts | 2 +- src/errors/pubnub-api-error.ts | 35 +- src/errors/pubnub-error.ts | 33 +- src/transport/node-transport.ts | 17 +- src/transport/react-native-transport.ts | 17 +- .../subscription-worker.ts | 17 +- src/transport/web-transport.ts | 14 +- test/dist/web-titanium.test.js | 12 +- 135 files changed, 691 insertions(+), 1698 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index ee947b1e8..4345ec7b6 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2025-02-18 + version: v8.9.0 + changes: + - type: feature + text: "Emit 'PNDisconnectedUnexpectedlyCategory' in cases when client receives bad request or unexpected / malformed service response." + - type: improvement + text: "Move error / malformed response handling into `AbstractRequest` to simplify actual endpoint classes." - date: 2025-02-10 version: v8.8.1 changes: @@ -1137,7 +1144,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.8.1' +version: '8.9.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1153,7 +1160,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.8.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.9.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1824,7 +1831,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.8.1/pubnub.8.8.1.js + location: https://github.com/pubnub/javascript/releases/download/v8.9.0/pubnub.8.9.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fcecbabf..57065e5b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v8.9.0 +February 18 2025 + +#### Added +- Emit 'PNDisconnectedUnexpectedlyCategory' in cases when client receives bad request or unexpected / malformed service response. + +#### Modified +- Move error / malformed response handling into `AbstractRequest` to simplify actual endpoint classes. + ## v8.8.1 February 10 2025 diff --git a/README.md b/README.md index d998aaa07..5c6f82a1f 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.8.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.8.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 3db1a262a..e9957c248 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -835,6 +835,14 @@ * Some API endpoints respond with request processing status w/o useful data. */ StatusCategory["PNAcknowledgmentCategory"] = "PNAcknowledgmentCategory"; + /** + * PubNub service or intermediate "actor" returned unexpected response. + * + * There can be few sources of unexpected return with success code: + * - proxy server / VPN; + * - Wi-Fi hotspot authorization page. + */ + StatusCategory["PNMalformedResponseCategory"] = "PNMalformedResponseCategory"; /** * Something strange happened; please check the logs. */ @@ -914,15 +922,16 @@ * Create error status object. * * @param errorPayload - Additional information which should be attached to the error status object. + * @param category - Occurred error category. * * @returns Error status object. * * @internal */ - function createError(errorPayload) { + function createError(errorPayload, category) { var _a; (_a = errorPayload.statusCode) !== null && _a !== void 0 ? _a : (errorPayload.statusCode = 0); - return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: StatusCategory$1.PNValidationErrorCategory, error: true }); + return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category, error: true }); } /** * Create operation arguments validation error status object. @@ -935,7 +944,16 @@ * @internal */ function createValidationError(message, statusCode) { - return createError(Object.assign({ message }, ({}))); + return createError(Object.assign({ message }, ({})), StatusCategory$1.PNValidationErrorCategory); + } + /** + * Create malformed service response error status object. + * + * @param [responseText] - Stringified original service response. + * @param [statusCode] - Operation HTTP status code. + */ + function createMalformedResponseError(responseText, statusCode) { + return createError(Object.assign(Object.assign({ message: 'Unable to deserialize service response' }, (responseText !== undefined ? { responseText } : {})), (statusCode !== undefined ? { statusCode } : {})), StatusCategory$1.PNMalformedResponseCategory); } /** @@ -2979,20 +2997,29 @@ response.headers['content-type'].indexOf('application/json') !== -1) { try { const errorResponse = JSON.parse(decoded); - if (typeof errorResponse === 'object' && !Array.isArray(errorResponse)) { - if ('error' in errorResponse && - (errorResponse.error === 1 || errorResponse.error === true) && - 'status' in errorResponse && - typeof errorResponse.status === 'number' && - 'message' in errorResponse && - 'service' in errorResponse) { - errorData = errorResponse; - status = errorResponse.status; + if (typeof errorResponse === 'object') { + if (!Array.isArray(errorResponse)) { + if ('error' in errorResponse && + (errorResponse.error === 1 || errorResponse.error === true) && + 'status' in errorResponse && + typeof errorResponse.status === 'number' && + 'message' in errorResponse && + 'service' in errorResponse) { + errorData = errorResponse; + status = errorResponse.status; + } + else + errorData = errorResponse; + if ('error' in errorResponse && errorResponse.error instanceof Error) + errorData = errorResponse.error; + } + else { + // Handling Publish API payload error. + if (typeof errorResponse[0] === 'number' && errorResponse[0] === 0) { + if (errorResponse.length > 1 && typeof errorResponse[1] === 'string') + errorData = errorResponse[1]; + } } - else - errorData = errorResponse; - if ('error' in errorResponse && errorResponse.error instanceof Error) - errorData = errorResponse.error; } } catch (_) { @@ -3732,7 +3759,7 @@ return base.PubNubFile; }, get version() { - return '8.8.1'; + return '8.9.0'; }, getVersion() { return this.version; @@ -4217,7 +4244,7 @@ const abortController = new AbortController(); const cancellation = { abortController, - abort: () => !abortController.signal.aborted && abortController.abort(), + abort: (reason) => !abortController.signal.aborted && abortController.abort(reason), }; return [ this.webTransportRequestFromTransportRequest(req).then((request) => { @@ -4243,7 +4270,15 @@ return transportResponse; }) .catch((error) => { - throw PubNubAPIError.create(error); + let fetchError = error; + if (typeof error === 'string') { + const errorMessage = error.toLowerCase(); + if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) + fetchError = new Error(error); + else if (errorMessage.includes('cancel')) + fetchError = new DOMException('Aborted', 'AbortError'); + } + throw PubNubAPIError.create(fetchError); }); }), cancellation, @@ -4286,7 +4321,7 @@ timeoutId = setTimeout(() => { clearTimeout(timeoutId); reject(new Error('Request timeout')); - controller.abort(); + controller.abort('Cancel because of timeout'); }, req.timeout * 1000); }); const request = new Request(req.url, { @@ -5025,13 +5060,15 @@ this.reconnectionManager.startPolling(); this.listenerManager.announceStatus(status); } - else if (status.category === StatusCategory$1.PNBadRequestCategory) { - this.stopHeartbeatTimer(); - this.listenerManager.announceStatus(status); + else if (status.category === StatusCategory$1.PNBadRequestCategory || + status.category == StatusCategory$1.PNMalformedResponseCategory) { + const category = this.isOnline ? StatusCategory$1.PNDisconnectedUnexpectedlyCategory : status.category; + this.isOnline = false; + this.disconnect(); + this.listenerManager.announceStatus(Object.assign(Object.assign({}, status), { category })); } - else { + else this.listenerManager.announceStatus(status); - } return; } if (this.storedTimetoken) { @@ -5828,10 +5865,12 @@ } /** * Abort request if possible. + * + * @param [reason] Information about why request has been cancelled. */ - abort() { + abort(reason) { if (this && this.cancellationController) - this.cancellationController.abort(); + this.cancellationController.abort(reason); } /** * Target REST API endpoint operation type. @@ -5850,11 +5889,11 @@ /** * Parse service response. * - * @param _response - Raw service response which should be parsed. + * @param response - Raw service response which should be parsed. */ - parse(_response) { + parse(response) { return __awaiter(this, void 0, void 0, function* () { - throw Error('Should be implemented by subclass.'); + return this.deserializeResponse(response); }); } /** @@ -5926,21 +5965,28 @@ * * @param response - Transparent response object with headers and body information. * - * @returns Deserialized data or `undefined` in case of `JSON.parse(..)` error. + * @returns Deserialized service response data. + * + * @throws {Error} if received service response can't be processed (has unexpected content-type or can't be parsed as + * JSON). */ deserializeResponse(response) { + const responseText = AbstractRequest.decoder.decode(response.body); const contentType = response.headers['content-type']; + let parsedJson; if (!contentType || (contentType.indexOf('javascript') === -1 && contentType.indexOf('json') === -1)) - return undefined; - const json = AbstractRequest.decoder.decode(response.body); + throw new PubNubError('Service response error, check status for details', createMalformedResponseError(responseText, response.status)); try { - const parsedJson = JSON.parse(json); - return parsedJson; + parsedJson = JSON.parse(responseText); } catch (error) { console.error('Error parsing JSON response:', error); - return undefined; + throw new PubNubError('Service response error, check status for details', createMalformedResponseError(responseText, response.status)); } + // Throw and exception in case of client / server error. + if ('status' in parsedJson && typeof parsedJson.status === 'number' && parsedJson.status >= 400) + throw PubNubAPIError.create(response); + return parsedJson; } } /** @@ -6282,16 +6328,17 @@ parse(response) { return __awaiter(this, void 0, void 0, function* () { let serviceResponse; + let responseText; try { - const json = AbstractRequest.decoder.decode(response.body); - const parsedJson = JSON.parse(json); + responseText = AbstractRequest.decoder.decode(response.body); + const parsedJson = JSON.parse(responseText); serviceResponse = parsedJson; } catch (error) { console.error('Error parsing JSON response:', error); } if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); + throw new PubNubError('Service response error, check status for details', createMalformedResponseError(responseText, response.status)); } const events = serviceResponse.m .filter((envelope) => { @@ -8474,10 +8521,7 @@ } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - return { timetoken: serviceResponse[2] }; + return { timetoken: this.deserializeResponse(response)[2] }; }); } get path() { @@ -8501,6 +8545,8 @@ return query; } get headers() { + if (!this.parameters.sendByPost) + return undefined; return { 'Content-Type': 'application/json' }; } get body() { @@ -8554,10 +8600,7 @@ } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - return { timetoken: serviceResponse[2] }; + return { timetoken: this.deserializeResponse(response)[2] }; }); } get path() { @@ -8685,11 +8728,6 @@ parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); const { channels = [], channelGroups = [] } = this.parameters; const state = { channels: {} }; if (channels.length === 1 && channelGroups.length === 0) @@ -8741,13 +8779,7 @@ } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return { state: serviceResponse.payload }; + return { state: this.deserializeResponse(response).payload }; }); } get path() { @@ -8790,14 +8822,11 @@ return 'Please provide a list of channels and/or channel-groups'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { @@ -8846,14 +8875,11 @@ return 'At least one `channel` or `channel group` should be provided.'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { @@ -8895,11 +8921,6 @@ parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); if (!serviceResponse.payload) return { channels: [] }; return { channels: serviceResponse.payload.channels }; @@ -8959,11 +8980,6 @@ return __awaiter(this, void 0, void 0, function* () { var _a, _b; const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); // Extract general presence information. const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; const totalOccupancy = 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_occupancy; @@ -9036,14 +9052,11 @@ return 'Missing channel'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { @@ -9090,13 +9103,7 @@ } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return { channels: serviceResponse.channels }; + return { channels: this.deserializeResponse(response).channels }; }); } get path() { @@ -9167,8 +9174,6 @@ parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); const messages = serviceResponse[0]; const startTimeToken = serviceResponse[1]; const endTimeToken = serviceResponse[2]; @@ -9329,11 +9334,6 @@ return __awaiter(this, void 0, void 0, function* () { var _a; const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); const responseChannels = (_a = serviceResponse.channels) !== null && _a !== void 0 ? _a : {}; const channels = {}; Object.keys(responseChannels).forEach((channel) => { @@ -9457,11 +9457,6 @@ parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); let start = null; let end = null; if (serviceResponse.data.length > 0) { @@ -9523,14 +9518,11 @@ return 'Action.type value exceed maximum length of 15'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return { data: serviceResponse.data }; + return _super.parse.call(this, response).then(({ data }) => ({ data })); }); } get path() { @@ -9576,14 +9568,11 @@ return 'Missing action timetoken'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return { data: serviceResponse.data }; + return _super.parse.call(this, response).then(({ data }) => ({ data })); }); } get path() { @@ -9634,10 +9623,7 @@ } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - return { timetoken: serviceResponse[2] }; + return { timetoken: this.deserializeResponse(response)[2] }; }); } get path() { @@ -9746,17 +9732,6 @@ if (!name) return "file name can't be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, id, channel, name, } = this.parameters; return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files/${id}/${name}`; @@ -9798,17 +9773,6 @@ if (!this.parameters.channel) return "channel can't be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/files`; @@ -9847,11 +9811,6 @@ parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); return { id: serviceResponse.data.id, name: serviceResponse.data.name, @@ -10602,14 +10561,11 @@ return 'Missing channels'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { @@ -10650,14 +10606,11 @@ return 'Missing channels'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { @@ -10696,13 +10649,7 @@ } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return { channels: serviceResponse.payload.channels }; + return { channels: this.deserializeResponse(response).payload.channels }; }); } get path() { @@ -10737,14 +10684,11 @@ return 'Missing Channel Group'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { @@ -10778,13 +10722,7 @@ } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return { groups: serviceResponse.payload.groups }; + return { groups: this.deserializeResponse(response).payload.groups }; }); } get path() { @@ -10951,11 +10889,6 @@ if (this.parameters.pushGateway === 'apns2' && !this.parameters.topic) return 'Missing APNS2 topic'; } - parse(_response) { - return __awaiter(this, void 0, void 0, function* () { - throw Error('Should be implemented in subclass.'); - }); - } get path() { const { keySet: { subscribeKey }, action, device, pushGateway, } = this.parameters; let path = pushGateway === 'apns2' @@ -10998,11 +10931,11 @@ return RequestOperation$1.PNRemovePushNotificationEnabledChannelsOperation; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } } @@ -11028,10 +10961,7 @@ } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - return { channels: serviceResponse }; + return { channels: this.deserializeResponse(response) }; }); } } @@ -11056,11 +10986,11 @@ return RequestOperation$1.PNAddPushNotificationEnabledChannelsOperation; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } } @@ -11085,11 +11015,11 @@ return RequestOperation$1.PNRemoveAllPushNotificationsOperation; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } } @@ -11217,17 +11147,6 @@ operation() { return RequestOperation$1.PNGetAllChannelMetadataOperation; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { return `/v2/objects/${this.parameters.keySet.subscribeKey}/channels`; } @@ -11265,17 +11184,6 @@ if (!this.parameters.channel) return 'Channel cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}`; @@ -11361,17 +11269,6 @@ if (!this.parameters.uuid) return "'uuid' cannot be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}/channels`; @@ -11484,17 +11381,6 @@ if (!channels || channels.length === 0) return 'Channels cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}/channels`; @@ -11575,17 +11461,6 @@ operation() { return RequestOperation$1.PNGetAllUUIDMetadataOperation; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { return `/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`; } @@ -11636,17 +11511,6 @@ if (!this.parameters.channel) return 'Channel cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}`; @@ -11704,17 +11568,6 @@ return undefined; } } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}`; @@ -11755,17 +11608,6 @@ if (!this.parameters.uuid) return "'uuid' cannot be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}`; @@ -11848,17 +11690,6 @@ if (!this.parameters.channel) return 'Channel cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}/uuids`; @@ -11968,17 +11799,6 @@ if (!uuids || uuids.length === 0) return 'UUIDs cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${encodeString(channel)}/uuids`; @@ -12061,17 +11881,6 @@ if (!this.parameters.uuid) return "'uuid' cannot be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}`; @@ -12131,17 +11940,6 @@ return undefined; } } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${encodeString(uuid)}`; @@ -12718,10 +12516,7 @@ } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new PubNubError('Service response error, check status for details', createValidationError('Unable to deserialize service response')); - return { timetoken: serviceResponse[0] }; + return { timetoken: this.deserializeResponse(response)[0] }; }); } get path() { @@ -13242,12 +13037,15 @@ status.statusCode = response.status; // Handle special case when request completed but not fully processed by PubNub service. if (response.status !== 200 && response.status !== 204) { + const responseText = PubNubCore.decoder.decode(response.body); const contentType = response.headers['content-type']; if (contentType || contentType.indexOf('javascript') !== -1 || contentType.indexOf('json') !== -1) { - const json = JSON.parse(PubNubCore.decoder.decode(response.body)); + const json = JSON.parse(responseText); if (typeof json === 'object' && 'error' in json && json.error && typeof json.error === 'object') status.errorData = json.error; } + else + status.responseText = responseText; } return request.parse(response); }) @@ -13490,7 +13288,7 @@ */ if (this.subscriptionManager) { // Creating identifiable abort caller. - const callableAbort = () => request.abort(); + const callableAbort = () => request.abort('Cancel long-poll subscribe request'); callableAbort.identifier = request.requestIdentifier; this.subscriptionManager.abort = callableAbort; } @@ -13574,7 +13372,7 @@ { const request = new HandshakeSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); + request.abort('Cancel subscribe handshake request'); }); /** * Allow subscription cancellation. @@ -13602,7 +13400,7 @@ { const request = new ReceiveMessagesSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); + request.abort('Cancel long-poll subscribe request'); }); /** * Allow subscription cancellation. @@ -13610,8 +13408,8 @@ * **Note:** Had to be done after scheduling because transport provider return cancellation * controller only when schedule new request. */ - const handshakeResponse = this.sendRequest(request); - return handshakeResponse.then((response) => { + const receiveResponse = this.sendRequest(request); + return receiveResponse.then((response) => { abortUnsubscribe(); return response; }); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 9c4f63683..6ec372c60 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var s={exports:{}};!function(t){!function(e,s){var n=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var o={encode:function(e){var t,n=new ArrayBuffer(256),o=new DataView(n),a=0;function c(e){for(var s=n.byteLength,r=a+e;s>2,u=0;u>6),r.push(128|63&o)):o<55296?(r.push(224|o>>12),r.push(128|o>>6&63),r.push(128|63&o)):(o=(1023&o)<<10,o|=1023&t.charCodeAt(++n),o+=65536,r.push(240|o>>18),r.push(128|o>>12&63),r.push(128|o>>6&63),r.push(128|63&o))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),n=0;n>5!==e)throw"Invalid indefinite length element";return s}function f(e,t){for(var s=0;s>10),e.push(56320|1023&n))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return s});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),s=h(),r=32768&s,i=31744&s,o=1023&s;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==o)return o*n;return t.setUint32(0,r<<16|i<<13|o<<13),t.getFloat32(0)}();case 26:return c(o.getFloat32(a),4);case 27:return c(o.getFloat64(a),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const s=new FileReader;s.addEventListener("load",(()=>{if(s.result instanceof ArrayBuffer)return e(s.result)})),s.addEventListener("error",(()=>t(s.error))),s.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const s=new FileReader;s.addEventListener("load",(()=>{if("string"==typeof s.result)return e(s.result)})),s.addEventListener("error",(()=>{t(s.error)})),s.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}a.supportsBlob="undefined"!=typeof Blob,a.supportsFile="undefined"!=typeof File,a.supportsBuffer=!1,a.supportsStream=!1,a.supportsString=!0,a.supportsArrayBuffer=!0,a.supportsEncryptFile=!0,a.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),s=Math.floor(t.length/4*3),n=new ArrayBuffer(s),r=new Uint8Array(n);let i=0;function o(){const e=t.charAt(i++),s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===s)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return s}for(let e=0;e>4,c=(15&s)<<4|n>>2,u=(3&n)<<6|i;r[e]=a,64!=n&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return n}function u(e){let t="";const s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",n=new Uint8Array(e),r=n.byteLength,i=r%3,o=r-i;let a,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=s[a]+s[c]+s[u]+s[l];return 1==i?(h=n[o],a=(252&h)>>2,c=(3&h)<<4,t+=s[a]+s[c]+"=="):2==i&&(h=n[o]<<8|n[o+1],a=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=s[a]+s[c]+s[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){return s=Object.assign({message:e},{}),null!==(n=s.statusCode)&&void 0!==n||(s.statusCode=0),Object.assign(Object.assign({},s),{statusCode:s.statusCode,category:h.PNValidationErrorCategory,error:!0});var s,n}var g,y,f,m,b,v=v||function(e){var t={},s=t.lib={},n=function(){},r=s.Base={extend:function(e){n.prototype=this;var t=new n;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=s.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||a).stringify(this)},concat:function(e){var t=this.words,s=e.words,n=this.sigBytes;if(e=e.sigBytes,this.clamp(),n%4)for(var r=0;r>>2]|=(s[r>>>2]>>>24-r%4*8&255)<<24-(n+r)%4*8;else if(65535>>2]=s[r>>>2];else t.push.apply(t,s);return this.sigBytes+=e,this},clamp:function(){var t=this.words,s=this.sigBytes;t[s>>>2]&=4294967295<<32-s%4*8,t.length=e.ceil(s/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var s=[],n=0;n>>2]>>>24-n%4*8&255;s.push((r>>>4).toString(16)),s.push((15&r).toString(16))}return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>3]|=parseInt(e.substr(n,2),16)<<24-n%8*4;return new i.init(s,t/2)}},c=o.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var s=[],n=0;n>>2]>>>24-n%4*8&255));return s.join("")},parse:function(e){for(var t=e.length,s=[],n=0;n>>2]|=(255&e.charCodeAt(n))<<24-n%4*8;return new i.init(s,t)}},u=o.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=s.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var s=this._data,n=s.words,r=s.sigBytes,o=this.blockSize,a=r/(4*o);if(t=(a=t?e.ceil(a):e.max((0|a)-this._minBufferSize,0))*o,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=a(e.pow(c,.5))),o[u]=a(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=n.extend({_doReset:function(){this._hash=new s.init(i.slice(0))},_doProcessBlock:function(e,t){for(var s=this._hash.words,n=s[0],r=s[1],i=s[2],a=s[3],c=s[4],u=s[5],l=s[6],h=s[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+o[d]+p[d],y=((n<<30|n>>>2)^(n<<19|n>>>13)^(n<<10|n>>>22))+(n&r^n&i^r&i),h=l,l=u,u=c,c=a+g|0,a=i,i=r,r=n,n=g+y|0}s[0]=s[0]+n|0,s[1]=s[1]+r|0,s[2]=s[2]+i|0,s[3]=s[3]+a|0,s[4]=s[4]+c|0,s[5]=s[5]+u|0,s[6]=s[6]+l|0,s[7]=s[7]+h|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;return s[r>>>5]|=128<<24-r%32,s[14+(r+64>>>9<<4)]=e.floor(n/4294967296),s[15+(r+64>>>9<<4)]=n,t.sigBytes=4*s.length,this._process(),this._hash},clone:function(){var e=n.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=n._createHelper(r),t.HmacSHA256=n._createHmacHelper(r)}(Math),y=(g=v).enc.Utf8,g.algo.HMAC=g.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=y.parse(t));var s=e.blockSize,n=4*s;t.sigBytes>n&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),o=r.words,a=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;4>o&&r+.75*o>>6*(3-o)&63));if(t=n.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,s=this._map;(n=s.charAt(64))&&-1!=(n=e.indexOf(n))&&(t=n);for(var n=[],r=0,i=0;i>>6-i%4*2;n[r>>>2]|=(o|a)<<24-r%4*8,r++}return m.create(n,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,s,n,r,i,o){return((e=e+(t&s|~t&n)+r+o)<>>32-i)+t}function s(e,t,s,n,r,i,o){return((e=e+(t&n|s&~n)+r+o)<>>32-i)+t}function n(e,t,s,n,r,i,o){return((e=e+(t^s^n)+r+o)<>>32-i)+t}function r(e,t,s,n,r,i,o){return((e=e+(s^(t|~n))+r+o)<>>32-i)+t}for(var i=v,o=(c=i.lib).WordArray,a=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=a.extend({_doReset:function(){this._hash=new o.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var o=0;16>o;o++){var a=e[c=i+o];e[c]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8)}o=this._hash.words;var c=e[i+0],l=(a=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=o[0],P=o[1],N=o[2],C=o[3],c,7,u[0]),C=t(C,O,P,N,a,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=s(O,P=t(P,N,C,O,E,22,u[15]),N,C,a,5,u[16]),C=s(C,O,P,N,g,9,u[17]),N=s(N,C,O,P,v,14,u[18]),P=s(P,N,C,O,c,20,u[19]),O=s(O,P,N,C,p,5,u[20]),C=s(C,O,P,N,b,9,u[21]),N=s(N,C,O,P,E,14,u[22]),P=s(P,N,C,O,d,20,u[23]),O=s(O,P,N,C,m,5,u[24]),C=s(C,O,P,N,k,9,u[25]),N=s(N,C,O,P,h,14,u[26]),P=s(P,N,C,O,f,20,u[27]),O=s(O,P,N,C,S,5,u[28]),C=s(C,O,P,N,l,9,u[29]),N=s(N,C,O,P,y,14,u[30]),O=n(O,P=s(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=n(C,O,P,N,f,11,u[33]),N=n(N,C,O,P,v,16,u[34]),P=n(P,N,C,O,k,23,u[35]),O=n(O,P,N,C,a,4,u[36]),C=n(C,O,P,N,d,11,u[37]),N=n(N,C,O,P,y,16,u[38]),P=n(P,N,C,O,b,23,u[39]),O=n(O,P,N,C,S,4,u[40]),C=n(C,O,P,N,c,11,u[41]),N=n(N,C,O,P,h,16,u[42]),P=n(P,N,C,O,g,23,u[43]),O=n(O,P,N,C,m,4,u[44]),C=n(C,O,P,N,w,11,u[45]),N=n(N,C,O,P,E,16,u[46]),O=r(O,P=n(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,a,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);o[0]=o[0]+O|0,o[1]=o[1]+P|0,o[2]=o[2]+N|0,o[3]=o[3]+C|0},_doFinalize:function(){var t=this._data,s=t.words,n=8*this._nDataBytes,r=8*t.sigBytes;s[r>>>5]|=128<<24-r%32;var i=e.floor(n/4294967296);for(s[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),s[14+(r+64>>>9<<4)]=16711935&(n<<8|n>>>24)|4278255360&(n<<24|n>>>8),t.sigBytes=4*(s.length+1),this._process(),s=(t=this._hash).words,n=0;4>n;n++)r=s[n],s[n]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=a.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=a._createHelper(c),i.HmacMD5=a._createHmacHelper(c)}(Math),function(){var e,t=v,s=(e=t.lib).Base,n=e.WordArray,r=(e=t.algo).EvpKDF=s.extend({cfg:s.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var s=(a=this.cfg).hasher.create(),r=n.create(),i=r.words,o=a.keySize,a=a.iterations;i.length>>2]}},e.BlockCipher=o.extend({cfg:o.cfg.extend({mode:a,padding:u}),reset:function(){o.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var s=t.createEncryptor;else s=t.createDecryptor,this._minBufferSize=1;this._mode=s.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(a=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?s.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var n=s.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:n})}},e.SerializableCipher=t.extend({cfg:t.extend({format:a}),encrypt:function(e,t,s,n){n=this.cfg.extend(n);var r=e.createEncryptor(s,n);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:s,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:n.format})},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),e.createDecryptor(s,n).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,n,r){return r||(r=s.random(8)),e=i.create({keySize:t+n}).compute(e,r),n=s.create(e.words.slice(t),4*n),e.sigBytes=4*t,l.create({key:e,iv:n,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,s,n){return s=(n=this.cfg.extend(n)).kdf.execute(s,e.keySize,e.ivSize),n.iv=s.iv,(e=h.encrypt.call(this,e,t,s.key,n)).mixIn(s),e},decrypt:function(e,t,s,n){return n=this.cfg.extend(n),t=this._parse(t,n.format),s=n.kdf.execute(s,e.keySize,e.ivSize,t.salt),n.iv=s.iv,h.decrypt.call(this,e,t,s.key,n)}})}(),function(){for(var e=v,t=e.lib.BlockCipher,s=e.algo,n=[],r=[],i=[],o=[],a=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;n[y]=m,r[m]=y;var b=p[y],w=p[b],S=p[w],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,o[y]=k<<16|k>>>16,a[y]=k<<8|k>>>24,c[y]=k,k=16843009*S^65537*w^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[S^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];s=s.AES=t.extend({_doReset:function(){for(var e=(s=this._key).words,t=s.sigBytes/4,s=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o]):(o=n[(o=o<<8|o>>>24)>>>24]<<24|n[o>>>16&255]<<16|n[o>>>8&255]<<8|n[255&o],o^=E[i/t|0]<<24),r[i]=r[i-t]^o}for(e=this._invKeySchedule=[],t=0;tt||4>=i?o:u[n[o>>>24]]^l[n[o>>>16&255]]^h[n[o>>>8&255]]^d[n[255&o]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,o,a,c,n)},decryptBlock:function(e,t){var s=e[t+1];e[t+1]=e[t+3],e[t+3]=s,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),s=e[t+1],e[t+1]=e[t+3],e[t+3]=s},_doCryptBlock:function(e,t,s,n,r,i,o,a){for(var c=this._nRounds,u=e[t]^s[0],l=e[t+1]^s[1],h=e[t+2]^s[2],d=e[t+3]^s[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^o[255&d]^s[p++],f=n[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^o[255&u]^s[p++],m=n[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^o[255&l]^s[p++];d=n[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^o[255&h]^s[p++],u=y,l=f,h=m}y=(a[u>>>24]<<24|a[l>>>16&255]<<16|a[h>>>8&255]<<8|a[255&d])^s[p++],f=(a[l>>>24]<<24|a[h>>>16&255]<<16|a[d>>>8&255]<<8|a[255&u])^s[p++],m=(a[h>>>24]<<24|a[d>>>16&255]<<16|a[u>>>8&255]<<8|a[255&l])^s[p++],d=(a[d>>>24]<<24|a[u>>>16&255]<<16|a[l>>>8&255]<<8|a[255&h])^s[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(s)}(),v.mode.ECB=((b=v.lib.BlockCipherMode.extend()).Encryptor=b.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),b.Decryptor=b.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),b);var w=t(v);class S{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=w,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:S.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),s=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:s},t,e),metadata:s}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),s=this.bufferToWordArray(new Uint8ClampedArray(e.data));return S.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:s},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(S.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=S.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let s;for(s=0;se.toString(16).padStart(2,"0"))).join(""),n=O.encoder.encode(s.slice(0,32)).buffer;return crypto.subtle.importKey("raw",n,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}}O.IV_LENGTH=16,O.encoder=new TextEncoder,O.decoder=new TextDecoder;class C{constructor(e){this.config=e,this.cryptor=new E(Object.assign({},e)),this.fileCryptor=new O}encrypt(e){const t="string"==typeof e?e:C.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(s=this.config)||void 0===s?void 0:s.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}C.encoder=new TextEncoder,C.decoder=new TextDecoder;class N extends o{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new S({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new N({default:new S({cipherKey:e.cipherKey}),cryptors:[new C(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===N.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(N.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const s=this.getHeaderData(t);return this.concatArrayBuffer(s,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===P.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const s=yield this.getFileData(e),n=yield this.defaultCryptor.encryptFileData(s);if("string"==typeof n.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(n),n.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,s=P.tryParse(t),n=this.getCryptor(s),r=s.length>0?t.slice(s.length-s.metadataLength,s.length):null;if(t.slice(s.length).byteLength<=0)throw new Error("Decryption error: empty content");return n.decrypt({data:t.slice(s.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const s=yield e.data.arrayBuffer(),n=P.tryParse(s),r=this.getCryptor(n);if((null==r?void 0:r.identifier)===P.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(s)).slice(n.length-n.metadataLength,n.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:s.slice(n.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof M)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=P.from(this.defaultCryptor.identifier,e.metadata),s=new Uint8Array(t.length);let n=0;return s.set(t.data,n),n+=t.length-e.metadata.byteLength,s.set(new Uint8Array(e.metadata),n),s.buffer}concatArrayBuffer(e,t){const s=new Uint8Array(e.byteLength+t.byteLength);return s.set(new Uint8Array(e),0),s.set(new Uint8Array(t),e.byteLength),s.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof a)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}N.LEGACY_IDENTIFIER="";class P{static from(e,t){if(e!==P.LEGACY_IDENTIFIER)return new M(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let s,n,r=null;if(t.byteLength>=4&&(s=t.slice(0,4),this.decoder.decode(s)!==P.SENTINEL))return N.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>P.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+P.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");n=t.slice(5,i);let o=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return o=t[i],i+=1,255===o&&t.byteLength>=i+2&&(o=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new M(this.decoder.decode(n),o)}}P.SENTINEL="PNED",P.LEGACY_IDENTIFIER="",P.IDENTIFIER_LENGTH=4,P.VERSION=1,P.MAX_VERSION=1,P.decoder=new TextDecoder;class M{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return P.VERSION}get length(){return P.SENTINEL.length+1+P.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),s=new TextEncoder;t.set(s.encode(P.SENTINEL)),e+=P.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(s.encode(this.identifier),e);const n=this.metadataLength;return e+=P.IDENTIFIER_LENGTH,n<255?t[e]=n:t.set([255,n>>8,255&n],e),t}}M.IDENTIFIER_LENGTH=4,M.SENTINEL="PNED";class _ extends Error{static create(e,t){return e instanceof Error?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,s="Unknown error",n="Error";if(!e)return new _(s,t,0);if(e instanceof _)return e;if(e instanceof Error&&(s=e.message,n=e.name),"AbortError"===n||-1!==s.indexOf("Aborted"))t=h.PNCancelledCategory,s="Request cancelled";else if(-1!==s.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,s="Request timeout";else if(-1!==s.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,s="Network issues";else if("TypeError"===n)t=-1!==s.indexOf("Load failed")||-1!=s.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===n){const n=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(n)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===n?s="Connection refused":"ENETUNREACH"===n?s="Network not reachable":"ENOTFOUND"===n?s="Server not found":"ECONNRESET"===n?s="Connection reset by peer":"EAI_AGAIN"===n?s="Name resolution error":"ETIMEDOUT"===n?(t=h.PNTimeoutCategory,s="Request timeout"):s=`Unknown system error: ${e}`}else"Request timeout"===s&&(t=h.PNTimeoutCategory);return new _(s,t,0,e)}static createFromServiceResponse(e,t){let s,n=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(n=h.PNBadRequestCategory,r="Bad request"):403===i&&(n=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const n=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(n);"object"!=typeof e||Array.isArray(e)||("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(s=e,i=e.status):s=e,"error"in e&&e.error instanceof Error&&(s=e.error))}catch(e){s=n}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(n);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else s=n}return new _(r,n,i,s)}constructor(e,t,s,n){super(e),this.category=t,this.statusCode=s,this.errorData=n,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class A{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const s={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,n)=>{this.callbacks.set(e.identifier,{resolve:t,reject:n}),this.scheduleEventPost(s)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const s=this.sharedSubscriptionWorker;s?s.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:s}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:s,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:s}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,n="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),n=`${t.error.message} (${t.identifier})`;else if(t.response)return s(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));s(new _(n,e,0,new Error(n)))}}}logRequestProgress(e){var t,s;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(s=e.query)&&void 0!==s?s:{})}\n${e.response}`),console.log("-----"))}}function j(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,s=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const n={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let o=r;const a=e[r];if(i&&r.indexOf(",")>=0){o=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(s(r)||i&&!isNaN(Number(r)))&&(o=String.fromCharCode(s(r)?r:parseInt(r,10)));n[o]=t(a)?j(a):a})),n}const I=e=>{var t,s,n,r;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,s,n,r,i,o,a,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(s=m.ssl)&&void 0!==s||(m.ssl=!0),null!==(n=m.transactionalRequestTimeout)&&void 0!==n||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(o=m.restore)&&void 0!==o||(m.restore=!1),null!==(a=m.useInstanceId)&&void 0!==a||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,k=!1,E=100,O=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(O=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:O,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(s=e.subscriptionWorkerLogVerbosity)&&void 0!==s&&s,transport:null!==(n=e.transport)&&void 0!==n?n:"fetch",keepAlive:null===(r=e.keepAlive)||void 0===r||r})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",s={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function n(){var e,t,s="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(s+="-"),s+=(12===e?4:16===e?3&t|8:t).toString(16);return s}function r(e,t){var n=s[t||"all"];return n&&n.test(e)||!1}n.isUUID=r,n.VERSION=t,e.uuid=n,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var F=t(R.exports),T={createUUID:()=>F.uuid?F.uuid():F()};const U=(e,t)=>{var s,n,r;null===(s=e.retryConfiguration)||void 0===s||s.validate(),null!==(n=e.useRandomIVs)&&void 0!==n||(e.useRandomIVs=true),e.origin=x(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const o=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${T.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.8.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?o.setCipherKey(e.cipherKey):i&&(o._cryptoModule=i),o},x=(e,t)=>{const s=e?"https://":"http://";return"string"==typeof t?`${s}${t}`:`${s}${t[Math.floor(Math.random()*t.length)]}`};class D{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],s=Object.keys(t.res.chan),n=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),o=Object.keys(t.pat.grp),a={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=s.length>0,l=n.length>0;if(c||u||l){if(a.resources={},c){const s=a.resources.uuids={};e.forEach((e=>s[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=a.resources.channels={};s.forEach((s=>e[s]=this.extractPermissions(t.res.chan[s])))}if(l){const e=a.resources.groups={};n.forEach((s=>e[s]=this.extractPermissions(t.res.grp[s])))}}const h=r.length>0,d=i.length>0,p=o.length>0;if(h||d||p){if(a.patterns={},h){const e=a.patterns.uuids={};r.forEach((s=>e[s]=this.extractPermissions(t.pat.uuid[s])))}if(d){const e=a.patterns.channels={};i.forEach((s=>e[s]=this.extractPermissions(t.pat.chan[s])))}if(p){const e=a.patterns.groups={};o.forEach((s=>e[s]=this.extractPermissions(t.pat.grp[s])))}}return t.meta&&Object.keys(t.meta).length>0&&(a.meta=t.meta),a}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var q;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(q||(q={}));const G=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),K=(e,t)=>{const s=e.map((e=>G(e)));return s.length?s.join(","):null!=t?t:""},$=(e,t)=>{const s=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!s[e])||(s[e]=!0,!1)))},L=(e,t)=>[...e].filter((s=>t.includes(s)&&e.indexOf(s)===e.lastIndexOf(s)&&t.indexOf(s)===t.lastIndexOf(s)));class B{constructor(e,t,s){this.publishKey=e,this.secretKey=t,this.hasher=s}signature(e){const t=e.path.startsWith("/publish")?q.GET:e.method;let s=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===q.POST||t===q.PATCH){const t=e.body;let n;t&&t instanceof ArrayBuffer?n=B.textDecoder.decode(t):t&&"object"!=typeof t&&(n=t),n&&(s+=n)}return`v2.${this.hasher(s,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const s=e[t];return Array.isArray(s)?s.sort().map((e=>`${t}=${G(e)}`)).join("&"):`${t}=${G(s)}`})).join("&")}}B.textDecoder=new TextDecoder("utf-8");class H{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:s}=e;t.secretKey&&s&&(this.signatureGenerator=new B(t.publishKey,t.secretKey,s))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:s}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),s.useInstanceId&&(e.queryParameters.instanceid=s.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=s.userId),s.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=s.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:s,tokenManager:n}=this.configuration,r=null!==(t=n&&n.getToken())&&void 0!==t?t:s.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const s=e._getPnsdkSuffix(" ");return s.length>0&&(t+=s),t}}class z{constructor(e="fetch",t=!1,s=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=s,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!s)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,s={abortController:t,abort:()=>!t.signal.aborted&&t.abort()};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const n=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,s).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const s=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],o={};i.forEach(((e,t)=>o[t]=e.toLowerCase()));const a={status:r,url:t.url,headers:o,body:s};if(r>=400)throw _.create(a);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-n,s),a})).catch((e=>{throw _.create(e)}))})),s]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let s;const n=new Promise(((n,r)=>{s=setTimeout((()=>{clearTimeout(s),r(new Error("Request timeout")),t.abort()}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(s&&clearTimeout(s),e))),n])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((s,n)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>n(new Error("Aborted")),i.ontimeout=()=>n(new Error("Request timeout")),i.onerror=()=>n(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[s,n]=t.split(": ");s.length>1&&n.length>1&&e.append(s,n)})),s(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,s=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const s=e.body,n=new FormData;for(const{key:t,value:s}of e.formData)n.append(t,s);try{const e=yield s.toArrayBuffer();n.append("file",new Blob([e],{type:"application/octet-stream"}),s.name)}catch(e){try{const e=yield s.toFileUri();n.append("file",e,s.name)}catch(e){}}t=n}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var n;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(s=`${s}?${n=e.queryParameters,Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${G(t)}`)).join("&"):`${e}=${G(t)}`})).join("&")}`),{url:`${e.origin}${s}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,s,n){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:o,search:a}=new URL(e.url),c=(new Date).toISOString();if(s){let e=`[${c} / ${s}]\n${r}//${i}${o}\n${a}`;n&&(e+=`\n\n${z.decoder.decode(n)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${o}\n${a}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class V{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class W{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class J{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let s=0;s{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==s||s.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:s,channelGroups:n}=e;const i=new Set,o=new Set;null==s||s.forEach((e=>{e in this.channels&&(delete this.channels[e],o.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],o.add(e))})),null==n||n.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===o.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(n=Array.from(i),s=Array.from(o),this.leaveCall({channels:s,channelGroups:n},(e=>{const{error:t}=e,i=r(e,["error"]);let o;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?o=e.errorData.message:"message"in e&&"string"==typeof e.message&&(o=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=o&&o,affectedChannels:s,affectedChannelGroups:n,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e)):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:s}=t,{requestMessageCountThreshold:n,dedupeOnSubscribe:r}=this.configuration;n&&s.length>=n&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{s.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:s,channelGroups:n}=e;null==s||s.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==n||n.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:s,channelGroups:n}=e;t?(null==s||s.forEach((e=>this.heartbeatChannels[e]={})),null==n||n.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==s||s.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==n||n.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:s,channelGroups:n},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Q{constructor(e,t,s){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=s}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class Y extends Q{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:s}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return s&&Object.keys(s).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,s={}),this._isSilent||s&&Object.keys(s).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:s}=e,n={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(n.collapse_id=t),s&&(n.expiration=s.toISOString()),n}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:s="development",excludedDevices:n=[]}=e,r={topic:t,environment:s};return n.length&&(r.excluded_devices=n),r}}class Z extends Q{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const s={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(s.data=e),t&&Object.keys(t).length&&(s.notification=t),Object.keys(s).length?s:null}}class ee{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new Y(this._payload.apns,e,t),this.fcm=new Z(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const s=this.apns.toObject();s&&Object.keys(s).length&&(t.pn_apns=s)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class te{constructor(e){this.params=e,this.requestIdentifier=T.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(){this&&this.cancellationController&&this.cancellationController.abort()}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented by subclass.")}))}request(){var e,t,s,n;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:q.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(n=null===(s=this.params)||void 0===s?void 0:s.cancellable)&&void 0!==n&&n,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===q.POST||r.method===q.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=e.headers["content-type"];if(!t||-1===t.indexOf("javascript")&&-1===t.indexOf("json"))return;const s=te.decoder.decode(e.body);try{return JSON.parse(s)}catch(e){return void console.error("Error parsing JSON response:",e)}}}var se;te.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(se||(se={}));var ne=se;var re;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(re||(re={}));class ie extends te{constructor(e){var t,s,n,r,i,o;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(s=(i=this.parameters).channelGroups)&&void 0!==s||(i.channelGroups=[]),null!==(n=(o=this.parameters).channels)&&void 0!==n||(o.channels=[])}operation(){return ne.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;return e?t||s?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t;try{const s=te.decoder.decode(e.body);t=JSON.parse(s)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?re.Presence:re.Message),t!=re.Signal&&"string"==typeof e.d?t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}:t==re.Message?{type:re.Message,data:this.messageFromEnvelope(e)}:t===re.Presence?{type:re.Presence,data:this.presenceEventFromEnvelope(e)}:t==re.Signal?{type:re.Signal,data:this.signalFromEnvelope(e)}:t===re.AppContext?{type:re.AppContext,data:this.appContextFromEnvelope(e)}:t===re.MessageAction?{type:re.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:re.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:s}=e,[n,r]=this.subscriptionChannelFromEnvelope(e),i=n.replace("-pnpres",""),o=null!==r?i:null,a=null!==r?r:i;return"string"!=typeof s&&("data"in s?(s.state=s.data,delete s.data):"action"in s&&"interval"===s.action&&(s.hereNowRefresh=null!==(t=s.here_now_refresh)&&void 0!==t&&t,delete s.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:o,subscribedChannel:a,timetoken:e.p.t},s)}messageFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d),i={channel:t,subscription:s,actualChannel:null!==s?t:null,subscribedChannel:null!==s?s:t,timetoken:e.p.t,publisher:e.i,message:n};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(n.userMetadata=e.u),e.cmt&&(n.customMessageType=e.cmt),n}messageActionFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,publisher:e.i,event:n.event,data:Object.assign(Object.assign({},n.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),n=e.d;return{channel:t,subscription:s,timetoken:e.p.t,message:n}}fileFromEnvelope(e){const[t,s]=this.subscriptionChannelFromEnvelope(e),[n,r]=this.decryptedData(e.d);let i=r;const o={channel:t,subscription:s,timetoken:e.p.t,publisher:e.i};return e.u&&(o.userMetadata=e.u),n?"string"==typeof n?null!=i||(i="Unexpected file information payload data type."):(o.message=n.message,n.file&&(o.file={id:n.file.id,name:n.file.name,url:this.parameters.getFileUrl({id:n.file.id,name:n.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(o.customMessageType=e.cmt),i&&(o.error=i),o}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,s;try{const s=this.parameters.crypto.decrypt(e);t=s instanceof ArrayBuffer?JSON.parse(oe.decoder.decode(s)):s}catch(e){t=null,s=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,s]}}class oe extends ie{get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/subscribe/${t}/${K(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:s,state:n,timetoken:r,region:i}=this.parameters,o={};return e&&e.length>0&&(o["channel-group"]=e.sort().join(",")),t&&t.length>0&&(o["filter-expr"]=t),s&&(o.heartbeat=s),n&&Object.keys(n).length>0&&(o.state=JSON.stringify(n)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(o.tt=r):void 0!==r&&r>0&&(o.tt=r),i&&(o.tr=i),o}}class ae{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===re.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===re.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===re.AppContext){const{data:t}=e,{message:s}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,type:a}=s,c=r(s,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===s.type){const{message:e,channel:n}=t,i=r(t,["message","channel"]),{event:o,data:a}=s,c=r(s,["event","data"]),{uuid:u,channel:l}=a,h=r(a,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:n,message:Object.assign(Object.assign({},c),{event:"set"===o?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===re.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===re.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,s){t&&s?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const s=this.channelListenerMap.get(t);s.includes(e)||s.push(e)}else this.channelListenerMap.set(t,[e])})),null==s||s.forEach((t=>{if(this.groupListenerMap.has(t)){const s=this.groupListenerMap.get(t);s.includes(e)||s.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,s){t&&s?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==s||s.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,s,n){t&&this.channelListenerMap.has(s)&&this.channelListenerMap.get(s).forEach((s=>{const n=s[e];n&&n(t)})),n&&this.groupListenerMap.has(n)&&this.groupListenerMap.get(n).forEach((s=>{const n=s[e];n&&n(t)}))}}class ce{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class ue{transition(e,t){var s;if(this.transitionMap.has(t.type))return null===(s=this.transitionMap.get(t.type))||void 0===s?void 0:s(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class le extends ce{describe(e){return new ue(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[s,n,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=s;const o=this.currentContext;this.currentContext=n,this.notify({type:"transitionDone",fromState:i,fromContext:o,toState:s,toContext:n,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class he{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const s=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,s),s.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function de(e,t){const s=function(...s){return{type:e,payload:null==t?void 0:t(...s)}};return s.type=e,s}function pe(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!1});return s.type=e,s}function ge(e,t){const s=(...s)=>({type:e,payload:t(...s),managed:!0});return s.type=e,s.cancel={type:"CANCEL",payload:e,managed:!1},s}class ye extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class fe extends ce{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new ye}abort(){this._aborted=!0,this.notify(new ye)}}class me{constructor(e,t){this.payload=e,this.dependencies=t}}class be extends me{constructor(e,t,s){super(e,t),this.asyncFunction=s,this.abortSignal=new fe}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const ve=e=>(t,s)=>new be(t,s,e),we=de("RECONNECT",(()=>({}))),Se=de("DISCONNECT",(()=>({}))),ke=de("JOINED",((e,t)=>({channels:e,groups:t}))),Ee=de("LEFT",((e,t)=>({channels:e,groups:t}))),Oe=de("LEFT_ALL",(()=>({}))),Ce=de("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Ne=de("HEARTBEAT_FAILURE",(e=>e)),Pe=de("HEARTBEAT_GIVEUP",(()=>({}))),Me=de("TIMES_UP",(()=>({}))),_e=pe("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ae=pe("LEAVE",((e,t)=>({channels:e,groups:t}))),je=pe("EMIT_STATUS",(e=>e)),Ie=ge("WAIT",(()=>({}))),Re=ge("DELAYED_HEARTBEAT",(e=>e));class Fe extends he{constructor(e,t){super(t),this.on(_e.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,presenceState:r,config:i}){try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(Ae.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{leave:s,config:n}){if(!n.suppressLeaveEvents)try{s({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Ie.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeatDelay:n}){return s.throwIfAborted(),yield n(),s.throwIfAborted(),e.transition(Me())}))))),this.on(Re.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{heartbeat:n,retryDelay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Pe());s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{yield n(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},o.maintainPresenceState&&{state:i}),{heartbeat:o.presenceTimeout}));return e.transition(Ce(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ne(t))}}}))))),this.on(je.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s,config:n}){var r;n.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?s(e.status):n.announceSuccessfulHeartbeats&&200===e.statusCode&&s(Object.assign(Object.assign({},e),{operation:ne.PNHeartbeatOperation,error:!1}))})))))}}const Te=new ue("HEARTBEAT_STOPPED");Te.on(ke.type,((e,t)=>Te.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Te.on(Ee.type,((e,t)=>Te.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Te.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Te.on(Oe.type,((e,t)=>Ge.with(void 0)));const Ue=new ue("HEARTBEAT_COOLDOWN");Ue.onEnter((()=>Ie())),Ue.onExit((()=>Ie.cancel)),Ue.on(Me.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ue.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ue.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),Ue.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),Ue.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const xe=new ue("HEARTBEAT_FAILED");xe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),xe.on(we.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),xe.on(Se.type,((e,t)=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),xe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const De=new ue("HEARBEAT_RECONNECTING");De.onEnter((e=>Re(e))),De.onExit((()=>Re.cancel)),De.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),De.on(Se.type,((e,t)=>{Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)])})),De.on(Ce.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups}))),De.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),De.on(Pe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const qe=new ue("HEARTBEATING");qe.onEnter((e=>_e(e.channels,e.groups))),qe.on(Ce.type,((e,t)=>Ue.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>qe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ee.type,((e,t)=>qe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ae(t.payload.channels,t.payload.groups)]))),qe.on(Ne.type,((e,t)=>De.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),qe.on(Se.type,(e=>Te.with({channels:e.channels,groups:e.groups},[Ae(e.channels,e.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with(void 0,[Ae(e.channels,e.groups)])));const Ge=new ue("HEARTBEAT_INACTIVE");Ge.on(ke.type,((e,t)=>qe.with({channels:t.payload.channels,groups:t.payload.groups})));class Ke{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new le,this.channels=[],this.groups=[],this.dispatcher=new Fe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ge,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ee(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Oe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class $e{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:this.delay)+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var s;return 403!==(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)&&this.maximumRetry>t},getDelay(e,t){var s;return 1e3*((null!==(s=t.retryAfter)&&void 0!==s?s:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var s;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(s=null==e?void 0:e.status)||void 0===s?void 0:s.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const Le=ge("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Be=ge("RECEIVE_MESSAGES",((e,t,s)=>({channels:e,groups:t,cursor:s}))),He=pe("EMIT_MESSAGES",(e=>e)),ze=pe("EMIT_STATUS",(e=>e)),Ve=ge("RECEIVE_RECONNECT",(e=>e)),We=ge("HANDSHAKE_RECONNECT",(e=>e)),Je=de("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Xe=de("SUBSCRIPTION_RESTORED",((e,t,s,n)=>({channels:e,groups:t,cursor:{timetoken:s,region:null!=n?n:0}}))),Qe=de("HANDSHAKE_SUCCESS",(e=>e)),Ye=de("HANDSHAKE_FAILURE",(e=>e)),Ze=de("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),et=de("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),tt=de("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),st=de("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),nt=de("RECEIVE_FAILURE",(e=>e)),rt=de("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=de("RECEIVE_RECONNECT_FAILURE",(e=>e)),ot=de("RECEIVING_RECONNECT_GIVEUP",(e=>e)),at=de("DISCONNECT",(()=>({}))),ct=de("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ut=de("UNSUBSCRIBE_ALL",(()=>({})));class lt extends he{constructor(e,t){super(t),this.on(Le.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,presenceState:r,config:i}){s.throwIfAborted();try{const o=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Qe(o))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ye(t))}}}))))),this.on(Be.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,config:r}){s.throwIfAborted();try{const i=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(st(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!s.aborted)return e.transition(nt(t))}}}))))),this.on(He.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitMessages:s}){e.length>0&&s(e)}))))),this.on(ze.type,ve(((e,t,s)=>i(this,[e,t,s],void 0,(function*(e,t,{emitStatus:s}){s(e)}))))),this.on(Ve.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{receiveMessages:n,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ot(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));s.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n({abortSignal:s,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(rt(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(it(t))}}}))))),this.on(We.type,ve(((t,s,n)=>i(this,[t,s,n],void 0,(function*(t,s,{handshake:n,delay:r,presenceState:i,config:o}){if(!o.retryConfiguration||!o.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(tt(new d(o.retryConfiguration?o.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));s.throwIfAborted(),yield r(o.retryConfiguration.getDelay(t.attempts,t.reason)),s.throwIfAborted();try{const r=yield n(Object.assign({abortSignal:s,channels:t.channels,channelGroups:t.groups,filterExpression:o.filterExpression},o.maintainPresenceState&&{state:i}));return e.transition(Ze(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}})))))}}const ht=new ue("HANDSHAKE_FAILED");ht.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ht.on(ct.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),ht.on(Xe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(n=null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)&&void 0!==n?n:0}})})),ht.on(ut.type,(e=>vt.with()));const dt=new ue("HANDSHAKE_STOPPED");dt.on(Je.type,((e,t)=>dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),dt.on(ct.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),dt.on(Xe.type,((e,t)=>{var s;return dt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),dt.on(ut.type,(e=>vt.with()));const pt=new ue("RECEIVE_FAILED");pt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),pt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),pt.on(ut.type,(e=>vt.with(void 0)));const gt=new ue("RECEIVE_STOPPED");gt.on(Je.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(Xe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),gt.on(ct.type,((e,t)=>{var s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(s=t.payload.cursor)||void 0===s?void 0:s.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),gt.on(ut.type,(()=>vt.with(void 0)));const yt=new ue("RECEIVE_RECONNECTING");yt.onEnter((e=>Ve(e))),yt.onExit((()=>Ve.cancel)),yt.on(rt.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),yt.on(it.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),yt.on(ot.type,((e,t)=>{var s;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),yt.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),yt.on(Xe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(Je.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const ft=new ue("RECEIVING");ft.onEnter((e=>Be(e.channels,e.groups,e.cursor))),ft.onExit((()=>Be.cancel)),ft.on(st.type,((e,t)=>ft.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[He(t.payload.events)]))),ft.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),ft.on(Xe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(nt.type,((e,t)=>yt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),ft.on(at.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),ft.on(ut.type,(e=>vt.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new ue("HANDSHAKE_RECONNECTING");mt.onEnter((e=>We(e))),mt.onExit((()=>We.cancel)),mt.on(Ze.type,((e,t)=>{var s,n;const r={timetoken:(null===(s=e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=e.cursor)||void 0===n?void 0:n.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return ft.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),mt.on(et.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(tt.type,((e,t)=>{var s;return ht.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(s=t.payload)||void 0===s?void 0:s.message})])})),mt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),mt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(Xe.type,((e,t)=>{var s,n;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(s=t.payload.cursor)||void 0===s?void 0:s.region)||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),mt.on(ut.type,(e=>vt.with(void 0)));const bt=new ue("HANDSHAKING");bt.onEnter((e=>Le(e.channels,e.groups))),bt.onExit((()=>Le.cancel)),bt.on(Je.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?vt.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(Qe.type,((e,t)=>{var s,n;return ft.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken)?null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),bt.on(Ye.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),bt.on(at.type,(e=>dt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),bt.on(Xe.type,((e,t)=>{var s;return bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),bt.on(ut.type,(e=>vt.with()));const vt=new ue("UNSUBSCRIBED");vt.on(Je.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups}))),vt.on(Xe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class wt{get _engine(){return this.engine}constructor(e){this.engine=new le,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new lt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(vt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:s,withPresence:n}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],n&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),s?this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),s)):this.engine.transition(Je(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const s=$(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),n=$(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(s).size||new Set(this.groups).size!==new Set(n).size){const r=L(this.channels,e),i=L(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=s,this.groups=n,this.engine.transition(Je(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Je(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(ct(e,t))}disconnect(){this.engine.transition(at()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class St extends te{constructor(e){var t,s;super({method:e.sendByPost?q.POST:q.GET}),this.parameters=e,null!==(t=(s=this.parameters).sendByPost)&&void 0!==t||(s.sendByPost=false)}operation(){return ne.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:s}=this.parameters,n=this.prepareMessagePayload(e);return`/publish/${s.publishKey}/${s.subscribeKey}/0/${G(t)}/0${this.parameters.sendByPost?"":`/${G(n)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:s,storeInHistory:n,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==n&&(i.store=n?"1":"0"),void 0!==r&&(i.ttl=r),void 0===s||s||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class kt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:s}}=this.parameters;return t?e?s?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:s,message:n}=this.parameters,r=JSON.stringify(n);return`/signal/${e}/${t}/0/${G(s)}/0/${G(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Et extends ie{operation(){return ne.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${K(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:s,region:n}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof s?s&&s.length>0&&(r.tt=s):s&&s>0&&(r.tt=s),n&&(r.tr=n),r}}class Ot extends ie{operation(){return ne.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${K(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:s}=this.parameters,n={tt:0,ee:""};return e&&e.length>0&&(n["channel-group"]=e.sort().join(",")),t&&t.length>0&&(n["filter-expr"]=t),s&&Object.keys(s).length>0&&(n.state=JSON.stringify(s)),n}}class Ct extends te{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=(n=this.parameters).channels)&&void 0!==t||(n.channels=[]),null!==(s=(r=this.parameters).channelGroups)&&void 0!==s||(r.channelGroups=[])}operation(){return ne.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);const{channels:s=[],channelGroups:n=[]}=this.parameters,r={channels:{}};return 1===s.length&&0===n.length?r.channels[s[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=s?s:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Nt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:s=[],channelGroups:n=[]}=this.parameters;return e?t?0===(null==s?void 0:s.length)&&0===(null==n?void 0:n.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{state:t.payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:s}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=s?s:[],",")}/uuid/${G(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,s={state:JSON.stringify(t)};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),s}}class Pt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${K(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:s}=this.parameters,n={heartbeat:`${s}`};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),t&&(n.state=JSON.stringify(t)),n}}class Mt extends te{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ne.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:s=[]}=this.parameters;return e?0===t.length&&0===s.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){var e;const{keySet:{subscribeKey:t},channels:s}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${K(null!==(e=null==s?void 0:s.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${G(t)}`}}class At extends te{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(s=(i=this.parameters).includeUUIDs)&&void 0!==s||(i.includeUUIDs=true),null!==(n=(o=this.parameters).includeState)&&void 0!==n||(o.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ne.PNGlobalHereNowOperation:ne.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,s;const n=this.deserializeResponse(e);if(!n)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(n.status>=400)throw _.create(e);const r="occupancy"in n?1:n.payload.total_channels,i="occupancy"in n?n.occupancy:n.payload.total_occupancy,o={};let a={};if("occupancy"in n){const e=this.parameters.channels[0];a[e]={uuids:null!==(t=n.uuids)&&void 0!==t?t:[],occupancy:i}}else a=null!==(s=n.payload.channels)&&void 0!==s?s:{};return Object.keys(a).forEach((e=>{const t=a[e];o[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:o}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:s}=this.parameters;let n=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||s&&s.length>0)&&(n+=`/channel/${K(null!=t?t:[],",")}`),n}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:s,queryParameters:n}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=s&&s?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),n)}}class jt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${G(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class It extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:s,channelTimetokens:n}=this.parameters;return e?t?s&&n?"`timetoken` and `channelTimetokens` are incompatible together":s||n?n&&n.length>1&&n.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${K(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends te{constructor(e){var t,s,n;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(s=e.includeMeta)&&void 0!==s||(e.includeMeta=false),null!==(n=e.logVerbosity)&&void 0!==n||(e.logVerbosity=false)}operation(){return ne.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));const s=t[0],n=t[1],r=t[2];return Array.isArray(s)?{messages:s.map((e=>{const t=this.processPayload(e.message),s={entry:t.payload,timetoken:e.timetoken};return t.error&&(s.error=t.error),e.meta&&(s.meta=e.meta),s})),startTimeToken:n,endTimeToken:r}:{messages:[],startTimeToken:n,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${G(t)}`}get queryParameters(){const{start:e,end:t,reverse:s,count:n,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:n,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=s?{reverse:s.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:s}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let n,r;try{const s=t.decrypt(e);n=s instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(s)):s}catch(t){s&&console.log("decryption error",t.message),n=e,r=`Error while decrypting message content: ${t.message}`}return{payload:n,error:r}}}var Ft;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ft||(Ft={}));class Tt extends te{constructor(e){var t,s,n,r,i;super(),this.parameters=e;const o=null!==(t=e.includeMessageActions)&&void 0!==t&&t,a=e.channels.length>1||o?25:100;e.count?e.count=Math.min(e.count,a):e.count=a,e.includeUuid?e.includeUUID=e.includeUuid:null!==(s=e.includeUUID)&&void 0!==s||(e.includeUUID=true),null!==(n=e.stringifiedTimeToken)&&void 0!==n||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ne.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return e?t?void 0!==s&&s&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const s=this.deserializeResponse(e);if(!s)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(s.status>=400)throw _.create(e);const n=null!==(t=s.channels)&&void 0!==t?t:{},r={};return Object.keys(n).forEach((e=>{r[e]=n[e].map((t=>{null===t.message_type&&(t.message_type=Ft.Message);const s=this.processPayload(e,t),n=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:s.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=n;e.actions=t.actions,e.data=t.actions}return t.meta&&(n.meta=t.meta),s.error&&(n.error=s.error),n}))})),s.more?{channels:r,more:s.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:s}=this.parameters;return`/v3/${s?"history-with-actions":"history"}/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,count:s,includeCustomMessageType:n,includeMessageType:r,includeMeta:i,includeUUID:o,stringifiedTimeToken:a}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:s},e?{start:e}:{}),t?{end:t}:{}),a?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),o?{include_uuid:"true"}:{}),null!=n?{include_custom_message_type:n?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:s,logVerbosity:n}=this.parameters;if(!s||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=s.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Tt.decoder.decode(e)):e}catch(e){n&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ft.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Ut extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);let s=null,n=null;return t.data.length>0&&(s=t.data[0].actionTimetoken,n=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:s,end:n}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}`}get queryParameters(){const{limit:e,start:t,end:s}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),s?{end:s}:{}),e?{limit:e}:{})}}class xt extends te{constructor(e){super({method:q.POST}),this.parameters=e}operation(){return ne.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:s,messageTimetoken:n}=this.parameters;return e?s?n?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}/message/${s}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Dt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:s,actionTimetoken:n}=this.parameters;return e?t?s?n?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{data:t.data}}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:s,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${G(t)}/message/${n}/action/${s}`}}class qt extends te{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).storeInHistory)&&void 0!==t||(s.storeInHistory=true)}operation(){return ne.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:s,subscribeKey:n},fileId:r,fileName:i}=this.parameters,o=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${s}/${n}/0/${G(t)}/0/${G(this.prepareMessagePayload(o))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:s,meta:n}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),s?{ttl:s}:{}),n&&"object"==typeof n?{meta:JSON.stringify(n)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const s=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof s?s:u(s))}}class Gt extends te{constructor(e){super({method:q.LOCAL}),this.parameters=e}operation(){return ne.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:s,keySet:{subscribeKey:n}}=this.parameters;return`/v1/files/${n}/channels/${G(e)}/files/${t}/${s}`}}class Kt extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},id:t,channel:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${G(s)}/files/${t}/${n}`}}class $t extends te{constructor(e){var t,s;super(),this.parameters=e,null!==(t=(s=this.parameters).limit)&&void 0!==t||(s.limit=100)}operation(){return ne.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Lt extends te{constructor(e){super({method:q.POST}),this.parameters=e}operation(){return ne.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Bt extends te{constructor(e){super({method:q.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ne.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:s,uploadUrl:n}=this.parameters;return e?t?s?n?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Bt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Ht{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((s=>(e=s.name,t=s.id,this.uploadFile(s)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ne.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ne.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Lt(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:s,crypto:n,cryptography:r}=this.parameters,{id:i,name:o,url:a,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&n?this.file=yield n.encryptFile(this.file,s):t&&r&&(this.file=yield r.encryptFile(t,this.file,s))),this.parameters.sendRequest(new Bt({fileId:i,fileName:o,file:this.file,uploadUrl:a,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i;let o,a={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{a=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(o=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:a.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(n=null===(s=o.status)||void 0===s?void 0:s.category)&&void 0!==n?n:h.PNUnknownCategory,statusCode:null!==(i=null===(r=o.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),s=this.groupNames.filter((e=>!t.includes(e))),n=this.channelNames.filter((t=>!e.includes(t)));0===n.length&&0===s.length||this.pubnub.unsubscribe({channels:n,channelGroups:s})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Vt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=s,this.eventEmitter=n,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,s)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,s=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!s.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,s)}get subscriptions(){return this.subscriptionList.slice(0)}}class Wt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:s,eventEmitter:n,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=s,this.pubnub=r,this.eventEmitter=n,this.listener={},n.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Vt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Jt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Xt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Qt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.id=e}subscription(e){return new Wt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,s){this.eventEmitter=t,this.pubnub=s,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Wt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class es extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:s}=this.parameters;return e?s?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class ts extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{channels:t.payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}`}}class ss extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${G(t)}/remove`}}class ns extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return{groups:t.payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class rs{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new ts(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new ns({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new es(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const s=new ss(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class is extends te{constructor(e){var t,s;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(s=this.parameters).environment)&&void 0!==t||(s.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;return e?s?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?n?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){throw Error("Should be implemented in subclass.")}))}get path(){const{keySet:{subscribeKey:e},action:t,device:s,pushGateway:n}=this.parameters;let r="apns2"===n?`/v2/push/sub-key/${e}/devices-apns2/${s}`:`/v1/push/sub-key/${e}/devices/${s}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let s=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(s[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;s=Object.assign(Object.assign({},s),{environment:e,topic:t})}return s}}class os extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ne.PNRemovePushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class as extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ne.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{channels:t}}))}}class cs extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ne.PNAddPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class us extends is{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ne.PNRemoveAllPushNotificationsOperation}parse(e){return i(this,void 0,void 0,(function*(){if(!this.deserializeResponse(e))throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{}}))}}class ls{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new as(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new cs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const s=new os(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const s=new us(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}}class hs extends te{constructor(e){var t,s,n,r,i,o;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(i=e.include).customFields)&&void 0!==s||(i.customFields=false),null!==(n=(o=e.include).totalCount)&&void 0!==n||(o.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ne.PNGetAllChannelMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ds extends te{constructor(e){super({method:q.DELETE}),this.parameters=e}operation(){return ne.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}}class ps extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gs extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).channelFields)&&void 0!==o||(y.channelFields=false),null!==(a=(f=e.include).customChannelFields)&&void 0!==a||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["channel.status","channel.type","status"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.channelFields&&o.push("channel"),e.channelStatusField&&o.push("channel.status"),e.channelTypeField&&o.push("channel.type"),e.customChannelFields&&o.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class ys extends te{constructor(e){var t,s,n,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(r=e.include).customFields)&&void 0!==s||(r.customFields=false),null!==(n=e.limit)&&void 0!==n||(e.limit=100)}operation(){return ne.PNGetAllUUIDMetadataOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";return i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class fs extends te{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class ms extends te{constructor(e){var t,s,n;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true)}operation(){return ne.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bs extends te{constructor(e){super({method:q.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}}class vs extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=[];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ws extends te{constructor(e){var t,s,n,r,i,o,a,c,u,l,h,d,p,g,y,f,m,b;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(h=e.include).customFields)&&void 0!==s||(h.customFields=false),null!==(n=(d=e.include).totalCount)&&void 0!==n||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(o=(y=e.include).UUIDFields)&&void 0!==o||(y.UUIDFields=false),null!==(a=(f=e.include).customUUIDFields)&&void 0!==a||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ne.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${G(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:s,sort:n,limit:r}=this.parameters;let i="";i="string"==typeof n?n:Object.entries(null!=n?n:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const o=["uuid.status","uuid.type","type"];return e.statusField&&o.push("status"),e.typeField&&o.push("type"),e.customFields&&o.push("custom"),e.UUIDFields&&o.push("uuid"),e.UUIDStatusField&&o.push("uuid.status"),e.UUIDTypeField&&o.push("uuid.type"),e.customUUIDFields&&o.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},o.length>0?{include:o.join(",")}:{}),s?{filter:s}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class Ss extends te{constructor(e){var t,s,n;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class ks extends te{constructor(e){var t,s,n;super({method:q.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(s=(n=e.include).customFields)&&void 0!==s||(n.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ne.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));if(t.status>=400)throw _.create(e);return t}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${G(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Es{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new ys(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new Ss(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new ks(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new bs(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const n=new hs(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new fs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ms(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const s=new ds(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new vs(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const s=new ws(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),n.userId&&(n.uuid=n.userId),null!==(s=n.uuid)&&void 0!==s||(n.uuid=this.configuration.userId);const r=new ps(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s;e.userId&&(e.uuid=e.userId),null!==(s=e.uuid)&&void 0!==s||(e.uuid=this.configuration.userId);const n=new gs(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n;if("spaceId"in e){const n=e,r={channel:null!==(s=n.spaceId)&&void 0!==s?s:n.channel,filter:n.filter,limit:n.limit,page:n.page,include:Object.assign({},n.include),sort:n.sort?Object.fromEntries(Object.entries(n.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,s)=>{t(e,s?i(s):s)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(n=r.userId)&&void 0!==n?n:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},o=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,s)=>{t(e,s?o(s):s)})):this.getMemberships(i).then(o)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r,i,o,a;if("spaceId"in e){const i=e,o={channel:null!==(s=i.spaceId)&&void 0!==s?s:i.channel,uuids:null!==(r=null===(n=i.users)||void 0===n?void 0:n.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(o,t):this.setChannelMembers(o)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(a=null===(o=c.spaces)||void 0===o?void 0:o.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==a?a:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Os extends te{constructor(){super()}operation(){return ne.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);if(!t)throw new d("Service response error, check status for details",p("Unable to deserialize service response"));return{timetoken:t[0]}}))}get path(){return"/time/0"}}class Cs extends te{constructor(e){super(),this.parameters=e}operation(){return ne.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:s}=this.parameters;return e?t?s?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:s,cryptography:n,name:r,PubNubFile:i}=this.parameters,o=e.headers["content-type"];let a,c=e.body;return i.supportsEncryptFile&&(t||s)&&(t&&n?c=yield n.decrypt(t,c):!t&&s&&(a=yield s.decryptFile(i.create({data:c,name:r,mimeType:o}),i))),a||i.create({data:c,name:r,mimeType:o})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:s,name:n}=this.parameters;return`/v1/files/${e}/channels/${G(t)}/files/${s}/${n}`}}class Ns{static notificationPayload(e,t){return new ee(e,t)}static generateUUID(){return T.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Es(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new rs(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new ls(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new V,this.eventEmitter=new ae(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Ke({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,s)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):s(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new wt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new X(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Yt(e,this.eventEmitter,this)}channelGroup(e){return new Xt(e,this.eventEmitter,this)}channelMetadata(e){return new Jt(e,this.eventEmitter,this)}userMetadata(e){return new Qt(e,this.eventEmitter,this)}subscriptionSet(e){return new Vt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const s=e.validate();if(s){if(t)return t(p(s),null);throw new d("Validation failed, check status for details",p(s))}const n=e.request(),r=e.operation();n.formData&&n.formData.length>0||r===ne.PNDownloadFileOperation?n.timeout=this._configuration.getFileTimeout():r===ne.PNSubscribeOperation||r===ne.PNReceiveMessagesOperation?n.timeout=this._configuration.getSubscribeTimeout():n.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[o,a]=this.transport.makeSendable(n);return e.cancellationController=a||null,o.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=t.headers["content-type"];if(e||-1!==e.indexOf("javascript")||-1!==e.indexOf("json")){const e=JSON.parse(Ns.decoder.decode(t.body));"object"==typeof e&&"error"in e&&e.error&&"object"==typeof e.error&&(i.errorData=e.error)}}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const s=e instanceof _?e:_.create(e);if(t)return t(s.toStatus(r),null);throw s.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const s=new St(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const s=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const s=new oe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(s,((e,n)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===s.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,n)})),this.subscriptionManager){const e=()=>s.abort();e.identifier=s.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),s=e.abortSignal.subscribe((e=>{t.abort()}));return this.sendRequest(t).then((e=>(s(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const s=new Ut(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const s=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const s=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const s=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const s=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const s=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new _t({uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var s;{const n=new Ct(Object.assign(Object.assign({},e),{uuid:null!==(s=e.uuid)&&void 0!==s?s:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var s,n;{const{keySet:r,userId:i}=this._configuration,o=this._configuration.getPresenceTimeout();let a;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(s=e.channels)||void 0===s||s.forEach((s=>t[s]=e.state)),"channelGroups"in e&&(null===(n=e.channelGroups)||void 0===n||n.forEach((s=>t[s]=e.state)))}return a="withHeartbeat"in e?new Pt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:o})):new Nt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(a,t):this.sendRequest(a)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const s=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var s,n,r;{if("spaceId"in e){const r=e,i={channel:null!==(s=r.spaceId)&&void 0!==s?s:r.channel,uuids:null!==(n=r.userIds)&&void 0!==n?n:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,o={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(o,t):this.objects.removeMemberships(o)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Ht(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),n={error:!1,operation:ne.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return s.process().then((e=>(n.statusCode=e.status,t?t(n,e):e))).catch((e=>{let s;throw e instanceof d?s=e.status:e instanceof _&&(s=e.toStatus(n.operation)),t&&s&&t(s,null),new d("REST API request processing error, check status for details",s)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const s=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getFileUrl(e){var t;{const s=this.transport.request(new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),n=null!==(t=s.queryParameters)&&void 0!==t?t:{},r=Object.keys(n).map((e=>{const t=n[e];return Array.isArray(t)?t.map((t=>`${e}=${G(t)}`)).join("&"):`${e}=${G(t)}`})).join("&");return`${s.origin}${s.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const s=new Cs(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(s,t):yield this.sendRequest(s)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const s=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Os;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s&&"string"==typeof e){const t=s.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const s=this._configuration.getCryptoModule();if(!t&&s){const t=s.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var s;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(s=this._configuration.getCryptoModule())||void 0===s?void 0:s.decryptFile(t,this._configuration.PubNubFile)}))}}Ns.decoder=new TextDecoder,Ns.OPERATIONS=ne,Ns.CATEGORIES=h,Ns.ExponentialRetryPolicy=$e.ExponentialRetryPolicy,Ns.LinearRetryPolicy=$e.LinearRetryPolicy;class Ps{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const s=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,n=this.decode(this.base64ToBinary(s));return"object"==typeof n?n:void 0}}class Ms extends Ns{constructor(e){var t;const s=I(e),r=Object.assign(Object.assign({},s),{sdkFamily:"Web"});r.PubNubFile=a;const i=U(r,(e=>{if(e.cipherKey)return new N({default:new C(Object.assign({},e)),cryptors:[new S({cipherKey:e.cipherKey})]})}));let o,u,l;o=new D(new Ps((e=>j(n.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new E({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new O;let h=new z(r.transport,i.keepAlive,i.logVerbosity);s.subscriptionWorkerUrl&&(h=new A({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:s.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new H({clientConfiguration:i,tokenManager:o,transport:h}),cryptography:l,tokenManager:o,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return Ms.CryptoModule=N,Ms})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var E=new Uint8Array(S),O=0;for(r=0;r=0;)f(k,d);else f(k,d);return String.fromCharCode.apply(null,k);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,m,b,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],E=e[i+14],O=e[i+15],k=t(k=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,k,P,N,o,12,u[1]),N=t(N,C,k,P,l,17,u[2]),P=t(P,N,C,k,h,22,u[3]);k=t(k,P,N,C,d,7,u[4]),C=t(C,k,P,N,p,12,u[5]),N=t(N,C,k,P,g,17,u[6]),P=t(P,N,C,k,y,22,u[7]),k=t(k,P,N,C,f,7,u[8]),C=t(C,k,P,N,m,12,u[9]),N=t(N,C,k,P,b,17,u[10]),P=t(P,N,C,k,v,22,u[11]),k=t(k,P,N,C,w,7,u[12]),C=t(C,k,P,N,S,12,u[13]),N=t(N,C,k,P,E,17,u[14]),k=n(k,P=t(P,N,C,k,O,22,u[15]),N,C,o,5,u[16]),C=n(C,k,P,N,g,9,u[17]),N=n(N,C,k,P,v,14,u[18]),P=n(P,N,C,k,c,20,u[19]),k=n(k,P,N,C,p,5,u[20]),C=n(C,k,P,N,b,9,u[21]),N=n(N,C,k,P,O,14,u[22]),P=n(P,N,C,k,d,20,u[23]),k=n(k,P,N,C,m,5,u[24]),C=n(C,k,P,N,E,9,u[25]),N=n(N,C,k,P,h,14,u[26]),P=n(P,N,C,k,f,20,u[27]),k=n(k,P,N,C,S,5,u[28]),C=n(C,k,P,N,l,9,u[29]),N=n(N,C,k,P,y,14,u[30]),k=s(k,P=n(P,N,C,k,w,20,u[31]),N,C,p,4,u[32]),C=s(C,k,P,N,f,11,u[33]),N=s(N,C,k,P,v,16,u[34]),P=s(P,N,C,k,E,23,u[35]),k=s(k,P,N,C,o,4,u[36]),C=s(C,k,P,N,d,11,u[37]),N=s(N,C,k,P,y,16,u[38]),P=s(P,N,C,k,b,23,u[39]),k=s(k,P,N,C,S,4,u[40]),C=s(C,k,P,N,c,11,u[41]),N=s(N,C,k,P,h,16,u[42]),P=s(P,N,C,k,g,23,u[43]),k=s(k,P,N,C,m,4,u[44]),C=s(C,k,P,N,w,11,u[45]),N=s(N,C,k,P,O,16,u[46]),k=r(k,P=s(P,N,C,k,l,23,u[47]),N,C,c,6,u[48]),C=r(C,k,P,N,y,10,u[49]),N=r(N,C,k,P,E,15,u[50]),P=r(P,N,C,k,p,21,u[51]),k=r(k,P,N,C,w,6,u[52]),C=r(C,k,P,N,h,10,u[53]),N=r(N,C,k,P,b,15,u[54]),P=r(P,N,C,k,o,21,u[55]),k=r(k,P,N,C,f,6,u[56]),C=r(C,k,P,N,O,10,u[57]),N=r(N,C,k,P,g,15,u[58]),P=r(P,N,C,k,S,21,u[59]),k=r(k,P,N,C,d,6,u[60]),C=r(C,k,P,N,v,10,u[61]),N=r(N,C,k,P,l,15,u[62]),P=r(P,N,C,k,m,21,u[63]);a[0]=a[0]+k|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;s[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],E=257*p[m]^16843008*m;i[y]=E<<24|E>>>8,a[y]=E<<16|E>>>16,o[y]=E<<8|E>>>24,c[y]=E,E=16843009*w^65537*v^257*b^16843008*y,u[m]=E<<24|E>>>8,l[m]=E<<16|E>>>16,h[m]=E<<8|E>>>24,d[m]=E,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],m=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=m}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],m=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var E=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=_.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=_.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==_.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(s),a)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";class j extends Error{static create(e,t){return e instanceof Error?j.createFromError(e):j.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new j(n,t,0);if(e instanceof j)return e;if(e instanceof Error&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new j(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new j(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.scheduleEventPost(n)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(j.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new j(s,e,0,new Error(s)))}}}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,E=!1,O=100,k=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(E=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(O=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(k=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:k,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(n=e.subscriptionWorkerLogVerbosity)&&void 0!==n&&n,transport:null!==(s=e.transport)&&void 0!==s?s:"fetch",keepAlive:null===(r=e.keepAlive)||void 0===r||r})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.9.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class G{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var K;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(K||(K={}));const $=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),L=(e,t)=>{const n=e.map((e=>$(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?K.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===K.POST||t===K.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${$(e)}`)).join("&"):`${t}=${$(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class z{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class W{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(W.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(W.originalFetch=W.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(W.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw j.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();n.includes("timeout")||!n.includes("cancel")?t=new Error(e):n.includes("cancel")&&(t=new DOMException("Aborted","AbortError"))}throw j.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([W.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${W.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${W.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}W.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;if(e.category===h.PNTimeoutCategory)this.startSubscribeLoop();else if(e.category===h.PNNetworkIssuesCategory)this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e);else if(e.category===h.PNBadRequestCategory||e.category==h.PNMalformedResponseCategory){const t=this.isOnline?h.PNDisconnectedUnexpectedlyCategory:e.category;this.isOnline=!1,this.disconnect(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:t}))}else this.listenerManager.announceStatus(e);return}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:K.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===K.POST||r.method===K.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw j.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n){t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const n=this.channelListenerMap.get(t);n.includes(e)||n.push(e)}else this.channelListenerMap.set(t,[e])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){const n=this.groupListenerMap.get(t);n.includes(e)||n.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,n){t&&n?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==n||n.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class me extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class be extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new me}abort(){this._aborted=!0,this.notify(new me)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new be}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),Ee=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),ke=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),_e=ge("HEARTBEAT_GIVEUP",(()=>({}))),Ae=ge("TIMES_UP",(()=>({}))),je=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Ae())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(_e());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(ke.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(Ee.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(Ae.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(Ee.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARBEAT_RECONNECTING");Ge.onEnter((e=>Re(e))),Ge.onExit((()=>Re.cancel)),Ge.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ge.on(_e.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEATING");Ke.onEnter((e=>je(e.channels,e.groups))),Ke.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ke.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ke.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(ke.type,((e,t)=>Ke.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),ze=ye("EMIT_MESSAGES",(e=>e)),We=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const mt=new he("RECEIVE_RECONNECTING");mt.onEnter((e=>Je(e))),mt.onExit((()=>Je.cancel)),mt.on(at.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(ot.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:h.PNDisconnectedCategory})]))),mt.on(Ye.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(ht.type,(e=>St.with(void 0,[We({category:h.PNDisconnectedCategory})])));const bt=new he("RECEIVING");bt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),bt.onExit((()=>Ve.cancel)),bt.on(rt.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),bt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),bt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(it.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:h.PNDisconnectedCategory})]))),bt.on(ht.type,(e=>St.with(void 0,[We({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return bt.with({channels:e.channels,groups:e.groups,cursor:r},[We({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[We({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class Et{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?K.POST:K.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${$(t)}/0${this.parameters.sendByPost?"":`/${$(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${$(n)}/0/${$(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${$(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class At extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class jt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${$(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${L(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${L(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${L(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Gt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${s}/action/${n}`}}class Kt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${$(t)}/0/${$(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class $t extends se{constructor(e){super({method:K.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${$(e)}/files/${t}/${n}`}}class Lt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:K.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof j?e:j.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Wt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends Wt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,n)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,n)}get subscriptions(){return this.subscriptionList.slice(0)}}class Xt extends Wt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class mn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class bn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class kn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new bn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new kn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files/${n}/${s}`}}class _n{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new Et({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=_n.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof j?e:j.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new jt({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new _t(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const n=new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof j&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}_n.decoder=new TextDecoder,_n.OPERATIONS=ie,_n.CATEGORIES=h,_n.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,_n.LinearRetryPolicy=Be.LinearRetryPolicy;class An{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class jn extends _n{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new G(new An((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new W(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new z({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return jn.CryptoModule=M,jn})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index b3a5f56b5..0c5b6a43b 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -547,7 +547,15 @@ const clients = getClients(); if (clients.length === 0) return; - failure(clients, error); + let fetchError = error; + if (typeof error === 'string') { + const errorMessage = error.toLowerCase(); + if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) + fetchError = new Error(error); + else if (errorMessage.includes('cancel')) + fetchError = new DOMException('Aborted', 'AbortError'); + } + failure(clients, fetchError); }); }))(); }; @@ -564,7 +572,7 @@ delete serviceRequests[requestId]; // Abort request if possible. if (controller) - controller.abort(); + controller.abort('Cancel request'); } }; /** @@ -1081,12 +1089,12 @@ message = error.message; name = error.name; } - if (name === 'AbortError') { + if (message.toLowerCase().includes('timeout')) + type = 'TIMEOUT'; + else if (name === 'AbortError' || message.toLowerCase().includes('cancel')) { message = 'Request aborted'; type = 'ABORTED'; } - else if (message === 'Request timeout') - type = 'TIMEOUT'; return { type: 'request-process-error', clientIdentifier: '', diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index 9c9f4f1cd..494438463 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ -!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{u(r.next(e))}catch(e){s(e)}}function c(e){try{u(r.throw(e))}catch(e){s(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}u((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,r,i={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=i,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(r=i.exports),null!==n&&(n.exports=r.uuid);var s=t(i.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=1e4,u=new Map,l=new TextDecoder;let a,d=!1;const h=o.createUUID(),p=new Map,f={},b={},g={},v={},y={},q={};self.onconnect=e=>{ee("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)!d&&n.workerLogVerbosity&&(d=!0),n.port=e,U(n),ee(`Client '${n.clientIdentifier}' registered with '${h}' shared worker`);else if("client-pong"===n.type)V(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){L(n);const e=f[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!u.has(t)){const e=setTimeout((()=>{I(n),u.delete(t)}),50);u.set(t,e)}}}else n.request.path.endsWith("/heartbeat")?(N(n),j(n)):O(n);else"cancel-request"===n.type&&$(n)},e.postMessage({type:"shared-worker-connected"})}))};const I=e=>{var t;const n=R(e),r=f[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),F("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=q[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),u=new Response(o,{status:200,headers:c}),l=C([u,o]);l.url=`${e.request.origin}${e.request.path}`,l.clientIdentifier=e.clientIdentifier,l.identifier=e.request.identifier,F("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),A(r,l)}return}e.request.cancellable&&p.set(n.identifier,new AbortController);const s=q[n.identifier],{timetokenOverride:o,regionOverride:c}=s;S(n,(()=>G(n.identifier)),((t,r)=>{W(t,r,e.request),T(t,n.identifier)}),((t,r)=>{W(t,null,e.request,D(r)),T(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(q[n.identifier],t=m(t,o,c)),t})),ee(`'${Object.keys(q).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ee(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ee(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},j=e=>{var t;const n=f[e.clientIdentifier],r=K(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=g[n.subscriptionKey],o=(null!=s?s:{})[i];if(F("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ee(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=C([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,F("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}S(r,(()=>[n]),((t,n)=>{o&&(o.response=n),W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),ee("Started heartbeat request.",n)},O=e=>{const t=f[e.clientIdentifier],n=x(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=C([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(S(n,(()=>[t]),((t,n)=>{W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),ee("Started leave request.",t),void 0===i)return;const s=G(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),w(s)},$=e=>{const t=f[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},w=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&I({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},S=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(E(t),{signal:null===(e=p.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),P(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(F("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();0!==t.length&&i(t,e)}))}))},k=e=>{if(0===G(e).length){const t=p.get(e);p.delete(e),delete q[e],t&&t.abort()}},P=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{p.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),G=e=>Object.values(f).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),T=(e,t)=>{delete q[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},E=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ne(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},R=e=>{var t,n,r,i,s;const c=f[e.clientIdentifier],u=c.subscription,l=Q(u.timetoken,e),a=o.createUUID(),h=Object.assign({},e.request);let p,b;if(l.length>1){const s=_(l,e);if(s){const e=q[s],{channels:n,channelGroups:r}=null!==(t=c.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Y(e.channels,n))&&(!(r.length>0)||Y(e.channelGroups,r)))return s}const o=(null!==(n=v[c.subscriptionKey])&&void 0!==n?n:{})[c.userId],d={},f=new Set(u.channelGroups),g=new Set(u.channels);o&&u.objectsWithState.length&&u.objectsWithState.forEach((e=>{const t=o[e];t&&(d[e]=t)}));for(const e of l){const{subscription:t}=e;if(!t)continue;1!==l.length&&e.clientIdentifier===c.clientIdentifier||!t.timetoken||(p=t.timetoken,b=t.region),t.channelGroups.forEach(f.add,f),t.channels.forEach(g.add,g);const n=t.serviceRequestId;t.serviceRequestId=a,n&&q[n]&&k(n),o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!d[e]&&(d[e]=t)}))}const y=null!==(r=q[a])&&void 0!==r?r:q[a]={requestId:a,timetoken:null!==(i=h.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(g.size){y.channels=Array.from(g).sort();const e=h.path.split("/");e[4]=y.channels.join(","),h.path=e.join("/")}f.size&&(y.channelGroups=Array.from(f).sort(),h.queryParameters["channel-group"]=y.channelGroups.join(",")),Object.keys(d).length&&(h.queryParameters.state=JSON.stringify(d))}else q[a]={requestId:a,timetoken:null!==(s=h.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:u.channelGroups,channels:u.channels};if(q[a]&&(h.queryParameters&&void 0!==h.queryParameters.tt&&void 0!==h.queryParameters.tr&&(q[a].region=h.queryParameters.tr),q[a].timetokenOverride=p,q[a].regionOverride=b),u.serviceRequestId=a,h.identifier=a,d){const e=l.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");te(q[a],`Started aggregated request for clients: ${e}`)}return h},K=e=>{var t,n,r,i,s;const o=f[e.clientIdentifier],c=B(e),u=Object.assign({},e.request);if(!o||!o.heartbeat)return;const l=null!==(t=g[s=o.subscriptionKey])&&void 0!==t?t:g[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,h=o.heartbeat.channels;let p={},b=!1,v=!0;if(l[a]){const{channels:e,channelGroups:t,response:n}=l[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},v=Y(e,o.heartbeat.channels)&&Y(t,o.heartbeat.channelGroups),n&&(b=n[0].status>=400)}else l[a]={channels:h,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},v=!1;if(v){const t=l[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!b&&n5e3)return;delete l[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),h.push(...n.channels.filter((e=>!h.includes(e)))))}}l[a].channels=h,l[a].channelGroups=d,l[a].timestamp=Date.now();for(const e in Object.keys(p))h.includes(e)||d.includes(e)||delete p[e];if(h.length){const e=u.path.split("/");e[6]=h.join(","),u.path=e.join("/")}return d.length&&(u.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?u.queryParameters.state=JSON.stringify(p):delete u.queryParameters.state,u},x=e=>{const t=f[e.clientIdentifier],n=H(e);let r=X(e.request),i=z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(d&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");ee(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(e){}return!1},F=(e,t,n,r,i,s,o)=>{var c,u;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let h;if("start"===e)h={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=l.decode(i)),h={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(u=e.subscription)&&void 0!==u?u:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},h),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},W=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},c=n&&n.path.startsWith("/v2/subscribe");!r&&t&&(r=t[0].status>=400?D(void 0,t):C(t));for(const t of e){if(c&&!t.subscription)continue;const e=o[t.clientIdentifier],{request:i}=null!==(s=t.subscription)&&void 0!==s?s:{};let u=null!=i?i:n;if(c||(u=n),e&&u){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:u.identifier,url:`${u.origin}${u.path}`});A(t,e)}}},C=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},C(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";return e&&e instanceof Error&&(r=e.message,i=e.name),"AbortError"===i?(r="Request aborted",n="ABORTED"):"Request timeout"===r&&(n="TIMEOUT"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},U=e=>{var t,n,r,i;const{clientIdentifier:s}=e;if(f[s])return;const o=f[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity},u=null!==(t=b[r=e.subscriptionKey])&&void 0!==t?t:b[r]=[];u.every((e=>e.clientIdentifier!==s))&&u.push(o),(null!==(n=y[i=e.subscriptionKey])&&void 0!==n?n:y[i]={})[s]=e.port,ee(`Registered PubNub client with '${s}' identifier. '${Object.keys(f).length}' clients currently active.`),!a&&Object.keys(f).length>0&&(ee("Setup PubNub client ping event 10 seconds"),a=setInterval((()=>Z()),c))},L=e=>{var t,n,r,i,s,o,c,u,l,a,d,h,p,b,g,y,q,I,m,j;const O=e.request.queryParameters,{clientIdentifier:$}=e,w=f[$];if(!w)return;const S=null!==(t=O["channel-group"])&&void 0!==t?t:"",k=null!==(n=O.state)&&void 0!==n?n:"";let P=w.subscription;if(P){if(k.length>0){const e=JSON.parse(k),t=null!==(o=(y=null!==(s=v[g=w.subscriptionKey])&&void 0!==s?s:v[g]={})[q=w.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of P.objectsWithState)e[n]||delete t[n];P.objectsWithState=Object.keys(e)}else if(P.objectsWithState.length){const e=null!==(u=(m=null!==(c=v[I=w.subscriptionKey])&&void 0!==c?c:v[I]={})[j=w.userId])&&void 0!==u?u:m[j]={};for(const t of P.objectsWithState)delete e[t];P.objectsWithState=[]}}else{if(P={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},k.length>0){const e=JSON.parse(k),t=null!==(i=(p=null!==(r=v[h=w.subscriptionKey])&&void 0!==r?r:v[h]={})[b=w.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),P.objectsWithState=Object.keys(e)}w.subscription=P}P.path!==e.request.path&&(P.path=e.request.path,P.channels=z(e.request)),P.channelGroupQuery!==S&&(P.channelGroupQuery=S,P.channelGroups=X(e.request));const{authKey:G,userId:T}=w;P.request=e.request,P.filterExpression=null!==(l=O["filter-expr"])&&void 0!==l?l:"",P.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(P.region=O.tr),w.authKey=null!==(d=O.auth)&&void 0!==d?d:"",w.userId=O.uuid,M(w,T,G)},N=e=>{var t,n;const r=f[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=X(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=g[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},V=e=>{const t=f[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},_=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=f[t.clientIdentifier],u=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ee(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${u}' request completion.`,c),e.serviceRequestId;{const r=q[e.serviceRequestId];if(s||(s=X(t.request)),o||(o=z(t.request)),o.length&&!Y(r.channels,o))continue;if(s.length&&!Y(r.channelGroups,s))continue;return te(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${u}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${u}' request completion.`,c),e.serviceRequestId}}},Q=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",u=s.uuid;return(null!==(i=b[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===u&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>H(e),H=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=b[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},X=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Y=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},Z=()=>{ee("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(f).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(ee(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>5)&&(n=!0,ee(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete f[t];let n=b[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?b[e]=n:(delete b[e],delete g[e]),0===n.length&&delete v[e],n.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];ee(`Invalidate '${t}' client. '${Object.keys(f).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(ee(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,A(t,e))})),0===Object.keys(f).length&&a&&clearInterval(a)},ee=(e,t)=>{if(!d)return;const n=t?[t]:Object.values(f),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},te=(e,t,n)=>{if(!d)return;const r=n?[n]:Object.values(f),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},ne=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${re(e)}`)).join("&"):`${t}=${re(n)}`})).join("&"),re=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,r,i={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=i,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(r=i.exports),null!==n&&(n.exports=r.uuid);var s=t(i.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=1e4,l=new Map,u=new TextDecoder;let a,d=!1;const h=o.createUUID(),p=new Map,f={},b={},g={},v={},y={},q={};self.onconnect=e=>{ee("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)!d&&n.workerLogVerbosity&&(d=!0),n.port=e,U(n),ee(`Client '${n.clientIdentifier}' registered with '${h}' shared worker`);else if("client-pong"===n.type)V(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){L(n);const e=f[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!l.has(t)){const e=setTimeout((()=>{I(n),l.delete(t)}),50);l.set(t,e)}}}else n.request.path.endsWith("/heartbeat")?(N(n),w(n)):j(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const I=e=>{var t;const n=A(e),r=f[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),C("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=q[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=D([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,C("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),R(r,u)}return}e.request.cancellable&&p.set(n.identifier,new AbortController);const s=q[n.identifier],{timetokenOverride:o,regionOverride:c}=s;S(n,(()=>E(n.identifier)),((t,r)=>{F(t,r,e.request),G(t,n.identifier)}),((t,r)=>{F(t,null,e.request,W(r)),G(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(q[n.identifier],t=m(t,o,c)),t})),ee(`'${Object.keys(q).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ee(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ee(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},w=e=>{var t;const n=f[e.clientIdentifier],r=x(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=g[n.subscriptionKey],o=(null!=s?s:{})[i];if(C("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ee(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=D([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,C("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void R(n,i)}S(r,(()=>[n]),((t,n)=>{o&&(o.response=n),F(t,n,e.request)}),((t,n)=>{F(t,null,e.request,W(n))})),ee("Started heartbeat request.",n)},j=e=>{const t=f[e.clientIdentifier],n=K(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=D([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void R(t,s)}if(S(n,(()=>[t]),((t,n)=>{F(t,n,e.request)}),((t,n)=>{F(t,null,e.request,W(n))})),ee("Started leave request.",t),void 0===i)return;const s=E(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),$(s)},O=e=>{const t=f[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},$=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&I({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},S=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(T(t),{signal:null===(e=p.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),P(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(C("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();t.includes("timeout")||!t.includes("cancel")?r=new Error(e):t.includes("cancel")&&(r=new DOMException("Aborted","AbortError"))}i(t,r)}))}))},k=e=>{if(0===E(e).length){const t=p.get(e);p.delete(e),delete q[e],t&&t.abort("Cancel request")}},P=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{p.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),E=e=>Object.values(f).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),G=(e,t)=>{delete q[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},T=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ne(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},A=e=>{var t,n,r,i,s;const c=f[e.clientIdentifier],l=c.subscription,u=Q(l.timetoken,e),a=o.createUUID(),h=Object.assign({},e.request);let p,b;if(u.length>1){const s=_(u,e);if(s){const e=q[s],{channels:n,channelGroups:r}=null!==(t=c.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Y(e.channels,n))&&(!(r.length>0)||Y(e.channelGroups,r)))return s}const o=(null!==(n=v[c.subscriptionKey])&&void 0!==n?n:{})[c.userId],d={},f=new Set(l.channelGroups),g=new Set(l.channels);o&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=o[e];t&&(d[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===c.clientIdentifier||!t.timetoken||(p=t.timetoken,b=t.region),t.channelGroups.forEach(f.add,f),t.channels.forEach(g.add,g);const n=t.serviceRequestId;t.serviceRequestId=a,n&&q[n]&&k(n),o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!d[e]&&(d[e]=t)}))}const y=null!==(r=q[a])&&void 0!==r?r:q[a]={requestId:a,timetoken:null!==(i=h.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(g.size){y.channels=Array.from(g).sort();const e=h.path.split("/");e[4]=y.channels.join(","),h.path=e.join("/")}f.size&&(y.channelGroups=Array.from(f).sort(),h.queryParameters["channel-group"]=y.channelGroups.join(",")),Object.keys(d).length&&(h.queryParameters.state=JSON.stringify(d))}else q[a]={requestId:a,timetoken:null!==(s=h.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};if(q[a]&&(h.queryParameters&&void 0!==h.queryParameters.tt&&void 0!==h.queryParameters.tr&&(q[a].region=h.queryParameters.tr),q[a].timetokenOverride=p,q[a].regionOverride=b),l.serviceRequestId=a,h.identifier=a,d){const e=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");te(q[a],`Started aggregated request for clients: ${e}`)}return h},x=e=>{var t,n,r,i,s;const o=f[e.clientIdentifier],c=B(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=g[s=o.subscriptionKey])&&void 0!==t?t:g[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,h=o.heartbeat.channels;let p={},b=!1,v=!0;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},v=Y(e,o.heartbeat.channels)&&Y(t,o.heartbeat.channelGroups),n&&(b=n[0].status>=400)}else u[a]={channels:h,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},v=!1;if(v){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!b&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),h.push(...n.channels.filter((e=>!h.includes(e)))))}}u[a].channels=h,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))h.includes(e)||d.includes(e)||delete p[e];if(h.length){const e=l.path.split("/");e[6]=h.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},K=e=>{const t=f[e.clientIdentifier],n=H(e);let r=X(e.request),i=z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(d&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");ee(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},R=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(e){}return!1},C=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let h;if("start"===e)h={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),h={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},h),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});R(e,t)}}},F=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},c=n&&n.path.startsWith("/v2/subscribe");!r&&t&&(r=t[0].status>=400?W(void 0,t):D(t));for(const t of e){if(c&&!t.subscription)continue;const e=o[t.clientIdentifier],{request:i}=null!==(s=t.subscription)&&void 0!==s?s:{};let l=null!=i?i:n;if(c||(l=n),e&&l){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:l.identifier,url:`${l.origin}${l.path}`});R(t,e)}}},D=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},W=(e,t)=>{if(t)return Object.assign(Object.assign({},D(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";return e&&e instanceof Error&&(r=e.message,i=e.name),r.toLowerCase().includes("timeout")?n="TIMEOUT":("AbortError"===i||r.toLowerCase().includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},U=e=>{var t,n,r,i;const{clientIdentifier:s}=e;if(f[s])return;const o=f[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity},l=null!==(t=b[r=e.subscriptionKey])&&void 0!==t?t:b[r]=[];l.every((e=>e.clientIdentifier!==s))&&l.push(o),(null!==(n=y[i=e.subscriptionKey])&&void 0!==n?n:y[i]={})[s]=e.port,ee(`Registered PubNub client with '${s}' identifier. '${Object.keys(f).length}' clients currently active.`),!a&&Object.keys(f).length>0&&(ee("Setup PubNub client ping event 10 seconds"),a=setInterval((()=>Z()),c))},L=e=>{var t,n,r,i,s,o,c,l,u,a,d,h,p,b,g,y,q,I,m,w;const j=e.request.queryParameters,{clientIdentifier:O}=e,$=f[O];if(!$)return;const S=null!==(t=j["channel-group"])&&void 0!==t?t:"",k=null!==(n=j.state)&&void 0!==n?n:"";let P=$.subscription;if(P){if(k.length>0){const e=JSON.parse(k),t=null!==(o=(y=null!==(s=v[g=$.subscriptionKey])&&void 0!==s?s:v[g]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of P.objectsWithState)e[n]||delete t[n];P.objectsWithState=Object.keys(e)}else if(P.objectsWithState.length){const e=null!==(l=(m=null!==(c=v[I=$.subscriptionKey])&&void 0!==c?c:v[I]={})[w=$.userId])&&void 0!==l?l:m[w]={};for(const t of P.objectsWithState)delete e[t];P.objectsWithState=[]}}else{if(P={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},k.length>0){const e=JSON.parse(k),t=null!==(i=(p=null!==(r=v[h=$.subscriptionKey])&&void 0!==r?r:v[h]={})[b=$.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),P.objectsWithState=Object.keys(e)}$.subscription=P}P.path!==e.request.path&&(P.path=e.request.path,P.channels=z(e.request)),P.channelGroupQuery!==S&&(P.channelGroupQuery=S,P.channelGroups=X(e.request));const{authKey:E,userId:G}=$;P.request=e.request,P.filterExpression=null!==(u=j["filter-expr"])&&void 0!==u?u:"",P.timetoken=null!==(a=j.tt)&&void 0!==a?a:"0",void 0!==j.tr&&(P.region=j.tr),$.authKey=null!==(d=j.auth)&&void 0!==d?d:"",$.userId=j.uuid,M($,G,E)},N=e=>{var t,n;const r=f[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=X(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=g[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},V=e=>{const t=f[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},_=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=f[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ee(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=q[e.serviceRequestId];if(s||(s=X(t.request)),o||(o=z(t.request)),o.length&&!Y(r.channels,o))continue;if(s.length&&!Y(r.channelGroups,s))continue;return te(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},Q=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",l=s.uuid;return(null!==(i=b[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>H(e),H=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=b[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},X=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Y=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},Z=()=>{ee("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(f).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(ee(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>5)&&(n=!0,ee(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete f[t];let n=b[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?b[e]=n:(delete b[e],delete g[e]),0===n.length&&delete v[e],n.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];ee(`Invalidate '${t}' client. '${Object.keys(f).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(ee(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,R(t,e))})),0===Object.keys(f).length&&a&&clearInterval(a)},ee=(e,t)=>{if(!d)return;const n=t?[t]:Object.values(f),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&R(e,r)}))},te=(e,t,n)=>{if(!d)return;const r=n?[n]:Object.values(f),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&R(e,i)}))},ne=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${re(e)}`)).join("&"):`${t}=${re(n)}`})).join("&"),re=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 7a695af9e..3340b856d 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.8.1'; + return '8.9.0'; }, getVersion() { return this.version; diff --git a/lib/core/components/request.js b/lib/core/components/request.js index b3d050940..8ef292d73 100644 --- a/lib/core/components/request.js +++ b/lib/core/components/request.js @@ -19,6 +19,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractRequest = void 0; const transport_request_1 = require("../types/transport-request"); +const pubnub_error_1 = require("../../errors/pubnub-error"); +const pubnub_api_error_1 = require("../../errors/pubnub-api-error"); const uuid_1 = __importDefault(require("./uuid")); /** * Base REST API request class. @@ -62,10 +64,12 @@ class AbstractRequest { } /** * Abort request if possible. + * + * @param [reason] Information about why request has been cancelled. */ - abort() { + abort(reason) { if (this && this.cancellationController) - this.cancellationController.abort(); + this.cancellationController.abort(reason); } /** * Target REST API endpoint operation type. @@ -84,11 +88,11 @@ class AbstractRequest { /** * Parse service response. * - * @param _response - Raw service response which should be parsed. + * @param response - Raw service response which should be parsed. */ - parse(_response) { + parse(response) { return __awaiter(this, void 0, void 0, function* () { - throw Error('Should be implemented by subclass.'); + return this.deserializeResponse(response); }); } /** @@ -160,21 +164,28 @@ class AbstractRequest { * * @param response - Transparent response object with headers and body information. * - * @returns Deserialized data or `undefined` in case of `JSON.parse(..)` error. + * @returns Deserialized service response data. + * + * @throws {Error} if received service response can't be processed (has unexpected content-type or can't be parsed as + * JSON). */ deserializeResponse(response) { + const responseText = AbstractRequest.decoder.decode(response.body); const contentType = response.headers['content-type']; + let parsedJson; if (!contentType || (contentType.indexOf('javascript') === -1 && contentType.indexOf('json') === -1)) - return undefined; - const json = AbstractRequest.decoder.decode(response.body); + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createMalformedResponseError)(responseText, response.status)); try { - const parsedJson = JSON.parse(json); - return parsedJson; + parsedJson = JSON.parse(responseText); } catch (error) { console.error('Error parsing JSON response:', error); - return undefined; + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createMalformedResponseError)(responseText, response.status)); } + // Throw and exception in case of client / server error. + if ('status' in parsedJson && typeof parsedJson.status === 'number' && parsedJson.status >= 400) + throw pubnub_api_error_1.PubNubAPIError.create(response); + return parsedJson; } } exports.AbstractRequest = AbstractRequest; diff --git a/lib/core/components/subscription-manager.js b/lib/core/components/subscription-manager.js index d8b1dcd49..a40977e7f 100644 --- a/lib/core/components/subscription-manager.js +++ b/lib/core/components/subscription-manager.js @@ -23,7 +23,6 @@ exports.SubscriptionManager = void 0; const reconnection_manager_1 = require("./reconnection_manager"); const categories_1 = __importDefault(require("../constants/categories")); const deduping_manager_1 = require("./deduping_manager"); -const categories_2 = __importDefault(require("../constants/categories")); /** * Subscription loop manager. * @@ -229,10 +228,10 @@ class SubscriptionManager { status.errorData.name === 'AbortError') || status.category === categories_1.default.PNCancelledCategory) return; - if (status.category === categories_2.default.PNTimeoutCategory) { + if (status.category === categories_1.default.PNTimeoutCategory) { this.startSubscribeLoop(); } - else if (status.category === categories_2.default.PNNetworkIssuesCategory) { + else if (status.category === categories_1.default.PNNetworkIssuesCategory) { this.disconnect(); if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { this.isOnline = false; @@ -246,7 +245,7 @@ class SubscriptionManager { this.reconnect(); this.subscriptionStatusAnnounced = true; const reconnectedAnnounce = { - category: categories_2.default.PNReconnectedCategory, + category: categories_1.default.PNReconnectedCategory, operation: status.operation, lastTimetoken: this.lastTimetoken, currentTimetoken: this.currentTimetoken, @@ -256,13 +255,15 @@ class SubscriptionManager { this.reconnectionManager.startPolling(); this.listenerManager.announceStatus(status); } - else if (status.category === categories_2.default.PNBadRequestCategory) { - this.stopHeartbeatTimer(); - this.listenerManager.announceStatus(status); + else if (status.category === categories_1.default.PNBadRequestCategory || + status.category == categories_1.default.PNMalformedResponseCategory) { + const category = this.isOnline ? categories_1.default.PNDisconnectedUnexpectedlyCategory : status.category; + this.isOnline = false; + this.disconnect(); + this.listenerManager.announceStatus(Object.assign(Object.assign({}, status), { category })); } - else { + else this.listenerManager.announceStatus(status); - } return; } if (this.storedTimetoken) { diff --git a/lib/core/constants/categories.js b/lib/core/constants/categories.js index faab584be..cffeb25aa 100644 --- a/lib/core/constants/categories.js +++ b/lib/core/constants/categories.js @@ -35,6 +35,14 @@ var StatusCategory; * Some API endpoints respond with request processing status w/o useful data. */ StatusCategory["PNAcknowledgmentCategory"] = "PNAcknowledgmentCategory"; + /** + * PubNub service or intermediate "actor" returned unexpected response. + * + * There can be few sources of unexpected return with success code: + * - proxy server / VPN; + * - Wi-Fi hotspot authorization page. + */ + StatusCategory["PNMalformedResponseCategory"] = "PNMalformedResponseCategory"; /** * Something strange happened; please check the logs. */ diff --git a/lib/core/endpoints/access_manager/audit.js b/lib/core/endpoints/access_manager/audit.js index e3a78d4bb..929eb1d8d 100644 --- a/lib/core/endpoints/access_manager/audit.js +++ b/lib/core/endpoints/access_manager/audit.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuditRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); // -------------------------------------------------------- @@ -54,13 +52,7 @@ class AuditRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse.payload; + return this.deserializeResponse(response).payload; }); } get path() { diff --git a/lib/core/endpoints/access_manager/grant.js b/lib/core/endpoints/access_manager/grant.js index d1b0735f8..e1a3ab37f 100644 --- a/lib/core/endpoints/access_manager/grant.js +++ b/lib/core/endpoints/access_manager/grant.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GrantRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); // -------------------------------------------------------- @@ -96,13 +94,7 @@ class GrantRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse.payload; + return this.deserializeResponse(response).payload; }); } get path() { diff --git a/lib/core/endpoints/access_manager/grant_token.js b/lib/core/endpoints/access_manager/grant_token.js index 5440ccc4e..1ad1d5151 100644 --- a/lib/core/endpoints/access_manager/grant_token.js +++ b/lib/core/endpoints/access_manager/grant_token.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GrantTokenRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); @@ -77,13 +75,7 @@ class GrantTokenRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse.data.token; + return this.deserializeResponse(response).data.token; }); } get path() { diff --git a/lib/core/endpoints/access_manager/revoke_token.js b/lib/core/endpoints/access_manager/revoke_token.js index 270365fda..745230e39 100644 --- a/lib/core/endpoints/access_manager/revoke_token.js +++ b/lib/core/endpoints/access_manager/revoke_token.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RevokeTokenRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); @@ -47,14 +45,11 @@ class RevokeTokenRequest extends request_1.AbstractRequest { return "token can't be empty"; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { diff --git a/lib/core/endpoints/actions/add_message_action.js b/lib/core/endpoints/actions/add_message_action.js index e9b368f9b..4be106070 100644 --- a/lib/core/endpoints/actions/add_message_action.js +++ b/lib/core/endpoints/actions/add_message_action.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AddMessageActionRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); @@ -56,14 +54,11 @@ class AddMessageActionRequest extends request_1.AbstractRequest { return 'Action.type value exceed maximum length of 15'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return { data: serviceResponse.data }; + return _super.parse.call(this, response).then(({ data }) => ({ data })); }); } get path() { diff --git a/lib/core/endpoints/actions/get_message_actions.js b/lib/core/endpoints/actions/get_message_actions.js index e4f0eb11e..f6f28fbde 100644 --- a/lib/core/endpoints/actions/get_message_actions.js +++ b/lib/core/endpoints/actions/get_message_actions.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetMessageActionsRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -46,11 +44,6 @@ class GetMessageActionsRequest extends request_1.AbstractRequest { parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); let start = null; let end = null; if (serviceResponse.data.length > 0) { diff --git a/lib/core/endpoints/actions/remove_message_action.js b/lib/core/endpoints/actions/remove_message_action.js index 648d06159..b138ba376 100644 --- a/lib/core/endpoints/actions/remove_message_action.js +++ b/lib/core/endpoints/actions/remove_message_action.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoveMessageAction = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); @@ -50,14 +48,11 @@ class RemoveMessageAction extends request_1.AbstractRequest { return 'Missing action timetoken'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return { data: serviceResponse.data }; + return _super.parse.call(this, response).then(({ data }) => ({ data })); }); } get path() { diff --git a/lib/core/endpoints/channel_groups/add_channels.js b/lib/core/endpoints/channel_groups/add_channels.js index 23468abe8..ec42b5c61 100644 --- a/lib/core/endpoints/channel_groups/add_channels.js +++ b/lib/core/endpoints/channel_groups/add_channels.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AddChannelGroupChannelsRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -47,14 +45,11 @@ class AddChannelGroupChannelsRequest extends request_1.AbstractRequest { return 'Missing channels'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { diff --git a/lib/core/endpoints/channel_groups/delete_group.js b/lib/core/endpoints/channel_groups/delete_group.js index adbb517f5..95339166a 100644 --- a/lib/core/endpoints/channel_groups/delete_group.js +++ b/lib/core/endpoints/channel_groups/delete_group.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteChannelGroupRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -44,14 +42,11 @@ class DeleteChannelGroupRequest extends request_1.AbstractRequest { return 'Missing Channel Group'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { diff --git a/lib/core/endpoints/channel_groups/list_channels.js b/lib/core/endpoints/channel_groups/list_channels.js index 1b0450c9e..fa585a3b2 100644 --- a/lib/core/endpoints/channel_groups/list_channels.js +++ b/lib/core/endpoints/channel_groups/list_channels.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ListChannelGroupChannels = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -45,13 +43,7 @@ class ListChannelGroupChannels extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return { channels: serviceResponse.payload.channels }; + return { channels: this.deserializeResponse(response).payload.channels }; }); } get path() { diff --git a/lib/core/endpoints/channel_groups/list_groups.js b/lib/core/endpoints/channel_groups/list_groups.js index 405a9a9aa..5455884e2 100644 --- a/lib/core/endpoints/channel_groups/list_groups.js +++ b/lib/core/endpoints/channel_groups/list_groups.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ListChannelGroupsRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); // endregion @@ -42,13 +40,7 @@ class ListChannelGroupsRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return { groups: serviceResponse.payload.groups }; + return { groups: this.deserializeResponse(response).payload.groups }; }); } get path() { diff --git a/lib/core/endpoints/channel_groups/remove_channels.js b/lib/core/endpoints/channel_groups/remove_channels.js index b4472116b..f748b0dd0 100644 --- a/lib/core/endpoints/channel_groups/remove_channels.js +++ b/lib/core/endpoints/channel_groups/remove_channels.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoveChannelGroupChannelsRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -48,14 +46,11 @@ class RemoveChannelGroupChannelsRequest extends request_1.AbstractRequest { return 'Missing channels'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { diff --git a/lib/core/endpoints/fetch_messages.js b/lib/core/endpoints/fetch_messages.js index 758894a70..3d65d7d06 100644 --- a/lib/core/endpoints/fetch_messages.js +++ b/lib/core/endpoints/fetch_messages.js @@ -41,8 +41,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FetchMessagesRequest = void 0; -const pubnub_error_1 = require("../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../errors/pubnub-api-error"); const request_1 = require("../components/request"); const operations_1 = __importDefault(require("../constants/operations")); const History = __importStar(require("../types/api/history")); @@ -121,11 +119,6 @@ class FetchMessagesRequest extends request_1.AbstractRequest { return __awaiter(this, void 0, void 0, function* () { var _a; const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); const responseChannels = (_a = serviceResponse.channels) !== null && _a !== void 0 ? _a : {}; const channels = {}; Object.keys(responseChannels).forEach((channel) => { diff --git a/lib/core/endpoints/file_upload/delete_file.js b/lib/core/endpoints/file_upload/delete_file.js index f916e6653..ba9a038b2 100644 --- a/lib/core/endpoints/file_upload/delete_file.js +++ b/lib/core/endpoints/file_upload/delete_file.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteFileRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); @@ -47,17 +36,6 @@ class DeleteFileRequest extends request_1.AbstractRequest { if (!name) return "file name can't be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, id, channel, name, } = this.parameters; return `/v1/files/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/files/${id}/${name}`; diff --git a/lib/core/endpoints/file_upload/generate_upload_url.js b/lib/core/endpoints/file_upload/generate_upload_url.js index 5c621f062..57416cea1 100644 --- a/lib/core/endpoints/file_upload/generate_upload_url.js +++ b/lib/core/endpoints/file_upload/generate_upload_url.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GenerateFileUploadUrlRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); @@ -47,11 +45,6 @@ class GenerateFileUploadUrlRequest extends request_1.AbstractRequest { parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); return { id: serviceResponse.data.id, name: serviceResponse.data.name, diff --git a/lib/core/endpoints/file_upload/list_files.js b/lib/core/endpoints/file_upload/list_files.js index 614de6471..bccdbec40 100644 --- a/lib/core/endpoints/file_upload/list_files.js +++ b/lib/core/endpoints/file_upload/list_files.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.FilesListRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -53,17 +42,6 @@ class FilesListRequest extends request_1.AbstractRequest { if (!this.parameters.channel) return "channel can't be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v1/files/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/files`; diff --git a/lib/core/endpoints/file_upload/publish_file.js b/lib/core/endpoints/file_upload/publish_file.js index 82af6dc76..ea75057aa 100644 --- a/lib/core/endpoints/file_upload/publish_file.js +++ b/lib/core/endpoints/file_upload/publish_file.js @@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PublishFileMessageRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const base64_codec_1 = require("../../components/base64_codec"); @@ -60,10 +59,7 @@ class PublishFileMessageRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - return { timetoken: serviceResponse[2] }; + return { timetoken: this.deserializeResponse(response)[2] }; }); } get path() { diff --git a/lib/core/endpoints/file_upload/send_file.js b/lib/core/endpoints/file_upload/send_file.js index 2f4512ea6..9d4ebeb1d 100644 --- a/lib/core/endpoints/file_upload/send_file.js +++ b/lib/core/endpoints/file_upload/send_file.js @@ -19,11 +19,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); exports.SendFileRequest = void 0; const generate_upload_url_1 = require("./generate_upload_url"); +const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const pubnub_error_1 = require("../../../errors/pubnub-error"); const operations_1 = __importDefault(require("../../constants/operations")); -const upload_file_1 = require("./upload-file"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const categories_1 = __importDefault(require("../../constants/categories")); +const upload_file_1 = require("./upload-file"); // endregion /** * Send file composed request. diff --git a/lib/core/endpoints/history/delete_messages.js b/lib/core/endpoints/history/delete_messages.js index 2ded57b82..fb72cdd50 100644 --- a/lib/core/endpoints/history/delete_messages.js +++ b/lib/core/endpoints/history/delete_messages.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeleteMessageRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const transport_request_1 = require("../../types/transport-request"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); @@ -45,14 +43,11 @@ class DeleteMessageRequest extends request_1.AbstractRequest { return 'Missing channel'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { diff --git a/lib/core/endpoints/history/get_history.js b/lib/core/endpoints/history/get_history.js index 7a8ac874e..388598710 100644 --- a/lib/core/endpoints/history/get_history.js +++ b/lib/core/endpoints/history/get_history.js @@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetHistoryRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -74,8 +73,6 @@ class GetHistoryRequest extends request_1.AbstractRequest { parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); const messages = serviceResponse[0]; const startTimeToken = serviceResponse[1]; const endTimeToken = serviceResponse[2]; diff --git a/lib/core/endpoints/history/message_counts.js b/lib/core/endpoints/history/message_counts.js index 07f236743..04c485958 100644 --- a/lib/core/endpoints/history/message_counts.js +++ b/lib/core/endpoints/history/message_counts.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.MessageCountRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -52,13 +50,7 @@ class MessageCountRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return { channels: serviceResponse.channels }; + return { channels: this.deserializeResponse(response).channels }; }); } get path() { diff --git a/lib/core/endpoints/objects/channel/get.js b/lib/core/endpoints/objects/channel/get.js index 56caa61d1..c2fe425a7 100644 --- a/lib/core/endpoints/objects/channel/get.js +++ b/lib/core/endpoints/objects/channel/get.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetChannelMetadataRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); @@ -54,17 +43,6 @@ class GetChannelMetadataRequest extends request_1.AbstractRequest { if (!this.parameters.channel) return 'Channel cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}`; diff --git a/lib/core/endpoints/objects/channel/get_all.js b/lib/core/endpoints/objects/channel/get_all.js index d5decf2d9..cf6003fb7 100644 --- a/lib/core/endpoints/objects/channel/get_all.js +++ b/lib/core/endpoints/objects/channel/get_all.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetAllChannelsMetadataRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); // -------------------------------------------------------- @@ -59,17 +48,6 @@ class GetAllChannelsMetadataRequest extends request_1.AbstractRequest { operation() { return operations_1.default.PNGetAllChannelMetadataOperation; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { return `/v2/objects/${this.parameters.keySet.subscribeKey}/channels`; } diff --git a/lib/core/endpoints/objects/channel/remove.js b/lib/core/endpoints/objects/channel/remove.js index 3b5a3cdb3..b54d2a7aa 100644 --- a/lib/core/endpoints/objects/channel/remove.js +++ b/lib/core/endpoints/objects/channel/remove.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoveChannelMetadataRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); @@ -42,17 +31,6 @@ class RemoveChannelMetadataRequest extends request_1.AbstractRequest { if (!this.parameters.channel) return 'Channel cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}`; diff --git a/lib/core/endpoints/objects/channel/set.js b/lib/core/endpoints/objects/channel/set.js index 9868323f0..74a89c36e 100644 --- a/lib/core/endpoints/objects/channel/set.js +++ b/lib/core/endpoints/objects/channel/set.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SetChannelMetadataRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); @@ -65,17 +54,6 @@ class SetChannelMetadataRequest extends request_1.AbstractRequest { return undefined; } } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}`; diff --git a/lib/core/endpoints/objects/member/get.js b/lib/core/endpoints/objects/member/get.js index 170817a08..95fa842be 100644 --- a/lib/core/endpoints/objects/member/get.js +++ b/lib/core/endpoints/objects/member/get.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetChannelMembersRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); @@ -94,17 +83,6 @@ class GetChannelMembersRequest extends request_1.AbstractRequest { if (!this.parameters.channel) return 'Channel cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/uuids`; diff --git a/lib/core/endpoints/objects/member/set.js b/lib/core/endpoints/objects/member/set.js index 45682cb0c..705b8f188 100644 --- a/lib/core/endpoints/objects/member/set.js +++ b/lib/core/endpoints/objects/member/set.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SetChannelMembersRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); @@ -98,17 +87,6 @@ class SetChannelMembersRequest extends request_1.AbstractRequest { if (!uuids || uuids.length === 0) return 'UUIDs cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, channel, } = this.parameters; return `/v2/objects/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/uuids`; diff --git a/lib/core/endpoints/objects/membership/get.js b/lib/core/endpoints/objects/membership/get.js index 5b333955b..519c343db 100644 --- a/lib/core/endpoints/objects/membership/get.js +++ b/lib/core/endpoints/objects/membership/get.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetUUIDMembershipsRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); @@ -97,17 +86,6 @@ class GetUUIDMembershipsRequest extends request_1.AbstractRequest { if (!this.parameters.uuid) return "'uuid' cannot be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}/channels`; diff --git a/lib/core/endpoints/objects/membership/set.js b/lib/core/endpoints/objects/membership/set.js index f4e6f8039..1cb8ea4d8 100644 --- a/lib/core/endpoints/objects/membership/set.js +++ b/lib/core/endpoints/objects/membership/set.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SetUUIDMembershipsRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); @@ -101,17 +90,6 @@ class SetUUIDMembershipsRequest extends request_1.AbstractRequest { if (!channels || channels.length === 0) return 'Channels cannot be empty'; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}/channels`; diff --git a/lib/core/endpoints/objects/uuid/get.js b/lib/core/endpoints/objects/uuid/get.js index 2f9705040..db83b7e6a 100644 --- a/lib/core/endpoints/objects/uuid/get.js +++ b/lib/core/endpoints/objects/uuid/get.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetUUIDMetadataRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); const utils_1 = require("../../../utils"); @@ -57,17 +46,6 @@ class GetUUIDMetadataRequest extends request_1.AbstractRequest { if (!this.parameters.uuid) return "'uuid' cannot be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}`; diff --git a/lib/core/endpoints/objects/uuid/get_all.js b/lib/core/endpoints/objects/uuid/get_all.js index e95a18b9a..7fe3baf2e 100644 --- a/lib/core/endpoints/objects/uuid/get_all.js +++ b/lib/core/endpoints/objects/uuid/get_all.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetAllUUIDMetadataRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); // -------------------------------------------------------- @@ -54,17 +43,6 @@ class GetAllUUIDMetadataRequest extends request_1.AbstractRequest { operation() { return operations_1.default.PNGetAllUUIDMetadataOperation; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { return `/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`; } diff --git a/lib/core/endpoints/objects/uuid/remove.js b/lib/core/endpoints/objects/uuid/remove.js index c97245691..b42fd4f48 100644 --- a/lib/core/endpoints/objects/uuid/remove.js +++ b/lib/core/endpoints/objects/uuid/remove.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoveUUIDMetadataRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); @@ -45,17 +34,6 @@ class RemoveUUIDMetadataRequest extends request_1.AbstractRequest { if (!this.parameters.uuid) return "'uuid' cannot be empty"; } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}`; diff --git a/lib/core/endpoints/objects/uuid/set.js b/lib/core/endpoints/objects/uuid/set.js index 48680a812..17669ca9b 100644 --- a/lib/core/endpoints/objects/uuid/set.js +++ b/lib/core/endpoints/objects/uuid/set.js @@ -4,22 +4,11 @@ * * @internal */ -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 __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SetUUIDMetadataRequest = void 0; -const pubnub_error_1 = require("../../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../../errors/pubnub-api-error"); const transport_request_1 = require("../../../types/transport-request"); const request_1 = require("../../../components/request"); const operations_1 = __importDefault(require("../../../constants/operations")); @@ -68,17 +57,6 @@ class SetUUIDMetadataRequest extends request_1.AbstractRequest { return undefined; } } - parse(response) { - return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return serviceResponse; - }); - } get path() { const { keySet: { subscribeKey }, uuid, } = this.parameters; return `/v2/objects/${subscribeKey}/uuids/${(0, utils_1.encodeString)(uuid)}`; diff --git a/lib/core/endpoints/presence/get_state.js b/lib/core/endpoints/presence/get_state.js index ee37ee086..a38d4a65a 100644 --- a/lib/core/endpoints/presence/get_state.js +++ b/lib/core/endpoints/presence/get_state.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetPresenceStateRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -50,11 +48,6 @@ class GetPresenceStateRequest extends request_1.AbstractRequest { parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); const { channels = [], channelGroups = [] } = this.parameters; const state = { channels: {} }; if (channels.length === 1 && channelGroups.length === 0) diff --git a/lib/core/endpoints/presence/heartbeat.js b/lib/core/endpoints/presence/heartbeat.js index 51bd2497c..8c34211bc 100644 --- a/lib/core/endpoints/presence/heartbeat.js +++ b/lib/core/endpoints/presence/heartbeat.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -45,14 +43,11 @@ class HeartbeatRequest extends request_1.AbstractRequest { return 'Please provide a list of channels and/or channel-groups'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { diff --git a/lib/core/endpoints/presence/here_now.js b/lib/core/endpoints/presence/here_now.js index 7a2a464c4..2beb6656d 100644 --- a/lib/core/endpoints/presence/here_now.js +++ b/lib/core/endpoints/presence/here_now.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HereNowRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -66,11 +64,6 @@ class HereNowRequest extends request_1.AbstractRequest { return __awaiter(this, void 0, void 0, function* () { var _a, _b; const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); // Extract general presence information. const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; const totalOccupancy = 'occupancy' in serviceResponse ? serviceResponse.occupancy : serviceResponse.payload.total_occupancy; diff --git a/lib/core/endpoints/presence/leave.js b/lib/core/endpoints/presence/leave.js index 7ed6e2f62..5a2bd09d2 100644 --- a/lib/core/endpoints/presence/leave.js +++ b/lib/core/endpoints/presence/leave.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PresenceLeaveRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -49,14 +47,11 @@ class PresenceLeaveRequest extends request_1.AbstractRequest { return 'At least one `channel` or `channel group` should be provided.'; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } get path() { diff --git a/lib/core/endpoints/presence/set_state.js b/lib/core/endpoints/presence/set_state.js index eb7648474..ade901f85 100644 --- a/lib/core/endpoints/presence/set_state.js +++ b/lib/core/endpoints/presence/set_state.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SetPresenceStateRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -48,13 +46,7 @@ class SetPresenceStateRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); - return { state: serviceResponse.payload }; + return { state: this.deserializeResponse(response).payload }; }); } get path() { diff --git a/lib/core/endpoints/presence/where_now.js b/lib/core/endpoints/presence/where_now.js index f2f5a7724..0c8ce6c30 100644 --- a/lib/core/endpoints/presence/where_now.js +++ b/lib/core/endpoints/presence/where_now.js @@ -18,8 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.WhereNowRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); -const pubnub_api_error_1 = require("../../../errors/pubnub-api-error"); const request_1 = require("../../components/request"); const operations_1 = __importDefault(require("../../constants/operations")); const utils_1 = require("../../utils"); @@ -44,11 +42,6 @@ class WhereNowRequest extends request_1.AbstractRequest { parse(response) { return __awaiter(this, void 0, void 0, function* () { const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - } - else if (serviceResponse.status >= 400) - throw pubnub_api_error_1.PubNubAPIError.create(response); if (!serviceResponse.payload) return { channels: [] }; return { channels: serviceResponse.payload.channels }; diff --git a/lib/core/endpoints/publish.js b/lib/core/endpoints/publish.js index 3cdedc0a8..1bffd8ed6 100644 --- a/lib/core/endpoints/publish.js +++ b/lib/core/endpoints/publish.js @@ -16,7 +16,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PublishRequest = void 0; -const pubnub_error_1 = require("../../errors/pubnub-error"); const transport_request_1 = require("../types/transport-request"); const request_1 = require("../components/request"); const operations_1 = __importDefault(require("../constants/operations")); @@ -67,10 +66,7 @@ class PublishRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - return { timetoken: serviceResponse[2] }; + return { timetoken: this.deserializeResponse(response)[2] }; }); } get path() { @@ -94,6 +90,8 @@ class PublishRequest extends request_1.AbstractRequest { return query; } get headers() { + if (!this.parameters.sendByPost) + return undefined; return { 'Content-Type': 'application/json' }; } get body() { diff --git a/lib/core/endpoints/push/add_push_channels.js b/lib/core/endpoints/push/add_push_channels.js index 8396d1d91..eee7e2bbb 100644 --- a/lib/core/endpoints/push/add_push_channels.js +++ b/lib/core/endpoints/push/add_push_channels.js @@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AddDevicePushNotificationChannelsRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); const push_1 = require("./push"); const operations_1 = __importDefault(require("../../constants/operations")); // endregion @@ -36,11 +35,11 @@ class AddDevicePushNotificationChannelsRequest extends push_1.BasePushNotificati return operations_1.default.PNAddPushNotificationEnabledChannelsOperation; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } } diff --git a/lib/core/endpoints/push/list_push_channels.js b/lib/core/endpoints/push/list_push_channels.js index 1f62c8ff4..c1f1ba679 100644 --- a/lib/core/endpoints/push/list_push_channels.js +++ b/lib/core/endpoints/push/list_push_channels.js @@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ListDevicePushNotificationChannelsRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); const push_1 = require("./push"); const operations_1 = __importDefault(require("../../constants/operations")); // endregion @@ -37,10 +36,7 @@ class ListDevicePushNotificationChannelsRequest extends push_1.BasePushNotificat } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - return { channels: serviceResponse }; + return { channels: this.deserializeResponse(response) }; }); } } diff --git a/lib/core/endpoints/push/push.js b/lib/core/endpoints/push/push.js index 5d12c31c5..93867ffd5 100644 --- a/lib/core/endpoints/push/push.js +++ b/lib/core/endpoints/push/push.js @@ -4,15 +4,6 @@ * * @internal */ -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()); - }); -}; Object.defineProperty(exports, "__esModule", { value: true }); exports.BasePushNotificationChannelsRequest = void 0; const request_1 = require("../../components/request"); @@ -63,11 +54,6 @@ class BasePushNotificationChannelsRequest extends request_1.AbstractRequest { if (this.parameters.pushGateway === 'apns2' && !this.parameters.topic) return 'Missing APNS2 topic'; } - parse(_response) { - return __awaiter(this, void 0, void 0, function* () { - throw Error('Should be implemented in subclass.'); - }); - } get path() { const { keySet: { subscribeKey }, action, device, pushGateway, } = this.parameters; let path = pushGateway === 'apns2' diff --git a/lib/core/endpoints/push/remove_device.js b/lib/core/endpoints/push/remove_device.js index 563e091d6..6a870e110 100644 --- a/lib/core/endpoints/push/remove_device.js +++ b/lib/core/endpoints/push/remove_device.js @@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoveDevicePushNotificationRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); const push_1 = require("./push"); const operations_1 = __importDefault(require("../../constants/operations")); // endregion @@ -36,11 +35,11 @@ class RemoveDevicePushNotificationRequest extends push_1.BasePushNotificationCha return operations_1.default.PNRemoveAllPushNotificationsOperation; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } } diff --git a/lib/core/endpoints/push/remove_push_channels.js b/lib/core/endpoints/push/remove_push_channels.js index 8d7455b4a..d60200e1b 100644 --- a/lib/core/endpoints/push/remove_push_channels.js +++ b/lib/core/endpoints/push/remove_push_channels.js @@ -18,7 +18,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoveDevicePushNotificationChannelsRequest = void 0; -const pubnub_error_1 = require("../../../errors/pubnub-error"); const push_1 = require("./push"); const operations_1 = __importDefault(require("../../constants/operations")); // endregion @@ -36,11 +35,11 @@ class RemoveDevicePushNotificationChannelsRequest extends push_1.BasePushNotific return operations_1.default.PNRemovePushNotificationEnabledChannelsOperation; } parse(response) { + const _super = Object.create(null, { + parse: { get: () => super.parse } + }); return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - return {}; + return _super.parse.call(this, response).then((_) => ({})); }); } } diff --git a/lib/core/endpoints/signal.js b/lib/core/endpoints/signal.js index a6f34181e..8bdad1b80 100644 --- a/lib/core/endpoints/signal.js +++ b/lib/core/endpoints/signal.js @@ -16,7 +16,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SignalRequest = void 0; -const pubnub_error_1 = require("../../errors/pubnub-error"); const request_1 = require("../components/request"); const operations_1 = __importDefault(require("../constants/operations")); const utils_1 = require("../utils"); @@ -45,10 +44,7 @@ class SignalRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - return { timetoken: serviceResponse[2] }; + return { timetoken: this.deserializeResponse(response)[2] }; }); } get path() { diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index 401ebbda5..03b9c1533 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -99,16 +99,17 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { parse(response) { return __awaiter(this, void 0, void 0, function* () { let serviceResponse; + let responseText; try { - const json = request_1.AbstractRequest.decoder.decode(response.body); - const parsedJson = JSON.parse(json); + responseText = request_1.AbstractRequest.decoder.decode(response.body); + const parsedJson = JSON.parse(responseText); serviceResponse = parsedJson; } catch (error) { console.error('Error parsing JSON response:', error); } if (!serviceResponse) { - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); + throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createMalformedResponseError)(responseText, response.status)); } const events = serviceResponse.m .filter((envelope) => { diff --git a/lib/core/endpoints/time.js b/lib/core/endpoints/time.js index ce2e5a3a6..4b0ad61f4 100644 --- a/lib/core/endpoints/time.js +++ b/lib/core/endpoints/time.js @@ -16,7 +16,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.TimeRequest = void 0; -const pubnub_error_1 = require("../../errors/pubnub-error"); const request_1 = require("../components/request"); const operations_1 = __importDefault(require("../constants/operations")); // endregion @@ -34,10 +33,7 @@ class TimeRequest extends request_1.AbstractRequest { } parse(response) { return __awaiter(this, void 0, void 0, function* () { - const serviceResponse = this.deserializeResponse(response); - if (!serviceResponse) - throw new pubnub_error_1.PubNubError('Service response error, check status for details', (0, pubnub_error_1.createValidationError)('Unable to deserialize service response')); - return { timetoken: serviceResponse[0] }; + return { timetoken: this.deserializeResponse(response)[0] }; }); } get path() { diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 6059ec9fc..c90337f70 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -583,12 +583,15 @@ class PubNubCore { status.statusCode = response.status; // Handle special case when request completed but not fully processed by PubNub service. if (response.status !== 200 && response.status !== 204) { + const responseText = PubNubCore.decoder.decode(response.body); const contentType = response.headers['content-type']; if (contentType || contentType.indexOf('javascript') !== -1 || contentType.indexOf('json') !== -1) { - const json = JSON.parse(PubNubCore.decoder.decode(response.body)); + const json = JSON.parse(responseText); if (typeof json === 'object' && 'error' in json && json.error && typeof json.error === 'object') status.errorData = json.error; } + else + status.responseText = responseText; } return request.parse(response); }) @@ -857,7 +860,7 @@ class PubNubCore { */ if (this.subscriptionManager) { // Creating identifiable abort caller. - const callableAbort = () => request.abort(); + const callableAbort = () => request.abort('Cancel long-poll subscribe request'); callableAbort.identifier = request.requestIdentifier; this.subscriptionManager.abort = callableAbort; } @@ -954,7 +957,7 @@ class PubNubCore { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { const request = new handshake_1.HandshakeSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); + request.abort('Cancel subscribe handshake request'); }); /** * Allow subscription cancellation. @@ -984,7 +987,7 @@ class PubNubCore { if (process.env.SUBSCRIBE_EVENT_ENGINE_MODULE !== 'disabled') { const request = new receiveMessages_1.ReceiveMessagesSubscribeRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet, crypto: this._configuration.getCryptoModule(), getFileUrl: this.getFileUrl.bind(this) })); const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); + request.abort('Cancel long-poll subscribe request'); }); /** * Allow subscription cancellation. @@ -992,8 +995,8 @@ class PubNubCore { * **Note:** Had to be done after scheduling because transport provider return cancellation * controller only when schedule new request. */ - const handshakeResponse = this.sendRequest(request); - return handshakeResponse.then((response) => { + const receiveResponse = this.sendRequest(request); + return receiveResponse.then((response) => { abortUnsubscribe(); return response; }); diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js index 1a9b41e2e..c9ad14517 100644 --- a/lib/errors/pubnub-api-error.js +++ b/lib/errors/pubnub-api-error.js @@ -129,20 +129,29 @@ class PubNubAPIError extends Error { response.headers['content-type'].indexOf('application/json') !== -1) { try { const errorResponse = JSON.parse(decoded); - if (typeof errorResponse === 'object' && !Array.isArray(errorResponse)) { - if ('error' in errorResponse && - (errorResponse.error === 1 || errorResponse.error === true) && - 'status' in errorResponse && - typeof errorResponse.status === 'number' && - 'message' in errorResponse && - 'service' in errorResponse) { - errorData = errorResponse; - status = errorResponse.status; + if (typeof errorResponse === 'object') { + if (!Array.isArray(errorResponse)) { + if ('error' in errorResponse && + (errorResponse.error === 1 || errorResponse.error === true) && + 'status' in errorResponse && + typeof errorResponse.status === 'number' && + 'message' in errorResponse && + 'service' in errorResponse) { + errorData = errorResponse; + status = errorResponse.status; + } + else + errorData = errorResponse; + if ('error' in errorResponse && errorResponse.error instanceof Error) + errorData = errorResponse.error; + } + else { + // Handling Publish API payload error. + if (typeof errorResponse[0] === 'number' && errorResponse[0] === 0) { + if (errorResponse.length > 1 && typeof errorResponse[1] === 'string') + errorData = errorResponse[1]; + } } - else - errorData = errorResponse; - if ('error' in errorResponse && errorResponse.error instanceof Error) - errorData = errorResponse.error; } } catch (_) { diff --git a/lib/errors/pubnub-error.js b/lib/errors/pubnub-error.js index 97c5938c4..e4c30fd64 100644 --- a/lib/errors/pubnub-error.js +++ b/lib/errors/pubnub-error.js @@ -8,6 +8,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { Object.defineProperty(exports, "__esModule", { value: true }); exports.PubNubError = void 0; exports.createValidationError = createValidationError; +exports.createMalformedResponseError = createMalformedResponseError; const categories_1 = __importDefault(require("../core/constants/categories")); /** * PubNub operation error. @@ -38,15 +39,16 @@ exports.PubNubError = PubNubError; * Create error status object. * * @param errorPayload - Additional information which should be attached to the error status object. + * @param category - Occurred error category. * * @returns Error status object. * * @internal */ -function createError(errorPayload) { +function createError(errorPayload, category) { var _a; (_a = errorPayload.statusCode) !== null && _a !== void 0 ? _a : (errorPayload.statusCode = 0); - return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category: categories_1.default.PNValidationErrorCategory, error: true }); + return Object.assign(Object.assign({}, errorPayload), { statusCode: errorPayload.statusCode, category, error: true }); } /** * Create operation arguments validation error status object. @@ -59,5 +61,14 @@ function createError(errorPayload) { * @internal */ function createValidationError(message, statusCode) { - return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {}))); + return createError(Object.assign({ message }, (statusCode !== undefined ? { statusCode } : {})), categories_1.default.PNValidationErrorCategory); +} +/** + * Create malformed service response error status object. + * + * @param [responseText] - Stringified original service response. + * @param [statusCode] - Operation HTTP status code. + */ +function createMalformedResponseError(responseText, statusCode) { + return createError(Object.assign(Object.assign({ message: 'Unable to deserialize service response' }, (responseText !== undefined ? { responseText } : {})), (statusCode !== undefined ? { statusCode } : {})), categories_1.default.PNMalformedResponseCategory); } diff --git a/lib/transport/node-transport.js b/lib/transport/node-transport.js index ea2aae6b0..91884f872 100644 --- a/lib/transport/node-transport.js +++ b/lib/transport/node-transport.js @@ -89,7 +89,11 @@ class NodeTransport { controller = { // Storing controller inside to prolong object lifetime. abortController, - abort: () => abortController === null || abortController === void 0 ? void 0 : abortController.abort(), + abort: (reason) => { + if (!abortController || abortController.signal.aborted) + return; + abortController === null || abortController === void 0 ? void 0 : abortController.abort(reason); + }, }; } return [ @@ -119,7 +123,15 @@ class NodeTransport { return transportResponse; }) .catch((error) => { - throw pubnub_api_error_1.PubNubAPIError.create(error); + let fetchError = error; + if (typeof error === 'string') { + const errorMessage = error.toLowerCase(); + if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) + fetchError = new Error(error); + else if (errorMessage.includes('cancel')) + fetchError = new node_fetch_1.AbortError('Aborted'); + } + throw pubnub_api_error_1.PubNubAPIError.create(fetchError); }); }), controller, diff --git a/lib/transport/react-native-transport.js b/lib/transport/react-native-transport.js index d738dbde8..4372dcdd1 100644 --- a/lib/transport/react-native-transport.js +++ b/lib/transport/react-native-transport.js @@ -40,7 +40,7 @@ class ReactNativeTransport { const controller = { // Storing controller inside to prolong object lifetime. abortController, - abort: () => !abortController.signal.aborted && abortController.abort(), + abort: (reason) => !abortController.signal.aborted && abortController.abort(reason), }; return [ this.requestFromTransportRequest(req).then((request) => { @@ -56,7 +56,7 @@ class ReactNativeTransport { timeoutId = setTimeout(() => { clearTimeout(timeoutId); reject(new Error('Request timeout')); - controller.abort(); + controller.abort('Cancel because of timeout'); }, req.timeout * 1000); }); return Promise.race([ @@ -91,7 +91,17 @@ class ReactNativeTransport { return transportResponse; }) .catch((error) => { - throw pubnub_api_error_1.PubNubAPIError.create(error); + let fetchError = error; + if (typeof error === 'string') { + const errorMessage = error.toLowerCase(); + if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) + fetchError = new Error(error); + else if (errorMessage.includes('cancel')) { + fetchError = new Error('Aborted'); + fetchError.name = 'AbortError'; + } + } + throw pubnub_api_error_1.PubNubAPIError.create(fetchError); }); }), controller, diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 7730d19b3..cbfb2fb6d 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -2043,6 +2043,14 @@ declare namespace PubNub { * Some API endpoints respond with request processing status w/o useful data. */ PNAcknowledgmentCategory = 'PNAcknowledgmentCategory', + /** + * PubNub service or intermediate "actor" returned unexpected response. + * + * There can be few sources of unexpected return with success code: + * - proxy server / VPN; + * - Wi-Fi hotspot authorization page. + */ + PNMalformedResponseCategory = 'PNMalformedResponseCategory', /** * Something strange happened; please check the logs. */ @@ -2892,7 +2900,7 @@ declare namespace PubNub { /** * Request cancellation / abort function. */ - abort: () => void; + abort: (reason?: string) => void; }; /** diff --git a/package-lock.json b/package-lock.json index 4b12108a1..187770ec6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.3.2", + "version": "8.8.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.3.2", + "version": "8.8.1", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", diff --git a/package.json b/package.json index 504b4d8ca..41fc4a0c1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.8.1", + "version": "8.9.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index e53d26192..e66e67c05 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.8.1'; + return '8.9.0'; }, getVersion(): string { return this.version; diff --git a/src/core/components/request.ts b/src/core/components/request.ts index 50b028140..8863e5a07 100644 --- a/src/core/components/request.ts +++ b/src/core/components/request.ts @@ -5,7 +5,9 @@ */ import { CancellationController, TransportMethod, TransportRequest } from '../types/transport-request'; +import { createMalformedResponseError, PubNubError } from '../../errors/pubnub-error'; import { TransportResponse } from '../types/transport-response'; +import { PubNubAPIError } from '../../errors/pubnub-api-error'; import RequestOperation from '../constants/operations'; import { PubNubFileInterface } from '../types/file'; import { Request } from '../interfaces/request'; @@ -17,7 +19,7 @@ import uuidGenerator from './uuid'; * * @internal */ -export abstract class AbstractRequest implements Request { +export abstract class AbstractRequest implements Request { /** * Service `ArrayBuffer` response decoder. */ @@ -66,9 +68,11 @@ export abstract class AbstractRequest implements Request implements Request { - throw Error('Should be implemented by subclass.'); + async parse(response: TransportResponse): Promise { + return this.deserializeResponse(response) as unknown as ResponseType; } /** @@ -170,21 +174,37 @@ export abstract class AbstractRequest implements Request(response: TransportResponse): ServiceResponse | undefined { + protected deserializeResponse(response: TransportResponse): ServiceResponse { + const responseText = AbstractRequest.decoder.decode(response.body); const contentType = response.headers['content-type']; - if (!contentType || (contentType.indexOf('javascript') === -1 && contentType.indexOf('json') === -1)) - return undefined; + let parsedJson: ServiceResponse; - const json = AbstractRequest.decoder.decode(response.body); + if (!contentType || (contentType.indexOf('javascript') === -1 && contentType.indexOf('json') === -1)) + throw new PubNubError( + 'Service response error, check status for details', + createMalformedResponseError(responseText, response.status), + ); try { - const parsedJson = JSON.parse(json); - return parsedJson as ServiceResponse; + parsedJson = JSON.parse(responseText); } catch (error) { console.error('Error parsing JSON response:', error); - return undefined; + + throw new PubNubError( + 'Service response error, check status for details', + createMalformedResponseError(responseText, response.status), + ); } + + // Throw and exception in case of client / server error. + if ('status' in parsedJson && typeof parsedJson.status === 'number' && parsedJson.status >= 400) + throw PubNubAPIError.create(response); + + return parsedJson; } } diff --git a/src/core/components/subscription-manager.ts b/src/core/components/subscription-manager.ts index df0db8bc4..3dcca2727 100644 --- a/src/core/components/subscription-manager.ts +++ b/src/core/components/subscription-manager.ts @@ -13,7 +13,6 @@ import * as Subscription from '../types/api/subscription'; import { ListenerManager } from './listener_manager'; import StatusCategory from '../constants/categories'; import { DedupingManager } from './deduping_manager'; -import Categories from '../constants/categories'; import * as Presence from '../types/api/presence'; import { PubNubCore } from '../pubnub-common'; import EventEmitter from './eventEmitter'; @@ -382,9 +381,9 @@ export class SubscriptionManager { ) return; - if (status.category === Categories.PNTimeoutCategory) { + if (status.category === StatusCategory.PNTimeoutCategory) { this.startSubscribeLoop(); - } else if (status.category === Categories.PNNetworkIssuesCategory) { + } else if (status.category === StatusCategory.PNNetworkIssuesCategory) { this.disconnect(); if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { @@ -402,7 +401,7 @@ export class SubscriptionManager { this.subscriptionStatusAnnounced = true; const reconnectedAnnounce = { - category: Categories.PNReconnectedCategory, + category: StatusCategory.PNReconnectedCategory, operation: status.operation, lastTimetoken: this.lastTimetoken, currentTimetoken: this.currentTimetoken, @@ -412,12 +411,16 @@ export class SubscriptionManager { this.reconnectionManager.startPolling(); this.listenerManager.announceStatus(status); - } else if (status.category === Categories.PNBadRequestCategory) { - this.stopHeartbeatTimer(); - this.listenerManager.announceStatus(status); - } else { - this.listenerManager.announceStatus(status); - } + } else if ( + status.category === StatusCategory.PNBadRequestCategory || + status.category == StatusCategory.PNMalformedResponseCategory + ) { + const category = this.isOnline ? StatusCategory.PNDisconnectedUnexpectedlyCategory : status.category; + this.isOnline = false; + this.disconnect(); + + this.listenerManager.announceStatus({ ...status, category }); + } else this.listenerManager.announceStatus(status); return; } diff --git a/src/core/constants/categories.ts b/src/core/constants/categories.ts index 6550b4538..54ead3e4e 100644 --- a/src/core/constants/categories.ts +++ b/src/core/constants/categories.ts @@ -39,6 +39,15 @@ enum StatusCategory { */ PNAcknowledgmentCategory = 'PNAcknowledgmentCategory', + /** + * PubNub service or intermediate "actor" returned unexpected response. + * + * There can be few sources of unexpected return with success code: + * - proxy server / VPN; + * - Wi-Fi hotspot authorization page. + */ + PNMalformedResponseCategory = 'PNMalformedResponseCategory', + /** * Something strange happened; please check the logs. */ diff --git a/src/core/endpoints/access_manager/audit.ts b/src/core/endpoints/access_manager/audit.ts index 30aef5bfc..ec30dc018 100644 --- a/src/core/endpoints/access_manager/audit.ts +++ b/src/core/endpoints/access_manager/audit.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import * as PAM from '../../types/api/access-manager'; @@ -69,7 +67,7 @@ type ServiceResponse = { * * @internal */ -export class AuditRequest extends AbstractRequest { +export class AuditRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -86,16 +84,7 @@ export class AuditRequest extends AbstractRequest { } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse.payload; + return this.deserializeResponse(response).payload; } protected get path(): string { diff --git a/src/core/endpoints/access_manager/grant.ts b/src/core/endpoints/access_manager/grant.ts index a6eff8629..731c68091 100644 --- a/src/core/endpoints/access_manager/grant.ts +++ b/src/core/endpoints/access_manager/grant.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import * as PAM from '../../types/api/access-manager'; @@ -99,7 +97,7 @@ type ServiceResponse = { * * @internal */ -export class GrantRequest extends AbstractRequest { +export class GrantRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -140,16 +138,7 @@ export class GrantRequest extends AbstractRequest { } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse.payload; + return this.deserializeResponse(response).payload; } protected get path(): string { diff --git a/src/core/endpoints/access_manager/grant_token.ts b/src/core/endpoints/access_manager/grant_token.ts index 0a6fd0df9..329faaca9 100644 --- a/src/core/endpoints/access_manager/grant_token.ts +++ b/src/core/endpoints/access_manager/grant_token.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { TransportMethod } from '../../types/transport-request'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; @@ -93,7 +91,7 @@ type ServiceResponse = { * * @internal */ -export class GrantTokenRequest extends AbstractRequest { +export class GrantTokenRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.POST }); @@ -146,16 +144,7 @@ export class GrantTokenRequest extends AbstractRequest { } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse.data.token; + return this.deserializeResponse(response).data.token; } protected get path(): string { diff --git a/src/core/endpoints/access_manager/revoke_token.ts b/src/core/endpoints/access_manager/revoke_token.ts index 600e350e8..cdce6ecae 100644 --- a/src/core/endpoints/access_manager/revoke_token.ts +++ b/src/core/endpoints/access_manager/revoke_token.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { TransportMethod } from '../../types/transport-request'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; @@ -62,7 +60,7 @@ type ServiceResponse = { * * @internal */ -export class RevokeTokenRequest extends AbstractRequest { +export class RevokeTokenRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.DELETE }); } @@ -77,16 +75,7 @@ export class RevokeTokenRequest extends AbstractRequest } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return {}; + return super.parse(response).then((_) => ({})); } protected get path(): string { diff --git a/src/core/endpoints/actions/add_message_action.ts b/src/core/endpoints/actions/add_message_action.ts index 75d3488e2..10f06e8f4 100644 --- a/src/core/endpoints/actions/add_message_action.ts +++ b/src/core/endpoints/actions/add_message_action.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { TransportMethod } from '../../types/transport-request'; import * as MessageAction from '../../types/api/message-action'; import { AbstractRequest } from '../../components/request'; @@ -50,7 +48,7 @@ type ServiceResponse = { * * @internal */ -export class AddMessageActionRequest extends AbstractRequest { +export class AddMessageActionRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.POST }); } @@ -77,16 +75,7 @@ export class AddMessageActionRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return { data: serviceResponse.data }; + return super.parse(response).then(({ data }) => ({ data })); } protected get path(): string { diff --git a/src/core/endpoints/actions/get_message_actions.ts b/src/core/endpoints/actions/get_message_actions.ts index 5c72a63fc..66b12ac17 100644 --- a/src/core/endpoints/actions/get_message_actions.ts +++ b/src/core/endpoints/actions/get_message_actions.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import * as MessageAction from '../../types/api/message-action'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; @@ -54,7 +52,10 @@ type ServiceResponse = { * * @internal */ -export class GetMessageActionsRequest extends AbstractRequest { +export class GetMessageActionsRequest extends AbstractRequest< + MessageAction.GetMessageActionsResponse, + ServiceResponse +> { constructor(private readonly parameters: RequestParameters) { super(); } @@ -69,15 +70,7 @@ export class GetMessageActionsRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - + const serviceResponse = this.deserializeResponse(response); let start: string | null = null; let end: string | null = null; diff --git a/src/core/endpoints/actions/remove_message_action.ts b/src/core/endpoints/actions/remove_message_action.ts index f6d6ee8ca..f17a7c916 100644 --- a/src/core/endpoints/actions/remove_message_action.ts +++ b/src/core/endpoints/actions/remove_message_action.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { TransportMethod } from '../../types/transport-request'; import * as MessageAction from '../../types/api/message-action'; import { AbstractRequest } from '../../components/request'; @@ -50,7 +48,7 @@ type ServiceResponse = { * * @internal */ -export class RemoveMessageAction extends AbstractRequest { +export class RemoveMessageAction extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.DELETE }); } @@ -74,16 +72,7 @@ export class RemoveMessageAction extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return { data: serviceResponse.data }; + return super.parse(response).then(({ data }) => ({ data })); } protected get path(): string { diff --git a/src/core/endpoints/channel_groups/add_channels.ts b/src/core/endpoints/channel_groups/add_channels.ts index 49be453f2..32b1cce76 100644 --- a/src/core/endpoints/channel_groups/add_channels.ts +++ b/src/core/endpoints/channel_groups/add_channels.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import * as ChannelGroups from '../../types/api/channel-groups'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; @@ -59,7 +57,10 @@ type ServiceResponse = { * * @internal */ -export class AddChannelGroupChannelsRequest extends AbstractRequest { +export class AddChannelGroupChannelsRequest extends AbstractRequest< + ChannelGroups.ManageChannelGroupChannelsResponse, + ServiceResponse +> { constructor(private readonly parameters: RequestParameters) { super(); } @@ -81,16 +82,7 @@ export class AddChannelGroupChannelsRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return {}; + return super.parse(response).then((_) => ({})); } protected get path(): string { diff --git a/src/core/endpoints/channel_groups/delete_group.ts b/src/core/endpoints/channel_groups/delete_group.ts index 6426177c9..9d2259733 100644 --- a/src/core/endpoints/channel_groups/delete_group.ts +++ b/src/core/endpoints/channel_groups/delete_group.ts @@ -4,14 +4,12 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import * as ChannelGroups from '../../types/api/channel-groups'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; -import { KeySet } from '../../types/api'; import { encodeString } from '../../utils'; +import { KeySet } from '../../types/api'; // -------------------------------------------------------- // ------------------------ Types ------------------------- @@ -59,7 +57,10 @@ type ServiceResponse = { * * @internal */ -export class DeleteChannelGroupRequest extends AbstractRequest { +export class DeleteChannelGroupRequest extends AbstractRequest< + ChannelGroups.DeleteChannelGroupResponse, + ServiceResponse +> { constructor(private readonly parameters: RequestParameters) { super(); } @@ -74,16 +75,7 @@ export class DeleteChannelGroupRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return {}; + return super.parse(response).then((_) => ({})); } protected get path(): string { diff --git a/src/core/endpoints/channel_groups/list_channels.ts b/src/core/endpoints/channel_groups/list_channels.ts index 470594660..848c5b373 100644 --- a/src/core/endpoints/channel_groups/list_channels.ts +++ b/src/core/endpoints/channel_groups/list_channels.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import * as ChannelGroups from '../../types/api/channel-groups'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; @@ -74,7 +72,10 @@ type ServiceResponse = { * * @internal */ -export class ListChannelGroupChannels extends AbstractRequest { +export class ListChannelGroupChannels extends AbstractRequest< + ChannelGroups.ListChannelGroupChannelsResponse, + ServiceResponse +> { constructor(private readonly parameters: RequestParameters) { super(); } @@ -89,16 +90,7 @@ export class ListChannelGroupChannels extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return { channels: serviceResponse.payload.channels }; + return { channels: this.deserializeResponse(response).payload.channels }; } protected get path(): string { diff --git a/src/core/endpoints/channel_groups/list_groups.ts b/src/core/endpoints/channel_groups/list_groups.ts index 1b3659e23..598793b59 100644 --- a/src/core/endpoints/channel_groups/list_groups.ts +++ b/src/core/endpoints/channel_groups/list_groups.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import * as ChannelGroups from '../../types/api/channel-groups'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; @@ -73,7 +71,10 @@ type ServiceResponse = { * * @internal */ -export class ListChannelGroupsRequest extends AbstractRequest { +export class ListChannelGroupsRequest extends AbstractRequest< + ChannelGroups.ListAllChannelGroupsResponse, + ServiceResponse +> { constructor(private readonly parameters: RequestParameters) { super(); } @@ -87,16 +88,7 @@ export class ListChannelGroupsRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return { groups: serviceResponse.payload.groups }; + return { groups: this.deserializeResponse(response).payload.groups }; } protected get path(): string { diff --git a/src/core/endpoints/channel_groups/remove_channels.ts b/src/core/endpoints/channel_groups/remove_channels.ts index d960f9275..ecbb76489 100644 --- a/src/core/endpoints/channel_groups/remove_channels.ts +++ b/src/core/endpoints/channel_groups/remove_channels.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import * as ChannelGroups from '../../types/api/channel-groups'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; @@ -61,7 +59,8 @@ type ServiceResponse = { */ // prettier-ignore export class RemoveChannelGroupChannelsRequest extends AbstractRequest< - ChannelGroups.ManageChannelGroupChannelsResponse + ChannelGroups.ManageChannelGroupChannelsResponse, + ServiceResponse > { constructor(private readonly parameters: RequestParameters) { super(); @@ -84,16 +83,7 @@ export class RemoveChannelGroupChannelsRequest extends AbstractRequest< } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return {}; + return super.parse(response).then((_) => ({})); } protected get path(): string { diff --git a/src/core/endpoints/fetch_messages.ts b/src/core/endpoints/fetch_messages.ts index 0ec208996..da9963882 100644 --- a/src/core/endpoints/fetch_messages.ts +++ b/src/core/endpoints/fetch_messages.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../errors/pubnub-error'; import { TransportResponse } from '../types/transport-response'; -import { PubNubAPIError } from '../../errors/pubnub-api-error'; import { ICryptoModule } from '../interfaces/crypto-module'; import { AbstractRequest } from '../components/request'; import * as FileSharing from '../types/api/file-sharing'; @@ -172,7 +170,7 @@ type ServiceResponse = { * * @internal */ -export class FetchMessagesRequest extends AbstractRequest { +export class FetchMessagesRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -213,15 +211,7 @@ export class FetchMessagesRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - + const serviceResponse = this.deserializeResponse(response); const responseChannels = serviceResponse.channels ?? {}; const channels: History.FetchMessagesResponse['channels'] = {}; diff --git a/src/core/endpoints/file_upload/delete_file.ts b/src/core/endpoints/file_upload/delete_file.ts index 71617b36a..e740a8e75 100644 --- a/src/core/endpoints/file_upload/delete_file.ts +++ b/src/core/endpoints/file_upload/delete_file.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; -import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { TransportMethod } from '../../types/transport-request'; import { AbstractRequest } from '../../components/request'; import * as FileSharing from '../../types/api/file-sharing'; @@ -45,7 +42,7 @@ type ServiceResponse = { * * @internal */ -export class DeleteFileRequest extends AbstractRequest { +export class DeleteFileRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.DELETE }); } @@ -62,19 +59,6 @@ export class DeleteFileRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/file_upload/download_file.ts b/src/core/endpoints/file_upload/download_file.ts index 90055d25d..4a0674d38 100644 --- a/src/core/endpoints/file_upload/download_file.ts +++ b/src/core/endpoints/file_upload/download_file.ts @@ -52,7 +52,7 @@ type RequestParameters = FileSharing.DownloadFileParameters & { */ export class DownloadFileRequest< PlatformFile extends Partial = Record, -> extends AbstractRequest { +> extends AbstractRequest> { constructor(private readonly parameters: RequestParameters) { super(); } diff --git a/src/core/endpoints/file_upload/generate_upload_url.ts b/src/core/endpoints/file_upload/generate_upload_url.ts index b71ebf798..66c87379a 100644 --- a/src/core/endpoints/file_upload/generate_upload_url.ts +++ b/src/core/endpoints/file_upload/generate_upload_url.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { TransportMethod } from '../../types/transport-request'; import { AbstractRequest } from '../../components/request'; import * as FileSharing from '../../types/api/file-sharing'; @@ -105,7 +103,10 @@ type ServiceResponse = { * * @internal */ -export class GenerateFileUploadUrlRequest extends AbstractRequest { +export class GenerateFileUploadUrlRequest extends AbstractRequest< + FileSharing.GenerateFileUploadUrlResponse, + ServiceResponse +> { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.POST }); } @@ -120,14 +121,7 @@ export class GenerateFileUploadUrlRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + const serviceResponse = this.deserializeResponse(response); return { id: serviceResponse.data.id, diff --git a/src/core/endpoints/file_upload/get_file_url.ts b/src/core/endpoints/file_upload/get_file_url.ts index b81f4c91b..754109f52 100644 --- a/src/core/endpoints/file_upload/get_file_url.ts +++ b/src/core/endpoints/file_upload/get_file_url.ts @@ -35,7 +35,7 @@ type RequestParameters = FileSharing.FileUrlParameters & { * * @internal */ -export class GetFileDownloadUrlRequest extends AbstractRequest { +export class GetFileDownloadUrlRequest extends AbstractRequest> { /** * Construct file download Url generation request. * diff --git a/src/core/endpoints/file_upload/list_files.ts b/src/core/endpoints/file_upload/list_files.ts index 3949e05a4..091c7a9b1 100644 --- a/src/core/endpoints/file_upload/list_files.ts +++ b/src/core/endpoints/file_upload/list_files.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; -import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import * as FileSharing from '../../types/api/file-sharing'; import RequestOperation from '../../constants/operations'; @@ -70,7 +67,7 @@ type ServiceResponse = { * * @internal */ -export class FilesListRequest extends AbstractRequest { +export class FilesListRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -86,19 +83,6 @@ export class FilesListRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/file_upload/publish_file.ts b/src/core/endpoints/file_upload/publish_file.ts index 21784b89b..c836638bd 100644 --- a/src/core/endpoints/file_upload/publish_file.ts +++ b/src/core/endpoints/file_upload/publish_file.ts @@ -4,7 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; import { ICryptoModule } from '../../interfaces/crypto-module'; import { AbstractRequest } from '../../components/request'; @@ -56,7 +55,10 @@ type ServiceResponse = [0 | 1, string, string]; * * @internal */ -export class PublishFileMessageRequest extends AbstractRequest { +export class PublishFileMessageRequest extends AbstractRequest< + FileSharing.PublishFileMessageResponse, + ServiceResponse +> { constructor(private readonly parameters: RequestParameters) { super(); @@ -77,15 +79,7 @@ export class PublishFileMessageRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - - return { timetoken: serviceResponse[2] }; + return { timetoken: this.deserializeResponse(response)[2] }; } protected get path(): string { diff --git a/src/core/endpoints/file_upload/send_file.ts b/src/core/endpoints/file_upload/send_file.ts index 177dcba73..b991c4742 100644 --- a/src/core/endpoints/file_upload/send_file.ts +++ b/src/core/endpoints/file_upload/send_file.ts @@ -6,16 +6,16 @@ import { PubNubFileConstructor, PubNubFileInterface } from '../../types/file'; import { GenerateFileUploadUrlRequest } from './generate_upload_url'; +import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { ICryptoModule } from '../../interfaces/crypto-module'; import { Cryptography } from '../../interfaces/cryptography'; import { AbstractRequest } from '../../components/request'; import * as FileSharing from '../../types/api/file-sharing'; import { PubNubError } from '../../../errors/pubnub-error'; import RequestOperation from '../../constants/operations'; +import StatusCategory from '../../constants/categories'; import { UploadFileRequest } from './upload-file'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { KeySet } from '../../types/api'; -import StatusCategory from '../../constants/categories'; // -------------------------------------------------------- // ------------------------ Types ------------------------- @@ -46,7 +46,7 @@ type RequestParameters = FileSharing.SendFileParameters(request: AbstractRequest) => Promise; + sendRequest: (request: AbstractRequest>) => Promise; /** * File message publish method. diff --git a/src/core/endpoints/file_upload/upload-file.ts b/src/core/endpoints/file_upload/upload-file.ts index 7c2b0e0b8..a1ef99507 100644 --- a/src/core/endpoints/file_upload/upload-file.ts +++ b/src/core/endpoints/file_upload/upload-file.ts @@ -4,8 +4,8 @@ * @internal */ -import { TransportResponse } from '../../types/transport-response'; import { TransportMethod, TransportRequest } from '../../types/transport-request'; +import { TransportResponse } from '../../types/transport-response'; import { AbstractRequest } from '../../components/request'; import * as FileSharing from '../../types/api/file-sharing'; import RequestOperation from '../../constants/operations'; @@ -16,7 +16,7 @@ import { PubNubFileInterface } from '../../types/file'; * * @internal */ -export class UploadFileRequest extends AbstractRequest { +export class UploadFileRequest extends AbstractRequest> { constructor(private readonly parameters: FileSharing.UploadFileParameters) { super({ method: TransportMethod.POST }); diff --git a/src/core/endpoints/history/delete_messages.ts b/src/core/endpoints/history/delete_messages.ts index 1964d982f..e4639fc2a 100644 --- a/src/core/endpoints/history/delete_messages.ts +++ b/src/core/endpoints/history/delete_messages.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import type { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { TransportMethod } from '../../types/transport-request'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; @@ -55,7 +53,7 @@ type ServiceResponse = { * * @internal */ -export class DeleteMessageRequest extends AbstractRequest { +export class DeleteMessageRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.DELETE }); } @@ -70,16 +68,7 @@ export class DeleteMessageRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return {}; + return super.parse(response).then((_) => ({})); } protected get path(): string { diff --git a/src/core/endpoints/history/get_history.ts b/src/core/endpoints/history/get_history.ts index a8d82043a..99c970c96 100644 --- a/src/core/endpoints/history/get_history.ts +++ b/src/core/endpoints/history/get_history.ts @@ -4,7 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; import { ICryptoModule } from '../../interfaces/crypto-module'; import { AbstractRequest } from '../../components/request'; @@ -108,7 +107,7 @@ type ServiceResponse = [ * * @internal */ -export class GetHistoryRequest extends AbstractRequest { +export class GetHistoryRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -131,14 +130,7 @@ export class GetHistoryRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - + const serviceResponse = this.deserializeResponse(response); const messages = serviceResponse[0]; const startTimeToken = serviceResponse[1]; const endTimeToken = serviceResponse[2]; diff --git a/src/core/endpoints/history/message_counts.ts b/src/core/endpoints/history/message_counts.ts index 43d92d0bc..6e1c32d3d 100644 --- a/src/core/endpoints/history/message_counts.ts +++ b/src/core/endpoints/history/message_counts.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import * as History from '../../types/api/history'; @@ -75,7 +73,7 @@ type ServiceResponse = { * * @internal */ -export class MessageCountRequest extends AbstractRequest { +export class MessageCountRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); } @@ -101,16 +99,7 @@ export class MessageCountRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return { channels: serviceResponse.channels }; + return { channels: this.deserializeResponse(response).channels }; } protected get path(): string { diff --git a/src/core/endpoints/objects/channel/get.ts b/src/core/endpoints/objects/channel/get.ts index 9748609e6..d2b37378e 100644 --- a/src/core/endpoints/objects/channel/get.ts +++ b/src/core/endpoints/objects/channel/get.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; import * as AppContext from '../../../types/api/app-context'; @@ -48,7 +45,7 @@ type RequestParameters = AppContext.GetChannelMetadataParameters & { export class GetChannelMetadataRequest< Response extends AppContext.GetChannelMetadataResponse, Custom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -65,19 +62,6 @@ export class GetChannelMetadataRequest< if (!this.parameters.channel) return 'Channel cannot be empty'; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/objects/channel/get_all.ts b/src/core/endpoints/objects/channel/get_all.ts index 8adaf8f42..f7af5889e 100644 --- a/src/core/endpoints/objects/channel/get_all.ts +++ b/src/core/endpoints/objects/channel/get_all.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; import * as AppContext from '../../../types/api/app-context'; @@ -58,7 +55,7 @@ type RequestParameters, Custom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -73,19 +70,6 @@ export class GetAllChannelsMetadataRequest< return RequestOperation.PNGetAllChannelMetadataOperation; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { return `/v2/objects/${this.parameters.keySet.subscribeKey}/channels`; } diff --git a/src/core/endpoints/objects/channel/remove.ts b/src/core/endpoints/objects/channel/remove.ts index 440517d7d..79c2bad7c 100644 --- a/src/core/endpoints/objects/channel/remove.ts +++ b/src/core/endpoints/objects/channel/remove.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { TransportMethod } from '../../../types/transport-request'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; @@ -37,7 +34,7 @@ type RequestParameters = AppContext.RemoveChannelMetadataParameters & { */ export class RemoveChannelMetadataRequest< Response extends AppContext.RemoveChannelMetadataResponse, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.DELETE }); } @@ -50,19 +47,6 @@ export class RemoveChannelMetadataRequest< if (!this.parameters.channel) return 'Channel cannot be empty'; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/objects/channel/set.ts b/src/core/endpoints/objects/channel/set.ts index dd82075b6..65a96cfc6 100644 --- a/src/core/endpoints/objects/channel/set.ts +++ b/src/core/endpoints/objects/channel/set.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { TransportMethod } from '../../../types/transport-request'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; @@ -49,7 +46,7 @@ type RequestParameters = AppContext.SetChannelMetadataParameters, Custom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.PATCH }); @@ -75,19 +72,6 @@ export class SetChannelMetadataRequest< } } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/objects/member/get.ts b/src/core/endpoints/objects/member/get.ts index da0ffecc5..04a96826a 100644 --- a/src/core/endpoints/objects/member/get.ts +++ b/src/core/endpoints/objects/member/get.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; import * as AppContext from '../../../types/api/app-context'; @@ -89,7 +86,7 @@ export class GetChannelMembersRequest< Response extends AppContext.GetMembersResponse, MembersCustom extends AppContext.CustomData = AppContext.CustomData, UUIDCustom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -114,19 +111,6 @@ export class GetChannelMembersRequest< if (!this.parameters.channel) return 'Channel cannot be empty'; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/objects/member/set.ts b/src/core/endpoints/objects/member/set.ts index f29889a8a..56a5ccc5f 100644 --- a/src/core/endpoints/objects/member/set.ts +++ b/src/core/endpoints/objects/member/set.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { TransportMethod } from '../../../types/transport-request'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; @@ -95,7 +92,7 @@ export class SetChannelMembersRequest< Response extends AppContext.SetMembersResponse, MembersCustom extends AppContext.CustomData = AppContext.CustomData, UUIDCustom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.PATCH }); @@ -123,19 +120,6 @@ export class SetChannelMembersRequest< if (!uuids || uuids.length === 0) return 'UUIDs cannot be empty'; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/objects/membership/get.ts b/src/core/endpoints/objects/membership/get.ts index 89850ec1f..6a647862f 100644 --- a/src/core/endpoints/objects/membership/get.ts +++ b/src/core/endpoints/objects/membership/get.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; import * as AppContext from '../../../types/api/app-context'; @@ -89,7 +86,7 @@ export class GetUUIDMembershipsRequest< Response extends AppContext.GetMembershipsResponse, MembersCustom extends AppContext.CustomData = AppContext.CustomData, UUIDCustom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -117,19 +114,6 @@ export class GetUUIDMembershipsRequest< if (!this.parameters.uuid) return "'uuid' cannot be empty"; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/objects/membership/set.ts b/src/core/endpoints/objects/membership/set.ts index fa2cecc73..9971c5e58 100644 --- a/src/core/endpoints/objects/membership/set.ts +++ b/src/core/endpoints/objects/membership/set.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { TransportMethod } from '../../../types/transport-request'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; @@ -95,7 +92,7 @@ export class SetUUIDMembershipsRequest< Response extends AppContext.SetMembershipsResponse, MembersCustom extends AppContext.CustomData = AppContext.CustomData, UUIDCustom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.PATCH }); @@ -126,19 +123,6 @@ export class SetUUIDMembershipsRequest< if (!channels || channels.length === 0) return 'Channels cannot be empty'; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/objects/uuid/get.ts b/src/core/endpoints/objects/uuid/get.ts index 9c3e22781..6642574c4 100644 --- a/src/core/endpoints/objects/uuid/get.ts +++ b/src/core/endpoints/objects/uuid/get.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; import * as AppContext from '../../../types/api/app-context'; @@ -48,7 +45,7 @@ type RequestParameters = AppContext.GetUUIDMetadataParameters & { export class GetUUIDMetadataRequest< Response extends AppContext.GetUUIDMetadataResponse, Custom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -68,19 +65,6 @@ export class GetUUIDMetadataRequest< if (!this.parameters.uuid) return "'uuid' cannot be empty"; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/objects/uuid/get_all.ts b/src/core/endpoints/objects/uuid/get_all.ts index e2b86be3c..a637a1279 100644 --- a/src/core/endpoints/objects/uuid/get_all.ts +++ b/src/core/endpoints/objects/uuid/get_all.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; import * as AppContext from '../../../types/api/app-context'; @@ -53,7 +50,7 @@ type RequestParameters, Custom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -67,19 +64,6 @@ export class GetAllUUIDMetadataRequest< return RequestOperation.PNGetAllUUIDMetadataOperation; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { return `/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`; } diff --git a/src/core/endpoints/objects/uuid/remove.ts b/src/core/endpoints/objects/uuid/remove.ts index 09afb9b2b..7d1f817bb 100644 --- a/src/core/endpoints/objects/uuid/remove.ts +++ b/src/core/endpoints/objects/uuid/remove.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { TransportMethod } from '../../../types/transport-request'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; @@ -35,9 +32,10 @@ type RequestParameters = AppContext.RemoveUUIDMetadataParameters & { * * @internal */ -export class RemoveUUIDMetadataRequest< - Response extends AppContext.RemoveUUIDMetadataResponse, -> extends AbstractRequest { +export class RemoveUUIDMetadataRequest extends AbstractRequest< + Response, + Response +> { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.DELETE }); @@ -53,19 +51,6 @@ export class RemoveUUIDMetadataRequest< if (!this.parameters.uuid) return "'uuid' cannot be empty"; } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/objects/uuid/set.ts b/src/core/endpoints/objects/uuid/set.ts index 879689a76..17be16d55 100644 --- a/src/core/endpoints/objects/uuid/set.ts +++ b/src/core/endpoints/objects/uuid/set.ts @@ -4,9 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../../errors/pubnub-error'; -import { TransportResponse } from '../../../types/transport-response'; -import { PubNubAPIError } from '../../../../errors/pubnub-api-error'; import { TransportMethod } from '../../../types/transport-request'; import { AbstractRequest } from '../../../components/request'; import RequestOperation from '../../../constants/operations'; @@ -49,7 +46,7 @@ type RequestParameters = AppContext.SetUUIDMetadataParameters, Custom extends AppContext.CustomData = AppContext.CustomData, -> extends AbstractRequest { +> extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super({ method: TransportMethod.PATCH }); @@ -78,19 +75,6 @@ export class SetUUIDMetadataRequest< } } - async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return serviceResponse; - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/presence/get_state.ts b/src/core/endpoints/presence/get_state.ts index 496f5e471..ab7905ad3 100644 --- a/src/core/endpoints/presence/get_state.ts +++ b/src/core/endpoints/presence/get_state.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import { KeySet, Payload, Query } from '../../types/api'; @@ -64,7 +62,7 @@ type ServiceResponse = { * * @internal */ -export class GetPresenceStateRequest extends AbstractRequest { +export class GetPresenceStateRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -88,15 +86,7 @@ export class GetPresenceStateRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - + const serviceResponse = this.deserializeResponse(response); const { channels = [], channelGroups = [] } = this.parameters; const state: { channels: Record } = { channels: {} }; diff --git a/src/core/endpoints/presence/heartbeat.ts b/src/core/endpoints/presence/heartbeat.ts index 76eeb903a..ab4513fff 100644 --- a/src/core/endpoints/presence/heartbeat.ts +++ b/src/core/endpoints/presence/heartbeat.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import * as Presence from '../../types/api/presence'; @@ -54,7 +52,7 @@ type ServiceResponse = { * * @internal */ -export class HeartbeatRequest extends AbstractRequest { +export class HeartbeatRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); } @@ -76,16 +74,7 @@ export class HeartbeatRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return {}; + return super.parse(response).then((_) => ({})); } protected get path(): string { diff --git a/src/core/endpoints/presence/here_now.ts b/src/core/endpoints/presence/here_now.ts index a8dacb4d9..e4bea8ade 100644 --- a/src/core/endpoints/presence/here_now.ts +++ b/src/core/endpoints/presence/here_now.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import { KeySet, Payload, Query } from '../../types/api'; @@ -131,7 +129,7 @@ type ServiceResponse = SingleChannelServiceResponse | MultipleChannelServiceResp * * @internal */ -export class HereNowRequest extends AbstractRequest { +export class HereNowRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -153,15 +151,7 @@ export class HereNowRequest extends AbstractRequest { } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - + const serviceResponse = this.deserializeResponse(response); // Extract general presence information. const totalChannels = 'occupancy' in serviceResponse ? 1 : serviceResponse.payload.total_channels; const totalOccupancy = diff --git a/src/core/endpoints/presence/leave.ts b/src/core/endpoints/presence/leave.ts index 471354028..0fd4c9894 100644 --- a/src/core/endpoints/presence/leave.ts +++ b/src/core/endpoints/presence/leave.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import * as Presence from '../../types/api/presence'; @@ -59,7 +57,7 @@ type ServiceResponse = { * * @internal */ -export class PresenceLeaveRequest extends AbstractRequest { +export class PresenceLeaveRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -85,16 +83,7 @@ export class PresenceLeaveRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return {}; + return super.parse(response).then((_) => ({})); } protected get path(): string { diff --git a/src/core/endpoints/presence/set_state.ts b/src/core/endpoints/presence/set_state.ts index 989ddbf1c..2bd2aec08 100644 --- a/src/core/endpoints/presence/set_state.ts +++ b/src/core/endpoints/presence/set_state.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import { KeySet, Payload, Query } from '../../types/api'; @@ -64,7 +62,7 @@ type ServiceResponse = { * * @internal */ -export class SetPresenceStateRequest extends AbstractRequest { +export class SetPresenceStateRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); } @@ -88,16 +86,7 @@ export class SetPresenceStateRequest extends AbstractRequest { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); - - return { state: serviceResponse.payload }; + return { state: this.deserializeResponse(response).payload }; } protected get path(): string { diff --git a/src/core/endpoints/presence/where_now.ts b/src/core/endpoints/presence/where_now.ts index dfd12e8d8..828ec5e0b 100644 --- a/src/core/endpoints/presence/where_now.ts +++ b/src/core/endpoints/presence/where_now.ts @@ -4,9 +4,7 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; -import { PubNubAPIError } from '../../../errors/pubnub-api-error'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import * as Presence from '../../types/api/presence'; @@ -64,7 +62,7 @@ type ServiceResponse = { * * @internal */ -export class WhereNowRequest extends AbstractRequest { +export class WhereNowRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); } @@ -78,19 +76,13 @@ export class WhereNowRequest extends AbstractRequest } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) { - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - } else if (serviceResponse.status >= 400) throw PubNubAPIError.create(response); + const serviceResponse = this.deserializeResponse(response); if (!serviceResponse.payload) return { channels: [] }; return { channels: serviceResponse.payload.channels }; } + protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/publish.ts b/src/core/endpoints/publish.ts index 6d0bfb3b5..14683c025 100644 --- a/src/core/endpoints/publish.ts +++ b/src/core/endpoints/publish.ts @@ -2,7 +2,6 @@ * Publish REST API module. */ -import { createValidationError, PubNubError } from '../../errors/pubnub-error'; import { TransportResponse } from '../types/transport-response'; import { TransportMethod } from '../types/transport-request'; import { ICryptoModule } from '../interfaces/crypto-module'; @@ -133,7 +132,7 @@ type ServiceResponse = [0 | 1, string, string]; * * @internal */ -export class PublishRequest extends AbstractRequest { +export class PublishRequest extends AbstractRequest { /** * Construct data publish request. * @@ -163,15 +162,7 @@ export class PublishRequest extends AbstractRequest { } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - - return { timetoken: serviceResponse[2] }; + return { timetoken: this.deserializeResponse(response)[2] }; } protected get path(): string { @@ -197,6 +188,7 @@ export class PublishRequest extends AbstractRequest { } protected get headers(): Record | undefined { + if (!this.parameters.sendByPost) return undefined; return { 'Content-Type': 'application/json' }; } diff --git a/src/core/endpoints/push/add_push_channels.ts b/src/core/endpoints/push/add_push_channels.ts index 9f665b5b3..fcad65603 100644 --- a/src/core/endpoints/push/add_push_channels.ts +++ b/src/core/endpoints/push/add_push_channels.ts @@ -4,7 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; import { BasePushNotificationChannelsRequest } from './push'; import RequestOperation from '../../constants/operations'; @@ -39,7 +38,8 @@ type ServiceResponse = [0 | 1, string]; */ // prettier-ignore export class AddDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest< - Push.ManageDeviceChannelsResponse + Push.ManageDeviceChannelsResponse, + ServiceResponse > { constructor(parameters: RequestParameters) { super({ ...parameters, action: 'add' }); @@ -50,14 +50,6 @@ export class AddDevicePushNotificationChannelsRequest extends BasePushNotificati } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - - return {}; + return super.parse(response).then((_) => ({})); } } diff --git a/src/core/endpoints/push/list_push_channels.ts b/src/core/endpoints/push/list_push_channels.ts index f1ad59b02..0362511eb 100644 --- a/src/core/endpoints/push/list_push_channels.ts +++ b/src/core/endpoints/push/list_push_channels.ts @@ -4,7 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; import { BasePushNotificationChannelsRequest } from './push'; import RequestOperation from '../../constants/operations'; @@ -39,7 +38,8 @@ type ServiceResponse = string[]; */ // prettier-ignore export class ListDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest< - Push.ListDeviceChannelsResponse + Push.ListDeviceChannelsResponse, + ServiceResponse > { constructor(parameters: RequestParameters) { super({ ...parameters, action: 'list' }); @@ -50,14 +50,6 @@ export class ListDevicePushNotificationChannelsRequest extends BasePushNotificat } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - - return { channels: serviceResponse }; + return { channels: this.deserializeResponse(response) }; } } diff --git a/src/core/endpoints/push/push.ts b/src/core/endpoints/push/push.ts index fdbe36d3d..f7c64e67f 100644 --- a/src/core/endpoints/push/push.ts +++ b/src/core/endpoints/push/push.ts @@ -4,7 +4,6 @@ * @internal */ -import { TransportResponse } from '../../types/transport-response'; import { AbstractRequest } from '../../components/request'; import RequestOperation from '../../constants/operations'; import { KeySet, Query } from '../../types/api'; @@ -52,7 +51,7 @@ type RequestParameters = (Push.ManageDeviceChannelsParameters | Push.RemoveDevic * * @internal */ -export class BasePushNotificationChannelsRequest extends AbstractRequest { +export class BasePushNotificationChannelsRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); @@ -85,10 +84,6 @@ export class BasePushNotificationChannelsRequest extends AbstractRequest { if (this.parameters.pushGateway === 'apns2' && !this.parameters.topic) return 'Missing APNS2 topic'; } - async parse(_response: TransportResponse): Promise { - throw Error('Should be implemented in subclass.'); - } - protected get path(): string { const { keySet: { subscribeKey }, diff --git a/src/core/endpoints/push/remove_device.ts b/src/core/endpoints/push/remove_device.ts index b1150eeea..e099f53a8 100644 --- a/src/core/endpoints/push/remove_device.ts +++ b/src/core/endpoints/push/remove_device.ts @@ -4,7 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; import { BasePushNotificationChannelsRequest } from './push'; import RequestOperation from '../../constants/operations'; @@ -39,7 +38,8 @@ type ServiceResponse = [0 | 1, string]; */ // prettier-ignore export class RemoveDevicePushNotificationRequest extends BasePushNotificationChannelsRequest< - Push.RemoveDeviceResponse + Push.RemoveDeviceResponse, + ServiceResponse > { constructor(parameters: RequestParameters) { super({ ...parameters, action: 'remove-device' }); @@ -50,14 +50,6 @@ export class RemoveDevicePushNotificationRequest extends BasePushNotificationCha } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - - return {}; + return super.parse(response).then((_) =>({})); } } diff --git a/src/core/endpoints/push/remove_push_channels.ts b/src/core/endpoints/push/remove_push_channels.ts index 88648952b..c43923bfd 100644 --- a/src/core/endpoints/push/remove_push_channels.ts +++ b/src/core/endpoints/push/remove_push_channels.ts @@ -4,7 +4,6 @@ * @internal */ -import { createValidationError, PubNubError } from '../../../errors/pubnub-error'; import { TransportResponse } from '../../types/transport-response'; import { BasePushNotificationChannelsRequest } from './push'; import RequestOperation from '../../constants/operations'; @@ -39,7 +38,8 @@ type ServiceResponse = [0 | 1, string]; */ // prettier-ignore export class RemoveDevicePushNotificationChannelsRequest extends BasePushNotificationChannelsRequest< - Push.ManageDeviceChannelsResponse + Push.ManageDeviceChannelsResponse, + ServiceResponse > { constructor(parameters: RequestParameters) { super({ ...parameters, action: 'remove' }); @@ -50,14 +50,6 @@ export class RemoveDevicePushNotificationChannelsRequest extends BasePushNotific } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - - return {}; + return super.parse(response).then((_) =>({})); } } diff --git a/src/core/endpoints/signal.ts b/src/core/endpoints/signal.ts index 7015c17ae..58d683b55 100644 --- a/src/core/endpoints/signal.ts +++ b/src/core/endpoints/signal.ts @@ -2,7 +2,6 @@ * Signal REST API module. */ -import { createValidationError, PubNubError } from '../../errors/pubnub-error'; import { TransportResponse } from '../types/transport-response'; import { AbstractRequest } from '../components/request'; import RequestOperation from '../constants/operations'; @@ -70,7 +69,7 @@ type ServiceResponse = [0 | 1, string, string]; * * @internal */ -export class SignalRequest extends AbstractRequest { +export class SignalRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { super(); } @@ -92,15 +91,7 @@ export class SignalRequest extends AbstractRequest { } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - - return { timetoken: serviceResponse[2] }; + return { timetoken: this.deserializeResponse(response)[2] }; } protected get path(): string { diff --git a/src/core/endpoints/subscribe.ts b/src/core/endpoints/subscribe.ts index 4af64fc70..f972115ac 100644 --- a/src/core/endpoints/subscribe.ts +++ b/src/core/endpoints/subscribe.ts @@ -2,7 +2,7 @@ * Subscription REST API module. */ -import { createValidationError, PubNubError } from '../../errors/pubnub-error'; +import { createMalformedResponseError, createValidationError, PubNubError } from '../../errors/pubnub-error'; import { TransportResponse } from '../types/transport-response'; import { ICryptoModule } from '../interfaces/crypto-module'; import * as Subscription from '../types/api/subscription'; @@ -603,7 +603,7 @@ export type SubscribeRequestParameters = Subscription.SubscribeParameters & { * * @internal */ -export class BaseSubscribeRequest extends AbstractRequest { +export class BaseSubscribeRequest extends AbstractRequest { constructor(protected readonly parameters: SubscribeRequestParameters) { super({ cancellable: true }); @@ -630,10 +630,11 @@ export class BaseSubscribeRequest extends AbstractRequest { let serviceResponse: ServiceResponse | undefined; + let responseText: string | undefined; try { - const json = AbstractRequest.decoder.decode(response.body); - const parsedJson = JSON.parse(json); + responseText = AbstractRequest.decoder.decode(response.body); + const parsedJson = JSON.parse(responseText); serviceResponse = parsedJson as ServiceResponse; } catch (error) { console.error('Error parsing JSON response:', error); @@ -642,7 +643,7 @@ export class BaseSubscribeRequest extends AbstractRequest { +export class TimeRequest extends AbstractRequest { constructor() { super(); } @@ -43,15 +42,7 @@ export class TimeRequest extends AbstractRequest { } async parse(response: TransportResponse): Promise { - const serviceResponse = this.deserializeResponse(response); - - if (!serviceResponse) - throw new PubNubError( - 'Service response error, check status for details', - createValidationError('Unable to deserialize service response'), - ); - - return { timetoken: serviceResponse[0] }; + return { timetoken: this.deserializeResponse(response)[0] }; } protected get path(): string { diff --git a/src/core/pubnub-channel-groups.ts b/src/core/pubnub-channel-groups.ts index 908c60d54..870763a2f 100644 --- a/src/core/pubnub-channel-groups.ts +++ b/src/core/pubnub-channel-groups.ts @@ -27,7 +27,7 @@ export default class PubNubChannelGroups { * * @internal */ - private readonly sendRequest: SendRequestFunction; + private readonly sendRequest: SendRequestFunction; /** * Create stream / channel group API access object. @@ -40,7 +40,7 @@ export default class PubNubChannelGroups { constructor( keySet: KeySet, /* eslint-disable @typescript-eslint/no-explicit-any */ - sendRequest: SendRequestFunction, + sendRequest: SendRequestFunction, ) { this.sendRequest = sendRequest; this.keySet = keySet; diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index fad5a3a75..0fc402dc0 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -764,8 +764,8 @@ export class PubNubCore< * * @internal */ - private sendRequest( - request: AbstractRequest, + private sendRequest( + request: AbstractRequest, callback: ResultCallback, ): void; @@ -778,7 +778,9 @@ export class PubNubCore< * * @returns Asynchronous request execution and response parsing result. */ - private async sendRequest(request: AbstractRequest): Promise; + private async sendRequest( + request: AbstractRequest, + ): Promise; /** * Schedule request execution. @@ -793,8 +795,8 @@ export class PubNubCore< * * @throws PubNubError in case of request processing error. */ - private async sendRequest( - request: AbstractRequest, + private async sendRequest( + request: AbstractRequest, callback?: ResultCallback, ): Promise { // Validate user-input. @@ -846,12 +848,13 @@ export class PubNubCore< // Handle special case when request completed but not fully processed by PubNub service. if (response.status !== 200 && response.status !== 204) { + const responseText = PubNubCore.decoder.decode(response.body); const contentType = response.headers['content-type']; if (contentType || contentType.indexOf('javascript') !== -1 || contentType.indexOf('json') !== -1) { - const json = JSON.parse(PubNubCore.decoder.decode(response.body)) as Payload; + const json = JSON.parse(responseText) as Payload; if (typeof json === 'object' && 'error' in json && json.error && typeof json.error === 'object') status.errorData = json.error; - } + } else status.responseText = responseText; } return request.parse(response); @@ -1203,7 +1206,7 @@ export class PubNubCore< */ if (this.subscriptionManager) { // Creating identifiable abort caller. - const callableAbort = () => request.abort(); + const callableAbort = () => request.abort('Cancel long-poll subscribe request'); callableAbort.identifier = request.requestIdentifier; this.subscriptionManager.abort = callableAbort; @@ -1297,7 +1300,7 @@ export class PubNubCore< }); const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); + request.abort('Cancel subscribe handshake request'); }); /** @@ -1331,7 +1334,7 @@ export class PubNubCore< }); const abortUnsubscribe = parameters.abortSignal.subscribe((err) => { - request.abort(); + request.abort('Cancel long-poll subscribe request'); }); /** @@ -1340,8 +1343,8 @@ export class PubNubCore< * **Note:** Had to be done after scheduling because transport provider return cancellation * controller only when schedule new request. */ - const handshakeResponse = this.sendRequest(request); - return handshakeResponse.then((response) => { + const receiveResponse = this.sendRequest(request); + return receiveResponse.then((response) => { abortUnsubscribe(); return response; }); @@ -1857,7 +1860,10 @@ export class PubNubCore< if (process.env.PRESENCE_MODULE !== 'disabled') { const { keySet, userId: userId } = this._configuration; const heartbeat = this._configuration.getPresenceTimeout(); - let request: AbstractRequest; + let request: AbstractRequest< + Presence.PresenceHeartbeatResponse | Presence.SetPresenceStateResponse, + Record + >; // Maintain presence information (if required). if (this._configuration.enableEventEngine && this.presenceState) { diff --git a/src/core/pubnub-objects.ts b/src/core/pubnub-objects.ts index b4587f76f..7113bdced 100644 --- a/src/core/pubnub-objects.ts +++ b/src/core/pubnub-objects.ts @@ -36,7 +36,7 @@ export default class PubNubObjects { * * @internal */ - private readonly sendRequest: SendRequestFunction; + private readonly sendRequest: SendRequestFunction; /** * REST API endpoints access credentials. * @@ -55,7 +55,7 @@ export default class PubNubObjects { constructor( configuration: PrivateClientConfiguration, /* eslint-disable @typescript-eslint/no-explicit-any */ - sendRequest: SendRequestFunction, + sendRequest: SendRequestFunction, ) { this.keySet = configuration.keySet; this.configuration = configuration; diff --git a/src/core/pubnub-push.ts b/src/core/pubnub-push.ts index c994533ac..eb53d2fc7 100644 --- a/src/core/pubnub-push.ts +++ b/src/core/pubnub-push.ts @@ -27,7 +27,7 @@ export default class PubNubPushNotifications { * * @internal */ - private readonly sendRequest: SendRequestFunction; + private readonly sendRequest: SendRequestFunction; /** * Create mobile push notifications API access object. @@ -40,7 +40,7 @@ export default class PubNubPushNotifications { constructor( keySet: KeySet, /* eslint-disable @typescript-eslint/no-explicit-any */ - sendRequest: SendRequestFunction, + sendRequest: SendRequestFunction, ) { this.sendRequest = sendRequest; this.keySet = keySet; diff --git a/src/core/types/api/index.ts b/src/core/types/api/index.ts index 0f85c95f8..172660476 100644 --- a/src/core/types/api/index.ts +++ b/src/core/types/api/index.ts @@ -31,8 +31,8 @@ export type KeySet = { * * @internal */ -export type SendRequestFunction = ( - request: AbstractRequest, +export type SendRequestFunction = ( + request: AbstractRequest, callback?: ResultCallback, ) => Promise; diff --git a/src/core/types/transport-request.ts b/src/core/types/transport-request.ts index 582dc640c..e2bcc62e7 100644 --- a/src/core/types/transport-request.ts +++ b/src/core/types/transport-request.ts @@ -39,7 +39,7 @@ export type CancellationController = { /** * Request cancellation / abort function. */ - abort: () => void; + abort: (reason?: string) => void; }; /** diff --git a/src/errors/pubnub-api-error.ts b/src/errors/pubnub-api-error.ts index 6f7c4d3de..2b948be64 100644 --- a/src/errors/pubnub-api-error.ts +++ b/src/errors/pubnub-api-error.ts @@ -121,20 +121,27 @@ export class PubNubAPIError extends Error { try { const errorResponse: Payload = JSON.parse(decoded); - if (typeof errorResponse === 'object' && !Array.isArray(errorResponse)) { - if ( - 'error' in errorResponse && - (errorResponse.error === 1 || errorResponse.error === true) && - 'status' in errorResponse && - typeof errorResponse.status === 'number' && - 'message' in errorResponse && - 'service' in errorResponse - ) { - errorData = errorResponse; - status = errorResponse.status; - } else errorData = errorResponse; - - if ('error' in errorResponse && errorResponse.error instanceof Error) errorData = errorResponse.error; + if (typeof errorResponse === 'object') { + if (!Array.isArray(errorResponse)) { + if ( + 'error' in errorResponse && + (errorResponse.error === 1 || errorResponse.error === true) && + 'status' in errorResponse && + typeof errorResponse.status === 'number' && + 'message' in errorResponse && + 'service' in errorResponse + ) { + errorData = errorResponse; + status = errorResponse.status; + } else errorData = errorResponse; + + if ('error' in errorResponse && errorResponse.error instanceof Error) errorData = errorResponse.error; + } else { + // Handling Publish API payload error. + if (typeof errorResponse[0] === 'number' && errorResponse[0] === 0) { + if (errorResponse.length > 1 && typeof errorResponse[1] === 'string') errorData = errorResponse[1]; + } + } } } catch (_) { errorData = decoded; diff --git a/src/errors/pubnub-error.ts b/src/errors/pubnub-error.ts index b3fee4d9b..69c1b174a 100644 --- a/src/errors/pubnub-error.ts +++ b/src/errors/pubnub-error.ts @@ -37,20 +37,15 @@ export class PubNubError extends Error { * Create error status object. * * @param errorPayload - Additional information which should be attached to the error status object. + * @param category - Occurred error category. * * @returns Error status object. * * @internal */ -function createError(errorPayload: { message: string; statusCode?: number }): Status { +function createError(errorPayload: { message: string; statusCode?: number }, category: StatusCategory): Status { errorPayload.statusCode ??= 0; - - return { - ...errorPayload, - statusCode: errorPayload.statusCode!, - category: StatusCategory.PNValidationErrorCategory, - error: true, - }; + return { ...errorPayload, statusCode: errorPayload.statusCode!, category, error: true }; } /** @@ -64,5 +59,25 @@ function createError(errorPayload: { message: string; statusCode?: number }): St * @internal */ export function createValidationError(message: string, statusCode?: number) { - return createError({ message, ...(statusCode !== undefined ? { statusCode } : {}) }); + return createError( + { message, ...(statusCode !== undefined ? { statusCode } : {}) }, + StatusCategory.PNValidationErrorCategory, + ); +} + +/** + * Create malformed service response error status object. + * + * @param [responseText] - Stringified original service response. + * @param [statusCode] - Operation HTTP status code. + */ +export function createMalformedResponseError(responseText?: string, statusCode?: number) { + return createError( + { + message: 'Unable to deserialize service response', + ...(responseText !== undefined ? { responseText } : {}), + ...(statusCode !== undefined ? { statusCode } : {}), + }, + StatusCategory.PNMalformedResponseCategory, + ); } diff --git a/src/transport/node-transport.ts b/src/transport/node-transport.ts index 2759f622b..a09f0b381 100644 --- a/src/transport/node-transport.ts +++ b/src/transport/node-transport.ts @@ -4,7 +4,7 @@ * @internal */ -import fetch, { Request, Response, RequestInit } from 'node-fetch'; +import fetch, { Request, Response, RequestInit, AbortError } from 'node-fetch'; import { ProxyAgent, ProxyAgentOptions } from 'proxy-agent'; import { Agent as HttpsAgent } from 'https'; import { Agent as HttpAgent } from 'http'; @@ -82,7 +82,10 @@ export class NodeTransport implements Transport { controller = { // Storing controller inside to prolong object lifetime. abortController, - abort: () => abortController?.abort(), + abort: (reason) => { + if (!abortController || abortController.signal.aborted) return; + abortController?.abort(reason); + }, } as CancellationController; } @@ -121,7 +124,15 @@ export class NodeTransport implements Transport { return transportResponse; }) .catch((error) => { - throw PubNubAPIError.create(error); + let fetchError = error; + + if (typeof error === 'string') { + const errorMessage = error.toLowerCase(); + if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) fetchError = new Error(error); + else if (errorMessage.includes('cancel')) fetchError = new AbortError('Aborted'); + } + + throw PubNubAPIError.create(fetchError); }); }), controller, diff --git a/src/transport/react-native-transport.ts b/src/transport/react-native-transport.ts index a6fd22e42..492787ad7 100644 --- a/src/transport/react-native-transport.ts +++ b/src/transport/react-native-transport.ts @@ -42,7 +42,7 @@ export class ReactNativeTransport implements Transport { const controller = { // Storing controller inside to prolong object lifetime. abortController, - abort: () => !abortController.signal.aborted && abortController.abort(), + abort: (reason) => !abortController.signal.aborted && abortController.abort(reason), } as CancellationController; return [ @@ -63,7 +63,7 @@ export class ReactNativeTransport implements Transport { clearTimeout(timeoutId); reject(new Error('Request timeout')); - controller.abort(); + controller.abort('Cancel because of timeout'); }, req.timeout * 1000); }); @@ -104,7 +104,18 @@ export class ReactNativeTransport implements Transport { return transportResponse; }) .catch((error) => { - throw PubNubAPIError.create(error); + let fetchError = error; + + if (typeof error === 'string') { + const errorMessage = error.toLowerCase(); + if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) fetchError = new Error(error); + else if (errorMessage.includes('cancel')) { + fetchError = new Error('Aborted'); + fetchError.name = 'AbortError'; + } + } + + throw PubNubAPIError.create(fetchError); }); }), controller, diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index 8b3b2d358..13bf73f1a 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -1097,7 +1097,15 @@ const sendRequest = ( const clients = getClients(); if (clients.length === 0) return; - failure(clients, error); + let fetchError = error; + + if (typeof error === 'string') { + const errorMessage = error.toLowerCase(); + if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) fetchError = new Error(error); + else if (errorMessage.includes('cancel')) fetchError = new DOMException('Aborted', 'AbortError'); + } + + failure(clients, fetchError); }); })(); }; @@ -1116,7 +1124,7 @@ const cancelRequest = (requestId: string) => { delete serviceRequests[requestId]; // Abort request if possible. - if (controller) controller.abort(); + if (controller) controller.abort('Cancel request'); } }; @@ -1722,10 +1730,11 @@ const requestProcessingError = (error?: unknown, res?: [Response, ArrayBuffer]): name = error.name; } - if (name === 'AbortError') { + if (message.toLowerCase().includes('timeout')) type = 'TIMEOUT'; + else if (name === 'AbortError' || message.toLowerCase().includes('cancel')) { message = 'Request aborted'; type = 'ABORTED'; - } else if (message === 'Request timeout') type = 'TIMEOUT'; + } return { type: 'request-process-error', diff --git a/src/transport/web-transport.ts b/src/transport/web-transport.ts index 1fac8c14f..c82a3ceab 100644 --- a/src/transport/web-transport.ts +++ b/src/transport/web-transport.ts @@ -116,7 +116,7 @@ export class WebTransport implements Transport { const abortController = new AbortController(); const cancellation: WebCancellationController = { abortController, - abort: () => !abortController.signal.aborted && abortController.abort(), + abort: (reason) => !abortController.signal.aborted && abortController.abort(reason), }; return [ @@ -151,7 +151,15 @@ export class WebTransport implements Transport { return transportResponse; }) .catch((error) => { - throw PubNubAPIError.create(error); + let fetchError = error; + + if (typeof error === 'string') { + const errorMessage = error.toLowerCase(); + if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) fetchError = new Error(error); + else if (errorMessage.includes('cancel')) fetchError = new DOMException('Aborted', 'AbortError'); + } + + throw PubNubAPIError.create(fetchError); }); }), cancellation, @@ -195,7 +203,7 @@ export class WebTransport implements Transport { clearTimeout(timeoutId); reject(new Error('Request timeout')); - controller.abort(); + controller.abort('Cancel because of timeout'); }, req.timeout * 1000); }); diff --git a/test/dist/web-titanium.test.js b/test/dist/web-titanium.test.js index 862a4bf68..e7cb57ccc 100644 --- a/test/dist/web-titanium.test.js +++ b/test/dist/web-titanium.test.js @@ -29,7 +29,7 @@ describe('#distribution test (titanium)', function () { listener = { status: function (st) { try { - expect(st.operation).to.be.equal("PNSubscribeOperation"); + expect(st.operation).to.be.equal('PNSubscribeOperation'); done(); } catch (error) { done(error); @@ -50,7 +50,7 @@ describe('#distribution test (titanium)', function () { message: function (m) { try { expect(m.channel).to.be.equal(myChannel2); - expect(m.message.text).to.be.equal("hello Titanium SDK"); + expect(m.message.text).to.be.equal('hello Titanium SDK'); done(); } catch (error) { done(error); @@ -68,7 +68,7 @@ describe('#distribution test (titanium)', function () { pubnub.setState({ channels: [myChannel1], state: { hello: 'there' } }, function (status, response) { try { expect(status.error).to.be.equal(false); - expect(response.state.hello).to.be.equal("there"); + expect(response.state.hello).to.be.equal('there'); done(); } catch (error) { done(error); @@ -79,7 +79,7 @@ describe('#distribution test (titanium)', function () { it('should have to get the time', function (done) { pubnub.time(function (status) { try { - expect(status.operation).to.be.equal("PNTimeOperation"); + expect(status.operation).to.be.equal('PNTimeOperation'); expect(status.statusCode).to.be.equal(200); done(); } catch (error) { @@ -142,7 +142,7 @@ describe('#distribution test (titanium)', function () { pubnub.setUUID('CustomUUID'); try { - expect(pubnub.getUUID()).to.be.equal("CustomUUID"); + expect(pubnub.getUUID()).to.be.equal('CustomUUID'); done(); } catch (error) { done(error); @@ -159,7 +159,7 @@ describe('#distribution test (titanium)', function () { pubnub.addListener({ status: function (st) { try { - expect(st.operation).to.be.equal("PNUnsubscribeOperation"); + expect(st.operation).to.be.equal('PNUnsubscribeOperation'); if (!finished) { // prevent calling done twice From b36cf023f7985dfe41db68a484c16e247873d17c Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Wed, 26 Feb 2025 10:35:37 +0200 Subject: [PATCH 38/49] Fix fetch issue with empty object rejection (#439) fix(fetch): fix fetch issue with empty object rejection Fix issue because of which code doesn't handle edge case when `fetch` reject with empty object and not `Error`. refactor(presence): remove `-pnpres` entries from presence requests Remove `-pnpres` channels and groups from presence `leave` and `heartbeat` requests. --- .pubnub.yml | 13 +- CHANGELOG.md | 9 ++ README.md | 4 +- dist/web/pubnub.js | 113 ++++++++++++--- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 12 +- dist/web/pubnub.worker.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/components/subscription-manager.js | 14 +- lib/core/pubnub-common.js | 38 ++++- lib/errors/pubnub-api-error.js | 63 +++++++- package-lock.json | 4 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/components/subscription-manager.ts | 17 +-- src/core/pubnub-common.ts | 40 +++++- src/errors/pubnub-api-error.ts | 60 +++++++- .../subscription-worker.ts | 10 +- src/transport/web-transport.ts | 5 +- .../components/subscription_manager.test.ts | 136 ++++++++++++++++++ .../operations/unsubscribe.test.ts | 96 +++++++++++++ 21 files changed, 570 insertions(+), 76 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 4345ec7b6..664fcd54f 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2025-02-26 + version: v8.9.1 + changes: + - type: bug + text: "Fix issue because of which code doesn't handle edge case when `fetch` reject with empty object and not `Error`." + - type: improvement + text: "Remove `-pnpres` channels and groups from presence `leave` and `heartbeat` requests." - date: 2025-02-18 version: v8.9.0 changes: @@ -1144,7 +1151,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.9.0' +version: '8.9.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1160,7 +1167,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.9.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.9.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1831,7 +1838,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.9.0/pubnub.8.9.0.js + location: https://github.com/pubnub/javascript/releases/download/v8.9.1/pubnub.8.9.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 57065e5b6..bf0369903 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v8.9.1 +February 26 2025 + +#### Fixed +- Fix issue because of which code doesn't handle edge case when `fetch` reject with empty object and not `Error`. + +#### Modified +- Remove `-pnpres` channels and groups from presence `leave` and `heartbeat` requests. + ## v8.9.0 February 18 2025 diff --git a/README.md b/README.md index 5c6f82a1f..4780f799a 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index e9957c248..689b8f9b6 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -2890,7 +2890,7 @@ * * @param errorOrResponse - `Error` or service error response object from which error information * should be extracted. - * @param data - Preprocessed service error response. + * @param [data] - Preprocessed service error response. * * @returns `PubNubAPIError` object with known error category and additional information (if * available). @@ -2969,7 +2969,7 @@ * * @param response - Service error response object from which error information should be * extracted. - * @param data - Preprocessed service error response. + * @param [data] - Preprocessed service error response. * * @returns `PubNubAPIError` object with known error category and additional information (if * available). @@ -2990,6 +2990,11 @@ category = StatusCategory$1.PNAccessDeniedCategory; message = 'Access denied'; } + if (typeof response === 'object' && Object.keys(response).length === 0) { + category = StatusCategory$1.PNMalformedResponseCategory; + message = 'Malformed response (network issues)'; + status = 400; + } // Try to get more information about error from service response. if (data && data.byteLength > 0) { const decoded = new TextDecoder().decode(data); @@ -3042,7 +3047,7 @@ * @param message - Short API call error description. * @param category - Error category. * @param statusCode - Response HTTP status code. - * @param errorData - Error information. + * @param [errorData] - Error information. */ constructor(message, category, statusCode, errorData) { super(message); @@ -3065,19 +3070,58 @@ operation, statusCode: this.statusCode, errorData: this.errorData, + // @ts-expect-error Inner helper for JSON.stringify. + toJSON: function () { + let normalizedErrorData; + const errorData = this.errorData; + if (errorData) { + try { + if (typeof errorData === 'object') { + const errorObject = Object.assign(Object.assign(Object.assign(Object.assign({}, ('name' in errorData ? { name: errorData.name } : {})), ('message' in errorData ? { message: errorData.message } : {})), ('stack' in errorData ? { stack: errorData.stack } : {})), errorData); + normalizedErrorData = JSON.parse(JSON.stringify(errorObject, PubNubAPIError.circularReplacer())); + } + else + normalizedErrorData = errorData; + } + catch (_) { + normalizedErrorData = { error: 'Could not serialize the error object' }; + } + } + // Make sure to exclude `toJSON` function from the final object. + const _a = this, status = __rest(_a, ["toJSON"]); + return JSON.stringify(Object.assign(Object.assign({}, status), { errorData: normalizedErrorData })); + }, }; } /** * Convert API error object to PubNub client error object. * * @param operation - Request operation during which error happened. - * @param message - Custom error message. + * @param [message] - Custom error message. * * @returns Client-facing pre-formatted endpoint call error. */ toPubNubError(operation, message) { return new PubNubError(message !== null && message !== void 0 ? message : this.message, this.toStatus(operation)); } + /** + * Function which handles circular references in serialized JSON. + * + * @returns Circular reference replacer function. + * + * @internal + */ + static circularReplacer() { + const visited = new WeakSet(); + return function (_, value) { + if (typeof value === 'object' && value !== null) { + if (visited.has(value)) + return '[Circular]'; + visited.add(value); + } + return value; + }; + } } /** @@ -3759,7 +3803,7 @@ return base.PubNubFile; }, get version() { - return '8.9.0'; + return '8.9.1'; }, getVersion() { return this.version; @@ -4273,10 +4317,9 @@ let fetchError = error; if (typeof error === 'string') { const errorMessage = error.toLowerCase(); - if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) - fetchError = new Error(error); - else if (errorMessage.includes('cancel')) - fetchError = new DOMException('Aborted', 'AbortError'); + fetchError = new Error(error); + if (!errorMessage.includes('timeout') && errorMessage.includes('cancel')) + fetchError.name = 'AbortError'; } throw PubNubAPIError.create(fetchError); }); @@ -5036,7 +5079,8 @@ if (status.category === StatusCategory$1.PNTimeoutCategory) { this.startSubscribeLoop(); } - else if (status.category === StatusCategory$1.PNNetworkIssuesCategory) { + else if (status.category === StatusCategory$1.PNNetworkIssuesCategory || + status.category === StatusCategory$1.PNMalformedResponseCategory) { this.disconnect(); if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { this.isOnline = false; @@ -5058,14 +5102,11 @@ this.listenerManager.announceStatus(reconnectedAnnounce); }); this.reconnectionManager.startPolling(); - this.listenerManager.announceStatus(status); + this.listenerManager.announceStatus(Object.assign(Object.assign({}, status), { category: StatusCategory$1.PNNetworkIssuesCategory })); } - else if (status.category === StatusCategory$1.PNBadRequestCategory || - status.category == StatusCategory$1.PNMalformedResponseCategory) { - const category = this.isOnline ? StatusCategory$1.PNDisconnectedUnexpectedlyCategory : status.category; - this.isOnline = false; - this.disconnect(); - this.listenerManager.announceStatus(Object.assign(Object.assign({}, status), { category })); + else if (status.category === StatusCategory$1.PNBadRequestCategory) { + this.stopHeartbeatTimer(); + this.listenerManager.announceStatus(status); } else this.listenerManager.announceStatus(status); @@ -13319,7 +13360,22 @@ */ makeUnsubscribe(parameters, callback) { { - this.sendRequest(new PresenceLeaveRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })), callback); + // Filtering out presence channels and groups. + let { channels, channelGroups } = parameters; + if (channelGroups) + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + // Complete immediately request only for presence channels. + if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) { + return callback({ + error: false, + operation: RequestOperation$1.PNUnsubscribeOperation, + category: StatusCategory$1.PNAcknowledgmentCategory, + statusCode: 200, + }); + } + this.sendRequest(new PresenceLeaveRequest({ channels, channelGroups, keySet: this._configuration.keySet }), callback); } } /** @@ -13670,7 +13726,26 @@ heartbeat(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { { - const request = new HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + // Filtering out presence channels and groups. + let { channels, channelGroups } = parameters; + if (channelGroups) + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + // Complete immediately request only for presence channels. + if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) { + const responseStatus = { + error: false, + operation: RequestOperation$1.PNHeartbeatOperation, + category: StatusCategory$1.PNAcknowledgmentCategory, + statusCode: 200, + }; + if (callback) + return callback(responseStatus, {}); + return Promise.resolve(responseStatus); + } + const request = new HeartbeatRequest(Object.assign(Object.assign({}, parameters), { channels, + channelGroups, keySet: this._configuration.keySet })); if (callback) return this.sendRequest(request, callback); return this.sendRequest(request); diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 6ec372c60..7ef391b9e 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var E=new Uint8Array(S),O=0;for(r=0;r=0;)f(k,d);else f(k,d);return String.fromCharCode.apply(null,k);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,m,b,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],E=e[i+14],O=e[i+15],k=t(k=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,k,P,N,o,12,u[1]),N=t(N,C,k,P,l,17,u[2]),P=t(P,N,C,k,h,22,u[3]);k=t(k,P,N,C,d,7,u[4]),C=t(C,k,P,N,p,12,u[5]),N=t(N,C,k,P,g,17,u[6]),P=t(P,N,C,k,y,22,u[7]),k=t(k,P,N,C,f,7,u[8]),C=t(C,k,P,N,m,12,u[9]),N=t(N,C,k,P,b,17,u[10]),P=t(P,N,C,k,v,22,u[11]),k=t(k,P,N,C,w,7,u[12]),C=t(C,k,P,N,S,12,u[13]),N=t(N,C,k,P,E,17,u[14]),k=n(k,P=t(P,N,C,k,O,22,u[15]),N,C,o,5,u[16]),C=n(C,k,P,N,g,9,u[17]),N=n(N,C,k,P,v,14,u[18]),P=n(P,N,C,k,c,20,u[19]),k=n(k,P,N,C,p,5,u[20]),C=n(C,k,P,N,b,9,u[21]),N=n(N,C,k,P,O,14,u[22]),P=n(P,N,C,k,d,20,u[23]),k=n(k,P,N,C,m,5,u[24]),C=n(C,k,P,N,E,9,u[25]),N=n(N,C,k,P,h,14,u[26]),P=n(P,N,C,k,f,20,u[27]),k=n(k,P,N,C,S,5,u[28]),C=n(C,k,P,N,l,9,u[29]),N=n(N,C,k,P,y,14,u[30]),k=s(k,P=n(P,N,C,k,w,20,u[31]),N,C,p,4,u[32]),C=s(C,k,P,N,f,11,u[33]),N=s(N,C,k,P,v,16,u[34]),P=s(P,N,C,k,E,23,u[35]),k=s(k,P,N,C,o,4,u[36]),C=s(C,k,P,N,d,11,u[37]),N=s(N,C,k,P,y,16,u[38]),P=s(P,N,C,k,b,23,u[39]),k=s(k,P,N,C,S,4,u[40]),C=s(C,k,P,N,c,11,u[41]),N=s(N,C,k,P,h,16,u[42]),P=s(P,N,C,k,g,23,u[43]),k=s(k,P,N,C,m,4,u[44]),C=s(C,k,P,N,w,11,u[45]),N=s(N,C,k,P,O,16,u[46]),k=r(k,P=s(P,N,C,k,l,23,u[47]),N,C,c,6,u[48]),C=r(C,k,P,N,y,10,u[49]),N=r(N,C,k,P,E,15,u[50]),P=r(P,N,C,k,p,21,u[51]),k=r(k,P,N,C,w,6,u[52]),C=r(C,k,P,N,h,10,u[53]),N=r(N,C,k,P,b,15,u[54]),P=r(P,N,C,k,o,21,u[55]),k=r(k,P,N,C,f,6,u[56]),C=r(C,k,P,N,O,10,u[57]),N=r(N,C,k,P,g,15,u[58]),P=r(P,N,C,k,S,21,u[59]),k=r(k,P,N,C,d,6,u[60]),C=r(C,k,P,N,v,10,u[61]),N=r(N,C,k,P,l,15,u[62]),P=r(P,N,C,k,m,21,u[63]);a[0]=a[0]+k|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;s[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],E=257*p[m]^16843008*m;i[y]=E<<24|E>>>8,a[y]=E<<16|E>>>16,o[y]=E<<8|E>>>24,c[y]=E,E=16843009*w^65537*v^257*b^16843008*y,u[m]=E<<24|E>>>8,l[m]=E<<16|E>>>16,h[m]=E<<8|E>>>24,d[m]=E,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],m=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=m}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],m=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var E=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=_.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=_.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==_.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(s),a)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";class j extends Error{static create(e,t){return e instanceof Error?j.createFromError(e):j.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new j(n,t,0);if(e instanceof j)return e;if(e instanceof Error&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new j(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new j(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.scheduleEventPost(n)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(j.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new j(s,e,0,new Error(s)))}}}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,E=!1,O=100,k=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(E=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(O=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(k=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:k,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(n=e.subscriptionWorkerLogVerbosity)&&void 0!==n&&n,transport:null!==(s=e.transport)&&void 0!==s?s:"fetch",keepAlive:null===(r=e.keepAlive)||void 0===r||r})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.9.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class G{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var K;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(K||(K={}));const $=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),L=(e,t)=>{const n=e.map((e=>$(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?K.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===K.POST||t===K.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${$(e)}`)).join("&"):`${t}=${$(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class z{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class W{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(W.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(W.originalFetch=W.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(W.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw j.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();n.includes("timeout")||!n.includes("cancel")?t=new Error(e):n.includes("cancel")&&(t=new DOMException("Aborted","AbortError"))}throw j.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([W.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${W.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${W.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}W.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;if(e.category===h.PNTimeoutCategory)this.startSubscribeLoop();else if(e.category===h.PNNetworkIssuesCategory)this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(e);else if(e.category===h.PNBadRequestCategory||e.category==h.PNMalformedResponseCategory){const t=this.isOnline?h.PNDisconnectedUnexpectedlyCategory:e.category;this.isOnline=!1,this.disconnect(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:t}))}else this.listenerManager.announceStatus(e);return}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:K.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===K.POST||r.method===K.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw j.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n){t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const n=this.channelListenerMap.get(t);n.includes(e)||n.push(e)}else this.channelListenerMap.set(t,[e])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){const n=this.groupListenerMap.get(t);n.includes(e)||n.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,n){t&&n?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==n||n.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class me extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class be extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new me}abort(){this._aborted=!0,this.notify(new me)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new be}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),Ee=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),ke=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),_e=ge("HEARTBEAT_GIVEUP",(()=>({}))),Ae=ge("TIMES_UP",(()=>({}))),je=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Ae())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(_e());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(ke.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(Ee.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(Ae.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(Ee.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARBEAT_RECONNECTING");Ge.onEnter((e=>Re(e))),Ge.onExit((()=>Re.cancel)),Ge.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ge.on(_e.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEATING");Ke.onEnter((e=>je(e.channels,e.groups))),Ke.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ke.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ke.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(ke.type,((e,t)=>Ke.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),ze=ye("EMIT_MESSAGES",(e=>e)),We=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const mt=new he("RECEIVE_RECONNECTING");mt.onEnter((e=>Je(e))),mt.onExit((()=>Je.cancel)),mt.on(at.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(ot.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:h.PNDisconnectedCategory})]))),mt.on(Ye.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(ht.type,(e=>St.with(void 0,[We({category:h.PNDisconnectedCategory})])));const bt=new he("RECEIVING");bt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),bt.onExit((()=>Ve.cancel)),bt.on(rt.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),bt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),bt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(it.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:h.PNDisconnectedCategory})]))),bt.on(ht.type,(e=>St.with(void 0,[We({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return bt.with({channels:e.channels,groups:e.groups,cursor:r},[We({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[We({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class Et{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?K.POST:K.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${$(t)}/0${this.parameters.sendByPost?"":`/${$(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${$(n)}/0/${$(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${$(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class At extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class jt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${$(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${L(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${L(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${L(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Gt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${s}/action/${n}`}}class Kt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${$(t)}/0/${$(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class $t extends se{constructor(e){super({method:K.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${$(e)}/files/${t}/${n}`}}class Lt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:K.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof j?e:j.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Wt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends Wt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,n)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,n)}get subscriptions(){return this.subscriptionList.slice(0)}}class Xt extends Wt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class mn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class bn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class kn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new bn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new kn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files/${n}/${s}`}}class _n{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new Et({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=_n.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof j?e:j.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){this.sendRequest(new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})),t)}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new jt({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new _t(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{const n=new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof j&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}_n.decoder=new TextDecoder,_n.OPERATIONS=ie,_n.CATEGORIES=h,_n.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,_n.LinearRetryPolicy=Be.LinearRetryPolicy;class An{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class jn extends _n{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new G(new An((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new W(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new z({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return jn.CryptoModule=M,jn})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var E=new Uint8Array(S),O=0;for(r=0;r=0;)f(k,d);else f(k,d);return String.fromCharCode.apply(null,k);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,m,b,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],E=e[i+14],O=e[i+15],k=t(k=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,k,P,N,o,12,u[1]),N=t(N,C,k,P,l,17,u[2]),P=t(P,N,C,k,h,22,u[3]);k=t(k,P,N,C,d,7,u[4]),C=t(C,k,P,N,p,12,u[5]),N=t(N,C,k,P,g,17,u[6]),P=t(P,N,C,k,y,22,u[7]),k=t(k,P,N,C,f,7,u[8]),C=t(C,k,P,N,m,12,u[9]),N=t(N,C,k,P,b,17,u[10]),P=t(P,N,C,k,v,22,u[11]),k=t(k,P,N,C,w,7,u[12]),C=t(C,k,P,N,S,12,u[13]),N=t(N,C,k,P,E,17,u[14]),k=n(k,P=t(P,N,C,k,O,22,u[15]),N,C,o,5,u[16]),C=n(C,k,P,N,g,9,u[17]),N=n(N,C,k,P,v,14,u[18]),P=n(P,N,C,k,c,20,u[19]),k=n(k,P,N,C,p,5,u[20]),C=n(C,k,P,N,b,9,u[21]),N=n(N,C,k,P,O,14,u[22]),P=n(P,N,C,k,d,20,u[23]),k=n(k,P,N,C,m,5,u[24]),C=n(C,k,P,N,E,9,u[25]),N=n(N,C,k,P,h,14,u[26]),P=n(P,N,C,k,f,20,u[27]),k=n(k,P,N,C,S,5,u[28]),C=n(C,k,P,N,l,9,u[29]),N=n(N,C,k,P,y,14,u[30]),k=s(k,P=n(P,N,C,k,w,20,u[31]),N,C,p,4,u[32]),C=s(C,k,P,N,f,11,u[33]),N=s(N,C,k,P,v,16,u[34]),P=s(P,N,C,k,E,23,u[35]),k=s(k,P,N,C,o,4,u[36]),C=s(C,k,P,N,d,11,u[37]),N=s(N,C,k,P,y,16,u[38]),P=s(P,N,C,k,b,23,u[39]),k=s(k,P,N,C,S,4,u[40]),C=s(C,k,P,N,c,11,u[41]),N=s(N,C,k,P,h,16,u[42]),P=s(P,N,C,k,g,23,u[43]),k=s(k,P,N,C,m,4,u[44]),C=s(C,k,P,N,w,11,u[45]),N=s(N,C,k,P,O,16,u[46]),k=r(k,P=s(P,N,C,k,l,23,u[47]),N,C,c,6,u[48]),C=r(C,k,P,N,y,10,u[49]),N=r(N,C,k,P,E,15,u[50]),P=r(P,N,C,k,p,21,u[51]),k=r(k,P,N,C,w,6,u[52]),C=r(C,k,P,N,h,10,u[53]),N=r(N,C,k,P,b,15,u[54]),P=r(P,N,C,k,o,21,u[55]),k=r(k,P,N,C,f,6,u[56]),C=r(C,k,P,N,O,10,u[57]),N=r(N,C,k,P,g,15,u[58]),P=r(P,N,C,k,S,21,u[59]),k=r(k,P,N,C,d,6,u[60]),C=r(C,k,P,N,v,10,u[61]),N=r(N,C,k,P,l,15,u[62]),P=r(P,N,C,k,m,21,u[63]);a[0]=a[0]+k|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;s[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],E=257*p[m]^16843008*m;i[y]=E<<24|E>>>8,a[y]=E<<16|E>>>16,o[y]=E<<8|E>>>24,c[y]=E,E=16843009*w^65537*v^257*b^16843008*y,u[m]=E<<24|E>>>8,l[m]=E<<16|E>>>16,h[m]=E<<8|E>>>24,d[m]=E,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],m=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=m}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],m=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var E=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=_.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=_.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==_.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new A(n,t,0);if(e instanceof A)return e;if(e instanceof Error&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new A(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new A(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,A.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.scheduleEventPost(n)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new A(s,e,0,new Error(s)))}}}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,E=!1,O=100,k=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(E=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(O=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(k=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:k,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(n=e.subscriptionWorkerLogVerbosity)&&void 0!==n&&n,transport:null!==(s=e.transport)&&void 0!==s?s:"fetch",keepAlive:null===(r=e.keepAlive)||void 0===r||r})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.9.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class G{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var K;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(K||(K={}));const $=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),L=(e,t)=>{const n=e.map((e=>$(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?K.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===K.POST||t===K.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${$(e)}`)).join("&"):`${t}=${$(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class z{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class W{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(W.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(W.originalFetch=W.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(W.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw A.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw A.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([W.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${W.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${W.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}W.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:K.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===K.POST||r.method===K.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw A.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n){t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const n=this.channelListenerMap.get(t);n.includes(e)||n.push(e)}else this.channelListenerMap.set(t,[e])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){const n=this.groupListenerMap.get(t);n.includes(e)||n.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,n){t&&n?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==n||n.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class me extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class be extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new me}abort(){this._aborted=!0,this.notify(new me)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new be}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),Ee=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),ke=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),_e=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),Ae=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(Ae.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(_e());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(ke.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(Ee.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(Ee.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARBEAT_RECONNECTING");Ge.onEnter((e=>Re(e))),Ge.onExit((()=>Re.cancel)),Ge.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ge.on(_e.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEATING");Ke.onEnter((e=>Ae(e.channels,e.groups))),Ke.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ke.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ke.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(ke.type,((e,t)=>Ke.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),ze=ye("EMIT_MESSAGES",(e=>e)),We=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const mt=new he("RECEIVE_RECONNECTING");mt.onEnter((e=>Je(e))),mt.onExit((()=>Je.cancel)),mt.on(at.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(ot.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:h.PNDisconnectedCategory})]))),mt.on(Ye.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(ht.type,(e=>St.with(void 0,[We({category:h.PNDisconnectedCategory})])));const bt=new he("RECEIVING");bt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),bt.onExit((()=>Ve.cancel)),bt.on(rt.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),bt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),bt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(it.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:h.PNDisconnectedCategory})]))),bt.on(ht.type,(e=>St.with(void 0,[We({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return bt.with({channels:e.channels,groups:e.groups,cursor:r},[We({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[We({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class Et{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?K.POST:K.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${$(t)}/0${this.parameters.sendByPost?"":`/${$(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${$(n)}/0/${$(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${$(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${$(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${L(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${L(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${L(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Gt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${s}/action/${n}`}}class Kt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${$(t)}/0/${$(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class $t extends se{constructor(e){super({method:K.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${$(e)}/files/${t}/${n}`}}class Lt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:K.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Wt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends Wt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,n)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,n)}get subscriptions(){return this.subscriptionList.slice(0)}}class Xt extends Wt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class mn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class bn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class kn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new bn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new kn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files/${n}/${s}`}}class _n{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new Et({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=_n.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof A?e:A.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new At({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new _t(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new _t(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof A&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}_n.decoder=new TextDecoder,_n.OPERATIONS=ie,_n.CATEGORIES=h,_n.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,_n.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class An extends _n{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new G(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new W(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new z({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return An.CryptoModule=M,An})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index 0c5b6a43b..1ab7edd3b 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -550,10 +550,9 @@ let fetchError = error; if (typeof error === 'string') { const errorMessage = error.toLowerCase(); - if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) - fetchError = new Error(error); - else if (errorMessage.includes('cancel')) - fetchError = new DOMException('Aborted', 'AbortError'); + fetchError = new Error(error); + if (!errorMessage.includes('timeout') && errorMessage.includes('cancel')) + fetchError.name = 'AbortError'; } failure(clients, fetchError); }); @@ -1089,9 +1088,10 @@ message = error.message; name = error.name; } - if (message.toLowerCase().includes('timeout')) + const errorMessage = message.toLowerCase(); + if (errorMessage.includes('timeout')) type = 'TIMEOUT'; - else if (name === 'AbortError' || message.toLowerCase().includes('cancel')) { + else if (name === 'AbortError' || errorMessage.includes('aborted') || errorMessage.includes('cancel')) { message = 'Request aborted'; type = 'ABORTED'; } diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index 494438463..2fd538f35 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,r,i={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=i,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(r=i.exports),null!==n&&(n.exports=r.uuid);var s=t(i.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=1e4,l=new Map,u=new TextDecoder;let a,d=!1;const h=o.createUUID(),p=new Map,f={},b={},g={},v={},y={},q={};self.onconnect=e=>{ee("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)!d&&n.workerLogVerbosity&&(d=!0),n.port=e,U(n),ee(`Client '${n.clientIdentifier}' registered with '${h}' shared worker`);else if("client-pong"===n.type)V(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){L(n);const e=f[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!l.has(t)){const e=setTimeout((()=>{I(n),l.delete(t)}),50);l.set(t,e)}}}else n.request.path.endsWith("/heartbeat")?(N(n),w(n)):j(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const I=e=>{var t;const n=A(e),r=f[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),C("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=q[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=D([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,C("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),R(r,u)}return}e.request.cancellable&&p.set(n.identifier,new AbortController);const s=q[n.identifier],{timetokenOverride:o,regionOverride:c}=s;S(n,(()=>E(n.identifier)),((t,r)=>{F(t,r,e.request),G(t,n.identifier)}),((t,r)=>{F(t,null,e.request,W(r)),G(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(q[n.identifier],t=m(t,o,c)),t})),ee(`'${Object.keys(q).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ee(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ee(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},w=e=>{var t;const n=f[e.clientIdentifier],r=x(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=g[n.subscriptionKey],o=(null!=s?s:{})[i];if(C("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ee(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=D([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,C("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void R(n,i)}S(r,(()=>[n]),((t,n)=>{o&&(o.response=n),F(t,n,e.request)}),((t,n)=>{F(t,null,e.request,W(n))})),ee("Started heartbeat request.",n)},j=e=>{const t=f[e.clientIdentifier],n=K(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=D([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void R(t,s)}if(S(n,(()=>[t]),((t,n)=>{F(t,n,e.request)}),((t,n)=>{F(t,null,e.request,W(n))})),ee("Started leave request.",t),void 0===i)return;const s=E(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),$(s)},O=e=>{const t=f[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},$=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&I({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},S=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(T(t),{signal:null===(e=p.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),P(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(C("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();t.includes("timeout")||!t.includes("cancel")?r=new Error(e):t.includes("cancel")&&(r=new DOMException("Aborted","AbortError"))}i(t,r)}))}))},k=e=>{if(0===E(e).length){const t=p.get(e);p.delete(e),delete q[e],t&&t.abort("Cancel request")}},P=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{p.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),E=e=>Object.values(f).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),G=(e,t)=>{delete q[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},T=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ne(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},A=e=>{var t,n,r,i,s;const c=f[e.clientIdentifier],l=c.subscription,u=Q(l.timetoken,e),a=o.createUUID(),h=Object.assign({},e.request);let p,b;if(u.length>1){const s=_(u,e);if(s){const e=q[s],{channels:n,channelGroups:r}=null!==(t=c.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Y(e.channels,n))&&(!(r.length>0)||Y(e.channelGroups,r)))return s}const o=(null!==(n=v[c.subscriptionKey])&&void 0!==n?n:{})[c.userId],d={},f=new Set(l.channelGroups),g=new Set(l.channels);o&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=o[e];t&&(d[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===c.clientIdentifier||!t.timetoken||(p=t.timetoken,b=t.region),t.channelGroups.forEach(f.add,f),t.channels.forEach(g.add,g);const n=t.serviceRequestId;t.serviceRequestId=a,n&&q[n]&&k(n),o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!d[e]&&(d[e]=t)}))}const y=null!==(r=q[a])&&void 0!==r?r:q[a]={requestId:a,timetoken:null!==(i=h.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(g.size){y.channels=Array.from(g).sort();const e=h.path.split("/");e[4]=y.channels.join(","),h.path=e.join("/")}f.size&&(y.channelGroups=Array.from(f).sort(),h.queryParameters["channel-group"]=y.channelGroups.join(",")),Object.keys(d).length&&(h.queryParameters.state=JSON.stringify(d))}else q[a]={requestId:a,timetoken:null!==(s=h.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};if(q[a]&&(h.queryParameters&&void 0!==h.queryParameters.tt&&void 0!==h.queryParameters.tr&&(q[a].region=h.queryParameters.tr),q[a].timetokenOverride=p,q[a].regionOverride=b),l.serviceRequestId=a,h.identifier=a,d){const e=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");te(q[a],`Started aggregated request for clients: ${e}`)}return h},x=e=>{var t,n,r,i,s;const o=f[e.clientIdentifier],c=B(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=g[s=o.subscriptionKey])&&void 0!==t?t:g[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,h=o.heartbeat.channels;let p={},b=!1,v=!0;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},v=Y(e,o.heartbeat.channels)&&Y(t,o.heartbeat.channelGroups),n&&(b=n[0].status>=400)}else u[a]={channels:h,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},v=!1;if(v){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!b&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),h.push(...n.channels.filter((e=>!h.includes(e)))))}}u[a].channels=h,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))h.includes(e)||d.includes(e)||delete p[e];if(h.length){const e=l.path.split("/");e[6]=h.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},K=e=>{const t=f[e.clientIdentifier],n=H(e);let r=X(e.request),i=z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(d&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");ee(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},R=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(e){}return!1},C=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let h;if("start"===e)h={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),h={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},h),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});R(e,t)}}},F=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},c=n&&n.path.startsWith("/v2/subscribe");!r&&t&&(r=t[0].status>=400?W(void 0,t):D(t));for(const t of e){if(c&&!t.subscription)continue;const e=o[t.clientIdentifier],{request:i}=null!==(s=t.subscription)&&void 0!==s?s:{};let l=null!=i?i:n;if(c||(l=n),e&&l){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:l.identifier,url:`${l.origin}${l.path}`});R(t,e)}}},D=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},W=(e,t)=>{if(t)return Object.assign(Object.assign({},D(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";return e&&e instanceof Error&&(r=e.message,i=e.name),r.toLowerCase().includes("timeout")?n="TIMEOUT":("AbortError"===i||r.toLowerCase().includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},U=e=>{var t,n,r,i;const{clientIdentifier:s}=e;if(f[s])return;const o=f[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity},l=null!==(t=b[r=e.subscriptionKey])&&void 0!==t?t:b[r]=[];l.every((e=>e.clientIdentifier!==s))&&l.push(o),(null!==(n=y[i=e.subscriptionKey])&&void 0!==n?n:y[i]={})[s]=e.port,ee(`Registered PubNub client with '${s}' identifier. '${Object.keys(f).length}' clients currently active.`),!a&&Object.keys(f).length>0&&(ee("Setup PubNub client ping event 10 seconds"),a=setInterval((()=>Z()),c))},L=e=>{var t,n,r,i,s,o,c,l,u,a,d,h,p,b,g,y,q,I,m,w;const j=e.request.queryParameters,{clientIdentifier:O}=e,$=f[O];if(!$)return;const S=null!==(t=j["channel-group"])&&void 0!==t?t:"",k=null!==(n=j.state)&&void 0!==n?n:"";let P=$.subscription;if(P){if(k.length>0){const e=JSON.parse(k),t=null!==(o=(y=null!==(s=v[g=$.subscriptionKey])&&void 0!==s?s:v[g]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of P.objectsWithState)e[n]||delete t[n];P.objectsWithState=Object.keys(e)}else if(P.objectsWithState.length){const e=null!==(l=(m=null!==(c=v[I=$.subscriptionKey])&&void 0!==c?c:v[I]={})[w=$.userId])&&void 0!==l?l:m[w]={};for(const t of P.objectsWithState)delete e[t];P.objectsWithState=[]}}else{if(P={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},k.length>0){const e=JSON.parse(k),t=null!==(i=(p=null!==(r=v[h=$.subscriptionKey])&&void 0!==r?r:v[h]={})[b=$.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),P.objectsWithState=Object.keys(e)}$.subscription=P}P.path!==e.request.path&&(P.path=e.request.path,P.channels=z(e.request)),P.channelGroupQuery!==S&&(P.channelGroupQuery=S,P.channelGroups=X(e.request));const{authKey:E,userId:G}=$;P.request=e.request,P.filterExpression=null!==(u=j["filter-expr"])&&void 0!==u?u:"",P.timetoken=null!==(a=j.tt)&&void 0!==a?a:"0",void 0!==j.tr&&(P.region=j.tr),$.authKey=null!==(d=j.auth)&&void 0!==d?d:"",$.userId=j.uuid,M($,G,E)},N=e=>{var t,n;const r=f[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=X(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=g[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},V=e=>{const t=f[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},_=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=f[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ee(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=q[e.serviceRequestId];if(s||(s=X(t.request)),o||(o=z(t.request)),o.length&&!Y(r.channels,o))continue;if(s.length&&!Y(r.channelGroups,s))continue;return te(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},Q=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",l=s.uuid;return(null!==(i=b[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>H(e),H=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=b[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},X=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Y=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},Z=()=>{ee("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(f).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(ee(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>5)&&(n=!0,ee(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete f[t];let n=b[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?b[e]=n:(delete b[e],delete g[e]),0===n.length&&delete v[e],n.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];ee(`Invalidate '${t}' client. '${Object.keys(f).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(ee(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,R(t,e))})),0===Object.keys(f).length&&a&&clearInterval(a)},ee=(e,t)=>{if(!d)return;const n=t?[t]:Object.values(f),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&R(e,r)}))},te=(e,t,n)=>{if(!d)return;const r=n?[n]:Object.values(f),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&R(e,i)}))},ne=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${re(e)}`)).join("&"):`${t}=${re(n)}`})).join("&"),re=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=i,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(r=i.exports),null!==n&&(n.exports=r.uuid);var s=t(i.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=1e4,l=new Map,u=new TextDecoder;let a,d=!1;const h=o.createUUID(),p=new Map,f={},b={},g={},v={},y={},q={};self.onconnect=e=>{ee("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)!d&&n.workerLogVerbosity&&(d=!0),n.port=e,U(n),ee(`Client '${n.clientIdentifier}' registered with '${h}' shared worker`);else if("client-pong"===n.type)V(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){L(n);const e=f[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!l.has(t)){const e=setTimeout((()=>{I(n),l.delete(t)}),50);l.set(t,e)}}}else n.request.path.endsWith("/heartbeat")?(N(n),j(n)):w(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const I=e=>{var t;const n=A(e),r=f[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),F("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=q[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=W([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,F("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),x(r,u)}return}e.request.cancellable&&p.set(n.identifier,new AbortController);const s=q[n.identifier],{timetokenOverride:o,regionOverride:c}=s;S(n,(()=>E(n.identifier)),((t,r)=>{C(t,r,e.request),G(t,n.identifier)}),((t,r)=>{C(t,null,e.request,D(r)),G(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(q[n.identifier],t=m(t,o,c)),t})),ee(`'${Object.keys(q).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ee(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ee(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},j=e=>{var t;const n=f[e.clientIdentifier],r=K(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=g[n.subscriptionKey],o=(null!=s?s:{})[i];if(F("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ee(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=W([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,F("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void x(n,i)}S(r,(()=>[n]),((t,n)=>{o&&(o.response=n),C(t,n,e.request)}),((t,n)=>{C(t,null,e.request,D(n))})),ee("Started heartbeat request.",n)},w=e=>{const t=f[e.clientIdentifier],n=R(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=W([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void x(t,s)}if(S(n,(()=>[t]),((t,n)=>{C(t,n,e.request)}),((t,n)=>{C(t,null,e.request,D(n))})),ee("Started leave request.",t),void 0===i)return;const s=E(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),$(s)},O=e=>{const t=f[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},$=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&I({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},S=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(T(t),{signal:null===(e=p.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),P(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(F("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},k=e=>{if(0===E(e).length){const t=p.get(e);p.delete(e),delete q[e],t&&t.abort("Cancel request")}},P=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{p.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),E=e=>Object.values(f).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),G=(e,t)=>{delete q[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},T=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ne(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},A=e=>{var t,n,r,i,s;const c=f[e.clientIdentifier],l=c.subscription,u=Q(l.timetoken,e),a=o.createUUID(),h=Object.assign({},e.request);let p,b;if(u.length>1){const s=_(u,e);if(s){const e=q[s],{channels:n,channelGroups:r}=null!==(t=c.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Y(e.channels,n))&&(!(r.length>0)||Y(e.channelGroups,r)))return s}const o=(null!==(n=v[c.subscriptionKey])&&void 0!==n?n:{})[c.userId],d={},f=new Set(l.channelGroups),g=new Set(l.channels);o&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=o[e];t&&(d[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===c.clientIdentifier||!t.timetoken||(p=t.timetoken,b=t.region),t.channelGroups.forEach(f.add,f),t.channels.forEach(g.add,g);const n=t.serviceRequestId;t.serviceRequestId=a,n&&q[n]&&k(n),o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!d[e]&&(d[e]=t)}))}const y=null!==(r=q[a])&&void 0!==r?r:q[a]={requestId:a,timetoken:null!==(i=h.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(g.size){y.channels=Array.from(g).sort();const e=h.path.split("/");e[4]=y.channels.join(","),h.path=e.join("/")}f.size&&(y.channelGroups=Array.from(f).sort(),h.queryParameters["channel-group"]=y.channelGroups.join(",")),Object.keys(d).length&&(h.queryParameters.state=JSON.stringify(d))}else q[a]={requestId:a,timetoken:null!==(s=h.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};if(q[a]&&(h.queryParameters&&void 0!==h.queryParameters.tt&&void 0!==h.queryParameters.tr&&(q[a].region=h.queryParameters.tr),q[a].timetokenOverride=p,q[a].regionOverride=b),l.serviceRequestId=a,h.identifier=a,d){const e=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");te(q[a],`Started aggregated request for clients: ${e}`)}return h},K=e=>{var t,n,r,i,s;const o=f[e.clientIdentifier],c=B(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=g[s=o.subscriptionKey])&&void 0!==t?t:g[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,h=o.heartbeat.channels;let p={},b=!1,v=!0;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},v=Y(e,o.heartbeat.channels)&&Y(t,o.heartbeat.channelGroups),n&&(b=n[0].status>=400)}else u[a]={channels:h,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},v=!1;if(v){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!b&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),h.push(...n.channels.filter((e=>!h.includes(e)))))}}u[a].channels=h,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))h.includes(e)||d.includes(e)||delete p[e];if(h.length){const e=l.path.split("/");e[6]=h.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},R=e=>{const t=f[e.clientIdentifier],n=H(e);let r=X(e.request),i=z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(d&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");ee(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},x=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(e){}return!1},F=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let h;if("start"===e)h={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),h={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},h),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});x(e,t)}}},C=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},c=n&&n.path.startsWith("/v2/subscribe");!r&&t&&(r=t[0].status>=400?D(void 0,t):W(t));for(const t of e){if(c&&!t.subscription)continue;const e=o[t.clientIdentifier],{request:i}=null!==(s=t.subscription)&&void 0!==s?s:{};let l=null!=i?i:n;if(c||(l=n),e&&l){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:l.identifier,url:`${l.origin}${l.path}`});x(t,e)}}},W=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},W(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},U=e=>{var t,n,r,i;const{clientIdentifier:s}=e;if(f[s])return;const o=f[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity},l=null!==(t=b[r=e.subscriptionKey])&&void 0!==t?t:b[r]=[];l.every((e=>e.clientIdentifier!==s))&&l.push(o),(null!==(n=y[i=e.subscriptionKey])&&void 0!==n?n:y[i]={})[s]=e.port,ee(`Registered PubNub client with '${s}' identifier. '${Object.keys(f).length}' clients currently active.`),!a&&Object.keys(f).length>0&&(ee("Setup PubNub client ping event 10 seconds"),a=setInterval((()=>Z()),c))},L=e=>{var t,n,r,i,s,o,c,l,u,a,d,h,p,b,g,y,q,I,m,j;const w=e.request.queryParameters,{clientIdentifier:O}=e,$=f[O];if(!$)return;const S=null!==(t=w["channel-group"])&&void 0!==t?t:"",k=null!==(n=w.state)&&void 0!==n?n:"";let P=$.subscription;if(P){if(k.length>0){const e=JSON.parse(k),t=null!==(o=(y=null!==(s=v[g=$.subscriptionKey])&&void 0!==s?s:v[g]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of P.objectsWithState)e[n]||delete t[n];P.objectsWithState=Object.keys(e)}else if(P.objectsWithState.length){const e=null!==(l=(m=null!==(c=v[I=$.subscriptionKey])&&void 0!==c?c:v[I]={})[j=$.userId])&&void 0!==l?l:m[j]={};for(const t of P.objectsWithState)delete e[t];P.objectsWithState=[]}}else{if(P={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},k.length>0){const e=JSON.parse(k),t=null!==(i=(p=null!==(r=v[h=$.subscriptionKey])&&void 0!==r?r:v[h]={})[b=$.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),P.objectsWithState=Object.keys(e)}$.subscription=P}P.path!==e.request.path&&(P.path=e.request.path,P.channels=z(e.request)),P.channelGroupQuery!==S&&(P.channelGroupQuery=S,P.channelGroups=X(e.request));const{authKey:E,userId:G}=$;P.request=e.request,P.filterExpression=null!==(u=w["filter-expr"])&&void 0!==u?u:"",P.timetoken=null!==(a=w.tt)&&void 0!==a?a:"0",void 0!==w.tr&&(P.region=w.tr),$.authKey=null!==(d=w.auth)&&void 0!==d?d:"",$.userId=w.uuid,M($,G,E)},N=e=>{var t,n;const r=f[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=X(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=g[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},V=e=>{const t=f[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},_=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=f[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ee(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=q[e.serviceRequestId];if(s||(s=X(t.request)),o||(o=z(t.request)),o.length&&!Y(r.channels,o))continue;if(s.length&&!Y(r.channelGroups,s))continue;return te(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},Q=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",l=s.uuid;return(null!==(i=b[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>H(e),H=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=b[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},X=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Y=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},Z=()=>{ee("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(f).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(ee(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>5)&&(n=!0,ee(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete f[t];let n=b[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?b[e]=n:(delete b[e],delete g[e]),0===n.length&&delete v[e],n.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];ee(`Invalidate '${t}' client. '${Object.keys(f).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(ee(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,x(t,e))})),0===Object.keys(f).length&&a&&clearInterval(a)},ee=(e,t)=>{if(!d)return;const n=t?[t]:Object.values(f),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&x(e,r)}))},te=(e,t,n)=>{if(!d)return;const r=n?[n]:Object.values(f),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&x(e,i)}))},ne=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${re(e)}`)).join("&"):`${t}=${re(n)}`})).join("&"),re=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 3340b856d..cbdcb5eca 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.9.0'; + return '8.9.1'; }, getVersion() { return this.version; diff --git a/lib/core/components/subscription-manager.js b/lib/core/components/subscription-manager.js index a40977e7f..eba764d5d 100644 --- a/lib/core/components/subscription-manager.js +++ b/lib/core/components/subscription-manager.js @@ -231,7 +231,8 @@ class SubscriptionManager { if (status.category === categories_1.default.PNTimeoutCategory) { this.startSubscribeLoop(); } - else if (status.category === categories_1.default.PNNetworkIssuesCategory) { + else if (status.category === categories_1.default.PNNetworkIssuesCategory || + status.category === categories_1.default.PNMalformedResponseCategory) { this.disconnect(); if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { this.isOnline = false; @@ -253,14 +254,11 @@ class SubscriptionManager { this.listenerManager.announceStatus(reconnectedAnnounce); }); this.reconnectionManager.startPolling(); - this.listenerManager.announceStatus(status); + this.listenerManager.announceStatus(Object.assign(Object.assign({}, status), { category: categories_1.default.PNNetworkIssuesCategory })); } - else if (status.category === categories_1.default.PNBadRequestCategory || - status.category == categories_1.default.PNMalformedResponseCategory) { - const category = this.isOnline ? categories_1.default.PNDisconnectedUnexpectedlyCategory : status.category; - this.isOnline = false; - this.disconnect(); - this.listenerManager.announceStatus(Object.assign(Object.assign({}, status), { category })); + else if (status.category === categories_1.default.PNBadRequestCategory) { + this.stopHeartbeatTimer(); + this.listenerManager.announceStatus(status); } else this.listenerManager.announceStatus(status); diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index c90337f70..46e5836dc 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -895,7 +895,22 @@ class PubNubCore { */ makeUnsubscribe(parameters, callback) { if (process.env.PRESENCE_MODULE !== 'disabled') { - this.sendRequest(new leave_1.PresenceLeaveRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })), callback); + // Filtering out presence channels and groups. + let { channels, channelGroups } = parameters; + if (channelGroups) + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + // Complete immediately request only for presence channels. + if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) { + return callback({ + error: false, + operation: operations_1.default.PNUnsubscribeOperation, + category: categories_1.default.PNAcknowledgmentCategory, + statusCode: 200, + }); + } + this.sendRequest(new leave_1.PresenceLeaveRequest({ channels, channelGroups, keySet: this._configuration.keySet }), callback); } else throw new Error('Unsubscription error: presence module disabled'); @@ -1284,7 +1299,26 @@ class PubNubCore { heartbeat(parameters, callback) { return __awaiter(this, void 0, void 0, function* () { if (process.env.PRESENCE_MODULE !== 'disabled') { - const request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { keySet: this._configuration.keySet })); + // Filtering out presence channels and groups. + let { channels, channelGroups } = parameters; + if (channelGroups) + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + // Complete immediately request only for presence channels. + if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) { + const responseStatus = { + error: false, + operation: operations_1.default.PNHeartbeatOperation, + category: categories_1.default.PNAcknowledgmentCategory, + statusCode: 200, + }; + if (callback) + return callback(responseStatus, {}); + return Promise.resolve(responseStatus); + } + const request = new heartbeat_1.HeartbeatRequest(Object.assign(Object.assign({}, parameters), { channels, + channelGroups, keySet: this._configuration.keySet })); if (callback) return this.sendRequest(request, callback); return this.sendRequest(request); diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js index c9ad14517..c3e76c213 100644 --- a/lib/errors/pubnub-api-error.js +++ b/lib/errors/pubnub-api-error.js @@ -4,6 +4,17 @@ * * @internal */ +var __rest = (this && this.__rest) || function (s, e) { + var t = {}; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) + t[p] = s[p]; + if (s != null && typeof Object.getOwnPropertySymbols === "function") + for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { + if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) + t[p[i]] = s[p[i]]; + } + return t; +}; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; @@ -22,7 +33,7 @@ class PubNubAPIError extends Error { * * @param errorOrResponse - `Error` or service error response object from which error information * should be extracted. - * @param data - Preprocessed service error response. + * @param [data] - Preprocessed service error response. * * @returns `PubNubAPIError` object with known error category and additional information (if * available). @@ -101,7 +112,7 @@ class PubNubAPIError extends Error { * * @param response - Service error response object from which error information should be * extracted. - * @param data - Preprocessed service error response. + * @param [data] - Preprocessed service error response. * * @returns `PubNubAPIError` object with known error category and additional information (if * available). @@ -122,6 +133,11 @@ class PubNubAPIError extends Error { category = categories_1.default.PNAccessDeniedCategory; message = 'Access denied'; } + if (typeof response === 'object' && Object.keys(response).length === 0) { + category = categories_1.default.PNMalformedResponseCategory; + message = 'Malformed response (network issues)'; + status = 400; + } // Try to get more information about error from service response. if (data && data.byteLength > 0) { const decoded = new TextDecoder().decode(data); @@ -174,7 +190,7 @@ class PubNubAPIError extends Error { * @param message - Short API call error description. * @param category - Error category. * @param statusCode - Response HTTP status code. - * @param errorData - Error information. + * @param [errorData] - Error information. */ constructor(message, category, statusCode, errorData) { super(message); @@ -197,18 +213,57 @@ class PubNubAPIError extends Error { operation, statusCode: this.statusCode, errorData: this.errorData, + // @ts-expect-error Inner helper for JSON.stringify. + toJSON: function () { + let normalizedErrorData; + const errorData = this.errorData; + if (errorData) { + try { + if (typeof errorData === 'object') { + const errorObject = Object.assign(Object.assign(Object.assign(Object.assign({}, ('name' in errorData ? { name: errorData.name } : {})), ('message' in errorData ? { message: errorData.message } : {})), ('stack' in errorData ? { stack: errorData.stack } : {})), errorData); + normalizedErrorData = JSON.parse(JSON.stringify(errorObject, PubNubAPIError.circularReplacer())); + } + else + normalizedErrorData = errorData; + } + catch (_) { + normalizedErrorData = { error: 'Could not serialize the error object' }; + } + } + // Make sure to exclude `toJSON` function from the final object. + const _a = this, { toJSON } = _a, status = __rest(_a, ["toJSON"]); + return JSON.stringify(Object.assign(Object.assign({}, status), { errorData: normalizedErrorData })); + }, }; } /** * Convert API error object to PubNub client error object. * * @param operation - Request operation during which error happened. - * @param message - Custom error message. + * @param [message] - Custom error message. * * @returns Client-facing pre-formatted endpoint call error. */ toPubNubError(operation, message) { return new pubnub_error_1.PubNubError(message !== null && message !== void 0 ? message : this.message, this.toStatus(operation)); } + /** + * Function which handles circular references in serialized JSON. + * + * @returns Circular reference replacer function. + * + * @internal + */ + static circularReplacer() { + const visited = new WeakSet(); + return function (_, value) { + if (typeof value === 'object' && value !== null) { + if (visited.has(value)) + return '[Circular]'; + visited.add(value); + } + return value; + }; + } } exports.PubNubAPIError = PubNubAPIError; diff --git a/package-lock.json b/package-lock.json index 187770ec6..e1e23a68e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.8.1", + "version": "8.9.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.8.1", + "version": "8.9.0", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", diff --git a/package.json b/package.json index 41fc4a0c1..78f5835b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.9.0", + "version": "8.9.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index e66e67c05..e87a19d7e 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.9.0'; + return '8.9.1'; }, getVersion(): string { return this.version; diff --git a/src/core/components/subscription-manager.ts b/src/core/components/subscription-manager.ts index 3dcca2727..269f08d1f 100644 --- a/src/core/components/subscription-manager.ts +++ b/src/core/components/subscription-manager.ts @@ -383,7 +383,10 @@ export class SubscriptionManager { if (status.category === StatusCategory.PNTimeoutCategory) { this.startSubscribeLoop(); - } else if (status.category === StatusCategory.PNNetworkIssuesCategory) { + } else if ( + status.category === StatusCategory.PNNetworkIssuesCategory || + status.category === StatusCategory.PNMalformedResponseCategory + ) { this.disconnect(); if (status.error && this.configuration.autoNetworkDetection && this.isOnline) { @@ -410,16 +413,10 @@ export class SubscriptionManager { }); this.reconnectionManager.startPolling(); + this.listenerManager.announceStatus({ ...status, category: StatusCategory.PNNetworkIssuesCategory }); + } else if (status.category === StatusCategory.PNBadRequestCategory) { + this.stopHeartbeatTimer(); this.listenerManager.announceStatus(status); - } else if ( - status.category === StatusCategory.PNBadRequestCategory || - status.category == StatusCategory.PNMalformedResponseCategory - ) { - const category = this.isOnline ? StatusCategory.PNDisconnectedUnexpectedlyCategory : status.category; - this.isOnline = false; - this.disconnect(); - - this.listenerManager.announceStatus({ ...status, category }); } else this.listenerManager.announceStatus(status); return; diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index 0fc402dc0..0ed8b5883 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -1238,11 +1238,23 @@ export class PubNubCore< */ private makeUnsubscribe(parameters: Presence.PresenceLeaveParameters, callback: StatusCallback): void { if (process.env.PRESENCE_MODULE !== 'disabled') { + // Filtering out presence channels and groups. + let { channels, channelGroups } = parameters; + if (channelGroups) channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + + // Complete immediately request only for presence channels. + if ((channelGroups ?? []).length === 0 && (channels ?? []).length === 0) { + return callback({ + error: false, + operation: RequestOperation.PNUnsubscribeOperation, + category: StatusCategory.PNAcknowledgmentCategory, + statusCode: 200, + }); + } + this.sendRequest( - new PresenceLeaveRequest({ - ...parameters, - keySet: this._configuration.keySet, - }), + new PresenceLeaveRequest({ channels, channelGroups, keySet: this._configuration.keySet }), callback, ); } else throw new Error('Unsubscription error: presence module disabled'); @@ -1917,8 +1929,28 @@ export class PubNubCore< callback?: ResultCallback, ) { if (process.env.PRESENCE_MODULE !== 'disabled') { + // Filtering out presence channels and groups. + let { channels, channelGroups } = parameters; + if (channelGroups) channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + + // Complete immediately request only for presence channels. + if ((channelGroups ?? []).length === 0 && (channels ?? []).length === 0) { + const responseStatus = { + error: false, + operation: RequestOperation.PNHeartbeatOperation, + category: StatusCategory.PNAcknowledgmentCategory, + statusCode: 200, + }; + + if (callback) return callback(responseStatus, {}); + return Promise.resolve(responseStatus); + } + const request = new HeartbeatRequest({ ...parameters, + channels, + channelGroups, keySet: this._configuration.keySet, }); diff --git a/src/errors/pubnub-api-error.ts b/src/errors/pubnub-api-error.ts index 2b948be64..e5bd7834f 100644 --- a/src/errors/pubnub-api-error.ts +++ b/src/errors/pubnub-api-error.ts @@ -21,7 +21,7 @@ export class PubNubAPIError extends Error { * * @param errorOrResponse - `Error` or service error response object from which error information * should be extracted. - * @param data - Preprocessed service error response. + * @param [data] - Preprocessed service error response. * * @returns `PubNubAPIError` object with known error category and additional information (if * available). @@ -89,7 +89,7 @@ export class PubNubAPIError extends Error { * * @param response - Service error response object from which error information should be * extracted. - * @param data - Preprocessed service error response. + * @param [data] - Preprocessed service error response. * * @returns `PubNubAPIError` object with known error category and additional information (if * available). @@ -110,6 +110,12 @@ export class PubNubAPIError extends Error { message = 'Access denied'; } + if (typeof response === 'object' && Object.keys(response).length === 0) { + category = StatusCategory.PNMalformedResponseCategory; + message = 'Malformed response (network issues)'; + status = 400; + } + // Try to get more information about error from service response. if (data && data.byteLength > 0) { const decoded = new TextDecoder().decode(data); @@ -163,7 +169,7 @@ export class PubNubAPIError extends Error { * @param message - Short API call error description. * @param category - Error category. * @param statusCode - Response HTTP status code. - * @param errorData - Error information. + * @param [errorData] - Error information. */ constructor( message: string, @@ -190,6 +196,32 @@ export class PubNubAPIError extends Error { operation, statusCode: this.statusCode, errorData: this.errorData, + // @ts-expect-error Inner helper for JSON.stringify. + toJSON: function (this: Status): string { + let normalizedErrorData: Payload | undefined; + const errorData = this.errorData; + + if (errorData) { + try { + if (typeof errorData === 'object') { + const errorObject = { + ...('name' in errorData ? { name: errorData.name } : {}), + ...('message' in errorData ? { message: errorData.message } : {}), + ...('stack' in errorData ? { stack: errorData.stack } : {}), + ...errorData, + }; + + normalizedErrorData = JSON.parse(JSON.stringify(errorObject, PubNubAPIError.circularReplacer())); + } else normalizedErrorData = errorData; + } catch (_) { + normalizedErrorData = { error: 'Could not serialize the error object' }; + } + } + + // Make sure to exclude `toJSON` function from the final object. + const { toJSON, ...status } = this; + return JSON.stringify({ ...status, errorData: normalizedErrorData }); + }, }; } @@ -197,11 +229,31 @@ export class PubNubAPIError extends Error { * Convert API error object to PubNub client error object. * * @param operation - Request operation during which error happened. - * @param message - Custom error message. + * @param [message] - Custom error message. * * @returns Client-facing pre-formatted endpoint call error. */ public toPubNubError(operation: RequestOperation, message?: string): PubNubError { return new PubNubError(message ?? this.message, this.toStatus(operation)); } + + /** + * Function which handles circular references in serialized JSON. + * + * @returns Circular reference replacer function. + * + * @internal + */ + private static circularReplacer() { + const visited = new WeakSet(); + + return function (_: unknown, value: object | null) { + if (typeof value === 'object' && value !== null) { + if (visited.has(value)) return '[Circular]'; + visited.add(value); + } + + return value; + }; + } } diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index 13bf73f1a..e71e4ee19 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -1101,8 +1101,9 @@ const sendRequest = ( if (typeof error === 'string') { const errorMessage = error.toLowerCase(); - if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) fetchError = new Error(error); - else if (errorMessage.includes('cancel')) fetchError = new DOMException('Aborted', 'AbortError'); + fetchError = new Error(error); + + if (!errorMessage.includes('timeout') && errorMessage.includes('cancel')) fetchError.name = 'AbortError'; } failure(clients, fetchError); @@ -1730,8 +1731,9 @@ const requestProcessingError = (error?: unknown, res?: [Response, ArrayBuffer]): name = error.name; } - if (message.toLowerCase().includes('timeout')) type = 'TIMEOUT'; - else if (name === 'AbortError' || message.toLowerCase().includes('cancel')) { + const errorMessage = message.toLowerCase(); + if (errorMessage.includes('timeout')) type = 'TIMEOUT'; + else if (name === 'AbortError' || errorMessage.includes('aborted') || errorMessage.includes('cancel')) { message = 'Request aborted'; type = 'ABORTED'; } diff --git a/src/transport/web-transport.ts b/src/transport/web-transport.ts index c82a3ceab..2facc4bfd 100644 --- a/src/transport/web-transport.ts +++ b/src/transport/web-transport.ts @@ -155,8 +155,9 @@ export class WebTransport implements Transport { if (typeof error === 'string') { const errorMessage = error.toLowerCase(); - if (errorMessage.includes('timeout') || !errorMessage.includes('cancel')) fetchError = new Error(error); - else if (errorMessage.includes('cancel')) fetchError = new DOMException('Aborted', 'AbortError'); + fetchError = new Error(error); + + if (!errorMessage.includes('timeout') && errorMessage.includes('cancel')) fetchError.name = 'AbortError'; } throw PubNubAPIError.create(fetchError); diff --git a/test/integration/components/subscription_manager.test.ts b/test/integration/components/subscription_manager.test.ts index 802690bf6..e040af904 100644 --- a/test/integration/components/subscription_manager.test.ts +++ b/test/integration/components/subscription_manager.test.ts @@ -383,6 +383,8 @@ describe('#components/subscription_manager', () => { pubnub.addListener({ status(statusPayload) { if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + // @ts-expect-error Remove helper function before compare. + delete statusPayload['toJSON']; const statusWithoutError = _.omit(statusPayload, 'errorData', 'statusCode'); try { @@ -423,6 +425,8 @@ describe('#components/subscription_manager', () => { pubnub.addListener({ status(statusPayload) { if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + // @ts-expect-error Remove helper function before compare. + delete statusPayload['toJSON']; const statusWithoutError = _.omit(statusPayload, 'errorData'); try { @@ -465,6 +469,8 @@ describe('#components/subscription_manager', () => { pubnubWithPassingHeartbeats.addListener({ status(statusPayload) { if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + // @ts-expect-error Remove helper function before compare. + delete statusPayload['toJSON']; try { assert.equal(scope.isDone(), true); @@ -491,6 +497,88 @@ describe('#components/subscription_manager', () => { }); }); + it('heartbeat removes presence channels', (done) => { + const scope = utils + .createNock() + .get('/v2/presence/sub-key/mySubKey/channel/ch1/heartbeat') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + heartbeat: 300, + state: '{}', + }) + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); + + pubnubWithPassingHeartbeats.addListener({ + status(statusPayload) { + if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + // @ts-expect-error Remove helper function before compare. + delete statusPayload['toJSON']; + + try { + assert.equal(scope.isDone(), true); + assert.deepEqual( + { + error: false, + operation: PubNub.OPERATIONS.PNHeartbeatOperation, + category: PubNub.CATEGORIES.PNAcknowledgmentCategory, + statusCode: 200, + }, + statusPayload, + ); + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnubWithPassingHeartbeats.subscribe({ + channels: ['ch1', 'ch2-pnpres'], + }); + }); + + it("heartbeat doesn't make a call with only presence channels", (done) => { + const scope = utils + .createNock() + .get('/v2/presence/sub-key/mySubKey/channel/ch1-pnpres,ch2-pnpres/heartbeat') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + heartbeat: 300, + state: '{}', + }) + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); + + pubnubWithPassingHeartbeats.addListener({ + status(statusPayload) { + if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + // @ts-expect-error Remove helper function before compare. + delete statusPayload['toJSON']; + + try { + assert.equal(scope.isDone(), false); + assert.deepEqual( + { + error: false, + operation: PubNub.OPERATIONS.PNHeartbeatOperation, + category: PubNub.CATEGORIES.PNAcknowledgmentCategory, + statusCode: 200, + }, + statusPayload, + ); + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnubWithPassingHeartbeats.subscribe({ + channels: ['ch1-pnpres', 'ch2-pnpres'], + }); + }); + it('reports when heartbeats pass with heartbeatChannels', (done) => { const scope = utils .createNock() @@ -506,6 +594,8 @@ describe('#components/subscription_manager', () => { pubnubWithPassingHeartbeats.addListener({ status(statusPayload) { if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + // @ts-expect-error Remove helper function before compare. + delete statusPayload['toJSON']; try { assert.equal(scope.isDone(), true); @@ -531,6 +621,48 @@ describe('#components/subscription_manager', () => { }); }); + it('heartbeat removes presence channel groups', (done) => { + const scope = utils + .createNock() + .get('/v2/presence/sub-key/mySubKey/channel/,/heartbeat') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + heartbeat: 300, + state: '{}', + 'channel-group': 'cg1', + }) + .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); + + pubnubWithPassingHeartbeats.addListener({ + status(statusPayload) { + if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + // @ts-expect-error Remove helper function before compare. + delete statusPayload['toJSON']; + + try { + assert.equal(scope.isDone(), true); + assert.deepEqual( + { + error: false, + operation: PubNub.OPERATIONS.PNHeartbeatOperation, + category: PubNub.CATEGORIES.PNAcknowledgmentCategory, + statusCode: 200, + }, + statusPayload, + ); + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnubWithPassingHeartbeats.subscribe({ + channelGroups: ['cg1', 'cg2-pnpres'], + }); + }); + it('reports when heartbeats pass with heartbeatChannelGroups', (done) => { const scope = utils .createNock() @@ -547,6 +679,8 @@ describe('#components/subscription_manager', () => { pubnubWithPassingHeartbeats.addListener({ status(statusPayload) { if (statusPayload.operation !== PubNub.OPERATIONS.PNHeartbeatOperation) return; + // @ts-expect-error Remove helper function before compare. + delete statusPayload['toJSON']; try { assert.equal(scope.isDone(), true); @@ -600,6 +734,8 @@ describe('#components/subscription_manager', () => { pubnubWithLimitedQueue.addListener({ status(statusPayload) { if (statusPayload.category !== PubNub.CATEGORIES.PNRequestMessageCountExceededCategory) return; + // @ts-expect-error Remove helper function before compare. + delete statusPayload['toJSON']; try { assert.equal(scope.isDone(), true); diff --git a/test/integration/operations/unsubscribe.test.ts b/test/integration/operations/unsubscribe.test.ts index 919c4e7d3..982ebc093 100644 --- a/test/integration/operations/unsubscribe.test.ts +++ b/test/integration/operations/unsubscribe.test.ts @@ -232,6 +232,70 @@ describe('unsubscribe', () => { pubnub.subscribe({ channels: ['ch1', 'ch2'] }); }); + it('presence leave removes presence channels', (done) => { + const scope = utils + .createNock() + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1/leave') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); + + pubnub.addListener({ + status(status) { + if (status.operation !== PubNub.OPERATIONS.PNUnsubscribeOperation) { + pubnub.unsubscribe({ channels: ['ch1', 'ch2-pnpres'] }); + return; + } + + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + assert.deepEqual(status.affectedChannels, ['ch1', 'ch2-pnpres']); + assert.deepEqual(status.affectedChannelGroups, []); + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnub.subscribe({ channels: ['ch1', 'ch2-pnpres'] }); + }); + + it("presence doesn't make a call with only presence channels", (done) => { + const scope = utils + .createNock() + .get('/v2/presence/sub-key/mySubscribeKey/channel/ch1-pnpres,ch2-pnpres/leave') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + }) + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); + + pubnub.addListener({ + status(status) { + if (status.operation !== PubNub.OPERATIONS.PNUnsubscribeOperation) { + pubnub.unsubscribe({ channels: ['ch1-pnpres', 'ch2-pnpres'] }); + return; + } + + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), false); + assert.deepEqual(status.affectedChannels, ['ch1-pnpres', 'ch2-pnpres']); + assert.deepEqual(status.affectedChannelGroups, []); + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnub.subscribe({ channels: ['ch1-pnpres', 'ch2-pnpres'] }); + }); + it('supports partial leaving for channel groups', (done) => { const scope = utils .createNock() @@ -263,6 +327,38 @@ describe('unsubscribe', () => { pubnub.subscribe({ channelGroups: ['cg1', 'cg2'] }); }); + + it('presence leave removes presence channel groups', (done) => { + const scope = utils + .createNock() + .get('/v2/presence/sub-key/mySubscribeKey/channel/,/leave') + .query({ + pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, + uuid: 'myUUID', + 'channel-group': 'cg1', + }) + .reply(200, '{ "status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript' }); + + pubnub.addListener({ + status(status) { + if (status.operation !== PubNub.OPERATIONS.PNUnsubscribeOperation) { + pubnub.unsubscribe({ channelGroups: ['cg1', 'cg2-pnpres'] }); + return; + } + try { + assert.equal(status.error, false); + assert.equal(scope.isDone(), true); + assert.deepEqual(status.affectedChannels, []); + assert.deepEqual(status.affectedChannelGroups, ['cg1', 'cg2-pnpres']); + done(); + } catch (error) { + done(error); + } + }, + }); + + pubnub.subscribe({ channelGroups: ['cg1', 'cg2-pnpres'] }); + }); }); describe('#unsubscribeAll', () => { From 0cbe409c7c5ef3afe622535e2a7e3465180f9a15 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 6 Mar 2025 10:58:32 +0200 Subject: [PATCH 39/49] Add ability to opt-out smart heartbeat (#440) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(heartbeat): add ability to opt-out smart heartbeat Add `useSmartHeartbeat` configuration option which allows ignoring implicit heartbeat (with successful subscribe response) and keep sending `heartbeat` calls with fixed intervals. feat(shared-worker): configurable offline detection interval `subscriptionWorkerOfflineClientsCheckInterval` configuration option can be used to configure the interval at which “offline” PubNub clients (when tab closed) detection will be done. feat(shared-worker): configurable unsubscribe for offline clients `subscriptionWorkerUnsubscribeOfflineClients` configuration option can be used to force unsubscribe (presence leave) for “offline” PubNub clients (when tab closed). refactor(shared-worker): debug output on request completion When `subscriptionWorkerLogVerbosity` is set, there will be additional output to the page console with information about which clients will be notified about request completion. --- .pubnub.yml | 15 +- CHANGELOG.md | 8 + README.md | 4 +- dist/web/pubnub.js | 33 ++- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 223 +++++++++++---- dist/web/pubnub.worker.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/core/components/subscription-manager.js | 2 +- lib/core/interfaces/configuration.js | 13 +- lib/types/index.d.ts | 13 + package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/components/subscription-manager.ts | 2 +- src/core/interfaces/configuration.ts | 20 ++ .../subscription-worker-middleware.ts | 12 + .../subscription-worker.ts | 256 +++++++++++++----- src/web/components/configuration.ts | 34 +++ src/web/index.ts | 2 + 19 files changed, 504 insertions(+), 147 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 664fcd54f..652877d4b 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,14 @@ --- changelog: + - date: 2025-03-06 + version: v8.10.0 + changes: + - type: feature + text: "Add `useSmartHeartbeat` configuration option which allows ignoring implicit heartbeat (with successful subscribe response) and keep sending `heartbeat` calls with fixed intervals." + - type: feature + text: "`subscriptionWorkerOfflineClientsCheckInterval` configuration option can be used to configure the interval at which “offline” PubNub clients (when tab closed) detection will be done." + - type: feature + text: "`subscriptionWorkerUnsubscribeOfflineClients` configuration option can be used to force unsubscribe (presence leave) for “offline” PubNub clients (when tab closed)." - date: 2025-02-26 version: v8.9.1 changes: @@ -1151,7 +1160,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.9.1' +version: '8.10.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1167,7 +1176,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.9.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v8.10.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1838,7 +1847,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.9.1/pubnub.8.9.1.js + location: https://github.com/pubnub/javascript/releases/download/v8.10.0/pubnub.8.10.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index bf0369903..d5a897289 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +## v8.10.0 +March 06 2025 + +#### Added +- Add `useSmartHeartbeat` configuration option which allows ignoring implicit heartbeat (with successful subscribe response) and keep sending `heartbeat` calls with fixed intervals. +- `subscriptionWorkerOfflineClientsCheckInterval` configuration option can be used to configure the interval at which “offline” PubNub clients (when tab closed) detection will be done. +- `subscriptionWorkerUnsubscribeOfflineClients` configuration option can be used to force unsubscribe (presence leave) for “offline” PubNub clients (when tab closed). + ## v8.9.1 February 26 2025 diff --git a/README.md b/README.md index 4780f799a..dfdbdfd46 100644 --- a/README.md +++ b/README.md @@ -28,8 +28,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.9.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.10.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.8.10.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 689b8f9b6..c02305eee 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3261,6 +3261,8 @@ userId: this.configuration.userId, heartbeatInterval: this.configuration.heartbeatInterval, logVerbosity: this.configuration.logVerbosity, + workerOfflineClientsCheckInterval: this.configuration.workerOfflineClientsCheckInterval, + workerUnsubscribeOfflineClients: this.configuration.workerUnsubscribeOfflineClients, workerLogVerbosity: this.configuration.workerLogVerbosity, }, true); this.subscriptionWorker.port.onmessage = (event) => this.handleWorkerEvent(event); @@ -3433,6 +3435,10 @@ * Whether configured user presence state should be maintained by the PubNub client or not. */ const MAINTAIN_PRESENCE_STATE = true; + /** + * Whether heartbeat should be postponed on successful subscribe response or not. + */ + const USE_SMART_HEARTBEAT = true; /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -3489,7 +3495,7 @@ * @internal */ const setDefaults$1 = (configuration) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r; // Copy configuration. const configurationCopy = Object.assign({}, configuration); (_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING); @@ -3504,13 +3510,14 @@ (_k = configurationCopy.autoNetworkDetection) !== null && _k !== void 0 ? _k : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION); (_l = configurationCopy.enableEventEngine) !== null && _l !== void 0 ? _l : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE); (_m = configurationCopy.maintainPresenceState) !== null && _m !== void 0 ? _m : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE); - (_o = configurationCopy.keepAlive) !== null && _o !== void 0 ? _o : (configurationCopy.keepAlive = KEEP_ALIVE$1); + (_o = configurationCopy.useSmartHeartbeat) !== null && _o !== void 0 ? _o : (configurationCopy.useSmartHeartbeat = USE_SMART_HEARTBEAT); + (_p = configurationCopy.keepAlive) !== null && _p !== void 0 ? _p : (configurationCopy.keepAlive = KEEP_ALIVE$1); if (configurationCopy.userId && configurationCopy.uuid) throw new PubNubError("PubNub client configuration error: use only 'userId'"); - (_p = configurationCopy.userId) !== null && _p !== void 0 ? _p : (configurationCopy.userId = configurationCopy.uuid); + (_q = configurationCopy.userId) !== null && _q !== void 0 ? _q : (configurationCopy.userId = configurationCopy.uuid); if (!configurationCopy.userId) throw new PubNubError("PubNub client configuration error: 'userId' not set"); - else if (((_q = configurationCopy.userId) === null || _q === void 0 ? void 0 : _q.trim().length) === 0) + else if (((_r = configurationCopy.userId) === null || _r === void 0 ? void 0 : _r.trim().length) === 0) throw new PubNubError("PubNub client configuration error: 'userId' is empty"); // Generate default origin subdomains. if (!configurationCopy.origin) @@ -3599,6 +3606,14 @@ * Whether verbose logging should be enabled for `Subscription` worker to print debug messages or not. */ const SUBSCRIPTION_WORKER_LOG_VERBOSITY = false; + /** + * Interval at which Shared Worker should check whether PubNub instances which used it still active or not. + */ + const SUBSCRIPTION_WORKER_OFFLINE_CLIENTS_CHECK_INTERVAL = 10; + /** + * Whether `leave` request should be sent for _offline_ PubNub client or not. + */ + const SUBSCRIPTION_WORKER_UNSUBSCRIBE_OFFLINE_CLIENTS = false; /** * Use modern Web Fetch API for network requests by default. */ @@ -3615,13 +3630,13 @@ * @internal */ const setDefaults = (configuration) => { - var _a, _b, _c, _d; + var _a, _b, _c, _d, _e, _f; // Force disable service workers if environment doesn't support them. if (configuration.subscriptionWorkerUrl && typeof SharedWorker === 'undefined') configuration.subscriptionWorkerUrl = null; return Object.assign(Object.assign({}, setDefaults$1(configuration)), { // Set platform-specific options. - listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, subscriptionWorkerLogVerbosity: (_b = configuration.subscriptionWorkerLogVerbosity) !== null && _b !== void 0 ? _b : SUBSCRIPTION_WORKER_LOG_VERBOSITY, transport: (_c = configuration.transport) !== null && _c !== void 0 ? _c : TRANSPORT, keepAlive: (_d = configuration.keepAlive) !== null && _d !== void 0 ? _d : KEEP_ALIVE }); + listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, subscriptionWorkerOfflineClientsCheckInterval: (_b = configuration.subscriptionWorkerOfflineClientsCheckInterval) !== null && _b !== void 0 ? _b : SUBSCRIPTION_WORKER_OFFLINE_CLIENTS_CHECK_INTERVAL, subscriptionWorkerUnsubscribeOfflineClients: (_c = configuration.subscriptionWorkerUnsubscribeOfflineClients) !== null && _c !== void 0 ? _c : SUBSCRIPTION_WORKER_UNSUBSCRIBE_OFFLINE_CLIENTS, subscriptionWorkerLogVerbosity: (_d = configuration.subscriptionWorkerLogVerbosity) !== null && _d !== void 0 ? _d : SUBSCRIPTION_WORKER_LOG_VERBOSITY, transport: (_e = configuration.transport) !== null && _e !== void 0 ? _e : TRANSPORT, keepAlive: (_f = configuration.keepAlive) !== null && _f !== void 0 ? _f : KEEP_ALIVE }); }; var uuid = {exports: {}}; @@ -3803,7 +3818,7 @@ return base.PubNubFile; }, get version() { - return '8.9.1'; + return '8.10.0'; }, getVersion() { return this.version; @@ -4930,7 +4945,7 @@ */ reconnect(forUnsubscribe = false) { this.startSubscribeLoop(); - if (!forUnsubscribe) + if (!forUnsubscribe && this.configuration.useSmartHeartbeat) this.startHeartbeatTimer(); } /** @@ -14565,6 +14580,8 @@ workerUrl: configurationCopy.subscriptionWorkerUrl, sdkVersion: clientConfiguration.getVersion(), heartbeatInterval: clientConfiguration.getHeartbeatInterval(), + workerOfflineClientsCheckInterval: platformConfiguration.subscriptionWorkerOfflineClientsCheckInterval, + workerUnsubscribeOfflineClients: platformConfiguration.subscriptionWorkerUnsubscribeOfflineClients, logVerbosity: clientConfiguration.logVerbosity, workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity, transport, diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 7ef391b9e..5f2676dcd 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var E=new Uint8Array(S),O=0;for(r=0;r=0;)f(k,d);else f(k,d);return String.fromCharCode.apply(null,k);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,m,b,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],E=e[i+14],O=e[i+15],k=t(k=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,k,P,N,o,12,u[1]),N=t(N,C,k,P,l,17,u[2]),P=t(P,N,C,k,h,22,u[3]);k=t(k,P,N,C,d,7,u[4]),C=t(C,k,P,N,p,12,u[5]),N=t(N,C,k,P,g,17,u[6]),P=t(P,N,C,k,y,22,u[7]),k=t(k,P,N,C,f,7,u[8]),C=t(C,k,P,N,m,12,u[9]),N=t(N,C,k,P,b,17,u[10]),P=t(P,N,C,k,v,22,u[11]),k=t(k,P,N,C,w,7,u[12]),C=t(C,k,P,N,S,12,u[13]),N=t(N,C,k,P,E,17,u[14]),k=n(k,P=t(P,N,C,k,O,22,u[15]),N,C,o,5,u[16]),C=n(C,k,P,N,g,9,u[17]),N=n(N,C,k,P,v,14,u[18]),P=n(P,N,C,k,c,20,u[19]),k=n(k,P,N,C,p,5,u[20]),C=n(C,k,P,N,b,9,u[21]),N=n(N,C,k,P,O,14,u[22]),P=n(P,N,C,k,d,20,u[23]),k=n(k,P,N,C,m,5,u[24]),C=n(C,k,P,N,E,9,u[25]),N=n(N,C,k,P,h,14,u[26]),P=n(P,N,C,k,f,20,u[27]),k=n(k,P,N,C,S,5,u[28]),C=n(C,k,P,N,l,9,u[29]),N=n(N,C,k,P,y,14,u[30]),k=s(k,P=n(P,N,C,k,w,20,u[31]),N,C,p,4,u[32]),C=s(C,k,P,N,f,11,u[33]),N=s(N,C,k,P,v,16,u[34]),P=s(P,N,C,k,E,23,u[35]),k=s(k,P,N,C,o,4,u[36]),C=s(C,k,P,N,d,11,u[37]),N=s(N,C,k,P,y,16,u[38]),P=s(P,N,C,k,b,23,u[39]),k=s(k,P,N,C,S,4,u[40]),C=s(C,k,P,N,c,11,u[41]),N=s(N,C,k,P,h,16,u[42]),P=s(P,N,C,k,g,23,u[43]),k=s(k,P,N,C,m,4,u[44]),C=s(C,k,P,N,w,11,u[45]),N=s(N,C,k,P,O,16,u[46]),k=r(k,P=s(P,N,C,k,l,23,u[47]),N,C,c,6,u[48]),C=r(C,k,P,N,y,10,u[49]),N=r(N,C,k,P,E,15,u[50]),P=r(P,N,C,k,p,21,u[51]),k=r(k,P,N,C,w,6,u[52]),C=r(C,k,P,N,h,10,u[53]),N=r(N,C,k,P,b,15,u[54]),P=r(P,N,C,k,o,21,u[55]),k=r(k,P,N,C,f,6,u[56]),C=r(C,k,P,N,O,10,u[57]),N=r(N,C,k,P,g,15,u[58]),P=r(P,N,C,k,S,21,u[59]),k=r(k,P,N,C,d,6,u[60]),C=r(C,k,P,N,v,10,u[61]),N=r(N,C,k,P,l,15,u[62]),P=r(P,N,C,k,m,21,u[63]);a[0]=a[0]+k|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;s[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],E=257*p[m]^16843008*m;i[y]=E<<24|E>>>8,a[y]=E<<16|E>>>16,o[y]=E<<8|E>>>24,c[y]=E,E=16843009*w^65537*v^257*b^16843008*y,u[m]=E<<24|E>>>8,l[m]=E<<16|E>>>16,h[m]=E<<8|E>>>24,d[m]=E,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],m=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=m}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],m=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var E=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=E,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=_.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=_.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==_.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new A(n,t,0);if(e instanceof A)return e;if(e instanceof Error&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new A(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new A(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,A.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.scheduleEventPost(n)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new A(s,e,0,new Error(s)))}}}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.keepAlive)&&void 0!==g||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(y=m.userId)&&void 0!==y||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(f=m.userId)||void 0===f?void 0:f.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const b={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let v=!1,w=!0,S=5,E=!1,O=100,k=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(E=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(O=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(k=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(v=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(S=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:b,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:k,announceSuccessfulHeartbeats:v,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:S})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerLogVerbosity:null!==(n=e.subscriptionWorkerLogVerbosity)&&void 0!==n&&n,transport:null!==(s=e.transport)&&void 0!==s?s:"fetch",keepAlive:null===(r=e.keepAlive)||void 0===r||r})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.9.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class G{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var K;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(K||(K={}));const $=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),L=(e,t)=>{const n=e.map((e=>$(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?K.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===K.POST||t===K.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${$(e)}`)).join("&"):`${t}=${$(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class z{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class W{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(W.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(W.originalFetch=W.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(W.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw A.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw A.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([W.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${W.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${W.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}W.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:K.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===K.POST||r.method===K.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw A.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n){t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const n=this.channelListenerMap.get(t);n.includes(e)||n.push(e)}else this.channelListenerMap.set(t,[e])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){const n=this.groupListenerMap.get(t);n.includes(e)||n.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,n){t&&n?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==n||n.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class me extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class be extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new me}abort(){this._aborted=!0,this.notify(new me)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new be}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),Ee=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),ke=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),_e=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),Ae=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(Ae.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(_e());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(ke.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(Ee.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),De.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(Ee.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARBEAT_RECONNECTING");Ge.onEnter((e=>Re(e))),Ge.onExit((()=>Re.cancel)),Ge.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ge.on(_e.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEATING");Ke.onEnter((e=>Ae(e.channels,e.groups))),Ke.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(ke.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ke.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ke.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(ke.type,((e,t)=>Ke.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(ke(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),ze=ye("EMIT_MESSAGES",(e=>e)),We=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const mt=new he("RECEIVE_RECONNECTING");mt.onEnter((e=>Je(e))),mt.onExit((()=>Je.cancel)),mt.on(at.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),mt.on(ot.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:h.PNDisconnectedCategory})]))),mt.on(Ye.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(ht.type,(e=>St.with(void 0,[We({category:h.PNDisconnectedCategory})])));const bt=new he("RECEIVING");bt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),bt.onExit((()=>Ve.cancel)),bt.on(rt.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[ze(t.payload.events)]))),bt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),bt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(it.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[We({category:h.PNDisconnectedCategory})]))),bt.on(ht.type,(e=>St.with(void 0,[We({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return bt.with({channels:e.channels,groups:e.groups,cursor:r},[We({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[We({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[We({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class Et{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?K.POST:K.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${$(t)}/0${this.parameters.sendByPost?"":`/${$(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class kt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${$(n)}/0/${$(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${$(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${$(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${L(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${L(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${L(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Gt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${s}/action/${n}`}}class Kt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${$(t)}/0/${$(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class $t extends se{constructor(e){super({method:K.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${$(e)}/files/${t}/${n}`}}class Lt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:K.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class zt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class Wt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends Wt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,n)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,n)}get subscriptions(){return this.subscriptionList.slice(0)}}class Xt extends Wt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class mn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class bn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class kn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new bn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new kn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files/${n}/${s}`}}class _n{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new Et({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=_n.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof A?e:A.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new At({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new _t(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new _t(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new zt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof A&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}_n.decoder=new TextDecoder,_n.OPERATIONS=ie,_n.CATEGORIES=h,_n.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,_n.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class An extends _n{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new G(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new W(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new z({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return An.CryptoModule=M,An})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,m,b,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,O,P,N,o,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=n(O,P=t(P,N,C,O,E,22,u[15]),N,C,o,5,u[16]),C=n(C,O,P,N,g,9,u[17]),N=n(N,C,O,P,v,14,u[18]),P=n(P,N,C,O,c,20,u[19]),O=n(O,P,N,C,p,5,u[20]),C=n(C,O,P,N,b,9,u[21]),N=n(N,C,O,P,E,14,u[22]),P=n(P,N,C,O,d,20,u[23]),O=n(O,P,N,C,m,5,u[24]),C=n(C,O,P,N,k,9,u[25]),N=n(N,C,O,P,h,14,u[26]),P=n(P,N,C,O,f,20,u[27]),O=n(O,P,N,C,S,5,u[28]),C=n(C,O,P,N,l,9,u[29]),N=n(N,C,O,P,y,14,u[30]),O=s(O,P=n(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=s(C,O,P,N,f,11,u[33]),N=s(N,C,O,P,v,16,u[34]),P=s(P,N,C,O,k,23,u[35]),O=s(O,P,N,C,o,4,u[36]),C=s(C,O,P,N,d,11,u[37]),N=s(N,C,O,P,y,16,u[38]),P=s(P,N,C,O,b,23,u[39]),O=s(O,P,N,C,S,4,u[40]),C=s(C,O,P,N,c,11,u[41]),N=s(N,C,O,P,h,16,u[42]),P=s(P,N,C,O,g,23,u[43]),O=s(O,P,N,C,m,4,u[44]),C=s(C,O,P,N,w,11,u[45]),N=s(N,C,O,P,E,16,u[46]),O=r(O,P=s(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,o,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);a[0]=a[0]+O|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;s[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=E[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],m=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=m}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],m=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new E({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=_.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=_.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==_.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new A(n,t,0);if(e instanceof A)return e;if(e instanceof Error&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new A(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new A(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,A.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.scheduleEventPost(n)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new A(s,e,0,new Error(s)))}}}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,m;const b=Object.assign({},e);if(null!==(t=b.logVerbosity)&&void 0!==t||(b.logVerbosity=!1),null!==(n=b.ssl)&&void 0!==n||(b.ssl=!0),null!==(s=b.transactionalRequestTimeout)&&void 0!==s||(b.transactionalRequestTimeout=15),null!==(r=b.subscribeRequestTimeout)&&void 0!==r||(b.subscribeRequestTimeout=310),null!==(i=b.fileRequestTimeout)&&void 0!==i||(b.fileRequestTimeout=300),null!==(a=b.restore)&&void 0!==a||(b.restore=!1),null!==(o=b.useInstanceId)&&void 0!==o||(b.useInstanceId=!1),null!==(c=b.suppressLeaveEvents)&&void 0!==c||(b.suppressLeaveEvents=!1),null!==(u=b.requestMessageCountThreshold)&&void 0!==u||(b.requestMessageCountThreshold=100),null!==(l=b.autoNetworkDetection)&&void 0!==l||(b.autoNetworkDetection=!1),null!==(h=b.enableEventEngine)&&void 0!==h||(b.enableEventEngine=!1),null!==(p=b.maintainPresenceState)&&void 0!==p||(b.maintainPresenceState=!0),null!==(g=b.useSmartHeartbeat)&&void 0!==g||(b.useSmartHeartbeat=!0),null!==(y=b.keepAlive)&&void 0!==y||(b.keepAlive=!1),b.userId&&b.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=b.userId)&&void 0!==f||(b.userId=b.uuid),!b.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(m=b.userId)||void 0===m?void 0:m.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");b.origin||(b.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:b.subscribeKey,publishKey:b.publishKey,secretKey:b.secretKey};void 0!==b.presenceTimeout&&b.presenceTimeout<20&&(b.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==b.presenceTimeout?b.heartbeatInterval=b.presenceTimeout/2-1:b.presenceTimeout=300;let w=!1,S=!0,k=5,E=!1,O=100,C=!0;return void 0!==b.dedupeOnSubscribe&&"boolean"==typeof b.dedupeOnSubscribe&&(E=b.dedupeOnSubscribe),void 0!==b.maximumCacheSize&&"number"==typeof b.maximumCacheSize&&(O=b.maximumCacheSize),void 0!==b.useRequestId&&"boolean"==typeof b.useRequestId&&(C=b.useRequestId),void 0!==b.announceSuccessfulHeartbeats&&"boolean"==typeof b.announceSuccessfulHeartbeats&&(w=b.announceSuccessfulHeartbeats),void 0!==b.announceFailedHeartbeats&&"boolean"==typeof b.announceFailedHeartbeats&&(S=b.announceFailedHeartbeats),void 0!==b.fileUploadPublishRetryLimit&&"number"==typeof b.fileUploadPublishRetryLimit&&(k=b.fileUploadPublishRetryLimit),Object.assign(Object.assign({},b),{keySet:v,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.10.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class G{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var K;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(K||(K={}));const $=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),L=(e,t)=>{const n=e.map((e=>$(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?K.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===K.POST||t===K.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${$(e)}`)).join("&"):`${t}=${$(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw A.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw A.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:K.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===K.POST||r.method===K.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw A.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n){t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const n=this.channelListenerMap.get(t);n.includes(e)||n.push(e)}else this.channelListenerMap.set(t,[e])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){const n=this.groupListenerMap.get(t);n.includes(e)||n.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,n){t&&n?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==n||n.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class me extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class be extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new me}abort(){this._aborted=!0,this.notify(new me)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new be}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Ee=ge("DISCONNECT",(()=>({}))),Oe=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),_e=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),Ae=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(Ae.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(_e());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Oe.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARBEAT_RECONNECTING");Ge.onEnter((e=>Re(e))),Ge.onExit((()=>Re.cancel)),Ge.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Ee.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ge.on(_e.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEATING");Ke.onEnter((e=>Ae(e.channels,e.groups))),Ke.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ke.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ke.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(Oe.type,((e,t)=>Ke.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Oe(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const mt=new he("RECEIVE_RECONNECTING");mt.onEnter((e=>Je(e))),mt.onExit((()=>Je.cancel)),mt.on(at.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(ot.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(Ye.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const bt=new he("RECEIVING");bt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),bt.onExit((()=>Ve.cancel)),bt.on(rt.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),bt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(it.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return bt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Et extends se{constructor(e){var t,n;super({method:e.sendByPost?K.POST:K.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${$(t)}/0${this.parameters.sendByPost?"":`/${$(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ot extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${$(n)}/0/${$(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${$(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${$(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${L(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${L(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${L(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Gt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${s}/action/${n}`}}class Kt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${$(t)}/0/${$(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class $t extends se{constructor(e){super({method:K.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${$(e)}/files/${t}/${n}`}}class Lt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:K.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,n)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,n)}get subscriptions(){return this.subscriptionList.slice(0)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class mn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class bn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class On extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new bn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new On(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files/${n}/${s}`}}class _n{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=_n.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof A?e:A.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new At({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new _t(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new _t(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof A&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}_n.decoder=new TextDecoder,_n.OPERATIONS=ie,_n.CATEGORIES=h,_n.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,_n.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class An extends _n{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})}));let a,u,l;a=new G(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return An.CryptoModule=M,An})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index 1ab7edd3b..88728b81c 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -35,6 +35,37 @@ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; }; + /** + * Enum representing possible transport methods for HTTP requests. + * + * @enum {number} + */ + var TransportMethod; + (function (TransportMethod) { + /** + * Request will be sent using `GET` method. + */ + TransportMethod["GET"] = "GET"; + /** + * Request will be sent using `POST` method. + */ + TransportMethod["POST"] = "POST"; + /** + * Request will be sent using `PATCH` method. + */ + TransportMethod["PATCH"] = "PATCH"; + /** + * Request will be sent using `DELETE` method. + */ + TransportMethod["DELETE"] = "DELETE"; + /** + * Local request. + * + * Request won't be sent to the service and probably used to compute URL. + */ + TransportMethod["LOCAL"] = "LOCAL"; + })(TransportMethod || (TransportMethod = {})); + var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; function getDefaultExportFromCjs (x) { @@ -114,10 +145,6 @@ * * @internal */ - /** - * How often PING request should be sent to the PubNub clients. - */ - const clientPingRequestInterval = 10000; /** * Aggregation timer timeout. * @@ -135,13 +162,9 @@ */ const decoder = new TextDecoder(); /** - * Whether `Subscription` worker should print debug information to the console or not. - */ - let logVerbosity = false; - /** - * PubNub clients active ping interval. + * Per-subscription key map of "offline" clients detection timeouts. */ - let pingInterval; + const pingTimeouts = {}; /** * Unique shared worker instance identifier. */ @@ -204,8 +227,6 @@ return; const data = event.data; if (data.type === 'client-register') { - if (!logVerbosity && data.workerLogVerbosity) - logVerbosity = true; // Appending information about messaging port for responses. data.port = receiver; registerClientIfRequired(data); @@ -300,7 +321,6 @@ }, (response) => { let serverResponse = response; if (isInitialSubscribe && timetokenOverride && timetokenOverride !== '0') { - serviceRequests[requestOrId.identifier]; serverResponse = patchInitialSubscribeResponse(serverResponse, timetokenOverride, regionOverride); } return serverResponse; @@ -398,9 +418,10 @@ * Handle client request to leave request. * * @param data - Leave event details. + * @param [client] - Specific client to handle leave request. */ - const handleSendLeaveRequestEvent = (data) => { - const client = pubNubClients[data.clientIdentifier]; + const handleSendLeaveRequestEvent = (data, client) => { + client = client !== null && client !== void 0 ? client : pubNubClients[data.clientIdentifier]; const request = leaveTransportRequestFromEvent(data); if (!client) return; @@ -605,7 +626,7 @@ /** * Clean up PubNub client states from ongoing request. * - * Reset requested and scheduled request information to make PubNub client "free" for neext requests. + * Reset requested and scheduled request information to make PubNub client "free" for next requests. * * @param clients - List of PubNub clients which awaited for scheduled request completion. * @param requestId - Unique subscribe request identifier for which {@link clients} has been provided. @@ -752,14 +773,15 @@ } subscription.serviceRequestId = serviceRequestId; request.identifier = serviceRequestId; - if (logVerbosity) { - const clientIds = clients - .reduce((identifiers, { clientIdentifier }) => { - identifiers.push(clientIdentifier); - return identifiers; - }, []) - .join(','); - consoleDir(serviceRequests[serviceRequestId], `Started aggregated request for clients: ${clientIds}`); + const clientIds = clients + .reduce((identifiers, { clientIdentifier }) => { + identifiers.push(clientIdentifier); + return identifiers; + }, []) + .join(', '); + if (clientIds.length > 0) { + for (const _client of clients) + consoleDir(serviceRequests[serviceRequestId], `Started aggregated request for clients: ${clientIds}`, _client); } return request; }; @@ -785,9 +807,9 @@ const heartbeatRequestKey = `${client.userId}_${(_b = client.authKey) !== null && _b !== void 0 ? _b : ''}`; const channelGroupsForAnnouncement = client.heartbeat.channelGroups; const channelsForAnnouncement = client.heartbeat.channels; - let aggregatedState = {}; + let aggregatedState; let failedPreviousRequest = false; - let aggregated = true; + let aggregated; if (!hbRequestsBySubscriptionKey[heartbeatRequestKey]) { hbRequestsBySubscriptionKey[heartbeatRequestKey] = { channels: channelsForAnnouncement, @@ -895,13 +917,13 @@ channelGroups = channelGroups.filter((group) => !subscription.channelGroups.includes(group)); } if (channels.length === 0 && channelGroups.length === 0) { - if (logVerbosity && client) { + if (client && client.workerLogVerbosity) { const clientIds = clients .reduce((identifiers, { clientIdentifier }) => { identifiers.push(clientIdentifier); return identifiers; }, []) - .join(','); + .join(', '); consoleLog(`Specified channels and groups still in use by other clients: ${clientIds}. Ignoring leave request.`, client); } return undefined; @@ -932,7 +954,10 @@ receiver.postMessage(event); return true; } - catch (error) { } + catch (error) { + if (client.workerLogVerbosity) + console.error(`[SharedWorker] Unable send message using message port: ${error}`); + } return false; }; /** @@ -1008,6 +1033,7 @@ return; if (!result && !response) return; + const workerLogVerbosity = clients.some((client) => client && client.workerLogVerbosity); const clientIds = (_a = sharedWorkerClients[clients[0].subscriptionKey]) !== null && _a !== void 0 ? _a : {}; const isSubscribeRequest = request && request.path.startsWith('/v2/subscribe'); if (!result && response) { @@ -1017,9 +1043,29 @@ requestProcessingError(undefined, response) : requestProcessingSuccess(response); } + // Notify about subscribe and leave requests completion. + if (workerLogVerbosity && request && !request.path.endsWith('/heartbeat')) { + const notifiedClientIds = clients + .reduce((identifiers, { clientIdentifier }) => { + identifiers.push(clientIdentifier); + return identifiers; + }, []) + .join(', '); + const endpoint = isSubscribeRequest ? 'subscribe' : 'leave'; + const message = `Notify clients about ${endpoint} request completion: ${notifiedClientIds}`; + for (const client of clients) + consoleLog(message, client); + } for (const client of clients) { - if (isSubscribeRequest && !client.subscription) + if (isSubscribeRequest && !client.subscription) { + // Notifying about client with inactive subscription. + if (workerLogVerbosity) { + const message = `${client.clientIdentifier} doesn't have active subscription. Don't notify about completion.`; + for (const nClient of clients) + consoleLog(message, nClient); + } continue; + } const serviceWorkerClientId = clientIds[client.clientIdentifier]; const { request: clientRequest } = (_b = client.subscription) !== null && _b !== void 0 ? _b : {}; let decidedRequest = clientRequest !== null && clientRequest !== void 0 ? clientRequest : request; @@ -1029,6 +1075,14 @@ const payload = Object.assign(Object.assign({}, result), { clientIdentifier: client.clientIdentifier, identifier: decidedRequest.identifier, url: `${decidedRequest.origin}${decidedRequest.path}` }); publishClientEvent(client, payload); } + else if (!serviceWorkerClientId && workerLogVerbosity) { + // Notifying about client without Shared Worker's communication channel. + const message = `${client.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`; + for (const nClient of clients) { + if (nClient.clientIdentifier !== client.clientIdentifier) + consoleLog(message, nClient); + } + } } }; /** @@ -1118,8 +1172,8 @@ * @param event - Base information about PubNub client instance and Service Worker {@link Client}. */ const registerClientIfRequired = (event) => { - var _a, _b; - var _c, _d; + var _a, _b, _c; + var _d, _e; const { clientIdentifier } = event; if (pubNubClients[clientIdentifier]) return; @@ -1129,18 +1183,27 @@ userId: event.userId, heartbeatInterval: event.heartbeatInterval, logVerbosity: event.logVerbosity, + offlineClientsCheckInterval: event.workerOfflineClientsCheckInterval, + unsubscribeOfflineClients: event.workerUnsubscribeOfflineClients, + workerLogVerbosity: event.workerLogVerbosity, }); // Map registered PubNub client to its subscription key. - const clientsBySubscriptionKey = ((_a = pubNubClientsBySubscriptionKey[_c = event.subscriptionKey]) !== null && _a !== void 0 ? _a : (pubNubClientsBySubscriptionKey[_c] = [])); + const clientsBySubscriptionKey = ((_a = pubNubClientsBySubscriptionKey[_d = event.subscriptionKey]) !== null && _a !== void 0 ? _a : (pubNubClientsBySubscriptionKey[_d] = [])); if (clientsBySubscriptionKey.every((entry) => entry.clientIdentifier !== clientIdentifier)) clientsBySubscriptionKey.push(client); // Binding PubNub client to the MessagePort (receiver). - ((_b = sharedWorkerClients[_d = event.subscriptionKey]) !== null && _b !== void 0 ? _b : (sharedWorkerClients[_d] = {}))[clientIdentifier] = event.port; - consoleLog(`Registered PubNub client with '${clientIdentifier}' identifier. ` + - `'${Object.keys(pubNubClients).length}' clients currently active.`); - if (!pingInterval && Object.keys(pubNubClients).length > 0) { - consoleLog(`Setup PubNub client ping event ${clientPingRequestInterval / 1000} seconds`); - pingInterval = setInterval(() => pingClients(), clientPingRequestInterval); + ((_b = sharedWorkerClients[_e = event.subscriptionKey]) !== null && _b !== void 0 ? _b : (sharedWorkerClients[_e] = {}))[clientIdentifier] = event.port; + const message = `Registered PubNub client with '${clientIdentifier}' identifier. ` + + `'${clientsBySubscriptionKey.length}' clients currently active.`; + for (const _client of clientsBySubscriptionKey) + consoleLog(message, _client); + if (!pingTimeouts[event.subscriptionKey] && + ((_c = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _c !== void 0 ? _c : []).length > 0) { + const { subscriptionKey } = event; + const interval = event.workerOfflineClientsCheckInterval; + for (const _client of clientsBySubscriptionKey) + consoleLog(`Setup PubNub client ping event ${interval} seconds`, _client); + pingTimeouts[event.subscriptionKey] = setTimeout(() => pingClients(subscriptionKey), interval * 500 - 1); } }; /** @@ -1214,7 +1277,9 @@ if (query.tr !== undefined) subscription.region = query.tr; client.authKey = ((_l = query.auth) !== null && _l !== void 0 ? _l : ''); + client.origin = event.request.origin; client.userId = query.uuid; + client.pnsdk = query.pnsdk; handleClientIdentityChangeIfRequired(client, userId, authKey); }; /** @@ -1282,8 +1347,13 @@ * @param clientId - Unique PubNub client identifier. */ const invalidateClient = (subscriptionKey, clientId) => { + var _a; + const invalidatedClient = pubNubClients[clientId]; delete pubNubClients[clientId]; let clients = pubNubClientsBySubscriptionKey[subscriptionKey]; + // Unsubscribe invalidated PubNub client. + if (invalidatedClient && invalidatedClient.unsubscribeOfflineClients) + unsubscribeClient(invalidatedClient); if (clients) { // Clean up linkage between client and subscription key. clients = clients.filter((client) => client.clientIdentifier !== clientId); @@ -1308,7 +1378,47 @@ else delete sharedWorkerClients[subscriptionKey]; } - consoleLog(`Invalidate '${clientId}' client. '${Object.keys(pubNubClients).length}' clients currently active.`); + const message = `Invalidate '${clientId}' client. '${((_a = pubNubClientsBySubscriptionKey[subscriptionKey]) !== null && _a !== void 0 ? _a : []).length}' clients currently active.`; + if (!clients) + consoleLog(message); + else + for (const _client of clients) + consoleLog(message, _client); + }; + const unsubscribeClient = (client) => { + if (!client.subscription) + return; + const { channels, channelGroups } = client.subscription; + const encodedChannelGroups = (channelGroups !== null && channelGroups !== void 0 ? channelGroups : []) + .filter((name) => !name.endsWith('-pnpres')) + .map((name) => encodeString(name)) + .sort(); + const encodedChannels = (channels !== null && channels !== void 0 ? channels : []) + .filter((name) => !name.endsWith('-pnpres')) + .map((name) => encodeString(name)) + .sort(); + if (encodedChannels.length === 0 && encodedChannelGroups.length === 0) + return; + const channelGroupsString = encodedChannelGroups.length > 0 ? encodedChannelGroups.join(',') : undefined; + const channelsString = encodedChannels.length === 0 ? ',' : encodedChannels.join(','); + const query = Object.assign(Object.assign({ instanceid: client.clientIdentifier, uuid: client.userId, requestid: uuidGenerator.createUUID() }, (client.authKey ? { auth: client.authKey } : {})), (channelGroupsString ? { 'channel-group': channelGroupsString } : {})); + const request = { + type: 'send-request', + clientIdentifier: client.clientIdentifier, + subscriptionKey: client.subscriptionKey, + logVerbosity: client.logVerbosity, + request: { + origin: client.origin, + path: `/v2/presence/sub-key/${client.subscriptionKey}/channel/${channelsString}/leave`, + queryParameters: query, + method: TransportMethod.GET, + headers: {}, + timeout: 10, + cancellable: false, + identifier: query.requestid, + }, + }; + handleSendLeaveRequestEvent(request, client); }; /** * Validate received event payload. @@ -1468,31 +1578,34 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' }; /** * Send PubNub client PING request to identify disconnected instances. + * + * @param subscriptionKey - Subscribe key for which offline PubNub client should be checked. */ - const pingClients = () => { - consoleLog(`Pinging clients...`); + const pingClients = (subscriptionKey) => { const payload = { type: 'shared-worker-ping' }; - Object.values(pubNubClients).forEach((client) => { + const _pubNubClients = Object.values(pubNubClients).filter((client) => client && client.subscriptionKey === subscriptionKey); + _pubNubClients.forEach((client) => { let clientInvalidated = false; if (client && client.lastPingRequest) { - consoleLog(`Checking whether ${client.clientIdentifier} ping has been sent too long ago...`); + const interval = client.offlineClientsCheckInterval; // Check whether client never respond or last response was too long time ago. - if (!client.lastPongEvent || - Math.abs(client.lastPongEvent - client.lastPingRequest) > (clientPingRequestInterval / 1000) * 0.5) { + if (!client.lastPongEvent || Math.abs(client.lastPongEvent - client.lastPingRequest) > interval * 0.5) { clientInvalidated = true; - consoleLog(`'${client.clientIdentifier}' client is inactive. Invalidating.`); + for (const _client of _pubNubClients) + consoleLog(`'${client.clientIdentifier}' client is inactive. Invalidating...`, _client); invalidateClient(client.subscriptionKey, client.clientIdentifier); } } if (client && !clientInvalidated) { - consoleLog(`Sending ping to ${client.clientIdentifier}...`); client.lastPingRequest = new Date().getTime() / 1000; publishClientEvent(client, payload); } }); - // Cancel interval if there is no active clients. - if (Object.keys(pubNubClients).length === 0 && pingInterval) - clearInterval(pingInterval); + // Restart ping timer if there is still active PubNub clients for subscription key. + if (_pubNubClients && _pubNubClients.length > 0 && _pubNubClients[0]) { + const interval = _pubNubClients[0].offlineClientsCheckInterval; + pingTimeouts[subscriptionKey] = setTimeout(() => pingClients(subscriptionKey), interval * 500 - 1); + } }; /** * Print message on the worker's clients console. @@ -1501,9 +1614,7 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' * @param [client] - Target client to which log message should be sent. */ const consoleLog = (message, client) => { - if (!logVerbosity) - return; - const clients = client ? [client] : Object.values(pubNubClients); + const clients = (client ? [client] : Object.values(pubNubClients)).filter((client) => client && client.workerLogVerbosity); const payload = { type: 'shared-worker-console-log', message, @@ -1521,9 +1632,7 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' * @param [client] - Target client to which log message should be sent. */ const consoleDir = (data, message, client) => { - if (!logVerbosity) - return; - const clients = client ? [client] : Object.values(pubNubClients); + const clients = (client ? [client] : Object.values(pubNubClients)).filter((client) => client && client.workerLogVerbosity); const payload = { type: 'shared-worker-console-dir', message, diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index 2fd538f35..302641a9b 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ -!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((r=r.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n,r,i={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */n=i,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(r=i.exports),null!==n&&(n.exports=r.uuid);var s=t(i.exports),o={createUUID:()=>s.uuid?s.uuid():s()};const c=1e4,l=new Map,u=new TextDecoder;let a,d=!1;const h=o.createUUID(),p=new Map,f={},b={},g={},v={},y={},q={};self.onconnect=e=>{ee("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)!d&&n.workerLogVerbosity&&(d=!0),n.port=e,U(n),ee(`Client '${n.clientIdentifier}' registered with '${h}' shared worker`);else if("client-pong"===n.type)V(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){L(n);const e=f[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!l.has(t)){const e=setTimeout((()=>{I(n),l.delete(t)}),50);l.set(t,e)}}}else n.request.path.endsWith("/heartbeat")?(N(n),j(n)):w(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const I=e=>{var t;const n=A(e),r=f[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),F("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=q[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=W([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,F("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),x(r,u)}return}e.request.cancellable&&p.set(n.identifier,new AbortController);const s=q[n.identifier],{timetokenOverride:o,regionOverride:c}=s;S(n,(()=>E(n.identifier)),((t,r)=>{C(t,r,e.request),G(t,n.identifier)}),((t,r)=>{C(t,null,e.request,D(r)),G(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(q[n.identifier],t=m(t,o,c)),t})),ee(`'${Object.keys(q).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ee(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ee(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},j=e=>{var t;const n=f[e.clientIdentifier],r=K(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=g[n.subscriptionKey],o=(null!=s?s:{})[i];if(F("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ee(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=W([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,F("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void x(n,i)}S(r,(()=>[n]),((t,n)=>{o&&(o.response=n),C(t,n,e.request)}),((t,n)=>{C(t,null,e.request,D(n))})),ee("Started heartbeat request.",n)},w=e=>{const t=f[e.clientIdentifier],n=R(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=W([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void x(t,s)}if(S(n,(()=>[t]),((t,n)=>{C(t,n,e.request)}),((t,n)=>{C(t,null,e.request,D(n))})),ee("Started leave request.",t),void 0===i)return;const s=E(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),$(s)},O=e=>{const t=f[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},$=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&I({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},S=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(T(t),{signal:null===(e=p.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),P(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(F("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},k=e=>{if(0===E(e).length){const t=p.get(e);p.delete(e),delete q[e],t&&t.abort("Cancel request")}},P=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{p.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),E=e=>Object.values(f).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),G=(e,t)=>{delete q[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},T=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ne(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},A=e=>{var t,n,r,i,s;const c=f[e.clientIdentifier],l=c.subscription,u=Q(l.timetoken,e),a=o.createUUID(),h=Object.assign({},e.request);let p,b;if(u.length>1){const s=_(u,e);if(s){const e=q[s],{channels:n,channelGroups:r}=null!==(t=c.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Y(e.channels,n))&&(!(r.length>0)||Y(e.channelGroups,r)))return s}const o=(null!==(n=v[c.subscriptionKey])&&void 0!==n?n:{})[c.userId],d={},f=new Set(l.channelGroups),g=new Set(l.channels);o&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=o[e];t&&(d[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===c.clientIdentifier||!t.timetoken||(p=t.timetoken,b=t.region),t.channelGroups.forEach(f.add,f),t.channels.forEach(g.add,g);const n=t.serviceRequestId;t.serviceRequestId=a,n&&q[n]&&k(n),o&&t.objectsWithState.forEach((e=>{const t=o[e];t&&!d[e]&&(d[e]=t)}))}const y=null!==(r=q[a])&&void 0!==r?r:q[a]={requestId:a,timetoken:null!==(i=h.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(g.size){y.channels=Array.from(g).sort();const e=h.path.split("/");e[4]=y.channels.join(","),h.path=e.join("/")}f.size&&(y.channelGroups=Array.from(f).sort(),h.queryParameters["channel-group"]=y.channelGroups.join(",")),Object.keys(d).length&&(h.queryParameters.state=JSON.stringify(d))}else q[a]={requestId:a,timetoken:null!==(s=h.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};if(q[a]&&(h.queryParameters&&void 0!==h.queryParameters.tt&&void 0!==h.queryParameters.tr&&(q[a].region=h.queryParameters.tr),q[a].timetokenOverride=p,q[a].regionOverride=b),l.serviceRequestId=a,h.identifier=a,d){const e=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");te(q[a],`Started aggregated request for clients: ${e}`)}return h},K=e=>{var t,n,r,i,s;const o=f[e.clientIdentifier],c=B(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=g[s=o.subscriptionKey])&&void 0!==t?t:g[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,h=o.heartbeat.channels;let p={},b=!1,v=!0;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},v=Y(e,o.heartbeat.channels)&&Y(t,o.heartbeat.channelGroups),n&&(b=n[0].status>=400)}else u[a]={channels:h,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},v=!1;if(v){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!b&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),h.push(...n.channels.filter((e=>!h.includes(e)))))}}u[a].channels=h,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))h.includes(e)||d.includes(e)||delete p[e];if(h.length){const e=l.path.split("/");e[6]=h.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},R=e=>{const t=f[e.clientIdentifier],n=H(e);let r=X(e.request),i=z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(d&&t){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(",");ee(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},x=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(e){}return!1},F=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let h;if("start"===e)h={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),h={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},h),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});x(e,t)}}},C=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},c=n&&n.path.startsWith("/v2/subscribe");!r&&t&&(r=t[0].status>=400?D(void 0,t):W(t));for(const t of e){if(c&&!t.subscription)continue;const e=o[t.clientIdentifier],{request:i}=null!==(s=t.subscription)&&void 0!==s?s:{};let l=null!=i?i:n;if(c||(l=n),e&&l){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:l.identifier,url:`${l.origin}${l.path}`});x(t,e)}}},W=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},W(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},U=e=>{var t,n,r,i;const{clientIdentifier:s}=e;if(f[s])return;const o=f[s]={clientIdentifier:s,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity},l=null!==(t=b[r=e.subscriptionKey])&&void 0!==t?t:b[r]=[];l.every((e=>e.clientIdentifier!==s))&&l.push(o),(null!==(n=y[i=e.subscriptionKey])&&void 0!==n?n:y[i]={})[s]=e.port,ee(`Registered PubNub client with '${s}' identifier. '${Object.keys(f).length}' clients currently active.`),!a&&Object.keys(f).length>0&&(ee("Setup PubNub client ping event 10 seconds"),a=setInterval((()=>Z()),c))},L=e=>{var t,n,r,i,s,o,c,l,u,a,d,h,p,b,g,y,q,I,m,j;const w=e.request.queryParameters,{clientIdentifier:O}=e,$=f[O];if(!$)return;const S=null!==(t=w["channel-group"])&&void 0!==t?t:"",k=null!==(n=w.state)&&void 0!==n?n:"";let P=$.subscription;if(P){if(k.length>0){const e=JSON.parse(k),t=null!==(o=(y=null!==(s=v[g=$.subscriptionKey])&&void 0!==s?s:v[g]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of P.objectsWithState)e[n]||delete t[n];P.objectsWithState=Object.keys(e)}else if(P.objectsWithState.length){const e=null!==(l=(m=null!==(c=v[I=$.subscriptionKey])&&void 0!==c?c:v[I]={})[j=$.userId])&&void 0!==l?l:m[j]={};for(const t of P.objectsWithState)delete e[t];P.objectsWithState=[]}}else{if(P={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},k.length>0){const e=JSON.parse(k),t=null!==(i=(p=null!==(r=v[h=$.subscriptionKey])&&void 0!==r?r:v[h]={})[b=$.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),P.objectsWithState=Object.keys(e)}$.subscription=P}P.path!==e.request.path&&(P.path=e.request.path,P.channels=z(e.request)),P.channelGroupQuery!==S&&(P.channelGroupQuery=S,P.channelGroups=X(e.request));const{authKey:E,userId:G}=$;P.request=e.request,P.filterExpression=null!==(u=w["filter-expr"])&&void 0!==u?u:"",P.timetoken=null!==(a=w.tt)&&void 0!==a?a:"0",void 0!==w.tr&&(P.region=w.tr),$.authKey=null!==(d=w.auth)&&void 0!==d?d:"",$.userId=w.uuid,M($,G,E)},N=e=>{var t,n;const r=f[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=X(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=g[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},V=e=>{const t=f[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},_=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=f[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ee(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=q[e.serviceRequestId];if(s||(s=X(t.request)),o||(o=z(t.request)),o.length&&!Y(r.channels,o))continue;if(s.length&&!Y(r.channelGroups,s))continue;return te(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},Q=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",l=s.uuid;return(null!==(i=b[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>H(e),H=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=b[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},X=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Y=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},Z=()=>{ee("Pinging clients...");const e={type:"shared-worker-ping"};Object.values(f).forEach((t=>{let n=!1;t&&t.lastPingRequest&&(ee(`Checking whether ${t.clientIdentifier} ping has been sent too long ago...`),(!t.lastPongEvent||Math.abs(t.lastPongEvent-t.lastPingRequest)>5)&&(n=!0,ee(`'${t.clientIdentifier}' client is inactive. Invalidating.`),((e,t)=>{delete f[t];let n=b[e];if(n)if(n=n.filter((e=>e.clientIdentifier!==t)),n.length>0?b[e]=n:(delete b[e],delete g[e]),0===n.length&&delete v[e],n.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];ee(`Invalidate '${t}' client. '${Object.keys(f).length}' clients currently active.`)})(t.subscriptionKey,t.clientIdentifier))),t&&!n&&(ee(`Sending ping to ${t.clientIdentifier}...`),t.lastPingRequest=(new Date).getTime()/1e3,x(t,e))})),0===Object.keys(f).length&&a&&clearInterval(a)},ee=(e,t)=>{if(!d)return;const n=t?[t]:Object.values(f),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&x(e,r)}))},te=(e,t,n)=>{if(!d)return;const r=n?[n]:Object.values(f),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&x(e,i)}))},ne=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${re(e)}`)).join("&"):`${t}=${re(n)}`})).join("&"),re=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((r=r.apply(e,t||[])).next())}))}var t;"function"==typeof SuppressedError&&SuppressedError,function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(t||(t={}));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r,i,s={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},v={},y={};self.onconnect=e=>{ee("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)n.port=e,D(n),ee(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-pong"===n.type)N(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){F(n);const e=h[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!l.has(t)){const e=setTimeout((()=>{q(n),l.delete(t)}),50);l.set(t,e)}}}else n.request.path.endsWith("/heartbeat")?(U(n),m(n)):w(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=e=>{var t;const n=P(e),r=h[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),R("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=y[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,R("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),A(r,u)}return}e.request.cancellable&&f.set(n.identifier,new AbortController);const s=y[n.identifier],{timetokenOverride:o,regionOverride:c}=s;j(n,(()=>T(n.identifier)),((t,r)=>{x(t,r,e.request),E(t,n.identifier)}),((t,r)=>{x(t,null,e.request,W(r)),E(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(t=I(t,o,c)),t})),ee(`'${Object.keys(y).length}' subscription request currently active.`)},I=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ee(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ee(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},m=e=>{var t;const n=h[e.clientIdentifier],r=C(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(R("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ee(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,R("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}j(r,(()=>[n]),((t,n)=>{o&&(o.response=n),x(t,n,e.request)}),((t,n)=>{x(t,null,e.request,W(n))})),ee("Started heartbeat request.",n)},w=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=G(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(j(n,(()=>[t]),((t,n)=>{x(t,n,e.request)}),((t,n)=>{x(t,null,e.request,W(n))})),ee("Started leave request.",t),void 0===i)return;const s=T(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),$(s)},O=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},$=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&q({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},j=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(K(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),S(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(R("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},k=e=>{if(0===T(e).length){const t=f.get(e);f.delete(e),delete y[e],t&&t.abort("Cancel request")}},S=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),T=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete y[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},K=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ne(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},P=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=_(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=H(u,e);if(s){const e=y[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Y(e.channels,n))&&(!(r.length>0)||Y(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),v=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(v.add,v);const n=t.serviceRequestId;t.serviceRequestId=a,n&&y[n]&&k(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=y[a])&&void 0!==r?r:y[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(v.size){q.channels=Array.from(v).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h))}else y[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};y[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(y[a].region=d.queryParameters.tr),y[a].timetokenOverride=f,y[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)te(y[a],`Started aggregated request for clients: ${b}`,e);return d},C=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=Q(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,v=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=Y(e,o.heartbeat.channels)&&Y(t,o.heartbeat.channelGroups),n&&(v=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;if(g){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!v&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},G=e=>{const t=h[e.clientIdentifier],n=B(e);let r=X(e.request),i=z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");ee(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=v[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},R=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=v[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},x=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=v[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?W(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)ee(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)ee(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&ee(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},W=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},D=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=v[s=e.subscriptionKey])&&void 0!==n?n:v[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)ee(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)ee(`Setup PubNub client ping event ${n} seconds`,e);a[e.subscriptionKey]=setTimeout((()=>Z(t)),500*n-1)}},F=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,v,y,q,I,m,w;const O=e.request.queryParameters,{clientIdentifier:$}=e,j=h[$];if(!j)return;const k=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let T=j.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=g[v=j.subscriptionKey])&&void 0!==s?s:g[v]={})[q=j.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=j.subscriptionKey])&&void 0!==c?c:g[I]={})[w=j.userId])&&void 0!==l?l:m[w]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=j.subscriptionKey])&&void 0!==r?r:g[f]={})[b=j.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}j.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=z(e.request)),T.channelGroupQuery!==k&&(T.channelGroupQuery=k,T.channelGroups=X(e.request));const{authKey:E,userId:K}=j;T.request=e.request,T.filterExpression=null!==(u=O["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(T.region=O.tr),j.authKey=null!==(d=O.auth)&&void 0!==d?d:"",j.origin=e.request.origin,j.userId=O.uuid,j.pnsdk=O.pnsdk,V(j,K,E)},U=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=X(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},V=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},N=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},M=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r}=e.subscription,i=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>re(e))).sort(),s=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>re(e))).sort();if(0===s.length&&0===i.length)return;const o=i.length>0?i.join(","):void 0,l=0===s.length?",":s.join(","),u=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),o?{"channel-group":o}:{}),a={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${l}/leave`,queryParameters:u,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:u.requestid}};w(a,e)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},H=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ee(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=y[e.serviceRequestId];if(s||(s=X(t.request)),o||(o=z(t.request)),o.length&&!Y(r.channels,o))continue;if(s.length&&!Y(r.channelGroups,s))continue;return te(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},_=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",l=s.uuid;return(null!==(i=p[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},Q=e=>B(e),B=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=p[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},X=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Y=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},Z=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)ee(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);((e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r&&r.unsubscribeOfflineClients&&M(r),i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=v[e];n&&(delete n[t],0===Object.keys(n).length&&delete v[e])}else delete v[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)ee(s,e);else ee(s)})(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>Z(e)),500*t-1)}},ee=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},te=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},ne=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${re(e)}`)).join("&"):`${t}=${re(n)}`})).join("&"),re=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index cbdcb5eca..225cbdaed 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.9.1'; + return '8.10.0'; }, getVersion() { return this.version; diff --git a/lib/core/components/subscription-manager.js b/lib/core/components/subscription-manager.js index eba764d5d..35dd1a633 100644 --- a/lib/core/components/subscription-manager.js +++ b/lib/core/components/subscription-manager.js @@ -82,7 +82,7 @@ class SubscriptionManager { */ reconnect(forUnsubscribe = false) { this.startSubscribeLoop(); - if (!forUnsubscribe) + if (!forUnsubscribe && this.configuration.useSmartHeartbeat) this.startHeartbeatTimer(); } /** diff --git a/lib/core/interfaces/configuration.js b/lib/core/interfaces/configuration.js index 9749f38ac..ddca709b2 100644 --- a/lib/core/interfaces/configuration.js +++ b/lib/core/interfaces/configuration.js @@ -42,6 +42,10 @@ const ENABLE_EVENT_ENGINE = false; * Whether configured user presence state should be maintained by the PubNub client or not. */ const MAINTAIN_PRESENCE_STATE = true; +/** + * Whether heartbeat should be postponed on successful subscribe response or not. + */ +const USE_SMART_HEARTBEAT = true; /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -98,7 +102,7 @@ const PRESENCE_TIMEOUT_MINIMUM = 20; * @internal */ const setDefaults = (configuration) => { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r; // Copy configuration. const configurationCopy = Object.assign({}, configuration); (_a = configurationCopy.logVerbosity) !== null && _a !== void 0 ? _a : (configurationCopy.logVerbosity = USE_VERBOSE_LOGGING); @@ -113,13 +117,14 @@ const setDefaults = (configuration) => { (_k = configurationCopy.autoNetworkDetection) !== null && _k !== void 0 ? _k : (configurationCopy.autoNetworkDetection = AUTO_NETWORK_DETECTION); (_l = configurationCopy.enableEventEngine) !== null && _l !== void 0 ? _l : (configurationCopy.enableEventEngine = ENABLE_EVENT_ENGINE); (_m = configurationCopy.maintainPresenceState) !== null && _m !== void 0 ? _m : (configurationCopy.maintainPresenceState = MAINTAIN_PRESENCE_STATE); - (_o = configurationCopy.keepAlive) !== null && _o !== void 0 ? _o : (configurationCopy.keepAlive = KEEP_ALIVE); + (_o = configurationCopy.useSmartHeartbeat) !== null && _o !== void 0 ? _o : (configurationCopy.useSmartHeartbeat = USE_SMART_HEARTBEAT); + (_p = configurationCopy.keepAlive) !== null && _p !== void 0 ? _p : (configurationCopy.keepAlive = KEEP_ALIVE); if (configurationCopy.userId && configurationCopy.uuid) throw new pubnub_error_1.PubNubError("PubNub client configuration error: use only 'userId'"); - (_p = configurationCopy.userId) !== null && _p !== void 0 ? _p : (configurationCopy.userId = configurationCopy.uuid); + (_q = configurationCopy.userId) !== null && _q !== void 0 ? _q : (configurationCopy.userId = configurationCopy.uuid); if (!configurationCopy.userId) throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' not set"); - else if (((_q = configurationCopy.userId) === null || _q === void 0 ? void 0 : _q.trim().length) === 0) + else if (((_r = configurationCopy.userId) === null || _r === void 0 ? void 0 : _r.trim().length) === 0) throw new pubnub_error_1.PubNubError("PubNub client configuration error: 'userId' is empty"); // Generate default origin subdomains. if (!configurationCopy.origin) diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index cbfb2fb6d..c93707f1c 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -2580,6 +2580,19 @@ declare namespace PubNub { * @default `true` */ maintainPresenceState?: boolean; + /** + * Whether heartbeat should be postponed on successful subscribe response. + * + * With implicit heartbeat each successful `subscribe` loop response is treated as `heartbeat` + * and there is no need to send another explicit heartbeat earlier than `heartbeatInterval` + * since moment of `subscribe` response. + * + * **Note:** With disabled implicit heartbeat this feature may cause `timeout` if there is + * constant activity on subscribed channels / groups. + * + * @default `true` + */ + useSmartHeartbeat?: boolean; /** * `UUID` to use. You should set a unique `UUID` to identify the user or the device that * connects to PubNub. diff --git a/package.json b/package.json index 78f5835b4..fe93bdd1d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.9.1", + "version": "8.10.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index e87a19d7e..13df6eed1 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.9.1'; + return '8.10.0'; }, getVersion(): string { return this.version; diff --git a/src/core/components/subscription-manager.ts b/src/core/components/subscription-manager.ts index 269f08d1f..c3de3cffc 100644 --- a/src/core/components/subscription-manager.ts +++ b/src/core/components/subscription-manager.ts @@ -197,7 +197,7 @@ export class SubscriptionManager { */ public reconnect(forUnsubscribe: boolean = false) { this.startSubscribeLoop(); - if (!forUnsubscribe) this.startHeartbeatTimer(); + if (!forUnsubscribe && this.configuration.useSmartHeartbeat) this.startHeartbeatTimer(); } /** diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index d0817a50b..78f4091cd 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -54,6 +54,11 @@ const ENABLE_EVENT_ENGINE = false; */ const MAINTAIN_PRESENCE_STATE = true; +/** + * Whether heartbeat should be postponed on successful subscribe response or not. + */ +const USE_SMART_HEARTBEAT = true; + /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -307,6 +312,20 @@ export type UserConfiguration = { */ maintainPresenceState?: boolean; + /** + * Whether heartbeat should be postponed on successful subscribe response. + * + * With implicit heartbeat each successful `subscribe` loop response is treated as `heartbeat` + * and there is no need to send another explicit heartbeat earlier than `heartbeatInterval` + * since moment of `subscribe` response. + * + * **Note:** With disabled implicit heartbeat this feature may cause `timeout` if there is + * constant activity on subscribed channels / groups. + * + * @default `true` + */ + useSmartHeartbeat?: boolean; + /** * `UUID` to use. You should set a unique `UUID` to identify the user or the device that * connects to PubNub. @@ -736,6 +755,7 @@ export const setDefaults = (configuration: UserConfiguration): ExtendedConfigura configurationCopy.autoNetworkDetection ??= AUTO_NETWORK_DETECTION; configurationCopy.enableEventEngine ??= ENABLE_EVENT_ENGINE; configurationCopy.maintainPresenceState ??= MAINTAIN_PRESENCE_STATE; + configurationCopy.useSmartHeartbeat ??= USE_SMART_HEARTBEAT; configurationCopy.keepAlive ??= KEEP_ALIVE; if (configurationCopy.userId && configurationCopy.uuid) diff --git a/src/transport/subscription-worker/subscription-worker-middleware.ts b/src/transport/subscription-worker/subscription-worker-middleware.ts index b1c5acf4c..10663c0c6 100644 --- a/src/transport/subscription-worker/subscription-worker-middleware.ts +++ b/src/transport/subscription-worker/subscription-worker-middleware.ts @@ -50,6 +50,16 @@ type PubNubMiddlewareConfiguration = { */ logVerbosity: boolean; + /** + * Interval at which Shared Worker should check whether PubNub instances which used it still active or not. + */ + workerOfflineClientsCheckInterval: number; + + /** + * Whether `leave` request should be sent for _offline_ PubNub client or not. + */ + workerUnsubscribeOfflineClients: boolean; + /** * Whether verbose logging should be enabled for `Subscription` worker should print debug messages or not. */ @@ -234,6 +244,8 @@ export class SubscriptionWorkerMiddleware implements Transport { userId: this.configuration.userId, heartbeatInterval: this.configuration.heartbeatInterval, logVerbosity: this.configuration.logVerbosity, + workerOfflineClientsCheckInterval: this.configuration.workerOfflineClientsCheckInterval, + workerUnsubscribeOfflineClients: this.configuration.workerUnsubscribeOfflineClients, workerLogVerbosity: this.configuration.workerLogVerbosity, }, true, diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index e71e4ee19..54b24150b 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -8,7 +8,7 @@ * @internal */ -import { TransportRequest } from '../../core/types/transport-request'; +import { TransportMethod, TransportRequest } from '../../core/types/transport-request'; import uuidGenerator from '../../core/components/uuid'; import { Payload, Query } from '../../core/types/api'; @@ -37,6 +37,16 @@ type BasicEvent = { */ logVerbosity: boolean; + /** + * Interval at which Shared Worker should check whether PubNub instances which used it still active or not. + */ + workerOfflineClientsCheckInterval?: number; + + /** + * Whether `leave` request should be sent for _offline_ PubNub client or not. + */ + workerUnsubscribeOfflineClients?: boolean; + /** * Whether verbose logging should be enabled for `Subscription` worker should print debug messages or not. */ @@ -373,6 +383,16 @@ type PubNubClientState = { */ authKey?: string; + /** + * Origin which is used to access PubNub REST API. + */ + origin?: string; + + /** + * PubNub JS SDK identification string. + */ + pnsdk?: string; + /** * How often the client will announce itself to server. The value is in seconds. * @@ -385,6 +405,21 @@ type PubNubClientState = { */ logVerbosity: boolean; + /** + * Interval at which Shared Worker should check whether PubNub instances which used it still active or not. + */ + offlineClientsCheckInterval?: number; + + /** + * Whether `leave` request should be sent for _offline_ PubNub client or not. + */ + unsubscribeOfflineClients?: boolean; + + /** + * Whether client should log Shared Worker logs or not. + */ + workerLogVerbosity?: boolean; + /** * Last time when PING request has been sent. */ @@ -498,11 +533,6 @@ type PubNubClientState = { declare const self: SharedWorkerGlobalScope; -/** - * How often PING request should be sent to the PubNub clients. - */ -const clientPingRequestInterval = 10000; - /** * Aggregation timer timeout. * @@ -523,25 +553,15 @@ const aggregationTimers: Map = new Map(); const decoder = new TextDecoder(); /** - * Whether `Subscription` worker should print debug information to the console or not. - */ -let logVerbosity: boolean = false; - -/** - * PubNub clients active ping interval. + * Per-subscription key map of "offline" clients detection timeouts. */ -let pingInterval: number | undefined; +const pingTimeouts: { [subscriptionKey: string]: number | undefined } = {}; /** * Unique shared worker instance identifier. */ const sharedWorkerIdentifier = uuidGenerator.createUUID(); -/** - * FIFO list of events which should be processed by - */ -const eventsQueue: MessageEvent[] = []; - /** * Map of identifiers, scheduled by the Service Worker, to their abort controllers. * @@ -664,8 +684,6 @@ self.onconnect = (event) => { const data = event.data as ClientEvent; if (data.type === 'client-register') { - if (!logVerbosity && data.workerLogVerbosity) logVerbosity = true; - // Appending information about messaging port for responses. data.port = receiver; registerClientIfRequired(data); @@ -781,7 +799,6 @@ const handleSendSubscribeRequestEvent = (event: SendRequestEvent) => { (response) => { let serverResponse = response; if (isInitialSubscribe && timetokenOverride && timetokenOverride !== '0') { - const scheduledRequest = serviceRequests[requestOrId.identifier]; serverResponse = patchInitialSubscribeResponse(serverResponse, timetokenOverride, regionOverride); } @@ -915,9 +932,10 @@ const handleHeartbeatRequestEvent = (event: SendRequestEvent) => { * Handle client request to leave request. * * @param data - Leave event details. + * @param [client] - Specific client to handle leave request. */ -const handleSendLeaveRequestEvent = (data: SendRequestEvent) => { - const client = pubNubClients[data.clientIdentifier]; +const handleSendLeaveRequestEvent = (data: SendRequestEvent, client?: PubNubClientState) => { + client = client ?? pubNubClients[data.clientIdentifier]; const request = leaveTransportRequestFromEvent(data); if (!client) return; @@ -1167,7 +1185,7 @@ const clientsForRequest = (identifier: string) => { /** * Clean up PubNub client states from ongoing request. * - * Reset requested and scheduled request information to make PubNub client "free" for neext requests. + * Reset requested and scheduled request information to make PubNub client "free" for next requests. * * @param clients - List of PubNub clients which awaited for scheduled request completion. * @param requestId - Unique subscribe request identifier for which {@link clients} has been provided. @@ -1335,15 +1353,16 @@ const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportR subscription.serviceRequestId = serviceRequestId; request.identifier = serviceRequestId; - if (logVerbosity) { - const clientIds = clients - .reduce((identifiers: string[], { clientIdentifier }) => { - identifiers.push(clientIdentifier); - return identifiers; - }, []) - .join(','); + const clientIds = clients + .reduce((identifiers: string[], { clientIdentifier }) => { + identifiers.push(clientIdentifier); + return identifiers; + }, []) + .join(', '); - consoleDir(serviceRequests[serviceRequestId], `Started aggregated request for clients: ${clientIds}`); + if (clientIds.length > 0) { + for (const _client of clients) + consoleDir(serviceRequests[serviceRequestId], `Started aggregated request for clients: ${clientIds}`, _client); } return request; @@ -1370,9 +1389,9 @@ const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportR const heartbeatRequestKey = `${client.userId}_${client.authKey ?? ''}`; const channelGroupsForAnnouncement: string[] = client.heartbeat.channelGroups; const channelsForAnnouncement: string[] = client.heartbeat.channels; - let aggregatedState: Record = {}; + let aggregatedState: Record; let failedPreviousRequest = false; - let aggregated = true; + let aggregated: boolean; if (!hbRequestsBySubscriptionKey[heartbeatRequestKey]) { hbRequestsBySubscriptionKey[heartbeatRequestKey] = { @@ -1492,13 +1511,13 @@ const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportReque } if (channels.length === 0 && channelGroups.length === 0) { - if (logVerbosity && client) { + if (client && client.workerLogVerbosity) { const clientIds = clients .reduce((identifiers: string[], { clientIdentifier }) => { identifiers.push(clientIdentifier); return identifiers; }, []) - .join(','); + .join(', '); consoleLog( `Specified channels and groups still in use by other clients: ${clientIds}. Ignoring leave request.`, @@ -1535,7 +1554,9 @@ const publishClientEvent = (client: PubNubClientState, event: SubscriptionWorker try { receiver.postMessage(event); return true; - } catch (error) {} + } catch (error) { + if (client.workerLogVerbosity) console.error(`[SharedWorker] Unable send message using message port: ${error}`); + } return false; }; @@ -1634,6 +1655,7 @@ const notifyRequestProcessingResult = ( if (clients.length === 0) return; if (!result && !response) return; + const workerLogVerbosity = clients.some((client) => client && client.workerLogVerbosity); const clientIds = sharedWorkerClients[clients[0].subscriptionKey] ?? {}; const isSubscribeRequest = request && request.path.startsWith('/v2/subscribe'); @@ -1645,8 +1667,30 @@ const notifyRequestProcessingResult = ( : requestProcessingSuccess(response); } + // Notify about subscribe and leave requests completion. + if (workerLogVerbosity && request && !request.path.endsWith('/heartbeat')) { + const notifiedClientIds = clients + .reduce((identifiers: string[], { clientIdentifier }) => { + identifiers.push(clientIdentifier); + return identifiers; + }, []) + .join(', '); + const endpoint = isSubscribeRequest ? 'subscribe' : 'leave'; + + const message = `Notify clients about ${endpoint} request completion: ${notifiedClientIds}`; + for (const client of clients) consoleLog(message, client); + } + for (const client of clients) { - if (isSubscribeRequest && !client.subscription) continue; + if (isSubscribeRequest && !client.subscription) { + // Notifying about client with inactive subscription. + if (workerLogVerbosity) { + const message = `${client.clientIdentifier} doesn't have active subscription. Don't notify about completion.`; + for (const nClient of clients) consoleLog(message, nClient); + } + + continue; + } const serviceWorkerClientId = clientIds[client.clientIdentifier]; const { request: clientRequest } = client.subscription ?? {}; @@ -1662,6 +1706,14 @@ const notifyRequestProcessingResult = ( }; publishClientEvent(client, payload); + } else if (!serviceWorkerClientId && workerLogVerbosity) { + // Notifying about client without Shared Worker's communication channel. + const message = `${ + client.clientIdentifier + } doesn't have Shared Worker's communication channel. Don't notify about completion.`; + for (const nClient of clients) { + if (nClient.clientIdentifier !== client.clientIdentifier) consoleLog(message, nClient); + } } } }; @@ -1773,6 +1825,9 @@ const registerClientIfRequired = (event: RegisterEvent) => { userId: event.userId, heartbeatInterval: event.heartbeatInterval, logVerbosity: event.logVerbosity, + offlineClientsCheckInterval: event.workerOfflineClientsCheckInterval, + unsubscribeOfflineClients: event.workerUnsubscribeOfflineClients, + workerLogVerbosity: event.workerLogVerbosity, }); // Map registered PubNub client to its subscription key. @@ -1783,14 +1838,24 @@ const registerClientIfRequired = (event: RegisterEvent) => { // Binding PubNub client to the MessagePort (receiver). (sharedWorkerClients[event.subscriptionKey] ??= {})[clientIdentifier] = event.port; - consoleLog( + const message = `Registered PubNub client with '${clientIdentifier}' identifier. ` + - `'${Object.keys(pubNubClients).length}' clients currently active.`, - ); - - if (!pingInterval && Object.keys(pubNubClients).length > 0) { - consoleLog(`Setup PubNub client ping event ${clientPingRequestInterval / 1000} seconds`); - pingInterval = setInterval(() => pingClients(), clientPingRequestInterval) as unknown as number; + `'${clientsBySubscriptionKey.length}' clients currently active.`; + for (const _client of clientsBySubscriptionKey) consoleLog(message, _client); + + if ( + !pingTimeouts[event.subscriptionKey] && + (pubNubClientsBySubscriptionKey[event.subscriptionKey] ?? []).length > 0 + ) { + const { subscriptionKey } = event; + const interval = event.workerOfflineClientsCheckInterval!; + for (const _client of clientsBySubscriptionKey) + consoleLog(`Setup PubNub client ping event ${interval} seconds`, _client); + + pingTimeouts[event.subscriptionKey] = setTimeout( + () => pingClients(subscriptionKey), + interval * 500 - 1, + ) as unknown as number; } }; @@ -1870,7 +1935,9 @@ const updateClientSubscribeStateIfRequired = (event: SendRequestEvent) => { subscription.timetoken = (query.tt ?? '0') as string; if (query.tr !== undefined) subscription.region = query.tr as string; client.authKey = (query.auth ?? '') as string; + client.origin = event.request.origin; client.userId = query.uuid as string; + client.pnsdk = query.pnsdk as string; handleClientIdentityChangeIfRequired(client, userId, authKey); }; @@ -1945,9 +2012,13 @@ const handleClientPong = (event: PongEvent) => { * @param clientId - Unique PubNub client identifier. */ const invalidateClient = (subscriptionKey: string, clientId: string) => { + const invalidatedClient = pubNubClients[clientId]; delete pubNubClients[clientId]; let clients = pubNubClientsBySubscriptionKey[subscriptionKey]; + // Unsubscribe invalidated PubNub client. + if (invalidatedClient && invalidatedClient.unsubscribeOfflineClients) unsubscribeClient(invalidatedClient); + if (clients) { // Clean up linkage between client and subscription key. clients = clients.filter((client) => client.clientIdentifier !== clientId); @@ -1971,7 +2042,56 @@ const invalidateClient = (subscriptionKey: string, clientId: string) => { } else delete sharedWorkerClients[subscriptionKey]; } - consoleLog(`Invalidate '${clientId}' client. '${Object.keys(pubNubClients).length}' clients currently active.`); + const message = `Invalidate '${clientId}' client. '${ + (pubNubClientsBySubscriptionKey[subscriptionKey] ?? []).length + }' clients currently active.`; + if (!clients) consoleLog(message); + else for (const _client of clients) consoleLog(message, _client); +}; + +const unsubscribeClient = (client: PubNubClientState) => { + if (!client.subscription) return; + + const { channels, channelGroups } = client.subscription; + const encodedChannelGroups = (channelGroups ?? []) + .filter((name) => !name.endsWith('-pnpres')) + .map((name) => encodeString(name)) + .sort(); + const encodedChannels = (channels ?? []) + .filter((name) => !name.endsWith('-pnpres')) + .map((name) => encodeString(name)) + .sort(); + + if (encodedChannels.length === 0 && encodedChannelGroups.length === 0) return; + const channelGroupsString: string | undefined = + encodedChannelGroups.length > 0 ? encodedChannelGroups.join(',') : undefined; + const channelsString = encodedChannels.length === 0 ? ',' : encodedChannels.join(','); + const query: Query = { + instanceid: client.clientIdentifier, + uuid: client.userId, + requestid: uuidGenerator.createUUID(), + ...(client.authKey ? { auth: client.authKey } : {}), + ...(channelGroupsString ? { 'channel-group': channelGroupsString } : {}), + }; + + const request: SendRequestEvent = { + type: 'send-request', + clientIdentifier: client.clientIdentifier, + subscriptionKey: client.subscriptionKey, + logVerbosity: client.logVerbosity, + request: { + origin: client.origin, + path: `/v2/presence/sub-key/${client.subscriptionKey}/channel/${channelsString}/leave`, + queryParameters: query, + method: TransportMethod.GET, + headers: {}, + timeout: 10, + cancellable: false, + identifier: query.requestid as string, + }, + }; + + handleSendLeaveRequestEvent(request, client); }; /** @@ -2153,37 +2273,45 @@ const includesStrings = (main: string[], sub: string[]) => { /** * Send PubNub client PING request to identify disconnected instances. + * + * @param subscriptionKey - Subscribe key for which offline PubNub client should be checked. */ -const pingClients = () => { - consoleLog(`Pinging clients...`); +const pingClients = (subscriptionKey: string) => { const payload: SharedWorkerPing = { type: 'shared-worker-ping' }; - Object.values(pubNubClients).forEach((client) => { + const _pubNubClients = Object.values(pubNubClients).filter( + (client) => client && client.subscriptionKey === subscriptionKey, + ); + _pubNubClients.forEach((client) => { let clientInvalidated = false; if (client && client.lastPingRequest) { - consoleLog(`Checking whether ${client.clientIdentifier} ping has been sent too long ago...`); + const interval = client.offlineClientsCheckInterval!; + // Check whether client never respond or last response was too long time ago. - if ( - !client.lastPongEvent || - Math.abs(client.lastPongEvent - client.lastPingRequest) > (clientPingRequestInterval / 1000) * 0.5 - ) { + if (!client.lastPongEvent || Math.abs(client.lastPongEvent - client.lastPingRequest) > interval * 0.5) { clientInvalidated = true; - consoleLog(`'${client.clientIdentifier}' client is inactive. Invalidating.`); + for (const _client of _pubNubClients) + consoleLog(`'${client.clientIdentifier}' client is inactive. Invalidating...`, _client); invalidateClient(client.subscriptionKey, client.clientIdentifier); } } if (client && !clientInvalidated) { - consoleLog(`Sending ping to ${client.clientIdentifier}...`); client.lastPingRequest = new Date().getTime() / 1000; publishClientEvent(client, payload); } }); - // Cancel interval if there is no active clients. - if (Object.keys(pubNubClients).length === 0 && pingInterval) clearInterval(pingInterval); + // Restart ping timer if there is still active PubNub clients for subscription key. + if (_pubNubClients && _pubNubClients.length > 0 && _pubNubClients[0]) { + const interval = _pubNubClients[0].offlineClientsCheckInterval!; + pingTimeouts[subscriptionKey] = setTimeout( + () => pingClients(subscriptionKey), + interval * 500 - 1, + ) as unknown as number; + } }; /** @@ -2193,9 +2321,9 @@ const pingClients = () => { * @param [client] - Target client to which log message should be sent. */ const consoleLog = (message: string, client?: PubNubClientState): void => { - if (!logVerbosity) return; - - const clients = client ? [client] : Object.values(pubNubClients); + const clients = (client ? [client] : Object.values(pubNubClients)).filter( + (client) => client && client.workerLogVerbosity, + ); const payload: SharedWorkerConsoleLog = { type: 'shared-worker-console-log', message, @@ -2214,9 +2342,9 @@ const consoleLog = (message: string, client?: PubNubClientState): void => { * @param [client] - Target client to which log message should be sent. */ const consoleDir = (data: Payload, message?: string, client?: PubNubClientState): void => { - if (!logVerbosity) return; - - const clients = client ? [client] : Object.values(pubNubClients); + const clients = (client ? [client] : Object.values(pubNubClients)).filter( + (client) => client && client.workerLogVerbosity, + ); const payload: SharedWorkerConsoleDir = { type: 'shared-worker-console-dir', message, diff --git a/src/web/components/configuration.ts b/src/web/components/configuration.ts index e9ae3363f..a958bbf0e 100644 --- a/src/web/components/configuration.ts +++ b/src/web/components/configuration.ts @@ -23,6 +23,16 @@ const LISTEN_TO_BROWSER_NETWORK_EVENTS = true; */ const SUBSCRIPTION_WORKER_LOG_VERBOSITY = false; +/** + * Interval at which Shared Worker should check whether PubNub instances which used it still active or not. + */ +const SUBSCRIPTION_WORKER_OFFLINE_CLIENTS_CHECK_INTERVAL = 10; + +/** + * Whether `leave` request should be sent for _offline_ PubNub client or not. + */ +const SUBSCRIPTION_WORKER_UNSUBSCRIBE_OFFLINE_CLIENTS = false; + /** * Use modern Web Fetch API for network requests by default. */ @@ -58,6 +68,26 @@ export type PubNubConfiguration = UserConfiguration & { */ subscriptionWorkerUrl?: string | null; + /** + * Interval at which Shared Worker should check whether PubNub instances which used it still active or not. + * + * With every iteration, Shared Worker will detect for _offline_ PubNub client instances which should be removed from + * the list of tracked instances. + * + * @default `10` seconds + */ + subscriptionWorkerOfflineClientsCheckInterval?: number; + + /** + * Whether `leave` request should be sent for _offline_ PubNub client or not. + * + * It is possible for Shared Worker as part of _offline_ PubNub clients clean up send `leave` request for proper + * leave. This behavior can be useful to gracefully handle browser tab / window close. + * + * @default `false` + */ + subscriptionWorkerUnsubscribeOfflineClients?: boolean; + /** * Whether verbose logging should be enabled for `Subscription` worker should print debug messages or not. * @@ -131,6 +161,10 @@ export const setDefaults = (configuration: PubNubConfiguration): PubNubConfigura // Set platform-specific options. listenToBrowserNetworkEvents: configuration.listenToBrowserNetworkEvents ?? LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, + subscriptionWorkerOfflineClientsCheckInterval: + configuration.subscriptionWorkerOfflineClientsCheckInterval ?? SUBSCRIPTION_WORKER_OFFLINE_CLIENTS_CHECK_INTERVAL, + subscriptionWorkerUnsubscribeOfflineClients: + configuration.subscriptionWorkerUnsubscribeOfflineClients ?? SUBSCRIPTION_WORKER_UNSUBSCRIBE_OFFLINE_CLIENTS, subscriptionWorkerLogVerbosity: configuration.subscriptionWorkerLogVerbosity ?? SUBSCRIPTION_WORKER_LOG_VERBOSITY, transport: configuration.transport ?? TRANSPORT, keepAlive: configuration.keepAlive ?? KEEP_ALIVE, diff --git a/src/web/index.ts b/src/web/index.ts index f24ffb924..b94035f5e 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -108,6 +108,8 @@ export default class PubNub extends PubNubCore Date: Mon, 10 Mar 2025 12:17:37 +0200 Subject: [PATCH 40/49] Subscription set will subscribe added entities and SharedWorker will make proper subscribe throttling (#443) feat(subscription-set): subscription set will subscribe added entities `SubscriptionSet` will subscribe / unsubscribe added / removed `Subscription` or `SubscriptionSet` objects if the set itself already subscribed. fix(shared-worker): fix subscribe throttle Fix issue because of which throttle didn't consider difference in client settings (throttled only by user ID and subscribe key, which is not enough). fix(smart-heartbeat): fix smart heartbeat usage With the fix, smart heartbeat as feature has been added to the SDK, and it is disabled by default. refactor(shared-worker): use more complex aggregation timer key --- .pubnub.yml | 15 +++- CHANGELOG.md | 10 +++ README.md | 5 +- dist/web/pubnub.js | 86 +++++++++++++++++-- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 49 +++++++++-- dist/web/pubnub.worker.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/components/subscription-manager.js | 21 ++++- lib/core/interfaces/configuration.js | 2 +- lib/entities/SubscribeCapable.js | 4 + lib/entities/Subscription.js | 27 +++++- lib/entities/SubscriptionSet.js | 30 +++++++ package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/components/subscription-manager.ts | 22 ++++- src/core/interfaces/configuration.ts | 2 +- src/entities/SubscribeCapable.ts | 21 +++++ src/entities/Subscription.ts | 32 ++++++- src/entities/SubscriptionSet.ts | 34 ++++++++ .../subscription-worker.ts | 53 +++++++++--- 21 files changed, 375 insertions(+), 50 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 652877d4b..063adc0da 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,14 @@ --- changelog: + - date: 2025-03-10 + version: v9.0.0 + changes: + - type: feature + text: "BREAKING CHANGES: `SubscriptionSet` will subscribe / unsubscribe added / removed `Subscription` or `SubscriptionSet` objects if the set itself already subscribed." + - type: bug + text: "Fix issue because of which throttle didn't consider difference in client settings (throttled only by user ID and subscribe key, which is not enough)." + - type: bug + text: "With the fix, smart heartbeat as feature has been added to the SDK, and it is disabled by default." - date: 2025-03-06 version: v8.10.0 changes: @@ -1160,7 +1169,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '8.10.0' +version: '9.0.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1176,7 +1185,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v8.10.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.0.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1847,7 +1856,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v8.10.0/pubnub.8.10.0.js + location: https://github.com/pubnub/javascript/releases/download/v9.0.0/pubnub.9.0.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index d5a897289..4c7118b41 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## v9.0.0 +March 10 2025 + +#### Added +- BREAKING CHANGES: `SubscriptionSet` will subscribe / unsubscribe added / removed `Subscription` or `SubscriptionSet` objects if the set itself already subscribed. + +#### Fixed +- Fix issue because of which throttle didn't consider difference in client settings (throttled only by user ID and subscribe key, which is not enough). +- With the fix, smart heartbeat as feature has been added to the SDK, and it is disabled by default. + ## v8.10.0 March 06 2025 diff --git a/README.md b/README.md index dfdbdfd46..996487ed0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # PubNub JavaScript SDK (V4) -[![Build Status](https://travis-ci.com/pubnub/javascript.svg?branch=master)](https://travis-ci.com/pubnub/javascript) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2859917905c549b8bfa27630ff276fce)](https://www.codacy.com/app/PubNub/javascript?utm_source=github.com&utm_medium=referral&utm_content=pubnub/javascript&utm_campaign=Badge_Grade) [![npm](https://img.shields.io/npm/v/pubnub.svg)]() [![Bower](https://img.shields.io/bower/v/pubnub.svg)]() @@ -28,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.10.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.8.10.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.0.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.0.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index c02305eee..22c65e545 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3438,7 +3438,7 @@ /** * Whether heartbeat should be postponed on successful subscribe response or not. */ - const USE_SMART_HEARTBEAT = true; + const USE_SMART_HEARTBEAT = false; /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ @@ -3818,7 +3818,7 @@ return base.PubNubFile; }, get version() { - return '8.10.0'; + return '9.0.0'; }, getVersion() { return this.version; @@ -4944,8 +4944,9 @@ * unsubscribe or not. */ reconnect(forUnsubscribe = false) { - this.startSubscribeLoop(); - if (!forUnsubscribe && this.configuration.useSmartHeartbeat) + this.startSubscribeLoop(forUnsubscribe); + // Starting heartbeat loop for provided channels and groups. + if (!forUnsubscribe && !this.configuration.useSmartHeartbeat) this.startHeartbeatTimer(); } /** @@ -5053,7 +5054,15 @@ channelGroups: this.subscribedChannelGroups, }, isOffline); } - startSubscribeLoop() { + /** + * Start next subscription loop. + * + * @param restartOnUnsubscribe - Whether restarting subscription loop as part of channels list change on + * unsubscribe or not. + * + * @internal + */ + startSubscribeLoop(restartOnUnsubscribe = false) { this.stopSubscribeLoop(); const channelGroups = [...Object.keys(this.channelGroups)]; const channels = [...Object.keys(this.channels)]; @@ -5073,6 +5082,8 @@ }, (status, result) => { this.processSubscribeResponse(status, result); }); + if (!restartOnUnsubscribe && this.configuration.useSmartHeartbeat) + this.startHeartbeatTimer(); } stopSubscribeLoop() { if (this._subscribeAbort) { @@ -5224,7 +5235,9 @@ const heartbeatInterval = this.configuration.getHeartbeatInterval(); if (!heartbeatInterval || heartbeatInterval === 0) return; - this.sendHeartbeat(); + // Sending immediate heartbeat only if not working as smart heartbeat. + if (!this.configuration.useSmartHeartbeat) + this.sendHeartbeat(); this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), heartbeatInterval * 1000); } /** @@ -10084,6 +10097,8 @@ subscribe(subscribeParameters) { const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken; this.pubnub.registerSubscribeCapable(this); + this.subscribedAutomatically = false; + this.subscribed = true; this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken }))); } /** @@ -10091,6 +10106,8 @@ */ unsubscribe() { this.pubnub.unregisterSubscribeCapable(this); + this.subscribedAutomatically = false; + this.subscribed = false; const { channels, channelGroups } = this.pubnub.getSubscribeCapableEntities(); // Identify channels and groups from which PubNub client can safely unsubscribe. const filteredChannelGroups = this.groupNames.filter((cg) => !channelGroups.includes(cg)); @@ -10251,6 +10268,19 @@ * @internal */ this.subscriptionList = []; + /** + * Whether subscribed ({@link SubscribeCapable#subscribe}) automatically during subscription + * object / sets manipulation or not. + * + * @internal + */ + this.subscribedAutomatically = false; + /** + * Whether subscribable object subscribed ({@link SubscribeCapable#subscribe}) or not. + * + * @internal + */ + this.subscribed = false; this.options = subscriptionOptions; this.eventEmitter = eventEmitter; this.pubnub = pubnub; @@ -10280,6 +10310,13 @@ this.channelNames = [...this.channelNames, ...subscription.channels]; this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); + // Subscribe subscription object if subscription set already subscribed. + // @ts-expect-error: Required access of protected field. + if (this.subscribed && !subscription.subscribed) { + subscription.subscribe(); + // @ts-expect-error: Required modification of protected field. + subscription.subscribedAutomatically = true; // should be placed after .subscribe() call. + } } /** * Remove entity's subscription object from the set. @@ -10296,6 +10333,9 @@ this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + // @ts-expect-error: Required access of protected field. + if (subscription.subscribedAutomatically) + subscription.unsubscribe(); } /** * Merge with other subscription set object. @@ -10310,6 +10350,11 @@ this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); + // Subscribe subscription object if subscription set already subscribed. + if (this.subscribed && !subscriptionSet.subscribed) { + subscriptionSet.subscribe(); + subscriptionSet.subscribedAutomatically = true; // should be placed after .subscribe() call. + } } /** * Subtract other subscription set object. @@ -10326,6 +10371,8 @@ this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + if (subscriptionSet.subscribedAutomatically) + subscriptionSet.unsubscribe(); } /** * Get list of entities' subscription objects registered in subscription set. @@ -10381,6 +10428,19 @@ * @internal */ this.groupNames = []; + /** + * Whether subscribed ({@link SubscribeCapable#subscribe}) automatically during subscription + * object / sets manipulation or not. + * + * @internal + */ + this.subscribedAutomatically = false; + /** + * Whether subscribable object subscribed ({@link SubscribeCapable#subscribe}) or not. + * + * @internal + */ + this.subscribed = false; this.channelNames = channels; this.groupNames = channelGroups; this.options = subscriptionOptions; @@ -10396,13 +10456,25 @@ * @return Subscription set which contains both receiver and other entities' subscription objects. */ addSubscription(subscription) { - return new SubscriptionSet({ + const subscriptionSet = new SubscriptionSet({ channels: [...this.channelNames, ...subscription.channels], channelGroups: [...this.groupNames, ...subscription.channelGroups], subscriptionOptions: Object.assign(Object.assign({}, this.options), subscription === null || subscription === void 0 ? void 0 : subscription.options), eventEmitter: this.eventEmitter, pubnub: this.pubnub, }); + // Subscribe whole subscription set if it has been created with receiving subscription object + // which is already subscribed. + if (this.subscribed) { + if (!subscription.subscribed) { + subscription.subscribe(); + subscription.subscribedAutomatically = true; // should be placed after .subscribe() call. + } + this.pubnub.registerSubscribeCapable(subscriptionSet); + // @ts-expect-error: Required modification of protected field. + subscriptionSet.subscribed = true; + } + return subscriptionSet; } } diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 5f2676dcd..8b3a56d4e 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var m=function e(){var r,d,m=l(),b=m>>5,v=31&m;if(7===b)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(b<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,m,b,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),m=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=m.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],m=e[i+9],b=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,O,P,N,o,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,m,12,u[9]),N=t(N,C,O,P,b,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=n(O,P=t(P,N,C,O,E,22,u[15]),N,C,o,5,u[16]),C=n(C,O,P,N,g,9,u[17]),N=n(N,C,O,P,v,14,u[18]),P=n(P,N,C,O,c,20,u[19]),O=n(O,P,N,C,p,5,u[20]),C=n(C,O,P,N,b,9,u[21]),N=n(N,C,O,P,E,14,u[22]),P=n(P,N,C,O,d,20,u[23]),O=n(O,P,N,C,m,5,u[24]),C=n(C,O,P,N,k,9,u[25]),N=n(N,C,O,P,h,14,u[26]),P=n(P,N,C,O,f,20,u[27]),O=n(O,P,N,C,S,5,u[28]),C=n(C,O,P,N,l,9,u[29]),N=n(N,C,O,P,y,14,u[30]),O=s(O,P=n(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=s(C,O,P,N,f,11,u[33]),N=s(N,C,O,P,v,16,u[34]),P=s(P,N,C,O,k,23,u[35]),O=s(O,P,N,C,o,4,u[36]),C=s(C,O,P,N,d,11,u[37]),N=s(N,C,O,P,y,16,u[38]),P=s(P,N,C,O,b,23,u[39]),O=s(O,P,N,C,S,4,u[40]),C=s(C,O,P,N,c,11,u[41]),N=s(N,C,O,P,h,16,u[42]),P=s(P,N,C,O,g,23,u[43]),O=s(O,P,N,C,m,4,u[44]),C=s(C,O,P,N,w,11,u[45]),N=s(N,C,O,P,E,16,u[46]),O=r(O,P=s(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,b,15,u[54]),P=r(P,N,C,O,o,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,m,21,u[63]);a[0]=a[0]+O|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var m=(m=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&m^99;s[y]=m,r[m]=y;var b=p[y],v=p[b],w=p[v],k=257*p[m]^16843008*m;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*b^16843008*y,u[m]=k<<24|k>>>8,l[m]=k<<16|k>>>16,h[m]=k<<8|k>>>24,d[m]=k,y?(y=b^p[p[p[w^b]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=E[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],m=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=m}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],m=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=m,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new E({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===_.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=_.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=_.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===_.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=_.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class _{static from(e,t){if(e!==_.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==_.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>_.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+_.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}_.SENTINEL="PNED",_.LEGACY_IDENTIFIER="",_.IDENTIFIER_LENGTH=4,_.VERSION=1,_.MAX_VERSION=1,_.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return _.VERSION}get length(){return _.SENTINEL.length+1+_.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(_.SENTINEL)),e+=_.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=_.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class A extends Error{static create(e,t){return e instanceof Error?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new A(n,t,0);if(e instanceof A)return e;if(e instanceof Error&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new A(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new A(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,A.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.scheduleEventPost(n)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new A(s,e,0,new Error(s)))}}}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,m;const b=Object.assign({},e);if(null!==(t=b.logVerbosity)&&void 0!==t||(b.logVerbosity=!1),null!==(n=b.ssl)&&void 0!==n||(b.ssl=!0),null!==(s=b.transactionalRequestTimeout)&&void 0!==s||(b.transactionalRequestTimeout=15),null!==(r=b.subscribeRequestTimeout)&&void 0!==r||(b.subscribeRequestTimeout=310),null!==(i=b.fileRequestTimeout)&&void 0!==i||(b.fileRequestTimeout=300),null!==(a=b.restore)&&void 0!==a||(b.restore=!1),null!==(o=b.useInstanceId)&&void 0!==o||(b.useInstanceId=!1),null!==(c=b.suppressLeaveEvents)&&void 0!==c||(b.suppressLeaveEvents=!1),null!==(u=b.requestMessageCountThreshold)&&void 0!==u||(b.requestMessageCountThreshold=100),null!==(l=b.autoNetworkDetection)&&void 0!==l||(b.autoNetworkDetection=!1),null!==(h=b.enableEventEngine)&&void 0!==h||(b.enableEventEngine=!1),null!==(p=b.maintainPresenceState)&&void 0!==p||(b.maintainPresenceState=!0),null!==(g=b.useSmartHeartbeat)&&void 0!==g||(b.useSmartHeartbeat=!0),null!==(y=b.keepAlive)&&void 0!==y||(b.keepAlive=!1),b.userId&&b.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=b.userId)&&void 0!==f||(b.userId=b.uuid),!b.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(m=b.userId)||void 0===m?void 0:m.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");b.origin||(b.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:b.subscribeKey,publishKey:b.publishKey,secretKey:b.secretKey};void 0!==b.presenceTimeout&&b.presenceTimeout<20&&(b.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==b.presenceTimeout?b.heartbeatInterval=b.presenceTimeout/2-1:b.presenceTimeout=300;let w=!1,S=!0,k=5,E=!1,O=100,C=!0;return void 0!==b.dedupeOnSubscribe&&"boolean"==typeof b.dedupeOnSubscribe&&(E=b.dedupeOnSubscribe),void 0!==b.maximumCacheSize&&"number"==typeof b.maximumCacheSize&&(O=b.maximumCacheSize),void 0!==b.useRequestId&&"boolean"==typeof b.useRequestId&&(C=b.useRequestId),void 0!==b.announceSuccessfulHeartbeats&&"boolean"==typeof b.announceSuccessfulHeartbeats&&(w=b.announceSuccessfulHeartbeats),void 0!==b.announceFailedHeartbeats&&"boolean"==typeof b.announceFailedHeartbeats&&(S=b.announceFailedHeartbeats),void 0!==b.fileUploadPublishRetryLimit&&"number"==typeof b.fileUploadPublishRetryLimit&&(k=b.fileUploadPublishRetryLimit),Object.assign(Object.assign({},b),{keySet:v,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"8.10.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class G{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var K;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(K||(K={}));const $=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),L=(e,t)=>{const n=e.map((e=>$(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?K.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===K.POST||t===K.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${$(e)}`)).join("&"):`${t}=${$(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw A.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw A.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(){this.stopSubscribeLoop();const e=[...Object.keys(this.channelGroups)],t=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((t=>e.push(`${t}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>t.push(`${e}-pnpres`))),0===t.length&&0===e.length||this.subscribeCall({channels:t,channelGroups:e,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)}))}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:K.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===K.POST||r.method===K.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw A.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n){t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const n=this.channelListenerMap.get(t);n.includes(e)||n.push(e)}else this.channelListenerMap.set(t,[e])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){const n=this.groupListenerMap.get(t);n.includes(e)||n.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,n){t&&n?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==n||n.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class me extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class be extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new me}abort(){this._aborted=!0,this.notify(new me)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new be}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Ee=ge("DISCONNECT",(()=>({}))),Oe=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),_e=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),Ae=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(Ae.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(_e());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Oe.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARBEAT_RECONNECTING");Ge.onEnter((e=>Re(e))),Ge.onExit((()=>Re.cancel)),Ge.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Ee.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ge.on(_e.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEATING");Ke.onEnter((e=>Ae(e.channels,e.groups))),Ke.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ke.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ke.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(Oe.type,((e,t)=>Ke.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Oe(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const mt=new he("RECEIVE_RECONNECTING");mt.onEnter((e=>Je(e))),mt.onExit((()=>Je.cancel)),mt.on(at.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(ot.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),mt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(Ye.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(Qe.type,((e,t)=>bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const bt=new he("RECEIVING");bt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),bt.onExit((()=>Ve.cancel)),bt.on(rt.type,((e,t)=>bt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),bt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):bt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(it.type,((e,t)=>mt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return bt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return bt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Et extends se{constructor(e){var t,n;super({method:e.sendByPost?K.POST:K.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${$(t)}/0${this.parameters.sendByPost?"":`/${$(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ot extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${$(n)}/0/${$(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${$(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${$(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${L(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${L(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${L(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Gt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${s}/action/${n}`}}class Kt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${$(t)}/0/${$(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class $t extends se{constructor(e){super({method:K.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${$(e)}/files/${t}/${n}`}}class Lt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:K.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this);const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,n)}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,n)}get subscriptions(){return this.subscriptionList.slice(0)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){return new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class mn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(m=e.include).channelStatusField)&&void 0!==c||(m.channelStatusField=false),null!==(u=(b=e.include).channelTypeField)&&void 0!==u||(b.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class bn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,m,b;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(m=e.include).UUIDStatusField)&&void 0!==c||(m.UUIDStatusField=false),null!==(u=(b=e.include).UUIDTypeField)&&void 0!==u||(b.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class On extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new bn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new On(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new mn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files/${n}/${s}`}}class _n{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=_n.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof A?e:A.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new At({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new _t(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new _t(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof A&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}_n.decoder=new TextDecoder,_n.OPERATIONS=ie,_n.CATEGORIES=h,_n.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,_n.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class An extends _n{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})}));let a,u,l;a=new G(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return An.CryptoModule=M,An})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,O,P,N,o,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,b,12,u[9]),N=t(N,C,O,P,m,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=n(O,P=t(P,N,C,O,E,22,u[15]),N,C,o,5,u[16]),C=n(C,O,P,N,g,9,u[17]),N=n(N,C,O,P,v,14,u[18]),P=n(P,N,C,O,c,20,u[19]),O=n(O,P,N,C,p,5,u[20]),C=n(C,O,P,N,m,9,u[21]),N=n(N,C,O,P,E,14,u[22]),P=n(P,N,C,O,d,20,u[23]),O=n(O,P,N,C,b,5,u[24]),C=n(C,O,P,N,k,9,u[25]),N=n(N,C,O,P,h,14,u[26]),P=n(P,N,C,O,f,20,u[27]),O=n(O,P,N,C,S,5,u[28]),C=n(C,O,P,N,l,9,u[29]),N=n(N,C,O,P,y,14,u[30]),O=s(O,P=n(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=s(C,O,P,N,f,11,u[33]),N=s(N,C,O,P,v,16,u[34]),P=s(P,N,C,O,k,23,u[35]),O=s(O,P,N,C,o,4,u[36]),C=s(C,O,P,N,d,11,u[37]),N=s(N,C,O,P,y,16,u[38]),P=s(P,N,C,O,m,23,u[39]),O=s(O,P,N,C,S,4,u[40]),C=s(C,O,P,N,c,11,u[41]),N=s(N,C,O,P,h,16,u[42]),P=s(P,N,C,O,g,23,u[43]),O=s(O,P,N,C,b,4,u[44]),C=s(C,O,P,N,w,11,u[45]),N=s(N,C,O,P,E,16,u[46]),O=r(O,P=s(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,m,15,u[54]),P=r(P,N,C,O,o,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,b,21,u[63]);a[0]=a[0]+O|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=E[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new E({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class j extends Error{static create(e,t){return e instanceof Error?j.createFromError(e):j.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new j(n,t,0);if(e instanceof j)return e;if(e instanceof Error&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new j(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new j(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,j.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.scheduleEventPost(n)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(j.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new j(s,e,0,new Error(s)))}}}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,E=!1,O=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(E=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(O=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.0.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class G{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var K;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(K||(K={}));const $=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),L=(e,t)=>{const n=e.map((e=>$(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?K.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===K.POST||t===K.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${$(e)}`)).join("&"):`${t}=${$(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw j.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw j.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:K.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===K.POST||r.method===K.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw j.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n){t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const n=this.channelListenerMap.get(t);n.includes(e)||n.push(e)}else this.channelListenerMap.set(t,[e])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){const n=this.groupListenerMap.get(t);n.includes(e)||n.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,n){t&&n?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==n||n.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Ee=ge("DISCONNECT",(()=>({}))),Oe=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),_e=ge("TIMES_UP",(()=>({}))),je=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(_e())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Oe.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(_e.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARBEAT_RECONNECTING");Ge.onEnter((e=>Re(e))),Ge.onExit((()=>Re.cancel)),Ge.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Ee.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ge.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEATING");Ke.onEnter((e=>je(e.channels,e.groups))),Ke.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ke.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ke.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(Oe.type,((e,t)=>Ke.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Oe(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Et extends se{constructor(e){var t,n;super({method:e.sendByPost?K.POST:K.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${$(t)}/0${this.parameters.sendByPost?"":`/${$(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ot extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${$(n)}/0/${$(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${$(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class jt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${$(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${L(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${L(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${L(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Gt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${s}/action/${n}`}}class Kt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${$(t)}/0/${$(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class $t extends se{constructor(e){super({method:K.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${$(e)}/files/${t}/${n}`}}class Lt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:K.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof j?e:j.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,n),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,n),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class On extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new On(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof j?e:j.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new _t({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new jt({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof j&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class _n{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class jn extends An{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})}));let a,u,l;a=new G(new _n((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return jn.CryptoModule=M,jn})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index 88728b81c..94ea97d5f 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -239,15 +239,21 @@ updateClientSubscribeStateIfRequired(data); const client = pubNubClients[data.clientIdentifier]; if (client) { - const timerIdentifier = `${client.userId}-${client.subscriptionKey}`; - // Check whether we need to start new aggregation timer or not. - if (!aggregationTimers.has(timerIdentifier)) { - const aggregationTimer = setTimeout(() => { - handleSendSubscribeRequestEvent(data); - aggregationTimers.delete(timerIdentifier); - }, subscribeAggregationTimeout); - aggregationTimers.set(timerIdentifier, aggregationTimer); + // Check whether there are more clients which may schedule next subscription loop and they need to be + // aggregated or not. + if (hasClientsForSendAggregatedSubscribeRequestEvent(client, data)) { + const timerIdentifier = aggregateTimerId(client); + // Check whether we need to start new aggregation timer or not. + if (!aggregationTimers.has(timerIdentifier)) { + const aggregationTimer = setTimeout(() => { + handleSendSubscribeRequestEvent(data); + aggregationTimers.delete(timerIdentifier); + }, subscribeAggregationTimeout); + aggregationTimers.set(timerIdentifier, aggregationTimer); + } } + else + handleSendSubscribeRequestEvent(data); } } else if (data.request.path.endsWith('/heartbeat')) { @@ -1477,6 +1483,18 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' } return undefined; }; + /** + * Check whether there are any clients which can be used for subscribe request aggregation or not. + * + * @param client - PubNub client state which will be checked. + * @param event - Send subscribe request event information. + * + * @returns `true` in case there is more than 1 client which has same parameters for subscribe request to aggregate. + */ + const hasClientsForSendAggregatedSubscribeRequestEvent = (client, event) => { + var _a, _b; + return clientsForSendSubscribeRequestEvent((_b = ((_a = client.subscription) !== null && _a !== void 0 ? _a : {}).timetoken) !== null && _b !== void 0 ? _b : '0', event).length > 1; + }; /** * Find PubNub client states with configuration compatible with the one in request. * @@ -1607,6 +1625,21 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' pingTimeouts[subscriptionKey] = setTimeout(() => pingClients(subscriptionKey), interval * 500 - 1); } }; + /** + * Compose clients' aggregation key. + * + * Aggregation key includes key parameters which differentiate clients between each other. + * + * @param client - Client for which identifier should be composed. + * + * @returns Aggregation timeout identifier string. + */ + const aggregateTimerId = (client) => { + let id = `${client.userId}-${client.subscriptionKey}${client.authKey ? `-${client.authKey}` : ''}`; + if (client.subscription && client.subscription.filterExpression) + id += `-${client.subscription.filterExpression}`; + return id; + }; /** * Print message on the worker's clients console. * diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index 302641a9b..81c794219 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((r=r.apply(e,t||[])).next())}))}var t;"function"==typeof SuppressedError&&SuppressedError,function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(t||(t={}));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r,i,s={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},v={},y={};self.onconnect=e=>{ee("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)n.port=e,D(n),ee(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-pong"===n.type)N(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){F(n);const e=h[n.clientIdentifier];if(e){const t=`${e.userId}-${e.subscriptionKey}`;if(!l.has(t)){const e=setTimeout((()=>{q(n),l.delete(t)}),50);l.set(t,e)}}}else n.request.path.endsWith("/heartbeat")?(U(n),m(n)):w(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=e=>{var t;const n=P(e),r=h[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),R("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=y[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,R("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),A(r,u)}return}e.request.cancellable&&f.set(n.identifier,new AbortController);const s=y[n.identifier],{timetokenOverride:o,regionOverride:c}=s;j(n,(()=>T(n.identifier)),((t,r)=>{x(t,r,e.request),E(t,n.identifier)}),((t,r)=>{x(t,null,e.request,W(r)),E(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(t=I(t,o,c)),t})),ee(`'${Object.keys(y).length}' subscription request currently active.`)},I=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ee(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ee(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},m=e=>{var t;const n=h[e.clientIdentifier],r=C(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(R("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ee(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,R("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}j(r,(()=>[n]),((t,n)=>{o&&(o.response=n),x(t,n,e.request)}),((t,n)=>{x(t,null,e.request,W(n))})),ee("Started heartbeat request.",n)},w=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=G(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(j(n,(()=>[t]),((t,n)=>{x(t,n,e.request)}),((t,n)=>{x(t,null,e.request,W(n))})),ee("Started leave request.",t),void 0===i)return;const s=T(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),$(s)},O=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},$=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&q({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},j=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(K(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),S(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(R("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},k=e=>{if(0===T(e).length){const t=f.get(e);f.delete(e),delete y[e],t&&t.abort("Cancel request")}},S=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),T=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete y[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},K=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ne(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},P=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=_(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=H(u,e);if(s){const e=y[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Y(e.channels,n))&&(!(r.length>0)||Y(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),v=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(v.add,v);const n=t.serviceRequestId;t.serviceRequestId=a,n&&y[n]&&k(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=y[a])&&void 0!==r?r:y[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(v.size){q.channels=Array.from(v).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h))}else y[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};y[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(y[a].region=d.queryParameters.tr),y[a].timetokenOverride=f,y[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)te(y[a],`Started aggregated request for clients: ${b}`,e);return d},C=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=Q(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,v=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=Y(e,o.heartbeat.channels)&&Y(t,o.heartbeat.channelGroups),n&&(v=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;if(g){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!v&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},G=e=>{const t=h[e.clientIdentifier],n=B(e);let r=X(e.request),i=z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");ee(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=v[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},R=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=v[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},x=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=v[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?W(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)ee(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)ee(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&ee(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},W=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},D=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=v[s=e.subscriptionKey])&&void 0!==n?n:v[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)ee(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)ee(`Setup PubNub client ping event ${n} seconds`,e);a[e.subscriptionKey]=setTimeout((()=>Z(t)),500*n-1)}},F=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,v,y,q,I,m,w;const O=e.request.queryParameters,{clientIdentifier:$}=e,j=h[$];if(!j)return;const k=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let T=j.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=g[v=j.subscriptionKey])&&void 0!==s?s:g[v]={})[q=j.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=j.subscriptionKey])&&void 0!==c?c:g[I]={})[w=j.userId])&&void 0!==l?l:m[w]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=j.subscriptionKey])&&void 0!==r?r:g[f]={})[b=j.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}j.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=z(e.request)),T.channelGroupQuery!==k&&(T.channelGroupQuery=k,T.channelGroups=X(e.request));const{authKey:E,userId:K}=j;T.request=e.request,T.filterExpression=null!==(u=O["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(T.region=O.tr),j.authKey=null!==(d=O.auth)&&void 0!==d?d:"",j.origin=e.request.origin,j.userId=O.uuid,j.pnsdk=O.pnsdk,V(j,K,E)},U=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=X(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},V=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},N=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},M=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r}=e.subscription,i=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>re(e))).sort(),s=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>re(e))).sort();if(0===s.length&&0===i.length)return;const o=i.length>0?i.join(","):void 0,l=0===s.length?",":s.join(","),u=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),o?{"channel-group":o}:{}),a={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${l}/leave`,queryParameters:u,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:u.requestid}};w(a,e)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},H=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ee(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=y[e.serviceRequestId];if(s||(s=X(t.request)),o||(o=z(t.request)),o.length&&!Y(r.channels,o))continue;if(s.length&&!Y(r.channelGroups,s))continue;return te(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},_=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",l=s.uuid;return(null!==(i=p[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},Q=e=>B(e),B=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=p[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},X=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Y=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},Z=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)ee(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);((e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r&&r.unsubscribeOfflineClients&&M(r),i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=v[e];n&&(delete n[t],0===Object.keys(n).length&&delete v[e])}else delete v[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)ee(s,e);else ee(s)})(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>Z(e)),500*t-1)}},ee=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},te=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},ne=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${re(e)}`)).join("&"):`${t}=${re(n)}`})).join("&"),re=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},v={},y={};self.onconnect=e=>{ne("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)n.port=e,D(n),ne(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-pong"===n.type)N(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){F(n);const e=h[n.clientIdentifier];if(e)if(_(e,n)){const t=te(e);if(!l.has(t)){const e=setTimeout((()=>{q(n),l.delete(t)}),50);l.set(t,e)}}else q(n)}else n.request.path.endsWith("/heartbeat")?(U(n),m(n)):w(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=e=>{var t;const n=P(e),r=h[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),x("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=y[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,x("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),A(r,u)}return}e.request.cancellable&&f.set(n.identifier,new AbortController);const s=y[n.identifier],{timetokenOverride:o,regionOverride:c}=s;j(n,(()=>E(n.identifier)),((t,r)=>{R(t,r,e.request),T(t,n.identifier)}),((t,r)=>{R(t,null,e.request,W(r)),T(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(t=I(t,o,c)),t})),ne(`'${Object.keys(y).length}' subscription request currently active.`)},I=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ne(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ne(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},m=e=>{var t;const n=h[e.clientIdentifier],r=C(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(x("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ne(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,x("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}j(r,(()=>[n]),((t,n)=>{o&&(o.response=n),R(t,n,e.request)}),((t,n)=>{R(t,null,e.request,W(n))})),ne("Started heartbeat request.",n)},w=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=G(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(j(n,(()=>[t]),((t,n)=>{R(t,n,e.request)}),((t,n)=>{R(t,null,e.request,W(n))})),ne("Started leave request.",t),void 0===i)return;const s=E(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),$(s)},O=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},$=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&q({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},j=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(K(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),S(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},k=e=>{if(0===E(e).length){const t=f.get(e);f.delete(e),delete y[e],t&&t.abort("Cancel request")}},S=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),E=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),T=(e,t)=>{delete y[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},K=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ie(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},P=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=Q(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=H(u,e);if(s){const e=y[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Z(e.channels,n))&&(!(r.length>0)||Z(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),v=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(v.add,v);const n=t.serviceRequestId;t.serviceRequestId=a,n&&y[n]&&k(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=y[a])&&void 0!==r?r:y[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(v.size){q.channels=Array.from(v).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h))}else y[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};y[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(y[a].region=d.queryParameters.tr),y[a].timetokenOverride=f,y[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)re(y[a],`Started aggregated request for clients: ${b}`,e);return d},C=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=B(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,v=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=Z(e,o.heartbeat.channels)&&Z(t,o.heartbeat.channelGroups),n&&(v=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;if(g){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!v&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},G=e=>{const t=h[e.clientIdentifier],n=z(e);let r=Y(e.request),i=X(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");ne(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=v[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},x=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=v[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},R=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=v[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?W(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)ne(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)ne(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&ne(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},W=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},D=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=v[s=e.subscriptionKey])&&void 0!==n?n:v[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)ne(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)ne(`Setup PubNub client ping event ${n} seconds`,e);a[e.subscriptionKey]=setTimeout((()=>ee(t)),500*n-1)}},F=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,v,y,q,I,m,w;const O=e.request.queryParameters,{clientIdentifier:$}=e,j=h[$];if(!j)return;const k=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let E=j.subscription;if(E){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=g[v=j.subscriptionKey])&&void 0!==s?s:g[v]={})[q=j.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of E.objectsWithState)e[n]||delete t[n];E.objectsWithState=Object.keys(e)}else if(E.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=j.subscriptionKey])&&void 0!==c?c:g[I]={})[w=j.userId])&&void 0!==l?l:m[w]={};for(const t of E.objectsWithState)delete e[t];E.objectsWithState=[]}}else{if(E={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=j.subscriptionKey])&&void 0!==r?r:g[f]={})[b=j.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),E.objectsWithState=Object.keys(e)}j.subscription=E}E.path!==e.request.path&&(E.path=e.request.path,E.channels=X(e.request)),E.channelGroupQuery!==k&&(E.channelGroupQuery=k,E.channelGroups=Y(e.request));const{authKey:T,userId:K}=j;E.request=e.request,E.filterExpression=null!==(u=O["filter-expr"])&&void 0!==u?u:"",E.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(E.region=O.tr),j.authKey=null!==(d=O.auth)&&void 0!==d?d:"",j.origin=e.request.origin,j.userId=O.uuid,j.pnsdk=O.pnsdk,V(j,K,T)},U=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=Y(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=X(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},V=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},N=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},M=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r}=e.subscription,i=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>se(e))).sort(),s=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>se(e))).sort();if(0===s.length&&0===i.length)return;const o=i.length>0?i.join(","):void 0,l=0===s.length?",":s.join(","),u=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),o?{"channel-group":o}:{}),a={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${l}/leave`,queryParameters:u,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:u.requestid}};w(a,e)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},H=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ne(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=y[e.serviceRequestId];if(s||(s=Y(t.request)),o||(o=X(t.request)),o.length&&!Z(r.channels,o))continue;if(s.length&&!Z(r.channelGroups,s))continue;return re(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},_=(e,t)=>{var n,r;return Q(null!==(r=(null!==(n=e.subscription)&&void 0!==n?n:{}).timetoken)&&void 0!==r?r:"0",t).length>1},Q=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",l=s.uuid;return(null!==(i=p[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>z(e),z=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=p[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},X=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},Y=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Z=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ee=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)ne(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);((e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r&&r.unsubscribeOfflineClients&&M(r),i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=v[e];n&&(delete n[t],0===Object.keys(n).length&&delete v[e])}else delete v[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)ne(s,e);else ne(s)})(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ee(e)),500*t-1)}},te=e=>{let t=`${e.userId}-${e.subscriptionKey}${e.authKey?`-${e.authKey}`:""}`;return e.subscription&&e.subscription.filterExpression&&(t+=`-${e.subscription.filterExpression}`),t},ne=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},re=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},ie=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${se(e)}`)).join("&"):`${t}=${se(n)}`})).join("&"),se=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 225cbdaed..30f62f99b 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '8.10.0'; + return '9.0.0'; }, getVersion() { return this.version; diff --git a/lib/core/components/subscription-manager.js b/lib/core/components/subscription-manager.js index 35dd1a633..f73a13408 100644 --- a/lib/core/components/subscription-manager.js +++ b/lib/core/components/subscription-manager.js @@ -81,8 +81,9 @@ class SubscriptionManager { * unsubscribe or not. */ reconnect(forUnsubscribe = false) { - this.startSubscribeLoop(); - if (!forUnsubscribe && this.configuration.useSmartHeartbeat) + this.startSubscribeLoop(forUnsubscribe); + // Starting heartbeat loop for provided channels and groups. + if (!forUnsubscribe && !this.configuration.useSmartHeartbeat) this.startHeartbeatTimer(); } /** @@ -190,7 +191,15 @@ class SubscriptionManager { channelGroups: this.subscribedChannelGroups, }, isOffline); } - startSubscribeLoop() { + /** + * Start next subscription loop. + * + * @param restartOnUnsubscribe - Whether restarting subscription loop as part of channels list change on + * unsubscribe or not. + * + * @internal + */ + startSubscribeLoop(restartOnUnsubscribe = false) { this.stopSubscribeLoop(); const channelGroups = [...Object.keys(this.channelGroups)]; const channels = [...Object.keys(this.channels)]; @@ -210,6 +219,8 @@ class SubscriptionManager { }, (status, result) => { this.processSubscribeResponse(status, result); }); + if (!restartOnUnsubscribe && this.configuration.useSmartHeartbeat) + this.startHeartbeatTimer(); } stopSubscribeLoop() { if (this._subscribeAbort) { @@ -361,7 +372,9 @@ class SubscriptionManager { const heartbeatInterval = this.configuration.getHeartbeatInterval(); if (!heartbeatInterval || heartbeatInterval === 0) return; - this.sendHeartbeat(); + // Sending immediate heartbeat only if not working as smart heartbeat. + if (!this.configuration.useSmartHeartbeat) + this.sendHeartbeat(); this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), heartbeatInterval * 1000); } /** diff --git a/lib/core/interfaces/configuration.js b/lib/core/interfaces/configuration.js index ddca709b2..4bea7594f 100644 --- a/lib/core/interfaces/configuration.js +++ b/lib/core/interfaces/configuration.js @@ -45,7 +45,7 @@ const MAINTAIN_PRESENCE_STATE = true; /** * Whether heartbeat should be postponed on successful subscribe response or not. */ -const USE_SMART_HEARTBEAT = true; +const USE_SMART_HEARTBEAT = false; /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. */ diff --git a/lib/entities/SubscribeCapable.js b/lib/entities/SubscribeCapable.js index bd33f979e..db295f50e 100644 --- a/lib/entities/SubscribeCapable.js +++ b/lib/entities/SubscribeCapable.js @@ -11,6 +11,8 @@ class SubscribeCapable { subscribe(subscribeParameters) { const timetoken = subscribeParameters === null || subscribeParameters === void 0 ? void 0 : subscribeParameters.timetoken; this.pubnub.registerSubscribeCapable(this); + this.subscribedAutomatically = false; + this.subscribed = true; this.pubnub.subscribe(Object.assign({ channels: this.channelNames, channelGroups: this.groupNames }, (timetoken !== null && timetoken !== '' && { timetoken: timetoken }))); } /** @@ -18,6 +20,8 @@ class SubscribeCapable { */ unsubscribe() { this.pubnub.unregisterSubscribeCapable(this); + this.subscribedAutomatically = false; + this.subscribed = false; const { channels, channelGroups } = this.pubnub.getSubscribeCapableEntities(); // Identify channels and groups from which PubNub client can safely unsubscribe. const filteredChannelGroups = this.groupNames.filter((cg) => !channelGroups.includes(cg)); diff --git a/lib/entities/Subscription.js b/lib/entities/Subscription.js index 158e0163a..351271c8d 100644 --- a/lib/entities/Subscription.js +++ b/lib/entities/Subscription.js @@ -47,6 +47,19 @@ class Subscription extends SubscribeCapable_1.SubscribeCapable { * @internal */ this.groupNames = []; + /** + * Whether subscribed ({@link SubscribeCapable#subscribe}) automatically during subscription + * object / sets manipulation or not. + * + * @internal + */ + this.subscribedAutomatically = false; + /** + * Whether subscribable object subscribed ({@link SubscribeCapable#subscribe}) or not. + * + * @internal + */ + this.subscribed = false; this.channelNames = channels; this.groupNames = channelGroups; this.options = subscriptionOptions; @@ -62,13 +75,25 @@ class Subscription extends SubscribeCapable_1.SubscribeCapable { * @return Subscription set which contains both receiver and other entities' subscription objects. */ addSubscription(subscription) { - return new SubscriptionSet_1.SubscriptionSet({ + const subscriptionSet = new SubscriptionSet_1.SubscriptionSet({ channels: [...this.channelNames, ...subscription.channels], channelGroups: [...this.groupNames, ...subscription.channelGroups], subscriptionOptions: Object.assign(Object.assign({}, this.options), subscription === null || subscription === void 0 ? void 0 : subscription.options), eventEmitter: this.eventEmitter, pubnub: this.pubnub, }); + // Subscribe whole subscription set if it has been created with receiving subscription object + // which is already subscribed. + if (this.subscribed) { + if (!subscription.subscribed) { + subscription.subscribe(); + subscription.subscribedAutomatically = true; // should be placed after .subscribe() call. + } + this.pubnub.registerSubscribeCapable(subscriptionSet); + // @ts-expect-error: Required modification of protected field. + subscriptionSet.subscribed = true; + } + return subscriptionSet; } } exports.Subscription = Subscription; diff --git a/lib/entities/SubscriptionSet.js b/lib/entities/SubscriptionSet.js index d2a04a69f..5df4547a5 100644 --- a/lib/entities/SubscriptionSet.js +++ b/lib/entities/SubscriptionSet.js @@ -60,6 +60,19 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { * @internal */ this.subscriptionList = []; + /** + * Whether subscribed ({@link SubscribeCapable#subscribe}) automatically during subscription + * object / sets manipulation or not. + * + * @internal + */ + this.subscribedAutomatically = false; + /** + * Whether subscribable object subscribed ({@link SubscribeCapable#subscribe}) or not. + * + * @internal + */ + this.subscribed = false; this.options = subscriptionOptions; this.eventEmitter = eventEmitter; this.pubnub = pubnub; @@ -89,6 +102,13 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.channelNames = [...this.channelNames, ...subscription.channels]; this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); + // Subscribe subscription object if subscription set already subscribed. + // @ts-expect-error: Required access of protected field. + if (this.subscribed && !subscription.subscribed) { + subscription.subscribe(); + // @ts-expect-error: Required modification of protected field. + subscription.subscribedAutomatically = true; // should be placed after .subscribe() call. + } } /** * Remove entity's subscription object from the set. @@ -105,6 +125,9 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + // @ts-expect-error: Required access of protected field. + if (subscription.subscribedAutomatically) + subscription.unsubscribe(); } /** * Merge with other subscription set object. @@ -119,6 +142,11 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); + // Subscribe subscription object if subscription set already subscribed. + if (this.subscribed && !subscriptionSet.subscribed) { + subscriptionSet.subscribe(); + subscriptionSet.subscribedAutomatically = true; // should be placed after .subscribe() call. + } } /** * Subtract other subscription set object. @@ -135,6 +163,8 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + if (subscriptionSet.subscribedAutomatically) + subscriptionSet.unsubscribe(); } /** * Get list of entities' subscription objects registered in subscription set. diff --git a/package.json b/package.json index fe93bdd1d..c7668123a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "8.10.0", + "version": "9.0.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 13df6eed1..cd4832970 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '8.10.0'; + return '9.0.0'; }, getVersion(): string { return this.version; diff --git a/src/core/components/subscription-manager.ts b/src/core/components/subscription-manager.ts index c3de3cffc..6cc0252b5 100644 --- a/src/core/components/subscription-manager.ts +++ b/src/core/components/subscription-manager.ts @@ -196,8 +196,10 @@ export class SubscriptionManager { * unsubscribe or not. */ public reconnect(forUnsubscribe: boolean = false) { - this.startSubscribeLoop(); - if (!forUnsubscribe && this.configuration.useSmartHeartbeat) this.startHeartbeatTimer(); + this.startSubscribeLoop(forUnsubscribe); + + // Starting heartbeat loop for provided channels and groups. + if (!forUnsubscribe && !this.configuration.useSmartHeartbeat) this.startHeartbeatTimer(); } /** @@ -333,8 +335,17 @@ export class SubscriptionManager { ); } - private startSubscribeLoop() { + /** + * Start next subscription loop. + * + * @param restartOnUnsubscribe - Whether restarting subscription loop as part of channels list change on + * unsubscribe or not. + * + * @internal + */ + private startSubscribeLoop(restartOnUnsubscribe: boolean = false) { this.stopSubscribeLoop(); + const channelGroups = [...Object.keys(this.channelGroups)]; const channels = [...Object.keys(this.channels)]; @@ -358,6 +369,8 @@ export class SubscriptionManager { this.processSubscribeResponse(status, result); }, ); + + if (!restartOnUnsubscribe && this.configuration.useSmartHeartbeat) this.startHeartbeatTimer(); } private stopSubscribeLoop() { @@ -528,7 +541,8 @@ export class SubscriptionManager { const heartbeatInterval = this.configuration.getHeartbeatInterval(); if (!heartbeatInterval || heartbeatInterval === 0) return; - this.sendHeartbeat(); + // Sending immediate heartbeat only if not working as smart heartbeat. + if (!this.configuration.useSmartHeartbeat) this.sendHeartbeat(); this.heartbeatTimer = setInterval(() => this.sendHeartbeat(), heartbeatInterval * 1000) as unknown as number; } diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index 78f4091cd..36ce2e747 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -57,7 +57,7 @@ const MAINTAIN_PRESENCE_STATE = true; /** * Whether heartbeat should be postponed on successful subscribe response or not. */ -const USE_SMART_HEARTBEAT = true; +const USE_SMART_HEARTBEAT = false; /** * Whether PubNub client should try to utilize existing TCP connection for new requests or not. diff --git a/src/entities/SubscribeCapable.ts b/src/entities/SubscribeCapable.ts index 00d039ace..7447117aa 100644 --- a/src/entities/SubscribeCapable.ts +++ b/src/entities/SubscribeCapable.ts @@ -49,6 +49,21 @@ export abstract class SubscribeCapable { */ protected abstract pubnub: PubNub; + /** + * Whether subscribed ({@link SubscribeCapable#subscribe}) automatically during subscription + * object / sets manipulation or not. + * + * @internal + */ + protected abstract subscribedAutomatically: boolean; + + /** + * Whether subscribable object subscribed ({@link SubscribeCapable#subscribe}) or not. + * + * @internal + */ + protected abstract subscribed: boolean; + /** * Start receiving real-time updates. * @@ -58,6 +73,9 @@ export abstract class SubscribeCapable { subscribe(subscribeParameters?: { timetoken?: string }) { const timetoken = subscribeParameters?.timetoken; this.pubnub.registerSubscribeCapable(this); + this.subscribedAutomatically = false; + this.subscribed = true; + this.pubnub.subscribe({ channels: this.channelNames, channelGroups: this.groupNames, @@ -70,6 +88,9 @@ export abstract class SubscribeCapable { */ unsubscribe() { this.pubnub.unregisterSubscribeCapable(this); + this.subscribedAutomatically = false; + this.subscribed = false; + const { channels, channelGroups } = this.pubnub.getSubscribeCapableEntities(); // Identify channels and groups from which PubNub client can safely unsubscribe. diff --git a/src/entities/Subscription.ts b/src/entities/Subscription.ts index 384d9625f..f935532de 100644 --- a/src/entities/Subscription.ts +++ b/src/entities/Subscription.ts @@ -65,6 +65,21 @@ export class Subscription extends SubscribeCapable { */ protected listener: Listener; + /** + * Whether subscribed ({@link SubscribeCapable#subscribe}) automatically during subscription + * object / sets manipulation or not. + * + * @internal + */ + protected subscribedAutomatically: boolean = false; + + /** + * Whether subscribable object subscribed ({@link SubscribeCapable#subscribe}) or not. + * + * @internal + */ + protected subscribed: boolean = false; + /** * Create entity's subscription object. * @@ -109,12 +124,27 @@ export class Subscription extends SubscribeCapable { * @return Subscription set which contains both receiver and other entities' subscription objects. */ addSubscription(subscription: Subscription) { - return new SubscriptionSet({ + const subscriptionSet = new SubscriptionSet({ channels: [...this.channelNames, ...subscription.channels], channelGroups: [...this.groupNames, ...subscription.channelGroups], subscriptionOptions: { ...this.options, ...subscription?.options }, eventEmitter: this.eventEmitter, pubnub: this.pubnub, }); + + // Subscribe whole subscription set if it has been created with receiving subscription object + // which is already subscribed. + if (this.subscribed) { + if (!subscription.subscribed) { + subscription.subscribe(); + subscription.subscribedAutomatically = true; // should be placed after .subscribe() call. + } + + this.pubnub.registerSubscribeCapable(subscriptionSet); + // @ts-expect-error: Required modification of protected field. + subscriptionSet.subscribed = true; + } + + return subscriptionSet; } } diff --git a/src/entities/SubscriptionSet.ts b/src/entities/SubscriptionSet.ts index 438017547..a9cbdc603 100644 --- a/src/entities/SubscriptionSet.ts +++ b/src/entities/SubscriptionSet.ts @@ -77,6 +77,21 @@ export class SubscriptionSet extends SubscribeCapable { */ protected listener: Listener; + /** + * Whether subscribed ({@link SubscribeCapable#subscribe}) automatically during subscription + * object / sets manipulation or not. + * + * @internal + */ + protected subscribedAutomatically: boolean = false; + + /** + * Whether subscribable object subscribed ({@link SubscribeCapable#subscribe}) or not. + * + * @internal + */ + protected subscribed: boolean = false; + /** * Create entities' subscription set object. * @@ -139,6 +154,14 @@ export class SubscriptionSet extends SubscribeCapable { this.channelNames = [...this.channelNames, ...subscription.channels]; this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); + + // Subscribe subscription object if subscription set already subscribed. + // @ts-expect-error: Required access of protected field. + if (this.subscribed && !subscription.subscribed) { + subscription.subscribe(); + // @ts-expect-error: Required modification of protected field. + subscription.subscribedAutomatically = true; // should be placed after .subscribe() call. + } } /** @@ -156,6 +179,9 @@ export class SubscriptionSet extends SubscribeCapable { this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + + // @ts-expect-error: Required access of protected field. + if (subscription.subscribedAutomatically) subscription.unsubscribe(); } /** @@ -171,6 +197,12 @@ export class SubscriptionSet extends SubscribeCapable { this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); + + // Subscribe subscription object if subscription set already subscribed. + if (this.subscribed && !subscriptionSet.subscribed) { + subscriptionSet.subscribe(); + subscriptionSet.subscribedAutomatically = true; // should be placed after .subscribe() call. + } } /** @@ -188,6 +220,8 @@ export class SubscriptionSet extends SubscribeCapable { this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + + if (subscriptionSet.subscribedAutomatically) subscriptionSet.unsubscribe(); } /** diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index 54b24150b..bb379ee46 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -696,17 +696,21 @@ self.onconnect = (event) => { const client = pubNubClients[data.clientIdentifier]; if (client) { - const timerIdentifier = `${client.userId}-${client.subscriptionKey}`; - - // Check whether we need to start new aggregation timer or not. - if (!aggregationTimers.has(timerIdentifier)) { - const aggregationTimer = setTimeout(() => { - handleSendSubscribeRequestEvent(data); - aggregationTimers.delete(timerIdentifier); - }, subscribeAggregationTimeout); - - aggregationTimers.set(timerIdentifier, aggregationTimer); - } + // Check whether there are more clients which may schedule next subscription loop and they need to be + // aggregated or not. + if (hasClientsForSendAggregatedSubscribeRequestEvent(client, data)) { + const timerIdentifier = aggregateTimerId(client); + + // Check whether we need to start new aggregation timer or not. + if (!aggregationTimers.has(timerIdentifier)) { + const aggregationTimer = setTimeout(() => { + handleSendSubscribeRequestEvent(data); + aggregationTimers.delete(timerIdentifier); + }, subscribeAggregationTimeout); + + aggregationTimers.set(timerIdentifier, aggregationTimer); + } + } else handleSendSubscribeRequestEvent(data); } } else if (data.request.path.endsWith('/heartbeat')) { updateClientHeartbeatState(data); @@ -2162,6 +2166,18 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' return undefined; }; +/** + * Check whether there are any clients which can be used for subscribe request aggregation or not. + * + * @param client - PubNub client state which will be checked. + * @param event - Send subscribe request event information. + * + * @returns `true` in case there is more than 1 client which has same parameters for subscribe request to aggregate. + */ +const hasClientsForSendAggregatedSubscribeRequestEvent = (client: PubNubClientState, event: SendRequestEvent) => { + return clientsForSendSubscribeRequestEvent((client.subscription ?? {}).timetoken ?? '0', event).length > 1; +}; + /** * Find PubNub client states with configuration compatible with the one in request. * @@ -2314,6 +2330,21 @@ const pingClients = (subscriptionKey: string) => { } }; +/** + * Compose clients' aggregation key. + * + * Aggregation key includes key parameters which differentiate clients between each other. + * + * @param client - Client for which identifier should be composed. + * + * @returns Aggregation timeout identifier string. + */ +const aggregateTimerId = (client: PubNubClientState) => { + let id = `${client.userId}-${client.subscriptionKey}${client.authKey ? `-${client.authKey}` : ''}`; + if (client.subscription && client.subscription.filterExpression) id += `-${client.subscription.filterExpression}`; + return id; +}; + /** * Print message on the worker's clients console. * From e80c97083128f08a57d60e48494546025aa4b602 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 13 Mar 2025 17:01:06 +0200 Subject: [PATCH 41/49] Fix `fetch` errors handling (#444) fix(fetch): fix fetch error handling Fix issue because of errors returned by `fetch` taken from `iframe` (to protect against monkey-patching by APM packages) was't handled as Error. feat(listener): `SubscriptionSet` listener will receive updates from new Subscription `SubscriptionSet` will re-add listener every time when `Subscription` or `SubscriptionSet` added to it - this will let receive updates from newly added subscribe capable objects. refactor(shared-worker): change request aggregate by authKey Use access token (auth key) content instead of base64 encoded token to identify PubNub clients, which can be used for requests aggregation. --- .pubnub.yml | 15 +- CHANGELOG.md | 12 + README.md | 4 +- dist/web/pubnub.js | 227 ++++++++++++++---- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 61 ++++- dist/web/pubnub.worker.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/components/eventEmitter.js | 52 ++-- lib/core/components/listener_manager.js | 6 +- lib/entities/SubscribeCapable.js | 23 +- lib/entities/Subscription.js | 6 +- lib/entities/SubscriptionSet.js | 36 ++- lib/errors/pubnub-api-error.js | 32 ++- package-lock.json | 4 +- package.json | 2 +- src/core/components/configuration.ts | 4 +- src/core/components/eventEmitter.ts | 57 +++-- src/core/components/listener_manager.ts | 5 +- src/entities/SubscribeCapable.ts | 45 +++- src/entities/Subscription.ts | 28 ++- src/entities/SubscriptionSet.ts | 91 ++++++- src/errors/pubnub-api-error.ts | 34 ++- .../subscription-worker-middleware.ts | 90 ++++++- .../subscription-worker.ts | 73 +++++- src/web/index.ts | 1 + test/integration/components/listeners.test.ts | 21 +- 27 files changed, 769 insertions(+), 168 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 063adc0da..cd04a7dcf 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,14 @@ --- changelog: + - date: 2025-03-13 + version: v9.1.0 + changes: + - type: feature + text: "`SubscriptionSet` will re-add listener every time when `Subscription` or `SubscriptionSet` added to it - this will let receive updates from newly added subscribe capable objects." + - type: bug + text: "Fix issue because of errors returned by `fetch` taken from `iframe` (to protect against monkey-patching by APM packages) was't handled as Error." + - type: improvement + text: "Use access token (auth key) content instead of base64 encoded token to identify PubNub clients, which can be used for requests aggregation." - date: 2025-03-10 version: v9.0.0 changes: @@ -1169,7 +1178,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '9.0.0' +version: '9.1.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1185,7 +1194,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v9.0.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.1.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1856,7 +1865,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v9.0.0/pubnub.9.0.0.js + location: https://github.com/pubnub/javascript/releases/download/v9.1.0/pubnub.9.1.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c7118b41..eae01bdb0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,15 @@ +## v9.1.0 +March 13 2025 + +#### Added +- `SubscriptionSet` will re-add listener every time when `Subscription` or `SubscriptionSet` added to it - this will let receive updates from newly added subscribe capable objects. + +#### Fixed +- Fix issue because of errors returned by `fetch` taken from `iframe` (to protect against monkey-patching by APM packages) was't handled as Error. + +#### Modified +- Use access token (auth key) content instead of base64 encoded token to identify PubNub clients, which can be used for requests aggregation. + ## v9.0.0 March 10 2025 diff --git a/README.md b/README.md index 996487ed0..aba9f1740 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.0.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.0.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.1.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.1.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 22c65e545..fe48c8961 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -2896,7 +2896,7 @@ * available). */ static create(errorOrResponse, data) { - if (errorOrResponse instanceof Error) + if (PubNubAPIError.isErrorObject(errorOrResponse)) return PubNubAPIError.createFromError(errorOrResponse); else return PubNubAPIError.createFromServiceResponse(errorOrResponse, data); @@ -2917,7 +2917,7 @@ return new PubNubAPIError(message, category, 0); else if (error instanceof PubNubAPIError) return error; - if (error instanceof Error) { + if (PubNubAPIError.isErrorObject(error)) { message = error.message; errorName = error.name; } @@ -3122,6 +3122,34 @@ return value; }; } + /** + * Check whether provided `object` is an `Error` or not. + * + * This check is required because the error object may be tied to a different execution context (global + * environment) and won't pass `instanceof Error` from the main window. + * To protect against monkey-patching, the `fetch` function is taken from an invisible `iframe` and, as a result, + * it is bind to the separate execution context. Errors generated by `fetch` won't pass the simple + * `instanceof Error` test. + * + * @param object - Object which should be checked. + * + * @returns `true` if `object` looks like an `Error` object. + * + * @internal + */ + static isErrorObject(object) { + if (!object || typeof object !== 'object') + return false; + if (object instanceof Error) + return true; + if ('name' in object && + 'message' in object && + typeof object.name === 'string' && + typeof object.message === 'string') { + return true; + } + return Object.prototype.toString.call(object) === '[object Error]'; + } } /** @@ -3143,6 +3171,10 @@ * Whether subscription worker has been initialized and ready to handle events. */ this.subscriptionWorkerReady = false; + /** + * Map of base64-encoded access tokens to their parsed representations. + */ + this.accessTokensMap = {}; this.workerEventsQueue = []; this.callbacks = new Map(); this.setupSubscriptionWorker(); @@ -3180,7 +3212,9 @@ // `onmessage` handler block to return results. this.callbacks.set(req.identifier, { resolve, reject }); // Trigger request processing by Service Worker. - this.scheduleEventPost(sendRequestEvent); + this.parsedAccessTokenForRequest(req) + .then((accessToken) => (sendRequestEvent.token = accessToken)) + .then(() => this.scheduleEventPost(sendRequestEvent)); }), controller, ]; @@ -3336,6 +3370,71 @@ } } } + /** + * Get parsed access token object. + * + * @param req - Transport request which may contain access token for processing. + * + * @returns Object with stringified access token information and expiration date information. + */ + parsedAccessTokenForRequest(req) { + return __awaiter(this, void 0, void 0, function* () { + var _a; + const accessToken = req.queryParameters ? ((_a = req.queryParameters.auth) !== null && _a !== void 0 ? _a : '') : undefined; + if (!accessToken) + return undefined; + else if (this.accessTokensMap[accessToken]) + return this.accessTokensMap[accessToken]; + return this.stringifyAccessToken(accessToken).then(([token, stringifiedToken]) => { + if (!token || !stringifiedToken) + return undefined; + return (this.accessTokensMap = { + [accessToken]: { token: stringifiedToken, expiration: token.timestamp * token.ttl * 60 }, + })[accessToken]; + }); + }); + } + /** + * Stringify access token content. + * + * Stringify information about resources with permissions. + * + * @param tokenString - Base64-encoded access token which should be parsed and stringified. + * + * @returns Tuple with parsed access token and its stringified content hash string. + */ + stringifyAccessToken(tokenString) { + return __awaiter(this, void 0, void 0, function* () { + if (!this.configuration.tokenManager) + return [undefined, undefined]; + const token = this.configuration.tokenManager.parseToken(tokenString); + if (!token) + return [undefined, undefined]; + // Translate permission to short string built from first chars of enabled permission. + const stringifyPermissions = (permission) => Object.entries(permission) + .filter(([_, v]) => v) + .map(([k]) => k[0]) + .sort() + .join(''); + const stringifyResources = (resource) => resource + ? Object.entries(resource) + .sort(([a], [b]) => a.localeCompare(b)) + .map(([type, entries]) => Object.entries(entries || {}) + .sort(([a], [b]) => a.localeCompare(b)) + .map(([name, perms]) => `${type}:${name}=${perms ? stringifyPermissions(perms) : ''}`) + .join(',')) + .join(';') + : ''; + let accessToken = [stringifyResources(token.resources), stringifyResources(token.patterns), token.authorized_uuid] + .filter(Boolean) + .join('|'); + if (typeof crypto !== 'undefined' && crypto.subtle) { + const hash = yield crypto.subtle.digest('SHA-256', new TextEncoder().encode(accessToken)); + accessToken = String.fromCharCode(...new Uint8Array(hash)); + } + return [token, typeof btoa !== 'undefined' ? btoa(accessToken) : accessToken]; + }); + } /** * Print request progress information. * @@ -3818,7 +3917,7 @@ return base.PubNubFile; }, get version() { - return '9.0.0'; + return '9.1.0'; }, getVersion() { return this.version; @@ -4591,8 +4690,6 @@ * @param listener - Listener with event callbacks to handle different types of events. */ addListener(listener) { - if (this.listeners.includes(listener)) - return; this.listeners.push(listener); } /** @@ -4601,7 +4698,9 @@ * @param listener - Event listeners which should be removed. */ removeListener(listener) { - this.listeners = this.listeners.filter((storedListener) => storedListener !== listener); + const listenerIdx = this.listeners.indexOf(listener); + if (listenerIdx !== -1) + this.listeners.splice(listenerIdx, 1); } /** * Clear all real-time event listeners. @@ -6749,10 +6848,14 @@ * Register real-time event listener for specific channels and groups. * * @param listener - Listener with event callbacks to handle different types of events. - * @param channels - List of channels for which listener should be registered. - * @param groups - List of channel groups for which listener should be registered. + * @param [channels] - List of channels for which listener should be registered. + * @param [groups] - List of channel groups for which listener should be registered. + * @param [listenerId] - Unique listener identifier which is used to update previous setup. + * + * @returns Registered listener identifier. */ - addListener(listener, channels, groups) { + addListener(listener, channels, groups, listenerId) { + listenerId !== null && listenerId !== void 0 ? listenerId : (listenerId = uuidGenerator.createUUID()); // Register event-listener listener globally. if (!(channels && groups)) { this.listenerManager.addListener(listener); @@ -6761,43 +6864,51 @@ channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { if (this.channelListenerMap.has(channel)) { const channelListeners = this.channelListenerMap.get(channel); - if (!channelListeners.includes(listener)) - channelListeners.push(listener); + channelListeners.push({ id: listenerId, listener }); } else - this.channelListenerMap.set(channel, [listener]); + this.channelListenerMap.set(channel, [{ id: listenerId, listener }]); }); groups === null || groups === void 0 ? void 0 : groups.forEach((group) => { if (this.groupListenerMap.has(group)) { const groupListeners = this.groupListenerMap.get(group); - if (!groupListeners.includes(listener)) - groupListeners.push(listener); + groupListeners.push({ id: listenerId, listener }); } else - this.groupListenerMap.set(group, [listener]); + this.groupListenerMap.set(group, [{ id: listenerId, listener }]); }); } + return listenerId; } /** * Remove real-time event listener. * * @param listener - Event listeners which should be removed. + * @param listenerId - Unique listener identifier assigned to it during addition. * @param channels - List of channels for which listener should be removed. * @param groups - List of channel groups for which listener should be removed. */ - removeListener(listener, channels, groups) { + removeListener(listener, listenerId, channels, groups) { if (!(channels && groups)) { this.listenerManager.removeListener(listener); } else { channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { - if (this.channelListenerMap.has(channel)) { - this.channelListenerMap.set(channel, this.channelListenerMap.get(channel).filter((channelListener) => channelListener !== listener)); + const channelListeners = this.channelListenerMap.get(channel); + if (channelListeners) { + const listenerObject = channelListeners.find((listenerObject) => listenerObject.id === listenerId); + const listenerIdx = listenerObject ? channelListeners.indexOf(listenerObject) : -1; + if (listenerIdx !== -1) + channelListeners.splice(listenerIdx, 1); } }); groups === null || groups === void 0 ? void 0 : groups.forEach((group) => { - if (this.groupListenerMap.has(group)) { - this.groupListenerMap.set(group, this.groupListenerMap.get(group).filter((groupListener) => groupListener !== listener)); + const groupListeners = this.groupListenerMap.get(group); + if (groupListeners) { + const listenerObject = groupListeners.find((listenerObject) => listenerObject.id === listenerId); + const listenerIdx = listenerObject ? groupListeners.indexOf(listenerObject) : -1; + if (listenerIdx !== -1) + groupListeners.splice(listenerIdx, 1); } }); } @@ -6820,15 +6931,15 @@ */ announce(type, event, channel, group) { if (event && this.channelListenerMap.has(channel)) - this.channelListenerMap.get(channel).forEach((listener) => { - const typedListener = listener[type]; + this.channelListenerMap.get(channel).forEach((listenerObject) => { + const typedListener = listenerObject.listener[type]; // @ts-expect-error Dynamic events mapping. if (typedListener) typedListener(event); }); if (group && this.groupListenerMap.has(group)) - this.groupListenerMap.get(group).forEach((listener) => { - const typedListener = listener[type]; + this.groupListenerMap.get(group).forEach((listenerObject) => { + const typedListener = listenerObject.listener[type]; // @ts-expect-error Dynamic events mapping. if (typedListener) typedListener(event); @@ -10126,7 +10237,7 @@ * is received from the real-time network. */ set onMessage(onMessageListener) { - this.listener.message = onMessageListener; + this.typeBasedListener.message = onMessageListener; } /** * Set new presence events handler. @@ -10135,7 +10246,7 @@ * presence event is received from the real-time network. */ set onPresence(onPresenceListener) { - this.listener.presence = onPresenceListener; + this.typeBasedListener.presence = onPresenceListener; } /** * Set new signal handler. @@ -10144,7 +10255,7 @@ * is received from the real-time network. */ set onSignal(onSignalListener) { - this.listener.signal = onSignalListener; + this.typeBasedListener.signal = onSignalListener; } /** * Set new app context event handler. @@ -10153,7 +10264,7 @@ * app context event is received from the real-time network. */ set onObjects(onObjectsListener) { - this.listener.objects = onObjectsListener; + this.typeBasedListener.objects = onObjectsListener; } /** * Set new message reaction event handler. @@ -10162,7 +10273,7 @@ * new message reaction event is received from the real-time network. */ set onMessageAction(messageActionEventListener) { - this.listener.messageAction = messageActionEventListener; + this.typeBasedListener.messageAction = messageActionEventListener; } /** * Set new file handler. @@ -10171,7 +10282,7 @@ * is received from the real-time network. */ set onFile(fileEventListener) { - this.listener.file = fileEventListener; + this.typeBasedListener.file = fileEventListener; } /** * Set events handler. @@ -10180,7 +10291,10 @@ * types of events. */ addListener(listener) { - this.eventEmitter.addListener(listener, this.channelNames, this.groupNames); + if (this.aggregatedListener && this.aggregatedListener !== listener) + this.removeListener(this.aggregatedListener); + this.aggregatedListenerId = this.eventEmitter.addListener(listener, this.channelNames, this.groupNames); + this.aggregatedListener = listener; } /** * Remove events handler. @@ -10190,7 +10304,11 @@ * {@link addListener}. */ removeListener(listener) { - this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); + if (!this.aggregatedListener) + return; + this.eventEmitter.removeListener(listener, this.aggregatedListenerId, this.channelNames, this.groupNames); + this.aggregatedListenerId = undefined; + this.aggregatedListener = undefined; } /** * Get list of channels which is used for subscription. @@ -10294,8 +10412,8 @@ this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.subscriptionList.push(subscription); }); - this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); + this.typeBasedListener = {}; + this.typeBasedListenerId = eventEmitter.addListener(this.typeBasedListener, this.channelNames, this.groupNames); } /** * Add additional entity's subscription to the subscription set. @@ -10309,7 +10427,9 @@ this.subscriptionList.push(subscription); this.channelNames = [...this.channelNames, ...subscription.channels]; this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); + this.eventEmitter.addListener(this.typeBasedListener, subscription.channels, subscription.channelGroups, this.typeBasedListenerId); + // Make sure to listen events on channels / groups added with `subscription`. + this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. // @ts-expect-error: Required access of protected field. if (this.subscribed && !subscription.subscribed) { @@ -10332,7 +10452,9 @@ this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); - this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + // Make sure to stop listening for events from channels / groups removed with `subscription`. + this.updateListeners(); // @ts-expect-error: Required access of protected field. if (subscription.subscribedAutomatically) subscription.unsubscribe(); @@ -10349,7 +10471,9 @@ this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; - this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); + this.eventEmitter.addListener(this.typeBasedListener, subscriptionSet.channels, subscriptionSet.channelGroups, this.typeBasedListenerId); + // Make sure to listen events on channels / groups added with `subscription set`. + this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. if (this.subscribed && !subscriptionSet.subscribed) { subscriptionSet.subscribe(); @@ -10370,7 +10494,9 @@ this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); - this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + // Make sure to stop listening for events from channels / groups removed with `subscription set`. + this.updateListeners(); if (subscriptionSet.subscribedAutomatically) subscriptionSet.unsubscribe(); } @@ -10382,6 +10508,22 @@ get subscriptions() { return this.subscriptionList.slice(0); } + /** + * Update listeners for current {@link SubscriptionSet} state. + * + * When {@link Subscription} or {@link SubscriptionSet} added / removed it is **required** to + * update mapping of channels / groups (based on current {@link SubscriptionSet} state) to the + * event listeners. + * + * @internal + */ + updateListeners() { + if (!this.aggregatedListener) + return; + const aggregatedListener = this.aggregatedListener; + this.removeListener(this.aggregatedListener); + this.addListener(aggregatedListener); + } } /** @@ -10446,8 +10588,8 @@ this.options = subscriptionOptions; this.pubnub = pubnub; this.eventEmitter = eventEmitter; - this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); + this.typeBasedListener = {}; + eventEmitter.addListener(this.typeBasedListener, this.channelNames, this.groupNames); } /** * Merge entities' subscription objects into subscription set. @@ -10470,6 +10612,8 @@ subscription.subscribe(); subscription.subscribedAutomatically = true; // should be placed after .subscribe() call. } + if (this.aggregatedListener) + subscriptionSet.addListener(this.aggregatedListener); this.pubnub.registerSubscribeCapable(subscriptionSet); // @ts-expect-error: Required modification of protected field. subscriptionSet.subscribed = true; @@ -14656,6 +14800,7 @@ workerUnsubscribeOfflineClients: platformConfiguration.subscriptionWorkerUnsubscribeOfflineClients, logVerbosity: clientConfiguration.logVerbosity, workerLogVerbosity: platformConfiguration.subscriptionWorkerLogVerbosity, + tokenManager, transport, }); } diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 8b3a56d4e..e1022274c 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,O,P,N,o,12,u[1]),N=t(N,C,O,P,l,17,u[2]),P=t(P,N,C,O,h,22,u[3]);O=t(O,P,N,C,d,7,u[4]),C=t(C,O,P,N,p,12,u[5]),N=t(N,C,O,P,g,17,u[6]),P=t(P,N,C,O,y,22,u[7]),O=t(O,P,N,C,f,7,u[8]),C=t(C,O,P,N,b,12,u[9]),N=t(N,C,O,P,m,17,u[10]),P=t(P,N,C,O,v,22,u[11]),O=t(O,P,N,C,w,7,u[12]),C=t(C,O,P,N,S,12,u[13]),N=t(N,C,O,P,k,17,u[14]),O=n(O,P=t(P,N,C,O,E,22,u[15]),N,C,o,5,u[16]),C=n(C,O,P,N,g,9,u[17]),N=n(N,C,O,P,v,14,u[18]),P=n(P,N,C,O,c,20,u[19]),O=n(O,P,N,C,p,5,u[20]),C=n(C,O,P,N,m,9,u[21]),N=n(N,C,O,P,E,14,u[22]),P=n(P,N,C,O,d,20,u[23]),O=n(O,P,N,C,b,5,u[24]),C=n(C,O,P,N,k,9,u[25]),N=n(N,C,O,P,h,14,u[26]),P=n(P,N,C,O,f,20,u[27]),O=n(O,P,N,C,S,5,u[28]),C=n(C,O,P,N,l,9,u[29]),N=n(N,C,O,P,y,14,u[30]),O=s(O,P=n(P,N,C,O,w,20,u[31]),N,C,p,4,u[32]),C=s(C,O,P,N,f,11,u[33]),N=s(N,C,O,P,v,16,u[34]),P=s(P,N,C,O,k,23,u[35]),O=s(O,P,N,C,o,4,u[36]),C=s(C,O,P,N,d,11,u[37]),N=s(N,C,O,P,y,16,u[38]),P=s(P,N,C,O,m,23,u[39]),O=s(O,P,N,C,S,4,u[40]),C=s(C,O,P,N,c,11,u[41]),N=s(N,C,O,P,h,16,u[42]),P=s(P,N,C,O,g,23,u[43]),O=s(O,P,N,C,b,4,u[44]),C=s(C,O,P,N,w,11,u[45]),N=s(N,C,O,P,E,16,u[46]),O=r(O,P=s(P,N,C,O,l,23,u[47]),N,C,c,6,u[48]),C=r(C,O,P,N,y,10,u[49]),N=r(N,C,O,P,k,15,u[50]),P=r(P,N,C,O,p,21,u[51]),O=r(O,P,N,C,w,6,u[52]),C=r(C,O,P,N,h,10,u[53]),N=r(N,C,O,P,m,15,u[54]),P=r(P,N,C,O,o,21,u[55]),O=r(O,P,N,C,f,6,u[56]),C=r(C,O,P,N,E,10,u[57]),N=r(N,C,O,P,g,15,u[58]),P=r(P,N,C,O,S,21,u[59]),O=r(O,P,N,C,d,6,u[60]),C=r(C,O,P,N,v,10,u[61]),N=r(N,C,O,P,l,15,u[62]),P=r(P,N,C,O,b,21,u[63]);a[0]=a[0]+O|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=E[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new E({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class j extends Error{static create(e,t){return e instanceof Error?j.createFromError(e):j.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new j(n,t,0);if(e instanceof j)return e;if(e instanceof Error&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new j(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new j(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,j.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.scheduleEventPost(n)})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(j.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new j(s,e,0,new Error(s)))}}}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,E=!1,O=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(E=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(O=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.0.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class G{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var K;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(K||(K={}));const $=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),L=(e,t)=>{const n=e.map((e=>$(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?K.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===K.POST||t===K.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${$(e)}`)).join("&"):`${t}=${$(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw j.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw j.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.includes(e)||this.listeners.push(e)}removeListener(e){this.listeners=this.listeners.filter((t=>t!==e))}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:K.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===K.POST||r.method===K.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw j.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n){t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){const n=this.channelListenerMap.get(t);n.includes(e)||n.push(e)}else this.channelListenerMap.set(t,[e])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){const n=this.groupListenerMap.get(t);n.includes(e)||n.push(e)}else this.groupListenerMap.set(t,[e])}))):this.listenerManager.addListener(e)}removeListener(e,t,n){t&&n?(null==t||t.forEach((t=>{this.channelListenerMap.has(t)&&this.channelListenerMap.set(t,this.channelListenerMap.get(t).filter((t=>t!==e)))})),null==n||n.forEach((t=>{this.groupListenerMap.has(t)&&this.groupListenerMap.set(t,this.groupListenerMap.get(t).filter((t=>t!==e)))}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Ee=ge("DISCONNECT",(()=>({}))),Oe=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),_e=ge("TIMES_UP",(()=>({}))),je=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(_e())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Oe.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>$e.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(_e.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ke.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARBEAT_RECONNECTING");Ge.onEnter((e=>Re(e))),Ge.onExit((()=>Re.cancel)),Ge.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Ee.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Ge.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Ge.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEATING");Ke.onEnter((e=>je(e.channels,e.groups))),Ke.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ke.on(Oe.type,((e,t)=>Ke.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ce.type,((e,t)=>Ke.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ke.on(Me.type,((e,t)=>Ge.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ke.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with(void 0,[Ie(e.channels,e.groups)])));const $e=new he("HEARTBEAT_INACTIVE");$e.on(Oe.type,((e,t)=>Ke.with({channels:t.payload.channels,groups:t.payload.groups})));class Le{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start($e,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Oe(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Et extends se{constructor(e){var t,n;super({method:e.sendByPost?K.POST:K.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${$(t)}/0${this.parameters.sendByPost?"":`/${$(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ot extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${$(n)}/0/${$(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${L(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=n?n:[],",")}/uuid/${$(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${L(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class _t extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${L(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class jt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${$(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${L(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${L(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${L(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Gt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${$(t)}/message/${s}/action/${n}`}}class Kt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${$(t)}/0/${$(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class $t extends se{constructor(e){super({method:K.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${$(e)}/files/${t}/${n}`}}class Lt extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:K.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:K.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof j?e:j.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.listener.message=e}set onPresence(e){this.listener.presence=e}set onSignal(e){this.listener.signal=e}set onObjects(e){this.listener.objects=e}set onMessageAction(e){this.listener.messageAction=e}set onFile(e){this.listener.file=e}addListener(e){this.eventEmitter.addListener(e,this.channelNames,this.groupNames)}removeListener(e){this.eventEmitter.removeListener(e,this.channelNames,this.groupNames)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.listener,t,n),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.listener,e.channels,e.channelGroups),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.listener,t,n),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.listener={},s.addListener(this.listener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${$(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:K.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${$(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class On extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:K.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${$(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new On(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${$(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new Le({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof j?e:j.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new _t({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new jt({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof j&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${$(t)}`)).join("&"):`${e}=${$(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class _n{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class jn extends An{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})}));let a,u,l;a=new G(new _n((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,transport:h}));super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return jn.CryptoModule=M,jn})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),O=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],O=e[i+15],E=t(E=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,E,P,N,o,12,u[1]),N=t(N,C,E,P,l,17,u[2]),P=t(P,N,C,E,h,22,u[3]);E=t(E,P,N,C,d,7,u[4]),C=t(C,E,P,N,p,12,u[5]),N=t(N,C,E,P,g,17,u[6]),P=t(P,N,C,E,y,22,u[7]),E=t(E,P,N,C,f,7,u[8]),C=t(C,E,P,N,b,12,u[9]),N=t(N,C,E,P,m,17,u[10]),P=t(P,N,C,E,v,22,u[11]),E=t(E,P,N,C,w,7,u[12]),C=t(C,E,P,N,S,12,u[13]),N=t(N,C,E,P,k,17,u[14]),E=n(E,P=t(P,N,C,E,O,22,u[15]),N,C,o,5,u[16]),C=n(C,E,P,N,g,9,u[17]),N=n(N,C,E,P,v,14,u[18]),P=n(P,N,C,E,c,20,u[19]),E=n(E,P,N,C,p,5,u[20]),C=n(C,E,P,N,m,9,u[21]),N=n(N,C,E,P,O,14,u[22]),P=n(P,N,C,E,d,20,u[23]),E=n(E,P,N,C,b,5,u[24]),C=n(C,E,P,N,k,9,u[25]),N=n(N,C,E,P,h,14,u[26]),P=n(P,N,C,E,f,20,u[27]),E=n(E,P,N,C,S,5,u[28]),C=n(C,E,P,N,l,9,u[29]),N=n(N,C,E,P,y,14,u[30]),E=s(E,P=n(P,N,C,E,w,20,u[31]),N,C,p,4,u[32]),C=s(C,E,P,N,f,11,u[33]),N=s(N,C,E,P,v,16,u[34]),P=s(P,N,C,E,k,23,u[35]),E=s(E,P,N,C,o,4,u[36]),C=s(C,E,P,N,d,11,u[37]),N=s(N,C,E,P,y,16,u[38]),P=s(P,N,C,E,m,23,u[39]),E=s(E,P,N,C,S,4,u[40]),C=s(C,E,P,N,c,11,u[41]),N=s(N,C,E,P,h,16,u[42]),P=s(P,N,C,E,g,23,u[43]),E=s(E,P,N,C,b,4,u[44]),C=s(C,E,P,N,w,11,u[45]),N=s(N,C,E,P,O,16,u[46]),E=r(E,P=s(P,N,C,E,l,23,u[47]),N,C,c,6,u[48]),C=r(C,E,P,N,y,10,u[49]),N=r(N,C,E,P,k,15,u[50]),P=r(P,N,C,E,p,21,u[51]),E=r(E,P,N,C,w,6,u[52]),C=r(C,E,P,N,h,10,u[53]),N=r(N,C,E,P,m,15,u[54]),P=r(P,N,C,E,o,21,u[55]),E=r(E,P,N,C,f,6,u[56]),C=r(C,E,P,N,O,10,u[57]),N=r(N,C,E,P,g,15,u[58]),P=r(P,N,C,E,S,21,u[59]),E=r(E,P,N,C,d,6,u[60]),C=r(C,E,P,N,v,10,u[61]),N=r(N,C,E,P,l,15,u[62]),P=r(P,N,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=j.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=j.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===j.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=j.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class j{static from(e,t){if(e!==j.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==j.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>j.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+j.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(s),a)}}j.SENTINEL="PNED",j.LEGACY_IDENTIFIER="",j.IDENTIFIER_LENGTH=4,j.VERSION=1,j.MAX_VERSION=1,j.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return j.VERSION}get length(){return j.SENTINEL.length+1+j.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(j.SENTINEL)),e+=j.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=j.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...new Uint8Array(e))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,O=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(O=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:O,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.1.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),je=ge("HEARTBEAT_GIVEUP",(()=>({}))),Ae=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Ae())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(je());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(Ae.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(je.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class jt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class At extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){if(!this.aggregatedListener)return;const e=this.aggregatedListener;this.removeListener(this.aggregatedListener),this.addListener(e)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class jn{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=jn.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new At({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new jt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new jt(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}jn.decoder=new TextDecoder,jn.OPERATIONS=ie,jn.CATEGORIES=h,jn.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,jn.LinearRetryPolicy=Be.LinearRetryPolicy;class An{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends jn{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new An((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h}));super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index 94ea97d5f..d7245c48c 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -759,6 +759,12 @@ // Update request `state` (if required). if (Object.keys(aggregatedState).length) request.queryParameters['state'] = JSON.stringify(aggregatedState); + // Update `auth` key (if required). + if (request.queryParameters && request.queryParameters.auth) { + const authKey = authKeyForAggregatedClientsRequest(clients); + if (authKey) + request.queryParameters.auth = authKey; + } } else { serviceRequests[serviceRequestId] = { @@ -1286,6 +1292,7 @@ client.origin = event.request.origin; client.userId = query.uuid; client.pnsdk = query.pnsdk; + client.accessToken = event.token; handleClientIdentityChangeIfRequired(client, userId, authKey); }; /** @@ -1394,7 +1401,7 @@ const unsubscribeClient = (client) => { if (!client.subscription) return; - const { channels, channelGroups } = client.subscription; + const { channels, channelGroups, serviceRequestId } = client.subscription; const encodedChannelGroups = (channelGroups !== null && channelGroups !== void 0 ? channelGroups : []) .filter((name) => !name.endsWith('-pnpres')) .map((name) => encodeString(name)) @@ -1403,6 +1410,10 @@ .filter((name) => !name.endsWith('-pnpres')) .map((name) => encodeString(name)) .sort(); + if (serviceRequestId) { + delete client.subscription.serviceRequestId; + cancelRequest(serviceRequestId); + } if (encodedChannels.length === 0 && encodedChannelGroups.length === 0) return; const channelGroupsString = encodedChannelGroups.length > 0 ? encodedChannelGroups.join(',') : undefined; @@ -1512,13 +1523,16 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' * @returns List of PubNub client states which works from other pages for the same user. */ const clientsForSendSubscribeRequestEvent = (timetoken, event) => { - var _a, _b, _c; + var _a, _b; + const reqClient = pubNubClients[event.clientIdentifier]; + if (!reqClient) + return []; const query = event.request.queryParameters; + const authKey = clientAggregateAuthKey(reqClient); const filterExpression = ((_a = query['filter-expr']) !== null && _a !== void 0 ? _a : ''); - const authKey = ((_b = query.auth) !== null && _b !== void 0 ? _b : ''); const userId = query.uuid; - return ((_c = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _c !== void 0 ? _c : []).filter((client) => client.userId === userId && - client.authKey === authKey && + return ((_b = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _b !== void 0 ? _b : []).filter((client) => client.userId === userId && + clientAggregateAuthKey(client) === authKey && client.subscription && // Only clients with active subscription can be used. (client.subscription.channels.length !== 0 || client.subscription.channelGroups.length !== 0) && @@ -1553,11 +1567,14 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' * @returns List of PubNub client states which works from other pages for the same user. */ const clientsForSendLeaveRequestEvent = (event) => { - var _a, _b; + var _a; + const reqClient = pubNubClients[event.clientIdentifier]; + if (!reqClient) + return []; const query = event.request.queryParameters; - const authKey = ((_a = query.auth) !== null && _a !== void 0 ? _a : ''); + const authKey = reqClient.authKey; const userId = query.uuid; - return ((_b = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _b !== void 0 ? _b : []).filter((client) => client.userId === userId && client.authKey === authKey); + return ((_a = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _a !== void 0 ? _a : []).filter((client) => client.userId === userId && clientAggregateAuthKey(client) === authKey); }; /** * Extract list of channels from request URI path. @@ -1625,6 +1642,31 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' pingTimeouts[subscriptionKey] = setTimeout(() => pingClients(subscriptionKey), interval * 500 - 1); } }; + /** + * Retrieve auth key which is suitable for common clients request aggregation. + * + * @param client - Client for which auth key for aggregation should be retrieved. + * + * @returns Client aggregation auth key. + */ + const clientAggregateAuthKey = (client) => { + var _a; + return client.accessToken ? ((_a = client.accessToken.token) !== null && _a !== void 0 ? _a : client.authKey) : client.authKey; + }; + /** + * Pick auth key for clients with latest expiration date. + * + * @param clients - List of clients for which latest auth key should be retrieved. + * + * @returns Access token which can be used to confirm `userId` permissions for aggregated request. + */ + const authKeyForAggregatedClientsRequest = (clients) => { + const latestClient = clients + .filter((client) => !!client.accessToken) + .sort((a, b) => a.accessToken.expiration - b.accessToken.expiration) + .pop(); + return latestClient ? latestClient.authKey : undefined; + }; /** * Compose clients' aggregation key. * @@ -1635,7 +1677,8 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' * @returns Aggregation timeout identifier string. */ const aggregateTimerId = (client) => { - let id = `${client.userId}-${client.subscriptionKey}${client.authKey ? `-${client.authKey}` : ''}`; + const authKey = clientAggregateAuthKey(client); + let id = `${client.userId}-${client.subscriptionKey}${authKey ? `-${authKey}` : ''}`; if (client.subscription && client.subscription.filterExpression) id += `-${client.subscription.filterExpression}`; return id; diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index 81c794219..caebba97d 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((r=r.apply(e,t||[])).next())}))}var t;"function"==typeof SuppressedError&&SuppressedError,function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(t||(t={}));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r,i,s={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},v={},y={};self.onconnect=e=>{ne("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)n.port=e,D(n),ne(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-pong"===n.type)N(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){F(n);const e=h[n.clientIdentifier];if(e)if(_(e,n)){const t=te(e);if(!l.has(t)){const e=setTimeout((()=>{q(n),l.delete(t)}),50);l.set(t,e)}}else q(n)}else n.request.path.endsWith("/heartbeat")?(U(n),m(n)):w(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=e=>{var t;const n=P(e),r=h[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),x("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=y[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,x("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),A(r,u)}return}e.request.cancellable&&f.set(n.identifier,new AbortController);const s=y[n.identifier],{timetokenOverride:o,regionOverride:c}=s;j(n,(()=>E(n.identifier)),((t,r)=>{R(t,r,e.request),T(t,n.identifier)}),((t,r)=>{R(t,null,e.request,W(r)),T(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(t=I(t,o,c)),t})),ne(`'${Object.keys(y).length}' subscription request currently active.`)},I=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ne(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ne(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},m=e=>{var t;const n=h[e.clientIdentifier],r=C(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(x("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ne(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,x("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}j(r,(()=>[n]),((t,n)=>{o&&(o.response=n),R(t,n,e.request)}),((t,n)=>{R(t,null,e.request,W(n))})),ne("Started heartbeat request.",n)},w=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=G(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(j(n,(()=>[t]),((t,n)=>{R(t,n,e.request)}),((t,n)=>{R(t,null,e.request,W(n))})),ne("Started leave request.",t),void 0===i)return;const s=E(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),k(i),$(s)},O=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,k(n))},$=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&q({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},j=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(K(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),S(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},k=e=>{if(0===E(e).length){const t=f.get(e);f.delete(e),delete y[e],t&&t.abort("Cancel request")}},S=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),E=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),T=(e,t)=>{delete y[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},K=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${ie(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},P=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=Q(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=H(u,e);if(s){const e=y[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Z(e.channels,n))&&(!(r.length>0)||Z(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),v=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(v.add,v);const n=t.serviceRequestId;t.serviceRequestId=a,n&&y[n]&&k(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=y[a])&&void 0!==r?r:y[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(v.size){q.channels=Array.from(v).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h))}else y[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};y[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(y[a].region=d.queryParameters.tr),y[a].timetokenOverride=f,y[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)re(y[a],`Started aggregated request for clients: ${b}`,e);return d},C=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=B(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,v=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=Z(e,o.heartbeat.channels)&&Z(t,o.heartbeat.channelGroups),n&&(v=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;if(g){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!v&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},G=e=>{const t=h[e.clientIdentifier],n=z(e);let r=Y(e.request),i=X(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");ne(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=v[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},x=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=v[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},R=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=v[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?W(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)ne(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)ne(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&ne(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},W=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},D=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=v[s=e.subscriptionKey])&&void 0!==n?n:v[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)ne(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)ne(`Setup PubNub client ping event ${n} seconds`,e);a[e.subscriptionKey]=setTimeout((()=>ee(t)),500*n-1)}},F=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,v,y,q,I,m,w;const O=e.request.queryParameters,{clientIdentifier:$}=e,j=h[$];if(!j)return;const k=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let E=j.subscription;if(E){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=g[v=j.subscriptionKey])&&void 0!==s?s:g[v]={})[q=j.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of E.objectsWithState)e[n]||delete t[n];E.objectsWithState=Object.keys(e)}else if(E.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=j.subscriptionKey])&&void 0!==c?c:g[I]={})[w=j.userId])&&void 0!==l?l:m[w]={};for(const t of E.objectsWithState)delete e[t];E.objectsWithState=[]}}else{if(E={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=j.subscriptionKey])&&void 0!==r?r:g[f]={})[b=j.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),E.objectsWithState=Object.keys(e)}j.subscription=E}E.path!==e.request.path&&(E.path=e.request.path,E.channels=X(e.request)),E.channelGroupQuery!==k&&(E.channelGroupQuery=k,E.channelGroups=Y(e.request));const{authKey:T,userId:K}=j;E.request=e.request,E.filterExpression=null!==(u=O["filter-expr"])&&void 0!==u?u:"",E.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(E.region=O.tr),j.authKey=null!==(d=O.auth)&&void 0!==d?d:"",j.origin=e.request.origin,j.userId=O.uuid,j.pnsdk=O.pnsdk,V(j,K,T)},U=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=Y(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=X(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},V=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},N=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},M=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r}=e.subscription,i=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>se(e))).sort(),s=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>se(e))).sort();if(0===s.length&&0===i.length)return;const o=i.length>0?i.join(","):void 0,l=0===s.length?",":s.join(","),u=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),o?{"channel-group":o}:{}),a={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${l}/leave`,queryParameters:u,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:u.requestid}};w(a,e)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},H=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ne(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=y[e.serviceRequestId];if(s||(s=Y(t.request)),o||(o=X(t.request)),o.length&&!Z(r.channels,o))continue;if(s.length&&!Z(r.channelGroups,s))continue;return re(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},_=(e,t)=>{var n,r;return Q(null!==(r=(null!==(n=e.subscription)&&void 0!==n?n:{}).timetoken)&&void 0!==r?r:"0",t).length>1},Q=(e,t)=>{var n,r,i;const s=t.request.queryParameters,o=null!==(n=s["filter-expr"])&&void 0!==n?n:"",c=null!==(r=s.auth)&&void 0!==r?r:"",l=s.uuid;return(null!==(i=p[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&t.authKey===c&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===o&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>z(e),z=e=>{var t,n;const r=e.request.queryParameters,i=null!==(t=r.auth)&&void 0!==t?t:"",s=r.uuid;return(null!==(n=p[e.subscriptionKey])&&void 0!==n?n:[]).filter((e=>e.userId===s&&e.authKey===i))},X=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},Y=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Z=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ee=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)ne(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);((e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r&&r.unsubscribeOfflineClients&&M(r),i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=v[e];n&&(delete n[t],0===Object.keys(n).length&&delete v[e])}else delete v[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)ne(s,e);else ne(s)})(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ee(e)),500*t-1)}},te=e=>{let t=`${e.userId}-${e.subscriptionKey}${e.authKey?`-${e.authKey}`:""}`;return e.subscription&&e.subscription.filterExpression&&(t+=`-${e.subscription.filterExpression}`),t},ne=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},re=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},ie=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${se(e)}`)).join("&"):`${t}=${se(n)}`})).join("&"),se=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},v={},y={};self.onconnect=e=>{ie("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)n.port=e,D(n),ie(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-pong"===n.type)N(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){F(n);const e=h[n.clientIdentifier];if(e)if(_(e,n)){const t=re(e);if(!l.has(t)){const e=setTimeout((()=>{q(n),l.delete(t)}),50);l.set(t,e)}}else q(n)}else n.request.path.endsWith("/heartbeat")?(U(n),m(n)):w(n);else"cancel-request"===n.type&&k(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=e=>{var t;const n=K(e),r=h[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),x("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=y[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,x("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),A(r,u)}return}e.request.cancellable&&f.set(n.identifier,new AbortController);const s=y[n.identifier],{timetokenOverride:o,regionOverride:c}=s;$(n,(()=>T(n.identifier)),((t,r)=>{R(t,r,e.request),E(t,n.identifier)}),((t,r)=>{R(t,null,e.request,W(r)),E(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(t=I(t,o,c)),t})),ie(`'${Object.keys(y).length}' subscription request currently active.`)},I=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ie(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ie(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},m=e=>{var t;const n=h[e.clientIdentifier],r=C(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(x("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ie(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,x("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}$(r,(()=>[n]),((t,n)=>{o&&(o.response=n),R(t,n,e.request)}),((t,n)=>{R(t,null,e.request,W(n))})),ie("Started heartbeat request.",n)},w=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=G(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if($(n,(()=>[t]),((t,n)=>{R(t,n,e.request)}),((t,n)=>{R(t,null,e.request,W(n))})),ie("Started leave request.",t),void 0===i)return;const s=T(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),j(i),O(s)},k=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,j(n))},O=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&q({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},$=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(P(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),S(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},j=e=>{if(0===T(e).length){const t=f.get(e);f.delete(e),delete y[e],t&&t.abort("Cancel request")}},S=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),T=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete y[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},P=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${oe(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},K=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=Q(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=H(u,e);if(s){const e=y[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Z(e.channels,n))&&(!(r.length>0)||Z(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),v=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(v.add,v);const n=t.serviceRequestId;t.serviceRequestId=a,n&&y[n]&&j(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=y[a])&&void 0!==r?r:y[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(v.size){q.channels=Array.from(v).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}if(b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h)),d.queryParameters&&d.queryParameters.auth){const e=ne(u);e&&(d.queryParameters.auth=e)}}else y[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};y[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(y[a].region=d.queryParameters.tr),y[a].timetokenOverride=f,y[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)se(y[a],`Started aggregated request for clients: ${b}`,e);return d},C=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=B(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,v=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=Z(e,o.heartbeat.channels)&&Z(t,o.heartbeat.channelGroups),n&&(v=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;if(g){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!v&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},G=e=>{const t=h[e.clientIdentifier],n=z(e);let r=Y(e.request),i=X(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");ie(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=v[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},x=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=v[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},R=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=v[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?W(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)ie(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)ie(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&ie(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},W=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},D=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=v[s=e.subscriptionKey])&&void 0!==n?n:v[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)ie(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)ie(`Setup PubNub client ping event ${n} seconds`,e);a[e.subscriptionKey]=setTimeout((()=>ee(t)),500*n-1)}},F=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,v,y,q,I,m,w;const k=e.request.queryParameters,{clientIdentifier:O}=e,$=h[O];if(!$)return;const j=null!==(t=k["channel-group"])&&void 0!==t?t:"",S=null!==(n=k.state)&&void 0!==n?n:"";let T=$.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=g[v=$.subscriptionKey])&&void 0!==s?s:g[v]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=$.subscriptionKey])&&void 0!==c?c:g[I]={})[w=$.userId])&&void 0!==l?l:m[w]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=$.subscriptionKey])&&void 0!==r?r:g[f]={})[b=$.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}$.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=X(e.request)),T.channelGroupQuery!==j&&(T.channelGroupQuery=j,T.channelGroups=Y(e.request));const{authKey:E,userId:P}=$;T.request=e.request,T.filterExpression=null!==(u=k["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=k.tt)&&void 0!==a?a:"0",void 0!==k.tr&&(T.region=k.tr),$.authKey=null!==(d=k.auth)&&void 0!==d?d:"",$.origin=e.request.origin,$.userId=k.uuid,$.pnsdk=k.pnsdk,$.accessToken=e.token,V($,P,E)},U=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=Y(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=X(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},V=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},N=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},M=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r,serviceRequestId:i}=e.subscription,s=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ce(e))).sort(),o=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ce(e))).sort();if(i&&(delete e.subscription.serviceRequestId,j(i)),0===o.length&&0===s.length)return;const l=s.length>0?s.join(","):void 0,u=0===o.length?",":o.join(","),a=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),l?{"channel-group":l}:{}),d={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${u}/leave`,queryParameters:a,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:a.requestid}};w(d,e)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},H=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ie(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=y[e.serviceRequestId];if(s||(s=Y(t.request)),o||(o=X(t.request)),o.length&&!Z(r.channels,o))continue;if(s.length&&!Z(r.channelGroups,s))continue;return se(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},_=(e,t)=>{var n,r;return Q(null!==(r=(null!==(n=e.subscription)&&void 0!==n?n:{}).timetoken)&&void 0!==r?r:"0",t).length>1},Q=(e,t)=>{var n,r;const i=h[t.clientIdentifier];if(!i)return[];const s=t.request.queryParameters,o=te(i),c=null!==(n=s["filter-expr"])&&void 0!==n?n:"",l=s.uuid;return(null!==(r=p[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===l&&te(t)===o&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===c&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>z(e),z=e=>{var t;const n=h[e.clientIdentifier];if(!n)return[];const r=e.request.queryParameters,i=n.authKey,s=r.uuid;return(null!==(t=p[e.subscriptionKey])&&void 0!==t?t:[]).filter((e=>e.userId===s&&te(e)===i))},X=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},Y=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Z=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ee=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)ie(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);((e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r&&r.unsubscribeOfflineClients&&M(r),i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=v[e];n&&(delete n[t],0===Object.keys(n).length&&delete v[e])}else delete v[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)ie(s,e);else ie(s)})(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ee(e)),500*t-1)}},te=e=>{var t;return e.accessToken&&null!==(t=e.accessToken.token)&&void 0!==t?t:e.authKey},ne=e=>{const t=e.filter((e=>!!e.accessToken)).sort(((e,t)=>e.accessToken.expiration-t.accessToken.expiration)).pop();return t?t.authKey:void 0},re=e=>{const t=te(e);let n=`${e.userId}-${e.subscriptionKey}${t?`-${t}`:""}`;return e.subscription&&e.subscription.filterExpression&&(n+=`-${e.subscription.filterExpression}`),n},ie=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},se=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},oe=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${ce(e)}`)).join("&"):`${t}=${ce(n)}`})).join("&"),ce=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 30f62f99b..36d9175c1 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -120,7 +120,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '9.0.0'; + return '9.1.0'; }, getVersion() { return this.version; diff --git a/lib/core/components/eventEmitter.js b/lib/core/components/eventEmitter.js index a16e3097c..ed0376d38 100644 --- a/lib/core/components/eventEmitter.js +++ b/lib/core/components/eventEmitter.js @@ -15,8 +15,12 @@ var __rest = (this && this.__rest) || function (s, e) { } return t; }; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); const subscribe_1 = require("../endpoints/subscribe"); +const uuid_1 = __importDefault(require("./uuid")); /** * Real-time events' emitter. * @@ -99,10 +103,14 @@ class EventEmitter { * Register real-time event listener for specific channels and groups. * * @param listener - Listener with event callbacks to handle different types of events. - * @param channels - List of channels for which listener should be registered. - * @param groups - List of channel groups for which listener should be registered. + * @param [channels] - List of channels for which listener should be registered. + * @param [groups] - List of channel groups for which listener should be registered. + * @param [listenerId] - Unique listener identifier which is used to update previous setup. + * + * @returns Registered listener identifier. */ - addListener(listener, channels, groups) { + addListener(listener, channels, groups, listenerId) { + listenerId !== null && listenerId !== void 0 ? listenerId : (listenerId = uuid_1.default.createUUID()); // Register event-listener listener globally. if (!(channels && groups)) { this.listenerManager.addListener(listener); @@ -111,43 +119,51 @@ class EventEmitter { channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { if (this.channelListenerMap.has(channel)) { const channelListeners = this.channelListenerMap.get(channel); - if (!channelListeners.includes(listener)) - channelListeners.push(listener); + channelListeners.push({ id: listenerId, listener }); } else - this.channelListenerMap.set(channel, [listener]); + this.channelListenerMap.set(channel, [{ id: listenerId, listener }]); }); groups === null || groups === void 0 ? void 0 : groups.forEach((group) => { if (this.groupListenerMap.has(group)) { const groupListeners = this.groupListenerMap.get(group); - if (!groupListeners.includes(listener)) - groupListeners.push(listener); + groupListeners.push({ id: listenerId, listener }); } else - this.groupListenerMap.set(group, [listener]); + this.groupListenerMap.set(group, [{ id: listenerId, listener }]); }); } + return listenerId; } /** * Remove real-time event listener. * * @param listener - Event listeners which should be removed. + * @param listenerId - Unique listener identifier assigned to it during addition. * @param channels - List of channels for which listener should be removed. * @param groups - List of channel groups for which listener should be removed. */ - removeListener(listener, channels, groups) { + removeListener(listener, listenerId, channels, groups) { if (!(channels && groups)) { this.listenerManager.removeListener(listener); } else { channels === null || channels === void 0 ? void 0 : channels.forEach((channel) => { - if (this.channelListenerMap.has(channel)) { - this.channelListenerMap.set(channel, this.channelListenerMap.get(channel).filter((channelListener) => channelListener !== listener)); + const channelListeners = this.channelListenerMap.get(channel); + if (channelListeners) { + const listenerObject = channelListeners.find((listenerObject) => listenerObject.id === listenerId); + const listenerIdx = listenerObject ? channelListeners.indexOf(listenerObject) : -1; + if (listenerIdx !== -1) + channelListeners.splice(listenerIdx, 1); } }); groups === null || groups === void 0 ? void 0 : groups.forEach((group) => { - if (this.groupListenerMap.has(group)) { - this.groupListenerMap.set(group, this.groupListenerMap.get(group).filter((groupListener) => groupListener !== listener)); + const groupListeners = this.groupListenerMap.get(group); + if (groupListeners) { + const listenerObject = groupListeners.find((listenerObject) => listenerObject.id === listenerId); + const listenerIdx = listenerObject ? groupListeners.indexOf(listenerObject) : -1; + if (listenerIdx !== -1) + groupListeners.splice(listenerIdx, 1); } }); } @@ -170,15 +186,15 @@ class EventEmitter { */ announce(type, event, channel, group) { if (event && this.channelListenerMap.has(channel)) - this.channelListenerMap.get(channel).forEach((listener) => { - const typedListener = listener[type]; + this.channelListenerMap.get(channel).forEach((listenerObject) => { + const typedListener = listenerObject.listener[type]; // @ts-expect-error Dynamic events mapping. if (typedListener) typedListener(event); }); if (group && this.groupListenerMap.has(group)) - this.groupListenerMap.get(group).forEach((listener) => { - const typedListener = listener[type]; + this.groupListenerMap.get(group).forEach((listenerObject) => { + const typedListener = listenerObject.listener[type]; // @ts-expect-error Dynamic events mapping. if (typedListener) typedListener(event); diff --git a/lib/core/components/listener_manager.js b/lib/core/components/listener_manager.js index 59072e7ed..86cd97953 100644 --- a/lib/core/components/listener_manager.js +++ b/lib/core/components/listener_manager.js @@ -27,8 +27,6 @@ class ListenerManager { * @param listener - Listener with event callbacks to handle different types of events. */ addListener(listener) { - if (this.listeners.includes(listener)) - return; this.listeners.push(listener); } /** @@ -37,7 +35,9 @@ class ListenerManager { * @param listener - Event listeners which should be removed. */ removeListener(listener) { - this.listeners = this.listeners.filter((storedListener) => storedListener !== listener); + const listenerIdx = this.listeners.indexOf(listener); + if (listenerIdx !== -1) + this.listeners.splice(listenerIdx, 1); } /** * Clear all real-time event listeners. diff --git a/lib/entities/SubscribeCapable.js b/lib/entities/SubscribeCapable.js index db295f50e..761f45d7a 100644 --- a/lib/entities/SubscribeCapable.js +++ b/lib/entities/SubscribeCapable.js @@ -40,7 +40,7 @@ class SubscribeCapable { * is received from the real-time network. */ set onMessage(onMessageListener) { - this.listener.message = onMessageListener; + this.typeBasedListener.message = onMessageListener; } /** * Set new presence events handler. @@ -49,7 +49,7 @@ class SubscribeCapable { * presence event is received from the real-time network. */ set onPresence(onPresenceListener) { - this.listener.presence = onPresenceListener; + this.typeBasedListener.presence = onPresenceListener; } /** * Set new signal handler. @@ -58,7 +58,7 @@ class SubscribeCapable { * is received from the real-time network. */ set onSignal(onSignalListener) { - this.listener.signal = onSignalListener; + this.typeBasedListener.signal = onSignalListener; } /** * Set new app context event handler. @@ -67,7 +67,7 @@ class SubscribeCapable { * app context event is received from the real-time network. */ set onObjects(onObjectsListener) { - this.listener.objects = onObjectsListener; + this.typeBasedListener.objects = onObjectsListener; } /** * Set new message reaction event handler. @@ -76,7 +76,7 @@ class SubscribeCapable { * new message reaction event is received from the real-time network. */ set onMessageAction(messageActionEventListener) { - this.listener.messageAction = messageActionEventListener; + this.typeBasedListener.messageAction = messageActionEventListener; } /** * Set new file handler. @@ -85,7 +85,7 @@ class SubscribeCapable { * is received from the real-time network. */ set onFile(fileEventListener) { - this.listener.file = fileEventListener; + this.typeBasedListener.file = fileEventListener; } /** * Set events handler. @@ -94,7 +94,10 @@ class SubscribeCapable { * types of events. */ addListener(listener) { - this.eventEmitter.addListener(listener, this.channelNames, this.groupNames); + if (this.aggregatedListener && this.aggregatedListener !== listener) + this.removeListener(this.aggregatedListener); + this.aggregatedListenerId = this.eventEmitter.addListener(listener, this.channelNames, this.groupNames); + this.aggregatedListener = listener; } /** * Remove events handler. @@ -104,7 +107,11 @@ class SubscribeCapable { * {@link addListener}. */ removeListener(listener) { - this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); + if (!this.aggregatedListener) + return; + this.eventEmitter.removeListener(listener, this.aggregatedListenerId, this.channelNames, this.groupNames); + this.aggregatedListenerId = undefined; + this.aggregatedListener = undefined; } /** * Get list of channels which is used for subscription. diff --git a/lib/entities/Subscription.js b/lib/entities/Subscription.js index 351271c8d..bed5ba5a2 100644 --- a/lib/entities/Subscription.js +++ b/lib/entities/Subscription.js @@ -65,8 +65,8 @@ class Subscription extends SubscribeCapable_1.SubscribeCapable { this.options = subscriptionOptions; this.pubnub = pubnub; this.eventEmitter = eventEmitter; - this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); + this.typeBasedListener = {}; + eventEmitter.addListener(this.typeBasedListener, this.channelNames, this.groupNames); } /** * Merge entities' subscription objects into subscription set. @@ -89,6 +89,8 @@ class Subscription extends SubscribeCapable_1.SubscribeCapable { subscription.subscribe(); subscription.subscribedAutomatically = true; // should be placed after .subscribe() call. } + if (this.aggregatedListener) + subscriptionSet.addListener(this.aggregatedListener); this.pubnub.registerSubscribeCapable(subscriptionSet); // @ts-expect-error: Required modification of protected field. subscriptionSet.subscribed = true; diff --git a/lib/entities/SubscriptionSet.js b/lib/entities/SubscriptionSet.js index 5df4547a5..ddb250708 100644 --- a/lib/entities/SubscriptionSet.js +++ b/lib/entities/SubscriptionSet.js @@ -86,8 +86,8 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.subscriptionList.push(subscription); }); - this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); + this.typeBasedListener = {}; + this.typeBasedListenerId = eventEmitter.addListener(this.typeBasedListener, this.channelNames, this.groupNames); } /** * Add additional entity's subscription to the subscription set. @@ -101,7 +101,9 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.subscriptionList.push(subscription); this.channelNames = [...this.channelNames, ...subscription.channels]; this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); + this.eventEmitter.addListener(this.typeBasedListener, subscription.channels, subscription.channelGroups, this.typeBasedListenerId); + // Make sure to listen events on channels / groups added with `subscription`. + this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. // @ts-expect-error: Required access of protected field. if (this.subscribed && !subscription.subscribed) { @@ -124,7 +126,9 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); - this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + // Make sure to stop listening for events from channels / groups removed with `subscription`. + this.updateListeners(); // @ts-expect-error: Required access of protected field. if (subscription.subscribedAutomatically) subscription.unsubscribe(); @@ -141,7 +145,9 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; - this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); + this.eventEmitter.addListener(this.typeBasedListener, subscriptionSet.channels, subscriptionSet.channelGroups, this.typeBasedListenerId); + // Make sure to listen events on channels / groups added with `subscription set`. + this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. if (this.subscribed && !subscriptionSet.subscribed) { subscriptionSet.subscribe(); @@ -162,7 +168,9 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); - this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + // Make sure to stop listening for events from channels / groups removed with `subscription set`. + this.updateListeners(); if (subscriptionSet.subscribedAutomatically) subscriptionSet.unsubscribe(); } @@ -174,5 +182,21 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { get subscriptions() { return this.subscriptionList.slice(0); } + /** + * Update listeners for current {@link SubscriptionSet} state. + * + * When {@link Subscription} or {@link SubscriptionSet} added / removed it is **required** to + * update mapping of channels / groups (based on current {@link SubscriptionSet} state) to the + * event listeners. + * + * @internal + */ + updateListeners() { + if (!this.aggregatedListener) + return; + const aggregatedListener = this.aggregatedListener; + this.removeListener(this.aggregatedListener); + this.addListener(aggregatedListener); + } } exports.SubscriptionSet = SubscriptionSet; diff --git a/lib/errors/pubnub-api-error.js b/lib/errors/pubnub-api-error.js index c3e76c213..bfe5d30b2 100644 --- a/lib/errors/pubnub-api-error.js +++ b/lib/errors/pubnub-api-error.js @@ -39,7 +39,7 @@ class PubNubAPIError extends Error { * available). */ static create(errorOrResponse, data) { - if (errorOrResponse instanceof Error) + if (PubNubAPIError.isErrorObject(errorOrResponse)) return PubNubAPIError.createFromError(errorOrResponse); else return PubNubAPIError.createFromServiceResponse(errorOrResponse, data); @@ -60,7 +60,7 @@ class PubNubAPIError extends Error { return new PubNubAPIError(message, category, 0); else if (error instanceof PubNubAPIError) return error; - if (error instanceof Error) { + if (PubNubAPIError.isErrorObject(error)) { message = error.message; errorName = error.name; } @@ -265,5 +265,33 @@ class PubNubAPIError extends Error { return value; }; } + /** + * Check whether provided `object` is an `Error` or not. + * + * This check is required because the error object may be tied to a different execution context (global + * environment) and won't pass `instanceof Error` from the main window. + * To protect against monkey-patching, the `fetch` function is taken from an invisible `iframe` and, as a result, + * it is bind to the separate execution context. Errors generated by `fetch` won't pass the simple + * `instanceof Error` test. + * + * @param object - Object which should be checked. + * + * @returns `true` if `object` looks like an `Error` object. + * + * @internal + */ + static isErrorObject(object) { + if (!object || typeof object !== 'object') + return false; + if (object instanceof Error) + return true; + if ('name' in object && + 'message' in object && + typeof object.name === 'string' && + typeof object.message === 'string') { + return true; + } + return Object.prototype.toString.call(object) === '[object Error]'; + } } exports.PubNubAPIError = PubNubAPIError; diff --git a/package-lock.json b/package-lock.json index e1e23a68e..1de135375 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "8.9.0", + "version": "9.0.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "8.9.0", + "version": "9.0.0", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", diff --git a/package.json b/package.json index c7668123a..c7d9246cb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "9.0.0", + "version": "9.1.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index cd4832970..fe5a95dc2 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -7,8 +7,8 @@ import { ExtendedConfiguration, PlatformConfiguration, PrivateClientConfiguration } from '../interfaces/configuration'; import { ICryptoModule, CryptorConfiguration } from '../interfaces/crypto-module'; import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; -import uuidGenerator from './uuid'; import { Payload } from '../types/api'; +import uuidGenerator from './uuid'; // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -178,7 +178,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '9.0.0'; + return '9.1.0'; }, getVersion(): string { return this.version; diff --git a/src/core/components/eventEmitter.ts b/src/core/components/eventEmitter.ts index 95d2a495b..c335ccd9a 100644 --- a/src/core/components/eventEmitter.ts +++ b/src/core/components/eventEmitter.ts @@ -7,6 +7,7 @@ import { Listener, ListenerManager } from './listener_manager'; import * as Subscription from '../types/api/subscription'; import { PubNubEventType } from '../endpoints/subscribe'; +import uuidGenerator from './uuid'; /** * Real-time events' emitter. @@ -20,12 +21,12 @@ export default class EventEmitter { /** * Map of channels to listener callbacks for them. */ - private readonly channelListenerMap: Map = new Map(); + private readonly channelListenerMap: Map = new Map(); /** * Map of channel group names to the listener callbacks for them. */ - private readonly groupListenerMap: Map = new Map(); + private readonly groupListenerMap: Map = new Map(); constructor(private readonly listenerManager: ListenerManager) {} @@ -116,10 +117,15 @@ export default class EventEmitter { * Register real-time event listener for specific channels and groups. * * @param listener - Listener with event callbacks to handle different types of events. - * @param channels - List of channels for which listener should be registered. - * @param groups - List of channel groups for which listener should be registered. + * @param [channels] - List of channels for which listener should be registered. + * @param [groups] - List of channel groups for which listener should be registered. + * @param [listenerId] - Unique listener identifier which is used to update previous setup. + * + * @returns Registered listener identifier. */ - public addListener(listener: Listener, channels?: string[], groups?: string[]) { + public addListener(listener: Listener, channels?: string[], groups?: string[], listenerId?: string): string { + listenerId ??= uuidGenerator.createUUID() as string; + // Register event-listener listener globally. if (!(channels && groups)) { this.listenerManager.addListener(listener); @@ -127,45 +133,48 @@ export default class EventEmitter { channels?.forEach((channel) => { if (this.channelListenerMap.has(channel)) { const channelListeners = this.channelListenerMap.get(channel)!; - if (!channelListeners.includes(listener)) channelListeners.push(listener); - } else this.channelListenerMap.set(channel, [listener]); + channelListeners.push({ id: listenerId, listener }); + } else this.channelListenerMap.set(channel, [{ id: listenerId, listener }]); }); groups?.forEach((group) => { if (this.groupListenerMap.has(group)) { const groupListeners = this.groupListenerMap.get(group)!; - if (!groupListeners.includes(listener)) groupListeners.push(listener); - } else this.groupListenerMap.set(group, [listener]); + groupListeners.push({ id: listenerId, listener }); + } else this.groupListenerMap.set(group, [{ id: listenerId, listener }]); }); } + + return listenerId; } /** * Remove real-time event listener. * * @param listener - Event listeners which should be removed. + * @param listenerId - Unique listener identifier assigned to it during addition. * @param channels - List of channels for which listener should be removed. * @param groups - List of channel groups for which listener should be removed. */ - public removeListener(listener: Listener, channels?: string[], groups?: string[]) { + public removeListener(listener: Listener, listenerId?: string, channels?: string[], groups?: string[]) { if (!(channels && groups)) { this.listenerManager.removeListener(listener); } else { channels?.forEach((channel) => { - if (this.channelListenerMap.has(channel)) { - this.channelListenerMap.set( - channel, - this.channelListenerMap.get(channel)!.filter((channelListener) => channelListener !== listener), - ); + const channelListeners = this.channelListenerMap.get(channel); + if (channelListeners) { + const listenerObject = channelListeners.find((listenerObject) => listenerObject.id === listenerId); + const listenerIdx = listenerObject ? channelListeners.indexOf(listenerObject) : -1; + if (listenerIdx !== -1) channelListeners.splice(listenerIdx, 1); } }); groups?.forEach((group) => { - if (this.groupListenerMap.has(group)) { - this.groupListenerMap.set( - group, - this.groupListenerMap.get(group)!.filter((groupListener) => groupListener !== listener), - ); + const groupListeners = this.groupListenerMap.get(group); + if (groupListeners) { + const listenerObject = groupListeners.find((listenerObject) => listenerObject.id === listenerId); + const listenerIdx = listenerObject ? groupListeners.indexOf(listenerObject) : -1; + if (listenerIdx !== -1) groupListeners.splice(listenerIdx, 1); } }); } @@ -195,15 +204,15 @@ export default class EventEmitter { group?: string | null, ) { if (event && this.channelListenerMap.has(channel)) - this.channelListenerMap.get(channel)!.forEach((listener) => { - const typedListener = listener[type]; + this.channelListenerMap.get(channel)!.forEach((listenerObject) => { + const typedListener = listenerObject.listener[type]; // @ts-expect-error Dynamic events mapping. if (typedListener) typedListener(event); }); if (group && this.groupListenerMap.has(group)) - this.groupListenerMap.get(group)!.forEach((listener) => { - const typedListener = listener[type]; + this.groupListenerMap.get(group)!.forEach((listenerObject) => { + const typedListener = listenerObject.listener[type]; // @ts-expect-error Dynamic events mapping. if (typedListener) typedListener(event); }); diff --git a/src/core/components/listener_manager.ts b/src/core/components/listener_manager.ts index dd8d56040..33c41c39b 100644 --- a/src/core/components/listener_manager.ts +++ b/src/core/components/listener_manager.ts @@ -110,8 +110,6 @@ export class ListenerManager { * @param listener - Listener with event callbacks to handle different types of events. */ public addListener(listener: Listener) { - if (this.listeners.includes(listener)) return; - this.listeners.push(listener); } @@ -121,7 +119,8 @@ export class ListenerManager { * @param listener - Event listeners which should be removed. */ public removeListener(listener: Listener) { - this.listeners = this.listeners.filter((storedListener) => storedListener !== listener); + const listenerIdx = this.listeners.indexOf(listener); + if (listenerIdx !== -1) this.listeners.splice(listenerIdx, 1); } /** diff --git a/src/entities/SubscribeCapable.ts b/src/entities/SubscribeCapable.ts index 7447117aa..5496b3096 100644 --- a/src/entities/SubscribeCapable.ts +++ b/src/entities/SubscribeCapable.ts @@ -33,6 +33,27 @@ export abstract class SubscribeCapable { */ protected abstract eventEmitter: EventEmitter; + /** + * Real-time events listener object associated with channels and groups of subscription object. + * + * Listener will be used to notify about updates received from the channels / groups. + * + * **Note:** this is different from {@link typeBasedListener} because it is passed as aggregated + * listener using {@link addListener} and {@link removeListener}. This listener will be passed to + * the added {@link Subscription} and {@link SubscriptionSet} if they will be added into already + * subscribed object. + * + * @internal + */ + protected abstract aggregatedListener?: Listener; + + /** + * Unique identifier of aggregated listener registered for subscribe capable object. + * + * @internal. + */ + protected abstract aggregatedListenerId?: string; + /** * Real-time events listener object associated with entity subscription object. * @@ -40,7 +61,7 @@ export abstract class SubscribeCapable { * * @internal */ - protected abstract listener: Listener; + protected abstract typeBasedListener: Listener; /** * PubNub instance which will perform subscribe / unsubscribe requests. @@ -112,7 +133,7 @@ export abstract class SubscribeCapable { * is received from the real-time network. */ set onMessage(onMessageListener: (messageEvent: Subscription.Message) => void) { - this.listener.message = onMessageListener; + this.typeBasedListener.message = onMessageListener; } /** @@ -122,7 +143,7 @@ export abstract class SubscribeCapable { * presence event is received from the real-time network. */ set onPresence(onPresenceListener: (presenceEvent: Subscription.Presence) => void) { - this.listener.presence = onPresenceListener; + this.typeBasedListener.presence = onPresenceListener; } /** @@ -132,7 +153,7 @@ export abstract class SubscribeCapable { * is received from the real-time network. */ set onSignal(onSignalListener: (signalEvent: Subscription.Signal) => void) { - this.listener.signal = onSignalListener; + this.typeBasedListener.signal = onSignalListener; } /** @@ -142,7 +163,7 @@ export abstract class SubscribeCapable { * app context event is received from the real-time network. */ set onObjects(onObjectsListener: (objectsEvent: Subscription.AppContextObject) => void) { - this.listener.objects = onObjectsListener; + this.typeBasedListener.objects = onObjectsListener; } /** @@ -152,7 +173,7 @@ export abstract class SubscribeCapable { * new message reaction event is received from the real-time network. */ set onMessageAction(messageActionEventListener: (messageActionEvent: Subscription.MessageAction) => void) { - this.listener.messageAction = messageActionEventListener; + this.typeBasedListener.messageAction = messageActionEventListener; } /** @@ -162,7 +183,7 @@ export abstract class SubscribeCapable { * is received from the real-time network. */ set onFile(fileEventListener: (fileEvent: Subscription.File) => void) { - this.listener.file = fileEventListener; + this.typeBasedListener.file = fileEventListener; } /** @@ -172,7 +193,9 @@ export abstract class SubscribeCapable { * types of events. */ addListener(listener: Listener) { - this.eventEmitter.addListener(listener, this.channelNames, this.groupNames); + if (this.aggregatedListener && this.aggregatedListener !== listener) this.removeListener(this.aggregatedListener); + this.aggregatedListenerId = this.eventEmitter.addListener(listener, this.channelNames, this.groupNames); + this.aggregatedListener = listener; } /** @@ -183,7 +206,11 @@ export abstract class SubscribeCapable { * {@link addListener}. */ removeListener(listener: Listener) { - this.eventEmitter.removeListener(listener, this.channelNames, this.groupNames); + if (!this.aggregatedListener) return; + + this.eventEmitter.removeListener(listener, this.aggregatedListenerId, this.channelNames, this.groupNames); + this.aggregatedListenerId = undefined; + this.aggregatedListener = undefined; } /** diff --git a/src/entities/Subscription.ts b/src/entities/Subscription.ts index f935532de..1bf32a71b 100644 --- a/src/entities/Subscription.ts +++ b/src/entities/Subscription.ts @@ -56,6 +56,27 @@ export class Subscription extends SubscribeCapable { */ protected eventEmitter: EventEmitter; + /** + * Real-time events listener object associated with channels and groups of subscription object. + * + * Listener will be used to notify about updates received from the channels / groups. + * + * **Note:** this is different from {@link typeBasedListener} because it is passed as aggregated + * listener using {@link addListener} and {@link removeListener}. This listener will be passed to + * the added {@link Subscription} and {@link SubscriptionSet} if they will be added into already + * subscribed object. + * + * @internal + */ + protected aggregatedListener?: Listener; + + /** + * Unique identifier of aggregated listener registered for subscribe capable object. + * + * @internal. + */ + protected aggregatedListenerId?: string; + /** * Real-time events listener object associated with entity subscription object. * @@ -63,7 +84,7 @@ export class Subscription extends SubscribeCapable { * * @internal */ - protected listener: Listener; + protected typeBasedListener: Listener; /** * Whether subscribed ({@link SubscribeCapable#subscribe}) automatically during subscription @@ -113,8 +134,8 @@ export class Subscription extends SubscribeCapable { this.options = subscriptionOptions; this.pubnub = pubnub; this.eventEmitter = eventEmitter; - this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); + this.typeBasedListener = {}; + eventEmitter.addListener(this.typeBasedListener, this.channelNames, this.groupNames); } /** @@ -140,6 +161,7 @@ export class Subscription extends SubscribeCapable { subscription.subscribedAutomatically = true; // should be placed after .subscribe() call. } + if (this.aggregatedListener) subscriptionSet.addListener(this.aggregatedListener); this.pubnub.registerSubscribeCapable(subscriptionSet); // @ts-expect-error: Required modification of protected field. subscriptionSet.subscribed = true; diff --git a/src/entities/SubscriptionSet.ts b/src/entities/SubscriptionSet.ts index a9cbdc603..c7e9c7996 100644 --- a/src/entities/SubscriptionSet.ts +++ b/src/entities/SubscriptionSet.ts @@ -68,6 +68,34 @@ export class SubscriptionSet extends SubscribeCapable { */ protected subscriptionList: Subscription[] = []; + /** + * Real-time events listener object associated with channels and groups of subscription object. + * + * Listener will be used to notify about updates received from the channels / groups. + * + * **Note:** this is different from {@link typeBasedListener} because it is passed as aggregated + * listener using {@link addListener} and {@link removeListener}. This listener will be passed to + * the added {@link Subscription} and {@link SubscriptionSet} if they will be added into already + * subscribed object. + * + * @internal + */ + protected aggregatedListener?: Listener; + + /** + * Unique identifier of aggregated listener registered for subscribe capable object. + * + * @internal. + */ + protected aggregatedListenerId?: string; + + /** + * Unique identifier of object associated listener. + * + * @internal. + */ + protected typeBasedListenerId: string; + /** * Real-time events listener object associated with entities' subscription objects. * @@ -75,7 +103,7 @@ export class SubscriptionSet extends SubscribeCapable { * * @internal */ - protected listener: Listener; + protected typeBasedListener: Listener; /** * Whether subscribed ({@link SubscribeCapable#subscribe}) automatically during subscription @@ -137,8 +165,8 @@ export class SubscriptionSet extends SubscribeCapable { this.groupNames = [...this.groupNames, ...subscription.channelGroups]; this.subscriptionList.push(subscription); }); - this.listener = {}; - eventEmitter.addListener(this.listener, this.channelNames, this.groupNames); + this.typeBasedListener = {}; + this.typeBasedListenerId = eventEmitter.addListener(this.typeBasedListener, this.channelNames, this.groupNames); } /** @@ -153,7 +181,15 @@ export class SubscriptionSet extends SubscribeCapable { this.subscriptionList.push(subscription); this.channelNames = [...this.channelNames, ...subscription.channels]; this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.eventEmitter.addListener(this.listener, subscription.channels, subscription.channelGroups); + this.eventEmitter.addListener( + this.typeBasedListener, + subscription.channels, + subscription.channelGroups, + this.typeBasedListenerId, + ); + + // Make sure to listen events on channels / groups added with `subscription`. + this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. // @ts-expect-error: Required access of protected field. @@ -178,7 +214,15 @@ export class SubscriptionSet extends SubscribeCapable { this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); - this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + this.eventEmitter.removeListener( + this.typeBasedListener, + this.typeBasedListenerId, + channelsToRemove, + groupsToRemove, + ); + + // Make sure to stop listening for events from channels / groups removed with `subscription`. + this.updateListeners(); // @ts-expect-error: Required access of protected field. if (subscription.subscribedAutomatically) subscription.unsubscribe(); @@ -196,7 +240,15 @@ export class SubscriptionSet extends SubscribeCapable { this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; - this.eventEmitter.addListener(this.listener, subscriptionSet.channels, subscriptionSet.channelGroups); + this.eventEmitter.addListener( + this.typeBasedListener, + subscriptionSet.channels, + subscriptionSet.channelGroups, + this.typeBasedListenerId, + ); + + // Make sure to listen events on channels / groups added with `subscription set`. + this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. if (this.subscribed && !subscriptionSet.subscribed) { @@ -219,7 +271,15 @@ export class SubscriptionSet extends SubscribeCapable { this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); - this.eventEmitter.removeListener(this.listener, channelsToRemove, groupsToRemove); + this.eventEmitter.removeListener( + this.typeBasedListener, + this.typeBasedListenerId, + channelsToRemove, + groupsToRemove, + ); + + // Make sure to stop listening for events from channels / groups removed with `subscription set`. + this.updateListeners(); if (subscriptionSet.subscribedAutomatically) subscriptionSet.unsubscribe(); } @@ -232,4 +292,21 @@ export class SubscriptionSet extends SubscribeCapable { get subscriptions(): Subscription[] { return this.subscriptionList.slice(0); } + + /** + * Update listeners for current {@link SubscriptionSet} state. + * + * When {@link Subscription} or {@link SubscriptionSet} added / removed it is **required** to + * update mapping of channels / groups (based on current {@link SubscriptionSet} state) to the + * event listeners. + * + * @internal + */ + private updateListeners() { + if (!this.aggregatedListener) return; + + const aggregatedListener = this.aggregatedListener; + this.removeListener(this.aggregatedListener); + this.addListener(aggregatedListener); + } } diff --git a/src/errors/pubnub-api-error.ts b/src/errors/pubnub-api-error.ts index e5bd7834f..6e7872982 100644 --- a/src/errors/pubnub-api-error.ts +++ b/src/errors/pubnub-api-error.ts @@ -27,7 +27,7 @@ export class PubNubAPIError extends Error { * available). */ static create(errorOrResponse: Error | TransportResponse, data?: ArrayBuffer): PubNubAPIError { - if (errorOrResponse instanceof Error) return PubNubAPIError.createFromError(errorOrResponse); + if (PubNubAPIError.isErrorObject(errorOrResponse)) return PubNubAPIError.createFromError(errorOrResponse); else return PubNubAPIError.createFromServiceResponse(errorOrResponse, data); } @@ -47,7 +47,7 @@ export class PubNubAPIError extends Error { if (!error) return new PubNubAPIError(message, category, 0); else if (error instanceof PubNubAPIError) return error; - if (error instanceof Error) { + if (PubNubAPIError.isErrorObject(error)) { message = error.message; errorName = error.name; } @@ -256,4 +256,34 @@ export class PubNubAPIError extends Error { return value; }; } + + /** + * Check whether provided `object` is an `Error` or not. + * + * This check is required because the error object may be tied to a different execution context (global + * environment) and won't pass `instanceof Error` from the main window. + * To protect against monkey-patching, the `fetch` function is taken from an invisible `iframe` and, as a result, + * it is bind to the separate execution context. Errors generated by `fetch` won't pass the simple + * `instanceof Error` test. + * + * @param object - Object which should be checked. + * + * @returns `true` if `object` looks like an `Error` object. + * + * @internal + */ + private static isErrorObject(object: unknown): object is Error { + if (!object || typeof object !== 'object') return false; + if (object instanceof Error) return true; + if ( + 'name' in object && + 'message' in object && + typeof object.name === 'string' && + typeof object.message === 'string' + ) { + return true; + } + + return Object.prototype.toString.call(object) === '[object Error]'; + } } diff --git a/src/transport/subscription-worker/subscription-worker-middleware.ts b/src/transport/subscription-worker/subscription-worker-middleware.ts index 10663c0c6..b2130a4ca 100644 --- a/src/transport/subscription-worker/subscription-worker-middleware.ts +++ b/src/transport/subscription-worker/subscription-worker-middleware.ts @@ -9,10 +9,12 @@ import { CancellationController, TransportRequest } from '../../core/types/transport-request'; import { TransportResponse } from '../../core/types/transport-response'; +import { TokenManager } from '../../core/components/token_manager'; import * as PubNubSubscriptionWorker from './subscription-worker'; import { PubNubAPIError } from '../../errors/pubnub-api-error'; import StatusCategory from '../../core/constants/categories'; import { Transport } from '../../core/interfaces/transport'; +import * as PAM from '../../core/types/api/access-manager'; // -------------------------------------------------------- // ------------------------ Types ------------------------- @@ -72,6 +74,11 @@ type PubNubMiddlewareConfiguration = { */ heartbeatInterval?: number; + /** + * REST API endpoints access tokens manager. + */ + tokenManager?: TokenManager; + /** * Platform-specific transport for requests processing. */ @@ -108,6 +115,17 @@ export class SubscriptionWorkerMiddleware implements Transport { */ subscriptionWorkerReady: boolean = false; + /** + * Map of base64-encoded access tokens to their parsed representations. + */ + accessTokensMap: Record< + string, + { + token: string; + expiration: number; + } + > = {}; + constructor(private readonly configuration: PubNubMiddlewareConfiguration) { this.workerEventsQueue = []; this.callbacks = new Map(); @@ -153,7 +171,9 @@ export class SubscriptionWorkerMiddleware implements Transport { this.callbacks!.set(req.identifier, { resolve, reject }); // Trigger request processing by Service Worker. - this.scheduleEventPost(sendRequestEvent); + this.parsedAccessTokenForRequest(req) + .then((accessToken) => (sendRequestEvent.token = accessToken)) + .then(() => this.scheduleEventPost(sendRequestEvent)); }), controller, ]; @@ -327,6 +347,74 @@ export class SubscriptionWorkerMiddleware implements Transport { } } + /** + * Get parsed access token object. + * + * @param req - Transport request which may contain access token for processing. + * + * @returns Object with stringified access token information and expiration date information. + */ + private async parsedAccessTokenForRequest(req: TransportRequest) { + const accessToken = req.queryParameters ? ((req.queryParameters.auth as string) ?? '') : undefined; + if (!accessToken) return undefined; + else if (this.accessTokensMap[accessToken]) return this.accessTokensMap[accessToken]; + + return this.stringifyAccessToken(accessToken).then(([token, stringifiedToken]) => { + if (!token || !stringifiedToken) return undefined; + + return (this.accessTokensMap = { + [accessToken]: { token: stringifiedToken, expiration: token.timestamp * token.ttl * 60 }, + })[accessToken]; + }); + } + + /** + * Stringify access token content. + * + * Stringify information about resources with permissions. + * + * @param tokenString - Base64-encoded access token which should be parsed and stringified. + * + * @returns Tuple with parsed access token and its stringified content hash string. + */ + private async stringifyAccessToken(tokenString: string): Promise<[PAM.Token | undefined, string | undefined]> { + if (!this.configuration.tokenManager) return [undefined, undefined]; + const token = this.configuration.tokenManager.parseToken(tokenString); + if (!token) return [undefined, undefined]; + + // Translate permission to short string built from first chars of enabled permission. + const stringifyPermissions = (permission: PAM.Permissions) => + Object.entries(permission) + .filter(([_, v]) => v) + .map(([k]) => k[0]) + .sort() + .join(''); + + const stringifyResources = (resource: PAM.Token['resources']) => + resource + ? Object.entries(resource) + .sort(([a], [b]) => a.localeCompare(b)) + .map(([type, entries]) => + Object.entries(entries || {}) + .sort(([a], [b]) => a.localeCompare(b)) + .map(([name, perms]) => `${type}:${name}=${perms ? stringifyPermissions(perms) : ''}`) + .join(','), + ) + .join(';') + : ''; + + let accessToken = [stringifyResources(token.resources), stringifyResources(token.patterns), token.authorized_uuid] + .filter(Boolean) + .join('|'); + + if (typeof crypto !== 'undefined' && crypto.subtle) { + const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(accessToken)); + accessToken = String.fromCharCode(...new Uint8Array(hash)); + } + + return [token, typeof btoa !== 'undefined' ? btoa(accessToken) : accessToken]; + } + /** * Print request progress information. * diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index bb379ee46..42ff91f2e 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -89,6 +89,11 @@ export type SendRequestEvent = BasicEvent & { * Instruction to construct actual {@link Request}. */ request: TransportRequest; + + /** + * Pre-processed access token (If set). + */ + token?: PubNubClientState['accessToken']; }; /** @@ -383,6 +388,16 @@ type PubNubClientState = { */ authKey?: string; + /** + * Aggregateable {@link authKey} representation. + * + * Representation based on information stored in `resources`, `patterns`, and `authorized_uuid`. + */ + accessToken?: { + token: string; + expiration: number; + }; + /** * Origin which is used to access PubNub REST API. */ @@ -1333,6 +1348,12 @@ const subscribeTransportRequestFromEvent = (event: SendRequestEvent): TransportR // Update request `state` (if required). if (Object.keys(aggregatedState).length) request.queryParameters!['state'] = JSON.stringify(aggregatedState); + + // Update `auth` key (if required). + if (request.queryParameters && request.queryParameters.auth) { + const authKey = authKeyForAggregatedClientsRequest(clients); + if (authKey) request.queryParameters.auth = authKey; + } } else { serviceRequests[serviceRequestId] = { requestId: serviceRequestId, @@ -1942,6 +1963,7 @@ const updateClientSubscribeStateIfRequired = (event: SendRequestEvent) => { client.origin = event.request.origin; client.userId = query.uuid as string; client.pnsdk = query.pnsdk as string; + client.accessToken = event.token; handleClientIdentityChangeIfRequired(client, userId, authKey); }; @@ -2056,7 +2078,7 @@ const invalidateClient = (subscriptionKey: string, clientId: string) => { const unsubscribeClient = (client: PubNubClientState) => { if (!client.subscription) return; - const { channels, channelGroups } = client.subscription; + const { channels, channelGroups, serviceRequestId } = client.subscription; const encodedChannelGroups = (channelGroups ?? []) .filter((name) => !name.endsWith('-pnpres')) .map((name) => encodeString(name)) @@ -2066,6 +2088,11 @@ const unsubscribeClient = (client: PubNubClientState) => { .map((name) => encodeString(name)) .sort(); + if (serviceRequestId) { + delete client.subscription.serviceRequestId; + cancelRequest(serviceRequestId); + } + if (encodedChannels.length === 0 && encodedChannelGroups.length === 0) return; const channelGroupsString: string | undefined = encodedChannelGroups.length > 0 ? encodedChannelGroups.join(',') : undefined; @@ -2195,15 +2222,18 @@ const hasClientsForSendAggregatedSubscribeRequestEvent = (client: PubNubClientSt * @returns List of PubNub client states which works from other pages for the same user. */ const clientsForSendSubscribeRequestEvent = (timetoken: string, event: SendRequestEvent) => { + const reqClient = pubNubClients[event.clientIdentifier]; + if (!reqClient) return []; + const query = event.request.queryParameters!; + const authKey = clientAggregateAuthKey(reqClient); const filterExpression = (query['filter-expr'] ?? '') as string; - const authKey = (query.auth ?? '') as string; const userId = query.uuid! as string; return (pubNubClientsBySubscriptionKey[event.subscriptionKey] ?? []).filter( (client) => client.userId === userId && - client.authKey === authKey && + clientAggregateAuthKey(client) === authKey && client.subscription && // Only clients with active subscription can be used. (client.subscription.channels.length !== 0 || client.subscription.channelGroups.length !== 0) && @@ -2241,12 +2271,15 @@ const clientsForSendHeartbeatRequestEvent = (event: SendRequestEvent) => { * @returns List of PubNub client states which works from other pages for the same user. */ const clientsForSendLeaveRequestEvent = (event: SendRequestEvent) => { + const reqClient = pubNubClients[event.clientIdentifier]; + if (!reqClient) return []; + const query = event.request.queryParameters!; - const authKey = (query.auth ?? '') as string; + const authKey = reqClient.authKey; const userId = query.uuid! as string; return (pubNubClientsBySubscriptionKey[event.subscriptionKey] ?? []).filter( - (client) => client.userId === userId && client.authKey === authKey, + (client) => client.userId === userId && clientAggregateAuthKey(client) === authKey, ); }; @@ -2330,6 +2363,33 @@ const pingClients = (subscriptionKey: string) => { } }; +/** + * Retrieve auth key which is suitable for common clients request aggregation. + * + * @param client - Client for which auth key for aggregation should be retrieved. + * + * @returns Client aggregation auth key. + */ +const clientAggregateAuthKey = (client: PubNubClientState): string | undefined => { + return client.accessToken ? (client.accessToken.token ?? client.authKey) : client.authKey; +}; + +/** + * Pick auth key for clients with latest expiration date. + * + * @param clients - List of clients for which latest auth key should be retrieved. + * + * @returns Access token which can be used to confirm `userId` permissions for aggregated request. + */ +const authKeyForAggregatedClientsRequest = (clients: PubNubClientState[]) => { + const latestClient = clients + .filter((client) => !!client.accessToken) + .sort((a, b) => a.accessToken!.expiration - b.accessToken!.expiration) + .pop(); + + return latestClient ? latestClient.authKey : undefined; +}; + /** * Compose clients' aggregation key. * @@ -2340,7 +2400,8 @@ const pingClients = (subscriptionKey: string) => { * @returns Aggregation timeout identifier string. */ const aggregateTimerId = (client: PubNubClientState) => { - let id = `${client.userId}-${client.subscriptionKey}${client.authKey ? `-${client.authKey}` : ''}`; + const authKey = clientAggregateAuthKey(client); + let id = `${client.userId}-${client.subscriptionKey}${authKey ? `-${authKey}` : ''}`; if (client.subscription && client.subscription.filterExpression) id += `-${client.subscription.filterExpression}`; return id; }; diff --git a/src/web/index.ts b/src/web/index.ts index b94035f5e..3c41fdc08 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -112,6 +112,7 @@ export default class PubNub extends PubNubCore { { 'content-type': 'text/javascript' }, ); const messages: Subscription.Message[] = []; - const channel = pubnub.channel('ch1'); - const subscription = channel.subscription(); + const subscription = pubnub.channel('ch1').subscription(); const listener = { message: (m: Subscription.Message) => messages.push(m) }; subscription.addListener(listener); - const messagePromise = new Promise((resolveMessage) => + const messagePromise = new Promise((resolveMessage) => { + subscription.removeListener(listener); subscription.addListener({ message: (m) => resolveMessage(m), - }), - ); - subscription.removeListener(listener); + }); + }); subscription.subscribe(); const actual = await messagePromise; expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); @@ -441,12 +442,12 @@ describe('#listeners', () => { const subscription = channel.subscription(); const listener = { message: (m: Subscription.Message) => messages.push(m) }; subscription.addListener(listener); - const messagePromise = new Promise((resolveMessage) => + const messagePromise = new Promise((resolveMessage) => { + subscription.removeListener(listener); subscription.addListener({ message: (m) => resolveMessage(m), - }), - ); - subscription.removeListener(listener); + }); + }); subscription.subscribe(); const actual = await messagePromise; expect(JSON.stringify(actual.message)).to.equal('{"message":"My message!"}'); From 36e0ec3afe5d22e9aecd6ef6bee81e56dd8289da Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Wed, 19 Mar 2025 13:20:09 +0200 Subject: [PATCH 42/49] Fix Shared Worker state update on presence change and listen for `pagehide` (#445) feat(shared-worker): early request terminate on pagehide On `pagehide` without `bfcache` client on page will send `terminate` to Shared Worker for early long-poll request termination and `leave` request sending (if configured). fix(presence): fix channels and groups update in Shared worker Fix an issue with the client's state update in Shared Worker caused by `-pnpres` suffixed entries being removed from heartbeat / leave request channels and groups. --- .pubnub.yml | 13 +- CHANGELOG.md | 9 + README.md | 4 +- dist/web/pubnub.js | 48 ++++-- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 140 ++++++++++------ dist/web/pubnub.worker.min.js | 2 +- lib/core/components/configuration.js | 6 +- lib/core/pubnub-common.js | 22 ++- package-lock.json | 4 +- package.json | 2 +- src/core/components/configuration.ts | 6 +- src/core/interfaces/configuration.ts | 9 + src/core/pubnub-common.ts | 16 +- .../subscription-worker-middleware.ts | 14 +- .../subscription-worker.ts | 156 +++++++++++++----- src/web/index.ts | 7 +- 17 files changed, 337 insertions(+), 125 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index cd04a7dcf..82c495668 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2025-03-19 + version: v9.2.0 + changes: + - type: feature + text: "On `pagehide` without `bfcache` client on page will send `terminate` to Shared Worker for early long-poll request termination and `leave` request sending (if configured)." + - type: bug + text: "Fix an issue with the client's state update in Shared Worker caused by `-pnpres` suffixed entries being removed from heartbeat / leave request channels and groups." - date: 2025-03-13 version: v9.1.0 changes: @@ -1178,7 +1185,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '9.1.0' +version: '9.2.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1194,7 +1201,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v9.1.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.2.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1865,7 +1872,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v9.1.0/pubnub.9.1.0.js + location: https://github.com/pubnub/javascript/releases/download/v9.2.0/pubnub.9.2.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index eae01bdb0..899dbdbc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v9.2.0 +March 19 2025 + +#### Added +- On `pagehide` without `bfcache` client on page will send `terminate` to Shared Worker for early long-poll request termination and `leave` request sending (if configured). + +#### Fixed +- Fix an issue with the client's state update in Shared Worker caused by `-pnpres` suffixed entries being removed from heartbeat / leave request channels and groups. + ## v9.1.0 March 13 2025 diff --git a/README.md b/README.md index aba9f1740..acc66d9c7 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.1.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.1.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.2.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.2.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index fe48c8961..24c7f6f5a 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3179,6 +3179,17 @@ this.callbacks = new Map(); this.setupSubscriptionWorker(); } + /** + * Terminate all ongoing long-poll requests. + */ + terminate() { + this.scheduleEventPost({ + type: 'client-unregister', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + logVerbosity: this.configuration.logVerbosity, + }); + } makeSendable(req) { // Use default request flow for non-subscribe / presence leave requests. if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/heartbeat') && !req.path.endsWith('/leave')) @@ -3430,7 +3441,7 @@ .join('|'); if (typeof crypto !== 'undefined' && crypto.subtle) { const hash = yield crypto.subtle.digest('SHA-256', new TextEncoder().encode(accessToken)); - accessToken = String.fromCharCode(...new Uint8Array(hash)); + accessToken = String.fromCharCode(...Array.from(new Uint8Array(hash))); } return [token, typeof btoa !== 'undefined' ? btoa(accessToken) : accessToken]; }); @@ -3891,6 +3902,10 @@ getUseRandomIVs() { return base.useRandomIVs; }, + getKeepPresenceChannelsInPresenceRequests() { + // @ts-expect-error: Access field from web-based SDK configuration. + return base.sdkFamily === 'Web' && base['subscriptionWorkerUrl']; + }, setPresenceTimeout(value) { this.heartbeatInterval = value / 2 - 1; this.presenceTimeout = value; @@ -3917,7 +3932,7 @@ return base.PubNubFile; }, get version() { - return '9.1.0'; + return '9.2.0'; }, getVersion() { return this.version; @@ -13593,10 +13608,13 @@ { // Filtering out presence channels and groups. let { channels, channelGroups } = parameters; - if (channelGroups) - channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); - if (channels) - channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + // Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration. + if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) { + if (channelGroups) + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + } // Complete immediately request only for presence channels. if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) { return callback({ @@ -13959,10 +13977,13 @@ { // Filtering out presence channels and groups. let { channels, channelGroups } = parameters; - if (channelGroups) - channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); - if (channels) - channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + // Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration. + if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) { + if (channelGroups) + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + } // Complete immediately request only for presence channels. if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) { const responseStatus = { @@ -14789,7 +14810,7 @@ { if (configurationCopy.subscriptionWorkerUrl) { // Inject subscription worker into transport provider stack. - transport = new SubscriptionWorkerMiddleware({ + const middleware = new SubscriptionWorkerMiddleware({ clientIdentifier: clientConfiguration._instanceId, subscriptionKey: clientConfiguration.subscribeKey, userId: clientConfiguration.getUserId(), @@ -14803,6 +14824,11 @@ tokenManager, transport, }); + transport = middleware; + window.onpagehide = (event) => { + if (!event.persisted) + middleware.terminate(); + }; } } const transportMiddleware = new PubNubMiddleware({ diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index e1022274c..c2969bda7 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),O=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],O=e[i+15],E=t(E=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,E,P,N,o,12,u[1]),N=t(N,C,E,P,l,17,u[2]),P=t(P,N,C,E,h,22,u[3]);E=t(E,P,N,C,d,7,u[4]),C=t(C,E,P,N,p,12,u[5]),N=t(N,C,E,P,g,17,u[6]),P=t(P,N,C,E,y,22,u[7]),E=t(E,P,N,C,f,7,u[8]),C=t(C,E,P,N,b,12,u[9]),N=t(N,C,E,P,m,17,u[10]),P=t(P,N,C,E,v,22,u[11]),E=t(E,P,N,C,w,7,u[12]),C=t(C,E,P,N,S,12,u[13]),N=t(N,C,E,P,k,17,u[14]),E=n(E,P=t(P,N,C,E,O,22,u[15]),N,C,o,5,u[16]),C=n(C,E,P,N,g,9,u[17]),N=n(N,C,E,P,v,14,u[18]),P=n(P,N,C,E,c,20,u[19]),E=n(E,P,N,C,p,5,u[20]),C=n(C,E,P,N,m,9,u[21]),N=n(N,C,E,P,O,14,u[22]),P=n(P,N,C,E,d,20,u[23]),E=n(E,P,N,C,b,5,u[24]),C=n(C,E,P,N,k,9,u[25]),N=n(N,C,E,P,h,14,u[26]),P=n(P,N,C,E,f,20,u[27]),E=n(E,P,N,C,S,5,u[28]),C=n(C,E,P,N,l,9,u[29]),N=n(N,C,E,P,y,14,u[30]),E=s(E,P=n(P,N,C,E,w,20,u[31]),N,C,p,4,u[32]),C=s(C,E,P,N,f,11,u[33]),N=s(N,C,E,P,v,16,u[34]),P=s(P,N,C,E,k,23,u[35]),E=s(E,P,N,C,o,4,u[36]),C=s(C,E,P,N,d,11,u[37]),N=s(N,C,E,P,y,16,u[38]),P=s(P,N,C,E,m,23,u[39]),E=s(E,P,N,C,S,4,u[40]),C=s(C,E,P,N,c,11,u[41]),N=s(N,C,E,P,h,16,u[42]),P=s(P,N,C,E,g,23,u[43]),E=s(E,P,N,C,b,4,u[44]),C=s(C,E,P,N,w,11,u[45]),N=s(N,C,E,P,O,16,u[46]),E=r(E,P=s(P,N,C,E,l,23,u[47]),N,C,c,6,u[48]),C=r(C,E,P,N,y,10,u[49]),N=r(N,C,E,P,k,15,u[50]),P=r(P,N,C,E,p,21,u[51]),E=r(E,P,N,C,w,6,u[52]),C=r(C,E,P,N,h,10,u[53]),N=r(N,C,E,P,m,15,u[54]),P=r(P,N,C,E,o,21,u[55]),E=r(E,P,N,C,f,6,u[56]),C=r(C,E,P,N,O,10,u[57]),N=r(N,C,E,P,g,15,u[58]),P=r(P,N,C,E,S,21,u[59]),E=r(E,P,N,C,d,6,u[60]),C=r(C,E,P,N,v,10,u[61]),N=r(N,C,E,P,l,15,u[62]),P=r(P,N,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=j.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=j.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===j.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=j.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class j{static from(e,t){if(e!==j.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==j.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>j.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+j.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(s),a)}}j.SENTINEL="PNED",j.LEGACY_IDENTIFIER="",j.IDENTIFIER_LENGTH=4,j.VERSION=1,j.MAX_VERSION=1,j.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return j.VERSION}get length(){return j.SENTINEL.length+1+j.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(j.SENTINEL)),e+=j.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=j.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...new Uint8Array(e))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,O=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(O=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:O,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.1.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),je=ge("HEARTBEAT_GIVEUP",(()=>({}))),Ae=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Ae())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(je());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(Ae.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(je.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class jt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class At extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){if(!this.aggregatedListener)return;const e=this.aggregatedListener;this.removeListener(this.aggregatedListener),this.addListener(e)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class jn{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=jn.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new At({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new jt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres")))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new jt(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}jn.decoder=new TextDecoder,jn.OPERATIONS=ie,jn.CATEGORIES=h,jn.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,jn.LinearRetryPolicy=Be.LinearRetryPolicy;class An{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends jn{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new An((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);n.subscriptionWorkerUrl&&(h=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h}));super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),O=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],O=e[i+15],E=t(E=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,E,P,N,o,12,u[1]),N=t(N,C,E,P,l,17,u[2]),P=t(P,N,C,E,h,22,u[3]);E=t(E,P,N,C,d,7,u[4]),C=t(C,E,P,N,p,12,u[5]),N=t(N,C,E,P,g,17,u[6]),P=t(P,N,C,E,y,22,u[7]),E=t(E,P,N,C,f,7,u[8]),C=t(C,E,P,N,b,12,u[9]),N=t(N,C,E,P,m,17,u[10]),P=t(P,N,C,E,v,22,u[11]),E=t(E,P,N,C,w,7,u[12]),C=t(C,E,P,N,S,12,u[13]),N=t(N,C,E,P,k,17,u[14]),E=n(E,P=t(P,N,C,E,O,22,u[15]),N,C,o,5,u[16]),C=n(C,E,P,N,g,9,u[17]),N=n(N,C,E,P,v,14,u[18]),P=n(P,N,C,E,c,20,u[19]),E=n(E,P,N,C,p,5,u[20]),C=n(C,E,P,N,m,9,u[21]),N=n(N,C,E,P,O,14,u[22]),P=n(P,N,C,E,d,20,u[23]),E=n(E,P,N,C,b,5,u[24]),C=n(C,E,P,N,k,9,u[25]),N=n(N,C,E,P,h,14,u[26]),P=n(P,N,C,E,f,20,u[27]),E=n(E,P,N,C,S,5,u[28]),C=n(C,E,P,N,l,9,u[29]),N=n(N,C,E,P,y,14,u[30]),E=s(E,P=n(P,N,C,E,w,20,u[31]),N,C,p,4,u[32]),C=s(C,E,P,N,f,11,u[33]),N=s(N,C,E,P,v,16,u[34]),P=s(P,N,C,E,k,23,u[35]),E=s(E,P,N,C,o,4,u[36]),C=s(C,E,P,N,d,11,u[37]),N=s(N,C,E,P,y,16,u[38]),P=s(P,N,C,E,m,23,u[39]),E=s(E,P,N,C,S,4,u[40]),C=s(C,E,P,N,c,11,u[41]),N=s(N,C,E,P,h,16,u[42]),P=s(P,N,C,E,g,23,u[43]),E=s(E,P,N,C,b,4,u[44]),C=s(C,E,P,N,w,11,u[45]),N=s(N,C,E,P,O,16,u[46]),E=r(E,P=s(P,N,C,E,l,23,u[47]),N,C,c,6,u[48]),C=r(C,E,P,N,y,10,u[49]),N=r(N,C,E,P,k,15,u[50]),P=r(P,N,C,E,p,21,u[51]),E=r(E,P,N,C,w,6,u[52]),C=r(C,E,P,N,h,10,u[53]),N=r(N,C,E,P,m,15,u[54]),P=r(P,N,C,E,o,21,u[55]),E=r(E,P,N,C,f,6,u[56]),C=r(C,E,P,N,O,10,u[57]),N=r(N,C,E,P,g,15,u[58]),P=r(P,N,C,E,S,21,u[59]),E=r(E,P,N,C,d,6,u[60]),C=r(C,E,P,N,v,10,u[61]),N=r(N,C,E,P,l,15,u[62]),P=r(P,N,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,O=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(O=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:O,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.2.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){if(!this.aggregatedListener)return;const e=this.aggregatedListener;this.removeListener(this.aggregatedListener),this.addListener(e)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends An{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index d7245c48c..39953a7c1 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -153,7 +153,7 @@ */ const subscribeAggregationTimeout = 50; /** - * Map of PubNub client subscription keys to the started aggregation timeout timers. + * Map of clients aggregation keys to the started aggregation timeout timers with client and event information. */ const aggregationTimers = new Map(); // region State @@ -232,6 +232,8 @@ registerClientIfRequired(data); consoleLog(`Client '${data.clientIdentifier}' registered with '${sharedWorkerIdentifier}' shared worker`); } + else if (data.type === 'client-unregister') + unRegisterClient(data); else if (data.type === 'client-pong') handleClientPong(data); else if (data.type === 'send-request') { @@ -241,19 +243,19 @@ if (client) { // Check whether there are more clients which may schedule next subscription loop and they need to be // aggregated or not. - if (hasClientsForSendAggregatedSubscribeRequestEvent(client, data)) { - const timerIdentifier = aggregateTimerId(client); - // Check whether we need to start new aggregation timer or not. - if (!aggregationTimers.has(timerIdentifier)) { - const aggregationTimer = setTimeout(() => { - handleSendSubscribeRequestEvent(data); - aggregationTimers.delete(timerIdentifier); - }, subscribeAggregationTimeout); - aggregationTimers.set(timerIdentifier, aggregationTimer); - } + const timerIdentifier = aggregateTimerId(client); + let enqueuedClients = []; + if (aggregationTimers.has(timerIdentifier)) + enqueuedClients = aggregationTimers.get(timerIdentifier)[0]; + enqueuedClients.push([client, data]); + // Check whether we need to start new aggregation timer or not. + if (!aggregationTimers.has(timerIdentifier)) { + const aggregationTimer = setTimeout(() => { + handleSendSubscribeRequestEventForClients(enqueuedClients, data); + aggregationTimers.delete(timerIdentifier); + }, subscribeAggregationTimeout); + aggregationTimers.set(timerIdentifier, [enqueuedClients, aggregationTimer]); } - else - handleSendSubscribeRequestEvent(data); } } else if (data.request.path.endsWith('/heartbeat')) { @@ -270,20 +272,37 @@ }); }; /** - * Handle client request to send subscription request. + * Handle aggregated clients request to send subscription request. * + * @param clients - List of aggregated clients which would like to send subscription requests. * @param event - Subscription event details. */ - const handleSendSubscribeRequestEvent = (event) => { - var _a; + const handleSendSubscribeRequestEventForClients = (clients, event) => { const requestOrId = subscribeTransportRequestFromEvent(event); const client = pubNubClients[event.clientIdentifier]; + if (!client) + return; + // Getting rest of aggregated clients. + clients = clients.filter((aggregatedClient) => aggregatedClient[0].clientIdentifier !== client.clientIdentifier); + handleSendSubscribeRequestForClient(client, event, requestOrId, true); + clients.forEach(([aggregatedClient, clientEvent]) => handleSendSubscribeRequestForClient(aggregatedClient, clientEvent, requestOrId, false)); + }; + /** + * Handle subscribe request by single client. + * + * @param client - Client which processes `request`. + * @param event - Subscription event details. + * @param requestOrId - New aggregated request object or its identifier (if already scheduled). + * @param requestOrigin - Whether `client` is the one who triggered subscribe request or not. + */ + const handleSendSubscribeRequestForClient = (client, event, requestOrId, requestOrigin) => { + var _a; let isInitialSubscribe = false; - if (client) { - if (client.subscription) - isInitialSubscribe = client.subscription.timetoken === '0'; - notifyRequestProcessing('start', [client], new Date().toISOString(), event.request); - } + if (!requestOrigin && typeof requestOrId !== 'string') + requestOrId = requestOrId.identifier; + if (client.subscription) + isInitialSubscribe = client.subscription.timetoken === '0'; + notifyRequestProcessing('start', [client], new Date().toISOString(), event.request); if (typeof requestOrId === 'string') { const scheduledRequest = serviceRequests[requestOrId]; if (client) { @@ -382,7 +401,7 @@ const request = heartbeatTransportRequestFromEvent(event); if (!client) return; - const heartbeatRequestKey = `${client.userId}_${(_a = client.authKey) !== null && _a !== void 0 ? _a : ''}`; + const heartbeatRequestKey = `${client.userId}_${(_a = clientAggregateAuthKey(client)) !== null && _a !== void 0 ? _a : ''}`; const hbRequestsBySubscriptionKey = serviceHeartbeatRequests[client.subscriptionKey]; const hbRequests = (hbRequestsBySubscriptionKey !== null && hbRequestsBySubscriptionKey !== void 0 ? hbRequestsBySubscriptionKey : {})[heartbeatRequestKey]; notifyRequestProcessing('start', [client], new Date().toISOString(), request); @@ -526,13 +545,14 @@ } if (!request || !clientWithRequest) return; - handleSendSubscribeRequestEvent({ + const sendRequest = { type: 'send-request', clientIdentifier: clientWithRequest.clientIdentifier, subscriptionKey: clientWithRequest.subscriptionKey, logVerbosity: clientWithRequest.logVerbosity, request, - }); + }; + handleSendSubscribeRequestEventForClients([[clientWithRequest, sendRequest]], sendRequest); }; // endregion // -------------------------------------------------------- @@ -816,7 +836,7 @@ if (!client || !client.heartbeat) return undefined; const hbRequestsBySubscriptionKey = ((_a = serviceHeartbeatRequests[_e = client.subscriptionKey]) !== null && _a !== void 0 ? _a : (serviceHeartbeatRequests[_e] = {})); - const heartbeatRequestKey = `${client.userId}_${(_b = client.authKey) !== null && _b !== void 0 ? _b : ''}`; + const heartbeatRequestKey = `${client.userId}_${(_b = clientAggregateAuthKey(client)) !== null && _b !== void 0 ? _b : ''}`; const channelGroupsForAnnouncement = client.heartbeat.channelGroups; const channelsForAnnouncement = client.heartbeat.channels; let aggregatedState; @@ -882,6 +902,12 @@ request.queryParameters['state'] = JSON.stringify(aggregatedState); else delete request.queryParameters['state']; + // Update `auth` key (if required). + if (clients.length > 1 && request.queryParameters && request.queryParameters.auth) { + const aggregatedAuthKey = authKeyForAggregatedClientsRequest(clients); + if (aggregatedAuthKey) + request.queryParameters.auth = aggregatedAuthKey; + } return request; }; /** @@ -924,10 +950,15 @@ if (client.clientIdentifier === event.clientIdentifier) continue; if (channels.length) - channels = channels.filter((channel) => !subscription.channels.includes(channel)); + channels = channels.filter((channel) => !channel.endsWith('-pnpres') && !subscription.channels.includes(channel)); if (channelGroups.length) - channelGroups = channelGroups.filter((group) => !subscription.channelGroups.includes(group)); + channelGroups = channelGroups.filter((group) => !group.endsWith('-pnpres') && !subscription.channelGroups.includes(group)); } + // Clean up from presence channels and groups + if (channels.length) + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + if (channelGroups.length) + channelGroups = channelGroups.filter((group) => !group.endsWith('-pnpres')); if (channels.length === 0 && channelGroups.length === 0) { if (client && client.workerLogVerbosity) { const clientIds = clients @@ -949,6 +980,12 @@ // Update request channel groups list (if required). if (channelGroups.length) request.queryParameters['channel-group'] = channelGroups.join(','); + // Update `auth` key (if required). + if (clients.length > 1 && request.queryParameters && request.queryParameters.auth) { + const aggregatedAuthKey = authKeyForAggregatedClientsRequest(clients); + if (aggregatedAuthKey) + request.queryParameters.auth = aggregatedAuthKey; + } return request; }; /** @@ -1215,9 +1252,20 @@ const interval = event.workerOfflineClientsCheckInterval; for (const _client of clientsBySubscriptionKey) consoleLog(`Setup PubNub client ping event ${interval} seconds`, _client); - pingTimeouts[event.subscriptionKey] = setTimeout(() => pingClients(subscriptionKey), interval * 500 - 1); + pingTimeouts[subscriptionKey] = setTimeout(() => pingClients(subscriptionKey), interval * 500 - 1); } }; + /** + * Unregister client if it uses Service Worker before. + * + * During registration removal client information will be removed from the Shared Worker and + * long-poll request will be cancelled if possible. + * + * @param event - Base information about PubNub client instance and Service Worker {@link Client}. + */ + const unRegisterClient = (event) => { + invalidateClient(event.subscriptionKey, event.clientIdentifier); + }; /** * Update information about previously registered client. * @@ -1333,11 +1381,11 @@ * @param authKey - `authKey` which has been used by `PubNub` client before state refresh. */ const handleClientIdentityChangeIfRequired = (client, userId, authKey) => { - var _a, _b; + var _a, _b, _c; if (!client || (userId === client.userId && (authKey !== null && authKey !== void 0 ? authKey : '') === ((_a = client.authKey) !== null && _a !== void 0 ? _a : ''))) return; const _heartbeatRequests = (_b = serviceHeartbeatRequests[client.subscriptionKey]) !== null && _b !== void 0 ? _b : {}; - const heartbeatRequestKey = `${userId}_${authKey !== null && authKey !== void 0 ? authKey : ''}`; + const heartbeatRequestKey = `${userId}_${(_c = clientAggregateAuthKey(client)) !== null && _c !== void 0 ? _c : ''}`; if (_heartbeatRequests[heartbeatRequestKey] !== undefined) delete _heartbeatRequests[heartbeatRequestKey]; }; @@ -1365,8 +1413,18 @@ delete pubNubClients[clientId]; let clients = pubNubClientsBySubscriptionKey[subscriptionKey]; // Unsubscribe invalidated PubNub client. - if (invalidatedClient && invalidatedClient.unsubscribeOfflineClients) - unsubscribeClient(invalidatedClient); + if (invalidatedClient) { + // Cancel long-poll request if possible. + if (invalidatedClient.subscription) { + const { serviceRequestId } = invalidatedClient.subscription; + delete invalidatedClient.subscription.serviceRequestId; + if (serviceRequestId) + cancelRequest(serviceRequestId); + } + // Leave subscribed channels / groups properly. + if (invalidatedClient.unsubscribeOfflineClients) + unsubscribeClient(invalidatedClient); + } if (clients) { // Clean up linkage between client and subscription key. clients = clients.filter((client) => client.clientIdentifier !== clientId); @@ -1410,10 +1468,6 @@ .filter((name) => !name.endsWith('-pnpres')) .map((name) => encodeString(name)) .sort(); - if (serviceRequestId) { - delete client.subscription.serviceRequestId; - cancelRequest(serviceRequestId); - } if (encodedChannels.length === 0 && encodedChannelGroups.length === 0) return; const channelGroupsString = encodedChannelGroups.length > 0 ? encodedChannelGroups.join(',') : undefined; @@ -1494,18 +1548,6 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' } return undefined; }; - /** - * Check whether there are any clients which can be used for subscribe request aggregation or not. - * - * @param client - PubNub client state which will be checked. - * @param event - Send subscribe request event information. - * - * @returns `true` in case there is more than 1 client which has same parameters for subscribe request to aggregate. - */ - const hasClientsForSendAggregatedSubscribeRequestEvent = (client, event) => { - var _a, _b; - return clientsForSendSubscribeRequestEvent((_b = ((_a = client.subscription) !== null && _a !== void 0 ? _a : {}).timetoken) !== null && _b !== void 0 ? _b : '0', event).length > 1; - }; /** * Find PubNub client states with configuration compatible with the one in request. * @@ -1572,7 +1614,7 @@ which has started by '${client.clientIdentifier}' client. Waiting for existing ' if (!reqClient) return []; const query = event.request.queryParameters; - const authKey = reqClient.authKey; + const authKey = clientAggregateAuthKey(reqClient); const userId = query.uuid; return ((_a = pubNubClientsBySubscriptionKey[event.subscriptionKey]) !== null && _a !== void 0 ? _a : []).filter((client) => client.userId === userId && clientAggregateAuthKey(client) === authKey); }; diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index caebba97d..03063e8ab 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((r=r.apply(e,t||[])).next())}))}var t;"function"==typeof SuppressedError&&SuppressedError,function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(t||(t={}));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r,i,s={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},v={},y={};self.onconnect=e=>{ie("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!J(t))return;const n=t.data;if("client-register"===n.type)n.port=e,D(n),ie(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-pong"===n.type)N(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){F(n);const e=h[n.clientIdentifier];if(e)if(_(e,n)){const t=re(e);if(!l.has(t)){const e=setTimeout((()=>{q(n),l.delete(t)}),50);l.set(t,e)}}else q(n)}else n.request.path.endsWith("/heartbeat")?(U(n),m(n)):w(n);else"cancel-request"===n.type&&k(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=e=>{var t;const n=K(e),r=h[e.clientIdentifier];let i=!1;if(r&&(r.subscription&&(i="0"===r.subscription.timetoken),x("start",[r],(new Date).toISOString(),e.request)),"string"==typeof n){const s=y[n];if(r){if(r.subscription&&(r.subscription.timetoken=s.timetoken,r.subscription.region=s.region,r.subscription.serviceRequestId=n),!i)return;const o=(new TextEncoder).encode(`{"t":{"t":"${s.timetoken}","r":${null!==(t=s.region)&&void 0!==t?t:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${e.request.origin}${e.request.path}`,u.clientIdentifier=e.clientIdentifier,u.identifier=e.request.identifier,x("end",[r],(new Date).toISOString(),e.request,o,c.get("Content-Type"),0),A(r,u)}return}e.request.cancellable&&f.set(n.identifier,new AbortController);const s=y[n.identifier],{timetokenOverride:o,regionOverride:c}=s;$(n,(()=>T(n.identifier)),((t,r)=>{R(t,r,e.request),E(t,n.identifier)}),((t,r)=>{R(t,null,e.request,W(r)),E(t,n.identifier)}),(e=>{let t=e;return i&&o&&"0"!==o&&(t=I(t,o,c)),t})),ie(`'${Object.keys(y).length}' subscription request currently active.`)},I=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return ie(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return ie(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},m=e=>{var t;const n=h[e.clientIdentifier],r=C(e);if(!n)return;const i=`${n.userId}_${null!==(t=n.authKey)&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(x("start",[n],(new Date).toISOString(),r),!r){let t,r;if(ie(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,x("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}$(r,(()=>[n]),((t,n)=>{o&&(o.response=n),R(t,n,e.request)}),((t,n)=>{R(t,null,e.request,W(n))})),ie("Started heartbeat request.",n)},w=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=G(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if($(n,(()=>[t]),((t,n)=>{R(t,n,e.request)}),((t,n)=>{R(t,null,e.request,W(n))})),ie("Started leave request.",t),void 0===i)return;const s=T(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),j(i),O(s)},k=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,j(n))},O=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}n&&t&&q({type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n})},$=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(P(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),S(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},j=e=>{if(0===T(e).length){const t=f.get(e);f.delete(e),delete y[e],t&&t.abort("Cancel request")}},S=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),T=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete y[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},P=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${oe(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},K=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=Q(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=H(u,e);if(s){const e=y[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||Z(e.channels,n))&&(!(r.length>0)||Z(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),v=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(v.add,v);const n=t.serviceRequestId;t.serviceRequestId=a,n&&y[n]&&j(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=y[a])&&void 0!==r?r:y[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(v.size){q.channels=Array.from(v).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}if(b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h)),d.queryParameters&&d.queryParameters.auth){const e=ne(u);e&&(d.queryParameters.auth=e)}}else y[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};y[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(y[a].region=d.queryParameters.tr),y[a].timetokenOverride=f,y[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)se(y[a],`Started aggregated request for clients: ${b}`,e);return d},C=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=B(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=o.authKey)&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,v=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=Z(e,o.heartbeat.channels)&&Z(t,o.heartbeat.channelGroups),n&&(v=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;if(g){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!v&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}return d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,l},G=e=>{const t=h[e.clientIdentifier],n=z(e);let r=Y(e.request),i=X(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!n.channelGroups.includes(e))))))}if(0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}return r.length&&(s.queryParameters["channel-group"]=r.join(",")),s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");ie(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=v[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},x=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=v[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},R=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=v[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?W(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)ie(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)ie(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&ie(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},W=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},D=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=v[s=e.subscriptionKey])&&void 0!==n?n:v[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)ie(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)ie(`Setup PubNub client ping event ${n} seconds`,e);a[e.subscriptionKey]=setTimeout((()=>ee(t)),500*n-1)}},F=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,v,y,q,I,m,w;const k=e.request.queryParameters,{clientIdentifier:O}=e,$=h[O];if(!$)return;const j=null!==(t=k["channel-group"])&&void 0!==t?t:"",S=null!==(n=k.state)&&void 0!==n?n:"";let T=$.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(y=null!==(s=g[v=$.subscriptionKey])&&void 0!==s?s:g[v]={})[q=$.userId])&&void 0!==o?o:y[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=$.subscriptionKey])&&void 0!==c?c:g[I]={})[w=$.userId])&&void 0!==l?l:m[w]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=$.subscriptionKey])&&void 0!==r?r:g[f]={})[b=$.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}$.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=X(e.request)),T.channelGroupQuery!==j&&(T.channelGroupQuery=j,T.channelGroups=Y(e.request));const{authKey:E,userId:P}=$;T.request=e.request,T.filterExpression=null!==(u=k["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=k.tt)&&void 0!==a?a:"0",void 0!==k.tr&&(T.region=k.tr),$.authKey=null!==(d=k.auth)&&void 0!==d?d:"",$.origin=e.request.origin,$.userId=k.uuid,$.pnsdk=k.pnsdk,$.accessToken=e.token,V($,P,E)},U=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=Y(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=X(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},V=(e,t,n)=>{var r,i;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const s=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},o=`${t}_${null!=n?n:""}`;void 0!==s[o]&&delete s[o]},N=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},M=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r,serviceRequestId:i}=e.subscription,s=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ce(e))).sort(),o=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ce(e))).sort();if(i&&(delete e.subscription.serviceRequestId,j(i)),0===o.length&&0===s.length)return;const l=s.length>0?s.join(","):void 0,u=0===o.length?",":o.join(","),a=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),l?{"channel-group":l}:{}),d={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${u}/leave`,queryParameters:a,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:a.requestid}};w(d,e)},J=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},H=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return ie(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=y[e.serviceRequestId];if(s||(s=Y(t.request)),o||(o=X(t.request)),o.length&&!Z(r.channels,o))continue;if(s.length&&!Z(r.channelGroups,s))continue;return se(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},_=(e,t)=>{var n,r;return Q(null!==(r=(null!==(n=e.subscription)&&void 0!==n?n:{}).timetoken)&&void 0!==r?r:"0",t).length>1},Q=(e,t)=>{var n,r;const i=h[t.clientIdentifier];if(!i)return[];const s=t.request.queryParameters,o=te(i),c=null!==(n=s["filter-expr"])&&void 0!==n?n:"",l=s.uuid;return(null!==(r=p[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===l&&te(t)===o&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===c&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},B=e=>z(e),z=e=>{var t;const n=h[e.clientIdentifier];if(!n)return[];const r=e.request.queryParameters,i=n.authKey,s=r.uuid;return(null!==(t=p[e.subscriptionKey])&&void 0!==t?t:[]).filter((e=>e.userId===s&&te(e)===i))},X=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},Y=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},Z=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ee=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)ie(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);((e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r&&r.unsubscribeOfflineClients&&M(r),i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=v[e];n&&(delete n[t],0===Object.keys(n).length&&delete v[e])}else delete v[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)ie(s,e);else ie(s)})(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ee(e)),500*t-1)}},te=e=>{var t;return e.accessToken&&null!==(t=e.accessToken.token)&&void 0!==t?t:e.authKey},ne=e=>{const t=e.filter((e=>!!e.accessToken)).sort(((e,t)=>e.accessToken.expiration-t.accessToken.expiration)).pop();return t?t.authKey:void 0},re=e=>{const t=te(e);let n=`${e.userId}-${e.subscriptionKey}${t?`-${t}`:""}`;return e.subscription&&e.subscription.filterExpression&&(n+=`-${e.subscription.filterExpression}`),n},ie=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},se=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},oe=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${ce(e)}`)).join("&"):`${t}=${ce(n)}`})).join("&"),ce=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},y={},v={};self.onconnect=e=>{oe("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!Q(t))return;const n=t.data;if("client-register"===n.type)n.port=e,F(n),oe(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-unregister"===n.type)U(n);else if("client-pong"===n.type)J(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){V(n);const e=h[n.clientIdentifier];if(e){const t=se(e);let r=[];if(l.has(t)&&(r=l.get(t)[0]),r.push([e,n]),!l.has(t)){const e=setTimeout((()=>{q(r,n),l.delete(t)}),50);l.set(t,[r,e])}}}else n.request.path.endsWith("/heartbeat")?(N(n),w(n)):O(n);else"cancel-request"===n.type&&$(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=(e,t)=>{const n=K(t),r=h[t.clientIdentifier];r&&(e=e.filter((e=>e[0].clientIdentifier!==r.clientIdentifier)),I(r,t,n,!0),e.forEach((([e,t])=>I(e,t,n,!1))))},I=(e,t,n,r)=>{var i;let s=!1;if(r||"string"==typeof n||(n=n.identifier),e.subscription&&(s="0"===e.subscription.timetoken),R("start",[e],(new Date).toISOString(),t.request),"string"==typeof n){const r=v[n];if(e){if(e.subscription&&(e.subscription.timetoken=r.timetoken,e.subscription.region=r.region,e.subscription.serviceRequestId=n),!s)return;const o=(new TextEncoder).encode(`{"t":{"t":"${r.timetoken}","r":${null!==(i=r.region)&&void 0!==i?i:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${t.request.origin}${t.request.path}`,u.clientIdentifier=t.clientIdentifier,u.identifier=t.request.identifier,R("end",[e],(new Date).toISOString(),t.request,o,c.get("Content-Type"),0),x(e,u)}return}t.request.cancellable&&f.set(n.identifier,new AbortController);const o=v[n.identifier],{timetokenOverride:c,regionOverride:l}=o;j(n,(()=>P(n.identifier)),((e,r)=>{W(e,r,t.request),E(e,n.identifier)}),((e,r)=>{W(e,null,t.request,D(r)),E(e,n.identifier)}),(e=>{let t=e;return s&&c&&"0"!==c&&(t=m(t,c,l)),t})),oe(`'${Object.keys(v).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return oe(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return oe(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},w=e=>{var t;const n=h[e.clientIdentifier],r=G(e);if(!n)return;const i=`${n.userId}_${null!==(t=re(n))&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(R("start",[n],(new Date).toISOString(),r),!r){let t,r;if(oe(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,R("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void x(n,i)}j(r,(()=>[n]),((t,n)=>{o&&(o.response=n),W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started heartbeat request.",n)},O=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=A(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void x(t,s)}if(j(n,(()=>[t]),((t,n)=>{W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started leave request.",t),void 0===i)return;const s=P(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),S(i),k(s)},$=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,S(n))},k=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}if(!n||!t)return;const r={type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n};q([[t,r]],r)},j=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(C(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),T(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(R("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},S=e=>{if(0===P(e).length){const t=f.get(e);f.delete(e),delete v[e],t&&t.abort("Cancel request")}},T=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),P=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete v[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},C=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${le(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},K=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=z(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=B(u,e);if(s){const e=v[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||te(e.channels,n))&&(!(r.length>0)||te(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),y=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(y.add,y);const n=t.serviceRequestId;t.serviceRequestId=a,n&&v[n]&&S(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=v[a])&&void 0!==r?r:v[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(y.size){q.channels=Array.from(y).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}if(b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h)),d.queryParameters&&d.queryParameters.auth){const e=ie(u);e&&(d.queryParameters.auth=e)}}else v[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};v[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(v[a].region=d.queryParameters.tr),v[a].timetokenOverride=f,v[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)ce(v[a],`Started aggregated request for clients: ${b}`,e);return d},G=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=X(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=re(o))&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,y=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=te(e,o.heartbeat.channels)&&te(t,o.heartbeat.channelGroups),n&&(y=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;if(g){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!y&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}if(d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,c.length>1&&l.queryParameters&&l.queryParameters.auth){const e=ie(c);e&&(l.queryParameters.auth=e)}return l},A=e=>{const t=h[e.clientIdentifier],n=Y(e);let r=ee(e.request),i=Z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!e.endsWith("-pnpres")&&!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")&&!n.channelGroups.includes(e))))))}if(i.length&&(i=i.filter((e=>!e.endsWith("-pnpres")))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")))),0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}if(r.length&&(s.queryParameters["channel-group"]=r.join(",")),n.length>1&&s.queryParameters&&s.queryParameters.auth){const e=ie(n);e&&(s.queryParameters.auth=e)}return s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");oe(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},x=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},R=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});x(e,t)}}},W=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?D(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)oe(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)oe(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});x(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&oe(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},F=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=y[s=e.subscriptionKey])&&void 0!==n?n:y[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)oe(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)oe(`Setup PubNub client ping event ${n} seconds`,e);a[t]=setTimeout((()=>ne(t)),500*n-1)}},U=e=>{H(e.subscriptionKey,e.clientIdentifier)},V=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,y,v,q,I,m,w;const O=e.request.queryParameters,{clientIdentifier:$}=e,k=h[$];if(!k)return;const j=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let T=k.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(v=null!==(s=g[y=k.subscriptionKey])&&void 0!==s?s:g[y]={})[q=k.userId])&&void 0!==o?o:v[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=k.subscriptionKey])&&void 0!==c?c:g[I]={})[w=k.userId])&&void 0!==l?l:m[w]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=k.subscriptionKey])&&void 0!==r?r:g[f]={})[b=k.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}k.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=Z(e.request)),T.channelGroupQuery!==j&&(T.channelGroupQuery=j,T.channelGroups=ee(e.request));const{authKey:P,userId:E}=k;T.request=e.request,T.filterExpression=null!==(u=O["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(T.region=O.tr),k.authKey=null!==(d=O.auth)&&void 0!==d?d:"",k.origin=e.request.origin,k.userId=O.uuid,k.pnsdk=O.pnsdk,k.accessToken=e.token,M(k,E,P)},N=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=ee(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=Z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i,s;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const o=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},c=`${t}_${null!==(s=re(e))&&void 0!==s?s:""}`;void 0!==o[c]&&delete o[c]},J=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},H=(e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r){if(r.subscription){const{serviceRequestId:e}=r.subscription;delete r.subscription.serviceRequestId,e&&S(e)}r.unsubscribeOfflineClients&&_(r)}if(i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)oe(s,e);else oe(s)},_=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r,serviceRequestId:i}=e.subscription,s=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort(),o=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort();if(0===o.length&&0===s.length)return;const l=s.length>0?s.join(","):void 0,u=0===o.length?",":o.join(","),a=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),l?{"channel-group":l}:{}),d={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${u}/leave`,queryParameters:a,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:a.requestid}};O(d,e)},Q=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},B=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return oe(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=v[e.serviceRequestId];if(s||(s=ee(t.request)),o||(o=Z(t.request)),o.length&&!te(r.channels,o))continue;if(s.length&&!te(r.channelGroups,s))continue;return ce(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},z=(e,t)=>{var n,r;const i=h[t.clientIdentifier];if(!i)return[];const s=t.request.queryParameters,o=re(i),c=null!==(n=s["filter-expr"])&&void 0!==n?n:"",l=s.uuid;return(null!==(r=p[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===l&&re(t)===o&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===c&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},X=e=>Y(e),Y=e=>{var t;const n=h[e.clientIdentifier];if(!n)return[];const r=e.request.queryParameters,i=re(n),s=r.uuid;return(null!==(t=p[e.subscriptionKey])&&void 0!==t?t:[]).filter((e=>e.userId===s&&re(e)===i))},Z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},ee=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},te=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ne=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)oe(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);H(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,x(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ne(e)),500*t-1)}},re=e=>{var t;return e.accessToken&&null!==(t=e.accessToken.token)&&void 0!==t?t:e.authKey},ie=e=>{const t=e.filter((e=>!!e.accessToken)).sort(((e,t)=>e.accessToken.expiration-t.accessToken.expiration)).pop();return t?t.authKey:void 0},se=e=>{const t=re(e);let n=`${e.userId}-${e.subscriptionKey}${t?`-${t}`:""}`;return e.subscription&&e.subscription.filterExpression&&(n+=`-${e.subscription.filterExpression}`),n},oe=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&x(e,r)}))},ce=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&x(e,i)}))},le=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${ue(e)}`)).join("&"):`${t}=${ue(n)}`})).join("&"),ue=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 36d9175c1..61952e3f3 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -94,6 +94,10 @@ const makeConfiguration = (base, setupCryptoModule) => { getUseRandomIVs() { return base.useRandomIVs; }, + getKeepPresenceChannelsInPresenceRequests() { + // @ts-expect-error: Access field from web-based SDK configuration. + return base.sdkFamily === 'Web' && base['subscriptionWorkerUrl']; + }, setPresenceTimeout(value) { this.heartbeatInterval = value / 2 - 1; this.presenceTimeout = value; @@ -120,7 +124,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '9.1.0'; + return '9.2.0'; }, getVersion() { return this.version; diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 46e5836dc..c470ce500 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -897,10 +897,13 @@ class PubNubCore { if (process.env.PRESENCE_MODULE !== 'disabled') { // Filtering out presence channels and groups. let { channels, channelGroups } = parameters; - if (channelGroups) - channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); - if (channels) - channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + // Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration. + if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) { + if (channelGroups) + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + } // Complete immediately request only for presence channels. if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) { return callback({ @@ -1301,10 +1304,13 @@ class PubNubCore { if (process.env.PRESENCE_MODULE !== 'disabled') { // Filtering out presence channels and groups. let { channels, channelGroups } = parameters; - if (channelGroups) - channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); - if (channels) - channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + // Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration. + if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) { + if (channelGroups) + channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) + channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + } // Complete immediately request only for presence channels. if ((channelGroups !== null && channelGroups !== void 0 ? channelGroups : []).length === 0 && (channels !== null && channels !== void 0 ? channels : []).length === 0) { const responseStatus = { diff --git a/package-lock.json b/package-lock.json index 1de135375..843713e8f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "9.0.0", + "version": "9.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "9.0.0", + "version": "9.1.0", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", diff --git a/package.json b/package.json index c7d9246cb..d968a38a6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "9.1.0", + "version": "9.2.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index fe5a95dc2..1675c0a26 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -152,6 +152,10 @@ export const makeConfiguration = ( getUseRandomIVs(): boolean | undefined { return base.useRandomIVs; }, + getKeepPresenceChannelsInPresenceRequests(): boolean { + // @ts-expect-error: Access field from web-based SDK configuration. + return base.sdkFamily === 'Web' && base['subscriptionWorkerUrl']; + }, setPresenceTimeout(value: number): void { this.heartbeatInterval = value / 2 - 1; this.presenceTimeout = value; @@ -178,7 +182,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '9.1.0'; + return '9.2.0'; }, getVersion(): string { return this.version; diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index 36ce2e747..f9018752c 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -607,6 +607,15 @@ export interface PrivateClientConfiguration */ getCryptoModule(): ICryptoModule | undefined; + /** + * Whether `-pnpres` should not be filtered out from list of channels / groups in presence-related requests or not. + * + * This option required and set to `true` for Shared Worker setup to properly update client's state. + * + * @returns `true` if `-pnpres` channels and groups shouldn't be removed before sending request. + */ + getKeepPresenceChannelsInPresenceRequests(): boolean; + /** * Retrieve user's presence timeout. * diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index 0ed8b5883..db9328599 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -1240,8 +1240,12 @@ export class PubNubCore< if (process.env.PRESENCE_MODULE !== 'disabled') { // Filtering out presence channels and groups. let { channels, channelGroups } = parameters; - if (channelGroups) channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); - if (channels) channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + + // Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration. + if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) { + if (channelGroups) channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + } // Complete immediately request only for presence channels. if ((channelGroups ?? []).length === 0 && (channels ?? []).length === 0) { @@ -1931,8 +1935,12 @@ export class PubNubCore< if (process.env.PRESENCE_MODULE !== 'disabled') { // Filtering out presence channels and groups. let { channels, channelGroups } = parameters; - if (channelGroups) channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); - if (channels) channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + + // Remove `-pnpres` channels / groups if they not acceptable in current PubNub client configuration. + if (!this._configuration.getKeepPresenceChannelsInPresenceRequests()) { + if (channelGroups) channelGroups = channelGroups.filter((channelGroup) => !channelGroup.endsWith('-pnpres')); + if (channels) channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + } // Complete immediately request only for presence channels. if ((channelGroups ?? []).length === 0 && (channels ?? []).length === 0) { diff --git a/src/transport/subscription-worker/subscription-worker-middleware.ts b/src/transport/subscription-worker/subscription-worker-middleware.ts index b2130a4ca..5487e0247 100644 --- a/src/transport/subscription-worker/subscription-worker-middleware.ts +++ b/src/transport/subscription-worker/subscription-worker-middleware.ts @@ -133,6 +133,18 @@ export class SubscriptionWorkerMiddleware implements Transport { this.setupSubscriptionWorker(); } + /** + * Terminate all ongoing long-poll requests. + */ + terminate() { + this.scheduleEventPost({ + type: 'client-unregister', + clientIdentifier: this.configuration.clientIdentifier, + subscriptionKey: this.configuration.subscriptionKey, + logVerbosity: this.configuration.logVerbosity, + }); + } + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { // Use default request flow for non-subscribe / presence leave requests. if (!req.path.startsWith('/v2/subscribe') && !req.path.endsWith('/heartbeat') && !req.path.endsWith('/leave')) @@ -409,7 +421,7 @@ export class SubscriptionWorkerMiddleware implements Transport { if (typeof crypto !== 'undefined' && crypto.subtle) { const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(accessToken)); - accessToken = String.fromCharCode(...new Uint8Array(hash)); + accessToken = String.fromCharCode(...Array.from(new Uint8Array(hash))); } return [token, typeof btoa !== 'undefined' ? btoa(accessToken) : accessToken]; diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index 42ff91f2e..02e6edb3e 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -115,10 +115,19 @@ export type PongEvent = BasicEvent & { type: 'client-pong'; }; +/** + * PubNub client remove registration event. + * + * On registration removal ongoing long-long poll request will be cancelled. + */ +export type UnRegisterEvent = BasicEvent & { + type: 'client-unregister'; +}; + /** * List of known events from the PubNub Core. */ -export type ClientEvent = RegisterEvent | PongEvent | SendRequestEvent | CancelRequestEvent; +export type ClientEvent = RegisterEvent | PongEvent | SendRequestEvent | CancelRequestEvent | UnRegisterEvent; // endregion // region Subscription Worker @@ -557,9 +566,9 @@ declare const self: SharedWorkerGlobalScope; const subscribeAggregationTimeout = 50; /** - * Map of PubNub client subscription keys to the started aggregation timeout timers. + * Map of clients aggregation keys to the started aggregation timeout timers with client and event information. */ -const aggregationTimers: Map = new Map(); +const aggregationTimers: Map = new Map(); // region State /** @@ -704,7 +713,8 @@ self.onconnect = (event) => { registerClientIfRequired(data); consoleLog(`Client '${data.clientIdentifier}' registered with '${sharedWorkerIdentifier}' shared worker`); - } else if (data.type === 'client-pong') handleClientPong(data); + } else if (data.type === 'client-unregister') unRegisterClient(data); + else if (data.type === 'client-pong') handleClientPong(data); else if (data.type === 'send-request') { if (data.request.path.startsWith('/v2/subscribe')) { updateClientSubscribeStateIfRequired(data); @@ -713,19 +723,21 @@ self.onconnect = (event) => { if (client) { // Check whether there are more clients which may schedule next subscription loop and they need to be // aggregated or not. - if (hasClientsForSendAggregatedSubscribeRequestEvent(client, data)) { - const timerIdentifier = aggregateTimerId(client); - - // Check whether we need to start new aggregation timer or not. - if (!aggregationTimers.has(timerIdentifier)) { - const aggregationTimer = setTimeout(() => { - handleSendSubscribeRequestEvent(data); - aggregationTimers.delete(timerIdentifier); - }, subscribeAggregationTimeout); - - aggregationTimers.set(timerIdentifier, aggregationTimer); - } - } else handleSendSubscribeRequestEvent(data); + const timerIdentifier = aggregateTimerId(client); + let enqueuedClients: [PubNubClientState, SendRequestEvent][] = []; + + if (aggregationTimers.has(timerIdentifier)) enqueuedClients = aggregationTimers.get(timerIdentifier)![0]; + enqueuedClients.push([client, data]); + + // Check whether we need to start new aggregation timer or not. + if (!aggregationTimers.has(timerIdentifier)) { + const aggregationTimer = setTimeout(() => { + handleSendSubscribeRequestEventForClients(enqueuedClients, data); + aggregationTimers.delete(timerIdentifier); + }, subscribeAggregationTimeout); + + aggregationTimers.set(timerIdentifier, [enqueuedClients, aggregationTimer]); + } } } else if (data.request.path.endsWith('/heartbeat')) { updateClientHeartbeatState(data); @@ -739,19 +751,47 @@ self.onconnect = (event) => { }; /** - * Handle client request to send subscription request. + * Handle aggregated clients request to send subscription request. * + * @param clients - List of aggregated clients which would like to send subscription requests. * @param event - Subscription event details. */ -const handleSendSubscribeRequestEvent = (event: SendRequestEvent) => { +const handleSendSubscribeRequestEventForClients = ( + clients: [PubNubClientState, SendRequestEvent][], + event: SendRequestEvent, +) => { const requestOrId = subscribeTransportRequestFromEvent(event); const client = pubNubClients[event.clientIdentifier]; + + if (!client) return; + + // Getting rest of aggregated clients. + clients = clients.filter((aggregatedClient) => aggregatedClient[0].clientIdentifier !== client.clientIdentifier); + handleSendSubscribeRequestForClient(client, event, requestOrId, true); + clients.forEach(([aggregatedClient, clientEvent]) => + handleSendSubscribeRequestForClient(aggregatedClient, clientEvent, requestOrId, false), + ); +}; + +/** + * Handle subscribe request by single client. + * + * @param client - Client which processes `request`. + * @param event - Subscription event details. + * @param requestOrId - New aggregated request object or its identifier (if already scheduled). + * @param requestOrigin - Whether `client` is the one who triggered subscribe request or not. + */ +const handleSendSubscribeRequestForClient = ( + client: PubNubClientState, + event: SendRequestEvent, + requestOrId: ReturnType, + requestOrigin: boolean, +) => { let isInitialSubscribe = false; + if (!requestOrigin && typeof requestOrId !== 'string') requestOrId = requestOrId.identifier; - if (client) { - if (client.subscription) isInitialSubscribe = client.subscription.timetoken === '0'; - notifyRequestProcessing('start', [client], new Date().toISOString(), event.request); - } + if (client.subscription) isInitialSubscribe = client.subscription.timetoken === '0'; + notifyRequestProcessing('start', [client], new Date().toISOString(), event.request); if (typeof requestOrId === 'string') { const scheduledRequest = serviceRequests[requestOrId]; @@ -884,7 +924,7 @@ const handleHeartbeatRequestEvent = (event: SendRequestEvent) => { const request = heartbeatTransportRequestFromEvent(event); if (!client) return; - const heartbeatRequestKey = `${client.userId}_${client.authKey ?? ''}`; + const heartbeatRequestKey = `${client.userId}_${clientAggregateAuthKey(client) ?? ''}`; const hbRequestsBySubscriptionKey = serviceHeartbeatRequests[client.subscriptionKey]; const hbRequests = (hbRequestsBySubscriptionKey ?? {})[heartbeatRequestKey]; notifyRequestProcessing('start', [client], new Date().toISOString(), request); @@ -1067,13 +1107,15 @@ const restartSubscribeRequestForClients = (clients: PubNubClientState[]) => { } if (!request || !clientWithRequest) return; - handleSendSubscribeRequestEvent({ + const sendRequest: SendRequestEvent = { type: 'send-request', clientIdentifier: clientWithRequest.clientIdentifier, subscriptionKey: clientWithRequest.subscriptionKey, logVerbosity: clientWithRequest.logVerbosity, request, - }); + }; + + handleSendSubscribeRequestEventForClients([[clientWithRequest, sendRequest]], sendRequest); }; // endregion @@ -1411,7 +1453,7 @@ const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportR if (!client || !client.heartbeat) return undefined; const hbRequestsBySubscriptionKey = (serviceHeartbeatRequests[client.subscriptionKey] ??= {}); - const heartbeatRequestKey = `${client.userId}_${client.authKey ?? ''}`; + const heartbeatRequestKey = `${client.userId}_${clientAggregateAuthKey(client) ?? ''}`; const channelGroupsForAnnouncement: string[] = client.heartbeat.channelGroups; const channelsForAnnouncement: string[] = client.heartbeat.channels; let aggregatedState: Record; @@ -1489,6 +1531,12 @@ const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportR if (Object.keys(aggregatedState).length) request.queryParameters!['state'] = JSON.stringify(aggregatedState); else delete request.queryParameters!['state']; + // Update `auth` key (if required). + if (clients.length > 1 && request.queryParameters && request.queryParameters.auth) { + const aggregatedAuthKey = authKeyForAggregatedClientsRequest(clients); + if (aggregatedAuthKey) request.queryParameters.auth = aggregatedAuthKey; + } + return request; }; @@ -1530,11 +1578,18 @@ const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportReque const subscription = client.subscription; if (subscription === undefined) continue; if (client.clientIdentifier === event.clientIdentifier) continue; - if (channels.length) channels = channels.filter((channel) => !subscription.channels.includes(channel)); + if (channels.length) + channels = channels.filter((channel) => !channel.endsWith('-pnpres') && !subscription.channels.includes(channel)); if (channelGroups.length) - channelGroups = channelGroups.filter((group) => !subscription.channelGroups.includes(group)); + channelGroups = channelGroups.filter( + (group) => !group.endsWith('-pnpres') && !subscription.channelGroups.includes(group), + ); } + // Clean up from presence channels and groups + if (channels.length) channels = channels.filter((channel) => !channel.endsWith('-pnpres')); + if (channelGroups.length) channelGroups = channelGroups.filter((group) => !group.endsWith('-pnpres')); + if (channels.length === 0 && channelGroups.length === 0) { if (client && client.workerLogVerbosity) { const clientIds = clients @@ -1563,6 +1618,12 @@ const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportReque // Update request channel groups list (if required). if (channelGroups.length) request.queryParameters!['channel-group'] = channelGroups.join(','); + // Update `auth` key (if required). + if (clients.length > 1 && request.queryParameters && request.queryParameters.auth) { + const aggregatedAuthKey = authKeyForAggregatedClientsRequest(clients); + if (aggregatedAuthKey) request.queryParameters.auth = aggregatedAuthKey; + } + return request; }; @@ -1877,13 +1938,25 @@ const registerClientIfRequired = (event: RegisterEvent) => { for (const _client of clientsBySubscriptionKey) consoleLog(`Setup PubNub client ping event ${interval} seconds`, _client); - pingTimeouts[event.subscriptionKey] = setTimeout( + pingTimeouts[subscriptionKey] = setTimeout( () => pingClients(subscriptionKey), interval * 500 - 1, ) as unknown as number; } }; +/** + * Unregister client if it uses Service Worker before. + * + * During registration removal client information will be removed from the Shared Worker and + * long-poll request will be cancelled if possible. + * + * @param event - Base information about PubNub client instance and Service Worker {@link Client}. + */ +const unRegisterClient = (event: UnRegisterEvent) => { + invalidateClient(event.subscriptionKey, event.clientIdentifier); +}; + /** * Update information about previously registered client. * @@ -2013,7 +2086,7 @@ const handleClientIdentityChangeIfRequired = (client: PubNubClientState, userId: const _heartbeatRequests = serviceHeartbeatRequests[client.subscriptionKey] ?? {}; - const heartbeatRequestKey = `${userId}_${authKey ?? ''}`; + const heartbeatRequestKey = `${userId}_${clientAggregateAuthKey(client) ?? ''}`; if (_heartbeatRequests[heartbeatRequestKey] !== undefined) delete _heartbeatRequests[heartbeatRequestKey]; }; @@ -2043,7 +2116,17 @@ const invalidateClient = (subscriptionKey: string, clientId: string) => { let clients = pubNubClientsBySubscriptionKey[subscriptionKey]; // Unsubscribe invalidated PubNub client. - if (invalidatedClient && invalidatedClient.unsubscribeOfflineClients) unsubscribeClient(invalidatedClient); + if (invalidatedClient) { + // Cancel long-poll request if possible. + if (invalidatedClient.subscription) { + const { serviceRequestId } = invalidatedClient.subscription; + delete invalidatedClient.subscription.serviceRequestId; + if (serviceRequestId) cancelRequest(serviceRequestId); + } + + // Leave subscribed channels / groups properly. + if (invalidatedClient.unsubscribeOfflineClients) unsubscribeClient(invalidatedClient); + } if (clients) { // Clean up linkage between client and subscription key. @@ -2088,12 +2171,8 @@ const unsubscribeClient = (client: PubNubClientState) => { .map((name) => encodeString(name)) .sort(); - if (serviceRequestId) { - delete client.subscription.serviceRequestId; - cancelRequest(serviceRequestId); - } - if (encodedChannels.length === 0 && encodedChannelGroups.length === 0) return; + const channelGroupsString: string | undefined = encodedChannelGroups.length > 0 ? encodedChannelGroups.join(',') : undefined; const channelsString = encodedChannels.length === 0 ? ',' : encodedChannels.join(','); @@ -2275,7 +2354,7 @@ const clientsForSendLeaveRequestEvent = (event: SendRequestEvent) => { if (!reqClient) return []; const query = event.request.queryParameters!; - const authKey = reqClient.authKey; + const authKey = clientAggregateAuthKey(reqClient); const userId = query.uuid! as string; return (pubNubClientsBySubscriptionKey[event.subscriptionKey] ?? []).filter( @@ -2331,6 +2410,7 @@ const pingClients = (subscriptionKey: string) => { const _pubNubClients = Object.values(pubNubClients).filter( (client) => client && client.subscriptionKey === subscriptionKey, ); + _pubNubClients.forEach((client) => { let clientInvalidated = false; diff --git a/src/web/index.ts b/src/web/index.ts index 3c41fdc08..28b91d46e 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -101,7 +101,7 @@ export default class PubNub extends PubNubCore { + if (!event.persisted) middleware.terminate(); + }; } } From 71ba3a1a886b64653c03820749284f1b1f051ad8 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 20 Mar 2025 15:13:14 +0200 Subject: [PATCH 43/49] Remove minimum presence timeout (#446) feat(presence): remove minimum presence timeout Remove minimum limit for presence timeout (was 20 seconds) to make it possible specify shorter intervals. fix(shared-worker): fix issue because of which similar requests didn't stacked Fix issue because of which channels not aggregated and caused separate heartbeat requests. --- .pubnub.yml | 13 +++-- CHANGELOG.md | 9 ++++ README.md | 4 +- dist/web/pubnub.js | 21 +++++--- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 45 ++++++++++------ dist/web/pubnub.worker.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/interfaces/configuration.js | 19 ++++--- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/interfaces/configuration.ts | 21 +++++--- .../subscription-worker.ts | 52 ++++++++++++------- 13 files changed, 131 insertions(+), 65 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 82c495668..060c2ca50 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2025-03-20 + version: v9.3.0 + changes: + - type: feature + text: "Remove minimum limit for presence timeout (was 20 seconds) to make it possible specify shorter intervals." + - type: bug + text: "Fix issue because of which channels not aggregated and caused separate heartbeat requests." - date: 2025-03-19 version: v9.2.0 changes: @@ -1185,7 +1192,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '9.2.0' +version: '9.3.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1201,7 +1208,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v9.2.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.3.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1872,7 +1879,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v9.2.0/pubnub.9.2.0.js + location: https://github.com/pubnub/javascript/releases/download/v9.3.0/pubnub.9.3.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 899dbdbc2..73ab8ede8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v9.3.0 +March 20 2025 + +#### Added +- Remove minimum limit for presence timeout (was 20 seconds) to make it possible specify shorter intervals. + +#### Fixed +- Fix issue because of which channels not aggregated and caused separate heartbeat requests. + ## v9.2.0 March 19 2025 diff --git a/README.md b/README.md index acc66d9c7..2d4100037 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.2.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.2.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 24c7f6f5a..2e0c8e347 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3594,9 +3594,9 @@ */ const PRESENCE_TIMEOUT = 300; /** - * Minimum user presence timeout. + * Maximum user presence timeout. */ - const PRESENCE_TIMEOUT_MINIMUM = 20; + const PRESENCE_TIMEOUT_MAXIMUM = 320; /** * Apply configuration default values. * @@ -3637,10 +3637,17 @@ publishKey: configurationCopy.publishKey, secretKey: configurationCopy.secretKey, }; - if (configurationCopy.presenceTimeout !== undefined && configurationCopy.presenceTimeout < PRESENCE_TIMEOUT_MINIMUM) { - configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; - // eslint-disable-next-line no-console - console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); + if (configurationCopy.presenceTimeout !== undefined) { + if (configurationCopy.presenceTimeout > PRESENCE_TIMEOUT_MAXIMUM) { + configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MAXIMUM; + // eslint-disable-next-line no-console + console.warn('WARNING: Presence timeout is larger than the maximum. Using maximum value: ', PRESENCE_TIMEOUT_MAXIMUM); + } + else if (configurationCopy.presenceTimeout <= 0) { + // eslint-disable-next-line no-console + console.warn('WARNING: Presence timeout should be larger than zero.'); + delete configurationCopy.presenceTimeout; + } } if (configurationCopy.presenceTimeout !== undefined) configurationCopy.heartbeatInterval = configurationCopy.presenceTimeout / 2 - 1; @@ -3932,7 +3939,7 @@ return base.PubNubFile; }, get version() { - return '9.2.0'; + return '9.3.0'; }, getVersion() { return this.version; diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index c2969bda7..30b9543d3 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),O=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],O=e[i+15],E=t(E=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,E,P,N,o,12,u[1]),N=t(N,C,E,P,l,17,u[2]),P=t(P,N,C,E,h,22,u[3]);E=t(E,P,N,C,d,7,u[4]),C=t(C,E,P,N,p,12,u[5]),N=t(N,C,E,P,g,17,u[6]),P=t(P,N,C,E,y,22,u[7]),E=t(E,P,N,C,f,7,u[8]),C=t(C,E,P,N,b,12,u[9]),N=t(N,C,E,P,m,17,u[10]),P=t(P,N,C,E,v,22,u[11]),E=t(E,P,N,C,w,7,u[12]),C=t(C,E,P,N,S,12,u[13]),N=t(N,C,E,P,k,17,u[14]),E=n(E,P=t(P,N,C,E,O,22,u[15]),N,C,o,5,u[16]),C=n(C,E,P,N,g,9,u[17]),N=n(N,C,E,P,v,14,u[18]),P=n(P,N,C,E,c,20,u[19]),E=n(E,P,N,C,p,5,u[20]),C=n(C,E,P,N,m,9,u[21]),N=n(N,C,E,P,O,14,u[22]),P=n(P,N,C,E,d,20,u[23]),E=n(E,P,N,C,b,5,u[24]),C=n(C,E,P,N,k,9,u[25]),N=n(N,C,E,P,h,14,u[26]),P=n(P,N,C,E,f,20,u[27]),E=n(E,P,N,C,S,5,u[28]),C=n(C,E,P,N,l,9,u[29]),N=n(N,C,E,P,y,14,u[30]),E=s(E,P=n(P,N,C,E,w,20,u[31]),N,C,p,4,u[32]),C=s(C,E,P,N,f,11,u[33]),N=s(N,C,E,P,v,16,u[34]),P=s(P,N,C,E,k,23,u[35]),E=s(E,P,N,C,o,4,u[36]),C=s(C,E,P,N,d,11,u[37]),N=s(N,C,E,P,y,16,u[38]),P=s(P,N,C,E,m,23,u[39]),E=s(E,P,N,C,S,4,u[40]),C=s(C,E,P,N,c,11,u[41]),N=s(N,C,E,P,h,16,u[42]),P=s(P,N,C,E,g,23,u[43]),E=s(E,P,N,C,b,4,u[44]),C=s(C,E,P,N,w,11,u[45]),N=s(N,C,E,P,O,16,u[46]),E=r(E,P=s(P,N,C,E,l,23,u[47]),N,C,c,6,u[48]),C=r(C,E,P,N,y,10,u[49]),N=r(N,C,E,P,k,15,u[50]),P=r(P,N,C,E,p,21,u[51]),E=r(E,P,N,C,w,6,u[52]),C=r(C,E,P,N,h,10,u[53]),N=r(N,C,E,P,m,15,u[54]),P=r(P,N,C,E,o,21,u[55]),E=r(E,P,N,C,f,6,u[56]),C=r(C,E,P,N,O,10,u[57]),N=r(N,C,E,P,g,15,u[58]),P=r(P,N,C,E,S,21,u[59]),E=r(E,P,N,C,d,6,u[60]),C=r(C,E,P,N,v,10,u[61]),N=r(N,C,E,P,l,15,u[62]),P=r(P,N,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&m.presenceTimeout<20&&(m.presenceTimeout=20,console.log("WARNING: Presence timeout is less than the minimum. Using minimum value: ",20)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,O=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(O=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:O,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.2.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){if(!this.aggregatedListener)return;const e=this.aggregatedListener;this.removeListener(this.aggregatedListener),this.addListener(e)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends An{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),O=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],O=e[i+15],E=t(E=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,E,P,N,o,12,u[1]),N=t(N,C,E,P,l,17,u[2]),P=t(P,N,C,E,h,22,u[3]);E=t(E,P,N,C,d,7,u[4]),C=t(C,E,P,N,p,12,u[5]),N=t(N,C,E,P,g,17,u[6]),P=t(P,N,C,E,y,22,u[7]),E=t(E,P,N,C,f,7,u[8]),C=t(C,E,P,N,b,12,u[9]),N=t(N,C,E,P,m,17,u[10]),P=t(P,N,C,E,v,22,u[11]),E=t(E,P,N,C,w,7,u[12]),C=t(C,E,P,N,S,12,u[13]),N=t(N,C,E,P,k,17,u[14]),E=n(E,P=t(P,N,C,E,O,22,u[15]),N,C,o,5,u[16]),C=n(C,E,P,N,g,9,u[17]),N=n(N,C,E,P,v,14,u[18]),P=n(P,N,C,E,c,20,u[19]),E=n(E,P,N,C,p,5,u[20]),C=n(C,E,P,N,m,9,u[21]),N=n(N,C,E,P,O,14,u[22]),P=n(P,N,C,E,d,20,u[23]),E=n(E,P,N,C,b,5,u[24]),C=n(C,E,P,N,k,9,u[25]),N=n(N,C,E,P,h,14,u[26]),P=n(P,N,C,E,f,20,u[27]),E=n(E,P,N,C,S,5,u[28]),C=n(C,E,P,N,l,9,u[29]),N=n(N,C,E,P,y,14,u[30]),E=s(E,P=n(P,N,C,E,w,20,u[31]),N,C,p,4,u[32]),C=s(C,E,P,N,f,11,u[33]),N=s(N,C,E,P,v,16,u[34]),P=s(P,N,C,E,k,23,u[35]),E=s(E,P,N,C,o,4,u[36]),C=s(C,E,P,N,d,11,u[37]),N=s(N,C,E,P,y,16,u[38]),P=s(P,N,C,E,m,23,u[39]),E=s(E,P,N,C,S,4,u[40]),C=s(C,E,P,N,c,11,u[41]),N=s(N,C,E,P,h,16,u[42]),P=s(P,N,C,E,g,23,u[43]),E=s(E,P,N,C,b,4,u[44]),C=s(C,E,P,N,w,11,u[45]),N=s(N,C,E,P,O,16,u[46]),E=r(E,P=s(P,N,C,E,l,23,u[47]),N,C,c,6,u[48]),C=r(C,E,P,N,y,10,u[49]),N=r(N,C,E,P,k,15,u[50]),P=r(P,N,C,E,p,21,u[51]),E=r(E,P,N,C,w,6,u[52]),C=r(C,E,P,N,h,10,u[53]),N=r(N,C,E,P,m,15,u[54]),P=r(P,N,C,E,o,21,u[55]),E=r(E,P,N,C,f,6,u[56]),C=r(C,E,P,N,O,10,u[57]),N=r(N,C,E,P,g,15,u[58]),P=r(P,N,C,E,S,21,u[59]),E=r(E,P,N,C,d,6,u[60]),C=r(C,E,P,N,v,10,u[61]),N=r(N,C,E,P,l,15,u[62]),P=r(P,N,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,O=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(O=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:O,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.3.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){if(!this.aggregatedListener)return;const e=this.aggregatedListener;this.removeListener(this.aggregatedListener),this.addListener(e)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends An{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index 39953a7c1..3b28d7e06 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -406,7 +406,7 @@ const hbRequests = (hbRequestsBySubscriptionKey !== null && hbRequestsBySubscriptionKey !== void 0 ? hbRequestsBySubscriptionKey : {})[heartbeatRequestKey]; notifyRequestProcessing('start', [client], new Date().toISOString(), request); if (!request) { - consoleLog(`Previous heartbeat request has been sent less than ${client.heartbeatInterval} seconds ago. Skipping...`); + consoleLog(`Previous heartbeat request has been sent less than ${client.heartbeatInterval} seconds ago. Skipping...`, client); let response; let body; // Pulling out previous response. @@ -855,30 +855,36 @@ const { channels, channelGroups, response } = hbRequestsBySubscriptionKey[heartbeatRequestKey]; aggregatedState = (_d = client.heartbeat.presenceState) !== null && _d !== void 0 ? _d : {}; aggregated = - includesStrings(channels, client.heartbeat.channels) && - includesStrings(channelGroups, client.heartbeat.channelGroups); + includesStrings(channels, channelsForAnnouncement) && + includesStrings(channelGroups, channelGroupsForAnnouncement); if (response) failedPreviousRequest = response[0].status >= 400; } + // Find minimum heartbeat interval which maybe required to use. + let minimumHeartbeatInterval = client.heartbeatInterval; + for (const client of clients) { + if (client.heartbeatInterval) + minimumHeartbeatInterval = Math.min(minimumHeartbeatInterval, client.heartbeatInterval); + } if (aggregated) { - const expectedTimestamp = hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp + client.heartbeatInterval * 1000; + const expectedTimestamp = hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp + minimumHeartbeatInterval * 1000; const currentTimestamp = Date.now(); // Check whether it is too soon to send request or not (5 is leeway which let send request a bit earlier). // Request should be sent if previous attempt failed. if (!failedPreviousRequest && currentTimestamp < expectedTimestamp && expectedTimestamp - currentTimestamp > 5000) return undefined; - delete hbRequestsBySubscriptionKey[heartbeatRequestKey].response; - // Aggregate channels for similar clients which is pending for heartbeat. - for (const client of clients) { - const { heartbeat } = client; - if (heartbeat === undefined || client.clientIdentifier === event.clientIdentifier) - continue; - // Append presence state from the client (will override previously set value if already set). - if (heartbeat.presenceState) - aggregatedState = Object.assign(Object.assign({}, aggregatedState), heartbeat.presenceState); - channelGroupsForAnnouncement.push(...heartbeat.channelGroups.filter((channel) => !channelGroupsForAnnouncement.includes(channel))); - channelsForAnnouncement.push(...heartbeat.channels.filter((channel) => !channelsForAnnouncement.includes(channel))); - } + } + delete hbRequestsBySubscriptionKey[heartbeatRequestKey].response; + // Aggregate channels for similar clients which is pending for heartbeat. + for (const client of clients) { + const { heartbeat } = client; + if (heartbeat === undefined || client.clientIdentifier === event.clientIdentifier) + continue; + // Append presence state from the client (will override previously set value if already set). + if (heartbeat.presenceState) + aggregatedState = Object.assign(Object.assign({}, aggregatedState), heartbeat.presenceState); + channelGroupsForAnnouncement.push(...heartbeat.channelGroups.filter((channel) => !channelGroupsForAnnouncement.includes(channel))); + channelsForAnnouncement.push(...heartbeat.channels.filter((channel) => !channelsForAnnouncement.includes(channel))); } hbRequestsBySubscriptionKey[heartbeatRequestKey].channels = channelsForAnnouncement; hbRequestsBySubscriptionKey[heartbeatRequestKey].channelGroups = channelGroupsForAnnouncement; @@ -1231,6 +1237,7 @@ subscriptionKey: event.subscriptionKey, userId: event.userId, heartbeatInterval: event.heartbeatInterval, + newlyRegistered: true, logVerbosity: event.logVerbosity, offlineClientsCheckInterval: event.workerOfflineClientsCheckInterval, unsubscribeOfflineClients: event.workerUnsubscribeOfflineClients, @@ -1330,7 +1337,8 @@ subscription.channelGroupQuery = channelGroupQuery; subscription.channelGroups = channelGroupsFromRequest(event.request); } - const { authKey, userId } = client; + let { authKey } = client; + const { userId } = client; subscription.request = event.request; subscription.filterExpression = ((_j = query['filter-expr']) !== null && _j !== void 0 ? _j : ''); subscription.timetoken = ((_k = query.tt) !== null && _k !== void 0 ? _k : '0'); @@ -1341,6 +1349,9 @@ client.userId = query.uuid; client.pnsdk = query.pnsdk; client.accessToken = event.token; + if (client.newlyRegistered && !authKey && client.authKey) + authKey = client.authKey; + client.newlyRegistered = false; handleClientIdentityChangeIfRequired(client, userId, authKey); }; /** diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index 03063e8ab..c339d6bd1 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((r=r.apply(e,t||[])).next())}))}var t;"function"==typeof SuppressedError&&SuppressedError,function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(t||(t={}));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r,i,s={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},y={},v={};self.onconnect=e=>{oe("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!Q(t))return;const n=t.data;if("client-register"===n.type)n.port=e,F(n),oe(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-unregister"===n.type)U(n);else if("client-pong"===n.type)J(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){V(n);const e=h[n.clientIdentifier];if(e){const t=se(e);let r=[];if(l.has(t)&&(r=l.get(t)[0]),r.push([e,n]),!l.has(t)){const e=setTimeout((()=>{q(r,n),l.delete(t)}),50);l.set(t,[r,e])}}}else n.request.path.endsWith("/heartbeat")?(N(n),w(n)):O(n);else"cancel-request"===n.type&&$(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=(e,t)=>{const n=K(t),r=h[t.clientIdentifier];r&&(e=e.filter((e=>e[0].clientIdentifier!==r.clientIdentifier)),I(r,t,n,!0),e.forEach((([e,t])=>I(e,t,n,!1))))},I=(e,t,n,r)=>{var i;let s=!1;if(r||"string"==typeof n||(n=n.identifier),e.subscription&&(s="0"===e.subscription.timetoken),R("start",[e],(new Date).toISOString(),t.request),"string"==typeof n){const r=v[n];if(e){if(e.subscription&&(e.subscription.timetoken=r.timetoken,e.subscription.region=r.region,e.subscription.serviceRequestId=n),!s)return;const o=(new TextEncoder).encode(`{"t":{"t":"${r.timetoken}","r":${null!==(i=r.region)&&void 0!==i?i:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${t.request.origin}${t.request.path}`,u.clientIdentifier=t.clientIdentifier,u.identifier=t.request.identifier,R("end",[e],(new Date).toISOString(),t.request,o,c.get("Content-Type"),0),x(e,u)}return}t.request.cancellable&&f.set(n.identifier,new AbortController);const o=v[n.identifier],{timetokenOverride:c,regionOverride:l}=o;j(n,(()=>P(n.identifier)),((e,r)=>{W(e,r,t.request),E(e,n.identifier)}),((e,r)=>{W(e,null,t.request,D(r)),E(e,n.identifier)}),(e=>{let t=e;return s&&c&&"0"!==c&&(t=m(t,c,l)),t})),oe(`'${Object.keys(v).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return oe(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return oe(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},w=e=>{var t;const n=h[e.clientIdentifier],r=G(e);if(!n)return;const i=`${n.userId}_${null!==(t=re(n))&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(R("start",[n],(new Date).toISOString(),r),!r){let t,r;if(oe(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,R("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void x(n,i)}j(r,(()=>[n]),((t,n)=>{o&&(o.response=n),W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started heartbeat request.",n)},O=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=A(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void x(t,s)}if(j(n,(()=>[t]),((t,n)=>{W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started leave request.",t),void 0===i)return;const s=P(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),S(i),k(s)},$=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,S(n))},k=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}if(!n||!t)return;const r={type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n};q([[t,r]],r)},j=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(C(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),T(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(R("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},S=e=>{if(0===P(e).length){const t=f.get(e);f.delete(e),delete v[e],t&&t.abort("Cancel request")}},T=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),P=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete v[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},C=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${le(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},K=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=z(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=B(u,e);if(s){const e=v[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||te(e.channels,n))&&(!(r.length>0)||te(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),y=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(y.add,y);const n=t.serviceRequestId;t.serviceRequestId=a,n&&v[n]&&S(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=v[a])&&void 0!==r?r:v[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(y.size){q.channels=Array.from(y).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}if(b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h)),d.queryParameters&&d.queryParameters.auth){const e=ie(u);e&&(d.queryParameters.auth=e)}}else v[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};v[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(v[a].region=d.queryParameters.tr),v[a].timetokenOverride=f,v[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)ce(v[a],`Started aggregated request for clients: ${b}`,e);return d},G=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=X(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=re(o))&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,y=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=te(e,o.heartbeat.channels)&&te(t,o.heartbeat.channelGroups),n&&(y=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;if(g){const t=u[a].timestamp+1e3*o.heartbeatInterval,n=Date.now();if(!y&&n5e3)return;delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}if(d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,c.length>1&&l.queryParameters&&l.queryParameters.auth){const e=ie(c);e&&(l.queryParameters.auth=e)}return l},A=e=>{const t=h[e.clientIdentifier],n=Y(e);let r=ee(e.request),i=Z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!e.endsWith("-pnpres")&&!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")&&!n.channelGroups.includes(e))))))}if(i.length&&(i=i.filter((e=>!e.endsWith("-pnpres")))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")))),0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}if(r.length&&(s.queryParameters["channel-group"]=r.join(",")),n.length>1&&s.queryParameters&&s.queryParameters.auth){const e=ie(n);e&&(s.queryParameters.auth=e)}return s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");oe(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},x=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},R=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});x(e,t)}}},W=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?D(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)oe(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)oe(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});x(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&oe(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},F=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=y[s=e.subscriptionKey])&&void 0!==n?n:y[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)oe(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)oe(`Setup PubNub client ping event ${n} seconds`,e);a[t]=setTimeout((()=>ne(t)),500*n-1)}},U=e=>{H(e.subscriptionKey,e.clientIdentifier)},V=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,y,v,q,I,m,w;const O=e.request.queryParameters,{clientIdentifier:$}=e,k=h[$];if(!k)return;const j=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let T=k.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(v=null!==(s=g[y=k.subscriptionKey])&&void 0!==s?s:g[y]={})[q=k.userId])&&void 0!==o?o:v[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=k.subscriptionKey])&&void 0!==c?c:g[I]={})[w=k.userId])&&void 0!==l?l:m[w]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=k.subscriptionKey])&&void 0!==r?r:g[f]={})[b=k.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}k.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=Z(e.request)),T.channelGroupQuery!==j&&(T.channelGroupQuery=j,T.channelGroups=ee(e.request));const{authKey:P,userId:E}=k;T.request=e.request,T.filterExpression=null!==(u=O["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(T.region=O.tr),k.authKey=null!==(d=O.auth)&&void 0!==d?d:"",k.origin=e.request.origin,k.userId=O.uuid,k.pnsdk=O.pnsdk,k.accessToken=e.token,M(k,E,P)},N=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=ee(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=Z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i,s;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const o=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},c=`${t}_${null!==(s=re(e))&&void 0!==s?s:""}`;void 0!==o[c]&&delete o[c]},J=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},H=(e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r){if(r.subscription){const{serviceRequestId:e}=r.subscription;delete r.subscription.serviceRequestId,e&&S(e)}r.unsubscribeOfflineClients&&_(r)}if(i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)oe(s,e);else oe(s)},_=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r,serviceRequestId:i}=e.subscription,s=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort(),o=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort();if(0===o.length&&0===s.length)return;const l=s.length>0?s.join(","):void 0,u=0===o.length?",":o.join(","),a=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),l?{"channel-group":l}:{}),d={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${u}/leave`,queryParameters:a,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:a.requestid}};O(d,e)},Q=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},B=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return oe(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=v[e.serviceRequestId];if(s||(s=ee(t.request)),o||(o=Z(t.request)),o.length&&!te(r.channels,o))continue;if(s.length&&!te(r.channelGroups,s))continue;return ce(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},z=(e,t)=>{var n,r;const i=h[t.clientIdentifier];if(!i)return[];const s=t.request.queryParameters,o=re(i),c=null!==(n=s["filter-expr"])&&void 0!==n?n:"",l=s.uuid;return(null!==(r=p[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===l&&re(t)===o&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===c&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},X=e=>Y(e),Y=e=>{var t;const n=h[e.clientIdentifier];if(!n)return[];const r=e.request.queryParameters,i=re(n),s=r.uuid;return(null!==(t=p[e.subscriptionKey])&&void 0!==t?t:[]).filter((e=>e.userId===s&&re(e)===i))},Z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},ee=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},te=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ne=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)oe(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);H(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,x(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ne(e)),500*t-1)}},re=e=>{var t;return e.accessToken&&null!==(t=e.accessToken.token)&&void 0!==t?t:e.authKey},ie=e=>{const t=e.filter((e=>!!e.accessToken)).sort(((e,t)=>e.accessToken.expiration-t.accessToken.expiration)).pop();return t?t.authKey:void 0},se=e=>{const t=re(e);let n=`${e.userId}-${e.subscriptionKey}${t?`-${t}`:""}`;return e.subscription&&e.subscription.filterExpression&&(n+=`-${e.subscription.filterExpression}`),n},oe=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&x(e,r)}))},ce=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&x(e,i)}))},le=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${ue(e)}`)).join("&"):`${t}=${ue(n)}`})).join("&"),ue=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},y={},v={};self.onconnect=e=>{oe("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!Q(t))return;const n=t.data;if("client-register"===n.type)n.port=e,F(n),oe(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-unregister"===n.type)U(n);else if("client-pong"===n.type)J(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){V(n);const e=h[n.clientIdentifier];if(e){const t=se(e);let r=[];if(l.has(t)&&(r=l.get(t)[0]),r.push([e,n]),!l.has(t)){const e=setTimeout((()=>{q(r,n),l.delete(t)}),50);l.set(t,[r,e])}}}else n.request.path.endsWith("/heartbeat")?(N(n),w(n)):O(n);else"cancel-request"===n.type&&$(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=(e,t)=>{const n=C(t),r=h[t.clientIdentifier];r&&(e=e.filter((e=>e[0].clientIdentifier!==r.clientIdentifier)),I(r,t,n,!0),e.forEach((([e,t])=>I(e,t,n,!1))))},I=(e,t,n,r)=>{var i;let s=!1;if(r||"string"==typeof n||(n=n.identifier),e.subscription&&(s="0"===e.subscription.timetoken),x("start",[e],(new Date).toISOString(),t.request),"string"==typeof n){const r=v[n];if(e){if(e.subscription&&(e.subscription.timetoken=r.timetoken,e.subscription.region=r.region,e.subscription.serviceRequestId=n),!s)return;const o=(new TextEncoder).encode(`{"t":{"t":"${r.timetoken}","r":${null!==(i=r.region)&&void 0!==i?i:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${t.request.origin}${t.request.path}`,u.clientIdentifier=t.clientIdentifier,u.identifier=t.request.identifier,x("end",[e],(new Date).toISOString(),t.request,o,c.get("Content-Type"),0),A(e,u)}return}t.request.cancellable&&f.set(n.identifier,new AbortController);const o=v[n.identifier],{timetokenOverride:c,regionOverride:l}=o;j(n,(()=>P(n.identifier)),((e,r)=>{W(e,r,t.request),E(e,n.identifier)}),((e,r)=>{W(e,null,t.request,D(r)),E(e,n.identifier)}),(e=>{let t=e;return s&&c&&"0"!==c&&(t=m(t,c,l)),t})),oe(`'${Object.keys(v).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return oe(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return oe(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},w=e=>{var t;const n=h[e.clientIdentifier],r=G(e);if(!n)return;const i=`${n.userId}_${null!==(t=re(n))&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(x("start",[n],(new Date).toISOString(),r),!r){let t,r;if(oe(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`,n),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,x("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}j(r,(()=>[n]),((t,n)=>{o&&(o.response=n),W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started heartbeat request.",n)},O=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=R(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(j(n,(()=>[t]),((t,n)=>{W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started leave request.",t),void 0===i)return;const s=P(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),S(i),k(s)},$=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,S(n))},k=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}if(!n||!t)return;const r={type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n};q([[t,r]],r)},j=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(K(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),T(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},S=e=>{if(0===P(e).length){const t=f.get(e);f.delete(e),delete v[e],t&&t.abort("Cancel request")}},T=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),P=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete v[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},K=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${le(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},C=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=z(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=B(u,e);if(s){const e=v[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||te(e.channels,n))&&(!(r.length>0)||te(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),y=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(y.add,y);const n=t.serviceRequestId;t.serviceRequestId=a,n&&v[n]&&S(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=v[a])&&void 0!==r?r:v[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(y.size){q.channels=Array.from(y).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}if(b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h)),d.queryParameters&&d.queryParameters.auth){const e=ie(u);e&&(d.queryParameters.auth=e)}}else v[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};v[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(v[a].region=d.queryParameters.tr),v[a].timetokenOverride=f,v[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)ce(v[a],`Started aggregated request for clients: ${b}`,e);return d},G=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=X(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=re(o))&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,y=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=te(e,f)&&te(t,d),n&&(y=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;let v=o.heartbeatInterval;for(const e of c)e.heartbeatInterval&&(v=Math.min(v,e.heartbeatInterval));if(g){const e=u[a].timestamp+1e3*v,t=Date.now();if(!y&&t5e3)return}delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}if(d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,c.length>1&&l.queryParameters&&l.queryParameters.auth){const e=ie(c);e&&(l.queryParameters.auth=e)}return l},R=e=>{const t=h[e.clientIdentifier],n=Y(e);let r=ee(e.request),i=Z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!e.endsWith("-pnpres")&&!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")&&!n.channelGroups.includes(e))))))}if(i.length&&(i=i.filter((e=>!e.endsWith("-pnpres")))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")))),0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}if(r.length&&(s.queryParameters["channel-group"]=r.join(",")),n.length>1&&s.queryParameters&&s.queryParameters.auth){const e=ie(n);e&&(s.queryParameters.auth=e)}return s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");oe(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},x=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},W=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?D(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)oe(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)oe(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&oe(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},F=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,newlyRegistered:!0,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=y[s=e.subscriptionKey])&&void 0!==n?n:y[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)oe(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)oe(`Setup PubNub client ping event ${n} seconds`,e);a[t]=setTimeout((()=>ne(t)),500*n-1)}},U=e=>{H(e.subscriptionKey,e.clientIdentifier)},V=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,y,v,q,I,m,w;const O=e.request.queryParameters,{clientIdentifier:$}=e,k=h[$];if(!k)return;const j=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let T=k.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(v=null!==(s=g[y=k.subscriptionKey])&&void 0!==s?s:g[y]={})[q=k.userId])&&void 0!==o?o:v[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=k.subscriptionKey])&&void 0!==c?c:g[I]={})[w=k.userId])&&void 0!==l?l:m[w]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=k.subscriptionKey])&&void 0!==r?r:g[f]={})[b=k.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}k.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=Z(e.request)),T.channelGroupQuery!==j&&(T.channelGroupQuery=j,T.channelGroups=ee(e.request));let{authKey:P}=k;const{userId:E}=k;T.request=e.request,T.filterExpression=null!==(u=O["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(T.region=O.tr),k.authKey=null!==(d=O.auth)&&void 0!==d?d:"",k.origin=e.request.origin,k.userId=O.uuid,k.pnsdk=O.pnsdk,k.accessToken=e.token,k.newlyRegistered&&!P&&k.authKey&&(P=k.authKey),k.newlyRegistered=!1,M(k,E,P)},N=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=ee(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=Z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i,s;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const o=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},c=`${t}_${null!==(s=re(e))&&void 0!==s?s:""}`;void 0!==o[c]&&delete o[c]},J=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},H=(e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r){if(r.subscription){const{serviceRequestId:e}=r.subscription;delete r.subscription.serviceRequestId,e&&S(e)}r.unsubscribeOfflineClients&&_(r)}if(i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)oe(s,e);else oe(s)},_=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r,serviceRequestId:i}=e.subscription,s=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort(),o=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort();if(0===o.length&&0===s.length)return;const l=s.length>0?s.join(","):void 0,u=0===o.length?",":o.join(","),a=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),l?{"channel-group":l}:{}),d={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${u}/leave`,queryParameters:a,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:a.requestid}};O(d,e)},Q=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},B=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return oe(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=v[e.serviceRequestId];if(s||(s=ee(t.request)),o||(o=Z(t.request)),o.length&&!te(r.channels,o))continue;if(s.length&&!te(r.channelGroups,s))continue;return ce(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},z=(e,t)=>{var n,r;const i=h[t.clientIdentifier];if(!i)return[];const s=t.request.queryParameters,o=re(i),c=null!==(n=s["filter-expr"])&&void 0!==n?n:"",l=s.uuid;return(null!==(r=p[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===l&&re(t)===o&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===c&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},X=e=>Y(e),Y=e=>{var t;const n=h[e.clientIdentifier];if(!n)return[];const r=e.request.queryParameters,i=re(n),s=r.uuid;return(null!==(t=p[e.subscriptionKey])&&void 0!==t?t:[]).filter((e=>e.userId===s&&re(e)===i))},Z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},ee=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},te=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ne=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)oe(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);H(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ne(e)),500*t-1)}},re=e=>{var t;return e.accessToken&&null!==(t=e.accessToken.token)&&void 0!==t?t:e.authKey},ie=e=>{const t=e.filter((e=>!!e.accessToken)).sort(((e,t)=>e.accessToken.expiration-t.accessToken.expiration)).pop();return t?t.authKey:void 0},se=e=>{const t=re(e);let n=`${e.userId}-${e.subscriptionKey}${t?`-${t}`:""}`;return e.subscription&&e.subscription.filterExpression&&(n+=`-${e.subscription.filterExpression}`),n},oe=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},ce=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},le=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${ue(e)}`)).join("&"):`${t}=${ue(n)}`})).join("&"),ue=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 61952e3f3..776ba1fff 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -124,7 +124,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '9.2.0'; + return '9.3.0'; }, getVersion() { return this.version; diff --git a/lib/core/interfaces/configuration.js b/lib/core/interfaces/configuration.js index 4bea7594f..89739eeb3 100644 --- a/lib/core/interfaces/configuration.js +++ b/lib/core/interfaces/configuration.js @@ -91,9 +91,9 @@ const FILE_REQUEST_TIMEOUT = 300; */ const PRESENCE_TIMEOUT = 300; /** - * Minimum user presence timeout. + * Maximum user presence timeout. */ -const PRESENCE_TIMEOUT_MINIMUM = 20; +const PRESENCE_TIMEOUT_MAXIMUM = 320; /** * Apply configuration default values. * @@ -134,10 +134,17 @@ const setDefaults = (configuration) => { publishKey: configurationCopy.publishKey, secretKey: configurationCopy.secretKey, }; - if (configurationCopy.presenceTimeout !== undefined && configurationCopy.presenceTimeout < PRESENCE_TIMEOUT_MINIMUM) { - configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; - // eslint-disable-next-line no-console - console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); + if (configurationCopy.presenceTimeout !== undefined) { + if (configurationCopy.presenceTimeout > PRESENCE_TIMEOUT_MAXIMUM) { + configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MAXIMUM; + // eslint-disable-next-line no-console + console.warn('WARNING: Presence timeout is larger than the maximum. Using maximum value: ', PRESENCE_TIMEOUT_MAXIMUM); + } + else if (configurationCopy.presenceTimeout <= 0) { + // eslint-disable-next-line no-console + console.warn('WARNING: Presence timeout should be larger than zero.'); + delete configurationCopy.presenceTimeout; + } } if (configurationCopy.presenceTimeout !== undefined) configurationCopy.heartbeatInterval = configurationCopy.presenceTimeout / 2 - 1; diff --git a/package.json b/package.json index d968a38a6..99e826923 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "9.2.0", + "version": "9.3.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 1675c0a26..0fd596bad 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -182,7 +182,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '9.2.0'; + return '9.3.0'; }, getVersion(): string { return this.version; diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index f9018752c..ddd18ffbf 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -115,9 +115,9 @@ const FILE_REQUEST_TIMEOUT = 300; const PRESENCE_TIMEOUT = 300; /** - * Minimum user presence timeout. + * Maximum user presence timeout. */ -const PRESENCE_TIMEOUT_MINIMUM = 20; +const PRESENCE_TIMEOUT_MAXIMUM = 320; // endregion /** @@ -786,10 +786,19 @@ export const setDefaults = (configuration: UserConfiguration): ExtendedConfigura secretKey: configurationCopy.secretKey, }; - if (configurationCopy.presenceTimeout !== undefined && configurationCopy.presenceTimeout < PRESENCE_TIMEOUT_MINIMUM) { - configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MINIMUM; - // eslint-disable-next-line no-console - console.log('WARNING: Presence timeout is less than the minimum. Using minimum value: ', PRESENCE_TIMEOUT_MINIMUM); + if (configurationCopy.presenceTimeout !== undefined) { + if (configurationCopy.presenceTimeout > PRESENCE_TIMEOUT_MAXIMUM) { + configurationCopy.presenceTimeout = PRESENCE_TIMEOUT_MAXIMUM; + // eslint-disable-next-line no-console + console.warn( + 'WARNING: Presence timeout is larger than the maximum. Using maximum value: ', + PRESENCE_TIMEOUT_MAXIMUM, + ); + } else if (configurationCopy.presenceTimeout <= 0) { + // eslint-disable-next-line no-console + console.warn('WARNING: Presence timeout should be larger than zero.'); + delete configurationCopy.presenceTimeout; + } } if (configurationCopy.presenceTimeout !== undefined) diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index 02e6edb3e..a7baac897 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -424,6 +424,11 @@ type PubNubClientState = { */ heartbeatInterval?: number; + /** + * Whether instance registered for the first time or not. + */ + newlyRegistered: boolean; + /** * Whether verbose logging enabled or not. */ @@ -932,6 +937,7 @@ const handleHeartbeatRequestEvent = (event: SendRequestEvent) => { if (!request) { consoleLog( `Previous heartbeat request has been sent less than ${client.heartbeatInterval} seconds ago. Skipping...`, + client, ); let response: Response | undefined; @@ -1472,38 +1478,43 @@ const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportR const { channels, channelGroups, response } = hbRequestsBySubscriptionKey[heartbeatRequestKey]; aggregatedState = client.heartbeat.presenceState ?? {}; aggregated = - includesStrings(channels, client.heartbeat.channels) && - includesStrings(channelGroups, client.heartbeat.channelGroups); + includesStrings(channels, channelsForAnnouncement) && + includesStrings(channelGroups, channelGroupsForAnnouncement); if (response) failedPreviousRequest = response[0].status >= 400; } + // Find minimum heartbeat interval which maybe required to use. + let minimumHeartbeatInterval = client.heartbeatInterval!; + for (const client of clients) { + if (client.heartbeatInterval) + minimumHeartbeatInterval = Math.min(minimumHeartbeatInterval, client.heartbeatInterval); + } + if (aggregated) { const expectedTimestamp = - hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp + client.heartbeatInterval! * 1000; + hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp + minimumHeartbeatInterval * 1000; const currentTimestamp = Date.now(); // Check whether it is too soon to send request or not (5 is leeway which let send request a bit earlier). // Request should be sent if previous attempt failed. if (!failedPreviousRequest && currentTimestamp < expectedTimestamp && expectedTimestamp - currentTimestamp > 5000) return undefined; + } - delete hbRequestsBySubscriptionKey[heartbeatRequestKey].response; + delete hbRequestsBySubscriptionKey[heartbeatRequestKey]!.response; - // Aggregate channels for similar clients which is pending for heartbeat. - for (const client of clients) { - const { heartbeat } = client; - if (heartbeat === undefined || client.clientIdentifier === event.clientIdentifier) continue; + // Aggregate channels for similar clients which is pending for heartbeat. + for (const client of clients) { + const { heartbeat } = client; + if (heartbeat === undefined || client.clientIdentifier === event.clientIdentifier) continue; - // Append presence state from the client (will override previously set value if already set). - if (heartbeat.presenceState) aggregatedState = { ...aggregatedState, ...heartbeat.presenceState }; + // Append presence state from the client (will override previously set value if already set). + if (heartbeat.presenceState) aggregatedState = { ...aggregatedState, ...heartbeat.presenceState }; - channelGroupsForAnnouncement.push( - ...heartbeat.channelGroups.filter((channel) => !channelGroupsForAnnouncement.includes(channel)), - ); - channelsForAnnouncement.push( - ...heartbeat.channels.filter((channel) => !channelsForAnnouncement.includes(channel)), - ); - } + channelGroupsForAnnouncement.push( + ...heartbeat.channelGroups.filter((channel) => !channelGroupsForAnnouncement.includes(channel)), + ); + channelsForAnnouncement.push(...heartbeat.channels.filter((channel) => !channelsForAnnouncement.includes(channel))); } hbRequestsBySubscriptionKey[heartbeatRequestKey].channels = channelsForAnnouncement; @@ -1910,6 +1921,7 @@ const registerClientIfRequired = (event: RegisterEvent) => { subscriptionKey: event.subscriptionKey, userId: event.userId, heartbeatInterval: event.heartbeatInterval, + newlyRegistered: true, logVerbosity: event.logVerbosity, offlineClientsCheckInterval: event.workerOfflineClientsCheckInterval, unsubscribeOfflineClients: event.workerUnsubscribeOfflineClients, @@ -2027,7 +2039,8 @@ const updateClientSubscribeStateIfRequired = (event: SendRequestEvent) => { subscription.channelGroups = channelGroupsFromRequest(event.request); } - const { authKey, userId } = client; + let { authKey } = client; + const { userId } = client; subscription.request = event.request; subscription.filterExpression = (query['filter-expr'] ?? '') as string; subscription.timetoken = (query.tt ?? '0') as string; @@ -2038,6 +2051,9 @@ const updateClientSubscribeStateIfRequired = (event: SendRequestEvent) => { client.pnsdk = query.pnsdk as string; client.accessToken = event.token; + if (client.newlyRegistered && !authKey && client.authKey) authKey = client.authKey; + client.newlyRegistered = false; + handleClientIdentityChangeIfRequired(client, userId, authKey); }; From c51bb05e8757afc244fa0677c2540a93a936dcc9 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 25 Mar 2025 13:24:30 +0200 Subject: [PATCH 44/49] Fix heartbeat cached channels and groups (#447) fix(shared-worker): fix heartbeat cached channels and groups Fix issue because of which channels and groups aggregated inside PubNub client state objects and didn't clean up properly on unsubscribe / invalidate. refactor(subscription-set): refactor subscriptions manipulation Refactor how subscription set updated with additional / removal other subscriptions and sets. --- .pubnub.yml | 11 ++- CHANGELOG.md | 6 ++ README.md | 4 +- dist/web/pubnub.js | 73 +++++++------- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 81 +++++++++++---- dist/web/pubnub.worker.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/entities/SubscriptionSet.js | 71 ++++++------- lib/types/index.d.ts | 2 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/interfaces/configuration.ts | 2 +- src/entities/SubscriptionSet.ts | 99 +++++++++---------- .../subscription-worker.ts | 91 +++++++++++++---- 15 files changed, 277 insertions(+), 177 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 060c2ca50..b7f47d281 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2025-03-25 + version: v9.3.1 + changes: + - type: bug + text: "Fix issue because of which channels and groups aggregated inside PubNub client state objects and didn't clean up properly on unsubscribe / invalidate." - date: 2025-03-20 version: v9.3.0 changes: @@ -1192,7 +1197,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '9.3.0' +version: '9.3.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1208,7 +1213,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v9.3.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.3.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1879,7 +1884,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v9.3.0/pubnub.9.3.0.js + location: https://github.com/pubnub/javascript/releases/download/v9.3.1/pubnub.9.3.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 73ab8ede8..c4cf21afc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v9.3.1 +March 25 2025 + +#### Fixed +- Fix issue because of which channels and groups aggregated inside PubNub client state objects and didn't clean up properly on unsubscribe / invalidate. + ## v9.3.0 March 20 2025 diff --git a/README.md b/README.md index 2d4100037..3524560a3 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 2e0c8e347..24ba3c5f2 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3939,7 +3939,7 @@ return base.PubNubFile; }, get version() { - return '9.3.0'; + return '9.3.1'; }, getVersion() { return this.version; @@ -10424,18 +10424,11 @@ this.options = subscriptionOptions; this.eventEmitter = eventEmitter; this.pubnub = pubnub; - channels.forEach((c) => { - const subscription = this.pubnub.channel(c).subscription(this.options); - this.channelNames = [...this.channelNames, ...subscription.channels]; - this.subscriptionList.push(subscription); - }); - channelGroups.forEach((cg) => { - const subscription = this.pubnub.channelGroup(cg).subscription(this.options); - this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.subscriptionList.push(subscription); - }); + channels.forEach((c) => this.subscriptionList.push(this.pubnub.channel(c).subscription(this.options))); + channelGroups.forEach((cg) => this.subscriptionList.push(this.pubnub.channelGroup(cg).subscription(this.options))); this.typeBasedListener = {}; this.typeBasedListenerId = eventEmitter.addListener(this.typeBasedListener, this.channelNames, this.groupNames); + this.updateListeners(); } /** * Add additional entity's subscription to the subscription set. @@ -10446,10 +10439,8 @@ * @param subscription - Other entity's subscription object, which should be added. */ addSubscription(subscription) { - this.subscriptionList.push(subscription); - this.channelNames = [...this.channelNames, ...subscription.channels]; - this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.eventEmitter.addListener(this.typeBasedListener, subscription.channels, subscription.channelGroups, this.typeBasedListenerId); + if (!this.subscriptionList.includes(subscription)) + this.subscriptionList.push(subscription); // Make sure to listen events on channels / groups added with `subscription`. this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. @@ -10469,12 +10460,7 @@ * @param subscription - Other entity's subscription object, which should be removed. */ removeSubscription(subscription) { - const channelsToRemove = subscription.channels; - const groupsToRemove = subscription.channelGroups; - this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); - this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); - this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); - this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + this.subscriptionList = this.subscriptionList.filter((sub) => sub !== subscription); // Make sure to stop listening for events from channels / groups removed with `subscription`. this.updateListeners(); // @ts-expect-error: Required access of protected field. @@ -10490,10 +10476,7 @@ * @param subscriptionSet - Other entities' subscription set, which should be joined. */ addSubscriptionSet(subscriptionSet) { - this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; - this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; - this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; - this.eventEmitter.addListener(this.typeBasedListener, subscriptionSet.channels, subscriptionSet.channelGroups, this.typeBasedListenerId); + this.subscriptionList = Array.from(new Set([...this.subscriptionList, ...subscriptionSet.subscriptions])); // Make sure to listen events on channels / groups added with `subscription set`. this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. @@ -10511,12 +10494,7 @@ * @param subscriptionSet - Other entities' subscription set, which should be subtracted. */ removeSubscriptionSet(subscriptionSet) { - const channelsToRemove = subscriptionSet.channels; - const groupsToRemove = subscriptionSet.channelGroups; - this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); - this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); - this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); - this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + this.subscriptionList = this.subscriptionList.filter((sub) => !subscriptionSet.subscriptions.includes(sub)); // Make sure to stop listening for events from channels / groups removed with `subscription set`. this.updateListeners(); if (subscriptionSet.subscribedAutomatically) @@ -10540,11 +10518,36 @@ * @internal */ updateListeners() { - if (!this.aggregatedListener) - return; + // Actual list of channels and groups. + const channelGroups = []; + const channels = []; + // Gather actual information about active channels / groups. + this.subscriptionList.forEach((subscription) => { + if (subscription.channelGroups.length) + channelGroups.push(...subscription.channelGroups); + if (subscription.channels.length) + channels.push(...subscription.channels); + }); + // Identify channels / groups which should be added / removed. + const channelsToRemove = this.channelNames.filter((channel) => !channels.includes(channel)); + const groupsToRemove = this.groupNames.filter((group) => !channelGroups.includes(group)); + const channelsToAdd = channels.filter((channel) => !this.channelNames.includes(channel)); + const groupsToAdd = channelGroups.filter((group) => !this.groupNames.includes(group)); + // Removing type-based listener for unused channels / groups. + if (channelsToRemove.length || groupsToRemove.length) { + this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + } + // Adding type-based listener for unused channels / groups. + if (channelsToAdd.length || groupsToAdd.length) + this.eventEmitter.addListener(this.typeBasedListener, channelsToAdd, groupsToAdd, this.typeBasedListenerId); const aggregatedListener = this.aggregatedListener; - this.removeListener(this.aggregatedListener); - this.addListener(aggregatedListener); + if (aggregatedListener) + this.removeListener(aggregatedListener); + // Set actual list of channels and groups. + this.groupNames = channelGroups; + this.channelNames = channels; + if (aggregatedListener) + this.addListener(aggregatedListener); } } diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 30b9543d3..b9298d9e1 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),O=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],O=e[i+15],E=t(E=a[0],P=a[1],N=a[2],C=a[3],c,7,u[0]),C=t(C,E,P,N,o,12,u[1]),N=t(N,C,E,P,l,17,u[2]),P=t(P,N,C,E,h,22,u[3]);E=t(E,P,N,C,d,7,u[4]),C=t(C,E,P,N,p,12,u[5]),N=t(N,C,E,P,g,17,u[6]),P=t(P,N,C,E,y,22,u[7]),E=t(E,P,N,C,f,7,u[8]),C=t(C,E,P,N,b,12,u[9]),N=t(N,C,E,P,m,17,u[10]),P=t(P,N,C,E,v,22,u[11]),E=t(E,P,N,C,w,7,u[12]),C=t(C,E,P,N,S,12,u[13]),N=t(N,C,E,P,k,17,u[14]),E=n(E,P=t(P,N,C,E,O,22,u[15]),N,C,o,5,u[16]),C=n(C,E,P,N,g,9,u[17]),N=n(N,C,E,P,v,14,u[18]),P=n(P,N,C,E,c,20,u[19]),E=n(E,P,N,C,p,5,u[20]),C=n(C,E,P,N,m,9,u[21]),N=n(N,C,E,P,O,14,u[22]),P=n(P,N,C,E,d,20,u[23]),E=n(E,P,N,C,b,5,u[24]),C=n(C,E,P,N,k,9,u[25]),N=n(N,C,E,P,h,14,u[26]),P=n(P,N,C,E,f,20,u[27]),E=n(E,P,N,C,S,5,u[28]),C=n(C,E,P,N,l,9,u[29]),N=n(N,C,E,P,y,14,u[30]),E=s(E,P=n(P,N,C,E,w,20,u[31]),N,C,p,4,u[32]),C=s(C,E,P,N,f,11,u[33]),N=s(N,C,E,P,v,16,u[34]),P=s(P,N,C,E,k,23,u[35]),E=s(E,P,N,C,o,4,u[36]),C=s(C,E,P,N,d,11,u[37]),N=s(N,C,E,P,y,16,u[38]),P=s(P,N,C,E,m,23,u[39]),E=s(E,P,N,C,S,4,u[40]),C=s(C,E,P,N,c,11,u[41]),N=s(N,C,E,P,h,16,u[42]),P=s(P,N,C,E,g,23,u[43]),E=s(E,P,N,C,b,4,u[44]),C=s(C,E,P,N,w,11,u[45]),N=s(N,C,E,P,O,16,u[46]),E=r(E,P=s(P,N,C,E,l,23,u[47]),N,C,c,6,u[48]),C=r(C,E,P,N,y,10,u[49]),N=r(N,C,E,P,k,15,u[50]),P=r(P,N,C,E,p,21,u[51]),E=r(E,P,N,C,w,6,u[52]),C=r(C,E,P,N,h,10,u[53]),N=r(N,C,E,P,m,15,u[54]),P=r(P,N,C,E,o,21,u[55]),E=r(E,P,N,C,f,6,u[56]),C=r(C,E,P,N,O,10,u[57]),N=r(N,C,E,P,g,15,u[58]),P=r(P,N,C,E,S,21,u[59]),E=r(E,P,N,C,d,6,u[60]),C=r(C,E,P,N,v,10,u[61]),N=r(N,C,E,P,l,15,u[62]),P=r(P,N,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+P|0,a[2]=a[2]+N|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=N.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}N.IV_LENGTH=16,N.encoder=new TextEncoder,N.decoder=new TextDecoder;class P{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new N}encrypt(e){const t="string"==typeof e?e:P.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}P.encoder=new TextEncoder,P.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new P(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,O=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(O=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:O,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.3.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Ne=ge("LEFT_ALL",(()=>({}))),Pe=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Pe(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Ne.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Pe.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Ne.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ne())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Nt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Pt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>{const t=this.pubnub.channel(e).subscription(this.options);this.channelNames=[...this.channelNames,...t.channels],this.subscriptionList.push(t)})),t.forEach((e=>{const t=this.pubnub.channelGroup(e).subscription(this.options);this.groupNames=[...this.groupNames,...t.channelGroups],this.subscriptionList.push(t)})),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){this.subscriptionList.push(e),this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=[...this.subscriptionList,...e.subscriptions],this.channelNames=[...this.channelNames,...e.channels],this.groupNames=[...this.groupNames,...e.channelGroups],this.eventEmitter.addListener(this.typeBasedListener,e.channels,e.channelGroups,this.typeBasedListenerId),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){const t=e.channels,n=e.channelGroups;this.channelNames=this.channelNames.filter((e=>!t.includes(e))),this.groupNames=this.groupNames.filter((e=>!n.includes(e))),this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,t,n),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){if(!this.aggregatedListener)return;const e=this.aggregatedListener;this.removeListener(this.aggregatedListener),this.addListener(e)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Nn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Pn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Nn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Nt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Pt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Pn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends An{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new P(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new N;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),O=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],O=e[i+15],E=t(E=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,E,N,P,o,12,u[1]),P=t(P,C,E,N,l,17,u[2]),N=t(N,P,C,E,h,22,u[3]);E=t(E,N,P,C,d,7,u[4]),C=t(C,E,N,P,p,12,u[5]),P=t(P,C,E,N,g,17,u[6]),N=t(N,P,C,E,y,22,u[7]),E=t(E,N,P,C,f,7,u[8]),C=t(C,E,N,P,b,12,u[9]),P=t(P,C,E,N,m,17,u[10]),N=t(N,P,C,E,v,22,u[11]),E=t(E,N,P,C,w,7,u[12]),C=t(C,E,N,P,S,12,u[13]),P=t(P,C,E,N,k,17,u[14]),E=n(E,N=t(N,P,C,E,O,22,u[15]),P,C,o,5,u[16]),C=n(C,E,N,P,g,9,u[17]),P=n(P,C,E,N,v,14,u[18]),N=n(N,P,C,E,c,20,u[19]),E=n(E,N,P,C,p,5,u[20]),C=n(C,E,N,P,m,9,u[21]),P=n(P,C,E,N,O,14,u[22]),N=n(N,P,C,E,d,20,u[23]),E=n(E,N,P,C,b,5,u[24]),C=n(C,E,N,P,k,9,u[25]),P=n(P,C,E,N,h,14,u[26]),N=n(N,P,C,E,f,20,u[27]),E=n(E,N,P,C,S,5,u[28]),C=n(C,E,N,P,l,9,u[29]),P=n(P,C,E,N,y,14,u[30]),E=s(E,N=n(N,P,C,E,w,20,u[31]),P,C,p,4,u[32]),C=s(C,E,N,P,f,11,u[33]),P=s(P,C,E,N,v,16,u[34]),N=s(N,P,C,E,k,23,u[35]),E=s(E,N,P,C,o,4,u[36]),C=s(C,E,N,P,d,11,u[37]),P=s(P,C,E,N,y,16,u[38]),N=s(N,P,C,E,m,23,u[39]),E=s(E,N,P,C,S,4,u[40]),C=s(C,E,N,P,c,11,u[41]),P=s(P,C,E,N,h,16,u[42]),N=s(N,P,C,E,g,23,u[43]),E=s(E,N,P,C,b,4,u[44]),C=s(C,E,N,P,w,11,u[45]),P=s(P,C,E,N,O,16,u[46]),E=r(E,N=s(N,P,C,E,l,23,u[47]),P,C,c,6,u[48]),C=r(C,E,N,P,y,10,u[49]),P=r(P,C,E,N,k,15,u[50]),N=r(N,P,C,E,p,21,u[51]),E=r(E,N,P,C,w,6,u[52]),C=r(C,E,N,P,h,10,u[53]),P=r(P,C,E,N,m,15,u[54]),N=r(N,P,C,E,o,21,u[55]),E=r(E,N,P,C,f,6,u[56]),C=r(C,E,N,P,O,10,u[57]),P=r(P,C,E,N,g,15,u[58]),N=r(N,P,C,E,S,21,u[59]),E=r(E,N,P,C,d,6,u[60]),C=r(C,E,N,P,v,10,u[61]),P=r(P,C,E,N,l,15,u[62]),N=r(N,P,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,O=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(O=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:O,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.3.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Pe=ge("LEFT_ALL",(()=>({}))),Ne=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Pe.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Pe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Pt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Nt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Pn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Nn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Pn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Nn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends An{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index 3b28d7e06..744e372c2 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -404,7 +404,7 @@ const heartbeatRequestKey = `${client.userId}_${(_a = clientAggregateAuthKey(client)) !== null && _a !== void 0 ? _a : ''}`; const hbRequestsBySubscriptionKey = serviceHeartbeatRequests[client.subscriptionKey]; const hbRequests = (hbRequestsBySubscriptionKey !== null && hbRequestsBySubscriptionKey !== void 0 ? hbRequestsBySubscriptionKey : {})[heartbeatRequestKey]; - notifyRequestProcessing('start', [client], new Date().toISOString(), request); + notifyRequestProcessing('start', [client], new Date().toISOString(), event.request); if (!request) { consoleLog(`Previous heartbeat request has been sent less than ${client.heartbeatInterval} seconds ago. Skipping...`, client); let response; @@ -446,22 +446,31 @@ * @param [client] - Specific client to handle leave request. */ const handleSendLeaveRequestEvent = (data, client) => { + var _a, _b; + var _c; client = client !== null && client !== void 0 ? client : pubNubClients[data.clientIdentifier]; const request = leaveTransportRequestFromEvent(data); if (!client) return; // Clean up client subscription information if there is no more channels / groups to use. - const { subscription } = client; + const { subscription, heartbeat } = client; const serviceRequestId = subscription === null || subscription === void 0 ? void 0 : subscription.serviceRequestId; - if (subscription) { - if (subscription.channels.length === 0 && subscription.channelGroups.length === 0) { - subscription.channelGroupQuery = ''; - subscription.path = ''; - subscription.previousTimetoken = '0'; - subscription.timetoken = '0'; - delete subscription.region; - delete subscription.serviceRequestId; - delete subscription.request; + if (subscription && subscription.channels.length === 0 && subscription.channelGroups.length === 0) { + subscription.channelGroupQuery = ''; + subscription.path = ''; + subscription.previousTimetoken = '0'; + subscription.timetoken = '0'; + delete subscription.region; + delete subscription.serviceRequestId; + delete subscription.request; + } + if (serviceHeartbeatRequests[client.subscriptionKey]) { + if (heartbeat && heartbeat.channels.length === 0 && heartbeat.channelGroups.length === 0) { + const hbRequestsBySubscriptionKey = ((_a = serviceHeartbeatRequests[_c = client.subscriptionKey]) !== null && _a !== void 0 ? _a : (serviceHeartbeatRequests[_c] = {})); + const heartbeatRequestKey = `${client.userId}_${(_b = clientAggregateAuthKey(client)) !== null && _b !== void 0 ? _b : ''}`; + if (hbRequestsBySubscriptionKey[heartbeatRequestKey] && + hbRequestsBySubscriptionKey[heartbeatRequestKey].clientIdentifier === client.clientIdentifier) + delete hbRequestsBySubscriptionKey[heartbeatRequestKey].clientIdentifier; } } if (!request) { @@ -837,8 +846,8 @@ return undefined; const hbRequestsBySubscriptionKey = ((_a = serviceHeartbeatRequests[_e = client.subscriptionKey]) !== null && _a !== void 0 ? _a : (serviceHeartbeatRequests[_e] = {})); const heartbeatRequestKey = `${client.userId}_${(_b = clientAggregateAuthKey(client)) !== null && _b !== void 0 ? _b : ''}`; - const channelGroupsForAnnouncement = client.heartbeat.channelGroups; - const channelsForAnnouncement = client.heartbeat.channels; + const channelGroupsForAnnouncement = [...client.heartbeat.channelGroups]; + const channelsForAnnouncement = [...client.heartbeat.channels]; let aggregatedState; let failedPreviousRequest = false; let aggregated; @@ -846,6 +855,7 @@ hbRequestsBySubscriptionKey[heartbeatRequestKey] = { channels: channelsForAnnouncement, channelGroups: channelGroupsForAnnouncement, + clientIdentifier: client.clientIdentifier, timestamp: Date.now(), }; aggregatedState = (_c = client.heartbeat.presenceState) !== null && _c !== void 0 ? _c : {}; @@ -866,7 +876,10 @@ if (client.heartbeatInterval) minimumHeartbeatInterval = Math.min(minimumHeartbeatInterval, client.heartbeatInterval); } - if (aggregated) { + // Check whether multiple instance aggregate heartbeat and there is previous sender known. + // `clientIdentifier` maybe empty in case if client which triggered heartbeats before has been invalidated and new + // should handle heartbeat unconditionally. + if (aggregated && hbRequestsBySubscriptionKey[heartbeatRequestKey].clientIdentifier) { const expectedTimestamp = hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp + minimumHeartbeatInterval * 1000; const currentTimestamp = Date.now(); // Check whether it is too soon to send request or not (5 is leeway which let send request a bit earlier). @@ -875,10 +888,11 @@ return undefined; } delete hbRequestsBySubscriptionKey[heartbeatRequestKey].response; + hbRequestsBySubscriptionKey[heartbeatRequestKey].clientIdentifier = client.clientIdentifier; // Aggregate channels for similar clients which is pending for heartbeat. - for (const client of clients) { - const { heartbeat } = client; - if (heartbeat === undefined || client.clientIdentifier === event.clientIdentifier) + for (const _client of clients) { + const { heartbeat } = _client; + if (heartbeat === undefined || _client.clientIdentifier === event.clientIdentifier) continue; // Append presence state from the client (will override previously set value if already set). if (heartbeat.presenceState) @@ -894,10 +908,13 @@ if (!channelsForAnnouncement.includes(objectName) && !channelGroupsForAnnouncement.includes(objectName)) delete aggregatedState[objectName]; } + // No need to try send request with empty list of channels and groups. + if (channelsForAnnouncement.length === 0 && channelGroupsForAnnouncement.length === 0) + return undefined; // Update request channels list (if required). - if (channelsForAnnouncement.length) { + if (channelsForAnnouncement.length || channelGroupsForAnnouncement.length) { const pathComponents = request.path.split('/'); - pathComponents[6] = channelsForAnnouncement.join(','); + pathComponents[6] = channelsForAnnouncement.length ? channelsForAnnouncement.join(',') : ','; request.path = pathComponents.join('/'); } // Update request channel groups list (if required). @@ -927,6 +944,7 @@ * done. */ const leaveTransportRequestFromEvent = (event) => { + var _a; const client = pubNubClients[event.clientIdentifier]; const clients = clientsForSendLeaveRequestEvent(event); let channelGroups = channelGroupsFromRequest(event.request); @@ -977,6 +995,20 @@ } return undefined; } + // Update aggregated heartbeat state object. + if (client && serviceHeartbeatRequests[client.subscriptionKey] && (channels.length || channelGroups.length)) { + const hbRequestsBySubscriptionKey = serviceHeartbeatRequests[client.subscriptionKey]; + const heartbeatRequestKey = `${client.userId}_${(_a = clientAggregateAuthKey(client)) !== null && _a !== void 0 ? _a : ''}`; + if (hbRequestsBySubscriptionKey[heartbeatRequestKey]) { + let { channels: hbChannels, channelGroups: hbChannelGroups } = hbRequestsBySubscriptionKey[heartbeatRequestKey]; + if (channelGroups.length) + hbChannelGroups = hbChannelGroups.filter((group) => !channels.includes(group)); + if (channels.length) + hbChannels = hbChannels.filter((channel) => !channels.includes(channel)); + hbRequestsBySubscriptionKey[heartbeatRequestKey].channelGroups = hbChannelGroups; + hbRequestsBySubscriptionKey[heartbeatRequestKey].channels = hbChannels; + } + } // Update request channels list (if required). if (channels.length) { const pathComponents = request.path.split('/'); @@ -1419,7 +1451,7 @@ * @param clientId - Unique PubNub client identifier. */ const invalidateClient = (subscriptionKey, clientId) => { - var _a; + var _a, _b, _c; const invalidatedClient = pubNubClients[clientId]; delete pubNubClients[clientId]; let clients = pubNubClientsBySubscriptionKey[subscriptionKey]; @@ -1432,6 +1464,13 @@ if (serviceRequestId) cancelRequest(serviceRequestId); } + if (serviceHeartbeatRequests[subscriptionKey]) { + const hbRequestsBySubscriptionKey = ((_a = serviceHeartbeatRequests[subscriptionKey]) !== null && _a !== void 0 ? _a : (serviceHeartbeatRequests[subscriptionKey] = {})); + const heartbeatRequestKey = `${invalidatedClient.userId}_${(_b = clientAggregateAuthKey(invalidatedClient)) !== null && _b !== void 0 ? _b : ''}`; + if (hbRequestsBySubscriptionKey[heartbeatRequestKey] && + hbRequestsBySubscriptionKey[heartbeatRequestKey].clientIdentifier === invalidatedClient.clientIdentifier) + delete hbRequestsBySubscriptionKey[heartbeatRequestKey].clientIdentifier; + } // Leave subscribed channels / groups properly. if (invalidatedClient.unsubscribeOfflineClients) unsubscribeClient(invalidatedClient); @@ -1460,7 +1499,7 @@ else delete sharedWorkerClients[subscriptionKey]; } - const message = `Invalidate '${clientId}' client. '${((_a = pubNubClientsBySubscriptionKey[subscriptionKey]) !== null && _a !== void 0 ? _a : []).length}' clients currently active.`; + const message = `Invalidate '${clientId}' client. '${((_c = pubNubClientsBySubscriptionKey[subscriptionKey]) !== null && _c !== void 0 ? _c : []).length}' clients currently active.`; if (!clients) consoleLog(message); else diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index c339d6bd1..87ec57ce9 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ -!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,r){return new(n||(n=Promise))((function(i,s){function o(e){try{l(r.next(e))}catch(e){s(e)}}function c(e){try{l(r.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((r=r.apply(e,t||[])).next())}))}var t;"function"==typeof SuppressedError&&SuppressedError,function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(t||(t={}));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var r,i,s={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */r=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function r(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function i(e,t){var r=n[t||"all"];return r&&r.test(e)||!1}r.isUUID=i,r.VERSION=t,e.uuid=r,e.isUUID=i}(i=s.exports),null!==r&&(r.exports=i.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},y={},v={};self.onconnect=e=>{oe("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!Q(t))return;const n=t.data;if("client-register"===n.type)n.port=e,F(n),oe(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-unregister"===n.type)U(n);else if("client-pong"===n.type)J(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){V(n);const e=h[n.clientIdentifier];if(e){const t=se(e);let r=[];if(l.has(t)&&(r=l.get(t)[0]),r.push([e,n]),!l.has(t)){const e=setTimeout((()=>{q(r,n),l.delete(t)}),50);l.set(t,[r,e])}}}else n.request.path.endsWith("/heartbeat")?(N(n),w(n)):O(n);else"cancel-request"===n.type&&$(n)},e.postMessage({type:"shared-worker-connected"})}))};const q=(e,t)=>{const n=C(t),r=h[t.clientIdentifier];r&&(e=e.filter((e=>e[0].clientIdentifier!==r.clientIdentifier)),I(r,t,n,!0),e.forEach((([e,t])=>I(e,t,n,!1))))},I=(e,t,n,r)=>{var i;let s=!1;if(r||"string"==typeof n||(n=n.identifier),e.subscription&&(s="0"===e.subscription.timetoken),x("start",[e],(new Date).toISOString(),t.request),"string"==typeof n){const r=v[n];if(e){if(e.subscription&&(e.subscription.timetoken=r.timetoken,e.subscription.region=r.region,e.subscription.serviceRequestId=n),!s)return;const o=(new TextEncoder).encode(`{"t":{"t":"${r.timetoken}","r":${null!==(i=r.region)&&void 0!==i?i:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${t.request.origin}${t.request.path}`,u.clientIdentifier=t.clientIdentifier,u.identifier=t.request.identifier,x("end",[e],(new Date).toISOString(),t.request,o,c.get("Content-Type"),0),A(e,u)}return}t.request.cancellable&&f.set(n.identifier,new AbortController);const o=v[n.identifier],{timetokenOverride:c,regionOverride:l}=o;j(n,(()=>P(n.identifier)),((e,r)=>{W(e,r,t.request),E(e,n.identifier)}),((e,r)=>{W(e,null,t.request,D(r)),E(e,n.identifier)}),(e=>{let t=e;return s&&c&&"0"!==c&&(t=m(t,c,l)),t})),oe(`'${Object.keys(v).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let r;const i=e[0];let s=i,o=e[1];try{r=JSON.parse((new TextDecoder).decode(o))}catch(t){return oe(`Subscribe response parse error: ${t}`),e}r.t.t=t,n&&(r.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(r)).buffer,o.byteLength){const e=new Headers(i.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:i.status,statusText:i.statusText,headers:e})}}catch(t){return oe(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},w=e=>{var t;const n=h[e.clientIdentifier],r=G(e);if(!n)return;const i=`${n.userId}_${null!==(t=re(n))&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[i];if(x("start",[n],(new Date).toISOString(),r),!r){let t,r;if(oe(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`,n),o&&o.response&&([t,r]=o.response),!t){r=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${r.byteLength}`});t=new Response(r,{status:200,headers:e})}const i=L([t,r]);return i.url=`${e.request.origin}${e.request.path}`,i.clientIdentifier=e.clientIdentifier,i.identifier=e.request.identifier,x("end",[n],(new Date).toISOString(),e.request,r,t.headers.get("Content-Type"),0),void A(n,i)}j(r,(()=>[n]),((t,n)=>{o&&(o.response=n),W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started heartbeat request.",n)},O=(e,t)=>{t=null!=t?t:h[e.clientIdentifier];const n=R(e);if(!t)return;const{subscription:r}=t,i=null==r?void 0:r.serviceRequestId;if(r&&0===r.channels.length&&0===r.channelGroups.length&&(r.channelGroupQuery="",r.path="",r.previousTimetoken="0",r.timetoken="0",delete r.region,delete r.serviceRequestId,delete r.request),!n){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),r=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),i=new Response(n,{status:200,headers:r}),s=L([i,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(j(n,(()=>[t]),((t,n)=>{W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started leave request.",t),void 0===i)return;const s=P(i);s.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),S(i),k(s)},$=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,S(n))},k=e=>{let t,n;for(const r of e)if(r.subscription&&r.subscription.request){n=r.subscription.request,t=r;break}if(!n||!t)return;const r={type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n};q([[t,r]],r)},j=(t,n,r,i,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(K(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),T(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const i=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,i,e[0].headers.get("Content-Type"),(new Date).getTime()-o),r(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let r=e;if("string"==typeof e){const t=e.toLowerCase();r=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(r.name="AbortError")}i(t,r)}))}))},S=e=>{if(0===P(e).length){const t=f.get(e);f.delete(e),delete v[e],t&&t.abort("Cancel request")}},T=(e,t)=>new Promise(((n,r)=>{const i=setTimeout((()=>{f.delete(e),clearTimeout(i),r(new Error("Request timeout"))}),1e3*t)})),P=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete v[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},K=e=>{let t;const n=e.queryParameters;let r=e.path;if(e.headers){t={};for(const[n,r]of Object.entries(e.headers))t[n]=r}return n&&0!==Object.keys(n).length&&(r=`${r}?${le(n)}`),new Request(`${e.origin}${r}`,{method:e.method,headers:t,redirect:"follow"})},C=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],l=o.subscription,u=z(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=B(u,e);if(s){const e=v[s],{channels:n,channelGroups:r}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||te(e.channels,n))&&(!(r.length>0)||te(e.channelGroups,r)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),y=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(y.add,y);const n=t.serviceRequestId;t.serviceRequestId=a,n&&v[n]&&S(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const q=null!==(r=v[a])&&void 0!==r?r:v[a]={requestId:a,timetoken:null!==(i=d.queryParameters.tt)&&void 0!==i?i:"0",channelGroups:[],channels:[]};if(y.size){q.channels=Array.from(y).sort();const e=d.path.split("/");e[4]=q.channels.join(","),d.path=e.join("/")}if(b.size&&(q.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=q.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h)),d.queryParameters&&d.queryParameters.auth){const e=ie(u);e&&(d.queryParameters.auth=e)}}else v[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};v[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(v[a].region=d.queryParameters.tr),v[a].timetokenOverride=f,v[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)ce(v[a],`Started aggregated request for clients: ${b}`,e);return d},G=e=>{var t,n,r,i,s;const o=h[e.clientIdentifier],c=X(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=re(o))&&void 0!==n?n:""}`,d=o.heartbeat.channelGroups,f=o.heartbeat.channels;let p,g,y=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=te(e,f)&&te(t,d),n&&(y=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,timestamp:Date.now()},p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=!1;let v=o.heartbeatInterval;for(const e of c)e.heartbeatInterval&&(v=Math.min(v,e.heartbeatInterval));if(g){const e=u[a].timestamp+1e3*v,t=Date.now();if(!y&&t5e3)return}delete u[a].response;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(f.length){const e=l.path.split("/");e[6]=f.join(","),l.path=e.join("/")}if(d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,c.length>1&&l.queryParameters&&l.queryParameters.auth){const e=ie(c);e&&(l.queryParameters.auth=e)}return l},R=e=>{const t=h[e.clientIdentifier],n=Y(e);let r=ee(e.request),i=Z(e.request);const s=Object.assign({},e.request);if(t&&t.subscription){const{subscription:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(t&&t.heartbeat){const{heartbeat:e}=t;i.length&&(e.channels=e.channels.filter((e=>!i.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of n){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(i.length&&(i=i.filter((e=>!e.endsWith("-pnpres")&&!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")&&!n.channelGroups.includes(e))))))}if(i.length&&(i=i.filter((e=>!e.endsWith("-pnpres")))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")))),0!==i.length||0!==r.length){if(i.length){const e=s.path.split("/");e[6]=i.join(","),s.path=e.join("/")}if(r.length&&(s.queryParameters["channel-group"]=r.join(",")),n.length>1&&s.queryParameters&&s.queryParameters.auth){const e=ie(n);e&&(s.queryParameters.auth=e)}return s}if(t&&t.workerLogVerbosity){const e=n.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");oe(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,t)}},A=(e,t)=>{var n;const r=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!r)return!1;try{return r.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},x=(e,t,n,r,i,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=r&&r.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;i&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(i)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let i=null!=n?n:r;if(d||(i=r),e.logVerbosity&&t&&i){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${i.origin}${i.path}`,query:i.queryParameters});A(e,t)}}},W=(e,t,n,r)=>{var i,s;if(0===e.length)return;if(!r&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(i=y[e[0].subscriptionKey])&&void 0!==i?i:{},l=n&&n.path.startsWith("/v2/subscribe");if(!r&&t&&(r=t[0].status>=400?D(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)oe(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)oe(n,t)}continue}const i=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),i&&a){const e=Object.assign(Object.assign({},r),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!i&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const r of e)r.clientIdentifier!==t.clientIdentifier&&oe(n,r)}}},L=e=>{var t;const[n,r]=e,i=r.byteLength>0?r:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:i}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",r="Unknown error",i="Error";e&&e instanceof Error&&(r=e.message,i=e.name);const s=r.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===i||s.includes("aborted")||s.includes("cancel"))&&(r="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:i,type:n,message:r}}},F=e=>{var t,n,r,i,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,newlyRegistered:!0,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[i=e.subscriptionKey])&&void 0!==t?t:p[i]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=y[s=e.subscriptionKey])&&void 0!==n?n:y[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)oe(u,e);if(!a[e.subscriptionKey]&&(null!==(r=p[e.subscriptionKey])&&void 0!==r?r:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)oe(`Setup PubNub client ping event ${n} seconds`,e);a[t]=setTimeout((()=>ne(t)),500*n-1)}},U=e=>{H(e.subscriptionKey,e.clientIdentifier)},V=e=>{var t,n,r,i,s,o,c,l,u,a,d,f,p,b,y,v,q,I,m,w;const O=e.request.queryParameters,{clientIdentifier:$}=e,k=h[$];if(!k)return;const j=null!==(t=O["channel-group"])&&void 0!==t?t:"",S=null!==(n=O.state)&&void 0!==n?n:"";let T=k.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(v=null!==(s=g[y=k.subscriptionKey])&&void 0!==s?s:g[y]={})[q=k.userId])&&void 0!==o?o:v[q]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[I=k.subscriptionKey])&&void 0!==c?c:g[I]={})[w=k.userId])&&void 0!==l?l:m[w]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(i=(p=null!==(r=g[f=k.subscriptionKey])&&void 0!==r?r:g[f]={})[b=k.userId])&&void 0!==i?i:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}k.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=Z(e.request)),T.channelGroupQuery!==j&&(T.channelGroupQuery=j,T.channelGroups=ee(e.request));let{authKey:P}=k;const{userId:E}=k;T.request=e.request,T.filterExpression=null!==(u=O["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=O.tt)&&void 0!==a?a:"0",void 0!==O.tr&&(T.region=O.tr),k.authKey=null!==(d=O.auth)&&void 0!==d?d:"",k.origin=e.request.origin,k.userId=O.uuid,k.pnsdk=O.pnsdk,k.accessToken=e.token,k.newlyRegistered&&!P&&k.authKey&&(P=k.authKey),k.newlyRegistered=!1,M(k,E,P)},N=e=>{var t,n;const r=h[e.clientIdentifier],{request:i}=e;if(!r)return;const s=null!==(t=r.heartbeat)&&void 0!==t?t:r.heartbeat={channels:[],channelGroups:[]};s.channelGroups=ee(i).filter((e=>!e.endsWith("-pnpres"))),s.channels=Z(i).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=i.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var r,i,s;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(r=e.authKey)&&void 0!==r?r:""))return;const o=null!==(i=b[e.subscriptionKey])&&void 0!==i?i:{},c=`${t}_${null!==(s=re(e))&&void 0!==s?s:""}`;void 0!==o[c]&&delete o[c]},J=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},H=(e,t)=>{var n;const r=h[t];delete h[t];let i=p[e];if(r){if(r.subscription){const{serviceRequestId:e}=r.subscription;delete r.subscription.serviceRequestId,e&&S(e)}r.unsubscribeOfflineClients&&_(r)}if(i)if(i=i.filter((e=>e.clientIdentifier!==t)),i.length>0?p[e]=i:(delete p[e],delete b[e]),0===i.length&&delete g[e],i.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];const s=`Invalidate '${t}' client. '${(null!==(n=p[e])&&void 0!==n?n:[]).length}' clients currently active.`;if(i)for(const e of i)oe(s,e);else oe(s)},_=e=>{if(!e.subscription)return;const{channels:n,channelGroups:r,serviceRequestId:i}=e.subscription,s=(null!=r?r:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort(),o=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort();if(0===o.length&&0===s.length)return;const l=s.length>0?s.join(","):void 0,u=0===o.length?",":o.join(","),a=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),l?{"channel-group":l}:{}),d={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${u}/leave`,queryParameters:a,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:a.requestid}};O(d,e)},Q=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:r}=e.data;return void 0!==r&&"boolean"==typeof r&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},B=(e,t)=>{var n;const r=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",i=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===i&&e.channelGroupQuery===r)return oe(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const r=v[e.serviceRequestId];if(s||(s=ee(t.request)),o||(o=Z(t.request)),o.length&&!te(r.channels,o))continue;if(s.length&&!te(r.channelGroups,s))continue;return ce(r,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},z=(e,t)=>{var n,r;const i=h[t.clientIdentifier];if(!i)return[];const s=t.request.queryParameters,o=re(i),c=null!==(n=s["filter-expr"])&&void 0!==n?n:"",l=s.uuid;return(null!==(r=p[t.subscriptionKey])&&void 0!==r?r:[]).filter((t=>t.userId===l&&re(t)===o&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===c&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},X=e=>Y(e),Y=e=>{var t;const n=h[e.clientIdentifier];if(!n)return[];const r=e.request.queryParameters,i=re(n),s=r.uuid;return(null!==(t=p[e.subscriptionKey])&&void 0!==t?t:[]).filter((e=>e.userId===s&&re(e)===i))},Z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},ee=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},te=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ne=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let r=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){r=!0;for(const t of n)oe(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);H(e.subscriptionKey,e.clientIdentifier)}}e&&!r&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ne(e)),500*t-1)}},re=e=>{var t;return e.accessToken&&null!==(t=e.accessToken.token)&&void 0!==t?t:e.authKey},ie=e=>{const t=e.filter((e=>!!e.accessToken)).sort(((e,t)=>e.accessToken.expiration-t.accessToken.expiration)).pop();return t?t.authKey:void 0},se=e=>{const t=re(e);let n=`${e.userId}-${e.subscriptionKey}${t?`-${t}`:""}`;return e.subscription&&e.subscription.filterExpression&&(n+=`-${e.subscription.filterExpression}`),n},oe=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,r)}))},ce=(e,t,n)=>{const r=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-dir",message:t,data:e};r.forEach((e=>{e&&A(e,i)}))},le=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${ue(e)}`)).join("&"):`${t}=${ue(n)}`})).join("&"),ue=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +!function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{l(i.next(e))}catch(e){s(e)}}function c(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((i=i.apply(e,t||[])).next())}))}var t;"function"==typeof SuppressedError&&SuppressedError,function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(t||(t={}));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i,r,s={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */i=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function i(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var i=n[t||"all"];return i&&i.test(e)||!1}i.isUUID=r,i.VERSION=t,e.uuid=i,e.isUUID=r}(r=s.exports),null!==i&&(i.exports=r.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},y={},v={};self.onconnect=e=>{oe("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!Q(t))return;const n=t.data;if("client-register"===n.type)n.port=e,F(n),oe(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-unregister"===n.type)U(n);else if("client-pong"===n.type)_(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){V(n);const e=h[n.clientIdentifier];if(e){const t=se(e);let i=[];if(l.has(t)&&(i=l.get(t)[0]),i.push([e,n]),!l.has(t)){const e=setTimeout((()=>{I(i,n),l.delete(t)}),50);l.set(t,[i,e])}}}else n.request.path.endsWith("/heartbeat")?(N(n),$(n)):w(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const I=(e,t)=>{const n=G(t),i=h[t.clientIdentifier];i&&(e=e.filter((e=>e[0].clientIdentifier!==i.clientIdentifier)),q(i,t,n,!0),e.forEach((([e,t])=>q(e,t,n,!1))))},q=(e,t,n,i)=>{var r;let s=!1;if(i||"string"==typeof n||(n=n.identifier),e.subscription&&(s="0"===e.subscription.timetoken),x("start",[e],(new Date).toISOString(),t.request),"string"==typeof n){const i=v[n];if(e){if(e.subscription&&(e.subscription.timetoken=i.timetoken,e.subscription.region=i.region,e.subscription.serviceRequestId=n),!s)return;const o=(new TextEncoder).encode(`{"t":{"t":"${i.timetoken}","r":${null!==(r=i.region)&&void 0!==r?r:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${t.request.origin}${t.request.path}`,u.clientIdentifier=t.clientIdentifier,u.identifier=t.request.identifier,x("end",[e],(new Date).toISOString(),t.request,o,c.get("Content-Type"),0),A(e,u)}return}t.request.cancellable&&f.set(n.identifier,new AbortController);const o=v[n.identifier],{timetokenOverride:c,regionOverride:l}=o;j(n,(()=>P(n.identifier)),((e,i)=>{W(e,i,t.request),E(e,n.identifier)}),((e,i)=>{W(e,null,t.request,D(i)),E(e,n.identifier)}),(e=>{let t=e;return s&&c&&"0"!==c&&(t=m(t,c,l)),t})),oe(`'${Object.keys(v).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let i;const r=e[0];let s=r,o=e[1];try{i=JSON.parse((new TextDecoder).decode(o))}catch(t){return oe(`Subscribe response parse error: ${t}`),e}i.t.t=t,n&&(i.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(i)).buffer,o.byteLength){const e=new Headers(r.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:r.status,statusText:r.statusText,headers:e})}}catch(t){return oe(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},$=e=>{var t;const n=h[e.clientIdentifier],i=C(e);if(!n)return;const r=`${n.userId}_${null!==(t=ie(n))&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[r];if(x("start",[n],(new Date).toISOString(),e.request),!i){let t,i;if(oe(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`,n),o&&o.response&&([t,i]=o.response),!t){i=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${i.byteLength}`});t=new Response(i,{status:200,headers:e})}const r=L([t,i]);return r.url=`${e.request.origin}${e.request.path}`,r.clientIdentifier=e.clientIdentifier,r.identifier=e.request.identifier,x("end",[n],(new Date).toISOString(),e.request,i,t.headers.get("Content-Type"),0),void A(n,r)}j(i,(()=>[n]),((t,n)=>{o&&(o.response=n),W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started heartbeat request.",n)},w=(e,t)=>{var n,i,r;t=null!=t?t:h[e.clientIdentifier];const s=R(e);if(!t)return;const{subscription:o,heartbeat:c}=t,l=null==o?void 0:o.serviceRequestId;if(o&&0===o.channels.length&&0===o.channelGroups.length&&(o.channelGroupQuery="",o.path="",o.previousTimetoken="0",o.timetoken="0",delete o.region,delete o.serviceRequestId,delete o.request),b[t.subscriptionKey]&&c&&0===c.channels.length&&0===c.channelGroups.length){const e=null!==(n=b[r=t.subscriptionKey])&&void 0!==n?n:b[r]={},s=`${t.userId}_${null!==(i=ie(t))&&void 0!==i?i:""}`;e[s]&&e[s].clientIdentifier===t.clientIdentifier&&delete e[s].clientIdentifier}if(!s){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),i=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),r=new Response(n,{status:200,headers:i}),s=L([r,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(j(s,(()=>[t]),((t,n)=>{W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started leave request.",t),void 0===l)return;const u=P(l);u.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),S(l),k(u)},O=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,S(n))},k=e=>{let t,n;for(const i of e)if(i.subscription&&i.subscription.request){n=i.subscription.request,t=i;break}if(!n||!t)return;const i={type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n};I([[t,i]],i)},j=(t,n,i,r,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(K(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),T(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const r=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,r,e[0].headers.get("Content-Type"),(new Date).getTime()-o),i(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let i=e;if("string"==typeof e){const t=e.toLowerCase();i=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(i.name="AbortError")}r(t,i)}))}))},S=e=>{if(0===P(e).length){const t=f.get(e);f.delete(e),delete v[e],t&&t.abort("Cancel request")}},T=(e,t)=>new Promise(((n,i)=>{const r=setTimeout((()=>{f.delete(e),clearTimeout(r),i(new Error("Request timeout"))}),1e3*t)})),P=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete v[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},K=e=>{let t;const n=e.queryParameters;let i=e.path;if(e.headers){t={};for(const[n,i]of Object.entries(e.headers))t[n]=i}return n&&0!==Object.keys(n).length&&(i=`${i}?${le(n)}`),new Request(`${e.origin}${i}`,{method:e.method,headers:t,redirect:"follow"})},G=e=>{var t,n,i,r,s;const o=h[e.clientIdentifier],l=o.subscription,u=z(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=B(u,e);if(s){const e=v[s],{channels:n,channelGroups:i}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||te(e.channels,n))&&(!(i.length>0)||te(e.channelGroups,i)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),y=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(y.add,y);const n=t.serviceRequestId;t.serviceRequestId=a,n&&v[n]&&S(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const I=null!==(i=v[a])&&void 0!==i?i:v[a]={requestId:a,timetoken:null!==(r=d.queryParameters.tt)&&void 0!==r?r:"0",channelGroups:[],channels:[]};if(y.size){I.channels=Array.from(y).sort();const e=d.path.split("/");e[4]=I.channels.join(","),d.path=e.join("/")}if(b.size&&(I.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=I.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h)),d.queryParameters&&d.queryParameters.auth){const e=re(u);e&&(d.queryParameters.auth=e)}}else v[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};v[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(v[a].region=d.queryParameters.tr),v[a].timetokenOverride=f,v[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)ce(v[a],`Started aggregated request for clients: ${b}`,e);return d},C=e=>{var t,n,i,r,s;const o=h[e.clientIdentifier],c=X(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=ie(o))&&void 0!==n?n:""}`,d=[...o.heartbeat.channelGroups],f=[...o.heartbeat.channels];let p,g,y=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=te(e,f)&&te(t,d),n&&(y=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,clientIdentifier:o.clientIdentifier,timestamp:Date.now()},p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=!1;let v=o.heartbeatInterval;for(const e of c)e.heartbeatInterval&&(v=Math.min(v,e.heartbeatInterval));if(g&&u[a].clientIdentifier){const e=u[a].timestamp+1e3*v,t=Date.now();if(!y&&t5e3)return}delete u[a].response,u[a].clientIdentifier=o.clientIdentifier;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(0!==f.length||0!==d.length){if(f.length||d.length){const e=l.path.split("/");e[6]=f.length?f.join(","):",",l.path=e.join("/")}if(d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,c.length>1&&l.queryParameters&&l.queryParameters.auth){const e=re(c);e&&(l.queryParameters.auth=e)}return l}},R=e=>{var t;const n=h[e.clientIdentifier],i=Y(e);let r=ee(e.request),s=Z(e.request);const o=Object.assign({},e.request);if(n&&n.subscription){const{subscription:e}=n;s.length&&(e.channels=e.channels.filter((e=>!s.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(n&&n.heartbeat){const{heartbeat:e}=n;s.length&&(e.channels=e.channels.filter((e=>!s.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of i){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(s.length&&(s=s.filter((e=>!e.endsWith("-pnpres")&&!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")&&!n.channelGroups.includes(e))))))}if(s.length&&(s=s.filter((e=>!e.endsWith("-pnpres")))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")))),0!==s.length||0!==r.length){if(n&&b[n.subscriptionKey]&&(s.length||r.length)){const e=b[n.subscriptionKey],i=`${n.userId}_${null!==(t=ie(n))&&void 0!==t?t:""}`;if(e[i]){let{channels:t,channelGroups:n}=e[i];r.length&&(n=n.filter((e=>!s.includes(e)))),s.length&&(t=t.filter((e=>!s.includes(e)))),e[i].channelGroups=n,e[i].channels=t}}if(s.length){const e=o.path.split("/");e[6]=s.join(","),o.path=e.join("/")}if(r.length&&(o.queryParameters["channel-group"]=r.join(",")),i.length>1&&o.queryParameters&&o.queryParameters.auth){const e=re(i);e&&(o.queryParameters.auth=e)}return o}if(n&&n.workerLogVerbosity){const e=i.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");oe(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,n)}},A=(e,t)=>{var n;const i=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!i)return!1;try{return i.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},x=(e,t,n,i,r,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=i&&i.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;r&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(r)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let r=null!=n?n:i;if(d||(r=i),e.logVerbosity&&t&&r){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${r.origin}${r.path}`,query:r.queryParameters});A(e,t)}}},W=(e,t,n,i)=>{var r,s;if(0===e.length)return;if(!i&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(r=y[e[0].subscriptionKey])&&void 0!==r?r:{},l=n&&n.path.startsWith("/v2/subscribe");if(!i&&t&&(i=t[0].status>=400?D(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)oe(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)oe(n,t)}continue}const r=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),r&&a){const e=Object.assign(Object.assign({},i),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!r&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const i of e)i.clientIdentifier!==t.clientIdentifier&&oe(n,i)}}},L=e=>{var t;const[n,i]=e,r=i.byteLength>0?i:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:r}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",i="Unknown error",r="Error";e&&e instanceof Error&&(i=e.message,r=e.name);const s=i.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===r||s.includes("aborted")||s.includes("cancel"))&&(i="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:r,type:n,message:i}}},F=e=>{var t,n,i,r,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,newlyRegistered:!0,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[r=e.subscriptionKey])&&void 0!==t?t:p[r]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=y[s=e.subscriptionKey])&&void 0!==n?n:y[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)oe(u,e);if(!a[e.subscriptionKey]&&(null!==(i=p[e.subscriptionKey])&&void 0!==i?i:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)oe(`Setup PubNub client ping event ${n} seconds`,e);a[t]=setTimeout((()=>ne(t)),500*n-1)}},U=e=>{J(e.subscriptionKey,e.clientIdentifier)},V=e=>{var t,n,i,r,s,o,c,l,u,a,d,f,p,b,y,v,I,q,m,$;const w=e.request.queryParameters,{clientIdentifier:O}=e,k=h[O];if(!k)return;const j=null!==(t=w["channel-group"])&&void 0!==t?t:"",S=null!==(n=w.state)&&void 0!==n?n:"";let T=k.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(v=null!==(s=g[y=k.subscriptionKey])&&void 0!==s?s:g[y]={})[I=k.userId])&&void 0!==o?o:v[I]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[q=k.subscriptionKey])&&void 0!==c?c:g[q]={})[$=k.userId])&&void 0!==l?l:m[$]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(r=(p=null!==(i=g[f=k.subscriptionKey])&&void 0!==i?i:g[f]={})[b=k.userId])&&void 0!==r?r:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}k.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=Z(e.request)),T.channelGroupQuery!==j&&(T.channelGroupQuery=j,T.channelGroups=ee(e.request));let{authKey:P}=k;const{userId:E}=k;T.request=e.request,T.filterExpression=null!==(u=w["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=w.tt)&&void 0!==a?a:"0",void 0!==w.tr&&(T.region=w.tr),k.authKey=null!==(d=w.auth)&&void 0!==d?d:"",k.origin=e.request.origin,k.userId=w.uuid,k.pnsdk=w.pnsdk,k.accessToken=e.token,k.newlyRegistered&&!P&&k.authKey&&(P=k.authKey),k.newlyRegistered=!1,M(k,E,P)},N=e=>{var t,n;const i=h[e.clientIdentifier],{request:r}=e;if(!i)return;const s=null!==(t=i.heartbeat)&&void 0!==t?t:i.heartbeat={channels:[],channelGroups:[]};s.channelGroups=ee(r).filter((e=>!e.endsWith("-pnpres"))),s.channels=Z(r).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=r.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var i,r,s;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(i=e.authKey)&&void 0!==i?i:""))return;const o=null!==(r=b[e.subscriptionKey])&&void 0!==r?r:{},c=`${t}_${null!==(s=ie(e))&&void 0!==s?s:""}`;void 0!==o[c]&&delete o[c]},_=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},J=(e,t)=>{var n,i,r;const s=h[t];delete h[t];let o=p[e];if(s){if(s.subscription){const{serviceRequestId:e}=s.subscription;delete s.subscription.serviceRequestId,e&&S(e)}if(b[e]){const t=null!==(n=b[e])&&void 0!==n?n:b[e]={},r=`${s.userId}_${null!==(i=ie(s))&&void 0!==i?i:""}`;t[r]&&t[r].clientIdentifier===s.clientIdentifier&&delete t[r].clientIdentifier}s.unsubscribeOfflineClients&&H(s)}if(o)if(o=o.filter((e=>e.clientIdentifier!==t)),o.length>0?p[e]=o:(delete p[e],delete b[e]),0===o.length&&delete g[e],o.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];const c=`Invalidate '${t}' client. '${(null!==(r=p[e])&&void 0!==r?r:[]).length}' clients currently active.`;if(o)for(const e of o)oe(c,e);else oe(c)},H=e=>{if(!e.subscription)return;const{channels:n,channelGroups:i,serviceRequestId:r}=e.subscription,s=(null!=i?i:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort(),o=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort();if(0===o.length&&0===s.length)return;const l=s.length>0?s.join(","):void 0,u=0===o.length?",":o.join(","),a=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),l?{"channel-group":l}:{}),d={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${u}/leave`,queryParameters:a,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:a.requestid}};w(d,e)},Q=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:i}=e.data;return void 0!==i&&"boolean"==typeof i&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},B=(e,t)=>{var n;const i=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",r=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===r&&e.channelGroupQuery===i)return oe(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const i=v[e.serviceRequestId];if(s||(s=ee(t.request)),o||(o=Z(t.request)),o.length&&!te(i.channels,o))continue;if(s.length&&!te(i.channelGroups,s))continue;return ce(i,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},z=(e,t)=>{var n,i;const r=h[t.clientIdentifier];if(!r)return[];const s=t.request.queryParameters,o=ie(r),c=null!==(n=s["filter-expr"])&&void 0!==n?n:"",l=s.uuid;return(null!==(i=p[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&ie(t)===o&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===c&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},X=e=>Y(e),Y=e=>{var t;const n=h[e.clientIdentifier];if(!n)return[];const i=e.request.queryParameters,r=ie(n),s=i.uuid;return(null!==(t=p[e.subscriptionKey])&&void 0!==t?t:[]).filter((e=>e.userId===s&&ie(e)===r))},Z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},ee=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},te=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ne=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let i=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){i=!0;for(const t of n)oe(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);J(e.subscriptionKey,e.clientIdentifier)}}e&&!i&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ne(e)),500*t-1)}},ie=e=>{var t;return e.accessToken&&null!==(t=e.accessToken.token)&&void 0!==t?t:e.authKey},re=e=>{const t=e.filter((e=>!!e.accessToken)).sort(((e,t)=>e.accessToken.expiration-t.accessToken.expiration)).pop();return t?t.authKey:void 0},se=e=>{const t=ie(e);let n=`${e.userId}-${e.subscriptionKey}${t?`-${t}`:""}`;return e.subscription&&e.subscription.filterExpression&&(n+=`-${e.subscription.filterExpression}`),n},oe=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,i)}))},ce=(e,t,n)=>{const i=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-dir",message:t,data:e};i.forEach((e=>{e&&A(e,r)}))},le=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${ue(e)}`)).join("&"):`${t}=${ue(n)}`})).join("&"),ue=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 776ba1fff..dcedce464 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -124,7 +124,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '9.3.0'; + return '9.3.1'; }, getVersion() { return this.version; diff --git a/lib/entities/SubscriptionSet.js b/lib/entities/SubscriptionSet.js index ddb250708..aef13eaa9 100644 --- a/lib/entities/SubscriptionSet.js +++ b/lib/entities/SubscriptionSet.js @@ -76,18 +76,11 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { this.options = subscriptionOptions; this.eventEmitter = eventEmitter; this.pubnub = pubnub; - channels.forEach((c) => { - const subscription = this.pubnub.channel(c).subscription(this.options); - this.channelNames = [...this.channelNames, ...subscription.channels]; - this.subscriptionList.push(subscription); - }); - channelGroups.forEach((cg) => { - const subscription = this.pubnub.channelGroup(cg).subscription(this.options); - this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.subscriptionList.push(subscription); - }); + channels.forEach((c) => this.subscriptionList.push(this.pubnub.channel(c).subscription(this.options))); + channelGroups.forEach((cg) => this.subscriptionList.push(this.pubnub.channelGroup(cg).subscription(this.options))); this.typeBasedListener = {}; this.typeBasedListenerId = eventEmitter.addListener(this.typeBasedListener, this.channelNames, this.groupNames); + this.updateListeners(); } /** * Add additional entity's subscription to the subscription set. @@ -98,10 +91,8 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { * @param subscription - Other entity's subscription object, which should be added. */ addSubscription(subscription) { - this.subscriptionList.push(subscription); - this.channelNames = [...this.channelNames, ...subscription.channels]; - this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.eventEmitter.addListener(this.typeBasedListener, subscription.channels, subscription.channelGroups, this.typeBasedListenerId); + if (!this.subscriptionList.includes(subscription)) + this.subscriptionList.push(subscription); // Make sure to listen events on channels / groups added with `subscription`. this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. @@ -121,12 +112,7 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { * @param subscription - Other entity's subscription object, which should be removed. */ removeSubscription(subscription) { - const channelsToRemove = subscription.channels; - const groupsToRemove = subscription.channelGroups; - this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); - this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); - this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); - this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + this.subscriptionList = this.subscriptionList.filter((sub) => sub !== subscription); // Make sure to stop listening for events from channels / groups removed with `subscription`. this.updateListeners(); // @ts-expect-error: Required access of protected field. @@ -142,10 +128,7 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { * @param subscriptionSet - Other entities' subscription set, which should be joined. */ addSubscriptionSet(subscriptionSet) { - this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; - this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; - this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; - this.eventEmitter.addListener(this.typeBasedListener, subscriptionSet.channels, subscriptionSet.channelGroups, this.typeBasedListenerId); + this.subscriptionList = Array.from(new Set([...this.subscriptionList, ...subscriptionSet.subscriptions])); // Make sure to listen events on channels / groups added with `subscription set`. this.updateListeners(); // Subscribe subscription object if subscription set already subscribed. @@ -163,12 +146,7 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { * @param subscriptionSet - Other entities' subscription set, which should be subtracted. */ removeSubscriptionSet(subscriptionSet) { - const channelsToRemove = subscriptionSet.channels; - const groupsToRemove = subscriptionSet.channelGroups; - this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); - this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); - this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); - this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + this.subscriptionList = this.subscriptionList.filter((sub) => !subscriptionSet.subscriptions.includes(sub)); // Make sure to stop listening for events from channels / groups removed with `subscription set`. this.updateListeners(); if (subscriptionSet.subscribedAutomatically) @@ -192,11 +170,36 @@ class SubscriptionSet extends SubscribeCapable_1.SubscribeCapable { * @internal */ updateListeners() { - if (!this.aggregatedListener) - return; + // Actual list of channels and groups. + const channelGroups = []; + const channels = []; + // Gather actual information about active channels / groups. + this.subscriptionList.forEach((subscription) => { + if (subscription.channelGroups.length) + channelGroups.push(...subscription.channelGroups); + if (subscription.channels.length) + channels.push(...subscription.channels); + }); + // Identify channels / groups which should be added / removed. + const channelsToRemove = this.channelNames.filter((channel) => !channels.includes(channel)); + const groupsToRemove = this.groupNames.filter((group) => !channelGroups.includes(group)); + const channelsToAdd = channels.filter((channel) => !this.channelNames.includes(channel)); + const groupsToAdd = channelGroups.filter((group) => !this.groupNames.includes(group)); + // Removing type-based listener for unused channels / groups. + if (channelsToRemove.length || groupsToRemove.length) { + this.eventEmitter.removeListener(this.typeBasedListener, this.typeBasedListenerId, channelsToRemove, groupsToRemove); + } + // Adding type-based listener for unused channels / groups. + if (channelsToAdd.length || groupsToAdd.length) + this.eventEmitter.addListener(this.typeBasedListener, channelsToAdd, groupsToAdd, this.typeBasedListenerId); const aggregatedListener = this.aggregatedListener; - this.removeListener(this.aggregatedListener); - this.addListener(aggregatedListener); + if (aggregatedListener) + this.removeListener(aggregatedListener); + // Set actual list of channels and groups. + this.groupNames = channelGroups; + this.channelNames = channels; + if (aggregatedListener) + this.addListener(aggregatedListener); } } exports.SubscriptionSet = SubscriptionSet; diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index c93707f1c..7091bedc5 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -2484,7 +2484,7 @@ declare namespace PubNub { */ presenceTimeout?: number; /** - * How often the client will announce itself to server.The value is in seconds. + * How often the client will announce itself to server. The value is in seconds. * * @default `not set` */ diff --git a/package.json b/package.json index 99e826923..e4de370ff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "9.3.0", + "version": "9.3.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 0fd596bad..9d75aaae0 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -182,7 +182,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '9.3.0'; + return '9.3.1'; }, getVersion(): string { return this.version; diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index ddd18ffbf..746e5ebc3 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -204,7 +204,7 @@ export type UserConfiguration = { presenceTimeout?: number; /** - * How often the client will announce itself to server.The value is in seconds. + * How often the client will announce itself to server. The value is in seconds. * * @default `not set` */ diff --git a/src/entities/SubscriptionSet.ts b/src/entities/SubscriptionSet.ts index c7e9c7996..af49ea95d 100644 --- a/src/entities/SubscriptionSet.ts +++ b/src/entities/SubscriptionSet.ts @@ -155,18 +155,14 @@ export class SubscriptionSet extends SubscribeCapable { this.options = subscriptionOptions; this.eventEmitter = eventEmitter; this.pubnub = pubnub; - channels.forEach((c) => { - const subscription = this.pubnub.channel(c).subscription(this.options); - this.channelNames = [...this.channelNames, ...subscription.channels]; - this.subscriptionList.push(subscription); - }); - channelGroups.forEach((cg) => { - const subscription = this.pubnub.channelGroup(cg).subscription(this.options); - this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.subscriptionList.push(subscription); - }); + + channels.forEach((c) => this.subscriptionList.push(this.pubnub.channel(c).subscription(this.options))); + channelGroups.forEach((cg) => this.subscriptionList.push(this.pubnub.channelGroup(cg).subscription(this.options))); + this.typeBasedListener = {}; this.typeBasedListenerId = eventEmitter.addListener(this.typeBasedListener, this.channelNames, this.groupNames); + + this.updateListeners(); } /** @@ -178,15 +174,7 @@ export class SubscriptionSet extends SubscribeCapable { * @param subscription - Other entity's subscription object, which should be added. */ addSubscription(subscription: Subscription) { - this.subscriptionList.push(subscription); - this.channelNames = [...this.channelNames, ...subscription.channels]; - this.groupNames = [...this.groupNames, ...subscription.channelGroups]; - this.eventEmitter.addListener( - this.typeBasedListener, - subscription.channels, - subscription.channelGroups, - this.typeBasedListenerId, - ); + if (!this.subscriptionList.includes(subscription)) this.subscriptionList.push(subscription); // Make sure to listen events on channels / groups added with `subscription`. this.updateListeners(); @@ -209,17 +197,7 @@ export class SubscriptionSet extends SubscribeCapable { * @param subscription - Other entity's subscription object, which should be removed. */ removeSubscription(subscription: Subscription) { - const channelsToRemove = subscription.channels; - const groupsToRemove = subscription.channelGroups; - this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); - this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); - this.subscriptionList = this.subscriptionList.filter((s) => s !== subscription); - this.eventEmitter.removeListener( - this.typeBasedListener, - this.typeBasedListenerId, - channelsToRemove, - groupsToRemove, - ); + this.subscriptionList = this.subscriptionList.filter((sub) => sub !== subscription); // Make sure to stop listening for events from channels / groups removed with `subscription`. this.updateListeners(); @@ -237,15 +215,7 @@ export class SubscriptionSet extends SubscribeCapable { * @param subscriptionSet - Other entities' subscription set, which should be joined. */ addSubscriptionSet(subscriptionSet: SubscriptionSet) { - this.subscriptionList = [...this.subscriptionList, ...subscriptionSet.subscriptions]; - this.channelNames = [...this.channelNames, ...subscriptionSet.channels]; - this.groupNames = [...this.groupNames, ...subscriptionSet.channelGroups]; - this.eventEmitter.addListener( - this.typeBasedListener, - subscriptionSet.channels, - subscriptionSet.channelGroups, - this.typeBasedListenerId, - ); + this.subscriptionList = Array.from(new Set([...this.subscriptionList, ...subscriptionSet.subscriptions])); // Make sure to listen events on channels / groups added with `subscription set`. this.updateListeners(); @@ -266,17 +236,7 @@ export class SubscriptionSet extends SubscribeCapable { * @param subscriptionSet - Other entities' subscription set, which should be subtracted. */ removeSubscriptionSet(subscriptionSet: SubscriptionSet) { - const channelsToRemove = subscriptionSet.channels; - const groupsToRemove = subscriptionSet.channelGroups; - this.channelNames = this.channelNames.filter((c) => !channelsToRemove.includes(c)); - this.groupNames = this.groupNames.filter((cg) => !groupsToRemove.includes(cg)); - this.subscriptionList = this.subscriptionList.filter((s) => !subscriptionSet.subscriptions.includes(s)); - this.eventEmitter.removeListener( - this.typeBasedListener, - this.typeBasedListenerId, - channelsToRemove, - groupsToRemove, - ); + this.subscriptionList = this.subscriptionList.filter((sub) => !subscriptionSet.subscriptions.includes(sub)); // Make sure to stop listening for events from channels / groups removed with `subscription set`. this.updateListeners(); @@ -303,10 +263,43 @@ export class SubscriptionSet extends SubscribeCapable { * @internal */ private updateListeners() { - if (!this.aggregatedListener) return; + // Actual list of channels and groups. + const channelGroups: string[] = []; + const channels: string[] = []; + + // Gather actual information about active channels / groups. + this.subscriptionList.forEach((subscription) => { + if (subscription.channelGroups.length) channelGroups.push(...subscription.channelGroups); + if (subscription.channels.length) channels.push(...subscription.channels); + }); + + // Identify channels / groups which should be added / removed. + const channelsToRemove = this.channelNames.filter((channel) => !channels.includes(channel)); + const groupsToRemove = this.groupNames.filter((group) => !channelGroups.includes(group)); + const channelsToAdd = channels.filter((channel) => !this.channelNames.includes(channel)); + const groupsToAdd = channelGroups.filter((group) => !this.groupNames.includes(group)); + + // Removing type-based listener for unused channels / groups. + if (channelsToRemove.length || groupsToRemove.length) { + this.eventEmitter.removeListener( + this.typeBasedListener, + this.typeBasedListenerId, + channelsToRemove, + groupsToRemove, + ); + } + + // Adding type-based listener for unused channels / groups. + if (channelsToAdd.length || groupsToAdd.length) + this.eventEmitter.addListener(this.typeBasedListener, channelsToAdd, groupsToAdd, this.typeBasedListenerId); const aggregatedListener = this.aggregatedListener; - this.removeListener(this.aggregatedListener); - this.addListener(aggregatedListener); + if (aggregatedListener) this.removeListener(aggregatedListener); + + // Set actual list of channels and groups. + this.groupNames = channelGroups; + this.channelNames = channels; + + if (aggregatedListener) this.addListener(aggregatedListener); } } diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index a7baac897..59b694f37 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -616,7 +616,13 @@ const serviceHeartbeatRequests: { [subscriptionKey: string]: | { [userId: string]: - | { channels: string[]; channelGroups: string[]; timestamp: number; response?: [Response, ArrayBuffer] } + | { + channels: string[]; + channelGroups: string[]; + timestamp: number; + clientIdentifier?: string; + response?: [Response, ArrayBuffer]; + } | undefined; } | undefined; @@ -932,7 +938,7 @@ const handleHeartbeatRequestEvent = (event: SendRequestEvent) => { const heartbeatRequestKey = `${client.userId}_${clientAggregateAuthKey(client) ?? ''}`; const hbRequestsBySubscriptionKey = serviceHeartbeatRequests[client.subscriptionKey]; const hbRequests = (hbRequestsBySubscriptionKey ?? {})[heartbeatRequestKey]; - notifyRequestProcessing('start', [client], new Date().toISOString(), request); + notifyRequestProcessing('start', [client], new Date().toISOString(), event.request); if (!request) { consoleLog( @@ -1005,17 +1011,28 @@ const handleSendLeaveRequestEvent = (data: SendRequestEvent, client?: PubNubClie if (!client) return; // Clean up client subscription information if there is no more channels / groups to use. - const { subscription } = client; + const { subscription, heartbeat } = client; const serviceRequestId = subscription?.serviceRequestId; - if (subscription) { - if (subscription.channels.length === 0 && subscription.channelGroups.length === 0) { - subscription.channelGroupQuery = ''; - subscription.path = ''; - subscription.previousTimetoken = '0'; - subscription.timetoken = '0'; - delete subscription.region; - delete subscription.serviceRequestId; - delete subscription.request; + if (subscription && subscription.channels.length === 0 && subscription.channelGroups.length === 0) { + subscription.channelGroupQuery = ''; + subscription.path = ''; + subscription.previousTimetoken = '0'; + subscription.timetoken = '0'; + delete subscription.region; + delete subscription.serviceRequestId; + delete subscription.request; + } + + if (serviceHeartbeatRequests[client.subscriptionKey]) { + if (heartbeat && heartbeat.channels.length === 0 && heartbeat.channelGroups.length === 0) { + const hbRequestsBySubscriptionKey = (serviceHeartbeatRequests[client.subscriptionKey] ??= {}); + const heartbeatRequestKey = `${client.userId}_${clientAggregateAuthKey(client) ?? ''}`; + + if ( + hbRequestsBySubscriptionKey[heartbeatRequestKey] && + hbRequestsBySubscriptionKey[heartbeatRequestKey].clientIdentifier === client.clientIdentifier + ) + delete hbRequestsBySubscriptionKey[heartbeatRequestKey]!.clientIdentifier; } } @@ -1460,8 +1477,8 @@ const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportR const hbRequestsBySubscriptionKey = (serviceHeartbeatRequests[client.subscriptionKey] ??= {}); const heartbeatRequestKey = `${client.userId}_${clientAggregateAuthKey(client) ?? ''}`; - const channelGroupsForAnnouncement: string[] = client.heartbeat.channelGroups; - const channelsForAnnouncement: string[] = client.heartbeat.channels; + const channelGroupsForAnnouncement: string[] = [...client.heartbeat.channelGroups]; + const channelsForAnnouncement: string[] = [...client.heartbeat.channels]; let aggregatedState: Record; let failedPreviousRequest = false; let aggregated: boolean; @@ -1470,6 +1487,7 @@ const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportR hbRequestsBySubscriptionKey[heartbeatRequestKey] = { channels: channelsForAnnouncement, channelGroups: channelGroupsForAnnouncement, + clientIdentifier: client.clientIdentifier, timestamp: Date.now(), }; aggregatedState = client.heartbeat.presenceState ?? {}; @@ -1490,7 +1508,10 @@ const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportR minimumHeartbeatInterval = Math.min(minimumHeartbeatInterval, client.heartbeatInterval); } - if (aggregated) { + // Check whether multiple instance aggregate heartbeat and there is previous sender known. + // `clientIdentifier` maybe empty in case if client which triggered heartbeats before has been invalidated and new + // should handle heartbeat unconditionally. + if (aggregated && hbRequestsBySubscriptionKey[heartbeatRequestKey].clientIdentifier) { const expectedTimestamp = hbRequestsBySubscriptionKey[heartbeatRequestKey].timestamp + minimumHeartbeatInterval * 1000; const currentTimestamp = Date.now(); @@ -1502,11 +1523,12 @@ const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportR } delete hbRequestsBySubscriptionKey[heartbeatRequestKey]!.response; + hbRequestsBySubscriptionKey[heartbeatRequestKey]!.clientIdentifier = client.clientIdentifier; // Aggregate channels for similar clients which is pending for heartbeat. - for (const client of clients) { - const { heartbeat } = client; - if (heartbeat === undefined || client.clientIdentifier === event.clientIdentifier) continue; + for (const _client of clients) { + const { heartbeat } = _client; + if (heartbeat === undefined || _client.clientIdentifier === event.clientIdentifier) continue; // Append presence state from the client (will override previously set value if already set). if (heartbeat.presenceState) aggregatedState = { ...aggregatedState, ...heartbeat.presenceState }; @@ -1526,11 +1548,13 @@ const heartbeatTransportRequestFromEvent = (event: SendRequestEvent): TransportR if (!channelsForAnnouncement.includes(objectName) && !channelGroupsForAnnouncement.includes(objectName)) delete aggregatedState[objectName]; } + // No need to try send request with empty list of channels and groups. + if (channelsForAnnouncement.length === 0 && channelGroupsForAnnouncement.length === 0) return undefined; // Update request channels list (if required). - if (channelsForAnnouncement.length) { + if (channelsForAnnouncement.length || channelGroupsForAnnouncement.length) { const pathComponents = request.path.split('/'); - pathComponents[6] = channelsForAnnouncement.join(','); + pathComponents[6] = channelsForAnnouncement.length ? channelsForAnnouncement.join(',') : ','; request.path = pathComponents.join('/'); } @@ -1619,6 +1643,22 @@ const leaveTransportRequestFromEvent = (event: SendRequestEvent): TransportReque return undefined; } + // Update aggregated heartbeat state object. + if (client && serviceHeartbeatRequests[client.subscriptionKey] && (channels.length || channelGroups.length)) { + const hbRequestsBySubscriptionKey = serviceHeartbeatRequests[client.subscriptionKey]!; + const heartbeatRequestKey = `${client.userId}_${clientAggregateAuthKey(client) ?? ''}`; + + if (hbRequestsBySubscriptionKey[heartbeatRequestKey]) { + let { channels: hbChannels, channelGroups: hbChannelGroups } = hbRequestsBySubscriptionKey[heartbeatRequestKey]; + + if (channelGroups.length) hbChannelGroups = hbChannelGroups.filter((group) => !channels.includes(group)); + if (channels.length) hbChannels = hbChannels.filter((channel) => !channels.includes(channel)); + + hbRequestsBySubscriptionKey[heartbeatRequestKey].channelGroups = hbChannelGroups; + hbRequestsBySubscriptionKey[heartbeatRequestKey].channels = hbChannels; + } + } + // Update request channels list (if required). if (channels.length) { const pathComponents = request.path.split('/'); @@ -2140,6 +2180,17 @@ const invalidateClient = (subscriptionKey: string, clientId: string) => { if (serviceRequestId) cancelRequest(serviceRequestId); } + if (serviceHeartbeatRequests[subscriptionKey]) { + const hbRequestsBySubscriptionKey = (serviceHeartbeatRequests[subscriptionKey] ??= {}); + const heartbeatRequestKey = `${invalidatedClient.userId}_${clientAggregateAuthKey(invalidatedClient) ?? ''}`; + + if ( + hbRequestsBySubscriptionKey[heartbeatRequestKey] && + hbRequestsBySubscriptionKey[heartbeatRequestKey].clientIdentifier === invalidatedClient.clientIdentifier + ) + delete hbRequestsBySubscriptionKey[heartbeatRequestKey]!.clientIdentifier; + } + // Leave subscribed channels / groups properly. if (invalidatedClient.unsubscribeOfflineClients) unsubscribeClient(invalidatedClient); } From f1397e8f90380a5143cb644e18a4eb3e095d50da Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Mon, 31 Mar 2025 19:31:57 +0300 Subject: [PATCH 45/49] Fix issue with presence events (#448) fix(subscription-loop): fix issue with presence events Fix missing `heartbeat` and `leave` REST API calls when the event engine is enabled and `presenceTimeout` or `heartbeatInterval` not set. --- .pubnub.yml | 11 +- CHANGELOG.md | 6 + README.md | 4 +- dist/web/pubnub.js | 44 +- dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/core/endpoints/fetch_messages.js | 24 +- lib/core/pubnub-common.js | 55 +- .../modules/NodeCryptoModule/aesCbcCryptor.js | 2 +- lib/event-engine/dispatcher.js | 24 +- lib/event-engine/index.js | 38 +- lib/event-engine/presence/dispatcher.js | 24 +- lib/event-engine/presence/presence.js | 24 +- lib/file/modules/node.js | 4 +- lib/transport/node-transport.js | 24 +- lib/types/index.d.ts | 4 +- package-lock.json | 3817 +++++++++-------- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/pubnub-common.ts | 32 +- .../modules/NodeCryptoModule/aesCbcCryptor.ts | 2 +- src/event-engine/dispatcher.ts | 2 +- src/event-engine/index.ts | 15 +- src/file/modules/node.ts | 4 +- .../endpoints/message_actions.test.ts | 34 +- 25 files changed, 2365 insertions(+), 1839 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index b7f47d281..2025b5281 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,10 @@ --- changelog: + - date: 2025-03-31 + version: v9.3.2 + changes: + - type: bug + text: "Fix missing `heartbeat` and `leave` REST API calls when the event engine is enabled and `presenceTimeout` or `heartbeatInterval` not set." - date: 2025-03-25 version: v9.3.1 changes: @@ -1197,7 +1202,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '9.3.1' +version: '9.3.2' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1213,7 +1218,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v9.3.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.3.2.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1884,7 +1889,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v9.3.1/pubnub.9.3.1.js + location: https://github.com/pubnub/javascript/releases/download/v9.3.2/pubnub.9.3.2.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index c4cf21afc..5b6d19c0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v9.3.2 +March 31 2025 + +#### Fixed +- Fix missing `heartbeat` and `leave` REST API calls when the event engine is enabled and `presenceTimeout` or `heartbeatInterval` not set. + ## v9.3.1 March 25 2025 diff --git a/README.md b/README.md index 3524560a3..29b144373 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.2.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.2.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 24ba3c5f2..637676857 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3939,7 +3939,7 @@ return base.PubNubFile; }, get version() { - return '9.3.1'; + return '9.3.2'; }, getVersion() { return this.version; @@ -8641,6 +8641,8 @@ } } unsubscribeAll() { + const channelGroups = this.getSubscribedChannels(); + const channels = this.getSubscribedChannels(); this.channels = []; this.groups = []; if (this.dependencies.presenceState) { @@ -8649,18 +8651,18 @@ }); } this.engine.transition(subscriptionChange(this.channels.slice(0), this.groups.slice(0))); - if (this.dependencies.leaveAll) { - this.dependencies.leaveAll(); - } + if (this.dependencies.leaveAll) + this.dependencies.leaveAll({ channels, groups: channelGroups }); } reconnect({ timetoken, region }) { this.engine.transition(reconnect(timetoken, region)); } disconnect() { + const channelGroups = this.getSubscribedChannels(); + const channels = this.getSubscribedChannels(); this.engine.transition(disconnect()); - if (this.dependencies.leaveAll) { - this.dependencies.leaveAll(); - } + if (this.dependencies.leaveAll) + this.dependencies.leaveAll({ channels, groups: channelGroups }); } getSubscribedChannels() { return Array.from(new Set(this.channels.slice(0))); @@ -14024,8 +14026,13 @@ * @param parameters - List of channels and groups where `join` event should be sent. */ join(parameters) { - var _a; - (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.join(parameters); + { + if (this.presenceEventEngine) + this.presenceEventEngine.join(parameters); + else { + this.heartbeat(Object.assign(Object.assign({ channels: parameters.channels, channelGroups: parameters.groups }, (this._configuration.maintainPresenceState && { state: this.presenceState })), { heartbeat: this._configuration.getPresenceTimeout() }), () => { }); + } + } } // endregion // region Leave @@ -14038,16 +14045,27 @@ */ leave(parameters) { var _a; - (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leave(parameters); + { + if (this.presenceEventEngine) + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leave(parameters); + else + this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => { }); + } } /** * Announce user `leave` on all subscribed channels. * * @internal + * + * @param parameters - List of channels and groups where `leave` event should be sent. */ - leaveAll() { - var _a; - (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leaveAll(); + leaveAll(parameters) { + { + if (this.presenceEventEngine) + this.presenceEventEngine.leaveAll(); + else + this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => { }); + } } /** * Grant token permission. diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index b9298d9e1..9fb072609 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),O=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],O=e[i+15],E=t(E=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,E,N,P,o,12,u[1]),P=t(P,C,E,N,l,17,u[2]),N=t(N,P,C,E,h,22,u[3]);E=t(E,N,P,C,d,7,u[4]),C=t(C,E,N,P,p,12,u[5]),P=t(P,C,E,N,g,17,u[6]),N=t(N,P,C,E,y,22,u[7]),E=t(E,N,P,C,f,7,u[8]),C=t(C,E,N,P,b,12,u[9]),P=t(P,C,E,N,m,17,u[10]),N=t(N,P,C,E,v,22,u[11]),E=t(E,N,P,C,w,7,u[12]),C=t(C,E,N,P,S,12,u[13]),P=t(P,C,E,N,k,17,u[14]),E=n(E,N=t(N,P,C,E,O,22,u[15]),P,C,o,5,u[16]),C=n(C,E,N,P,g,9,u[17]),P=n(P,C,E,N,v,14,u[18]),N=n(N,P,C,E,c,20,u[19]),E=n(E,N,P,C,p,5,u[20]),C=n(C,E,N,P,m,9,u[21]),P=n(P,C,E,N,O,14,u[22]),N=n(N,P,C,E,d,20,u[23]),E=n(E,N,P,C,b,5,u[24]),C=n(C,E,N,P,k,9,u[25]),P=n(P,C,E,N,h,14,u[26]),N=n(N,P,C,E,f,20,u[27]),E=n(E,N,P,C,S,5,u[28]),C=n(C,E,N,P,l,9,u[29]),P=n(P,C,E,N,y,14,u[30]),E=s(E,N=n(N,P,C,E,w,20,u[31]),P,C,p,4,u[32]),C=s(C,E,N,P,f,11,u[33]),P=s(P,C,E,N,v,16,u[34]),N=s(N,P,C,E,k,23,u[35]),E=s(E,N,P,C,o,4,u[36]),C=s(C,E,N,P,d,11,u[37]),P=s(P,C,E,N,y,16,u[38]),N=s(N,P,C,E,m,23,u[39]),E=s(E,N,P,C,S,4,u[40]),C=s(C,E,N,P,c,11,u[41]),P=s(P,C,E,N,h,16,u[42]),N=s(N,P,C,E,g,23,u[43]),E=s(E,N,P,C,b,4,u[44]),C=s(C,E,N,P,w,11,u[45]),P=s(P,C,E,N,O,16,u[46]),E=r(E,N=s(N,P,C,E,l,23,u[47]),P,C,c,6,u[48]),C=r(C,E,N,P,y,10,u[49]),P=r(P,C,E,N,k,15,u[50]),N=r(N,P,C,E,p,21,u[51]),E=r(E,N,P,C,w,6,u[52]),C=r(C,E,N,P,h,10,u[53]),P=r(P,C,E,N,m,15,u[54]),N=r(N,P,C,E,o,21,u[55]),E=r(E,N,P,C,f,6,u[56]),C=r(C,E,N,P,O,10,u[57]),P=r(P,C,E,N,g,15,u[58]),N=r(N,P,C,E,S,21,u[59]),E=r(E,N,P,C,d,6,u[60]),C=r(C,E,N,P,v,10,u[61]),P=r(P,C,E,N,l,15,u[62]),N=r(N,P,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var O=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=O[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class O{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:O.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return O.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(O.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=O.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new O({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new O({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,O=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(O=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:O,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.3.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Oe=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Pe=ge("LEFT_ALL",(()=>({}))),Ne=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Fe=ye("EMIT_STATUS",(e=>e)),Te=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Te.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Fe.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Pe.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Te())),De.onExit((()=>Te.cancel)),De.on(je.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Oe.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Oe.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Oe.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Pe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll()}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll()}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Ot extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Pt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Nt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Ft extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Tt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Pn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Nn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Pn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.join(e)}leave(e){var t;null===(t=this.presenceEventEngine)||void 0===t||t.leave(e)}leaveAll(){var e;null===(e=this.presenceEventEngine)||void 0===e||e.leaveAll()}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Nn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends An{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new O({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new jn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,O,N,P,o,12,u[1]),P=t(P,C,O,N,l,17,u[2]),N=t(N,P,C,O,h,22,u[3]);O=t(O,N,P,C,d,7,u[4]),C=t(C,O,N,P,p,12,u[5]),P=t(P,C,O,N,g,17,u[6]),N=t(N,P,C,O,y,22,u[7]),O=t(O,N,P,C,f,7,u[8]),C=t(C,O,N,P,b,12,u[9]),P=t(P,C,O,N,m,17,u[10]),N=t(N,P,C,O,v,22,u[11]),O=t(O,N,P,C,w,7,u[12]),C=t(C,O,N,P,S,12,u[13]),P=t(P,C,O,N,k,17,u[14]),O=n(O,N=t(N,P,C,O,E,22,u[15]),P,C,o,5,u[16]),C=n(C,O,N,P,g,9,u[17]),P=n(P,C,O,N,v,14,u[18]),N=n(N,P,C,O,c,20,u[19]),O=n(O,N,P,C,p,5,u[20]),C=n(C,O,N,P,m,9,u[21]),P=n(P,C,O,N,E,14,u[22]),N=n(N,P,C,O,d,20,u[23]),O=n(O,N,P,C,b,5,u[24]),C=n(C,O,N,P,k,9,u[25]),P=n(P,C,O,N,h,14,u[26]),N=n(N,P,C,O,f,20,u[27]),O=n(O,N,P,C,S,5,u[28]),C=n(C,O,N,P,l,9,u[29]),P=n(P,C,O,N,y,14,u[30]),O=s(O,N=n(N,P,C,O,w,20,u[31]),P,C,p,4,u[32]),C=s(C,O,N,P,f,11,u[33]),P=s(P,C,O,N,v,16,u[34]),N=s(N,P,C,O,k,23,u[35]),O=s(O,N,P,C,o,4,u[36]),C=s(C,O,N,P,d,11,u[37]),P=s(P,C,O,N,y,16,u[38]),N=s(N,P,C,O,m,23,u[39]),O=s(O,N,P,C,S,4,u[40]),C=s(C,O,N,P,c,11,u[41]),P=s(P,C,O,N,h,16,u[42]),N=s(N,P,C,O,g,23,u[43]),O=s(O,N,P,C,b,4,u[44]),C=s(C,O,N,P,w,11,u[45]),P=s(P,C,O,N,E,16,u[46]),O=r(O,N=s(N,P,C,O,l,23,u[47]),P,C,c,6,u[48]),C=r(C,O,N,P,y,10,u[49]),P=r(P,C,O,N,k,15,u[50]),N=r(N,P,C,O,p,21,u[51]),O=r(O,N,P,C,w,6,u[52]),C=r(C,O,N,P,h,10,u[53]),P=r(P,C,O,N,m,15,u[54]),N=r(N,P,C,O,o,21,u[55]),O=r(O,N,P,C,f,6,u[56]),C=r(C,O,N,P,E,10,u[57]),P=r(P,C,O,N,g,15,u[58]),N=r(N,P,C,O,S,21,u[59]),O=r(O,N,P,C,d,6,u[60]),C=r(C,O,N,P,v,10,u[61]),P=r(P,C,O,N,l,15,u[62]),N=r(N,P,C,O,b,21,u[63]);a[0]=a[0]+O|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=E[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new E({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?T(o):o})),s}const F=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,E=!1,O=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(E=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(O=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.3.2"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Ee=ge("DISCONNECT",(()=>({}))),Oe=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Pe=ge("LEFT_ALL",(()=>({}))),Ne=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Te=ye("EMIT_STATUS",(e=>e)),Fe=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Fe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Te.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Oe.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Pe.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Fe())),De.onExit((()=>Fe.cancel)),De.on(je.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Ee.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Oe.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Oe(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Pe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Et extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ot extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Pt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Nt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Tt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class On extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Pn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new On(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Nn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Pn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){this.presenceEventEngine?this.presenceEventEngine.join(e):this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}leave(e){var t;this.presenceEventEngine?null===(t=this.presenceEventEngine)||void 0===t||t.leave(e):this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}leaveAll(e){this.presenceEventEngine?this.presenceEventEngine.leaveAll():this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Nn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends An{constructor(e){var t;const n=F(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new jn((e=>T(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index dcedce464..2ac8caaff 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -124,7 +124,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '9.3.1'; + return '9.3.2'; }, getVersion() { return this.version; diff --git a/lib/core/endpoints/fetch_messages.js b/lib/core/endpoints/fetch_messages.js index 3d65d7d06..34a822254 100644 --- a/lib/core/endpoints/fetch_messages.js +++ b/lib/core/endpoints/fetch_messages.js @@ -20,13 +20,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( }) : function(o, v) { o["default"] = v; }); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); 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) { diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index c470ce500..332f191e9 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( }) : function(o, v) { o["default"] = v; }); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); 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) { @@ -1343,9 +1353,13 @@ class PubNubCore { * @param parameters - List of channels and groups where `join` event should be sent. */ join(parameters) { - var _a; - if (process.env.PRESENCE_MODULE !== 'disabled') - (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.join(parameters); + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) + this.presenceEventEngine.join(parameters); + else { + this.heartbeat(Object.assign(Object.assign({ channels: parameters.channels, channelGroups: parameters.groups }, (this._configuration.maintainPresenceState && { state: this.presenceState })), { heartbeat: this._configuration.getPresenceTimeout() }), () => { }); + } + } else throw new Error('Announce UUID Presence error: presence module disabled'); } @@ -1360,8 +1374,12 @@ class PubNubCore { */ leave(parameters) { var _a; - if (process.env.PRESENCE_MODULE !== 'disabled') - (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leave(parameters); + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) + (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leave(parameters); + else + this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => { }); + } else throw new Error('Announce UUID Leave error: presence module disabled'); } @@ -1369,11 +1387,16 @@ class PubNubCore { * Announce user `leave` on all subscribed channels. * * @internal + * + * @param parameters - List of channels and groups where `leave` event should be sent. */ - leaveAll() { - var _a; - if (process.env.PRESENCE_MODULE !== 'disabled') - (_a = this.presenceEventEngine) === null || _a === void 0 ? void 0 : _a.leaveAll(); + leaveAll(parameters) { + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) + this.presenceEventEngine.leaveAll(); + else + this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => { }); + } else throw new Error('Announce UUID Leave error: presence module disabled'); } diff --git a/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js b/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js index 65b0093e3..935e36aa0 100644 --- a/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js +++ b/lib/crypto/modules/NodeCryptoModule/aesCbcCryptor.js @@ -81,7 +81,7 @@ class AesCbcCryptor { let data = stream.stream.read(); while (data !== null) { if (data) { - const bChunk = Buffer.from(data); + const bChunk = typeof data === 'string' ? Buffer.from(data) : data; const sliceLen = stream.metadataLength - bIv.byteLength; if (bChunk.byteLength < sliceLen) { bIv = Buffer.concat([bIv, bChunk]); diff --git a/lib/event-engine/dispatcher.js b/lib/event-engine/dispatcher.js index b09274532..f5f65ceb1 100644 --- a/lib/event-engine/dispatcher.js +++ b/lib/event-engine/dispatcher.js @@ -20,13 +20,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( }) : function(o, v) { o["default"] = v; }); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); 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) { diff --git a/lib/event-engine/index.js b/lib/event-engine/index.js index 255b7bfbd..7eea35090 100644 --- a/lib/event-engine/index.js +++ b/lib/event-engine/index.js @@ -20,13 +20,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( }) : function(o, v) { o["default"] = v; }); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); Object.defineProperty(exports, "__esModule", { value: true }); exports.EventEngine = void 0; const core_1 = require("./core"); @@ -105,6 +115,8 @@ class EventEngine { } } unsubscribeAll() { + const channelGroups = this.getSubscribedChannels(); + const channels = this.getSubscribedChannels(); this.channels = []; this.groups = []; if (this.dependencies.presenceState) { @@ -113,18 +125,18 @@ class EventEngine { }); } this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0))); - if (this.dependencies.leaveAll) { - this.dependencies.leaveAll(); - } + if (this.dependencies.leaveAll) + this.dependencies.leaveAll({ channels, groups: channelGroups }); } reconnect({ timetoken, region }) { this.engine.transition(events.reconnect(timetoken, region)); } disconnect() { + const channelGroups = this.getSubscribedChannels(); + const channels = this.getSubscribedChannels(); this.engine.transition(events.disconnect()); - if (this.dependencies.leaveAll) { - this.dependencies.leaveAll(); - } + if (this.dependencies.leaveAll) + this.dependencies.leaveAll({ channels, groups: channelGroups }); } getSubscribedChannels() { return Array.from(new Set(this.channels.slice(0))); diff --git a/lib/event-engine/presence/dispatcher.js b/lib/event-engine/presence/dispatcher.js index c4f0ebef2..120c13478 100644 --- a/lib/event-engine/presence/dispatcher.js +++ b/lib/event-engine/presence/dispatcher.js @@ -20,13 +20,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( }) : function(o, v) { o["default"] = v; }); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); 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) { diff --git a/lib/event-engine/presence/presence.js b/lib/event-engine/presence/presence.js index 826929e72..a319f1e5a 100644 --- a/lib/event-engine/presence/presence.js +++ b/lib/event-engine/presence/presence.js @@ -20,13 +20,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( }) : function(o, v) { o["default"] = v; }); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); Object.defineProperty(exports, "__esModule", { value: true }); exports.PresenceEventEngine = void 0; const core_1 = require("../core"); diff --git a/lib/file/modules/node.js b/lib/file/modules/node.js index 886a205d7..8f70a0dcc 100644 --- a/lib/file/modules/node.js +++ b/lib/file/modules/node.js @@ -38,7 +38,7 @@ class PubNubFile { let fileName; if (stream && stream instanceof stream_1.Readable) { fileData = stream; - if (stream instanceof fs_1.default.ReadStream && !(stream.path instanceof buffer_1.Buffer)) { + if (stream instanceof fs_1.default.ReadStream && typeof stream.path === 'string') { fileName = (0, path_1.basename)(stream.path); contentLength = fs_1.default.statSync(stream.path).size; } @@ -80,7 +80,7 @@ class PubNubFile { */ toBuffer() { return __awaiter(this, void 0, void 0, function* () { - if (this.data instanceof buffer_1.Buffer) + if (!(this.data instanceof stream_1.Readable)) return this.data; const stream = this.data; return new Promise((resolve, reject) => { diff --git a/lib/transport/node-transport.js b/lib/transport/node-transport.js index 91884f872..5dad44887 100644 --- a/lib/transport/node-transport.js +++ b/lib/transport/node-transport.js @@ -20,13 +20,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? ( }) : function(o, v) { o["default"] = v; }); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; +var __importStar = (this && this.__importStar) || (function () { + var ownKeys = function(o) { + ownKeys = Object.getOwnPropertyNames || function (o) { + var ar = []; + for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; + return ar; + }; + return ownKeys(o); + }; + return function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); + __setModuleDefault(result, mod); + return result; + }; +})(); 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) { diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 7091bedc5..263757806 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -1,4 +1,4 @@ -import { Readable, PassThrough } from 'stream'; +import { Readable } from 'stream'; import { Buffer } from 'buffer'; import { ProxyAgentOptions } from 'proxy-agent'; @@ -2199,7 +2199,7 @@ declare namespace PubNub { * * @returns Asynchronous results of conversion to the {@link Readable} stream. */ - toStream(): Promise; + toStream(): Promise; /** * Convert {@link PubNub} File object content to {@link File}. * diff --git a/package-lock.json b/package-lock.json index 843713e8f..ecde6d336 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "9.1.0", + "version": "9.3.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "9.1.0", + "version": "9.3.1", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", @@ -88,6 +88,20 @@ "node": ">=6.0.0" } }, + "node_modules/@asamuzakjp/css-color": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-3.1.1.tgz", + "integrity": "sha512-hpRD68SV2OMcZCsrbdkccTw5FXjNDLo5OuqSHyHZfwweGsDWZwDJ2+gONyNAbazZclobMirACLw0lk8WVxIqxA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@csstools/css-calc": "^2.1.2", + "@csstools/css-color-parser": "^3.0.8", + "@csstools/css-parser-algorithms": "^3.0.4", + "@csstools/css-tokenizer": "^3.0.3", + "lru-cache": "^10.4.3" + } + }, "node_modules/@babel/code-frame": { "version": "7.26.2", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz", @@ -103,9 +117,9 @@ } }, "node_modules/@babel/compat-data": { - "version": "7.26.2", - "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.26.2.tgz", - "integrity": "sha512-Z0WgzSEa+aUcdiJuCIqgujCshpMWgUpgOxXotrYPSA53hA3qopNaqcJpyr0hVb1FeWdnqFA35/fUtXgBK8srQg==", + "version": "7.26.8", + "resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.26.8.tgz", + "integrity": "sha512-oH5UPLMWR3L2wEFLnFJ1TZXqHufiTKAiLfqw5zkhS4dKXLJ10yVztfil/twG8EDTA4F/tvVNw9nOl4ZMslB8rQ==", "license": "MIT", "peer": true, "engines": { @@ -113,22 +127,22 @@ } }, "node_modules/@babel/core": { - "version": "7.26.0", - "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.26.0.tgz", - "integrity": "sha512-i1SLeK+DzNnQ3LL/CswPCa/E5u4lh1k6IAEphON8F+cXt0t9euTshDru0q7/IqMa1PMPz5RnHuHscF8/ZJsStg==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/core/-/core-7.26.10.tgz", + "integrity": "sha512-vMqyb7XCDMPvJFFOaT9kxtiRh42GwlZEg1/uIgtZshS5a/8OaduUfCi7kynKgc3Tw/6Uo2D+db9qBttghhmxwQ==", "license": "MIT", "peer": true, "dependencies": { "@ampproject/remapping": "^2.2.0", - "@babel/code-frame": "^7.26.0", - "@babel/generator": "^7.26.0", - "@babel/helper-compilation-targets": "^7.25.9", + "@babel/code-frame": "^7.26.2", + "@babel/generator": "^7.26.10", + "@babel/helper-compilation-targets": "^7.26.5", "@babel/helper-module-transforms": "^7.26.0", - "@babel/helpers": "^7.26.0", - "@babel/parser": "^7.26.0", - "@babel/template": "^7.25.9", - "@babel/traverse": "^7.25.9", - "@babel/types": "^7.26.0", + "@babel/helpers": "^7.26.10", + "@babel/parser": "^7.26.10", + "@babel/template": "^7.26.9", + "@babel/traverse": "^7.26.10", + "@babel/types": "^7.26.10", "convert-source-map": "^2.0.0", "debug": "^4.1.0", "gensync": "^1.0.0-beta.2", @@ -154,14 +168,14 @@ } }, "node_modules/@babel/generator": { - "version": "7.26.2", - "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.26.2.tgz", - "integrity": "sha512-zevQbhbau95nkoxSq3f/DC/SC+EEOUZd3DYqfSkMhY2/wfSeaHV1Ew4vk8e+x8lja31IbyuUa2uQ3JONqKbysw==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.27.0.tgz", + "integrity": "sha512-VybsKvpiN1gU1sdMZIp7FcqphVVKEwcuj02x73uvcHE0PTihx1nlBcowYWhDwjpoAXRv43+gDzyggGnn1XZhVw==", "license": "MIT", "peer": true, "dependencies": { - "@babel/parser": "^7.26.2", - "@babel/types": "^7.26.0", + "@babel/parser": "^7.27.0", + "@babel/types": "^7.27.0", "@jridgewell/gen-mapping": "^0.3.5", "@jridgewell/trace-mapping": "^0.3.25", "jsesc": "^3.0.2" @@ -183,28 +197,14 @@ "node": ">=6.9.0" } }, - "node_modules/@babel/helper-builder-binary-assignment-operator-visitor": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/helper-builder-binary-assignment-operator-visitor/-/helper-builder-binary-assignment-operator-visitor-7.25.9.tgz", - "integrity": "sha512-C47lC7LIDCnz0h4vai/tpNOI95tCd5ZT3iBt/DBH5lXKHZsyNQv18yf1wIIg2ntiQNgmAvA+DgZ82iW8Qdym8g==", - "license": "MIT", - "peer": true, - "dependencies": { - "@babel/traverse": "^7.25.9", - "@babel/types": "^7.25.9" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/@babel/helper-compilation-targets": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.25.9.tgz", - "integrity": "sha512-j9Db8Suy6yV/VHa4qzrj9yZfZxhLWQdVnRlXxmKLYlhWUVB1sB2G5sxuWYXk/whHD9iW76PmNzxZ4UCnTQTVEQ==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.27.0.tgz", + "integrity": "sha512-LVk7fbXml0H2xH34dFzKQ7TDZ2G4/rVTOrq9V+icbbadjbVxxeFeDsNHv2SrZeWoA+6ZiTyWYWtScEIW07EAcA==", "license": "MIT", "peer": true, "dependencies": { - "@babel/compat-data": "^7.25.9", + "@babel/compat-data": "^7.26.8", "@babel/helper-validator-option": "^7.25.9", "browserslist": "^4.24.0", "lru-cache": "^5.1.1", @@ -235,18 +235,18 @@ } }, "node_modules/@babel/helper-create-class-features-plugin": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.25.9.tgz", - "integrity": "sha512-UTZQMvt0d/rSz6KI+qdu7GQze5TIajwTS++GUozlw8VBJDEOAqSXwm1WvmYEZwqdqSGQshRocPDqrt4HBZB3fQ==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/helper-create-class-features-plugin/-/helper-create-class-features-plugin-7.27.0.tgz", + "integrity": "sha512-vSGCvMecvFCd/BdpGlhpXYNhhC4ccxyvQWpbGL4CWbvfEoLFWUZuSuf7s9Aw70flgQF+6vptvgK2IfOnKlRmBg==", "license": "MIT", "peer": true, "dependencies": { "@babel/helper-annotate-as-pure": "^7.25.9", "@babel/helper-member-expression-to-functions": "^7.25.9", "@babel/helper-optimise-call-expression": "^7.25.9", - "@babel/helper-replace-supers": "^7.25.9", + "@babel/helper-replace-supers": "^7.26.5", "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9", - "@babel/traverse": "^7.25.9", + "@babel/traverse": "^7.27.0", "semver": "^6.3.1" }, "engines": { @@ -267,14 +267,14 @@ } }, "node_modules/@babel/helper-create-regexp-features-plugin": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.25.9.tgz", - "integrity": "sha512-ORPNZ3h6ZRkOyAa/SaHU+XsLZr0UQzRwuDQ0cczIA17nAzZ+85G5cVkOJIj7QavLZGSe8QXUmNFxSZzjcZF9bw==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/helper-create-regexp-features-plugin/-/helper-create-regexp-features-plugin-7.27.0.tgz", + "integrity": "sha512-fO8l08T76v48BhpNRW/nQ0MxfnSdoSKUJBMjubOAYffsVuGG5qOfMq7N6Es7UJvi7Y8goXXo07EfcHZXDPuELQ==", "license": "MIT", "peer": true, "dependencies": { "@babel/helper-annotate-as-pure": "^7.25.9", - "regexpu-core": "^6.1.1", + "regexpu-core": "^6.2.0", "semver": "^6.3.1" }, "engines": { @@ -295,9 +295,9 @@ } }, "node_modules/@babel/helper-define-polyfill-provider": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/@babel/helper-define-polyfill-provider/-/helper-define-polyfill-provider-0.6.2.tgz", - "integrity": "sha512-LV76g+C502biUK6AyZ3LK10vDpDyCzZnhZFXkH1L75zHPj68+qc8Zfpx2th+gzwA2MzyK+1g/3EPl62yFnVttQ==", + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/@babel/helper-define-polyfill-provider/-/helper-define-polyfill-provider-0.6.4.tgz", + "integrity": "sha512-jljfR1rGnXXNWnmQg2K3+bvhkxB51Rl32QRaOTuwwjviGrHzIbSc8+x9CpraDtbT7mfyjXObULP4w/adunNwAw==", "license": "MIT", "peer": true, "dependencies": { @@ -371,9 +371,9 @@ } }, "node_modules/@babel/helper-plugin-utils": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.25.9.tgz", - "integrity": "sha512-kSMlyUVdWe25rEsRGviIgOWnoT/nfABVWlqt9N19/dIPWViAOW2s9wznP5tURbs/IDuNk4gPy3YdYRgH3uxhBw==", + "version": "7.26.5", + "resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.26.5.tgz", + "integrity": "sha512-RS+jZcRdZdRFzMyr+wcsaqOmld1/EqTghfaBGQQd/WnRdzdlvSZ//kF7U8VQTxf1ynZ4cjUcYgjVGx13ewNPMg==", "license": "MIT", "peer": true, "engines": { @@ -399,15 +399,15 @@ } }, "node_modules/@babel/helper-replace-supers": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.25.9.tgz", - "integrity": "sha512-IiDqTOTBQy0sWyeXyGSC5TBJpGFXBkRynjBeXsvbhQFKj2viwJC76Epz35YLU1fpe/Am6Vppb7W7zM4fPQzLsQ==", + "version": "7.26.5", + "resolved": "https://registry.npmjs.org/@babel/helper-replace-supers/-/helper-replace-supers-7.26.5.tgz", + "integrity": "sha512-bJ6iIVdYX1YooY2X7w1q6VITt+LnUILtNk7zT78ykuwStx8BauCzxvFqFaHjOpW1bVnSUM1PN1f0p5P21wHxvg==", "license": "MIT", "peer": true, "dependencies": { "@babel/helper-member-expression-to-functions": "^7.25.9", "@babel/helper-optimise-call-expression": "^7.25.9", - "@babel/traverse": "^7.25.9" + "@babel/traverse": "^7.26.5" }, "engines": { "node": ">=6.9.0" @@ -416,20 +416,6 @@ "@babel/core": "^7.0.0" } }, - "node_modules/@babel/helper-simple-access": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.25.9.tgz", - "integrity": "sha512-c6WHXuiaRsJTyHYLJV75t9IqsmTbItYfdj99PnzYGQZkYKvan5/2jKJ7gu31J3/BJ/A18grImSPModuyG/Eo0Q==", - "license": "MIT", - "peer": true, - "dependencies": { - "@babel/traverse": "^7.25.9", - "@babel/types": "^7.25.9" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/@babel/helper-skip-transparent-expression-wrappers": { "version": "7.25.9", "resolved": "https://registry.npmjs.org/@babel/helper-skip-transparent-expression-wrappers/-/helper-skip-transparent-expression-wrappers-7.25.9.tgz", @@ -489,27 +475,27 @@ } }, "node_modules/@babel/helpers": { - "version": "7.26.0", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.26.0.tgz", - "integrity": "sha512-tbhNuIxNcVb21pInl3ZSjksLCvgdZy9KwJ8brv993QtIVKJBBkYXz4q4ZbAv31GdnC+R90np23L5FbEBlthAEw==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.27.0.tgz", + "integrity": "sha512-U5eyP/CTFPuNE3qk+WZMxFkp/4zUzdceQlfzf7DdGdhp+Fezd7HD+i8Y24ZuTMKX3wQBld449jijbGq6OdGNQg==", "license": "MIT", "peer": true, "dependencies": { - "@babel/template": "^7.25.9", - "@babel/types": "^7.26.0" + "@babel/template": "^7.27.0", + "@babel/types": "^7.27.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/parser": { - "version": "7.26.2", - "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.2.tgz", - "integrity": "sha512-DWMCZH9WA4Maitz2q21SRKHo9QXZxkDsbNZoVD62gusNtNBBqDg9i7uOhASfTfIGNzW+O+r7+jAlM8dwphcJKQ==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.27.0.tgz", + "integrity": "sha512-iaepho73/2Pz7w2eMS0Q5f83+0RKI7i4xmiYeBmDzfRVbQtTOG7Ts0S4HzJVsTMGI9keU8rNfuZr8DKfSt7Yyg==", "license": "MIT", "peer": true, "dependencies": { - "@babel/types": "^7.26.0" + "@babel/types": "^7.27.0" }, "bin": { "parser": "bin/babel-parser.js" @@ -602,24 +588,6 @@ "@babel/core": "^7.0.0" } }, - "node_modules/@babel/plugin-proposal-class-properties": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-class-properties/-/plugin-proposal-class-properties-7.18.6.tgz", - "integrity": "sha512-cumfXOF0+nzZrrN8Rf0t7M+tF6sZc7vhQwYQck9q1/5w2OExlD+b4v4RpMJFaV1Z7WcDRgO6FqvxqxGlwo+RHQ==", - "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-class-properties instead.", - "license": "MIT", - "peer": true, - "dependencies": { - "@babel/helper-create-class-features-plugin": "^7.18.6", - "@babel/helper-plugin-utils": "^7.18.6" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, "node_modules/@babel/plugin-proposal-export-default-from": { "version": "7.25.9", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-export-default-from/-/plugin-proposal-export-default-from-7.25.9.tgz", @@ -636,43 +604,6 @@ "@babel/core": "^7.0.0-0" } }, - "node_modules/@babel/plugin-proposal-nullish-coalescing-operator": { - "version": "7.18.6", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-nullish-coalescing-operator/-/plugin-proposal-nullish-coalescing-operator-7.18.6.tgz", - "integrity": "sha512-wQxQzxYeJqHcfppzBDnm1yAY0jSRkUXR2z8RePZYrKwMKgMlE8+Z6LUno+bd6LvbGh8Gltvy74+9pIYkr+XkKA==", - "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-nullish-coalescing-operator instead.", - "license": "MIT", - "peer": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.18.6", - "@babel/plugin-syntax-nullish-coalescing-operator": "^7.8.3" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, - "node_modules/@babel/plugin-proposal-optional-chaining": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-optional-chaining/-/plugin-proposal-optional-chaining-7.21.0.tgz", - "integrity": "sha512-p4zeefM72gpmEe2fkUr/OnOXpWEf8nAgk7ZYVqqfFiyIG7oFfVZcCrU64hWn5xp4tQ9LkV4bTIa5rD0KANpKNA==", - "deprecated": "This proposal has been merged to the ECMAScript standard and thus this plugin is no longer maintained. Please use @babel/plugin-transform-optional-chaining instead.", - "license": "MIT", - "peer": true, - "dependencies": { - "@babel/helper-plugin-utils": "^7.20.2", - "@babel/helper-skip-transparent-expression-wrappers": "^7.20.0", - "@babel/plugin-syntax-optional-chaining": "^7.8.3" - }, - "engines": { - "node": ">=6.9.0" - }, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, "node_modules/@babel/plugin-proposal-private-property-in-object": { "version": "7.21.0-placeholder-for-preset-env.2", "resolved": "https://registry.npmjs.org/@babel/plugin-proposal-private-property-in-object/-/plugin-proposal-private-property-in-object-7.21.0-placeholder-for-preset-env.2.tgz", @@ -1020,15 +951,15 @@ } }, "node_modules/@babel/plugin-transform-async-generator-functions": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-generator-functions/-/plugin-transform-async-generator-functions-7.25.9.tgz", - "integrity": "sha512-RXV6QAzTBbhDMO9fWwOmwwTuYaiPbggWQ9INdZqAYeSHyG7FzQ+nOZaUUjNwKv9pV3aE4WFqFm1Hnbci5tBCAw==", + "version": "7.26.8", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-async-generator-functions/-/plugin-transform-async-generator-functions-7.26.8.tgz", + "integrity": "sha512-He9Ej2X7tNf2zdKMAGOsmg2MrFc+hfoAhd3po4cWfo/NWjzEAKa0oQruj1ROVUdl0e6fb6/kE/G3SSxE0lRJOg==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-plugin-utils": "^7.26.5", "@babel/helper-remap-async-to-generator": "^7.25.9", - "@babel/traverse": "^7.25.9" + "@babel/traverse": "^7.26.8" }, "engines": { "node": ">=6.9.0" @@ -1056,13 +987,13 @@ } }, "node_modules/@babel/plugin-transform-block-scoped-functions": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.25.9.tgz", - "integrity": "sha512-toHc9fzab0ZfenFpsyYinOX0J/5dgJVA2fm64xPewu7CoYHWEivIWKxkK2rMi4r3yQqLnVmheMXRdG+k239CgA==", + "version": "7.26.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoped-functions/-/plugin-transform-block-scoped-functions-7.26.5.tgz", + "integrity": "sha512-chuTSY+hq09+/f5lMj8ZSYgCFpppV2CbYrhNFJ1BFoXpiWPnnAb7R0MqrafCpN8E1+YRrtM1MXZHJdIx8B6rMQ==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9" + "@babel/helper-plugin-utils": "^7.26.5" }, "engines": { "node": ">=6.9.0" @@ -1072,13 +1003,13 @@ } }, "node_modules/@babel/plugin-transform-block-scoping": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.25.9.tgz", - "integrity": "sha512-1F05O7AYjymAtqbsFETboN1NvBdcnzMerO+zlMyJBEz6WkMdejvGWw9p05iTSjC85RLlBseHHQpYaM4gzJkBGg==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-block-scoping/-/plugin-transform-block-scoping-7.27.0.tgz", + "integrity": "sha512-u1jGphZ8uDI2Pj/HJj6YQ6XQLZCNjOlprjxB5SVz6rq2T6SwAR+CdrWK0CP7F+9rDVMXdB0+r6Am5G5aobOjAQ==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9" + "@babel/helper-plugin-utils": "^7.26.5" }, "engines": { "node": ">=6.9.0" @@ -1252,13 +1183,12 @@ } }, "node_modules/@babel/plugin-transform-exponentiation-operator": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.25.9.tgz", - "integrity": "sha512-KRhdhlVk2nObA5AYa7QMgTMTVJdfHprfpAk4DjZVtllqRg9qarilstTKEhpVjyt+Npi8ThRyiV8176Am3CodPA==", + "version": "7.26.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-exponentiation-operator/-/plugin-transform-exponentiation-operator-7.26.3.tgz", + "integrity": "sha512-7CAHcQ58z2chuXPWblnn1K6rLDnDWieghSOEmqQsrBenH0P9InCUtOJYD89pvngljmZlJcz3fcmgYsXFNGa1ZQ==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-builder-binary-assignment-operator-visitor": "^7.25.9", "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { @@ -1285,14 +1215,14 @@ } }, "node_modules/@babel/plugin-transform-flow-strip-types": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.25.9.tgz", - "integrity": "sha512-/VVukELzPDdci7UUsWQaSkhgnjIWXnIyRpM02ldxaVoFK96c41So8JcKT3m0gYjyv7j5FNPGS5vfELrWalkbDA==", + "version": "7.26.5", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-flow-strip-types/-/plugin-transform-flow-strip-types-7.26.5.tgz", + "integrity": "sha512-eGK26RsbIkYUns3Y8qKl362juDDYK+wEdPGHGrhzUl6CewZFo55VZ7hg+CyMFU4dd5QQakBN86nBMpRsFpRvbQ==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9", - "@babel/plugin-syntax-flow": "^7.25.9" + "@babel/helper-plugin-utils": "^7.26.5", + "@babel/plugin-syntax-flow": "^7.26.0" }, "engines": { "node": ">=6.9.0" @@ -1302,13 +1232,13 @@ } }, "node_modules/@babel/plugin-transform-for-of": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.25.9.tgz", - "integrity": "sha512-LqHxduHoaGELJl2uhImHwRQudhCM50pT46rIBNvtT/Oql3nqiS3wOwP+5ten7NpYSXrrVLgtZU3DZmPtWZo16A==", + "version": "7.26.9", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-for-of/-/plugin-transform-for-of-7.26.9.tgz", + "integrity": "sha512-Hry8AusVm8LW5BVFgiyUReuoGzPUpdHQQqJY5bZnbbf+ngOHWuCuYFKw/BqaaWlvEUrF91HMhDtEaI1hZzNbLg==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-plugin-utils": "^7.26.5", "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9" }, "engines": { @@ -1418,15 +1348,14 @@ } }, "node_modules/@babel/plugin-transform-modules-commonjs": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.25.9.tgz", - "integrity": "sha512-dwh2Ol1jWwL2MgkCzUSOvfmKElqQcuswAZypBSUsScMXvgdT8Ekq5YA6TtqpTVWH+4903NmboMuH1o9i8Rxlyg==", + "version": "7.26.3", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-modules-commonjs/-/plugin-transform-modules-commonjs-7.26.3.tgz", + "integrity": "sha512-MgR55l4q9KddUDITEzEFYn5ZsGDXMSsU9E+kh7fjRXTIC3RHqfCo8RPRbyReYJh44HQ/yomFkqbOFohXvDCiIQ==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-module-transforms": "^7.25.9", - "@babel/helper-plugin-utils": "^7.25.9", - "@babel/helper-simple-access": "^7.25.9" + "@babel/helper-module-transforms": "^7.26.0", + "@babel/helper-plugin-utils": "^7.25.9" }, "engines": { "node": ">=6.9.0" @@ -1505,13 +1434,13 @@ } }, "node_modules/@babel/plugin-transform-nullish-coalescing-operator": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.25.9.tgz", - "integrity": "sha512-ENfftpLZw5EItALAD4WsY/KUWvhUlZndm5GC7G3evUsVeSJB6p0pBeLQUnRnBCBx7zV0RKQjR9kCuwrsIrjWog==", + "version": "7.26.6", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-nullish-coalescing-operator/-/plugin-transform-nullish-coalescing-operator-7.26.6.tgz", + "integrity": "sha512-CKW8Vu+uUZneQCPtXmSBUC6NCAUdya26hWCElAWh5mVSlSRsmiCPUUDKb3Z0szng1hiAJa098Hkhg9o4SE35Qw==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9" + "@babel/helper-plugin-utils": "^7.26.5" }, "engines": { "node": ">=6.9.0" @@ -1740,13 +1669,13 @@ } }, "node_modules/@babel/plugin-transform-regenerator": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.25.9.tgz", - "integrity": "sha512-vwDcDNsgMPDGP0nMqzahDWE5/MLcX8sv96+wfX7as7LoF/kr97Bo/7fI00lXY4wUXYfVmwIIyG80fGZ1uvt2qg==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.27.0.tgz", + "integrity": "sha512-LX/vCajUJQDqE7Aum/ELUMZAY19+cDpghxrnyt5I1tV6X5PyC86AOoWXWFYFeIvauyeSA6/ktn4tQVn/3ZifsA==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-plugin-utils": "^7.26.5", "regenerator-transform": "^0.15.2" }, "engines": { @@ -1790,16 +1719,16 @@ } }, "node_modules/@babel/plugin-transform-runtime": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.25.9.tgz", - "integrity": "sha512-nZp7GlEl+yULJrClz0SwHPqir3lc0zsPrDHQUcxGspSL7AKrexNSEfTbfqnDNJUO13bgKyfuOLMF8Xqtu8j3YQ==", + "version": "7.26.10", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-runtime/-/plugin-transform-runtime-7.26.10.tgz", + "integrity": "sha512-NWaL2qG6HRpONTnj4JvDU6th4jYeZOJgu3QhmFTCihib0ermtOJqktA5BduGm3suhhVe9EMP9c9+mfJ/I9slqw==", "license": "MIT", "peer": true, "dependencies": { "@babel/helper-module-imports": "^7.25.9", - "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-plugin-utils": "^7.26.5", "babel-plugin-polyfill-corejs2": "^0.4.10", - "babel-plugin-polyfill-corejs3": "^0.10.6", + "babel-plugin-polyfill-corejs3": "^0.11.0", "babel-plugin-polyfill-regenerator": "^0.6.1", "semver": "^6.3.1" }, @@ -1870,13 +1799,13 @@ } }, "node_modules/@babel/plugin-transform-template-literals": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.25.9.tgz", - "integrity": "sha512-o97AE4syN71M/lxrCtQByzphAdlYluKPDBzDVzMmfCobUjjhAryZV0AIpRPrxN0eAkxXO6ZLEScmt+PNhj2OTw==", + "version": "7.26.8", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-template-literals/-/plugin-transform-template-literals-7.26.8.tgz", + "integrity": "sha512-OmGDL5/J0CJPJZTHZbi2XpO0tyT2Ia7fzpW5GURwdtp2X3fMmN8au/ej6peC/T33/+CRiIpA8Krse8hFGVmT5Q==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9" + "@babel/helper-plugin-utils": "^7.26.5" }, "engines": { "node": ">=6.9.0" @@ -1886,13 +1815,13 @@ } }, "node_modules/@babel/plugin-transform-typeof-symbol": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.25.9.tgz", - "integrity": "sha512-v61XqUMiueJROUv66BVIOi0Fv/CUuZuZMl5NkRoCVxLAnMexZ0A3kMe7vvZ0nulxMuMp0Mk6S5hNh48yki08ZA==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typeof-symbol/-/plugin-transform-typeof-symbol-7.27.0.tgz", + "integrity": "sha512-+LLkxA9rKJpNoGsbLnAgOCdESl73vwYn+V6b+5wHbrE7OGKVDPHIQvbFSzqE6rwqaCw2RE+zdJrlLkcf8YOA0w==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9" + "@babel/helper-plugin-utils": "^7.26.5" }, "engines": { "node": ">=6.9.0" @@ -1902,15 +1831,15 @@ } }, "node_modules/@babel/plugin-transform-typescript": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.25.9.tgz", - "integrity": "sha512-7PbZQZP50tzv2KGGnhh82GSyMB01yKY9scIjf1a+GfZCtInOWqUH5+1EBU4t9fyR5Oykkkc9vFTs4OHrhHXljQ==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/plugin-transform-typescript/-/plugin-transform-typescript-7.27.0.tgz", + "integrity": "sha512-fRGGjO2UEGPjvEcyAZXRXAS8AfdaQoq7HnxAbJoAoW10B9xOKesmmndJv+Sym2a+9FHWZ9KbyyLCe9s0Sn5jtg==", "license": "MIT", "peer": true, "dependencies": { "@babel/helper-annotate-as-pure": "^7.25.9", - "@babel/helper-create-class-features-plugin": "^7.25.9", - "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-create-class-features-plugin": "^7.27.0", + "@babel/helper-plugin-utils": "^7.26.5", "@babel/helper-skip-transparent-expression-wrappers": "^7.25.9", "@babel/plugin-syntax-typescript": "^7.25.9" }, @@ -1989,15 +1918,15 @@ } }, "node_modules/@babel/preset-env": { - "version": "7.26.0", - "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.26.0.tgz", - "integrity": "sha512-H84Fxq0CQJNdPFT2DrfnylZ3cf5K43rGfWK4LJGPpjKHiZlk0/RzwEus3PDDZZg+/Er7lCA03MVacueUuXdzfw==", + "version": "7.26.9", + "resolved": "https://registry.npmjs.org/@babel/preset-env/-/preset-env-7.26.9.tgz", + "integrity": "sha512-vX3qPGE8sEKEAZCWk05k3cpTAE3/nOYca++JA+Rd0z2NCNzabmYvEiSShKzm10zdquOIAVXsy2Ei/DTW34KlKQ==", "license": "MIT", "peer": true, "dependencies": { - "@babel/compat-data": "^7.26.0", - "@babel/helper-compilation-targets": "^7.25.9", - "@babel/helper-plugin-utils": "^7.25.9", + "@babel/compat-data": "^7.26.8", + "@babel/helper-compilation-targets": "^7.26.5", + "@babel/helper-plugin-utils": "^7.26.5", "@babel/helper-validator-option": "^7.25.9", "@babel/plugin-bugfix-firefox-class-in-computed-class-key": "^7.25.9", "@babel/plugin-bugfix-safari-class-field-initializer-scope": "^7.25.9", @@ -2009,9 +1938,9 @@ "@babel/plugin-syntax-import-attributes": "^7.26.0", "@babel/plugin-syntax-unicode-sets-regex": "^7.18.6", "@babel/plugin-transform-arrow-functions": "^7.25.9", - "@babel/plugin-transform-async-generator-functions": "^7.25.9", + "@babel/plugin-transform-async-generator-functions": "^7.26.8", "@babel/plugin-transform-async-to-generator": "^7.25.9", - "@babel/plugin-transform-block-scoped-functions": "^7.25.9", + "@babel/plugin-transform-block-scoped-functions": "^7.26.5", "@babel/plugin-transform-block-scoping": "^7.25.9", "@babel/plugin-transform-class-properties": "^7.25.9", "@babel/plugin-transform-class-static-block": "^7.26.0", @@ -2022,21 +1951,21 @@ "@babel/plugin-transform-duplicate-keys": "^7.25.9", "@babel/plugin-transform-duplicate-named-capturing-groups-regex": "^7.25.9", "@babel/plugin-transform-dynamic-import": "^7.25.9", - "@babel/plugin-transform-exponentiation-operator": "^7.25.9", + "@babel/plugin-transform-exponentiation-operator": "^7.26.3", "@babel/plugin-transform-export-namespace-from": "^7.25.9", - "@babel/plugin-transform-for-of": "^7.25.9", + "@babel/plugin-transform-for-of": "^7.26.9", "@babel/plugin-transform-function-name": "^7.25.9", "@babel/plugin-transform-json-strings": "^7.25.9", "@babel/plugin-transform-literals": "^7.25.9", "@babel/plugin-transform-logical-assignment-operators": "^7.25.9", "@babel/plugin-transform-member-expression-literals": "^7.25.9", "@babel/plugin-transform-modules-amd": "^7.25.9", - "@babel/plugin-transform-modules-commonjs": "^7.25.9", + "@babel/plugin-transform-modules-commonjs": "^7.26.3", "@babel/plugin-transform-modules-systemjs": "^7.25.9", "@babel/plugin-transform-modules-umd": "^7.25.9", "@babel/plugin-transform-named-capturing-groups-regex": "^7.25.9", "@babel/plugin-transform-new-target": "^7.25.9", - "@babel/plugin-transform-nullish-coalescing-operator": "^7.25.9", + "@babel/plugin-transform-nullish-coalescing-operator": "^7.26.6", "@babel/plugin-transform-numeric-separator": "^7.25.9", "@babel/plugin-transform-object-rest-spread": "^7.25.9", "@babel/plugin-transform-object-super": "^7.25.9", @@ -2052,17 +1981,17 @@ "@babel/plugin-transform-shorthand-properties": "^7.25.9", "@babel/plugin-transform-spread": "^7.25.9", "@babel/plugin-transform-sticky-regex": "^7.25.9", - "@babel/plugin-transform-template-literals": "^7.25.9", - "@babel/plugin-transform-typeof-symbol": "^7.25.9", + "@babel/plugin-transform-template-literals": "^7.26.8", + "@babel/plugin-transform-typeof-symbol": "^7.26.7", "@babel/plugin-transform-unicode-escapes": "^7.25.9", "@babel/plugin-transform-unicode-property-regex": "^7.25.9", "@babel/plugin-transform-unicode-regex": "^7.25.9", "@babel/plugin-transform-unicode-sets-regex": "^7.25.9", "@babel/preset-modules": "0.1.6-no-external-plugins", "babel-plugin-polyfill-corejs2": "^0.4.10", - "babel-plugin-polyfill-corejs3": "^0.10.6", + "babel-plugin-polyfill-corejs3": "^0.11.0", "babel-plugin-polyfill-regenerator": "^0.6.1", - "core-js-compat": "^3.38.1", + "core-js-compat": "^3.40.0", "semver": "^6.3.1" }, "engines": { @@ -2116,17 +2045,17 @@ } }, "node_modules/@babel/preset-typescript": { - "version": "7.26.0", - "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.26.0.tgz", - "integrity": "sha512-NMk1IGZ5I/oHhoXEElcm+xUnL/szL6xflkFZmoEU9xj1qSJXpiS7rsspYo92B4DRCDvZn2erT5LdsCeXAKNCkg==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/preset-typescript/-/preset-typescript-7.27.0.tgz", + "integrity": "sha512-vxaPFfJtHhgeOVXRKuHpHPAOgymmy8V8I65T1q53R7GCZlefKeCaTyDs3zOPHTTbmquvNlQYC5klEvWsBAtrBQ==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-plugin-utils": "^7.25.9", + "@babel/helper-plugin-utils": "^7.26.5", "@babel/helper-validator-option": "^7.25.9", "@babel/plugin-syntax-jsx": "^7.25.9", - "@babel/plugin-transform-modules-commonjs": "^7.25.9", - "@babel/plugin-transform-typescript": "^7.25.9" + "@babel/plugin-transform-modules-commonjs": "^7.26.3", + "@babel/plugin-transform-typescript": "^7.27.0" }, "engines": { "node": ">=6.9.0" @@ -2156,9 +2085,9 @@ } }, "node_modules/@babel/runtime": { - "version": "7.26.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.26.0.tgz", - "integrity": "sha512-FDSOghenHTiToteC/QRlv2q3DhPZ/oOXTBoirfWNx1Cx3TMVcGWQtMMmQcSvb/JjpNeGzx8Pq/b4fKEJuWm1sw==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.27.0.tgz", + "integrity": "sha512-VtPOkrdPHZsKc/clNqyi9WUA8TINkZ4cGk63UUE3u4pmB2k+ZMQRDuIOagv8UVd6j7k0T3+RRIb7beKTebNbcw==", "license": "MIT", "peer": true, "dependencies": { @@ -2176,32 +2105,32 @@ "peer": true }, "node_modules/@babel/template": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.25.9.tgz", - "integrity": "sha512-9DGttpmPvIxBb/2uwpVo3dqJ+O6RooAFOS+lB+xDqoE2PVCE8nfoHMdZLpfCQRLwvohzXISPZcgxt80xLfsuwg==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.27.0.tgz", + "integrity": "sha512-2ncevenBqXI6qRMukPlXwHKHchC7RyMuu4xv5JBXRfOGVcTy1mXCD12qrp7Jsoxll1EV3+9sE4GugBVRjT2jFA==", "license": "MIT", "peer": true, "dependencies": { - "@babel/code-frame": "^7.25.9", - "@babel/parser": "^7.25.9", - "@babel/types": "^7.25.9" + "@babel/code-frame": "^7.26.2", + "@babel/parser": "^7.27.0", + "@babel/types": "^7.27.0" }, "engines": { "node": ">=6.9.0" } }, "node_modules/@babel/traverse": { - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.9.tgz", - "integrity": "sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.27.0.tgz", + "integrity": "sha512-19lYZFzYVQkkHkl4Cy4WrAVcqBkgvV2YM2TU3xG6DIwO7O3ecbDPfW3yM3bjAGcqcQHi+CCtjMR3dIEHxsd6bA==", "license": "MIT", "peer": true, "dependencies": { - "@babel/code-frame": "^7.25.9", - "@babel/generator": "^7.25.9", - "@babel/parser": "^7.25.9", - "@babel/template": "^7.25.9", - "@babel/types": "^7.25.9", + "@babel/code-frame": "^7.26.2", + "@babel/generator": "^7.27.0", + "@babel/parser": "^7.27.0", + "@babel/template": "^7.27.0", + "@babel/types": "^7.27.0", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -2211,17 +2140,17 @@ }, "node_modules/@babel/traverse--for-generate-function-map": { "name": "@babel/traverse", - "version": "7.25.9", - "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.25.9.tgz", - "integrity": "sha512-ZCuvfwOwlz/bawvAuvcj8rrithP2/N55Tzz342AkTvq4qaWbGfmCk/tKhNaV2cthijKrPAA8SRJV5WWe7IBMJw==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.27.0.tgz", + "integrity": "sha512-19lYZFzYVQkkHkl4Cy4WrAVcqBkgvV2YM2TU3xG6DIwO7O3ecbDPfW3yM3bjAGcqcQHi+CCtjMR3dIEHxsd6bA==", "license": "MIT", "peer": true, "dependencies": { - "@babel/code-frame": "^7.25.9", - "@babel/generator": "^7.25.9", - "@babel/parser": "^7.25.9", - "@babel/template": "^7.25.9", - "@babel/types": "^7.25.9", + "@babel/code-frame": "^7.26.2", + "@babel/generator": "^7.27.0", + "@babel/parser": "^7.27.0", + "@babel/template": "^7.27.0", + "@babel/types": "^7.27.0", "debug": "^4.3.1", "globals": "^11.1.0" }, @@ -2250,9 +2179,9 @@ } }, "node_modules/@babel/types": { - "version": "7.26.0", - "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.0.tgz", - "integrity": "sha512-Z/yiTPj+lDVnF7lWeKCIJzaIkI0vYO87dMpZ4bg4TDrFe4XXLFWL1TbXU27gBP3QccxV9mZICCrnjnYlJjXHOA==", + "version": "7.27.0", + "resolved": "https://registry.npmjs.org/@babel/types/-/types-7.27.0.tgz", + "integrity": "sha512-H45s8fVLYjbhFH62dIJ3WtmJ6RSPt/3DRO0ZcT2SUiYiQyz3BLVb9ADEnLl91m74aQPS3AzzeajZHYOalWe3bg==", "license": "MIT", "peer": true, "dependencies": { @@ -2297,6 +2226,121 @@ "@jridgewell/sourcemap-codec": "^1.4.10" } }, + "node_modules/@csstools/color-helpers": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@csstools/color-helpers/-/color-helpers-5.0.2.tgz", + "integrity": "sha512-JqWH1vsgdGcw2RR6VliXXdA0/59LttzlU8UlRT/iUUsEeWfYq8I+K0yhihEUTTHLRm1EXvpsCx3083EU15ecsA==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT-0", + "engines": { + "node": ">=18" + } + }, + "node_modules/@csstools/css-calc": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@csstools/css-calc/-/css-calc-2.1.2.tgz", + "integrity": "sha512-TklMyb3uBB28b5uQdxjReG4L80NxAqgrECqLZFQbyLekwwlcDDS8r3f07DKqeo8C4926Br0gf/ZDe17Zv4wIuw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^3.0.4", + "@csstools/css-tokenizer": "^3.0.3" + } + }, + "node_modules/@csstools/css-color-parser": { + "version": "3.0.8", + "resolved": "https://registry.npmjs.org/@csstools/css-color-parser/-/css-color-parser-3.0.8.tgz", + "integrity": "sha512-pdwotQjCCnRPuNi06jFuP68cykU1f3ZWExLe/8MQ1LOs8Xq+fTkYgd+2V8mWUWMrOn9iS2HftPVaMZDaXzGbhQ==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "dependencies": { + "@csstools/color-helpers": "^5.0.2", + "@csstools/css-calc": "^2.1.2" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-parser-algorithms": "^3.0.4", + "@csstools/css-tokenizer": "^3.0.3" + } + }, + "node_modules/@csstools/css-parser-algorithms": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@csstools/css-parser-algorithms/-/css-parser-algorithms-3.0.4.tgz", + "integrity": "sha512-Up7rBoV77rv29d3uKHUIVubz1BTcgyUK72IvCQAbfbMv584xHcGKCKbWh7i8hPrRJ7qU4Y8IO3IY9m+iTB7P3A==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@csstools/css-tokenizer": "^3.0.3" + } + }, + "node_modules/@csstools/css-tokenizer": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@csstools/css-tokenizer/-/css-tokenizer-3.0.3.tgz", + "integrity": "sha512-UJnjoFsmxfKUdNYdWgOB0mWUypuLvAfQPH1+pyvRJs6euowbFkFC6P13w1l8mJyi3vxYMxc9kld5jZEGRQs6bw==", + "dev": true, + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/csstools" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/csstools" + } + ], + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/@cucumber/ci-environment": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/@cucumber/ci-environment/-/ci-environment-10.0.1.tgz", @@ -2388,153 +2432,30 @@ "node": ">=14" } }, - "node_modules/@cucumber/cucumber/node_modules/glob": { - "version": "10.4.5", - "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", - "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", + "node_modules/@cucumber/gherkin": { + "version": "28.0.0", + "resolved": "https://registry.npmjs.org/@cucumber/gherkin/-/gherkin-28.0.0.tgz", + "integrity": "sha512-Ee6zJQq0OmIUPdW0mSnsCsrWA2PZAELNDPICD2pLfs0Oz7RAPgj80UsD2UCtqyAhw2qAR62aqlktKUlai5zl/A==", "dev": true, - "license": "ISC", + "license": "MIT", "peer": true, "dependencies": { - "foreground-child": "^3.1.0", - "jackspeak": "^3.1.2", - "minimatch": "^9.0.4", - "minipass": "^7.1.2", - "package-json-from-dist": "^1.0.0", - "path-scurry": "^1.11.1" - }, - "bin": { - "glob": "dist/esm/bin.mjs" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" + "@cucumber/messages": ">=19.1.4 <=24" } }, - "node_modules/@cucumber/cucumber/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "node_modules/@cucumber/gherkin-streams": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/@cucumber/gherkin-streams/-/gherkin-streams-5.0.1.tgz", + "integrity": "sha512-/7VkIE/ASxIP/jd4Crlp4JHXqdNFxPGQokqWqsaCCiqBiu5qHoKMxcWNlp9njVL/n9yN4S08OmY3ZR8uC5x74Q==", "dev": true, - "license": "ISC", + "license": "MIT", "peer": true, "dependencies": { - "yallist": "^4.0.0" + "commander": "9.1.0", + "source-map-support": "0.5.21" }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@cucumber/cucumber/node_modules/mime": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", - "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", - "dev": true, - "license": "MIT", - "peer": true, "bin": { - "mime": "cli.js" - }, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/@cucumber/cucumber/node_modules/mkdirp": { - "version": "2.1.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.6.tgz", - "integrity": "sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==", - "dev": true, - "license": "MIT", - "peer": true, - "bin": { - "mkdirp": "dist/cjs/src/bin.js" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/@cucumber/cucumber/node_modules/semver": { - "version": "7.5.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", - "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", - "dev": true, - "license": "ISC", - "peer": true, - "dependencies": { - "lru-cache": "^6.0.0" - }, - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/@cucumber/cucumber/node_modules/supports-color": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", - "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", - "dev": true, - "license": "MIT", - "peer": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/supports-color?sponsor=1" - } - }, - "node_modules/@cucumber/cucumber/node_modules/type-fest": { - "version": "4.26.1", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.26.1.tgz", - "integrity": "sha512-yOGpmOAL7CkKe/91I5O3gPICmJNLJ1G4zFYVAsRHg7M64biSnPtRj0WNQt++bRkjYOqjWXrhnUw1utzmVErAdg==", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "peer": true, - "engines": { - "node": ">=16" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, - "node_modules/@cucumber/cucumber/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true, - "license": "ISC", - "peer": true - }, - "node_modules/@cucumber/gherkin": { - "version": "28.0.0", - "resolved": "https://registry.npmjs.org/@cucumber/gherkin/-/gherkin-28.0.0.tgz", - "integrity": "sha512-Ee6zJQq0OmIUPdW0mSnsCsrWA2PZAELNDPICD2pLfs0Oz7RAPgj80UsD2UCtqyAhw2qAR62aqlktKUlai5zl/A==", - "dev": true, - "license": "MIT", - "peer": true, - "dependencies": { - "@cucumber/messages": ">=19.1.4 <=24" - } - }, - "node_modules/@cucumber/gherkin-streams": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@cucumber/gherkin-streams/-/gherkin-streams-5.0.1.tgz", - "integrity": "sha512-/7VkIE/ASxIP/jd4Crlp4JHXqdNFxPGQokqWqsaCCiqBiu5qHoKMxcWNlp9njVL/n9yN4S08OmY3ZR8uC5x74Q==", - "dev": true, - "license": "MIT", - "peer": true, - "dependencies": { - "commander": "9.1.0", - "source-map-support": "0.5.21" - }, - "bin": { - "gherkin-javascript": "bin/gherkin" + "gherkin-javascript": "bin/gherkin" }, "peerDependencies": { "@cucumber/gherkin": ">=22.0.0", @@ -2627,9 +2548,9 @@ "peer": true }, "node_modules/@esbuild/aix-ppc64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", - "integrity": "sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.1.tgz", + "integrity": "sha512-kfYGy8IdzTGy+z0vFGvExZtxkFlA4zAxgKEahG9KE1ScBjpQnFsNOX8KTU5ojNru5ed5CVoJYXFtoxaq5nFbjQ==", "cpu": [ "ppc64" ], @@ -2644,9 +2565,9 @@ } }, "node_modules/@esbuild/android-arm": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.23.1.tgz", - "integrity": "sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.25.1.tgz", + "integrity": "sha512-dp+MshLYux6j/JjdqVLnMglQlFu+MuVeNrmT5nk6q07wNhCdSnB7QZj+7G8VMUGh1q+vj2Bq8kRsuyA00I/k+Q==", "cpu": [ "arm" ], @@ -2661,9 +2582,9 @@ } }, "node_modules/@esbuild/android-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.23.1.tgz", - "integrity": "sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.25.1.tgz", + "integrity": "sha512-50tM0zCJW5kGqgG7fQ7IHvQOcAn9TKiVRuQ/lN0xR+T2lzEFvAi1ZcS8DiksFcEpf1t/GYOeOfCAgDHFpkiSmA==", "cpu": [ "arm64" ], @@ -2678,9 +2599,9 @@ } }, "node_modules/@esbuild/android-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.23.1.tgz", - "integrity": "sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.25.1.tgz", + "integrity": "sha512-GCj6WfUtNldqUzYkN/ITtlhwQqGWu9S45vUXs7EIYf+7rCiiqH9bCloatO9VhxsL0Pji+PF4Lz2XXCES+Q8hDw==", "cpu": [ "x64" ], @@ -2695,9 +2616,9 @@ } }, "node_modules/@esbuild/darwin-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.1.tgz", - "integrity": "sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.25.1.tgz", + "integrity": "sha512-5hEZKPf+nQjYoSr/elb62U19/l1mZDdqidGfmFutVUjjUZrOazAtwK+Kr+3y0C/oeJfLlxo9fXb1w7L+P7E4FQ==", "cpu": [ "arm64" ], @@ -2712,9 +2633,9 @@ } }, "node_modules/@esbuild/darwin-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.23.1.tgz", - "integrity": "sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.25.1.tgz", + "integrity": "sha512-hxVnwL2Dqs3fM1IWq8Iezh0cX7ZGdVhbTfnOy5uURtao5OIVCEyj9xIzemDi7sRvKsuSdtCAhMKarxqtlyVyfA==", "cpu": [ "x64" ], @@ -2729,9 +2650,9 @@ } }, "node_modules/@esbuild/freebsd-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.23.1.tgz", - "integrity": "sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.25.1.tgz", + "integrity": "sha512-1MrCZs0fZa2g8E+FUo2ipw6jw5qqQiH+tERoS5fAfKnRx6NXH31tXBKI3VpmLijLH6yriMZsxJtaXUyFt/8Y4A==", "cpu": [ "arm64" ], @@ -2746,9 +2667,9 @@ } }, "node_modules/@esbuild/freebsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.23.1.tgz", - "integrity": "sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.25.1.tgz", + "integrity": "sha512-0IZWLiTyz7nm0xuIs0q1Y3QWJC52R8aSXxe40VUxm6BB1RNmkODtW6LHvWRrGiICulcX7ZvyH6h5fqdLu4gkww==", "cpu": [ "x64" ], @@ -2763,9 +2684,9 @@ } }, "node_modules/@esbuild/linux-arm": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.23.1.tgz", - "integrity": "sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.25.1.tgz", + "integrity": "sha512-NdKOhS4u7JhDKw9G3cY6sWqFcnLITn6SqivVArbzIaf3cemShqfLGHYMx8Xlm/lBit3/5d7kXvriTUGa5YViuQ==", "cpu": [ "arm" ], @@ -2780,9 +2701,9 @@ } }, "node_modules/@esbuild/linux-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.1.tgz", - "integrity": "sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.25.1.tgz", + "integrity": "sha512-jaN3dHi0/DDPelk0nLcXRm1q7DNJpjXy7yWaWvbfkPvI+7XNSc/lDOnCLN7gzsyzgu6qSAmgSvP9oXAhP973uQ==", "cpu": [ "arm64" ], @@ -2797,9 +2718,9 @@ } }, "node_modules/@esbuild/linux-ia32": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.23.1.tgz", - "integrity": "sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.25.1.tgz", + "integrity": "sha512-OJykPaF4v8JidKNGz8c/q1lBO44sQNUQtq1KktJXdBLn1hPod5rE/Hko5ugKKZd+D2+o1a9MFGUEIUwO2YfgkQ==", "cpu": [ "ia32" ], @@ -2814,9 +2735,9 @@ } }, "node_modules/@esbuild/linux-loong64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.23.1.tgz", - "integrity": "sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.25.1.tgz", + "integrity": "sha512-nGfornQj4dzcq5Vp835oM/o21UMlXzn79KobKlcs3Wz9smwiifknLy4xDCLUU0BWp7b/houtdrgUz7nOGnfIYg==", "cpu": [ "loong64" ], @@ -2831,9 +2752,9 @@ } }, "node_modules/@esbuild/linux-mips64el": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.23.1.tgz", - "integrity": "sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.25.1.tgz", + "integrity": "sha512-1osBbPEFYwIE5IVB/0g2X6i1qInZa1aIoj1TdL4AaAb55xIIgbg8Doq6a5BzYWgr+tEcDzYH67XVnTmUzL+nXg==", "cpu": [ "mips64el" ], @@ -2848,9 +2769,9 @@ } }, "node_modules/@esbuild/linux-ppc64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.23.1.tgz", - "integrity": "sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.25.1.tgz", + "integrity": "sha512-/6VBJOwUf3TdTvJZ82qF3tbLuWsscd7/1w+D9LH0W/SqUgM5/JJD0lrJ1fVIfZsqB6RFmLCe0Xz3fmZc3WtyVg==", "cpu": [ "ppc64" ], @@ -2865,9 +2786,9 @@ } }, "node_modules/@esbuild/linux-riscv64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.23.1.tgz", - "integrity": "sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.25.1.tgz", + "integrity": "sha512-nSut/Mx5gnilhcq2yIMLMe3Wl4FK5wx/o0QuuCLMtmJn+WeWYoEGDN1ipcN72g1WHsnIbxGXd4i/MF0gTcuAjQ==", "cpu": [ "riscv64" ], @@ -2882,9 +2803,9 @@ } }, "node_modules/@esbuild/linux-s390x": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.23.1.tgz", - "integrity": "sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.25.1.tgz", + "integrity": "sha512-cEECeLlJNfT8kZHqLarDBQso9a27o2Zd2AQ8USAEoGtejOrCYHNtKP8XQhMDJMtthdF4GBmjR2au3x1udADQQQ==", "cpu": [ "s390x" ], @@ -2899,9 +2820,9 @@ } }, "node_modules/@esbuild/linux-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.1.tgz", - "integrity": "sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.25.1.tgz", + "integrity": "sha512-xbfUhu/gnvSEg+EGovRc+kjBAkrvtk38RlerAzQxvMzlB4fXpCFCeUAYzJvrnhFtdeyVCDANSjJvOvGYoeKzFA==", "cpu": [ "x64" ], @@ -2915,10 +2836,27 @@ "node": ">=18" } }, + "node_modules/@esbuild/netbsd-arm64": { + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-arm64/-/netbsd-arm64-0.25.1.tgz", + "integrity": "sha512-O96poM2XGhLtpTh+s4+nP7YCCAfb4tJNRVZHfIE7dgmax+yMP2WgMd2OecBuaATHKTHsLWHQeuaxMRnCsH8+5g==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "netbsd" + ], + "engines": { + "node": ">=18" + } + }, "node_modules/@esbuild/netbsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.23.1.tgz", - "integrity": "sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.25.1.tgz", + "integrity": "sha512-X53z6uXip6KFXBQ+Krbx25XHV/NCbzryM6ehOAeAil7X7oa4XIq+394PWGnwaSQ2WRA0KI6PUO6hTO5zeF5ijA==", "cpu": [ "x64" ], @@ -2933,9 +2871,9 @@ } }, "node_modules/@esbuild/openbsd-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.23.1.tgz", - "integrity": "sha512-3x37szhLexNA4bXhLrCC/LImN/YtWis6WXr1VESlfVtVeoFJBRINPJ3f0a/6LV8zpikqoUg4hyXw0sFBt5Cr+Q==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.25.1.tgz", + "integrity": "sha512-Na9T3szbXezdzM/Kfs3GcRQNjHzM6GzFBeU1/6IV/npKP5ORtp9zbQjvkDJ47s6BCgaAZnnnu/cY1x342+MvZg==", "cpu": [ "arm64" ], @@ -2950,9 +2888,9 @@ } }, "node_modules/@esbuild/openbsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.23.1.tgz", - "integrity": "sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.25.1.tgz", + "integrity": "sha512-T3H78X2h1tszfRSf+txbt5aOp/e7TAz3ptVKu9Oyir3IAOFPGV6O9c2naym5TOriy1l0nNf6a4X5UXRZSGX/dw==", "cpu": [ "x64" ], @@ -2967,9 +2905,9 @@ } }, "node_modules/@esbuild/sunos-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.23.1.tgz", - "integrity": "sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.25.1.tgz", + "integrity": "sha512-2H3RUvcmULO7dIE5EWJH8eubZAI4xw54H1ilJnRNZdeo8dTADEZ21w6J22XBkXqGJbe0+wnNJtw3UXRoLJnFEg==", "cpu": [ "x64" ], @@ -2984,9 +2922,9 @@ } }, "node_modules/@esbuild/win32-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.23.1.tgz", - "integrity": "sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.25.1.tgz", + "integrity": "sha512-GE7XvrdOzrb+yVKB9KsRMq+7a2U/K5Cf/8grVFRAGJmfADr/e/ODQ134RK2/eeHqYV5eQRFxb1hY7Nr15fv1NQ==", "cpu": [ "arm64" ], @@ -3001,9 +2939,9 @@ } }, "node_modules/@esbuild/win32-ia32": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.23.1.tgz", - "integrity": "sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.25.1.tgz", + "integrity": "sha512-uOxSJCIcavSiT6UnBhBzE8wy3n0hOkJsBOzy7HDAuTDE++1DJMRRVCPGisULScHL+a/ZwdXPpXD3IyFKjA7K8A==", "cpu": [ "ia32" ], @@ -3018,9 +2956,9 @@ } }, "node_modules/@esbuild/win32-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.23.1.tgz", - "integrity": "sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.25.1.tgz", + "integrity": "sha512-Y1EQdcfwMSeQN/ujR5VayLOJ1BHaK+ssyk0AEzPjC+t1lITgsnccPqFjb6V+LsTp/9Iov4ysfjxLaGJ9RPtkVg==", "cpu": [ "x64" ], @@ -3035,9 +2973,9 @@ } }, "node_modules/@eslint-community/eslint-utils": { - "version": "4.4.1", - "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.4.1.tgz", - "integrity": "sha512-s3O3waFUrMV8P/XaF/+ZTp1X9XBZW1a4B97ZnjQF2KYWaFD2A8KyFBsrsfSjEmjn3RGWAIuvlneuZm3CUK3jbA==", + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/@eslint-community/eslint-utils/-/eslint-utils-4.5.1.tgz", + "integrity": "sha512-soEIOALTfTK6EjmKMMoLugwaP0rzkad90iIWd1hMO9ARkSAyjfMfkRRhLvD5qH7vvM0Cg72pieUfR6yh6XxC4w==", "dev": true, "license": "MIT", "dependencies": { @@ -3236,20 +3174,6 @@ "url": "https://github.com/chalk/ansi-regex?sponsor=1" } }, - "node_modules/@isaacs/cliui/node_modules/ansi-styles": { - "version": "6.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", - "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", - "dev": true, - "license": "MIT", - "peer": true, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, "node_modules/@isaacs/cliui/node_modules/emoji-regex": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", @@ -3294,25 +3218,6 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, - "node_modules/@isaacs/cliui/node_modules/wrap-ansi": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", - "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", - "dev": true, - "license": "MIT", - "peer": true, - "dependencies": { - "ansi-styles": "^6.1.0", - "string-width": "^5.0.1", - "strip-ansi": "^7.0.1" - }, - "engines": { - "node": ">=12" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, "node_modules/@isaacs/ttlcache": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/@isaacs/ttlcache/-/ttlcache-1.4.1.tgz", @@ -3533,9 +3438,9 @@ } }, "node_modules/@jridgewell/gen-mapping": { - "version": "0.3.5", - "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", - "integrity": "sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==", + "version": "0.3.8", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.8.tgz", + "integrity": "sha512-imAbBGkb+ebQyxKgzv5Hu2nmROxoDOXHh80evxdoXNOrvAnVx7zimzc1Oo5h9RlfV4vPXaE2iM5pOFbvOCClWA==", "license": "MIT", "dependencies": { "@jridgewell/set-array": "^1.2.1", @@ -3591,9 +3496,9 @@ } }, "node_modules/@mswjs/interceptors": { - "version": "0.36.7", - "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.36.7.tgz", - "integrity": "sha512-sdx02Wlus5hv6Bx7uUDb25gb0WGjCuSgnJB2LVERemoSGuqkZMe3QI6nEXhieFGtYwPrZbYrT2vPbsFN2XfbUw==", + "version": "0.38.0", + "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.38.0.tgz", + "integrity": "sha512-nPHVM+LUl4V1kXPXuTcNN5OMD//ltCQ0lccuEagvidJdpbig3hP3W6/ctWHx6mee7vZIWE0L+Mqj3vx0ASlm/w==", "dev": true, "license": "MIT", "dependencies": { @@ -3601,6 +3506,7 @@ "@open-draft/logger": "^0.3.0", "@open-draft/until": "^2.0.0", "is-node-process": "^1.2.0", + "jsdom": "^26.0.0", "outvariant": "^1.4.3", "strict-event-emitter": "^0.5.1" }, @@ -3684,9 +3590,9 @@ } }, "node_modules/@pkgr/core": { - "version": "0.1.1", - "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", - "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.2.0.tgz", + "integrity": "sha512-vsJDAkYR6qCPu+ioGScGiMYR7LvZYIXh/dlQeviqoTWNCVfKTLYD/LkNWH4Mxsv2a5vpIRc77FN5DnmK1eBggQ==", "dev": true, "license": "MIT", "engines": { @@ -3697,9 +3603,9 @@ } }, "node_modules/@react-native/assets-registry": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/assets-registry/-/assets-registry-0.76.1.tgz", - "integrity": "sha512-1mcDjyvC4Z+XYtY+Abl6pW9P49l/9HJmRChX7EHF1SoXe7zPAPBoAqeZsJNtf8dhJR3u/eGvapr1yJq8T/psEg==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/assets-registry/-/assets-registry-0.78.1.tgz", + "integrity": "sha512-SegfYQFuut05EQIQIVB/6QMGaxJ29jEtPmzFWJdIp/yc2mmhIq7MfWRjwOe6qbONzIdp6Ca8p835hiGiAGyeKQ==", "license": "MIT", "peer": true, "engines": { @@ -3707,22 +3613,23 @@ } }, "node_modules/@react-native/babel-plugin-codegen": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/babel-plugin-codegen/-/babel-plugin-codegen-0.76.1.tgz", - "integrity": "sha512-V9bGLyEdAF39nvn4L5gaJcPX1SvCHPJhaT3qfpVGvCnl7WPhdRyCq++WsN8HXlpo6WOAf6//oruLnLdl3RNM4Q==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/babel-plugin-codegen/-/babel-plugin-codegen-0.78.1.tgz", + "integrity": "sha512-rD0tnct/yPEtoOc8eeFHIf8ZJJJEzLkmqLs8HZWSkt3w9VYWngqLXZxiDGqv0ngXjunAlC/Hpq+ULMVOvOnByw==", "license": "MIT", "peer": true, "dependencies": { - "@react-native/codegen": "0.76.1" + "@babel/traverse": "^7.25.3", + "@react-native/codegen": "0.78.1" }, "engines": { "node": ">=18" } }, "node_modules/@react-native/babel-preset": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/babel-preset/-/babel-preset-0.76.1.tgz", - "integrity": "sha512-b6YRmA13CmVuTQKHRen/Q0glHwmZFZoEDs+MJ1NL0UNHq9V5ytvdwTW1ntkmjtXuTnPMzkwYvumJBN9UTZjkBA==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/babel-preset/-/babel-preset-0.78.1.tgz", + "integrity": "sha512-yTVcHmEdNQH4Ju7lhvbiQaGxBpMcalgkBy/IvHowXKk/ex3nY1PolF16/mBG1BrefcUA/rtJpqTtk2Ii+7T/Lw==", "license": "MIT", "peer": true, "dependencies": { @@ -3767,8 +3674,8 @@ "@babel/plugin-transform-typescript": "^7.25.2", "@babel/plugin-transform-unicode-regex": "^7.24.7", "@babel/template": "^7.25.0", - "@react-native/babel-plugin-codegen": "0.76.1", - "babel-plugin-syntax-hermes-parser": "^0.23.1", + "@react-native/babel-plugin-codegen": "0.78.1", + "babel-plugin-syntax-hermes-parser": "0.25.1", "babel-plugin-transform-flow-enums": "^0.0.2", "react-refresh": "^0.14.0" }, @@ -3780,18 +3687,17 @@ } }, "node_modules/@react-native/codegen": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/codegen/-/codegen-0.76.1.tgz", - "integrity": "sha512-7lE0hk2qq27wVeK5eF654v7XsKoRa7ficrfSwIDEDZ1aLB2xgUzLrsq+glSAP9EuzT6ycHhtD3QyqI+TqnlS/A==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/codegen/-/codegen-0.78.1.tgz", + "integrity": "sha512-kGG5qAM9JdFtxzUwe7c6CyJbsU2PnaTrtCHA2dF8VEiNX1K3yd9yKPzfkxA7HPvmHoAn3ga1941O79BStWcM3A==", "license": "MIT", "peer": true, "dependencies": { "@babel/parser": "^7.25.3", "glob": "^7.1.1", - "hermes-parser": "0.23.1", + "hermes-parser": "0.25.1", "invariant": "^2.2.4", - "jscodeshift": "^0.14.0", - "mkdirp": "^0.5.1", + "jscodeshift": "^17.0.0", "nullthrows": "^1.1.1", "yargs": "^17.6.2" }, @@ -3863,6 +3769,24 @@ "node": "*" } }, + "node_modules/@react-native/codegen/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "license": "MIT", + "peer": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/@react-native/codegen/node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", @@ -3893,39 +3817,56 @@ } }, "node_modules/@react-native/community-cli-plugin": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/community-cli-plugin/-/community-cli-plugin-0.76.1.tgz", - "integrity": "sha512-dECc1LuleMQDX/WK2oJInrYCpHb3OFBJxYkhPOAXb9HiktMWRA9T93qqpTDshmtLdYqvxeO9AM5eeoSL412WnQ==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/community-cli-plugin/-/community-cli-plugin-0.78.1.tgz", + "integrity": "sha512-S6vF4oWpFqThpt/dBLrqLQw5ED2M1kg5mVtiL6ZqpoYIg+/e0vg7LZ8EXNbcdMDH4obRnm2xbOd+qlC7mOzNBg==", "license": "MIT", "peer": true, "dependencies": { - "@react-native/dev-middleware": "0.76.1", - "@react-native/metro-babel-transformer": "0.76.1", + "@react-native/dev-middleware": "0.78.1", + "@react-native/metro-babel-transformer": "0.78.1", "chalk": "^4.0.0", - "execa": "^5.1.1", + "debug": "^2.2.0", "invariant": "^2.2.4", "metro": "^0.81.0", "metro-config": "^0.81.0", "metro-core": "^0.81.0", - "node-fetch": "^2.2.0", - "readline": "^1.3.0" + "readline": "^1.3.0", + "semver": "^7.1.3" }, "engines": { "node": ">=18" }, "peerDependencies": { - "@react-native-community/cli-server-api": "*" + "@react-native-community/cli": "*" }, "peerDependenciesMeta": { - "@react-native-community/cli-server-api": { + "@react-native-community/cli": { "optional": true } } }, + "node_modules/@react-native/community-cli-plugin/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "license": "MIT", + "peer": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/@react-native/community-cli-plugin/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "license": "MIT", + "peer": true + }, "node_modules/@react-native/debugger-frontend": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/debugger-frontend/-/debugger-frontend-0.76.1.tgz", - "integrity": "sha512-0gExx7GR8o2ctGfjIZ9+x54iFbg0eP6+kMYzRA6AcgmFAmMGLADMmjtObCN0CqGeZyWtdVVqcv5mAwRwmMlNWA==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/debugger-frontend/-/debugger-frontend-0.78.1.tgz", + "integrity": "sha512-xev/B++QLxSDpEBWsc74GyCuq9XOHYTBwcGSpsuhOJDUha6WZIbEEvZe3LpVW+OiFso4oGIdnVSQntwippZdWw==", "license": "BSD-3-Clause", "peer": true, "engines": { @@ -3933,22 +3874,23 @@ } }, "node_modules/@react-native/dev-middleware": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/dev-middleware/-/dev-middleware-0.76.1.tgz", - "integrity": "sha512-htaFSN2dwI0CinsMxjRuvIVdSDN6d6TDPeOJczM1bdAYalZX1M58knTKs5LJDComW5tleOCAg5lS5tIeFlM9+Q==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/dev-middleware/-/dev-middleware-0.78.1.tgz", + "integrity": "sha512-l8p7/dXa1vWPOdj0iuACkex8lgbLpYyPZ3QXGkocMcpl0bQ24K7hf3Bj02tfptP5PAm16b2RuEi04sjIGHUzzg==", "license": "MIT", "peer": true, "dependencies": { "@isaacs/ttlcache": "^1.4.1", - "@react-native/debugger-frontend": "0.76.1", + "@react-native/debugger-frontend": "0.78.1", "chrome-launcher": "^0.15.2", "chromium-edge-launcher": "^0.2.0", "connect": "^3.6.5", "debug": "^2.2.0", + "invariant": "^2.2.4", "nullthrows": "^1.1.1", "open": "^7.0.3", "selfsigned": "^2.4.1", - "serve-static": "^1.13.1", + "serve-static": "^1.16.2", "ws": "^6.2.3" }, "engines": { @@ -3972,10 +3914,20 @@ "license": "MIT", "peer": true }, + "node_modules/@react-native/dev-middleware/node_modules/ws": { + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.3.tgz", + "integrity": "sha512-jmTjYU0j60B+vHey6TfR3Z7RD61z/hmxBS3VMSGIrroOWXQEneK1zNuotOUrGyBHQj0yrpsLHPWtigEFd13ndA==", + "license": "MIT", + "peer": true, + "dependencies": { + "async-limiter": "~1.0.0" + } + }, "node_modules/@react-native/gradle-plugin": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/gradle-plugin/-/gradle-plugin-0.76.1.tgz", - "integrity": "sha512-X7rNFltPa9QYxvYrQGaSCw7U57C+y+DwspXf4AnLZj0bQm9tL6UYpijh5vE3VmPcHn76/RNU2bpFjVvWg6gjqw==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/gradle-plugin/-/gradle-plugin-0.78.1.tgz", + "integrity": "sha512-v8GJU+8DzQDWO3iuTFI1nbuQ/kzuqbXv07VVtSIMLbdofHzuuQT14DGBacBkrIDKBDTVaBGAc/baDNsyxCghng==", "license": "MIT", "peer": true, "engines": { @@ -3983,9 +3935,9 @@ } }, "node_modules/@react-native/js-polyfills": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/js-polyfills/-/js-polyfills-0.76.1.tgz", - "integrity": "sha512-HO3fzJ0FnrnQGmxdXxh2lcGGAMfaX9h1Pg1Zh38MkVw35/KnZHxHqxg6cruze6iWwZdfqSoIcQoalmMuAHby7Q==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/js-polyfills/-/js-polyfills-0.78.1.tgz", + "integrity": "sha512-Ogcv4QOA1o3IyErrf/i4cDnP+nfNcIfGTgw6iNQyAPry1xjPOz4ziajskLpWG/3ADeneIZuyZppKB4A28rZSvg==", "license": "MIT", "peer": true, "engines": { @@ -3993,15 +3945,15 @@ } }, "node_modules/@react-native/metro-babel-transformer": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/metro-babel-transformer/-/metro-babel-transformer-0.76.1.tgz", - "integrity": "sha512-LUAKqgsrioXS2a+pE0jak8sutTbLo3T34KWv7mdVUZ5lUACpqkIql1EFtIQlWjIcR4oZE480CkPbRHBI681tkQ==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/metro-babel-transformer/-/metro-babel-transformer-0.78.1.tgz", + "integrity": "sha512-jQWf69D+QTMvSZSWLR+cr3VUF16rGB6sbD+bItD8Czdfn3hajzfMoHJTkVFP7991cjK5sIVekNiQIObou8JSQw==", "license": "MIT", "peer": true, "dependencies": { "@babel/core": "^7.25.2", - "@react-native/babel-preset": "0.76.1", - "hermes-parser": "0.23.1", + "@react-native/babel-preset": "0.78.1", + "hermes-parser": "0.25.1", "nullthrows": "^1.1.1" }, "engines": { @@ -4012,16 +3964,16 @@ } }, "node_modules/@react-native/normalize-colors": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/normalize-colors/-/normalize-colors-0.76.1.tgz", - "integrity": "sha512-/+CUk/wGWIdXbJYVLw/q6Fs8Z0x91zzfXIbNiZUdSW1TNEDmytkF371H8a1/Nx3nWa1RqCMVsaZHCG4zqxeDvg==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/normalize-colors/-/normalize-colors-0.78.1.tgz", + "integrity": "sha512-h4wARnY4iBFgigN1NjnaKFtcegWwQyE9+CEBVG4nHmwMtr8lZBmc7ZKIM6hUc6lxqY/ugHg48aSQSynss7mJUg==", "license": "MIT", "peer": true }, "node_modules/@react-native/virtualized-lists": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/@react-native/virtualized-lists/-/virtualized-lists-0.76.1.tgz", - "integrity": "sha512-uWJfv0FC3zmlYORr0Sa17ngbAaw6K9yw4MAkBZyFeTM+W6AJRvTVyR1Mes/MU+vIyGFChnTcyaQrQz8jWqADOA==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/@react-native/virtualized-lists/-/virtualized-lists-0.78.1.tgz", + "integrity": "sha512-v0jqDNMFXpnRnSlkDVvwNxXgPhifzzTFlxTSnHj9erKJsKpE26gSU5qB4hmJkEsscLG/ygdJ1c88aqinSh/wRA==", "license": "MIT", "peer": true, "dependencies": { @@ -4032,7 +3984,7 @@ "node": ">=18" }, "peerDependencies": { - "@types/react": "^18.2.6", + "@types/react": "^19.0.0", "react": "*", "react-native": "*" }, @@ -4068,6 +4020,40 @@ } } }, + "node_modules/@rollup/plugin-commonjs/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "dev": true, + "license": "ISC", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/@rollup/plugin-commonjs/node_modules/minimatch": { + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", + "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "dev": true, + "license": "ISC", + "dependencies": { + "brace-expansion": "^2.0.1" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/@rollup/plugin-json": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.1.0.tgz", @@ -4090,9 +4076,9 @@ } }, "node_modules/@rollup/plugin-node-resolve": { - "version": "15.3.0", - "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.3.0.tgz", - "integrity": "sha512-9eO5McEICxMzJpDW9OnMYSv4Sta3hmt7VtBFz5zR9273suNOydOyq/FrGeGy+KsTRFm8w0SLVhzig2ILFT63Ag==", + "version": "15.3.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.3.1.tgz", + "integrity": "sha512-tgg6b91pAybXHJQMAAwW9VuWBO6Thi+q7BCNARLwSqlmsHz0XYURtGvh/AuwSADXSI4h/2uHbs7s4FzlZDGSGA==", "dev": true, "license": "MIT", "dependencies": { @@ -4187,9 +4173,9 @@ } }, "node_modules/@rollup/pluginutils": { - "version": "5.1.3", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.3.tgz", - "integrity": "sha512-Pnsb6f32CD2W3uCaLZIzDmeFyQ2b8UWMFI7xtwUezpcGBDVDW6y9XgAWIlARiGAo6eNF5FK5aQTr0LFyNyqq5A==", + "version": "5.1.4", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.4.tgz", + "integrity": "sha512-USm05zrsFxYLPdWWq+K3STlWiT/3ELn3RcV5hJMghpeAIhxfsUIg6mt12CBJBInWMV4VneoV7SfGv8xIwo2qNQ==", "dev": true, "license": "MIT", "dependencies": { @@ -4627,9 +4613,9 @@ } }, "node_modules/@types/babel__traverse": { - "version": "7.20.6", - "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.6.tgz", - "integrity": "sha512-r1bzfrm0tomOI8g1SzvCaQHo6Lcv6zu0EA+W2kHrt8dyrHQxGzBBL4kdkzIS+jBMV+EYcMAEAqXqYaLJq5rOZg==", + "version": "7.20.7", + "resolved": "https://registry.npmjs.org/@types/babel__traverse/-/babel__traverse-7.20.7.tgz", + "integrity": "sha512-dkO5fhS7+/oos4ciWxyEyjWe48zmG6wbCheo/G2ZnHx4fs3EU6YC6UM8rk56gAjNJ9P3MTH2jo5jb92/K6wbng==", "license": "MIT", "peer": true, "dependencies": { @@ -4660,13 +4646,6 @@ "@types/chai": "*" } }, - "node_modules/@types/cookie": { - "version": "0.4.1", - "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.4.1.tgz", - "integrity": "sha512-XW/Aa8APYr6jSVVA1y/DEIZX0/GMKLEVekNG727R8cs56ahETkRAy/3DR7+fJyh7oUgGwNQaRfXCun0+KbWY7Q==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/cors": { "version": "2.8.17", "resolved": "https://registry.npmjs.org/@types/cors/-/cors-2.8.17.tgz", @@ -4678,9 +4657,9 @@ } }, "node_modules/@types/estree": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.6.tgz", - "integrity": "sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==", + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.7.tgz", + "integrity": "sha512-w28IoSUCJpidD/TGviZwwMJckNESJZXFu7NBZ5YJ4mEUnNraUn9Pm8HSZm/jDF1pDWYKspWE7oVphigUPRakIQ==", "dev": true, "license": "MIT" }, @@ -4762,18 +4741,18 @@ } }, "node_modules/@types/node": { - "version": "22.8.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.5.tgz", - "integrity": "sha512-5iYk6AMPtsMbkZqCO1UGF9W5L38twq11S2pYWkybGHH2ogPUvXWNlQqJBzuEZWKj/WRH+QTeiv6ySWqJtvIEgA==", + "version": "22.13.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.14.tgz", + "integrity": "sha512-Zs/Ollc1SJ8nKUAgc7ivOEdIBM8JAKgrqqUYi2J997JuKO7/tpQC+WCetQ1sypiKCQWHdvdg9wBNpUPEWZae7w==", "license": "MIT", "dependencies": { - "undici-types": "~6.19.8" + "undici-types": "~6.20.0" } }, "node_modules/@types/node-fetch": { - "version": "2.6.11", - "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", - "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "version": "2.6.12", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.12.tgz", + "integrity": "sha512-8nneRWKCg3rMtF69nLQJnOYUcbafYeFSjqkw3jCRLsqkWFlHaoQrr5mXmofFGOx3DKn7UfmBMyov8ySvLRVldA==", "dev": true, "license": "MIT", "dependencies": { @@ -4807,9 +4786,9 @@ "license": "MIT" }, "node_modules/@types/sinon": { - "version": "17.0.3", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.3.tgz", - "integrity": "sha512-j3uovdn8ewky9kRBG19bOwaZbexJu/XjtkHyjvUgt4xfPFz18dcORIMqnYh66Fx3Powhcr85NT5+er3+oViapw==", + "version": "17.0.4", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.4.tgz", + "integrity": "sha512-RHnIrhfPO3+tJT0s7cFaXGZvsL4bbR3/k7z3P312qMS4JaS2Tk+KiwiLx1S0rQ56ERj00u1/BtdyVd0FY+Pdew==", "dev": true, "license": "MIT", "dependencies": { @@ -4867,21 +4846,21 @@ "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.12.2.tgz", - "integrity": "sha512-gQxbxM8mcxBwaEmWdtLCIGLfixBMHhQjBqR8sVWNTPpcj45WlYL2IObS/DNMLH1DBP0n8qz+aiiLTGfopPEebw==", + "version": "8.28.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.28.0.tgz", + "integrity": "sha512-lvFK3TCGAHsItNdWZ/1FkvpzCxTHUVuFrdnOGLMa0GGCFIbCgQWVk3CzCGdA7kM3qGVc+dfW9tr0Z/sHnGDFyg==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.12.2", - "@typescript-eslint/type-utils": "8.12.2", - "@typescript-eslint/utils": "8.12.2", - "@typescript-eslint/visitor-keys": "8.12.2", + "@typescript-eslint/scope-manager": "8.28.0", + "@typescript-eslint/type-utils": "8.28.0", + "@typescript-eslint/utils": "8.28.0", + "@typescript-eslint/visitor-keys": "8.28.0", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", - "ts-api-utils": "^1.3.0" + "ts-api-utils": "^2.0.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -4892,25 +4871,21 @@ }, "peerDependencies": { "@typescript-eslint/parser": "^8.0.0 || ^8.0.0-alpha.0", - "eslint": "^8.57.0 || ^9.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.9.0" } }, "node_modules/@typescript-eslint/parser": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.12.2.tgz", - "integrity": "sha512-MrvlXNfGPLH3Z+r7Tk+Z5moZAc0dzdVjTgUgwsdGweH7lydysQsnSww3nAmsq8blFuRD5VRlAr9YdEFw3e6PBw==", + "version": "8.28.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.28.0.tgz", + "integrity": "sha512-LPcw1yHD3ToaDEoljFEfQ9j2xShY367h7FZ1sq5NJT9I3yj4LHer1Xd1yRSOdYy9BpsrxU7R+eoDokChYM53lQ==", "dev": true, - "license": "BSD-2-Clause", + "license": "MIT", "dependencies": { - "@typescript-eslint/scope-manager": "8.12.2", - "@typescript-eslint/types": "8.12.2", - "@typescript-eslint/typescript-estree": "8.12.2", - "@typescript-eslint/visitor-keys": "8.12.2", + "@typescript-eslint/scope-manager": "8.28.0", + "@typescript-eslint/types": "8.28.0", + "@typescript-eslint/typescript-estree": "8.28.0", + "@typescript-eslint/visitor-keys": "8.28.0", "debug": "^4.3.4" }, "engines": { @@ -4921,23 +4896,19 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0" - }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.9.0" } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.12.2.tgz", - "integrity": "sha512-gPLpLtrj9aMHOvxJkSbDBmbRuYdtiEbnvO25bCMza3DhMjTQw0u7Y1M+YR5JPbMsXXnSPuCf5hfq0nEkQDL/JQ==", + "version": "8.28.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.28.0.tgz", + "integrity": "sha512-u2oITX3BJwzWCapoZ/pXw6BCOl8rJP4Ij/3wPoGvY8XwvXflOzd1kLrDUUUAIEdJSFh+ASwdTHqtan9xSg8buw==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.12.2", - "@typescript-eslint/visitor-keys": "8.12.2" + "@typescript-eslint/types": "8.28.0", + "@typescript-eslint/visitor-keys": "8.28.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -4948,16 +4919,16 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.12.2.tgz", - "integrity": "sha512-bwuU4TAogPI+1q/IJSKuD4shBLc/d2vGcRT588q+jzayQyjVK2X6v/fbR4InY2U2sgf8MEvVCqEWUzYzgBNcGQ==", + "version": "8.28.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.28.0.tgz", + "integrity": "sha512-oRoXu2v0Rsy/VoOGhtWrOKDiIehvI+YNrDk5Oqj40Mwm0Yt01FC/Q7nFqg088d3yAsR1ZcZFVfPCTTFCe/KPwg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/typescript-estree": "8.12.2", - "@typescript-eslint/utils": "8.12.2", + "@typescript-eslint/typescript-estree": "8.28.0", + "@typescript-eslint/utils": "8.28.0", "debug": "^4.3.4", - "ts-api-utils": "^1.3.0" + "ts-api-utils": "^2.0.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -4966,16 +4937,15 @@ "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } + "peerDependencies": { + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.9.0" } }, "node_modules/@typescript-eslint/types": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.12.2.tgz", - "integrity": "sha512-VwDwMF1SZ7wPBUZwmMdnDJ6sIFk4K4s+ALKLP6aIQsISkPv8jhiw65sAK6SuWODN/ix+m+HgbYDkH+zLjrzvOA==", + "version": "8.28.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.28.0.tgz", + "integrity": "sha512-bn4WS1bkKEjx7HqiwG2JNB3YJdC1q6Ue7GyGlwPHyt0TnVq6TtD/hiOdTZt71sq0s7UzqBFXD8t8o2e63tXgwA==", "dev": true, "license": "MIT", "engines": { @@ -4987,20 +4957,20 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.12.2.tgz", - "integrity": "sha512-mME5MDwGe30Pq9zKPvyduyU86PH7aixwqYR2grTglAdB+AN8xXQ1vFGpYaUSJ5o5P/5znsSBeNcs5g5/2aQwow==", + "version": "8.28.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.28.0.tgz", + "integrity": "sha512-H74nHEeBGeklctAVUvmDkxB1mk+PAZ9FiOMPFncdqeRBXxk1lWSYraHw8V12b7aa6Sg9HOBNbGdSHobBPuQSuA==", "dev": true, - "license": "BSD-2-Clause", + "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.12.2", - "@typescript-eslint/visitor-keys": "8.12.2", + "@typescript-eslint/types": "8.28.0", + "@typescript-eslint/visitor-keys": "8.28.0", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", "minimatch": "^9.0.4", "semver": "^7.6.0", - "ts-api-utils": "^1.3.0" + "ts-api-utils": "^2.0.1" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5009,23 +4979,34 @@ "type": "opencollective", "url": "https://opencollective.com/typescript-eslint" }, - "peerDependenciesMeta": { - "typescript": { - "optional": true - } + "peerDependencies": { + "typescript": ">=4.8.4 <5.9.0" + } + }, + "node_modules/@typescript-eslint/typescript-estree/node_modules/semver": { + "version": "7.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", + "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", + "dev": true, + "license": "ISC", + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" } }, "node_modules/@typescript-eslint/utils": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.12.2.tgz", - "integrity": "sha512-UTTuDIX3fkfAz6iSVa5rTuSfWIYZ6ATtEocQ/umkRSyC9O919lbZ8dcH7mysshrCdrAM03skJOEYaBugxN+M6A==", + "version": "8.28.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.28.0.tgz", + "integrity": "sha512-OELa9hbTYciYITqgurT1u/SzpQVtDLmQMFzy/N8pQE+tefOyCWT79jHsav294aTqV1q1u+VzqDGbuujvRYaeSQ==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.12.2", - "@typescript-eslint/types": "8.12.2", - "@typescript-eslint/typescript-estree": "8.12.2" + "@typescript-eslint/scope-manager": "8.28.0", + "@typescript-eslint/types": "8.28.0", + "@typescript-eslint/typescript-estree": "8.28.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5035,18 +5016,19 @@ "url": "https://opencollective.com/typescript-eslint" }, "peerDependencies": { - "eslint": "^8.57.0 || ^9.0.0" + "eslint": "^8.57.0 || ^9.0.0", + "typescript": ">=4.8.4 <5.9.0" } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.12.2", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.12.2.tgz", - "integrity": "sha512-PChz8UaKQAVNHghsHcPyx1OMHoFRUEA7rJSK/mDhdq85bk+PLsUHUBqTQTFt18VJZbmxBovM65fezlheQRsSDA==", + "version": "8.28.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.28.0.tgz", + "integrity": "sha512-hbn8SZ8w4u2pRwgQ1GlUrPKE+t2XvcCW5tTRF7j6SMYIuYG37XuzIW44JCZPa36evi0Oy2SnM664BlIaAuQcvg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.12.2", - "eslint-visitor-keys": "^3.4.3" + "@typescript-eslint/types": "8.28.0", + "eslint-visitor-keys": "^4.2.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -5056,12 +5038,25 @@ "url": "https://opencollective.com/typescript-eslint" } }, - "node_modules/@ungap/structured-clone": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.2.0.tgz", - "integrity": "sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==", + "node_modules/@typescript-eslint/visitor-keys/node_modules/eslint-visitor-keys": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-4.2.0.tgz", + "integrity": "sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==", "dev": true, - "license": "ISC" + "license": "Apache-2.0", + "engines": { + "node": "^18.18.0 || ^20.9.0 || >=21.1.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" + } + }, + "node_modules/@ungap/structured-clone": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@ungap/structured-clone/-/structured-clone-1.3.0.tgz", + "integrity": "sha512-WmoN8qaIAo7WTYWbAZuG8PYEhn5fkz7dZrqTBZ7dtt//lL2Gwms1IcnQ5yHqjDfX8Ft5j4YzDM23f87zBfDe9g==", + "dev": true, + "license": "ISC" }, "node_modules/abort-controller": { "version": "3.0.0", @@ -5090,9 +5085,9 @@ } }, "node_modules/acorn": { - "version": "8.14.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.0.tgz", - "integrity": "sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA==", + "version": "8.14.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.14.1.tgz", + "integrity": "sha512-OvQ/2pUDKmgfCg++xsTX1wGxfTaszcHVcTctW4UJB4hibJx2HXxxO5UmVgyjMa+ZDsiaf5wWLXYpRWMmBI0QHg==", "license": "MIT", "bin": { "acorn": "bin/acorn" @@ -5125,13 +5120,10 @@ } }, "node_modules/agent-base": { - "version": "7.1.1", - "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.1.tgz", - "integrity": "sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==", + "version": "7.1.3", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-7.1.3.tgz", + "integrity": "sha512-jRR5wdylq8CkOe6hei19GGZnxM6rBGwFl3Bg0YItGDimvjGtAvdZk4Pu6Cl4u4Igsws4a1fd1Vq3ezrhn4KmFw==", "license": "MIT", - "dependencies": { - "debug": "^4.3.4" - }, "engines": { "node": ">= 14" } @@ -5183,12 +5175,14 @@ } }, "node_modules/ansi-regex": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", - "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", + "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", + "dev": true, "license": "MIT", + "peer": true, "engines": { - "node": ">=8" + "node": ">=6" } }, "node_modules/ansi-styles": { @@ -5302,17 +5296,6 @@ "repeat-string": "^1.6.1" } }, - "node_modules/assertion-error-formatter/node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true, - "license": "BSD-3-Clause", - "peer": true, - "engines": { - "node": ">=0.3.1" - } - }, "node_modules/ast-types": { "version": "0.13.4", "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.13.4.tgz", @@ -5338,16 +5321,6 @@ "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", "license": "MIT" }, - "node_modules/babel-core": { - "version": "7.0.0-bridge.0", - "resolved": "https://registry.npmjs.org/babel-core/-/babel-core-7.0.0-bridge.0.tgz", - "integrity": "sha512-poPX9mZH/5CSanm50Q+1toVci6pv5KSRv/5TWCwtzQS5XEwn40BcCrgIeMFWP9CKKIniKXNxoIOnOq4VVlGXhg==", - "license": "MIT", - "peer": true, - "peerDependencies": { - "@babel/core": "^7.0.0-0" - } - }, "node_modules/babel-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.7.0.tgz", @@ -5404,14 +5377,14 @@ } }, "node_modules/babel-plugin-polyfill-corejs2": { - "version": "0.4.11", - "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.11.tgz", - "integrity": "sha512-sMEJ27L0gRHShOh5G54uAAPaiCOygY/5ratXuiyb2G46FmlSpc9eFCzYVyDiPxfNbwzA7mYahmjQc5q+CZQ09Q==", + "version": "0.4.13", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.13.tgz", + "integrity": "sha512-3sX/eOms8kd3q2KZ6DAhKPc0dgm525Gqq5NtWKZ7QYYZEv57OQ54KtblzJzH1lQF/eQxO8KjWGIK9IPUJNus5g==", "license": "MIT", "peer": true, "dependencies": { "@babel/compat-data": "^7.22.6", - "@babel/helper-define-polyfill-provider": "^0.6.2", + "@babel/helper-define-polyfill-provider": "^0.6.4", "semver": "^6.3.1" }, "peerDependencies": { @@ -5429,40 +5402,40 @@ } }, "node_modules/babel-plugin-polyfill-corejs3": { - "version": "0.10.6", - "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs3/-/babel-plugin-polyfill-corejs3-0.10.6.tgz", - "integrity": "sha512-b37+KR2i/khY5sKmWNVQAnitvquQbNdWy6lJdsr0kmquCKEEUgMKK4SboVM3HtfnZilfjr4MMQ7vY58FVWDtIA==", + "version": "0.11.1", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs3/-/babel-plugin-polyfill-corejs3-0.11.1.tgz", + "integrity": "sha512-yGCqvBT4rwMczo28xkH/noxJ6MZ4nJfkVYdoDaC/utLtWrXxv27HVrzAeSbqR8SxDsp46n0YF47EbHoixy6rXQ==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-define-polyfill-provider": "^0.6.2", - "core-js-compat": "^3.38.0" + "@babel/helper-define-polyfill-provider": "^0.6.3", + "core-js-compat": "^3.40.0" }, "peerDependencies": { "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, "node_modules/babel-plugin-polyfill-regenerator": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.6.2.tgz", - "integrity": "sha512-2R25rQZWP63nGwaAswvDazbPXfrM3HwVoBXK6HcqeKrSrL/JqcC/rDcf95l4r7LXLyxDXc8uQDa064GubtCABg==", + "version": "0.6.4", + "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-regenerator/-/babel-plugin-polyfill-regenerator-0.6.4.tgz", + "integrity": "sha512-7gD3pRadPrbjhjLyxebmx/WrFYcuSjZ0XbdUujQMZ/fcE9oeewk2U/7PCvez84UeuK3oSjmPZ0Ch0dlupQvGzw==", "license": "MIT", "peer": true, "dependencies": { - "@babel/helper-define-polyfill-provider": "^0.6.2" + "@babel/helper-define-polyfill-provider": "^0.6.4" }, "peerDependencies": { "@babel/core": "^7.4.0 || ^8.0.0-0 <8.0.0" } }, "node_modules/babel-plugin-syntax-hermes-parser": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/babel-plugin-syntax-hermes-parser/-/babel-plugin-syntax-hermes-parser-0.23.1.tgz", - "integrity": "sha512-uNLD0tk2tLUjGFdmCk+u/3FEw2o+BAwW4g+z2QVlxJrzZYOOPADroEcNtTPt5lNiScctaUmnsTkVEnOwZUOLhA==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/babel-plugin-syntax-hermes-parser/-/babel-plugin-syntax-hermes-parser-0.25.1.tgz", + "integrity": "sha512-IVNpGzboFLfXZUAwkLFcI/bnqVbwky0jP3eBno4HKtqvQJAHBLdgxiG6lQ4to0+Q/YCN3PO0od5NZwIKyY4REQ==", "license": "MIT", "peer": true, "dependencies": { - "hermes-parser": "0.23.1" + "hermes-parser": "0.25.1" } }, "node_modules/babel-plugin-transform-flow-enums": { @@ -5649,9 +5622,9 @@ "license": "ISC" }, "node_modules/browserslist": { - "version": "4.24.2", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.2.tgz", - "integrity": "sha512-ZIc+Q62revdMcqC6aChtW4jz3My3klmCO1fEmINZY/8J3EpBg5/A/D0AKmBveUh6pgoeycoMkVMko84tuYS+Gg==", + "version": "4.24.4", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.24.4.tgz", + "integrity": "sha512-KDi1Ny1gSePi1vm0q4oxSF8b4DR44GF4BbmS2YdhPLOEqd8pDviZOGH/GsmRwoWJ2+5Lr085X7naowMwKHDG1A==", "funding": [ { "type": "opencollective", @@ -5669,9 +5642,9 @@ "license": "MIT", "peer": true, "dependencies": { - "caniuse-lite": "^1.0.30001669", - "electron-to-chromium": "^1.5.41", - "node-releases": "^2.0.18", + "caniuse-lite": "^1.0.30001688", + "electron-to-chromium": "^1.5.73", + "node-releases": "^2.0.19", "update-browserslist-db": "^1.1.1" }, "bin": { @@ -5732,17 +5705,46 @@ } }, "node_modules/call-bind": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", - "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.8.tgz", + "integrity": "sha512-oKlSFMcMwpUg2ednkhQ454wfWiU/ul3CkJe/PEHcTKuiX6RpbehUiFMXu13HalGZxfUwCQzZG747YXBn1im9ww==", "dev": true, "license": "MIT", "dependencies": { + "call-bind-apply-helpers": "^1.0.0", "es-define-property": "^1.0.0", - "es-errors": "^1.3.0", - "function-bind": "^1.1.2", "get-intrinsic": "^1.2.4", - "set-function-length": "^1.2.1" + "set-function-length": "^1.2.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "dev": true, + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" }, "engines": { "node": ">= 0.4" @@ -5808,9 +5810,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001676", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001676.tgz", - "integrity": "sha512-Qz6zwGCiPghQXGJvgQAem79esjitvJ+CxSbSQkW9H/UX5hg8XM88d4lp2W+MEQ81j+Hip58Il+jGVdazk1z9cw==", + "version": "1.0.30001707", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001707.tgz", + "integrity": "sha512-3qtRjw/HQSMlDWf+X79N206fepf4SOOU6SQLMaq/0KkZLmSjPxAkBOQQ+FxbHKfHmYLZFfdWsO3KA90ceHPSnw==", "funding": [ { "type": "opencollective", @@ -5912,6 +5914,18 @@ "url": "https://github.com/chalk/chalk?sponsor=1" } }, + "node_modules/chalk/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "license": "MIT", + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/check-error": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.3.tgz", @@ -6062,6 +6076,24 @@ "wrap-ansi": "^7.0.0" } }, + "node_modules/cliui/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "dev": true, + "license": "MIT", + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/clone-deep": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/clone-deep/-/clone-deep-4.0.1.tgz", @@ -6196,26 +6228,19 @@ } }, "node_modules/core-js-compat": { - "version": "3.39.0", - "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.39.0.tgz", - "integrity": "sha512-VgEUx3VwlExr5no0tXlBt+silBvhTryPwCXRI2Id1PN8WTKu7MreethvddqOubrYxkFdv/RnYrqlv1sFNAUelw==", + "version": "3.41.0", + "resolved": "https://registry.npmjs.org/core-js-compat/-/core-js-compat-3.41.0.tgz", + "integrity": "sha512-RFsU9LySVue9RTwdDVX/T0e2Y6jRYWXERKElIjpuEOEnxaXffI0X7RUwVzfYLfzuLXSNJDYoRYUAmRUcyln20A==", "license": "MIT", "peer": true, "dependencies": { - "browserslist": "^4.24.2" + "browserslist": "^4.24.4" }, "funding": { "type": "opencollective", "url": "https://opencollective.com/core-js" } }, - "node_modules/core-util-is": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", - "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==", - "license": "MIT", - "peer": true - }, "node_modules/cors": { "version": "2.8.5", "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz", @@ -6278,9 +6303,10 @@ "license": "MIT" }, "node_modules/cross-spawn": { - "version": "7.0.5", - "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.5.tgz", - "integrity": "sha512-ZVJrKKYunU38/76t0RMOulHOnUcbU9GbpWKAOZ0mhjr7CX6FVrH+4FrAapSOekrgFQ3f/8gwMEuIft0aKq6Hug==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "dev": true, "license": "MIT", "dependencies": { "path-key": "^3.1.0", @@ -6291,6 +6317,20 @@ "node": ">= 8" } }, + "node_modules/cssstyle": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/cssstyle/-/cssstyle-4.3.0.tgz", + "integrity": "sha512-6r0NiY0xizYqfBvWp1G7WXJ06/bZyrk7Dc6PHql82C/pKGUTKu4yAX4Y8JPamb1ob9nBKuxWzCGTRuGwU3yxJQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@asamuzakjp/css-color": "^3.1.1", + "rrweb-cssom": "^0.8.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/cucumber-tsflow": { "version": "4.4.4", "resolved": "https://registry.npmjs.org/cucumber-tsflow/-/cucumber-tsflow-4.4.4.tgz", @@ -6323,6 +6363,20 @@ "node": ">= 14" } }, + "node_modules/data-urls": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/data-urls/-/data-urls-5.0.0.tgz", + "integrity": "sha512-ZYP5VBHshaDAiVZxjbRVcFJpc+4xGgT0bK3vzy1HLN8jTO975HEbuYzZJcHoQEY5K1a0z8YayJkyVETa08eNTg==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/date-format": { "version": "4.0.14", "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", @@ -6334,9 +6388,9 @@ } }, "node_modules/debug": { - "version": "4.3.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", - "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "version": "4.4.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.0.tgz", + "integrity": "sha512-6WTZ/IxCY/T6BALoZHaE4ctp9xm+Z5kY/pzYaCHRFeyVhojxlrm+46y68HA6hr0TcwEssoxNiDEUJQjfPZ/RYA==", "license": "MIT", "dependencies": { "ms": "^2.1.3" @@ -6363,6 +6417,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/decimal.js": { + "version": "10.5.0", + "resolved": "https://registry.npmjs.org/decimal.js/-/decimal.js-10.5.0.tgz", + "integrity": "sha512-8vDa8Qxvr/+d94hSh5P3IJwI5t8/c0KsMp+g8bNw9cY2icONa5aPfvKeieW1WlG0WQYwwhJ7mjui2xtiePQSXw==", + "dev": true, + "license": "MIT" + }, "node_modules/deep-eql": { "version": "4.1.4", "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-4.1.4.tgz", @@ -6473,13 +6534,6 @@ "node": ">=0.4.0" } }, - "node_modules/denodeify": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/denodeify/-/denodeify-1.2.1.tgz", - "integrity": "sha512-KNTihKNmQENUZeKu5fzfpzRqR5S2VMp4gl9RFHiWzj9DfvYQPMJ6XHKNaQxaGCXwPk6y9yme3aUoaiAe+KX+vg==", - "license": "MIT", - "peer": true - }, "node_modules/depd": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", @@ -6507,9 +6561,9 @@ "license": "MIT" }, "node_modules/diff": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", - "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", + "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", "dev": true, "license": "BSD-3-Clause", "engines": { @@ -6552,6 +6606,20 @@ "void-elements": "^2.0.0" } }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -6567,9 +6635,9 @@ "license": "MIT" }, "node_modules/electron-to-chromium": { - "version": "1.5.49", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.49.tgz", - "integrity": "sha512-ZXfs1Of8fDb6z7WEYZjXpgIRF6MEu8JdeGA0A40aZq6OQbS+eJpnnV49epZRna2DU/YsEjSQuGtQPPtvt6J65A==", + "version": "1.5.128", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.128.tgz", + "integrity": "sha512-bo1A4HH/NS522Ws0QNFIzyPcyUUNV/yyy70Ho1xqfGYzPUme2F/xr4tlEOuM6/A538U1vDA7a4XfCd1CKRegKQ==", "license": "ISC", "peer": true }, @@ -6589,13 +6657,12 @@ } }, "node_modules/engine.io": { - "version": "6.6.2", - "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.2.tgz", - "integrity": "sha512-gmNvsYi9C8iErnZdVcJnvCpSKbWTt1E8+JZo8b+daLninywUWi5NQ5STSHZ9rFjFO7imNcvb8Pc5pe/wMR5xEw==", + "version": "6.6.4", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.4.tgz", + "integrity": "sha512-ZCkIjSYNDyGn0R6ewHDtXgns/Zre/NT6Agvq1/WobF7JXgFff4SeDroKiCO3fNJreU9YG429Sc81o4w5ok/W5g==", "dev": true, "license": "MIT", "dependencies": { - "@types/cookie": "^0.4.1", "@types/cors": "^2.8.12", "@types/node": ">=10.0.0", "accepts": "~1.3.4", @@ -6620,6 +6687,24 @@ "node": ">=10.0.0" } }, + "node_modules/engine.io/node_modules/debug": { + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, "node_modules/engine.io/node_modules/ws": { "version": "8.17.1", "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", @@ -6643,18 +6728,34 @@ } }, "node_modules/ent": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/ent/-/ent-2.2.1.tgz", - "integrity": "sha512-QHuXVeZx9d+tIQAz/XztU0ZwZf2Agg9CcXcgE1rurqvdBeDBrpSwjl8/6XUqMg7tw2Y7uAdKb2sRv+bSEFqQ5A==", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/ent/-/ent-2.2.2.tgz", + "integrity": "sha512-kKvD1tO6BM+oK9HzCPpUdRb4vKFQY/FPTFmurMvh6LlN68VMrdj77w8yp51/kDbpkFOS9J8w5W6zIzgM2H8/hw==", "dev": true, "license": "MIT", "dependencies": { - "punycode": "^1.4.1" + "call-bound": "^1.0.3", + "es-errors": "^1.3.0", + "punycode": "^1.4.1", + "safe-regex-test": "^1.1.0" }, "engines": { "node": ">= 0.4" } }, + "node_modules/entities": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", + "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=0.12" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/error-ex": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/error-ex/-/error-ex-1.3.2.tgz", @@ -6676,14 +6777,10 @@ } }, "node_modules/es-define-property": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", - "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", - "dev": true, + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", "license": "MIT", - "dependencies": { - "get-intrinsic": "^1.2.4" - }, "engines": { "node": ">= 0.4" } @@ -6692,12 +6789,38 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" } }, + "node_modules/es-object-atoms": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.1.tgz", + "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-set-tostringtag": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", + "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.6", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es6-shim": { "version": "0.35.8", "resolved": "https://registry.npmjs.org/es6-shim/-/es6-shim-0.35.8.tgz", @@ -6706,9 +6829,9 @@ "license": "MIT" }, "node_modules/esbuild": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", - "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.25.1.tgz", + "integrity": "sha512-BGO5LtrGC7vxnqucAe/rmvKdJllfGaYWdyABvyMoXQlfYMb2bbRuReWR5tEGE//4LcNJj9XrkovTqNYRFZHAMQ==", "dev": true, "hasInstallScript": true, "license": "MIT", @@ -6719,30 +6842,31 @@ "node": ">=18" }, "optionalDependencies": { - "@esbuild/aix-ppc64": "0.23.1", - "@esbuild/android-arm": "0.23.1", - "@esbuild/android-arm64": "0.23.1", - "@esbuild/android-x64": "0.23.1", - "@esbuild/darwin-arm64": "0.23.1", - "@esbuild/darwin-x64": "0.23.1", - "@esbuild/freebsd-arm64": "0.23.1", - "@esbuild/freebsd-x64": "0.23.1", - "@esbuild/linux-arm": "0.23.1", - "@esbuild/linux-arm64": "0.23.1", - "@esbuild/linux-ia32": "0.23.1", - "@esbuild/linux-loong64": "0.23.1", - "@esbuild/linux-mips64el": "0.23.1", - "@esbuild/linux-ppc64": "0.23.1", - "@esbuild/linux-riscv64": "0.23.1", - "@esbuild/linux-s390x": "0.23.1", - "@esbuild/linux-x64": "0.23.1", - "@esbuild/netbsd-x64": "0.23.1", - "@esbuild/openbsd-arm64": "0.23.1", - "@esbuild/openbsd-x64": "0.23.1", - "@esbuild/sunos-x64": "0.23.1", - "@esbuild/win32-arm64": "0.23.1", - "@esbuild/win32-ia32": "0.23.1", - "@esbuild/win32-x64": "0.23.1" + "@esbuild/aix-ppc64": "0.25.1", + "@esbuild/android-arm": "0.25.1", + "@esbuild/android-arm64": "0.25.1", + "@esbuild/android-x64": "0.25.1", + "@esbuild/darwin-arm64": "0.25.1", + "@esbuild/darwin-x64": "0.25.1", + "@esbuild/freebsd-arm64": "0.25.1", + "@esbuild/freebsd-x64": "0.25.1", + "@esbuild/linux-arm": "0.25.1", + "@esbuild/linux-arm64": "0.25.1", + "@esbuild/linux-ia32": "0.25.1", + "@esbuild/linux-loong64": "0.25.1", + "@esbuild/linux-mips64el": "0.25.1", + "@esbuild/linux-ppc64": "0.25.1", + "@esbuild/linux-riscv64": "0.25.1", + "@esbuild/linux-s390x": "0.25.1", + "@esbuild/linux-x64": "0.25.1", + "@esbuild/netbsd-arm64": "0.25.1", + "@esbuild/netbsd-x64": "0.25.1", + "@esbuild/openbsd-arm64": "0.25.1", + "@esbuild/openbsd-x64": "0.25.1", + "@esbuild/sunos-x64": "0.25.1", + "@esbuild/win32-arm64": "0.25.1", + "@esbuild/win32-ia32": "0.25.1", + "@esbuild/win32-x64": "0.25.1" } }, "node_modules/escalade": { @@ -6869,14 +6993,14 @@ } }, "node_modules/eslint-plugin-prettier": { - "version": "5.2.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", - "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==", + "version": "5.2.5", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.5.tgz", + "integrity": "sha512-IKKP8R87pJyMl7WWamLgPkloB16dagPIdd2FjBDbyRYPKo93wS/NbCOPh6gH+ieNLC+XZrhJt/kWj0PS/DFdmg==", "dev": true, "license": "MIT", "dependencies": { "prettier-linter-helpers": "^1.0.0", - "synckit": "^0.9.1" + "synckit": "^0.10.2" }, "engines": { "node": "^14.18.0 || >=16.0.0" @@ -6887,7 +7011,7 @@ "peerDependencies": { "@types/eslint": ">=8.0.0", "eslint": ">=8.0.0", - "eslint-config-prettier": "*", + "eslint-config-prettier": ">= 7.0.0 <10.0.0 || >=10.1.0", "prettier": ">=3.0.0" }, "peerDependenciesMeta": { @@ -7111,30 +7235,6 @@ "dev": true, "license": "MIT" }, - "node_modules/execa": { - "version": "5.1.1", - "resolved": "https://registry.npmjs.org/execa/-/execa-5.1.1.tgz", - "integrity": "sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==", - "license": "MIT", - "peer": true, - "dependencies": { - "cross-spawn": "^7.0.3", - "get-stream": "^6.0.0", - "human-signals": "^2.1.0", - "is-stream": "^2.0.0", - "merge-stream": "^2.0.0", - "npm-run-path": "^4.0.1", - "onetime": "^5.1.2", - "signal-exit": "^3.0.3", - "strip-final-newline": "^2.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sindresorhus/execa?sponsor=1" - } - }, "node_modules/expect": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/expect/-/expect-29.7.0.tgz", @@ -7153,9 +7253,9 @@ } }, "node_modules/exponential-backoff": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.1.tgz", - "integrity": "sha512-dX7e/LHVJ6W3DE1MHWi9S1EYzDESENfLrYohG2G++ovZrYOkm4Knwa0mc1cn84xJOR4KEU0WSchhLbd0UklbHw==", + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/exponential-backoff/-/exponential-backoff-3.1.2.tgz", + "integrity": "sha512-8QxYTVXUkuy7fIIoitQkPwGonB8F3Zj8eEO8Sqg9Zv/bkI7RJAzowee4gr81Hak/dUTpA2Z7VfQgoijjPNlUZA==", "license": "Apache-2.0", "peer": true }, @@ -7181,9 +7281,9 @@ "license": "Apache-2.0" }, "node_modules/fast-glob": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", - "integrity": "sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", + "integrity": "sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==", "dev": true, "license": "MIT", "dependencies": { @@ -7191,7 +7291,7 @@ "@nodelib/fs.walk": "^1.2.3", "glob-parent": "^5.1.2", "merge2": "^1.3.0", - "micromatch": "^4.0.4" + "micromatch": "^4.0.8" }, "engines": { "node": ">=8.6.0" @@ -7224,9 +7324,9 @@ "license": "MIT" }, "node_modules/fastq": { - "version": "1.17.1", - "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.17.1.tgz", - "integrity": "sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==", + "version": "1.19.1", + "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.19.1.tgz", + "integrity": "sha512-GwLTyxkCXjXbxqIhTsMI2Nui8huMPtnxg7krajPJAjnEG/iiOS7i+zCtWGZR9G0NBKbXKh6X9m9UIsYX/N6vvQ==", "dev": true, "license": "ISC", "dependencies": { @@ -7399,9 +7499,9 @@ } }, "node_modules/flatted": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.1.tgz", - "integrity": "sha512-X8cqMLLie7KsNUDSdzeN8FYK9rEt4Dt67OsG/DNGnYTSDBG4uFAJFBnUeiV+zCVAvwFy56IjM9sH51jVaEhNxw==", + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.3.3.tgz", + "integrity": "sha512-GX+ysw4PBCz0PzosHDepZGANEuFCMLrnRTiEy9McGjmkCQYwRq4A/X786G/fjM/+OjsWSU1ZrY5qyARZmO/uwg==", "dev": true, "license": "ISC" }, @@ -7413,9 +7513,9 @@ "peer": true }, "node_modules/flow-parser": { - "version": "0.251.1", - "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.251.1.tgz", - "integrity": "sha512-8ZuLqJPlL/T9K3zFdr1m88Lx8JOoJluTTdyvN4uH5NT9zoIIFqbCDoXVhkHh022k2lhuAyFF27cu0BYKh5SmDA==", + "version": "0.266.1", + "resolved": "https://registry.npmjs.org/flow-parser/-/flow-parser-0.266.1.tgz", + "integrity": "sha512-dON6h+yO7FGa/FO5NQCZuZHN0o3I23Ev6VYOJf9d8LpdrArHPt39wE++LLmueNV/hNY5hgWGIIrgnrDkRcXkPg==", "license": "MIT", "peer": true, "engines": { @@ -7444,14 +7544,14 @@ } }, "node_modules/foreground-child": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.0.tgz", - "integrity": "sha512-Ld2g8rrAyMYFXBhEqMz8ZAHBi4J4uS1i/CxGMDnjyFWddMXLVcDp051DZfu+t7+ab7Wv6SMqpWmyFIj5UbfFvg==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz", + "integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==", "dev": true, "license": "ISC", "peer": true, "dependencies": { - "cross-spawn": "^7.0.0", + "cross-spawn": "^7.0.6", "signal-exit": "^4.0.1" }, "engines": { @@ -7461,28 +7561,15 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/foreground-child/node_modules/signal-exit": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", - "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", - "dev": true, - "license": "ISC", - "peer": true, - "engines": { - "node": ">=14" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/form-data": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz", - "integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==", + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz", + "integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==", "license": "MIT", "dependencies": { "asynckit": "^0.4.0", "combined-stream": "^1.0.8", + "es-set-tostringtag": "^2.1.0", "mime-types": "^2.1.12" }, "engines": { @@ -7500,17 +7587,18 @@ } }, "node_modules/fs-extra": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.2.0.tgz", - "integrity": "sha512-PmDi3uwK5nFuXh7XDTlVnS17xJS7vW36is2+w3xcv8SVxiB4NyATf4ctkVY5bkSjX0Y4nbvZCq1/EjtEyr9ktw==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", + "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", + "dev": true, "license": "MIT", "dependencies": { "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" }, "engines": { - "node": ">=14.14" + "node": ">=6 <7 || >=8" } }, "node_modules/fs.realpath": { @@ -7582,17 +7670,21 @@ } }, "node_modules/get-intrinsic": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", - "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", - "dev": true, + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", "license": "MIT", "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", "function-bind": "^1.1.2", - "has-proto": "^1.0.1", - "has-symbols": "^1.0.3", - "hasown": "^2.0.0" + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" }, "engines": { "node": ">= 0.4" @@ -7611,23 +7703,23 @@ "node": ">=8.0.0" } }, - "node_modules/get-stream": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz", - "integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==", + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", "license": "MIT", - "peer": true, - "engines": { - "node": ">=10" + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "engines": { + "node": ">= 0.4" } }, "node_modules/get-tsconfig": { - "version": "4.8.1", - "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.8.1.tgz", - "integrity": "sha512-k9PN+cFBmaLWtVz29SkUoqU5O0slLuHJXt/2P+tMVFT+phsSGXGkp9t3rQIqdz0e+06EHNGs3oM6ZX1s2zHxRg==", + "version": "4.10.0", + "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.10.0.tgz", + "integrity": "sha512-kGzZ3LWWQcGIAmg6iWvXn0ei6WDtV26wzHRMwDSzmAbcXrTEXxHy6IehI6/4eT6VRKyMP1eF1VqwrVUmE/LR7A==", "dev": true, "license": "MIT", "dependencies": { @@ -7638,36 +7730,36 @@ } }, "node_modules/get-uri": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/get-uri/-/get-uri-6.0.3.tgz", - "integrity": "sha512-BzUrJBS9EcUb4cFol8r4W3v1cPsSyajLSthNkz5BxbpDcHN5tIrM10E2eNvfnvBn3DaT3DUgx0OpsBKkaOpanw==", + "version": "6.0.4", + "resolved": "https://registry.npmjs.org/get-uri/-/get-uri-6.0.4.tgz", + "integrity": "sha512-E1b1lFFLvLgak2whF2xDBcOy6NLVGZBqqjJjsIhvopKfWWEi64pLVTWWehV8KlLerZkfNTA95sTe2OdJKm1OzQ==", "license": "MIT", "dependencies": { "basic-ftp": "^5.0.2", "data-uri-to-buffer": "^6.0.2", - "debug": "^4.3.4", - "fs-extra": "^11.2.0" + "debug": "^4.3.4" }, "engines": { "node": ">= 14" } }, "node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", - "deprecated": "Glob versions prior to v9 are no longer supported", + "version": "10.4.5", + "resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz", + "integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==", "dev": true, "license": "ISC", + "peer": true, "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" + "foreground-child": "^3.1.0", + "jackspeak": "^3.1.2", + "minimatch": "^9.0.4", + "minipass": "^7.1.2", + "package-json-from-dist": "^1.0.0", + "path-scurry": "^1.11.1" }, - "engines": { - "node": ">=12" + "bin": { + "glob": "dist/esm/bin.mjs" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -7686,19 +7778,6 @@ "node": ">=10.13.0" } }, - "node_modules/glob/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", - "dev": true, - "license": "ISC", - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/global-dirs": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/global-dirs/-/global-dirs-3.0.1.tgz", @@ -7732,14 +7811,26 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/gopd": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", - "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "node_modules/globals/node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", "dev": true, + "license": "(MIT OR CC0-1.0)", + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", "license": "MIT", - "dependencies": { - "get-intrinsic": "^1.1.3" + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -7772,17 +7863,6 @@ "node": ">=8" } }, - "node_modules/has-ansi/node_modules/ansi-regex": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.1.tgz", - "integrity": "sha512-ILlv4k/3f6vfQ4OoP2AGvirOktlQ98ZEL1k9FaQjxa3L1abBgbuTDAdPOpvbGncC0BTVQrl+OM8xZGK6tWXt7g==", - "dev": true, - "license": "MIT", - "peer": true, - "engines": { - "node": ">=6" - } - }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -7805,24 +7885,10 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/has-proto": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", - "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/has-symbols": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", - "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "dev": true, + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", "license": "MIT", "engines": { "node": ">= 0.4" @@ -7835,7 +7901,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "dev": true, "license": "MIT", "dependencies": { "has-symbols": "^1.0.3" @@ -7870,20 +7935,20 @@ } }, "node_modules/hermes-estree": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.23.1.tgz", - "integrity": "sha512-eT5MU3f5aVhTqsfIReZ6n41X5sYn4IdQL0nvz6yO+MMlPxw49aSARHLg/MSehQftyjnrE8X6bYregzSumqc6cg==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.25.1.tgz", + "integrity": "sha512-0wUoCcLp+5Ev5pDW2OriHC2MJCbwLwuRx+gAqMTOkGKJJiBCLjtrvy4PWUGn6MIVefecRpzoOZ/UV6iGdOr+Cw==", "license": "MIT", "peer": true }, "node_modules/hermes-parser": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.23.1.tgz", - "integrity": "sha512-oxl5h2DkFW83hT4DAUJorpah8ou4yvmweUzLJmmr6YV2cezduCdlil1AvU/a/xSsAFo4WUcNA4GoV5Bvq6JffA==", + "version": "0.25.1", + "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.25.1.tgz", + "integrity": "sha512-6pEjquH3rqaI6cYAXYPcz9MS4rY6R4ngRgrgfDshRptUZIc3lw0MCIJIGDj9++mfySOuPTHB4nrSW99BCvOPIA==", "license": "MIT", "peer": true, "dependencies": { - "hermes-estree": "0.23.1" + "hermes-estree": "0.25.1" } }, "node_modules/hosted-git-info": { @@ -7894,6 +7959,19 @@ "license": "ISC", "peer": true }, + "node_modules/html-encoding-sniffer": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/html-encoding-sniffer/-/html-encoding-sniffer-4.0.0.tgz", + "integrity": "sha512-Y22oTqIU4uuPgEemfz7NDJz6OeKf12Lsu+QC+s3BVpda64lTiMYCyGwg5ki4vFxkMwQdeZDl2adZoqUgdFuTgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "whatwg-encoding": "^3.1.1" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/http-errors": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.0.tgz", @@ -7948,28 +8026,18 @@ } }, "node_modules/https-proxy-agent": { - "version": "7.0.5", - "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.5.tgz", - "integrity": "sha512-1e4Wqeblerz+tMKPIq2EMGiiWW1dIjZOksyHWSUm1rmuvw/how9hBHZ38lAGj5ID4Ik6EdkOw7NmWPy6LAwalw==", + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.6.tgz", + "integrity": "sha512-vK9P5/iUfdl95AI+JVyUuIcVtd4ofvtrOr3HNtM2yxC9bnMbEdp3x01OhQNnjb8IJYi38VlTE3mBXwcfvywuSw==", "license": "MIT", "dependencies": { - "agent-base": "^7.0.2", + "agent-base": "^7.1.2", "debug": "4" }, "engines": { "node": ">= 14" } }, - "node_modules/human-signals": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/human-signals/-/human-signals-2.1.0.tgz", - "integrity": "sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==", - "license": "Apache-2.0", - "peer": true, - "engines": { - "node": ">=10.17.0" - } - }, "node_modules/humanize-ms": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", @@ -8023,9 +8091,9 @@ } }, "node_modules/image-size": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/image-size/-/image-size-1.1.1.tgz", - "integrity": "sha512-541xKlUw6jr/6gGuk92F+mYM5zaFAc5ahphvkqvNe2bQ6gVBkd6bfrmVJ2t4KDAfikAYZyIqTnktX3i6/aQDrQ==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/image-size/-/image-size-1.2.0.tgz", + "integrity": "sha512-4S8fwbO6w3GeCVN6OPtA9I5IGKkcDMPcKndtUlpJuCwu7JLjtj7JZpwqLuyY2nrmQT3AWsCJLSKPsc2mPBSl3w==", "license": "MIT", "peer": true, "dependencies": { @@ -8039,9 +8107,9 @@ } }, "node_modules/import-fresh": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", - "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.1.tgz", + "integrity": "sha512-TR3KfrTZTYLPB6jUjfx6MF9WcWrHL9su5TObK4ZkYgBdWKPOFoSoQIdEuTuR82pmtxH2spWG9h6etwfr1pLBqQ==", "dev": true, "license": "MIT", "dependencies": { @@ -8133,14 +8201,14 @@ "license": "BSD-3-Clause" }, "node_modules/is-arguments": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", - "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.2.0.tgz", + "integrity": "sha512-7bVbi0huj/wrIAOzb8U1aszg9kdi3KN/CyU19CTI7tAoZYEZoL9yCDXpbXN+uPsuWnP02cyug1gleqq+TU+YCA==", "dev": true, "license": "MIT", "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" + "call-bound": "^1.0.2", + "has-tostringtag": "^1.0.2" }, "engines": { "node": ">= 0.4" @@ -8170,9 +8238,9 @@ } }, "node_modules/is-core-module": { - "version": "2.15.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.15.1.tgz", - "integrity": "sha512-z0vtXSwucUJtANQWldhbtbt7BnL0vxiFjIdDLAatwhDYty2bad6s+rijD6Ri4YuYJubLzIJLUidCh09e1djEVQ==", + "version": "2.16.1", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.16.1.tgz", + "integrity": "sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==", "license": "MIT", "dependencies": { "hasown": "^2.0.2" @@ -8185,13 +8253,14 @@ } }, "node_modules/is-date-object": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", - "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.1.0.tgz", + "integrity": "sha512-PwwhEakHVKTdRNVOw+/Gyh0+MzlCl4R6qKvkhuvLtPMggI1WAHt9sOwZxQLSGpUaDnrdyDsomoRgNnCfKNSXXg==", "dev": true, "license": "MIT", "dependencies": { - "has-tostringtag": "^1.0.0" + "call-bound": "^1.0.2", + "has-tostringtag": "^1.0.2" }, "engines": { "node": ">= 0.4" @@ -8332,6 +8401,13 @@ "node": ">=0.10.0" } }, + "node_modules/is-potential-custom-element-name": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-potential-custom-element-name/-/is-potential-custom-element-name-1.0.1.tgz", + "integrity": "sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==", + "dev": true, + "license": "MIT" + }, "node_modules/is-reference": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.2.1.tgz", @@ -8343,14 +8419,16 @@ } }, "node_modules/is-regex": { - "version": "1.1.4", - "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", - "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.2.1.tgz", + "integrity": "sha512-MjYsKHO5O7mCsmRGxWcLWheFqN9DJ/2TmngvjKXihe6efViPqc274+Fx/4fYj/r03+ESvBdTXK0V6tA3rgez1g==", "dev": true, "license": "MIT", "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" + "call-bound": "^1.0.2", + "gopd": "^1.2.0", + "has-tostringtag": "^1.0.2", + "hasown": "^2.0.2" }, "engines": { "node": ">= 0.4" @@ -8363,6 +8441,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-2.0.1.tgz", "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", + "dev": true, "license": "MIT", "peer": true, "engines": { @@ -8422,6 +8501,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true, "license": "ISC" }, "node_modules/isobject": { @@ -8694,22 +8774,6 @@ "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, - "node_modules/jest-worker/node_modules/supports-color": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", - "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", - "license": "MIT", - "peer": true, - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/supports-color?sponsor=1" - } - }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -8735,13 +8799,6 @@ "integrity": "sha512-4bYVV3aAMtDTTu4+xsDYa6sy9GyJ69/amsu9sYF2zqjiEoZA5xJi3BrfX3uY+/IekIu7MwdObdbDWpoZdBv3/A==", "license": "MIT" }, - "node_modules/jsc-android": { - "version": "250231.0.0", - "resolved": "https://registry.npmjs.org/jsc-android/-/jsc-android-250231.0.0.tgz", - "integrity": "sha512-rS46PvsjYmdmuz1OAWXY/1kCYG7pnf1TBqeTiOJr1iDz7s5DLxxC9n/ZMknLDxzYzNVfI7R95MH10emSSG1Wuw==", - "license": "BSD-2-Clause", - "peer": true - }, "node_modules/jsc-safe-url": { "version": "0.2.4", "resolved": "https://registry.npmjs.org/jsc-safe-url/-/jsc-safe-url-0.2.4.tgz", @@ -8750,55 +8807,105 @@ "peer": true }, "node_modules/jscodeshift": { - "version": "0.14.0", - "resolved": "https://registry.npmjs.org/jscodeshift/-/jscodeshift-0.14.0.tgz", - "integrity": "sha512-7eCC1knD7bLUPuSCwXsMZUH51O8jIcoVyKtI6P0XM0IVzlGjckPy3FIwQlorzbN0Sg79oK+RlohN32Mqf/lrYA==", - "license": "MIT", - "peer": true, - "dependencies": { - "@babel/core": "^7.13.16", - "@babel/parser": "^7.13.16", - "@babel/plugin-proposal-class-properties": "^7.13.0", - "@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8", - "@babel/plugin-proposal-optional-chaining": "^7.13.12", - "@babel/plugin-transform-modules-commonjs": "^7.13.8", - "@babel/preset-flow": "^7.13.13", - "@babel/preset-typescript": "^7.13.0", - "@babel/register": "^7.13.16", - "babel-core": "^7.0.0-bridge.0", - "chalk": "^4.1.2", + "version": "17.3.0", + "resolved": "https://registry.npmjs.org/jscodeshift/-/jscodeshift-17.3.0.tgz", + "integrity": "sha512-LjFrGOIORqXBU+jwfC9nbkjmQfFldtMIoS6d9z2LG/lkmyNXsJAySPT+2SWXJEoE68/bCWcxKpXH37npftgmow==", + "license": "MIT", + "peer": true, + "dependencies": { + "@babel/core": "^7.24.7", + "@babel/parser": "^7.24.7", + "@babel/plugin-transform-class-properties": "^7.24.7", + "@babel/plugin-transform-modules-commonjs": "^7.24.7", + "@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7", + "@babel/plugin-transform-optional-chaining": "^7.24.7", + "@babel/plugin-transform-private-methods": "^7.24.7", + "@babel/preset-flow": "^7.24.7", + "@babel/preset-typescript": "^7.24.7", + "@babel/register": "^7.24.6", "flow-parser": "0.*", "graceful-fs": "^4.2.4", - "micromatch": "^4.0.4", + "micromatch": "^4.0.7", "neo-async": "^2.5.0", - "node-dir": "^0.1.17", - "recast": "^0.21.0", - "temp": "^0.8.4", - "write-file-atomic": "^2.3.0" + "picocolors": "^1.0.1", + "recast": "^0.23.11", + "tmp": "^0.2.3", + "write-file-atomic": "^5.0.1" }, "bin": { "jscodeshift": "bin/jscodeshift.js" }, + "engines": { + "node": ">=16" + }, "peerDependencies": { "@babel/preset-env": "^7.1.6" + }, + "peerDependenciesMeta": { + "@babel/preset-env": { + "optional": true + } } }, "node_modules/jscodeshift/node_modules/write-file-atomic": { - "version": "2.4.3", - "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-2.4.3.tgz", - "integrity": "sha512-GaETH5wwsX+GcnzhPgKcKjJ6M2Cq3/iZp1WyY/X1CSqrW+jVNM9Y7D8EC2sM4ZG/V8wZlSniJnCKWPmBYAucRQ==", + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/write-file-atomic/-/write-file-atomic-5.0.1.tgz", + "integrity": "sha512-+QU2zd6OTD8XWIJCbffaiQeH9U73qIqafo1x6V1snCWYGJf6cVE0cDR4D8xRzcEnfI21IFrUPzPGtcPf8AC+Rw==", "license": "ISC", "peer": true, "dependencies": { - "graceful-fs": "^4.1.11", "imurmurhash": "^0.1.4", - "signal-exit": "^3.0.2" + "signal-exit": "^4.0.1" + }, + "engines": { + "node": "^14.17.0 || ^16.13.0 || >=18.0.0" + } + }, + "node_modules/jsdom": { + "version": "26.0.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-26.0.0.tgz", + "integrity": "sha512-BZYDGVAIriBWTpIxYzrXjv3E/4u8+/pSG5bQdIYCbNCGOvsPkDQfTVLAIXAf9ETdCpduCVTkDe2NNZ8NIwUVzw==", + "dev": true, + "license": "MIT", + "dependencies": { + "cssstyle": "^4.2.1", + "data-urls": "^5.0.0", + "decimal.js": "^10.4.3", + "form-data": "^4.0.1", + "html-encoding-sniffer": "^4.0.0", + "http-proxy-agent": "^7.0.2", + "https-proxy-agent": "^7.0.6", + "is-potential-custom-element-name": "^1.0.1", + "nwsapi": "^2.2.16", + "parse5": "^7.2.1", + "rrweb-cssom": "^0.8.0", + "saxes": "^6.0.0", + "symbol-tree": "^3.2.4", + "tough-cookie": "^5.0.0", + "w3c-xmlserializer": "^5.0.0", + "webidl-conversions": "^7.0.0", + "whatwg-encoding": "^3.1.1", + "whatwg-mimetype": "^4.0.0", + "whatwg-url": "^14.1.0", + "ws": "^8.18.0", + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "canvas": "^3.0.0" + }, + "peerDependenciesMeta": { + "canvas": { + "optional": true + } } }, "node_modules/jsesc": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.0.2.tgz", - "integrity": "sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==", + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.1.0.tgz", + "integrity": "sha512-/sM3dO2FOzXjKQhJuo0Q173wf2KOo8t4I8vHy6lF9poUp7bKT0/NHE8fPX23PwfhnykfqnC2xRxOnVw5XuGIaA==", "license": "MIT", "peer": true, "bin": { @@ -8865,13 +8972,11 @@ } }, "node_modules/jsonfile": { - "version": "6.1.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz", - "integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==", + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", + "dev": true, "license": "MIT", - "dependencies": { - "universalify": "^2.0.0" - }, "optionalDependencies": { "graceful-fs": "^4.1.6" } @@ -9034,6 +9139,19 @@ "url": "https://github.com/sponsors/isaacs" } }, + "node_modules/karma/node_modules/mime": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", + "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", + "dev": true, + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=4.0.0" + } + }, "node_modules/karma/node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -9047,6 +9165,19 @@ "node": "*" } }, + "node_modules/karma/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "license": "MIT", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/keyv": { "version": "4.5.4", "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz", @@ -9272,13 +9403,11 @@ } }, "node_modules/lru-cache": { - "version": "7.18.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", - "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", - "license": "ISC", - "engines": { - "node": ">=12" - } + "version": "10.4.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", + "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", + "dev": true, + "license": "ISC" }, "node_modules/luxon": { "version": "3.2.1", @@ -9292,9 +9421,9 @@ } }, "node_modules/magic-string": { - "version": "0.30.12", - "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.12.tgz", - "integrity": "sha512-Ea8I3sQMVXr8JhN4z+H/d8zwo+tYDgHE9+5G4Wnrwhs0gaK9fXTKx0Tw5Xwsd/bCPTTZNRAdpyzvoeORe9LYpw==", + "version": "0.30.17", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz", + "integrity": "sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==", "dev": true, "license": "MIT", "dependencies": { @@ -9349,6 +9478,15 @@ "license": "Apache-2.0", "peer": true }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/media-typer": { "version": "0.3.0", "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", @@ -9384,9 +9522,9 @@ } }, "node_modules/metro": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro/-/metro-0.81.0.tgz", - "integrity": "sha512-kzdzmpL0gKhEthZ9aOV7sTqvg6NuTxDV8SIm9pf9sO8VVEbKrQk5DNcwupOUjgPPFAuKUc2NkT0suyT62hm2xg==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro/-/metro-0.81.4.tgz", + "integrity": "sha512-78f0aBNPuwXW7GFnSc+Y0vZhbuQorXxdgqQfvSRqcSizqwg9cwF27I05h47tL8AzQcizS1JZncvq4xf5u/Qykw==", "license": "MIT", "peer": true, "dependencies": { @@ -9402,33 +9540,31 @@ "ci-info": "^2.0.0", "connect": "^3.6.5", "debug": "^2.2.0", - "denodeify": "^1.2.1", "error-stack-parser": "^2.0.6", "flow-enums-runtime": "^0.0.6", "graceful-fs": "^4.2.4", - "hermes-parser": "0.24.0", + "hermes-parser": "0.25.1", "image-size": "^1.0.2", "invariant": "^2.2.4", - "jest-worker": "^29.6.3", + "jest-worker": "^29.7.0", "jsc-safe-url": "^0.2.2", "lodash.throttle": "^4.1.1", - "metro-babel-transformer": "0.81.0", - "metro-cache": "0.81.0", - "metro-cache-key": "0.81.0", - "metro-config": "0.81.0", - "metro-core": "0.81.0", - "metro-file-map": "0.81.0", - "metro-resolver": "0.81.0", - "metro-runtime": "0.81.0", - "metro-source-map": "0.81.0", - "metro-symbolicate": "0.81.0", - "metro-transform-plugins": "0.81.0", - "metro-transform-worker": "0.81.0", + "metro-babel-transformer": "0.81.4", + "metro-cache": "0.81.4", + "metro-cache-key": "0.81.4", + "metro-config": "0.81.4", + "metro-core": "0.81.4", + "metro-file-map": "0.81.4", + "metro-resolver": "0.81.4", + "metro-runtime": "0.81.4", + "metro-source-map": "0.81.4", + "metro-symbolicate": "0.81.4", + "metro-transform-plugins": "0.81.4", + "metro-transform-worker": "0.81.4", "mime-types": "^2.1.27", "nullthrows": "^1.1.1", "serialize-error": "^2.1.0", "source-map": "^0.5.6", - "strip-ansi": "^6.0.0", "throat": "^5.0.0", "ws": "^7.5.10", "yargs": "^17.6.2" @@ -9441,57 +9577,40 @@ } }, "node_modules/metro-babel-transformer": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-babel-transformer/-/metro-babel-transformer-0.81.0.tgz", - "integrity": "sha512-Dc0QWK4wZIeHnyZ3sevWGTnnSkIDDn/SWyfrn99zbKbDOCoCYy71PAn9uCRrP/hduKLJQOy+tebd63Rr9D8tXg==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-babel-transformer/-/metro-babel-transformer-0.81.4.tgz", + "integrity": "sha512-WW0yswWrW+eTVK9sYD+b1HwWOiUlZlUoomiw9TIOk0C+dh2V90Wttn/8g62kYi0Y4i+cJfISerB2LbV4nuRGTA==", "license": "MIT", "peer": true, "dependencies": { "@babel/core": "^7.25.2", "flow-enums-runtime": "^0.0.6", - "hermes-parser": "0.24.0", + "hermes-parser": "0.25.1", "nullthrows": "^1.1.1" }, "engines": { "node": ">=18.18" } }, - "node_modules/metro-babel-transformer/node_modules/hermes-estree": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.24.0.tgz", - "integrity": "sha512-LyoXLB7IFzeZW0EvAbGZacbxBN7t6KKSDqFJPo3Ydow7wDlrDjXwsdiAHV6XOdvEN9MEuWXsSIFN4tzpyrXIHw==", - "license": "MIT", - "peer": true - }, - "node_modules/metro-babel-transformer/node_modules/hermes-parser": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.24.0.tgz", - "integrity": "sha512-IJooSvvu2qNRe7oo9Rb04sUT4omtZqZqf9uq9WM25Tb6v3usmvA93UqfnnoWs5V0uYjEl9Al6MNU10MCGKLwpg==", - "license": "MIT", - "peer": true, - "dependencies": { - "hermes-estree": "0.24.0" - } - }, "node_modules/metro-cache": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-cache/-/metro-cache-0.81.0.tgz", - "integrity": "sha512-DyuqySicHXkHUDZFVJmh0ygxBSx6pCKUrTcSgb884oiscV/ROt1Vhye+x+OIHcsodyA10gzZtrVtxIFV4l9I4g==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-cache/-/metro-cache-0.81.4.tgz", + "integrity": "sha512-sxCPH3gowDxazSaZZrwdNPEpnxR8UeXDnvPjBF9+5btDBNN2DpWvDAXPvrohkYkFImhc0LajS2V7eOXvu9PnvQ==", "license": "MIT", "peer": true, "dependencies": { "exponential-backoff": "^3.1.1", "flow-enums-runtime": "^0.0.6", - "metro-core": "0.81.0" + "metro-core": "0.81.4" }, "engines": { "node": ">=18.18" } }, "node_modules/metro-cache-key": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-cache-key/-/metro-cache-key-0.81.0.tgz", - "integrity": "sha512-qX/IwtknP9bQZL78OK9xeSvLM/xlGfrs6SlUGgHvrxtmGTRSsxcyqxR+c+7ch1xr05n62Gin/O44QKg5V70rNQ==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-cache-key/-/metro-cache-key-0.81.4.tgz", + "integrity": "sha512-3SaWQybvf1ivasjBegIxzVKLJzOpcz+KsnGwXFOYADQq0VN4cnM7tT+u2jkOhk6yJiiO1WIjl68hqyMOQJRRLg==", "license": "MIT", "peer": true, "dependencies": { @@ -9502,64 +9621,59 @@ } }, "node_modules/metro-config": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-config/-/metro-config-0.81.0.tgz", - "integrity": "sha512-6CinEaBe3WLpRlKlYXXu8r1UblJhbwD6Gtnoib5U8j6Pjp7XxMG9h/DGMeNp9aGLDu1OieUqiXpFo7O0/rR5Kg==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-config/-/metro-config-0.81.4.tgz", + "integrity": "sha512-QnhMy3bRiuimCTy7oi5Ug60javrSa3lPh0gpMAspQZHY9h6y86jwHtZPLtlj8hdWQESIlrbeL8inMSF6qI/i9Q==", "license": "MIT", "peer": true, "dependencies": { "connect": "^3.6.5", "cosmiconfig": "^5.0.5", "flow-enums-runtime": "^0.0.6", - "jest-validate": "^29.6.3", - "metro": "0.81.0", - "metro-cache": "0.81.0", - "metro-core": "0.81.0", - "metro-runtime": "0.81.0" + "jest-validate": "^29.7.0", + "metro": "0.81.4", + "metro-cache": "0.81.4", + "metro-core": "0.81.4", + "metro-runtime": "0.81.4" }, "engines": { "node": ">=18.18" } }, "node_modules/metro-core": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-core/-/metro-core-0.81.0.tgz", - "integrity": "sha512-CVkM5YCOAFkNMvJai6KzA0RpztzfEKRX62/PFMOJ9J7K0uq/UkOFLxcgpcncMIrfy0PbfEj811b69tjULUQe1Q==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-core/-/metro-core-0.81.4.tgz", + "integrity": "sha512-GdL4IgmgJhrMA/rTy2lRqXKeXfC77Rg+uvhUEkbhyfj/oz7PrdSgvIFzziapjdHwk1XYq0KyFh/CcVm8ZawG6A==", "license": "MIT", "peer": true, "dependencies": { "flow-enums-runtime": "^0.0.6", "lodash.throttle": "^4.1.1", - "metro-resolver": "0.81.0" + "metro-resolver": "0.81.4" }, "engines": { "node": ">=18.18" } }, "node_modules/metro-file-map": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-file-map/-/metro-file-map-0.81.0.tgz", - "integrity": "sha512-zMDI5uYhQCyxbye/AuFx/pAbsz9K+vKL7h1ShUXdN2fz4VUPiyQYRsRqOoVG1DsiCgzd5B6LW0YW77NFpjDQeg==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-file-map/-/metro-file-map-0.81.4.tgz", + "integrity": "sha512-qUIBzkiqOi3qEuscu4cJ83OYQ4hVzjON19FAySWqYys9GKCmxlKa7LkmwqdpBso6lQl+JXZ7nCacX90w5wQvPA==", "license": "MIT", "peer": true, "dependencies": { - "anymatch": "^3.0.3", "debug": "^2.2.0", "fb-watchman": "^2.0.0", "flow-enums-runtime": "^0.0.6", "graceful-fs": "^4.2.4", "invariant": "^2.2.4", - "jest-worker": "^29.6.3", + "jest-worker": "^29.7.0", "micromatch": "^4.0.4", - "node-abort-controller": "^3.1.1", "nullthrows": "^1.1.1", "walker": "^1.0.7" }, "engines": { "node": ">=18.18" - }, - "optionalDependencies": { - "fsevents": "^2.3.2" } }, "node_modules/metro-file-map/node_modules/debug": { @@ -9580,9 +9694,9 @@ "peer": true }, "node_modules/metro-minify-terser": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-minify-terser/-/metro-minify-terser-0.81.0.tgz", - "integrity": "sha512-U2ramh3W822ZR1nfXgIk+emxsf5eZSg10GbQrT0ZizImK8IZ5BmJY+BHRIkQgHzWFpExOVxC7kWbGL1bZALswA==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-minify-terser/-/metro-minify-terser-0.81.4.tgz", + "integrity": "sha512-oVvq/AGvqmbhuijJDZZ9npeWzaVyeBwQKtdlnjcQ9fH7nR15RiBr5y2zTdgTEdynqOIb1Kc16l8CQIUSzOWVFA==", "license": "MIT", "peer": true, "dependencies": { @@ -9594,9 +9708,9 @@ } }, "node_modules/metro-resolver": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.81.0.tgz", - "integrity": "sha512-Uu2Q+buHhm571cEwpPek8egMbdSTqmwT/5U7ZVNpK6Z2ElQBBCxd7HmFAslKXa7wgpTO2FAn6MqGeERbAtVDUA==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.81.4.tgz", + "integrity": "sha512-Ng7G2mXjSExMeRzj6GC19G6IJ0mfIbOLgjArsMWJgtt9ViZiluCwgWsMW9juBC5NSwjJxUMK2x6pC5NIMFLiHA==", "license": "MIT", "peer": true, "dependencies": { @@ -9607,9 +9721,9 @@ } }, "node_modules/metro-runtime": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-runtime/-/metro-runtime-0.81.0.tgz", - "integrity": "sha512-6oYB5HOt37RuGz2eV4A6yhcl+PUTwJYLDlY9vhT+aVjbUWI6MdBCf69vc4f5K5Vpt+yOkjy+2LDwLS0ykWFwYw==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-runtime/-/metro-runtime-0.81.4.tgz", + "integrity": "sha512-fBoRgqkF69CwyPtBNxlDi5ha26Zc8f85n2THXYoh13Jn/Bkg8KIDCdKPp/A1BbSeNnkH/++H2EIIfnmaff4uRg==", "license": "MIT", "peer": true, "dependencies": { @@ -9621,9 +9735,9 @@ } }, "node_modules/metro-source-map": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-source-map/-/metro-source-map-0.81.0.tgz", - "integrity": "sha512-TzsVxhH83dyxg4A4+L1nzNO12I7ps5IHLjKGZH3Hrf549eiZivkdjYiq/S5lOB+p2HiQ+Ykcwtmcja95LIC62g==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-source-map/-/metro-source-map-0.81.4.tgz", + "integrity": "sha512-IOwVQ7mLqoqvsL70RZtl1EyE3f9jp43kVsAsb/B/zoWmu0/k4mwEhGLTxmjdXRkLJqPqPrh7WmFChAEf9trW4Q==", "license": "MIT", "peer": true, "dependencies": { @@ -9632,9 +9746,9 @@ "@babel/types": "^7.25.2", "flow-enums-runtime": "^0.0.6", "invariant": "^2.2.4", - "metro-symbolicate": "0.81.0", + "metro-symbolicate": "0.81.4", "nullthrows": "^1.1.1", - "ob1": "0.81.0", + "ob1": "0.81.4", "source-map": "^0.5.6", "vlq": "^1.0.0" }, @@ -9653,18 +9767,17 @@ } }, "node_modules/metro-symbolicate": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-symbolicate/-/metro-symbolicate-0.81.0.tgz", - "integrity": "sha512-C/1rWbNTPYp6yzID8IPuQPpVGzJ2rbWYBATxlvQ9dfK5lVNoxcwz77hjcY8ISLsRRR15hyd/zbjCNKPKeNgE1Q==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-symbolicate/-/metro-symbolicate-0.81.4.tgz", + "integrity": "sha512-rWxTmYVN6/BOSaMDUHT8HgCuRf6acd0AjHkenYlHpmgxg7dqdnAG1hLq999q2XpW5rX+cMamZD5W5Ez2LqGaag==", "license": "MIT", "peer": true, "dependencies": { "flow-enums-runtime": "^0.0.6", "invariant": "^2.2.4", - "metro-source-map": "0.81.0", + "metro-source-map": "0.81.4", "nullthrows": "^1.1.1", "source-map": "^0.5.6", - "through2": "^2.0.1", "vlq": "^1.0.0" }, "bin": { @@ -9685,9 +9798,9 @@ } }, "node_modules/metro-transform-plugins": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-transform-plugins/-/metro-transform-plugins-0.81.0.tgz", - "integrity": "sha512-uErLAPBvttGCrmGSCa0dNHlOTk3uJFVEVWa5WDg6tQ79PRmuYRwzUgLhVzn/9/kyr75eUX3QWXN79Jvu4txt6Q==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-transform-plugins/-/metro-transform-plugins-0.81.4.tgz", + "integrity": "sha512-nlP069nDXm4v28vbll4QLApAlvVtlB66rP6h+ml8Q/CCQCPBXu2JLaoxUmkIOJQjLhMRUcgTyQHq+TXWJhydOQ==", "license": "MIT", "peer": true, "dependencies": { @@ -9703,9 +9816,9 @@ } }, "node_modules/metro-transform-worker": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/metro-transform-worker/-/metro-transform-worker-0.81.0.tgz", - "integrity": "sha512-HrQ0twiruhKy0yA+9nK5bIe3WQXZcC66PXTvRIos61/EASLAP2DzEmW7IxN/MGsfZegN2UzqL2CG38+mOB45vg==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/metro-transform-worker/-/metro-transform-worker-0.81.4.tgz", + "integrity": "sha512-lKAeRZ8EUMtx2cA/Y4KvICr9bIr5SE03iK3lm+l9wyn2lkjLUuPjYVep159inLeDqC6AtSubsA8MZLziP7c03g==", "license": "MIT", "peer": true, "dependencies": { @@ -9714,13 +9827,13 @@ "@babel/parser": "^7.25.3", "@babel/types": "^7.25.2", "flow-enums-runtime": "^0.0.6", - "metro": "0.81.0", - "metro-babel-transformer": "0.81.0", - "metro-cache": "0.81.0", - "metro-cache-key": "0.81.0", - "metro-minify-terser": "0.81.0", - "metro-source-map": "0.81.0", - "metro-transform-plugins": "0.81.0", + "metro": "0.81.4", + "metro-babel-transformer": "0.81.4", + "metro-cache": "0.81.4", + "metro-cache-key": "0.81.4", + "metro-minify-terser": "0.81.4", + "metro-source-map": "0.81.4", + "metro-transform-plugins": "0.81.4", "nullthrows": "^1.1.1" }, "engines": { @@ -9759,23 +9872,6 @@ "ms": "2.0.0" } }, - "node_modules/metro/node_modules/hermes-estree": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/hermes-estree/-/hermes-estree-0.24.0.tgz", - "integrity": "sha512-LyoXLB7IFzeZW0EvAbGZacbxBN7t6KKSDqFJPo3Ydow7wDlrDjXwsdiAHV6XOdvEN9MEuWXsSIFN4tzpyrXIHw==", - "license": "MIT", - "peer": true - }, - "node_modules/metro/node_modules/hermes-parser": { - "version": "0.24.0", - "resolved": "https://registry.npmjs.org/hermes-parser/-/hermes-parser-0.24.0.tgz", - "integrity": "sha512-IJooSvvu2qNRe7oo9Rb04sUT4omtZqZqf9uq9WM25Tb6v3usmvA93UqfnnoWs5V0uYjEl9Al6MNU10MCGKLwpg==", - "license": "MIT", - "peer": true, - "dependencies": { - "hermes-estree": "0.24.0" - } - }, "node_modules/metro/node_modules/ms": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", @@ -9793,6 +9889,24 @@ "node": ">=0.10.0" } }, + "node_modules/metro/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "license": "MIT", + "peer": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, "node_modules/metro/node_modules/ws": { "version": "7.5.10", "resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz", @@ -9870,16 +9984,17 @@ } }, "node_modules/mime": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/mime/-/mime-2.6.0.tgz", - "integrity": "sha512-USPkMeET31rOMiarsBNIHZKLGgvKc/LrjofAnBlOttf5ajRvqiRA8QsenbcooctK6d6Ts6aqZXBA+XbkKthiQg==", - "dev": true, - "license": "MIT", + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", + "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", + "dev": true, + "license": "MIT", + "peer": true, "bin": { "mime": "cli.js" }, "engines": { - "node": ">=4.0.0" + "node": ">=10.0.0" } }, "node_modules/mime-db": { @@ -9903,16 +10018,6 @@ "node": ">= 0.6" } }, - "node_modules/mimic-fn": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", - "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", - "license": "MIT", - "peer": true, - "engines": { - "node": ">=6" - } - }, "node_modules/minimatch": { "version": "9.0.5", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz", @@ -9933,6 +10038,7 @@ "version": "1.2.8", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz", "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==", + "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -9950,15 +10056,20 @@ } }, "node_modules/mkdirp": { - "version": "0.5.6", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", - "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "version": "2.1.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.6.tgz", + "integrity": "sha512-+hEnITedc8LAtIP9u3HJDFIdcLV2vXP33sqLLIzkv1Db1zO/1OxbvYf0Y1OC/S/Qo5dxHXepofhmxL02PsKe+A==", + "dev": true, "license": "MIT", - "dependencies": { - "minimist": "^1.2.6" - }, + "peer": true, "bin": { - "mkdirp": "bin/cmd.js" + "mkdirp": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/mocha": { @@ -10057,6 +10168,37 @@ "dev": true, "license": "MIT" }, + "node_modules/mocha/node_modules/diff": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-5.0.0.tgz", + "integrity": "sha512-/VTCrvm5Z0JGty/BWHljh+BAiw3IK+2j87NGMu8Nwc/f48WoDAC395uomO9ZD117ZOBaHmkX1oyLvkVM/aIT3w==", + "dev": true, + "license": "BSD-3-Clause", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/mocha/node_modules/glob": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", + "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "deprecated": "Glob versions prior to v9 are no longer supported", + "dev": true, + "license": "ISC", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^5.0.1", + "once": "^1.3.0" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/mocha/node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", @@ -10106,22 +10248,6 @@ "randombytes": "^2.1.0" } }, - "node_modules/mocha/node_modules/supports-color": { - "version": "8.1.1", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", - "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "has-flag": "^4.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/supports-color?sponsor=1" - } - }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", @@ -10230,62 +10356,18 @@ } }, "node_modules/nock": { - "version": "14.0.0-beta.15", - "resolved": "https://registry.npmjs.org/nock/-/nock-14.0.0-beta.15.tgz", - "integrity": "sha512-rp72chatxoZbR/2cYHwtb+IX6n6kkanYKGN2PKn4c12JBrj9n4xGUKFykuQHB+Gkz3fynlikFbMH2LI6VoebuQ==", + "version": "14.0.2", + "resolved": "https://registry.npmjs.org/nock/-/nock-14.0.2.tgz", + "integrity": "sha512-jDUBpCNY7KLyOF2FTiT4mLRxV2kpjo4YrcGtv3IMCIwqFKxOQFrmeXefvuEiWvS3ApPWQHAkakkkVpoOrDNCVg==", "dev": true, "license": "MIT", "dependencies": { - "@mswjs/interceptors": "^0.36.4", + "@mswjs/interceptors": "^0.38.0", "json-stringify-safe": "^5.0.1", "propagate": "^2.0.0" }, "engines": { - "node": ">= 18" - } - }, - "node_modules/node-abort-controller": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/node-abort-controller/-/node-abort-controller-3.1.1.tgz", - "integrity": "sha512-AGK2yQKIjRuqnc6VkX2Xj5d+QW8xZ87pa1UK6yA6ouUyuxfHuMP6umE5QK7UmTeOAymo+Zx1Fxiuw9rVx8taHQ==", - "license": "MIT", - "peer": true - }, - "node_modules/node-dir": { - "version": "0.1.17", - "resolved": "https://registry.npmjs.org/node-dir/-/node-dir-0.1.17.tgz", - "integrity": "sha512-tmPX422rYgofd4epzrNoOXiE8XFZYOcCq1vD7MAXCDO+O+zndlA2ztdKKMa+EeuBG5tHETpr4ml4RGgpqDCCAg==", - "license": "MIT", - "peer": true, - "dependencies": { - "minimatch": "^3.0.2" - }, - "engines": { - "node": ">= 0.10.5" - } - }, - "node_modules/node-dir/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "license": "MIT", - "peer": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/node-dir/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "license": "ISC", - "peer": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" + "node": ">=18.20.0 <20 || >=20.12.1" } }, "node_modules/node-fetch": { @@ -10308,6 +10390,28 @@ } } }, + "node_modules/node-fetch/node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", + "license": "MIT" + }, + "node_modules/node-fetch/node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", + "license": "BSD-2-Clause" + }, + "node_modules/node-fetch/node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "license": "MIT", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/node-forge": { "version": "1.3.1", "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-1.3.1.tgz", @@ -10326,9 +10430,9 @@ "peer": true }, "node_modules/node-releases": { - "version": "2.0.18", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.18.tgz", - "integrity": "sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g==", + "version": "2.0.19", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.19.tgz", + "integrity": "sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==", "license": "MIT", "peer": true }, @@ -10366,19 +10470,6 @@ "node": ">=0.10.0" } }, - "node_modules/npm-run-path": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz", - "integrity": "sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw==", - "license": "MIT", - "peer": true, - "dependencies": { - "path-key": "^3.0.0" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/nullthrows": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/nullthrows/-/nullthrows-1.1.1.tgz", @@ -10386,10 +10477,17 @@ "license": "MIT", "peer": true }, + "node_modules/nwsapi": { + "version": "2.2.20", + "resolved": "https://registry.npmjs.org/nwsapi/-/nwsapi-2.2.20.tgz", + "integrity": "sha512-/ieB+mDe4MrrKMT8z+mQL8klXydZWGR5Dowt4RAGKbJ3kIGEx3X4ljUo+6V73IXtUPWgfOlU5B9MlGxFO5T+cA==", + "dev": true, + "license": "MIT" + }, "node_modules/ob1": { - "version": "0.81.0", - "resolved": "https://registry.npmjs.org/ob1/-/ob1-0.81.0.tgz", - "integrity": "sha512-6Cvrkxt1tqaRdWqTAMcVYEiO5i1xcF9y7t06nFdjFqkfPsEloCf8WwhXdwBpNUkVYSQlSGS7cDgVQR86miBfBQ==", + "version": "0.81.4", + "resolved": "https://registry.npmjs.org/ob1/-/ob1-0.81.4.tgz", + "integrity": "sha512-EZLYM8hfPraC2SYOR5EWLFAPV5e6g+p83m2Jth9bzCpFxP1NDQJYXdmXRB2bfbaWQSmm6NkIQlbzk7uU5lLfgg==", "license": "MIT", "peer": true, "dependencies": { @@ -10410,9 +10508,9 @@ } }, "node_modules/object-inspect": { - "version": "1.13.2", - "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", - "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", "dev": true, "license": "MIT", "engines": { @@ -10470,22 +10568,6 @@ "wrappy": "1" } }, - "node_modules/onetime": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", - "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", - "license": "MIT", - "peer": true, - "dependencies": { - "mimic-fn": "^2.1.0" - }, - "engines": { - "node": ">=6" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/open": { "version": "7.4.2", "resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz", @@ -10571,19 +10653,19 @@ } }, "node_modules/pac-proxy-agent": { - "version": "7.0.2", - "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.0.2.tgz", - "integrity": "sha512-BFi3vZnO9X5Qt6NRz7ZOaPja3ic0PhlsmCRYLOpN11+mWBCR6XJDqW5RF3j8jm4WGGQZtBA+bTfxYzeKW73eHg==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.2.0.tgz", + "integrity": "sha512-TEB8ESquiLMc0lV8vcd5Ql/JAKAoyzHFXaStwjkzpOpC5Yv+pIzLfHvjTSdf3vpa2bMiUQrg9i6276yn8666aA==", "license": "MIT", "dependencies": { "@tootallnate/quickjs-emscripten": "^0.23.0", - "agent-base": "^7.0.2", + "agent-base": "^7.1.2", "debug": "^4.3.4", "get-uri": "^6.0.1", "http-proxy-agent": "^7.0.0", - "https-proxy-agent": "^7.0.5", + "https-proxy-agent": "^7.0.6", "pac-resolver": "^7.0.1", - "socks-proxy-agent": "^8.0.4" + "socks-proxy-agent": "^8.0.5" }, "engines": { "node": ">= 14" @@ -10651,6 +10733,19 @@ "node": ">=4" } }, + "node_modules/parse5": { + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.2.1.tgz", + "integrity": "sha512-BuBYQYlv1ckiPdQi/ohiivi9Sagc9JG+Ozs0r7b/0iK3sKmrb0b9FdWdBbOdx6hBCM/F9Ir82ofnBhtZOjCRPQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "entities": "^4.5.0" + }, + "funding": { + "url": "https://github.com/inikulin/parse5?sponsor=1" + } + }, "node_modules/parseurl": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", @@ -10682,6 +10777,7 @@ "version": "3.1.1", "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -10711,14 +10807,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/path-scurry/node_modules/lru-cache": { - "version": "10.4.3", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz", - "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", - "dev": true, - "license": "ISC", - "peer": true - }, "node_modules/path-to-regexp": { "version": "1.9.0", "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.9.0.tgz", @@ -10769,9 +10857,9 @@ } }, "node_modules/pirates": { - "version": "4.0.6", - "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.6.tgz", - "integrity": "sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==", + "version": "4.0.7", + "resolved": "https://registry.npmjs.org/pirates/-/pirates-4.0.7.tgz", + "integrity": "sha512-TfySrs/5nm8fQJDcBDuUng3VOUKsd7S+zqvbOTiGXHfxX4wK31ard+hoNuvkicM/2YFzlpDgABOevKSsB4G/FA==", "license": "MIT", "peer": true, "engines": { @@ -10868,9 +10956,9 @@ } }, "node_modules/prettier": { - "version": "3.3.3", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", - "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.5.3.tgz", + "integrity": "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw==", "dev": true, "license": "MIT", "bin": { @@ -10922,13 +11010,6 @@ "url": "https://github.com/chalk/ansi-styles?sponsor=1" } }, - "node_modules/process-nextick-args": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", - "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==", - "license": "MIT", - "peer": true - }, "node_modules/progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", @@ -10969,24 +11050,33 @@ "peer": true }, "node_modules/proxy-agent": { - "version": "6.4.0", - "resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-6.4.0.tgz", - "integrity": "sha512-u0piLU+nCOHMgGjRbimiXmA9kM/L9EHh3zL81xCdp7m+Y2pHIsnmbdDoEDoAz5geaonNR6q6+yOPQs6n4T6sBQ==", + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/proxy-agent/-/proxy-agent-6.5.0.tgz", + "integrity": "sha512-TmatMXdr2KlRiA2CyDu8GqR8EjahTG3aY3nXjdzFyoZbmB8hrBsTyMezhULIXKnC0jpfjlmiZ3+EaCzoInSu/A==", "license": "MIT", "dependencies": { - "agent-base": "^7.0.2", + "agent-base": "^7.1.2", "debug": "^4.3.4", "http-proxy-agent": "^7.0.1", - "https-proxy-agent": "^7.0.3", + "https-proxy-agent": "^7.0.6", "lru-cache": "^7.14.1", - "pac-proxy-agent": "^7.0.1", + "pac-proxy-agent": "^7.1.0", "proxy-from-env": "^1.1.0", - "socks-proxy-agent": "^8.0.2" + "socks-proxy-agent": "^8.0.5" }, "engines": { "node": ">= 14" } }, + "node_modules/proxy-agent/node_modules/lru-cache": { + "version": "7.18.3", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz", + "integrity": "sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA==", + "license": "ISC", + "engines": { + "node": ">=12" + } + }, "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -11100,22 +11190,19 @@ } }, "node_modules/react": { - "version": "18.3.1", - "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", - "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", + "version": "19.1.0", + "resolved": "https://registry.npmjs.org/react/-/react-19.1.0.tgz", + "integrity": "sha512-FS+XFBNvn3GTAWq26joslQgWNoFu08F4kl0J4CgdNKADkdSGXQyTCnKteIAJy96Br6YbpEU1LSzV5dYtjMkMDg==", "license": "MIT", "peer": true, - "dependencies": { - "loose-envify": "^1.1.0" - }, "engines": { "node": ">=0.10.0" } }, "node_modules/react-devtools-core": { - "version": "5.3.2", - "resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-5.3.2.tgz", - "integrity": "sha512-crr9HkVrDiJ0A4zot89oS0Cgv0Oa4OG1Em4jit3P3ZxZSKPMYyMjfwMqgcJna9o625g8oN87rBm8SWWrSTBZxg==", + "version": "6.1.1", + "resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-6.1.1.tgz", + "integrity": "sha512-TFo1MEnkqE6hzAbaztnyR5uLTMoz6wnEWwWBsCUzNt+sVXJycuRJdDqvL078M4/h65BI/YO5XWTaxZDWVsW0fw==", "license": "MIT", "peer": true, "dependencies": { @@ -11152,25 +11239,25 @@ "license": "MIT" }, "node_modules/react-native": { - "version": "0.76.1", - "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.76.1.tgz", - "integrity": "sha512-z4KnbrnnAvloRs9NGnah3u6/LK3IbtNMrvByxa3ifigbMlsMY4WPRYV9lvt/hH4Mzt8bfuI+utnOxFyJTTq3lg==", + "version": "0.78.1", + "resolved": "https://registry.npmjs.org/react-native/-/react-native-0.78.1.tgz", + "integrity": "sha512-3CK/xxX02GeeVFyrXbsHvREZFVaXwHW43Km/EdYITn5G32cccWTGaqY9QdPddEBLw5O3BPip3LHbR1SywE0cpA==", "license": "MIT", "peer": true, "dependencies": { "@jest/create-cache-key-function": "^29.6.3", - "@react-native/assets-registry": "0.76.1", - "@react-native/codegen": "0.76.1", - "@react-native/community-cli-plugin": "0.76.1", - "@react-native/gradle-plugin": "0.76.1", - "@react-native/js-polyfills": "0.76.1", - "@react-native/normalize-colors": "0.76.1", - "@react-native/virtualized-lists": "0.76.1", + "@react-native/assets-registry": "0.78.1", + "@react-native/codegen": "0.78.1", + "@react-native/community-cli-plugin": "0.78.1", + "@react-native/gradle-plugin": "0.78.1", + "@react-native/js-polyfills": "0.78.1", + "@react-native/normalize-colors": "0.78.1", + "@react-native/virtualized-lists": "0.78.1", "abort-controller": "^3.0.0", "anser": "^1.4.9", "ansi-regex": "^5.0.0", "babel-jest": "^29.7.0", - "babel-plugin-syntax-hermes-parser": "^0.23.1", + "babel-plugin-syntax-hermes-parser": "0.25.1", "base64-js": "^1.5.1", "chalk": "^4.0.0", "commander": "^12.0.0", @@ -11179,18 +11266,16 @@ "glob": "^7.1.1", "invariant": "^2.2.4", "jest-environment-node": "^29.6.3", - "jsc-android": "^250231.0.0", "memoize-one": "^5.0.0", "metro-runtime": "^0.81.0", "metro-source-map": "^0.81.0", - "mkdirp": "^0.5.1", "nullthrows": "^1.1.1", "pretty-format": "^29.7.0", "promise": "^8.3.0", - "react-devtools-core": "^5.3.1", + "react-devtools-core": "^6.0.1", "react-refresh": "^0.14.0", "regenerator-runtime": "^0.13.2", - "scheduler": "0.24.0-canary-efb381bbf-20230505", + "scheduler": "0.25.0", "semver": "^7.1.3", "stacktrace-parser": "^0.1.10", "whatwg-fetch": "^3.0.0", @@ -11204,8 +11289,8 @@ "node": ">=18" }, "peerDependencies": { - "@types/react": "^18.2.6", - "react": "^18.2.0" + "@types/react": "^19.0.0", + "react": "^19.0.0" }, "peerDependenciesMeta": { "@types/react": { @@ -11225,6 +11310,16 @@ "react-native": "*" } }, + "node_modules/react-native/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8" + } + }, "node_modules/react-native/node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -11286,6 +11381,34 @@ "node": "*" } }, + "node_modules/react-native/node_modules/wrap-ansi": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", + "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "license": "MIT", + "peer": true, + "dependencies": { + "ansi-styles": "^4.0.0", + "string-width": "^4.1.0", + "strip-ansi": "^6.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/wrap-ansi?sponsor=1" + } + }, + "node_modules/react-native/node_modules/ws": { + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.3.tgz", + "integrity": "sha512-jmTjYU0j60B+vHey6TfR3Z7RD61z/hmxBS3VMSGIrroOWXQEneK1zNuotOUrGyBHQj0yrpsLHPWtigEFd13ndA==", + "license": "MIT", + "peer": true, + "dependencies": { + "async-limiter": "~1.0.0" + } + }, "node_modules/react-native/node_modules/yargs": { "version": "17.7.2", "resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz", @@ -11463,36 +11586,6 @@ "node": ">=8" } }, - "node_modules/readable-stream": { - "version": "2.3.8", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", - "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", - "license": "MIT", - "peer": true, - "dependencies": { - "core-util-is": "~1.0.0", - "inherits": "~2.0.3", - "isarray": "~1.0.0", - "process-nextick-args": "~2.0.0", - "safe-buffer": "~5.1.1", - "string_decoder": "~1.1.1", - "util-deprecate": "~1.0.1" - } - }, - "node_modules/readable-stream/node_modules/isarray": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==", - "license": "MIT", - "peer": true - }, - "node_modules/readable-stream/node_modules/safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "license": "MIT", - "peer": true - }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", @@ -11527,15 +11620,16 @@ "peer": true }, "node_modules/recast": { - "version": "0.21.5", - "resolved": "https://registry.npmjs.org/recast/-/recast-0.21.5.tgz", - "integrity": "sha512-hjMmLaUXAm1hIuTqOdeYObMslq/q+Xff6QE3Y2P+uoHAg2nmVlLBps2hzh1UJDdMtDTMXOFewK6ky51JQIeECg==", + "version": "0.23.11", + "resolved": "https://registry.npmjs.org/recast/-/recast-0.23.11.tgz", + "integrity": "sha512-YTUo+Flmw4ZXiWfQKGcwwc11KnoRAYgzAE2E7mXKCjSviTKShtxBsN6YUUBB2gtaBzKzeKunxhUwNHQuRryhWA==", "license": "MIT", "peer": true, "dependencies": { - "ast-types": "0.15.2", + "ast-types": "^0.16.1", "esprima": "~4.0.0", "source-map": "~0.6.1", + "tiny-invariant": "^1.3.3", "tslib": "^2.0.1" }, "engines": { @@ -11543,9 +11637,9 @@ } }, "node_modules/recast/node_modules/ast-types": { - "version": "0.15.2", - "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.15.2.tgz", - "integrity": "sha512-c27loCv9QkZinsa5ProX751khO9DJl/AcB5c2KNtA6NRvHKS0PgLfcftz72KVq504vB0Gku5s2kUZzDBvQWvHg==", + "version": "0.16.1", + "resolved": "https://registry.npmjs.org/ast-types/-/ast-types-0.16.1.tgz", + "integrity": "sha512-6t10qk83GOG8p0vKmaCr8eiilZwO171AvbROMtvvNiwrTly62t+7XkA8RdIIVbpMhCASAsxgAzdRSwh6nw/5Dg==", "license": "MIT", "peer": true, "dependencies": { @@ -11624,15 +11718,17 @@ } }, "node_modules/regexp.prototype.flags": { - "version": "1.5.3", - "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.3.tgz", - "integrity": "sha512-vqlC04+RQoFalODCbCumG2xIOvapzVMHwsyIGM/SIE8fRhFFsXeH8/QQ+s0T0kDAhKc4k30s73/0ydkHQz6HlQ==", + "version": "1.5.4", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.4.tgz", + "integrity": "sha512-dYqgNSZbDwkaJ2ceRd9ojCGjBq+mOm9LmtXnAnEGyHhN/5R7iDW2TRw3h+o/jCFxus3P2LfWIIiwowAjANm7IA==", "dev": true, "license": "MIT", "dependencies": { - "call-bind": "^1.0.7", + "call-bind": "^1.0.8", "define-properties": "^1.2.1", "es-errors": "^1.3.0", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", "set-function-name": "^2.0.2" }, "engines": { @@ -11643,16 +11739,16 @@ } }, "node_modules/regexpu-core": { - "version": "6.1.1", - "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-6.1.1.tgz", - "integrity": "sha512-k67Nb9jvwJcJmVpw0jPttR1/zVfnKf8Km0IPatrU/zJ5XeG3+Slx0xLXs9HByJSzXzrlz5EDvN6yLNMDc2qdnw==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/regexpu-core/-/regexpu-core-6.2.0.tgz", + "integrity": "sha512-H66BPQMrv+V16t8xtmq+UC0CBpiTBA60V8ibS1QVReIp8T1z8hwFxqcGzm9K6lgsN7sB5edVH8a+ze6Fqm4weA==", "license": "MIT", "peer": true, "dependencies": { "regenerate": "^1.4.2", "regenerate-unicode-properties": "^10.2.0", "regjsgen": "^0.8.0", - "regjsparser": "^0.11.0", + "regjsparser": "^0.12.0", "unicode-match-property-ecmascript": "^2.0.0", "unicode-match-property-value-ecmascript": "^2.1.0" }, @@ -11668,9 +11764,9 @@ "peer": true }, "node_modules/regjsparser": { - "version": "0.11.2", - "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.11.2.tgz", - "integrity": "sha512-3OGZZ4HoLJkkAZx/48mTXJNlmqTGOzc0o9OWQPuWpkOlXXPbyN6OafCcoXUnBqE2D3f/T5L+pWc1kdEmnfnRsA==", + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/regjsparser/-/regjsparser-0.12.0.tgz", + "integrity": "sha512-cnE+y8bz4NhMjISKbgeVJtqNbtf5QpjZP+Bslo+UqkIt9QPnX9q095eiRRASJG1/tz6dlNr6Z5NsBiWYokp6EQ==", "license": "BSD-2-Clause", "peer": true, "dependencies": { @@ -11680,11 +11776,24 @@ "regjsparser": "bin/parser" } }, - "node_modules/repeat-string": { - "version": "1.6.1", - "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", - "integrity": "sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==", - "dev": true, + "node_modules/regjsparser/node_modules/jsesc": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/jsesc/-/jsesc-3.0.2.tgz", + "integrity": "sha512-xKqzzWXDttJuOcawBt4KnKHHIf5oQ/Cxax+0PWFG+DFDgHNAdi+TXECADI+RYiFUMmx8792xsMbbgXj4CwnP4g==", + "license": "MIT", + "peer": true, + "bin": { + "jsesc": "bin/jsesc" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/repeat-string": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/repeat-string/-/repeat-string-1.6.1.tgz", + "integrity": "sha512-PV0dzCYDNfRi1jCDbJzpW7jNNDRuCOG/jI5ctQcGKt/clZD+YcPS3yIlWuTJMmESC8aevCFmWJy5wjAFgNqN6w==", + "dev": true, "license": "MIT", "peer": true, "engines": { @@ -11708,18 +11817,21 @@ "license": "MIT" }, "node_modules/resolve": { - "version": "1.22.8", - "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", - "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", + "version": "1.22.10", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.10.tgz", + "integrity": "sha512-NPRy+/ncIMeDlTAsuqwKIiferiawhefFJtkNSW0qZJEqMEb+qBt/77B/jGeeek+F0uOeN05CDa6HXbbIgtVX4w==", "license": "MIT", "dependencies": { - "is-core-module": "^2.13.0", + "is-core-module": "^2.16.0", "path-parse": "^1.0.7", "supports-preserve-symlinks-flag": "^1.0.0" }, "bin": { "resolve": "bin/resolve" }, + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -11770,9 +11882,9 @@ } }, "node_modules/reusify": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", - "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.1.0.tgz", + "integrity": "sha512-g6QUff04oZpHs0eG5p83rFLhHeV00ug/Yf9nZM6fLeUrPguBTkTQOdpAWWspMh55TZfVQDPaN3NQJfbVRAxdIw==", "dev": true, "license": "MIT", "engines": { @@ -11929,6 +12041,13 @@ "dev": true, "license": "MIT" }, + "node_modules/rrweb-cssom": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/rrweb-cssom/-/rrweb-cssom-0.8.0.tgz", + "integrity": "sha512-guoltQEx+9aMf2gDZ0s62EcV8lsXR+0w8915TC3ITdn2YueuNjdAYh/levpU9nFaoChh9RUS5ZdQMrKfVEN9tw==", + "dev": true, + "license": "MIT" + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -11974,6 +12093,24 @@ ], "license": "MIT" }, + "node_modules/safe-regex-test": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.1.0.tgz", + "integrity": "sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==", + "dev": true, + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "is-regex": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", @@ -11981,16 +12118,26 @@ "dev": true, "license": "MIT" }, - "node_modules/scheduler": { - "version": "0.24.0-canary-efb381bbf-20230505", - "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.24.0-canary-efb381bbf-20230505.tgz", - "integrity": "sha512-ABvovCDe/k9IluqSh4/ISoq8tIJnW8euVAWYt5j/bg6dRnqwQwiGO1F/V4AyK96NGF/FB04FhOUDuWj8IKfABA==", - "license": "MIT", - "peer": true, + "node_modules/saxes": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/saxes/-/saxes-6.0.0.tgz", + "integrity": "sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==", + "dev": true, + "license": "ISC", "dependencies": { - "loose-envify": "^1.1.0" + "xmlchars": "^2.2.0" + }, + "engines": { + "node": ">=v12.22.7" } }, + "node_modules/scheduler": { + "version": "0.25.0", + "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.25.0.tgz", + "integrity": "sha512-xFVuu11jh+xcO7JOAGJNOXld8/TcEHK/4CituBUeUb5hqxJLj9YuemAEuvm9gQ/+pgXYfbQuqAkiYu+u7YEsNA==", + "license": "MIT", + "peer": true + }, "node_modules/seed-random": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/seed-random/-/seed-random-2.2.0.tgz", @@ -12014,10 +12161,14 @@ } }, "node_modules/semver": { - "version": "7.6.3", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.6.3.tgz", - "integrity": "sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==", + "version": "7.5.3", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.5.3.tgz", + "integrity": "sha512-QBlUtyVk/5EeHbi7X0fw6liDZc7BBmEaSYn01fMU1OUYbf6GPsbTtd8WmnqbI20SeycoHSeiybkE/q1Q+qlThQ==", "license": "ISC", + "peer": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, "bin": { "semver": "bin/semver.js" }, @@ -12025,6 +12176,26 @@ "node": ">=10" } }, + "node_modules/semver/node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "license": "ISC", + "peer": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/semver/node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "license": "ISC", + "peer": true + }, "node_modules/send": { "version": "0.19.0", "resolved": "https://registry.npmjs.org/send/-/send-0.19.0.tgz", @@ -12193,6 +12364,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, "license": "MIT", "dependencies": { "shebang-regex": "^3.0.0" @@ -12205,32 +12377,93 @@ "version": "3.0.0", "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, "license": "MIT", "engines": { "node": ">=8" } }, "node_modules/shell-quote": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz", - "integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==", + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.2.tgz", + "integrity": "sha512-AzqKpGKjrj7EM6rKVQEPpB288oCfnrEIuyoT9cyF4nmGa7V8Zk6f7RRqYisX8X9m+Q7bd632aZW4ky7EhbQztA==", "license": "MIT", "peer": true, + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, "node_modules/side-channel": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", - "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.0.tgz", + "integrity": "sha512-ZX99e6tRweoUXqR+VBrslhda51Nh5MTQwou5tnUDgbtyM0dBgmhEDtWGP/xbKn6hqfPRHujUNwz5fy/wbbhnpw==", "dev": true, "license": "MIT", "dependencies": { - "call-bind": "^1.0.7", "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.4", - "object-inspect": "^1.13.1" + "object-inspect": "^1.13.3", + "side-channel-list": "^1.0.0", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.0.tgz", + "integrity": "sha512-FCLHtRD/gnpCiCHEiJLOwdmFP+wzCmDEkc9y7NsYxeF4u7Btsn1ZuwgwJGxImImHicJArLP4R0yX4c2KCrMrTA==", + "dev": true, + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "dev": true, + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "dev": true, + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" }, "engines": { "node": ">= 0.4" @@ -12240,11 +12473,17 @@ } }, "node_modules/signal-exit": { - "version": "3.0.7", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", - "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz", + "integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==", "license": "ISC", - "peer": true + "peer": true, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } }, "node_modules/sinon": { "version": "7.5.0", @@ -12383,6 +12622,24 @@ "ws": "~8.17.1" } }, + "node_modules/socket.io-adapter/node_modules/debug": { + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, "node_modules/socket.io-adapter/node_modules/ws": { "version": "8.17.1", "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", @@ -12419,10 +12676,46 @@ "node": ">=10.0.0" } }, + "node_modules/socket.io-parser/node_modules/debug": { + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/socket.io/node_modules/debug": { + "version": "4.3.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.7.tgz", + "integrity": "sha512-Er2nc/H7RrMXZBFCEim6TCmMk02Z8vLC2Rbi1KEBggpo0fS6l0S1nnapwmIi3yW/+GOJap1Krg4w0Hg80oCqgQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, "node_modules/socks": { - "version": "2.8.3", - "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.3.tgz", - "integrity": "sha512-l5x7VUUWbjVFbafGLxPWkYsHIhEvmF85tbIeFZWc8ZPtoMyybuEhL7Jye/ooC4/d48FgOjSJXgsF/AJPYCW8Zw==", + "version": "2.8.4", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.8.4.tgz", + "integrity": "sha512-D3YaD0aRxR3mEcqnidIs7ReYJFVzWdd6fXJYUM8ixcQcJRGTka/b3saV0KflYhyVJXKhb947GndU35SxYNResQ==", "license": "MIT", "dependencies": { "ip-address": "^9.0.5", @@ -12434,12 +12727,12 @@ } }, "node_modules/socks-proxy-agent": { - "version": "8.0.4", - "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.4.tgz", - "integrity": "sha512-GNAq/eg8Udq2x0eNiFkr9gRg5bA7PXEWagQdeRX4cPSG+X/8V38v637gim9bjFptMk1QWsCTr0ttrJEiXbNnRw==", + "version": "8.0.5", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.5.tgz", + "integrity": "sha512-HehCEsotFqbPW9sJ8WVYB6UbmIMv7kUUORIF2Nncq4VQvBfNBLibW9YZR5dlYCSUhwcD628pRllm7n+E+YTzJw==", "license": "MIT", "dependencies": { - "agent-base": "^7.1.1", + "agent-base": "^7.1.2", "debug": "^4.3.4", "socks": "^2.8.3" }, @@ -12499,9 +12792,9 @@ } }, "node_modules/spdx-license-ids": { - "version": "3.0.20", - "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.20.tgz", - "integrity": "sha512-jg25NiDV/1fLtSgEgyvVyDunvaNHbuwF9lfNV17gSmPFAlYzdfNBlLtLzXTevwkPj7DhGbmN9VnmJIgLnhvaBw==", + "version": "3.0.21", + "resolved": "https://registry.npmjs.org/spdx-license-ids/-/spdx-license-ids-3.0.21.tgz", + "integrity": "sha512-Bvg/8F5XephndSK3JffaRqdT+gyhfqIPwDHpX80tJrF8QQRYMo8sNMeaZ2Dp5+jhwKnUmIOyFFQfHRkjJm5nXg==", "dev": true, "license": "CC0-1.0", "peer": true @@ -12541,9 +12834,9 @@ "peer": true }, "node_modules/stacktrace-parser": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/stacktrace-parser/-/stacktrace-parser-0.1.10.tgz", - "integrity": "sha512-KJP1OCML99+8fhOHxwwzyWrlUuVX5GQ0ZpJTd1DFXhdkrvg1szxfHhawXUZ3g9TkXORQd4/WG68jMlQZ2p8wlg==", + "version": "0.1.11", + "resolved": "https://registry.npmjs.org/stacktrace-parser/-/stacktrace-parser-0.1.11.tgz", + "integrity": "sha512-WjlahMgHmCJpqzU8bIBy4qtsZdU9lRlcZE3Lvyej6t4tuOuv1vk57OW3MBrj6hXBFx/nNoC9MPMTcr5YA7NQbg==", "license": "MIT", "peer": true, "dependencies": { @@ -12587,41 +12880,6 @@ "node": ">=8.0" } }, - "node_modules/streamroller/node_modules/fs-extra": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-8.1.0.tgz", - "integrity": "sha512-yhlQgA6mnOJUKOsRUFsgJdQCvkKhcz8tlZG5HBQfReYZy46OwLcY+Zia0mtdHsOo9y/hP+CxMN0TU9QxoOtG4g==", - "dev": true, - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" - }, - "engines": { - "node": ">=6 <7 || >=8" - } - }, - "node_modules/streamroller/node_modules/jsonfile": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", - "integrity": "sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==", - "dev": true, - "license": "MIT", - "optionalDependencies": { - "graceful-fs": "^4.1.6" - } - }, - "node_modules/streamroller/node_modules/universalify": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", - "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">= 4.0.0" - } - }, "node_modules/strict-event-emitter": { "version": "0.5.1", "resolved": "https://registry.npmjs.org/strict-event-emitter/-/strict-event-emitter-0.5.1.tgz", @@ -12629,23 +12887,6 @@ "dev": true, "license": "MIT" }, - "node_modules/string_decoder": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", - "license": "MIT", - "peer": true, - "dependencies": { - "safe-buffer": "~5.1.0" - } - }, - "node_modules/string_decoder/node_modules/safe-buffer": { - "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", - "license": "MIT", - "peer": true - }, "node_modules/string-argv": { "version": "0.3.1", "resolved": "https://registry.npmjs.org/string-argv/-/string-argv-0.3.1.tgz", @@ -12715,6 +12956,26 @@ "node": ">=8" } }, + "node_modules/strip-ansi-cjs/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi/node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, "node_modules/strip-bom": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", @@ -12726,16 +12987,6 @@ "node": ">=4" } }, - "node_modules/strip-final-newline": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/strip-final-newline/-/strip-final-newline-2.0.0.tgz", - "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", - "license": "MIT", - "peer": true, - "engines": { - "node": ">=6" - } - }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -12750,15 +13001,18 @@ } }, "node_modules/supports-color": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", - "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "license": "MIT", - "dependencies": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz", + "integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==", + "license": "MIT", + "dependencies": { "has-flag": "^4.0.0" }, "engines": { - "node": ">=8" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/supports-color?sponsor=1" } }, "node_modules/supports-preserve-symlinks-flag": { @@ -12773,15 +13027,22 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/symbol-tree": { + "version": "3.2.4", + "resolved": "https://registry.npmjs.org/symbol-tree/-/symbol-tree-3.2.4.tgz", + "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", + "dev": true, + "license": "MIT" + }, "node_modules/synckit": { - "version": "0.9.2", - "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.2.tgz", - "integrity": "sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==", + "version": "0.10.3", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.10.3.tgz", + "integrity": "sha512-R1urvuyiTaWfeCggqEvpDJwAlDVdsT9NM+IP//Tk2x7qHCkSvBk/fwFgw/TLAHzZlrAnnazMcRw0ZD8HlYFTEQ==", "dev": true, "license": "MIT", "dependencies": { - "@pkgr/core": "^0.1.0", - "tslib": "^2.6.2" + "@pkgr/core": "^0.2.0", + "tslib": "^2.8.1" }, "engines": { "node": "^14.18.0 || >=16.0.0" @@ -12790,83 +13051,10 @@ "url": "https://opencollective.com/unts" } }, - "node_modules/temp": { - "version": "0.8.4", - "resolved": "https://registry.npmjs.org/temp/-/temp-0.8.4.tgz", - "integrity": "sha512-s0ZZzd0BzYv5tLSptZooSjK8oj6C+c19p7Vqta9+6NPOf7r+fxq0cJe6/oN4LTC79sy5NY8ucOJNgwsKCSbfqg==", - "license": "MIT", - "peer": true, - "dependencies": { - "rimraf": "~2.6.2" - }, - "engines": { - "node": ">=6.0.0" - } - }, - "node_modules/temp/node_modules/brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "license": "MIT", - "peer": true, - "dependencies": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, - "node_modules/temp/node_modules/glob": { - "version": "7.2.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", - "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", - "deprecated": "Glob versions prior to v9 are no longer supported", - "license": "ISC", - "peer": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/temp/node_modules/minimatch": { - "version": "3.1.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", - "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", - "license": "ISC", - "peer": true, - "dependencies": { - "brace-expansion": "^1.1.7" - }, - "engines": { - "node": "*" - } - }, - "node_modules/temp/node_modules/rimraf": { - "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", - "deprecated": "Rimraf versions prior to v4 are no longer supported", - "license": "ISC", - "peer": true, - "dependencies": { - "glob": "^7.1.3" - }, - "bin": { - "rimraf": "bin.js" - } - }, "node_modules/terser": { - "version": "5.36.0", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.36.0.tgz", - "integrity": "sha512-IYV9eNMuFAV4THUspIRXkLakHnV6XO7FEdtKjf/mDyrnqUg9LnlOn6/RwRvM9SZjR4GUq8Nk8zj67FzVARr74w==", + "version": "5.39.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.39.0.tgz", + "integrity": "sha512-LBAhFyLho16harJoWMg/nZsQYgTrg5jXOn2nCYjRUcZZEdE3qa2zb8QEDRUGVZBW4rlazf2fxkg8tztybTaqWw==", "license": "BSD-2-Clause", "dependencies": { "@jridgewell/source-map": "^0.3.3", @@ -12994,17 +13182,6 @@ "license": "MIT", "peer": true }, - "node_modules/through2": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz", - "integrity": "sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ==", - "license": "MIT", - "peer": true, - "dependencies": { - "readable-stream": "~2.3.6", - "xtend": "~4.0.1" - } - }, "node_modules/tiny-case": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/tiny-case/-/tiny-case-1.0.3.tgz", @@ -13013,11 +13190,37 @@ "license": "MIT", "peer": true }, + "node_modules/tiny-invariant": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.3.tgz", + "integrity": "sha512-+FbBPE1o9QAYvviau/qC5SE3caw21q3xkvWKBtja5vgqOWIHHJ3ioaq1VPfn/Szqctz2bU/oYeKd9/z5BL+PVg==", + "license": "MIT", + "peer": true + }, + "node_modules/tldts": { + "version": "6.1.85", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.85.tgz", + "integrity": "sha512-gBdZ1RjCSevRPFix/hpaUWeak2/RNUZB4/8frF1r5uYMHjFptkiT0JXIebWvgI/0ZHXvxaUDDJshiA0j6GdL3w==", + "dev": true, + "license": "MIT", + "dependencies": { + "tldts-core": "^6.1.85" + }, + "bin": { + "tldts": "bin/cli.js" + } + }, + "node_modules/tldts-core": { + "version": "6.1.85", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.85.tgz", + "integrity": "sha512-DTjUVvxckL1fIoPSb3KE7ISNtkWSawZdpfxGxwiIrZoO6EbHVDXXUIlIuWympPaeS+BLGyggozX/HTMsRAdsoA==", + "dev": true, + "license": "MIT" + }, "node_modules/tmp": { "version": "0.2.3", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.2.3.tgz", "integrity": "sha512-nZD7m9iCPC5g0pYmcaxogYKggSfLsdxl8of3Q/oIbqCqLLIO9IAF0GWjX1z9NZRHPiXv8Wex4yDCaZsgEw0Y8w==", - "dev": true, "license": "MIT", "engines": { "node": ">=14.14" @@ -13059,29 +13262,59 @@ "license": "MIT", "peer": true }, + "node_modules/tough-cookie": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-5.1.2.tgz", + "integrity": "sha512-FVDYdxtnj0G6Qm/DhNPSb8Ju59ULcup3tuJxkFb5K8Bv2pUXILbf0xZWU8PX8Ov19OXljbUyveOFwRMwkXzO+A==", + "dev": true, + "license": "BSD-3-Clause", + "dependencies": { + "tldts": "^6.1.32" + }, + "engines": { + "node": ">=16" + } + }, "node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==", - "license": "MIT" + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-5.1.0.tgz", + "integrity": "sha512-IUWnUK7ADYR5Sl1fZlO1INDUhVhatWl7BtJWsIhwJ0UAK7ilzzIa8uIqOO/aYVWHZPJkKbEL+362wrzoeRF7bw==", + "dev": true, + "license": "MIT", + "dependencies": { + "punycode": "^2.3.1" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/tr46/node_modules/punycode": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.3.1.tgz", + "integrity": "sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=6" + } }, "node_modules/ts-api-utils": { - "version": "1.4.0", - "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-1.4.0.tgz", - "integrity": "sha512-032cPxaEKwM+GT3vA5JXNzIaizx388rhsSW79vGRNGXfRRAdEAn2mvk36PvK5HnOchyWZ7afLEXqYCvPCrzuzQ==", + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.1.0.tgz", + "integrity": "sha512-CUgTZL1irw8u29bzrOD/nH85jqyc74D6SshFgujOIA7osm2Rz7dYH77agkx7H4FBNxDq7Cjf+IjaX/8zwFW+ZQ==", "dev": true, "license": "MIT", "engines": { - "node": ">=16" + "node": ">=18.12" }, "peerDependencies": { - "typescript": ">=4.2.0" + "typescript": ">=4.8.4" } }, "node_modules/ts-mocha": { - "version": "10.0.0", - "resolved": "https://registry.npmjs.org/ts-mocha/-/ts-mocha-10.0.0.tgz", - "integrity": "sha512-VRfgDO+iiuJFlNB18tzOfypJ21xn2xbuZyDvJvqpTbWgkAgD17ONGr8t+Tl8rcBtOBdjXp5e/Rk+d39f7XBHRw==", + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/ts-mocha/-/ts-mocha-10.1.0.tgz", + "integrity": "sha512-T0C0Xm3/WqCuF2tpa0GNGESTBoKZaiqdUP8guNv4ZY316AFXlyidnrzQ1LUrCT0Wb1i3J0zFTgOh/55Un44WdA==", "dev": true, "license": "MIT", "dependencies": { @@ -13097,7 +13330,7 @@ "tsconfig-paths": "^3.5.0" }, "peerDependencies": { - "mocha": "^3.X.X || ^4.X.X || ^5.X.X || ^6.X.X || ^7.X.X || ^8.X.X || ^9.X.X || ^10.X.X" + "mocha": "^3.X.X || ^4.X.X || ^5.X.X || ^6.X.X || ^7.X.X || ^8.X.X || ^9.X.X || ^10.X.X || ^11.X.X" } }, "node_modules/ts-mocha/node_modules/diff": { @@ -13110,6 +13343,19 @@ "node": ">=0.3.1" } }, + "node_modules/ts-mocha/node_modules/mkdirp": { + "version": "0.5.6", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.6.tgz", + "integrity": "sha512-FP+p8RB8OWpF3YZBCrP5gtADmtXApB5AMLn+vdyA+PyxCjrCs00mjyUozssO33cwDeT3wNGdLxJ5M//YqtHAJw==", + "dev": true, + "license": "MIT", + "dependencies": { + "minimist": "^1.2.6" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, "node_modules/ts-mocha/node_modules/ts-node": { "version": "7.0.1", "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-7.0.1.tgz", @@ -13187,16 +13433,6 @@ } } }, - "node_modules/ts-node/node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.3.1" - } - }, "node_modules/tsconfig-paths": { "version": "3.15.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.15.0.tgz", @@ -13226,19 +13462,19 @@ } }, "node_modules/tslib": { - "version": "2.8.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.0.tgz", - "integrity": "sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==", + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, "node_modules/tsx": { - "version": "4.19.2", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.2.tgz", - "integrity": "sha512-pOUl6Vo2LUq/bSa8S5q7b91cgNSjctn9ugq/+Mvow99qW6x/UZYwzxy/3NmqoT66eHYfCVvFvACC58UBPFf28g==", + "version": "4.19.3", + "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.3.tgz", + "integrity": "sha512-4H8vUNGNjQ4V2EOoGw005+c+dGuPSnhpPBPHBtsZdGZBk/iJb4kguGlPWaZTZ3q5nMtFOEsY0nRDlh9PJyd6SQ==", "dev": true, "license": "MIT", "dependencies": { - "esbuild": "~0.23.0", + "esbuild": "~0.25.0", "get-tsconfig": "^4.7.5" }, "bin": { @@ -13275,13 +13511,14 @@ } }, "node_modules/type-fest": { - "version": "0.20.2", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", - "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "version": "4.38.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-4.38.0.tgz", + "integrity": "sha512-2dBz5D5ycHIoliLYLi0Q2V7KRaDlH0uWIvmk7TYlAg5slqwiPv1ezJdZm1QEM0xgk29oYWMCbIG7E6gHpvChlg==", "dev": true, "license": "(MIT OR CC0-1.0)", + "peer": true, "engines": { - "node": ">=10" + "node": ">=16" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" @@ -13302,9 +13539,9 @@ } }, "node_modules/typescript": { - "version": "5.6.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", - "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", + "version": "5.8.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.2.tgz", + "integrity": "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==", "dev": true, "license": "Apache-2.0", "bin": { @@ -13316,9 +13553,9 @@ } }, "node_modules/ua-parser-js": { - "version": "0.7.39", - "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.39.tgz", - "integrity": "sha512-IZ6acm6RhQHNibSt7+c09hhvsKy9WUr4DVbeq9U8o71qxyYtJpQeDxQnMrVqnIFMLcQjHO0I9wgfO2vIahht4w==", + "version": "0.7.40", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.40.tgz", + "integrity": "sha512-us1E3K+3jJppDBa3Tl0L3MOJiGhe1C6P0+nIvQAFYbxlMAx0h81eOwLmU57xgqToduDDPx3y5QsdjPfDu+FgOQ==", "dev": true, "funding": [ { @@ -13350,9 +13587,9 @@ "license": "MIT" }, "node_modules/undici-types": { - "version": "6.19.8", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", - "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "version": "6.20.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz", + "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==", "license": "MIT" }, "node_modules/unicode-canonical-property-names-ecmascript": { @@ -13400,12 +13637,13 @@ } }, "node_modules/universalify": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz", - "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==", + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", + "integrity": "sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg==", + "dev": true, "license": "MIT", "engines": { - "node": ">= 10.0.0" + "node": ">= 4.0.0" } }, "node_modules/unpipe": { @@ -13418,9 +13656,9 @@ } }, "node_modules/update-browserslist-db": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.1.tgz", - "integrity": "sha512-R8UzCaa9Az+38REPiJ1tXlImTJXlVfgHZsglwBD/k6nj76ctsH1E3q4doGrukiLQd3sGQYu56r5+lo5r94l29A==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/update-browserslist-db/-/update-browserslist-db-1.1.3.tgz", + "integrity": "sha512-UxhIZQ+QInVdunkDAaiazvvT/+fXL5Osr0JZlJulepYu6Jd7qJtDZjlur0emRlT71EN3ScPoE7gvsuIKKNavKw==", "funding": [ { "type": "opencollective", @@ -13439,7 +13677,7 @@ "peer": true, "dependencies": { "escalade": "^3.2.0", - "picocolors": "^1.1.0" + "picocolors": "^1.1.1" }, "bin": { "update-browserslist-db": "cli.js" @@ -13487,13 +13725,6 @@ "license": "MIT", "peer": true }, - "node_modules/util-deprecate": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "license": "MIT", - "peer": true - }, "node_modules/utils-merge": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", @@ -13564,6 +13795,19 @@ "node": ">=0.10.0" } }, + "node_modules/w3c-xmlserializer": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/w3c-xmlserializer/-/w3c-xmlserializer-5.0.0.tgz", + "integrity": "sha512-o8qghlI8NZHU1lLPrpi2+Uq7abh4GGPpYANlalzWxyWteJOCsr/P+oPBA49TOLu5FTZO4d3F9MnWJfiMo4BkmA==", + "dev": true, + "license": "MIT", + "dependencies": { + "xml-name-validator": "^5.0.0" + }, + "engines": { + "node": ">=18" + } + }, "node_modules/walker": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/walker/-/walker-1.0.8.tgz", @@ -13575,10 +13819,40 @@ } }, "node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==", - "license": "BSD-2-Clause" + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-7.0.0.tgz", + "integrity": "sha512-VwddBukDzu71offAQR975unBIGqfKZpM+8ZX6ySk8nYhVoo5CYaZyzt3YBvYtRtO+aoGlqxPg/B87NGVZ/fu6g==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + } + }, + "node_modules/whatwg-encoding": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/whatwg-encoding/-/whatwg-encoding-3.1.1.tgz", + "integrity": "sha512-6qN4hJdMwfYBtE3YBTTHhoeuUrDBPZmbQaxWAqSALV/MeEnR5z1xd8UKud2RAkFoPkmB+hli1TZSnyi84xz1vQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "iconv-lite": "0.6.3" + }, + "engines": { + "node": ">=18" + } + }, + "node_modules/whatwg-encoding/node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "dev": true, + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } }, "node_modules/whatwg-fetch": { "version": "3.6.20", @@ -13587,14 +13861,28 @@ "license": "MIT", "peer": true }, + "node_modules/whatwg-mimetype": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/whatwg-mimetype/-/whatwg-mimetype-4.0.0.tgz", + "integrity": "sha512-QaKxh0eNIi2mE9p2vEdzfagOKHCcj1pJ56EEHGQOVxp8r9/iszLUUV7v89x9O1p/T+NlTM5W7jW6+cz4Fq1YVg==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">=18" + } + }, "node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-14.2.0.tgz", + "integrity": "sha512-De72GdQZzNTUBBChsXueQUnPKDkg/5A5zp7pFDuQAj5UFoENpiACU0wlCvzpAGnTkj++ihpKwKyYewn/XNUbKw==", + "dev": true, "license": "MIT", "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" + "tr46": "^5.1.0", + "webidl-conversions": "^7.0.0" + }, + "engines": { + "node": ">=18" } }, "node_modules/whatwg-url-without-unicode": { @@ -13657,6 +13945,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, "license": "ISC", "dependencies": { "isexe": "^2.0.0" @@ -13686,17 +13975,19 @@ "license": "Apache-2.0" }, "node_modules/wrap-ansi": { - "version": "7.0.0", - "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz", - "integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==", + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz", + "integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==", + "dev": true, "license": "MIT", + "peer": true, "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" + "ansi-styles": "^6.1.0", + "string-width": "^5.0.1", + "strip-ansi": "^7.0.1" }, "engines": { - "node": ">=10" + "node": ">=12" }, "funding": { "url": "https://github.com/chalk/wrap-ansi?sponsor=1" @@ -13722,6 +14013,78 @@ "url": "https://github.com/chalk/wrap-ansi?sponsor=1" } }, + "node_modules/wrap-ansi/node_modules/ansi-regex": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz", + "integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-regex?sponsor=1" + } + }, + "node_modules/wrap-ansi/node_modules/ansi-styles": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz", + "integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==", + "dev": true, + "license": "MIT", + "peer": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/wrap-ansi/node_modules/emoji-regex": { + "version": "9.2.2", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz", + "integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==", + "dev": true, + "license": "MIT", + "peer": true + }, + "node_modules/wrap-ansi/node_modules/string-width": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", + "integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "eastasianwidth": "^0.2.0", + "emoji-regex": "^9.2.2", + "strip-ansi": "^7.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/wrap-ansi/node_modules/strip-ansi": { + "version": "7.1.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", + "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", + "dev": true, + "license": "MIT", + "peer": true, + "dependencies": { + "ansi-regex": "^6.0.1" + }, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/chalk/strip-ansi?sponsor=1" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -13742,14 +14105,43 @@ "node": "^12.13.0 || ^14.15.0 || >=16.0.0" } }, + "node_modules/write-file-atomic/node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==", + "license": "ISC", + "peer": true + }, "node_modules/ws": { - "version": "6.2.3", - "resolved": "https://registry.npmjs.org/ws/-/ws-6.2.3.tgz", - "integrity": "sha512-jmTjYU0j60B+vHey6TfR3Z7RD61z/hmxBS3VMSGIrroOWXQEneK1zNuotOUrGyBHQj0yrpsLHPWtigEFd13ndA==", + "version": "8.18.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.18.1.tgz", + "integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==", + "dev": true, "license": "MIT", - "peer": true, - "dependencies": { - "async-limiter": "~1.0.0" + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + }, + "node_modules/xml-name-validator": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", + "integrity": "sha512-EvGK8EJ3DhaHfbRlETOWAS5pO9MZITeauHKJyb8wyajUfQUenkIg2MvLDTZ4T/TgIcm3HU0TFBgWWboAZ30UHg==", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18" } }, "node_modules/xmlbuilder": { @@ -13763,15 +14155,12 @@ "node": ">=8.0" } }, - "node_modules/xtend": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", - "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==", - "license": "MIT", - "peer": true, - "engines": { - "node": ">=0.4" - } + "node_modules/xmlchars": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/xmlchars/-/xmlchars-2.2.0.tgz", + "integrity": "sha512-JZnDKK8B0RCDw84FNdDAIpZK+JuJw+s7Lz8nksI7SIuU3UXJJslUthsi+uWBUYOwPFwW7W7PRLRfUKpxjtjFCw==", + "dev": true, + "license": "MIT" }, "node_modules/y18n": { "version": "5.0.8", @@ -13790,9 +14179,9 @@ "peer": true }, "node_modules/yaml": { - "version": "2.6.0", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.6.0.tgz", - "integrity": "sha512-a6ae//JvKDEra2kdi1qzCyrJW/WZCgFi8ydDV+eXExl95t+5R+ijnqHJbz9tmMh8FUjx3iv2fCQ4dclAQlO2UQ==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.7.1.tgz", + "integrity": "sha512-10ULxpnOCQXxJvBgxsn9ptjq6uviG/htZKk9veJGhlqn3w/DxQ631zFF+nlQXLwmImeS5amR2dl2U8sg6U9jsQ==", "dev": true, "license": "ISC", "peer": true, diff --git a/package.json b/package.json index e4de370ff..83b20737b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "9.3.1", + "version": "9.3.2", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 9d75aaae0..c86b7049c 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -182,7 +182,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '9.3.1'; + return '9.3.2'; }, getVersion(): string { return this.version; diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index db9328599..834242fdd 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -1977,8 +1977,20 @@ export class PubNubCore< * @param parameters - List of channels and groups where `join` event should be sent. */ private join(parameters: { channels?: string[]; groups?: string[] }) { - if (process.env.PRESENCE_MODULE !== 'disabled') this.presenceEventEngine?.join(parameters); - else throw new Error('Announce UUID Presence error: presence module disabled'); + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) this.presenceEventEngine.join(parameters); + else { + this.heartbeat( + { + channels: parameters.channels, + channelGroups: parameters.groups, + ...(this._configuration.maintainPresenceState && { state: this.presenceState }), + heartbeat: this._configuration.getPresenceTimeout(), + }, + () => {}, + ); + } + } else throw new Error('Announce UUID Presence error: presence module disabled'); } // endregion @@ -1991,18 +2003,24 @@ export class PubNubCore< * @param parameters - List of channels and groups where `leave` event should be sent. */ private leave(parameters: { channels?: string[]; groups?: string[] }) { - if (process.env.PRESENCE_MODULE !== 'disabled') this.presenceEventEngine?.leave(parameters); - else throw new Error('Announce UUID Leave error: presence module disabled'); + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) this.presenceEventEngine?.leave(parameters); + else this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => {}); + } else throw new Error('Announce UUID Leave error: presence module disabled'); } /** * Announce user `leave` on all subscribed channels. * * @internal + * + * @param parameters - List of channels and groups where `leave` event should be sent. */ - private leaveAll() { - if (process.env.PRESENCE_MODULE !== 'disabled') this.presenceEventEngine?.leaveAll(); - else throw new Error('Announce UUID Leave error: presence module disabled'); + private leaveAll(parameters: { channels?: string[]; groups?: string[] }) { + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) this.presenceEventEngine.leaveAll(); + else this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => {}); + } else throw new Error('Announce UUID Leave error: presence module disabled'); } // endregion // endregion diff --git a/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts b/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts index 934dccd75..98ad986d8 100644 --- a/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts +++ b/src/crypto/modules/NodeCryptoModule/aesCbcCryptor.ts @@ -101,7 +101,7 @@ export default class AesCbcCryptor implements ICryptor { while (data !== null) { if (data) { - const bChunk = Buffer.from(data); + const bChunk = typeof data === 'string' ? Buffer.from(data) : data; const sliceLen = stream.metadataLength - bIv.byteLength; if (bChunk.byteLength < sliceLen) { diff --git a/src/event-engine/dispatcher.ts b/src/event-engine/dispatcher.ts index 989bb8ce1..7abf9b130 100644 --- a/src/event-engine/dispatcher.ts +++ b/src/event-engine/dispatcher.ts @@ -25,7 +25,7 @@ export type Dependencies = { ) => Promise; join?: (parameters: { channels?: string[]; groups?: string[] }) => void; leave?: (parameters: { channels?: string[]; groups?: string[] }) => void; - leaveAll?: () => void; + leaveAll?: (parameters: { channels?: string[]; groups?: string[] }) => void; presenceState: Record; config: PrivateClientConfiguration; diff --git a/src/event-engine/index.ts b/src/event-engine/index.ts index 0dc1dedbe..3305063a2 100644 --- a/src/event-engine/index.ts +++ b/src/event-engine/index.ts @@ -125,6 +125,9 @@ export class EventEngine { } unsubscribeAll(): void { + const channelGroups = this.getSubscribedChannels(); + const channels = this.getSubscribedChannels(); + this.channels = []; this.groups = []; @@ -134,9 +137,7 @@ export class EventEngine { }); } this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0))); - if (this.dependencies.leaveAll) { - this.dependencies.leaveAll(); - } + if (this.dependencies.leaveAll) this.dependencies.leaveAll({ channels, groups: channelGroups }); } reconnect({ timetoken, region }: { timetoken?: string; region?: number }): void { @@ -144,10 +145,12 @@ export class EventEngine { } disconnect(): void { + const channelGroups = this.getSubscribedChannels(); + const channels = this.getSubscribedChannels(); + this.engine.transition(events.disconnect()); - if (this.dependencies.leaveAll) { - this.dependencies.leaveAll(); - } + + if (this.dependencies.leaveAll) this.dependencies.leaveAll({ channels, groups: channelGroups }); } getSubscribedChannels(): string[] { diff --git a/src/file/modules/node.ts b/src/file/modules/node.ts index 4cd56e8d3..e5fe996cb 100644 --- a/src/file/modules/node.ts +++ b/src/file/modules/node.ts @@ -131,7 +131,7 @@ export default class PubNubFile implements PubNubFileInterface { if (stream && stream instanceof Readable) { fileData = stream; - if (stream instanceof fs.ReadStream && !(stream.path instanceof Buffer)) { + if (stream instanceof fs.ReadStream && typeof stream.path === 'string') { fileName = basename(stream.path); contentLength = fs.statSync(stream.path).size; } @@ -167,7 +167,7 @@ export default class PubNubFile implements PubNubFileInterface { * @returns Asynchronous results of conversion to the {@link Buffer}. */ async toBuffer(): Promise { - if (this.data instanceof Buffer) return this.data; + if (!(this.data instanceof Readable)) return this.data; const stream = this.data; return new Promise((resolve, reject) => { diff --git a/test/integration/endpoints/message_actions.test.ts b/test/integration/endpoints/message_actions.test.ts index ab3bcf4a9..0e414f806 100644 --- a/test/integration/endpoints/message_actions.test.ts +++ b/test/integration/endpoints/message_actions.test.ts @@ -23,7 +23,7 @@ type MessageAction = MessageActions.AddMessageActionParameters['action']; */ function publishMessages(client: PubNub, count: number, channel: string, completion: (timetokens: string[]) => void) { let publishCompleted = 0; - let timetokens: string[] = []; + const timetokens: string[] = []; const publish = (messageIdx: number) => { const message = { messageIdx, time: Date.now() }; @@ -77,8 +77,8 @@ function addActions( PubNub.generateUUID(), PubNub.generateUUID(), ]; - let actionsToAdd: { messageTimetoken: string; action: MessageAction }[] = []; - let timetokens: string[] = []; + const actionsToAdd: { messageTimetoken: string; action: MessageAction }[] = []; + const timetokens: string[] = []; let actionsAdded = 0; for (let messageIdx = 0; messageIdx < messageTimetokens.length; messageIdx += 1) { @@ -114,7 +114,9 @@ function addActions( if (actionsAdded < actionsToAdd.length) { addAction(actionsAdded); } else if (actionsAdded === actionsToAdd.length) { - completion(timetokens.sort((left, right) => parseInt(left, 10) - parseInt(right, 10))); + setTimeout(() => { + completion(timetokens.sort((left, right) => parseInt(left, 10) - parseInt(right, 10))); + }, 500); } }); }; @@ -168,7 +170,7 @@ describe('message actions endpoints', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing Action"); + assert.equal(err.status.message, 'Missing Action'); done(); } catch (error) { done(error); @@ -194,7 +196,7 @@ describe('message actions endpoints', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing Action.type"); + assert.equal(err.status.message, 'Missing Action.type'); done(); } catch (error) { done(error); @@ -219,7 +221,7 @@ describe('message actions endpoints', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Action.type value exceed maximum length of 15"); + assert.equal(err.status.message, 'Action.type value exceed maximum length of 15'); done(); } catch (error) { done(error); @@ -245,7 +247,7 @@ describe('message actions endpoints', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing Action.value"); + assert.equal(err.status.message, 'Missing Action.value'); done(); } catch (error) { done(error); @@ -270,7 +272,7 @@ describe('message actions endpoints', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing message timetoken"); + assert.equal(err.status.message, 'Missing message timetoken'); done(); } catch (error) { done(error); @@ -295,7 +297,7 @@ describe('message actions endpoints', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing message channel"); + assert.equal(err.status.message, 'Missing message channel'); done(); } catch (error) { done(error); @@ -423,7 +425,7 @@ describe('message actions endpoints', () => { assert.equal(messageActionEvent.data.uuid, pubnub.getUUID()); assert.equal(messageActionEvent.data.messageTimetoken, messageTimetoken); assert(messageActionEvent.data.actionTimetoken); - assert.equal(messageActionEvent.event, "added"); + assert.equal(messageActionEvent.event, 'added'); pubnub.unsubscribeAll(); done(); @@ -455,7 +457,7 @@ describe('message actions endpoints', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing message timetoken"); + assert.equal(err.status.message, 'Missing message timetoken'); done(); } catch (error) { @@ -480,7 +482,7 @@ describe('message actions endpoints', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing action timetoken"); + assert.equal(err.status.message, 'Missing action timetoken'); done(); } catch (error) { @@ -505,7 +507,7 @@ describe('message actions endpoints', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing message action channel"); + assert.equal(err.status.message, 'Missing message action channel'); done(); } catch (error) { @@ -607,7 +609,7 @@ describe('message actions endpoints', () => { assert.equal(messageActionEvent.data.uuid, pubnub.getUUID()); assert.equal(messageActionEvent.data.messageTimetoken, messageTimetokens[0]); assert.equal(messageActionEvent.data.actionTimetoken, actionTimetokens[0]); - assert.equal(messageActionEvent.event, "removed"); + assert.equal(messageActionEvent.event, 'removed'); pubnub.unsubscribeAll(); done(); @@ -633,7 +635,7 @@ describe('message actions endpoints', () => { pubnub.getMessageActions({}).catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing message channel"); + assert.equal(err.status.message, 'Missing message channel'); done(); } catch (error) { From bee879411aafb0571ddf433c6e1edfbaf022591e Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 10 Apr 2025 15:53:07 +0300 Subject: [PATCH 46/49] Compress publish POST body (#450) feat(publish): compress publish POST body Compress the published payload if sent by POST. feat(request): explicit `Accept-Encoding` header Explicitly add `gzip, deflate` to the `Accept-Encoding` header. --- .pubnub.yml | 13 ++++- CHANGELOG.md | 7 +++ README.md | 4 +- dist/web/pubnub.js | 58 ++++++++++++++----- dist/web/pubnub.min.js | 4 +- dist/web/pubnub.worker.js | 1 + dist/web/pubnub.worker.min.js | 2 +- lib/core/components/configuration.js | 2 +- lib/core/components/request.js | 6 +- .../endpoints/access_manager/grant_token.js | 3 +- .../endpoints/actions/add_message_action.js | 3 +- .../file_upload/generate_upload_url.js | 3 +- lib/core/endpoints/objects/channel/set.js | 5 +- lib/core/endpoints/objects/uuid/set.js | 5 +- lib/core/endpoints/publish.js | 9 +-- lib/core/endpoints/subscribe.js | 3 +- lib/transport/node-transport.js | 7 ++- lib/transport/react-native-transport.js | 16 ++++- lib/types/index.d.ts | 4 ++ package-lock.json | 11 +++- package.json | 3 +- src/core/components/configuration.ts | 2 +- src/core/components/request.ts | 10 +++- .../endpoints/access_manager/grant_token.ts | 2 +- .../endpoints/actions/add_message_action.ts | 2 +- .../file_upload/generate_upload_url.ts | 2 +- src/core/endpoints/objects/channel/set.ts | 4 +- src/core/endpoints/objects/uuid/set.ts | 4 +- src/core/endpoints/publish.ts | 8 ++- src/core/endpoints/subscribe.ts | 2 +- src/core/types/transport-request.ts | 5 ++ src/transport/node-transport.ts | 6 +- src/transport/react-native-transport.ts | 17 +++++- .../subscription-worker.ts | 1 + src/transport/web-transport.ts | 21 ++++++- test/integration/endpoints/publish.test.ts | 35 ++++++++++- 36 files changed, 225 insertions(+), 65 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index 2025b5281..0d87323d2 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2025-04-10 + version: v9.4.0 + changes: + - type: feature + text: "Compress the published payload if sent by POST." + - type: feature + text: "Explicitly add `gzip, deflate` to the `Accept-Encoding` header." - date: 2025-03-31 version: v9.3.2 changes: @@ -1202,7 +1209,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '9.3.2' +version: '9.4.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1218,7 +1225,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v9.3.2.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.4.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1889,7 +1896,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v9.3.2/pubnub.9.3.2.js + location: https://github.com/pubnub/javascript/releases/download/v9.4.0/pubnub.9.4.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b6d19c0a..386910969 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## v9.4.0 +April 10 2025 + +#### Added +- Compress the published payload if sent by POST. +- Explicitly add `gzip, deflate` to the `Accept-Encoding` header. + ## v9.3.2 March 31 2025 diff --git a/README.md b/README.md index 29b144373..2c423ba86 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.2.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.3.2.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.4.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.4.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 637676857..09f25cfcb 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3939,7 +3939,7 @@ return base.PubNubFile; }, get version() { - return '9.3.2'; + return '9.4.0'; }, getVersion() { return this.version; @@ -4604,8 +4604,20 @@ body = formData; } // Handle regular body payload (if passed). - else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) - body = req.body; + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) { + // Compressing body if browser has native support. + if (req.compressible && typeof CompressionStream !== 'undefined') { + const bodyStream = new ReadableStream({ + start(controller) { + controller.enqueue(typeof req.body === 'string' ? WebTransport.encoder.encode(req.body) : req.body); + controller.close(); + }, + }); + body = yield new Response(bodyStream.pipeThrough(new CompressionStream('deflate'))).arrayBuffer(); + } + else + body = req.body; + } if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) path = `${path}?${queryStringFromObject(req.queryParameters)}`; return { @@ -4683,6 +4695,12 @@ return fetch; } } + /** + * Request body decoder. + * + * @internal + */ + WebTransport.encoder = new TextEncoder(); /** * Service {@link ArrayBuffer} response decoder. * @@ -6092,12 +6110,13 @@ * @returns Request object which can be processed using platform-specific requirements. */ request() { - var _a, _b, _c, _d; + var _a, _b, _c, _d, _e, _f; const request = { method: (_b = (_a = this.params) === null || _a === void 0 ? void 0 : _a.method) !== null && _b !== void 0 ? _b : TransportMethod.GET, path: this.path, queryParameters: this.queryParameters, cancellable: (_d = (_c = this.params) === null || _c === void 0 ? void 0 : _c.cancellable) !== null && _d !== void 0 ? _d : false, + compressible: (_f = (_e = this.params) === null || _e === void 0 ? void 0 : _e.compressible) !== null && _f !== void 0 ? _f : false, timeout: 10, identifier: this.requestIdentifier, }; @@ -6121,7 +6140,8 @@ * @returns Key/value headers which should be used with request. */ get headers() { - return undefined; + var _a, _b; + return Object.assign({ 'Accept-Encoding': 'gzip, deflate' }, (((_b = (_a = this.params) === null || _a === void 0 ? void 0 : _a.compressible) !== null && _b !== void 0 ? _b : false) ? { 'Content-Encoding': 'deflate' } : {})); } /** * Target REST API endpoint request path getter. @@ -6595,7 +6615,8 @@ }); } get headers() { - return { accept: 'text/javascript' }; + var _a; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { accept: 'text/javascript' }); } // -------------------------------------------------------- // ------------------ Envelope parsing -------------------- @@ -8705,11 +8726,11 @@ */ constructor(parameters) { var _a; - var _b; - super({ method: parameters.sendByPost ? TransportMethod.POST : TransportMethod.GET }); + const sendByPost = (_a = parameters.sendByPost) !== null && _a !== void 0 ? _a : SEND_BY_POST; + super({ method: sendByPost ? TransportMethod.POST : TransportMethod.GET, compressible: sendByPost }); this.parameters = parameters; // Apply default request parameters. - (_a = (_b = this.parameters).sendByPost) !== null && _a !== void 0 ? _a : (_b.sendByPost = SEND_BY_POST); + this.parameters.sendByPost = sendByPost; } operation() { return RequestOperation$1.PNPublishOperation; @@ -8749,9 +8770,10 @@ return query; } get headers() { + var _a; if (!this.parameters.sendByPost) return undefined; - return { 'Content-Type': 'application/json' }; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'Content-Type': 'application/json' }); } get body() { return this.prepareMessagePayload(this.parameters.message); @@ -9734,7 +9756,8 @@ return `/v1/message-actions/${subscribeKey}/channel/${encodeString(channel)}/message/${messageTimetoken}`; } get headers() { - return { 'Content-Type': 'application/json' }; + var _a; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'Content-Type': 'application/json' }); } get body() { return JSON.stringify(this.parameters.action); @@ -10028,7 +10051,8 @@ return `/v1/files/${subscribeKey}/channels/${encodeString(channel)}/generate-upload-url`; } get headers() { - return { 'Content-Type': 'application/json' }; + var _a; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'Content-Type': 'application/json' }); } get body() { return JSON.stringify({ name: this.parameters.name }); @@ -11860,11 +11884,12 @@ return 'Data cannot be empty'; } get headers() { + var _a; if (this.parameters.ifMatchesEtag) { - return { 'If-Match': this.parameters.ifMatchesEtag }; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'If-Match': this.parameters.ifMatchesEtag }); } else { - return undefined; + return super.headers; } } get path() { @@ -12232,11 +12257,12 @@ return 'Data cannot be empty'; } get headers() { + var _a; if (this.parameters.ifMatchesEtag) { - return { 'If-Match': this.parameters.ifMatchesEtag }; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'If-Match': this.parameters.ifMatchesEtag }); } else { - return undefined; + return super.headers; } } get path() { diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 9fb072609..108184ba4 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var k=new Uint8Array(S),E=0;for(r=0;r=0;)f(O,d);else f(O,d);return String.fromCharCode.apply(null,O);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],k=e[i+14],E=e[i+15],O=t(O=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,O,N,P,o,12,u[1]),P=t(P,C,O,N,l,17,u[2]),N=t(N,P,C,O,h,22,u[3]);O=t(O,N,P,C,d,7,u[4]),C=t(C,O,N,P,p,12,u[5]),P=t(P,C,O,N,g,17,u[6]),N=t(N,P,C,O,y,22,u[7]),O=t(O,N,P,C,f,7,u[8]),C=t(C,O,N,P,b,12,u[9]),P=t(P,C,O,N,m,17,u[10]),N=t(N,P,C,O,v,22,u[11]),O=t(O,N,P,C,w,7,u[12]),C=t(C,O,N,P,S,12,u[13]),P=t(P,C,O,N,k,17,u[14]),O=n(O,N=t(N,P,C,O,E,22,u[15]),P,C,o,5,u[16]),C=n(C,O,N,P,g,9,u[17]),P=n(P,C,O,N,v,14,u[18]),N=n(N,P,C,O,c,20,u[19]),O=n(O,N,P,C,p,5,u[20]),C=n(C,O,N,P,m,9,u[21]),P=n(P,C,O,N,E,14,u[22]),N=n(N,P,C,O,d,20,u[23]),O=n(O,N,P,C,b,5,u[24]),C=n(C,O,N,P,k,9,u[25]),P=n(P,C,O,N,h,14,u[26]),N=n(N,P,C,O,f,20,u[27]),O=n(O,N,P,C,S,5,u[28]),C=n(C,O,N,P,l,9,u[29]),P=n(P,C,O,N,y,14,u[30]),O=s(O,N=n(N,P,C,O,w,20,u[31]),P,C,p,4,u[32]),C=s(C,O,N,P,f,11,u[33]),P=s(P,C,O,N,v,16,u[34]),N=s(N,P,C,O,k,23,u[35]),O=s(O,N,P,C,o,4,u[36]),C=s(C,O,N,P,d,11,u[37]),P=s(P,C,O,N,y,16,u[38]),N=s(N,P,C,O,m,23,u[39]),O=s(O,N,P,C,S,4,u[40]),C=s(C,O,N,P,c,11,u[41]),P=s(P,C,O,N,h,16,u[42]),N=s(N,P,C,O,g,23,u[43]),O=s(O,N,P,C,b,4,u[44]),C=s(C,O,N,P,w,11,u[45]),P=s(P,C,O,N,E,16,u[46]),O=r(O,N=s(N,P,C,O,l,23,u[47]),P,C,c,6,u[48]),C=r(C,O,N,P,y,10,u[49]),P=r(P,C,O,N,k,15,u[50]),N=r(N,P,C,O,p,21,u[51]),O=r(O,N,P,C,w,6,u[52]),C=r(C,O,N,P,h,10,u[53]),P=r(P,C,O,N,m,15,u[54]),N=r(N,P,C,O,o,21,u[55]),O=r(O,N,P,C,f,6,u[56]),C=r(C,O,N,P,E,10,u[57]),P=r(P,C,O,N,g,15,u[58]),N=r(N,P,C,O,S,21,u[59]),O=r(O,N,P,C,d,6,u[60]),C=r(C,O,N,P,v,10,u[61]),P=r(P,C,O,N,l,15,u[62]),N=r(N,P,C,O,b,21,u[63]);a[0]=a[0]+O|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],k=257*p[b]^16843008*b;i[y]=k<<24|k>>>8,a[y]=k<<16|k>>>16,o[y]=k<<8|k>>>24,c[y]=k,k=16843009*w^65537*v^257*m^16843008*y,u[b]=k<<24|k>>>8,l[b]=k<<16|k>>>16,h[b]=k<<8|k>>>24,d[b]=k,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var E=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=E[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var k=t(S);class E{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=k,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:E.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return E.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(E.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=E.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new E({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new E({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===A.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=A.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=A.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===A.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof j)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=A.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class A{static from(e,t){if(e!==A.LEGACY_IDENTIFIER)return new j(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==A.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>A.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+A.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new j(this.decoder.decode(s),a)}}A.SENTINEL="PNED",A.LEGACY_IDENTIFIER="",A.IDENTIFIER_LENGTH=4,A.VERSION=1,A.MAX_VERSION=1,A.decoder=new TextDecoder;class j{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return A.VERSION}get length(){return A.SENTINEL.length+1+A.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(A.SENTINEL)),e+=A.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=A.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}j.IDENTIFIER_LENGTH=4,j.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?T(o):o})),s}const F=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,k=5,E=!1,O=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(E=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(O=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(k=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:E,maximumCacheSize:O,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:k})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.3.2"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer)&&(t=e.body);var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s;const r={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,timeout:10,identifier:this.requestIdentifier},i=this.headers;if(i&&(r.headers=i),r.method===G.POST||r.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(r.formData=t),e&&(r.body=e)}return r}get headers(){}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){return{accept:"text/javascript"}}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),ke=ge("RECONNECT",(()=>({}))),Ee=ge("DISCONNECT",(()=>({}))),Oe=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Pe=ge("LEFT_ALL",(()=>({}))),Ne=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),Ae=ge("HEARTBEAT_GIVEUP",(()=>({}))),je=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Te=ye("EMIT_STATUS",(e=>e)),Fe=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Fe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(je())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(Ae());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Te.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Oe.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Pe.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Fe())),De.onExit((()=>Fe.cancel)),De.on(je.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(ke.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(Ee.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(Ee.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(Ae.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Oe.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(Ee.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Oe.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Oe(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Pe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class kt{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class Et extends se{constructor(e){var t,n;super({method:e.sendByPost?G.POST:G.GET}),this.parameters=e,null!==(t=(n=this.parameters).sendByPost)&&void 0!==t||(n.sendByPost=false)}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){if(this.parameters.sendByPost)return{"Content-Type":"application/json"}}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ot extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Pt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Nt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class At extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class jt extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Tt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){return{"Content-Type":"application/json"}}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class En extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class On extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){return this.parameters.ifMatchesEtag?{"If-Match":this.parameters.ifMatchesEtag}:void 0}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Pn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new On(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new En(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Nn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class An{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Pn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new kt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=An.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ot(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new jt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new At(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new At(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){this.presenceEventEngine?this.presenceEventEngine.join(e):this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}leave(e){var t;this.presenceEventEngine?null===(t=this.presenceEventEngine)||void 0===t||t.leave(e):this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}leaveAll(e){this.presenceEventEngine?this.presenceEventEngine.leaveAll():this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Nn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}An.decoder=new TextDecoder,An.OPERATIONS=ie,An.CATEGORIES=h,An.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,An.LinearRetryPolicy=Be.LinearRetryPolicy;class jn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends An{constructor(e){var t;const n=F(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new E({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new jn((e=>T(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var O=new Uint8Array(S),k=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],O=e[i+14],k=e[i+15],E=t(E=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,E,N,P,o,12,u[1]),P=t(P,C,E,N,l,17,u[2]),N=t(N,P,C,E,h,22,u[3]);E=t(E,N,P,C,d,7,u[4]),C=t(C,E,N,P,p,12,u[5]),P=t(P,C,E,N,g,17,u[6]),N=t(N,P,C,E,y,22,u[7]),E=t(E,N,P,C,f,7,u[8]),C=t(C,E,N,P,b,12,u[9]),P=t(P,C,E,N,m,17,u[10]),N=t(N,P,C,E,v,22,u[11]),E=t(E,N,P,C,w,7,u[12]),C=t(C,E,N,P,S,12,u[13]),P=t(P,C,E,N,O,17,u[14]),E=n(E,N=t(N,P,C,E,k,22,u[15]),P,C,o,5,u[16]),C=n(C,E,N,P,g,9,u[17]),P=n(P,C,E,N,v,14,u[18]),N=n(N,P,C,E,c,20,u[19]),E=n(E,N,P,C,p,5,u[20]),C=n(C,E,N,P,m,9,u[21]),P=n(P,C,E,N,k,14,u[22]),N=n(N,P,C,E,d,20,u[23]),E=n(E,N,P,C,b,5,u[24]),C=n(C,E,N,P,O,9,u[25]),P=n(P,C,E,N,h,14,u[26]),N=n(N,P,C,E,f,20,u[27]),E=n(E,N,P,C,S,5,u[28]),C=n(C,E,N,P,l,9,u[29]),P=n(P,C,E,N,y,14,u[30]),E=s(E,N=n(N,P,C,E,w,20,u[31]),P,C,p,4,u[32]),C=s(C,E,N,P,f,11,u[33]),P=s(P,C,E,N,v,16,u[34]),N=s(N,P,C,E,O,23,u[35]),E=s(E,N,P,C,o,4,u[36]),C=s(C,E,N,P,d,11,u[37]),P=s(P,C,E,N,y,16,u[38]),N=s(N,P,C,E,m,23,u[39]),E=s(E,N,P,C,S,4,u[40]),C=s(C,E,N,P,c,11,u[41]),P=s(P,C,E,N,h,16,u[42]),N=s(N,P,C,E,g,23,u[43]),E=s(E,N,P,C,b,4,u[44]),C=s(C,E,N,P,w,11,u[45]),P=s(P,C,E,N,k,16,u[46]),E=r(E,N=s(N,P,C,E,l,23,u[47]),P,C,c,6,u[48]),C=r(C,E,N,P,y,10,u[49]),P=r(P,C,E,N,O,15,u[50]),N=r(N,P,C,E,p,21,u[51]),E=r(E,N,P,C,w,6,u[52]),C=r(C,E,N,P,h,10,u[53]),P=r(P,C,E,N,m,15,u[54]),N=r(N,P,C,E,o,21,u[55]),E=r(E,N,P,C,f,6,u[56]),C=r(C,E,N,P,k,10,u[57]),P=r(P,C,E,N,g,15,u[58]),N=r(N,P,C,E,S,21,u[59]),E=r(E,N,P,C,d,6,u[60]),C=r(C,E,N,P,v,10,u[61]),P=r(P,C,E,N,l,15,u[62]),N=r(N,P,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],O=257*p[b]^16843008*b;i[y]=O<<24|O>>>8,a[y]=O<<16|O>>>16,o[y]=O<<8|O>>>24,c[y]=O,O=16843009*w^65537*v^257*m^16843008*y,u[b]=O<<24|O>>>8,l[b]=O<<16|O>>>16,h[b]=O<<8|O>>>24,d[b]=O,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var k=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=k[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var O=t(S);class k{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=O,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:k.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return k.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(k.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=k.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new k({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new k({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=j.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=j.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===j.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=j.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class j{static from(e,t){if(e!==j.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==j.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>j.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+j.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(s),a)}}j.SENTINEL="PNED",j.LEGACY_IDENTIFIER="",j.IDENTIFIER_LENGTH=4,j.VERSION=1,j.MAX_VERSION=1,j.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return j.VERSION}get length(){return j.SENTINEL.length+1+j.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(j.SENTINEL)),e+=j.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=j.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?T(o):o})),s}const F=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,O=5,k=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(O=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:O})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.4.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else if(e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer))if(e.compressible&&"undefined"!=typeof CompressionStream){const n=new ReadableStream({start(t){t.enqueue("string"==typeof e.body?z.encoder.encode(e.body):e.body),t.close()}});t=yield new Response(n.pipeThrough(new CompressionStream("deflate"))).arrayBuffer()}else t=e.body;var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.encoder=new TextEncoder,z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s,r,i;const a={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,compressible:null!==(i=null===(r=this.params)||void 0===r?void 0:r.compressible)&&void 0!==i&&i,timeout:10,identifier:this.requestIdentifier},o=this.headers;if(o&&(a.headers=o),a.method===G.POST||a.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(a.formData=t),e&&(a.body=e)}return a}get headers(){var e,t;return Object.assign({"Accept-Encoding":"gzip, deflate"},null!==(t=null===(e=this.params)||void 0===e?void 0:e.compressible)&&void 0!==t&&t?{"Content-Encoding":"deflate"}:{})}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{accept:"text/javascript"})}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),Oe=ge("RECONNECT",(()=>({}))),ke=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Pe=ge("LEFT_ALL",(()=>({}))),Ne=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),je=ge("HEARTBEAT_GIVEUP",(()=>({}))),Ae=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Te=ye("EMIT_STATUS",(e=>e)),Fe=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Fe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Ae())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(je());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Te.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Pe.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Fe())),De.onExit((()=>Fe.cancel)),De.on(Ae.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(ke.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(ke.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(je.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Pe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class Ot{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t;const n=null!==(t=e.sendByPost)&&void 0!==t&&t;super({method:n?G.POST:G.GET,compressible:n}),this.parameters=e,this.parameters.sendByPost=n}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){var e;if(this.parameters.sendByPost)return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Pt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Nt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class jt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class At extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Tt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Pn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Nn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class jn{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Pn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new Ot({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=jn.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new At({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new jt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new jt(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){this.presenceEventEngine?this.presenceEventEngine.join(e):this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}leave(e){var t;this.presenceEventEngine?null===(t=this.presenceEventEngine)||void 0===t||t.leave(e):this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}leaveAll(e){this.presenceEventEngine?this.presenceEventEngine.leaveAll():this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Nn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}jn.decoder=new TextDecoder,jn.OPERATIONS=ie,jn.CATEGORIES=h,jn.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,jn.LinearRetryPolicy=Be.LinearRetryPolicy;class An{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends jn{constructor(e){var t;const n=F(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new k({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new An((e=>T(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); diff --git a/dist/web/pubnub.worker.js b/dist/web/pubnub.worker.js index 744e372c2..6cf2e4778 100644 --- a/dist/web/pubnub.worker.js +++ b/dist/web/pubnub.worker.js @@ -1536,6 +1536,7 @@ headers: {}, timeout: 10, cancellable: false, + compressible: false, identifier: query.requestid, }, }; diff --git a/dist/web/pubnub.worker.min.js b/dist/web/pubnub.worker.min.js index 87ec57ce9..03d79670f 100644 --- a/dist/web/pubnub.worker.min.js +++ b/dist/web/pubnub.worker.min.js @@ -1,2 +1,2 @@ !function(e){"function"==typeof define&&define.amd?define(e):e()}((function(){"use strict";function e(e,t,n,i){return new(n||(n=Promise))((function(r,s){function o(e){try{l(i.next(e))}catch(e){s(e)}}function c(e){try{l(i.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?r(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(o,c)}l((i=i.apply(e,t||[])).next())}))}var t;"function"==typeof SuppressedError&&SuppressedError,function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(t||(t={}));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function n(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var i,r,s={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */i=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function i(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var i=n[t||"all"];return i&&i.test(e)||!1}i.isUUID=r,i.VERSION=t,e.uuid=i,e.isUUID=r}(r=s.exports),null!==i&&(i.exports=r.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},y={},v={};self.onconnect=e=>{oe("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!Q(t))return;const n=t.data;if("client-register"===n.type)n.port=e,F(n),oe(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-unregister"===n.type)U(n);else if("client-pong"===n.type)_(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){V(n);const e=h[n.clientIdentifier];if(e){const t=se(e);let i=[];if(l.has(t)&&(i=l.get(t)[0]),i.push([e,n]),!l.has(t)){const e=setTimeout((()=>{I(i,n),l.delete(t)}),50);l.set(t,[i,e])}}}else n.request.path.endsWith("/heartbeat")?(N(n),$(n)):w(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const I=(e,t)=>{const n=G(t),i=h[t.clientIdentifier];i&&(e=e.filter((e=>e[0].clientIdentifier!==i.clientIdentifier)),q(i,t,n,!0),e.forEach((([e,t])=>q(e,t,n,!1))))},q=(e,t,n,i)=>{var r;let s=!1;if(i||"string"==typeof n||(n=n.identifier),e.subscription&&(s="0"===e.subscription.timetoken),x("start",[e],(new Date).toISOString(),t.request),"string"==typeof n){const i=v[n];if(e){if(e.subscription&&(e.subscription.timetoken=i.timetoken,e.subscription.region=i.region,e.subscription.serviceRequestId=n),!s)return;const o=(new TextEncoder).encode(`{"t":{"t":"${i.timetoken}","r":${null!==(r=i.region)&&void 0!==r?r:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${t.request.origin}${t.request.path}`,u.clientIdentifier=t.clientIdentifier,u.identifier=t.request.identifier,x("end",[e],(new Date).toISOString(),t.request,o,c.get("Content-Type"),0),A(e,u)}return}t.request.cancellable&&f.set(n.identifier,new AbortController);const o=v[n.identifier],{timetokenOverride:c,regionOverride:l}=o;j(n,(()=>P(n.identifier)),((e,i)=>{W(e,i,t.request),E(e,n.identifier)}),((e,i)=>{W(e,null,t.request,D(i)),E(e,n.identifier)}),(e=>{let t=e;return s&&c&&"0"!==c&&(t=m(t,c,l)),t})),oe(`'${Object.keys(v).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let i;const r=e[0];let s=r,o=e[1];try{i=JSON.parse((new TextDecoder).decode(o))}catch(t){return oe(`Subscribe response parse error: ${t}`),e}i.t.t=t,n&&(i.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(i)).buffer,o.byteLength){const e=new Headers(r.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:r.status,statusText:r.statusText,headers:e})}}catch(t){return oe(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},$=e=>{var t;const n=h[e.clientIdentifier],i=C(e);if(!n)return;const r=`${n.userId}_${null!==(t=ie(n))&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[r];if(x("start",[n],(new Date).toISOString(),e.request),!i){let t,i;if(oe(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`,n),o&&o.response&&([t,i]=o.response),!t){i=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${i.byteLength}`});t=new Response(i,{status:200,headers:e})}const r=L([t,i]);return r.url=`${e.request.origin}${e.request.path}`,r.clientIdentifier=e.clientIdentifier,r.identifier=e.request.identifier,x("end",[n],(new Date).toISOString(),e.request,i,t.headers.get("Content-Type"),0),void A(n,r)}j(i,(()=>[n]),((t,n)=>{o&&(o.response=n),W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started heartbeat request.",n)},w=(e,t)=>{var n,i,r;t=null!=t?t:h[e.clientIdentifier];const s=R(e);if(!t)return;const{subscription:o,heartbeat:c}=t,l=null==o?void 0:o.serviceRequestId;if(o&&0===o.channels.length&&0===o.channelGroups.length&&(o.channelGroupQuery="",o.path="",o.previousTimetoken="0",o.timetoken="0",delete o.region,delete o.serviceRequestId,delete o.request),b[t.subscriptionKey]&&c&&0===c.channels.length&&0===c.channelGroups.length){const e=null!==(n=b[r=t.subscriptionKey])&&void 0!==n?n:b[r]={},s=`${t.userId}_${null!==(i=ie(t))&&void 0!==i?i:""}`;e[s]&&e[s].clientIdentifier===t.clientIdentifier&&delete e[s].clientIdentifier}if(!s){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),i=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),r=new Response(n,{status:200,headers:i}),s=L([r,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(j(s,(()=>[t]),((t,n)=>{W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started leave request.",t),void 0===l)return;const u=P(l);u.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),S(l),k(u)},O=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,S(n))},k=e=>{let t,n;for(const i of e)if(i.subscription&&i.subscription.request){n=i.subscription.request,t=i;break}if(!n||!t)return;const i={type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n};I([[t,i]],i)},j=(t,n,i,r,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(K(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),T(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const r=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,r,e[0].headers.get("Content-Type"),(new Date).getTime()-o),i(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let i=e;if("string"==typeof e){const t=e.toLowerCase();i=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(i.name="AbortError")}r(t,i)}))}))},S=e=>{if(0===P(e).length){const t=f.get(e);f.delete(e),delete v[e],t&&t.abort("Cancel request")}},T=(e,t)=>new Promise(((n,i)=>{const r=setTimeout((()=>{f.delete(e),clearTimeout(r),i(new Error("Request timeout"))}),1e3*t)})),P=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete v[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},K=e=>{let t;const n=e.queryParameters;let i=e.path;if(e.headers){t={};for(const[n,i]of Object.entries(e.headers))t[n]=i}return n&&0!==Object.keys(n).length&&(i=`${i}?${le(n)}`),new Request(`${e.origin}${i}`,{method:e.method,headers:t,redirect:"follow"})},G=e=>{var t,n,i,r,s;const o=h[e.clientIdentifier],l=o.subscription,u=z(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=B(u,e);if(s){const e=v[s],{channels:n,channelGroups:i}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||te(e.channels,n))&&(!(i.length>0)||te(e.channelGroups,i)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),y=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(y.add,y);const n=t.serviceRequestId;t.serviceRequestId=a,n&&v[n]&&S(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const I=null!==(i=v[a])&&void 0!==i?i:v[a]={requestId:a,timetoken:null!==(r=d.queryParameters.tt)&&void 0!==r?r:"0",channelGroups:[],channels:[]};if(y.size){I.channels=Array.from(y).sort();const e=d.path.split("/");e[4]=I.channels.join(","),d.path=e.join("/")}if(b.size&&(I.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=I.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h)),d.queryParameters&&d.queryParameters.auth){const e=re(u);e&&(d.queryParameters.auth=e)}}else v[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};v[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(v[a].region=d.queryParameters.tr),v[a].timetokenOverride=f,v[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)ce(v[a],`Started aggregated request for clients: ${b}`,e);return d},C=e=>{var t,n,i,r,s;const o=h[e.clientIdentifier],c=X(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=ie(o))&&void 0!==n?n:""}`,d=[...o.heartbeat.channelGroups],f=[...o.heartbeat.channels];let p,g,y=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=te(e,f)&&te(t,d),n&&(y=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,clientIdentifier:o.clientIdentifier,timestamp:Date.now()},p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=!1;let v=o.heartbeatInterval;for(const e of c)e.heartbeatInterval&&(v=Math.min(v,e.heartbeatInterval));if(g&&u[a].clientIdentifier){const e=u[a].timestamp+1e3*v,t=Date.now();if(!y&&t5e3)return}delete u[a].response,u[a].clientIdentifier=o.clientIdentifier;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(0!==f.length||0!==d.length){if(f.length||d.length){const e=l.path.split("/");e[6]=f.length?f.join(","):",",l.path=e.join("/")}if(d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,c.length>1&&l.queryParameters&&l.queryParameters.auth){const e=re(c);e&&(l.queryParameters.auth=e)}return l}},R=e=>{var t;const n=h[e.clientIdentifier],i=Y(e);let r=ee(e.request),s=Z(e.request);const o=Object.assign({},e.request);if(n&&n.subscription){const{subscription:e}=n;s.length&&(e.channels=e.channels.filter((e=>!s.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(n&&n.heartbeat){const{heartbeat:e}=n;s.length&&(e.channels=e.channels.filter((e=>!s.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of i){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(s.length&&(s=s.filter((e=>!e.endsWith("-pnpres")&&!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")&&!n.channelGroups.includes(e))))))}if(s.length&&(s=s.filter((e=>!e.endsWith("-pnpres")))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")))),0!==s.length||0!==r.length){if(n&&b[n.subscriptionKey]&&(s.length||r.length)){const e=b[n.subscriptionKey],i=`${n.userId}_${null!==(t=ie(n))&&void 0!==t?t:""}`;if(e[i]){let{channels:t,channelGroups:n}=e[i];r.length&&(n=n.filter((e=>!s.includes(e)))),s.length&&(t=t.filter((e=>!s.includes(e)))),e[i].channelGroups=n,e[i].channels=t}}if(s.length){const e=o.path.split("/");e[6]=s.join(","),o.path=e.join("/")}if(r.length&&(o.queryParameters["channel-group"]=r.join(",")),i.length>1&&o.queryParameters&&o.queryParameters.auth){const e=re(i);e&&(o.queryParameters.auth=e)}return o}if(n&&n.workerLogVerbosity){const e=i.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");oe(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,n)}},A=(e,t)=>{var n;const i=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!i)return!1;try{return i.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},x=(e,t,n,i,r,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=i&&i.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;r&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(r)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let r=null!=n?n:i;if(d||(r=i),e.logVerbosity&&t&&r){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${r.origin}${r.path}`,query:r.queryParameters});A(e,t)}}},W=(e,t,n,i)=>{var r,s;if(0===e.length)return;if(!i&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(r=y[e[0].subscriptionKey])&&void 0!==r?r:{},l=n&&n.path.startsWith("/v2/subscribe");if(!i&&t&&(i=t[0].status>=400?D(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)oe(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)oe(n,t)}continue}const r=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),r&&a){const e=Object.assign(Object.assign({},i),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!r&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const i of e)i.clientIdentifier!==t.clientIdentifier&&oe(n,i)}}},L=e=>{var t;const[n,i]=e,r=i.byteLength>0?i:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:r}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",i="Unknown error",r="Error";e&&e instanceof Error&&(i=e.message,r=e.name);const s=i.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===r||s.includes("aborted")||s.includes("cancel"))&&(i="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:r,type:n,message:i}}},F=e=>{var t,n,i,r,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,newlyRegistered:!0,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[r=e.subscriptionKey])&&void 0!==t?t:p[r]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=y[s=e.subscriptionKey])&&void 0!==n?n:y[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)oe(u,e);if(!a[e.subscriptionKey]&&(null!==(i=p[e.subscriptionKey])&&void 0!==i?i:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)oe(`Setup PubNub client ping event ${n} seconds`,e);a[t]=setTimeout((()=>ne(t)),500*n-1)}},U=e=>{J(e.subscriptionKey,e.clientIdentifier)},V=e=>{var t,n,i,r,s,o,c,l,u,a,d,f,p,b,y,v,I,q,m,$;const w=e.request.queryParameters,{clientIdentifier:O}=e,k=h[O];if(!k)return;const j=null!==(t=w["channel-group"])&&void 0!==t?t:"",S=null!==(n=w.state)&&void 0!==n?n:"";let T=k.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(v=null!==(s=g[y=k.subscriptionKey])&&void 0!==s?s:g[y]={})[I=k.userId])&&void 0!==o?o:v[I]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[q=k.subscriptionKey])&&void 0!==c?c:g[q]={})[$=k.userId])&&void 0!==l?l:m[$]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(r=(p=null!==(i=g[f=k.subscriptionKey])&&void 0!==i?i:g[f]={})[b=k.userId])&&void 0!==r?r:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}k.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=Z(e.request)),T.channelGroupQuery!==j&&(T.channelGroupQuery=j,T.channelGroups=ee(e.request));let{authKey:P}=k;const{userId:E}=k;T.request=e.request,T.filterExpression=null!==(u=w["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=w.tt)&&void 0!==a?a:"0",void 0!==w.tr&&(T.region=w.tr),k.authKey=null!==(d=w.auth)&&void 0!==d?d:"",k.origin=e.request.origin,k.userId=w.uuid,k.pnsdk=w.pnsdk,k.accessToken=e.token,k.newlyRegistered&&!P&&k.authKey&&(P=k.authKey),k.newlyRegistered=!1,M(k,E,P)},N=e=>{var t,n;const i=h[e.clientIdentifier],{request:r}=e;if(!i)return;const s=null!==(t=i.heartbeat)&&void 0!==t?t:i.heartbeat={channels:[],channelGroups:[]};s.channelGroups=ee(r).filter((e=>!e.endsWith("-pnpres"))),s.channels=Z(r).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=r.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var i,r,s;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(i=e.authKey)&&void 0!==i?i:""))return;const o=null!==(r=b[e.subscriptionKey])&&void 0!==r?r:{},c=`${t}_${null!==(s=ie(e))&&void 0!==s?s:""}`;void 0!==o[c]&&delete o[c]},_=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},J=(e,t)=>{var n,i,r;const s=h[t];delete h[t];let o=p[e];if(s){if(s.subscription){const{serviceRequestId:e}=s.subscription;delete s.subscription.serviceRequestId,e&&S(e)}if(b[e]){const t=null!==(n=b[e])&&void 0!==n?n:b[e]={},r=`${s.userId}_${null!==(i=ie(s))&&void 0!==i?i:""}`;t[r]&&t[r].clientIdentifier===s.clientIdentifier&&delete t[r].clientIdentifier}s.unsubscribeOfflineClients&&H(s)}if(o)if(o=o.filter((e=>e.clientIdentifier!==t)),o.length>0?p[e]=o:(delete p[e],delete b[e]),0===o.length&&delete g[e],o.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];const c=`Invalidate '${t}' client. '${(null!==(r=p[e])&&void 0!==r?r:[]).length}' clients currently active.`;if(o)for(const e of o)oe(c,e);else oe(c)},H=e=>{if(!e.subscription)return;const{channels:n,channelGroups:i,serviceRequestId:r}=e.subscription,s=(null!=i?i:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort(),o=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort();if(0===o.length&&0===s.length)return;const l=s.length>0?s.join(","):void 0,u=0===o.length?",":o.join(","),a=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),l?{"channel-group":l}:{}),d={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${u}/leave`,queryParameters:a,method:t.GET,headers:{},timeout:10,cancellable:!1,identifier:a.requestid}};w(d,e)},Q=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:i}=e.data;return void 0!==i&&"boolean"==typeof i&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},B=(e,t)=>{var n;const i=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",r=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===r&&e.channelGroupQuery===i)return oe(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const i=v[e.serviceRequestId];if(s||(s=ee(t.request)),o||(o=Z(t.request)),o.length&&!te(i.channels,o))continue;if(s.length&&!te(i.channelGroups,s))continue;return ce(i,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},z=(e,t)=>{var n,i;const r=h[t.clientIdentifier];if(!r)return[];const s=t.request.queryParameters,o=ie(r),c=null!==(n=s["filter-expr"])&&void 0!==n?n:"",l=s.uuid;return(null!==(i=p[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&ie(t)===o&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===c&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},X=e=>Y(e),Y=e=>{var t;const n=h[e.clientIdentifier];if(!n)return[];const i=e.request.queryParameters,r=ie(n),s=i.uuid;return(null!==(t=p[e.subscriptionKey])&&void 0!==t?t:[]).filter((e=>e.userId===s&&ie(e)===r))},Z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},ee=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},te=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ne=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let i=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){i=!0;for(const t of n)oe(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);J(e.subscriptionKey,e.clientIdentifier)}}e&&!i&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ne(e)),500*t-1)}},ie=e=>{var t;return e.accessToken&&null!==(t=e.accessToken.token)&&void 0!==t?t:e.authKey},re=e=>{const t=e.filter((e=>!!e.accessToken)).sort(((e,t)=>e.accessToken.expiration-t.accessToken.expiration)).pop();return t?t.authKey:void 0},se=e=>{const t=ie(e);let n=`${e.userId}-${e.subscriptionKey}${t?`-${t}`:""}`;return e.subscription&&e.subscription.filterExpression&&(n+=`-${e.subscription.filterExpression}`),n},oe=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,i)}))},ce=(e,t,n)=>{const i=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-dir",message:t,data:e};i.forEach((e=>{e&&A(e,r)}))},le=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${ue(e)}`)).join("&"):`${t}=${ue(n)}`})).join("&"),ue=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */i=s,function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function i(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var i=n[t||"all"];return i&&i.test(e)||!1}i.isUUID=r,i.VERSION=t,e.uuid=i,e.isUUID=r}(r=s.exports),null!==i&&(i.exports=r.uuid);var o=n(s.exports),c={createUUID:()=>o.uuid?o.uuid():o()};const l=new Map,u=new TextDecoder,a={},d=c.createUUID(),f=new Map,h={},p={},b={},g={},y={},v={};self.onconnect=e=>{oe("New PubNub Client connected to the Subscription Shared Worker."),e.ports.forEach((e=>{e.start(),e.onmessage=t=>{if(!Q(t))return;const n=t.data;if("client-register"===n.type)n.port=e,F(n),oe(`Client '${n.clientIdentifier}' registered with '${d}' shared worker`);else if("client-unregister"===n.type)U(n);else if("client-pong"===n.type)_(n);else if("send-request"===n.type)if(n.request.path.startsWith("/v2/subscribe")){V(n);const e=h[n.clientIdentifier];if(e){const t=se(e);let i=[];if(l.has(t)&&(i=l.get(t)[0]),i.push([e,n]),!l.has(t)){const e=setTimeout((()=>{I(i,n),l.delete(t)}),50);l.set(t,[i,e])}}}else n.request.path.endsWith("/heartbeat")?(N(n),$(n)):w(n);else"cancel-request"===n.type&&O(n)},e.postMessage({type:"shared-worker-connected"})}))};const I=(e,t)=>{const n=G(t),i=h[t.clientIdentifier];i&&(e=e.filter((e=>e[0].clientIdentifier!==i.clientIdentifier)),q(i,t,n,!0),e.forEach((([e,t])=>q(e,t,n,!1))))},q=(e,t,n,i)=>{var r;let s=!1;if(i||"string"==typeof n||(n=n.identifier),e.subscription&&(s="0"===e.subscription.timetoken),x("start",[e],(new Date).toISOString(),t.request),"string"==typeof n){const i=v[n];if(e){if(e.subscription&&(e.subscription.timetoken=i.timetoken,e.subscription.region=i.region,e.subscription.serviceRequestId=n),!s)return;const o=(new TextEncoder).encode(`{"t":{"t":"${i.timetoken}","r":${null!==(r=i.region)&&void 0!==r?r:"0"}},"m":[]}`),c=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${o.length}`}),l=new Response(o,{status:200,headers:c}),u=L([l,o]);u.url=`${t.request.origin}${t.request.path}`,u.clientIdentifier=t.clientIdentifier,u.identifier=t.request.identifier,x("end",[e],(new Date).toISOString(),t.request,o,c.get("Content-Type"),0),A(e,u)}return}t.request.cancellable&&f.set(n.identifier,new AbortController);const o=v[n.identifier],{timetokenOverride:c,regionOverride:l}=o;j(n,(()=>P(n.identifier)),((e,i)=>{W(e,i,t.request),E(e,n.identifier)}),((e,i)=>{W(e,null,t.request,D(i)),E(e,n.identifier)}),(e=>{let t=e;return s&&c&&"0"!==c&&(t=m(t,c,l)),t})),oe(`'${Object.keys(v).length}' subscription request currently active.`)},m=(e,t,n)=>{if(void 0===t||"0"===t||e[0].status>=400)return e;let i;const r=e[0];let s=r,o=e[1];try{i=JSON.parse((new TextDecoder).decode(o))}catch(t){return oe(`Subscribe response parse error: ${t}`),e}i.t.t=t,n&&(i.t.r=parseInt(n,10));try{if(o=(new TextEncoder).encode(JSON.stringify(i)).buffer,o.byteLength){const e=new Headers(r.headers);e.set("Content-Length",`${o.byteLength}`),s=new Response(o,{status:r.status,statusText:r.statusText,headers:e})}}catch(t){return oe(`Subscribe serialization error: ${t}`),e}return o.byteLength>0?[s,o]:e},$=e=>{var t;const n=h[e.clientIdentifier],i=C(e);if(!n)return;const r=`${n.userId}_${null!==(t=ie(n))&&void 0!==t?t:""}`,s=b[n.subscriptionKey],o=(null!=s?s:{})[r];if(x("start",[n],(new Date).toISOString(),e.request),!i){let t,i;if(oe(`Previous heartbeat request has been sent less than ${n.heartbeatInterval} seconds ago. Skipping...`,n),o&&o.response&&([t,i]=o.response),!t){i=(new TextEncoder).encode('{ "status": 200, "message": "OK", "service": "Presence" }').buffer;const e=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${i.byteLength}`});t=new Response(i,{status:200,headers:e})}const r=L([t,i]);return r.url=`${e.request.origin}${e.request.path}`,r.clientIdentifier=e.clientIdentifier,r.identifier=e.request.identifier,x("end",[n],(new Date).toISOString(),e.request,i,t.headers.get("Content-Type"),0),void A(n,r)}j(i,(()=>[n]),((t,n)=>{o&&(o.response=n),W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started heartbeat request.",n)},w=(e,t)=>{var n,i,r;t=null!=t?t:h[e.clientIdentifier];const s=R(e);if(!t)return;const{subscription:o,heartbeat:c}=t,l=null==o?void 0:o.serviceRequestId;if(o&&0===o.channels.length&&0===o.channelGroups.length&&(o.channelGroupQuery="",o.path="",o.previousTimetoken="0",o.timetoken="0",delete o.region,delete o.serviceRequestId,delete o.request),b[t.subscriptionKey]&&c&&0===c.channels.length&&0===c.channelGroups.length){const e=null!==(n=b[r=t.subscriptionKey])&&void 0!==n?n:b[r]={},s=`${t.userId}_${null!==(i=ie(t))&&void 0!==i?i:""}`;e[s]&&e[s].clientIdentifier===t.clientIdentifier&&delete e[s].clientIdentifier}if(!s){const n=(new TextEncoder).encode('{"status": 200, "action": "leave", "message": "OK", "service":"Presence"}'),i=new Headers({"Content-Type":'text/javascript; charset="UTF-8"',"Content-Length":`${n.length}`}),r=new Response(n,{status:200,headers:i}),s=L([r,n]);return s.url=`${e.request.origin}${e.request.path}`,s.clientIdentifier=e.clientIdentifier,s.identifier=e.request.identifier,void A(t,s)}if(j(s,(()=>[t]),((t,n)=>{W(t,n,e.request)}),((t,n)=>{W(t,null,e.request,D(n))})),oe("Started leave request.",t),void 0===l)return;const u=P(l);u.forEach((e=>{e&&e.subscription&&delete e.subscription.serviceRequestId})),S(l),k(u)},O=e=>{const t=h[e.clientIdentifier];if(!t||!t.subscription)return;const n=t.subscription.serviceRequestId;t&&n&&(delete t.subscription.serviceRequestId,t.subscription.request&&t.subscription.request.identifier===e.identifier&&delete t.subscription.request,S(n))},k=e=>{let t,n;for(const i of e)if(i.subscription&&i.subscription.request){n=i.subscription.request,t=i;break}if(!n||!t)return;const i={type:"send-request",clientIdentifier:t.clientIdentifier,subscriptionKey:t.subscriptionKey,logVerbosity:t.logVerbosity,request:n};I([[t,i]],i)},j=(t,n,i,r,s)=>{e(void 0,void 0,void 0,(function*(){var e;const o=(new Date).getTime();Promise.race([fetch(K(t),{signal:null===(e=f.get(t.identifier))||void 0===e?void 0:e.signal,keepalive:!0}),T(t.identifier,t.timeout)]).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>s?s(e):e)).then((e=>{const r=e[1].byteLength>0?e[1]:void 0,s=n();0!==s.length&&(x("end",s,(new Date).toISOString(),t,r,e[0].headers.get("Content-Type"),(new Date).getTime()-o),i(s,e))})).catch((e=>{const t=n();if(0===t.length)return;let i=e;if("string"==typeof e){const t=e.toLowerCase();i=new Error(e),!t.includes("timeout")&&t.includes("cancel")&&(i.name="AbortError")}r(t,i)}))}))},S=e=>{if(0===P(e).length){const t=f.get(e);f.delete(e),delete v[e],t&&t.abort("Cancel request")}},T=(e,t)=>new Promise(((n,i)=>{const r=setTimeout((()=>{f.delete(e),clearTimeout(r),i(new Error("Request timeout"))}),1e3*t)})),P=e=>Object.values(h).filter((t=>void 0!==t&&void 0!==t.subscription&&t.subscription.serviceRequestId===e)),E=(e,t)=>{delete v[t],e.forEach((e=>{e.subscription&&(delete e.subscription.request,delete e.subscription.serviceRequestId)}))},K=e=>{let t;const n=e.queryParameters;let i=e.path;if(e.headers){t={};for(const[n,i]of Object.entries(e.headers))t[n]=i}return n&&0!==Object.keys(n).length&&(i=`${i}?${le(n)}`),new Request(`${e.origin}${i}`,{method:e.method,headers:t,redirect:"follow"})},G=e=>{var t,n,i,r,s;const o=h[e.clientIdentifier],l=o.subscription,u=z(l.timetoken,e),a=c.createUUID(),d=Object.assign({},e.request);let f,p;if(u.length>1){const s=B(u,e);if(s){const e=v[s],{channels:n,channelGroups:i}=null!==(t=o.subscription)&&void 0!==t?t:{channels:[],channelGroups:[]};if((!(n.length>0)||te(e.channels,n))&&(!(i.length>0)||te(e.channelGroups,i)))return s}const c=(null!==(n=g[o.subscriptionKey])&&void 0!==n?n:{})[o.userId],h={},b=new Set(l.channelGroups),y=new Set(l.channels);c&&l.objectsWithState.length&&l.objectsWithState.forEach((e=>{const t=c[e];t&&(h[e]=t)}));for(const e of u){const{subscription:t}=e;if(!t)continue;1!==u.length&&e.clientIdentifier===o.clientIdentifier||!t.timetoken||(f=t.timetoken,p=t.region),t.channelGroups.forEach(b.add,b),t.channels.forEach(y.add,y);const n=t.serviceRequestId;t.serviceRequestId=a,n&&v[n]&&S(n),c&&t.objectsWithState.forEach((e=>{const t=c[e];t&&!h[e]&&(h[e]=t)}))}const I=null!==(i=v[a])&&void 0!==i?i:v[a]={requestId:a,timetoken:null!==(r=d.queryParameters.tt)&&void 0!==r?r:"0",channelGroups:[],channels:[]};if(y.size){I.channels=Array.from(y).sort();const e=d.path.split("/");e[4]=I.channels.join(","),d.path=e.join("/")}if(b.size&&(I.channelGroups=Array.from(b).sort(),d.queryParameters["channel-group"]=I.channelGroups.join(",")),Object.keys(h).length&&(d.queryParameters.state=JSON.stringify(h)),d.queryParameters&&d.queryParameters.auth){const e=re(u);e&&(d.queryParameters.auth=e)}}else v[a]={requestId:a,timetoken:null!==(s=d.queryParameters.tt)&&void 0!==s?s:"0",channelGroups:l.channelGroups,channels:l.channels};v[a]&&(d.queryParameters&&void 0!==d.queryParameters.tt&&void 0!==d.queryParameters.tr&&(v[a].region=d.queryParameters.tr),v[a].timetokenOverride=f,v[a].regionOverride=p),l.serviceRequestId=a,d.identifier=a;const b=u.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");if(b.length>0)for(const e of u)ce(v[a],`Started aggregated request for clients: ${b}`,e);return d},C=e=>{var t,n,i,r,s;const o=h[e.clientIdentifier],c=X(e),l=Object.assign({},e.request);if(!o||!o.heartbeat)return;const u=null!==(t=b[s=o.subscriptionKey])&&void 0!==t?t:b[s]={},a=`${o.userId}_${null!==(n=ie(o))&&void 0!==n?n:""}`,d=[...o.heartbeat.channelGroups],f=[...o.heartbeat.channels];let p,g,y=!1;if(u[a]){const{channels:e,channelGroups:t,response:n}=u[a];p=null!==(r=o.heartbeat.presenceState)&&void 0!==r?r:{},g=te(e,f)&&te(t,d),n&&(y=n[0].status>=400)}else u[a]={channels:f,channelGroups:d,clientIdentifier:o.clientIdentifier,timestamp:Date.now()},p=null!==(i=o.heartbeat.presenceState)&&void 0!==i?i:{},g=!1;let v=o.heartbeatInterval;for(const e of c)e.heartbeatInterval&&(v=Math.min(v,e.heartbeatInterval));if(g&&u[a].clientIdentifier){const e=u[a].timestamp+1e3*v,t=Date.now();if(!y&&t5e3)return}delete u[a].response,u[a].clientIdentifier=o.clientIdentifier;for(const t of c){const{heartbeat:n}=t;void 0!==n&&t.clientIdentifier!==e.clientIdentifier&&(n.presenceState&&(p=Object.assign(Object.assign({},p),n.presenceState)),d.push(...n.channelGroups.filter((e=>!d.includes(e)))),f.push(...n.channels.filter((e=>!f.includes(e)))))}u[a].channels=f,u[a].channelGroups=d,u[a].timestamp=Date.now();for(const e in Object.keys(p))f.includes(e)||d.includes(e)||delete p[e];if(0!==f.length||0!==d.length){if(f.length||d.length){const e=l.path.split("/");e[6]=f.length?f.join(","):",",l.path=e.join("/")}if(d.length&&(l.queryParameters["channel-group"]=d.join(",")),Object.keys(p).length?l.queryParameters.state=JSON.stringify(p):delete l.queryParameters.state,c.length>1&&l.queryParameters&&l.queryParameters.auth){const e=re(c);e&&(l.queryParameters.auth=e)}return l}},R=e=>{var t;const n=h[e.clientIdentifier],i=Y(e);let r=ee(e.request),s=Z(e.request);const o=Object.assign({},e.request);if(n&&n.subscription){const{subscription:e}=n;s.length&&(e.channels=e.channels.filter((e=>!s.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}if(n&&n.heartbeat){const{heartbeat:e}=n;s.length&&(e.channels=e.channels.filter((e=>!s.includes(e)))),r.length&&(e.channelGroups=e.channelGroups.filter((e=>!r.includes(e))))}for(const t of i){const n=t.subscription;void 0!==n&&(t.clientIdentifier!==e.clientIdentifier&&(s.length&&(s=s.filter((e=>!e.endsWith("-pnpres")&&!n.channels.includes(e)))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")&&!n.channelGroups.includes(e))))))}if(s.length&&(s=s.filter((e=>!e.endsWith("-pnpres")))),r.length&&(r=r.filter((e=>!e.endsWith("-pnpres")))),0!==s.length||0!==r.length){if(n&&b[n.subscriptionKey]&&(s.length||r.length)){const e=b[n.subscriptionKey],i=`${n.userId}_${null!==(t=ie(n))&&void 0!==t?t:""}`;if(e[i]){let{channels:t,channelGroups:n}=e[i];r.length&&(n=n.filter((e=>!s.includes(e)))),s.length&&(t=t.filter((e=>!s.includes(e)))),e[i].channelGroups=n,e[i].channels=t}}if(s.length){const e=o.path.split("/");e[6]=s.join(","),o.path=e.join("/")}if(r.length&&(o.queryParameters["channel-group"]=r.join(",")),i.length>1&&o.queryParameters&&o.queryParameters.auth){const e=re(i);e&&(o.queryParameters.auth=e)}return o}if(n&&n.workerLogVerbosity){const e=i.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ");oe(`Specified channels and groups still in use by other clients: ${e}. Ignoring leave request.`,n)}},A=(e,t)=>{var n;const i=(null!==(n=y[e.subscriptionKey])&&void 0!==n?n:{})[e.clientIdentifier];if(!i)return!1;try{return i.postMessage(t),!0}catch(t){e.workerLogVerbosity&&console.error(`[SharedWorker] Unable send message using message port: ${t}`)}return!1},x=(e,t,n,i,r,s,o)=>{var c,l;if(0===t.length)return;const a=null!==(c=y[t[0].subscriptionKey])&&void 0!==c?c:{},d=i&&i.path.startsWith("/v2/subscribe");let f;if("start"===e)f={type:"request-progress-start",clientIdentifier:"",url:"",timestamp:n};else{let e;r&&s&&(-1!==s.indexOf("text/javascript")||-1!==s.indexOf("application/json")||-1!==s.indexOf("text/plain")||-1!==s.indexOf("text/html"))&&(e=u.decode(r)),f={type:"request-progress-end",clientIdentifier:"",url:"",response:e,timestamp:n,duration:o}}for(const e of t){if(d&&!e.subscription)continue;const t=a[e.clientIdentifier],{request:n}=null!==(l=e.subscription)&&void 0!==l?l:{};let r=null!=n?n:i;if(d||(r=i),e.logVerbosity&&t&&r){const t=Object.assign(Object.assign({},f),{clientIdentifier:e.clientIdentifier,url:`${r.origin}${r.path}`,query:r.queryParameters});A(e,t)}}},W=(e,t,n,i)=>{var r,s;if(0===e.length)return;if(!i&&!t)return;const o=e.some((e=>e&&e.workerLogVerbosity)),c=null!==(r=y[e[0].subscriptionKey])&&void 0!==r?r:{},l=n&&n.path.startsWith("/v2/subscribe");if(!i&&t&&(i=t[0].status>=400?D(void 0,t):L(t)),o&&n&&!n.path.endsWith("/heartbeat")){const t=`Notify clients about ${l?"subscribe":"leave"} request completion: ${e.reduce(((e,{clientIdentifier:t})=>(e.push(t),e)),[]).join(", ")}`;for(const n of e)oe(t,n)}for(const t of e){if(l&&!t.subscription){if(o){const n=`${t.clientIdentifier} doesn't have active subscription. Don't notify about completion.`;for(const t of e)oe(n,t)}continue}const r=c[t.clientIdentifier],{request:u}=null!==(s=t.subscription)&&void 0!==s?s:{};let a=null!=u?u:n;if(l||(a=n),r&&a){const e=Object.assign(Object.assign({},i),{clientIdentifier:t.clientIdentifier,identifier:a.identifier,url:`${a.origin}${a.path}`});A(t,e)}else if(!r&&o){const n=`${t.clientIdentifier} doesn't have Shared Worker's communication channel. Don't notify about completion.`;for(const i of e)i.clientIdentifier!==t.clientIdentifier&&oe(n,i)}}},L=e=>{var t;const[n,i]=e,r=i.byteLength>0?i:void 0,s=parseInt(null!==(t=n.headers.get("Content-Length"))&&void 0!==t?t:"0",10),o=n.headers.get("Content-Type"),c={};return n.headers.forEach(((e,t)=>c[t]=e.toLowerCase())),{type:"request-process-success",clientIdentifier:"",identifier:"",url:"",response:{contentLength:s,contentType:o,headers:c,status:n.status,body:r}}},D=(e,t)=>{if(t)return Object.assign(Object.assign({},L(t)),{type:"request-process-error"});let n="NETWORK_ISSUE",i="Unknown error",r="Error";e&&e instanceof Error&&(i=e.message,r=e.name);const s=i.toLowerCase();return s.includes("timeout")?n="TIMEOUT":("AbortError"===r||s.includes("aborted")||s.includes("cancel"))&&(i="Request aborted",n="ABORTED"),{type:"request-process-error",clientIdentifier:"",identifier:"",url:"",error:{name:r,type:n,message:i}}},F=e=>{var t,n,i,r,s;const{clientIdentifier:o}=e;if(h[o])return;const c=h[o]={clientIdentifier:o,subscriptionKey:e.subscriptionKey,userId:e.userId,heartbeatInterval:e.heartbeatInterval,newlyRegistered:!0,logVerbosity:e.logVerbosity,offlineClientsCheckInterval:e.workerOfflineClientsCheckInterval,unsubscribeOfflineClients:e.workerUnsubscribeOfflineClients,workerLogVerbosity:e.workerLogVerbosity},l=null!==(t=p[r=e.subscriptionKey])&&void 0!==t?t:p[r]=[];l.every((e=>e.clientIdentifier!==o))&&l.push(c),(null!==(n=y[s=e.subscriptionKey])&&void 0!==n?n:y[s]={})[o]=e.port;const u=`Registered PubNub client with '${o}' identifier. '${l.length}' clients currently active.`;for(const e of l)oe(u,e);if(!a[e.subscriptionKey]&&(null!==(i=p[e.subscriptionKey])&&void 0!==i?i:[]).length>0){const{subscriptionKey:t}=e,n=e.workerOfflineClientsCheckInterval;for(const e of l)oe(`Setup PubNub client ping event ${n} seconds`,e);a[t]=setTimeout((()=>ne(t)),500*n-1)}},U=e=>{J(e.subscriptionKey,e.clientIdentifier)},V=e=>{var t,n,i,r,s,o,c,l,u,a,d,f,p,b,y,v,I,q,m,$;const w=e.request.queryParameters,{clientIdentifier:O}=e,k=h[O];if(!k)return;const j=null!==(t=w["channel-group"])&&void 0!==t?t:"",S=null!==(n=w.state)&&void 0!==n?n:"";let T=k.subscription;if(T){if(S.length>0){const e=JSON.parse(S),t=null!==(o=(v=null!==(s=g[y=k.subscriptionKey])&&void 0!==s?s:g[y]={})[I=k.userId])&&void 0!==o?o:v[I]={};Object.entries(e).forEach((([e,n])=>t[e]=n));for(const n of T.objectsWithState)e[n]||delete t[n];T.objectsWithState=Object.keys(e)}else if(T.objectsWithState.length){const e=null!==(l=(m=null!==(c=g[q=k.subscriptionKey])&&void 0!==c?c:g[q]={})[$=k.userId])&&void 0!==l?l:m[$]={};for(const t of T.objectsWithState)delete e[t];T.objectsWithState=[]}}else{if(T={path:"",channelGroupQuery:"",channels:[],channelGroups:[],previousTimetoken:"0",timetoken:"0",objectsWithState:[]},S.length>0){const e=JSON.parse(S),t=null!==(r=(p=null!==(i=g[f=k.subscriptionKey])&&void 0!==i?i:g[f]={})[b=k.userId])&&void 0!==r?r:p[b]={};Object.entries(e).forEach((([e,n])=>t[e]=n)),T.objectsWithState=Object.keys(e)}k.subscription=T}T.path!==e.request.path&&(T.path=e.request.path,T.channels=Z(e.request)),T.channelGroupQuery!==j&&(T.channelGroupQuery=j,T.channelGroups=ee(e.request));let{authKey:P}=k;const{userId:E}=k;T.request=e.request,T.filterExpression=null!==(u=w["filter-expr"])&&void 0!==u?u:"",T.timetoken=null!==(a=w.tt)&&void 0!==a?a:"0",void 0!==w.tr&&(T.region=w.tr),k.authKey=null!==(d=w.auth)&&void 0!==d?d:"",k.origin=e.request.origin,k.userId=w.uuid,k.pnsdk=w.pnsdk,k.accessToken=e.token,k.newlyRegistered&&!P&&k.authKey&&(P=k.authKey),k.newlyRegistered=!1,M(k,E,P)},N=e=>{var t,n;const i=h[e.clientIdentifier],{request:r}=e;if(!i)return;const s=null!==(t=i.heartbeat)&&void 0!==t?t:i.heartbeat={channels:[],channelGroups:[]};s.channelGroups=ee(r).filter((e=>!e.endsWith("-pnpres"))),s.channels=Z(r).filter((e=>!e.endsWith("-pnpres")));const o=null!==(n=r.queryParameters.state)&&void 0!==n?n:"";if(o.length>0){const e=JSON.parse(o);for(const t of Object.keys(e))s.channels.includes(t)||s.channelGroups.includes(t)||delete e[t];s.presenceState=e}},M=(e,t,n)=>{var i,r,s;if(!e||t===e.userId&&(null!=n?n:"")===(null!==(i=e.authKey)&&void 0!==i?i:""))return;const o=null!==(r=b[e.subscriptionKey])&&void 0!==r?r:{},c=`${t}_${null!==(s=ie(e))&&void 0!==s?s:""}`;void 0!==o[c]&&delete o[c]},_=e=>{const t=h[e.clientIdentifier];t&&(t.lastPongEvent=(new Date).getTime()/1e3)},J=(e,t)=>{var n,i,r;const s=h[t];delete h[t];let o=p[e];if(s){if(s.subscription){const{serviceRequestId:e}=s.subscription;delete s.subscription.serviceRequestId,e&&S(e)}if(b[e]){const t=null!==(n=b[e])&&void 0!==n?n:b[e]={},r=`${s.userId}_${null!==(i=ie(s))&&void 0!==i?i:""}`;t[r]&&t[r].clientIdentifier===s.clientIdentifier&&delete t[r].clientIdentifier}s.unsubscribeOfflineClients&&H(s)}if(o)if(o=o.filter((e=>e.clientIdentifier!==t)),o.length>0?p[e]=o:(delete p[e],delete b[e]),0===o.length&&delete g[e],o.length>0){const n=y[e];n&&(delete n[t],0===Object.keys(n).length&&delete y[e])}else delete y[e];const c=`Invalidate '${t}' client. '${(null!==(r=p[e])&&void 0!==r?r:[]).length}' clients currently active.`;if(o)for(const e of o)oe(c,e);else oe(c)},H=e=>{if(!e.subscription)return;const{channels:n,channelGroups:i,serviceRequestId:r}=e.subscription,s=(null!=i?i:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort(),o=(null!=n?n:[]).filter((e=>!e.endsWith("-pnpres"))).map((e=>ue(e))).sort();if(0===o.length&&0===s.length)return;const l=s.length>0?s.join(","):void 0,u=0===o.length?",":o.join(","),a=Object.assign(Object.assign({instanceid:e.clientIdentifier,uuid:e.userId,requestid:c.createUUID()},e.authKey?{auth:e.authKey}:{}),l?{"channel-group":l}:{}),d={type:"send-request",clientIdentifier:e.clientIdentifier,subscriptionKey:e.subscriptionKey,logVerbosity:e.logVerbosity,request:{origin:e.origin,path:`/v2/presence/sub-key/${e.subscriptionKey}/channel/${u}/leave`,queryParameters:a,method:t.GET,headers:{},timeout:10,cancellable:!1,compressible:!1,identifier:a.requestid}};w(d,e)},Q=e=>{const{clientIdentifier:t,subscriptionKey:n,logVerbosity:i}=e.data;return void 0!==i&&"boolean"==typeof i&&(!(!t||"string"!=typeof t)&&!(!n||"string"!=typeof n))},B=(e,t)=>{var n;const i=null!==(n=t.request.queryParameters["channel-group"])&&void 0!==n?n:"",r=t.request.path;let s,o;for(const n of e){const{subscription:e}=n;if(!e||!e.serviceRequestId)continue;const c=h[t.clientIdentifier],l=e.serviceRequestId;if(e.path===r&&e.channelGroupQuery===i)return oe(`Found identical request started by '${n.clientIdentifier}' client. \nWaiting for existing '${l}' request completion.`,c),e.serviceRequestId;{const i=v[e.serviceRequestId];if(s||(s=ee(t.request)),o||(o=Z(t.request)),o.length&&!te(i.channels,o))continue;if(s.length&&!te(i.channelGroups,s))continue;return ce(i,`'${t.request.identifier}' request channels and groups are subset of ongoing '${l}' request \nwhich has started by '${n.clientIdentifier}' client. Waiting for existing '${l}' request completion.`,c),e.serviceRequestId}}},z=(e,t)=>{var n,i;const r=h[t.clientIdentifier];if(!r)return[];const s=t.request.queryParameters,o=ie(r),c=null!==(n=s["filter-expr"])&&void 0!==n?n:"",l=s.uuid;return(null!==(i=p[t.subscriptionKey])&&void 0!==i?i:[]).filter((t=>t.userId===l&&ie(t)===o&&t.subscription&&(0!==t.subscription.channels.length||0!==t.subscription.channelGroups.length)&&t.subscription.filterExpression===c&&("0"===e||"0"===t.subscription.timetoken||t.subscription.timetoken===e)))},X=e=>Y(e),Y=e=>{var t;const n=h[e.clientIdentifier];if(!n)return[];const i=e.request.queryParameters,r=ie(n),s=i.uuid;return(null!==(t=p[e.subscriptionKey])&&void 0!==t?t:[]).filter((e=>e.userId===s&&ie(e)===r))},Z=e=>{const t=e.path.split("/")[e.path.startsWith("/v2/subscribe/")?4:6];return","===t?[]:t.split(",").filter((e=>e.length>0))},ee=e=>{var t;const n=null!==(t=e.queryParameters["channel-group"])&&void 0!==t?t:"";return 0===n.length?[]:n.split(",").filter((e=>e.length>0))},te=(e,t)=>{const n=new Set(e);return t.every(n.has,n)},ne=e=>{const t={type:"shared-worker-ping"},n=Object.values(h).filter((t=>t&&t.subscriptionKey===e));if(n.forEach((e=>{let i=!1;if(e&&e.lastPingRequest){const t=e.offlineClientsCheckInterval;if(!e.lastPongEvent||Math.abs(e.lastPongEvent-e.lastPingRequest)>.5*t){i=!0;for(const t of n)oe(`'${e.clientIdentifier}' client is inactive. Invalidating...`,t);J(e.subscriptionKey,e.clientIdentifier)}}e&&!i&&(e.lastPingRequest=(new Date).getTime()/1e3,A(e,t))})),n&&n.length>0&&n[0]){const t=n[0].offlineClientsCheckInterval;a[e]=setTimeout((()=>ne(e)),500*t-1)}},ie=e=>{var t;return e.accessToken&&null!==(t=e.accessToken.token)&&void 0!==t?t:e.authKey},re=e=>{const t=e.filter((e=>!!e.accessToken)).sort(((e,t)=>e.accessToken.expiration-t.accessToken.expiration)).pop();return t?t.authKey:void 0},se=e=>{const t=ie(e);let n=`${e.userId}-${e.subscriptionKey}${t?`-${t}`:""}`;return e.subscription&&e.subscription.filterExpression&&(n+=`-${e.subscription.filterExpression}`),n},oe=(e,t)=>{const n=(t?[t]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),i={type:"shared-worker-console-log",message:e};n.forEach((e=>{e&&A(e,i)}))},ce=(e,t,n)=>{const i=(n?[n]:Object.values(h)).filter((e=>e&&e.workerLogVerbosity)),r={type:"shared-worker-console-dir",message:t,data:e};i.forEach((e=>{e&&A(e,r)}))},le=e=>Object.keys(e).map((t=>{const n=e[t];return Array.isArray(n)?n.map((e=>`${t}=${ue(e)}`)).join("&"):`${t}=${ue(n)}`})).join("&"),ue=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`))})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 2ac8caaff..8497ab8ac 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -124,7 +124,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '9.3.2'; + return '9.4.0'; }, getVersion() { return this.version; diff --git a/lib/core/components/request.js b/lib/core/components/request.js index 8ef292d73..009611791 100644 --- a/lib/core/components/request.js +++ b/lib/core/components/request.js @@ -101,12 +101,13 @@ class AbstractRequest { * @returns Request object which can be processed using platform-specific requirements. */ request() { - var _a, _b, _c, _d; + var _a, _b, _c, _d, _e, _f; const request = { method: (_b = (_a = this.params) === null || _a === void 0 ? void 0 : _a.method) !== null && _b !== void 0 ? _b : transport_request_1.TransportMethod.GET, path: this.path, queryParameters: this.queryParameters, cancellable: (_d = (_c = this.params) === null || _c === void 0 ? void 0 : _c.cancellable) !== null && _d !== void 0 ? _d : false, + compressible: (_f = (_e = this.params) === null || _e === void 0 ? void 0 : _e.compressible) !== null && _f !== void 0 ? _f : false, timeout: 10, identifier: this.requestIdentifier, }; @@ -130,7 +131,8 @@ class AbstractRequest { * @returns Key/value headers which should be used with request. */ get headers() { - return undefined; + var _a, _b; + return Object.assign({ 'Accept-Encoding': 'gzip, deflate' }, (((_b = (_a = this.params) === null || _a === void 0 ? void 0 : _a.compressible) !== null && _b !== void 0 ? _b : false) ? { 'Content-Encoding': 'deflate' } : {})); } /** * Target REST API endpoint request path getter. diff --git a/lib/core/endpoints/access_manager/grant_token.js b/lib/core/endpoints/access_manager/grant_token.js index 1ad1d5151..8d6230e74 100644 --- a/lib/core/endpoints/access_manager/grant_token.js +++ b/lib/core/endpoints/access_manager/grant_token.js @@ -82,7 +82,8 @@ class GrantTokenRequest extends request_1.AbstractRequest { return `/v3/pam/${this.parameters.keySet.subscribeKey}/grant`; } get headers() { - return { 'Content-Type': 'application/json' }; + var _a; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'Content-Type': 'application/json' }); } get body() { const { ttl, meta } = this.parameters; diff --git a/lib/core/endpoints/actions/add_message_action.js b/lib/core/endpoints/actions/add_message_action.js index 4be106070..f1ee1d776 100644 --- a/lib/core/endpoints/actions/add_message_action.js +++ b/lib/core/endpoints/actions/add_message_action.js @@ -66,7 +66,8 @@ class AddMessageActionRequest extends request_1.AbstractRequest { return `/v1/message-actions/${subscribeKey}/channel/${(0, utils_1.encodeString)(channel)}/message/${messageTimetoken}`; } get headers() { - return { 'Content-Type': 'application/json' }; + var _a; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'Content-Type': 'application/json' }); } get body() { return JSON.stringify(this.parameters.action); diff --git a/lib/core/endpoints/file_upload/generate_upload_url.js b/lib/core/endpoints/file_upload/generate_upload_url.js index 57416cea1..d4f93d10f 100644 --- a/lib/core/endpoints/file_upload/generate_upload_url.js +++ b/lib/core/endpoints/file_upload/generate_upload_url.js @@ -58,7 +58,8 @@ class GenerateFileUploadUrlRequest extends request_1.AbstractRequest { return `/v1/files/${subscribeKey}/channels/${(0, utils_1.encodeString)(channel)}/generate-upload-url`; } get headers() { - return { 'Content-Type': 'application/json' }; + var _a; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'Content-Type': 'application/json' }); } get body() { return JSON.stringify({ name: this.parameters.name }); diff --git a/lib/core/endpoints/objects/channel/set.js b/lib/core/endpoints/objects/channel/set.js index 74a89c36e..283cfb226 100644 --- a/lib/core/endpoints/objects/channel/set.js +++ b/lib/core/endpoints/objects/channel/set.js @@ -47,11 +47,12 @@ class SetChannelMetadataRequest extends request_1.AbstractRequest { return 'Data cannot be empty'; } get headers() { + var _a; if (this.parameters.ifMatchesEtag) { - return { 'If-Match': this.parameters.ifMatchesEtag }; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'If-Match': this.parameters.ifMatchesEtag }); } else { - return undefined; + return super.headers; } } get path() { diff --git a/lib/core/endpoints/objects/uuid/set.js b/lib/core/endpoints/objects/uuid/set.js index 17669ca9b..e31609946 100644 --- a/lib/core/endpoints/objects/uuid/set.js +++ b/lib/core/endpoints/objects/uuid/set.js @@ -50,11 +50,12 @@ class SetUUIDMetadataRequest extends request_1.AbstractRequest { return 'Data cannot be empty'; } get headers() { + var _a; if (this.parameters.ifMatchesEtag) { - return { 'If-Match': this.parameters.ifMatchesEtag }; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'If-Match': this.parameters.ifMatchesEtag }); } else { - return undefined; + return super.headers; } } get path() { diff --git a/lib/core/endpoints/publish.js b/lib/core/endpoints/publish.js index 1bffd8ed6..c4723254b 100644 --- a/lib/core/endpoints/publish.js +++ b/lib/core/endpoints/publish.js @@ -46,11 +46,11 @@ class PublishRequest extends request_1.AbstractRequest { */ constructor(parameters) { var _a; - var _b; - super({ method: parameters.sendByPost ? transport_request_1.TransportMethod.POST : transport_request_1.TransportMethod.GET }); + const sendByPost = (_a = parameters.sendByPost) !== null && _a !== void 0 ? _a : SEND_BY_POST; + super({ method: sendByPost ? transport_request_1.TransportMethod.POST : transport_request_1.TransportMethod.GET, compressible: sendByPost }); this.parameters = parameters; // Apply default request parameters. - (_a = (_b = this.parameters).sendByPost) !== null && _a !== void 0 ? _a : (_b.sendByPost = SEND_BY_POST); + this.parameters.sendByPost = sendByPost; } operation() { return operations_1.default.PNPublishOperation; @@ -90,9 +90,10 @@ class PublishRequest extends request_1.AbstractRequest { return query; } get headers() { + var _a; if (!this.parameters.sendByPost) return undefined; - return { 'Content-Type': 'application/json' }; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { 'Content-Type': 'application/json' }); } get body() { return this.prepareMessagePayload(this.parameters.message); diff --git a/lib/core/endpoints/subscribe.js b/lib/core/endpoints/subscribe.js index 03b9c1533..a06301b8e 100644 --- a/lib/core/endpoints/subscribe.js +++ b/lib/core/endpoints/subscribe.js @@ -176,7 +176,8 @@ class BaseSubscribeRequest extends request_1.AbstractRequest { }); } get headers() { - return { accept: 'text/javascript' }; + var _a; + return Object.assign(Object.assign({}, ((_a = super.headers) !== null && _a !== void 0 ? _a : {})), { accept: 'text/javascript' }); } // -------------------------------------------------------- // ------------------ Envelope parsing -------------------- diff --git a/lib/transport/node-transport.js b/lib/transport/node-transport.js index 5dad44887..ba5ca865a 100644 --- a/lib/transport/node-transport.js +++ b/lib/transport/node-transport.js @@ -57,6 +57,7 @@ const https_1 = require("https"); const http_1 = require("http"); const form_data_1 = __importDefault(require("form-data")); const buffer_1 = require("buffer"); +const zlib = __importStar(require("zlib")); const pubnub_api_error_1 = require("../errors/pubnub-api-error"); const utils_1 = require("../core/utils"); /** @@ -178,8 +179,10 @@ class NodeTransport { headers = formData.getHeaders(headers !== null && headers !== void 0 ? headers : {}); } // Handle regular body payload (if passed). - else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) - body = req.body; + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) { + // Compressing body (if required). + body = req.compressible ? zlib.deflateSync(req.body) : req.body; + } if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) path = `${path}?${(0, utils_1.queryStringFromObject)(req.queryParameters)}`; return new node_fetch_1.Request(`${req.origin}${path}`, { diff --git a/lib/transport/react-native-transport.js b/lib/transport/react-native-transport.js index 4372dcdd1..cd484f66e 100644 --- a/lib/transport/react-native-transport.js +++ b/lib/transport/react-native-transport.js @@ -15,6 +15,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReactNativeTransport = void 0; +const fflate_1 = require("fflate"); const pubnub_api_error_1 = require("../errors/pubnub-api-error"); const utils_1 = require("../core/utils"); /** @@ -146,8 +147,13 @@ class ReactNativeTransport { body = formData; } // Handle regular body payload (if passed). - else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) - body = req.body; + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) { + if (req.compressible) { + body = (0, fflate_1.gzipSync)(typeof req.body === 'string' ? ReactNativeTransport.encoder.encode(req.body) : new Uint8Array(req.body)); + } + else + body = req.body; + } if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) path = `${path}?${(0, utils_1.queryStringFromObject)(req.queryParameters)}`; return new Request(`${req.origin}${path}`, { @@ -196,6 +202,12 @@ class ReactNativeTransport { } } exports.ReactNativeTransport = ReactNativeTransport; +/** + * Request body decoder. + * + * @internal + */ +ReactNativeTransport.encoder = new TextEncoder(); /** * Service {@link ArrayBuffer} response decoder. * diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 263757806..4f4cc5e3a 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -2968,6 +2968,10 @@ declare namespace PubNub { * @default `false`. */ cancellable: boolean; + /** + * Whether `POST` body should be compressed or not. + */ + compressible: boolean; /** * Unique request identifier. */ diff --git a/package-lock.json b/package-lock.json index ecde6d336..93b2abefa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,18 +1,19 @@ { "name": "pubnub", - "version": "9.3.1", + "version": "9.3.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "9.3.1", + "version": "9.3.2", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", "buffer": "^6.0.3", "cbor-js": "^0.1.0", "cbor-sync": "^1.0.4", + "fflate": "^0.8.2", "form-data": "^4.0.0", "lil-uuid": "^0.1.1", "node-fetch": "^2.7.0", @@ -7343,6 +7344,12 @@ "bser": "2.1.1" } }, + "node_modules/fflate": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz", + "integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A==", + "license": "MIT" + }, "node_modules/figures": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/figures/-/figures-3.2.0.tgz", diff --git a/package.json b/package.json index 83b20737b..2b08025ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "9.3.2", + "version": "9.4.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { @@ -58,6 +58,7 @@ "buffer": "^6.0.3", "cbor-js": "^0.1.0", "cbor-sync": "^1.0.4", + "fflate": "^0.8.2", "form-data": "^4.0.0", "lil-uuid": "^0.1.1", "node-fetch": "^2.7.0", diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index c86b7049c..ff7bddf8c 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -182,7 +182,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '9.3.2'; + return '9.4.0'; }, getVersion(): string { return this.version; diff --git a/src/core/components/request.ts b/src/core/components/request.ts index 8863e5a07..8d7ef34cd 100644 --- a/src/core/components/request.ts +++ b/src/core/components/request.ts @@ -42,7 +42,9 @@ export abstract class AbstractRequest | undefined { - return undefined; + return { + 'Accept-Encoding': 'gzip, deflate', + ...((this.params?.compressible ?? false) ? { 'Content-Encoding': 'deflate' } : {}), + }; } /** diff --git a/src/core/endpoints/access_manager/grant_token.ts b/src/core/endpoints/access_manager/grant_token.ts index 329faaca9..6c985f10d 100644 --- a/src/core/endpoints/access_manager/grant_token.ts +++ b/src/core/endpoints/access_manager/grant_token.ts @@ -152,7 +152,7 @@ export class GrantTokenRequest extends AbstractRequest | undefined { - return { 'Content-Type': 'application/json' }; + return { ...(super.headers ?? {}), 'Content-Type': 'application/json' }; } protected get body(): string { diff --git a/src/core/endpoints/actions/add_message_action.ts b/src/core/endpoints/actions/add_message_action.ts index 10f06e8f4..fb48e537a 100644 --- a/src/core/endpoints/actions/add_message_action.ts +++ b/src/core/endpoints/actions/add_message_action.ts @@ -89,7 +89,7 @@ export class AddMessageActionRequest extends AbstractRequest | undefined { - return { 'Content-Type': 'application/json' }; + return { ...(super.headers ?? {}), 'Content-Type': 'application/json' }; } protected get body(): ArrayBuffer | string | undefined { diff --git a/src/core/endpoints/file_upload/generate_upload_url.ts b/src/core/endpoints/file_upload/generate_upload_url.ts index 66c87379a..19f5de96a 100644 --- a/src/core/endpoints/file_upload/generate_upload_url.ts +++ b/src/core/endpoints/file_upload/generate_upload_url.ts @@ -141,7 +141,7 @@ export class GenerateFileUploadUrlRequest extends AbstractRequest< } protected get headers(): Record | undefined { - return { 'Content-Type': 'application/json' }; + return { ...(super.headers ?? {}), 'Content-Type': 'application/json' }; } protected get body(): ArrayBuffer | string | undefined { diff --git a/src/core/endpoints/objects/channel/set.ts b/src/core/endpoints/objects/channel/set.ts index 65a96cfc6..8d7c414d7 100644 --- a/src/core/endpoints/objects/channel/set.ts +++ b/src/core/endpoints/objects/channel/set.ts @@ -66,9 +66,9 @@ export class SetChannelMetadataRequest< protected get headers(): Record | undefined { if (this.parameters.ifMatchesEtag) { - return { 'If-Match': this.parameters.ifMatchesEtag }; + return { ...(super.headers ?? {}), 'If-Match': this.parameters.ifMatchesEtag }; } else { - return undefined; + return super.headers; } } diff --git a/src/core/endpoints/objects/uuid/set.ts b/src/core/endpoints/objects/uuid/set.ts index 17be16d55..c2a060d70 100644 --- a/src/core/endpoints/objects/uuid/set.ts +++ b/src/core/endpoints/objects/uuid/set.ts @@ -69,9 +69,9 @@ export class SetUUIDMetadataRequest< protected get headers(): Record | undefined { if (this.parameters.ifMatchesEtag) { - return { 'If-Match': this.parameters.ifMatchesEtag }; + return { ...(super.headers ?? {}), 'If-Match': this.parameters.ifMatchesEtag }; } else { - return undefined; + return super.headers; } } diff --git a/src/core/endpoints/publish.ts b/src/core/endpoints/publish.ts index 14683c025..8bfa4a17a 100644 --- a/src/core/endpoints/publish.ts +++ b/src/core/endpoints/publish.ts @@ -139,10 +139,12 @@ export class PublishRequest extends AbstractRequest | undefined { if (!this.parameters.sendByPost) return undefined; - return { 'Content-Type': 'application/json' }; + return { ...(super.headers ?? {}), 'Content-Type': 'application/json' }; } protected get body(): ArrayBuffer | string | undefined { diff --git a/src/core/endpoints/subscribe.ts b/src/core/endpoints/subscribe.ts index f972115ac..9d4053e77 100644 --- a/src/core/endpoints/subscribe.ts +++ b/src/core/endpoints/subscribe.ts @@ -714,7 +714,7 @@ export class BaseSubscribeRequest extends AbstractRequest | undefined { - return { accept: 'text/javascript' }; + return { ...(super.headers ?? {}), accept: 'text/javascript' }; } // -------------------------------------------------------- diff --git a/src/core/types/transport-request.ts b/src/core/types/transport-request.ts index e2bcc62e7..c5f8f300a 100644 --- a/src/core/types/transport-request.ts +++ b/src/core/types/transport-request.ts @@ -103,6 +103,11 @@ export type TransportRequest = { */ cancellable: boolean; + /** + * Whether `POST` body should be compressed or not. + */ + compressible: boolean; + /** * Unique request identifier. */ diff --git a/src/transport/node-transport.ts b/src/transport/node-transport.ts index a09f0b381..36f57e2fc 100644 --- a/src/transport/node-transport.ts +++ b/src/transport/node-transport.ts @@ -10,6 +10,7 @@ import { Agent as HttpsAgent } from 'https'; import { Agent as HttpAgent } from 'http'; import FormData from 'form-data'; import { Buffer } from 'buffer'; +import * as zlib from 'zlib'; import { CancellationController, TransportRequest } from '../core/types/transport-request'; import { Transport, TransportKeepAlive } from '../core/interfaces/transport'; @@ -173,7 +174,10 @@ export class NodeTransport implements Transport { headers = formData.getHeaders(headers ?? {}); } // Handle regular body payload (if passed). - else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) body = req.body; + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) { + // Compressing body (if required). + body = req.compressible ? zlib.deflateSync(req.body) : req.body; + } if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) path = `${path}?${queryStringFromObject(req.queryParameters)}`; diff --git a/src/transport/react-native-transport.ts b/src/transport/react-native-transport.ts index 492787ad7..57988c875 100644 --- a/src/transport/react-native-transport.ts +++ b/src/transport/react-native-transport.ts @@ -4,6 +4,8 @@ * @internal */ +import { gzipSync } from 'fflate'; + import { CancellationController, TransportRequest } from '../core/types/transport-request'; import { TransportResponse } from '../core/types/transport-response'; import { PubNubAPIError } from '../errors/pubnub-api-error'; @@ -17,6 +19,13 @@ import { queryStringFromObject } from '../core/utils'; * @internal */ export class ReactNativeTransport implements Transport { + /** + * Request body decoder. + * + * @internal + */ + protected static encoder = new TextEncoder(); + /** * Service {@link ArrayBuffer} response decoder. * @@ -161,7 +170,13 @@ export class ReactNativeTransport implements Transport { body = formData; } // Handle regular body payload (if passed). - else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) body = req.body; + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) { + if (req.compressible) { + body = gzipSync( + typeof req.body === 'string' ? ReactNativeTransport.encoder.encode(req.body) : new Uint8Array(req.body), + ); + } else body = req.body; + } if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) path = `${path}?${queryStringFromObject(req.queryParameters)}`; diff --git a/src/transport/subscription-worker/subscription-worker.ts b/src/transport/subscription-worker/subscription-worker.ts index 59b694f37..e58735c94 100644 --- a/src/transport/subscription-worker/subscription-worker.ts +++ b/src/transport/subscription-worker/subscription-worker.ts @@ -2264,6 +2264,7 @@ const unsubscribeClient = (client: PubNubClientState) => { headers: {}, timeout: 10, cancellable: false, + compressible: false, identifier: query.requestid as string, }, }; diff --git a/src/transport/web-transport.ts b/src/transport/web-transport.ts index 2facc4bfd..7ecca83b5 100644 --- a/src/transport/web-transport.ts +++ b/src/transport/web-transport.ts @@ -68,6 +68,13 @@ export class WebTransport implements Transport { */ private static originalFetch: typeof fetch; + /** + * Request body decoder. + * + * @internal + */ + protected static encoder = new TextEncoder(); + /** * Service {@link ArrayBuffer} response decoder. * @@ -311,7 +318,19 @@ export class WebTransport implements Transport { body = formData; } // Handle regular body payload (if passed). - else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) body = req.body; + else if (req.body && (typeof req.body === 'string' || req.body instanceof ArrayBuffer)) { + // Compressing body if browser has native support. + if (req.compressible && typeof CompressionStream !== 'undefined') { + const bodyStream = new ReadableStream({ + start(controller) { + controller.enqueue(typeof req.body === 'string' ? WebTransport.encoder.encode(req.body) : req.body); + controller.close(); + }, + }); + + body = await new Response(bodyStream.pipeThrough(new CompressionStream('deflate'))).arrayBuffer(); + } else body = req.body; + } if (req.queryParameters && Object.keys(req.queryParameters).length !== 0) path = `${path}?${queryStringFromObject(req.queryParameters)}`; diff --git a/test/integration/endpoints/publish.test.ts b/test/integration/endpoints/publish.test.ts index 4df436825..8e36af414 100644 --- a/test/integration/endpoints/publish.test.ts +++ b/test/integration/endpoints/publish.test.ts @@ -1,6 +1,7 @@ /* global describe, beforeEach, it, before, after */ /* eslint no-console: 0 */ +import * as zlib from 'zlib'; import assert from 'assert'; import nock from 'nock'; @@ -240,9 +241,24 @@ describe('publish endpoints', () => { }); it('publishes a complex object via POST', (done) => { + const expectedRawBody = '{"such":"object"}'; const scope = utils .createNock() - .post('/publish/myPublishKey/mySubKey/0/ch1/0', '{"such":"object"}') + .post('/publish/myPublishKey/mySubKey/0/ch1/0', (body) => { + let decompressed: string; + let buffer; + if (typeof body === 'string' && /^[0-9a-f]+$/i.test(body)) buffer = Buffer.from(body, 'hex'); + else if (Buffer.isBuffer(body)) buffer = body; + else return false; + + try { + decompressed = zlib.inflateSync(buffer).toString('utf-8'); + } catch (_err) { + return false; + } + + return decompressed === expectedRawBody; + }) .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', @@ -264,9 +280,24 @@ describe('publish endpoints', () => { }); it('publishes a complex object via POST with encryption', (done) => { + const expectedRawBody = '"toDEeIZkmIyoiLpSojGu7n3+2t1rn7/DsrEZ1r8JKR4="'; const scope = utils .createNock() - .post('/publish/myPublishKey/mySubKey/0/ch1/0', '"toDEeIZkmIyoiLpSojGu7n3+2t1rn7/DsrEZ1r8JKR4="') + .post('/publish/myPublishKey/mySubKey/0/ch1/0', (body) => { + let decompressed: string; + let buffer; + if (typeof body === 'string' && /^[0-9a-f]+$/i.test(body)) buffer = Buffer.from(body, 'hex'); + else if (Buffer.isBuffer(body)) buffer = body; + else return false; + + try { + decompressed = zlib.inflateSync(buffer).toString('utf-8'); + } catch (_err) { + return false; + } + + return decompressed === expectedRawBody; + }) .query({ pnsdk: `PubNub-JS-Nodejs/${pubnub.getVersion()}`, uuid: 'myUUID', From b283e9e8b8c05f76f7b6701f259c407cd1ab11df Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 15 Apr 2025 12:29:31 +0300 Subject: [PATCH 47/49] Retry policy now applies to all requests and subscription change status emitted (#451) feat(retry-policy): retry policy now applies to all requests The configured retry policy will be used for any failed request. feat(retry-policy): exponential retry policy used by default for subscribe By default, the SDK is configured to use an exponential retry policy for failed subscribe requests. feat(retry-policy): add `None` retry policy Add type, which should be used to completely disable retries. fix(subscribe): add missing `subscription change` status `PNSubscriptionChangedCategory` will be emitted each time the list of channels and groups is changing. refactor(network): request retries moved to the network Automated request retry has been moved into the network layer to handle all requests (not only subscribed). refactor(retry-policy): add information about which APIs belong to endpoint Add more information about which APIs are related to the endpoints, which can be excluded. --- .mocharc.json | 3 +- .pubnub.yml | 19 +- CHANGELOG.md | 14 + README.md | 4 +- dist/web/pubnub.js | 1051 ++++++++--------- dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 21 +- lib/core/components/retryPolicy.js | 184 +++ lib/core/constants/categories.js | 4 + lib/core/endpoints/presence/heartbeat.js | 2 +- lib/core/pubnub-common.js | 52 +- lib/event-engine/core/retryPolicy.js | 80 -- lib/event-engine/dispatcher.js | 60 +- lib/event-engine/effects.js | 18 +- lib/event-engine/events.js | 57 +- lib/event-engine/index.js | 20 +- lib/event-engine/presence/dispatcher.js | 32 +- lib/event-engine/presence/effects.js | 12 +- lib/event-engine/presence/events.js | 12 +- lib/event-engine/presence/presence.js | 7 + .../presence/states/heartbeat_cooldown.js | 7 +- .../presence/states/heartbeat_failed.js | 7 +- .../presence/states/heartbeat_reconnecting.js | 54 - .../presence/states/heartbeating.js | 31 +- lib/event-engine/states/handshake_failed.js | 20 +- .../states/handshake_reconnecting.js | 74 -- lib/event-engine/states/handshake_stopped.js | 19 +- lib/event-engine/states/handshaking.js | 69 +- lib/event-engine/states/receive_failed.js | 23 +- .../states/receive_reconnecting.js | 63 - lib/event-engine/states/receive_stopped.js | 23 +- lib/event-engine/states/receiving.js | 88 +- lib/event-engine/states/unsubscribed.js | 13 +- lib/transport/middleware.js | 57 +- lib/types/index.d.ts | 237 ++-- package-lock.json | 87 +- package.json | 11 +- src/core/components/configuration.ts | 25 +- src/core/components/retryPolicy.ts | 359 ++++++ src/core/constants/categories.ts | 5 + src/core/endpoints/presence/heartbeat.ts | 2 +- src/core/interfaces/configuration.ts | 4 +- src/core/pubnub-common.ts | 56 +- src/core/types/api/index.ts | 2 +- src/event-engine/core/retryPolicy.ts | 158 --- src/event-engine/dispatcher.ts | 91 +- src/event-engine/effects.ts | 35 +- src/event-engine/events.ts | 68 +- src/event-engine/index.ts | 20 +- src/event-engine/presence/dispatcher.ts | 47 +- src/event-engine/presence/effects.ts | 19 +- src/event-engine/presence/events.ts | 12 +- src/event-engine/presence/presence.ts | 9 + .../presence/states/heartbeat_cooldown.ts | 12 +- .../presence/states/heartbeat_failed.ts | 12 +- .../presence/states/heartbeat_reconnecting.ts | 100 -- .../presence/states/heartbeating.ts | 44 +- src/event-engine/states/handshake_failed.ts | 22 +- .../states/handshake_reconnecting.ts | 114 -- src/event-engine/states/handshake_stopped.ts | 26 +- src/event-engine/states/handshaking.ts | 97 +- src/event-engine/states/receive_failed.ts | 25 +- .../states/receive_reconnecting.ts | 114 -- src/event-engine/states/receive_stopped.ts | 25 +- src/event-engine/states/receiving.ts | 108 +- src/event-engine/states/unsubscribed.ts | 17 +- src/transport/middleware.ts | 67 +- src/web/index.ts | 2 +- test/integration/components/crypto.test.ts | 1 + test/integration/components/listeners.test.ts | 6 +- .../integration/components/networking.test.ts | 10 +- .../components/reconnection_manager.test.ts | 6 +- .../components/subscription_manager.test.ts | 13 +- .../components/token_manager.test.ts | 18 +- test/integration/endpoints/access.test.ts | 58 +- .../endpoints/channel_groups.test.ts | 13 +- .../endpoints/fetch_messages.test.ts | 6 +- .../integration/endpoints/grant_token.test.ts | 12 +- test/integration/endpoints/history.test.ts | 6 +- .../endpoints/message_actions.test.ts | 6 +- .../endpoints/message_counts.test.ts | 8 +- .../endpoints/objects/channel.test.ts | 8 +- .../endpoints/objects/membership.test.ts | 8 +- .../endpoints/objects/uuid.test.ts | 8 +- test/integration/endpoints/presence.test.ts | 146 +-- test/integration/endpoints/publish.test.ts | 8 +- test/integration/endpoints/push.test.ts | 14 +- test/integration/endpoints/signal.test.ts | 8 +- test/integration/endpoints/subscribe.test.ts | 9 +- test/integration/endpoints/time.test.ts | 12 +- test/integration/operations/heartbeat.test.ts | 12 +- .../operations/stateSetting.test.ts | 20 +- .../operations/unsubscribe.test.ts | 6 +- test/setup-why.ts | 13 + test/unit/event_engine.test.ts | 53 +- 95 files changed, 2190 insertions(+), 2534 deletions(-) create mode 100644 lib/core/components/retryPolicy.js delete mode 100644 lib/event-engine/core/retryPolicy.js delete mode 100644 lib/event-engine/presence/states/heartbeat_reconnecting.js delete mode 100644 lib/event-engine/states/handshake_reconnecting.js delete mode 100644 lib/event-engine/states/receive_reconnecting.js create mode 100644 src/core/components/retryPolicy.ts delete mode 100644 src/event-engine/core/retryPolicy.ts delete mode 100644 src/event-engine/presence/states/heartbeat_reconnecting.ts delete mode 100644 src/event-engine/states/handshake_reconnecting.ts delete mode 100644 src/event-engine/states/receive_reconnecting.ts create mode 100644 test/setup-why.ts diff --git a/.mocharc.json b/.mocharc.json index eb96a9a45..daf29e5d2 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -1,5 +1,6 @@ { "require": "tsx", + "file": ["test/setup-why.ts"], "spec": "test/**/*.test.ts", "exclude": [ "test/dist/*.{js,ts}", @@ -7,4 +8,4 @@ ], "timeout": 5000, "reporter": "spec" -} \ No newline at end of file +} diff --git a/.pubnub.yml b/.pubnub.yml index 0d87323d2..e202fcdcc 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,18 @@ --- changelog: + - date: 2025-04-15 + version: v9.5.0 + changes: + - type: feature + text: "The configured retry policy will be used for any failed request." + - type: feature + text: "By default, the SDK is configured to use an exponential retry policy for failed subscribe requests." + - type: bug + text: "`PNSubscriptionChangedCategory` will be emitted each time the list of channels and groups is changing." + - type: improvement + text: "Automated request retry has been moved into the network layer to handle all requests (not only subscribed)." + - type: improvement + text: "Properly destroy `PubNub` instance after each test case to make sure that all connections closed and prevent tests from hanging." - date: 2025-04-10 version: v9.4.0 changes: @@ -1209,7 +1222,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '9.4.0' +version: '9.5.0' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1225,7 +1238,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v9.4.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.5.0.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1896,7 +1909,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v9.4.0/pubnub.9.4.0.js + location: https://github.com/pubnub/javascript/releases/download/v9.5.0/pubnub.9.5.0.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 386910969..dedd3e023 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,17 @@ +## v9.5.0 +April 15 2025 + +#### Added +- The configured retry policy will be used for any failed request. +- By default, the SDK is configured to use an exponential retry policy for failed subscribe requests. + +#### Fixed +- `PNSubscriptionChangedCategory` will be emitted each time the list of channels and groups is changing. + +#### Modified +- Automated request retry has been moved into the network layer to handle all requests (not only subscribed). +- Properly destroy `PubNub` instance after each test case to make sure that all connections closed and prevent tests from hanging. + ## v9.4.0 April 10 2025 diff --git a/README.md b/README.md index 2c423ba86..c24a6d91a 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.4.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.4.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.0.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.0.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 09f25cfcb..6e6d50265 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -869,6 +869,10 @@ * PubNub client connected to the real-time updates stream. */ StatusCategory["PNConnectedCategory"] = "PNConnectedCategory"; + /** + * Set of active channels and groups has been changed. + */ + StatusCategory["PNSubscriptionChangedCategory"] = "PNSubscriptionChangedCategory"; /** * Received real-time updates exceed specified threshold. * @@ -3756,6 +3760,183 @@ listenToBrowserNetworkEvents: (_a = configuration.listenToBrowserNetworkEvents) !== null && _a !== void 0 ? _a : LISTEN_TO_BROWSER_NETWORK_EVENTS, subscriptionWorkerUrl: configuration.subscriptionWorkerUrl, subscriptionWorkerOfflineClientsCheckInterval: (_b = configuration.subscriptionWorkerOfflineClientsCheckInterval) !== null && _b !== void 0 ? _b : SUBSCRIPTION_WORKER_OFFLINE_CLIENTS_CHECK_INTERVAL, subscriptionWorkerUnsubscribeOfflineClients: (_c = configuration.subscriptionWorkerUnsubscribeOfflineClients) !== null && _c !== void 0 ? _c : SUBSCRIPTION_WORKER_UNSUBSCRIBE_OFFLINE_CLIENTS, subscriptionWorkerLogVerbosity: (_d = configuration.subscriptionWorkerLogVerbosity) !== null && _d !== void 0 ? _d : SUBSCRIPTION_WORKER_LOG_VERBOSITY, transport: (_e = configuration.transport) !== null && _e !== void 0 ? _e : TRANSPORT, keepAlive: (_f = configuration.keepAlive) !== null && _f !== void 0 ? _f : KEEP_ALIVE }); }; + // -------------------------------------------------------- + // ------------------------ Types ------------------------- + // -------------------------------------------------------- + // region Types + /** + * List of known endpoint groups (by context). + */ + var Endpoint; + (function (Endpoint) { + /** + * Unknown endpoint. + * + * @internal + */ + Endpoint["Unknown"] = "UnknownEndpoint"; + /** + * The endpoints to send messages. + */ + Endpoint["MessageSend"] = "MessageSendEndpoint"; + /** + * The endpoint for real-time update retrieval. + */ + Endpoint["Subscribe"] = "SubscribeEndpoint"; + /** + * The endpoint to access and manage `user_id` presence and fetch channel presence information. + */ + Endpoint["Presence"] = "PresenceEndpoint"; + /** + * The endpoint to access and manage files in channel-specific storage. + */ + Endpoint["Files"] = "FilesEndpoint"; + /** + * The endpoint to access and manage messages for a specific channel(s) in the persistent storage. + */ + Endpoint["MessageStorage"] = "MessageStorageEndpoint"; + /** + * The endpoint to access and manage channel groups. + */ + Endpoint["ChannelGroups"] = "ChannelGroupsEndpoint"; + /** + * The endpoint to access and manage device registration for channel push notifications. + */ + Endpoint["DevicePushNotifications"] = "DevicePushNotificationsEndpoint"; + /** + * The endpoint to access and manage App Context objects. + */ + Endpoint["AppContext"] = "AppContextEndpoint"; + /** + * The endpoint to access and manage reactions for a specific message. + */ + Endpoint["MessageReactions"] = "MessageReactionsEndpoint"; + })(Endpoint || (Endpoint = {})); + // endregion + /** + * Failed request retry policy. + */ + class RetryPolicy { + static LinearRetryPolicy(configuration) { + var _a; + return { + delay: configuration.delay, + maximumRetry: configuration.maximumRetry, + excluded: (_a = configuration.excluded) !== null && _a !== void 0 ? _a : [], + shouldRetry(request, response, error, attempt) { + return isRetriableRequest(request, response, error, attempt !== null && attempt !== void 0 ? attempt : 0, this.maximumRetry, this.excluded); + }, + getDelay(_, response) { + let delay = -1; + if (response && response.headers['retry-after'] !== undefined) + delay = parseInt(response.headers['retry-after'], 10); + if (delay === -1) + delay = this.delay; + return (delay + Math.random()) * 1000; + }, + validate() { + if (this.delay < 2) + throw new Error('Delay can not be set less than 2 seconds for retry'); + if (this.maximumRetry > 10) + throw new Error('Maximum retry for linear retry policy can not be more than 10'); + }, + }; + } + static ExponentialRetryPolicy(configuration) { + var _a; + return { + minimumDelay: configuration.minimumDelay, + maximumDelay: configuration.maximumDelay, + maximumRetry: configuration.maximumRetry, + excluded: (_a = configuration.excluded) !== null && _a !== void 0 ? _a : [], + shouldRetry(request, response, error, attempt) { + return isRetriableRequest(request, response, error, attempt !== null && attempt !== void 0 ? attempt : 0, this.maximumRetry, this.excluded); + }, + getDelay(attempt, response) { + let delay = -1; + if (response && response.headers['retry-after'] !== undefined) + delay = parseInt(response.headers['retry-after'], 10); + if (delay === -1) + delay = Math.min(Math.pow(2, attempt), this.maximumDelay); + return (delay + Math.random()) * 1000; + }, + validate() { + if (this.minimumDelay < 2) + throw new Error('Minimum delay can not be set less than 2 seconds for retry'); + else if (this.maximumDelay > 150) + throw new Error('Maximum delay can not be set more than 150 seconds for' + ' retry'); + else if (this.maximumRetry > 6) + throw new Error('Maximum retry for exponential retry policy can not be more than 6'); + }, + }; + } + } + /** + * Check whether request can be retried or not. + * + * @param req - Request for which retry ability is checked. + * @param res - Service response which should be taken into consideration. + * @param errorCategory - Request processing error category. + * @param retryAttempt - Current retry attempt. + * @param maximumRetry - Maximum retry attempts count according to the retry policy. + * @param excluded - List of endpoints for which retry policy won't be applied. + * + * @return `true` if request can be retried. + * + * @internal + */ + const isRetriableRequest = (req, res, errorCategory, retryAttempt, maximumRetry, excluded) => { + if (errorCategory && errorCategory === StatusCategory$1.PNCancelledCategory) + return false; + else if (isExcludedRequest(req, excluded)) + return false; + else if (retryAttempt > maximumRetry) + return false; + return res ? res.status === 429 || res.status >= 500 : true; + }; + /** + * Check whether the provided request is in the list of endpoints for which retry is not allowed or not. + * + * @param req - Request which will be tested. + * @param excluded - List of excluded endpoints configured for retry policy. + * + * @returns `true` if request has been excluded and shouldn't be retried. + * + * @internal + */ + const isExcludedRequest = (req, excluded) => excluded && excluded.length > 0 ? excluded.includes(endpointFromRequest(req)) : false; + /** + * Identify API group from transport request. + * + * @param req - Request for which `path` will be analyzed to identify REST API group. + * + * @returns Endpoint group to which request belongs. + * + * @internal + */ + const endpointFromRequest = (req) => { + let endpoint = Endpoint.Unknown; + if (req.path.startsWith('/v2/subscribe')) + endpoint = Endpoint.Subscribe; + else if (req.path.startsWith('/publish/') || req.path.startsWith('/signal/')) + endpoint = Endpoint.MessageSend; + else if (req.path.startsWith('/v2/presence')) + endpoint = Endpoint.Presence; + else if (req.path.startsWith('/v2/history') || req.path.startsWith('/v3/history')) + endpoint = Endpoint.MessageStorage; + else if (req.path.startsWith('/v1/message-actions/')) + endpoint = Endpoint.MessageReactions; + else if (req.path.startsWith('/v1/channel-registration/')) + endpoint = Endpoint.ChannelGroups; + else if (req.path.startsWith('/v2/objects/')) + endpoint = Endpoint.ChannelGroups; + else if (req.path.startsWith('/v1/push/') || req.path.startsWith('/v2/push/')) + endpoint = Endpoint.DevicePushNotifications; + else if (req.path.startsWith('/v1/files/')) + endpoint = Endpoint.Files; + return endpoint; + }; + var uuid = {exports: {}}; /*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */ @@ -3847,6 +4028,24 @@ */ const makeConfiguration = (base, setupCryptoModule) => { var _a, _b, _c; + // Set default retry policy for subscribe (if new subscribe logic not used). + if (!base.retryConfiguration && base.enableEventEngine) { + base.retryConfiguration = RetryPolicy.ExponentialRetryPolicy({ + minimumDelay: 2, + maximumDelay: 150, + maximumRetry: 6, + excluded: [ + Endpoint.MessageSend, + Endpoint.Presence, + Endpoint.Files, + Endpoint.MessageStorage, + Endpoint.ChannelGroups, + Endpoint.DevicePushNotifications, + Endpoint.AppContext, + Endpoint.MessageReactions, + ], + }); + } // Ensure that retry policy has proper configuration (if has been set). (_a = base.retryConfiguration) === null || _a === void 0 ? void 0 : _a.validate(); (_b = base.useRandomIVs) !== null && _b !== void 0 ? _b : (base.useRandomIVs = USE_RANDOM_INITIALIZATION_VECTOR); @@ -3939,7 +4138,7 @@ return base.PubNubFile; }, get version() { - return '9.4.0'; + return '9.5.0'; }, getVersion() { return this.version; @@ -4310,7 +4509,58 @@ } } makeSendable(req) { - return this.configuration.transport.makeSendable(this.request(req)); + const retryPolicy = this.configuration.clientConfiguration.retryConfiguration; + const transport = this.configuration.transport; + // Make requests retryable. + if (retryPolicy !== undefined) { + let retryTimeout; + let activeCancellation; + let cancelled = false; + let attempt = 0; + const cancellation = { + abort: (reason) => { + cancelled = true; + if (retryTimeout) + clearTimeout(retryTimeout); + if (activeCancellation) + activeCancellation.abort(reason); + }, + }; + const retryableRequest = new Promise((resolve, reject) => { + const trySendRequest = () => { + // Check whether request already has been cancelled and there is no retry should proceed. + if (cancelled) + return; + const [attemptPromise, attemptCancellation] = transport.makeSendable(this.request(req)); + activeCancellation = attemptCancellation; + const responseHandler = (res, error) => { + const retriableError = error ? error.category !== StatusCategory$1.PNCancelledCategory : true; + const retriableStatusCode = !res || res.status >= 400; + let delay = -1; + if (retriableError && + retriableStatusCode && + retryPolicy.shouldRetry(req, res, error === null || error === void 0 ? void 0 : error.category, attempt + 1)) + delay = retryPolicy.getDelay(attempt, res); + if (delay > 0) { + attempt++; + retryTimeout = setTimeout(() => trySendRequest(), delay); + } + else { + if (res) + resolve(res); + else if (error) + reject(error); + } + }; + attemptPromise + .then((res) => responseHandler(res)) + .catch((err) => responseHandler(undefined, err)); + }; + trySendRequest(); + }); + return [retryableRequest, activeCancellation ? cancellation : undefined]; + } + return transport.makeSendable(this.request(req)); } request(req) { var _a; @@ -7339,7 +7589,7 @@ * * @internal */ - const disconnect$1 = createEvent('DISCONNECT', () => ({})); + const disconnect$1 = createEvent('DISCONNECT', (isOffline) => ({ isOffline })); /** * Channel / group join event. * @@ -7389,14 +7639,6 @@ * @internal */ const heartbeatFailure = createEvent('HEARTBEAT_FAILURE', (error) => error); - /** - * Presence heartbeat impossible event. - * - * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. - * - * @internal - */ - const heartbeatGiveup = createEvent('HEARTBEAT_GIVEUP', () => ({})); /** * Delayed presence heartbeat event. * @@ -7418,7 +7660,7 @@ * * @internal */ - const heartbeat = createEffect('HEARTBEAT', (channels, groups) => ({ + const heartbeat = createManagedEffect('HEARTBEAT', (channels, groups) => ({ channels, groups, })); @@ -7450,14 +7692,6 @@ * @internal */ const wait = createManagedEffect('WAIT', () => ({})); - /** - * Delayed heartbeat effect. - * - * Similar to the {@link wait} effect but used in case if previous heartbeat call did fail. - * - * @internal - */ - const delayedHeartbeat = createManagedEffect('DELAYED_HEARTBEAT', (context) => context); /** * Presence Event Engine effects dispatcher. @@ -7483,7 +7717,7 @@ if (e instanceof PubNubError) { if (e.status && e.status.category == StatusCategory$1.PNCancelledCategory) return; - return engine.transition(heartbeatFailure(e)); + engine.transition(heartbeatFailure(e)); } } }))); @@ -7504,34 +7738,12 @@ abortSignal.throwIfAborted(); return engine.transition(timesUp()); }))); - this.on(delayedHeartbeat.type, asyncHandler((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { heartbeat, retryDelay, presenceState, config }) { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - yield retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); - abortSignal.throwIfAborted(); - try { - const result = yield heartbeat(Object.assign(Object.assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })), { heartbeat: config.presenceTimeout })); - return engine.transition(heartbeatSuccess(200)); - } - catch (e) { - if (e instanceof PubNubError) { - if (e.status && e.status.category == StatusCategory$1.PNCancelledCategory) - return; - return engine.transition(heartbeatFailure(e)); - } - } - } - else { - return engine.transition(heartbeatGiveup()); - } - }))); this.on(emitStatus$1.type, asyncHandler((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus, config }) { - var _b; - if (config.announceFailedHeartbeats && ((_b = payload === null || payload === void 0 ? void 0 : payload.status) === null || _b === void 0 ? void 0 : _b.error) === true) { - emitStatus(payload.status); + if (config.announceFailedHeartbeats && (payload === null || payload === void 0 ? void 0 : payload.error) === true) { + emitStatus(Object.assign(Object.assign({}, payload), { operation: RequestOperation$1.PNHeartbeatOperation })); } else if (config.announceSuccessfulHeartbeats && payload.statusCode === 200) { - emitStatus(Object.assign(Object.assign({}, payload), { operation: RequestOperation$1.PNHeartbeatOperation, error: false })); + emitStatus(Object.assign(Object.assign({}, payload), { error: false, operation: RequestOperation$1.PNHeartbeatOperation, category: StatusCategory$1.PNAcknowledgmentCategory })); } }))); } @@ -7592,10 +7804,9 @@ channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), groups: context.groups.filter((group) => !event.payload.groups.includes(group)), }, [leave(event.payload.channels, event.payload.groups)])); - HeartbeatCooldownState.on(disconnect$1.type, (context) => HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [leave(context.channels, context.groups)])); + HeartbeatCooldownState.on(disconnect$1.type, (context, event) => HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ])); HeartbeatCooldownState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); /** @@ -7624,56 +7835,11 @@ channels: context.channels, groups: context.groups, })); - HeartbeatFailedState.on(disconnect$1.type, (context, _) => HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [leave(context.channels, context.groups)])); + HeartbeatFailedState.on(disconnect$1.type, (context, event) => HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ])); HeartbeatFailedState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); - /** - * Retry heartbeat state module. - * - * @internal - */ - /** - * Retry heartbeat state. - * - * State in which Presence Event Engine tries to recover after error which happened before. - * - * @internal - */ - const HearbeatReconnectingState = new State('HEARBEAT_RECONNECTING'); - HearbeatReconnectingState.onEnter((context) => delayedHeartbeat(context)); - HearbeatReconnectingState.onExit(() => delayedHeartbeat.cancel); - HearbeatReconnectingState.on(joined.type, (context, event) => HeartbeatingState.with({ - channels: [...context.channels, ...event.payload.channels], - groups: [...context.groups, ...event.payload.groups], - })); - HearbeatReconnectingState.on(left.type, (context, event) => HeartbeatingState.with({ - channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), - groups: context.groups.filter((group) => !event.payload.groups.includes(group)), - }, [leave(event.payload.channels, event.payload.groups)])); - HearbeatReconnectingState.on(disconnect$1.type, (context, _) => { - HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [leave(context.channels, context.groups)]); - }); - HearbeatReconnectingState.on(heartbeatSuccess.type, (context, event) => { - return HeartbeatCooldownState.with({ - channels: context.channels, - groups: context.groups, - }); - }); - HearbeatReconnectingState.on(heartbeatFailure.type, (context, event) => HearbeatReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); - HearbeatReconnectingState.on(heartbeatGiveup.type, (context, event) => { - return HeartbeatFailedState.with({ - channels: context.channels, - groups: context.groups, - }); - }); - HearbeatReconnectingState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); - /** * Heartbeating state module. * @@ -7688,12 +7854,10 @@ */ const HeartbeatingState = new State('HEARTBEATING'); HeartbeatingState.onEnter((context) => heartbeat(context.channels, context.groups)); - HeartbeatingState.on(heartbeatSuccess.type, (context, event) => { - return HeartbeatCooldownState.with({ - channels: context.channels, - groups: context.groups, - }); - }); + HeartbeatingState.onExit(() => heartbeat.cancel); + HeartbeatingState.on(heartbeatSuccess.type, (context, event) => HeartbeatCooldownState.with({ channels: context.channels, groups: context.groups }, [ + emitStatus$1(Object.assign({}, event.payload)), + ])); HeartbeatingState.on(joined.type, (context, event) => HeartbeatingState.with({ channels: [...context.channels, ...event.payload.channels], groups: [...context.groups, ...event.payload.groups], @@ -7704,13 +7868,12 @@ groups: context.groups.filter((group) => !event.payload.groups.includes(group)), }, [leave(event.payload.channels, event.payload.groups)]); }); - HeartbeatingState.on(heartbeatFailure.type, (context, event) => { - return HearbeatReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: 0, reason: event.payload })); - }); - HeartbeatingState.on(disconnect$1.type, (context) => HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [leave(context.channels, context.groups)])); + HeartbeatingState.on(heartbeatFailure.type, (context, event) => HeartbeatFailedState.with(Object.assign({}, context), [ + ...(event.payload.status ? [emitStatus$1(Object.assign({}, event.payload.status))] : []), + ])); + HeartbeatingState.on(disconnect$1.type, (context, event) => HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ])); HeartbeatingState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); /** @@ -7773,89 +7936,19 @@ leaveAll() { this.engine.transition(leftAll()); } + reconnect() { + this.engine.transition(reconnect$1()); + } + disconnect(isOffline) { + this.engine.transition(disconnect$1(isOffline)); + } dispose() { + this.disconnect(true); this._unsubscribeEngine(); this.dispatcher.dispose(); } } - /** - * Failed request retry policy. - */ - class RetryPolicy { - static LinearRetryPolicy(configuration) { - return { - delay: configuration.delay, - maximumRetry: configuration.maximumRetry, - /* eslint-disable @typescript-eslint/no-explicit-any */ - shouldRetry(error, attempt) { - var _a; - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return false; - } - return this.maximumRetry > attempt; - }, - getDelay(_, reason) { - var _a; - const delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : this.delay; - return (delay + Math.random()) * 1000; - }, - /* eslint-disable @typescript-eslint/no-explicit-any */ - getGiveupReason(error, attempt) { - var _a; - if (this.maximumRetry <= attempt) { - return 'retry attempts exhaused.'; - } - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return 'forbidden operation.'; - } - return 'unknown error'; - }, - validate() { - if (this.maximumRetry > 10) - throw new Error('Maximum retry for linear retry policy can not be more than 10'); - }, - }; - } - static ExponentialRetryPolicy(configuration) { - return { - minimumDelay: configuration.minimumDelay, - maximumDelay: configuration.maximumDelay, - maximumRetry: configuration.maximumRetry, - shouldRetry(reason, attempt) { - var _a; - if (((_a = reason === null || reason === void 0 ? void 0 : reason.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return false; - } - return this.maximumRetry > attempt; - }, - getDelay(attempt, reason) { - var _a; - const delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : Math.min(Math.pow(2, attempt), this.maximumDelay); - return (delay + Math.random()) * 1000; - }, - getGiveupReason(reason, attempt) { - var _a; - if (this.maximumRetry <= attempt) { - return 'retry attempts exhausted.'; - } - if (((_a = reason === null || reason === void 0 ? void 0 : reason.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return 'forbidden operation.'; - } - return 'unknown error'; - }, - validate() { - if (this.minimumDelay < 2) - throw new Error('Minimum delay can not be set less than 2 seconds for retry'); - else if (this.maximumDelay) - throw new Error('Maximum delay can not be set more than 150 seconds for retry'); - else if (this.maximumRetry > 6) - throw new Error('Maximum retry for exponential retry policy can not be more than 6'); - }, - }; - } - } - /** * Subscribe Event Engine effects module. * @@ -7897,22 +7990,6 @@ * @internal */ const emitStatus = createEffect('EMIT_STATUS', (status) => status); - /** - * Real-time updates receive restore effect. - * - * Performs subscribe REST API call with `tt` which has been received before disconnection or error. - * - * @internal - */ - const receiveReconnect = createManagedEffect('RECEIVE_RECONNECT', (context) => context); - /** - * Initial subscription restore effect. - * - * Performs subscribe REST API call with `tt=0` after error. - * - * @internal - */ - const handshakeReconnect = createManagedEffect('HANDSHAKE_RECONNECT', (context) => context); /** * Subscribe Event Engine events module. @@ -7961,32 +8038,6 @@ * @internal */ const handshakeFailure = createEvent('HANDSHAKE_FAILURE', (error) => error); - /** - * Initial subscription handshake reconnect success event. - * - * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. - * - * @internal - */ - const handshakeReconnectSuccess = createEvent('HANDSHAKE_RECONNECT_SUCCESS', (cursor) => ({ - cursor, - })); - /** - * Initial subscription handshake reconnect did fail event. - * - * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. - * - * @internal - */ - const handshakeReconnectFailure = createEvent('HANDSHAKE_RECONNECT_FAILURE', (error) => error); - /** - * Initial subscription handshake impossible event. - * - * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. - * - * @internal - */ - const handshakeReconnectGiveup = createEvent('HANDSHAKE_RECONNECT_GIVEUP', (error) => error); /** * Subscription successfully received real-time updates event. * @@ -8006,33 +8057,6 @@ * @internal */ const receiveFailure = createEvent('RECEIVE_FAILURE', (error) => error); - /** - * Subscription successfully received real-time updates on reconnection attempt event. - * - * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. - * - * @internal - */ - const receiveReconnectSuccess = createEvent('RECEIVE_RECONNECT_SUCCESS', (cursor, events) => ({ - cursor, - events, - })); - /** - * Subscription did fail to receive real-time updates on reconnection attempt event. - * - * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. - * - * @internal - */ - const receiveReconnectFailure = createEvent('RECEIVE_RECONNECT_FAILURE', (error) => error); - /** - * Subscription real-time updates received impossible event. - * - * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. - * - * @internal - */ - const receiveReconnectGiveup = createEvent('RECEIVING_RECONNECT_GIVEUP', (error) => error); /** * Client disconnect event. * @@ -8040,7 +8064,7 @@ * * @internal */ - const disconnect = createEvent('DISCONNECT', () => ({})); + const disconnect = createEvent('DISCONNECT', (isOffline) => ({ isOffline })); /** * Client reconnect event. * @@ -8115,106 +8139,13 @@ } }))); this.on(emitMessages.type, asyncHandler((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitMessages }) { - if (payload.length > 0) { + if (payload.length > 0) emitMessages(payload); - } - }))); - this.on(emitStatus.type, asyncHandler((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus }) { - emitStatus(payload); - }))); - this.on(receiveReconnect.type, asyncHandler((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { receiveMessages, delay, config }) { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); - abortSignal.throwIfAborted(); - try { - const result = yield receiveMessages({ - abortSignal: abortSignal, - channels: payload.channels, - channelGroups: payload.groups, - timetoken: payload.cursor.timetoken, - region: payload.cursor.region, - filterExpression: config.filterExpression, - }); - return engine.transition(receiveReconnectSuccess(result.cursor, result.messages)); - } - catch (error) { - if (error instanceof PubNubError) { - if (error.status && error.status.category == StatusCategory$1.PNCancelledCategory) - return; - return engine.transition(receiveReconnectFailure(error)); - } - } - } - else { - return engine.transition(receiveReconnectGiveup(new PubNubError(config.retryConfiguration - ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) - : 'Unable to complete subscribe messages receive.'))); - } - }))); - this.on(handshakeReconnect.type, asyncHandler((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { handshake, delay, presenceState, config }) { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); - abortSignal.throwIfAborted(); - try { - const result = yield handshake(Object.assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState }))); - return engine.transition(handshakeReconnectSuccess(result)); - } - catch (error) { - if (error instanceof PubNubError) { - if (error.status && error.status.category == StatusCategory$1.PNCancelledCategory) - return; - return engine.transition(handshakeReconnectFailure(error)); - } - } - } - else { - return engine.transition(handshakeReconnectGiveup(new PubNubError(config.retryConfiguration - ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) - : 'Unable to complete subscribe handshake'))); - } }))); + this.on(emitStatus.type, asyncHandler((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus }) { return emitStatus(payload); }))); } } - /** - * Failed initial subscription handshake (disconnected) state. - * - * @internal - */ - /** - * Failed initial subscription handshake (disconnected) state. - * - * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been - * exhausted. - * - * @internal - */ - const HandshakeFailedState = new State('HANDSHAKE_FAILED'); - HandshakeFailedState.on(subscriptionChange.type, (context, event) => HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - })); - HandshakeFailedState.on(reconnect.type, (context, event) => HandshakingState.with({ - channels: context.channels, - groups: context.groups, - cursor: event.payload.cursor || context.cursor, - })); - HandshakeFailedState.on(restore.type, (context, event) => { - var _a, _b; - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region ? event.payload.cursor.region : ((_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0), - }, - }); - }); - HandshakeFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); - /** * Stopped initial subscription handshake (disconnected) state. * @@ -8229,64 +8160,50 @@ * @internal */ const HandshakeStoppedState = new State('HANDSHAKE_STOPPED'); - HandshakeStoppedState.on(subscriptionChange.type, (context, event) => HandshakeStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - })); - HandshakeStoppedState.on(reconnect.type, (context, event) => HandshakingState.with(Object.assign(Object.assign({}, context), { cursor: event.payload.cursor || context.cursor }))); - HandshakeStoppedState.on(restore.type, (context, event) => { + HandshakeStoppedState.on(subscriptionChange.type, (context, { payload }) => HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); + HandshakeStoppedState.on(reconnect.type, (context, { payload }) => HandshakingState.with(Object.assign(Object.assign({}, context), { cursor: payload.cursor || context.cursor }))); + HandshakeStoppedState.on(restore.type, (context, { payload }) => { var _a; return HandshakeStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0, - }, + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || ((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0 }, }); }); HandshakeStoppedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); /** - * Failed to receive real-time updates (disconnected) state. + * Failed initial subscription handshake (disconnected) state. * * @internal */ /** - * Failed to receive real-time updates (disconnected) state. + * Failed initial subscription handshake (disconnected) state. * * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been * exhausted. * * @internal */ - const ReceiveFailedState = new State('RECEIVE_FAILED'); - ReceiveFailedState.on(reconnect.type, (context, event) => { - var _a; + const HandshakeFailedState = new State('HANDSHAKE_FAILED'); + HandshakeFailedState.on(subscriptionChange.type, (context, { payload }) => HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); + HandshakeFailedState.on(reconnect.type, (context, { payload }) => HandshakingState.with({ + channels: context.channels, + groups: context.groups, + cursor: payload.cursor || context.cursor, + })); + HandshakeFailedState.on(restore.type, (context, { payload }) => { + var _a, _b; return HandshakingState.with({ - channels: context.channels, - groups: context.groups, + channels: payload.channels, + groups: payload.groups, cursor: { - timetoken: !!event.payload.cursor.timetoken ? (_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, + timetoken: payload.cursor.timetoken, + region: payload.cursor.region ? payload.cursor.region : ((_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0), }, }); }); - ReceiveFailedState.on(subscriptionChange.type, (context, event) => HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - })); - ReceiveFailedState.on(restore.type, (context, event) => HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - })); - ReceiveFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); + HandshakeFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); /** * Stopped real-time updates (disconnected) state module. @@ -8302,81 +8219,57 @@ * @internal */ const ReceiveStoppedState = new State('RECEIVE_STOPPED'); - ReceiveStoppedState.on(subscriptionChange.type, (context, event) => ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - })); - ReceiveStoppedState.on(restore.type, (context, event) => ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, + ReceiveStoppedState.on(subscriptionChange.type, (context, { payload }) => ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); + ReceiveStoppedState.on(restore.type, (context, { payload }) => ReceiveStoppedState.with({ + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, })); - ReceiveStoppedState.on(reconnect.type, (context, event) => { + ReceiveStoppedState.on(reconnect.type, (context, { payload }) => { var _a; return HandshakingState.with({ channels: context.channels, groups: context.groups, cursor: { - timetoken: !!event.payload.cursor.timetoken ? (_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, + timetoken: !!payload.cursor.timetoken ? (_a = payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, + region: payload.cursor.region || context.cursor.region, }, }); }); ReceiveStoppedState.on(unsubscribeAll.type, () => UnsubscribedState.with(undefined)); /** - * Reconnect to receive real-time updates (disconnected) state. + * Failed to receive real-time updates (disconnected) state. * * @internal */ /** - * Reconnect to receive real-time updates (disconnected) state. + * Failed to receive real-time updates (disconnected) state. * - * State in which Subscription Event Engine tries to recover after error which happened before. + * State in which Subscription Event Engine waits for user to try to reconnect after all retry attempts has been + * exhausted. * * @internal */ - const ReceiveReconnectingState = new State('RECEIVE_RECONNECTING'); - ReceiveReconnectingState.onEnter((context) => receiveReconnect(context)); - ReceiveReconnectingState.onExit(() => receiveReconnect.cancel); - ReceiveReconnectingState.on(receiveReconnectSuccess.type, (context, event) => ReceivingState.with({ - channels: context.channels, - groups: context.groups, - cursor: event.payload.cursor, - }, [emitMessages(event.payload.events)])); - ReceiveReconnectingState.on(receiveReconnectFailure.type, (context, event) => ReceiveReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); - ReceiveReconnectingState.on(receiveReconnectGiveup.type, (context, event) => { + const ReceiveFailedState = new State('RECEIVE_FAILED'); + ReceiveFailedState.on(reconnect.type, (context, { payload }) => { var _a; - return ReceiveFailedState.with({ - groups: context.groups, + return HandshakingState.with({ channels: context.channels, - cursor: context.cursor, - reason: event.payload, - }, [emitStatus({ category: StatusCategory$1.PNDisconnectedUnexpectedlyCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); + groups: context.groups, + cursor: { + timetoken: !!payload.cursor.timetoken ? (_a = payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, + region: payload.cursor.region || context.cursor.region, + }, + }); }); - ReceiveReconnectingState.on(disconnect.type, (context) => ReceiveStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })])); - ReceiveReconnectingState.on(restore.type, (context, event) => ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - })); - ReceiveReconnectingState.on(subscriptionChange.type, (context, event) => ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, + ReceiveFailedState.on(subscriptionChange.type, (context, { payload }) => HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); + ReceiveFailedState.on(restore.type, (context, { payload }) => HandshakingState.with({ + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, })); - ReceiveReconnectingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })])); + ReceiveFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); /** * Receiving real-time updates (connected) state module. @@ -8393,105 +8286,61 @@ const ReceivingState = new State('RECEIVING'); ReceivingState.onEnter((context) => receiveMessages(context.channels, context.groups, context.cursor)); ReceivingState.onExit(() => receiveMessages.cancel); - ReceivingState.on(receiveSuccess.type, (context, event) => { - return ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: event.payload.cursor }, [ - emitMessages(event.payload.events), + ReceivingState.on(receiveSuccess.type, (context, { payload }) => { + return ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: payload.cursor }, [ + emitMessages(payload.events), ]); }); - ReceivingState.on(subscriptionChange.type, (context, event) => { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return UnsubscribedState.with(undefined); - } - return ReceivingState.with({ - cursor: context.cursor, - channels: event.payload.channels, - groups: event.payload.groups, - }); - }); - ReceivingState.on(restore.type, (context, event) => { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return UnsubscribedState.with(undefined); - } - return ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); - }); - ReceivingState.on(receiveFailure.type, (context, event) => { - return ReceiveReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: 0, reason: event.payload })); - }); - ReceivingState.on(disconnect.type, (context) => { - return ReceiveStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })]); + ReceivingState.on(subscriptionChange.type, (context, { payload }) => { + const subscriptionChangeStatus = { + category: StatusCategory$1.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + }; + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined, [emitStatus(subscriptionChangeStatus)]); + return ReceivingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }, [ + emitStatus(subscriptionChangeStatus), + ]); }); - ReceivingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })])); - - /** - * Retry initial subscription handshake (disconnected) state. - * - * @internal - */ - /** - * Retry initial subscription handshake (disconnected) state. - * - * State in which Subscription Event Engine tries to recover after error which happened before. - * - * @internal - */ - const HandshakeReconnectingState = new State('HANDSHAKE_RECONNECTING'); - HandshakeReconnectingState.onEnter((context) => handshakeReconnect(context)); - HandshakeReconnectingState.onExit(() => handshakeReconnect.cancel); - HandshakeReconnectingState.on(handshakeReconnectSuccess.type, (context, event) => { - var _a, _b; - const cursor = { - timetoken: !!((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : event.payload.cursor.timetoken, - region: event.payload.cursor.region, + ReceivingState.on(restore.type, (context, { payload }) => { + const subscriptionChangeStatus = { + category: StatusCategory$1.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), }; + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined, [emitStatus(subscriptionChangeStatus)]); return ReceivingState.with({ - channels: context.channels, - groups: context.groups, - cursor: cursor, - }, [emitStatus({ category: StatusCategory$1.PNConnectedCategory })]); + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, + }, [emitStatus(subscriptionChangeStatus)]); }); - HandshakeReconnectingState.on(handshakeReconnectFailure.type, (context, event) => HandshakeReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); - HandshakeReconnectingState.on(handshakeReconnectGiveup.type, (context, event) => { + ReceivingState.on(receiveFailure.type, (context, { payload }) => { var _a; - return HandshakeFailedState.with({ - groups: context.groups, - channels: context.channels, - cursor: context.cursor, - reason: event.payload, - }, [emitStatus({ category: StatusCategory$1.PNConnectionErrorCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); + return ReceiveFailedState.with(Object.assign(Object.assign({}, context), { reason: payload }), [ + emitStatus({ category: StatusCategory$1.PNDisconnectedUnexpectedlyCategory, error: (_a = payload.status) === null || _a === void 0 ? void 0 : _a.category }), + ]); }); - HandshakeReconnectingState.on(disconnect.type, (context) => HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - })); - HandshakeReconnectingState.on(subscriptionChange.type, (context, event) => HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - })); - HandshakeReconnectingState.on(restore.type, (context, event) => { - var _a, _b; - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: ((_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.region) || ((_b = context === null || context === void 0 ? void 0 : context.cursor) === null || _b === void 0 ? void 0 : _b.region) || 0, - }, - }); + ReceivingState.on(disconnect.type, (context, event) => { + var _a; + if (!event.payload.isOffline) { + return ReceiveStoppedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor }, [ + emitStatus({ category: StatusCategory$1.PNDisconnectedCategory }), + ]); + } + else { + const errorReason = PubNubAPIError.create(new Error('Network connection error')).toPubNubError(RequestOperation$1.PNSubscribeOperation); + return ReceiveFailedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor, reason: errorReason }, [ + emitStatus({ + category: StatusCategory$1.PNDisconnectedUnexpectedlyCategory, + error: (_a = errorReason.status) === null || _a === void 0 ? void 0 : _a.category, + }), + ]); + } }); - HandshakeReconnectingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); + ReceivingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })])); /** * Initial subscription handshake (disconnected) state. @@ -8509,54 +8358,51 @@ const HandshakingState = new State('HANDSHAKING'); HandshakingState.onEnter((context) => handshake(context.channels, context.groups)); HandshakingState.onExit(() => handshake.cancel); - HandshakingState.on(subscriptionChange.type, (context, event) => { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { + HandshakingState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); - } - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); }); - HandshakingState.on(handshakeSuccess.type, (context, event) => { + HandshakingState.on(handshakeSuccess.type, (context, { payload }) => { var _a, _b; return ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: { - timetoken: !!((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context === null || context === void 0 ? void 0 : context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : event.payload.timetoken, - region: event.payload.region, + timetoken: !!((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : payload.timetoken, + region: payload.region, }, - }, [ - emitStatus({ - category: StatusCategory$1.PNConnectedCategory, - }), - ]); + }, [emitStatus({ category: StatusCategory$1.PNConnectedCategory })]); }); HandshakingState.on(handshakeFailure.type, (context, event) => { - return HandshakeReconnectingState.with({ + var _a; + return HandshakeFailedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor, - attempts: 0, reason: event.payload, - }); + }, [emitStatus({ category: StatusCategory$1.PNConnectionErrorCategory, error: (_a = event.payload.status) === null || _a === void 0 ? void 0 : _a.category })]); }); - HandshakingState.on(disconnect.type, (context) => HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - })); - HandshakingState.on(restore.type, (context, event) => { + HandshakingState.on(disconnect.type, (context, event) => { + var _a; + if (!event.payload.isOffline) + return HandshakeStoppedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor }); + else { + const errorReason = PubNubAPIError.create(new Error('Network connection error')).toPubNubError(RequestOperation$1.PNSubscribeOperation); + return HandshakeFailedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor, reason: errorReason }, [ + emitStatus({ + category: StatusCategory$1.PNConnectionErrorCategory, + error: (_a = errorReason.status) === null || _a === void 0 ? void 0 : _a.category, + }), + ]); + } + }); + HandshakingState.on(restore.type, (context, { payload }) => { var _a; return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0, - }, + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0 }, }); }); HandshakingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); @@ -8574,17 +8420,8 @@ * @internal */ const UnsubscribedState = new State('UNSUBSCRIBED'); - UnsubscribedState.on(subscriptionChange.type, (_, event) => HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - })); - UnsubscribedState.on(restore.type, (_, event) => { - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: event.payload.cursor, - }); - }); + UnsubscribedState.on(subscriptionChange.type, (_, { payload }) => HandshakingState.with({ channels: payload.channels, groups: payload.groups })); + UnsubscribedState.on(restore.type, (_, { payload }) => HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: payload.cursor })); /** * Subscribe Event Engine module. @@ -8645,10 +8482,10 @@ if (new Set(this.channels).size !== new Set(filteredChannels).size || new Set(this.groups).size !== new Set(filteredGroups).size) { const channelsToLeave = findUniqueCommonElements(this.channels, channels); - const groupstoLeave = findUniqueCommonElements(this.groups, channelGroups); + const groupsToLeave = findUniqueCommonElements(this.groups, channelGroups); if (this.dependencies.presenceState) { channelsToLeave === null || channelsToLeave === void 0 ? void 0 : channelsToLeave.forEach((c) => delete this.dependencies.presenceState[c]); - groupstoLeave === null || groupstoLeave === void 0 ? void 0 : groupstoLeave.forEach((g) => delete this.dependencies.presenceState[g]); + groupsToLeave === null || groupsToLeave === void 0 ? void 0 : groupsToLeave.forEach((g) => delete this.dependencies.presenceState[g]); } this.channels = filteredChannels; this.groups = filteredGroups; @@ -8656,7 +8493,7 @@ if (this.dependencies.leave) { this.dependencies.leave({ channels: channelsToLeave.slice(0), - groups: groupstoLeave.slice(0), + groups: groupsToLeave.slice(0), }); } } @@ -8676,14 +8513,18 @@ this.dependencies.leaveAll({ channels, groups: channelGroups }); } reconnect({ timetoken, region }) { + const channelGroups = this.getSubscribedChannels(); + const channels = this.getSubscribedChannels(); this.engine.transition(reconnect(timetoken, region)); + if (this.dependencies.presenceReconnect) + this.dependencies.presenceReconnect({ channels, groups: channelGroups }); } - disconnect() { + disconnect(isOffline) { const channelGroups = this.getSubscribedChannels(); const channels = this.getSubscribedChannels(); - this.engine.transition(disconnect()); - if (this.dependencies.leaveAll) - this.dependencies.leaveAll({ channels, groups: channelGroups }); + this.engine.transition(disconnect(isOffline)); + if (this.dependencies.presenceDisconnect) + this.dependencies.presenceDisconnect({ channels, groups: channelGroups, isOffline }); } getSubscribedChannels() { return Array.from(new Set(this.channels.slice(0))); @@ -8692,7 +8533,7 @@ return Array.from(new Set(this.groups.slice(0))); } dispose() { - this.disconnect(); + this.disconnect(true); this._unsubscribeEngine(); this.dispatcher.dispose(); } @@ -9034,7 +8875,7 @@ */ class HeartbeatRequest extends AbstractRequest { constructor(parameters) { - super(); + super({ cancellable: true }); this.parameters = parameters; } operation() { @@ -12973,7 +12814,6 @@ else setTimeout(resolve, heartbeatInterval * 1000); }), - retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), emitStatus: (status) => this.listenerManager.announceStatus(status), config: this._configuration, presenceState: this.presenceState, @@ -12987,6 +12827,8 @@ join: this.join.bind(this), leave: this.leave.bind(this), leaveAll: this.leaveAll.bind(this), + presenceReconnect: this.presenceReconnect.bind(this), + presenceDisconnect: this.presenceDisconnect.bind(this), presenceState: this.presenceState, config: this._configuration, emitMessages: (events) => { @@ -13404,6 +13246,10 @@ } else if (this.eventEngine) this.eventEngine.dispose(); + { + if (this.presenceEventEngine) + this.presenceEventEngine.dispose(); + } } } /** @@ -13680,13 +13526,17 @@ } /** * Temporarily disconnect from real-time events stream. + * + * **Note:** `isOffline` is set to `true` only when client experience network issues. + * + * @param [isOffline] - Whether `offline` presence should be notified or not. */ - disconnect() { + disconnect(isOffline) { { if (this.subscriptionManager) this.subscriptionManager.disconnect(); else if (this.eventEngine) - this.eventEngine.disconnect(); + this.eventEngine.disconnect(isOffline); } } /** @@ -14060,6 +13910,22 @@ } } } + /** + * Reconnect presence event engine after network issues. + * + * @param parameters - List of channels and groups where `join` event should be sent. + * + * @internal + */ + presenceReconnect(parameters) { + { + if (this.presenceEventEngine) + this.presenceEventEngine.reconnect(); + else { + this.heartbeat(Object.assign(Object.assign({ channels: parameters.channels, channelGroups: parameters.groups }, (this._configuration.maintainPresenceState && { state: this.presenceState })), { heartbeat: this._configuration.getPresenceTimeout() }), () => { }); + } + } + } // endregion // region Leave /** @@ -14093,6 +13959,21 @@ this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => { }); } } + /** + * Announce user `leave` on disconnection. + * + * @internal + * + * @param parameters - List of channels and groups where `leave` event should be sent. + */ + presenceDisconnect(parameters) { + { + if (this.presenceEventEngine) + this.presenceEventEngine.disconnect(parameters.isOffline); + else if (!parameters.isOffline) + this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => { }); + } + } /** * Grant token permission. * @@ -14909,7 +14790,7 @@ networkDownDetected() { this.listenerManager.announceNetworkDown(); if (this._configuration.restore) - this.disconnect(); + this.disconnect(true); else this.destroy(true); } diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 108184ba4..c6ccb7bd7 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)S+=d,w.push(u(d));var O=new Uint8Array(S),k=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,w,S=S||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=S).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=S,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],w=e[i+12],S=e[i+13],O=e[i+14],k=e[i+15],E=t(E=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,E,N,P,o,12,u[1]),P=t(P,C,E,N,l,17,u[2]),N=t(N,P,C,E,h,22,u[3]);E=t(E,N,P,C,d,7,u[4]),C=t(C,E,N,P,p,12,u[5]),P=t(P,C,E,N,g,17,u[6]),N=t(N,P,C,E,y,22,u[7]),E=t(E,N,P,C,f,7,u[8]),C=t(C,E,N,P,b,12,u[9]),P=t(P,C,E,N,m,17,u[10]),N=t(N,P,C,E,v,22,u[11]),E=t(E,N,P,C,w,7,u[12]),C=t(C,E,N,P,S,12,u[13]),P=t(P,C,E,N,O,17,u[14]),E=n(E,N=t(N,P,C,E,k,22,u[15]),P,C,o,5,u[16]),C=n(C,E,N,P,g,9,u[17]),P=n(P,C,E,N,v,14,u[18]),N=n(N,P,C,E,c,20,u[19]),E=n(E,N,P,C,p,5,u[20]),C=n(C,E,N,P,m,9,u[21]),P=n(P,C,E,N,k,14,u[22]),N=n(N,P,C,E,d,20,u[23]),E=n(E,N,P,C,b,5,u[24]),C=n(C,E,N,P,O,9,u[25]),P=n(P,C,E,N,h,14,u[26]),N=n(N,P,C,E,f,20,u[27]),E=n(E,N,P,C,S,5,u[28]),C=n(C,E,N,P,l,9,u[29]),P=n(P,C,E,N,y,14,u[30]),E=s(E,N=n(N,P,C,E,w,20,u[31]),P,C,p,4,u[32]),C=s(C,E,N,P,f,11,u[33]),P=s(P,C,E,N,v,16,u[34]),N=s(N,P,C,E,O,23,u[35]),E=s(E,N,P,C,o,4,u[36]),C=s(C,E,N,P,d,11,u[37]),P=s(P,C,E,N,y,16,u[38]),N=s(N,P,C,E,m,23,u[39]),E=s(E,N,P,C,S,4,u[40]),C=s(C,E,N,P,c,11,u[41]),P=s(P,C,E,N,h,16,u[42]),N=s(N,P,C,E,g,23,u[43]),E=s(E,N,P,C,b,4,u[44]),C=s(C,E,N,P,w,11,u[45]),P=s(P,C,E,N,k,16,u[46]),E=r(E,N=s(N,P,C,E,l,23,u[47]),P,C,c,6,u[48]),C=r(C,E,N,P,y,10,u[49]),P=r(P,C,E,N,O,15,u[50]),N=r(N,P,C,E,p,21,u[51]),E=r(E,N,P,C,w,6,u[52]),C=r(C,E,N,P,h,10,u[53]),P=r(P,C,E,N,m,15,u[54]),N=r(N,P,C,E,o,21,u[55]),E=r(E,N,P,C,f,6,u[56]),C=r(C,E,N,P,k,10,u[57]),P=r(P,C,E,N,g,15,u[58]),N=r(N,P,C,E,S,21,u[59]),E=r(E,N,P,C,d,6,u[60]),C=r(C,E,N,P,v,10,u[61]),P=r(P,C,E,N,l,15,u[62]),N=r(N,P,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=S,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=S,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],w=p[v],O=257*p[b]^16843008*b;i[y]=O<<24|O>>>8,a[y]=O<<16|O>>>16,o[y]=O<<8|O>>>24,c[y]=O,O=16843009*w^65537*v^257*m^16843008*y,u[b]=O<<24|O>>>8,l[b]=O<<16|O>>>16,h[b]=O<<8|O>>>24,d[b]=O,y?(y=m^p[p[p[w^m]]],f^=p[p[f]]):y=f=1}var k=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=k[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),S.mode.ECB=((w=S.lib.BlockCipherMode.extend()).Encryptor=w.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),w.Decryptor=w.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),w);var O=t(S);class k{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=O,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:k.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return k.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(k.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=k.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new k({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new k({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=j.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=j.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===j.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=j.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class j{static from(e,t){if(e!==j.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==j.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>j.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+j.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(s),a)}}j.SENTINEL="PNED",j.LEGACY_IDENTIFIER="",j.IDENTIFIER_LENGTH=4,j.VERSION=1,j.MAX_VERSION=1,j.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return j.VERSION}get length(){return j.SENTINEL.length+1+j.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(j.SENTINEL)),e+=j.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=j.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function T(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?T(o):o})),s}const F=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let w=!1,S=!0,O=5,k=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(w=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(S=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(O=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:w,announceFailedHeartbeats:S,fileUploadPublishRetryLimit:O})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(R,R.exports);var U=t(R.exports),x={createUUID:()=>U.uuid?U.uuid():U()};const D=(e,t)=>{var n,s,r;null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=q(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${x.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.4.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},q=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class L{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var G;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(G||(G={}));const K=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),$=(e,t)=>{const n=e.map((e=>K(e)));return n.length?n.join(","):null!=t?t:""},B=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},H=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class V{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?G.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===G.POST||t===G.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=V.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${K(e)}`)).join("&"):`${t}=${K(n)}`})).join("&")}}V.textDecoder=new TextDecoder("utf-8");class W{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new V(t.publishKey,t.secretKey,n))}makeSendable(e){return this.configuration.transport.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(z.originalFetch=z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else if(e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer))if(e.compressible&&"undefined"!=typeof CompressionStream){const n=new ReadableStream({start(t){t.enqueue("string"==typeof e.body?z.encoder.encode(e.body):e.body),t.close()}});t=yield new Response(n.pipeThrough(new CompressionStream("deflate"))).arrayBuffer()}else t=e.body;var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}z.encoder=new TextEncoder,z.decoder=new TextDecoder;class J{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class X{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class Q{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class Z{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ee extends Z{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class te extends Z{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class ne{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ee(this._payload.apns,e,t),this.fcm=new te(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class se{constructor(e){this.params=e,this.requestIdentifier=x.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s,r,i;const a={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:G.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,compressible:null!==(i=null===(r=this.params)||void 0===r?void 0:r.compressible)&&void 0!==i&&i,timeout:10,identifier:this.requestIdentifier},o=this.headers;if(o&&(a.headers=o),a.method===G.POST||a.method===G.PATCH){const[e,t]=[this.body,this.formData];t&&(a.formData=t),e&&(a.body=e)}return a}get headers(){var e,t;return Object.assign({"Accept-Encoding":"gzip, deflate"},null!==(t=null===(e=this.params)||void 0===e?void 0:e.compressible)&&void 0!==t&&t?{"Content-Encoding":"deflate"}:{})}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=se.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var re;se.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(re||(re={}));var ie=re;var ae;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(ae||(ae={}));class oe extends se{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return ie.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=se.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?ae.Presence:ae.Message),t!=ae.Signal&&"string"==typeof e.d?t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}:t==ae.Message?{type:ae.Message,data:this.messageFromEnvelope(e)}:t===ae.Presence?{type:ae.Presence,data:this.presenceEventFromEnvelope(e)}:t==ae.Signal?{type:ae.Signal,data:this.signalFromEnvelope(e)}:t===ae.AppContext?{type:ae.AppContext,data:this.appContextFromEnvelope(e)}:t===ae.MessageAction?{type:ae.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:ae.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{accept:"text/javascript"})}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(ce.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class ce extends oe{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ue{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===ae.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===ae.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===ae.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===ae.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===ae.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=x.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class le{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class he{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class de extends le{describe(e){return new he(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class pe{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ge(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function ye(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function fe(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class be extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class me extends le{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new be}abort(){this._aborted=!0,this.notify(new be)}}class ve{constructor(e,t){this.payload=e,this.dependencies=t}}class we extends ve{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new me}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Se=e=>(t,n)=>new we(t,n,e),Oe=ge("RECONNECT",(()=>({}))),ke=ge("DISCONNECT",(()=>({}))),Ee=ge("JOINED",((e,t)=>({channels:e,groups:t}))),Ce=ge("LEFT",((e,t)=>({channels:e,groups:t}))),Pe=ge("LEFT_ALL",(()=>({}))),Ne=ge("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Me=ge("HEARTBEAT_FAILURE",(e=>e)),je=ge("HEARTBEAT_GIVEUP",(()=>({}))),Ae=ge("TIMES_UP",(()=>({}))),_e=ye("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ie=ye("LEAVE",((e,t)=>({channels:e,groups:t}))),Te=ye("EMIT_STATUS",(e=>e)),Fe=fe("WAIT",(()=>({}))),Re=fe("DELAYED_HEARTBEAT",(e=>e));class Ue extends pe{constructor(e,t){super(t),this.on(_e.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Ie.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(Fe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Ae())}))))),this.on(Re.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,retryDelay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(je());n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},a.maintainPresenceState&&{state:i}),{heartbeat:a.presenceTimeout}));return e.transition(Ne(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Me(t))}}}))))),this.on(Te.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){var r;s.announceFailedHeartbeats&&!0===(null===(r=null==e?void 0:e.status)||void 0===r?void 0:r.error)?n(e.status):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{operation:ie.PNHeartbeatOperation,error:!1}))})))))}}const xe=new he("HEARTBEAT_STOPPED");xe.on(Ee.type,((e,t)=>xe.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),xe.on(Ce.type,((e,t)=>xe.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),xe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),xe.on(Pe.type,((e,t)=>Ke.with(void 0)));const De=new he("HEARTBEAT_COOLDOWN");De.onEnter((()=>Fe())),De.onExit((()=>Fe.cancel)),De.on(Ae.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),De.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),De.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),De.on(ke.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),De.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const qe=new he("HEARTBEAT_FAILED");qe.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),qe.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),qe.on(Oe.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups}))),qe.on(ke.type,((e,t)=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),qe.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Le=new he("HEARBEAT_RECONNECTING");Le.onEnter((e=>Re(e))),Le.onExit((()=>Re.cancel)),Le.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Le.on(ke.type,((e,t)=>{xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)])})),Le.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Le.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),Le.on(je.type,((e,t)=>qe.with({channels:e.channels,groups:e.groups}))),Le.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ge=new he("HEARTBEATING");Ge.onEnter((e=>_e(e.channels,e.groups))),Ge.on(Ne.type,((e,t)=>De.with({channels:e.channels,groups:e.groups}))),Ge.on(Ee.type,((e,t)=>Ge.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ce.type,((e,t)=>Ge.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ie(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),Ge.on(ke.type,(e=>xe.with({channels:e.channels,groups:e.groups},[Ie(e.channels,e.groups)]))),Ge.on(Pe.type,((e,t)=>Ke.with(void 0,[Ie(e.channels,e.groups)])));const Ke=new he("HEARTBEAT_INACTIVE");Ke.on(Ee.type,((e,t)=>Ge.with({channels:t.payload.channels,groups:t.payload.groups})));class $e{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new de,this.channels=[],this.groups=[],this.dispatcher=new Ue(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Ke,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(Ee(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ce(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Pe())}dispose(){this._unsubscribeEngine(),this.dispatcher.dispose()}}class Be{static LinearRetryPolicy(e){return{delay:e.delay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:this.delay)+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhaused.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,shouldRetry(e,t){var n;return 403!==(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)&&this.maximumRetry>t},getDelay(e,t){var n;return 1e3*((null!==(n=t.retryAfter)&&void 0!==n?n:Math.min(Math.pow(2,e),this.maximumDelay))+Math.random())},getGiveupReason(e,t){var n;return this.maximumRetry<=t?"retry attempts exhausted.":403===(null===(n=null==e?void 0:e.status)||void 0===n?void 0:n.statusCode)?"forbidden operation.":"unknown error"},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const He=fe("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=fe("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),We=ye("EMIT_MESSAGES",(e=>e)),ze=ye("EMIT_STATUS",(e=>e)),Je=fe("RECEIVE_RECONNECT",(e=>e)),Xe=fe("HANDSHAKE_RECONNECT",(e=>e)),Qe=ge("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Ye=ge("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ze=ge("HANDSHAKE_SUCCESS",(e=>e)),et=ge("HANDSHAKE_FAILURE",(e=>e)),tt=ge("HANDSHAKE_RECONNECT_SUCCESS",(e=>({cursor:e}))),nt=ge("HANDSHAKE_RECONNECT_FAILURE",(e=>e)),st=ge("HANDSHAKE_RECONNECT_GIVEUP",(e=>e)),rt=ge("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),it=ge("RECEIVE_FAILURE",(e=>e)),at=ge("RECEIVE_RECONNECT_SUCCESS",((e,t)=>({cursor:e,events:t}))),ot=ge("RECEIVE_RECONNECT_FAILURE",(e=>e)),ct=ge("RECEIVING_RECONNECT_GIVEUP",(e=>e)),ut=ge("DISCONNECT",(()=>({}))),lt=ge("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),ht=ge("UNSUBSCRIBE_ALL",(()=>({})));class dt extends pe{constructor(e,t){super(t),this.on(He.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ze(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(et(t))}}}))))),this.on(Ve.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(rt(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(it(t))}}}))))),this.on(We.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(ze.type,Se(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){n(e)}))))),this.on(Je.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,delay:r,config:i}){if(!i.retryConfiguration||!i.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(ct(new d(i.retryConfiguration?i.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe messages receive.")));n.throwIfAborted(),yield r(i.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:i.filterExpression});return e.transition(at(r.cursor,r.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(ot(t))}}}))))),this.on(Xe.type,Se(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,delay:r,presenceState:i,config:a}){if(!a.retryConfiguration||!a.retryConfiguration.shouldRetry(t.reason,t.attempts))return e.transition(st(new d(a.retryConfiguration?a.retryConfiguration.getGiveupReason(t.reason,t.attempts):"Unable to complete subscribe handshake")));n.throwIfAborted(),yield r(a.retryConfiguration.getDelay(t.attempts,t.reason)),n.throwIfAborted();try{const r=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:a.filterExpression},a.maintainPresenceState&&{state:i}));return e.transition(tt(r))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(nt(t))}}})))))}}const pt=new he("HANDSHAKE_FAILED");pt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),pt.on(lt.type,((e,t)=>wt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor||e.cursor}))),pt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region?t.payload.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),pt.on(ht.type,(e=>St.with()));const gt=new he("HANDSHAKE_STOPPED");gt.on(Qe.type,((e,t)=>gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),gt.on(lt.type,((e,t)=>wt.with(Object.assign(Object.assign({},e),{cursor:t.payload.cursor||e.cursor})))),gt.on(Ye.type,((e,t)=>{var n;return gt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),gt.on(ht.type,(e=>St.with()));const yt=new he("RECEIVE_FAILED");yt.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),yt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),yt.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),yt.on(ht.type,(e=>St.with(void 0)));const ft=new he("RECEIVE_STOPPED");ft.on(Qe.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),ft.on(Ye.type,((e,t)=>ft.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),ft.on(lt.type,((e,t)=>{var n;return wt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.payload.cursor.timetoken?null===(n=t.payload.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}})})),ft.on(ht.type,(()=>St.with(void 0)));const bt=new he("RECEIVE_RECONNECTING");bt.onEnter((e=>Je(e))),bt.onExit((()=>Je.cancel)),bt.on(at.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),bt.on(ot.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),bt.on(ct.type,((e,t)=>{var n;return yt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),bt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),bt.on(Ye.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),bt.on(Qe.type,((e,t)=>mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),bt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const mt=new he("RECEIVING");mt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),mt.onExit((()=>Ve.cancel)),mt.on(rt.type,((e,t)=>mt.with({channels:e.channels,groups:e.groups,cursor:t.payload.cursor},[We(t.payload.events)]))),mt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({cursor:e.cursor,channels:t.payload.channels,groups:t.payload.groups}))),mt.on(Ye.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):mt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||e.cursor.region}}))),mt.on(it.type,((e,t)=>bt.with(Object.assign(Object.assign({},e),{attempts:0,reason:t.payload})))),mt.on(ut.type,(e=>ft.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[ze({category:h.PNDisconnectedCategory})]))),mt.on(ht.type,(e=>St.with(void 0,[ze({category:h.PNDisconnectedCategory})])));const vt=new he("HANDSHAKE_RECONNECTING");vt.onEnter((e=>Xe(e))),vt.onExit((()=>Xe.cancel)),vt.on(tt.type,((e,t)=>{var n,s;const r={timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region};return mt.with({channels:e.channels,groups:e.groups,cursor:r},[ze({category:h.PNConnectedCategory})])})),vt.on(nt.type,((e,t)=>vt.with(Object.assign(Object.assign({},e),{attempts:e.attempts+1,reason:t.payload})))),vt.on(st.type,((e,t)=>{var n;return pt.with({groups:e.groups,channels:e.channels,cursor:e.cursor,reason:t.payload},[ze({category:h.PNConnectionErrorCategory,error:null===(n=t.payload)||void 0===n?void 0:n.message})])})),vt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),vt.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),vt.on(Ye.type,((e,t)=>{var n,s;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:(null===(n=t.payload.cursor)||void 0===n?void 0:n.region)||(null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.region)||0}})})),vt.on(ht.type,(e=>St.with(void 0)));const wt=new he("HANDSHAKING");wt.onEnter((e=>He(e.channels,e.groups))),wt.onExit((()=>He.cancel)),wt.on(Qe.type,((e,t)=>0===t.payload.channels.length&&0===t.payload.groups.length?St.with(void 0):wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:e.cursor}))),wt.on(Ze.type,((e,t)=>{var n,s;return mt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=null==e?void 0:e.cursor)||void 0===s?void 0:s.timetoken:t.payload.timetoken,region:t.payload.region}},[ze({category:h.PNConnectedCategory})])})),wt.on(et.type,((e,t)=>vt.with({channels:e.channels,groups:e.groups,cursor:e.cursor,attempts:0,reason:t.payload}))),wt.on(ut.type,(e=>gt.with({channels:e.channels,groups:e.groups,cursor:e.cursor}))),wt.on(Ye.type,((e,t)=>{var n;return wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:{timetoken:t.payload.cursor.timetoken,region:t.payload.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),wt.on(ht.type,(e=>St.with()));const St=new he("UNSUBSCRIBED");St.on(Qe.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups}))),St.on(Ye.type,((e,t)=>wt.with({channels:t.payload.channels,groups:t.payload.groups,cursor:t.payload.cursor})));class Ot{get _engine(){return this.engine}constructor(e){this.engine=new de,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new dt(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(St,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Ye(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=B(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=B(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=H(this.channels,e),i=H(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Qe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Qe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}reconnect({timetoken:e,region:t}){this.engine.transition(lt(e,t))}disconnect(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.engine.transition(ut()),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(),this._unsubscribeEngine(),this.dispatcher.dispose()}}class kt extends se{constructor(e){var t;const n=null!==(t=e.sendByPost)&&void 0!==t&&t;super({method:n?G.POST:G.GET,compressible:n}),this.parameters=e,this.parameters.sendByPost=n}operation(){return ie.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${K(t)}/0${this.parameters.sendByPost?"":`/${K(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){var e;if(this.parameters.sendByPost)return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Et extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${K(n)}/0/${K(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class Ct extends oe{operation(){return ie.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class Pt extends oe{operation(){return ie.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${$(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class Nt extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return ie.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class Mt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=n?n:[],",")}/uuid/${K(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class jt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${$(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class At extends se{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return ie.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${$(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class _t extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${K(t)}`}}class It extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?ie.PNGlobalHereNowOperation:ie.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${$(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Tt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ft extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${$(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Rt extends se{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return ie.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${K(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Rt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Ut;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Ut||(Ut={}));class xt extends se{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return ie.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Ut.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${$(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(xt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Ut.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class Dt extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class qt extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${n}`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify(this.parameters.action)}}class Lt extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${K(t)}/message/${s}/action/${n}`}}class Gt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return ie.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${K(t)}/0/${K(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Kt extends se{constructor(e){super({method:G.LOCAL}),this.parameters=e}operation(){return ie.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${K(e)}/files/${t}/${n}`}}class $t extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(n)}/files/${t}/${s}`}}class Bt extends se{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return ie.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ht extends se{constructor(e){super({method:G.POST}),this.parameters=e}operation(){return ie.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/generate-upload-url`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify({name:this.parameters.name})}}class Vt extends se{constructor(e){super({method:G.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return ie.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?Vt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Wt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:ie.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(ie.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ht(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new Vt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class zt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Jt extends zt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Xt extends zt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Jt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Qt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Yt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Zt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Xt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class en{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Xt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class tn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class nn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class sn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}`}}class rn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${K(t)}/remove`}}class an extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class on{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new sn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new an({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new rn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class cn extends se{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class un extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return ie.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class ln extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return ie.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class hn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return ie.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class dn extends cn{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return ie.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class pn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new un(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new dn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class gn extends se{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return ie.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class yn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e}operation(){return ie.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}}class fn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class bn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class mn extends se{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return ie.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class vn extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class wn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return ie.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Sn extends se{constructor(e){super({method:G.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}}class On extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class kn extends se{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return ie.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${K(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class En extends se{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class Cn extends se{constructor(e){var t,n,s;super({method:G.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return ie.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${K(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class Pn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new mn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new En(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new Cn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new Sn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new gn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new vn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new wn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new yn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new On(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new kn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new fn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new bn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class Nn extends se{constructor(){super()}operation(){return ie.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class Mn extends se{constructor(e){super(),this.parameters=e}operation(){return ie.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${K(t)}/files/${n}/${s}`}}class jn{static notificationPayload(e,t){return new ne(e,t)}static generateUUID(){return x.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new Pn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new on(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new pn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new J,this.eventEmitter=new ue(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new $e({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),retryDelay:e=>new Promise((t=>setTimeout(t,e))),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new Ot({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new Y(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new en(e,this.eventEmitter,this)}channelGroup(e){return new Yt(e,this.eventEmitter,this)}channelMetadata(e){return new Qt(e,this.eventEmitter,this)}userMetadata(e){return new Zt(e,this.eventEmitter,this)}subscriptionSet(e){return new Jt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===ie.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===ie.PNSubscribeOperation||r===ie.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=jn.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new ce(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:ie.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new At({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect()}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new qt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new Lt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new xt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new _t({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Nt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new jt(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new Mt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:ie.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new jt(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){this.presenceEventEngine?this.presenceEventEngine.join(e):this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}leave(e){var t;this.presenceEventEngine?null===(t=this.presenceEventEngine)||void 0===t||t.leave(e):this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}leaveAll(e){this.presenceEventEngine?this.presenceEventEngine.leaveAll():this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Wt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:ie.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${K(t)}`)).join("&"):`${e}=${K(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Mn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new $t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new Nn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}jn.decoder=new TextDecoder,jn.OPERATIONS=ie,jn.CATEGORIES=h,jn.ExponentialRetryPolicy=Be.ExponentialRetryPolicy,jn.LinearRetryPolicy=Be.LinearRetryPolicy;class An{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class _n extends jn{constructor(e){var t;const n=F(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=D(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new k({cipherKey:e.cipherKey})]})}));let a,u,l;a=new L(new An((e=>T(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new W({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect():this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return _n.CryptoModule=M,_n})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)w+=d,S.push(u(d));var O=new Uint8Array(w),k=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNSubscriptionChangedCategory="PNSubscriptionChangedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,S,w=w||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=w).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=w,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],S=e[i+12],w=e[i+13],O=e[i+14],k=e[i+15],E=t(E=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,E,N,P,o,12,u[1]),P=t(P,C,E,N,l,17,u[2]),N=t(N,P,C,E,h,22,u[3]);E=t(E,N,P,C,d,7,u[4]),C=t(C,E,N,P,p,12,u[5]),P=t(P,C,E,N,g,17,u[6]),N=t(N,P,C,E,y,22,u[7]),E=t(E,N,P,C,f,7,u[8]),C=t(C,E,N,P,b,12,u[9]),P=t(P,C,E,N,m,17,u[10]),N=t(N,P,C,E,v,22,u[11]),E=t(E,N,P,C,S,7,u[12]),C=t(C,E,N,P,w,12,u[13]),P=t(P,C,E,N,O,17,u[14]),E=n(E,N=t(N,P,C,E,k,22,u[15]),P,C,o,5,u[16]),C=n(C,E,N,P,g,9,u[17]),P=n(P,C,E,N,v,14,u[18]),N=n(N,P,C,E,c,20,u[19]),E=n(E,N,P,C,p,5,u[20]),C=n(C,E,N,P,m,9,u[21]),P=n(P,C,E,N,k,14,u[22]),N=n(N,P,C,E,d,20,u[23]),E=n(E,N,P,C,b,5,u[24]),C=n(C,E,N,P,O,9,u[25]),P=n(P,C,E,N,h,14,u[26]),N=n(N,P,C,E,f,20,u[27]),E=n(E,N,P,C,w,5,u[28]),C=n(C,E,N,P,l,9,u[29]),P=n(P,C,E,N,y,14,u[30]),E=s(E,N=n(N,P,C,E,S,20,u[31]),P,C,p,4,u[32]),C=s(C,E,N,P,f,11,u[33]),P=s(P,C,E,N,v,16,u[34]),N=s(N,P,C,E,O,23,u[35]),E=s(E,N,P,C,o,4,u[36]),C=s(C,E,N,P,d,11,u[37]),P=s(P,C,E,N,y,16,u[38]),N=s(N,P,C,E,m,23,u[39]),E=s(E,N,P,C,w,4,u[40]),C=s(C,E,N,P,c,11,u[41]),P=s(P,C,E,N,h,16,u[42]),N=s(N,P,C,E,g,23,u[43]),E=s(E,N,P,C,b,4,u[44]),C=s(C,E,N,P,S,11,u[45]),P=s(P,C,E,N,k,16,u[46]),E=r(E,N=s(N,P,C,E,l,23,u[47]),P,C,c,6,u[48]),C=r(C,E,N,P,y,10,u[49]),P=r(P,C,E,N,O,15,u[50]),N=r(N,P,C,E,p,21,u[51]),E=r(E,N,P,C,S,6,u[52]),C=r(C,E,N,P,h,10,u[53]),P=r(P,C,E,N,m,15,u[54]),N=r(N,P,C,E,o,21,u[55]),E=r(E,N,P,C,f,6,u[56]),C=r(C,E,N,P,k,10,u[57]),P=r(P,C,E,N,g,15,u[58]),N=r(N,P,C,E,w,21,u[59]),E=r(E,N,P,C,d,6,u[60]),C=r(C,E,N,P,v,10,u[61]),P=r(P,C,E,N,l,15,u[62]),N=r(N,P,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=w,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=w,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],S=p[v],O=257*p[b]^16843008*b;i[y]=O<<24|O>>>8,a[y]=O<<16|O>>>16,o[y]=O<<8|O>>>24,c[y]=O,O=16843009*S^65537*v^257*m^16843008*y,u[b]=O<<24|O>>>8,l[b]=O<<16|O>>>16,h[b]=O<<8|O>>>24,d[b]=O,y?(y=m^p[p[p[S^m]]],f^=p[p[f]]):y=f=1}var k=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=k[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),w.mode.ECB=((S=w.lib.BlockCipherMode.extend()).Encryptor=S.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),S.Decryptor=S.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),S);var O=t(w);class k{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=O,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:k.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return k.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(k.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=k.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new k({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new k({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=j.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=j.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===j.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=j.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class j{static from(e,t){if(e!==j.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==j.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>j.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+j.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(s),a)}}j.SENTINEL="PNED",j.LEGACY_IDENTIFIER="",j.IDENTIFIER_LENGTH=4,j.VERSION=1,j.MAX_VERSION=1,j.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return j.VERSION}get length(){return j.SENTINEL.length+1+j.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(j.SENTINEL)),e+=j.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=j.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return A.isErrorObject(e)?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new A(n,t,0);if(e instanceof A)return e;if(A.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new A(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new A(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,A.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new A(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let S=!1,w=!0,O=5,k=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(S=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(O=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:S,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:O})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R;!function(e){e.Unknown="UnknownEndpoint",e.MessageSend="MessageSendEndpoint",e.Subscribe="SubscribeEndpoint",e.Presence="PresenceEndpoint",e.Files="FilesEndpoint",e.MessageStorage="MessageStorageEndpoint",e.ChannelGroups="ChannelGroupsEndpoint",e.DevicePushNotifications="DevicePushNotificationsEndpoint",e.AppContext="AppContextEndpoint",e.MessageReactions="MessageReactionsEndpoint"}(R||(R={}));class U{static LinearRetryPolicy(e){var t;return{delay:e.delay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=this.delay),1e3*(n+Math.random())},validate(){if(this.delay<2)throw new Error("Delay can not be set less than 2 seconds for retry");if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){var t;return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=Math.min(Math.pow(2,e),this.maximumDelay)),1e3*(n+Math.random())},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const x=(e,t,n,s,r,i)=>(!n||n!==h.PNCancelledCategory)&&(!D(e,i)&&(!(s>r)&&(!t||(429===t.status||t.status>=500)))),D=(e,t)=>!!(t&&t.length>0)&&t.includes(q(e)),q=e=>{let t=R.Unknown;return e.path.startsWith("/v2/subscribe")?t=R.Subscribe:e.path.startsWith("/publish/")||e.path.startsWith("/signal/")?t=R.MessageSend:e.path.startsWith("/v2/presence")?t=R.Presence:e.path.startsWith("/v2/history")||e.path.startsWith("/v3/history")?t=R.MessageStorage:e.path.startsWith("/v1/message-actions/")?t=R.MessageReactions:e.path.startsWith("/v1/channel-registration/")||e.path.startsWith("/v2/objects/")?t=R.ChannelGroups:e.path.startsWith("/v1/push/")||e.path.startsWith("/v2/push/")?t=R.DevicePushNotifications:e.path.startsWith("/v1/files/")&&(t=R.Files),t};var L={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(L,L.exports);var G=t(L.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var n,s,r;!e.retryConfiguration&&e.enableEventEngine&&(e.retryConfiguration=U.ExponentialRetryPolicy({minimumDelay:2,maximumDelay:150,maximumRetry:6,excluded:[R.MessageSend,R.Presence,R.Files,R.MessageStorage,R.ChannelGroups,R.DevicePushNotifications,R.AppContext,R.MessageReactions]})),null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=B(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.5.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},B=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class H{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var W;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(W||(W={}));const V=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),z=(e,t)=>{const n=e.map((e=>V(e)));return n.length?n.join(","):null!=t?t:""},J=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},X=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class Q{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?W.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===W.POST||t===W.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=Q.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${V(e)}`)).join("&"):`${t}=${V(n)}`})).join("&")}}Q.textDecoder=new TextDecoder("utf-8");class Y{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new Q(t.publishKey,t.secretKey,n))}makeSendable(e){const t=this.configuration.clientConfiguration.retryConfiguration,n=this.configuration.transport;if(void 0!==t){let s,r,i=!1,a=0;const o={abort:e=>{i=!0,s&&clearTimeout(s),r&&r.abort(e)}};return[new Promise(((o,c)=>{const u=()=>{if(i)return;const[l,d]=n.makeSendable(this.request(e));r=d;const p=(n,r)=>{const i=!r||r.category!==h.PNCancelledCategory,l=!n||n.status>=400;let d=-1;i&&l&&t.shouldRetry(e,n,null==r?void 0:r.category,a+1)&&(d=t.getDelay(a,n)),d>0?(a++,s=setTimeout((()=>u()),d)):n?o(n):r&&c(r)};l.then((e=>p(e))).catch((e=>p(void 0,e)))};u()})),r?o:void 0]}return n.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class Z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(Z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(Z.originalFetch=Z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(Z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw A.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw A.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([Z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else if(e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer))if(e.compressible&&"undefined"!=typeof CompressionStream){const n=new ReadableStream({start(t){t.enqueue("string"==typeof e.body?Z.encoder.encode(e.body):e.body),t.close()}});t=yield new Response(n.pipeThrough(new CompressionStream("deflate"))).arrayBuffer()}else t=e.body;var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${Z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${Z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}Z.encoder=new TextEncoder,Z.decoder=new TextDecoder;class ee{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class te{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class ne{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class re{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ie extends re{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class ae extends re{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class oe{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ie(this._payload.apns,e,t),this.fcm=new ae(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class ce{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s,r,i;const a={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:W.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,compressible:null!==(i=null===(r=this.params)||void 0===r?void 0:r.compressible)&&void 0!==i&&i,timeout:10,identifier:this.requestIdentifier},o=this.headers;if(o&&(a.headers=o),a.method===W.POST||a.method===W.PATCH){const[e,t]=[this.body,this.formData];t&&(a.formData=t),e&&(a.body=e)}return a}get headers(){var e,t;return Object.assign({"Accept-Encoding":"gzip, deflate"},null!==(t=null===(e=this.params)||void 0===e?void 0:e.compressible)&&void 0!==t&&t?{"Content-Encoding":"deflate"}:{})}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=ce.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw A.create(e);return s}}var ue;ce.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ue||(ue={}));var le=ue;var he;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(he||(he={}));class de extends ce{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return le.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=ce.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?he.Presence:he.Message),t!=he.Signal&&"string"==typeof e.d?t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}:t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:t===he.Presence?{type:he.Presence,data:this.presenceEventFromEnvelope(e)}:t==he.Signal?{type:he.Signal,data:this.signalFromEnvelope(e)}:t===he.AppContext?{type:he.AppContext,data:this.appContextFromEnvelope(e)}:t===he.MessageAction?{type:he.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{accept:"text/javascript"})}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(pe.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class pe extends de{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ge{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===he.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===he.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===he.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===he.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=K.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class ye{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class fe{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class be extends ye{describe(e){return new fe(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class me{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ve(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function Se(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function we(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class Oe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class ke extends ye{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new Oe}abort(){this._aborted=!0,this.notify(new Oe)}}class Ee{constructor(e,t){this.payload=e,this.dependencies=t}}class Ce extends Ee{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new ke}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Pe=e=>(t,n)=>new Ce(t,n,e),Ne=ve("RECONNECT",(()=>({}))),Me=ve("DISCONNECT",(e=>({isOffline:e}))),je=ve("JOINED",((e,t)=>({channels:e,groups:t}))),_e=ve("LEFT",((e,t)=>({channels:e,groups:t}))),Ae=ve("LEFT_ALL",(()=>({}))),Ie=ve("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Fe=ve("HEARTBEAT_FAILURE",(e=>e)),Te=ve("TIMES_UP",(()=>({}))),Re=we("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ue=Se("LEAVE",((e,t)=>({channels:e,groups:t}))),xe=Se("EMIT_STATUS",(e=>e)),De=we("WAIT",(()=>({})));class qe extends me{constructor(e,t){super(t),this.on(Re.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ie(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;e.transition(Fe(t))}}}))))),this.on(Ue.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(De.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Te())}))))),this.on(xe.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){s.announceFailedHeartbeats&&!0===(null==e?void 0:e.error)?n(Object.assign(Object.assign({},e),{operation:le.PNHeartbeatOperation})):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory}))})))))}}const Le=new fe("HEARTBEAT_STOPPED");Le.on(je.type,((e,t)=>Le.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(_e.type,((e,t)=>Le.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Le.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Le.on(Ae.type,((e,t)=>Be.with(void 0)));const Ge=new fe("HEARTBEAT_COOLDOWN");Ge.onEnter((()=>De())),Ge.onExit((()=>De.cancel)),Ge.on(Te.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ge.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ge.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const Ke=new fe("HEARTBEAT_FAILED");Ke.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ke.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ke.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const $e=new fe("HEARTBEATING");$e.onEnter((e=>Re(e.channels,e.groups))),$e.onExit((()=>Re.cancel)),$e.on(Ie.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups},[xe(Object.assign({},t.payload))]))),$e.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),$e.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),$e.on(Fe.type,((e,t)=>Ke.with(Object.assign({},e),[...t.payload.status?[xe(Object.assign({},t.payload.status))]:[]]))),$e.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),$e.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const Be=new fe("HEARTBEAT_INACTIVE");Be.on(je.type,((e,t)=>$e.with({channels:t.payload.channels,groups:t.payload.groups})));class He{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new be,this.channels=[],this.groups=[],this.dispatcher=new qe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Be,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(je(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(_e(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ae())}reconnect(){this.engine.transition(Ne())}disconnect(e){this.engine.transition(Me(e))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}const We=we("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=we("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),ze=Se("EMIT_MESSAGES",(e=>e)),Je=Se("EMIT_STATUS",(e=>e)),Xe=ve("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=ve("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ye=ve("HANDSHAKE_SUCCESS",(e=>e)),Ze=ve("HANDSHAKE_FAILURE",(e=>e)),et=ve("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),tt=ve("RECEIVE_FAILURE",(e=>e)),nt=ve("DISCONNECT",(e=>({isOffline:e}))),st=ve("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),rt=ve("UNSUBSCRIBE_ALL",(()=>({})));class it extends me{constructor(e,t){super(t),this.on(We.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(Ve.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(et(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(tt(t))}}}))))),this.on(ze.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(Je.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){return n(e)})))))}}const at=new fe("HANDSHAKE_STOPPED");at.on(Xe.type,((e,{payload:t})=>at.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),at.on(st.type,((e,{payload:t})=>ht.with(Object.assign(Object.assign({},e),{cursor:t.cursor||e.cursor})))),at.on(Qe.type,((e,{payload:t})=>{var n;return at.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=e.cursor)||void 0===n?void 0:n.region)||0}})})),at.on(rt.type,(e=>dt.with()));const ot=new fe("HANDSHAKE_FAILED");ot.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ot.on(st.type,((e,{payload:t})=>ht.with({channels:e.channels,groups:e.groups,cursor:t.cursor||e.cursor}))),ot.on(Qe.type,((e,{payload:t})=>{var n,s;return ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region?t.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),ot.on(rt.type,(e=>dt.with()));const ct=new fe("RECEIVE_STOPPED");ct.on(Xe.type,((e,{payload:t})=>ct.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ct.on(Qe.type,((e,{payload:t})=>ct.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ct.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ct.on(rt.type,(()=>dt.with(void 0)));const ut=new fe("RECEIVE_FAILED");ut.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ut.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ut.on(Qe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ut.on(rt.type,(e=>dt.with(void 0)));const lt=new fe("RECEIVING");lt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),lt.onExit((()=>Ve.cancel)),lt.on(et.type,((e,{payload:t})=>lt.with({channels:e.channels,groups:e.groups,cursor:t.cursor},[ze(t.events)]))),lt.on(Xe.type,((e,{payload:t})=>{const n={category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0)};return 0===t.channels.length&&0===t.groups.length?dt.with(void 0,[Je(n)]):lt.with({channels:t.channels,groups:t.groups,cursor:e.cursor},[Je(n)])})),lt.on(Qe.type,((e,{payload:t})=>{const n={category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0)};return 0===t.channels.length&&0===t.groups.length?dt.with(void 0,[Je(n)]):lt.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}},[Je(n)])})),lt.on(tt.type,((e,{payload:t})=>{var n;return ut.with(Object.assign(Object.assign({},e),{reason:t}),[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])})),lt.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=A.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ut.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return ct.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Je({category:h.PNDisconnectedCategory})])})),lt.on(rt.type,(e=>dt.with(void 0,[Je({category:h.PNDisconnectedCategory})])));const ht=new fe("HANDSHAKING");ht.onEnter((e=>We(e.channels,e.groups))),ht.onExit((()=>We.cancel)),ht.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ht.on(Ye.type,((e,{payload:t})=>{var n,s;return lt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.timetoken,region:t.region}},[Je({category:h.PNConnectedCategory})])})),ht.on(Ze.type,((e,t)=>{var n;return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t.payload},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.payload.status)||void 0===n?void 0:n.category})])})),ht.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=A.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return at.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),ht.on(Qe.type,((e,{payload:t})=>{var n;return ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),ht.on(rt.type,(e=>dt.with()));const dt=new fe("UNSUBSCRIBED");dt.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups}))),dt.on(Qe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:t.cursor})));class pt{get _engine(){return this.engine}constructor(e){this.engine=new be,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new it(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(dt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=J(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=J(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=X(this.channels,e),i=X(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Xe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Xe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}reconnect({timetoken:e,region:t}){const n=this.getSubscribedChannels(),s=this.getSubscribedChannels();this.engine.transition(st(e,t)),this.dependencies.presenceReconnect&&this.dependencies.presenceReconnect({channels:s,groups:n})}disconnect(e){const t=this.getSubscribedChannels(),n=this.getSubscribedChannels();this.engine.transition(nt(e)),this.dependencies.presenceDisconnect&&this.dependencies.presenceDisconnect({channels:n,groups:t,isOffline:e})}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}class gt extends ce{constructor(e){var t;const n=null!==(t=e.sendByPost)&&void 0!==t&&t;super({method:n?W.POST:W.GET,compressible:n}),this.parameters=e,this.parameters.sendByPost=n}operation(){return le.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${V(t)}/0${this.parameters.sendByPost?"":`/${V(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){var e;if(this.parameters.sendByPost)return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class yt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${V(n)}/0/${V(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class ft extends de{operation(){return le.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class bt extends de{operation(){return le.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class mt extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return le.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${V(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class St extends ce{constructor(e){super({cancellable:!0}),this.parameters=e}operation(){return le.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class wt extends ce{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return le.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class Ot extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${V(t)}`}}class kt extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?le.PNGlobalHereNowOperation:le.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${z(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Et extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ct extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${z(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Pt extends ce{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return le.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Pt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Nt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Nt||(Nt={}));class Mt extends ce{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return le.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Nt.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${z(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Mt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Nt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class _t extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${n}`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify(this.parameters.action)}}class At extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${s}/action/${n}`}}class It extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return le.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${V(t)}/0/${V(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ft extends ce{constructor(e){super({method:W.LOCAL}),this.parameters=e}operation(){return le.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${V(e)}/files/${t}/${n}`}}class Tt extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(n)}/files/${t}/${s}`}}class Rt extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return le.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ut extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/generate-upload-url`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify({name:this.parameters.name})}}class xt extends ce{constructor(e){super({method:W.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return le.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?xt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Dt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:le.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(le.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ut(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new xt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class qt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Lt extends qt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Gt extends qt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Lt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Kt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class $t{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Bt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Ht{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Wt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class Vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class zt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}}class Jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}/remove`}}class Xt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class Qt{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new Xt({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Vt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Wt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new Jt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class Yt extends ce{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class Zt extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return le.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class en extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return le.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class tn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return le.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class nn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return le.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class sn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new en(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class rn extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return le.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class an extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}}class on extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class cn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class un extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return le.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ln extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class hn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class dn extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}}class pn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class yn extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class fn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new un(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new yn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new fn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new dn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new rn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new an(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new pn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new on(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class mn extends ce{constructor(){super()}operation(){return le.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class vn extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files/${n}/${s}`}}class Sn{static notificationPayload(e,t){return new oe(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new bn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new Qt(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new sn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new ee,this.eventEmitter=new ge(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new He({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new pt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceReconnect:this.presenceReconnect.bind(this),presenceDisconnect:this.presenceDisconnect.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new se(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Ht(e,this.eventEmitter,this)}channelGroup(e){return new $t(e,this.eventEmitter,this)}channelMetadata(e){return new Kt(e,this.eventEmitter,this)}userMetadata(e){return new Bt(e,this.eventEmitter,this)}subscriptionSet(e){return new Lt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===le.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===le.PNSubscribeOperation||r===le.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=Sn.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof A?e:A.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose(),this.presenceEventEngine&&this.presenceEventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new yt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new pe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:le.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new wt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(e){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect(e)}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Ot({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new mt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new St(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new vt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new St(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){this.presenceEventEngine?this.presenceEventEngine.join(e):this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}presenceReconnect(e){this.presenceEventEngine?this.presenceEventEngine.reconnect():this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}leave(e){var t;this.presenceEventEngine?null===(t=this.presenceEventEngine)||void 0===t||t.leave(e):this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}leaveAll(e){this.presenceEventEngine?this.presenceEventEngine.leaveAll():this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}presenceDisconnect(e){this.presenceEventEngine?this.presenceEventEngine.disconnect(e.isOffline):e.isOffline||this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:le.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof A&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new vn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new mn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}Sn.decoder=new TextDecoder,Sn.OPERATIONS=le,Sn.CATEGORIES=h,Sn.ExponentialRetryPolicy=U.ExponentialRetryPolicy,Sn.LinearRetryPolicy=U.LinearRetryPolicy;class wn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class On extends Sn{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=$(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new k({cipherKey:e.cipherKey})]})}));let a,u,l;a=new H(new wn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new Z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new Y({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect(!0):this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return On.CryptoModule=M,On})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 8497ab8ac..9741d5d21 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeConfiguration = void 0; +const retryPolicy_1 = require("./retryPolicy"); const uuid_1 = __importDefault(require("./uuid")); // -------------------------------------------------------- // ----------------------- Defaults ----------------------- @@ -32,6 +33,24 @@ const USE_RANDOM_INITIALIZATION_VECTOR = true; */ const makeConfiguration = (base, setupCryptoModule) => { var _a, _b, _c; + // Set default retry policy for subscribe (if new subscribe logic not used). + if (!base.retryConfiguration && base.enableEventEngine) { + base.retryConfiguration = retryPolicy_1.RetryPolicy.ExponentialRetryPolicy({ + minimumDelay: 2, + maximumDelay: 150, + maximumRetry: 6, + excluded: [ + retryPolicy_1.Endpoint.MessageSend, + retryPolicy_1.Endpoint.Presence, + retryPolicy_1.Endpoint.Files, + retryPolicy_1.Endpoint.MessageStorage, + retryPolicy_1.Endpoint.ChannelGroups, + retryPolicy_1.Endpoint.DevicePushNotifications, + retryPolicy_1.Endpoint.AppContext, + retryPolicy_1.Endpoint.MessageReactions, + ], + }); + } // Ensure that retry policy has proper configuration (if has been set). (_a = base.retryConfiguration) === null || _a === void 0 ? void 0 : _a.validate(); (_b = base.useRandomIVs) !== null && _b !== void 0 ? _b : (base.useRandomIVs = USE_RANDOM_INITIALIZATION_VECTOR); @@ -124,7 +143,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '9.4.0'; + return '9.5.0'; }, getVersion() { return this.version; diff --git a/lib/core/components/retryPolicy.js b/lib/core/components/retryPolicy.js new file mode 100644 index 000000000..2ce03d7c2 --- /dev/null +++ b/lib/core/components/retryPolicy.js @@ -0,0 +1,184 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.RetryPolicy = exports.Endpoint = void 0; +const categories_1 = __importDefault(require("../constants/categories")); +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types +/** + * List of known endpoint groups (by context). + */ +var Endpoint; +(function (Endpoint) { + /** + * Unknown endpoint. + * + * @internal + */ + Endpoint["Unknown"] = "UnknownEndpoint"; + /** + * The endpoints to send messages. + */ + Endpoint["MessageSend"] = "MessageSendEndpoint"; + /** + * The endpoint for real-time update retrieval. + */ + Endpoint["Subscribe"] = "SubscribeEndpoint"; + /** + * The endpoint to access and manage `user_id` presence and fetch channel presence information. + */ + Endpoint["Presence"] = "PresenceEndpoint"; + /** + * The endpoint to access and manage files in channel-specific storage. + */ + Endpoint["Files"] = "FilesEndpoint"; + /** + * The endpoint to access and manage messages for a specific channel(s) in the persistent storage. + */ + Endpoint["MessageStorage"] = "MessageStorageEndpoint"; + /** + * The endpoint to access and manage channel groups. + */ + Endpoint["ChannelGroups"] = "ChannelGroupsEndpoint"; + /** + * The endpoint to access and manage device registration for channel push notifications. + */ + Endpoint["DevicePushNotifications"] = "DevicePushNotificationsEndpoint"; + /** + * The endpoint to access and manage App Context objects. + */ + Endpoint["AppContext"] = "AppContextEndpoint"; + /** + * The endpoint to access and manage reactions for a specific message. + */ + Endpoint["MessageReactions"] = "MessageReactionsEndpoint"; +})(Endpoint || (exports.Endpoint = Endpoint = {})); +// endregion +/** + * Failed request retry policy. + */ +class RetryPolicy { + static LinearRetryPolicy(configuration) { + var _a; + return { + delay: configuration.delay, + maximumRetry: configuration.maximumRetry, + excluded: (_a = configuration.excluded) !== null && _a !== void 0 ? _a : [], + shouldRetry(request, response, error, attempt) { + return isRetriableRequest(request, response, error, attempt !== null && attempt !== void 0 ? attempt : 0, this.maximumRetry, this.excluded); + }, + getDelay(_, response) { + let delay = -1; + if (response && response.headers['retry-after'] !== undefined) + delay = parseInt(response.headers['retry-after'], 10); + if (delay === -1) + delay = this.delay; + return (delay + Math.random()) * 1000; + }, + validate() { + if (this.delay < 2) + throw new Error('Delay can not be set less than 2 seconds for retry'); + if (this.maximumRetry > 10) + throw new Error('Maximum retry for linear retry policy can not be more than 10'); + }, + }; + } + static ExponentialRetryPolicy(configuration) { + var _a; + return { + minimumDelay: configuration.minimumDelay, + maximumDelay: configuration.maximumDelay, + maximumRetry: configuration.maximumRetry, + excluded: (_a = configuration.excluded) !== null && _a !== void 0 ? _a : [], + shouldRetry(request, response, error, attempt) { + return isRetriableRequest(request, response, error, attempt !== null && attempt !== void 0 ? attempt : 0, this.maximumRetry, this.excluded); + }, + getDelay(attempt, response) { + let delay = -1; + if (response && response.headers['retry-after'] !== undefined) + delay = parseInt(response.headers['retry-after'], 10); + if (delay === -1) + delay = Math.min(Math.pow(2, attempt), this.maximumDelay); + return (delay + Math.random()) * 1000; + }, + validate() { + if (this.minimumDelay < 2) + throw new Error('Minimum delay can not be set less than 2 seconds for retry'); + else if (this.maximumDelay > 150) + throw new Error('Maximum delay can not be set more than 150 seconds for' + ' retry'); + else if (this.maximumRetry > 6) + throw new Error('Maximum retry for exponential retry policy can not be more than 6'); + }, + }; + } +} +exports.RetryPolicy = RetryPolicy; +/** + * Check whether request can be retried or not. + * + * @param req - Request for which retry ability is checked. + * @param res - Service response which should be taken into consideration. + * @param errorCategory - Request processing error category. + * @param retryAttempt - Current retry attempt. + * @param maximumRetry - Maximum retry attempts count according to the retry policy. + * @param excluded - List of endpoints for which retry policy won't be applied. + * + * @return `true` if request can be retried. + * + * @internal + */ +const isRetriableRequest = (req, res, errorCategory, retryAttempt, maximumRetry, excluded) => { + if (errorCategory && errorCategory === categories_1.default.PNCancelledCategory) + return false; + else if (isExcludedRequest(req, excluded)) + return false; + else if (retryAttempt > maximumRetry) + return false; + return res ? res.status === 429 || res.status >= 500 : true; +}; +/** + * Check whether the provided request is in the list of endpoints for which retry is not allowed or not. + * + * @param req - Request which will be tested. + * @param excluded - List of excluded endpoints configured for retry policy. + * + * @returns `true` if request has been excluded and shouldn't be retried. + * + * @internal + */ +const isExcludedRequest = (req, excluded) => excluded && excluded.length > 0 ? excluded.includes(endpointFromRequest(req)) : false; +/** + * Identify API group from transport request. + * + * @param req - Request for which `path` will be analyzed to identify REST API group. + * + * @returns Endpoint group to which request belongs. + * + * @internal + */ +const endpointFromRequest = (req) => { + let endpoint = Endpoint.Unknown; + if (req.path.startsWith('/v2/subscribe')) + endpoint = Endpoint.Subscribe; + else if (req.path.startsWith('/publish/') || req.path.startsWith('/signal/')) + endpoint = Endpoint.MessageSend; + else if (req.path.startsWith('/v2/presence')) + endpoint = Endpoint.Presence; + else if (req.path.startsWith('/v2/history') || req.path.startsWith('/v3/history')) + endpoint = Endpoint.MessageStorage; + else if (req.path.startsWith('/v1/message-actions/')) + endpoint = Endpoint.MessageReactions; + else if (req.path.startsWith('/v1/channel-registration/')) + endpoint = Endpoint.ChannelGroups; + else if (req.path.startsWith('/v2/objects/')) + endpoint = Endpoint.ChannelGroups; + else if (req.path.startsWith('/v1/push/') || req.path.startsWith('/v2/push/')) + endpoint = Endpoint.DevicePushNotifications; + else if (req.path.startsWith('/v1/files/')) + endpoint = Endpoint.Files; + return endpoint; +}; diff --git a/lib/core/constants/categories.js b/lib/core/constants/categories.js index cffeb25aa..d731471d5 100644 --- a/lib/core/constants/categories.js +++ b/lib/core/constants/categories.js @@ -69,6 +69,10 @@ var StatusCategory; * PubNub client connected to the real-time updates stream. */ StatusCategory["PNConnectedCategory"] = "PNConnectedCategory"; + /** + * Set of active channels and groups has been changed. + */ + StatusCategory["PNSubscriptionChangedCategory"] = "PNSubscriptionChangedCategory"; /** * Received real-time updates exceed specified threshold. * diff --git a/lib/core/endpoints/presence/heartbeat.js b/lib/core/endpoints/presence/heartbeat.js index 8c34211bc..604acd76e 100644 --- a/lib/core/endpoints/presence/heartbeat.js +++ b/lib/core/endpoints/presence/heartbeat.js @@ -29,7 +29,7 @@ const utils_1 = require("../../utils"); */ class HeartbeatRequest extends request_1.AbstractRequest { constructor(parameters) { - super(); + super({ cancellable: true }); this.parameters = parameters; } operation() { diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 332f191e9..b48640c33 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -64,9 +64,9 @@ const categories_1 = __importDefault(require("./constants/categories")); // endregion const pubnub_error_1 = require("../errors/pubnub-error"); const pubnub_api_error_1 = require("../errors/pubnub-api-error"); +const retryPolicy_1 = require("./components/retryPolicy"); // region Event Engine const presence_1 = require("../event-engine/presence/presence"); -const retryPolicy_1 = require("../event-engine/core/retryPolicy"); const event_engine_1 = require("../event-engine"); // endregion // region Publish & Signal @@ -198,7 +198,6 @@ class PubNubCore { else setTimeout(resolve, heartbeatInterval * 1000); }), - retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), emitStatus: (status) => this.listenerManager.announceStatus(status), config: this._configuration, presenceState: this.presenceState, @@ -212,6 +211,8 @@ class PubNubCore { join: this.join.bind(this), leave: this.leave.bind(this), leaveAll: this.leaveAll.bind(this), + presenceReconnect: this.presenceReconnect.bind(this), + presenceDisconnect: this.presenceDisconnect.bind(this), presenceState: this.presenceState, config: this._configuration, emitMessages: (events) => { @@ -636,6 +637,10 @@ class PubNubCore { } else if (this.eventEngine) this.eventEngine.dispose(); + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) + this.presenceEventEngine.dispose(); + } } } /** @@ -946,13 +951,17 @@ class PubNubCore { } /** * Temporarily disconnect from real-time events stream. + * + * **Note:** `isOffline` is set to `true` only when client experience network issues. + * + * @param [isOffline] - Whether `offline` presence should be notified or not. */ - disconnect() { + disconnect(isOffline) { if (process.env.SUBSCRIBE_MODULE !== 'disabled') { if (this.subscriptionManager) this.subscriptionManager.disconnect(); else if (this.eventEngine) - this.eventEngine.disconnect(); + this.eventEngine.disconnect(isOffline); } else throw new Error('Disconnection error: subscription module disabled'); @@ -1363,6 +1372,24 @@ class PubNubCore { else throw new Error('Announce UUID Presence error: presence module disabled'); } + /** + * Reconnect presence event engine after network issues. + * + * @param parameters - List of channels and groups where `join` event should be sent. + * + * @internal + */ + presenceReconnect(parameters) { + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) + this.presenceEventEngine.reconnect(); + else { + this.heartbeat(Object.assign(Object.assign({ channels: parameters.channels, channelGroups: parameters.groups }, (this._configuration.maintainPresenceState && { state: this.presenceState })), { heartbeat: this._configuration.getPresenceTimeout() }), () => { }); + } + } + else + throw new Error('Announce UUID Presence error: presence module disabled'); + } // endregion // region Leave /** @@ -1400,6 +1427,23 @@ class PubNubCore { else throw new Error('Announce UUID Leave error: presence module disabled'); } + /** + * Announce user `leave` on disconnection. + * + * @internal + * + * @param parameters - List of channels and groups where `leave` event should be sent. + */ + presenceDisconnect(parameters) { + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) + this.presenceEventEngine.disconnect(parameters.isOffline); + else if (!parameters.isOffline) + this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => { }); + } + else + throw new Error('Announce UUID Leave error: presence module disabled'); + } /** * Grant token permission. * diff --git a/lib/event-engine/core/retryPolicy.js b/lib/event-engine/core/retryPolicy.js deleted file mode 100644 index 28cc74b6f..000000000 --- a/lib/event-engine/core/retryPolicy.js +++ /dev/null @@ -1,80 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.RetryPolicy = void 0; -/** - * Failed request retry policy. - */ -class RetryPolicy { - static LinearRetryPolicy(configuration) { - return { - delay: configuration.delay, - maximumRetry: configuration.maximumRetry, - /* eslint-disable @typescript-eslint/no-explicit-any */ - shouldRetry(error, attempt) { - var _a; - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return false; - } - return this.maximumRetry > attempt; - }, - getDelay(_, reason) { - var _a; - const delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : this.delay; - return (delay + Math.random()) * 1000; - }, - /* eslint-disable @typescript-eslint/no-explicit-any */ - getGiveupReason(error, attempt) { - var _a; - if (this.maximumRetry <= attempt) { - return 'retry attempts exhaused.'; - } - if (((_a = error === null || error === void 0 ? void 0 : error.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return 'forbidden operation.'; - } - return 'unknown error'; - }, - validate() { - if (this.maximumRetry > 10) - throw new Error('Maximum retry for linear retry policy can not be more than 10'); - }, - }; - } - static ExponentialRetryPolicy(configuration) { - return { - minimumDelay: configuration.minimumDelay, - maximumDelay: configuration.maximumDelay, - maximumRetry: configuration.maximumRetry, - shouldRetry(reason, attempt) { - var _a; - if (((_a = reason === null || reason === void 0 ? void 0 : reason.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return false; - } - return this.maximumRetry > attempt; - }, - getDelay(attempt, reason) { - var _a; - const delay = (_a = reason.retryAfter) !== null && _a !== void 0 ? _a : Math.min(Math.pow(2, attempt), this.maximumDelay); - return (delay + Math.random()) * 1000; - }, - getGiveupReason(reason, attempt) { - var _a; - if (this.maximumRetry <= attempt) { - return 'retry attempts exhausted.'; - } - if (((_a = reason === null || reason === void 0 ? void 0 : reason.status) === null || _a === void 0 ? void 0 : _a.statusCode) === 403) { - return 'forbidden operation.'; - } - return 'unknown error'; - }, - validate() { - if (this.minimumDelay < 2) - throw new Error('Minimum delay can not be set less than 2 seconds for retry'); - else if (this.maximumDelay) - throw new Error('Maximum delay can not be set more than 150 seconds for retry'); - else if (this.maximumRetry > 6) - throw new Error('Maximum retry for exponential retry policy can not be more than 6'); - }, - }; - } -} -exports.RetryPolicy = RetryPolicy; diff --git a/lib/event-engine/dispatcher.js b/lib/event-engine/dispatcher.js index f5f65ceb1..03a90caf8 100644 --- a/lib/event-engine/dispatcher.js +++ b/lib/event-engine/dispatcher.js @@ -103,66 +103,10 @@ class EventEngineDispatcher extends core_1.Dispatcher { } }))); this.on(effects.emitMessages.type, (0, core_1.asyncHandler)((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitMessages }) { - if (payload.length > 0) { + if (payload.length > 0) emitMessages(payload); - } - }))); - this.on(effects.emitStatus.type, (0, core_1.asyncHandler)((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus }) { - emitStatus(payload); - }))); - this.on(effects.receiveReconnect.type, (0, core_1.asyncHandler)((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { receiveMessages, delay, config }) { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); - abortSignal.throwIfAborted(); - try { - const result = yield receiveMessages({ - abortSignal: abortSignal, - channels: payload.channels, - channelGroups: payload.groups, - timetoken: payload.cursor.timetoken, - region: payload.cursor.region, - filterExpression: config.filterExpression, - }); - return engine.transition(events.receiveReconnectSuccess(result.cursor, result.messages)); - } - catch (error) { - if (error instanceof pubnub_error_1.PubNubError) { - if (error.status && error.status.category == categories_1.default.PNCancelledCategory) - return; - return engine.transition(events.receiveReconnectFailure(error)); - } - } - } - else { - return engine.transition(events.receiveReconnectGiveup(new pubnub_error_1.PubNubError(config.retryConfiguration - ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) - : 'Unable to complete subscribe messages receive.'))); - } - }))); - this.on(effects.handshakeReconnect.type, (0, core_1.asyncHandler)((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { handshake, delay, presenceState, config }) { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - yield delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); - abortSignal.throwIfAborted(); - try { - const result = yield handshake(Object.assign({ abortSignal: abortSignal, channels: payload.channels, channelGroups: payload.groups, filterExpression: config.filterExpression }, (config.maintainPresenceState && { state: presenceState }))); - return engine.transition(events.handshakeReconnectSuccess(result)); - } - catch (error) { - if (error instanceof pubnub_error_1.PubNubError) { - if (error.status && error.status.category == categories_1.default.PNCancelledCategory) - return; - return engine.transition(events.handshakeReconnectFailure(error)); - } - } - } - else { - return engine.transition(events.handshakeReconnectGiveup(new pubnub_error_1.PubNubError(config.retryConfiguration - ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) - : 'Unable to complete subscribe handshake'))); - } }))); + this.on(effects.emitStatus.type, (0, core_1.asyncHandler)((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus }) { return emitStatus(payload); }))); } } exports.EventEngineDispatcher = EventEngineDispatcher; diff --git a/lib/event-engine/effects.js b/lib/event-engine/effects.js index 96078052c..ec6d2bcf2 100644 --- a/lib/event-engine/effects.js +++ b/lib/event-engine/effects.js @@ -5,7 +5,7 @@ * @internal */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.handshakeReconnect = exports.receiveReconnect = exports.emitStatus = exports.emitMessages = exports.receiveMessages = exports.handshake = void 0; +exports.emitStatus = exports.emitMessages = exports.receiveMessages = exports.handshake = void 0; const core_1 = require("./core"); /** * Initial subscription effect. @@ -43,19 +43,3 @@ exports.emitMessages = (0, core_1.createEffect)('EMIT_MESSAGES', (events) => eve * @internal */ exports.emitStatus = (0, core_1.createEffect)('EMIT_STATUS', (status) => status); -/** - * Real-time updates receive restore effect. - * - * Performs subscribe REST API call with `tt` which has been received before disconnection or error. - * - * @internal - */ -exports.receiveReconnect = (0, core_1.createManagedEffect)('RECEIVE_RECONNECT', (context) => context); -/** - * Initial subscription restore effect. - * - * Performs subscribe REST API call with `tt=0` after error. - * - * @internal - */ -exports.handshakeReconnect = (0, core_1.createManagedEffect)('HANDSHAKE_RECONNECT', (context) => context); diff --git a/lib/event-engine/events.js b/lib/event-engine/events.js index 499e064b0..e1db92aaa 100644 --- a/lib/event-engine/events.js +++ b/lib/event-engine/events.js @@ -5,7 +5,7 @@ * @internal */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.unsubscribeAll = exports.reconnect = exports.disconnect = exports.receiveReconnectGiveup = exports.receiveReconnectFailure = exports.receiveReconnectSuccess = exports.receiveFailure = exports.receiveSuccess = exports.handshakeReconnectGiveup = exports.handshakeReconnectFailure = exports.handshakeReconnectSuccess = exports.handshakeFailure = exports.handshakeSuccess = exports.restore = exports.subscriptionChange = void 0; +exports.unsubscribeAll = exports.reconnect = exports.disconnect = exports.receiveFailure = exports.receiveSuccess = exports.handshakeFailure = exports.handshakeSuccess = exports.restore = exports.subscriptionChange = void 0; const core_1 = require("./core"); /** * Subscription list change event. @@ -49,32 +49,6 @@ exports.handshakeSuccess = (0, core_1.createEvent)('HANDSHAKE_SUCCESS', (cursor) * @internal */ exports.handshakeFailure = (0, core_1.createEvent)('HANDSHAKE_FAILURE', (error) => error); -/** - * Initial subscription handshake reconnect success event. - * - * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. - * - * @internal - */ -exports.handshakeReconnectSuccess = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_SUCCESS', (cursor) => ({ - cursor, -})); -/** - * Initial subscription handshake reconnect did fail event. - * - * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. - * - * @internal - */ -exports.handshakeReconnectFailure = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_FAILURE', (error) => error); -/** - * Initial subscription handshake impossible event. - * - * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. - * - * @internal - */ -exports.handshakeReconnectGiveup = (0, core_1.createEvent)('HANDSHAKE_RECONNECT_GIVEUP', (error) => error); /** * Subscription successfully received real-time updates event. * @@ -94,33 +68,6 @@ exports.receiveSuccess = (0, core_1.createEvent)('RECEIVE_SUCCESS', (cursor, eve * @internal */ exports.receiveFailure = (0, core_1.createEvent)('RECEIVE_FAILURE', (error) => error); -/** - * Subscription successfully received real-time updates on reconnection attempt event. - * - * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. - * - * @internal - */ -exports.receiveReconnectSuccess = (0, core_1.createEvent)('RECEIVE_RECONNECT_SUCCESS', (cursor, events) => ({ - cursor, - events, -})); -/** - * Subscription did fail to receive real-time updates on reconnection attempt event. - * - * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. - * - * @internal - */ -exports.receiveReconnectFailure = (0, core_1.createEvent)('RECEIVE_RECONNECT_FAILURE', (error) => error); -/** - * Subscription real-time updates received impossible event. - * - * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. - * - * @internal - */ -exports.receiveReconnectGiveup = (0, core_1.createEvent)('RECEIVING_RECONNECT_GIVEUP', (error) => error); /** * Client disconnect event. * @@ -128,7 +75,7 @@ exports.receiveReconnectGiveup = (0, core_1.createEvent)('RECEIVING_RECONNECT_GI * * @internal */ -exports.disconnect = (0, core_1.createEvent)('DISCONNECT', () => ({})); +exports.disconnect = (0, core_1.createEvent)('DISCONNECT', (isOffline) => ({ isOffline })); /** * Client reconnect event. * diff --git a/lib/event-engine/index.js b/lib/event-engine/index.js index 7eea35090..cc0a4db8c 100644 --- a/lib/event-engine/index.js +++ b/lib/event-engine/index.js @@ -98,10 +98,10 @@ class EventEngine { if (new Set(this.channels).size !== new Set(filteredChannels).size || new Set(this.groups).size !== new Set(filteredGroups).size) { const channelsToLeave = utils.findUniqueCommonElements(this.channels, channels); - const groupstoLeave = utils.findUniqueCommonElements(this.groups, channelGroups); + const groupsToLeave = utils.findUniqueCommonElements(this.groups, channelGroups); if (this.dependencies.presenceState) { channelsToLeave === null || channelsToLeave === void 0 ? void 0 : channelsToLeave.forEach((c) => delete this.dependencies.presenceState[c]); - groupstoLeave === null || groupstoLeave === void 0 ? void 0 : groupstoLeave.forEach((g) => delete this.dependencies.presenceState[g]); + groupsToLeave === null || groupsToLeave === void 0 ? void 0 : groupsToLeave.forEach((g) => delete this.dependencies.presenceState[g]); } this.channels = filteredChannels; this.groups = filteredGroups; @@ -109,7 +109,7 @@ class EventEngine { if (this.dependencies.leave) { this.dependencies.leave({ channels: channelsToLeave.slice(0), - groups: groupstoLeave.slice(0), + groups: groupsToLeave.slice(0), }); } } @@ -129,14 +129,18 @@ class EventEngine { this.dependencies.leaveAll({ channels, groups: channelGroups }); } reconnect({ timetoken, region }) { + const channelGroups = this.getSubscribedChannels(); + const channels = this.getSubscribedChannels(); this.engine.transition(events.reconnect(timetoken, region)); + if (this.dependencies.presenceReconnect) + this.dependencies.presenceReconnect({ channels, groups: channelGroups }); } - disconnect() { + disconnect(isOffline) { const channelGroups = this.getSubscribedChannels(); const channels = this.getSubscribedChannels(); - this.engine.transition(events.disconnect()); - if (this.dependencies.leaveAll) - this.dependencies.leaveAll({ channels, groups: channelGroups }); + this.engine.transition(events.disconnect(isOffline)); + if (this.dependencies.presenceDisconnect) + this.dependencies.presenceDisconnect({ channels, groups: channelGroups, isOffline }); } getSubscribedChannels() { return Array.from(new Set(this.channels.slice(0))); @@ -145,7 +149,7 @@ class EventEngine { return Array.from(new Set(this.groups.slice(0))); } dispose() { - this.disconnect(); + this.disconnect(true); this._unsubscribeEngine(); this.dispatcher.dispose(); } diff --git a/lib/event-engine/presence/dispatcher.js b/lib/event-engine/presence/dispatcher.js index 120c13478..769138fe9 100644 --- a/lib/event-engine/presence/dispatcher.js +++ b/lib/event-engine/presence/dispatcher.js @@ -51,12 +51,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PresenceEventEngineDispatcher = void 0; +const categories_1 = __importDefault(require("../../core/constants/categories")); const core_1 = require("../core"); const operations_1 = __importDefault(require("../../core/constants/operations")); const pubnub_error_1 = require("../../errors/pubnub-error"); const effects = __importStar(require("./effects")); const events = __importStar(require("./events")); -const categories_1 = __importDefault(require("../../core/constants/categories")); /** * Presence Event Engine dispatcher. * @@ -76,7 +76,7 @@ class PresenceEventEngineDispatcher extends core_1.Dispatcher { if (e instanceof pubnub_error_1.PubNubError) { if (e.status && e.status.category == categories_1.default.PNCancelledCategory) return; - return engine.transition(events.heartbeatFailure(e)); + engine.transition(events.heartbeatFailure(e)); } } }))); @@ -97,34 +97,12 @@ class PresenceEventEngineDispatcher extends core_1.Dispatcher { abortSignal.throwIfAborted(); return engine.transition(events.timesUp()); }))); - this.on(effects.delayedHeartbeat.type, (0, core_1.asyncHandler)((payload_1, abortSignal_1, _a) => __awaiter(this, [payload_1, abortSignal_1, _a], void 0, function* (payload, abortSignal, { heartbeat, retryDelay, presenceState, config }) { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - yield retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); - abortSignal.throwIfAborted(); - try { - const result = yield heartbeat(Object.assign(Object.assign({ channels: payload.channels, channelGroups: payload.groups }, (config.maintainPresenceState && { state: presenceState })), { heartbeat: config.presenceTimeout })); - return engine.transition(events.heartbeatSuccess(200)); - } - catch (e) { - if (e instanceof pubnub_error_1.PubNubError) { - if (e.status && e.status.category == categories_1.default.PNCancelledCategory) - return; - return engine.transition(events.heartbeatFailure(e)); - } - } - } - else { - return engine.transition(events.heartbeatGiveup()); - } - }))); this.on(effects.emitStatus.type, (0, core_1.asyncHandler)((payload_1, _1, _a) => __awaiter(this, [payload_1, _1, _a], void 0, function* (payload, _, { emitStatus, config }) { - var _b; - if (config.announceFailedHeartbeats && ((_b = payload === null || payload === void 0 ? void 0 : payload.status) === null || _b === void 0 ? void 0 : _b.error) === true) { - emitStatus(payload.status); + if (config.announceFailedHeartbeats && (payload === null || payload === void 0 ? void 0 : payload.error) === true) { + emitStatus(Object.assign(Object.assign({}, payload), { operation: operations_1.default.PNHeartbeatOperation })); } else if (config.announceSuccessfulHeartbeats && payload.statusCode === 200) { - emitStatus(Object.assign(Object.assign({}, payload), { operation: operations_1.default.PNHeartbeatOperation, error: false })); + emitStatus(Object.assign(Object.assign({}, payload), { error: false, operation: operations_1.default.PNHeartbeatOperation, category: categories_1.default.PNAcknowledgmentCategory })); } }))); } diff --git a/lib/event-engine/presence/effects.js b/lib/event-engine/presence/effects.js index 16c0a43bb..5198cff98 100644 --- a/lib/event-engine/presence/effects.js +++ b/lib/event-engine/presence/effects.js @@ -5,7 +5,7 @@ * @internal */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.delayedHeartbeat = exports.wait = exports.emitStatus = exports.leave = exports.heartbeat = void 0; +exports.wait = exports.emitStatus = exports.leave = exports.heartbeat = void 0; const core_1 = require("../core"); /** * Presence heartbeat effect. @@ -14,7 +14,7 @@ const core_1 = require("../core"); * * @internal */ -exports.heartbeat = (0, core_1.createEffect)('HEARTBEAT', (channels, groups) => ({ +exports.heartbeat = (0, core_1.createManagedEffect)('HEARTBEAT', (channels, groups) => ({ channels, groups, })); @@ -46,11 +46,3 @@ exports.emitStatus = (0, core_1.createEffect)('EMIT_STATUS', (status) => status) * @internal */ exports.wait = (0, core_1.createManagedEffect)('WAIT', () => ({})); -/** - * Delayed heartbeat effect. - * - * Similar to the {@link wait} effect but used in case if previous heartbeat call did fail. - * - * @internal - */ -exports.delayedHeartbeat = (0, core_1.createManagedEffect)('DELAYED_HEARTBEAT', (context) => context); diff --git a/lib/event-engine/presence/events.js b/lib/event-engine/presence/events.js index 625408642..7a57387df 100644 --- a/lib/event-engine/presence/events.js +++ b/lib/event-engine/presence/events.js @@ -5,7 +5,7 @@ * @internal */ Object.defineProperty(exports, "__esModule", { value: true }); -exports.timesUp = exports.heartbeatGiveup = exports.heartbeatFailure = exports.heartbeatSuccess = exports.leftAll = exports.left = exports.joined = exports.disconnect = exports.reconnect = void 0; +exports.timesUp = exports.heartbeatFailure = exports.heartbeatSuccess = exports.leftAll = exports.left = exports.joined = exports.disconnect = exports.reconnect = void 0; const core_1 = require("../core"); /** * Reconnect event. @@ -24,7 +24,7 @@ exports.reconnect = (0, core_1.createEvent)('RECONNECT', () => ({})); * * @internal */ -exports.disconnect = (0, core_1.createEvent)('DISCONNECT', () => ({})); +exports.disconnect = (0, core_1.createEvent)('DISCONNECT', (isOffline) => ({ isOffline })); /** * Channel / group join event. * @@ -74,14 +74,6 @@ exports.heartbeatSuccess = (0, core_1.createEvent)('HEARTBEAT_SUCCESS', (statusC * @internal */ exports.heartbeatFailure = (0, core_1.createEvent)('HEARTBEAT_FAILURE', (error) => error); -/** - * Presence heartbeat impossible event. - * - * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. - * - * @internal - */ -exports.heartbeatGiveup = (0, core_1.createEvent)('HEARTBEAT_GIVEUP', () => ({})); /** * Delayed presence heartbeat event. * diff --git a/lib/event-engine/presence/presence.js b/lib/event-engine/presence/presence.js index a319f1e5a..49b03378a 100644 --- a/lib/event-engine/presence/presence.js +++ b/lib/event-engine/presence/presence.js @@ -80,7 +80,14 @@ class PresenceEventEngine { leaveAll() { this.engine.transition(events.leftAll()); } + reconnect() { + this.engine.transition(events.reconnect()); + } + disconnect(isOffline) { + this.engine.transition(events.disconnect(isOffline)); + } dispose() { + this.disconnect(true); this._unsubscribeEngine(); this.dispatcher.dispose(); } diff --git a/lib/event-engine/presence/states/heartbeat_cooldown.js b/lib/event-engine/presence/states/heartbeat_cooldown.js index 061190231..6da55a77f 100644 --- a/lib/event-engine/presence/states/heartbeat_cooldown.js +++ b/lib/event-engine/presence/states/heartbeat_cooldown.js @@ -34,8 +34,7 @@ exports.HeartbeatCooldownState.on(events_1.left.type, (context, event) => heartb channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), groups: context.groups.filter((group) => !event.payload.groups.includes(group)), }, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)])); -exports.HeartbeatCooldownState.on(events_1.disconnect.type, (context) => heartbeat_stopped_1.HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, -}, [(0, effects_1.leave)(context.channels, context.groups)])); +exports.HeartbeatCooldownState.on(events_1.disconnect.type, (context, event) => heartbeat_stopped_1.HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ + ...(!event.payload.isOffline ? [(0, effects_1.leave)(context.channels, context.groups)] : []), +])); exports.HeartbeatCooldownState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); diff --git a/lib/event-engine/presence/states/heartbeat_failed.js b/lib/event-engine/presence/states/heartbeat_failed.js index a74c72fdf..c6c665b25 100644 --- a/lib/event-engine/presence/states/heartbeat_failed.js +++ b/lib/event-engine/presence/states/heartbeat_failed.js @@ -33,8 +33,7 @@ exports.HeartbeatFailedState.on(events_1.reconnect.type, (context, _) => heartbe channels: context.channels, groups: context.groups, })); -exports.HeartbeatFailedState.on(events_1.disconnect.type, (context, _) => heartbeat_stopped_1.HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, -}, [(0, effects_1.leave)(context.channels, context.groups)])); +exports.HeartbeatFailedState.on(events_1.disconnect.type, (context, event) => heartbeat_stopped_1.HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ + ...(!event.payload.isOffline ? [(0, effects_1.leave)(context.channels, context.groups)] : []), +])); exports.HeartbeatFailedState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); diff --git a/lib/event-engine/presence/states/heartbeat_reconnecting.js b/lib/event-engine/presence/states/heartbeat_reconnecting.js deleted file mode 100644 index cc265a5c0..000000000 --- a/lib/event-engine/presence/states/heartbeat_reconnecting.js +++ /dev/null @@ -1,54 +0,0 @@ -"use strict"; -/** - * Retry heartbeat state module. - * - * @internal - */ -Object.defineProperty(exports, "__esModule", { value: true }); -exports.HearbeatReconnectingState = void 0; -const state_1 = require("../../core/state"); -const events_1 = require("../events"); -const effects_1 = require("../effects"); -const heartbeating_1 = require("./heartbeating"); -const heartbeat_stopped_1 = require("./heartbeat_stopped"); -const heartbeat_cooldown_1 = require("./heartbeat_cooldown"); -const heartbeat_inactive_1 = require("./heartbeat_inactive"); -const heartbeat_failed_1 = require("./heartbeat_failed"); -/** - * Retry heartbeat state. - * - * State in which Presence Event Engine tries to recover after error which happened before. - * - * @internal - */ -exports.HearbeatReconnectingState = new state_1.State('HEARBEAT_RECONNECTING'); -exports.HearbeatReconnectingState.onEnter((context) => (0, effects_1.delayedHeartbeat)(context)); -exports.HearbeatReconnectingState.onExit(() => effects_1.delayedHeartbeat.cancel); -exports.HearbeatReconnectingState.on(events_1.joined.type, (context, event) => heartbeating_1.HeartbeatingState.with({ - channels: [...context.channels, ...event.payload.channels], - groups: [...context.groups, ...event.payload.groups], -})); -exports.HearbeatReconnectingState.on(events_1.left.type, (context, event) => heartbeating_1.HeartbeatingState.with({ - channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), - groups: context.groups.filter((group) => !event.payload.groups.includes(group)), -}, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)])); -exports.HearbeatReconnectingState.on(events_1.disconnect.type, (context, _) => { - heartbeat_stopped_1.HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, - }, [(0, effects_1.leave)(context.channels, context.groups)]); -}); -exports.HearbeatReconnectingState.on(events_1.heartbeatSuccess.type, (context, event) => { - return heartbeat_cooldown_1.HeartbeatCooldownState.with({ - channels: context.channels, - groups: context.groups, - }); -}); -exports.HearbeatReconnectingState.on(events_1.heartbeatFailure.type, (context, event) => exports.HearbeatReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); -exports.HearbeatReconnectingState.on(events_1.heartbeatGiveup.type, (context, event) => { - return heartbeat_failed_1.HeartbeatFailedState.with({ - channels: context.channels, - groups: context.groups, - }); -}); -exports.HearbeatReconnectingState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); diff --git a/lib/event-engine/presence/states/heartbeating.js b/lib/event-engine/presence/states/heartbeating.js index b93059d8e..20ae37a96 100644 --- a/lib/event-engine/presence/states/heartbeating.js +++ b/lib/event-engine/presence/states/heartbeating.js @@ -6,13 +6,13 @@ */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HeartbeatingState = void 0; -const state_1 = require("../../core/state"); const events_1 = require("../events"); -const effects_1 = require("../effects"); +const heartbeat_inactive_1 = require("./heartbeat_inactive"); const heartbeat_cooldown_1 = require("./heartbeat_cooldown"); -const heartbeat_reconnecting_1 = require("./heartbeat_reconnecting"); const heartbeat_stopped_1 = require("./heartbeat_stopped"); -const heartbeat_inactive_1 = require("./heartbeat_inactive"); +const heartbeat_failed_1 = require("./heartbeat_failed"); +const effects_1 = require("../effects"); +const state_1 = require("../../core/state"); /** * Heartbeating state module. * @@ -22,12 +22,10 @@ const heartbeat_inactive_1 = require("./heartbeat_inactive"); */ exports.HeartbeatingState = new state_1.State('HEARTBEATING'); exports.HeartbeatingState.onEnter((context) => (0, effects_1.heartbeat)(context.channels, context.groups)); -exports.HeartbeatingState.on(events_1.heartbeatSuccess.type, (context, event) => { - return heartbeat_cooldown_1.HeartbeatCooldownState.with({ - channels: context.channels, - groups: context.groups, - }); -}); +exports.HeartbeatingState.onExit(() => effects_1.heartbeat.cancel); +exports.HeartbeatingState.on(events_1.heartbeatSuccess.type, (context, event) => heartbeat_cooldown_1.HeartbeatCooldownState.with({ channels: context.channels, groups: context.groups }, [ + (0, effects_1.emitStatus)(Object.assign({}, event.payload)), +])); exports.HeartbeatingState.on(events_1.joined.type, (context, event) => exports.HeartbeatingState.with({ channels: [...context.channels, ...event.payload.channels], groups: [...context.groups, ...event.payload.groups], @@ -38,11 +36,10 @@ exports.HeartbeatingState.on(events_1.left.type, (context, event) => { groups: context.groups.filter((group) => !event.payload.groups.includes(group)), }, [(0, effects_1.leave)(event.payload.channels, event.payload.groups)]); }); -exports.HeartbeatingState.on(events_1.heartbeatFailure.type, (context, event) => { - return heartbeat_reconnecting_1.HearbeatReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: 0, reason: event.payload })); -}); -exports.HeartbeatingState.on(events_1.disconnect.type, (context) => heartbeat_stopped_1.HeartbeatStoppedState.with({ - channels: context.channels, - groups: context.groups, -}, [(0, effects_1.leave)(context.channels, context.groups)])); +exports.HeartbeatingState.on(events_1.heartbeatFailure.type, (context, event) => heartbeat_failed_1.HeartbeatFailedState.with(Object.assign({}, context), [ + ...(event.payload.status ? [(0, effects_1.emitStatus)(Object.assign({}, event.payload.status))] : []), +])); +exports.HeartbeatingState.on(events_1.disconnect.type, (context, event) => heartbeat_stopped_1.HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ + ...(!event.payload.isOffline ? [(0, effects_1.leave)(context.channels, context.groups)] : []), +])); exports.HeartbeatingState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); diff --git a/lib/event-engine/states/handshake_failed.js b/lib/event-engine/states/handshake_failed.js index 457940d56..7010c7d6c 100644 --- a/lib/event-engine/states/handshake_failed.js +++ b/lib/event-engine/states/handshake_failed.js @@ -19,24 +19,20 @@ const unsubscribed_1 = require("./unsubscribed"); * @internal */ exports.HandshakeFailedState = new state_1.State('HANDSHAKE_FAILED'); -exports.HandshakeFailedState.on(events_1.subscriptionChange.type, (context, event) => handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, -})); -exports.HandshakeFailedState.on(events_1.reconnect.type, (context, event) => handshaking_1.HandshakingState.with({ +exports.HandshakeFailedState.on(events_1.subscriptionChange.type, (context, { payload }) => handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); +exports.HandshakeFailedState.on(events_1.reconnect.type, (context, { payload }) => handshaking_1.HandshakingState.with({ channels: context.channels, groups: context.groups, - cursor: event.payload.cursor || context.cursor, + cursor: payload.cursor || context.cursor, })); -exports.HandshakeFailedState.on(events_1.restore.type, (context, event) => { +exports.HandshakeFailedState.on(events_1.restore.type, (context, { payload }) => { var _a, _b; return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, + channels: payload.channels, + groups: payload.groups, cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region ? event.payload.cursor.region : ((_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0), + timetoken: payload.cursor.timetoken, + region: payload.cursor.region ? payload.cursor.region : ((_b = (_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) !== null && _b !== void 0 ? _b : 0), }, }); }); diff --git a/lib/event-engine/states/handshake_reconnecting.js b/lib/event-engine/states/handshake_reconnecting.js deleted file mode 100644 index 9f8e61c9f..000000000 --- a/lib/event-engine/states/handshake_reconnecting.js +++ /dev/null @@ -1,74 +0,0 @@ -"use strict"; -/** - * Retry initial subscription handshake (disconnected) state. - * - * @internal - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.HandshakeReconnectingState = void 0; -const state_1 = require("../core/state"); -const effects_1 = require("../effects"); -const events_1 = require("../events"); -const handshake_failed_1 = require("./handshake_failed"); -const handshake_stopped_1 = require("./handshake_stopped"); -const handshaking_1 = require("./handshaking"); -const receiving_1 = require("./receiving"); -const unsubscribed_1 = require("./unsubscribed"); -const categories_1 = __importDefault(require("../../core/constants/categories")); -/** - * Retry initial subscription handshake (disconnected) state. - * - * State in which Subscription Event Engine tries to recover after error which happened before. - * - * @internal - */ -exports.HandshakeReconnectingState = new state_1.State('HANDSHAKE_RECONNECTING'); -exports.HandshakeReconnectingState.onEnter((context) => (0, effects_1.handshakeReconnect)(context)); -exports.HandshakeReconnectingState.onExit(() => effects_1.handshakeReconnect.cancel); -exports.HandshakeReconnectingState.on(events_1.handshakeReconnectSuccess.type, (context, event) => { - var _a, _b; - const cursor = { - timetoken: !!((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : event.payload.cursor.timetoken, - region: event.payload.cursor.region, - }; - return receiving_1.ReceivingState.with({ - channels: context.channels, - groups: context.groups, - cursor: cursor, - }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNConnectedCategory })]); -}); -exports.HandshakeReconnectingState.on(events_1.handshakeReconnectFailure.type, (context, event) => exports.HandshakeReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); -exports.HandshakeReconnectingState.on(events_1.handshakeReconnectGiveup.type, (context, event) => { - var _a; - return handshake_failed_1.HandshakeFailedState.with({ - groups: context.groups, - channels: context.channels, - cursor: context.cursor, - reason: event.payload, - }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNConnectionErrorCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); -}); -exports.HandshakeReconnectingState.on(events_1.disconnect.type, (context) => handshake_stopped_1.HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, -})); -exports.HandshakeReconnectingState.on(events_1.subscriptionChange.type, (context, event) => handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, -})); -exports.HandshakeReconnectingState.on(events_1.restore.type, (context, event) => { - var _a, _b; - return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: ((_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.region) || ((_b = context === null || context === void 0 ? void 0 : context.cursor) === null || _b === void 0 ? void 0 : _b.region) || 0, - }, - }); -}); -exports.HandshakeReconnectingState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with(undefined)); diff --git a/lib/event-engine/states/handshake_stopped.js b/lib/event-engine/states/handshake_stopped.js index d8af1cea1..62bf85b00 100644 --- a/lib/event-engine/states/handshake_stopped.js +++ b/lib/event-engine/states/handshake_stopped.js @@ -19,21 +19,14 @@ const unsubscribed_1 = require("./unsubscribed"); * @internal */ exports.HandshakeStoppedState = new state_1.State('HANDSHAKE_STOPPED'); -exports.HandshakeStoppedState.on(events_1.subscriptionChange.type, (context, event) => exports.HandshakeStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, -})); -exports.HandshakeStoppedState.on(events_1.reconnect.type, (context, event) => handshaking_1.HandshakingState.with(Object.assign(Object.assign({}, context), { cursor: event.payload.cursor || context.cursor }))); -exports.HandshakeStoppedState.on(events_1.restore.type, (context, event) => { +exports.HandshakeStoppedState.on(events_1.subscriptionChange.type, (context, { payload }) => exports.HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); +exports.HandshakeStoppedState.on(events_1.reconnect.type, (context, { payload }) => handshaking_1.HandshakingState.with(Object.assign(Object.assign({}, context), { cursor: payload.cursor || context.cursor }))); +exports.HandshakeStoppedState.on(events_1.restore.type, (context, { payload }) => { var _a; return exports.HandshakeStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0, - }, + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || ((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0 }, }); }); exports.HandshakeStoppedState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with()); diff --git a/lib/event-engine/states/handshaking.js b/lib/event-engine/states/handshaking.js index b4cd08709..c9f34d4b2 100644 --- a/lib/event-engine/states/handshaking.js +++ b/lib/event-engine/states/handshaking.js @@ -9,14 +9,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HandshakingState = void 0; -const state_1 = require("../core/state"); const effects_1 = require("../effects"); const events_1 = require("../events"); -const handshake_reconnecting_1 = require("./handshake_reconnecting"); +const categories_1 = __importDefault(require("../../core/constants/categories")); const handshake_stopped_1 = require("./handshake_stopped"); -const receiving_1 = require("./receiving"); +const handshake_failed_1 = require("./handshake_failed"); const unsubscribed_1 = require("./unsubscribed"); -const categories_1 = __importDefault(require("../../core/constants/categories")); +const receiving_1 = require("./receiving"); +const state_1 = require("../core/state"); +const pubnub_api_error_1 = require("../../errors/pubnub-api-error"); +const operations_1 = __importDefault(require("../../core/constants/operations")); /** * Initial subscription handshake (disconnected) state. * @@ -28,54 +30,51 @@ const categories_1 = __importDefault(require("../../core/constants/categories")) exports.HandshakingState = new state_1.State('HANDSHAKING'); exports.HandshakingState.onEnter((context) => (0, effects_1.handshake)(context.channels, context.groups)); exports.HandshakingState.onExit(() => effects_1.handshake.cancel); -exports.HandshakingState.on(events_1.subscriptionChange.type, (context, event) => { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { +exports.HandshakingState.on(events_1.subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return unsubscribed_1.UnsubscribedState.with(undefined); - } - return exports.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); + return exports.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); }); -exports.HandshakingState.on(events_1.handshakeSuccess.type, (context, event) => { +exports.HandshakingState.on(events_1.handshakeSuccess.type, (context, { payload }) => { var _a, _b; return receiving_1.ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: { - timetoken: !!((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context === null || context === void 0 ? void 0 : context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : event.payload.timetoken, - region: event.payload.region, + timetoken: !!((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : payload.timetoken, + region: payload.region, }, - }, [ - (0, effects_1.emitStatus)({ - category: categories_1.default.PNConnectedCategory, - }), - ]); + }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNConnectedCategory })]); }); exports.HandshakingState.on(events_1.handshakeFailure.type, (context, event) => { - return handshake_reconnecting_1.HandshakeReconnectingState.with({ + var _a; + return handshake_failed_1.HandshakeFailedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor, - attempts: 0, reason: event.payload, - }); + }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNConnectionErrorCategory, error: (_a = event.payload.status) === null || _a === void 0 ? void 0 : _a.category })]); +}); +exports.HandshakingState.on(events_1.disconnect.type, (context, event) => { + var _a; + if (!event.payload.isOffline) + return handshake_stopped_1.HandshakeStoppedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor }); + else { + const errorReason = pubnub_api_error_1.PubNubAPIError.create(new Error('Network connection error')).toPubNubError(operations_1.default.PNSubscribeOperation); + return handshake_failed_1.HandshakeFailedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor, reason: errorReason }, [ + (0, effects_1.emitStatus)({ + category: categories_1.default.PNConnectionErrorCategory, + error: (_a = errorReason.status) === null || _a === void 0 ? void 0 : _a.category, + }), + ]); + } }); -exports.HandshakingState.on(events_1.disconnect.type, (context) => handshake_stopped_1.HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, -})); -exports.HandshakingState.on(events_1.restore.type, (context, event) => { +exports.HandshakingState.on(events_1.restore.type, (context, { payload }) => { var _a; return exports.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0, - }, + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || ((_a = context === null || context === void 0 ? void 0 : context.cursor) === null || _a === void 0 ? void 0 : _a.region) || 0 }, }); }); exports.HandshakingState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with()); diff --git a/lib/event-engine/states/receive_failed.js b/lib/event-engine/states/receive_failed.js index 3794a03b6..a2fc22708 100644 --- a/lib/event-engine/states/receive_failed.js +++ b/lib/event-engine/states/receive_failed.js @@ -19,28 +19,21 @@ const unsubscribed_1 = require("./unsubscribed"); * @internal */ exports.ReceiveFailedState = new state_1.State('RECEIVE_FAILED'); -exports.ReceiveFailedState.on(events_1.reconnect.type, (context, event) => { +exports.ReceiveFailedState.on(events_1.reconnect.type, (context, { payload }) => { var _a; return handshaking_1.HandshakingState.with({ channels: context.channels, groups: context.groups, cursor: { - timetoken: !!event.payload.cursor.timetoken ? (_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, + timetoken: !!payload.cursor.timetoken ? (_a = payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, + region: payload.cursor.region || context.cursor.region, }, }); }); -exports.ReceiveFailedState.on(events_1.subscriptionChange.type, (context, event) => handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, -})); -exports.ReceiveFailedState.on(events_1.restore.type, (context, event) => handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, +exports.ReceiveFailedState.on(events_1.subscriptionChange.type, (context, { payload }) => handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); +exports.ReceiveFailedState.on(events_1.restore.type, (context, { payload }) => handshaking_1.HandshakingState.with({ + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, })); exports.ReceiveFailedState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with(undefined)); diff --git a/lib/event-engine/states/receive_reconnecting.js b/lib/event-engine/states/receive_reconnecting.js deleted file mode 100644 index 428ffc028..000000000 --- a/lib/event-engine/states/receive_reconnecting.js +++ /dev/null @@ -1,63 +0,0 @@ -"use strict"; -/** - * Reconnect to receive real-time updates (disconnected) state. - * - * @internal - */ -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.ReceiveReconnectingState = void 0; -const state_1 = require("../core/state"); -const effects_1 = require("../effects"); -const events_1 = require("../events"); -const receiving_1 = require("./receiving"); -const receive_failed_1 = require("./receive_failed"); -const receive_stopped_1 = require("./receive_stopped"); -const unsubscribed_1 = require("./unsubscribed"); -const categories_1 = __importDefault(require("../../core/constants/categories")); -/** - * Reconnect to receive real-time updates (disconnected) state. - * - * State in which Subscription Event Engine tries to recover after error which happened before. - * - * @internal - */ -exports.ReceiveReconnectingState = new state_1.State('RECEIVE_RECONNECTING'); -exports.ReceiveReconnectingState.onEnter((context) => (0, effects_1.receiveReconnect)(context)); -exports.ReceiveReconnectingState.onExit(() => effects_1.receiveReconnect.cancel); -exports.ReceiveReconnectingState.on(events_1.receiveReconnectSuccess.type, (context, event) => receiving_1.ReceivingState.with({ - channels: context.channels, - groups: context.groups, - cursor: event.payload.cursor, -}, [(0, effects_1.emitMessages)(event.payload.events)])); -exports.ReceiveReconnectingState.on(events_1.receiveReconnectFailure.type, (context, event) => exports.ReceiveReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: context.attempts + 1, reason: event.payload }))); -exports.ReceiveReconnectingState.on(events_1.receiveReconnectGiveup.type, (context, event) => { - var _a; - return receive_failed_1.ReceiveFailedState.with({ - groups: context.groups, - channels: context.channels, - cursor: context.cursor, - reason: event.payload, - }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedUnexpectedlyCategory, error: (_a = event.payload) === null || _a === void 0 ? void 0 : _a.message })]); -}); -exports.ReceiveReconnectingState.on(events_1.disconnect.type, (context) => receive_stopped_1.ReceiveStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, -}, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })])); -exports.ReceiveReconnectingState.on(events_1.restore.type, (context, event) => receiving_1.ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, -})); -exports.ReceiveReconnectingState.on(events_1.subscriptionChange.type, (context, event) => receiving_1.ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, -})); -exports.ReceiveReconnectingState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })])); diff --git a/lib/event-engine/states/receive_stopped.js b/lib/event-engine/states/receive_stopped.js index e608078a5..5d456cc48 100644 --- a/lib/event-engine/states/receive_stopped.js +++ b/lib/event-engine/states/receive_stopped.js @@ -19,27 +19,20 @@ const unsubscribed_1 = require("./unsubscribed"); * @internal */ exports.ReceiveStoppedState = new state_1.State('RECEIVE_STOPPED'); -exports.ReceiveStoppedState.on(events_1.subscriptionChange.type, (context, event) => exports.ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, +exports.ReceiveStoppedState.on(events_1.subscriptionChange.type, (context, { payload }) => exports.ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); +exports.ReceiveStoppedState.on(events_1.restore.type, (context, { payload }) => exports.ReceiveStoppedState.with({ + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, })); -exports.ReceiveStoppedState.on(events_1.restore.type, (context, event) => exports.ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, -})); -exports.ReceiveStoppedState.on(events_1.reconnect.type, (context, event) => { +exports.ReceiveStoppedState.on(events_1.reconnect.type, (context, { payload }) => { var _a; return handshaking_1.HandshakingState.with({ channels: context.channels, groups: context.groups, cursor: { - timetoken: !!event.payload.cursor.timetoken ? (_a = event.payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, + timetoken: !!payload.cursor.timetoken ? (_a = payload.cursor) === null || _a === void 0 ? void 0 : _a.timetoken : context.cursor.timetoken, + region: payload.cursor.region || context.cursor.region, }, }); }); diff --git a/lib/event-engine/states/receiving.js b/lib/event-engine/states/receiving.js index 381c722fc..8b66d52bd 100644 --- a/lib/event-engine/states/receiving.js +++ b/lib/event-engine/states/receiving.js @@ -9,13 +9,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReceivingState = void 0; -const state_1 = require("../core/state"); const effects_1 = require("../effects"); const events_1 = require("../events"); -const unsubscribed_1 = require("./unsubscribed"); -const receive_reconnecting_1 = require("./receive_reconnecting"); -const receive_stopped_1 = require("./receive_stopped"); const categories_1 = __importDefault(require("../../core/constants/categories")); +const receive_stopped_1 = require("./receive_stopped"); +const receive_failed_1 = require("./receive_failed"); +const unsubscribed_1 = require("./unsubscribed"); +const state_1 = require("../core/state"); +const pubnub_api_error_1 = require("../../errors/pubnub-api-error"); +const operations_1 = __importDefault(require("../../core/constants/operations")); /** * Receiving real-time updates (connected) state. * @@ -26,42 +28,58 @@ const categories_1 = __importDefault(require("../../core/constants/categories")) exports.ReceivingState = new state_1.State('RECEIVING'); exports.ReceivingState.onEnter((context) => (0, effects_1.receiveMessages)(context.channels, context.groups, context.cursor)); exports.ReceivingState.onExit(() => effects_1.receiveMessages.cancel); -exports.ReceivingState.on(events_1.receiveSuccess.type, (context, event) => { - return exports.ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: event.payload.cursor }, [ - (0, effects_1.emitMessages)(event.payload.events), +exports.ReceivingState.on(events_1.receiveSuccess.type, (context, { payload }) => { + return exports.ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: payload.cursor }, [ + (0, effects_1.emitMessages)(payload.events), ]); }); -exports.ReceivingState.on(events_1.subscriptionChange.type, (context, event) => { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return unsubscribed_1.UnsubscribedState.with(undefined); - } - return exports.ReceivingState.with({ - cursor: context.cursor, - channels: event.payload.channels, - groups: event.payload.groups, - }); +exports.ReceivingState.on(events_1.subscriptionChange.type, (context, { payload }) => { + const subscriptionChangeStatus = { + category: categories_1.default.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + }; + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)(subscriptionChangeStatus)]); + return exports.ReceivingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }, [ + (0, effects_1.emitStatus)(subscriptionChangeStatus), + ]); }); -exports.ReceivingState.on(events_1.restore.type, (context, event) => { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return unsubscribed_1.UnsubscribedState.with(undefined); - } +exports.ReceivingState.on(events_1.restore.type, (context, { payload }) => { + const subscriptionChangeStatus = { + category: categories_1.default.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + }; + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)(subscriptionChangeStatus)]); return exports.ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, + }, [(0, effects_1.emitStatus)(subscriptionChangeStatus)]); }); -exports.ReceivingState.on(events_1.receiveFailure.type, (context, event) => { - return receive_reconnecting_1.ReceiveReconnectingState.with(Object.assign(Object.assign({}, context), { attempts: 0, reason: event.payload })); +exports.ReceivingState.on(events_1.receiveFailure.type, (context, { payload }) => { + var _a; + return receive_failed_1.ReceiveFailedState.with(Object.assign(Object.assign({}, context), { reason: payload }), [ + (0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedUnexpectedlyCategory, error: (_a = payload.status) === null || _a === void 0 ? void 0 : _a.category }), + ]); }); -exports.ReceivingState.on(events_1.disconnect.type, (context) => { - return receive_stopped_1.ReceiveStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })]); +exports.ReceivingState.on(events_1.disconnect.type, (context, event) => { + var _a; + if (!event.payload.isOffline) { + return receive_stopped_1.ReceiveStoppedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor }, [ + (0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory }), + ]); + } + else { + const errorReason = pubnub_api_error_1.PubNubAPIError.create(new Error('Network connection error')).toPubNubError(operations_1.default.PNSubscribeOperation); + return receive_failed_1.ReceiveFailedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor, reason: errorReason }, [ + (0, effects_1.emitStatus)({ + category: categories_1.default.PNDisconnectedUnexpectedlyCategory, + error: (_a = errorReason.status) === null || _a === void 0 ? void 0 : _a.category, + }), + ]); + } }); exports.ReceivingState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })])); diff --git a/lib/event-engine/states/unsubscribed.js b/lib/event-engine/states/unsubscribed.js index 29a2f7748..351b848ea 100644 --- a/lib/event-engine/states/unsubscribed.js +++ b/lib/event-engine/states/unsubscribed.js @@ -17,14 +17,5 @@ const handshaking_1 = require("./handshaking"); * @internal */ exports.UnsubscribedState = new state_1.State('UNSUBSCRIBED'); -exports.UnsubscribedState.on(events_1.subscriptionChange.type, (_, event) => handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, -})); -exports.UnsubscribedState.on(events_1.restore.type, (_, event) => { - return handshaking_1.HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: event.payload.cursor, - }); -}); +exports.UnsubscribedState.on(events_1.subscriptionChange.type, (_, { payload }) => handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups })); +exports.UnsubscribedState.on(events_1.restore.type, (_, { payload }) => handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: payload.cursor })); diff --git a/lib/transport/middleware.js b/lib/transport/middleware.js index c677faef7..09d384912 100644 --- a/lib/transport/middleware.js +++ b/lib/transport/middleware.js @@ -4,9 +4,13 @@ * * @internal */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; Object.defineProperty(exports, "__esModule", { value: true }); exports.PubNubMiddleware = void 0; const transport_request_1 = require("../core/types/transport-request"); +const categories_1 = __importDefault(require("../core/constants/categories")); const utils_1 = require("../core/utils"); /** * Request signature generator. @@ -82,7 +86,58 @@ class PubNubMiddleware { } } makeSendable(req) { - return this.configuration.transport.makeSendable(this.request(req)); + const retryPolicy = this.configuration.clientConfiguration.retryConfiguration; + const transport = this.configuration.transport; + // Make requests retryable. + if (retryPolicy !== undefined) { + let retryTimeout; + let activeCancellation; + let cancelled = false; + let attempt = 0; + const cancellation = { + abort: (reason) => { + cancelled = true; + if (retryTimeout) + clearTimeout(retryTimeout); + if (activeCancellation) + activeCancellation.abort(reason); + }, + }; + const retryableRequest = new Promise((resolve, reject) => { + const trySendRequest = () => { + // Check whether request already has been cancelled and there is no retry should proceed. + if (cancelled) + return; + const [attemptPromise, attemptCancellation] = transport.makeSendable(this.request(req)); + activeCancellation = attemptCancellation; + const responseHandler = (res, error) => { + const retriableError = error ? error.category !== categories_1.default.PNCancelledCategory : true; + const retriableStatusCode = !res || res.status >= 400; + let delay = -1; + if (retriableError && + retriableStatusCode && + retryPolicy.shouldRetry(req, res, error === null || error === void 0 ? void 0 : error.category, attempt + 1)) + delay = retryPolicy.getDelay(attempt, res); + if (delay > 0) { + attempt++; + retryTimeout = setTimeout(() => trySendRequest(), delay); + } + else { + if (res) + resolve(res); + else if (error) + reject(error); + } + }; + attemptPromise + .then((res) => responseHandler(res)) + .catch((err) => responseHandler(undefined, err)); + }; + trySendRequest(); + }); + return [retryableRequest, activeCancellation ? cancellation : undefined]; + } + return transport.makeSendable(this.request(req)); } request(req) { var _a; diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 4f4cc5e3a..6334aa404 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -407,8 +407,12 @@ declare class PubNubCore< unsubscribeAll(): void; /** * Temporarily disconnect from real-time events stream. + * + * **Note:** `isOffline` is set to `true` only when client experience network issues. + * + * @param [isOffline] - Whether `offline` presence should be notified or not. */ - disconnect(): void; + disconnect(isOffline?: boolean): void; /** * Restore connection to the real-time events stream. * @@ -1756,7 +1760,7 @@ declare namespace PubNub { /** * Information about error. */ - error?: string | boolean; + error?: string | StatusCategory | boolean; /** * List of channels for which status update announced. */ @@ -2071,6 +2075,10 @@ declare namespace PubNub { * PubNub client connected to the real-time updates stream. */ PNConnectedCategory = 'PNConnectedCategory', + /** + * Set of active channels and groups has been changed. + */ + PNSubscriptionChangedCategory = 'PNSubscriptionChangedCategory', /** * Received real-time updates exceed specified threshold. * @@ -2709,60 +2717,76 @@ declare namespace PubNub { } /** - * Failed request retry policy. + * List of known endpoint groups (by context). */ - export class RetryPolicy { - static LinearRetryPolicy( - configuration: LinearRetryPolicyConfiguration, - ): RequestRetryPolicy & LinearRetryPolicyConfiguration; - static ExponentialRetryPolicy( - configuration: ExponentialRetryPolicyConfiguration, - ): RequestRetryPolicy & ExponentialRetryPolicyConfiguration; + export enum Endpoint { + /** + * The endpoints to send messages. + */ + MessageSend = 'MessageSendEndpoint', + /** + * The endpoint for real-time update retrieval. + */ + Subscribe = 'SubscribeEndpoint', + /** + * The endpoint to access and manage `user_id` presence and fetch channel presence information. + */ + Presence = 'PresenceEndpoint', + /** + * The endpoint to access and manage files in channel-specific storage. + */ + Files = 'FilesEndpoint', + /** + * The endpoint to access and manage messages for a specific channel(s) in the persistent storage. + */ + MessageStorage = 'MessageStorageEndpoint', + /** + * The endpoint to access and manage channel groups. + */ + ChannelGroups = 'ChannelGroupsEndpoint', + /** + * The endpoint to access and manage device registration for channel push notifications. + */ + DevicePushNotifications = 'DevicePushNotificationsEndpoint', + /** + * The endpoint to access and manage App Context objects. + */ + AppContext = 'AppContextEndpoint', + /** + * The endpoint to access and manage reactions for a specific message. + */ + MessageReactions = 'MessageReactionsEndpoint', } + /** + * Request retry configuration interface. + */ export type RequestRetryPolicy = { /** * Check whether failed request can be retried. * - * @param reason - Request processing failure reason. - * @param attempt - Number of sequential failure. + * @param request - Transport request for which retry ability should be identifier. + * @param [response] - Service response (if available) + * @param [errorCategory] - Request processing error category. + * @param [attempt] - Number of sequential failure. * * @returns `true` if another request retry attempt can be done. */ shouldRetry( - reason: PubNubError & { - retryAfter?: number; - }, - attempt: number, + request: TransportRequest, + response?: TransportResponse, + errorCategory?: StatusCategory, + attempt?: number, ): boolean; /** * Computed delay for next request retry attempt. * * @param attempt - Number of sequential failure. - * @param reason - Request processing failure reason. + * @param [response] - Service response (if available). * * @returns Delay before next request retry attempt in milliseconds. */ - getDelay( - attempt: number, - reason: PubNubError & { - retryAfter?: number; - }, - ): number; - /** - * Identify reason why another retry attempt can't be made. - * - * @param reason - Request processing failure reason. - * @param attempt - Number of sequential failure. - * - * @returns Give up reason. - */ - getGiveupReason( - reason: PubNubError & { - retryAfter?: number; - }, - attempt: number, - ): string; + getDelay(attempt: number, response?: TransportResponse): number; /** * Validate retry policy parameters. * @@ -2786,6 +2810,10 @@ declare namespace PubNub { * Maximum number of retry attempts. */ maximumRetry: number; + /** + * Endpoints that won't be retried. + */ + excluded?: Endpoint[]; }; /** @@ -2804,78 +2832,48 @@ declare namespace PubNub { * Maximum number of retry attempts. */ maximumRetry: number; + /** + * Endpoints that won't be retried. + */ + excluded?: Endpoint[]; }; /** - * PubNub operation error. - * - * When an operation can't be performed or there is an error from the server, this object will be returned. + * Failed request retry policy. */ - export class PubNubError extends Error { - status?: Status | undefined; + export class RetryPolicy { + static LinearRetryPolicy( + configuration: LinearRetryPolicyConfiguration, + ): RequestRetryPolicy & LinearRetryPolicyConfiguration; + static ExponentialRetryPolicy( + configuration: ExponentialRetryPolicyConfiguration, + ): RequestRetryPolicy & ExponentialRetryPolicyConfiguration; } /** - * Represents the configuration options for keeping the transport connection alive. + * Represents a transport response from a service. */ - export type TransportKeepAlive = { + export type TransportResponse = { /** - * The time interval in milliseconds for keeping the connection alive. - * - * @default 1000 + * Full remote resource URL used to retrieve response. */ - keepAliveMsecs?: number; + url: string; /** - * The maximum number of sockets allowed per host. - * - * @default Infinity + * Service response status code. */ - maxSockets?: number; + status: number; /** - * The maximum number of open and free sockets in the pool per host. + * Service response headers. * - * @default 256 + * **Important:** Header names are in lowercase. */ - maxFreeSockets?: number; + headers: Record; /** - * Timeout in milliseconds, after which the `idle` socket will be closed. - * - * @default 30000 + * Service response body. */ - timeout?: number; + body?: ArrayBuffer; }; - /** - * This interface is used to send requests to the PubNub API. - * - * You can implement this interface for your types, or use one of the provided modules to use a - * transport library. - * - * @interface - */ - export interface Transport { - /** - * Make request sendable. - * - * @param req - The transport request to be processed. - * - * @returns - A promise that resolves to a transport response and request cancellation - * controller (if required). - */ - makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; - /** - * Pre-processed request. - * - * Transport implementation may pre-process original transport requests before making - * platform-specific request objects from it. - * - * @param req - Transport request provided by the PubNub client. - * - * @returns Transport request with updated properties (if it was required). - */ - request(req: TransportRequest): TransportRequest; - } - /** * Enum representing possible transport methods for HTTP requests. * @@ -2979,29 +2977,66 @@ declare namespace PubNub { }; /** - * Represents a transport response from a service. + * Represents the configuration options for keeping the transport connection alive. */ - export type TransportResponse = { + export type TransportKeepAlive = { /** - * Full remote resource URL used to retrieve response. + * The time interval in milliseconds for keeping the connection alive. + * + * @default 1000 */ - url: string; + keepAliveMsecs?: number; /** - * Service response status code. + * The maximum number of sockets allowed per host. + * + * @default Infinity */ - status: number; + maxSockets?: number; /** - * Service response headers. + * The maximum number of open and free sockets in the pool per host. * - * **Important:** Header names are in lowercase. + * @default 256 */ - headers: Record; + maxFreeSockets?: number; /** - * Service response body. + * Timeout in milliseconds, after which the `idle` socket will be closed. + * + * @default 30000 */ - body?: ArrayBuffer; + timeout?: number; }; + /** + * This interface is used to send requests to the PubNub API. + * + * You can implement this interface for your types, or use one of the provided modules to use a + * transport library. + * + * @interface + */ + export interface Transport { + /** + * Make request sendable. + * + * @param req - The transport request to be processed. + * + * @returns - A promise that resolves to a transport response and request cancellation + * controller (if required). + */ + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined]; + /** + * Pre-processed request. + * + * Transport implementation may pre-process original transport requests before making + * platform-specific request objects from it. + * + * @param req - Transport request provided by the PubNub client. + * + * @returns Transport request with updated properties (if it was required). + */ + request(req: TransportRequest): TransportRequest; + } + /** * Real-time events listener. */ diff --git a/package-lock.json b/package-lock.json index 93b2abefa..bd1ff6ead 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "pubnub", - "version": "9.3.2", + "version": "9.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "pubnub", - "version": "9.3.2", + "version": "9.4.0", "license": "SEE LICENSE IN LICENSE", "dependencies": { "agentkeepalive": "^3.5.2", @@ -39,11 +39,12 @@ "@types/sinon": "^17.0.3", "@types/text-encoding": "^0.0.39", "@types/underscore": "^1.11.15", + "@types/wtfnode": "^0.7.3", "@typescript-eslint/eslint-plugin": "^8.12.2", "@typescript-eslint/parser": "^8.12.2", "chai": "^4.4.1", "chai-as-promised": "^7.1.1", - "chai-nock": "^1.2.0", + "chai-nock": "^1.3.0", "commander": "^12.1.0", "cucumber-tsflow": "^4.4.4", "es6-shim": "^0.35.8", @@ -59,7 +60,7 @@ "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.32", "mocha": "10.4.0", - "nock": "^14.0.0-beta.15", + "nock": "^14.0.3", "prettier": "^3.2.5", "rimraf": "^3.0.2", "rollup": "4.22.4", @@ -72,7 +73,9 @@ "ts-node": "^10.9.2", "tsx": "^4.7.1", "typescript": "^5.4.5", - "underscore": "^1.9.2" + "underscore": "^1.9.2", + "why-is-node-running": "^3.2.2", + "wtfnode": "^0.10.0" } }, "node_modules/@ampproject/remapping": { @@ -3497,9 +3500,9 @@ } }, "node_modules/@mswjs/interceptors": { - "version": "0.38.0", - "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.38.0.tgz", - "integrity": "sha512-nPHVM+LUl4V1kXPXuTcNN5OMD//ltCQ0lccuEagvidJdpbig3hP3W6/ctWHx6mee7vZIWE0L+Mqj3vx0ASlm/w==", + "version": "0.38.3", + "resolved": "https://registry.npmjs.org/@mswjs/interceptors/-/interceptors-0.38.3.tgz", + "integrity": "sha512-3AMc2fTnX4q3qyO6K/LKwWXjUAFc3COC3bo5YCROIyQYJ8g/++5Col5fSIglIyUdBN787CTbL+c04KRwaaZ/UA==", "dev": true, "license": "MIT", "dependencies": { @@ -4831,6 +4834,13 @@ "license": "MIT", "peer": true }, + "node_modules/@types/wtfnode": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/@types/wtfnode/-/wtfnode-0.7.3.tgz", + "integrity": "sha512-UMkHpx+o2xRWLJ7PmT3bBzvIA9/0oFw80oPtY/xO4jfdq+Gznn4wP7K9B/JjMxyxy+wF+5oRPIykxeBbEDjwRg==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/yargs": { "version": "17.0.33", "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.33.tgz", @@ -8869,16 +8879,15 @@ } }, "node_modules/jsdom": { - "version": "26.0.0", - "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-26.0.0.tgz", - "integrity": "sha512-BZYDGVAIriBWTpIxYzrXjv3E/4u8+/pSG5bQdIYCbNCGOvsPkDQfTVLAIXAf9ETdCpduCVTkDe2NNZ8NIwUVzw==", + "version": "26.1.0", + "resolved": "https://registry.npmjs.org/jsdom/-/jsdom-26.1.0.tgz", + "integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==", "dev": true, "license": "MIT", "dependencies": { "cssstyle": "^4.2.1", "data-urls": "^5.0.0", - "decimal.js": "^10.4.3", - "form-data": "^4.0.1", + "decimal.js": "^10.5.0", "html-encoding-sniffer": "^4.0.0", "http-proxy-agent": "^7.0.2", "https-proxy-agent": "^7.0.6", @@ -8888,12 +8897,12 @@ "rrweb-cssom": "^0.8.0", "saxes": "^6.0.0", "symbol-tree": "^3.2.4", - "tough-cookie": "^5.0.0", + "tough-cookie": "^5.1.1", "w3c-xmlserializer": "^5.0.0", "webidl-conversions": "^7.0.0", "whatwg-encoding": "^3.1.1", "whatwg-mimetype": "^4.0.0", - "whatwg-url": "^14.1.0", + "whatwg-url": "^14.1.1", "ws": "^8.18.0", "xml-name-validator": "^5.0.0" }, @@ -10363,13 +10372,13 @@ } }, "node_modules/nock": { - "version": "14.0.2", - "resolved": "https://registry.npmjs.org/nock/-/nock-14.0.2.tgz", - "integrity": "sha512-jDUBpCNY7KLyOF2FTiT4mLRxV2kpjo4YrcGtv3IMCIwqFKxOQFrmeXefvuEiWvS3ApPWQHAkakkkVpoOrDNCVg==", + "version": "14.0.3", + "resolved": "https://registry.npmjs.org/nock/-/nock-14.0.3.tgz", + "integrity": "sha512-sJ9RNmCuYBqXDmGZZHgZ1D1441MqFOU4T5aeLGVGEB4OWI/2LM0mZlkfBQzQKdOfJypL+2nPPBugXKjixBn4kQ==", "dev": true, "license": "MIT", "dependencies": { - "@mswjs/interceptors": "^0.38.0", + "@mswjs/interceptors": "^0.38.1", "json-stringify-safe": "^5.0.1", "propagate": "^2.0.0" }, @@ -13205,22 +13214,22 @@ "peer": true }, "node_modules/tldts": { - "version": "6.1.85", - "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.85.tgz", - "integrity": "sha512-gBdZ1RjCSevRPFix/hpaUWeak2/RNUZB4/8frF1r5uYMHjFptkiT0JXIebWvgI/0ZHXvxaUDDJshiA0j6GdL3w==", + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-6.1.86.tgz", + "integrity": "sha512-WMi/OQ2axVTf/ykqCQgXiIct+mSQDFdH2fkwhPwgEwvJ1kSzZRiinb0zF2Xb8u4+OqPChmyI6MEu4EezNJz+FQ==", "dev": true, "license": "MIT", "dependencies": { - "tldts-core": "^6.1.85" + "tldts-core": "^6.1.86" }, "bin": { "tldts": "bin/cli.js" } }, "node_modules/tldts-core": { - "version": "6.1.85", - "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.85.tgz", - "integrity": "sha512-DTjUVvxckL1fIoPSb3KE7ISNtkWSawZdpfxGxwiIrZoO6EbHVDXXUIlIuWympPaeS+BLGyggozX/HTMsRAdsoA==", + "version": "6.1.86", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-6.1.86.tgz", + "integrity": "sha512-Je6p7pkk+KMzMv2XXKmAE3McmolOQFdxkKw0R8EYNr7sELW46JqnNeTX8ybPiQgvg1ymCoF8LXs5fzFaZvJPTA==", "dev": true, "license": "MIT" }, @@ -13964,6 +13973,19 @@ "node": ">= 8" } }, + "node_modules/why-is-node-running": { + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/why-is-node-running/-/why-is-node-running-3.2.2.tgz", + "integrity": "sha512-NKUzAelcoCXhXL4dJzKIwXeR8iEVqsA0Lq6Vnd0UXvgaKbzVo4ZTHROF2Jidrv+SgxOQ03fMinnNhzZATxOD3A==", + "dev": true, + "license": "MIT", + "bin": { + "why-is-node-running": "cli.js" + }, + "engines": { + "node": ">=20.11" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", @@ -14141,6 +14163,19 @@ } } }, + "node_modules/wtfnode": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/wtfnode/-/wtfnode-0.10.0.tgz", + "integrity": "sha512-/GxfQORu0SZZC8AQA4Eq1wH08Akz6W42OiqNGBzTHXCJWZFhKFBJNaUfEomWnLA2MXfpy6KbFerG8iNtFcPRdg==", + "dev": true, + "license": "ISC", + "bin": { + "wtfnode": "proxy.js" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/xml-name-validator": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/xml-name-validator/-/xml-name-validator-5.0.0.tgz", diff --git a/package.json b/package.json index 2b08025ea..27d546116 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "9.4.0", + "version": "9.5.0", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { @@ -84,11 +84,12 @@ "@types/sinon": "^17.0.3", "@types/text-encoding": "^0.0.39", "@types/underscore": "^1.11.15", + "@types/wtfnode": "^0.7.3", "@typescript-eslint/eslint-plugin": "^8.12.2", "@typescript-eslint/parser": "^8.12.2", "chai": "^4.4.1", "chai-as-promised": "^7.1.1", - "chai-nock": "^1.2.0", + "chai-nock": "^1.3.0", "commander": "^12.1.0", "cucumber-tsflow": "^4.4.4", "es6-shim": "^0.35.8", @@ -104,7 +105,7 @@ "karma-sourcemap-loader": "^0.3.7", "karma-spec-reporter": "0.0.32", "mocha": "10.4.0", - "nock": "^14.0.0-beta.15", + "nock": "^14.0.3", "prettier": "^3.2.5", "rimraf": "^3.0.2", "rollup": "4.22.4", @@ -117,7 +118,9 @@ "ts-node": "^10.9.2", "tsx": "^4.7.1", "typescript": "^5.4.5", - "underscore": "^1.9.2" + "underscore": "^1.9.2", + "why-is-node-running": "^3.2.2", + "wtfnode": "^0.10.0" }, "license": "SEE LICENSE IN LICENSE", "engine": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index ff7bddf8c..f1c11fcf8 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -5,8 +5,9 @@ */ import { ExtendedConfiguration, PlatformConfiguration, PrivateClientConfiguration } from '../interfaces/configuration'; -import { ICryptoModule, CryptorConfiguration } from '../interfaces/crypto-module'; +import { CryptorConfiguration, ICryptoModule } from '../interfaces/crypto-module'; import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; +import { Endpoint, RetryPolicy } from './retryPolicy'; import { Payload } from '../types/api'; import uuidGenerator from './uuid'; @@ -82,6 +83,26 @@ export const makeConfiguration = ( base: ExtendedConfiguration & PlatformConfiguration, setupCryptoModule?: SetupCryptoModule, ): PrivateClientConfiguration & PrivateConfigurationFields => { + // Set default retry policy for subscribe (if new subscribe logic not used). + if (!base.retryConfiguration && base.enableEventEngine) { + const s = RetryPolicy.None; + base.retryConfiguration = RetryPolicy.ExponentialRetryPolicy({ + minimumDelay: 2, + maximumDelay: 150, + maximumRetry: 6, + excluded: [ + Endpoint.MessageSend, + Endpoint.Presence, + Endpoint.Files, + Endpoint.MessageStorage, + Endpoint.ChannelGroups, + Endpoint.DevicePushNotifications, + Endpoint.AppContext, + Endpoint.MessageReactions, + ], + }); + } + // Ensure that retry policy has proper configuration (if has been set). base.retryConfiguration?.validate(); @@ -182,7 +203,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '9.4.0'; + return '9.5.0'; }, getVersion(): string { return this.version; diff --git a/src/core/components/retryPolicy.ts b/src/core/components/retryPolicy.ts new file mode 100644 index 000000000..e12f2e23b --- /dev/null +++ b/src/core/components/retryPolicy.ts @@ -0,0 +1,359 @@ +/** + * Failed requests retry module. + */ +import { TransportResponse } from '../types/transport-response'; +import { TransportRequest } from '../types/transport-request'; +import StatusCategory from '../constants/categories'; + +// -------------------------------------------------------- +// ------------------------ Types ------------------------- +// -------------------------------------------------------- +// region Types + +/** + * List of known endpoint groups (by context). + */ +export enum Endpoint { + /** + * Unknown endpoint. + * + * @internal + */ + Unknown = 'UnknownEndpoint', + + /** + * The endpoints to send messages. + * + * This is related to the following functionality: + * - `publish` + * - `signal` + * - `publish file` + * - `fire` + */ + MessageSend = 'MessageSendEndpoint', + + /** + * The endpoint for real-time update retrieval. + * + * This is related to the following functionality: + * - `subscribe` + */ + Subscribe = 'SubscribeEndpoint', + + /** + * The endpoint to access and manage `user_id` presence and fetch channel presence information. + * + * This is related to the following functionality: + * - `get presence state` + * - `set presence state` + * - `here now` + * - `where now` + * - `heartbeat` + */ + Presence = 'PresenceEndpoint', + + /** + * The endpoint to access and manage files in channel-specific storage. + * + * This is related to the following functionality: + * - `send file` + * - `download file` + * - `list files` + * - `delete file` + */ + Files = 'FilesEndpoint', + + /** + * The endpoint to access and manage messages for a specific channel(s) in the persistent storage. + * + * This is related to the following functionality: + * - `fetch messages / message actions` + * - `delete messages` + * - `messages count` + */ + MessageStorage = 'MessageStorageEndpoint', + + /** + * The endpoint to access and manage channel groups. + * + * This is related to the following functionality: + * - `add channels to group` + * - `list channels in group` + * - `remove channels from group` + * - `list channel groups` + */ + ChannelGroups = 'ChannelGroupsEndpoint', + + /** + * The endpoint to access and manage device registration for channel push notifications. + * + * This is related to the following functionality: + * - `enable channels for push notifications` + * - `list push notification enabled channels` + * - `disable push notifications for channels` + * - `disable push notifications for all channels` + */ + DevicePushNotifications = 'DevicePushNotificationsEndpoint', + + /** + * The endpoint to access and manage App Context objects. + * + * This is related to the following functionality: + * - `set UUID metadata` + * - `get UUID metadata` + * - `remove UUID metadata` + * - `get all UUID metadata` + * - `set Channel metadata` + * - `get Channel metadata` + * - `remove Channel metadata` + * - `get all Channel metadata` + * - `manage members` + * - `list members` + * - `manage memberships` + * - `list memberships` + */ + AppContext = 'AppContextEndpoint', + + /** + * The endpoint to access and manage reactions for a specific message. + * + * This is related to the following functionality: + * - `add message action` + * - `get message actions` + * - `remove message action` + */ + MessageReactions = 'MessageReactionsEndpoint', +} + +/** + * Request retry configuration interface. + */ +export type RequestRetryPolicy = { + /** + * Check whether failed request can be retried. + * + * @param request - Transport request for which retry ability should be identifier. + * @param [response] - Service response (if available) + * @param [errorCategory] - Request processing error category. + * @param [attempt] - Number of sequential failure. + * + * @returns `true` if another request retry attempt can be done. + */ + shouldRetry( + request: TransportRequest, + response?: TransportResponse, + errorCategory?: StatusCategory, + attempt?: number, + ): boolean; + + /** + * Computed delay for next request retry attempt. + * + * @param attempt - Number of sequential failure. + * @param [response] - Service response (if available). + * + * @returns Delay before next request retry attempt in milliseconds. + */ + getDelay(attempt: number, response?: TransportResponse): number; + + /** + * Validate retry policy parameters. + * + * @throws Error if `minimum` delay is smaller than 2 seconds for `exponential` retry policy. + * @throws Error if `maximum` delay is larger than 150 seconds for `exponential` retry policy. + * @throws Error if `maximumRetry` attempts is larger than 6 for `exponential` retry policy. + * @throws Error if `maximumRetry` attempts is larger than 10 for `linear` retry policy. + */ + validate(): void; +}; + +/** + * Policy, which uses linear formula to calculate next request retry attempt time. + */ +export type LinearRetryPolicyConfiguration = { + /** + * Delay between retry attempt (in seconds). + */ + delay: number; + + /** + * Maximum number of retry attempts. + */ + maximumRetry: number; + + /** + * Endpoints that won't be retried. + */ + excluded?: Endpoint[]; +}; + +/** + * Policy, which uses exponential formula to calculate next request retry attempt time. + */ +export type ExponentialRetryPolicyConfiguration = { + /** + * Minimum delay between retry attempts (in seconds). + */ + minimumDelay: number; + + /** + * Maximum delay between retry attempts (in seconds). + */ + maximumDelay: number; + + /** + * Maximum number of retry attempts. + */ + maximumRetry: number; + + /** + * Endpoints that won't be retried. + */ + excluded?: Endpoint[]; +}; +// endregion + +/** + * Failed request retry policy. + */ +export class RetryPolicy { + static None: RequestRetryPolicy = { + shouldRetry(_request, _response, _errorCategory, _attempt): boolean { + return false; + }, + getDelay(_attempt, _response): number { + return -1; + }, + validate() { + return true; + }, + }; + + static LinearRetryPolicy( + configuration: LinearRetryPolicyConfiguration, + ): RequestRetryPolicy & LinearRetryPolicyConfiguration { + return { + delay: configuration.delay, + maximumRetry: configuration.maximumRetry, + excluded: configuration.excluded ?? [], + + shouldRetry(request, response, error, attempt) { + return isRetriableRequest(request, response, error, attempt ?? 0, this.maximumRetry, this.excluded); + }, + + getDelay(_, response) { + let delay = -1; + if (response && response.headers['retry-after'] !== undefined) + delay = parseInt(response.headers['retry-after'], 10); + if (delay === -1) delay = this.delay; + + return (delay + Math.random()) * 1000; + }, + + validate() { + if (this.delay < 2) throw new Error('Delay can not be set less than 2 seconds for retry'); + if (this.maximumRetry > 10) throw new Error('Maximum retry for linear retry policy can not be more than 10'); + }, + }; + } + + static ExponentialRetryPolicy( + configuration: ExponentialRetryPolicyConfiguration, + ): RequestRetryPolicy & ExponentialRetryPolicyConfiguration { + return { + minimumDelay: configuration.minimumDelay, + maximumDelay: configuration.maximumDelay, + maximumRetry: configuration.maximumRetry, + excluded: configuration.excluded ?? [], + + shouldRetry(request, response, error, attempt) { + return isRetriableRequest(request, response, error, attempt ?? 0, this.maximumRetry, this.excluded); + }, + + getDelay(attempt, response) { + let delay = -1; + if (response && response.headers['retry-after'] !== undefined) + delay = parseInt(response.headers['retry-after'], 10); + if (delay === -1) delay = Math.min(Math.pow(2, attempt), this.maximumDelay); + + return (delay + Math.random()) * 1000; + }, + + validate() { + if (this.minimumDelay < 2) throw new Error('Minimum delay can not be set less than 2 seconds for retry'); + else if (this.maximumDelay > 150) + throw new Error('Maximum delay can not be set more than 150 seconds for' + ' retry'); + else if (this.maximumRetry > 6) + throw new Error('Maximum retry for exponential retry policy can not be more than 6'); + }, + }; + } +} + +/** + * Check whether request can be retried or not. + * + * @param req - Request for which retry ability is checked. + * @param res - Service response which should be taken into consideration. + * @param errorCategory - Request processing error category. + * @param retryAttempt - Current retry attempt. + * @param maximumRetry - Maximum retry attempts count according to the retry policy. + * @param excluded - List of endpoints for which retry policy won't be applied. + * + * @return `true` if request can be retried. + * + * @internal + */ +const isRetriableRequest = ( + req: TransportRequest, + res: TransportResponse | undefined, + errorCategory: StatusCategory | undefined, + retryAttempt: number, + maximumRetry: number, + excluded?: Endpoint[], +) => { + if (errorCategory && errorCategory === StatusCategory.PNCancelledCategory) return false; + else if (isExcludedRequest(req, excluded)) return false; + else if (retryAttempt > maximumRetry) return false; + + return res ? res.status === 429 || res.status >= 500 : true; +}; + +/** + * Check whether the provided request is in the list of endpoints for which retry is not allowed or not. + * + * @param req - Request which will be tested. + * @param excluded - List of excluded endpoints configured for retry policy. + * + * @returns `true` if request has been excluded and shouldn't be retried. + * + * @internal + */ +const isExcludedRequest = (req: TransportRequest, excluded?: Endpoint[]) => + excluded && excluded.length > 0 ? excluded.includes(endpointFromRequest(req)) : false; + +/** + * Identify API group from transport request. + * + * @param req - Request for which `path` will be analyzed to identify REST API group. + * + * @returns Endpoint group to which request belongs. + * + * @internal + */ +const endpointFromRequest = (req: TransportRequest) => { + let endpoint = Endpoint.Unknown; + + if (req.path.startsWith('/v2/subscribe')) endpoint = Endpoint.Subscribe; + else if (req.path.startsWith('/publish/') || req.path.startsWith('/signal/')) endpoint = Endpoint.MessageSend; + else if (req.path.startsWith('/v2/presence')) endpoint = Endpoint.Presence; + else if (req.path.startsWith('/v2/history') || req.path.startsWith('/v3/history')) endpoint = Endpoint.MessageStorage; + else if (req.path.startsWith('/v1/message-actions/')) endpoint = Endpoint.MessageReactions; + else if (req.path.startsWith('/v1/channel-registration/')) endpoint = Endpoint.ChannelGroups; + else if (req.path.startsWith('/v2/objects/')) endpoint = Endpoint.ChannelGroups; + else if (req.path.startsWith('/v1/push/') || req.path.startsWith('/v2/push/')) + endpoint = Endpoint.DevicePushNotifications; + else if (req.path.startsWith('/v1/files/')) endpoint = Endpoint.Files; + + return endpoint; +}; diff --git a/src/core/constants/categories.ts b/src/core/constants/categories.ts index 54ead3e4e..180649f7d 100644 --- a/src/core/constants/categories.ts +++ b/src/core/constants/categories.ts @@ -81,6 +81,11 @@ enum StatusCategory { */ PNConnectedCategory = 'PNConnectedCategory', + /** + * Set of active channels and groups has been changed. + */ + PNSubscriptionChangedCategory = 'PNSubscriptionChangedCategory', + /** * Received real-time updates exceed specified threshold. * diff --git a/src/core/endpoints/presence/heartbeat.ts b/src/core/endpoints/presence/heartbeat.ts index ab4513fff..500e690c6 100644 --- a/src/core/endpoints/presence/heartbeat.ts +++ b/src/core/endpoints/presence/heartbeat.ts @@ -54,7 +54,7 @@ type ServiceResponse = { */ export class HeartbeatRequest extends AbstractRequest { constructor(private readonly parameters: RequestParameters) { - super(); + super({ cancellable: true }); } operation(): RequestOperation { diff --git a/src/core/interfaces/configuration.ts b/src/core/interfaces/configuration.ts index 746e5ebc3..915d53d08 100644 --- a/src/core/interfaces/configuration.ts +++ b/src/core/interfaces/configuration.ts @@ -3,10 +3,10 @@ */ import { PubNubFileConstructor, PubNubFileInterface } from '../types/file'; -import { RequestRetryPolicy } from '../../event-engine/core/retryPolicy'; +import { RequestRetryPolicy } from '../components/retryPolicy'; +import { PubNubError } from '../../errors/pubnub-error'; import { ICryptoModule } from './crypto-module'; import { KeySet, Payload } from '../types/api'; -import { PubNubError } from '../../errors/pubnub-error'; // -------------------------------------------------------- // ----------------------- Defaults ----------------------- diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index 834242fdd..07bc5fd67 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -32,10 +32,10 @@ import StatusCategory from './constants/categories'; import { createValidationError, PubNubError } from '../errors/pubnub-error'; import { PubNubAPIError } from '../errors/pubnub-api-error'; +import { RetryPolicy } from './components/retryPolicy'; // region Event Engine import { PresenceEventEngine } from '../event-engine/presence/presence'; -import { RetryPolicy } from '../event-engine/core/retryPolicy'; import { EventEngine } from '../event-engine'; // endregion // region Publish & Signal @@ -374,7 +374,6 @@ export class PubNubCore< if (!heartbeatInterval) reject(new PubNubError('Heartbeat interval has been reset.')); else setTimeout(resolve, heartbeatInterval * 1000); }), - retryDelay: (amount) => new Promise((resolve) => setTimeout(resolve, amount)), emitStatus: (status) => this.listenerManager.announceStatus(status), config: this._configuration, presenceState: this.presenceState, @@ -389,6 +388,8 @@ export class PubNubCore< join: this.join.bind(this), leave: this.leave.bind(this), leaveAll: this.leaveAll.bind(this), + presenceReconnect: this.presenceReconnect.bind(this), + presenceDisconnect: this.presenceDisconnect.bind(this), presenceState: this.presenceState, config: this._configuration, emitMessages: (events) => { @@ -888,6 +889,10 @@ export class PubNubCore< this.subscriptionManager.unsubscribeAll(isOffline); this.subscriptionManager.disconnect(); } else if (this.eventEngine) this.eventEngine.dispose(); + + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) this.presenceEventEngine.dispose(); + } } } @@ -1278,11 +1283,15 @@ export class PubNubCore< /** * Temporarily disconnect from real-time events stream. + * + * **Note:** `isOffline` is set to `true` only when client experience network issues. + * + * @param [isOffline] - Whether `offline` presence should be notified or not. */ - public disconnect(): void { + public disconnect(isOffline?: boolean): void { if (process.env.SUBSCRIBE_MODULE !== 'disabled') { if (this.subscriptionManager) this.subscriptionManager.disconnect(); - else if (this.eventEngine) this.eventEngine.disconnect(); + else if (this.eventEngine) this.eventEngine.disconnect(isOffline); } else throw new Error('Disconnection error: subscription module disabled'); } @@ -1992,6 +2001,30 @@ export class PubNubCore< } } else throw new Error('Announce UUID Presence error: presence module disabled'); } + + /** + * Reconnect presence event engine after network issues. + * + * @param parameters - List of channels and groups where `join` event should be sent. + * + * @internal + */ + private presenceReconnect(parameters: { channels?: string[]; groups?: string[] }) { + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) this.presenceEventEngine.reconnect(); + else { + this.heartbeat( + { + channels: parameters.channels, + channelGroups: parameters.groups, + ...(this._configuration.maintainPresenceState && { state: this.presenceState }), + heartbeat: this._configuration.getPresenceTimeout(), + }, + () => {}, + ); + } + } else throw new Error('Announce UUID Presence error: presence module disabled'); + } // endregion // region Leave @@ -2022,6 +2055,21 @@ export class PubNubCore< else this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => {}); } else throw new Error('Announce UUID Leave error: presence module disabled'); } + + /** + * Announce user `leave` on disconnection. + * + * @internal + * + * @param parameters - List of channels and groups where `leave` event should be sent. + */ + private presenceDisconnect(parameters: { channels?: string[]; groups?: string[]; isOffline?: boolean }) { + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) this.presenceEventEngine.disconnect(parameters.isOffline); + else if (!parameters.isOffline) + this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => {}); + } else throw new Error('Announce UUID Leave error: presence module disabled'); + } // endregion // endregion diff --git a/src/core/types/api/index.ts b/src/core/types/api/index.ts index 172660476..ebcf3ddfc 100644 --- a/src/core/types/api/index.ts +++ b/src/core/types/api/index.ts @@ -104,7 +104,7 @@ export type StatusEvent = { /** * Information about error. */ - error?: string | boolean; + error?: string | StatusCategory | boolean; /** * List of channels for which status update announced. diff --git a/src/event-engine/core/retryPolicy.ts b/src/event-engine/core/retryPolicy.ts deleted file mode 100644 index 289f15abb..000000000 --- a/src/event-engine/core/retryPolicy.ts +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Failed requests retry module. - */ -import { PubNubError } from '../../errors/pubnub-error'; - -/** - * Failed request retry policy. - */ -export class RetryPolicy { - static LinearRetryPolicy( - configuration: LinearRetryPolicyConfiguration, - ): RequestRetryPolicy & LinearRetryPolicyConfiguration { - return { - delay: configuration.delay, - maximumRetry: configuration.maximumRetry, - /* eslint-disable @typescript-eslint/no-explicit-any */ - shouldRetry(error: any, attempt: number) { - if (error?.status?.statusCode === 403) { - return false; - } - return this.maximumRetry > attempt; - }, - getDelay(_, reason) { - const delay = reason.retryAfter ?? this.delay; - return (delay + Math.random()) * 1000; - }, - /* eslint-disable @typescript-eslint/no-explicit-any */ - getGiveupReason(error: any, attempt: number) { - if (this.maximumRetry <= attempt) { - return 'retry attempts exhaused.'; - } - if (error?.status?.statusCode === 403) { - return 'forbidden operation.'; - } - return 'unknown error'; - }, - validate() { - if (this.maximumRetry > 10) throw new Error('Maximum retry for linear retry policy can not be more than 10'); - }, - }; - } - - static ExponentialRetryPolicy( - configuration: ExponentialRetryPolicyConfiguration, - ): RequestRetryPolicy & ExponentialRetryPolicyConfiguration { - return { - minimumDelay: configuration.minimumDelay, - maximumDelay: configuration.maximumDelay, - maximumRetry: configuration.maximumRetry, - - shouldRetry(reason, attempt) { - if (reason?.status?.statusCode === 403) { - return false; - } - return this.maximumRetry > attempt; - }, - - getDelay(attempt, reason) { - const delay = reason.retryAfter ?? Math.min(Math.pow(2, attempt), this.maximumDelay); - return (delay + Math.random()) * 1000; - }, - - getGiveupReason(reason, attempt) { - if (this.maximumRetry <= attempt) { - return 'retry attempts exhausted.'; - } - if (reason?.status?.statusCode === 403) { - return 'forbidden operation.'; - } - return 'unknown error'; - }, - - validate() { - if (this.minimumDelay < 2) throw new Error('Minimum delay can not be set less than 2 seconds for retry'); - else if (this.maximumDelay) throw new Error('Maximum delay can not be set more than 150 seconds for retry'); - else if (this.maximumRetry > 6) - throw new Error('Maximum retry for exponential retry policy can not be more than 6'); - }, - }; - } -} - -export type RequestRetryPolicy = { - /** - * Check whether failed request can be retried. - * - * @param reason - Request processing failure reason. - * @param attempt - Number of sequential failure. - * - * @returns `true` if another request retry attempt can be done. - */ - shouldRetry(reason: PubNubError & { retryAfter?: number }, attempt: number): boolean; - - /** - * Computed delay for next request retry attempt. - * - * @param attempt - Number of sequential failure. - * @param reason - Request processing failure reason. - * - * @returns Delay before next request retry attempt in milliseconds. - */ - getDelay(attempt: number, reason: PubNubError & { retryAfter?: number }): number; - - /** - * Identify reason why another retry attempt can't be made. - * - * @param reason - Request processing failure reason. - * @param attempt - Number of sequential failure. - * - * @returns Give up reason. - */ - getGiveupReason(reason: PubNubError & { retryAfter?: number }, attempt: number): string; - - /** - * Validate retry policy parameters. - * - * @throws Error if `minimum` delay is smaller than 2 seconds for `exponential` retry policy. - * @throws Error if `maximum` delay is larger than 150 seconds for `exponential` retry policy. - * @throws Error if `maximumRetry` attempts is larger than 6 for `exponential` retry policy. - * @throws Error if `maximumRetry` attempts is larger than 10 for `linear` retry policy. - */ - validate(): void; -}; - -/** - * Policy, which uses linear formula to calculate next request retry attempt time. - */ -export type LinearRetryPolicyConfiguration = { - /** - * Delay between retry attempt (in seconds). - */ - delay: number; - - /** - * Maximum number of retry attempts. - */ - maximumRetry: number; -}; - -/** - * Policy, which uses exponential formula to calculate next request retry attempt time. - */ -export type ExponentialRetryPolicyConfiguration = { - /** - * Minimum delay between retry attempts (in seconds). - */ - minimumDelay: number; - - /** - * Maximum delay between retry attempts (in seconds). - */ - maximumDelay: number; - - /** - * Maximum number of retry attempts. - */ - maximumRetry: number; -}; diff --git a/src/event-engine/dispatcher.ts b/src/event-engine/dispatcher.ts index 7abf9b130..e09d2671f 100644 --- a/src/event-engine/dispatcher.ts +++ b/src/event-engine/dispatcher.ts @@ -26,6 +26,8 @@ export type Dependencies = { join?: (parameters: { channels?: string[]; groups?: string[] }) => void; leave?: (parameters: { channels?: string[]; groups?: string[] }) => void; leaveAll?: (parameters: { channels?: string[]; groups?: string[] }) => void; + presenceReconnect?: (parameters: { channels?: string[]; groups?: string[] }) => void; + presenceDisconnect?: (parameters: { channels?: string[]; groups?: string[]; isOffline?: boolean }) => void; presenceState: Record; config: PrivateClientConfiguration; @@ -96,98 +98,13 @@ export class EventEngineDispatcher extends Dispatcher { - if (payload.length > 0) { - emitMessages(payload); - } + if (payload.length > 0) emitMessages(payload); }), ); this.on( effects.emitStatus.type, - asyncHandler(async (payload, _, { emitStatus }) => { - emitStatus(payload); - }), - ); - - this.on( - effects.receiveReconnect.type, - asyncHandler(async (payload, abortSignal, { receiveMessages, delay, config }) => { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - - await delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); - - abortSignal.throwIfAborted(); - - try { - const result = await receiveMessages({ - abortSignal: abortSignal, - channels: payload.channels, - channelGroups: payload.groups, - timetoken: payload.cursor.timetoken, - region: payload.cursor.region, - filterExpression: config.filterExpression, - }); - - return engine.transition(events.receiveReconnectSuccess(result.cursor, result.messages)); - } catch (error) { - if (error instanceof PubNubError) { - if (error.status && error.status.category == StatusCategory.PNCancelledCategory) return; - return engine.transition(events.receiveReconnectFailure(error)); - } - } - } else { - return engine.transition( - events.receiveReconnectGiveup( - new PubNubError( - config.retryConfiguration - ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) - : 'Unable to complete subscribe messages receive.', - ), - ), - ); - } - }), - ); - - this.on( - effects.handshakeReconnect.type, - asyncHandler(async (payload, abortSignal, { handshake, delay, presenceState, config }) => { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - - await delay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); - - abortSignal.throwIfAborted(); - - try { - const result = await handshake({ - abortSignal: abortSignal, - channels: payload.channels, - channelGroups: payload.groups, - filterExpression: config.filterExpression, - ...(config.maintainPresenceState && { state: presenceState }), - }); - - return engine.transition(events.handshakeReconnectSuccess(result)); - } catch (error) { - if (error instanceof PubNubError) { - if (error.status && error.status.category == StatusCategory.PNCancelledCategory) return; - return engine.transition(events.handshakeReconnectFailure(error)); - } - } - } else { - return engine.transition( - events.handshakeReconnectGiveup( - new PubNubError( - config.retryConfiguration - ? config.retryConfiguration.getGiveupReason(payload.reason, payload.attempts) - : 'Unable to complete subscribe handshake', - ), - ), - ); - } - }), + asyncHandler(async (payload, _, { emitStatus }) => emitStatus(payload)), ); } } diff --git a/src/event-engine/effects.ts b/src/event-engine/effects.ts index 8aab8a20a..2251ed294 100644 --- a/src/event-engine/effects.ts +++ b/src/event-engine/effects.ts @@ -5,8 +5,6 @@ */ import { createEffect, createManagedEffect, MapOf } from './core'; -import { HandshakeReconnectingStateContext } from './states/handshake_reconnecting'; -import { ReceiveReconnectingStateContext } from './states/receive_reconnecting'; import * as Subscription from '../core/types/api/subscription'; import { StatusEvent } from '../core/types/api'; @@ -56,40 +54,9 @@ export const emitMessages = createEffect( */ export const emitStatus = createEffect('EMIT_STATUS', (status: StatusEvent) => status); -/** - * Real-time updates receive restore effect. - * - * Performs subscribe REST API call with `tt` which has been received before disconnection or error. - * - * @internal - */ -export const receiveReconnect = createManagedEffect( - 'RECEIVE_RECONNECT', - (context: ReceiveReconnectingStateContext) => context, -); - -/** - * Initial subscription restore effect. - * - * Performs subscribe REST API call with `tt=0` after error. - * - * @internal - */ -export const handshakeReconnect = createManagedEffect( - 'HANDSHAKE_RECONNECT', - (context: HandshakeReconnectingStateContext) => context, -); - /** * Subscribe Event Engine effects. * * @internal */ -export type Effects = MapOf< - | typeof receiveMessages - | typeof handshake - | typeof emitMessages - | typeof receiveReconnect - | typeof handshakeReconnect - | typeof emitStatus ->; +export type Effects = MapOf; diff --git a/src/event-engine/events.ts b/src/event-engine/events.ts index afd2b7e56..2787697d3 100644 --- a/src/event-engine/events.ts +++ b/src/event-engine/events.ts @@ -57,36 +57,6 @@ export const handshakeSuccess = createEvent('HANDSHAKE_SUCCESS', (cursor: Subscr */ export const handshakeFailure = createEvent('HANDSHAKE_FAILURE', (error: PubNubError) => error); -/** - * Initial subscription handshake reconnect success event. - * - * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. - * - * @internal - */ -export const handshakeReconnectSuccess = createEvent( - 'HANDSHAKE_RECONNECT_SUCCESS', - (cursor: Subscription.SubscriptionCursor) => ({ - cursor, - }), -); -/** - * Initial subscription handshake reconnect did fail event. - * - * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. - * - * @internal - */ -export const handshakeReconnectFailure = createEvent('HANDSHAKE_RECONNECT_FAILURE', (error: PubNubError) => error); -/** - * Initial subscription handshake impossible event. - * - * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. - * - * @internal - */ -export const handshakeReconnectGiveup = createEvent('HANDSHAKE_RECONNECT_GIVEUP', (error: PubNubError) => error); - /** * Subscription successfully received real-time updates event. * @@ -110,36 +80,6 @@ export const receiveSuccess = createEvent( */ export const receiveFailure = createEvent('RECEIVE_FAILURE', (error: PubNubError) => error); -/** - * Subscription successfully received real-time updates on reconnection attempt event. - * - * Event is sent by corresponding effect handler if REST API call was successful after transition to the failed state. - * - * @internal - */ -export const receiveReconnectSuccess = createEvent( - 'RECEIVE_RECONNECT_SUCCESS', - (cursor: Subscription.SubscriptionCursor, events: Subscription.SubscriptionResponse['messages']) => ({ - cursor, - events, - }), -); -/** - * Subscription did fail to receive real-time updates on reconnection attempt event. - * - * Event is sent by corresponding effect handler if REST API call did fail while tried to enter to the success state. - * - * @internal - */ -export const receiveReconnectFailure = createEvent('RECEIVE_RECONNECT_FAILURE', (error: PubNubError) => error); -/** - * Subscription real-time updates received impossible event. - * - * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. - * - * @internal - */ -export const receiveReconnectGiveup = createEvent('RECEIVING_RECONNECT_GIVEUP', (error: PubNubError) => error); /** * Client disconnect event. * @@ -147,7 +87,7 @@ export const receiveReconnectGiveup = createEvent('RECEIVING_RECONNECT_GIVEUP', * * @internal */ -export const disconnect = createEvent('DISCONNECT', () => ({})); +export const disconnect = createEvent('DISCONNECT', (isOffline?: boolean) => ({ isOffline })); /** * Client reconnect event. @@ -182,14 +122,8 @@ export type Events = MapOf< | typeof restore | typeof handshakeSuccess | typeof handshakeFailure - | typeof handshakeReconnectSuccess - | typeof handshakeReconnectFailure - | typeof handshakeReconnectGiveup | typeof receiveSuccess | typeof receiveFailure - | typeof receiveReconnectSuccess - | typeof receiveReconnectFailure - | typeof receiveReconnectGiveup | typeof disconnect | typeof reconnect | typeof unsubscribeAll diff --git a/src/event-engine/index.ts b/src/event-engine/index.ts index 3305063a2..b65155e04 100644 --- a/src/event-engine/index.ts +++ b/src/event-engine/index.ts @@ -102,10 +102,10 @@ export class EventEngine { new Set(this.groups).size !== new Set(filteredGroups).size ) { const channelsToLeave = utils.findUniqueCommonElements(this.channels, channels); - const groupstoLeave = utils.findUniqueCommonElements(this.groups, channelGroups); + const groupsToLeave = utils.findUniqueCommonElements(this.groups, channelGroups); if (this.dependencies.presenceState) { channelsToLeave?.forEach((c) => delete this.dependencies.presenceState[c]); - groupstoLeave?.forEach((g) => delete this.dependencies.presenceState[g]); + groupsToLeave?.forEach((g) => delete this.dependencies.presenceState[g]); } this.channels = filteredChannels; this.groups = filteredGroups; @@ -118,7 +118,7 @@ export class EventEngine { if (this.dependencies.leave) { this.dependencies.leave({ channels: channelsToLeave.slice(0), - groups: groupstoLeave.slice(0), + groups: groupsToLeave.slice(0), }); } } @@ -141,16 +141,22 @@ export class EventEngine { } reconnect({ timetoken, region }: { timetoken?: string; region?: number }): void { + const channelGroups = this.getSubscribedChannels(); + const channels = this.getSubscribedChannels(); + this.engine.transition(events.reconnect(timetoken, region)); + + if (this.dependencies.presenceReconnect) this.dependencies.presenceReconnect({ channels, groups: channelGroups }); } - disconnect(): void { + disconnect(isOffline?: boolean): void { const channelGroups = this.getSubscribedChannels(); const channels = this.getSubscribedChannels(); - this.engine.transition(events.disconnect()); + this.engine.transition(events.disconnect(isOffline)); - if (this.dependencies.leaveAll) this.dependencies.leaveAll({ channels, groups: channelGroups }); + if (this.dependencies.presenceDisconnect) + this.dependencies.presenceDisconnect({ channels, groups: channelGroups, isOffline }); } getSubscribedChannels(): string[] { @@ -162,7 +168,7 @@ export class EventEngine { } dispose(): void { - this.disconnect(); + this.disconnect(true); this._unsubscribeEngine(); this.dispatcher.dispose(); } diff --git a/src/event-engine/presence/dispatcher.ts b/src/event-engine/presence/dispatcher.ts index e6d12ba63..ab58c8f5c 100644 --- a/src/event-engine/presence/dispatcher.ts +++ b/src/event-engine/presence/dispatcher.ts @@ -5,14 +5,14 @@ */ import { PrivateClientConfiguration } from '../../core/interfaces/configuration'; +import { Payload, ResultCallback } from '../../core/types/api'; +import StatusCategory from '../../core/constants/categories'; import { asyncHandler, Dispatcher, Engine } from '../core'; import PNOperations from '../../core/constants/operations'; import * as Presence from '../../core/types/api/presence'; import { PubNubError } from '../../errors/pubnub-error'; -import { Payload, ResultCallback } from '../../core/types/api'; import * as effects from './effects'; import * as events from './events'; -import StatusCategory from '../../core/constants/categories'; /** * Presence Event Engine dependencies set (configuration). @@ -27,7 +27,6 @@ export type Dependencies = { leave: (parameters: Presence.PresenceLeaveParameters) => void; heartbeatDelay: () => Promise; - retryDelay: (milliseconds: number) => Promise; config: PrivateClientConfiguration; presenceState: Record; @@ -60,7 +59,7 @@ export class PresenceEventEngineDispatcher extends Dispatcher { - if (config.retryConfiguration && config.retryConfiguration.shouldRetry(payload.reason, payload.attempts)) { - abortSignal.throwIfAborted(); - - await retryDelay(config.retryConfiguration.getDelay(payload.attempts, payload.reason)); - - abortSignal.throwIfAborted(); - try { - const result = await heartbeat({ - channels: payload.channels, - channelGroups: payload.groups, - ...(config.maintainPresenceState && { state: presenceState }), - heartbeat: config.presenceTimeout!, - }); - return engine.transition(events.heartbeatSuccess(200)); - } catch (e) { - if (e instanceof PubNubError) { - if (e.status && e.status.category == StatusCategory.PNCancelledCategory) return; - return engine.transition(events.heartbeatFailure(e)); - } - } - } else { - return engine.transition(events.heartbeatGiveup()); - } - }), - ); - this.on( effects.emitStatus.type, asyncHandler(async (payload, _, { emitStatus, config }) => { - if (config.announceFailedHeartbeats && payload?.status?.error === true) { - emitStatus(payload.status); + if (config.announceFailedHeartbeats && payload?.error === true) { + emitStatus({ ...payload, operation: PNOperations.PNHeartbeatOperation }); } else if (config.announceSuccessfulHeartbeats && payload.statusCode === 200) { - emitStatus({ ...payload, operation: PNOperations.PNHeartbeatOperation, error: false }); + emitStatus({ + ...payload, + error: false, + operation: PNOperations.PNHeartbeatOperation, + category: StatusCategory.PNAcknowledgmentCategory, + }); } }), ); diff --git a/src/event-engine/presence/effects.ts b/src/event-engine/presence/effects.ts index 1bcfa5c87..f0e45832d 100644 --- a/src/event-engine/presence/effects.ts +++ b/src/event-engine/presence/effects.ts @@ -5,7 +5,6 @@ */ import { createEffect, createManagedEffect, MapOf } from '../core'; -import { HeartbeatReconnectingStateContext } from './states/heartbeat_reconnecting'; import { Status } from '../../core/types/api'; /** @@ -15,7 +14,7 @@ import { Status } from '../../core/types/api'; * * @internal */ -export const heartbeat = createEffect('HEARTBEAT', (channels: string[], groups: string[]) => ({ +export const heartbeat = createManagedEffect('HEARTBEAT', (channels: string[], groups: string[]) => ({ channels, groups, })); @@ -51,23 +50,9 @@ export const emitStatus = createEffect('EMIT_STATUS', (status: any) => status); */ export const wait = createManagedEffect('WAIT', () => ({})); -/** - * Delayed heartbeat effect. - * - * Similar to the {@link wait} effect but used in case if previous heartbeat call did fail. - * - * @internal - */ -export const delayedHeartbeat = createManagedEffect( - 'DELAYED_HEARTBEAT', - (context: HeartbeatReconnectingStateContext) => context, -); - /** * Presence Event Engine effects. * * @internal */ -export type Effects = MapOf< - typeof heartbeat | typeof leave | typeof emitStatus | typeof wait | typeof delayedHeartbeat ->; +export type Effects = MapOf; diff --git a/src/event-engine/presence/events.ts b/src/event-engine/presence/events.ts index 0b3b67a12..f3c7e3f64 100644 --- a/src/event-engine/presence/events.ts +++ b/src/event-engine/presence/events.ts @@ -24,7 +24,7 @@ export const reconnect = createEvent('RECONNECT', () => ({})); * * @internal */ -export const disconnect = createEvent('DISCONNECT', () => ({})); +export const disconnect = createEvent('DISCONNECT', (isOffline?: boolean) => ({ isOffline })); /** * Channel / group join event. @@ -80,15 +80,6 @@ export const heartbeatSuccess = createEvent('HEARTBEAT_SUCCESS', (statusCode: nu */ export const heartbeatFailure = createEvent('HEARTBEAT_FAILURE', (error: PubNubError) => error); -/** - * Presence heartbeat impossible event. - * - * Event is sent by corresponding effect handler if REST API call exhausted all retry attempt and won't try again. - * - * @internal - */ -export const heartbeatGiveup = createEvent('HEARTBEAT_GIVEUP', () => ({})); - /** * Delayed presence heartbeat event. * @@ -109,7 +100,6 @@ export type Events = MapOf< | typeof leftAll | typeof heartbeatSuccess | typeof heartbeatFailure - | typeof heartbeatGiveup | typeof joined | typeof left | typeof timesUp diff --git a/src/event-engine/presence/presence.ts b/src/event-engine/presence/presence.ts index 408a2f329..1e0d9731b 100644 --- a/src/event-engine/presence/presence.ts +++ b/src/event-engine/presence/presence.ts @@ -59,7 +59,16 @@ export class PresenceEventEngine { this.engine.transition(events.leftAll()); } + reconnect() { + this.engine.transition(events.reconnect()); + } + + disconnect(isOffline?: boolean) { + this.engine.transition(events.disconnect(isOffline)); + } + dispose() { + this.disconnect(true); this._unsubscribeEngine(); this.dispatcher.dispose(); } diff --git a/src/event-engine/presence/states/heartbeat_cooldown.ts b/src/event-engine/presence/states/heartbeat_cooldown.ts index 97faebd7e..5b7a78f76 100644 --- a/src/event-engine/presence/states/heartbeat_cooldown.ts +++ b/src/event-engine/presence/states/heartbeat_cooldown.ts @@ -57,14 +57,10 @@ HeartbeatCooldownState.on(left.type, (context, event) => ), ); -HeartbeatCooldownState.on(disconnect.type, (context) => - HeartbeatStoppedState.with( - { - channels: context.channels, - groups: context.groups, - }, - [leave(context.channels, context.groups)], - ), +HeartbeatCooldownState.on(disconnect.type, (context, event) => + HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ]), ); HeartbeatCooldownState.on(leftAll.type, (context, _) => diff --git a/src/event-engine/presence/states/heartbeat_failed.ts b/src/event-engine/presence/states/heartbeat_failed.ts index b82042d6d..d07c8c940 100644 --- a/src/event-engine/presence/states/heartbeat_failed.ts +++ b/src/event-engine/presence/states/heartbeat_failed.ts @@ -55,14 +55,10 @@ HeartbeatFailedState.on(reconnect.type, (context, _) => }), ); -HeartbeatFailedState.on(disconnect.type, (context, _) => - HeartbeatStoppedState.with( - { - channels: context.channels, - groups: context.groups, - }, - [leave(context.channels, context.groups)], - ), +HeartbeatFailedState.on(disconnect.type, (context, event) => + HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ]), ); HeartbeatFailedState.on(leftAll.type, (context, _) => diff --git a/src/event-engine/presence/states/heartbeat_reconnecting.ts b/src/event-engine/presence/states/heartbeat_reconnecting.ts deleted file mode 100644 index 26f3e84e5..000000000 --- a/src/event-engine/presence/states/heartbeat_reconnecting.ts +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Retry heartbeat state module. - * - * @internal - */ - -import { PubNubError } from '../../../errors/pubnub-error'; -import { State } from '../../core/state'; -import { - Events, - disconnect, - heartbeatFailure, - heartbeatGiveup, - heartbeatSuccess, - joined, - left, - leftAll, -} from '../events'; -import { Effects, delayedHeartbeat, emitStatus, leave } from '../effects'; -import { HeartbeatingState } from './heartbeating'; -import { HeartbeatStoppedState } from './heartbeat_stopped'; -import { HeartbeatCooldownState } from './heartbeat_cooldown'; -import { HeartbeatInactiveState } from './heartbeat_inactive'; -import { HeartbeatFailedState } from './heartbeat_failed'; - -/** - * Context which represent current Subscription Event Engine data state. - * - * @internal - */ -export type HeartbeatReconnectingStateContext = { - channels: string[]; - groups: string[]; - - attempts: number; - reason: PubNubError; -}; - -/** - * Retry heartbeat state. - * - * State in which Presence Event Engine tries to recover after error which happened before. - * - * @internal - */ -export const HearbeatReconnectingState = new State( - 'HEARBEAT_RECONNECTING', -); - -HearbeatReconnectingState.onEnter((context) => delayedHeartbeat(context)); -HearbeatReconnectingState.onExit(() => delayedHeartbeat.cancel); - -HearbeatReconnectingState.on(joined.type, (context, event) => - HeartbeatingState.with({ - channels: [...context.channels, ...event.payload.channels], - groups: [...context.groups, ...event.payload.groups], - }), -); - -HearbeatReconnectingState.on(left.type, (context, event) => - HeartbeatingState.with( - { - channels: context.channels.filter((channel) => !event.payload.channels.includes(channel)), - groups: context.groups.filter((group) => !event.payload.groups.includes(group)), - }, - [leave(event.payload.channels, event.payload.groups)], - ), -); - -HearbeatReconnectingState.on(disconnect.type, (context, _) => { - HeartbeatStoppedState.with( - { - channels: context.channels, - groups: context.groups, - }, - [leave(context.channels, context.groups)], - ); -}); - -HearbeatReconnectingState.on(heartbeatSuccess.type, (context, event) => { - return HeartbeatCooldownState.with({ - channels: context.channels, - groups: context.groups, - }); -}); - -HearbeatReconnectingState.on(heartbeatFailure.type, (context, event) => - HearbeatReconnectingState.with({ ...context, attempts: context.attempts + 1, reason: event.payload }), -); - -HearbeatReconnectingState.on(heartbeatGiveup.type, (context, event) => { - return HeartbeatFailedState.with({ - channels: context.channels, - groups: context.groups, - }); -}); - -HearbeatReconnectingState.on(leftAll.type, (context, _) => - HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)]), -); diff --git a/src/event-engine/presence/states/heartbeating.ts b/src/event-engine/presence/states/heartbeating.ts index f2e4a1c6b..ca864c1c1 100644 --- a/src/event-engine/presence/states/heartbeating.ts +++ b/src/event-engine/presence/states/heartbeating.ts @@ -4,13 +4,13 @@ * @internal */ -import { State } from '../../core/state'; import { Events, disconnect, heartbeatFailure, heartbeatSuccess, joined, left, leftAll } from '../events'; -import { Effects, emitStatus, heartbeat, leave } from '../effects'; +import { HeartbeatInactiveState } from './heartbeat_inactive'; import { HeartbeatCooldownState } from './heartbeat_cooldown'; -import { HearbeatReconnectingState } from './heartbeat_reconnecting'; import { HeartbeatStoppedState } from './heartbeat_stopped'; -import { HeartbeatInactiveState } from './heartbeat_inactive'; +import { HeartbeatFailedState } from './heartbeat_failed'; +import { Effects, emitStatus, heartbeat, leave } from '../effects'; +import { State } from '../../core/state'; /** * Context which represent current Presence Event Engine data state. @@ -32,13 +32,13 @@ export type HeartbeatingStateContext = { export const HeartbeatingState = new State('HEARTBEATING'); HeartbeatingState.onEnter((context) => heartbeat(context.channels, context.groups)); +HeartbeatingState.onExit(() => heartbeat.cancel); -HeartbeatingState.on(heartbeatSuccess.type, (context, event) => { - return HeartbeatCooldownState.with({ - channels: context.channels, - groups: context.groups, - }); -}); +HeartbeatingState.on(heartbeatSuccess.type, (context, event) => + HeartbeatCooldownState.with({ channels: context.channels, groups: context.groups }, [ + emitStatus({ ...event.payload }), + ]), +); HeartbeatingState.on(joined.type, (context, event) => HeartbeatingState.with({ @@ -57,22 +57,16 @@ HeartbeatingState.on(left.type, (context, event) => { ); }); -HeartbeatingState.on(heartbeatFailure.type, (context, event) => { - return HearbeatReconnectingState.with({ - ...context, - attempts: 0, - reason: event.payload, - }); -}); +HeartbeatingState.on(heartbeatFailure.type, (context, event) => + HeartbeatFailedState.with({ ...context }, [ + ...(event.payload.status ? [emitStatus({ ...event.payload.status })] : []), + ]), +); -HeartbeatingState.on(disconnect.type, (context) => - HeartbeatStoppedState.with( - { - channels: context.channels, - groups: context.groups, - }, - [leave(context.channels, context.groups)], - ), +HeartbeatingState.on(disconnect.type, (context, event) => + HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ]), ); HeartbeatingState.on(leftAll.type, (context, _) => diff --git a/src/event-engine/states/handshake_failed.ts b/src/event-engine/states/handshake_failed.ts index 5ca187877..56599e199 100644 --- a/src/event-engine/states/handshake_failed.ts +++ b/src/event-engine/states/handshake_failed.ts @@ -35,29 +35,25 @@ export type HandshakeFailedStateContext = { */ export const HandshakeFailedState = new State('HANDSHAKE_FAILED'); -HandshakeFailedState.on(subscriptionChange.type, (context, event) => - HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }), +HandshakeFailedState.on(subscriptionChange.type, (context, { payload }) => + HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }), ); -HandshakeFailedState.on(reconnect.type, (context, event) => +HandshakeFailedState.on(reconnect.type, (context, { payload }) => HandshakingState.with({ channels: context.channels, groups: context.groups, - cursor: event.payload.cursor || context.cursor, + cursor: payload.cursor || context.cursor, }), ); -HandshakeFailedState.on(restore.type, (context, event) => +HandshakeFailedState.on(restore.type, (context, { payload }) => HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, + channels: payload.channels, + groups: payload.groups, cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region ? event.payload.cursor.region : (context?.cursor?.region ?? 0), + timetoken: payload.cursor.timetoken, + region: payload.cursor.region ? payload.cursor.region : (context?.cursor?.region ?? 0), }, }), ); diff --git a/src/event-engine/states/handshake_reconnecting.ts b/src/event-engine/states/handshake_reconnecting.ts deleted file mode 100644 index aece709c3..000000000 --- a/src/event-engine/states/handshake_reconnecting.ts +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Retry initial subscription handshake (disconnected) state. - * - * @internal - */ - -import { PubNubError } from '../../errors/pubnub-error'; -import { State } from '../core/state'; -import { Effects, emitStatus, handshakeReconnect } from '../effects'; -import { - disconnect, - Events, - handshakeReconnectFailure, - handshakeReconnectGiveup, - handshakeReconnectSuccess, - restore, - subscriptionChange, - unsubscribeAll, -} from '../events'; -import { HandshakeFailedState } from './handshake_failed'; -import { HandshakeStoppedState } from './handshake_stopped'; -import { HandshakingState } from './handshaking'; -import { ReceivingState } from './receiving'; -import { UnsubscribedState } from './unsubscribed'; -import categoryConstants from '../../core/constants/categories'; -import * as Subscription from '../../core/types/api/subscription'; - -/** - * Context which represent current Subscription Event Engine data state. - * - * @internal - */ -export type HandshakeReconnectingStateContext = { - channels: string[]; - groups: string[]; - cursor?: Subscription.SubscriptionCursor; - - attempts: number; - reason: PubNubError; -}; - -/** - * Retry initial subscription handshake (disconnected) state. - * - * State in which Subscription Event Engine tries to recover after error which happened before. - * - * @internal - */ -export const HandshakeReconnectingState = new State( - 'HANDSHAKE_RECONNECTING', -); - -HandshakeReconnectingState.onEnter((context) => handshakeReconnect(context)); -HandshakeReconnectingState.onExit(() => handshakeReconnect.cancel); - -HandshakeReconnectingState.on(handshakeReconnectSuccess.type, (context, event) => { - const cursor = { - timetoken: !!context.cursor?.timetoken ? context.cursor?.timetoken : event.payload.cursor.timetoken, - region: event.payload.cursor.region, - }; - return ReceivingState.with( - { - channels: context.channels, - groups: context.groups, - cursor: cursor, - }, - [emitStatus({ category: categoryConstants.PNConnectedCategory })], - ); -}); - -HandshakeReconnectingState.on(handshakeReconnectFailure.type, (context, event) => - HandshakeReconnectingState.with({ ...context, attempts: context.attempts + 1, reason: event.payload }), -); - -HandshakeReconnectingState.on(handshakeReconnectGiveup.type, (context, event) => - HandshakeFailedState.with( - { - groups: context.groups, - channels: context.channels, - cursor: context.cursor, - reason: event.payload, - }, - [emitStatus({ category: categoryConstants.PNConnectionErrorCategory, error: event.payload?.message })], - ), -); - -HandshakeReconnectingState.on(disconnect.type, (context) => - HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }), -); - -HandshakeReconnectingState.on(subscriptionChange.type, (context, event) => - HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }), -); - -HandshakeReconnectingState.on(restore.type, (context, event) => - HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor?.region || context?.cursor?.region || 0, - }, - }), -); - -HandshakeReconnectingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); diff --git a/src/event-engine/states/handshake_stopped.ts b/src/event-engine/states/handshake_stopped.ts index a902dda9e..909ba97c1 100644 --- a/src/event-engine/states/handshake_stopped.ts +++ b/src/event-engine/states/handshake_stopped.ts @@ -32,29 +32,19 @@ type HandshakeStoppedStateContext = { */ export const HandshakeStoppedState = new State('HANDSHAKE_STOPPED'); -HandshakeStoppedState.on(subscriptionChange.type, (context, event) => - HandshakeStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }), +HandshakeStoppedState.on(subscriptionChange.type, (context, { payload }) => + HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }), ); -HandshakeStoppedState.on(reconnect.type, (context, event) => - HandshakingState.with({ - ...context, - cursor: event.payload.cursor || context.cursor, - }), +HandshakeStoppedState.on(reconnect.type, (context, { payload }) => + HandshakingState.with({ ...context, cursor: payload.cursor || context.cursor }), ); -HandshakeStoppedState.on(restore.type, (context, event) => +HandshakeStoppedState.on(restore.type, (context, { payload }) => HandshakeStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context?.cursor?.region || 0, - }, + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor?.region || 0 }, }), ); diff --git a/src/event-engine/states/handshaking.ts b/src/event-engine/states/handshaking.ts index d856b7e20..7e2e881be 100644 --- a/src/event-engine/states/handshaking.ts +++ b/src/event-engine/states/handshaking.ts @@ -4,23 +4,25 @@ * @internal */ -import { State } from '../core/state'; -import { Effects, handshake, emitStatus } from '../effects'; +import { Effects, emitStatus, handshake } from '../effects'; import { disconnect, - restore, Events, handshakeFailure, handshakeSuccess, + restore, subscriptionChange, unsubscribeAll, } from '../events'; -import { HandshakeReconnectingState } from './handshake_reconnecting'; +import * as Subscription from '../../core/types/api/subscription'; +import categoryConstants from '../../core/constants/categories'; import { HandshakeStoppedState } from './handshake_stopped'; -import { ReceivingState } from './receiving'; +import { HandshakeFailedState } from './handshake_failed'; import { UnsubscribedState } from './unsubscribed'; -import categoryConstants from '../../core/constants/categories'; -import * as Subscription from '../../core/types/api/subscription'; +import { ReceivingState } from './receiving'; +import { State } from '../core/state'; +import { PubNubAPIError } from '../../errors/pubnub-api-error'; +import RequestOperation from '../../core/constants/operations'; /** * Context which represent current Subscription Event Engine data state. @@ -46,62 +48,63 @@ export const HandshakingState = new State handshake(context.channels, context.groups)); HandshakingState.onExit(() => handshake.cancel); -HandshakingState.on(subscriptionChange.type, (context, event) => { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return UnsubscribedState.with(undefined); - } +HandshakingState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }); + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); }); -HandshakingState.on(handshakeSuccess.type, (context, event) => +HandshakingState.on(handshakeSuccess.type, (context, { payload }) => ReceivingState.with( { channels: context.channels, groups: context.groups, cursor: { - timetoken: !!context?.cursor?.timetoken ? context?.cursor?.timetoken : event.payload.timetoken, - region: event.payload.region, + timetoken: !!context.cursor?.timetoken ? context.cursor?.timetoken : payload.timetoken, + region: payload.region, }, }, - [ - emitStatus({ - category: categoryConstants.PNConnectedCategory, - }), - ], + [emitStatus({ category: categoryConstants.PNConnectedCategory })], ), ); -HandshakingState.on(handshakeFailure.type, (context, event) => { - return HandshakeReconnectingState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - attempts: 0, - reason: event.payload, - }); -}); - -HandshakingState.on(disconnect.type, (context) => - HandshakeStoppedState.with({ - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }), +HandshakingState.on(handshakeFailure.type, (context, event) => + HandshakeFailedState.with( + { + channels: context.channels, + groups: context.groups, + cursor: context.cursor, + reason: event.payload, + }, + [emitStatus({ category: categoryConstants.PNConnectionErrorCategory, error: event.payload.status?.category })], + ), ); -HandshakingState.on(restore.type, (context, event) => +HandshakingState.on(disconnect.type, (context, event) => { + if (!event.payload.isOffline) + return HandshakeStoppedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor }); + else { + const errorReason = PubNubAPIError.create(new Error('Network connection error')).toPubNubError( + RequestOperation.PNSubscribeOperation, + ); + + return HandshakeFailedState.with( + { channels: context.channels, groups: context.groups, cursor: context.cursor, reason: errorReason }, + [ + emitStatus({ + category: categoryConstants.PNConnectionErrorCategory, + error: errorReason.status?.category, + }), + ], + ); + } +}); + +HandshakingState.on(restore.type, (context, { payload }) => HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context?.cursor?.region || 0, - }, + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context?.cursor?.region || 0 }, }), ); diff --git a/src/event-engine/states/receive_failed.ts b/src/event-engine/states/receive_failed.ts index 34d46ed71..5304e375a 100644 --- a/src/event-engine/states/receive_failed.ts +++ b/src/event-engine/states/receive_failed.ts @@ -35,33 +35,26 @@ export type ReceiveFailedStateContext = { */ export const ReceiveFailedState = new State('RECEIVE_FAILED'); -ReceiveFailedState.on(reconnect.type, (context, event) => +ReceiveFailedState.on(reconnect.type, (context, { payload }) => HandshakingState.with({ channels: context.channels, groups: context.groups, cursor: { - timetoken: !!event.payload.cursor.timetoken ? event.payload.cursor?.timetoken : context.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, + timetoken: !!payload.cursor.timetoken ? payload.cursor?.timetoken : context.cursor.timetoken, + region: payload.cursor.region || context.cursor.region, }, }), ); -ReceiveFailedState.on(subscriptionChange.type, (context, event) => - HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }), +ReceiveFailedState.on(subscriptionChange.type, (context, { payload }) => + HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }), ); -ReceiveFailedState.on(restore.type, (context, event) => +ReceiveFailedState.on(restore.type, (context, { payload }) => HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, }), ); diff --git a/src/event-engine/states/receive_reconnecting.ts b/src/event-engine/states/receive_reconnecting.ts deleted file mode 100644 index 91854e2b6..000000000 --- a/src/event-engine/states/receive_reconnecting.ts +++ /dev/null @@ -1,114 +0,0 @@ -/** - * Reconnect to receive real-time updates (disconnected) state. - * - * @internal - */ - -import { PubNubError } from '../../errors/pubnub-error'; -import { State } from '../core/state'; -import { Effects, emitMessages, receiveReconnect, emitStatus } from '../effects'; -import { - disconnect, - Events, - receiveReconnectFailure, - receiveReconnectGiveup, - receiveReconnectSuccess, - restore, - subscriptionChange, - unsubscribeAll, -} from '../events'; -import { ReceivingState } from './receiving'; -import { ReceiveFailedState } from './receive_failed'; -import { ReceiveStoppedState } from './receive_stopped'; -import { UnsubscribedState } from './unsubscribed'; -import categoryConstants from '../../core/constants/categories'; -import * as Subscription from '../../core/types/api/subscription'; - -/** - * Context which represent current Subscription Event Engine data state. - * - * @internal - */ -export type ReceiveReconnectingStateContext = { - channels: string[]; - groups: string[]; - cursor: Subscription.SubscriptionCursor; - - attempts: number; - reason: PubNubError; -}; - -/** - * Reconnect to receive real-time updates (disconnected) state. - * - * State in which Subscription Event Engine tries to recover after error which happened before. - * - * @internal - */ -export const ReceiveReconnectingState = new State( - 'RECEIVE_RECONNECTING', -); - -ReceiveReconnectingState.onEnter((context) => receiveReconnect(context)); -ReceiveReconnectingState.onExit(() => receiveReconnect.cancel); - -ReceiveReconnectingState.on(receiveReconnectSuccess.type, (context, event) => - ReceivingState.with( - { - channels: context.channels, - groups: context.groups, - cursor: event.payload.cursor, - }, - [emitMessages(event.payload.events)], - ), -); - -ReceiveReconnectingState.on(receiveReconnectFailure.type, (context, event) => - ReceiveReconnectingState.with({ ...context, attempts: context.attempts + 1, reason: event.payload }), -); - -ReceiveReconnectingState.on(receiveReconnectGiveup.type, (context, event) => - ReceiveFailedState.with( - { - groups: context.groups, - channels: context.channels, - cursor: context.cursor, - reason: event.payload, - }, - [emitStatus({ category: categoryConstants.PNDisconnectedUnexpectedlyCategory, error: event.payload?.message })], - ), -); - -ReceiveReconnectingState.on(disconnect.type, (context) => - ReceiveStoppedState.with( - { - channels: context.channels, - groups: context.groups, - cursor: context.cursor, - }, - [emitStatus({ category: categoryConstants.PNDisconnectedCategory })], - ), -); - -ReceiveReconnectingState.on(restore.type, (context, event) => - ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }), -); - -ReceiveReconnectingState.on(subscriptionChange.type, (context, event) => - ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }), -); - -ReceiveReconnectingState.on(unsubscribeAll.type, (_) => - UnsubscribedState.with(undefined, [emitStatus({ category: categoryConstants.PNDisconnectedCategory })]), -); diff --git a/src/event-engine/states/receive_stopped.ts b/src/event-engine/states/receive_stopped.ts index 39e13e1d4..c1a4b9ef5 100644 --- a/src/event-engine/states/receive_stopped.ts +++ b/src/event-engine/states/receive_stopped.ts @@ -32,32 +32,25 @@ type ReceiveStoppedStateContext = { */ export const ReceiveStoppedState = new State('RECEIVE_STOPPED'); -ReceiveStoppedState.on(subscriptionChange.type, (context, event) => - ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: context.cursor, - }), +ReceiveStoppedState.on(subscriptionChange.type, (context, { payload }) => + ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }), ); -ReceiveStoppedState.on(restore.type, (context, event) => +ReceiveStoppedState.on(restore.type, (context, { payload }) => ReceiveStoppedState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, }), ); -ReceiveStoppedState.on(reconnect.type, (context, event) => +ReceiveStoppedState.on(reconnect.type, (context, { payload }) => HandshakingState.with({ channels: context.channels, groups: context.groups, cursor: { - timetoken: !!event.payload.cursor.timetoken ? event.payload.cursor?.timetoken : context.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, + timetoken: !!payload.cursor.timetoken ? payload.cursor?.timetoken : context.cursor.timetoken, + region: payload.cursor.region || context.cursor.region, }, }), ); diff --git a/src/event-engine/states/receiving.ts b/src/event-engine/states/receiving.ts index 84362a694..5f158322b 100644 --- a/src/event-engine/states/receiving.ts +++ b/src/event-engine/states/receiving.ts @@ -4,7 +4,6 @@ * @internal */ -import { State } from '../core/state'; import { Effects, emitMessages, emitStatus, receiveMessages } from '../effects'; import { disconnect, @@ -15,11 +14,15 @@ import { subscriptionChange, unsubscribeAll, } from '../events'; -import { UnsubscribedState } from './unsubscribed'; -import { ReceiveReconnectingState } from './receive_reconnecting'; -import { ReceiveStoppedState } from './receive_stopped'; -import categoryConstants from '../../core/constants/categories'; import * as Subscription from '../../core/types/api/subscription'; +import categoryConstants from '../../core/constants/categories'; +import { ReceiveStoppedState } from './receive_stopped'; +import { ReceiveFailedState } from './receive_failed'; +import { UnsubscribedState } from './unsubscribed'; +import { State } from '../core/state'; +import { HandshakeFailedState } from './handshake_failed'; +import { PubNubAPIError } from '../../errors/pubnub-api-error'; +import RequestOperation from '../../core/constants/operations'; /** * Context which represent current Subscription Event Engine data state. @@ -44,58 +47,75 @@ export const ReceivingState = new State( ReceivingState.onEnter((context) => receiveMessages(context.channels, context.groups, context.cursor)); ReceivingState.onExit(() => receiveMessages.cancel); -ReceivingState.on(receiveSuccess.type, (context, event) => { - return ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: event.payload.cursor }, [ - emitMessages(event.payload.events), +ReceivingState.on(receiveSuccess.type, (context, { payload }) => { + return ReceivingState.with({ channels: context.channels, groups: context.groups, cursor: payload.cursor }, [ + emitMessages(payload.events), ]); }); -ReceivingState.on(subscriptionChange.type, (context, event) => { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return UnsubscribedState.with(undefined); - } - - return ReceivingState.with({ - cursor: context.cursor, - channels: event.payload.channels, - groups: event.payload.groups, - }); -}); +ReceivingState.on(subscriptionChange.type, (context, { payload }) => { + const subscriptionChangeStatus = { + category: categoryConstants.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + }; -ReceivingState.on(restore.type, (context, event) => { - if (event.payload.channels.length === 0 && event.payload.groups.length === 0) { - return UnsubscribedState.with(undefined); - } + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined, [emitStatus(subscriptionChangeStatus)]); - return ReceivingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: { - timetoken: event.payload.cursor.timetoken, - region: event.payload.cursor.region || context.cursor.region, - }, - }); + return ReceivingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }, [ + emitStatus(subscriptionChangeStatus), + ]); }); -ReceivingState.on(receiveFailure.type, (context, event) => { - return ReceiveReconnectingState.with({ - ...context, - attempts: 0, - reason: event.payload, - }); -}); +ReceivingState.on(restore.type, (context, { payload }) => { + const subscriptionChangeStatus = { + category: categoryConstants.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + }; + + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined, [emitStatus(subscriptionChangeStatus)]); -ReceivingState.on(disconnect.type, (context) => { - return ReceiveStoppedState.with( + return ReceivingState.with( { - channels: context.channels, - groups: context.groups, - cursor: context.cursor, + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, }, - [emitStatus({ category: categoryConstants.PNDisconnectedCategory })], + [emitStatus(subscriptionChangeStatus)], ); }); +ReceivingState.on(receiveFailure.type, (context, { payload }) => + ReceiveFailedState.with({ ...context, reason: payload }, [ + emitStatus({ category: categoryConstants.PNDisconnectedUnexpectedlyCategory, error: payload.status?.category }), + ]), +); + +ReceivingState.on(disconnect.type, (context, event) => { + if (!event.payload.isOffline) { + return ReceiveStoppedState.with({ channels: context.channels, groups: context.groups, cursor: context.cursor }, [ + emitStatus({ category: categoryConstants.PNDisconnectedCategory }), + ]); + } else { + const errorReason = PubNubAPIError.create(new Error('Network connection error')).toPubNubError( + RequestOperation.PNSubscribeOperation, + ); + + return ReceiveFailedState.with( + { channels: context.channels, groups: context.groups, cursor: context.cursor, reason: errorReason }, + [ + emitStatus({ + category: categoryConstants.PNDisconnectedUnexpectedlyCategory, + error: errorReason.status?.category, + }), + ], + ); + } +}); + ReceivingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined, [emitStatus({ category: categoryConstants.PNDisconnectedCategory })]), ); diff --git a/src/event-engine/states/unsubscribed.ts b/src/event-engine/states/unsubscribed.ts index 8d62499b1..772a770bc 100644 --- a/src/event-engine/states/unsubscribed.ts +++ b/src/event-engine/states/unsubscribed.ts @@ -18,17 +18,10 @@ import { HandshakingState } from './handshaking'; */ export const UnsubscribedState = new State('UNSUBSCRIBED'); -UnsubscribedState.on(subscriptionChange.type, (_, event) => - HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - }), +UnsubscribedState.on(subscriptionChange.type, (_, { payload }) => + HandshakingState.with({ channels: payload.channels, groups: payload.groups }), ); -UnsubscribedState.on(restore.type, (_, event) => { - return HandshakingState.with({ - channels: event.payload.channels, - groups: event.payload.groups, - cursor: event.payload.cursor, - }); -}); +UnsubscribedState.on(restore.type, (_, { payload }) => + HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: payload.cursor }), +); diff --git a/src/transport/middleware.ts b/src/transport/middleware.ts index 9ef69c0a4..0ce146a7d 100644 --- a/src/transport/middleware.ts +++ b/src/transport/middleware.ts @@ -4,9 +4,12 @@ * @internal */ -import { TransportMethod, TransportRequest } from '../core/types/transport-request'; +import { CancellationController, TransportMethod, TransportRequest } from '../core/types/transport-request'; import { PrivateClientConfiguration } from '../core/interfaces/configuration'; +import { TransportResponse } from '../core/types/transport-response'; import { TokenManager } from '../core/components/token_manager'; +import { PubNubAPIError } from '../errors/pubnub-api-error'; +import StatusCategory from '../core/constants/categories'; import { Transport } from '../core/interfaces/transport'; import { encodeString } from '../core/utils'; import { Query } from '../core/types/api'; @@ -125,8 +128,66 @@ export class PubNubMiddleware implements Transport { } } - makeSendable(req: TransportRequest) { - return this.configuration.transport.makeSendable(this.request(req)); + makeSendable(req: TransportRequest): [Promise, CancellationController | undefined] { + const retryPolicy = this.configuration.clientConfiguration.retryConfiguration; + const transport = this.configuration.transport; + + // Make requests retryable. + if (retryPolicy !== undefined) { + let retryTimeout: ReturnType | undefined; + let activeCancellation: CancellationController | undefined; + let cancelled = false; + let attempt = 0; + + const cancellation: CancellationController = { + abort: (reason) => { + cancelled = true; + if (retryTimeout) clearTimeout(retryTimeout); + if (activeCancellation) activeCancellation.abort(reason); + }, + }; + + const retryableRequest = new Promise((resolve, reject) => { + const trySendRequest = () => { + // Check whether request already has been cancelled and there is no retry should proceed. + if (cancelled) return; + + const [attemptPromise, attemptCancellation] = transport.makeSendable(this.request(req)); + activeCancellation = attemptCancellation; + + const responseHandler = (res?: TransportResponse, error?: PubNubAPIError) => { + const retriableError = error ? error.category !== StatusCategory.PNCancelledCategory : true; + const retriableStatusCode = !res || res.status >= 400; + let delay = -1; + + if ( + retriableError && + retriableStatusCode && + retryPolicy.shouldRetry(req, res, error?.category, attempt + 1) + ) + delay = retryPolicy.getDelay(attempt, res); + + if (delay > 0) { + attempt++; + retryTimeout = setTimeout(() => trySendRequest(), delay); + } else { + if (res) resolve(res); + else if (error) reject(error); + } + }; + + attemptPromise + .then((res) => responseHandler(res)) + .catch((err: PubNubAPIError) => responseHandler(undefined, err)); + }; + + trySendRequest(); + }); + + return [retryableRequest, activeCancellation ? cancellation : undefined]; + } + + return transport.makeSendable(this.request(req)); } request(req: TransportRequest): TransportRequest { diff --git a/src/web/index.ts b/src/web/index.ts index 28b91d46e..b4a4e0982 100644 --- a/src/web/index.ts +++ b/src/web/index.ts @@ -151,7 +151,7 @@ export default class PubNub extends PubNubCore { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -33,7 +29,7 @@ describe('#listeners', () => { }); afterEach(() => { - pubnub.destroy(); + pubnub.destroy(true); }); it('should pass messages of subscribed channel to its listener', async () => { diff --git a/test/integration/components/networking.test.ts b/test/integration/components/networking.test.ts index bf27209d1..7dc595548 100644 --- a/test/integration/components/networking.test.ts +++ b/test/integration/components/networking.test.ts @@ -18,10 +18,6 @@ describe('#components/networking', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -49,6 +45,12 @@ describe('#components/networking', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + pubnubPartner.destroy(true); + pubnubSDKName.destroy(true); + }); + describe('supports user-agent generation with partner', () => { it('returns a correct user-agent object', (done) => { utils diff --git a/test/integration/components/reconnection_manager.test.ts b/test/integration/components/reconnection_manager.test.ts index 8dd2ca5ef..49559a554 100644 --- a/test/integration/components/reconnection_manager.test.ts +++ b/test/integration/components/reconnection_manager.test.ts @@ -17,10 +17,6 @@ describe('#components/reconnection_manger', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -36,7 +32,7 @@ describe('#components/reconnection_manger', () => { }); afterEach(() => { - pubnub.destroy(); + pubnub.destroy(true); clock.restore(); }); diff --git a/test/integration/components/subscription_manager.test.ts b/test/integration/components/subscription_manager.test.ts index e040af904..e3f48fe16 100644 --- a/test/integration/components/subscription_manager.test.ts +++ b/test/integration/components/subscription_manager.test.ts @@ -19,10 +19,6 @@ describe('#components/subscription_manager', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -81,10 +77,11 @@ describe('#components/subscription_manager', () => { }); afterEach(() => { - pubnub.stop(); - pubnubWithLimitedDeduplicationQueue.stop(); - pubnubWithPassingHeartbeats.stop(); - pubnubWithLimitedQueue.stop(); + pubnub.destroy(true); + pubnubWithLimitedDeduplicationQueue.destroy(true); + pubnubWithPassingHeartbeats.destroy(true); + pubnubWithLimitedQueue.destroy(true); + pubnubWithCrypto.destroy(true); }); it('passes the correct message information', (done) => { diff --git a/test/integration/components/token_manager.test.ts b/test/integration/components/token_manager.test.ts index 99751afa4..e3a144155 100644 --- a/test/integration/components/token_manager.test.ts +++ b/test/integration/components/token_manager.test.ts @@ -18,17 +18,21 @@ describe('#components/token_manager', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('parse token', () => { it('ignore invalid tokens', () => { - let noPermissions = pubnub.parseToken('bad-token'); + const noPermissions = pubnub.parseToken('bad-token'); assert(noPermissions === undefined); }); it('contains correct permissions', () => { - let tokenWithAll = + const tokenWithAll = 'p0F2AkF0GmEK-4NDdHRsGDxDcmVzpURjaGFuoWhjaGFubmVsMQFDZ3JwoWZncm91cDEBQ3VzcqBDc3BjoER1dWlkoWV1c2VyMQFDcGF0pURjaGFuoWIuKgFDZ3JwoWIuKgFDdXNyoENzcGOgRHV1aWShYi4qAURtZXRhoENzaWdYII5bQpWLi6Z-l5jbShWxZ7QL6o8Dz6_vxluhxrMGzQCN'; - let permissions = pubnub.parseToken(tokenWithAll)!; + const permissions = pubnub.parseToken(tokenWithAll)!; assert(permissions.version === 2); assert(permissions.timestamp === 1628109699); @@ -65,21 +69,21 @@ describe('#components/token_manager', () => { describe('supports token update', () => { it('support get and set token', () => { - let token = + const token = 'p0F2AkF0GmEK8NZDdHRsGDxDcmVzpURjaGFuoENncnCgQ3VzcqBDc3BjoER1dWlkoWV1c2VyMRhoQ3BhdKVEY2hhbqBDZ3JwoEN1c3KgQ3NwY6BEdXVpZKBEbWV0YaBDc2lnWCB6sYaT3ZbNVV6TBxDKGvdOk6TSQRMoRZir4cwoN9-_dA=='; // has uuid id 'user1' pubnub.setToken(token); - let tokenCheck = pubnub.getToken(); + const tokenCheck = pubnub.getToken(); assert(tokenCheck === token); }); it('adding new token replaces previous', () => { - let token = + const token = 'p0F2AkF0GmEK8NZDdHRsGDxDcmVzpURjaGFuoENncnCgQ3VzcqBDc3BjoER1dWlkoWV1c2VyMRhoQ3BhdKVEY2hhbqBDZ3JwoEN1c3KgQ3NwY6BEdXVpZKBEbWV0YaBDc2lnWCB6sYaT3ZbNVV6TBxDKGvdOk6TSQRMoRZir4cwoN9-_dA=='; - let token2 = + const token2 = 'p0F2AkF0GmEK8LFDdHRsGDxDcmVzpURjaGFuoENncnCgQ3VzcqBDc3BjoER1dWlkoWV1c2VyMhhoQ3BhdKVEY2hhbqBDZ3JwoEN1c3KgQ3NwY6BEdXVpZKBEbWV0YaBDc2lnWCDq63hdreA9JbHVnHLDJuHzK-AWSdcVFZKG0nse79JMZw=='; // has uuid id 'uuid1' diff --git a/test/integration/endpoints/access.test.ts b/test/integration/endpoints/access.test.ts index 75f40c5f6..df879d7f4 100644 --- a/test/integration/endpoints/access.test.ts +++ b/test/integration/endpoints/access.test.ts @@ -36,6 +36,10 @@ describe('access endpoints', () => { pubnub._config.getVersion = () => 'suchJavascript'; }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('#audit', () => { it('issues the correct RESTful request for channels', (done) => { const scope = utils @@ -58,17 +62,17 @@ describe('access endpoints', () => { try { assert.equal(status.error, false); assert.deepEqual(response, { - level: "channel-group+auth", - subscribe_key: "mySubscribeKey", - "channel-group": "cg2", + level: 'channel-group+auth', + subscribe_key: 'mySubscribeKey', + 'channel-group': 'cg2', auths: { key1: { r: 1, m: 1, w: 1, - d: 1 - } - } + d: 1, + }, + }, }); assert.equal(scope.isDone(), true); done(); @@ -99,17 +103,17 @@ describe('access endpoints', () => { try { assert.equal(status.error, false); assert.deepEqual(response, { - level: "channel-group+auth", - subscribe_key: "mySubscribeKey", - "channel-group": "cg2", + level: 'channel-group+auth', + subscribe_key: 'mySubscribeKey', + 'channel-group': 'cg2', auths: { key1: { r: 1, m: 1, w: 1, - d: 1 - } - } + d: 1, + }, + }, }); assert.equal(scope.isDone(), true); done(); @@ -140,17 +144,17 @@ describe('access endpoints', () => { try { assert.equal(status.error, false); assert.deepEqual(response, { - level: "channel-group+auth", - subscribe_key: "mySubscribeKey", - "channel-group": "cg2", + level: 'channel-group+auth', + subscribe_key: 'mySubscribeKey', + 'channel-group': 'cg2', auths: { key1: { r: 1, m: 1, w: 1, - d: 1 - } - } + d: 1, + }, + }, }); assert.equal(scope.isDone(), true); done(); @@ -414,7 +418,7 @@ describe('access endpoints', () => { assert.equal(scope.isDone(), false); assert.equal( error.status.message, - "Both channel/channel group and uuid cannot be used in the same request" + 'Both channel/channel group and uuid cannot be used in the same request', ); done(); } catch (error) { @@ -463,7 +467,7 @@ describe('access endpoints', () => { assert.equal(scope.isDone(), false); assert.equal( error.status.message, - "Both channel/channel group and uuid cannot be used in the same request" + 'Both channel/channel group and uuid cannot be used in the same request', ); done(); } catch (error) { @@ -506,7 +510,7 @@ describe('access endpoints', () => { .catch((error) => { try { assert.equal(scope.isDone(), false); - assert.equal(error.status.message, "authKeys are required for grant request on uuids"); + assert.equal(error.status.message, 'authKeys are required for grant request on uuids'); done(); } catch (error) { done(error); @@ -524,10 +528,6 @@ describe('access endpoints telemetry', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -541,9 +541,13 @@ describe('access endpoints telemetry', () => { pubnub._config.getVersion = () => 'suchJavascript'; }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('#audit', () => { it('should add PAM audit API telemetry information', (done) => { - let scope = utils.createNock().get('/v2/auth/audit/sub-key/mySubscribeKey').query(true); + const scope = utils.createNock().get('/v2/auth/audit/sub-key/mySubscribeKey').query(true); const delays = [100, 200, 300, 400]; const countedDelays = delays.slice(0, delays.length - 1); const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); @@ -569,7 +573,7 @@ describe('access endpoints telemetry', () => { describe('#grant', () => { it('should add PAM grant API telemetry information', (done) => { - let scope = utils.createNock().get('/v2/auth/grant/sub-key/mySubscribeKey').query(true); + const scope = utils.createNock().get('/v2/auth/grant/sub-key/mySubscribeKey').query(true); const delays = [100, 200, 300, 400]; const countedDelays = delays.slice(0, delays.length - 1); const average = Math.floor(countedDelays.reduce((acc, delay) => acc + delay, 0) / countedDelays.length); diff --git a/test/integration/endpoints/channel_groups.test.ts b/test/integration/endpoints/channel_groups.test.ts index abe20a179..04e3464ac 100644 --- a/test/integration/endpoints/channel_groups.test.ts +++ b/test/integration/endpoints/channel_groups.test.ts @@ -7,7 +7,6 @@ import nock from 'nock'; import PubNub from '../../../src/node/index'; import utils from '../../utils'; - describe('channel group endpoints', () => { let pubnub: PubNub; @@ -15,10 +14,6 @@ describe('channel group endpoints', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -30,6 +25,10 @@ describe('channel group endpoints', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('adding channels to channel group', () => { it('supports addition of multiple channels', (done) => { const scope = utils @@ -98,7 +97,7 @@ describe('channel group endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.groups, ["a", "b"]); + assert.deepEqual(response.groups, ['a', 'b']); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -129,7 +128,7 @@ describe('channel group endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.channels, ["a", "b"]); + assert.deepEqual(response.channels, ['a', 'b']); assert.equal(scope.isDone(), true); done(); } catch (error) { diff --git a/test/integration/endpoints/fetch_messages.test.ts b/test/integration/endpoints/fetch_messages.test.ts index a9c3ca975..e3abb68db 100644 --- a/test/integration/endpoints/fetch_messages.test.ts +++ b/test/integration/endpoints/fetch_messages.test.ts @@ -148,15 +148,11 @@ describe('fetch messages endpoints', () => { const publishKey = process.env.PUBLISH_KEY || 'demo'; let pubnub: PubNub; - after(() => { - nock.enableNetConnect(); - }); - afterEach(() => { nock.enableNetConnect(); pubnub.removeAllListeners(); pubnub.unsubscribeAll(); - pubnub.stop(); + pubnub.destroy(true); }); beforeEach(() => { diff --git a/test/integration/endpoints/grant_token.test.ts b/test/integration/endpoints/grant_token.test.ts index 0ae467d84..247dcf76f 100644 --- a/test/integration/endpoints/grant_token.test.ts +++ b/test/integration/endpoints/grant_token.test.ts @@ -39,6 +39,10 @@ describe('grant token endpoint', () => { } else pubnub._config.getVersion = () => 'testVersion'; }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('#grantToken', () => { describe('##validation', () => { it('ensure resources or patterns', (done) => { @@ -65,7 +69,7 @@ describe('grant token endpoint', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing values for either Resources or Patterns"); + assert.equal(err.status.message, 'Missing values for either Resources or Patterns'); done(); } catch (error) { done(error); @@ -102,7 +106,7 @@ describe('grant token endpoint', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing values for either Resources or Patterns"); + assert.equal(err.status.message, 'Missing values for either Resources or Patterns'); done(); } catch (error) { done(error); @@ -139,7 +143,7 @@ describe('grant token endpoint', () => { .catch((err) => { try { assert.equal(scope.isDone(), false); - assert.equal(err.status.message, "Missing values for either Resources or Patterns"); + assert.equal(err.status.message, 'Missing values for either Resources or Patterns'); done(); } catch (error) { done(error); @@ -170,7 +174,7 @@ describe('grant token endpoint', () => { }); it('should correctly translate VSP terms into legacy terms', async () => { - let scope = utils + const scope = utils .createNock() .post( '/v3/pam/mySubscribeKey/grant', diff --git a/test/integration/endpoints/history.test.ts b/test/integration/endpoints/history.test.ts index 8f879c7c5..3537cbf15 100644 --- a/test/integration/endpoints/history.test.ts +++ b/test/integration/endpoints/history.test.ts @@ -64,15 +64,11 @@ describe('history endpoints', () => { const publishKey = process.env.PUBLISH_KEY || 'demo'; let pubnub: PubNub; - after(() => { - nock.enableNetConnect(); - }); - afterEach(() => { nock.enableNetConnect(); pubnub.removeAllListeners(); pubnub.unsubscribeAll(); - pubnub.stop(); + pubnub.destroy(true); }); beforeEach(() => { diff --git a/test/integration/endpoints/message_actions.test.ts b/test/integration/endpoints/message_actions.test.ts index 0e414f806..b9519f0e2 100644 --- a/test/integration/endpoints/message_actions.test.ts +++ b/test/integration/endpoints/message_actions.test.ts @@ -129,15 +129,11 @@ describe('message actions endpoints', () => { const publishKey = process.env.PUBLISH_KEY || 'demo'; let pubnub: PubNub; - after(() => { - nock.enableNetConnect(); - }); - afterEach(() => { nock.enableNetConnect(); pubnub.removeAllListeners(); pubnub.unsubscribeAll(); - pubnub.stop(); + pubnub.destroy(true); }); beforeEach(() => { diff --git a/test/integration/endpoints/message_counts.test.ts b/test/integration/endpoints/message_counts.test.ts index 19f66d255..bd4b82ad7 100644 --- a/test/integration/endpoints/message_counts.test.ts +++ b/test/integration/endpoints/message_counts.test.ts @@ -14,10 +14,6 @@ describe('message counts', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -29,6 +25,10 @@ describe('message counts', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + }); + it('get history with messages for a channel', (done) => { const scope = utils .createNock() diff --git a/test/integration/endpoints/objects/channel.test.ts b/test/integration/endpoints/objects/channel.test.ts index 1bd25182a..69c39491c 100644 --- a/test/integration/endpoints/objects/channel.test.ts +++ b/test/integration/endpoints/objects/channel.test.ts @@ -18,10 +18,6 @@ describe('objects channel', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -35,6 +31,10 @@ describe('objects channel', () => { PNSDK = `PubNub-JS-Nodejs/${pubnub.getVersion()}`; }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('getAllChannelMetadata', () => { it('should resolve to a list of channel metadata', async () => { const scope = utils diff --git a/test/integration/endpoints/objects/membership.test.ts b/test/integration/endpoints/objects/membership.test.ts index 626f66659..afeb708d6 100644 --- a/test/integration/endpoints/objects/membership.test.ts +++ b/test/integration/endpoints/objects/membership.test.ts @@ -20,10 +20,6 @@ describe('objects membership', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -36,4 +32,8 @@ describe('objects membership', () => { }); PNSDK = `PubNub-JS-Nodejs/${pubnub.getVersion()}`; }); + + afterEach(() => { + pubnub.destroy(true); + }); }); diff --git a/test/integration/endpoints/objects/uuid.test.ts b/test/integration/endpoints/objects/uuid.test.ts index e51a9a765..4d67076c5 100644 --- a/test/integration/endpoints/objects/uuid.test.ts +++ b/test/integration/endpoints/objects/uuid.test.ts @@ -18,10 +18,6 @@ describe('objects UUID', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -35,6 +31,10 @@ describe('objects UUID', () => { PNSDK = `PubNub-JS-Nodejs/${pubnub.getVersion()}`; }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('getAllUUIDMetadata', () => { it('should resolve to a list of UUID metadata', async () => { const scope = utils diff --git a/test/integration/endpoints/presence.test.ts b/test/integration/endpoints/presence.test.ts index 3ff847a3d..3e37e714b 100644 --- a/test/integration/endpoints/presence.test.ts +++ b/test/integration/endpoints/presence.test.ts @@ -13,10 +13,6 @@ describe('presence endpoints', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -28,6 +24,10 @@ describe('presence endpoints', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('#whereNow', () => { it('returns the requested data for user UUID', (done) => { const scope = utils @@ -45,7 +45,7 @@ describe('presence endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.channels, ["a", "b"]); + assert.deepEqual(response.channels, ['a', 'b']); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -78,10 +78,12 @@ describe('presence endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.channels, ["a", "b"]); + assert.deepEqual(response.channels, ['a', 'b']); assert.equal(scope.isDone(), true); + pubnubClient.destroy(true); done(); } catch (error) { + pubnubClient.destroy(true); done(error); } }); @@ -103,7 +105,7 @@ describe('presence endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.channels, ["a", "b"]); + assert.deepEqual(response.channels, ['a', 'b']); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -158,7 +160,7 @@ describe('presence endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.deepEqual(response.state, { age: 20, status: 'online' }); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -194,10 +196,12 @@ describe('presence endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.deepEqual(response.state, { age: 20, status: 'online' }); assert.equal(scope.isDone(), true); + pubnubClient.destroy(true); done(); } catch (error) { + pubnubClient.destroy(true); done(error); } }); @@ -224,8 +228,8 @@ describe('presence endpoints', () => { assert.equal(status.error, false); assert(response !== null); assert.deepEqual(response.state, { - ch1: { age: 20, status: "online" }, - ch2: { age: 100, status: "offline" } + ch1: { age: 20, status: 'online' }, + ch2: { age: 100, status: 'offline' }, }); assert.equal(scope.isDone(), true); done(); @@ -261,7 +265,7 @@ describe('presence endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.deepEqual(response.state, { age: 20, status: 'online' }); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -292,7 +296,7 @@ describe('presence endpoints', () => { assert.equal(status.error, false); assert(response !== null); assert.deepEqual(response.channels, { - testChannel: { age: 20, status: "online" } + testChannel: { age: 20, status: 'online' }, }); assert.equal(scope.isDone(), true); done(); @@ -321,7 +325,7 @@ describe('presence endpoints', () => { assert.equal(status.error, false); assert(response !== null); assert.deepEqual(response.channels, { - testChannel: { age: 20, status: "online" } + testChannel: { age: 20, status: 'online' }, }); assert.equal(scope.isDone(), true); done(); @@ -350,8 +354,8 @@ describe('presence endpoints', () => { assert.equal(status.error, false); assert(response !== null); assert.deepEqual(response.channels, { - ch1: { age: 20, status: "online" }, - ch2: { age: 100, status: "offline" } + ch1: { age: 20, status: 'online' }, + ch2: { age: 100, status: 'offline' }, }); assert.equal(scope.isDone(), true); done(); @@ -381,8 +385,8 @@ describe('presence endpoints', () => { assert.equal(status.error, false); assert(response !== null); assert.deepEqual(response.channels, { - ch1: { age: 20, status: "online" }, - ch2: { age: 100, status: "offline" } + ch1: { age: 20, status: 'online' }, + ch2: { age: 100, status: 'offline' }, }); assert.equal(scope.isDone(), true); done(); @@ -414,15 +418,15 @@ describe('presence endpoints', () => { assert(response !== null); assert.deepEqual(response.channels, { game1: { - name: "game1", + name: 'game1', occupancy: 1, occupants: [ { state: null, - uuid: "a3ffd012-a3b9-478c-8705-64089f24d71e" - } - ] - } + uuid: 'a3ffd012-a3b9-478c-8705-64089f24d71e', + }, + ], + }, }); assert.equal(scope.isDone(), true); done(); @@ -450,10 +454,10 @@ describe('presence endpoints', () => { assert(response !== null); assert.deepEqual(response.channels, { game1: { - name: "game1", + name: 'game1', occupancy: 1, - occupants: [] - } + occupants: [], + }, }); assert.equal(scope.isDone(), true); done(); @@ -483,15 +487,15 @@ describe('presence endpoints', () => { assert(response !== null); assert.deepEqual(response.channels, { game1: { - name: "game1", + name: 'game1', occupancy: 1, occupants: [ { state: null, - uuid: "a3ffd012-a3b9-478c-8705-64089f24d71e" - } - ] - } + uuid: 'a3ffd012-a3b9-478c-8705-64089f24d71e', + }, + ], + }, }); assert.equal(scope.isDone(), true); done(); @@ -522,26 +526,26 @@ describe('presence endpoints', () => { assert(response !== null); assert.deepEqual(response.channels, { ch1: { - name: "ch1", + name: 'ch1', occupancy: 1, occupants: [ { - uuid: "user1" - } - ] + uuid: 'user1', + }, + ], }, ch2: { - name: "ch2", + name: 'ch2', occupancy: 2, occupants: [ { - uuid: "user1" + uuid: 'user1', }, { - uuid: "user3" - } - ] - } + uuid: 'user3', + }, + ], + }, }); assert.equal(scope.isDone(), true); done(); @@ -572,15 +576,15 @@ describe('presence endpoints', () => { assert(response !== null); assert.deepEqual(response.channels, { ch1: { - name: "ch1", + name: 'ch1', occupancy: 1, - occupants: [] + occupants: [], }, ch2: { - name: "ch2", + name: 'ch2', occupancy: 2, - occupants: [] - } + occupants: [], + }, }); assert.equal(scope.isDone(), true); done(); @@ -611,15 +615,15 @@ describe('presence endpoints', () => { assert(response !== null); assert.deepEqual(response.channels, { ch1: { - name: "ch1", + name: 'ch1', occupancy: 1, occupants: [ { state: null, - uuid: "a581c974-e2f9-4088-9cc8-9632708e012d" - } - ] - } + uuid: 'a581c974-e2f9-4088-9cc8-9632708e012d', + }, + ], + }, }); assert.equal(response.totalChannels, 3); assert.equal(response.totalOccupancy, 7); @@ -651,25 +655,25 @@ describe('presence endpoints', () => { assert(response !== null); assert.deepEqual(response.channels, { bot_object: { - name: "bot_object", + name: 'bot_object', occupancy: 1, occupants: [ { state: null, - uuid: "fb49e109-756f-483e-92dc-d966d73a119d" - } - ] + uuid: 'fb49e109-756f-483e-92dc-d966d73a119d', + }, + ], }, ch10: { - name: "ch10", + name: 'ch10', occupancy: 1, occupants: [ { state: null, - uuid: "2c3b136e-dc9e-4e97-939c-752dbb47acbd" - } - ] - } + uuid: '2c3b136e-dc9e-4e97-939c-752dbb47acbd', + }, + ], + }, }); assert.equal(scope.isDone(), true); done(); @@ -700,15 +704,15 @@ describe('presence endpoints', () => { assert(response !== null); assert.deepEqual(response.channels, { bot_object: { - name: "bot_object", + name: 'bot_object', occupancy: 1, - occupants: [] + occupants: [], }, ch10: { - name: "ch10", + name: 'ch10', occupancy: 1, - occupants: [] - } + occupants: [], + }, }); assert.equal(scope.isDone(), true); done(); @@ -758,7 +762,7 @@ describe('presence endpoints', () => { }, ); - let expected = + const expected = 'This feature is not turned on for this account. Contact support@pubnub.com to activate this feature.'; pubnub.hereNow({ channels: [] }, (status) => { try { @@ -795,15 +799,15 @@ describe('presence endpoints', () => { assert(response !== null); assert.deepEqual(response.channels, { game1: { - name: "game1", + name: 'game1', occupancy: 1, occupants: [ { state: null, - uuid: "a3ffd012-a3b9-478c-8705-64089f24d71e" - } - ] - } + uuid: 'a3ffd012-a3b9-478c-8705-64089f24d71e', + }, + ], + }, }); assert.equal(scope.isDone(), true); done(); diff --git a/test/integration/endpoints/publish.test.ts b/test/integration/endpoints/publish.test.ts index 8e36af414..38c2072b3 100644 --- a/test/integration/endpoints/publish.test.ts +++ b/test/integration/endpoints/publish.test.ts @@ -15,10 +15,6 @@ describe('publish endpoints', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -32,6 +28,10 @@ describe('publish endpoints', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('##validation', () => { it('fails if channel is missing', (done) => { const scope = utils diff --git a/test/integration/endpoints/push.test.ts b/test/integration/endpoints/push.test.ts index 3cb11089d..0996afa78 100644 --- a/test/integration/endpoints/push.test.ts +++ b/test/integration/endpoints/push.test.ts @@ -14,10 +14,6 @@ describe('push endpoints', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -29,6 +25,10 @@ describe('push endpoints', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('adding channels to device', () => { it('supports addition of multiple channels for apple', (done) => { const scope = utils @@ -121,7 +121,7 @@ describe('push endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.channels, ["ch1", "ch2", "ch3"]); + assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -149,7 +149,7 @@ describe('push endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.channels, ["ch1", "ch2", "ch3"]); + assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -174,7 +174,7 @@ describe('push endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.channels, ["ch1", "ch2", "ch3"]); + assert.deepEqual(response.channels, ['ch1', 'ch2', 'ch3']); assert.equal(scope.isDone(), true); done(); } catch (error) { diff --git a/test/integration/endpoints/signal.test.ts b/test/integration/endpoints/signal.test.ts index c5c343599..4ba22d600 100644 --- a/test/integration/endpoints/signal.test.ts +++ b/test/integration/endpoints/signal.test.ts @@ -14,10 +14,6 @@ describe('signal endpoints', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -30,6 +26,10 @@ describe('signal endpoints', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('##validation', () => { it('fails if channel is missing', (done) => { const scope = utils diff --git a/test/integration/endpoints/subscribe.test.ts b/test/integration/endpoints/subscribe.test.ts index 2b4b3bad5..ae98ea527 100644 --- a/test/integration/endpoints/subscribe.test.ts +++ b/test/integration/endpoints/subscribe.test.ts @@ -16,10 +16,6 @@ describe('subscribe endpoints', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -50,8 +46,9 @@ describe('subscribe endpoints', () => { }); afterEach(() => { - pubnub.stop(); - pubnubWithFiltering.stop(); + pubnub.destroy(true); + pubnubWithFiltering.destroy(true); + pubnubWithEE.destroy(true); }); it('supports addition of multiple channels', (done) => { diff --git a/test/integration/endpoints/time.test.ts b/test/integration/endpoints/time.test.ts index 1b71fa05e..60910be8e 100644 --- a/test/integration/endpoints/time.test.ts +++ b/test/integration/endpoints/time.test.ts @@ -15,10 +15,6 @@ describe('time endpoints', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -29,6 +25,10 @@ describe('time endpoints', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + }); + it('calls the callback function when time is fetched', (done) => { utils.createNock().get('/time/0').query(true).reply(200, ['14570763868573725']); @@ -36,7 +36,7 @@ describe('time endpoints', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.timetoken, "14570763868573725"); + assert.deepEqual(response.timetoken, '14570763868573725'); done(); } catch (error) { done(error); @@ -77,7 +77,7 @@ describe('time endpoints', () => { pubnub.time().catch((ex) => { try { assert(ex instanceof PubNubError); - assert.equal(ex.message, "REST API request processing error, check status for details"); + assert.equal(ex.message, 'REST API request processing error, check status for details'); assert.equal(ex.status!.error, true); assert.equal(ex.status!.statusCode, 500); done(); diff --git a/test/integration/operations/heartbeat.test.ts b/test/integration/operations/heartbeat.test.ts index 1a9939b66..de59ab3e7 100644 --- a/test/integration/operations/heartbeat.test.ts +++ b/test/integration/operations/heartbeat.test.ts @@ -15,10 +15,6 @@ describe('heartbeat', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -34,12 +30,12 @@ describe('heartbeat', () => { afterEach(() => { pubnub.removeAllListeners(); - pubnub.stop(); + pubnub.destroy(true); }); describe('#heartbeat', () => { it('heartbeat loop should not get started when heartbeatInterval not set', async () => { - pubnub = new PubNub({ + const pubnubHB = new PubNub({ subscribeKey: 'mySubscribeKey', publishKey: 'myPublishKey', uuid: 'myUUID', @@ -58,8 +54,10 @@ describe('heartbeat', () => { .reply(200, '{"status": 200, "message": "OK", "service": "Presence"}', { 'content-type': 'text/javascript', }); - pubnub.subscribe({ channels: ['ch1', 'ch2'], withHeartbeats: true }); + pubnubHB.subscribe({ channels: ['ch1', 'ch2'], withHeartbeats: true }); await expect(scope).to.have.not.been.requested; + + pubnubHB.destroy(true); }); it('supports heartbeating for one channel', (done) => { diff --git a/test/integration/operations/stateSetting.test.ts b/test/integration/operations/stateSetting.test.ts index ced3d0e7e..619e7d4e1 100644 --- a/test/integration/operations/stateSetting.test.ts +++ b/test/integration/operations/stateSetting.test.ts @@ -14,10 +14,6 @@ describe('setting state operation', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -29,12 +25,16 @@ describe('setting state operation', () => { }); }); + afterEach(() => { + pubnub.destroy(true); + }); + describe('#setState', () => { it('fails if no channels are provided', (done) => { pubnub.setState({ state: { hello: 'there' } }, (status) => { try { assert.equal(status.error, true); - assert.equal(status.message, "Please provide a list of channels and/or channel-groups"); + assert.equal(status.message, 'Please provide a list of channels and/or channel-groups'); done(); } catch (error) { done(error); @@ -61,7 +61,7 @@ describe('setting state operation', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.deepEqual(response.state, { age: 20, status: 'online' }); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -89,7 +89,7 @@ describe('setting state operation', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.deepEqual(response.state, { age: 20, status: 'online' }); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -118,7 +118,7 @@ describe('setting state operation', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.deepEqual(response.state, { age: 20, status: 'online' }); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -147,7 +147,7 @@ describe('setting state operation', () => { try { assert.equal(status.error, false); assert(response !== null); - assert.deepEqual(response.state, { age: 20, status: "online" }); + assert.deepEqual(response.state, { age: 20, status: 'online' }); assert.equal(scope.isDone(), true); done(); } catch (error) { @@ -171,7 +171,7 @@ describe('setting state operation', () => { { 'content-type': 'text/javascript' }, ); - let promise = pubnub.setState({ + const promise = pubnub.setState({ channels: ['ch1'], state: { hello: 'there' }, }); diff --git a/test/integration/operations/unsubscribe.test.ts b/test/integration/operations/unsubscribe.test.ts index 982ebc093..f4843bc3c 100644 --- a/test/integration/operations/unsubscribe.test.ts +++ b/test/integration/operations/unsubscribe.test.ts @@ -14,10 +14,6 @@ describe('unsubscribe', () => { nock.disableNetConnect(); }); - after(() => { - nock.enableNetConnect(); - }); - beforeEach(() => { nock.cleanAll(); pubnub = new PubNub({ @@ -32,7 +28,7 @@ describe('unsubscribe', () => { afterEach(() => { pubnub.removeAllListeners(); - pubnub.stop(); + pubnub.destroy(true); }); describe('#unsubscribe', () => { diff --git a/test/setup-why.ts b/test/setup-why.ts new file mode 100644 index 000000000..bffde2f1f --- /dev/null +++ b/test/setup-why.ts @@ -0,0 +1,13 @@ +/* global after */ +import whyIsNodeRunning from 'why-is-node-running'; +import wtf from 'wtfnode'; +import nock from 'nock'; + +after(function () { + nock.enableNetConnect(); + nock.restore(); + setTimeout(() => { + // whyIsNodeRunning(); + wtf.dump(); + }, 1000); +}); diff --git a/test/unit/event_engine.test.ts b/test/unit/event_engine.test.ts index 28dd1edfd..66b2e1458 100644 --- a/test/unit/event_engine.test.ts +++ b/test/unit/event_engine.test.ts @@ -1,6 +1,6 @@ import nock from 'nock'; -import { Payload } from '../../src/core/types/api'; +import StatusCategory from '../../src/core/constants/categories'; import PubNub from '../../src/node/index'; import utils from '../utils'; @@ -42,6 +42,28 @@ describe('EventEngine', () => { unsub(); }); + function forStatus(statusCategory: StatusCategory, timeout?: number) { + return new Promise((resolve, reject) => { + let timeoutId: ReturnType; + + pubnub.addListener({ + status: (statusEvent) => { + if (statusEvent.category === statusCategory) { + pubnub.removeAllListeners(); + resolve(); + } + }, + }); + + if (timeout) { + timeoutId = setTimeout(() => { + pubnub.removeAllListeners(); + reject(new Error(`Timeout occurred while waiting for state ${statusCategory}`)); + }, timeout); + } + }); + } + function forEvent(eventLabel: string, timeout?: number) { return new Promise((resolve, reject) => { let timeoutId: NodeJS.Timeout | null = null; @@ -57,7 +79,7 @@ describe('EventEngine', () => { if (timeout) { timeoutId = setTimeout(() => { unsubscribe(); - reject(new Error(`Timeout occured while waiting for state ${eventLabel}`)); + reject(new Error(`Timeout occurred while waiting for state ${eventLabel}`)); }, timeout); } }); @@ -118,6 +140,33 @@ describe('EventEngine', () => { await forState('UNSUBSCRIBED', 1000); }); + it('should work correctly', async () => { + utils.createNock().get('/v2/subscribe/demo/test/0').query(true).reply(200, '{"t":{"t":"12345","r":1}, "m": []}'); + utils.createNock().get('/v2/subscribe/demo/test/0').query(true).reply(200, '{"t":{"t":"12345","r":1}, "m": []}'); + utils + .createNock() + .get('/v2/subscribe/demo/test,test1/0') + .query(true) + .reply(200, '{"t":{"t":"12345","r":1}, "m":[]}'); + utils + .createNock() + .get('/v2/subscribe/demo/test,test1/0') + .query(true) + .reply(200, '{"t":{"t":"12345","r":1}, "m":[]}'); + + pubnub.subscribe({ channels: ['test'] }); + + await forEvent('HANDSHAKE_SUCCESS', 1000); + + pubnub.subscribe({ channels: ['test1'] }); + + await forStatus(StatusCategory.PNSubscriptionChangedCategory); + + pubnub.unsubscribe({ channels: ['test', 'test1'] }); + + await forState('UNSUBSCRIBED', 1000); + }); + // TODO: retry with configuration // it('should retry correctly', async () => { // utils.createNock().get('/v2/subscribe/demo/test/0').query(true).reply(200, '{"t":{"t":"12345","r":1}, "m": []}'); From fc389df6cf6b346d00430a26289d03d093903dab Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 15 Apr 2025 13:41:49 +0300 Subject: [PATCH 48/49] Add missing new retry policy as static field of PubNub (#452) fix(interface): add missing new retry policy as static field of PubNub Add missing `NoneRetryPolicy` static field for `PubNub` class. --- .pubnub.yml | 13 ++++- CHANGELOG.md | 9 +++ README.md | 4 +- dist/web/pubnub.js | 85 +++++++++++++++++++++++++++- dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 3 +- lib/core/components/retryPolicy.js | 71 +++++++++++++++++++++++ lib/core/pubnub-common.js | 12 ++++ lib/types/index.d.ts | 71 +++++++++++++++++++++++ package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/components/retryPolicy.ts | 24 ++++---- src/core/pubnub-common.ts | 16 +++++- 13 files changed, 293 insertions(+), 23 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index e202fcdcc..c105a576e 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2025-04-15 + version: v9.5.1 + changes: + - type: bug + text: "Add missing `NoneRetryPolicy` static field for `PubNub` class." + - type: improvement + text: "`RetryPolicy.None` exported as a function to not affect tree-shaking and modules exclusion possibilities." - date: 2025-04-15 version: v9.5.0 changes: @@ -1222,7 +1229,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '9.5.0' +version: '9.5.1' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1238,7 +1245,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v9.5.0.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.5.1.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1909,7 +1916,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v9.5.0/pubnub.9.5.0.js + location: https://github.com/pubnub/javascript/releases/download/v9.5.1/pubnub.9.5.1.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index dedd3e023..2ee2df455 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v9.5.1 +April 15 2025 + +#### Fixed +- Add missing `NoneRetryPolicy` static field for `PubNub` class. + +#### Modified +- `RetryPolicy.None` exported as a function to not affect tree-shaking and modules exclusion possibilities. + ## v9.5.0 April 15 2025 diff --git a/README.md b/README.md index c24a6d91a..3519c7f62 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.0.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.0.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.1.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.1.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 6e6d50265..9531eb233 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3777,38 +3777,96 @@ Endpoint["Unknown"] = "UnknownEndpoint"; /** * The endpoints to send messages. + * + * This is related to the following functionality: + * - `publish` + * - `signal` + * - `publish file` + * - `fire` */ Endpoint["MessageSend"] = "MessageSendEndpoint"; /** * The endpoint for real-time update retrieval. + * + * This is related to the following functionality: + * - `subscribe` */ Endpoint["Subscribe"] = "SubscribeEndpoint"; /** * The endpoint to access and manage `user_id` presence and fetch channel presence information. + * + * This is related to the following functionality: + * - `get presence state` + * - `set presence state` + * - `here now` + * - `where now` + * - `heartbeat` */ Endpoint["Presence"] = "PresenceEndpoint"; /** * The endpoint to access and manage files in channel-specific storage. + * + * This is related to the following functionality: + * - `send file` + * - `download file` + * - `list files` + * - `delete file` */ Endpoint["Files"] = "FilesEndpoint"; /** * The endpoint to access and manage messages for a specific channel(s) in the persistent storage. + * + * This is related to the following functionality: + * - `fetch messages / message actions` + * - `delete messages` + * - `messages count` */ Endpoint["MessageStorage"] = "MessageStorageEndpoint"; /** * The endpoint to access and manage channel groups. + * + * This is related to the following functionality: + * - `add channels to group` + * - `list channels in group` + * - `remove channels from group` + * - `list channel groups` */ Endpoint["ChannelGroups"] = "ChannelGroupsEndpoint"; /** * The endpoint to access and manage device registration for channel push notifications. + * + * This is related to the following functionality: + * - `enable channels for push notifications` + * - `list push notification enabled channels` + * - `disable push notifications for channels` + * - `disable push notifications for all channels` */ Endpoint["DevicePushNotifications"] = "DevicePushNotificationsEndpoint"; /** * The endpoint to access and manage App Context objects. + * + * This is related to the following functionality: + * - `set UUID metadata` + * - `get UUID metadata` + * - `remove UUID metadata` + * - `get all UUID metadata` + * - `set Channel metadata` + * - `get Channel metadata` + * - `remove Channel metadata` + * - `get all Channel metadata` + * - `manage members` + * - `list members` + * - `manage memberships` + * - `list memberships` */ Endpoint["AppContext"] = "AppContextEndpoint"; /** * The endpoint to access and manage reactions for a specific message. + * + * This is related to the following functionality: + * - `add message action` + * - `get message actions` + * - `remove message action` */ Endpoint["MessageReactions"] = "MessageReactionsEndpoint"; })(Endpoint || (Endpoint = {})); @@ -3817,6 +3875,19 @@ * Failed request retry policy. */ class RetryPolicy { + static None() { + return { + shouldRetry(_request, _response, _errorCategory, _attempt) { + return false; + }, + getDelay(_attempt, _response) { + return -1; + }, + validate() { + return true; + }, + }; + } static LinearRetryPolicy(configuration) { var _a; return { @@ -4138,7 +4209,7 @@ return base.PubNubFile; }, get version() { - return '9.5.0'; + return '9.5.1'; }, getVersion() { return this.version; @@ -14648,6 +14719,11 @@ * API call status category. */ PubNubCore.CATEGORIES = StatusCategory$1; + /** + * Enum with API endpoint groups which can be used with retry policy to set up exclusions (which shouldn't be + * retried). + */ + PubNubCore.Endpoint = Endpoint; /** * Exponential retry policy constructor. */ @@ -14656,6 +14732,13 @@ * Linear retry policy constructor. */ PubNubCore.LinearRetryPolicy = RetryPolicy.LinearRetryPolicy; + /** + * Disabled / inactive retry policy. + * + * **Note:** By default `ExponentialRetryPolicy` is set for subscribe requests and this one can be used to disable + * retry policy for all requests (setting `undefined` for retry configuration will set default policy). + */ + PubNubCore.NoneRetryPolicy = RetryPolicy.None; /** * Cbor decoder module. diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index c6ccb7bd7..0a35f77f9 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)w+=d,S.push(u(d));var O=new Uint8Array(w),k=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNSubscriptionChangedCategory="PNSubscriptionChangedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,S,w=w||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=w).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=w,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],S=e[i+12],w=e[i+13],O=e[i+14],k=e[i+15],E=t(E=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,E,N,P,o,12,u[1]),P=t(P,C,E,N,l,17,u[2]),N=t(N,P,C,E,h,22,u[3]);E=t(E,N,P,C,d,7,u[4]),C=t(C,E,N,P,p,12,u[5]),P=t(P,C,E,N,g,17,u[6]),N=t(N,P,C,E,y,22,u[7]),E=t(E,N,P,C,f,7,u[8]),C=t(C,E,N,P,b,12,u[9]),P=t(P,C,E,N,m,17,u[10]),N=t(N,P,C,E,v,22,u[11]),E=t(E,N,P,C,S,7,u[12]),C=t(C,E,N,P,w,12,u[13]),P=t(P,C,E,N,O,17,u[14]),E=n(E,N=t(N,P,C,E,k,22,u[15]),P,C,o,5,u[16]),C=n(C,E,N,P,g,9,u[17]),P=n(P,C,E,N,v,14,u[18]),N=n(N,P,C,E,c,20,u[19]),E=n(E,N,P,C,p,5,u[20]),C=n(C,E,N,P,m,9,u[21]),P=n(P,C,E,N,k,14,u[22]),N=n(N,P,C,E,d,20,u[23]),E=n(E,N,P,C,b,5,u[24]),C=n(C,E,N,P,O,9,u[25]),P=n(P,C,E,N,h,14,u[26]),N=n(N,P,C,E,f,20,u[27]),E=n(E,N,P,C,w,5,u[28]),C=n(C,E,N,P,l,9,u[29]),P=n(P,C,E,N,y,14,u[30]),E=s(E,N=n(N,P,C,E,S,20,u[31]),P,C,p,4,u[32]),C=s(C,E,N,P,f,11,u[33]),P=s(P,C,E,N,v,16,u[34]),N=s(N,P,C,E,O,23,u[35]),E=s(E,N,P,C,o,4,u[36]),C=s(C,E,N,P,d,11,u[37]),P=s(P,C,E,N,y,16,u[38]),N=s(N,P,C,E,m,23,u[39]),E=s(E,N,P,C,w,4,u[40]),C=s(C,E,N,P,c,11,u[41]),P=s(P,C,E,N,h,16,u[42]),N=s(N,P,C,E,g,23,u[43]),E=s(E,N,P,C,b,4,u[44]),C=s(C,E,N,P,S,11,u[45]),P=s(P,C,E,N,k,16,u[46]),E=r(E,N=s(N,P,C,E,l,23,u[47]),P,C,c,6,u[48]),C=r(C,E,N,P,y,10,u[49]),P=r(P,C,E,N,O,15,u[50]),N=r(N,P,C,E,p,21,u[51]),E=r(E,N,P,C,S,6,u[52]),C=r(C,E,N,P,h,10,u[53]),P=r(P,C,E,N,m,15,u[54]),N=r(N,P,C,E,o,21,u[55]),E=r(E,N,P,C,f,6,u[56]),C=r(C,E,N,P,k,10,u[57]),P=r(P,C,E,N,g,15,u[58]),N=r(N,P,C,E,w,21,u[59]),E=r(E,N,P,C,d,6,u[60]),C=r(C,E,N,P,v,10,u[61]),P=r(P,C,E,N,l,15,u[62]),N=r(N,P,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=w,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=w,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],S=p[v],O=257*p[b]^16843008*b;i[y]=O<<24|O>>>8,a[y]=O<<16|O>>>16,o[y]=O<<8|O>>>24,c[y]=O,O=16843009*S^65537*v^257*m^16843008*y,u[b]=O<<24|O>>>8,l[b]=O<<16|O>>>16,h[b]=O<<8|O>>>24,d[b]=O,y?(y=m^p[p[p[S^m]]],f^=p[p[f]]):y=f=1}var k=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=k[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),w.mode.ECB=((S=w.lib.BlockCipherMode.extend()).Encryptor=S.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),S.Decryptor=S.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),S);var O=t(w);class k{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=O,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:k.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return k.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(k.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=k.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new k({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new k({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=j.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=j.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===j.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=j.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class j{static from(e,t){if(e!==j.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==j.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>j.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+j.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(s),a)}}j.SENTINEL="PNED",j.LEGACY_IDENTIFIER="",j.IDENTIFIER_LENGTH=4,j.VERSION=1,j.MAX_VERSION=1,j.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return j.VERSION}get length(){return j.SENTINEL.length+1+j.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(j.SENTINEL)),e+=j.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=j.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return A.isErrorObject(e)?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new A(n,t,0);if(e instanceof A)return e;if(A.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new A(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new A(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,A.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new A(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let S=!1,w=!0,O=5,k=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(S=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(O=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:S,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:O})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R;!function(e){e.Unknown="UnknownEndpoint",e.MessageSend="MessageSendEndpoint",e.Subscribe="SubscribeEndpoint",e.Presence="PresenceEndpoint",e.Files="FilesEndpoint",e.MessageStorage="MessageStorageEndpoint",e.ChannelGroups="ChannelGroupsEndpoint",e.DevicePushNotifications="DevicePushNotificationsEndpoint",e.AppContext="AppContextEndpoint",e.MessageReactions="MessageReactionsEndpoint"}(R||(R={}));class U{static LinearRetryPolicy(e){var t;return{delay:e.delay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=this.delay),1e3*(n+Math.random())},validate(){if(this.delay<2)throw new Error("Delay can not be set less than 2 seconds for retry");if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){var t;return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=Math.min(Math.pow(2,e),this.maximumDelay)),1e3*(n+Math.random())},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const x=(e,t,n,s,r,i)=>(!n||n!==h.PNCancelledCategory)&&(!D(e,i)&&(!(s>r)&&(!t||(429===t.status||t.status>=500)))),D=(e,t)=>!!(t&&t.length>0)&&t.includes(q(e)),q=e=>{let t=R.Unknown;return e.path.startsWith("/v2/subscribe")?t=R.Subscribe:e.path.startsWith("/publish/")||e.path.startsWith("/signal/")?t=R.MessageSend:e.path.startsWith("/v2/presence")?t=R.Presence:e.path.startsWith("/v2/history")||e.path.startsWith("/v3/history")?t=R.MessageStorage:e.path.startsWith("/v1/message-actions/")?t=R.MessageReactions:e.path.startsWith("/v1/channel-registration/")||e.path.startsWith("/v2/objects/")?t=R.ChannelGroups:e.path.startsWith("/v1/push/")||e.path.startsWith("/v2/push/")?t=R.DevicePushNotifications:e.path.startsWith("/v1/files/")&&(t=R.Files),t};var L={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(L,L.exports);var G=t(L.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var n,s,r;!e.retryConfiguration&&e.enableEventEngine&&(e.retryConfiguration=U.ExponentialRetryPolicy({minimumDelay:2,maximumDelay:150,maximumRetry:6,excluded:[R.MessageSend,R.Presence,R.Files,R.MessageStorage,R.ChannelGroups,R.DevicePushNotifications,R.AppContext,R.MessageReactions]})),null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=B(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.5.0"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},B=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class H{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var W;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(W||(W={}));const V=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),z=(e,t)=>{const n=e.map((e=>V(e)));return n.length?n.join(","):null!=t?t:""},J=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},X=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class Q{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?W.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===W.POST||t===W.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=Q.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${V(e)}`)).join("&"):`${t}=${V(n)}`})).join("&")}}Q.textDecoder=new TextDecoder("utf-8");class Y{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new Q(t.publishKey,t.secretKey,n))}makeSendable(e){const t=this.configuration.clientConfiguration.retryConfiguration,n=this.configuration.transport;if(void 0!==t){let s,r,i=!1,a=0;const o={abort:e=>{i=!0,s&&clearTimeout(s),r&&r.abort(e)}};return[new Promise(((o,c)=>{const u=()=>{if(i)return;const[l,d]=n.makeSendable(this.request(e));r=d;const p=(n,r)=>{const i=!r||r.category!==h.PNCancelledCategory,l=!n||n.status>=400;let d=-1;i&&l&&t.shouldRetry(e,n,null==r?void 0:r.category,a+1)&&(d=t.getDelay(a,n)),d>0?(a++,s=setTimeout((()=>u()),d)):n?o(n):r&&c(r)};l.then((e=>p(e))).catch((e=>p(void 0,e)))};u()})),r?o:void 0]}return n.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class Z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(Z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(Z.originalFetch=Z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(Z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw A.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw A.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([Z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else if(e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer))if(e.compressible&&"undefined"!=typeof CompressionStream){const n=new ReadableStream({start(t){t.enqueue("string"==typeof e.body?Z.encoder.encode(e.body):e.body),t.close()}});t=yield new Response(n.pipeThrough(new CompressionStream("deflate"))).arrayBuffer()}else t=e.body;var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${Z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${Z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}Z.encoder=new TextEncoder,Z.decoder=new TextDecoder;class ee{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class te{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class ne{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class re{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ie extends re{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class ae extends re{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class oe{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ie(this._payload.apns,e,t),this.fcm=new ae(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class ce{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s,r,i;const a={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:W.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,compressible:null!==(i=null===(r=this.params)||void 0===r?void 0:r.compressible)&&void 0!==i&&i,timeout:10,identifier:this.requestIdentifier},o=this.headers;if(o&&(a.headers=o),a.method===W.POST||a.method===W.PATCH){const[e,t]=[this.body,this.formData];t&&(a.formData=t),e&&(a.body=e)}return a}get headers(){var e,t;return Object.assign({"Accept-Encoding":"gzip, deflate"},null!==(t=null===(e=this.params)||void 0===e?void 0:e.compressible)&&void 0!==t&&t?{"Content-Encoding":"deflate"}:{})}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=ce.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw A.create(e);return s}}var ue;ce.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ue||(ue={}));var le=ue;var he;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(he||(he={}));class de extends ce{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return le.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=ce.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?he.Presence:he.Message),t!=he.Signal&&"string"==typeof e.d?t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}:t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:t===he.Presence?{type:he.Presence,data:this.presenceEventFromEnvelope(e)}:t==he.Signal?{type:he.Signal,data:this.signalFromEnvelope(e)}:t===he.AppContext?{type:he.AppContext,data:this.appContextFromEnvelope(e)}:t===he.MessageAction?{type:he.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{accept:"text/javascript"})}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(pe.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class pe extends de{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ge{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===he.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===he.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===he.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===he.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=K.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class ye{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class fe{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class be extends ye{describe(e){return new fe(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class me{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ve(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function Se(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function we(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class Oe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class ke extends ye{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new Oe}abort(){this._aborted=!0,this.notify(new Oe)}}class Ee{constructor(e,t){this.payload=e,this.dependencies=t}}class Ce extends Ee{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new ke}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Pe=e=>(t,n)=>new Ce(t,n,e),Ne=ve("RECONNECT",(()=>({}))),Me=ve("DISCONNECT",(e=>({isOffline:e}))),je=ve("JOINED",((e,t)=>({channels:e,groups:t}))),_e=ve("LEFT",((e,t)=>({channels:e,groups:t}))),Ae=ve("LEFT_ALL",(()=>({}))),Ie=ve("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Fe=ve("HEARTBEAT_FAILURE",(e=>e)),Te=ve("TIMES_UP",(()=>({}))),Re=we("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ue=Se("LEAVE",((e,t)=>({channels:e,groups:t}))),xe=Se("EMIT_STATUS",(e=>e)),De=we("WAIT",(()=>({})));class qe extends me{constructor(e,t){super(t),this.on(Re.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ie(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;e.transition(Fe(t))}}}))))),this.on(Ue.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(De.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Te())}))))),this.on(xe.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){s.announceFailedHeartbeats&&!0===(null==e?void 0:e.error)?n(Object.assign(Object.assign({},e),{operation:le.PNHeartbeatOperation})):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory}))})))))}}const Le=new fe("HEARTBEAT_STOPPED");Le.on(je.type,((e,t)=>Le.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(_e.type,((e,t)=>Le.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Le.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Le.on(Ae.type,((e,t)=>Be.with(void 0)));const Ge=new fe("HEARTBEAT_COOLDOWN");Ge.onEnter((()=>De())),Ge.onExit((()=>De.cancel)),Ge.on(Te.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ge.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ge.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const Ke=new fe("HEARTBEAT_FAILED");Ke.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ke.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ke.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const $e=new fe("HEARTBEATING");$e.onEnter((e=>Re(e.channels,e.groups))),$e.onExit((()=>Re.cancel)),$e.on(Ie.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups},[xe(Object.assign({},t.payload))]))),$e.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),$e.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),$e.on(Fe.type,((e,t)=>Ke.with(Object.assign({},e),[...t.payload.status?[xe(Object.assign({},t.payload.status))]:[]]))),$e.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),$e.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const Be=new fe("HEARTBEAT_INACTIVE");Be.on(je.type,((e,t)=>$e.with({channels:t.payload.channels,groups:t.payload.groups})));class He{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new be,this.channels=[],this.groups=[],this.dispatcher=new qe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Be,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(je(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(_e(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ae())}reconnect(){this.engine.transition(Ne())}disconnect(e){this.engine.transition(Me(e))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}const We=we("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=we("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),ze=Se("EMIT_MESSAGES",(e=>e)),Je=Se("EMIT_STATUS",(e=>e)),Xe=ve("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=ve("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ye=ve("HANDSHAKE_SUCCESS",(e=>e)),Ze=ve("HANDSHAKE_FAILURE",(e=>e)),et=ve("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),tt=ve("RECEIVE_FAILURE",(e=>e)),nt=ve("DISCONNECT",(e=>({isOffline:e}))),st=ve("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),rt=ve("UNSUBSCRIBE_ALL",(()=>({})));class it extends me{constructor(e,t){super(t),this.on(We.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(Ve.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(et(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(tt(t))}}}))))),this.on(ze.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(Je.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){return n(e)})))))}}const at=new fe("HANDSHAKE_STOPPED");at.on(Xe.type,((e,{payload:t})=>at.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),at.on(st.type,((e,{payload:t})=>ht.with(Object.assign(Object.assign({},e),{cursor:t.cursor||e.cursor})))),at.on(Qe.type,((e,{payload:t})=>{var n;return at.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=e.cursor)||void 0===n?void 0:n.region)||0}})})),at.on(rt.type,(e=>dt.with()));const ot=new fe("HANDSHAKE_FAILED");ot.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ot.on(st.type,((e,{payload:t})=>ht.with({channels:e.channels,groups:e.groups,cursor:t.cursor||e.cursor}))),ot.on(Qe.type,((e,{payload:t})=>{var n,s;return ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region?t.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),ot.on(rt.type,(e=>dt.with()));const ct=new fe("RECEIVE_STOPPED");ct.on(Xe.type,((e,{payload:t})=>ct.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ct.on(Qe.type,((e,{payload:t})=>ct.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ct.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ct.on(rt.type,(()=>dt.with(void 0)));const ut=new fe("RECEIVE_FAILED");ut.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ut.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ut.on(Qe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ut.on(rt.type,(e=>dt.with(void 0)));const lt=new fe("RECEIVING");lt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),lt.onExit((()=>Ve.cancel)),lt.on(et.type,((e,{payload:t})=>lt.with({channels:e.channels,groups:e.groups,cursor:t.cursor},[ze(t.events)]))),lt.on(Xe.type,((e,{payload:t})=>{const n={category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0)};return 0===t.channels.length&&0===t.groups.length?dt.with(void 0,[Je(n)]):lt.with({channels:t.channels,groups:t.groups,cursor:e.cursor},[Je(n)])})),lt.on(Qe.type,((e,{payload:t})=>{const n={category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0)};return 0===t.channels.length&&0===t.groups.length?dt.with(void 0,[Je(n)]):lt.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}},[Je(n)])})),lt.on(tt.type,((e,{payload:t})=>{var n;return ut.with(Object.assign(Object.assign({},e),{reason:t}),[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])})),lt.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=A.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ut.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return ct.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Je({category:h.PNDisconnectedCategory})])})),lt.on(rt.type,(e=>dt.with(void 0,[Je({category:h.PNDisconnectedCategory})])));const ht=new fe("HANDSHAKING");ht.onEnter((e=>We(e.channels,e.groups))),ht.onExit((()=>We.cancel)),ht.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ht.on(Ye.type,((e,{payload:t})=>{var n,s;return lt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.timetoken,region:t.region}},[Je({category:h.PNConnectedCategory})])})),ht.on(Ze.type,((e,t)=>{var n;return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t.payload},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.payload.status)||void 0===n?void 0:n.category})])})),ht.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=A.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return at.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),ht.on(Qe.type,((e,{payload:t})=>{var n;return ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),ht.on(rt.type,(e=>dt.with()));const dt=new fe("UNSUBSCRIBED");dt.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups}))),dt.on(Qe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:t.cursor})));class pt{get _engine(){return this.engine}constructor(e){this.engine=new be,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new it(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(dt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=J(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=J(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=X(this.channels,e),i=X(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Xe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Xe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}reconnect({timetoken:e,region:t}){const n=this.getSubscribedChannels(),s=this.getSubscribedChannels();this.engine.transition(st(e,t)),this.dependencies.presenceReconnect&&this.dependencies.presenceReconnect({channels:s,groups:n})}disconnect(e){const t=this.getSubscribedChannels(),n=this.getSubscribedChannels();this.engine.transition(nt(e)),this.dependencies.presenceDisconnect&&this.dependencies.presenceDisconnect({channels:n,groups:t,isOffline:e})}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}class gt extends ce{constructor(e){var t;const n=null!==(t=e.sendByPost)&&void 0!==t&&t;super({method:n?W.POST:W.GET,compressible:n}),this.parameters=e,this.parameters.sendByPost=n}operation(){return le.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${V(t)}/0${this.parameters.sendByPost?"":`/${V(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){var e;if(this.parameters.sendByPost)return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class yt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${V(n)}/0/${V(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class ft extends de{operation(){return le.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class bt extends de{operation(){return le.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class mt extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return le.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${V(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class St extends ce{constructor(e){super({cancellable:!0}),this.parameters=e}operation(){return le.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class wt extends ce{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return le.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class Ot extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${V(t)}`}}class kt extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?le.PNGlobalHereNowOperation:le.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${z(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Et extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ct extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${z(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Pt extends ce{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return le.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Pt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Nt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Nt||(Nt={}));class Mt extends ce{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return le.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Nt.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${z(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Mt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Nt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class _t extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${n}`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify(this.parameters.action)}}class At extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${s}/action/${n}`}}class It extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return le.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${V(t)}/0/${V(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ft extends ce{constructor(e){super({method:W.LOCAL}),this.parameters=e}operation(){return le.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${V(e)}/files/${t}/${n}`}}class Tt extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(n)}/files/${t}/${s}`}}class Rt extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return le.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ut extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/generate-upload-url`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify({name:this.parameters.name})}}class xt extends ce{constructor(e){super({method:W.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return le.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?xt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Dt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:le.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(le.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ut(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new xt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class qt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Lt extends qt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Gt extends qt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Lt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Kt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class $t{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Bt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Ht{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Wt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class Vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class zt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}}class Jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}/remove`}}class Xt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class Qt{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new Xt({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Vt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Wt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new Jt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class Yt extends ce{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class Zt extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return le.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class en extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return le.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class tn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return le.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class nn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return le.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class sn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new en(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class rn extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return le.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class an extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}}class on extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class cn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class un extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return le.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ln extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class hn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class dn extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}}class pn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class yn extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class fn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new un(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new yn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new fn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new dn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new rn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new an(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new pn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new on(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class mn extends ce{constructor(){super()}operation(){return le.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class vn extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files/${n}/${s}`}}class Sn{static notificationPayload(e,t){return new oe(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new bn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new Qt(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new sn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new ee,this.eventEmitter=new ge(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new He({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new pt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceReconnect:this.presenceReconnect.bind(this),presenceDisconnect:this.presenceDisconnect.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new se(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Ht(e,this.eventEmitter,this)}channelGroup(e){return new $t(e,this.eventEmitter,this)}channelMetadata(e){return new Kt(e,this.eventEmitter,this)}userMetadata(e){return new Bt(e,this.eventEmitter,this)}subscriptionSet(e){return new Lt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===le.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===le.PNSubscribeOperation||r===le.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=Sn.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof A?e:A.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose(),this.presenceEventEngine&&this.presenceEventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new yt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new pe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:le.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new wt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(e){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect(e)}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Ot({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new mt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new St(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new vt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new St(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){this.presenceEventEngine?this.presenceEventEngine.join(e):this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}presenceReconnect(e){this.presenceEventEngine?this.presenceEventEngine.reconnect():this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}leave(e){var t;this.presenceEventEngine?null===(t=this.presenceEventEngine)||void 0===t||t.leave(e):this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}leaveAll(e){this.presenceEventEngine?this.presenceEventEngine.leaveAll():this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}presenceDisconnect(e){this.presenceEventEngine?this.presenceEventEngine.disconnect(e.isOffline):e.isOffline||this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:le.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof A&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new vn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new mn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}Sn.decoder=new TextDecoder,Sn.OPERATIONS=le,Sn.CATEGORIES=h,Sn.ExponentialRetryPolicy=U.ExponentialRetryPolicy,Sn.LinearRetryPolicy=U.LinearRetryPolicy;class wn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class On extends Sn{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=$(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new k({cipherKey:e.cipherKey})]})}));let a,u,l;a=new H(new wn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new Z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new Y({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect(!0):this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return On.CryptoModule=M,On})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)w+=d,S.push(u(d));var O=new Uint8Array(w),k=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNSubscriptionChangedCategory="PNSubscriptionChangedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,S,w=w||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=w).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=w,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],S=e[i+12],w=e[i+13],O=e[i+14],k=e[i+15],E=t(E=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,E,N,P,o,12,u[1]),P=t(P,C,E,N,l,17,u[2]),N=t(N,P,C,E,h,22,u[3]);E=t(E,N,P,C,d,7,u[4]),C=t(C,E,N,P,p,12,u[5]),P=t(P,C,E,N,g,17,u[6]),N=t(N,P,C,E,y,22,u[7]),E=t(E,N,P,C,f,7,u[8]),C=t(C,E,N,P,b,12,u[9]),P=t(P,C,E,N,m,17,u[10]),N=t(N,P,C,E,v,22,u[11]),E=t(E,N,P,C,S,7,u[12]),C=t(C,E,N,P,w,12,u[13]),P=t(P,C,E,N,O,17,u[14]),E=n(E,N=t(N,P,C,E,k,22,u[15]),P,C,o,5,u[16]),C=n(C,E,N,P,g,9,u[17]),P=n(P,C,E,N,v,14,u[18]),N=n(N,P,C,E,c,20,u[19]),E=n(E,N,P,C,p,5,u[20]),C=n(C,E,N,P,m,9,u[21]),P=n(P,C,E,N,k,14,u[22]),N=n(N,P,C,E,d,20,u[23]),E=n(E,N,P,C,b,5,u[24]),C=n(C,E,N,P,O,9,u[25]),P=n(P,C,E,N,h,14,u[26]),N=n(N,P,C,E,f,20,u[27]),E=n(E,N,P,C,w,5,u[28]),C=n(C,E,N,P,l,9,u[29]),P=n(P,C,E,N,y,14,u[30]),E=s(E,N=n(N,P,C,E,S,20,u[31]),P,C,p,4,u[32]),C=s(C,E,N,P,f,11,u[33]),P=s(P,C,E,N,v,16,u[34]),N=s(N,P,C,E,O,23,u[35]),E=s(E,N,P,C,o,4,u[36]),C=s(C,E,N,P,d,11,u[37]),P=s(P,C,E,N,y,16,u[38]),N=s(N,P,C,E,m,23,u[39]),E=s(E,N,P,C,w,4,u[40]),C=s(C,E,N,P,c,11,u[41]),P=s(P,C,E,N,h,16,u[42]),N=s(N,P,C,E,g,23,u[43]),E=s(E,N,P,C,b,4,u[44]),C=s(C,E,N,P,S,11,u[45]),P=s(P,C,E,N,k,16,u[46]),E=r(E,N=s(N,P,C,E,l,23,u[47]),P,C,c,6,u[48]),C=r(C,E,N,P,y,10,u[49]),P=r(P,C,E,N,O,15,u[50]),N=r(N,P,C,E,p,21,u[51]),E=r(E,N,P,C,S,6,u[52]),C=r(C,E,N,P,h,10,u[53]),P=r(P,C,E,N,m,15,u[54]),N=r(N,P,C,E,o,21,u[55]),E=r(E,N,P,C,f,6,u[56]),C=r(C,E,N,P,k,10,u[57]),P=r(P,C,E,N,g,15,u[58]),N=r(N,P,C,E,w,21,u[59]),E=r(E,N,P,C,d,6,u[60]),C=r(C,E,N,P,v,10,u[61]),P=r(P,C,E,N,l,15,u[62]),N=r(N,P,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=w,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=w,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],S=p[v],O=257*p[b]^16843008*b;i[y]=O<<24|O>>>8,a[y]=O<<16|O>>>16,o[y]=O<<8|O>>>24,c[y]=O,O=16843009*S^65537*v^257*m^16843008*y,u[b]=O<<24|O>>>8,l[b]=O<<16|O>>>16,h[b]=O<<8|O>>>24,d[b]=O,y?(y=m^p[p[p[S^m]]],f^=p[p[f]]):y=f=1}var k=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=k[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),w.mode.ECB=((S=w.lib.BlockCipherMode.extend()).Encryptor=S.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),S.Decryptor=S.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),S);var O=t(w);class k{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=O,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:k.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return k.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(k.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=k.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new k({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new k({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=j.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=j.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===j.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=j.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class j{static from(e,t){if(e!==j.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==j.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>j.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+j.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(s),a)}}j.SENTINEL="PNED",j.LEGACY_IDENTIFIER="",j.IDENTIFIER_LENGTH=4,j.VERSION=1,j.MAX_VERSION=1,j.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return j.VERSION}get length(){return j.SENTINEL.length+1+j.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(j.SENTINEL)),e+=j.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=j.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return A.isErrorObject(e)?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new A(n,t,0);if(e instanceof A)return e;if(A.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new A(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new A(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,A.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new A(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let S=!1,w=!0,O=5,k=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(S=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(O=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:S,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:O})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R;!function(e){e.Unknown="UnknownEndpoint",e.MessageSend="MessageSendEndpoint",e.Subscribe="SubscribeEndpoint",e.Presence="PresenceEndpoint",e.Files="FilesEndpoint",e.MessageStorage="MessageStorageEndpoint",e.ChannelGroups="ChannelGroupsEndpoint",e.DevicePushNotifications="DevicePushNotificationsEndpoint",e.AppContext="AppContextEndpoint",e.MessageReactions="MessageReactionsEndpoint"}(R||(R={}));class U{static None(){return{shouldRetry:(e,t,n,s)=>!1,getDelay:(e,t)=>-1,validate:()=>!0}}static LinearRetryPolicy(e){var t;return{delay:e.delay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=this.delay),1e3*(n+Math.random())},validate(){if(this.delay<2)throw new Error("Delay can not be set less than 2 seconds for retry");if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){var t;return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=Math.min(Math.pow(2,e),this.maximumDelay)),1e3*(n+Math.random())},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const x=(e,t,n,s,r,i)=>(!n||n!==h.PNCancelledCategory)&&(!D(e,i)&&(!(s>r)&&(!t||(429===t.status||t.status>=500)))),D=(e,t)=>!!(t&&t.length>0)&&t.includes(q(e)),q=e=>{let t=R.Unknown;return e.path.startsWith("/v2/subscribe")?t=R.Subscribe:e.path.startsWith("/publish/")||e.path.startsWith("/signal/")?t=R.MessageSend:e.path.startsWith("/v2/presence")?t=R.Presence:e.path.startsWith("/v2/history")||e.path.startsWith("/v3/history")?t=R.MessageStorage:e.path.startsWith("/v1/message-actions/")?t=R.MessageReactions:e.path.startsWith("/v1/channel-registration/")||e.path.startsWith("/v2/objects/")?t=R.ChannelGroups:e.path.startsWith("/v1/push/")||e.path.startsWith("/v2/push/")?t=R.DevicePushNotifications:e.path.startsWith("/v1/files/")&&(t=R.Files),t};var L={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(L,L.exports);var G=t(L.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var n,s,r;!e.retryConfiguration&&e.enableEventEngine&&(e.retryConfiguration=U.ExponentialRetryPolicy({minimumDelay:2,maximumDelay:150,maximumRetry:6,excluded:[R.MessageSend,R.Presence,R.Files,R.MessageStorage,R.ChannelGroups,R.DevicePushNotifications,R.AppContext,R.MessageReactions]})),null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=B(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.5.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},B=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class H{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var W;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(W||(W={}));const V=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),z=(e,t)=>{const n=e.map((e=>V(e)));return n.length?n.join(","):null!=t?t:""},J=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},X=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class Q{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?W.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===W.POST||t===W.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=Q.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${V(e)}`)).join("&"):`${t}=${V(n)}`})).join("&")}}Q.textDecoder=new TextDecoder("utf-8");class Y{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new Q(t.publishKey,t.secretKey,n))}makeSendable(e){const t=this.configuration.clientConfiguration.retryConfiguration,n=this.configuration.transport;if(void 0!==t){let s,r,i=!1,a=0;const o={abort:e=>{i=!0,s&&clearTimeout(s),r&&r.abort(e)}};return[new Promise(((o,c)=>{const u=()=>{if(i)return;const[l,d]=n.makeSendable(this.request(e));r=d;const p=(n,r)=>{const i=!r||r.category!==h.PNCancelledCategory,l=!n||n.status>=400;let d=-1;i&&l&&t.shouldRetry(e,n,null==r?void 0:r.category,a+1)&&(d=t.getDelay(a,n)),d>0?(a++,s=setTimeout((()=>u()),d)):n?o(n):r&&c(r)};l.then((e=>p(e))).catch((e=>p(void 0,e)))};u()})),r?o:void 0]}return n.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class Z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(Z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(Z.originalFetch=Z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(Z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw A.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw A.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([Z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else if(e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer))if(e.compressible&&"undefined"!=typeof CompressionStream){const n=new ReadableStream({start(t){t.enqueue("string"==typeof e.body?Z.encoder.encode(e.body):e.body),t.close()}});t=yield new Response(n.pipeThrough(new CompressionStream("deflate"))).arrayBuffer()}else t=e.body;var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${Z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${Z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}Z.encoder=new TextEncoder,Z.decoder=new TextDecoder;class ee{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class te{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class ne{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class re{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ie extends re{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class ae extends re{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class oe{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ie(this._payload.apns,e,t),this.fcm=new ae(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class ce{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s,r,i;const a={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:W.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,compressible:null!==(i=null===(r=this.params)||void 0===r?void 0:r.compressible)&&void 0!==i&&i,timeout:10,identifier:this.requestIdentifier},o=this.headers;if(o&&(a.headers=o),a.method===W.POST||a.method===W.PATCH){const[e,t]=[this.body,this.formData];t&&(a.formData=t),e&&(a.body=e)}return a}get headers(){var e,t;return Object.assign({"Accept-Encoding":"gzip, deflate"},null!==(t=null===(e=this.params)||void 0===e?void 0:e.compressible)&&void 0!==t&&t?{"Content-Encoding":"deflate"}:{})}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=ce.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw A.create(e);return s}}var ue;ce.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ue||(ue={}));var le=ue;var he;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(he||(he={}));class de extends ce{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return le.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=ce.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?he.Presence:he.Message),t!=he.Signal&&"string"==typeof e.d?t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}:t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:t===he.Presence?{type:he.Presence,data:this.presenceEventFromEnvelope(e)}:t==he.Signal?{type:he.Signal,data:this.signalFromEnvelope(e)}:t===he.AppContext?{type:he.AppContext,data:this.appContextFromEnvelope(e)}:t===he.MessageAction?{type:he.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{accept:"text/javascript"})}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(pe.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class pe extends de{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ge{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===he.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===he.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===he.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===he.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=K.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class ye{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class fe{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class be extends ye{describe(e){return new fe(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class me{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ve(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function Se(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function we(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class Oe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class ke extends ye{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new Oe}abort(){this._aborted=!0,this.notify(new Oe)}}class Ee{constructor(e,t){this.payload=e,this.dependencies=t}}class Ce extends Ee{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new ke}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Pe=e=>(t,n)=>new Ce(t,n,e),Ne=ve("RECONNECT",(()=>({}))),Me=ve("DISCONNECT",(e=>({isOffline:e}))),je=ve("JOINED",((e,t)=>({channels:e,groups:t}))),_e=ve("LEFT",((e,t)=>({channels:e,groups:t}))),Ae=ve("LEFT_ALL",(()=>({}))),Ie=ve("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Fe=ve("HEARTBEAT_FAILURE",(e=>e)),Te=ve("TIMES_UP",(()=>({}))),Re=we("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ue=Se("LEAVE",((e,t)=>({channels:e,groups:t}))),xe=Se("EMIT_STATUS",(e=>e)),De=we("WAIT",(()=>({})));class qe extends me{constructor(e,t){super(t),this.on(Re.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ie(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;e.transition(Fe(t))}}}))))),this.on(Ue.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(De.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Te())}))))),this.on(xe.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){s.announceFailedHeartbeats&&!0===(null==e?void 0:e.error)?n(Object.assign(Object.assign({},e),{operation:le.PNHeartbeatOperation})):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory}))})))))}}const Le=new fe("HEARTBEAT_STOPPED");Le.on(je.type,((e,t)=>Le.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(_e.type,((e,t)=>Le.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Le.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Le.on(Ae.type,((e,t)=>Be.with(void 0)));const Ge=new fe("HEARTBEAT_COOLDOWN");Ge.onEnter((()=>De())),Ge.onExit((()=>De.cancel)),Ge.on(Te.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ge.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ge.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const Ke=new fe("HEARTBEAT_FAILED");Ke.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ke.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ke.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const $e=new fe("HEARTBEATING");$e.onEnter((e=>Re(e.channels,e.groups))),$e.onExit((()=>Re.cancel)),$e.on(Ie.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups},[xe(Object.assign({},t.payload))]))),$e.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),$e.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),$e.on(Fe.type,((e,t)=>Ke.with(Object.assign({},e),[...t.payload.status?[xe(Object.assign({},t.payload.status))]:[]]))),$e.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),$e.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const Be=new fe("HEARTBEAT_INACTIVE");Be.on(je.type,((e,t)=>$e.with({channels:t.payload.channels,groups:t.payload.groups})));class He{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new be,this.channels=[],this.groups=[],this.dispatcher=new qe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Be,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(je(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(_e(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ae())}reconnect(){this.engine.transition(Ne())}disconnect(e){this.engine.transition(Me(e))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}const We=we("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=we("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),ze=Se("EMIT_MESSAGES",(e=>e)),Je=Se("EMIT_STATUS",(e=>e)),Xe=ve("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=ve("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ye=ve("HANDSHAKE_SUCCESS",(e=>e)),Ze=ve("HANDSHAKE_FAILURE",(e=>e)),et=ve("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),tt=ve("RECEIVE_FAILURE",(e=>e)),nt=ve("DISCONNECT",(e=>({isOffline:e}))),st=ve("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),rt=ve("UNSUBSCRIBE_ALL",(()=>({})));class it extends me{constructor(e,t){super(t),this.on(We.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(Ve.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(et(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(tt(t))}}}))))),this.on(ze.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(Je.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){return n(e)})))))}}const at=new fe("HANDSHAKE_STOPPED");at.on(Xe.type,((e,{payload:t})=>at.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),at.on(st.type,((e,{payload:t})=>ht.with(Object.assign(Object.assign({},e),{cursor:t.cursor||e.cursor})))),at.on(Qe.type,((e,{payload:t})=>{var n;return at.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=e.cursor)||void 0===n?void 0:n.region)||0}})})),at.on(rt.type,(e=>dt.with()));const ot=new fe("HANDSHAKE_FAILED");ot.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ot.on(st.type,((e,{payload:t})=>ht.with({channels:e.channels,groups:e.groups,cursor:t.cursor||e.cursor}))),ot.on(Qe.type,((e,{payload:t})=>{var n,s;return ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region?t.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),ot.on(rt.type,(e=>dt.with()));const ct=new fe("RECEIVE_STOPPED");ct.on(Xe.type,((e,{payload:t})=>ct.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ct.on(Qe.type,((e,{payload:t})=>ct.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ct.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ct.on(rt.type,(()=>dt.with(void 0)));const ut=new fe("RECEIVE_FAILED");ut.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ut.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ut.on(Qe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ut.on(rt.type,(e=>dt.with(void 0)));const lt=new fe("RECEIVING");lt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),lt.onExit((()=>Ve.cancel)),lt.on(et.type,((e,{payload:t})=>lt.with({channels:e.channels,groups:e.groups,cursor:t.cursor},[ze(t.events)]))),lt.on(Xe.type,((e,{payload:t})=>{const n={category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0)};return 0===t.channels.length&&0===t.groups.length?dt.with(void 0,[Je(n)]):lt.with({channels:t.channels,groups:t.groups,cursor:e.cursor},[Je(n)])})),lt.on(Qe.type,((e,{payload:t})=>{const n={category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0)};return 0===t.channels.length&&0===t.groups.length?dt.with(void 0,[Je(n)]):lt.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}},[Je(n)])})),lt.on(tt.type,((e,{payload:t})=>{var n;return ut.with(Object.assign(Object.assign({},e),{reason:t}),[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])})),lt.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=A.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ut.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return ct.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Je({category:h.PNDisconnectedCategory})])})),lt.on(rt.type,(e=>dt.with(void 0,[Je({category:h.PNDisconnectedCategory})])));const ht=new fe("HANDSHAKING");ht.onEnter((e=>We(e.channels,e.groups))),ht.onExit((()=>We.cancel)),ht.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ht.on(Ye.type,((e,{payload:t})=>{var n,s;return lt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.timetoken,region:t.region}},[Je({category:h.PNConnectedCategory})])})),ht.on(Ze.type,((e,t)=>{var n;return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t.payload},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.payload.status)||void 0===n?void 0:n.category})])})),ht.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=A.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return at.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),ht.on(Qe.type,((e,{payload:t})=>{var n;return ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),ht.on(rt.type,(e=>dt.with()));const dt=new fe("UNSUBSCRIBED");dt.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups}))),dt.on(Qe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:t.cursor})));class pt{get _engine(){return this.engine}constructor(e){this.engine=new be,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new it(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(dt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=J(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=J(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=X(this.channels,e),i=X(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Xe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Xe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}reconnect({timetoken:e,region:t}){const n=this.getSubscribedChannels(),s=this.getSubscribedChannels();this.engine.transition(st(e,t)),this.dependencies.presenceReconnect&&this.dependencies.presenceReconnect({channels:s,groups:n})}disconnect(e){const t=this.getSubscribedChannels(),n=this.getSubscribedChannels();this.engine.transition(nt(e)),this.dependencies.presenceDisconnect&&this.dependencies.presenceDisconnect({channels:n,groups:t,isOffline:e})}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}class gt extends ce{constructor(e){var t;const n=null!==(t=e.sendByPost)&&void 0!==t&&t;super({method:n?W.POST:W.GET,compressible:n}),this.parameters=e,this.parameters.sendByPost=n}operation(){return le.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${V(t)}/0${this.parameters.sendByPost?"":`/${V(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){var e;if(this.parameters.sendByPost)return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class yt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${V(n)}/0/${V(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class ft extends de{operation(){return le.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class bt extends de{operation(){return le.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class mt extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return le.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${V(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class St extends ce{constructor(e){super({cancellable:!0}),this.parameters=e}operation(){return le.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class wt extends ce{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return le.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class Ot extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${V(t)}`}}class kt extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?le.PNGlobalHereNowOperation:le.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${z(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Et extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ct extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${z(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Pt extends ce{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return le.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Pt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Nt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Nt||(Nt={}));class Mt extends ce{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return le.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Nt.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${z(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Mt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Nt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class _t extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${n}`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify(this.parameters.action)}}class At extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${s}/action/${n}`}}class It extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return le.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${V(t)}/0/${V(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ft extends ce{constructor(e){super({method:W.LOCAL}),this.parameters=e}operation(){return le.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${V(e)}/files/${t}/${n}`}}class Tt extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(n)}/files/${t}/${s}`}}class Rt extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return le.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ut extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/generate-upload-url`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify({name:this.parameters.name})}}class xt extends ce{constructor(e){super({method:W.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return le.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?xt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Dt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:le.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(le.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ut(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new xt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class qt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Lt extends qt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Gt extends qt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Lt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Kt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class $t{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Bt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Ht{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Wt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class Vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class zt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}}class Jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}/remove`}}class Xt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class Qt{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new Xt({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Vt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Wt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new Jt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class Yt extends ce{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class Zt extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return le.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class en extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return le.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class tn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return le.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class nn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return le.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class sn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new en(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class rn extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return le.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class an extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}}class on extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class cn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class un extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return le.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ln extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class hn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class dn extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}}class pn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class yn extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class fn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new un(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new yn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new fn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new dn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new rn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new an(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new pn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new on(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class mn extends ce{constructor(){super()}operation(){return le.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class vn extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files/${n}/${s}`}}class Sn{static notificationPayload(e,t){return new oe(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new bn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new Qt(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new sn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new ee,this.eventEmitter=new ge(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new He({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new pt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceReconnect:this.presenceReconnect.bind(this),presenceDisconnect:this.presenceDisconnect.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new se(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Ht(e,this.eventEmitter,this)}channelGroup(e){return new $t(e,this.eventEmitter,this)}channelMetadata(e){return new Kt(e,this.eventEmitter,this)}userMetadata(e){return new Bt(e,this.eventEmitter,this)}subscriptionSet(e){return new Lt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===le.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===le.PNSubscribeOperation||r===le.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=Sn.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof A?e:A.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose(),this.presenceEventEngine&&this.presenceEventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new yt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new pe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:le.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new wt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(e){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect(e)}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Ot({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new mt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new St(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new vt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new St(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){this.presenceEventEngine?this.presenceEventEngine.join(e):this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}presenceReconnect(e){this.presenceEventEngine?this.presenceEventEngine.reconnect():this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}leave(e){var t;this.presenceEventEngine?null===(t=this.presenceEventEngine)||void 0===t||t.leave(e):this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}leaveAll(e){this.presenceEventEngine?this.presenceEventEngine.leaveAll():this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}presenceDisconnect(e){this.presenceEventEngine?this.presenceEventEngine.disconnect(e.isOffline):e.isOffline||this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:le.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof A&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new vn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new mn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}Sn.decoder=new TextDecoder,Sn.OPERATIONS=le,Sn.CATEGORIES=h,Sn.Endpoint=R,Sn.ExponentialRetryPolicy=U.ExponentialRetryPolicy,Sn.LinearRetryPolicy=U.LinearRetryPolicy,Sn.NoneRetryPolicy=U.None;class wn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class On extends Sn{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=$(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new k({cipherKey:e.cipherKey})]})}));let a,u,l;a=new H(new wn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new Z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new Y({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect(!0):this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return On.CryptoModule=M,On})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 9741d5d21..76d7902d1 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -35,6 +35,7 @@ const makeConfiguration = (base, setupCryptoModule) => { var _a, _b, _c; // Set default retry policy for subscribe (if new subscribe logic not used). if (!base.retryConfiguration && base.enableEventEngine) { + const s = retryPolicy_1.RetryPolicy.None; base.retryConfiguration = retryPolicy_1.RetryPolicy.ExponentialRetryPolicy({ minimumDelay: 2, maximumDelay: 150, @@ -143,7 +144,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '9.5.0'; + return '9.5.1'; }, getVersion() { return this.version; diff --git a/lib/core/components/retryPolicy.js b/lib/core/components/retryPolicy.js index 2ce03d7c2..f81765e5b 100644 --- a/lib/core/components/retryPolicy.js +++ b/lib/core/components/retryPolicy.js @@ -22,38 +22,96 @@ var Endpoint; Endpoint["Unknown"] = "UnknownEndpoint"; /** * The endpoints to send messages. + * + * This is related to the following functionality: + * - `publish` + * - `signal` + * - `publish file` + * - `fire` */ Endpoint["MessageSend"] = "MessageSendEndpoint"; /** * The endpoint for real-time update retrieval. + * + * This is related to the following functionality: + * - `subscribe` */ Endpoint["Subscribe"] = "SubscribeEndpoint"; /** * The endpoint to access and manage `user_id` presence and fetch channel presence information. + * + * This is related to the following functionality: + * - `get presence state` + * - `set presence state` + * - `here now` + * - `where now` + * - `heartbeat` */ Endpoint["Presence"] = "PresenceEndpoint"; /** * The endpoint to access and manage files in channel-specific storage. + * + * This is related to the following functionality: + * - `send file` + * - `download file` + * - `list files` + * - `delete file` */ Endpoint["Files"] = "FilesEndpoint"; /** * The endpoint to access and manage messages for a specific channel(s) in the persistent storage. + * + * This is related to the following functionality: + * - `fetch messages / message actions` + * - `delete messages` + * - `messages count` */ Endpoint["MessageStorage"] = "MessageStorageEndpoint"; /** * The endpoint to access and manage channel groups. + * + * This is related to the following functionality: + * - `add channels to group` + * - `list channels in group` + * - `remove channels from group` + * - `list channel groups` */ Endpoint["ChannelGroups"] = "ChannelGroupsEndpoint"; /** * The endpoint to access and manage device registration for channel push notifications. + * + * This is related to the following functionality: + * - `enable channels for push notifications` + * - `list push notification enabled channels` + * - `disable push notifications for channels` + * - `disable push notifications for all channels` */ Endpoint["DevicePushNotifications"] = "DevicePushNotificationsEndpoint"; /** * The endpoint to access and manage App Context objects. + * + * This is related to the following functionality: + * - `set UUID metadata` + * - `get UUID metadata` + * - `remove UUID metadata` + * - `get all UUID metadata` + * - `set Channel metadata` + * - `get Channel metadata` + * - `remove Channel metadata` + * - `get all Channel metadata` + * - `manage members` + * - `list members` + * - `manage memberships` + * - `list memberships` */ Endpoint["AppContext"] = "AppContextEndpoint"; /** * The endpoint to access and manage reactions for a specific message. + * + * This is related to the following functionality: + * - `add message action` + * - `get message actions` + * - `remove message action` */ Endpoint["MessageReactions"] = "MessageReactionsEndpoint"; })(Endpoint || (exports.Endpoint = Endpoint = {})); @@ -62,6 +120,19 @@ var Endpoint; * Failed request retry policy. */ class RetryPolicy { + static None() { + return { + shouldRetry(_request, _response, _errorCategory, _attempt) { + return false; + }, + getDelay(_attempt, _response) { + return -1; + }, + validate() { + return true; + }, + }; + } static LinearRetryPolicy(configuration) { var _a; return { diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index b48640c33..7c27e0bcb 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -2216,6 +2216,11 @@ PubNubCore.OPERATIONS = operations_1.default; * API call status category. */ PubNubCore.CATEGORIES = categories_1.default; +/** + * Enum with API endpoint groups which can be used with retry policy to set up exclusions (which shouldn't be + * retried). + */ +PubNubCore.Endpoint = retryPolicy_1.Endpoint; /** * Exponential retry policy constructor. */ @@ -2224,3 +2229,10 @@ PubNubCore.ExponentialRetryPolicy = retryPolicy_1.RetryPolicy.ExponentialRetryPo * Linear retry policy constructor. */ PubNubCore.LinearRetryPolicy = retryPolicy_1.RetryPolicy.LinearRetryPolicy; +/** + * Disabled / inactive retry policy. + * + * **Note:** By default `ExponentialRetryPolicy` is set for subscribe requests and this one can be used to disable + * retry policy for all requests (setting `undefined` for retry configuration will set default policy). + */ +PubNubCore.NoneRetryPolicy = retryPolicy_1.RetryPolicy.None; diff --git a/lib/types/index.d.ts b/lib/types/index.d.ts index 6334aa404..22d20f700 100644 --- a/lib/types/index.d.ts +++ b/lib/types/index.d.ts @@ -53,6 +53,11 @@ declare class PubNubCore< * API call status category. */ static CATEGORIES: typeof PubNub.StatusCategory; + /** + * Enum with API endpoint groups which can be used with retry policy to set up exclusions (which shouldn't be + * retried). + */ + static Endpoint: typeof PubNub.Endpoint; /** * Exponential retry policy constructor. */ @@ -61,6 +66,13 @@ declare class PubNubCore< * Linear retry policy constructor. */ static LinearRetryPolicy: typeof PubNub.RetryPolicy.LinearRetryPolicy; + /** + * Disabled / inactive retry policy. + * + * **Note:** By default `ExponentialRetryPolicy` is set for subscribe requests and this one can be used to disable + * retry policy for all requests (setting `undefined` for retry configuration will set default policy). + */ + static NoneRetryPolicy: typeof PubNub.RetryPolicy.None; /** * Construct notification payload which will trigger push notification. * @@ -2722,38 +2734,96 @@ declare namespace PubNub { export enum Endpoint { /** * The endpoints to send messages. + * + * This is related to the following functionality: + * - `publish` + * - `signal` + * - `publish file` + * - `fire` */ MessageSend = 'MessageSendEndpoint', /** * The endpoint for real-time update retrieval. + * + * This is related to the following functionality: + * - `subscribe` */ Subscribe = 'SubscribeEndpoint', /** * The endpoint to access and manage `user_id` presence and fetch channel presence information. + * + * This is related to the following functionality: + * - `get presence state` + * - `set presence state` + * - `here now` + * - `where now` + * - `heartbeat` */ Presence = 'PresenceEndpoint', /** * The endpoint to access and manage files in channel-specific storage. + * + * This is related to the following functionality: + * - `send file` + * - `download file` + * - `list files` + * - `delete file` */ Files = 'FilesEndpoint', /** * The endpoint to access and manage messages for a specific channel(s) in the persistent storage. + * + * This is related to the following functionality: + * - `fetch messages / message actions` + * - `delete messages` + * - `messages count` */ MessageStorage = 'MessageStorageEndpoint', /** * The endpoint to access and manage channel groups. + * + * This is related to the following functionality: + * - `add channels to group` + * - `list channels in group` + * - `remove channels from group` + * - `list channel groups` */ ChannelGroups = 'ChannelGroupsEndpoint', /** * The endpoint to access and manage device registration for channel push notifications. + * + * This is related to the following functionality: + * - `enable channels for push notifications` + * - `list push notification enabled channels` + * - `disable push notifications for channels` + * - `disable push notifications for all channels` */ DevicePushNotifications = 'DevicePushNotificationsEndpoint', /** * The endpoint to access and manage App Context objects. + * + * This is related to the following functionality: + * - `set UUID metadata` + * - `get UUID metadata` + * - `remove UUID metadata` + * - `get all UUID metadata` + * - `set Channel metadata` + * - `get Channel metadata` + * - `remove Channel metadata` + * - `get all Channel metadata` + * - `manage members` + * - `list members` + * - `manage memberships` + * - `list memberships` */ AppContext = 'AppContextEndpoint', /** * The endpoint to access and manage reactions for a specific message. + * + * This is related to the following functionality: + * - `add message action` + * - `get message actions` + * - `remove message action` */ MessageReactions = 'MessageReactionsEndpoint', } @@ -2842,6 +2912,7 @@ declare namespace PubNub { * Failed request retry policy. */ export class RetryPolicy { + static None(): RequestRetryPolicy; static LinearRetryPolicy( configuration: LinearRetryPolicyConfiguration, ): RequestRetryPolicy & LinearRetryPolicyConfiguration; diff --git a/package.json b/package.json index 27d546116..bdabcfc81 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "9.5.0", + "version": "9.5.1", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index f1c11fcf8..7973ecd65 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -203,7 +203,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '9.5.0'; + return '9.5.1'; }, getVersion(): string { return this.version; diff --git a/src/core/components/retryPolicy.ts b/src/core/components/retryPolicy.ts index e12f2e23b..36be522c2 100644 --- a/src/core/components/retryPolicy.ts +++ b/src/core/components/retryPolicy.ts @@ -217,17 +217,19 @@ export type ExponentialRetryPolicyConfiguration = { * Failed request retry policy. */ export class RetryPolicy { - static None: RequestRetryPolicy = { - shouldRetry(_request, _response, _errorCategory, _attempt): boolean { - return false; - }, - getDelay(_attempt, _response): number { - return -1; - }, - validate() { - return true; - }, - }; + static None(): RequestRetryPolicy { + return { + shouldRetry(_request, _response, _errorCategory, _attempt): boolean { + return false; + }, + getDelay(_attempt, _response): number { + return -1; + }, + validate() { + return true; + }, + }; + } static LinearRetryPolicy( configuration: LinearRetryPolicyConfiguration, diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index 07bc5fd67..65e7dbd0d 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -32,7 +32,7 @@ import StatusCategory from './constants/categories'; import { createValidationError, PubNubError } from '../errors/pubnub-error'; import { PubNubAPIError } from '../errors/pubnub-api-error'; -import { RetryPolicy } from './components/retryPolicy'; +import { RetryPolicy, Endpoint } from './components/retryPolicy'; // region Event Engine import { PresenceEventEngine } from '../event-engine/presence/presence'; @@ -295,6 +295,12 @@ export class PubNubCore< */ static CATEGORIES = StatusCategory; + /** + * Enum with API endpoint groups which can be used with retry policy to set up exclusions (which shouldn't be + * retried). + */ + static Endpoint = Endpoint; + /** * Exponential retry policy constructor. */ @@ -305,6 +311,14 @@ export class PubNubCore< */ static LinearRetryPolicy = RetryPolicy.LinearRetryPolicy; + /** + * Disabled / inactive retry policy. + * + * **Note:** By default `ExponentialRetryPolicy` is set for subscribe requests and this one can be used to disable + * retry policy for all requests (setting `undefined` for retry configuration will set default policy). + */ + static NoneRetryPolicy = RetryPolicy.None; + /** * Construct notification payload which will trigger push notification. * From b8e1af9685fb658680e1dd7aa85a1cde19904f28 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 22 Apr 2025 15:52:41 +0300 Subject: [PATCH 49/49] Shouldn't retry on bad access denied and bad request (#454) fix(retry): shouldn't retry on bad access denied and bad request Fixed issue because of which client retried for both bad request and access denied. refactor(subscription): add channels and groups to connected status Add current list of channels and groups to connected status. --- .pubnub.yml | 13 +- CHANGELOG.md | 9 + README.md | 4 +- dist/web/pubnub.js | 177 ++++++++++++------ dist/web/pubnub.min.js | 4 +- lib/core/components/configuration.js | 2 +- lib/core/components/retryPolicy.js | 10 +- lib/core/pubnub-common.js | 16 +- lib/event-engine/events.js | 3 +- lib/event-engine/index.js | 6 +- lib/event-engine/presence/events.js | 2 +- lib/event-engine/presence/presence.js | 4 +- .../presence/states/heartbeat_cooldown.js | 4 +- .../presence/states/heartbeat_failed.js | 4 +- .../presence/states/heartbeating.js | 4 +- lib/event-engine/states/handshake_failed.js | 8 +- lib/event-engine/states/handshake_stopped.js | 8 +- lib/event-engine/states/handshaking.js | 13 +- lib/event-engine/states/receive_failed.js | 20 +- lib/event-engine/states/receive_stopped.js | 20 +- lib/event-engine/states/receiving.js | 45 +++-- lib/event-engine/states/unsubscribed.js | 12 +- package.json | 2 +- src/core/components/configuration.ts | 2 +- src/core/components/retryPolicy.ts | 11 +- src/core/pubnub-common.ts | 15 +- src/event-engine/dispatcher.ts | 2 +- src/event-engine/events.ts | 12 +- src/event-engine/index.ts | 6 +- src/event-engine/presence/events.ts | 2 +- src/event-engine/presence/presence.ts | 4 +- .../presence/states/heartbeat_cooldown.ts | 6 +- .../presence/states/heartbeat_failed.ts | 6 +- .../presence/states/heartbeating.ts | 6 +- src/event-engine/states/handshake_failed.ts | 18 +- src/event-engine/states/handshake_stopped.ts | 18 +- src/event-engine/states/handshaking.ts | 19 +- src/event-engine/states/receive_failed.ts | 18 +- src/event-engine/states/receive_stopped.ts | 18 +- src/event-engine/states/receiving.ts | 51 +++-- src/event-engine/states/unsubscribed.ts | 16 +- 41 files changed, 415 insertions(+), 205 deletions(-) diff --git a/.pubnub.yml b/.pubnub.yml index c105a576e..452e6cc06 100644 --- a/.pubnub.yml +++ b/.pubnub.yml @@ -1,5 +1,12 @@ --- changelog: + - date: 2025-04-22 + version: v9.5.2 + changes: + - type: bug + text: "Fixed issue because of which client retried for both bad request and access denied." + - type: improvement + text: "Add current list of channels and groups to connected status." - date: 2025-04-15 version: v9.5.1 changes: @@ -1229,7 +1236,7 @@ supported-platforms: - 'Ubuntu 14.04 and up' - 'Windows 7 and up' version: 'Pubnub Javascript for Node' -version: '9.5.1' +version: '9.5.2' sdks: - full-name: PubNub Javascript SDK short-name: Javascript @@ -1245,7 +1252,7 @@ sdks: - distribution-type: source distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/archive/refs/tags/v9.5.1.zip + location: https://github.com/pubnub/javascript/archive/refs/tags/v9.5.2.zip requires: - name: 'agentkeepalive' min-version: '3.5.2' @@ -1916,7 +1923,7 @@ sdks: - distribution-type: library distribution-repository: GitHub release package-name: pubnub.js - location: https://github.com/pubnub/javascript/releases/download/v9.5.1/pubnub.9.5.1.js + location: https://github.com/pubnub/javascript/releases/download/v9.5.2/pubnub.9.5.2.js requires: - name: 'agentkeepalive' min-version: '3.5.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ee2df455..e7dd0fe2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## v9.5.2 +April 22 2025 + +#### Fixed +- Fixed issue because of which client retried for both bad request and access denied. + +#### Modified +- Add current list of channels and groups to connected status. + ## v9.5.1 April 15 2025 diff --git a/README.md b/README.md index 3519c7f62..27df1b583 100644 --- a/README.md +++ b/README.md @@ -27,8 +27,8 @@ Watch [Getting Started with PubNub JS SDK](https://app.dashcam.io/replay/64ee0d2 npm install pubnub ``` * or download one of our builds from our CDN: - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.1.js - * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.1.min.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.2.js + * https://cdn.pubnub.com/sdk/javascript/pubnub.9.5.2.min.js 2. Configure your keys: diff --git a/dist/web/pubnub.js b/dist/web/pubnub.js index 9531eb233..61b322524 100644 --- a/dist/web/pubnub.js +++ b/dist/web/pubnub.js @@ -3957,9 +3957,13 @@ * @internal */ const isRetriableRequest = (req, res, errorCategory, retryAttempt, maximumRetry, excluded) => { - if (errorCategory && errorCategory === StatusCategory$1.PNCancelledCategory) - return false; - else if (isExcludedRequest(req, excluded)) + if (errorCategory) { + if (errorCategory === StatusCategory$1.PNCancelledCategory || + errorCategory === StatusCategory$1.PNBadRequestCategory || + errorCategory === StatusCategory$1.PNAccessDeniedCategory) + return false; + } + if (isExcludedRequest(req, excluded)) return false; else if (retryAttempt > maximumRetry) return false; @@ -4209,7 +4213,7 @@ return base.PubNubFile; }, get version() { - return '9.5.1'; + return '9.5.2'; }, getVersion() { return this.version; @@ -7693,7 +7697,7 @@ * * @internal */ - const leftAll = createEvent('LEFT_ALL', () => ({})); + const leftAll = createEvent('LEFT_ALL', (isOffline) => ({ isOffline })); /** * Presence heartbeat success event. * @@ -7878,7 +7882,9 @@ HeartbeatCooldownState.on(disconnect$1.type, (context, event) => HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), ])); - HeartbeatCooldownState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + HeartbeatCooldownState.on(leftAll.type, (context, event) => HeartbeatInactiveState.with(undefined, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ])); /** * Failed to heartbeat state module. @@ -7909,7 +7915,9 @@ HeartbeatFailedState.on(disconnect$1.type, (context, event) => HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), ])); - HeartbeatFailedState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + HeartbeatFailedState.on(leftAll.type, (context, event) => HeartbeatInactiveState.with(undefined, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ])); /** * Heartbeating state module. @@ -7945,7 +7953,9 @@ HeartbeatingState.on(disconnect$1.type, (context, event) => HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), ])); - HeartbeatingState.on(leftAll.type, (context, _) => HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)])); + HeartbeatingState.on(leftAll.type, (context, event) => HeartbeatInactiveState.with(undefined, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ])); /** * Inactive heratbeating state module. @@ -8004,8 +8014,8 @@ } this.engine.transition(left(channels !== null && channels !== void 0 ? channels : [], groups !== null && groups !== void 0 ? groups : [])); } - leaveAll() { - this.engine.transition(leftAll()); + leaveAll(isOffline) { + this.engine.transition(leftAll(isOffline)); } reconnect() { this.engine.transition(reconnect$1()); @@ -8074,9 +8084,10 @@ * * @internal */ - const subscriptionChange = createEvent('SUBSCRIPTION_CHANGED', (channels, groups) => ({ + const subscriptionChange = createEvent('SUBSCRIPTION_CHANGED', (channels, groups, isOffline) => ({ channels, groups, + isOffline, })); /** * Subscription loop restore. @@ -8231,10 +8242,16 @@ * @internal */ const HandshakeStoppedState = new State('HANDSHAKE_STOPPED'); - HandshakeStoppedState.on(subscriptionChange.type, (context, { payload }) => HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); + HandshakeStoppedState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); + return HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); + }); HandshakeStoppedState.on(reconnect.type, (context, { payload }) => HandshakingState.with(Object.assign(Object.assign({}, context), { cursor: payload.cursor || context.cursor }))); HandshakeStoppedState.on(restore.type, (context, { payload }) => { var _a; + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); return HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, @@ -8257,7 +8274,11 @@ * @internal */ const HandshakeFailedState = new State('HANDSHAKE_FAILED'); - HandshakeFailedState.on(subscriptionChange.type, (context, { payload }) => HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); + HandshakeFailedState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); + }); HandshakeFailedState.on(reconnect.type, (context, { payload }) => HandshakingState.with({ channels: context.channels, groups: context.groups, @@ -8265,6 +8286,8 @@ })); HandshakeFailedState.on(restore.type, (context, { payload }) => { var _a, _b; + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); return HandshakingState.with({ channels: payload.channels, groups: payload.groups, @@ -8290,12 +8313,20 @@ * @internal */ const ReceiveStoppedState = new State('RECEIVE_STOPPED'); - ReceiveStoppedState.on(subscriptionChange.type, (context, { payload }) => ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); - ReceiveStoppedState.on(restore.type, (context, { payload }) => ReceiveStoppedState.with({ - channels: payload.channels, - groups: payload.groups, - cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, - })); + ReceiveStoppedState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); + return ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); + }); + ReceiveStoppedState.on(restore.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); + return ReceiveStoppedState.with({ + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, + }); + }); ReceiveStoppedState.on(reconnect.type, (context, { payload }) => { var _a; return HandshakingState.with({ @@ -8334,12 +8365,20 @@ }, }); }); - ReceiveFailedState.on(subscriptionChange.type, (context, { payload }) => HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); - ReceiveFailedState.on(restore.type, (context, { payload }) => HandshakingState.with({ - channels: payload.channels, - groups: payload.groups, - cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, - })); + ReceiveFailedState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); + }); + ReceiveFailedState.on(restore.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); + return HandshakingState.with({ + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, + }); + }); ReceiveFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); /** @@ -8363,30 +8402,41 @@ ]); }); ReceivingState.on(subscriptionChange.type, (context, { payload }) => { - const subscriptionChangeStatus = { - category: StatusCategory$1.PNSubscriptionChangedCategory, - affectedChannels: payload.channels.slice(0), - affectedChannelGroups: payload.groups.slice(0), - }; - if (payload.channels.length === 0 && payload.groups.length === 0) - return UnsubscribedState.with(undefined, [emitStatus(subscriptionChangeStatus)]); + var _a; + if (payload.channels.length === 0 && payload.groups.length === 0) { + let errorCategory; + if (payload.isOffline) + errorCategory = (_a = PubNubAPIError.create(new Error('Network connection error')).toPubNubError(RequestOperation$1.PNSubscribeOperation).status) === null || _a === void 0 ? void 0 : _a.category; + return UnsubscribedState.with(undefined, [ + emitStatus(Object.assign({ category: !payload.isOffline + ? StatusCategory$1.PNDisconnectedCategory + : StatusCategory$1.PNDisconnectedUnexpectedlyCategory }, (errorCategory ? { error: errorCategory } : {}))), + ]); + } return ReceivingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }, [ - emitStatus(subscriptionChangeStatus), + emitStatus({ + category: StatusCategory$1.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + currentTimetoken: context.cursor.timetoken, + }), ]); }); ReceivingState.on(restore.type, (context, { payload }) => { - const subscriptionChangeStatus = { - category: StatusCategory$1.PNSubscriptionChangedCategory, - affectedChannels: payload.channels.slice(0), - affectedChannelGroups: payload.groups.slice(0), - }; if (payload.channels.length === 0 && payload.groups.length === 0) - return UnsubscribedState.with(undefined, [emitStatus(subscriptionChangeStatus)]); + return UnsubscribedState.with(undefined, [emitStatus({ category: StatusCategory$1.PNDisconnectedCategory })]); return ReceivingState.with({ channels: payload.channels, groups: payload.groups, cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, - }, [emitStatus(subscriptionChangeStatus)]); + }, [ + emitStatus({ + category: StatusCategory$1.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + currentTimetoken: payload.cursor.timetoken, + }), + ]); }); ReceivingState.on(receiveFailure.type, (context, { payload }) => { var _a; @@ -8435,7 +8485,7 @@ return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); }); HandshakingState.on(handshakeSuccess.type, (context, { payload }) => { - var _a, _b; + var _a, _b, _c, _d; return ReceivingState.with({ channels: context.channels, groups: context.groups, @@ -8443,7 +8493,14 @@ timetoken: !!((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : payload.timetoken, region: payload.region, }, - }, [emitStatus({ category: StatusCategory$1.PNConnectedCategory })]); + }, [ + emitStatus({ + category: StatusCategory$1.PNConnectedCategory, + affectedChannels: context.channels.slice(0), + affectedChannelGroups: context.groups.slice(0), + currentTimetoken: !!((_c = context.cursor) === null || _c === void 0 ? void 0 : _c.timetoken) ? (_d = context.cursor) === null || _d === void 0 ? void 0 : _d.timetoken : payload.timetoken, + }), + ]); }); HandshakingState.on(handshakeFailure.type, (context, event) => { var _a; @@ -8470,6 +8527,8 @@ }); HandshakingState.on(restore.type, (context, { payload }) => { var _a; + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); return HandshakingState.with({ channels: payload.channels, groups: payload.groups, @@ -8491,8 +8550,16 @@ * @internal */ const UnsubscribedState = new State('UNSUBSCRIBED'); - UnsubscribedState.on(subscriptionChange.type, (_, { payload }) => HandshakingState.with({ channels: payload.channels, groups: payload.groups })); - UnsubscribedState.on(restore.type, (_, { payload }) => HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: payload.cursor })); + UnsubscribedState.on(subscriptionChange.type, (_, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); + return HandshakingState.with({ channels: payload.channels, groups: payload.groups }); + }); + UnsubscribedState.on(restore.type, (_, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return UnsubscribedState.with(undefined); + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: payload.cursor }); + }); /** * Subscribe Event Engine module. @@ -8569,7 +8636,7 @@ } } } - unsubscribeAll() { + unsubscribeAll(isOffline) { const channelGroups = this.getSubscribedChannels(); const channels = this.getSubscribedChannels(); this.channels = []; @@ -8579,9 +8646,9 @@ delete this.dependencies.presenceState[objectName]; }); } - this.engine.transition(subscriptionChange(this.channels.slice(0), this.groups.slice(0))); + this.engine.transition(subscriptionChange(this.channels.slice(0), this.groups.slice(0), isOffline)); if (this.dependencies.leaveAll) - this.dependencies.leaveAll({ channels, groups: channelGroups }); + this.dependencies.leaveAll({ channels, groups: channelGroups, isOffline }); } reconnect({ timetoken, region }) { const channelGroups = this.getSubscribedChannels(); @@ -13316,11 +13383,11 @@ this.subscriptionManager.disconnect(); } else if (this.eventEngine) - this.eventEngine.dispose(); - { - if (this.presenceEventEngine) - this.presenceEventEngine.dispose(); - } + this.eventEngine.unsubscribeAll(isOffline); + } + { + if (this.presenceEventEngine) + this.presenceEventEngine.leaveAll(isOffline); } } /** @@ -14022,11 +14089,11 @@ * * @param parameters - List of channels and groups where `leave` event should be sent. */ - leaveAll(parameters) { + leaveAll(parameters = {}) { { if (this.presenceEventEngine) - this.presenceEventEngine.leaveAll(); - else + this.presenceEventEngine.leaveAll(parameters.isOffline); + else if (!parameters.isOffline) this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => { }); } } diff --git a/dist/web/pubnub.min.js b/dist/web/pubnub.min.js index 0a35f77f9..e8263f586 100644 --- a/dist/web/pubnub.min.js +++ b/dist/web/pubnub.min.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)w+=d,S.push(u(d));var O=new Uint8Array(w),k=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNSubscriptionChangedCategory="PNSubscriptionChangedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,S,w=w||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=w).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=w,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],S=e[i+12],w=e[i+13],O=e[i+14],k=e[i+15],E=t(E=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,E,N,P,o,12,u[1]),P=t(P,C,E,N,l,17,u[2]),N=t(N,P,C,E,h,22,u[3]);E=t(E,N,P,C,d,7,u[4]),C=t(C,E,N,P,p,12,u[5]),P=t(P,C,E,N,g,17,u[6]),N=t(N,P,C,E,y,22,u[7]),E=t(E,N,P,C,f,7,u[8]),C=t(C,E,N,P,b,12,u[9]),P=t(P,C,E,N,m,17,u[10]),N=t(N,P,C,E,v,22,u[11]),E=t(E,N,P,C,S,7,u[12]),C=t(C,E,N,P,w,12,u[13]),P=t(P,C,E,N,O,17,u[14]),E=n(E,N=t(N,P,C,E,k,22,u[15]),P,C,o,5,u[16]),C=n(C,E,N,P,g,9,u[17]),P=n(P,C,E,N,v,14,u[18]),N=n(N,P,C,E,c,20,u[19]),E=n(E,N,P,C,p,5,u[20]),C=n(C,E,N,P,m,9,u[21]),P=n(P,C,E,N,k,14,u[22]),N=n(N,P,C,E,d,20,u[23]),E=n(E,N,P,C,b,5,u[24]),C=n(C,E,N,P,O,9,u[25]),P=n(P,C,E,N,h,14,u[26]),N=n(N,P,C,E,f,20,u[27]),E=n(E,N,P,C,w,5,u[28]),C=n(C,E,N,P,l,9,u[29]),P=n(P,C,E,N,y,14,u[30]),E=s(E,N=n(N,P,C,E,S,20,u[31]),P,C,p,4,u[32]),C=s(C,E,N,P,f,11,u[33]),P=s(P,C,E,N,v,16,u[34]),N=s(N,P,C,E,O,23,u[35]),E=s(E,N,P,C,o,4,u[36]),C=s(C,E,N,P,d,11,u[37]),P=s(P,C,E,N,y,16,u[38]),N=s(N,P,C,E,m,23,u[39]),E=s(E,N,P,C,w,4,u[40]),C=s(C,E,N,P,c,11,u[41]),P=s(P,C,E,N,h,16,u[42]),N=s(N,P,C,E,g,23,u[43]),E=s(E,N,P,C,b,4,u[44]),C=s(C,E,N,P,S,11,u[45]),P=s(P,C,E,N,k,16,u[46]),E=r(E,N=s(N,P,C,E,l,23,u[47]),P,C,c,6,u[48]),C=r(C,E,N,P,y,10,u[49]),P=r(P,C,E,N,O,15,u[50]),N=r(N,P,C,E,p,21,u[51]),E=r(E,N,P,C,S,6,u[52]),C=r(C,E,N,P,h,10,u[53]),P=r(P,C,E,N,m,15,u[54]),N=r(N,P,C,E,o,21,u[55]),E=r(E,N,P,C,f,6,u[56]),C=r(C,E,N,P,k,10,u[57]),P=r(P,C,E,N,g,15,u[58]),N=r(N,P,C,E,w,21,u[59]),E=r(E,N,P,C,d,6,u[60]),C=r(C,E,N,P,v,10,u[61]),P=r(P,C,E,N,l,15,u[62]),N=r(N,P,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=w,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=w,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],S=p[v],O=257*p[b]^16843008*b;i[y]=O<<24|O>>>8,a[y]=O<<16|O>>>16,o[y]=O<<8|O>>>24,c[y]=O,O=16843009*S^65537*v^257*m^16843008*y,u[b]=O<<24|O>>>8,l[b]=O<<16|O>>>16,h[b]=O<<8|O>>>24,d[b]=O,y?(y=m^p[p[p[S^m]]],f^=p[p[f]]):y=f=1}var k=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=k[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),w.mode.ECB=((S=w.lib.BlockCipherMode.extend()).Encryptor=S.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),S.Decryptor=S.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),S);var O=t(w);class k{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=O,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:k.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return k.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(k.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=k.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new k({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new k({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=j.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=j.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===j.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof _)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=j.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class j{static from(e,t){if(e!==j.LEGACY_IDENTIFIER)return new _(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==j.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>j.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+j.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new _(this.decoder.decode(s),a)}}j.SENTINEL="PNED",j.LEGACY_IDENTIFIER="",j.IDENTIFIER_LENGTH=4,j.VERSION=1,j.MAX_VERSION=1,j.decoder=new TextDecoder;class _{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return j.VERSION}get length(){return j.SENTINEL.length+1+j.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(j.SENTINEL)),e+=j.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=j.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}_.IDENTIFIER_LENGTH=4,_.SENTINEL="PNED";class A extends Error{static create(e,t){return A.isErrorObject(e)?A.createFromError(e):A.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new A(n,t,0);if(e instanceof A)return e;if(A.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new A(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new A(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,A.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(A.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new A(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let S=!1,w=!0,O=5,k=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(S=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(O=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:S,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:O})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R;!function(e){e.Unknown="UnknownEndpoint",e.MessageSend="MessageSendEndpoint",e.Subscribe="SubscribeEndpoint",e.Presence="PresenceEndpoint",e.Files="FilesEndpoint",e.MessageStorage="MessageStorageEndpoint",e.ChannelGroups="ChannelGroupsEndpoint",e.DevicePushNotifications="DevicePushNotificationsEndpoint",e.AppContext="AppContextEndpoint",e.MessageReactions="MessageReactionsEndpoint"}(R||(R={}));class U{static None(){return{shouldRetry:(e,t,n,s)=>!1,getDelay:(e,t)=>-1,validate:()=>!0}}static LinearRetryPolicy(e){var t;return{delay:e.delay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=this.delay),1e3*(n+Math.random())},validate(){if(this.delay<2)throw new Error("Delay can not be set less than 2 seconds for retry");if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){var t;return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=Math.min(Math.pow(2,e),this.maximumDelay)),1e3*(n+Math.random())},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const x=(e,t,n,s,r,i)=>(!n||n!==h.PNCancelledCategory)&&(!D(e,i)&&(!(s>r)&&(!t||(429===t.status||t.status>=500)))),D=(e,t)=>!!(t&&t.length>0)&&t.includes(q(e)),q=e=>{let t=R.Unknown;return e.path.startsWith("/v2/subscribe")?t=R.Subscribe:e.path.startsWith("/publish/")||e.path.startsWith("/signal/")?t=R.MessageSend:e.path.startsWith("/v2/presence")?t=R.Presence:e.path.startsWith("/v2/history")||e.path.startsWith("/v3/history")?t=R.MessageStorage:e.path.startsWith("/v1/message-actions/")?t=R.MessageReactions:e.path.startsWith("/v1/channel-registration/")||e.path.startsWith("/v2/objects/")?t=R.ChannelGroups:e.path.startsWith("/v1/push/")||e.path.startsWith("/v2/push/")?t=R.DevicePushNotifications:e.path.startsWith("/v1/files/")&&(t=R.Files),t};var L={exports:{}}; -/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(L,L.exports);var G=t(L.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var n,s,r;!e.retryConfiguration&&e.enableEventEngine&&(e.retryConfiguration=U.ExponentialRetryPolicy({minimumDelay:2,maximumDelay:150,maximumRetry:6,excluded:[R.MessageSend,R.Presence,R.Files,R.MessageStorage,R.ChannelGroups,R.DevicePushNotifications,R.AppContext,R.MessageReactions]})),null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=B(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.5.1"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},B=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class H{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var W;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(W||(W={}));const V=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),z=(e,t)=>{const n=e.map((e=>V(e)));return n.length?n.join(","):null!=t?t:""},J=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},X=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class Q{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?W.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===W.POST||t===W.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=Q.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${V(e)}`)).join("&"):`${t}=${V(n)}`})).join("&")}}Q.textDecoder=new TextDecoder("utf-8");class Y{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new Q(t.publishKey,t.secretKey,n))}makeSendable(e){const t=this.configuration.clientConfiguration.retryConfiguration,n=this.configuration.transport;if(void 0!==t){let s,r,i=!1,a=0;const o={abort:e=>{i=!0,s&&clearTimeout(s),r&&r.abort(e)}};return[new Promise(((o,c)=>{const u=()=>{if(i)return;const[l,d]=n.makeSendable(this.request(e));r=d;const p=(n,r)=>{const i=!r||r.category!==h.PNCancelledCategory,l=!n||n.status>=400;let d=-1;i&&l&&t.shouldRetry(e,n,null==r?void 0:r.category,a+1)&&(d=t.getDelay(a,n)),d>0?(a++,s=setTimeout((()=>u()),d)):n?o(n):r&&c(r)};l.then((e=>p(e))).catch((e=>p(void 0,e)))};u()})),r?o:void 0]}return n.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class Z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(Z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(Z.originalFetch=Z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(Z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw A.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw A.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([Z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else if(e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer))if(e.compressible&&"undefined"!=typeof CompressionStream){const n=new ReadableStream({start(t){t.enqueue("string"==typeof e.body?Z.encoder.encode(e.body):e.body),t.close()}});t=yield new Response(n.pipeThrough(new CompressionStream("deflate"))).arrayBuffer()}else t=e.body;var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${Z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${Z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}Z.encoder=new TextEncoder,Z.decoder=new TextDecoder;class ee{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class te{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class ne{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class re{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ie extends re{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class ae extends re{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class oe{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ie(this._payload.apns,e,t),this.fcm=new ae(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class ce{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s,r,i;const a={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:W.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,compressible:null!==(i=null===(r=this.params)||void 0===r?void 0:r.compressible)&&void 0!==i&&i,timeout:10,identifier:this.requestIdentifier},o=this.headers;if(o&&(a.headers=o),a.method===W.POST||a.method===W.PATCH){const[e,t]=[this.body,this.formData];t&&(a.formData=t),e&&(a.body=e)}return a}get headers(){var e,t;return Object.assign({"Accept-Encoding":"gzip, deflate"},null!==(t=null===(e=this.params)||void 0===e?void 0:e.compressible)&&void 0!==t&&t?{"Content-Encoding":"deflate"}:{})}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=ce.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw A.create(e);return s}}var ue;ce.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ue||(ue={}));var le=ue;var he;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(he||(he={}));class de extends ce{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return le.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=ce.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?he.Presence:he.Message),t!=he.Signal&&"string"==typeof e.d?t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}:t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:t===he.Presence?{type:he.Presence,data:this.presenceEventFromEnvelope(e)}:t==he.Signal?{type:he.Signal,data:this.signalFromEnvelope(e)}:t===he.AppContext?{type:he.AppContext,data:this.appContextFromEnvelope(e)}:t===he.MessageAction?{type:he.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{accept:"text/javascript"})}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(pe.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class pe extends de{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ge{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===he.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===he.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===he.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===he.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=K.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class ye{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class fe{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class be extends ye{describe(e){return new fe(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class me{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ve(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function Se(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function we(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class Oe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class ke extends ye{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new Oe}abort(){this._aborted=!0,this.notify(new Oe)}}class Ee{constructor(e,t){this.payload=e,this.dependencies=t}}class Ce extends Ee{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new ke}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Pe=e=>(t,n)=>new Ce(t,n,e),Ne=ve("RECONNECT",(()=>({}))),Me=ve("DISCONNECT",(e=>({isOffline:e}))),je=ve("JOINED",((e,t)=>({channels:e,groups:t}))),_e=ve("LEFT",((e,t)=>({channels:e,groups:t}))),Ae=ve("LEFT_ALL",(()=>({}))),Ie=ve("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Fe=ve("HEARTBEAT_FAILURE",(e=>e)),Te=ve("TIMES_UP",(()=>({}))),Re=we("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ue=Se("LEAVE",((e,t)=>({channels:e,groups:t}))),xe=Se("EMIT_STATUS",(e=>e)),De=we("WAIT",(()=>({})));class qe extends me{constructor(e,t){super(t),this.on(Re.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ie(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;e.transition(Fe(t))}}}))))),this.on(Ue.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(De.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Te())}))))),this.on(xe.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){s.announceFailedHeartbeats&&!0===(null==e?void 0:e.error)?n(Object.assign(Object.assign({},e),{operation:le.PNHeartbeatOperation})):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory}))})))))}}const Le=new fe("HEARTBEAT_STOPPED");Le.on(je.type,((e,t)=>Le.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(_e.type,((e,t)=>Le.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Le.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Le.on(Ae.type,((e,t)=>Be.with(void 0)));const Ge=new fe("HEARTBEAT_COOLDOWN");Ge.onEnter((()=>De())),Ge.onExit((()=>De.cancel)),Ge.on(Te.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ge.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ge.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const Ke=new fe("HEARTBEAT_FAILED");Ke.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ke.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ke.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const $e=new fe("HEARTBEATING");$e.onEnter((e=>Re(e.channels,e.groups))),$e.onExit((()=>Re.cancel)),$e.on(Ie.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups},[xe(Object.assign({},t.payload))]))),$e.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),$e.on(_e.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),$e.on(Fe.type,((e,t)=>Ke.with(Object.assign({},e),[...t.payload.status?[xe(Object.assign({},t.payload.status))]:[]]))),$e.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),$e.on(Ae.type,((e,t)=>Be.with(void 0,[Ue(e.channels,e.groups)])));const Be=new fe("HEARTBEAT_INACTIVE");Be.on(je.type,((e,t)=>$e.with({channels:t.payload.channels,groups:t.payload.groups})));class He{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new be,this.channels=[],this.groups=[],this.dispatcher=new qe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Be,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(je(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(_e(null!=e?e:[],null!=t?t:[]))}leaveAll(){this.engine.transition(Ae())}reconnect(){this.engine.transition(Ne())}disconnect(e){this.engine.transition(Me(e))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}const We=we("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=we("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),ze=Se("EMIT_MESSAGES",(e=>e)),Je=Se("EMIT_STATUS",(e=>e)),Xe=ve("SUBSCRIPTION_CHANGED",((e,t)=>({channels:e,groups:t}))),Qe=ve("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ye=ve("HANDSHAKE_SUCCESS",(e=>e)),Ze=ve("HANDSHAKE_FAILURE",(e=>e)),et=ve("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),tt=ve("RECEIVE_FAILURE",(e=>e)),nt=ve("DISCONNECT",(e=>({isOffline:e}))),st=ve("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),rt=ve("UNSUBSCRIBE_ALL",(()=>({})));class it extends me{constructor(e,t){super(t),this.on(We.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(Ve.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(et(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(tt(t))}}}))))),this.on(ze.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(Je.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){return n(e)})))))}}const at=new fe("HANDSHAKE_STOPPED");at.on(Xe.type,((e,{payload:t})=>at.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),at.on(st.type,((e,{payload:t})=>ht.with(Object.assign(Object.assign({},e),{cursor:t.cursor||e.cursor})))),at.on(Qe.type,((e,{payload:t})=>{var n;return at.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=e.cursor)||void 0===n?void 0:n.region)||0}})})),at.on(rt.type,(e=>dt.with()));const ot=new fe("HANDSHAKE_FAILED");ot.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ot.on(st.type,((e,{payload:t})=>ht.with({channels:e.channels,groups:e.groups,cursor:t.cursor||e.cursor}))),ot.on(Qe.type,((e,{payload:t})=>{var n,s;return ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region?t.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),ot.on(rt.type,(e=>dt.with()));const ct=new fe("RECEIVE_STOPPED");ct.on(Xe.type,((e,{payload:t})=>ct.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ct.on(Qe.type,((e,{payload:t})=>ct.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ct.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ct.on(rt.type,(()=>dt.with(void 0)));const ut=new fe("RECEIVE_FAILED");ut.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ut.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ut.on(Qe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ut.on(rt.type,(e=>dt.with(void 0)));const lt=new fe("RECEIVING");lt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),lt.onExit((()=>Ve.cancel)),lt.on(et.type,((e,{payload:t})=>lt.with({channels:e.channels,groups:e.groups,cursor:t.cursor},[ze(t.events)]))),lt.on(Xe.type,((e,{payload:t})=>{const n={category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0)};return 0===t.channels.length&&0===t.groups.length?dt.with(void 0,[Je(n)]):lt.with({channels:t.channels,groups:t.groups,cursor:e.cursor},[Je(n)])})),lt.on(Qe.type,((e,{payload:t})=>{const n={category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0)};return 0===t.channels.length&&0===t.groups.length?dt.with(void 0,[Je(n)]):lt.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}},[Je(n)])})),lt.on(tt.type,((e,{payload:t})=>{var n;return ut.with(Object.assign(Object.assign({},e),{reason:t}),[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])})),lt.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=A.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ut.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return ct.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Je({category:h.PNDisconnectedCategory})])})),lt.on(rt.type,(e=>dt.with(void 0,[Je({category:h.PNDisconnectedCategory})])));const ht=new fe("HANDSHAKING");ht.onEnter((e=>We(e.channels,e.groups))),ht.onExit((()=>We.cancel)),ht.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ht.on(Ye.type,((e,{payload:t})=>{var n,s;return lt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.timetoken,region:t.region}},[Je({category:h.PNConnectedCategory})])})),ht.on(Ze.type,((e,t)=>{var n;return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t.payload},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.payload.status)||void 0===n?void 0:n.category})])})),ht.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=A.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return at.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),ht.on(Qe.type,((e,{payload:t})=>{var n;return ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),ht.on(rt.type,(e=>dt.with()));const dt=new fe("UNSUBSCRIBED");dt.on(Xe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups}))),dt.on(Qe.type,((e,{payload:t})=>ht.with({channels:t.channels,groups:t.groups,cursor:t.cursor})));class pt{get _engine(){return this.engine}constructor(e){this.engine=new be,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new it(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(dt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=J(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=J(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=X(this.channels,e),i=X(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Xe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(){const e=this.getSubscribedChannels(),t=this.getSubscribedChannels();this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Xe(this.channels.slice(0),this.groups.slice(0))),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:t,groups:e})}reconnect({timetoken:e,region:t}){const n=this.getSubscribedChannels(),s=this.getSubscribedChannels();this.engine.transition(st(e,t)),this.dependencies.presenceReconnect&&this.dependencies.presenceReconnect({channels:s,groups:n})}disconnect(e){const t=this.getSubscribedChannels(),n=this.getSubscribedChannels();this.engine.transition(nt(e)),this.dependencies.presenceDisconnect&&this.dependencies.presenceDisconnect({channels:n,groups:t,isOffline:e})}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}class gt extends ce{constructor(e){var t;const n=null!==(t=e.sendByPost)&&void 0!==t&&t;super({method:n?W.POST:W.GET,compressible:n}),this.parameters=e,this.parameters.sendByPost=n}operation(){return le.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${V(t)}/0${this.parameters.sendByPost?"":`/${V(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){var e;if(this.parameters.sendByPost)return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class yt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${V(n)}/0/${V(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class ft extends de{operation(){return le.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class bt extends de{operation(){return le.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class mt extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return le.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${V(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class St extends ce{constructor(e){super({cancellable:!0}),this.parameters=e}operation(){return le.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class wt extends ce{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return le.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class Ot extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${V(t)}`}}class kt extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?le.PNGlobalHereNowOperation:le.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${z(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Et extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ct extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${z(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Pt extends ce{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return le.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Pt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Nt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Nt||(Nt={}));class Mt extends ce{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return le.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Nt.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${z(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Mt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Nt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class _t extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${n}`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify(this.parameters.action)}}class At extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${s}/action/${n}`}}class It extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return le.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${V(t)}/0/${V(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ft extends ce{constructor(e){super({method:W.LOCAL}),this.parameters=e}operation(){return le.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${V(e)}/files/${t}/${n}`}}class Tt extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(n)}/files/${t}/${s}`}}class Rt extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return le.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ut extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/generate-upload-url`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify({name:this.parameters.name})}}class xt extends ce{constructor(e){super({method:W.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return le.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?xt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Dt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:le.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof A?e:A.create(e);throw new d("File upload error.",t.toStatus(le.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ut(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new xt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class qt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Lt extends qt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Gt extends qt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Lt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Kt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class $t{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Bt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Ht{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Wt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class Vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class zt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}}class Jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}/remove`}}class Xt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class Qt{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new Xt({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Vt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Wt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new Jt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class Yt extends ce{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class Zt extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return le.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class en extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return le.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class tn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return le.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class nn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return le.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class sn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new en(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class rn extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return le.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class an extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}}class on extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class cn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class un extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return le.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ln extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class hn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class dn extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}}class pn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class yn extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class fn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new un(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new yn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new fn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new dn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new rn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new an(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new pn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new on(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class mn extends ce{constructor(){super()}operation(){return le.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class vn extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files/${n}/${s}`}}class Sn{static notificationPayload(e,t){return new oe(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new bn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new Qt(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new sn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new ee,this.eventEmitter=new ge(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new He({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new pt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceReconnect:this.presenceReconnect.bind(this),presenceDisconnect:this.presenceDisconnect.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new se(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Ht(e,this.eventEmitter,this)}channelGroup(e){return new $t(e,this.eventEmitter,this)}channelMetadata(e){return new Kt(e,this.eventEmitter,this)}userMetadata(e){return new Bt(e,this.eventEmitter,this)}subscriptionSet(e){return new Lt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===le.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===le.PNSubscribeOperation||r===le.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=Sn.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof A?e:A.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.dispose(),this.presenceEventEngine&&this.presenceEventEngine.dispose()}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new yt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new pe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:le.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new wt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(e){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect(e)}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Ot({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new mt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new St(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new vt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new St(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){this.presenceEventEngine?this.presenceEventEngine.join(e):this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}presenceReconnect(e){this.presenceEventEngine?this.presenceEventEngine.reconnect():this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}leave(e){var t;this.presenceEventEngine?null===(t=this.presenceEventEngine)||void 0===t||t.leave(e):this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}leaveAll(e){this.presenceEventEngine?this.presenceEventEngine.leaveAll():this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}presenceDisconnect(e){this.presenceEventEngine?this.presenceEventEngine.disconnect(e.isOffline):e.isOffline||this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:le.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof A&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new vn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new mn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}Sn.decoder=new TextDecoder,Sn.OPERATIONS=le,Sn.CATEGORIES=h,Sn.Endpoint=R,Sn.ExponentialRetryPolicy=U.ExponentialRetryPolicy,Sn.LinearRetryPolicy=U.LinearRetryPolicy,Sn.NoneRetryPolicy=U.None;class wn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class On extends Sn{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=$(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new k({cipherKey:e.cipherKey})]})}));let a,u,l;a=new H(new wn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new Z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new Y({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect(!0):this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return On.CryptoModule=M,On})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).PubNub=t()}(this,(function(){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function t(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var n={exports:{}};!function(t){!function(e,n){var s=Math.pow(2,-24),r=Math.pow(2,32),i=Math.pow(2,53);var a={encode:function(e){var t,s=new ArrayBuffer(256),a=new DataView(s),o=0;function c(e){for(var n=s.byteLength,r=o+e;n>2,u=0;u>6),r.push(128|63&a)):a<55296?(r.push(224|a>>12),r.push(128|a>>6&63),r.push(128|63&a)):(a=(1023&a)<<10,a|=1023&t.charCodeAt(++s),a+=65536,r.push(240|a>>18),r.push(128|a>>12&63),r.push(128|a>>6&63),r.push(128|63&a))}return d(3,r.length),h(r);default:var p;if(Array.isArray(t))for(d(4,p=t.length),s=0;s>5!==e)throw"Invalid indefinite length element";return n}function f(e,t){for(var n=0;n>10),e.push(56320|1023&s))}}"function"!=typeof t&&(t=function(e){return e}),"function"!=typeof i&&(i=function(){return n});var b=function e(){var r,d,b=l(),m=b>>5,v=31&b;if(7===m)switch(v){case 25:return function(){var e=new ArrayBuffer(4),t=new DataView(e),n=h(),r=32768&n,i=31744&n,a=1023&n;if(31744===i)i=261120;else if(0!==i)i+=114688;else if(0!==a)return a*s;return t.setUint32(0,r<<16|i<<13|a<<13),t.getFloat32(0)}();case 26:return c(a.getFloat32(o),4);case 27:return c(a.getFloat64(o),8)}if((d=g(v))<0&&(m<2||6=0;)w+=d,S.push(u(d));var O=new Uint8Array(w),k=0;for(r=0;r=0;)f(E,d);else f(E,d);return String.fromCharCode.apply(null,E);case 4:var C;if(d<0)for(C=[];!p();)C.push(e());else for(C=new Array(d),r=0;r{const n=new FileReader;n.addEventListener("load",(()=>{if(n.result instanceof ArrayBuffer)return e(n.result)})),n.addEventListener("error",(()=>t(n.error))),n.readAsArrayBuffer(this.data)}))}))}toString(){return i(this,void 0,void 0,(function*(){return new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(()=>{if("string"==typeof n.result)return e(n.result)})),n.addEventListener("error",(()=>{t(n.error)})),n.readAsBinaryString(this.data)}))}))}toStream(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in Node.js environments.")}))}toFile(){return i(this,void 0,void 0,(function*(){return this.data}))}toFileUri(){return i(this,void 0,void 0,(function*(){throw new Error("This feature is only supported in React Native environments.")}))}toBlob(){return i(this,void 0,void 0,(function*(){return this.data}))}}o.supportsBlob="undefined"!=typeof Blob,o.supportsFile="undefined"!=typeof File,o.supportsBuffer=!1,o.supportsStream=!1,o.supportsString=!0,o.supportsArrayBuffer=!0,o.supportsEncryptFile=!0,o.supportsFileUri=!1;function c(e){const t=e.replace(/==?$/,""),n=Math.floor(t.length/4*3),s=new ArrayBuffer(n),r=new Uint8Array(s);let i=0;function a(){const e=t.charAt(i++),n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(e);if(-1===n)throw new Error(`Illegal character at ${i}: ${t.charAt(i-1)}`);return n}for(let e=0;e>4,c=(15&n)<<4|s>>2,u=(3&s)<<6|i;r[e]=o,64!=s&&(r[e+1]=c),64!=i&&(r[e+2]=u)}return s}function u(e){let t="";const n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=new Uint8Array(e),r=s.byteLength,i=r%3,a=r-i;let o,c,u,l,h;for(let e=0;e>18,c=(258048&h)>>12,u=(4032&h)>>6,l=63&h,t+=n[o]+n[c]+n[u]+n[l];return 1==i?(h=s[a],o=(252&h)>>2,c=(3&h)<<4,t+=n[o]+n[c]+"=="):2==i&&(h=s[a]<<8|s[a+1],o=(64512&h)>>10,c=(1008&h)>>4,u=(15&h)<<2,t+=n[o]+n[c]+n[u]+"="),t}var l;!function(e){e.PNNetworkIssuesCategory="PNNetworkIssuesCategory",e.PNTimeoutCategory="PNTimeoutCategory",e.PNCancelledCategory="PNCancelledCategory",e.PNBadRequestCategory="PNBadRequestCategory",e.PNAccessDeniedCategory="PNAccessDeniedCategory",e.PNValidationErrorCategory="PNValidationErrorCategory",e.PNAcknowledgmentCategory="PNAcknowledgmentCategory",e.PNMalformedResponseCategory="PNMalformedResponseCategory",e.PNUnknownCategory="PNUnknownCategory",e.PNNetworkUpCategory="PNNetworkUpCategory",e.PNNetworkDownCategory="PNNetworkDownCategory",e.PNReconnectedCategory="PNReconnectedCategory",e.PNConnectedCategory="PNConnectedCategory",e.PNSubscriptionChangedCategory="PNSubscriptionChangedCategory",e.PNRequestMessageCountExceededCategory="PNRequestMessageCountExceededCategory",e.PNDisconnectedCategory="PNDisconnectedCategory",e.PNConnectionErrorCategory="PNConnectionErrorCategory",e.PNDisconnectedUnexpectedlyCategory="PNDisconnectedUnexpectedlyCategory"}(l||(l={}));var h=l;class d extends Error{constructor(e,t){super(e),this.status=t,this.name="PubNubError",this.message=e,Object.setPrototypeOf(this,new.target.prototype)}}function p(e,t){var n;return null!==(n=e.statusCode)&&void 0!==n||(e.statusCode=0),Object.assign(Object.assign({},e),{statusCode:e.statusCode,category:t,error:!0})}function g(e,t){return p(Object.assign({message:e},{}),h.PNValidationErrorCategory)}function y(e,t){return p(Object.assign(Object.assign({message:"Unable to deserialize service response"},void 0!==e?{responseText:e}:{}),void 0!==t?{statusCode:t}:{}),h.PNMalformedResponseCategory)}var f,b,m,v,S,w=w||function(e){var t={},n=t.lib={},s=function(){},r=n.Base={extend:function(e){s.prototype=this;var t=new s;return e&&t.mixIn(e),t.hasOwnProperty("init")||(t.init=function(){t.$super.init.apply(this,arguments)}),t.init.prototype=t,t.$super=this,t},create:function(){var e=this.extend();return e.init.apply(e,arguments),e},init:function(){},mixIn:function(e){for(var t in e)e.hasOwnProperty(t)&&(this[t]=e[t]);e.hasOwnProperty("toString")&&(this.toString=e.toString)},clone:function(){return this.init.prototype.extend(this)}},i=n.WordArray=r.extend({init:function(e,t){e=this.words=e||[],this.sigBytes=null!=t?t:4*e.length},toString:function(e){return(e||o).stringify(this)},concat:function(e){var t=this.words,n=e.words,s=this.sigBytes;if(e=e.sigBytes,this.clamp(),s%4)for(var r=0;r>>2]|=(n[r>>>2]>>>24-r%4*8&255)<<24-(s+r)%4*8;else if(65535>>2]=n[r>>>2];else t.push.apply(t,n);return this.sigBytes+=e,this},clamp:function(){var t=this.words,n=this.sigBytes;t[n>>>2]&=4294967295<<32-n%4*8,t.length=e.ceil(n/4)},clone:function(){var e=r.clone.call(this);return e.words=this.words.slice(0),e},random:function(t){for(var n=[],s=0;s>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>3]|=parseInt(e.substr(s,2),16)<<24-s%8*4;return new i.init(n,t/2)}},c=a.Latin1={stringify:function(e){var t=e.words;e=e.sigBytes;for(var n=[],s=0;s>>2]>>>24-s%4*8&255));return n.join("")},parse:function(e){for(var t=e.length,n=[],s=0;s>>2]|=(255&e.charCodeAt(s))<<24-s%4*8;return new i.init(n,t)}},u=a.Utf8={stringify:function(e){try{return decodeURIComponent(escape(c.stringify(e)))}catch(e){throw Error("Malformed UTF-8 data")}},parse:function(e){return c.parse(unescape(encodeURIComponent(e)))}},l=n.BufferedBlockAlgorithm=r.extend({reset:function(){this._data=new i.init,this._nDataBytes=0},_append:function(e){"string"==typeof e&&(e=u.parse(e)),this._data.concat(e),this._nDataBytes+=e.sigBytes},_process:function(t){var n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a);if(t=(o=t?e.ceil(o):e.max((0|o)-this._minBufferSize,0))*a,r=e.min(4*t,r),t){for(var c=0;cu;){var l;e:{l=c;for(var h=e.sqrt(l),d=2;d<=h;d++)if(!(l%d)){l=!1;break e}l=!0}l&&(8>u&&(i[u]=o(e.pow(c,.5))),a[u]=o(e.pow(c,1/3)),u++),c++}var p=[];r=r.SHA256=s.extend({_doReset:function(){this._hash=new n.init(i.slice(0))},_doProcessBlock:function(e,t){for(var n=this._hash.words,s=n[0],r=n[1],i=n[2],o=n[3],c=n[4],u=n[5],l=n[6],h=n[7],d=0;64>d;d++){if(16>d)p[d]=0|e[t+d];else{var g=p[d-15],y=p[d-2];p[d]=((g<<25|g>>>7)^(g<<14|g>>>18)^g>>>3)+p[d-7]+((y<<15|y>>>17)^(y<<13|y>>>19)^y>>>10)+p[d-16]}g=h+((c<<26|c>>>6)^(c<<21|c>>>11)^(c<<7|c>>>25))+(c&u^~c&l)+a[d]+p[d],y=((s<<30|s>>>2)^(s<<19|s>>>13)^(s<<10|s>>>22))+(s&r^s&i^r&i),h=l,l=u,u=c,c=o+g|0,o=i,i=r,r=s,s=g+y|0}n[0]=n[0]+s|0,n[1]=n[1]+r|0,n[2]=n[2]+i|0,n[3]=n[3]+o|0,n[4]=n[4]+c|0,n[5]=n[5]+u|0,n[6]=n[6]+l|0,n[7]=n[7]+h|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;return n[r>>>5]|=128<<24-r%32,n[14+(r+64>>>9<<4)]=e.floor(s/4294967296),n[15+(r+64>>>9<<4)]=s,t.sigBytes=4*n.length,this._process(),this._hash},clone:function(){var e=s.clone.call(this);return e._hash=this._hash.clone(),e}});t.SHA256=s._createHelper(r),t.HmacSHA256=s._createHmacHelper(r)}(Math),b=(f=w).enc.Utf8,f.algo.HMAC=f.lib.Base.extend({init:function(e,t){e=this._hasher=new e.init,"string"==typeof t&&(t=b.parse(t));var n=e.blockSize,s=4*n;t.sigBytes>s&&(t=e.finalize(t)),t.clamp();for(var r=this._oKey=t.clone(),i=this._iKey=t.clone(),a=r.words,o=i.words,c=0;c>>2]>>>24-r%4*8&255)<<16|(t[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|t[r+2>>>2]>>>24-(r+2)%4*8&255,a=0;4>a&&r+.75*a>>6*(3-a)&63));if(t=s.charAt(64))for(;e.length%4;)e.push(t);return e.join("")},parse:function(e){var t=e.length,n=this._map;(s=n.charAt(64))&&-1!=(s=e.indexOf(s))&&(t=s);for(var s=[],r=0,i=0;i>>6-i%4*2;s[r>>>2]|=(a|o)<<24-r%4*8,r++}return v.create(s,r)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},function(e){function t(e,t,n,s,r,i,a){return((e=e+(t&n|~t&s)+r+a)<>>32-i)+t}function n(e,t,n,s,r,i,a){return((e=e+(t&s|n&~s)+r+a)<>>32-i)+t}function s(e,t,n,s,r,i,a){return((e=e+(t^n^s)+r+a)<>>32-i)+t}function r(e,t,n,s,r,i,a){return((e=e+(n^(t|~s))+r+a)<>>32-i)+t}for(var i=w,a=(c=i.lib).WordArray,o=c.Hasher,c=i.algo,u=[],l=0;64>l;l++)u[l]=4294967296*e.abs(e.sin(l+1))|0;c=c.MD5=o.extend({_doReset:function(){this._hash=new a.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(e,i){for(var a=0;16>a;a++){var o=e[c=i+a];e[c]=16711935&(o<<8|o>>>24)|4278255360&(o<<24|o>>>8)}a=this._hash.words;var c=e[i+0],l=(o=e[i+1],e[i+2]),h=e[i+3],d=e[i+4],p=e[i+5],g=e[i+6],y=e[i+7],f=e[i+8],b=e[i+9],m=e[i+10],v=e[i+11],S=e[i+12],w=e[i+13],O=e[i+14],k=e[i+15],E=t(E=a[0],N=a[1],P=a[2],C=a[3],c,7,u[0]),C=t(C,E,N,P,o,12,u[1]),P=t(P,C,E,N,l,17,u[2]),N=t(N,P,C,E,h,22,u[3]);E=t(E,N,P,C,d,7,u[4]),C=t(C,E,N,P,p,12,u[5]),P=t(P,C,E,N,g,17,u[6]),N=t(N,P,C,E,y,22,u[7]),E=t(E,N,P,C,f,7,u[8]),C=t(C,E,N,P,b,12,u[9]),P=t(P,C,E,N,m,17,u[10]),N=t(N,P,C,E,v,22,u[11]),E=t(E,N,P,C,S,7,u[12]),C=t(C,E,N,P,w,12,u[13]),P=t(P,C,E,N,O,17,u[14]),E=n(E,N=t(N,P,C,E,k,22,u[15]),P,C,o,5,u[16]),C=n(C,E,N,P,g,9,u[17]),P=n(P,C,E,N,v,14,u[18]),N=n(N,P,C,E,c,20,u[19]),E=n(E,N,P,C,p,5,u[20]),C=n(C,E,N,P,m,9,u[21]),P=n(P,C,E,N,k,14,u[22]),N=n(N,P,C,E,d,20,u[23]),E=n(E,N,P,C,b,5,u[24]),C=n(C,E,N,P,O,9,u[25]),P=n(P,C,E,N,h,14,u[26]),N=n(N,P,C,E,f,20,u[27]),E=n(E,N,P,C,w,5,u[28]),C=n(C,E,N,P,l,9,u[29]),P=n(P,C,E,N,y,14,u[30]),E=s(E,N=n(N,P,C,E,S,20,u[31]),P,C,p,4,u[32]),C=s(C,E,N,P,f,11,u[33]),P=s(P,C,E,N,v,16,u[34]),N=s(N,P,C,E,O,23,u[35]),E=s(E,N,P,C,o,4,u[36]),C=s(C,E,N,P,d,11,u[37]),P=s(P,C,E,N,y,16,u[38]),N=s(N,P,C,E,m,23,u[39]),E=s(E,N,P,C,w,4,u[40]),C=s(C,E,N,P,c,11,u[41]),P=s(P,C,E,N,h,16,u[42]),N=s(N,P,C,E,g,23,u[43]),E=s(E,N,P,C,b,4,u[44]),C=s(C,E,N,P,S,11,u[45]),P=s(P,C,E,N,k,16,u[46]),E=r(E,N=s(N,P,C,E,l,23,u[47]),P,C,c,6,u[48]),C=r(C,E,N,P,y,10,u[49]),P=r(P,C,E,N,O,15,u[50]),N=r(N,P,C,E,p,21,u[51]),E=r(E,N,P,C,S,6,u[52]),C=r(C,E,N,P,h,10,u[53]),P=r(P,C,E,N,m,15,u[54]),N=r(N,P,C,E,o,21,u[55]),E=r(E,N,P,C,f,6,u[56]),C=r(C,E,N,P,k,10,u[57]),P=r(P,C,E,N,g,15,u[58]),N=r(N,P,C,E,w,21,u[59]),E=r(E,N,P,C,d,6,u[60]),C=r(C,E,N,P,v,10,u[61]),P=r(P,C,E,N,l,15,u[62]),N=r(N,P,C,E,b,21,u[63]);a[0]=a[0]+E|0,a[1]=a[1]+N|0,a[2]=a[2]+P|0,a[3]=a[3]+C|0},_doFinalize:function(){var t=this._data,n=t.words,s=8*this._nDataBytes,r=8*t.sigBytes;n[r>>>5]|=128<<24-r%32;var i=e.floor(s/4294967296);for(n[15+(r+64>>>9<<4)]=16711935&(i<<8|i>>>24)|4278255360&(i<<24|i>>>8),n[14+(r+64>>>9<<4)]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8),t.sigBytes=4*(n.length+1),this._process(),n=(t=this._hash).words,s=0;4>s;s++)r=n[s],n[s]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8);return t},clone:function(){var e=o.clone.call(this);return e._hash=this._hash.clone(),e}}),i.MD5=o._createHelper(c),i.HmacMD5=o._createHmacHelper(c)}(Math),function(){var e,t=w,n=(e=t.lib).Base,s=e.WordArray,r=(e=t.algo).EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:e.MD5,iterations:1}),init:function(e){this.cfg=this.cfg.extend(e)},compute:function(e,t){for(var n=(o=this.cfg).hasher.create(),r=s.create(),i=r.words,a=o.keySize,o=o.iterations;i.length>>2]}},e.BlockCipher=a.extend({cfg:a.cfg.extend({mode:o,padding:u}),reset:function(){a.reset.call(this);var e=(t=this.cfg).iv,t=t.mode;if(this._xformMode==this._ENC_XFORM_MODE)var n=t.createEncryptor;else n=t.createDecryptor,this._minBufferSize=1;this._mode=n.call(t,this,e&&e.words)},_doProcessBlock:function(e,t){this._mode.processBlock(e,t)},_doFinalize:function(){var e=this.cfg.padding;if(this._xformMode==this._ENC_XFORM_MODE){e.pad(this._data,this.blockSize);var t=this._process(!0)}else t=this._process(!0),e.unpad(t);return t},blockSize:4});var l=e.CipherParams=t.extend({init:function(e){this.mixIn(e)},toString:function(e){return(e||this.formatter).stringify(this)}}),h=(o=(d.format={}).OpenSSL={stringify:function(e){var t=e.ciphertext;return((e=e.salt)?n.create([1398893684,1701076831]).concat(e).concat(t):t).toString(r)},parse:function(e){var t=(e=r.parse(e)).words;if(1398893684==t[0]&&1701076831==t[1]){var s=n.create(t.slice(2,4));t.splice(0,4),e.sigBytes-=16}return l.create({ciphertext:e,salt:s})}},e.SerializableCipher=t.extend({cfg:t.extend({format:o}),encrypt:function(e,t,n,s){s=this.cfg.extend(s);var r=e.createEncryptor(n,s);return t=r.finalize(t),r=r.cfg,l.create({ciphertext:t,key:n,iv:r.iv,algorithm:e,mode:r.mode,padding:r.padding,blockSize:e.blockSize,formatter:s.format})},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),e.createDecryptor(n,s).finalize(t.ciphertext)},_parse:function(e,t){return"string"==typeof e?t.parse(e,this):e}})),d=(d.kdf={}).OpenSSL={execute:function(e,t,s,r){return r||(r=n.random(8)),e=i.create({keySize:t+s}).compute(e,r),s=n.create(e.words.slice(t),4*s),e.sigBytes=4*t,l.create({key:e,iv:s,salt:r})}},p=e.PasswordBasedCipher=h.extend({cfg:h.cfg.extend({kdf:d}),encrypt:function(e,t,n,s){return n=(s=this.cfg.extend(s)).kdf.execute(n,e.keySize,e.ivSize),s.iv=n.iv,(e=h.encrypt.call(this,e,t,n.key,s)).mixIn(n),e},decrypt:function(e,t,n,s){return s=this.cfg.extend(s),t=this._parse(t,s.format),n=s.kdf.execute(n,e.keySize,e.ivSize,t.salt),s.iv=n.iv,h.decrypt.call(this,e,t,n.key,s)}})}(),function(){for(var e=w,t=e.lib.BlockCipher,n=e.algo,s=[],r=[],i=[],a=[],o=[],c=[],u=[],l=[],h=[],d=[],p=[],g=0;256>g;g++)p[g]=128>g?g<<1:g<<1^283;var y=0,f=0;for(g=0;256>g;g++){var b=(b=f^f<<1^f<<2^f<<3^f<<4)>>>8^255&b^99;s[y]=b,r[b]=y;var m=p[y],v=p[m],S=p[v],O=257*p[b]^16843008*b;i[y]=O<<24|O>>>8,a[y]=O<<16|O>>>16,o[y]=O<<8|O>>>24,c[y]=O,O=16843009*S^65537*v^257*m^16843008*y,u[b]=O<<24|O>>>8,l[b]=O<<16|O>>>16,h[b]=O<<8|O>>>24,d[b]=O,y?(y=m^p[p[p[S^m]]],f^=p[p[f]]):y=f=1}var k=[0,1,2,4,8,16,32,64,128,27,54];n=n.AES=t.extend({_doReset:function(){for(var e=(n=this._key).words,t=n.sigBytes/4,n=4*((this._nRounds=t+6)+1),r=this._keySchedule=[],i=0;i>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a]):(a=s[(a=a<<8|a>>>24)>>>24]<<24|s[a>>>16&255]<<16|s[a>>>8&255]<<8|s[255&a],a^=k[i/t|0]<<24),r[i]=r[i-t]^a}for(e=this._invKeySchedule=[],t=0;tt||4>=i?a:u[s[a>>>24]]^l[s[a>>>16&255]]^h[s[a>>>8&255]]^d[s[255&a]]},encryptBlock:function(e,t){this._doCryptBlock(e,t,this._keySchedule,i,a,o,c,s)},decryptBlock:function(e,t){var n=e[t+1];e[t+1]=e[t+3],e[t+3]=n,this._doCryptBlock(e,t,this._invKeySchedule,u,l,h,d,r),n=e[t+1],e[t+1]=e[t+3],e[t+3]=n},_doCryptBlock:function(e,t,n,s,r,i,a,o){for(var c=this._nRounds,u=e[t]^n[0],l=e[t+1]^n[1],h=e[t+2]^n[2],d=e[t+3]^n[3],p=4,g=1;g>>24]^r[l>>>16&255]^i[h>>>8&255]^a[255&d]^n[p++],f=s[l>>>24]^r[h>>>16&255]^i[d>>>8&255]^a[255&u]^n[p++],b=s[h>>>24]^r[d>>>16&255]^i[u>>>8&255]^a[255&l]^n[p++];d=s[d>>>24]^r[u>>>16&255]^i[l>>>8&255]^a[255&h]^n[p++],u=y,l=f,h=b}y=(o[u>>>24]<<24|o[l>>>16&255]<<16|o[h>>>8&255]<<8|o[255&d])^n[p++],f=(o[l>>>24]<<24|o[h>>>16&255]<<16|o[d>>>8&255]<<8|o[255&u])^n[p++],b=(o[h>>>24]<<24|o[d>>>16&255]<<16|o[u>>>8&255]<<8|o[255&l])^n[p++],d=(o[d>>>24]<<24|o[u>>>16&255]<<16|o[l>>>8&255]<<8|o[255&h])^n[p++],e[t]=y,e[t+1]=f,e[t+2]=b,e[t+3]=d},keySize:8});e.AES=t._createHelper(n)}(),w.mode.ECB=((S=w.lib.BlockCipherMode.extend()).Encryptor=S.extend({processBlock:function(e,t){this._cipher.encryptBlock(e,t)}}),S.Decryptor=S.extend({processBlock:function(e,t){this._cipher.decryptBlock(e,t)}}),S);var O=t(w);class k{constructor({cipherKey:e}){this.cipherKey=e,this.CryptoJS=O,this.encryptedKey=this.CryptoJS.SHA256(e)}encrypt(e){if(0===("string"==typeof e?e:k.decoder.decode(e)).length)throw new Error("encryption error. empty content");const t=this.getIv();return{metadata:t,data:c(this.CryptoJS.AES.encrypt(e,this.encryptedKey,{iv:this.bufferToWordArray(t),mode:this.CryptoJS.mode.CBC}).ciphertext.toString(this.CryptoJS.enc.Base64))}}encryptFileData(e){return i(this,void 0,void 0,(function*(){const t=yield this.getKey(),n=this.getIv();return{data:yield crypto.subtle.encrypt({name:this.algo,iv:n},t,e),metadata:n}}))}decrypt(e){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=this.bufferToWordArray(new Uint8ClampedArray(e.metadata)),n=this.bufferToWordArray(new Uint8ClampedArray(e.data));return k.encoder.encode(this.CryptoJS.AES.decrypt({ciphertext:n},this.encryptedKey,{iv:t,mode:this.CryptoJS.mode.CBC}).toString(this.CryptoJS.enc.Utf8)).buffer}decryptFileData(e){return i(this,void 0,void 0,(function*(){if("string"==typeof e.data)throw new Error("Decryption error: data for decryption should be ArrayBuffed.");const t=yield this.getKey();return crypto.subtle.decrypt({name:this.algo,iv:e.metadata},t,e.data)}))}get identifier(){return"ACRH"}get algo(){return"AES-CBC"}getIv(){return crypto.getRandomValues(new Uint8Array(k.BLOCK_SIZE))}getKey(){return i(this,void 0,void 0,(function*(){const e=k.encoder.encode(this.cipherKey),t=yield crypto.subtle.digest("SHA-256",e.buffer);return crypto.subtle.importKey("raw",t,this.algo,!0,["encrypt","decrypt"])}))}bufferToWordArray(e){const t=[];let n;for(n=0;ne.toString(16).padStart(2,"0"))).join(""),s=P.encoder.encode(n.slice(0,32)).buffer;return crypto.subtle.importKey("raw",s,"AES-CBC",!0,["encrypt","decrypt"])}))}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}}P.IV_LENGTH=16,P.encoder=new TextEncoder,P.decoder=new TextDecoder;class N{constructor(e){this.config=e,this.cryptor=new C(Object.assign({},e)),this.fileCryptor=new P}encrypt(e){const t="string"==typeof e?e:N.decoder.decode(e);return{data:this.cryptor.encrypt(t),metadata:null}}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.encryptFile(null===(n=this.config)||void 0===n?void 0:n.cipherKey,e,t)}))}decrypt(e){const t="string"==typeof e.data?e.data:u(e.data);return this.cryptor.decrypt(t)}decryptFile(e,t){return i(this,void 0,void 0,(function*(){if(!this.config.cipherKey)throw new d("File encryption error: cipher key not set.");return this.fileCryptor.decryptFile(this.config.cipherKey,e,t)}))}get identifier(){return""}}N.encoder=new TextEncoder,N.decoder=new TextDecoder;class M extends a{static legacyCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t})),cryptors:[new k({cipherKey:e.cipherKey})]})}static aesCbcCryptoModule(e){var t;if(!e.cipherKey)throw new d("Crypto module error: cipher key not set.");return new M({default:new k({cipherKey:e.cipherKey}),cryptors:[new N(Object.assign(Object.assign({},e),{useRandomIVs:null===(t=e.useRandomIVs)||void 0===t||t}))]})}static withDefaultCryptor(e){return new this({default:e})}encrypt(e){const t=e instanceof ArrayBuffer&&this.defaultCryptor.identifier===M.LEGACY_IDENTIFIER?this.defaultCryptor.encrypt(M.decoder.decode(e)):this.defaultCryptor.encrypt(e);if(!t.metadata)return t.data;if("string"==typeof t.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");const n=this.getHeaderData(t);return this.concatArrayBuffer(n,t.data)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){if(this.defaultCryptor.identifier===j.LEGACY_IDENTIFIER)return this.defaultCryptor.encryptFile(e,t);const n=yield this.getFileData(e),s=yield this.defaultCryptor.encryptFileData(n);if("string"==typeof s.data)throw new Error("Encryption error: encrypted data should be ArrayBuffed.");return t.create({name:e.name,mimeType:"application/octet-stream",data:this.concatArrayBuffer(this.getHeaderData(s),s.data)})}))}decrypt(e){const t="string"==typeof e?c(e):e,n=j.tryParse(t),s=this.getCryptor(n),r=n.length>0?t.slice(n.length-n.metadataLength,n.length):null;if(t.slice(n.length).byteLength<=0)throw new Error("Decryption error: empty content");return s.decrypt({data:t.slice(n.length),metadata:r})}decryptFile(e,t){return i(this,void 0,void 0,(function*(){const n=yield e.data.arrayBuffer(),s=j.tryParse(n),r=this.getCryptor(s);if((null==r?void 0:r.identifier)===j.LEGACY_IDENTIFIER)return r.decryptFile(e,t);const i=(yield this.getFileData(n)).slice(s.length-s.metadataLength,s.length);return t.create({name:e.name,data:yield this.defaultCryptor.decryptFileData({data:n.slice(s.length),metadata:i})})}))}getCryptorFromId(e){const t=this.getAllCryptors().find((t=>e===t.identifier));if(t)return t;throw Error("Unknown cryptor error")}getCryptor(e){if("string"==typeof e){const t=this.getAllCryptors().find((t=>t.identifier===e));if(t)return t;throw new Error("Unknown cryptor error")}if(e instanceof A)return this.getCryptorFromId(e.identifier)}getHeaderData(e){if(!e.metadata)return;const t=j.from(this.defaultCryptor.identifier,e.metadata),n=new Uint8Array(t.length);let s=0;return n.set(t.data,s),s+=t.length-e.metadata.byteLength,n.set(new Uint8Array(e.metadata),s),n.buffer}concatArrayBuffer(e,t){const n=new Uint8Array(e.byteLength+t.byteLength);return n.set(new Uint8Array(e),0),n.set(new Uint8Array(t),e.byteLength),n.buffer}getFileData(e){return i(this,void 0,void 0,(function*(){if(e instanceof ArrayBuffer)return e;if(e instanceof o)return e.toArrayBuffer();throw new Error("Cannot decrypt/encrypt file. In browsers file encrypt/decrypt supported for string, ArrayBuffer or Blob")}))}}M.LEGACY_IDENTIFIER="";class j{static from(e,t){if(e!==j.LEGACY_IDENTIFIER)return new A(e,t.byteLength)}static tryParse(e){const t=new Uint8Array(e);let n,s,r=null;if(t.byteLength>=4&&(n=t.slice(0,4),this.decoder.decode(n)!==j.SENTINEL))return M.LEGACY_IDENTIFIER;if(!(t.byteLength>=5))throw new Error("Decryption error: invalid header version");if(r=t[4],r>j.MAX_VERSION)throw new Error("Decryption error: Unknown cryptor error");let i=5+j.IDENTIFIER_LENGTH;if(!(t.byteLength>=i))throw new Error("Decryption error: invalid crypto identifier");s=t.slice(5,i);let a=null;if(!(t.byteLength>=i+1))throw new Error("Decryption error: invalid metadata length");return a=t[i],i+=1,255===a&&t.byteLength>=i+2&&(a=new Uint16Array(t.slice(i,i+2)).reduce(((e,t)=>(e<<8)+t),0)),new A(this.decoder.decode(s),a)}}j.SENTINEL="PNED",j.LEGACY_IDENTIFIER="",j.IDENTIFIER_LENGTH=4,j.VERSION=1,j.MAX_VERSION=1,j.decoder=new TextDecoder;class A{constructor(e,t){this._identifier=e,this._metadataLength=t}get identifier(){return this._identifier}set identifier(e){this._identifier=e}get metadataLength(){return this._metadataLength}set metadataLength(e){this._metadataLength=e}get version(){return j.VERSION}get length(){return j.SENTINEL.length+1+j.IDENTIFIER_LENGTH+(this.metadataLength<255?1:3)+this.metadataLength}get data(){let e=0;const t=new Uint8Array(this.length),n=new TextEncoder;t.set(n.encode(j.SENTINEL)),e+=j.SENTINEL.length,t[e]=this.version,e++,this.identifier&&t.set(n.encode(this.identifier),e);const s=this.metadataLength;return e+=j.IDENTIFIER_LENGTH,s<255?t[e]=s:t.set([255,s>>8,255&s],e),t}}A.IDENTIFIER_LENGTH=4,A.SENTINEL="PNED";class _ extends Error{static create(e,t){return _.isErrorObject(e)?_.createFromError(e):_.createFromServiceResponse(e,t)}static createFromError(e){let t=h.PNUnknownCategory,n="Unknown error",s="Error";if(!e)return new _(n,t,0);if(e instanceof _)return e;if(_.isErrorObject(e)&&(n=e.message,s=e.name),"AbortError"===s||-1!==n.indexOf("Aborted"))t=h.PNCancelledCategory,n="Request cancelled";else if(-1!==n.toLowerCase().indexOf("timeout"))t=h.PNTimeoutCategory,n="Request timeout";else if(-1!==n.toLowerCase().indexOf("network"))t=h.PNNetworkIssuesCategory,n="Network issues";else if("TypeError"===s)t=-1!==n.indexOf("Load failed")||-1!=n.indexOf("Failed to fetch")?h.PNNetworkIssuesCategory:h.PNBadRequestCategory;else if("FetchError"===s){const s=e.code;["ECONNREFUSED","ENETUNREACH","ENOTFOUND","ECONNRESET","EAI_AGAIN"].includes(s)&&(t=h.PNNetworkIssuesCategory),"ECONNREFUSED"===s?n="Connection refused":"ENETUNREACH"===s?n="Network not reachable":"ENOTFOUND"===s?n="Server not found":"ECONNRESET"===s?n="Connection reset by peer":"EAI_AGAIN"===s?n="Name resolution error":"ETIMEDOUT"===s?(t=h.PNTimeoutCategory,n="Request timeout"):n=`Unknown system error: ${e}`}else"Request timeout"===n&&(t=h.PNTimeoutCategory);return new _(n,t,0,e)}static createFromServiceResponse(e,t){let n,s=h.PNUnknownCategory,r="Unknown error",{status:i}=e;if(null!=t||(t=e.body),402===i?r="Not available for used key set. Contact support@pubnub.com":400===i?(s=h.PNBadRequestCategory,r="Bad request"):403===i&&(s=h.PNAccessDeniedCategory,r="Access denied"),"object"==typeof e&&0===Object.keys(e).length&&(s=h.PNMalformedResponseCategory,r="Malformed response (network issues)",i=400),t&&t.byteLength>0){const s=(new TextDecoder).decode(t);if(-1!==e.headers["content-type"].indexOf("text/javascript")||-1!==e.headers["content-type"].indexOf("application/json"))try{const e=JSON.parse(s);"object"==typeof e&&(Array.isArray(e)?"number"==typeof e[0]&&0===e[0]&&e.length>1&&"string"==typeof e[1]&&(n=e[1]):("error"in e&&(1===e.error||!0===e.error)&&"status"in e&&"number"==typeof e.status&&"message"in e&&"service"in e?(n=e,i=e.status):n=e,"error"in e&&e.error instanceof Error&&(n=e.error)))}catch(e){n=s}else if(-1!==e.headers["content-type"].indexOf("xml")){const e=/(.*)<\/Message>/gi.exec(s);r=e?`Upload to bucket failed: ${e[1]}`:"Upload to bucket failed."}else n=s}return new _(r,s,i,n)}constructor(e,t,n,s){super(e),this.category=t,this.statusCode=n,this.errorData=s,this.name="PubNubAPIError"}toStatus(e){return{error:!0,category:this.category,operation:e,statusCode:this.statusCode,errorData:this.errorData,toJSON:function(){let e;const t=this.errorData;if(t)try{if("object"==typeof t){const n=Object.assign(Object.assign(Object.assign(Object.assign({},"name"in t?{name:t.name}:{}),"message"in t?{message:t.message}:{}),"stack"in t?{stack:t.stack}:{}),t);e=JSON.parse(JSON.stringify(n,_.circularReplacer()))}else e=t}catch(t){e={error:"Could not serialize the error object"}}const n=r(this,["toJSON"]);return JSON.stringify(Object.assign(Object.assign({},n),{errorData:e}))}}}toPubNubError(e,t){return new d(null!=t?t:this.message,this.toStatus(e))}static circularReplacer(){const e=new WeakSet;return function(t,n){if("object"==typeof n&&null!==n){if(e.has(n))return"[Circular]";e.add(n)}return n}}static isErrorObject(e){return!(!e||"object"!=typeof e)&&(e instanceof Error||("name"in e&&"message"in e&&"string"==typeof e.name&&"string"==typeof e.message||"[object Error]"===Object.prototype.toString.call(e)))}}class I{constructor(e){this.configuration=e,this.subscriptionWorkerReady=!1,this.accessTokensMap={},this.workerEventsQueue=[],this.callbacks=new Map,this.setupSubscriptionWorker()}terminate(){this.scheduleEventPost({type:"client-unregister",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity})}makeSendable(e){if(!e.path.startsWith("/v2/subscribe")&&!e.path.endsWith("/heartbeat")&&!e.path.endsWith("/leave"))return this.configuration.transport.makeSendable(e);let t;const n={type:"send-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,request:e};return e.cancellable&&(t={abort:()=>{const t={type:"cancel-request",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,logVerbosity:this.configuration.logVerbosity,identifier:e.identifier};this.scheduleEventPost(t)}}),[new Promise(((t,s)=>{this.callbacks.set(e.identifier,{resolve:t,reject:s}),this.parsedAccessTokenForRequest(e).then((e=>n.token=e)).then((()=>this.scheduleEventPost(n)))})),t]}request(e){return e}scheduleEventPost(e,t=!1){const n=this.sharedSubscriptionWorker;n?n.port.postMessage(e):t?this.workerEventsQueue.splice(0,0,e):this.workerEventsQueue.push(e)}flushScheduledEvents(){const e=this.sharedSubscriptionWorker;if(!e||0===this.workerEventsQueue.length)return;const t=[];for(let e=0;e!t.includes(e))),this.workerEventsQueue.forEach((t=>e.port.postMessage(t))),this.workerEventsQueue=[]}get sharedSubscriptionWorker(){return this.subscriptionWorkerReady?this.subscriptionWorker:null}setupSubscriptionWorker(){"undefined"!=typeof SharedWorker&&(this.subscriptionWorker=new SharedWorker(this.configuration.workerUrl,`/pubnub-${this.configuration.sdkVersion}`),this.subscriptionWorker.port.start(),this.scheduleEventPost({type:"client-register",clientIdentifier:this.configuration.clientIdentifier,subscriptionKey:this.configuration.subscriptionKey,userId:this.configuration.userId,heartbeatInterval:this.configuration.heartbeatInterval,logVerbosity:this.configuration.logVerbosity,workerOfflineClientsCheckInterval:this.configuration.workerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:this.configuration.workerUnsubscribeOfflineClients,workerLogVerbosity:this.configuration.workerLogVerbosity},!0),this.subscriptionWorker.port.onmessage=e=>this.handleWorkerEvent(e))}handleWorkerEvent(e){const{data:t}=e;if("shared-worker-ping"===t.type||"shared-worker-connected"===t.type||"shared-worker-console-log"===t.type||"shared-worker-console-dir"===t.type||t.clientIdentifier===this.configuration.clientIdentifier)if("shared-worker-connected"===t.type)this.subscriptionWorkerReady=!0,this.flushScheduledEvents();else if("shared-worker-console-log"===t.type)console.log(`[SharedWorker] ${t.message}`);else if("shared-worker-console-dir"===t.type)t.message&&console.log(`[SharedWorker] ${t.message}`),console.dir(t.data,{depth:10});else if("shared-worker-ping"===t.type){const{logVerbosity:e,subscriptionKey:t,clientIdentifier:n}=this.configuration;this.scheduleEventPost({type:"client-pong",subscriptionKey:t,clientIdentifier:n,logVerbosity:e})}else if("request-progress-start"===t.type||"request-progress-end"===t.type)this.logRequestProgress(t);else if("request-process-success"===t.type||"request-process-error"===t.type){const{resolve:e,reject:n}=this.callbacks.get(t.identifier);if("request-process-success"===t.type)e({status:t.response.status,url:t.url,headers:t.response.headers,body:t.response.body});else{let e=h.PNUnknownCategory,s="Unknown error";if(t.error)"NETWORK_ISSUE"===t.error.type?e=h.PNNetworkIssuesCategory:"TIMEOUT"===t.error.type?e=h.PNTimeoutCategory:"ABORTED"===t.error.type&&(e=h.PNCancelledCategory),s=`${t.error.message} (${t.identifier})`;else if(t.response)return n(_.create({url:t.url,headers:t.response.headers,body:t.response.body,status:t.response.status},t.response.body));n(new _(s,e,0,new Error(s)))}}}parsedAccessTokenForRequest(e){return i(this,void 0,void 0,(function*(){var t;const n=e.queryParameters?null!==(t=e.queryParameters.auth)&&void 0!==t?t:"":void 0;if(n)return this.accessTokensMap[n]?this.accessTokensMap[n]:this.stringifyAccessToken(n).then((([e,t])=>{if(e&&t)return(this.accessTokensMap={[n]:{token:t,expiration:e.timestamp*e.ttl*60}})[n]}))}))}stringifyAccessToken(e){return i(this,void 0,void 0,(function*(){if(!this.configuration.tokenManager)return[void 0,void 0];const t=this.configuration.tokenManager.parseToken(e);if(!t)return[void 0,void 0];const n=e=>e?Object.entries(e).sort((([e],[t])=>e.localeCompare(t))).map((([e,t])=>Object.entries(t||{}).sort((([e],[t])=>e.localeCompare(t))).map((([t,n])=>{return`${e}:${t}=${n?(s=n,Object.entries(s).filter((([e,t])=>t)).map((([e])=>e[0])).sort().join("")):""}`;var s})).join(","))).join(";"):"";let s=[n(t.resources),n(t.patterns),t.authorized_uuid].filter(Boolean).join("|");if("undefined"!=typeof crypto&&crypto.subtle){const e=yield crypto.subtle.digest("SHA-256",(new TextEncoder).encode(s));s=String.fromCharCode(...Array.from(new Uint8Array(e)))}return[t,"undefined"!=typeof btoa?btoa(s):s]}))}logRequestProgress(e){var t,n;"request-progress-start"===e.type?(console.log("<<<<<"),console.log(`[${e.timestamp}] ${e.url}\n${JSON.stringify(null!==(t=e.query)&&void 0!==t?t:{})}`),console.log("-----")):(console.log(">>>>>>"),console.log(`[${e.timestamp} / ${e.duration}] ${e.url}\n${JSON.stringify(null!==(n=e.query)&&void 0!==n?n:{})}\n${e.response}`),console.log("-----"))}}function F(e){const t=e=>"object"==typeof e&&null!==e&&e.constructor===Object,n=e=>"number"==typeof e&&isFinite(e);if(!t(e))return e;const s={};return Object.keys(e).forEach((r=>{const i=(e=>"string"==typeof e||e instanceof String)(r);let a=r;const o=e[r];if(i&&r.indexOf(",")>=0){a=r.split(",").map(Number).reduce(((e,t)=>e+String.fromCharCode(t)),"")}else(n(r)||i&&!isNaN(Number(r)))&&(a=String.fromCharCode(n(r)?r:parseInt(r,10)));s[a]=t(o)?F(o):o})),s}const T=e=>{var t,n,s,r,i,a;return e.subscriptionWorkerUrl&&"undefined"==typeof SharedWorker&&(e.subscriptionWorkerUrl=null),Object.assign(Object.assign({},(e=>{var t,n,s,r,i,a,o,c,u,l,h,p,g,y,f,b;const m=Object.assign({},e);if(null!==(t=m.logVerbosity)&&void 0!==t||(m.logVerbosity=!1),null!==(n=m.ssl)&&void 0!==n||(m.ssl=!0),null!==(s=m.transactionalRequestTimeout)&&void 0!==s||(m.transactionalRequestTimeout=15),null!==(r=m.subscribeRequestTimeout)&&void 0!==r||(m.subscribeRequestTimeout=310),null!==(i=m.fileRequestTimeout)&&void 0!==i||(m.fileRequestTimeout=300),null!==(a=m.restore)&&void 0!==a||(m.restore=!1),null!==(o=m.useInstanceId)&&void 0!==o||(m.useInstanceId=!1),null!==(c=m.suppressLeaveEvents)&&void 0!==c||(m.suppressLeaveEvents=!1),null!==(u=m.requestMessageCountThreshold)&&void 0!==u||(m.requestMessageCountThreshold=100),null!==(l=m.autoNetworkDetection)&&void 0!==l||(m.autoNetworkDetection=!1),null!==(h=m.enableEventEngine)&&void 0!==h||(m.enableEventEngine=!1),null!==(p=m.maintainPresenceState)&&void 0!==p||(m.maintainPresenceState=!0),null!==(g=m.useSmartHeartbeat)&&void 0!==g||(m.useSmartHeartbeat=!1),null!==(y=m.keepAlive)&&void 0!==y||(m.keepAlive=!1),m.userId&&m.uuid)throw new d("PubNub client configuration error: use only 'userId'");if(null!==(f=m.userId)&&void 0!==f||(m.userId=m.uuid),!m.userId)throw new d("PubNub client configuration error: 'userId' not set");if(0===(null===(b=m.userId)||void 0===b?void 0:b.trim().length))throw new d("PubNub client configuration error: 'userId' is empty");m.origin||(m.origin=Array.from({length:20},((e,t)=>`ps${t+1}.pndsn.com`)));const v={subscribeKey:m.subscribeKey,publishKey:m.publishKey,secretKey:m.secretKey};void 0!==m.presenceTimeout&&(m.presenceTimeout>320?(m.presenceTimeout=320,console.warn("WARNING: Presence timeout is larger than the maximum. Using maximum value: ",320)):m.presenceTimeout<=0&&(console.warn("WARNING: Presence timeout should be larger than zero."),delete m.presenceTimeout)),void 0!==m.presenceTimeout?m.heartbeatInterval=m.presenceTimeout/2-1:m.presenceTimeout=300;let S=!1,w=!0,O=5,k=!1,E=100,C=!0;return void 0!==m.dedupeOnSubscribe&&"boolean"==typeof m.dedupeOnSubscribe&&(k=m.dedupeOnSubscribe),void 0!==m.maximumCacheSize&&"number"==typeof m.maximumCacheSize&&(E=m.maximumCacheSize),void 0!==m.useRequestId&&"boolean"==typeof m.useRequestId&&(C=m.useRequestId),void 0!==m.announceSuccessfulHeartbeats&&"boolean"==typeof m.announceSuccessfulHeartbeats&&(S=m.announceSuccessfulHeartbeats),void 0!==m.announceFailedHeartbeats&&"boolean"==typeof m.announceFailedHeartbeats&&(w=m.announceFailedHeartbeats),void 0!==m.fileUploadPublishRetryLimit&&"number"==typeof m.fileUploadPublishRetryLimit&&(O=m.fileUploadPublishRetryLimit),Object.assign(Object.assign({},m),{keySet:v,dedupeOnSubscribe:k,maximumCacheSize:E,useRequestId:C,announceSuccessfulHeartbeats:S,announceFailedHeartbeats:w,fileUploadPublishRetryLimit:O})})(e)),{listenToBrowserNetworkEvents:null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t,subscriptionWorkerUrl:e.subscriptionWorkerUrl,subscriptionWorkerOfflineClientsCheckInterval:null!==(n=e.subscriptionWorkerOfflineClientsCheckInterval)&&void 0!==n?n:10,subscriptionWorkerUnsubscribeOfflineClients:null!==(s=e.subscriptionWorkerUnsubscribeOfflineClients)&&void 0!==s&&s,subscriptionWorkerLogVerbosity:null!==(r=e.subscriptionWorkerLogVerbosity)&&void 0!==r&&r,transport:null!==(i=e.transport)&&void 0!==i?i:"fetch",keepAlive:null===(a=e.keepAlive)||void 0===a||a})};var R;!function(e){e.Unknown="UnknownEndpoint",e.MessageSend="MessageSendEndpoint",e.Subscribe="SubscribeEndpoint",e.Presence="PresenceEndpoint",e.Files="FilesEndpoint",e.MessageStorage="MessageStorageEndpoint",e.ChannelGroups="ChannelGroupsEndpoint",e.DevicePushNotifications="DevicePushNotificationsEndpoint",e.AppContext="AppContextEndpoint",e.MessageReactions="MessageReactionsEndpoint"}(R||(R={}));class U{static None(){return{shouldRetry:(e,t,n,s)=>!1,getDelay:(e,t)=>-1,validate:()=>!0}}static LinearRetryPolicy(e){var t;return{delay:e.delay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=this.delay),1e3*(n+Math.random())},validate(){if(this.delay<2)throw new Error("Delay can not be set less than 2 seconds for retry");if(this.maximumRetry>10)throw new Error("Maximum retry for linear retry policy can not be more than 10")}}}static ExponentialRetryPolicy(e){var t;return{minimumDelay:e.minimumDelay,maximumDelay:e.maximumDelay,maximumRetry:e.maximumRetry,excluded:null!==(t=e.excluded)&&void 0!==t?t:[],shouldRetry(e,t,n,s){return x(e,t,n,null!=s?s:0,this.maximumRetry,this.excluded)},getDelay(e,t){let n=-1;return t&&void 0!==t.headers["retry-after"]&&(n=parseInt(t.headers["retry-after"],10)),-1===n&&(n=Math.min(Math.pow(2,e),this.maximumDelay)),1e3*(n+Math.random())},validate(){if(this.minimumDelay<2)throw new Error("Minimum delay can not be set less than 2 seconds for retry");if(this.maximumDelay>150)throw new Error("Maximum delay can not be set more than 150 seconds for retry");if(this.maximumRetry>6)throw new Error("Maximum retry for exponential retry policy can not be more than 6")}}}}const x=(e,t,n,s,r,i)=>(!n||n!==h.PNCancelledCategory&&n!==h.PNBadRequestCategory&&n!==h.PNAccessDeniedCategory)&&(!D(e,i)&&(!(s>r)&&(!t||(429===t.status||t.status>=500)))),D=(e,t)=>!!(t&&t.length>0)&&t.includes(q(e)),q=e=>{let t=R.Unknown;return e.path.startsWith("/v2/subscribe")?t=R.Subscribe:e.path.startsWith("/publish/")||e.path.startsWith("/signal/")?t=R.MessageSend:e.path.startsWith("/v2/presence")?t=R.Presence:e.path.startsWith("/v2/history")||e.path.startsWith("/v3/history")?t=R.MessageStorage:e.path.startsWith("/v1/message-actions/")?t=R.MessageReactions:e.path.startsWith("/v1/channel-registration/")||e.path.startsWith("/v2/objects/")?t=R.ChannelGroups:e.path.startsWith("/v1/push/")||e.path.startsWith("/v2/push/")?t=R.DevicePushNotifications:e.path.startsWith("/v1/files/")&&(t=R.Files),t};var L={exports:{}}; +/*! lil-uuid - v0.1 - MIT License - https://github.com/lil-js/uuid */!function(e,t){!function(e){var t="0.1.0",n={3:/^[0-9A-F]{8}-[0-9A-F]{4}-3[0-9A-F]{3}-[0-9A-F]{4}-[0-9A-F]{12}$/i,4:/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,5:/^[0-9A-F]{8}-[0-9A-F]{4}-5[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i,all:/^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i};function s(){var e,t,n="";for(e=0;e<32;e++)t=16*Math.random()|0,8!==e&&12!==e&&16!==e&&20!==e||(n+="-"),n+=(12===e?4:16===e?3&t|8:t).toString(16);return n}function r(e,t){var s=n[t||"all"];return s&&s.test(e)||!1}s.isUUID=r,s.VERSION=t,e.uuid=s,e.isUUID=r}(t),null!==e&&(e.exports=t.uuid)}(L,L.exports);var G=t(L.exports),K={createUUID:()=>G.uuid?G.uuid():G()};const $=(e,t)=>{var n,s,r;!e.retryConfiguration&&e.enableEventEngine&&(e.retryConfiguration=U.ExponentialRetryPolicy({minimumDelay:2,maximumDelay:150,maximumRetry:6,excluded:[R.MessageSend,R.Presence,R.Files,R.MessageStorage,R.ChannelGroups,R.DevicePushNotifications,R.AppContext,R.MessageReactions]})),null===(n=e.retryConfiguration)||void 0===n||n.validate(),null!==(s=e.useRandomIVs)&&void 0!==s||(e.useRandomIVs=true),e.origin=B(null!==(r=e.ssl)&&void 0!==r&&r,e.origin);const i=e.cryptoModule;i&&delete e.cryptoModule;const a=Object.assign(Object.assign({},e),{_pnsdkSuffix:{},_instanceId:`pn-${K.createUUID()}`,_cryptoModule:void 0,_cipherKey:void 0,_setupCryptoModule:t,get instanceId(){if(this.useInstanceId)return this._instanceId},getInstanceId(){if(this.useInstanceId)return this._instanceId},getUserId(){return this.userId},setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this.userId=e},getAuthKey(){return this.authKey},setAuthKey(e){this.authKey=e},getFilterExpression(){return this.filterExpression},setFilterExpression(e){this.filterExpression=e},getCipherKey(){return this._cipherKey},setCipherKey(t){this._cipherKey=t,t||!this._cryptoModule?t&&this._setupCryptoModule&&(this._cryptoModule=this._setupCryptoModule({cipherKey:t,useRandomIVs:e.useRandomIVs,customEncrypt:this.getCustomEncrypt(),customDecrypt:this.getCustomDecrypt()})):this._cryptoModule=void 0},getCryptoModule(){return this._cryptoModule},getUseRandomIVs:()=>e.useRandomIVs,getKeepPresenceChannelsInPresenceRequests:()=>"Web"===e.sdkFamily&&e.subscriptionWorkerUrl,setPresenceTimeout(e){this.heartbeatInterval=e/2-1,this.presenceTimeout=e},getPresenceTimeout(){return this.presenceTimeout},getHeartbeatInterval(){return this.heartbeatInterval},setHeartbeatInterval(e){this.heartbeatInterval=e},getTransactionTimeout(){return this.transactionalRequestTimeout},getSubscribeTimeout(){return this.subscribeRequestTimeout},getFileTimeout(){return this.fileRequestTimeout},get PubNubFile(){return e.PubNubFile},get version(){return"9.5.2"},getVersion(){return this.version},_addPnsdkSuffix(e,t){this._pnsdkSuffix[e]=`${t}`},_getPnsdkSuffix(e){const t=Object.values(this._pnsdkSuffix).join(e);return t.length>0?e+t:""},getUUID(){return this.getUserId()},setUUID(e){this.setUserId(e)},getCustomEncrypt:()=>e.customEncrypt,getCustomDecrypt:()=>e.customDecrypt});return e.cipherKey?a.setCipherKey(e.cipherKey):i&&(a._cryptoModule=i),a},B=(e,t)=>{const n=e?"https://":"http://";return"string"==typeof t?`${n}${t}`:`${n}${t[Math.floor(Math.random()*t.length)]}`};class H{constructor(e){this.cbor=e}setToken(e){e&&e.length>0?this.token=e:this.token=void 0}getToken(){return this.token}parseToken(e){const t=this.cbor.decodeToken(e);if(void 0!==t){const e=t.res.uuid?Object.keys(t.res.uuid):[],n=Object.keys(t.res.chan),s=Object.keys(t.res.grp),r=t.pat.uuid?Object.keys(t.pat.uuid):[],i=Object.keys(t.pat.chan),a=Object.keys(t.pat.grp),o={version:t.v,timestamp:t.t,ttl:t.ttl,authorized_uuid:t.uuid,signature:t.sig},c=e.length>0,u=n.length>0,l=s.length>0;if(c||u||l){if(o.resources={},c){const n=o.resources.uuids={};e.forEach((e=>n[e]=this.extractPermissions(t.res.uuid[e])))}if(u){const e=o.resources.channels={};n.forEach((n=>e[n]=this.extractPermissions(t.res.chan[n])))}if(l){const e=o.resources.groups={};s.forEach((n=>e[n]=this.extractPermissions(t.res.grp[n])))}}const h=r.length>0,d=i.length>0,p=a.length>0;if(h||d||p){if(o.patterns={},h){const e=o.patterns.uuids={};r.forEach((n=>e[n]=this.extractPermissions(t.pat.uuid[n])))}if(d){const e=o.patterns.channels={};i.forEach((n=>e[n]=this.extractPermissions(t.pat.chan[n])))}if(p){const e=o.patterns.groups={};a.forEach((n=>e[n]=this.extractPermissions(t.pat.grp[n])))}}return t.meta&&Object.keys(t.meta).length>0&&(o.meta=t.meta),o}}extractPermissions(e){const t={read:!1,write:!1,manage:!1,delete:!1,get:!1,update:!1,join:!1};return 128&~e||(t.join=!0),64&~e||(t.update=!0),32&~e||(t.get=!0),8&~e||(t.delete=!0),4&~e||(t.manage=!0),2&~e||(t.write=!0),1&~e||(t.read=!0),t}}var W;!function(e){e.GET="GET",e.POST="POST",e.PATCH="PATCH",e.DELETE="DELETE",e.LOCAL="LOCAL"}(W||(W={}));const V=e=>encodeURIComponent(e).replace(/[!~*'()]/g,(e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`)),z=(e,t)=>{const n=e.map((e=>V(e)));return n.length?n.join(","):null!=t?t:""},J=(e,t)=>{const n=Object.fromEntries(t.map((e=>[e,!1])));return e.filter((e=>!(t.includes(e)&&!n[e])||(n[e]=!0,!1)))},X=(e,t)=>[...e].filter((n=>t.includes(n)&&e.indexOf(n)===e.lastIndexOf(n)&&t.indexOf(n)===t.lastIndexOf(n)));class Q{constructor(e,t,n){this.publishKey=e,this.secretKey=t,this.hasher=n}signature(e){const t=e.path.startsWith("/publish")?W.GET:e.method;let n=`${t}\n${this.publishKey}\n${e.path}\n${this.queryParameters(e.queryParameters)}\n`;if(t===W.POST||t===W.PATCH){const t=e.body;let s;t&&t instanceof ArrayBuffer?s=Q.textDecoder.decode(t):t&&"object"!=typeof t&&(s=t),s&&(n+=s)}return`v2.${this.hasher(n,this.secretKey)}`.replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}queryParameters(e){return Object.keys(e).sort().map((t=>{const n=e[t];return Array.isArray(n)?n.sort().map((e=>`${t}=${V(e)}`)).join("&"):`${t}=${V(n)}`})).join("&")}}Q.textDecoder=new TextDecoder("utf-8");class Y{constructor(e){this.configuration=e;const{clientConfiguration:{keySet:t},shaHMAC:n}=e;t.secretKey&&n&&(this.signatureGenerator=new Q(t.publishKey,t.secretKey,n))}makeSendable(e){const t=this.configuration.clientConfiguration.retryConfiguration,n=this.configuration.transport;if(void 0!==t){let s,r,i=!1,a=0;const o={abort:e=>{i=!0,s&&clearTimeout(s),r&&r.abort(e)}};return[new Promise(((o,c)=>{const u=()=>{if(i)return;const[l,d]=n.makeSendable(this.request(e));r=d;const p=(n,r)=>{const i=!r||r.category!==h.PNCancelledCategory,l=!n||n.status>=400;let d=-1;i&&l&&t.shouldRetry(e,n,null==r?void 0:r.category,a+1)&&(d=t.getDelay(a,n)),d>0?(a++,s=setTimeout((()=>u()),d)):n?o(n):r&&c(r)};l.then((e=>p(e))).catch((e=>p(void 0,e)))};u()})),r?o:void 0]}return n.makeSendable(this.request(e))}request(e){var t;const{clientConfiguration:n}=this.configuration;return(e=this.configuration.transport.request(e)).queryParameters||(e.queryParameters={}),n.useInstanceId&&(e.queryParameters.instanceid=n.getInstanceId()),e.queryParameters.uuid||(e.queryParameters.uuid=n.userId),n.useRequestId&&(e.queryParameters.requestid=e.identifier),e.queryParameters.pnsdk=this.generatePNSDK(),null!==(t=e.origin)&&void 0!==t||(e.origin=n.origin),this.authenticateRequest(e),this.signRequest(e),e}authenticateRequest(e){var t;if(e.path.startsWith("/v2/auth/")||e.path.startsWith("/v3/pam/")||e.path.startsWith("/time"))return;const{clientConfiguration:n,tokenManager:s}=this.configuration,r=null!==(t=s&&s.getToken())&&void 0!==t?t:n.authKey;r&&(e.queryParameters.auth=r)}signRequest(e){this.signatureGenerator&&!e.path.startsWith("/time")&&(e.queryParameters.timestamp=String(Math.floor((new Date).getTime()/1e3)),e.queryParameters.signature=this.signatureGenerator.signature(e))}generatePNSDK(){const{clientConfiguration:e}=this.configuration;if(e.sdkName)return e.sdkName;let t=`PubNub-JS-${e.sdkFamily}`;e.partnerId&&(t+=`-${e.partnerId}`),t+=`/${e.getVersion()}`;const n=e._getPnsdkSuffix(" ");return n.length>0&&(t+=n),t}}class Z{constructor(e="fetch",t=!1,n=!1){if(this.transport=e,this.keepAlive=t,this.logVerbosity=n,"fetch"!==e||window&&window.fetch||(this.transport="xhr"),"fetch"===this.transport&&(Z.originalFetch=fetch.bind(window),this.isFetchMonkeyPatched())){if(Z.originalFetch=Z.getOriginalFetch(),!n)return;console.warn("[PubNub] Native Web Fetch API 'fetch' function monkey patched."),this.isFetchMonkeyPatched(Z.originalFetch)?console.warn("[PubNub] Unable receive native Web Fetch API. There can be issues with subscribe long-poll cancellation"):console.info("[PubNub] Use native Web Fetch API 'fetch' implementation from iframe as APM workaround.")}}makeSendable(e){const t=new AbortController,n={abortController:t,abort:e=>!t.signal.aborted&&t.abort(e)};return[this.webTransportRequestFromTransportRequest(e).then((t=>{const s=(new Date).getTime();return this.logRequestProcessProgress(t,e.body),this.sendRequest(t,n).then((e=>e.arrayBuffer().then((t=>[e,t])))).then((e=>{const n=e[1].byteLength>0?e[1]:void 0,{status:r,headers:i}=e[0],a={};i.forEach(((e,t)=>a[t]=e.toLowerCase()));const o={status:r,url:t.url,headers:a,body:n};if(r>=400)throw _.create(o);return this.logRequestProcessProgress(t,void 0,(new Date).getTime()-s,n),o})).catch((e=>{let t=e;if("string"==typeof e){const n=e.toLowerCase();t=new Error(e),!n.includes("timeout")&&n.includes("cancel")&&(t.name="AbortError")}throw _.create(t)}))})),n]}request(e){return e}sendRequest(e,t){return i(this,void 0,void 0,(function*(){return"fetch"===this.transport?this.sendFetchRequest(e,t):this.sendXHRRequest(e,t)}))}sendFetchRequest(e,t){return i(this,void 0,void 0,(function*(){let n;const s=new Promise(((s,r)=>{n=setTimeout((()=>{clearTimeout(n),r(new Error("Request timeout")),t.abort("Cancel because of timeout")}),1e3*e.timeout)})),r=new Request(e.url,{method:e.method,headers:e.headers,redirect:"follow",body:e.body});return Promise.race([Z.originalFetch(r,{signal:t.abortController.signal,credentials:"omit",cache:"no-cache"}).then((e=>(n&&clearTimeout(n),e))),s])}))}sendXHRRequest(e,t){return i(this,void 0,void 0,(function*(){return new Promise(((n,s)=>{var r;const i=new XMLHttpRequest;i.open(e.method,e.url,!0),i.responseType="arraybuffer",i.timeout=1e3*e.timeout,t.abortController.signal.onabort=()=>{i.readyState!=XMLHttpRequest.DONE&&i.readyState!=XMLHttpRequest.UNSENT&&i.abort()},Object.entries(null!==(r=e.headers)&&void 0!==r?r:{}).forEach((([e,t])=>i.setRequestHeader(e,t))),i.onabort=()=>s(new Error("Aborted")),i.ontimeout=()=>s(new Error("Request timeout")),i.onerror=()=>s(new Error("Request timeout")),i.onload=()=>{const e=new Headers;i.getAllResponseHeaders().split("\r\n").forEach((t=>{const[n,s]=t.split(": ");n.length>1&&s.length>1&&e.append(n,s)})),n(new Response(i.response,{status:i.status,headers:e,statusText:i.statusText}))},i.send(e.body)}))}))}webTransportRequestFromTransportRequest(e){return i(this,void 0,void 0,(function*(){let t,n=e.path;if(e.formData&&e.formData.length>0){e.queryParameters={};const n=e.body,s=new FormData;for(const{key:t,value:n}of e.formData)s.append(t,n);try{const e=yield n.toArrayBuffer();s.append("file",new Blob([e],{type:"application/octet-stream"}),n.name)}catch(e){try{const e=yield n.toFileUri();s.append("file",e,n.name)}catch(e){}}t=s}else if(e.body&&("string"==typeof e.body||e.body instanceof ArrayBuffer))if(e.compressible&&"undefined"!=typeof CompressionStream){const n=new ReadableStream({start(t){t.enqueue("string"==typeof e.body?Z.encoder.encode(e.body):e.body),t.close()}});t=yield new Response(n.pipeThrough(new CompressionStream("deflate"))).arrayBuffer()}else t=e.body;var s;return e.queryParameters&&0!==Object.keys(e.queryParameters).length&&(n=`${n}?${s=e.queryParameters,Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&")}`),{url:`${e.origin}${n}`,method:e.method,headers:e.headers,timeout:e.timeout,body:t}}))}logRequestProcessProgress(e,t,n,s){if(!this.logVerbosity)return;const{protocol:r,host:i,pathname:a,search:o}=new URL(e.url),c=(new Date).toISOString();if(n){let e=`[${c} / ${n}]\n${r}//${i}${a}\n${o}`;s&&(e+=`\n\n${Z.decoder.decode(s)}`),console.log(">>>>>>"),console.log(e),console.log("-----")}else{let e=`[${c}]\n${r}//${i}${a}\n${o}`;t&&("string"==typeof t||t instanceof ArrayBuffer)&&(e+="string"==typeof t?`\n\n${t}`:`\n\n${Z.decoder.decode(t)}`),console.log("<<<<<"),console.log(e),console.log("-----")}}isFetchMonkeyPatched(e){return!(null!=e?e:fetch).toString().includes("[native code]")&&"fetch"!==fetch.name}static getOriginalFetch(){let e=document.querySelector('iframe[name="pubnub-context-unpatched-fetch"]');return e||(e=document.createElement("iframe"),e.style.display="none",e.name="pubnub-context-unpatched-fetch",e.src="/service/about:blank",document.body.appendChild(e)),e.contentWindow?e.contentWindow.fetch.bind(e.contentWindow):fetch}}Z.encoder=new TextEncoder,Z.decoder=new TextDecoder;class ee{constructor(){this.listeners=[]}addListener(e){this.listeners.push(e)}removeListener(e){const t=this.listeners.indexOf(e);-1!==t&&this.listeners.splice(t,1)}removeAllListeners(){this.listeners=[]}announceStatus(e){this.listeners.forEach((t=>{t.status&&t.status(e)}))}announcePresence(e){this.listeners.forEach((t=>{t.presence&&t.presence(e)}))}announceMessage(e){this.listeners.forEach((t=>{t.message&&t.message(e)}))}announceSignal(e){this.listeners.forEach((t=>{t.signal&&t.signal(e)}))}announceMessageAction(e){this.listeners.forEach((t=>{t.messageAction&&t.messageAction(e)}))}announceFile(e){this.listeners.forEach((t=>{t.file&&t.file(e)}))}announceObjects(e){this.listeners.forEach((t=>{t.objects&&t.objects(e)}))}announceNetworkUp(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkUpCategory})}))}announceNetworkDown(){this.listeners.forEach((e=>{e.status&&e.status({category:h.PNNetworkDownCategory})}))}announceUser(e){this.listeners.forEach((t=>{t.user&&t.user(e)}))}announceSpace(e){this.listeners.forEach((t=>{t.space&&t.space(e)}))}announceMembership(e){this.listeners.forEach((t=>{t.membership&&t.membership(e)}))}}class te{constructor(e){this.time=e}onReconnect(e){this.callback=e}startPolling(){this.timeTimer=setInterval((()=>this.callTime()),3e3)}stopPolling(){this.timeTimer&&clearInterval(this.timeTimer),this.timeTimer=null}callTime(){this.time((e=>{e.error||(this.stopPolling(),this.callback&&this.callback())}))}}class ne{constructor({maximumCacheSize:e}){this.maximumCacheSize=e,this.hashHistory=[]}getKey(e){var t;return`${e.timetoken}-${this.hashCode(JSON.stringify(null!==(t=e.message)&&void 0!==t?t:"")).toString()}`}isDuplicate(e){return this.hashHistory.includes(this.getKey(e))}addEntry(e){this.hashHistory.length>=this.maximumCacheSize&&this.hashHistory.shift(),this.hashHistory.push(this.getKey(e))}clearHistory(){this.hashHistory=[]}hashCode(e){let t=0;if(0===e.length)return t;for(let n=0;n{this.pendingChannelSubscriptions.add(e),this.channels[e]={},r&&(this.presenceChannels[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannels[e]={})})),null==n||n.forEach((e=>{this.pendingChannelGroupSubscriptions.add(e),this.channelGroups[e]={},r&&(this.presenceChannelGroups[e]={}),(i||this.configuration.getHeartbeatInterval())&&(this.heartbeatChannelGroups[e]={})})),this.subscriptionStatusAnnounced=!1,this.reconnect()}unsubscribe(e,t){let{channels:n,channelGroups:s}=e;const i=new Set,a=new Set;null==n||n.forEach((e=>{e in this.channels&&(delete this.channels[e],a.add(e),e in this.heartbeatChannels&&delete this.heartbeatChannels[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannels&&(delete this.presenceChannels[e],a.add(e))})),null==s||s.forEach((e=>{e in this.channelGroups&&(delete this.channelGroups[e],i.add(e),e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]),e in this.presenceState&&delete this.presenceState[e],e in this.presenceChannelGroups&&(delete this.presenceChannelGroups[e],i.add(e))})),0===a.size&&0===i.size||(!1!==this.configuration.suppressLeaveEvents||t||(s=Array.from(i),n=Array.from(a),this.leaveCall({channels:n,channelGroups:s},(e=>{const{error:t}=e,i=r(e,["error"]);let a;t&&(e.errorData&&"object"==typeof e.errorData&&"message"in e.errorData&&"string"==typeof e.errorData.message?a=e.errorData.message:"message"in e&&"string"==typeof e.message&&(a=e.message)),this.listenerManager.announceStatus(Object.assign(Object.assign({},i),{error:null!=a&&a,affectedChannels:n,affectedChannelGroups:s,currentTimetoken:this.currentTimetoken,lastTimetoken:this.lastTimetoken}))}))),0===Object.keys(this.channels).length&&0===Object.keys(this.presenceChannels).length&&0===Object.keys(this.channelGroups).length&&0===Object.keys(this.presenceChannelGroups).length&&(this.lastTimetoken=0,this.currentTimetoken=0,this.storedTimetoken=null,this.region=null,this.reconnectionManager.stopPolling()),this.reconnect(!0))}unsubscribeAll(e){this.unsubscribe({channels:this.subscribedChannels,channelGroups:this.subscribedChannelGroups},e)}startSubscribeLoop(e=!1){this.stopSubscribeLoop();const t=[...Object.keys(this.channelGroups)],n=[...Object.keys(this.channels)];Object.keys(this.presenceChannelGroups).forEach((e=>t.push(`${e}-pnpres`))),Object.keys(this.presenceChannels).forEach((e=>n.push(`${e}-pnpres`))),0===n.length&&0===t.length||(this.subscribeCall({channels:n,channelGroups:t,state:this.presenceState,heartbeat:this.configuration.getPresenceTimeout(),timetoken:this.currentTimetoken,region:null!==this.region?this.region:void 0,filterExpression:this.configuration.filterExpression},((e,t)=>{this.processSubscribeResponse(e,t)})),!e&&this.configuration.useSmartHeartbeat&&this.startHeartbeatTimer())}stopSubscribeLoop(){this._subscribeAbort&&(this._subscribeAbort(),this._subscribeAbort=null)}processSubscribeResponse(e,t){if(e.error){if("object"==typeof e.errorData&&"name"in e.errorData&&"AbortError"===e.errorData.name||e.category===h.PNCancelledCategory)return;return void(e.category===h.PNTimeoutCategory?this.startSubscribeLoop():e.category===h.PNNetworkIssuesCategory||e.category===h.PNMalformedResponseCategory?(this.disconnect(),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.listenerManager.announceNetworkDown()),this.reconnectionManager.onReconnect((()=>{this.configuration.autoNetworkDetection&&!this.isOnline&&(this.isOnline=!0,this.listenerManager.announceNetworkUp()),this.reconnect(),this.subscriptionStatusAnnounced=!0;const t={category:h.PNReconnectedCategory,operation:e.operation,lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.listenerManager.announceStatus(t)})),this.reconnectionManager.startPolling(),this.listenerManager.announceStatus(Object.assign(Object.assign({},e),{category:h.PNNetworkIssuesCategory}))):e.category===h.PNBadRequestCategory?(this.stopHeartbeatTimer(),this.listenerManager.announceStatus(e)):this.listenerManager.announceStatus(e))}if(this.storedTimetoken?(this.currentTimetoken=this.storedTimetoken,this.storedTimetoken=null):(this.lastTimetoken=this.currentTimetoken,this.currentTimetoken=t.cursor.timetoken),!this.subscriptionStatusAnnounced){const t={category:h.PNConnectedCategory,operation:e.operation,affectedChannels:Array.from(this.pendingChannelSubscriptions),subscribedChannels:this.subscribedChannels,affectedChannelGroups:Array.from(this.pendingChannelGroupSubscriptions),lastTimetoken:this.lastTimetoken,currentTimetoken:this.currentTimetoken};this.subscriptionStatusAnnounced=!0,this.listenerManager.announceStatus(t),this.pendingChannelGroupSubscriptions.clear(),this.pendingChannelSubscriptions.clear()}const{messages:n}=t,{requestMessageCountThreshold:s,dedupeOnSubscribe:r}=this.configuration;s&&n.length>=s&&this.listenerManager.announceStatus({category:h.PNRequestMessageCountExceededCategory,operation:e.operation});try{n.forEach((e=>{if(r&&"message"in e.data&&"timetoken"in e.data){if(this.dedupingManager.isDuplicate(e.data))return;this.dedupingManager.addEntry(e.data)}this.eventEmitter.emitEvent(e)}))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}this.region=t.cursor.region,this.startSubscribeLoop()}setState(e){const{state:t,channels:n,channelGroups:s}=e;null==n||n.forEach((e=>e in this.channels&&(this.presenceState[e]=t))),null==s||s.forEach((e=>e in this.channelGroups&&(this.presenceState[e]=t)))}changePresence(e){const{connected:t,channels:n,channelGroups:s}=e;t?(null==n||n.forEach((e=>this.heartbeatChannels[e]={})),null==s||s.forEach((e=>this.heartbeatChannelGroups[e]={}))):(null==n||n.forEach((e=>{e in this.heartbeatChannels&&delete this.heartbeatChannels[e]})),null==s||s.forEach((e=>{e in this.heartbeatChannelGroups&&delete this.heartbeatChannelGroups[e]})),!1===this.configuration.suppressLeaveEvents&&this.leaveCall({channels:n,channelGroups:s},(e=>this.listenerManager.announceStatus(e)))),this.reconnect()}startHeartbeatTimer(){this.stopHeartbeatTimer();const e=this.configuration.getHeartbeatInterval();e&&0!==e&&(this.configuration.useSmartHeartbeat||this.sendHeartbeat(),this.heartbeatTimer=setInterval((()=>this.sendHeartbeat()),1e3*e))}stopHeartbeatTimer(){this.heartbeatTimer&&(clearInterval(this.heartbeatTimer),this.heartbeatTimer=null)}sendHeartbeat(){const e=Object.keys(this.heartbeatChannelGroups),t=Object.keys(this.heartbeatChannels);0===t.length&&0===e.length||this.heartbeatCall({channels:t,channelGroups:e,heartbeat:this.configuration.getPresenceTimeout(),state:this.presenceState},(e=>{e.error&&this.configuration.announceFailedHeartbeats&&this.listenerManager.announceStatus(e),e.error&&this.configuration.autoNetworkDetection&&this.isOnline&&(this.isOnline=!1,this.disconnect(),this.listenerManager.announceNetworkDown(),this.reconnect()),!e.error&&this.configuration.announceSuccessfulHeartbeats&&this.listenerManager.announceStatus(e)}))}}class re{constructor(e,t,n){this._payload=e,this.setDefaultPayloadStructure(),this.title=t,this.body=n}get payload(){return this._payload}set title(e){this._title=e}set subtitle(e){this._subtitle=e}set body(e){this._body=e}set badge(e){this._badge=e}set sound(e){this._sound=e}setDefaultPayloadStructure(){}toObject(){return{}}}class ie extends re{constructor(){super(...arguments),this._apnsPushType="apns",this._isSilent=!1}get payload(){return this._payload}set configurations(e){e&&e.length&&(this._configurations=e)}get notification(){return this.payload.aps}get title(){return this._title}set title(e){e&&e.length&&(this.payload.aps.alert.title=e,this._title=e)}get subtitle(){return this._subtitle}set subtitle(e){e&&e.length&&(this.payload.aps.alert.subtitle=e,this._subtitle=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.aps.alert.body=e,this._body=e)}get badge(){return this._badge}set badge(e){null!=e&&(this.payload.aps.badge=e,this._badge=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.aps.sound=e,this._sound=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.aps={alert:{}}}toObject(){const e=Object.assign({},this.payload),{aps:t}=e;let{alert:n}=t;if(this._isSilent&&(t["content-available"]=1),"apns2"===this._apnsPushType){if(!this._configurations||!this._configurations.length)throw new ReferenceError("APNS2 configuration is missing");const t=[];this._configurations.forEach((e=>{t.push(this.objectFromAPNS2Configuration(e))})),t.length&&(e.pn_push=t)}return n&&Object.keys(n).length||delete t.alert,this._isSilent&&(delete t.alert,delete t.badge,delete t.sound,n={}),this._isSilent||n&&Object.keys(n).length?e:null}objectFromAPNS2Configuration(e){if(!e.targets||!e.targets.length)throw new ReferenceError("At least one APNS2 target should be provided");const{collapseId:t,expirationDate:n}=e,s={auth_method:"token",targets:e.targets.map((e=>this.objectFromAPNSTarget(e))),version:"v2"};return t&&t.length&&(s.collapse_id=t),n&&(s.expiration=n.toISOString()),s}objectFromAPNSTarget(e){if(!e.topic||!e.topic.length)throw new TypeError("Target 'topic' undefined.");const{topic:t,environment:n="development",excludedDevices:s=[]}=e,r={topic:t,environment:n};return s.length&&(r.excluded_devices=s),r}}class ae extends re{get payload(){return this._payload}get notification(){return this.payload.notification}get data(){return this.payload.data}get title(){return this._title}set title(e){e&&e.length&&(this.payload.notification.title=e,this._title=e)}get body(){return this._body}set body(e){e&&e.length&&(this.payload.notification.body=e,this._body=e)}get sound(){return this._sound}set sound(e){e&&e.length&&(this.payload.notification.sound=e,this._sound=e)}get icon(){return this._icon}set icon(e){e&&e.length&&(this.payload.notification.icon=e,this._icon=e)}get tag(){return this._tag}set tag(e){e&&e.length&&(this.payload.notification.tag=e,this._tag=e)}set silent(e){this._isSilent=e}setDefaultPayloadStructure(){this.payload.notification={},this.payload.data={}}toObject(){let e=Object.assign({},this.payload.data),t=null;const n={};if(Object.keys(this.payload).length>2){const t=r(this.payload,["notification","data"]);e=Object.assign(Object.assign({},e),t)}return this._isSilent?e.notification=this.payload.notification:t=this.payload.notification,Object.keys(e).length&&(n.data=e),t&&Object.keys(t).length&&(n.notification=t),Object.keys(n).length?n:null}}class oe{constructor(e,t){this._payload={apns:{},fcm:{}},this._title=e,this._body=t,this.apns=new ie(this._payload.apns,e,t),this.fcm=new ae(this._payload.fcm,e,t)}set debugging(e){this._debugging=e}get title(){return this._title}get subtitle(){return this._subtitle}set subtitle(e){this._subtitle=e,this.apns.subtitle=e,this.fcm.subtitle=e}get body(){return this._body}get badge(){return this._badge}set badge(e){this._badge=e,this.apns.badge=e,this.fcm.badge=e}get sound(){return this._sound}set sound(e){this._sound=e,this.apns.sound=e,this.fcm.sound=e}buildPayload(e){const t={};if(e.includes("apns")||e.includes("apns2")){this.apns._apnsPushType=e.includes("apns")?"apns":"apns2";const n=this.apns.toObject();n&&Object.keys(n).length&&(t.pn_apns=n)}if(e.includes("fcm")){const e=this.fcm.toObject();e&&Object.keys(e).length&&(t.pn_gcm=e)}return Object.keys(t).length&&this._debugging&&(t.pn_debug=!0),t}}class ce{constructor(e){this.params=e,this.requestIdentifier=K.createUUID(),this._cancellationController=null}get cancellationController(){return this._cancellationController}set cancellationController(e){this._cancellationController=e}abort(e){this&&this.cancellationController&&this.cancellationController.abort(e)}operation(){throw Error("Should be implemented by subclass.")}validate(){}parse(e){return i(this,void 0,void 0,(function*(){return this.deserializeResponse(e)}))}request(){var e,t,n,s,r,i;const a={method:null!==(t=null===(e=this.params)||void 0===e?void 0:e.method)&&void 0!==t?t:W.GET,path:this.path,queryParameters:this.queryParameters,cancellable:null!==(s=null===(n=this.params)||void 0===n?void 0:n.cancellable)&&void 0!==s&&s,compressible:null!==(i=null===(r=this.params)||void 0===r?void 0:r.compressible)&&void 0!==i&&i,timeout:10,identifier:this.requestIdentifier},o=this.headers;if(o&&(a.headers=o),a.method===W.POST||a.method===W.PATCH){const[e,t]=[this.body,this.formData];t&&(a.formData=t),e&&(a.body=e)}return a}get headers(){var e,t;return Object.assign({"Accept-Encoding":"gzip, deflate"},null!==(t=null===(e=this.params)||void 0===e?void 0:e.compressible)&&void 0!==t&&t?{"Content-Encoding":"deflate"}:{})}get path(){throw Error("`path` getter should be implemented by subclass.")}get queryParameters(){return{}}get formData(){}get body(){}deserializeResponse(e){const t=ce.decoder.decode(e.body),n=e.headers["content-type"];let s;if(!n||-1===n.indexOf("javascript")&&-1===n.indexOf("json"))throw new d("Service response error, check status for details",y(t,e.status));try{s=JSON.parse(t)}catch(n){throw console.error("Error parsing JSON response:",n),new d("Service response error, check status for details",y(t,e.status))}if("status"in s&&"number"==typeof s.status&&s.status>=400)throw _.create(e);return s}}var ue;ce.decoder=new TextDecoder,function(e){e.PNPublishOperation="PNPublishOperation",e.PNSignalOperation="PNSignalOperation",e.PNSubscribeOperation="PNSubscribeOperation",e.PNUnsubscribeOperation="PNUnsubscribeOperation",e.PNWhereNowOperation="PNWhereNowOperation",e.PNHereNowOperation="PNHereNowOperation",e.PNGlobalHereNowOperation="PNGlobalHereNowOperation",e.PNSetStateOperation="PNSetStateOperation",e.PNGetStateOperation="PNGetStateOperation",e.PNHeartbeatOperation="PNHeartbeatOperation",e.PNAddMessageActionOperation="PNAddActionOperation",e.PNRemoveMessageActionOperation="PNRemoveMessageActionOperation",e.PNGetMessageActionsOperation="PNGetMessageActionsOperation",e.PNTimeOperation="PNTimeOperation",e.PNHistoryOperation="PNHistoryOperation",e.PNDeleteMessagesOperation="PNDeleteMessagesOperation",e.PNFetchMessagesOperation="PNFetchMessagesOperation",e.PNMessageCounts="PNMessageCountsOperation",e.PNGetAllUUIDMetadataOperation="PNGetAllUUIDMetadataOperation",e.PNGetUUIDMetadataOperation="PNGetUUIDMetadataOperation",e.PNSetUUIDMetadataOperation="PNSetUUIDMetadataOperation",e.PNRemoveUUIDMetadataOperation="PNRemoveUUIDMetadataOperation",e.PNGetAllChannelMetadataOperation="PNGetAllChannelMetadataOperation",e.PNGetChannelMetadataOperation="PNGetChannelMetadataOperation",e.PNSetChannelMetadataOperation="PNSetChannelMetadataOperation",e.PNRemoveChannelMetadataOperation="PNRemoveChannelMetadataOperation",e.PNGetMembersOperation="PNGetMembersOperation",e.PNSetMembersOperation="PNSetMembersOperation",e.PNGetMembershipsOperation="PNGetMembershipsOperation",e.PNSetMembershipsOperation="PNSetMembershipsOperation",e.PNListFilesOperation="PNListFilesOperation",e.PNGenerateUploadUrlOperation="PNGenerateUploadUrlOperation",e.PNPublishFileOperation="PNPublishFileOperation",e.PNPublishFileMessageOperation="PNPublishFileMessageOperation",e.PNGetFileUrlOperation="PNGetFileUrlOperation",e.PNDownloadFileOperation="PNDownloadFileOperation",e.PNDeleteFileOperation="PNDeleteFileOperation",e.PNAddPushNotificationEnabledChannelsOperation="PNAddPushNotificationEnabledChannelsOperation",e.PNRemovePushNotificationEnabledChannelsOperation="PNRemovePushNotificationEnabledChannelsOperation",e.PNPushNotificationEnabledChannelsOperation="PNPushNotificationEnabledChannelsOperation",e.PNRemoveAllPushNotificationsOperation="PNRemoveAllPushNotificationsOperation",e.PNChannelGroupsOperation="PNChannelGroupsOperation",e.PNRemoveGroupOperation="PNRemoveGroupOperation",e.PNChannelsForGroupOperation="PNChannelsForGroupOperation",e.PNAddChannelsToGroupOperation="PNAddChannelsToGroupOperation",e.PNRemoveChannelsFromGroupOperation="PNRemoveChannelsFromGroupOperation",e.PNAccessManagerGrant="PNAccessManagerGrant",e.PNAccessManagerGrantToken="PNAccessManagerGrantToken",e.PNAccessManagerAudit="PNAccessManagerAudit",e.PNAccessManagerRevokeToken="PNAccessManagerRevokeToken",e.PNHandshakeOperation="PNHandshakeOperation",e.PNReceiveMessagesOperation="PNReceiveMessagesOperation"}(ue||(ue={}));var le=ue;var he;!function(e){e[e.Presence=-2]="Presence",e[e.Message=-1]="Message",e[e.Signal=1]="Signal",e[e.AppContext=2]="AppContext",e[e.MessageAction=3]="MessageAction",e[e.Files=4]="Files"}(he||(he={}));class de extends ce{constructor(e){var t,n,s,r,i,a;super({cancellable:!0}),this.parameters=e,null!==(t=(r=this.parameters).withPresence)&&void 0!==t||(r.withPresence=false),null!==(n=(i=this.parameters).channelGroups)&&void 0!==n||(i.channelGroups=[]),null!==(s=(a=this.parameters).channels)&&void 0!==s||(a.channels=[])}operation(){return le.PNSubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;return e?t||n?void 0:"`channels` and `channelGroups` both should not be empty":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){let t,n;try{n=ce.decoder.decode(e.body);t=JSON.parse(n)}catch(e){console.error("Error parsing JSON response:",e)}if(!t)throw new d("Service response error, check status for details",y(n,e.status));const s=t.m.filter((e=>{const t=void 0===e.b?e.c:e.b;return this.parameters.channels&&this.parameters.channels.includes(t)||this.parameters.channelGroups&&this.parameters.channelGroups.includes(t)})).map((e=>{let{e:t}=e;return null!=t||(t=e.c.endsWith("-pnpres")?he.Presence:he.Message),t!=he.Signal&&"string"==typeof e.d?t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}:t==he.Message?{type:he.Message,data:this.messageFromEnvelope(e)}:t===he.Presence?{type:he.Presence,data:this.presenceEventFromEnvelope(e)}:t==he.Signal?{type:he.Signal,data:this.signalFromEnvelope(e)}:t===he.AppContext?{type:he.AppContext,data:this.appContextFromEnvelope(e)}:t===he.MessageAction?{type:he.MessageAction,data:this.messageActionFromEnvelope(e)}:{type:he.Files,data:this.fileFromEnvelope(e)}}));return{cursor:{timetoken:t.t.t,region:t.t.r},messages:s}}))}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{accept:"text/javascript"})}presenceEventFromEnvelope(e){var t;const{d:n}=e,[s,r]=this.subscriptionChannelFromEnvelope(e),i=s.replace("-pnpres",""),a=null!==r?i:null,o=null!==r?r:i;return"string"!=typeof n&&("data"in n?(n.state=n.data,delete n.data):"action"in n&&"interval"===n.action&&(n.hereNowRefresh=null!==(t=n.here_now_refresh)&&void 0!==t&&t,delete n.here_now_refresh)),Object.assign({channel:i,subscription:r,actualChannel:a,subscribedChannel:o,timetoken:e.p.t},n)}messageFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d),i={channel:t,subscription:n,actualChannel:null!==n?t:null,subscribedChannel:null!==n?n:t,timetoken:e.p.t,publisher:e.i,message:s};return e.u&&(i.userMetadata=e.u),e.cmt&&(i.customMessageType=e.cmt),r&&(i.error=r),i}signalFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,message:e.d};return e.u&&(s.userMetadata=e.u),e.cmt&&(s.customMessageType=e.cmt),s}messageActionFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,publisher:e.i,event:s.event,data:Object.assign(Object.assign({},s.data),{uuid:e.i})}}appContextFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),s=e.d;return{channel:t,subscription:n,timetoken:e.p.t,message:s}}fileFromEnvelope(e){const[t,n]=this.subscriptionChannelFromEnvelope(e),[s,r]=this.decryptedData(e.d);let i=r;const a={channel:t,subscription:n,timetoken:e.p.t,publisher:e.i};return e.u&&(a.userMetadata=e.u),s?"string"==typeof s?null!=i||(i="Unexpected file information payload data type."):(a.message=s.message,s.file&&(a.file={id:s.file.id,name:s.file.name,url:this.parameters.getFileUrl({id:s.file.id,name:s.file.name,channel:t})})):null!=i||(i="File information payload is missing."),e.cmt&&(a.customMessageType=e.cmt),i&&(a.error=i),a}subscriptionChannelFromEnvelope(e){return[e.c,void 0===e.b?e.c:e.b]}decryptedData(e){if(!this.parameters.crypto||"string"!=typeof e)return[e,void 0];let t,n;try{const n=this.parameters.crypto.decrypt(e);t=n instanceof ArrayBuffer?JSON.parse(pe.decoder.decode(n)):n}catch(e){t=null,n=`Error while decrypting message content: ${e.message}`}return[null!=t?t:e,n]}}class pe extends de{get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/subscribe/${t}/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,heartbeat:n,state:s,timetoken:r,region:i}=this.parameters,a={};return e&&e.length>0&&(a["channel-group"]=e.sort().join(",")),t&&t.length>0&&(a["filter-expr"]=t),n&&(a.heartbeat=n),s&&Object.keys(s).length>0&&(a.state=JSON.stringify(s)),void 0!==r&&"string"==typeof r?r.length>0&&"0"!==r&&(a.tt=r):void 0!==r&&r>0&&(a.tt=r),i&&(a.tr=i),a}}class ge{constructor(e){this.listenerManager=e,this.channelListenerMap=new Map,this.groupListenerMap=new Map}emitEvent(e){var t;if(e.type===he.Message)this.listenerManager.announceMessage(e.data),this.announce("message",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Signal)this.listenerManager.announceSignal(e.data),this.announce("signal",e.data,e.data.channel,e.data.subscription);else if(e.type===he.Presence)this.listenerManager.announcePresence(e.data),this.announce("presence",e.data,null!==(t=e.data.subscription)&&void 0!==t?t:e.data.channel,e.data.subscription);else if(e.type===he.AppContext){const{data:t}=e,{message:n}=t;if(this.listenerManager.announceObjects(t),this.announce("objects",t,t.channel,t.subscription),"uuid"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"user"})});this.listenerManager.announceUser(u),this.announce("user",u,u.spaceId,u.subscription)}else if("channel"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,type:o}=n,c=r(n,["event","type"]),u=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",type:"space"})});this.listenerManager.announceSpace(u),this.announce("space",u,u.spaceId,u.subscription)}else if("membership"===n.type){const{message:e,channel:s}=t,i=r(t,["message","channel"]),{event:a,data:o}=n,c=r(n,["event","data"]),{uuid:u,channel:l}=o,h=r(o,["uuid","channel"]),d=Object.assign(Object.assign({},i),{spaceId:s,message:Object.assign(Object.assign({},c),{event:"set"===a?"updated":"removed",data:Object.assign(Object.assign({},h),{user:u,space:l})})});this.listenerManager.announceMembership(d),this.announce("membership",d,d.spaceId,d.subscription)}}else e.type===he.MessageAction?(this.listenerManager.announceMessageAction(e.data),this.announce("messageAction",e.data,e.data.channel,e.data.subscription)):e.type===he.Files&&(this.listenerManager.announceFile(e.data),this.announce("file",e.data,e.data.channel,e.data.subscription))}addListener(e,t,n,s){return null!=s||(s=K.createUUID()),t&&n?(null==t||t.forEach((t=>{if(this.channelListenerMap.has(t)){this.channelListenerMap.get(t).push({id:s,listener:e})}else this.channelListenerMap.set(t,[{id:s,listener:e}])})),null==n||n.forEach((t=>{if(this.groupListenerMap.has(t)){this.groupListenerMap.get(t).push({id:s,listener:e})}else this.groupListenerMap.set(t,[{id:s,listener:e}])}))):this.listenerManager.addListener(e),s}removeListener(e,t,n,s){n&&s?(null==n||n.forEach((e=>{const n=this.channelListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}})),null==s||s.forEach((e=>{const n=this.groupListenerMap.get(e);if(n){const e=n.find((e=>e.id===t)),s=e?n.indexOf(e):-1;-1!==s&&n.splice(s,1)}}))):this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners(),this.channelListenerMap.clear(),this.groupListenerMap.clear()}announce(e,t,n,s){t&&this.channelListenerMap.has(n)&&this.channelListenerMap.get(n).forEach((n=>{const s=n.listener[e];s&&s(t)})),s&&this.groupListenerMap.has(s)&&this.groupListenerMap.get(s).forEach((n=>{const s=n.listener[e];s&&s(t)}))}}class ye{constructor(e=!1){this.sync=e,this.listeners=new Set}subscribe(e){return this.listeners.add(e),()=>{this.listeners.delete(e)}}notify(e){const t=()=>{this.listeners.forEach((t=>{t(e)}))};this.sync?t():setTimeout(t,0)}}class fe{transition(e,t){var n;if(this.transitionMap.has(t.type))return null===(n=this.transitionMap.get(t.type))||void 0===n?void 0:n(e,t)}constructor(e){this.label=e,this.transitionMap=new Map,this.enterEffects=[],this.exitEffects=[]}on(e,t){return this.transitionMap.set(e,t),this}with(e,t){return[this,e,null!=t?t:[]]}onEnter(e){return this.enterEffects.push(e),this}onExit(e){return this.exitEffects.push(e),this}}class be extends ye{describe(e){return new fe(e)}start(e,t){this.currentState=e,this.currentContext=t,this.notify({type:"engineStarted",state:e,context:t})}transition(e){if(!this.currentState)throw new Error("Start the engine first");this.notify({type:"eventReceived",event:e});const t=this.currentState.transition(this.currentContext,e);if(t){const[n,s,r]=t;for(const e of this.currentState.exitEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)});const i=this.currentState;this.currentState=n;const a=this.currentContext;this.currentContext=s,this.notify({type:"transitionDone",fromState:i,fromContext:a,toState:n,toContext:s,event:e});for(const e of r)this.notify({type:"invocationDispatched",invocation:e});for(const e of this.currentState.enterEffects)this.notify({type:"invocationDispatched",invocation:e(this.currentContext)})}}}class me{constructor(e){this.dependencies=e,this.instances=new Map,this.handlers=new Map}on(e,t){this.handlers.set(e,t)}dispatch(e){if("CANCEL"===e.type){if(this.instances.has(e.payload)){const t=this.instances.get(e.payload);null==t||t.cancel(),this.instances.delete(e.payload)}return}const t=this.handlers.get(e.type);if(!t)throw new Error(`Unhandled invocation '${e.type}'`);const n=t(e.payload,this.dependencies);e.managed&&this.instances.set(e.type,n),n.start()}dispose(){for(const[e,t]of this.instances.entries())t.cancel(),this.instances.delete(e)}}function ve(e,t){const n=function(...n){return{type:e,payload:null==t?void 0:t(...n)}};return n.type=e,n}function Se(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!1});return n.type=e,n}function we(e,t){const n=(...n)=>({type:e,payload:t(...n),managed:!0});return n.type=e,n.cancel={type:"CANCEL",payload:e,managed:!1},n}class Oe extends Error{constructor(){super("The operation was aborted."),this.name="AbortError",Object.setPrototypeOf(this,new.target.prototype)}}class ke extends ye{constructor(){super(...arguments),this._aborted=!1}get aborted(){return this._aborted}throwIfAborted(){if(this._aborted)throw new Oe}abort(){this._aborted=!0,this.notify(new Oe)}}class Ee{constructor(e,t){this.payload=e,this.dependencies=t}}class Ce extends Ee{constructor(e,t,n){super(e,t),this.asyncFunction=n,this.abortSignal=new ke}start(){this.asyncFunction(this.payload,this.abortSignal,this.dependencies).catch((e=>{}))}cancel(){this.abortSignal.abort()}}const Pe=e=>(t,n)=>new Ce(t,n,e),Ne=ve("RECONNECT",(()=>({}))),Me=ve("DISCONNECT",(e=>({isOffline:e}))),je=ve("JOINED",((e,t)=>({channels:e,groups:t}))),Ae=ve("LEFT",((e,t)=>({channels:e,groups:t}))),_e=ve("LEFT_ALL",(e=>({isOffline:e}))),Ie=ve("HEARTBEAT_SUCCESS",(e=>({statusCode:e}))),Fe=ve("HEARTBEAT_FAILURE",(e=>e)),Te=ve("TIMES_UP",(()=>({}))),Re=we("HEARTBEAT",((e,t)=>({channels:e,groups:t}))),Ue=Se("LEAVE",((e,t)=>({channels:e,groups:t}))),xe=Se("EMIT_STATUS",(e=>e)),De=we("WAIT",(()=>({})));class qe extends me{constructor(e,t){super(t),this.on(Re.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeat:s,presenceState:r,config:i}){try{yield s(Object.assign(Object.assign({channels:t.channels,channelGroups:t.groups},i.maintainPresenceState&&{state:r}),{heartbeat:i.presenceTimeout}));e.transition(Ie(200))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;e.transition(Fe(t))}}}))))),this.on(Ue.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{leave:n,config:s}){if(!s.suppressLeaveEvents)try{n({channels:e.channels,channelGroups:e.groups})}catch(e){}}))))),this.on(De.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{heartbeatDelay:s}){return n.throwIfAborted(),yield s(),n.throwIfAborted(),e.transition(Te())}))))),this.on(xe.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n,config:s}){s.announceFailedHeartbeats&&!0===(null==e?void 0:e.error)?n(Object.assign(Object.assign({},e),{operation:le.PNHeartbeatOperation})):s.announceSuccessfulHeartbeats&&200===e.statusCode&&n(Object.assign(Object.assign({},e),{error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory}))})))))}}const Le=new fe("HEARTBEAT_STOPPED");Le.on(je.type,((e,t)=>Le.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Le.on(Ae.type,((e,t)=>Le.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))}))),Le.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Le.on(_e.type,((e,t)=>Be.with(void 0)));const Ge=new fe("HEARTBEAT_COOLDOWN");Ge.onEnter((()=>De())),Ge.onExit((()=>De.cancel)),Ge.on(Te.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ge.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ge.on(Ae.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ge.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ge.on(_e.type,((e,t)=>Be.with(void 0,[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]])));const Ke=new fe("HEARTBEAT_FAILED");Ke.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),Ke.on(Ae.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),Ke.on(Ne.type,((e,t)=>$e.with({channels:e.channels,groups:e.groups}))),Ke.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),Ke.on(_e.type,((e,t)=>Be.with(void 0,[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]])));const $e=new fe("HEARTBEATING");$e.onEnter((e=>Re(e.channels,e.groups))),$e.onExit((()=>Re.cancel)),$e.on(Ie.type,((e,t)=>Ge.with({channels:e.channels,groups:e.groups},[xe(Object.assign({},t.payload))]))),$e.on(je.type,((e,t)=>$e.with({channels:[...e.channels,...t.payload.channels],groups:[...e.groups,...t.payload.groups]}))),$e.on(Ae.type,((e,t)=>$e.with({channels:e.channels.filter((e=>!t.payload.channels.includes(e))),groups:e.groups.filter((e=>!t.payload.groups.includes(e)))},[Ue(t.payload.channels,t.payload.groups)]))),$e.on(Fe.type,((e,t)=>Ke.with(Object.assign({},e),[...t.payload.status?[xe(Object.assign({},t.payload.status))]:[]]))),$e.on(Me.type,((e,t)=>Le.with({channels:e.channels,groups:e.groups},[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]]))),$e.on(_e.type,((e,t)=>Be.with(void 0,[...t.payload.isOffline?[]:[Ue(e.channels,e.groups)]])));const Be=new fe("HEARTBEAT_INACTIVE");Be.on(je.type,((e,t)=>$e.with({channels:t.payload.channels,groups:t.payload.groups})));class He{get _engine(){return this.engine}constructor(e){this.dependencies=e,this.engine=new be,this.channels=[],this.groups=[],this.dispatcher=new qe(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(Be,void 0)}join({channels:e,groups:t}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],this.engine.transition(je(this.channels.slice(0),this.groups.slice(0)))}leave({channels:e,groups:t}){this.dependencies.presenceState&&(null==e||e.forEach((e=>delete this.dependencies.presenceState[e])),null==t||t.forEach((e=>delete this.dependencies.presenceState[e]))),this.engine.transition(Ae(null!=e?e:[],null!=t?t:[]))}leaveAll(e){this.engine.transition(_e(e))}reconnect(){this.engine.transition(Ne())}disconnect(e){this.engine.transition(Me(e))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}const We=we("HANDSHAKE",((e,t)=>({channels:e,groups:t}))),Ve=we("RECEIVE_MESSAGES",((e,t,n)=>({channels:e,groups:t,cursor:n}))),ze=Se("EMIT_MESSAGES",(e=>e)),Je=Se("EMIT_STATUS",(e=>e)),Xe=ve("SUBSCRIPTION_CHANGED",((e,t,n)=>({channels:e,groups:t,isOffline:n}))),Qe=ve("SUBSCRIPTION_RESTORED",((e,t,n,s)=>({channels:e,groups:t,cursor:{timetoken:n,region:null!=s?s:0}}))),Ye=ve("HANDSHAKE_SUCCESS",(e=>e)),Ze=ve("HANDSHAKE_FAILURE",(e=>e)),et=ve("RECEIVE_SUCCESS",((e,t)=>({cursor:e,events:t}))),tt=ve("RECEIVE_FAILURE",(e=>e)),nt=ve("DISCONNECT",(e=>({isOffline:e}))),st=ve("RECONNECT",((e,t)=>({cursor:{timetoken:null!=e?e:"",region:null!=t?t:0}}))),rt=ve("UNSUBSCRIBE_ALL",(()=>({})));class it extends me{constructor(e,t){super(t),this.on(We.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{handshake:s,presenceState:r,config:i}){n.throwIfAborted();try{const a=yield s(Object.assign({abortSignal:n,channels:t.channels,channelGroups:t.groups,filterExpression:i.filterExpression},i.maintainPresenceState&&{state:r}));return e.transition(Ye(a))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;return e.transition(Ze(t))}}}))))),this.on(Ve.type,Pe(((t,n,s)=>i(this,[t,n,s],void 0,(function*(t,n,{receiveMessages:s,config:r}){n.throwIfAborted();try{const i=yield s({abortSignal:n,channels:t.channels,channelGroups:t.groups,timetoken:t.cursor.timetoken,region:t.cursor.region,filterExpression:r.filterExpression});e.transition(et(i.cursor,i.messages))}catch(t){if(t instanceof d){if(t.status&&t.status.category==h.PNCancelledCategory)return;if(!n.aborted)return e.transition(tt(t))}}}))))),this.on(ze.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitMessages:n}){e.length>0&&n(e)}))))),this.on(Je.type,Pe(((e,t,n)=>i(this,[e,t,n],void 0,(function*(e,t,{emitStatus:n}){return n(e)})))))}}const at=new fe("HANDSHAKE_STOPPED");at.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):at.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),at.on(st.type,((e,{payload:t})=>ht.with(Object.assign(Object.assign({},e),{cursor:t.cursor||e.cursor})))),at.on(Qe.type,((e,{payload:t})=>{var n;return 0===t.channels.length&&0===t.groups.length?dt.with(void 0):at.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=e.cursor)||void 0===n?void 0:n.region)||0}})})),at.on(rt.type,(e=>dt.with()));const ot=new fe("HANDSHAKE_FAILED");ot.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ot.on(st.type,((e,{payload:t})=>ht.with({channels:e.channels,groups:e.groups,cursor:t.cursor||e.cursor}))),ot.on(Qe.type,((e,{payload:t})=>{var n,s;return 0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region?t.cursor.region:null!==(s=null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)&&void 0!==s?s:0}})})),ot.on(rt.type,(e=>dt.with()));const ct=new fe("RECEIVE_STOPPED");ct.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ct.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ct.on(Qe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ct.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ct.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ct.on(rt.type,(()=>dt.with(void 0)));const ut=new fe("RECEIVE_FAILED");ut.on(st.type,((e,{payload:t})=>{var n;return ht.with({channels:e.channels,groups:e.groups,cursor:{timetoken:t.cursor.timetoken?null===(n=t.cursor)||void 0===n?void 0:n.timetoken:e.cursor.timetoken,region:t.cursor.region||e.cursor.region}})})),ut.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ut.on(Qe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}}))),ut.on(rt.type,(e=>dt.with(void 0)));const lt=new fe("RECEIVING");lt.onEnter((e=>Ve(e.channels,e.groups,e.cursor))),lt.onExit((()=>Ve.cancel)),lt.on(et.type,((e,{payload:t})=>lt.with({channels:e.channels,groups:e.groups,cursor:t.cursor},[ze(t.events)]))),lt.on(Xe.type,((e,{payload:t})=>{var n;if(0===t.channels.length&&0===t.groups.length){let e;return t.isOffline&&(e=null===(n=_.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation).status)||void 0===n?void 0:n.category),dt.with(void 0,[Je(Object.assign({category:t.isOffline?h.PNDisconnectedUnexpectedlyCategory:h.PNDisconnectedCategory},e?{error:e}:{}))])}return lt.with({channels:t.channels,groups:t.groups,cursor:e.cursor},[Je({category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0),currentTimetoken:e.cursor.timetoken})])})),lt.on(Qe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0,[Je({category:h.PNDisconnectedCategory})]):lt.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||e.cursor.region}},[Je({category:h.PNSubscriptionChangedCategory,affectedChannels:t.channels.slice(0),affectedChannelGroups:t.groups.slice(0),currentTimetoken:t.cursor.timetoken})]))),lt.on(tt.type,((e,{payload:t})=>{var n;return ut.with(Object.assign(Object.assign({},e),{reason:t}),[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])})),lt.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=_.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ut.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNDisconnectedUnexpectedlyCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return ct.with({channels:e.channels,groups:e.groups,cursor:e.cursor},[Je({category:h.PNDisconnectedCategory})])})),lt.on(rt.type,(e=>dt.with(void 0,[Je({category:h.PNDisconnectedCategory})])));const ht=new fe("HANDSHAKING");ht.onEnter((e=>We(e.channels,e.groups))),ht.onExit((()=>We.cancel)),ht.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:e.cursor}))),ht.on(Ye.type,((e,{payload:t})=>{var n,s,r,i;return lt.with({channels:e.channels,groups:e.groups,cursor:{timetoken:(null===(n=e.cursor)||void 0===n?void 0:n.timetoken)?null===(s=e.cursor)||void 0===s?void 0:s.timetoken:t.timetoken,region:t.region}},[Je({category:h.PNConnectedCategory,affectedChannels:e.channels.slice(0),affectedChannelGroups:e.groups.slice(0),currentTimetoken:(null===(r=e.cursor)||void 0===r?void 0:r.timetoken)?null===(i=e.cursor)||void 0===i?void 0:i.timetoken:t.timetoken})])})),ht.on(Ze.type,((e,t)=>{var n;return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t.payload},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.payload.status)||void 0===n?void 0:n.category})])})),ht.on(nt.type,((e,t)=>{var n;if(t.payload.isOffline){const t=_.create(new Error("Network connection error")).toPubNubError(le.PNSubscribeOperation);return ot.with({channels:e.channels,groups:e.groups,cursor:e.cursor,reason:t},[Je({category:h.PNConnectionErrorCategory,error:null===(n=t.status)||void 0===n?void 0:n.category})])}return at.with({channels:e.channels,groups:e.groups,cursor:e.cursor})})),ht.on(Qe.type,((e,{payload:t})=>{var n;return 0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:{timetoken:t.cursor.timetoken,region:t.cursor.region||(null===(n=null==e?void 0:e.cursor)||void 0===n?void 0:n.region)||0}})})),ht.on(rt.type,(e=>dt.with()));const dt=new fe("UNSUBSCRIBED");dt.on(Xe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups}))),dt.on(Qe.type,((e,{payload:t})=>0===t.channels.length&&0===t.groups.length?dt.with(void 0):ht.with({channels:t.channels,groups:t.groups,cursor:t.cursor})));class pt{get _engine(){return this.engine}constructor(e){this.engine=new be,this.channels=[],this.groups=[],this.dependencies=e,this.dispatcher=new it(this.engine,e),this._unsubscribeEngine=this.engine.subscribe((e=>{"invocationDispatched"===e.type&&this.dispatcher.dispatch(e.invocation)})),this.engine.start(dt,void 0)}subscribe({channels:e,channelGroups:t,timetoken:n,withPresence:s}){this.channels=[...this.channels,...null!=e?e:[]],this.groups=[...this.groups,...null!=t?t:[]],s&&(this.channels.map((e=>this.channels.push(`${e}-pnpres`))),this.groups.map((e=>this.groups.push(`${e}-pnpres`)))),n?this.engine.transition(Qe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])),n)):this.engine.transition(Xe(Array.from(new Set([...this.channels,...null!=e?e:[]])),Array.from(new Set([...this.groups,...null!=t?t:[]])))),this.dependencies.join&&this.dependencies.join({channels:Array.from(new Set(this.channels.filter((e=>!e.endsWith("-pnpres"))))),groups:Array.from(new Set(this.groups.filter((e=>!e.endsWith("-pnpres")))))})}unsubscribe({channels:e=[],channelGroups:t=[]}){const n=J(this.channels,[...e,...e.map((e=>`${e}-pnpres`))]),s=J(this.groups,[...t,...t.map((e=>`${e}-pnpres`))]);if(new Set(this.channels).size!==new Set(n).size||new Set(this.groups).size!==new Set(s).size){const r=X(this.channels,e),i=X(this.groups,t);this.dependencies.presenceState&&(null==r||r.forEach((e=>delete this.dependencies.presenceState[e])),null==i||i.forEach((e=>delete this.dependencies.presenceState[e]))),this.channels=n,this.groups=s,this.engine.transition(Xe(Array.from(new Set(this.channels.slice(0))),Array.from(new Set(this.groups.slice(0))))),this.dependencies.leave&&this.dependencies.leave({channels:r.slice(0),groups:i.slice(0)})}}unsubscribeAll(e){const t=this.getSubscribedChannels(),n=this.getSubscribedChannels();this.channels=[],this.groups=[],this.dependencies.presenceState&&Object.keys(this.dependencies.presenceState).forEach((e=>{delete this.dependencies.presenceState[e]})),this.engine.transition(Xe(this.channels.slice(0),this.groups.slice(0),e)),this.dependencies.leaveAll&&this.dependencies.leaveAll({channels:n,groups:t,isOffline:e})}reconnect({timetoken:e,region:t}){const n=this.getSubscribedChannels(),s=this.getSubscribedChannels();this.engine.transition(st(e,t)),this.dependencies.presenceReconnect&&this.dependencies.presenceReconnect({channels:s,groups:n})}disconnect(e){const t=this.getSubscribedChannels(),n=this.getSubscribedChannels();this.engine.transition(nt(e)),this.dependencies.presenceDisconnect&&this.dependencies.presenceDisconnect({channels:n,groups:t,isOffline:e})}getSubscribedChannels(){return Array.from(new Set(this.channels.slice(0)))}getSubscribedChannelGroups(){return Array.from(new Set(this.groups.slice(0)))}dispose(){this.disconnect(!0),this._unsubscribeEngine(),this.dispatcher.dispose()}}class gt extends ce{constructor(e){var t;const n=null!==(t=e.sendByPost)&&void 0!==t&&t;super({method:n?W.POST:W.GET,compressible:n}),this.parameters=e,this.parameters.sendByPost=n}operation(){return le.PNPublishOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:n}=this.parameters,s=this.prepareMessagePayload(e);return`/publish/${n.publishKey}/${n.subscribeKey}/0/${V(t)}/0${this.parameters.sendByPost?"":`/${V(s)}`}`}get queryParameters(){const{customMessageType:e,meta:t,replicate:n,storeInHistory:s,ttl:r}=this.parameters,i={};return e&&(i.custom_message_type=e),void 0!==s&&(i.store=s?"1":"0"),void 0!==r&&(i.ttl=r),void 0===n||n||(i.norep="true"),t&&"object"==typeof t&&(i.meta=JSON.stringify(t)),i}get headers(){var e;if(this.parameters.sendByPost)return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return this.prepareMessagePayload(this.parameters.message)}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class yt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSignalOperation}validate(){const{message:e,channel:t,keySet:{publishKey:n}}=this.parameters;return t?e?n?void 0:"Missing 'publishKey'":"Missing 'message'":"Missing 'channel'"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{keySet:{publishKey:e,subscribeKey:t},channel:n,message:s}=this.parameters,r=JSON.stringify(s);return`/signal/${e}/${t}/0/${V(n)}/0/${V(r)}`}get queryParameters(){const{customMessageType:e}=this.parameters,t={};return e&&(t.custom_message_type=e),t}}class ft extends de{operation(){return le.PNReceiveMessagesOperation}validate(){const e=super.validate();return e||(this.parameters.timetoken?this.parameters.region?void 0:"region can not be empty":"timetoken can not be empty")}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,timetoken:n,region:s}=this.parameters,r={ee:""};return e&&e.length>0&&(r["channel-group"]=e.sort().join(",")),t&&t.length>0&&(r["filter-expr"]=t),"string"==typeof n?n&&n.length>0&&(r.tt=n):n&&n>0&&(r.tt=n),s&&(r.tr=s),r}}class bt extends de{operation(){return le.PNHandshakeOperation}get path(){const{keySet:{subscribeKey:e},channels:t=[]}=this.parameters;return`/v2/subscribe/${e}/${z(t.sort(),",")}/0`}get queryParameters(){const{channelGroups:e,filterExpression:t,state:n}=this.parameters,s={tt:0,ee:""};return e&&e.length>0&&(s["channel-group"]=e.sort().join(",")),t&&t.length>0&&(s["filter-expr"]=t),n&&Object.keys(n).length>0&&(s.state=JSON.stringify(n)),s}}class mt extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=(s=this.parameters).channels)&&void 0!==t||(s.channels=[]),null!==(n=(r=this.parameters).channelGroups)&&void 0!==n||(r.channelGroups=[])}operation(){return le.PNGetStateOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;if(!e)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),{channels:n=[],channelGroups:s=[]}=this.parameters,r={channels:{}};return 1===n.length&&0===s.length?r.channels[n[0]]=t.payload:r.channels=t.payload,r}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${t}`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.join(",")}:{}}}class vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNSetStateOperation}validate(){const{keySet:{subscribeKey:e},state:t,channels:n=[],channelGroups:s=[]}=this.parameters;return e?t?0===(null==n?void 0:n.length)&&0===(null==s?void 0:s.length)?"Please provide a list of channels and/or channel-groups":void 0:"Missing State":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{state:this.deserializeResponse(e).payload}}))}get path(){const{keySet:{subscribeKey:e},uuid:t,channels:n}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=n?n:[],",")}/uuid/${V(t)}/data`}get queryParameters(){const{channelGroups:e,state:t}=this.parameters,n={state:JSON.stringify(t)};return e&&0!==e.length&&(n["channel-group"]=e.join(",")),n}}class St extends ce{constructor(e){super({cancellable:!0}),this.parameters=e}operation(){return le.PNHeartbeatOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"Please provide a list of channels and/or channel-groups":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channels:t}=this.parameters;return`/v2/presence/sub-key/${e}/channel/${z(null!=t?t:[],",")}/heartbeat`}get queryParameters(){const{channelGroups:e,state:t,heartbeat:n}=this.parameters,s={heartbeat:`${n}`};return e&&0!==e.length&&(s["channel-group"]=e.join(",")),t&&(s.state=JSON.stringify(t)),s}}class wt extends ce{constructor(e){super(),this.parameters=e,this.parameters.channelGroups&&(this.parameters.channelGroups=Array.from(new Set(this.parameters.channelGroups))),this.parameters.channels&&(this.parameters.channels=Array.from(new Set(this.parameters.channels)))}operation(){return le.PNUnsubscribeOperation}validate(){const{keySet:{subscribeKey:e},channels:t=[],channelGroups:n=[]}=this.parameters;return e?0===t.length&&0===n.length?"At least one `channel` or `channel group` should be provided.":void 0:"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){var e;const{keySet:{subscribeKey:t},channels:n}=this.parameters;return`/v2/presence/sub-key/${t}/channel/${z(null!==(e=null==n?void 0:n.sort())&&void 0!==e?e:[],",")}/leave`}get queryParameters(){const{channelGroups:e}=this.parameters;return e&&0!==e.length?{"channel-group":e.sort().join(",")}:{}}}class Ot extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNWhereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return t.payload?{channels:t.payload.channels}:{channels:[]}}))}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/presence/sub-key/${e}/uuid/${V(t)}`}}class kt extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=(r=this.parameters).queryParameters)&&void 0!==t||(r.queryParameters={}),null!==(n=(i=this.parameters).includeUUIDs)&&void 0!==n||(i.includeUUIDs=true),null!==(s=(a=this.parameters).includeState)&&void 0!==s||(a.includeState=false)}operation(){const{channels:e=[],channelGroups:t=[]}=this.parameters;return 0===e.length&&0===t.length?le.PNGlobalHereNowOperation:le.PNHereNowOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t,n;const s=this.deserializeResponse(e),r="occupancy"in s?1:s.payload.total_channels,i="occupancy"in s?s.occupancy:s.payload.total_occupancy,a={};let o={};if("occupancy"in s){const e=this.parameters.channels[0];o[e]={uuids:null!==(t=s.uuids)&&void 0!==t?t:[],occupancy:i}}else o=null!==(n=s.payload.channels)&&void 0!==n?n:{};return Object.keys(o).forEach((e=>{const t=o[e];a[e]={occupants:this.parameters.includeUUIDs?t.uuids.map((e=>"string"==typeof e?{uuid:e,state:null}:e)):[],name:e,occupancy:t.occupancy}})),{totalChannels:r,totalOccupancy:i,channels:a}}))}get path(){const{keySet:{subscribeKey:e},channels:t,channelGroups:n}=this.parameters;let s=`/v2/presence/sub-key/${e}`;return(t&&t.length>0||n&&n.length>0)&&(s+=`/channel/${z(null!=t?t:[],",")}`),s}get queryParameters(){const{channelGroups:e,includeUUIDs:t,includeState:n,queryParameters:s}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign({},t?{}:{disable_uuids:"1"}),null!=n&&n?{state:"1"}:{}),e&&e.length>0?{"channel-group":e.join(",")}:{}),s)}}class Et extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteMessagesOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v3/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t}=this.parameters;return Object.assign(Object.assign({},e?{start:e}:{}),t?{end:t}:{})}}class Ct extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNMessageCounts}validate(){const{keySet:{subscribeKey:e},channels:t,timetoken:n,channelTimetokens:s}=this.parameters;return e?t?n&&s?"`timetoken` and `channelTimetokens` are incompatible together":n||s?s&&s.length>1&&s.length!==t.length?"Length of `channelTimetokens` and `channels` do not match":void 0:"`timetoken` or `channelTimetokens` need to be set":"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).channels}}))}get path(){return`/v3/history/sub-key/${this.parameters.keySet.subscribeKey}/message-counts/${z(this.parameters.channels)}`}get queryParameters(){let{channelTimetokens:e}=this.parameters;return this.parameters.timetoken&&(e=[this.parameters.timetoken]),Object.assign(Object.assign({},1===e.length?{timetoken:e[0]}:{}),e.length>1?{channelsTimetoken:e.join(",")}:{})}}class Pt extends ce{constructor(e){var t,n,s;super(),this.parameters=e,e.count?e.count=Math.min(e.count,100):e.count=100,null!==(t=e.stringifiedTimeToken)&&void 0!==t||(e.stringifiedTimeToken=false),null!==(n=e.includeMeta)&&void 0!==n||(e.includeMeta=false),null!==(s=e.logVerbosity)&&void 0!==s||(e.logVerbosity=false)}operation(){return le.PNHistoryOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e),n=t[0],s=t[1],r=t[2];return Array.isArray(n)?{messages:n.map((e=>{const t=this.processPayload(e.message),n={entry:t.payload,timetoken:e.timetoken};return t.error&&(n.error=t.error),e.meta&&(n.meta=e.meta),n})),startTimeToken:s,endTimeToken:r}:{messages:[],startTimeToken:s,endTimeToken:r}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/history/sub-key/${e}/channel/${V(t)}`}get queryParameters(){const{start:e,end:t,reverse:n,count:s,stringifiedTimeToken:r,includeMeta:i}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:s,include_token:"true"},e?{start:e}:{}),t?{end:t}:{}),r?{string_message_token:"true"}:{}),null!=n?{reverse:n.toString()}:{}),i?{include_meta:"true"}:{})}processPayload(e){const{crypto:t,logVerbosity:n}=this.parameters;if(!t||"string"!=typeof e)return{payload:e};let s,r;try{const n=t.decrypt(e);s=n instanceof ArrayBuffer?JSON.parse(Pt.decoder.decode(n)):n}catch(t){n&&console.log("decryption error",t.message),s=e,r=`Error while decrypting message content: ${t.message}`}return{payload:s,error:r}}}var Nt;!function(e){e[e.Message=-1]="Message",e[e.Files=4]="Files"}(Nt||(Nt={}));class Mt extends ce{constructor(e){var t,n,s,r,i;super(),this.parameters=e;const a=null!==(t=e.includeMessageActions)&&void 0!==t&&t,o=e.channels.length>1||a?25:100;e.count?e.count=Math.min(e.count,o):e.count=o,e.includeUuid?e.includeUUID=e.includeUuid:null!==(n=e.includeUUID)&&void 0!==n||(e.includeUUID=true),null!==(s=e.stringifiedTimeToken)&&void 0!==s||(e.stringifiedTimeToken=false),null!==(r=e.includeMessageType)&&void 0!==r||(e.includeMessageType=true),null!==(i=e.logVerbosity)&&void 0!==i||(e.logVerbosity=false)}operation(){return le.PNFetchMessagesOperation}validate(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return e?t?void 0!==n&&n&&t.length>1?"History can return actions data for a single channel only. Either pass a single channel or disable the includeMessageActions flag.":void 0:"Missing channels":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){var t;const n=this.deserializeResponse(e),s=null!==(t=n.channels)&&void 0!==t?t:{},r={};return Object.keys(s).forEach((e=>{r[e]=s[e].map((t=>{null===t.message_type&&(t.message_type=Nt.Message);const n=this.processPayload(e,t),s=Object.assign(Object.assign({channel:e,timetoken:t.timetoken,message:n.payload,messageType:t.message_type},t.custom_message_type?{customMessageType:t.custom_message_type}:{}),{uuid:t.uuid});if(t.actions){const e=s;e.actions=t.actions,e.data=t.actions}return t.meta&&(s.meta=t.meta),n.error&&(s.error=n.error),s}))})),n.more?{channels:r,more:n.more}:{channels:r}}))}get path(){const{keySet:{subscribeKey:e},channels:t,includeMessageActions:n}=this.parameters;return`/v3/${n?"history-with-actions":"history"}/sub-key/${e}/channel/${z(t)}`}get queryParameters(){const{start:e,end:t,count:n,includeCustomMessageType:s,includeMessageType:r,includeMeta:i,includeUUID:a,stringifiedTimeToken:o}=this.parameters;return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({max:n},e?{start:e}:{}),t?{end:t}:{}),o?{string_message_token:"true"}:{}),void 0!==i&&i?{include_meta:"true"}:{}),a?{include_uuid:"true"}:{}),null!=s?{include_custom_message_type:s?"true":"false"}:{}),r?{include_message_type:"true"}:{})}processPayload(e,t){const{crypto:n,logVerbosity:s}=this.parameters;if(!n||"string"!=typeof t.message)return{payload:t.message};let r,i;try{const e=n.decrypt(t.message);r=e instanceof ArrayBuffer?JSON.parse(Mt.decoder.decode(e)):e}catch(e){s&&console.log("decryption error",e.message),r=t.message,i=`Error while decrypting message content: ${e.message}`}if(!i&&r&&t.message_type==Nt.Files&&"object"==typeof r&&this.isFileMessage(r)){const t=r;return{payload:{message:t.message,file:Object.assign(Object.assign({},t.file),{url:this.parameters.getFileUrl({channel:e,id:t.file.id,name:t.file.name})})},error:i}}return{payload:r,error:i}}isFileMessage(e){return void 0!==e.file}}class jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNGetMessageActionsOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channel?void 0:"Missing message channel":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);let n=null,s=null;return t.data.length>0&&(n=t.data[0].actionTimetoken,s=t.data[t.data.length-1].actionTimetoken),{data:t.data,more:t.more,start:n,end:s}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}`}get queryParameters(){const{limit:e,start:t,end:n}=this.parameters;return Object.assign(Object.assign(Object.assign({},t?{start:t}:{}),n?{end:n}:{}),e?{limit:e}:{})}}class At extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNAddMessageActionOperation}validate(){const{keySet:{subscribeKey:e},action:t,channel:n,messageTimetoken:s}=this.parameters;return e?n?s?t?t.value?t.type?t.type.length>15?"Action.type value exceed maximum length of 15":void 0:"Missing Action.type":"Missing Action.value":"Missing Action":"Missing message timetoken":"Missing message channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${n}`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify(this.parameters.action)}}class _t extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveMessageActionOperation}validate(){const{keySet:{subscribeKey:e},channel:t,messageTimetoken:n,actionTimetoken:s}=this.parameters;return e?t?n?s?void 0:"Missing action timetoken":"Missing message timetoken":"Missing message action channel":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((({data:e})=>({data:e})))}))}get path(){const{keySet:{subscribeKey:e},channel:t,actionTimetoken:n,messageTimetoken:s}=this.parameters;return`/v1/message-actions/${e}/channel/${V(t)}/message/${s}/action/${n}`}}class It extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).storeInHistory)&&void 0!==t||(n.storeInHistory=true)}operation(){return le.PNPublishFileMessageOperation}validate(){const{channel:e,fileId:t,fileName:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[2]}}))}get path(){const{message:e,channel:t,keySet:{publishKey:n,subscribeKey:s},fileId:r,fileName:i}=this.parameters,a=Object.assign({file:{name:i,id:r}},e?{message:e}:{});return`/v1/files/publish-file/${n}/${s}/0/${V(t)}/0/${V(this.prepareMessagePayload(a))}`}get queryParameters(){const{customMessageType:e,storeInHistory:t,ttl:n,meta:s}=this.parameters;return Object.assign(Object.assign(Object.assign({store:t?"1":"0"},e?{custom_message_type:e}:{}),n?{ttl:n}:{}),s&&"object"==typeof s?{meta:JSON.stringify(s)}:{})}prepareMessagePayload(e){const{crypto:t}=this.parameters;if(!t)return JSON.stringify(e)||"";const n=t.encrypt(JSON.stringify(e));return JSON.stringify("string"==typeof n?n:u(n))}}class Ft extends ce{constructor(e){super({method:W.LOCAL}),this.parameters=e}operation(){return le.PNGetFileUrlOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return e.url}))}get path(){const{channel:e,id:t,name:n,keySet:{subscribeKey:s}}=this.parameters;return`/v1/files/${s}/channels/${V(e)}/files/${t}/${n}`}}class Tt extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNDeleteFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},id:t,channel:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(n)}/files/${t}/${s}`}}class Rt extends ce{constructor(e){var t,n;super(),this.parameters=e,null!==(t=(n=this.parameters).limit)&&void 0!==t||(n.limit=100)}operation(){return le.PNListFilesOperation}validate(){if(!this.parameters.channel)return"channel can't be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files`}get queryParameters(){const{limit:e,next:t}=this.parameters;return Object.assign({limit:e},t?{next:t}:{})}}class Ut extends ce{constructor(e){super({method:W.POST}),this.parameters=e}operation(){return le.PNGenerateUploadUrlOperation}validate(){return this.parameters.channel?this.parameters.name?void 0:"'name' can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const t=this.deserializeResponse(e);return{id:t.data.id,name:t.data.name,url:t.file_upload_request.url,formFields:t.file_upload_request.form_fields}}))}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/generate-upload-url`}get headers(){var e;return Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"Content-Type":"application/json"})}get body(){return JSON.stringify({name:this.parameters.name})}}class xt extends ce{constructor(e){super({method:W.POST}),this.parameters=e;const t=e.file.mimeType;t&&(e.formFields=e.formFields.map((e=>"Content-Type"===e.name?{name:e.name,value:t}:e)))}operation(){return le.PNPublishFileOperation}validate(){const{fileId:e,fileName:t,file:n,uploadUrl:s}=this.parameters;return e?t?n?s?void 0:"Validation failed: file upload 'url' can't be empty":"Validation failed: 'file' can't be empty":"Validation failed: file 'name' can't be empty":"Validation failed: file 'id' can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){return{status:e.status,message:e.body?xt.decoder.decode(e.body):"OK"}}))}request(){return Object.assign(Object.assign({},super.request()),{origin:new URL(this.parameters.uploadUrl).origin,timeout:300})}get path(){const{pathname:e,search:t}=new URL(this.parameters.uploadUrl);return`${e}${t}`}get body(){return this.parameters.file}get formData(){return this.parameters.formFields}}class Dt{constructor(e){var t;if(this.parameters=e,this.file=null===(t=this.parameters.PubNubFile)||void 0===t?void 0:t.create(e.file),!this.file)throw new Error("File upload error: unable to create File object.")}process(){return i(this,void 0,void 0,(function*(){let e,t;return this.generateFileUploadUrl().then((n=>(e=n.name,t=n.id,this.uploadFile(n)))).then((e=>{if(204!==e.status)throw new d("Upload to bucket was unsuccessful",{error:!0,statusCode:e.status,category:h.PNUnknownCategory,operation:le.PNPublishFileOperation,errorData:{message:e.message}})})).then((()=>this.publishFileMessage(t,e))).catch((e=>{if(e instanceof d)throw e;const t=e instanceof _?e:_.create(e);throw new d("File upload error.",t.toStatus(le.PNPublishFileOperation))}))}))}generateFileUploadUrl(){return i(this,void 0,void 0,(function*(){const e=new Ut(Object.assign(Object.assign({},this.parameters),{name:this.file.name,keySet:this.parameters.keySet}));return this.parameters.sendRequest(e)}))}uploadFile(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,PubNubFile:n,crypto:s,cryptography:r}=this.parameters,{id:i,name:a,url:o,formFields:c}=e;return this.parameters.PubNubFile.supportsEncryptFile&&(!t&&s?this.file=yield s.encryptFile(this.file,n):t&&r&&(this.file=yield r.encryptFile(t,this.file,n))),this.parameters.sendRequest(new xt({fileId:i,fileName:a,file:this.file,uploadUrl:o,formFields:c}))}))}publishFileMessage(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i;let a,o={timetoken:"0"},c=this.parameters.fileUploadPublishRetryLimit,u=!1;do{try{o=yield this.parameters.publishFile(Object.assign(Object.assign({},this.parameters),{fileId:e,fileName:t})),u=!0}catch(e){e instanceof d&&(a=e),c-=1}}while(!u&&c>0);if(u)return{status:200,timetoken:o.timetoken,id:e,name:t};throw new d("Publish failed. You may want to execute that operation manually using pubnub.publishFile",{error:!0,category:null!==(s=null===(n=a.status)||void 0===n?void 0:n.category)&&void 0!==s?s:h.PNUnknownCategory,statusCode:null!==(i=null===(r=a.status)||void 0===r?void 0:r.statusCode)&&void 0!==i?i:0,channel:this.parameters.channel,id:e,name:t})}))}}class qt{subscribe(e){const t=null==e?void 0:e.timetoken;this.pubnub.registerSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!0,this.pubnub.subscribe(Object.assign({channels:this.channelNames,channelGroups:this.groupNames},null!==t&&""!==t&&{timetoken:t}))}unsubscribe(){this.pubnub.unregisterSubscribeCapable(this),this.subscribedAutomatically=!1,this.subscribed=!1;const{channels:e,channelGroups:t}=this.pubnub.getSubscribeCapableEntities(),n=this.groupNames.filter((e=>!t.includes(e))),s=this.channelNames.filter((t=>!e.includes(t)));0===s.length&&0===n.length||this.pubnub.unsubscribe({channels:s,channelGroups:n})}set onMessage(e){this.typeBasedListener.message=e}set onPresence(e){this.typeBasedListener.presence=e}set onSignal(e){this.typeBasedListener.signal=e}set onObjects(e){this.typeBasedListener.objects=e}set onMessageAction(e){this.typeBasedListener.messageAction=e}set onFile(e){this.typeBasedListener.file=e}addListener(e){this.aggregatedListener&&this.aggregatedListener!==e&&this.removeListener(this.aggregatedListener),this.aggregatedListenerId=this.eventEmitter.addListener(e,this.channelNames,this.groupNames),this.aggregatedListener=e}removeListener(e){this.aggregatedListener&&(this.eventEmitter.removeListener(e,this.aggregatedListenerId,this.channelNames,this.groupNames),this.aggregatedListenerId=void 0,this.aggregatedListener=void 0)}get channels(){return this.channelNames.slice(0)}get channelGroups(){return this.groupNames.slice(0)}}class Lt extends qt{constructor({channels:e=[],channelGroups:t=[],subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscriptionList=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.options=n,this.eventEmitter=s,this.pubnub=r,e.forEach((e=>this.subscriptionList.push(this.pubnub.channel(e).subscription(this.options)))),t.forEach((e=>this.subscriptionList.push(this.pubnub.channelGroup(e).subscription(this.options)))),this.typeBasedListener={},this.typeBasedListenerId=s.addListener(this.typeBasedListener,this.channelNames,this.groupNames),this.updateListeners()}addSubscription(e){this.subscriptionList.includes(e)||this.subscriptionList.push(e),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscription(e){this.subscriptionList=this.subscriptionList.filter((t=>t!==e)),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}addSubscriptionSet(e){this.subscriptionList=Array.from(new Set([...this.subscriptionList,...e.subscriptions])),this.updateListeners(),this.subscribed&&!e.subscribed&&(e.subscribe(),e.subscribedAutomatically=!0)}removeSubscriptionSet(e){this.subscriptionList=this.subscriptionList.filter((t=>!e.subscriptions.includes(t))),this.updateListeners(),e.subscribedAutomatically&&e.unsubscribe()}get subscriptions(){return this.subscriptionList.slice(0)}updateListeners(){const e=[],t=[];this.subscriptionList.forEach((n=>{n.channelGroups.length&&e.push(...n.channelGroups),n.channels.length&&t.push(...n.channels)}));const n=this.channelNames.filter((e=>!t.includes(e))),s=this.groupNames.filter((t=>!e.includes(t))),r=t.filter((e=>!this.channelNames.includes(e))),i=e.filter((e=>!this.groupNames.includes(e)));(n.length||s.length)&&this.eventEmitter.removeListener(this.typeBasedListener,this.typeBasedListenerId,n,s),(r.length||i.length)&&this.eventEmitter.addListener(this.typeBasedListener,r,i,this.typeBasedListenerId);const a=this.aggregatedListener;a&&this.removeListener(a),this.groupNames=e,this.channelNames=t,a&&this.addListener(a)}}class Gt extends qt{constructor({channels:e,channelGroups:t,subscriptionOptions:n,eventEmitter:s,pubnub:r}){super(),this.channelNames=[],this.groupNames=[],this.subscribedAutomatically=!1,this.subscribed=!1,this.channelNames=e,this.groupNames=t,this.options=n,this.pubnub=r,this.eventEmitter=s,this.typeBasedListener={},s.addListener(this.typeBasedListener,this.channelNames,this.groupNames)}addSubscription(e){const t=new Lt({channels:[...this.channelNames,...e.channels],channelGroups:[...this.groupNames,...e.channelGroups],subscriptionOptions:Object.assign(Object.assign({},this.options),null==e?void 0:e.options),eventEmitter:this.eventEmitter,pubnub:this.pubnub});return this.subscribed&&(e.subscribed||(e.subscribe(),e.subscribedAutomatically=!0),this.aggregatedListener&&t.addListener(this.aggregatedListener),this.pubnub.registerSubscribeCapable(t),t.subscribed=!0),t}}class Kt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class $t{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:[],channelGroups:t,subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Bt{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.id=e}subscription(e){return new Gt({channels:[this.id],channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}class Ht{constructor(e,t,n){this.eventEmitter=t,this.pubnub=n,this.name=e}subscription(e){{const t=[this.name];return(null==e?void 0:e.receivePresenceEvents)&&!this.name.endsWith("-pnpres")&&t.push(`${this.name}-pnpres`),new Gt({channels:t,channelGroups:[],subscriptionOptions:e,eventEmitter:this.eventEmitter,pubnub:this.pubnub})}}}class Wt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveChannelsFromGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{remove:this.parameters.channels.join(",")}}}class Vt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNAddChannelsToGroupOperation}validate(){const{keySet:{subscribeKey:e},channels:t,channelGroup:n}=this.parameters;return e?n?t?void 0:"Missing channels":"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}get queryParameters(){return{add:this.parameters.channels.join(",")}}}class zt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelsForGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e).payload.channels}}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}`}}class Jt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNRemoveGroupOperation}validate(){return this.parameters.keySet.subscribeKey?this.parameters.channelGroup?void 0:"Missing Channel Group":"Missing Subscribe Key"}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}get path(){const{keySet:{subscribeKey:e},channelGroup:t}=this.parameters;return`/v1/channel-registration/sub-key/${e}/channel-group/${V(t)}/remove`}}class Xt extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNChannelGroupsOperation}validate(){if(!this.parameters.keySet.subscribeKey)return"Missing Subscribe Key"}parse(e){return i(this,void 0,void 0,(function*(){return{groups:this.deserializeResponse(e).payload.groups}}))}get path(){return`/v1/channel-registration/sub-key/${this.parameters.keySet.subscribeKey}/channel-group`}}class Qt{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}listGroups(e){return i(this,void 0,void 0,(function*(){const t=new Xt({keySet:this.keySet});return e?this.sendRequest(t,e):this.sendRequest(t)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Vt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Wt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteGroup(e,t){return i(this,void 0,void 0,(function*(){const n=new Jt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class Yt extends ce{constructor(e){var t,n;super(),this.parameters=e,"apns2"===this.parameters.pushGateway&&(null!==(t=(n=this.parameters).environment)&&void 0!==t||(n.environment="development")),this.parameters.count&&this.parameters.count>1e3&&(this.parameters.count=1e3)}operation(){throw Error("Should be implemented in subclass.")}validate(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;return e?n?"add"!==t&&"remove"!==t||"channels"in this.parameters&&0!==this.parameters.channels.length?s?"apns2"!==this.parameters.pushGateway||this.parameters.topic?void 0:"Missing APNS2 topic":"Missing GW Type (pushGateway: gcm or apns2)":"Missing Channels":"Missing Device ID (device)":"Missing Subscribe Key"}get path(){const{keySet:{subscribeKey:e},action:t,device:n,pushGateway:s}=this.parameters;let r="apns2"===s?`/v2/push/sub-key/${e}/devices-apns2/${n}`:`/v1/push/sub-key/${e}/devices/${n}`;return"remove-device"===t&&(r=`${r}/remove`),r}get queryParameters(){const{start:e,count:t}=this.parameters;let n=Object.assign(Object.assign({type:this.parameters.pushGateway},e?{start:e}:{}),t&&t>0?{count:t}:{});if("channels"in this.parameters&&(n[this.parameters.action]=this.parameters.channels.join(",")),"apns2"===this.parameters.pushGateway){const{environment:e,topic:t}=this.parameters;n=Object.assign(Object.assign({},n),{environment:e,topic:t})}return n}}class Zt extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove"}))}operation(){return le.PNRemovePushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class en extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"list"}))}operation(){return le.PNPushNotificationEnabledChannelsOperation}parse(e){return i(this,void 0,void 0,(function*(){return{channels:this.deserializeResponse(e)}}))}}class tn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"add"}))}operation(){return le.PNAddPushNotificationEnabledChannelsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class nn extends Yt{constructor(e){super(Object.assign(Object.assign({},e),{action:"remove-device"}))}operation(){return le.PNRemoveAllPushNotificationsOperation}parse(e){const t=Object.create(null,{parse:{get:()=>super.parse}});return i(this,void 0,void 0,(function*(){return t.parse.call(this,e).then((e=>({})))}))}}class sn{constructor(e,t){this.sendRequest=t,this.keySet=e}listChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new en(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}addChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new tn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannels(e,t){return i(this,void 0,void 0,(function*(){const n=new Zt(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}deleteDevice(e,t){return i(this,void 0,void 0,(function*(){const n=new nn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}}class rn extends ce{constructor(e){var t,n,s,r,i,a;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(i=e.include).customFields)&&void 0!==n||(i.customFields=false),null!==(s=(a=e.include).totalCount)&&void 0!==s||(a.totalCount=false),null!==(r=e.limit)&&void 0!==r||(e.limit=100)}operation(){return le.PNGetAllChannelMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(","),count:`${e.totalCount}`},n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class an extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e}operation(){return le.PNRemoveChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}}class on extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetMembershipsOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class cn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).channelFields)&&void 0!==a||(y.channelFields=false),null!==(o=(f=e.include).customChannelFields)&&void 0!==o||(f.customChannelFields=false),null!==(c=(b=e.include).channelStatusField)&&void 0!==c||(b.channelStatusField=false),null!==(u=(m=e.include).channelTypeField)&&void 0!==u||(m.channelTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetMembershipsOperation}validate(){const{uuid:e,channels:t}=this.parameters;return e?t&&0!==t.length?void 0:"Channels cannot be empty":"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}/channels`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["channel.status","channel.type","status"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.channelFields&&a.push("channel"),e.channelStatusField&&a.push("channel.status"),e.channelTypeField&&a.push("channel.type"),e.customChannelFields&&a.push("channel.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{channels:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{channel:{id:e}}:{channel:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class un extends ce{constructor(e){var t,n,s,r;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(r=e.include).customFields)&&void 0!==n||(r.customFields=false),null!==(s=e.limit)&&void 0!==s||(e.limit=100)}operation(){return le.PNGetAllUUIDMetadataOperation}get path(){return`/v2/objects/${this.parameters.keySet.subscribeKey}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";return i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e)),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({include:["status","type",...e.customFields?["custom"]:[]].join(",")},void 0!==e.totalCount?{count:`${e.totalCount}`}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class ln extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNGetChannelMetadataOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}}class hn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true)}operation(){return le.PNSetChannelMetadataOperation}validate(){return this.parameters.channel?this.parameters.data?void 0:"Data cannot be empty":"Channel cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class dn extends ce{constructor(e){super({method:W.DELETE}),this.parameters=e,this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNRemoveUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}}class pn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){if(!this.parameters.channel)return"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=[];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}}class gn extends ce{constructor(e){var t,n,s,r,i,a,o,c,u,l,h,d,p,g,y,f,b,m;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(h=e.include).customFields)&&void 0!==n||(h.customFields=false),null!==(s=(d=e.include).totalCount)&&void 0!==s||(d.totalCount=false),null!==(r=(p=e.include).statusField)&&void 0!==r||(p.statusField=false),null!==(i=(g=e.include).typeField)&&void 0!==i||(g.typeField=false),null!==(a=(y=e.include).UUIDFields)&&void 0!==a||(y.UUIDFields=false),null!==(o=(f=e.include).customUUIDFields)&&void 0!==o||(f.customUUIDFields=false),null!==(c=(b=e.include).UUIDStatusField)&&void 0!==c||(b.UUIDStatusField=false),null!==(u=(m=e.include).UUIDTypeField)&&void 0!==u||(m.UUIDTypeField=false),null!==(l=e.limit)&&void 0!==l||(e.limit=100)}operation(){return le.PNSetMembersOperation}validate(){const{channel:e,uuids:t}=this.parameters;return e?t&&0!==t.length?void 0:"UUIDs cannot be empty":"Channel cannot be empty"}get path(){const{keySet:{subscribeKey:e},channel:t}=this.parameters;return`/v2/objects/${e}/channels/${V(t)}/uuids`}get queryParameters(){const{include:e,page:t,filter:n,sort:s,limit:r}=this.parameters;let i="";i="string"==typeof s?s:Object.entries(null!=s?s:{}).map((([e,t])=>null!==t?`${e}:${t}`:e));const a=["uuid.status","uuid.type","type"];return e.statusField&&a.push("status"),e.typeField&&a.push("type"),e.customFields&&a.push("custom"),e.UUIDFields&&a.push("uuid"),e.UUIDStatusField&&a.push("uuid.status"),e.UUIDTypeField&&a.push("uuid.type"),e.customUUIDFields&&a.push("uuid.custom"),Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({count:`${e.totalCount}`},a.length>0?{include:a.join(",")}:{}),n?{filter:n}:{}),(null==t?void 0:t.next)?{start:t.next}:{}),(null==t?void 0:t.prev)?{end:t.prev}:{}),r?{limit:r}:{}),i.length?{sort:i}:{})}get body(){const{uuids:e,type:t}=this.parameters;return JSON.stringify({[`${t}`]:e.map((e=>"string"==typeof e?{uuid:{id:e}}:{uuid:{id:e.id},status:e.status,type:e.type,custom:e.custom}))})}}class yn extends ce{constructor(e){var t,n,s;super(),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNGetUUIDMetadataOperation}validate(){if(!this.parameters.uuid)return"'uuid' cannot be empty"}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){const{include:e}=this.parameters;return{include:["status","type",...e.customFields?["custom"]:[]].join(",")}}}class fn extends ce{constructor(e){var t,n,s;super({method:W.PATCH}),this.parameters=e,null!==(t=e.include)&&void 0!==t||(e.include={}),null!==(n=(s=e.include).customFields)&&void 0!==n||(s.customFields=true),this.parameters.userId&&(this.parameters.uuid=this.parameters.userId)}operation(){return le.PNSetUUIDMetadataOperation}validate(){return this.parameters.uuid?this.parameters.data?void 0:"Data cannot be empty":"'uuid' cannot be empty"}get headers(){var e;return this.parameters.ifMatchesEtag?Object.assign(Object.assign({},null!==(e=super.headers)&&void 0!==e?e:{}),{"If-Match":this.parameters.ifMatchesEtag}):super.headers}get path(){const{keySet:{subscribeKey:e},uuid:t}=this.parameters;return`/v2/objects/${e}/uuids/${V(t)}`}get queryParameters(){return{include:["status","type",...this.parameters.include.customFields?["custom"]:[]].join(",")}}get body(){return JSON.stringify(this.parameters.data)}}class bn{constructor(e,t){this.keySet=e.keySet,this.configuration=e,this.sendRequest=t}getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllUUIDMetadata(e,t)}))}_getAllUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new un(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getUUIDMetadata(e,t)}))}_getUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new yn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setUUIDMetadata(e,t)}))}_setUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new fn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeUUIDMetadata(e,t)}))}_removeUUIDMetadata(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new dn(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getAllChannelMetadata(e,t)}))}_getAllChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0);const s=new rn(Object.assign(Object.assign({},n),{keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._getChannelMetadata(e,t)}))}_getChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new ln(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._setChannelMetadata(e,t)}))}_setChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new hn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){return this._removeChannelMetadata(e,t)}))}_removeChannelMetadata(e,t){return i(this,void 0,void 0,(function*(){const n=new an(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new pn(Object.assign(Object.assign({},e),{keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}setChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}removeChannelMembers(e,t){return i(this,void 0,void 0,(function*(){const n=new gn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}))}getMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;const s=e&&"function"!=typeof e?e:{};null!=t||(t="function"==typeof e?e:void 0),s.userId&&(s.uuid=s.userId),null!==(n=s.uuid)&&void 0!==n||(s.uuid=this.configuration.userId);const r=new on(Object.assign(Object.assign({},s),{keySet:this.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}))}setMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"set",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n;e.userId&&(e.uuid=e.userId),null!==(n=e.uuid)&&void 0!==n||(e.uuid=this.configuration.userId);const s=new cn(Object.assign(Object.assign({},e),{type:"delete",keySet:this.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s;if("spaceId"in e){const s=e,r={channel:null!==(n=s.spaceId)&&void 0!==n?n:s.channel,filter:s.filter,limit:s.limit,page:s.page,include:Object.assign({},s.include),sort:s.sort?Object.fromEntries(Object.entries(s.sort).map((([e,t])=>[e.replace("user","uuid"),t]))):void 0},i=e=>({status:e.status,data:e.data.map((e=>({user:e.uuid,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getChannelMembers(r,((e,n)=>{t(e,n?i(n):n)})):this.getChannelMembers(r).then(i)}const r=e,i={uuid:null!==(s=r.userId)&&void 0!==s?s:r.uuid,filter:r.filter,limit:r.limit,page:r.page,include:Object.assign({},r.include),sort:r.sort?Object.fromEntries(Object.entries(r.sort).map((([e,t])=>[e.replace("space","channel"),t]))):void 0},a=e=>({status:e.status,data:e.data.map((e=>({space:e.channel,custom:e.custom,updated:e.updated,eTag:e.eTag}))),totalCount:e.totalCount,next:e.next,prev:e.prev});return t?this.getMemberships(i,((e,n)=>{t(e,n?a(n):n)})):this.getMemberships(i).then(a)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r,i,a,o;if("spaceId"in e){const i=e,a={channel:null!==(n=i.spaceId)&&void 0!==n?n:i.channel,uuids:null!==(r=null===(s=i.users)||void 0===s?void 0:s.map((e=>"string"==typeof e?e:{id:e.userId,custom:e.custom})))&&void 0!==r?r:i.uuids,limit:0};return t?this.setChannelMembers(a,t):this.setChannelMembers(a)}const c=e,u={uuid:null!==(i=c.userId)&&void 0!==i?i:c.uuid,channels:null!==(o=null===(a=c.spaces)||void 0===a?void 0:a.map((e=>"string"==typeof e?e:{id:e.spaceId,custom:e.custom})))&&void 0!==o?o:c.channels,limit:0};return t?this.setMemberships(u,t):this.setMemberships(u)}))}}class mn extends ce{constructor(){super()}operation(){return le.PNTimeOperation}parse(e){return i(this,void 0,void 0,(function*(){return{timetoken:this.deserializeResponse(e)[0]}}))}get path(){return"/time/0"}}class vn extends ce{constructor(e){super(),this.parameters=e}operation(){return le.PNDownloadFileOperation}validate(){const{channel:e,id:t,name:n}=this.parameters;return e?t?n?void 0:"file name can't be empty":"file id can't be empty":"channel can't be empty"}parse(e){return i(this,void 0,void 0,(function*(){const{cipherKey:t,crypto:n,cryptography:s,name:r,PubNubFile:i}=this.parameters,a=e.headers["content-type"];let o,c=e.body;return i.supportsEncryptFile&&(t||n)&&(t&&s?c=yield s.decrypt(t,c):!t&&n&&(o=yield n.decryptFile(i.create({data:c,name:r,mimeType:a}),i))),o||i.create({data:c,name:r,mimeType:a})}))}get path(){const{keySet:{subscribeKey:e},channel:t,id:n,name:s}=this.parameters;return`/v1/files/${e}/channels/${V(t)}/files/${n}/${s}`}}class Sn{static notificationPayload(e,t){return new oe(e,t)}static generateUUID(){return K.createUUID()}constructor(e){if(this._configuration=e.configuration,this.cryptography=e.cryptography,this.tokenManager=e.tokenManager,this.transport=e.transport,this.crypto=e.crypto,this._objects=new bn(this._configuration,this.sendRequest.bind(this)),this._channelGroups=new Qt(this._configuration.keySet,this.sendRequest.bind(this)),this._push=new sn(this._configuration.keySet,this.sendRequest.bind(this)),this.listenerManager=new ee,this.eventEmitter=new ge(this.listenerManager),this.subscribeCapable=new Set,this._configuration.enableEventEngine){let e=this._configuration.getHeartbeatInterval();this.presenceState={},e&&(this.presenceEventEngine=new He({heartbeat:this.heartbeat.bind(this),leave:e=>this.makeUnsubscribe(e,(()=>{})),heartbeatDelay:()=>new Promise(((t,n)=>{e=this._configuration.getHeartbeatInterval(),e?setTimeout(t,1e3*e):n(new d("Heartbeat interval has been reset."))})),emitStatus:e=>this.listenerManager.announceStatus(e),config:this._configuration,presenceState:this.presenceState})),this.eventEngine=new pt({handshake:this.subscribeHandshake.bind(this),receiveMessages:this.subscribeReceiveMessages.bind(this),delay:e=>new Promise((t=>setTimeout(t,e))),join:this.join.bind(this),leave:this.leave.bind(this),leaveAll:this.leaveAll.bind(this),presenceReconnect:this.presenceReconnect.bind(this),presenceDisconnect:this.presenceDisconnect.bind(this),presenceState:this.presenceState,config:this._configuration,emitMessages:e=>{try{e.forEach((e=>this.eventEmitter.emitEvent(e)))}catch(e){const t={error:!0,category:h.PNUnknownCategory,errorData:e,statusCode:0};this.listenerManager.announceStatus(t)}},emitStatus:e=>this.listenerManager.announceStatus(e)})}else this.subscriptionManager=new se(this._configuration,this.listenerManager,this.eventEmitter,this.makeSubscribe.bind(this),this.heartbeat.bind(this),this.makeUnsubscribe.bind(this),this.time.bind(this))}get configuration(){return this._configuration}get _config(){return this.configuration}get authKey(){var e;return null!==(e=this._configuration.authKey)&&void 0!==e?e:void 0}getAuthKey(){return this.authKey}setAuthKey(e){this._configuration.setAuthKey(e)}get userId(){return this._configuration.userId}set userId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}getUserId(){return this._configuration.userId}setUserId(e){if(!e||"string"!=typeof e||0===e.trim().length)throw new Error("Missing or invalid userId parameter. Provide a valid string userId");this._configuration.userId=e}get filterExpression(){var e;return null!==(e=this._configuration.getFilterExpression())&&void 0!==e?e:void 0}getFilterExpression(){return this.filterExpression}set filterExpression(e){this._configuration.setFilterExpression(e)}setFilterExpression(e){this.filterExpression=e}get cipherKey(){return this._configuration.getCipherKey()}set cipherKey(e){this._configuration.setCipherKey(e)}setCipherKey(e){this.cipherKey=e}set heartbeatInterval(e){this._configuration.setHeartbeatInterval(e)}setHeartbeatInterval(e){this.heartbeatInterval=e}getVersion(){return this._configuration.getVersion()}_addPnsdkSuffix(e,t){this._configuration._addPnsdkSuffix(e,t)}getUUID(){return this.userId}setUUID(e){this.userId=e}get customEncrypt(){return this._configuration.getCustomEncrypt()}get customDecrypt(){return this._configuration.getCustomDecrypt()}channel(e){return new Ht(e,this.eventEmitter,this)}channelGroup(e){return new $t(e,this.eventEmitter,this)}channelMetadata(e){return new Kt(e,this.eventEmitter,this)}userMetadata(e){return new Bt(e,this.eventEmitter,this)}subscriptionSet(e){return new Lt(Object.assign(Object.assign({},e),{eventEmitter:this.eventEmitter,pubnub:this}))}sendRequest(e,t){return i(this,void 0,void 0,(function*(){const n=e.validate();if(n){if(t)return t(g(n),null);throw new d("Validation failed, check status for details",g(n))}const s=e.request(),r=e.operation();s.formData&&s.formData.length>0||r===le.PNDownloadFileOperation?s.timeout=this._configuration.getFileTimeout():r===le.PNSubscribeOperation||r===le.PNReceiveMessagesOperation?s.timeout=this._configuration.getSubscribeTimeout():s.timeout=this._configuration.getTransactionTimeout();const i={error:!1,operation:r,category:h.PNAcknowledgmentCategory,statusCode:0},[a,o]=this.transport.makeSendable(s);return e.cancellationController=o||null,a.then((t=>{if(i.statusCode=t.status,200!==t.status&&204!==t.status){const e=Sn.decoder.decode(t.body),n=t.headers["content-type"];if(n||-1!==n.indexOf("javascript")||-1!==n.indexOf("json")){const t=JSON.parse(e);"object"==typeof t&&"error"in t&&t.error&&"object"==typeof t.error&&(i.errorData=t.error)}else i.responseText=e}return e.parse(t)})).then((e=>t?t(i,e):e)).catch((e=>{const n=e instanceof _?e:_.create(e);if(t)return t(n.toStatus(r),null);throw n.toPubNubError(r,"REST API request processing error, check status for details")}))}))}destroy(e){var t;null===(t=this.subscribeCapable)||void 0===t||t.clear(),this.subscriptionManager?(this.subscriptionManager.unsubscribeAll(e),this.subscriptionManager.disconnect()):this.eventEngine&&this.eventEngine.unsubscribeAll(e),this.presenceEventEngine&&this.presenceEventEngine.leaveAll(e)}stop(){this.destroy()}addListener(e){this.listenerManager.addListener(e)}removeListener(e){this.listenerManager.removeListener(e)}removeAllListeners(){this.listenerManager.removeAllListeners()}publish(e,t){return i(this,void 0,void 0,(function*(){{const n=new gt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}signal(e,t){return i(this,void 0,void 0,(function*(){{const n=new yt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fire(e,t){return i(this,void 0,void 0,(function*(){return null!=t||(t=()=>{}),this.publish(Object.assign(Object.assign({},e),{replicate:!1,storeInHistory:!1}),t)}))}getSubscribedChannels(){return this.subscriptionManager?this.subscriptionManager.subscribedChannels:this.eventEngine?this.eventEngine.getSubscribedChannels():[]}getSubscribedChannelGroups(){return this.subscriptionManager?this.subscriptionManager.subscribedChannelGroups:this.eventEngine?this.eventEngine.getSubscribedChannelGroups():[]}registerSubscribeCapable(e){this.subscribeCapable&&!this.subscribeCapable.has(e)&&this.subscribeCapable.add(e)}unregisterSubscribeCapable(e){this.subscribeCapable&&this.subscribeCapable.has(e)&&this.subscribeCapable.delete(e)}getSubscribeCapableEntities(){{const e={channels:[],channelGroups:[]};if(!this.subscribeCapable)return e;for(const t of this.subscribeCapable)e.channelGroups.push(...t.channelGroups),e.channels.push(...t.channels);return e}}subscribe(e){this.subscriptionManager?this.subscriptionManager.subscribe(e):this.eventEngine&&this.eventEngine.subscribe(e)}makeSubscribe(e,t){{const n=new pe(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));if(this.sendRequest(n,((e,s)=>{var r;this.subscriptionManager&&(null===(r=this.subscriptionManager.abort)||void 0===r?void 0:r.identifier)===n.requestIdentifier&&(this.subscriptionManager.abort=null),t(e,s)})),this.subscriptionManager){const e=()=>n.abort("Cancel long-poll subscribe request");e.identifier=n.requestIdentifier,this.subscriptionManager.abort=e}}}unsubscribe(e){this.subscriptionManager?this.subscriptionManager.unsubscribe(e):this.eventEngine&&this.eventEngine.unsubscribe(e)}makeUnsubscribe(e,t){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length)return t({error:!1,operation:le.PNUnsubscribeOperation,category:h.PNAcknowledgmentCategory,statusCode:200});this.sendRequest(new wt({channels:n,channelGroups:s,keySet:this._configuration.keySet}),t)}}unsubscribeAll(){var e;null===(e=this.subscribeCapable)||void 0===e||e.clear(),this.subscriptionManager?this.subscriptionManager.unsubscribeAll():this.eventEngine&&this.eventEngine.unsubscribeAll()}disconnect(e){this.subscriptionManager?this.subscriptionManager.disconnect():this.eventEngine&&this.eventEngine.disconnect(e)}reconnect(e){this.subscriptionManager?this.subscriptionManager.reconnect():this.eventEngine&&this.eventEngine.reconnect(null!=e?e:{})}subscribeHandshake(e){return i(this,void 0,void 0,(function*(){{const t=new bt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel subscribe handshake request")}));return this.sendRequest(t).then((e=>(n(),e.cursor)))}}))}subscribeReceiveMessages(e){return i(this,void 0,void 0,(function*(){{const t=new ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)})),n=e.abortSignal.subscribe((e=>{t.abort("Cancel long-poll subscribe request")}));return this.sendRequest(t).then((e=>(n(),e)))}}))}getMessageActions(e,t){return i(this,void 0,void 0,(function*(){{const n=new jt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}addMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new At(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}removeMessageAction(e,t){return i(this,void 0,void 0,(function*(){{const n=new _t(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}fetchMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Mt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule(),getFileUrl:this.getFileUrl.bind(this)}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}deleteMessages(e,t){return i(this,void 0,void 0,(function*(){{const n=new Et(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}messageCounts(e,t){return i(this,void 0,void 0,(function*(){{const n=new Ct(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}history(e,t){return i(this,void 0,void 0,(function*(){{const n=new Pt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}hereNow(e,t){return i(this,void 0,void 0,(function*(){{const n=new kt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}whereNow(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new Ot({uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet});return t?this.sendRequest(s,t):this.sendRequest(s)}}))}getState(e,t){return i(this,void 0,void 0,(function*(){var n;{const s=new mt(Object.assign(Object.assign({},e),{uuid:null!==(n=e.uuid)&&void 0!==n?n:this._configuration.userId,keySet:this._configuration.keySet}));return t?this.sendRequest(s,t):this.sendRequest(s)}}))}setState(e,t){return i(this,void 0,void 0,(function*(){var n,s;{const{keySet:r,userId:i}=this._configuration,a=this._configuration.getPresenceTimeout();let o;if(this._configuration.enableEventEngine&&this.presenceState){const t=this.presenceState;null===(n=e.channels)||void 0===n||n.forEach((n=>t[n]=e.state)),"channelGroups"in e&&(null===(s=e.channelGroups)||void 0===s||s.forEach((n=>t[n]=e.state)))}return o="withHeartbeat"in e?new St(Object.assign(Object.assign({},e),{keySet:r,heartbeat:a})):new vt(Object.assign(Object.assign({},e),{keySet:r,uuid:i})),this.subscriptionManager&&this.subscriptionManager.setState(e),t?this.sendRequest(o,t):this.sendRequest(o)}}))}presence(e){var t;null===(t=this.subscriptionManager)||void 0===t||t.changePresence(e)}heartbeat(e,t){return i(this,void 0,void 0,(function*(){{let{channels:n,channelGroups:s}=e;if(this._configuration.getKeepPresenceChannelsInPresenceRequests()||(s&&(s=s.filter((e=>!e.endsWith("-pnpres")))),n&&(n=n.filter((e=>!e.endsWith("-pnpres"))))),0===(null!=s?s:[]).length&&0===(null!=n?n:[]).length){const e={error:!1,operation:le.PNHeartbeatOperation,category:h.PNAcknowledgmentCategory,statusCode:200};return t?t(e,{}):Promise.resolve(e)}const r=new St(Object.assign(Object.assign({},e),{channels:n,channelGroups:s,keySet:this._configuration.keySet}));return t?this.sendRequest(r,t):this.sendRequest(r)}}))}join(e){this.presenceEventEngine?this.presenceEventEngine.join(e):this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}presenceReconnect(e){this.presenceEventEngine?this.presenceEventEngine.reconnect():this.heartbeat(Object.assign(Object.assign({channels:e.channels,channelGroups:e.groups},this._configuration.maintainPresenceState&&{state:this.presenceState}),{heartbeat:this._configuration.getPresenceTimeout()}),(()=>{}))}leave(e){var t;this.presenceEventEngine?null===(t=this.presenceEventEngine)||void 0===t||t.leave(e):this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}leaveAll(e={}){this.presenceEventEngine?this.presenceEventEngine.leaveAll(e.isOffline):e.isOffline||this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}presenceDisconnect(e){this.presenceEventEngine?this.presenceEventEngine.disconnect(e.isOffline):e.isOffline||this.makeUnsubscribe({channels:e.channels,channelGroups:e.groups},(()=>{}))}grantToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Token error: PAM module disabled")}))}revokeToken(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Revoke Token error: PAM module disabled")}))}get token(){return this.tokenManager&&this.tokenManager.getToken()}getToken(){return this.token}set token(e){this.tokenManager&&this.tokenManager.setToken(e)}setToken(e){this.token=e}parseToken(e){return this.tokenManager&&this.tokenManager.parseToken(e)}grant(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant error: PAM module disabled")}))}audit(e,t){return i(this,void 0,void 0,(function*(){throw new Error("Grant Permissions error: PAM module disabled")}))}get objects(){return this._objects}fetchUsers(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllUUIDMetadata(e,t)}))}fetchUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getUUIDMetadata(e,t)}))}createUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}updateUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setUUIDMetadata(e,t)}))}removeUser(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeUUIDMetadata(e,t)}))}fetchSpaces(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getAllChannelMetadata(e,t)}))}fetchSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._getChannelMetadata(e,t)}))}createSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}updateSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._setChannelMetadata(e,t)}))}removeSpace(e,t){return i(this,void 0,void 0,(function*(){return this.objects._removeChannelMetadata(e,t)}))}fetchMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.fetchMemberships(e,t)}))}addMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}updateMemberships(e,t){return i(this,void 0,void 0,(function*(){return this.objects.addMemberships(e,t)}))}removeMemberships(e,t){return i(this,void 0,void 0,(function*(){var n,s,r;{if("spaceId"in e){const r=e,i={channel:null!==(n=r.spaceId)&&void 0!==n?n:r.channel,uuids:null!==(s=r.userIds)&&void 0!==s?s:r.uuids,limit:0};return t?this.objects.removeChannelMembers(i,t):this.objects.removeChannelMembers(i)}const i=e,a={uuid:i.userId,channels:null!==(r=i.spaceIds)&&void 0!==r?r:i.channels,limit:0};return t?this.objects.removeMemberships(a,t):this.objects.removeMemberships(a)}}))}get channelGroups(){return this._channelGroups}get push(){return this._push}sendFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new Dt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,fileUploadPublishRetryLimit:this._configuration.fileUploadPublishRetryLimit,file:e.file,sendRequest:this.sendRequest.bind(this),publishFile:this.publishFile.bind(this),crypto:this._configuration.getCryptoModule(),cryptography:this.cryptography?this.cryptography:void 0})),s={error:!1,operation:le.PNPublishFileOperation,category:h.PNAcknowledgmentCategory,statusCode:0};return n.process().then((e=>(s.statusCode=e.status,t?t(s,e):e))).catch((e=>{let n;throw e instanceof d?n=e.status:e instanceof _&&(n=e.toStatus(s.operation)),t&&n&&t(n,null),new d("REST API request processing error, check status for details",n)}))}}))}publishFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new It(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}listFiles(e,t){return i(this,void 0,void 0,(function*(){{const n=new Rt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}getFileUrl(e){var t;{const n=this.transport.request(new Ft(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet})).request()),s=null!==(t=n.queryParameters)&&void 0!==t?t:{},r=Object.keys(s).map((e=>{const t=s[e];return Array.isArray(t)?t.map((t=>`${e}=${V(t)}`)).join("&"):`${e}=${V(t)}`})).join("&");return`${n.origin}${n.path}?${r}`}}downloadFile(e,t){return i(this,void 0,void 0,(function*(){{if(!this._configuration.PubNubFile)throw new Error("Validation failed: 'PubNubFile' not configured or file upload not supported by the platform.");const n=new vn(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet,PubNubFile:this._configuration.PubNubFile,cryptography:this.cryptography?this.cryptography:void 0,crypto:this._configuration.getCryptoModule()}));return t?this.sendRequest(n,t):yield this.sendRequest(n)}}))}deleteFile(e,t){return i(this,void 0,void 0,(function*(){{const n=new Tt(Object.assign(Object.assign({},e),{keySet:this._configuration.keySet}));return t?this.sendRequest(n,t):this.sendRequest(n)}}))}time(e){return i(this,void 0,void 0,(function*(){const t=new mn;return e?this.sendRequest(t,e):this.sendRequest(t)}))}encrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n&&"string"==typeof e){const t=n.encrypt(e);return"string"==typeof t?t:u(t)}if(!this.crypto)throw new Error("Encryption error: cypher key not set");return this.crypto.encrypt(e,t)}decrypt(e,t){const n=this._configuration.getCryptoModule();if(!t&&n){const t=n.decrypt(e);return t instanceof ArrayBuffer?JSON.parse((new TextDecoder).decode(t)):t}if(!this.crypto)throw new Error("Decryption error: cypher key not set");return this.crypto.decrypt(e,t)}encryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File encryption error. File constructor not configured.");if("string"!=typeof e&&!this._configuration.getCryptoModule())throw new Error("File encryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File encryption error. File encryption not available");return this.cryptography.encryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.encryptFile(t,this._configuration.PubNubFile)}))}decryptFile(e,t){return i(this,void 0,void 0,(function*(){var n;if("string"!=typeof e&&(t=e),!t)throw new Error("File encryption error. Source file is missing.");if(!this._configuration.PubNubFile)throw new Error("File decryption error. File constructor not configured.");if("string"==typeof e&&!this._configuration.getCryptoModule())throw new Error("File decryption error. Crypto module not configured.");if("string"==typeof e){if(!this.cryptography)throw new Error("File decryption error. File decryption not available");return this.cryptography.decryptFile(e,t,this._configuration.PubNubFile)}return null===(n=this._configuration.getCryptoModule())||void 0===n?void 0:n.decryptFile(t,this._configuration.PubNubFile)}))}}Sn.decoder=new TextDecoder,Sn.OPERATIONS=le,Sn.CATEGORIES=h,Sn.Endpoint=R,Sn.ExponentialRetryPolicy=U.ExponentialRetryPolicy,Sn.LinearRetryPolicy=U.LinearRetryPolicy,Sn.NoneRetryPolicy=U.None;class wn{constructor(e,t){this.decode=e,this.base64ToBinary=t}decodeToken(e){let t="";e.length%4==3?t="=":e.length%4==2&&(t="==");const n=e.replace(/-/gi,"+").replace(/_/gi,"/")+t,s=this.decode(this.base64ToBinary(n));return"object"==typeof s?s:void 0}}class On extends Sn{constructor(e){var t;const n=T(e),r=Object.assign(Object.assign({},n),{sdkFamily:"Web"});r.PubNubFile=o;const i=$(r,(e=>{if(e.cipherKey)return new M({default:new N(Object.assign({},e)),cryptors:[new k({cipherKey:e.cipherKey})]})}));let a,u,l;a=new H(new wn((e=>F(s.decode(e))),c)),(i.getCipherKey()||i.secretKey)&&(u=new C({secretKey:i.secretKey,cipherKey:i.getCipherKey(),useRandomIVs:i.getUseRandomIVs(),customEncrypt:i.getCustomEncrypt(),customDecrypt:i.getCustomDecrypt()})),l=new P;let h=new Z(r.transport,i.keepAlive,i.logVerbosity);if(n.subscriptionWorkerUrl){const e=new I({clientIdentifier:i._instanceId,subscriptionKey:i.subscribeKey,userId:i.getUserId(),workerUrl:n.subscriptionWorkerUrl,sdkVersion:i.getVersion(),heartbeatInterval:i.getHeartbeatInterval(),workerOfflineClientsCheckInterval:r.subscriptionWorkerOfflineClientsCheckInterval,workerUnsubscribeOfflineClients:r.subscriptionWorkerUnsubscribeOfflineClients,logVerbosity:i.logVerbosity,workerLogVerbosity:r.subscriptionWorkerLogVerbosity,tokenManager:a,transport:h});h=e,window.onpagehide=t=>{t.persisted||e.terminate()}}super({configuration:i,transport:new Y({clientConfiguration:i,tokenManager:a,transport:h}),cryptography:l,tokenManager:a,crypto:u}),(null===(t=e.listenToBrowserNetworkEvents)||void 0===t||t)&&(window.addEventListener("offline",(()=>{this.networkDownDetected()})),window.addEventListener("online",(()=>{this.networkUpDetected()})))}networkDownDetected(){this.listenerManager.announceNetworkDown(),this._configuration.restore?this.disconnect(!0):this.destroy(!0)}networkUpDetected(){this.listenerManager.announceNetworkUp(),this.reconnect()}}return On.CryptoModule=M,On})); diff --git a/lib/core/components/configuration.js b/lib/core/components/configuration.js index 76d7902d1..91f8fd7c8 100644 --- a/lib/core/components/configuration.js +++ b/lib/core/components/configuration.js @@ -144,7 +144,7 @@ const makeConfiguration = (base, setupCryptoModule) => { return base.PubNubFile; }, get version() { - return '9.5.1'; + return '9.5.2'; }, getVersion() { return this.version; diff --git a/lib/core/components/retryPolicy.js b/lib/core/components/retryPolicy.js index f81765e5b..f2484d07b 100644 --- a/lib/core/components/retryPolicy.js +++ b/lib/core/components/retryPolicy.js @@ -203,9 +203,13 @@ exports.RetryPolicy = RetryPolicy; * @internal */ const isRetriableRequest = (req, res, errorCategory, retryAttempt, maximumRetry, excluded) => { - if (errorCategory && errorCategory === categories_1.default.PNCancelledCategory) - return false; - else if (isExcludedRequest(req, excluded)) + if (errorCategory) { + if (errorCategory === categories_1.default.PNCancelledCategory || + errorCategory === categories_1.default.PNBadRequestCategory || + errorCategory === categories_1.default.PNAccessDeniedCategory) + return false; + } + if (isExcludedRequest(req, excluded)) return false; else if (retryAttempt > maximumRetry) return false; diff --git a/lib/core/pubnub-common.js b/lib/core/pubnub-common.js index 7c27e0bcb..b61252662 100644 --- a/lib/core/pubnub-common.js +++ b/lib/core/pubnub-common.js @@ -636,11 +636,11 @@ class PubNubCore { this.subscriptionManager.disconnect(); } else if (this.eventEngine) - this.eventEngine.dispose(); - if (process.env.PRESENCE_MODULE !== 'disabled') { - if (this.presenceEventEngine) - this.presenceEventEngine.dispose(); - } + this.eventEngine.unsubscribeAll(isOffline); + } + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) + this.presenceEventEngine.leaveAll(isOffline); } } /** @@ -1417,11 +1417,11 @@ class PubNubCore { * * @param parameters - List of channels and groups where `leave` event should be sent. */ - leaveAll(parameters) { + leaveAll(parameters = {}) { if (process.env.PRESENCE_MODULE !== 'disabled') { if (this.presenceEventEngine) - this.presenceEventEngine.leaveAll(); - else + this.presenceEventEngine.leaveAll(parameters.isOffline); + else if (!parameters.isOffline) this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => { }); } else diff --git a/lib/event-engine/events.js b/lib/event-engine/events.js index e1db92aaa..bfa5e0413 100644 --- a/lib/event-engine/events.js +++ b/lib/event-engine/events.js @@ -14,9 +14,10 @@ const core_1 = require("./core"); * * @internal */ -exports.subscriptionChange = (0, core_1.createEvent)('SUBSCRIPTION_CHANGED', (channels, groups) => ({ +exports.subscriptionChange = (0, core_1.createEvent)('SUBSCRIPTION_CHANGED', (channels, groups, isOffline) => ({ channels, groups, + isOffline, })); /** * Subscription loop restore. diff --git a/lib/event-engine/index.js b/lib/event-engine/index.js index cc0a4db8c..a5f3bd005 100644 --- a/lib/event-engine/index.js +++ b/lib/event-engine/index.js @@ -114,7 +114,7 @@ class EventEngine { } } } - unsubscribeAll() { + unsubscribeAll(isOffline) { const channelGroups = this.getSubscribedChannels(); const channels = this.getSubscribedChannels(); this.channels = []; @@ -124,9 +124,9 @@ class EventEngine { delete this.dependencies.presenceState[objectName]; }); } - this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0))); + this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0), isOffline)); if (this.dependencies.leaveAll) - this.dependencies.leaveAll({ channels, groups: channelGroups }); + this.dependencies.leaveAll({ channels, groups: channelGroups, isOffline }); } reconnect({ timetoken, region }) { const channelGroups = this.getSubscribedChannels(); diff --git a/lib/event-engine/presence/events.js b/lib/event-engine/presence/events.js index 7a57387df..67bdb74ae 100644 --- a/lib/event-engine/presence/events.js +++ b/lib/event-engine/presence/events.js @@ -57,7 +57,7 @@ exports.left = (0, core_1.createEvent)('LEFT', (channels, groups) => ({ * * @internal */ -exports.leftAll = (0, core_1.createEvent)('LEFT_ALL', () => ({})); +exports.leftAll = (0, core_1.createEvent)('LEFT_ALL', (isOffline) => ({ isOffline })); /** * Presence heartbeat success event. * diff --git a/lib/event-engine/presence/presence.js b/lib/event-engine/presence/presence.js index 49b03378a..434bd8831 100644 --- a/lib/event-engine/presence/presence.js +++ b/lib/event-engine/presence/presence.js @@ -77,8 +77,8 @@ class PresenceEventEngine { } this.engine.transition(events.left(channels !== null && channels !== void 0 ? channels : [], groups !== null && groups !== void 0 ? groups : [])); } - leaveAll() { - this.engine.transition(events.leftAll()); + leaveAll(isOffline) { + this.engine.transition(events.leftAll(isOffline)); } reconnect() { this.engine.transition(events.reconnect()); diff --git a/lib/event-engine/presence/states/heartbeat_cooldown.js b/lib/event-engine/presence/states/heartbeat_cooldown.js index 6da55a77f..2b7b1e236 100644 --- a/lib/event-engine/presence/states/heartbeat_cooldown.js +++ b/lib/event-engine/presence/states/heartbeat_cooldown.js @@ -37,4 +37,6 @@ exports.HeartbeatCooldownState.on(events_1.left.type, (context, event) => heartb exports.HeartbeatCooldownState.on(events_1.disconnect.type, (context, event) => heartbeat_stopped_1.HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ ...(!event.payload.isOffline ? [(0, effects_1.leave)(context.channels, context.groups)] : []), ])); -exports.HeartbeatCooldownState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); +exports.HeartbeatCooldownState.on(events_1.leftAll.type, (context, event) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [ + ...(!event.payload.isOffline ? [(0, effects_1.leave)(context.channels, context.groups)] : []), +])); diff --git a/lib/event-engine/presence/states/heartbeat_failed.js b/lib/event-engine/presence/states/heartbeat_failed.js index c6c665b25..da519c0e6 100644 --- a/lib/event-engine/presence/states/heartbeat_failed.js +++ b/lib/event-engine/presence/states/heartbeat_failed.js @@ -36,4 +36,6 @@ exports.HeartbeatFailedState.on(events_1.reconnect.type, (context, _) => heartbe exports.HeartbeatFailedState.on(events_1.disconnect.type, (context, event) => heartbeat_stopped_1.HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ ...(!event.payload.isOffline ? [(0, effects_1.leave)(context.channels, context.groups)] : []), ])); -exports.HeartbeatFailedState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); +exports.HeartbeatFailedState.on(events_1.leftAll.type, (context, event) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [ + ...(!event.payload.isOffline ? [(0, effects_1.leave)(context.channels, context.groups)] : []), +])); diff --git a/lib/event-engine/presence/states/heartbeating.js b/lib/event-engine/presence/states/heartbeating.js index 20ae37a96..41e24a523 100644 --- a/lib/event-engine/presence/states/heartbeating.js +++ b/lib/event-engine/presence/states/heartbeating.js @@ -42,4 +42,6 @@ exports.HeartbeatingState.on(events_1.heartbeatFailure.type, (context, event) => exports.HeartbeatingState.on(events_1.disconnect.type, (context, event) => heartbeat_stopped_1.HeartbeatStoppedState.with({ channels: context.channels, groups: context.groups }, [ ...(!event.payload.isOffline ? [(0, effects_1.leave)(context.channels, context.groups)] : []), ])); -exports.HeartbeatingState.on(events_1.leftAll.type, (context, _) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [(0, effects_1.leave)(context.channels, context.groups)])); +exports.HeartbeatingState.on(events_1.leftAll.type, (context, event) => heartbeat_inactive_1.HeartbeatInactiveState.with(undefined, [ + ...(!event.payload.isOffline ? [(0, effects_1.leave)(context.channels, context.groups)] : []), +])); diff --git a/lib/event-engine/states/handshake_failed.js b/lib/event-engine/states/handshake_failed.js index 7010c7d6c..24b6eb7b3 100644 --- a/lib/event-engine/states/handshake_failed.js +++ b/lib/event-engine/states/handshake_failed.js @@ -19,7 +19,11 @@ const unsubscribed_1 = require("./unsubscribed"); * @internal */ exports.HandshakeFailedState = new state_1.State('HANDSHAKE_FAILED'); -exports.HandshakeFailedState.on(events_1.subscriptionChange.type, (context, { payload }) => handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); +exports.HandshakeFailedState.on(events_1.subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined); + return handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); +}); exports.HandshakeFailedState.on(events_1.reconnect.type, (context, { payload }) => handshaking_1.HandshakingState.with({ channels: context.channels, groups: context.groups, @@ -27,6 +31,8 @@ exports.HandshakeFailedState.on(events_1.reconnect.type, (context, { payload }) })); exports.HandshakeFailedState.on(events_1.restore.type, (context, { payload }) => { var _a, _b; + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined); return handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, diff --git a/lib/event-engine/states/handshake_stopped.js b/lib/event-engine/states/handshake_stopped.js index 62bf85b00..3227a8ec8 100644 --- a/lib/event-engine/states/handshake_stopped.js +++ b/lib/event-engine/states/handshake_stopped.js @@ -19,10 +19,16 @@ const unsubscribed_1 = require("./unsubscribed"); * @internal */ exports.HandshakeStoppedState = new state_1.State('HANDSHAKE_STOPPED'); -exports.HandshakeStoppedState.on(events_1.subscriptionChange.type, (context, { payload }) => exports.HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); +exports.HandshakeStoppedState.on(events_1.subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined); + return exports.HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); +}); exports.HandshakeStoppedState.on(events_1.reconnect.type, (context, { payload }) => handshaking_1.HandshakingState.with(Object.assign(Object.assign({}, context), { cursor: payload.cursor || context.cursor }))); exports.HandshakeStoppedState.on(events_1.restore.type, (context, { payload }) => { var _a; + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined); return exports.HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, diff --git a/lib/event-engine/states/handshaking.js b/lib/event-engine/states/handshaking.js index c9f34d4b2..58239bf4d 100644 --- a/lib/event-engine/states/handshaking.js +++ b/lib/event-engine/states/handshaking.js @@ -36,7 +36,7 @@ exports.HandshakingState.on(events_1.subscriptionChange.type, (context, { payloa return exports.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); }); exports.HandshakingState.on(events_1.handshakeSuccess.type, (context, { payload }) => { - var _a, _b; + var _a, _b, _c, _d; return receiving_1.ReceivingState.with({ channels: context.channels, groups: context.groups, @@ -44,7 +44,14 @@ exports.HandshakingState.on(events_1.handshakeSuccess.type, (context, { payload timetoken: !!((_a = context.cursor) === null || _a === void 0 ? void 0 : _a.timetoken) ? (_b = context.cursor) === null || _b === void 0 ? void 0 : _b.timetoken : payload.timetoken, region: payload.region, }, - }, [(0, effects_1.emitStatus)({ category: categories_1.default.PNConnectedCategory })]); + }, [ + (0, effects_1.emitStatus)({ + category: categories_1.default.PNConnectedCategory, + affectedChannels: context.channels.slice(0), + affectedChannelGroups: context.groups.slice(0), + currentTimetoken: !!((_c = context.cursor) === null || _c === void 0 ? void 0 : _c.timetoken) ? (_d = context.cursor) === null || _d === void 0 ? void 0 : _d.timetoken : payload.timetoken, + }), + ]); }); exports.HandshakingState.on(events_1.handshakeFailure.type, (context, event) => { var _a; @@ -71,6 +78,8 @@ exports.HandshakingState.on(events_1.disconnect.type, (context, event) => { }); exports.HandshakingState.on(events_1.restore.type, (context, { payload }) => { var _a; + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined); return exports.HandshakingState.with({ channels: payload.channels, groups: payload.groups, diff --git a/lib/event-engine/states/receive_failed.js b/lib/event-engine/states/receive_failed.js index a2fc22708..d683465ea 100644 --- a/lib/event-engine/states/receive_failed.js +++ b/lib/event-engine/states/receive_failed.js @@ -30,10 +30,18 @@ exports.ReceiveFailedState.on(events_1.reconnect.type, (context, { payload }) => }, }); }); -exports.ReceiveFailedState.on(events_1.subscriptionChange.type, (context, { payload }) => handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); -exports.ReceiveFailedState.on(events_1.restore.type, (context, { payload }) => handshaking_1.HandshakingState.with({ - channels: payload.channels, - groups: payload.groups, - cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, -})); +exports.ReceiveFailedState.on(events_1.subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined); + return handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); +}); +exports.ReceiveFailedState.on(events_1.restore.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined); + return handshaking_1.HandshakingState.with({ + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, + }); +}); exports.ReceiveFailedState.on(events_1.unsubscribeAll.type, (_) => unsubscribed_1.UnsubscribedState.with(undefined)); diff --git a/lib/event-engine/states/receive_stopped.js b/lib/event-engine/states/receive_stopped.js index 5d456cc48..95f08bc1b 100644 --- a/lib/event-engine/states/receive_stopped.js +++ b/lib/event-engine/states/receive_stopped.js @@ -19,12 +19,20 @@ const unsubscribed_1 = require("./unsubscribed"); * @internal */ exports.ReceiveStoppedState = new state_1.State('RECEIVE_STOPPED'); -exports.ReceiveStoppedState.on(events_1.subscriptionChange.type, (context, { payload }) => exports.ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor })); -exports.ReceiveStoppedState.on(events_1.restore.type, (context, { payload }) => exports.ReceiveStoppedState.with({ - channels: payload.channels, - groups: payload.groups, - cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, -})); +exports.ReceiveStoppedState.on(events_1.subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined); + return exports.ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); +}); +exports.ReceiveStoppedState.on(events_1.restore.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return unsubscribed_1.UnsubscribedState.with(undefined); + return exports.ReceiveStoppedState.with({ + channels: payload.channels, + groups: payload.groups, + cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, + }); +}); exports.ReceiveStoppedState.on(events_1.reconnect.type, (context, { payload }) => { var _a; return handshaking_1.HandshakingState.with({ diff --git a/lib/event-engine/states/receiving.js b/lib/event-engine/states/receiving.js index 8b66d52bd..bc315811c 100644 --- a/lib/event-engine/states/receiving.js +++ b/lib/event-engine/states/receiving.js @@ -12,12 +12,12 @@ exports.ReceivingState = void 0; const effects_1 = require("../effects"); const events_1 = require("../events"); const categories_1 = __importDefault(require("../../core/constants/categories")); +const pubnub_api_error_1 = require("../../errors/pubnub-api-error"); +const operations_1 = __importDefault(require("../../core/constants/operations")); const receive_stopped_1 = require("./receive_stopped"); const receive_failed_1 = require("./receive_failed"); const unsubscribed_1 = require("./unsubscribed"); const state_1 = require("../core/state"); -const pubnub_api_error_1 = require("../../errors/pubnub-api-error"); -const operations_1 = __importDefault(require("../../core/constants/operations")); /** * Receiving real-time updates (connected) state. * @@ -34,30 +34,41 @@ exports.ReceivingState.on(events_1.receiveSuccess.type, (context, { payload }) = ]); }); exports.ReceivingState.on(events_1.subscriptionChange.type, (context, { payload }) => { - const subscriptionChangeStatus = { - category: categories_1.default.PNSubscriptionChangedCategory, - affectedChannels: payload.channels.slice(0), - affectedChannelGroups: payload.groups.slice(0), - }; - if (payload.channels.length === 0 && payload.groups.length === 0) - return unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)(subscriptionChangeStatus)]); + var _a; + if (payload.channels.length === 0 && payload.groups.length === 0) { + let errorCategory; + if (payload.isOffline) + errorCategory = (_a = pubnub_api_error_1.PubNubAPIError.create(new Error('Network connection error')).toPubNubError(operations_1.default.PNSubscribeOperation).status) === null || _a === void 0 ? void 0 : _a.category; + return unsubscribed_1.UnsubscribedState.with(undefined, [ + (0, effects_1.emitStatus)(Object.assign({ category: !payload.isOffline + ? categories_1.default.PNDisconnectedCategory + : categories_1.default.PNDisconnectedUnexpectedlyCategory }, (errorCategory ? { error: errorCategory } : {}))), + ]); + } return exports.ReceivingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }, [ - (0, effects_1.emitStatus)(subscriptionChangeStatus), + (0, effects_1.emitStatus)({ + category: categories_1.default.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + currentTimetoken: context.cursor.timetoken, + }), ]); }); exports.ReceivingState.on(events_1.restore.type, (context, { payload }) => { - const subscriptionChangeStatus = { - category: categories_1.default.PNSubscriptionChangedCategory, - affectedChannels: payload.channels.slice(0), - affectedChannelGroups: payload.groups.slice(0), - }; if (payload.channels.length === 0 && payload.groups.length === 0) - return unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)(subscriptionChangeStatus)]); + return unsubscribed_1.UnsubscribedState.with(undefined, [(0, effects_1.emitStatus)({ category: categories_1.default.PNDisconnectedCategory })]); return exports.ReceivingState.with({ channels: payload.channels, groups: payload.groups, cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, - }, [(0, effects_1.emitStatus)(subscriptionChangeStatus)]); + }, [ + (0, effects_1.emitStatus)({ + category: categories_1.default.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + currentTimetoken: payload.cursor.timetoken, + }), + ]); }); exports.ReceivingState.on(events_1.receiveFailure.type, (context, { payload }) => { var _a; diff --git a/lib/event-engine/states/unsubscribed.js b/lib/event-engine/states/unsubscribed.js index 351b848ea..7cea37318 100644 --- a/lib/event-engine/states/unsubscribed.js +++ b/lib/event-engine/states/unsubscribed.js @@ -17,5 +17,13 @@ const handshaking_1 = require("./handshaking"); * @internal */ exports.UnsubscribedState = new state_1.State('UNSUBSCRIBED'); -exports.UnsubscribedState.on(events_1.subscriptionChange.type, (_, { payload }) => handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups })); -exports.UnsubscribedState.on(events_1.restore.type, (_, { payload }) => handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: payload.cursor })); +exports.UnsubscribedState.on(events_1.subscriptionChange.type, (_, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return exports.UnsubscribedState.with(undefined); + return handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups }); +}); +exports.UnsubscribedState.on(events_1.restore.type, (_, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) + return exports.UnsubscribedState.with(undefined); + return handshaking_1.HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: payload.cursor }); +}); diff --git a/package.json b/package.json index bdabcfc81..91becc9c3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pubnub", - "version": "9.5.1", + "version": "9.5.2", "author": "PubNub ", "description": "Publish & Subscribe Real-time Messaging with PubNub", "scripts": { diff --git a/src/core/components/configuration.ts b/src/core/components/configuration.ts index 7973ecd65..c5a55e94a 100644 --- a/src/core/components/configuration.ts +++ b/src/core/components/configuration.ts @@ -203,7 +203,7 @@ export const makeConfiguration = ( return base.PubNubFile; }, get version(): string { - return '9.5.1'; + return '9.5.2'; }, getVersion(): string { return this.version; diff --git a/src/core/components/retryPolicy.ts b/src/core/components/retryPolicy.ts index 36be522c2..7fdddd43c 100644 --- a/src/core/components/retryPolicy.ts +++ b/src/core/components/retryPolicy.ts @@ -314,8 +314,15 @@ const isRetriableRequest = ( maximumRetry: number, excluded?: Endpoint[], ) => { - if (errorCategory && errorCategory === StatusCategory.PNCancelledCategory) return false; - else if (isExcludedRequest(req, excluded)) return false; + if (errorCategory) { + if ( + errorCategory === StatusCategory.PNCancelledCategory || + errorCategory === StatusCategory.PNBadRequestCategory || + errorCategory === StatusCategory.PNAccessDeniedCategory + ) + return false; + } + if (isExcludedRequest(req, excluded)) return false; else if (retryAttempt > maximumRetry) return false; return res ? res.status === 429 || res.status >= 500 : true; diff --git a/src/core/pubnub-common.ts b/src/core/pubnub-common.ts index 65e7dbd0d..99c213748 100644 --- a/src/core/pubnub-common.ts +++ b/src/core/pubnub-common.ts @@ -902,11 +902,11 @@ export class PubNubCore< if (this.subscriptionManager) { this.subscriptionManager.unsubscribeAll(isOffline); this.subscriptionManager.disconnect(); - } else if (this.eventEngine) this.eventEngine.dispose(); + } else if (this.eventEngine) this.eventEngine.unsubscribeAll(isOffline); + } - if (process.env.PRESENCE_MODULE !== 'disabled') { - if (this.presenceEventEngine) this.presenceEventEngine.dispose(); - } + if (process.env.PRESENCE_MODULE !== 'disabled') { + if (this.presenceEventEngine) this.presenceEventEngine.leaveAll(isOffline); } } @@ -2063,10 +2063,11 @@ export class PubNubCore< * * @param parameters - List of channels and groups where `leave` event should be sent. */ - private leaveAll(parameters: { channels?: string[]; groups?: string[] }) { + private leaveAll(parameters: { channels?: string[]; groups?: string[]; isOffline?: boolean } = {}) { if (process.env.PRESENCE_MODULE !== 'disabled') { - if (this.presenceEventEngine) this.presenceEventEngine.leaveAll(); - else this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => {}); + if (this.presenceEventEngine) this.presenceEventEngine.leaveAll(parameters.isOffline); + else if (!parameters.isOffline) + this.makeUnsubscribe({ channels: parameters.channels, channelGroups: parameters.groups }, () => {}); } else throw new Error('Announce UUID Leave error: presence module disabled'); } diff --git a/src/event-engine/dispatcher.ts b/src/event-engine/dispatcher.ts index e09d2671f..3055b1fda 100644 --- a/src/event-engine/dispatcher.ts +++ b/src/event-engine/dispatcher.ts @@ -25,7 +25,7 @@ export type Dependencies = { ) => Promise; join?: (parameters: { channels?: string[]; groups?: string[] }) => void; leave?: (parameters: { channels?: string[]; groups?: string[] }) => void; - leaveAll?: (parameters: { channels?: string[]; groups?: string[] }) => void; + leaveAll?: (parameters: { channels?: string[]; groups?: string[]; isOffline?: boolean }) => void; presenceReconnect?: (parameters: { channels?: string[]; groups?: string[] }) => void; presenceDisconnect?: (parameters: { channels?: string[]; groups?: string[]; isOffline?: boolean }) => void; presenceState: Record; diff --git a/src/event-engine/events.ts b/src/event-engine/events.ts index 2787697d3..af8437a5a 100644 --- a/src/event-engine/events.ts +++ b/src/event-engine/events.ts @@ -15,10 +15,14 @@ import { createEvent, MapOf } from './core'; * * @internal */ -export const subscriptionChange = createEvent('SUBSCRIPTION_CHANGED', (channels: string[], groups: string[]) => ({ - channels, - groups, -})); +export const subscriptionChange = createEvent( + 'SUBSCRIPTION_CHANGED', + (channels: string[], groups: string[], isOffline?: boolean) => ({ + channels, + groups, + isOffline, + }), +); /** * Subscription loop restore. diff --git a/src/event-engine/index.ts b/src/event-engine/index.ts index b65155e04..2d8d34691 100644 --- a/src/event-engine/index.ts +++ b/src/event-engine/index.ts @@ -124,7 +124,7 @@ export class EventEngine { } } - unsubscribeAll(): void { + unsubscribeAll(isOffline?: boolean): void { const channelGroups = this.getSubscribedChannels(); const channels = this.getSubscribedChannels(); @@ -136,8 +136,8 @@ export class EventEngine { delete this.dependencies.presenceState[objectName]; }); } - this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0))); - if (this.dependencies.leaveAll) this.dependencies.leaveAll({ channels, groups: channelGroups }); + this.engine.transition(events.subscriptionChange(this.channels.slice(0), this.groups.slice(0), isOffline)); + if (this.dependencies.leaveAll) this.dependencies.leaveAll({ channels, groups: channelGroups, isOffline }); } reconnect({ timetoken, region }: { timetoken?: string; region?: number }): void { diff --git a/src/event-engine/presence/events.ts b/src/event-engine/presence/events.ts index f3c7e3f64..543414400 100644 --- a/src/event-engine/presence/events.ts +++ b/src/event-engine/presence/events.ts @@ -60,7 +60,7 @@ export const left = createEvent('LEFT', (channels: string[], groups: string[]) = * * @internal */ -export const leftAll = createEvent('LEFT_ALL', () => ({})); +export const leftAll = createEvent('LEFT_ALL', (isOffline?: boolean) => ({ isOffline })); /** * Presence heartbeat success event. diff --git a/src/event-engine/presence/presence.ts b/src/event-engine/presence/presence.ts index 1e0d9731b..87220e244 100644 --- a/src/event-engine/presence/presence.ts +++ b/src/event-engine/presence/presence.ts @@ -55,8 +55,8 @@ export class PresenceEventEngine { this.engine.transition(events.left(channels ?? [], groups ?? [])); } - leaveAll() { - this.engine.transition(events.leftAll()); + leaveAll(isOffline?: boolean) { + this.engine.transition(events.leftAll(isOffline)); } reconnect() { diff --git a/src/event-engine/presence/states/heartbeat_cooldown.ts b/src/event-engine/presence/states/heartbeat_cooldown.ts index 5b7a78f76..52013b717 100644 --- a/src/event-engine/presence/states/heartbeat_cooldown.ts +++ b/src/event-engine/presence/states/heartbeat_cooldown.ts @@ -63,6 +63,8 @@ HeartbeatCooldownState.on(disconnect.type, (context, event) => ]), ); -HeartbeatCooldownState.on(leftAll.type, (context, _) => - HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)]), +HeartbeatCooldownState.on(leftAll.type, (context, event) => + HeartbeatInactiveState.with(undefined, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ]), ); diff --git a/src/event-engine/presence/states/heartbeat_failed.ts b/src/event-engine/presence/states/heartbeat_failed.ts index d07c8c940..d14033699 100644 --- a/src/event-engine/presence/states/heartbeat_failed.ts +++ b/src/event-engine/presence/states/heartbeat_failed.ts @@ -61,6 +61,8 @@ HeartbeatFailedState.on(disconnect.type, (context, event) => ]), ); -HeartbeatFailedState.on(leftAll.type, (context, _) => - HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)]), +HeartbeatFailedState.on(leftAll.type, (context, event) => + HeartbeatInactiveState.with(undefined, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ]), ); diff --git a/src/event-engine/presence/states/heartbeating.ts b/src/event-engine/presence/states/heartbeating.ts index ca864c1c1..c0a3c6b42 100644 --- a/src/event-engine/presence/states/heartbeating.ts +++ b/src/event-engine/presence/states/heartbeating.ts @@ -69,6 +69,8 @@ HeartbeatingState.on(disconnect.type, (context, event) => ]), ); -HeartbeatingState.on(leftAll.type, (context, _) => - HeartbeatInactiveState.with(undefined, [leave(context.channels, context.groups)]), +HeartbeatingState.on(leftAll.type, (context, event) => + HeartbeatInactiveState.with(undefined, [ + ...(!event.payload.isOffline ? [leave(context.channels, context.groups)] : []), + ]), ); diff --git a/src/event-engine/states/handshake_failed.ts b/src/event-engine/states/handshake_failed.ts index 56599e199..65fa3ab1f 100644 --- a/src/event-engine/states/handshake_failed.ts +++ b/src/event-engine/states/handshake_failed.ts @@ -35,9 +35,11 @@ export type HandshakeFailedStateContext = { */ export const HandshakeFailedState = new State('HANDSHAKE_FAILED'); -HandshakeFailedState.on(subscriptionChange.type, (context, { payload }) => - HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }), -); +HandshakeFailedState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); + + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); +}); HandshakeFailedState.on(reconnect.type, (context, { payload }) => HandshakingState.with({ @@ -47,15 +49,17 @@ HandshakeFailedState.on(reconnect.type, (context, { payload }) => }), ); -HandshakeFailedState.on(restore.type, (context, { payload }) => - HandshakingState.with({ +HandshakeFailedState.on(restore.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); + + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region ? payload.cursor.region : (context?.cursor?.region ?? 0), }, - }), -); + }); +}); HandshakeFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); diff --git a/src/event-engine/states/handshake_stopped.ts b/src/event-engine/states/handshake_stopped.ts index 909ba97c1..fd8d388d3 100644 --- a/src/event-engine/states/handshake_stopped.ts +++ b/src/event-engine/states/handshake_stopped.ts @@ -32,20 +32,24 @@ type HandshakeStoppedStateContext = { */ export const HandshakeStoppedState = new State('HANDSHAKE_STOPPED'); -HandshakeStoppedState.on(subscriptionChange.type, (context, { payload }) => - HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }), -); +HandshakeStoppedState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); + + return HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); +}); HandshakeStoppedState.on(reconnect.type, (context, { payload }) => HandshakingState.with({ ...context, cursor: payload.cursor || context.cursor }), ); -HandshakeStoppedState.on(restore.type, (context, { payload }) => - HandshakeStoppedState.with({ +HandshakeStoppedState.on(restore.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); + + return HandshakeStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor?.region || 0 }, - }), -); + }); +}); HandshakeStoppedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); diff --git a/src/event-engine/states/handshaking.ts b/src/event-engine/states/handshaking.ts index 7e2e881be..01210e935 100644 --- a/src/event-engine/states/handshaking.ts +++ b/src/event-engine/states/handshaking.ts @@ -64,7 +64,14 @@ HandshakingState.on(handshakeSuccess.type, (context, { payload }) => region: payload.region, }, }, - [emitStatus({ category: categoryConstants.PNConnectedCategory })], + [ + emitStatus({ + category: categoryConstants.PNConnectedCategory, + affectedChannels: context.channels.slice(0), + affectedChannelGroups: context.groups.slice(0), + currentTimetoken: !!context.cursor?.timetoken ? context.cursor?.timetoken : payload.timetoken, + }), + ], ), ); @@ -100,12 +107,14 @@ HandshakingState.on(disconnect.type, (context, event) => { } }); -HandshakingState.on(restore.type, (context, { payload }) => - HandshakingState.with({ +HandshakingState.on(restore.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); + + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context?.cursor?.region || 0 }, - }), -); + }); +}); HandshakingState.on(unsubscribeAll.type, (_) => UnsubscribedState.with()); diff --git a/src/event-engine/states/receive_failed.ts b/src/event-engine/states/receive_failed.ts index 5304e375a..6f9d43c43 100644 --- a/src/event-engine/states/receive_failed.ts +++ b/src/event-engine/states/receive_failed.ts @@ -46,16 +46,20 @@ ReceiveFailedState.on(reconnect.type, (context, { payload }) => }), ); -ReceiveFailedState.on(subscriptionChange.type, (context, { payload }) => - HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }), -); +ReceiveFailedState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); -ReceiveFailedState.on(restore.type, (context, { payload }) => - HandshakingState.with({ + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); +}); + +ReceiveFailedState.on(restore.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); + + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, - }), -); + }); +}); ReceiveFailedState.on(unsubscribeAll.type, (_) => UnsubscribedState.with(undefined)); diff --git a/src/event-engine/states/receive_stopped.ts b/src/event-engine/states/receive_stopped.ts index c1a4b9ef5..0805af9f4 100644 --- a/src/event-engine/states/receive_stopped.ts +++ b/src/event-engine/states/receive_stopped.ts @@ -32,17 +32,21 @@ type ReceiveStoppedStateContext = { */ export const ReceiveStoppedState = new State('RECEIVE_STOPPED'); -ReceiveStoppedState.on(subscriptionChange.type, (context, { payload }) => - ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }), -); +ReceiveStoppedState.on(subscriptionChange.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); + + return ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }); +}); + +ReceiveStoppedState.on(restore.type, (context, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); -ReceiveStoppedState.on(restore.type, (context, { payload }) => - ReceiveStoppedState.with({ + return ReceiveStoppedState.with({ channels: payload.channels, groups: payload.groups, cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, - }), -); + }); +}); ReceiveStoppedState.on(reconnect.type, (context, { payload }) => HandshakingState.with({ diff --git a/src/event-engine/states/receiving.ts b/src/event-engine/states/receiving.ts index 5f158322b..2c9d2ae2f 100644 --- a/src/event-engine/states/receiving.ts +++ b/src/event-engine/states/receiving.ts @@ -16,13 +16,12 @@ import { } from '../events'; import * as Subscription from '../../core/types/api/subscription'; import categoryConstants from '../../core/constants/categories'; +import { PubNubAPIError } from '../../errors/pubnub-api-error'; +import RequestOperation from '../../core/constants/operations'; import { ReceiveStoppedState } from './receive_stopped'; import { ReceiveFailedState } from './receive_failed'; import { UnsubscribedState } from './unsubscribed'; import { State } from '../core/state'; -import { HandshakeFailedState } from './handshake_failed'; -import { PubNubAPIError } from '../../errors/pubnub-api-error'; -import RequestOperation from '../../core/constants/operations'; /** * Context which represent current Subscription Event Engine data state. @@ -54,29 +53,36 @@ ReceivingState.on(receiveSuccess.type, (context, { payload }) => { }); ReceivingState.on(subscriptionChange.type, (context, { payload }) => { - const subscriptionChangeStatus = { - category: categoryConstants.PNSubscriptionChangedCategory, - affectedChannels: payload.channels.slice(0), - affectedChannelGroups: payload.groups.slice(0), - }; + if (payload.channels.length === 0 && payload.groups.length === 0) { + let errorCategory: string | undefined; + if (payload.isOffline) + errorCategory = PubNubAPIError.create(new Error('Network connection error')).toPubNubError( + RequestOperation.PNSubscribeOperation, + ).status?.category; - if (payload.channels.length === 0 && payload.groups.length === 0) - return UnsubscribedState.with(undefined, [emitStatus(subscriptionChangeStatus)]); + return UnsubscribedState.with(undefined, [ + emitStatus({ + category: !payload.isOffline + ? categoryConstants.PNDisconnectedCategory + : categoryConstants.PNDisconnectedUnexpectedlyCategory, + ...(errorCategory ? { error: errorCategory } : {}), + }), + ]); + } return ReceivingState.with({ channels: payload.channels, groups: payload.groups, cursor: context.cursor }, [ - emitStatus(subscriptionChangeStatus), + emitStatus({ + category: categoryConstants.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + currentTimetoken: context.cursor.timetoken, + }), ]); }); ReceivingState.on(restore.type, (context, { payload }) => { - const subscriptionChangeStatus = { - category: categoryConstants.PNSubscriptionChangedCategory, - affectedChannels: payload.channels.slice(0), - affectedChannelGroups: payload.groups.slice(0), - }; - if (payload.channels.length === 0 && payload.groups.length === 0) - return UnsubscribedState.with(undefined, [emitStatus(subscriptionChangeStatus)]); + return UnsubscribedState.with(undefined, [emitStatus({ category: categoryConstants.PNDisconnectedCategory })]); return ReceivingState.with( { @@ -84,7 +90,14 @@ ReceivingState.on(restore.type, (context, { payload }) => { groups: payload.groups, cursor: { timetoken: payload.cursor.timetoken, region: payload.cursor.region || context.cursor.region }, }, - [emitStatus(subscriptionChangeStatus)], + [ + emitStatus({ + category: categoryConstants.PNSubscriptionChangedCategory, + affectedChannels: payload.channels.slice(0), + affectedChannelGroups: payload.groups.slice(0), + currentTimetoken: payload.cursor.timetoken, + }), + ], ); }); diff --git a/src/event-engine/states/unsubscribed.ts b/src/event-engine/states/unsubscribed.ts index 772a770bc..44a661c4e 100644 --- a/src/event-engine/states/unsubscribed.ts +++ b/src/event-engine/states/unsubscribed.ts @@ -18,10 +18,14 @@ import { HandshakingState } from './handshaking'; */ export const UnsubscribedState = new State('UNSUBSCRIBED'); -UnsubscribedState.on(subscriptionChange.type, (_, { payload }) => - HandshakingState.with({ channels: payload.channels, groups: payload.groups }), -); +UnsubscribedState.on(subscriptionChange.type, (_, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); -UnsubscribedState.on(restore.type, (_, { payload }) => - HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: payload.cursor }), -); + return HandshakingState.with({ channels: payload.channels, groups: payload.groups }); +}); + +UnsubscribedState.on(restore.type, (_, { payload }) => { + if (payload.channels.length === 0 && payload.groups.length === 0) return UnsubscribedState.with(undefined); + + return HandshakingState.with({ channels: payload.channels, groups: payload.groups, cursor: payload.cursor }); +});